add printf wrapper

While Wine's stdout implementation appears to be fine with no
modification, this is not the case in Windows XP.
This commit is contained in:
Zack Buhman 2025-12-24 11:01:30 -06:00
parent 40d4ff0e96
commit ed6afbb9aa
2 changed files with 37 additions and 6 deletions

View File

@ -14,7 +14,8 @@ CFLAGS += -Wno-error=unused-function
CFLAGS += -Wno-error=unused-variable CFLAGS += -Wno-error=unused-variable
CFLAGS += -DUNICODE CFLAGS += -DUNICODE
LDFLAGS += -Wl,--subsystem,windows -mwindows -mconsole -municode -ld3d9 -ld3dx9 -lwinmm -ldinput8 -ldxguid -ldsound -luuid # -Wl,--subsystem,windows
LDFLAGS += -Wl,--subsystem,windows -municode -mconsole -mwindows -ld3d9 -ld3dx9 -lwinmm -ldinput8 -ldxguid -ldsound -luuid -static-libgcc
OPT = -Og OPT = -Og

View File

@ -6,8 +6,10 @@
#include <dinput.h> #include <dinput.h>
#include <dsound.h> #include <dsound.h>
#include <assert.h> #include <assert.h>
#include <io.h>
#include <comdef.h> #define printf(...)
#define fprintf(...)
struct CUSTOMVERTEX struct CUSTOMVERTEX
{ {
@ -21,6 +23,28 @@ const CUSTOMVERTEX g_Vertices[] = {
{ 0.0f, 1.0f, 0.0f, 0xffffffff, }, { 0.0f, 1.0f, 0.0f, 0xffffffff, },
}; };
void new_printf(const char * format, ...)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
char buf[512];
va_list ap;
va_start(ap, format);
int length = vsnprintf(buf, (sizeof (buf)), format, ap);
va_end(ap);
WriteConsoleA(hStdout, buf, length, NULL, NULL);
}
#ifdef printf
#undef printf
#endif
#define printf(...) new_printf(__VA_ARGS__)
#ifdef fprintf
#undef fprintf
#endif
#define fprintf(f, ...) new_printf(__VA_ARGS__)
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
IDirect3D9 * g_pD3D = NULL; IDirect3D9 * g_pD3D = NULL;
@ -158,7 +182,7 @@ void Render()
UINT registerIndex = g_TextureConstDesc.RegisterIndex; UINT registerIndex = g_TextureConstDesc.RegisterIndex;
g_pd3dDevice->SetTexture(registerIndex, g_pTexture); g_pd3dDevice->SetTexture(registerIndex, g_pTexture);
g_pd3dDevice->SetSamplerState(registerIndex, D3DSAMP_MINFILTER, D3DTEXF_POINT); g_pd3dDevice->SetSamplerState(registerIndex, D3DSAMP_MINFILTER, D3DTEXF_POINT);
g_pd3dDevice->Setsamplerstate(registerIndex, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); g_pd3dDevice->SetSamplerState(registerIndex, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
g_pd3dDevice->SetSamplerState(registerIndex, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); g_pd3dDevice->SetSamplerState(registerIndex, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
g_pd3dDevice->SetStreamSource(0, g_pVB, 0, (sizeof (CUSTOMVERTEX))); g_pd3dDevice->SetStreamSource(0, g_pVB, 0, (sizeof (CUSTOMVERTEX)));
@ -267,16 +291,22 @@ HRESULT InitDirectSound(HWND hwnd)
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{ {
if (0) { AttachConsole(ATTACH_PARENT_PROCESS);
if (1) {
HRESULT hr; HRESULT hr;
hr = InitDirectInput(hInstance); hr = InitDirectInput(hInstance);
if (FAILED(hr)) if (FAILED(hr)) {
printf("InitDirectInput\n");
return 0; return 0;
}
while (true) { while (true) {
hr = UpdateInput(); hr = UpdateInput();
if (FAILED(hr)) if (FAILED(hr)) {
printf("UpdateInput\n");
return 0; return 0;
}
Sleep(100); Sleep(100);
} }
} }