From d9eccd4fbad519f1f202c60ba3e40eed6a0b4473 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 5 Apr 2021 23:21:07 +0200 Subject: [PATCH] set correct rom banks when using floats --- compiler/src/prog8/compiler/astprocessing/AstChecker.kt | 6 ++++++ .../src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt | 6 +++++- docs/source/todo.rst | 2 -- examples/test.p8 | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 029b3f1bb..b481d58e9 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -9,6 +9,7 @@ import prog8.ast.statements.* import prog8.ast.walk.IAstVisitor import prog8.compiler.CompilationOptions import prog8.compiler.IErrorReporter +import prog8.compiler.ZeropageType import prog8.compiler.functions.BuiltinFunctions import prog8.compiler.functions.builtinFunctionReturnType import prog8.compiler.target.C64Target @@ -41,6 +42,11 @@ internal class AstChecker(private val program: Program, } } + if(compilerOptions.floats) { + if (compilerOptions.zeropage !in setOf(ZeropageType.FLOATSAFE, ZeropageType.BASICSAFE, ZeropageType.DONTUSE )) + errors.err("when floats are enabled, zero page type should be 'floatsafe' or 'basicsafe' or 'dontuse'", program.mainModule.position) + } + super.visit(program) } diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index f84178bd5..149fd2af2 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -159,7 +159,11 @@ internal class AsmGen(private val program: Program, // make sure that on the cx16 and c64, basic rom is banked in again when we exit the program when(compTarget.name) { - Cx16Target.name -> out(" jsr main.start | lda #4 | sta $01 | rts") + Cx16Target.name -> { + if(options.floats) + out(" lda #4 | sta $01") // to use floats, make sure Basic rom is banked in + out(" jsr main.start | lda #4 | sta $01 | rts") + } C64Target.name -> out(" jsr main.start | lda #31 | sta $01 | rts") else -> jmp("main.start") } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 15ede19d3..8abbb2f05 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,8 +2,6 @@ TODO ==== -- make the floats lib set rombank 4 on cx16 and set sysinit back to rombank 0 (kernal only) -- make sure rombank is back to 4 on cx16 when program exits back to basic - check use of float NEGOP vs NEGFAC for cx16 - allow inlining of subroutines with params diff --git a/examples/test.p8 b/examples/test.p8 index fdaca91db..3996a203c 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,6 +1,6 @@ %import textio %import floats -%zeropage basicsafe +%zeropage floatsafe main { @@ -21,7 +21,7 @@ main { f3 = cos(f3) floats.print_f(f3) - cx16.rombank(0) + ;cx16.rombank(0) txt.print("ok!\n")