From 546a12a2b233b825ea9cf6aca5ec50fa4daeb43c Mon Sep 17 00:00:00 2001 From: anon Date: Mon, 6 Oct 2008 05:55:32 +0800 Subject: [PATCH] nagra-0501: propper map18 timing fix --- systems/nagra/nagra2-0101.c | 1 + systems/nagra/nagra2-0501.c | 2 +- systems/nagra/nagra2.c | 8 ++++++++ systems/nagra/nagra2.h | 2 ++ testing/testN2Emu.c | 2 ++ 5 files changed, 14 insertions(+), 1 deletion(-) 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 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 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