mirror of https://github.com/mgba-emu/mgba.git
Python: Sprite access in GB core
This commit is contained in:
parent
9a104508ac
commit
471bbf1da5
|
@ -4,13 +4,16 @@
|
|||
# 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/.
|
||||
from ._pylib import ffi, lib
|
||||
from . import core, lr35902
|
||||
from .lr35902 import LR35902Core
|
||||
from .core import Core
|
||||
from .tile import Sprite
|
||||
|
||||
class GB:
|
||||
class GB(Core):
|
||||
def __init__(self, native):
|
||||
super(GB, self).__init__(native)
|
||||
self._native = ffi.cast("struct GB*", native.board)
|
||||
self.cpu = lr35902.LR35902Core(self._core.cpu)
|
||||
self.sprites = GBObjs(self)
|
||||
self.cpu = LR35902Core(self._core.cpu)
|
||||
|
||||
def _initTileCache(self, cache):
|
||||
lib.GBVideoTileCacheInit(cache)
|
||||
|
@ -19,3 +22,37 @@ class GB:
|
|||
def _deinitTileCache(self, cache):
|
||||
self._native.video.renderer.cache = ffi.NULL
|
||||
lib.mTileCacheDeinit(cache)
|
||||
|
||||
class GBSprite(Sprite):
|
||||
PALETTE_BASE = 8,
|
||||
|
||||
def __init__(self, obj, core):
|
||||
self.x = obj.x
|
||||
self.y = obj.y
|
||||
self.tile = obj.tile
|
||||
self._attr = obj.attr
|
||||
self.width = 8
|
||||
lcdc = core._native.memory.io[0x40]
|
||||
self.height = 16 if lcdc & 4 else 8
|
||||
if core._native.model >= lib.GB_MODEL_CGB:
|
||||
if self._attr & 8:
|
||||
self.tile += 512
|
||||
self.paletteId = self._attr & 7
|
||||
else:
|
||||
self.paletteId = (self._attr >> 4) & 1
|
||||
|
||||
|
||||
class GBObjs:
|
||||
def __init__(self, core):
|
||||
self._core = core
|
||||
self._obj = core._native.video.oam.obj
|
||||
|
||||
def __len__(self):
|
||||
return 40
|
||||
|
||||
def __getitem__(self, index):
|
||||
if index >= len(self):
|
||||
raise IndexError()
|
||||
sprite = GBSprite(self._obj[index], self._core)
|
||||
sprite.constitute(self._core.tiles, 0, 0)
|
||||
return sprite
|
||||
|
|
Loading…
Reference in New Issue