Skip to content

Commit

Permalink
fix Golden ram issues
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Feb 9, 2025
1 parent efd4126 commit 0691430
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions codeCore/src/prog8/code/target/C64Target.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by No

override val BSSHIGHRAM_START = 0xc000u
override val BSSHIGHRAM_END = 0xcfdfu
override val BSSGOLDENRAM_START = 0u
override val BSSGOLDENRAM_START = 0u // no golden ram on C64
override val BSSGOLDENRAM_END = 0u

override lateinit var zeropage: Zeropage
Expand Down Expand Up @@ -80,7 +80,7 @@ class C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by No

override fun initializeMemoryAreas(compilerOptions: CompilationOptions) {
zeropage = C64Zeropage(compilerOptions)
golden = GoldenRam(compilerOptions, 0xc000u until 0xd000u)
golden = GoldenRam(compilerOptions, UIntRange.EMPTY)
}

}
Expand Down
2 changes: 1 addition & 1 deletion codeCore/src/prog8/code/target/Cx16Target.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Cx16Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by N

override fun initializeMemoryAreas(compilerOptions: CompilationOptions) {
zeropage = CX16Zeropage(compilerOptions)
golden = GoldenRam(compilerOptions, 0x0400u until 0x0800u)
golden = GoldenRam(compilerOptions, BSSGOLDENRAM_START..BSSGOLDENRAM_END)
}


Expand Down
2 changes: 1 addition & 1 deletion codeCore/src/prog8/code/target/PETTarget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PETTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by No

override fun initializeMemoryAreas(compilerOptions: CompilationOptions) {
zeropage = PETZeropage(compilerOptions)
// there's no golden ram.
golden = GoldenRam(compilerOptions, UIntRange.EMPTY)
}

}
1 change: 1 addition & 0 deletions codeCore/src/prog8/code/target/VMTarget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class VMTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by Nor

override fun initializeMemoryAreas(compilerOptions: CompilationOptions) {
zeropage = VirtualZeropage(compilerOptions)
golden = GoldenRam(compilerOptions, UIntRange.EMPTY)
}

override fun memorySize(dt: DataType, numElements: Int?): Int {
Expand Down
8 changes: 0 additions & 8 deletions compiler/src/prog8/CompilerMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,12 @@ private fun compileMain(args: Array<String>): Boolean {
}

if (varsGolden==true) {
if (compilationTarget != Cx16Target.NAME) {
System.err.println("Golden Ram is only available on the Commander X16 target.")
return false
}
if (varsHighBank!=null || slabsHighBank!=null) {
System.err.println("Either use varsgolden or varshigh (and slabsgolden or slabshigh), not both or mixed.")
return false
}
}
if (slabsGolden==true) {
if (compilationTarget != Cx16Target.NAME) {
System.err.println("Golden Ram is only available on the Commander X16 target.")
return false
}
if (varsHighBank!=null || slabsHighBank!=null) {
System.err.println("Either use golden or high ram, not both.")
return false
Expand Down
7 changes: 7 additions & 0 deletions compiler/src/prog8/compiler/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
getCompilationTargetByName(args.compilationTarget)
}

if(args.varsGolden || args.slabsGolden) {
if(compTarget.BSSGOLDENRAM_END-compTarget.BSSGOLDENRAM_START==0u) {
System.err.println("The current compilation target doesn't support Golden Ram.")
return null
}
}

try {
val totalTime = measureTimeMillis {
val libraryDirs = if(compTarget.libraryPath!=null) listOf(compTarget.libraryPath.toString()) else emptyList()
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/prog8/compiler/astprocessing/AstChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,8 @@ internal class AstChecker(private val program: Program,
err("invalid encoding directive, expected one of $allowedEncodings")
}
"%jmptable" -> {
if(directive.parent !is Block)
err("this directive may only occur in a block")
for(arg in directive.args) {
val target = directive.definingScope.lookup(arg.string!!.split('.'))
if(target==null)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ One or more .p8 module files
``-varsgolden``
Like ``-varshigh``, but places the variables in the $0400-$07FF "golden ram" area instead.
Because this is in normal system memory, there are no bank switching issues.
This mode is only available on the Commander X16.
This mode is only available on the Commander X16, and possibly on custom configured targets.

``-varshigh <rambank>``
Places uninitialized non-zeropage variables in a separate memory area, instead of inside the program itself.
Expand Down
8 changes: 8 additions & 0 deletions docs/source/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ Directives
jmp lib.routine2
...

This is usually put at the top of the main block so that it ends up at the beginning
of the library file. *Note:* the compiler may still insert the required bootstrapping
code in front of it, which in the case of a library, is the JMP to the start routine
which also does some variable initialization and BSS area clearing. So the first JMP
in the jumptable will then end up at offset 3 in the resulting binary. You could consider
the JMP start that prog8 inserts as the implicit first entry of the jump table.
Check the generated assembly code to see exactly what's up.

.. data:: %launcher <type>

Level: module.
Expand Down

0 comments on commit 0691430

Please sign in to comment.