]> www.vanbest.org Git - sasc-ng.git/commitdiff
nagra: more generic map IRQ & timing API
authorleslie <unknown>
Sat, 14 Jun 2008 09:20:28 +0000 (17:20 +0800)
committerleslie <unknown>
Sat, 14 Jun 2008 09:20:28 +0000 (17:20 +0800)
systems/nagra/nagra2-0101.c
systems/nagra/nagra2-0501.c
systems/nagra/nagra2-4101.c
systems/nagra/nagra2.c
systems/nagra/nagra2.h

index 5bfb805f6f53c2c4a701fc019271a07efbf08081..764288f1a3d7ae35f37de4c48b61f9203947234b 100644 (file)
@@ -116,25 +116,17 @@ int cAuxSrv::Map(int map, unsigned char *data, int len, int outlen)
 
 // -- cMap0101 ----------------------------------------------------------------
 
-#define MAP_IRQ_BEGIN() interruptible=true; try {
-#define MAP_IRQ_END()   } catch(int) { interrupted=true; } interruptible=false;
-
 class cMap0101 : public cMapCore {
 private:
   static const unsigned char primes[];
   static const unsigned short coef22[][32];
-  bool interruptible, interrupted;
 #ifdef HAS_AUXSRV
   cAuxSrv aux;
 #endif
   //
   void MakePrime(BIGNUM *n, unsigned char *residues);
 protected:
-  void DoMap(int f, unsigned char *data=0, int l=0);
-  bool Interruptible(void) { return interruptible; }
-  bool Interrupted(void) { return interrupted; }
-public:
-  cMap0101(void) { interruptible=false; }
+  bool Map(int f, unsigned char *data, int l);
   };
 
 const unsigned char cMap0101::primes[] = {
@@ -166,15 +158,11 @@ void cMap0101::MakePrime(BIGNUM *n, unsigned char *residues)
     } while(!isPrime);
 }
 
-void cMap0101::DoMap(int f, unsigned char *data, int l)
+bool cMap0101::Map(int f, unsigned char *data, int l)
 {
-  PRINTF(L_SYS_MAP,"0101: calling function %02X",f);
   l=GetOpSize(l);
-  cycles=0; interrupted=false;
-  unsigned int startcycles=MapCycles();
   switch(f) {
     case 0x21:
-      MAP_IRQ_BEGIN();
       AddMapCycles(288);
       WS_START(1);
       MakeJ0(J,D,C);
@@ -182,7 +170,6 @@ void cMap0101::DoMap(int f, unsigned char *data, int l)
       BN_clear(C);
       WS_END();
       cycles=898;
-      MAP_IRQ_END();
       break;     
     case 0x22:
       if(BN_is_zero(D)) { cycles=639-6; break; }
@@ -352,12 +339,9 @@ void cMap0101::DoMap(int f, unsigned char *data, int l)
       break;
       }
     default:
-      if(!cMapCore::DoMap(f,data,l))
-        PRINTF(L_SYS_MAP,"0101: unsupported call %02x",f);
-      break;
+      return false;
     }
-  if(!interrupted && cycles)
-    cycles-=MapCycles()-startcycles;
+  return true;
 }
 
 // -- cN2Prov0101 --------------------------------------------------------------
@@ -401,6 +385,7 @@ cN2Prov0101::cN2Prov0101(int Id, int Flags)
   mecmAddr[0]=0x91d7; mecmAddr[1]=0x92d7; mecmKeyId=0x106;
   seedSize=10;
   desSize=16; hwMapper=0;
+  SetMapIdent(Id);
 }
 
 void cN2Prov0101::DynamicHD(unsigned char *hd, const unsigned char *ed)
@@ -652,7 +637,6 @@ bool cN2Prov0101::ProcessMap(int f)
       return false;
     }
   c6805::a=0; c6805::x=0; c6805::y=0; 
-  if(cycles>0) AddMapCycles(cycles);
   return true;
 }
 
index 1bfe95faacfbfd02dfb841a4ffd3c91dbb68c352..c15266153e8523359122348b1d70a596189e6af8 100644 (file)
 // -- cMap0501 -----------------------------------------------------------------
 
 class cMap0501 : public cMapCore {
-private:
-  int mId;
 protected:
-  void DoMap(int f, unsigned char *data=0, int l=0);
-public:
-  cMap0501(int Id);
+  bool Map(int f, unsigned char *data, int l);
   };
 
-cMap0501::cMap0501(int Id)
-{
-  mId=Id|0x100;
-}
-
-void cMap0501::DoMap(int f, unsigned char *data, int l)
+bool cMap0501::Map(int f, unsigned char *data, int l)
 {
-  PRINTF(L_SYS_MAP,"%04x: calling function %02X",mId,f);
   l=GetOpSize(l);
-  cycles=0;
   switch(f) {
     case 0x37:
       I.GetLE(data,l<<3);
       MonMul(B,I,B);
       break;
     default:
-      if(!cMapCore::DoMap(f,data,l))
-        PRINTF(L_SYS_MAP,"%04x: unsupported call %02x",mId,f);
-      break;
+      return false;
     }
+  return true;
 }
 
 // -- cN2Prov0501 --------------------------------------------------------------
@@ -81,9 +69,9 @@ static cN2ProvLinkReg<cN2Prov0501,0x0501,(N2FLAG_MECM|N2FLAG_INV|N2FLAG_Bx)> sta
 
 cN2Prov0501::cN2Prov0501(int Id, int Flags)
 :cN2Prov(Id,Flags)
-,cMap0501(Id)
 {
   hwMapper=0; hasMaprom=false;
+  SetMapIdent(Id);
 }
 
 bool cN2Prov0501::Algo(int algo, const unsigned char *hd, unsigned char *hw)
@@ -194,7 +182,6 @@ bool cN2Prov0501::ProcessMap(int f)
       PRINTF(L_SYS_EMU,"%04x: map call %02x not emulated",id,f);
       return false;
     }
-  if(cycles>0) AddMapCycles(cycles);
   return true;
 }
 
index 4b7a81d3716096e9f7602b7cd4ef6616d2761a62..35a45f3cfe196531fbe31ec24f16bd476ff45e7e 100644 (file)
 // -- cMap4101 -----------------------------------------------------------------
 
 class cMap4101 : public cMapCore {
-private:
-  int mId;
 protected:
-  void DoMap(int f, unsigned char *data=0, int l=0);
-public:
-  cMap4101(int Id);
+  bool Map(int f, unsigned char *data, int l);
   };
 
-cMap4101::cMap4101(int Id)
-{
-  mId=Id|0x100;
-}
-
-void cMap4101::DoMap(int f, unsigned char *data, int l)
+bool cMap4101::Map(int f, unsigned char *data, int l)
 {
-  PRINTF(L_SYS_MAP,"%04x: calling function %02X",mId,f);
   switch(f) {
     case 0x58:
       {
@@ -78,10 +68,9 @@ void cMap4101::DoMap(int f, unsigned char *data, int l)
       cMapCore::DoMap(0x44,data);
       break;
     default:
-      if(!cMapCore::DoMap(f,data,l))
-        PRINTF(L_SYS_MAP,"%04x: unsupported call %02x",mId,f);
-      break;
+      return false;
     }
+  return true;
 }
 
 // -- cN2Prov4101 ----------------------------------------------------------------
@@ -99,9 +88,9 @@ static cN2ProvLinkReg<cN2Prov4101,0x4101,(N2FLAG_POSTAU|N2FLAG_Bx)> staticPL4101
 
 cN2Prov4101::cN2Prov4101(int Id, int Flags)
 :cN2Prov(Id,Flags)
-,cMap4101(Id)
 {
   hasWriteHandler=true;
+  SetMapIdent(Id);
 }
 
 bool cN2Prov4101::PostProcAU(int id, unsigned char *data)
index 4ed23b9561ce5f917a1a13e5aee9fb31598e3e13..b872ff4ac5557ebe7f8aa0314b7f47d34e7552b7 100644 (file)
@@ -484,8 +484,9 @@ void cMapMath::MonLoop(BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BI
 
 cMapCore::cMapCore(void)
 {
-  last=1;
+  last=1; mapid=0;
   regs[0]=&J; regs[1]=&A; regs[2]=&B; regs[3]=&C; regs[4]=&D;
+  interruptible=false;
 }
 
 void cMapCore::MonInit(int bits)
@@ -653,11 +654,25 @@ int cMapCore::GetOpSize(int l)
   return l!=0 ? l : wordsize;
 }
 
-bool cMapCore::DoMap(int f, unsigned char *data, int l)
+void cMapCore::DoMap(int f, unsigned char *data, int l)
+{
+  PRINTF(L_SYS_MAP,"%04x: calling function %02X",mapid,f);
+  cycles=0;
+  unsigned int startcycles=MapCycles();
+  interrupted=false; interruptible=true;
+  try {
+    if(!Map(f,data,l) && !MapGeneric(f,data,l))
+      PRINTF(L_SYS_MAP,"%04x: unsupported call %02x",mapid,f);
+    } catch(int) { interrupted=true; }
+  interruptible=false;
+  if(!interrupted && cycles)
+    AddMapCycles(MapCycles()-startcycles);
+}
+
+bool cMapCore::MapGeneric(int f, unsigned char *data, int l)
 {
   const int l1=GetOpSize(l);
   const int dl=l1<<3;
-  cycles=0;
   switch(f) {
     case SETSIZE:
       cycles=(l>17 ? 459 : (l ? 475 : 454))-6;
index 19bc5078202ef505fb069b5c7989fe411fc04124..673605dc16eb71de97beca400dd04e2535d4db24 100644 (file)
@@ -140,9 +140,12 @@ public:
 
 class cMapCore : public cMapMath {
 private:
-  int last;
+  int mapid, last;
   cBN e;
   cMapReg *regs[5];
+  bool interruptible, interrupted;
+  //
+  bool MapGeneric(int f, unsigned char *data, int l);
 protected:
   unsigned int cycles;
   cBN Px, Py, Pz,Qx, Qy, Qz; // 0x00,0x20,0x40,0x60,0x80,0x180
@@ -159,7 +162,11 @@ protected:
   void CurveInit(BIGNUM *a);
   //
   int GetOpSize(int l);
-  bool DoMap(int f, unsigned char *data=0, int l=0);
+  void DoMap(int f, unsigned char *data=0, int l=0);
+  virtual bool Map(int f, unsigned char *data, int l) { return false; }
+  void SetMapIdent(int Mapid) { mapid=Mapid; }
+  bool Interruptible(void) { return interruptible; }
+  bool Interrupted(void) { return interrupted; }
   virtual void AddMapCycles(unsigned int num) {}
   virtual unsigned int MapCycles(void) { return 0; }
 public: