2022-04-02 00:08:01 +00:00
|
|
|
%import textio
|
|
|
|
%zeropage basicsafe
|
|
|
|
%option no_sysinit
|
|
|
|
|
|
|
|
main {
|
|
|
|
|
|
|
|
sub start() {
|
|
|
|
|
2022-08-04 21:04:16 +00:00
|
|
|
txt.print("ps2 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
|
|
|
|
cx16.KEYHDL = &main.keyboard_scancode_handler.asm_shim
|
|
|
|
sys.clear_irqd()
|
|
|
|
|
2022-07-08 19:50:32 +00:00
|
|
|
bool escape_pressed
|
2022-04-02 00:08:01 +00:00
|
|
|
while not escape_pressed {
|
|
|
|
; just sit here
|
|
|
|
}
|
|
|
|
sys.set_irqd()
|
|
|
|
cx16.KEYHDL = old_keyhdl
|
|
|
|
sys.clear_irqd()
|
|
|
|
}
|
|
|
|
|
2022-08-04 21:04:16 +00:00
|
|
|
sub keyboard_scancode_handler(ubyte prefix, ubyte scancode, bool updown) -> bool {
|
2022-04-02 15:53:24 +00:00
|
|
|
txt.print_ubhex(prefix, true)
|
|
|
|
txt.chrout(':')
|
|
|
|
txt.print_ubhex(scancode, true)
|
2022-04-02 00:08:01 +00:00
|
|
|
txt.spc()
|
|
|
|
if updown
|
|
|
|
txt.chrout('u')
|
|
|
|
else
|
|
|
|
txt.chrout('d')
|
|
|
|
txt.nl()
|
|
|
|
if prefix==0 and scancode==119 and updown {
|
|
|
|
; escape was pressed! exit back to basic
|
|
|
|
main.start.escape_pressed = true
|
|
|
|
}
|
2022-08-04 21:04:16 +00:00
|
|
|
return true ; true = consume key event, false = continue processing it
|
2022-04-02 00:08:01 +00:00
|
|
|
|
|
|
|
asm_shim:
|
|
|
|
%asm {{
|
|
|
|
php
|
|
|
|
pha
|
|
|
|
phx
|
|
|
|
stz updown
|
|
|
|
bcc +
|
|
|
|
inc updown
|
2022-04-02 15:53:24 +00:00
|
|
|
+ stx prefix
|
|
|
|
sta scancode
|
|
|
|
jsr keyboard_scancode_handler
|
2022-08-04 21:04:16 +00:00
|
|
|
beq +
|
2022-04-02 00:08:01 +00:00
|
|
|
plx
|
|
|
|
pla
|
2022-08-04 21:04:16 +00:00
|
|
|
lda #0 ;By setting A=0 we will consume this key event
|
|
|
|
tax
|
|
|
|
plp
|
|
|
|
rts
|
|
|
|
+ plx
|
|
|
|
pla ; leave A untouched, continue processing
|
2022-04-02 00:08:01 +00:00
|
|
|
plp
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|