Skip to content

Commit

Permalink
TONY: Replace copyMemory with memcpy.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzie committed Aug 25, 2012
1 parent b14a616 commit a9828c8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 39 deletions.
12 changes: 6 additions & 6 deletions engines/tony/gfxcore.cpp
Expand Up @@ -135,7 +135,7 @@ RMGfxBuffer::RMGfxBuffer(int dimx, int dimy, int nBpp, bool bUseDDraw) {

int RMGfxSourceBuffer::init(const byte *buf, int dimx, int dimy, bool bLoadPalette) {
create(dimx, dimy, getBpp());
copyMemory(_buf, buf, dimx * dimy * getBpp() / 8);
memcpy(_buf, buf, dimx * dimy * getBpp() / 8);

// Invokes the method for preparing the surface (inherited)
prepareImage();
Expand Down Expand Up @@ -484,7 +484,7 @@ int RMGfxSourceBufferPal::loadPaletteWA(const byte *buf, bool bSwapped) {
_pal[i * 3 + 2] = buf[i * 3 + 0];
}
} else {
copyMemory(_pal, buf, (1 << getBpp()) * 3);
memcpy(_pal, buf, (1 << getBpp()) * 3);
}

preparePalette();
Expand All @@ -496,7 +496,7 @@ int RMGfxSourceBufferPal::loadPalette(const byte *buf) {
int i;

for (i = 0; i < 256; i++)
copyMemory(_pal + i * 3, buf + i * 4, 3);
memcpy(_pal + i * 3, buf + i * 4, 3);

preparePalette();

Expand Down Expand Up @@ -984,7 +984,7 @@ void RMGfxSourceBuffer8RLEByte::RLEWriteData(byte *&cur, int rep, byte *src) {

*cur ++ = rep;
if (rep > 0) {
copyMemory(cur, src, rep);
memcpy(cur, src, rep);
cur += rep;
src += rep;
}
Expand Down Expand Up @@ -1232,7 +1232,7 @@ void RMGfxSourceBuffer8RLEWord::RLEWriteData(byte *&cur, int rep, byte *src) {
cur += 2;

if (rep > 0) {
copyMemory(cur, src, rep);
memcpy(cur, src, rep);
cur += rep;
src += rep;
}
Expand Down Expand Up @@ -1683,7 +1683,7 @@ void RMGfxSourceBuffer8AA::calculateAA() {
delete[] _aabuf;

_aabuf = new byte[_dimx * _dimy];
copyMemory(_aabuf, _megaAABuf, _dimx * _dimy);
memcpy(_aabuf, _megaAABuf, _dimx * _dimy);
}

RMGfxSourceBuffer8AA::RMGfxSourceBuffer8AA() : RMGfxSourceBuffer8() {
Expand Down
8 changes: 4 additions & 4 deletions engines/tony/mpal/expr.cpp
Expand Up @@ -121,7 +121,7 @@ static byte *duplicateExpression(HGLOBAL h) {
clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(EXPRESSION) * num + 1);
two = (LPEXPRESSION)(clone + 1);

copyMemory(clone, orig, sizeof(EXPRESSION) * num + 1);
memcpy(clone, orig, sizeof(EXPRESSION) * num + 1);

for (i = 0; i < num; i++) {
if (one->type == ELT_PARENTH) {
Expand Down Expand Up @@ -191,7 +191,7 @@ static void solve(LPEXPRESSION one, int num) {
two = one + 1;
if ((two->symbol == 0) || (one->symbol & 0xF0) <= (two->symbol & 0xF0)) {
two->val.num = Compute(one->val.num, two->val.num, one->symbol);
copyMemory(one, two, (num - 1) * sizeof(EXPRESSION));
memcpy(one, two, (num - 1) * sizeof(EXPRESSION));
--num;
} else {
j = 1;
Expand All @@ -203,7 +203,7 @@ static void solve(LPEXPRESSION one, int num) {
}

three->val.num = Compute(two->val.num, three->val.num, two->symbol);
copyMemory(two, three, (num - j - 1) * sizeof(EXPRESSION));
memcpy(two, three, (num - j - 1) * sizeof(EXPRESSION));
--num;
}
}
Expand Down Expand Up @@ -291,7 +291,7 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) {
cur->val.name = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, (*lpBuf) + 1);
if (cur->val.name == NULL)
return NULL;
copyMemory(cur->val.name, lpBuf + 1, *lpBuf);
memcpy(cur->val.name, lpBuf + 1, *lpBuf);
lpBuf += *lpBuf + 1;
break;

Expand Down
10 changes: 5 additions & 5 deletions engines/tony/mpal/loadmpc.cpp
Expand Up @@ -102,7 +102,7 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) {
lpmsScript->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1);
if (lpmsScript->_command[curCmd].lpszVarName == NULL)
return NULL;
copyMemory(lpmsScript->_command[curCmd].lpszVarName, lpBuf, len);
memcpy(lpmsScript->_command[curCmd].lpszVarName, lpBuf, len);
lpBuf += len;

lpBuf = parseExpression(lpBuf, &lpmsScript->_command[curCmd].expr);
Expand Down Expand Up @@ -346,7 +346,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) {

len = *lpBuf;
lpBuf++;
copyMemory(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len));
memcpy(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len));
lpBuf += len;

if (len >= MAX_DESCRIBE_SIZE)
Expand Down Expand Up @@ -416,7 +416,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) {
lpmiItem->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1);
if (lpmiItem->_command[curCmd].lpszVarName == NULL)
return NULL;
copyMemory(lpmiItem->_command[curCmd].lpszVarName, lpBuf, len);
memcpy(lpmiItem->_command[curCmd].lpszVarName, lpBuf, len);
lpBuf += len;

lpBuf = parseExpression(lpBuf, &lpmiItem->_command[curCmd].expr);
Expand Down Expand Up @@ -548,7 +548,7 @@ bool ParseMpc(const byte *lpBuf) {
for (i = 0; i < GLOBALS._nVars; i++) {
wLen = *(const byte *)lpBuf;
lpBuf++;
copyMemory(GLOBALS._lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32));
memcpy(GLOBALS._lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32));
lpBuf += wLen;
GLOBALS._lpmvVars->dwVal = READ_LE_UINT32(lpBuf);
lpBuf += 4;
Expand Down Expand Up @@ -590,7 +590,7 @@ bool ParseMpc(const byte *lpBuf) {
lpTemp = (byte *)globalLock(GLOBALS._lpmmMsgs->_hText);

for (j = 0; lpBuf[j] != 0;) {
copyMemory(lpTemp, &lpBuf[j + 1], lpBuf[j]);
memcpy(lpTemp, &lpBuf[j + 1], lpBuf[j]);
lpTemp += lpBuf[j];
*lpTemp ++= '\0';
j += lpBuf[j] + 1;
Expand Down
9 changes: 0 additions & 9 deletions engines/tony/mpal/memory.cpp
Expand Up @@ -124,15 +124,6 @@ void MemoryManager::unlockItem(HANDLE handle) {
}


/****************************************************************************\
* Stand-alone methods
\****************************************************************************/

void copyMemory(void *dst, const void *first, int size) {
Common::copy((const byte *)first, (const byte *)first + size, (byte *)dst);
}


} // end of namespace MPAL

} // end of namespace Tony
3 changes: 0 additions & 3 deletions engines/tony/mpal/memory.h
Expand Up @@ -70,9 +70,6 @@ class MemoryManager {
#define GMEM_MOVEABLE 2
#define GMEM_ZEROINIT 4

// Stand-alone methods
extern void copyMemory(void *dst, const void *first, int size);

} // end of namespace MPAL

} // end of namespace Tony
Expand Down
24 changes: 12 additions & 12 deletions engines/tony/mpal/mpal.cpp
Expand Up @@ -313,7 +313,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) {
if (clonemsg == NULL)
return NULL;

copyMemory(clonemsg, origmsg, j);
memcpy(clonemsg, origmsg, j);
globalUnlock(GLOBALS._lpmmMsgs[nMsgOrd]._hText);

return clonemsg;
Expand Down Expand Up @@ -346,7 +346,7 @@ static char *duplicateDialogPeriod(uint32 nPeriod) {
if (clonemsg == NULL)
return NULL;

copyMemory(clonemsg, origmsg, i);
memcpy(clonemsg, origmsg, i);

globalUnlock(dialog->_periods[j]);

Expand Down Expand Up @@ -546,7 +546,7 @@ static LPITEM getItemData(uint32 nOrdItem) {

if (ret->_frames[i] == NULL)
return NULL;
copyMemory(ret->_frames[i], dat, dim);
memcpy(ret->_frames[i], dat, dim);
dat += dim;
}

Expand Down Expand Up @@ -906,7 +906,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
_ctx->MyActions[_ctx->k].perc = _ctx->curItem->Action[_ctx->j].perc;
_ctx->MyActions[_ctx->k].when = _ctx->curItem->Action[_ctx->j].when;
_ctx->MyActions[_ctx->k].nCmds = _ctx->curItem->Action[_ctx->j].nCmds;
copyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum,
memcpy(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum,
MAX_COMMANDS_PER_ACTION * sizeof(uint16));

_ctx->MyActions[_ctx->k].dwLastTime = g_vm->getTime();
Expand Down Expand Up @@ -995,12 +995,12 @@ void LocationPollThread(CORO_PARAM, const void *param) {
return;
}

copyMemory(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM));
memcpy(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM));
unlockItems();

/* We copy the action in #0 */
// _ctx->newItem->Action[0].nCmds = _ctx->curItem->Action[_ctx->j].nCmds;
// copyMemory(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0]));
// memcpy(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0]));
_ctx->newItem->dwRes=_ctx->j;

/* We will create an action, and will provide the necessary details */
Expand Down Expand Up @@ -1298,7 +1298,7 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) {
// In the new version number of the action in writing dwRes
Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem);
/* newitem->Action[0].nCmds=item->Action[i].nCmds;
copyMemory(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0]));
memcpy(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0]));
*/
newitem->dwRes = i;

Expand Down Expand Up @@ -1679,7 +1679,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) {
else {
lockItems();
y = itemGetOrderFromNum(x);
copyMemory(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE);
memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE);
unlockItems();
}

Expand Down Expand Up @@ -1857,7 +1857,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) {
else {
lockItems();
y = itemGetOrderFromNum(x);
copyMemory(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE);
memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE);
unlockItems();
}

Expand Down Expand Up @@ -1986,7 +1986,7 @@ bool mpalExecuteScript(int nScript) {
if (s == NULL)
return false;

copyMemory(s, GLOBALS._lpmsScripts + n, sizeof(MPALSCRIPT));
memcpy(s, GLOBALS._lpmsScripts + n, sizeof(MPALSCRIPT));
unlockScripts();

// !!! New process management
Expand Down Expand Up @@ -2095,7 +2095,7 @@ int mpalGetSaveStateSize() {
void mpalSaveState(byte *buf) {
lockVar();
WRITE_LE_UINT32(buf, GLOBALS._nVars);
copyMemory(buf + 4, (byte *)GLOBALS._lpmvVars, GLOBALS._nVars * sizeof(MPALVAR));
memcpy(buf + 4, (byte *)GLOBALS._lpmvVars, GLOBALS._nVars * sizeof(MPALVAR));
unlockVar();
}

Expand All @@ -2114,7 +2114,7 @@ int mpalLoadState(byte *buf) {

GLOBALS._hVars = globalAllocate(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS._nVars * sizeof(MPALVAR));
lockVar();
copyMemory((byte *)GLOBALS._lpmvVars, buf + 4, GLOBALS._nVars * sizeof(MPALVAR));
memcpy((byte *)GLOBALS._lpmvVars, buf + 4, GLOBALS._nVars * sizeof(MPALVAR));
unlockVar();

return GLOBALS._nVars * sizeof(MPALVAR) + 4;
Expand Down

0 comments on commit a9828c8

Please sign in to comment.