diff --git a/MakefileVC b/MakefileVC index 2b77c209c..55dd6804e 100644 --- a/MakefileVC +++ b/MakefileVC @@ -58,8 +58,7 @@ DIABLO_SRC += Source/render.cpp OBJS=$(DIABLO_SRC:.cpp=.obj) # hardcoded list of src files, because only some of them are ready to be compiled as C instead of C++ # once all files compile as C we should use the /TC flag abd DIABLO_SRC instead -DIABLO_SRC_FIXED = Source/appfat.cpp /TcSource/automap.cpp /TcSource/capture.cpp /TcSource/codec.cpp Source/control.cpp /TcSource/cursor.cpp /TcSource/dead.cpp /TcSource/debug.cpp /TcSource/diablo.cpp /TcSource/doom.cpp /TcSource/drlg_l1.cpp /TcSource/drlg_l2.cpp /TcSource/drlg_l3.cpp /TcSource/drlg_l4.cpp Source/dthread.cpp Source/dx.cpp /TcSource/effects.cpp /TcSource/encrypt.cpp Source/engine.cpp /TcSource/error.cpp Source/fault.cpp /TcSource/gamemenu.cpp /TcSource/gendung.cpp /TcSource/gmenu.cpp /TcSource/help.cpp /TcSource/init.cpp /TcSource/interfac.cpp /TcSource/inv.cpp Source/items.cpp /TcSource/lighting.cpp /TcSource/loadsave.cpp Source/logging.cpp /TcSource/mainmenu.cpp /TcSource/minitext.cpp /TcSource/missiles.cpp /TcSource/monster.cpp /TcSource/movie.cpp /TcSource/mpqapi.cpp /TcSource/msg.cpp Source/msgcmd.cpp /TcSource/multi.cpp Source/nthread.cpp /TcSource/objects.cpp /TcSource/pack.cpp /TcSource/palette.cpp /TcSource/path.cpp /TcSource/pfile.cpp /TcSource/player.cpp /TcSource/plrmsg.cpp /TcSource/portal.cpp /TcSource/quests.cpp /TcSource/restrict.cpp /TcSource/scrollrt.cpp /TcSource/setmaps.cpp /TcSource/sha.cpp /TcSource/sound.cpp /TcSource/spells.cpp /TcSource/stores.cpp /TcSource/sync.cpp /TcSource/textdat.cpp /TcSource/themes.cpp /TcSource/tmsg.cpp /TcSource/town.cpp /TcSource/towners.cpp /TcSource/track.cpp /TcSource/trigs.cpp /TcSource/wave.cpp /TcSource/render.cpp -DIABLO_SRC_FIXED = Source/appfat.cpp /TcSource/automap.cpp /TcSource/capture.cpp /TcSource/codec.cpp Source/control.cpp /TcSource/cursor.cpp /TcSource/dead.cpp /TcSource/debug.cpp /TcSource/diablo.cpp /TcSource/doom.cpp /TcSource/drlg_l1.cpp /TcSource/drlg_l2.cpp /TcSource/drlg_l3.cpp /TcSource/drlg_l4.cpp Source/dthread.cpp Source/dx.cpp /TcSource/effects.cpp /TcSource/encrypt.cpp Source/engine.cpp /TcSource/error.cpp Source/fault.cpp /TcSource/gamemenu.cpp /TcSource/gendung.cpp /TcSource/gmenu.cpp /TcSource/help.cpp /TcSource/init.cpp /TcSource/interfac.cpp /TcSource/inv.cpp /TcSource/items.cpp Source/lighting.cpp /TcSource/loadsave.cpp Source/logging.cpp /TcSource/mainmenu.cpp /TcSource/minitext.cpp /TcSource/missiles.cpp /TcSource/monster.cpp /TcSource/movie.cpp /TcSource/mpqapi.cpp /TcSource/msg.cpp Source/msgcmd.cpp /TcSource/multi.cpp Source/nthread.cpp /TcSource/objects.cpp /TcSource/pack.cpp /TcSource/palette.cpp /TcSource/path.cpp /TcSource/pfile.cpp /TcSource/player.cpp /TcSource/plrmsg.cpp /TcSource/portal.cpp /TcSource/quests.cpp /TcSource/restrict.cpp /TcSource/scrollrt.cpp /TcSource/setmaps.cpp /TcSource/sha.cpp /TcSource/sound.cpp /TcSource/spells.cpp /TcSource/stores.cpp /TcSource/sync.cpp /TcSource/textdat.cpp /TcSource/themes.cpp /TcSource/tmsg.cpp /TcSource/town.cpp /TcSource/towners.cpp /TcSource/track.cpp /TcSource/trigs.cpp /TcSource/wave.cpp /TcSource/render.cpp +DIABLO_SRC_FIXED = Source/appfat.cpp /TcSource/automap.cpp /TcSource/capture.cpp /TcSource/codec.cpp /TcSource/control.cpp /TcSource/cursor.cpp /TcSource/dead.cpp /TcSource/debug.cpp /TcSource/diablo.cpp /TcSource/doom.cpp /TcSource/drlg_l1.cpp /TcSource/drlg_l2.cpp /TcSource/drlg_l3.cpp /TcSource/drlg_l4.cpp Source/dthread.cpp Source/dx.cpp /TcSource/effects.cpp /TcSource/encrypt.cpp Source/engine.cpp /TcSource/error.cpp Source/fault.cpp /TcSource/gamemenu.cpp /TcSource/gendung.cpp /TcSource/gmenu.cpp /TcSource/help.cpp /TcSource/init.cpp /TcSource/interfac.cpp /TcSource/inv.cpp Source/items.cpp /TcSource/lighting.cpp /TcSource/loadsave.cpp Source/logging.cpp /TcSource/mainmenu.cpp /TcSource/minitext.cpp /TcSource/missiles.cpp /TcSource/monster.cpp /TcSource/movie.cpp /TcSource/mpqapi.cpp /TcSource/msg.cpp Source/msgcmd.cpp /TcSource/multi.cpp Source/nthread.cpp /TcSource/objects.cpp /TcSource/pack.cpp /TcSource/palette.cpp /TcSource/path.cpp /TcSource/pfile.cpp /TcSource/player.cpp /TcSource/plrmsg.cpp /TcSource/portal.cpp /TcSource/quests.cpp /TcSource/restrict.cpp /TcSource/scrollrt.cpp /TcSource/setmaps.cpp /TcSource/sha.cpp /TcSource/sound.cpp /TcSource/spells.cpp /TcSource/stores.cpp /TcSource/sync.cpp /TcSource/textdat.cpp /TcSource/themes.cpp /TcSource/tmsg.cpp /TcSource/town.cpp /TcSource/towners.cpp /TcSource/track.cpp /TcSource/trigs.cpp /TcSource/wave.cpp /TcSource/render.cpp PKWARE_SRC=$(sort $(wildcard 3rdParty/PKWare/*.cpp)) PKWARE_OBJS=$(PKWARE_SRC:.cpp=.obj) diff --git a/Source/control.cpp b/Source/control.cpp index 975e36f84..4bed7f96d 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -241,13 +241,13 @@ void __fastcall DrawSpellCel(int xp, int yp, char *Trans, int nCel, int w) _EAX = *(_DWORD *)v6; v6 += 4; ASM_XLAT(_EAX, _EBX); - _EAX = __ROR4__(_EAX, 8); + _EAX = _rotr(_EAX, 8); ASM_XLAT(_EAX, _EBX); - _EAX = __ROR4__(_EAX, 8); + _EAX = _rotr(_EAX, 8); ASM_XLAT(_EAX, _EBX); - _EAX = __ROR4__(_EAX, 8); + _EAX = _rotr(_EAX, 8); ASM_XLAT(_EAX, _EBX); - *(_DWORD *)v7 = __ROR4__(_EAX, 8); + *(_DWORD *)v7 = _rotr(_EAX, 8); v7 += 4; --v15; } while (v15); diff --git a/Source/engine.cpp b/Source/engine.cpp index 26e0b32b4..4150431a8 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -260,7 +260,7 @@ void __fastcall CelDecDatLightTrans(char *pDecodeTo, char *pRLEBytes, int frame_ ASM_XLAT(_EAX, _EBX); *(_BYTE *)v5 = _EAX; v25 = (_BYTE *)(v5 + 2); - _EAX = __ROR4__(_EAX, 16); + _EAX = _rotr(_EAX, 16); ASM_XLAT(_EAX, _EBX); *v25 = _EAX; v5 = (int)(v25 + 2); @@ -295,10 +295,10 @@ void __fastcall CelDecDatLightTrans(char *pDecodeTo, char *pRLEBytes, int frame_ _EAX = *(_DWORD *)v4; v4 += 4; v18 = (_BYTE *)(v5 + 1); - _EAX = __ROR4__(_EAX, 8); + _EAX = _rotr(_EAX, 8); ASM_XLAT(_EAX, _EBX); *v18 = _EAX; - _EAX = __ROR4__(_EAX, 16); + _EAX = _rotr(_EAX, 16); v18 += 2; ASM_XLAT(_EAX, _EBX); *v18 = _EAX; @@ -740,7 +740,7 @@ void __fastcall Cel2DecDatLightTrans(char *pDecodeTo, char *pRLEBytes, int frame ASM_XLAT(_EAX, _EBX); *(_BYTE *)v5 = _EAX; v25 = (_BYTE *)(v5 + 2); - _EAX = __ROR4__(_EAX, 16); + _EAX = _rotr(_EAX, 16); ASM_XLAT(_EAX, _EBX); *v25 = _EAX; v5 = (unsigned int)(v25 + 2); @@ -775,10 +775,10 @@ void __fastcall Cel2DecDatLightTrans(char *pDecodeTo, char *pRLEBytes, int frame _EAX = *(_DWORD *)v4; v4 += 4; v18 = (_BYTE *)(v5 + 1); - _EAX = __ROR4__(_EAX, 8); + _EAX = _rotr(_EAX, 8); ASM_XLAT(_EAX, _EBX); *v18 = _EAX; - _EAX = __ROR4__(_EAX, 16); + _EAX = _rotr(_EAX, 16); v18 += 2; ASM_XLAT(_EAX, _EBX); *v18 = _EAX; diff --git a/defs.h b/defs.h index c9984b6da..765aeb3db 100644 --- a/defs.h +++ b/defs.h @@ -135,12 +135,10 @@ typedef __int64 int64; // Helper functions to represent some assembly instructions. -#ifdef __cplusplus - #ifdef FAST_MEMCPY #define qmemcpy memcpy #else -inline void *qmemcpy(void *dst, const void *src, size_t cnt) +__inline void *qmemcpy(void *dst, const void *src, size_t cnt) { char *out = (char *)dst; const char *in = (const char *)src; @@ -152,31 +150,15 @@ inline void *qmemcpy(void *dst, const void *src, size_t cnt) } #endif -// rotate left -template -T __ROL__(T value, int count) +// rotate right +__inline WORD __ROR2__(WORD value, DWORD count) { - const unsigned int nbits = sizeof(T) * 8; - - if (count > 0) { - count %= nbits; - T high = value >> (nbits - count); - if (T(-1) < 0) // signed value - high &= ~((T(-1) << count)); - value <<= count; - value |= high; - } else { - count = -count % nbits; - T low = value << (nbits - count); - value >>= count; - value |= low; - } - return value; -} + count %= 16; -inline unsigned short __ROR2__(unsigned short value, int count) { return __ROL__((unsigned short)value, -count); } -inline unsigned int __ROR4__(unsigned int value, int count) { return __ROL__((unsigned int)value, -count); } + return value >> count | value << (16 - count); +} +#ifdef __cplusplus // sign flag template char __SETS__(T x) @@ -204,9 +186,6 @@ char __OFSUB__(T x, U y) return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x - y2)); } } - -#else -#define qmemcpy memcpy #endif #endif /* IDA_GARBAGE */