Skip to content

Commit

Permalink
Implement CelGetFrame (CEL decoder helper)
Browse files Browse the repository at this point in the history
This implements the first of the inlined CEL decoder helper functions
that are still visable in the Mac port code.

Functions are still bin exact
  • Loading branch information
AJenbo committed Sep 27, 2019
1 parent 449b9fd commit ce6fc51
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
8 changes: 3 additions & 5 deletions Source/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,14 +726,12 @@ void CPrintString(int nOffset, int nCel, char col)
labret:
}
#else
int i;
int i, nDataSize;
BYTE width, pix;
BYTE *src, *dst, *end;
DWORD *pFrameTable;

pFrameTable = (DWORD *)&pPanelText[4 * nCel];
src = &pPanelText[pFrameTable[0]];
end = &src[pFrameTable[1] - pFrameTable[0]];
src = CelGetFrame(pPanelText, nCel, &nDataSize);
end = &src[nDataSize];
dst = &gpBuffer[nOffset];

switch (col) {
Expand Down
50 changes: 24 additions & 26 deletions Source/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ BOOL gbNotInView; // valid - if x/y are in bounds
const int RndInc = 1;
const int RndMult = 0x015A4E35;

__FINLINE BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize)
{
DWORD *pFrameTable;
DWORD nCellStart;

pFrameTable = (DWORD *)pCelBuff;
nCellStart = SwapLE32(pFrameTable[nCel]);
*nDataSize = SwapLE32(pFrameTable[nCel + 1]) - nCellStart;

return pCelBuff + nCellStart;
}

void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
{
int w;
Expand Down Expand Up @@ -120,7 +132,8 @@ void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)

void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
{
DWORD *pFrameTable;
int nDataSize;
BYTE *pRLEBytes;

/// ASSERT: assert(gpBuffer);
if (!gpBuffer)
Expand All @@ -129,18 +142,14 @@ void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
if (!pCelBuff)
return;

pFrameTable = (DWORD *)pCelBuff;

CelDrawDatOnly(
&gpBuffer[sx + PitchTbl[sy]],
&pCelBuff[pFrameTable[nCel]],
pFrameTable[nCel + 1] - pFrameTable[nCel],
nWidth);
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
CelDrawDatOnly(&gpBuffer[sx + PitchTbl[sy]], pRLEBytes, nDataSize, nWidth);
}

void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth)
{
DWORD *pFrameTable;
int nDataSize;
BYTE *pRLEBytes;

/// ASSERT: assert(pCelBuff != NULL);
if (!pCelBuff)
Expand All @@ -149,13 +158,8 @@ void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth)
if (!pBuff)
return;

pFrameTable = (DWORD *)pCelBuff;

CelDrawDatOnly(
pBuff,
&pCelBuff[pFrameTable[nCel]],
pFrameTable[nCel + 1] - pFrameTable[nCel],
nWidth);
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
CelDrawDatOnly(pBuff, pRLEBytes, nDataSize, nWidth);
}

/**
Expand Down Expand Up @@ -580,7 +584,6 @@ void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
{
int nDataSize;
BYTE *pDecodeTo, *pRLEBytes;
DWORD *pFrameTable;

/// ASSERT: assert(gpBuffer);
if (!gpBuffer)
Expand All @@ -589,10 +592,7 @@ void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
if (!pCelBuff)
return;

pFrameTable = (DWORD *)pCelBuff;

nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel];
pRLEBytes = &pCelBuff[pFrameTable[nCel]];
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
pDecodeTo = &gpBuffer[sx + PitchTbl[sy]];

if (light_table_index)
Expand Down Expand Up @@ -1643,13 +1643,11 @@ void CelDecodeRect(BYTE *pBuff, int CelSkip, int hgt, int wdt, BYTE *pCelBuff, i
jnz label1
}
#else
int i;
int i, nDataSize;
BYTE width;
DWORD *pFrameTable;

pFrameTable = (DWORD *)&pCelBuff[4 * nCel];
pRLEBytes = &pCelBuff[pFrameTable[0]];
end = &pRLEBytes[pFrameTable[1] - pFrameTable[0]];
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
end = &pRLEBytes[nDataSize];
dst = &pBuff[hgt * wdt + CelSkip];

for (; pRLEBytes != end; dst -= wdt + nWidth) {
Expand Down
2 changes: 2 additions & 0 deletions Source/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ extern int orgseed;
extern int SeedCount;
extern BOOL gbNotInView; // valid - if x/y are in bounds

__FINLINE BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize);

void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth);
void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth);
void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth);
Expand Down
12 changes: 12 additions & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,15 @@ typedef void (*_PVFV)(void);
#else
#define ALIGN_BY_1
#endif

#if (_MSC_VER == 1200)
#define __FINLINE __forceinline
#else
#define __FINLINE
#endif

#ifndef _BIG_ENDIAN_
#define SwapLE32
#else
#define SwapLE32(value) (value << 24 | (value & 0xFF00) << 8 | (value & 0xFF0000) >> 8 | value >> 24);
#endif

0 comments on commit ce6fc51

Please sign in to comment.