| Routines

6652: 'O' pressed - left

The address of this routine is found in the table of keypress handling routines at 6800. It is called from the main loop at 6767 when 'O' or '5' is pressed, and is also used by the routines at 657F and 65E4.
Input
B | ERIC's animatory state
DE | ERIC's coordinates
6652 | CALL $6564 | Is ERIC sitting or lying down?
6655 | RET NZ | Return if so
6656 | CALL $6648 | Check whether ERIC is on a staircase
6659 | LD A,E | A=ERIC's x-coordinate
665A | JR Z,$6664 | Jump if ERIC's not on a staircase
665C | CP $30 | Is ERIC on a staircase at the right of the skool?
665E | JP NC,$657F | Move ERIC down a step if so
6661 | JP $65E4 | Otherwise move ERIC up a step
6664 | BIT 7,B | Is ERIC facing right?
6666 | JP NZ,$656A | Turn ERIC round if so
ERIC is facing left, and is not on a staircase.
6669 | AND A | Is ERIC standing at the far left side of the skool?
666A | RET Z | Return if so
666B | LD A,D | A=ERIC's y-coordinate
666C | CP $A9 | Is ERIC on the bottom floor?
666E | JR Z,$667A | Jump if so
6670 | CP $9B | Set the zero flag if ERIC is on the top floor
6672 | LD A,$3A | This is the x-coordinate of the wall between the Map and Reading Rooms
6674 | JR Z,$6678 | Jump if ERIC's on the top floor
6676 | LD A,$27 | This is the x-coordinate of the wall between the Exam and White Rooms
6678 | CP E | Is ERIC facing this wall (from the right side)?
6679 | RET Z | Return if so (ERIC cannot walk through walls)
There is no wall obstructing ERIC, so it's time to put him midstride.
667A | LD A,$01 | A=0x01 (ERIC midstride, facing left)
667C | LD L,E | L=ERIC's current x-coordinate
667D | DEC E | E=ERIC's post-midstride x-coordinate
This entry point is used by the routine at 66AA with A=0x81 (ERIC facing right, midstride).
667E | LD C,A | C=0x01/0x81 (ERIC midstride)
667F | LD A,($7FFC) | 7FFC holds the ASCII code of the last keypress
6682 | BIT 5,A | Was the last keypress upper case (fast)?
6684 | JR Z,$668A | Jump if so
6686 | LD A,C | Clearly these instructions have no effect, but one wonders what they might once have been and done
6687 | ADD A,$00
6689 | LD C,A
668A | LD A,($7FFB) | Collect ERIC's status flags from 7FFB
668D | BIT 6,A | Bit 6 is always reset, so this jump is always made
668F | JR Z,$6695
6691 | LD A,C | Clearly these instructions have no effect, but one wonders what they might once have been and done
6692 | ADD A,$00
6694 | LD C,A
6695 | LD A,C | A=0x01/0x81 (ERIC midstride)
6696 | LD H,D | H=ERIC's current y-coordinate
6697 | LD B,A | B=0x02/0x82 (ERIC standing, phase 3)
6698 | INC B
6699 | BIT 0,L | Is ERIC's current x-coordinate even?
669B | JR Z,$66A1 | Jump if so
669D | DEC B | Adjust ERIC's midstride animatory state (in A) to 0x03/0x83 and post-midstride animatory state (in B) to 0x00/0x80 if ERIC's current x-coordinate is odd
669E | DEC B
669F | ADD A,$02
66A1 | JP $653C | Put ERIC midstride