From: anon <unknown>
Date: Sun, 5 Oct 2008 21:55:32 +0000 (+0800)
Subject: nagra-0501: propper map18 timing fix
X-Git-Tag: 0.9.1~16
X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=546a12a2b233b825ea9cf6aca5ec50fa4daeb43c;p=sasc-ng.git

nagra-0501: propper map18 timing fix
---

diff --git a/systems/nagra/nagra2-0101.c b/systems/nagra/nagra2-0101.c
index fa1cb85..8e9577b 100644
--- a/systems/nagra/nagra2-0101.c
+++ b/systems/nagra/nagra2-0101.c
@@ -440,6 +440,7 @@ public:
   virtual int ProcessBx(unsigned char *data, int len, int pos);
   virtual int ProcessEx(unsigned char *data, int len, int pos);
   virtual int RunEmu(unsigned char *data, int len, unsigned short load, unsigned short run, unsigned short stop, unsigned short fetch, int fetch_len);
+  virtual void PostDecrypt(bool ecm) { PostDecryptSetup(ecm); }
   };
 
 static cN2ProvLinkReg<cN2Prov0101,0x0101,(N2FLAG_MECM|N2FLAG_POSTAU|N2FLAG_Bx|N2FLAG_Ex)> staticPL0101;
diff --git a/systems/nagra/nagra2-0501.c b/systems/nagra/nagra2-0501.c
index bfc3e80..80a01e8 100644
--- a/systems/nagra/nagra2-0501.c
+++ b/systems/nagra/nagra2-0501.c
@@ -65,6 +65,7 @@ public:
   cN2Prov0501(int Id, int Flags);
   virtual int ProcessBx(unsigned char *data, int len, int pos);
   virtual int RunEmu(unsigned char *data, int len, unsigned short load, unsigned short run, unsigned short stop, unsigned short fetch, int fetch_len);
+  virtual void PostDecrypt(bool ecm) { PostDecryptSetup(ecm); }
   };
 
 static cN2ProvLinkReg<cN2Prov0501,0x0501,(N2FLAG_MECM|N2FLAG_INV|N2FLAG_Bx)> staticPL0501;
@@ -164,7 +165,6 @@ bool cN2Prov0501::ProcessMap(int f)
     case COPY_C_D:
     case COPY_D_C:
       DoMap(f);
-      if(f>=COPY_A_B) AddMapCycles(64); // quick timing fix. Is there an AUXed ROM120 to check???
       break;
     case 0x37:
       GetMem(HILO(0x44),tmp,dl,0);
diff --git a/systems/nagra/nagra2.c b/systems/nagra/nagra2.c
index 2f01cb6..c1af024 100644
--- a/systems/nagra/nagra2.c
+++ b/systems/nagra/nagra2.c
@@ -726,6 +726,12 @@ void cMapCore::CurveInit(BIGNUM *a)
   MonMul(s160,B,a);
 }
 
+void cMapCore::PostDecryptSetup(bool ecm)
+{
+  if(ecm) wordsize=0x8;
+  else    wordsize=0xC;
+}
+
 int cMapCore::GetOpSize(int l)
 {
   return l!=0 ? l : wordsize;
@@ -1202,6 +1208,7 @@ bool cSystemNagra2::ProcessECM(const cEcmInfo *ecm, unsigned char *data)
     if(ecmP) ecmP->PrintCaps(L_SYS_ECM);
     }
   lastEcmId=id;
+  if(ecmP) ecmP->PostDecrypt(true);
 
   HEXDUMP(L_SYS_RAWECM,buff,cmdLen,"Nagra2 RAWECM");
   int l=0, mecmAlgo=0;
@@ -1308,6 +1315,7 @@ void cSystemNagra2::ProcessEMM(int pid, int caid, unsigned char *buffer)
     if(emmP) emmP->PrintCaps(L_SYS_EMM);
     }
   lastEmmId=id;
+  if(emmP) emmP->PostDecrypt(false);
 
   HEXDUMP(L_SYS_RAWEMM,emmdata,cmdLen,"Nagra2 RAWEMM");
   id=(emmdata[8]<<8)+emmdata[9];
diff --git a/systems/nagra/nagra2.h b/systems/nagra/nagra2.h
index e4fedba..6463bb6 100644
--- a/systems/nagra/nagra2.h
+++ b/systems/nagra/nagra2.h
@@ -176,6 +176,7 @@ protected:
   virtual void AddMapCycles(unsigned int num) {}
   unsigned int MapCycles(void) { return cycles; }
   virtual unsigned int CpuCycles(void) { return 0; }
+  virtual void PostDecryptSetup(bool ecm);
 public:
   cMapCore(void);
   virtual ~cMapCore() {}
@@ -297,6 +298,7 @@ public:
   virtual int ProcessEx(unsigned char *data, int len, int pos) { return -1; }
   virtual bool PostProcAU(int id, unsigned char *data) { return true; }
   virtual int RunEmu(unsigned char *data, int len, unsigned short load, unsigned short run, unsigned short stop, unsigned short fetch, int fetch_len) { return -1; }
+  virtual void PostDecrypt(bool ecm) {}
   bool CanHandle(int Id) { return MATCH_ID(Id,id); }
   bool HasFlags(int Flags) { return (flags&Flags)==Flags; }
   void PrintCaps(int c);
diff --git a/testing/testN2Emu.c b/testing/testN2Emu.c
index c2ea053..4c25c4c 100644
--- a/testing/testN2Emu.c
+++ b/testing/testN2Emu.c
@@ -20,6 +20,7 @@ void Emm(unsigned char *emmdata, int cmdLen, int id)
     emmP=cN2Providers::GetProv(id,N2FLAG_NONE);
     if(emmP) emmP->PrintCaps(L_SYS_EMM);
     }
+  if(emmP) emmP->PostDecrypt(false);
 
   HEXDUMP(L_SYS_RAWEMM,emmdata,cmdLen,"Nagra2 RAWEMM");
   id=(emmdata[8]<<8)+emmdata[9];
@@ -134,6 +135,7 @@ bool Ecm(unsigned char *buff, int cmdLen, int id)
 
   cN2Prov *ecmP=cN2Providers::GetProv(id,N2FLAG_NONE);
   if(ecmP) ecmP->PrintCaps(L_SYS_ECM);
+  if(ecmP) ecmP->PostDecrypt(true);
 
   int l=0, mecmAlgo=0;
   for(int i=(buff[14]&0x10)?16:20; i<cmdLen-10 && l!=3; ) {