$80/8DCD BATTLE: Setup HDMA Data Tables for Color Cycling

The Data Tables are going to be at $7E/BEBE and $7E/C0BE (and $7E/BFBE and $7E/C1BE, more on that later). They will consist of two bytes CGRAM address followed by two bytes of Color Data.

The second half of the subroutine is executed twice: At $8DE6, it jumps to the next line as a subroutine; it executes everything and then reaches a RTS. This RTS moves it back to $8DE9 where it executes everything again. As the Store Index in X isn't changed, it goes on writing the same stuff in the registers after whose who where worked off in the first run.

$80/9A21 Calculate the Global Cursor Position from it's Position on Map

Sorry, my language skills as well as my explanation skills are too limited to explain here how the calculation works, so you/we have to accept that it works.

What this subroutine does, is: It takes the coordinates of the cursor on the grid (you know, the Northeast-Southwest-Axis/Northwest-Southeast-coordinates) and turns it into an actual number of pixel offset.

$80/9DA7 Long Jump to the WRAM-Clear-DMA

$80/9DAB WRAM-Clear-DMA

This Subroutine is half a setup for a DMA and starts the DMA.
The first half of the setup has to be done before this Subroutine gets called.
A call can be found at $80/801B.
This is a fixed Transfer, so it's used for Clear Up DMAs. Furthermore, due to it's construction it is fixed to WRAM addresses. Before this subroutine is called, there are additional values that are loaded into certain registers:

$80/9DC8 Long Jump to Write Empty Tilemap in WRAM

$80/9DCC Write Empty Tilemap in WRAM

This subroutine is used to write the same double-byte over and over into a bigger space. This is used to write empty tilemaps in WRAM.

X contains the number of bytes to do

Y contains the destination address (the destination bank has to be set as Data Bank before this subroutine is called)

A (16-bit) contains the 16-bit value that should be written

This subroutine has to ways of doing this: Either it simply works off $20 byte in one step, or it does less if it has to do less then $20 byte. So, whatever amount you give it, it clears the big bunch in $20 byte steps first and then does the rest in the second way of doing it. The first part of the program is about distinguishing which method is to use.

This subroutine is actually quite well done: At $80/9DE4, it uses the remaining number of bytes to do which is in X as an index for a jump table, the jump table then lets the program jump right into the middle of the whole Store commands that start at $9E0D - that's the reason why it starts at $001E,y and not at $0000,y!

$80/9EEB VRAM DMA with accompanying Data Bytes

Important: Whenever and from wherever this subroutine is called, the next few bytes AFTER the JSL $809EEB is Data for this subroutine. So, the first part of this subroutine is changing the Jump-Back-Address on stack so the program does not accidentally try to interpret these data bytes as code, but skip them.

The rest is the regular VRAM DMA subroutine at $80/9F2C

The Data following this Subroutine's called are structured as follows:

$80/9F2C VRAM DMA

This Subroutine executes an DMA to VRAM.

First it checks if currently FBLANK is active. Then it checks if a HDMA is active. If it is, it pauses the HDMA for the time the DMA gets prepared and executed. The following preparations have been made in order to make this subroutine work properly:

$80/A901 Calculate the Square Number of 16-bit A

This subroutine calculates the Square Number of the 16-bit value in A. If A contains a really big value, the result could easily be outmax the 16-bit storage of A, so this subroutine does three calculations (Low Byte * Low Byte, High Byte * Low Byte * 2, High Byte * High Byte) and fits this all together to one big 32-bit number in registers $00-$03.

$80/ADCB Calculate Address in Tilemap

This seems to be about calculation of an Address in a Tilemap. You put the number of a tile's row number in A and the columns number in X, and it calculates the actual offset for it. The mathmatical formula is:

$80/B135 Update Graphics Settings Buffer Registers

I'm not sure, but it looks like you can buffer values for the screen settings in buffer registers, so that they get transfered in the next frame to their destination. Because this seems to be the subroutine that makes these values step up in queue.

$80/B9BA ?

This subroutine checks all values from $0603 to $0642. If the value in these registers is something else than #$00 or #$C9, it uses that value as index for the Jump Table in the subroutine below this one.

$80/F734 BATTLE: Get the Map Address of the Rhomb the Cursor points to

If you enter Battle, the program sets up several Maps on Bank $7F, which are all structured the same, for example the Height Map at $7F/D800. This is the map where the height of each Rhomb on the Battle Map is stored.

This subroutine turns the current position of the cursor into the offset for the corresponding entry on any of the the Maps. This is used for example on the Height Map to position the cursor on screen - depending on the Rhomb's height, the cursor has to be higher or lower on the screen.

These Maps have Rows and Columns. Each Row is $20 bytes long and contains all Rhombs with the same position on the NE-SW-Axis. This is why the calculation takes the NE-SW-Axis position and multiplies it by 20.

Bank $82

$82/89B0 Clear Map that shows which Figure Stands where

The Map at $7F/DC00 is structured as the others at the upper end of Bank $7F (the whole NE-SW-/NW-SE-Axis stuff); this maps shows where each figure stands. Either the entry for corresponding rhomb on this map contains a figure's number (#$00, #$02... #$24 or #$26), or #$FF to mark that there is no figure on that rhomb.

This subroutine creates a new, clear map of this kind - it sets every entry on this Map/Table to #$FF.

$82/AE91 Battle Stats Menu - Tilemap builder

This subroutine is called when the game has to build the status menu at the bottom of the battle screen. It builds some tiles into the tilemap - it is used quite often. This writes a rectangle shape into the tilemap, you have to give it the number of columns and rows it has to span.

Before it is called, certain values have to be set up.

X contains the 16-bit address where to read the tile data that has to be implemented into the tilemap.

$0A/B and $98/9 contain adress data that, together, form another part of the offset for the write address. Not sure what component each one brings in.

$0C contains what has to be added to the ROM read data before it is added to the tilemap, i. e. flipping or palette stuff.

$0E contains the number of rows this should edit, $0F the number of lines; these get transfered to $00/$01

$82/B1DA Clear BG3 Tilemap

This subroutine writes an empty tilemap for BG3 in WRAM and transfers it to VRAM. It writes at 7E/A800 "$03EE" for $800 bytes and transfers this to VRAM at $3C00, where the BG3 Tilemap in many/most of the cases is located. "$03EE" is of course an empty tile - "$0000" is used by some sprite tiles.

$82/F75D Update BG1 Tilemap Buffer (from Scrolling?)

WHY OH WHY IS THERE THIS ADC #$80 STUFF!?!

This Subroutine transfers data from the address in $20-2 to the BG1 Tilemap Buffer at $7FE000 onwards. This is used in Battle to transfer Data from the Buffer of the whole Battle Map (stored at $7F2000) to the VRAM Tilemap buffer at $7FE000. In the latter, there is always just as much as needs to be transfered to the VRAM.

Depending on the LSB of the value in Y, it changes between two styles of transfer.

A contains number of double-bytes to transfer - A is 16 bit, but the value may not exceed #$FF.

$82/F791 Update BG2 Tilemap Buffer (from Scrolling?)

WHY OH WHY IS THERE THIS ADC #$80 STUFF!?!

This Subroutine transfers data from the address in $20-2 to the BG2 Tilemap Buffer at $7FEC00 onwards. This is used in Battle to transfer Data from the Buffer of the whole Battle Map (stored at $7F5000) to the VRAM Tilemap buffer at $7FEC00. In the latter, there is always just as much as needs to be transfered to the VRAM.

Depending on the LSB of the value in Y, it changes between two styles of transfer.

A contains number of double-bytes to transfer - A is 16 bit, but the value may not exceed #$FF.

$82/FAAC ?

The second part of this subroutine transfers the data from $164B onwards into the CGRAM buffer and builds actual palettes from it - the data at $164B only contains fourteen colors per planned palette.

The palettes are built the following way:

($FAD2 to $FAD9) The first color is $0000
($FADA to $FAE9) The next #$0D (thirteen) colors are copied from [$20] = $00/164B + x
($FAEA to $FAEB) The fourteenth color gets left out
($FAEC to $FAF7) The fifteenth and last color gets copied from [$20] = $00/164B + x

Bank $84

$84/805F Do the Tile/Figure Animation

$05F4 is the General Animation Counter. It counts each frame from #$00 to #$07 and then gets reset. In the frames when the counter is $#00 or $01, this subroutine does the Tile Animation, like the movement of the water in the Opening Battle - it replaces the Tile graphics in VRAM via DMA. The other 6 counter steps/frames, this subroutine changes the Tile Graphics for two or four Figures.