Prev: 6DCD Up: Map Next: 6E71
6E46: Cursor-key shortcuts
Called by 6DCD for the first key of a line only. If the key is one of the four cursor keys, this routine types a complete movement command on its own and ends the line, so that a single key press moves Bilbo. The key codes come from the keyboard tables at 7BEE and 7C16:
Key Code Command
7 (up) $5B N
6 (down) $0A S
8 (right) $09 E
5 (left) $08 W
The key works with or without CAPS SHIFT. The letter is stored in the input buffer and echoed, an ENTER ($0D) is stored after it, and the routine returns with A=$0D. The line editor then carries on as if the player had pressed ENTER: it prints the new line, stores a second (harmless) ENTER and finishes the line. So one key press both types and enters the command.
For any other key the routine returns with A unchanged and the line editor deals with the key as usual. The code for the left cursor ($08) is also the backspace code; this is why cursor-left only means 'west' as the first key of a line, and means 'delete' afterwards. Cursor right and down later in a line are simply ignored.
Input
A Key code
HL Current position in the input buffer
B Space left in the buffer
Output
A $0D if a movement command was typed, otherwise unchanged
6E46 CP $09 Cursor right?
6E48 JR Z,$6E69 If yes, go to 6E69
6E4A CP $08 Cursor left?
6E4C JR Z,$6E6D If yes, go to 6E6D
6E4E CP $0A Cursor down?
6E50 JR Z,$6E65 If yes, go to 6E65
6E52 CP $5B Cursor up (code $5B)? If not, return with A unchanged
6E54 RET NZ Return if no
6E55 LD A,$4E Up: "N"
6E57 LD (HL),A Store the letter...
6E58 INC HL Increment HL
6E59 CALL $7580 ...and echo it
6E5C DEC B Decrement B
6E5D LD A,$0D Then store an ENTER
6E5F LD (HL),A Store A at (HL)
6E60 INC HL Increment HL
6E61 DEC B Decrement B
6E62 OR $01 Return with A=$0D (ENTER)
6E64 RET Done
6E65 LD A,$53 Down: "S"
6E67 JR $6E57 Continue at 6E57
6E69 LD A,$45 Right: "E"
6E6B JR $6E57 Continue at 6E57
6E6D LD A,$57 Left: "W"
6E6F JR $6E57 Continue at 6E57
Prev: 6DCD Up: Map Next: 6E71