mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-12-04 04:51:27 +00:00
Further improvements and refactoring to logging.
This commit is contained in:
parent
47aca32da7
commit
5cb6f3488e
14
src/bus.c
14
src/bus.c
@ -2,15 +2,18 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <utlist.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "log.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) {
|
||||
fprintf(stderr, "Hitting unmapped bus space @ %x!", addr);
|
||||
rk6502_log(LOG_WARN, "Hitting unmapped bus space @ %x!", addr);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -90,7 +93,8 @@ bus_read_1(bus_t *t, uint16_t addr)
|
||||
val = d->read_1(d, off);
|
||||
|
||||
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;
|
||||
}
|
||||
@ -104,7 +108,8 @@ bus_write_1(bus_t *t, uint16_t addr, uint8_t val)
|
||||
bus_access_device(t, addr, &d, &off);
|
||||
|
||||
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);
|
||||
}
|
||||
@ -158,7 +163,8 @@ bus_load_file(bus_t *t, uint16_t addr, const char *filename)
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "rk65c02.h"
|
||||
#include "instruction.h"
|
||||
#include "log.h"
|
||||
#include "debug.h"
|
||||
|
||||
void
|
||||
@ -26,7 +27,7 @@ debug_trace_print_all(rk65c02emu_t *e)
|
||||
i.op1 = tr->op1;
|
||||
i.op2 = tr->op2;
|
||||
|
||||
printf("TRACE %X:\t", tr->address);
|
||||
rk6502_log(LOG_TRACE, " %X:\t", tr->address);
|
||||
instruction_print(&i);
|
||||
printf("\t");
|
||||
rk65c02_dump_regs(tr->regs);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "65c02isa.h"
|
||||
#include "log.h"
|
||||
#include "instruction.h"
|
||||
|
||||
instruction_t
|
||||
@ -172,14 +173,16 @@ assemble_single_buf(uint8_t **buf, uint8_t *bsize, const char *mnemonic, address
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
*bsize = id.size;
|
||||
*buf = malloc(id.size);
|
||||
if(*buf == NULL) {
|
||||
fprintf(stderr, "Error allocating assembly buffer\n");
|
||||
rk6502_log(LOG_ERROR, "Error allocating assembly buffer.");
|
||||
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.
|
||||
*/
|
||||
default:
|
||||
printf("unhandled addressing mode for opcode %x\n",
|
||||
i->opcode);
|
||||
rk6502_log(LOG_ERROR,
|
||||
"unhandled addressing mode for opcode %x\n", i->opcode);
|
||||
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.
|
||||
*/
|
||||
default:
|
||||
printf("unhandled addressing mode for opcode %x\n",
|
||||
i->opcode);
|
||||
rk6502_log(LOG_ERROR,
|
||||
"unhandled addressing mode for opcode %x\n", i->opcode);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
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, ...)
|
||||
{
|
||||
va_list args;
|
||||
struct timeval t;
|
||||
|
||||
gettimeofday(&t, NULL);
|
||||
|
||||
if (l > level)
|
||||
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);
|
||||
vfprintf(stderr, fmt, args);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#define LOG_TRACE 5
|
||||
#define LOG_DEBUG 4
|
||||
#define LOG_INFO 3
|
||||
#define LOG_WARN 4
|
||||
#define LOG_ERROR 2
|
||||
#define LOG_CRIT 1
|
||||
#define LOG_NOTHING 0 /* At 0 nothing will get logged, can be set as
|
||||
|
@ -119,8 +119,8 @@ rk65c02_exec(rk65c02emu_t *e)
|
||||
if (!instruction_modify_pc(&id))
|
||||
program_counter_increment(e, &id);
|
||||
} else {
|
||||
printf("unimplemented opcode %X @ %X\n", i.opcode,
|
||||
e->regs.PC);
|
||||
rk6502_log(LOG_ERROR, "unimplemented opcode %X @ %X\n",
|
||||
i.opcode, e->regs.PC);
|
||||
e->state = STOPPED;
|
||||
e->stopreason = EMUERROR;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "instruction.h"
|
||||
#include "debug.h"
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(breakpoint);
|
||||
ATF_TC_BODY(breakpoint, tc)
|
||||
@ -54,10 +55,13 @@ ATF_TC_BODY(trace, tc)
|
||||
trace_t *tr;
|
||||
int i;
|
||||
|
||||
rk6502_loglevel_set(LOG_TRACE);
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
a = assemble_init(&b, ROM_LOAD_ADDR);
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
|
||||
e.regs.PC = ROM_LOAD_ADDR;
|
||||
debug_trace_set(&e, true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user