mirror of https://github.com/mgba-emu/mgba.git
Python: Add support for 256-color sprites
This commit is contained in:
parent
9b915fb13d
commit
9a104508ac
|
@ -24,8 +24,8 @@ class GBA(Core):
|
|||
lib.mTileCacheDeinit(cache)
|
||||
|
||||
class GBASprite(Sprite):
|
||||
TILE_BASE = 0x800
|
||||
PALETTE_BASE = 0x10
|
||||
TILE_BASE = 0x800, 0x400
|
||||
PALETTE_BASE = 0x10, 1
|
||||
|
||||
def __init__(self, obj):
|
||||
self._a = obj.a
|
||||
|
@ -35,11 +35,12 @@ class GBASprite(Sprite):
|
|||
self.y = self._a & 0xFF
|
||||
self._shape = self._a >> 14
|
||||
self._size = self._b >> 14
|
||||
self._256Color = bool(self._b & 0x2000)
|
||||
self._256Color = bool(self._a & 0x2000)
|
||||
self.width, self.height = lib.GBAVideoObjSizes[self._shape * 4 + self._size]
|
||||
self.tile = self._c & 0x3FF
|
||||
if self._256Color:
|
||||
self.paletteId = 0
|
||||
self.tile >>= 1
|
||||
else:
|
||||
self.paletteId = self._c >> 12
|
||||
|
||||
|
@ -56,6 +57,5 @@ class GBAObjs:
|
|||
raise IndexError()
|
||||
sprite = GBASprite(self._obj[index])
|
||||
map1D = bool(self._core._native.memory.io[0] & 0x40)
|
||||
# TODO: 256 colors
|
||||
sprite.constitute(self._core.tiles, 0 if map1D else 0x20)
|
||||
sprite.constitute(self._core.tiles, 0 if map1D else 0x20, int(sprite._256Color))
|
||||
return sprite
|
||||
|
|
|
@ -26,22 +26,32 @@ class TileView:
|
|||
self.cache = ffi.gc(ffi.new("struct mTileCache*"), core._deinitTileCache)
|
||||
core._initTileCache(self.cache)
|
||||
lib.mTileCacheSetPalette(self.cache, 0)
|
||||
self.paletteSet = 0
|
||||
|
||||
def getTile(self, tile, palette):
|
||||
return Tile(lib.mTileCacheGetTile(self.cache, tile, palette))
|
||||
|
||||
class Sprite(object):
|
||||
TILE_BASE = 0
|
||||
PALETTE_BASE = 0
|
||||
def setPalette(self, paletteSet):
|
||||
if paletteSet > 1 or paletteSet < 0:
|
||||
raise IndexError("Palette Set ID out of bounds")
|
||||
lib.mTileCacheSetPalette(self.cache, paletteSet)
|
||||
self.paletteSet = paletteSet
|
||||
|
||||
def constitute(self, tileView, tilePitch):
|
||||
class Sprite(object):
|
||||
TILE_BASE = 0, 0
|
||||
PALETTE_BASE = 0, 0
|
||||
|
||||
def constitute(self, tileView, tilePitch, paletteSet):
|
||||
oldPaletteSet = tileView.paletteSet
|
||||
tileView.setPalette(paletteSet)
|
||||
i = image.Image(self.width, self.height)
|
||||
tileId = self.tile + self.TILE_BASE
|
||||
tileId = self.tile + self.TILE_BASE[paletteSet]
|
||||
for y in range(self.height // 8):
|
||||
for x in range(self.width // 8):
|
||||
tile = tileView.getTile(tileId, self.paletteId + self.PALETTE_BASE)
|
||||
tile = tileView.getTile(tileId, self.paletteId + self.PALETTE_BASE[paletteSet])
|
||||
tile.composite(i, x * 8, y * 8)
|
||||
tileId += 1
|
||||
if tilePitch:
|
||||
tileId += tilePitch - self.width // 8
|
||||
self.image = i
|
||||
tileView.setPalette(oldPaletteSet)
|
||||
|
|
Loading…
Reference in New Issue