From 2ced18d15138072675de05f1dc1d8c2196c455ff Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 6 Apr 2021 23:08:22 +0100 Subject: [PATCH] Change the log to my good old trusty log framework. --- main.c | 12 +-- source/audio.c | 3 +- source/emulate.c | 4 +- source/io.c | 24 ++--- source/log.c | 179 ++++++++++++++++++++++++++------------ source/log.h | 133 ++++++++++++++++++++++++---- source/memory.c | 10 +-- source/nec/CMakeLists.txt | 4 +- source/nec/nec.c | 8 +- source/rom.c | 84 +++++------------- source/ws.c | 13 +-- 11 files changed, 300 insertions(+), 174 deletions(-) diff --git a/main.c b/main.c index c1fcd9f..9649e1c 100644 --- a/main.c +++ b/main.c @@ -118,14 +118,9 @@ int main(int argc, char *argv[]) { wssystem_t ws_system = WS_SYSTEM_AUTODETECT; - if (!log_init(LOG_PATH)) - { - printf("Warning: cannot open log file %s\n", LOG_PATH); - } - snprintf(app_window_title, 255, "Oswan %s - Esc to return to GUI", VERSION); - fprintf(log_get(), "NewOswan %s (built at: %s %s)\n", VERSION, __DATE__, __TIME__); + Log(TLOG_ALWAYS, NULL, "NewOswan %s (built at: %s %s)", VERSION, __DATE__, __TIME__); ws_rom_path = NULL; @@ -141,7 +136,7 @@ int main(int argc, char *argv[]) ws_cyclesByLine = atoi(argv[n]); } - fprintf(log_get(), "Cycles by line set to %d\n", ws_cyclesByLine); + Log(TLOG_ALWAYS, "main", "Cycles by line set to %d", ws_cyclesByLine); break; case 'w': @@ -150,7 +145,7 @@ int main(int argc, char *argv[]) ws_system = atoi(argv[n]); } - fprintf(log_get(), "WonderSwan set to %d\n", ws_system); + Log(TLOG_ALWAYS, "main", "WonderSwan set to %d", ws_system); break; case 's': @@ -194,7 +189,6 @@ int main(int argc, char *argv[]) } } - log_done(); return (0); } diff --git a/source/audio.c b/source/audio.c index 8bbabca..6ee8231 100644 --- a/source/audio.c +++ b/source/audio.c @@ -143,8 +143,7 @@ static unsigned int ws_audio_log; //////////////////////////////////////////////////////////////////////////////// void ws_audio_init(void) { - fprintf(log_get(), "audio init\n"); - fflush(log_get()); + Log(TLOG_NORMAL, "audio", "audio init"); ws_audio_log = 0; //ws_audio_seal_init(); ws_audio_reset(); diff --git a/source/emulate.c b/source/emulate.c index d12f45c..e98a0b0 100644 --- a/source/emulate.c +++ b/source/emulate.c @@ -203,7 +203,7 @@ static void initDisplay(GLWindow *g) if (!(g->windows = glfwCreateWindow(g->WIDTH, g->HEIGHT, "Main", NULL, NULL))) { glfwTerminate(); - fprintf(stderr, "Window creation error...\n"); + Log(TLOG_PANIC, "emulate", "Window creation error..."); abort(); } @@ -274,7 +274,7 @@ static void read_keys() if (getKeyState(GLFW_KEY_R)) { - printf("Boop\n"); + Log(TLOG_DEBUG, "emulate", "Boop reset"); ws_reset(); } diff --git a/source/io.c b/source/io.c index 106687d..539f79e 100644 --- a/source/io.c +++ b/source/io.c @@ -281,7 +281,7 @@ void check_serial_data() if (f > 0) { - printf("Ho [%d]!\n", f); + Log(TLOG_DEBUG, "serial", "Have data from serial [%d]!", f); fflush(stdout); serial_have_data = 0x01; serial_data = buf[0]; @@ -294,7 +294,7 @@ void check_serial_data() if (ws_ioRam[0xB2] & 0x04) { ws_ioRam[0xb6] &= ~0x04; - printf("SERIAL INNNNNTTTT!!!!!!!"); + Log(TLOG_DEBUG, "serial", "SERIAL INNNNNTTTT!!!!!!!"); nec_int((ws_ioRam[0xb0] + 3) * 4); } } @@ -565,7 +565,7 @@ uint8_t cpu_readport(uint8_t port) /* Serial port link.. */ case 0xB1: retVal = read_serial(); - printf("RS232: Read %02X\n", retVal); + Log(TLOG_DEBUG, "serial", "Read %02X", retVal); goto exit; case 0xB3: @@ -580,7 +580,7 @@ uint8_t cpu_readport(uint8_t port) retVal = 0x00; } - printf("<<< 0xD0) { - printf("ReadIO %02X <= %02X\n", port, retVal); + Log(TLOG_DEBUG, "io", "ReadIO %02X <= %02X", port, retVal); } break; @@ -611,7 +611,7 @@ uint8_t cpu_readport(uint8_t port) if (port >= 0xC4) { - printf("ReadMBCIO(%02X) <= %02X\n", port, retVal); + Log(TLOG_DEBUG, "io", "ReadMBCIO(%02X) <= %02X", port, retVal); } @@ -688,7 +688,7 @@ void cpu_writeport(uint32_t port, uint8_t value) break; case 0x15: - printf("Icons %c %c %c %c %c %c %c %c\n", (value >> 7) & 1 ? '?' : ' ', (value >> 6) & 1 ? '?' : ' ', + Log(TLOG_DEBUG, "io", "Icons %c %c %c %c %c %c %c %c", (value >> 7) & 1 ? '?' : ' ', (value >> 6) & 1 ? '?' : ' ', (value >> 5) & 1 ? '3' : ' ', (value >> 4) & 1 ? '2' : ' ', (value >> 3) & 1 ? '1' : ' ', (value >> 2) & 1 ? 'H' : ' ', (value >> 1) & 1 ? 'V' : ' ', (value >> 0) & 1 ? 'S' : ' '); break; @@ -787,7 +787,7 @@ void cpu_writeport(uint32_t port, uint8_t value) break; /* System */ case 0x62: - printf("HeyHo!"); + Log(TLOG_DEBUG, "io", "HeyHo!"); break; /* Audio */ @@ -857,7 +857,7 @@ void cpu_writeport(uint32_t port, uint8_t value) break; case 0xB3: - printf(">>>>RS232STA: %02X [%c%c%cxx%c%c%c]\n", value, (value & 0x80) ? 'E' : 'd', (value & 0x40) ? '3' : '9', + Log(TLOG_DEBUG, "serial", ">>>>RS232STA: %02X [%c%c%cxx%c%c%c]", value, (value & 0x80) ? 'E' : 'd', (value & 0x40) ? '3' : '9', (value & 0x20) ? 'R' : 'n', (value & 0x04) ? 'E' : 'f', (value & 0x02) ? 'V' : 'n', (value & 0x01) ? 'D' : 'e'); @@ -1080,7 +1080,7 @@ void cpu_writeport(uint32_t port, uint8_t value) } else { - printf(" Unknown value: %02X\n", value); + printf(" Unknown value: %02X@", value); } fflush(stdout); } @@ -1119,11 +1119,11 @@ void cpu_writeport(uint32_t port, uint8_t value) if ((ws_gpu_port_write(port, value) == 1) && (unknown_io_port == 1)) { - fprintf(log_get(), "WriteIO(%02X, %02X) [%04X:%04Xh];\n", port, value, I.sregs[CS], I.ip); + Log(TLOG_DEBUG, "io", "WriteIO(%02X, %02X) [%04X:%04Xh];", port, value, I.sregs[CS], I.ip); } if (port >= 0xC4) { - fprintf(log_get(), "WriteMBCIO(%02X, %02X);\n", port, value); + Log(TLOG_DEBUG, "io", "WriteMBCIO(%02X, %02X);", port, value); } } diff --git a/source/log.c b/source/log.c index 0ad170e..c9fe4b7 100644 --- a/source/log.c +++ b/source/log.c @@ -1,74 +1,139 @@ /* - * NewOswan + * C Fancy Logger * log.c: - * Based on the original Oswan-unix - * Copyright (c) 2014-2021 986-Studio. All rights reserved. + * Copyright (c) 2009-2021 986-Studio. All rights reserved. * + * Created by Manoël Trapier on 20/01/2009. */ -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + +#define __LOG_C_INTERNAL_ #include -#include -#include "log.h" +#include +#include +#include +#include +#include +#include -FILE *log_stream = NULL; - -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -int log_init(char *path) +void log_displayPanic(int signal) { - //log_stream=fopen(path,"wrt"); - log_stream = stdout; + size_t size = 0; - if (log_stream == NULL) + //size = backtrace(array, 30); + /* Now flood user with unusefull data. */ + fprintf(stderr, FYELLOW "\n\n ----- " FYELLOW " YICK! ERROR YICK! [bt:%zu]" FYELLOW "----- \n", size); + + // get void*'s for all entries on the stack + + // print out all the frames to stderr + fprintf(stderr, " ----- Error: signal: %d -----\n" FRED, signal); + //backtrace_symbols_fd(array, size, 2); + fprintf(stderr, FYELLOW "\n\n ----- " FYELLOW " YICK! ERROR YICK! " FYELLOW "----- " CNORMAL "\n"); +} + +void time_stamp_line(void) +{ + /* Time "0" will be thefirst log line */ + static char firstRun = 1; + static struct timeval firstTime; + struct timeval curTime; + + int cMin, cSec; + long long cMSec; + + /* Get datetime */ + gettimeofday(&curTime, NULL); + + if (firstRun == 1) { - return (0); + firstRun = 0; + firstTime.tv_sec = curTime.tv_sec; + firstTime.tv_usec = curTime.tv_usec; } - return (1); + cMSec = ((curTime.tv_sec - firstTime.tv_sec) * 1000) + (curTime.tv_usec - firstTime.tv_usec) / 1000; + cSec = (cMSec / 1000); + cMSec %= 1000; + + cMin = cSec / 60; + + cSec %= 60; + + /* Put cursor at start of line */ + fprintf(stderr, "%c[s", 0x1B); + fprintf(stderr, "%c[7000D", 0x1B); + fprintf(stderr, "%c[1C", 0x1B); + fprintf(stderr, FWHITE"[" FYELLOW "%03d" FRED "." FBLUE "%02d" FRED "." FGREEN "%03lld" FWHITE "]" CNORMAL, cMin, + cSec, cMSec); + fprintf(stderr, "%c[u", 0x1B); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -FILE *log_get(void) +void log_real(int level, const char *user, const char *fmt, ...) { - return (log_stream); + int i; + va_list va; + + /* The LOG_PANIC must always be displayed */ + if ((level <= MAX_DEBUG_LEVEL) || (level <= TLOG_PANIC)) + { + fprintf(stderr, CNORMAL); + time_stamp_line(); + fprintf(stderr, CNORMAL " | "); + + switch (level) + { + case TLOG_PANIC: fprintf(stderr, BRED FWHITE); break; + case TLOG_ERROR: fprintf(stderr, FRED); break; + case TLOG_WARNING: fprintf(stderr, FYELLOW); break; + default: + case TLOG_NORMAL: fprintf(stderr, FGREEN); break; + case TLOG_VERBOSE: fprintf(stderr, FCYAN); break; + case TLOG_DEBUG: fprintf(stderr, BBLUE FWHITE); break; + } + + if (user != NULL) + { + i = strlen(user); + if (i < 12) + { + i = 12 - i; + for (; i >= 0 ; i--) + { + fprintf(stderr, " "); + } + } + fprintf(stderr, "%s", user); + } + else + { + switch (level) + { + case TLOG_PANIC: fprintf(stderr, " PANIC"); break; + case TLOG_ERROR: fprintf(stderr, " Error"); break; + case TLOG_WARNING: fprintf(stderr, " Warning"); break; + default: + case TLOG_NORMAL: fprintf(stderr, " Info"); break; + case TLOG_VERBOSE: fprintf(stderr, " Verbose"); break; + case TLOG_DEBUG: fprintf(stderr, " Debug"); break; + } + } + + fprintf(stderr, CNORMAL " | "); + + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); + + if (fmt[0] != 0) + { + fprintf(stderr, "\n"); + } + +#ifdef LOG_ALWAYS_FFLUSH + /* Systematicaly flush */ + fflush(stderr); +#endif + } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void log_done(void) -{ - fclose(log_stream); -} diff --git a/source/log.h b/source/log.h index 14b6941..c871e2e 100644 --- a/source/log.h +++ b/source/log.h @@ -1,25 +1,124 @@ /* - * NewOswan + * C Fancy Logger * log.h: - * Based on the original Oswan-unix - * Copyright (c) 2014-2021 986-Studio. All rights reserved. + * Copyright (c) 2009-2021 986-Studio. All rights reserved. * + * Created by Manoël Trapier on 20/01/2009. */ -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -#ifndef __LOG_H__ -#define __LOG_H__ - -int log_init(char *path); -FILE *log_get(void); -void log_done(void); +#ifndef _LOG_H +#define _LOG_H +#ifdef __cplusplus +extern "C" { #endif +#define ALLOW_COLORS + +#ifdef ALLOW_COLORS +#define __C(c) "\x1B[" c "m" +#else +#define __C(c) "" +#endif + +#define ANSI_COLOR __C +#define FBLACK ANSI_COLOR("30") +#define FRED ANSI_COLOR("31") +#define FGREEN ANSI_COLOR("32") +#define FYELLOW ANSI_COLOR("33") +#define FBLUE ANSI_COLOR("34") +#define FMAGENTA ANSI_COLOR("35") +#define FCYAN ANSI_COLOR("36") +#define FWHITE ANSI_COLOR("37") + +#define BBLACK ANSI_COLOR("40") +#define BRED ANSI_COLOR("41") +#define BGREEN ANSI_COLOR("42") +#define BYELLOW ANSI_COLOR("43") +#define BBLUE ANSI_COLOR("44") +#define BMAGENTA ANSI_COLOR("45") +#define BCYAN ANSI_COLOR("46") +#define BWHITE ANSI_COLOR("47") + +#define CNORMAL ANSI_COLOR("0") + +enum +{ + TLOG_ALWAYS = -1, + TLOG_PANIC = 0, + TLOG_ERROR, + TLOG_WARNING, + TLOG_NORMAL, + TLOG_VERBOSE, + TLOG_DEBUG, +}; + +//#define LOG_ALWAYS_FFLUSH +#define DYNA_LOG_LEVEL +#define SET_DEBUG_LOG + +/* Set if DYNALOG is set the maximum compiled log level */ +#ifndef MAXIMUM_DEBUG_LEVEL + +#ifndef SET_DEBUG_LOG +#define MAXIMUM_DEBUG_LEVEL TLOG_NORMAL +#else +#define MAXIMUM_DEBUG_LEVEL TLOG_DEBUG +#endif + +#endif /* MAXIMUM_DEBUG_LEVEL */ + +/* Set the default log level */ +#ifndef SET_DEBUG_LOG +#define DEFAULT_DEBUG_LEVEL TLOG_PANIC +#else +#define DEFAULT_DEBUG_LEVEL TLOG_DEBUG +#endif + +/******************************************************************************/ +/* DO NOT MESS AFTER THIS LINE */ +/******************************************************************************/ + +#ifdef DYNA_LOG_LEVEL +# ifdef MAX_DEBUG_LEVEL +# undef MAX_DEBUG_LEVEL +# endif +# ifdef __LOG_C_INTERNAL_ +int MAX_DEBUG_LEVEL = DEFAULT_DEBUG_LEVEL; +#else +extern int MAX_DEBUG_LEVEL; +#endif +#else +# ifndef MAX_DEBUG_LEVEL +# define MAX_DEBUG_LEVEL DEFAULT_DEBUG_LEVEL +# endif +#endif + +#define Log(_level, _user, _fmt, ...)\ + if (_level <= MAXIMUM_DEBUG_LEVEL)\ + if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC))\ + do { log_real(_level, _user, _fmt, ##__VA_ARGS__); } while(0) + +void log_real(int level, const char *user, const char *fmt, ...); + +#define LOG(_level, _str, ...) if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC)) do { fputs(_str, stderr); } while(0) +#define LOGCODE(_level, _user, _code)\ + if (_level <= MAXIMUM_DEBUG_LEVEL) do{\ + Log(_level, _user, "");\ + if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC))\ + do { _code; fprintf(stderr, "\n"); } while(0); } while(0) + +#define INFOL(_level, _fmt) LOGCODE(_level, "INFOL", { printf _fmt; }) + +#define FUNC_IN() Log(TLOG_VERBOSE, NULL, ">>%s", __func__) +#define FUNC_OUT() Log(TLOG_VERBOSE, NULL, "<<%s", __func__) +#define FUNC_OUTR(out) Log(TLOG_VERBOSE, NULL, "<<%s (%d)", __func__, out) + +void log_displayPanic(int signal); + +#ifdef __cplusplus +} +#endif + +#endif /* _LOG_H */ + diff --git a/source/memory.c b/source/memory.c index 2bfd545..5388936 100644 --- a/source/memory.c +++ b/source/memory.c @@ -277,7 +277,7 @@ char *load_file(char *filename) fstat(fd, &FileStat); - printf("Trying to load %s, size = %lu...\n", filename, (unsigned long)FileStat.st_size); + Log(TLOG_DEBUG, "memory", "Trying to load %s, size = %lu...", filename, (unsigned long)FileStat.st_size); ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); @@ -309,7 +309,7 @@ char *create_file(char *filename, uint32_t size) char *ret_ptr; char buf[] = {0}; - printf("Trying to create %s, size = %u...\n", filename, size); + Log(TLOG_DEBUG, "memory", "Trying to create %s, size = %u...\n", filename, size); fd = open(filename, O_CREAT | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_TRUNC, 0644); fchmod(fd, 0644); close(fd); @@ -399,17 +399,17 @@ void ws_memory_init(uint8_t *rom, uint32_t wsRomSize) if (internalColorIRom != NULL) { - printf("B&W IROM Found!\n"); + Log(TLOG_DEBUG, "memory", "B&W IROM Found!"); ws_haveColorIRom = true; } if (internalBWIRom != NULL) { - printf("Color IROM Found!\n"); + Log(TLOG_DEBUG, "memory", "Color IROM Found!"); ws_haveBWIRom = true; } if (internalCrystalIRom != NULL) { - printf("Crystal IROM Found!\n"); + Log(TLOG_DEBUG, "memory", "Crystal IROM Found!"); ws_haveCrystalIRom = true; } diff --git a/source/nec/CMakeLists.txt b/source/nec/CMakeLists.txt index 8d1d182..2adfabd 100644 --- a/source/nec/CMakeLists.txt +++ b/source/nec/CMakeLists.txt @@ -1,4 +1,6 @@ set(SOURCES nec.c) set(HEADERS nec.h necea.h necinstr.h necintrf.h necmodrm.h) -add_library(nec_v30 ${SOURCES} ${HEADERS}) \ No newline at end of file +add_library(nec_v30 ${SOURCES} ${HEADERS}) + +target_include_directories(nec_v30 PUBLIC . ..) \ No newline at end of file diff --git a/source/nec/nec.c b/source/nec/nec.c index dd1516f..26dcd9d 100644 --- a/source/nec/nec.c +++ b/source/nec/nec.c @@ -37,6 +37,8 @@ #include #include +#include + #include "nec.h" #include "necintrf.h" @@ -130,7 +132,7 @@ void nec_int(uint16_t vector) if ((dest_off == 0) && (dest_seg == 0)) { - printf("Something wrong with the interrupt, exiting...\n"); + Log(TLOG_PANIC, "NEC v30", "Something wrong with the interrupt, exiting..."); //dump_memory(); return; } @@ -160,7 +162,7 @@ static void nec_interrupt(uint32_t int_num, /*BOOLEAN*/ int md_flag) if ((dest_off == 0) && (dest_seg == 0)) { - printf("Something wrong with the interrupt, exiting...\n"); + Log(TLOG_PANIC, "NEC v30", "Something wrong with the interrupt, exiting..."); //dump_memory(); return; } @@ -4241,7 +4243,7 @@ int nec_execute(int cycles) { #if 0 uint8_t op = cpu_readmem20((I.sregs[CS]<<4) + I.ip); - printf("[%04x:%04xh] %02xh '%s' - I=%d\n", I.sregs[CS], I.ip, + Log(TLOG_NORMAL, "NEC v30", "[%04x:%04xh] %02xh '%s' - I=%d\n", I.sregs[CS], I.ip, op, instructionsName[op], I.IF); #endif nec_instruction[FETCHOP](); diff --git a/source/rom.c b/source/rom.c index f93e637..3146137 100644 --- a/source/rom.c +++ b/source/rom.c @@ -73,70 +73,34 @@ uint8_t *ws_rom_load(char *path, uint32_t *romSize) // // //////////////////////////////////////////////////////////////////////////////// + +const char *eepromSizeName[] = +{ + [WS_EEPROM_SIZE_NONE] = "none", + [WS_EEPROM_SIZE_64k] = "64kb", + [WS_EEPROM_SIZE_256k] = "256kb", +}; + +const char *sramSizeName[] = +{ + [WS_SRAM_SIZE_NONE] = "none", + [WS_SRAM_SIZE_1k] = "1kb", + [WS_SRAM_SIZE_8k] = "8kb", + [WS_SRAM_SIZE_16k] = "16kb", +}; + void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t romSize) { ws_romHeaderStruct *romHeader = ws_rom_getHeader(wsrom, romSize); - fprintf(log_get(), "rom: developper Id 0x%.2x\n", romHeader->developperId); - fprintf(log_get(), "rom: cart Id 0x%.2x\n", romHeader->cartId); - fprintf(log_get(), "rom: minimum system %s\n", - (romHeader->minimumSupportSystem == 0) ? "Wonderswan mono" : "Wonderswan color"); - fprintf(log_get(), "rom: size %i Mbits\n", (romSize >> 20) << 3); - fprintf(log_get(), "rom: eeprom "); - - switch (romHeader->eepromSize & 0xf) - { - case WS_EEPROM_SIZE_NONE: - { - fprintf(log_get(), "none\n"); - break; - } - - case WS_EEPROM_SIZE_64k: - { - fprintf(log_get(), "64 kb\n"); - break; - } - - case WS_EEPROM_SIZE_256k: - { - fprintf(log_get(), "256 kb\n"); - break; - } - } - - fprintf(log_get(), "rom: sram "); - - switch (romHeader->eepromSize & 0xf0) - { - case WS_SRAM_SIZE_NONE: - { - fprintf(log_get(), "none\n"); - break; - } - - case WS_SRAM_SIZE_1k: - { - fprintf(log_get(), "1 kb\n"); - break; - } - - case WS_SRAM_SIZE_16k: - { - fprintf(log_get(), "16 kb\n"); - break; - } - - case WS_SRAM_SIZE_8k: - { - fprintf(log_get(), "8 kn\n"); - break; - } - } - - fprintf(log_get(), "rom: rtc %s\n", (romHeader->realtimeClock) ? "Yes" : "None"); - fprintf(log_get(), "checksum 0x%.4x\n", romHeader->checksum); - + Log(TLOG_NORMAL, "rom", "developper Id 0x%.2x", romHeader->developperId); + Log(TLOG_NORMAL, "rom", "cart Id 0x%.2x", romHeader->cartId); + Log(TLOG_NORMAL, "rom", "minimum system %s", (romHeader->minimumSupportSystem == 0) ? "Wonderswan mono" : "Wonderswan color"); + Log(TLOG_NORMAL, "rom", "size %i Mbits", (romSize >> 20) << 3); + Log(TLOG_NORMAL, "rom", "eeprom %s", eepromSizeName[romHeader->eepromSize & 0xf]); + Log(TLOG_NORMAL, "rom", "sram %s", sramSizeName[romHeader->eepromSize & 0xF0]); + Log(TLOG_NORMAL, "rom", "rtc %s", (romHeader->realtimeClock) ? "Yes" : "None"); + Log(TLOG_NORMAL, "rom", "checksum 0x%.4x", romHeader->checksum); } //////////////////////////////////////////////////////////////////////////////// diff --git a/source/ws.c b/source/ws.c index 1b1aecc..830a831 100644 --- a/source/ws.c +++ b/source/ws.c @@ -75,7 +75,8 @@ void ws_patchRom(void) uint8_t *rom = memory_getRom(); uint32_t romSize = memory_getRomSize(); - fprintf(log_get(), "developper Id: 0x%.2x\nGame Id: 0x%.2x\n", rom[romSize - 10], rom[romSize - 8]); + Log(TLOG_DEBUG, "ws", "developper Id: 0x%.2x", rom[romSize - 10]); + Log(TLOG_DEBUG, "ws", "Game Id: 0x%.2x", rom[romSize - 8]); if (!ws_cyclesByLine) { @@ -101,7 +102,7 @@ int ws_init(char *rompath) if ((rom = ws_rom_load(rompath, &romSize)) == NULL) { - printf("Error: cannot load %s\n", rompath); + Log(TLOG_PANIC, "ws", "Error: cannot load %s", rompath); return (0); } @@ -116,7 +117,7 @@ int ws_init(char *rompath) if (ws_staticRam == NULL) { - printf("Card SRAM load error!\n"); + Log(TLOG_PANIC, "ws", "Card SRAM load error!\n"); return 0; } @@ -127,7 +128,7 @@ int ws_init(char *rompath) } if (externalEeprom == NULL) { - printf("Card EEPROM load error!\n"); + Log(TLOG_PANIC, "ws", "Card EEPROM load error!\n"); return 0; } @@ -332,7 +333,7 @@ wssystem_t ws_get_system() int ws_loadState(char *statepath) { - fprintf(log_get(), "loading %s\n", statepath); + Log(TLOG_NORMAL, "ws", "loading %s\n", statepath); uint16_t crc = memory_getRomCrc(); uint16_t newCrc; unsigned value; @@ -408,7 +409,7 @@ int ws_saveState(char *statepath) uint16_t crc = memory_getRomCrc(); uint32_t value; char newPath[1024]; - fprintf(log_get(), "saving %s\n", statepath); + Log(TLOG_DEBUG, "ws", "saving %s\n", statepath); if (strlen(statepath) < 4) {