1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 14:58:06 +11:00

emul/z80: flatten directory structure

I'm about to reuse sdc.c in sms.c and the old directory structure
was becoming awkward.
This commit is contained in:
Virgil Dupras 2020-10-25 15:58:00 -04:00
parent 44abcaa8f8
commit 490eceab6d
36 changed files with 101 additions and 163 deletions

3
emul/z80/.gitignore vendored
View File

@ -1,2 +1,5 @@
/forth /forth
/forth.bin /forth.bin
/ti84
/sms
/rc2014

View File

@ -1,5 +1,8 @@
TARGETS = forth TARGETS = forth rc2014 sms ti84
OBJS = emul.o z80.o 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 CDIR = ../../cvm
STAGE = $(CDIR)/stage STAGE = $(CDIR)/stage
BLKFS = $(CDIR)/blkfs BLKFS = $(CDIR)/blkfs
@ -10,6 +13,15 @@ all: $(TARGETS)
forth: forth.c $(OBJS) $(BLKFS) forth: forth.c $(OBJS) $(BLKFS)
$(CC) forth.c $(OBJS) -lncurses -o $@ $(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) emul.o: emul.c forth.bin $(BLKFS)
$(CC) -DFBIN_PATH=\"`pwd`/forth.bin\" -DBLKFS_PATH=\"`pwd`/$(BLKFS)\" -c -o emul.o emul.c $(CC) -DFBIN_PATH=\"`pwd`/forth.bin\" -DBLKFS_PATH=\"`pwd`/$(BLKFS)\" -c -o emul.o emul.c
@ -23,4 +35,4 @@ $(STAGE):
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(TARGETS) emul.o *.bin z80.o rm -f $(TARGETS) *.o *.bin

View File

@ -1,4 +1,4 @@
# emul # Z80 emulation
This folder contains a couple of tools running under the [libz80][libz80] This folder contains a couple of tools running under the [libz80][libz80]
emulator. emulator.
@ -8,23 +8,80 @@ emulator.
You need `ncurses` to build the `forth` executable. In debian-based distros, You need `ncurses` to build the `forth` executable. In debian-based distros,
it's `libncurses5-dev`. it's `libncurses5-dev`.
For `sms` and `ti84` emulators, you need XCB and pkg-config.
## Build ## 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 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 under an emulated z80 machine instead of running natively. Refer to
`/cvm/README.md` for details. `/cvm/README.md` for details.
## Not real hardware
`./forth` doesn't try to emulate real hardware `./forth` doesn't try to emulate real hardware
because the goal here is to facilitate "high level" development. because the goal here is to facilitate "high level" development.
These apps run on imaginary hardware and use many cheats to simplify I/Os. 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 [libz80]: https://github.com/ggambetta/libz80

View File

@ -1,4 +1,4 @@
#include "kbd.h" #include "ps2_kbd.h"
void kbd_init(Kbd *kbd, Tristate *TH) void kbd_init(Kbd *kbd, Tristate *TH)
{ {

View File

@ -1,6 +1,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "port.h" #include "emul.h"
#define KBD_BUFSZ 0x10 #define KBD_BUFSZ 0x10

View File

@ -11,7 +11,7 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <termios.h> #include <termios.h>
#include "../emul.h" #include "emul.h"
#include "acia.h" #include "acia.h"
#include "sio.h" #include "sio.h"
#include "sdc.h" #include "sdc.h"

View File

@ -1 +0,0 @@
/classic

View File

@ -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)

View File

@ -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`.

View File

@ -7,11 +7,11 @@
#define XK_MISCELLANY #define XK_MISCELLANY
#include <X11/keysymdef.h> #include <X11/keysymdef.h>
#include "../emul.h" #include "emul.h"
#include "vdp.h" #include "sms_vdp.h"
#include "port.h" #include "sms_ports.h"
#include "pad.h" #include "sms_pad.h"
#include "kbd.h" #include "ps2_kbd.h"
#define RAMSTART 0xc000 #define RAMSTART 0xc000
#define VDP_CMD_PORT 0xbf #define VDP_CMD_PORT 0xbf

View File

@ -1 +0,0 @@
/sms

View File

@ -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)

View File

@ -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.

View File

@ -1,4 +1,4 @@
#include "pad.h" #include "sms_pad.h"
void pad_init(Pad *pad, Tristate *TH) void pad_init(Pad *pad, Tristate *TH)
{ {

View File

@ -1,6 +1,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "port.h" #include "emul.h"
typedef enum { typedef enum {
PAD_BTN_UP = 0, PAD_BTN_UP = 0,

View File

@ -1,4 +1,4 @@
#include "port.h" #include "sms_ports.h"
void ports_init(Ports *ports) void ports_init(Ports *ports)
{ {

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "../emul.h" #include "emul.h"
// Each port is a bitmask of each pin's status. 1 means high. // 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 // From Bit 0 to 6: up, down, left, right, TL, TR, TH

View File

@ -1,5 +1,5 @@
#include <string.h> #include <string.h>
#include "vdp.h" #include "sms_vdp.h"
void vdp_init(VDP *vdp) void vdp_init(VDP *vdp)
{ {

View File

@ -1 +0,0 @@
/ti84

View File

@ -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)

View File

@ -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.

View File

@ -14,9 +14,9 @@
#define XK_MISCELLANY #define XK_MISCELLANY
#include <X11/keysymdef.h> #include <X11/keysymdef.h>
#include "../emul.h" #include "emul.h"
#include "t6a04.h" #include "t6a04.h"
#include "kbd.h" #include "ti84_kbd.h"
#define RAMSTART 0x8000 #define RAMSTART 0x8000
#define KBD_PORT 0x01 #define KBD_PORT 0x01

View File

@ -1,7 +1,7 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "kbd.h" #include "ti84_kbd.h"
void kbd_init(KBD *kbd) void kbd_init(KBD *kbd)
{ {

View File

@ -4,7 +4,7 @@ CDIR = $(BASE)/cvm
EDIR = $(BASE)/emul/z80 EDIR = $(BASE)/emul/z80
STAGE = $(CDIR)/stage STAGE = $(CDIR)/stage
BLKPACK = $(BASE)/tools/blkpack BLKPACK = $(BASE)/tools/blkpack
EMUL = $(EDIR)/rc2014/classic EMUL = $(EDIR)/rc2014
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)
@ -21,7 +21,7 @@ $(STAGE):
$(MAKE) -C $(CDIR) stage $(MAKE) -C $(CDIR) stage
$(EMUL): $(EMUL):
$(MAKE) -C ${@:%/classic=%} $(MAKE) -C $(EDIR)
.PHONY: emul .PHONY: emul
emul: $(EMUL) $(TARGET) emul: $(EMUL) $(TARGET)

View File

@ -3,7 +3,7 @@ BASE = ../..
STAGE = $(BASE)/cvm/stage STAGE = $(BASE)/cvm/stage
BLKPACK = $(BASE)/tools/blkpack BLKPACK = $(BASE)/tools/blkpack
SMSROM = $(BASE)/tools/smsrom SMSROM = $(BASE)/tools/smsrom
EMUL = $(BASE)/emul/z80/sms/sms EMUL = $(BASE)/emul/z80/sms
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)

View File

@ -3,7 +3,7 @@ BASE = ../..
CDIR = $(BASE)/cvm CDIR = $(BASE)/cvm
STAGE = $(CDIR)/stage STAGE = $(CDIR)/stage
BLKPACK = $(BASE)/tools/blkpack BLKPACK = $(BASE)/tools/blkpack
EMUL = $(BASE)/emul/z80/ti/ti84 EMUL = $(BASE)/emul/z80/ti84
MKTIUPGRADE = mktiupgrade MKTIUPGRADE = mktiupgrade
.PHONY: all .PHONY: all