diff --git a/compiler/res/prog8lib/c64lib.p8 b/compiler/res/prog8lib/c64lib.p8 index 5f3a6611c..ac81b1eb5 100644 --- a/compiler/res/prog8lib/c64lib.p8 +++ b/compiler/res/prog8lib/c64lib.p8 @@ -231,4 +231,36 @@ romsub $FFF3 = IOBASE() -> uword @ XY ; read base addr ; ---- end of C64 kernal routines ---- +asmsub init_system() { + ; Initializes the machine to a sane starting state. + ; Called automatically by the loader program logic. + ; This means that the BASIC, KERNAL and CHARGEN ROMs are banked in, + ; the VIC, SID and CIA chips are reset, screen is cleared, and the default IRQ is set. + ; Also a different color scheme is chosen to identify ourselves a little. + ; Uppercase charset is activated, and all three registers set to 0, status flags cleared. + %asm {{ + sei + cld + lda #%00101111 + sta $00 + lda #%00100111 + sta $01 + jsr c64.IOINIT + jsr c64.RESTOR + jsr c64.CINT + lda #6 + sta c64.EXTCOL + lda #7 + sta c64.COLOR + lda #0 + sta c64.BGCOL0 + tax + tay + clc + clv + cli + rts + }} +} + } diff --git a/compiler/res/prog8lib/prog8lib.asm b/compiler/res/prog8lib/prog8lib.asm index f281756ab..24a53e546 100644 --- a/compiler/res/prog8lib/prog8lib.asm +++ b/compiler/res/prog8lib/prog8lib.asm @@ -6,38 +6,6 @@ ; indent format: TABS, size=8 -; TODO move this one to c64lib: -init_system .proc - ; -- initializes the machine to a sane starting state - ; Called automatically by the loader program logic. - ; This means that the BASIC, KERNAL and CHARGEN ROMs are banked in, - ; the VIC, SID and CIA chips are reset, screen is cleared, and the default IRQ is set. - ; Also a different color scheme is chosen to identify ourselves a little. - ; Uppercase charset is activated, and all three registers set to 0, status flags cleared. - sei - cld - lda #%00101111 - sta $00 - lda #%00100111 - sta $01 - jsr c64.IOINIT - jsr c64.RESTOR - jsr c64.CINT - lda #6 - sta c64.EXTCOL - lda #7 - sta c64.COLOR - lda #0 - sta c64.BGCOL0 - tax - tay - clc - clv - cli - rts - .pend - - read_byte_from_address_on_stack .proc ; -- read the byte from the memory address on the top of the stack, return in A (stack remains unchanged) lda P8ESTACK_LO+1,x diff --git a/compiler/src/prog8/compiler/target/IMachineDefinition.kt b/compiler/src/prog8/compiler/target/IMachineDefinition.kt index edb4b61c4..29f76eeaa 100644 --- a/compiler/src/prog8/compiler/target/IMachineDefinition.kt +++ b/compiler/src/prog8/compiler/target/IMachineDefinition.kt @@ -21,6 +21,7 @@ interface IMachineDefinition { val opcodeNames: Set var zeropage: Zeropage + val initSystemProcname: String fun initializeZeropage(compilerOptions: CompilationOptions) fun getFloat(num: Number): IMachineFloat diff --git a/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt b/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt index 14841b49b..790dbcdbb 100644 --- a/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt +++ b/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt @@ -26,6 +26,8 @@ internal object C64MachineDefinition: IMachineDefinition { override val ESTACK_HI = 0xcf00 // $ce00-$ceff inclusive override lateinit var zeropage: Zeropage + override val initSystemProcname = "c64.init_system" + override fun getFloat(num: Number) = Mflpt5.fromNumber(num) override fun getFloatRomConst(number: Double): String? { diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index b6b2ac8cd..32e938967 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -12,7 +12,6 @@ import prog8.compiler.target.CompilationTarget import prog8.compiler.target.IAssemblyGenerator import prog8.compiler.target.IAssemblyProgram import prog8.compiler.target.c64.AssemblyProgram -import prog8.compiler.target.c64.C64MachineDefinition import prog8.compiler.target.c64.Petscii import prog8.compiler.target.c64.codegen.assignment.AsmAssignSource import prog8.compiler.target.c64.codegen.assignment.AsmAssignTarget @@ -22,7 +21,6 @@ import prog8.compiler.target.c64.codegen.assignment.TargetStorageKind import prog8.compiler.target.generatedLabelPrefix import prog8.functions.BuiltinFunctions import prog8.functions.FSignature -import java.math.RoundingMode import java.nio.file.Path import java.time.LocalDate import java.time.LocalDateTime @@ -93,6 +91,7 @@ internal class AsmGen(private val program: Program, // the global prog8 variables needed val zp = CompilationTarget.machine.zeropage + val initproc = CompilationTarget.machine.initSystemProcname out("P8ZP_SCRATCH_B1 = ${zp.SCRATCH_B1}") out("P8ZP_SCRATCH_REG = ${zp.SCRATCH_REG}") out("P8ZP_SCRATCH_REG_X = ${zp.SCRATCH_REG_X}") @@ -114,14 +113,16 @@ internal class AsmGen(private val program: Program, out("_prog8_entrypoint\t; assembly code starts here\n") out(" tsx") out(" stx prog8_lib.orig_stackpointer") - out(" jsr prog8_lib.init_system") + if(!initproc.isNullOrEmpty()) + out(" jsr $initproc") } options.output == OutputType.PRG -> { out("; ---- program without basic sys call ----") out("* = ${program.actualLoadAddress.toHex()}\n") out(" tsx") out(" stx prog8_lib.orig_stackpointer") - out(" jsr prog8_lib.init_system") + if(!initproc.isNullOrEmpty()) + out(" jsr $initproc") } options.output == OutputType.RAW -> { out("; ---- raw assembler program ----") diff --git a/compiler/src/prog8/optimizer/CallGraph.kt b/compiler/src/prog8/optimizer/CallGraph.kt index 16253963f..6e7e36c2b 100644 --- a/compiler/src/prog8/optimizer/CallGraph.kt +++ b/compiler/src/prog8/optimizer/CallGraph.kt @@ -14,8 +14,7 @@ import prog8.compiler.loadAsmIncludeFile private val alwaysKeepSubroutines = setOf( Pair("main", "start"), - Pair("irq", "irq"), - Pair("prog8_lib", "init_system") + Pair("irq", "irq") ) private val asmJumpRx = Regex("""[\-+a-zA-Z0-9_ \t]+(jmp|jsr)[ \t]+(\S+).*""", RegexOption.IGNORE_CASE)