The ship bounces off hillsides, the attackers slide down slopes and the lasers stop at the ground, and all of it comes from boxes. While a cell is first drawn, each piece also writes a 5-byte box into that cell's list; a moving thing's box is placed where its speed would take it, cut into the parts that lie in each cell, and tested against those cells' boxes. Floors, ceilings and walls reverse and halve the speed into them; slopes reflect it.

The boxes, made while drawing

Each of the four cells on the screen has a list of 37 bytes: a count, then up to seven boxes, one per piece of the cell's tile -- loader_entry for the view's cell (over the loader's entry, dead once the game runs), ground_cell_bottom_left below it, ground_cell_top_right to its right and ground_cell_bottom_right below and right; empty_box_list is an empty list for a cell off the screen. draw_landscape writes the count every pass, but the boxes only while record_ground is set: when scroll_landscape has wrapped into a new cell this pass, or while the screen is built after a restart. A box, in the page's coordinates (y counting down, a block spanning its height upwards from its bottom line):

OffsetFlat pieceWallSlope
+0xx (16 less for direction 15)x of one end (a slope running left starts a step further right)
+1bottom line: y + 16 for a floor, y for a ceilingythat end's y
+2width: 24 a step$18x of the far end
+3height: 2016 a stepy of the far end
+4classclassclass

The class is piece_classes's byte for the piece's direction: bits 0-1 the slope's steepness (1 gentle, 2 45 degrees, 3 steep), bit 2 a flat floor, bit 3 a flat ceiling, bits 4 and 5 the two walls, bit 6 a slope climbing left, bit 7 a ceiling slope. Any of bits 2-5 makes a block; none, a slope. Read from the game:

DirectionPieceClassTested as
0flat floor$04floor
1gentle slope, climbing right$01slope
245 degrees, climbing right$02slope
3steep, climbing right$03slope
4gentle slope, climbing left$41slope
545 degrees, climbing left$42slope
6steep, climbing left$43slope
7flat ceiling$08ceiling
8gentle ceiling, climbing right$81slope
945-degree ceiling, climbing right$82slope
10steep ceiling, climbing right$83slope
11gentle ceiling, climbing left$C1slope
1245-degree ceiling, climbing left$C2slope
13steep ceiling, climbing left$C3slope
14wall, stepping right$10wall
15wall, stepping left$20wall

A screen's boxes

The terrace scene from the landscape page, stopped after draw_landscape has run, and the four lists read out of the game's memory; each box is drawn where the view puts it on the screen (floor, ceiling, wall, slope), clipped to the play area:

The terrace scene's boxes

The terrace scene with its collision boxes.

CellBox atBytesKindIn the page
the view's cell$5B81$08 $A7 $90 $14 $04floorx $08, 144 wide; 20 lines up from line $A7
the view's cell$5B86$A8 $B7 $98 $97 $43slopex $A8 to $98, line $B7 to $97
the cell below$5BA6$E8 $57 $A8 $17 $42slopex $E8 to $A8, line $57 to $17
the cell below and right$5BF0$48 $B7 $28 $77 $43slopex $48 to $28, line $B7 to $77
the cell below and right$5BF5$28 $77 $08 $57 $42slopex $28 to $08, line $77 to $57

A floor's box is a 20-line slab whose top is the surface's top line, and a slope's is the line from one end of its run of steps to the other, which the test turns into a staircase by the slope's steepness. The long slope west of the start, flown to the same way:

The hill's boxes

The long slope west of the start, with its boxes.

Testing a move

collide_with_landscape is given a record in IX, a width in C, a height in B and who is testing in piece_step_x ($FF the ship, $80 a shot's probe or an object that explodes, 0 an object that bounces). place_collision_box places the record's box where this pass's speed would take it (move_across, move_down, without storing it), finds the cell's list (find_page_boxes), and cuts the box into the parts inside each cell: placed by its bottom-left corner, it can stick out only to the right and above, so there are 1, 2 or 4 parts. Each part is tested against its own cell's boxes (next_part_boxes, next_box, next_part): a block by hit_block, a slope by hit_slope. Every overlap test, here and for every sprite contact in the game, is boxes_overlap: a handful of 8-bit compares, at most seven boxes a cell and four parts, 28 a pass. piece_ceiling keeps what has happened this pass: bit 7 a block hit (no more blocks tested), bit 6 a bounce (no more boxes at all), bit 4 a slope hit (no more slopes).

The ship's box is 48 pixels wide and its picture's height plus 4; the shots' probes are 24 by 12 (24 by 16 for the special beam); the objects' boxes go by type (34 by 35 for an attacker, 48 by 32 for a cloud).

Blocks: floors, ceilings, walls

hit_block tests a block only if the record is moving into it or still: a floor while it falls, a ceiling while it rises, a wall by the way it moves across. On a hit the speed into it is negated, halved (halve_hl), clamped to whole parts -3 to +2 (clamp_object_speed) and put through a dead band (dead_band: anything from -$A8 to +$63 in 256ths becomes 0). Still moving, it is a bounce; the ship's new speed sets this pass's step at once (move_ship) with a bump (sound_crackle).

Worked example: at the start of a game the ship thrust up for 12 passes and then left to fall onto the plain, the simulator stopped at $C3C5 and $C3C8 in ship_pass every pass. The climb speed (up positive, in units of 2 pixels a pass) gains a quarter downwards a pass from gravity until the ship meets the floor's box; then it comes back up at half the speed, and the bounces die away until one falls inside the dead band and the ship sits still:

PassClimb speed beforeAfterEvents
16-2.500-2.500$00
17-2.750-2.750$00
18-3.000+1.500$C0bounce
19+1.250+1.250$00
44+0.289+0.289$00
45-0.309-0.309$00
46-0.758+0.000$80a block hit, the speed in the dead band: stopped
47-0.523+0.000$80a block hit, the speed in the dead band: stopped

Pass 18: -3.000 became +1.500, minus half. Between the bounces other things nudged the ship (a touch from an attacker pushes it), which is why the later bounces are not neat halves.

Slopes

One slope a pass. test_landscape_piece tests the part against the slope's shape by class bits 6 and 7 -- as stored, mirrored (test_slope_reversed, test_slope_swapped), upside down (test_slope_upside_down) or both (test_slope_both_ways) -- and test_slope finds how far the part reaches under the slope's edge, scaled by the steepness, into touch_depth. Then, with U the speed across (left positive) and V up and down (up positive), the speeds are reflected:

SlopeRoutineNew UNew V
45 degrees, climbing rightbounce_45_negate-V-U
45 degrees, climbing leftbounce_45_swap_onlyVU
gentle, climbing rightbounce_shallow_negate3/8 U - 3/8 V-3/4 V - 3/4 U
gentle, climbing leftbounce_shallow3/8 U + 3/8 V-3/4 V + 3/4 U
steepthe same twothe gentle rule with U and V swapped before and after (swap_speeds)

The 45-degree rows are exact reflections off the lines y = x and y = -x; the others' cross terms go through slope_negate, which negates the whole word for a ceiling or steep slope and only the whole part otherwise, so they are approximate. Every factor is under 1: every slope bounce loses speed. The negations are switched on and off by two JRs whose displacements each routine patches. After a slope (leave_slope) an object is pushed out by the depth and may slide downhill (downhill); the ship (ship_on_slope_response) stops scrolling for the pass, and on its second pass in a row on a slope (ship_on_slope) slides 2 pixels downhill.

Worked example: the flight to the long slope west of the start, then 24 passes holding left into it, the speeds read either side of the test (the speed across is kept in the scroll's sense, so steering left is positive):

PassAcross beforeUp beforeAcross afterUp afterEventsOn the slope
0+2.000+1.668+2.000+1.668$00
1+2.250+1.418+2.250+1.418$00
2+2.500+1.168+2.500+1.168$00
3+2.750+0.918+2.750+0.918$00
4+2.000+0.668+2.000+0.668$00
5+2.250+0.418+0.418+2.250$10yes
6+0.668+1.000+0.668+1.000$00
7+0.918+0.750+0.918+0.750$00
8+1.168+0.500+1.168+0.500$00
9+1.418+0.250+1.418+0.250$00
10+1.668+0.000+0.000+1.668$10yes
11+0.250+1.418+0.250+1.418$00
12+0.500+1.168+0.500+1.168$00
13+0.750+0.918+0.750+0.918$00
14+1.000+0.668+1.000+0.668$00
15+1.250+0.418+1.250+0.418$00

Pass 5: the ship touched the slope, a 45-degree one climbing left (class $42), and the two speeds were swapped, +2.250 across and +0.418 up becoming +0.418 and +2.250, as bounce_45_swap_only says; steering left builds the speed across up again until the next touch. (The listing's sessions never ran this rule; it ran here.)

A bounce off the landscape changes the speeds before anything is drawn: ship_pass works out the scroll from them, so the ship never visibly enters the ground.

For a game of your own

Confirmed and inferred