added hiram bank number to -varshigh

This commit is contained in:
Irmen de Jong 2023-06-27 00:27:34 +02:00
parent 5b9e71a27d
commit b0794cf35e
12 changed files with 48 additions and 22 deletions

View File

@ -19,7 +19,7 @@ class CompilationOptions(val output: OutputType,
var asmQuiet: Boolean = false, var asmQuiet: Boolean = false,
var asmListfile: Boolean = false, var asmListfile: Boolean = false,
var experimentalCodegen: Boolean = false, var experimentalCodegen: Boolean = false,
var varsHigh: Boolean = false, var varsHighBank: Int? = null,
var useNewExprCode: Boolean = false, var useNewExprCode: Boolean = false,
var splitWordArrays: Boolean = false, var splitWordArrays: Boolean = false,
var evalStackBaseAddress: UInt? = null, var evalStackBaseAddress: UInt? = null,

View File

@ -175,7 +175,8 @@ internal class ProgramAndVarsGen(
private fun footer() { private fun footer() {
asmgen.out("; bss sections") asmgen.out("; bss sections")
if(options.varsHigh) { asmgen.out("PROG8_VARSHIGH_RAMBANK = ${options.varsHighBank ?: 1}")
if(options.varsHighBank!=null) {
if(options.compTarget.machine.BSSHIGHRAM_START == 0u || options.compTarget.machine.BSSHIGHRAM_END==0u) { if(options.compTarget.machine.BSSHIGHRAM_START == 0u || options.compTarget.machine.BSSHIGHRAM_END==0u) {
throw AssemblyError("current compilation target hasn't got the high ram area properly defined") throw AssemblyError("current compilation target hasn't got the high ram area properly defined")
} }

View File

@ -739,12 +739,13 @@ asmsub init_system() {
lda #$90 ; black lda #$90 ; black
jsr cbm.CHROUT jsr cbm.CHROUT
lda #1 lda #1
sta $00 ; select ram bank 1
jsr cbm.CHROUT ; swap fg/bg jsr cbm.CHROUT ; swap fg/bg
lda #$9e ; yellow lda #$9e ; yellow
jsr cbm.CHROUT jsr cbm.CHROUT
lda #147 ; clear screen lda #147 ; clear screen
jsr cbm.CHROUT jsr cbm.CHROUT
lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank
lda #0 lda #0
tax tax
tay tay
@ -762,6 +763,8 @@ asmsub init_system_phase2() {
sta restore_irq._orig_irqvec sta restore_irq._orig_irqvec
lda cx16.CINV+1 lda cx16.CINV+1
sta restore_irq._orig_irqvec+1 sta restore_irq._orig_irqvec+1
lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank
cli cli
rts rts
}} }}

View File

@ -51,7 +51,7 @@ private fun compileMain(args: Array<String>): Boolean {
val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler (one of '${C64Target.NAME}', '${C128Target.NAME}', '${Cx16Target.NAME}', '${AtariTarget.NAME}', '${VMTarget.NAME}')").required() val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler (one of '${C64Target.NAME}', '${C128Target.NAME}', '${Cx16Target.NAME}', '${AtariTarget.NAME}', '${VMTarget.NAME}')").required()
val startVm by cli.option(ArgType.Boolean, fullName = "vm", description = "load and run a .p8ir IR source file in the VM") val startVm by cli.option(ArgType.Boolean, fullName = "vm", description = "load and run a .p8ir IR source file in the VM")
val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watch for file changes)") val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watch for file changes)")
val varsHigh by cli.option(ArgType.Boolean, fullName = "varshigh", description = "put uninitialized variables in high memory area instead of at the end of the program") val varsHighBank by cli.option(ArgType.Int, fullName = "varshigh", description = "put uninitialized variables in high memory area instead of at the end of the program. On the cx16 target the value specifies the HiRAM bank (0=keep active), on other systems it is ignored.")
val useNewExprCode by cli.option(ArgType.Boolean, fullName = "newexpr", description = "use new expression code-gen (experimental)") val useNewExprCode by cli.option(ArgType.Boolean, fullName = "newexpr", description = "use new expression code-gen (experimental)")
val splitWordArrays by cli.option(ArgType.Boolean, fullName = "splitarrays", description = "treat all word arrays as tagged with @split to make them lsb/msb split in memory") val splitWordArrays by cli.option(ArgType.Boolean, fullName = "splitarrays", description = "treat all word arrays as tagged with @split to make them lsb/msb split in memory")
val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999) val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999)
@ -84,6 +84,11 @@ private fun compileMain(args: Array<String>): Boolean {
return false return false
} }
if(varsHighBank==0 && compilationTarget==Cx16Target.NAME) {
System.err.println("On the Commander X16, HiRAM bank 0 is used by the kernal and can't be used.")
return false
}
if(startVm==true) { if(startVm==true) {
return runVm(moduleFiles.first()) return runVm(moduleFiles.first())
} }
@ -127,7 +132,7 @@ private fun compileMain(args: Array<String>): Boolean {
quietAssembler == true, quietAssembler == true,
asmListfile == true, asmListfile == true,
experimentalCodegen == true, experimentalCodegen == true,
varsHigh == true, varsHighBank,
useNewExprCode == true, useNewExprCode == true,
compilationTarget, compilationTarget,
evalStackAddr, evalStackAddr,
@ -180,6 +185,10 @@ private fun compileMain(args: Array<String>): Boolean {
} }
} else { } else {
if((startEmulator1==true || startEmulator2==true) && moduleFiles.size>1) {
System.err.println("can't start emulator when multiple module files are specified")
return false
}
for(filepathRaw in moduleFiles) { for(filepathRaw in moduleFiles) {
val filepath = pathFrom(filepathRaw).normalize() val filepath = pathFrom(filepathRaw).normalize()
val compilationResult: CompilationResult val compilationResult: CompilationResult
@ -193,7 +202,7 @@ private fun compileMain(args: Array<String>): Boolean {
quietAssembler == true, quietAssembler == true,
asmListfile == true, asmListfile == true,
experimentalCodegen == true, experimentalCodegen == true,
varsHigh == true, varsHighBank,
useNewExprCode == true, useNewExprCode == true,
compilationTarget, compilationTarget,
evalStackAddr, evalStackAddr,

View File

@ -36,7 +36,7 @@ class CompilerArguments(val filepath: Path,
val quietAssembler: Boolean, val quietAssembler: Boolean,
val asmListfile: Boolean, val asmListfile: Boolean,
val experimentalCodegen: Boolean, val experimentalCodegen: Boolean,
val varsHigh: Boolean, val varsHighBank: Int?,
val useNewExprCode: Boolean, val useNewExprCode: Boolean,
val compilationTarget: String, val compilationTarget: String,
val evalStackBaseAddress: UInt?, val evalStackBaseAddress: UInt?,
@ -78,7 +78,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
asmQuiet = args.quietAssembler asmQuiet = args.quietAssembler
asmListfile = args.asmListfile asmListfile = args.asmListfile
experimentalCodegen = args.experimentalCodegen experimentalCodegen = args.experimentalCodegen
varsHigh = args.varsHigh varsHighBank = args.varsHighBank
useNewExprCode = args.useNewExprCode useNewExprCode = args.useNewExprCode
evalStackBaseAddress = args.evalStackBaseAddress evalStackBaseAddress = args.evalStackBaseAddress
splitWordArrays = args.splitWordArrays splitWordArrays = args.splitWordArrays

View File

@ -32,7 +32,7 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat
quietAssembler = true, quietAssembler = true,
asmListfile = false, asmListfile = false,
experimentalCodegen = false, experimentalCodegen = false,
varsHigh = false, varsHighBank = null,
useNewExprCode = false, useNewExprCode = false,
compilationTarget = target.name, compilationTarget = target.name,
evalStackBaseAddress = null, evalStackBaseAddress = null,

View File

@ -49,7 +49,7 @@ class TestCompilerOptionSourcedirs: FunSpec({
quietAssembler = true, quietAssembler = true,
asmListfile = false, asmListfile = false,
experimentalCodegen = false, experimentalCodegen = false,
varsHigh = false, varsHighBank = null,
useNewExprCode = false, useNewExprCode = false,
compilationTarget = Cx16Target.NAME, compilationTarget = Cx16Target.NAME,
evalStackBaseAddress = null, evalStackBaseAddress = null,

View File

@ -31,7 +31,7 @@ internal fun compileFile(
quietAssembler = true, quietAssembler = true,
asmListfile = false, asmListfile = false,
experimentalCodegen = false, experimentalCodegen = false,
varsHigh = false, varsHighBank = null,
useNewExprCode = useNewExprCode, useNewExprCode = useNewExprCode,
platform.name, platform.name,
evalStackBaseAddress = null, evalStackBaseAddress = null,

View File

@ -180,16 +180,16 @@ One or more .p8 module files
When not compiling for the Commander X16 target, the location of the 16 virtual registers cx16.r0..r15 When not compiling for the Commander X16 target, the location of the 16 virtual registers cx16.r0..r15
is changed accordingly (to keep them in the same memory space as the evaluation stack). is changed accordingly (to keep them in the same memory space as the evaluation stack).
``-varshigh`` ``-varshigh <rambank>``
Places the non-zeropage variables in a separate high memory area, instead of inside the program itself. Places the non-zeropage variables in a separate high memory area, instead of inside the program itself.
This results in an increase of the amount of system ram available for the program This results in an increase of the amount of system ram available for the program
itself. The amount of ram saved depends on the amount and types of variables in the program, itself. The amount of ram saved depends on the amount and types of variables in the program,
but can be several hundreds of bytes or more. but can be several hundreds of bytes or more.
The new memory location of the variables depends on the compilation target machine: The new memory location of the variables depends on the compilation target machine:
c64: $C000 - $CEFF c64: $C000 - $CEFF (specified rambank number is ignored)
cx16: $A000 - $BFFF (note: you must make sure that the correct HiRam bank #1 is mapped in when accessing these variables!) cx16: $A000 - $BFFF in the given HiRAM bank (note: you must make sure that this HiRAM bank is mapped in when accessing variables! The bank should be 1 or up. Choose 1 if unsure.)
If you use this option, you can no longer use the part of the above memory area that is If you use this option, you can no longer use the part of the above memory area that is
now alotted to the variables for your own purposes. The output of the 64tass assembler step at the now alotted to the variables for your own purposes. The output of the 64tass assembler step at the

View File

@ -1,7 +1,6 @@
TODO TODO
==== ====
- hiram bank 1 usage configurable or maybe even just keep whatever bank is active at program start?
- is it possible to allow the curly brace to be on the next line instead of requiring it to follow on the same line? - is it possible to allow the curly brace to be on the next line instead of requiring it to follow on the same line?
... ...

View File

@ -1,14 +1,28 @@
%zeropage basicsafe %import textio
%option no_sysinit %option no_sysinit
%zeropage dontuse
main { main {
sub start() { uword variable=55555
if foobar1 {
cx16.r0++
}
sys.exit(foobar3) sub start() {
txt.print("active rambank=")
txt.print_ub(cx16.getrambank())
txt.print("\nvar addr=")
txt.print_uwhex(&variable, true)
txt.print("\nvalue=")
txt.print_uw(variable)
txt.print("\n(rambank 10) variable=")
cx16.rambank(10)
txt.print_uw(variable)
txt.print("\n(rambank 2) variable=")
cx16.rambank(2)
txt.print_uw(variable)
txt.print("\n(rambank 1) variable=")
cx16.rambank(1)
txt.print_uw(variable)
txt.nl()
} }
} }

View File

@ -43,7 +43,7 @@ class RequestParser : Take {
asmListfile = false, asmListfile = false,
experimentalCodegen = false, experimentalCodegen = false,
splitWordArrays = false, splitWordArrays = false,
varsHigh = false, varsHighBank = null,
useNewExprCode = false useNewExprCode = false
) )
val compilationResult = compileProgram(args) val compilationResult = compileProgram(args)