home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Elite Hackers Toolkit
/
TheEliteHackersToolkitVolume1_1998.rar
/
HACKERS.BIN
/
appcraks
/
P5WGLIDE.ZIP
/
MAIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-21
|
6KB
|
246 lines
// main.c
// Contains the .dll entry point and overridden functions
// uses imports.c for loading symbols, dib.c for getting framebuffer access.
// Copr. 1998 - Justin Frankel/Nullsoft, Inc. (http://www.nullsoft.com)
// Version 0.5 - 1/4/1998
//Pentium optimized 3Dfx to DIB memory copy added by Chris Dohnal (cwdohnal@ucdavis.edu)
//This dll will not work with scanline interleaved systems
#include <windows.h>
#define FX_GLIDE_NO_FUNC_PROTO
#include <glide.h>
#include <glideutl.h>
#include "pointers.h"
HINSTANCE hGlide, hDllInst;
#define ENTRY __declspec(dllexport)
#define CALL __stdcall
// dib.c functions
extern void dibinit(HWND hwnd, int w, int h);
extern void dibquit();
extern short *dibgetbuf();
extern void dibupdate();
extern int dibgetpitch();
// imports.c functions
extern int LoadSymbols(HINSTANCE *hGlide, HINSTANCE hDllInst);
// DLL entry point. Calls on load/unload of the .dll. Loads or frees the real glide2x.dll.
BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved) {
hDllInst = hInstDll;
if (fdwReason == DLL_PROCESS_ATTACH) {
if (!LoadSymbols(&hGlide,hDllInst)) {
hGlide = NULL;
return FALSE;
}
}
if (fdwReason == DLL_PROCESS_DETACH) {
FreeModule(hGlide);
hGlide = NULL;
}
return TRUE;
}
int enable=1, // are we running windowed?
sw, // screen width (window width)
sh; // screen height (window height)
// quake 2 320x240 and 400x300 hack.
int iQuake2LowResOffset;
// Our new, overridden functions go here.
// override grSstWinOpen, for opening the 3dfx hardware.
ENTRY FxBool CALL grSstWinOpen(FxU32 hFxWnd, GrScreenResolution_t grResolution,
GrScreenRefresh_t grRefresh, GrColorFormat_t grColorFormat,
GrOriginLocation_t grOriginLocation, int nColBuffers, int nAuxBuffers) {
HWND hWnd;
//Get hFxWnd as a HWND.
hWnd = (HWND)hFxWnd;
if (_grSstWinOpen(hFxWnd, grResolution, grRefresh, grColorFormat,
grOriginLocation, nColBuffers, nAuxBuffers) == FXFALSE) {
return FXFALSE;
}
sw = _grSstScreenWidth();
sh = _grSstScreenHeight();
// decide if we are running fullscreen or windowed
if (hWnd && IsWindow(hWnd)) {
RECT rect;
GetWindowRect(hWnd, &rect);
if ((rect.left == 0) && (rect.top == 0) && (rect.right == sw) &&
(rect.bottom == sh)) {
enable = 0;
}
else {
enable = 1;
}
}
else {
enable = 0;
}
// if enabled, initialize us
if (enable) {
RECT rect;
GetClientRect(hWnd, &rect);
if (grOriginLocation == GR_ORIGIN_LOWER_LEFT && sh == 384) {
iQuake2LowResOffset = 384 - rect.bottom;
}
else {
iQuake2LowResOffset = 0;
}
sw = rect.right;
sh = rect.bottom;
_grSstControl(GR_CONTROL_DEACTIVATE);
_grRenderBuffer(GR_BUFFER_BACKBUFFER);
dibinit(hWnd, sw, sh);
}
return FXTRUE;
}
// override grBufferSwap to copy the hardware's data into our DIBSection
ENTRY void CALL grBufferSwap(int swapInterval) {
FxBool fxbRet;
GrLfbInfo_t grLFBInfo;
if (enable) {
short *data = dibgetbuf();
if (data) {
long lLine;
LPVOID pDIB;
LPVOID p3DfxScanlineStart;
int swTimesTwo, swDivFour;
//Lock the 3Dfx LFB
ZeroMemory(&grLFBInfo, sizeof(grLFBInfo));
grLFBInfo.size = sizeof(grLFBInfo);
fxbRet = _grLfbLock(GR_LFB_READ_ONLY, GR_BUFFER_BACKBUFFER, 0,
GR_ORIGIN_ANY, FXFALSE, &grLFBInfo);
if (fxbRet != FXTRUE) {
//Could not lock the 3Dfx LFB
return;
}
//Setup pointers to the 3Dfx LFB and the DIB
p3DfxScanlineStart = (BYTE *)grLFBInfo.lfbPtr +
grLFBInfo.strideInBytes * (sh - 1);
pDIB = data;
swTimesTwo = sw * 2;
swDivFour = sw >> 2;
//Transfer the data from the 3Dfx LFB to the DIB
for (lLine = 0; lLine < sh; lLine++) {
//Transfer a scanline
//CopyMemory(pDIB, p3DfxScanlineStart, sw * 2);
_asm {
mov esi, p3DfxScanlineStart
mov edi, pDIB
mov ecx, swDivFour
/*sub edi, 8
copyloop:
fild qword ptr [esi]
add esi, 8
add edi, 8
fistp qword ptr [edi]
dec ecx
jnz copyloop*/
xor edx, edx
copyloop:
fild qword ptr [esi + edx*8]
fistp qword ptr [edi + edx*8]
inc edx
dec ecx
jnz copyloop
/*xor edx, edx
copyloop:
mov eax, [esi + edx*8]
mov ebx, [esi + edx*8 + 4]
mov [edi + edx*8], eax
mov [edi + edx*8 + 4], ebx
inc edx
dec ecx
jnz copyloop*/
/*copyloop:
mov eax, [esi]
add esi, 4
mov ebx, [esi]
add esi, 4
mov [edi], eax
add edi, 4
mov [edi], ebx
add edi, 4
dec ecx
jnz copyloop*/
}
//Calculate the address of the next scanline
(BYTE *)p3DfxScanlineStart -= grLFBInfo.strideInBytes;
(BYTE *)pDIB += swTimesTwo;
}
//Unlock the 3Dfx LFB
fxbRet = _grLfbUnlock(GR_LFB_READ_ONLY, GR_BUFFER_BACKBUFFER);
if (fxbRet != FXTRUE) {
//Could not unlock the 3Dfx LFB
return;
}
//Old 3Dfx LFB Read function
//_grLfbReadRegion(GR_BUFFER_BACKBUFFER, 0, iQuake2LowResOffset, sw, sh, dibgetpitch(), data);
dibupdate();
}
}
else {
_grBufferSwap(swapInterval);
}
return;
}
// override grSstWinClose to delete our DIB
ENTRY void CALL grSstWinClose(void) {
_grSstWinClose();
if (enable) {
dibquit();
}
return;
}
// override grSstControl to keep the calling app from reenabling the hardware's video output
ENTRY FxBool CALL grSstControl(FxU32 code) {
if (!enable) {
return _grSstControl(code);
}
return 0;
}