diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index 39697377c..7a33ce925 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -81,7 +81,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_byte_value_to_variable(target.asmVarname, target.datatype, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } } in WordDatatypes -> { @@ -100,7 +99,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_word_value_to_variable(target.asmVarname, target.datatype, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } } DataType.FLOAT -> { @@ -142,7 +140,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, ) } } - else -> throw AssemblyError("weird source type ${value.kind}") } } else -> throw AssemblyError("weird type to do in-place modification on ${target.datatype}") @@ -167,7 +164,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_byte_value_to_variable(addr.toHex(), DataType.UBYTE, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } } is PtIdentifier -> { @@ -186,7 +182,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_byte_value_to_pointer(pointer, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } } else -> { @@ -207,7 +202,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } asmgen.restoreRegisterStack(CpuRegister.Y, false) asmgen.restoreRegisterStack(CpuRegister.A, false) @@ -240,7 +234,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_byte_value_to_variable(targetVarName, target.datatype, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } } in WordDatatypes -> { @@ -258,7 +251,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_word_value_to_variable(targetVarName, target.datatype, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } } DataType.FLOAT -> { @@ -300,7 +292,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, ) } } - else -> throw AssemblyError("weird source type ${value.kind}") } } else -> throw AssemblyError("weird type to do in-place modification on ${target.datatype}") @@ -329,7 +320,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", target.datatype, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } asmgen.restoreRegisterStack(CpuRegister.Y, false) asmgen.out(" lda P8ZP_SCRATCH_B1 | sta ${target.array.variable.name},y") @@ -361,7 +351,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, inplaceModification_word_value_to_variable("P8ZP_SCRATCH_W1", target.datatype, operator, value.expression!!) } } - else -> throw AssemblyError("weird source type ${value.kind}") } asmgen.restoreRegisterStack(CpuRegister.Y, false) if(target.array.splitWords) { @@ -425,7 +414,6 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, ) } } - else -> throw AssemblyError("weird source type ${value.kind}") } asmgen.out(""" lda P8ZP_SCRATCH_W1 diff --git a/compiler/src/prog8/buildversion/BuildVersion.kt b/compiler/src/prog8/buildversion/BuildVersion.kt index b50ae16cd..cea017ca5 100644 --- a/compiler/src/prog8/buildversion/BuildVersion.kt +++ b/compiler/src/prog8/buildversion/BuildVersion.kt @@ -5,11 +5,11 @@ package prog8.buildversion */ const val MAVEN_GROUP = "prog8" const val MAVEN_NAME = "compiler" -const val VERSION = "9.1-SNAPSHOT" -const val GIT_REVISION = 3930 -const val GIT_SHA = "b4e94ae4dd1c29a966bb5ea0454ab31f1e9863cb" -const val GIT_DATE = "2023-07-05T21:15:04Z" -const val GIT_BRANCH = "master" -const val BUILD_DATE = "2023-07-05T21:15:07Z" -const val BUILD_UNIX_TIME = 1688591707834L +const val VERSION = "9.2-SNAPSHOT" +const val GIT_REVISION = 3974 +const val GIT_SHA = "ab8173637a9939352ddb027ecd67f1c42b63b1fc" +const val GIT_DATE = "2023-07-16T09:15:28Z" +const val GIT_BRANCH = "remove_evalstack" +const val BUILD_DATE = "2023-07-16T11:04:18Z" +const val BUILD_UNIX_TIME = 1689505458888L const val DIRTY = 1 diff --git a/docs/source/todo.rst b/docs/source/todo.rst index b1c001c71..6289ce662 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -- (branch): fix up cx16/keyboardhandler.p8 X register shenanigans - - IR: instructions that do type conversion (SZ etc, CONCAT, SGN) should put the result in a DIFFERENT register. - IR: reduce the number of branch instructions (gradually), replace with CMP(I) + status branch instruction diff --git a/examples/cx16/keyboardhandler.p8 b/examples/cx16/keyboardhandler.p8 index f53b3dd9c..614bc1eb4 100644 --- a/examples/cx16/keyboardhandler.p8 +++ b/examples/cx16/keyboardhandler.p8 @@ -2,21 +2,24 @@ %zeropage basicsafe %option no_sysinit -; The documentation for custom PS2 key handlers can be found here: -; https://github.com/X16Community/x16-docs/blob/master/X16%20Reference%20-%2002%20-%20Editor.md#custom-keyboard-scancode-handler +; 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 main { + bool stop_program = false + sub start() { txt.print("custom key handler test - press keys! esc to quit!\n") sys.set_irqd() uword old_keyhdl = cx16.KEYHDL - cx16.KEYHDL = &keyboard_scancode_handler + cx16.KEYHDL = &keyboard_handler sys.clear_irqd() - while handle_keyboard_event() { + while not stop_program { + ; wait } sys.set_irqd() @@ -24,55 +27,23 @@ main { sys.clear_irqd() } - ; 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_scancode - - sub handle_keyboard_event() -> bool { - ; 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 true - keyhdl_event = false - txt.print_ubhex(keyhdl_scancode, true) + 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) txt.spc() - if keyhdl_scancode & $80 + if keynum & $80 txt.chrout('u') else txt.chrout('d') txt.nl() - return keyhdl_scancode!=$6e ; escape breaks the loop - } - 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 by the kernal. - ; Pog8 uses the X register internally (for the software eval 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 easily 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 {{ - pha - sta p8_keyhdl_scancode - lda #1 - sta p8_keyhdl_event - pla - - lda #0 ; By setting A=0 we will eat this key event. leave A unchanged to pass it through. - rts - }} + 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. } }