File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,9 @@ func (ppu *P2c02) Tick() {
170170 ppu .currentScanline ++
171171 }
172172 ppu .renderCycle = 0
173+ if ppu .shouldSkipFirstCycleOnOddFrame () {
174+ ppu .renderCycle = 1
175+ }
173176 } else {
174177 ppu .renderCycle ++
175178 }
@@ -181,6 +184,10 @@ func (ppu *P2c02) Tick() {
181184 }
182185}
183186
187+ func (ppu * P2c02 ) shouldSkipFirstCycleOnOddFrame () bool {
188+ return ppu .PpuMask .ShowBackground == 1 && ppu .scanlineIsVisibleOrIsPreRender () && ppu .evenFrame == false && ppu .currentScanline == 0 && ppu .renderCycle == 0
189+ }
190+
184191func (ppu * P2c02 ) incrementX () {
185192 if ppu .PpuMask .renderingEnabled () {
186193 if ppu .vRam .CoarseX () == 31 { // if CoarseX == 31
Original file line number Diff line number Diff line change @@ -26,6 +26,26 @@ func aPPU() *P2c02 {
2626 return ppu
2727}
2828
29+ func TestPpu2c02_odd_frames_are_1_cycle_shorter_when_rendering_is_enabled (t * testing.T ) {
30+ ppu := aPPU ()
31+ ppu .PpuMask .ShowBackground = 1
32+ for i := 0 ; i < (341 * (261 + 1 )); i ++ {
33+ ppu .Tick ()
34+ }
35+
36+ assert .Equal (t , uint16 (1 ), ppu .renderCycle , "Did not skip cycle 0" )
37+ }
38+
39+ func TestPpu2c02_odd_frames_are_last_341_cycles_when_rendering_is_disabled (t * testing.T ) {
40+ ppu := aPPU ()
41+ ppu .PpuMask .ShowBackground = 0
42+ for i := 0 ; i < (341 * (261 + 1 )); i ++ {
43+ ppu .Tick ()
44+ }
45+
46+ assert .Equal (t , uint16 (0 ), ppu .renderCycle , "Should not skip cycle 0" )
47+ }
48+
2949// Render cycles tests
3050func TestPPU_Render_Cycles_should_increment_scanline_after_341_cycles (t * testing.T ) {
3151 ppu := aPPU ()
@@ -40,6 +60,7 @@ func TestPPU_Render_Cycles_should_reset_scanline_after_261_scanlines(t *testing.
4060 ppu := aPPU ()
4161 ppu .renderCycle = 340
4262 ppu .currentScanline = 261
63+ ppu .evenFrame = false
4364
4465 ppu .Tick ()
4566
You can’t perform that action at this time.
0 commit comments