From 3ea0d1b444c9180b4dbb5d12990aac45973d2fe3 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 23 Aug 2013 21:46:40 -0500 Subject: [PATCH] Add VM opcodes NOP, LANG, and SANG - To simplify code generation genericizing, add three new opcodes * NOP: No-Operation * LANG: Load Angle - load a BAM angle into a float reg as degrees * SANG: Save Angle - store a float reg into a BEM angle, converting from degrees --- src/zscript/vmdisasm.cpp | 2 ++ src/zscript/vmexec.h | 24 ++++++++++++++++++++++++ src/zscript/vmops.h | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/src/zscript/vmdisasm.cpp b/src/zscript/vmdisasm.cpp index 35ca6aa1f..e003d1595 100644 --- a/src/zscript/vmdisasm.cpp +++ b/src/zscript/vmdisasm.cpp @@ -1,6 +1,8 @@ #include "vm.h" #include "c_console.h" +#define NOP MODE_AUNUSED | MODE_BUNUSED | MODE_CUNUSED + #define LI MODE_AI | MODE_BCJOINT | MODE_BCIMMS #define LKI MODE_AI | MODE_BCJOINT | MODE_BCKI #define LKF MODE_AF | MODE_BCJOINT | MODE_BCKF diff --git a/src/zscript/vmexec.h b/src/zscript/vmexec.h index be32dd3c1..01c0e28de 100644 --- a/src/zscript/vmexec.h +++ b/src/zscript/vmexec.h @@ -220,6 +220,16 @@ begin: GETADDR(PB,RC,X_READ_NIL); reg.f[a] = *(VM_SWORD *)ptr / 65536.0; NEXTOP; + OP(LANG): + ASSERTF(a); ASSERTA(B); ASSERTKD(C); + GETADDR(PB,KC,X_READ_NIL); + reg.f[a] = (*(VM_UWORD *)ptr >> 1) * (180.0 / 0x40000000); // BAM -> deg + NEXTOP; + OP(LANG_R): + ASSERTF(a); ASSERTA(B); ASSERTD(C); + GETADDR(PB,RC,X_READ_NIL); + reg.f[a] = (*(VM_UWORD *)ptr >> 1) * (180.0 / 0x40000000); + NEXTOP; OP(LBIT): ASSERTD(a); ASSERTA(B); GETADDR(PB,0,X_READ_NIL); @@ -326,6 +336,17 @@ begin: GETADDR(PA,RC,X_WRITE_NIL); *(VM_SWORD *)ptr = (VM_SWORD)(reg.f[B] * 65536.0); NEXTOP; + OP(SANG): + ASSERTA(a); ASSERTF(B); ASSERTKD(C); + GETADDR(PA,KC,X_WRITE_NIL); + *(VM_UWORD *)ptr = (VM_UWORD)(reg.f[B] * ((1<<30) / 180.0)) << 1; // deg -> BAM + NEXTOP; + OP(SANG_R): + ASSERTA(a); ASSERTF(B); ASSERTD(C); + GETADDR(PA,RC,X_WRITE_NIL); + *(VM_UWORD *)ptr = (VM_UWORD)(reg.f[B] * ((1<<30) / 180.0)) << 1; + NEXTOP; + OP(SBIT): ASSERTA(a); ASSERTD(B); GETADDR(PA,0,X_WRITE_NIL); @@ -1301,6 +1322,9 @@ begin: ASSERTA(B); ASSERTKA(C); CMPJMP(reg.a[B] == konsta[C].v); NEXTOP; + + OP(NOP): + NEXTOP; } } catch(VMException *exception) diff --git a/src/zscript/vmops.h b/src/zscript/vmops.h index 353dc3e85..125e5463d 100644 --- a/src/zscript/vmops.h +++ b/src/zscript/vmops.h @@ -2,6 +2,8 @@ #define xx(op, name, mode) OP_##op #endif +xx(NOP, nop, NOP), // no operation + // Load constants. xx(LI, li, LI), // load immediate signed 16-bit constant xx(LK, lk, LKI), // load integer constant @@ -35,6 +37,8 @@ xx(LV, lv, RVRPKI), // load vector xx(LV_R, lv, RVRPRI), xx(LX, lx, RFRPKI), // load fixed point xx(LX_R, lx, RFRPRI), +xx(LANG, lang, RFRPKI), // load angle +xx(LANG_R, lang, RFRPRI), xx(LBIT, lbit, RIRPI8), // rA = !!(*rB & C) -- *rB is a byte @@ -57,6 +61,8 @@ xx(SV, sv, RPRVKI), // store vector xx(SV_R, sv, RPRVRI), xx(SX, sx, RPRFKI), // store fixed point xx(SX_R, sx, RPRFRI), +xx(SANG, sang, RPRFKI), // store angle +xx(SANG_R, sang, RPRFRI), xx(SBIT, sbit, RPRII8), // *rA |= C if rB is true, *rA &= ~C otherwise