From 2ca5fed63ad231a2a62e4af3bd441c584c803ba1 Mon Sep 17 00:00:00 2001 From: NicoleFaye <41876584+NicoleFaye@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:04:15 +0100 Subject: [PATCH] Add CGB palette and bank number support for api/sprite.py --- pyboy/api/sprite.pxd | 3 ++- pyboy/api/sprite.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pyboy/api/sprite.pxd b/pyboy/api/sprite.pxd index bfbba208c..85ed8af29 100644 --- a/pyboy/api/sprite.pxd +++ b/pyboy/api/sprite.pxd @@ -19,7 +19,8 @@ cdef class Sprite: cdef readonly bint attr_obj_bg_priority cdef readonly bint attr_y_flip cdef readonly bint attr_x_flip - cdef readonly bint attr_palette_number + cdef readonly int attr_palette_number + cdef readonly bint attr_cgb_bank_number cdef readonly tuple shape cdef readonly list tiles cdef readonly bint on_screen diff --git a/pyboy/api/sprite.py b/pyboy/api/sprite.py index 99eb0dfd8..6847e7a0f 100644 --- a/pyboy/api/sprite.py +++ b/pyboy/api/sprite.py @@ -116,7 +116,18 @@ def __init__(self, mb, sprite_index): The state of the bit in the attributes lookup. """ - self.attr_palette_number = _bit(attr, 4) + self.attr_palette_number = 0 + """ + To better understand this values, look in the [Pan Docs: VRAM Sprite Attribute Table + (OAM)](https://gbdev.io/pandocs/OAM.html). + + Returns + ------- + int: + The state of the bit(s) in the attributes lookup. + """ + + self.attr_cgb_bank_number = 0 """ To better understand this values, look in the [Pan Docs: VRAM Sprite Attribute Table (OAM)](https://gbdev.io/pandocs/OAM.html). @@ -127,6 +138,12 @@ def __init__(self, mb, sprite_index): The state of the bit in the attributes lookup. """ + if self.mb.cgb: + self.attr_palette_number = attr & 0b111 + self.attr_cgb_bank_number = _bit(attr, 3) + else: + self.attr_palette_number = _bit(attr, 4) + LCDC = LCDCRegister(self.mb.getitem(LCDC_OFFSET)) sprite_height = 16 if LCDC._get_sprite_height() else 8 self.shape = (8, sprite_height)