Change the log to my good old trusty log framework.
This commit is contained in:
parent
359b05a518
commit
2ced18d151
12
main.c
12
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);
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
24
source/io.c
24
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("<<<<RS232STA: %02X [%c%c%cxx%c%c%c]\n", retVal, (retVal & 0x80) ? 'E' : 'd',
|
||||
Log(TLOG_DEBUG, "serial", "<<<<RS232STA: %02X [%c%c%cxx%c%c%c]", retVal, (retVal & 0x80) ? 'E' : 'd',
|
||||
(retVal & 0x40) ? '3' : '9', (retVal & 0x20) ? 'R' : 'n', (retVal & 0x04) ? 'E' : 'f',
|
||||
(retVal & 0x02) ? 'V' : 'n', (retVal & 0x01) ? 'D' : 'e');
|
||||
goto exit;
|
||||
@ -594,7 +594,7 @@ uint8_t cpu_readport(uint8_t port)
|
||||
retVal = ws_ioRam[port];
|
||||
if (port > 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);
|
||||
}
|
||||
}
|
||||
|
||||
179
source/log.c
179
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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "log.h"
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <log.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
133
source/log.h
133
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 */
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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})
|
||||
add_library(nec_v30 ${SOURCES} ${HEADERS})
|
||||
|
||||
target_include_directories(nec_v30 PUBLIC . ..)
|
||||
@ -37,6 +37,8 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <log.h>
|
||||
|
||||
#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]();
|
||||
|
||||
84
source/rom.c
84
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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
13
source/ws.c
13
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)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user