WinMain and respective SEH code (filter and handler)

This commit is contained in:
krystalgamer 2024-08-17 20:57:14 +01:00
parent 95b5475ac1
commit 32056ea5d1
6 changed files with 276 additions and 35 deletions

View File

@ -9,11 +9,13 @@ void AUDIOGROUPS_GetGroup(char *)
printf("AUDIOGROUPS_GetGroup(char *)");
}
#ifdef _WIN32
// @SMALLTODO
void DXINIT_DirectX8(HWND__ *,HINSTANCE__ *,u32)
void DXINIT_DirectX8(HWND ,HINSTANCE,u32)
{
printf("DXINIT_DirectX8(HWND__ *,HINSTANCE__ *,u32)");
}
#endif
// @SMALLTODO
void DXINIT_GetCurrentResolution(u32 *,u32 *)

View File

@ -5,10 +5,17 @@
#include "export.h"
#ifdef _WIN32
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#else
// @FIXME
#define HWND__ i32
// @FIXME
#define HINSTANCE__ i32
#endif
// @FIXME
#define _D3DDeviceDesc7 i32
// @FIXME
@ -18,7 +25,11 @@
EXPORT void DXINIT_GetCurrentResolution(int *, int *);
EXPORT void AUDIOGROUPS_GetGroup(char *);
EXPORT void DXINIT_DirectX8(HWND__ *,HINSTANCE__ *,u32);
#ifdef _WIN32
EXPORT void DXINIT_DirectX8(HWND, HINSTANCE,u32);
#endif
EXPORT void DXINIT_GetCurrentResolution(u32 *,u32 *);
EXPORT void DXINIT_GetNextColorDepth(u32);
EXPORT void DXINIT_GetNextResolution(u32 *,u32 *,u32,i32,bool);

View File

@ -1,4 +1,39 @@
#include "SpideyDX.h"
#include "main.h"
#include "PCTimer.h"
#include "DXinit.h"
i32 gRenderTest;
i32 gGameResolutionX = 640;
i32 gGameResolutionY = 480;
i32 gDxResolutionX;
i32 gDxResolutionY;
u8 gMMXSupport;
u8 g3DAccelator = 1;
// @Ok
EXPORT u8 isMMX(void)
{
#ifdef _OLD_WINDOWS
u32 flags;
__asm
{
mov eax, 1
cpuid
mov [flags], edx
};
return (flags >> 23) & 1;
#else
// @FIXME most processors have MMX so it shouldn't be a problem
return 1;
#endif
}
// @SMALLTODO
void BuildTwiddleTable(void)
@ -42,11 +77,14 @@ void SPIDEYDX_Shutdown(void)
printf("SPIDEYDX_Shutdown(void)");
}
#ifdef _WIN32
// @SMALLTODO
void SpideyWndProc(void *,u32,u32,long)
LRESULT CALLBACK SpideyWndProc(HWND, UINT, WPARAM, LPARAM)
{
printf("SpideyWndProc(HWND__ *,u32,u32,long)");
return 0;
}
#endif
// @SMALLTODO
void WinYield(void)
@ -71,3 +109,176 @@ void parseCommandLine(char *)
{
printf("parseCommandLine(char *)");
}
// @BIGTODO
// DRM stuff can ignore for now
EXPORT void gDrmShit(i32)
{
printf("void gDrmShit(i32)");
}
// @Ok
void DXERR_printf(const char*, ...)
{
printf("void DXERR_printf(const char*, ...)");
}
#if _WIN32
INLINE i32 filter(u32 code, struct _EXCEPTION_POINTERS *ep)
{
DXERR_printf(
"Exception %08X at %08X",
ep->ExceptionRecord->ExceptionCode,
ep->ExceptionRecord->ExceptionAddress);
switch (ep->ExceptionRecord->ExceptionCode)
{
case EXCEPTION_ACCESS_VIOLATION:
DXERR_printf("Access Violation\n");
break;
case EXCEPTION_INT_DIVIDE_BY_ZERO:
DXERR_printf("floating-point ");
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
DXERR_printf("Divide by 0\n");
break;
}
return 0;
}
#endif
#ifdef _OLD_WINDOWS
// @Ok
// man so much to talk about this funciton
// starting with dumb filter that always continues and just logs
// to the numerous setters of globals
i32 WINAPI RealWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
i32 nCmdShow)
{
gDrmShit(0);
SPIDEYDX_LoadSettings();
gRenderTest = 0;
gGameResolutionX = 640;
gDxResolutionX = 640;
gGameResolutionY = 480;
gDxResolutionY = 480;
gMMXSupport = isMMX();
if (hPrevInstance == 0)
{
WNDCLASSA wndClass;
wndClass.style = 3;
wndClass.lpfnWndProc = SpideyWndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIconA(0, (LPCSTR)0x65);
wndClass.hCursor = LoadCursorA(0, (LPCSTR)0x7F00);
wndClass.hbrBackground = (HBRUSH)GetStockObject(4);
wndClass.lpszMenuName = 0;
wndClass.lpszClassName = "Spiderman PC";
if ( !RegisterClassA(&wndClass) )
return -1;
}
HWND hwnd;
if ( gRenderTest & 1)
{
hwnd = CreateWindowExA(
0,
"Spiderman PC",
"Spiderman PC",
WS_VISIBLE | WS_CAPTION,
0,
0,
640,
480,
0,
0,
hInstance,
0);
}
else
{
i32 yres = GetSystemMetrics(1);
i32 xres = GetSystemMetrics(0);
hwnd = CreateWindowExA(
0,
"Spiderman PC",
"Spiderman PC",
WS_VISIBLE | WS_POPUP,
0,
0,
xres,
yres,
0,
0,
hInstance,
0);
}
if (hwnd == 0)
{
DXERR_printf("Unable to create application window!\r\n");
return -1;
}
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
SetFocus(hwnd);
SetCursor(0);
ShowCursor(0);
WinYield();
PCTIMER_Init();
DXINIT_DirectX8(hwnd, hInstance, 2);
if (g3DAccelator || gMMXSupport)
{
__try
{
if (gRenderTest & 2)
{
MessageBoxA(
hwnd,
"RENDERTEST flag not supported anymore!",
"Spiderman Error",
MB_ICONERROR);
DXINIT_ShutDown();
}
else
{
SpideyMain();
}
}
__except (filter(GetExceptionCode(), GetExceptionInformation()))
{
}
}
else
{
MessageBoxA(
hwnd,
"Your machine does not support MMX or have 3D accelerator hardware so this game can not run.",
"SpideyPC Fatal Error",
MB_ICONERROR);
}
SPIDEYDX_Shutdown();
Sleep(0x64);
PostMessage(hwnd, WM_CLOSE, 0, 0);
WinYield();
return 0;
}
#endif

View File

@ -5,6 +5,22 @@
#include "export.h"
#ifdef _WIN32
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#endif
EXPORT extern i32 gRenderTest;
EXPORT extern i32 gGameResolutionX;
EXPORT extern i32 gGameResolutionY;
EXPORT extern i32 gDxResolutionX;
EXPORT extern i32 gDxResolutionY;
EXPORT extern u8 gMMXSupport;
EXPORT extern u8 g3DAccelator;
EXPORT void BuildTwiddleTable(void);
EXPORT void CalcUntwiddledPos(u32,u32,u32,u32);
EXPORT void ComputeMaskShift(u32,u32,u32 *,u32 *);
@ -12,13 +28,19 @@ EXPORT void SPIDEYDX_DisplayDeviceSettings(char *);
EXPORT void SPIDEYDX_LoadSettings(void);
EXPORT void SPIDEYDX_SaveSettings(void);
EXPORT void SPIDEYDX_Shutdown(void);
EXPORT void DXERR_printf(const char*, ...);
#ifdef _WIN32
EXPORT LRESULT CALLBACK SpideyWndProc(HWND, UINT, WPARAM, LPARAM);
#endif
//@FIXME void* should be HWND
EXPORT void SpideyWndProc(void *,u32,u32,long);
EXPORT void WinYield(void);
EXPORT void debugSettings(void);
EXPORT void mipmapOffset(u32,u32,float);
EXPORT void parseCommandLine(char *);
#ifdef _WIN32
EXPORT i32 WINAPI RealWinMain(HINSTANCE, HINSTANCE, LPSTR, i32);
#endif
#endif

View File

@ -76,24 +76,12 @@
#include "backgrnd.h"
#include "dcshellutils.h"
// @Ok
EXPORT u8 isMMX(void)
extern int FAIL_VALIDATION;
// @MEDIUMTODO
void SpideyMain(void)
{
#ifdef _OLD_WINDOWS
u32 flags;
__asm
{
mov eax, 1
cpuid
mov [flags], edx
};
return (flags >> 23) & 1;
#else
// @FIXME most processors have MMX so it shouldn't be a problem
return 1;
#endif
printf("void SpideyMain(void)");
}
// @Ok
@ -162,18 +150,8 @@ void compile_time_assertions(){
StaticAssert<sizeof(i8)==1>::assert();
}
extern int FAIL_VALIDATION;
#ifdef _OLD_WINDOWS
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpCmdLine, int nCmdShow)
#else
int main()
#endif
i32 validate(void)
{
compile_time_assertions();
#ifdef _OLD_WINDOWS
AllocConsole();
freopen("CONOUT$", "w", stdout);
@ -441,7 +419,23 @@ int main()
while(1){}
#endif
return FAIL_VALIDATION;
}
#ifdef _OLD_WINDOWS
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpCmdLine, int nCmdShow)
#else
int main()
#endif
{
compile_time_assertions();
#ifdef BOOT_GAME
return RealWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
#else
return validate();
#endif
}

1
main.h
View File

@ -13,4 +13,5 @@ class CClass
EXPORT virtual ~CClass();
};
EXPORT void SpideyMain(void);
#endif