@@ -25,12 +25,39 @@ void write6502(uint16_t address, uint8_t value) {
25
25
ram [address ] = value ;
26
26
}
27
27
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
+
28
48
int main (int argc , char * * args ) {
29
49
// First, we load a binary file to memory, and wait until execution reaches the end of it.
30
50
if (argc < 2 ) {
31
51
printf ("Please specify a binary file to load!\nExiting.\n" );
32
52
exit (1 );
33
53
}
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
+
34
61
FILE * file = fopen (args [1 ], "rb" );
35
62
if (file == NULL ) {
36
63
printf ("Error: file not found!\nExiting.\n" );
@@ -47,10 +74,14 @@ int main(int argc, char **args) {
47
74
strcat (dumpFileName , ".execLog.csv" );
48
75
FILE * output = fopen (outputFileName , "w" );
49
76
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" );
51
82
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 ++ ) {
54
85
const int limit = 4096 ;
55
86
reset6502 ();
56
87
pc = 0x200 ;
@@ -59,10 +90,18 @@ int main(int argc, char **args) {
59
90
60
91
int c ;
61
92
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 ]]);
63
98
64
99
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 ) {
66
105
break ;
67
106
}
68
107
}
0 commit comments