| Routines

6177: 'J' pressed - joystick

The address of this routine is found in the table of keypress handling routines at ED00. It is called from the main loop at F02B when 'J' is pressed.
6177 | LD A,$60 | Message 0x60: newline
6179 | LD ($7FD2),A | Store this message number at 7FD2 so that it can be watched in the message queue
617C | CALL $75CA | Queue the message urgently
617F | LD A,$61 | Message 0x61: 'JOYSTICK?'
6181 | CALL $75CA | Queue this message urgently
6184 | CALL $78FC | Wait until message 0x60 (newline) has left the queue (and therefore 'JOYSTICK?' is displayed)
6187 | JR Z,$6184
6189 | CALL $EAD9 | Wait for a keypress and collect its ASCII code in A
618C | JR Z,$6189
618E | SET 5,A | Convert the keypress to lower case
6190 | LD HL,$61BB | Point HL at the keypress offset patch table at 61BB
6193 | LD DE,$C330 | Point DE at the main keypress offset table
6196 | LD BC,$000A | There will be 10 bytes to copy
6199 | CP $6B | Was 'k' pressed?
619B | JR NZ,$61A9 | Jump if not
Now HL points at the appropriate keypress offset patch table (61C5 if 'i' (Int2) was pressed, or 61BB otherwise), and A holds the input device indicator (0x6B if 'k' (Kempston) was pressed, or 0x00 otherwise).
619D | PUSH HL | Save the pointer to the keypress offset patch table briefly
619E | LD HL,$FFFA | Set the input device indicator for future games at FFFA
61A1 | LD (HL),A
61A2 | LD H,$7F | Set the input device indicator for the current game at 7FFA
61A4 | LD (HL),A
61A5 | POP HL | Restore the address of the keypress offset patch table to HL
61A6 | LDIR | Update the entries for keys 0-9 in the keypress offset table
61A8 | RET |
Some key other than 'k' (Kempston) was pressed.
61A9 | CP $63 | Was 'c' (Cursor) pressed?
61AB | JR Z,$61B5 | Jump if so
61AD | CP $6E | Was 'n' (None) pressed?
61AF | JR Z,$61B5 | Jump if so
61B1 | LD L,$C5 | HL=61C5 (keypress offset patch table for Int2)
61B3 | CP $69 | Set the zero flag if 'i' was pressed
61B5 | LD A,$00 | 0 indicates that we're not using the Kempston joystick
61B7 | JR Z,$619D | Jump if 'i' (Int2) was pressed
61B9 | JR $6189 | Otherwise jump back to collect another keypress