mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Refactored ASM code of some hooks using 4.x as ref
Code edits to DisplayKarmaChanges. Implemented the buf_to_buf_ replacement function from 4.x.
This commit is contained in:
@@ -1057,6 +1057,72 @@ void __fastcall TransCscale(long i_width, long i_height, long s_width, long s_he
|
||||
}
|
||||
}
|
||||
|
||||
// buf_to_buf_ function with pure MMX implementation
|
||||
void __cdecl BufToBuf(void* src, long width, long height, long src_width, void* dst, long dst_width) {
|
||||
if (height <= 0 || width <= 0) return;
|
||||
|
||||
size_t blockCount = width / 64; // 64 bytes
|
||||
size_t remainder = width % 64;
|
||||
size_t remainderD = remainder / 4;
|
||||
size_t remainderB = remainder % 4;
|
||||
size_t s_pitch = src_width - width;
|
||||
size_t d_pitch = dst_width - width;
|
||||
|
||||
__asm {
|
||||
mov ebx, s_pitch;
|
||||
mov edx, d_pitch;
|
||||
mov esi, src;
|
||||
mov edi, dst;
|
||||
mov eax, height;
|
||||
startLoop:
|
||||
mov ecx, blockCount;
|
||||
test ecx, ecx;
|
||||
jz copySmall;
|
||||
copyBlock: // copies block of 64 bytes
|
||||
movq mm0, [esi]; // movups xmm0, [esi]; // SSE implementation
|
||||
movq mm1, [esi + 8];
|
||||
movq mm2, [esi + 16]; // movups xmm1, [esi + 16];
|
||||
movq mm3, [esi + 24];
|
||||
movq mm4, [esi + 32]; // movups xmm2, [esi + 32];
|
||||
movq mm5, [esi + 40];
|
||||
movq mm6, [esi + 48]; // movups xmm3, [esi + 48];
|
||||
movq mm7, [esi + 56];
|
||||
movq [edi], mm0; // movups [edi], xmm0;
|
||||
movq [edi + 8], mm1;
|
||||
movq [edi + 16], mm2; // movups [edi + 16], xmm1;
|
||||
movq [edi + 24], mm3;
|
||||
movq [edi + 32], mm4; // movups xmm2, [esi + 32];
|
||||
movq [edi + 40], mm5;
|
||||
movq [edi + 48], mm6; // movups xmm3, [esi + 48];
|
||||
movq [edi + 56], mm7;
|
||||
add esi, 64;
|
||||
lea edi, [edi + 64];
|
||||
dec ecx; // blockCount
|
||||
jnz copyBlock;
|
||||
// copies the remaining bytes
|
||||
mov ecx, remainderD;
|
||||
rep movsd;
|
||||
mov ecx, remainderB;
|
||||
rep movsb;
|
||||
add esi, ebx; // s_pitch
|
||||
add edi, edx; // d_pitch
|
||||
dec eax; // height
|
||||
jnz startLoop;
|
||||
emms;
|
||||
jmp end;
|
||||
copySmall: // copies the small size data
|
||||
mov ecx, remainderD;
|
||||
rep movsd;
|
||||
mov ecx, remainderB;
|
||||
rep movsb;
|
||||
add esi, ebx; // s_pitch
|
||||
add edi, edx; // d_pitch
|
||||
dec eax; // height
|
||||
jnz copySmall;
|
||||
end:
|
||||
}
|
||||
}
|
||||
|
||||
long __fastcall GetGameConfigString(const char* outValue, const char* section, const char* param) {
|
||||
__asm {
|
||||
mov ebx, param;
|
||||
|
||||
@@ -1167,6 +1167,9 @@ void __fastcall DisplayInWindow(long w_here, long width, long height, void* data
|
||||
|
||||
void __fastcall TransCscale(long i_width, long i_height, long s_width, long s_height, long xy_shift, long w_width, void* data);
|
||||
|
||||
// buf_to_buf_ function with pure MMX implementation
|
||||
void __cdecl BufToBuf(void* src, long width, long height, long src_width, void* dst, long dst_width);
|
||||
|
||||
long __fastcall GetGameConfigString(const char* outValue, const char* section, const char* param);
|
||||
|
||||
/* stdcall */
|
||||
|
||||
+9
-5
@@ -781,10 +781,11 @@ public:
|
||||
int pitch = dRect.Pitch;
|
||||
|
||||
if (GPUBlt) {
|
||||
char* pBits = (char*)dRect.pBits;
|
||||
for (DWORD y = 0; y < mveDesc.dwHeight; y++) {
|
||||
CopyMemory(&pBits[y * pitch], &lockTarget[y * width], width);
|
||||
}
|
||||
BufToBuf(lockTarget, width, mveDesc.dwHeight, width, dRect.pBits, pitch);
|
||||
//char* pBits = (char*)dRect.pBits;
|
||||
//for (DWORD y = 0; y < mveDesc.dwHeight; y++) {
|
||||
// CopyMemory(&pBits[y * pitch], &lockTarget[y * width], width);
|
||||
//}
|
||||
} else {
|
||||
pitch /= 4;
|
||||
for (DWORD y = 0; y < mveDesc.dwHeight; y++) {
|
||||
@@ -1011,7 +1012,7 @@ public:
|
||||
HRESULT __stdcall SetEntries(DWORD a, DWORD b, DWORD c, LPPALETTEENTRY destPal) { // used to set palette for splash screen, fades, subtitles
|
||||
if (!windowInit || c == 0 || b + c > 256) return DDERR_INVALIDPARAMS;
|
||||
|
||||
CopyMemory(&palette[b], destPal, c * 4);
|
||||
__movsd(&palette[b], (unsigned long*)destPal, c);
|
||||
|
||||
if (GPUBlt && gpuPalette) {
|
||||
D3DLOCKED_RECT rect;
|
||||
@@ -1308,6 +1309,9 @@ void GraphicsInit() {
|
||||
fadeMulti = ((double)fadeMulti) / 100.0;
|
||||
dlogr(" Done", DL_INIT);
|
||||
}
|
||||
|
||||
// Replace the srcCopy_ function with a pure MMX implementation
|
||||
MakeJump(0x4D36D4, BufToBuf); // buf_to_buf_
|
||||
}
|
||||
|
||||
void GraphicsExit() {
|
||||
|
||||
+175
-142
File diff suppressed because it is too large
Load Diff
+8
-12
@@ -61,30 +61,26 @@ skip:
|
||||
}
|
||||
|
||||
static void __stdcall SetKarma(int value) {
|
||||
int old;
|
||||
__asm {
|
||||
xor eax, eax;
|
||||
call game_get_global_var_;
|
||||
mov old, eax;
|
||||
}
|
||||
old = value - old;
|
||||
char buf[128];
|
||||
if (old == 0) return;
|
||||
if (old > 0) {
|
||||
sprintf_s(buf, karmaGainMsg, old);
|
||||
if (value > 0) {
|
||||
sprintf_s(buf, karmaGainMsg, value);
|
||||
} else {
|
||||
sprintf_s(buf, karmaLossMsg, -old);
|
||||
sprintf_s(buf, karmaLossMsg, -value);
|
||||
}
|
||||
DisplayPrint(buf);
|
||||
}
|
||||
|
||||
static void __declspec(naked) SetGlobalVarWrapper() {
|
||||
__asm {
|
||||
test eax, eax; // GVar number
|
||||
test eax, eax; // Gvar number
|
||||
jnz end;
|
||||
pushadc;
|
||||
call game_get_global_var_;
|
||||
sub edx, eax; // value -= old
|
||||
jz skip;
|
||||
push edx;
|
||||
call SetKarma;
|
||||
skip:
|
||||
popadc;
|
||||
end:
|
||||
jmp game_set_global_var_;
|
||||
|
||||
Reference in New Issue
Block a user