Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- a/include/dos_inc.h
- +++ b/include/dos_inc.h
- @@ -249,27 +249,26 @@ static INLINE Bit16u DOS_PackDate(Bit16u year,Bit16u mon,Bit16u day) {
- /* Remains some classes used to access certain things */
- -#define sOffset(s,m) ((char*)&(((s*)NULL)->m)-(char*)NULL)
- -#define sGet(s,m) GetIt(sizeof(((s *)&pt)->m),(PhysPt)sOffset(s,m))
- -#define sSave(s,m,val) SaveIt(sizeof(((s *)&pt)->m),(PhysPt)sOffset(s,m),val)
- +#define sGet(s,m) GetIt<sizeof(s().m)>((PhysPt)offsetof(s,m))
- +#define sSave(s,m,val) SaveIt<sizeof(s().m)>((PhysPt)offsetof(s,m),val)
- class MemStruct {
- public:
- - Bitu GetIt(Bitu size,PhysPt addr) {
- - switch (size) {
- - case 1:return mem_readb(pt+addr);
- - case 2:return mem_readw(pt+addr);
- - case 4:return mem_readd(pt+addr);
- - }
- - return 0;
- - }
- - void SaveIt(Bitu size,PhysPt addr,Bitu val) {
- - switch (size) {
- - case 1:mem_writeb(pt+addr,(Bit8u)val);break;
- - case 2:mem_writew(pt+addr,(Bit16u)val);break;
- - case 4:mem_writed(pt+addr,(Bit32u)val);break;
- - }
- - }
- + template<size_t S> struct BitType;
- + template<> struct BitType<1> { typedef Bit8u Type; };
- + template<> struct BitType<2> { typedef Bit16u Type; };
- + template<> struct BitType<4> { typedef Bit32u Type; };
- +
- + template<size_t S> typename BitType<S>::Type GetIt(PhysPt) const;
- + template<> INLINE Bit8u GetIt<1>(PhysPt offset) const { return mem_readb(pt+offset); }
- + template<> INLINE Bit16u GetIt<2>(PhysPt offset) const { return mem_readw(pt+offset); }
- + template<> INLINE Bit32u GetIt<4>(PhysPt offset) const { return mem_readd(pt+offset); }
- +
- + template<size_t S> void SaveIt(PhysPt, typename BitType<S>::Type) const;
- + template<> INLINE void SaveIt<1>(PhysPt offset, Bit8u val) const { mem_writeb(pt+offset, val); }
- + template<> INLINE void SaveIt<2>(PhysPt offset, Bit16u val) const { mem_writew(pt+offset, val); }
- + template<> INLINE void SaveIt<4>(PhysPt offset, Bit32u val) const { mem_writed(pt+offset, val); }
- +
- void SetPt(Bit16u seg) { pt=PhysMake(seg,0);}
- void SetPt(Bit16u seg,Bit16u off) { pt=PhysMake(seg,off);}
- void SetPt(RealPt addr) { pt=Real2Phys(addr);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement