1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-11 18:49:16 +00:00

Make bus read/writes possible to devices mapped anywhere, not only 0.

This commit is contained in:
Radosław Kujawa 2017-02-22 22:43:58 +01:00
parent 7ab946c5df
commit dcf275939b

View File

@ -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