1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-06-01 05:41:27 +00:00

Add minimal logging functionality.

This commit is contained in:
Radosław Kujawa 2018-03-21 16:22:29 +01:00
parent 065d001135
commit 47aca32da7
4 changed files with 56 additions and 1 deletions

View File

@ -1,13 +1,14 @@
CLI=rk65c02cli
CLI_OBJS=rk65c02cli.o
LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_serial.o
LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_serial.o log.o
LIB_SO=librk65c02.so
LIB_STATIC=librk65c02.a
LDFLAGS_SO=-shared
LDFLAGS_CLI=-lreadline
CFLAGS=-Wall -fpic -ggdb
#CFLAGS=-Wall -fpic -ggdb -I/opt/local/include/uthash
65C02ISA=65c02isa
EMULATION=emulation

37
src/log.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdarg.h>
#include "log.h"
static const char *level_str[] = {
"",
"CRITICAL",
"ERROR",
"INFO",
"DEBUG",
"TRACE"
};
static uint8_t level = LOG_INFO;
void rk6502_loglevel_set(uint8_t l)
{
level = l;
}
void rk6502_log(uint8_t l, const char* fmt, ...)
{
va_list args;
if (l > level)
return;
fprintf(stderr, "%s:\t", level_str[l]);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
}

14
src/log.h Normal file
View File

@ -0,0 +1,14 @@
#include <stdint.h>
#define LOG_TRACE 5
#define LOG_DEBUG 4
#define LOG_INFO 3
#define LOG_ERROR 2
#define LOG_CRIT 1
#define LOG_NOTHING 0 /* At 0 nothing will get logged, can be set as
current level, but not when creating new log
messages. */
void rk6502_loglevel_set(uint8_t);
void rk6502_log(uint8_t, const char *, ...);

View File

@ -9,6 +9,7 @@
#include "bus.h"
#include "instruction.h"
#include "rk65c02.h"
#include "log.h"
#include "debug.h"
void rk65c02_exec(rk65c02emu_t *);
@ -34,6 +35,8 @@ rk65c02_init(bus_t *b)
e.trace_head = NULL;
e.runtime_disassembly = false;
rk6502_log(LOG_DEBUG, "Initialized new emulator.");
return e;
}