2022-04-02 00:08:01 +00:00
|
|
|
%import textio
|
|
|
|
%zeropage basicsafe
|
|
|
|
%option no_sysinit
|
|
|
|
|
2023-07-16 11:23:34 +00:00
|
|
|
; The documentation for custom key handlers can be found here:
|
|
|
|
; https://github.com/X16Community/x16-docs/blob/master/X16%20Reference%20-%2002%20-%20Editor.md#custom-keyboard-keynum-code-handler
|
2023-03-12 15:09:55 +00:00
|
|
|
|
2022-04-02 00:08:01 +00:00
|
|
|
main {
|
|
|
|
|
2023-07-16 11:23:34 +00:00
|
|
|
bool stop_program = false
|
|
|
|
|
2022-04-02 00:08:01 +00:00
|
|
|
sub start() {
|
|
|
|
|
2023-05-14 21:33:57 +00:00
|
|
|
txt.print("custom key handler test - press keys! esc to quit!\n")
|
2022-04-02 00:08:01 +00:00
|
|
|
|
|
|
|
sys.set_irqd()
|
|
|
|
uword old_keyhdl = cx16.KEYHDL
|
2023-07-16 11:23:34 +00:00
|
|
|
cx16.KEYHDL = &keyboard_handler
|
2022-04-02 00:08:01 +00:00
|
|
|
sys.clear_irqd()
|
|
|
|
|
2023-07-16 11:23:34 +00:00
|
|
|
while not stop_program {
|
|
|
|
; wait
|
2022-04-02 00:08:01 +00:00
|
|
|
}
|
2023-05-14 21:33:57 +00:00
|
|
|
|
2022-04-02 00:08:01 +00:00
|
|
|
sys.set_irqd()
|
|
|
|
cx16.KEYHDL = old_keyhdl
|
|
|
|
sys.clear_irqd()
|
|
|
|
}
|
|
|
|
|
2023-07-16 11:23:34 +00:00
|
|
|
sub keyboard_handler(ubyte keynum) -> ubyte {
|
|
|
|
; NOTE: this handler routine expects the keynum in A and return value in A
|
|
|
|
; which is thankfully how prog8 translates this subroutine's calling convention.
|
|
|
|
; NOTE: it may be better to store the keynum somewhere else and let the main program
|
|
|
|
; loop figure out what to do with it, rather than putting it all in the handler routine
|
|
|
|
txt.print_ubhex(keynum, true)
|
2022-04-02 00:08:01 +00:00
|
|
|
txt.spc()
|
2024-02-04 22:18:11 +00:00
|
|
|
if keynum & $80 !=0
|
2022-04-02 00:08:01 +00:00
|
|
|
txt.chrout('u')
|
|
|
|
else
|
|
|
|
txt.chrout('d')
|
|
|
|
txt.nl()
|
2023-01-24 00:30:57 +00:00
|
|
|
|
2023-07-16 11:23:34 +00:00
|
|
|
if keynum==$6e {
|
|
|
|
; escape stops the program
|
|
|
|
main.stop_program = true
|
|
|
|
}
|
|
|
|
return 0 ; By returning 0 (in A) we will eat this key event. Return the original keynum value to pass it through.
|
2023-05-14 21:29:04 +00:00
|
|
|
}
|
2022-04-02 00:08:01 +00:00
|
|
|
}
|