REDRIVER2/src_rebuild/redriver2_psxpc.c

250 lines
5.1 KiB
C
Raw Normal View History

// redriver2_psxpc.cpp
//
2020-05-14 08:56:30 +02:00
#include "GAME/C/MAIN.H"
#include "EMULATOR.H"
#include "EMULATOR_PRIVATE.H"
2020-04-27 09:53:49 +02:00
#include <SDL_scancode.h>
2020-05-14 08:56:30 +02:00
// eq engine console output
typedef enum
{
SPEW_NORM,
SPEW_INFO,
SPEW_WARNING,
SPEW_ERROR,
SPEW_SUCCESS,
}SpewType_t;
#ifdef _WIN32
#include <Windows.h>
#include <conio.h>
#include <sys/types.h>
#include <sys/stat.h>
static unsigned short g_InitialColor = 0xFFFF;
static unsigned short g_LastColor = 0xFFFF;
static unsigned short g_BadColor = 0xFFFF;
static WORD g_BackgroundFlags = 0xFFFF;
static void GetInitialColors()
{
// Get the old background attributes.
CONSOLE_SCREEN_BUFFER_INFO oldInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &oldInfo);
g_InitialColor = g_LastColor = oldInfo.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
g_BackgroundFlags = oldInfo.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
g_BadColor = 0;
if (g_BackgroundFlags & BACKGROUND_RED)
g_BadColor |= FOREGROUND_RED;
if (g_BackgroundFlags & BACKGROUND_GREEN)
g_BadColor |= FOREGROUND_GREEN;
if (g_BackgroundFlags & BACKGROUND_BLUE)
g_BadColor |= FOREGROUND_BLUE;
if (g_BackgroundFlags & BACKGROUND_INTENSITY)
g_BadColor |= FOREGROUND_INTENSITY;
}
static WORD SetConsoleTextColor(int red, int green, int blue, int intensity)
{
WORD ret = g_LastColor;
g_LastColor = 0;
if (red) g_LastColor |= FOREGROUND_RED;
if (green) g_LastColor |= FOREGROUND_GREEN;
if (blue) g_LastColor |= FOREGROUND_BLUE;
if (intensity) g_LastColor |= FOREGROUND_INTENSITY;
// Just use the initial color if there's a match...
if (g_LastColor == g_BadColor)
g_LastColor = g_InitialColor;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), g_LastColor | g_BackgroundFlags);
return ret;
}
static void RestoreConsoleTextColor(WORD color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color | g_BackgroundFlags);
g_LastColor = color;
}
CRITICAL_SECTION g_SpewCS;
bool g_bSpewCSInitted = false;
void fnConDebugSpew(SpewType_t type, char* text)
{
// Hopefully two threads won't call this simultaneously right at the start!
if (!g_bSpewCSInitted)
{
GetInitialColors();
InitializeCriticalSection(&g_SpewCS);
g_bSpewCSInitted = true;
}
WORD old;
EnterCriticalSection(&g_SpewCS);
{
if (type == SPEW_NORM)
{
old = SetConsoleTextColor(1, 1, 1, 0);
}
else if (type == SPEW_WARNING)
{
old = SetConsoleTextColor(1, 1, 0, 1);
}
else if (type == SPEW_SUCCESS)
{
old = SetConsoleTextColor(0, 1, 0, 1);
}
else if (type == SPEW_ERROR)
{
old = SetConsoleTextColor(1, 0, 0, 1);
}
else if (type == SPEW_INFO)
{
old = SetConsoleTextColor(0, 1, 1, 1);
}
else
{
old = SetConsoleTextColor(1, 1, 1, 1);
}
OutputDebugStringA(text);
printf("%s", text);
RestoreConsoleTextColor(old);
}
LeaveCriticalSection(&g_SpewCS);
}
#endif
void SpewMessageToOutput(SpewType_t spewtype, char const* pMsgFormat, va_list args)
{
static char pTempBuffer[4096];
int len = 0;
vsprintf(&pTempBuffer[len], pMsgFormat, args);
#ifdef WIN32
fnConDebugSpew(spewtype, pTempBuffer);
#else
printf(pTempBuffer);
#endif
}
void printMsg(char *fmt, ...)
{
va_list argptr;
va_start(argptr, fmt);
SpewMessageToOutput(SPEW_NORM, fmt, argptr);
va_end(argptr);
}
void printInfo(char *fmt, ...)
{
va_list argptr;
va_start(argptr, fmt);
SpewMessageToOutput(SPEW_INFO, fmt, argptr);
va_end(argptr);
}
void printWarning(char *fmt, ...)
{
va_list argptr;
va_start(argptr, fmt);
SpewMessageToOutput(SPEW_WARNING, fmt, argptr);
va_end(argptr);
}
void printError(char *fmt, ...)
{
va_list argptr;
va_start(argptr, fmt);
SpewMessageToOutput(SPEW_ERROR, fmt, argptr);
va_end(argptr);
}
int(*GPU_printf)(const char *fmt, ...);
extern int g_texturelessMode;
extern int g_wireframeMode;
int gShowCollisionDebug = 0;
2020-04-27 09:53:49 +02:00
extern int gDrawDistance;
extern int gDisplayPosition;
extern int gDisplayDrawStats;
2020-05-14 08:56:30 +02:00
extern void FunkUpDaBGMTunez(int funk);
2020-04-27 09:53:49 +02:00
void GameDebugKeys(int nKey, bool down)
{
if (!down)
return;
if (nKey == SDL_SCANCODE_F1)
{
gDrawDistance -= 100;
if (gDrawDistance < 441)
gDrawDistance = 441;
printf("gDrawDistance = %d\n", gDrawDistance);
}
else if (nKey == SDL_SCANCODE_F2)
{
gDrawDistance += 100;
if (gDrawDistance > 6000)
gDrawDistance = 6000;
printf("gDrawDistance = %d\n", gDrawDistance);
}
else if (nKey == SDL_SCANCODE_F3)
{
gDisplayPosition ^= 1;
printf("Position display %s\n", gDisplayPosition ? "ON" : "OFF");
}
else if (nKey == SDL_SCANCODE_F4)
{
gShowCollisionDebug ^= 1;
printf("Collision debug %s\n", gShowCollisionDebug ? "ON" : "OFF");
}
else if (nKey == SDL_SCANCODE_F5)
{
gDisplayDrawStats ^= 1;
printf("Stats %s\n", gDisplayDrawStats ? "ON" : "OFF");
}
2020-05-14 08:56:30 +02:00
else if (nKey == SDL_SCANCODE_KP_DIVIDE)
{
FunkUpDaBGMTunez(0);
}
else if (nKey == SDL_SCANCODE_KP_MULTIPLY)
{
FunkUpDaBGMTunez(1);
}
2020-04-27 09:53:49 +02:00
}
int main()
{
//g_texturelessMode = 1;
//g_wireframeMode = 1;
2020-04-27 09:53:49 +02:00
gameDebugKeys = GameDebugKeys;
gDrawDistance = 1300; // best distance
GPU_printf = printf;
Emulator_Initialise("REDRIVER2", 800, 600);
redriver2_main();
Emulator_ShutDown();
}