@@ -8,31 +8,31 @@ pub struct Bus {
88 rom : NesRom ,
99 prg_ram : Ram ,
1010 pub ppu : Ppu < PpuMemory > ,
11- cycle : u32
11+ cycle : u32 ,
1212}
1313
1414impl Bus {
15-
1615 pub fn new ( rom : NesRom ) -> Self {
1716 Self {
1817 sram : Ram :: new ( 0x8000 ) ,
1918 rom : rom. clone ( ) ,
2019 prg_ram : Ram :: new ( 0x2000 ) ,
2120 ppu : Ppu :: new ( rom. chr_rom , rom. nametable_mirroring ) ,
22- cycle : 0
21+ cycle : 0 ,
2322 }
2423 }
2524
2625 pub fn tick ( & mut self , cycle : u32 ) {
26+ let delta = cycle - self . cycle ;
2727 self . cycle = cycle;
28- self . ppu . tick ( cycle * 3 ) ;
28+ self . ppu . tick ( delta * 3 ) ;
2929 }
3030
31- pub fn poll_nmi ( & mut self ) -> bool {
32- self . ppu . poll_nmi ( )
31+ pub fn poll_nmi ( & mut self ) -> bool {
32+ self . ppu . poll_nmi ( )
3333 }
3434
35- pub fn poll_new_frame ( & mut self ) -> bool {
35+ pub fn poll_new_frame ( & mut self ) -> bool {
3636 self . ppu . poll_new_frame ( )
3737 }
3838
@@ -50,6 +50,9 @@ impl Bus {
5050 a, register
5151 ) ,
5252 }
53+ } else if a == 0x4016 || a == 0x4017 {
54+ // TODO
55+ 0
5356 } else if ( 0x6000 ..0x8000 ) . contains ( & a) {
5457 self . prg_ram . read ( a - 0x6000 )
5558 } else if a >= 0x8000 {
@@ -67,7 +70,9 @@ impl Bus {
6770 match register {
6871 0 => self . ppu . write_ppu_ctrl ( v) ,
6972 1 => self . ppu . write_ppu_mask ( v) ,
70- 3 => unimplemented ! ( ) ,
73+ 3 => {
74+ // unimplemented!()
75+ }
7176 4 => unimplemented ! ( ) ,
7277 5 => self . ppu . write_ppu_scroll ( v) ,
7378 6 => self . ppu . write_ppu_addr ( v) ,
@@ -78,7 +83,9 @@ impl Bus {
7883 ) ,
7984 } ;
8085 } else if a == 0x4014 {
81- unimplemented ! ( )
86+ // unimplemented!()
87+ } else if ( 0x4000 ..=0x4017 ) . contains ( & a) {
88+ // TODO APU
8289 } else if ( 0x6000 ..0x8000 ) . contains ( & a) {
8390 self . prg_ram . write ( a - 0x6000 , v) ;
8491 } else {
@@ -91,5 +98,4 @@ impl Bus {
9198 let lo = self . rom . prg_rom [ ( 0xFFFC - 0x8000 ) % self . rom . prg_rom . len ( ) ] as u16 ;
9299 ( hi << 8 ) | lo
93100 }
94-
95101}
0 commit comments