def test_load_rom(self): global rom rom = None load_rom() self.failIf(rom == None) rom = RomStr(None) load_rom() self.failIf(rom == RomStr(None))
def test_rom_until(self): global rom load_rom() address = 0x1337 byte = 0x13 bytes = rom.until(address, byte, strings=True) self.failUnless(len(bytes) == 3) self.failUnless(bytes[0] == '0xd5') bytes = rom.until(address, byte, strings=False) self.failUnless(len(bytes) == 3) self.failUnless(bytes[0] == 0xd5)
def test_rom_interval(self): global rom load_rom() address = 0x100 interval = 10 correct_strings = ['0x0', '0xc3', '0x6e', '0x1', '0xce', '0xed', '0x66', '0x66', '0xcc', '0xd'] byte_strings = rom.interval(address, interval, strings=True) self.assertEqual(byte_strings, correct_strings) correct_ints = [0, 195, 110, 1, 206, 237, 102, 102, 204, 13] ints = rom.interval(address, interval, strings=False) self.assertEqual(ints, correct_ints)
def dump_monster_pals(): rom = load_rom() pals = 0xa8d6 pal_length = 0x4 for mon in range(251): name = pokemon_constants[mon+1].title().replace('_','') num = str(mon+1).zfill(3) dir = 'gfx/pics/'+num+'/' address = pals + mon*pal_length*2 pal_data = [] for byte in range(pal_length): pal_data.append(ord(rom[address])) address += 1 filename = 'normal.pal' to_file('../'+dir+filename, pal_data) spacing = ' ' * (15 - len(name)) #print name+'Palette:'+spacing+' INCBIN "'+dir+filename+'"' pal_data = [] for byte in range(pal_length): pal_data.append(ord(rom[address])) address += 1 filename = 'shiny.pal' to_file('../'+dir+filename, pal_data) spacing = ' ' * (10 - len(name))
def get_uncompressed_gfx(start, num_tiles, filename): """grab tiles directly from rom and write to file""" bytes_per_tile = 0x10 length = num_tiles*bytes_per_tile end = start + length rom = load_rom() image = [] for address in range(start,end): image.append(ord(rom[address])) to_file(filename, image)
def dump_trainer_pals(): rom = load_rom() pals = 0xb0d2 pal_length = 0x4 for trainer in range(67): name = trainer_group_names[trainer+1]['constant'].title().replace('_','') num = str(trainer).zfill(3) dir = 'gfx/trainers/' address = pals + trainer*pal_length pal_data = [] for byte in range(pal_length): pal_data.append(ord(rom[address])) address += 1 filename = num+'.pal' to_file('../'+dir+filename, pal_data) spacing = ' ' * (12 - len(name)) print name+'Palette:'+spacing+' INCBIN"'+dir+filename+'"'
# -*- coding: utf-8 -*- import os import sys import png from math import sqrt, floor, ceil from crystal import load_rom from pokemon_constants import pokemon_constants from trainers import trainer_group_names if __name__ != "__main__": rom = load_rom() def mkdir_p(path): """ Make a directory at a given path. """ try: os.makedirs(path) except OSError as exc: # Python >2.5 if exc.errno == errno.EEXIST: pass else: raise def hex_dump(input, debug=True): """
def setUpClass(cls): load_rom() cls.address = 10 cls.sbp = SingleByteParam(address=cls.address)
# -*- encoding: utf-8 -*- """ Dump out asm for scripting things in bank $25. This script will modify main.asm and insert all scripting commands. """ import crystal import gbz80disasm rom = crystal.load_rom() roml = [ord(x) for x in rom] script_command_table_address = 0x96cb1 script_command_count = 170 # a list of addresses for each script command command_pointers = [crystal.calculate_pointer_from_bytes_at(script_command_table_address + (id * 2), bank=0x25) for id in range(0, 170)] # a list of hex addresses for each script command in bank $25 command_pointers_hex = ["$%.2x" % (x % 0x4000 + 0x4000) for x in command_pointers] commands = {} # force data into a more usable form for command in crystal.command_classes: name = "Script_" + command.macro_name id = command.id params = {} for (id2, param_type) in command.param_types.items(): param = {
import sys import crystal rom = crystal.load_rom() addr = int(sys.argv[1], 16) count = int(sys.argv[2]) if len(sys.argv) > 2 else 256 label_prefix = sys.argv[3] if len(sys.argv) > 3 else "UnknownString" ex = None for i in range(count): try: string = crystal.PokedexText(addr) asm = string.to_asm() except Exception as ex: break print label_prefix+str(i)+": ; "+hex(addr) print "\t"+asm print addr = string.last_address print "; "+hex(addr) if ex: raise ex
from crystal import ( SingleByteParam, PointerLabelParam, DecimalParam, BigEndianParam, Command, load_rom ) from gbz80disasm import get_local_address, get_global_address from audio import sort_asms from wram import read_constants rom = bytearray(load_rom()) sfx_constants = read_constants(os.path.join(conf.path, 'constants/sfx_constants.asm')) class SoundEffectParam(SingleByteParam): def to_asm(self): if self.byte in sfx_constants.keys(): sfx_constant = sfx_constants[self.byte] return sfx_constant return SingleByteParam.to_asm(self) anim_gfx_constants = read_constants(os.path.join(conf.path, 'constants/gfx_constants.asm')) class AnimGFXParam(SingleByteParam): def to_asm(self): if self.byte in anim_gfx_constants.keys(): return anim_gfx_constants[self.byte] return SingleByteParam.to_asm(self)
from song_names import song_names from sfx_names import sfx_names from cry_names import cry_names from gbz80disasm import get_global_address, get_local_address from labels import line_has_label from crystal import music_classes as sound_classes from crystal import ( Command, SingleByteParam, MultiByteParam, PointerLabelParam, load_rom, ) rom = load_rom() rom = bytearray(rom) import configuration conf = configuration.Config() def is_comment(asm): return asm.startswith(';') def asm_sort(asm_def): """ Sort key for asm lists. Usage:
import os from new import classobj import configuration conf = configuration.Config() from crystal import (SingleByteParam, PointerLabelParam, DecimalParam, BigEndianParam, Command, load_rom) from gbz80disasm import get_local_address, get_global_address from audio import sort_asms from wram import read_constants rom = bytearray(load_rom()) sfx_constants = read_constants( os.path.join(conf.path, 'constants/sfx_constants.asm')) class SoundEffectParam(SingleByteParam): def to_asm(self): if self.byte in sfx_constants.keys(): sfx_constant = sfx_constants[self.byte] return sfx_constant return SingleByteParam.to_asm(self) anim_gfx_constants = read_constants( os.path.join(conf.path, 'constants/gfx_constants.asm'))