Browse Source

emul/z80: flatten directory structure

I'm about to reuse sdc.c in sms.c and the old directory structure
was becoming awkward.
master
Virgil Dupras 3 years ago
parent
commit
490eceab6d
36 changed files with 101 additions and 163 deletions
  1. +3
    -0
      emul/z80/.gitignore
  2. +14
    -2
      emul/z80/Makefile
  3. +63
    -6
      emul/z80/README.md
  4. +0
    -0
      emul/z80/acia.c
  5. +0
    -0
      emul/z80/acia.h
  6. +1
    -1
      emul/z80/ps2_kbd.c
  7. +1
    -1
      emul/z80/ps2_kbd.h
  8. +1
    -1
      emul/z80/rc2014.c
  9. +0
    -1
      emul/z80/rc2014/.gitignore
  10. +0
    -16
      emul/z80/rc2014/Makefile
  11. +0
    -18
      emul/z80/rc2014/README.md
  12. +0
    -0
      emul/z80/sdc.c
  13. +0
    -0
      emul/z80/sdc.h
  14. +0
    -0
      emul/z80/sio.c
  15. +0
    -0
      emul/z80/sio.h
  16. +5
    -5
      emul/z80/sms.c
  17. +0
    -1
      emul/z80/sms/.gitignore
  18. +0
    -19
      emul/z80/sms/Makefile
  19. +0
    -33
      emul/z80/sms/README.md
  20. +1
    -1
      emul/z80/sms_pad.c
  21. +1
    -1
      emul/z80/sms_pad.h
  22. +1
    -1
      emul/z80/sms_ports.c
  23. +1
    -1
      emul/z80/sms_ports.h
  24. +1
    -1
      emul/z80/sms_vdp.c
  25. +0
    -0
      emul/z80/sms_vdp.h
  26. +0
    -0
      emul/z80/t6a04.c
  27. +0
    -0
      emul/z80/t6a04.h
  28. +0
    -1
      emul/z80/ti/.gitignore
  29. +0
    -19
      emul/z80/ti/Makefile
  30. +0
    -26
      emul/z80/ti/README.md
  31. +2
    -2
      emul/z80/ti84.c
  32. +1
    -1
      emul/z80/ti84_kbd.c
  33. +0
    -0
      emul/z80/ti84_kbd.h
  34. +2
    -2
      recipes/rc2014/Makefile
  35. +1
    -1
      recipes/sms/Makefile
  36. +2
    -2
      recipes/ti84/Makefile

+ 3
- 0
emul/z80/.gitignore View File

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

+ 14
- 2
emul/z80/Makefile View File

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

+ 63
- 6
emul/z80/README.md View File

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

emul/z80/rc2014/acia.c → emul/z80/acia.c View File


emul/z80/rc2014/acia.h → emul/z80/acia.h View File


emul/z80/sms/kbd.c → emul/z80/ps2_kbd.c View File

@@ -1,4 +1,4 @@
#include "kbd.h"
#include "ps2_kbd.h"

void kbd_init(Kbd *kbd, Tristate *TH)
{

emul/z80/sms/kbd.h → emul/z80/ps2_kbd.h View File

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

#define KBD_BUFSZ 0x10


emul/z80/rc2014/classic.c → emul/z80/rc2014.c View File

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

+ 0
- 1
emul/z80/rc2014/.gitignore View File

@@ -1 +0,0 @@
/classic

+ 0
- 16
emul/z80/rc2014/Makefile 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)

+ 0
- 18
emul/z80/rc2014/README.md 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`.

emul/z80/rc2014/sdc.c → emul/z80/sdc.c View File


emul/z80/rc2014/sdc.h → emul/z80/sdc.h View File


emul/z80/rc2014/sio.c → emul/z80/sio.c View File


emul/z80/rc2014/sio.h → emul/z80/sio.h View File


emul/z80/sms/sms.c → emul/z80/sms.c View File

@@ -7,11 +7,11 @@
#define XK_MISCELLANY
#include <X11/keysymdef.h>

#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

+ 0
- 1
emul/z80/sms/.gitignore View File

@@ -1 +0,0 @@
/sms

+ 0
- 19
emul/z80/sms/Makefile 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)

+ 0
- 33
emul/z80/sms/README.md 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.

emul/z80/sms/pad.c → emul/z80/sms_pad.c View File

@@ -1,4 +1,4 @@
#include "pad.h"
#include "sms_pad.h"

void pad_init(Pad *pad, Tristate *TH)
{

emul/z80/sms/pad.h → emul/z80/sms_pad.h View File

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

typedef enum {
PAD_BTN_UP = 0,

emul/z80/sms/port.c → emul/z80/sms_ports.c View File

@@ -1,4 +1,4 @@
#include "port.h"
#include "sms_ports.h"

void ports_init(Ports *ports)
{

emul/z80/sms/port.h → emul/z80/sms_ports.h View File

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

emul/z80/sms/vdp.c → emul/z80/sms_vdp.c View File

@@ -1,5 +1,5 @@
#include <string.h>
#include "vdp.h"
#include "sms_vdp.h"

void vdp_init(VDP *vdp)
{

emul/z80/sms/vdp.h → emul/z80/sms_vdp.h View File


emul/z80/ti/t6a04.c → emul/z80/t6a04.c View File


emul/z80/ti/t6a04.h → emul/z80/t6a04.h View File


+ 0
- 1
emul/z80/ti/.gitignore View File

@@ -1 +0,0 @@
/ti84

+ 0
- 19
emul/z80/ti/Makefile 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)

+ 0
- 26
emul/z80/ti/README.md 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.

emul/z80/ti/ti84.c → emul/z80/ti84.c View File

@@ -14,9 +14,9 @@
#define XK_MISCELLANY
#include <X11/keysymdef.h>

#include "../emul.h"
#include "emul.h"
#include "t6a04.h"
#include "kbd.h"
#include "ti84_kbd.h"

#define RAMSTART 0x8000
#define KBD_PORT 0x01

emul/z80/ti/kbd.c → emul/z80/ti84_kbd.c View File

@@ -1,7 +1,7 @@
#include <string.h>
#include <ctype.h>

#include "kbd.h"
#include "ti84_kbd.h"

void kbd_init(KBD *kbd)
{

emul/z80/ti/kbd.h → emul/z80/ti84_kbd.h View File


+ 2
- 2
recipes/rc2014/Makefile View File

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


+ 1
- 1
recipes/sms/Makefile View File

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


+ 2
- 2
recipes/ti84/Makefile View File

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



Loading…
Cancel
Save