From e659b91c4dbff141a6a5e5d6c5072eac551c92bc Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 23 May 2022 21:01:02 +0200 Subject: [PATCH] vm: fix storezm/storezx instructions --- .../prog8/codegen/virtual/AssignmentGen.kt | 4 +-- docs/source/todo.rst | 1 + examples/test.p8 | 28 +++++++------------ virtualmachine/src/prog8/vm/VirtualMachine.kt | 7 +++-- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/codeGenVirtual/src/prog8/codegen/virtual/AssignmentGen.kt b/codeGenVirtual/src/prog8/codegen/virtual/AssignmentGen.kt index e9c4c01b6..0651f4d6c 100644 --- a/codeGenVirtual/src/prog8/codegen/virtual/AssignmentGen.kt +++ b/codeGenVirtual/src/prog8/codegen/virtual/AssignmentGen.kt @@ -163,11 +163,11 @@ internal class AssignmentGen(private val codeGen: CodeGen, private val expressio if(zero) { if(fixedIndex!=null) { variableAddr += fixedIndex*itemsize - code += VmCodeInstruction(Opcode.STOREZM, VmDataType.FLOAT, value=variableAddr) + code += VmCodeInstruction(Opcode.STOREZM, vmDt, value=variableAddr) } else { val indexReg = codeGen.vmRegisters.nextFree() code += loadIndexReg(array, itemsize, indexReg) - code += VmCodeInstruction(Opcode.STOREZX, VmDataType.FLOAT, reg1=indexReg, value=variableAddr) + code += VmCodeInstruction(Opcode.STOREZX, vmDt, reg1=indexReg, value=variableAddr) } } else { if(vmDt== VmDataType.FLOAT) { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 56aed5396..c09dd1fdf 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,6 +3,7 @@ TODO For next release ^^^^^^^^^^^^^^^^ +- vm: fix primes.p8 calculating wrong primes ... diff --git a/examples/test.p8 b/examples/test.p8 index 89fb056a9..b678ccdc8 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,8 +1,5 @@ %import textio -%import math -%import string -%import floats -%zeropage dontuse +%zeropage basicsafe ; NOTE: meant to test to virtual machine output target (use -target vitual) @@ -34,22 +31,17 @@ main { sub start() { ; mcCarthy() - - ubyte @shared bb = %10110001 - byte @shared sb = -99 - bb *= 2 - bb /= 2 - bb *= 8 - bb /= 8 - txt.print_ub(bb) ; 17 + ubyte[256] sieve + ubyte xx + for xx in 0 to 255 { + sieve[xx] = false + } + for xx in 0 to 255 { + txt.print_ub(sieve[xx]) + txt.spc() + } txt.nl() - sb *= 2 - sb /= 2 - sb *= 8 - sb /= 8 - txt.print_b(sb) ; -3 - txt.nl() ; ; a "pixelshader": ; sys.gfx_enable(0) ; enable lo res screen diff --git a/virtualmachine/src/prog8/vm/VirtualMachine.kt b/virtualmachine/src/prog8/vm/VirtualMachine.kt index 5e55f8679..41a755b07 100644 --- a/virtualmachine/src/prog8/vm/VirtualMachine.kt +++ b/virtualmachine/src/prog8/vm/VirtualMachine.kt @@ -630,10 +630,11 @@ class VirtualMachine(val memory: Memory, program: List) { } private fun InsINCM(i: Instruction) { + val address = i.value!! when(i.type!!) { - VmDataType.BYTE -> memory.setUB(i.value!!, (memory.getUB(i.value)+1u).toUByte()) - VmDataType.WORD -> memory.setUW(i.value!!, (memory.getUW(i.value)+1u).toUShort()) - VmDataType.FLOAT -> memory.setFloat(i.value!!, memory.getFloat(i.value)+1f) + VmDataType.BYTE -> memory.setUB(address, (memory.getUB(address)+1u).toUByte()) + VmDataType.WORD -> memory.setUW(address, (memory.getUW(address)+1u).toUShort()) + VmDataType.FLOAT -> memory.setFloat(address, memory.getFloat(address)+1f) } pc++ }