Unified DISPSTAT representation

This commit is contained in:
Jeffrey Pfau 2014-01-20 14:18:24 -08:00
parent 5a1a04a353
commit 35a5e83465
2 changed files with 25 additions and 32 deletions

View File

@ -132,10 +132,12 @@ int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles) {
} }
void GBAVideoWriteDISPSTAT(struct GBAVideo* video, uint16_t value) { void GBAVideoWriteDISPSTAT(struct GBAVideo* video, uint16_t value) {
video->vblankIRQ = value & 0x0008; union GBARegisterDISPSTAT dispstat;
video->hblankIRQ = value & 0x0010; dispstat.packed = value;
video->vcounterIRQ = value & 0x0020; video->vblankIRQ = dispstat.vblankIRQ;
video->vcountSetting = (value & 0xFF00) >> 8; video->hblankIRQ = dispstat.hblankIRQ;
video->vcounterIRQ = dispstat.vcounterIRQ;
video->vcountSetting = dispstat.vcountSetting;
if (video->vcounterIRQ) { if (video->vcounterIRQ) {
// FIXME: this can be too late if we're in the middle of an Hblank // FIXME: this can be too late if we're in the middle of an Hblank
@ -181,26 +183,14 @@ void GBAVideoSerialize(struct GBAVideo* video, struct GBASerializedState* state)
memcpy(state->vram, video->renderer->vram, SIZE_VRAM); memcpy(state->vram, video->renderer->vram, SIZE_VRAM);
memcpy(state->oam, video->oam.raw, SIZE_OAM); memcpy(state->oam, video->oam.raw, SIZE_OAM);
memcpy(state->pram, video->palette, SIZE_PALETTE_RAM); memcpy(state->pram, video->palette, SIZE_PALETTE_RAM);
union { union GBARegisterDISPSTAT dispstat;
struct {
unsigned inVblank : 1;
unsigned inHblank : 1;
unsigned vcounter : 1;
unsigned vblankIRQ : 1;
unsigned hblankIRQ : 1;
unsigned vcounterIRQ : 1;
unsigned : 2;
unsigned vcount : 1;
};
uint32_t packed;
} dispstat;
dispstat.inVblank = video->inVblank; dispstat.inVblank = video->inVblank;
dispstat.inHblank = video->inHblank; dispstat.inHblank = video->inHblank;
dispstat.vcounter = video->vcounter; dispstat.vcounter = video->vcounter;
dispstat.vblankIRQ = video->vblankIRQ; dispstat.vblankIRQ = video->vblankIRQ;
dispstat.hblankIRQ = video->hblankIRQ; dispstat.hblankIRQ = video->hblankIRQ;
dispstat.vcounterIRQ = video->vcounterIRQ; dispstat.vcounterIRQ = video->vcounterIRQ;
dispstat.vcount = video->vcount; dispstat.vcountSetting = video->vcountSetting;
state->io[REG_DISPSTAT >> 1] = dispstat.packed; state->io[REG_DISPSTAT >> 1] = dispstat.packed;
state->video.nextEvent = video->nextEvent; state->video.nextEvent = video->nextEvent;
state->video.eventDiff = video->eventDiff; state->video.eventDiff = video->eventDiff;
@ -218,19 +208,7 @@ void GBAVideoDeserialize(struct GBAVideo* video, struct GBASerializedState* stat
for (i = 0; i < SIZE_PALETTE_RAM; i += 2) { for (i = 0; i < SIZE_PALETTE_RAM; i += 2) {
GBAStore16(&video->p->memory.d, BASE_PALETTE_RAM | i, state->pram[i >> 1], 0); GBAStore16(&video->p->memory.d, BASE_PALETTE_RAM | i, state->pram[i >> 1], 0);
} }
union { union GBARegisterDISPSTAT dispstat;
struct {
unsigned inVblank : 1;
unsigned inHblank : 1;
unsigned vcounter : 1;
unsigned vblankIRQ : 1;
unsigned hblankIRQ : 1;
unsigned vcounterIRQ : 1;
unsigned : 2;
unsigned vcount : 1;
};
uint32_t packed;
} dispstat;
dispstat.packed = state->io[REG_DISPSTAT >> 1]; dispstat.packed = state->io[REG_DISPSTAT >> 1];
video->inVblank = dispstat.inVblank; video->inVblank = dispstat.inVblank;
video->inHblank = dispstat.inHblank; video->inHblank = dispstat.inHblank;
@ -238,7 +216,7 @@ void GBAVideoDeserialize(struct GBAVideo* video, struct GBASerializedState* stat
video->vblankIRQ = dispstat.vblankIRQ; video->vblankIRQ = dispstat.vblankIRQ;
video->hblankIRQ = dispstat.hblankIRQ; video->hblankIRQ = dispstat.hblankIRQ;
video->vcounterIRQ = dispstat.vcounterIRQ; video->vcounterIRQ = dispstat.vcounterIRQ;
video->vcount = dispstat.vcount; video->vcountSetting = dispstat.vcountSetting;
video->nextEvent = state->video.nextEvent; video->nextEvent = state->video.nextEvent;
video->eventDiff = state->video.eventDiff; video->eventDiff = state->video.eventDiff;
video->lastHblank = state->video.lastHblank; video->lastHblank = state->video.lastHblank;
@ -246,4 +224,5 @@ void GBAVideoDeserialize(struct GBAVideo* video, struct GBASerializedState* stat
video->nextHblankIRQ = state->video.nextHblankIRQ; video->nextHblankIRQ = state->video.nextHblankIRQ;
video->nextVblankIRQ = state->video.nextVblankIRQ; video->nextVblankIRQ = state->video.nextVblankIRQ;
video->nextVcounterIRQ = state->video.nextVcounterIRQ; video->nextVcounterIRQ = state->video.nextVcounterIRQ;
video->vcount = state->io[REG_VCOUNT >> 1];
} }

View File

@ -136,6 +136,20 @@ union GBARegisterDISPCNT {
uint16_t packed; uint16_t packed;
}; };
union GBARegisterDISPSTAT {
struct {
unsigned inVblank : 1;
unsigned inHblank : 1;
unsigned vcounter : 1;
unsigned vblankIRQ : 1;
unsigned hblankIRQ : 1;
unsigned vcounterIRQ : 1;
unsigned : 2;
unsigned vcountSetting : 8;
};
uint32_t packed;
};
union GBARegisterBGCNT { union GBARegisterBGCNT {
struct { struct {
unsigned priority : 2; unsigned priority : 2;