Puyo Puyo Tsu/Memory Allocator

From Puyo Nexus Wiki
Jump to: navigation, search

Here are some memory management mechanisms used by Puyo Puyo Tsu for managing each player's status and the falling puyo and their sprites. This is an ongoing effort as the full reverse engineering of the ROM has not yet been completed.

Allocation routine

The game seems to have defined a reusable data structure and has a memory allocation function dedicated to it.

allocate_buffer() manages a pool of memory starting from FFD100 and can hold 60 structures of 64 bytes each.

RE-Allocate buffer.png

The function first calls find_free_buffer() which will find the first free 64-byte-long slot and allocate it. This is somewhat of an optimization to avoid having to do garbage collection and reuse (overwrite) a previously allocated structure.

RE-Find free buffer.png

These 2 routines handle what is commonly known as a linked-list, but also perform some extra operations: they put a pool tag at the front of the structure, which seems to describe what use is made of the buffer, and they put an initial value in the first 4-byte field.

You can read the assembly comments which should be self-explanatory.

Memory "heap" chunks

Here's a visual depiction of the allocated structures, describing how the currently falling pieces are actually stored:

RE-Status memory structure.png

When used for a falling puyo (pool tag 0xF780?), the structure looks like the one described on this page.

Using the MESS or MAME emulator, one can fiddle with those structures while actually playing by enabling the debugger:

  • open the memory window
  • pause the execution (the simplest way to do so is by pressing F8)
  • watch the address 0xFFD100 to find the buffers
  • pause the execution while the first pair is falling on the board
  • change the in-memory values to your linking.

The (x,y) coordinates can be changed to any valid coordinate, or the puyos' color value. Pressing F8 a few times will then advance the game by a few frames, which will update the view.

Here's what can ultimately be achieved when playing with the board at 0xFF8000:

RE-board-hacking.gif