GBA: Overdue constant prefixing

This commit is contained in:
Vicki Pfau 2022-05-28 20:58:57 -07:00
parent c8978fd425
commit 38299f397f
13 changed files with 43 additions and 44 deletions

View File

@ -27,7 +27,6 @@ extern const uint32_t SGB_SM83_FREQUENCY;
mLOG_DECLARE_CATEGORY(GB); mLOG_DECLARE_CATEGORY(GB);
// TODO: Prefix GBAIRQ
enum GBIRQ { enum GBIRQ {
GB_IRQ_VBLANK = 0x0, GB_IRQ_VBLANK = 0x0,
GB_IRQ_LCDSTAT = 0x1, GB_IRQ_LCDSTAT = 0x1,

View File

@ -22,20 +22,20 @@ CXX_GUARD_START
#define GBA_ARM7TDMI_FREQUENCY 0x1000000U #define GBA_ARM7TDMI_FREQUENCY 0x1000000U
enum GBAIRQ { enum GBAIRQ {
IRQ_VBLANK = 0x0, GBA_IRQ_VBLANK = 0x0,
IRQ_HBLANK = 0x1, GBA_IRQ_HBLANK = 0x1,
IRQ_VCOUNTER = 0x2, GBA_IRQ_VCOUNTER = 0x2,
IRQ_TIMER0 = 0x3, GBA_IRQ_TIMER0 = 0x3,
IRQ_TIMER1 = 0x4, GBA_IRQ_TIMER1 = 0x4,
IRQ_TIMER2 = 0x5, GBA_IRQ_TIMER2 = 0x5,
IRQ_TIMER3 = 0x6, GBA_IRQ_TIMER3 = 0x6,
IRQ_SIO = 0x7, GBA_IRQ_SIO = 0x7,
IRQ_DMA0 = 0x8, GBA_IRQ_DMA0 = 0x8,
IRQ_DMA1 = 0x9, GBA_IRQ_DMA1 = 0x9,
IRQ_DMA2 = 0xA, GBA_IRQ_DMA2 = 0xA,
IRQ_DMA3 = 0xB, GBA_IRQ_DMA3 = 0xB,
IRQ_KEYPAD = 0xC, GBA_IRQ_KEYPAD = 0xC,
IRQ_GAMEPAK = 0xD GBA_IRQ_GAMEPAK = 0xD
}; };
enum GBAIdleLoopOptimization { enum GBAIdleLoopOptimization {
@ -45,9 +45,9 @@ enum GBAIdleLoopOptimization {
}; };
enum { enum {
SP_BASE_SYSTEM = 0x03007F00, GBA_SP_BASE_SYSTEM = 0x03007F00,
SP_BASE_IRQ = 0x03007FA0, GBA_SP_BASE_IRQ = 0x03007FA0,
SP_BASE_SUPERVISOR = 0x03007FE0 GBA_SP_BASE_SUPERVISOR = 0x03007FE0
}; };
struct ARMCore; struct ARMCore;

View File

@ -40,14 +40,14 @@ static void _SoftReset(struct GBA* gba) {
ARMSetPrivilegeMode(cpu, MODE_IRQ); ARMSetPrivilegeMode(cpu, MODE_IRQ);
cpu->spsr.packed = 0; cpu->spsr.packed = 0;
cpu->gprs[ARM_LR] = 0; cpu->gprs[ARM_LR] = 0;
cpu->gprs[ARM_SP] = SP_BASE_IRQ; cpu->gprs[ARM_SP] = GBA_SP_BASE_IRQ;
ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR); ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR);
cpu->spsr.packed = 0; cpu->spsr.packed = 0;
cpu->gprs[ARM_LR] = 0; cpu->gprs[ARM_LR] = 0;
cpu->gprs[ARM_SP] = SP_BASE_SUPERVISOR; cpu->gprs[ARM_SP] = GBA_SP_BASE_SUPERVISOR;
ARMSetPrivilegeMode(cpu, MODE_SYSTEM); ARMSetPrivilegeMode(cpu, MODE_SYSTEM);
cpu->gprs[ARM_LR] = 0; cpu->gprs[ARM_LR] = 0;
cpu->gprs[ARM_SP] = SP_BASE_SYSTEM; cpu->gprs[ARM_SP] = GBA_SP_BASE_SYSTEM;
int8_t flag = ((int8_t*) gba->memory.iwram)[0x7FFA]; int8_t flag = ((int8_t*) gba->memory.iwram)[0x7FFA];
memset(((int8_t*) gba->memory.iwram) + SIZE_WORKING_IRAM - 0x200, 0, 0x200); memset(((int8_t*) gba->memory.iwram) + SIZE_WORKING_IRAM - 0x200, 0, 0x200);
if (flag) { if (flag) {

View File

@ -718,7 +718,7 @@ void _eReaderReadData(struct GBACartEReader* ereader) {
if (led > 0x4000) { if (led > 0x4000) {
led = 0x4000; led = 0x4000;
} }
GBARaiseIRQ(ereader->p, IRQ_GAMEPAK, -led); GBARaiseIRQ(ereader->p, GBA_IRQ_GAMEPAK, -led);
} }
} }

View File

@ -208,7 +208,7 @@ void _dmaEvent(struct mTiming* timing, void* context, uint32_t cyclesLate) {
dma->nextDest = dma->dest; dma->nextDest = dma->dest;
} }
if (GBADMARegisterIsDoIRQ(dma->reg)) { if (GBADMARegisterIsDoIRQ(dma->reg)) {
GBARaiseIRQ(gba, IRQ_DMA0 + memory->activeDMA, cyclesLate); GBARaiseIRQ(gba, GBA_IRQ_DMA0 + memory->activeDMA, cyclesLate);
} }
GBADMAUpdate(gba); GBADMAUpdate(gba);
} }

View File

@ -102,7 +102,7 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle
gate->d.p->p->memory.io[REG_SIODATA32_HI >> 1] = 0; gate->d.p->p->memory.io[REG_SIODATA32_HI >> 1] = 0;
gate->d.p->siocnt = GBASIONormalClearStart(gate->d.p->siocnt); gate->d.p->siocnt = GBASIONormalClearStart(gate->d.p->siocnt);
if (GBASIONormalIsIrq(gate->d.p->siocnt)) { if (GBASIONormalIsIrq(gate->d.p->siocnt)) {
GBARaiseIRQ(gate->d.p->p, IRQ_SIO, cyclesLate); GBARaiseIRQ(gate->d.p->p, GBA_IRQ_SIO, cyclesLate);
} }
return; return;
} }
@ -194,6 +194,6 @@ void _battlechipTransferEvent(struct mTiming* timing, void* user, uint32_t cycle
gate->d.p->p->memory.io[REG_SIOMULTI1 >> 1] = reply; gate->d.p->p->memory.io[REG_SIOMULTI1 >> 1] = reply;
if (GBASIOMultiplayerIsIrq(gate->d.p->siocnt)) { if (GBASIOMultiplayerIsIrq(gate->d.p->siocnt)) {
GBARaiseIRQ(gate->d.p->p, IRQ_SIO, cyclesLate); GBARaiseIRQ(gate->d.p->p, GBA_IRQ_SIO, cyclesLate);
} }
} }

View File

@ -198,11 +198,11 @@ void GBAInterruptHandlerInit(struct ARMInterruptHandler* irqh) {
void GBAReset(struct ARMCore* cpu) { void GBAReset(struct ARMCore* cpu) {
ARMSetPrivilegeMode(cpu, MODE_IRQ); ARMSetPrivilegeMode(cpu, MODE_IRQ);
cpu->gprs[ARM_SP] = SP_BASE_IRQ; cpu->gprs[ARM_SP] = GBA_SP_BASE_IRQ;
ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR); ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR);
cpu->gprs[ARM_SP] = SP_BASE_SUPERVISOR; cpu->gprs[ARM_SP] = GBA_SP_BASE_SUPERVISOR;
ARMSetPrivilegeMode(cpu, MODE_SYSTEM); ARMSetPrivilegeMode(cpu, MODE_SYSTEM);
cpu->gprs[ARM_SP] = SP_BASE_SYSTEM; cpu->gprs[ARM_SP] = GBA_SP_BASE_SYSTEM;
struct GBA* gba = (struct GBA*) cpu->master; struct GBA* gba = (struct GBA*) cpu->master;
gba->memory.savedata.maskWriteback = false; gba->memory.savedata.maskWriteback = false;
@ -465,7 +465,7 @@ void GBAYankROM(struct GBA* gba) {
gba->yankedRomSize = gba->memory.romSize; gba->yankedRomSize = gba->memory.romSize;
gba->memory.romSize = 0; gba->memory.romSize = 0;
gba->memory.romMask = 0; gba->memory.romMask = 0;
GBARaiseIRQ(gba, IRQ_GAMEPAK, 0); GBARaiseIRQ(gba, GBA_IRQ_GAMEPAK, 0);
} }
void GBALoadBIOS(struct GBA* gba, struct VFile* vf) { void GBALoadBIOS(struct GBA* gba, struct VFile* vf) {
@ -554,7 +554,7 @@ void GBAHalt(struct GBA* gba) {
} }
void GBAStop(struct GBA* gba) { void GBAStop(struct GBA* gba) {
int validIrqs = (1 << IRQ_GAMEPAK) | (1 << IRQ_KEYPAD) | (1 << IRQ_SIO); int validIrqs = (1 << GBA_IRQ_GAMEPAK) | (1 << GBA_IRQ_KEYPAD) | (1 << GBA_IRQ_SIO);
int sleep = gba->memory.io[REG_IE >> 1] & validIrqs; int sleep = gba->memory.io[REG_IE >> 1] & validIrqs;
size_t c; size_t c;
for (c = 0; c < mCoreCallbacksListSize(&gba->coreCallbacks); ++c) { for (c = 0; c < mCoreCallbacksListSize(&gba->coreCallbacks); ++c) {
@ -921,9 +921,9 @@ void GBATestKeypadIRQ(struct GBA* gba) {
if (keysLast == keysActive) { if (keysLast == keysActive) {
return; return;
} }
GBARaiseIRQ(gba, IRQ_KEYPAD, 0); GBARaiseIRQ(gba, GBA_IRQ_KEYPAD, 0);
} else if (!isAnd && (keysActive & keycnt)) { } else if (!isAnd && (keysActive & keycnt)) {
GBARaiseIRQ(gba, IRQ_KEYPAD, 0); GBARaiseIRQ(gba, GBA_IRQ_KEYPAD, 0);
} else { } else {
gba->keysLast = 0x400; gba->keysLast = 0x400;
} }

View File

@ -188,7 +188,7 @@ void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value) {
if ((value & 0x0081) == 0x0081) { if ((value & 0x0081) == 0x0081) {
if (value & 0x4000) { if (value & 0x4000) {
// TODO: Test this on hardware to see if this is correct // TODO: Test this on hardware to see if this is correct
GBARaiseIRQ(sio->p, IRQ_SIO, 0); GBARaiseIRQ(sio->p, GBA_IRQ_SIO, 0);
} }
value &= ~0x0080; value &= ~0x0080;
} }

View File

@ -141,7 +141,7 @@ void _gbpSioProcessEvents(struct mTiming* timing, void* user, uint32_t cyclesLat
gbp->p->memory.io[REG_SIODATA32_LO >> 1] = tx; gbp->p->memory.io[REG_SIODATA32_LO >> 1] = tx;
gbp->p->memory.io[REG_SIODATA32_HI >> 1] = tx >> 16; gbp->p->memory.io[REG_SIODATA32_HI >> 1] = tx >> 16;
if (GBASIONormalIsIrq(gbp->d.p->siocnt)) { if (GBASIONormalIsIrq(gbp->d.p->siocnt)) {
GBARaiseIRQ(gbp->p, IRQ_SIO, cyclesLate); GBARaiseIRQ(gbp->p, GBA_IRQ_SIO, cyclesLate);
} }
gbp->d.p->siocnt = GBASIONormalClearStart(gbp->d.p->siocnt); gbp->d.p->siocnt = GBASIONormalClearStart(gbp->d.p->siocnt);
gbp->p->memory.io[REG_SIOCNT >> 1] = gbp->d.p->siocnt & ~0x0080; gbp->p->memory.io[REG_SIOCNT >> 1] = gbp->d.p->siocnt & ~0x0080;

View File

@ -46,7 +46,7 @@ int GBASIOJOYSendCommand(struct GBASIODriver* sio, enum GBASIOJOYCommand command
case JOY_RESET: case JOY_RESET:
sio->p->p->memory.io[REG_JOYCNT >> 1] |= JOYCNT_RESET; sio->p->p->memory.io[REG_JOYCNT >> 1] |= JOYCNT_RESET;
if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) { if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) {
GBARaiseIRQ(sio->p->p, IRQ_SIO, 0); GBARaiseIRQ(sio->p->p, GBA_IRQ_SIO, 0);
} }
// Fall through // Fall through
case JOY_POLL: case JOY_POLL:
@ -68,7 +68,7 @@ int GBASIOJOYSendCommand(struct GBASIODriver* sio, enum GBASIOJOYCommand command
mLOG(GBA_SIO, DEBUG, "JOY recv: %02X (%02X)", data[0], sio->p->p->memory.io[REG_JOYCNT >> 1]); mLOG(GBA_SIO, DEBUG, "JOY recv: %02X (%02X)", data[0], sio->p->p->memory.io[REG_JOYCNT >> 1]);
if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) { if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) {
GBARaiseIRQ(sio->p->p, IRQ_SIO, 0); GBARaiseIRQ(sio->p->p, GBA_IRQ_SIO, 0);
} }
return 1; return 1;
case JOY_TRANS: case JOY_TRANS:
@ -84,7 +84,7 @@ int GBASIOJOYSendCommand(struct GBASIODriver* sio, enum GBASIOJOYCommand command
mLOG(GBA_SIO, DEBUG, "JOY trans: %02X%02X%02X%02X:%02X (%02X)", data[0], data[1], data[2], data[3], data[4], sio->p->p->memory.io[REG_JOYCNT >> 1]); mLOG(GBA_SIO, DEBUG, "JOY trans: %02X%02X%02X%02X:%02X (%02X)", data[0], data[1], data[2], data[3], data[4], sio->p->p->memory.io[REG_JOYCNT >> 1]);
if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) { if (sio->p->p->memory.io[REG_JOYCNT >> 1] & 0x40) {
GBARaiseIRQ(sio->p->p, IRQ_SIO, 0); GBARaiseIRQ(sio->p->p, GBA_IRQ_SIO, 0);
} }
return 5; return 5;
} }

View File

@ -230,7 +230,7 @@ static void _finishTransfer(struct GBASIOLockstepNode* node) {
sio->siocnt = GBASIOMultiplayerClearBusy(sio->siocnt); sio->siocnt = GBASIOMultiplayerClearBusy(sio->siocnt);
sio->siocnt = GBASIOMultiplayerSetId(sio->siocnt, node->id); sio->siocnt = GBASIOMultiplayerSetId(sio->siocnt, node->id);
if (GBASIOMultiplayerIsIrq(sio->siocnt)) { if (GBASIOMultiplayerIsIrq(sio->siocnt)) {
GBARaiseIRQ(sio->p, IRQ_SIO, 0); GBARaiseIRQ(sio->p, GBA_IRQ_SIO, 0);
} }
break; break;
case SIO_NORMAL_8: case SIO_NORMAL_8:
@ -243,7 +243,7 @@ static void _finishTransfer(struct GBASIOLockstepNode* node) {
node->d.p->p->memory.io[REG_SIODATA8 >> 1] = 0xFFFF; node->d.p->p->memory.io[REG_SIODATA8 >> 1] = 0xFFFF;
} }
if (GBASIONormalIsIrq(sio->siocnt)) { if (GBASIONormalIsIrq(sio->siocnt)) {
GBARaiseIRQ(sio->p, IRQ_SIO, 0); GBARaiseIRQ(sio->p, GBA_IRQ_SIO, 0);
} }
break; break;
case SIO_NORMAL_32: case SIO_NORMAL_32:
@ -258,7 +258,7 @@ static void _finishTransfer(struct GBASIOLockstepNode* node) {
node->d.p->p->memory.io[REG_SIODATA32_HI >> 1] = 0xFFFF; node->d.p->p->memory.io[REG_SIODATA32_HI >> 1] = 0xFFFF;
} }
if (GBASIONormalIsIrq(sio->siocnt)) { if (GBASIONormalIsIrq(sio->siocnt)) {
GBARaiseIRQ(sio->p, IRQ_SIO, 0); GBARaiseIRQ(sio->p, GBA_IRQ_SIO, 0);
} }
break; break;
default: default:

View File

@ -19,7 +19,7 @@ static void GBATimerUpdate(struct GBA* gba, int timerId, uint32_t cyclesLate) {
} }
if (GBATimerFlagsIsDoIrq(timer->flags)) { if (GBATimerFlagsIsDoIrq(timer->flags)) {
GBARaiseIRQ(gba, IRQ_TIMER0 + timerId, cyclesLate); GBARaiseIRQ(gba, GBA_IRQ_TIMER0 + timerId, cyclesLate);
} }
if (gba->audio.enable && timerId < 2) { if (gba->audio.enable && timerId < 2) {

View File

@ -157,7 +157,7 @@ void _startHdraw(struct mTiming* timing, void* context, uint32_t cyclesLate) {
if (video->vcount == GBARegisterDISPSTATGetVcountSetting(dispstat)) { if (video->vcount == GBARegisterDISPSTATGetVcountSetting(dispstat)) {
dispstat = GBARegisterDISPSTATFillVcounter(dispstat); dispstat = GBARegisterDISPSTATFillVcounter(dispstat);
if (GBARegisterDISPSTATIsVcounterIRQ(dispstat)) { if (GBARegisterDISPSTATIsVcounterIRQ(dispstat)) {
GBARaiseIRQ(video->p, IRQ_VCOUNTER, cyclesLate); GBARaiseIRQ(video->p, GBA_IRQ_VCOUNTER, cyclesLate);
} }
} else { } else {
dispstat = GBARegisterDISPSTATClearVcounter(dispstat); dispstat = GBARegisterDISPSTATClearVcounter(dispstat);
@ -176,7 +176,7 @@ void _startHdraw(struct mTiming* timing, void* context, uint32_t cyclesLate) {
} }
GBADMARunVblank(video->p, -cyclesLate); GBADMARunVblank(video->p, -cyclesLate);
if (GBARegisterDISPSTATIsVblankIRQ(dispstat)) { if (GBARegisterDISPSTATIsVblankIRQ(dispstat)) {
GBARaiseIRQ(video->p, IRQ_VBLANK, cyclesLate); GBARaiseIRQ(video->p, GBA_IRQ_VBLANK, cyclesLate);
} }
GBAFrameEnded(video->p); GBAFrameEnded(video->p);
mCoreSyncPostFrame(video->p->sync); mCoreSyncPostFrame(video->p->sync);
@ -212,7 +212,7 @@ void _startHblank(struct mTiming* timing, void* context, uint32_t cyclesLate) {
GBADMARunDisplayStart(video->p, -cyclesLate); GBADMARunDisplayStart(video->p, -cyclesLate);
} }
if (GBARegisterDISPSTATIsHblankIRQ(dispstat)) { if (GBARegisterDISPSTATIsHblankIRQ(dispstat)) {
GBARaiseIRQ(video->p, IRQ_HBLANK, cyclesLate - 6); // TODO: Where does this fudge factor come from? GBARaiseIRQ(video->p, GBA_IRQ_HBLANK, cyclesLate - 6); // TODO: Where does this fudge factor come from?
} }
video->shouldStall = 0; video->shouldStall = 0;
video->p->memory.io[REG_DISPSTAT >> 1] = dispstat; video->p->memory.io[REG_DISPSTAT >> 1] = dispstat;