Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace __ROR4__ stdlib, make _ROR2__ C frindly #540

Merged
merged 4 commits into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions MakefileVC
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Source/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions Source/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 7 additions & 28 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -152,31 +150,15 @@ inline void *qmemcpy(void *dst, const void *src, size_t cnt)
}
#endif

// rotate left
template <class T>
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 <class T>
char __SETS__(T x)
Expand Down Expand Up @@ -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 */