Generalize the getGameState functions.

This commit is contained in:
Michael Martin
2013-10-13 18:49:54 -07:00
parent e7d30008a2
commit 40dcd65afa
2 changed files with 23 additions and 23 deletions
+13 -13
View File
@@ -48,31 +48,31 @@ GLOBDATA GlobData;
BYTE BYTE
getGameState (int startBit, int endBit) getGameState (BYTE *state, int startBit, int endBit)
{ {
return (BYTE) (((startBit >> 3) == (endBit >> 3) return (BYTE) (((startBit >> 3) == (endBit >> 3)
? (GLOBAL (GameState[startBit >> 3]) >> (startBit & 7)) ? (state[startBit >> 3] >> (startBit & 7))
: ((GLOBAL (GameState[startBit >> 3]) >> (startBit & 7)) : ((state[startBit >> 3] >> (startBit & 7))
| (GLOBAL (GameState[endBit >> 3]) | (state[endBit >> 3]
<< (endBit - startBit - (endBit & 7))))) << (endBit - startBit - (endBit & 7)))))
& ((1 << (endBit - startBit + 1)) - 1)); & ((1 << (endBit - startBit + 1)) - 1));
} }
void void
setGameState (int startBit, int endBit, BYTE val setGameState (BYTE *state, int startBit, int endBit, BYTE val
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
, const char *name , const char *name
#endif #endif
) )
{ {
GLOBAL (GameState[startBit >> 3]) = state[startBit >> 3] =
(GLOBAL (GameState[startBit >> 3]) (state[startBit >> 3]
& (BYTE) ~(((1 << (endBit - startBit + 1)) - 1) << (startBit & 7))) & (BYTE) ~(((1 << (endBit - startBit + 1)) - 1) << (startBit & 7)))
| (BYTE)((val) << (startBit & 7)); | (BYTE)((val) << (startBit & 7));
if ((startBit >> 3) < (endBit >> 3)) { if ((startBit >> 3) < (endBit >> 3)) {
GLOBAL (GameState[endBit >> 3]) = state[endBit >> 3] =
(GLOBAL (GameState[endBit >> 3]) (state[endBit >> 3]
& (BYTE)~((1 << ((endBit & 7) + 1)) - 1)) & (BYTE)~((1 << ((endBit & 7) + 1)) - 1))
| (BYTE)((val) >> (endBit - startBit - (endBit & 7))); | (BYTE)((val) >> (endBit - startBit - (endBit & 7)));
} }
@@ -82,21 +82,21 @@ setGameState (int startBit, int endBit, BYTE val
} }
DWORD DWORD
getGameState32 (int startBit) getGameState32 (BYTE *state, int startBit)
{ {
DWORD v; DWORD v;
int shift; int shift;
for (v = 0, shift = 0; shift < 32; shift += 8, startBit += 8) for (v = 0, shift = 0; shift < 32; shift += 8, startBit += 8)
{ {
v |= getGameState (startBit, startBit + 7) << shift; v |= getGameState (state, startBit, startBit + 7) << shift;
} }
return v; return v;
} }
void void
setGameState32 (int startBit, DWORD val setGameState32 (BYTE *state, int startBit, DWORD val
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
, const char *name , const char *name
#endif #endif
@@ -107,7 +107,7 @@ setGameState32 (int startBit, DWORD val
for (i = 0; i < 4; ++i, v >>= 8, startBit += 8) for (i = 0; i < 4; ++i, v >>= 8, startBit += 8)
{ {
setGameState (startBit, startBit + 7, v & 0xff setGameState (state, startBit, startBit + 7, v & 0xff
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
, "(ignored)" , "(ignored)"
#endif #endif
+10 -10
View File
@@ -972,36 +972,36 @@ extern GLOBDATA GlobData;
//#define STATE_DEBUG //#define STATE_DEBUG
extern BYTE getGameState (int startBit, int endBit); extern BYTE getGameState (BYTE *state, int startBit, int endBit);
extern void setGameState (int startBit, int endBit, BYTE val extern void setGameState (BYTE *state, int startBit, int endBit, BYTE val
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
, const char *name , const char *name
#endif #endif
); );
#define GET_GAME_STATE(SName) getGameState ((SName), (END_##SName)) #define GET_GAME_STATE(SName) getGameState (GLOBAL(GameState), (SName), (END_##SName))
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
# define SET_GAME_STATE(SName, val) \ # define SET_GAME_STATE(SName, val) \
setGameState ((SName), (END_##SName), (val), #SName) setGameState (GLOBAL(GameState), (SName), (END_##SName), (val), #SName)
#else #else
# define SET_GAME_STATE(SName, val) \ # define SET_GAME_STATE(SName, val) \
setGameState ((SName), (END_##SName), (val)) setGameState (GLOBAL(GameState), (SName), (END_##SName), (val))
#endif #endif
extern DWORD getGameState32 (int startBit); extern DWORD getGameState32 (BYTE *state, int startBit);
extern void setGameState32 (int startBit, DWORD val extern void setGameState32 (BYTE *state, int startBit, DWORD val
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
, const char *name , const char *name
#endif #endif
); );
#define GET_GAME_STATE_32(SName) getGameState32 ((SName)) #define GET_GAME_STATE_32(SName) getGameState32 (GLOBAL(GameState), (SName))
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
# define SET_GAME_STATE_32(SName, val) \ # define SET_GAME_STATE_32(SName, val) \
setGameState32 ((SName), (val), #SName) setGameState32 (GLOBAL(GameState), (SName), (val), #SName)
#else #else
# define SET_GAME_STATE_32(SName, val) \ # define SET_GAME_STATE_32(SName, val) \
setGameState32 ((SName), (val)) setGameState32 (GLOBAL(GameState), (SName), (val))
#endif #endif