all repos — mgba @ 5c5be73c473a957af45eff152425e4c0207a0d6d

mGBA Game Boy Advance Emulator

GB MBC: Support for unlicensed Wisdom Tree Game Boy mapper
Vicki Pfau vi@endrift.com
Thu, 04 Jul 2019 17:45:03 -0700
commit

5c5be73c473a957af45eff152425e4c0207a0d6d

parent

916d14cd780a90cd8d712bb7932755c65b555b08

4 files changed, 45 insertions(+), 0 deletions(-)

jump to
M CHANGESCHANGES

@@ -17,6 +17,7 @@ - Ports: Ability to enable or disable all SGB features (closes mgba.io/i/1205)

- Ports: Ability to crop SGB borders off screen (closes mgba.io/i/1204) - Cheats: Add support for loading Libretro-style cht files - GBA Cheats: Add support for loading EZ Flash-style cht files + - Support for unlicensed Wisdom Tree Game Boy mapper Emulation fixes: - GBA: All IRQs have 7 cycle delay (fixes mgba.io/i/539, mgba.io/i/1208) - GBA: Reset now reloads multiboot ROMs
M README.mdREADME.md

@@ -49,6 +49,7 @@ - MBC3+RTC

- MBC5 - MBC5+Rumble - MBC7 +- Wisdom Tree (unlicensed) The following mappers are partially supported:
M include/mgba/gb/interface.hinclude/mgba/gb/interface.h

@@ -34,6 +34,7 @@ GB_HuC1 = 0x11,

GB_HuC3 = 0x12, GB_POCKETCAM = 0x13, GB_TAMA5 = 0x14, + GB_UNL_WISDOM_TREE = 0x20, GB_MBC3_RTC = 0x103, GB_MBC5_RUMBLE = 0x105 };
M src/gb/mbc.csrc/gb/mbc.c

@@ -35,6 +35,7 @@ static void _GBHuC1(struct GB*, uint16_t address, uint8_t value);

static void _GBHuC3(struct GB*, uint16_t address, uint8_t value); static void _GBPocketCam(struct GB* gb, uint16_t address, uint8_t value); static void _GBTAMA5(struct GB* gb, uint16_t address, uint8_t value); +static void _GBWisdomTree(struct GB* gb, uint16_t address, uint8_t value); static uint8_t _GBMBC2Read(struct GBMemory*, uint16_t address); static uint8_t _GBMBC6Read(struct GBMemory*, uint16_t address);

@@ -119,6 +120,24 @@

return success; } +static bool _isWisdomTree(const uint8_t* mem) { + int i; + for (i = 0x134; i < 0x14C; i += 4) { + if (*(uint32_t*) &mem[i] != 0) { + return false; + } + } + for (i = 0xF0; i < 0x100; i += 4) { + if (*(uint32_t*) &mem[i] != 0) { + return false; + } + } + if (mem[0x14D] != 0xE7) { + return false; + } + return true; +} + void GBMBCSwitchSramBank(struct GB* gb, int bank) { size_t bankStart = bank * GB_SIZE_EXTERNAL_RAM; if (bankStart + GB_SIZE_EXTERNAL_RAM > gb->sramSize) {

@@ -180,6 +199,11 @@

if (gb->memory.mbcType == GB_MBC_AUTODETECT) { switch (cart->type) { case 0: + if (_isWisdomTree(gb->memory.rom)) { + gb->memory.mbcType = GB_UNL_WISDOM_TREE; + break; + } + // Fall through case 8: case 9: gb->memory.mbcType = GB_MBC_NONE;

@@ -309,6 +333,9 @@ gb->memory.mbcRead = _GBPocketCamRead;

if (gb->memory.cam && gb->memory.cam->startRequestImage) { gb->memory.cam->startRequestImage(gb->memory.cam, GBCAM_WIDTH, GBCAM_HEIGHT, mCOLOR_ANY); } + break; + case GB_UNL_WISDOM_TREE: + gb->memory.mbcWrite = _GBWisdomTree; break; }

@@ -1164,6 +1191,21 @@ default:

mLOG(GB_MBC, STUB, "TAMA5 unknown read: %02X", tama5->reg); return 0xF1; } + } +} + +void _GBWisdomTree(struct GB* gb, uint16_t address, uint8_t value) { + UNUSED(value); + int bank = address & 0x3F; + switch (address >> 14) { + case 0x0: + GBMBCSwitchBank0(gb, bank * 2); + GBMBCSwitchBank(gb, bank * 2 + 1); + break; + default: + // TODO + mLOG(GB_MBC, STUB, "Wisdom Tree unknown address: %04X:%02X", address, value); + break; } }