| Routines

725E: Deal with ERIC when he's riding the bike

Called by the routine at F7AD when bit 0 at 7FED is set (by the routine at 7316). Listens for and responds appropriately to keypresses while ERIC is sitting on the saddle of the bike.
725E | LD HL,$7FF3 | 7FF3 holds ERIC's main action timer
7261 | DEC (HL) | Is it time to deal with ERIC yet?
7262 | JR NZ,$72DA | Jump if not
7264 | INC (HL) | Set ERIC's action timer to 1, ensuring that we pass through the following section of code on the next call to this routine if no pedalling is detected this time (if 'left' or 'right' is pressed, the action timer will be reset to 5)
7265 | CALL $71FA | A=value from the keypress offset table corresponding to the key just pressed (if any)
7268 | LD HL,$7FEE | 7FEE holds the offset of the last key pressed while ERIC was riding the bike
726B | JR Z,$72DA | Jump if no keys were pressed since the last check
726D | SET 3,A | We don't distinguish between fast (upper case) and slow (lower case) keypresses while ERIC is riding the bike
726F | CP $58 | Was 'left' pressed?
7271 | JR Z,$7277 | Jump if so
7273 | CP $5A | Was 'right' pressed?
7275 | JR NZ,$7295 | Jump if not
7277 | CP (HL) | Was the key just pressed the same as the last one pressed?
7278 | JR Z,$72DA | Jump if so
The 'left' key was pressed after a non-left key, or the 'right' key was pressed after a non-right key. In other words, ERIC pedalled.
727A | LD (HL),A | Store the offset of the key just pressed in 7FEE
727B | LD L,$F3 | HL=7FF3 (ERIC's main action timer)
727D | LD (HL),$05 | Reset this to 5
727F | LD L,$F0 | HL=7FF0 (bike momentum)
7281 | LD A,(HL) | Increase the bike's momentum, but not beyond 0xFF
7282 | ADD A,$0C
7284 | JR NC,$7288
7286 | LD A,$FF
7288 | LD (HL),A
7289 | LD H,$D2 | 0xD2=ERIC
728B | CALL $61B4 | Update the SRB for ERIC's current animatory state and location
728E | XOR $01 | Now A=ERIC's new animatory state (0x0C, 0x0D, 0x8C or 0x8D)
7290 | CALL $6130 | Update ERIC's animatory state and update the SRB
7293 | JR $72DA |
Neither 'left' nor 'right' was pressed.
7295 | CP $5C | Was 'up' pressed?
7297 | JR NZ,$72C6 | Jump if not
7299 | LD L,$ED | HL=7FED (ERIC's status flags)
729B | LD (HL),$80 | Set bit 7: ERIC is standing on the saddle of the bike
729D | LD H,$D2 | 0xD2=ERIC
729F | CALL $61B4 | Update the SRB for ERIC's current animatory state and location
72A2 | PUSH DE |
72A3 | DEC D | D=ERIC's new y-coordinate (up a level)
72A4 | NOP |
72A5 | INC E |
72A6 | BIT 7,A | Is ERIC facing left?
72A8 | JR Z,$72AC | Jump if so
72AA | DEC E |
72AB | DEC E |
72AC | AND $80 | Now A=ERIC's new animatory state, E=ERIC's new x-coordinate
72AE | CALL $6130 | Update ERIC's animatory state and location and update the SRB
72B1 | LD A,(HL) | A=ERIC's animatory state
72B2 | POP DE | DE=ERIC's location before he jumped on the saddle or got off the bike
72B3 | ADD A,$19 | A=animatory state of the bike standing upright (0x19 or 0x99)
72B5 | INC H | H=0xD3: bike
72B6 | CALL $6130 | Update the bike's animatory state and update the SRB
72B9 | LD HL,$720A | Place the address of the uninterruptible subcommand routine at 720A into bytes 0x11 and 0x12 of the bike's buffer
72BC | LD ($D311),HL
72BF | LD HL,$7FF3 | 7FF3 holds ERIC's main action timer
72C2 | LD (HL),$05 | Reset this to 5
72C4 | JR $72FC | Also reset the bike's speed counter (at 7FEF) to 5
Not one of 'left', 'right' and 'up' was pressed.
72C6 | CP $5E | Was 'down' pressed?
72C8 | JR NZ,$72DA | Jump if not
72CA | LD L,$ED | HL=7FED (ERIC's status flags)
72CC | LD (HL),$00 | Reset all bits here, signalling that ERIC has his feet back on the ground
72CE | LD L,$FB | HL=7FFB (ERIC's other status flags)
72D0 | RES 1,(HL) | Reset bit 1 here, signalling that 7FED is empty
72D2 | LD H,$D2 | 0xD2=ERIC
72D4 | CALL $61B4 | Update the SRB for ERIC's current animatory state and location
72D7 | PUSH DE | Save ERIC's current location
72D8 | JR $72AC | Jump back to update the animatory state and location of ERIC and the bike
The following section of code is executed on every pass through this routine while ERIC is sitting on the saddle (in other words, unless 'up' or 'down' was pressed).
72DA | LD HL,$7FF0 | 7FF0 holds the bike's momentum
72DD | DEC (HL) | Has the bike run out of momentum?
72DE | JR NZ,$7301 | Jump if not
72E0 | LD H,$D2 | 0xD2=ERIC, who will now fall off the bike
72E2 | CALL $61B4 | Update the SRB for ERIC's current animatory state and location
72E5 | PUSH DE | Save ERIC's coordinates briefly
72E6 | AND $80 | Keep only the 'direction' bit of ERIC's animatory state
72E8 | PUSH AF |
72E9 | ADD A,$04 | A=0x04 or 0x84 (ERIC sitting on a chair)
72EB | CALL $6130 | Update ERIC's animatory state and update the ARB
72EE | POP AF | A=0x00 if ERIC's facing left, 0x80 if facing right
72EF | POP DE | Restore ERIC's coordinates to DE
72F0 | ADD A,$18 | A=0x18 or 0x98 (bike lying on the floor)
72F2 | LD H,$D3 | 0xD3=bike
72F4 | CALL $6130 | Update the bike's animatory state and update the SRB
72F7 | LD HL,$7FED | 7FED holds ERIC's status flags
72FA | LD (HL),$10 | Set bit 4: ERIC will not land on his feet
72FC | LD L,$EF | HL=7FEF (which holds the bike's speed counter)
72FE | LD (HL),$05 | Reset this to 5
7300 | RET |
The bike still has momentum.
7301 | LD L,$EF | HL=7FEF (which holds the bike's speed counter)
7303 | DEC (HL) | Is it time to move the bike forward?
7304 | RET NZ | Return if not
7305 | LD (HL),$07 | Reset the bike's speed counter to 7
7307 | LD HL,($D200) | A=ERIC's animatory state, E=ERIC's x-coordinate
730A | LD A,L
730B | LD E,H
730C | CALL $7000 | Are there any walls, closed doors or ALBERTs in ERIC's path?
730F | JR C,$72E0 | Knock ERIC off the bike if so
7311 | JR Z,$72E0
7313 | JP $724E | Otherwise move ERIC forward one space, update the SRB, and scroll the screen if necessary