summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--INSTALL.md31
-rw-r--r--Makefile4
-rw-r--r--README.md1
-rw-r--r--extras/comparator.py17
-rw-r--r--extras/crystal.py18
-rw-r--r--extras/gbz80disasm.py82
-rw-r--r--extras/gfx.py2647
-rw-r--r--extras/labels.py6
-rw-r--r--extras/overworldripper.py7
-rw-r--r--extras/romstr.py26
-rw-r--r--extras/vba.py126
-rw-r--r--extras/vba_autoplayer.py8
-rw-r--r--extras/wram.py36
-rw-r--r--main.asm309
-rw-r--r--wram.asm116
16 files changed, 1811 insertions, 1626 deletions
diff --git a/.gitignore b/.gitignore
index 77577a838..3a35100af 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,9 @@
# precompiled python
*.pyc
+# precompiled jython
+*$py.class
+
# compiled object file
*.o
diff --git a/INSTALL.md b/INSTALL.md
index 68d5c09b8..50b180c9a 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -28,6 +28,8 @@ During the install:
* Most mirrors are molasses. Use **http://mirrors.kernel.org**.
+* From the package selection, select **wget**.
+
## Using Cygwin
@@ -48,31 +50,38 @@ cd /away/we/go
We need a couple more things to be able to compile.
+
If you're feeling lazy, just paste these commands into your terminal.
+
+**apt-cyg** lets you install new packages without running Cygwin setup.
+
```bash
-apt-cyg install make git wget python python-setuptools
-easy_install pip
+wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
+chmod +x apt-cyg
+mv apt-cyg /usr/local/bin/
```
-**rgbds** will let you compile Game Boy roms.
+Now we can use apt-cyg to install everything else.
```bash
-cd ~
+apt-cyg install make git python python-setuptools unzip
+easy_install pip
+```
-# download rgbds binaries
-wget http://diyhpl.us/~bryan/irc/pokered/rgbds/rgbds.zip
-unzip rgbds.zip
-rm rgbds.zip
+**rgbds** will let you compile Game Boy roms.
-# make rgbds accessible for all time
-export PATH=$PATH:`pwd`/rgbds
-echo "export PATH=$PATH" >> ~/.bashrc
+```bash
+wget http://diyhpl.us/~bryan/irc/pokered/rgbds/rgbds-0.0.1.zip
+unzip rgbds-0.0.1.zip
+mv rgbds-0.0.1/* /usr/local/bin
+rm -r rgbds-0.0.1*
```
Set up the **pokecrystal** repository:
```bash
+cd ~
git clone https://github.com/kanzure/pokecrystal
cd pokecrystal
diff --git a/Makefile b/Makefile
index 697515b6e..6a75eeef0 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ pokecrystal.o: $(TEXTFILES:.asm=.tx) wram.asm constants.asm $(shell find constan
rgbasm -o pokecrystal.o pokecrystal.asm
.asm.tx:
$(eval TEXTQUEUE := $(TEXTQUEUE) $<)
- @rm $@
+ @rm -f $@
pokecrystal.gbc: pokecrystal.o
rgblink -o $@ $<
@@ -30,7 +30,7 @@ pngs:
lzs: $(LZ_GFX) $(TWOBPP_GFX)
@:
-gfx/pics/%/front.lz: gfx/pics/%/front.png gfx/pics/%/tiles.2bpp
+gfx/pics/%/front.lz: gfx/pics/%/tiles.2bpp gfx/pics/%/front.png
python extras/gfx.py png-to-lz --front $^
gfx/pics/%/tiles.2bpp: gfx/pics/%/tiles.png
python extras/gfx.py png-to-2bpp $<
diff --git a/README.md b/README.md
index 6adb65625..f191cd917 100644
--- a/README.md
+++ b/README.md
@@ -31,4 +31,3 @@ Eventually this will not be necessary.
* Hang out with us on irc: **[nucleus.kafuka.org #skeetendo](https://kiwiirc.com/client/irc.nolimitzone.com/?#skeetendo)**
* Disassembly of **[Pokémon Red](http://bitbucket.org/iimarckus/pokered)**.
-
diff --git a/extras/comparator.py b/extras/comparator.py
index 48bdb6b09..e338f4391 100644
--- a/extras/comparator.py
+++ b/extras/comparator.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
-Finds shared functions between red/crystal.
+Find shared functions between red/crystal.
"""
from crystal import (
@@ -18,13 +18,13 @@ from romstr import (
def load_rom(path):
"""
- Loads a ROM file into an abbreviated RomStr object.
+ Load a ROM file into an abbreviated RomStr object.
"""
return direct_load_rom(filename=path)
def load_asm(path):
"""
- Loads source ASM into an abbreviated AsmList object.
+ Load source ASM into an abbreviated AsmList object.
"""
return direct_load_asm(filename=path)
@@ -63,7 +63,8 @@ found_blobs = []
class BinaryBlob(object):
"""
- Stores a label, line number, and addresses of a function from Pokémon Red.
+ Store a label, line number, and addresses of a function from Pokémon Red.
+
These details can be used to determine whether or not the function was
copied into Pokémon Crystal.
"""
@@ -128,7 +129,7 @@ class BinaryBlob(object):
def parse_from_red(self):
"""
- Reads bytes from Pokémon Red and stores them.
+ Read bytes from Pokémon Red and stores them.
"""
self.bytes = redrom[self.start_address : self.end_address + 1]
@@ -146,7 +147,7 @@ class BinaryBlob(object):
def find_in_crystal(self):
"""
- Checks whether or not the bytes appear in Pokémon Crystal.
+ Check whether or not the bytes appear in Pokémon Crystal.
"""
finditer = findall_iter(self.bytes, cryrom)
@@ -160,7 +161,7 @@ class BinaryBlob(object):
def find_by_first_bytes(self):
"""
- Finds this blob in Crystal based on the first n bytes.
+ Find this blob in Crystal based on the first n bytes.
"""
# how many bytes to match
@@ -194,7 +195,7 @@ redsrc = load_asm(pokered_src_path)
def scan_red_asm(bank_stop=3, debug=True):
"""
- Scans the ASM from Pokémon Red. Finds labels and objects. Does things.
+ Scan the ASM from Pokémon Red. Finds labels and objects. Does things.
Uses get_label_from_line and get_address_from_line_comment.
"""
diff --git a/extras/crystal.py b/extras/crystal.py
index d14642cf7..c54ade01b 100644
--- a/extras/crystal.py
+++ b/extras/crystal.py
@@ -1476,7 +1476,7 @@ class PointerLabelToScriptPointer(PointerLabelParam):
def parse(self):
PointerLabelParam.parse(self)
address = calculate_pointer_from_bytes_at(self.parsed_address, bank=self.bank)
- address2 = calculate_pointer_from_bytes_at(address, bank="reverse") # maybe not "reverse"?
+ address2 = calculate_pointer_from_bytes_at(address, bank=True)
self.script = parse_script_engine_script_at(address2, origin=False, map_group=self.map_group, map_id=self.map_id, force=self.force, debug=self.debug)
@@ -2660,10 +2660,10 @@ text_command_classes = inspect.getmembers(sys.modules[__name__], \
pksv_crystal_more = {
0x00: ["2call", ["pointer", ScriptPointerLabelParam]],
0x01: ["3call", ["pointer", ScriptPointerLabelBeforeBank]],
- 0x02: ["2ptcall", ["pointer", PointerLabelToScriptPointer]],
+ 0x02: ["2ptcall", ["pointer", RAMAddressParam]],
0x03: ["2jump", ["pointer", ScriptPointerLabelParam]],
0x04: ["3jump", ["pointer", ScriptPointerLabelBeforeBank]],
- 0x05: ["2ptjump", ["pointer", PointerLabelToScriptPointer]],
+ 0x05: ["2ptjump", ["pointer", RAMAddressParam]],
0x06: ["if equal", ["byte", SingleByteParam], ["pointer", ScriptPointerLabelParam]],
0x07: ["if not equal", ["byte", SingleByteParam], ["pointer", ScriptPointerLabelParam]],
0x08: ["iffalse", ["pointer", ScriptPointerLabelParam]],
@@ -2674,7 +2674,7 @@ pksv_crystal_more = {
0x0D: ["callstd", ["predefined_script", MultiByteParam]],
0x0E: ["3callasm", ["asm", AsmPointerParam]],
0x0F: ["special", ["predefined_script", MultiByteParam]],
- 0x10: ["2ptcallasm", ["asm", PointerToAsmPointerParam]],
+ 0x10: ["2ptcallasm", ["asm", RAMAddressParam]],
# should map_group/map_id be dealt with in some special way in the asm?
0x11: ["checkmaptriggers", ["map_group", SingleByteParam], ["map_id", SingleByteParam]],
0x12: ["domaptrigger", ["map_group", MapGroupParam], ["map_id", MapIdParam], ["trigger_id", SingleByteParam]],
@@ -7356,15 +7356,15 @@ def write_all_labels(all_labels, filename="labels.json"):
fh.close()
return True
-# TODO: implement get_ram_label
-# wram.asm integration would be nice
+from wram import wram_labels
def get_ram_label(address):
- """not implemented yet.. supposed to get a label for a particular RAM location
- like W_PARTYPOKE1HP"""
+ """returns a label assigned to a particular ram address"""
+ if address in wram_labels.keys():
+ return wram_labels[address][-1]
return None
def get_label_for(address):
- """returns a label assigned to a particular address"""
+ """returns a label assigned to a particular rom address"""
global all_labels
if address == None:
diff --git a/extras/gbz80disasm.py b/extras/gbz80disasm.py
index ed546ef98..03824180e 100644
--- a/extras/gbz80disasm.py
+++ b/extras/gbz80disasm.py
@@ -13,6 +13,11 @@ if not hasattr(json, "read"):
json.read = json.loads
def load_rom(filename="../baserom.gbc"):
+ """
+ Load the specified rom.
+
+ If no rom is given, load "../baserom.gbc".
+ """
global rom
rom = bytearray(open(filename,'rb').read())
return rom
@@ -550,6 +555,8 @@ end_08_scripts_with = [
##0x18, #jr
###0xda, 0xe9, 0xd2, 0xc2, 0xca, 0xc3, 0x38, 0x30, 0x20, 0x28, 0x18, 0xd8, 0xd0, 0xc0, 0xc8, 0xc9
]
+
+discrete_jumps = [0xda, 0xe9, 0xd2, 0xc2, 0xca, 0xc3]
relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18, 0xc3, 0xda, 0xc2]
relative_unconditional_jumps = [0xc3, 0x18]
@@ -557,6 +564,11 @@ call_commands = [0xdc, 0xd4, 0xc4, 0xcc, 0xcd]
all_labels = {}
def load_labels(filename="labels.json"):
+ """
+ Load labels from specified file.
+
+ If no filename is given, loads 'labels.json'.
+ """
global all_labels
# don't re-load labels each time
@@ -587,30 +599,49 @@ def find_label(local_address, bank_id=0):
return constants[local_address]
return None
+def find_address_from_label(label):
+ for label_entry in all_labels:
+ if label == label_entry["label"]:
+ return label_entry["address"]
+ return None
+
def asm_label(address):
+ """
+ Return the ASM label using the address.
+ """
# why using a random value when you can use the address?
return '.asm_%x' % address
+
def data_label(address):
return '.data_%x' % address
def get_local_address(address):
bank = address / 0x4000
return (address & 0x3fff) + 0x4000 * bool(bank)
+
def get_global_address(address, bank):
- return (address & 0x3fff) + 0x4000 * bank
+ if address < 0x8000:
+ return (address & 0x3fff) + 0x4000 * bank
+ return None
-def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_address=True, stop_at=[], debug = False):
- #fs = current_address
- #b = bank_byte
- #in = input_data -- rom
- #bank_size = byte_count
- #i = offset
- #ad = end_address
- #a, oa = current_byte_number
+ return ".ASM_" + hex(address)[2:]
- # stop_at can be used to supply a list of addresses to not disassemble
- # over. This is useful if you know in advance that there are a lot of
- # fall-throughs.
+def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_address=True, stop_at=[], debug=False):
+ """
+ Output bank opcodes.
+
+ fs = current_address
+ b = bank_byte
+ in = input_data -- rom
+ bank_size = byte_count
+ i = offset
+ ad = end_address
+ a, oa = current_byte_number
+
+ stop_at can be used to supply a list of addresses to not disassemble
+ over. This is useful if you know in advance that there are a lot of
+ fall-throughs.
+ """
load_labels()
load_rom()
@@ -781,12 +812,13 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
number = byte1
number += byte2 << 8
- pointer = get_global_address(number, bank_id)
- if pointer not in data_tables.keys():
- data_tables[pointer] = {}
- data_tables[pointer]['usage'] = 0
- else:
- data_tables[pointer]['usage'] += 1
+ if current_byte not in call_commands + discrete_jumps + relative_jumps:
+ pointer = get_global_address(number, bank_id)
+ if pointer not in data_tables.keys():
+ data_tables[pointer] = {}
+ data_tables[pointer]['usage'] = 0
+ else:
+ data_tables[pointer]['usage'] += 1
insertion = "$%.4x" % (number)
result = find_label(insertion, bank_id)
@@ -840,7 +872,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
keep_reading = False
is_data = False #cleanup
break
- elif offset not in byte_labels.keys() or offset in data_tables.keys():
+ elif offset not in byte_labels.keys() and offset in data_tables.keys():
is_data = True
keep_reading = True
else:
@@ -880,8 +912,9 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
def has_outstanding_labels(byte_labels):
"""
- If a label is used once in the asm output, then that means it has to be
- called or specified later.
+ Check whether a label is used once in the asm output.
+
+ If so, then that means it has to be called or specified later.
"""
for label_line in byte_labels.keys():
real_line = byte_labels[label_line]
@@ -898,10 +931,15 @@ def all_outstanding_labels_are_reverse(byte_labels, offset):
if __name__ == "__main__":
+ load_labels()
addr = sys.argv[1]
if ":" in addr:
addr = addr.split(":")
addr = int(addr[0], 16)*0x4000+(int(addr[1], 16)%0x4000)
else:
- addr = int(addr, 16)
+ label_addr = find_address_from_label(addr)
+ if label_addr:
+ addr = label_addr
+ else:
+ addr = int(addr, 16)
print output_bank_opcodes(addr)[0]
diff --git a/extras/gfx.py b/extras/gfx.py
index a8e06cce8..1504933a4 100644
--- a/extras/gfx.py
+++ b/extras/gfx.py
@@ -12,125 +12,136 @@ from trainers import trainer_group_names
if __name__ != "__main__":
- rom = load_rom()
+ rom = load_rom()
def mkdir_p(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):
- """display hex dump in rows of 16 bytes"""
-
- dump = ''
- output = ''
- stream = ''
- address = 0x00
- margin = 2 + len(hex(len(input))[2:])
-
- # dump
- for byte in input:
- cool = hex(byte)[2:].zfill(2)
- dump += cool + ' '
- if debug: stream += cool
-
- # convenient for testing quick edits in bgb
- if debug: output += stream + '\n'
-
- # get dump info
- bytes_per_line = 16
- chars_per_byte = 3 # '__ '
- chars_per_line = bytes_per_line * chars_per_byte
- num_lines = int(ceil(float(len(dump)) / float(chars_per_line)))
-
- # top
- # margin
- for char in range(margin):
- output += ' '
- #
- for byte in range(bytes_per_line):
- output += hex(byte)[2:].zfill(2) + ' '
- output = output[:-1] # last space
-
- # print hex
- for line in range(num_lines):
- # address
- output += '\n' + hex(address)[2:].zfill(margin - 2) + ': '
- # contents
- start = line * chars_per_line
- end = chars_per_line + start - 1 # ignore last space
- output += dump[start:end]
- address += 0x10
-
- return output
+ """
+ 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):
+ """
+ Display hex dump in rows of 16 bytes.
+ """
+
+ dump = ''
+ output = ''
+ stream = ''
+ address = 0x00
+ margin = 2 + len(hex(len(input))[2:])
+
+ # dump
+ for byte in input:
+ cool = hex(byte)[2:].zfill(2)
+ dump += cool + ' '
+ if debug: stream += cool
+
+ # convenient for testing quick edits in bgb
+ if debug: output += stream + '\n'
+
+ # get dump info
+ bytes_per_line = 16
+ chars_per_byte = 3 # '__ '
+ chars_per_line = bytes_per_line * chars_per_byte
+ num_lines = int(ceil(float(len(dump)) / float(chars_per_line)))
+
+ # top
+ # margin
+ for char in range(margin):
+ output += ' '
+
+ for byte in range(bytes_per_line):
+ output += hex(byte)[2:].zfill(2) + ' '
+ output = output[:-1] # last space
+
+ # print hex
+ for line in range(num_lines):
+ # address
+ output += '\n' + hex(address)[2:].zfill(margin - 2) + ': '
+ # contents
+ start = line * chars_per_line
+ end = chars_per_line + start - 1 # ignore last space
+ output += dump[start:end]
+ address += 0x10
+
+ return output
def get_tiles(image):
- """split a 2bpp image into 8x8 tiles"""
- tiles = []
- tile = []
- bytes_per_tile = 16
-
- cur_byte = 0
- for byte in image:
- # build tile
- tile.append(byte)
- cur_byte += 1
- # done building?
- if cur_byte >= bytes_per_tile:
- # push completed tile
- tiles.append(tile)
- tile = []
- cur_byte = 0
- return tiles
+ """
+ Split a 2bpp image into 8x8 tiles.
+ """
+ tiles = []
+ tile = []
+ bytes_per_tile = 16
+
+ cur_byte = 0
+ for byte in image:
+ # build tile
+ tile.append(byte)
+ cur_byte += 1
+ # done building?
+ if cur_byte >= bytes_per_tile:
+ # push completed tile
+ tiles.append(tile)
+ tile = []
+ cur_byte = 0
+ return tiles
def connect(tiles):
- """combine 8x8 tiles into a 2bpp image"""
- out = []
- for tile in tiles:
- for byte in tile:
- out.append(byte)
- return out
+ """
+ Combine 8x8 tiles into a 2bpp image.
+ """
+ out = []
+ for tile in tiles:
+ for byte in tile:
+ out.append(byte)
+ return out
def transpose(tiles):
- """transpose a tile arrangement along line y=x"""
-
- # horizontal <-> vertical
- # 00 01 02 03 04 05 00 06 0c 12 18 1e
- # 06 07 08 09 0a 0b 01 07 0d 13 19 1f
- # 0c 0d 0e 0f 10 11 <-> 02 08 0e 14 1a 20
- # 12 13 14 15 16 17 <-> 03 09 0f 15 1b 21
- # 18 19 1a 1b 1c 1d 04 0a 10 16 1c 22
- # 1e 1f 20 21 22 23 05 0b 11 17 1d 23
- # etc
-
- flipped = []
- t = 0 # which tile we're on
- w = int(sqrt(len(tiles))) # assume square image
- for tile in tiles:
- flipped.append(tiles[t])
- t += w
- # end of row?
- if t >= w*w:
- # wrap around
- t -= w*w
- # next row
- t += 1
- return flipped
+ """
+ Transpose a tile arrangement along line y=x.
+ """
+
+ # horizontal <-> vertical
+ # 00 01 02 03 04 05 00 06 0c 12 18 1e
+ # 06 07 08 09 0a 0b 01 07 0d 13 19 1f
+ # 0c 0d 0e 0f 10 11 <-> 02 08 0e 14 1a 20
+ # 12 13 14 15 16 17 <-> 03 09 0f 15 1b 21
+ # 18 19 1a 1b 1c 1d 04 0a 10 16 1c 22
+ # 1e 1f 20 21 22 23 05 0b 11 17 1d 23
+ # etc
+
+ flipped = []
+ t = 0 # which tile we're on
+ w = int(sqrt(len(tiles))) # assume square image
+ for tile in tiles:
+ flipped.append(tiles[t])
+ t += w
+ # end of row?
+ if t >= w*w:
+ # wrap around
+ t -= w*w
+ # next row
+ t += 1
+ return flipped
def to_file(filename, data):
- file = open(filename, 'wb')
- for byte in data:
- file.write('%c' % byte)
- file.close()
+ file = open(filename, 'wb')
+ for byte in data:
+ file.write('%c' % byte)
+ file.close()
@@ -184,578 +195,605 @@ lowmax = 1 << 5 # standard 5-bit param
class Compressed:
- """compress 2bpp data"""
-
- def __init__(self, image = None, mode = 'horiz', size = None):
-
- assert image, 'need something to compress!'
- image = list(image)
- self.image = image
- self.pic = []
- self.animtiles = []
- # only transpose pic (animtiles were never transposed in decompression)
- if size != None:
- for byte in range((size*size)*16):
- self.pic += image[byte]
- for byte in range(((size*size)*16),len(image)):
- self.animtiles += image[byte]
- else:
- self.pic = image
+ """
+ Compress 2bpp data.
+ """
- if mode == 'vert':
- self.tiles = get_tiles(self.pic)
- self.tiles = transpose(self.tiles)
- self.pic = connect(self.tiles)
+ def __init__(self, image=None, mode='horiz', size=None):
+ assert image, 'need something to compress!'
+ image = list(image)
+ self.image = image
+ self.pic = []
+ self.animtiles = []
- self.image = self.pic + self.animtiles
+ # only transpose pic (animtiles were never transposed in decompression)
+ if size != None:
+ for byte in range((size*size)*16):
+ self.pic += image[byte]
+ for byte in range(((size*size)*16),len(image)):
+ self.animtiles += image[byte]
+ else:
+ self.pic = image
- self.end = len(self.image)
+ if mode == 'vert':
+ self.tiles = get_tiles(self.pic)
+ self.tiles = transpose(self.tiles)
+ self.pic = connect(self.tiles)
- self.byte = None
- self.address = 0
+ self.image = self.pic + self.animtiles
- self.stream = []
+ self.end = len(self.image)
- self.zeros = []
- self.alts = []
- self.iters = []
- self.repeats = []
- self.flips = []
- self.reverses = []
- self.literals = []
+ self.byte = None
+ self.address = 0
- self.output = []
+ self.stream = []
- self.compress()
+ self.zeros = []
+ self.alts = []
+ self.iters = []
+ self.repeats = []
+ self.flips = []
+ self.reverses = []
+ self.literals = []
+ self.output = []
- def compress(self):
- """incomplete, but outputs working compressed data"""
+ self.compress()
- self.address = 0
- # todo
- #self.scanRepeats()
+ def compress(self):
+ """
+ Incomplete, but outputs working compressed data.
+ """
- while ( self.address < self.end ):
+ self.address = 0
- #if (self.repeats):
- # self.doRepeats()
+ # todo
+ #self.scanRepeats()
- #if (self.flips):
- # self.doFlips()
-
- #if (self.reverses):
- # self.doReverses
-
- if (self.checkWhitespace()):
- self.doLiterals()
- self.doWhitespace()
-
- elif (self.checkIter()):
- self.doLiterals()
- self.doIter()
-
- elif (self.checkAlts()):
- self.doLiterals()
- self.doAlts()
-
- else: # doesn't fit any pattern -> literal
- self.addLiteral()
- self.next()
-
- self.doStream()
-
- # add any literals we've been sitting on
- self.doLiterals()
-
- # done
- self.output.append(lz_end)
-
-
- def getCurByte(self):
- if self.address < self.end:
- self.byte = ord(self.image[self.address])
- else: self.byte = None
-
- def next(self):
- self.address += 1
- self.getCurByte()
-
- def addLiteral(self):
- self.getCurByte()
- self.literals.append(self.byte)
- if len(self.literals) > max_length:
- raise Exception, "literals exceeded max length and the compressor didn't catch it"
- elif len(self.literals) == max_length:
- self.doLiterals()
-
- def doLiterals(self):
- if len(self.literals) > lowmax:
- self.output.append( (lz_hi << 5) | (lz_lit << 2) | ((len(self.literals) - 1) >> 8) )
- self.output.append( (len(self.literals) - 1) & 0xff )
- elif len(self.literals) > 0:
- self.output.append( (lz_lit << 5) | (len(self.literals) - 1) )
- for byte in self.literals:
- self.output.append(byte)
- self.literals = []
-
- def doStream(self):
- for byte in self.stream:
- self.output.append(byte)
- self.stream = []
-
-
- def scanRepeats(self):
- """works, but doesn't do flipped/reversed streams yet
-
- this takes up most of the compress time and only saves a few bytes
- it might be more feasible to exclude it entirely"""
-
- self.repeats = []
- self.flips = []
- self.reverses = []
-
- # make a 5-letter word list of the sequence
- letters = 5 # how many bytes it costs to use a repeat over a literal
- # any shorter and it's not worth the trouble
- num_words = len(self.image) - letters
- words = []
- for i in range(self.address,num_words):
- word = []
- for j in range(letters):
- word.append( ord(self.image[i+j]) )
- words.append((word, i))
-
- zeros = []
- for zero in range(letters):
- zeros.append( 0 )
-
- # check for matches
- def get_matches():
- # TODO:
- # append to 3 different match lists instead of yielding to one
- #
- #flipped = []
- #for byte in enumerate(this[0]):
- # flipped.append( sum(1<<(7-i) for i in range(8) if (this[0][byte])>>i&1) )
- #reversed = this[0][::-1]
- #
- for whereabout, this in enumerate(words):
- for that in range(whereabout+1,len(words)):
- if words[that][0] == this[0]:
- if words[that][1] - this[1] >= letters:
- # remove zeros
- if this[0] != zeros:
- yield [this[0], this[1], words[that][1]]
-
- matches = list(get_matches())
-
- # remove more zeros
- buffer = []
- for match in matches:
- # count consecutive zeros in a word
- num_zeros = 0
- highest = 0
- for j in range(letters):
- if match[0][j] == 0:
- num_zeros += 1
- else:
- if highest < num_zeros: highest = num_zeros
- num_zeros = 0
- if highest < 4:
- # any more than 3 zeros in a row isn't worth it
- # (and likely to already be accounted for)
- buffer.append(match)
- matches = buffer
-
- # combine overlapping matches
- buffer = []
- for this, match in enumerate(matches):
- if this < len(matches) - 1: # special case for the last match
- if matches[this+1][1] <= (match[1] + len(match[0])): # check overlap
- if match[1] + len(match[0]) < match[2]:
- # next match now contains this match's bytes too
- # this only appends the last byte (assumes overlaps are +1
- match[0].append(matches[this+1][0][-1])
- matches[this+1] = match
- elif match[1] + len(match[0]) == match[2]:
- # we've run into the thing we matched
- buffer.append(match)
- # else we've gone past it and we can ignore it
- else: # no more overlaps
- buffer.append(match)
- else: # last match, so there's nothing to check
- buffer.append(match)
- matches = buffer
-
- # remove alternating sequences
- buffer = []
- for match in matches:
- for i in range(6 if letters > 6 else letters):
- if match[0][i] != match[0][i&1]:
- buffer.append(match)
- break
- matches = buffer
-
- self.repeats = matches
-
-
- def doRepeats(self):
- """doesn't output the right values yet"""
-
- unusedrepeats = []
- for repeat in self.repeats:
- if self.address >= repeat[2]:
-
- # how far in we are
- length = (len(repeat[0]) - (self.address - repeat[2]))
-
- # decide which side we're copying from
- if (self.address - repeat[1]) <= 0x80:
- self.doLiterals()
- self.stream.append( (lz_repeat << 5) | length - 1 )
-
- # wrong?
- self.stream.append( (((self.address - repeat[1])^0xff)+1)&0xff )
-
- else:
- self.doLiterals()
- self.stream.append( (lz_repeat << 5) | length - 1 )
-
- # wrong?
- self.stream.append(repeat[1]>>8)
- self.stream.append(repeat[1]&0xff)
-
- #print hex(self.address) + ': ' + hex(len(self.output)) + ' ' + hex(length)
- self.address += length
-
- else: unusedrepeats.append(repeat)
-
- self.repeats = unusedrepeats
-
-
- def checkWhitespace(self):
- self.zeros = []
- self.getCurByte()
- original_address = self.address
-
- if ( self.byte == 0 ):
- while ( self.byte == 0 ) & ( len(self.zeros) <= max_length ):
- self.zeros.append(self.byte)
- self.next()
- if len(self.zeros) > 1:
- return True
- self.address = original_address
- return False
-
- def doWhitespace(self):
- if (len(self.zeros) + 1) >= lowmax:
- self.stream.append( (lz_hi << 5) | (lz_zeros << 2) | ((len(self.zeros) - 1) >> 8) )
- self.stream.append( (len(self.zeros) - 1) & 0xff )
- elif len(self.zeros) > 1:
- self.stream.append( lz_zeros << 5 | (len(self.zeros) - 1) )
- else:
- raise Exception, "checkWhitespace() should prevent this from happening"
-
-
- def checkAlts(self):
- self.alts = []
- self.getCurByte()
- original_address = self.address
- num_alts = 0
-
- # make sure we don't check for alts at the end of the file
- if self.address+3 >= self.end: return False
-
- self.alts.append(self.byte)
- self.alts.append(ord(self.image[self.address+1]))
-
- # are we onto smething?
- if ( ord(self.image[self.address+2]) == self.alts[0] ):
- cur_alt = 0
- while (ord(self.image[(self.address)+1]) == self.alts[num_alts&1]) & (num_alts <= max_length):
- num_alts += 1
- self.next()
- # include the last alternated byte
- num_alts += 1
- self.address = original_address
- if num_alts > lowmax:
- return True
- elif num_alts > 2:
- return True
- return False
-
- def doAlts(self):
- original_address = self.address
- self.getCurByte()
-
- #self.alts = []
- #num_alts = 0
-
- #self.alts.append(self.byte)
- #self.alts.append(ord(self.image[self.address+1]))
-
- #i = 0
- #while (ord(self.image[self.address+1]) == self.alts[i^1]) & (num_alts <= max_length):
- # num_alts += 1
- # i ^=1
- # self.next()
- ## include the last alternated byte
- #num_alts += 1
-
- num_alts = len(self.iters) + 1
-
- if num_alts > lowmax:
- self.stream.append( (lz_hi << 5) | (lz_alt << 2) | ((num_alts - 1) >> 8) )
- self.stream.append( num_alts & 0xff )
- self.stream.append( self.alts[0] )
- self.stream.append( self.alts[1] )
- elif num_alts > 2:
- self.stream.append( (lz_alt << 5) | (num_alts - 1) )
- self.stream.append( self.alts[0] )
- self.stream.append( self.alts[1] )
- else:
- raise Exception, "checkAlts() should prevent this from happening"
-
- self.address = original_address
- self.address += num_alts
-
-
- def checkIter(self):
- self.iters = []
- self.getCurByte()
- iter = self.byte
- original_address = self.address
- while (self.byte == iter) & (len(self.iters) < max_length):
- self.iters.append(self.byte)
- self.next()
- self.address = original_address
- if len(self.iters) > 3:
- # 3 or fewer isn't worth the trouble and actually longer
- # if part of a larger literal set
- return True
-
- return False
-
- def doIter(self):
- self.getCurByte()
- iter = self.byte
- original_address = self.address
-
- self.iters = []
- while (self.byte == iter) & (len(self.iters) < max_length):
- self.iters.append(self.byte)
- self.next()
-
- if (len(self.iters) - 1) >= lowmax:
- self.stream.append( (lz_hi << 5) | (lz_iter << 2) | ((len(self.iters)-1) >> 8) )
- self.stream.append( (len(self.iters) - 1) & 0xff )
- self.stream.append( iter )
- elif len(self.iters) > 3:
- # 3 or fewer isn't worth the trouble and actually longer
- # if part of a larger literal set
- self.stream.append( (lz_iter << 5) | (len(self.iters) - 1) )
- self.stream.append( iter )
- else:
- self.address = original_address
- raise Exception, "checkIter() should prevent this from happening"
+ while ( self.address < self.end ):
+
+ #if (self.repeats):
+ # self.doRepeats()
+
+ #if (self.flips):
+ # self.doFlips()
+
+ #if (self.reverses):
+ # self.doReverses
+
+ if (self.checkWhitespace()):
+ self.doLiterals()
+ self.doWhitespace()
+
+ elif (self.checkIter()):
+ self.doLiterals()
+ self.doIter()
+
+ elif (self.checkAlts()):
+ self.doLiterals()
+ self.doAlts()
+
+ else: # doesn't fit any pattern -> literal
+ self.addLiteral()
+ self.next()
+
+ self.doStream()
+
+ # add any literals we've been sitting on
+ self.doLiterals()
+
+ # done
+ self.output.append(lz_end)
+
+
+ def getCurByte(self):
+ if self.address < self.end:
+ self.byte = ord(self.image[self.address])
+ else: self.byte = None
+
+ def next(self):
+ self.address += 1
+ self.getCurByte()
+
+ def addLiteral(self):
+ self.getCurByte()
+ self.literals.append(self.byte)
+ if len(self.literals) > max_length:
+ raise Exception, "literals exceeded max length and the compressor didn't catch it"
+ elif len(self.literals) == max_length:
+ self.doLiterals()
+
+ def doLiterals(self):
+ if len(self.literals) > lowmax:
+ self.output.append( (lz_hi << 5) | (lz_lit << 2) | ((len(self.literals) - 1) >> 8) )
+ self.output.append( (len(self.literals) - 1) & 0xff )
+ elif len(self.literals) > 0:
+ self.output.append( (lz_lit << 5) | (len(self.literals) - 1) )
+ for byte in self.literals:
+ self.output.append(byte)
+ self.literals = []
+
+ def doStream(self):
+ for byte in self.stream:
+ self.output.append(byte)
+ self.stream = []
+
+
+ def scanRepeats(self):
+ """
+ Works, but doesn't do flipped/reversed streams yet.
+
+ This takes up most of the compress time and only saves a few bytes
+ it might be more feasible to exclude it entirely.
+ """
+
+ self.repeats = []
+ self.flips = []
+ self.reverses = []
+
+ # make a 5-letter word list of the sequence
+ letters = 5 # how many bytes it costs to use a repeat over a literal
+ # any shorter and it's not worth the trouble
+ num_words = len(self.image) - letters
+ words = []
+ for i in range(self.address,num_words):
+ word = []
+ for j in range(letters):
+ word.append( ord(self.image[i+j]) )
+ words.append((word, i))
+
+ zeros = []
+ for zero in range(letters):
+ zeros.append( 0 )
+
+ # check for matches
+ def get_matches():
+ # TODO:
+ # append to 3 different match lists instead of yielding to one
+ #
+ #flipped = []
+ #for byte in enumerate(this[0]):
+ # flipped.append( sum(1<<(7-i) for i in range(8) if (this[0][byte])>>i&1) )
+ #reversed = this[0][::-1]
+ #
+ for whereabout, this in enumerate(words):
+ for that in range(whereabout+1,len(words)):
+ if words[that][0] == this[0]:
+ if words[that][1] - this[1] >= letters:
+ # remove zeros
+ if this[0] != zeros:
+ yield [this[0], this[1], words[that][1]]
+
+ matches = list(get_matches())
+
+ # remove more zeros
+ buffer = []
+ for match in matches:
+ # count consecutive zeros in a word
+ num_zeros = 0
+ highest = 0
+ for j in range(letters):
+ if match[0][j] == 0:
+ num_zeros += 1
+ else:
+ if highest < num_zeros: highest = num_zeros
+ num_zeros = 0
+ if highest < 4:
+ # any more than 3 zeros in a row isn't worth it
+ # (and likely to already be accounted for)
+ buffer.append(match)
+ matches = buffer
+
+ # combine overlapping matches
+ buffer = []
+ for this, match in enumerate(matches):
+ if this < len(matches) - 1: # special case for the last match
+ if matches[this+1][1] <= (match[1] + len(match[0])): # check overlap
+ if match[1] + len(match[0]) < match[2]:
+ # next match now contains this match's bytes too
+ # this only appends the last byte (assumes overlaps are +1
+ match[0].append(matches[this+1][0][-1])
+ matches[this+1] = match
+ elif match[1] + len(match[0]) == match[2]:
+ # we've run into the thing we matched
+ buffer.append(match)
+ # else we've gone past it and we can ignore it
+ else: # no more overlaps
+ buffer.append(match)
+ else: # last match, so there's nothing to check
+ buffer.append(match)
+ matches = buffer
+
+ # remove alternating sequences
+ buffer = []
+ for match in matches:
+ for i in range(6 if letters > 6 else letters):
+ if match[0][i] != match[0][i&1]:
+ buffer.append(match)
+ break
+ matches = buffer
+
+ self.repeats = matches
+
+
+ def doRepeats(self):
+ """doesn't output the right values yet"""
+
+ unusedrepeats = []
+ for repeat in self.repeats:
+ if self.address >= repeat[2]:
+
+ # how far in we are
+ length = (len(repeat[0]) - (self.address - repeat[2]))
+
+ # decide which side we're copying from
+ if (self.address - repeat[1]) <= 0x80:
+ self.doLiterals()
+ self.stream.append( (lz_repeat << 5) | length - 1 )
+
+ # wrong?
+ self.stream.append( (((self.address - repeat[1])^0xff)+1)&0xff )
+
+ else:
+ self.doLiterals()
+ self.stream.append( (lz_repeat << 5) | length - 1 )
+
+ # wrong?
+ self.stream.append(repeat[1]>>8)
+ self.stream.append(repeat[1]&0xff)
+
+ #print hex(self.address) + ': ' + hex(len(self.output)) + ' ' + hex(length)
+ self.address += length
+
+ else: unusedrepeats.append(repeat)
+
+ self.repeats = unusedrepeats
+
+
+ def checkWhitespace(self):
+ self.zeros = []
+ self.getCurByte()
+ original_address = self.address
+
+ if ( self.byte == 0 ):
+ while ( self.byte == 0 ) & ( len(self.zeros) <= max_length ):
+ self.zeros.append(self.byte)
+ self.next()
+ if len(self.zeros) > 1:
+ return True
+ self.address = original_address
+ return False
+
+ def doWhitespace(self):
+ if (len(self.zeros) + 1) >= lowmax:
+ self.stream.append( (lz_hi << 5) | (lz_zeros << 2) | ((len(self.zeros) - 1) >> 8) )
+ self.stream.append( (len(self.zeros) - 1) & 0xff )
+ elif len(self.zeros) > 1:
+ self.stream.append( lz_zeros << 5 | (len(self.zeros) - 1) )
+ else:
+ raise Exception, "checkWhitespace() should prevent this from happening"
+
+
+ def checkAlts(self):
+ self.alts = []
+ self.getCurByte()
+ original_address = self.address
+ num_alts = 0
+
+ # make sure we don't check for alts at the end of the file
+ if self.address+3 >= self.end: return False
+
+ self.alts.append(self.byte)
+ self.alts.append(ord(self.image[self.address+1]))
+
+ # are we onto smething?
+ if ( ord(self.image[self.address+2]) == self.alts[0] ):
+ cur_alt = 0
+ while (ord(self.image[(self.address)+1]) == self.alts[num_alts&1]) & (num_alts <= max_length):
+ num_alts += 1
+ self.next()
+ # include the last alternated byte
+ num_alts += 1
+ self.address = original_address
+ if num_alts > lowmax:
+ return True
+ elif num_alts > 2:
+ return True
+ return False
+
+ def doAlts(self):
+ original_address = self.address
+ self.getCurByte()
+
+ #self.alts = []
+ #num_alts = 0
+
+ #self.alts.append(self.byte)
+ #self.alts.append(ord(self.image[self.address+1]))
+
+ #i = 0
+ #while (ord(self.image[self.address+1]) == self.alts[i^1]) & (num_alts <= max_length):
+ # num_alts += 1
+ # i ^=1
+ # self.next()
+ ## include the last alternated byte
+ #num_alts += 1
+
+ num_alts = len(self.iters) + 1
+
+ if num_alts > lowmax:
+ self.stream.append( (lz_hi << 5) | (lz_alt << 2) | ((num_alts - 1) >> 8) )
+ self.stream.append( num_alts & 0xff )
+ self.stream.append( self.alts[0] )
+ self.stream.append( self.alts[1] )
+ elif num_alts > 2:
+ self.stream.append( (lz_alt << 5) | (num_alts - 1) )
+ self.stream.append( self.alts[0] )
+ self.stream.append( self.alts[1] )
+ else:
+ raise Exception, "checkAlts() should prevent this from happening"
+
+ self.address = original_address
+ self.address += num_alts
+
+
+ def checkIter(self):
+ self.iters = []
+ self.getCurByte()
+ iter = self.byte
+ original_address = self.address
+ while (self.byte == iter) & (len(self.iters) < max_length):
+ self.iters.append(self.byte)
+ self.next()
+ self.address = original_address
+ if len(self.iters) > 3:
+ # 3 or fewer isn't worth the trouble and actually longer
+ # if part of a larger literal set
+ return True
+
+ return False
+
+ def doIter(self):
+ self.getCurByte()
+ iter = self.byte
+ original_address = self.address
+
+ self.iters = []
+ while (self.byte == iter) & (len(self.iters) < max_length):
+ self.iters.append(self.byte)
+ self.next()
+
+ if (len(self.iters) - 1) >= lowmax:
+ self.stream.append( (lz_hi << 5) | (lz_iter << 2) | ((len(self.iters)-1) >> 8) )
+ self.stream.append( (len(self.iters) - 1) & 0xff )
+ self.stream.append( iter )
+ elif len(self.iters) > 3:
+ # 3 or fewer isn't worth the trouble and actually longer
+ # if part of a larger literal set
+ self.stream.append( (lz_iter << 5) | (len(self.iters) - 1) )
+ self.stream.append( iter )
+ else:
+ self.address = original_address
+ raise Exception, "checkIter() should prevent this from happening"
class Decompressed:
- """parse compressed 2bpp data
+ """
+ Parse compressed 2bpp data.
- parameters:
- [compressed 2bpp data]
- [tile arrangement] default: 'vert'
- [size of pic] default: None
- [start] (optional)
+ parameters:
+ [compressed 2bpp data]
+ [tile arrangement] default: 'vert'
+ [size of pic] default: None
+ [start] (optional)
- splits output into pic [size] and animation tiles if applicable
- data can be fed in from rom if [start] is specified"""
+ splits output into pic [size] and animation tiles if applicable
+ data can be fed in from rom if [start] is specified
+ """
- def __init__(self, lz = None, mode = None, size = None, start = 0):
- # todo: play nice with Compressed
+ def __init__(self, lz=None, mode=None, size=None, start=0):
+ # todo: play nice with Compressed
+
+ assert lz, 'need something to compress!'
+ self.lz = lz
- assert lz, 'need something to compress!'
- self.lz = lz
-
- self.byte = None
- self.address = 0
- self.start = start
-
- self.output = []
-
- self.decompress()
-
- debug = False
- # print tuple containing start and end address
- if debug: print '(' + hex(self.start) + ', ' + hex(self.start + self.address+1) + '),'
-
- # only transpose pic
- self.pic = []
- self.animtiles = []
-
- if size != None:
- self.tiles = get_tiles(self.output)
- self.pic = connect(self.tiles[:(size*size)])
- self.animtiles = connect(self.tiles[(size*size):])
- else: self.pic = self.output
-
- if mode == 'vert':
- self.tiles = get_tiles(self.pic)
- self.tiles = transpose(self.tiles)
- self.pic = connect(self.tiles)
-
- self.output = self.pic + self.animtiles
-
-
- def decompress(self):
- """replica of crystal's decompression"""
-
- self.output = []
-
- while True:
- self.getCurByte()
-
- if (self.byte == lz_end):
- break
-
- self.cmd = (self.byte & 0b11100000) >> 5
-
- if self.cmd == lz_hi: # 10-bit param
- self.cmd = (self.byte & 0b00011100) >> 2
- self.length = (self.byte & 0b00000011) << 8
- self.next()
- self.length += self.byte + 1
- else: # 5-bit param
- self.length = (self.byte & 0b00011111) + 1
-
- # literals
- if self.cmd == lz_lit:
- self.doLiteral()
- elif self.cmd == lz_iter:
- self.doIter()
- elif self.cmd == lz_alt:
- self.doAlt()
- elif self.cmd == lz_zeros:
- self.doZeros()
-
- else: # repeaters
- self.next()
- if self.byte > 0x7f: # negative
- self.displacement = self.byte & 0x7f
- self.displacement = len(self.output) - self.displacement - 1
- else: # positive
- self.displacement = self.byte * 0x100
- self.next()
- self.displacement += self.byte
-
- if self.cmd == lz_flip:
- self.doFlip()
- elif self.cmd == lz_reverse:
- self.doReverse()
- else: # lz_repeat
- self.doRepeat()
-
- self.address += 1
- #self.next() # somewhat of a hack
-
-
- def getCurByte(self):
- self.byte = ord(self.lz[self.start+self.address])
-
- def next(self):
- self.address += 1
- self.getCurByte()
-
- def doLiteral(self):
- # copy 2bpp data directly
- for byte in range(self.length):
- self.next()
- self.output.append(self.byte)
-
- def doIter(self):
- # write one byte repeatedly
- self.next()
- for byte in range(self.length):
- self.output.append(self.byte)
-
- def doAlt(self):
- # write alternating bytes
- self.alts = []
- self.next()
- self.alts.append(self.byte)
- self.next()
- self.alts.append(self.byte)
-
- for byte in range(self.length):
- self.output.append(self.alts[byte&1])
-
- def doZeros(self):
- # write zeros
- for byte in range(self.length):
- self.output.append(0x00)
-
- def doFlip(self):
- # repeat flipped bytes from 2bpp output
- # eg 11100100 -> 00100111
- # quat 3 2 1 0 -> 0 2 1 3
- for byte in range(self.length):
- flipped = sum(1<<(7-i) for i in range(8) if self.output[self.displacement+byte]>>i&1)
- self.output.append(flipped)
-
- def doReverse(self):
- # repeat reversed bytes from 2bpp output
- for byte in range(self.length):
- self.output.append(self.output[self.displacement-byte])
-
- def doRepeat(self):
- # repeat bytes from 2bpp output
- for byte in range(self.length):
- self.output.append(self.output[self.displacement+byte])
+ self.byte = None
+ self.address = 0
+ self.start = start
+
+ self.output = []
+
+ self.decompress()
+
+ debug = False
+ # print tuple containing start and end address
+ if debug: print '(' + hex(self.start) + ', ' + hex(self.start + self.address+1) + '),'
+
+ # only transpose pic
+ self.pic = []
+ self.animtiles = []
+
+ if size != None:
+ self.tiles = get_tiles(self.output)
+ self.pic = connect(self.tiles[:(size*size)])
+ self.animtiles = connect(self.tiles[(size*size):])
+ else: self.pic = self.output
+
+ if mode == 'vert':
+ self.tiles = get_tiles(self.pic)
+ self.tiles = transpose(self.tiles)
+ self.pic = connect(self.tiles)
+
+ self.output = self.pic + self.animtiles
+
+
+ def decompress(self):
+ """
+ Replica of crystal's decompression.
+ """
+
+ self.output = []
+
+ while True:
+ self.getCurByte()
+
+ if (self.byte == lz_end):
+ break
+
+ self.cmd = (self.byte & 0b11100000) >> 5
+
+ if self.cmd == lz_hi: # 10-bit param
+ self.cmd = (self.byte & 0b00011100) >> 2
+ self.length = (self.byte & 0b00000011) << 8
+ self.next()
+ self.length += self.byte + 1
+ else: # 5-bit param
+ self.length = (self.byte & 0b00011111) + 1
+
+ # literals
+ if self.cmd == lz_lit:
+ self.doLiteral()
+ elif self.cmd == lz_iter:
+ self.doIter()
+ elif self.cmd == lz_alt:
+ self.doAlt()
+ elif self.cmd == lz_zeros:
+ self.doZeros()
+
+ else: # repeaters
+ self.next()
+ if self.byte > 0x7f: # negative
+ self.displacement = self.byte & 0x7f
+ self.displacement = len(self.output) - self.displacement - 1
+ else: # positive
+ self.displacement = self.byte * 0x100
+ self.next()
+ self.displacement += self.byte
+
+ if self.cmd == lz_flip:
+ self.doFlip()
+ elif self.cmd == lz_reverse:
+ self.doReverse()
+ else: # lz_repeat
+ self.doRepeat()
+
+ self.address += 1
+ #self.next() # somewhat of a hack
+
+
+ def getCurByte(self):
+ self.byte = ord(self.lz[self.start+self.address])
+
+ def next(self):
+ self.address += 1
+ self.getCurByte()
+
+ def doLiteral(self):
+ """
+ Copy 2bpp data directly.
+ """
+ for byte in range(self.length):
+ self.next()
+ self.output.append(self.byte)
+
+ def doIter(self):
+ """
+ Write one byte repeatedly.
+ """
+ self.next()
+ for byte in range(self.length):
+ self.output.append(self.byte)
+
+ def doAlt(self):
+ """
+ Write alternating bytes.
+ """
+ self.alts = []
+ self.next()
+ self.alts.append(self.byte)
+ self.next()
+ self.alts.append(self.byte)
+
+ for byte in range(self.length):
+ self.output.append(self.alts[byte&1])
+
+ def doZeros(self):
+ """
+ Write zeros.
+ """
+ for byte in range(self.length):
+ self.output.append(0x00)
+
+ def doFlip(self):
+ """
+ Repeat flipped bytes from 2bpp output.
+
+ eg 11100100 -> 00100111
+ quat 3 2 1 0 -> 0 2 1 3
+ """
+ for byte in range(self.length):
+ flipped = sum(1<<(7-i) for i in range(8) if self.output[self.displacement+byte]>>i&1)
+ self.output.append(flipped)
+
+ def doReverse(self):
+ """
+ Repeat reversed bytes from 2bpp output.
+ """
+ for byte in range(self.length):
+ self.output.append(self.output[self.displacement-byte])
+
+ def doRepeat(self):
+ """
+ Repeat bytes from 2bpp output.
+ """
+ for byte in range(self.length):
+ self.output.append(self.output[self.displacement+byte])
sizes = [
- 5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 5, 7, 5, 5, 7, 5,
- 6, 7, 5, 6, 5, 7, 5, 7, 5, 7, 5, 6, 5, 6, 7, 5,
- 6, 7, 5, 6, 6, 7, 5, 6, 5, 7, 5, 6, 7, 5, 7, 5,
- 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 6, 7, 5, 6,
- 7, 5, 7, 7, 5, 6, 7, 5, 6, 5, 6, 6, 6, 7, 5, 7,
- 5, 6, 6, 5, 7, 6, 7, 5, 7, 5, 7, 7, 6, 6, 7, 6,
- 7, 5, 7, 5, 5, 7, 7, 5, 6, 7, 6, 7, 6, 7, 7, 7,
- 6, 6, 7, 5, 6, 6, 7, 6, 6, 6, 7, 6, 6, 6, 7, 7,
- 6, 7, 7, 5, 5, 6, 6, 6, 6, 5, 6, 5, 6, 7, 7, 7,
- 7, 7, 5, 6, 7, 7, 5, 5, 6, 7, 5, 6, 7, 5, 6, 7,
- 6, 6, 5, 7, 6, 6, 5, 7, 7, 6, 6, 5, 5, 5, 5, 7,
- 5, 6, 5, 6, 7, 7, 5, 7, 6, 7, 5, 6, 7, 5, 5, 6,
- 6, 5, 6, 6, 6, 6, 7, 6, 5, 6, 7, 5, 7, 6, 6, 7,
- 6, 6, 5, 7, 5, 6, 6, 5, 7, 5, 6, 5, 6, 6, 5, 6,
- 6, 7, 7, 6, 7, 7, 5, 7, 6, 7, 7, 5, 7, 5, 6, 6,
- 6, 7, 7, 7, 7, 5, 6, 7, 7, 7, 5,
+ 5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 5, 7, 5, 5, 7, 5,
+ 6, 7, 5, 6, 5, 7, 5, 7, 5, 7, 5, 6, 5, 6, 7, 5,
+ 6, 7, 5, 6, 6, 7, 5, 6, 5, 7, 5, 6, 7, 5, 7, 5,
+ 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 6, 7, 5, 6,
+ 7, 5, 7, 7, 5, 6, 7, 5, 6, 5, 6, 6, 6, 7, 5, 7,
+ 5, 6, 6, 5, 7, 6, 7, 5, 7, 5, 7, 7, 6, 6, 7, 6,
+ 7, 5, 7, 5, 5, 7, 7, 5, 6, 7, 6, 7, 6, 7, 7, 7,
+ 6, 6, 7, 5, 6, 6, 7, 6, 6, 6, 7, 6, 6, 6, 7, 7,
+ 6, 7, 7, 5, 5, 6, 6, 6, 6, 5, 6, 5, 6, 7, 7, 7,
+ 7, 7, 5, 6, 7, 7, 5, 5, 6, 7, 5, 6, 7, 5, 6, 7,
+ 6, 6, 5, 7, 6, 6, 5, 7, 7, 6, 6, 5, 5, 5, 5, 7,
+ 5, 6, 5, 6, 7, 7, 5, 7, 6, 7, 5, 6, 7, 5, 5, 6,
+ 6, 5, 6, 6, 6, 6, 7, 6, 5, 6, 7, 5, 7, 6, 6, 7,
+ 6, 6, 5, 7, 5, 6, 6, 5, 7, 5, 6, 5, 6, 6, 5, 6,
+ 6, 7, 7, 6, 7, 7, 5, 7, 6, 7, 7, 5, 7, 5, 6, 6,
+ 6, 7, 7, 7, 7, 5, 6, 7, 7, 7, 5,
]
def make_sizes():
- """front pics have specified sizes"""
- top = 251
- base_stats = 0x51424
- # print monster sizes
- address = base_stats + 0x11
+ """
+ Front pics have specified sizes.
+ """
+ top = 251
+ base_stats = 0x51424
+ # print monster sizes
+ address = base_stats + 0x11
- output = ''
+ output = ''
- for id in range(top):
- size = (ord(rom[address])) & 0x0f
- if id % 16 == 0: output += '\n\t'
- output += str(size) + ', '
- address += 0x20
+ for id in range(top):
+ size = (ord(rom[address])) & 0x0f
+ if id % 16 == 0: output += '\n\t'
+ output += str(size) + ', '
+ address += 0x20
- print output
+ print output
@@ -763,22 +801,22 @@ fxs = 0xcfcf6
num_fx = 40
def decompress_fx_by_id(id):
- address = fxs + id*4 # len_fxptr
- # get size
- num_tiles = ord(rom[address]) # # tiles
- # get pointer
- bank = ord(rom[address+1])
- address = (ord(rom[address+3]) << 8) + ord(rom[address+2])
- address = (bank * 0x4000) + (address & 0x3fff)
- # decompress
- fx = Decompressed(rom, 'horiz', num_tiles, address)
- return fx
+ address = fxs + id*4 # len_fxptr
+ # get size
+ num_tiles = ord(rom[address]) # # tiles
+ # get pointer
+ bank = ord(rom[address+1])
+ address = (ord(rom[address+3]) << 8) + ord(rom[address+2])
+ address = (bank * 0x4000) + (address & 0x3fff)
+ # decompress
+ fx = Decompressed(rom, 'horiz', num_tiles, address)
+ return fx
def decompress_fx():
- for id in range(num_fx):
- fx = decompress_fx_by_id(id)
- filename = '../gfx/fx/' + str(id).zfill(3) + '.2bpp' # ../gfx/fx/039.2bpp
- to_file(filename, fx.pic)
+ for id in range(num_fx):
+ fx = decompress_fx_by_id(id)
+ filename = '../gfx/fx/' + str(id).zfill(3) + '.2bpp' # ../gfx/fx/039.2bpp
+ to_file(filename, fx.pic)
num_pics = 2
@@ -792,280 +830,286 @@ unowns = 0x124000
num_unowns = 26
unown_dex = 201
-def decompress_monster_by_id(id = 0, type = front):
- # no unowns here
- if id + 1 == unown_dex: return None
- # get size
- if type == front:
- size = sizes[id]
- else: size = None
- # get pointer
- address = monsters + (id*2 + type)*3 # bank, address
- bank = ord(rom[address]) + 0x36 # crystal
- address = (ord(rom[address+2]) << 8) + ord(rom[address+1])
- address = (bank * 0x4000) + (address & 0x3fff)
- # decompress
- monster = Decompressed(rom, 'vert', size, address)
- return monster
-
-def decompress_monsters(type = front):
- for id in range(num_monsters):
- # decompress
- monster = decompress_monster_by_id(id, type)
- if monster != None: # no unowns here
- if not type: # front
- filename = 'front.2bpp'
- folder = '../gfx/pics/' + str(id+1).zfill(3) + '/'
- to_file(folder+filename, monster.pic)
- filename = 'tiles.2bpp'
- folder = '../gfx/pics/' + str(id+1).zfill(3) + '/'
- to_file(folder+filename, monster.animtiles)
- else: # back
- filename = 'back.2bpp'
- folder = '../gfx/pics/' + str(id+1).zfill(3) + '/'
- to_file(folder+filename, monster.pic)
-
-
-def decompress_unown_by_id(letter, type = front):
- # get size
- if type == front:
- size = sizes[unown_dex-1]
- else: size = None
- # get pointer
- address = unowns + (letter*2 + type)*3 # bank, address
- bank = ord(rom[address]) + 0x36 # crystal
- address = (ord(rom[address+2]) << 8) + ord(rom[address+1])
- address = (bank * 0x4000) + (address & 0x3fff)
- # decompress
- unown = Decompressed(rom, 'vert', size, address)
- return unown
-
-def decompress_unowns(type = front):
- for letter in range(num_unowns):
- # decompress
- unown = decompress_unown_by_id(letter, type)
-
- if not type: # front
- filename = 'front.2bpp'
- folder = '../gfx/pics/' + str(unown_dex).zfill(3) + chr(ord('a') + letter) + '/'
- to_file(folder+filename, unown.pic)
- filename = 'tiles.2bpp'
- folder = '../gfx/anim/'
- to_file(folder+filename, unown.animtiles)
- else: # back
- filename = 'back.2bpp'
- folder = '../gfx/pics/' + str(unown_dex).zfill(3) + chr(ord('a') + letter) + '/'
- to_file(folder+filename, unown.pic)
+def decompress_monster_by_id(id=0, type=front):
+ # no unowns here
+ if id + 1 == unown_dex: return None
+ # get size
+ if type == front:
+ size = sizes[id]
+ else: size = None
+ # get pointer
+ address = monsters + (id*2 + type)*3 # bank, address
+ bank = ord(rom[address]) + 0x36 # crystal
+ address = (ord(rom[address+2]) << 8) + ord(rom[address+1])
+ address = (bank * 0x4000) + (address & 0x3fff)
+ # decompress
+ monster = Decompressed(rom, 'vert', size, address)
+ return monster
+
+def decompress_monsters(type=front):
+ for id in range(num_monsters):
+ # decompress
+ monster = decompress_monster_by_id(id, type)
+ if monster != None: # no unowns here
+ if not type: # front
+ filename = 'front.2bpp'
+ folder = '../gfx/pics/' + str(id+1).zfill(3) + '/'
+ to_file(folder+filename, monster.pic)
+ filename = 'tiles.2bpp'
+ folder = '../gfx/pics/' + str(id+1).zfill(3) + '/'
+ to_file(folder+filename, monster.animtiles)
+ else: # back
+ filename = 'back.2bpp'
+ folder = '../gfx/pics/' + str(id+1).zfill(3) + '/'
+ to_file(folder+filename, monster.pic)
+
+
+def decompress_unown_by_id(letter, type=front):
+ # get size
+ if type == front:
+ size = sizes[unown_dex-1]
+ else: size = None
+ # get pointer
+ address = unowns + (letter*2 + type)*3 # bank, address
+ bank = ord(rom[address]) + 0x36 # crystal
+ address = (ord(rom[address+2]) << 8) + ord(rom[address+1])
+ address = (bank * 0x4000) + (address & 0x3fff)
+ # decompress
+ unown = Decompressed(rom, 'vert', size, address)
+ return unown
+
+def decompress_unowns(type=front):
+ for letter in range(num_unowns):
+ # decompress
+ unown = decompress_unown_by_id(letter, type)
+
+ if not type: # front
+ filename = 'front.2bpp'
+ folder = '../gfx/pics/' + str(unown_dex).zfill(3) + chr(ord('a') + letter) + '/'
+ to_file(folder+filename, unown.pic)
+ filename = 'tiles.2bpp'
+ folder = '../gfx/anim/'
+ to_file(folder+filename, unown.animtiles)
+ else: # back
+ filename = 'back.2bpp'
+ folder = '../gfx/pics/' + str(unown_dex).zfill(3) + chr(ord('a') + letter) + '/'
+ to_file(folder+filename, unown.pic)
trainers = 0x128000
num_trainers = 67
def decompress_trainer_by_id(id):
- # get pointer
- address = trainers + id*3 # bank, address
- bank = ord(rom[address]) + 0x36 # crystal
- address = (ord(rom[address+2]) << 8) + ord(rom[address+1])
- address = (bank * 0x4000) + (address & 0x3fff)
- # decompress
- trainer = Decompressed(rom, 'vert', None, address)
- return trainer
+ # get pointer
+ address = trainers + id*3 # bank, address
+ bank = ord(rom[address]) + 0x36 # crystal
+ address = (ord(rom[address+2]) << 8) + ord(rom[address+1])
+ address = (bank * 0x4000) + (address & 0x3fff)
+ # decompress
+ trainer = Decompressed(rom, 'vert', None, address)
+ return trainer
def decompress_trainers():
- for id in range(num_trainers):
- # decompress
- trainer = decompress_trainer_by_id(id)
- filename = '../gfx/trainers/' + str(id).zfill(3) + '.2bpp' # ../gfx/trainers/066.2bpp
- to_file(filename, trainer.pic)
+ for id in range(num_trainers):
+ # decompress
+ trainer = decompress_trainer_by_id(id)
+ filename = '../gfx/trainers/' + str(id).zfill(3) + '.2bpp' # ../gfx/trainers/066.2bpp
+ to_file(filename, trainer.pic)
# in order of use (sans repeats)
intro_gfx = [
- ('logo', 0x109407),
- ('001', 0xE641D), # tilemap
- ('unowns', 0xE5F5D),
- ('pulse', 0xE634D),
- ('002', 0xE63DD), # tilemap
- ('003', 0xE5ECD), # tilemap
- ('background', 0xE5C7D),
- ('004', 0xE5E6D), # tilemap
- ('005', 0xE647D), # tilemap
- ('006', 0xE642D), # tilemap
- ('pichu_wooper', 0xE592D),
- ('suicune_run', 0xE555D),
- ('007', 0xE655D), # tilemap
- ('008', 0xE649D), # tilemap
- ('009', 0xE76AD), # tilemap
- ('suicune_jump', 0xE6DED),
- ('unown_back', 0xE785D),
- ('010', 0xE764D), # tilemap
- ('011', 0xE6D0D), # tilemap
- ('suicune_close', 0xE681D),
- ('012', 0xE6C3D), # tilemap
- ('013', 0xE778D), # tilemap
- ('suicune_back', 0xE72AD),
- ('014', 0xE76BD), # tilemap
- ('015', 0xE676D), # tilemap
- ('crystal_unowns', 0xE662D),
- ('017', 0xE672D), # tilemap
+ ('logo', 0x109407),
+ ('001', 0xE641D), # tilemap
+ ('unowns', 0xE5F5D),
+ ('pulse', 0xE634D),
+ ('002', 0xE63DD), # tilemap
+ ('003', 0xE5ECD), # tilemap
+ ('background', 0xE5C7D),
+ ('004', 0xE5E6D), # tilemap
+ ('005', 0xE647D), # tilemap
+ ('006', 0xE642D), # tilemap
+ ('pichu_wooper', 0xE592D),
+ ('suicune_run', 0xE555D),
+ ('007', 0xE655D), # tilemap
+ ('008', 0xE649D), # tilemap
+ ('009', 0xE76AD), # tilemap
+ ('suicune_jump', 0xE6DED),
+ ('unown_back', 0xE785D),
+ ('010', 0xE764D), # tilemap
+ ('011', 0xE6D0D), # tilemap
+ ('suicune_close', 0xE681D),
+ ('012', 0xE6C3D), # tilemap
+ ('013', 0xE778D), # tilemap
+ ('suicune_back', 0xE72AD),
+ ('014', 0xE76BD), # tilemap
+ ('015', 0xE676D), # tilemap
+ ('crystal_unowns', 0xE662D),
+ ('017', 0xE672D), # tilemap
]
def decompress_intro():
- for name, address in intro_gfx:
- filename = '../gfx/intro/' + name + '.2bpp'
- gfx = Decompressed( rom, 'horiz', None, address )
- to_file(filename, gfx.output)
+ for name, address in intro_gfx:
+ filename = '../gfx/intro/' + name + '.2bpp'
+ gfx = Decompressed( rom, 'horiz', None, address )
+ to_file(filename, gfx.output)
title_gfx = [
- ('suicune', 0x10EF46),
- ('logo', 0x10F326),
- ('crystal', 0x10FCEE),
+ ('suicune', 0x10EF46),
+ ('logo', 0x10F326),
+ ('crystal', 0x10FCEE),
]
def decompress_title():
- for name, address in title_gfx:
- filename = '../gfx/title/' + name + '.2bpp'
- gfx = Decompressed( rom, 'horiz', None, address )
- to_file(filename, gfx.output)
+ for name, address in title_gfx:
+ filename = '../gfx/title/' + name + '.2bpp'
+ gfx = Decompressed( rom, 'horiz', None, address )
+ to_file(filename, gfx.output)
def decompress_tilesets():
- tileset_headers = 0x4d596
- len_tileset = 15
- num_tilesets = 0x25
- for tileset in range(num_tilesets):
- ptr = tileset*len_tileset + tileset_headers
- address = (ord(rom[ptr])*0x4000) + (((ord(rom[ptr+1]))+ord(rom[ptr+2])*0x100)&0x3fff)
- tiles = Decompressed( rom, 'horiz', None, address )
- filename = '../gfx/tilesets/'+str(tileset).zfill(2)+'.2bpp'
- to_file( filename, tiles.output )
- #print '(' + hex(address) + ', '+ hex(address+tiles.address+1) + '),'
+ tileset_headers = 0x4d596
+ len_tileset = 15
+ num_tilesets = 0x25
+ for tileset in range(num_tilesets):
+ ptr = tileset*len_tileset + tileset_headers
+ address = (ord(rom[ptr])*0x4000) + (((ord(rom[ptr+1]))+ord(rom[ptr+2])*0x100)&0x3fff)
+ tiles = Decompressed( rom, 'horiz', None, address )
+ filename = '../gfx/tilesets/'+str(tileset).zfill(2)+'.2bpp'
+ to_file( filename, tiles.output )
+ #print '(' + hex(address) + ', '+ hex(address+tiles.address+1) + '),'
misc = [
- ('player', 0x2BA1A, 'vert'),
- ('dude', 0x2BBAA, 'vert'),
- ('town_map', 0xF8BA0, 'horiz'),
- ('pokegear', 0x1DE2E4, 'horiz'),
- ('pokegear_sprites', 0x914DD, 'horiz'),
+ ('player', 0x2BA1A, 'vert'),
+ ('dude', 0x2BBAA, 'vert'),
+ ('town_map', 0xF8BA0, 'horiz'),
+ ('pokegear', 0x1DE2E4, 'horiz'),
+ ('pokegear_sprites', 0x914DD, 'horiz'),
]
def decompress_misc():
- for name, address, mode in misc:
- filename = '../gfx/misc/' + name + '.2bpp'
- gfx = Decompressed( rom, mode, None, address )
- to_file(filename, gfx.output)
+ for name, address, mode in misc:
+ filename = '../gfx/misc/' + name + '.2bpp'
+ gfx = Decompressed( rom, mode, None, address )
+ to_file(filename, gfx.output)
-def decompress_all(debug = False):
- """decompress all known compressed data in baserom"""
+def decompress_all(debug=False):
+ """
+ Decompress all known compressed data in baserom.
+ """
- if debug: print 'fronts'
- decompress_monsters(front)
- if debug: print 'backs'
- decompress_monsters(back)
- if debug: print 'unown fronts'
- decompress_unowns(front)
- if debug: print 'unown backs'
- decompress_unowns(back)
+ if debug: print 'fronts'
+ decompress_monsters(front)
+ if debug: print 'backs'
+ decompress_monsters(back)
+ if debug: print 'unown fronts'
+ decompress_unowns(front)
+ if debug: print 'unown backs'
+ decompress_unowns(back)
- if debug: print 'trainers'
- decompress_trainers()
+ if debug: print 'trainers'
+ decompress_trainers()
- if debug: print 'fx'
- decompress_fx()
+ if debug: print 'fx'
+ decompress_fx()
- if debug: print 'intro'
- decompress_intro()
+ if debug: print 'intro'
+ decompress_intro()
- if debug: print 'title'
- decompress_title()
+ if debug: print 'title'
+ decompress_title()
- if debug: print 'tilesets'
- decompress_tilesets()
+ if debug: print 'tilesets'
+ decompress_tilesets()
- if debug: print 'misc'
- decompress_misc()
+ if debug: print 'misc'
+ decompress_misc()
- return
+ return
-def decompress_from_address(address, mode='horiz', filename = 'de.2bpp', size = None):
- """write decompressed data from an address to a 2bpp file"""
- image = Decompressed(rom, mode, size, address)
- to_file(filename, image.pic)
+def decompress_from_address(address, mode='horiz', filename='de.2bpp', size=None):
+ """
+ Write decompressed data from an address to a 2bpp file.
+ """
+ image = Decompressed(rom, mode, size, address)
+ to_file(filename, image.pic)
-def decompress_file(filein, fileout, mode = 'horiz', size = None):
- f = open(filein, 'rb')
- image = f.read()
- f.close()
+def decompress_file(filein, fileout, mode='horiz', size=None):
+ f = open(filein, 'rb')
+ image = f.read()
+ f.close()
- de = Decompressed(image, mode, size)
+ de = Decompressed(image, mode, size)
- to_file(fileout, de.pic)
+ to_file(fileout, de.pic)
-def compress_file(filein, fileout, mode = 'horiz'):
- f = open(filein, 'rb')
- image = f.read()
- f.close()
+def compress_file(filein, fileout, mode='horiz'):
+ f = open(filein, 'rb')
+ image = f.read()
+ f.close()
- lz = Compressed(image, mode)
+ lz = Compressed(image, mode)
- to_file(fileout, lz.output)
+ to_file(fileout, lz.output)
def compress_monster_frontpic(id, fileout):
- mode = 'vert'
+ mode = 'vert'
- fpic = '../gfx/pics/' + str(id).zfill(3) + '/front.2bpp'
- fanim = '../gfx/pics/' + str(id).zfill(3) + '/tiles.2bpp'
+ fpic = '../gfx/pics/' + str(id).zfill(3) + '/front.2bpp'
+ fanim = '../gfx/pics/' + str(id).zfill(3) + '/tiles.2bpp'
- pic = open(fpic, 'rb').read()
- anim = open(fanim, 'rb').read()
- image = pic + anim
+ pic = open(fpic, 'rb').read()
+ anim = open(fanim, 'rb').read()
+ image = pic + anim
- lz = Compressed(image, mode, sizes[id-1])
+ lz = Compressed(image, mode, sizes[id-1])
- out = '../gfx/pics/' + str(id).zfill(3) + '/front.lz'
+ out = '../gfx/pics/' + str(id).zfill(3) + '/front.lz'
- to_file(out, lz.output)
+ to_file(out, lz.output)
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)
+ """
+ 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 hex_to_rgb(word):
- red = word & 0b11111
- word >>= 5
- green = word & 0b11111
- word >>= 5
- blue = word & 0b11111
- return (red, green, blue)
+ red = word & 0b11111
+ word >>= 5
+ green = word & 0b11111
+ word >>= 5
+ blue = word & 0b11111
+ return (red, green, blue)
-def grab_palettes(address, length = 0x80):
- output = ''
- for word in range(length/2):
- color = ord(rom[address+1])*0x100 + ord(rom[address])
- address += 2
- color = hex_to_rgb(color)
- red = str(color[0]).zfill(2)
- green = str(color[1]).zfill(2)
- blue = str(color[2]).zfill(2)
- output += '\tRGB '+red+', '+green+', '+blue
- output += '\n'
- return output
+def grab_palettes(address, length=0x80):
+ output = ''
+ for word in range(length/2):
+ color = ord(rom[address+1])*0x100 + ord(rom[address])
+ address += 2
+ color = hex_to_rgb(color)
+ red = str(color[0]).zfill(2)
+ green = str(color[1]).zfill(2)
+ blue = str(color[2]).zfill(2)
+ output += '\tRGB '+red+', '+green+', '+blue
+ output += '\n'
+ return output
@@ -1074,433 +1118,433 @@ def grab_palettes(address, length = 0x80):
def dump_monster_pals():
- rom = load_rom()
+ rom = load_rom()
- pals = 0xa8d6
- pal_length = 0x4
- for mon in range(251):
+ 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+'/'
+ name = pokemon_constants[mon+1].title().replace('_','')
+ num = str(mon+1).zfill(3)
+ dir = 'gfx/pics/'+num+'/'
- address = pals + mon*pal_length*2
+ address = pals + mon*pal_length*2
- pal_data = []
- for byte in range(pal_length):
- pal_data.append(ord(rom[address]))
- address += 1
+ 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)
+ filename = 'normal.pal'
+ to_file('../'+dir+filename, pal_data)
- spacing = ' ' * (15 - len(name))
- #print name+'Palette:'+spacing+' INCBIN "'+dir+filename+'"'
+ 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
+ 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)
+ filename = 'shiny.pal'
+ to_file('../'+dir+filename, pal_data)
- spacing = ' ' * (10 - len(name))
- #print name+'ShinyPalette:'+spacing+' INCBIN "'+dir+filename+'"'
+ spacing = ' ' * (10 - len(name))
+ #print name+'ShinyPalette:'+spacing+' INCBIN "'+dir+filename+'"'
def dump_trainer_pals():
- rom = load_rom()
+ rom = load_rom()
- pals = 0xb0d2
- pal_length = 0x4
- for trainer in range(67):
+ 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/'
+ name = trainer_group_names[trainer+1]['constant'].title().replace('_','')
+ num = str(trainer).zfill(3)
+ dir = 'gfx/trainers/'
- address = pals + trainer*pal_length
+ address = pals + trainer*pal_length
- pal_data = []
- for byte in range(pal_length):
- pal_data.append(ord(rom[address]))
- address += 1
+ 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)
+ filename = num+'.pal'
+ to_file('../'+dir+filename, pal_data)
- spacing = ' ' * (12 - len(name))
- print name+'Palette:'+spacing+' INCBIN"'+dir+filename+'"'
+ spacing = ' ' * (12 - len(name))
+ print name+'Palette:'+spacing+' INCBIN"'+dir+filename+'"'
def flatten(planar):
- """
- Flattens planar 2bpp image data into a quaternary pixel map.
- """
- strips = []
- for pair in range(len(planar)/2):
- bottom = ord(planar[(pair*2) ])
- top = ord(planar[(pair*2)+1])
- strip = []
- for i in range(7,-1,-1):
- color = ((bottom >> i) & 1) + (((top >> i-1) if i > 0 else (top << 1-i)) & 2)
- strip.append(color)
- strips += strip
- return strips
+ """
+ Flatten planar 2bpp image data into a quaternary pixel map.
+ """
+ strips = []
+ for pair in range(len(planar)/2):
+ bottom = ord(planar[(pair*2) ])
+ top = ord(planar[(pair*2)+1])
+ strip = []
+ for i in range(7,-1,-1):
+ color = ((bottom >> i) & 1) + (((top >> i-1) if i > 0 else (top << 1-i)) & 2)
+ strip.append(color)
+ strips += strip
+ return strips
def to_lines(image, width):
- """
- Converts a tiled quaternary pixel map to lines of quaternary pixels.
- """
-
- tile = 8 * 8
-
- # so we know how many strips of 8px we're putting into a line
- num_columns = width / 8
- # number of lines
- height = len(image) / width
-
- lines = []
- for cur_line in range(height):
- tile_row = int(cur_line / 8)
- line = []
- for column in range(num_columns):
- anchor = num_columns*tile_row*tile + column*tile + (cur_line%8)*8
- line += image[anchor:anchor+8]
- lines.append(line)
- return lines
+ """
+ Convert a tiled quaternary pixel map to lines of quaternary pixels.
+ """
+
+ tile = 8 * 8
+
+ # so we know how many strips of 8px we're putting into a line
+ num_columns = width / 8
+ # number of lines
+ height = len(image) / width
+
+ lines = []
+ for cur_line in range(height):
+ tile_row = int(cur_line / 8)
+ line = []
+ for column in range(num_columns):
+ anchor = num_columns*tile_row*tile + column*tile + (cur_line%8)*8
+ line += image[anchor:anchor+8]
+ lines.append(line)
+ return lines
def dmg2rgb(word):
- red = word & 0b11111
- word >>= 5
- green = word & 0b11111
- word >>= 5
- blue = word & 0b11111
- alpha = 255
- return ((red<<3)+0b100, (green<<3)+0b100, (blue<<3)+0b100, alpha)
-
+ red = word & 0b11111
+ word >>= 5
+ green = word & 0b11111
+ word >>= 5
+ blue = word & 0b11111
+ alpha = 255
+ return ((red<<3)+0b100, (green<<3)+0b100, (blue<<3)+0b100, alpha)
+
def rgb_to_dmg(color):
- word = (color['r'] / 8)
- word += (color['g'] / 8) << 5
- word += (color['b'] / 8) << 10
- return word
+ word = (color['r'] / 8)
+ word += (color['g'] / 8) << 5
+ word += (color['b'] / 8) << 10
+ return word
def png_pal(filename):
- palette = []
- with open(filename, 'rb') as pal_data:
- words = pal_data.read()
- dmg_pals = []
- for word in range(len(words)/2):
- dmg_pals.append(ord(words[word*2]) + ord(words[word*2+1])*0x100)
- white = (255,255,255,255)
- black = (000,000,000,255)
- for word in dmg_pals: palette += [dmg2rgb(word)]
- if white not in dmg_pals and len(palette) < 4: palette = [white] + palette
- if black not in dmg_pals and len(palette) < 4: palette += [black]
- return palette
+ palette = []
+ with open(filename, 'rb') as pal_data:
+ words = pal_data.read()
+ dmg_pals = []
+ for word in range(len(words)/2):
+ dmg_pals.append(ord(words[word*2]) + ord(words[word*2+1])*0x100)
+ white = (255,255,255,255)
+ black = (000,000,000,255)
+ for word in dmg_pals: palette += [dmg2rgb(word)]
+ if white not in dmg_pals and len(palette) < 4: palette = [white] + palette
+ if black not in dmg_pals and len(palette) < 4: palette += [black]
+ return palette
def to_png(filein, fileout=None, pal_file=None, height=None, width=None):
- """
- Takes a planar 2bpp graphics file and converts it to png.
- """
+ """
+ Take a planar 2bpp graphics file and converts it to png.
+ """
- if fileout == None: fileout = '.'.join(filein.split('.')[:-1]) + '.png'
+ if fileout == None: fileout = '.'.join(filein.split('.')[:-1]) + '.png'
- image = open(filein, 'rb').read()
+ image = open(filein, 'rb').read()
- num_pixels = len(image) * 4
+ num_pixels = len(image) * 4
- if num_pixels == 0: return 'empty image!'
+ if num_pixels == 0: return 'empty image!'
- # unless the pic is square, at least one dimension should be given
+ # unless the pic is square, at least one dimension should be given
- if width == None and height == None:
- width = int(sqrt(num_pixels))
- height = width
+ if width == None and height == None:
+ width = int(sqrt(num_pixels))
+ height = width
- elif height == None:
- height = num_pixels / width
+ elif height == None:
+ height = num_pixels / width
- elif width == None:
- width = num_pixels / height
+ elif width == None:
+ width = num_pixels / height
- # but try to see if it can be made rectangular
+ # but try to see if it can be made rectangular
- if width * height != num_pixels:
+ if width * height != num_pixels:
- # look for possible combos of width/height that would form a rectangle
- matches = []
+ # look for possible combos of width/height that would form a rectangle
+ matches = []
- # this is pretty inefficient, and there is probably a simpler way
- for width in range(8,256+1,8): # we only want dimensions that fit in tiles
- height = num_pixels / width
- if height % 8 == 0:
- matches.append((width, height))
+ # this is pretty inefficient, and there is probably a simpler way
+ for width in range(8,256+1,8): # we only want dimensions that fit in tiles
+ height = num_pixels / width
+ if height % 8 == 0:
+ matches.append((width, height))
- # go for the most square image
- width, height = sorted(matches, key=lambda (x,y): x+y)[0] # favors height
+ # go for the most square image
+ width, height = sorted(matches, key=lambda (x,y): x+y)[0] # favors height
- # if it can't, the only option is a width of 1 tile
+ # if it can't, the only option is a width of 1 tile
- if width * height != num_pixels:
- width = 8
- height = num_pixels / width
+ if width * height != num_pixels:
+ width = 8
+ height = num_pixels / width
- # if this still isn't rectangular, then the image isn't made of tiles
+ # if this still isn't rectangular, then the image isn't made of tiles
- # for now we'll just spit out a warning
- if width * height != num_pixels:
- print 'Warning! ' + fileout + ' is ' + width + 'x' + height + '(' + width*height + ' pixels),\n' +\
- 'but ' + filein + ' is ' + num_pixels + ' pixels!'
+ # for now we'll just spit out a warning
+ if width * height != num_pixels:
+ print 'Warning! ' + fileout + ' is ' + width + 'x' + height + '(' + width*height + ' pixels),\n' +\
+ 'but ' + filein + ' is ' + num_pixels + ' pixels!'
- # map it out
+ # map it out
- lines = to_lines(flatten(image), width)
+ lines = to_lines(flatten(image), width)
- if pal_file == None:
- if os.path.exists(os.path.splitext(fileout)[0]+'.pal'):
- pal_file = os.path.splitext(fileout)[0]+'.pal'
+ if pal_file == None:
+ if os.path.exists(os.path.splitext(fileout)[0]+'.pal'):
+ pal_file = os.path.splitext(fileout)[0]+'.pal'
- if pal_file == None:
- palette = None
- greyscale = True
- bitdepth = 2
- inverse = { 0:3, 1:2, 2:1, 3:0 }
- map = [[inverse[pixel] for pixel in line] for line in lines]
+ if pal_file == None:
+ palette = None
+ greyscale = True
+ bitdepth = 2
+ inverse = { 0:3, 1:2, 2:1, 3:0 }
+ map = [[inverse[pixel] for pixel in line] for line in lines]
- else: # gbc color
- palette = png_pal(pal_file)
- greyscale = False
- bitdepth = 8
- map = [[pixel for pixel in line] for line in lines]
+ else: # gbc color
+ palette = png_pal(pal_file)
+ greyscale = False
+ bitdepth = 8
+ map = [[pixel for pixel in line] for line in lines]
- w = png.Writer(width, height, palette=palette, compression = 9, greyscale = greyscale, bitdepth = bitdepth)
- with open(fileout, 'wb') as file:
- w.write(file, map)
+ w = png.Writer(width, height, palette=palette, compression = 9, greyscale = greyscale, bitdepth = bitdepth)
+ with open(fileout, 'wb') as file:
+ w.write(file, map)
def to_2bpp(filein, fileout=None, palout=None):
- """
- Takes a png and converts it to planar 2bpp.
- """
-
- if fileout == None: fileout = '.'.join(filein.split('.')[:-1]) + '.2bpp'
-
- with open(filein, 'rb') as file:
-
- r = png.Reader(file)
- info = r.asRGBA8()
-
- width = info[0]
- height = info[1]
-
- rgba = list(info[2])
- greyscale = info[3]['greyscale']
-
-
- padding = { 'left': 0,
- 'right': 0,
- 'top': 0,
- 'bottom': 0, }
- #if width % 8 != 0:
- # padding['left'] = int(ceil((width / 8 + 8 - width) / 2))
- # padding['right'] = int(floor((width / 8 + 8 - width) / 2))
- #if height % 8 != 0:
- # padding['top'] = int(ceil((height / 8 + 8 - height) / 2))
- # padding['bottom'] = int(floor((height / 8 + 8 - height) / 2))
-
-
- # turn the flat values into something more workable
-
- pixel_length = 4 # rgba
- image = []
-
- # while we're at it, let's size up the palette
-
- palette = []
-
- for line in rgba:
- newline = []
- for pixel in range(len(line)/pixel_length):
- i = pixel * pixel_length
- color = { 'r': line[i ],
- 'g': line[i+1],
- 'b': line[i+2],
- 'a': line[i+3], }
- newline += [color]
- if color not in palette: palette += [color]
- image.append(newline)
-
- # pad out any small palettes
- hues = {
- 'white': { 'r': 0xff, 'g': 0xff, 'b': 0xff, 'a': 0xff },
- 'black': { 'r': 0x00, 'g': 0x00, 'b': 0x00, 'a': 0xff },
- 'grey': { 'r': 0x55, 'g': 0x55, 'b': 0x55, 'a': 0xff },
- 'gray': { 'r': 0xaa, 'g': 0xaa, 'b': 0xaa, 'a': 0xff },
- }
- while len(palette) < 4:
- for hue in hues.values():
- if not any(color is hue for color in palette):
- palette += [hue]
- if len(palette) >= 4: break
-
- assert len(palette) <= 4, 'Palette should be 4 colors, is really ' + str(len(palette))
-
- # sort by luminance
- def luminance(color):
- # this is actually in reverse, thanks to dmg/cgb palette ordering
- rough = { 'r': 4.7,
- 'g': 1.4,
- 'b': 13.8, }
- return sum(color[key] * -rough[key] for key in rough.keys())
- palette = sorted(palette, key=luminance)
-
- # spit out a new .pal file
- # disable this if it causes problems with paletteless images
- if palout == None:
- if os.path.exists(os.path.splitext(fileout)[0]+'.pal'):
- palout = os.path.splitext(fileout)[0]+'.pal'
- if palout != None:
- output = []
- for color in palette:
- word = rgb_to_dmg(color)
- output += [word & 0xff]
- output += [word >> 8]
- to_file(palout, output)
-
- # create a new map of quaternary color ids
- map = []
- if padding['top']: map += [0] * (width + padding['left'] + padding['right']) * padding['top']
- for line in image:
- if padding['left']: map += [0] * padding['left']
- for color in line:
- map.append(palette.index(color))
- if padding['right']: map += [0] * padding['right']
- if padding['bottom']: map += [0] * (width + padding['left'] + padding['right']) * padding['bottom']
-
- # split it into strips of 8, and make them planar
- num_columns = width / 8
- num_rows = height / 8
- tile = 8 * 8
- image = []
- for row in range(num_rows):
- for column in range(num_columns):
- for strip in range(tile / 8):
- anchor = row*num_columns*tile + column*tile/8 + strip*width
- line = map[anchor:anchor+8]
- bottom = 0
- top = 0
- for bit, quad in enumerate(line):
- bottom += (quad & 1) << (7-bit)
- top += ((quad & 2) >> 1) << (7-bit)
- image.append(bottom)
- image.append(top)
-
- to_file(fileout, image)
+ """
+ Take a png and converts it to planar 2bpp.
+ """
+
+ if fileout == None: fileout = '.'.join(filein.split('.')[:-1]) + '.2bpp'
+
+ with open(filein, 'rb') as file:
+
+ r = png.Reader(file)
+ info = r.asRGBA8()
+
+ width = info[0]
+ height = info[1]
+
+ rgba = list(info[2])
+ greyscale = info[3]['greyscale']
+
+
+ padding = { 'left': 0,
+ 'right': 0,
+ 'top': 0,
+ 'bottom': 0, }
+ #if width % 8 != 0:
+ # padding['left'] = int(ceil((width / 8 + 8 - width) / 2))
+ # padding['right'] = int(floor((width / 8 + 8 - width) / 2))
+ #if height % 8 != 0:
+ # padding['top'] = int(ceil((height / 8 + 8 - height) / 2))
+ # padding['bottom'] = int(floor((height / 8 + 8 - height) / 2))
+
+
+ # turn the flat values into something more workable
+
+ pixel_length = 4 # rgba
+ image = []
+
+ # while we're at it, let's size up the palette
+
+ palette = []
+
+ for line in rgba:
+ newline = []
+ for pixel in range(len(line)/pixel_length):
+ i = pixel * pixel_length
+ color = { 'r': line[i ],
+ 'g': line[i+1],
+ 'b': line[i+2],
+ 'a': line[i+3], }
+ newline += [color]
+ if color not in palette: palette += [color]
+ image.append(newline)
+
+ # pad out any small palettes
+ hues = {
+ 'white': { 'r': 0xff, 'g': 0xff, 'b': 0xff, 'a': 0xff },
+ 'black': { 'r': 0x00, 'g': 0x00, 'b': 0x00, 'a': 0xff },
+ 'grey': { 'r': 0x55, 'g': 0x55, 'b': 0x55, 'a': 0xff },
+ 'gray': { 'r': 0xaa, 'g': 0xaa, 'b': 0xaa, 'a': 0xff },
+ }
+ while len(palette) < 4:
+ for hue in hues.values():
+ if not any(color is hue for color in palette):
+ palette += [hue]
+ if len(palette) >= 4: break
+
+ assert len(palette) <= 4, 'Palette should be 4 colors, is really ' + str(len(palette))
+
+ # sort by luminance
+ def luminance(color):
+ # this is actually in reverse, thanks to dmg/cgb palette ordering
+ rough = { 'r': 4.7,
+ 'g': 1.4,
+ 'b': 13.8, }
+ return sum(color[key] * -rough[key] for key in rough.keys())
+ palette = sorted(palette, key=luminance)
+
+ # spit out a new .pal file
+ # disable this if it causes problems with paletteless images
+ if palout == None:
+ if os.path.exists(os.path.splitext(fileout)[0]+'.pal'):
+ palout = os.path.splitext(fileout)[0]+'.pal'
+ if palout != None:
+ output = []
+ for color in palette:
+ word = rgb_to_dmg(color)
+ output += [word & 0xff]
+ output += [word >> 8]
+ to_file(palout, output)
+
+ # create a new map of quaternary color ids
+ map = []
+ if padding['top']: map += [0] * (width + padding['left'] + padding['right']) * padding['top']
+ for line in image:
+ if padding['left']: map += [0] * padding['left']
+ for color in line:
+ map.append(palette.index(color))
+ if padding['right']: map += [0] * padding['right']
+ if padding['bottom']: map += [0] * (width + padding['left'] + padding['right']) * padding['bottom']
+
+ # split it into strips of 8, and make them planar
+ num_columns = width / 8
+ num_rows = height / 8
+ tile = 8 * 8
+ image = []
+ for row in range(num_rows):
+ for column in range(num_columns):
+ for strip in range(tile / 8):
+ anchor = row*num_columns*tile + column*tile/8 + strip*width
+ line = map[anchor:anchor+8]
+ bottom = 0
+ top = 0
+ for bit, quad in enumerate(line):
+ bottom += (quad & 1) << (7-bit)
+ top += ((quad & 2) >> 1) << (7-bit)
+ image.append(bottom)
+ image.append(top)
+
+ to_file(fileout, image)
def png_to_lz(filein):
- name = os.path.splitext(filein)[0]
+ name = os.path.splitext(filein)[0]
- to_2bpp(filein)
- image = open(name+'.2bpp', 'rb').read()
- to_file(name+'.lz', Compressed(image).output)
+ to_2bpp(filein)
+ image = open(name+'.2bpp', 'rb').read()
+ to_file(name+'.lz', Compressed(image).output)
def mass_to_png(debug=False):
- # greyscale
- for root, dirs, files in os.walk('../gfx/'):
- for name in files:
- if debug: print os.path.splitext(name), os.path.join(root, name)
- if os.path.splitext(name)[1] == '.2bpp':
- to_png(os.path.join(root, name))
+ # greyscale
+ for root, dirs, files in os.walk('../gfx/'):
+ for name in files:
+ if debug: print os.path.splitext(name), os.path.join(root, name)
+ if os.path.splitext(name)[1] == '.2bpp':
+ to_png(os.path.join(root, name))
def mass_to_colored_png(debug=False):
- # greyscale, unless a palette is detected
- for root, dirs, files in os.walk('../gfx/'):
- if 'pics' not in root and 'trainers' not in root:
- for name in files:
- if debug: print os.path.splitext(name), os.path.join(root, name)
- if os.path.splitext(name)[1] == '.2bpp':
- to_png(os.path.join(root, name))
- os.utime(os.path.join(root, name), None)
-
- # only monster and trainer pics for now
- for root, dirs, files in os.walk('../gfx/pics/'):
- for name in files:
- if debug: print os.path.splitext(name), os.path.join(root, name)
- if os.path.splitext(name)[1] == '.2bpp':
- if 'normal.pal' in files:
- to_png(os.path.join(root, name), None, os.path.join(root, 'normal.pal'))
- else:
- to_png(os.path.join(root, name))
- os.utime(os.path.join(root, name), None)
-
- for root, dirs, files in os.walk('../gfx/trainers/'):
- for name in files:
- if debug: print os.path.splitext(name), os.path.join(root, name)
- if os.path.splitext(name)[1] == '.2bpp':
- to_png(os.path.join(root, name))
- os.utime(os.path.join(root, name), None)
+ # greyscale, unless a palette is detected
+ for root, dirs, files in os.walk('../gfx/'):
+ if 'pics' not in root and 'trainers' not in root:
+ for name in files:
+ if debug: print os.path.splitext(name), os.path.join(root, name)
+ if os.path.splitext(name)[1] == '.2bpp':
+ to_png(os.path.join(root, name))
+ os.utime(os.path.join(root, name), None)
+
+ # only monster and trainer pics for now
+ for root, dirs, files in os.walk('../gfx/pics/'):
+ for name in files:
+ if debug: print os.path.splitext(name), os.path.join(root, name)
+ if os.path.splitext(name)[1] == '.2bpp':
+ if 'normal.pal' in files:
+ to_png(os.path.join(root, name), None, os.path.join(root, 'normal.pal'))
+ else:
+ to_png(os.path.join(root, name))
+ os.utime(os.path.join(root, name), None)
+
+ for root, dirs, files in os.walk('../gfx/trainers/'):
+ for name in files:
+ if debug: print os.path.splitext(name), os.path.join(root, name)
+ if os.path.splitext(name)[1] == '.2bpp':
+ to_png(os.path.join(root, name))
+ os.utime(os.path.join(root, name), None)
def mass_decompress(debug=False):
- for root, dirs, files in os.walk('../gfx/'):
- for name in files:
- if 'lz' in name:
- if '/pics' in root:
- if 'front' in name:
- id = root.split('pics/')[1][:3]
- if id != 'egg':
- with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert', sizes[int(id)-1])
- else:
- with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert', 4)
- to_file(os.path.join(root, 'front.2bpp'), de.pic)
- to_file(os.path.join(root, 'tiles.2bpp'), de.animtiles)
- elif 'back' in name:
- with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert')
- to_file(os.path.join(root, 'back.2bpp'), de.output)
- elif '/trainers' in root or '/fx' in root:
- with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert')
- to_file(os.path.join(root, os.path.splitext(name)[0]+'.2bpp'), de.output)
- else:
- with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read())
- to_file(os.path.join(root, os.path.splitext(name)[0]+'.2bpp'), de.output)
- os.utime(os.path.join(root, name), None)
+ for root, dirs, files in os.walk('../gfx/'):
+ for name in files:
+ if 'lz' in name:
+ if '/pics' in root:
+ if 'front' in name:
+ id = root.split('pics/')[1][:3]
+ if id != 'egg':
+ with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert', sizes[int(id)-1])
+ else:
+ with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert', 4)
+ to_file(os.path.join(root, 'front.2bpp'), de.pic)
+ to_file(os.path.join(root, 'tiles.2bpp'), de.animtiles)
+ elif 'back' in name:
+ with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert')
+ to_file(os.path.join(root, 'back.2bpp'), de.output)
+ elif '/trainers' in root or '/fx' in root:
+ with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert')
+ to_file(os.path.join(root, os.path.splitext(name)[0]+'.2bpp'), de.output)
+ else:
+ with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read())
+ to_file(os.path.join(root, os.path.splitext(name)[0]+'.2bpp'), de.output)
+ os.utime(os.path.join(root, name), None)
def append_terminator_to_lzs(directory):
- # fix lzs that were extracted with a missing terminator
- for root, dirs, files in os.walk(directory):
- for file in files:
- if '.lz' in file:
- data = open(root+file,'rb').read()
- if data[-1] != chr(0xff):
- data += chr(0xff)
- new = open(root+file,'wb')
- new.write(data)
- new.close()
+ # fix lzs that were extracted with a missing terminator
+ for root, dirs, files in os.walk(directory):
+ for file in files:
+ if '.lz' in file:
+ data = open(root+file,'rb').read()
+ if data[-1] != chr(0xff):
+ data += chr(0xff)
+ new = open(root+file,'wb')
+ new.write(data)
+ new.close()
def lz_to_png_by_file(filename):
"""
- Converts a lz file to png. Dumps a 2bpp file too.
+ Convert a lz file to png. Dump a 2bpp file too.
"""
assert filename[-3:] == ".lz"
lz_data = open(filename, "rb").read()
@@ -1511,117 +1555,118 @@ def lz_to_png_by_file(filename):
def dump_tileset_pngs():
"""
- Converts .lz format tilesets into .png format tilesets. Also, leaves a
- bunch of wonderful .2bpp files everywhere for your amusement.
+ Convert .lz format tilesets into .png format tilesets.
+
+ Also, leaves a bunch of wonderful .2bpp files everywhere for your amusement.
"""
for tileset_id in range(37):
tileset_filename = "../gfx/tilesets/" + str(tileset_id).zfill(2) + ".lz"
lz_to_png_by_file(tileset_filename)
def decompress_frontpic(lz_file):
- """
- Convert the pic portion of front.lz to front.2bpp
- """
- lz = open(lz_file, 'rb').read()
- to_file(Decompressed(lz).pic, os.path.splitext(filein)[0] + '.2bpp')
+ """
+ Convert the pic portion of front.lz to front.2bpp
+ """
+ lz = open(lz_file, 'rb').read()
+ to_file(Decompressed(lz).pic, os.path.splitext(filein)[0] + '.2bpp')
def decompress_frontpic_anim(lz_file):
- """
- Convert the animation tile portion of front.lz to tiles.2bpp
- """
- lz = open(lz_file, 'rb').read()
- to_file(Decompressed(lz).animtiles, 'tiles.2bpp')
+ """
+ Convert the animation tile portion of front.lz to tiles.2bpp
+ """
+ lz = open(lz_file, 'rb').read()
+ to_file(Decompressed(lz).animtiles, 'tiles.2bpp')
def expand_pic_palettes():
- """
- Add white and black to palette files with fewer than 4 colors.
-
- Pokemon Crystal only defines two colors for a pic palette to
- save space, filling in black/white at runtime.
- Instead of managing palette files of varying length, black
- and white are added to pic palettes and excluded from incbins.
- """
- for root, dirs, files in os.walk('../gfx/'):
- if 'gfx/pics' in root or 'gfx/trainers' in root:
- for name in files:
- if os.path.splitext(name)[1] == '.pal':
- filename = os.path.join(root, name)
- palette = bytearray(open(filename, 'rb').read())
- w = bytearray([0xff, 0x7f])
- b = bytearray([0x00, 0x00])
- if len(palette) == 4:
- with open(filename, 'wb') as out:
- out.write(w + palette + b)
+ """
+ Add white and black to palette files with fewer than 4 colors.
+
+ Pokemon Crystal only defines two colors for a pic palette to
+ save space, filling in black/white at runtime.
+ Instead of managing palette files of varying length, black
+ and white are added to pic palettes and excluded from incbins.
+ """
+ for root, dirs, files in os.walk('../gfx/'):
+ if 'gfx/pics' in root or 'gfx/trainers' in root:
+ for name in files:
+ if os.path.splitext(name)[1] == '.pal':
+ filename = os.path.join(root, name)
+ palette = bytearray(open(filename, 'rb').read())
+ w = bytearray([0xff, 0x7f])
+ b = bytearray([0x00, 0x00])
+ if len(palette) == 4:
+ with open(filename, 'wb') as out:
+ out.write(w + palette + b)
if __name__ == "__main__":
- debug = False
-
- argv = [None] * 5
- for i, arg in enumerate(sys.argv):
- argv[i] = arg
-
- if argv[1] == 'dump-pngs':
- mass_to_colored_png()
-
- elif argv[1] == 'mass-decompress':
- mass_decompress()
-
- elif argv[1] == 'front-to-2bpp':
- decompress_frontpic(argv[2])
-
- elif argv[1] == 'anim-from-front':
- decompress_frontpic_anim(argv[2])
-
- elif argv[1] == 'lz-to-2bpp':
- name = os.path.splitext(argv[3])[0]
- lz = open(name+'.lz', 'rb').read()
- if argv[2] == '--vert':
- to_file(name+'.2bpp', Decompressed(lz, 'vert').output)
- else:
- to_file(name+'.2bpp', Decompressed(lz).output)
-
- elif argv[1] == 'lz-to-png':
- if argv[2] == '--vert':
- name = os.path.splitext(argv[3])[0]
- lz = open(name+'.lz', 'rb').read()
- to_file(name+'.2bpp', Decompressed(lz, 'vert').output)
- pic = open(name+'.2bpp', 'rb').read()
- to_file(name+'.png', to_png(pic))
- else:
- lz_to_png_by_file(argv[2])
-
- elif argv[1] == 'png-to-lz':
- # python gfx.py png-to-lz [--front anim(2bpp) | --vert] [png]
- if argv[2] == '--front':
- # front.2bpp and tiles.2bpp are combined before compression,
- # so we have to pass in the anim file and pic size
- name = os.path.splitext(argv[4])[0]
- to_2bpp(name+'.png', name+'.2bpp')
- pic = open(name+'.2bpp', 'rb').read()
- anim = open(argv[3], 'rb').read()
- size = int(sqrt(len(pic)/16)) # assume square pic
- to_file(name+'.lz', Compressed(pic + anim, 'vert', size).output)
- elif argv[2] == '--vert':
- name = os.path.splitext(argv[3])[0]
- to_2bpp(name+'.png', name+'.2bpp')
- pic = open(name+'.2bpp', 'rb').read()
- to_file(name+'.lz', Compressed(pic, 'vert').output)
- else:
- png_to_lz(argv[2])
-
- elif argv[1] == 'png-to-2bpp':
- to_2bpp(argv[2])
-
- elif argv[1] == '2bpp-to-lz':
- if argv[2] == '--vert':
- filein = argv[3]
- fileout = argv[4]
- compress_file(filein, fileout, 'vert')
- else:
- filein = argv[2]
- fileout = argv[3]
- compress_file(filein, fileout)
-
- elif argv[1] == '2bpp-to-png':
- to_png(argv[2])
+ debug = False
+
+ argv = [None] * 5
+ for i, arg in enumerate(sys.argv):
+ argv[i] = arg
+
+ if argv[1] == 'dump-pngs':
+ mass_to_colored_png()
+
+ elif argv[1] == 'mass-decompress':
+ mass_decompress()
+
+ elif argv[1] == 'front-to-2bpp':
+ decompress_frontpic(argv[2])
+
+ elif argv[1] == 'anim-from-front':
+ decompress_frontpic_anim(argv[2])
+
+ elif argv[1] == 'lz-to-2bpp':
+ name = os.path.splitext(argv[3])[0]
+ lz = open(name+'.lz', 'rb').read()
+ if argv[2] == '--vert':
+ to_file(name+'.2bpp', Decompressed(lz, 'vert').output)
+ else:
+ to_file(name+'.2bpp', Decompressed(lz).output)
+
+ elif argv[1] == 'lz-to-png':
+ if argv[2] == '--vert':
+ name = os.path.splitext(argv[3])[0]
+ lz = open(name+'.lz', 'rb').read()
+ to_file(name+'.2bpp', Decompressed(lz, 'vert').output)
+ pic = open(name+'.2bpp', 'rb').read()
+ to_file(name+'.png', to_png(pic))
+ else:
+ lz_to_png_by_file(argv[2])
+
+ elif argv[1] == 'png-to-lz':
+ # python gfx.py png-to-lz [--front anim(2bpp) | --vert] [png]
+ if argv[2] == '--front':
+ # front.2bpp and tiles.2bpp are combined before compression,
+ # so we have to pass in the anim file and pic size
+ name = os.path.splitext(argv[4])[0]
+ to_2bpp(name+'.png', name+'.2bpp')
+ pic = open(name+'.2bpp', 'rb').read()
+ anim = open(argv[3], 'rb').read()
+ size = int(sqrt(len(pic)/16)) # assume square pic
+ to_file(name+'.lz', Compressed(pic + anim, 'vert', size).output)
+ elif argv[2] == '--vert':
+ name = os.path.splitext(argv[3])[0]
+ to_2bpp(name+'.png', name+'.2bpp')
+ pic = open(name+'.2bpp', 'rb').read()
+ to_file(name+'.lz', Compressed(pic, 'vert').output)
+ else:
+ png_to_lz(argv[2])
+
+ elif argv[1] == 'png-to-2bpp':
+ to_2bpp(argv[2])
+
+ elif argv[1] == '2bpp-to-lz':
+ if argv[2] == '--vert':
+ filein = argv[3]
+ fileout = argv[4]
+ compress_file(filein, fileout, 'vert')
+ else:
+ filein = argv[2]
+ fileout = argv[3]
+ compress_file(filein, fileout)
+
+ elif argv[1] == '2bpp-to-png':
+ to_png(argv[2])
diff --git a/extras/labels.py b/extras/labels.py
index 61ec4c29a..8b4df1638 100644
--- a/extras/labels.py
+++ b/extras/labels.py
@@ -31,8 +31,10 @@ def line_has_comment_address(line, returnable={}, bank=None):
returnable["bank"] = None
returnable["offset"] = None
returnable["address"] = None
- #only valid characters are 0-9A-F
- valid = [str(x) for x in range(0,10)] + [chr(x) for x in range(97, 102+1)]
+ #only valid characters are 0-9a-fA-F
+ valid = [str(x) for x in range(10)] + \
+ [chr(x) for x in range(ord('a'), ord('f')+1)] + \
+ [chr(x) for x in range(ord('A'), ord('F')+1)]
#check if there is a comment in this line
if ";" not in line:
return False
diff --git a/extras/overworldripper.py b/extras/overworldripper.py
index 7148db6fd..654f28747 100644
--- a/extras/overworldripper.py
+++ b/extras/overworldripper.py
@@ -1,6 +1,11 @@
import gfx
def rip_sprites_from_bank(bank, offset=0):
+ """
+ Rips sprites from specified bank.
+
+ Sprites are 4x4.
+ """
file_handler = open("../gfx/overworld/bank" + str(hex(bank))[2:] + ".asm", "w")
for sprite in range(0 + offset, 256 + offset):
filename = "../gfx/overworld/" + str(sprite).zfill(3) + ".2bpp"
@@ -10,4 +15,4 @@ def rip_sprites_from_bank(bank, offset=0):
file_handler.close()
rip_sprites_from_bank(0x30)
-rip_sprites_from_bank(0x31, offset=256) \ No newline at end of file
+rip_sprites_from_bank(0x31, offset=256)
diff --git a/extras/romstr.py b/extras/romstr.py
index 90c099f3d..7a14fdc37 100644
--- a/extras/romstr.py
+++ b/extras/romstr.py
@@ -50,7 +50,7 @@ class RomStr(str):
@classmethod
def load(cls, filename=None, crystal=True, red=False):
"""
- Loads a ROM into a RomStr.
+ Load a ROM into a RomStr.
"""
if crystal and not red and not filename:
file_handler = open("../baserom.gbc", "r")
@@ -66,8 +66,10 @@ class RomStr(str):
def load_labels(self, filename="labels.json"):
"""
- Loads labels from labels.json, or parses the source code file and
- generates new labels.
+ Loads labels from labels.json.
+
+ (Or parses the source code file and
+ generates new labels.)
"""
filename = os.path.join(os.path.dirname(__file__), filename)
@@ -114,8 +116,9 @@ class RomStr(str):
def get_address_for(self, label):
"""
- Returns the address of a label. This is slow and could be improved
- dramatically.
+ Return the address of a label.
+
+ This is slow and could be improved dramatically.
"""
label = str(label)
for address in self.labels.keys():
@@ -137,7 +140,7 @@ class RomStr(str):
def interval(self, offset, length, strings=True, debug=True):
"""
- returns hex values for the rom starting at offset until offset+length
+ Return hex values for the rom starting at offset until offset+length.
"""
returnable = []
for byte in self[offset:offset+length]:
@@ -149,16 +152,17 @@ class RomStr(str):
def until(self, offset, byte, strings=True, debug=False):
"""
- Returns hex values from rom starting at offset until the given byte.
+ Return hex values from rom starting at offset until the given byte.
"""
return self.interval(offset, self.find(chr(byte), offset) - offset, strings=strings)
def to_asm(self, address, end_address=None, size=None, max_size=0x4000, debug=None):
"""
- Disassembles ASM at some address. This will stop disassembling when
- either the end_address or size is met. Also, there's a maximum size
- that will be parsed, so that large patches of data aren't parsed as
- code.
+ Disassemble ASM at some address.
+
+ This will stop disassembling when either the end_address or size is
+ met. Also, there's a maximum size that will be parsed, so that large
+ patches of data aren't parsed as code.
"""
if type(address) in [str, unicode] and "0x" in address:
address = int(address, 16)
diff --git a/extras/vba.py b/extras/vba.py
index f85f838b4..9b5d6e443 100644
--- a/extras/vba.py
+++ b/extras/vba.py
@@ -6,13 +6,15 @@ vba-clojure (but really it's jython/python/jvm)
This is jython, not python. Use jython to run this file. Before running this
file, some of the dependencies need to be constructed. These can be obtained
from the vba-clojure project.
- sudo apt-get install g++ libtool openjdk-6-jre openjdk-6-jdk libsdl1.2-dev ant jython
+ sudo apt-get install g++ libtool openjdk-6-jre openjdk-6-jdk libsdl1.2-dev mercurial ant autoconf jython
export JAVA_INCLUDE_PATH=/usr/lib/jvm/java-6-openjdk-amd64/include/
export JAVA_INCLUDE_PATH2=/usr/lib/jvm/java-6-openjdk-amd64/include/
hg clone http://hg.bortreb.com/vba-clojure
- cd vba-clojure/java/
+ cd vba-clojure/
+ ./dl-libs.sh
+ cd java/
ant all
cd ..
autoreconf -i
@@ -28,6 +30,9 @@ Make sure vba-clojure is available within "java.library.path":
$HOME/local/vba-clojure/vba-clojure/src/clojure/.libs/libvba.so.0.0.0 \
/usr/lib/jni/libvba.so
+(In the above command, substitute the first path with the path of the vba-clojure
+directory you made, if it is different.)
+
Also make sure VisualBoyAdvance.cfg is somewhere in the $PATH for VBA to find.
A default configuration is provided in vba-clojure under src/.
@@ -114,15 +119,19 @@ if not os.path.exists(rom_path):
def _check_java_library_path():
"""
- Returns the value of java.library.path. The vba-clojure library must be
- compiled and linked from this location.
+ Returns the value of java.library.path.
+
+ The vba-clojure library must be compiled
+ and linked from this location.
"""
return System.getProperty("java.library.path")
class RomList(list):
+
"""
Simple wrapper to prevent a giant rom from being shown on screen.
"""
+
def __init__(self, *args, **kwargs):
list.__init__(self, *args, **kwargs)
@@ -150,8 +159,9 @@ a, b, r, l, u, d, select, start, restart = "a", "b", "r", "l", "u", "d", "select
def button_combiner(buttons):
"""
- Combines multiple button presses into an integer. This is used when sending
- a keypress to the emulator.
+ Combines multiple button presses into an integer.
+
+ This is used when sending a keypress to the emulator.
"""
result = 0
@@ -186,8 +196,9 @@ def button_combiner(buttons):
def load_rom(path=None):
"""
- Starts the emulator with a certain ROM. Defaults to rom_path if no
- parameters are given.
+ Starts the emulator with a certain ROM.
+
+ Defaults to rom_path if no parameters are given.
"""
if path == None:
path = rom_path
@@ -204,8 +215,9 @@ def load_rom(path=None):
def shutdown():
"""
- Stops the emulator. Closes the window. The "opposite" of this is the
- load_rom function.
+ Stops the emulator. Closes the window.
+
+ The "opposite" of this is the load_rom function.
"""
Gb.shutdown()
@@ -239,8 +251,9 @@ def translate_chars(charz):
def _create_byte_buffer(data):
"""
- Converts data into a ByteBuffer. This is useful for interfacing with the Gb
- class.
+ Converts data into a ByteBuffer.
+
+ This is useful for interfacing with the Gb class.
"""
buf = ByteBuffer.allocateDirect(len(data))
if isinstance(data[0], int):
@@ -253,9 +266,11 @@ def _create_byte_buffer(data):
def set_state(state, do_step=False):
"""
- Injects the given state into the emulator. Use do_step if you want to call
- step(), which also allows SDL to render the latest frame. Note that the
- default is to not step, and that the screen (if it is enabled) will appear
+ Injects the given state into the emulator.
+
+ Use do_step if you want to call step(), which also allows
+ SDL to render the latest frame. Note that the default is to
+ not step, and that the screen (if it is enabled) will appear
as if it still has the last state loaded. This is normal.
"""
Gb.loadState(_create_byte_buffer(state))
@@ -274,7 +289,9 @@ def get_state():
def save_state(name, state=None, override=False):
"""
- Saves the given state to save_state_path. The file format must be ".sav"
+ Saves the given state to save_state_path.
+
+ The file format must be ".sav"
(and this will be appended to your string if necessary).
"""
if state == None:
@@ -296,7 +313,9 @@ def save_state(name, state=None, override=False):
def load_state(name):
"""
- Reads a state from file based on name. Looks in save_state_path for a file
+ Reads a state from file based on name.
+
+ Looks in save_state_path for a file
with this name (".sav" is optional).
"""
save_path = os.path.join(save_state_path, name)
@@ -321,8 +340,9 @@ def generate_root():
def get_root():
"""
- Loads the root state, or restarts the emulator and creates a new root
- state.
+ Loads the root state.
+
+ (Or restarts the emulator and creates a new root state.)
"""
try:
root = load_state("root")
@@ -377,15 +397,17 @@ def get_memory():
def set_memory(memory):
"""
- Sets memory in the emulator. Use get_memory() to retrieve the current
- state.
+ Sets memory in the emulator.
+
+ Use get_memory() to retrieve the current state.
"""
Gb.writeMemory(memory)
def get_pixels():
"""
- Returns a list of pixels on the screen display. Broken, probably. Use
- screenshot() instead.
+ Returns a list of pixels on the screen display.
+
+ Broken, probably. Use screenshot() instead.
"""
sys.stderr.write("ERROR: seems to be broken on VBA's end? Good luck. Use"
" screenshot() instead.\n")
@@ -396,9 +418,10 @@ def get_pixels():
def screenshot(filename, literal=False):
"""
- Saves a PNG screenshot to the file at filename. Use literal if you want to
- store it in the current directory. Default is to save it to screenshots/
- under the project.
+ Saves a PNG screenshot to the file at filename.
+
+ Use literal if you want to store it in the current directory.
+ Default is to save it to screenshots/ under the project.
"""
screenshots_path = os.path.join(project_path, "screenshots/")
filename = os.path.join(screenshots_path, filename)
@@ -430,14 +453,18 @@ def get_memory_range(start_address, byte_count):
def set_memory_at(address, value):
"""
- Sets a byte at a certain address in memory. This directly sets the memory
- instead of copying the memory from the emulator.
+ Sets a byte at a certain address in memory.
+
+ This directly sets the memory instead of copying
+ the memory from the emulator.
"""
Gb.setMemoryAt(address, value)
def press(buttons, holdsteps=1, aftersteps=1):
"""
- Press a button. Use steplimit to say for how many steps you want to press
+ Press a button.
+
+ Use steplimit to say for how many steps you want to press
the button (try leaving it at the default, 1).
"""
if hasattr(buttons, "__len__"):
@@ -456,7 +483,9 @@ def press(buttons, holdsteps=1, aftersteps=1):
def get_buttons():
"""
- Returns the currentButtons[0] value (an integer with bits set for which
+ Returns the currentButtons[0] value
+
+ (an integer with bits set for which
buttons are currently pressed).
"""
return Gb.getCurrentButtons()
@@ -708,6 +737,7 @@ class cheats:
Gb.cheatAddGameshark(code, description)
class crystal:
+
"""
Just a simple namespace to store a bunch of functions for Pokémon Crystal.
"""
@@ -715,8 +745,7 @@ class crystal:
@staticmethod
def text_wait(step_size=10, max_wait=500):
"""
- Watches for a sign that text is done being drawn to screen, then
- presses the "A" button.
+ Presses the "A" button when text is done being drawn to screen.
:param step_size: number of steps per wait loop
:param max_wait: number of wait loops to perform
@@ -744,10 +773,12 @@ class crystal:
@staticmethod
def walk_through_walls():
"""
- Lets the player walk all over the map. These values are probably reset
- by some of the map/collision functions when you move on to a new
- location, so this needs to be executed each step/tick if continuous
- walk-through-walls is desired.
+ Lets the player walk all over the map.
+
+ These values are probably reset by some of the map/collision
+ functions when you move on to a new location, so this needs
+ to be executed each step/tick if continuous walk-through-walls
+ is desired.
"""
set_memory_at(0xC2FA, 0)
set_memory_at(0xC2FB, 0)
@@ -761,8 +792,9 @@ class crystal:
@staticmethod
def nstep(steplimit=500):
"""
- Steps the CPU forward and calls some functions in between each step,
- like to manipulate memory. This is pretty slow.
+ Steps the CPU forward and calls some functions in between each step.
+
+ (For example, to manipulate memory.) This is pretty slow.
"""
for step_counter in range(0, steplimit):
crystal.walk_through_walls()
@@ -806,6 +838,7 @@ class crystal:
def get_xy():
"""
(x, y) coordinates of player on map.
+
Relative to top-left corner of map.
"""
x = get_memory_at(0xdcb8)
@@ -815,9 +848,10 @@ class crystal:
@staticmethod
def menu_select(id=1):
"""
- Sets the cursor to the given pokemon in the player's party. This is
- under Start -> PKMN. This is useful for selecting a certain pokemon
- with fly or another skill.
+ Sets the cursor to the given pokemon in the player's party.
+
+ This is under Start -> PKMN. This is useful for selecting a
+ certain pokemon with fly or another skill.
This probably works on other menus.
"""
@@ -902,8 +936,9 @@ class crystal:
@staticmethod
def get_text():
"""
- Returns alphanumeric text on the screen. Other characters will not be
- shown.
+ Returns alphanumeric text on the screen.
+
+ Other characters will not be shown.
"""
output = ""
tiles = get_memory_range(0xc4a0, 1000)
@@ -942,8 +977,9 @@ class crystal:
@staticmethod
def write(something="TrAiNeR"):
"""
- Uses a planning algorithm to type out a word in the most efficient way
- possible.
+ Types out a word.
+
+ Uses a planning algorithm to do this in the most efficient way possible.
"""
button_sequence = keyboard.plan_typing(something)
crystal.keyboard_apply([[x] for x in button_sequence])
diff --git a/extras/vba_autoplayer.py b/extras/vba_autoplayer.py
index eafbff134..349fc2033 100644
--- a/extras/vba_autoplayer.py
+++ b/extras/vba_autoplayer.py
@@ -26,8 +26,10 @@ def main():
def skippable(func):
"""
- Makes a function skippable by saving the state before and after the
- function runs. Pass "skip=True" to the function to load the previous save
+ Makes a function skippable.
+
+ Saves the state before and after the function runs.
+ Pass "skip=True" to the function to load the previous save
state from when the function finished.
"""
def wrapped_function(*args, **kwargs):
@@ -433,6 +435,8 @@ def handle_elm(starter_choice):
@skippable
def new_bark_level_grind(level):
"""
+ Do level grinding in New Bark.
+
Starting just outside of Elm's Lab, do some level grinding until the first
partymon level is equal to the given value..
"""
diff --git a/extras/wram.py b/extras/wram.py
index bad0b9fa9..85057bee4 100644
--- a/extras/wram.py
+++ b/extras/wram.py
@@ -2,6 +2,10 @@
# RGBDS BSS section and constant parsing.
+import os
+path = os.path.dirname(os.path.abspath(__file__))
+
+
def read_bss_sections(bss):
sections = []
section = {}
@@ -19,21 +23,37 @@ def read_bss_sections(bss):
'start': address,
'labels': [],
}
+
elif ':' in line:
- # the only labels that don't use :s so far are enders,
- # which we typically don't want to end up in the output
+ # rgbds allows labels without :, but prefer convention
label = line[:line.find(':')]
if ';' not in label:
- section['labels'] += [{'label': label, 'address': address, 'length': 0}]
+ section['labels'] += [{
+ 'label': label,
+ 'address': address,
+ 'length': 0,
+ }]
+
elif line[:3] == 'ds ':
length = eval(line[3:line.find(';')].replace('$','0x'))
address += length
- if section['labels']:
- section['labels'][-1]['length'] += length
+ # adjacent labels use the same space
+ for label in section['labels'][::-1]:
+ if label['length'] == 0:
+ label['length'] = length
+ else:
+ break
+
+ elif 'EQU' in line:
+ # some space is defined using constants
+ name, value = line.split('EQU')
+ name, value = name.strip(), value.strip().replace('$','0x').replace('%','0b')
+ globals()[name] = eval(value)
+
sections.append(section)
return sections
-wram_sections = read_bss_sections(open('../wram.asm', 'r').readlines())
+wram_sections = read_bss_sections(open(os.path.join(path, '../wram.asm'), 'r').readlines())
def make_wram_labels():
@@ -56,6 +76,6 @@ def scrape_constants(text):
text = text.split('\n')
return constants_to_dict([line for line in text if 'EQU' in line[:line.find(';')]])
-hram_constants = scrape_constants(open('../hram.asm','r').readlines())
-gbhw_constants = scrape_constants(open('../gbhw.asm','r').readlines())
+hram_constants = scrape_constants(open(os.path.join(path, '../hram.asm'),'r').readlines())
+gbhw_constants = scrape_constants(open(os.path.join(path, '../gbhw.asm'),'r').readlines())
diff --git a/main.asm b/main.asm
index da4967743..a769710bb 100644
--- a/main.asm
+++ b/main.asm
@@ -1,23 +1,23 @@
-SECTION "bank0",HOME
-SECTION "rst0",HOME[$0]
+SECTION "bank0",ROM0
+SECTION "rst0",ROM0[$0]
di
jp Start
-SECTION "rst8",HOME[$8] ; FarCall
+SECTION "rst8",ROM0[$8] ; FarCall
jp FarJpHl
-SECTION "rst10",HOME[$10] ; Bankswitch
+SECTION "rst10",ROM0[$10] ; Bankswitch
ld [hROMBank], a
ld [MBC3RomBank], a
ret
-SECTION "rst18",HOME[$18] ; Unused
+SECTION "rst18",ROM0[$18] ; Unused
rst $38
-SECTION "rst20",HOME[$20] ; Unused
+SECTION "rst20",ROM0[$20] ; Unused
rst $38
-SECTION "rst28",HOME[$28] ; JumpTable
+SECTION "rst28",ROM0[$28] ; JumpTable
push de
ld e, a
ld d, 00
@@ -31,30 +31,30 @@ SECTION "rst28",HOME[$28] ; JumpTable
; rst30 is midst rst28
-SECTION "rst38",HOME[$38] ; Unused
+SECTION "rst38",ROM0[$38] ; Unused
rst $38
-SECTION "vblank",HOME[$40] ; vblank interrupt
+SECTION "vblank",ROM0[$40] ; vblank interrupt
jp VBlank
-SECTION "lcd",HOME[$48] ; lcd interrupt
+SECTION "lcd",ROM0[$48] ; lcd interrupt
jp $0552
-SECTION "timer",HOME[$50] ; timer interrupt
+SECTION "timer",ROM0[$50] ; timer interrupt
jp $3e93
-SECTION "serial",HOME[$58] ; serial interrupt
+SECTION "serial",ROM0[$58] ; serial interrupt
jp $06ef
-SECTION "joypad",HOME[$60] ; joypad interrupt
+SECTION "joypad",ROM0[$60] ; joypad interrupt
jp JoypadInt
-SECTION "romheader",HOME[$100]
+SECTION "romheader",ROM0[$100]
Start:
nop
jp $016e
-SECTION "start",HOME[$150]
+SECTION "start",ROM0[$150]
INCBIN "baserom.gbc", $150, $283 - $150
@@ -5565,7 +5565,7 @@ SFXChannelsOff: ; 3e21
INCBIN "baserom.gbc", $3e32, $3fb5 - $3e32
-SECTION "bank1",DATA,BANK[$1]
+SECTION "bank1",ROMX,BANK[$1]
INCBIN "baserom.gbc", $4000, $5f99 - $4000
@@ -6246,7 +6246,7 @@ SpecialGiveShuckle: ; 7305
INCBIN "baserom.gbc", $737e, $747b - $737e
-SECTION "bank2",DATA,BANK[$2]
+SECTION "bank2",ROMX,BANK[$2]
INCBIN "baserom.gbc", $8000, $854b - $8000
@@ -6476,7 +6476,7 @@ INCBIN "tilesets/dark.pal"
INCBIN "baserom.gbc", $b419, $b825 - $b419
-SECTION "bank3",DATA,BANK[$3]
+SECTION "bank3",ROMX,BANK[$3]
INCBIN "baserom.gbc", $c000, $29
@@ -7415,7 +7415,7 @@ INCLUDE "items/item_effects.asm"
INCBIN "baserom.gbc", $f780, $fa0b - $f780
-SECTION "bank4",DATA,BANK[$4]
+SECTION "bank4",ROMX,BANK[$4]
INCBIN "baserom.gbc", $10000, $10b16 - $10000
@@ -8795,7 +8795,7 @@ root set root+1
; 13d96
-SECTION "bank5",DATA,BANK[$5]
+SECTION "bank5",ROMX,BANK[$5]
INCBIN "baserom.gbc", $14000, $14032 - $14000
@@ -10542,7 +10542,7 @@ MenuData15a08: ; 0x15a08
INCBIN "baserom.gbc", $15a20, $174ba - $15a20
-SECTION "bank6",DATA,BANK[$6]
+SECTION "bank6",ROMX,BANK[$6]
Tileset03GFX: ; 0x18000
INCBIN "gfx/tilesets/03.lz"
@@ -10621,7 +10621,7 @@ INCBIN "tilesets/20_collision.bin"
; 0x1bdfe
-SECTION "bank7",DATA,BANK[$7]
+SECTION "bank7",ROMX,BANK[$7]
INCBIN "baserom.gbc", $1c000, $1c30c - $1c000
@@ -10726,7 +10726,7 @@ Music_Clair: INCLUDE "audio/music/clair.asm"
Music_MobileAdapter: INCLUDE "audio/music/mobileadapter.asm"
-SECTION "bank8",DATA,BANK[$8]
+SECTION "bank8",ROMX,BANK[$8]
INCBIN "baserom.gbc", $20000, $20181 - $20000
@@ -10847,7 +10847,7 @@ INCLUDE "stats/egg_move_pointers.asm"
INCLUDE "stats/egg_moves.asm"
-SECTION "bank9",DATA,BANK[$9]
+SECTION "bank9",ROMX,BANK[$9]
INCBIN "baserom.gbc", $24000, $244c3 - $24000
@@ -11325,9 +11325,30 @@ INCLUDE "battle/moves/move_effects.asm"
INCBIN "baserom.gbc", $27a28, $27a2d - $27a28
-SECTION "bankA",DATA,BANK[$A]
+SECTION "bankA",ROMX,BANK[$A]
-INCBIN "baserom.gbc", $28000, $2a2a0 - $28000
+INCBIN "baserom.gbc", $28000, $28785 - $28000
+
+TimeCapsuleItemConversions: ; 0x28785
+; Pokémon traded from RBY do not have held items, so GSC usually interprets the
+; catch rate as an item. However, if the catch rate appears in this table, the
+; item associated with the table entry is used instead.
+
+ db 25, LEFTOVERS
+ db 45, BITTER_BERRY
+ db 50, GOLD_BERRY
+ db 90, BERRY
+ db 100, BERRY
+ db 120, BERRY
+ db 135, BERRY
+ db 190, BERRY
+ db 195, BERRY
+ db 220, BERRY
+ db 250, BERRY
+ db 255, BERRY
+ db 0
+
+INCBIN "baserom.gbc", $2879e, $2a2a0 - $2879e
SpecialRoamMons: ; 2a2a0
; initialize RoamMon structs
@@ -11409,7 +11430,7 @@ INCBIN "gfx/misc/dude.lz"
; 2bce1
-SECTION "bankB",DATA,BANK[$B]
+SECTION "bankB",ROMX,BANK[$B]
INCBIN "baserom.gbc", $2C000, $2c1ef - $2C000
@@ -11711,7 +11732,7 @@ FillBox: ; 2ef6e
-SECTION "bankC",DATA,BANK[$C]
+SECTION "bankC",ROMX,BANK[$C]
Tileset15GFX: ; 0x30000
INCBIN "gfx/tilesets/15.lz"
@@ -11803,12 +11824,12 @@ INCBIN "gfx/tilesets/30.lz"
INCBIN "baserom.gbc", $329ed, $333f0 - $329ed
-SECTION "bankD",DATA,BANK[$D]
+SECTION "bankD",ROMX,BANK[$D]
INCLUDE "battle/effect_commands.asm"
-SECTION "bankE",DATA,BANK[$E]
+SECTION "bankE",ROMX,BANK[$E]
INCBIN "baserom.gbc", $38000, $38591 - $38000
@@ -11826,7 +11847,7 @@ INCLUDE "trainers/trainer_pointers.asm"
INCLUDE "trainers/trainers.asm"
-SECTION "bankF",DATA,BANK[$F]
+SECTION "bankF",ROMX,BANK[$F]
INCBIN "baserom.gbc", $3c000, $3cc83 - $3c000
@@ -13046,7 +13067,7 @@ INCLUDE "battle/effect_command_pointers.asm"
-SECTION "bank10",DATA,BANK[$10]
+SECTION "bank10",ROMX,BANK[$10]
INCBIN "baserom.gbc", $40000, $40c65-$40000
@@ -13069,7 +13090,7 @@ INCLUDE "stats/evos_attacks_pointers.asm"
INCLUDE "stats/evos_attacks.asm"
-SECTION "bank11",DATA,BANK[$11]
+SECTION "bank11",ROMX,BANK[$11]
FruitTreeScript: ; 44000
3callasm BANK(GetCurTreeFruit), GetCurTreeFruit
@@ -13744,7 +13765,7 @@ MenuData44964: ; 0x44964
db "ATTACH MAIL@"
db "CANCEL@"
-SECTION "bank12",DATA,BANK[$12]
+SECTION "bank12",ROMX,BANK[$12]
INCBIN "baserom.gbc", $48000, $48e9b - $48000
@@ -14127,7 +14148,7 @@ UpdateOTPointer: ; 0x4a83a
INCBIN "baserom.gbc", $4a843, $4ae78 - $4a843
-SECTION "bank13",DATA,BANK[$13]
+SECTION "bank13",ROMX,BANK[$13]
INCBIN "baserom.gbc", $4c000, $4c075 - $4c000
@@ -14817,7 +14838,7 @@ INCBIN "gfx/evo/bubble.2bpp"
INCBIN "baserom.gbc", $4e881, $4f31c - $4e881
-SECTION "bank14",DATA,BANK[$14]
+SECTION "bank14",ROMX,BANK[$14]
INCBIN "baserom.gbc", $50000, $5005f-$50000
@@ -15243,7 +15264,7 @@ INCLUDE "stats/pokemon_names.asm"
INCBIN "baserom.gbc", $53D84, $53e2e - $53D84
-SECTION "bank15",DATA,BANK[$15]
+SECTION "bank15",ROMX,BANK[$15]
; Map Scripts I
@@ -15266,7 +15287,7 @@ INCLUDE "maps/GoldenrodDeptStoreRoof.asm"
INCLUDE "maps/GoldenrodGameCorner.asm"
-SECTION "bank16",DATA,BANK[$16]
+SECTION "bank16",ROMX,BANK[$16]
; Map Scripts II
@@ -15296,7 +15317,7 @@ INCLUDE "maps/OlivineLighthouse3F.asm"
INCLUDE "maps/OlivineLighthouse4F.asm"
-SECTION "bank17",DATA,BANK[$17]
+SECTION "bank17",ROMX,BANK[$17]
; Map Scripts III
@@ -15308,7 +15329,7 @@ INCLUDE "maps/RadioTower3F.asm"
INCLUDE "maps/RadioTower4F.asm"
-SECTION "bank18",DATA,BANK[$18]
+SECTION "bank18",ROMX,BANK[$18]
; Map Scripts IV
@@ -15322,12 +15343,12 @@ INCLUDE "maps/Route34IlexForestGate.asm"
INCLUDE "maps/DayCare.asm"
-SECTION "bank19",DATA,BANK[$19]
+SECTION "bank19",ROMX,BANK[$19]
INCBIN "baserom.gbc", $64000, $67308 - $64000
-SECTION "bank1A",DATA,BANK[$1A]
+SECTION "bank1A",ROMX,BANK[$1A]
; Map Scripts V
@@ -15346,7 +15367,7 @@ INCLUDE "maps/Route36RuinsofAlphgate.asm"
INCLUDE "maps/Route36NationalParkgate.asm"
-SECTION "bank1B",DATA,BANK[$1B]
+SECTION "bank1B",ROMX,BANK[$1B]
; Map Scripts VI
@@ -15358,7 +15379,7 @@ INCLUDE "maps/TeamRocketBaseB3F.asm"
INCLUDE "maps/IlexForest.asm"
-SECTION "bank1C",DATA,BANK[$1C]
+SECTION "bank1C",ROMX,BANK[$1C]
; Map Scripts VII
@@ -15387,7 +15408,7 @@ INCLUDE "maps/Route7SaffronGate.asm"
INCLUDE "maps/Route1718Gate.asm"
-SECTION "bank1D",DATA,BANK[$1D]
+SECTION "bank1D",ROMX,BANK[$1D]
; Map Scripts VIII
@@ -15413,7 +15434,7 @@ INCLUDE "maps/MountMoonGiftShop.asm"
INCLUDE "maps/TinTowerRoof.asm"
-SECTION "bank1E",DATA,BANK[$1E]
+SECTION "bank1E",ROMX,BANK[$1E]
; Map Scripts IX
@@ -15429,7 +15450,7 @@ INCLUDE "maps/Route27SandstormHouse.asm"
INCLUDE "maps/Route2946Gate.asm"
-SECTION "bank1F",DATA,BANK[$1F]
+SECTION "bank1F",ROMX,BANK[$1F]
; Map Scripts X
@@ -15459,7 +15480,7 @@ INCLUDE "maps/Route8SaffronGate.asm"
INCLUDE "maps/Route12SuperRodHouse.asm"
-SECTION "bank20",DATA,BANK[$20]
+SECTION "bank20",ROMX,BANK[$20]
DoPlayerMovement: ; 80000
@@ -16410,7 +16431,7 @@ INCBIN "gfx/debug/color_test.2bpp"
INCBIN "baserom.gbc", $82153, $823c8-$82153
-SECTION "bank21",DATA,BANK[$21]
+SECTION "bank21",ROMX,BANK[$21]
INCBIN "baserom.gbc", $84000, $84a2e - $84000
@@ -16692,7 +16713,7 @@ HallOfFame3: ; 0x8640e
INCBIN "baserom.gbc", $86455, $88000 - $86455
-SECTION "bank22",DATA,BANK[$22]
+SECTION "bank22",ROMX,BANK[$22]
INCBIN "baserom.gbc", $88000, $88258 - $88000
@@ -17005,7 +17026,7 @@ GetNthPartyMon: ; 0x8b1ce
INCBIN "baserom.gbc", $8b1e1, $8ba24-$8b1e1
-SECTION "bank23",DATA,BANK[$23]
+SECTION "bank23",ROMX,BANK[$23]
INCBIN "baserom.gbc", $8c000, $8c011 - $8c000
@@ -17817,7 +17838,7 @@ SudowoodoIcon: INCBIN "gfx/icon/sudowoodo.2bpp" ; 0x8fe0d
BigmonIcon: INCBIN "gfx/icon/bigmon.2bpp" ; 0x8fe8d
-SECTION "bank24",DATA,BANK[$24]
+SECTION "bank24",ROMX,BANK[$24]
INCBIN "baserom.gbc", $90000, $909F2-$90000
@@ -18310,7 +18331,7 @@ INCLUDE "stats/wild/fish.asm"
INCBIN "baserom.gbc", $926c7, $93a31 - $926c7
-SECTION "bank25",DATA,BANK[$25]
+SECTION "bank25",ROMX,BANK[$25]
MapGroupPointers: ; 0x94000
; pointers to the first map header of each map group
@@ -19005,7 +19026,7 @@ INCLUDE "engine/scripting.asm"
INCBIN "baserom.gbc", $97c20, $97f7e - $97c20
-SECTION "bank26",DATA,BANK[$26]
+SECTION "bank26",ROMX,BANK[$26]
; Map Scripts XI
@@ -19029,7 +19050,7 @@ INCLUDE "maps/Route2Gate.asm"
INCLUDE "maps/VictoryRoadGate.asm"
-SECTION "bank27",DATA,BANK[$27]
+SECTION "bank27",ROMX,BANK[$27]
; Map Scripts XII
@@ -19059,17 +19080,17 @@ INCLUDE "maps/Route40BattleTowerGate.asm"
INCLUDE "maps/BattleTowerOutside.asm"
-SECTION "bank28",DATA,BANK[$28]
+SECTION "bank28",ROMX,BANK[$28]
INCBIN "baserom.gbc", $a0000, $a1eca - $a0000
-SECTION "bank29",DATA,BANK[$29]
+SECTION "bank29",ROMX,BANK[$29]
INCBIN "baserom.gbc", $a4000, $a64ad - $a4000
-SECTION "bank2A",DATA,BANK[$2A]
+SECTION "bank2A",ROMX,BANK[$2A]
Route32_BlockData: ; 0xa8000
INCBIN "maps/Route32.blk"
@@ -19380,7 +19401,7 @@ Route22_BlockData: ; 0xabef7
; 0xabfab
-SECTION "bank2B",DATA,BANK[$2B]
+SECTION "bank2B",ROMX,BANK[$2B]
Route14_BlockData: ; 0xac000
INCBIN "maps/Route14.blk"
@@ -19935,7 +19956,7 @@ OlivineLighthouse6F_BlockData: ; 0xaff00
; 0xaff5a
-SECTION "bank2C",DATA,BANK[$2C]
+SECTION "bank2C",ROMX,BANK[$2C]
BetaCave2_BlockData: ; 0xb0000
INCBIN "maps/BetaCave2.blk"
@@ -20286,7 +20307,7 @@ GoldenrodDeptStoreRoof_BlockData: ; 0xb1b22
; 0xb1b42
-SECTION "bank2D",DATA,BANK[$2D]
+SECTION "bank2D",ROMX,BANK[$2D]
Tileset21GFX: ; 0xb4000
INCBIN "gfx/tilesets/21.lz"
@@ -20403,7 +20424,7 @@ INCBIN "tilesets/16_collision.bin"
; 0xb7ea8
-SECTION "bank2E",DATA,BANK[$2E]
+SECTION "bank2E",ROMX,BANK[$2E]
INCBIN "baserom.gbc", $B8000, $b8219 - $b8000
@@ -20648,7 +20669,7 @@ WildRockMonTable: ; b83de
INCBIN "baserom.gbc", $b83e5, $b9e8b - $b83e5
-SECTION "bank2F",DATA,BANK[$2F]
+SECTION "bank2F",ROMX,BANK[$2F]
INCBIN "baserom.gbc", $bc000, $bc09c - $bc000
@@ -21077,20 +21098,20 @@ ElmPhoneScript2: ; 0xbd081
INCBIN "baserom.gbc", $bd0d0, $be699-$bd0d0
-SECTION "bank30",DATA,BANK[$30]
+SECTION "bank30",ROMX,BANK[$30]
INCLUDE "gfx/overworld/sprites_1.asm"
-SECTION "bank31",DATA,BANK[$31]
+SECTION "bank31",ROMX,BANK[$31]
INCLUDE "gfx/overworld/sprites_2.asm"
-SECTION "bank32",DATA,BANK[$32]
+SECTION "bank32",ROMX,BANK[$32]
INCBIN "baserom.gbc", $c8000, $cbe2b - $c8000
-SECTION "bank33",DATA,BANK[$33]
+SECTION "bank33",ROMX,BANK[$33]
INCBIN "baserom.gbc", $cc000, $cfd9e - $cc000
@@ -21102,7 +21123,7 @@ Music_PostCredits: INCLUDE "audio/music/postcredits.asm"
; Pic animations I
-SECTION "bank34",DATA,BANK[$34]
+SECTION "bank34",ROMX,BANK[$34]
; Pic animations asm
INCBIN "baserom.gbc", $d0000, $d0695 - $d0000
@@ -21146,7 +21167,7 @@ INCLUDE "gfx/pics/unown_bitmasks.asm"
; Pic animations II
-SECTION "bank35",DATA,BANK[$35]
+SECTION "bank35",ROMX,BANK[$35]
; Frame definitions
FramesPointers: INCLUDE "gfx/pics/frame_pointers.asm"
@@ -21156,7 +21177,7 @@ INCLUDE "gfx/pics/kanto_frames.asm"
; Pic animations III
-SECTION "bank36",DATA,BANK[$36]
+SECTION "bank36",ROMX,BANK[$36]
FontInversed: INCBIN "gfx/misc/font_inversed.1bpp"
@@ -21168,7 +21189,7 @@ UnownFramesPointers: INCLUDE "gfx/pics/unown_frame_pointers.asm"
INCLUDE "gfx/pics/unown_frames.asm"
-SECTION "bank37",DATA,BANK[$37]
+SECTION "bank37",ROMX,BANK[$37]
Tileset31GFX: ; 0xdc000
INCBIN "gfx/tilesets/31.lz"
@@ -21282,12 +21303,12 @@ INCBIN "tilesets/36_collision.bin"
; 0xdfd90
-SECTION "bank38",DATA,BANK[$38]
+SECTION "bank38",ROMX,BANK[$38]
INCBIN "baserom.gbc", $e0000, $e37f9 - $e0000
-SECTION "bank39",DATA,BANK[$39]
+SECTION "bank39",ROMX,BANK[$39]
INCBIN "baserom.gbc", $e4000, $e555d - $e4000
@@ -21450,7 +21471,7 @@ INCBIN "baserom.gbc", $e799a, $e7a70 - $e799a
; ================================================================
; Sound engine and music/sound effect pointers
-SECTION "bank3A",DATA,BANK[$3A]
+SECTION "bank3A",ROMX,BANK[$3A]
; The sound engine. Interfaces are in bank 0
@@ -21491,7 +21512,7 @@ Music_LookPokemaniac: INCLUDE "audio/music/lookpokemaniac.asm"
Music_TrainerVictory: INCLUDE "audio/music/trainervictory.asm"
-SECTION "bank3B",DATA,BANK[$3B]
+SECTION "bank3B",ROMX,BANK[$3B]
; Songs II
@@ -21528,7 +21549,7 @@ Music_DancingHall: INCLUDE "audio/music/dancinghall.asm"
Music_ContestResults: INCLUDE "audio/music/bugcatchingcontestresults.asm"
Music_Route30: INCLUDE "audio/music/route30.asm"
-SECTION "bank3C",DATA,BANK[$3C]
+SECTION "bank3C",ROMX,BANK[$3C]
; Songs III
@@ -21547,7 +21568,7 @@ INCLUDE "audio/cry_headers.asm"
INCBIN "baserom.gbc", $f2d69, $f3fb6 - $f2d69
-SECTION "bank3D",DATA,BANK[$3D]
+SECTION "bank3D",ROMX,BANK[$3D]
; Songs IV
@@ -21589,7 +21610,7 @@ Music_LookKimonoGirl: INCLUDE "audio/music/lookkimonogirl.asm"
Music_PokeFluteChannel: INCLUDE "audio/music/pokeflutechannel.asm"
Music_BugCatchingContest: INCLUDE "audio/music/bugcatchingcontest.asm"
-SECTION "bank3E",DATA,BANK[$3E]
+SECTION "bank3E",ROMX,BANK[$3E]
FontExtra:
INCBIN "gfx/misc/font_extra.2bpp", $0, $200
@@ -21820,7 +21841,7 @@ DoBadgeTypeBoosts: ; fbe24
; fbe91
-SECTION "bank3F",DATA,BANK[$3F]
+SECTION "bank3F",ROMX,BANK[$3F]
DoTileAnimation: ; fc000
; Iterate over a given pointer array of animation functions
@@ -22853,12 +22874,12 @@ Trades: ; 0xfce58
INCBIN "baserom.gbc", $fcf38, $fd1d2-$fcf38
-SECTION "bank40",DATA,BANK[$40]
+SECTION "bank40",ROMX,BANK[$40]
INCBIN "baserom.gbc", $100000, $10389d - $100000
-SECTION "bank41",DATA,BANK[$41]
+SECTION "bank41",ROMX,BANK[$41]
INCBIN "baserom.gbc", $104000, $104350 - $104000
@@ -23405,7 +23426,7 @@ Function1060bb: ; 1060bb
INCBIN "baserom.gbc", $1060bc, $106dbc - $1060bc
-SECTION "bank42",DATA,BANK[$42]
+SECTION "bank42",ROMX,BANK[$42]
INCBIN "baserom.gbc", $108000, $109407 - $108000
@@ -23419,7 +23440,7 @@ INCBIN "baserom.gbc", $10983f, $1099aa - $10983f
INCLUDE "engine/credits.asm"
-SECTION "bank43",DATA,BANK[$43]
+SECTION "bank43",ROMX,BANK[$43]
INCBIN "baserom.gbc", $10c000, $10ed67 - $10c000
@@ -23787,7 +23808,7 @@ TitleScreenPalettes:
RGB 00, 00, 00
RGB 00, 00, 00
-SECTION "bank44",DATA,BANK[$44]
+SECTION "bank44",ROMX,BANK[$44]
INCBIN "baserom.gbc", $110000, $110fad - $110000
@@ -23804,7 +23825,7 @@ HTTPRankingURL: ; 0x111020
INCBIN "baserom.gbc", $111044, $113f84 - $111044
-SECTION "bank45",DATA,BANK[$45]
+SECTION "bank45",ROMX,BANK[$45]
INCBIN "baserom.gbc", $114000, $117a7f - $114000
@@ -24155,7 +24176,7 @@ Function117cdd: ; 0x117cdd
ret
-SECTION "bank46",DATA,BANK[$46]
+SECTION "bank46",ROMX,BANK[$46]
INCBIN "baserom.gbc", $118000, $118ba5 - $118000
@@ -24186,12 +24207,12 @@ db $0
INCBIN "baserom.gbc", $118d35, $11bc9e - $118d35
-SECTION "bank47",DATA,BANK[$47]
+SECTION "bank47",ROMX,BANK[$47]
INCBIN "baserom.gbc", $11c000, $11f686 - $11c000
-SECTION "bank48",DATA,BANK[$48]
+SECTION "bank48",ROMX,BANK[$48]
PicPointers:
INCLUDE "gfx/pics/pic_pointers.asm"
@@ -24214,7 +24235,7 @@ TyphlosionFrontpic: INCBIN "gfx/pics/157/front.lz"
; 123ffa
-SECTION "bank49",DATA,BANK[$49]
+SECTION "bank49",ROMX,BANK[$49]
UnownPicPointers:
INCLUDE "gfx/pics/unown_pic_pointers.asm"
@@ -24240,7 +24261,7 @@ QuilavaFrontpic: INCBIN "gfx/pics/156/front.lz"
; 127ffe
-SECTION "bank4a",DATA,BANK[$4a]
+SECTION "bank4a",ROMX,BANK[$4a]
TrainerPicPointers:
INCLUDE "gfx/pics/trainer_pic_pointers.asm"
@@ -24268,7 +24289,7 @@ OmastarBackpic: INCBIN "gfx/pics/139/back.lz"
; 12bffe
-SECTION "bank4b",DATA,BANK[$4b]
+SECTION "bank4b",ROMX,BANK[$4b]
; Pics IV
@@ -24295,7 +24316,7 @@ UnownEFrontpic: INCBIN "gfx/pics/201e/front.lz"
; 130000
-SECTION "bank4C",DATA,BANK[$4C]
+SECTION "bank4C",ROMX,BANK[$4C]
; Pics V
@@ -24323,7 +24344,7 @@ HeracrossFrontpic: INCBIN "gfx/pics/214/front.lz"
; 133fff
-SECTION "bank4d",DATA,BANK[$4d]
+SECTION "bank4d",ROMX,BANK[$4d]
; Pics VI
@@ -24353,7 +24374,7 @@ DunsparceFrontpic: INCBIN "gfx/pics/206/front.lz"
; 137fff
-SECTION "bank4E",DATA,BANK[$4E]
+SECTION "bank4E",ROMX,BANK[$4E]
; Pics VII
@@ -24385,7 +24406,7 @@ KangaskhanBackpic: INCBIN "gfx/pics/115/back.lz"
; 13c000
-SECTION "bank4f",DATA,BANK[$4f]
+SECTION "bank4f",ROMX,BANK[$4f]
; Pics VIII
@@ -24419,7 +24440,7 @@ QuagsireFrontpic: INCBIN "gfx/pics/195/front.lz"
; 13fff7
-SECTION "bank50",DATA,BANK[$50]
+SECTION "bank50",ROMX,BANK[$50]
; Pics IX
@@ -24457,7 +24478,7 @@ ParasectBackpic: INCBIN "gfx/pics/047/back.lz"
; 144000
-SECTION "bank51",DATA,BANK[$51]
+SECTION "bank51",ROMX,BANK[$51]
; Pics X
@@ -24499,7 +24520,7 @@ UnownFBackpic: INCBIN "gfx/pics/201f/back.lz"
; 148000
-SECTION "bank52",DATA,BANK[$52]
+SECTION "bank52",ROMX,BANK[$52]
; Pics XI
@@ -24544,7 +24565,7 @@ SnorlaxBackpic: INCBIN "gfx/pics/143/back.lz"
; 14bffb
-SECTION "bank53",DATA,BANK[$53]
+SECTION "bank53",ROMX,BANK[$53]
; Pics XII
@@ -24592,7 +24613,7 @@ StarmieBackpic: INCBIN "gfx/pics/121/back.lz"
; 150000
-SECTION "bank54",DATA,BANK[$54]
+SECTION "bank54",ROMX,BANK[$54]
; Pics XIII
@@ -24642,7 +24663,7 @@ ElectrodeFrontpic: INCBIN "gfx/pics/101/front.lz"
; 153fe3
-SECTION "bank55",DATA,BANK[$55]
+SECTION "bank55",ROMX,BANK[$55]
; Pics XIV
@@ -24695,7 +24716,7 @@ SwinubBackpic: INCBIN "gfx/pics/220/back.lz"
; 158000
-SECTION "bank56",DATA,BANK[$56]
+SECTION "bank56",ROMX,BANK[$56]
; Pics XV
@@ -24751,7 +24772,7 @@ MagnemiteBackpic: INCBIN "gfx/pics/081/back.lz"
; 15bffa
-SECTION "bank57",DATA,BANK[$57]
+SECTION "bank57",ROMX,BANK[$57]
; Pics XVI
@@ -24811,7 +24832,7 @@ UnownHBackpic: INCBIN "gfx/pics/201h/back.lz"
; 15ffff
-SECTION "bank58",DATA,BANK[$58]
+SECTION "bank58",ROMX,BANK[$58]
; Pics XVII
@@ -24879,7 +24900,7 @@ UnownDBackpic: INCBIN "gfx/pics/201d/back.lz"
; 163ffc
-SECTION "bank59",DATA,BANK[$59]
+SECTION "bank59",ROMX,BANK[$59]
; Pics XVIII
@@ -24946,7 +24967,7 @@ UnownRBackpic: INCBIN "gfx/pics/201r/back.lz"
; 1669d3
-SECTION "bank5A",DATA,BANK[$5A]
+SECTION "bank5A",ROMX,BANK[$5A]
; This bank is identical to bank 59!
; It's also unreferenced, so it's a free bank
@@ -25013,22 +25034,22 @@ INCBIN "gfx/pics/201i/back.lz"
INCBIN "gfx/pics/201r/back.lz"
-SECTION "bank5B",DATA,BANK[$5B]
+SECTION "bank5B",ROMX,BANK[$5B]
INCBIN "baserom.gbc", $16c000, $16d7fe - $16c000
-SECTION "bank5C",DATA,BANK[$5C]
+SECTION "bank5C",ROMX,BANK[$5C]
INCBIN "baserom.gbc", $170000, $17367f - $170000
-SECTION "bank5D",DATA,BANK[$5D]
+SECTION "bank5D",ROMX,BANK[$5D]
INCBIN "baserom.gbc", $174000, $177561 - $174000
-SECTION "bank5E",DATA,BANK[$5E]
+SECTION "bank5E",ROMX,BANK[$5E]
INCBIN "baserom.gbc", $178000, $1f
@@ -25051,12 +25072,12 @@ INCBIN "gfx/misc/mobile_adapter.2bpp"
INCBIN "baserom.gbc", $17a68f, $17b629 - $17a68f
-SECTION "bank5F",DATA,BANK[$5F]
+SECTION "bank5F",ROMX,BANK[$5F]
INCBIN "baserom.gbc", $17c000, $17ff6c - $17c000
-SECTION "bank60",DATA,BANK[$60]
+SECTION "bank60",ROMX,BANK[$60]
; Map Scripts XIII
@@ -25075,7 +25096,7 @@ PokedexEntries1:
INCLUDE "stats/pokedex/entries_1.asm"
-SECTION "bank61",DATA,BANK[$61]
+SECTION "bank61",ROMX,BANK[$61]
; Map Scripts XIV
@@ -25096,7 +25117,7 @@ INCLUDE "maps/BurnedTower1F.asm"
INCLUDE "maps/BurnedTowerB1F.asm"
-SECTION "bank62",DATA,BANK[$62]
+SECTION "bank62",ROMX,BANK[$62]
; Map Scripts XV
@@ -25126,7 +25147,7 @@ INCLUDE "maps/Route5SaffronCityGate.asm"
INCLUDE "maps/Route5CleanseTagSpeechHouse.asm"
-SECTION "bank63",DATA,BANK[$63]
+SECTION "bank63",ROMX,BANK[$63]
; Map Scripts XVI
@@ -25156,7 +25177,7 @@ INCLUDE "maps/KurtsHouse.asm"
INCLUDE "maps/AzaleaGym.asm"
-SECTION "bank64",DATA,BANK[$64]
+SECTION "bank64",ROMX,BANK[$64]
; Map Scripts XVII
@@ -25180,7 +25201,7 @@ INCLUDE "maps/MobileTradeRoomMobile.asm"
INCLUDE "maps/MobileBattleRoom.asm"
-SECTION "bank65",DATA,BANK[$65]
+SECTION "bank65",ROMX,BANK[$65]
; Map Scripts XVIII
@@ -25211,7 +25232,7 @@ INCLUDE "maps/MrPokemonsHouse.asm"
INCLUDE "maps/Route31VioletGate.asm"
-SECTION "bank66",DATA,BANK[$66]
+SECTION "bank66",ROMX,BANK[$66]
; Map Scripts XIX
@@ -25232,7 +25253,7 @@ INCLUDE "maps/BluesHouse.asm"
INCLUDE "maps/OaksLab.asm"
-SECTION "bank67",DATA,BANK[$67]
+SECTION "bank67",ROMX,BANK[$67]
; Map Scripts XX
@@ -25245,7 +25266,7 @@ INCLUDE "maps/Route19.asm"
INCLUDE "maps/Route25.asm"
-SECTION "bank68",DATA,BANK[$68]
+SECTION "bank68",ROMX,BANK[$68]
; Map Scripts XXI
@@ -25263,7 +25284,7 @@ INCLUDE "maps/PewterPokeCEnter2FBeta.asm"
INCLUDE "maps/PewterSnoozeSpeechHouse.asm"
-SECTION "bank69",DATA,BANK[$69]
+SECTION "bank69",ROMX,BANK[$69]
; Map Scripts XXII
@@ -25278,7 +25299,7 @@ INCLUDE "maps/Route41.asm"
INCLUDE "maps/Route12.asm"
-SECTION "bank6A",DATA,BANK[$6A]
+SECTION "bank6A",ROMX,BANK[$6A]
; Map Scripts XXIII
@@ -25299,7 +25320,7 @@ INCLUDE "maps/Route19FuchsiaGate.asm"
INCLUDE "maps/SeafoamGym.asm"
-SECTION "bank6B",DATA,BANK[$6B]
+SECTION "bank6B",ROMX,BANK[$6B]
; Map Scripts XXIV
@@ -25327,7 +25348,7 @@ INCLUDE "maps/SilverCavePokeCenter1F.asm"
INCLUDE "maps/Route28FamousSpeechHouse.asm"
-SECTION "bank6C",DATA,BANK[$6C]
+SECTION "bank6C",ROMX,BANK[$6C]
; Common text I
@@ -25339,7 +25360,7 @@ INCLUDE "maps/SilverCaveOutside.asm"
INCLUDE "maps/Route10North.asm"
-SECTION "bank6D",DATA,BANK[$6D]
+SECTION "bank6D",ROMX,BANK[$6D]
INCLUDE "text/phone/mom.tx"
INCLUDE "text/phone/bill.tx"
@@ -25347,7 +25368,7 @@ INCLUDE "text/phone/elm.tx"
INCLUDE "text/phone/trainers1.tx"
-SECTION "bank6E",DATA,BANK[$6E]
+SECTION "bank6E",ROMX,BANK[$6E]
; Pokedex entries II
; 065-128
@@ -25355,7 +25376,7 @@ PokedexEntries2:
INCLUDE "stats/pokedex/entries_2.asm"
-SECTION "bank6F",DATA,BANK[$6F]
+SECTION "bank6F",ROMX,BANK[$6F]
_FruitBearingTreeText: ; 0x1bc000
db $0, "It's a fruit-", $4f
@@ -25389,21 +25410,21 @@ _NothingHereText: ; 0x1bc055
INCBIN "baserom.gbc", $1bc06b, $1be08d - $1bc06b
-SECTION "bank70",DATA,BANK[$70]
+SECTION "bank70",ROMX,BANK[$70]
; Common text II
INCLUDE "text/common_2.tx"
-SECTION "bank71",DATA,BANK[$71]
+SECTION "bank71",ROMX,BANK[$71]
; Common text III
INCLUDE "text/common_3.tx"
-SECTION "bank72",DATA,BANK[$72]
+SECTION "bank72",ROMX,BANK[$72]
; Item names & descriptions
@@ -25453,7 +25474,7 @@ RegionCheck: ; 0x1caea1
ret
-SECTION "bank73",DATA,BANK[$73]
+SECTION "bank73",ROMX,BANK[$73]
; Pokedex entries III
; 129-192
@@ -25461,7 +25482,7 @@ PokedexEntries3:
INCLUDE "stats/pokedex/entries_3.asm"
-SECTION "bank74",DATA,BANK[$74]
+SECTION "bank74",ROMX,BANK[$74]
; Pokedex entries IV
; 193-251
@@ -25469,13 +25490,13 @@ PokedexEntries4:
INCLUDE "stats/pokedex/entries_4.asm"
-SECTION "bank75",DATA,BANK[$75]
+SECTION "bank75",ROMX,BANK[$75]
-SECTION "bank76",DATA,BANK[$76]
+SECTION "bank76",ROMX,BANK[$76]
-SECTION "bank77",DATA,BANK[$77]
+SECTION "bank77",ROMX,BANK[$77]
INCBIN "baserom.gbc", $1dc000, $1dc5a1 - $1dc000
@@ -25539,7 +25560,7 @@ INCBIN "gfx/misc/pokegear.lz"
INCBIN "baserom.gbc", $1de5c7, $1df238 - $1de5c7
-SECTION "bank78",DATA,BANK[$78]
+SECTION "bank78",ROMX,BANK[$78]
Tileset33Meta: ; 0x1e0000
INCBIN "tilesets/33_metatiles.bin"
@@ -25558,34 +25579,34 @@ INCBIN "tilesets/36_metatiles.bin"
; 0x1e1000
-SECTION "bank79",DATA,BANK[$79]
+SECTION "bank79",ROMX,BANK[$79]
-SECTION "bank7A",DATA,BANK[$7A]
+SECTION "bank7A",ROMX,BANK[$7A]
-SECTION "bank7B",DATA,BANK[$7B]
+SECTION "bank7B",ROMX,BANK[$7B]
INCBIN "baserom.gbc", $1ec000, $1ecf02 - $1ec000
-SECTION "bank7C",DATA,BANK[$7C]
+SECTION "bank7C",ROMX,BANK[$7C]
INCBIN "baserom.gbc", $1f0000, $1f09d8 - $1f0000
-SECTION "bank7D",DATA,BANK[$7D]
+SECTION "bank7D",ROMX,BANK[$7D]
INCBIN "baserom.gbc", $1f4000, $1f636a - $1f4000
-SECTION "bank7E",DATA,BANK[$7E]
+SECTION "bank7E",ROMX,BANK[$7E]
INCBIN "baserom.gbc", $1f8000, $1fb8a8 - $1f8000
-SECTION "bank7F",DATA,BANK[$7F]
+SECTION "bank7F",ROMX,BANK[$7F]
-SECTION "stadium2",DATA[$8000-$220],BANK[$7F]
+SECTION "stadium2",ROMX[$8000-$220],BANK[$7F]
INCBIN "baserom.gbc", $1ffde0, $220
diff --git a/wram.asm b/wram.asm
index b7a610ba4..f40e8d551 100644
--- a/wram.asm
+++ b/wram.asm
@@ -1,27 +1,24 @@
-SECTION "tiles0",VRAM[$8000]
+SECTION "tiles0",VRAM[$8000],BANK[0]
VTiles0:
-SECTION "tiles1",VRAM[$8800]
+SECTION "tiles1",VRAM[$8800],BANK[0]
VTiles1:
-SECTION "tiles2",VRAM[$9000]
+SECTION "tiles2",VRAM[$9000],BANK[0]
VTiles2:
-SECTION "bgmap0",VRAM[$9800]
+SECTION "bgmap0",VRAM[$9800],BANK[0]
VBGMap0:
-SECTION "bgmap1",VRAM[$9C00]
+SECTION "bgmap1",VRAM[$9C00],BANK[0]
VBGMap1:
-; WRAM banks 0 and 1 are included as BSS labels.
-; Other WRAM banks (2-7) are constants for now.
+SECTION "WRAMBank0",WRAM0[$c000]
-SECTION "WRAMBank0",BSS[$c000]
-
-SECTION "stack",BSS[$c000]
+SECTION "stack",WRAM0[$c000]
ds $100
Stack: ; c100
-SECTION "audio",BSS[$c100]
+SECTION "audio",WRAM0[$c100]
MusicPlaying: ; c100
; nonzero if playing
ds 1
@@ -309,7 +306,7 @@ CurMusic: ; c2c0
; id of music currently playing
ds 1
-SECTION "auto",BSS[$c2c7]
+SECTION "auto",WRAM0[$c2c7]
InputType: ; c2c7
AUTO_INPUT EQU $ff
ds 1
@@ -320,19 +317,19 @@ AutoInputBank: ; c2ca
AutoInputLength: ; c2cb
ds 1
-SECTION "linkbattle",BSS[$c2dc]
+SECTION "linkbattle",WRAM0[$c2dc]
InLinkBattle: ; c2dc
; 0 not in link battle
; 1 link battle
; 4 mobile battle
ds 1
-SECTION "scriptengine",BSS[$c2dd]
+SECTION "scriptengine",WRAM0[$c2dd]
ScriptVar: ; c2dd
ds 1
-SECTION "tiles",BSS[$c2fa]
+SECTION "tiles",WRAM0[$c2fa]
TileDown: ; c2fa
ds 1
TileUp: ; c2fb
@@ -351,12 +348,12 @@ TilePermissions: ; c2fe
; bit 0: right
ds 1
-SECTION "icons",BSS[$c3b6]
+SECTION "icons",WRAM0[$c3b6]
CurIcon: ; c3b6
ds 1
-SECTION "gfx",BSS[$c400]
+SECTION "gfx",WRAM0[$c400]
Sprites: ; c400
; 4 bytes per sprite
@@ -379,7 +376,7 @@ TileMap: ; c4a0
ds 360
-SECTION "BattleMons",BSS[$c608]
+SECTION "BattleMons",WRAM0[$c608]
EnemyMoveStruct:
EnemyMoveAnimation: ; c608
@@ -776,19 +773,19 @@ LastEnemyMove: ; c71c
ds 1
-SECTION "battle",BSS[$c734]
+SECTION "battle",WRAM0[$c734]
BattleEnded: ; c734
ds 1
-SECTION "overworldmap",BSS[$c800]
+SECTION "overworldmap",WRAM0[$c800]
OverworldMap: ; c800
ds 1300
OverworldMapEnd:
ds 12
-SECTION "gfx2",BSS[$cd20]
+SECTION "gfx2",WRAM0[$cd20]
BGMapBuffer:
CreditsPos: ; cd20
ds 2
@@ -845,7 +842,7 @@ TileX: ; cf83
-SECTION "VBlank",BSS[$cfb2]
+SECTION "VBlank",WRAM0[$cfb2]
TextDelayFrames: ; cfb2
ds 1
VBlankOccurred: ; cfb3
@@ -857,7 +854,7 @@ GameTimerPause: ; cfbc
; bit 0
ds 1
-SECTION "Engine",BSS[$cfc2]
+SECTION "Engine",WRAM0[$cfc2]
FXAnimID:
FXAnimIDLo: ; cfc2
ds 1
@@ -905,7 +902,7 @@ Options2: ; cfd1
ds 46
-SECTION "WRAMBank1",BSS[$d000]
+SECTION "WRAMBank1",WRAMX[$d000],BANK[1]
ds 2
@@ -1082,11 +1079,11 @@ CurPartyLevel: ; d143
ds 1
-SECTION "UsedSprites",BSS[$d154]
+SECTION "UsedSprites",WRAMX[$d154],BANK[1]
UsedSprites: ; d154
ds 32
-SECTION "connections",BSS[$d1a9]
+SECTION "connections",WRAMX[$d1a9],BANK[1]
MapConnections:
@@ -1205,7 +1202,7 @@ MovementType:
Buffer2: ; d1eb
ds 1
-SECTION "BattleMons2",BSS[$d1fa]
+SECTION "BattleMons2",WRAMX[$d1fa],BANK[1]
LinkBattleRNs: ; d1fa
ds 10
@@ -1391,7 +1388,7 @@ CurDamage: ; d256
ds 2
-SECTION "TimeOfDay",BSS[$d269]
+SECTION "TimeOfDay",WRAMX[$d269],BANK[1]
TimeOfDay: ; d269
MORN EQU 0
@@ -1400,7 +1397,7 @@ NITE EQU 2
DARKNESS EQU 3
ds 1
-SECTION "OTParty",BSS[$d280]
+SECTION "OTParty",WRAMX[$d280],BANK[1]
OTPartyCount: ; d280
ds 1 ; number of Pokémon in party
@@ -1530,7 +1527,7 @@ OTPartyMon5Nickname: ; d416
OTPartyMon6Nickname: ; d421
ds 11
-SECTION "Scripting",BSS[$d434]
+SECTION "Scripting",WRAMX[$d434],BANK[1]
ScriptFlags: ; d434
SCRIPT_RUNNING EQU 2
ds 1
@@ -1555,7 +1552,7 @@ ScriptPos: ; d43a
ScriptDelay: ; d44d
ds 1
-SECTION "Player",BSS[$d472]
+SECTION "Player",WRAMX[$d472],BANK[1]
PlayerGender: ; d472
; bit 0:
; 0 male
@@ -1627,7 +1624,7 @@ PlayerDirection: ; d4de
ds 1
-SECTION "MapEngine",BSS[$d4e4]
+SECTION "MapEngine",WRAMX[$d4e4],BANK[1]
StandingTile: ; d4e4
ds 1
StandingTile2: ; d4e5
@@ -1652,7 +1649,7 @@ PlayerSpriteY: ; d4ee
ds 1
-SECTION "Objects",BSS[$d71e]
+SECTION "Objects",WRAMX[$d71e],BANK[1]
MapObjects: ; d71e
PLAYER_OBJECT EQU 0
@@ -1662,12 +1659,12 @@ OBJECT_LENGTH EQU $10
ds OBJECT_LENGTH * NUM_OBJECTS
-SECTION "VariableSprites",BSS[$d82e]
+SECTION "VariableSprites",WRAMX[$d82e],BANK[1]
VariableSprites: ; d82e
ds $10
-SECTION "Status",BSS[$d841]
+SECTION "Status",WRAMX[$d841],BANK[1]
TimeOfDayPal: ; d841
ds 1
ds 4
@@ -1695,7 +1692,7 @@ JohtoBadges: ; d857
KantoBadges: ; d858
ds 1
-SECTION "Items",BSS[$d859]
+SECTION "Items",WRAMX[$d859],BANK[1]
TMsHMs: ; d859
ds 57
@@ -1714,7 +1711,7 @@ NumBalls: ; d8d7
Balls: ; d8d8
ds 25
-SECTION "overworld",BSS[$d95b]
+SECTION "overworld",WRAMX[$d95b],BANK[1]
WhichRegisteredItem: ; d95b
REGISTERED_POCKET EQU %11000000
REGISTERED_NUMBER EQU %00111111
@@ -1730,7 +1727,7 @@ PLAYER_SURF EQU 4
PLAYER_SURF_PIKA EQU 8
ds 1
-SECTION "scriptram",BSS[$d962]
+SECTION "scriptram",WRAMX[$d962],BANK[1]
MooMooBerries: ; d962
ds 1 ; how many berries fed to MooMoo
UndergroundSwitchPositions: ; d963
@@ -1738,7 +1735,7 @@ UndergroundSwitchPositions: ; d963
FarfetchdPosition: ; d964
ds 1 ; which position the ilex farfetch'd is in
-SECTION "Events",BSS[$dad4]
+SECTION "Events",WRAMX[$dad4],BANK[1]
;RoomDecorations: ; dac6
; db 7
@@ -1756,7 +1753,7 @@ LugiaEvent: ; dad5
;SalesmanMahoganyTownEvent: ; db5c
;RedGyaradosEvent: ; db5c
-SECTION "BoxNames",BSS[$db75]
+SECTION "BoxNames",WRAMX[$db75],BANK[1]
; 8 chars + $50
Box1Name: ; db75
ds 9
@@ -1787,13 +1784,13 @@ Box13Name: ; dbe1
Box14Name: ; dbea
ds 9
-SECTION "bike", BSS[$dbf5]
+SECTION "bike", WRAMX[$dbf5],BANK[1]
BikeFlags: ; dbf5
; bit 1: always on bike
; bit 2: downhill
ds 1
-SECTION "decorations", BSS[$dc0f]
+SECTION "decorations", WRAMX[$dc0f],BANK[1]
; Sprite id of each decoration
Bed: ; dc0f
ds 1
@@ -1812,21 +1809,21 @@ RightOrnament: ; dc15
BigDoll: ; dc16
ds 1
-SECTION "fruittrees", BSS[$dc27]
+SECTION "fruittrees", WRAMX[$dc27],BANK[1]
FruitTreeFlags: ; dc27
ds 1
-SECTION "steps", BSS[$dc73]
+SECTION "steps", WRAMX[$dc73],BANK[1]
StepCount: ; dc73
ds 1
PoisonStepCount: ; dc74
ds 1
-SECTION "FlypointPermissions", BSS[$dca5]
+SECTION "FlypointPermissions", WRAMX[$dca5],BANK[1]
FlypointPerms: ; dca5
ds 4
-SECTION "BackupMapInfo", BSS[$dcad]
+SECTION "BackupMapInfo", WRAMX[$dcad],BANK[1]
; used on maps like second floor pokécenter, which are reused, so we know which
; map to return to
@@ -1835,7 +1832,7 @@ BackupMapGroup: ; dcad
BackupMapNumber: ; dcae
ds 1
-SECTION "PlayerMapInfo", BSS[$dcb4]
+SECTION "PlayerMapInfo", WRAMX[$dcb4],BANK[1]
WarpNumber: ; dcb4
ds 1
@@ -1848,7 +1845,7 @@ YCoord: ; dcb7
XCoord: ; dcb8
ds 1 ; current x coordinate relative to top-left corner of current map
-SECTION "PlayerParty",BSS[$dcd7]
+SECTION "PlayerParty",WRAMX[$dcd7],BANK[1]
PartyCount: ; dcd7
ds 1 ; number of Pokémon in party
@@ -1968,7 +1965,7 @@ PartyMon5Nickname: ; de6d
PartyMon6Nickname: ; de78
ds 11
-SECTION "Pokedex",BSS[$de99]
+SECTION "Pokedex",WRAMX[$de99],BANK[1]
PokedexSeen: ; de99
ds 32
EndPokedexSeen:
@@ -1980,7 +1977,7 @@ UnownDex: ; ded9
UnlockedUnowns: ; def3
ds 1
-SECTION "Breeding",BSS[$def5]
+SECTION "Breeding",WRAMX[$def5],BANK[1]
DaycareMan: ; def5
; bit 7: active
; bit 6: monsters are compatible
@@ -2030,7 +2027,7 @@ EggSpecies: ; df7b
ds 1
ds 31
-SECTION "RoamMons",BSS[$dfcf]
+SECTION "RoamMons",WRAMX[$dfcf],BANK[1]
RoamMon1Species: ; dfcf
ds 1
RoamMon1Level: ; dfd0
@@ -2072,14 +2069,15 @@ RoamMon3DVs: ; dfe2
-; SECTION "WRAMBank5",BSS[$d000]
+SECTION "WRAMBank5",WRAMX[$d000],BANK[5]
; 8 4-color palettes
-Unkn1Pals EQU $d000
-Unkn2Pals EQU $d040
-BGPals EQU $d080
-OBPals EQU $d0c0
-
-
-
+Unkn1Pals:
+ ds $40
+Unkn2Pals:
+ ds $40
+BGPals:
+ ds $40
+OBPals:
+ ds $40