Prev: 7986 Up: Map Next: 79E4
7996: Collect a keypress during the game (or simulate one in demo mode)
Called from the main loop at F02B.
7996 LD A,($7FEE) A=current game mode (0-4)
7999 AND A Is it demo mode?
799A JP NZ,$EAB2 Jump if not
It's demo mode.
799D CALL $EAD9 Collect the ASCII code of the last key pressed in A
79A0 JP NZ,$F0EA Start a new game if a game key was pressed
79A3 LD A,$26 Message 0x26: 'PRESS A KEY TO PLAY'
79A5 LD ($7FD2),A Store this message number at 7FD2 so that it can be monitored
79A8 CALL $78FF Is this message in the message queue?
79AB CALL NZ,$6EC5 If not, add it to the message queue (again)
79AE LD A,$F8 Set bits 3-7 at 7FEA, effectively giving Sam the keys to all the houses
79B0 LD ($7FEA),A
79B3 LD A,($E60B) Pick up byte 0x0B of Sam's buffer (which holds his destination y-coordinate)
79B6 AND A Has a destination been set for Sam yet?
79B7 JR NZ,$79D4 Jump if so
We need to set a new destination for Sam.
79B9 CALL $F17F Get an even random number between 0x86 and 0x94 in A
79BC AND $0E
79BE ADD A,$86
79C0 LD L,A Point HL at an entry in the table of locations at 7986
79C1 LD H,$79
79C3 LD E,(HL) Collect the location coordinates in DE
79C4 INC L
79C5 LD D,(HL)
79C6 LD HL,$E60A Copy the location coordinates into bytes 0x0A and 0x0B of Sam's buffer
79C9 LD (HL),E
79CA INC L
79CB LD (HL),D
79CC LD C,$01 Assume a z-coordinate of 1 (indoors)
79CE CALL $ED47 Obtain an identifier for the location
79D1 LD L,$0C Copy the destination location identifier into byte 0x0C of Sam's buffer
79D3 LD (HL),A
79D4 LD H,$E6 0xE6=Sam
79D6 CALL $ED8C Determine the next move Sam should make to reach his destination
79D9 AND A Is Sam already at his destination?
79DA JR Z,$79B9 Jump back to set a new destination if so
Sam's destination has been set. Now to simulate a keypress that will make him take the next step towards it.
79DC ADD A,$7F Point HL at the offset of the appropriate keypress to simulate in the table at 7980
79DE LD L,A
79DF LD H,$79
79E1 LD A,(HL) Pick up the keypress offset
79E2 AND A Make sure the zero flag is reset to indicate that a simulated keypress was made (this instruction is redundant)
79E3 RET
Prev: 7986 Up: Map Next: 79E4