| Routines

6CAF: 'S' pressed - sit/stand

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 'S' is pressed.
6CAF | LD HL,$7FFB | Flip bit 7 of ERIC's status flags at 7FFB
6CB2 | LD A,(HL)
6CB3 | XOR $80
6CB5 | LD (HL),A
6CB6 | LD H,$AC | 0xAC=ERIC
6CB8 | RLCA | Is ERIC sitting now?
6CB9 | JR C,$6CC3 | Jump if so
6CBB | CALL $6214 | Update the SRB for ERIC's current animatory state
6CBE | AND $80 | A=animatory state of ERIC standing up
6CC0 | JP $61B0 | Update ERIC's animatory state and update the SRB
ERIC is sitting now - on the floor, the stairs, or a chair?
6CC3 | CALL $6214 | Update the SRB for ERIC's current animatory state
6CC6 | LD B,A | B=ERIC's animatory state
6CC7 | CALL $6648 | Is ERIC on a staircase?
6CCA | JR Z,$6CD8 | Jump if not
ERIC is on a staircase.
6CCC | LD A,E | A=ERIC's x-coordinate
6CCD | CP $30 | Set the carry flag if ERIC's on the left side of the skool
6CCF | LD A,$85 | 0x85=ERIC sitting down facing right
6CD1 | JR C,$6CD5 | Jump if ERIC is on a staircase on the left side of the skool
6CD3 | LD A,$05 | 0x05=ERIC sitting down facing left
6CD5 | JP $61B0 | Update ERIC's animatory state and update the SRB
ERIC is not on a staircase.
6CD8 | CP $A9 | Is ERIC on the bottom floor?
6CDA | JR Z,$6CE6 | Jump if so
6CDC | BIT 7,B | Is ERIC facing right?
6CDE | JR NZ,$6CE6 | Jump if so
6CE0 | CALL $6BF1 | This should be CALL 6BF2 - is ERIC beside a chair?
6CE3 | JP Z,$6B7D | Seat him if so
6CE6 | LD A,B | A=0x06 or 0x86 (ERIC sitting on the floor)
6CE7 | AND $80
6CE9 | ADD A,$06
6CEB | JP $61B0 | Update ERIC's animatory state and update the SRB