diff --git a/.idea/misc.xml b/.idea/misc.xml
index a73ef3d0a..cd58425e0 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -19,7 +19,7 @@
-
+
\ No newline at end of file
diff --git a/codeGenVirtual/codeGenVirtual.iml b/codeGenVirtual/codeGenVirtual.iml
new file mode 100644
index 000000000..99e1bf4ce
--- /dev/null
+++ b/codeGenVirtual/codeGenVirtual.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/cx16/keyboardhandler.p8 b/examples/cx16/keyboardhandler.p8
index ae224bd90..2a4d266f8 100644
--- a/examples/cx16/keyboardhandler.p8
+++ b/examples/cx16/keyboardhandler.p8
@@ -10,56 +10,85 @@ main {
sys.set_irqd()
uword old_keyhdl = cx16.KEYHDL
- cx16.KEYHDL = &main.keyboard_scancode_handler.asm_shim
+ cx16.KEYHDL = &keyboard_scancode_handler
sys.clear_irqd()
bool escape_pressed
while not escape_pressed {
- ; just sit here
+ handle_keyboard_event()
}
sys.set_irqd()
cx16.KEYHDL = old_keyhdl
sys.clear_irqd()
}
- sub keyboard_scancode_handler(ubyte prefix, ubyte scancode, bool updown) -> bool {
- txt.print_ubhex(prefix, true)
+ ; Keyboard handler communication variables.
+ ; these need to be in block scope instead of in a subroutine,
+ ; so that they won't get overwritten with initialization values every time.
+ ; The assembly keyboard handler will set these, prog8 will read them.
+ bool @shared keyhdl_event ; is there a keyboard event to handle?
+ ubyte @shared keyhdl_prefix
+ ubyte @shared keyhdl_scancode
+ ubyte @shared keyhdl_updown
+
+ sub handle_keyboard_event() {
+ ; Potentially handle keyboard event.
+ ; Note that we do this from the program's main loop instead of
+ ; the actual keyboard handler routine itself.
+ ; The reason for this is documented below in the handler assembly routine.
+ if not keyhdl_event
+ return
+ keyhdl_event = false
+ txt.print_ubhex(keyhdl_prefix, true)
txt.chrout(':')
- txt.print_ubhex(scancode, true)
+ txt.print_ubhex(keyhdl_scancode, true)
txt.spc()
- if updown
+ if keyhdl_updown
txt.chrout('u')
else
txt.chrout('d')
txt.nl()
- if prefix==0 and scancode==119 and updown {
+ if keyhdl_prefix==0 and keyhdl_scancode==119 and keyhdl_updown {
; escape was pressed! exit back to basic
main.start.escape_pressed = true
}
- return true ; true = consume key event, false = continue processing it
+ }
+
+ asmsub keyboard_scancode_handler() {
+
+ ; NOTE that the keyboard handler is an asm subroutine.
+ ; Unfortunately is it not possible to use prog8 code or calls here,
+ ; because the X register gets overwritten here (to store the prefix byte)
+ ; and prog8 uses the X register internally (for the evaluation stack).
+ ; So it is unsafe to call prog8 code from here because the evaluation stack pointer
+ ; will be invalid which produces undefined results.
+ ; So, instead, we store the various keyboard event bytes and signal
+ ; the main prog8 program that a keyboard event has occurred.
+ ; It then processes it independently from the assembly code here.
+ ;
+ ; Unfortunately this also means you cannot decide from that prog8 code
+ ; if the keyboard press should be consumed/ignored or put into the keyboard queue
+ ; (this is controlled by returning 0 or 1 in register A here)
-asm_shim:
%asm {{
php
pha
phx
- stz updown
+ stz keyhdl_updown
bcc +
- inc updown
-+ stx prefix
- sta scancode
- jsr keyboard_scancode_handler
- beq +
+ inc keyhdl_updown
++ stx keyhdl_prefix
+ sta keyhdl_scancode
+ lda #1
+ sta keyhdl_event
+ ; we can do additional stuff here and decide if we want to
+ ; consume the key event or not (A=0 or A!=0)
plx
pla
- lda #0 ;By setting A=0 we will consume this key event
+ lda #0 ;By setting A=0 we will remove this key event for now
tax
plp
rts
-+ plx
- pla ; leave A untouched, continue processing
- plp
- rts
}}
}
}
diff --git a/examples/cx16/vtui/VTUI0.9.BIN b/examples/cx16/vtui/VTUI0.9.BIN
deleted file mode 100644
index 86c086bf5..000000000
Binary files a/examples/cx16/vtui/VTUI0.9.BIN and /dev/null differ
diff --git a/examples/cx16/vtui/VTUI1.0.BIN b/examples/cx16/vtui/VTUI1.0.BIN
new file mode 100644
index 000000000..6d36bb86c
Binary files /dev/null and b/examples/cx16/vtui/VTUI1.0.BIN differ
diff --git a/examples/cx16/vtui/testvtui.p8 b/examples/cx16/vtui/testvtui.p8
index bfac7e06f..707dc9df7 100644
--- a/examples/cx16/vtui/testvtui.p8
+++ b/examples/cx16/vtui/testvtui.p8
@@ -110,10 +110,10 @@ char_loop:
vtui $1000 {
- %asmbinary "VTUI0.9.BIN", 2 ; skip the 2 dummy load address bytes
+ %asmbinary "VTUI1.0.BIN", 2 ; skip the 2 dummy load address bytes
; NOTE: base address $1000 here must be the same as the block's memory address, for obvious reasons!
- ; The routines below are for VTUI 0.8
+ ; The routines below are for VTUI 1.0
romsub $1000 = initialize() clobbers(A, X, Y)
romsub $1002 = screen_set(ubyte mode @A) clobbers(A, X, Y)
romsub $1005 = set_bank(ubyte bank @Pc) clobbers(A)
@@ -133,6 +133,9 @@ vtui $1000 {
romsub $102f = save_rect(ubyte ramtype @A, ubyte vbank @Pc, uword address @R0, ubyte width @R1, ubyte height @R2) clobbers(A, X, Y)
romsub $1032 = rest_rect(ubyte ramtype @A, ubyte vbank @Pc, uword address @R0, ubyte width @R1, ubyte height @R2) clobbers(A, X, Y)
romsub $1035 = input_str(uword buffer @R0, ubyte buflen @Y, ubyte colors @X) clobbers (A) -> ubyte @Y
+ romsub $1038 = get_bank() clobbers (A) -> ubyte @Pc
+ romsub $103b = get_stride() -> ubyte @A
+ romsub $103e = get_decr() clobbers (A) -> ubyte @Pc
; -- helper function to do string length counting for you internally, and turn the convertchars flag into a boolean again
asmsub print_str2(str txtstring @R0, ubyte colors @X, ubyte convertchars @Pc) clobbers(A, Y) {