-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge IMachineDefinition into ICompilationTarget
- Loading branch information
Showing
56 changed files
with
685 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,72 @@ | ||
package prog8.code.target | ||
|
||
import prog8.code.core.* | ||
import prog8.code.target.atari.AtariMachineDefinition | ||
import prog8.code.target.encodings.Encoder | ||
import prog8.code.target.zp.AtariZeropage | ||
import java.nio.file.Path | ||
|
||
|
||
class AtariTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer { | ||
|
||
class AtariTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by NormalMemSizer(FLOAT_MEM_SIZE) { | ||
override val name = NAME | ||
override val machine = AtariMachineDefinition() | ||
override val defaultEncoding = Encoding.ATASCII | ||
|
||
companion object { | ||
const val NAME = "atari" | ||
const val FLOAT_MEM_SIZE = 6 | ||
} | ||
|
||
override fun memorySize(dt: DataType, numElements: Int?): Int { | ||
if(dt.isArray) { | ||
if(numElements==null) return 2 // treat it as a pointer size | ||
return when(dt.sub) { | ||
BaseDataType.BOOL, BaseDataType.UBYTE, BaseDataType.BYTE -> numElements | ||
BaseDataType.UWORD, BaseDataType.WORD, BaseDataType.STR -> numElements * 2 | ||
BaseDataType.FLOAT-> numElements * machine.FLOAT_MEM_SIZE | ||
BaseDataType.UNDEFINED -> throw IllegalArgumentException("undefined has no memory size") | ||
else -> throw IllegalArgumentException("invalid sub type") | ||
override val cpu = CpuType.CPU6502 | ||
|
||
override val FLOAT_MAX_POSITIVE = 9.999999999e97 | ||
override val FLOAT_MAX_NEGATIVE = -9.999999999e97 | ||
override val FLOAT_MEM_SIZE = AtariTarget.FLOAT_MEM_SIZE | ||
override val STARTUP_CODE_RESERVED_SIZE = 20u | ||
override val PROGRAM_LOAD_ADDRESS = 0x2000u | ||
override val PROGRAM_MEMTOP_ADDRESS = 0xffffu // TODO what's memtop? | ||
|
||
override val BSSHIGHRAM_START = 0u // TODO | ||
override val BSSHIGHRAM_END = 0u // TODO | ||
override val BSSGOLDENRAM_START = 0u // TODO | ||
override val BSSGOLDENRAM_END = 0u // TODO | ||
|
||
override lateinit var zeropage: Zeropage | ||
override lateinit var golden: GoldenRam | ||
|
||
override fun getFloatAsmBytes(num: Number) = TODO("atari float asm bytes from number") | ||
override fun convertFloatToBytes(num: Double): List<UByte> = TODO("atari float to bytes") | ||
override fun convertBytesToFloat(bytes: List<UByte>): Double = TODO("atari bytes to float") | ||
|
||
override fun launchEmulator(selectedEmulator: Int, programNameWithPath: Path) { | ||
val emulatorName: String | ||
val cmdline: List<String> | ||
when(selectedEmulator) { | ||
1 -> { | ||
emulatorName = "atari800" | ||
cmdline = listOf(emulatorName, "-xl", "-xl-rev", "2", "-nobasic", "-run", "${programNameWithPath}.xex") | ||
} | ||
2 -> { | ||
emulatorName = "altirra" | ||
cmdline = listOf("Altirra64.exe", "${programNameWithPath.normalize()}.xex") | ||
} | ||
else -> { | ||
System.err.println("Atari target only supports atari800 and altirra emulators.") | ||
return | ||
} | ||
} | ||
else if (dt.isString) { | ||
if(numElements!=null) return numElements // treat it as the size of the given string with the length | ||
else return 2 // treat it as the size to store a string pointer | ||
} | ||
|
||
return when { | ||
dt.isByteOrBool -> 1 * (numElements ?: 1) | ||
dt.isFloat -> machine.FLOAT_MEM_SIZE * (numElements ?: 1) | ||
dt.isLong -> throw IllegalArgumentException("long can not yet be put into memory") | ||
dt.isUndefined -> throw IllegalArgumentException("undefined has no memory size") | ||
else -> 2 * (numElements ?: 1) | ||
} | ||
// TODO monlist? | ||
|
||
println("\nStarting Atari800XL emulator $emulatorName...") | ||
val processb = ProcessBuilder(cmdline).inheritIO() | ||
val process: Process = processb.start() | ||
process.waitFor() | ||
} | ||
|
||
override fun isIOAddress(address: UInt): Boolean = address==0u || address==1u || address in 0xd000u..0xdfffu // TODO | ||
|
||
override fun initializeMemoryAreas(compilerOptions: CompilationOptions) { | ||
zeropage = AtariZeropage(compilerOptions) | ||
golden = GoldenRam(compilerOptions, UIntRange.EMPTY) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,77 @@ | ||
package prog8.code.target | ||
|
||
import prog8.code.core.CompilationOptions | ||
import prog8.code.core.CpuType | ||
import prog8.code.core.Encoding | ||
import prog8.code.core.GoldenRam | ||
import prog8.code.core.ICompilationTarget | ||
import prog8.code.core.IMemSizer | ||
import prog8.code.core.IStringEncoding | ||
import prog8.code.target.c128.C128MachineDefinition | ||
import prog8.code.target.cbm.CbmMemorySizer | ||
import prog8.code.core.Zeropage | ||
import prog8.code.target.zp.C128Zeropage | ||
import prog8.code.target.encodings.Encoder | ||
import java.nio.file.Path | ||
|
||
|
||
class C128Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer { | ||
class C128Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by NormalMemSizer(Mflpt5.FLOAT_MEM_SIZE) { | ||
override val name = NAME | ||
override val machine = C128MachineDefinition() | ||
override val defaultEncoding = Encoding.PETSCII | ||
|
||
companion object { | ||
const val NAME = "c128" | ||
} | ||
|
||
|
||
override val cpu = CpuType.CPU6502 | ||
|
||
override val FLOAT_MAX_POSITIVE = Mflpt5.FLOAT_MAX_POSITIVE | ||
override val FLOAT_MAX_NEGATIVE = Mflpt5.FLOAT_MAX_NEGATIVE | ||
override val FLOAT_MEM_SIZE = Mflpt5.FLOAT_MEM_SIZE | ||
override val STARTUP_CODE_RESERVED_SIZE = 20u | ||
override val PROGRAM_LOAD_ADDRESS = 0x1c01u | ||
override val PROGRAM_MEMTOP_ADDRESS = 0xc000u | ||
|
||
override val BSSHIGHRAM_START = 0u // TODO | ||
override val BSSHIGHRAM_END = 0u // TODO | ||
override val BSSGOLDENRAM_START = 0u // TODO | ||
override val BSSGOLDENRAM_END = 0u // TODO | ||
|
||
override lateinit var zeropage: Zeropage | ||
override lateinit var golden: GoldenRam | ||
|
||
override fun getFloatAsmBytes(num: Number) = Mflpt5.fromNumber(num).makeFloatFillAsm() | ||
|
||
override fun convertFloatToBytes(num: Double): List<UByte> { | ||
val m5 = Mflpt5.fromNumber(num) | ||
return listOf(m5.b0, m5.b1, m5.b2, m5.b3, m5.b4) | ||
} | ||
|
||
override fun convertBytesToFloat(bytes: List<UByte>): Double { | ||
require(bytes.size==5) { "need 5 bytes" } | ||
val m5 = Mflpt5(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4]) | ||
return m5.toDouble() | ||
} | ||
|
||
override fun launchEmulator(selectedEmulator: Int, programNameWithPath: Path) { | ||
if(selectedEmulator!=1) { | ||
System.err.println("The c128 target only supports the main emulator (Vice).") | ||
return | ||
} | ||
|
||
println("\nStarting C-128 emulator x128...") | ||
val viceMonlist = C64Target.viceMonListName(programNameWithPath.toString()) | ||
val cmdline = listOf("x128", "-silent", "-moncommands", viceMonlist, | ||
"-autostartprgmode", "1", "-autostart-warp", "-autostart", "${programNameWithPath}.prg") | ||
val processb = ProcessBuilder(cmdline).inheritIO() | ||
val process: Process = processb.start() | ||
process.waitFor() | ||
} | ||
|
||
override fun isIOAddress(address: UInt): Boolean = address==0u || address==1u || address in 0xd000u..0xdfffu | ||
|
||
override fun initializeMemoryAreas(compilerOptions: CompilationOptions) { | ||
zeropage = C128Zeropage(compilerOptions) | ||
golden = GoldenRam(compilerOptions, UIntRange.EMPTY) // TODO does the c128 have some of this somewhere? | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.