-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand cartridge information #336
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ def __init__(self, filename, rombanks, external_ram_count, carttype, sram, batte | |
self.external_ram_count = external_ram_count | ||
self.init_rambanks(external_ram_count) | ||
self.gamename = self.getgamename(rombanks) | ||
self.gametype = self.getgametype(rombanks) | ||
self.gameregion = self.getgameregion(rombanks) | ||
|
||
self.memorymodel = 0 | ||
self.rambank_enabled = False | ||
|
@@ -103,7 +105,55 @@ 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] | ||
return "".join([chr(rombanks[0, x]) for x in range(0x0134, 0x0143)]).split("\0")[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to conditionally extract a shorter or longer string if it's a CGB or DMG ROM? I know it's a little outside of your PR |
||
|
||
def getgametype(self, rombanks): | ||
if rombanks[0, 0x143] == 0x80 or rombanks[0, 0x143] == 0xc0: | ||
return "Game Boy Color" | ||
elif rombanks[0, 0x146] == 0x03: | ||
return "Super Game Boy" | ||
else: | ||
return "Game Boy" | ||
Comment on lines
+110
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably better to split this out into separate "cgb" and "sgb" checks, as they are seemingly not mutually exclusive https://gbdev.io/pandocs/The_Cartridge_Header.html |
||
|
||
def getgameregion(self, rombanks): | ||
game_type = self.getgametype(rombanks) | ||
# The region character is only present in GBC/SGB games only; for regular GB games can't be fetched | ||
if game_type == 'Game Boy': | ||
return "Unknown" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to return I.e. this won't work if it's if python.cartridge_region:
do_something(python.cartridge_region) |
||
else: | ||
# Get the last letter of the sales code that determines the region | ||
region_string = "".join([chr(rombanks[0, x]) for x in range(0x13f, 0x0143)]).split("\0")[0] | ||
if region_string: | ||
region_code = region_string[-1] | ||
else: | ||
return "Unknown" | ||
# Return game region according to the last letter of the serial code | ||
if region_code == 'J': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did you find these codes? |
||
return "Japan" | ||
elif region_code == 'E': | ||
return "USA" | ||
elif region_code == 'P': | ||
return "Europe" | ||
elif region_code == 'S': | ||
return "Spain" | ||
elif region_code == 'I': | ||
return "Italy" | ||
elif region_code == 'F': | ||
return "France" | ||
elif region_code == 'D': | ||
return "Germany" | ||
elif region_code == 'A': | ||
return "World" | ||
elif region_code == 'X': | ||
return "Europe" | ||
elif region_code == 'Y': | ||
return "Europe" | ||
elif region_code == 'K': | ||
return "Korea" | ||
elif region_code == 'U': | ||
return "Australia" | ||
else: | ||
return "Unknown" | ||
|
||
def setitem(self, address, value): | ||
raise Exception("Cannot set item in MBC") | ||
|
@@ -138,6 +188,8 @@ def __repr__(self): | |
"MBC class: %s" % self.__class__.__name__, | ||
"Filename: %s" % self.filename, | ||
"Game name: %s" % self.gamename, | ||
"Game type: %s" % self.gametype, | ||
"Game region: %s" % self.gameregion, | ||
"GB Color: %s" % str(self.rombanks[0, 0x143] == 0x80), | ||
"Cartridge type: %s" % hex(self.carttype), | ||
"Number of ROM banks: %s" % self.external_rom_count, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,6 +323,42 @@ def __init__( | |
Game title | ||
""" | ||
|
||
self.cartridge_type = self.mb.cartridge.gametype | ||
""" | ||
The game type stored on the currently loaded cartridge ROM. Values are: | ||
Game Boy, Game Boy Color, Super Game Boy | ||
|
||
Example: | ||
```python | ||
>>> pyboy.cartridge_type # Game type of PyBoy's default ROM | ||
'Game Boy Color' | ||
|
||
``` | ||
|
||
Returns | ||
------- | ||
str : | ||
Game type | ||
""" | ||
|
||
self.cartridge_region = self.mb.cartridge.gameregion | ||
""" | ||
The game region stored on the currently loaded cartridge ROM. Example values are: | ||
Europe, USA, Japan, Spain, Germany, World... | ||
|
||
Example: | ||
```python | ||
>>> pyboy.cartridge_region # Game region of PyBoy's default ROM | ||
'Europe' | ||
|
||
``` | ||
|
||
Returns | ||
------- | ||
str : | ||
Europe | ||
""" | ||
|
||
Comment on lines
+326
to
+361
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might make sense to move this to |
||
self._hooks = {} | ||
|
||
self._plugin_manager = PluginManager(self, self.mb, kwargs) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misspelled
str