Kelv's Random Collection

A random collection of my contributions to the world.

The Pokémon ROM

Posted by kelvSYC on 6-14-2014

Those of you who do know of Synalyze It! also know that you can download existing fully published grammars.  Through the painstaking process of reverse engineering, I’ve been using it to compile a grammar for the Pokémon Generation III games for the Game Boy Advance.

This grammar ONLY works with the US release ROMs, but they do work on all five games (Ruby, Sapphire, FireRed, LeafGreen, and Emerald).  The development of this grammar in particular has been extremely influential in the development of Synalyze It! as well; a number of things in this grammar were simply not possible in earlier versions of the program.  (I’ve had Synalyze It! since version 1.0.3, and things have changed a lot since then.)

This Pokémon ROM grammar has probably led to some help in exposing bugs and the development or better understanding of certain features:

  • Modelling discriminated unions
  • Offset to array scripts
  • Null-terminated array scripts
  • Scripting element scoping (after there was a bug found in the above script)
  • Zero-length scripting elements (though it doesn’t appear in this version of the grammar)
  • A crapton of bugs relating to structure inheritance (often times, the RS, FRLG, and Emerald versions of the data structure have subtle differences, and sometimes the inheritance from a common structure doesn’t work as expected…)
  • A crapton of bugs relating to structure alignment

And that’s only from the emails that I’ve been able to dig up.

In any event, this is the latest version of the file.  Changelists after the break.

Download the Pokémon ROM Grammar here!

Changes for 6-20-14:

A couple of hotfixes due to issues due to the latest version of Synalyze It! (1.8):

  • Fixed an issue due to a bug in Synalyze It! where sizes in inherited inner structures were not overridden if the structure was empty.  This affected the Battle Frontier and Battle Tent data structures, where the Pokémon used data is specified by subclasses (individual facilities).
  • Fixed an issue with some of the older Lua scripts (still in transition to all-Python) due to mapStructureAtPosition() taking more arguments than before.
  • Flattened and synchronized the RS file.

Changes for 6-14-14: 

  • Replaced the kludgey “Decompressed Size” scripts in the LZ77 data blocks and “Render Blocks” script in the “LZ77 Compressed Flag Data” structure in favor of a new “Render Blocks” script in the LZ77 header structure.  This is because you can terminate the decompression while in the middle of parsing a flag block, which the previous scripts could not accommodate.
  • Replaced the “String Pool String” string with a custom element.  The translation table is incomplete right now: notably missing is the mapping for “PK” and “MN”, for example.  There’s still a bit of work to be done, as I probably want to also make it a selection script.  Only the String Pool String versions of the string are affected; fixed-length strings elsewhere using the same charset are unaffected.
  • Flattened out most of the “padding structures” in FRLG.  Only “0.2” is not flattened right now.

Note that loading the ROMs is going to take MUCH longer.  That’s because there’s a lot of LZ77 headers in the Pokémon ROMs, and those blocks are now fully rendered, rather than having just the header rendered… (we’re talking about one Python script executing over 2000 times here…)

Advertisements

Comment on this

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: