diff --git a/codeGenVirtual/src/prog8/codegen/virtual/ExpressionGen.kt b/codeGenVirtual/src/prog8/codegen/virtual/ExpressionGen.kt index c61c6d34b..94ebc1073 100644 --- a/codeGenVirtual/src/prog8/codegen/virtual/ExpressionGen.kt +++ b/codeGenVirtual/src/prog8/codegen/virtual/ExpressionGen.kt @@ -6,6 +6,7 @@ import prog8.code.ast.* import prog8.code.core.* import prog8.vm.Instruction import prog8.vm.Opcode +import prog8.vm.Syscall import prog8.vm.VmDataType @@ -360,6 +361,17 @@ internal class ExpressionGen(val codeGen: CodeGen) { "lsb" -> { code += translateExpression(call.args.single(), resultRegister, regUsage) } + "memory" -> { + val name = (call.args[0] as PtString).value + val size = (call.args[1] as PtNumber).number.toUInt() + val align = (call.args[2] as PtNumber).number.toUInt() + TODO("Memory($name, $size, $align)") + } + "rnd" -> { + code += VmCodeInstruction(Instruction(Opcode.SYSCALL, value=Syscall.RND.ordinal)) + if(resultRegister!=0) + code += VmCodeInstruction(Instruction(Opcode.LOADR, VmDataType.BYTE, reg1=resultRegister, reg2=0)) + } else -> { // TODO builtin functions... TODO("builtinfunc ${call.name}") diff --git a/compiler/res/prog8lib/virtual/textio.p8 b/compiler/res/prog8lib/virtual/textio.p8 index 6ef2dd38c..ca9f14715 100644 --- a/compiler/res/prog8lib/virtual/textio.p8 +++ b/compiler/res/prog8lib/virtual/textio.p8 @@ -19,6 +19,14 @@ sub spc() { txt.chrout(' ') } +sub lowercase() { + ; not supported +} + +sub uppercase() { + ; not supported +} + sub chrout(ubyte char) { syscall1(2, char) } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 67f23043a..92e8fc8ce 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,6 +3,9 @@ TODO For next release ^^^^^^^^^^^^^^^^ +- adapt to new(?) addresses in cx16 math library https://github.com/commanderx16/x16-docs/blob/master/Commander%20X16%20Programmer's%20Reference%20Guide.md#math-library + also fix calls to FPWRT etc as suggested there + ... diff --git a/examples/fibonacci.p8 b/examples/fibonacci.p8 index ab7b3222c..7b8b602ed 100644 --- a/examples/fibonacci.p8 +++ b/examples/fibonacci.p8 @@ -10,7 +10,7 @@ main { repeat 21 { txt.print_uw(fib_next()) - c64.CHROUT('\n') + txt.nl() } } diff --git a/virtualmachine/src/prog8/vm/SysCalls.kt b/virtualmachine/src/prog8/vm/SysCalls.kt index 0bf05379f..ab54849b1 100644 --- a/virtualmachine/src/prog8/vm/SysCalls.kt +++ b/virtualmachine/src/prog8/vm/SysCalls.kt @@ -1,6 +1,7 @@ package prog8.vm import kotlin.math.min +import kotlin.random.Random /* SYSCALLS: @@ -16,6 +17,7 @@ SYSCALLS: 8 = gfx_enable ; enable graphics window r0.b = 0 -> lores 320x240, r0.b = 1 -> hires 640x480 9 = gfx_clear ; clear graphics window with shade in r0.b 10 = gfx_plot ; plot pixel in graphics window, r0.w/r1.w contain X and Y coordinates, r2.b contains brightness +11 = rnd ; random BYTE */ enum class Syscall { @@ -29,7 +31,8 @@ enum class Syscall { SLEEP, GFX_ENABLE, GFX_CLEAR, - GFX_PLOT + GFX_PLOT, + RND } object SysCalls { @@ -76,6 +79,9 @@ object SysCalls { Syscall.GFX_ENABLE -> vm.gfx_enable() Syscall.GFX_CLEAR -> vm.gfx_clear() Syscall.GFX_PLOT -> vm.gfx_plot() + Syscall.RND -> { + vm.registers.setB(0, (Random.nextInt() ushr 3).toUByte()) + } } } }