GB Video: Improved video timings
Jeffrey Pfau jeffrey@endrift.com
Sun, 25 Sep 2016 19:18:46 -0700
3 files changed,
10 insertions(+),
7 deletions(-)
M
src/gb/video.c
→
src/gb/video.c
@@ -110,7 +110,7 @@ ++video->ly;
video->p->memory.io[REG_LY] = video->ly; video->stat = GBRegisterSTATSetLYC(video->stat, lyc == video->ly); if (video->ly < GB_VIDEO_VERTICAL_PIXELS) { - video->nextMode = GB_VIDEO_MODE_2_LENGTH; + video->nextMode = GB_VIDEO_MODE_2_LENGTH + (video->p->memory.io[REG_SCX] & 7); video->mode = 2; if (!GBRegisterSTATIsHblankIRQ(video->stat) && GBRegisterSTATIsOAMIRQ(video->stat)) { video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT);@@ -142,7 +142,8 @@ ++video->ly;
if (video->ly == GB_VIDEO_VERTICAL_TOTAL_PIXELS + 1) { video->ly = 0; video->p->memory.io[REG_LY] = video->ly; - video->nextMode = GB_VIDEO_MODE_2_LENGTH; + // TODO: Cache SCX & 7 in case it changes during mode 2 + video->nextMode = GB_VIDEO_MODE_2_LENGTH + (video->p->memory.io[REG_SCX] & 7); video->mode = 2; if (GBRegisterSTATIsOAMIRQ(video->stat)) { video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT);@@ -175,11 +176,12 @@ _cleanOAM(video, video->ly);
video->dotCounter = 0; video->nextEvent = GB_VIDEO_HORIZONTAL_LENGTH; video->x = 0; - video->nextMode = GB_VIDEO_MODE_3_LENGTH_BASE + video->objMax * 12; + // TODO: Estimate sprite timings better + video->nextMode = GB_VIDEO_MODE_3_LENGTH_BASE + video->objMax * 11 - (video->p->memory.io[REG_SCX] & 7); video->mode = 3; break; case 3: - video->nextMode = GB_VIDEO_MODE_0_LENGTH_BASE - video->objMax * 12; + video->nextMode = GB_VIDEO_MODE_0_LENGTH_BASE - video->objMax * 11; video->mode = 0; if (GBRegisterSTATIsHblankIRQ(video->stat)) { video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT);
M
src/gb/video.h
→
src/gb/video.h
@@ -19,9 +19,9 @@ GB_VIDEO_VBLANK_PIXELS = 10,
GB_VIDEO_VERTICAL_TOTAL_PIXELS = GB_VIDEO_VERTICAL_PIXELS + GB_VIDEO_VBLANK_PIXELS, // TODO: Figure out exact lengths - GB_VIDEO_MODE_2_LENGTH = 78, - GB_VIDEO_MODE_3_LENGTH_BASE = 160, - GB_VIDEO_MODE_0_LENGTH_BASE = 218, + GB_VIDEO_MODE_2_LENGTH = 83, + GB_VIDEO_MODE_3_LENGTH_BASE = 158, + GB_VIDEO_MODE_0_LENGTH_BASE = 215, GB_VIDEO_HORIZONTAL_LENGTH = GB_VIDEO_MODE_0_LENGTH_BASE + GB_VIDEO_MODE_2_LENGTH + GB_VIDEO_MODE_3_LENGTH_BASE,