Merge remote-tracking branch 'base/port' into port

This commit is contained in:
Raf committed 2023-08-31 20:07:43 +08:00
commit 49963c2e47
15 files changed
+192 -54

No files matched your search

+1 -2
View File
@@ -799,8 +799,7 @@ typedef void (APIENTRY *DEBUGPROC)(GLenum source,
static void APIENTRY gl_debug(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *msg, const void *p) {
if (severity > 0x826B) {
printf("GL: from %04x: type %04x: %s\n", source, type, msg);
fflush(stdout);
sysLogPrintf(LOG_WARNING, "GL: %s", msg);
}
}
+7 -9
View File
@@ -430,7 +430,7 @@ static void gfx_generate_cc(struct ColorCombiner* comb, const ColorCombinerKey&
val = SHADER_COMBINED;
break;
default:
fprintf(stderr, "Unsupported ccmux: %d\n", c[i][0][j]);
sysLogPrintf(LOG_WARNING, "Unsupported ccmux: %d", c[i][0][j]);
break;
}
shader_id0 |= (uint64_t)val << (i * 32 + j * 4);
@@ -878,7 +878,7 @@ static void import_texture(int i, int tile, bool importReplacement) {
} else if (siz == G_IM_SIZ_32b) {
import_texture_rgba32(tile, importReplacement);
} else {
abort();
sysFatalError("Bad size for RGBA texture in tile %d: %02x", tile, siz);
}
} else if (fmt == G_IM_FMT_IA) {
if (siz == G_IM_SIZ_4b) {
@@ -888,7 +888,7 @@ static void import_texture(int i, int tile, bool importReplacement) {
} else if (siz == G_IM_SIZ_16b) {
import_texture_ia16(tile, importReplacement);
} else {
abort();
sysFatalError("Bad size for IA texture in tile %d: %02x", tile, siz);
}
} else if (fmt == G_IM_FMT_CI) {
if (siz == G_IM_SIZ_4b) {
@@ -896,7 +896,7 @@ static void import_texture(int i, int tile, bool importReplacement) {
} else if (siz == G_IM_SIZ_8b) {
import_texture_ci8(tile, importReplacement);
} else {
abort();
sysFatalError("Bad size for CI texture in tile %d: %02x", tile, siz);
}
} else if (fmt == G_IM_FMT_I) {
if (siz == G_IM_SIZ_4b) {
@@ -904,10 +904,10 @@ static void import_texture(int i, int tile, bool importReplacement) {
} else if (siz == G_IM_SIZ_8b) {
import_texture_i8(tile, importReplacement);
} else {
abort();
sysFatalError("Bad size for I texture in tile %d: %02x", tile, siz);
}
} else {
abort();
sysFatalError("Bad texture format in tile %d: %02x %02x", tile, fmt, siz);
}
}
@@ -2590,9 +2590,7 @@ static void gfx_run_dl(Gfx* cmd) {
case G_RDPTILESYNC:
break;
default:
fprintf(stderr, "gfx: unknown opcode %d, words %08x %08x\n", (s8)opcode, cmd->words.w0, cmd->words.w1);
fflush(stderr);
SUPPORT_CHECK(0 && "Unknown GBI opcode");
sysFatalError("Unknown GBI opcode 0x%02x at %p.\nw0 %08x\nw1 %08x", opcode, cmd, cmd->words.w0, cmd->words.w1);
break;
}
++cmd;
+1 -1
View File
@@ -10,7 +10,7 @@
#include <PR/gbi.h>
extern "C" void sysFatalError(const char *fmt, ...) __attribute__((noreturn));
#include "system.h"
#define SCREEN_WIDTH ((int32_t)gfx_current_native_viewport.width)
#define SCREEN_HEIGHT ((int32_t)gfx_current_native_viewport.height)
+11 -1
View File
@@ -8,6 +8,8 @@
#include <time.h>
#endif
#include "system.h"
#include "gfx_window_manager_api.h"
#include "gfx_screen_config.h"
@@ -63,7 +65,9 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s
window_width = width;
window_height = height;
SDL_Init(SDL_INIT_VIDEO);
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
sysFatalError("Could not init SDL:\n%s", SDL_GetError());
}
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
@@ -97,9 +101,15 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s
}
wnd = SDL_CreateWindow(title, posX, posY, window_width, window_height, flags);
if (!wnd) {
sysFatalError("Could not open SDL window:\n%s", SDL_GetError());
}
if (use_opengl) {
ctx = SDL_GL_CreateContext(wnd);
if (!ctx) {
sysFatalError("Could not create GL2.1 context:\n%s", SDL_GetError());
}
SDL_GL_MakeCurrent(wnd, ctx);
SDL_GL_SetSwapInterval(1);
}
+22 -1
View File
@@ -1,17 +1,38 @@
#ifndef _IN_SYSTEM_H
#define _IN_SYSTEM_H
#ifdef __cplusplus
extern "C" {
#endif
#include <PR/ultratypes.h>
void sysInitTicks(void);
enum LogLevel {
LOG_NOTE,
LOG_WARNING,
LOG_ERROR,
};
void sysInit(s32 argc, const char **argv);
s32 sysArgCheck(const char *arg);
const char *sysArgGetString(const char *arg);
s32 sysArgGetInt(const char *arg, s32 defval);
u64 sysGetMicroseconds(void);
void sysFatalError(const char *fmt, ...) __attribute__((noreturn));
void sysLogPrintf(s32 level, const char *fmt, ...);
void sysGetExecutablePath(char *outPath, const u32 outLen);
void *sysMemAlloc(const u32 size);
void *sysMemZeroAlloc(const u32 size);
void sysMemFree(void *ptr);
#ifdef __cplusplus
}
#endif
#endif
+3 -2
View File
@@ -3,6 +3,7 @@
#include <SDL.h>
#include "config.h"
#include "audio.h"
#include "system.h"
static SDL_AudioDeviceID dev;
static const s16 *nextBuf;
@@ -12,7 +13,7 @@ static u32 queueLimit = 8192;
s32 audioInit(void)
{
if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) {
fprintf(stderr, "SDL audio init error: %s\n", SDL_GetError());
sysLogPrintf(LOG_ERROR, "SDL audio init error: %s", SDL_GetError());
return -1;
}
@@ -28,7 +29,7 @@ s32 audioInit(void)
dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
if (dev == 0) {
fprintf(stderr, "SDL_OpenAudio error: %s\n", SDL_GetError());
sysLogPrintf(LOG_ERROR, "SDL_OpenAudio error: %s", SDL_GetError());
return -1;
}
+2 -1
View File
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <string.h>
#include <PR/ultratypes.h>
#include "system.h"
u8 g_CrashHasMessage = 0;
s32 g_CrashEnabled = 0;
@@ -16,7 +17,7 @@ void crashCreateThread(void)
void crashSetMessage(char *string)
{
strncpy(crashMsg, string, sizeof(crashMsg) - 1);
fprintf(stderr, "crashSetMessage: %s\n", crashMsg);
sysLogPrintf(LOG_ERROR, "crashSetMessage: %s", crashMsg);
g_CrashHasMessage = 1;
}
+3 -3
View File
@@ -54,7 +54,7 @@ void *fsFileLoad(const char *name, u32 *outSize)
FILE *f = fopen(fullName, "rb");
if (!f) {
fprintf(stderr, "fsFileLoad: could not find file: %s\n", fullName);
sysLogPrintf(LOG_ERROR, "fsFileLoad: could not find file: %s", fullName);
return NULL;
}
@@ -63,7 +63,7 @@ void *fsFileLoad(const char *name, u32 *outSize)
fseek(f, 0, SEEK_SET);
if (size < 0) {
fprintf(stderr, "fsFileLoad: empty file or invalid size (%d): %s\n", size, fullName);
sysLogPrintf(LOG_ERROR, "fsFileLoad: empty file or invalid size (%d): %s", size, fullName);
fclose(f);
return NULL;
}
@@ -72,7 +72,7 @@ void *fsFileLoad(const char *name, u32 *outSize)
if (size) {
buf = sysMemZeroAlloc(size + 1); // sick hack for a free null terminator
if (!buf) {
fprintf(stderr, "fsFileLoad: could not alloc %d bytes for file: %s\n", size, fullName);
sysLogPrintf(LOG_ERROR, "fsFileLoad: could not alloc %d bytes for file: %s", size, fullName);
fclose(f);
return NULL;
}
+3 -2
View File
@@ -8,6 +8,7 @@
#include "input.h"
#include "video.h"
#include "config.h"
#include "system.h"
#define MAX_BINDS 4
#define TRIG_THRESHOLD (30 * 256)
@@ -741,7 +742,7 @@ s32 inputGetContKeyByName(const char *name)
return i;
}
}
fprintf(stderr, "unknown bind name: `%s`\n", name);
sysLogPrintf(LOG_WARNING, "unknown bind name: `%s`", name);
return -1;
}
@@ -785,7 +786,7 @@ s32 inputGetKeyByName(const char *name)
}
}
fprintf(stderr, "unknown key name: `%s`\n", name);
sysLogPrintf(LOG_WARNING, "unknown key name: `%s`", name);
return -1;
}
+2 -2
View File
@@ -260,7 +260,7 @@ static inline void osEeepromLoad(const char *fname)
fread(eeprom, 1, EEPROM_SIZE, fp);
fsFileClose(fp);
} else {
printf("could not read EEPROM from `%s`: %s\n", fname, strerror(errno));
sysLogPrintf(LOG_NOTE, "could not read EEPROM from `%s`: %s", fname, strerror(errno));
}
}
}
@@ -272,7 +272,7 @@ static inline void osEeepromSave(const char *fname)
fwrite(eeprom, 1, EEPROM_SIZE, fp);
fsFileClose(fp);
} else {
fprintf(stderr, "could not save EEPROM to `%s`: %s\n", fname, strerror(errno));
sysLogPrintf(LOG_ERROR, "could not save EEPROM to `%s`: %s", fname, strerror(errno));
}
}
+12 -3
View File
@@ -32,6 +32,8 @@ u32 g_VmNumPageMisses = 0;
u32 g_VmNumPageReplaces = 0;
u8 g_VmShowStats = 0;
extern s32 g_StageNum;
s32 bootGetMemSize(void)
{
return (s32)g_OsMemSize;
@@ -55,6 +57,7 @@ void bootCreateSched(void)
static void cleanup(void)
{
sysLogPrintf(LOG_NOTE, "shutdown");
inputSaveConfig();
configSave(CONFIG_FNAME);
// TODO: actually shut down all subsystems
@@ -72,7 +75,7 @@ static void gameLoadConfig(void)
int main(int argc, const char **argv)
{
sysInitTicks();
sysInit(argc, argv);
fsInit();
configInit();
videoInit();
@@ -94,8 +97,14 @@ int main(int argc, const char **argv)
sysFatalError("Could not alloc %u bytes for memp heap.", g_MempHeapSize);
}
printf("memp heap at %p - %p\n", g_MempHeap, g_MempHeap + g_MempHeapSize);
printf("rom file at %p - %p\n", g_RomFile, g_RomFile + g_RomFileSize);
sysLogPrintf(LOG_NOTE, "memp heap at %p - %p", g_MempHeap, g_MempHeap + g_MempHeapSize);
sysLogPrintf(LOG_NOTE, "rom file at %p - %p", g_RomFile, g_RomFile + g_RomFileSize);
g_SndDisabled = sysArgCheck("--no-sound");
g_StageNum = sysArgGetInt("--boot-stage", STAGE_TITLE);
if (g_StageNum != STAGE_TITLE) {
sysLogPrintf(LOG_NOTE, "boot stage set to 0x%02x", g_StageNum);
}
mainProc();
+3 -4
View File
@@ -12,6 +12,7 @@
#include "game/texdecompress.h"
#include "preprocess.h"
#include "romdata.h"
#include "system.h"
static inline f32 swapF32(f32 x) { *(u32 *)&x = PD_BE32(*(u32 *)&x); return x; }
static inline u32 swapU32(u32 x) { return PD_BE32(x); }
@@ -413,7 +414,7 @@ static u8 *preprocessModelNode(struct modelnode *node, u8 *base, u32 ofs)
}
break;
default:
fprintf(stderr, "preprocessModelNode: node at %p: unknown node->type: 0x%02x\n", node, node->type & 0xff);
sysLogPrintf(LOG_ERROR, "preprocessModelNode: node at %p: unknown node->type: 0x%02x", node, node->type & 0xff);
break;
}
}
@@ -939,9 +940,7 @@ static void preprocessPropObj(struct defaultobj *obj)
break;
}
default: {
fprintf(stderr, "unknown objtype: %02x @ %p\n", obj->type, obj);
fflush(stderr);
assert(0 && "Unknown object type in prop list");
sysFatalError("Unknown object type in prop list: %02x\nat %p", obj->type, obj);
break;
}
}
+22 -18
View File
@@ -38,6 +38,7 @@ u32 g_RomFileSize;
static u8 *romDataSeg;
static u32 romDataSegSize;
static const char *romName = ROMDATA_ROM_NAME;
struct romfile {
u8 **segstart;
@@ -120,10 +121,12 @@ static preprocessfunc filePreprocFuncs[] = {
static inline void romdataLoadRom(void)
{
g_RomFile = fsFileLoad(ROMDATA_ROM_NAME, &g_RomFileSize);
sysLogPrintf(LOG_NOTE, "ROM file: %s", romName);
g_RomFile = fsFileLoad(romName, &g_RomFileSize);
if (!g_RomFile) {
sysFatalError("Could not open ROM file " ROMDATA_ROM_NAME ".\nEnsure that it is in the data directory.");
sysFatalError("Could not open ROM file %s.\nEnsure that it is in the data directory.", romName);
}
if (g_RomFileSize != ROMDATA_ROM_SIZE) {
@@ -190,16 +193,14 @@ static inline void romdataInitSegment(struct romfile *seg)
// no external data, just make it point to the rom
if (g_RomFile) {
newData = g_RomFile + (uintptr_t)seg->data;
printf("loading segment %s from ROM (offset %08x pointer %p)\n", seg->name, (u32)seg->data, newData);
fflush(stdout);
sysLogPrintf(LOG_NOTE, "loading segment %s from ROM (offset %08x pointer %p)", seg->name, (u32)seg->data, newData);
} else {
sysFatalError("No ROM or external file for segment:\n%s", seg->name);
}
} else {
// loaded external data
seg->external = 1;
printf("loading segment %s from file (pointer %p)\n", seg->name, newData);
fflush(stdout);
sysLogPrintf(LOG_NOTE, "loading segment %s from file (pointer %p)", seg->name, newData);
}
seg->data = newData;
@@ -275,7 +276,6 @@ static inline void romdataInitFiles(void)
for (i = 1; nameOffsets[i]; ++i) {
const u32 ofs = PD_BE32(nameOffsets[i]);
fileSlots[i].name = (const char *)nameOffsets + ofs; // ofs is relative to the start of the name table
printf("file %d name `%s` ofs %d size %u\n", i, fileSlots[i].name, fileSlots[i].data - g_RomFile, fileSlots[i].size);
}
}
@@ -290,6 +290,11 @@ static inline struct romfile *romdataGetSeg(const char *name)
s32 romdataInit(void)
{
const char *altRomName = sysArgGetString("--rom-file");
if (altRomName) {
romName = altRomName;
}
romdataLoadRom();
// set segments to point to the rom or load them externally
@@ -300,8 +305,7 @@ s32 romdataInit(void)
// load file table from the files segment
romdataInitFiles();
printf("romdataInit: loaded rom, size = %u\n", g_RomFileSize);
fflush(stdout);
sysLogPrintf(LOG_NOTE, "romdataInit: loaded rom, size = %u", g_RomFileSize);
return 0;
}
@@ -309,11 +313,11 @@ s32 romdataInit(void)
s32 romdataFileGetSize(s32 fileNum)
{
if (fileNum < 1 || fileNum >= ROMDATA_MAX_FILES) {
fprintf(stderr, "romdataFileGetSize: invalid file num %d", fileNum);
sysLogPrintf(LOG_ERROR, "romdataFileGetSize: invalid file num %d", fileNum);
return -1;
}
if (!fileSlots[fileNum].data) {
fprintf(stderr, "romdataFileGetSize: file %d is not loaded", fileNum);
sysLogPrintf(LOG_ERROR, "romdataFileGetSize: file %d is not loaded", fileNum);
return -1;
}
return fileSlots[fileNum].size;
@@ -322,11 +326,11 @@ s32 romdataFileGetSize(s32 fileNum)
u8 *romdataFileGetData(s32 fileNum)
{
if (fileNum < 1 || fileNum >= ROMDATA_MAX_FILES) {
fprintf(stderr, "romdataFileGetData: invalid file num %d", fileNum);
sysLogPrintf(LOG_ERROR, "romdataFileGetData: invalid file num %d", fileNum);
return NULL;
}
if (!fileSlots[fileNum].data) {
fprintf(stderr, "romdataFileGetData: file %d is not loaded, loading", fileNum);
sysLogPrintf(LOG_NOTE, "romdataFileGetData: file %d is not loaded, loading", fileNum);
return romdataFileLoad(fileNum, NULL);
}
return fileSlots[fileNum].data;
@@ -335,7 +339,7 @@ u8 *romdataFileGetData(s32 fileNum)
u8 *romdataFileLoad(s32 fileNum, u32 *outSize)
{
if (fileNum < 1 || fileNum >= ROMDATA_MAX_FILES) {
fprintf(stderr, "romdataFileLoad: invalid file num %d", fileNum);
sysLogPrintf(LOG_ERROR, "romdataFileLoad: invalid file num %d", fileNum);
return NULL;
}
@@ -349,7 +353,7 @@ u8 *romdataFileLoad(s32 fileNum, u32 *outSize)
u32 size = 0;
out = fsFileLoad(tmp, &size);
if (out && size) {
printf("file %d (%s) loaded externally\n", fileNum, fileSlots[fileNum].name);
sysLogPrintf(LOG_NOTE, "file %d (%s) loaded externally", fileNum, fileSlots[fileNum].name);
fileSlots[fileNum].data = out;
fileSlots[fileNum].size = size;
fileSlots[fileNum].external = 1;
@@ -371,7 +375,7 @@ u8 *romdataFileLoad(s32 fileNum, u32 *outSize)
void romdataFilePreprocess(s32 fileNum, s32 loadType, u8 *data, u32 size)
{
if (fileNum < 1 || fileNum >= ROMDATA_MAX_FILES) {
fprintf(stderr, "romdataFilePreprocess: invalid file num %d", fileNum);
sysLogPrintf(LOG_ERROR, "romdataFilePreprocess: invalid file num %d", fileNum);
return;
}
@@ -386,12 +390,12 @@ void romdataFilePreprocess(s32 fileNum, s32 loadType, u8 *data, u32 size)
void romdataFileFree(s32 fileNum)
{
if (fileNum < 1 || fileNum >= ROMDATA_MAX_FILES) {
fprintf(stderr, "fsFileFree: invalid file num %d", fileNum);
sysLogPrintf(LOG_ERROR, "fsFileFree: invalid file num %d", fileNum);
return;
}
if (!fileSlots[fileNum].external) {
fprintf(stderr, "fsFileFree: file %d not external", fileNum);
sysLogPrintf(LOG_ERROR, "fsFileFree: file %d not external", fileNum);
return;
}
+92 -2
View File
@@ -2,18 +2,80 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <sys/time.h>
#include <SDL.h>
#include <PR/ultratypes.h>
#include "system.h"
#define LOG_FNAME "./pd.log"
#define USEC_IN_SEC 1000000ULL
static u64 startTick = 0;
static s32 logToFile = 0;
void sysInitTicks(void)
static s32 sysArgc;
static const char **sysArgv;
void sysInit(s32 argc, const char **argv)
{
startTick = sysGetMicroseconds();
sysArgc = argc;
sysArgv = argv;
logToFile = sysArgCheck("--log");
if (logToFile) {
// clear log
FILE *f = fopen(LOG_FNAME, "wb");
if (f) {
fclose(f);
}
}
#ifdef VERSION_HASH
sysLogPrintf(LOG_NOTE, "version: " VERSION_HASH " (" VERSION_TARGET ")");
#endif
char timestr[256];
const time_t curtime = time(NULL);
strftime(timestr, sizeof(timestr), "%d %b %Y %H:%M:%S", localtime(&curtime));
sysLogPrintf(LOG_NOTE, "startup date: %s", timestr);
}
s32 sysArgCheck(const char *arg)
{
for (s32 i = 1; i < sysArgc; ++i) {
if (!strcasecmp(sysArgv[i], arg)) {
return 1;
}
}
return 0;
}
const char *sysArgGetString(const char *arg)
{
for (s32 i = 1; i < sysArgc; ++i) {
if (!strcasecmp(sysArgv[i], arg)) {
if (i < sysArgc - 1) {
return sysArgv[i + 1];
}
}
}
return NULL;
}
s32 sysArgGetInt(const char *arg, s32 defval)
{
for (s32 i = 1; i < sysArgc; ++i) {
if (!strcasecmp(sysArgv[i], arg)) {
if (i < sysArgc - 1) {
return strtol(sysArgv[i + 1], NULL, 0);
}
}
}
return defval;
}
u64 sysGetMicroseconds(void)
@@ -23,6 +85,31 @@ u64 sysGetMicroseconds(void)
return ((u64)tv.tv_sec * USEC_IN_SEC + (u64)tv.tv_usec) - startTick;
}
void sysLogPrintf(s32 level, const char *fmt, ...)
{
static const char *prefix[3] = {
"", "WARNING: ", "ERROR: "
};
char logmsg[2048];
va_list ap;
va_start(ap, fmt);
vsnprintf(logmsg, sizeof(logmsg), fmt, ap);
va_end(ap);
if (logToFile) {
FILE *f = fopen(LOG_FNAME, "ab");
if (f) {
fprintf(f, "%s%s\n", prefix[level], logmsg);
fclose(f);
}
}
FILE *fout = (level == LOG_NOTE) ? stdout : stderr;
fprintf(fout, "%s%s\n", prefix[level], logmsg);
}
void sysFatalError(const char *fmt, ...)
{
char errmsg[2048] = { 0 };
@@ -32,10 +119,13 @@ void sysFatalError(const char *fmt, ...)
vsnprintf(errmsg, sizeof(errmsg), fmt, ap);
va_end(ap);
fprintf(stderr, "FATAL ERROR: %s\n", errmsg);
sysLogPrintf(LOG_ERROR, "FATAL: %s", errmsg);
fflush(stdout);
fflush(stderr);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error", errmsg, NULL);
exit(1);
}
+8 -3
View File
@@ -8,9 +8,11 @@
#include "data.h"
#include "types.h"
#else
#include <stdio.h>
#include <stdarg.h>
#include <stdio.h>
#include "system.h"
#include "types.h"
#include "lib/crash.h"
#endif
void rmonproc()
@@ -72,14 +74,17 @@ char *rmonProut(char *dst, const char *src, size_t count)
void rmonPrintf(const char *format, ...)
{
#ifndef PLATFORM_N64
char msg[2048];
#endif
va_list ap;
va_start(ap, format);
#ifdef PLATFORM_N64
_Printf(rmonProut, NULL, format, ap);
#else
fprintf(stderr, "rmonPrintf: ");
vfprintf(stderr, format, ap);
vsnprintf(msg, sizeof(msg), format, ap);
va_end(ap);
sysLogPrintf(LOG_NOTE, "rmonPrintf: %s", msg);
#endif
}