Copy DISPSTAT implementation from GBA.js

This commit is contained in:
Jeffrey Pfau 2013-04-16 07:10:38 -07:00
parent e874266343
commit 7de2c91efb
3 changed files with 29 additions and 0 deletions

View File

@ -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 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) {
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;

View File

@ -104,6 +104,24 @@ int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles) {
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);

View File

@ -60,4 +60,7 @@ struct GBAVideo {
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