| Routines

FBCC: Deal with ERIC while he's falling (1)

Used by the routine at F7AD when bit 4 at 7FED is set (by the routine at 720A, 725E or FA4D). On entry, bit 6 at 7FED is also set if ERIC has already begun his descent (i.e. we've already made the first pass through this routine).
FBCC | LD HL,$7FED | 7FED holds ERIC's secondary status flags
FBCF | BIT 6,(HL) | Has ERIC already begun his descent?
FBD1 | JR NZ,$FC01 | Jump if so
ERIC has not begun his descent yet, which means we need to figure out what his trajectory will be first.
FBD3 | LD H,$D2 | 0xD2=ERIC
FBD5 | CALL $61B4 | Update the SRB for ERIC's current animatory state and location
FBD8 | AND $80 | A=0x00 if ERIC's facing left, 0x80 if facing right
This entry point is used by the routine at 7316 when ERIC has jumped from the saddle of the bike (with A=0x02 or 0x82, and D holding the y-coordinate of the spot above ERIC's hand).
FBDA | LD B,A | Now B=0x00 (or 0x02) if ERIC's facing left, 0x80 (or 0x82) if facing right
FBDB | LD A,D | A=y-coordinate of ERIC (or the spot above his hand)
FBDC | CP $11 | Is ERIC on the bottom floor?
FBDE | JR NZ,$FBE2 | Jump if not
FBE0 | DEC D | D=16
FBE1 | DEC A | A=16
FBE2 | ADD A,$04 | Set A=-7+(y-3)%7 if y<17, or -1 if y=17 (where y is ERIC's y-coordinate); this is the distance (negated) left to travel till ERIC reaches the floor
FBE4 | SUB $07
FBE6 | JR NC,$FBE4
FBE8 | ADD A,$A6 | A=0x9F-0xA5 (normal descent table entry pointer)
FBEA | PUSH AF | Save this briefly
FBEB | LD A,$05 | Now A=animatory state of ERIC sitting on the floor (0x05/0x85) or with his arm up (0x07/0x87)
FBED | ADD A,B
FBEE | CALL $6130 | Update ERIC's animatory state and location and update the SRB
FBF1 | POP AF | Restore the normal descent table entry pointer to A
FBF2 | LD H,A | Point HL at the appropriate entry (H=0x9F-0xA5) in the normal descent table (L=0xFC) for ERIC's current height above the floor
FBF3 | LD L,$FC
This entry point is used by the routines at 5D23 (with H=0x9F, L=0xFD or 0xFE) and 5D33 (with H=0x9F, L=0xFF).
FBF5 | LD ($7FD7),HL | Store the descent table pointer at 7FD7
FBF8 | LD HL,$7FED | 7FED holds ERIC's secondary status flags
FBFB | LD (HL),$50 | Set bits 4 (ERIC is still falling) and 6 (ERIC has begun his descent)
FBFD | LD L,$F3 | Set ERIC's main action timer at 7FF3 to 7
FBFF | LD (HL),$07
Deal with the next phase of ERIC's descent.
FC01 | LD L,$F3 | HL=7FF3 (which holds ERIC's main action timer)
FC03 | DEC (HL) | Is it time to deal with ERIC yet?
FC04 | RET NZ | Return if not
FC05 | LD (HL),$03 | Reset ERIC's action timer to 3
FC07 | LD L,$D8 | HL=7FD7 (which holds the descent table pointer)
FC09 | INC (HL) | Collect the descent table pointer into DE
FC0A | LD D,(HL)
FC0B | DEC L
FC0C | LD E,(HL)
FC0D | LD A,(DE) | Pick up an entry from the descent table in A
FC0E | AND A | Has ERIC landed yet?
FC0F | JR NZ,$FC22 | Jump if not
ERIC has landed. Time to set ERIC's status flags at 7FFB and 7FED appropriately.
FC11 | LD L,$FB | HL=7FFB (ERIC's main status flags)
FC13 | INC D | Collect the first set of flags from the descent table
FC14 | LD A,(DE)
FC15 | LD (HL),A | Copy them into 7FFB
FC16 | INC D | Collect the second set of flags from the descent table
FC17 | LD A,(DE)
FC18 | LD L,$ED | Copy them into 7FED
FC1A | LD (HL),A
FC1B | AND A | Did ERIC jump from the top floor window (bit 5 set)?
FC1C | CALL NZ,$F532 | Set MR WACKER on his way to expel ERIC if so
FC1F | JP $F2C3 | Make a sound effect for ERIC's landing
ERIC hasn't landed yet. Determine his next move through the air.
FC22 | PUSH AF | Save the descent table entry briefly
FC23 | LD H,$D2 | 0xD2=ERIC
FC25 | CALL $61B4 | Update the SRB for ERIC's current animatory state and location
FC28 | AND $80 | B=0x00 if ERIC's facing left, 0x80 if facing right
FC2A | LD B,A
FC2B | POP AF | Restore the descent table entry to A
FC2C | LD C,A | Copy it to C
FC2D | JP $5D00 | The routine continues at 5D00
This routine uses a descent table to guide ERIC to the floor. The bits in each table entry have the following significance:
Bit(s) | Meaning
--- | ---
0-3 | ERIC's next animatory state
4 | If set, move backwards one space
5 | If set, move forwards one space
6 | If set, descend one level
7 | If set, ascend one level
The descent tables themselves contain the following entries:
E=0xFC (normal descent)
D | DE | (DE) | Meaning
--- | --- | --- | ---
0xA0 | A0FC | 0x45 | Animatory state 0x05 or 0x85; descend
0xA1 | A1FC | 0x45 | Animatory state 0x05 or 0x85; descend
0xA2 | A2FC | 0x45 | Animatory state 0x05 or 0x85; descend
0xA3 | A3FC | 0x45 | Animatory state 0x05 or 0x85; descend
0xA4 | A4FC | 0x45 | Animatory state 0x05 or 0x85; descend
0xA5 | A5FC | 0x45 | Animatory state 0x05 or 0x85; descend
0xA6 | A6FC | 0x45 | Animatory state 0x05 or 0x85; descend
0xA7 | A7FC | 0x00 | ERIC has landed
0xA8 | A8FC | 0x04 | Set bit 2 at 7FFB (ERIC is sitting)
0xA9 | A9FC | 0x00 | Reset all bits at 7FED (ERIC landed safely)
E=0xFD (from the bike saddle over the closed skool gate)
D | DE | (DE) | Meaning
--- | --- | --- | ---
0xA0 | A0FD | 0xA0 | Animatory state 0x00 or 0x80; ascend; move forward
0xA1 | A1FD | 0xA0 | Animatory state 0x00 or 0x80; ascend; move forward
0xA2 | A2FD | 0xA0 | Animatory state 0x00 or 0x80; ascend; move forward
0xA3 | A3FD | 0x60 | Animatory state 0x00 or 0x80; descend; move forward
0xA4 | A4FD | 0x64 | Animatory state 0x04 or 0x84; descend; move forward
0xA5 | A5FD | 0x25 | Animatory state 0x05 or 0x85; move forward
0xA6 | A6FD | 0x45 | Animatory state 0x05 or 0x85; descend
0xA7 | A7FD | 0x45 | Animatory state 0x05 or 0x85; descend
0xA8 | A8FD | 0x00 | ERIC has landed
0xA9 | A9FD | 0x04 | Set bit 2 at 7FFB (ERIC is sitting)
0xAA | AAFD | 0x00 | Reset all bits at 7FED (ERIC landed safely)
E=0xFE (from the bike saddle into a wall or closed door)
D | DE | (DE) | Meaning
--- | --- | --- | ---
0xA0 | A0FE | 0xA0 | Animatory state 0x00 or 0x80; ascend; move forward
0xA1 | A1FE | 0xA0 | Animatory state 0x00 or 0x80; ascend; move forward
0xA2 | A2FE | 0x02 | Animatory state 0x02 or 0x82; ascend
0xA3 | A3FE | 0x40 | Animatory state 0x00 or 0x80; descend
0xA4 | A4FE | 0x40 | Animatory state 0x00 or 0x80; descend
0xA5 | A5FE | 0x40 | Animatory state 0x00 or 0x80; descend
0xA6 | A6FE | 0x16 | Animatory state 0x06 or 0x86; move backwards
0xA7 | A7FE | 0x00 | ERIC has landed
0xA8 | A8FE | 0x04 | Set bit 2 at 7FFB (ERIC is sitting)
0xA9 | A9FE | 0x00 | Reset all bits at 7FED (ERIC landed safely)
E=0xFF (from the top-floor window)
D | DE | (DE) | Meaning
--- | --- | --- | ---
0xA0 | A0FF | 0x60 | Animatory state 0x00 or 0x80; descend; move forwards
0xA1 | A1FF | 0x60 | Animatory state 0x00 or 0x80; descend; move forwards
0xA2 | A2FF | 0x60 | Animatory state 0x00 or 0x80; descend; move forwards
0xA3 | A3FF | 0x60 | Animatory state 0x00 or 0x80; descend; move forwards
0xA4 | A4FF | 0x40 | Animatory state 0x00 or 0x80; descend
0xA5 | A5FF | 0x40 | Animatory state 0x00 or 0x80; descend
0xA6 | A6FF | 0x40 | Animatory state 0x00 or 0x80; descend
0xA7 | A7FF | 0x40 | Animatory state 0x00 or 0x80; descend
0xA8 | A8FF | 0x40 | Animatory state 0x00 or 0x80; descend
0xA9 | A9FF | 0x40 | Animatory state 0x00 or 0x80; descend
0xAA | AAFF | 0x44 | Animatory state 0x04 or 0x84; descend
0xAB | ABFF | 0x44 | Animatory state 0x04 or 0x84; descend
0xAC | ACFF | 0x44 | Animatory state 0x04 or 0x84; descend
0xAD | ADFF | 0x05 | Animatory state 0x05 or 0x85
0xAE | AEFF | 0x45 | Animatory state 0x05 or 0x85; descend
0xAF | AFFF | 0x45 | Animatory state 0x05 or 0x85; descend
0xB0 | B0FF | 0x45 | Animatory state 0x05 or 0x85; descend
0xB1 | B1FF | 0x46 | Animatory state 0x06 or 0x86; descend
0xB2 | B2FF | 0x00 | ERIC has landed
0xB3 | B3FF | 0x40 | Set bit 6 at 7FFB (MR WACKER should expel ERIC)
0xB4 | B4FF | 0x20 | Set bit 5 at 7FED (ERIC fell out of the top-floor window)