From c4cfff45819d261ef6c158dabff9e4c2082fb3c1 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 25 Sep 2016 19:18:46 -0700 Subject: [PATCH] GB Video: Improved video timings --- CHANGES | 1 + src/gb/video.c | 10 ++++++---- src/gb/video.h | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index c89446be9..960bed6df 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,7 @@ Misc: - All: Only update version info if needed - FFmpeg: Encoding cleanup - GB Memory: Initialize RAM pattern for GBC + - GB Video: Improved video timings 0.5.0: (2016-09-19) Features: diff --git a/src/gb/video.c b/src/gb/video.c index a5d154476..21c887086 100644 --- a/src/gb/video.c +++ b/src/gb/video.c @@ -110,7 +110,7 @@ int32_t GBVideoProcessEvents(struct GBVideo* video, int32_t cycles) { 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 @@ int32_t GBVideoProcessEvents(struct GBVideo* video, int32_t cycles) { 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 @@ int32_t GBVideoProcessEvents(struct GBVideo* video, int32_t cycles) { 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); diff --git a/src/gb/video.h b/src/gb/video.h index 05f84c913..1f81d6ee4 100644 --- a/src/gb/video.h +++ b/src/gb/video.h @@ -19,9 +19,9 @@ enum { 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,