]> www.vanbest.org Git - sasc-ng.git/commitdiff
nagra 0101/0501: cleanup map handling
authorleslie <unknown>
Thu, 7 Feb 2008 18:11:03 +0000 (19:11 +0100)
committerleslie <unknown>
Thu, 7 Feb 2008 18:11:03 +0000 (19:11 +0100)
systems/nagra/nagra2-0101.c
systems/nagra/nagra2-0501.c
systems/nagra/nagra2.c
systems/nagra/nagra2.h

index aa4b14e705c9dfb61d162429bbc1bd6c9fbb9b4a..42b3fbe3bfd943e52e69d3343c93bb1192064fb1 100644 (file)
@@ -420,6 +420,7 @@ void cMap0101::MakePrime(BIGNUM *n, unsigned char *residues)
 void cMap0101::DoMap(int f, unsigned char *data, int l)
 {
   PRINTF(L_SYS_MAP,"0101: calling function %02X",f);
+  l=GetOpSize(l);
   cycles=0;
   switch(f) {
     case 0x22:
@@ -446,14 +447,13 @@ void cMap0101::DoMap(int f, unsigned char *data, int l)
       }
       break; 
     case 0x3b:
-      if(!l) l=wordsize;
       MonInit(wordsize*60+4*l);
       I.GetLE(data,l<<3);
       MonMul(B,I,B,l);
       break;
     case 0x3e:
       {
-      I.GetLE(data,(l?l:wordsize)<<3);
+      I.GetLE(data,l<<3);
       BN_mod_exp(B,A,I,D,ctx);
       BN_one(A);
       int end=BN_num_bits(I);
@@ -465,7 +465,6 @@ void cMap0101::DoMap(int f, unsigned char *data, int l)
       }
     case 0x4d:
       if(-0x018000==l)
-        //for(int i=64; i<(wordsize<<6); i++) BN_clear_bit(B,i);
         BN_mask_bits(B,64);
       else {
         BN_set_bit(B,(wordsize<<6)-1);
@@ -715,41 +714,42 @@ bool cN2Prov0101::RomInit(void)
 bool cN2Prov0101::ProcessMap(int f)
 {
   unsigned short addr;
-  int size=wordsize<<3;
   unsigned char tmp[256];
+  int l=GetOpSize(Get(0x48));
+  int dl=l<<3;
 
   switch(f) {
-    case SETSIZE: // set map size 
+    case SETSIZE:
       DoMap(f,0,Get(0x48));
-      if((wordsize<<3)>256) {
-        PRINTF(L_SYS_EMU,"%04x: MAP word size too large: %d",id,wordsize);
-        return false;
-        }
+      AddCycles(MapCycles());
       break;
-    case IMPORT_J: //Import Ram at [44:45] to Map Registers A-E, E is 0x03 the rest in sequence
+    case IMPORT_J:
     case IMPORT_A:
     case IMPORT_B:
     case IMPORT_C:
     case IMPORT_D:
     case IMPORT_LAST:
       addr=HILO(0x44);
-      GetMem(addr,tmp,size,0); DoMap(f,tmp);
+      GetMem(addr,tmp,dl,0); DoMap(f,tmp,l);
+      AddCycles(MapCycles());
       break;
-    case EXPORT_J: //Export Registers A-E with 44:45: 0x09 is E
+    case EXPORT_J:
     case EXPORT_A:
     case EXPORT_B:
     case EXPORT_C:
     case EXPORT_D:
     case EXPORT_LAST:
       addr=HILO(0x44);
-      DoMap(f,tmp); SetMem(addr,tmp,size,0);
+      DoMap(f,tmp,l); SetMem(addr,tmp,dl,0);
+      AddCycles(MapCycles());
       break;
-    case SWAP_A: //Swap Registers A-D with 44:45
+    case SWAP_A:
     case SWAP_B:
     case SWAP_C:
     case SWAP_D:
       addr=HILO(0x44);
-      GetMem(addr,tmp,size,0); DoMap(f,tmp); SetMem(addr,tmp,size,0);
+      GetMem(addr,tmp,dl,0); DoMap(f,tmp,l); SetMem(addr,tmp,dl,0);
+      AddCycles(MapCycles());
       break;
     case CLEAR_A:
     case CLEAR_B:
@@ -761,15 +761,16 @@ bool cN2Prov0101::ProcessMap(int f)
     case COPY_C_A:
     case COPY_C_D:
     case COPY_D_C:
-      DoMap(f); break;
+      DoMap(f);
+      AddCycles(MapCycles());
+      break;
     case 0x22:
       DoMap(f,tmp,-((Get(0x48)<<16)|(Get(0x49)<<8)|Get(0x4a)));
       AddCycles(MapCycles());
       break;
     case 0x3b:
-      size=Get(0x48); if(!size) size=wordsize;
-      GetMem(HILO(0x44),tmp,size<<3,0);
-      DoMap(f,tmp,size);
+      GetMem(HILO(0x44),tmp,dl,0);
+      DoMap(f,tmp,l);
       break;
     case 0x29:
       DoMap(f,tmp,-Get(0x48));
@@ -777,8 +778,8 @@ bool cN2Prov0101::ProcessMap(int f)
       AddCycles(MapCycles());
       break;
     case 0x3e:
-      GetMem(HILO(0x44),tmp,size,0);
-      DoMap(f,tmp,Get(0x48));
+      GetMem(HILO(0x44),tmp,dl,0);
+      DoMap(f,tmp,l);
       AddCycles(MapCycles());
       break;
     case 0x43:
@@ -791,7 +792,7 @@ bool cN2Prov0101::ProcessMap(int f)
       break;
     case 0x45:
       GetMem(0x400,tmp,64,0);
-      DoMap(f,tmp,Get(0x48));
+      DoMap(f,tmp,l);
       SetMem(0x440,tmp,20,0);
       break; 
     case 0x4d:
index 9faab7225a3a83fa83dea998b43d137cfb7df3d4..8f112febc4b710e4af17b6f665afdb223b8f13eb 100644 (file)
@@ -45,7 +45,7 @@ void cMap0501::DoMap(int f, unsigned char *data, int l)
   cycles=0;
   switch(f) {
     case 0x37:
-      l=(l?l:wordsize)<<3;
+      l=GetOpSize(l)<<3;
       B.GetLE(data,l);
       MonMul(B,B,A);
       break;
@@ -134,42 +134,41 @@ bool cN2Prov0501::RomInit(void)
 bool cN2Prov0501::ProcessMap(int f)
 {
   unsigned short addr;
-  int size;
   unsigned char tmp[256];
+  int l=GetOpSize(Get(0x48));
 
   switch(f) {
-    case SETSIZE: // set map size 
+    case SETSIZE:
       DoMap(f,0,Get(0x48));
-      if((wordsize<<3)>256) {
-        PRINTF(L_SYS_EMU,"%04x: MAP word size too large: %d",id,wordsize);
-        return false;
-        }
+      AddCycles(MapCycles());
       break;
-    case IMPORT_J: //Import Ram at [44:45] to Map Registers A-E, E is 0x03 the rest in sequence
+    case IMPORT_J:
     case IMPORT_A:
     case IMPORT_B:
     case IMPORT_C:
     case IMPORT_D:
     case IMPORT_LAST:
-      addr=HILO(0x44); size=Get(0x48);
-      GetMem(addr,tmp,size<<3,0); DoMap(f,tmp,size);
+      addr=HILO(0x44);
+      GetMem(addr,tmp,l<<3,0); DoMap(f,tmp,l);
       AddCycles(MapCycles());
       break;
-    case EXPORT_J: //Export Registers A-E with 44:45: 0x09 is E
+    case EXPORT_J:
     case EXPORT_A:
     case EXPORT_B:
     case EXPORT_C:
     case EXPORT_D:
     case EXPORT_LAST:
-      addr=HILO(0x44); size=Get(0x48);
-      DoMap(f,tmp,size); SetMem(addr,tmp,size<<3,0);
+      addr=HILO(0x44);
+      DoMap(f,tmp,l); SetMem(addr,tmp,l<<3,0);
+      AddCycles(MapCycles());
       break;
-    case SWAP_A: //Swap Registers A-D with 44:45
+    case SWAP_A:
     case SWAP_B:
     case SWAP_C:
     case SWAP_D:
-      addr=HILO(0x44); size=Get(0x48);
-      GetMem(addr,tmp,size<<3,0); DoMap(f,tmp,size); SetMem(addr,tmp,size<<3,0);
+      addr=HILO(0x44);
+      GetMem(addr,tmp,l<<3,0); DoMap(f,tmp,l); SetMem(addr,tmp,l<<3,0);
+      AddCycles(MapCycles());
       break;
     case CLEAR_A:
     case CLEAR_B:
@@ -181,9 +180,10 @@ bool cN2Prov0501::ProcessMap(int f)
     case COPY_C_A:
     case COPY_C_D:
     case COPY_D_C:
-      DoMap(f); break;
+      DoMap(f);
+      AddCycles(MapCycles());
+      break;
     default:
-      PRINTF(L_SYS_EMU,"%04x: map call %02x not emulated",id,f);
       return false;
     }
   return true;
index 1d223f234386c12f554a21dc4ca174fe44e2f6cd..fcfad1e031a50aae840c719a8f7a414404364af5 100644 (file)
@@ -446,9 +446,14 @@ void cMapCore::CurveInit(BIGNUM *a)
   MonMul(s160,B,a);
 }
 
+int cMapCore::GetOpSize(int l)
+{
+  return l!=0 ? l : wordsize;
+}
+
 bool cMapCore::DoMap(int f, unsigned char *data, int l)
 {
-  const int l1=l?l:wordsize;
+  const int l1=GetOpSize(l);
   const int dl=l1<<3;
   cycles=0;
   switch(f) {
index db94f3f18aac36b8a6e5202815784b24988bd878..3aa60bf3d5bb56241f0ac4887806ac27382a29c5 100644 (file)
@@ -178,6 +178,7 @@ protected:
   void ToAffine(void);
   void CurveInit(BIGNUM *a);
   //
+  int GetOpSize(int l);
   bool DoMap(int f, unsigned char *data=0, int l=0);
   unsigned int MapCycles() { return cycles; }
 public: