changeset 15:74aee0b81da0 src

only one bits function now.
author jcdutton
date Wed, 10 Apr 2002 13:33:12 +0000
parents ebf344d11bde
children 46fbd218a689
files decoder.c decoder.h vmcmd.c
diffstat 3 files changed, 142 insertions(+), 172 deletions(-) [+]
line wrap: on
line diff
--- a/decoder.c	Wed Apr 10 13:09:40 2002 +0000
+++ b/decoder.c	Wed Apr 10 13:33:12 2002 +0000
@@ -35,16 +35,7 @@
 #include "vmcmd.h"
 #include "decoder.h"
 
-typedef struct
-{
-  uint64_t instruction;
-  uint64_t examined;
-  registers_t *registers;
-} command_t;
-
-static uint32_t new_bits(command_t* command, int32_t start, int32_t count);
-
-static uint32_t new_bits(command_t *command, int32_t start, int32_t count) {
+uint32_t vm_getbits(command_t *command, int start, int count) {
   uint64_t result = 0;
   uint64_t bit_mask=0xffffffffffffffff;  /* I could put -1 instead */
   uint64_t examining = 0;
@@ -56,7 +47,7 @@
        (start > 63) ||
        (count < 0) ||
        (start < 0) ){
-    fprintf(stderr, "Bad call to new_bits. Parameter out of range\n");
+    fprintf(stderr, "Bad call to vm_getbits. Parameter out of range\n");
     assert(0);
   }
   bit_mask >>= start;
@@ -82,9 +73,9 @@
    lower eight bits for the system or general purpose register. */
 static uint16_t eval_reg_or_data(command_t* command, int32_t imm, int32_t byte) {
   if(imm) { /*  immediate */
-    return new_bits(command, (byte*8), 16);
+    return vm_getbits(command, (byte*8), 16);
   } else {
-    return eval_reg(command, new_bits(command, ((byte + 1)*8), 8));
+    return eval_reg(command, vm_getbits(command, ((byte + 1)*8), 8));
   }
 }
 
@@ -94,9 +85,9 @@
 /* Evaluates gprm or data depending on bit, data is in byte n */
 uint16_t eval_reg_or_data_2(command_t* command, int32_t imm, int32_t byte) {
   if(imm) /* immediate */
-    return new_bits(command, ((byte*8)+1), 7);
+    return vm_getbits(command, ((byte*8)+1), 7);
   else
-    return command->registers->GPRM[new_bits(command, ((byte*8)+4), 4)];
+    return command->registers->GPRM[vm_getbits(command, ((byte*8)+4), 4)];
 }
 
 
@@ -127,10 +118,10 @@
 /* Evaluate if version 1.
    Has comparison data in byte 3 and 4-5 (immediate or register) */
 static int32_t eval_if_version_1(command_t* command) {
-  uint8_t op = new_bits(command, 9, 3);
+  uint8_t op = vm_getbits(command, 9, 3);
   if(op) {
-    return eval_compare(op, eval_reg(command, new_bits(command, 24, 8)), 
-                            eval_reg_or_data(command, new_bits(command, 8, 1), 4));
+    return eval_compare(op, eval_reg(command, vm_getbits(command, 24, 8)), 
+                            eval_reg_or_data(command, vm_getbits(command, 8, 1), 4));
   }
   return 1;
 }
@@ -138,10 +129,10 @@
 /* Evaluate if version 2.
    This version only compares register which are in byte 6 and 7 */
 static int32_t eval_if_version_2(command_t* command) {
-  uint8_t op = new_bits(command, 9, 3);
+  uint8_t op = vm_getbits(command, 9, 3);
   if(op) {
-    return eval_compare(op, eval_reg(command, new_bits(command, 48, 8)), 
-                            eval_reg(command, new_bits(command, 56, 8)));
+    return eval_compare(op, eval_reg(command, vm_getbits(command, 48, 8)), 
+                            eval_reg(command, vm_getbits(command, 56, 8)));
   }
   return 1;
 }
@@ -149,10 +140,10 @@
 /* Evaluate if version 3.
    Has comparison data in byte 2 and 6-7 (immediate or register) */
 static int32_t eval_if_version_3(command_t* command) {
-  uint8_t op = new_bits(command, 9, 3);
+  uint8_t op = vm_getbits(command, 9, 3);
   if(op) {
-    return eval_compare(op, eval_reg(command, new_bits(command, 16, 8)), 
-                            eval_reg_or_data(command, new_bits(command, 8, 1), 6));
+    return eval_compare(op, eval_reg(command, vm_getbits(command, 16, 8)), 
+                            eval_reg_or_data(command, vm_getbits(command, 8, 1), 6));
   }
   return 1;
 }
@@ -161,10 +152,10 @@
    Has comparison data in byte 1 and 4-5 (immediate or register) 
    The register in byte 1 is only the lowe nibble (4 bits) */
 static int32_t eval_if_version_4(command_t* command) {
-  uint8_t op = new_bits(command, 9, 3);
+  uint8_t op = vm_getbits(command, 9, 3);
   if(op) {
-    return eval_compare(op, eval_reg(command, new_bits(command, 12, 4)), 
-                            eval_reg_or_data(command, new_bits(command, 8, 1), 4));
+    return eval_compare(op, eval_reg(command, vm_getbits(command, 12, 4)), 
+                            eval_reg_or_data(command, vm_getbits(command, 8, 1), 4));
   }
   return 1;
 }
@@ -174,20 +165,20 @@
 static int32_t eval_special_instruction(command_t* command, int32_t cond) {
   int32_t line, level;
   
-  switch(new_bits(command, 12, 4)) {
+  switch(vm_getbits(command, 12, 4)) {
     case 0: /*  NOP */
       line = 0;
       return cond ? line : 0;
     case 1: /*  Goto line */
-      line = new_bits(command, 56, 8);
+      line = vm_getbits(command, 56, 8);
       return cond ? line : 0;
     case 2: /*  Break */
       /*  max number of rows < 256, so we will end this set */
       line = 256;
       return cond ? 256 : 0;
     case 3: /*  Set temporary parental level and goto */
-      line = new_bits(command, 56, 8); 
-      level = new_bits(command, 52, 4);
+      line = vm_getbits(command, 56, 8); 
+      level = vm_getbits(command, 52, 4);
       if(cond) {
 	/*  This always succeeds now, if we want real parental protection */
 	/*  we need to ask the user and have passwords and stuff. */
@@ -202,8 +193,8 @@
    Return 1 if link, or 0 if no link
    Actual link instruction is in return_values parameter */
 static int32_t eval_link_subins(command_t* command, int32_t cond, link_t *return_values) {
-  uint16_t button = new_bits(command, 48, 6);
-  uint8_t  linkop = new_bits(command, 59, 5);
+  uint16_t button = vm_getbits(command, 48, 6);
+  uint8_t  linkop = vm_getbits(command, 59, 5);
   
   if(linkop > 0x10)
     return 0;    /*  Unknown Link by Sub-Instruction command */
@@ -219,29 +210,29 @@
    Return 1 if link, or 0 if no link
    Actual link instruction is in return_values parameter */
 static int32_t eval_link_instruction(command_t* command, int32_t cond, link_t *return_values) {
-  uint8_t op = new_bits(command, 12, 4);
+  uint8_t op = vm_getbits(command, 12, 4);
   
   switch(op) {
     case 1:
 	return eval_link_subins(command, cond, return_values);
     case 4:
 	return_values->command = LinkPGCN;
-	return_values->data1   = new_bits(command, 49, 15);
+	return_values->data1   = vm_getbits(command, 49, 15);
 	return cond;
     case 5:
 	return_values->command = LinkPTTN;
-	return_values->data1 = new_bits(command, 54, 10);
-	return_values->data2 = new_bits(command, 48, 6);
+	return_values->data1 = vm_getbits(command, 54, 10);
+	return_values->data2 = vm_getbits(command, 48, 6);
 	return cond;
     case 6:
 	return_values->command = LinkPGN;
-	return_values->data1 = new_bits(command, 57, 7);
-	return_values->data2 = new_bits(command, 48, 6);
+	return_values->data1 = vm_getbits(command, 57, 7);
+	return_values->data2 = vm_getbits(command, 48, 6);
 	return cond;
     case 7:
 	return_values->command = LinkCN;
-	return_values->data1 = new_bits(command, 56, 8);
-	return_values->data2 = new_bits(command, 48, 6);
+	return_values->data1 = vm_getbits(command, 56, 8);
+	return_values->data2 = vm_getbits(command, 48, 6);
 	return cond;
   }
   return 0;
@@ -253,64 +244,64 @@
    actual jump instruction is in return_values parameter */
 static int32_t eval_jump_instruction(command_t* command, int32_t cond, link_t *return_values) {
   
-  switch(new_bits(command, 12, 4)) {
+  switch(vm_getbits(command, 12, 4)) {
     case 1:
       return_values->command = Exit;
       return cond;
     case 2:
       return_values->command = JumpTT;
-      return_values->data1 = new_bits(command, 41, 7);
+      return_values->data1 = vm_getbits(command, 41, 7);
       return cond;
     case 3:
       return_values->command = JumpVTS_TT;
-      return_values->data1 = new_bits(command, 41, 7);
+      return_values->data1 = vm_getbits(command, 41, 7);
       return cond;
     case 5:
       return_values->command = JumpVTS_PTT;
-      return_values->data1 = new_bits(command, 41, 7);
-      return_values->data2 = new_bits(command, 22, 10);
+      return_values->data1 = vm_getbits(command, 41, 7);
+      return_values->data2 = vm_getbits(command, 22, 10);
       return cond;
     case 6:
-      switch(new_bits(command, 40, 2)) {
+      switch(vm_getbits(command, 40, 2)) {
         case 0:
           return_values->command = JumpSS_FP;
           return cond;
         case 1:
           return_values->command = JumpSS_VMGM_MENU;
-          return_values->data1 =  new_bits(command, 44, 4);
+          return_values->data1 =  vm_getbits(command, 44, 4);
           return cond;
         case 2:
           return_values->command = JumpSS_VTSM;
-          return_values->data1 =  new_bits(command, 32, 8);
-          return_values->data2 =  new_bits(command, 24, 8);
-          return_values->data3 =  new_bits(command, 44, 4);
+          return_values->data1 =  vm_getbits(command, 32, 8);
+          return_values->data2 =  vm_getbits(command, 24, 8);
+          return_values->data3 =  vm_getbits(command, 44, 4);
           return cond;
         case 3:
           return_values->command = JumpSS_VMGM_PGC;
-          return_values->data1 =  new_bits(command, 17, 15);
+          return_values->data1 =  vm_getbits(command, 17, 15);
           return cond;
         }
       break;
     case 8:
-      switch(new_bits(command, 40, 2)) {
+      switch(vm_getbits(command, 40, 2)) {
         case 0:
           return_values->command = CallSS_FP;
-          return_values->data1 = new_bits(command, 32, 8);
+          return_values->data1 = vm_getbits(command, 32, 8);
           return cond;
         case 1:
           return_values->command = CallSS_VMGM_MENU;
-          return_values->data1 = new_bits(command, 44, 4);
-          return_values->data2 = new_bits(command, 32, 8);
+          return_values->data1 = vm_getbits(command, 44, 4);
+          return_values->data2 = vm_getbits(command, 32, 8);
           return cond;
         case 2:
           return_values->command = CallSS_VTSM;
-          return_values->data1 = new_bits(command, 44, 4);
-          return_values->data2 = new_bits(command, 32, 8);
+          return_values->data1 = vm_getbits(command, 44, 4);
+          return_values->data2 = vm_getbits(command, 32, 8);
           return cond;
         case 3:
           return_values->command = CallSS_VMGM_PGC;
-          return_values->data1 = new_bits(command, 17, 15);
-          return_values->data2 = new_bits(command, 32, 8);
+          return_values->data1 = vm_getbits(command, 17, 15);
+          return_values->data2 = vm_getbits(command, 32, 8);
           return cond;
       }
       break;
@@ -324,11 +315,11 @@
   int32_t i;
   uint16_t data, data2;
   
-  switch(new_bits(command, 4, 4)) {
+  switch(vm_getbits(command, 4, 4)) {
     case 1: /*  Set system reg 1 &| 2 &| 3 (Audio, Subp. Angle) */
       for(i = 1; i <= 3; i++) {
-        if(new_bits(command, ((2 + i)*8), 1)) {
-          data = eval_reg_or_data_2(command, new_bits(command, 3, 1), 2 + i);
+        if(vm_getbits(command, ((2 + i)*8), 1)) {
+          data = eval_reg_or_data_2(command, vm_getbits(command, 3, 1), 2 + i);
           if(cond) {
             command->registers->SPRM[i] = data;
           }
@@ -336,17 +327,17 @@
       }
       break;
     case 2: /*  Set system reg 9 & 10 (Navigation timer, Title PGC number) */
-      data = eval_reg_or_data(command, new_bits(command, 3, 1), 2);
-      data2 = new_bits(command, 40, 8); /*  ?? size */
+      data = eval_reg_or_data(command, vm_getbits(command, 3, 1), 2);
+      data2 = vm_getbits(command, 40, 8); /*  ?? size */
       if(cond) {
 	command->registers->SPRM[9] = data; /*  time */
 	command->registers->SPRM[10] = data2; /*  pgcN */
       }
       break;
     case 3: /*  Mode: Counter / Register + Set */
-      data = eval_reg_or_data(command, new_bits(command, 3, 1), 2);
-      data2 = new_bits(command, 44, 4);
-      if(new_bits(command, 40, 1)) {
+      data = eval_reg_or_data(command, vm_getbits(command, 3, 1), 2);
+      data2 = vm_getbits(command, 44, 4);
+      if(vm_getbits(command, 40, 1)) {
 	fprintf(stderr, "Detected SetGPRMMD Counter!! This is unsupported.\n");
 	command->registers->GPRM_mode[data2] = 1;
       } else {
@@ -358,13 +349,13 @@
       }
       break;
     case 6: /*  Set system reg 8 (Highlighted button) */
-      data = eval_reg_or_data(command, new_bits(command, 3, 1), 4); /*  Not system reg!! */
+      data = eval_reg_or_data(command, vm_getbits(command, 3, 1), 4); /*  Not system reg!! */
       if(cond) {
 	command->registers->SPRM[8] = data;
       }
       break;
   }
-  if(new_bits(command, 12, 4)) {
+  if(vm_getbits(command, 12, 4)) {
     return eval_link_instruction(command, cond, return_values);
   }
   return 0;
@@ -428,10 +419,10 @@
 
 /* Evaluate set instruction, combined with either Link or Compare. */
 static void eval_set_version_1(command_t* command, int32_t cond) {
-  uint8_t  op   = new_bits(command, 4, 4);
-  uint8_t  reg  = new_bits(command, 28, 4); /* FIXME: This is different from vmcmd.c!!! */
-  uint8_t  reg2 = new_bits(command, 44, 4);
-  uint16_t data = eval_reg_or_data(command, new_bits(command, 3, 1), 4);
+  uint8_t  op   = vm_getbits(command, 4, 4);
+  uint8_t  reg  = vm_getbits(command, 28, 4); /* FIXME: This is different from vmcmd.c!!! */
+  uint8_t  reg2 = vm_getbits(command, 44, 4);
+  uint16_t data = eval_reg_or_data(command, vm_getbits(command, 3, 1), 4);
 
   if(cond) {
     eval_set_op(command, op, reg, reg2, data);
@@ -441,10 +432,10 @@
 
 /* Evaluate set instruction, combined with both Link and Compare. */
 static void eval_set_version_2(command_t* command, int32_t cond) {
-  uint8_t  op   = new_bits(command, 4, 4);
-  uint8_t  reg  = new_bits(command, 12, 4);
-  uint8_t  reg2 = new_bits(command, 28, 4); /* FIXME: This is different from vmcmd.c!!! */
-  uint16_t data = eval_reg_or_data(command, new_bits(command, 3, 1), 2);
+  uint8_t  op   = vm_getbits(command, 4, 4);
+  uint8_t  reg  = vm_getbits(command, 12, 4);
+  uint8_t  reg2 = vm_getbits(command, 28, 4); /* FIXME: This is different from vmcmd.c!!! */
+  uint16_t data = eval_reg_or_data(command, vm_getbits(command, 3, 1), 2);
 
   if(cond) {
     eval_set_op(command, op, reg, reg2, data);
@@ -470,7 +461,7 @@
   command.registers = registers;
   memset(return_values, 0, sizeof(link_t));
 
-  switch(new_bits(&command, 0, 3)) { /* three first old_bits */
+  switch(vm_getbits(&command, 0, 3)) { /* three first old_bits */
     case 0: /*  Special instructions */
       cond = eval_if_version_1(&command);
       res = eval_special_instruction(&command, cond);
@@ -480,7 +471,7 @@
       }
       break;
     case 1: /*  Link/jump instructions */
-      if(new_bits(&command, 3, 1)) {
+      if(vm_getbits(&command, 3, 1)) {
         cond = eval_if_version_2(&command);
         res = eval_jump_instruction(&command, cond, return_values);
       } else {
@@ -499,7 +490,7 @@
     case 3: /*  Set instructions, either Compare or Link may be used */
       cond = eval_if_version_3(&command);
       eval_set_version_1(&command, cond);
-      if(new_bits(&command, 12, 4)) {
+      if(vm_getbits(&command, 12, 4)) {
 	res = eval_link_instruction(&command, cond, return_values);
       }
       if(res)
@@ -527,7 +518,7 @@
 	res = -1;
       break;
     default: /* Unknown command */
-      fprintf(stderr, "WARNING: Unknown Command=%x\n", new_bits(&command, 0, 3));
+      fprintf(stderr, "WARNING: Unknown Command=%x\n", vm_getbits(&command, 0, 3));
   }
   /*  Check if there are bits not yet examined */
 
--- a/decoder.h	Wed Apr 10 13:09:40 2002 +0000
+++ b/decoder.h	Wed Apr 10 13:33:12 2002 +0000
@@ -88,10 +88,18 @@
   uint8_t  GPRM_mode[16];  /* Need to have some thing to indicate normal/counter mode for every GPRM */
 } registers_t;
 
+typedef struct
+{
+  uint64_t instruction;
+  uint64_t examined;
+  registers_t *registers;
+} command_t;
+
 int vmEval_CMD(vm_cmd_t commands[], int num_commands, 
 	       registers_t *registers, link_t *return_values);
 
 void vmPrint_LINK(link_t value);
 void vmPrint_registers( registers_t *registers );
+uint32_t vm_getbits(command_t* command, int start, int count);
 
 #endif /* DECODER_H_INCLUDED */
--- a/vmcmd.c	Wed Apr 10 13:09:40 2002 +0000
+++ b/vmcmd.c	Wed Apr 10 13:33:12 2002 +0000
@@ -113,35 +113,6 @@
   NULL,
 };
     
-typedef struct
-{
-  uint64_t instruction;
-  uint64_t examined;
-} command_t;
-
-static uint32_t new_bits(command_t* command, int start, int count);
-
-static uint32_t new_bits(command_t *command, int start, int count) {
-  uint64_t result = 0;
-  uint64_t bit_mask=0xffffffffffffffff;  /* I could put -1 instead */
-  uint64_t examining = 0;
-  if (count == 0) return 0;
-
-  if ( ((count+start) > 64) ||
-       (count > 32) ||
-       (start > 63) ||
-       (count < 0) ||
-       (start < 0) ){
-    fprintf(stderr, "Bad call to new_bits. Parameter out of range\n");
-    assert(0);
-  }
-  bit_mask >>= start;
-  examining = ((bit_mask >> (64-count-start)) << (64-count-start) );
-  command->examined |= examining;
-  result = (command->instruction & bit_mask) >> (64-count-start);
-  return (uint32_t) result;
-}
-
 static void print_system_reg(uint16_t reg) {
   if(reg < sizeof(system_reg_abbr_table) / sizeof(char *))
     fprintf(stderr, "%s (SRPM:%d)", system_reg_table[reg], reg);
@@ -175,97 +146,97 @@
 
 static void print_reg_or_data(command_t* command, int immediate, int byte) {
   if(immediate) {
-    int i = new_bits(command, (byte*8), 16);
+    int i = vm_getbits(command, (byte*8), 16);
     
     fprintf(stderr, "0x%x", i);
     if(isprint(i & 0xff) && isprint((i>>8) & 0xff))
       fprintf(stderr, " (\"%c%c\")", (char)((i>>8) & 0xff), (char)(i & 0xff));
   } else {
-    print_reg(new_bits(command, ((byte + 1)*8), 8));
+    print_reg(vm_getbits(command, ((byte + 1)*8), 8));
   }
 }
 
 static void print_reg_or_data_2(command_t* command, int immediate, int byte) {
   if(immediate)
-    fprintf(stderr, "0x%x", new_bits(command, ((byte*8)+1), 7));
+    fprintf(stderr, "0x%x", vm_getbits(command, ((byte*8)+1), 7));
   else
-    fprintf(stderr, "g[%" PRIu8 "]", new_bits(command, ((byte*8)+4), 4));
+    fprintf(stderr, "g[%" PRIu8 "]", vm_getbits(command, ((byte*8)+4), 4));
 }
 
 static void print_if_version_1(command_t* command) {
-  uint8_t op = new_bits(command, 9, 3);
+  uint8_t op = vm_getbits(command, 9, 3);
   
   if(op) {
     fprintf(stderr, "if (");
-    print_reg(new_bits(command,24,8));
+    print_reg(vm_getbits(command,24,8));
     print_cmp_op(op);
-    print_reg_or_data(command, new_bits(command, 8,1), 4);
+    print_reg_or_data(command, vm_getbits(command, 8,1), 4);
     fprintf(stderr, ") ");
   }
 }
 
 static void print_if_version_2(command_t* command) {
-  uint8_t op = new_bits(command, 9, 3);
+  uint8_t op = vm_getbits(command, 9, 3);
   
   if(op) {
     fprintf(stderr, "if (");
-    print_reg(new_bits(command, 48, 8));
+    print_reg(vm_getbits(command, 48, 8));
     print_cmp_op(op);
-    print_reg(new_bits(command, 56, 8));
+    print_reg(vm_getbits(command, 56, 8));
     fprintf(stderr, ") ");
   }
 }
 
 static void print_if_version_3(command_t* command) {
-  uint8_t op = new_bits(command, 9, 3);
+  uint8_t op = vm_getbits(command, 9, 3);
   
   if(op) {
     fprintf(stderr, "if (");
-    print_reg(new_bits(command, 20, 4));
+    print_reg(vm_getbits(command, 20, 4));
     print_cmp_op(op);
-    print_reg_or_data(command, new_bits(command, 8, 1), 6);
+    print_reg_or_data(command, vm_getbits(command, 8, 1), 6);
     fprintf(stderr, ") ");
   }
 }
 
 static void print_if_version_4(command_t* command) {
-  uint8_t op = new_bits(command, 9, 3);
+  uint8_t op = vm_getbits(command, 9, 3);
   
   if(op) {
     fprintf(stderr, "if (");
-    print_reg(new_bits(command, 12, 4));
+    print_reg(vm_getbits(command, 12, 4));
     print_cmp_op(op);
-    print_reg_or_data(command, new_bits(command, 8, 1), 4);
+    print_reg_or_data(command, vm_getbits(command, 8, 1), 4);
     fprintf(stderr, ") ");
   }
 }
 
 static void print_special_instruction(command_t* command) {
-  uint8_t op = new_bits(command, 12, 4);
+  uint8_t op = vm_getbits(command, 12, 4);
   
   switch(op) {
     case 0: /*  NOP */
       fprintf(stderr, "Nop");
       break;
     case 1: /*  Goto line */
-      fprintf(stderr, "Goto %" PRIu8, new_bits(command, 56, 8));
+      fprintf(stderr, "Goto %" PRIu8, vm_getbits(command, 56, 8));
       break;
     case 2: /*  Break */
       fprintf(stderr, "Break");
       break;
     case 3: /*  Parental level */
       fprintf(stderr, "SetTmpPML %" PRIu8 ", Goto %" PRIu8, 
-	      new_bits(command, 52, 4), new_bits(command, 56, 8));
+	      vm_getbits(command, 52, 4), vm_getbits(command, 56, 8));
       break;
     default:
       fprintf(stderr, "WARNING: Unknown special instruction (%i)", 
-	      new_bits(command, 12, 4));
+	      vm_getbits(command, 12, 4));
   }
 }
 
 static void print_linksub_instruction(command_t* command) {
-  int linkop = new_bits(command, 59, 5);
-  int button = new_bits(command, 48, 6);
+  int linkop = vm_getbits(command, 59, 5);
+  int button = vm_getbits(command, 48, 6);
   
   if(linkop < sizeof(link_table)/sizeof(char *) && link_table[linkop] != NULL)
     fprintf(stderr, "%s (button %" PRIu8 ")", link_table[linkop], button);
@@ -274,7 +245,7 @@
 }
 
 static void print_link_instruction(command_t* command, int optional) {
-  uint8_t op = new_bits(command, 12, 4);
+  uint8_t op = vm_getbits(command, 12, 4);
   
   if(optional && op)
     fprintf(stderr, ", ");
@@ -288,19 +259,19 @@
       print_linksub_instruction(command);
       break;
     case 4:
-      fprintf(stderr, "LinkPGCN %" PRIu16, new_bits(command, 49, 15));
+      fprintf(stderr, "LinkPGCN %" PRIu16, vm_getbits(command, 49, 15));
       break;
     case 5:
       fprintf(stderr, "LinkPTT %" PRIu16 " (button %" PRIu8 ")", 
-	      new_bits(command, 54, 10), new_bits(command, 48, 6));
+	      vm_getbits(command, 54, 10), vm_getbits(command, 48, 6));
       break;
     case 6:
       fprintf(stderr, "LinkPGN %" PRIu8 " (button %" PRIu8 ")", 
-	      new_bits(command, 57, 7), new_bits(command, 48, 6));
+	      vm_getbits(command, 57, 7), vm_getbits(command, 48, 6));
       break;
     case 7:
       fprintf(stderr, "LinkCN %" PRIu8 " (button %" PRIu8 ")", 
-	      new_bits(command, 56, 8), new_bits(command, 48, 6));
+	      vm_getbits(command, 56, 8), vm_getbits(command, 48, 6));
       break;
     default:
       fprintf(stderr, "WARNING: Unknown link instruction");
@@ -308,54 +279,54 @@
 }
 
 static void print_jump_instruction(command_t* command) {
-  switch(new_bits(command, 12, 4)) {
+  switch(vm_getbits(command, 12, 4)) {
     case 1:
       fprintf(stderr, "Exit");
       break;
     case 2:
-      fprintf(stderr, "JumpTT %" PRIu8, new_bits(command, 41, 7));
+      fprintf(stderr, "JumpTT %" PRIu8, vm_getbits(command, 41, 7));
       break;
     case 3:
-      fprintf(stderr, "JumpVTS_TT %" PRIu8, new_bits(command, 41, 7));
+      fprintf(stderr, "JumpVTS_TT %" PRIu8, vm_getbits(command, 41, 7));
       break;
     case 5:
       fprintf(stderr, "JumpVTS_PTT %" PRIu8 ":%" PRIu16, 
-	      new_bits(command, 41, 7), new_bits(command, 22, 10));
+	      vm_getbits(command, 41, 7), vm_getbits(command, 22, 10));
       break;
     case 6:
-      switch(new_bits(command, 40, 2)) {
+      switch(vm_getbits(command, 40, 2)) {
         case 0:
           fprintf(stderr, "JumpSS FP");
           break;
         case 1:
-          fprintf(stderr, "JumpSS VMGM (menu %" PRIu8 ")", new_bits(command, 44, 4));
+          fprintf(stderr, "JumpSS VMGM (menu %" PRIu8 ")", vm_getbits(command, 44, 4));
           break;
         case 2:
           fprintf(stderr, "JumpSS VTSM (vts %" PRIu8 ", title %" PRIu8 
-		  ", menu %" PRIu8 ")", new_bits(command, 32, 8), new_bits(command, 24, 8), new_bits(command, 44, 4));
+		  ", menu %" PRIu8 ")", vm_getbits(command, 32, 8), vm_getbits(command, 24, 8), vm_getbits(command, 44, 4));
           break;
         case 3:
-          fprintf(stderr, "JumpSS VMGM (pgc %" PRIu8 ")", new_bits(command, 17, 15));
+          fprintf(stderr, "JumpSS VMGM (pgc %" PRIu8 ")", vm_getbits(command, 17, 15));
           break;
         }
       break;
     case 8:
-      switch(new_bits(command, 40, 2)) {
+      switch(vm_getbits(command, 40, 2)) {
         case 0:
           fprintf(stderr, "CallSS FP (rsm_cell %" PRIu8 ")",
-              new_bits(command, 32, 8));
+              vm_getbits(command, 32, 8));
           break;
         case 1:
           fprintf(stderr, "CallSS VMGM (menu %" PRIu8 
-		  ", rsm_cell %" PRIu8 ")", new_bits(command, 44, 4), new_bits(command, 32, 8));
+		  ", rsm_cell %" PRIu8 ")", vm_getbits(command, 44, 4), vm_getbits(command, 32, 8));
           break;
         case 2:
           fprintf(stderr, "CallSS VTSM (menu %" PRIu8 
-		  ", rsm_cell %" PRIu8 ")", new_bits(command, 44, 4), new_bits(command, 32, 8));
+		  ", rsm_cell %" PRIu8 ")", vm_getbits(command, 44, 4), vm_getbits(command, 32, 8));
           break;
         case 3:
           fprintf(stderr, "CallSS VMGM (pgc %" PRIu8 ", rsm_cell %" PRIu8 ")", 
-		  new_bits(command, 17, 15), new_bits(command, 32, 8));
+		  vm_getbits(command, 17, 15), vm_getbits(command, 32, 8));
           break;
       }
       break;
@@ -367,13 +338,13 @@
 static void print_system_set(command_t* command) {
   int i;
   
-  switch(new_bits(command, 4, 4)) {
+  switch(vm_getbits(command, 4, 4)) {
     case 1: /*  Set system reg 1 &| 2 &| 3 (Audio, Subp. Angle) */
       for(i = 1; i <= 3; i++) {
-        if(new_bits(command, ((2+i)*8), 1)) {
+        if(vm_getbits(command, ((2+i)*8), 1)) {
           print_system_reg(i);
           fprintf(stderr, " = ");
-          print_reg_or_data_2(command, new_bits(command, 3, 1), 2 + i);
+          print_reg_or_data_2(command, vm_getbits(command, 3, 1), 2 + i);
           fprintf(stderr, " ");
         }
       }
@@ -381,53 +352,53 @@
     case 2: /*  Set system reg 9 & 10 (Navigation timer, Title PGC number) */
       print_system_reg(9);
       fprintf(stderr, " = ");
-      print_reg_or_data(command, new_bits(command, 3, 1), 2);
+      print_reg_or_data(command, vm_getbits(command, 3, 1), 2);
       fprintf(stderr, " ");
       print_system_reg(10);
-      fprintf(stderr, " = %" PRIu8, new_bits(command, 40, 8)); /*  ?? */
+      fprintf(stderr, " = %" PRIu8, vm_getbits(command, 40, 8)); /*  ?? */
       break;
     case 3: /*  Mode: Counter / Register + Set */
       fprintf(stderr, "SetMode ");
-      if(new_bits(command, 40, 1))
+      if(vm_getbits(command, 40, 1))
 	fprintf(stderr, "Counter ");
       else
 	fprintf(stderr, "Register ");
-      print_reg(new_bits(command, 44, 4));
+      print_reg(vm_getbits(command, 44, 4));
       print_set_op(0x1); /*  '=' */
-      print_reg_or_data(command, new_bits(command, 3, 1), 2);
+      print_reg_or_data(command, vm_getbits(command, 3, 1), 2);
       break;
     case 6: /*  Set system reg 8 (Highlighted button) */
       print_system_reg(8);
-      if(new_bits(command, 3, 1)) /*  immediate */
-        fprintf(stderr, " = 0x%x (button no %d)", new_bits(command, 32, 16), new_bits(command, 32, 6));
+      if(vm_getbits(command, 3, 1)) /*  immediate */
+        fprintf(stderr, " = 0x%x (button no %d)", vm_getbits(command, 32, 16), vm_getbits(command, 32, 6));
       else
-        fprintf(stderr, " = g[%" PRIu8 "]", new_bits(command, 44, 4));
+        fprintf(stderr, " = g[%" PRIu8 "]", vm_getbits(command, 44, 4));
       break;
     default:
       fprintf(stderr, "WARNING: Unknown system set instruction (%i)", 
-	      new_bits(command, 4, 4));
+	      vm_getbits(command, 4, 4));
   }
 }
 
 static void print_set_version_1(command_t* command) {
-  uint8_t set_op = new_bits(command, 4, 4);
+  uint8_t set_op = vm_getbits(command, 4, 4);
   
   if(set_op) {
-    print_reg(new_bits(command, 24, 8));  /* FIXME: This is different from decoder.c!!!  */
+    print_reg(vm_getbits(command, 24, 8));  /* FIXME: This is different from decoder.c!!!  */
     print_set_op(set_op);
-    print_reg_or_data(command, new_bits(command, 3, 1), 4);
+    print_reg_or_data(command, vm_getbits(command, 3, 1), 4);
   } else {
     fprintf(stderr, "NOP");
   }
 }
 
 static void print_set_version_2(command_t* command) {
-  uint8_t set_op = new_bits(command, 4, 4);
+  uint8_t set_op = vm_getbits(command, 4, 4);
   
   if(set_op) {
-    print_reg(new_bits(command, 12, 4));
+    print_reg(vm_getbits(command, 12, 4));
     print_set_op(set_op);
-    print_reg_or_data(command, new_bits(command, 3, 1), 2);
+    print_reg_or_data(command, vm_getbits(command, 3, 1), 2);
   } else {
     fprintf(stderr, "NOP");
   }
@@ -445,13 +416,13 @@
           (uint64_t) vm_command->bytes[7] ;
   command.examined = 0; 
 
-  switch(new_bits(&command,0,3)) { /* three first bits */
+  switch(vm_getbits(&command,0,3)) { /* three first bits */
     case 0: /*  Special instructions */
       print_if_version_1(&command);
       print_special_instruction(&command);
       break;
     case 1: /*  Jump/Call or Link instructions */
-      if(new_bits(&command,3,1)) {
+      if(vm_getbits(&command,3,1)) {
         print_if_version_2(&command);
         print_jump_instruction(&command);
       } else {
@@ -491,7 +462,7 @@
       print_linksub_instruction(&command);
       break;
     default:
-      fprintf(stderr, "WARNING: Unknown instruction type (%i)", new_bits(&command, 0, 3));
+      fprintf(stderr, "WARNING: Unknown instruction type (%i)", vm_getbits(&command, 0, 3));
   }
   /*  Check if there still are bits set that were not examined */