2017-02-20 11:31:26 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-02-19 20:45:15 +00:00
|
|
|
#include "bus.h"
|
|
|
|
#include "device.h"
|
|
|
|
|
2017-02-20 11:31:26 +00:00
|
|
|
#define RAM_SIZE 0xDFFF /* should be configurable */
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
device_ram_read_1(void *vd, uint16_t offset)
|
|
|
|
{
|
|
|
|
device_t *d;
|
|
|
|
uint8_t *ram;
|
|
|
|
|
|
|
|
d = (device_t *) vd;
|
|
|
|
ram = d->aux;
|
|
|
|
|
|
|
|
return ram[offset];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
device_ram_write_1(void *vd, uint16_t offset, uint8_t val)
|
|
|
|
{
|
|
|
|
device_t *d;
|
|
|
|
uint8_t *ram;
|
|
|
|
|
|
|
|
d = (device_t *) vd;
|
|
|
|
ram = d->aux;
|
|
|
|
|
|
|
|
ram[offset] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_t *
|
|
|
|
device_ram_init()
|
2017-02-19 20:45:15 +00:00
|
|
|
{
|
2017-02-20 11:31:26 +00:00
|
|
|
device_t *d;
|
|
|
|
|
|
|
|
d = (device_t *) malloc(sizeof(device_t));
|
|
|
|
|
|
|
|
assert(d != NULL);
|
|
|
|
|
|
|
|
d->name = "RAM";
|
|
|
|
d->size = RAM_SIZE;
|
|
|
|
|
|
|
|
d->read_1 = device_ram_read_1;
|
|
|
|
d->write_1 = device_ram_write_1;
|
|
|
|
|
|
|
|
d->aux = malloc(RAM_SIZE);
|
|
|
|
memset(d->aux, 0, RAM_SIZE);
|
|
|
|
|
|
|
|
return d;
|
2017-02-19 20:45:15 +00:00
|
|
|
}
|
2017-02-20 11:31:26 +00:00
|
|
|
|
|
|
|
/* TODO: device_ram_finish */
|
|
|
|
|