From dcf275939b95638dc90d45afa79d49d357bfafe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Wed, 22 Feb 2017 22:43:58 +0100 Subject: [PATCH] Make bus read/writes possible to devices mapped anywhere, not only 0. --- src/bus.c | 58 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/bus.c b/src/bus.c index e9a2e87..01f7e7d 100644 --- a/src/bus.c +++ b/src/bus.c @@ -47,44 +47,54 @@ uint8_t bus_read_1(bus_t *t, uint16_t addr) { uint8_t val; + uint16_t doff; device_mapping_t *dm; - device_t *d; + device_t *dtmp, *d; + + d = NULL; LL_FOREACH(t->dm_head, dm) { - d = dm->dev; - - if (dm->addr == 0) - val = d->read_1(d, addr); - /* - * else - * Check if address is inside of given device range, calculate - * offset. - */ - + dtmp = dm->dev; + if ( (addr >= dm->addr) && (addr < (dm->addr + dtmp->size)) ) { + d = dtmp; + doff = dm->addr; + } } -// printf("bus READ @ %x value %x\n", addr, val); + + if (d == NULL) { + fprintf(stderr, "Hitting unmapped bus space @ %x!", addr); + return 0xFF; + } + + val = d->read_1(d, addr - doff); + + printf("bus READ @ %x (off %x) value %x\n", addr, addr - doff, val); return val; } void bus_write_1(bus_t *t, uint16_t addr, uint8_t val) { + uint16_t doff; device_mapping_t *dm; - device_t *d; + device_t *dtmp, *d; + + d = NULL; LL_FOREACH(t->dm_head, dm) { - d = dm->dev; - - if (dm->addr == 0) - d->write_1(d, addr, val); - /* - * else - * Check if address is inside of given device range, calculate - * offset. - */ - + dtmp = dm->dev; + if ( (addr >= dm->addr) && (addr < (dm->addr + dtmp->size)) ) { + d = dtmp; + doff = dm->addr; + } } -// printf("bus WRITE @ %x value %x\n", addr, val); + + if (d == NULL) { + fprintf(stderr, "Hitting unmapped bus space @ %x!", addr); + } + + printf("bus WRITE @ %x (off %x) value %x\n", addr, addr - doff, val); + d->write_1(d, addr, val); } bus_t