From 7baefe92776ac017248d9ec92944a7884be5de8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Sun, 19 Feb 2017 21:45:15 +0100 Subject: [PATCH] Attempt to design a semi-flexible device subsystem. --- src/Makefile | 3 ++- src/bus.c | 34 +++++++++++++++------------------- src/bus.h | 4 +++- src/device.h | 27 +++++++++++++++++++++++++++ src/device_ram.c | 8 ++++++++ 5 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 src/device.h create mode 100644 src/device_ram.c diff --git a/src/Makefile b/src/Makefile index 1983576..8b71d37 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,6 +11,7 @@ CFLAGS=-Wall -fpic -ggdb 65C02ISA=65c02isa EMULATION=emulation +DEVICE=device # TODO: better include handling all : $(LIB_SO) $(LIB_STATIC) $(CLI) @@ -31,7 +32,7 @@ $(EMULATION).h : $(65C02ISA).csv $(EMULATION).awk awk -f $(EMULATION).awk $(65C02ISA).csv > $(EMULATION).h # XXX: dependency on 65c02isa.h is only for instruction.c ? -%.o : %.c %.h $(65C02ISA).h $(EMULATION).h +%.o : %.c %.h $(65C02ISA).h $(EMULATION).h $(DEVICE).h $(CC) $(CFLAGS) -c $< clean : diff --git a/src/bus.c b/src/bus.c index 4608350..d7c8960 100644 --- a/src/bus.c +++ b/src/bus.c @@ -1,27 +1,23 @@ #include #include #include -#include +//#include #include #include -#include -#include +//#include +//#include #include +#include "bus.h" + #define RK65C02_BUS_SIZE 64*1024 -struct bus_tag { - uint8_t *space; -}; - -typedef struct bus_tag bus_t; - uint8_t bus_read_1(bus_t *t, uint16_t addr) { uint8_t val; - val = t->space[addr]; +// val = t->space[addr]; /* printf("bus READ @ %x value %x\n", addr, val); */ return val; } @@ -30,7 +26,7 @@ void bus_write_1(bus_t *t, uint16_t addr, uint8_t val) { /* printf("bus WRITE @ %x value %x\n", addr, val); */ - t->space[addr] = val; +// t->space[addr] = val; } bus_t @@ -38,15 +34,15 @@ bus_init() { bus_t t; - t.space = (uint8_t *) malloc(RK65C02_BUS_SIZE); +// t.space = (uint8_t *) malloc(RK65C02_BUS_SIZE); - assert(t.space != NULL); +// assert(t.space != NULL); - memset(t.space, 0, RK65C02_BUS_SIZE); +// memset(t.space, 0, RK65C02_BUS_SIZE); return t; } - +/* bool bus_load_buf(bus_t *t, uint16_t addr, uint8_t *buf, uint16_t bufsize) { @@ -54,7 +50,7 @@ bus_load_buf(bus_t *t, uint16_t addr, uint8_t *buf, uint16_t bufsize) i = 0; - /* XXX: add sanity checks */ + // XXX: add sanity checks while (i < bufsize) { t->space[addr+i] = buf[i]; // XXX: overflow addr @@ -84,13 +80,13 @@ bus_load_file(bus_t *t, uint16_t addr, const char *filename) return true; } - +*/ void bus_finish(bus_t *t) { assert(t != NULL); - assert(t->space != NULL); +// assert(t->space != NULL); - free(t->space); +// free(t->space); } diff --git a/src/bus.h b/src/bus.h index 6e4d31c..605cec9 100644 --- a/src/bus.h +++ b/src/bus.h @@ -4,10 +4,12 @@ #include #include +#include "device.h" + #define RK65C02_BUS_SIZE 64*1024 struct bus_tag { - uint8_t *space; + device_t *device_head; }; typedef struct bus_tag bus_t; diff --git a/src/device.h b/src/device.h new file mode 100644 index 0000000..aa224f6 --- /dev/null +++ b/src/device.h @@ -0,0 +1,27 @@ +#ifndef _DEVICE_H_ +#define _DEVICE_H_ + +//#include "bus.h" + +typedef struct device_space_t { + //uint8_t id; + uint16_t address; + uint16_t size; + + uint8_t (*read_1)(uint16_t addr); + void (*write_1)(uint16_t addr, uint8_t val); + + void *aux; /* any additional space-specific data */ + + struct device_space_t *next; +} device_space_t; + +typedef struct device_t { + const char *name; + device_space_t *space_head; + + struct device_t *next; +} device_t; + +#endif /* _DEVICE_H_ */ + diff --git a/src/device_ram.c b/src/device_ram.c new file mode 100644 index 0000000..a7757b7 --- /dev/null +++ b/src/device_ram.c @@ -0,0 +1,8 @@ +#include "bus.h" +#include "device.h" + +bool +device_ram_add(bus_t *t) +{ + +}