diff vmcmd.c @ 15:74aee0b81da0 src

only one bits function now.
author jcdutton
date Wed, 10 Apr 2002 13:33:12 +0000
parents 1a214a94a80d
children 0e2abe7083de
line wrap: on
line diff
--- 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 */