95 lines
2.0 KiB
C
95 lines
2.0 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "debug.h"
|
|
#if DOLPHIN
|
|
#include "display/display.h"
|
|
|
|
static char_t DEBUG_ERROR_BUFFER[16*1024] = {0};
|
|
#endif
|
|
|
|
void debugPrint(const char_t *message, ...) {
|
|
va_list args;
|
|
va_start(args, message);
|
|
vprintf(message, args);
|
|
va_end(args);
|
|
|
|
#if PSP
|
|
FILE *file = fopen("ms0:/PSP/GAME/Dusk/debug.log", "a");
|
|
if(file) {
|
|
va_start(args, message);
|
|
vfprintf(file, message, args);
|
|
va_end(args);
|
|
fclose(file);
|
|
}
|
|
|
|
#elif DOLPHIN
|
|
// append to error buffer
|
|
size_t start = strlen(DEBUG_ERROR_BUFFER);
|
|
va_start(args, message);
|
|
vsnprintf(
|
|
DEBUG_ERROR_BUFFER + start,
|
|
sizeof(DEBUG_ERROR_BUFFER) - start,
|
|
message,
|
|
args
|
|
);
|
|
va_end(args);
|
|
|
|
#endif
|
|
}
|
|
|
|
void debugFlush() {
|
|
#if PSP
|
|
// No buffering, so nothing to flush
|
|
#elif DOLPHIN
|
|
// Either create graphics, or hijack the displays' graphics.
|
|
void *xfb = NULL;
|
|
GXRModeObj *rmode = NULL;
|
|
void *framebuffer;
|
|
|
|
if(DISPLAY.frameBuffer[0]) {
|
|
console_init(
|
|
DISPLAY.frameBuffer[0],
|
|
20,
|
|
20,
|
|
DISPLAY.screenMode->fbWidth,
|
|
DISPLAY.screenMode->xfbHeight,
|
|
DISPLAY.screenMode->fbWidth * VI_DISPLAY_PIX_SZ
|
|
);
|
|
} else {
|
|
VIDEO_Init();
|
|
rmode = VIDEO_GetPreferredMode(NULL);
|
|
framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
|
|
console_init(
|
|
framebuffer,
|
|
20,
|
|
20,
|
|
rmode->fbWidth,
|
|
rmode->xfbHeight,
|
|
rmode->fbWidth*VI_DISPLAY_PIX_SZ
|
|
);
|
|
VIDEO_Configure(rmode);
|
|
VIDEO_SetNextFramebuffer(framebuffer);
|
|
VIDEO_SetBlack(FALSE);
|
|
VIDEO_Flush();
|
|
VIDEO_WaitVSync();
|
|
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
|
|
}
|
|
|
|
// Printf
|
|
printf("SOB\n");
|
|
printf(DEBUG_ERROR_BUFFER);
|
|
printf("\nEOB.");
|
|
|
|
while(SYS_MainLoop()) {
|
|
VIDEO_WaitVSync();
|
|
}
|
|
#else
|
|
fflush(stdout);
|
|
|
|
#endif
|
|
} |