SHARE
TWEET

Untitled

a guest Dec 9th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- a/include/dos_inc.h
  2. +++ b/include/dos_inc.h
  3. @@ -249,27 +249,26 @@ static INLINE Bit16u DOS_PackDate(Bit16u year,Bit16u mon,Bit16u day) {
  4.  
  5.  
  6.  /* Remains some classes used to access certain things */
  7. -#define sOffset(s,m) ((char*)&(((s*)NULL)->m)-(char*)NULL)
  8. -#define sGet(s,m) GetIt(sizeof(((s *)&pt)->m),(PhysPt)sOffset(s,m))
  9. -#define sSave(s,m,val) SaveIt(sizeof(((s *)&pt)->m),(PhysPt)sOffset(s,m),val)
  10. +#define sGet(s,m) GetIt<sizeof(s().m)>((PhysPt)offsetof(s,m))
  11. +#define sSave(s,m,val) SaveIt<sizeof(s().m)>((PhysPt)offsetof(s,m),val)
  12.  
  13.  class MemStruct {
  14.  public:
  15. -   Bitu GetIt(Bitu size,PhysPt addr) {
  16. -       switch (size) {
  17. -       case 1:return mem_readb(pt+addr);
  18. -       case 2:return mem_readw(pt+addr);
  19. -       case 4:return mem_readd(pt+addr);
  20. -       }
  21. -       return 0;
  22. -   }
  23. -   void SaveIt(Bitu size,PhysPt addr,Bitu val) {
  24. -       switch (size) {
  25. -       case 1:mem_writeb(pt+addr,(Bit8u)val);break;
  26. -       case 2:mem_writew(pt+addr,(Bit16u)val);break;
  27. -       case 4:mem_writed(pt+addr,(Bit32u)val);break;
  28. -       }
  29. -   }
  30. +   template<size_t S> struct BitType;
  31. +   template<> struct BitType<1> { typedef Bit8u Type; };
  32. +   template<> struct BitType<2> { typedef Bit16u Type; };
  33. +   template<> struct BitType<4> { typedef Bit32u Type; };
  34. +
  35. +   template<size_t S> typename BitType<S>::Type GetIt(PhysPt) const;
  36. +   template<> INLINE Bit8u  GetIt<1>(PhysPt offset) const { return mem_readb(pt+offset); }
  37. +   template<> INLINE Bit16u GetIt<2>(PhysPt offset) const { return mem_readw(pt+offset); }
  38. +   template<> INLINE Bit32u GetIt<4>(PhysPt offset) const { return mem_readd(pt+offset); }
  39. +
  40. +   template<size_t S> void SaveIt(PhysPt, typename BitType<S>::Type) const;
  41. +   template<> INLINE void SaveIt<1>(PhysPt offset, Bit8u  val) const { mem_writeb(pt+offset, val); }
  42. +   template<> INLINE void SaveIt<2>(PhysPt offset, Bit16u val) const { mem_writew(pt+offset, val); }
  43. +   template<> INLINE void SaveIt<4>(PhysPt offset, Bit32u val) const { mem_writed(pt+offset, val); }
  44. +
  45.     void SetPt(Bit16u seg) { pt=PhysMake(seg,0);}
  46.     void SetPt(Bit16u seg,Bit16u off) { pt=PhysMake(seg,off);}
  47.     void SetPt(RealPt addr) { pt=Real2Phys(addr);}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top