From 8e89ed067a7e7672ec361af03d312014957ec655 Mon Sep 17 00:00:00 2001 From: Radoslaw Kujawa Date: Mon, 25 Jan 2021 00:38:58 +0100 Subject: [PATCH] CPU emulator should not try to emulate peripherals. Especially in a lame/incomplete way. These should be later re-added in examples. --- src/Makefile | 2 +- src/device_fb.c | 103 ------------------------------- src/device_fb.h | 9 --- src/device_serial.c | 143 -------------------------------------------- src/device_serial.h | 10 ---- 5 files changed, 1 insertion(+), 266 deletions(-) delete mode 100644 src/device_fb.c delete mode 100644 src/device_fb.h delete mode 100644 src/device_serial.c delete mode 100644 src/device_serial.h diff --git a/src/Makefile b/src/Makefile index d6af0b7..e57bd55 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ # UNAME_S := $(shell uname -s) -LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_fb.o device_serial.o log.o assembler.o +LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o log.o assembler.o ifeq ($(UNAME_S),Darwin) LIB_SO=librk65c02.dylib diff --git a/src/device_fb.c b/src/device_fb.c deleted file mode 100644 index fe6a2d3..0000000 --- a/src/device_fb.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-3.0-only - * - * rk65c02 - * Copyright (C) 2017-2019 Radoslaw Kujawa - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#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 *) GC_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 = GC_MALLOC(sizeof(struct fb_state)); - assert(f != NULL); - d->aux = f; - - f->cram = GC_MALLOC(FB_AS_SIZE); - assert(f->cram != NULL); - memset(d->aux, 0, FB_AS_SIZE); - - return d; -} - -void -device_fb_finish(device_t *d) -{ -} - diff --git a/src/device_fb.h b/src/device_fb.h deleted file mode 100644 index af9443a..0000000 --- a/src/device_fb.h +++ /dev/null @@ -1,9 +0,0 @@ -#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_ */ diff --git a/src/device_serial.c b/src/device_serial.c deleted file mode 100644 index 74f0753..0000000 --- a/src/device_serial.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-3.0-only - * - * rk65c02 - * Copyright (C) 2017-2019 Radoslaw Kujawa - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include "bus.h" -#include "device.h" - -const static char *txpipepath = "/tmp/rk65c02_serial_tx"; /* should really be configurable */ -const static char *rxpipepath = "/tmp/rk65c02_serial_rx"; /* should really be configurable */ - -struct device_serial_priv { - int txpipefd; - int rxpipefd; -}; - -uint8_t device_serial_read_1(void *, uint16_t); -void device_serial_write_1(void *, uint16_t, uint8_t); -void device_serial_finish(void *); - -uint8_t -device_serial_read_1(void *vd, uint16_t offset) -{ - device_t *d; - struct device_serial_priv *dp; - ssize_t nread; - uint8_t val; - - d = (device_t *) vd; - dp = d->aux; - - switch (offset) { - case 0x1: - nread = read(dp->rxpipefd, &val, 1);; - if (nread == 0) - val = 0xFE; - if (nread == -1) - val = 0xFD; - default: - break; - } - // XXX: TODO - - return 0xFF; -} - -void -device_serial_write_1(void *vd, uint16_t offset, uint8_t val) -{ - device_t *d; - struct device_serial_priv *dp; - - d = (device_t *) vd; - dp = d->aux; - - switch (offset) { - case 0x0: - /*fprintf(stderr, "writing to fd %d val %x\n", dp->txpipefd, val);*/ - write(dp->txpipefd, &val, 1); - fsync(dp->txpipefd); - break; - default: - /* do nothing */ - break; - } -} - -device_t * -device_serial_init() -{ - device_t *d; - struct device_serial_priv *dp; - - d = (device_t *) GC_MALLOC(sizeof(device_t)); - - assert(d != NULL); - - d->name = "Serial"; - d->size = 4; - - d->read_1 = device_serial_read_1; - d->write_1 = device_serial_write_1; - d->finish = device_serial_finish; - - dp = (struct device_serial_priv *) GC_MALLOC(sizeof(struct device_serial_priv)); - assert(dp != NULL); - d->aux = dp; - - if (mkfifo(txpipepath, S_IRUSR | S_IWUSR) != 0) { - fprintf(stderr, "Creating FIFO for serial port failed!\n"); - /* perror, handle this failure... */ - } - if (mkfifo(rxpipepath, S_IRUSR | S_IWUSR) != 0) { - fprintf(stderr, "Creating FIFO for serial port failed!\n"); - /* perror, handle this failure... */ - } - - dp->txpipefd = open(txpipepath, O_WRONLY); - dp->rxpipefd = open(rxpipepath, O_RDONLY | O_NONBLOCK); - - return d; -} - -void -device_serial_finish(void *dv) -{ - struct device_serial_priv *dp; - struct device_t *d; - - d = (struct device_t *) dv; - dp = d->aux; - - close(dp->txpipefd); - close(dp->rxpipefd); - - unlink(txpipepath); - unlink(rxpipepath); -} - diff --git a/src/device_serial.h b/src/device_serial.h deleted file mode 100644 index 8336cc3..0000000 --- a/src/device_serial.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _DEVICE_SERIAL_H_ -#define _DEVICE_SERIAL_H_ - -#include "device.h" - -device_t * device_serial_init(); -void device_serial_finish(device_t *); - -#endif /* _DEVICE_SERIAL_H_ */ -