+; --------------------------------------------------------------------------
+; Make the function keys return function key codes instead of the current
+; strings so the program will see and may handle them.
+; Undo this change when the program ends
+
+ .constructor initkbd
+ .destructor donekbd
+
+.segment "INIT" ; Special init code segment may get overwritten
+
+.proc initkbd
+
+ ldy #15
+@L1: lda fnkeys,y
+ sta FKEY_SPACE,y
+ dey
+ bpl @L1
+ rts
+
+.endproc
+
+
+.segment "LOWCODE" ; Accesses the ROM - must go into low mem
+
+.proc donekbd
+
+ ldx #$39 ; Copy the original function keys
+ sta ENABLE_ROM ; Bank in the ROM
+@L1: lda FKEY_ORIG,x
+ sta FKEY_SPACE,x
+ dex
+ bpl @L1
+ sta ENABLE_RAM ; Bank out the ROM
+ rts
+
+.endproc
+
+
+; Function key table, readonly
+
+.rodata
+fnkeys: .byte $01, $01, $01, $01, $01, $01, $01, $01
+ .byte 133, 137, 134, 138, 135, 139, 136, 140
+