From 43e38e567d64d16f88b99fff53bda8f9ccb86ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Mon, 20 Feb 2017 21:29:52 +0100 Subject: [PATCH] Further adjustments to get device subsystem working. --- src/bus.c | 35 ++++++++++++++++++++++++----------- src/bus.h | 6 +++++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/bus.c b/src/bus.c index 39c47f1..e9a2e87 100644 --- a/src/bus.c +++ b/src/bus.c @@ -1,11 +1,10 @@ #include #include #include -//#include +#include #include #include -//#include -//#include +#include #include @@ -25,11 +24,25 @@ bus_device_add(bus_t *b, device_t *d, uint16_t addr) dm = (device_mapping_t *) malloc(sizeof(device_mapping_t)); dm->dev = d; + /* TODO: check if addr + size is not bigger than RK65C02_BUS_SIZE */ dm->addr = addr; LL_APPEND((b->dm_head), dm); } +void +bus_device_dump(bus_t *b) +{ + device_mapping_t *dm; + device_t *d; + + LL_FOREACH(b->dm_head, dm) { + d = dm->dev; + printf("@ %x size %x - %s\n", dm->addr, d->size, d->name); + /* TODO: device specific info */ + } +} + uint8_t bus_read_1(bus_t *t, uint16_t addr) { @@ -49,7 +62,7 @@ bus_read_1(bus_t *t, uint16_t addr) */ } - printf("bus READ @ %x value %x\n", addr, val); +// printf("bus READ @ %x value %x\n", addr, val); return val; } @@ -71,7 +84,7 @@ bus_write_1(bus_t *t, uint16_t addr, uint8_t val) */ } - printf("bus WRITE @ %x value %x\n", addr, val); +// printf("bus WRITE @ %x value %x\n", addr, val); } bus_t @@ -106,13 +119,14 @@ bus_load_buf(bus_t *t, uint16_t addr, uint8_t *buf, uint16_t bufsize) // XXX: add sanity checks while (i < bufsize) { - bus_write_1(t, i, buf[i]); // XXX: overflow addr + bus_write_1(t, addr+i, buf[i]); // XXX: overflow addr i++; } return true; } -/* + +/* TODO: should be moved to ram/rom specific devs */ bool bus_load_file(bus_t *t, uint16_t addr, const char *filename) { @@ -126,20 +140,19 @@ bus_load_file(bus_t *t, uint16_t addr, const char *filename) } while ((read(fd, &data, 1)) > 0) { - t->space[addr++] = data; // XXX: overflow addr + bus_write_1(t, addr++, data); // XXX: overflow addr } close(fd); return true; } -*/ + void bus_finish(bus_t *t) { assert(t != NULL); -// assert(t->space != NULL); -// free(t->space); + /* TODO: foreach devices free 'em */ } diff --git a/src/bus.h b/src/bus.h index 76ac8b8..cdda1b8 100644 --- a/src/bus.h +++ b/src/bus.h @@ -17,9 +17,13 @@ typedef struct bus_tag bus_t; uint8_t bus_read_1(bus_t *, uint16_t); void bus_write_1(bus_t *, uint16_t, uint8_t); bus_t bus_init(); +bus_t bus_init_with_default_devs(); void bus_finish(bus_t *); -//bool bus_load_file(bus_t *, uint16_t, const char *); +bool bus_load_file(bus_t *, uint16_t, const char *); bool bus_load_buf(bus_t *, uint16_t, uint8_t *, uint16_t); +void bus_device_add(bus_t *, device_t *, uint16_t); +void bus_device_dump(bus_t *); + #endif /* _BUS_H_ */