all repos — mgba @ 7de2c91efb1e99409f9ab5bec0ae64580c2581e6

mGBA Game Boy Advance Emulator

Copy DISPSTAT implementation from GBA.js
Jeffrey Pfau jeffrey@endrift.com
Tue, 16 Apr 2013 07:10:38 -0700
commit

7de2c91efb1e99409f9ab5bec0ae64580c2581e6

parent

e87426634373936d1c1fbb5755bc5ecf221c682a

3 files changed, 29 insertions(+), 0 deletions(-)

jump to
M src/gba/gba-io.csrc/gba/gba-io.c

@@ -1,7 +1,12 @@

#include "gba-io.h" +#include "gba-video.h" + void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) { switch (address) { + case REG_DISPSTAT: + GBAVideoWriteDISPSTAT(&gba->video, value); + break; case REG_WAITCNT: GBAAdjustWaitstates(&gba->memory, value); break;

@@ -14,6 +19,9 @@ }

uint16_t GBAIORead(struct GBA* gba, uint32_t address) { switch (address) { + case REG_DISPSTAT: + return GBAVideoReadDISPSTAT(&gba->video); + break; case REG_WAITCNT: // Handled transparently by registers break;
M src/gba/gba-video.csrc/gba/gba-video.c

@@ -104,6 +104,24 @@ }

return video->nextEvent; } +void GBAVideoWriteDISPSTAT(struct GBAVideo* video, uint16_t value) { + video->vblankIRQ = value & 0x0008; + video->hblankIRQ = value & 0x0010; + video->vcounterIRQ = value & 0x0020; + video->vcountSetting = (value & 0xFF00) >> 8; + + if (video->vcounterIRQ) { + // FIXME: this can be too late if we're in the middle of an Hblank + video->nextVcounterIRQ = video->nextHblank + VIDEO_HBLANK_LENGTH + (video->vcountSetting - video->vcount) * VIDEO_HORIZONTAL_LENGTH; + if (video->nextVcounterIRQ < video->nextEvent) { + video->nextVcounterIRQ += VIDEO_TOTAL_LENGTH; + } + } +} + +uint16_t GBAVideoReadDISPSTAT(struct GBAVideo* video) { + return (video->inVblank) | (video->inHblank << 1) | (video->vcounter << 2); +} static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer) { (void)(renderer);
M src/gba/gba-video.hsrc/gba/gba-video.h

@@ -60,4 +60,7 @@

void GBAVideoInit(struct GBAVideo* video); int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles); +void GBAVideoWriteDISPSTAT(struct GBAVideo* video, uint16_t value); +uint16_t GBAVideoReadDISPSTAT(struct GBAVideo* video); + #endif