auto select correct library to import based on target, instead of having c64- and cx16- prefix variants

some programs are now 100% source compatible between C64 and Cx16 targets!
import libraries have been rena;med
This commit is contained in:
Irmen de Jong 2020-09-20 23:49:36 +02:00
parent 3ff3f5e1cc
commit de06353194
92 changed files with 399 additions and 2475 deletions

View File

@ -7,7 +7,7 @@
%target c64
%option enable_floats
c64flt {
floats {
; ---- this block contains C-64 floating point related functions ----
const float PI = 3.141592653589793
@ -50,22 +50,22 @@ romsub $bc0f = MOVEF() clobbers(A,X) ; copy fac1 to fac2
romsub $bbd4 = MOVMF(uword mflpt @ XY) clobbers(A,Y) ; store fac1 to memory X/Y as 5-byte mflpt
; fac1-> signed word in Y/A (might throw ILLEGAL QUANTITY)
; (tip: use c64flt.FTOSWRDAY to get A/Y output; lo/hi switched to normal little endian order)
; (tip: use floats.FTOSWRDAY to get A/Y output; lo/hi switched to normal little endian order)
romsub $b1aa = FTOSWORDYA() clobbers(X) -> ubyte @ Y, ubyte @ A ; note: calls AYINT.
; fac1 -> unsigned word in Y/A (might throw ILLEGAL QUANTITY) (result also in $14/15)
; (tip: use c64flt.GETADRAY to get A/Y output; lo/hi switched to normal little endian order)
; (tip: use floats.GETADRAY to get A/Y output; lo/hi switched to normal little endian order)
romsub $b7f7 = GETADR() clobbers(X) -> ubyte @ Y, ubyte @ A
romsub $bc9b = QINT() clobbers(A,X,Y) ; fac1 -> 4-byte signed integer in 98-101 ($62-$65), with the MSB FIRST.
romsub $b1bf = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 100-101 ($64-$65) MSB FIRST. (might throw ILLEGAL QUANTITY)
; GIVAYF: signed word in Y/A (note different lsb/msb order) -> float in fac1
; (tip: use c64flt.GIVAYFAY to use A/Y input; lo/hi switched to normal order)
; there is also c64flt.GIVUAYFAY - unsigned word in A/Y (lo/hi) to fac1
; there is also c64flt.FREADS32 that reads from 98-101 ($62-$65) MSB FIRST
; there is also c64flt.FREADUS32 that reads from 98-101 ($62-$65) MSB FIRST
; there is also c64flt.FREADS24AXY that reads signed int24 into fac1 from A/X/Y (lo/mid/hi bytes)
; (tip: use floats.GIVAYFAY to use A/Y input; lo/hi switched to normal order)
; there is also floats.GIVUAYFAY - unsigned word in A/Y (lo/hi) to fac1
; there is also floats.FREADS32 that reads from 98-101 ($62-$65) MSB FIRST
; there is also floats.FREADUS32 that reads from 98-101 ($62-$65) MSB FIRST
; there is also floats.FREADS24AXY that reads signed int24 into fac1 from A/X/Y (lo/mid/hi bytes)
romsub $b391 = GIVAYF(ubyte lo @ Y, ubyte hi @ A) clobbers(A,X,Y)
romsub $b3a2 = FREADUY(ubyte value @ Y) clobbers(A,X,Y) ; 8 bit unsigned Y -> float in fac1
@ -212,6 +212,6 @@ sub print_f (float value) {
}}
}
%asminclude "library:c64floats.asm", ""
%asminclude "library:c64/floats.asm", ""
}

View File

@ -1,5 +1,5 @@
%target c64
%import c64textio
%import textio
; bitmap pixel graphics module for the C64
; only black/white monchrome for now

View File

@ -6,7 +6,7 @@
%target c64
%import c64lib
%import syslib
%import conv

View File

@ -7,7 +7,7 @@
%target cx16
%option enable_floats
c64flt {
floats {
; ---- this block contains C-64 floating point related functions ----
const float PI = 3.141592653589793
@ -25,7 +25,7 @@ c64flt {
romsub $fe00 = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 100-101 ($64-$65) MSB FIRST. (might throw ILLEGAL QUANTITY)
; GIVAYF: signed word in Y/A (note different lsb/msb order) -> float in fac1
; there is also c64flt.GIVUAYFAY - unsigned word in A/Y (lo/hi) to fac1
; there is also floats.GIVUAYFAY - unsigned word in A/Y (lo/hi) to fac1
; (tip: use GIVAYFAY to use A/Y input; lo/hi switched to normal order)
romsub $fe03 = GIVAYF(ubyte lo @ Y, ubyte hi @ A) clobbers(A,X,Y)
@ -148,6 +148,6 @@ sub print_f (float value) {
}}
}
%asminclude "library:c64floats.asm", ""
%asminclude "library:c64/floats.asm", ""
}

View File

@ -60,10 +60,10 @@ romsub $FFF3 = IOBASE() -> uword @ XY ; read base addr
cx16 {
; 65c02 hardware vectors:
&uword NMI_VEC = $FFFA ; 6502 nmi vector, determined by the kernal if banked in
&uword RESET_VEC = $FFFC ; 6502 reset vector, determined by the kernal if banked in
&uword IRQ_VEC = $FFFE ; 6502 interrupt vector, determined by the kernal if banked in
; 65c02 hardware vectors:
&uword NMI_VEC = $FFFA ; 6502 nmi vector, determined by the kernal if banked in
&uword RESET_VEC = $FFFC ; 6502 reset vector, determined by the kernal if banked in
&uword IRQ_VEC = $FFFE ; 6502 interrupt vector, determined by the kernal if banked in
; the sixteen virtual 16-bit registers

View File

@ -5,7 +5,7 @@
; indent format: TABS, size=8
%target cx16
%import cx16lib
%import syslib
%import conv

View File

@ -34,6 +34,16 @@ internal class AstIdentifiersChecker(private val program: Program, private val e
super.visit(block)
}
override fun visit(directive: Directive) {
if(directive.directive=="%target") {
val compatibleTarget = directive.args.single().name
if (compatibleTarget != CompilationTarget.instance.name)
errors.err("module's compilation target ($compatibleTarget) differs from active target (${CompilationTarget.instance.name})", directive.position)
}
super.visit(directive)
}
override fun visit(decl: VarDecl) {
decl.datatypeErrors.forEach { errors.err(it.message, it.position) }

View File

@ -27,8 +27,7 @@ data class CompilationOptions(val output: OutputType,
val launcher: LauncherType,
val zeropage: ZeropageType,
val zpReserved: List<IntRange>,
val floats: Boolean,
val compilationTarget: String?)
val floats: Boolean)
class CompilerException(message: String?) : Exception(message)

View File

@ -91,7 +91,7 @@ fun compileProgram(filepath: Path,
}
private fun parseImports(filepath: Path, errors: ErrorReporter): Triple<Program, CompilationOptions, List<Path>> {
println("Parsing...")
println("Compiler target: ${CompilationTarget.instance.name}. Parsing...")
val importer = ModuleImporter()
val programAst = Program(moduleName(filepath.fileName), mutableListOf())
importer.importModule(programAst, filepath)
@ -125,7 +125,7 @@ private fun determineCompilationOptions(program: Program): CompilationOptions {
as? Directive)?.args?.single()?.name?.toUpperCase()
val allOptions = program.modules.flatMap { it.statements }.filter { it is Directive && it.directive == "%option" }.flatMap { (it as Directive).args }.toSet()
val floatsEnabled = allOptions.any { it.name == "enable_floats" }
val zpType: ZeropageType =
var zpType: ZeropageType =
if (zpoption == null)
if(floatsEnabled) ZeropageType.FLOATSAFE else ZeropageType.KERNALSAFE
else
@ -135,6 +135,12 @@ private fun determineCompilationOptions(program: Program): CompilationOptions {
ZeropageType.KERNALSAFE
// error will be printed by the astchecker
}
if (zpType==ZeropageType.FLOATSAFE && CompilationTarget.instance.name == Cx16Target.name) {
System.err.println("Warning: Cx16 target must use zp option basicsafe instead of floatsafe")
zpType = ZeropageType.BASICSAFE
}
val zpReserved = mainModule.statements
.asSequence()
.filter { it is Directive && it.directive == "%zpreserved" }
@ -142,20 +148,10 @@ private fun determineCompilationOptions(program: Program): CompilationOptions {
.map { it[0].int!!..it[1].int!! }
.toList()
var target = (mainModule.statements.singleOrNull { it is Directive && it.directive == "%target" }
as? Directive)?.args?.single()?.name
when(target) {
C64Target.name -> CompilationTarget.instance = C64Target
Cx16Target.name -> CompilationTarget.instance = Cx16Target
null -> target = CompilationTarget.instance.name
else -> throw FatalAstException("invalid target")
}
return CompilationOptions(
if (outputType == null) OutputType.PRG else OutputType.valueOf(outputType),
if (launcherType == null) LauncherType.BASIC else LauncherType.valueOf(launcherType),
zpType, zpReserved, floatsEnabled, target
zpType, zpReserved, floatsEnabled
)
}
@ -214,9 +210,6 @@ private fun writeAssembly(programAst: Program, errors: ErrorReporter, outputDir:
// printAst(programAst)
if(compilerOptions.compilationTarget!=null && compilerOptions.compilationTarget != CompilationTarget.instance.name)
throw AssemblyError("program's compilation target differs from configured target")
CompilationTarget.instance.machine.initializeZeropage(compilerOptions)
val assembly = CompilationTarget.instance.asmGenerator(
programAst,

View File

@ -37,28 +37,28 @@ internal object C64MachineDefinition: IMachineDefinition {
val mflpt5 = Mflpt5.fromNumber(number)
val floatbytes = shortArrayOf(mflpt5.b0, mflpt5.b1, mflpt5.b2, mflpt5.b3, mflpt5.b4)
when {
floatbytes.contentEquals(shortArrayOf(0x00, 0x00, 0x00, 0x00, 0x00)) -> return "c64flt.ZERO" // not a ROM const
floatbytes.contentEquals(shortArrayOf(0x82, 0x49, 0x0f, 0xda, 0xa1)) -> return "c64flt.FL_PIVAL"
floatbytes.contentEquals(shortArrayOf(0x90, 0x80, 0x00, 0x00, 0x00)) -> return "c64flt.FL_N32768"
floatbytes.contentEquals(shortArrayOf(0x81, 0x00, 0x00, 0x00, 0x00)) -> return "c64flt.FL_FONE"
floatbytes.contentEquals(shortArrayOf(0x80, 0x35, 0x04, 0xf3, 0x34)) -> return "c64flt.FL_SQRHLF"
floatbytes.contentEquals(shortArrayOf(0x81, 0x35, 0x04, 0xf3, 0x34)) -> return "c64flt.FL_SQRTWO"
floatbytes.contentEquals(shortArrayOf(0x80, 0x80, 0x00, 0x00, 0x00)) -> return "c64flt.FL_NEGHLF"
floatbytes.contentEquals(shortArrayOf(0x80, 0x31, 0x72, 0x17, 0xf8)) -> return "c64flt.FL_LOG2"
floatbytes.contentEquals(shortArrayOf(0x84, 0x20, 0x00, 0x00, 0x00)) -> return "c64flt.FL_TENC"
floatbytes.contentEquals(shortArrayOf(0x9e, 0x6e, 0x6b, 0x28, 0x00)) -> return "c64flt.FL_NZMIL"
floatbytes.contentEquals(shortArrayOf(0x80, 0x00, 0x00, 0x00, 0x00)) -> return "c64flt.FL_FHALF"
floatbytes.contentEquals(shortArrayOf(0x81, 0x38, 0xaa, 0x3b, 0x29)) -> return "c64flt.FL_LOGEB2"
floatbytes.contentEquals(shortArrayOf(0x81, 0x49, 0x0f, 0xda, 0xa2)) -> return "c64flt.FL_PIHALF"
floatbytes.contentEquals(shortArrayOf(0x83, 0x49, 0x0f, 0xda, 0xa2)) -> return "c64flt.FL_TWOPI"
floatbytes.contentEquals(shortArrayOf(0x7f, 0x00, 0x00, 0x00, 0x00)) -> return "c64flt.FL_FR4"
floatbytes.contentEquals(shortArrayOf(0x00, 0x00, 0x00, 0x00, 0x00)) -> return "floats.ZERO" // not a ROM const
floatbytes.contentEquals(shortArrayOf(0x82, 0x49, 0x0f, 0xda, 0xa1)) -> return "floats.FL_PIVAL"
floatbytes.contentEquals(shortArrayOf(0x90, 0x80, 0x00, 0x00, 0x00)) -> return "floats.FL_N32768"
floatbytes.contentEquals(shortArrayOf(0x81, 0x00, 0x00, 0x00, 0x00)) -> return "floats.FL_FONE"
floatbytes.contentEquals(shortArrayOf(0x80, 0x35, 0x04, 0xf3, 0x34)) -> return "floats.FL_SQRHLF"
floatbytes.contentEquals(shortArrayOf(0x81, 0x35, 0x04, 0xf3, 0x34)) -> return "floats.FL_SQRTWO"
floatbytes.contentEquals(shortArrayOf(0x80, 0x80, 0x00, 0x00, 0x00)) -> return "floats.FL_NEGHLF"
floatbytes.contentEquals(shortArrayOf(0x80, 0x31, 0x72, 0x17, 0xf8)) -> return "floats.FL_LOG2"
floatbytes.contentEquals(shortArrayOf(0x84, 0x20, 0x00, 0x00, 0x00)) -> return "floats.FL_TENC"
floatbytes.contentEquals(shortArrayOf(0x9e, 0x6e, 0x6b, 0x28, 0x00)) -> return "floats.FL_NZMIL"
floatbytes.contentEquals(shortArrayOf(0x80, 0x00, 0x00, 0x00, 0x00)) -> return "floats.FL_FHALF"
floatbytes.contentEquals(shortArrayOf(0x81, 0x38, 0xaa, 0x3b, 0x29)) -> return "floats.FL_LOGEB2"
floatbytes.contentEquals(shortArrayOf(0x81, 0x49, 0x0f, 0xda, 0xa2)) -> return "floats.FL_PIHALF"
floatbytes.contentEquals(shortArrayOf(0x83, 0x49, 0x0f, 0xda, 0xa2)) -> return "floats.FL_TWOPI"
floatbytes.contentEquals(shortArrayOf(0x7f, 0x00, 0x00, 0x00, 0x00)) -> return "floats.FL_FR4"
else -> {
// attempt to correct for a few rounding issues
when (number.toBigDecimal().setScale(10, RoundingMode.HALF_DOWN).toDouble()) {
3.1415926536 -> return "c64flt.FL_PIVAL"
1.4142135624 -> return "c64flt.FL_SQRTWO"
0.7071067812 -> return "c64flt.FL_SQRHLF"
0.6931471806 -> return "c64flt.FL_LOG2"
3.1415926536 -> return "floats.FL_PIVAL"
1.4142135624 -> return "floats.FL_SQRTWO"
0.7071067812 -> return "floats.FL_SQRHLF"
0.6931471806 -> return "floats.FL_LOG2"
else -> {}
}
}
@ -68,7 +68,7 @@ internal object C64MachineDefinition: IMachineDefinition {
override fun importLibs(compilerOptions: CompilationOptions, importer: ModuleImporter, program: Program) {
if (compilerOptions.launcher == LauncherType.BASIC || compilerOptions.output == OutputType.PRG)
importer.importLibraryModule(program, "c64lib")
importer.importLibraryModule(program, "syslib")
}
override fun launchEmulator(programName: String) {

View File

@ -152,7 +152,7 @@ private fun optimizeSameAssignments(linesByFourteen: List<List<IndexedValue<Stri
if(first.startsWith("lda") && second.startsWith("ldy") && third.startsWith("sta") && fourth.startsWith("sty") &&
fifth.startsWith("lda") && sixth.startsWith("ldy") &&
(seventh.startsWith("jsr c64flt.copy_float") || seventh.startsWith("jsr cx16flt.copy_float"))) {
(seventh.startsWith("jsr floats.copy_float") || seventh.startsWith("jsr cx16flt.copy_float"))) {
val nineth = pair[8].value.trimStart()
val tenth = pair[9].value.trimStart()
@ -163,7 +163,7 @@ private fun optimizeSameAssignments(linesByFourteen: List<List<IndexedValue<Stri
if(eighth.startsWith("lda") && nineth.startsWith("ldy") && tenth.startsWith("sta") && eleventh.startsWith("sty") &&
twelveth.startsWith("lda") && thirteenth.startsWith("ldy") &&
(fourteenth.startsWith("jsr c64flt.copy_float") || fourteenth.startsWith("jsr cx16flt.copy_float"))) {
(fourteenth.startsWith("jsr floats.copy_float") || fourteenth.startsWith("jsr cx16flt.copy_float"))) {
if(first.substring(4) == eighth.substring(4) && second.substring(4)==nineth.substring(4)) {
// identical float init

View File

@ -348,7 +348,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
private fun funcVariousFloatFuncs(fcall: IFunctionCall, func: FSignature, functionName: String) {
translateFunctionArguments(fcall.args, func)
asmgen.out(" jsr c64flt.func_$functionName")
asmgen.out(" jsr floats.func_$functionName")
}
private fun funcSgn(fcall: IFunctionCall, func: FSignature) {
@ -359,7 +359,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
DataType.BYTE -> asmgen.out(" jsr math.sign_b")
DataType.UWORD -> asmgen.out(" jsr math.sign_uw")
DataType.WORD -> asmgen.out(" jsr math.sign_w")
DataType.FLOAT -> asmgen.out(" jsr c64flt.sign_f")
DataType.FLOAT -> asmgen.out(" jsr floats.sign_f")
else -> throw AssemblyError("weird type $dt")
}
}
@ -370,7 +370,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
when (dt.typeOrElse(DataType.STRUCT)) {
DataType.ARRAY_B, DataType.ARRAY_UB, DataType.STR -> asmgen.out(" jsr prog8_lib.func_${functionName}_b")
DataType.ARRAY_UW, DataType.ARRAY_W -> asmgen.out(" jsr prog8_lib.func_${functionName}_w")
DataType.ARRAY_F -> asmgen.out(" jsr c64flt.func_${functionName}_f")
DataType.ARRAY_F -> asmgen.out(" jsr floats.func_${functionName}_f")
else -> throw AssemblyError("weird type $dt")
}
}
@ -383,7 +383,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
DataType.ARRAY_B -> asmgen.out(" jsr prog8_lib.func_${functionName}_b")
DataType.ARRAY_UW -> asmgen.out(" jsr prog8_lib.func_${functionName}_uw")
DataType.ARRAY_W -> asmgen.out(" jsr prog8_lib.func_${functionName}_w")
DataType.ARRAY_F -> asmgen.out(" jsr c64flt.func_${functionName}_f")
DataType.ARRAY_F -> asmgen.out(" jsr floats.func_${functionName}_f")
else -> throw AssemblyError("weird type $dt")
}
}
@ -434,7 +434,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
sta P8ZP_SCRATCH_W2
lda #>$secondName
sta P8ZP_SCRATCH_W2+1
jsr c64flt.swap_floats
jsr floats.swap_floats
""")
return
}
@ -546,7 +546,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
sta P8ZP_SCRATCH_W2
lda #>(${arrayVarName2}+$index2)
sta P8ZP_SCRATCH_W2+1
jsr c64flt.swap_floats
jsr floats.swap_floats
""")
}
else -> throw AssemblyError("invalid aray elt type")
@ -619,7 +619,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
sta P8ZP_SCRATCH_W2
bcc +
inc P8ZP_SCRATCH_W2+1
+ jsr c64flt.swap_floats
+ jsr floats.swap_floats
""")
}
else -> throw AssemblyError("invalid aray elt type")
@ -632,7 +632,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
when (dt.typeOrElse(DataType.STRUCT)) {
in ByteDatatypes -> asmgen.out(" jsr prog8_lib.abs_b")
in WordDatatypes -> asmgen.out(" jsr prog8_lib.abs_w")
DataType.FLOAT -> asmgen.out(" jsr c64flt.abs_f")
DataType.FLOAT -> asmgen.out(" jsr floats.abs_f")
else -> throw AssemblyError("weird type")
}
}

View File

@ -90,7 +90,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
else
asmgen.out(" lda #0 | sta P8ESTACK_HI+1,x")
}
DataType.FLOAT -> asmgen.out(" jsr c64flt.stack_ub2float")
DataType.FLOAT -> asmgen.out(" jsr floats.stack_ub2float")
in PassByReferenceDatatypes -> throw AssemblyError("cannot cast to a pass-by-reference datatype")
else -> throw AssemblyError("weird type")
}
@ -107,7 +107,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
lda #0
+ sta P8ESTACK_HI+1,x""")
}
DataType.FLOAT -> asmgen.out(" jsr c64flt.stack_b2float")
DataType.FLOAT -> asmgen.out(" jsr floats.stack_b2float")
in PassByReferenceDatatypes -> throw AssemblyError("cannot cast to a pass-by-reference datatype")
else -> throw AssemblyError("weird type")
}
@ -116,7 +116,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
when(expr.type) {
DataType.BYTE, DataType.UBYTE -> {}
DataType.WORD, DataType.UWORD -> {}
DataType.FLOAT -> asmgen.out(" jsr c64flt.stack_uw2float")
DataType.FLOAT -> asmgen.out(" jsr floats.stack_uw2float")
in PassByReferenceDatatypes -> throw AssemblyError("cannot cast to a pass-by-reference datatype")
else -> throw AssemblyError("weird type")
}
@ -125,17 +125,17 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
when(expr.type) {
DataType.BYTE, DataType.UBYTE -> {}
DataType.WORD, DataType.UWORD -> {}
DataType.FLOAT -> asmgen.out(" jsr c64flt.stack_w2float")
DataType.FLOAT -> asmgen.out(" jsr floats.stack_w2float")
in PassByReferenceDatatypes -> throw AssemblyError("cannot cast to a pass-by-reference datatype")
else -> throw AssemblyError("weird type")
}
}
DataType.FLOAT -> {
when(expr.type) {
DataType.UBYTE -> asmgen.out(" jsr c64flt.stack_float2uw")
DataType.BYTE -> asmgen.out(" jsr c64flt.stack_float2w")
DataType.UWORD -> asmgen.out(" jsr c64flt.stack_float2uw")
DataType.WORD -> asmgen.out(" jsr c64flt.stack_float2w")
DataType.UBYTE -> asmgen.out(" jsr floats.stack_float2uw")
DataType.BYTE -> asmgen.out(" jsr floats.stack_float2w")
DataType.UWORD -> asmgen.out(" jsr floats.stack_float2uw")
DataType.WORD -> asmgen.out(" jsr floats.stack_float2w")
DataType.FLOAT -> {}
in PassByReferenceDatatypes -> throw AssemblyError("cannot cast to a pass-by-reference datatype")
else -> throw AssemblyError("weird type")
@ -182,7 +182,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
""")
DataType.FLOAT -> {
val floatConst = asmgen.getFloatAsmConst(expr.number.toDouble())
asmgen.out(" lda #<$floatConst | ldy #>$floatConst | jsr c64flt.push_float")
asmgen.out(" lda #<$floatConst | ldy #>$floatConst | jsr floats.push_float")
}
else -> throw AssemblyError("weird type")
}
@ -198,7 +198,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
asmgen.out(" lda $varname | sta P8ESTACK_LO,x | lda $varname+1 | sta P8ESTACK_HI,x | dex")
}
DataType.FLOAT -> {
asmgen.out(" lda #<$varname | ldy #>$varname| jsr c64flt.push_float")
asmgen.out(" lda #<$varname | ldy #>$varname| jsr floats.push_float")
}
in IterableDatatypes -> {
asmgen.out(" lda #<$varname | sta P8ESTACK_LO,x | lda #>$varname | sta P8ESTACK_HI,x | dex")
@ -368,7 +368,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
when(type) {
in ByteDatatypes -> asmgen.out(" jsr prog8_lib.neg_b")
in WordDatatypes -> asmgen.out(" jsr prog8_lib.neg_w")
DataType.FLOAT -> asmgen.out(" jsr c64flt.neg_f")
DataType.FLOAT -> asmgen.out(" jsr floats.neg_f")
else -> throw AssemblyError("weird type")
}
}
@ -409,7 +409,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
asmgen.out(" lda $arrayVarName+$indexValue | sta P8ESTACK_LO,x | lda $arrayVarName+$indexValue+1 | sta P8ESTACK_HI,x | dex")
}
DataType.FLOAT -> {
asmgen.out(" lda #<$arrayVarName+$indexValue | ldy #>$arrayVarName+$indexValue | jsr c64flt.push_float")
asmgen.out(" lda #<$arrayVarName+$indexValue | ldy #>$arrayVarName+$indexValue | jsr floats.push_float")
}
else -> throw AssemblyError("weird element type")
}
@ -431,7 +431,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
adc #<$arrayVarName
bcc +
iny
+ jsr c64flt.push_float""")
+ jsr floats.push_float""")
}
else -> throw AssemblyError("weird dt")
}
@ -513,17 +513,17 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
private fun translateBinaryOperatorFloats(operator: String) {
when(operator) {
"**" -> asmgen.out(" jsr c64flt.pow_f")
"*" -> asmgen.out(" jsr c64flt.mul_f")
"/" -> asmgen.out(" jsr c64flt.div_f")
"+" -> asmgen.out(" jsr c64flt.add_f")
"-" -> asmgen.out(" jsr c64flt.sub_f")
"<" -> asmgen.out(" jsr c64flt.less_f")
">" -> asmgen.out(" jsr c64flt.greater_f")
"<=" -> asmgen.out(" jsr c64flt.lesseq_f")
">=" -> asmgen.out(" jsr c64flt.greatereq_f")
"==" -> asmgen.out(" jsr c64flt.equal_f")
"!=" -> asmgen.out(" jsr c64flt.notequal_f")
"**" -> asmgen.out(" jsr floats.pow_f")
"*" -> asmgen.out(" jsr floats.mul_f")
"/" -> asmgen.out(" jsr floats.div_f")
"+" -> asmgen.out(" jsr floats.add_f")
"-" -> asmgen.out(" jsr floats.sub_f")
"<" -> asmgen.out(" jsr floats.less_f")
">" -> asmgen.out(" jsr floats.greater_f")
"<=" -> asmgen.out(" jsr floats.lesseq_f")
">=" -> asmgen.out(" jsr floats.greatereq_f")
"==" -> asmgen.out(" jsr floats.equal_f")
"!=" -> asmgen.out(" jsr floats.notequal_f")
"%", "<<", ">>", "&", "^", "|", "and", "or", "xor" -> throw AssemblyError("requires integer datatype")
else -> throw AssemblyError("invalid operator $operator")
}

View File

@ -33,7 +33,7 @@ internal class PostIncrDecrAsmGen(private val program: Program, private val asmg
}
DataType.FLOAT -> {
asmgen.out(" lda #<$what | ldy #>$what")
asmgen.out(if(incr) " jsr c64flt.inc_var_f" else " jsr c64flt.dec_var_f")
asmgen.out(if(incr) " jsr floats.inc_var_f" else " jsr floats.dec_var_f")
}
else -> throw AssemblyError("need numeric type")
}
@ -90,7 +90,7 @@ internal class PostIncrDecrAsmGen(private val program: Program, private val asmg
}
DataType.FLOAT -> {
asmgen.out(" lda #<$asmArrayvarname+$indexValue | ldy #>$asmArrayvarname+$indexValue")
asmgen.out(if(incr) " jsr c64flt.inc_var_f" else " jsr c64flt.dec_var_f")
asmgen.out(if(incr) " jsr floats.inc_var_f" else " jsr floats.dec_var_f")
}
else -> throw AssemblyError("need numeric type")
}
@ -121,7 +121,7 @@ internal class PostIncrDecrAsmGen(private val program: Program, private val asmg
adc #<$asmArrayvarname
bcc +
iny
+ jsr c64flt.inc_var_f""")
+ jsr floats.inc_var_f""")
}
else -> throw AssemblyError("weird array elt dt")
}

View File

@ -65,7 +65,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
in WordDatatypes ->
asmgen.out(" lda $arrayVarName+$indexValue | sta P8ESTACK_LO,x | lda $arrayVarName+$indexValue+1 | sta P8ESTACK_HI,x | dex")
DataType.FLOAT ->
asmgen.out(" lda #<$arrayVarName+$indexValue | ldy #>$arrayVarName+$indexValue | jsr c64flt.push_float")
asmgen.out(" lda #<$arrayVarName+$indexValue | ldy #>$arrayVarName+$indexValue | jsr floats.push_float")
else ->
throw AssemblyError("weird array type")
}
@ -87,7 +87,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
adc #<$arrayVarName
bcc +
iny
+ jsr c64flt.push_float""")
+ jsr floats.push_float""")
}
else ->
throw AssemblyError("weird array elt type")
@ -217,7 +217,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
asmgen.out("""
lda #<${target.asmVarname}
ldy #>${target.asmVarname}
jsr c64flt.pop_float
jsr floats.pop_float
""")
}
else -> throw AssemblyError("weird target variable type ${target.datatype}")
@ -249,7 +249,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
asmgen.out("""
lda #<${target.asmVarname}+$scaledIdx
ldy #>${target.asmVarname}+$scaledIdx
jsr c64flt.pop_float
jsr floats.pop_float
""")
}
else -> throw AssemblyError("weird target variable type ${target.datatype}")
@ -279,7 +279,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
adc #<${target.asmVarname}
bcc +
iny
+ jsr c64flt.pop_float""")
+ jsr floats.pop_float""")
}
else -> throw AssemblyError("weird dt")
}
@ -406,7 +406,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
sty P8ZP_SCRATCH_W1+1
lda #<${target.asmVarname}+$scaledIdx
ldy #>${target.asmVarname}+$scaledIdx
jsr c64flt.copy_float
jsr floats.copy_float
""")
}
else -> throw AssemblyError("weird target variable type ${target.datatype}")
@ -439,7 +439,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
adc #<${target.asmVarname}
bcc +
iny
+ jsr c64flt.copy_float""")
+ jsr floats.copy_float""")
}
else -> throw AssemblyError("weird dt")
}
@ -496,13 +496,13 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
// TODO("array[var] ${target.constArrayIndexValue}")
// }
val index = target.array!!.arrayspec.index
asmgen.out(" lda #<$sourceName | ldy #>$sourceName | jsr c64flt.push_float")
asmgen.out(" lda #<$sourceName | ldy #>$sourceName | jsr floats.push_float")
asmgen.translateExpression(index)
asmgen.out(" lda #<${target.asmVarname} | ldy #>${target.asmVarname} | jsr c64flt.pop_float_to_indexed_var")
asmgen.out(" lda #<${target.asmVarname} | ldy #>${target.asmVarname} | jsr floats.pop_float_to_indexed_var")
}
TargetStorageKind.MEMORY -> throw AssemblyError("can't assign float to mem byte")
TargetStorageKind.REGISTER -> throw AssemblyError("can't assign float to register")
TargetStorageKind.STACK -> asmgen.out(" lda #<$sourceName | ldy #>$sourceName | jsr c64flt.push_float")
TargetStorageKind.STACK -> asmgen.out(" lda #<$sourceName | ldy #>$sourceName | jsr floats.push_float")
}
}
@ -850,7 +850,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
sta P8ZP_SCRATCH_W1
lda #>${target.asmVarname}
sta P8ZP_SCRATCH_W1+1
jsr c64flt.set_0_array_float
jsr floats.set_0_array_float
""")
}
}
@ -858,7 +858,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
TargetStorageKind.REGISTER -> throw AssemblyError("can't assign float to register")
TargetStorageKind.STACK -> {
val floatConst = asmgen.getFloatAsmConst(float)
asmgen.out(" lda #<$floatConst | ldy #>$floatConst | jsr c64flt.push_float")
asmgen.out(" lda #<$floatConst | ldy #>$floatConst | jsr floats.push_float")
}
}
} else {
@ -913,7 +913,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
sta P8ZP_SCRATCH_W2
lda #>${arrayVarName}
sta P8ZP_SCRATCH_W2+1
jsr c64flt.set_array_float
jsr floats.set_array_float
""")
}
}
@ -921,7 +921,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
TargetStorageKind.REGISTER -> throw AssemblyError("can't assign float to register")
TargetStorageKind.STACK -> {
val floatConst = asmgen.getFloatAsmConst(float)
asmgen.out(" lda #<$floatConst | ldy #>$floatConst | jsr c64flt.push_float")
asmgen.out(" lda #<$floatConst | ldy #>$floatConst | jsr floats.push_float")
}
}
}
@ -1117,7 +1117,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
dex
lda #<$asmArrayvarname
ldy #>$asmArrayvarname
jsr c64flt.pop_float_to_indexed_var
jsr floats.pop_float_to_indexed_var
""")
else ->
throw AssemblyError("weird array type")

View File

@ -1145,43 +1145,43 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
// because the value is evaluated onto the eval stack (=slow).
println("warning: slow stack evaluation used (2): $name $operator= ${value::class.simpleName} at ${value.position}") // TODO
asmgen.translateExpression(value)
asmgen.out(" jsr c64flt.pop_float_fac1")
asmgen.out(" jsr floats.pop_float_fac1")
asmgen.saveRegister(CpuRegister.X)
when (operator) {
"**" -> {
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.CONUPK
jsr c64flt.FPWRT
jsr floats.CONUPK
jsr floats.FPWRT
""")
}
"+" -> {
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.FADD
jsr floats.FADD
""")
}
"-" -> {
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.FSUB
jsr floats.FSUB
""")
}
"*" -> {
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.FMULT
jsr floats.FMULT
""")
}
"/" -> {
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.FDIV
jsr floats.FDIV
""")
}
else -> throw AssemblyError("invalid operator for in-place float modification $operator")
@ -1189,7 +1189,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
ldx #<$name
ldy #>$name
jsr c64flt.MOVMF
jsr floats.MOVMF
""")
asmgen.restoreRegister(CpuRegister.X)
}
@ -1206,50 +1206,50 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.CONUPK
jsr floats.CONUPK
lda #<$otherName
ldy #>$otherName
jsr c64flt.FPWR
jsr floats.FPWR
""")
}
"+" -> {
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.MOVFM
jsr floats.MOVFM
lda #<$otherName
ldy #>$otherName
jsr c64flt.FADD
jsr floats.FADD
""")
}
"-" -> {
asmgen.out("""
lda #<$otherName
ldy #>$otherName
jsr c64flt.MOVFM
jsr floats.MOVFM
lda #<$name
ldy #>$name
jsr c64flt.FSUB
jsr floats.FSUB
""")
}
"*" -> {
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.MOVFM
jsr floats.MOVFM
lda #<$otherName
ldy #>$otherName
jsr c64flt.FMULT
jsr floats.FMULT
""")
}
"/" -> {
asmgen.out("""
lda #<$otherName
ldy #>$otherName
jsr c64flt.MOVFM
jsr floats.MOVFM
lda #<$name
ldy #>$name
jsr c64flt.FDIV
jsr floats.FDIV
""")
}
else -> throw AssemblyError("invalid operator for in-place float modification $operator")
@ -1258,7 +1258,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
ldx #<$name
ldy #>$name
jsr c64flt.MOVMF
jsr floats.MOVMF
""")
asmgen.restoreRegister(CpuRegister.X)
}
@ -1271,10 +1271,10 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.CONUPK
jsr floats.CONUPK
lda #<$constValueName
ldy #>$constValueName
jsr c64flt.FPWR
jsr floats.FPWR
""")
}
"+" -> {
@ -1283,10 +1283,10 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.MOVFM
jsr floats.MOVFM
lda #<$constValueName
ldy #>$constValueName
jsr c64flt.FADD
jsr floats.FADD
""")
}
"-" -> {
@ -1295,10 +1295,10 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
lda #<$constValueName
ldy #>$constValueName
jsr c64flt.MOVFM
jsr floats.MOVFM
lda #<$name
ldy #>$name
jsr c64flt.FSUB
jsr floats.FSUB
""")
}
"*" -> {
@ -1306,10 +1306,10 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
lda #<$name
ldy #>$name
jsr c64flt.MOVFM
jsr floats.MOVFM
lda #<$constValueName
ldy #>$constValueName
jsr c64flt.FMULT
jsr floats.FMULT
""")
}
"/" -> {
@ -1318,10 +1318,10 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
lda #<$constValueName
ldy #>$constValueName
jsr c64flt.MOVFM
jsr floats.MOVFM
lda #<$name
ldy #>$name
jsr c64flt.FDIV
jsr floats.FDIV
""")
}
else -> throw AssemblyError("invalid operator for in-place float modification $operator")
@ -1330,7 +1330,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
ldx #<$name
ldy #>$name
jsr c64flt.MOVMF
jsr floats.MOVMF
""")
asmgen.restoreRegister(CpuRegister.X)
}
@ -1572,11 +1572,11 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
asmgen.out("""
lda #<${target.asmVarname}
ldy #>${target.asmVarname}
jsr c64flt.MOVFM
jsr c64flt.NEGOP
jsr floats.MOVFM
jsr floats.NEGOP
ldx #<${target.asmVarname}
ldy #>${target.asmVarname}
jsr c64flt.MOVMF
jsr floats.MOVMF
""")
asmgen.restoreRegister(CpuRegister.X)
}

View File

@ -32,7 +32,7 @@ internal object CX16MachineDefinition: IMachineDefinition {
override fun getFloatRomConst(number: Double): String? = null // Cx16 has no pulblic ROM float locations
override fun importLibs(compilerOptions: CompilationOptions, importer: ModuleImporter, program: Program) {
if (compilerOptions.launcher == LauncherType.BASIC || compilerOptions.output == OutputType.PRG)
importer.importLibraryModule(program, "cx16lib")
importer.importLibraryModule(program, "syslib")
}
override fun launchEmulator(programName: String) {

View File

@ -9,6 +9,7 @@ import prog8.ast.base.SyntaxError
import prog8.ast.base.checkImportedValid
import prog8.ast.statements.Directive
import prog8.ast.statements.DirectiveArg
import prog8.compiler.target.CompilationTarget
import prog8.pathFrom
import java.io.InputStream
import java.nio.file.Files
@ -148,6 +149,10 @@ internal class ModuleImporter {
}
private fun tryGetEmbeddedResource(name: String): InputStream? {
val target = CompilationTarget.instance.name
val targetSpecific = object{}.javaClass.getResourceAsStream("/prog8lib/$target/$name")
if(targetSpecific!=null)
return targetSpecific
return object{}.javaClass.getResourceAsStream("/prog8lib/$name")
}
}

View File

@ -129,7 +129,7 @@ class TestC64Zeropage {
@Test
fun testNames() {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, "c64"))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false))
zp.allocate("", DataType.UBYTE, null, errors)
zp.allocate("", DataType.UBYTE, null, errors)
@ -142,37 +142,37 @@ class TestC64Zeropage {
@Test
fun testZpFloatEnable() {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, "c64"))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false))
assertFailsWith<CompilerException> {
zp.allocate("", DataType.FLOAT, null, errors)
}
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), true, "c64"))
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), true))
assertFailsWith<CompilerException> {
zp2.allocate("", DataType.FLOAT, null, errors)
}
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true, "c64"))
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true))
zp3.allocate("", DataType.FLOAT, null, errors)
}
@Test
fun testZpModesWithFloats() {
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, "c64"))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, "c64"))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, "c64"))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, "c64"))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, "c64"))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true, "c64"))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true))
assertFailsWith<CompilerException> {
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), true, "c64"))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), true))
}
assertFailsWith<CompilerException> {
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), true, "c64"))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), true))
}
}
@Test
fun testZpDontuse() {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), false, "c64"))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), false))
println(zp.free)
assertEquals(0, zp.available())
assertFailsWith<CompilerException> {
@ -182,19 +182,19 @@ class TestC64Zeropage {
@Test
fun testFreeSpaces() {
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, "c64"))
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true))
assertEquals(16, zp1.available())
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, "c64"))
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false))
assertEquals(91, zp2.available())
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, "c64"))
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false))
assertEquals(125, zp3.available())
val zp4 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, "c64"))
val zp4 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false))
assertEquals(238, zp4.available())
}
@Test
fun testReservedSpace() {
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, "c64"))
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false))
assertEquals(238, zp1.available())
assertTrue(50 in zp1.free)
assertTrue(100 in zp1.free)
@ -203,7 +203,7 @@ class TestC64Zeropage {
assertTrue(200 in zp1.free)
assertTrue(255 in zp1.free)
assertTrue(199 in zp1.free)
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, listOf(50 .. 100, 200..255), false, "c64"))
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, listOf(50 .. 100, 200..255), false))
assertEquals(139, zp2.available())
assertFalse(50 in zp2.free)
assertFalse(100 in zp2.free)
@ -216,7 +216,7 @@ class TestC64Zeropage {
@Test
fun testBasicsafeAllocation() {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, "c64"))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true))
assertEquals(16, zp.available())
assertFailsWith<ZeropageDepletedError> {
@ -239,7 +239,7 @@ class TestC64Zeropage {
@Test
fun testFullAllocation() {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, "c64"))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false))
assertEquals(238, zp.available())
val loc = zp.allocate("", DataType.UWORD, null, errors)
assertTrue(loc > 3)
@ -269,7 +269,7 @@ class TestC64Zeropage {
@Test
fun testEfficientAllocation() {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, "c64"))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true))
assertEquals(16, zp.available())
assertEquals(0x04, zp.allocate("", DataType.WORD, null, errors))
assertEquals(0x06, zp.allocate("", DataType.UBYTE, null, errors))

View File

@ -36,9 +36,8 @@ Directives
.. data:: %target <target>
Level: module.
Global setting, selects a compilation target from within the source file.
The default compilation target is "c64" which targets the Commodore-64 machine.
You can also omit this and use the ``-target`` command line option.
Global setting, specifies that this module can only work for the given compiler target.
If compiled with a different target, compilation is aborted with an error message.
.. data:: %output <type>

View File

@ -9,8 +9,7 @@ Prog8 targets the following hardware:
- optional use of memory mapped I/O registers
- optional use of system ROM routines
Currently there are two machines that are supported as compiler target (via the ``-target`` compiler argument
or the ``%target`` directive in your program source):
Currently there are two machines that are supported as compiler target (selectable via the ``-target`` compiler argument):
- 'c64': the well-known Commodore-64, premium support
- 'cx16': the `CommanderX16 <https://www.commanderx16.com/>`_ a project from the 8-Bit Guy. Support for this is still experimental.

View File

@ -6,7 +6,6 @@ TODO
- line-circle-gfx examples are now a few hundred bytes larger than before. Why is that, can it be fixed?
- make it possible for array literals to not only contain compile time constants
- further optimize assignment codegeneration
- auto select correct library to import based on target, instead of having c64- and cx16- prefix variants
- implement @stack for asmsub parameters
- make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_'
- option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging)

View File

@ -1,5 +1,5 @@
%import c64flt
%import c64textio
%import floats
%import textio
%zeropage basicsafe
main {

View File

@ -1,4 +1,4 @@
%import c64textio
%import textio
%zeropage basicsafe

View File

@ -1,7 +1,9 @@
%import c64flt
%import c64textio
%import floats
%import textio
%zeropage basicsafe
; TODO fix crash on CX16
main {
sub start() {
@ -93,11 +95,11 @@ main {
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
floats.print_f(a1)
txt.print(" / ")
c64flt.print_f(a2)
floats.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
floats.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -1,7 +1,9 @@
%import c64flt
%import c64textio
%import floats
%import textio
%zeropage basicsafe
; TODO fix crash on CX16
main {
sub start() {
@ -101,11 +103,11 @@ main {
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
floats.print_f(a1)
txt.print(" - ")
c64flt.print_f(a2)
floats.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
floats.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -1,7 +1,9 @@
%import c64flt
%import c64textio
%import floats
%import textio
%zeropage basicsafe
; TODO fix crash on CX16
main {
sub start() {
@ -95,11 +97,11 @@ main {
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
floats.print_f(a1)
txt.print(" * ")
c64flt.print_f(a2)
floats.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
floats.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -1,7 +1,9 @@
%import c64flt
%import c64textio
%import floats
%import textio
%zeropage basicsafe
; TODO fix crash on CX16
main {
sub start() {
@ -99,11 +101,11 @@ main {
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
floats.print_f(a1)
txt.print(" + ")
c64flt.print_f(a2)
floats.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
floats.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -1,7 +1,9 @@
%import c64flt
%import c64textio
%import floats
%import textio
%zeropage basicsafe
; TODO fix crash on CX16
main {
sub start() {
@ -132,9 +134,9 @@ main {
else
txt.print("err! ")
txt.print(" float ")
c64flt.print_f(value)
floats.print_f(value)
c64.CHROUT(',')
c64flt.print_f(expected)
floats.print_f(expected)
c64.CHROUT('\n')
}
}

View File

@ -1,4 +1,4 @@
%import c64textio
%import textio
%zeropage basicsafe
main {

View File

@ -1,5 +1,5 @@
%import c64flt
%import c64textio
%import floats
%import textio
%zeropage basicsafe
main {

View File

@ -1,5 +1,6 @@
%import c64lib
%import c64textio
%target c64
%import syslib
%import textio
%zeropage basicsafe
main {

View File

@ -1,5 +1,6 @@
%import c64lib
%import c64textio
%target c64
%import syslib
%import textio
%zeropage basicsafe
main {

View File

@ -1,4 +1,6 @@
%import c64textio
%target c64
%import textio
%import syslib
main {

View File

@ -1,6 +1,7 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {

View File

@ -1,7 +1,9 @@
%import c64textio
%import c64flt
%import textio
%import floats
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,7 +1,9 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,6 +1,7 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {

View File

@ -1,6 +1,7 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {

View File

@ -1,6 +1,8 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,7 +1,9 @@
%import c64textio
%import c64flt
%import textio
%import floats
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,6 +1,8 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,6 +1,8 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,6 +1,8 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,12 +1,11 @@
%import c64lib
%import c64textio
%import c64flt
%import floats
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
const uword width = 40
const uword height = 25
; vertices
float[] xcoor = [ -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0 ]
float[] ycoor = [ -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0 ]
@ -19,18 +18,29 @@ main {
sub start() {
float time=0.0
ubyte timer_jiffies
repeat {
rotate_vertices(time)
txt.clear_screenchars(32)
txt.clear_screenchars(' ')
draw_edges()
time+=0.2
time+=0.1
txt.plot(0,0)
txt.print("3d cube! (float) ")
txt.print_ub(c64.TIME_LO)
txt.print("3d cube! floats. ")
%asm {{
stx P8ZP_SCRATCH_REG
jsr c64.RDTIM ; A/X/Y
sta timer_jiffies
lda #0
jsr c64.SETTIM
ldx P8ZP_SCRATCH_REG
}}
txt.print_ub(timer_jiffies)
txt.print(" jiffies/fr = ")
txt.print_ub(60/c64.TIME_LO)
txt.print_ub(60/timer_jiffies)
txt.print(" fps")
c64.TIME_LO=0
}
}
@ -78,20 +88,20 @@ main {
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz >= 0.1 {
persp = (5.0+rz)/(height as float)
sx = rotatedx[i] / persp + width/2.0 as ubyte
sy = rotatedy[i] / persp + height/2.0 as ubyte
txt.setcc(sx, sy, 46, i+2)
persp = (5.0+rz)/(txt.DEFAULT_HEIGHT as float)
sx = rotatedx[i] / persp + txt.DEFAULT_WIDTH/2.0 as ubyte
sy = rotatedy[i] / persp + txt.DEFAULT_HEIGHT/2.0 as ubyte
txt.setcc(sx, sy, 46, 1)
}
}
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz < 0.1 {
persp = (5.0+rz)/(height as float)
sx = rotatedx[i] / persp + width/2.0 as ubyte
sy = rotatedy[i] / persp + height/2.0 as ubyte
txt.setcc(sx, sy, 81, i+2)
persp = (5.0+rz)/(txt.DEFAULT_HEIGHT as float)
sx = rotatedx[i] / persp + txt.DEFAULT_WIDTH/2.0 as ubyte
sy = rotatedy[i] / persp + txt.DEFAULT_HEIGHT/2.0 as ubyte
txt.setcc(sx, sy, 81, 1)
}
}
}

View File

@ -1,5 +1,9 @@
%import c64lib
%import c64graphics
%target c64
%import graphics
%import syslib
; TODO make the graphics library not C64 specific
main {

View File

@ -1,5 +1,6 @@
%import c64lib
%import c64textio
%target c64
%import syslib
%import textio
spritedata $2000 {

View File

@ -1,11 +1,9 @@
%import c64lib
%import c64textio
%target c64
%import syslib
%import textio
main {
const uword width = 40
const uword height = 25
; vertices
word[] xcoor = [ -40, -40, -40, -40, 40, 40, 40, 40 ]
word[] ycoor = [ -40, -40, 40, 40, -40, -40, 40, 40 ]
@ -86,8 +84,8 @@ main {
rz = rotatedz[i]
if rz >= 10 {
persp = 900 + rz/32
sx = rotatedx[i] / persp as byte + width/2
sy = rotatedy[i] / persp as byte + height/2
sx = rotatedx[i] / persp as byte + txt.DEFAULT_WIDTH/2
sy = rotatedy[i] / persp as byte + txt.DEFAULT_HEIGHT/2
txt.setcc(sx as ubyte, sy as ubyte, 46, 7)
}
}
@ -96,8 +94,8 @@ main {
rz = rotatedz[i]
if rz < 10 {
persp = 900 + rz/32
sx = rotatedx[i] / persp as byte + width/2
sy = rotatedy[i] / persp as byte + height/2
sx = rotatedx[i] / persp as byte + txt.DEFAULT_WIDTH/2
sy = rotatedy[i] / persp as byte + txt.DEFAULT_HEIGHT/2
txt.setcc(sx as ubyte, sy as ubyte, 81, 7)
}
}

View File

@ -1,109 +0,0 @@
%target cx16
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
ubyte[] ubarr = [100, 0, 99, 199, 22]
byte[] barr = [-100, 0, 99, -122, 22]
uword[] uwarr = [1000, 0, 222, 4444, 999]
word[] warr = [-1000, 0, 999, -4444, 222]
float[] farr = [-1000.1, 0, 999.9, -4444.4, 222.2]
str name = "irmen"
ubyte ub
byte bb
word ww
uword uw
float ff
; LEN/STRLEN
ubyte length = len(name)
if length!=5 txt.print("error len1\n")
length = len(uwarr)
if length!=5 txt.print("error len2\n")
length=strlen(name)
if length!=5 txt.print("error strlen1\n")
name[3] = 0
length=strlen(name)
if length!=3 txt.print("error strlen2\n")
; MAX
ub = max(ubarr)
if ub!=199 txt.print("error max1\n")
bb = max(barr)
if bb!=99 txt.print("error max2\n")
uw = max(uwarr)
if uw!=4444 txt.print("error max3\n")
ww = max(warr)
if ww!=999 txt.print("error max4\n")
ff = max(farr)
if ff!=999.9 txt.print("error max5\n")
; MIN
ub = min(ubarr)
if ub!=0 txt.print("error min1\n")
bb = min(barr)
if bb!=-122 txt.print("error min2\n")
uw = min(uwarr)
if uw!=0 txt.print("error min3\n")
ww = min(warr)
if ww!=-4444 txt.print("error min4\n")
ff = min(farr)
if ff!=-4444.4 txt.print("error min5\n")
; SUM
uw = sum(ubarr)
if uw!=420 txt.print("error sum1\n")
ww = sum(barr)
if ww!=-101 txt.print("error sum2\n")
uw = sum(uwarr)
if uw!=6665 txt.print("error sum3\n")
ww = sum(warr)
if ww!=-4223 txt.print("error sum4\n")
ff = sum(farr)
if ff!=-4222.4 txt.print("error sum5\n")
; ANY
ub = any(ubarr)
if ub==0 txt.print("error any1\n")
ub = any(barr)
if ub==0 txt.print("error any2\n")
ub = any(uwarr)
if ub==0 txt.print("error any3\n")
ub = any(warr)
if ub==0 txt.print("error any4\n")
ub = any(farr)
if ub==0 txt.print("error any5\n")
; ALL
ub = all(ubarr)
if ub==1 txt.print("error all1\n")
ub = all(barr)
if ub==1 txt.print("error all2\n")
ub = all(uwarr)
if ub==1 txt.print("error all3\n")
ub = all(warr)
if ub==1 txt.print("error all4\n")
ub = all(farr)
if ub==1 txt.print("error all5\n")
ubarr[1]=$40
barr[1]=$40
uwarr[1]=$4000
warr[1]=$4000
farr[1]=1.1
ub = all(ubarr)
if ub==0 txt.print("error all6\n")
ub = all(barr)
if ub==0 txt.print("error all7\n")
ub = all(uwarr)
if ub==0 txt.print("error all8\n")
ub = all(warr)
if ub==0 txt.print("error all9\n")
ub = all(farr)
if ub==0 txt.print("error all10\n")
txt.print("\nyou should see no errors printed above (only at first run).")
}
}

View File

@ -1,924 +0,0 @@
%target cx16
%import cx16textio
%zeropage basicsafe
main {
sub start() {
ubyte A
txt.print("ubyte shift left\n")
A = shiftlb0()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb1()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb2()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb3()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb4()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb5()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb6()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb7()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb8()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb9()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("ubyte shift right\n")
A = shiftrb0()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb1()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb2()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb3()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb4()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb5()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb6()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb7()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb8()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb9()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("signed byte shift left\n")
byte signedb
signedb = shiftlsb0()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb1()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb2()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb3()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb4()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb5()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb6()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb7()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb8()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb9()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("signed byte shift right\n")
signedb = shiftrsb0()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb1()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb2()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb3()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb4()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb5()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb6()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb7()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb8()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb9()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("uword shift left\n")
uword uw
uw = shiftluw0()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw1()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw2()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw3()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw4()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw5()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw6()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw7()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw8()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw9()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw10()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw11()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw12()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw13()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw14()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw15()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw16()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw17()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("uword shift right\n")
uw = shiftruw0()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw1()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw2()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw3()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw4()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw5()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw6()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw7()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw8()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw9()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw10()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw11()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw12()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw13()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw14()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw15()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw16()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw17()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("signed word shift left\n")
word sw
sw = shiftlsw0()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw1()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw2()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw3()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw4()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw5()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw6()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw7()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw8()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw9()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw10()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw11()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw12()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw13()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw14()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw15()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw16()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw17()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("signed word shift right\n")
sw = shiftrsw0()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw1()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw2()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw3()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw4()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw5()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw6()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw7()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw8()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw9()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw10()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw11()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw12()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw13()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw14()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw15()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw16()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw17()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
}
sub shiftruw0() -> uword {
uword q = $a49f
return q >> 0
}
sub shiftruw1() -> uword {
uword q = $a49f
return q >> 1
}
sub shiftruw2() -> uword {
uword q = $a49f
return q >> 2
}
sub shiftruw3() -> uword {
uword q = $a49f
return q >> 3
}
sub shiftruw4() -> uword {
uword q = $a49f
return q >> 4
}
sub shiftruw5() -> uword {
uword q = $a49f
return q >> 5
}
sub shiftruw6() -> uword {
uword q = $a49f
return q >> 6
}
sub shiftruw7() -> uword {
uword q = $a49f
return q >> 7
}
sub shiftruw8() -> uword {
uword q = $a49f
return (q >> 8)
}
sub shiftruw9() -> uword {
uword q = $a49f
return (q >> 9)
}
sub shiftruw10() -> uword {
uword q = $a49f
return (q >> 10)
}
sub shiftruw11() -> uword {
uword q = $a49f
return (q >> 11)
}
sub shiftruw12() -> uword {
uword q = $a49f
return (q >> 12)
}
sub shiftruw13() -> uword {
uword q = $a49f
return (q >> 13)
}
sub shiftruw14() -> uword {
uword q = $a49f
return (q >> 14)
}
sub shiftruw15() -> uword {
uword q = $a49f
return (q >> 15)
}
sub shiftruw16() -> uword {
uword q = $a49f
return (q >> 16)
}
sub shiftruw17() -> uword {
uword q = $a49f
return (q >> 17)
}
sub shiftrsw0() -> word {
word q = -12345
return q >> 0
}
sub shiftrsw1() -> word {
word q = -12345
return q >> 1
}
sub shiftrsw2() -> word {
word q = -12345
return q >> 2
}
sub shiftrsw3() -> word {
word q = -12345
return q >> 3
}
sub shiftrsw4() -> word {
word q = -12345
return q >> 4
}
sub shiftrsw5() -> word {
word q = -12345
return q >> 5
}
sub shiftrsw6() -> word {
word q = -12345
return q >> 6
}
sub shiftrsw7() -> word {
word q = -12345
return q >> 7
}
sub shiftrsw8() -> word {
word q = -12345
return (q >> 8)
}
sub shiftrsw9() -> word {
word q = -12345
return (q >> 9)
}
sub shiftrsw10() -> word {
word q = -12345
return (q >> 10)
}
sub shiftrsw11() -> word {
word q = -12345
return (q >> 11)
}
sub shiftrsw12() -> word {
word q = -12345
return (q >> 12)
}
sub shiftrsw13() -> word {
word q = -12345
return (q >> 13)
}
sub shiftrsw14() -> word {
word q = -12345
return (q >> 14)
}
sub shiftrsw15() -> word {
word q = -12345
return (q >> 15)
}
sub shiftrsw16() -> word {
word q = -12345
return (q >> 16)
}
sub shiftrsw17() -> word {
word q = -12345
return (q >> 17)
}
sub shiftluw0() -> uword {
uword q = $a49f
return q << 0
}
sub shiftluw1() -> uword {
uword q = $a49f
return q << 1
}
sub shiftluw2() -> uword {
uword q = $a49f
return q << 2
}
sub shiftluw3() -> uword {
uword q = $a49f
return q << 3
}
sub shiftluw4() -> uword {
uword q = $a49f
return q << 4
}
sub shiftluw5() -> uword {
uword q = $a49f
return q << 5
}
sub shiftluw6() -> uword {
uword q = $a49f
return q << 6
}
sub shiftluw7() -> uword {
uword q = $a49f
return q << 7
}
sub shiftluw8() -> uword {
uword q = $a49f
return q << 8
}
sub shiftluw9() -> uword {
uword q = $a49f
return q << 9
}
sub shiftluw10() -> uword {
uword q = $a49f
return q << 10
}
sub shiftluw11() -> uword {
uword q = $a49f
return q << 11
}
sub shiftluw12() -> uword {
uword q = $a49f
return q << 12
}
sub shiftluw13() -> uword {
uword q = $a49f
return q << 13
}
sub shiftluw14() -> uword {
uword q = $a49f
return q << 14
}
sub shiftluw15() -> uword {
uword q = $a49f
return q << 15
}
sub shiftluw16() -> uword {
uword q = $a49f
return q << 16
}
sub shiftluw17() -> uword {
uword q = $a49f
return q << 17
}
sub shiftlsw0() -> word {
word q = -12345
return q << 0
}
sub shiftlsw1() -> word {
word q = -12345
return q << 1
}
sub shiftlsw2() -> word {
word q = -12345
return q << 2
}
sub shiftlsw3() -> word {
word q = -12345
return q << 3
}
sub shiftlsw4() -> word {
word q = -12345
return q << 4
}
sub shiftlsw5() -> word {
word q = -12345
return q << 5
}
sub shiftlsw6() -> word {
word q = -12345
return q << 6
}
sub shiftlsw7() -> word {
word q = -12345
return q << 7
}
sub shiftlsw8() -> word {
word q = -12345
return q << 8
}
sub shiftlsw9() -> word {
word q = -12345
return q << 9
}
sub shiftlsw10() -> word {
word q = -12345
return q << 10
}
sub shiftlsw11() -> word {
word q = -12345
return q << 11
}
sub shiftlsw12() -> word {
word q = -12345
return q << 12
}
sub shiftlsw13() -> word {
word q = -12345
return q << 13
}
sub shiftlsw14() -> word {
word q = -12345
return q << 14
}
sub shiftlsw15() -> word {
word q = -12345
return q << 15
}
sub shiftlsw16() -> word {
word q = -12345
return q << 16
}
sub shiftlsw17() -> word {
word q = -12345
return q << 17
}
sub shiftlb0() -> ubyte {
ubyte yy=$ed
return yy << 0
}
sub shiftlb1() -> ubyte {
ubyte yy=$ed
return yy << 1
}
sub shiftlb2() -> ubyte {
ubyte yy=$ed
return yy << 2
}
sub shiftlb3() -> ubyte {
ubyte yy=$ed
return yy << 3
}
sub shiftlb4() -> ubyte {
ubyte yy=$ed
return yy << 4
}
sub shiftlb5() -> ubyte {
ubyte yy=$ed
return yy << 5
}
sub shiftlb6() -> ubyte {
ubyte yy=$ed
return yy << 6
}
sub shiftlb7() -> ubyte {
ubyte yy=$ed
return yy << 7
}
sub shiftlb8() -> ubyte {
ubyte yy=$ed
return yy << 8
}
sub shiftlb9() -> ubyte {
ubyte yy=$ed
return yy << 9
}
sub shiftrb0() -> ubyte {
ubyte yy=$ed
return yy >> 0
}
sub shiftrb1() -> ubyte {
ubyte yy=$ed
return yy >> 1
}
sub shiftrb2() -> ubyte {
ubyte yy=$ed
return yy >> 2
}
sub shiftrb3() -> ubyte {
ubyte yy=$ed
return yy >> 3
}
sub shiftrb4() -> ubyte {
ubyte yy=$ed
return yy >> 4
}
sub shiftrb5() -> ubyte {
ubyte yy=$ed
return yy >> 5
}
sub shiftrb6() -> ubyte {
ubyte yy=$ed
return yy >> 6
}
sub shiftrb7() -> ubyte {
ubyte yy=$ed
return yy >> 7
}
sub shiftrb8() -> ubyte {
ubyte yy=$ed
return yy >> 8
}
sub shiftrb9() -> ubyte {
ubyte yy=$ed
return yy >> 9
}
sub shiftlsb0() -> byte {
byte yy=-123
return yy << 0
}
sub shiftlsb1() -> byte {
byte yy=-123
return yy << 1
}
sub shiftlsb2() -> byte {
byte yy=-123
return yy << 2
}
sub shiftlsb3() -> byte {
byte yy=-123
return yy << 3
}
sub shiftlsb4() -> byte {
byte yy=-123
return yy << 4
}
sub shiftlsb5() -> byte {
byte yy=-123
return yy << 5
}
sub shiftlsb6() -> byte {
byte yy=-123
return yy << 6
}
sub shiftlsb7() -> byte {
byte yy=-123
return yy << 7
}
sub shiftlsb8() -> byte {
byte yy=-123
return yy << 8
}
sub shiftlsb9() -> byte {
byte yy=-123
return yy << 9
}
sub shiftrsb0() -> byte {
byte yy=-123
return yy >> 0
}
sub shiftrsb1() -> byte {
byte yy=-123
return yy >> 1
}
sub shiftrsb2() -> byte {
byte yy=-123
return yy >> 2
}
sub shiftrsb3() -> byte {
byte yy=-123
return yy >> 3
}
sub shiftrsb4() -> byte {
byte yy=-123
return yy >> 4
}
sub shiftrsb5() -> byte {
byte yy=-123
return yy >> 5
}
sub shiftrsb6() -> byte {
byte yy=-123
return yy >> 6
}
sub shiftrsb7() -> byte {
byte yy=-123
return yy >> 7
}
sub shiftrsb8() -> byte {
byte yy=-123
return yy >> 8
}
sub shiftrsb9() -> byte {
byte yy=-123
return yy >> 9
}
}

View File

@ -1,104 +0,0 @@
%target cx16
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
div_ubyte(0, 1, 0)
div_ubyte(100, 6, 16)
div_ubyte(255, 2, 127)
div_byte(0, 1, 0)
div_byte(100, -6, -16)
div_byte(127, -2, -63)
div_uword(0,1,0)
div_uword(40000,500,80)
div_uword(43211,2,21605)
div_word(0,1,0)
div_word(-20000,500,-40)
div_word(-2222,2,-1111)
div_float(0,1,0)
div_float(999.9,111.0,9.008108108108107)
}
sub div_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1/a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" / ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub div_byte(byte a1, byte a2, byte c) {
byte r = a1/a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("byte ")
txt.print_b(a1)
txt.print(" / ")
txt.print_b(a2)
txt.print(" = ")
txt.print_b(r)
c64.CHROUT('\n')
}
sub div_uword(uword a1, uword a2, uword c) {
uword r = a1/a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" / ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
sub div_word(word a1, word a2, word c) {
word r = a1/a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("word ")
txt.print_w(a1)
txt.print(" / ")
txt.print_w(a2)
txt.print(" = ")
txt.print_w(r)
c64.CHROUT('\n')
}
sub div_float(float a1, float a2, float c) {
float r = a1/a2
if abs(r-c)<0.00001
txt.print(" ok ")
else
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
txt.print(" / ")
c64flt.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -1,112 +0,0 @@
%target cx16
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
minus_ubyte(0, 0, 0)
minus_ubyte(200, 0, 200)
minus_ubyte(200, 100, 100)
minus_ubyte(100, 200, 156)
minus_byte(0, 0, 0)
minus_byte(100, 100, 0)
minus_byte(50, -50, 100)
minus_byte(0, -30, 30)
minus_byte(-30, 0, -30)
minus_uword(0,0,0)
minus_uword(50000,0, 50000)
minus_uword(50000,20000,30000)
minus_uword(20000,50000,35536)
minus_word(0,0,0)
minus_word(1000,1000,0)
minus_word(-1000,1000,-2000)
minus_word(1000,500,500)
minus_word(0,-3333,3333)
minus_word(-3333,0,-3333)
minus_float(0,0,0)
minus_float(2.5,1.5,1.0)
minus_float(-1.5,3.5,-5.0)
}
sub minus_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1-a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" - ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub minus_byte(byte a1, byte a2, byte c) {
byte r = a1-a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("byte ")
txt.print_b(a1)
txt.print(" - ")
txt.print_b(a2)
txt.print(" = ")
txt.print_b(r)
c64.CHROUT('\n')
}
sub minus_uword(uword a1, uword a2, uword c) {
uword r = a1-a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" - ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
sub minus_word(word a1, word a2, word c) {
word r = a1-a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("word ")
txt.print_w(a1)
txt.print(" - ")
txt.print_w(a2)
txt.print(" = ")
txt.print_w(r)
c64.CHROUT('\n')
}
sub minus_float(float a1, float a2, float c) {
float r = a1-a2
if abs(r-c)<0.00001
txt.print(" ok ")
else
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
txt.print(" - ")
c64flt.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -1,106 +0,0 @@
%target cx16
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
mul_ubyte(0, 0, 0)
mul_ubyte(20, 1, 20)
mul_ubyte(20, 10, 200)
mul_byte(0, 0, 0)
mul_byte(10, 10, 100)
mul_byte(5, -5, -25)
mul_byte(0, -30, 0)
mul_uword(0,0,0)
mul_uword(50000,1, 50000)
mul_uword(500,100,50000)
mul_word(0,0,0)
mul_word(-10,1000,-10000)
mul_word(1,-3333,-3333)
mul_float(0,0,0)
mul_float(2.5,10,25)
mul_float(-1.5,10,-15)
}
sub mul_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1*a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" * ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub mul_byte(byte a1, byte a2, byte c) {
byte r = a1*a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("byte ")
txt.print_b(a1)
txt.print(" * ")
txt.print_b(a2)
txt.print(" = ")
txt.print_b(r)
c64.CHROUT('\n')
}
sub mul_uword(uword a1, uword a2, uword c) {
uword r = a1*a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" * ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
sub mul_word(word a1, word a2, word c) {
word r = a1*a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("word ")
txt.print_w(a1)
txt.print(" * ")
txt.print_w(a2)
txt.print(" = ")
txt.print_w(r)
c64.CHROUT('\n')
}
sub mul_float(float a1, float a2, float c) {
float r = a1*a2
if abs(r-c)<0.00001
txt.print(" ok ")
else
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
txt.print(" * ")
c64flt.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -1,110 +0,0 @@
%target cx16
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
plus_ubyte(0, 0, 0)
plus_ubyte(0, 200, 200)
plus_ubyte(100, 200, 44)
plus_byte(0, 0, 0)
plus_byte(-100, 100, 0)
plus_byte(-50, 100, 50)
plus_byte(0, -30, -30)
plus_byte(-30, 0, -30)
plus_uword(0,0,0)
plus_uword(0,50000,50000)
plus_uword(50000,20000,4464)
plus_word(0,0,0)
plus_word(-1000,1000,0)
plus_word(-500,1000,500)
plus_word(0,-3333,-3333)
plus_word(-3333,0,-3333)
plus_float(0,0,0)
plus_float(1.5,2.5,4.0)
plus_float(-1.5,3.5,2.0)
plus_float(-1.1,3.3,2.2)
}
sub plus_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1+a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" + ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub plus_byte(byte a1, byte a2, byte c) {
byte r = a1+a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("byte ")
txt.print_b(a1)
txt.print(" + ")
txt.print_b(a2)
txt.print(" = ")
txt.print_b(r)
c64.CHROUT('\n')
}
sub plus_uword(uword a1, uword a2, uword c) {
uword r = a1+a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" + ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
sub plus_word(word a1, word a2, word c) {
word r = a1+a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("word ")
txt.print_w(a1)
txt.print(" + ")
txt.print_w(a2)
txt.print(" = ")
txt.print_w(r)
c64.CHROUT('\n')
}
sub plus_float(float a1, float a2, float c) {
float r = a1+a2
if abs(r-c)<0.00001
txt.print(" ok ")
else
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
txt.print(" + ")
c64flt.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -1,141 +0,0 @@
%target cx16
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
txt.plot(0,24)
ubyte Y
ubyte ub=200
byte bb=-100
uword uw = 2000
word ww = -1000
float fl = 999.99
ubyte[3] ubarr = 200
byte[3] barr = -100
uword[3] uwarr = 2000
word[3] warr = -1000
float[3] flarr = 999.99
txt.print("++\n")
ub++
bb++
uw++
ww++
fl++
ubarr[1]++
barr[1]++
uwarr[1]++
warr[1]++
flarr[1] ++
check_ub(ub, 201)
Y=100
Y++
check_ub(Y, 101)
check_fl(fl, 1000.99)
check_b(bb, -99)
check_uw(uw, 2001)
check_w(ww, -999)
check_ub(ubarr[0], 200)
check_fl(flarr[0], 999.99)
check_b(barr[0], -100)
check_uw(uwarr[0], 2000)
check_w(warr[0], -1000)
check_ub(ubarr[1], 201)
check_fl(flarr[1], 1000.99)
check_b(barr[1], -99)
check_uw(uwarr[1], 2001)
check_w(warr[1], -999)
txt.print("--\n")
ub--
bb--
uw--
ww--
fl--
ubarr[1]--
barr[1]--
uwarr[1]--
warr[1]--
flarr[1] --
check_ub(ub, 200)
Y=100
Y--
check_ub(Y, 99)
check_fl(fl, 999.99)
check_b(bb, -100)
check_uw(uw, 2000)
check_w(ww, -1000)
check_ub(ubarr[1], 200)
check_fl(flarr[1], 999.99)
check_b(barr[1], -100)
check_uw(uwarr[1], 2000)
check_w(warr[1], -1000)
}
sub check_ub(ubyte value, ubyte expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" ubyte ")
txt.print_ub(value)
c64.CHROUT(',')
txt.print_ub(expected)
c64.CHROUT('\n')
}
sub check_b(byte value, byte expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" byte ")
txt.print_b(value)
c64.CHROUT(',')
txt.print_b(expected)
c64.CHROUT('\n')
}
sub check_uw(uword value, uword expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" uword ")
txt.print_uw(value)
c64.CHROUT(',')
txt.print_uw(expected)
c64.CHROUT('\n')
}
sub check_w(word value, word expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" word ")
txt.print_w(value)
c64.CHROUT(',')
txt.print_w(expected)
c64.CHROUT('\n')
}
sub check_fl(float value, float expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" float ")
c64flt.print_f(value)
c64.CHROUT(',')
c64flt.print_f(expected)
c64.CHROUT('\n')
}
}

View File

@ -1,48 +0,0 @@
%target cx16
%import cx16textio
%zeropage basicsafe
main {
sub start() {
remainder_ubyte(0, 1, 0)
remainder_ubyte(100, 6, 4)
remainder_ubyte(255, 2, 1)
remainder_ubyte(255, 20, 15)
remainder_uword(0,1,0)
remainder_uword(40000,511,142)
remainder_uword(40000,500,0)
remainder_uword(43211,12,11)
}
sub remainder_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1%a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" % ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub remainder_uword(uword a1, uword a2, uword c) {
uword r = a1%a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" % ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
}

View File

@ -1,132 +0,0 @@
%target cx16
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
byte b1
byte b2
ubyte ub1
ubyte ub2
word w1
word w2
uword uw1
uword uw2
float f1
float f2
b1 = 10
b2 = 10
if sgn(b2-b1) != 0
txt.print("sgn1 error1\n")
b1 = -100
b2 = -100
if sgn(b2-b1) != 0
txt.print("sgn1 error2\n")
ub1 = 200
ub2 = 200
if sgn(ub2-ub1) != 0
txt.print("sgn1 error3\n")
w1 = 100
w2 = 100
if sgn(w2-w1) != 0
txt.print("sgn1 error4\n")
w1 = -2000
w2 = -2000
if sgn(w2-w1) != 0
txt.print("sgn1 error5\n")
uw1 = 999
uw2 = 999
if sgn(uw2-uw1) != 0
txt.print("sgn1 error6\n")
f1 = 3.45
f2 = 3.45
if sgn(f2-f1) != 0
txt.print("sgn1 error7\n")
; -1
b1 = 11
b2 = 10
if sgn(b2-b1) != -1
txt.print("sgn2 error1\n")
b1 = -10
b2 = -100
if sgn(b2-b1) != -1
txt.print("sgn2 error2\n")
ub1 = 202
ub2 = 200
if sgn(ub2 as byte - ub1 as byte) != -1
txt.print("sgn2 error3\n")
w1 = 101
w2 = 100
if sgn(w2-w1) != -1
txt.print("sgn2 error4\n")
w1 = -200
w2 = -2000
if sgn(w2-w1) != -1
txt.print("sgn2 error5\n")
uw1 = 2222
uw2 = 999
if sgn((uw2 as word) - (uw1 as word)) != -1
txt.print("sgn2 error6a\n")
if sgn(uw2 - uw1) != 1 ; always 0 or 1 if unsigned
txt.print("sgn2 error6b\n")
f1 = 3.45
f2 = 1.11
if sgn(f2-f1) != -1
txt.print("sgn2 error7\n")
; +1
b1 = 11
b2 = 20
if sgn(b2-b1) != 1
txt.print("sgn3 error1\n")
b1 = -10
b2 = -1
if sgn(b2-b1) != 1
txt.print("sgn3 error2\n")
ub1 = 202
ub2 = 205
if sgn(ub2-ub1) != 1
txt.print("sgn3 error3\n")
w1 = 101
w2 = 200
if sgn(w2-w1) != 1
txt.print("sgn3 error4\n")
w1 = -200
w2 = -20
if sgn(w2-w1) != 1
txt.print("sgn3 error5\n")
uw1 = 2222
uw2 = 9999
if sgn(uw2-uw1) != 1
txt.print("sgn3 error6\n")
f1 = 3.45
f2 = 5.11
if sgn(f2-f1) != 1
txt.print("sgn3 error7\n")
txt.print("should see no sgn errors\n")
}
}

View File

@ -1,5 +1,5 @@
%target cx16
%import cx16lib
%import syslib
%import conv
; TODO add all other Elite's ships, show their name, advance to next ship on keypress

View File

@ -1,110 +0,0 @@
%target cx16
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
const uword width = 80
const uword height = 60
; vertices
float[] xcoor = [ -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0 ]
float[] ycoor = [ -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0 ]
float[] zcoor = [ -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ]
; storage for rotated coordinates
float[len(xcoor)] rotatedx=0.0
float[len(ycoor)] rotatedy=0.0
float[len(zcoor)] rotatedz=-1.0
sub start() {
float time=0.0
ubyte timer_jiffies
repeat {
rotate_vertices(time)
txt.clear_screenchars(' ')
draw_edges()
time+=0.1
txt.plot(0,0)
txt.print("3d cube! (floating point calc) ")
%asm {{
phx
jsr c64.RDTIM ; A/X/Y
sta timer_jiffies
lda #0
jsr c64.SETTIM
plx
}}
txt.print_ub(timer_jiffies)
txt.print(" jiffies/fr = ")
txt.print_ub(60/timer_jiffies)
txt.print(" fps")
}
}
sub rotate_vertices(float t) {
; rotate around origin (0,0,0)
; set up the 3d rotation matrix values
float cosa = cos(t)
float sina = sin(t)
float cosb = cos(t*0.33)
float sinb = sin(t*0.33)
float cosc = cos(t*0.78)
float sinc = sin(t*0.78)
float cosa_sinb = cosa*sinb
float sina_sinb = sina*sinb
float Axx = cosa*cosb
float Axy = cosa_sinb*sinc - sina*cosc
float Axz = cosa_sinb*cosc + sina*sinc
float Ayx = sina*cosb
float Ayy = sina_sinb*sinc + cosa*cosc
float Ayz = sina_sinb*cosc - cosa*sinc
float Azx = -sinb
float Azy = cosb*sinc
float Azz = cosb*cosc
ubyte @zp i
for i in 0 to len(xcoor)-1 {
rotatedx[i] = Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i]
rotatedy[i] = Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i]
rotatedz[i] = Azx*xcoor[i] + Azy*ycoor[i] + Azz*zcoor[i]
}
}
sub draw_edges() {
; plot the points of the 3d cube
; first the points on the back, then the points on the front (painter algorithm)
ubyte @zp i
float rz
float persp
ubyte sx
ubyte sy
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz >= 0.1 {
persp = (5.0+rz)/(height as float)
sx = rotatedx[i] / persp + width/2.0 as ubyte
sy = rotatedy[i] / persp + height/2.0 as ubyte
txt.setcc(sx, sy, 46, 1)
}
}
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz < 0.1 {
persp = (5.0+rz)/(height as float)
sx = rotatedx[i] / persp + width/2.0 as ubyte
sy = rotatedy[i] / persp + height/2.0 as ubyte
txt.setcc(sx, sy, 81, 1)
}
}
}
}

View File

@ -1,11 +1,8 @@
%target cx16
%import cx16textio
%import textio
main {
const uword screen_width = 80
const uword screen_height = 60
; vertices
word[] xcoor = [ -40, -40, -40, -40, 40, 40, 40, 40 ]
word[] ycoor = [ -40, -40, 40, 40, -40, -40, 40, 40 ]
@ -80,9 +77,9 @@ main {
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz >= 10 {
persp = 500 + rz/64
sx = rotatedx[i] / persp as byte + screen_width/2
sy = rotatedy[i] / persp as byte + screen_height/2
persp = 400 + rz/64
sx = rotatedx[i] / persp as byte + txt.DEFAULT_WIDTH/2
sy = rotatedy[i] / persp as byte + txt.DEFAULT_HEIGHT/2
txt.setcc(sx as ubyte, sy as ubyte, 46, 7)
}
}
@ -90,9 +87,9 @@ main {
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz < 10 {
persp = 500 + rz/64
sx = rotatedx[i] / persp as byte + screen_width/2
sy = rotatedy[i] / persp as byte + screen_height/2
persp = 400 + rz/64
sx = rotatedx[i] / persp as byte + txt.DEFAULT_WIDTH/2
sy = rotatedy[i] / persp as byte + txt.DEFAULT_HEIGHT/2
txt.setcc(sx as ubyte, sy as ubyte, 81, 7)
}
}

View File

@ -1,8 +1,7 @@
; CommanderX16 text datetime example!
; make sure to compile with the cx16 compiler target.
%target cx16
%import cx16textio
%import textio
%zeropage basicsafe
main {

View File

@ -1,6 +1,6 @@
%target cx16
%import cx16textio
%import cx16flt
%import textio
%import floats
%zeropage basicsafe
main {

View File

@ -1,6 +1,6 @@
%target cx16
%import cx16textio
%import cx16flt
%import textio
%import floats
%zeropage basicsafe
main {
@ -33,7 +33,6 @@ main {
ysquared = y*y
iter++
}
; txt.setchr(pixelx, pixely, '*')
txt.color2(1, max_iter-iter)
c64.CHROUT(' ')
}

View File

@ -1,65 +0,0 @@
%target cx16
%import cx16textio
%import conv
%zeropage basicsafe
; The classic number guessing game.
; TODO this code is identical to the C64 one except the imports
main {
sub start() {
str name = "????????????????????????????????????????"
str input = "??????????"
ubyte secretnumber = rnd() % 99 + 1 ; random number 1..100
ubyte attempts_left
txt.lowercase()
txt.print("Please introduce yourself: ")
void txt.input_chars(name)
txt.print("\n\nHello, ")
txt.print(name)
txt.print(".\nLet's play a number guessing game.\nI am thinking of a number from 1 to 100!You'll have to guess it!\n")
for attempts_left in 10 downto 1 {
txt.print("\nYou have ")
txt.print_ub(attempts_left)
txt.print(" guess")
if attempts_left>1
txt.print("es")
txt.print(" left.\nWhat is your next guess? ")
void txt.input_chars(input)
ubyte guess = lsb(conv.str2uword(input))
if guess==secretnumber {
ending(true)
return
} else {
txt.print("\n\nThat is too ")
if guess<secretnumber
txt.print("low!\n")
else
txt.print("high!\n")
}
}
ending(false)
return
sub ending(ubyte success) {
if success
txt.print("\n\nYou guessed it, impressive!\n")
else {
txt.print("\nToo bad! My number was: ")
txt.print_ub(secretnumber)
txt.print(".\n")
}
txt.print("Thanks for playing, ")
txt.print(name)
txt.print(".\n")
}
}
}

View File

@ -1,5 +1,4 @@
; CommanderX16 simple graphics example!
; make sure to compile with the cx16 compiler target.
%target cx16
%zeropage basicsafe

View File

@ -1,28 +0,0 @@
%target cx16
%import cx16textio
%import cx16flt
%zeropage basicsafe
main {
const uword width = 80
const uword height = 60
struct Ball {
float t
ubyte color
}
sub start() {
Ball ball
repeat {
ubyte xx=(sin(ball.t) * width/2.1) + width/2.0 as ubyte
ubyte yy=(cos(ball.t*1.1356) * height/2.1) + height/2.0 as ubyte
txt.setcc(xx, yy, 81, ball.color)
ball.t += 0.05
ball.color++
}
}
}

View File

@ -1,27 +0,0 @@
%target cx16
%import cx16textio
%zeropage basicsafe
; TODO this code is identical to the c64 one except the import
main {
const uword screenwidth = txt.DEFAULT_WIDTH
const uword screenheight = txt.DEFAULT_HEIGHT
struct Ball {
uword anglex
uword angley
ubyte color
}
sub start() {
Ball ball
repeat {
ubyte x = msb(sin8u(msb(ball.anglex)) * screenwidth)
ubyte y = msb(cos8u(msb(ball.angley)) * screenheight)
txt.setcc(x, y, 81, ball.color)
ball.anglex+=366
ball.angley+=291
ball.color++
}
}
}

View File

@ -1,7 +1,8 @@
%import c64textio
%import textio
%zeropage basicsafe
; This example computes the first 20 values of the Fibonacci sequence.
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,8 +1,9 @@
%import c64lib
%import c64textio
%import c64flt
%import syslib
%import textio
%import floats
%zeropage basicsafe
; TODO use RDTIM() to get the time and make this system agnostic
main {
@ -32,11 +33,11 @@ main {
clock_seconds = floor(clock_seconds - minutes * 60.0)
txt.print("system time in ti$ is ")
c64flt.print_f(hours)
floats.print_f(hours)
c64.CHROUT(':')
c64flt.print_f(minutes)
floats.print_f(minutes)
c64.CHROUT(':')
c64flt.print_f(clock_seconds)
floats.print_f(clock_seconds)
c64.CHROUT('\n')
txt.print("bye!\n")

View File

@ -1,4 +1,6 @@
%import c64graphics
%import graphics
; TODO make graphics lib cross-system
main {

View File

@ -1,7 +1,8 @@
%import c64lib
%import c64textio
%import textio
%import syslib
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {

View File

@ -1,11 +1,13 @@
%import c64graphics
%import c64flt
%import graphics
%import floats
%zeropage floatsafe
; Draw a mandelbrot in graphics mode (the image will be 256 x 200 pixels).
; NOTE: this will take an eternity to draw on a real c64.
; even in Vice in warp mode (700% speed on my machine) it's slow, but you can see progress
; TODO make graphics lib cross-system
main {
const ubyte width = 255
const ubyte height = 200

View File

@ -1,8 +1,10 @@
%import c64lib
%import c64textio
%import c64flt
%import syslib
%import textio
%import floats
%zeropage basicsafe
; TODO use RDTIM() to get the time and make this system agnostic
main {
const uword width = 30
const uword height = 20
@ -46,7 +48,7 @@ main {
+ 65536.0*(c64.TIME_HI as float))/60.0
txt.plot(0, 21)
txt.print("finished in ")
c64flt.print_f(duration)
floats.print_f(duration)
txt.print(" seconds!\n")
}
}

View File

@ -1,10 +1,9 @@
%import c64textio
%import textio
%import conv
%zeropage basicsafe
; The classic number guessing game.
; TODO this code is identical to the commanderx16 one except the imports
; Note: this program is compatible with C64 and CX16.
main {

View File

@ -1,5 +1,6 @@
%import c64lib
%import c64textio
%target c64
%import syslib
%import textio
;/*****************************************************************************\

View File

@ -1,6 +1,8 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
ubyte[256] sieve
@ -20,10 +22,10 @@ main {
txt.print(", ")
amount++
}
c64.CHROUT('\n')
txt.chrout('\n')
txt.print("number of primes (expected 54): ")
txt.print_ub(amount)
c64.CHROUT('\n')
txt.chrout('\n')
}

View File

@ -1,4 +1,5 @@
%import c64lib
%target c64
%import syslib
main {

View File

@ -1,94 +0,0 @@
%import c64flt
%zeropage basicsafe
main {
sub start() {
print_rom_floats_values()
c64.CHROUT('\n')
print_rom_floats()
c64.CHROUT('\n')
}
sub print_rom_floats() {
c64flt.FL_PIVAL=9.9999
c64flt.print_f(c64flt.FL_PIVAL)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_N32768)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_FONE)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_SQRHLF)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_SQRTWO)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_NEGHLF)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_LOG2)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_TENC)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_NZMIL)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_FHALF)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_LOGEB2)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_PIHALF)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_TWOPI)
c64.CHROUT('\n')
c64flt.print_f(c64flt.FL_FR4)
c64.CHROUT('\n')
}
sub print_rom_floats_values() {
; these are all floating point constants defined in the ROM so no allocation required
; the compiler recognises these and will substitute the ROM values automatically
c64flt.print_f(3.141592653589793)
c64.CHROUT('\n')
c64flt.print_f(-32768.0)
c64.CHROUT('\n')
c64flt.print_f( 1.0)
c64.CHROUT('\n')
c64flt.print_f(0.7071067811865476)
c64.CHROUT('\n')
c64flt.print_f(1.4142135623730951)
c64.CHROUT('\n')
c64flt.print_f( -0.5)
c64.CHROUT('\n')
c64flt.print_f(0.6931471805599453)
c64.CHROUT('\n')
c64flt.print_f(10.0)
c64.CHROUT('\n')
c64flt.print_f(1.0e9)
c64.CHROUT('\n')
c64flt.print_f(0.5)
c64.CHROUT('\n')
c64flt.print_f(1.4426950408889634)
c64.CHROUT('\n')
c64flt.print_f(1.5707963267948966)
c64.CHROUT('\n')
c64flt.print_f(6.283185307179586)
c64.CHROUT('\n')
c64flt.print_f(0.25)
c64.CHROUT('\n')
c64flt.print_f(0.0)
c64.CHROUT('\n')
}
}

View File

@ -1,7 +1,8 @@
%import c64lib
%import c64textio
%target c64
%import textio
%zeropage basicsafe
; TODO use setcc instead of poking screen ram directly to make this cross-system
main {

View File

@ -1,7 +1,8 @@
%import c64lib
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {
@ -40,28 +41,28 @@ main {
word ww
for ub in uba {
txt.print_ub(ub)
c64.CHROUT(',')
txt.chrout(',')
}
c64.CHROUT('\n')
txt.chrout('\n')
for uw in uwa {
txt.print_uw(uw)
c64.CHROUT(',')
txt.chrout(',')
}
c64.CHROUT('\n')
txt.chrout('\n')
for bb in ba {
txt.print_b(bb)
c64.CHROUT(',')
txt.chrout(',')
}
c64.CHROUT('\n')
txt.chrout('\n')
for ww in wa {
txt.print_w(ww)
c64.CHROUT(',')
txt.chrout(',')
}
c64.CHROUT('\n')
c64.CHROUT('\n')
txt.chrout('\n')
txt.chrout('\n')
}
}
}

View File

@ -1,5 +1,6 @@
%import c64textio
%import c64lib
%target c64
%import textio
%import syslib
%zeropage basicsafe

View File

@ -1,31 +0,0 @@
%import c64textio
%zeropage basicsafe
main {
struct Color {
ubyte red
ubyte green
ubyte blue
}
sub start() {
Color purple = [255, 0, 255]
Color other
other = purple
other.red /= 2
other.green = 10 + other.green / 2
other.blue = 99
txt.print_ub(other.red)
c64.CHROUT(',')
txt.print_ub(other.green)
c64.CHROUT(',')
txt.print_ub(other.blue)
c64.CHROUT('\n')
}
}

View File

@ -1,11 +1,11 @@
%import c64textio
%import c64flt
%import textio
%import floats
%zeropage floatsafe
; Note: this program is compatible with C64 and CX16.
main {
const uword width = 40
const uword height = 25
struct Ball {
float t
ubyte color
@ -16,8 +16,8 @@ main {
Ball ball
repeat {
ubyte xx=(sin(ball.t) * width/2.1) + width/2.0 as ubyte
ubyte yy=(cos(ball.t*1.1356) * height/2.1) + height/2.0 as ubyte
ubyte xx=(sin(ball.t) * txt.DEFAULT_WIDTH/2.1) + txt.DEFAULT_WIDTH/2.0 as ubyte
ubyte yy=(cos(ball.t*1.1356) * txt.DEFAULT_HEIGHT/2.1) + txt.DEFAULT_HEIGHT/2.0 as ubyte
txt.setcc(xx, yy, 81, ball.color)
ball.t += 0.08
ball.color++

View File

@ -1,7 +1,7 @@
%import c64textio
%import textio
%zeropage basicsafe
; TODO this code is identical to the commanderx16 one except the import
; Note: this program is compatible with C64 and CX16.
main {
const uword screenwidth = txt.DEFAULT_WIDTH

View File

@ -7,8 +7,9 @@
; staged speed increase
; some simple sound effects
%import c64lib
%import c64textio
%target c64
%import syslib
%import textio
main {

View File

@ -1,10 +1,8 @@
;%import c64lib
;%import c64graphics
;%import c64textio
%import c64flt
;%option enable_floats
%target cx16
%import cx16textio
%target c64
%import syslib
%import graphics
%import textio
%import floats
%zeropage basicsafe

View File

@ -1,8 +1,10 @@
%import c64textio
%import c64flt
%import textio
%import floats
%zeropage basicsafe
%option enable_floats
; Note: this program is compatible with C64 and CX16.
main {
; this is only a parser/compiler test, there's no actual working program

View File

@ -1,6 +1,8 @@
%import c64textio
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
sub start() {

View File

@ -1,5 +1,9 @@
%import c64flt
%import c64graphics
%target c64
%import floats
%import graphics
; TODO FIX OUTPUT when Optimizer is enabled (it's ok when compiling without optimization)
main {

View File

@ -1,4 +1,5 @@
%import c64lib
%target c64
%import syslib
%zeropage basicsafe