SMA2 hacking notes 1.0 - By Smallhacker ======================================= A lot of things are stored in the same way as in SMW, albeit with a few tweaks. As such, I won't go into detail if something works the same way as in SMW. ============== LEVELS ============== == Main pointer tables == The pointers are stored as 4-byte GBA pointers (which, simply put, is the normal PC address with $08 added as the highest byte) in little-endian byte order. Layer 1 data: $0F22CC Layer 2 data: $0F2AF0 Sprites data: $0F3314 Note that SMA2 has 521 levels (000-208), compared to SMW's 512 (000-1FF). The nine additional levels are the special Donut Plains 2 sublevels not found in SMW's main pointer table. == Primary level header == The level header is the first 7 bytes of the layer 1/2LV data. It has been changed slightly from SMW. -----------+-----------+-----------+-----------+-----------+-----------+----------- BBBL LLLL | SSSM MMMM | mmmm ssss | ttPP PFFF | IIOC TTTT | bbbb cccc | ???? ???? -----------+-----------+-----------+-----------+-----------+-----------+----------- BBB : BG Palette LLLLL : Level length SSS : Scroll type [1] MMMMM : Level mode mmmm : Music [2] ssss : Spriteset tt : Time PPP : Sprite Palette FFF : FG Palette II : Item memory O : Screen snap [3] C : Camera height [4] TTTT : Tileset bbbb : BG Color [5] cccc : Camera sensitivity [6] The purpose of the final byte is unknown. None of the standard levels have a value other than 00. 1) The scroll type has been expanded from two to three bits. The values are as follows: 000 : No vertical scroll 001 : Vertical scroll if running+jumping, climbing or standing high 010 : Vertical scroll at will (medium) 011 : No horizontal or vertical scroll 100 : Vertical scroll at will (within SNES screen) 101 : Vertical scroll at will (high) 110 : Vertical scroll at will (entire level) 111 : Vertical scroll at will (low) 2) The music has been expanded from three to four bits. The values are as follows: 0000 : Here we go! 0001 : Cave Drums 0010 : Piano 0011 : Castle 0100 : Ghost House 0101 : Water Level 0110 : Boss Battle 0111 : Switch Palace 1000 : Switch Palace 1001 : Bowser Battle The rest is either nothing or crashes. 3) The screen snap bit moves the camera to the center of the first screen in order to make rooms taking up a single screen look better on the limited screen. 4) If the camera height bit is cleared, the lowest point the camera will scroll to is the same as in SMW (hiding the lowest row of blocks). If set, the lowest point is a block higher than normal (hiding the two lowest rows of blocks). This is done to allow some levels to use the limited GBA screen more efficiently. 5) The BG color has been increased from three to four bits. The first 8 colors are the same as in SMW (albeit brighter like the rest of the game's palette). 6) This setting changes how sensitive the camera is, i.e. how high on the screen Mario has to be in order to start scrolling. == Secondary level header == Like in SMW, the secondary header bytes are not stored sequentially. First, there's a table with all levels' first byte, then one with all levels' second byte, etc. This header has also been changed slightly. The tables are stored in these locations: Byte 1 table: $0F3D44 Byte 2 table: $0F3F44 Byte 3 table: $0F4144 Byte 4 table: $0F4344 Byte 5 table: $0F4544 -----------+-----------+-----------+-----------+----------- SSSS YYYY | 33TT TXXX | MMMM BBBB | ???? FFFF | IUVP PPPP -----------+-----------+-----------+-----------+----------- SSSS : Layer 2 scroll settings YYYY : Level entrance Y position 33 : Layer 3 image TTT : Entrance type XXX : Level entrance X position MMMM : Midway entrance screen BBBB : Initial BG Y [1] FFFF : Initial FG Y [1] I : Disable no-Yoshi intro flag U : Unknown vertical position flag V : Vertical positioning flag PPPPP : Level entrance screen 1) The initial BG/FG Y settings have been expanded from two to four bits. == Layer 1/2LV data == Some blocks' sizes are for some reason stored in a different way from SMW. The known instances of this: * Wooden log - The nibbles of the size bits have changed places. (Thus, if it was 1A in SMW, it would be A1 in SMA2.) * Arch ledge - Okay, Nintendo screwed this one up big time. The table below shows how many arches are placed for certain values. (V = Value, A = Arches in SMA2, W = Arches in SMW) V A W ------------ 00 2 256 01 1 1 02 3 2 03 4 3 04 5 4 05 6 5 ...etc... == Sprite level data == Sprite data (including the header) seems to be stored in the same way, with a few exceptions: * Sprite $C9 and above in SMW have been moved three steps forward to $CC and above. * In that opening, three new sprites have been placed: $C9 - Coin collection block (from DP1), $CA - Yoshi Coin, $CB - Yoshi Coin (behind fence). * One or more 4-byte sprites have been added. All normal SMW sprites (including the three SMA2 ones mentioned above) still seem to be 3 bytes long, though. * SMA2 requires all sprites to be stored sorted according to their global X coordinate. (Y coordinate, I assume, for vertical levels) == Secondary level entrances == Like the secondary headers, this data is also split up into five separate tables, starting at $F4744. Five byte tables, each with 512 entries. -----------+-----------+-----------+-----------+----------- DDDD DDDD | FFFF YYYY | ???? BBBB | XXXS SSSS | I??? ?AAA -----------+-----------+-----------+-----------+----------- DDDDDDDD : Destination level FFFF : Initial FG Y [1] YYYY : Mario Y position BBBB : Initial BG Y [1] SSSSS : Destination screen XXX : Mario X position I : Slippery level AAA : Mario Action 1) The initial BG/FG Y settings have been expanded from two to four bits.