Prev: B31A Up: Map Next: B39A
B31F: The update routines for the lift (graphic 47) and the bobbing block (graphic 31)
The lift is object template 12 and the bobbing block template 4. Both keep their state in bit 2 of +D, which the kill bits leave free: clear while it goes down, one unit a turn, and set while it goes up, two a turn. Going down, it turns round when it is stopped (bit 2 of +C, set by the collision code whenever a move in Z is stopped, down or up); going up, it turns round when its Z passes the top, LIFT_TOP, the variable stage 1 called UNKNOWN_5B25, which the first of them updated after the room is built sets and every lift and block in the room then shares.
The lift (entry here) waits on the floor: LIFT_TOP is its first Z plus 48, and it moves only in a turn the robot or another mover of graphics 16 to 47 lands on it (bit 3 of +D, set by ADJ_DZ_FOR_OBJ_INTERSECT and cleared here), or while its last move was stopped in Z -- as it is each turn it pushes a rider up. Left alone in mid-air it would stay where it is (by the reading; not tried). The bobbing block (entry at BOBBER) moves every turn, and LIFT_TOP is its first Z: it starts at the top.
Going up, a stopped move is tried again at a step of 4: the collision code passes the lift's Z step to what it pushes into (ADJ_DZ_FOR_OBJ_INTERSECT), so the rider is lifted.
Measured in the simulator. Room $23: two lifts at Z 64 stayed put; dropped on one, he rode it up one unit a turn to Z 113 (LIFT_TOP 112), and it came down with him one unit a turn to the floor, and up again. Room $36: two bobbing blocks, LIFT_TOP 100, each falling one unit a turn to what is under it at Z 76 and rising two a turn to 102, half a cycle apart.
Input
IX the lift or the block
LIFT B31F CALL DRAW_AT_L16_D9 the drawing nudge
B322 LD A,(LIFT_TOP) the first lift in the room sets the top: its Z plus 48
B325 AND A
B326 JR NZ,LIFT_0
B328 LD A,(IX+$03)
B32B ADD A,$30
B32D LD (LIFT_TOP),A
LIFT_0 B330 BIT 3,(IX+$0D) landed on this turn? (cleared for the next)
B334 RES 3,(IX+$0D)
B338 JR NZ,LIFT_MOVE
B33A BIT 2,(IX+$0C) no: only move if the last move was stopped in Z
B33E RET Z
BOBBER B33F CALL DRAW_AT_L16_D9 the drawing nudge (the bobbing block's entry)
B342 LD A,(LIFT_TOP) the first bobbing block in the room sets the top: its Z
B345 AND A
B346 JR NZ,LIFT_MOVE
B348 LD A,(IX+$03)
B34B LD (LIFT_TOP),A
LIFT_MOVE B34E CALL BEEP_BY_Z a note pitched by Z
B351 XOR A no step in U or V
B352 LD (IX+$09),A
B355 LD (IX+$0A),A
B358 BIT 2,(IX+$0D) going up?
B35C JR NZ,LIFT_2
B35E LD (IX+$0B),A down: a Z step of 0, which the fall makes -1
B361 CALL DEC_DZ_AND_UPDATE_UVZ
B364 BIT 2,(IX+$0C) stopped: go up from the next turn
B368 JR Z,LIFT_1
B36A SET 2,(IX+$0D)
LIFT_1 B36E JP SET_WIPE_AND_DRAW_FLAGS redraw it
LIFT_2 B371 LD (IX+$0B),$03 up: a Z step of 3, which the fall makes 2
B375 CALL DEC_DZ_AND_UPDATE_UVZ
B378 BIT 2,(IX+$0C) not stopped: see if it is past the top
B37C JR Z,LIFT_3
B37E LD (IX+$0B),$04 stopped by what is on it: try again at 4, which lifts the rider
B382 XOR A
B383 LD (IX+$09),A
B386 LD (IX+$0A),A
B389 CALL DEC_DZ_AND_UPDATE_UVZ
LIFT_3 B38C LD A,(LIFT_TOP) not past the top: redraw it
B38F CP (IX+$03)
B392 JR NC,LIFT_1
B394 RES 2,(IX+$0D) past it: go down from the next turn
B398 JR LIFT_1
Prev: B31A Up: Map Next: B39A