all repos — mgba @ 7539742689990be0687f82b19d3bc9b312ed528d

mGBA Game Boy Advance Emulator

GB Video: Fix timing for vblank IRQs
Jeffrey Pfau jeffrey@endrift.com
Sat, 16 Apr 2016 10:39:35 -0700
commit

7539742689990be0687f82b19d3bc9b312ed528d

parent

4d839d03b46918ae0db7cc7f0c7f04e8e6f2c62a

1 files changed, 14 insertions(+), 8 deletions(-)

jump to
M src/gb/video.csrc/gb/video.c

@@ -143,29 +143,35 @@ break;

case 1: // TODO: One M-cycle delay ++video->ly; - video->stat = GBRegisterSTATSetLYC(video->stat, lyc == video->ly); - if (video->ly == GB_VIDEO_VERTICAL_TOTAL_PIXELS) { + 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; video->mode = 2; if (GBRegisterSTATIsOAMIRQ(video->stat)) { video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); + GBUpdateIRQs(video->p); } - } else { - video->nextMode = GB_VIDEO_HORIZONTAL_LENGTH; - } - if (video->ly == GB_VIDEO_VERTICAL_TOTAL_PIXELS - 1) { + break; + } else if (video->ly == GB_VIDEO_VERTICAL_TOTAL_PIXELS) { video->p->memory.io[REG_LY] = 0; + video->nextMode = GB_VIDEO_HORIZONTAL_LENGTH - 8; + } else if (video->ly == GB_VIDEO_VERTICAL_TOTAL_PIXELS - 1) { + video->p->memory.io[REG_LY] = video->ly; + video->nextMode = 8; } else { video->p->memory.io[REG_LY] = video->ly; + video->nextMode = GB_VIDEO_HORIZONTAL_LENGTH; } - if (GBRegisterSTATIsLYCIRQ(video->stat) && lyc == video->ly) { + + video->stat = GBRegisterSTATSetLYC(video->stat, lyc == video->p->memory.io[REG_LY]); + if (GBRegisterSTATIsLYCIRQ(video->stat) && lyc == video->p->memory.io[REG_LY]) { video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); + GBUpdateIRQs(video->p); } if (video->p->memory.mbcType == GB_MBC7 && video->p->memory.rotation && video->p->memory.rotation->sample) { video->p->memory.rotation->sample(video->p->memory.rotation); } - GBUpdateIRQs(video->p); break; case 2: _cleanOAM(video, video->ly);