GB: Add preliminary HuC-3 support

This commit is contained in:
Jeffrey Pfau 2016-06-01 02:56:53 -07:00
parent c213ee9bb6
commit 59938208ab
1 changed files with 39 additions and 0 deletions

View File

@ -35,6 +35,7 @@ static void _GBMBC6(struct GBMemory*, uint16_t address, uint8_t value);
static void _GBMBC7(struct GBMemory*, uint16_t address, uint8_t value); static void _GBMBC7(struct GBMemory*, uint16_t address, uint8_t value);
static uint8_t _GBMBC7Read(struct GBMemory*, uint16_t address); static uint8_t _GBMBC7Read(struct GBMemory*, uint16_t address);
static void _GBMBC7Write(struct GBMemory*, uint16_t address, uint8_t value); static void _GBMBC7Write(struct GBMemory*, uint16_t address, uint8_t value);
static void _GBHuC3(struct GBMemory*, uint16_t address, uint8_t value);
static uint8_t GBFastLoad8(struct LR35902Core* cpu, uint16_t address) { static uint8_t GBFastLoad8(struct LR35902Core* cpu, uint16_t address) {
if (UNLIKELY(address > cpu->memory.activeRegionEnd)) { if (UNLIKELY(address > cpu->memory.activeRegionEnd)) {
@ -188,6 +189,10 @@ void GBMemoryReset(struct GB* gb) {
gb->memory.mbc = _GBMBC7; gb->memory.mbc = _GBMBC7;
gb->memory.mbcType = GB_MBC7; gb->memory.mbcType = GB_MBC7;
break; break;
case 0xFE:
gb->memory.mbc = _GBHuC3;
gb->memory.mbcType = GB_HuC3;
break;
} }
if (!gb->memory.wram) { if (!gb->memory.wram) {
@ -229,6 +234,8 @@ uint8_t GBLoad8(struct LR35902Core* cpu, uint16_t address) {
return gb->memory.sramBank[address & (GB_SIZE_EXTERNAL_RAM - 1)]; return gb->memory.sramBank[address & (GB_SIZE_EXTERNAL_RAM - 1)];
} else if (memory->mbcType == GB_MBC7) { } else if (memory->mbcType == GB_MBC7) {
return _GBMBC7Read(memory, address); return _GBMBC7Read(memory, address);
} else if (memory->mbcType == GB_HuC3) {
return 0x01; // TODO: Is this supposed to be the current SRAM bank?
} }
return 0xFF; return 0xFF;
case GB_REGION_WORKING_RAM_BANK0: case GB_REGION_WORKING_RAM_BANK0:
@ -933,6 +940,38 @@ void _GBMBC7Write(struct GBMemory* memory, uint16_t address, uint8_t value) {
} }
} }
void _GBHuC3(struct GBMemory* memory, uint16_t address, uint8_t value) {
int bank = value & 0x3F;
if (address & 0x1FFF) {
mLOG(GB_MBC, STUB, "HuC-3 unknown value %04X:%02X", address, value);
}
switch (address >> 13) {
case 0x0:
switch (value) {
case 0xA:
memory->sramAccess = true;
_switchSramBank(memory, memory->sramCurrentBank);
break;
default:
memory->sramAccess = false;
break;
}
break;
case 0x1:
mLOG(GB_MBC, STUB, "Bank switch %02X", value);
_switchBank(memory, bank);
break;
case 0x2:
_switchSramBank(memory, bank);
break;
default:
// TODO
mLOG(GB_MBC, STUB, "HuC-3 unknown address: %04X:%02X", address, value);
break;
}
}
void GBMemorySerialize(const struct GBMemory* memory, struct GBSerializedState* state) { void GBMemorySerialize(const struct GBMemory* memory, struct GBSerializedState* state) {
memcpy(state->wram, memory->wram, GB_SIZE_WORKING_RAM); memcpy(state->wram, memory->wram, GB_SIZE_WORKING_RAM);
memcpy(state->hram, memory->hram, GB_SIZE_HRAM); memcpy(state->hram, memory->hram, GB_SIZE_HRAM);