mirror of
https://github.com/irmen/prog8.git
synced 2025-03-13 05:31:01 +00:00
library now includes the 2 byte PRG header
fixed some assorted things
This commit is contained in:
parent
2478aea316
commit
bb75be0b44
@ -59,7 +59,7 @@ internal class AssemblyProgram(
|
||||
binFile
|
||||
}
|
||||
OutputType.LIBRARY -> {
|
||||
command.add("--nostart")
|
||||
command.add("--cbm-prg") // include the 2-byte PRG header on library .bins, so they can be easily loaded on the correct memory address even on C64
|
||||
println("\nCreating binary library file for target ${compTarget.name}.")
|
||||
binFile
|
||||
}
|
||||
|
@ -91,7 +91,10 @@ internal class ProgramAndVarsGen(
|
||||
|
||||
asmgen.out("; ---- library assembler program ----")
|
||||
asmgen.out("* = ${options.loadAddress.toHex()}")
|
||||
asmgen.out(" jmp p8b_main.p8s_start") // TODO still needed otherwise 64tass removes all .procs
|
||||
asmgen.out(" jmp p8b_main.p8s_start")
|
||||
// note: the jmp above has 2 effects:
|
||||
// 1. it prevents 64tass from stripping away all procs as unused code
|
||||
// 2. it functions as the first entrypoint of the library, required anyway, to run the variable initialization/bss clear bootstrap code.
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -19,7 +19,7 @@ import prog8.optimizer.*
|
||||
import prog8.parser.ParseError
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.isReadable
|
||||
import kotlin.io.path.isRegularFile
|
||||
import kotlin.io.path.nameWithoutExtension
|
||||
import kotlin.math.round
|
||||
import kotlin.system.exitProcess
|
||||
@ -65,7 +65,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
|
||||
var importedFiles: List<Path>
|
||||
|
||||
val targetConfigFile = expandTilde(Path(args.compilationTarget))
|
||||
val compTarget = if(targetConfigFile.isReadable()) {
|
||||
val compTarget = if(targetConfigFile.isRegularFile()) {
|
||||
ConfigFileTarget.fromConfigFile(targetConfigFile)
|
||||
} else {
|
||||
getCompilationTargetByName(args.compilationTarget)
|
||||
|
@ -1563,7 +1563,7 @@ internal class AstChecker(private val program: Program,
|
||||
if(target.returntypes.size>16) {
|
||||
errors.err("cannot have more than 16 return values", target.position)
|
||||
}
|
||||
if(target.returntypes.size>3) {
|
||||
if(!target.isAsmSubroutine && target.returntypes.size>3) {
|
||||
errors.info("a large number of return values incurs a substantial value copying overhead", target.position)
|
||||
}
|
||||
}
|
||||
|
@ -171,15 +171,17 @@ internal fun Program.moveMainBlockAsFirst(target: ICompilationTarget) {
|
||||
// the program startup and cleanup machinery needs to be located in system ram
|
||||
// so in an attempt to not be pushed into ROM space at the end of the program,
|
||||
// this moves that block to the beginning of the program as much as possible.
|
||||
val startupBlock = this.allBlocks.single { it.name == "p8_sys_startup" }
|
||||
val mainBlockIdx = module.statements.indexOf(block)
|
||||
(startupBlock.parent as IStatementContainer).remove(startupBlock)
|
||||
if (block.address == null) {
|
||||
module.statements.add(mainBlockIdx, startupBlock)
|
||||
} else {
|
||||
module.statements.add(mainBlockIdx + 1, startupBlock)
|
||||
val startupBlock = this.allBlocks.singleOrNull { it.name == "p8_sys_startup" }
|
||||
if(startupBlock!=null) {
|
||||
val mainBlockIdx = module.statements.indexOf(block)
|
||||
(startupBlock.parent as IStatementContainer).remove(startupBlock)
|
||||
if (block.address == null) {
|
||||
module.statements.add(mainBlockIdx, startupBlock)
|
||||
} else {
|
||||
module.statements.add(mainBlockIdx + 1, startupBlock)
|
||||
}
|
||||
startupBlock.parent = module
|
||||
}
|
||||
startupBlock.parent = module
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,35 @@
|
||||
|
||||
|
||||
main {
|
||||
; Create a jump table as first thing in the library.
|
||||
uword[] @shared @nosplit jumptable = [
|
||||
; NOTE: the compiler has inserted a single JMP instruction at the start of the 'main' block, that jumps to the start() routine.
|
||||
; This is convenient because the rest of the jump table simply follows it,
|
||||
; making the first jump neatly be the required initialization routine for the library (initializing variables and BSS region).
|
||||
; btw, $4c = opcode for JMP.
|
||||
$4c00, &library.func1,
|
||||
$4c00, &library.func2,
|
||||
$4c00, &library.func3,
|
||||
]
|
||||
|
||||
sub start() {
|
||||
txt.print("hello from library\n")
|
||||
; has to be here for initialization
|
||||
txt.print("lib initialized\n")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
library {
|
||||
sub func1() {
|
||||
txt.print("lib func 1\n")
|
||||
}
|
||||
|
||||
sub func2() {
|
||||
txt.print("lib func 2\n")
|
||||
}
|
||||
|
||||
sub func3() {
|
||||
txt.print("lib func 3\n")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user