This repo will contain various libraries I've created for my personal use.
Currently, this only contains an Address Conversion tool, and a Pointer class which are used similarly to LunarAddress, except I don't support ZSNES save states. (I could, but... meh.)
- LoROM (Type 1/2)
- HiROM
- ExLoROM
- ExHiROM
- PC/Binary
from snes import SFCAddress, SFCAddressType
addr = SFCAddress(0x5f800, SFCAddressType.PC)
print(addr.all()) # all applicable conversions are shown
print(addr.exhirom_address) # hex-formatted EXHIROM address
=====TYPE====:=ADDRESS=
****Binary/PC: 0x05F800
*****(1)LoROM: 0x0BF800
**(2/Ex)LoROM: 0x8BF800
*****Ex/HiROM: 0xC5F800
'0xC5F800'
There are several helper methods that can be used for converting SNES/SFC addresses. Essentially, this library can be combined with any number of other tools such as script dumping, pointer table generation, address conversions built in to hex editors, etc.
I plan on adding more tools as I need it, but in the meantime,
The SFCPointer
class represents a Super Famicom (SFC) pointer. Pointers can be defined, modified, and read in various ways. The class allows you to specify low, high, and bank values, and it provides methods for validation, conversion, and display.
Pointers can be defined, modified, and read in many ways. Low and high values can be used to fill part of, or the entire address, depending on what is desired.
low
: Can be as small as 8 bit, as big as 24 bit (over 24 bit is ignored).high
: Can be 8 to 16 bit (over 16 bit is ignored).bank
: Only be 8 bit (extra data is lost).
Validates and normalizes low, high, and bank values.
args
: Low, high, and bank values. Returns a tuple(low, high, bank)
.
Formats an integer value as a hexadecimal string.
value
: Integer value to be formatted.pad
: Width of the formatted string (default is 4).prefix
: Prefix for the hexadecimal string (default is '0x'). Returns the formatted hexadecimal string.
Converts the SFCPointer
to an SFCAddress
instance.
addr_type
: The address type to convert to. Returns anSFCAddress
instance.
Validates and normalizes input values, applying masking to the value.
value
: Input value (integer or hexadecimal string).mask
: Mask to be applied (default is 0xFF). Returns the normalized and masked integer value.
Sets the value at the specified index in the full pointer.
The SFCAddressType
class defines constants representing different Super Famicom (SFC) address types.
PC
: Address type for PC addresses.LOROM1
: Address type for LoROM1 addresses.LOROM2
: Address type for LoROM2 addresses.HIROM
: Address type for HiROM addresses.EXHIROM
: Address type for ExHiROM addresses.EXLOROM
: Address type for ExLoROM addresses.
The SFCAddress
class provides a flexible way to handle Super Famicom (SFC) addresses. It allows for instantiation with various input types and supports multiple conversions between different address types.
__init__(self, address: Union[int, str, list, tuple], address_type: int = SFCAddressType.PC,
default_value='N/A', hex_prefix='0x', decimal: bool = False, header: bool = False,
verbose=False, lorom_fallback=True)
address
: Integer, hexadecimal string, list, or tuple representing the address value.address_type
: The input address type (default is SFCAddressType.PC).default_value
: The value shown while printing if the conversion fails (default is 'N/A').hex_prefix
: String prepended to the output hex value (default is '0x').decimal
: Boolean indicating the default conversion output value (default is False).header
: Indicates whether the conversion should consider a copier header (default is False).verbose
: If more console output is desired (default is False).lorom_fallback
: If LoROM 1/2 conversion fails, it will fall back to the other type.
Prints a formatted representation of the address in various SFC address types.
Formats and displays the given address.
Returns the address in the specified type.
Converts the given address to an SFCPointer object.
Returns a list of low, high, and bank bytes of the address.
Returns the low byte of the address.
Returns the high byte of the address.
Returns the bank byte of the address.
Returns the address in PC format.
Returns the address in LoROM1 format.
Returns the address in LoROM2 format.
Returns the address in ExLoROM format.
Returns the address in HiROM format.
Returns the address in ExHiROM format.
Converts a PC address to LoROM1 format.
Converts a PC address to LoROM2 format.
Converts a PC address to HiROM format.
Converts a PC address to ExLoROM format.
Converts a PC address to ExHiROM format.
Converts a LoROM1 address to PC format.
Converts a LoROM2 address to PC format.
Converts a HiROM address to PC format.
Converts an ExLoROM address to PC format.
Converts an ExHiROM address to PC format.