From 546688f9fb9ea87589d786cdf7a909a34be0c904 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 12 Aug 2017 14:12:49 -0700 Subject: [PATCH] GB Memory: Fix HDMA count starting in mode 0 (fixes #855) --- CHANGES | 1 + src/gb/memory.c | 7 +++++-- src/gb/video.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index bd68c106f..370e58f98 100644 --- a/CHANGES +++ b/CHANGES @@ -31,6 +31,7 @@ Bugfixes: - Qt: Fix sprite export pausing game indefinitely (fixes mgba.io/i/841) - ARM: Fix MSR when T bit is set - GB Video: Fix potential hang when ending mode 0 + - GB Memory: Fix HDMA count starting in mode 0 (fixes mgba.io/i/855) Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722) diff --git a/src/gb/memory.c b/src/gb/memory.c index 5e0574b2f..362c4b244 100644 --- a/src/gb/memory.c +++ b/src/gb/memory.c @@ -469,10 +469,13 @@ void GBMemoryWriteHDMA5(struct GB* gb, uint8_t value) { bool wasHdma = gb->memory.isHdma; gb->memory.isHdma = value & 0x80; if ((!wasHdma && !gb->memory.isHdma) || gb->video.mode == 0) { - gb->memory.hdmaRemaining = ((value & 0x7F) + 1) * 0x10; + if (gb->memory.isHdma) { + gb->memory.hdmaRemaining = 0x10; + } else { + gb->memory.hdmaRemaining = ((value & 0x7F) + 1) * 0x10; + } gb->cpuBlocked = true; mTimingSchedule(&gb->timing, &gb->memory.hdmaEvent, 0); - gb->cpu->nextEvent = gb->cpu->cycles; } } diff --git a/src/gb/video.c b/src/gb/video.c index 5ed2ab641..5810be63e 100644 --- a/src/gb/video.c +++ b/src/gb/video.c @@ -304,6 +304,7 @@ void _endMode3(struct mTiming* timing, void* context, uint32_t cyclesLate) { GBVideoProcessDots(video); if (video->ly < GB_VIDEO_VERTICAL_PIXELS && video->p->memory.isHdma && video->p->memory.io[REG_HDMA5] != 0xFF) { video->p->memory.hdmaRemaining = 0x10; + video->p->cpuBlocked = true; mTimingDeschedule(timing, &video->p->memory.hdmaEvent); mTimingSchedule(timing, &video->p->memory.hdmaEvent, 0); }