mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2024-11-16 11:27:33 -08:00
Merge branch 'kanzure/master' into yenatch/master
This commit is contained in:
commit
d2333a90c9
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "extras"]
|
||||
path = extras
|
||||
url = git://github.com/kanzure/pokemon-reverse-engineering-tools.git
|
39
INSTALL.md
39
INSTALL.md
@ -9,13 +9,10 @@ md5: 9f2922b235a5eeb78d65594e82ef5dde
|
||||
|
||||
Save it as **baserom.gbc** in the repository.
|
||||
|
||||
|
||||
Feel free to ask us on
|
||||
**[nucleus.kafuka.org #skeetendo](https://kiwiirc.com/client/irc.nolimitzone.com/?#skeetendo)**
|
||||
if something goes wrong.
|
||||
|
||||
|
||||
|
||||
# Windows
|
||||
|
||||
If you're on Windows and can't install Linux, **Cygwin** is a great alternative.
|
||||
@ -39,7 +36,6 @@ During the install:
|
||||
* **python-setuptools**
|
||||
* **unzip**
|
||||
|
||||
|
||||
## Using Cygwin
|
||||
|
||||
Launch the **Cygwin terminal**.
|
||||
@ -56,7 +52,6 @@ pwd
|
||||
cd /away/we/go
|
||||
```
|
||||
|
||||
|
||||
## Getting up and running
|
||||
|
||||
We need three things to assemble the source into a rom.
|
||||
@ -65,8 +60,6 @@ We need three things to assemble the source into a rom.
|
||||
2. a **pokecrystal** repository
|
||||
3. a **base rom**
|
||||
|
||||
-
|
||||
|
||||
We use **rgbds** to spit out a Game Boy rom from source.
|
||||
```bash
|
||||
cd /usr/local/bin
|
||||
@ -96,10 +89,17 @@ md5: 9f2922b235a5eeb78d65594e82ef5dde
|
||||
|
||||
Name it **baserom.gbc**.
|
||||
|
||||
-
|
||||
**pokecrystal** only compiles with the use of a git submodule. To activate the submodule type:
|
||||
|
||||
```
|
||||
git submodule init
|
||||
git submodule update
|
||||
```
|
||||
|
||||
Now you should be able to build **pokecrystal.gbc** for the first time.
|
||||
This assembles a new rom from the source code.
|
||||
|
||||
This compiles a new rom from the source code, with any patches filled in from the base rom.
|
||||
|
||||
```bash
|
||||
make
|
||||
```
|
||||
@ -112,8 +112,6 @@ Your first build processes every source file at once.
|
||||
After that, **only modified source files have to be processed again**,
|
||||
so compiling again should be a few seconds faster.
|
||||
|
||||
|
||||
|
||||
# Linux
|
||||
|
||||
```bash
|
||||
@ -131,7 +129,16 @@ cd ..
|
||||
# download pokecrystal
|
||||
git clone git://github.com/kanzure/pokecrystal.git
|
||||
cd pokecrystal
|
||||
pip install -r requirements.txt
|
||||
|
||||
# grab extras/ which is required for compiling
|
||||
git submodule init
|
||||
git submodule update
|
||||
|
||||
# install python requirements
|
||||
pip install -r extras/requirements.txt
|
||||
|
||||
# use hexdump to diff binary files
|
||||
git config diff.hex.textconv hexdump
|
||||
```
|
||||
|
||||
Put your base rom in the pokecrystal repository. Name it **baserom.gbc**.
|
||||
@ -145,7 +152,6 @@ That will take between 3 and 15 seconds, depending on your computer.
|
||||
If you see `cmp baserom.gbc pokecrystal.gbc` as the last line, the build was successful! Rejoice!
|
||||
|
||||
|
||||
|
||||
# Now what?
|
||||
|
||||
**[pokecrystal.asm](https://github.com/kanzure/pokecrystal/blob/master/pokecrystal.asm)** is a good starting point.
|
||||
@ -169,3 +175,10 @@ We'll be happy to answer any **questions** on
|
||||
**[nucleus.kafuka.org #skeetendo](https://kiwiirc.com/client/irc.nolimitzone.com/?#skeetendo)**.
|
||||
|
||||
|
||||
Other **make targets** that may come in handy:
|
||||
|
||||
`make clean` deletes any preprocessed source files (.tx), rgbds object files and pokecrystal.gbc, in case something goes wrong.
|
||||
|
||||
`make pngs` decompresses any **lz** files in gfx/ and then exports any graphics files to **png**.
|
||||
|
||||
`make lzs` does the reverse. This is already part of the build process, so **modified pngs will automatically be converted to 2bpp and lz-compressed** without any additional work.
|
||||
|
21
Makefile
21
Makefile
@ -7,8 +7,8 @@ PNG_GFX := $(shell find gfx/ -type f -name '*.png')
|
||||
LZ_GFX := $(shell find gfx/ -type f -name '*.lz')
|
||||
TWOBPP_GFX := $(shell find gfx/ -type f -name '*.2bpp')
|
||||
|
||||
all: pokecrystal.gbc
|
||||
cmp baserom.gbc $<
|
||||
all: baserom.gbc pokecrystal.gbc
|
||||
cmp baserom.gbc pokecrystal.gbc
|
||||
clean:
|
||||
rm -f pokecrystal.o pokecrystal.gbc
|
||||
@echo 'rm -f $(TEXTFILES:.asm=.tx)'
|
||||
@ -19,27 +19,30 @@ pokecrystal.o: $(TEXTFILES:.asm=.tx) wram.asm constants.asm $(shell find constan
|
||||
.asm.tx:
|
||||
$(eval TEXTQUEUE := $(TEXTQUEUE) $<)
|
||||
@rm -f $@
|
||||
baserom.gbc:
|
||||
python -c "import os; assert 'baserom.gbc' in os.listdir('.'), 'Wait! Need baserom.gbc first. Check README and INSTALL for details.';"
|
||||
|
||||
pokecrystal.gbc: pokecrystal.o
|
||||
rgblink -n pokecrystal.sym -m pokecrystal.map -o $@ $<
|
||||
rgbfix -Cjv -i BYTE -k 01 -l 0x33 -m 0x10 -p 0 -r 3 -t PM_CRYSTAL $@
|
||||
|
||||
pngs:
|
||||
cd extras && python gfx.py mass-decompress && python gfx.py dump-pngs
|
||||
python extras/pokemontools/gfx.py mass-decompress
|
||||
python extras/pokemontools/gfx.py dump-pngs
|
||||
|
||||
lzs: $(LZ_GFX) $(TWOBPP_GFX)
|
||||
@:
|
||||
|
||||
gfx/pics/%/front.lz: gfx/pics/%/tiles.2bpp gfx/pics/%/front.png
|
||||
python extras/gfx.py png-to-lz --front $^
|
||||
python extras/pokemontools/gfx.py png-to-lz --front $^
|
||||
gfx/pics/%/tiles.2bpp: gfx/pics/%/tiles.png
|
||||
python extras/gfx.py png-to-2bpp $<
|
||||
python extras/pokemontools/gfx.py png-to-2bpp $<
|
||||
gfx/pics/%/back.lz: gfx/pics/%/back.png
|
||||
python extras/gfx.py png-to-lz --vert $<
|
||||
python extras/pokemontools/gfx.py png-to-lz --vert $<
|
||||
gfx/trainers/%.lz: gfx/trainers/%.png
|
||||
python extras/gfx.py png-to-lz --vert $<
|
||||
python extras/pokemontools/gfx.py png-to-lz --vert $<
|
||||
.png.lz:
|
||||
python extras/gfx.py png-to-lz $<
|
||||
python extras/pokemontools/gfx.py png-to-lz $<
|
||||
.png.2bpp:
|
||||
python extras/gfx.py png-to-lz $<
|
||||
python extras/pokemontools/gfx.py png-to-lz $<
|
||||
|
||||
|
1
extras
Submodule
1
extras
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 016f0206b5029fc83a6200be29b0f980c76dfd90
|
255
extras/README.md
255
extras/README.md
@ -1,255 +0,0 @@
|
||||
Pokémon Crystal utilities and extras
|
||||
==============================
|
||||
|
||||
`crystal.py` parses the ROM and provides convenient classes to dump human-readable ASM with the global `to_asm()` method. This ASM can then be compiled back into the original ROM. Currently it parses map headers, "second" map headers, map event headers, map script headers, map triggers, map "callbacks", map blockdata, xy triggers, warps, people-events, texts and scripts.
|
||||
|
||||
#### Simple ASM generation example
|
||||
|
||||
Note: throughout these examples it is possible to use `reload(crystal)` instead of `import crystal`. Once the module is loaded a first time, it must be reloaded if the file changes and the updates are desired.
|
||||
|
||||
```python
|
||||
import crystal
|
||||
|
||||
# parse the ROM
|
||||
crystal.run_main()
|
||||
|
||||
# create a new dump
|
||||
asm = crystal.Asm()
|
||||
|
||||
# insert the first 10 maps
|
||||
x = 10
|
||||
asm.insert_with_dependencies(crystal.all_map_headers[:x])
|
||||
|
||||
# dump to extras/output.txt
|
||||
asm.dump()
|
||||
```
|
||||
|
||||
After running those lines, `cp extras/output.txt main.asm` and run `git diff main.asm` to confirm that changes to `main.asm` have occurred. To test whether or not the newly inserted ASM compiles into the same ROM, use: `make clean && make`. This will complain very loudly if something is broken.
|
||||
|
||||
#### Testing
|
||||
|
||||
Unit tests cover most of the classes.
|
||||
|
||||
```bash
|
||||
python tests.py
|
||||
```
|
||||
|
||||
#### Parsing a script at a known address
|
||||
|
||||
Here is a demo of how to investigate a particular script, starting with only an address to a known script (0x58043). In this case, the script calls the `2writetext` command to show some dialog. This dialog will be shown at the end of the example.
|
||||
|
||||
```python
|
||||
import crystal
|
||||
|
||||
# parse the script at 0x58043 from the map event header at 0x584c3
|
||||
# from the second map header at 0x958b8
|
||||
# from the map header at 0x941ae
|
||||
# for "Ruins of Alph Outside" (map_group=3 map_id=0x16)
|
||||
script = Script(0x58043)
|
||||
|
||||
# show the script
|
||||
print script.to_asm()
|
||||
|
||||
# what labels does it point to in the to_asm output?
|
||||
# these must be present in the final asm file for rgbasm to compile the file
|
||||
objdeps = script.get_dependencies()
|
||||
print str(objdeps)
|
||||
|
||||
# the individual commands that make up the script
|
||||
commands = script.commands
|
||||
print str(commands)
|
||||
|
||||
# the 3rd command is 2writetext and points to a text
|
||||
thirdcommand = script.commands[2]
|
||||
print thirdcommand
|
||||
# <crystal.2writetextCommand instance at 0x8ad4c0c>
|
||||
|
||||
# look at the command parameters
|
||||
params = thirdcommand.params
|
||||
print params
|
||||
# {0: <crystal.RawTextPointerLabelParam instance at 0x8ad4b0c>}
|
||||
|
||||
# 2writetext always has a single parameter
|
||||
definition_param_count = len(getattr(crystal, "2writetextCommand").param_types.keys())
|
||||
current_param_count = len(params.keys())
|
||||
assert definition_param_count == current_param_count, "this should never " + \
|
||||
"happen: instance of a command has more parameters than the " + \
|
||||
"definition of the command allows"
|
||||
|
||||
# get the first parameter (the text pointer)
|
||||
param = params[0]
|
||||
print param
|
||||
# <crystal.RawTextPointerLabelParam instance at 0x8ad4b0c>
|
||||
|
||||
# RawTextPointerLabelParam instances point to their text
|
||||
text = param.text
|
||||
print text
|
||||
# <crystal.TextScript instance at 0x8ad47ec>
|
||||
|
||||
# now investigate this text appearing in this script in "Ruins of Alph Outside"
|
||||
print text.to_asm()
|
||||
```
|
||||
|
||||
The final output will be the following text.
|
||||
|
||||
```asm
|
||||
db $0, "Hm? That's a #-", $4f
|
||||
db "DEX, isn't it?", $55
|
||||
; ...
|
||||
```
|
||||
|
||||
However, this is not how that `TextScript` object would appear in the final ASM. To see how it would appear in `main.asm` once inserted, you would run `print crystal.to_asm(text)` to get the following.
|
||||
|
||||
```asm
|
||||
UnknownText_0x580c7: ; 0x580c7
|
||||
db $0, "Hm? That's a #-", $4f
|
||||
db "DEX, isn't it?", $55
|
||||
db "May I see it?", $51
|
||||
db "There are so many", $4f
|
||||
db "kinds of #MON.", $51
|
||||
db "Hm? What's this?", $51
|
||||
db "What is this", $4f
|
||||
db "#MON?", $51
|
||||
db "It looks like the", $4f
|
||||
db "strange writing on", $51
|
||||
db "the walls of the", $4f
|
||||
db "RUINS.", $51
|
||||
db "If those drawings", $4f
|
||||
db "are really #-", $55
|
||||
db "MON, there should", $55
|
||||
db "be many more.", $51
|
||||
db "I know! Let me up-", $4f
|
||||
db "grade your #-", $55
|
||||
db "DEX. Follow me.", $57
|
||||
; 0x581e5
|
||||
```
|
||||
|
||||
#### Figuring out where a script appears based on a known address
|
||||
|
||||
Another approach is to parse the entire ROM, then check a script at a particular address. This has the advantage that the script object will have the `map_group` and `map_id` variables set.
|
||||
|
||||
```python
|
||||
import crystal
|
||||
|
||||
# parse the ROM
|
||||
crystal.run_main()
|
||||
|
||||
# get the parsed script
|
||||
script = crystal.script_parse_table[0x58043]
|
||||
|
||||
# read its attributes to figure out map group / map id
|
||||
map_group = script.map_group
|
||||
map_id = script.map_id
|
||||
|
||||
# MapHeader is not given all the info yet
|
||||
# in the mean time "map_names" contains some metadata
|
||||
map_dict = crystal.map_names[map_group][map_id]
|
||||
map_header = map_dict["header_new"]
|
||||
|
||||
print map_dict["name"]
|
||||
# Ruins of Alph Outside
|
||||
```
|
||||
|
||||
While the above doesn't show this, it turns out that the script at 0x58043 is referenced in the `MapEventHeader` as a person-event.
|
||||
|
||||
```python
|
||||
print map_header.second_map_header.event_header.to_asm()
|
||||
```
|
||||
|
||||
This will show a structure roughly like:
|
||||
|
||||
```asm
|
||||
person_event $3c, 19, 15, $7, $0, 255, 255, $0, 0, UnknownScript_0x58043, $0703
|
||||
```
|
||||
|
||||
within this:
|
||||
|
||||
```asm
|
||||
MapEventHeader_0x584c3: ; 0x584c3
|
||||
; filler
|
||||
db 0, 0
|
||||
|
||||
; warps
|
||||
db 11
|
||||
warp_def $11, $2, 1, GROUP_RUINS_OF_ALPH_HO_OH_CHAMBER, MAP_RUINS_OF_ALPH_HO_OH_CHAMBER
|
||||
warp_def $7, $e, 1, GROUP_RUINS_OF_ALPH_KABUTO_CHAMBER, MAP_RUINS_OF_ALPH_KABUTO_CHAMBER
|
||||
warp_def $1d, $2, 1, GROUP_RUINS_OF_ALPH_OMANYTE_CHAMBER, MAP_RUINS_OF_ALPH_OMANYTE_CHAMBER
|
||||
warp_def $21, $10, 1, GROUP_RUINS_OF_ALPH_AERODACTYL_CHAMBER, MAP_RUINS_OF_ALPH_AERODACTYL_CHAMBER
|
||||
warp_def $d, $a, 1, GROUP_RUINS_OF_ALPH_INNER_CHAMBER, MAP_RUINS_OF_ALPH_INNER_CHAMBER
|
||||
warp_def $b, $11, 1, GROUP_RUINS_OF_ALPH_RESEARCH_CENTER, MAP_RUINS_OF_ALPH_RESEARCH_CENTER
|
||||
warp_def $13, $6, 1, GROUP_UNION_CAVE_B1F, MAP_UNION_CAVE_B1F
|
||||
warp_def $1b, $6, 2, GROUP_UNION_CAVE_B1F, MAP_UNION_CAVE_B1F
|
||||
warp_def $5, $7, 3, GROUP_ROUTE_36_RUINS_OF_ALPH_GATE, MAP_ROUTE_36_RUINS_OF_ALPH_GATE
|
||||
warp_def $14, $d, 1, GROUP_ROUTE_32_RUINS_OF_ALPH_GATE, MAP_ROUTE_32_RUINS_OF_ALPH_GATE
|
||||
warp_def $15, $d, 2, GROUP_ROUTE_32_RUINS_OF_ALPH_GATE, MAP_ROUTE_32_RUINS_OF_ALPH_GATE
|
||||
|
||||
; xy triggers
|
||||
db 2
|
||||
xy_trigger 1, $e, $b, $0, UnknownScript_0x58031, $0, $0
|
||||
xy_trigger 1, $f, $a, $0, UnknownScript_0x5803a, $0, $0
|
||||
|
||||
; signposts
|
||||
db 3
|
||||
signpost 8, 16, $0, UnknownScript_0x580b1
|
||||
signpost 16, 12, $0, UnknownScript_0x580b4
|
||||
signpost 12, 18, $0, UnknownScript_0x580b7
|
||||
|
||||
; people-events
|
||||
db 5
|
||||
person_event $27, 24, 8, $6, $0, 255, 255, $2, 1, Trainer_0x58089, $ffff
|
||||
person_event $3c, 19, 15, $7, $0, 255, 255, $0, 0, UnknownScript_0x58043, $0703
|
||||
person_event $3a, 21, 17, $3, $0, 255, 255, $a0, 0, UnknownScript_0x58061, $078e
|
||||
person_event $27, 15, 18, $2, $11, 255, 255, $b0, 0, UnknownScript_0x58076, $078f
|
||||
person_event $27, 12, 16, $7, $0, 255, 255, $80, 0, UnknownScript_0x5807e, $078f
|
||||
; 0x58560
|
||||
```
|
||||
|
||||
#### Helpful ROM investigation tools
|
||||
|
||||
```python
|
||||
import crystal
|
||||
|
||||
# load the bytes
|
||||
crystal.load_rom()
|
||||
|
||||
# get a sequence of bytes
|
||||
crystal.rom_interval(0x112116, 10)
|
||||
# ['0x48', '0x54', '0x54', '0x50', '0x2f', '0x31', '0x2e', '0x30', '0xd', '0xa']
|
||||
crystal.rom_interval(0x112116, 10, strings=False)
|
||||
# [72, 84, 84, 80, 47, 49, 46, 48, 13, 10]
|
||||
|
||||
# get bytes until a certain byte
|
||||
crystal.rom_until(0x112116, 0x50, strings=False)
|
||||
# ['0x48', '0x54', '0x54']
|
||||
# [72, 84, 84]
|
||||
|
||||
# or just look at the encoded characters directly
|
||||
crystal.rom[0x112116:0x112116+10]
|
||||
# 'HTTP/1.0\r\n'
|
||||
|
||||
# look at a text at 0x197186
|
||||
text = crystal.parse_text_at2(0x197186, 601, debug=False)
|
||||
print text
|
||||
```
|
||||
|
||||
That last text at 0x197186 will look like:
|
||||
|
||||
```python
|
||||
"""
|
||||
OAK: Aha! So
|
||||
you're !
|
||||
I'm OAK! A #MON
|
||||
researcher.
|
||||
I was just visit-
|
||||
ing my old friend
|
||||
MR.#MON.
|
||||
I heard you were
|
||||
running an errand
|
||||
for PROF.ELM, so I
|
||||
waited here.
|
||||
Oh! What's this?
|
||||
A rare #MON!
|
||||
...
|
||||
"""
|
||||
```
|
||||
|
281
extras/chars.py
281
extras/chars.py
@ -1,281 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from copy import copy
|
||||
|
||||
# this is straight out of ../preprocessor.py because i'm lazy
|
||||
# (also, it's flipped)
|
||||
# see jap_chars for overrides if you are in japanese mode?
|
||||
chars = {
|
||||
0x50: "@",
|
||||
0x54: "#",
|
||||
0x75: "…",
|
||||
|
||||
0x79: "┌",
|
||||
0x7A: "─",
|
||||
0x7B: "┐",
|
||||
0x7C: "│",
|
||||
0x7D: "└",
|
||||
0x7E: "┘",
|
||||
|
||||
0x74: "№",
|
||||
|
||||
0x7F: " ",
|
||||
0x80: "A",
|
||||
0x81: "B",
|
||||
0x82: "C",
|
||||
0x83: "D",
|
||||
0x84: "E",
|
||||
0x85: "F",
|
||||
0x86: "G",
|
||||
0x87: "H",
|
||||
0x88: "I",
|
||||
0x89: "J",
|
||||
0x8A: "K",
|
||||
0x8B: "L",
|
||||
0x8C: "M",
|
||||
0x8D: "N",
|
||||
0x8E: "O",
|
||||
0x8F: "P",
|
||||
0x90: "Q",
|
||||
0x91: "R",
|
||||
0x92: "S",
|
||||
0x93: "T",
|
||||
0x94: "U",
|
||||
0x95: "V",
|
||||
0x96: "W",
|
||||
0x97: "X",
|
||||
0x98: "Y",
|
||||
0x99: "Z",
|
||||
0x9A: "(",
|
||||
0x9B: ")",
|
||||
0x9C: ":",
|
||||
0x9D: ";",
|
||||
0x9E: "[",
|
||||
0x9F: "]",
|
||||
0xA0: "a",
|
||||
0xA1: "b",
|
||||
0xA2: "c",
|
||||
0xA3: "d",
|
||||
0xA4: "e",
|
||||
0xA5: "f",
|
||||
0xA6: "g",
|
||||
0xA7: "h",
|
||||
0xA8: "i",
|
||||
0xA9: "j",
|
||||
0xAA: "k",
|
||||
0xAB: "l",
|
||||
0xAC: "m",
|
||||
0xAD: "n",
|
||||
0xAE: "o",
|
||||
0xAF: "p",
|
||||
0xB0: "q",
|
||||
0xB1: "r",
|
||||
0xB2: "s",
|
||||
0xB3: "t",
|
||||
0xB4: "u",
|
||||
0xB5: "v",
|
||||
0xB6: "w",
|
||||
0xB7: "x",
|
||||
0xB8: "y",
|
||||
0xB9: "z",
|
||||
0xC0: "Ä",
|
||||
0xC1: "Ö",
|
||||
0xC2: "Ü",
|
||||
0xC3: "ä",
|
||||
0xC4: "ö",
|
||||
0xC5: "ü",
|
||||
0xD0: "'d",
|
||||
0xD1: "'l",
|
||||
0xD2: "'m",
|
||||
0xD3: "'r",
|
||||
0xD4: "'s",
|
||||
0xD5: "'t",
|
||||
0xD6: "'v",
|
||||
0xE0: "'",
|
||||
0xE3: "-",
|
||||
0xE6: "?",
|
||||
0xE7: "!",
|
||||
0xE8: ".",
|
||||
0xE9: "&",
|
||||
0xEA: "é",
|
||||
0xEB: "→",
|
||||
0xEC: "▷",
|
||||
0xED: "▶",
|
||||
0xEE: "▼",
|
||||
0xEF: "♂",
|
||||
0xF0: "¥",
|
||||
0xF1: "×",
|
||||
0xF3: "/",
|
||||
0xF4: ",",
|
||||
0xF5: "♀",
|
||||
0xF6: "0",
|
||||
0xF7: "1",
|
||||
0xF8: "2",
|
||||
0xF9: "3",
|
||||
0xFA: "4",
|
||||
0xFB: "5",
|
||||
0xFC: "6",
|
||||
0xFD: "7",
|
||||
0xFE: "8",
|
||||
0xFF: "9",
|
||||
}
|
||||
|
||||
#override whatever defaults for japanese symbols
|
||||
jap_chars = copy(chars)
|
||||
jap_chars.update({
|
||||
0x05: "ガ",
|
||||
0x06: "ギ",
|
||||
0x07: "グ",
|
||||
0x08: "ゲ",
|
||||
0x09: "ゴ",
|
||||
0x0A: "ザ",
|
||||
0x0B: "ジ",
|
||||
0x0C: "ズ",
|
||||
0x0D: "ゼ",
|
||||
0x0E: "ゾ",
|
||||
0x0F: "ダ",
|
||||
0x10: "ヂ",
|
||||
0x11: "ヅ",
|
||||
0x12: "デ",
|
||||
0x13: "ド",
|
||||
0x19: "バ",
|
||||
0x1A: "ビ",
|
||||
0x1B: "ブ",
|
||||
0x1C: "ボ",
|
||||
0x26: "が",
|
||||
0x27: "ぎ",
|
||||
0x28: "ぐ",
|
||||
0x29: "げ",
|
||||
0x2A: "ご",
|
||||
0x2B: "ざ",
|
||||
0x2C: "じ",
|
||||
0x2D: "ず",
|
||||
0x2E: "ぜ",
|
||||
0x2F: "ぞ",
|
||||
0x30: "だ",
|
||||
0x31: "ぢ",
|
||||
0x32: "づ",
|
||||
0x33: "で",
|
||||
0x34: "ど",
|
||||
0x3A: "ば",
|
||||
0x3B: "び",
|
||||
0x3C: "ぶ",
|
||||
0x3D: "べ",
|
||||
0x3E: "ぼ",
|
||||
0x40: "パ",
|
||||
0x41: "ピ",
|
||||
0x42: "プ",
|
||||
0x43: "ポ",
|
||||
0x44: "ぱ",
|
||||
0x45: "ぴ",
|
||||
0x46: "ぷ",
|
||||
0x47: "ぺ",
|
||||
0x48: "ぽ",
|
||||
0x80: "ア",
|
||||
0x81: "イ",
|
||||
0x82: "ウ",
|
||||
0x83: "エ",
|
||||
0x84: "ォ",
|
||||
0x85: "カ",
|
||||
0x86: "キ",
|
||||
0x87: "ク",
|
||||
0x88: "ケ",
|
||||
0x89: "コ",
|
||||
0x8A: "サ",
|
||||
0x8B: "シ",
|
||||
0x8C: "ス",
|
||||
0x8D: "セ",
|
||||
0x8E: "ソ",
|
||||
0x8F: "タ",
|
||||
0x90: "チ",
|
||||
0x91: "ツ",
|
||||
0x92: "テ",
|
||||
0x93: "ト",
|
||||
0x94: "ナ",
|
||||
0x95: "ニ",
|
||||
0x96: "ヌ",
|
||||
0x97: "ネ",
|
||||
0x98: "ノ",
|
||||
0x99: "ハ",
|
||||
0x9A: "ヒ",
|
||||
0x9B: "フ",
|
||||
0x9C: "ホ",
|
||||
0x9D: "マ",
|
||||
0x9E: "ミ",
|
||||
0x9F: "ム",
|
||||
0xA0: "メ",
|
||||
0xA1: "モ",
|
||||
0xA2: "ヤ",
|
||||
0xA3: "ユ",
|
||||
0xA4: "ヨ",
|
||||
0xA5: "ラ",
|
||||
0xA6: "ル",
|
||||
0xA7: "レ",
|
||||
0xA8: "ロ",
|
||||
0xA9: "ワ",
|
||||
0xAA: "ヲ",
|
||||
0xAB: "ン",
|
||||
0xAC: "ッ",
|
||||
0xAD: "ャ",
|
||||
0xAE: "ュ",
|
||||
0xAF: "ョ",
|
||||
0xB0: "ィ",
|
||||
0xB1: "あ",
|
||||
0xB2: "い",
|
||||
0xB3: "う",
|
||||
0xB4: "え",
|
||||
0xB5: "お",
|
||||
0xB6: "か",
|
||||
0xB7: "き",
|
||||
0xB8: "く",
|
||||
0xB9: "け",
|
||||
0xBA: "こ",
|
||||
0xBB: "さ",
|
||||
0xBC: "し",
|
||||
0xBD: "す",
|
||||
0xBE: "せ",
|
||||
0xBF: "そ",
|
||||
0xC0: "た",
|
||||
0xC1: "ち",
|
||||
0xC2: "つ",
|
||||
0xC3: "て",
|
||||
0xC4: "と",
|
||||
0xC5: "な",
|
||||
0xC6: "に",
|
||||
0xC7: "ぬ",
|
||||
0xC8: "ね",
|
||||
0xC9: "の",
|
||||
0xCA: "は",
|
||||
0xCB: "ひ",
|
||||
0xCC: "ふ",
|
||||
0xCD: "へ",
|
||||
0xCE: "ほ",
|
||||
0xCF: "ま",
|
||||
0xD0: "み",
|
||||
0xD1: "む",
|
||||
0xD2: "め",
|
||||
0xD3: "も",
|
||||
0xD4: "や",
|
||||
0xD5: "ゆ",
|
||||
0xD6: "よ",
|
||||
0xD7: "ら",
|
||||
0xD8: "り",
|
||||
0xD9: "る",
|
||||
0xDA: "れ",
|
||||
0xDB: "ろ",
|
||||
0xDC: "わ",
|
||||
0xDD: "を",
|
||||
0xDE: "ん",
|
||||
0xDF: "っ",
|
||||
0xE0: "ゃ",
|
||||
0xE1: "ゅ",
|
||||
0xE2: "ょ",
|
||||
0xE3: "ー",
|
||||
0xE9: "ァ",
|
||||
})
|
||||
|
||||
#some of the japanese characters can probably fit into the english table
|
||||
#without overriding any of the other mappings.
|
||||
for key, value in jap_chars.items():
|
||||
if key not in chars.keys():
|
||||
chars[key] = value
|
||||
|
@ -1,268 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Find shared functions between red/crystal.
|
||||
"""
|
||||
|
||||
from crystal import (
|
||||
get_label_from_line,
|
||||
get_address_from_line_comment,
|
||||
AsmSection,
|
||||
direct_load_rom,
|
||||
direct_load_asm,
|
||||
)
|
||||
|
||||
from romstr import (
|
||||
RomStr,
|
||||
AsmList,
|
||||
)
|
||||
|
||||
def load_rom(path):
|
||||
"""
|
||||
Load a ROM file into an abbreviated RomStr object.
|
||||
"""
|
||||
return direct_load_rom(filename=path)
|
||||
|
||||
def load_asm(path):
|
||||
"""
|
||||
Load source ASM into an abbreviated AsmList object.
|
||||
"""
|
||||
return direct_load_asm(filename=path)
|
||||
|
||||
def findall_iter(sub, string):
|
||||
# url: http://stackoverflow.com/a/3874760/687783
|
||||
|
||||
def next_index(length):
|
||||
index = 0 - length
|
||||
while True:
|
||||
index = string.find(sub, index + length)
|
||||
yield index
|
||||
|
||||
return iter(next_index(len(sub)).next, -1)
|
||||
|
||||
class Address(int):
|
||||
"""
|
||||
A simple int wrapper to take 0xFFFF and $FFFF addresses.
|
||||
"""
|
||||
|
||||
def __new__(cls, x=None, *args, **kwargs):
|
||||
if type(x) == str:
|
||||
if "$" in x:
|
||||
x = x.replace("$", "0x")
|
||||
|
||||
if "0x" in str:
|
||||
instance = int.__new__(cls, int(x, base=16), *args, **kwargs)
|
||||
else:
|
||||
msg = "Address.__new__ doesn't know how to parse this string"
|
||||
raise Exception, msg
|
||||
else:
|
||||
instance = int.__new__(cls, x, *args, **kwargs)
|
||||
|
||||
return instance
|
||||
|
||||
found_blobs = []
|
||||
|
||||
class BinaryBlob(object):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
start_address = None
|
||||
end_address = None
|
||||
label = None
|
||||
line_number = None
|
||||
bytes = None
|
||||
bank = None
|
||||
debug = False
|
||||
locations = None
|
||||
|
||||
def __init__(self, start_address=None, end_address=None, label=None, \
|
||||
debug=None, line_number=None):
|
||||
if not isinstance(start_address, Address):
|
||||
start_address = Address(start_address)
|
||||
if not isinstance(end_address, Address):
|
||||
end_address = Address(end_address)
|
||||
|
||||
assert label != None, "label can't be none"
|
||||
assert isinstance(label, str), "label must be a string"
|
||||
assert line_number != None, "line_number must be provided"
|
||||
|
||||
self.start_address = start_address
|
||||
self.end_address = end_address
|
||||
self.label = label
|
||||
self.line_number = line_number
|
||||
self.bytes = []
|
||||
self.locations = []
|
||||
self.bank = start_address / 0x4000
|
||||
|
||||
if debug != None:
|
||||
self.debug = debug
|
||||
|
||||
self.parse_from_red()
|
||||
# self.find_in_crystal()
|
||||
self.find_by_first_bytes()
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
A beautiful poem.
|
||||
"""
|
||||
|
||||
r = "BinaryBlob("
|
||||
r += "label=\""+self.label+"\", "
|
||||
r += "start_address="+hex(self.start_address)+", "
|
||||
r += "size="+str(self.end_address - self.start_address)+", "
|
||||
locnum = len(self.locations)
|
||||
if locnum == 1:
|
||||
r += "located="+hex(self.locations[0])
|
||||
elif locnum <= 5:
|
||||
r += "located="+str([hex(x) for x in self.locations])
|
||||
else:
|
||||
r += "located="+str(locnum)
|
||||
r += ")"
|
||||
|
||||
return r
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
def parse_from_red(self):
|
||||
"""
|
||||
Read bytes from Pokémon Red and stores them.
|
||||
"""
|
||||
|
||||
self.bytes = redrom[self.start_address : self.end_address + 1]
|
||||
|
||||
def pretty_bytes(self):
|
||||
"""
|
||||
Returns a better looking range of bytes.
|
||||
"""
|
||||
|
||||
bytes = redrom.interval(self.start_address, \
|
||||
self.end_address - self.start_address, \
|
||||
strings=False, debug=True)
|
||||
|
||||
return bytes
|
||||
|
||||
def find_in_crystal(self):
|
||||
"""
|
||||
Check whether or not the bytes appear in Pokémon Crystal.
|
||||
"""
|
||||
|
||||
finditer = findall_iter(self.bytes, cryrom)
|
||||
self.locations = [match for match in finditer]
|
||||
|
||||
if len(self.locations) > 0:
|
||||
found_blobs.append(self)
|
||||
|
||||
if self.debug:
|
||||
print self.label + ": found " + str(len(self.locations)) + " matches."
|
||||
|
||||
def find_by_first_bytes(self):
|
||||
"""
|
||||
Find this blob in Crystal based on the first n bytes.
|
||||
"""
|
||||
|
||||
# how many bytes to match
|
||||
first_n = 3
|
||||
|
||||
# no match
|
||||
if len(self.bytes) <= first_n:
|
||||
return
|
||||
|
||||
finditer = findall_iter(self.bytes[0:first_n], cryrom)
|
||||
self.locations = [match for match in finditer]
|
||||
|
||||
# filter out locations that suck
|
||||
self.locations = [i for i in self.locations if abs(self.start_address - i) <= 0x8000]
|
||||
|
||||
if len(self.locations) > 0:
|
||||
found_blobs.append(self)
|
||||
|
||||
if self.debug:
|
||||
print self.label + ": found " + str(len(self.locations)) + " matches."
|
||||
|
||||
pokecrystal_rom_path = "../baserom.gbc"
|
||||
pokecrystal_src_path = "../main.asm"
|
||||
pokered_rom_path = "../pokered-baserom.gbc"
|
||||
pokered_src_path = "../pokered-main.asm"
|
||||
|
||||
cryrom = load_rom(pokecrystal_rom_path)
|
||||
crysrc = load_asm(pokecrystal_src_path)
|
||||
redrom = load_rom(pokered_rom_path)
|
||||
redsrc = load_asm(pokered_src_path)
|
||||
|
||||
def scan_red_asm(bank_stop=3, debug=True):
|
||||
"""
|
||||
Scan the ASM from Pokémon Red. Finds labels and objects. Does things.
|
||||
|
||||
Uses get_label_from_line and get_address_from_line_comment.
|
||||
"""
|
||||
|
||||
# whether or not to show the lines from redsrc
|
||||
show_lines = False
|
||||
|
||||
line_number = 0
|
||||
current_bank = 0
|
||||
|
||||
current_label = None
|
||||
latest_label = "ignore me"
|
||||
current_start_address = None
|
||||
latest_start_address = 0
|
||||
latest_line = ""
|
||||
|
||||
for line in redsrc:
|
||||
if debug and show_lines:
|
||||
print "processing a line from red: " + line
|
||||
|
||||
if line[0:7] == "SECTION":
|
||||
thing = AsmSection(line)
|
||||
current_bank = thing.bank_id
|
||||
|
||||
if debug:
|
||||
print "scan_red_asm: switching to bank " + str(current_bank)
|
||||
|
||||
elif line[0:6] != "INCBIN":
|
||||
if ":" in line and not ";XXX:" in line and not " ; XXX:" in line:
|
||||
current_label = get_label_from_line(line)
|
||||
current_start_address = get_address_from_line_comment(line, \
|
||||
bank=current_bank)
|
||||
|
||||
if current_label != None and current_start_address != None and latest_start_address != None \
|
||||
and current_start_address != 0 and current_start_address != latest_start_address \
|
||||
and (current_start_address - latest_start_address) > 1:
|
||||
if latest_label != None:
|
||||
if latest_label not in ["Char52", "PokeCenterSignText", "DefaultNamesPlayer", "Unnamed_6a12"]:
|
||||
blob = BinaryBlob(label=latest_label, \
|
||||
start_address=latest_start_address, \
|
||||
end_address=current_start_address, \
|
||||
line_number=line_number)
|
||||
|
||||
if debug:
|
||||
print "Created a new blob: " + str(blob) + " from line: " + str(latest_line)
|
||||
|
||||
latest_label = current_label
|
||||
latest_start_address = current_start_address
|
||||
latest_line = line
|
||||
|
||||
line_number += 1
|
||||
|
||||
if current_bank == bank_stop:
|
||||
if debug:
|
||||
print "scan_red_asm: stopping because current_bank >= " + \
|
||||
str(bank_stop) + " (bank_stop)"
|
||||
|
||||
break
|
||||
|
||||
scan_red_asm(bank_stop=3)
|
||||
|
||||
print "================================"
|
||||
|
||||
for blob in found_blobs:
|
||||
print blob
|
||||
|
||||
print "Found " + str(len(found_blobs)) + " possibly copied functions."
|
||||
|
||||
print [hex(x) for x in found_blobs[10].locations]
|
||||
|
7630
extras/crystal.py
7630
extras/crystal.py
File diff suppressed because it is too large
Load Diff
@ -1,151 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
Dump out asm for scripting things in bank $25. This script will modify main.asm
|
||||
and insert all scripting commands.
|
||||
"""
|
||||
|
||||
import crystal
|
||||
from gbz80disasm import output_bank_opcodes
|
||||
|
||||
rom = crystal.load_rom()
|
||||
roml = [ord(x) for x in rom]
|
||||
|
||||
script_command_table_address = 0x96cb1
|
||||
script_command_count = 170
|
||||
|
||||
# a list of addresses for each script command
|
||||
command_pointers = [crystal.calculate_pointer_from_bytes_at(script_command_table_address + (id * 2), bank=0x25) for id in range(0, 170)]
|
||||
|
||||
# a list of hex addresses for each script command in bank $25
|
||||
command_pointers_hex = ["$%.2x" % (x % 0x4000 + 0x4000) for x in command_pointers]
|
||||
|
||||
commands = {}
|
||||
|
||||
# force data into a more usable form
|
||||
for command in crystal.command_classes:
|
||||
name = "Script_" + command.macro_name
|
||||
id = command.id
|
||||
params = {}
|
||||
|
||||
for (id2, param_type) in command.param_types.items():
|
||||
param = {
|
||||
"name": param_type["name"],
|
||||
"type": param_type["class"].__name__,
|
||||
}
|
||||
params[id2] = param
|
||||
|
||||
if id <= 0xa9:
|
||||
commands[id] = {
|
||||
"name": name,
|
||||
"params": params,
|
||||
"address": command_pointers[id],
|
||||
}
|
||||
|
||||
avoid = [
|
||||
0x974b0,
|
||||
0x974be,
|
||||
0x9754b,
|
||||
0x97556,
|
||||
0x97562,
|
||||
0x9756e,
|
||||
0x97540,
|
||||
|
||||
0x96f8e, # verbosegiveitem2
|
||||
]
|
||||
|
||||
class DisassembledScriptCommand():
|
||||
"""
|
||||
Just a temporary object to store information about a script command's asm.
|
||||
This is used by some of the infrastructure in crystal.py to automatically
|
||||
insert asm into main.asm, rather than having someone do it manually.
|
||||
"""
|
||||
dependencies = None
|
||||
|
||||
def __init__(self, label=None, id=None, address=None, params=None):
|
||||
self.id = id
|
||||
self.label = crystal.Label(name=label, address=address, object=self)
|
||||
self.address = address
|
||||
self.params = params
|
||||
|
||||
max_byte_count = 0x4000
|
||||
|
||||
# Some of these scripts need to be truncated before insertion, because
|
||||
# output_bank_opcodes doesn't know anything about stopping if some of
|
||||
# the local labels are not resolved yet.
|
||||
|
||||
# Script_if_equal
|
||||
if address == 0x97540:
|
||||
max_byte_count = 86
|
||||
|
||||
# disassemble and laso get the last address
|
||||
(asm, last_address, last_hl_address, last_a_address, used_3d97) = output_bank_opcodes(address, max_byte_count=max_byte_count, stop_at=command_pointers, include_last_address=False)
|
||||
|
||||
# remove indentation
|
||||
asm = asm.replace("\n\t", "\n")
|
||||
if asm[0] == "\t":
|
||||
asm = asm[1:]
|
||||
|
||||
# remove the last two newlines
|
||||
while asm[-1] == "\n":
|
||||
asm = asm[:-1]
|
||||
|
||||
self.asm = asm
|
||||
self.last_address = last_address
|
||||
|
||||
# make sure this gets dumped into main.asm
|
||||
#if crystal.script_parse_table[self.address] == None and crystal.script_parse_table[self.last_address] == None:
|
||||
crystal.script_parse_table[self.address : self.last_address] = self
|
||||
#else:
|
||||
# print ".. hm, something is already at " + hex(self.address) + " for " + self.label.name
|
||||
|
||||
def to_asm(self):
|
||||
#output += self.label + ": ; " + hex(self.address) + "\n"
|
||||
output = "; script command " + hex(self.id) + "\n"
|
||||
if len(self.params) > 0:
|
||||
output += "; parameters:\n"
|
||||
for (id2, param) in self.params.items():
|
||||
output += "; " + param["name"] + " (" + param["type"] + ")\n"
|
||||
output += "\n"
|
||||
output += self.asm
|
||||
return output
|
||||
|
||||
def get_dependencies(*args, **kwargs):
|
||||
return []
|
||||
|
||||
# make instances of DisassembledScriptCommand
|
||||
for (id, command) in commands.items():
|
||||
name = command["name"]
|
||||
params = command["params"]
|
||||
address = command["address"]
|
||||
|
||||
script_asm = DisassembledScriptCommand(label=name, id=id, address=address, params=params)
|
||||
#print script_asm.to_asm()
|
||||
#print crystal.to_asm(script_asm, use_asm_rules=True)
|
||||
|
||||
class ScriptCommandTable():
|
||||
address = script_command_table_address
|
||||
last_address = script_command_table_address + (2 * 170)
|
||||
dependencies = None
|
||||
|
||||
def __init__(self):
|
||||
self.label = crystal.Label(name="ScriptCommandTable", address=self.address, object=self)
|
||||
|
||||
# make sure this gets dumped into main.asm
|
||||
crystal.script_parse_table[self.address : self.last_address] = self
|
||||
|
||||
def get_dependencies(*args, **kwargs):
|
||||
return []
|
||||
|
||||
def to_asm(self):
|
||||
output = ""
|
||||
for (id, command) in commands.items():
|
||||
output += "dw " + command["name"] + "; " + hex(command["address"]) + "\n"
|
||||
if output[-1] == "\n":
|
||||
output = output[:-1]
|
||||
return output
|
||||
script_command_table = ScriptCommandTable()
|
||||
#print crystal.to_asm(script_command_table, use_asm_rules=True)
|
||||
|
||||
# automatic asm insertion
|
||||
asm = crystal.Asm()
|
||||
asm.insert_and_dump(limit=500)
|
@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
# This wraps dump_sections.py so that other python scripts can import the
|
||||
# functions. If dump_sections.py was instead called dump_sections, then other
|
||||
# python source code would be unable to use the functions via import
|
||||
# statements.
|
||||
|
||||
# figure out the path to this script
|
||||
cwd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# construct the path to dump_sections.py
|
||||
secpath=$cwd/dump_sections.py
|
||||
|
||||
# run dump_sections.py
|
||||
$secpath $1
|
@ -1,130 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Use this tool to dump an asm file for a new source code or disassembly project.
|
||||
|
||||
usage:
|
||||
|
||||
from dump_sections import dump_sections
|
||||
|
||||
output = dump_sections("../../butt.gbc")
|
||||
|
||||
file_handler = open("main.asm", "w")
|
||||
file_handler.write(output)
|
||||
file_handler.close()
|
||||
|
||||
You can also use this script from the shell, where it will look for
|
||||
"baserom.gbc" in the current working path or whatever file path you pass in the
|
||||
first positional argument.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
def upper_hex(input):
|
||||
"""
|
||||
Converts the input to an uppercase hex string.
|
||||
"""
|
||||
if input in [0, "0"]:
|
||||
return "0"
|
||||
elif input <= 0xF:
|
||||
return ("%.x" % (input)).upper()
|
||||
else:
|
||||
return ("%.2x" % (input)).upper()
|
||||
|
||||
def format_bank_number(address, bank_size=0x4000):
|
||||
"""
|
||||
Returns a str of the hex number of the bank based on the address.
|
||||
"""
|
||||
return upper_hex(address / bank_size)
|
||||
|
||||
def calculate_bank_quantity(path, bank_size=0x4000):
|
||||
"""
|
||||
Returns the number of 0x4000 banks in the file at path.
|
||||
"""
|
||||
return float(os.lstat(path).st_size) / bank_size
|
||||
|
||||
def dump_section(bank_number, separator="\n\n"):
|
||||
"""
|
||||
Returns a str of a section header for the asm file.
|
||||
"""
|
||||
output = "SECTION \""
|
||||
if bank_number in [0, "0"]:
|
||||
output += "bank0\",HOME"
|
||||
else:
|
||||
output += "bank"
|
||||
output += bank_number
|
||||
output += "\",DATA,BANK[$"
|
||||
output += bank_number
|
||||
output += "]"
|
||||
output += separator
|
||||
return output
|
||||
|
||||
def dump_incbin_for_section(address, bank_size=0x4000, baserom="baserom.gbc", separator="\n\n"):
|
||||
"""
|
||||
Returns a str for an INCBIN line for an entire section.
|
||||
"""
|
||||
output = "INCBIN \""
|
||||
output += baserom
|
||||
output += "\",$"
|
||||
output += upper_hex(address)
|
||||
output += ",$"
|
||||
output += upper_hex(bank_size)
|
||||
output += separator
|
||||
return output
|
||||
|
||||
def dump_sections(path, bank_size=0x4000, initial_bank=0, last_bank=None, separator="\n\n"):
|
||||
"""
|
||||
Returns a str of assembly source code. The source code delineates each
|
||||
SECTION and includes bytes from the file specified by baserom.
|
||||
"""
|
||||
if not last_bank:
|
||||
last_bank = calculate_bank_quantity(path, bank_size=bank_size)
|
||||
|
||||
if last_bank < initial_bank:
|
||||
raise Exception("last_bank must be greater than or equal to initial_bank")
|
||||
|
||||
baserom_name = os.path.basename(path)
|
||||
|
||||
output = ""
|
||||
|
||||
banks = range(initial_bank, last_bank)
|
||||
|
||||
for bank_number in banks:
|
||||
address = bank_number * bank_size
|
||||
|
||||
# get a formatted hex number of the bank based on the address
|
||||
formatted_bank_number = format_bank_number(address, bank_size=bank_size)
|
||||
|
||||
# SECTION
|
||||
output += dump_section(formatted_bank_number, separator=separator)
|
||||
|
||||
# INCBIN a range of bytes from the ROM
|
||||
output += dump_incbin_for_section(address, bank_size=bank_size, baserom=baserom_name, separator=separator)
|
||||
|
||||
# clean up newlines at the end of the output
|
||||
if output[-2:] == "\n\n":
|
||||
output = output[:-2]
|
||||
output += "\n"
|
||||
|
||||
return output
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("rompath", nargs="?", metavar="rompath", type=str)
|
||||
args = parser.parse_args()
|
||||
|
||||
# default to "baserom.gbc" in the current working directory
|
||||
baserom = "baserom.gbc"
|
||||
|
||||
# but let the user override the default
|
||||
if args.rompath:
|
||||
baserom = args.rompath
|
||||
|
||||
# generate some asm
|
||||
output = dump_sections(baserom)
|
||||
|
||||
# dump everything to stdout
|
||||
sys.stdout.write(output)
|
||||
|
@ -1,945 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
from copy import copy, deepcopy
|
||||
from ctypes import c_int8
|
||||
import random
|
||||
import json
|
||||
from wram import *
|
||||
|
||||
# New versions of json don't have read anymore.
|
||||
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
|
||||
|
||||
spacing = "\t"
|
||||
|
||||
temp_opt_table = [
|
||||
[ "ADC A", 0x8f, 0 ],
|
||||
[ "ADC B", 0x88, 0 ],
|
||||
[ "ADC C", 0x89, 0 ],
|
||||
[ "ADC D", 0x8a, 0 ],
|
||||
[ "ADC E", 0x8b, 0 ],
|
||||
[ "ADC H", 0x8c, 0 ],
|
||||
[ "ADC [HL]", 0x8e, 0 ],
|
||||
[ "ADC L", 0x8d, 0 ],
|
||||
[ "ADC x", 0xce, 1 ],
|
||||
[ "ADD A", 0x87, 0 ],
|
||||
[ "ADD B", 0x80, 0 ],
|
||||
[ "ADD C", 0x81, 0 ],
|
||||
[ "ADD D", 0x82, 0 ],
|
||||
[ "ADD E", 0x83, 0 ],
|
||||
[ "ADD H", 0x84, 0 ],
|
||||
[ "ADD [HL]", 0x86, 0 ],
|
||||
[ "ADD HL, BC", 0x9, 0 ],
|
||||
[ "ADD HL, DE", 0x19, 0 ],
|
||||
[ "ADD HL, HL", 0x29, 0 ],
|
||||
[ "ADD HL, SP", 0x39, 0 ],
|
||||
[ "ADD L", 0x85, 0 ],
|
||||
[ "ADD SP, x", 0xe8, 1 ],
|
||||
[ "ADD x", 0xc6, 1 ],
|
||||
[ "AND A", 0xa7, 0 ],
|
||||
[ "AND B", 0xa0, 0 ],
|
||||
[ "AND C", 0xa1, 0 ],
|
||||
[ "AND D", 0xa2, 0 ],
|
||||
[ "AND E", 0xa3, 0 ],
|
||||
[ "AND H", 0xa4, 0 ],
|
||||
[ "AND [HL]", 0xa6, 0 ],
|
||||
[ "AND L", 0xa5, 0 ],
|
||||
[ "AND x", 0xe6, 1 ],
|
||||
[ "BIT 0, A", 0x47cb, 3 ],
|
||||
[ "BIT 0, B", 0x40cb, 3 ],
|
||||
[ "BIT 0, C", 0x41cb, 3 ],
|
||||
[ "BIT 0, D", 0x42cb, 3 ],
|
||||
[ "BIT 0, E", 0x43cb, 3 ],
|
||||
[ "BIT 0, H", 0x44cb, 3 ],
|
||||
[ "BIT 0, [HL]", 0x46cb, 3 ],
|
||||
[ "BIT 0, L", 0x45cb, 3 ],
|
||||
[ "BIT 1, A", 0x4fcb, 3 ],
|
||||
[ "BIT 1, B", 0x48cb, 3 ],
|
||||
[ "BIT 1, C", 0x49cb, 3 ],
|
||||
[ "BIT 1, D", 0x4acb, 3 ],
|
||||
[ "BIT 1, E", 0x4bcb, 3 ],
|
||||
[ "BIT 1, H", 0x4ccb, 3 ],
|
||||
[ "BIT 1, [HL]", 0x4ecb, 3 ],
|
||||
[ "BIT 1, L", 0x4dcb, 3 ],
|
||||
[ "BIT 2, A", 0x57cb, 3 ],
|
||||
[ "BIT 2, B", 0x50cb, 3 ],
|
||||
[ "BIT 2, C", 0x51cb, 3 ],
|
||||
[ "BIT 2, D", 0x52cb, 3 ],
|
||||
[ "BIT 2, E", 0x53cb, 3 ],
|
||||
[ "BIT 2, H", 0x54cb, 3 ],
|
||||
[ "BIT 2, [HL]", 0x56cb, 3 ],
|
||||
[ "BIT 2, L", 0x55cb, 3 ],
|
||||
[ "BIT 3, A", 0x5fcb, 3 ],
|
||||
[ "BIT 3, B", 0x58cb, 3 ],
|
||||
[ "BIT 3, C", 0x59cb, 3 ],
|
||||
[ "BIT 3, D", 0x5acb, 3 ],
|
||||
[ "BIT 3, E", 0x5bcb, 3 ],
|
||||
[ "BIT 3, H", 0x5ccb, 3 ],
|
||||
[ "BIT 3, [HL]", 0x5ecb, 3 ],
|
||||
[ "BIT 3, L", 0x5dcb, 3 ],
|
||||
[ "BIT 4, A", 0x67cb, 3 ],
|
||||
[ "BIT 4, B", 0x60cb, 3 ],
|
||||
[ "BIT 4, C", 0x61cb, 3 ],
|
||||
[ "BIT 4, D", 0x62cb, 3 ],
|
||||
[ "BIT 4, E", 0x63cb, 3 ],
|
||||
[ "BIT 4, H", 0x64cb, 3 ],
|
||||
[ "BIT 4, [HL]", 0x66cb, 3 ],
|
||||
[ "BIT 4, L", 0x65cb, 3 ],
|
||||
[ "BIT 5, A", 0x6fcb, 3 ],
|
||||
[ "BIT 5, B", 0x68cb, 3 ],
|
||||
[ "BIT 5, C", 0x69cb, 3 ],
|
||||
[ "BIT 5, D", 0x6acb, 3 ],
|
||||
[ "BIT 5, E", 0x6bcb, 3 ],
|
||||
[ "BIT 5, H", 0x6ccb, 3 ],
|
||||
[ "BIT 5, [HL]", 0x6ecb, 3 ],
|
||||
[ "BIT 5, L", 0x6dcb, 3 ],
|
||||
[ "BIT 6, A", 0x77cb, 3 ],
|
||||
[ "BIT 6, B", 0x70cb, 3 ],
|
||||
[ "BIT 6, C", 0x71cb, 3 ],
|
||||
[ "BIT 6, D", 0x72cb, 3 ],
|
||||
[ "BIT 6, E", 0x73cb, 3 ],
|
||||
[ "BIT 6, H", 0x74cb, 3 ],
|
||||
[ "BIT 6, [HL]", 0x76cb, 3 ],
|
||||
[ "BIT 6, L", 0x75cb, 3 ],
|
||||
[ "BIT 7, A", 0x7fcb, 3 ],
|
||||
[ "BIT 7, B", 0x78cb, 3 ],
|
||||
[ "BIT 7, C", 0x79cb, 3 ],
|
||||
[ "BIT 7, D", 0x7acb, 3 ],
|
||||
[ "BIT 7, E", 0x7bcb, 3 ],
|
||||
[ "BIT 7, H", 0x7ccb, 3 ],
|
||||
[ "BIT 7, [HL]", 0x7ecb, 3 ],
|
||||
[ "BIT 7, L", 0x7dcb, 3 ],
|
||||
[ "CALL C, ?", 0xdc, 2 ],
|
||||
[ "CALL NC, ?", 0xd4, 2 ],
|
||||
[ "CALL NZ, ?", 0xc4, 2 ],
|
||||
[ "CALL Z, ?", 0xcc, 2 ],
|
||||
[ "CALL ?", 0xcd, 2 ],
|
||||
[ "CCF", 0x3f, 0 ],
|
||||
[ "CP A", 0xbf, 0 ],
|
||||
[ "CP B", 0xb8, 0 ],
|
||||
[ "CP C", 0xb9, 0 ],
|
||||
[ "CP D", 0xba, 0 ],
|
||||
[ "CP E", 0xbb, 0 ],
|
||||
[ "CP H", 0xbc, 0 ],
|
||||
[ "CP [HL]", 0xbe, 0 ],
|
||||
[ "CPL", 0x2f, 0 ],
|
||||
[ "CP L", 0xbd, 0 ],
|
||||
[ "CP x", 0xfe, 1 ],
|
||||
[ "DAA", 0x27, 0 ],
|
||||
[ "DEBUG", 0xed, 0 ],
|
||||
[ "DEC A", 0x3d, 0 ],
|
||||
[ "DEC B", 0x5, 0 ],
|
||||
[ "DEC BC", 0xb, 0 ],
|
||||
[ "DEC C", 0xd, 0 ],
|
||||
[ "DEC D", 0x15, 0 ],
|
||||
[ "DEC DE", 0x1b, 0 ],
|
||||
[ "DEC E", 0x1d, 0 ],
|
||||
[ "DEC H", 0x25, 0 ],
|
||||
[ "DEC HL", 0x2b, 0 ],
|
||||
[ "DEC [HL]", 0x35, 0 ],
|
||||
[ "DEC L", 0x2d, 0 ],
|
||||
[ "DEC SP", 0x3b, 0 ],
|
||||
[ "DI", 0xf3, 0 ],
|
||||
[ "EI", 0xfb, 0 ],
|
||||
[ "HALT", 0x76, 0 ],
|
||||
[ "INC A", 0x3c, 0 ],
|
||||
[ "INC B", 0x4, 0 ],
|
||||
[ "INC BC", 0x3, 0 ],
|
||||
[ "INC C", 0xc, 0 ],
|
||||
[ "INC D", 0x14, 0 ],
|
||||
[ "INC DE", 0x13, 0 ],
|
||||
[ "INC E", 0x1c, 0 ],
|
||||
[ "INC H", 0x24, 0 ],
|
||||
[ "INC HL", 0x23, 0 ],
|
||||
[ "INC [HL]", 0x34, 0 ],
|
||||
[ "INC L", 0x2c, 0 ],
|
||||
[ "INC SP", 0x33, 0 ],
|
||||
[ "JP C, ?", 0xda, 2 ],
|
||||
[ "JP [HL]", 0xe9, 0 ],
|
||||
[ "JP NC, ?", 0xd2, 2 ],
|
||||
[ "JP NZ, ?", 0xc2, 2 ],
|
||||
[ "JP Z, ?", 0xca, 2 ],
|
||||
[ "JP ?", 0xc3, 2 ],
|
||||
[ "JR C, x", 0x38, 1 ],
|
||||
[ "JR NC, x", 0x30, 1 ],
|
||||
[ "JR NZ, x", 0x20, 1 ],
|
||||
[ "JR Z, x", 0x28, 1 ],
|
||||
[ "JR x", 0x18, 1 ],
|
||||
[ "LD A, A", 0x7f, 0 ],
|
||||
[ "LD A, B", 0x78, 0 ],
|
||||
[ "LD A, C", 0x79, 0 ],
|
||||
[ "LD A, D", 0x7a, 0 ],
|
||||
[ "LD A, E", 0x7b, 0 ],
|
||||
[ "LD A, H", 0x7c, 0 ],
|
||||
[ "LD A, L", 0x7d, 0 ],
|
||||
[ "LD A, [$FF00+C]", 0xf2, 0 ],
|
||||
[ "LD A, [$FF00+x]", 0xf0, 1 ],
|
||||
# [ "LDH A, [x]", 0xf0, 1 ], # rgbds has trouble with this one?
|
||||
[ "LD A, [BC]", 0xa, 0 ],
|
||||
[ "LD A, [DE]", 0x1a, 0 ],
|
||||
# [ "LD A, [HL+]", 0x2a, 0 ],
|
||||
# [ "LD A, [HL-]", 0x3a, 0 ],
|
||||
[ "LD A, [HL]", 0x7e, 0 ],
|
||||
[ "LD A, [HLD]", 0x3a, 0 ],
|
||||
[ "LD A, [HLI]", 0x2a, 0 ],
|
||||
[ "LD A, [?]", 0xfa, 2 ],
|
||||
[ "LD A, x", 0x3e, 1 ],
|
||||
[ "LD B, A", 0x47, 0 ],
|
||||
[ "LD B, B", 0x40, 0 ],
|
||||
[ "LD B, C", 0x41, 0 ],
|
||||
[ "LD [BC], A", 0x2, 0 ],
|
||||
[ "LD B, D", 0x42, 0 ],
|
||||
[ "LD B, E", 0x43, 0 ],
|
||||
[ "LD B, H", 0x44, 0 ],
|
||||
[ "LD B, [HL]", 0x46, 0 ],
|
||||
[ "LD B, L", 0x45, 0 ],
|
||||
[ "LD B, x", 0x6, 1 ],
|
||||
[ "LD C, A", 0x4f, 0 ],
|
||||
[ "LD C, B", 0x48, 0 ],
|
||||
[ "LD C, C", 0x49, 0 ],
|
||||
[ "LD C, D", 0x4a, 0 ],
|
||||
[ "LD C, E", 0x4b, 0 ],
|
||||
[ "LD C, H", 0x4c, 0 ],
|
||||
[ "LD C, [HL]", 0x4e, 0 ],
|
||||
[ "LD C, L", 0x4d, 0 ],
|
||||
[ "LD C, x", 0xe, 1 ],
|
||||
[ "LD D, A", 0x57, 0 ],
|
||||
# [ "LDD A, [HL]", 0x3a, 0 ],
|
||||
[ "LD D, B", 0x50, 0 ],
|
||||
[ "LD D, C", 0x51, 0 ],
|
||||
[ "LD D, D", 0x52, 0 ],
|
||||
[ "LD D, E", 0x53, 0 ],
|
||||
[ "LD [DE], A", 0x12, 0 ],
|
||||
[ "LD D, H", 0x54, 0 ],
|
||||
[ "LD D, [HL]", 0x56, 0 ],
|
||||
# [ "LDD [HL], A", 0x32, 0 ],
|
||||
[ "LD D, L", 0x55, 0 ],
|
||||
[ "LD D, x", 0x16, 1 ],
|
||||
[ "LD E, A", 0x5f, 0 ],
|
||||
[ "LD E, B", 0x58, 0 ],
|
||||
[ "LD E, C", 0x59, 0 ],
|
||||
[ "LD E, D", 0x5a, 0 ],
|
||||
[ "LD E, E", 0x5b, 0 ],
|
||||
[ "LD E, H", 0x5c, 0 ],
|
||||
[ "LD E, [HL]", 0x5e, 0 ],
|
||||
[ "LD E, L", 0x5d, 0 ],
|
||||
[ "LD E, x", 0x1e, 1 ],
|
||||
[ "LD [$FF00+C], A", 0xe2, 0 ],
|
||||
[ "LD [$FF00+x], A", 0xe0, 1 ],
|
||||
# [ "LDH [x], A", 0xe0, 1 ],
|
||||
[ "LD H, A", 0x67, 0 ],
|
||||
[ "LD H, B", 0x60, 0 ],
|
||||
[ "LD H, C", 0x61, 0 ],
|
||||
[ "LD H, D", 0x62, 0 ],
|
||||
[ "LD H, E", 0x63, 0 ],
|
||||
[ "LD H, H", 0x64, 0 ],
|
||||
[ "LD H, [HL]", 0x66, 0 ],
|
||||
[ "LD H, L", 0x65, 0 ],
|
||||
# [ "LD [HL+], A", 0x22, 0 ],
|
||||
# [ "LD [HL-], A", 0x32, 0 ],
|
||||
[ "LD [HL], A", 0x77, 0 ],
|
||||
[ "LD [HL], B", 0x70, 0 ],
|
||||
[ "LD [HL], C", 0x71, 0 ],
|
||||
[ "LD [HL], D", 0x72, 0 ],
|
||||
[ "LD [HLD], A", 0x32, 0 ],
|
||||
[ "LD [HL], E", 0x73, 0 ],
|
||||
[ "LD [HL], H", 0x74, 0 ],
|
||||
[ "LD [HLI], A", 0x22, 0 ],
|
||||
[ "LD [HL], L", 0x75, 0 ],
|
||||
# [ "LD HL, SP+x", 0xf8, 1 ], # rgbds uses [sp+x]
|
||||
[ "LD HL, [SP+x]", 0xf8, 1 ],
|
||||
[ "LD [HL], x", 0x36, 1 ],
|
||||
[ "LD H, x", 0x26, 1 ],
|
||||
# [ "LDI A, [HL]", 0x2a, 0 ],
|
||||
# [ "LDI [HL], A", 0x22, 0 ],
|
||||
[ "LD L, A", 0x6f, 0 ],
|
||||
[ "LD L, B", 0x68, 0 ],
|
||||
[ "LD L, C", 0x69, 0 ],
|
||||
[ "LD L, D", 0x6a, 0 ],
|
||||
[ "LD L, E", 0x6b, 0 ],
|
||||
[ "LD L, H", 0x6c, 0 ],
|
||||
[ "LD L, [HL]", 0x6e, 0 ],
|
||||
[ "LD L, L", 0x6d, 0 ],
|
||||
[ "LD L, x", 0x2e, 1 ],
|
||||
# [ "LD PC, HL", 0xe9, 0 ], #prefer jp [hl]
|
||||
[ "LD SP, HL", 0xf9, 0 ],
|
||||
[ "LD BC, ?", 0x1, 2 ],
|
||||
[ "LD DE, ?", 0x11, 2 ],
|
||||
[ "LD HL, ?", 0x21, 2 ],
|
||||
[ "LD SP, ?", 0x31, 2 ],
|
||||
[ "LD [?], SP", 0x8, 2 ],
|
||||
[ "LD [?], A", 0xea, 2 ],
|
||||
[ "NOP", 0x0, 0 ],
|
||||
[ "OR A", 0xb7, 0 ],
|
||||
[ "OR B", 0xb0, 0 ],
|
||||
[ "OR C", 0xb1, 0 ],
|
||||
[ "OR D", 0xb2, 0 ],
|
||||
[ "OR E", 0xb3, 0 ],
|
||||
[ "OR H", 0xb4, 0 ],
|
||||
[ "OR [HL]", 0xb6, 0 ],
|
||||
[ "OR L", 0xb5, 0 ],
|
||||
[ "OR x", 0xf6, 1 ],
|
||||
[ "POP AF", 0xf1, 0 ],
|
||||
[ "POP BC", 0xc1, 0 ],
|
||||
[ "POP DE", 0xd1, 0 ],
|
||||
[ "POP HL", 0xe1, 0 ],
|
||||
[ "PUSH AF", 0xf5, 0 ],
|
||||
[ "PUSH BC", 0xc5, 0 ],
|
||||
[ "PUSH DE", 0xd5, 0 ],
|
||||
[ "PUSH HL", 0xe5, 0 ],
|
||||
[ "RES 0, A", 0x87cb, 3 ],
|
||||
[ "RES 0, B", 0x80cb, 3 ],
|
||||
[ "RES 0, C", 0x81cb, 3 ],
|
||||
[ "RES 0, D", 0x82cb, 3 ],
|
||||
[ "RES 0, E", 0x83cb, 3 ],
|
||||
[ "RES 0, H", 0x84cb, 3 ],
|
||||
[ "RES 0, [HL]", 0x86cb, 3 ],
|
||||
[ "RES 0, L", 0x85cb, 3 ],
|
||||
[ "RES 1, A", 0x8fcb, 3 ],
|
||||
[ "RES 1, B", 0x88cb, 3 ],
|
||||
[ "RES 1, C", 0x89cb, 3 ],
|
||||
[ "RES 1, D", 0x8acb, 3 ],
|
||||
[ "RES 1, E", 0x8bcb, 3 ],
|
||||
[ "RES 1, H", 0x8ccb, 3 ],
|
||||
[ "RES 1, [HL]", 0x8ecb, 3 ],
|
||||
[ "RES 1, L", 0x8dcb, 3 ],
|
||||
[ "RES 2, A", 0x97cb, 3 ],
|
||||
[ "RES 2, B", 0x90cb, 3 ],
|
||||
[ "RES 2, C", 0x91cb, 3 ],
|
||||
[ "RES 2, D", 0x92cb, 3 ],
|
||||
[ "RES 2, E", 0x93cb, 3 ],
|
||||
[ "RES 2, H", 0x94cb, 3 ],
|
||||
[ "RES 2, [HL]", 0x96cb, 3 ],
|
||||
[ "RES 2, L", 0x95cb, 3 ],
|
||||
[ "RES 3, A", 0x9fcb, 3 ],
|
||||
[ "RES 3, B", 0x98cb, 3 ],
|
||||
[ "RES 3, C", 0x99cb, 3 ],
|
||||
[ "RES 3, D", 0x9acb, 3 ],
|
||||
[ "RES 3, E", 0x9bcb, 3 ],
|
||||
[ "RES 3, H", 0x9ccb, 3 ],
|
||||
[ "RES 3, [HL]", 0x9ecb, 3 ],
|
||||
[ "RES 3, L", 0x9dcb, 3 ],
|
||||
[ "RES 4, A", 0xa7cb, 3 ],
|
||||
[ "RES 4, B", 0xa0cb, 3 ],
|
||||
[ "RES 4, C", 0xa1cb, 3 ],
|
||||
[ "RES 4, D", 0xa2cb, 3 ],
|
||||
[ "RES 4, E", 0xa3cb, 3 ],
|
||||
[ "RES 4, H", 0xa4cb, 3 ],
|
||||
[ "RES 4, [HL]", 0xa6cb, 3 ],
|
||||
[ "RES 4, L", 0xa5cb, 3 ],
|
||||
[ "RES 5, A", 0xafcb, 3 ],
|
||||
[ "RES 5, B", 0xa8cb, 3 ],
|
||||
[ "RES 5, C", 0xa9cb, 3 ],
|
||||
[ "RES 5, D", 0xaacb, 3 ],
|
||||
[ "RES 5, E", 0xabcb, 3 ],
|
||||
[ "RES 5, H", 0xaccb, 3 ],
|
||||
[ "RES 5, [HL]", 0xaecb, 3 ],
|
||||
[ "RES 5, L", 0xadcb, 3 ],
|
||||
[ "RES 6, A", 0xb7cb, 3 ],
|
||||
[ "RES 6, B", 0xb0cb, 3 ],
|
||||
[ "RES 6, C", 0xb1cb, 3 ],
|
||||
[ "RES 6, D", 0xb2cb, 3 ],
|
||||
[ "RES 6, E", 0xb3cb, 3 ],
|
||||
[ "RES 6, H", 0xb4cb, 3 ],
|
||||
[ "RES 6, [HL]", 0xb6cb, 3 ],
|
||||
[ "RES 6, L", 0xb5cb, 3 ],
|
||||
[ "RES 7, A", 0xbfcb, 3 ],
|
||||
[ "RES 7, B", 0xb8cb, 3 ],
|
||||
[ "RES 7, C", 0xb9cb, 3 ],
|
||||
[ "RES 7, D", 0xbacb, 3 ],
|
||||
[ "RES 7, E", 0xbbcb, 3 ],
|
||||
[ "RES 7, H", 0xbccb, 3 ],
|
||||
[ "RES 7, [HL]", 0xbecb, 3 ],
|
||||
[ "RES 7, L", 0xbdcb, 3 ],
|
||||
[ "RETI", 0xd9, 0 ],
|
||||
[ "RET C", 0xd8, 0 ],
|
||||
[ "RET NC", 0xd0, 0 ],
|
||||
[ "RET NZ", 0xc0, 0 ],
|
||||
[ "RET Z", 0xc8, 0 ],
|
||||
[ "RET", 0xc9, 0 ],
|
||||
[ "RLA", 0x17, 0 ],
|
||||
[ "RL A", 0x17cb, 3 ],
|
||||
[ "RL B", 0x10cb, 3 ],
|
||||
[ "RL C", 0x11cb, 3 ],
|
||||
[ "RLCA", 0x7, 0 ],
|
||||
[ "RLC A", 0x7cb, 3 ],
|
||||
[ "RLC B", 0xcb, 3 ],
|
||||
[ "RLC C", 0x1cb, 3 ],
|
||||
[ "RLC D", 0x2cb, 3 ],
|
||||
[ "RLC E", 0x3cb, 3 ],
|
||||
[ "RLC H", 0x4cb, 3 ],
|
||||
[ "RLC [HL]", 0x6cb, 3 ],
|
||||
[ "RLC L", 0x5cb, 3 ],
|
||||
[ "RL D", 0x12cb, 3 ],
|
||||
[ "RL E", 0x13cb, 3 ],
|
||||
[ "RL H", 0x14cb, 3 ],
|
||||
[ "RL [HL]", 0x16cb, 3 ],
|
||||
[ "RL L", 0x15cb, 3 ],
|
||||
[ "RRA", 0x1f, 0 ],
|
||||
[ "RR A", 0x1fcb, 3 ],
|
||||
[ "RR B", 0x18cb, 3 ],
|
||||
[ "RR C", 0x19cb, 3 ],
|
||||
[ "RRCA", 0xf, 0 ],
|
||||
[ "RRC A", 0xfcb, 3 ],
|
||||
[ "RRC B", 0x8cb, 3 ],
|
||||
[ "RRC C", 0x9cb, 3 ],
|
||||
[ "RRC D", 0xacb, 3 ],
|
||||
[ "RRC E", 0xbcb, 3 ],
|
||||
[ "RRC H", 0xccb, 3 ],
|
||||
[ "RRC [HL]", 0xecb, 3 ],
|
||||
[ "RRC L", 0xdcb, 3 ],
|
||||
[ "RR D", 0x1acb, 3 ],
|
||||
[ "RR E", 0x1bcb, 3 ],
|
||||
[ "RR H", 0x1ccb, 3 ],
|
||||
[ "RR [HL]", 0x1ecb, 3 ],
|
||||
[ "RR L", 0x1dcb, 3 ],
|
||||
[ "RST $0", 0xc7, 0 ],
|
||||
[ "RST $10", 0xd7, 0 ],
|
||||
[ "RST $18", 0xdf, 0 ],
|
||||
[ "RST $20", 0xe7, 0 ],
|
||||
[ "RST $28", 0xef, 0 ],
|
||||
[ "RST $30", 0xf7, 0 ],
|
||||
[ "RST $38", 0xff, 0 ],
|
||||
[ "RST $8", 0xcf, 0 ],
|
||||
[ "SBC A", 0x9f, 0 ],
|
||||
[ "SBC B", 0x98, 0 ],
|
||||
[ "SBC C", 0x99, 0 ],
|
||||
[ "SBC D", 0x9a, 0 ],
|
||||
[ "SBC E", 0x9b, 0 ],
|
||||
[ "SBC H", 0x9c, 0 ],
|
||||
[ "SBC [HL]", 0x9e, 0 ],
|
||||
[ "SBC L", 0x9d, 0 ],
|
||||
[ "SBC x", 0xde, 1 ],
|
||||
[ "SCF", 0x37, 0 ],
|
||||
[ "SET 0, A", 0xc7cb, 3 ],
|
||||
[ "SET 0, B", 0xc0cb, 3 ],
|
||||
[ "SET 0, C", 0xc1cb, 3 ],
|
||||
[ "SET 0, D", 0xc2cb, 3 ],
|
||||
[ "SET 0, E", 0xc3cb, 3 ],
|
||||
[ "SET 0, H", 0xc4cb, 3 ],
|
||||
[ "SET 0, [HL]", 0xc6cb, 3 ],
|
||||
[ "SET 0, L", 0xc5cb, 3 ],
|
||||
[ "SET 1, A", 0xcfcb, 3 ],
|
||||
[ "SET 1, B", 0xc8cb, 3 ],
|
||||
[ "SET 1, C", 0xc9cb, 3 ],
|
||||
[ "SET 1, D", 0xcacb, 3 ],
|
||||
[ "SET 1, E", 0xcbcb, 3 ],
|
||||
[ "SET 1, H", 0xcccb, 3 ],
|
||||
[ "SET 1, [HL]", 0xcecb, 3 ],
|
||||
[ "SET 1, L", 0xcdcb, 3 ],
|
||||
[ "SET 2, A", 0xd7cb, 3 ],
|
||||
[ "SET 2, B", 0xd0cb, 3 ],
|
||||
[ "SET 2, C", 0xd1cb, 3 ],
|
||||
[ "SET 2, D", 0xd2cb, 3 ],
|
||||
[ "SET 2, E", 0xd3cb, 3 ],
|
||||
[ "SET 2, H", 0xd4cb, 3 ],
|
||||
[ "SET 2, [HL]", 0xd6cb, 3 ],
|
||||
[ "SET 2, L", 0xd5cb, 3 ],
|
||||
[ "SET 3, A", 0xdfcb, 3 ],
|
||||
[ "SET 3, B", 0xd8cb, 3 ],
|
||||
[ "SET 3, C", 0xd9cb, 3 ],
|
||||
[ "SET 3, D", 0xdacb, 3 ],
|
||||
[ "SET 3, E", 0xdbcb, 3 ],
|
||||
[ "SET 3, H", 0xdccb, 3 ],
|
||||
[ "SET 3, [HL]", 0xdecb, 3 ],
|
||||
[ "SET 3, L", 0xddcb, 3 ],
|
||||
[ "SET 4, A", 0xe7cb, 3 ],
|
||||
[ "SET 4, B", 0xe0cb, 3 ],
|
||||
[ "SET 4, C", 0xe1cb, 3 ],
|
||||
[ "SET 4, D", 0xe2cb, 3 ],
|
||||
[ "SET 4, E", 0xe3cb, 3 ],
|
||||
[ "SET 4, H", 0xe4cb, 3 ],
|
||||
[ "SET 4, [HL]", 0xe6cb, 3 ],
|
||||
[ "SET 4, L", 0xe5cb, 3 ],
|
||||
[ "SET 5, A", 0xefcb, 3 ],
|
||||
[ "SET 5, B", 0xe8cb, 3 ],
|
||||
[ "SET 5, C", 0xe9cb, 3 ],
|
||||
[ "SET 5, D", 0xeacb, 3 ],
|
||||
[ "SET 5, E", 0xebcb, 3 ],
|
||||
[ "SET 5, H", 0xeccb, 3 ],
|
||||
[ "SET 5, [HL]", 0xeecb, 3 ],
|
||||
[ "SET 5, L", 0xedcb, 3 ],
|
||||
[ "SET 6, A", 0xf7cb, 3 ],
|
||||
[ "SET 6, B", 0xf0cb, 3 ],
|
||||
[ "SET 6, C", 0xf1cb, 3 ],
|
||||
[ "SET 6, D", 0xf2cb, 3 ],
|
||||
[ "SET 6, E", 0xf3cb, 3 ],
|
||||
[ "SET 6, H", 0xf4cb, 3 ],
|
||||
[ "SET 6, [HL]", 0xf6cb, 3 ],
|
||||
[ "SET 6, L", 0xf5cb, 3 ],
|
||||
[ "SET 7, A", 0xffcb, 3 ],
|
||||
[ "SET 7, B", 0xf8cb, 3 ],
|
||||
[ "SET 7, C", 0xf9cb, 3 ],
|
||||
[ "SET 7, D", 0xfacb, 3 ],
|
||||
[ "SET 7, E", 0xfbcb, 3 ],
|
||||
[ "SET 7, H", 0xfccb, 3 ],
|
||||
[ "SET 7, [HL]", 0xfecb, 3 ],
|
||||
[ "SET 7, L", 0xfdcb, 3 ],
|
||||
[ "SLA A", 0x27cb, 3 ],
|
||||
[ "SLA B", 0x20cb, 3 ],
|
||||
[ "SLA C", 0x21cb, 3 ],
|
||||
[ "SLA D", 0x22cb, 3 ],
|
||||
[ "SLA E", 0x23cb, 3 ],
|
||||
[ "SLA H", 0x24cb, 3 ],
|
||||
[ "SLA [HL]", 0x26cb, 3 ],
|
||||
[ "SLA L", 0x25cb, 3 ],
|
||||
[ "SRA A", 0x2fcb, 3 ],
|
||||
[ "SRA B", 0x28cb, 3 ],
|
||||
[ "SRA C", 0x29cb, 3 ],
|
||||
[ "SRA D", 0x2acb, 3 ],
|
||||
[ "SRA E", 0x2bcb, 3 ],
|
||||
[ "SRA H", 0x2ccb, 3 ],
|
||||
[ "SRA [HL]", 0x2ecb, 3 ],
|
||||
[ "SRA L", 0x2dcb, 3 ],
|
||||
[ "SRL A", 0x3fcb, 3 ],
|
||||
[ "SRL B", 0x38cb, 3 ],
|
||||
[ "SRL C", 0x39cb, 3 ],
|
||||
[ "SRL D", 0x3acb, 3 ],
|
||||
[ "SRL E", 0x3bcb, 3 ],
|
||||
[ "SRL H", 0x3ccb, 3 ],
|
||||
[ "SRL [HL]", 0x3ecb, 3 ],
|
||||
[ "SRL L", 0x3dcb, 3 ],
|
||||
[ "STOP", 0x10, 0 ],
|
||||
[ "SUB A", 0x97, 0 ],
|
||||
[ "SUB B", 0x90, 0 ],
|
||||
[ "SUB C", 0x91, 0 ],
|
||||
[ "SUB D", 0x92, 0 ],
|
||||
[ "SUB E", 0x93, 0 ],
|
||||
[ "SUB H", 0x94, 0 ],
|
||||
[ "SUB [HL]", 0x96, 0 ],
|
||||
[ "SUB L", 0x95, 0 ],
|
||||
[ "SUB x", 0xd6, 1 ],
|
||||
[ "SWAP A", 0x37cb, 3 ],
|
||||
[ "SWAP B", 0x30cb, 3 ],
|
||||
[ "SWAP C", 0x31cb, 3 ],
|
||||
[ "SWAP D", 0x32cb, 3 ],
|
||||
[ "SWAP E", 0x33cb, 3 ],
|
||||
[ "SWAP H", 0x34cb, 3 ],
|
||||
[ "SWAP [HL]", 0x36cb, 3 ],
|
||||
[ "SWAP L", 0x35cb, 3 ],
|
||||
[ "XOR A", 0xaf, 0 ],
|
||||
[ "XOR B", 0xa8, 0 ],
|
||||
[ "XOR C", 0xa9, 0 ],
|
||||
[ "XOR D", 0xaa, 0 ],
|
||||
[ "XOR E", 0xab, 0 ],
|
||||
[ "XOR H", 0xac, 0 ],
|
||||
[ "XOR [HL]", 0xae, 0 ],
|
||||
[ "XOR L", 0xad, 0 ],
|
||||
[ "XOR x", 0xee, 1 ],
|
||||
[ "E", 0x100, -1 ],
|
||||
]
|
||||
|
||||
# construct a more useful version of opt_table
|
||||
opt_table = {}
|
||||
for line in temp_opt_table:
|
||||
opt_table[line[1]] = [line[0], line[2]]
|
||||
del line
|
||||
|
||||
end_08_scripts_with = [
|
||||
0xc9, #ret
|
||||
0xd9, #reti
|
||||
0xe9, #jp hl
|
||||
#0xc3, #jp
|
||||
##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]
|
||||
|
||||
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
|
||||
if all_labels != {}:
|
||||
return
|
||||
|
||||
if os.path.exists(filename):
|
||||
all_labels = json.read(open(filename, "r").read())
|
||||
else:
|
||||
print "You must run crystal.scan_for_predefined_labels() to create \"labels.json\". Trying..."
|
||||
import crystal
|
||||
crystal.scan_for_predefined_labels()
|
||||
|
||||
def find_label(local_address, bank_id=0):
|
||||
# keep an integer
|
||||
if type(local_address) == str:
|
||||
local_address = int(local_address.replace("$", "0x"), 16)
|
||||
|
||||
if local_address < 0x8000:
|
||||
for label_entry in all_labels:
|
||||
if get_local_address(label_entry["address"]) == local_address:
|
||||
if label_entry["bank"] == bank_id or label_entry["bank"] == 0:
|
||||
return label_entry["label"]
|
||||
if local_address in wram_labels.keys():
|
||||
return wram_labels[local_address][-1]
|
||||
for constants in [gbhw_constants, hram_constants]:
|
||||
if local_address in constants.keys() and local_address >= 0xff00:
|
||||
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):
|
||||
if address < 0x8000:
|
||||
return (address & 0x3fff) + 0x4000 * bank
|
||||
return None
|
||||
|
||||
return ".ASM_" + hex(address)[2:]
|
||||
|
||||
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()
|
||||
|
||||
bank_id = original_offset / 0x4000
|
||||
if debug: print "bank id is: " + str(bank_id)
|
||||
|
||||
last_hl_address = None #for when we're scanning the main map script
|
||||
last_a_address = None
|
||||
used_3d97 = False
|
||||
|
||||
global rom
|
||||
offset = original_offset
|
||||
current_byte_number = 0 #start from the beginning
|
||||
|
||||
#we don't actually have an end address, but we'll just say $4000
|
||||
end_address = original_offset + max_byte_count
|
||||
|
||||
byte_labels = {}
|
||||
data_tables = {}
|
||||
|
||||
first_loop = True
|
||||
output = ""
|
||||
keep_reading = True
|
||||
is_data = False
|
||||
while offset <= end_address and keep_reading:
|
||||
current_byte = rom[offset]
|
||||
maybe_byte = current_byte
|
||||
|
||||
# stop at any address
|
||||
if not first_loop and offset in stop_at:
|
||||
keep_reading = False
|
||||
break
|
||||
|
||||
#first check if this byte already has a label
|
||||
#if it does, use the label
|
||||
#if not, generate a new label
|
||||
if offset in byte_labels.keys():
|
||||
line_label = byte_labels[offset]["name"]
|
||||
byte_labels[offset]["usage"] += 1
|
||||
output += "\n"
|
||||
else:
|
||||
line_label = asm_label(offset)
|
||||
byte_labels[offset] = {}
|
||||
byte_labels[offset]["name"] = line_label
|
||||
byte_labels[offset]["usage"] = 0
|
||||
byte_labels[offset]["definition"] = True
|
||||
output += line_label + "\n" #" ; " + hex(offset) + "\n"
|
||||
|
||||
#find out if there's a two byte key like this
|
||||
temp_maybe = maybe_byte
|
||||
temp_maybe += ( rom[offset+1] << 8)
|
||||
if not is_data and temp_maybe in opt_table.keys() and rom[offset+1]!=0:
|
||||
opstr = opt_table[temp_maybe][0].lower()
|
||||
|
||||
if "x" in opstr:
|
||||
for x in range(0, opstr.count("x")):
|
||||
insertion = rom[offset + 1]
|
||||
insertion = "$" + hex(insertion)[2:]
|
||||
|
||||
opstr = opstr[:opstr.find("x")].lower() + insertion + opstr[opstr.find("x")+1:].lower()
|
||||
|
||||
current_byte += 1
|
||||
offset += 1
|
||||
if "?" in opstr:
|
||||
for y in range(0, opstr.count("?")):
|
||||
byte1 = rom[offset + 1]
|
||||
byte2 = rom[offset + 2]
|
||||
|
||||
number = byte1
|
||||
number += byte2 << 8;
|
||||
|
||||
insertion = "$%.4x" % (number)
|
||||
|
||||
opstr = opstr[:opstr.find("?")].lower() + insertion + opstr[opstr.find("?")+1:].lower()
|
||||
|
||||
current_byte_number += 2
|
||||
offset += 2
|
||||
|
||||
output += spacing + opstr #+ " ; " + hex(offset)
|
||||
output += "\n"
|
||||
|
||||
current_byte_number += 2
|
||||
offset += 2
|
||||
elif not is_data and maybe_byte in opt_table.keys():
|
||||
op_code = opt_table[maybe_byte]
|
||||
op_code_type = op_code[1]
|
||||
op_code_byte = maybe_byte
|
||||
|
||||
#type = -1 when it's the E op
|
||||
#if op_code_type != -1:
|
||||
if op_code_type == 0 and rom[offset] == op_code_byte:
|
||||
op_str = op_code[0].lower()
|
||||
|
||||
output += spacing + op_code[0].lower() #+ " ; " + hex(offset)
|
||||
output += "\n"
|
||||
|
||||
offset += 1
|
||||
current_byte_number += 1
|
||||
elif op_code_type == 1 and rom[offset] == op_code_byte:
|
||||
oplen = len(op_code[0])
|
||||
opstr = copy(op_code[0])
|
||||
xes = op_code[0].count("x")
|
||||
include_comment = False
|
||||
for x in range(0, xes):
|
||||
insertion = rom[offset + 1]
|
||||
insertion = "$" + hex(insertion)[2:]
|
||||
|
||||
if current_byte == 0x18 or current_byte==0x20 or current_byte in relative_jumps: #jr or jr nz
|
||||
#generate a label for the byte we're jumping to
|
||||
target_address = offset + 2 + c_int8(rom[offset + 1]).value
|
||||
if target_address in byte_labels.keys():
|
||||
byte_labels[target_address]["usage"] = 1 + byte_labels[target_address]["usage"]
|
||||
line_label2 = byte_labels[target_address]["name"]
|
||||
else:
|
||||
line_label2 = asm_label(target_address)
|
||||
byte_labels[target_address] = {}
|
||||
byte_labels[target_address]["name"] = line_label2
|
||||
byte_labels[target_address]["usage"] = 1
|
||||
byte_labels[target_address]["definition"] = False
|
||||
|
||||
insertion = line_label2
|
||||
if has_outstanding_labels(byte_labels) and all_outstanding_labels_are_reverse(byte_labels, offset):
|
||||
include_comment = True
|
||||
elif current_byte == 0x3e:
|
||||
last_a_address = rom[offset + 1]
|
||||
|
||||
opstr = opstr[:opstr.find("x")].lower() + insertion + opstr[opstr.find("x")+1:].lower()
|
||||
|
||||
# because the $ff00+$ff syntax is silly
|
||||
if opstr.count("$") > 1 and "+" in opstr:
|
||||
first_orig = opstr[opstr.find("$"):opstr.find("+")]
|
||||
first_val = eval(first_orig.replace("$","0x"))
|
||||
|
||||
second_orig = opstr[opstr.find("+$")+1:opstr.find("]")]
|
||||
second_val = eval(second_orig.replace("$","0x"))
|
||||
|
||||
combined_val = "$%.4x" % (first_val + second_val)
|
||||
result = find_label(combined_val, bank_id)
|
||||
if result != None:
|
||||
combined_val = result
|
||||
|
||||
replacetron = "[%s+%s]" % (first_orig, second_orig)
|
||||
opstr = opstr.replace(replacetron, "[%s]" % combined_val)
|
||||
|
||||
output += spacing + opstr
|
||||
if include_comment:
|
||||
output += " ; " + hex(offset)
|
||||
if current_byte in relative_jumps:
|
||||
output += " $" + hex(rom[offset + 1])[2:]
|
||||
output += "\n"
|
||||
|
||||
current_byte_number += 1
|
||||
offset += 1
|
||||
insertion = ""
|
||||
|
||||
current_byte_number += 1
|
||||
offset += 1
|
||||
include_comment = False
|
||||
elif op_code_type == 2 and rom[offset] == op_code_byte:
|
||||
oplen = len(op_code[0])
|
||||
opstr = copy(op_code[0])
|
||||
qes = op_code[0].count("?")
|
||||
for x in range(0, qes):
|
||||
byte1 = rom[offset + 1]
|
||||
byte2 = rom[offset + 2]
|
||||
|
||||
number = byte1
|
||||
number += byte2 << 8
|
||||
|
||||
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)
|
||||
if result != None:
|
||||
insertion = result
|
||||
|
||||
opstr = opstr[:opstr.find("?")].lower() + insertion + opstr[opstr.find("?")+1:].lower()
|
||||
output += spacing + opstr #+ " ; " + hex(offset)
|
||||
output += "\n"
|
||||
|
||||
current_byte_number += 2
|
||||
offset += 2
|
||||
|
||||
current_byte_number += 1
|
||||
offset += 1
|
||||
|
||||
if current_byte == 0x21:
|
||||
last_hl_address = byte1 + (byte2 << 8)
|
||||
if current_byte == 0xcd:
|
||||
if number == 0x3d97: used_3d97 = True
|
||||
|
||||
#duck out if this is jp $24d7
|
||||
if current_byte == 0xc3 or current_byte in relative_unconditional_jumps:
|
||||
if current_byte == 0xc3:
|
||||
if number == 0x3d97: used_3d97 = True
|
||||
#if number == 0x24d7: #jp
|
||||
if not has_outstanding_labels(byte_labels) or all_outstanding_labels_are_reverse(byte_labels, offset):
|
||||
keep_reading = False
|
||||
is_data = False
|
||||
break
|
||||
else:
|
||||
is_data = True
|
||||
else:
|
||||
#if is_data and keep_reading:
|
||||
output += spacing + "db $" + hex(rom[offset])[2:] #+ " ; " + hex(offset)
|
||||
output += "\n"
|
||||
offset += 1
|
||||
current_byte_number += 1
|
||||
if offset in byte_labels.keys():
|
||||
is_data = False
|
||||
keep_reading = True
|
||||
#else the while loop would have spit out the opcode
|
||||
|
||||
#these two are done prior
|
||||
#offset += 1
|
||||
#current_byte_number += 1
|
||||
|
||||
if not is_data and current_byte in relative_unconditional_jumps + end_08_scripts_with:
|
||||
#stop reading at a jump, relative jump or return
|
||||
if not has_outstanding_labels(byte_labels) or all_outstanding_labels_are_reverse(byte_labels, offset):
|
||||
keep_reading = False
|
||||
is_data = False #cleanup
|
||||
break
|
||||
elif offset not in byte_labels.keys() and offset in data_tables.keys():
|
||||
is_data = True
|
||||
keep_reading = True
|
||||
else:
|
||||
is_data = False
|
||||
keep_reading = True
|
||||
output += "\n"
|
||||
elif is_data and offset not in byte_labels.keys():
|
||||
is_data = True
|
||||
keep_reading = True
|
||||
else:
|
||||
is_data = False
|
||||
keep_reading = True
|
||||
|
||||
if offset in data_tables.keys():
|
||||
output = output.replace('$%x' % (get_local_address(offset)), data_label(offset))
|
||||
output += data_label(offset) + '\n'
|
||||
is_data = True
|
||||
keep_reading = True
|
||||
|
||||
first_loop = False
|
||||
|
||||
#clean up unused labels
|
||||
for label_line in byte_labels.keys():
|
||||
address = label_line
|
||||
label_line = byte_labels[label_line]
|
||||
if label_line["usage"] == 0:
|
||||
output = output.replace((label_line["name"] + "\n"), "")
|
||||
|
||||
#tone down excessive spacing
|
||||
output = output.replace("\n\n\n","\n\n")
|
||||
|
||||
#add the offset of the final location
|
||||
if include_last_address:
|
||||
output += "; " + hex(offset)
|
||||
|
||||
return (output, offset, last_hl_address, last_a_address, used_3d97)
|
||||
|
||||
def has_outstanding_labels(byte_labels):
|
||||
"""
|
||||
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]
|
||||
if real_line["definition"] == False: return True
|
||||
return False
|
||||
|
||||
def all_outstanding_labels_are_reverse(byte_labels, offset):
|
||||
for label_id in byte_labels.keys():
|
||||
line = byte_labels[label_id] # label_id is also the address
|
||||
if line["definition"] == False:
|
||||
if not label_id < offset: return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
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:
|
||||
label_addr = find_address_from_label(addr)
|
||||
if label_addr:
|
||||
addr = label_addr
|
||||
else:
|
||||
addr = int(addr, 16)
|
||||
print output_bank_opcodes(addr)[0]
|
1672
extras/gfx.py
1672
extras/gfx.py
File diff suppressed because it is too large
Load Diff
169
extras/graph.py
169
extras/graph.py
@ -1,169 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import networkx as nx
|
||||
|
||||
from romstr import (
|
||||
RomStr,
|
||||
relative_jumps,
|
||||
call_commands,
|
||||
relative_unconditional_jumps,
|
||||
)
|
||||
|
||||
class RomGraph(nx.DiGraph):
|
||||
"""
|
||||
Graphs various functions pointing to each other.
|
||||
|
||||
TODO: Bank switches are nasty. They should be detected. Otherwise,
|
||||
functions will point to non-functions within the same bank. Another way
|
||||
to detect bankswitches is retroactively. By disassembling one function
|
||||
after another within the function banks, it can be roughly assumed that
|
||||
anything pointing to something else (within the same bank) is really
|
||||
actually a bankswitch. An even better method to handle bankswitches
|
||||
would be to just detect those situations in the asm (but I presently
|
||||
forget how bankswitches are performed in pokecrystal).
|
||||
"""
|
||||
|
||||
# some areas shouldn't be parsed as asm
|
||||
exclusions = []
|
||||
|
||||
# where is the first function located?
|
||||
start_address = 0x150
|
||||
|
||||
# and where is a good place to stop?
|
||||
end_address = 0x4000 * 0x03 # only do the first bank? sure..
|
||||
|
||||
# where is the rom stored?
|
||||
rompath = "../baserom.gbc"
|
||||
|
||||
def __init__(self, rom=None, **kwargs):
|
||||
"""
|
||||
Loads and parses the ROM into a function graph.
|
||||
"""
|
||||
# continue the initialization
|
||||
nx.DiGraph.__init__(self, **kwargs)
|
||||
|
||||
# load the graph
|
||||
if rom == None:
|
||||
self.load_rom()
|
||||
else:
|
||||
self.rom = rom
|
||||
|
||||
# start parsing the ROM
|
||||
self.parse()
|
||||
|
||||
def load_rom(self):
|
||||
"""
|
||||
Creates a RomStr from rompath.
|
||||
"""
|
||||
file_handler = open(self.rompath, "r")
|
||||
self.rom = RomStr(file_handler.read())
|
||||
file_handler.close()
|
||||
|
||||
def parse(self):
|
||||
"""
|
||||
Parses the ROM starting with the first function address. Each
|
||||
function is disassembled and parsed to find where else it leads to.
|
||||
"""
|
||||
functions = {}
|
||||
|
||||
address = self.start_address
|
||||
|
||||
other_addresses = set()
|
||||
|
||||
count = 0
|
||||
|
||||
while True:
|
||||
if count > 3000:
|
||||
break
|
||||
|
||||
if address < self.end_address and (address not in functions.keys()) and address >= 0x150:
|
||||
# address is okay to parse at, keep going
|
||||
pass
|
||||
elif len(other_addresses) > 0:
|
||||
# parse some other address possibly in a remote bank
|
||||
address = other_addresses.pop()
|
||||
else:
|
||||
# no more addresses detected- exit loop
|
||||
break
|
||||
|
||||
# parse the asm
|
||||
func = self.rom.to_asm(address)
|
||||
|
||||
# check if there are any nops (probably not a function)
|
||||
nops = 0
|
||||
for (id, command) in func.asm_commands.items():
|
||||
if command.has_key("id") and command["id"] == 0x0:
|
||||
nops += 1
|
||||
|
||||
# skip this function
|
||||
if nops > 1:
|
||||
address = 0
|
||||
continue
|
||||
|
||||
# store this parsed function
|
||||
functions[address] = func
|
||||
|
||||
# where does this function jump to?
|
||||
used_addresses = set(func.used_addresses())
|
||||
|
||||
# add this information to the graph
|
||||
for used_address in used_addresses:
|
||||
# only add this remote address if it's not yet parsed
|
||||
if used_address not in functions.keys():
|
||||
other_addresses.update([used_address])
|
||||
|
||||
# add this other address to the graph
|
||||
if used_address > 100:
|
||||
self.add_node(used_address)
|
||||
|
||||
# add this as an edge between the two nodes
|
||||
self.add_edge(address, used_address)
|
||||
|
||||
# setup the next function to be parsed
|
||||
address = func.last_address
|
||||
|
||||
count += 1
|
||||
|
||||
self.functions = functions
|
||||
|
||||
def pretty_printer(self):
|
||||
"""
|
||||
Shows some text output describing which nodes point to which other
|
||||
nodes.
|
||||
"""
|
||||
print self.edges()
|
||||
|
||||
def to_d3(self):
|
||||
"""
|
||||
Exports to d3.js because we're gangster like that.
|
||||
"""
|
||||
import networkx.readwrite.json_graph as json_graph
|
||||
content = json_graph.dumps(self)
|
||||
fh = open("crystal/crystal.json", "w")
|
||||
fh.write(content)
|
||||
fh.close()
|
||||
|
||||
def to_gephi(self):
|
||||
"""
|
||||
Generates a gexf file.
|
||||
"""
|
||||
nx.write_gexf(self, "graph.gexf")
|
||||
|
||||
class RedGraph(RomGraph):
|
||||
"""
|
||||
Not implemented. Go away.
|
||||
"""
|
||||
|
||||
rompath = "../pokered-baserom.gbc"
|
||||
|
||||
class CryGraph(RomGraph):
|
||||
exclusions = [
|
||||
[0x000, 0x149],
|
||||
]
|
||||
|
||||
rompath = "../baserom.gbc"
|
||||
|
||||
if __name__ == "__main__":
|
||||
crygraph = CryGraph()
|
||||
crygraph.pretty_printer()
|
||||
crygraph.to_gephi()
|
@ -1,104 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from bisect import bisect_left, bisect_right
|
||||
from itertools import izip
|
||||
|
||||
class IntervalMap(object):
|
||||
"""
|
||||
This class maps a set of intervals to a set of values.
|
||||
|
||||
>>> i = IntervalMap()
|
||||
>>> i[0:5] = "hello world"
|
||||
>>> i[6:10] = "hello cruel world"
|
||||
>>> print i[4]
|
||||
"hello world"
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""initializes an empty IntervalMap"""
|
||||
self._bounds = []
|
||||
self._items = []
|
||||
self._upperitem = None
|
||||
|
||||
def __setitem__(self, _slice, _value):
|
||||
"""sets an interval mapping"""
|
||||
assert isinstance(_slice, slice), 'The key must be a slice object'
|
||||
|
||||
if _slice.start is None:
|
||||
start_point = -1
|
||||
else:
|
||||
start_point = bisect_left(self._bounds, _slice.start)
|
||||
|
||||
if _slice.stop is None:
|
||||
end_point = -1
|
||||
else:
|
||||
end_point = bisect_left(self._bounds, _slice.stop)
|
||||
|
||||
if start_point>=0:
|
||||
if start_point < len(self._bounds) and self._bounds[start_point]<_slice.start:
|
||||
start_point += 1
|
||||
|
||||
if end_point>=0:
|
||||
self._bounds[start_point:end_point] = [_slice.start, _slice.stop]
|
||||
if start_point < len(self._items):
|
||||
self._items[start_point:end_point] = [self._items[start_point], _value]
|
||||
else:
|
||||
self._items[start_point:end_point] = [self._upperitem, _value]
|
||||
else:
|
||||
self._bounds[start_point:] = [_slice.start]
|
||||
if start_point < len(self._items):
|
||||
self._items[start_point:] = [self._items[start_point], _value]
|
||||
else:
|
||||
self._items[start_point:] = [self._upperitem]
|
||||
self._upperitem = _value
|
||||
else:
|
||||
if end_point>=0:
|
||||
self._bounds[:end_point] = [_slice.stop]
|
||||
self._items[:end_point] = [_value]
|
||||
else:
|
||||
self._bounds[:] = []
|
||||
self._items[:] = []
|
||||
self._upperitem = _value
|
||||
|
||||
def __getitem__(self,_point):
|
||||
"""gets a value from the mapping"""
|
||||
assert not isinstance(_point, slice), 'The key cannot be a slice object'
|
||||
|
||||
index = bisect_right(self._bounds, _point)
|
||||
if index < len(self._bounds):
|
||||
return self._items[index]
|
||||
else:
|
||||
return self._upperitem
|
||||
|
||||
def items(self):
|
||||
"""returns an iterator with each item being
|
||||
((low_bound, high_bound), value)
|
||||
these items are returned in order"""
|
||||
previous_bound = None
|
||||
for (b, v) in izip(self._bounds, self._items):
|
||||
if v is not None:
|
||||
yield (previous_bound, b), v
|
||||
previous_bound = b
|
||||
if self._upperitem is not None:
|
||||
yield (previous_bound, None), self._upperitem
|
||||
|
||||
def values(self):
|
||||
"""returns an iterator with each item being a stored value
|
||||
the items are returned in order"""
|
||||
for v in self._items:
|
||||
if v is not None:
|
||||
yield v
|
||||
if self._upperitem is not None:
|
||||
yield self._upperitem
|
||||
|
||||
def __repr__(self):
|
||||
s = []
|
||||
for b,v in self.items():
|
||||
if v is not None:
|
||||
s.append('[%r, %r] => %r'%(
|
||||
b[0],
|
||||
b[1],
|
||||
v
|
||||
))
|
||||
return '{'+', '.join(s)+'}'
|
||||
|
@ -1,241 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
item_constants = {
|
||||
1: 'MASTER_BALL',
|
||||
2: 'ULTRA_BALL',
|
||||
3: 'BRIGHTPOWDER',
|
||||
4: 'GREAT_BALL',
|
||||
5: 'POKE_BALL',
|
||||
7: 'BICYCLE',
|
||||
8: 'MOON_STONE',
|
||||
9: 'ANTIDOTE',
|
||||
10: 'BURN_HEAL',
|
||||
11: 'ICE_HEAL',
|
||||
12: 'AWAKENING',
|
||||
13: 'PARLYZ_HEAL',
|
||||
14: 'FULL_RESTORE',
|
||||
15: 'MAX_POTION',
|
||||
16: 'HYPER_POTION',
|
||||
17: 'SUPER_POTION',
|
||||
18: 'POTION',
|
||||
19: 'ESCAPE_ROPE',
|
||||
20: 'REPEL',
|
||||
21: 'MAX_ELIXER',
|
||||
22: 'FIRE_STONE',
|
||||
23: 'THUNDERSTONE',
|
||||
24: 'WATER_STONE',
|
||||
26: 'HP_UP',
|
||||
27: 'PROTEIN',
|
||||
28: 'IRON',
|
||||
29: 'CARBOS',
|
||||
30: 'LUCKY_PUNCH',
|
||||
31: 'CALCIUM',
|
||||
32: 'RARE_CANDY',
|
||||
33: 'X_ACCURACY',
|
||||
34: 'LEAF_STONE',
|
||||
35: 'METAL_POWDER',
|
||||
36: 'NUGGET',
|
||||
37: 'POKE_DOLL',
|
||||
38: 'FULL_HEAL',
|
||||
39: 'REVIVE',
|
||||
40: 'MAX_REVIVE',
|
||||
41: 'GUARD_SPEC',
|
||||
42: 'SUPER_REPEL',
|
||||
43: 'MAX_REPEL',
|
||||
44: 'DIRE_HIT',
|
||||
46: 'FRESH_WATER',
|
||||
47: 'SODA_POP',
|
||||
48: 'LEMONADE',
|
||||
49: 'X_ATTACK',
|
||||
51: 'X_DEFEND',
|
||||
52: 'X_SPEED',
|
||||
53: 'X_SPECIAL',
|
||||
54: 'COIN_CASE',
|
||||
55: 'ITEMFINDER',
|
||||
57: 'EXP_SHARE',
|
||||
58: 'OLD_ROD',
|
||||
59: 'GOOD_ROD',
|
||||
60: 'SILVER_LEAF',
|
||||
61: 'SUPER_ROD',
|
||||
62: 'PP_UP',
|
||||
63: 'ETHER',
|
||||
64: 'MAX_ETHER',
|
||||
65: 'ELIXER',
|
||||
66: 'RED_SCALE',
|
||||
67: 'SECRETPOTION',
|
||||
68: 'S_S_TICKET',
|
||||
69: 'MYSTERY_EGG',
|
||||
70: 'CLEAR_BELL',
|
||||
71: 'SILVER_WING',
|
||||
72: 'MOOMOO_MILK',
|
||||
73: 'QUICK_CLAW',
|
||||
74: 'PSNCUREBERRY',
|
||||
75: 'GOLD_LEAF',
|
||||
76: 'SOFT_SAND',
|
||||
77: 'SHARP_BEAK',
|
||||
78: 'PRZCUREBERRY',
|
||||
79: 'BURNT_BERRY',
|
||||
80: 'ICE_BERRY',
|
||||
81: 'POISON_BARB',
|
||||
82: "KINGS_ROCK",
|
||||
83: 'BITTER_BERRY',
|
||||
84: 'MINT_BERRY',
|
||||
85: 'RED_APRICORN',
|
||||
86: 'TINYMUSHROOM',
|
||||
87: 'BIG_MUSHROOM',
|
||||
88: 'SILVERPOWDER',
|
||||
89: 'BLU_APRICORN',
|
||||
91: 'AMULET_COIN',
|
||||
92: 'YLW_APRICORN',
|
||||
93: 'GRN_APRICORN',
|
||||
94: 'CLEANSE_TAG',
|
||||
95: 'MYSTIC_WATER',
|
||||
96: 'TWISTEDSPOON',
|
||||
97: 'WHT_APRICORN',
|
||||
98: 'BLACKBELT',
|
||||
99: 'BLK_APRICORN',
|
||||
101: 'PNK_APRICORN',
|
||||
102: 'BLACKGLASSES',
|
||||
103: 'SLOWPOKETAIL',
|
||||
104: 'PINK_BOW',
|
||||
105: 'STICK',
|
||||
106: 'SMOKE_BALL',
|
||||
107: 'NEVERMELTICE',
|
||||
108: 'MAGNET',
|
||||
109: 'MIRACLEBERRY',
|
||||
110: 'PEARL',
|
||||
111: 'BIG_PEARL',
|
||||
112: 'EVERSTONE',
|
||||
113: 'SPELL_TAG',
|
||||
114: 'RAGECANDYBAR',
|
||||
115: 'GS_BALL',
|
||||
116: 'BLUE_CARD',
|
||||
117: 'MIRACLE_SEED',
|
||||
118: 'THICK_CLUB',
|
||||
119: 'FOCUS_BAND',
|
||||
121: 'ENERGYPOWDER',
|
||||
122: 'ENERGY_ROOT',
|
||||
123: 'HEAL_POWDER',
|
||||
124: 'REVIVAL_HERB',
|
||||
125: 'HARD_STONE',
|
||||
126: 'LUCKY_EGG',
|
||||
127: 'CARD_KEY',
|
||||
128: 'MACHINE_PART',
|
||||
129: 'EGG_TICKET',
|
||||
130: 'LOST_ITEM',
|
||||
131: 'STARDUST',
|
||||
132: 'STAR_PIECE',
|
||||
133: 'BASEMENT_KEY',
|
||||
134: 'PASS',
|
||||
138: 'CHARCOAL',
|
||||
139: 'BERRY_JUICE',
|
||||
140: 'SCOPE_LENS',
|
||||
143: 'METAL_COAT',
|
||||
144: 'DRAGON_FANG',
|
||||
146: 'LEFTOVERS',
|
||||
150: 'MYSTERYBERRY',
|
||||
151: 'DRAGON_SCALE',
|
||||
152: 'BERSERK_GENE',
|
||||
156: 'SACRED_ASH',
|
||||
157: 'HEAVY_BALL',
|
||||
158: 'FLOWER_MAIL',
|
||||
159: 'LEVEL_BALL',
|
||||
160: 'LURE_BALL',
|
||||
161: 'FAST_BALL',
|
||||
163: 'LIGHT_BALL',
|
||||
164: 'FRIEND_BALL',
|
||||
165: 'MOON_BALL',
|
||||
166: 'LOVE_BALL',
|
||||
167: 'NORMAL_BOX',
|
||||
168: 'GORGEOUS_BOX',
|
||||
169: 'SUN_STONE',
|
||||
170: 'POLKADOT_BOW',
|
||||
172: 'UP_GRADE',
|
||||
173: 'BERRY',
|
||||
174: 'GOLD_BERRY',
|
||||
175: 'SQUIRTBOTTLE',
|
||||
177: 'PARK_BALL',
|
||||
178: 'RAINBOW_WING',
|
||||
180: 'BRICK_PIECE',
|
||||
181: 'SURF_MAIL',
|
||||
182: 'LITEBLUEMAIL',
|
||||
183: 'PORTRAITMAIL',
|
||||
184: 'LOVELY_MAIL',
|
||||
185: 'EON_MAIL',
|
||||
186: 'MORPH_MAIL',
|
||||
187: 'BLUESKY_MAIL',
|
||||
188: 'MUSIC_MAIL',
|
||||
189: 'MIRAGE_MAIL',
|
||||
191: 'TM_01',
|
||||
192: 'TM_02',
|
||||
193: 'TM_03',
|
||||
194: 'TM_04',
|
||||
196: 'TM_05',
|
||||
197: 'TM_06',
|
||||
198: 'TM_07',
|
||||
199: 'TM_08',
|
||||
200: 'TM_09',
|
||||
201: 'TM_10',
|
||||
202: 'TM_11',
|
||||
203: 'TM_12',
|
||||
204: 'TM_13',
|
||||
205: 'TM_14',
|
||||
206: 'TM_15',
|
||||
207: 'TM_16',
|
||||
208: 'TM_17',
|
||||
209: 'TM_18',
|
||||
210: 'TM_19',
|
||||
211: 'TM_20',
|
||||
212: 'TM_21',
|
||||
213: 'TM_22',
|
||||
214: 'TM_23',
|
||||
215: 'TM_24',
|
||||
216: 'TM_25',
|
||||
217: 'TM_26',
|
||||
218: 'TM_27',
|
||||
219: 'TM_28',
|
||||
221: 'TM_29',
|
||||
222: 'TM_30',
|
||||
223: 'TM_31',
|
||||
224: 'TM_32',
|
||||
225: 'TM_33',
|
||||
226: 'TM_34',
|
||||
227: 'TM_35',
|
||||
228: 'TM_36',
|
||||
229: 'TM_37',
|
||||
230: 'TM_38',
|
||||
231: 'TM_39',
|
||||
232: 'TM_40',
|
||||
233: 'TM_41',
|
||||
234: 'TM_42',
|
||||
235: 'TM_43',
|
||||
236: 'TM_44',
|
||||
237: 'TM_45',
|
||||
238: 'TM_46',
|
||||
239: 'TM_47',
|
||||
240: 'TM_48',
|
||||
241: 'TM_49',
|
||||
242: 'TM_50',
|
||||
243: 'HM_01',
|
||||
244: 'HM_02',
|
||||
245: 'HM_03',
|
||||
246: 'HM_04',
|
||||
247: 'HM_05',
|
||||
248: 'HM_06',
|
||||
249: 'HM_07',
|
||||
}
|
||||
|
||||
def find_item_label_by_id(id):
|
||||
if id in item_constants.keys():
|
||||
return item_constants[id]
|
||||
else: return None
|
||||
|
||||
def generate_item_constants():
|
||||
"""make a list of items to put in constants.asm"""
|
||||
output = ""
|
||||
for (id, item) in item_constants.items():
|
||||
val = ("$%.2x"%id).upper()
|
||||
while len(item)<13: item+= " "
|
||||
output += item + " EQU " + val + "\n"
|
||||
return output
|
||||
|
172
extras/labels.py
172
extras/labels.py
@ -1,172 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Various label/line-related functions.
|
||||
"""
|
||||
|
||||
from pointers import (
|
||||
calculate_pointer,
|
||||
calculate_bank,
|
||||
)
|
||||
|
||||
def remove_quoted_text(line):
|
||||
"""get rid of content inside quotes
|
||||
and also removes the quotes from the input string"""
|
||||
while line.count("\"") % 2 == 0 and line.count("\"") > 0:
|
||||
first = line.find("\"")
|
||||
second = line.find("\"", first+1)
|
||||
line = line[0:first] + line[second+1:]
|
||||
while line.count("\'") % 2 == 0 and line.count("'") > 0:
|
||||
first = line.find("\'")
|
||||
second = line.find("\'", first+1)
|
||||
line = line[0:first] + line[second+1:]
|
||||
return line
|
||||
|
||||
def line_has_comment_address(line, returnable={}, bank=None):
|
||||
"""checks that a given line has a comment
|
||||
with a valid address, and returns the address in the object.
|
||||
Note: bank is required if you have a 4-letter-or-less address,
|
||||
because otherwise there is no way to figure out which bank
|
||||
is curretly being scanned."""
|
||||
#first set the bank/offset to nada
|
||||
returnable["bank"] = None
|
||||
returnable["offset"] = None
|
||||
returnable["address"] = None
|
||||
#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
|
||||
#first throw away anything in quotes
|
||||
if (line.count("\"") % 2 == 0 and line.count("\"")!=0) \
|
||||
or (line.count("\'") % 2 == 0 and line.count("\'")!=0):
|
||||
line = remove_quoted_text(line)
|
||||
#check if there is still a comment in this line after quotes removed
|
||||
if ";" not in line:
|
||||
return False
|
||||
#but even if there's a semicolon there must be later text
|
||||
if line[-1] == ";":
|
||||
return False
|
||||
#and just a space doesn't count
|
||||
if line[-2:] == "; ":
|
||||
return False
|
||||
#and multiple whitespace doesn't count either
|
||||
line = line.rstrip(" ").lstrip(" ")
|
||||
if line[-1] == ";":
|
||||
return False
|
||||
#there must be more content after the semicolon
|
||||
if len(line)-1 == line.find(";"):
|
||||
return False
|
||||
#split it up into the main comment part
|
||||
comment = line[line.find(";")+1:]
|
||||
#don't want no leading whitespace
|
||||
comment = comment.lstrip(" ").rstrip(" ")
|
||||
#split up multi-token comments into single tokens
|
||||
token = comment
|
||||
if " " in comment:
|
||||
#use the first token in the comment
|
||||
token = comment.split(" ")[0]
|
||||
if token in ["0x", "$", "x", ":"]:
|
||||
return False
|
||||
offset = None
|
||||
#process a token with a A:B format
|
||||
if ":" in token: #3:3F0A, $3:$3F0A, 0x3:0x3F0A, 3:3F0A
|
||||
#split up the token
|
||||
bank_piece = token.split(":")[0].lower()
|
||||
offset_piece = token.split(":")[1].lower()
|
||||
#filter out blanks/duds
|
||||
if bank_piece in ["$", "0x", "x"] \
|
||||
or offset_piece in ["$", "0x", "x"]:
|
||||
return False
|
||||
#they can't have both "$" and "x"
|
||||
if "$" in bank_piece and "x" in bank_piece:
|
||||
return False
|
||||
if "$" in offset_piece and "x" in offset_piece:
|
||||
return False
|
||||
#process the bank piece
|
||||
if "$" in bank_piece:
|
||||
bank_piece = bank_piece.replace("$", "0x")
|
||||
#check characters for validity?
|
||||
for c in bank_piece.replace("x", ""):
|
||||
if c not in valid:
|
||||
return False
|
||||
bank = int(bank_piece, 16)
|
||||
#process the offset piece
|
||||
if "$" in offset_piece:
|
||||
offset_piece = offset_piece.replace("$", "0x")
|
||||
#check characters for validity?
|
||||
for c in offset_piece.replace("x", ""):
|
||||
if c not in valid:
|
||||
return False
|
||||
if len(offset_piece) == 0:
|
||||
return None
|
||||
offset = int(offset_piece, 16)
|
||||
#filter out blanks/duds
|
||||
elif token in ["$", "0x", "x"]:
|
||||
return False
|
||||
#can't have both "$" and "x" in the number
|
||||
elif "$" in token and "x" in token:
|
||||
return False
|
||||
elif "x" in token and not "0x" in token: #it should be 0x
|
||||
return False
|
||||
elif "$" in token and not "x" in token:
|
||||
token = token.replace("$", "0x")
|
||||
offset = int(token, 16)
|
||||
elif "0x" in token and not "$" in token:
|
||||
offset = int(token, 16)
|
||||
else: #might just be "1" at this point
|
||||
token = token.lower()
|
||||
#check if there are bad characters
|
||||
for c in token:
|
||||
if c not in valid:
|
||||
return False
|
||||
offset = int(token, 16)
|
||||
if offset == None and bank == None:
|
||||
return False
|
||||
if bank == None:
|
||||
bank = calculate_bank(offset)
|
||||
returnable["bank"] = bank
|
||||
returnable["offset"] = offset
|
||||
returnable["address"] = calculate_pointer(offset, bank=bank)
|
||||
return True
|
||||
|
||||
def get_address_from_line_comment(line, bank=None):
|
||||
"""
|
||||
wrapper for line_has_comment_address
|
||||
"""
|
||||
returnable = {}
|
||||
result = line_has_comment_address(line, returnable=returnable, bank=bank)
|
||||
if not result:
|
||||
return False
|
||||
return returnable["address"]
|
||||
|
||||
def line_has_label(line):
|
||||
"""returns True if the line has an asm label"""
|
||||
if not isinstance(line, str):
|
||||
raise Exception, "can't check this type of object"
|
||||
line = line.rstrip(" ").lstrip(" ")
|
||||
line = remove_quoted_text(line)
|
||||
if ";" in line:
|
||||
line = line.split(";")[0]
|
||||
if 0 <= len(line) <= 1:
|
||||
return False
|
||||
if ":" not in line:
|
||||
return False
|
||||
if line[0] == ";":
|
||||
return False
|
||||
if line[0] == "\"":
|
||||
return False
|
||||
if "::" in line:
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_label_from_line(line):
|
||||
"""returns the label from the line"""
|
||||
#check if the line has a label
|
||||
if not line_has_label(line):
|
||||
return None
|
||||
#split up the line
|
||||
label = line.split(":")[0]
|
||||
return label
|
||||
|
@ -1,484 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# this is modified in crystal.py during run-time
|
||||
map_names = {
|
||||
1: {
|
||||
0x1: {"name": "Olivine Pokémon Center 1F",
|
||||
"label": "OlivinePokeCenter1F"},
|
||||
0x2: {"name": "Olivine Gym"},
|
||||
0x3: {"name": "Olivine Voltorb House"},
|
||||
0x4: {"name": "Olivine House Beta"},
|
||||
0x5: {"name": "Olivine Punishment Speech House"},
|
||||
0x6: {"name": "Olivine Good Rod House"},
|
||||
0x7: {"name": "Olivine Cafe"},
|
||||
0x8: {"name": "Olivine Mart"},
|
||||
0x9: {"name": "Route 38 Ecruteak Gate"},
|
||||
0xA: {"name": "Route 39 Barn"},
|
||||
0xB: {"name": "Route 39 Farmhouse"},
|
||||
0xC: {"name": "Route 38"},
|
||||
0xD: {"name": "Route 39"},
|
||||
0xE: {"name": "Olivine City"},
|
||||
},
|
||||
2: {
|
||||
0x1: {"name": "Mahogany Red Gyarados Speech House"},
|
||||
0x2: {"name": "Mahogany Gym"},
|
||||
0x3: {"name": "Mahogany Pokémon Center 1F",
|
||||
"label": "MahoganyPokeCenter1F"},
|
||||
0x4: {"name": "Route 42 Ecruteak Gate"},
|
||||
0x5: {"name": "Route 42"},
|
||||
0x6: {"name": "Route 44"},
|
||||
0x7: {"name": "Mahogany Town"},
|
||||
},
|
||||
3: {
|
||||
0x1: {"name": "Sprout Tower 1F"},
|
||||
0x2: {"name": "Sprout Tower 2F"},
|
||||
0x3: {"name": "Sprout Tower 3F"},
|
||||
0x4: {"name": "Tin Tower 1F"},
|
||||
0x5: {"name": "Tin Tower 2F"},
|
||||
0x6: {"name": "Tin Tower 3F"},
|
||||
0x7: {"name": "Tin Tower 4F"},
|
||||
0x8: {"name": "Tin Tower 5F"},
|
||||
0x9: {"name": "Tin Tower 6F"},
|
||||
0xA: {"name": "Tin Tower 7F"},
|
||||
0xB: {"name": "Tin Tower 8F"},
|
||||
0xC: {"name": "Tin Tower 9F"},
|
||||
0xD: {"name": "Burned Tower 1F"},
|
||||
0xE: {"name": "Burned Tower B1F"},
|
||||
0xF: {"name": "National Park"},
|
||||
0x10: {"name": "National Park Bug Contest"},
|
||||
0x11: {"name": "Radio Tower 1F"},
|
||||
0x12: {"name": "Radio Tower 2F"},
|
||||
0x13: {"name": "Radio Tower 3F"},
|
||||
0x14: {"name": "Radio Tower 4F"},
|
||||
0x15: {"name": "Radio Tower 5F"},
|
||||
0x16: {"name": "Ruins of Alph Outside"},
|
||||
0x17: {"name": "Ruins of Alph Ho-oh Chamber"},
|
||||
0x18: {"name": "Ruins of Alph Kabuto Chamber"},
|
||||
0x19: {"name": "Ruins of Alph Omanyte Chamber"},
|
||||
0x1A: {"name": "Ruins of Alph Aerodactyl Chamber"},
|
||||
0x1B: {"name": "Ruins of Alph Inner Chamber"},
|
||||
0x1C: {"name": "Ruins of Alph Research Center"},
|
||||
0x1D: {"name": "Ruins of Alph Ho-oh Item Room"},
|
||||
0x1E: {"name": "Ruins of Alph Kabuto Item Room"},
|
||||
0x1F: {"name": "Ruins of Alph Omanyte Item Room"},
|
||||
0x20: {"name": "Ruins of Alph Aerodactyl Item Room"},
|
||||
0x21: {"name": "Ruins of Alph Ho-Oh Word Room"},
|
||||
0x22: {"name": "Ruins of Alph Kabuto Word Room"},
|
||||
0x23: {"name": "Ruins of Alph Omanyte Word Room"},
|
||||
0x24: {"name": "Ruins of Alph Aerodactyl Word Room"},
|
||||
0x25: {"name": "Union Cave 1F"},
|
||||
0x26: {"name": "Union Cave B1F"},
|
||||
0x27: {"name": "Union Cave B2F"},
|
||||
0x28: {"name": "Slowpoke Well B1F"},
|
||||
0x29: {"name": "Slowpoke Well B2F"},
|
||||
0x2A: {"name": "Olivine Lighthouse 1F"},
|
||||
0x2B: {"name": "Olivine Lighthouse 2F"},
|
||||
0x2C: {"name": "Olivine Lighthouse 3F"},
|
||||
0x2D: {"name": "Olivine Lighthouse 4F"},
|
||||
0x2E: {"name": "Olivine Lighthouse 5F"},
|
||||
0x2F: {"name": "Olivine Lighthouse 6F"},
|
||||
0x30: {"name": "Mahogany Mart 1F"},
|
||||
0x31: {"name": "Team Rocket Base B1F"},
|
||||
0x32: {"name": "Team Rocket Base B2F"},
|
||||
0x33: {"name": "Team Rocket Base B3F"},
|
||||
0x34: {"name": "Ilex Forest"},
|
||||
0x35: {"name": "Warehouse Entrance"},
|
||||
0x36: {"name": "Underground Path Switch Room Entrances"},
|
||||
0x37: {"name": "Goldenrod Dept Store B1F"},
|
||||
0x38: {"name": "Underground Warehouse"},
|
||||
0x39: {"name": "Mount Mortar 1F Outside"},
|
||||
0x3A: {"name": "Mount Mortar 1F Inside"},
|
||||
0x3B: {"name": "Mount Mortar 2F Inside"},
|
||||
0x3C: {"name": "Mount Mortar B1F"},
|
||||
0x3D: {"name": "Ice Path 1F"},
|
||||
0x3E: {"name": "Ice Path B1F"},
|
||||
0x3F: {"name": "Ice Path B2F Mahogany Side"},
|
||||
0x40: {"name": "Ice Path B2F Blackthorn Side"},
|
||||
0x41: {"name": "Ice Path B3F"},
|
||||
0x42: {"name": "Whirl Island NW"},
|
||||
0x43: {"name": "Whirl Island NE"},
|
||||
0x44: {"name": "Whirl Island SW"},
|
||||
0x45: {"name": "Whirl Island Cave"},
|
||||
0x46: {"name": "Whirl Island SE"},
|
||||
0x47: {"name": "Whirl Island B1F"},
|
||||
0x48: {"name": "Whirl Island B2F"},
|
||||
0x49: {"name": "Whirl Island Lugia Chamber"},
|
||||
0x4A: {"name": "Silver Cave Room 1"},
|
||||
0x4B: {"name": "Silver Cave Room 2"},
|
||||
0x4C: {"name": "Silver Cave Room 3"},
|
||||
0x4D: {"name": "Silver Cave Item Rooms"},
|
||||
0x4E: {"name": "Dark Cave Violet Entrance"},
|
||||
0x4F: {"name": "Dark Cave Blackthorn Entrance"},
|
||||
0x50: {"name": "Dragon's Den 1F"},
|
||||
0x51: {"name": "Dragon's Den B1F"},
|
||||
0x52: {"name": "Dragon Shrine"},
|
||||
0x53: {"name": "Tohjo Falls"},
|
||||
0x54: {"name": "Diglett's Cave"},
|
||||
0x55: {"name": "Mount Moon"},
|
||||
0x56: {"name": "Underground"},
|
||||
0x57: {"name": "Rock Tunnel 1F"},
|
||||
0x58: {"name": "Rock Tunnel B1F"},
|
||||
0x59: {"name": "Safari Zone Fuchsia Gate Beta"},
|
||||
0x5A: {"name": "Safari Zone Beta"},
|
||||
0x5B: {"name": "Victory Road"},
|
||||
},
|
||||
4: {
|
||||
0x1: {"name": "Ecruteak House"}, # passage to Tin Tower
|
||||
0x2: {"name": "Wise Trio's Room"},
|
||||
0x3: {"name": "Ecruteak Pokémon Center 1F",
|
||||
"label": "EcruteakPokeCenter1F"},
|
||||
0x4: {"name": "Ecruteak Lugia Speech House"},
|
||||
0x5: {"name": "Dance Theatre"},
|
||||
0x6: {"name": "Ecruteak Mart"},
|
||||
0x7: {"name": "Ecruteak Gym"},
|
||||
0x8: {"name": "Ecruteak Itemfinder House"},
|
||||
0x9: {"name": "Ecruteak City"},
|
||||
},
|
||||
5: {
|
||||
0x1: {"name": "Blackthorn Gym 1F"},
|
||||
0x2: {"name": "Blackthorn Gym 2F"},
|
||||
0x3: {"name": "Blackthorn Dragon Speech House"},
|
||||
0x4: {"name": "Blackthorn Dodrio Trade House"},
|
||||
0x5: {"name": "Blackthorn Mart"},
|
||||
0x6: {"name": "Blackthorn Pokémon Center 1F",
|
||||
"label": "BlackthornPokeCenter1F"},
|
||||
0x7: {"name": "Move Deleter's House"},
|
||||
0x8: {"name": "Route 45"},
|
||||
0x9: {"name": "Route 46"},
|
||||
0xA: {"name": "Blackthorn City"},
|
||||
},
|
||||
6: {
|
||||
0x1: {"name": "Cinnabar Pokémon Center 1F",
|
||||
"label": "CinnabarPokeCenter1F"},
|
||||
0x2: {"name": "Cinnabar Pokémon Center 2F Beta",
|
||||
"label": "CinnabarPokeCenter2FBeta"},
|
||||
0x3: {"name": "Route 19 - Fuchsia Gate"},
|
||||
0x4: {"name": "Seafoam Gym"},
|
||||
0x5: {"name": "Route 19"},
|
||||
0x6: {"name": "Route 20"},
|
||||
0x7: {"name": "Route 21"},
|
||||
0x8: {"name": "Cinnabar Island"},
|
||||
},
|
||||
7: {
|
||||
0x1: {"name": "Cerulean Gym Badge Speech House"},
|
||||
0x2: {"name": "Cerulean Police Station"},
|
||||
0x3: {"name": "Cerulean Trade Speech House"},
|
||||
0x4: {"name": "Cerulean Pokémon Center 1F",
|
||||
"label": "CeruleanPokeCenter1F"},
|
||||
0x5: {"name": "Cerulean Pokémon Center 2F Beta",
|
||||
"label": "CeruleanPokeCenter2FBeta"},
|
||||
0x6: {"name": "Cerulean Gym"},
|
||||
0x7: {"name": "Cerulean Mart"},
|
||||
0x8: {"name": "Route 10 Pokémon Center 1F",
|
||||
"label": "Route10PokeCenter1F"},
|
||||
0x9: {"name": "Route 10 Pokémon Center 2F Beta",
|
||||
"label": "Route10PokeCenter2FBeta"},
|
||||
0xA: {"name": "Power Plant"},
|
||||
0xB: {"name": "Bill's House"},
|
||||
0xC: {"name": "Route 4"},
|
||||
0xD: {"name": "Route 9"},
|
||||
0xE: {"name": "Route 10 North"},
|
||||
0xF: {"name": "Route 24"},
|
||||
0x10: {"name": "Route 25"},
|
||||
0x11: {"name": "Cerulean City"},
|
||||
},
|
||||
8: {
|
||||
0x1: {"name": "Azalea Pokémon Center 1F",
|
||||
"label": "AzaleaPokeCenter1F"},
|
||||
0x2: {"name": "Charcoal Kiln"},
|
||||
0x3: {"name": "Azalea Mart"},
|
||||
0x4: {"name": "Kurt's House"},
|
||||
0x5: {"name": "Azalea Gym"},
|
||||
0x6: {"name": "Route 33"},
|
||||
0x7: {"name": "Azalea Town"},
|
||||
},
|
||||
9: {
|
||||
0x1: {"name": "Lake of Rage Hidden Power House"},
|
||||
0x2: {"name": "Lake of Rage Magikarp House"},
|
||||
0x3: {"name": "Route 43 Mahogany Gate"},
|
||||
0x4: {"name": "Route 43 Gate"},
|
||||
0x5: {"name": "Route 43"},
|
||||
0x6: {"name": "Lake of Rage"},
|
||||
},
|
||||
10: {
|
||||
0x1: {"name": "Route 32"},
|
||||
0x2: {"name": "Route 35"},
|
||||
0x3: {"name": "Route 36"},
|
||||
0x4: {"name": "Route 37"},
|
||||
0x5: {"name": "Violet City"},
|
||||
0x6: {"name": "Violet Mart"},
|
||||
0x7: {"name": "Violet Gym"},
|
||||
0x8: {"name": "Earl's Pokémon Academy",
|
||||
"label": "EarlsPokemonAcademy"},
|
||||
0x9: {"name": "Violet Nickname Speech House"},
|
||||
0xA: {"name": "Violet Pokémon Center 1F",
|
||||
"label": "VioletPokeCenter1F"},
|
||||
0xB: {"name": "Violet Onix Trade House"},
|
||||
0xC: {"name": "Route 32 Ruins of Alph Gate"},
|
||||
0xD: {"name": "Route 32 Pokémon Center 1F",
|
||||
"label": "Route32PokeCenter1F"},
|
||||
0xE: {"name": "Route 35 Goldenrod gate"},
|
||||
0xF: {"name": "Route 35 National Park gate"},
|
||||
0x10: {"name": "Route 36 Ruins of Alph gate"},
|
||||
0x11: {"name": "Route 36 National Park gate"},
|
||||
},
|
||||
11: {
|
||||
0x1: {"name": "Route 34"},
|
||||
0x2: {"name": "Goldenrod City"},
|
||||
0x3: {"name": "Goldenrod Gym"},
|
||||
0x4: {"name": "Goldenrod Bike Shop"},
|
||||
0x5: {"name": "Goldenrod Happiness Rater"},
|
||||
0x6: {"name": "Goldenrod Bill's House"},
|
||||
0x7: {"name": "Goldenrod Magnet Train Station"},
|
||||
0x8: {"name": "Goldenrod Flower Shop"},
|
||||
0x9: {"name": "Goldenrod PP Speech House"},
|
||||
0xA: {"name": "Goldenrod Name Rater's House"},
|
||||
0xB: {"name": "Goldenrod Dept Store 1F"},
|
||||
0xC: {"name": "Goldenrod Dept Store 2F"},
|
||||
0xD: {"name": "Goldenrod Dept Store 3F"},
|
||||
0xE: {"name": "Goldenrod Dept Store 4F"},
|
||||
0xF: {"name": "Goldenrod Dept Store 5F"},
|
||||
0x10: {"name": "Goldenrod Dept Store 6F"},
|
||||
0x11: {"name": "Goldenrod Dept Store Elevator"},
|
||||
0x12: {"name": "Goldenrod Dept Store Roof"},
|
||||
0x13: {"name": "Goldenrod Game Corner"},
|
||||
0x14: {"name": "Goldenrod Pokémon Center 1F",
|
||||
"label": "GoldenrodPokeCenter1F"},
|
||||
0x15: {"name": "Goldenrod PokéCom Center 2F Mobile",
|
||||
"label": "GoldenrodPokeComCenter2FMobile"},
|
||||
0x16: {"name": "Ilex Forest Azalea Gate"},
|
||||
0x17: {"name": "Route 34 Ilex Forest Gate"},
|
||||
0x18: {"name": "Day Care"},
|
||||
},
|
||||
12: {
|
||||
0x1: {"name": "Route 6"},
|
||||
0x2: {"name": "Route 11"},
|
||||
0x3: {"name": "Vermilion City"},
|
||||
0x4: {"name": "Vermilion House Fishing Speech House"},
|
||||
0x5: {"name": "Vermilion Pokémon Center 1F",
|
||||
"label": "VermilionPokeCenter1F"},
|
||||
0x6: {"name": "Vermilion Pokémon Center 2F Beta",
|
||||
"label": "VermilionPokeCenter2FBeta"},
|
||||
0x7: {"name": "Pokémon Fan Club"},
|
||||
0x8: {"name": "Vermilion Magnet Train Speech House"},
|
||||
0x9: {"name": "Vermilion Mart"},
|
||||
0xA: {"name": "Vermilion House Diglett's Cave Speech House"},
|
||||
0xB: {"name": "Vermilion Gym"},
|
||||
0xC: {"name": "Route 6 Saffron Gate"},
|
||||
0xD: {"name": "Route 6 Underground Entrance"},
|
||||
},
|
||||
13: {
|
||||
0x1: {"name": "Route 1"},
|
||||
0x2: {"name": "Pallet Town"},
|
||||
0x3: {"name": "Red's House 1F"},
|
||||
0x4: {"name": "Red's House 2F"},
|
||||
0x5: {"name": "Blue's House"},
|
||||
0x6: {"name": "Oak's Lab"},
|
||||
},
|
||||
14: {
|
||||
0x1: {"name": "Route 3"},
|
||||
0x2: {"name": "Pewter City"},
|
||||
0x3: {"name": "Pewter Nidoran Speech House"},
|
||||
0x4: {"name": "Pewter Gym"},
|
||||
0x5: {"name": "Pewter Mart"},
|
||||
0x6: {"name": "Pewter Pokémon Center 1F",
|
||||
"label": "PewterPokeCenter1F"},
|
||||
0x7: {"name": "Pewter Pokémon Center 2F Beta",
|
||||
"label": "PewterPokeCEnter2FBeta"},
|
||||
0x8: {"name": "Pewter Snooze Speech House"},
|
||||
},
|
||||
15: {
|
||||
0x1: {"name": "Olivine Port"},
|
||||
0x2: {"name": "Vermilion Port"},
|
||||
0x3: {"name": "Fast Ship 1F"},
|
||||
0x4: {"name": "Fast Ship Cabins NNW, NNE, NE",
|
||||
"label": "FastShipCabins_NNW_NNE_NE"},
|
||||
0x5: {"name": "Fast Ship Cabins SW, SSW, NW",
|
||||
"label": "FastShipCabins_SW_SSW_NW"},
|
||||
0x6: {"name": "Fast Ship Cabins SE, SSE, Captain's Cabin",
|
||||
"label": "FastShipCabins_SE_SSE_CaptainsCabin"},
|
||||
0x7: {"name": "Fast Ship B1F"},
|
||||
0x8: {"name": "Olivine Port Passage"},
|
||||
0x9: {"name": "Vermilion Port Passage"},
|
||||
0xA: {"name": "Mount Moon Square"},
|
||||
0xB: {"name": "Mount Moon Gift Shop"},
|
||||
0xC: {"name": "Tin Tower Roof"},
|
||||
},
|
||||
16: {
|
||||
0x1: {"name": "Route 23"},
|
||||
0x2: {"name": "Indigo Plateau Pokémon Center 1F",
|
||||
"label": "IndigoPlateauPokeCenter1F"},
|
||||
0x3: {"name": "Will's Room"},
|
||||
0x4: {"name": "Koga's Room"},
|
||||
0x5: {"name": "Bruno's Room"},
|
||||
0x6: {"name": "Karen's Room"},
|
||||
0x7: {"name": "Lance's Room"},
|
||||
0x8: {"name": "Hall of Fame",
|
||||
"label": "HallOfFame"},
|
||||
},
|
||||
17: {
|
||||
0x1: {"name": "Route 13"},
|
||||
0x2: {"name": "Route 14"},
|
||||
0x3: {"name": "Route 15"},
|
||||
0x4: {"name": "Route 18"},
|
||||
0x5: {"name": "Fuchsia City"},
|
||||
0x6: {"name": "Fuchsia Mart"},
|
||||
0x7: {"name": "Safari Zone Main Office"},
|
||||
0x8: {"name": "Fuchsia Gym"},
|
||||
0x9: {"name": "Fuchsia Bill Speech House"},
|
||||
0xA: {"name": "Fuchsia Pokémon Center 1F",
|
||||
"label": "FuchsiaPokeCenter1F"},
|
||||
0xB: {"name": "Fuchsia Pokémon Center 2F Beta",
|
||||
"label": "FuchsiaPokeCenter2FBeta"},
|
||||
0xC: {"name": "Safari Zone Warden's Home"},
|
||||
0xD: {"name": "Route 15 Fuchsia Gate"},
|
||||
},
|
||||
18: {
|
||||
0x1: {"name": "Route 8"},
|
||||
0x2: {"name": "Route 12"},
|
||||
0x3: {"name": "Route 10 South"},
|
||||
0x4: {"name": "Lavender Town"},
|
||||
0x5: {"name": "Lavender Pokémon Center 1F",
|
||||
"label": "LavenderPokeCenter1F"},
|
||||
0x6: {"name": "Lavender Pokémon Center 2F Beta",
|
||||
"label": "LavenderPokeCenter2FBeta"},
|
||||
0x7: {"name": "Mr. Fuji's House"},
|
||||
0x8: {"name": "Lavender Town Speech House"},
|
||||
0x9: {"name": "Lavender Name Rater"},
|
||||
0xA: {"name": "Lavender Mart"},
|
||||
0xB: {"name": "Soul House"},
|
||||
0xC: {"name": "Lav Radio Tower 1F"},
|
||||
0xD: {"name": "Route 8 Saffron Gate"},
|
||||
0xE: {"name": "Route 12 Super Rod House"},
|
||||
},
|
||||
19: {
|
||||
0x1: {"name": "Route 28"},
|
||||
0x2: {"name": "Silver Cave Outside"},
|
||||
0x3: {"name": "Silver Cave Pokémon Center 1F",
|
||||
"label": "SilverCavePokeCenter1F"},
|
||||
0x4: {"name": "Route 28 Famous Speech House"},
|
||||
},
|
||||
20: {
|
||||
0x1: {"name": "Pokémon Center 2F",
|
||||
"label": "PokeCenter2F"},
|
||||
0x2: {"name": "Trade Center"},
|
||||
0x3: {"name": "Colosseum"},
|
||||
0x4: {"name": "Time Capsule"},
|
||||
0x5: {"name": "Mobile Trade Room Mobile"},
|
||||
0x6: {"name": "Mobile Battle Room"},
|
||||
},
|
||||
21: {
|
||||
0x1: {"name": "Route 7"},
|
||||
0x2: {"name": "Route 16"},
|
||||
0x3: {"name": "Route 17"},
|
||||
0x4: {"name": "Celadon City"},
|
||||
0x5: {"name": "Celadon Dept Store 1F"},
|
||||
0x6: {"name": "Celadon Dept Store 2F"},
|
||||
0x7: {"name": "Celadon Dept Store 3F"},
|
||||
0x8: {"name": "Celadon Dept Store 4F"},
|
||||
0x9: {"name": "Celadon Dept Store 5F"},
|
||||
0xA: {"name": "Celadon Dept Store 6F"},
|
||||
0xB: {"name": "Celadon Dept Store Elevator"},
|
||||
0xC: {"name": "Celadon Mansion 1F"},
|
||||
0xD: {"name": "Celadon Mansion 2F"},
|
||||
0xE: {"name": "Celadon Mansion 3F"},
|
||||
0xF: {"name": "Celadon Mansion Roof"},
|
||||
0x10: {"name": "Celadon Mansion Roof House"},
|
||||
0x11: {"name": "Celadon Pokémon Center 1F",
|
||||
"label": "CeladonPokeCenter1F"},
|
||||
0x12: {"name": "Celadon Pokémon Center 2F Beta",
|
||||
"label": "CeladonPokeCenter2FBeta"},
|
||||
0x13: {"name": "Celadon Game Corner"},
|
||||
0x14: {"name": "Celadon Game Corner Prize Room"},
|
||||
0x15: {"name": "Celadon Gym"},
|
||||
0x16: {"name": "Celadon Cafe"},
|
||||
0x17: {"name": "Route 16 Fuchsia Speech House"},
|
||||
0x18: {"name": "Route 16 Gate"},
|
||||
0x19: {"name": "Route 7 Saffron Gate"},
|
||||
0x1A: {"name": "Route 17 18 Gate"},
|
||||
},
|
||||
22: {
|
||||
0x1: {"name": "Route 40"},
|
||||
0x2: {"name": "Route 41"},
|
||||
0x3: {"name": "Cianwood City"},
|
||||
0x4: {"name": "Mania's House"},
|
||||
0x5: {"name": "Cianwood Gym"},
|
||||
0x6: {"name": "Cianwood Pokémon Center 1F",
|
||||
"label": "CianwoodPokeCenter1F"},
|
||||
0x7: {"name": "Cianwood Pharmacy"},
|
||||
0x8: {"name": "Cianwood City Photo Studio"},
|
||||
0x9: {"name": "Cianwood Lugia Speech House"},
|
||||
0xA: {"name": "Poke Seer's House"},
|
||||
0xB: {"name": "Battle Tower 1F"},
|
||||
0xC: {"name": "Battle Tower Battle Room"},
|
||||
0xD: {"name": "Battle Tower Elevator"},
|
||||
0xE: {"name": "Battle Tower Hallway"},
|
||||
0xF: {"name": "Route 40 Battle Tower Gate"},
|
||||
0x10: {"name": "Battle Tower Outside"},
|
||||
},
|
||||
23: {
|
||||
0x1: {"name": "Route 2"},
|
||||
0x2: {"name": "Route 22"},
|
||||
0x3: {"name": "Viridian City"},
|
||||
0x4: {"name": "Viridian Gym"},
|
||||
0x5: {"name": "Viridian Nickname Speech House"},
|
||||
0x6: {"name": "Trainer House 1F"},
|
||||
0x7: {"name": "Trainer House B1F"},
|
||||
0x8: {"name": "Viridian Mart"},
|
||||
0x9: {"name": "Viridian Pokémon Center 1F",
|
||||
"label": "ViridianPokeCenter1F"},
|
||||
0xA: {"name": "Viridian Pokémon Center 2F Beta",
|
||||
"label": "ViridianPokeCenter2FBeta"},
|
||||
0xB: {"name": "Route 2 Nugget Speech House"},
|
||||
0xC: {"name": "Route 2 Gate"},
|
||||
0xD: {"name": "Victory Road Gate"},
|
||||
},
|
||||
24: {
|
||||
0x1: {"name": "Route 26"},
|
||||
0x2: {"name": "Route 27"},
|
||||
0x3: {"name": "Route 29"},
|
||||
0x4: {"name": "New Bark Town"},
|
||||
0x5: {"name": "Elm's Lab"},
|
||||
0x6: {"name": "Kris's House 1F"},
|
||||
0x7: {"name": "Kris's House 2F"},
|
||||
0x8: {"name": "Kris's Neighbor's House"},
|
||||
0x9: {"name": "Elm's House"},
|
||||
0xA: {"name": "Route 26 Heal Speech House"},
|
||||
0xB: {"name": "Route 26 Day of Week Siblings House"},
|
||||
0xC: {"name": "Route 27 Sandstorm House"},
|
||||
0xD: {"name": "Route 29 46 Gate"},
|
||||
},
|
||||
25: {
|
||||
0x1: {"name": "Route 5"},
|
||||
0x2: {"name": "Saffron City"},
|
||||
0x3: {"name": "Fighting Dojo"},
|
||||
0x4: {"name": "Saffron Gym"},
|
||||
0x5: {"name": "Saffron Mart"},
|
||||
0x6: {"name": "Saffron Pokémon Center 1F",
|
||||
"label": "SaffronPokeCenter1F"},
|
||||
0x7: {"name": "Saffron Pokémon Center 2F Beta",
|
||||
"label": "SaffronPokeCenter2FBeta"},
|
||||
0x8: {"name": "Mr. Psychic's House"},
|
||||
0x9: {"name": "Saffron Train Station"},
|
||||
0xA: {"name": "Silph Co. 1F"},
|
||||
0xB: {"name": "Copycat's House 1F"},
|
||||
0xC: {"name": "Copycat's House 2F"},
|
||||
0xD: {"name": "Route 5 Underground Entrance"},
|
||||
0xE: {"name": "Route 5 Saffron City Gate"},
|
||||
0xF: {"name": "Route 5 Cleanse Tag Speech House"},
|
||||
},
|
||||
26: {
|
||||
0x1: {"name": "Route 30"},
|
||||
0x2: {"name": "Route 31"},
|
||||
0x3: {"name": "Cherrygrove City"},
|
||||
0x4: {"name": "Cherrygrove Mart"},
|
||||
0x5: {"name": "Cherrygrove Pokémon Center 1F",
|
||||
"label": "CherrygrovePokeCenter1F"},
|
||||
0x6: {"name": "Cherrygrove Gym Speech House"},
|
||||
0x7: {"name": "Guide Gent's House"},
|
||||
0x8: {"name": "Cherrygrove Evolution Speech House"},
|
||||
0x9: {"name": "Route 30 Berry Speech House"},
|
||||
0xA: {"name": "Mr. Pokémon's House"},
|
||||
0xB: {"name": "Route 31 Violet Gate"},
|
||||
},
|
||||
}
|
@ -1,255 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
moves = {
|
||||
0x01: "POUND",
|
||||
0x02: "KARATE_CHOP",
|
||||
0x03: "DOUBLESLAP",
|
||||
0x04: "COMET_PUNCH",
|
||||
0x05: "MEGA_PUNCH",
|
||||
0x06: "PAY_DAY",
|
||||
0x07: "FIRE_PUNCH",
|
||||
0x08: "ICE_PUNCH",
|
||||
0x09: "THUNDERPUNCH",
|
||||
0x0A: "SCRATCH",
|
||||
0x0B: "VICEGRIP",
|
||||
0x0C: "GUILLOTINE",
|
||||
0x0D: "RAZOR_WIND",
|
||||
0x0E: "SWORDS_DANCE",
|
||||
0x0F: "CUT",
|
||||
0x10: "GUST",
|
||||
0x11: "WING_ATTACK",
|
||||
0x12: "WHIRLWIND",
|
||||
0x13: "FLY",
|
||||
0x14: "BIND",
|
||||
0x15: "SLAM",
|
||||
0x16: "VINE_WHIP",
|
||||
0x17: "STOMP",
|
||||
0x18: "DOUBLE_KICK",
|
||||
0x19: "MEGA_KICK",
|
||||
0x1A: "JUMP_KICK",
|
||||
0x1B: "ROLLING_KICK",
|
||||
0x1C: "SAND_ATTACK",
|
||||
0x1D: "HEADBUTT",
|
||||
0x1E: "HORN_ATTACK",
|
||||
0x1F: "FURY_ATTACK",
|
||||
0x20: "HORN_DRILL",
|
||||
0x21: "TACKLE",
|
||||
0x22: "BODY_SLAM",
|
||||
0x23: "WRAP",
|
||||
0x24: "TAKE_DOWN",
|
||||
0x25: "THRASH",
|
||||
0x26: "DOUBLE_EDGE",
|
||||
0x27: "TAIL_WHIP",
|
||||
0x28: "POISON_STING",
|
||||
0x29: "TWINEEDLE",
|
||||
0x2A: "PIN_MISSILE",
|
||||
0x2B: "LEER",
|
||||
0x2C: "BITE",
|
||||
0x2D: "GROWL",
|
||||
0x2E: "ROAR",
|
||||
0x2F: "SING",
|
||||
0x30: "SUPERSONIC",
|
||||
0x31: "SONICBOOM",
|
||||
0x32: "DISABLE",
|
||||
0x33: "ACID",
|
||||
0x34: "EMBER",
|
||||
0x35: "FLAMETHROWER",
|
||||
0x36: "MIST",
|
||||
0x37: "WATER_GUN",
|
||||
0x38: "HYDRO_PUMP",
|
||||
0x39: "SURF",
|
||||
0x3A: "ICE_BEAM",
|
||||
0x3B: "BLIZZARD",
|
||||
0x3C: "PSYBEAM",
|
||||
0x3D: "BUBBLEBEAM",
|
||||
0x3E: "AURORA_BEAM",
|
||||
0x3F: "HYPER_BEAM",
|
||||
0x40: "PECK",
|
||||
0x41: "DRILL_PECK",
|
||||
0x42: "SUBMISSION",
|
||||
0x43: "LOW_KICK",
|
||||
0x44: "COUNTER",
|
||||
0x45: "SEISMIC_TOSS",
|
||||
0x46: "STRENGTH",
|
||||
0x47: "ABSORB",
|
||||
0x48: "MEGA_DRAIN",
|
||||
0x49: "LEECH_SEED",
|
||||
0x4A: "GROWTH",
|
||||
0x4B: "RAZOR_LEAF",
|
||||
0x4C: "SOLARBEAM",
|
||||
0x4D: "POISONPOWDER",
|
||||
0x4E: "STUN_SPORE",
|
||||
0x4F: "SLEEP_POWDER",
|
||||
0x50: "PETAL_DANCE",
|
||||
0x51: "STRING_SHOT",
|
||||
0x52: "DRAGON_RAGE",
|
||||
0x53: "FIRE_SPIN",
|
||||
0x54: "THUNDERSHOCK",
|
||||
0x55: "THUNDERBOLT",
|
||||
0x56: "THUNDER_WAVE",
|
||||
0x57: "THUNDER",
|
||||
0x58: "ROCK_THROW",
|
||||
0x59: "EARTHQUAKE",
|
||||
0x5A: "FISSURE",
|
||||
0x5B: "DIG",
|
||||
0x5C: "TOXIC",
|
||||
0x5D: "CONFUSION",
|
||||
0x5E: "PSYCHIC_M",
|
||||
0x5F: "HYPNOSIS",
|
||||
0x60: "MEDITATE",
|
||||
0x61: "AGILITY",
|
||||
0x62: "QUICK_ATTACK",
|
||||
0x63: "RAGE",
|
||||
0x64: "TELEPORT",
|
||||
0x65: "NIGHT_SHADE",
|
||||
0x66: "MIMIC",
|
||||
0x67: "SCREECH",
|
||||
0x68: "DOUBLE_TEAM",
|
||||
0x69: "RECOVER",
|
||||
0x6A: "HARDEN",
|
||||
0x6B: "MINIMIZE",
|
||||
0x6C: "SMOKESCREEN",
|
||||
0x6D: "CONFUSE_RAY",
|
||||
0x6E: "WITHDRAW",
|
||||
0x6F: "DEFENSE_CURL",
|
||||
0x70: "BARRIER",
|
||||
0x71: "LIGHT_SCREEN",
|
||||
0x72: "HAZE",
|
||||
0x73: "REFLECT",
|
||||
0x74: "FOCUS_ENERGY",
|
||||
0x75: "BIDE",
|
||||
0x76: "METRONOME",
|
||||
0x77: "MIRROR_MOVE",
|
||||
0x78: "SELFDESTRUCT",
|
||||
0x79: "EGG_BOMB",
|
||||
0x7A: "LICK",
|
||||
0x7B: "SMOG",
|
||||
0x7C: "SLUDGE",
|
||||
0x7D: "BONE_CLUB",
|
||||
0x7E: "FIRE_BLAST",
|
||||
0x7F: "WATERFALL",
|
||||
0x80: "CLAMP",
|
||||
0x81: "SWIFT",
|
||||
0x82: "SKULL_BASH",
|
||||
0x83: "SPIKE_CANNON",
|
||||
0x84: "CONSTRICT",
|
||||
0x85: "AMNESIA",
|
||||
0x86: "KINESIS",
|
||||
0x87: "SOFTBOILED",
|
||||
0x88: "HI_JUMP_KICK",
|
||||
0x89: "GLARE",
|
||||
0x8A: "DREAM_EATER",
|
||||
0x8B: "POISON_GAS",
|
||||
0x8C: "BARRAGE",
|
||||
0x8D: "LEECH_LIFE",
|
||||
0x8E: "LOVELY_KISS",
|
||||
0x8F: "SKY_ATTACK",
|
||||
0x90: "TRANSFORM",
|
||||
0x91: "BUBBLE",
|
||||
0x92: "DIZZY_PUNCH",
|
||||
0x93: "SPORE",
|
||||
0x94: "FLASH",
|
||||
0x95: "PSYWAVE",
|
||||
0x96: "SPLASH",
|
||||
0x97: "ACID_ARMOR",
|
||||
0x98: "CRABHAMMER",
|
||||
0x99: "EXPLOSION",
|
||||
0x9A: "FURY_SWIPES",
|
||||
0x9B: "BONEMERANG",
|
||||
0x9C: "REST",
|
||||
0x9D: "ROCK_SLIDE",
|
||||
0x9E: "HYPER_FANG",
|
||||
0x9F: "SHARPEN",
|
||||
0xA0: "CONVERSION",
|
||||
0xA1: "TRI_ATTACK",
|
||||
0xA2: "SUPER_FANG",
|
||||
0xA3: "SLASH",
|
||||
0xA4: "SUBSTITUTE",
|
||||
0xA5: "STRUGGLE",
|
||||
0xA6: "SKETCH",
|
||||
0xA7: "TRIPLE_KICK",
|
||||
0xA8: "THIEF",
|
||||
0xA9: "SPIDER_WEB",
|
||||
0xAA: "MIND_READER",
|
||||
0xAB: "NIGHTMARE",
|
||||
0xAC: "FLAME_WHEEL",
|
||||
0xAD: "SNORE",
|
||||
0xAE: "CURSE",
|
||||
0xAF: "FLAIL",
|
||||
0xB0: "CONVERSION2",
|
||||
0xB1: "AEROBLAST",
|
||||
0xB2: "COTTON_SPORE",
|
||||
0xB3: "REVERSAL",
|
||||
0xB4: "SPITE",
|
||||
0xB5: "POWDER_SNOW",
|
||||
0xB6: "PROTECT",
|
||||
0xB7: "MACH_PUNCH",
|
||||
0xB8: "SCARY_FACE",
|
||||
0xB9: "FAINT_ATTACK",
|
||||
0xBA: "SWEET_KISS",
|
||||
0xBB: "BELLY_DRUM",
|
||||
0xBC: "SLUDGE_BOMB",
|
||||
0xBD: "MUD_SLAP",
|
||||
0xBE: "OCTAZOOKA",
|
||||
0xBF: "SPIKES",
|
||||
0xC0: "ZAP_CANNON",
|
||||
0xC1: "FORESIGHT",
|
||||
0xC2: "DESTINY_BOND",
|
||||
0xC3: "PERISH_SONG",
|
||||
0xC4: "ICY_WIND",
|
||||
0xC5: "DETECT",
|
||||
0xC6: "BONE_RUSH",
|
||||
0xC7: "LOCK_ON",
|
||||
0xC8: "OUTRAGE",
|
||||
0xC9: "SANDSTORM",
|
||||
0xCA: "GIGA_DRAIN",
|
||||
0xCB: "ENDURE",
|
||||
0xCC: "CHARM",
|
||||
0xCD: "ROLLOUT",
|
||||
0xCE: "FALSE_SWIPE",
|
||||
0xCF: "SWAGGER",
|
||||
0xD0: "MILK_DRINK",
|
||||
0xD1: "SPARK",
|
||||
0xD2: "FURY_CUTTER",
|
||||
0xD3: "STEEL_WING",
|
||||
0xD4: "MEAN_LOOK",
|
||||
0xD5: "ATTRACT",
|
||||
0xD6: "SLEEP_TALK",
|
||||
0xD7: "HEAL_BELL",
|
||||
0xD8: "RETURN",
|
||||
0xD9: "PRESENT",
|
||||
0xDA: "FRUSTRATION",
|
||||
0xDB: "SAFEGUARD",
|
||||
0xDC: "PAIN_SPLIT",
|
||||
0xDD: "SACRED_FIRE",
|
||||
0xDE: "MAGNITUDE",
|
||||
0xDF: "DYNAMICPUNCH",
|
||||
0xE0: "MEGAHORN",
|
||||
0xE1: "DRAGONBREATH",
|
||||
0xE2: "BATON_PASS",
|
||||
0xE3: "ENCORE",
|
||||
0xE4: "PURSUIT",
|
||||
0xE5: "RAPID_SPIN",
|
||||
0xE6: "SWEET_SCENT",
|
||||
0xE7: "IRON_TAIL",
|
||||
0xE8: "METAL_CLAW",
|
||||
0xE9: "VITAL_THROW",
|
||||
0xEA: "MORNING_SUN",
|
||||
0xEB: "SYNTHESIS",
|
||||
0xEC: "MOONLIGHT",
|
||||
0xED: "HIDDEN_POWER",
|
||||
0xEE: "CROSS_CHOP",
|
||||
0xEF: "TWISTER",
|
||||
0xF0: "RAIN_DANCE",
|
||||
0xF1: "SUNNY_DAY",
|
||||
0xF2: "CRUNCH",
|
||||
0xF3: "MIRROR_COAT",
|
||||
0xF4: "PSYCH_UP",
|
||||
0xF5: "EXTREMESPEED",
|
||||
0xF6: "ANCIENTPOWER",
|
||||
0xF7: "SHADOW_BALL",
|
||||
0xF8: "FUTURE_SIGHT",
|
||||
0xF9: "ROCK_SMASH",
|
||||
0xFA: "WHIRLPOOL",
|
||||
0xFB: "BEAT_UP",
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +0,0 @@
|
||||
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"
|
||||
gfx.get_uncompressed_gfx((bank * 0x4000 + ((sprite - offset) * 4 * 0x10)), 4, filename)
|
||||
gfx.to_png(filename)
|
||||
file_handler.write("INCBIN \"" + filename[3:] + "\"\n")
|
||||
file_handler.close()
|
||||
|
||||
rip_sprites_from_bank(0x30)
|
||||
rip_sprites_from_bank(0x31, offset=256)
|
@ -1,25 +0,0 @@
|
||||
import sys
|
||||
|
||||
import crystal
|
||||
|
||||
rom = crystal.load_rom()
|
||||
|
||||
addr = int(sys.argv[1], 16)
|
||||
count = int(sys.argv[2]) if len(sys.argv) > 2 else 256
|
||||
label_prefix = sys.argv[3] if len(sys.argv) > 3 else "UnknownString"
|
||||
|
||||
ex = None
|
||||
|
||||
for i in range(count):
|
||||
try:
|
||||
string = crystal.PokedexText(addr)
|
||||
asm = string.to_asm()
|
||||
except Exception as ex:
|
||||
break
|
||||
print label_prefix+str(i)+": ; "+hex(addr)
|
||||
print "\t"+asm
|
||||
print
|
||||
addr = string.last_address
|
||||
|
||||
print "; "+hex(addr)
|
||||
if ex: raise ex
|
@ -1,494 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ply.lex as lex
|
||||
import sys, os
|
||||
|
||||
|
||||
FILENAME = '' # Current filename
|
||||
|
||||
|
||||
_tokens = ('STRING', 'NEWLINE', 'LABEL',
|
||||
'ID', 'COMMA', 'PLUS', 'MINUS', 'LP', 'RP', 'MUL', 'DIV', 'POW',
|
||||
'UMINUS', 'APO', 'INTEGER', 'ADDR', 'RB', 'LB',
|
||||
'LOCALLABEL', 'LSHIFT', 'RSHIFT', 'BITWISE_OR', 'BITWISE_AND',
|
||||
'LOGICAL_NOT', 'BITWISE_COMPLEMENT',
|
||||
)
|
||||
|
||||
reserved_instructions = {
|
||||
'adc': 'ADC',
|
||||
'add': 'ADD',
|
||||
'and': 'AND',
|
||||
'bit': 'BIT',
|
||||
'call': 'CALL',
|
||||
'ccf': 'CCF',
|
||||
'cp': 'CP',
|
||||
'cpd': 'CPD',
|
||||
'cpdr': 'CPDR',
|
||||
'cpi': 'CPI',
|
||||
'cpir': 'CPIR',
|
||||
'cpl': 'CPL',
|
||||
'daa': 'DAA',
|
||||
'dec': 'DEC',
|
||||
'di': 'DI',
|
||||
'djnz': 'DJNZ',
|
||||
'ei': 'EI',
|
||||
'ex': 'EX',
|
||||
'exx': 'EXX',
|
||||
'halt': 'HALT',
|
||||
'im': 'IM',
|
||||
'in': 'IN',
|
||||
'inc': 'INC',
|
||||
'ind': 'IND',
|
||||
'indr': 'INDR',
|
||||
'ini': 'INI',
|
||||
'inir': 'INIR',
|
||||
'jp': 'JP',
|
||||
'jr': 'JR',
|
||||
'ld': 'LD',
|
||||
'ldd': 'LDD',
|
||||
'lddr': 'LDDR',
|
||||
'ldi': 'LDI',
|
||||
'ldir': 'LDIR',
|
||||
'neg': 'NEG',
|
||||
'nop': 'NOP',
|
||||
'or': 'OR',
|
||||
'otdr': 'OTDR',
|
||||
'otir': 'OTIR',
|
||||
'out': 'OUT',
|
||||
'outd': 'OUTD',
|
||||
'outi': 'OUTI',
|
||||
'pop': 'POP',
|
||||
'push': 'PUSH',
|
||||
'res': 'RES',
|
||||
'ret': 'RET',
|
||||
'reti': 'RETI',
|
||||
'retn': 'RETN',
|
||||
'rl': 'RL',
|
||||
'rla': 'RLA',
|
||||
'rlc': 'RLC',
|
||||
'rlca': 'RLCA',
|
||||
'rld': 'RLD',
|
||||
'rr': 'RR',
|
||||
'rra': 'RRA',
|
||||
'rrc': 'RRC',
|
||||
'rrca': 'RRCA',
|
||||
'rrd': 'RRD',
|
||||
'rst': 'RST',
|
||||
'sbc': 'SBC',
|
||||
'scf': 'SCF',
|
||||
'set': 'SET',
|
||||
'sla': 'SLA',
|
||||
'sll': 'SLL',
|
||||
'sra': 'SRA',
|
||||
'srl': 'SRL',
|
||||
'sub': 'SUB',
|
||||
'xor': 'XOR',
|
||||
}
|
||||
|
||||
|
||||
pseudo = { # pseudo ops
|
||||
'align': 'ALIGN',
|
||||
'org': 'ORG',
|
||||
'defb': 'DEFB',
|
||||
'defm': 'DEFB',
|
||||
'db' : 'DEFB',
|
||||
'defs': 'DEFS',
|
||||
'defw': 'DEFW',
|
||||
'ds' : 'DEFS',
|
||||
'dw' : 'DEFW',
|
||||
'equ': 'EQU',
|
||||
'proc': 'PROC',
|
||||
'endp': 'ENDP',
|
||||
'local': 'LOCAL',
|
||||
'end': 'END',
|
||||
'incbin': 'INCBIN'
|
||||
}
|
||||
|
||||
|
||||
regs8 = {'a': 'A',
|
||||
'b': 'B', 'c': 'C',
|
||||
'd': 'D', 'e': 'E',
|
||||
'h': 'H', 'l': 'L',
|
||||
'i': 'I', 'r': 'R',
|
||||
'ixh': 'IXH', 'ixl': 'IXL',
|
||||
'iyh': 'IYH', 'iyl': 'IYL'
|
||||
}
|
||||
|
||||
|
||||
regs16 = {
|
||||
'af': 'AF',
|
||||
'bc': 'BC',
|
||||
'de': 'DE',
|
||||
'hl': 'HL',
|
||||
'ix': 'IX',
|
||||
'iy': 'IY',
|
||||
'sp': 'SP'
|
||||
}
|
||||
|
||||
|
||||
flags = {
|
||||
'z' : 'Z',
|
||||
'nz' : 'NZ',
|
||||
'nc' : 'NC',
|
||||
'po' : 'PO',
|
||||
'pe' : 'PE',
|
||||
'p' : 'P',
|
||||
'm' : 'M',
|
||||
}
|
||||
|
||||
|
||||
preprocessor = {
|
||||
'init' : '_INIT',
|
||||
'line' : '_LINE'
|
||||
}
|
||||
|
||||
|
||||
|
||||
# List of token names.
|
||||
_tokens = _tokens \
|
||||
+ tuple(reserved_instructions.values()) \
|
||||
+ tuple(pseudo.values()) \
|
||||
+ tuple(regs8.values()) \
|
||||
+ tuple(regs16.values()) \
|
||||
+ tuple(flags.values()) \
|
||||
+ tuple(preprocessor.values())
|
||||
|
||||
|
||||
def get_uniques(l):
|
||||
''' Returns a list with no repeated elements.
|
||||
'''
|
||||
result = []
|
||||
|
||||
for i in l:
|
||||
if i not in result:
|
||||
result.append(i)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
tokens = get_uniques(_tokens)
|
||||
|
||||
|
||||
class Lexer(object):
|
||||
''' Own class lexer to allow multiple instances.
|
||||
This lexer is just a wrapper of the current FILESTACK[-1] lexer
|
||||
'''
|
||||
states = (
|
||||
('preproc', 'exclusive'),
|
||||
)
|
||||
|
||||
# -------------- TOKEN ACTIONS --------------
|
||||
|
||||
|
||||
def __set_lineno(self, value):
|
||||
''' Setter for lexer.lineno
|
||||
'''
|
||||
self.lex.lineno = value
|
||||
|
||||
|
||||
def __get_lineno(self):
|
||||
''' Getter for lexer.lineno
|
||||
'''
|
||||
if self.lex is None:
|
||||
return 0
|
||||
|
||||
return self.lex.lineno
|
||||
|
||||
lineno = property(__get_lineno, __set_lineno)
|
||||
|
||||
|
||||
def t_INITIAL_preproc_skip(self, t):
|
||||
r'[ \t]+'
|
||||
pass # Ignore whitespaces and tabs
|
||||
|
||||
|
||||
def t_CHAR(self, t):
|
||||
r"'.'" # A single char
|
||||
|
||||
t.value = ord(t.value[1])
|
||||
t.type = 'INTEGER'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_HEXA(self, t):
|
||||
r'([0-9][0-9a-fA-F]*[hH])|(\$[0-9a-fA-F]+)'
|
||||
|
||||
if t.value[0] == '$':
|
||||
t.value = t.value[1:] # Remove initial '$'
|
||||
else:
|
||||
t.value = t.value[:-1] # Remove last 'h'
|
||||
|
||||
t.value = int(t.value, 16) # Convert to decimal
|
||||
t.type = 'INTEGER'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_BIN(self, t):
|
||||
r'(%[01]+)|([01]+[bB])' # A Binary integer
|
||||
# Note 00B is a 0 binary, but
|
||||
# 00Bh is a 12 in hex. So this pattern must come
|
||||
# after HEXA
|
||||
|
||||
if t.value[0] == '%':
|
||||
t.value = t.value[1:] # Remove initial %
|
||||
else:
|
||||
t.value = t.value[:-1] # Remove last 'b'
|
||||
|
||||
t.value = int(t.value, 2) # Convert to decimal
|
||||
t.type = 'INTEGER'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_INITIAL_preproc_INTEGER(self, t):
|
||||
r'[0-9]+' # an integer decimal number
|
||||
|
||||
t.value = int(t.value)
|
||||
|
||||
return t
|
||||
|
||||
def t_INITIAL_ID(self, t):
|
||||
r'[_a-zA-Z.]([.]?[_a-zA-Z0-9\\@\#]+)*[:]?(\\\W)?' # Any identifier
|
||||
|
||||
tmp = t.value # Saves original value
|
||||
if tmp[-1] == ':':
|
||||
t.type = 'LABEL'
|
||||
t.value = tmp[:-1]
|
||||
return t
|
||||
if tmp[0] == "." and (tmp[-2:] == "\@" or tmp[-3:] == "\@:"):
|
||||
t.type = "LOCALLABEL"
|
||||
t.value = tmp[1:]
|
||||
return t
|
||||
|
||||
t.value = tmp.upper() # Convert it to uppercase, since our internal tables uses uppercase
|
||||
id = tmp.lower()
|
||||
|
||||
t.type = reserved_instructions.get(id)
|
||||
if t.type is not None: return t
|
||||
|
||||
t.type = pseudo.get(id)
|
||||
if t.type is not None: return t
|
||||
|
||||
t.type = regs8.get(id)
|
||||
if t.type is not None: return t
|
||||
|
||||
t.type = flags.get(id)
|
||||
if t.type is not None: return t
|
||||
|
||||
t.type = regs16.get(id, 'ID')
|
||||
if t.type == 'ID':
|
||||
t.value = tmp # Restores original value
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_preproc_ID(self, t):
|
||||
r'[_a-zA-Z][_a-zA-Z0-9]*' # preprocessor directives
|
||||
|
||||
t.type = preprocessor.get(t.value.lower(), 'ID')
|
||||
return t
|
||||
|
||||
|
||||
def t_COMMA(self, t):
|
||||
r','
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_ADDR(self, t):
|
||||
r'\$'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_LP(self, t):
|
||||
r'\('
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_RP(self, t):
|
||||
r'\)'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_RB(self, t):
|
||||
r'\['
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_LB(self, t):
|
||||
r'\]'
|
||||
return t
|
||||
|
||||
def t_LSHIFT(self, t):
|
||||
r'<<'
|
||||
return t
|
||||
def t_RSHIFT(self, t):
|
||||
r'>>'
|
||||
return t
|
||||
|
||||
def t_BITWISE_OR(self, t):
|
||||
r'\|'
|
||||
return t
|
||||
def t_BITWISE_AND(self, t):
|
||||
r'\&'
|
||||
return t
|
||||
def t_BITWISE_COMPLEMENT(self, t):
|
||||
r'~'
|
||||
return t
|
||||
def t_LOGICAL_NOT(self, t):
|
||||
r'\!'
|
||||
return t
|
||||
|
||||
def t_PLUS(self, t):
|
||||
r'\+'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_MINUS(self, t):
|
||||
r'\-'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_MUL(self, t):
|
||||
r'\*'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_DIV(self, t):
|
||||
r'\/'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_POW(self, t):
|
||||
r'\^'
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_APO(self, t):
|
||||
r"'"
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_INITIAL_preproc_STRING(self, t):
|
||||
r'"[^"]*"' # a doubled quoted string
|
||||
t.value = t.value[1:-1] # Remove quotes
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_INITIAL_preproc_error(self, t):
|
||||
''' error handling rule
|
||||
'''
|
||||
self.error("illegal character '%s'" % t.value[0])
|
||||
|
||||
|
||||
def t_INITIAL_preproc_CONTINUE(self, t):
|
||||
r'\\\r?\n'
|
||||
t.lexer.lineno += 1
|
||||
|
||||
# Allows line breaking
|
||||
|
||||
|
||||
def t_COMMENT(self, t):
|
||||
r';.*'
|
||||
|
||||
# Skip to end of line (except end of line)
|
||||
|
||||
|
||||
def t_INITIAL_preproc_NEWLINE(self, t):
|
||||
r'\r?\n'
|
||||
|
||||
t.lexer.lineno += 1
|
||||
t.lexer.begin('INITIAL')
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def t_INITIAL_SHARP(self, t):
|
||||
r'\#'
|
||||
|
||||
if self.find_column(t) == 1:
|
||||
t.lexer.begin('preproc')
|
||||
else:
|
||||
self.error("illegal character '%s'" % t.value[0])
|
||||
|
||||
|
||||
def __init__(self):
|
||||
''' Creates a new GLOBAL lexer instance
|
||||
'''
|
||||
self.lex = None
|
||||
self.filestack = [] # Current filename, and line number being parsed
|
||||
self.input_data = ''
|
||||
self.tokens = tokens
|
||||
self.next_token = None # if set to something, this will be returned once
|
||||
|
||||
|
||||
def input(self, str):
|
||||
''' Defines input string, removing current lexer.
|
||||
'''
|
||||
self.input_data = str
|
||||
self.lex = lex.lex(object = self)
|
||||
self.lex.input(self.input_data)
|
||||
|
||||
|
||||
def token(self):
|
||||
return self.lex.token()
|
||||
|
||||
|
||||
def find_column(self, token):
|
||||
''' Compute column:
|
||||
- token is a token instance
|
||||
'''
|
||||
i = token.lexpos
|
||||
while i > 0:
|
||||
if self.input_data[i - 1] == '\n': break
|
||||
i -= 1
|
||||
|
||||
column = token.lexpos - i + 1
|
||||
|
||||
return column
|
||||
|
||||
|
||||
def msg(self, str):
|
||||
''' Prints an error msg.
|
||||
'''
|
||||
#print '%s:%i %s' % (FILENAME, self.lex.lineno, str)
|
||||
print '%s:%s %s' % (FILENAME, "?", str)
|
||||
|
||||
|
||||
def error(self, str):
|
||||
''' Prints an error msg, and exits.
|
||||
'''
|
||||
self.msg('Error: %s' % str)
|
||||
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def warning(self, str):
|
||||
''' Emmits a warning and continue execution.
|
||||
'''
|
||||
self.msg('Warning: %s' % str)
|
||||
|
||||
# Needed for states
|
||||
tmp = lex.lex(object = Lexer(), lextab = 'zxbasmlextab')
|
||||
|
||||
if __name__ == '__main__':
|
||||
FILENAME = sys.argv[1]
|
||||
tmp.input(open(sys.argv[1]).read())
|
||||
tok = tmp.token()
|
||||
while tok:
|
||||
print tok
|
||||
tok = tmp.token()
|
312
extras/pksv.py
312
extras/pksv.py
@ -1,312 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
pksv_gs = {
|
||||
0x00: "2call",
|
||||
0x01: "3call",
|
||||
0x02: "2ptcall",
|
||||
0x03: "2jump",
|
||||
0x04: "3jump",
|
||||
0x05: "2ptjump",
|
||||
0x06: "if equal",
|
||||
0x07: "if not equal",
|
||||
0x08: "if false",
|
||||
0x09: "if true",
|
||||
0x0A: "if less than",
|
||||
0x0B: "if greater than",
|
||||
0x0C: "jumpstd",
|
||||
0x0D: "callstd",
|
||||
0x0E: "3callasm",
|
||||
0x0F: "special",
|
||||
0x10: "2ptcallasm",
|
||||
0x11: "checkmaptriggers",
|
||||
0x12: "domaptrigger",
|
||||
0x13: "checktriggers",
|
||||
0x14: "dotrigger",
|
||||
0x15: "writebyte",
|
||||
0x16: "addvar",
|
||||
0x17: "random",
|
||||
0x19: "copybytetovar",
|
||||
0x1A: "copyvartobyte",
|
||||
0x1B: "loadvar",
|
||||
0x1C: "checkcode",
|
||||
0x1E: "writecode",
|
||||
0x1F: "giveitem",
|
||||
0x20: "takeitem",
|
||||
0x21: "checkitem",
|
||||
0x22: "givemoney",
|
||||
0x23: "takemoney",
|
||||
0x24: "checkmoney",
|
||||
0x25: "givecoins",
|
||||
0x26: "takecoins",
|
||||
0x27: "checkcoins",
|
||||
0x2B: "checktime",
|
||||
0x2C: "checkpoke",
|
||||
0x2D: "givepoke",
|
||||
0x2E: "giveegg",
|
||||
0x2F: "givepokeitem",
|
||||
0x31: "checkbit1",
|
||||
0x32: "clearbit1",
|
||||
0x33: "setbit1",
|
||||
0x34: "checkbit2",
|
||||
0x35: "clearbit2",
|
||||
0x36: "setbit2",
|
||||
0x37: "wildoff",
|
||||
0x38: "wildon",
|
||||
0x39: "xycompare",
|
||||
0x3A: "warpmod",
|
||||
0x3B: "blackoutmod",
|
||||
0x3C: "warp",
|
||||
0x41: "itemtotext",
|
||||
0x43: "trainertotext",
|
||||
0x44: "stringtotext",
|
||||
0x45: "itemnotify",
|
||||
0x46: "pocketisfull",
|
||||
0x47: "loadfont",
|
||||
0x48: "refreshscreen",
|
||||
0x49: "loadmovesprites",
|
||||
0x4B: "3writetext",
|
||||
0x4C: "2writetext",
|
||||
0x4E: "yesorno",
|
||||
0x4F: "loadmenudata",
|
||||
0x50: "writebackup",
|
||||
0x51: "jumptextfaceplayer",
|
||||
0x52: "jumptext",
|
||||
0x53: "closetext",
|
||||
0x54: "keeptextopen",
|
||||
0x55: "pokepic",
|
||||
0x56: "pokepicyesorno",
|
||||
0x57: "interpretmenu",
|
||||
0x58: "interpretmenu2",
|
||||
0x5C: "loadpokedata",
|
||||
0x5D: "loadtrainer",
|
||||
0x5E: "startbattle",
|
||||
0x5F: "returnafterbattle",
|
||||
0x60: "catchtutorial",
|
||||
0x63: "winlosstext",
|
||||
0x65: "talkaftercancel",
|
||||
0x67: "setlasttalked",
|
||||
0x68: "applymovement",
|
||||
0x6A: "faceplayer",
|
||||
0x6B: "faceperson",
|
||||
0x6C: "variablesprite",
|
||||
0x6D: "disappear",
|
||||
0x6E: "appear",
|
||||
0x6F: "follow",
|
||||
0x70: "stopfollow",
|
||||
0x71: "moveperson",
|
||||
0x74: "showemote",
|
||||
0x75: "spriteface",
|
||||
0x76: "follownotexact",
|
||||
0x77: "earthquake",
|
||||
0x79: "changeblock",
|
||||
0x7A: "reloadmap",
|
||||
0x7B: "reloadmappart",
|
||||
0x7C: "writecmdqueue",
|
||||
0x7D: "delcmdqueue",
|
||||
0x7E: "playmusic",
|
||||
0x7F: "playrammusic",
|
||||
0x80: "musicfadeout",
|
||||
0x81: "playmapmusic",
|
||||
0x82: "reloadmapmusic",
|
||||
0x83: "cry",
|
||||
0x84: "playsound",
|
||||
0x85: "waitbutton",
|
||||
0x86: "warpsound",
|
||||
0x87: "specialsound",
|
||||
0x88: "passtoengine",
|
||||
0x89: "newloadmap",
|
||||
0x8A: "pause",
|
||||
0x8B: "deactivatefacing",
|
||||
0x8C: "priorityjump",
|
||||
0x8D: "warpcheck",
|
||||
0x8E: "ptpriorityjump",
|
||||
0x8F: "return",
|
||||
0x90: "end",
|
||||
0x91: "reloadandreturn",
|
||||
0x92: "resetfuncs",
|
||||
0x93: "pokemart",
|
||||
0x94: "elevator",
|
||||
0x95: "trade",
|
||||
0x96: "askforphonenumber",
|
||||
0x97: "phonecall",
|
||||
0x98: "hangup",
|
||||
0x99: "describedecoration",
|
||||
0x9A: "fruittree",
|
||||
0x9C: "checkphonecall",
|
||||
0x9D: "verbosegiveitem",
|
||||
0x9E: "loadwilddata",
|
||||
0x9F: "halloffame",
|
||||
0xA0: "credits",
|
||||
0xA1: "warpfacing",
|
||||
0xA2: "storetext",
|
||||
0xA3: "displaylocation",
|
||||
}
|
||||
|
||||
# see http://www.pokecommunity.com/showpost.php?p=4347261
|
||||
# NOTE: this has some updates that need to be back-ported to gold
|
||||
pksv_crystal = {
|
||||
0x00: "2call",
|
||||
0x01: "3call",
|
||||
0x02: "2ptcall",
|
||||
0x03: "2jump",
|
||||
0x04: "3jump",
|
||||
0x05: "2ptjump",
|
||||
0x06: "if equal",
|
||||
0x07: "if not equal",
|
||||
0x08: "if false",
|
||||
0x09: "if true",
|
||||
0x0A: "if less than",
|
||||
0x0B: "if greater than",
|
||||
0x0C: "jumpstd",
|
||||
0x0D: "callstd",
|
||||
0x0E: "3callasm",
|
||||
0x0F: "special",
|
||||
0x10: "2ptcallasm",
|
||||
0x11: "checkmaptriggers",
|
||||
0x12: "domaptrigger",
|
||||
0x13: "checktriggers",
|
||||
0x14: "dotrigger",
|
||||
0x15: "writebyte",
|
||||
0x16: "addvar",
|
||||
0x17: "random",
|
||||
0x19: "copybytetovar",
|
||||
0x1A: "copyvartobyte",
|
||||
0x1B: "loadvar",
|
||||
0x1C: "checkcode",
|
||||
0x1D: "writevarcode",
|
||||
0x1E: "writecode",
|
||||
0x1F: "giveitem",
|
||||
0x20: "takeitem",
|
||||
0x21: "checkitem",
|
||||
0x22: "givemoney",
|
||||
0x23: "takemoney",
|
||||
0x24: "checkmoney",
|
||||
0x25: "givecoins",
|
||||
0x26: "takecoins",
|
||||
0x27: "checkcoins",
|
||||
0x28: "addcellnum",
|
||||
0x29: "delcellnum",
|
||||
0x2B: "checktime",
|
||||
0x2C: "checkpoke",
|
||||
0x2D: "givepoke",
|
||||
0x2E: "giveegg",
|
||||
0x2F: "givepokeitem",
|
||||
0x31: "checkbit1",
|
||||
0x32: "clearbit1",
|
||||
0x33: "setbit1",
|
||||
0x34: "checkbit2",
|
||||
0x35: "clearbit2",
|
||||
0x36: "setbit2",
|
||||
0x37: "wildoff",
|
||||
0x38: "wildon",
|
||||
0x39: "xycompare",
|
||||
0x3A: "warpmod",
|
||||
0x3B: "blackoutmod",
|
||||
0x3C: "warp",
|
||||
0x41: "itemtotext",
|
||||
0x43: "trainertotext",
|
||||
0x44: "stringtotext",
|
||||
0x45: "itemnotify",
|
||||
0x46: "pocketisfull",
|
||||
0x47: "loadfont",
|
||||
0x48: "refreshscreen",
|
||||
0x49: "loadmovesprites",
|
||||
0x4B: "3writetext",
|
||||
0x4C: "2writetext",
|
||||
0x4E: "yesorno",
|
||||
0x4F: "loadmenudata",
|
||||
0x50: "writebackup",
|
||||
0x51: "jumptextfaceplayer",
|
||||
0x53: "jumptext",
|
||||
0x54: "closetext",
|
||||
0x55: "keeptextopen",
|
||||
0x56: "pokepic",
|
||||
0x57: "pokepicyesorno",
|
||||
0x58: "interpretmenu",
|
||||
0x59: "interpretmenu2",
|
||||
0x5D: "loadpokedata",
|
||||
0x5E: "loadtrainer",
|
||||
0x5F: "startbattle",
|
||||
0x60: "returnafterbattle",
|
||||
0x61: "catchtutorial",
|
||||
0x64: "winlosstext",
|
||||
0x66: "talkaftercancel",
|
||||
0x68: "setlasttalked",
|
||||
0x69: "applymovement",
|
||||
0x6B: "faceplayer",
|
||||
0x6C: "faceperson",
|
||||
0x6D: "variablesprite",
|
||||
0x6E: "disappear",
|
||||
0x6F: "appear",
|
||||
0x70: "follow",
|
||||
0x71: "stopfollow",
|
||||
0x72: "moveperson",
|
||||
0x75: "showemote",
|
||||
0x76: "spriteface",
|
||||
0x77: "follownotexact",
|
||||
0x78: "earthquake",
|
||||
0x7A: "changeblock",
|
||||
0x7B: "reloadmap",
|
||||
0x7C: "reloadmappart",
|
||||
0x7D: "writecmdqueue",
|
||||
0x7E: "delcmdqueue",
|
||||
0x7F: "playmusic",
|
||||
0x80: "playrammusic",
|
||||
0x81: "musicfadeout",
|
||||
0x82: "playmapmusic",
|
||||
0x83: "reloadmapmusic",
|
||||
0x84: "cry",
|
||||
0x85: "playsound",
|
||||
0x86: "waitbutton",
|
||||
0x87: "warpsound",
|
||||
0x88: "specialsound",
|
||||
0x89: "passtoengine",
|
||||
0x8A: "newloadmap",
|
||||
0x8B: "pause",
|
||||
0x8C: "deactivatefacing",
|
||||
0x8D: "priorityjump",
|
||||
0x8E: "warpcheck",
|
||||
0x8F: "ptpriorityjump",
|
||||
0x90: "return",
|
||||
0x91: "end",
|
||||
0x92: "reloadandreturn",
|
||||
0x93: "resetfuncs",
|
||||
0x94: "pokemart",
|
||||
0x95: "elevator",
|
||||
0x96: "trade",
|
||||
0x97: "askforphonenumber",
|
||||
0x98: "phonecall",
|
||||
0x99: "hangup",
|
||||
0x9A: "describedecoration",
|
||||
0x9B: "fruittree",
|
||||
0x9C: "specialphonecall",
|
||||
0x9D: "checkphonecall",
|
||||
0x9E: "verbosegiveitem",
|
||||
0x9F: "verbosegiveitem2",
|
||||
0xA0: "loadwilddata",
|
||||
0xA1: "halloffame",
|
||||
0xA2: "credits",
|
||||
0xA3: "warpfacing",
|
||||
0xA4: "storetext",
|
||||
0xA5: "displaylocation",
|
||||
0xB2: "unknown0xb2",
|
||||
}
|
||||
|
||||
#these cause the script to end; used in create_command_classes
|
||||
pksv_crystal_more_enders = [0x03, 0x04, 0x05, 0x0C, 0x51, 0x52, 0x53,
|
||||
0x65, 0x8D, 0x8F, 0x90, 0x91, 0x92, 0x9B,
|
||||
0x9A, # describedecoration
|
||||
]
|
||||
|
||||
# these have no pksv names as of pksv 2.1.1
|
||||
pksv_crystal_unknowns = [
|
||||
0x9F,
|
||||
0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8,
|
||||
0xCC, 0xCD,
|
||||
0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
|
||||
0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
|
||||
0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
|
||||
]
|
||||
|
@ -1,25 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Various functions related to pointer and address math. Mostly to avoid
|
||||
depedency loops.
|
||||
"""
|
||||
|
||||
def calculate_bank(address):
|
||||
"""you are too lazy to divide on your own?"""
|
||||
if type(address) == str:
|
||||
address = int(address, 16)
|
||||
#if 0x4000 <= address <= 0x7FFF:
|
||||
# raise Exception, "bank 1 does not exist"
|
||||
return int(address) / 0x4000
|
||||
|
||||
def calculate_pointer(short_pointer, bank=None):
|
||||
"""calculates the full address given a 4-byte pointer and bank byte"""
|
||||
short_pointer = int(short_pointer)
|
||||
if 0x4000 <= short_pointer <= 0x7fff:
|
||||
short_pointer -= 0x4000
|
||||
bank = int(bank)
|
||||
else:
|
||||
bank = 0
|
||||
pointer = short_pointer + (bank * 0x4000)
|
||||
return pointer
|
||||
|
@ -1,255 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
pokemon_constants = {
|
||||
1: "BULBASAUR",
|
||||
2: "IVYSAUR",
|
||||
3: "VENUSAUR",
|
||||
4: "CHARMANDER",
|
||||
5: "CHARMELEON",
|
||||
6: "CHARIZARD",
|
||||
7: "SQUIRTLE",
|
||||
8: "WARTORTLE",
|
||||
9: "BLASTOISE",
|
||||
10: "CATERPIE",
|
||||
11: "METAPOD",
|
||||
12: "BUTTERFREE",
|
||||
13: "WEEDLE",
|
||||
14: "KAKUNA",
|
||||
15: "BEEDRILL",
|
||||
16: "PIDGEY",
|
||||
17: "PIDGEOTTO",
|
||||
18: "PIDGEOT",
|
||||
19: "RATTATA",
|
||||
20: "RATICATE",
|
||||
21: "SPEAROW",
|
||||
22: "FEAROW",
|
||||
23: "EKANS",
|
||||
24: "ARBOK",
|
||||
25: "PIKACHU",
|
||||
26: "RAICHU",
|
||||
27: "SANDSHREW",
|
||||
28: "SANDSLASH",
|
||||
29: "NIDORAN_F",
|
||||
30: "NIDORINA",
|
||||
31: "NIDOQUEEN",
|
||||
32: "NIDORAN_M",
|
||||
33: "NIDORINO",
|
||||
34: "NIDOKING",
|
||||
35: "CLEFAIRY",
|
||||
36: "CLEFABLE",
|
||||
37: "VULPIX",
|
||||
38: "NINETALES",
|
||||
39: "JIGGLYPUFF",
|
||||
40: "WIGGLYTUFF",
|
||||
41: "ZUBAT",
|
||||
42: "GOLBAT",
|
||||
43: "ODDISH",
|
||||
44: "GLOOM",
|
||||
45: "VILEPLUME",
|
||||
46: "PARAS",
|
||||
47: "PARASECT",
|
||||
48: "VENONAT",
|
||||
49: "VENOMOTH",
|
||||
50: "DIGLETT",
|
||||
51: "DUGTRIO",
|
||||
52: "MEOWTH",
|
||||
53: "PERSIAN",
|
||||
54: "PSYDUCK",
|
||||
55: "GOLDUCK",
|
||||
56: "MANKEY",
|
||||
57: "PRIMEAPE",
|
||||
58: "GROWLITHE",
|
||||
59: "ARCANINE",
|
||||
60: "POLIWAG",
|
||||
61: "POLIWHIRL",
|
||||
62: "POLIWRATH",
|
||||
63: "ABRA",
|
||||
64: "KADABRA",
|
||||
65: "ALAKAZAM",
|
||||
66: "MACHOP",
|
||||
67: "MACHOKE",
|
||||
68: "MACHAMP",
|
||||
69: "BELLSPROUT",
|
||||
70: "WEEPINBELL",
|
||||
71: "VICTREEBEL",
|
||||
72: "TENTACOOL",
|
||||
73: "TENTACRUEL",
|
||||
74: "GEODUDE",
|
||||
75: "GRAVELER",
|
||||
76: "GOLEM",
|
||||
77: "PONYTA",
|
||||
78: "RAPIDASH",
|
||||
79: "SLOWPOKE",
|
||||
80: "SLOWBRO",
|
||||
81: "MAGNEMITE",
|
||||
82: "MAGNETON",
|
||||
83: "FARFETCH_D",
|
||||
84: "DODUO",
|
||||
85: "DODRIO",
|
||||
86: "SEEL",
|
||||
87: "DEWGONG",
|
||||
88: "GRIMER",
|
||||
89: "MUK",
|
||||
90: "SHELLDER",
|
||||
91: "CLOYSTER",
|
||||
92: "GASTLY",
|
||||
93: "HAUNTER",
|
||||
94: "GENGAR",
|
||||
95: "ONIX",
|
||||
96: "DROWZEE",
|
||||
97: "HYPNO",
|
||||
98: "KRABBY",
|
||||
99: "KINGLER",
|
||||
100: "VOLTORB",
|
||||
101: "ELECTRODE",
|
||||
102: "EXEGGCUTE",
|
||||
103: "EXEGGUTOR",
|
||||
104: "CUBONE",
|
||||
105: "MAROWAK",
|
||||
106: "HITMONLEE",
|
||||
107: "HITMONCHAN",
|
||||
108: "LICKITUNG",
|
||||
109: "KOFFING",
|
||||
110: "WEEZING",
|
||||
111: "RHYHORN",
|
||||
112: "RHYDON",
|
||||
113: "CHANSEY",
|
||||
114: "TANGELA",
|
||||
115: "KANGASKHAN",
|
||||
116: "HORSEA",
|
||||
117: "SEADRA",
|
||||
118: "GOLDEEN",
|
||||
119: "SEAKING",
|
||||
120: "STARYU",
|
||||
121: "STARMIE",
|
||||
122: "MR__MIME",
|
||||
123: "SCYTHER",
|
||||
124: "JYNX",
|
||||
125: "ELECTABUZZ",
|
||||
126: "MAGMAR",
|
||||
127: "PINSIR",
|
||||
128: "TAUROS",
|
||||
129: "MAGIKARP",
|
||||
130: "GYARADOS",
|
||||
131: "LAPRAS",
|
||||
132: "DITTO",
|
||||
133: "EEVEE",
|
||||
134: "VAPOREON",
|
||||
135: "JOLTEON",
|
||||
136: "FLAREON",
|
||||
137: "PORYGON",
|
||||
138: "OMANYTE",
|
||||
139: "OMASTAR",
|
||||
140: "KABUTO",
|
||||
141: "KABUTOPS",
|
||||
142: "AERODACTYL",
|
||||
143: "SNORLAX",
|
||||
144: "ARTICUNO",
|
||||
145: "ZAPDOS",
|
||||
146: "MOLTRES",
|
||||
147: "DRATINI",
|
||||
148: "DRAGONAIR",
|
||||
149: "DRAGONITE",
|
||||
150: "MEWTWO",
|
||||
151: "MEW",
|
||||
152: "CHIKORITA",
|
||||
153: "BAYLEEF",
|
||||
154: "MEGANIUM",
|
||||
155: "CYNDAQUIL",
|
||||
156: "QUILAVA",
|
||||
157: "TYPHLOSION",
|
||||
158: "TOTODILE",
|
||||
159: "CROCONAW",
|
||||
160: "FERALIGATR",
|
||||
161: "SENTRET",
|
||||
162: "FURRET",
|
||||
163: "HOOTHOOT",
|
||||
164: "NOCTOWL",
|
||||
165: "LEDYBA",
|
||||
166: "LEDIAN",
|
||||
167: "SPINARAK",
|
||||
168: "ARIADOS",
|
||||
169: "CROBAT",
|
||||
170: "CHINCHOU",
|
||||
171: "LANTURN",
|
||||
172: "PICHU",
|
||||
173: "CLEFFA",
|
||||
174: "IGGLYBUFF",
|
||||
175: "TOGEPI",
|
||||
176: "TOGETIC",
|
||||
177: "NATU",
|
||||
178: "XATU",
|
||||
179: "MAREEP",
|
||||
180: "FLAAFFY",
|
||||
181: "AMPHAROS",
|
||||
182: "BELLOSSOM",
|
||||
183: "MARILL",
|
||||
184: "AZUMARILL",
|
||||
185: "SUDOWOODO",
|
||||
186: "POLITOED",
|
||||
187: "HOPPIP",
|
||||
188: "SKIPLOOM",
|
||||
189: "JUMPLUFF",
|
||||
190: "AIPOM",
|
||||
191: "SUNKERN",
|
||||
192: "SUNFLORA",
|
||||
193: "YANMA",
|
||||
194: "WOOPER",
|
||||
195: "QUAGSIRE",
|
||||
196: "ESPEON",
|
||||
197: "UMBREON",
|
||||
198: "MURKROW",
|
||||
199: "SLOWKING",
|
||||
200: "MISDREAVUS",
|
||||
201: "UNOWN",
|
||||
202: "WOBBUFFET",
|
||||
203: "GIRAFARIG",
|
||||
204: "PINECO",
|
||||
205: "FORRETRESS",
|
||||
206: "DUNSPARCE",
|
||||
207: "GLIGAR",
|
||||
208: "STEELIX",
|
||||
209: "SNUBBULL",
|
||||
210: "GRANBULL",
|
||||
211: "QWILFISH",
|
||||
212: "SCIZOR",
|
||||
213: "SHUCKLE",
|
||||
214: "HERACROSS",
|
||||
215: "SNEASEL",
|
||||
216: "TEDDIURSA",
|
||||
217: "URSARING",
|
||||
218: "SLUGMA",
|
||||
219: "MAGCARGO",
|
||||
220: "SWINUB",
|
||||
221: "PILOSWINE",
|
||||
222: "CORSOLA",
|
||||
223: "REMORAID",
|
||||
224: "OCTILLERY",
|
||||
225: "DELIBIRD",
|
||||
226: "MANTINE",
|
||||
227: "SKARMORY",
|
||||
228: "HOUNDOUR",
|
||||
229: "HOUNDOOM",
|
||||
230: "KINGDRA",
|
||||
231: "PHANPY",
|
||||
232: "DONPHAN",
|
||||
233: "PORYGON2",
|
||||
234: "STANTLER",
|
||||
235: "SMEARGLE",
|
||||
236: "TYROGUE",
|
||||
237: "HITMONTOP",
|
||||
238: "SMOOCHUM",
|
||||
239: "ELEKID",
|
||||
240: "MAGBY",
|
||||
241: "MILTANK",
|
||||
242: "BLISSEY",
|
||||
243: "RAIKOU",
|
||||
244: "ENTEI",
|
||||
245: "SUICUNE",
|
||||
246: "LARVITAR",
|
||||
247: "PUPITAR",
|
||||
248: "TYRANITAR",
|
||||
249: "LUGIA",
|
||||
250: "HO_OH",
|
||||
251: "CELEBI",
|
||||
}
|
219
extras/romstr.py
219
extras/romstr.py
@ -1,219 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import datetime
|
||||
from ctypes import c_int8
|
||||
from copy import copy
|
||||
import json
|
||||
|
||||
# New versions of json don't have read anymore.
|
||||
if not hasattr(json, "read"):
|
||||
json.read = json.loads
|
||||
|
||||
from labels import (
|
||||
get_label_from_line,
|
||||
get_address_from_line_comment,
|
||||
)
|
||||
|
||||
relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18, 0xc3, 0xda, 0xc2, 0x32]
|
||||
relative_unconditional_jumps = [0xc3, 0x18]
|
||||
call_commands = [0xdc, 0xd4, 0xc4, 0xcc, 0xcd]
|
||||
end_08_scripts_with = [
|
||||
0xe9, # jp hl
|
||||
0xc9, # ret
|
||||
] # possibly also:
|
||||
# 0xc3, # jp
|
||||
# 0xc18, # jr
|
||||
# 0xda, 0xe9, 0xd2, 0xc2, 0xca, 0x38, 0x30, 0x20, 0x28, 0x18, 0xd8,
|
||||
# 0xd0, 0xc0, 0xc8, 0xc9
|
||||
|
||||
spacing = "\t"
|
||||
|
||||
class RomStr(str):
|
||||
"""
|
||||
Simple wrapper to prevent a giant rom from being shown on screen.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if "labels" in kwargs.keys() and kwargs["labels"] == True:
|
||||
self.load_labels()
|
||||
str.__init__(self)
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
Simplifies this object so that the output doesn't overflow stdout.
|
||||
"""
|
||||
return "RomStr(too long)"
|
||||
|
||||
@classmethod
|
||||
def load(cls, filename=None, crystal=True, red=False):
|
||||
"""
|
||||
Load a ROM into a RomStr.
|
||||
"""
|
||||
if crystal and not red and not filename:
|
||||
file_handler = open("../baserom.gbc", "r")
|
||||
elif red and not crystal and not filename:
|
||||
file_handler = open("../pokered-baserom.gbc", "r")
|
||||
elif filename not in ["", None]:
|
||||
file_handler = open(filename, "rb")
|
||||
else:
|
||||
raise Exception("not sure which rom to load?")
|
||||
bytes = file_handler.read()
|
||||
file_handler.close()
|
||||
return RomStr(bytes)
|
||||
|
||||
def load_labels(self, filename="labels.json"):
|
||||
"""
|
||||
Loads labels from labels.json.
|
||||
|
||||
(Or parses the source code file and
|
||||
generates new labels.)
|
||||
"""
|
||||
filename = os.path.join(os.path.dirname(__file__), filename)
|
||||
|
||||
# blank out the hash
|
||||
self.labels = {}
|
||||
|
||||
# check if the labels file exists
|
||||
file_existence = os.path.exists(filename)
|
||||
|
||||
generate_labels = False
|
||||
|
||||
# determine if the labels file needs to be regenerated
|
||||
if file_existence:
|
||||
modified = os.path.getmtime(filename)
|
||||
modified = datetime.datetime.fromtimestamp(modified)
|
||||
current = datetime.datetime.fromtimestamp(time.time())
|
||||
|
||||
is_old = (current - modified) > datetime.timedelta(days=3)
|
||||
|
||||
if is_old:
|
||||
generate_labels = True
|
||||
else:
|
||||
generate_labels = True
|
||||
|
||||
# scan the asm source code for labels
|
||||
if generate_labels:
|
||||
asm = open(os.path.join(os.path.dirname(__file__), "../main.asm"), "r").read().split("\n")
|
||||
|
||||
for line in asm:
|
||||
label = get_label_from_line(line)
|
||||
|
||||
if label:
|
||||
address = get_address_from_line_comment(line)
|
||||
|
||||
self.labels[address] = label
|
||||
|
||||
content = json.dumps(self.labels)
|
||||
file_handler = open(filename, "w")
|
||||
file_handler.write(content)
|
||||
file_handler.close()
|
||||
|
||||
# load the labels from the file
|
||||
self.labels = json.read(open(filename, "r").read())
|
||||
|
||||
def get_address_for(self, label):
|
||||
"""
|
||||
Return the address of a label.
|
||||
|
||||
This is slow and could be improved dramatically.
|
||||
"""
|
||||
label = str(label)
|
||||
for address in self.labels.keys():
|
||||
if self.labels[address] == label:
|
||||
return address
|
||||
return None
|
||||
|
||||
def length(self):
|
||||
"""
|
||||
len(self)
|
||||
"""
|
||||
return len(self)
|
||||
|
||||
def len(self):
|
||||
"""
|
||||
len(self)
|
||||
"""
|
||||
return self.length()
|
||||
|
||||
def interval(self, offset, length, strings=True, debug=True):
|
||||
"""
|
||||
Return hex values for the rom starting at offset until offset+length.
|
||||
"""
|
||||
returnable = []
|
||||
for byte in self[offset:offset+length]:
|
||||
if strings:
|
||||
returnable.append(hex(ord(byte)))
|
||||
else:
|
||||
returnable.append(ord(byte))
|
||||
return returnable
|
||||
|
||||
def until(self, offset, byte, strings=True, debug=False):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
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)
|
||||
|
||||
start_address = address
|
||||
|
||||
if start_address == None:
|
||||
raise Exception, "address must be given"
|
||||
|
||||
if debug == None:
|
||||
if not hasattr(self, "debug"):
|
||||
debug = False
|
||||
else:
|
||||
debug = self.debug
|
||||
|
||||
# this is probably a terrible idea.. why am i doing this?
|
||||
if size != None and max_size < size:
|
||||
raise Exception, "max_size must be greater than or equal to size"
|
||||
elif end_address != None and (end_address - start_address) > max_size:
|
||||
raise Exception, "end_address is out of bounds"
|
||||
elif end_address != None and size != None:
|
||||
if (end_address - start_address) >= size:
|
||||
size = end_address - start_address
|
||||
else:
|
||||
end_address = start_address + size
|
||||
elif end_address == None and size != None:
|
||||
end_address = start_address + size
|
||||
elif end_address != None and size == None:
|
||||
size = end_address - start_address
|
||||
|
||||
raise NotImplementedError("DisAsm was removed and never worked; hook up another disassembler please.")
|
||||
#return DisAsm(start_address=start_address, end_address=end_address, size=size, max_size=max_size, debug=debug, rom=self)
|
||||
|
||||
class AsmList(list):
|
||||
"""
|
||||
Simple wrapper to prevent all asm lines from being shown on screen.
|
||||
"""
|
||||
|
||||
def length(self):
|
||||
"""
|
||||
len(self)
|
||||
"""
|
||||
return len(self)
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
Simplifies this object so that the output doesn't overflow stdout.
|
||||
"""
|
||||
return "AsmList(too long)"
|
||||
|
||||
if __name__ == "__main__":
|
||||
cryrom = RomStr(open("../pokecrystal.gbc", "r").read());
|
||||
asm = cryrom.to_asm(sys.argv[1])
|
||||
print asm
|
100
extras/sym.py
100
extras/sym.py
@ -1,100 +0,0 @@
|
||||
# coding: utf-8
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
|
||||
|
||||
def make_sym_from_json(filename = '../pokecrystal.sym', j = 'labels.json'):
|
||||
output = ''
|
||||
labels = json.load(open(j))
|
||||
for label in labels:
|
||||
output += '{0:x}:{1:x} {2}\n'.format(label['bank'], label['address'], label['label'])
|
||||
with open(filename, 'w') as sym:
|
||||
sym.write(output)
|
||||
|
||||
|
||||
def make_json_from_mapfile(filename = 'labels.json', mapfile = '../pokecrystal.map'):
|
||||
output = []
|
||||
labels = filter_wram_addresses(read_mapfile(mapfile))
|
||||
with open(filename, 'w') as out:
|
||||
out.write(json.dumps(labels))
|
||||
|
||||
|
||||
def read_mapfile(filename = '../pokecrystal.map'):
|
||||
"""
|
||||
Scrape label addresses from an rgbds mapfile.
|
||||
"""
|
||||
|
||||
labels = []
|
||||
|
||||
with open(filename,'r') as map:
|
||||
lines = map.readlines()
|
||||
|
||||
for line in lines:
|
||||
# bank #
|
||||
if 'Bank #' in line:
|
||||
cur_bank = int(line.lstrip('Bank #').strip(':\n').strip(' (HOME)'))
|
||||
|
||||
# label definition
|
||||
elif '=' in line:
|
||||
address, label = line.split('=')
|
||||
address = int(address.lstrip().replace('$','0x'), 16)
|
||||
label = label.strip()
|
||||
|
||||
# rgbds doesn't support ram banks yet
|
||||
bank = cur_bank
|
||||
offset = address
|
||||
if 0x8000 <= address < 0xa000:
|
||||
bank = 0
|
||||
elif 0xa000 <= address < 0xc000:
|
||||
bank = 0
|
||||
elif 0xc000 <= address < 0xd000:
|
||||
bank = 0
|
||||
elif 0xd000 <= address < 0xe000:
|
||||
bank = 0
|
||||
else:
|
||||
offset += (bank * 0x4000 - 0x4000) if bank > 0 else 0
|
||||
|
||||
labels += [{
|
||||
'label': label,
|
||||
'bank': bank,
|
||||
'address': offset,
|
||||
'offset': offset,
|
||||
'local_address': address,
|
||||
}]
|
||||
|
||||
return labels
|
||||
|
||||
def filter_wram_addresses(labels):
|
||||
filtered_labels = []
|
||||
for label in labels:
|
||||
if label['local_address'] < 0x8000:
|
||||
filtered_labels += [label]
|
||||
return filtered_labels
|
||||
|
||||
|
||||
def make_sym_from_mapfile(filename = '../pokecrystal.sym'):
|
||||
# todo: sort label definitions by address
|
||||
|
||||
output = ''
|
||||
labels = read_mapfile()
|
||||
|
||||
# convert to sym format (bank:addr label)
|
||||
for label in labels:
|
||||
output += '%.2x:%.4x %s\n' % (label['bank'], label['address'], label['label'])
|
||||
|
||||
# dump contents to symfile
|
||||
with open(filename, 'w') as sym:
|
||||
sym.write(output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#if os.path.exists('../pokecrystal.sym'):
|
||||
# sys.exit()
|
||||
#elif os.path.exists('../pokecrystal.map'):
|
||||
# make_sym_from_mapfile()
|
||||
#elif os.path.exists('labels.json'):
|
||||
# make_sym_from_json()
|
||||
make_json_from_mapfile()
|
||||
|
@ -1,74 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
# check for things we need in unittest
|
||||
if not hasattr(unittest.TestCase, 'setUpClass'):
|
||||
sys.stderr.write("The unittest2 module or Python 2.7 is required to run this script.")
|
||||
sys.exit(1)
|
||||
|
||||
from dump_sections import (
|
||||
upper_hex,
|
||||
format_bank_number,
|
||||
calculate_bank_quantity,
|
||||
dump_section,
|
||||
dump_incbin_for_section,
|
||||
)
|
||||
|
||||
class TestDumpSections(unittest.TestCase):
|
||||
def test_upper_hex(self):
|
||||
number = 0x52
|
||||
self.assertEquals(number, int("0x" + upper_hex(number), 16))
|
||||
|
||||
number = 0x1
|
||||
self.assertEquals(number, int("0x" + upper_hex(number), 16))
|
||||
|
||||
number = 0x0
|
||||
self.assertEquals(number, int("0x" + upper_hex(number), 16))
|
||||
|
||||
number = 0xAA
|
||||
self.assertEquals(number, int("0x" + upper_hex(number), 16))
|
||||
|
||||
number = 0xFFFFAAA0000
|
||||
self.assertEquals(number, int("0x" + upper_hex(number), 16))
|
||||
|
||||
def test_format_bank_number(self):
|
||||
address = 0x0
|
||||
self.assertEquals("0", format_bank_number(address))
|
||||
|
||||
address = 0x4000
|
||||
self.assertEquals("1", format_bank_number(address))
|
||||
|
||||
address = 0x1FC000
|
||||
self.assertEquals("7F", format_bank_number(address))
|
||||
|
||||
def test_dump_section(self):
|
||||
self.assertIn("SECTION", dump_section(str(0)))
|
||||
self.assertIn("HOME", dump_section(str(0)))
|
||||
self.assertNotIn("HOME", dump_section(str(1)))
|
||||
self.assertIn("DATA", dump_section(str(2)))
|
||||
self.assertIn("BANK", dump_section(str(40)))
|
||||
self.assertNotIn("BANK", dump_section(str(0)))
|
||||
|
||||
def test_dump_incbin_for_section(self):
|
||||
self.assertIn("INCBIN", dump_incbin_for_section(0))
|
||||
|
||||
def test_dump_incbin_for_section_separator(self):
|
||||
separator = "\n\n"
|
||||
self.assertIn(separator, dump_incbin_for_section(0, separator=separator))
|
||||
|
||||
separator = "\t\t" # dumb
|
||||
self.assertIn(separator, dump_incbin_for_section(0, separator=separator))
|
||||
|
||||
def test_dump_incbin_for_section_default(self):
|
||||
rom = "baserom.gbc"
|
||||
self.assertIn(rom, dump_incbin_for_section(0))
|
||||
|
||||
rom = "baserom"
|
||||
self.assertIn(rom, dump_incbin_for_section(0x4000))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
1015
extras/tests.py
1015
extras/tests.py
File diff suppressed because it is too large
Load Diff
@ -1,108 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# url: http://hax.iimarck.us/topic/8/
|
||||
|
||||
# for fixing trainer_group_names
|
||||
import re
|
||||
|
||||
trainer_group_pointer_table_address = 0x39999
|
||||
trainer_group_pointer_table_address_gs = 0x3993E
|
||||
|
||||
# Any trainer that appears more than once should have an id after each
|
||||
# trainer name.
|
||||
|
||||
# "uses_numeric_trainer_ids" means never use a name for the trainer_id
|
||||
trainer_group_names = {
|
||||
0x01: {"name": "Falkner", "uses_numeric_trainer_ids": True, "constant": "FALKNER"},
|
||||
0x02: {"name": "Whitney", "uses_numeric_trainer_ids": True, "constant": "WHITNEY"},
|
||||
0x03: {"name": "Bugsy", "uses_numeric_trainer_ids": True, "constant": "BUGSY"},
|
||||
0x04: {"name": "Morty", "uses_numeric_trainer_ids": True, "constant": "MORTY"},
|
||||
0x05: {"name": "Pryce", "uses_numeric_trainer_ids": True, "constant": "PRYCE"},
|
||||
0x06: {"name": "Jasmine", "uses_numeric_trainer_ids": True, "constant": "JASMINE"},
|
||||
0x07: {"name": "Chuck", "uses_numeric_trainer_ids": True, "constant": "CHUCK"},
|
||||
0x08: {"name": "Clair", "uses_numeric_trainer_ids": True, "constant": "CLAIR"},
|
||||
0x09: {"name": "Rival1", "constant": "RIVAL1"},
|
||||
#PokemonProf group is empty :/
|
||||
0x0A: {"name": "Pokémon Prof.", "constant": "POKEMON_PROF"},
|
||||
0x0B: {"name": "Elite Four Will", "uses_numeric_trainer_ids": True, "constant": "WILL"},
|
||||
0x0C: {"name": "PKMN [Cal]", "constant": "CAL"},
|
||||
0x0D: {"name": "Elite Four Bruno", "uses_numeric_trainer_ids": True, "constant": "BRUNO"},
|
||||
0x0E: {"name": "Elite Four Karen", "uses_numeric_trainer_ids": True, "constant": "KAREN"},
|
||||
0x0F: {"name": "Elite Four Koga", "uses_numeric_trainer_ids": True, "constant": "KOGA"},
|
||||
0x10: {"name": "Champion", "constant": "CHAMPION"},
|
||||
0x11: {"name": "Brock", "uses_numeric_trainer_ids": True, "constant": "BROCK"},
|
||||
0x12: {"name": "Misty", "uses_numeric_trainer_ids": True, "constant": "MISTY"},
|
||||
0x13: {"name": "Lt.Surge", "uses_numeric_trainer_ids": True, "constant": "LT_SURGE"},
|
||||
0x14: {"name": "Scientist", "constant": "SCIENTIST"},
|
||||
0x15: {"name": "Erika", "uses_numeric_trainer_ids": True, "constant": "ERIKA"},
|
||||
0x16: {"name": "Youngster", "constant": "YOUNGSTER"},
|
||||
0x17: {"name": "Schoolboy", "constant": "SCHOOLBOY"},
|
||||
0x18: {"name": "Bird Keeper", "constant": "BIRD_KEEPER"},
|
||||
0x19: {"name": "Lass", "constant": "LASS"},
|
||||
0x1A: {"name": "Janine", "uses_numeric_trainer_ids": True, "constant": "JANINE"},
|
||||
0x1B: {"name": "CooltrainerM", "constant": "COOLTRAINERM"},
|
||||
0x1C: {"name": "CooltrainerF", "constant": "COOLTRAINERF"},
|
||||
0x1D: {"name": "Beauty", "constant": "BEAUTY"},
|
||||
0x1E: {"name": "Pokémaniac", "constant": "POKEMANIAC"},
|
||||
0x1F: {"name": "GruntM", "uses_numeric_trainer_ids": True, "constant": "GRUNTM"},
|
||||
0x20: {"name": "Gentleman", "constant": "GENTLEMAN"},
|
||||
0x21: {"name": "Skier", "constant": "SKIER"},
|
||||
0x22: {"name": "Teacher", "constant": "TEACHER"},
|
||||
0x23: {"name": "Sabrina", "uses_numeric_trainer_ids": True, "constant": "SABRINA"},
|
||||
0x24: {"name": "Bug Catcher", "constant": "BUG_CATCHER"},
|
||||
0x25: {"name": "Fisher", "constant": "FISHER"},
|
||||
0x26: {"name": "SwimmerM", "constant": "SWIMMERM"},
|
||||
0x27: {"name": "SwimmerF", "constant": "SWIMMERF"},
|
||||
0x28: {"name": "Sailor", "constant": "SAILOR"},
|
||||
0x29: {"name": "Super Nerd", "constant": "SUPER_NERD"},
|
||||
0x2A: {"name": "Rival2", "uses_numeric_trainer_ids": True, "constant": "RIVAL2"},
|
||||
0x2B: {"name": "Guitarist", "constant": "GUITARIST"},
|
||||
0x2C: {"name": "Hiker", "constant": "HIKER"},
|
||||
0x2D: {"name": "Biker", "constant": "BIKER"},
|
||||
0x2E: {"name": "Blaine", "uses_numeric_trainer_ids": True, "constant": "BLAINE"},
|
||||
0x2F: {"name": "Burglar", "constant": "BURGLAR"},
|
||||
0x30: {"name": "Firebreather", "constant": "FIREBREATHER"},
|
||||
0x31: {"name": "Juggler", "constant": "JUGGLER"},
|
||||
0x32: {"name": "Blackbelt_T", "constant": "BLACKBELT_T"},
|
||||
0x33: {"name": "ExecutiveM", "uses_numeric_trainer_ids": True, "constant": "EXECUTIVEM"},
|
||||
0x34: {"name": "Psychic_T", "constant": "PSYCHIC_T"},
|
||||
0x35: {"name": "Picnicker", "constant": "PICNICKER"},
|
||||
0x36: {"name": "Camper", "constant": "CAMPER"},
|
||||
0x37: {"name": "ExecutiveF", "uses_numeric_trainer_ids": True, "constant": "EXECUTIVEF"},
|
||||
0x38: {"name": "Sage", "constant": "SAGE"},
|
||||
0x39: {"name": "Medium", "constant": "MEDIUM"},
|
||||
0x3A: {"name": "Boarder", "constant": "BOARDER"},
|
||||
0x3B: {"name": "PokéfanM", "constant": "POKEFANM"},
|
||||
0x3C: {"name": "Kimono Girl", "constant": "KIMONO_GIRL"},
|
||||
0x3D: {"name": "Twins", "constant": "TWINS"},
|
||||
0x3E: {"name": "PokéfanF", "constant": "POKEFANF"},
|
||||
0x3F: {"name": "Red", "uses_numeric_trainer_ids": True, "constant": "RED"},
|
||||
0x40: {"name": "Blue", "uses_numeric_trainer_ids": True, "constant": "BLUE"},
|
||||
0x41: {"name": "Officer", "constant": "OFFICER"},
|
||||
0x42: {"name": "GruntF", "uses_numeric_trainer_ids": True, "constant": "GRUNTF"},
|
||||
0x43: {"name": "Mysticalman [Eusine]", "constant": "MYSTICALMAN"}, # crystal only
|
||||
}
|
||||
|
||||
def remove_parentheticals_from_trainer_group_names():
|
||||
"""
|
||||
Clean up the trainer group names.
|
||||
"""
|
||||
i = 0
|
||||
for (key, value) in trainer_group_names.items():
|
||||
# remove the brackets and inner contents from each name
|
||||
newvalue = re.sub(r'\[[^\)]*\]', '', value["name"]).strip()
|
||||
|
||||
# clean up some characters
|
||||
newvalue = newvalue.replace("♀", "F")\
|
||||
.replace("♂", "M")\
|
||||
.replace(".", "")\
|
||||
.replace(" ", "")\
|
||||
.replace("é", "e")
|
||||
|
||||
# and calculate the address of the first byte of this pointer
|
||||
trainer_group_names[key]["name"] = newvalue
|
||||
trainer_group_names[key]["pointer_address"] = trainer_group_pointer_table_address + (i * 2)
|
||||
i += 1
|
||||
return trainer_group_names
|
||||
|
||||
# remove [Blue] from each trainer group name
|
||||
remove_parentheticals_from_trainer_group_names()
|
@ -1,21 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
type_constants = {
|
||||
"NORMAL": 0x00,
|
||||
"FIGHTING": 0x01,
|
||||
"FLYING": 0x02,
|
||||
"POISON": 0x03,
|
||||
"GROUND": 0x04,
|
||||
"ROCK": 0x05,
|
||||
"BUG": 0x07,
|
||||
"GHOST": 0x08,
|
||||
"STEEL": 0x09,
|
||||
"CURSE_T": 0x13,
|
||||
"FIRE": 0x14,
|
||||
"WATER": 0x15,
|
||||
"GRASS": 0x16,
|
||||
"ELECTRIC": 0x17,
|
||||
"PSYCHIC": 0x18,
|
||||
"ICE": 0x19,
|
||||
"DRAGON": 0x1A,
|
||||
"DARK": 0x1B,
|
||||
}
|
1067
extras/vba.py
1067
extras/vba.py
File diff suppressed because it is too large
Load Diff
@ -1,468 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Programmatic speedrun of Pokémon Crystal
|
||||
"""
|
||||
import os
|
||||
|
||||
# bring in the emulator and basic tools
|
||||
import vba
|
||||
|
||||
def main():
|
||||
"""
|
||||
Start the game.
|
||||
"""
|
||||
vba.load_rom()
|
||||
|
||||
# get past the opening sequence
|
||||
skip_intro()
|
||||
|
||||
# walk to mom and handle her text
|
||||
handle_mom()
|
||||
|
||||
# walk to elm and do whatever he wants
|
||||
handle_elm("totodile")
|
||||
|
||||
new_bark_level_grind(10, skip=False)
|
||||
|
||||
def skippable(func):
|
||||
"""
|
||||
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):
|
||||
skip = True
|
||||
|
||||
if "skip" in kwargs.keys():
|
||||
skip = kwargs["skip"]
|
||||
del kwargs["skip"]
|
||||
|
||||
# override skip if there's no save
|
||||
if skip:
|
||||
full_name = func.__name__ + "-end.sav"
|
||||
if not os.path.exists(os.path.join(vba.save_state_path, full_name)):
|
||||
skip = False
|
||||
|
||||
return_value = None
|
||||
|
||||
if not skip:
|
||||
vba.save_state(func.__name__ + "-start", override=True)
|
||||
return_value = func(*args, **kwargs)
|
||||
vba.save_state(func.__name__ + "-end", override=True)
|
||||
elif skip:
|
||||
vba.set_state(vba.load_state(func.__name__ + "-end"))
|
||||
|
||||
return return_value
|
||||
return wrapped_function
|
||||
|
||||
@skippable
|
||||
def skip_intro():
|
||||
"""
|
||||
Skip the game boot intro sequence.
|
||||
"""
|
||||
# copyright sequence
|
||||
vba.nstep(400)
|
||||
|
||||
# skip the ditto sequence
|
||||
vba.press("a")
|
||||
vba.nstep(100)
|
||||
|
||||
# skip the start screen
|
||||
vba.press("start")
|
||||
vba.nstep(100)
|
||||
|
||||
# click "new game"
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
# Are you a boy? Or are you a girl?
|
||||
vba.nstep(145)
|
||||
|
||||
# pick "boy"
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
# ....
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# What time is it?
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# DAY 10 o'clock
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
# WHAT? DAY 10 o'clock? YES/NO.
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
# How many minutes? 0 min.
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
# Whoa! 0 min.? YES/NO.
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# People call me
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# tures that we call
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# everything about pokemon yet.
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# Now, what did you say your name was?
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# move down to "CHRIS"
|
||||
vba.press("d")
|
||||
vba.nstep(50)
|
||||
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# wait until playable
|
||||
# could be 150, but it sometimes takes longer??
|
||||
vba.nstep(200)
|
||||
|
||||
return
|
||||
|
||||
@skippable
|
||||
def handle_mom():
|
||||
"""
|
||||
Walk to mom. Handle her speech and questions.
|
||||
"""
|
||||
vba.press("r"); vba.nstep(50)
|
||||
vba.press("r"); vba.nstep(50)
|
||||
vba.press("r"); vba.nstep(50)
|
||||
vba.press("r"); vba.nstep(50)
|
||||
vba.press("r"); vba.nstep(50)
|
||||
vba.press("u"); vba.nstep(50)
|
||||
vba.press("u"); vba.nstep(50)
|
||||
vba.press("u"); vba.nstep(50)
|
||||
vba.press("u"); vba.nstep(50)
|
||||
|
||||
# wait for next map to load
|
||||
vba.nstep(50)
|
||||
|
||||
vba.press("d"); vba.nstep(50)
|
||||
vba.press("d"); vba.nstep(50)
|
||||
vba.press("d"); vba.nstep(50)
|
||||
|
||||
# walk into mom's line of sight
|
||||
vba.press("d"); vba.nstep(50)
|
||||
|
||||
vba.nstep(50)
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# What day is it? SUNDAY.
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
# SUNDAY, is it? YES/NO
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
vba.nstep(200)
|
||||
|
||||
# is it DST now? YES/NO.
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
# 10:06 AM DST, is that OK? YES/NO.
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# know how to use the PHONE? YES/NO.
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.press("a", holdsteps=50, aftersteps=1)
|
||||
|
||||
# have to wait for her to move back :(
|
||||
vba.nstep(50)
|
||||
|
||||
# face down
|
||||
vba.press("d"); vba.nstep(50)
|
||||
|
||||
return
|
||||
|
||||
@skippable
|
||||
def handle_elm(starter_choice):
|
||||
"""
|
||||
Walk to Elm's Lab and get a starter.
|
||||
"""
|
||||
|
||||
# walk down
|
||||
vba.press("d"); vba.nstep(50)
|
||||
vba.press("d"); vba.nstep(50)
|
||||
|
||||
# face left
|
||||
vba.press("l"); vba.nstep(50)
|
||||
|
||||
# walk left
|
||||
vba.press("l"); vba.nstep(50)
|
||||
vba.press("l"); vba.nstep(50)
|
||||
|
||||
# face down
|
||||
vba.press("d"); vba.nstep(50)
|
||||
|
||||
# walk down
|
||||
vba.press("d"); vba.nstep(50)
|
||||
|
||||
# walk down to warp to outside
|
||||
vba.press("d"); vba.nstep(50)
|
||||
vba.nstep(10)
|
||||
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
|
||||
vba.press("u", holdsteps=10, aftersteps=50)
|
||||
vba.press("u", holdsteps=10, aftersteps=50)
|
||||
|
||||
# warp into elm's lab (bottom left warp)
|
||||
vba.press("u", holdsteps=5, aftersteps=50)
|
||||
|
||||
# let the script play
|
||||
vba.nstep(200)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
# I needed to ask you a fa
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.nstep(50)
|
||||
|
||||
# YES/NO.
|
||||
vba.press("a")
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.press("a")
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.press("a")
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.crystal.text_wait()
|
||||
|
||||
for x in range(0, 8): # was 15
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.nstep(50)
|
||||
vba.press("a")
|
||||
vba.nstep(100)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# Go on! Pick one.
|
||||
vba.nstep(100)
|
||||
vba.press("a"); vba.nstep(50)
|
||||
|
||||
vba.press("r"); vba.nstep(50)
|
||||
vba.press("r"); vba.nstep(50)
|
||||
|
||||
right = 0
|
||||
if starter_choice in [1, "cyndaquil"]:
|
||||
right = 0
|
||||
elif starter_choice in [2, "totodile"]:
|
||||
right = 1
|
||||
elif starter_choice in [3, "chikorita"]:
|
||||
right = 2
|
||||
else:
|
||||
raise Exception("bad starter")
|
||||
|
||||
for each in range(0, right):
|
||||
vba.press("r"); vba.nstep(50)
|
||||
|
||||
# look up
|
||||
vba.press("u", holdsteps=5, aftersteps=50)
|
||||
|
||||
# get menu
|
||||
vba.press("a", holdsteps=5, aftersteps=50)
|
||||
|
||||
# let the image show
|
||||
vba.nstep(100)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# YES/NO.
|
||||
vba.press("a")
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# received.. music is playing.
|
||||
vba.press("a")
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# YES/NO (nickname)
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.press("b")
|
||||
|
||||
# get back to elm
|
||||
vba.nstep(100)
|
||||
vba.nstep(100)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# phone number..
|
||||
vba.press("a")
|
||||
vba.crystal.text_wait()
|
||||
vba.nstep(100)
|
||||
vba.press("a")
|
||||
vba.nstep(300)
|
||||
vba.press("a")
|
||||
vba.nstep(100)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
# I'm counting on you!
|
||||
vba.nstep(200)
|
||||
vba.press("a")
|
||||
vba.nstep(50)
|
||||
|
||||
# look down
|
||||
vba.press("d", holdsteps=5, aftersteps=50)
|
||||
|
||||
# walk down
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.press("a")
|
||||
vba.nstep(50)
|
||||
vba.press("a")
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.crystal.text_wait()
|
||||
|
||||
vba.press("a")
|
||||
vba.nstep(50)
|
||||
|
||||
vba.crystal.text_wait()
|
||||
vba.press("a")
|
||||
|
||||
vba.nstep(100)
|
||||
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
|
||||
# step outside
|
||||
vba.nstep(40)
|
||||
|
||||
@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..
|
||||
"""
|
||||
|
||||
# walk to the grass area
|
||||
new_bark_level_grind_walk_to_grass(skip=False)
|
||||
|
||||
# TODO: walk around in grass, handle battles
|
||||
# TODO: heal at the lab, then repeat entire function
|
||||
|
||||
@skippable
|
||||
def new_bark_level_grind_travel_to_grass():
|
||||
"""
|
||||
Move to just above the grass.
|
||||
"""
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
vba.press("l", holdsteps=10, aftersteps=50)
|
||||
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
vba.press("d", holdsteps=10, aftersteps=50)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,12 +0,0 @@
|
||||
#!/usr/bin/jython
|
||||
# -*- encoding: utf-8 -*-
|
||||
import os
|
||||
|
||||
# by default we assume the user has vba in pokecrystal/extras
|
||||
project_path = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..'))
|
||||
|
||||
# save states are in pokecrystal/save-states/
|
||||
save_state_path = os.path.join(project_path, "save-states")
|
||||
|
||||
# where is your rom?
|
||||
rom_path = os.path.join(project_path, "baserom.gbc")
|
@ -1,563 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
This file constructs a networkx.DiGraph object called graph, which can be used
|
||||
to find the shortest path of keypresses on the keyboard to type a word.
|
||||
"""
|
||||
|
||||
import itertools
|
||||
import networkx
|
||||
|
||||
graph = networkx.DiGraph()
|
||||
|
||||
graph_data = """
|
||||
A a select
|
||||
A B r
|
||||
A I l
|
||||
A lower-upper-column-1 u
|
||||
A J d
|
||||
|
||||
B b select
|
||||
B A l
|
||||
B C r
|
||||
B lower-upper-column-2 u
|
||||
B K d
|
||||
|
||||
C c select
|
||||
C D r
|
||||
C B l
|
||||
C lower-upper-column-3 u
|
||||
C L d
|
||||
|
||||
D d select
|
||||
D E r
|
||||
D C l
|
||||
D del-upper-column-1 u
|
||||
D M d
|
||||
|
||||
E e select
|
||||
E del-upper-column-2 u
|
||||
E N d
|
||||
E D l
|
||||
E F r
|
||||
|
||||
F f select
|
||||
F del-upper-column-3 u
|
||||
F O d
|
||||
F E l
|
||||
F G r
|
||||
|
||||
G g select
|
||||
G end-upper-column-1 u
|
||||
G P d
|
||||
G F l
|
||||
G H r
|
||||
|
||||
H h select
|
||||
H end-upper-column-2 u
|
||||
H Q d
|
||||
H G l
|
||||
H I r
|
||||
|
||||
I i select
|
||||
I end-upper-column-3 u
|
||||
I R d
|
||||
I H l
|
||||
I A r
|
||||
|
||||
J j select
|
||||
J A u
|
||||
J S d
|
||||
J R l
|
||||
J K r
|
||||
|
||||
K k select
|
||||
K B u
|
||||
K T d
|
||||
K J l
|
||||
K L r
|
||||
|
||||
L l select
|
||||
L C u
|
||||
L U d
|
||||
L K l
|
||||
L M r
|
||||
|
||||
M m select
|
||||
M D u
|
||||
M V d
|
||||
M L l
|
||||
M N r
|
||||
|
||||
N n select
|
||||
N E u
|
||||
N W d
|
||||
N M l
|
||||
N O r
|
||||
|
||||
O o select
|
||||
O F u
|
||||
O X d
|
||||
O N l
|
||||
O P r
|
||||
|
||||
P p select
|
||||
P G u
|
||||
P Y d
|
||||
P O l
|
||||
P Q r
|
||||
|
||||
Q q select
|
||||
Q H u
|
||||
Q Z d
|
||||
Q P l
|
||||
Q R r
|
||||
|
||||
R r select
|
||||
R I u
|
||||
R space-upper-x8-y2 d
|
||||
R Q l
|
||||
R J r
|
||||
|
||||
S s select
|
||||
S J u
|
||||
S - d
|
||||
S space-upper-x8-y2 l
|
||||
|
||||
T t select
|
||||
T K u
|
||||
T ? d
|
||||
T S l
|
||||
T U r
|
||||
|
||||
U u select
|
||||
U L u
|
||||
U ! d
|
||||
U T l
|
||||
U V r
|
||||
|
||||
V v select
|
||||
V M u
|
||||
V / d
|
||||
V U l
|
||||
V W r
|
||||
|
||||
W w select
|
||||
W N u
|
||||
W . d
|
||||
W V l
|
||||
W X r
|
||||
|
||||
X x select
|
||||
X O u
|
||||
X , d
|
||||
X W l
|
||||
X Y r
|
||||
|
||||
Y y select
|
||||
Y P u
|
||||
Y space-upper-x6-y3 d
|
||||
Y X l
|
||||
Y Z r
|
||||
|
||||
Z z select
|
||||
Z Q u
|
||||
Z space-upper-x7-y3 d
|
||||
Z Y l
|
||||
Z space-upper-x8-y2 r
|
||||
|
||||
end-upper-column-1 lower-upper-column-1 r
|
||||
end-upper-column-2 lower-upper-column-1 r
|
||||
end-upper-column-3 lower-upper-column-1 r
|
||||
end-upper-column-1 del-upper-column-1 l
|
||||
end-upper-column-2 del-upper-column-1 l
|
||||
end-upper-column-3 del-upper-column-1 l
|
||||
lower-upper-column-1 end-upper-column-1 l
|
||||
lower-upper-column-2 end-upper-column-1 l
|
||||
lower-upper-column-3 end-upper-column-1 l
|
||||
lower-upper-column-1 del-upper-column-1 r
|
||||
lower-upper-column-2 del-upper-column-1 r
|
||||
lower-upper-column-3 del-upper-column-1 r
|
||||
del-upper-column-1 lower-upper-column-1 l
|
||||
del-upper-column-2 lower-upper-column-1 l
|
||||
del-upper-column-3 lower-upper-column-1 l
|
||||
del-upper-column-1 end-upper-column-1 r
|
||||
del-upper-column-2 end-upper-column-1 r
|
||||
del-upper-column-3 end-upper-column-1 r
|
||||
|
||||
lower-upper-column-1 A d
|
||||
lower-upper-column-2 B d
|
||||
lower-upper-column-3 C d
|
||||
lower-upper-column-1 - u
|
||||
lower-upper-column-2 ? u
|
||||
lower-upper-column-3 ! u
|
||||
|
||||
del-upper-column-1 D d
|
||||
del-upper-column-2 E d
|
||||
del-upper-column-3 F d
|
||||
del-upper-column-1 / u
|
||||
del-upper-column-2 . u
|
||||
del-upper-column-3 , u
|
||||
|
||||
end-upper-column-1 G d
|
||||
end-upper-column-2 H d
|
||||
end-upper-column-3 I d
|
||||
end-upper-column-1 space-upper-x6-y3 u
|
||||
end-upper-column-2 space-upper-x7-y3 u
|
||||
end-upper-column-3 space-upper-x8-y3 u
|
||||
|
||||
space-upper-x8-y2 space-lower-x8-y2 select
|
||||
space-upper-x8-y2 R u
|
||||
space-upper-x8-y2 space-upper-x8-y3 d
|
||||
space-upper-x8-y2 Z l
|
||||
space-upper-x8-y2 S r
|
||||
|
||||
space-upper-x8-y3 MN select
|
||||
space-upper-x8-y3 space-upper-x8-y2 u
|
||||
space-upper-x8-y3 end-upper-column-3 d
|
||||
space-upper-x8-y3 space-upper-x7-y3 l
|
||||
space-upper-x8-y3 - r
|
||||
|
||||
space-upper-x7-y3 PK select
|
||||
space-upper-x7-y3 Z u
|
||||
space-upper-x7-y3 end-upper-column-2 d
|
||||
space-upper-x7-y3 space-upper-x6-y3 l
|
||||
space-upper-x7-y3 space-upper-x8-y3 r
|
||||
|
||||
space-upper-x6-y3 ] select
|
||||
space-upper-x6-y3 Y u
|
||||
space-upper-x6-y3 end-upper-column-1 d
|
||||
space-upper-x6-y3 , l
|
||||
space-upper-x6-y3 space-upper-x7-y3 r
|
||||
|
||||
end-upper-column-1 end-lower-column-1 select
|
||||
end-upper-column-2 end-lower-column-2 select
|
||||
end-upper-column-3 end-lower-column-3 select
|
||||
lower-upper-column-1 lower-lower-column-1 select
|
||||
lower-upper-column-2 lower-lower-column-2 select
|
||||
lower-upper-column-3 lower-lower-column-3 select
|
||||
del-upper-column-1 del-lower-column-1 select
|
||||
del-upper-column-2 del-lower-column-2 select
|
||||
del-upper-column-3 del-lower-column-3 select
|
||||
|
||||
lower-lower-column-1 × u
|
||||
lower-lower-column-2 ( u
|
||||
lower-lower-column-3 ) u
|
||||
lower-lower-column-1 a d
|
||||
lower-lower-column-2 b d
|
||||
lower-lower-column-3 c d
|
||||
|
||||
end-lower-column-1 ] u
|
||||
end-lower-column-2 PK u
|
||||
end-lower-column-3 MN u
|
||||
end-lower-column-1 g d
|
||||
end-lower-column-2 h d
|
||||
end-lower-column-3 i d
|
||||
|
||||
del-lower-column-1 : u
|
||||
del-lower-column-2 ; u
|
||||
del-lower-column-3 [ u
|
||||
del-lower-column-1 d d
|
||||
del-lower-column-2 e d
|
||||
del-lower-column-3 f d
|
||||
|
||||
- × select
|
||||
- S u
|
||||
- lower-upper-column-1 d
|
||||
- space-upper-x8-y3 l
|
||||
- ? r
|
||||
|
||||
? ( select
|
||||
? T u
|
||||
? lower-upper-column-2 d
|
||||
? - l
|
||||
? ! r
|
||||
|
||||
! ) select
|
||||
! U u
|
||||
! lower-upper-column-3 d
|
||||
! ? l
|
||||
! / r
|
||||
|
||||
/ : select
|
||||
/ V u
|
||||
/ del-upper-column-1 d
|
||||
/ ! l
|
||||
/ . r
|
||||
|
||||
. ; select
|
||||
. W u
|
||||
. del-upper-column-2 d
|
||||
. / l
|
||||
. , r
|
||||
|
||||
, [ select
|
||||
, X u
|
||||
, del-upper-column-3 d
|
||||
, . l
|
||||
, space-upper-x6-y3 r
|
||||
|
||||
× - select
|
||||
× s u
|
||||
× upper-lower-column-1 d
|
||||
× MN l
|
||||
× ( r
|
||||
|
||||
( ? select
|
||||
( t u
|
||||
( upper-lower-column-2 d
|
||||
( × l
|
||||
( ) r
|
||||
|
||||
) ! select
|
||||
) u u
|
||||
) upper-lower-column-3 d
|
||||
) ( l
|
||||
) : r
|
||||
|
||||
: / select
|
||||
: v u
|
||||
: del-lower-column-1 d
|
||||
: ) l
|
||||
: ; r
|
||||
|
||||
; . select
|
||||
; w u
|
||||
; del-lower-column-2 d
|
||||
; : l
|
||||
; [ r
|
||||
|
||||
[ , select
|
||||
[ x u
|
||||
[ del-lower-column-3 d
|
||||
[ ; l
|
||||
[ ] r
|
||||
|
||||
] space-upper-x6-y3 select
|
||||
] y u
|
||||
] end-lower-column-1 d
|
||||
] [ l
|
||||
] PK r
|
||||
|
||||
PK space-upper-x7-y3 select
|
||||
PK z u
|
||||
PK end-lower-column-2 d
|
||||
PK ] l
|
||||
PK MN r
|
||||
|
||||
MN space-upper-x8-y3 select
|
||||
MN space-lower-x8-y2 u
|
||||
MN end-lower-column-3 d
|
||||
MN PK l
|
||||
MN × r
|
||||
|
||||
space-lower-x8-y2 space-upper-x8-y2 select
|
||||
space-lower-x8-y2 r u
|
||||
space-lower-x8-y2 MN d
|
||||
space-lower-x8-y2 z l
|
||||
space-lower-x8-y2 s r
|
||||
|
||||
a A select
|
||||
a upper-lower-column-1 u
|
||||
a j d
|
||||
a i l
|
||||
a b r
|
||||
|
||||
b B select
|
||||
b upper-lower-column-2 u
|
||||
b k d
|
||||
b a l
|
||||
b c r
|
||||
|
||||
c C select
|
||||
c upper-lower-column-3 u
|
||||
c l d
|
||||
c b l
|
||||
c d r
|
||||
|
||||
d D select
|
||||
d del-lower-column-1 u
|
||||
d m d
|
||||
d c l
|
||||
d e r
|
||||
|
||||
e E select
|
||||
e del-lower-column-2 u
|
||||
e n d
|
||||
e d l
|
||||
e f r
|
||||
|
||||
f F select
|
||||
f del-lower-column-3 u
|
||||
f o d
|
||||
f e l
|
||||
f g r
|
||||
|
||||
g G select
|
||||
g end-lower-column-1 u
|
||||
g p d
|
||||
g f l
|
||||
g h r
|
||||
|
||||
h H select
|
||||
h end-lower-column-2 u
|
||||
h q d
|
||||
h g l
|
||||
h i r
|
||||
|
||||
i I select
|
||||
i end-lower-column-3 u
|
||||
i r d
|
||||
i h l
|
||||
i a r
|
||||
|
||||
j J select
|
||||
j a u
|
||||
j s d
|
||||
j r l
|
||||
j k r
|
||||
|
||||
k K select
|
||||
k b u
|
||||
k t d
|
||||
k j l
|
||||
k l r
|
||||
|
||||
l L select
|
||||
l c u
|
||||
l u d
|
||||
l k l
|
||||
l m r
|
||||
|
||||
m M select
|
||||
m d u
|
||||
m v d
|
||||
m l l
|
||||
m n r
|
||||
|
||||
n N select
|
||||
n e u
|
||||
n w d
|
||||
n m l
|
||||
n o r
|
||||
|
||||
o O select
|
||||
o f u
|
||||
o x d
|
||||
o n l
|
||||
o p r
|
||||
|
||||
p P select
|
||||
p g u
|
||||
p y d
|
||||
p o l
|
||||
p q r
|
||||
|
||||
q Q select
|
||||
q h u
|
||||
q z d
|
||||
q p l
|
||||
q r r
|
||||
|
||||
r R select
|
||||
r i u
|
||||
r space-lower-x8-y2 d
|
||||
r q l
|
||||
r j r
|
||||
|
||||
s S select
|
||||
s j u
|
||||
s × d
|
||||
s space-lower-x8-y2 l
|
||||
s t r
|
||||
|
||||
t T select
|
||||
t k u
|
||||
t ( d
|
||||
t s l
|
||||
t u r
|
||||
|
||||
u U select
|
||||
u l u
|
||||
u ) d
|
||||
u t l
|
||||
u v r
|
||||
|
||||
v V select
|
||||
v m u
|
||||
v : d
|
||||
v u l
|
||||
v w r
|
||||
|
||||
w W select
|
||||
w n u
|
||||
w ; d
|
||||
w v l
|
||||
w x r
|
||||
|
||||
x X select
|
||||
x o u
|
||||
x [ d
|
||||
x w l
|
||||
x y r
|
||||
|
||||
y Y select
|
||||
y p u
|
||||
y ] d
|
||||
y x l
|
||||
y z r
|
||||
|
||||
z Z select
|
||||
z q u
|
||||
z PK d
|
||||
z y l
|
||||
z space-lower-x8-y2 r"""
|
||||
|
||||
for line in graph_data.split("\n"):
|
||||
if line == "":
|
||||
continue
|
||||
elif line[0] == "#":
|
||||
continue
|
||||
|
||||
(node1, node2, edge_name) = line.split(" ")
|
||||
graph.add_edge(node1, node2, key=edge_name)
|
||||
|
||||
#print "Adding edge ("+edge_name+") "+node1+" -> "+node2
|
||||
|
||||
def shortest_path(node1, node2):
|
||||
"""
|
||||
Figures out the shortest list of button presses to move from one letter to
|
||||
another.
|
||||
"""
|
||||
buttons = []
|
||||
last = None
|
||||
path = networkx.shortest_path(graph, node1, node2)
|
||||
for each in path:
|
||||
if last != None:
|
||||
buttons.append(convert_nodes_to_button_press(last, each))
|
||||
last = each
|
||||
return buttons
|
||||
#return [convert_nodes_to_button_press(node3, node4) for (node3, node4) in zip(*(iter(networkx.shortest_path(graph, node1, node2)),) * 2)]
|
||||
|
||||
def convert_nodes_to_button_press(node1, node2):
|
||||
"""
|
||||
Determines the button necessary to switch from node1 to node2.
|
||||
"""
|
||||
print "getting button press for state transition: " + node1 + " -> " + node2
|
||||
return graph.get_edge_data(node1, node2)["key"]
|
||||
|
||||
def plan_typing(text, current="A"):
|
||||
"""
|
||||
Plans a sequence of button presses to spell out the given text.
|
||||
"""
|
||||
buttons = []
|
||||
for target in text:
|
||||
if target == current:
|
||||
buttons.append("a")
|
||||
else:
|
||||
print "Finding the shortest path between " + current + " and " + target
|
||||
more_buttons = shortest_path(current, target)
|
||||
buttons.extend(more_buttons)
|
||||
buttons.append("a")
|
||||
current = target
|
||||
return buttons
|
||||
|
@ -1,81 +0,0 @@
|
||||
# coding: utf-8
|
||||
|
||||
# RGBDS BSS section and constant parsing.
|
||||
|
||||
import os
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def read_bss_sections(bss):
|
||||
sections = []
|
||||
section = {}
|
||||
address = None
|
||||
if type(bss) is not list: bss = bss.split('\n')
|
||||
for line in bss:
|
||||
line = line.lstrip()
|
||||
if 'SECTION' in line:
|
||||
if section: sections.append(section) # last section
|
||||
|
||||
address = eval(line[line.find('[')+1:line.find(']')].replace('$','0x'))
|
||||
section = {
|
||||
'name': line.split('"')[1],
|
||||
#'type': line.split(',')[1].split('[')[0].strip(),
|
||||
'start': address,
|
||||
'labels': [],
|
||||
}
|
||||
|
||||
elif ':' in line:
|
||||
# rgbds allows labels without :, but prefer convention
|
||||
label = line[:line.find(':')]
|
||||
if ';' not in label:
|
||||
section['labels'] += [{
|
||||
'label': label,
|
||||
'address': address,
|
||||
'length': 0,
|
||||
}]
|
||||
|
||||
elif line[:3] == 'ds ':
|
||||
length = eval(line[3:line.find(';')].replace('$','0x'))
|
||||
address += 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(os.path.join(path, '../wram.asm'), 'r').readlines())
|
||||
|
||||
|
||||
def make_wram_labels():
|
||||
wram_labels = {}
|
||||
for section in wram_sections:
|
||||
for label in section['labels']:
|
||||
if label['address'] not in wram_labels.keys():
|
||||
wram_labels[label['address']] = []
|
||||
wram_labels[label['address']] += [label['label']]
|
||||
return wram_labels
|
||||
|
||||
wram_labels = make_wram_labels()
|
||||
|
||||
|
||||
def constants_to_dict(constants):
|
||||
return dict((eval(constant[constant.find('EQU')+3:constant.find(';')].replace('$','0x')), constant[:constant.find('EQU')].strip()) for constant in constants)
|
||||
|
||||
def scrape_constants(text):
|
||||
if type(text) is not list:
|
||||
text = text.split('\n')
|
||||
return constants_to_dict([line for line in text if 'EQU' in line[:line.find(';')]])
|
||||
|
||||
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())
|
||||
|
@ -3,18 +3,14 @@
|
||||
|
||||
import sys
|
||||
|
||||
from extras.crystal import (
|
||||
from extras.pokemontools.crystal import (
|
||||
command_classes,
|
||||
Warp,
|
||||
XYTrigger,
|
||||
Signpost,
|
||||
PeopleEvent,
|
||||
DataByteWordMacro,
|
||||
PointerLabelBeforeBank,
|
||||
PointerLabelAfterBank,
|
||||
MoneyByteParam,
|
||||
ItemFragment,
|
||||
TextEndingCommand,
|
||||
text_command_classes,
|
||||
movement_command_classes,
|
||||
music_classes,
|
||||
@ -43,6 +39,9 @@ show_original_lines = False
|
||||
# helpful for debugging macros
|
||||
do_macro_sanity_check = False
|
||||
|
||||
class SkippableMacro(object):
|
||||
macro_name = "db"
|
||||
|
||||
chars = {
|
||||
"ガ": 0x05,
|
||||
"ギ": 0x06,
|
||||
@ -410,11 +409,10 @@ def quote_translator(asm):
|
||||
def extract_token(asm):
|
||||
return asm.split(" ")[0].strip()
|
||||
|
||||
def make_macro_table():
|
||||
def make_macro_table(macros):
|
||||
return dict(((macro.macro_name, macro) for macro in macros))
|
||||
macro_table = make_macro_table()
|
||||
|
||||
def macro_test(asm):
|
||||
def macro_test(asm, macro_table):
|
||||
"""
|
||||
Returns a matching macro, or None/False.
|
||||
"""
|
||||
@ -426,7 +424,19 @@ def macro_test(asm):
|
||||
else:
|
||||
return (None, None)
|
||||
|
||||
def macro_translator(macro, token, line):
|
||||
def is_based_on(something, base):
|
||||
"""
|
||||
Checks whether or not 'something' is a class that is a subclass of a class
|
||||
by name. This is a terrible hack but it removes a direct dependency on
|
||||
existing macros.
|
||||
|
||||
Used by macro_translator.
|
||||
"""
|
||||
options = [str(klass.__name__) for klass in something.__bases__]
|
||||
options += [something.__name__]
|
||||
return (base in options)
|
||||
|
||||
def macro_translator(macro, token, line, skippable_macros):
|
||||
"""
|
||||
Converts a line with a macro into a rgbasm-compatible line.
|
||||
"""
|
||||
@ -465,10 +475,10 @@ def macro_translator(macro, token, line):
|
||||
if show_original_lines:
|
||||
sys.stdout.write("; original_line: " + original_line)
|
||||
|
||||
# "db" is a macro because of TextEndingCommand
|
||||
# "db" is a macro because of SkippableMacro
|
||||
# rgbasm can handle "db" so no preprocessing is required
|
||||
# (don't check its param count)
|
||||
if macro.macro_name == "db" and macro in [TextEndingCommand, ItemFragment]:
|
||||
if macro.__name__ in skippable_macros or (macro.macro_name == "db" and macro in skippable_macros):
|
||||
sys.stdout.write(original_line)
|
||||
return
|
||||
|
||||
@ -498,8 +508,6 @@ def macro_translator(macro, token, line):
|
||||
elif param_klass.byte_type == "dw":
|
||||
if param_klass.size == 2:
|
||||
allowed_length += 1 # just label
|
||||
elif param_klass == MoneyByteParam:
|
||||
allowed_length += 1
|
||||
elif param_klass.size == 3:
|
||||
allowed_length += 2 # bank and label
|
||||
else:
|
||||
@ -527,7 +535,10 @@ def macro_translator(macro, token, line):
|
||||
|
||||
index = 0
|
||||
while index < len(params):
|
||||
param_type = macro.param_types[index - correction]
|
||||
try:
|
||||
param_type = macro.param_types[index - correction]
|
||||
except KeyError as exception:
|
||||
raise Exception("line is: " + str(line) + " and macro is: " + str(macro))
|
||||
description = param_type["name"]
|
||||
param_klass = param_type["class"]
|
||||
byte_type = param_klass.byte_type # db or dw
|
||||
@ -543,22 +554,22 @@ def macro_translator(macro, token, line):
|
||||
|
||||
output += ("; " + description + "\n")
|
||||
|
||||
if size == 3 and issubclass(param_klass, PointerLabelBeforeBank):
|
||||
if size == 3 and is_based_on(param_klass, "PointerLabelBeforeBank"):
|
||||
# write the bank first
|
||||
output += ("db " + param + "\n")
|
||||
# write the pointer second
|
||||
output += ("dw " + params[index+1].strip() + "\n")
|
||||
index += 2
|
||||
correction += 1
|
||||
elif size == 3 and issubclass(param_klass, PointerLabelAfterBank):
|
||||
elif size == 3 and is_based_on(param_klass, "PointerLabelAfterBank"):
|
||||
# write the pointer first
|
||||
output += ("dw " + param + "\n")
|
||||
# write the bank second
|
||||
output += ("db " + params[index+1].strip() + "\n")
|
||||
index += 2
|
||||
correction += 1
|
||||
elif size == 3 and issubclass(param_klass, MoneyByteParam):
|
||||
output += ("db " + MoneyByteParam.from_asm(param) + "\n")
|
||||
elif size == 3 and "from_asm" in dir(param_klass):
|
||||
output += ("db " + param_klass.from_asm(param) + "\n")
|
||||
index += 1
|
||||
else:
|
||||
raise Exception, "dunno what to do with this macro " + \
|
||||
@ -573,7 +584,7 @@ def macro_translator(macro, token, line):
|
||||
|
||||
sys.stdout.write(output)
|
||||
|
||||
def read_line(l):
|
||||
def read_line(l, skippable_macros, macro_table):
|
||||
"""Preprocesses a given line of asm."""
|
||||
|
||||
# strip comments from asm
|
||||
@ -599,16 +610,23 @@ def read_line(l):
|
||||
|
||||
# check against other preprocessor features
|
||||
else:
|
||||
macro, token = macro_test(asm)
|
||||
macro, token = macro_test(asm, macro_table)
|
||||
if macro:
|
||||
macro_translator(macro, token, asm)
|
||||
macro_translator(macro, token, asm, skippable_macros)
|
||||
else:
|
||||
sys.stdout.write(asm)
|
||||
|
||||
if comment: sys.stdout.write(comment)
|
||||
|
||||
def preprocess(lines=None):
|
||||
def preprocess(macros, skippable_macros=None, lines=None):
|
||||
"""Main entry point for the preprocessor."""
|
||||
if skippable_macros == None:
|
||||
skippable_macros = [SkippableMacro]
|
||||
|
||||
macro_table = make_macro_table(list(set(macros + skippable_macros)))
|
||||
|
||||
# HACK for pokecrystal. Must be after make_macro_table call.
|
||||
skippable_macros += ["TextEndingCommand"]
|
||||
|
||||
if not lines:
|
||||
# read each line from stdin
|
||||
@ -618,8 +636,8 @@ def preprocess(lines=None):
|
||||
lines = lines.split("\n")
|
||||
|
||||
for l in lines:
|
||||
read_line(l)
|
||||
read_line(l, skippable_macros, macro_table)
|
||||
|
||||
# only run against stdin when not included as a module
|
||||
if __name__ == "__main__":
|
||||
preprocess()
|
||||
preprocess(macros)
|
||||
|
@ -13,4 +13,4 @@ if __name__ == '__main__':
|
||||
dest = os.path.splitext(source)[0] + '.tx'
|
||||
sys.stdin = open(source, 'r')
|
||||
sys.stdout = open(dest, 'w')
|
||||
preprocessor.preprocess()
|
||||
preprocessor.preprocess(preprocessor.macros)
|
||||
|
@ -1 +0,0 @@
|
||||
-e git://github.com/drj11/pypng.git@master#egg=pypng
|
Loading…
Reference in New Issue
Block a user