@@ -59,6 +59,8 @@ bool input_eof = false;
5959
6060uint64_t clockTicksAtAddress [65536 ];
6161
62+ void finish (void );
63+
6264int8_t read6502 (uint16_t address ) {
6365 if (address == 0xfff0 ) {
6466 * ((uint32_t * )(memory + address )) = clockticks6502 - clock_start ;
@@ -68,6 +70,10 @@ int8_t read6502(uint16_t address) {
6870 return (int8_t )c ;
6971 } else if (address == 0xfff6 ) {
7072 return (int8_t )input_eof ;
73+ } else if (address == 0xfffe ) {
74+ fprintf (stderr , "%04x:%02x %02x %02x read fffe\n" , pc , memory [pc ], memory [pc + 1 ], memory [pc + 2 ]);
75+ finish ();
76+ abort ();
7177 }
7278 return memory [address ];
7379}
@@ -91,9 +97,13 @@ void write6502(uint16_t address, uint8_t value) {
9197 clock_start = clockticks6502 ;
9298 break ;
9399 case 0xFFF7 :
100+ if (shouldProfile )
101+ fprintf (stderr , "%04x:%02x %02x %02x write fff7\n" , pc , memory [pc ], memory [pc + 1 ], memory [pc + 2 ]);
94102 finish ();
95103 abort ();
96104 case 0xFFF8 :
105+ if (shouldProfile )
106+ fprintf (stderr , "%04x:%02x %02x %02x write fff7\n" , pc , memory [pc ], memory [pc + 1 ], memory [pc + 2 ]);
97107 finish ();
98108 exit (value );
99109 case 0xFFF9 :
@@ -187,9 +197,21 @@ int main(int argc, const char *argv[]) {
187197
188198 reset6502 (cmos );
189199 for (;;) {
190- if (shouldTrace )
191- fprintf (stderr , "%04x a:%02x x:%02x y:%02x s: %02x st:%02x\n" , pc , a , x ,
192- y , sp , status );
200+ char status_buf [9 ];
201+ status_buf [8 ] = '\0' ;
202+ const char statuses [] = "czidb1vn" ;
203+
204+ if (shouldTrace ) {
205+ for (int i = 0 ; i < 8 ; ++ i ) {
206+ status_buf [7 - i ] = status & (1 <<i ) ?
207+ statuses [i ] : '.' ;
208+ }
209+ fprintf (stderr ,
210+ "%04x a:%02x x:%02x y:%02x s:%02x st:%02x (%s)"
211+ " insn:%02x %02x %02x\n" ,
212+ pc , a , x , y , sp , status , status_buf ,
213+ memory [pc ], memory [(pc + 1 )& 0xffff ], memory [(pc + 2 )& 0xffff ]);
214+ }
193215 uint32_t clockTicksBefore = clockticks6502 ;
194216 uint16_t addr = pc ;
195217 step6502 ();
0 commit comments