@@ -245,12 +245,24 @@ impl Cpu {
245
245
F : FnMut ( & mut Cpu ) ,
246
246
{
247
247
loop {
248
+ if self . bus . poll_nmi_status ( ) {
249
+ todo ! ( "implement NMI interrupt" ) ;
250
+ // self.interrupt_nmi();
251
+ }
252
+
248
253
callback ( self ) ;
249
254
250
255
let opcode = self . mem_read ( self . pc ) ;
251
256
self . pc += 1 ;
252
257
253
- let ( name, mode) = lookup_opcode ( opcode) ;
258
+ let ( name, cycles, mode) = lookup_opcode ( opcode) ;
259
+ if cycles. 0 == 0 {
260
+ todo ! (
261
+ "cycles is mistakenly set to 0 for {} (0x{:02X}) " ,
262
+ name,
263
+ opcode
264
+ ) ;
265
+ }
254
266
let size = addressing_mode_to_size ( & mode) ;
255
267
256
268
let saved_pc = self . pc ;
@@ -336,6 +348,13 @@ impl Cpu {
336
348
OpName :: RRA => self . rra ( & mode) ,
337
349
}
338
350
351
+ // TODO: Handle extra cycles behavior
352
+ // (1) page wrapping behavior for some ops that adds +1 to the number of cycles
353
+ // Memory page size is 256 bytes. For example, the range [0x0000 .. 0x00FF]- belongs to page 0, [0x0100 .. 0x01FF] belongs to page 1, etc.
354
+ // It's enough to compare the upper byte of the addresses to see if they are on the same page.
355
+ // (2) branching behavior that adds +1 or +2 to cycles
356
+ self . bus . tick ( cycles. 0 as usize ) ;
357
+
339
358
// some operations modify the pc, like JMP. We shouldn't override that.
340
359
if self . pc == saved_pc {
341
360
self . pc += size - 1 ;
@@ -836,7 +855,7 @@ impl Cpu {
836
855
//// Address syntax by mode looks like:
837
856
838
857
let op = lookup_opcode ( code) ;
839
- let ( name, mode) = op;
858
+ let ( name, _ , mode) = op;
840
859
let size = addressing_mode_to_size ( & mode) ;
841
860
842
861
let tla = format ! ( "{}{}" , if is_official( code) { "" } else { "*" } , name) ;
0 commit comments