diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt index e1c7fca6a..f06b82f64 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt @@ -89,6 +89,12 @@ internal class ProgramAndVarsGen( OutputType.RAW -> { asmgen.out("; ---- raw assembler program ----") asmgen.out("* = ${options.loadAddress.toHex()}") + asmgen.out(" cld") + asmgen.out(" tsx ; save stackpointer for sys.exit()") + asmgen.out(" stx prog8_lib.orig_stackpointer") + if(!options.noSysInit) + asmgen.out(" jsr sys.init_system") + asmgen.out(" jsr sys.init_system_phase2") } OutputType.PRG -> { when(options.launcher) { @@ -111,6 +117,7 @@ internal class ProgramAndVarsGen( asmgen.out(" jsr sys.init_system_phase2") } CbmPrgLauncherType.NONE -> { + // this is the same as RAW asmgen.out("; ---- program without basic sys call ----") asmgen.out("* = ${options.loadAddress.toHex()}") asmgen.out(" cld") @@ -575,7 +582,7 @@ internal class ProgramAndVarsGen( asmgen.out("") val (varsNoInit, varsWithInit) = variables.partition { it.uninitialized } if(varsNoInit.isNotEmpty()) { - asmgen.out("; non-zeropage variables without initialization value") + asmgen.out("; non-zeropage variables") asmgen.out(" .section BSS") varsNoInit.sortedWith(compareBy { it.name }.thenBy { it.dt }).forEach { uninitializedVariable2asm(it) @@ -584,7 +591,7 @@ internal class ProgramAndVarsGen( } if(varsWithInit.isNotEmpty()) { - asmgen.out("; non-zeropage variables") + asmgen.out("; non-zeropage variables with init value") val (stringvars, othervars) = varsWithInit.sortedBy { it.name }.partition { it.dt == DataType.STR } stringvars.forEach { outputStringvar( diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 6dee64380..68c3bfea5 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -248,7 +248,7 @@ internal fun determineProgramLoadAddress(program: Program, options: CompilationO } if(loadAddress==null) { - errors.err("load address must be specified with these output options", program.toplevelModule.position) + errors.err("load address must be specified with the specifid output/launcher options", program.toplevelModule.position) return } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index c87475527..489f1f809 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -Shouldn't RAW output target have some initialization logic too? Does it even clear the variables/bss etc? - Doc improvements: some short overview for people coming from other programming languages like C: tell something about prog8 not having function overloading, max 16 bit (u)word integer as native type (and floats sometimes), static variable allocations, no dynamic memory allocation in the language itself (although possible via user written libraries), diff --git a/examples/test.p8 b/examples/test.p8 index 003fd4623..3bc1d1d0a 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,6 +1,9 @@ %import textio %zeropage dontuse -%option no_sysinit + +%output raw +%launcher none +%address $2000 main { uword @shared variable