mirror of
https://github.com/irmen/prog8.git
synced 2026-04-21 17:16:33 +00:00
added ability to configure custom ASM launcher code in target configuration file
This commit is contained in:
@@ -34,6 +34,7 @@ interface ICompilationTarget: IStringEncoding, IMemSizer {
|
||||
var zeropage: Zeropage
|
||||
var golden: GoldenRam
|
||||
val libraryPath: Path?
|
||||
val customLauncher: List<String>?
|
||||
|
||||
fun initializeMemoryAreas(compilerOptions: CompilationOptions)
|
||||
fun getFloatAsmBytes(num: Number): String
|
||||
|
||||
@@ -11,6 +11,7 @@ class AtariTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by
|
||||
override val name = NAME
|
||||
override val defaultEncoding = Encoding.ATASCII
|
||||
override val libraryPath = null
|
||||
override val customLauncher = null
|
||||
|
||||
companion object {
|
||||
const val NAME = "atari"
|
||||
|
||||
@@ -18,6 +18,7 @@ class C128Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by N
|
||||
override val name = NAME
|
||||
override val defaultEncoding = Encoding.PETSCII
|
||||
override val libraryPath = null
|
||||
override val customLauncher = null
|
||||
|
||||
companion object {
|
||||
const val NAME = "c128"
|
||||
|
||||
@@ -11,6 +11,7 @@ class C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by No
|
||||
override val name = NAME
|
||||
override val defaultEncoding = Encoding.PETSCII
|
||||
override val libraryPath = null
|
||||
override val customLauncher = null
|
||||
|
||||
companion object {
|
||||
const val NAME = "c64"
|
||||
|
||||
@@ -26,6 +26,7 @@ class ConfigFileTarget(
|
||||
override val BSSGOLDENRAM_START: UInt,
|
||||
override val BSSGOLDENRAM_END: UInt,
|
||||
override val libraryPath: Path,
|
||||
override val customLauncher: List<String>?,
|
||||
val ioAddresses: List<UIntRange>,
|
||||
val zpScratchB1: UInt,
|
||||
val zpScratchReg: UInt,
|
||||
@@ -101,6 +102,12 @@ class ConfigFileTarget(
|
||||
if(!libraryPath.isDirectory())
|
||||
throw IOException("invalid library path: $libraryPath")
|
||||
|
||||
val customLauncherStr = props.getProperty("custom_launcher", null)
|
||||
val customLauncher =
|
||||
if(customLauncherStr?.isNotBlank()==true)
|
||||
(customLauncherStr+"\n").lines().map { it.trimEnd() }
|
||||
else null
|
||||
|
||||
return ConfigFileTarget(
|
||||
configfile.nameWithoutExtension,
|
||||
Encoding.entries.first { it.prefix==props.getString("encoding") },
|
||||
@@ -114,6 +121,7 @@ class ConfigFileTarget(
|
||||
props.getInteger("bss_goldenram_start"),
|
||||
props.getInteger("bss_goldenram_end"),
|
||||
libraryPath,
|
||||
customLauncher,
|
||||
ioAddresses,
|
||||
props.getInteger("zp_scratch_b1"),
|
||||
props.getInteger("zp_scratch_reg"),
|
||||
|
||||
@@ -18,6 +18,7 @@ class Cx16Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by N
|
||||
override val name = NAME
|
||||
override val defaultEncoding = Encoding.PETSCII
|
||||
override val libraryPath = null
|
||||
override val customLauncher = null
|
||||
|
||||
companion object {
|
||||
const val NAME = "cx16"
|
||||
|
||||
@@ -10,6 +10,7 @@ class Neo6502Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer b
|
||||
override val name = NAME
|
||||
override val defaultEncoding = Encoding.ISO
|
||||
override val libraryPath = null
|
||||
override val customLauncher = null
|
||||
|
||||
companion object {
|
||||
const val NAME = "neo"
|
||||
|
||||
@@ -18,6 +18,7 @@ class PETTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by No
|
||||
override val name = NAME
|
||||
override val defaultEncoding = Encoding.PETSCII
|
||||
override val libraryPath = null
|
||||
override val customLauncher = null
|
||||
|
||||
companion object {
|
||||
const val NAME = "pet32"
|
||||
|
||||
@@ -11,6 +11,7 @@ class VMTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by Nor
|
||||
override val name = NAME
|
||||
override val defaultEncoding = Encoding.ISO
|
||||
override val libraryPath = null
|
||||
override val customLauncher = null
|
||||
|
||||
companion object {
|
||||
const val NAME = "virtual"
|
||||
|
||||
@@ -87,6 +87,16 @@ internal class ProgramAndVarsGen(
|
||||
}
|
||||
}
|
||||
|
||||
if(options.compTarget.customLauncher?.isNotEmpty()==true) {
|
||||
asmgen.out("; ---- custom launcher assembler program ----")
|
||||
asmgen.out("* = ${options.loadAddress.toHex()}")
|
||||
asmgen.out("prog8_program_start\t; start of program label")
|
||||
for(line in options.compTarget.customLauncher) {
|
||||
asmgen.out(line)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if(options.output == OutputType.LIBRARY) {
|
||||
|
||||
asmgen.out("; ---- library assembler program ----")
|
||||
|
||||
@@ -52,6 +52,13 @@ You also need to create some essential ``syslib`` library module for the configu
|
||||
compiler won't have a built in library that can be used this time. The customtarget examples also show how to build
|
||||
the essentials.
|
||||
|
||||
The target configuration file also allows you to override the entire launcher assembly fragment that the compiler
|
||||
usually puts at the start of the program (immediately after the setting of the program counter/load address and
|
||||
the program start label). This allows you to have full control over exactly what code or data bytes appear at
|
||||
the program's load address. But with great power comes great responsibility: you'll have to make sure you take
|
||||
care of some very low level Prog8 internals if you want to support stuff like the `exit` builtin function.
|
||||
Maybe the best thing is to look at the code generated by the compiler for an existing target and adapt that.
|
||||
|
||||
|
||||
Memory Model
|
||||
============
|
||||
|
||||
@@ -33,5 +33,9 @@ virtual_registers = $cfe0
|
||||
# Where can we find the standard library (syslib.p8). You can still add more paths manually using -srcdirs
|
||||
library = ./libraries/tinyc64
|
||||
|
||||
# if a custom launcher string is supplied, the compiler won't output ANY launcher / init code by itself,
|
||||
# and instead outputs whatever is specified here. (You can use \n here for newline and \ for line continuantions)
|
||||
custom_launcher =
|
||||
|
||||
# TODO should the 64tass arguments be in here too perhaps? So that the "program" parameter that now selects 1 of a few fixed sets of arguments, can be removed?
|
||||
# TODO should an emulator command line also be in here perhaps? So that -emu will work too.
|
||||
|
||||
@@ -33,5 +33,9 @@ virtual_registers = $02
|
||||
# Where can we find the standard library (syslib.p8). You can still add more paths manually using -srcdirs
|
||||
library = ./libraries/tinycx16
|
||||
|
||||
# if a custom launcher string is supplied, the compiler won't output ANY launcher / init code by itself,
|
||||
# and instead outputs whatever is specified here. (You can use \n here for newline and \ for line continuantions)
|
||||
custom_launcher =
|
||||
|
||||
# TODO should the 64tass arguments be in here too perhaps? So that the "program" parameter that now selects 1 of a few fixed sets of arguments, can be removed?
|
||||
# TODO should an emulator command line also be in here perhaps? So that -emu will work too.
|
||||
|
||||
@@ -33,5 +33,9 @@ virtual_registers = $7fe0
|
||||
# Where can we find the standard library (syslib.p8). You can still add more paths manually using -srcdirs
|
||||
library = ./libraries/tinypet
|
||||
|
||||
# if a custom launcher string is supplied, the compiler won't output ANY launcher / init code by itself,
|
||||
# and instead outputs whatever is specified here. (You can use \n here for newline and \ for line continuantions)
|
||||
custom_launcher =
|
||||
|
||||
# TODO should the 64tass arguments be in here too perhaps? So that the "program" parameter that now selects 1 of a few fixed sets of arguments, can be removed?
|
||||
# TODO should an emulator command line also be in here perhaps? So that -emu will work too.
|
||||
|
||||
Reference in New Issue
Block a user