Core: Add getPeripheral function

This commit is contained in:
Vicki Pfau 2023-06-01 00:05:41 -07:00
parent 6561223536
commit 294470d940
3 changed files with 31 additions and 0 deletions

View File

@ -120,6 +120,7 @@ struct mCore {
void (*getGameCode)(const struct mCore*, char* title);
void (*setPeripheral)(struct mCore*, int type, void*);
void* (*getPeripheral)(struct mCore*, int type);
uint32_t (*busRead8)(struct mCore*, uint32_t address);
uint32_t (*busRead16)(struct mCore*, uint32_t address);

View File

@ -795,6 +795,20 @@ static void _GBCoreSetPeripheral(struct mCore* core, int type, void* periph) {
}
}
static void* _GBCoreGetPeripheral(struct mCore* core, int type) {
struct GB* gb = core->board;
switch (type) {
case mPERIPH_ROTATION:
return gb->memory.rotation;
case mPERIPH_RUMBLE:
return gb->memory.rumble;
case mPERIPH_IMAGE_SOURCE:
return gb->memory.cam;
default:
return NULL;
}
}
static uint32_t _GBCoreBusRead8(struct mCore* core, uint32_t address) {
struct SM83Core* cpu = core->cpu;
return cpu->memory.load8(cpu, address);
@ -1306,6 +1320,7 @@ struct mCore* GBCoreCreate(void) {
core->getGameTitle = _GBCoreGetGameTitle;
core->getGameCode = _GBCoreGetGameCode;
core->setPeripheral = _GBCoreSetPeripheral;
core->getPeripheral = _GBCoreGetPeripheral;
core->busRead8 = _GBCoreBusRead8;
core->busRead16 = _GBCoreBusRead16;
core->busRead32 = _GBCoreBusRead32;

View File

@ -844,6 +844,20 @@ static void _GBACoreSetPeripheral(struct mCore* core, int type, void* periph) {
}
}
static void* _GBACoreGetPeripheral(struct mCore* core, int type) {
struct GBA* gba = core->board;
switch (type) {
case mPERIPH_ROTATION:
return gba->rotationSource;
case mPERIPH_RUMBLE:
return gba->rumble;
case mPERIPH_GBA_LUMINANCE:
return gba->luminanceSource;
default:
return NULL;
}
}
static uint32_t _GBACoreBusRead8(struct mCore* core, uint32_t address) {
struct ARMCore* cpu = core->cpu;
return cpu->memory.load8(cpu, address, 0);
@ -1431,6 +1445,7 @@ struct mCore* GBACoreCreate(void) {
core->getGameTitle = _GBACoreGetGameTitle;
core->getGameCode = _GBACoreGetGameCode;
core->setPeripheral = _GBACoreSetPeripheral;
core->getPeripheral = _GBACoreGetPeripheral;
core->busRead8 = _GBACoreBusRead8;
core->busRead16 = _GBACoreBusRead16;
core->busRead32 = _GBACoreBusRead32;