]> Chaos Git - corbenik/corbenik.git/commitdiff
Add or, xor, and not to the VM
authorchaoskagami <chaos.kagami@gmail.com>
Sun, 5 Jun 2016 03:56:56 +0000 (23:56 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sun, 5 Jun 2016 03:56:56 +0000 (23:56 -0400)
host/bytecode_asm.py
source/interp.c

index 7d67c195f7082721daf44cea4b7fe2cf7e8d41a6..2f882e15f6a6b4394b598c11df04d0c10e30d257 100755 (executable)
@@ -148,11 +148,24 @@ def parse_op(token_list, instr_offs):
 
                # We cut corners and calculate stuff manually.
                return bytearray.fromhex("09") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1])
-       elif token_list[0] == "title":
+       elif token_list[0] == "or":
                if s != 2:
                        syn_err("invalid number of arguments")
 
-               return bytearray.fromhex("0A") + bytearray([len(token_list[1]) / 2 / 8]) + bytearray.fromhex(token_list[1])
+               # We cut corners and calculate stuff manually.
+               return bytearray.fromhex("0A") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1])
+       elif token_list[0] == "xor":
+               if s != 2:
+                       syn_err("invalid number of arguments")
+
+               # We cut corners and calculate stuff manually.
+               return bytearray.fromhex("0B") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1])
+       elif token_list[0] == "not":
+               if s != 2:
+                       syn_err("invalid number of arguments")
+
+               # We cut corners and calculate stuff manually.
+               return bytearray.fromhex("09") + bytearray.fromhex(token_list[1])
 
 def pad_zero_r(x, c):
        while len(x) < c:
index 08239384ead67989c0e04d898672f5332bd64d28..646071691c888a708c117d903b6063bea68e6714 100644 (file)
 #define OP_JMP 0x07
 #define OP_REWIND 0x08
 #define OP_AND 0x09
-#define OP_TITLE 0x0A
+#define OP_OR 0x0A
+#define OP_XOR 0x0B
+#define OP_NOT 0x0C
+
 #define OP_NEXT 0xFF
 
 #ifdef LOADER
@@ -254,6 +257,47 @@ exec_bytecode(uint8_t *bytecode, uint32_t len, int debug)
                 }
                 code += *(code - 1);
                 break;
+            case OP_OR:
+                if (debug)
+                    log("or\n");
+                code += 2;
+                if (!test_was_false) {
+                    for (i = 0; i < *(code - 1); i++) {
+                        *(current_mode->memory + offset) |= code[i];
+                    }
+                    offset += *(code - 1);
+                } else {
+                    test_was_false = 0;
+                }
+                code += *(code - 1);
+                break;
+            case OP_XOR:
+                if (debug)
+                    log("xor\n");
+                code += 2;
+                if (!test_was_false) {
+                    for (i = 0; i < *(code - 1); i++) {
+                        *(current_mode->memory + offset) ^= code[i];
+                    }
+                    offset += *(code - 1);
+                } else {
+                    test_was_false = 0;
+                }
+                code += *(code - 1);
+                break;
+            case OP_NOT:
+                if (debug)
+                    log("not\n");
+                if (!test_was_false) {
+                    for (i = 0; i < *(code + 1); i++) {
+                        *(current_mode->memory + offset) = ~*(current_mode->memory + offset);
+                    }
+                    offset += *(code + 1);
+                } else {
+                    test_was_false = 0;
+                }
+                code += 2;
+                break;
             case OP_NEXT:
                 if (debug)
                     log("next\n");