mirror of
https://github.com/rkujawa/rk65c02.git
synced 2025-01-10 18:29:53 +00:00
Add minimal logging functionality.
This commit is contained in:
parent
065d001135
commit
47aca32da7
@ -1,13 +1,14 @@
|
|||||||
CLI=rk65c02cli
|
CLI=rk65c02cli
|
||||||
CLI_OBJS=rk65c02cli.o
|
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_SO=librk65c02.so
|
||||||
LIB_STATIC=librk65c02.a
|
LIB_STATIC=librk65c02.a
|
||||||
|
|
||||||
LDFLAGS_SO=-shared
|
LDFLAGS_SO=-shared
|
||||||
LDFLAGS_CLI=-lreadline
|
LDFLAGS_CLI=-lreadline
|
||||||
CFLAGS=-Wall -fpic -ggdb
|
CFLAGS=-Wall -fpic -ggdb
|
||||||
|
#CFLAGS=-Wall -fpic -ggdb -I/opt/local/include/uthash
|
||||||
|
|
||||||
65C02ISA=65c02isa
|
65C02ISA=65c02isa
|
||||||
EMULATION=emulation
|
EMULATION=emulation
|
||||||
|
37
src/log.c
Normal file
37
src/log.c
Normal 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
14
src/log.h
Normal 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 *, ...);
|
||||||
|
|
@ -9,6 +9,7 @@
|
|||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
#include "instruction.h"
|
#include "instruction.h"
|
||||||
#include "rk65c02.h"
|
#include "rk65c02.h"
|
||||||
|
#include "log.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
void rk65c02_exec(rk65c02emu_t *);
|
void rk65c02_exec(rk65c02emu_t *);
|
||||||
@ -34,6 +35,8 @@ rk65c02_init(bus_t *b)
|
|||||||
e.trace_head = NULL;
|
e.trace_head = NULL;
|
||||||
e.runtime_disassembly = false;
|
e.runtime_disassembly = false;
|
||||||
|
|
||||||
|
rk6502_log(LOG_DEBUG, "Initialized new emulator.");
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user