The overworld: how SMW stores it and how Lunar Magic edits it

Addresses are vanilla and traced in the SMW disassembly's bank 04 unless a section says otherwise. Lunar Magic facts come from LM's help on the overworld editor [LM-DOC], restated in plain words, and from controlled before/after saves in LM and several LM-edited ROMs compared against vanilla.

1. Geometry

Two maps, each 32x32 16x16 tiles (512x512 px). The main map is index 0x000-0x3FF. The six submaps share one second map, index 0x400-0x7FF, two columns by three rows; a "submap" ($1F11: 1 Yoshi's Island, 2 Vanilla Dome, 3 Forest, 4 Valley, 5 Special, 6 Star) is a fixed camera plus a palette, not separate storage. Cameras at $049A0C: 1 (-17,-40), 2 (-17,128), 3 (-17,296), 4 (240,-40), 5 (240,128), 6 (240,296) px.

Lunar Magic draws both on one canvas: the main map at tile Y 0-0x1F, the submap map at Y 0x20-0x3F, with the submap map rotated 16px right and 8px down (two 8x8 cells and one row). Its tilemap's last two columns and last row wrap round to the lower map's left edge and top, as a hardware scroll would show them, and layer 1 rides the same shift. The game itself shows both layers on the plain grid; the rotation is only LM's canvas layout [MEASURED, aligning LM's window and an emulator frame of the game against a raw render].

Layer 1 index ($049885): (X&0xF) | (X&0x10)<<4 | (Y&0xF)<<4 | (Y&0x10 ? 0x200 : 0), i.e. four 16x16-tile screens TL TR BL BR of 0x100 each, +0x400 on the submap map.

2. Layer 1: level tiles, clouds, Mario's paths (16x16)

3. Layer 2: the land (8x8)

Two RLE streams: tile numbers $04A533, property bytes $04C02B (decoded at $04DABA). Header byte n: bit 7 clear = copy n+1 literal bytes, set = repeat the next byte (n&0x7F)+1 times; each stream fills one byte of every word until 0x2000 words. The result is two 64x64 8x8 tilemaps in SNES screen order (four 32x32 screens of 0x400 words, TL TR BL BR), main map then submap map, DMA'd to VRAM $3000. Layer 2 scrolls with layer 1 (no parallax); layer 3 is the static border.

Layer-2 event tiles (LM's 6x6 and 2x2 "pieces"): tile bytes $0C8000 (0x900 bytes of 6x6 pieces, then 2x2), property bytes RLE at $0C8D00 in the same encoding as layer 2's streams, so the two bytes join into an 8x8 word. 0xD00 cells in all: 64 pieces of 6x6, then 256 of 2x2. A step writes piece src at dst ($04E4D0 for 2x2 if src >= 0x900, $04E520 for 6x6).

4. Graphics and palettes

Both layers draw in rows 0-7; what a layer 1 tile from GFX1E or GFX08 shows is colours 8-F of its row (plane 3 above), so rows 0-3 colours 1-7 (the level loader's leftovers) hardly matter, and LM's palette editor shows them black. Path fading borrows rows 0-3 and C-F colours 1-7 during a reveal. LM's Overworld Palette Editor agrees with this derivation row for row on every submap [MEASURED].

5. Level tiles

Per translevel (0-0x5F): exit directions $04D678 (bits 7-6 normal, 5-4/3-2/1-0 secret 1-3; 0 up, 1 down, 2 left, 3 right); base event $05D608 ($FF none; secret exit N fires base+N); level name $04A0FC (word giving three string offsets into $049AC5). Flags RAM $1EA2: bit 7 passed, 6 midway, 3-0 directions enabled (LM adds 5 "no entry if passed", 4 "save prompt"); new-game pairs at $009EE0; Mario/Luigi start $009EF0 = submap 1, tile (6,7). Reveal list $04DA1D to $04DA33 (22 pairs); event N reveals the layer-1 cell at $04D85D[N]. No-auto-move levels $04906C (6). Music per submap $048D8A.

6. Paths

Walkability is the layer-1 tile at the next cell (path < 0x56 or level tile) and the direction bit at the level Mario stands on. What a path tile does is its pose byte at $049FEB (read at $0495EF): bit 3 swims (tiles 28-3E, 50), bit 4 climbs (3F-41, the ladders; also sets $1B80 for the ladder speed table $049414), anything else walks; bit 2 only picks Mario's front-facing walk frames. Exit tiles are the ten in $049426 (25, 40, 42-48, 4D). Fish jump on 4E-50, Koopa Kids trigger on 49-4B. Level tiles 56-82 enter; 83-86 stop Mario without entering.

[CONFIRMED] against Lunar Magic's "Layer 1 Mario Paths" view on a ROM whose layer 1 was a grid of every tile 01-86: LM draws exactly those sets as green / blue / rungs / red / X. LM stores no bitmap for these pictures: its exe resources hold the level editor's slope outlines and the message font, not these.

Step vectors $049058; corner tiles $04A03C; per-tile speed and animation $049EA7. Five hardcoded paths ($049078, $04910E, $0490CA, $049086) that LM cannot display, only disable. Layer-1 paths are static; "a path revealed by an event" is a layer-2 change.

7. Events

0x78 events (bitfield $1F02-$1F10; vanilla tables sized 0x70). Layer-2 standard steps: cumulative index $04E35B (event N = steps E35B[N-1]..E35B[N]-1), 4 bytes per step at $04DD8D [src word][dst word], animated one per frame with a sound. Silent steps (layer 1, and layer 2 on other maps): events $04E8E4, flags $04E910 (bit 0 = layer-2 piece), dst $04E93C, tile/piece $04E994 (0x2C each); applied all at once on load. Destroy (castle, switch palace): events $04E5D6 (0x18), offsets $04E5B6, source tiles $04E5A7, replacements $04E5AC/$04E5B1.

8. Transitions

The position carries the direction. Mario is centred on the axis he is not moving along and a tile short on the one he is, so an entry is a tile AND a way of travelling through it: moving down (x*16+8, y*16), up (x*16+8, y*16+16), right (x*16, y*16+8), left (x*16+16, y*16+8). The same bytes therefore read as "tile 20 walking down" or "tile 21 walking up"; the one of the two that is an exit tile settles it. This is the "side to enter from" LM's link dialog asks for, and the destination is the partner tile written the same way, since the player keeps travelling as he was [CONFIRMED against all 14 vanilla entries; decoding and re-encoding them reproduces the ROM's own bytes].

The map already knows the side: an exit tile is the end of a path, so the player leaves by the side the path does not use, which can be read off the four neighbours. All 13 vanilla entries that sit on an exit tile agree with it (the fourteenth, entry 04, sits on a plain walk tile). A tile with other than exactly one walkable neighbour is ambiguous.

9. Sprites

13 slots x 5 bytes at $04F625: type, X lo/hi, Y lo/hi. Types in LM's list order (Lakitu, bird, fish x3, piranha, cloud, Koopa kid x3, smoke x2, sign, Bowser, ghost x2). Mario's and Luigi's start positions are edited as sprites in LM.

10. Lunar Magic's editor

One canvas; left click selects, right click pastes, Ctrl+Right always pastes the selector's tile, left-drag lassos, dragging a selection moves it, Ctrl+Left on a selection edge resizes it as a repeating pattern. Five edit modes:

View toggles: Layer 1, Layer 2, Sprites, Show Level Numbers, Show Event Numbers, Show Star/Pipe/Location Numbers, Show Exit Path Numbers, Layer 1 Mario Paths (green walk, black climb, blue swim, red exit), Future Layer 1 Tiles, Tile Grid, Special World Passed Palette. "Modify Level Tile Settings" holds: level number, base event, direction per exit, reveal-on-events, and the eight initial flags. Gotchas LM warns about [LM-DOC]: test on a fresh save slot (directions live in SRAM); never reuse a level number on two tiles; paths must not dead-end, gap or cross; one destroy and one reveal per event; star/pipe at X=0 on the submap map do not work.

10a. The Layer 2 8x8 canvas, area by area [MEASURED off LM's own status bar]

Lunar Magic's Layer 2 8x8 mode is wider than the two maps. The cells below are the 8x8 grid LM counts in:

areacolsrowswhat a cell is
main map0-630-63a layer 2 word
submap map0-6364-127a layer 2 word (rotated 2 right, 1 down, §1)
event pieces, 6x664-1110-47a byte of $0C8000: 8 pieces across, 36 bytes each, row-major
event pieces, 2x2112-1590-21a byte from $0C8900: 24 pieces across, 4 bytes each
layer 1 tiles0-31128+a word of the Map16 defs $05D000: 16 tiles across, TL BL TR BR

Measured by hovering LM and reading its status bar: canvas (0x41,1) is the 6x6 pieces' byte 7 (0x11 in a vanilla ROM, which is what LM shows there), the 2x2 index steps by 1 across and 0x18 down (so 24 across), and (2,0x82) is "Map16 11" whose top-left word is 8x8 tile 0x1D9.

The filler. A cell no table reaches gets LM's filler tile rather than a hole: 8x8 tile 0x7A, a black cross on blue, in palette row 5 (LM's status bar reports "7A" out there, and 0x7A's pixels are colours 1 and 4, which row 5 paints black on the sea's blue). 0x7A is one of the cycling animated slots (0x78-0x7F, §4), so on the map it shows whichever GFX14 frame is up.

LM paints that same X over piece slots a vanilla ROM fills with tile 0xBA (a dither texture), so its event area looks emptier than the ROM's bytes, which are what the game would draw if a step used the piece. LM is showing its own normalised copy, which it writes on its first overworld save.

11. Lunar Magic's overworld hooks

Modify Level Tile Settings

LM's Alt+Right dialog on a level tile has five groups. Where each lives [MEASURED, by changing each in LM's own dialog and diffing]:

fieldwhere it lives
base event$05D608 + translevel, in place on every ROM
direction per exit (normal + 3 secret)$04D678 + translevel, 2 bits each, on a ROM LM has not saved the overworld of. LM's overworld save jumps the copy loop and reads a packed block of its own instead, so after that the vanilla table is not read
level numbervanilla: the scan order of §2. LM: its per-tile table, the LZ2 blob behind the scan's operands (below)
eight initial flagsvanilla: eight (translevel, flags) pairs at $009EE0, written by the new-game loop at $009F0E. LM replaces the loop with a table at $05DDA0 + translevel when it saves [INFERRED; not checked against an LM-saved ROM]
reveal on eventLM's layer 1 event data (§7, and the silent-events row below)

What moves when LM saves the overworld [CONFIRMED, three LM-edited ROMs vs vanilla]

LM saves an overworld by moving a few tables and leaving the vanilla bytes in place, so a reader that trusts the vanilla addresses shows vanilla land under the hack's level tiles. What moves, and where the loader says so. Example addresses are from two of the ROMs, called A and B:

tablevanillaLMread from
layer 2 tile stream$04A533anywhere (A $12B1D3, B $139F8E)LDA #$addr at $04DC71; bank LDA #$bb at $04DC78, shared by both streams
layer 2 property stream$04C02Bpacked right after the tile stream (A $12B259, B $13B2D6)LDA #$addr at $04DC8C
layer 1 Map16$05D000, 0xC1 tiles0x200 tiles, LM's STAR marker right after (A $15A42C; B kept vanilla)LDX #$addr at $04DCBB, LDA #$bb at $04DCBF; also at $04DC3B
layer 1 low bytes$0CF7DFin placenone
layer 1 high bytesnoneLZ2 blob, decompressed to $7FC800 at load (all zero in both ROMs)second LDX #$addr : STX $8A : LDA #$bb : STA $8C in LM's rewrite of the $04D7F2 block
translevel per tilethe scan at $04D7F2LZ2 blob, decompressed to $7ED000 (0x1000 bytes): this is "level number to use for this tile"; ROM B numbers 81 tiles differently from the scanfirst LDX/STX $8A/LDA/STA $8C in the same block; the decompressor is vanilla $00B8DE, called by PHK : PER : PEA : JML
standard event steps$04DD8DA $138C38, B $10F144 (vanilla bytes left behind)long operands at $04E49E/$04E4A3 and $04E708/$04E70F
step index $04E35Bin placenone
event piece tiles$0C8000A $148000, B $10E1E3bank LDA #$bb at $04E4AF, address LDA #$addr at $04E4BA
event piece properties$0C8D00A $148B4C, B $138080LDY #$addr at $04DD44, bank LDA #$bb at $04DD49
silent events$04E8E4/$04E910/$04E93C/$04E994LM's own block, 16-bit tiles; vanilla tables staleJSL at $04E9F1 to a hook (A $129353). Its four long operands in order: event-to-step index (words, 0x79), flags (byte per step, bit 0 = layer 2 piece), tile (word: layer 1 tile, or piece index with >= 0x900 = 2x2), destination (word: layer 1 index or layer 2 tilemap offset). Layer 2 pieces still go through vanilla $04E4A9
destroy events$04E5D6, $04E5B6...A $12A0B5/$12A045, B $10F880/$10F810long operands at $04E67C, $04E69C
reveal list$04D85DA $129C37, B $10EF1Dlong operands at $04DA73, $04EC8B, $04ED96
$04E587 table (level-tile flags)A $12A07D, B $10F848operand at $04EEC8, behind a JSL at $04EEC3 that indexes it by LM's translevel
star/pipe warps27 entries at $048431...in place; the entry count is the LDX #$n*2 at hook+$11 behind the JSL at $048509 (A 0, B 26)hook operand
base events $05D608, exit dirs $04D678, exit tiles $049964..., Koopa teleports $048E49, sprites $04F625, music $048D8A, no-auto-move $04906C...edited in place (ROM B changed music there)vanilla addresses hold
OW palettes $00B3D8, $00B528, $00B57C, $00B5ECin place until LM's first overworld palette save; then a whole palette per submap in LM's table (B $13A9B9), the vanilla tables unread (§4)JSL at $00AD32 to a hook; table address at hook+$12 (word) and hook+$1E (bank)
level names $049AC5ROM B only: JMP $04FFB1 at $049882/$049AC2, LM's names rewrite, not traced

Also hooked and not yet traced: $04DBB9 and $04DCA5 (the latter replaces INC $0F : LDA $0F in the load loop and replays passed events' silent steps from LM's tables), $04DCFA (to $06F5E4), $04E5F1 (to $05DCB0), $04E6C5, $04EDDD, $04EEF1, $05D7B9, $05D979, $05D9A1, $05D9E3 (the level-number / base-event code of bank 05), $0C9436. On SA-1 ROMs all of this moves to bank $40 and $6D-mirrored RAM; not traced here.