zladx/LADX-Disassembly

Identify and label the BG maps handlers

kemenaran opened this issue · 5 comments

The game engine supports loading a BG tilemap asynchronously: the game code requests a BG map to be loaded by writing to wBGMapToLoad, and later, during the next V-Blank interrupt, the V-Blank interrupt handler copies the requested tilemap to VRAM.

For now the BG maps are stored sequentially in src/data/backgrounds/background_tile_commands.asm – a file generated automatically by tools/generate_background_data.py, which dumps these data from the original game. They are named BackgroundTileCommands01, BackgroundTileCommands02, and so on.

We should identify and name these BG maps.

The relevant steps could be (with one PR for each step):

  1. Create new BGMAP_***** constants to src/constants/gfx.asm, and name them accordingly.
    For instance, if it turns out that BackgroundTileCommands01 is the title screen BG map, we should create a BGMAP_TITLE_SCREEN equ $01 constant.
  2. Then edit the Python script, to generate named labels (BGMapTitleScreen::) instead of automatic labels (BackgroundTileCommands01).
  3. Then split the BG maps into individual files, one for each BG map.
    _This would allow to reduce the size of the localized BG maps file in revisions/, by storing only the relevant BG maps that diverge from revision to revision, instead of storing the whole BG maps.

NB : additionnaly, once all of this is done, we could write a Python script that can decompress and re-compress BG maps. This would allow to store the BG maps uncompressed, (so they can be easily changed using a tile editor). The BG maps would be re-compressed to the original commands-based format at compile-time.

daid commented

NB : additionnaly, once all of this is done, we could rite a Python script that can decompress and re-compress BG maps. This would allow to store the BG maps uncompressed, (so they can be easily changed using a tile editor). The BG maps would be re-compressed to the original commands-based format at compile-time.

That won't work. There is some serious over-draw in there, so you cannot get the current rom result with automatic compression, as they are hand written (sometimes pretty badly)

I have some code here that does the 2 way trip: https://github.com/daid/LADXR/blob/master/backgroundEditor.py
It doesn't even try to do a good job at encoding, as there is quite some space left in that bank.

Aw, too bad. So no automatic compression then. Once we'll get a decent tilemap format, I'll maybe look deeper at your Python script to allow importing BG maps in the game more easily.

daid commented

Oh, and there is also the "fun" thing at the file select menu:

BackgroundTileCommands03:: ; $6336

You can see the very small set of commands has no "end" marker and just flows into the next set of commands.

A fallthrough in the drawing commands 😱 Never knew about that.

daid commented

It broke my tooling :) which read in all the backgrounds, and then writes them back. And suddenly, without making changes, there was not enough space for all the backgrounds (unless I claimed the empty space in the bank as well)