mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
working on vm
This commit is contained in:
parent
3b6e7eccdd
commit
5494f309c0
@ -6,6 +6,7 @@ import prog8.code.ast.*
|
|||||||
import prog8.code.core.*
|
import prog8.code.core.*
|
||||||
import prog8.vm.Instruction
|
import prog8.vm.Instruction
|
||||||
import prog8.vm.Opcode
|
import prog8.vm.Opcode
|
||||||
|
import prog8.vm.Syscall
|
||||||
import prog8.vm.VmDataType
|
import prog8.vm.VmDataType
|
||||||
|
|
||||||
|
|
||||||
@ -360,6 +361,17 @@ internal class ExpressionGen(val codeGen: CodeGen) {
|
|||||||
"lsb" -> {
|
"lsb" -> {
|
||||||
code += translateExpression(call.args.single(), resultRegister, regUsage)
|
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 -> {
|
else -> {
|
||||||
// TODO builtin functions...
|
// TODO builtin functions...
|
||||||
TODO("builtinfunc ${call.name}")
|
TODO("builtinfunc ${call.name}")
|
||||||
|
@ -19,6 +19,14 @@ sub spc() {
|
|||||||
txt.chrout(' ')
|
txt.chrout(' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub lowercase() {
|
||||||
|
; not supported
|
||||||
|
}
|
||||||
|
|
||||||
|
sub uppercase() {
|
||||||
|
; not supported
|
||||||
|
}
|
||||||
|
|
||||||
sub chrout(ubyte char) {
|
sub chrout(ubyte char) {
|
||||||
syscall1(2, char)
|
syscall1(2, char)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ TODO
|
|||||||
|
|
||||||
For next release
|
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
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ main {
|
|||||||
|
|
||||||
repeat 21 {
|
repeat 21 {
|
||||||
txt.print_uw(fib_next())
|
txt.print_uw(fib_next())
|
||||||
c64.CHROUT('\n')
|
txt.nl()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package prog8.vm
|
package prog8.vm
|
||||||
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SYSCALLS:
|
SYSCALLS:
|
||||||
@ -16,6 +17,7 @@ SYSCALLS:
|
|||||||
8 = gfx_enable ; enable graphics window r0.b = 0 -> lores 320x240, r0.b = 1 -> hires 640x480
|
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
|
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
|
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 {
|
enum class Syscall {
|
||||||
@ -29,7 +31,8 @@ enum class Syscall {
|
|||||||
SLEEP,
|
SLEEP,
|
||||||
GFX_ENABLE,
|
GFX_ENABLE,
|
||||||
GFX_CLEAR,
|
GFX_CLEAR,
|
||||||
GFX_PLOT
|
GFX_PLOT,
|
||||||
|
RND
|
||||||
}
|
}
|
||||||
|
|
||||||
object SysCalls {
|
object SysCalls {
|
||||||
@ -76,6 +79,9 @@ object SysCalls {
|
|||||||
Syscall.GFX_ENABLE -> vm.gfx_enable()
|
Syscall.GFX_ENABLE -> vm.gfx_enable()
|
||||||
Syscall.GFX_CLEAR -> vm.gfx_clear()
|
Syscall.GFX_CLEAR -> vm.gfx_clear()
|
||||||
Syscall.GFX_PLOT -> vm.gfx_plot()
|
Syscall.GFX_PLOT -> vm.gfx_plot()
|
||||||
|
Syscall.RND -> {
|
||||||
|
vm.registers.setB(0, (Random.nextInt() ushr 3).toUByte())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user