RAW output now also properly initializes variables

This commit is contained in:
Irmen de Jong 2024-09-27 18:46:03 +02:00
parent 04cb684fd4
commit 3f630ab1b0
4 changed files with 14 additions and 6 deletions

View File

@ -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<StStaticVariable> { 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(

View File

@ -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
}

View File

@ -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),

View File

@ -1,6 +1,9 @@
%import textio
%zeropage dontuse
%option no_sysinit
%output raw
%launcher none
%address $2000
main {
uword @shared variable