Routines

64460: Deal with ERIC if he's falling


This routine is called by the routine at 63405 when bit 4 at 32749 is set

64460 21ED7F LD HL,32749
64463 CB76 BIT 6,(HL) Has ERIC already started falling?
64465 202E JR NZ,64513 Jump if so
64467 26D2 LD H,210 210=ERIC
64469 CDB461 CALL 25012 Update SRB for ERIC's current animatory state and location
64472 E680 AND 128

This is the entry point used by the routine at 29462:
64474 47 LD B,A Now B=0 (or 2) if ERIC's facing left, 128 (or 130) if facing right
64475 7A LD A,D A=ERIC's y-coordinate
64476 FE11 CP 17 Is ERIC on the bottom floor?
64478 2002 JR NZ,64482 Jump if not
64480 15 DEC D
64481 3D DEC A
64482 C604 ADD A,4
64484 D607 SUB 7
64486 30FC JR NC,64484
64488 C6A6 ADD A,166 Now A=159+(y–3)%7 if x<17, or 165 if y=17 (where y is ERIC's y-coordinate)
64490 F5 PUSH AF
64491 3E05 LD A,5
64493 80 ADD A,B Now A=animatory state of ERIC sitting on floor or with arm up (5/133, or 7/135)
64494 CD3061 CALL 24880 Update SRB for the new animatory state and location of ERIC
64497 F1 POP AF
64498 67 LD H,A H=value corresponding to ERIC's y-coordinate (159-165)
64499 2EFC LD L,252

This entry point is used by the routines at 23843 and 23859:
64501 22D77F LD (32727),HL
64504 21ED7F LD HL,32749
64507 3650 LD (HL),80 Set bits 4 and 6 at 32749
64509 2EF3 LD L,243 HL=32755
64511 3607 LD (HL),7
64513 2EF3 LD L,243 HL=32755
64515 35 DEC (HL) Is it time to deal with ERIC yet?
64516 C0 RET NZ Return if not
64517 3603 LD (HL),3
64519 2ED8 LD L,216 HL=32728
64521 34 INC (HL)
64522 56 LD D,(HL)
64523 2D DEC L
64524 5E LD E,(HL) DE=address stored at 32727
64525 1A LD A,(DE)
64526 A7 AND A Has ERIC landed yet?
64527 2011 JR NZ,64546 Jump if not
64529 2EFB LD L,251 HL=32763
64531 14 INC D
64532 1A LD A,(DE)
64533 77 LD (HL),A
64534 14 INC D
64535 1A LD A,(DE)
64536 2EED LD L,237 HL=32749
64538 77 LD (HL),A
64539 A7 AND A Did ERIC jump from the top floor window?
64540 C432F5 CALL NZ,62770 Set WACKER on his way to expel ERIC if so
64543 C3C3F2 JP 62147 Make sound effect for ERIC's descent
64546 F5 PUSH AF
64547 26D2 LD H,210 210=ERIC
64549 CDB461 CALL 25012 Update SRB for ERIC's current animatory state and location
64552 E680 AND 128
64554 47 LD B,A Now B=0 if ERIC's facing left, 128 if facing right
64555 F1 POP AF
64556 4F LD C,A
64557 C3005D JP 23808 The routine continues at 23808

This routine uses the address stored at 32727, collected in DE, to guide ERIC through his descent. The bits in the byte at DE have the following significance:
Bit(s) Meaning
0-3 Next animatory state for ERIC
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

DE points to an entry in one of the following tables:
E=252 (normal descent)
D DE (DE) Meaning
160 41212 69 Animatory state 5 or 133; descend
161 41468 69 Animatory state 5 or 133; descend
162 41724 69 Animatory state 5 or 133; descend
163 41980 69 Animatory state 5 or 133; descend
164 42236 69 Animatory state 5 or 133; descend
165 42492 69 Animatory state 5 or 133; descend
166 42748 69 Animatory state 5 or 133; descend
167 43004 0 ERIC has landed
168 43260 4 Set bit 2 at 32763 (ERIC is sitting)
169 43516 0 Reset all bits at 32749 (ERIC landed safely)

E=253 (flight over closed skool gate)
D DE (DE) Meaning
160 41213 160 Animatory state 0 or 128; ascend; move forward
161 41469 160 Animatory state 0 or 128; ascend; move forward
162 41725 160 Animatory state 0 or 128; ascend; move forward
163 41981 96 Animatory state 0 or 128; descend; move forward
164 42237 100 Animatory state 4 or 132; descend; move forward
165 42493 37 Animatory state 5 or 133; move forward
166 42749 69 Animatory state 5 or 133; descend
167 43005 69 Animatory state 5 or 133; descend
168 43261 0 ERIC has landed
169 43517 4 Set bit 2 at 32763 (ERIC is sitting)
170 43773 0 Reset all bits at 32749 (ERIC landed safely)

E=254 (flight from bike saddle into wall or closed door)
D DE (DE) Meaning
160 41214 160 Animatory state 0 or 128; ascend; move forward
161 41470 160 Animatory state 0 or 128; ascend; move forward
162 41726 2 Animatory state 2 or 130; ascend
163 41982 64 Animatory state 0 or 128; descend
164 42238 64 Animatory state 0 or 128; descend
165 42494 64 Animatory state 0 or 128; descend
166 42750 22 Animatory state 6 or 134; move backwards
167 43006 0 ERIC has landed
168 43262 4 Set bit 2 at 32763 (ERIC is sitting)
169 43518 0 Reset all bits at 32749 (ERIC landed safely)

E=255 (descent from top floor window)
D DE (DE) Meaning
160 41215 96 Animatory state 0 or 128; descend; move forwards
161 41471 96 Animatory state 0 or 128; descend; move forwards
162 41727 96 Animatory state 0 or 128; descend; move forwards
163 41983 96 Animatory state 0 or 128; descend; move forwards
164 42239 64 Animatory state 0 or 128; descend
165 42495 64 Animatory state 0 or 128; descend
166 42751 64 Animatory state 0 or 128; descend
167 43007 64 Animatory state 0 or 128; descend
168 43263 64 Animatory state 0 or 128; descend
169 43519 64 Animatory state 0 or 128; descend
170 43775 68 Animatory state 4 or 132; descend
171 44031 68 Animatory state 4 or 132; descend
172 44287 68 Animatory state 4 or 132; descend
173 44543 5 Animatory state 5 or 133
174 44799 69 Animatory state 5 or 133; descend
175 45055 69 Animatory state 5 or 133; descend
176 45311 69 Animatory state 5 or 133; descend
177 45567 70 Animatory state 6 or 134; descend
178 45823 0 ERIC has landed
179 46079 64 Set bit 6 at 32763 (MR WACKER should expel ERIC)
180 46335 32 Set bit 5 at 32749 (ERIC fell out of top floor window)