GBA Hardware: Add a function for detecting a GB Player-compatible game
Jeffrey Pfau jeffrey@endrift.com
Sun, 28 Jun 2015 23:50:17 -0700
2 files changed,
27 insertions(+),
0 deletions(-)
M
src/gba/hardware.c
→
src/gba/hardware.c
@@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "hardware.h" #include "gba/serialize.h" +#include "util/hash.h" static void _readPins(struct GBACartridgeHardware* hw); static void _outputPins(struct GBACartridgeHardware* hw, unsigned pins);@@ -418,6 +419,29 @@ GBALog(hw->p, GBA_LOG_GAME_ERROR, "Invalid tilt sensor read from %04x", address);
break; } return 0xFF; +} + +// == Game Boy Player + +static const uint16_t _logoPalette[] = { + 0xFFDF, 0x640C, 0xE40C, 0xE42D, 0x644E, 0xE44E, 0xE46E, 0x68AF, + 0xE8B0, 0x68D0, 0x68F0, 0x6911, 0xE911, 0x6D32, 0xED32, 0xED73, + 0x6D93, 0xED94, 0x6DB4, 0xF1D5, 0x71F5, 0xF1F6, 0x7216, 0x7257, + 0xF657, 0x7678, 0xF678, 0xF699, 0xF6B9, 0x76D9, 0xF6DA, 0x7B1B, + 0xFB1B, 0xFB3C, 0x7B5C, 0x7B7D, 0xFF7D, 0x7F9D, 0x7FBE, 0x7FFF, + 0x642D, 0x648E, 0xE88F, 0xE8F1, 0x6D52, 0x6D73, 0xF1B4, 0xF216, + 0x7237, 0x7698, 0x7AFA, 0xFAFA, 0xFB5C, 0xFFBE, 0x7FDE, 0xFFFF, + 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 +}; + +static const uint32_t _logoHash = 0xEEDA6963; + +bool GBAHardwarePlayerCheckScreen(const struct GBAVideo* video) { + if (memcmp(video->palette, _logoPalette, sizeof(_logoPalette)) != 0) { + return false; + } + uint32_t hash = hash32(&video->renderer->vram[0x4000], 0x4000, 0); + return hash == _logoHash; } // == Serialization
M
src/gba/hardware.h
→
src/gba/hardware.h
@@ -129,6 +129,9 @@ void GBAHardwareGPIOWrite(struct GBACartridgeHardware* gpio, uint32_t address, uint16_t value);
void GBAHardwareTiltWrite(struct GBACartridgeHardware* gpio, uint32_t address, uint8_t value); uint8_t GBAHardwareTiltRead(struct GBACartridgeHardware* gpio, uint32_t address); +struct GBAVideo; +bool GBAHardwarePlayerCheckScreen(cosnt struct GBAVideo* video); + struct GBASerializedState; void GBAHardwareSerialize(const struct GBACartridgeHardware* gpio, struct GBASerializedState* state); void GBAHardwareDeserialize(struct GBACartridgeHardware* gpio, const struct GBASerializedState* state);