From abece0b1697f06cab39d8f9af6ca3f7479045fe8 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Sun, 8 May 2016 23:22:22 -0300 Subject: [PATCH] added a spetacular hack to support cheevos --- libgambatte/include/gambatte.h | 4 ++++ libgambatte/libretro/libretro.cpp | 13 +++++++++++++ libgambatte/src/gambatte.cpp | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/libgambatte/include/gambatte.h b/libgambatte/include/gambatte.h index 1f85e42..068401c 100644 --- a/libgambatte/include/gambatte.h +++ b/libgambatte/include/gambatte.h @@ -114,6 +114,10 @@ public: void setGameShark(const std::string &codes); void clearCheats(); + +#ifdef __LIBRETRO__ + unsigned char read(unsigned p) const; +#endif private: struct Priv; diff --git a/libgambatte/libretro/libretro.cpp b/libgambatte/libretro/libretro.cpp index 23a87f1..0298a5c 100644 --- a/libgambatte/libretro/libretro.cpp +++ b/libgambatte/libretro/libretro.cpp @@ -545,6 +545,8 @@ unsigned retro_get_region() { return RETRO_REGION_NTSC; } void *retro_get_memory_data(unsigned id) { + static uint8_t bytes[4]; + switch (id) { case RETRO_MEMORY_SAVE_RAM: @@ -557,6 +559,17 @@ void *retro_get_memory_data(unsigned id) * realizing that that memchunk hack is ugly, or * otherwise getting rearranged. */ return (char*)gb.savedata_ptr() + gb.savedata_size(); + default: + /* An even uglier hack, since we pass an invalid memory + * id to read directly from the emulated memory. This is + * done so because both retro_get_memory_data and + * RETRO_ENVIRONMENT_SET_MEMORY_MAPS are too restrictive + * to implement what the cheevos module needs. */ + bytes[0] = gb.read(id); + bytes[1] = gb.read(id + 1); + bytes[2] = gb.read(id + 2); + bytes[3] = gb.read(id + 3); + return bytes; } return 0; diff --git a/libgambatte/src/gambatte.cpp b/libgambatte/src/gambatte.cpp index 80c4899..fc75db3 100644 --- a/libgambatte/src/gambatte.cpp +++ b/libgambatte/src/gambatte.cpp @@ -142,5 +142,11 @@ void GB::clearCheats() { p_->cpu.clearCheats(); } +#ifdef __LIBRETRO__ +unsigned char GB::read(unsigned p) const { + return p_->cpu.mem_.read(p, 0); +} +#endif + }