From 5fe6eb97ea87f46e38a4a283f2228f4cf506b3f3 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 9 Oct 2017 11:41:02 -0700 Subject: [PATCH] Python: gamedata integration --- src/platform/python/mgba/core.py | 4 ++++ src/platform/python/mgba/gamedata.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/platform/python/mgba/gamedata.py diff --git a/src/platform/python/mgba/core.py b/src/platform/python/mgba/core.py index 84f59caa3..84dc80e05 100644 --- a/src/platform/python/mgba/core.py +++ b/src/platform/python/mgba/core.py @@ -258,6 +258,10 @@ class Core(object): def addFrameCallback(self, cb): self._callbacks.videoFrameEnded.append(cb) + @property + def crc32(self): + return self._native.romCrc32 + class ICoreOwner(object): def claim(self): raise NotImplementedError diff --git a/src/platform/python/mgba/gamedata.py b/src/platform/python/mgba/gamedata.py new file mode 100644 index 000000000..40eb16c04 --- /dev/null +++ b/src/platform/python/mgba/gamedata.py @@ -0,0 +1,22 @@ +# Copyright (c) 2013-2017 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +try: + import mgba_gamedata +except ImportError: + pass + +def search(core): + crc32 = None + if hasattr(core, 'PLATFORM_GBA') and core.platform() == core.PLATFORM_GBA: + platform = 'GBA' + crc32 = core.crc32 + if hasattr(core, 'PLATFORM_GB') and core.platform() == core.PLATFORM_GB: + platform = 'GB' + crc32 = core.crc32 + cls = mgba_gamedata.registry.search(platform, {'crc32': crc32}) + if not cls: + return None + return cls(core.memory.u8)