Esempio n. 1
0
def parse(data):
    if _sub(data, 0x0, 4) != 'NES\x1a':
        raise ValueError

    if len(data) % 8192 != 16:
        name = _sub(data, len(data) - 128, 128).replace('\x00', '')
    else:
        name = None

    num_rom_banks = _unpack(_sub(data, 0x4, 1))
    num_vrom_banks = _unpack(_sub(data, 0x5, 1))
    rom_size = 16 * num_rom_banks + 8 * num_vrom_banks
    num_ram_banks = _unpack(_sub(data, 0x8, 1))
    ram_size = 8 * num_ram_banks

    return _ROM(name, 'NES', rom_size=rom_size, ram_size=ram_size)
Esempio n. 2
0
def _deinterleave_smd(data):
    block_count = len(data) / 16384
    blocks = [
        _deinterleave_bytes(_sub(data, i * 16384, 16384))
        for i in xrange(block_count)
    ]
    return ''.join(blocks)
Esempio n. 3
0
def parse(data):
    
    if not _valid_rom_info(data):
        if len(data) % 16384 != 0:
            # SMD, omit 512B external header and deinterleave first block
            data = data[512:]
            data = _deinterleave_smd(data)    
        else:
            # MD, deinterleave entire ROM
            data = _deinterleave_bytes(data)
            
        if not _valid_rom_info(data):
            raise ValueError

    name = ' '.join(_sub(data, 0x150, 48).split())
    version = _sub(data, 0x182, 12).replace(' ', '')
    rom_start = _unpack(_sub(data, 0x1a0, 4))
    rom_end = _unpack(_sub(data, 0x1a4, 4))
    ram_start = _unpack(_sub(data, 0x1b4, 4))
    ram_end = _unpack(_sub(data, 0x1b8, 4))
    country = _sub(data, 0x1f0, 16).strip()
    return _ROM(name,
                'Genesis',
                rom_size=(rom_end-rom_start+1)/1024,
                ram_size=(ram_end-ram_start+1)/1024,
                country=country,
                version=version)
Esempio n. 4
0
def parse(data):

    if not _valid_rom_info(data):
        if len(data) % 16384 != 0:
            # SMD, omit 512B external header and deinterleave first block
            data = data[512:]
            data = _deinterleave_smd(data)
        else:
            # MD, deinterleave entire ROM
            data = _deinterleave_bytes(data)

        if not _valid_rom_info(data):
            raise ValueError

    name = ' '.join(_sub(data, 0x150, 48).split())
    version = _sub(data, 0x182, 12).replace(' ', '')
    rom_start = _unpack(_sub(data, 0x1a0, 4))
    rom_end = _unpack(_sub(data, 0x1a4, 4))
    ram_start = _unpack(_sub(data, 0x1b4, 4))
    ram_end = _unpack(_sub(data, 0x1b8, 4))
    country = _sub(data, 0x1f0, 16).strip()
    return _ROM(name,
                'Genesis',
                rom_size=(rom_end - rom_start + 1) / 1024,
                ram_size=(ram_end - ram_start + 1) / 1024,
                country=country,
                version=version)
Esempio n. 5
0
def parse(data):
    if _sub(data, 0x0, 4) != 'NES\x1a':
        raise ValueError

    if len(data) % 8192 != 16:
        name = _sub(data, len(data)-128, 128).replace('\x00', '')
    else:
        name = None

    num_rom_banks = _unpack(_sub(data, 0x4, 1))
    num_vrom_banks = _unpack(_sub(data, 0x5, 1))
    rom_size = 16*num_rom_banks + 8*num_vrom_banks
    num_ram_banks = _unpack(_sub(data, 0x8, 1))
    ram_size = 8*num_ram_banks

    return _ROM(name,
                'NES',
                rom_size=rom_size,
                ram_size=ram_size)
Esempio n. 6
0
def parse(data):

    # omit 512B external header
    if len(data) % 32768 != 0:
        data = data[512:]

    # find 64B internal header address
    hdr = _find_header_address(data)

    name = _sub(data, hdr, 21).strip()
    rom_byte = ord(data[hdr + 0x17])
    rom_size = 1 << rom_byte if rom_byte > 0 else 0
    ram_byte = ord(data[hdr + 0x18])
    ram_size = 1 << ram_byte if ram_byte > 0 else 0
    ccode = ord(data[hdr + 0x19])
    country, region = _country_and_region(ccode)
    version = '1.%d' % ord(data[hdr + 0x1b])
    return _ROM(name,
                'SNES',
                rom_size=rom_size,
                ram_size=ram_size,
                country=country,
                region=region,
                version=version)
Esempio n. 7
0
def parse(data):
        
    # omit 512B external header
    if len(data) % 32768 != 0:
        data = data[512:]
            
    # find 64B internal header address
    hdr = _find_header_address(data)
                
    name = _sub(data, hdr, 21).strip()
    rom_byte = ord(data[hdr+0x17])
    rom_size = 1 << rom_byte if rom_byte > 0 else 0
    ram_byte = ord(data[hdr+0x18])         
    ram_size = 1 << ram_byte if ram_byte > 0 else 0
    ccode = ord(data[hdr+0x19])
    country, region = _country_and_region(ccode)
    version = '1.%d' % ord(data[hdr+0x1b])        
    return _ROM(name,
                'SNES',
                rom_size=rom_size,
                ram_size=ram_size,
                country=country,
                region=region,
                version=version)
Esempio n. 8
0
def _has_lorom_makeup(data, hdr):
    l_nibble = _unpack(_sub(data, hdr + 0x15, 1)) & 0xf
    return l_nibble % 2 == 0
Esempio n. 9
0
def _checksum_heuristic(data, hdr):
    chksum_cpl = _unpack(_sub(data, hdr + 0x1c, 2))
    chksum = _unpack(_sub(data, hdr + 0x1e, 2))
    return chksum_cpl ^ chksum == 0xffff
Esempio n. 10
0
def _valid_rom_info(data):
    console = _sub(data, 0x100, 16).strip()
    return console == 'SEGA MEGA DRIVE' or console == 'SEGA GENESIS'
Esempio n. 11
0
def _deinterleave_smd(data):
    block_count = len(data) / 16384
    blocks = [_deinterleave_bytes(_sub(data, i*16384, 16384)) for i in xrange(block_count)]
    return ''.join(blocks)
Esempio n. 12
0
def _has_lorom_makeup(data, hdr):
    l_nibble = _unpack(_sub(data, hdr+0x15, 1)) & 0xf
    return l_nibble % 2 == 0
Esempio n. 13
0
def _checksum_heuristic(data, hdr):
    chksum_cpl = _unpack(_sub(data, hdr+0x1c, 2))
    chksum = _unpack(_sub(data, hdr+0x1e, 2))
    return chksum_cpl ^ chksum == 0xffff
Esempio n. 14
0
def _valid_rom_info(data):
    console = _sub(data, 0x100, 16).strip()
    return console == 'SEGA MEGA DRIVE' or console == 'SEGA GENESIS'