Skip to content

Commit f994823

Browse files
committedApr 29, 2018
Expanded testsuite funcionality to disassembly
1 parent 4b1fea3 commit f994823

File tree

2 files changed

+61
-32
lines changed

2 files changed

+61
-32
lines changed
 

‎mult4packed.s

+17-27
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mult4packed:
5656
; A high, RotA high, B low, and RotB low.
5757
and #$F
5858
sta multBrotlow
59-
lda multBrot
59+
lda multB
6060
and #$F
6161
sta multBlow
6262
lda multA
@@ -66,46 +66,36 @@ mult4packed:
6666
and #$F0
6767
sta multArothigh
6868

69-
; Now, we assemble our partial products, starting with the with an
69+
; Now, we assemble our partial products, starting with an
7070
; element already in the accumulator - P0. The rest follows.
71+
; Finally, we use the partial products as arguments in a look-up
72+
; multiplication table, and start building our products.
7173

7274
; P0
7375
ora multBlow
76+
tax
77+
lda mult44table, x
7478
sta p0
7579
; P1
7680
lda multAhigh
7781
ora multBlow
82+
tax
83+
lda mult44table, x
84+
tax
85+
lda rot4table, x
7886
sta p1
7987
; P2
8088
lda multArothigh
8189
ora multBrotlow
82-
sta p2
83-
; P3
84-
lda multAhigh
85-
ora multBrotlow
86-
sta p3
87-
88-
; Finally, we use the partial products as arguments in a look-up
89-
; multiplication table, and start building our products.
90-
91-
; P0
92-
ldx p0
93-
lda mult44table, x
94-
sta p0
95-
; P1, rotated
96-
ldx p1
97-
lda mult44table, x
9890
tax
99-
lda rot4table, x
100-
sta p1
101-
; P2, rotated
102-
ldx p2
10391
lda mult44table, x
10492
tax
10593
lda rot4table, x
10694
sta p2
10795
; P3
108-
ldx p3
96+
lda multAhigh
97+
ora multBrotlow
98+
tax
10999
lda mult44table, x
110100
sta p3
111101

@@ -114,20 +104,20 @@ mult4packed:
114104
clc
115105
; First we sum P1...
116106
lda p1
117-
ora #$F0
107+
and #$F0
118108
adc p0
119109
sta p0
120110
lda p1
121-
ora #$F
111+
and #$F
122112
adc p3
123113
sta p3
124114
; ...and finally we sum P2. Done!
125115
lda p2
126-
ora #$F0
116+
and #$F0
127117
adc p0
128118
sta p0
129119
lda p2
130-
ora #$F
120+
and #$F
131121
adc p3
132122
sta p3
133123
rts

‎testMain.c

+44-5
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,39 @@ void write6502(uint16_t address, uint8_t value) {
2525
ram[address] = value;
2626
}
2727

28+
const char opString[][4] = {
29+
/* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | */
30+
/* 0 */ "brk","ora","nop","slo","nop","ora","asl","slo","php","ora","asl","nop","nop","ora","asl","slo", /* 0 */
31+
/* 1 */ "bpl","ora","nop","slo","nop","ora","asl","slo","clc","ora","nop","slo","nop","ora","asl","slo", /* 1 */
32+
/* 2 */ "jsr","and","nop","rla","bit","and","rol","rla","plp","and","rol","nop","bit","and","rol","rla", /* 2 */
33+
/* 3 */ "bmi","and","nop","rla","nop","and","rol","rla","sec","and","nop","rla","nop","and","rol","rla", /* 3 */
34+
/* 4 */ "rti","eor","nop","sre","nop","eor","lsr","sre","pha","eor","lsr","nop","jmp","eor","lsr","sre", /* 4 */
35+
/* 5 */ "bvc","eor","nop","sre","nop","eor","lsr","sre","cli","eor","nop","sre","nop","eor","lsr","sre", /* 5 */
36+
/* 6 */ "rts","adc","nop","rra","nop","adc","ror","rra","pla","adc","ror","nop","jmp","adc","ror","rra", /* 6 */
37+
/* 7 */ "bvs","adc","nop","rra","nop","adc","ror","rra","sei","adc","nop","rra","nop","adc","ror","rra", /* 7 */
38+
/* 8 */ "nop","sta","nop","sax","sty","sta","stx","sax","dey","nop","txa","nop","sty","sta","stx","sax", /* 8 */
39+
/* 9 */ "bcc","sta","nop","nop","sty","sta","stx","sax","tya","sta","txs","nop","nop","sta","nop","nop", /* 9 */
40+
/* A */ "ldy","lda","ldx","lax","ldy","lda","ldx","lax","tay","lda","tax","nop","ldy","lda","ldx","lax", /* A */
41+
/* B */ "bcs","lda","nop","lax","ldy","lda","ldx","lax","clv","lda","tsx","lax","ldy","lda","ldx","lax", /* B */
42+
/* C */ "cpy","cmp","nop","dcp","cpy","cmp","dec","dcp","iny","cmp","dex","nop","cpy","cmp","dec","dcp", /* C */
43+
/* D */ "bne","cmp","nop","dcp","nop","cmp","dec","dcp","cld","cmp","nop","dcp","nop","cmp","dec","dcp", /* D */
44+
/* E */ "cpx","sbc","nop","isb","cpx","sbc","inc","isb","inx","sbc","nop","sbc","cpx","sbc","inc","isb", /* E */
45+
/* F */ "beq","sbc","nop","isb","nop","sbc","inc","isb","sed","sbc","nop","isb","nop","sbc","inc","isb" /* F */
46+
};
47+
2848
int main(int argc, char **args) {
2949
// First, we load a binary file to memory, and wait until execution reaches the end of it.
3050
if (argc < 2) {
3151
printf("Please specify a binary file to load!\nExiting.\n");
3252
exit(1);
3353
}
54+
55+
if (argc < 3) {
56+
printf("Please specify how many registers are to be watched!\nExiting.\n");
57+
exit(1);
58+
}
59+
int numRegs = atoi(args[2]);
60+
3461
FILE *file = fopen(args[1], "rb");
3562
if (file == NULL) {
3663
printf("Error: file not found!\nExiting.\n");
@@ -47,10 +74,14 @@ int main(int argc, char **args) {
4774
strcat(dumpFileName, ".execLog.csv");
4875
FILE *output = fopen(outputFileName, "w");
4976
FILE *dump = fopen(dumpFileName, "w");
50-
fprintf(dump, "Address,A,X,Y,P,R0,R1,R2,R3\n");
77+
fprintf(dump, "Address,A,X,Y,P");
78+
for (int r = 0; r < numRegs; r++) {
79+
fprintf(dump, ",R%d", r);
80+
}
81+
fprintf(dump, ",Opcode\n");
5182

52-
for (int rX = 0; rX < 256; rX++) {
53-
for (int rY = 0; rY < 256; rY++) {
83+
for (int rX = 0xAB; rX < 256; rX++) {
84+
for (int rY = 0xCD; rY < 256; rY++) {
5485
const int limit = 4096;
5586
reset6502();
5687
pc = 0x200;
@@ -59,10 +90,18 @@ int main(int argc, char **args) {
5990

6091
int c;
6192
for (c = 0; c < limit; c++) {
62-
fprintf(dump, "%04x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n", pc, a, x, y, status, ram[0], ram[1], ram[2], ram[3]);
93+
fprintf(dump, "%04x,%02x,%02x,%02x,%02x", pc, a, x, y, status);
94+
for (int r = 0; r < numRegs; r++) {
95+
fprintf(dump, ",%02x", ram[r]);
96+
}
97+
fprintf(dump, ",%s\n", opString[ram[pc]]);
6398

6499
step6502();
65-
if (pc == 0x200 + binSize - 1) {
100+
// The correct way of testing for termination is to see if
101+
// the PC points to an RTS instruction. But an equally
102+
// effective way is to test to see if it's pointing to any
103+
// address below our strating point.
104+
if (pc < 0x200) {
66105
break;
67106
}
68107
}

0 commit comments

Comments
 (0)
Please sign in to comment.