Level Data Format

From Super Mario World Speedrunning Wiki
Revision as of 05:41, 19 March 2017 by Kaizoman (talk | contribs) (also I forgot to change a couple numbers)
Jump to: navigation, search

Pointer Tables

Address Description Format
$05E000 Layer 1 data 0x200 levels, 3 bytes each (1,536 bytes)
$05E600 Layer 2 data 0x200 levels, 3* bytes each (1,536 bytes)
$05EC00 Sprite data 0x200 levels, 2** bytes each (1,024 bytes)

* If the long byte of the Layer 2 data is #$FF, it will get replaced by #$0C and the data will be interpreted as a BG tilemap rather than object data.
** All sprite data is located in bank 07.


Primary Level Header

The first five bytes of object data for Layer 1 is the primary level header, which dictates various information about the level. Layer 2 object data also contains this header, but it is skipped over and ignored.

Format
BBBLLLLL CCCOOOOO 3MMMSSSS TTPPPFFF IIVVZZZZ
BBB BG palette
LLLLL Length of level (number of screens, -1)
CCC Back area color
OOOOO Level mode
3 Layer 3 priority
MMM Music
SSSS Sprite GFX setting
TT Timer setting
PPP Sprite palette
FFF FG palette
II Item memory setting
VV Vertical scroll setting
ZZZZ FG/BG GFX setting


Secondary Level Header

The secondary level header consists of four bytes, spread across four seperate tables with one byte per level.

Format
$05F000 $05F200 $05F400 $05F600
SSSSYYYY 33AAAXXX MMMMFFBB IUVEEEEE
SSSS Layer 2 scroll setting
YYYY Level entrance Y position
33 Layer 3 setting
AAA Level entrance Mario action
XXX Level entrance X position
MMMM Midway entrance screen number
FF FG initial position
BB BG initial position
I Disable No-Yoshi Intro flag
U Unknown/unused vertical position flag
V Vertical positioning flag
EEEEE Level entrance screen number


Sprite Header

The first byte of sprite data is the sprite header, which handles some miscellaneous sprite-related information.

Format
SBMMMMMM
S Sprite buoyancy
B Sprite buoyancy (disable sprite-Layer 2 interaction)
MMMMMM Sprite memory*

* Although values up to #$3F are possible, only up to #$12 are actually intended for use.


Object Data

Object data is used to define Layer 1 and Layer 2 foreground data. The Z order of the objects is determined by the order they're written; an object earlier in the data, for instance, will appear below an object written later.

The data consists of a five byte header, followed by a list of all the objects. If the first byte of an object is #$FF, it indicates the end of the data has been reached.


Standard Objects

Standard objects are 3 bytes long. The 'settings byte' usage varies depending on the object, but generally specifies the height and width of the object.

Format
NBBYYYYY bbbbXXXX SSSSSSSS
N New Screen flag
BBbbbb Object number
YYYYY Y position
XXXX X position
SSSSSSSS Settings

The "new screen" flag increases the object high X position by one. In order to increase it by a larger amount, a screen jump must be used.
In vertical levels, the X and Y position values are swapped.


Extended Objects

Extended objects function as standard object 00, and are also 3 bytes long.

Format
N00YYYYY 0000XXXX BBBBBBBB
N New Screen flag
YYYYY Y position
XXXX X position
BBBBBBBB Extended object number

The "new screen" flag increases the object high X position by one. In order to increase it by a larger amount, a screen jump must be used.
In vertical levels, the X and Y position values are swapped.


Screen Exits

Screen exits function as extended object 00. Unlike the rest of object data, they're 4 bytes long rather than 3.

Format
000PPPPP 0000WUSH 00000000 DDDDDDDD
PPPPP Screen number
W Water flag* (secondary exit)
U LM-modified flag**
S Secondary exit flag
H High bit of destination level*
DDDDDDDD Lower 8 bits of destination level

* Added by Lunar Magic; not used in the original game.
** Indicates the screen exit uses the secondary exit flag added by LM rather than SMW's default functionality.

In vanilla SMW, if the last screen exit in the data has the secondary exit flag set, all screen exits in the level will be interpreted as secondary exits.


Screen Jump

Screen jumps function as extended object 01, and change the high X position of proceding objects to a specified screen. They can be used to skip over screens if no objects exit on them, or to move back a screen to change the Z ordering of an object crossing over a screen boundary. Like standard and extended objects, they consist of three bytes.

Format
000PPPPP 0000---- 00000001
PPPPP Screen number
---- Currently unused


Background Data

When Layer 2 is stored as a background tilemap (see the note on the pointer table), it's written as a raw tilemap with no header, compressed in the LC_RLE1 format.

Format
RLLLLLLL ...
R RLE flag
LLLLLLL Length
... If the RLE flag is clear, the following (length + 1) bytes are intepreted as direct tile data.
If the RLE flag is set, the following byte is repeated (length + 1) times.

The entire left half of the BG is stored first, then the right half. A command of FF FF indicates the end of the data.


Sprite Data

Sprite data consists of a single-byte header, followed by a list of all the sprites. If the first byte of a sprite is #$FF, it indicates the end of the data has been reached.

Format
yyyyEESY XXXXssss NNNNNNNN
Yyyyy Y position
EE Extra bits
XXXX X position
Sssss Screen number
NNNNNNNN Sprite ID

In vertical levels, the X and Y position values are swapped.


Secondary Entrances

Secondary entrance data consists of four bytes, spread across four seperate tables with one byte per secondary exit ID.

Format
$05F800 $05FA00 $05FC00 $05FE00
DDDDDDDD BBFFYYYY XXXSSSSS L---HAAA
DDDDDDDD Low byte of destination level
BB BG initial position
FF FG initial position
YYYY Entrance Y position
XXX Entrance X position
SSSSS Entrance screen number
L Slippery level flag*
--- Currently unused
H High bit of destination level*
AAA Entrance Mario action

* Added by Lunar Magic; not used in the original game.