Loop
A ring of track that a fast character runs all the way around, which the level has to make solid on the way round but open on the way in.
Facts
- Games
- 3 · 1991–1994
- Evidence
- Code (7)
Guide (1) - Sources
- 4
On this page
A loop’s far side, the wall the character runs down on the way round, stands across the track they ran in on, so it has to be open on the way in and solid on the way round. Sonic the Hedgehog builds each loop from one piece of level in two versions, and a flag on Sonic picks the one he collides with, first the version with only the near side solid, then the far side1. The flag flips as he passes the top2.
Sonic the Hedgehog 2 gives every block of level solidity for two collision paths, with each player on one of them at a time3. Invisible lines move a player from one path to the other as he crosses them4. A loop usually has one at its middle, which acts only on a player on the ground, and another after it5. Sonic 3 & Knuckles keeps them, but a crossing counts only within 64 px of the line6.
Going round takes speed. On a wall or the ceiling below 2.5 px a frame, Sonic drops off and loses the d-pad for 30 frames7; Sonic 3 & Knuckles still drops a slow player near walls and ceilings8. Slope physics has the rest.
- Chunk swapSonic the Hedgehog (1991). Each loop's piece of level comes in two versions, and a flag on Sonic, flipped at the loop's top, picks the solid one.1,2
- Path switchSonic the Hedgehog 2 (1992). Invisible lines move Sonic between two collision paths, one for the way in and one for the way round.3,4,5Sonic 3 & Knuckles (1994). Sonic 2's invisible path lines, which now act only on a player within 64 px of them.6
Every claim about this mechanic, by game (7)
References
- ^ abCodesonicretro/s1disasm · Sonic Retro, “Sonic Physics Guide: Solid Terrain”LevelSizeLoad & BgScrollSpeed.asm 224–228; sub FindNearestTile & FindFloor & FindWall.asm 67–74, 24–26, 295–296
How we know
Each loop in Green Hill and Star Light is one 256 × 256 px chunk of level with two versions, and a loop flag on Sonic picks which one is solid under him. The zone's table names the loop chunks, Green Hill's
$B5and Star Light's$AAand$B4, their high bit marking them special in the layout; for a special chunk, with Sonic's loop flag set, the block lookup that the wall and floor searches call reads the chunk after it instead.224LoopChunkNums: ; loop loop tunnel tunnel 225 dc.b $B5, $7F, $1F, $20 ; Green Hill 226 dc.b $7F, $7F, $7F, $7F ; Labyrinth 227 dc.b $7F, $7F, $7F, $7F ; Marble 228 dc.b $AA, $B4, $7F, $7F ; Star Light
_inc/LevelSizeLoad & BgScrollSpeed.asm lines 224–228 at 15dfa3a · upstream ↗ 67.specialtile: 68 andi.w #$7F,d1 69 btst #sprite_looping_bit,obRender(a0) ; is object "behind a loop"? 70 beq.s .treatasnormal ; if not, branch 71 addq.w #1,d1 72 cmpi.w #$29,d1 ; is 256x256 chunk number $28? 73 bne.s .treatasnormal ; if not, branch 74 move.w #$51,d1 ; replace with $51
_incObj/sub FindNearestTile & FindFloor & FindWall.asm lines 67–74 at 15dfa3a · upstream ↗ 24 move.b (a1,d0.w),d1 ; get 256x256 chunk number 25 beq.s .blanktile ; branch if 0 (blank chunk) 26 bmi.s .specialtile ; branch if > $7F
_incObj/sub FindNearestTile & FindFloor & FindWall.asm lines 24–26 at 15dfa3a · upstream ↗ In Sonic 1, loop chunks are simply built different. When the Player enters the loop chunk from the left, only the right side of it is solid. As the Player goes around the loop, the entire chunk will swap for another half way and sets the left side solid instead.
Chunk Swapping · archived copy ↗ - ^ abCodesonicretro/s1disasm01 Sonic.asm 2058–2062, 2075–2085, 2090–2094, 2099–2135
How we know
Sonic's loop flag switches at the loop's top: on a loop chunk it clears in the chunk's first 44 px and sets from 224 px on; between them, a clear flag sets once his angle is
$01to$80($80upside down), and a set flag clears once his angle passes$80. On Star Light's second loop chunk,$B4, it clears while he is in the air. Off a loop chunk it clears, except on Green Hill's two roll-tunnel chunks, which force a roll and leave it as it is. Only Green Hill and Star Light run the check.2058Sonic_Loops: 2059 cmpi.b #id_SLZ,(v_zone).w ; is level SLZ? 2060 beq.s .levelhasloops ; if yes, check for loop chunks 2061 tst.b (v_zone).w ; is level GHZ? 2062 bne.w .return ; if not, return (level has no loops, so no need to check for them)
_incObj/01 Sonic.asm lines 2058–2062 at 15dfa3a · upstream ↗ 2075 cmp.b (v_256roll1).w,d1 ; is Sonic on a "roll tunnel" tile? (type A, entrance from the left) 2076 beq.w Sonic_ChkRoll ; if yes, force Sonic into a rolling state 2077 cmp.b (v_256roll2).w,d1 ; is Sonic on a "roll tunnel" tile? (type B, exit to the right) 2078 beq.w Sonic_ChkRoll ; if yes, force Sonic into a rolling state ⋮ 2080 cmp.b (v_256loop1).w,d1 ; is Sonic on a loop tile? (type A, entering from/exiting to the left) 2081 beq.s .chkifleft ; if yes, branch 2082 cmp.b (v_256loop2).w,d1 ; is Sonic on a loop tile? (type B, entering from/exiting to the right) 2083 beq.s .chkifinair ; if yes, branch ⋮ 2085 bclr #sprite_looping_bit,obRender(a0) ; clear loop flag (return Sonic to high plane)
_incObj/01 Sonic.asm lines 2075–2085 at 15dfa3a · upstream ↗ 2090.chkifinair: 2091 btst #status_in_air_bit,obStatus(a0) ; is Sonic in the air? 2092 beq.s .chkifleft ; if not, branch ⋮ 2094 bclr #sprite_looping_bit,obRender(a0) ; clear loop flag (return Sonic to high plane)
_incObj/01 Sonic.asm lines 2090–2094 at 15dfa3a · upstream ↗ - ^ abCodesonicretro/s2disasms2.asm 43050–43056, 43459–43478
How we know
Every block of level carries solidity for two collision paths, and each player is on one path at a time, so two paths can cross in one place. The floor search reads the primary collision array when the player's top-solid bit is
$Cand the secondary one otherwise, and it counts a block as solid only if the block's flag at that bit is set.43050; loc_1E234: Sonic_AnglePos: 43051AnglePos: 43052 move.l #Primary_Collision,(Collision_addr).w 43053 cmpi.b #$C,top_solid_bit(a0) 43054 beq.s + 43055 move.l #Secondary_Collision,(Collision_addr).w
s2.asm lines 43050–43056 at 4ef457c · upstream ↗ 43459FindFloor: 43460 bsr.w Find_Tile 43461 move.w (a1),d0 43462 move.w d0,d4 43463 andi.w #$3FF,d0 43464 beq.s loc_1E7E2 43465 btst d5,d4 43466 bne.s loc_1E7F0 ⋮ 43468loc_1E7E2: 43469 add.w a3,d2 43470 bsr.w FindFloor2 43471 sub.w a3,d2 ⋮
s2.asm lines 43459–43478 at 4ef457c · upstream ↗ - ^ abCodesonicretro/s2disasms2.asm 45679–45681, 45649–45653, 45702–45725, 45727–45770, 45772–45805
How we know
An invisible line, Object 03, switches a player's collision path when he crosses it. It is vertical or horizontal (subtype bit 2) and 64, 128, 256, or 512 px long (bits 0–1), and it remembers which side each player is on. Crossing it right or down within its span puts him on the first path (solidity bits
$C/$D), or the second ($E/$F) with bit 3, and sets his sprite's high-priority drawing bit with bit 5, clearing it without; crossing back left or up does the same by bits 4 and 6. With bit 7 it acts only on a player on the ground, and an X-flipped switcher leaves the path alone and sets only the priority.45679 move.b subtype(a0),d0 45680 btst #2,d0 45681 beq.s Obj03_Init_CheckX
s2.asm lines 45679–45681 at 4ef457c · upstream ↗ 45649; Object 03 - Collision plane/layer switcher 45650; --------------------------------------------------------------------------- 45651; OST Variables: 45652planeswitch_radius = objoff_32 ; word ; half-height of x-switcher or half-width of y-switcher 45653planeswitch_p1_flag = objoff_34 ; byte ; 0 if player 1 is above or left of switcher; 1 if below or to right
s2.asm lines 45649–45653 at 4ef457c · upstream ↗ 45702word_1FD68: 45703 dc.w $20 45704 dc.w $40 ; 1 45705 dc.w $80 ; 2 45706 dc.w $100 ; 3 45707; =========================================================================== 45708; loc_1FD70: 45709Obj03_Init_CheckX: 45710 andi.w #3,d0 45711 move.b d0,mapping_frame(a0) 45712 add.w d0,d0 45713 move.w word_1FD68(pc,d0.w),planeswitch_radius(a0) ⋮
s2.asm lines 45702–45725 at 4ef457c · upstream ↗ - ^ abGuideSonic Retro, “Sonic Physics Guide: Solid Terrain”
How we know
From Sonic 2 on, a loop uses two or more plane switchers, usually a ground-only one at the loop's middle and another after it, according to the Sonic Physics Guide.
In Sonic 2 onwards, loops will use 2 or more layer switchers in order to swap the Player to the correct path. … Typically this is one grounded_only layer switcher in the middle of the loop, and one layer switcher after the loop.
Loops · archived copy ↗ - ^ abCodesonicretro/skdisasm · sonicretro/s2disasmsonic3k.asm 39746–39748, 39774–39775, 39991–39992, 39836–39880; s2.asm 45749–45758
How we know
Sonic 3 & Knuckles keeps Sonic 2's collision path switcher with one addition: a crossing counts only within 64 px of the line, measured across it, for vertical and horizontal lines alike. Otherwise the subtype works as in Sonic 2: the orientation, the length, the first or second path and the priority for each direction, ground-only, and X-flip leaving the path alone.
39746 move.b subtype(a0),d0 39747 btst #2,d0 39748 beq.s loc_1CD3C
sonic3k.asm lines 39746–39748 at 73de97c · upstream ↗ 39774word_1CD34: 39775 dc.w $20, $40, $80, $100
sonic3k.asm lines 39774–39775 at 73de97c · upstream ↗ 39991loc_1CF8E: 39992 cmpi.w #$40,d2
sonic3k.asm lines 39991–39992 at 73de97c · upstream ↗ - ^Codesonicretro/s2disasm · sonicretro/s1disasms2.asm 37832–37841; 01 Sonic.asm 1412–1427
How we know
On a wall or ceiling below
$280(2.5 px/frame) ground speed, the slope-repel check zeroes the speed, drops Sonic off, and locks the d-pad for 30 frames, as in Sonic 1.37833 addi.b #$20,d0 37834 andi.b #$C0,d0 ⋮ 37837 cmpi.w #$280,d0 ⋮ 37839 clr.w inertia(a0) 37840 bset #status.player.in_air,status(a0) 37841 move.w #$1E,move_lock(a0)
s2.asm lines 37832–37841 at 4ef457c · upstream ↗ 1423 cmpi.w #$280,d0 ; is Sonic's ground speed high enough?_incObj/01 Sonic.asm lines 1412–1427 at 15dfa3a · upstream ↗ - ^Codesonicretro/skdisasm · sonicretro/s2disasm · sonicretro/s1disasmsonic3k.asm 23953–23983, 22469–22472, 23987–23988; s2.asm 37832–37841; +1 files
How we know
Below
$280ground speed on a steep slope the player now slips, with a$80push along the slope, and falls off only near walls and ceilings; Sonic 1 and 2 dropped him from any slope past 45°. As in Sonic 2, the slip also ignores Left and Right for 30 frames.23953 move.b angle(a0),d0 23954 addi.b #$18,d0 23955 cmpi.b #$30,d0 23956 blo.s locret_11E6E ⋮ 23962 cmpi.w #$280,d0 23963 bhs.s locret_11E6E 23964 move.w #30,move_lock(a0) 23965 move.b angle(a0),d0 23966 addi.b #$30,d0 23967 cmpi.b #$60,d0 23968 blo.s loc_11E70 23969 bset #Status_InAir,status(a0) ⋮
sonic3k.asm lines 23953–23983 at 73de97c · upstream ↗ 37833 addi.b #$20,d0 37834 andi.b #$C0,d0 ⋮ 37839 clr.w inertia(a0) 37840 bset #status.player.in_air,status(a0) 37841 move.w #$1E,move_lock(a0)
s2.asm lines 37832–37841 at 4ef457c · upstream ↗ 1413 addi.b #$20,d0 ; rotate it by 45 degrees 1414 andi.b #$C0,d0 ; snap to nearest multiple of 90 degrees ⋮ 1425 clr.w obInertia(a0) ; clear ground speed 1426 bset #status_in_air_bit,obStatus(a0) ; set in-air flag to detach Sonic from wall
_incObj/01 Sonic.asm lines 1412–1427 at 15dfa3a · upstream ↗
Sources
Code
- Sonic Retro contributors. 2026. “s1disasm: Sonic the Hedgehog (16-bit) disassembly (sonicretro/s1disasm).” Commit 15dfa3a. sonicretro/s1disasm @ 15dfa3a · licence, all uses
- Sonic Retro contributors. 2026. “s2disasm: Sonic the Hedgehog 2 (16-bit) disassembly (sonicretro/s2disasm).” Commit 4ef457c. sonicretro/s2disasm @ 4ef457c · licence, all uses
- Sonic Retro contributors. 2026. “skdisasm: Sonic 3 & Knuckles disassembly (sonicretro/skdisasm).” Commit 73de97c. sonicretro/skdisasm @ 73de97c · licence, all uses
Secondary
- Sonic Retro contributors. n.d. “Sonic Physics Guide: Solid Terrain.” Sonic Retro. original · archived · licence, all uses