| Routines

25296: Move the characters

Used by the routine at 63156.
25296 | CALL 25302 | Move one character
25299 | CALL 25302 | Move the next character
25302 | LD HL,32764 |
25305 | LD A,(HL) | A=number of the character last moved (183-209, 211-214)
25306 | INC A | A=number of the next character to move
25307 | CP 210 | Is it ERIC?
25309 | JR Z,25306 | Jump if so (we don't want to move ERIC!)
25311 | CP 215 | Have we completed an entire cast movement cycle?
25313 | JR C,25317 | Jump if not
25315 | LD A,183 | Back to 183 (little girl no. 1) if so
25317 | CP 198 | Are we dealing with little girls 1-7 or little boys 1-8?
25319 | JR NC,25360 | Jump if not
It's the turn of one of the little girls (183-189), or one of the first 8 little boys (190-197). But if the part of the play area currently on-screen is somewhere this character never ventures into, we skip ahead to the next suitable candidate. Specifically, the following characters are skipped depending on the value of X (the leftmost column of the skool on-screen):
X | Skip
--- | ---
X<=72 | girls 1-7 (183-189)
80<=X<=112 | girls 4-7 and boys 1-3 (187-192)
X>=120 | boys 1-8 (190-197)
25321 | LD E,A | E=character number (183-197)
25322 | LD D,190 | 190=little boy no. 1
25324 | LD A,(32767) | A=leftmost column of the play area on screen
25327 | CP 80 | This is the x-coordinate of the middle of the assembly hall stage
25329 | JR NC,25338 | Jump if we can't see to the left of this
We are deep into the boys' skool, where no girls ever set foot.
25331 | LD A,E | A=character number (183-197)
25332 | CP D | Is this a little boy?
25333 | JR NC,25360 | Move him if so
25335 | LD A,D | Otherwise bypass the little girls and skip ahead to little boy no. 1 (190)
25336 | JR 25360
The leftmost column of the play area on screen is at least 80.
25338 | CP 120 | This x-coordinate is about halfway between the tree and the gate
25340 | LD A,E | A=character number (183-197)
25341 | JR C,25350 | Jump if we can't see the first half of the girls' playground
The leftmost column of the play area on screen is at least 120. Little boys 1-8 never set foot here.
25343 | CP D | Is this a little girl?
25344 | JR C,25360 | Move her if so
25346 | LD A,198 | Otherwise bypass little boys 1-8 and skip ahead to little boy no. 9 (198)
25348 | JR 25360
The leftmost column of the play area on screen is between 80 and 112. Little girls 4-7 and little boys 1-3 never visit these parts.
25350 | CP 186 | Is this little girl no. 1-3?
25352 | JR C,25360 | Move her if so
25354 | CP 193 | Is this little boy no. 4-8?
25356 | JR NC,25360 | Move him if so
25358 | LD A,193 | Otherwise bypass little girls 4-7 and little boys 1-3 and skip ahead to little boy no. 4 (193)
We've now determined which character to move next. His character number is in A.
25360 | LD (HL),A | Store the number of the character to be moved next in 32764
25361 | LD H,A | Point HL at byte 30 of this character's buffer
25362 | LD L,30
25364 | DEC (HL) | Is it time to consider a change in walking speed?
25365 | JR NZ,25401 | Jump if not
It's time to consider a change in walking speed. If the character is a boy or girl, decide whether they will walk or run for the next little while.
25367 | CALL 25233 | A=random number
25370 | AND 31 | 0<=A<=31
25372 | ADD A,32 | 32<=A<=63
25374 | RRA | 16<=A<=31 (and the carry flag is set if the random number was odd)
25375 | LD (HL),A | Place this number into byte 30 of the character's buffer
25376 | SBC A,A | A=0 if the random number was even, 255 otherwise
25377 | DEC L | L=29
25378 | AND 128 | A=0 (character will walk) or 128 (character will run if he's a kid)
25380 | OR (HL) | Superimpose the current contents of byte 29
25381 | BIT 6,(HL) | Is this a human character (183<=H<=209)?
25383 | JR NZ,25389 | Jump if not
We're dealing with a human character. Bit 4 of byte 29 of the character's buffer is never set, but if it were, it would make the character run until the current command list routine has finished. Check bit 4 of byte 29 now.
25385 | BIT 4,(HL) | Bit 4 of byte 29 is unused and always reset
25387 | JR Z,25393 | Always make this jump
25389 | OR 128 | Ensure that bit 7 of byte 29 is set for non-human characters
25391 | JR 25399 |
25393 | BIT 5,(HL) | Is this an adult character (200<=H<=205)?
25395 | JR Z,25399 | Jump if not
25397 | AND 127 | Ensure that bit 7 of byte 29 is reset for adult characters (to make them walk)
25399 | LD (HL),A | Restore byte 29 with bit 7 set (run) or reset (walk) as appropriate
25400 | INC L | L=30
Now to determine whether to move the character this time round. The answer will be yes if byte 30 (which is decremented on each pass through this routine) is even, or bit 7 of byte 29 is set (indicating that the character is either running or non-human).
25401 | BIT 0,(HL) | Is the counter at byte 30 currently even?
25403 | JR Z,25409 | Jump if so (half the time)
25405 | DEC L | L=29
25406 | BIT 7,(HL) | Is the character both human and not running?
25408 | RET Z | Return if so
The character shall be moved. From this point, the following steps are taken:
Step | Action
--- | ---
1 | If there is an uninterruptible subcommand routine address in bytes 17 and 18 of the character's buffer, jump to it
2 | If there is a continual subcommand routine address in bytes 23 and 24 of the character's buffer, call it (and then return to step 3)
3 | If there is an interruptible subcommand routine address in bytes 9 and 10 of the character's buffer, jump to it
4 | Restart the command list if bit 0 of byte 29 of the character's buffer is set (and carry on to step 5)
5 | If there is a primary command routine address in bytes 3 and 4 of the character's buffer, jump to it
6 | Remove any continual subcommand routine address from bytes 23 and 24 of the character's buffer
7 | Collect the next primary command routine address from the command list, place it into bytes 3 and 4 of the character's buffer, and jump to it
The address of one of the following uninterruptible subcommand routines (or an entry point thereof) may be present in bytes 17 and 18 of the character's buffer:
Address | Description
--- | ---
24328 | Make HAYLEY hit ERIC
26224 | Deal with a character who's been dethroned (1)
26239 | Deal with a character who's been dethroned (2)
26263 | Deal with a character who is looking for a seat
27941 | Make a boy sit still until assembly is finished
28855 | Make a character open or close a door
29194 | Control the bike when ERIC's not sitting on the saddle
29896 | Control the descent of the water, sherry or conker
30102 | Deal with a character who has been knocked over
30380 | Control the flight of a catapult pellet
30643 | Deal with BOY WANDER when he is firing
30739 | Deal with ANGELFACE when he is hitting
30804 | Deal with the frog when it has been knocked out of a cup
30906 | Control the frog
31078 | Control a female character while she's standing on a chair or jumping (1)
31092 | Make a female character stand on a chair or start jumping
31254 | Control a mouse
53796 | Make a character do nothing
62386 | Control an open desk lid
63627 | Control a stinkbomb cloud
63733 | Make MR WACKER find a window to open after smelling a stinkbomb
63960 | Control water fired from the pistol
64175 | Control a watered plant
The address of one of the following continual subcommand routines (or an entry point thereof) may be present in bytes 23 and 24 of the character's buffer:
Address | Description
--- | ---
30555 | Make BOY WANDER fire his catapult now and then
62668 | Make ALBERT keep an eye out for ERIC during lessons
63455 | Make ANGELFACE stalk HAYLEY
63492 | Make ANGELFACE or BOY WANDER hit or fire now and then
The address of one of the following interruptible subcommand routines (or an entry point thereof) may be present in bytes 9 and 10 of the character's buffer:
Address | Description
--- | ---
25581 | Guide a character to an intermediate destination
25656 | Guide a character up a staircase
25677 | Guide a character down a staircase
26639 | Make a teacher wipe a blackboard
26752 | Make a character write on a blackboard
27144 | Make a character speak
32379 | Make MISS TAKE chase ERIC (2)
61463 | Make EINSTEIN speak
61595 | Make a teacher find the truant ERIC
62794 | Make MR WACKER find the truant ERIC
The address of one of the following primary command routines (or an entry point thereof) may be present in bytes 3 and 4 of the character's buffer:
Address | Description
--- | ---
25700 | Make a character go to a location
25815 | Make a character go to a random location
26304 | Make a character find a seat
27904 | Control a boy during assembly
29052 | Make a character open or close a door
31952 | Make a character walk up and down until a certain time
31969 | Make a character walk up and down a few times or until a certain time
32497 | Make BOY WANDER write on a blackboard
53796 | Make a character do nothing
61440 | Control EINSTEIN during class
61555 | Restart the command list or make a teacher tell the kids to sit down
61624 | Restart the command list
61631 | Make a teacher find ERIC if he's absent during dinner
61658 | Control a teacher during assembly
61696 | Make a teacher conduct a class
62032 | Make MR WACKER put the kids in detention
62560 | Make the next command be the start of the command list
62572 | Restart the command list unless the boys' skool door is closed
62599 | Jump forward in the command list if the boys' skool door or the gate is closed
62620 | Wait till everyone has gone past the gate or the boys' skool door
63447 | Place a continual subcommand routine address into a character's buffer
63501 | Restart the command list unless it's time for assembly
25409 | LD L,18 | Jump if there is an uninterruptible subcommand routine address in bytes 17 and 18 of the character's buffer
25411 | LD A,(HL)
25412 | AND A
25413 | JR NZ,25479
25415 | LD L,24 | Jump if there is no continual subcommand routine address in bytes 23 and 24 of the character's buffer
25417 | LD A,(HL)
25418 | AND A
25419 | JR Z,25432
25421 | PUSH HL | Save the character number
25422 | LD BC,25431 | Push 25431 (the address of the entry point to return to) onto the stack
25425 | PUSH BC
25426 | LD B,A | Collect the address of the continual subcommand routine from bytes 23 and 24 of the character's buffer into BC and push it onto the stack
25427 | DEC L
25428 | LD C,(HL)
25429 | PUSH BC
25430 | RET | JP (BC) and then return to 25431 below
25431 | POP HL | Restore the character number to H
This entry point is used by the routine at 25492.
25432 | LD L,10 | Jump if there is an interruptible subcommand routine address in bytes 9 and 10 of the character's buffer
25434 | LD A,(HL)
25435 | AND A
25436 | JR NZ,25479
If we get here, that means there's no uninterruptible subcommand routine address in bytes 17 and 18 and no interruptible subcommand routine address in bytes 9 and 10 of the character's buffer at the moment. We take this opportunity to check whether a command list restart has been requested, by inspecting bit 0 of byte 29. This bit is set in the following routines on particular occasions:
Routine | Occasion
--- | ---
32062 | MISS TAKE needs to chase ERIC out of the girls' skool
61595 | A teacher must find the absent ERIC during class, dinner or assembly
62668 | MR WACKER must find the truant ERIC
62770 | MR WACKER must find and expel ERIC
63309 | Lesson has ended
In addition, a command in the command list may have requested a restart (see 61555, 61624, 62572 and 63501).
25438 | LD L,29 | Check bit 0 of byte 29: do we need to restart the command list?
25440 | BIT 0,(HL)
25442 | JR Z,25457 | Jump if not
25444 | RES 0,(HL) | Reset bit 0 of byte 29 now that we are going to restart
25446 | LD D,H | D=character number
25447 | LD L,27 | Point HL at where the address of the character's current command list is held
25449 | LD E,25 | Point DE at where the address of the place reached in the character's current command list is held
25451 | LDI | Copy the former into the latter (thus returning to the start of the command list)
25453 | LDI
25455 | JR 25467 |
25457 | LD L,4 | Jump if there is a primary command routine address in bytes 3 and 4 of the character's buffer
25459 | LD A,(HL)
25460 | AND A
25461 | JR NZ,25479
There is no primary command routine address in bytes 3 and 4 of the character's buffer, which means it's time to move to the next command in the list.
25463 | LD L,29 | Reset bit 3 of byte 29, indicating that this character may not be considered for teleportation for the remainder of this lesson (see 25026)
25465 | RES 3,(HL)
25467 | RES 4,(HL) | Reset bit 4 of byte 29, indicating that the character should no longer run if he was doing so (though this bit is unused and always reset)
25469 | LD L,24 | Remove the address of any continual subcommand routine from bytes 23 and 24 of the character's buffer
25471 | LD (HL),0
This entry point is used by the routine at 63447.
25473 | LD L,3 | Collect the routine address of the next command in the character's current command list and place it into bytes 3 and 4 of the buffer
25475 | CALL 25188
25478 | INC L | L=4
25479 | LD B,(HL) | Collect the command routine address from bytes 3 and 4, bytes 9 and 10, or bytes 17 and 18 of the character's buffer into BC
25480 | DEC L
25481 | LD C,(HL)
25482 | PUSH BC | Make an indirect jump to this address
25483 | RET