From 197081f10dcc7ae9c6baf26eff912fd0c8987088 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 4 Aug 2022 23:04:16 +0200 Subject: [PATCH] keyboardhandler --- codeAst/src/prog8/code/ast/AstExpressions.kt | 6 +++--- compiler/res/prog8lib/cx16/syslib.p8 | 2 +- examples/cx16/keyboardhandler.p8 | 13 ++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/codeAst/src/prog8/code/ast/AstExpressions.kt b/codeAst/src/prog8/code/ast/AstExpressions.kt index 8308c2d17..0a10473bb 100644 --- a/codeAst/src/prog8/code/ast/AstExpressions.kt +++ b/codeAst/src/prog8/code/ast/AstExpressions.kt @@ -15,9 +15,9 @@ sealed class PtExpression(val type: DataType, position: Position) : PtNode(posit if(type==DataType.UNDEFINED) { @Suppress("LeakingThis") when(this) { - is PtBuiltinFunctionCall -> {} - is PtFunctionCall -> {} - is PtIdentifier -> {} + is PtBuiltinFunctionCall -> { /* void function call */ } + is PtFunctionCall -> { /* void function call */ } + is PtIdentifier -> { /* non-variable identifier */ } else -> throw IllegalArgumentException("type should be known @$position") } } diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index 8fc2d27e0..3a24b27b6 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -98,7 +98,7 @@ cx16 { &uword ISTOP = $0328 &uword IGETIN = $032a &uword ICLALL = $032c - &uword KEYHDL = $032e ; keyboard scan code handler + &uword KEYHDL = $032e ; keyboard scan code handler see examples/cx16/keyboardhandler.p8 &uword ILOAD = $0330 &uword ISAVE = $0332 &uword NMI_VEC = $FFFA ; 65c02 nmi vector, determined by the kernal if banked in diff --git a/examples/cx16/keyboardhandler.p8 b/examples/cx16/keyboardhandler.p8 index 8f1450f1e..ae224bd90 100644 --- a/examples/cx16/keyboardhandler.p8 +++ b/examples/cx16/keyboardhandler.p8 @@ -6,7 +6,7 @@ main { sub start() { - txt.print("ps2 scancode handler test - press keys! esc to quit!\n") + txt.print("ps2 custom key handler test - press keys! esc to quit!\n") sys.set_irqd() uword old_keyhdl = cx16.KEYHDL @@ -22,7 +22,7 @@ main { sys.clear_irqd() } - sub keyboard_scancode_handler(ubyte prefix, ubyte scancode, bool updown) { + sub keyboard_scancode_handler(ubyte prefix, ubyte scancode, bool updown) -> bool { txt.print_ubhex(prefix, true) txt.chrout(':') txt.print_ubhex(scancode, true) @@ -36,7 +36,7 @@ main { ; escape was pressed! exit back to basic main.start.escape_pressed = true } - return + return true ; true = consume key event, false = continue processing it asm_shim: %asm {{ @@ -49,8 +49,15 @@ asm_shim: + stx prefix sta scancode jsr keyboard_scancode_handler + beq + plx pla + lda #0 ;By setting A=0 we will consume this key event + tax + plp + rts ++ plx + pla ; leave A untouched, continue processing plp rts }}