Prev: 31252 Up: Map Next: 31462
31254: Control a mouse
The address of this uninterruptible subcommand routine is placed into bytes 17 and 18 of a mouse's buffer by the routine at 31502 (if the mouse was released by ERIC) or by the routine at 62910 (when preparing for a new game). Bytes 16 and 19-22 of the mouse's buffer are used to store the following values that control its movement:
Byte Contents
16 Counter decremented each time the mouse hides (if the mouse was released by ERIC); when it reaches 0, the mouse dies (returns control to the character whose buffer it borrowed)
19 Direction of travel, and the distance remaining to travel before hiding or considering a change of direction: it is positive (bit 7 reset) if the mouse is travelling right, and decremented on each pass; it is negative (bit 7 set) if the mouse is travelling left, and incremented on each pass; while the mouse is hiding, it is 0
20 Counter decremented on each change of direction or distance to travel; when it reaches 0, the mouse hides
21 Counter determining how much longer the mouse has left to hide
22 x-coordinate of the mouse when it last hid
Input
H Mouse's character number (198, 199, 206-208, 212)
31254 LD L,19 A=remaining distance to travel
31256 LD A,(HL)
31257 AND A Is this mouse (a) hiding, (b) about to hide, or (c) about to consider a change of direction and distance to travel?
31258 JR Z,31330 Jump if so
31260 LD A,(32756) 32756 holds the door/window status flags
31263 PUSH AF Save these flags
31264 AND 63 Reset bits 6 and 7 of the door/window status flags (i.e. pretend that the windows are closed)
31266 LD (32756),A
31269 BIT 7,(HL) Set the zero flag if the mouse is travelling right
31271 LD L,1 Collect the mouse's x-coordinate in E
31273 LD E,(HL)
31274 JR Z,31278 Jump if the mouse is travelling right
31276 DEC E
31277 DEC E
31278 INC E E=x-coordinate of the spot in front of the mouse
31279 INC L L=2
31280 LD A,(HL) A=mouse's y-coordinate
31281 LD D,A Copy this to D
31282 CP 10 Is the mouse on the middle floor?
31284 JR NZ,31291 Jump if not
31286 LD A,E A=x-coordinate of the spot in front of the mouse
31287 CP 84 Is the mouse at the top of the stairs leading down to the stage?
31289 JR Z,31296 Turn the mouse round if so
31291 CALL 30292 Check for walls and closed doors in the mouse's path
31294 JR NC,31304 Jump if there are none
31296 LD L,19 Turn the mouse round without changing the distance remaining to travel
31298 LD A,(HL)
31299 NEG
31301 LD (HL),A
31302 JR 31269 See what's in front of the mouse in this direction
There are no walls or closed doors in the mouse's path.
31304 POP AF Restore the door/window status flags
31305 LD (32756),A
31308 CALL 25012 Update the SRB for the mouse's current animatory state and location
31311 LD L,19 Is the mouse travelling right?
31313 BIT 7,(HL)
31315 JR Z,31323 Jump if so
31317 INC (HL) Decrease the distance left to travel
31318 DEC E Move the mouse one space left
31319 LD A,47 47: animatory state of a mouse travelling left
31321 JR 31327
31323 DEC (HL) Decrease the distance left to travel
31324 INC E Move the mouse one space right
31325 LD A,175 175: animatory state of a mouse travelling right
31327 JP 24880 Update the mouse's animatory state and location and update the SRB
Byte 19 holds 0, which means (a) the mouse is hiding at the moment, or (b) it's time for the mouse to consider a change of direction and distance to travel, or (c) it's time to hide for a bit.
31330 INC L Pick up byte 20 in A
31331 LD A,(HL)
31332 AND A Is the mouse already hiding?
31333 JR Z,31372 Jump if so
31335 DEC (HL) Is it time for the mouse to hide temporarily?
31336 JR NZ,31347 Jump if not
31338 LD L,1 Point HL at byte 1 of the mouse's buffer
31340 LD A,(HL) A=mouse's x-coordinate
31341 LD L,22 Store this in byte 22 of the mouse's buffer for later retrieval
31343 LD (HL),A
31344 JP 29907 Make the mouse hide
It's time for the mouse to consider a change of direction and distance to travel.
31347 PUSH HL
31348 CALL 31150 Make any girls near this mouse start jumping
31351 POP HL
31352 CALL 25233 A=random number
31355 AND 131 A=2-5 (bit 7 reset) or 130-133 (bit 7 set)
31357 ADD A,2
31359 RLCA A=2-5 (bit 7 reset), with the carry flag holding the previous contents of bit 7
31360 AND A
31361 RRA
31362 JR C,31366 Jump if bit 7 was set (the new direction is right)
31364 NEG The new direction is left
31366 LD L,19 Set the new direction and distance to travel
31368 LD (HL),A
31369 JP 31260 Start moving
The mouse is currently hiding. Check whether it should transform into a frog before reappearing (in case ERIC obtained the Science Lab storeroom key in the meantime).
31372 INC L L=21
31373 DEC (HL) Is it time for the mouse to come out of hiding?
31374 RET NZ Return if not
31375 LD A,H A=mouse's character number
31376 CP 212 Was this mouse released by ERIC?
31378 JR NZ,31424 Jump if so
31380 LD A,(32747) 32747 holds the inventory flags
31383 BIT 1,A Has ERIC got the Science Lab storeroom key?
31385 JR Z,31398 Jump if not
31387 LD A,29 29: animatory state of the frog
31389 LD DE,2619 (E,D)=(59,10) (location where the frog enters the game)
31392 CALL 24880 Update the frog's animatory state and location and update the SRB
31395 JP 31061 Bring the frog into the game
It's time for this mouse to come out of hiding.
31398 CALL 25233 A=random number between 5 and 20; this determines how long the mouse will hide next time
31401 AND 15
31403 ADD A,5
31405 LD (HL),A Store this in byte 21 of the mouse's buffer
31406 CALL 25233 A=random number between 2 and 5; this determines how many changes of direction and distance to travel the mouse will make before hiding again
31409 AND 3
31411 ADD A,2
31413 DEC L Store this in byte 20 of the mouse's buffer
31414 LD (HL),A
31415 LD L,22 E=x-coordinate of the mouse before it hid
31417 LD E,(HL)
31418 LD L,2 D=y-coordinate of the mouse
31420 LD D,(HL)
31421 JP 31325 Unhide the mouse
This mouse was released by ERIC and is currently hiding. It's due to come out of hiding, or die.
31424 LD L,16 Byte 16 holds the mouse's lifespan counter
31426 DEC (HL) Is it time for this mouse to disappear for ever?
31427 JR NZ,31451 Jump if not
This mouse must die, and return control of the buffer it hijacked (198, 199, 206-208) to its original owner (little boy no. 9 or 10, BOY WANDER, ANGELFACE or EINSTEIN).
31429 LD L,29 Set bits 0 and 7 at byte 29: restart the command list and make the character run
31431 LD (HL),129
31433 LD L,10 Remove any interruptible subcommand routine address that may have been in the character's buffer before it was hijacked
31435 LD (HL),0
31437 LD L,15 Pick up from byte 15 the animatory state of the character whose buffer the mouse borrowed
31439 LD A,(HL)
31440 AND 240 A=character's base animatory state
31442 LD L,0 Restore this character's animatory state to its base value
31444 LD (HL),A
31445 INC L Make the character reappear at x-coordinate 32 (which should be off-screen because ERIC cannot release mice in the boys' skool)
31446 LD (HL),32
31448 JP 25492 Terminate this uninterruptible subcommand, thus returning control to the character who normally owns the buffer
This mouse (released by ERIC) is about to come out of hiding.
31451 LD A,(32767) A=leftmost column of the play area on screen
31454 CP 144 Is at least half of the girls' skool on-screen?
31456 JR C,31429 Terminate the mouse if not
31458 LD L,21
31460 JR 31398 Otherwise make the mouse reappear
Prev: 31252 Up: Map Next: 31462