Skip to content

Commit

Permalink
Add CGB palette and bank number support for api/sprite.py
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoleFaye authored and Baekalfen committed Dec 20, 2023
1 parent fd633f2 commit 2ca5fed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pyboy/api/sprite.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion pyboy/api/sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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)
Expand Down

0 comments on commit 2ca5fed

Please sign in to comment.