| Routines

657F: 'A' pressed - down

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 'A' or '6' is pressed, and is also used by the routines at 6652 and 66AA.
Input
B | ERIC's animatory state
DE | ERIC's coordinates
657F | CALL $6564 | Is ERIC sitting or lying down?
6582 | RET NZ | Return if so
6583 | BIT 6,A | Bit 6 of ERIC's status flags at 7FFB is always reset, so this jump (which should be to 65D3) is never made
6585 | JR NZ,$65D4
6587 | LD A,D | A=ERIC's y-coordinate
6588 | CP $A9 | Is ERIC on the bottom floor?
658A | JR Z,$65D3 | Jump forward to move him left or right if so
658C | CP $A2 | Is ERIC on the middle floor?
658E | JR Z,$65BF | Jump if so
6590 | CP $9B | Is ERIC on the top floor?
6592 | JR Z,$65BF | Jump if so
ERIC's not on the top, middle or bottom floor, so he must be on a staircase. Should he go down a step, or turn round first?
6594 | LD A,E | A=ERIC's x-coordinate
6595 | CP $30 | Set the carry flag if ERIC's on a staircase at the left of the skool
6597 | BIT 7,B | Set the zero flag if ERIC is facing left
6599 | JR C,$65A0 | Jump if ERIC's on a staircase at the left of the skool
659B | JP NZ,$656A | Turn ERIC round if he's facing up a staircase at the right of the skool
659E | JR $65A3 |
65A0 | JP Z,$656A | Turn ERIC round if he's facing up a staircase at the left of the skool
ERIC's at the top of or on a staircase, facing the bottom of it.
65A3 | LD H,D | Copy ERIC's coordinates to HL
65A4 | LD L,E
65A5 | NOP |
65A6 | INC D | Down a step
65A7 | DEC E | One pace to the left
65A8 | LD B,$02 | 0x02=ERIC standing, facing left
65AA | CP $30 | Is ERIC on a staircase on the right side of the skool?
65AC | JR NC,$65B2 | Jump if so
65AE | LD B,$82 | 0x82=ERIC standing, facing right
65B0 | INC E | One pace to the right (taking into the account the one pace to the left made above)
65B1 | INC E
65B2 | LD A,B | A=0x02/0x82
65B3 | BIT 0,L | A=0x01/0x81, B=0x02/0x82 if ERIC's current x-coordinate is even; A=0x03/0x83, B=0x00/0x80 if ERIC's current x-coordinate is odd
65B5 | JR Z,$65BB
65B7 | DEC B
65B8 | DEC B
65B9 | ADD A,$02
65BB | DEC A
65BC | JP $653C | Update ERIC's animatory state and location
ERIC is on the middle floor or the top floor.
65BF | LD A,E | A=ERIC's x-coordinate
65C0 | CP $0C | This is the x-coordinate of the tops of the staircases at the left of the skool
65C2 | JR NZ,$65CB | Jump unless ERIC is there
65C4 | BIT 7,B | Is ERIC facing left?
65C6 | JP Z,$6652 | Move ERIC left if so
65C9 | JR $65A3 | Otherwise send ERIC down a step
65CB | CP $4D | This is the x-coordinate of the tops of the staircases at the right of the skool
65CD | JR NZ,$65D3 | Jump unless ERIC is there
65CF | BIT 7,B | Is ERIC facing left?
65D1 | JR Z,$65A3 | Send ERIC down a step if so
This entry point is used by the routine at 65E4.
65D3 | BIT 7,B | Is ERIC facing left?
65D5 | JP Z,$6652 | Move ERIC left if so
65D8 | JP $66AA | Otherwise move ERIC right