1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2025-01-10 18:29:53 +00:00

Further improvements and refactoring to logging.

This commit is contained in:
Radosław Kujawa 2018-03-22 15:08:51 +01:00
parent 47aca32da7
commit 5cb6f3488e
7 changed files with 35 additions and 14 deletions

View File

@ -2,15 +2,18 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <utlist.h> #include <utlist.h>
#include "bus.h" #include "bus.h"
#include "log.h"
#include "device_ram.h" #include "device_ram.h"
@ -68,7 +71,7 @@ bus_access_device(bus_t *t, uint16_t addr, device_t **d, uint16_t *off)
} }
if (*d == NULL) { if (*d == NULL) {
fprintf(stderr, "Hitting unmapped bus space @ %x!", addr); rk6502_log(LOG_WARN, "Hitting unmapped bus space @ %x!", addr);
return; return;
} }
@ -90,7 +93,8 @@ bus_read_1(bus_t *t, uint16_t addr)
val = d->read_1(d, off); val = d->read_1(d, off);
if (t->access_debug) if (t->access_debug)
printf("bus READ @ %x (off %x) value %x\n", addr, off, val); rk6502_log(LOG_DEBUG, "bus READ @ %x (off %x) value %x\n",
addr, off, val);
return val; return val;
} }
@ -104,7 +108,8 @@ bus_write_1(bus_t *t, uint16_t addr, uint8_t val)
bus_access_device(t, addr, &d, &off); bus_access_device(t, addr, &d, &off);
if (t->access_debug) if (t->access_debug)
printf("bus WRITE @ %x (off %x) value %x\n", addr, off, val); rk6502_log(LOG_DEBUG, "bus WRITE @ %x (off %x) value %x\n",
addr, off, val);
d->write_1(d, off, val); d->write_1(d, off, val);
} }
@ -158,7 +163,8 @@ bus_load_file(bus_t *t, uint16_t addr, const char *filename)
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd == -1) { if (fd == -1) {
perror("Problem while trying to open file"); rk6502_log(LOG_ERROR, "Problem while trying to open file: %s",
strerror(errno));
return false; return false;
} }

View File

@ -4,6 +4,7 @@
#include "rk65c02.h" #include "rk65c02.h"
#include "instruction.h" #include "instruction.h"
#include "log.h"
#include "debug.h" #include "debug.h"
void void
@ -26,7 +27,7 @@ debug_trace_print_all(rk65c02emu_t *e)
i.op1 = tr->op1; i.op1 = tr->op1;
i.op2 = tr->op2; i.op2 = tr->op2;
printf("TRACE %X:\t", tr->address); rk6502_log(LOG_TRACE, " %X:\t", tr->address);
instruction_print(&i); instruction_print(&i);
printf("\t"); printf("\t");
rk65c02_dump_regs(tr->regs); rk65c02_dump_regs(tr->regs);

View File

@ -9,6 +9,7 @@
#include "bus.h" #include "bus.h"
#include "rk65c02.h" #include "rk65c02.h"
#include "65c02isa.h" #include "65c02isa.h"
#include "log.h"
#include "instruction.h" #include "instruction.h"
instruction_t instruction_t
@ -172,14 +173,16 @@ assemble_single_buf(uint8_t **buf, uint8_t *bsize, const char *mnemonic, address
} }
if (!found) { if (!found) {
fprintf(stderr, "Couldn't find opcode for mnemonic %s mode %x\n", mnemonic, mode); rk6502_log(LOG_ERROR,
"Couldn't find opcode for mnemonic %s mode %x.",
mnemonic, mode);
return false; return false;
} }
*bsize = id.size; *bsize = id.size;
*buf = malloc(id.size); *buf = malloc(id.size);
if(*buf == NULL) { if(*buf == NULL) {
fprintf(stderr, "Error allocating assembly buffer\n"); rk6502_log(LOG_ERROR, "Error allocating assembly buffer.");
return false; return false;
} }
@ -301,8 +304,8 @@ instruction_data_write_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i, uint
* PC which is handled within emulation of a given opcode. * PC which is handled within emulation of a given opcode.
*/ */
default: default:
printf("unhandled addressing mode for opcode %x\n", rk6502_log(LOG_ERROR,
i->opcode); "unhandled addressing mode for opcode %x\n", i->opcode);
break; break;
} }
} }
@ -368,8 +371,8 @@ instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i)
* PC which is handled within emulation of a given opcode. * PC which is handled within emulation of a given opcode.
*/ */
default: default:
printf("unhandled addressing mode for opcode %x\n", rk6502_log(LOG_ERROR,
i->opcode); "unhandled addressing mode for opcode %x\n", i->opcode);
break; break;
} }

View File

@ -1,6 +1,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/time.h>
#include "log.h" #include "log.h"
static const char *level_str[] = { static const char *level_str[] = {
@ -22,11 +24,15 @@ void rk6502_loglevel_set(uint8_t l)
void rk6502_log(uint8_t l, const char* fmt, ...) void rk6502_log(uint8_t l, const char* fmt, ...)
{ {
va_list args; va_list args;
struct timeval t;
gettimeofday(&t, NULL);
if (l > level) if (l > level)
return; return;
fprintf(stderr, "%s:\t", level_str[l]); fprintf(stderr, "%ld %s:\t", (t.tv_sec * 1000000 + t.tv_usec),
level_str[l]);
va_start(args, fmt); va_start(args, fmt);
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);

View File

@ -3,6 +3,7 @@
#define LOG_TRACE 5 #define LOG_TRACE 5
#define LOG_DEBUG 4 #define LOG_DEBUG 4
#define LOG_INFO 3 #define LOG_INFO 3
#define LOG_WARN 4
#define LOG_ERROR 2 #define LOG_ERROR 2
#define LOG_CRIT 1 #define LOG_CRIT 1
#define LOG_NOTHING 0 /* At 0 nothing will get logged, can be set as #define LOG_NOTHING 0 /* At 0 nothing will get logged, can be set as

View File

@ -119,8 +119,8 @@ rk65c02_exec(rk65c02emu_t *e)
if (!instruction_modify_pc(&id)) if (!instruction_modify_pc(&id))
program_counter_increment(e, &id); program_counter_increment(e, &id);
} else { } else {
printf("unimplemented opcode %X @ %X\n", i.opcode, rk6502_log(LOG_ERROR, "unimplemented opcode %X @ %X\n",
e->regs.PC); i.opcode, e->regs.PC);
e->state = STOPPED; e->state = STOPPED;
e->stopreason = EMUERROR; e->stopreason = EMUERROR;
} }

View File

@ -12,6 +12,7 @@
#include "instruction.h" #include "instruction.h"
#include "debug.h" #include "debug.h"
#include "utils.h" #include "utils.h"
#include "log.h"
ATF_TC_WITHOUT_HEAD(breakpoint); ATF_TC_WITHOUT_HEAD(breakpoint);
ATF_TC_BODY(breakpoint, tc) ATF_TC_BODY(breakpoint, tc)
@ -54,10 +55,13 @@ ATF_TC_BODY(trace, tc)
trace_t *tr; trace_t *tr;
int i; int i;
rk6502_loglevel_set(LOG_TRACE);
b = bus_init_with_default_devs(); b = bus_init_with_default_devs();
a = assemble_init(&b, ROM_LOAD_ADDR); a = assemble_init(&b, ROM_LOAD_ADDR);
e = rk65c02_init(&b); e = rk65c02_init(&b);
e.regs.PC = ROM_LOAD_ADDR; e.regs.PC = ROM_LOAD_ADDR;
debug_trace_set(&e, true); debug_trace_set(&e, true);