| Routines

63210: Main loop

The routine at 63189 continues here.
63210 | LD HL,32739 | 32739 holds the lesson clock
63213 | DEC (HL) | Decrement the LSB
63214 | JR NZ,63223 | Jump if it's non-zero
63216 | INC L | Point HL at the MSB of the lesson clock
63217 | DEC (HL) | Decrement the MSB
63218 | LD A,(HL) | Copy the new MSB to A
63219 | INC A | Have we reached the end of the lesson?
63220 | CALL Z,63309 | Ring the bell and start the next lesson if so
63223 | CALL 63156 | Move the characters, close any temporarily open doors, and make the nearest teacher give ERIC lines if he's up to something he shouldn't be
63226 | LD HL,32763 | 32763 holds ERIC's primary status flags
63229 | LD A,(HL) | Pick these up in A
63230 | AND A | Are any of the status flags set?
63231 | JR Z,63238 | Jump if not
63233 | CALL 63405 | Deal with ERIC if any of the status flags at 32763 are set
63236 | JR 63283 |
No status flags at 32763 are set, which means ERIC is standing, or midstride, or just about to finish a 'short action' (bending over, dropping a stinkbomb, firing the water pistol, or moving forward as if to kiss). Here we finish ERIC's stride if he's midstride, finish any action he's just about to finish, or check for keypresses.
63238 | LD L,243 | Decrement ERIC's main action timer at 32755
63240 | DEC (HL)
63241 | JR NZ,63283 | Jump unless it's 0
63243 | DEC L | Collect the mid-action timer from 32754 into A; it will be non-zero if ERIC is midstride or mid-action
63244 | LD A,(HL)
63245 | LD (HL),0 | Reset the mid-action timer to 0
63247 | INC L | Copy the previous contents of the mid-action timer into the main action timer at 32755
63248 | LD (HL),A
63249 | AND A | Is ERIC midstride or mid-action?
63250 | JR NZ,63280 | Jump if so
ERIC is neither midstride nor just about to finish a short action, so check the keyboard.
63252 | CALL 62483 | Check for keypresses
63255 | JR Z,63283 | Jump if there haven't been any
63257 | LD (32753),A | Store the offset of the last keypress in 32753
63260 | LD H,229 | HL will index the table of keypress handling routines at 58704
63262 | LD DE,63283 | Push the address 63283 (see below) onto the stack so we return there after dealing with the keypress
63265 | PUSH DE
63266 | LD L,A | Point HL at the appropriate entry
63267 | LD C,(HL) | Copy the address of the routine for dealing with the keypress into BC
63268 | INC L
63269 | LD B,(HL)
63270 | PUSH BC | Push this address onto the stack
63271 | LD HL,53760 | Point HL at byte 0 of ERIC's buffer
63274 | LD A,(HL) | Collect ERIC's animatory state into A, and his coordinates into DE
63275 | INC L
63276 | LD E,(HL)
63277 | INC L
63278 | LD D,(HL)
63279 | RET | Make an indirect jump to the relevant keypress-handling routine, and then return to 63283
ERIC is midstride, or just about to finish an action (such as firing the water pistol or catching a mouse). Make him finish the stride or action.
63280 | CALL 28160 | Update ERIC's animatory state and location, update the SRB, and scroll the screen if necessary
Now that ERIC's movements have been dealt with, the main loop continues.
63283 | CALL 25248 | Update the display
63286 | LD HL,32755 | 32755 holds ERIC's main action timer
63289 | LD A,(HL) | Pick this up in A
63290 | AND A | Did we check for keypresses on this pass?
63291 | JR NZ,63295 | Jump if not
63293 | LD (HL),2 | Otherwise reset ERIC's main action timer to 2
This next section of code ensures that we don't pass through the main loop more than once every 1/50th of a second.
63295 | LD L,217 | HL=32729 (which holds the LSB of the system variable FRAMES as it was when the last pass through the main loop was completed)
63297 | LD A,(23672) | A=LSB of the system variable FRAMES, which is incremented every 1/50th of a second
63300 | SUB (HL) | Now A=0 if FRAMES hasn't been incremented since the last pass through the main loop
63301 | CP 1 | Was FRAMES incremented?
63303 | JR C,63297 | Jump back if not to check again
63305 | ADD A,(HL) | Store the current value of the LSB of FRAMES at 32729
63306 | LD (HL),A
63307 | JR 63210 | Jump back to the start of the main loop