| Super Mario Bros.'s cartridge ROM, counted by part of the game: each stretch of code or data goes to the part its code shows it serves, and the value sums the bytes of each part. | smb1.asm L28–33 | Code |
| World 1-1's main area as a 224 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L184–197src/prg.asm L2786–2817src/prg.asm L409–412src/prg.asm L3759–3764src/prg.asm L11149–11168src/prg.asm L6151–6196src/prg.asm L6304–6320src/prg.asm L11461–11466src/prg.asm L11486–11505src/prg.asm L11588–11609src/prg.asm L11202–11212src/levels/enemies.asm L89–94src/prg.asm L6996–7015src/prg.asm L11242–11267src/prg.asm L11287–11324 | Code |
| The underground bonus rooms, one area whose pages hold the rooms that 1-1, 1-2, 2-1, 3-1, 4-1, 4-2, 5-1, 6-2, 7-1, 8-1, and 8-2 lead to, as a 176 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L456–473src/levels/enemies.asm L222–228 | Code |
| The pipe intro area that opens 1-2, 2-2, 4-2, and 7-2, as a 48 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L246–250src/levels/levels.asm L9–25 | Code |
| World 1-2's main area as a 224 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L414–433src/levels/enemies.asm L204–211 | Code |
| The main area 1-3 and 5-3 share, as a 192 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L199–211src/levels/levels.asm L9–25 | Code |
| The main area 1-4 and 6-4 share, as a 176 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L3–16src/levels/levels.asm L9–25 | Code |
| World 2-1's main area as a 240 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L231–244src/prg.asm L4684–4688src/levels/enemies.asm L109–117src/prg.asm L4680–4683src/prg.asm L4651–4652 | Code |
| The cloud area that 2-1 and 5-2 lead to, as a 112 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L263–268src/levels/enemies.asm L127–130src/prg.asm L4035–4046src/prg.asm L2738–2742 | Code |
| The main area 2-2 and 7-2 share, as a 224 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L486–501src/levels/enemies.asm L236–242src/levels/levels.asm L9–25 | Code |
| The main area 2-3 and 7-3 share, as a 256 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L213–229src/levels/levels.asm L9–25 | Code |
| The main area 2-4 and 5-4 share, as a 176 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L36–51src/levels/levels.asm L9–25 | Code |
| World 3-1's main area as a 240 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L167–182src/levels/enemies.asm L80–87 | Code |
| The cloud area that 3-1 and 6-2 lead to, as a 128 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L395–402src/levels/enemies.asm L191–194 | Code |
| World 3-2's main area as a 240 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L404–412 | Code |
| World 3-3's main area as a 192 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L104–117 | Code |
| World 3-4's main area as a 176 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L53–67 | Code |
| World 4-1's main area as a 256 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L135–146src/levels/enemies.asm L66–70 | Code |
| World 4-2's main area as a 256 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L435–454src/levels/enemies.asm L213–220 | Code |
| The warp zone area that 4-2 leads to, as a 96 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L317–325 | Code |
| World 4-3's main area as a 176 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L270–283 | Code |
| World 4-4's main area as a 208 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L18–34 | Code |
| World 5-1's main area as a 224 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L252–261src/levels/enemies.asm L119–125 | Code |
| World 5-2's main area as a 240 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L347–362src/levels/enemies.asm L167–173 | Code |
| The water area that 5-2 and 6-2 lead to, as a 96 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L475–484src/levels/enemies.asm L230–234 | Code |
| World 6-1's main area as a 224 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L300–315 | Code |
| World 6-2's main area as a 256 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L148–165src/levels/enemies.asm L72–78 | Code |
| World 6-3's main area as a 208 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L285–298 | Code |
| World 7-1's main area as a 208 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L381–393src/levels/enemies.asm L184–189 | Code |
| World 7-4's main area as a 240 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L69–86 | Code |
| World 8-1's main area as a 416 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L327–345src/levels/enemies.asm L157–165 | Code |
| World 8-2's main area as a 256 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L364–379src/levels/enemies.asm L175–182 | Code |
| World 8-3's main area as a 256 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L119–133 | Code |
| World 8-4's main area as a 336 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L88–102src/levels/enemies.asm L42–49 | Code |
| The water area that 8-4 leads to, as a 96 × 13 grid of what Mario collides with: each cell the metatile the game's area parser puts in the block buffer there, column by column from the area's left edge. | src/levels/objects.asm L503–509src/levels/enemies.asm L244–248src/prg.asm L2730–2737src/prg.asm L2639–2640 | Code |
| The NMI handler first sets the scroll to 0; then, while the game's sprite 0 check is on, it waits for the sprite 0 hit flag to clear, spins until the sprite 0 hit, waits a short loop for horizontal blank, and only then writes the level's scroll, so the status bar above the hit is drawn at scroll 0. With the check off it writes the level's scroll without waiting. | src/prg.asm L159–183src/prg.asm L74–92src/prg.asm L1963–1965 | Code |
The game sets sprite 0 to OAM bytes $18, $FF, $23, $58, so tile $FF sits at Y $18 and X $58 behind the background in palette 7, the last sprite palette (computed). | src/prg.asm L2118–2119src/prg.asm L2236–2245src/ram.asm L84src/prg.asm L94–95 | Code |
Every unpaused frame the sprite shuffler adds one of three amounts, $58, $48, or $38 in turn, to each object's OAM offset at or above $28, wrapping within $28-$FF, so the objects' sprites change OAM slots each frame and a ninth sprite on a line drops out on different frames. | src/prg.asm L164–169src/prg.asm L240–266src/prg.asm L2225–2230 | Code |
Every 8th frame the color-rotation routine rewrites background palette 3 at $3F0C, putting the next of six colors, $27, $27, $27, $17, $07, $17, in its second entry, so the question blocks and coins shimmer on a 48-frame loop. | src/prg.asm L1386–1390src/prg.asm L1399–1402src/prg.asm L1429–1441 | Code |
| The cartridge header declares two 16 KB PRG ROM pages and one 8 KB CHR ROM page, so the game's tile set never changes. | smb1.asm L4–10 | Code |
| The NMI handler calls the sound engine, which outside the title screen and pause runs the music handler: it steps square 2, square 1, the triangle, and the noise channel in turn, and each counts its note length down by 1 per call and reads its next byte at 0. Square 1 is skipped while its data offset is 0, and the noise channel is skipped during the underground and castle songs and while an event song has replaced the area song. | src/prg.asm L115src/music-engine.asm L691–698src/music-engine.asm L763–766src/music-engine.asm L1–20src/music-engine.asm L64–68src/music-engine.asm L613–624src/music-engine.asm L814–820src/music-engine.asm L861–871src/defs.asm L36–37 | Code |
| A song's header picks an 8-entry row of the note-length table, and a length code of 0-7 indexes it in frames; the overworld theme's row is 54, 3, 9, 6, 18, 27, 36, 12, and the hurry-up version adds 8 to the row offset for 36, 2, 6, 4, 12, 18, 24, 8. | src/music-data.asm L34–39src/music-engine.asm L662–666src/ram.asm L521src/music-data.asm L63–64src/music-data.asm L377–383src/music-engine.asm L925–933src/music-engine.asm L625–627 | Code |
| A note byte is an offset into a table of 51 two-byte timer periods that the driver writes to the channel's timer registers; a recreation turns period into Hz on a square channel and half that on the triangle. | src/music-engine.asm L107–115src/music-data.asm L362–375 | Code |
A new area-music square note sets duty and volume byte $82 and an envelope index of 8; each frame the driver writes the envelope table's entry at that index to the channel and counts the index down, so the note plays at 50% duty with volumes 0, 8, 7, 6, 5, 5, 4, 4 and then 0 until the next note. | src/music-engine.asm L934–952src/music-engine.asm L754–759src/music-data.asm L388–392 | Code |
The noise channel plays three drum sounds, all at constant volume 12 ($400C = $1C): a short beat at period index 3, a strong beat at period index 12, and a long beat at period index 3 with length-counter load $58 instead of $18; a silent beat writes $10, constant volume 0. | src/music-engine.asm L888–913src/ram.asm L16 | Code |
During the overworld and underwater songs the sound engine raises a counter by 1 a frame up to $30 and writes it to the DMC's output level at $4011; other songs count it back down to 0. | src/music-engine.asm L79–91src/ram.asm L17src/defs.asm L38–39 | Code |
Super Mario Bros.'s song table, at $F90D, holds 49 entries, all music, each the offset of one of the song headers that follow it; two entries are silence. The game asks for a song by setting one bit in the event-music queue at $FC (bits 0 to 7 are entries $00 to $07) or the area-music queue at $FB (bits 1 to 7 are entries $09 to $0F). The area queue's bit 0 starts the aboveground theme instead, which the engine plays as entries $10 to $30 in turn and then repeats from $11. Requests reach 15 entries and the aboveground theme's step counter 32 more. Of the 18 stores that name the two queues, two in the sound engine clear them each frame, and each of the other 16 writes one bit: a constant, 1, or a byte from a six-entry table indexed 0 to 5. None of those asks for entry $04 (the event queue's bit 4) or $08 (the area queue's bit 0 taken as a bit); stores through an index or a pointer that might reach the queues are not yet bounded. Each row says where the game plays the entry, from the code that requests it. | src/music-data.asm L3–31src/defs.asm L101–102src/defs.asm L30–47src/ram.asm L503–504src/music-engine.asm L64–71src/music-engine.asm L603–629src/music-engine.asm L631–664src/music-engine.asm L701–726src/prg.asm L512–518src/prg.asm L574–595src/prg.asm L2188–2190src/prg.asm L2224src/prg.asm L2277–2302src/prg.asm L3955–3961src/prg.asm L4036–4043src/prg.asm L4115–4125src/prg.asm L2402–2408src/prg.asm L2456–2461src/prg.asm L2476–2478src/prg.asm L4436–4451src/prg.asm L4654–4663src/prg.asm L4689–4696src/prg.asm L5326–5338src/prg.asm L5348–5350src/prg.asm L9180–9195src/prg.asm L10411–10426src/prg.asm L10587–10589src/prg.asm L10611–10614src/prg.asm L11386–11399src/prg.asm L11528–11536src/ram.asm L300–309src/prg.asm L5180–5185 | Code |
Super Mario Bros.'s song table has a second entry for the game-over song that none of the stores that name the event-music queue asks for: entry $04, bit 4 of that queue, points at $F966, the game-over song's header, as entry $01 does. Those stores write $08, $04, $02, $20, $40, $80, or 1. The square channels' code treats bit 4 as it treats bits 0 and 7, the death song and silence: for an event song with any of those bits (it tests %10010001), both square channels skip their envelope table. | src/music-data.asm L4–8src/defs.asm L41–47src/music-engine.asm L748–753src/music-engine.asm L796–800 | Code notes |
Super Mario Bros.'s song table has an entry for steps of the aboveground theme that no store naming the area-music queue reaches: entry $08, which the engine's bit search gives for bit 0 of that queue, points at $F976, the header that steps 2, 3, 16 and 17 of the aboveground theme play. The area byte $01 alone goes to the aboveground theme's steps, entries $10 on; the search reaches entry $08 only for a byte with bit 0 and another bit set. Every store that names the area queue writes one bit: $80, $40, or one of $02, $01, $04, $08, $10 and $20 from a table, and the engine's own restarts pass on a byte it took from the queue. | src/music-data.asm L13–14src/music-engine.asm L640–660 | Code notes |
Super Mario Bros. has a song header that no entry of its song table points at, so no request can play it. The five bytes at $F94E give note-length offset $20, as the level-clear song's header does, and song data at $FCC4, 20 bytes into the level-clear song's data, which starts at $FCB0; its triangle and square 1 offsets are $3F and $1D, where the level-clear song's are $3D and $21. | src/music-data.asm L45–48src/music-engine.asm L662–676 | Code |
| Super Mario Bros.' demo is a script of 21 controller bytes in an action table, each held for the number of frames at the same place in a timing table; the demo routine moves to the next byte when the count runs out. The 21 counts add up to 1,119 frames (computed), about 18.6 seconds at the NES's 60.1 frames a second (computed). | src/prg.asm L459–467src/prg.asm L469–485src/defs.asm L104–111 | Code |
The demo writes each byte into controller 1's saved byte at $06FC, the byte the interrupt routine fills from controller 1 every frame, and then calls the game's core routine, the same engine a game in play runs, so Mario moves by the ordinary player code. | src/prg.asm L74src/prg.asm L116src/prg.asm L1895src/prg.asm L480–481src/prg.asm L343–348src/prg.asm L390–391src/ram.asm L31–32 | Code |
Each time the title screen starts, the game's initialization sets the demo timer at $07A2 to $18 (24). It is one of the interval timers, which the interrupt routine counts down once every 21 frames, so the demo starts about 500 frames after the title appears (computed: 24 × 21 = 504, less up to 20 for the first tick). Pressing Select, or B once world select is enabled, puts the timer back to $18 while it is still running; once it has reached 0, the press resets the title screen instead. | src/prg.asm L316–323src/prg.asm L2131–2132src/prg.asm L74src/prg.asm L126–140src/ram.asm L60–82src/prg.asm L355–359src/prg.asm L348–354 | Code |
| The demo ends, and the title screen restarts from its initialization, in three ways: the script reaches its closing count of 0; the engine reaches its lose-life routine (engine subroutine 6); or a player presses Start (alone or with A) or Select on either controller; B, which the title screen checks for world select, isn't tested while the demo runs. | src/prg.asm L474–478src/prg.asm L390–400src/prg.asm L4266–4276src/prg.asm L330–342src/prg.asm L343–344src/prg.asm L348–357src/prg.asm L402–404 | Code |
The demo doesn't reseed the random generator. The random register at $07A7 gets its seed $A5 only at reset, and the interrupt routine shifts it every frame; the game's initialization clears memory only up to $076F. The generator's state when the demo starts therefore depends on the number of frames since reset. | src/prg.asm L29–35src/prg.asm L74src/prg.asm L142–158src/prg.asm L2124–2125src/ram.asm L237 | Code |
| A jump starts only on the frame A goes down while Mario is grounded; the jump setup zeroes the vertical subpixel and sets the jumping state. | src/prg.asm L4913–4923src/prg.asm L4931–4942src/prg.asm L4139–4141 | Code |
The jump setup picks one of five jump rows by take-off horizontal speed, stepping up at $09, $10, $19, and $1C. | src/prg.asm L4943–4955 | Code |
| Horizontal speeds are 4.4 fixed point, whole pixels and sixteenths per frame; the horizontal-move routine shifts the sixteenths into the subpixel byte. | src/prg.asm L6492–6503 | Code |
Mario's top ground speed is $18 walking and $28 running (B held). | src/prg.asm L4873–4874src/prg.asm L5000–5014 | Code |
| The jump-speed table starts a jump at −4 px/frame (rows 0–2) or −5 px/frame (rows 3–4). | src/prg.asm L4864–4865src/prg.asm L4972–4973 | Code |
| The jump's starting-fraction table gives jump rows 0–4 a zero speed fraction, so take-off is exactly −4.00 or −5.00 px/frame. | src/prg.asm L4867–4868src/prg.asm L4970–4971 | Code |
While a jump rises with A held, gravity is the rising-gravity table's $20, $20, $1E, $28, $28 subpixels/frame² for rows 0–4. | src/prg.asm L4858–4859src/prg.asm L4966–4967 | Code |
After the switch, gravity is the falling-gravity table's $70, $70, $60, $90, $90 subpixels/frame² for rows 0–4. | src/prg.asm L4861–4862src/prg.asm L4968–4969 | Code |
In rows 0–1, the standing and slow jumps, held gravity is $20/256 = 0.125 px/frame². | src/prg.asm L4858–4859src/prg.asm L6681–6687 | Code |
In rows 0–1, falling gravity is $70/256 = 0.4375 px/frame². | src/prg.asm L4861–4862src/prg.asm L6681–6687 | Code |
| The jump-and-swim routine swaps in falling gravity, never back, once speed is zero or downward, or once the jump has risen at least a set minimum (smb1/diff-to-halt-jump) on a frame when A is not held, or was not held the frame before. | src/prg.asm L4756–4769 | Code |
| The jump setup sets the minimum rise for a release to 1, so a release switches gravity only once Mario has risen at least 1 pixel. | src/prg.asm L4957–4958 | Code |
| The press frame already moves Mario, since the player physics routine starts the jump before the state dispatch runs the jump-and-swim routine and the vertical move. | src/prg.asm L4713–4725src/prg.asm L4796 | Code |
| Vertical motion is 8.8 fixed point; each frame, the gravity routine adds speed to position, the fraction via a subpixel byte, then gravity to speed. | src/prg.asm L6666–6687 | Code |
The vertical-move routine gives the gravity routine 4 px/frame as Mario's maximum fall speed; the clamp sets the speed back to 4 only when its whole part is at least 4 and its fraction byte at least $80. | src/prg.asm L6547–6550src/prg.asm L6688–6696 | Code |
| Mario gets no grace window after leaving a ledge; the jump check refuses airborne jumps unless he is swimming. | src/prg.asm L4921–4925 | Code |
| Measured in the game on flat ground, the apexes, tapped/held, are 24/66 px standing, 27/71 px walking, and 29/83 px running. | src/prg.asm L4756–4769src/prg.asm L6664–6696src/prg.asm L4957–4958 | Verified |
| Measured in the game with A held, Mario's jumps peak at 66 px standing, 71 px walking, and 83 px running. | src/prg.asm L4756–4769src/prg.asm L6664–6696src/prg.asm L4957–4958 | Verified |
The gravity routine clamps a fall of 4 px/frame or more only when the fraction byte is at least $80. | src/prg.asm L6688–6696 | Code |
| Swimming jumps use row 5 of the jump tables, or row 6 in a whirlpool. | src/prg.asm L4959–4964 | Code |
| Each frame the player control routine splits the d-pad bits, runs the jump check, the horizontal physics, and the state's routine (which changes the speed, then moves Mario), sets his moving direction from the speed's sign, and only then runs the background collision routine, which lands him. | src/prg.asm L4372–4378src/prg.asm L4391–4415src/prg.asm L4712–4727src/prg.asm L4735–4744 | Code |
| Mario's horizontal fraction byte sits below his speed byte, so acceleration works in 1/256 of a sixteenth (1/4096 px/frame) and carries into the speed byte, but the horizontal-move routine moves Mario by the speed byte alone. | src/prg.asm L5102–5108src/prg.asm L6492–6494 | Code |
The friction table gives Mario's acceleration and braking per frame: $E4 running, $98 walking, and $D0 walking while still fast from a run, in 1/4096 px/frame. | src/prg.asm L4877–4878src/prg.asm L5037–5041 | Code |
On the ground the horizontal physics routine uses the running row (cap $28, acceleration $E4) while B and the direction Mario moves in are held and for the 9 frames after B goes up; otherwise the walking row (cap $18, $98, or $D0 while a running flag is set or his speed is $21 or more). | src/prg.asm L4991–5026src/prg.asm L4870–4874src/prg.asm L5055–5074src/prg.asm L126–136 | Code |
The horizontal physics routine doubles the acceleration whenever Mario faces away from the direction he moves, so a turn brakes at $130, $1A0, or $1C8 a frame. | src/prg.asm L5042–5047 | Code |
| When a held direction carries the speed to its cap or past it, the friction routine sets the speed byte to the cap, so a speed above the cap drops to it in one frame. | src/prg.asm L5109–5114src/prg.asm L5122–5126 | Code |
| With neither Left nor Right held on the ground, the friction routine brakes Mario by the frame's acceleration toward zero and stops once the speed byte reaches 0, leaving the fraction byte as it is. | src/prg.asm L5091–5101 | Code |
On the ground, the animation-speed routine zeroes Mario's speed and turns his moving direction to his facing one when a button other than A is held, the d-pad's Left/Right bits differ from his moving direction, and his speed is below $0B. | src/prg.asm L5064–5083 | Code |
| On the ground the on-ground routine turns Mario toward a held Left or Right before friction runs; the jumping and falling routines change his facing only while he swims. | src/prg.asm L4735–4740src/prg.asm L4771–4784 | Code |
On the ground, Down with Left or Right clears both, so Mario neither walks nor crouches, and friction slows him as it does with the d-pad released. The skid check still reads the buttons held, though, so unless he holds the way he is moving it stops him dead below $0B. Big Mario holding Down alone crouches. | src/prg.asm L4379–4390src/prg.asm L4702–4711src/prg.asm L4735–4741src/prg.asm L5091–5098src/prg.asm L5005–5007src/prg.asm L5064–5083 | Code |
Measured from a standstill in World 1-1, Mario reaches $18 on frame 40 walking and $28 on frame 45 running, and let go at those speeds he stops in 40 and 49 frames. | src/prg.asm L4877–4878src/prg.asm L5042–5047src/prg.asm L4870–4874src/prg.asm L5028–5036 | Verified |
In the air the horizontal physics routine takes the running cap $28 and acceleration $E4 while Mario's speed is $19 or more, and the walking cap $18 with $98 (or $D0 while a running flag is set) below it, whatever B does. | src/prg.asm L4991–4999src/prg.asm L5013–5023 | Code |
| The air steering routine runs the friction routine only while Left or Right is held, so in the air a held direction accelerates Mario toward it up to the cap and a released d-pad keeps his speed. | src/prg.asm L4783–4788src/prg.asm L4748–4751 | Code |
Because a jump keeps Mario's take-off facing, steering back slows him at the plain rate until he moves the other way, then at double the rate ($1A0 from a run). | src/prg.asm L5042–5047src/prg.asm L4771–4784src/prg.asm L4877–4878src/prg.asm L4991–4999src/prg.asm L5013–5023src/prg.asm L5037–5041src/prg.asm L4402–4408src/prg.asm L4784–4786 | Verified |
| The jump setup leaves Mario's horizontal speed alone and sets the jumping state before the horizontal physics routine runs, so the press frame already uses the air rules, and the take-off speed only picks the jump row. | src/prg.asm L4941–4943src/prg.asm L4984–4991 | Code |
| On landing, the background collision routine snaps Mario's Y to a 16 px row and zeroes his vertical speed and its fraction, then sets the ground state; his horizontal speed is untouched, and the ground rules apply from the next frame. | src/prg.asm L11221–11233src/prg.asm L11214–11220 | Verified |
| The bounding-box table gives Mario a box for touching objects from 2 to 14 px across his sprite, and 8 to 32 px down when big or 20 to 32 px crouching; small Mario's runs from 3 to 13 across and 20 to 32 down. | src/prg.asm L12024–12029src/prg.asm L4393–4401 | Code |
| Against the level, the background collision routine tests a head point at x+8, feet at x+3 and x+12 (y+32), and sides at x+2 and x+13, at y+8 and y+24 when big and both at y+24 when small or crouching. | src/prg.asm L12295–12309src/prg.asm L11131–11142 | Code |
| A frame-by-frame model of the horizontal physics, animation-speed, and friction routines reproduces Mario's speed bytes, facing, moving direction, and run timer on every frame of 17 probed traces, walking, running, skidding, crouching, and jumping. | src/prg.asm L4991–5047src/prg.asm L5055–5089src/prg.asm L5091–5131 | Verified |
| A hit on big Mario sets the injury timer to 8, and enemy contact is skipped until it is back at 0. It is one of the interval timers, which the timer routine counts down once every 21 frames, so the window lasts 8 such ticks, 148 to 168 frames while the game's timers run. | src/prg.asm L10583–10592src/prg.asm L126–139src/ram.asm L60–78 | Code |
| The block-buffer lookup turns a point into a block lookup: it adds the point's offsets to Mario's position, takes the block column from X ÷ 16 and the block row from (Y & $F0) − 32, and returns the metatile stored there, with the low nybble of Mario's Y (head and feet) or X (sides) as the point's place inside its block. | src/prg.asm L12321–12362 | Code |
| Mario's background-collision routine runs after the frame's movement (smb1/frame-order). It first sets a swimming Mario's state to 1, and any other Mario in the normal or climbing state to falling (2), then tests the head, then the two foot points, then the side points, the left pair before the right. The first side point that finds a tile ends the check, though the first point of each pair passes over a pipe's top or a climbable. The side check then stops Mario unless the tile is a hidden block, a coin, a climbable, or a jumpspring in motion, or Mario, in the normal state and facing right, meets the bottom of a sideways or water pipe. | src/prg.asm L11108–11118src/prg.asm L11235–11269src/prg.asm L11287–11297src/prg.asm L11149–11154src/prg.asm L11180–11195src/prg.asm L11202–11204src/prg.asm L11273–11286src/prg.asm L12295–12302src/prg.asm L12317–12319 | Code |
| Mario leaves a ledge on the frame his horizontal move leaves neither foot point over a block; the falling state that the background collision routine sets first then stays, so he ends that frame in the air, with a vertical speed of 0, and starts falling on the next. Walking right, the left foot point decides, so he walks 5 px past the edge (measured); walking left, the right foot point decides, 4 px past it (from the code's points). | src/prg.asm L11185–11195 | Verified |
| A falling Mario's gravity is a stored falling gravity, which the falling routine copies in every frame. Each area's entrance sets it to $28 (40/256 px/frame²), and only a jump changes it, to its row's falling gravity, so a walk-off before any jump falls at $28 and one after a jump at that jump's falling gravity. | src/prg.asm L2324–2328src/prg.asm L4748–4751src/prg.asm L4965–4969 | Verified |
| When a foot point finds an ordinary solid block and Mario isn't moving up, the background collision routine lands him if his Y is less than 5 px into the block's 16 px row; 5 px or more, it calls the push-back routine in his moving direction instead, which pushes him 1 px back unless he is already moving away, and leaves without checking his sides. | src/prg.asm L11202–11220 | Code |
| A side point in a block calls the push-back routine, which moves Mario 1 px away from the block and zeroes his speed byte, unless he is already moving away; either way it clears that side's d-pad bit in a collision byte, which the next frame's friction routine ANDs with the d-pad, so the next frame's friction ignores the direction into the wall. | src/prg.asm L11547–11584src/prg.asm L5091–5093 | Verified |
| Mario can jump off a wall because the foot check counts a block in the wall's side as ground. If his move into a wall puts a foot point in a wall block while he is falling and less than 5 px below a block boundary, the background collision routine lands him there; he starts the next frame on the ground, so a fresh press of A then jumps. | src/prg.asm L11214–11233src/prg.asm L4921–4923 | Code |
| A wall jump's press has to come on a frame that starts with Mario caught on the wall's side. Measured in the cartridge with big Mario, the window was one frame for a walking jump into a wall laid into World 1-1's start, two for a running hop into the level's first pipe, unedited, and one for a running hop from the bricks into World 2-1's last wall; a press on the catch frame itself, or one frame after the window, did nothing. | src/prg.asm L11214–11217src/prg.asm L11550–11575src/prg.asm L11221–11233src/prg.asm L4921–4923 | Verified |
| World 1-1's first four pipes stand at block columns 28, 38, 46, and 57, each two blocks wide, with their tops on rows 9, 8, 7, and 7, so 2, 3, 4, and 4 blocks above the floor; the fourth is the one Mario can enter. | src/levels/objects.asm L184–188src/prg.asm L2838–2844src/prg.asm L2956–2964src/prg.asm L3462–3468 | Code |
| World 2-1 ends with a column of solid blocks two wide and ten high, at block columns 190 and 191 from the level's start, rows 1 to 10, so its top is 160 px above the floor. Two columns before it is a jumpspring (column 188); over the ground in front of that are two bricks on row 7 (columns 185 and 186, tops 64 px up) and, over the second, a hidden coin block on row 3 (top 128 px up). | src/levels/objects.asm L231–244src/prg.asm L3022–3062src/prg.asm L3734–3755 | Verified |
| No jump from the floor or the bricks in front of it clears World 2-1's last wall, and a wall jump from the bricks does. Measured in the cartridge with big Mario, starting from the wall's screen: after a running hop onto the bricks, a running jump from them with A held peaked 147 px above the floor, short of the wall's top at 160 (computed from the level data), and he next stood on the floor. From the floor, by arithmetic rather than a run, his highest jump's 83 px rise can't reach 160. A 4-frame hop from the bricks brought his foot to the wall's side 80 px up on the way down, at the end of frame 91; a press on frame 92 jumped him to 163 px and onto the top, and presses on frames 91 and 93 didn't jump. The level has another way up without a wall jump: the hidden coin block over the second brick, once hit, is a ledge 128 px up (computed), and a jump from it reaches the top. | src/prg.asm L11214–11217src/levels/objects.asm L231–244src/prg.asm L3022–3029 | Verified |
While Mario moves up, the background collision routine tests a single head point, the first of its point set (smb1/bg-points), after the frame's movement and before the feet. It acts only if his vertical speed byte is negative, the low nybble of his own Y is 4 or more, and his Y is at least $20 (big) or $10 (small, or big and crouching), and only if the point's metatile is nonzero and not a coin. So one block at most is hit per frame: when his head spans two blocks, the one under the point is hit and the other is ignored. Measured: big Mario under a brick that covered only his box's left part rose past it untouched. | src/prg.asm L11149–11161src/prg.asm L11097–11098src/prg.asm L11145–11148 | Verified |
| When the head point finds a block in the solid ranges (smb1/head-kinds), the background collision routine sets Mario's vertical speed byte to 1 and plays the bump sound; his position and the speed's fraction are left as they are, so the frame ends with his head inside the block and he starts down on the next. In water levels, and while the block bounce timer runs (smb1/bounce-timer), a brick or ? block gets the same speed of 1 without the sound and without being hit. | src/prg.asm L11162–11178 | Verified |
The solid-metatile check splits what a head can meet by the metatile's top two bits: at or above $10, $61, $88, or $C4 in its group is solid (smb1/head-solid); below is hit (the head-hit routine). The collision map stores nothing below $10, $51, $88, and $C0 in the same groups, so the hit kinds are $51–$60 (bricks, the cracked-rock ground, bricks with items, hidden blocks) and $C0–$C1 (? blocks); a used block ($C4), the solid blocks from $61, and pipes are solid. | src/prg.asm L11588–11594src/prg.asm L2799–2819src/prg.asm L1634–1651src/prg.asm L1676–1681 | Code |
The head-hit routine bumps the block unless Mario is big and the metatile is missing from a list of ? blocks ($C0, $C1), hidden blocks ($5F, $60), and bricks with items ($55–$5E); then it breaks it (smb1/brick-break). So big Mario breaks plain bricks ($51–$53) and bumps the rest, and small Mario bumps everything. Size is the player-size byte, so by the code a crouching big Mario breaks bricks too (not probed). Measured: big Mario, standing, broke a brick and bumped a ? block and a hidden block; small Mario bumped a brick and a ? block. | src/prg.asm L6151–6159src/prg.asm L6168–6176src/prg.asm L6218–6224src/prg.asm L6304–6320 | Verified |
A bump sets Mario's vertical speed byte to 0, keeping the fraction, and starts a block object at the block's row moving up at 2 px/frame under a gravity of $50/256 px/frame². The object moves on the hit frame itself, after the player; measured against its row, it reads −2, −4, −6, −7, −7, −8, −8, −8, −7, −6, −5, −4, −2, 0 px on the hit frame and the 13 after, and it ends when its Y's low nybble is under 5. The block's cell holds $23 from the hit frame, and the next frame's block metatile updater writes the block back: a used block ($C4) for ? blocks, hidden blocks, and item bricks, the metatile itself for a plain brick or ground block that small Mario hit. Measured: the cell held $23 for 14 frames. | src/prg.asm L6249–6258src/prg.asm L6170–6203src/prg.asm L6430–6444src/prg.asm L6619–6623src/prg.asm L4101–4109src/prg.asm L6451–6470 | Verified |
| Every head hit that reaches the head-hit routine, bump or break, sets the block bounce timer to 16, a frame timer. Until it is back at 0, the head check treats bricks and ? blocks as solid without the sound (smb1/head-solid), so no second block can be bumped or broken for 16 frames. Measured after five bumps: 16 on the hit frame, 0 sixteen frames later. | src/prg.asm L6201–6202src/prg.asm L11166–11167src/ram.asm L60–65src/prg.asm L126–136 | Verified |
During a bounce, and on the frame after a brick breaks, the block's cell holds $23, and every test of the background collision routine takes its solid path for it: the head check's solid range starts at $10 in group 0; the foot check's exceptions (climbable from $24, the axe $C5, hidden blocks $5F and $60) miss it, so it lands Mario or pushes him back; and the side check's exceptions (hidden blocks, climbable, coins $C2 and $C3, jumpspring $67 and $68, the pipe openings) miss it, so it ends in the routine that stops his move. | src/prg.asm L1611src/prg.asm L11202–11221src/prg.asm L11273–11298src/prg.asm L11331–11332src/prg.asm L11461–11464src/prg.asm L11486–11489src/prg.asm L11596–11597 | Code |
Breaking a brick sets Mario's vertical speed byte to −2, adds 50 points, spawns debris (smb1/brick-debris), and flags the cell, which holds $23 meanwhile, to be cleared to 0. The clearing comes on the next frame's block metatile updater, after that frame's background collision routine, so the next frame's head check still meets $23 and sets the speed to 1: a break stops the jump one frame later, 1 or 2 px higher (computed), not passing through. Measured: 1 px higher, speed 1, and the cell 0 by the end of that frame, with a second brick stacked above never reached. | src/prg.asm L6324–6334src/prg.asm L6170–6172src/prg.asm L6160src/prg.asm L6451–6470 | Verified |
The debris routine makes the debris from two block objects at the block's place, the upper starting up at 6 px/frame and the lower, 8 px down, at 4 px/frame, both with horizontal speed $F0. The block-object routine moves each under the block gravity ($50/256 px/frame², fall cap 8) and draws them with the chunk-drawing routine, which puts each object's two sprites at its own X and at the original X mirrored across it, plus 6, so four chunks fly apart. | src/prg.asm L6362–6386src/prg.asm L6400–6412src/prg.asm L6612–6623src/prg.asm L13501–13522 | Code |
Big Mario breaks a ground block he hits from below: the overworld's terrain metatile, $54 (cracked rock), is in the hit range and not in the list of blocks that even big Mario only bumps (? blocks, hidden blocks, bricks with items; smb1/bump-or-break), so the game treats it as a plain brick (smb1/bump-or-break). Measured with a $54 block written 4 rows above World 1-1's floor: big Mario broke it, for 50 points, and small Mario bumped it, the block bouncing and coming back as $54. | src/prg.asm L2639–2640src/prg.asm L1637 | Verified |
A brick with coins ($58, $5D) starts a coin timer at 11 on its first hit. Every bump gives a coin; while the timer runs the brick comes back as itself, and the first bump after it reaches 0 leaves a used block. It is an interval timer, counted down once every 21 frames, so the brick pays out for 11 such ticks, 211 to 231 frames (computed). | src/prg.asm L6177–6194src/prg.asm L6259–6276src/prg.asm L6304–6309src/prg.asm L126–136src/ram.asm L60–77 | Code |
| Over its first 216 block columns, through the castle, World 1-1's collision map, as the probe reads it from the cartridge's block buffer, holds a floor with three pits (2, 3, and 2 blocks wide), six pipes (2, 3, 4, 4, 2, and 2 blocks tall), four 4-step stairs and an 8-step one, 13 ? blocks, 30 bricks, a hidden 1-up block, and the flagpole at column 198 on a one-block base. | src/levels/objects.asm L184–197 | Verified |
| Mario catches the flagpole when his lower side collision point finds a pole metatile and the low 4 bits of his own x position (not the point's) are 6 to 9, so the pole is 4 px thick in each 16. His right-hand points are 13 px right of that x, so running right he catches World 1-1's pole (block column 198, x 3168 to 3183) with his x at 3158 to 3161. | src/prg.asm L11371–11384src/prg.asm L12354–12358src/prg.asm L12298–12308src/prg.asm L11242–11281src/prg.asm L11235–11244src/prg.asm L12295–12296 | Verified |
| World 1-1's enemy list holds 16 Goombas and one Green Koopa Troopa. Four Goombas stand alone, at columns 22 and 40 on the floor (row 11) and 80 and 82 on the high bricks (row 3), and the Koopa is at column 107 on the floor. The other 12 come in six pairs, keyed to columns 54, 100, 117, 127, 131, and 177, which appear at the screen's right edge on the floor. On one run through the level with the star held, measured in Mesen, 16 of the 17 appeared: the pair at column 131 got one Goomba, because only one of the five enemy slots was free. | src/levels/enemies.asm L89–94src/prg.asm L7770–7774 | Verified |
| An enemy in Super Mario Bros.'s level data appears once the screen's right edge plus 48 px, rounded down to a 16 px column, reaches the enemy's column. A single enemy appears at its column's left edge, its y 8 px below its row's (row × 16 + 8) for an enemy id below $15, the Goomba's and the Koopa Troopa's among them, and a group appears at the screen's right edge, each member 24 px to the right of the last. Each one takes a free slot of the five, and a group member that finds none is dropped, not delayed (measured in Mesen). | src/prg.asm L6878–6885src/prg.asm L6930–6943src/prg.asm L7803–7831src/prg.asm L6858–6875src/prg.asm L7033–7040 | Verified |
| Super Mario Bros.' screen scrolls only to the right, by as many px as Mario moved right this frame, once his x on screen (his x less the screen's left edge, as of when he was last drawn) is 80 px or more; below 112 px a move of 2 px or more scrolls 1 px less. A scroll lock or a recent bump into a wall's side stops it, and a moving platform's push counts as his movement. While a springboard is animating, Mario doesn't move and its animation counter counts as his movement instead. | src/prg.asm L4165–4215src/prg.asm L4740–4743src/prg.asm L13892–13895src/prg.asm L4788–4789src/prg.asm L6487–6533src/prg.asm L14100–14155src/ram.asm L311–312 | Code |
| An enemy whose column is already left of the screen's right edge when the level data reaches it is skipped and never appears. With the game's hard-mode flag set, groups of Goombas come as Buzzy Beetles. | src/prg.asm L6914–6928src/prg.asm L7017–7031src/prg.asm L7776–7781 | Code |
| A Goomba starts walking left at 0.5 px a frame (1 px every second frame), and turns around at the same speed when it walks into a pipe or into another Goomba; two Goombas that meet both turn on the same frame. Walking off a ledge, it keeps its x speed and falls, its y speed growing by 61/256 px a frame every frame until its whole part reaches 3 px a frame (measured in Mesen). | src/prg.asm L7141–7152src/prg.asm L6554–6563src/prg.asm L10872–10896src/prg.asm L11845–11868 | Verified |
| Enemies test for touching each other only on odd frames and never in water levels. A touch turns both around for any enemy with an id below 7 but the Hammer Bro (Goombas, Koopa Troopas, and Buzzy Beetles), and for Spinies and jumping Green Paratroopas. If one of them is in a state from 6 up, as a kicked shell is, the other is knocked out instead, and an enemy already knocked out touches nothing. With the game's hard-mode flag set, a Goomba walks at 0.75 px a frame. | src/prg.asm L10740–10746src/prg.asm L10813–10870src/prg.asm L10872–10885src/prg.asm L7141–7150 | Code |
| A Goomba dies when Mario touches it while moving down: it is flattened, Mario bounces up with a y speed of −4, and, with the game's hard-mode flag clear, the flat Goomba is erased two ticks of the 21-frame interval timer later, 22 to 42 frames. A fireball, a kicked shell running into it, Mario touching it while the star is on, or a block bumped under it knock it out instead: it takes the defeated state and falls off the screen. Any other touch hurts Mario, unless the stomp timer is running, which makes it a stomp, or his injury timer is, which makes it nothing. | src/prg.asm L10555–10576src/prg.asm L10680–10697src/prg.asm L8408–8416src/prg.asm L10497–10500src/prg.asm L10292–10309src/prg.asm L10334–10354src/prg.asm L10813–10846src/prg.asm L11945–11949 | Code |
| A Goomba's hit box is 10 px wide and 6 px tall: from 3 to 13 px right of its x and from 14 to 20 px below its y (measured in Mesen). | src/prg.asm L7116–7118src/prg.asm L7189–7191src/prg.asm L12026–12036 | Verified |
| World 1-1 has 13 ? blocks: 11 placed one at a time and a row of two at columns 129 and 130. Three of the single ones hold a power-up: the left ? block in the first brick row (column 21), the ? block in the bricks past the first pit (column 78), and the high ? block at column 109. The other ten, the row's two among them, hold coins. | src/levels/objects.asm L185–195src/prg.asm L2837–2844src/prg.asm L3004–3010src/prg.asm L2908–2916src/prg.asm L2944–2954src/prg.asm L2968–2971src/prg.asm L3022–3052src/prg.asm L3497–3508src/prg.asm L3870–3893src/prg.asm L2977–2980src/prg.asm L2880–2884 | Code |
| A ? block's power-up is a mushroom when Mario is small and a fire flower when he's big. It appears 8 px above the block's top, behind the background, on the frame he bumps it, and rises a pixel on every frame whose frame counter is a multiple of 4: 17 px over 17 such frames. On the last it starts moving right at 1 px a frame and comes in front of the background. Until it has risen 5 px it isn't drawn and can't be touched. | src/prg.asm L6281–6290src/prg.asm L6050–6085src/prg.asm L6110–6136 | Verified |
| Once out, a mushroom moves as a walking enemy does: 1 px a frame, turned around by a solid block at its side, falling off an edge with gravity of 61/256 px a frame per frame up to 3 px a frame, and landing on a block its foot (8 px across, 24 down) finds when its y is 8 to 12 px into a tile row. A fire flower stays where it rose. | src/prg.asm L6091–6104src/prg.asm L8335–8340src/prg.asm L6554–6563src/prg.asm L6599–6606src/prg.asm L6625–6628src/prg.asm L6681–6694src/prg.asm L11636–11641src/prg.asm L11658–11669src/prg.asm L11966–11969src/prg.asm L12298–12308src/prg.asm L11674–11678src/prg.asm L11743–11756src/prg.asm L11805–11818src/prg.asm L11904–11916src/prg.asm L11822–11839src/prg.asm L11845–11865src/prg.asm L11869–11881src/prg.asm L11887–11888src/prg.asm L10886–10891 | Verified |
| Mario takes a power-up when its box, 2 to 14 px across its sprite and 9 to 21 down, touches his (edges count), tested only on frames with an even frame counter. Small Mario becomes super and super Mario fiery; either way the game stops for the change and puts him in the on-the-ground state, wherever he is. | src/prg.asm L10468–10485src/prg.asm L10492–10496src/prg.asm L10411–10414src/prg.asm L6067–6068src/prg.asm L12126–12147src/prg.asm L12026–12030src/prg.asm L12205–12211src/prg.asm L12220–12235src/prg.asm L10427–10456src/prg.asm L10599–10604 | Verified |
| Taking a mushroom stops the game for the next 59 frames: no timer runs and Mario doesn't move, though the frame counter keeps counting. His size changes on the 7th of them, and play resumes on the frame after the 59th. Taking a fire flower stops it for 63 frames. | src/prg.asm L121–141src/prg.asm L4548–4556src/prg.asm L4572–4580src/prg.asm L4592–4604src/prg.asm L4266–4279src/prg.asm L10599–10604 | Verified |
| At the movement lab's start in World 1-1 (the game started from power-on, Mario standing still, then 10 frames), the frame counter reads 166, and the leftover sub-pixel part of a power-up's fall is 0. | src/prg.asm L140–141src/ram.asm L334–336 | Verified |
| On land in Super Mario Bros., A jumps, and B held while walking runs; Fire Mario's B also throws a fireball. Left and Right walk, and Down crouches big Mario, Super or Fire, on the ground; small Mario doesn't crouch. Start on controller 1 pauses the game and resumes it. | src/prg.asm L4913–4918src/prg.asm L5000–5010src/prg.asm L5024–5025src/prg.asm L5142–5161src/prg.asm L4372–4378src/prg.asm L4702–4711src/prg.asm L213–216src/prg.asm L186–188src/prg.asm L4080–4083 | Code |
| In Super Mario Bros.'s water areas, A swims: each press sends Mario up a stroke, except while he is still rising after the last stroke's timer has run out. B no longer runs there, but Fire Mario's B still throws fireballs. The Control Pad moves him and crouches big Mario on the floor, and Start pauses as on land. Below a line near the bottom of the screen, or off the screen vertically, the game ignores the Control Pad, A, and B, though Start still pauses. | src/prg.asm L2337–2341src/prg.asm L4921–4930src/prg.asm L5000–5003src/prg.asm L4361–4371src/prg.asm L213–216 | Code |
| On Super Mario Bros.'s title screen, Select moves the mushroom between the one- and two-player games and Start begins, from either controller. Holding A with Start begins at the first area of the world where the last game ended. Once the game has been beaten and B pressed on the ending screen, B on the title screen steps through the worlds. | src/prg.asm L330–353src/prg.asm L364–376src/prg.asm L402–407src/prg.asm L428–433src/prg.asm L622–626src/prg.asm L638–645 | Code |
| The Lost Levels keeps Super Mario Bros.'s movement tables for Mario byte for byte. Take-off speeds, held and falling gravities, frictions, and top speeds all match, and when the game rewrites the gravity and friction tables for the chosen player, Mario's bytes in its second copy are the same. | src/prg.asm L4858–4878 | Code |
The jump routine starts a jump only while the player state is 0, on the ground, or while the player is swimming, as Super Mario Bros.'s does. Walking off a ledge doesn't keep that state: the player's background collision routine sets a player in the normal or climbing state to falling (or, swimming, to state 1) on each frame of play before it looks for ground, and only landing on a block sets the state back to 0, so out of water a jump can't start after walking off a ledge. The background check skips that step only during the game's scripted routines (engine subroutines 0 to 3 and $0B). | src/prg.asm L4921–4925 | Code |
| A hit on big Mario sets the injury timer to 8, as in Super Mario Bros., and the timer counts down once every 21 frames with the interval timers, through the same timer loop as Super Mario Bros.'s. | src/prg.asm L10583–10592src/prg.asm L126–139 | Code |
The code keeps the primary hard mode flag's checks, which turn Goombas into Buzzy Beetles, start walking enemies faster ($F4 against $F8), and revive stomped enemies sooner and send them off faster. Nothing in The Lost Levels' code sets the flag, and starting a game clears it, so none of these takes effect. Super Mario Bros. sets it from its world select flag when a game starts. | src/prg.asm L415–416 | Code |
| The Lost Levels' boot, NMI and pause code is Super Mario Bros.'s with these changes: the reset code sets mirroring through the disk drive's control register, keeps the world number across the reset and sets the BIOS's IRQ flag; the NMI arms the drive's timer IRQ to split the status bar from the level, where Super Mario Bros. waits for the sprite 0 hit, and its VRAM address table is one table of 31 words where Super Mario Bros. has low and high byte tables of 19; the pause routine allows a pause in game-mode task 4 instead of 3, the game mode's task list having gained a disk task at its head. The sprite shuffler and the routine that moves all sprites off screen are byte for byte the same, and the operating-mode dispatch differs only in its addresses. | src/prg.asm L160–164src/prg.asm L54–69src/prg.asm L206src/prg.asm L5–312 | Code |
| The castle victory sequence is Super Mario Bros.'s with these changes: on world 8, which world D also uses, the victory mode runs a second task list that loads the ending from disk; its set-up also sets the world's bit in a byte of completed worlds and queues the castle-clear music; the victory message printer loses Super Mario Bros.'s world 8 branch and its victory music, and gains a castle award that counts the remaining time into points. The title screen drawer, which sits in the middle, shrinks to a few instructions that queue a layout held in the program, where Super Mario Bros. copies it out of CHR ROM. The player's victory walk keeps every instruction; only its addresses and one branch's distance differ. | src/prg.asm L564–566src/prg.asm L594src/prg.asm L1007src/prg.asm L490–617 | Code |
| The score numbers, the screen setup tasks, the status bar and the game's text are Super Mario Bros.'s with these changes: the player color routine no longer picks a palette row by the current player (Super Mario Bros.'s table has a row for Luigi); the bottom status line goes through a new routine that shows worlds A to D as letters; the intermediate screen blanks the screen after the world and lives screen in world 9, and the time-up screen writes its text and resets the screen timer itself where Super Mario Bros. jumps into the intermediate screen's code; the title-screen part of the buffer-clearing and icon routine moves to the title code; the screen task list gains a demo reset; the game's text drops the two-player and Luigi texts and adds CONTINUE and RETRY to the game-over screen. The screen initializer, the intermediate set-up, the area palette and alternate palette routines, the top status line, the area parser's task control and the screen timer reset keep every instruction, with only addresses changed. | src/prg.asm L848–850src/prg.asm L944src/prg.asm L1042src/prg.asm L656–1220 | Code |
| The background renderer, the metatile tables and the area palettes are Super Mario Bros.'s with the metatiles renumbered: The Lost Levels inserts new metatiles, so the block replacement routine compares against shifted numbers ($56, $4F, $5C and $50 for Super Mario Bros.'s $58, $51, $5D and $52), and the metatile graphics table moves some entries and adds others. The palette data region also holds two new messages. The attribute table renderer is byte for byte the same, and the area graphics renderer and the palette color rotation differ only in their addresses. | src/prg.asm L1486src/prg.asm L1233–1753 | Code |
| The jump table dispatcher, the name table initializer, the joypad reader and the screen updater are Super Mario Bros.'s, instruction for instruction: the dispatcher is byte for byte the same, and the other three differ only in the addresses of their calls, jumps and tables. | src/prg.asm L1820–1973 | Code |
| The status bar numbers, game setup, lives and game over are Super Mario Bros.'s with a new game-over dispatch among them and these changes: the status bar's digit tables lose the second player's entries; the top score update checks one score where Super Mario Bros. checks two; the digit math routine drops a compare with zero before its BEQ; the default sprite offsets lose the sprite 0 data; the area initializer loads the player's physics and sets the secondary hard mode flag from 4-4 on and in all of worlds A to D, where Super Mario Bros. sets it from 5-3 on or once the primary hard mode flag is set; the secondary game setup sets the name table and switches on the status bar's IRQ split, where Super Mario Bros. sets the second player's lives and switches on the sprite 0 check; the memory initializer also spares $0100-$0108; the lose-a-life routine reads its own halfway pages and no longer swaps players; the game-over routine opens the continue-or-retry menu (or, in world 9, ends the game) where Super Mario Bros. ends the game on Start or when the screen timer runs out and then hands over to the other player if they have lives left. The area music selection and the entrance's game timer set-up keep every instruction, though the level timer's digits moved from $07F8 to $07EC. | src/prg.asm L2087src/prg.asm L2050src/prg.asm L2172–2179src/prg.asm L2245src/prg.asm L2441src/prg.asm L2472–2473src/prg.asm L1982–2534 | Code |
| The area parser and its object builders are Super Mario Bros.'s, with most changes in the metatile numbers they write, which shift with the renumbered metatiles (bridges, flagpole, coins, bricks, cannons, stairs, blocks, water pipe). Beyond those: the object jump table gains entries, the wind on and off commands among them, so three offsets into it change; the warp zone's scroll-lock object picks the warp zone's destination by world, level and area; the third ledge style uses metatiles $8A-$8C and draws no stem, where Super Mario Bros.'s mushroom ledge uses $19-$1B with a stem (and the renderer of an object's lower part drops its stem checks); the vertical pipes place a piranha plant through a shared set-up routine, with no exception for world 1-1; the jumpspring builder places nothing when no enemy slot is free. The column position increment, the area attribute changer, the enemy remover and the object position helpers are byte for byte the same. | src/prg.asm L2925src/prg.asm L3215src/prg.asm L3229src/prg.asm L3852–3855src/prg.asm L3428–3430src/prg.asm L2539–3938 | Code |
| The game core and the scroll handler are Super Mario Bros.'s with three changes: the game mode's task list gains the disk routines at its head and the core no longer reads the current player's saved joypad bits; each frame of play calls the wind simulation once a disk file beyond worlds 1 to 4 is loaded; the scroll handler waits for the status bar's timer IRQ before it scrolls and keeps the name table in a byte of its own, where Super Mario Bros. sets it in its PPU control mirror. The screen position routine is byte for byte the same. | src/prg.asm L4081–4083src/prg.asm L4206–4209src/prg.asm L4081–4262 | Code |
| The player's control and movement code is Super Mario Bros.'s, instruction for instruction in 14 of its 19 regions, with these changes: the on-ground state and the jump and swim code move the player through a new move routine, which lets the wind push them once a disk file beyond worlds 1 to 4 is loaded; the physics routine's friction table moves up to follow the fall forces, inside the 17 bytes that the physics loader overwrites with Mario's or Luigi's set; the level-end routine queues the level-end music once, guarded by a new flagpole music flag, where Super Mario Bros. queues it whenever the scroll lock is set, and sets the hidden 1-up's flag on 10 coins in any world, where Super Mario Bros. reads a per-world table, and starts world 9 over after 9-4; the player death routine shares one RTS. The entrances, pipes, size change, injury blink, flagpole slide, falling, climbing, animation speed and friction differ only in their addresses. | src/prg.asm L4788–4789src/prg.asm L4686src/prg.asm L4660–4663src/prg.asm L4267–5135 | Code |
| Fireballs, the level timer and the stage objects are Super Mario Bros.'s with these changes: the game timer tests the player's height with BPL instead of BCS and points at the timer digits' new place; the warp zone object no longer counts up its warp zone control byte; the flagpole routine gives a life for the new sixth flagpole score; the jumpspring handler launches with the green springs' force on world numbers 2, 3 and 7; the vine handler erases the vine and its metatiles once it goes off the left of the screen. The fireball and whirlpool routines differ only in their addresses, and the vine set-up is byte for byte the same. | src/prg.asm L5324src/prg.asm L5342src/prg.asm L5364src/prg.asm L5143–5658 | Code |
| Cannons, hammers, coins, power-ups and blocks are Super Mario Bros.'s with the poison mushroom added and one player: the bumped block's contents table gains poison mushroom blocks and the mushroom-or-flower block code gains a poison mushroom block, which sets power-up type 4; the power-up handler walks types 4 and 5 like a mushroom; the bumped-block check checks 19 block metatiles where Super Mario Bros. checks 14; the coin and score routines use fixed offsets where Super Mario Bros. indexes by the current player; the head-collision and coin checks use the renumbered metatiles. The power-up set-up is byte for byte Super Mario Bros.'s, though the poison mushroom now passes through it, and so are the block position set-up and the brick chunk spawner; the cannons, hammers, jumping coins, brick shatter and bouncing blocks differ only in their addresses. | src/prg.asm L6312src/prg.asm L6011–6012src/prg.asm L5663–6474 | Code |
| The movement and gravity routines are Super Mario Bros.'s, instruction for instruction: the gravity routine and the drop platform's mover are byte for byte the same, and the other seven differ only in the addresses of their calls and jumps. | src/prg.asm L6482–6722 | Code |
| Enemy spawning and set-up are Super Mario Bros.'s with these changes: the loop command reads 12 loop entries where Super Mario Bros. reads 11, and takes each loop's number of checks from a new table where Super Mario Bros. special-cases world 7; the enemy data processor skips a check in world 9 and gives one enemy code a piranha plant set-up; the Hammer Bro set-up checks the world; the Lakitu and Spiny handler brings Lakitu back once his reappear timer reaches 3, where Super Mario Bros. waits until it reaches 7, and brings him back lower on the screen in worlds 7 to 9 and A to D; the Bowser set-up first erases any other Bowser; the piranha plant set-up patches the plant's palette and pipe distance, green in worlds 1 to 3 and red from world 4 and in A to D; the jumping paratroopa's set-up starts it at x speed $F4 where Super Mario Bros. uses $F8. Of its 27 regions, 15 differ only in their addresses and 5 are byte for byte the same. | src/prg.asm L6797src/prg.asm L6813–6815src/prg.asm L7275–7276src/prg.asm L7895src/prg.asm L6727–7901 | Code |
| The platforms' set-up, the enemy object loop, the enemies' movers, Bowser and the fireworks (32 regions) are Super Mario Bros.'s instruction for instruction, with two changes: the enemy movers' jump table sends enemy 4, the upside-down piranha plant, to a new mover of its own, where Super Mario Bros. has the normal enemy mover; the swimming Cheep Cheep's mover adds $40 to its vertical fraction each frame where Super Mario Bros. adds $20. Three of the regions are byte for byte the same, and the rest differ only in the addresses of their calls, jumps and tables. | src/prg.asm L8124src/prg.asm L8682–8683src/prg.asm L8689–8691src/prg.asm L7906–9574 | Code |
| The code from the star flag object through the off-screen bounds check is Super Mario Bros.'s with these changes: the star flag object sets off fireworks when the timer's last digit matches the coin tally's, where Super Mario Bros. matches the timer's last digit against 1, 3 and 6, and adds its points to the one player's score; the piranha plant mover moves red piranha plants (the patched palette) every frame; the balance platform leaves a platform alone when its partner is no balance platform; the off-screen bounds check treats upside-down piranha plants like upright ones. The fire bar spin is byte for byte the same, and the moving platforms differ only in their addresses. | src/prg.asm L9602–9611src/prg.asm L9643src/prg.asm L9579–10216 | Code |
| The collision code is Super Mario Bros.'s with the upside-down piranha plant, the poison mushroom and the renumbered metatiles added: the fireball, enemy, background and stomp checks treat the upside-down plant like a piranha plant; the power-up collision injures the player on power-up type 4; the injury routine also does nothing while the star's invincibility timer runs; the routine that handles player-enemy contacts checks for the cannon's Bullet Bill before the piranha plants and Podoboo, where Super Mario Bros. checks it after them; the stomp test decides a stomp with LDY, DEY, BPL on the vertical speed where Super Mario Bros. uses BMI and BNE (the two disagree only at speed $80); every stomp bounces the player through a new bounce routine, at vertical speed $FA, or $F8 off red paratroopas and flying green paratroopas, where Super Mario Bros. sets $FD after a stomp that defeats an enemy and $FC after one that demotes a paratroopa or knocks an enemy into its shell; the climbing handler gives a life for grabbing the flagpole when the coin tally's digits and the timer's last digit match; the pipe entry handler sends the player to the warp zone's one destination whichever pipe they take, where Super Mario Bros. picks by the pipe's x position; the coin-metatile handler's axe restores Mario's physics; the jumpspring landing check sets the downward vertical force to $70 as well as the vertical force; the player-hammer collision also skips while the player is off screen; the enemy-to-background collision bounces a power-up on a bumped block without stunning it and never demotes a piranha plant; the player's vertical check drops its test of how far down the screen the player is; one bounding box grows from $14 to $16. The platform collisions, the enemy landing routine, the side checks and the block buffer collision differ only in their addresses, and three regions, the player's collision core among them, are byte for byte the same. | src/prg.asm L10515–10520src/prg.asm L10556–10558src/prg.asm L10661–10662src/prg.asm L10695–10697src/prg.asm L11521–11529src/prg.asm L11066–11072src/prg.asm L10227–12360 | Code |
| The sprite drawing code is Super Mario Bros.'s with these changes: the power-up drawer draws every mushroom from tiles $D8, $DA, $DB and $FF where Super Mario Bros. uses $76-$79, and gives the poison mushroom, a fifth row, palette 3; the enemy graphics handler's tile table takes up $76-$79, and the handler also flips the upside-down piranha plants and colors the jumpsprings green on world numbers 2, 3 and 7; the player renderer plays the skid sound; the flagpole graphics handler's score table gains the 1-up; the vertical off-screen bits routine has two of its tables' halves swapped, its instructions unchanged; the block drawer uses a renumbered metatile. 12 regions, the player graphics handler among them, differ only in their addresses, and five, the sprite object drawer among them, are byte for byte the same. | src/prg.asm L12372–14386 | Code |
| The game menu and the demo are Super Mario Bros.'s, rewritten in part: the menu drops the one- or two-player choice and the world select, and starts the game at world 1, or at world A when A is held and the game has been beaten 8 times; Select switches between Mario and Luigi; the demo plays new button presses and durations through the same code. | src/prg.asm L336–337src/prg.asm L350src/prg.asm L328–485 | Code |
| The area pointer routines (loading the pointer, finding it, and getting the area data addresses) are Super Mario Bros.'s, with the area data address tables made tables of words (indexed with an ASL) where Super Mario Bros. keeps separate low and high byte tables; the tables themselves hold The Lost Levels' worlds, and the area data loopback table its 12 loop points. Of the level data, only the 9-byte pipe intro area is byte for byte Super Mario Bros.'s. | src/levels/objects.asm L247src/prg.asm L3948–4054src/levels/levels.asm L4–71 | Code |
| The sound engine is Super Mario Bros.'s with two new sounds in the noise handler: the skid, played on the triangle channel from its own frequency table, and the wind, played from a frequency and envelope table of its own; both tables sit after the square 2 handler. The engine's entry, the square 1 register dump, the square 1 sound effect handler and the music handler differ only in their addresses. | src/music-engine.asm L2–969 | Code |
SM2MAIN's music data is Super Mario Bros.'s less the victory theme: the headers lose the victory theme's header and their offsets shift by its five bytes, the residual header bytes differ, and the victory theme's data is gone from between the castle-clear music and the frequency tables, with two of the three unused bytes after it (the ending's music lives in SM2DATA3). The notes of every other song and the frequency, note-length and envelope tables after them are byte for byte the same. | src/music-data.asm L55–56src/music-data.asm L349–360src/music-data.asm L4–406 | Code |
| 1,299 bytes of The Lost Levels' music are Super Mario Bros.'s byte for byte: the last bytes of the music headers and the notes of every song SM2MAIN plays, from the star music through the ground music's parts, death, castle, game over, time running out, level end, underground, water and the castle-clear music. | src/music-data.asm L114–347 | Code |
The ending's sound engine in SM2DATA3 is a rewrite of Super Mario Bros.'s music handler that keeps its note and length code: it has no event or area music buffers and no time-running-out handling, steps through a list of patterns with a pattern counter, reading each pattern's header from a header table, has its own pause and silence code, and plays the ending's music on the disk system's wavetable channel as well as the square, triangle and noise channels, with its own waveform, envelope and modulation tables. | src/music-engine.asm L608–609src/music-engine.asm L625src/music-engine.asm L601–969 | Code |
The first 80 tiles of the character data, $00-$4F, are Super Mario Bros.'s byte for byte. | smb1.asm L33 | Code |
Sprite tiles $50-$FF are Super Mario Bros.'s but for 15: $5B, $76-$7B, $85, $86, $D8, $DA, $DB and $FD-$FF differ. | smb1.asm L33 | Code |
The font, background tiles $00-$23 (the digits and A to Z), keeps Super Mario Bros.'s layout, so the game's text spells with the same numbers, but every one of its 36 tiles differs from Super Mario Bros.'s. | smb1.asm L33 | Code |
Background tiles $24-$EB are Super Mario Bros.'s but for 65 of their 200: $28, $29, $2B-$2D, $30-$3C, $45, $47, $4B, $4C, $4E-$52, $5D, $5E, $6B-$76, $80, $81, $9B-$9E, $A0, $A1, $A9, $AA, $AF, $B4-$BD, $C0, $C1 and $CF differ. | smb1.asm L33 | Code |
In the music driver, a song entry sets a base into a note-length table and a length code's low 3 bits, added to that base, index it; a note indexes a table of 16-bit timer periods stored high byte first; and a square note that isn't a rest writes duty byte $82 and sweep byte $7F to its channel's control registers. Super Mario Bros.' music code does the same two things: a length code's low 3 bits, added to an offset, pick the note length, and a square-2 note that isn't a rest writes the same $82 and $7F to square 2's control registers. | src/music-engine.asm L925–931src/music-engine.asm L736–743src/music-engine.asm L118–120src/music-engine.asm L934src/music-engine.asm L949–950 | Code |