From 85a53f89c810a48ad3accbeacb34564a4ced3cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Sun, 25 Mar 2018 18:01:15 +0200 Subject: [PATCH] Start implementation of display emulation. Something like a character RAM for a start. When 65C02 writes into this space, a callback will be executed that would allow redrawing the emulated screen. Multiple backends can be supported this way. --- src/Makefile | 2 +- src/device_fb.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ src/device_fb.h | 9 +++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/device_fb.c create mode 100644 src/device_fb.h diff --git a/src/Makefile b/src/Makefile index cd01075..622a5ba 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ CLI=rk65c02cli CLI_OBJS=rk65c02cli.o -LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_serial.o log.o +LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_fb.o device_serial.o log.o LIB_SO=librk65c02.so LIB_STATIC=librk65c02.a diff --git a/src/device_fb.c b/src/device_fb.c new file mode 100644 index 0000000..3cbcf24 --- /dev/null +++ b/src/device_fb.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include + +#include "bus.h" +#include "device.h" + +#define FB_AS_SIZE 0x1000 + +#define CHAR_RAM_SIZE (80*50) /* 0xFA0 */ +#define CHAR_FONT_WIDTH 8 +#define CHAR_FONT_HEIGHT 8 + +struct fb_state { + uint8_t *cram; + + void (*fb_callback_screen_update)(uint8_t *); +}; + +uint8_t device_fb_read_1(void *, uint16_t); +void device_fb_write_1(void *, uint16_t, uint8_t); + +uint8_t +device_fb_read_1(void *vd, uint16_t offset) +{ + device_t *d; + struct fb_state *f; + + d = (device_t *) vd; + f = d->aux; + + return f->cram[offset]; +} + +void +device_fb_write_1(void *vd, uint16_t offset, uint8_t val) +{ + device_t *d; + + struct fb_state *f; + + d = (device_t *) vd; + f = d->aux; + + f->cram[offset] = val; + + if (f->fb_callback_screen_update != NULL) + f->fb_callback_screen_update(f->cram); +} + +device_t * +device_fb_init() +{ + device_t *d; + struct fb_state *f; + + d = (device_t *) malloc(sizeof(device_t)); + + assert(d != NULL); + + d->name = "FB"; + d->size = FB_AS_SIZE; + + d->read_1 = device_fb_read_1; + d->write_1 = device_fb_write_1; + + f = malloc(sizeof(struct fb_state)); + d->aux = f; + + f->cram = malloc(FB_AS_SIZE); + memset(d->aux, 0, FB_AS_SIZE); + + return d; +} + +void +device_fb_finish(device_t *d) +{ + struct fb_state *f; + + f = d->aux; + + free(f->cram); + free(f); +} + diff --git a/src/device_fb.h b/src/device_fb.h new file mode 100644 index 0000000..af9443a --- /dev/null +++ b/src/device_fb.h @@ -0,0 +1,9 @@ +#ifndef _DEVICE_RAM_H_ +#define _DEVICE_RAM_H_ + +#include "device.h" + +device_t * device_fb_init(); +void device_fb_finish(device_t *); + +#endif /* _DEVICE_RAM_H_ */