working on vm

This commit is contained in:
Irmen de Jong 2022-03-27 11:48:44 +02:00
parent 0307f6b42c
commit 12712ef812
4 changed files with 56 additions and 21 deletions

View File

@ -226,15 +226,13 @@ internal class ExpressionGen(val codeGen: CodeGen) {
code += VmCodeInstruction(Instruction(Opcode.XOR, vmDt, reg1=resultRegister, reg2=leftResultReg, reg3=rightResultReg))
}
"<<" -> {
// TODO check if shift amount works
code += VmCodeInstruction(Instruction(Opcode.LSL, vmDt, reg1=resultRegister, reg2=leftResultReg, reg3=rightResultReg))
}
">>" -> {
// TODO check if shift amount works
code += VmCodeInstruction(Instruction(Opcode.LSR, vmDt, reg1=resultRegister, reg2=leftResultReg, reg3=rightResultReg))
}
"**" -> throw AssemblyError("** operator requires floating point ${binExpr.position}")
// TODO the other operators: "<<", ">>", "==", "!=", "<", ">", "<=", ">="
// TODO the other operators: "==", "!=", "<", ">", "<=", ">="
else -> TODO("operator ${binExpr.operator}")
}
return code

View File

@ -8,10 +8,35 @@ sys {
const ubyte target = 255 ; compilation target specifier. 64 = C64, 128 = C128, 16 = CommanderX16, 8 = atari800XL, 255 = virtual
; SYSCALLS
; 0 = reset ; resets system
; 1 = exit ; stops program and returns statuscode from r0.w
; 2 = print_c ; print single character
; 3 = print_s ; print 0-terminated string from memory
; 4 = print_u8 ; print unsigned int byte
; 5 = print_u16 ; print unsigned int word
; 6 = input ; reads a line of text entered by the user, r0.w = memory buffer, r1.b = maxlength (0-255, 0=unlimited). Zero-terminates the string. Returns length in r65535.w
; 7 = sleep ; sleep amount of milliseconds
; 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
const ubyte SC_RESET = 0
const ubyte SC_EXIT = 1
const ubyte SC_PRINT_C = 2
const ubyte SC_PRINT_S = 3
const ubyte SC_PRINT_U8 = 4
const ubyte SC_PRINT_u16 = 5
const ubyte SC_INPUT = 6
const ubyte SC_SLEEP = 7
const ubyte SC_GFX_ENABLE = 8
const ubyte SC_GFX_CLEAR = 9
const ubyte SC_GFX_PLOT = 10
sub reset_system() {
; Soft-reset the system back to initial power-on Basic prompt.
; TODO
syscall(SC_RESET)
}
sub wait(uword jiffies) {
@ -38,7 +63,7 @@ sys {
sub exit(ubyte returnvalue) {
; -- immediately exit the program with a return code in the A register
; TODO
syscall1(SC_EXIT, returnvalue)
}
}

View File

@ -87,14 +87,14 @@ sub print_uwhex (uword value, ubyte prefix) {
sub print_uw0 (uword value) {
; ---- print the uword value in decimal form, with left padding 0s (5 positions total)
; TODO use conv module?
ubyte tenthousands = value / 10000 as ubyte
value -= tenthousands * 10000
ubyte thousands = value / 1000 as ubyte
value -= thousands * 1000
ubyte hundreds = value / 100 as ubyte
value -= hundreds*100
ubyte tens = value / 10 as ubyte
value -= tens*10
ubyte tenthousands = (value / 10000) as ubyte
value -= 10000*tenthousands
ubyte thousands = (value / 1000) as ubyte
value -= 1000*thousands
ubyte hundreds = (value / 100) as ubyte
value -= 100 as uword * hundreds
ubyte tens = (value / 10) as ubyte
value -= 10*tens
chrout(tenthousands+'0')
chrout(thousands+'0')
chrout(hundreds+'0')
@ -104,14 +104,14 @@ sub print_uw0 (uword value) {
sub print_uw (uword value) {
; ---- print the uword in decimal form, without left padding 0s
ubyte tenthousands = value / 10000 as ubyte
value -= tenthousands * 10000
ubyte thousands = value / 1000 as ubyte
value -= thousands * 1000
ubyte hundreds = value / 100 as ubyte
value -= hundreds*100
ubyte tens = value / 10 as ubyte
value -= tens*10
ubyte tenthousands = (value / 10000) as ubyte
value -= 10000*tenthousands
ubyte thousands = (value / 1000) as ubyte
value -= 1000*thousands
ubyte hundreds = (value / 100) as ubyte
value -= 100 as uword * hundreds
ubyte tens = (value / 10) as ubyte
value -= 10*tens
if tenthousands
goto print_tenthousands
if thousands

View File

@ -6,6 +6,18 @@ main {
sub start() {
txt.clear_screen()
txt.print("Welcome to a prog8 pixel shader :-)\n")
ubyte bb = 10
uword ww = 123
bb <<= 4
ww <<= 5
txt.print("bb=")
txt.print_ub(bb)
txt.nl()
txt.print("ww=")
txt.print_uw(ww)
txt.nl()
sys.exit(99)
syscall1(8, 0) ; enable lo res creen
ubyte shifter