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 asmListfile: Boolean = false,
var experimentalCodegen: Boolean = false,
var varsHigh: Boolean = false,
var varsHighBank: Int? = null,
var useNewExprCode: Boolean = false,
var splitWordArrays: Boolean = false,
var evalStackBaseAddress: UInt? = null,

View File

@ -175,7 +175,8 @@ internal class ProgramAndVarsGen(
private fun footer() {
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) {
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
jsr cbm.CHROUT
lda #1
sta $00 ; select ram bank 1
jsr cbm.CHROUT ; swap fg/bg
lda #$9e ; yellow
jsr cbm.CHROUT
lda #147 ; clear screen
jsr cbm.CHROUT
lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank
lda #0
tax
tay
@ -762,6 +763,8 @@ asmsub init_system_phase2() {
sta restore_irq._orig_irqvec
lda cx16.CINV+1
sta restore_irq._orig_irqvec+1
lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank
cli
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 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 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 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)
@ -84,6 +84,11 @@ private fun compileMain(args: Array<String>): Boolean {
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) {
return runVm(moduleFiles.first())
}
@ -127,7 +132,7 @@ private fun compileMain(args: Array<String>): Boolean {
quietAssembler == true,
asmListfile == true,
experimentalCodegen == true,
varsHigh == true,
varsHighBank,
useNewExprCode == true,
compilationTarget,
evalStackAddr,
@ -180,6 +185,10 @@ private fun compileMain(args: Array<String>): Boolean {
}
} 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) {
val filepath = pathFrom(filepathRaw).normalize()
val compilationResult: CompilationResult
@ -193,7 +202,7 @@ private fun compileMain(args: Array<String>): Boolean {
quietAssembler == true,
asmListfile == true,
experimentalCodegen == true,
varsHigh == true,
varsHighBank,
useNewExprCode == true,
compilationTarget,
evalStackAddr,

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ internal fun compileFile(
quietAssembler = true,
asmListfile = false,
experimentalCodegen = false,
varsHigh = false,
varsHighBank = null,
useNewExprCode = useNewExprCode,
platform.name,
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
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.
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,
but can be several hundreds of bytes or more.
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
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
====
- 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?
...

View File

@ -1,14 +1,28 @@
%zeropage basicsafe
%import textio
%option no_sysinit
%zeropage dontuse
main {
sub start() {
if foobar1 {
cx16.r0++
}
uword variable=55555
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,
experimentalCodegen = false,
splitWordArrays = false,
varsHigh = false,
varsHighBank = null,
useNewExprCode = false
)
val compilationResult = compileProgram(args)