| Routines

62178: Deal with ERIC when he's sitting or lying down

Used by the routine at 63405 when bit 2 at 32763 is set (by the routine at 62094, 62423 or 64460). Makes ERIC stand up if 'S' is pressed, or open a desk (and collect any contents) if 'O' is pressed.
62178 | LD HL,32755 | 32755 holds ERIC's main action timer
62181 | DEC (HL) | Is it time to deal with ERIC yet?
62182 | RET NZ | Return if not
62183 | LD A,(32734) | 32734 holds 255 if we're in demo mode, 0 otherwise
62186 | INC A | Are we in demo mode?
62187 | JR NZ,62240 | Jump if not
We're in demo mode. Figure out ERIC's next move depending on what little boy no. 10 is doing.
62189 | CALL 63166 | Exit demo mode and start a new game if a key was pressed; otherwise return here with ERIC's animatory state in A
62192 | LD HL,50944 | Point HL at byte 0 of little boy no. 10's buffer
62195 | CP 4 | 4: Is ERIC sitting in a chair?
62197 | JR Z,62203 | Jump if so
62199 | CP 133 | 133: Is ERIC sitting on the floor facing right?
62201 | JR NZ,62216 | Jump if not
62203 | ADD A,64 | A=68 (little boy sitting on a chair) or 197 (little boy sitting on the floor facing right)
62205 | CP (HL) | Compare ERIC's animatory state with that of little boy no. 10
62206 | LD HL,32732 | 32732 holds the counter that determines the delay between little boy no. 10 standing up and ERIC standing up
62209 | JR NZ,62214 | Jump if ERIC's not doing what little boy no. 10 is doing
62211 | LD (HL),45 | Initialise the stand-up delay counter at 32732 to 45
62213 | RET |
62214 | DEC (HL) | Decrement the stand-up delay counter at 32732
62215 | RET NZ | Return if it's not time for ERIC to stand up
62216 | LD HL,32763 | 32763 holds ERIC's status flags
62219 | LD (HL),0 | Clear all of them (ERIC is no longer sitting or lying down)
This entry point is used by the routine at 24175.
62221 | CALL 29012 | Make a sound effect
62224 | LD H,210 | 210=ERIC
62226 | CALL 25012 | Update the SRB for ERIC's current animatory state and location
62229 | AND 128 | A=0/128: ERIC standing up
This entry point is used by the routines at 23907, 24133, 64242 and 64416.
62231 | CALL 24880 | Update ERIC's animatory state and location and update the SRB
62234 | LD A,6 | Set ERIC's main action timer (at 32755) to 6
62236 | LD (32755),A
62239 | RET |
We're not in demo mode.
62240 | CALL 29118 | Collect the code of the last key pressed in A
62243 | RET Z | Return if no keys were pressed
62244 | RES 5,A | Normalise the code to upper case
62246 | CP 83 | Was 'S' pressed?
62248 | JR Z,62216 | Make ERIC stand up if so
62250 | CP 79 | Was 'O' pressed?
62252 | RET NZ | Return if not
62253 | LD A,(53760) | A=ERIC's animatory state
62256 | CP 4 | 4: Is ERIC sitting in a chair?
62258 | RET NZ | Return if not
ERIC is sitting in a chair and 'O' (open desk) was pressed. Compute the ID of the desk ERIC is sitting at so we can determine whether he's found the water pistol or the stinkbombs.
62259 | LD A,(54785) | Pick up the x-coordinate of whatever object is using buffer 214
62262 | CP 192 | Is this buffer being used at the moment?
62264 | RET C | Return if so
62265 | LD DE,(53761) | Pick up ERIC's coordinates in DE
62269 | LD A,D | A=ERIC's y-coordinate
62270 | CP 10 | Is ERIC on the middle floor?
62272 | JR Z,62294 | Jump if so
62274 | CP 3 | Is ERIC on the top floor?
62276 | RET NZ | Return if not
62277 | LD A,E | A=ERIC's x-coordinate
62278 | CP 22 | Is ERIC in the Blue Room?
62280 | JR C,62290 | Jump if so
62282 | SUB 27 |
62284 | CP 34 | Is ERIC in the Yellow Room?
62286 | JR C,62290 | Jump if so
62288 | SUB 106 |
62290 | SUB 9 |
62292 | JR 62303 |
62294 | LD A,E | A=ERIC's x-coordinate
62295 | CP 53 | Is ERIC in the Science lab?
62297 | JR C,62301 | Jump if so
62299 | SUB 113 |
62301 | SUB 2 |
62303 | RRA |
62304 | LD B,A |
At this point B holds the identifier of the desk that ERIC's sitting at.
Desk IDs | Room
--- | ---
1-6 | Blue Room
7-12 | Yellow Room
13-18 | Top-floor room in the girls' skool
19-25 | Science Lab
26-31 | Middle-floor room in the girls' skool
Now we check whether the water pistol has been placed in a desk yet.
62305 | LD HL,32730 | 32730 holds the ID of the desk containing the water pistol
62308 | LD A,(HL) | Has the water pistol been placed in a desk yet?
62309 | AND A
62310 | JR NZ,62326 | Jump if so
The water pistol hasn't been placed in a desk yet. Pick one at random that doesn't match the desk containing the stinkbombs.
62312 | CALL 25233 | A=random desk ID from 1 to 31
62315 | AND 31
62317 | JR Z,62312
62319 | LD L,219 | HL=32731 (which holds the ID of the desk containing the stinkbombs)
62321 | CP (HL) | Is this the desk containing the stinkbombs?
62322 | JR Z,62312 | Get another random desk ID if so
62324 | DEC L | Otherwise place the newly determined ID of the desk containing the water pistol into 32730
62325 | LD (HL),A
Check whether ERIC has found the water pistol.
62326 | CP B | Is ERIC sitting at the desk that contains the water pistol?
62327 | JR NZ,62345 | Jump if not
62329 | LD (HL),0 | Set 32730 to 0 (the water pistol is not in any desk now)
62331 | LD L,235 | HL=32747 (inventory flags)
62333 | LD A,(HL) | Pick these up in A
62334 | AND 24 | Keep only bits 3 and 4 (the pistol bits)
62336 | LD A,44 | 44: animatory state of a desk lid
62338 | JR NZ,62377 | Jump if ERIC already has a water pistol
62340 | SET 3,(HL) | Give ERIC a water pistol (full of water)
62342 | INC A | 45: animatory state of a desk lid with a water pistol
62343 | JR 62377 |
There was no water pistol in the desk. Check whether there are stinkbombs.
62345 | INC L | HL=32731 (which holds the ID of the desk containing the stinkbombs)
62346 | LD A,(HL) | Have the stinkbombs been placed in a desk yet?
62347 | AND A
62348 | JR NZ,62364 | Jump if so
The stinkbombs haven't been placed in a desk yet. Pick one at random that doesn't match the desk containing the water pistol.
62350 | CALL 25233 | A=random desk ID from 1 to 31
62353 | AND 31
62355 | JR Z,62350
62357 | LD L,218 | HL=32730 (which holds the ID of the desk containing the water pistol)
62359 | CP (HL) | Is this the desk containing the water pistol?
62360 | JR Z,62350 | Get another random desk ID if so
62362 | INC L | Otherwise place the newly determined ID of the desk containing the stinkbombs into 32731
62363 | LD (HL),A
Check whether ERIC has found the stinkbombs.
62364 | CP B | Compare the ID of the desk ERIC's sitting at (A) with the ID of the desk containing the stinkbombs (B)
62365 | LD A,44 | 44: animatory state of a desk lid
62367 | JR NZ,62377 | Jump if ERIC isn't sitting at the desk that contains the stinkbombs
62369 | LD L,235 | HL=32747 (inventory flags)
62371 | LD A,(HL) | Set bits 5-7, giving ERIC three stinkbombs
62372 | OR 224
62374 | LD (HL),A
62375 | LD A,46 | 46: animatory state of a desk lid with stinkbombs
Now A holds the animatory state of the desk lid: 44 (empty desk), 45 (with pistol), or 46 (with stinkbombs).
62377 | LD HL,54803 | Point HL at byte 19 of the desk lid's buffer
62380 | LD (HL),8 | Initialise the counter determining how long the desk lid stays up
62382 | DEC E | E=x-coordinate of the desk lid in front of ERIC
62383 | CALL 30534 | Update the SRB for the desk lid's appearance and place address 62386 (below) into bytes 17 and 18 of its buffer
The address of this entry point is placed into bytes 17 and 18 of the desk lid's buffer by the instruction above.
62386 | LD L,19 | Byte 19 of the desk lid's buffer holds the delay counter that determines when the desk lid will shut
62388 | DEC (HL) | Decrement this counter
62389 | LD A,(HL) | Copy its current value to A
62390 | JP Z,29903 | Jump if it's time for the desk lid to close
62393 | SUB 6 | Is it time for ERIC to collect the contents of the desk?
62395 | RET NZ | Return if not
62396 | LD L,A | L=0
62397 | LD A,(HL) | A=animatory state of a desk lid (with contents, if any)
62398 | CP 44 | 44: Is the desk empty?
62400 | RET Z | Return if so
This entry point is used by the routines at 24028, 29462 and 29568.
62401 | CALL 31746 | Print the inventory
This entry point is used by the routine at 24348. Your browser doesn't support HTML5 audio. Here is a link to the audio instead.
62404 | LD C,5 | Make a celebratory sound effect (ERIC has achieved something rather handy)
62406 | LD B,3
62408 | LD HL,65303
62411 | LD D,H
62412 | LD E,H
62413 | CALL 62155
62416 | DEC C
62417 | JR NZ,62406
62419 | RET |