diff --git a/3rdParty/Storm/Source/storm.cpp b/3rdParty/Storm/Source/storm.cpp index 85222a4f5..583be190c 100644 --- a/3rdParty/Storm/Source/storm.cpp +++ b/3rdParty/Storm/Source/storm.cpp @@ -96,7 +96,7 @@ BOOL STORMAPI SBltROP3Tiled(void *lpDstBuffer, RECT *lpDstRect, POINT *lpDstPt, BOOL STORMAPI SBmpDecodeImage(DWORD dwImgType, void *pSrcBuffer, DWORD dwSrcBuffersize, PALETTEENTRY *pPalette, void *pDstBuffer, DWORD dwDstBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp) rBool; -BOOL STORMAPI SBmpLoadImage(const char *pszFileName, PALETTEENTRY *pPalette, void *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *dwHeight, DWORD *pdwBpp) rBool; +BOOL STORMAPI SBmpLoadImage(const char *pszFileName, PALETTEENTRY *pPalette, BYTE *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp) rBool; BOOL STORMAPI SBmpSaveImage(const char*, PALETTEENTRY*, void*, DWORD, DWORD, DWORD) rBool; HANDLE STORMAPI SBmpAllocLoadImage(const char *fileName, PALETTEENTRY *palette, void **buffer, int *width, int *height, int unused6, int unused7, void *(STORMAPI *allocFunction)(DWORD)) rPVoid; diff --git a/DiabloUI/_temp_funcs.h b/DiabloUI/_temp_funcs.h index 55cf681af..2780abe9f 100644 --- a/DiabloUI/_temp_funcs.h +++ b/DiabloUI/_temp_funcs.h @@ -70,7 +70,7 @@ char *__stdcall BNetGW_10002E0B(char *a1, unsigned int a2); void __cdecl Connect_FreeConnectData(); BOOL __cdecl Connect_LoadGFXAndStuff(); -BOOL __stdcall UiArtCallback(int game_type, unsigned int art_code, PALETTEENTRY *pPalette, void *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp); +BOOL __stdcall UiArtCallback(int game_type, unsigned int art_code, PALETTEENTRY *pPalette, BYTE *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp); void __cdecl j_Connect_cpp_init(); void __cdecl Connect_cpp_init(); BOOL __stdcall UiGetDataCallback(int game_type, int data_code, void *a3, int a4, int a5); diff --git a/DiabloUI/connect.cpp b/DiabloUI/connect.cpp index 0fbd485c9..bdd98d715 100644 --- a/DiabloUI/connect.cpp +++ b/DiabloUI/connect.cpp @@ -72,7 +72,7 @@ BOOL __cdecl Connect_LoadGFXAndStuff() // 100295C0: using guessed type int heroport_frames; // ref: 0x10003009 -BOOL __stdcall UiArtCallback(int game_type, unsigned int art_code, PALETTEENTRY *pPalette, void *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp) +BOOL __stdcall UiArtCallback(int game_type, unsigned int art_code, PALETTEENTRY *pPalette, BYTE *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp) { BOOL result; // eax char pszFileName[260]; // [esp+8h] [ebp-104h] diff --git a/DiabloUI/diabloui.h b/DiabloUI/diabloui.h index a222ef3cb..dd16d51f9 100644 --- a/DiabloUI/diabloui.h +++ b/DiabloUI/diabloui.h @@ -46,7 +46,7 @@ BOOL __stdcall UiSoundCallback(int a1, int type, int a3); void __stdcall UiMessageBoxCallback(HWND hWnd, char *lpText, LPCSTR lpCaption, UINT uType); BOOL __stdcall UiDrawDescCallback(int game_type, COLORREF color, LPCSTR lpString, char *a4, int a5, UINT align, time_t a7, HDC *a8); BOOL __stdcall UiCreateGameCallback(int a1, int a2, int a3, int a4, int a5, int a6); -BOOL __stdcall UiArtCallback(int game_type, unsigned int art_code, PALETTEENTRY *pPalette, void *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp); +BOOL __stdcall UiArtCallback(int game_type, unsigned int art_code, PALETTEENTRY *pPalette, BYTE *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp); int __stdcall UiSelectGame(int a1, _SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info, _SNETUIDATA *ui_info, _SNETVERSIONDATA *file_info, int *a6); int __stdcall UiSelectProvider(int a1, _SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info, _SNETUIDATA *ui_info, _SNETVERSIONDATA *file_info, int *type); BOOL __stdcall UiCreatePlayerDescription(_uiheroinfo *info, DWORD mode, char *desc); diff --git a/Source/asm_trans_rect.inc b/Source/asm_trans_rect.inc index 643d62e73..12ef861a6 100644 --- a/Source/asm_trans_rect.inc +++ b/Source/asm_trans_rect.inc @@ -50,7 +50,7 @@ x2loop: #else // _MSC_VER && _M_IX86 { int row, col; - char *pix = &gpBuffer->row[TRANS_RECT_Y + TRANS_RECT_HEIGHT - 1].pixels[TRANS_RECT_X]; + BYTE *pix = &gpBuffer[SCREENXY(TRANS_RECT_X, TRANS_RECT_Y + TRANS_RECT_HEIGHT - 1)]; for (row = TRANS_RECT_HEIGHT >> 1; row != 0; row--) { for (col = TRANS_RECT_WIDTH >> 1; col != 0; col--) { *pix++ = 0; diff --git a/Source/automap.cpp b/Source/automap.cpp index 00a963a3c..a7d8e1272 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -177,7 +177,7 @@ void __cdecl DrawAutomap() return; } - gpBufEnd = (unsigned char *)&gpBuffer->row[352]; + gpBufEnd = (unsigned char *)&gpBuffer[(352 + 160) * 768]; MapX = (ViewX - 16) >> 1; while (MapX + AutoMapXOfs < 0) diff --git a/Source/capture.cpp b/Source/capture.cpp index ba1ce0f40..beb09f8e7 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -24,7 +24,7 @@ void __cdecl CaptureScreen() j_lock_buf_priv(2); success = CaptureHdr(hObject, 640, 480); if (success) { - success = CapturePix(hObject, 640, 480, 768, (BYTE *)gpBuffer->row[0].pixels); + success = CapturePix(hObject, 640, 480, 768, &gpBuffer[SCREENXY(0, 0)]); if (success) { success = CapturePal(hObject, palette); } diff --git a/Source/control.cpp b/Source/control.cpp index 9f1375556..c8b0dbf61 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -187,12 +187,11 @@ int SpellPages[6][7] = { void __fastcall DrawSpellCel(int xp, int yp, BYTE *Trans, int nCel, int w) { - BYTE *tmp, *dst, *tbl, *end; + BYTE *dst, *tbl, *end; /// ASSERT: assert(gpBuffer); - tmp = (BYTE *)gpBuffer; /* remove when fixed */ - dst = &tmp[screen_y_times_768[yp] + xp]; + dst = &gpBuffer[xp + screen_y_times_768[yp]]; tbl = SplTransTbl; #if (_MSC_VER >= 800) && (_MSC_VER <= 1200) @@ -846,7 +845,7 @@ void __fastcall DrawPanelBox(int x, int y, int w, int h, int sx, int sy) unsigned int v11; // ecx v6 = (char *)pBtmBuff + 640 * y + x; - v7 = &gpBuffer->row_unused_1[sy].col_unused_1[sx]; + v7 = (char *)&gpBuffer[768 * sy + sx]; v8 = h; do { v9 = w >> 1; @@ -872,7 +871,7 @@ void __fastcall SetFlaskHeight(char *buf, int min, int max, int c, int r) int v7; // edx v5 = &buf[88 * min]; - v6 = &gpBuffer->row_unused_1[r].col_unused_1[c]; + v6 = (char *)&gpBuffer[768 * r + c]; v7 = max - min; do { qmemcpy(v6, v5, 0x58u); @@ -2270,7 +2269,7 @@ void __cdecl RedBack() _LOWORD(v0) = v0 & 0xF400; v12 = v0 + 768 * 6; if (leveltype == DTYPE_HELL) { - v7 = gpBuffer->row[0].pixels; + v7 = (char *)&gpBuffer[SCREENXY(0, 0)]; _EBX = &pLightTbl[v12]; v9 = 352; do { @@ -2286,7 +2285,7 @@ void __cdecl RedBack() --v9; } while (v9); } else { - v1 = gpBuffer->row[0].pixels; + v1 = (char *)&gpBuffer[SCREENXY(0, 0)]; _EBX = &pLightTbl[v12]; v3 = 352; do { diff --git a/Source/dx.cpp b/Source/dx.cpp index 1122b9c78..fc0727356 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -4,11 +4,11 @@ DEVILUTION_BEGIN_NAMESPACE -Screen *sgpBackBuf; +BYTE *sgpBackBuf; LPDIRECTDRAW lpDDInterface; IDirectDrawPalette *lpDDPalette; // idb int sgdwLockCount; -Screen *gpBuffer; +BYTE *gpBuffer; IDirectDrawSurface *lpDDSBackBuf; IDirectDrawSurface *lpDDSPrimary; #ifdef _DEBUG @@ -130,7 +130,7 @@ void __cdecl dx_create_back_buffer() #else lpDDSPrimary->lpVtbl->Unlock(lpDDSPrimary, NULL); #endif - sgpBackBuf = (Screen *)DiabloAllocPtr(sizeof(Screen)); + sgpBackBuf = (BYTE *)DiabloAllocPtr(656 * 768); return; } if (error_code != DDERR_CANTLOCKSURFACE) @@ -240,7 +240,7 @@ void __cdecl lock_buf_priv() DDErrMsg(error_code, 235, "C:\\Src\\Diablo\\Source\\dx.cpp"); gpBufEnd += (int)ddsd.lpSurface; - gpBuffer = (Screen *)ddsd.lpSurface; + gpBuffer = (BYTE *)ddsd.lpSurface; sgdwLockCount++; } @@ -282,7 +282,7 @@ void __cdecl unlock_buf_priv() void __cdecl dx_cleanup() { - Screen *v0; // ecx + BYTE *v0; // ecx if (ghMainWnd) ShowWindow(ghMainWnd, SW_HIDE); diff --git a/Source/dx.h b/Source/dx.h index 8597def2d..e5ae74a8d 100644 --- a/Source/dx.h +++ b/Source/dx.h @@ -4,7 +4,7 @@ extern IDirectDraw *lpDDInterface; extern IDirectDrawPalette *lpDDPalette; // idb -extern Screen *gpBuffer; +extern BYTE *gpBuffer; extern IDirectDrawSurface *lpDDSBackBuf; extern IDirectDrawSurface *lpDDSPrimary; extern char gbBackBuf; // weak diff --git a/Source/effects.cpp b/Source/effects.cpp index 6cd68febf..b1ed23f2b 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -1158,6 +1158,7 @@ void __cdecl sound_update() sfx_stop(); } } + // 415DBA: could not find valid save-restore pair for ebp void __cdecl effects_cleanup_sfx() diff --git a/Source/engine.cpp b/Source/engine.cpp index 9d9d73caf..22c026b0c 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -121,7 +121,6 @@ void __fastcall CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, void __fastcall CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) { - BYTE *tmp; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); @@ -131,11 +130,10 @@ void __fastcall CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWid if(!pCelBuff) return; - tmp = (BYTE *)gpBuffer; pFrameTable = (DWORD *)pCelBuff; CelDrawDatOnly( - &tmp[sx + screen_y_times_768[sy]], + &gpBuffer[sx + screen_y_times_768[sy]], &pCelBuff[pFrameTable[nCel]], pFrameTable[nCel + 1] - pFrameTable[nCel], nWidth); @@ -164,7 +162,7 @@ void __fastcall CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth) void __fastcall CelDrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int v1, v2, nDataSize; - BYTE *pRLEBytes, *tmp; + BYTE *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); @@ -192,9 +190,8 @@ void __fastcall CelDrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWi else nDataSize -= v1; - tmp = (BYTE *)gpBuffer; CelDrawDatOnly( - &tmp[sx + screen_y_times_768[sy - 16 * always_0]], + &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]], &pRLEBytes[v1], nDataSize, nWidth); @@ -577,7 +574,7 @@ L_ODD: void __fastcall CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) { int nDataSize; - BYTE *pDecodeTo, *pRLEBytes, *tmp; + BYTE *pDecodeTo, *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); @@ -587,12 +584,11 @@ void __fastcall CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int if(!pCelBuff) return; - tmp = (BYTE *)gpBuffer; pFrameTable = (DWORD *)pCelBuff; nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; pRLEBytes = &pCelBuff[pFrameTable[nCel]]; - pDecodeTo = &tmp[sx + screen_y_times_768[sy]]; + pDecodeTo = &gpBuffer[sx + screen_y_times_768[sy]]; if(light_table_index) CelDecDatLightOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); @@ -604,7 +600,7 @@ void __fastcall CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int void __fastcall CelDecodeHdrLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int hdr, nDataSize, v1, v2; - BYTE *pRLEBytes, *pDecodeTo, *tmp, *v9; + BYTE *pRLEBytes, *pDecodeTo, *v9; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); @@ -631,8 +627,7 @@ void __fastcall CelDecodeHdrLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, nDataSize = v1 - hdr; pRLEBytes = &v9[hdr]; - tmp = (BYTE *)gpBuffer; - pDecodeTo = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + pDecodeTo = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; if(light_table_index) CelDecDatLightOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); @@ -685,7 +680,7 @@ void __fastcall CelDecodeHdrLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, in void __fastcall CelDrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir, char light) { int w, hdr, idx, nDataSize, v1; - BYTE *src, *dst, *tbl, *tmp, *pRLEBytes; + BYTE *src, *dst, *tbl, *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); @@ -711,8 +706,7 @@ void __fastcall CelDrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nDataSize = pFrameTable[1] - pFrameTable[0] - hdr; src = &pRLEBytes[hdr]; - tmp = (BYTE *)gpBuffer; - dst = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + dst = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; idx = light4flag ? 1024 : 4096; if(light == 2) @@ -910,7 +904,7 @@ void __fastcall Cel2DecDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, void __fastcall Cel2DrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int v1, v2, nDataSize; - BYTE *pRLEBytes, *tmp; + BYTE *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); @@ -938,9 +932,8 @@ void __fastcall Cel2DrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nW else nDataSize -= v1; - tmp = (BYTE *)gpBuffer; Cel2DecDatOnly( - &tmp[sx + screen_y_times_768[sy - 16 * always_0]], + &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]], &pRLEBytes[v1], nDataSize, nWidth); @@ -1353,7 +1346,7 @@ L_ODD: void __fastcall Cel2DecodeHdrLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int hdr, nDataSize, v1; - BYTE *pRLEBytes, *pDecodeTo, *tmp, *v9; + BYTE *pRLEBytes, *pDecodeTo, *v9; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); @@ -1378,8 +1371,7 @@ void __fastcall Cel2DecodeHdrLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nDataSize = pFrameTable[1] - pFrameTable[0] - hdr; pRLEBytes = &v9[hdr]; - tmp = (BYTE *)gpBuffer; - pDecodeTo = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + pDecodeTo = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; if(light_table_index) Cel2DecDatLightOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); @@ -1428,7 +1420,7 @@ void __fastcall Cel2DecodeLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int void __fastcall Cel2DrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir, char light) { int w, hdr, idx, nDataSize, v1; - BYTE *src, *dst, *tbl, *tmp, *pRLEBytes; + BYTE *src, *dst, *tbl, *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); @@ -1454,8 +1446,7 @@ void __fastcall Cel2DrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, in nDataSize = pFrameTable[1] - pFrameTable[0] - hdr; src = &pRLEBytes[hdr]; - tmp = (BYTE *)gpBuffer; - dst = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + dst = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; idx = light4flag ? 1024 : 4096; if(light == 2) @@ -1667,7 +1658,7 @@ void __fastcall CelDecodeRect(BYTE *pBuff, int always_0, int hgt, int wdt, BYTE void __fastcall CelDecodeClr(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int w, hdr, nDataSize, v1; - BYTE *src, *dst, *tmp; + BYTE *src, *dst; /// ASSERT: assert(pCelBuff != NULL); if(!pCelBuff) @@ -1709,8 +1700,7 @@ void __fastcall CelDecodeClr(char col, int sx, int sy, BYTE *pCelBuff, int nCel, nDataSize -= hdr; src += hdr; - tmp = (BYTE *)gpBuffer; - dst = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + dst = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; __asm { mov esi, src @@ -1775,8 +1765,7 @@ void __fastcall CelDecodeClr(char col, int sx, int sy, BYTE *pCelBuff, int nCel, src = &pRLEBytes[hdr]; end = &src[nDataSize]; - tmp = (BYTE *)gpBuffer; - dst = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + dst = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; for(; src != end; dst -= 768 + nWidth) { for(w = nWidth; w;) { @@ -1806,7 +1795,7 @@ void __fastcall CelDecodeClr(char col, int sx, int sy, BYTE *pCelBuff, int nCel, void __fastcall CelDrawHdrClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int w, hdr, nDataSize, v1; - BYTE *src, *dst, *tmp; + BYTE *src, *dst; /// ASSERT: assert(pCelBuff != NULL); if(!pCelBuff) @@ -1848,8 +1837,7 @@ void __fastcall CelDrawHdrClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nC nDataSize -= hdr; src += hdr; - tmp = (BYTE *)gpBuffer; - dst = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + dst = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; __asm { mov esi, src @@ -1939,8 +1927,7 @@ void __fastcall CelDrawHdrClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nC src = &pRLEBytes[hdr]; end = &src[nDataSize]; - tmp = (BYTE *)gpBuffer; - dst = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + dst = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; for(; src != end; dst -= 768 + nWidth) { for(w = nWidth; w;) { @@ -2459,7 +2446,7 @@ void __fastcall Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel) void __fastcall Cl2DecodeFrm1(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int hdr, nDataSize; - BYTE *pRLEBytes, *tmp; + BYTE *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -2487,9 +2474,8 @@ void __fastcall Cl2DecodeFrm1(int sx, int sy, BYTE *pCelBuff, int nCel, int nWid if(!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - tmp = (BYTE *)gpBuffer; Cl2DecDatFrm1( - &tmp[sx + screen_y_times_768[sy - 16 * always_0]], + &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]], &pRLEBytes[hdr], nDataSize - hdr, nWidth); @@ -2639,7 +2625,7 @@ void __fastcall Cl2DecDatFrm1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, i void __fastcall Cl2DecodeFrm2(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int hdr, nDataSize; - BYTE *pRLEBytes, *tmp; + BYTE *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -2667,9 +2653,8 @@ void __fastcall Cl2DecodeFrm2(char col, int sx, int sy, BYTE *pCelBuff, int nCel if(!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - tmp = (BYTE *)gpBuffer; Cl2DecDatFrm2( - &tmp[sx + screen_y_times_768[sy - 16 * always_0]], + &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]], &pRLEBytes[hdr], nDataSize - hdr, nWidth, @@ -2841,7 +2826,7 @@ void __fastcall Cl2DecDatFrm2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, i void __fastcall Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir, char light) { int hdr, idx, nDataSize; - BYTE *pRLEBytes, *tmp; + BYTE *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -2875,9 +2860,8 @@ void __fastcall Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWid if(light >= 4) idx += (light - 1) << 8; - tmp = (BYTE *)gpBuffer; Cl2DecDatLightTbl1( - &tmp[sx + screen_y_times_768[sy - 16 * always_0]], + &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]], &pRLEBytes[hdr], nDataSize - hdr, nWidth, @@ -3039,7 +3023,7 @@ void __fastcall Cl2DecDatLightTbl1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSi void __fastcall Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int hdr, nDataSize; - BYTE *pRLEBytes, *pDecodeTo, *tmp; + BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -3067,8 +3051,7 @@ void __fastcall Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int if(!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - tmp = (BYTE *)gpBuffer; - pDecodeTo = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + pDecodeTo = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; if(light_table_index) Cl2DecDatLightTbl1(pDecodeTo, &pRLEBytes[hdr], nDataSize - hdr, nWidth, (BYTE *)&pLightTbl[light_table_index * 256]); @@ -3080,7 +3063,7 @@ void __fastcall Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int void __fastcall Cl2DecodeFrm4(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int hdr, nDataSize; - BYTE *pRLEBytes, *tmp; + BYTE *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -3108,9 +3091,8 @@ void __fastcall Cl2DecodeFrm4(int sx, int sy, BYTE *pCelBuff, int nCel, int nWid if(!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - tmp = (BYTE *)gpBuffer; Cl2DecDatFrm4( - &tmp[sx + screen_y_times_768[sy - 16 * always_0]], + &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]], &pRLEBytes[hdr], nDataSize - hdr, nWidth); @@ -3274,7 +3256,7 @@ void __fastcall Cl2DecDatFrm4(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, i void __fastcall Cl2DecodeClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int hdr, nDataSize; - BYTE *pRLEBytes, *tmp; + BYTE *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -3302,10 +3284,9 @@ void __fastcall Cl2DecodeClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCe if(!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - tmp = (BYTE *)gpBuffer; gpBufEnd -= 768; Cl2DecDatClrHL( - &tmp[sx + screen_y_times_768[sy - 16 * always_0]], + &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]], &pRLEBytes[hdr], nDataSize - hdr, nWidth, @@ -3491,7 +3472,7 @@ void __fastcall Cl2DecDatClrHL(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, void __fastcall Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir, char light) { int hdr, idx, nDataSize; - BYTE *pRLEBytes, *tmp; + BYTE *pRLEBytes; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -3525,9 +3506,8 @@ void __fastcall Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWid if(light >= 4) idx += (light - 1) << 8; - tmp = (BYTE *)gpBuffer; Cl2DecDatLightTbl2( - &tmp[sx + screen_y_times_768[sy - 16 * always_0]], + &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]], &pRLEBytes[hdr], nDataSize - hdr, nWidth, @@ -3703,7 +3683,7 @@ void __fastcall Cl2DecDatLightTbl2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSi void __fastcall Cl2DecodeFrm6(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int always_0, int dir) { int hdr, nDataSize; - BYTE *pRLEBytes, *pDecodeTo, *tmp; + BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -3731,8 +3711,7 @@ void __fastcall Cl2DecodeFrm6(int sx, int sy, BYTE *pCelBuff, int nCel, int nWid if(!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - tmp = (BYTE *)gpBuffer; - pDecodeTo = &tmp[sx + screen_y_times_768[sy - 16 * always_0]]; + pDecodeTo = &gpBuffer[sx + screen_y_times_768[sy - 16 * always_0]]; if(light_table_index) Cl2DecDatLightTbl2(pDecodeTo, &pRLEBytes[hdr], nDataSize - hdr, nWidth, (BYTE *)&pLightTbl[light_table_index * 256]); diff --git a/Source/inv.cpp b/Source/inv.cpp index 5eb5e3b77..32f19f590 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -283,8 +283,8 @@ void __cdecl DrawInv() CelDecodeHdrLightTrans( frame_width == INV_SLOT_SIZE_PX - ? (BYTE *)&gpBuffer->row[160].pixels[581] - : (BYTE *)&gpBuffer->row[160].pixels[567], + ? &gpBuffer[SCREENXY(581, 160)] + : &gpBuffer[SCREENXY(567, 160)], (BYTE *)pCursCels, frame, frame_width, 0, 8); cel_transparency_active = 0; diff --git a/Source/items.cpp b/Source/items.cpp index 86f27e852..39c37415b 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3767,8 +3767,8 @@ void __fastcall DrawULine(int y) char *v2; // edi signed int v3; // edx - v1 = &gpBuffer->row[25].pixels[26]; - v2 = &gpBuffer->row_unused_1[0].pixels[screen_y_times_768[SStringY[y] + 198] + 26]; + v1 = (char *)&gpBuffer[SCREENXY(26, 25)]; + v2 = (char *)&gpBuffer[screen_y_times_768[SStringY[y] + 198] + 26 + 64]; v3 = 3; do { qmemcpy(v2, v1, 0x10A); /* find real fix */ @@ -4129,15 +4129,18 @@ void __fastcall UseItem(int p, int Mid, int spl) } } -BOOLEAN __fastcall StoreStatOk(ItemStruct *h) +BOOL __fastcall StoreStatOk(ItemStruct *h) { - BOOLEAN sf; // al + BOOL sf; + + sf = TRUE; + if (plr[myplr]._pStrength < h->_iMinStr) + sf = FALSE; + if (plr[myplr]._pMagic < h->_iMinMag) + sf = FALSE; + if (plr[myplr]._pDexterity < h->_iMinDex) + sf = FALSE; - sf = 1; - if (plr[myplr]._pStrength < h->_iMinStr - || plr[myplr]._pMagic < h->_iMinMag - || plr[myplr]._pDexterity < h->_iMinDex) - sf = 0; return sf; } diff --git a/Source/items.h b/Source/items.h index cd058139e..e8c86fbab 100644 --- a/Source/items.h +++ b/Source/items.h @@ -88,7 +88,7 @@ void __fastcall PrintItemMisc(ItemStruct *x); void __fastcall PrintItemDetails(ItemStruct *x); void __fastcall PrintItemDur(ItemStruct *x); void __fastcall UseItem(int p, int Mid, int spl); -BOOLEAN __fastcall StoreStatOk(ItemStruct *h); +BOOL __fastcall StoreStatOk(ItemStruct *h); BOOL __fastcall SmithItemOk(int i); int __fastcall RndSmithItem(int lvl); void __fastcall BubbleSwapItem(ItemStruct *a, ItemStruct *b); diff --git a/Source/minitext.cpp b/Source/minitext.cpp index ec58a99fb..78b497586 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -96,59 +96,121 @@ void __cdecl DrawQTextBack() #include "asm_trans_rect.inc" } -void __fastcall PrintQTextChr(int screen_x, int screen_y, char *cel_buf, int frame) +void __fastcall PrintQTextChr(int sx, int sy, BYTE *pCelBuff, int nCel) { - char *v4; // ebx - char *v5; // esi - char *v6; // edi - int v7; // ebx - signed int v8; // edx - unsigned int v9; // eax - unsigned int v10; // ecx - char v11; // cf - unsigned int v12; // ecx - char *v13; // [esp+14h] [ebp-8h] - char *v14; // [esp+18h] [ebp-4h] + BYTE *dst, *pStart, *pEnd, *end; - v13 = (char *)gpBuffer + screen_y_times_768[209]; - v14 = (char *)gpBuffer + screen_y_times_768[469]; - v4 = &cel_buf[4 * frame]; - v5 = &cel_buf[*(_DWORD *)v4]; - v6 = (char *)gpBuffer + screen_y_times_768[screen_y] + screen_x; - v7 = (int)&v5[*((_DWORD *)v4 + 1) - *(_DWORD *)v4]; - do { - v8 = 22; - do { - while (1) { - v9 = (unsigned char)*v5++; - if ((v9 & 0x80u) == 0) - break; - _LOBYTE(v9) = -(char)v9; - v6 += v9; - v8 -= v9; - if (!v8) - goto LABEL_15; - } - v8 -= v9; - if (v6 < v13 || v6 > v14) { - v5 += v9; - v6 += v9; - } else { - v10 = v9 >> 1; - if (!(v9 & 1) || (*v6 = *v5, ++v5, ++v6, v10)) { - v11 = v10 & 1; - v12 = v9 >> 2; - if (!v11 || (*(_WORD *)v6 = *(_WORD *)v5, v5 += 2, v6 += 2, v12)) { - qmemcpy(v6, v5, 4 * v12); - v5 += 4 * v12; - v6 += 4 * v12; + /// ASSERT: assert(gpBuffer); + + dst = &gpBuffer[sx + screen_y_times_768[sy]]; + pStart = &gpBuffer[screen_y_times_768[209]]; + pEnd = &gpBuffer[screen_y_times_768[469]]; + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov ebx, pCelBuff + mov eax, nCel + shl eax, 2 + add ebx, eax + mov eax, [ebx+4] + sub eax, [ebx] + mov end, eax + mov esi, pCelBuff + add esi, [ebx] + mov edi, dst + mov ebx, end + add ebx, esi + label1: + mov edx, 22 + label2: + xor eax, eax + lodsb + or al, al + js label7 + sub edx, eax + cmp edi, pStart + jb label5 + cmp edi, pEnd + ja label5 + mov ecx, eax + shr ecx, 1 + jnb label3 + movsb + jecxz label6 + label3: + shr ecx, 1 + jnb label4 + movsw + jecxz label6 + label4: + rep movsd + jmp label6 + label5: + add esi, eax + add edi, eax + label6: + or edx, edx + jz label8 + jmp label2 + label7: + neg al + add edi, eax + sub edx, eax + jnz label2 + label8: + sub edi, 768 + 22 + cmp ebx, esi + jnz label1 + } +#else + int i; + BYTE width; + BYTE *src; + DWORD *pFrameTable; + + pFrameTable = (DWORD *)&pCelBuff[4 * nCel]; + src = &pCelBuff[pFrameTable[0]]; + end = &src[pFrameTable[1] - pFrameTable[0]]; + + for(; src != end; dst -= 768 + 22) { + for(i = 22; i;) { + width = *src++; + if(!(width & 0x80)) { + i -= width; + if(dst >= pStart && dst <= pEnd) { + if(width & 1) { + dst[0] = src[0]; + src++; + dst++; + } + width >>= 1; + if(width & 1) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 2; + dst += 2; + } + width >>= 1; + for(; width; width--) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + src += 4; + dst += 4; } + } else { + src += width; + dst += width; } + } else { + width = -(char)width; + dst += width; + i -= width; } - } while (v8); - LABEL_15: - v6 -= 790; - } while ((char *)v7 != v5); + } + } +#endif } void __cdecl DrawQText() @@ -213,7 +275,7 @@ void __cdecl DrawQText() if (*v0 == 10) ++v0; if (v10) - PrintQTextChr(screen_x, screen_y, (char *)pMedTextCels, v10); + PrintQTextChr(screen_x, screen_y, (BYTE *)pMedTextCels, v10); ++v9; screen_x += mfontkern[v10] + 2; v8 = *v9; diff --git a/Source/minitext.h b/Source/minitext.h index 8c7797047..fa27ae73c 100644 --- a/Source/minitext.h +++ b/Source/minitext.h @@ -14,7 +14,7 @@ void __cdecl FreeQuestText(); void __cdecl InitQuestText(); void __fastcall InitQTextMsg(int m); void __cdecl DrawQTextBack(); -void __fastcall PrintQTextChr(int screen_x, int screen_y, char *cel_buf, int frame); +void __fastcall PrintQTextChr(int sx, int sy, BYTE *pCelBuff, int nCel); void __cdecl DrawQText(); /* rdata */ diff --git a/Source/missiles.cpp b/Source/missiles.cpp index d0c4c02e4..ea201953e 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -5507,33 +5507,26 @@ void __cdecl ProcessMissiles() void __cdecl missiles_process_charge() { - int v0; // ebx - int i; // edi - int v2; // ecx - int v3; // esi - BOOLEAN v4; // zf - CMonster *v5; // eax - char v6; // dl - AnimStruct *v7; // eax - - v0 = nummissiles; - for (i = 0; i < v0; ++i) { - v2 = missileactive[i]; - v3 = missile[v2]._mimfnum; - v4 = missile[v2]._mitype == MIS_RHINO; - missile[v2]._miAnimData = misfiledata[0].mAnimData[v3 + 59 * _LOBYTE(missile[v2]._miAnimType)]; - if (v4) { - v5 = monster[missile[v2]._misource].MType; - v6 = v5->mtype; - if (v5->mtype < MT_HORNED || v6 > MT_OBLORD) { - if (v6 < MT_NSNAKE || v6 > MT_GSNAKE) - v7 = &v5->Anims[MA_WALK]; - else - v7 = &v5->Anims[MA_ATTACK]; + CMonster *mon; + AnimStruct *anim; + MissileStruct *mis; + int i, mi; + + for (i = 0; i < nummissiles; i++) { + mi = missileactive[i]; + mis = &missile[mi]; + mis->_miAnimData = misfiledata[mis->_miAnimType].mAnimData[mis->_mimfnum]; + if (mis->_mitype == MIS_RHINO) { + mon = monster[mis->_misource].MType; + if (mon->mtype >= MT_HORNED && mon->mtype <= MT_OBLORD) { + anim = &mon->Anims[MA_SPECIAL]; } else { - v7 = &v5->Anims[MA_SPECIAL]; + if (mon->mtype >= MT_NSNAKE && mon->mtype <= MT_GSNAKE) + anim = &mon->Anims[MA_ATTACK]; + else + anim = &mon->Anims[MA_WALK]; } - missile[v2]._miAnimData = v7->Data[v3]; + missile[mi]._miAnimData = anim->Data[mis->_mimfnum]; } } } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 0178a2633..435c8dfcb 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -2465,7 +2465,7 @@ void __fastcall DrawZoom(int x, int y) LABEL_24: v11 = (_WORD *)((char *)gpBuffer + a6b); v12 = (char *)gpBuffer + a5a; - v13 = &gpBuffer->row_unused_1[1].col_unused_1[a6b]; + v13 = (char *)&gpBuffer[a6b + 768]; v14 = 176; do { v15 = v19; @@ -2501,7 +2501,7 @@ void __cdecl ClearScreenBuffer() j_lock_buf_priv(3); for (i = 0; i < 480; i++) - memset(gpBuffer->row[i].pixels, 0, 640); + memset(&gpBuffer[SCREENXY(0, i)], 0, 640); j_unlock_buf_priv(3); } @@ -2629,7 +2629,7 @@ void __cdecl scrollrt_draw_cursor_back_buffer() if (sgdwCursWdt) { v1 = sgdwCursY; v2 = sgSaveBack; - v3 = &gpBuffer->row[sgdwCursY].pixels[sgdwCursX]; + v3 = (char *)&gpBuffer[SCREENXY(sgdwCursX, sgdwCursY)]; v4 = sgdwCursHgt; if (sgdwCursHgt) { v5 = sgdwCursHgt; @@ -2701,7 +2701,7 @@ void __cdecl scrollrt_draw_cursor_item() v14 = sgSaveBack; v6 = 1 - v3 + v5; sgdwCursHgt = v6; - v7 = &gpBuffer->row[v3].pixels[v2 & 0xFFFFFFFC]; + v7 = (char *)&gpBuffer[SCREENXY(v2 & 0xFFFFFFFC, v3)]; if (v6) { v8 = v6; do { diff --git a/Source/sound.cpp b/Source/sound.cpp index 8cdb5c326..02f706f31 100644 --- a/Source/sound.cpp +++ b/Source/sound.cpp @@ -6,7 +6,7 @@ DEVILUTION_BEGIN_NAMESPACE LPDIRECTSOUNDBUFFER DSBs[8]; LPDIRECTSOUND sglpDS; -char gbSndInited; +BOOLEAN gbSndInited; int sglMusicVolume; int sglSoundVolume; HMODULE hDsound_dll; diff --git a/Source/sound.h b/Source/sound.h index 9ef9a2f2d..ffc0439f2 100644 --- a/Source/sound.h +++ b/Source/sound.h @@ -3,7 +3,7 @@ #define __SOUND_H__ extern IDirectSoundBuffer *DSBs[8]; -extern char gbSndInited; +extern BOOLEAN gbSndInited; extern HMODULE hDsound_dll; void __fastcall snd_update(BOOL bStopAll); diff --git a/Source/stores.cpp b/Source/stores.cpp index 9cdaebb1c..8f628dff8 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -579,35 +579,36 @@ void __cdecl S_StartSmith() void __fastcall S_ScrollSBuy(int idx) { - int v1; // esi - int v2; // edi - char *v3; // esi - char *v4; // eax - int iclr; // [esp+Ch] [ebp-4h] + int y; + char clr; - v1 = idx; - v2 = 5; ClearSText(5, 21); - v3 = &smithitem[v1]._iMagical; stextup = 5; - do { - if (*((_DWORD *)v3 - 13) != -1) { - _LOBYTE(iclr) = COL_WHITE; - if (*v3) - _LOBYTE(iclr) = COL_BLUE; - if (!*((_DWORD *)v3 + 74)) - _LOBYTE(iclr) = COL_RED; - v4 = v3 + 65; - if (!*v3) - v4 = v3 + 1; - AddSText(20, v2, 0, v4, iclr, 1); - AddSTextVal(v2, *((_DWORD *)v3 + 35)); - PrintStoreItem((ItemStruct *)(v3 - 60), v2 + 1, iclr); - stextdown = v2; - v3 += 368; + + for (y = 5; y < 20; y += 4) { + if (smithitem[idx]._itype != -1) { + clr = COL_WHITE; + if (smithitem[idx]._iMagical) { + clr = COL_BLUE; + } + + if (!smithitem[idx]._iStatFlag) { + clr = COL_RED; + } + + if (smithitem[idx]._iMagical) { + AddSText(20, y, 0, smithitem[idx]._iIName, clr, 1); + } else { + AddSText(20, y, 0, smithitem[idx]._iName, clr, 1); + } + + AddSTextVal(y, smithitem[idx]._iIvalue); + PrintStoreItem(&smithitem[idx], y + 1, clr); + stextdown = y; + idx++; } - v2 += 4; - } while (v2 < 20); + } + if (!stext[stextsel]._ssel && stextsel != 22) stextsel = stextdown; } diff --git a/Source/town.cpp b/Source/town.cpp index 2aaa6250f..6304a3959 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -4,83 +4,143 @@ DEVILUTION_BEGIN_NAMESPACE -void __fastcall town_clear_upper_buf(unsigned char *a1) +void __fastcall town_clear_upper_buf(BYTE *pBuff) { - unsigned char *v1; // edi - signed int v2; // edx - signed int v3; // ebx - unsigned char *v4; // edi - signed int v5; // edx - signed int v6; // ebx - unsigned char *v7; // edi + /// ASSERT: assert(gpBuffer); - v1 = a1; - v2 = 30; - v3 = 1; - while (v1 >= gpBufEnd) { - v4 = &v1[v2]; - memset(v4, 0, 4 * v3); - v1 = &v4[4 * v3 - 832 + v2]; - if (!v2) { - v5 = 2; - v6 = 15; - do { - if (v1 < gpBufEnd) - break; - v7 = &v1[v5]; - memset(v7, 0, 4 * v6); - v1 = &v7[4 * v6-- - 832 + v5]; - v5 += 2; - } while (v5 != 32); - return; - } - v2 -= 2; - ++v3; +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov edi, pBuff + mov edx, 30 + mov ebx, 1 + xor eax, eax + label1: + cmp edi, gpBufEnd + jb label4 + add edi, edx + mov ecx, ebx + rep stosd + add edi, edx + sub edi, 768 + 64 + or edx, edx + jz label2 + sub edx, 2 + inc ebx + jmp label1 + label2: + mov edx, 2 + mov ebx, 15 + label3: + cmp edi, gpBufEnd + jb label4 + add edi, edx + mov ecx, ebx + rep stosd + add edi, edx + sub edi, 768 + 64 + dec ebx + add edx, 2 + cmp edx, 32 + jnz label3 + label4: + nop + } +#else + int i, j, k; + BYTE *dst; + + dst = pBuff; + + for(i = 30, j = 1; i >= 0 && dst >= gpBufEnd; i -= 2, j++, dst -= 768 + 64) { + dst += i; + for(k = 0; k < 4 * j; k++) + *dst++ = 0; + dst += i; } + for(i = 2, j = 15; i != 32 && dst >= gpBufEnd; i += 2, j--, dst -= 768 + 64) { + dst += i; + for(k = 0; k < 4 * j; k++) + *dst++ = 0; + dst += i; + } +#endif } // 69CF0C: using guessed type int gpBufEnd; -void __fastcall town_clear_low_buf(unsigned char *y_related) +void __fastcall town_clear_low_buf(BYTE *pBuff) { - unsigned char *v1; // edi - signed int v2; // edx - signed int i; // ebx - unsigned char *v4; // edi - unsigned char *v5; // edi - signed int v6; // edx - signed int v7; // ebx - unsigned char *v8; // edi - unsigned char *v9; // edi + /// ASSERT: assert(gpBuffer); + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov edi, pBuff + mov edx, 30 + mov ebx, 1 + xor eax, eax + label1: + cmp edi, gpBufEnd + jb label2 + add edi, 64 + jmp label3 + label2: + add edi, edx + mov ecx, ebx + rep stosd + add edi, edx + label3: + sub edi, 768 + 64 + or edx, edx + jz label4 + sub edx, 2 + inc ebx + jmp label1 + label4: + mov edx, 2 + mov ebx, 15 + label5: + cmp edi, gpBufEnd + jb label6 + add edi, 64 + jmp label7 + label6: + add edi, edx + mov ecx, ebx + rep stosd + add edi, edx + label7: + sub edi, 768 + 64 + dec ebx + add edx, 2 + cmp edx, 32 + jnz label5 + } +#else + int i, j, k; + BYTE *dst; - v1 = y_related; - v2 = 30; - for (i = 1;; ++i) { - if (v1 < gpBufEnd) { - v5 = &v1[v2]; - memset(v5, 0, 4 * i); - v4 = &v5[4 * i + v2]; + dst = pBuff; + + for(i = 30, j = 1; i >= 0; i -= 2, j++, dst -= 768 + 64) { + if(dst < gpBufEnd) { + dst += i; + for(k = 0; k < 4 * j; k++) + *dst++ = 0; + dst += i; } else { - v4 = v1 + 64; + dst += 64; } - v1 = v4 - 832; - if (!v2) - break; - v2 -= 2; } - v6 = 2; - v7 = 15; - do { - if (v1 < gpBufEnd) { - v9 = &v1[v6]; - memset(v9, 0, 4 * v7); - v8 = &v9[4 * v7 + v6]; + for(i = 2, j = 15; i != 32; i += 2, j--, dst -= 768 + 64) { + if(dst < gpBufEnd) { + dst += i; + for(k = 0; k < 4 * j; k++) + *dst++ = 0; + dst += i; } else { - v8 = v1 + 64; + dst += 64; } - v1 = v8 - 832; - --v7; - v6 += 2; - } while (v6 != 32); + } +#endif } // 69CF0C: using guessed type int gpBufEnd; @@ -253,7 +313,7 @@ void __fastcall town_draw_lower(int x, int y, int sx, int sy, int a5, int some_f if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX && (level_cel_block = dPiece[x][y]) != 0) { v6 = sy; v7 = &screen_y_times_768[sy]; - a1 = (unsigned char *)&gpBuffer->row_unused_1[0].col_unused_1[*v7 + 32 + sx]; + a1 = (unsigned char *)&gpBuffer[*v7 + 32 + sx]; v25 = 1; v8 = (char *)dpiece_defs_map_1 + 32 * gendung_get_dpiece_num_from_coord(x, y); do { @@ -712,7 +772,7 @@ void __fastcall town_draw_upper(int x, int y, int sx, int sy, INT_PTR a5, int a6 int v14; // esi int v15; // edi int v16; // eax - Screen *v17; // eax + BYTE *v17; // eax unsigned char *v18; // ebx char *v19; // edi int v20; // eax @@ -749,7 +809,7 @@ void __fastcall town_draw_upper(int x, int y, int sx, int sy, INT_PTR a5, int a6 v10 = v9 == 0; v11 = sy; if (!v10) { - a1 = (int *)&gpBuffer->row_unused_1[0].col_unused_1[sx + 32 + screen_y_times_768[sy]]; + a1 = (int *)&gpBuffer[sx + 32 + screen_y_times_768[sy]]; sxa = 0; v12 = &dpiece_defs_map_1[0][16 * gendung_get_dpiece_num_from_coord(x, y) + 1]; do { @@ -1106,7 +1166,7 @@ void __fastcall T_DrawZoom(int x, int y) LABEL_24: v11 = (_WORD *)((char *)gpBuffer + a5a); v12 = (char *)gpBuffer + a6b; - v13 = &gpBuffer->row_unused_1[1].col_unused_1[a5a]; + v13 = (char *)&gpBuffer[a5a + 768]; v14 = 176; do { v15 = v19; @@ -1245,94 +1305,121 @@ void __cdecl town_init_dpiece_defs_map() // 5C3000: using guessed type int scr_pix_width; // 5C3004: using guessed type int scr_pix_height; -void __fastcall T_FillSector(unsigned char *P3Tiles, unsigned char *pSector, int xi, int yi, int w, int h) /* check 7 params: int AddSec */ +void __fastcall T_FillSector(unsigned char *P3Tiles, unsigned char *pSector, int xi, int yi, int w, int h) { - int v7; // ebx - int v8; // edx - int v9; // edi - int *v10; // ecx - int v11; // eax - unsigned char *v12; // esi - unsigned short v13; // ax - int v14; // eax - int v15; // [esp+4h] [ebp-14h] - int v16; // [esp+8h] [ebp-10h] - unsigned char *v17; // [esp+Ch] [ebp-Ch] - unsigned char *v18; // [esp+10h] [ebp-8h] - signed int v19; // [esp+14h] [ebp-4h] - int a4; // [esp+24h] [ebp+Ch] - int a6; // [esp+2Ch] [ebp+14h] + int i, j, xx, yy; + long v1, v2, v3, v4, ii; - v7 = h; - v17 = pSector; - v8 = yi; - v18 = P3Tiles; - v19 = 4; - if (h > 0) { - do { - v9 = w; - if (w > 0) { - v10 = &dPiece[1][v8 + 112 * xi]; - do { - v11 = *(unsigned short *)&v17[v19]; - if ((_WORD)v11) { - v12 = &v18[8 * (v11 - 1)]; - v13 = *(_WORD *)v12; - v12 += 2; - v14 = v13 + 1; - a4 = v14; - _LOWORD(v14) = *(_WORD *)v12; - v12 += 2; - a6 = ++v14; - _LOWORD(v14) = *(_WORD *)v12; - v16 = ++v14; - _LOWORD(v14) = *((_WORD *)v12 + 1); - v15 = v14 + 1; - } else { - a4 = 0; - a6 = 0; - v16 = 0; - v15 = 0; - } - v19 += 2; - *(v10 - 112) = a4; - *v10 = a6; - *(v10 - 111) = v16; - v10[1] = v15; - v10 += 224; - --v9; - } while (v9); + ii = 4; + yy = yi; + for(j = 0; j < h; j++) { + xx = xi; + for(i = 0; i < w; i++) { +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov esi, pSector + mov eax, ii + add esi, eax + xor eax, eax + lodsw + or eax, eax + jz label1 + dec eax + mov esi, P3Tiles + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + jmp label2 + label1: + mov v1, eax + mov v2, eax + mov v3, eax + mov v4, eax + label2: + nop } - v8 += 2; - --v7; - } while (v7); +#else + WORD *Map; + + Map = (WORD *)&pSector[ii]; + if(*Map) { + v1 = *((WORD *)&P3Tiles[(*Map-1)*8])+1; + v2 = *((WORD *)&P3Tiles[(*Map-1)*8]+1)+1; + v3 = *((WORD *)&P3Tiles[(*Map-1)*8]+2)+1; + v4 = *((WORD *)&P3Tiles[(*Map-1)*8]+3)+1; + } else { + v1 = 0; + v2 = 0; + v3 = 0; + v4 = 0; + } +#endif + dPiece[xx][yy] = v1; + dPiece[xx + 1][yy] = v2; + dPiece[xx][yy + 1] = v3; + dPiece[xx + 1][yy + 1] = v4; + xx += 2; + ii += 2; + } + yy += 2; } } void __fastcall T_FillTile(unsigned char *P3Tiles, int xx, int yy, int t) { - unsigned char *v4; // esi - unsigned short v5; // ax - int v6; // eax - int v7; // ST10_4 - int v8; // ST0C_4 - int v9; // ST08_4 + long v1, v2, v3, v4; + +#if (_MSC_VER >= 800) && (_MSC_VER <= 1200) + __asm { + mov eax, t + dec eax + mov esi, P3Tiles + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + jmp label1 + mov v1, eax + mov v2, eax + mov v3, eax + mov v4, eax + label1: + nop + } +#else + v1 = *((WORD *)&P3Tiles[(t-1)*8])+1; + v2 = *((WORD *)&P3Tiles[(t-1)*8]+1)+1; + v3 = *((WORD *)&P3Tiles[(t-1)*8]+2)+1; + v4 = *((WORD *)&P3Tiles[(t-1)*8]+3)+1; +#endif - v4 = &P3Tiles[8 * (t - 1)]; - v5 = *(_WORD *)v4; - v4 += 2; - v6 = v5 + 1; - v7 = v6; - _LOWORD(v6) = *(_WORD *)v4; - v4 += 2; - v8 = ++v6; - _LOWORD(v6) = *(_WORD *)v4; - v9 = ++v6; - _LOWORD(v6) = *((_WORD *)v4 + 1); - dPiece[xx][yy] = v7; - dPiece[xx + 1][yy] = v8; - dPiece[xx][yy + 1] = v9; - dPiece[xx + 1][yy + 1] = v6 + 1; + dPiece[xx][yy] = v1; + dPiece[xx + 1][yy] = v2; + dPiece[xx][yy + 1] = v3; + dPiece[xx + 1][yy + 1] = v4; } void __cdecl T_Pass3() diff --git a/Source/town.h b/Source/town.h index 9580bc64f..de73f2b38 100644 --- a/Source/town.h +++ b/Source/town.h @@ -2,8 +2,8 @@ #ifndef __TOWN_H__ #define __TOWN_H__ -void __fastcall town_clear_upper_buf(unsigned char *a1); -void __fastcall town_clear_low_buf(unsigned char *y_related); +void __fastcall town_clear_upper_buf(BYTE *pBuff); +void __fastcall town_clear_low_buf(BYTE *pBuff); void __fastcall town_draw_clipped_e_flag(BYTE *buffer, int x, int y, int sx, int sy); void __fastcall town_draw_clipped_town(BYTE *buffer, int x, int y, int sx, int sy, int some_flag); void __fastcall town_draw_lower(int x, int y, int sx, int sy, int a5, int some_flag); diff --git a/SourceX/DiabloUI/diabloui.cpp b/SourceX/DiabloUI/diabloui.cpp index 6b74fb602..676d75ffe 100644 --- a/SourceX/DiabloUI/diabloui.cpp +++ b/SourceX/DiabloUI/diabloui.cpp @@ -487,7 +487,7 @@ BOOL UiCreateGameCallback(int a1, int a2, int a3, int a4, int a5, int a6) UNIMPLEMENTED(); } -BOOL UiArtCallback(int game_type, unsigned int art_code, PALETTEENTRY *pPalette, void *pBuffer, +BOOL UiArtCallback(int game_type, unsigned int art_code, PALETTEENTRY *pPalette, BYTE *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp) { UNIMPLEMENTED(); @@ -519,7 +519,7 @@ BOOL UiCreatePlayerDescription(_uiheroinfo *info, DWORD mode, char *desc) void DrawArt(int screenX, int screenY, Art *art, int nFrame, int drawW) { BYTE *src = (BYTE *)art->data + (art->width * art->height * nFrame); - BYTE *dst = (BYTE *)&gpBuffer->row[screenY].pixels[screenX]; + BYTE *dst = &gpBuffer[screenX + 64 + (screenY + 160) * 768]; drawW = drawW ?: art->width; for (int i = 0; i < art->height && i + screenY < SCREEN_HEIGHT; i++, src += art->width, dst += ROW_PITCH) { diff --git a/SourceX/dx.cpp b/SourceX/dx.cpp index 14af5359e..d473afcb0 100644 --- a/SourceX/dx.cpp +++ b/SourceX/dx.cpp @@ -6,7 +6,7 @@ namespace dvl { -Screen *gpBuffer; +BYTE *gpBuffer; IDirectDraw *lpDDInterface; IDirectDrawSurface *lpDDSPrimary; @@ -370,7 +370,7 @@ void dx_init(HWND hWnd) } const int pitch = 64 + SCREEN_WIDTH + 64; - gpBuffer = (Screen *)malloc(sizeof(Screen)); + gpBuffer = (BYTE *)malloc(656 * 768); gpBufEnd += (uintptr_t)gpBuffer; pal_surface = SDL_CreateRGBSurfaceFrom(gpBuffer, pitch, 160 + SCREEN_HEIGHT + 16, 8, pitch, 0, 0, 0, 0); diff --git a/SourceX/sound.cpp b/SourceX/sound.cpp index ce3364299..fece87865 100644 --- a/SourceX/sound.cpp +++ b/SourceX/sound.cpp @@ -8,7 +8,7 @@ namespace dvl { LPDIRECTSOUNDBUFFER DSBs[8]; LPDIRECTSOUND sglpDS; -char gbSndInited; +BOOLEAN gbSndInited; int sglMusicVolume; int sglSoundVolume; HMODULE hDsound_dll; diff --git a/defs.h b/defs.h index 73729fd34..182830eee 100644 --- a/defs.h +++ b/defs.h @@ -83,6 +83,8 @@ #define PAL16_RED 224 #define PAL16_GRAY 240 +#define SCREENXY(x, y) ((x) + 64 + (((y) + 160) * 768)) + #ifndef INVALID_FILE_ATTRIBUTES #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) #endif diff --git a/structs.h b/structs.h index 1adef2ece..5b63c3c09 100644 --- a/structs.h +++ b/structs.h @@ -1187,22 +1187,6 @@ typedef struct DeadStruct { char _deadtrans; } DeadStruct; -////////////////////////////////////////////////// -// dx -////////////////////////////////////////////////// - -typedef struct ScreenRow { - char col_unused_1[64]; - char pixels[640]; - char col_unused_2[64]; -} ScreenRow; - -typedef struct Screen { /* create union for work data vs visible data */ - ScreenRow row_unused_1[160]; - ScreenRow row[480]; - ScreenRow row_unused_2[16]; -} Screen; - ////////////////////////////////////////////////// // diabloui //////////////////////////////////////////////////