mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-12-11 18:49:16 +00:00
Attempt to design a semi-flexible device subsystem.
This commit is contained in:
parent
0df6387a41
commit
7baefe9277
@ -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 :
|
||||
|
34
src/bus.c
34
src/bus.c
@ -1,27 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
//#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
//#include <string.h>
|
||||
//#include <fcntl.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,12 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#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;
|
||||
|
27
src/device.h
Normal file
27
src/device.h
Normal file
@ -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_ */
|
||||
|
8
src/device_ram.c
Normal file
8
src/device_ram.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "bus.h"
|
||||
#include "device.h"
|
||||
|
||||
bool
|
||||
device_ram_add(bus_t *t)
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user