SASC-NG
DVBSoftCAM

cpu.h

Go to the documentation of this file.
00001 /*
00002  * Softcam plugin to VDR (C++)
00003  *
00004  * This code is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This code is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
00018  */
00019 
00020 #ifndef __NAGRA_CPU_H
00021 #define __NAGRA_CPU_H
00022 
00023 #define FILEMAP_DOMAIN "nagra"
00024 
00025 class cFileMap;
00026 class cLineBuff;
00027 class c6805;
00028 
00029 // ----------------------------------------------------------------
00030 
00031 class cMap {
00032 friend class c6805;
00033 protected:
00034   cLineBuff *loglb;
00035 public:
00036   virtual ~cMap() {};
00037   virtual unsigned char Get(unsigned short ea)=0;
00038   virtual void Set(unsigned short ea, unsigned char val)=0;
00039   virtual bool IsFine(void)=0;
00040 };
00041 
00042 // ----------------------------------------------------------------
00043 
00044 class cMapMem : public cMap {
00045 protected:
00046   unsigned short offset;
00047   unsigned char *mem;
00048   int size;
00049 public:
00050   cMapMem(unsigned short Offset, int Size);
00051   virtual ~cMapMem();
00052   virtual unsigned char Get(unsigned short ea);
00053   virtual void Set(unsigned short ea, unsigned char val);
00054   virtual bool IsFine(void);
00055   };
00056 
00057 // ----------------------------------------------------------------
00058 
00059 class cMapRom : public cMap {
00060 private:
00061   unsigned short offset;
00062   cFileMap *fm;
00063   unsigned char *addr;
00064   int size;
00065 public:
00066   cMapRom(unsigned short Offset, const char *Filename, int InFileOffset=0);
00067   virtual ~cMapRom();
00068   virtual unsigned char Get(unsigned short ea);
00069   virtual void Set(unsigned short ea, unsigned char val);
00070   virtual bool IsFine(void);
00071   };
00072 
00073 // ----------------------------------------------------------------
00074 
00075 class cMapEeprom : public cMap {
00076 private:
00077   unsigned short offset;
00078   cFileMap *fm;
00079   unsigned char *addr;
00080   int size, otpSize;
00081 public:
00082   cMapEeprom(unsigned short Offset, const char *Filename, int OtpSize, int InFileOffset=0);
00083   virtual ~cMapEeprom();
00084   virtual unsigned char Get(unsigned short ea);
00085   virtual void Set(unsigned short ea, unsigned char val);
00086   virtual bool IsFine(void);
00087   };
00088 
00089 // ----------------------------------------------------------------
00090 
00091 #define MAX_BREAKPOINTS 24
00092 #define MAX_MAPPER      10
00093 #define MAX_PAGES       5
00094 #define PAGE_SIZE       32*1024
00095 #define EXPT_MAX        16
00096 
00097 #define bitset(d,bit) (((d)>>(bit))&1)
00098 
00099 #define HILO(ea)      ((Get(ea)<<8)+Get((ea)+1))
00100 #define HILOS(s,ea)   ((Get((s),(ea))<<8)+Get((s),(ea)+1))
00101 
00102 class c6805 {
00103 private:
00104   unsigned short pc, sp, spHi, spLow, exptBase;
00105   unsigned short bp[MAX_BREAKPOINTS], numBp;
00106   unsigned char mapMap[(MAX_PAGES+1)*PAGE_SIZE];
00107   cMap *mapper[MAX_MAPPER];
00108   int nextMapper;
00109   int pageMap[256];
00110   bool indirect;
00111   unsigned int clockcycles;
00112   bool exptPending, exptReady, expt[EXPT_MAX];
00113   int timerDisable;
00114   //
00115   void InitMapper(void);
00116   void ClearMapper(void);
00117   void branch(bool branch);
00118   inline void tst(unsigned char c);
00119   inline void push(unsigned char c);
00120   inline unsigned char pop(void);
00121   void pushpc(void);
00122   void poppc(void);
00123   void pushc(void);
00124   void popc(void);
00125   unsigned char add(unsigned char op, unsigned char c);
00126   unsigned char sub(unsigned char op1, unsigned char op2, unsigned char c);
00127   unsigned char rollR(unsigned char op, unsigned char c);
00128   unsigned char rollL(unsigned char op, unsigned char c);
00129 protected:
00130   unsigned char a, x, y, cr, dr;
00131   struct CC { unsigned char c, z, n, i, h, v; } cc;
00132   bool hasReadHandler, hasWriteHandler;
00133   //
00134   int Run(int max_count);
00135   void AddBreakpoint(unsigned short addr);
00136   void ClearBreakpoints(void);
00137   bool AddMapper(cMap *map, unsigned short start, int size, unsigned char seg=0);
00138   void ResetMapper(void);
00139   unsigned char Get(unsigned short ea) const;
00140   unsigned char Get(unsigned char seg, unsigned short ea) const;
00141   void Set(unsigned short ea, unsigned char val);
00142   void Set(unsigned char seg, unsigned short ea, unsigned char val);
00143   void GetMem(unsigned short addr, unsigned char *data, int len, unsigned char seg=0) const;
00144   void SetMem(unsigned short addr, const unsigned char *data, int len, unsigned char seg=0);
00145   void ForceSet(unsigned short ea, unsigned char val, bool ro);
00146   void SetSp(unsigned short SpHi, unsigned short SpLow);
00147   void SetPc(unsigned short addr, unsigned char seg=0);
00148   unsigned short GetPc(void) const { return pc; }
00149   void PopPc(void);
00150   void PopCr(void);
00151   void Push(unsigned char c);
00152   void ResetCycles(void);
00153   void AddCycles(unsigned int num);
00154   unsigned int Cycles(void) { return clockcycles; }
00155   void RaiseException(int num);
00156   void ClearExceptions(void);
00157   void SetExptBase(unsigned short base);
00158   void DisableTimers(int num);
00159   virtual void Stepper(void)=0;
00160   virtual void WriteHandler(unsigned char seg, unsigned short ea, unsigned char &op) {}
00161   virtual void ReadHandler(unsigned char seg, unsigned short ea, unsigned char &op) {}
00162   virtual void TimerHandler(unsigned int num) {}
00163 private:
00164   unsigned int stats[256];
00165   char addrBuff[32];
00166   bool doDisAsm;
00167   int disAsmLogClass;
00168 protected:
00169   cLineBuff *loglb;
00170   char * PADDR(unsigned char s, unsigned short ea);
00171 public:
00172   c6805(void);
00173   virtual ~c6805();
00174   };
00175 
00176 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines