Routines
 Prev: F410 Up: Map Next: F460
F413: Collect a keypress during the game (or simulate one in demo mode)
Called from the main loop at F6EA. Returns with A holding the offset from the keypress table corresponding to the last (actual or simulated) keypress, or 0 if there was no (actual or simulated) keypress.
F413 LD A,(\$7FDE) A=0xFF if we're in demo mode, 0x00 otherwise
F416 INC A Are we in demo mode?
F417 JP NZ,\$71FA Read the keyboard if not
We're in demo mode.
F41A LD HL,\$0000 Set the score (held at 7FE5) and the number of lines (held at 7FE7) to 0
F41D LD (\$7FE5),HL
F420 LD (\$7FE7),HL
F423 CALL \$71BE Check for keypresses
F426 JP NZ,\$F6D5 Start a new game if there was one
No keys have been pressed, so figure out ERIC's next move by seeing what little boy no. 10 is doing.
F429 LD DE,(\$C701) Pick up the coordinates of little boy no. 10 in DE
F42D LD H,\$D2 0xD2=ERIC
F42F CALL \$64F3 Compare the coordinates of ERIC and little boy no. 10
F432 AND A Are they the same?
F433 JR Z,\$F445 Jump if so
F435 DEC A Now A=0 (ERIC is on a staircase facing up), 1 (on a staircase facing down), 2 (to the right of little boy no. 10), or 3 (to his left)
F436 LD HL,\$5C78 Point HL at the LSB of the system variable FRAMES
F439 XOR \$02 Flip bit 1 of A
Now A holds a value that will be translated into a simulated keypress depending on ERIC's location:
A ERIC's location Keypress
0 To the right of little boy no. 10 Left
1 To the left of little boy no. 10 Right
2 On a staircase, facing up Up
3 On a staircase, facing down Down
F43B BIT 7,(HL) Is the LSB of FRAMES < 0x80?
F43D JR Z,\$F441 Jump if so: this will be an upper case (fast) keypress
F43F ADD A,\$04 4<=A<=7: force a lower case (slow) keypress
F441 ADD A,A A=0x50+2n where 0<=n<=7 (simulated keypress for LEFT, RIGHT, UP, DOWN or left, right, up, down)
F444 RET
ERIC's coordinates match those of little boy no. 10 exactly.
F445 LD A,(\$C700) A=animatory state of little boy no. 10
F448 CP \$44 0x44: little boy sitting in a chair
F44A LD HL,\$D200 Point HL at byte 0x00 of ERIC's buffer
F44D JR Z,\$F455 Jump if little boy no. 10 is sitting in a chair
F44F CP \$C5 0xC5: Is little boy no. 10 sitting on the floor facing right (as in assembly)?
F451 JR Z,\$F455 Jump if so
F453 XOR A No simulated keypress (ERIC stays still)
F454 RET
Little boy no. 10 is sitting in a chair or sitting on the floor facing right (as in assembly), and ERIC is standing. Make ERIC face the same way and sit too (in the same spot as little boy no. 10).
F455 XOR (HL) Set the carry flag if ERIC and little boy no. 10 are facing in opposite directions
F456 RLCA
F457 LD A,\$62 0x62=keypress code for 'S' (sit)
F459 RET NC Return if ERIC and little boy no. 10 are facing the same way
F45A LD A,(HL) A=ERIC's animatory state
F45B RLCA Set A to 1 if ERIC is facing left (leading to a simulated keypress code of 0x52, or RIGHT), 0 if he's facing right (leading to a simulated keypress code of 0x50, or LEFT); that is, make ERIC turn round
F45C SBC A,A
F45D INC A
F45E JR \$F441
 Prev: F410 Up: Map Next: F460