diff --git a/codeCore/src/prog8/code/target/neo6502/Neo6502MachineDefinition.kt b/codeCore/src/prog8/code/target/neo6502/Neo6502MachineDefinition.kt index d067ea43b..2d48a8141 100644 --- a/codeCore/src/prog8/code/target/neo6502/Neo6502MachineDefinition.kt +++ b/codeCore/src/prog8/code/target/neo6502/Neo6502MachineDefinition.kt @@ -25,10 +25,6 @@ class Neo6502MachineDefinition: IMachineDefinition { override fun convertFloatToBytes(num: Double): List = TODO("atari float to bytes") override fun convertBytesToFloat(bytes: List): Double = TODO("atari bytes to float") - override fun importLibs(compilerOptions: CompilationOptions, compilationTargetName: String): List { - return listOf("syslib") - } - override fun launchEmulator(selectedEmulator: Int, programNameWithPath: Path) { if(selectedEmulator!=1) { System.err.println("The neo target only supports the main emulator (neo).") diff --git a/compiler/res/prog8lib/neo/syslib.p8 b/compiler/res/prog8lib/neo/syslib.p8 index 22eedf790..41810f8ca 100644 --- a/compiler/res/prog8lib/neo/syslib.p8 +++ b/compiler/res/prog8lib/neo/syslib.p8 @@ -15,6 +15,14 @@ sys { const ubyte target = 7 ; compilation target specifier. 255=virtual, 128=C128, 64=C64, 32=PET, 16=CommanderX16, 8=atari800XL, 7=Neo6502 + const ubyte sizeof_bool = 1 + const ubyte sizeof_byte = 1 + const ubyte sizeof_ubyte = 1 + const ubyte sizeof_word = 2 + const ubyte sizeof_uword = 2 + const ubyte sizeof_float = 0 ; undefined, no floats supported + + asmsub init_system() { ; Initializes the machine to a sane starting state. ; Called automatically by the loader program logic. @@ -35,6 +43,22 @@ sys { }} } +asmsub cleanup_at_exit() { + ; executed when the main subroutine does rts + %asm {{ +_exitcodeCarry = *+1 + lda #0 + lsr a +_exitcode = *+1 + lda #0 ; exit code possibly modified in exit() +_exitcodeX = *+1 + ldx #0 +_exitcodeY = *+1 + ldy #0 + rts + }} +} + asmsub reset_system() { ; Soft-reset the system back to initial power-on status ; TODO @@ -239,27 +263,38 @@ save_SCRATCH_ZPWORD2 .word 0 asmsub exit(ubyte returnvalue @A) { ; -- immediately exit the program with a return code in the A register - ; TODO where to store A as exit code? %asm {{ + sta cleanup_at_exit._exitcode ldx prog8_lib.orig_stackpointer txs - rts ; return to original caller + jmp cleanup_at_exit }} } asmsub exit2(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y) { ; -- immediately exit the program with result values in the A, X and Y registers. - ; TODO where to store A,X,Y as exit code? %asm {{ - jmp exit + sta cleanup_at_exit._exitcode + stx cleanup_at_exit._exitcodeX + sty cleanup_at_exit._exitcodeY + ldx prog8_lib.orig_stackpointer + txs + jmp cleanup_at_exit }} } asmsub exit3(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y, bool carry @Pc) { ; -- immediately exit the program with result values in the A, X and Y registers, and the Carry flag in the status register. - ; TODO where to store A,X,Y,Carry as exit code? %asm {{ - jmp exit + sta cleanup_at_exit._exitcode + lda #0 + rol a + sta cleanup_at_exit._exitcodeCarry + stx cleanup_at_exit._exitcodeX + sty cleanup_at_exit._exitcodeY + ldx prog8_lib.orig_stackpointer + txs + jmp cleanup_at_exit }} }