From 490eceab6dd2fa2ca1766850de520727a51c6175 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 25 Oct 2020 15:58:00 -0400 Subject: [PATCH] emul/z80: flatten directory structure I'm about to reuse sdc.c in sms.c and the old directory structure was becoming awkward. --- emul/z80/.gitignore | 3 ++ emul/z80/Makefile | 16 +++++++- emul/z80/README.md | 69 ++++++++++++++++++++++++++++++--- emul/z80/{rc2014 => }/acia.c | 0 emul/z80/{rc2014 => }/acia.h | 0 emul/z80/{sms/kbd.c => ps2_kbd.c} | 2 +- emul/z80/{sms/kbd.h => ps2_kbd.h} | 2 +- emul/z80/{rc2014/classic.c => rc2014.c} | 2 +- emul/z80/rc2014/.gitignore | 1 - emul/z80/rc2014/Makefile | 16 -------- emul/z80/rc2014/README.md | 18 --------- emul/z80/{rc2014 => }/sdc.c | 0 emul/z80/{rc2014 => }/sdc.h | 0 emul/z80/{rc2014 => }/sio.c | 0 emul/z80/{rc2014 => }/sio.h | 0 emul/z80/{sms => }/sms.c | 10 ++--- emul/z80/sms/.gitignore | 1 - emul/z80/sms/Makefile | 19 --------- emul/z80/sms/README.md | 33 ---------------- emul/z80/{sms/pad.c => sms_pad.c} | 2 +- emul/z80/{sms/pad.h => sms_pad.h} | 2 +- emul/z80/{sms/port.c => sms_ports.c} | 2 +- emul/z80/{sms/port.h => sms_ports.h} | 2 +- emul/z80/{sms/vdp.c => sms_vdp.c} | 2 +- emul/z80/{sms/vdp.h => sms_vdp.h} | 0 emul/z80/{ti => }/t6a04.c | 0 emul/z80/{ti => }/t6a04.h | 0 emul/z80/ti/.gitignore | 1 - emul/z80/ti/Makefile | 19 --------- emul/z80/ti/README.md | 26 ------------- emul/z80/{ti => }/ti84.c | 4 +- emul/z80/{ti/kbd.c => ti84_kbd.c} | 2 +- emul/z80/{ti/kbd.h => ti84_kbd.h} | 0 recipes/rc2014/Makefile | 4 +- recipes/sms/Makefile | 2 +- recipes/ti84/Makefile | 4 +- 36 files changed, 101 insertions(+), 163 deletions(-) rename emul/z80/{rc2014 => }/acia.c (100%) rename emul/z80/{rc2014 => }/acia.h (100%) rename emul/z80/{sms/kbd.c => ps2_kbd.c} (99%) rename emul/z80/{sms/kbd.h => ps2_kbd.h} (95%) rename emul/z80/{rc2014/classic.c => rc2014.c} (99%) delete mode 100644 emul/z80/rc2014/.gitignore delete mode 100644 emul/z80/rc2014/Makefile delete mode 100644 emul/z80/rc2014/README.md rename emul/z80/{rc2014 => }/sdc.c (100%) rename emul/z80/{rc2014 => }/sdc.h (100%) rename emul/z80/{rc2014 => }/sio.c (100%) rename emul/z80/{rc2014 => }/sio.h (100%) rename emul/z80/{sms => }/sms.c (98%) delete mode 100644 emul/z80/sms/.gitignore delete mode 100644 emul/z80/sms/Makefile delete mode 100644 emul/z80/sms/README.md rename emul/z80/{sms/pad.c => sms_pad.c} (96%) rename emul/z80/{sms/pad.h => sms_pad.h} (95%) rename emul/z80/{sms/port.c => sms_ports.c} (98%) rename emul/z80/{sms/port.h => sms_ports.h} (95%) rename emul/z80/{sms/vdp.c => sms_vdp.c} (99%) rename emul/z80/{sms/vdp.h => sms_vdp.h} (100%) rename emul/z80/{ti => }/t6a04.c (100%) rename emul/z80/{ti => }/t6a04.h (100%) delete mode 100644 emul/z80/ti/.gitignore delete mode 100644 emul/z80/ti/Makefile delete mode 100644 emul/z80/ti/README.md rename emul/z80/{ti => }/ti84.c (99%) rename emul/z80/{ti/kbd.c => ti84_kbd.c} (99%) rename emul/z80/{ti/kbd.h => ti84_kbd.h} (100%) diff --git a/emul/z80/.gitignore b/emul/z80/.gitignore index 00dbdb8..8e5c29f 100644 --- a/emul/z80/.gitignore +++ b/emul/z80/.gitignore @@ -1,2 +1,5 @@ /forth /forth.bin +/ti84 +/sms +/rc2014 diff --git a/emul/z80/Makefile b/emul/z80/Makefile index 2b71e62..7f1951f 100644 --- a/emul/z80/Makefile +++ b/emul/z80/Makefile @@ -1,5 +1,8 @@ -TARGETS = forth +TARGETS = forth rc2014 sms ti84 OBJS = emul.o z80.o +RC2014_OBJS = $(OBJS) sio.o acia.o sdc.o +SMS_OBJS = $(OBJS) sms_vdp.o sms_ports.o sms_pad.o ps2_kbd.o +TI84_OBJS = $(OBJS) t6a04.o ti84_kbd.o CDIR = ../../cvm STAGE = $(CDIR)/stage BLKFS = $(CDIR)/blkfs @@ -10,6 +13,15 @@ all: $(TARGETS) forth: forth.c $(OBJS) $(BLKFS) $(CC) forth.c $(OBJS) -lncurses -o $@ +rc2014: rc2014.c $(RC2014_OBJS) + $(CC) rc2014.c $(RC2014_OBJS) -o $@ + +sms: sms.c $(SMS_OBJS) + $(CC) sms.c $(SMS_OBJS) -o $@ `pkg-config --cflags --libs xcb` + +ti84: ti84.c $(TI84_OBJS) + $(CC) ti84.c $(TI84_OBJS) -o $@ `pkg-config --cflags --libs xcb` + emul.o: emul.c forth.bin $(BLKFS) $(CC) -DFBIN_PATH=\"`pwd`/forth.bin\" -DBLKFS_PATH=\"`pwd`/$(BLKFS)\" -c -o emul.o emul.c @@ -23,4 +35,4 @@ $(STAGE): .PHONY: clean clean: - rm -f $(TARGETS) emul.o *.bin z80.o + rm -f $(TARGETS) *.o *.bin diff --git a/emul/z80/README.md b/emul/z80/README.md index f76c155..94596c8 100644 --- a/emul/z80/README.md +++ b/emul/z80/README.md @@ -1,4 +1,4 @@ -# emul +# Z80 emulation This folder contains a couple of tools running under the [libz80][libz80] emulator. @@ -8,23 +8,80 @@ emulator. You need `ncurses` to build the `forth` executable. In debian-based distros, it's `libncurses5-dev`. +For `sms` and `ti84` emulators, you need XCB and pkg-config. + ## Build -Run `make` and it builds the `forth` interpreter. +Running `make` builds all targets described below -## Usage +## Vanilla Forth The `./forth` executable here works like the one in `/cvm`, except that it runs under an emulated z80 machine instead of running natively. Refer to `/cvm/README.md` for details. -## Not real hardware - `./forth` doesn't try to emulate real hardware because the goal here is to facilitate "high level" development. These apps run on imaginary hardware and use many cheats to simplify I/Os. -For real hardware emulation (which helps developing drivers), see subfolders. +## RC2014 emulation + +This emulates a RC2014 classic with 8K of ROM, 32K of RAM and an ACIA hooked to +stdin/stdout. + +Run `./rc2014 /path/to/rom` (for example, `os.bin` from RC2014's recipe). +Serial I/O is hooked to stdin/stdout. `CTRL+D` to quit. + +There are 2 options. `-s` replaces the ACIA with a Zilog SIO and +`-c/path/to/image` hooks up a SD card with specified contents. + +You can press `CTRL+E` to dump the whole 64K of memory into `memdump`. + +## Sega Master System emulator + +This emulates a Sega Master system with a monochrome screen and a Genesis pad +hooked to port A. + +Launch the emulator with `./sms /path/to/rom` (you can use the binary from the +`sms` recipe. + +This will show a window with the screen's content on it. The mappings to the +pad are: + +* W --> Up +* A --> Left +* S --> Down +* D --> Right +* H --> A +* J --> B +* K --> C +* L --> Start + +If your ROM is configured with PS/2 keyboard input, run this emulator with the +`-k` flag to replace SMS pad emulation with keyboard emulation. + +In both cases (pad or keyboard), only port A emulation is supported. + +Press ESC to quit. + +## TI-84 + +This emulates a TI-84+ with its screen and keyboard. This is suitable for +running the `ti84` recipe. + +Launch the emulator with `./ti84 /path/to/rom` (you can use the binary from the +`ti84` recipe. Use the small one, not the one having been filled to 1MB). + +This will show a window with the LCD screen's content on it. Most applications, +upon boot, halt after initialization and stay halted until the ON key is +pressed. The ON key is mapped to the tilde (~) key. + +Press ESC to quit. + +As for the rest of the mappings, they map at the key level. For example, the 'Y' +key maps to '1' (which yields 'y' when in alpha mode). Therefore, '1' and 'Y' +map to the same calculator key. Backspace maps to DEL. +Left Shift maps to 2nd. Left Ctrl maps to Alpha. [libz80]: https://github.com/ggambetta/libz80 diff --git a/emul/z80/rc2014/acia.c b/emul/z80/acia.c similarity index 100% rename from emul/z80/rc2014/acia.c rename to emul/z80/acia.c diff --git a/emul/z80/rc2014/acia.h b/emul/z80/acia.h similarity index 100% rename from emul/z80/rc2014/acia.h rename to emul/z80/acia.h diff --git a/emul/z80/sms/kbd.c b/emul/z80/ps2_kbd.c similarity index 99% rename from emul/z80/sms/kbd.c rename to emul/z80/ps2_kbd.c index c445a3b..af9a174 100644 --- a/emul/z80/sms/kbd.c +++ b/emul/z80/ps2_kbd.c @@ -1,4 +1,4 @@ -#include "kbd.h" +#include "ps2_kbd.h" void kbd_init(Kbd *kbd, Tristate *TH) { diff --git a/emul/z80/sms/kbd.h b/emul/z80/ps2_kbd.h similarity index 95% rename from emul/z80/sms/kbd.h rename to emul/z80/ps2_kbd.h index 2188111..cd888dd 100644 --- a/emul/z80/sms/kbd.h +++ b/emul/z80/ps2_kbd.h @@ -1,6 +1,6 @@ #include #include -#include "port.h" +#include "emul.h" #define KBD_BUFSZ 0x10 diff --git a/emul/z80/rc2014/classic.c b/emul/z80/rc2014.c similarity index 99% rename from emul/z80/rc2014/classic.c rename to emul/z80/rc2014.c index 783fae8..12703ae 100644 --- a/emul/z80/rc2014/classic.c +++ b/emul/z80/rc2014.c @@ -11,7 +11,7 @@ #include #include #include -#include "../emul.h" +#include "emul.h" #include "acia.h" #include "sio.h" #include "sdc.h" diff --git a/emul/z80/rc2014/.gitignore b/emul/z80/rc2014/.gitignore deleted file mode 100644 index 44e73b6..0000000 --- a/emul/z80/rc2014/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/classic diff --git a/emul/z80/rc2014/Makefile b/emul/z80/rc2014/Makefile deleted file mode 100644 index 7715de6..0000000 --- a/emul/z80/rc2014/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -EXTOBJS = ../emul.o ../z80.o -OBJS = sio.o acia.o sdc.o classic.o -TARGET = classic - -.PHONY: all -all: $(TARGET) - -../emul.o: - make -C .. - -$(TARGET): $(OBJS) $(EXTOBJS) - $(CC) $(OBJS) $(EXTOBJS) -o $@ - -.PHONY: clean -clean: - rm -f $(TARGET) $(OBJS) diff --git a/emul/z80/rc2014/README.md b/emul/z80/rc2014/README.md deleted file mode 100644 index ce31704..0000000 --- a/emul/z80/rc2014/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# RC2014 emulation - -This emulates a RC2014 classic with 8K of ROM, 32K of RAM and an ACIA hooked to -stdin/stdout. - -Run `make` to build. - -## Usage - -Run `./classic /path/to/rom` (for example, `os.bin` from RC2014's recipe). -Serial I/O is hooked to stdin/stdout. `CTRL+D` to quit. - -There are 2 options. `-s` replaces the ACIA with a Zilog SIO and -`-c/path/to/image` hooks up a SD card with specified contents. - -## Memory dump - -You can press `CTRL+E` to dump the whole 64K of memory into `memdump`. diff --git a/emul/z80/rc2014/sdc.c b/emul/z80/sdc.c similarity index 100% rename from emul/z80/rc2014/sdc.c rename to emul/z80/sdc.c diff --git a/emul/z80/rc2014/sdc.h b/emul/z80/sdc.h similarity index 100% rename from emul/z80/rc2014/sdc.h rename to emul/z80/sdc.h diff --git a/emul/z80/rc2014/sio.c b/emul/z80/sio.c similarity index 100% rename from emul/z80/rc2014/sio.c rename to emul/z80/sio.c diff --git a/emul/z80/rc2014/sio.h b/emul/z80/sio.h similarity index 100% rename from emul/z80/rc2014/sio.h rename to emul/z80/sio.h diff --git a/emul/z80/sms/sms.c b/emul/z80/sms.c similarity index 98% rename from emul/z80/sms/sms.c rename to emul/z80/sms.c index 4025973..2c76791 100644 --- a/emul/z80/sms/sms.c +++ b/emul/z80/sms.c @@ -7,11 +7,11 @@ #define XK_MISCELLANY #include -#include "../emul.h" -#include "vdp.h" -#include "port.h" -#include "pad.h" -#include "kbd.h" +#include "emul.h" +#include "sms_vdp.h" +#include "sms_ports.h" +#include "sms_pad.h" +#include "ps2_kbd.h" #define RAMSTART 0xc000 #define VDP_CMD_PORT 0xbf diff --git a/emul/z80/sms/.gitignore b/emul/z80/sms/.gitignore deleted file mode 100644 index 2ad1042..0000000 --- a/emul/z80/sms/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sms diff --git a/emul/z80/sms/Makefile b/emul/z80/sms/Makefile deleted file mode 100644 index d4366ef..0000000 --- a/emul/z80/sms/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -EXTOBJS = ../emul.o ../z80.o -OBJS = sms.o vdp.o port.o pad.o kbd.o -TARGET = sms -CFLAGS += `pkg-config --cflags xcb` -LDFLAGS += `pkg-config --libs xcb` - -.PHONY: all -all: $(TARGET) - -../emul.o: - make -C .. - -$(TARGET): $(OBJS) $(EXTOBJS) - $(CC) $(OBJS) $(EXTOBJS) -o $@ $(LDFLAGS) - -.PHONY: clean -clean: - rm -f $(TARGET) $(OBJS) - diff --git a/emul/z80/sms/README.md b/emul/z80/sms/README.md deleted file mode 100644 index fb62eb8..0000000 --- a/emul/z80/sms/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Sega Master System emulator - -This emulates a Sega Master system with a monochrome screen and a Genesis pad -hooked to port A. - -## Build - -You need `xcb` and `pkg-config` to build this. If you have them, run `make`. -You'll get a `sms` executable. - -## Usage - -Launch the emulator with `./sms /path/to/rom` (you can use the binary from the -`sms` recipe. - -This will show a window with the screen's content on it. The mappings to the -pad are: - -* W --> Up -* A --> Left -* S --> Down -* D --> Right -* H --> A -* J --> B -* K --> C -* L --> Start - -If your ROM is configured with PS/2 keyboard input, run this emulator with the -`-k` flag to replace SMS pad emulation with keyboard emulation. - -In both cases (pad or keyboard), only port A emulation is supported. - -Press ESC to quit. diff --git a/emul/z80/sms/pad.c b/emul/z80/sms_pad.c similarity index 96% rename from emul/z80/sms/pad.c rename to emul/z80/sms_pad.c index e835b88..aeb0db2 100644 --- a/emul/z80/sms/pad.c +++ b/emul/z80/sms_pad.c @@ -1,4 +1,4 @@ -#include "pad.h" +#include "sms_pad.h" void pad_init(Pad *pad, Tristate *TH) { diff --git a/emul/z80/sms/pad.h b/emul/z80/sms_pad.h similarity index 95% rename from emul/z80/sms/pad.h rename to emul/z80/sms_pad.h index cfcd9ad..b7fb8e2 100644 --- a/emul/z80/sms/pad.h +++ b/emul/z80/sms_pad.h @@ -1,6 +1,6 @@ #include #include -#include "port.h" +#include "emul.h" typedef enum { PAD_BTN_UP = 0, diff --git a/emul/z80/sms/port.c b/emul/z80/sms_ports.c similarity index 98% rename from emul/z80/sms/port.c rename to emul/z80/sms_ports.c index 67fa96e..e0936ff 100644 --- a/emul/z80/sms/port.c +++ b/emul/z80/sms_ports.c @@ -1,4 +1,4 @@ -#include "port.h" +#include "sms_ports.h" void ports_init(Ports *ports) { diff --git a/emul/z80/sms/port.h b/emul/z80/sms_ports.h similarity index 95% rename from emul/z80/sms/port.h rename to emul/z80/sms_ports.h index f2111c7..6c62737 100644 --- a/emul/z80/sms/port.h +++ b/emul/z80/sms_ports.h @@ -1,5 +1,5 @@ #pragma once -#include "../emul.h" +#include "emul.h" // Each port is a bitmask of each pin's status. 1 means high. // From Bit 0 to 6: up, down, left, right, TL, TR, TH diff --git a/emul/z80/sms/vdp.c b/emul/z80/sms_vdp.c similarity index 99% rename from emul/z80/sms/vdp.c rename to emul/z80/sms_vdp.c index ef71bae..27ac7e1 100644 --- a/emul/z80/sms/vdp.c +++ b/emul/z80/sms_vdp.c @@ -1,5 +1,5 @@ #include -#include "vdp.h" +#include "sms_vdp.h" void vdp_init(VDP *vdp) { diff --git a/emul/z80/sms/vdp.h b/emul/z80/sms_vdp.h similarity index 100% rename from emul/z80/sms/vdp.h rename to emul/z80/sms_vdp.h diff --git a/emul/z80/ti/t6a04.c b/emul/z80/t6a04.c similarity index 100% rename from emul/z80/ti/t6a04.c rename to emul/z80/t6a04.c diff --git a/emul/z80/ti/t6a04.h b/emul/z80/t6a04.h similarity index 100% rename from emul/z80/ti/t6a04.h rename to emul/z80/t6a04.h diff --git a/emul/z80/ti/.gitignore b/emul/z80/ti/.gitignore deleted file mode 100644 index 42e210f..0000000 --- a/emul/z80/ti/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/ti84 diff --git a/emul/z80/ti/Makefile b/emul/z80/ti/Makefile deleted file mode 100644 index 1a9752a..0000000 --- a/emul/z80/ti/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -EXTOBJS = ../emul.o ../z80.o -OBJS = ti84.o t6a04.o kbd.o -TARGET = ti84 -CFLAGS += `pkg-config --cflags xcb` -LDFLAGS += `pkg-config --libs xcb` - -.PHONY: all -all: $(TARGET) - -../emul.o: - make -C .. - -$(TARGET): $(OBJS) $(EXTOBJS) - $(CC) $(OBJS) $(EXTOBJS) -o $@ $(LDFLAGS) - -.PHONY: clean -clean: - rm -f $(TARGET) $(OBJS) - diff --git a/emul/z80/ti/README.md b/emul/z80/ti/README.md deleted file mode 100644 index 930d655..0000000 --- a/emul/z80/ti/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# TI-84+ emulator - -This emulates a TI-84+ with its screen and keyboard. This is suitable for -running the `ti84` recipe. - -## Build - -You need `xcb` and `pkg-config` to build this. If you have them, run `make`. -You'll get a `ti84` executable. - -## Usage - -Launch the emulator with `./ti84 /path/to/rom` (you can use the binary from the -`ti84` recipe. Use the small one, not the one having been filled to 1MB). - -This will show a window with the LCD screen's content on it. Most applications, -upon boot, halt after initialization and stay halted until the ON key is -pressed. The ON key is mapped to the tilde (~) key. - -Press ESC to quit. - -As for the rest of the mappings, they map at the key level. For example, the 'Y' -key maps to '1' (which yields 'y' when in alpha mode). Therefore, '1' and 'Y' -map to the same calculator key. Backspace maps to DEL. - -Left Shift maps to 2nd. Left Ctrl maps to Alpha. diff --git a/emul/z80/ti/ti84.c b/emul/z80/ti84.c similarity index 99% rename from emul/z80/ti/ti84.c rename to emul/z80/ti84.c index 8ede3e3..8a283ee 100644 --- a/emul/z80/ti/ti84.c +++ b/emul/z80/ti84.c @@ -14,9 +14,9 @@ #define XK_MISCELLANY #include -#include "../emul.h" +#include "emul.h" #include "t6a04.h" -#include "kbd.h" +#include "ti84_kbd.h" #define RAMSTART 0x8000 #define KBD_PORT 0x01 diff --git a/emul/z80/ti/kbd.c b/emul/z80/ti84_kbd.c similarity index 99% rename from emul/z80/ti/kbd.c rename to emul/z80/ti84_kbd.c index 54f1945..97e9a71 100644 --- a/emul/z80/ti/kbd.c +++ b/emul/z80/ti84_kbd.c @@ -1,7 +1,7 @@ #include #include -#include "kbd.h" +#include "ti84_kbd.h" void kbd_init(KBD *kbd) { diff --git a/emul/z80/ti/kbd.h b/emul/z80/ti84_kbd.h similarity index 100% rename from emul/z80/ti/kbd.h rename to emul/z80/ti84_kbd.h diff --git a/recipes/rc2014/Makefile b/recipes/rc2014/Makefile index b440803..a9fe24b 100644 --- a/recipes/rc2014/Makefile +++ b/recipes/rc2014/Makefile @@ -4,7 +4,7 @@ CDIR = $(BASE)/cvm EDIR = $(BASE)/emul/z80 STAGE = $(CDIR)/stage BLKPACK = $(BASE)/tools/blkpack -EMUL = $(EDIR)/rc2014/classic +EMUL = $(EDIR)/rc2014 .PHONY: all all: $(TARGET) @@ -21,7 +21,7 @@ $(STAGE): $(MAKE) -C $(CDIR) stage $(EMUL): - $(MAKE) -C ${@:%/classic=%} + $(MAKE) -C $(EDIR) .PHONY: emul emul: $(EMUL) $(TARGET) diff --git a/recipes/sms/Makefile b/recipes/sms/Makefile index 2db8925..a7bb9a7 100644 --- a/recipes/sms/Makefile +++ b/recipes/sms/Makefile @@ -3,7 +3,7 @@ BASE = ../.. STAGE = $(BASE)/cvm/stage BLKPACK = $(BASE)/tools/blkpack SMSROM = $(BASE)/tools/smsrom -EMUL = $(BASE)/emul/z80/sms/sms +EMUL = $(BASE)/emul/z80/sms .PHONY: all all: $(TARGET) diff --git a/recipes/ti84/Makefile b/recipes/ti84/Makefile index 20ef5a4..6f9503f 100644 --- a/recipes/ti84/Makefile +++ b/recipes/ti84/Makefile @@ -3,7 +3,7 @@ BASE = ../.. CDIR = $(BASE)/cvm STAGE = $(CDIR)/stage BLKPACK = $(BASE)/tools/blkpack -EMUL = $(BASE)/emul/z80/ti/ti84 +EMUL = $(BASE)/emul/z80/ti84 MKTIUPGRADE = mktiupgrade .PHONY: all @@ -26,7 +26,7 @@ $(EMUL): .PHONY: emul emul: $(EMUL) $(TARGET) $(EMUL) $(TARGET) - + os.rom: $(TARGET) dd if=$(TARGET) bs=1M of=$@ conv=sync