mirror of https://github.com/mgba-emu/mgba.git
Copy DISPSTAT implementation from GBA.js
This commit is contained in:
parent
e874266343
commit
7de2c91efb
|
@ -1,7 +1,12 @@
|
||||||
#include "gba-io.h"
|
#include "gba-io.h"
|
||||||
|
|
||||||
|
#include "gba-video.h"
|
||||||
|
|
||||||
void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) {
|
void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) {
|
||||||
switch (address) {
|
switch (address) {
|
||||||
|
case REG_DISPSTAT:
|
||||||
|
GBAVideoWriteDISPSTAT(&gba->video, value);
|
||||||
|
break;
|
||||||
case REG_WAITCNT:
|
case REG_WAITCNT:
|
||||||
GBAAdjustWaitstates(&gba->memory, value);
|
GBAAdjustWaitstates(&gba->memory, value);
|
||||||
break;
|
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) {
|
uint16_t GBAIORead(struct GBA* gba, uint32_t address) {
|
||||||
switch (address) {
|
switch (address) {
|
||||||
|
case REG_DISPSTAT:
|
||||||
|
return GBAVideoReadDISPSTAT(&gba->video);
|
||||||
|
break;
|
||||||
case REG_WAITCNT:
|
case REG_WAITCNT:
|
||||||
// Handled transparently by registers
|
// Handled transparently by registers
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -104,6 +104,24 @@ int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles) {
|
||||||
return video->nextEvent;
|
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) {
|
static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer) {
|
||||||
(void)(renderer);
|
(void)(renderer);
|
||||||
|
|
|
@ -60,4 +60,7 @@ struct GBAVideo {
|
||||||
void GBAVideoInit(struct GBAVideo* video);
|
void GBAVideoInit(struct GBAVideo* video);
|
||||||
int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles);
|
int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles);
|
||||||
|
|
||||||
|
void GBAVideoWriteDISPSTAT(struct GBAVideo* video, uint16_t value);
|
||||||
|
uint16_t GBAVideoReadDISPSTAT(struct GBAVideo* video);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue