all repos — mgba @ 274a97a5f0908a68a4e072f918b80b3f66aae382

mGBA Game Boy Advance Emulator

Libretro: Add cheevos support for GB/GBC

Working implementation:
https://github.com/libretro/mgba/issues/182#issuecomment-617561652
negativeExponent negativeExponent@users.noreply.github.com
Wed, 22 Apr 2020 15:57:07 +0800
commit

274a97a5f0908a68a4e072f918b80b3f66aae382

parent

0019cb69d8bb7588f7e9e50344e3d4bd2eca2aeb

1 files changed, 96 insertions(+), 0 deletions(-)

jump to
M src/platform/libretro/libretro.csrc/platform/libretro/libretro.c

@@ -435,6 +435,102 @@ environCallback(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &mmaps);

environCallback(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &yes); } #endif +#ifdef M_CORE_GB + if (core->platform(core) == PLATFORM_GB) { + struct GB* gb = core->board; + struct retro_memory_descriptor descs[11]; + struct retro_memory_map mmaps; + + memset(descs, 0, sizeof(descs)); + size_t savedataSize = retro_get_memory_size(RETRO_MEMORY_SAVE_RAM); + + unsigned i = 0; + + /* Map ROM */ + descs[i].ptr = gb->memory.rom; + descs[i].start = GB_BASE_CART_BANK0; + descs[i].len = GB_SIZE_CART_BANK0; + descs[i].flags = RETRO_MEMDESC_CONST; + i++; + + descs[i].ptr = gb->memory.rom; + descs[i].offset = GB_SIZE_CART_BANK0; + descs[i].start = GB_BASE_CART_BANK1; + descs[i].len = GB_SIZE_CART_BANK0; + descs[i].flags = RETRO_MEMDESC_CONST; + i++; + + /* Map VRAM */ + descs[i].ptr = gb->video.vram; + descs[i].start = GB_BASE_VRAM; + descs[i].len = GB_SIZE_VRAM; + i++; + + /* Map working RAM */ + descs[i].ptr = gb->memory.wram; + descs[i].start = GB_BASE_WORKING_RAM_BANK0; + descs[i].len = GB_SIZE_WORKING_RAM_BANK0; + i++; + + descs[i].ptr = gb->memory.wram; + descs[i].offset = GB_SIZE_WORKING_RAM_BANK0; + descs[i].start = GB_BASE_WORKING_RAM_BANK1; + descs[i].len = GB_SIZE_WORKING_RAM_BANK0; + i++; + + /* Map OAM */ + descs[i].ptr = &gb->video.oam; /* video.oam is a structure */ + descs[i].start = GB_BASE_OAM; + descs[i].len = GB_SIZE_OAM; + descs[i].select = 0xFFFFFF60; + i++; + + /* Map mmapped I/O */ + descs[i].ptr = gb->memory.io; + descs[i].start = GB_BASE_IO; + descs[i].len = GB_SIZE_IO; + i++; + + /* Map High RAM */ + descs[i].ptr = gb->memory.hram; + descs[i].start = GB_BASE_HRAM; + descs[i].len = GB_SIZE_HRAM; + descs[i].select = 0xFFFFFF80; + i++; + + /* Map IE Register */ + descs[i].ptr = &gb->memory.ie; + descs[i].start = GB_BASE_IE; + descs[i].len = 1; + i++; + + /* Map External RAM */ + if (savedataSize) { + descs[i].ptr = savedata; + descs[i].start = GB_BASE_EXTERNAL_RAM; + descs[i].len = savedataSize; + i++; + } + + if (gb->model >= GB_MODEL_CGB) { + /* Map working RAM */ + /* banks 2-7 of wram mapped in virtual address so it can be + * accessed without bank switching, GBC only */ + descs[i].ptr = gb->memory.wram + 0x2000; + descs[i].start = 0x10000; + descs[i].len = GB_SIZE_WORKING_RAM - 0x2000; + descs[i].select = 0xFFFFA000; + i++; + } + + mmaps.descriptors = descs; + mmaps.num_descriptors = i; + + bool yes = true; + environCallback(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &mmaps); + environCallback(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &yes); + } +#endif } void retro_reset(void) {