fix startup subroutine linking in VM

This commit is contained in:
Irmen de Jong 2023-03-12 16:09:55 +01:00
parent e5e63cc5ac
commit 592f74124c
3 changed files with 9 additions and 4 deletions

View File

@ -3,9 +3,6 @@ TODO
For next minor release
^^^^^^^^^^^^^^^^^^^^^^
- fix IR/VM: animals.p8 example is borked, it jumps straight to a suggestion and then somehow doesn't print the animal name correctly in the first question, and exits after 1 animal instead of looping
this has happened after v8.7: caused by c21913a6 ir: keep order of children in block 22-11-2022
...

View File

@ -2,6 +2,9 @@
%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
main {
sub start() {
@ -69,6 +72,9 @@ main {
; 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)
;
; see:
; https://github.com/X16Community/x16-docs/tree/X16%20Reference%20-%2002%20-%20Editor.md#custom-keyboard-scancode-handler
%asm {{
php

View File

@ -23,9 +23,11 @@ class VmProgramLoader {
// make sure that if there is a "main.start" entrypoint, we jump to it
irProgram.blocks.firstOrNull()?.let {
if(it.children.any { sub -> sub is IRSubroutine && sub.label=="main.start" }) {
val chunk = IRCodeChunk(null, null)
val previous = programChunks.lastOrNull()
val chunk = IRCodeChunk(null, previous)
placeholders[Pair(chunk, 0)] = "main.start"
chunk += IRInstruction(Opcode.JUMP, labelSymbol = "main.start")
previous?.let { p -> p.next = chunk }
programChunks += chunk
}
}