Skip to content

Commit

Permalink
Better handling of DMG and CGB cartridge name in header
Browse files Browse the repository at this point in the history
  • Loading branch information
Baekalfen committed Feb 17, 2025
1 parent ff45687 commit bc6d88e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion extras/examples/gamewrapper_kirby.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
quiet = "--quiet" in sys.argv
pyboy = PyBoy(filename, window="null" if quiet else "SDL2", scale=3, debug=not quiet)
pyboy.set_emulation_speed(0)
assert pyboy.cartridge_title == "KIRBY DREAM LA"
assert pyboy.cartridge_title == "KIRBY DREAM LAN"

kirby = pyboy.game_wrapper
kirby.start_game()
Expand Down
2 changes: 1 addition & 1 deletion extras/examples/gamewrapper_mario.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
quiet = "--quiet" in sys.argv
pyboy = PyBoy(filename, window="null" if quiet else "SDL2", scale=3, debug=not quiet)
pyboy.set_emulation_speed(0)
assert pyboy.cartridge_title == "SUPER MARIOLAN"
assert pyboy.cartridge_title == "SUPER MARIOLAND"

mario = pyboy.game_wrapper
mario.start_game()
Expand Down
14 changes: 11 additions & 3 deletions pyboy/core/cartridge/base_mbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __init__(self, filename, rombanks, external_ram_count, carttype, sram, batte
self.external_rom_count = len(rombanks)
self.external_ram_count = external_ram_count
self.init_rambanks(external_ram_count)

# CGB flag overlaps with earlier game titles
self.cgb = bool(self.rombanks[0, 0x0143] >> 7)
self.gamename = self.getgamename(rombanks)

self.memorymodel = 0
Expand All @@ -40,8 +43,6 @@ def __init__(self, filename, rombanks, external_ram_count, carttype, sram, batte
self.rombank_selected = 1
self.rombank_selected_low = 0

self.cgb = bool(self.rombanks[0, 0x0143] >> 7)

if not os.path.exists(self.filename):
logger.debug("No RAM file found. Skipping.")
else:
Expand Down Expand Up @@ -102,7 +103,14 @@ def init_rambanks(self, n):
self.rambanks = memoryview(array.array("B", [0] * (8 * 1024 * 16))).cast("B", shape=(16, 8 * 1024))

def getgamename(self, rombanks):
return "".join([chr(rombanks[0, x]) for x in range(0x0134, 0x0142)]).split("\0")[0]
# Title was originally 0x134-0x143.
# Later 0x13F-0x142 became manufacturer code and 0x143 became a CGB flag
if self.cgb:
end = 0x0142 # Including manufacturer code
# end = 0x013F # Excluding potential(?) manufacturer code
else:
end = 0x0143
return "".join([chr(rombanks[0, x]) for x in range(0x0134, end)]).split("\0")[0]

def setitem(self, address, value):
raise PyBoyException("Cannot set item in MBC")
Expand Down
2 changes: 1 addition & 1 deletion pyboy/plugins/game_wrapper_kirby_dream_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GameWrapperKirbyDreamLand(PyBoyGameWrapper):
If you call `print` on an instance of this object, it will show an overview of everything this object provides.
"""

cartridge_title = "KIRBY DREAM LA"
cartridge_title = "KIRBY DREAM LAN"

def __init__(self, *args, **kwargs):
self.score = 0
Expand Down
2 changes: 1 addition & 1 deletion pyboy/plugins/game_wrapper_super_mario_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class GameWrapperSuperMarioLand(PyBoyGameWrapper):
"""

cartridge_title = "SUPER MARIOLAN"
cartridge_title = "SUPER MARIOLAND"
mapping_compressed = mapping_compressed
"""
Compressed mapping for `pyboy.PyBoy.game_area_mapping`
Expand Down
4 changes: 2 additions & 2 deletions tests/test_game_wrapper_mario.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def test_mario_basics(supermarioland_rom):
pyboy = PyBoy(supermarioland_rom, window="null")
pyboy.set_emulation_speed(0)
assert pyboy.cartridge_title == "SUPER MARIOLAN"
assert pyboy.cartridge_title == "SUPER MARIOLAND"

mario = pyboy.game_wrapper
mario.start_game(world_level=(1, 1))
Expand All @@ -23,7 +23,7 @@ def test_mario_basics(supermarioland_rom):
def test_mario_advanced(supermarioland_rom):
pyboy = PyBoy(supermarioland_rom, window="null")
pyboy.set_emulation_speed(0)
assert pyboy.cartridge_title == "SUPER MARIOLAN"
assert pyboy.cartridge_title == "SUPER MARIOLAND"

mario = pyboy.game_wrapper
mario.start_game(world_level=(3, 2))
Expand Down

0 comments on commit bc6d88e

Please sign in to comment.