Skip to content

Commit

Permalink
Add support for Trevor Flowers' mini VT100.
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbrinkhoff committed Nov 5, 2024
1 parent 0fe6abf commit c8c340a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vt100/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif
check: vt100 ../test/test.sh
cd ..; sh test/test.sh
WARN=-Wall -Wno-unused-parameter -Wno-parentheses -Wno-unused-result
SRC=main.c cpu.c sys.c ddt.c pusart.c \
SRC=main.c cpu.c sys.c ddt.c pusart.c flowers.c \
nvr.c keyboard.c video.c rom.c sound.c render.c \
../common/sdl.c ../common/opengl.c ../common/event.c \
../common/logger.c ../common/pty.c
Expand Down
66 changes: 66 additions & 0 deletions vt100/flowers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
#include <sys/ioctl.h>
#include "vt100.h"

int flowers = -1; // Trevor Flowers' mini VT100.

void flowers_init(const char *device)
{
struct termios t;

flowers = open(device, O_RDWR);
if (flowers == -1)
panic("Couldn't open %s: %s", optarg, strerror (errno));

memset(&t, 0, sizeof t);
tcsetattr(flowers, TCSAFLUSH, &t);
}

void flowers_leds(u8 data)
{
char command[100];
int n;
if (flowers < 0)
return;
n = snprintf(command, sizeof command, "\nSET_ALL_LEDS %c%c%c%c%c%c%c\n",
(data & 0x20) ? '0' : '1',
(data & 0x20) ? '1' : '0',
(data & 0x10) ? '1' : '0',
(data & 0x08) ? '1' : '0',
(data & 0x04) ? '1' : '0',
(data & 0x02) ? '1' : '0',
(data & 0x01) ? '1' : '0');
write(flowers, command, n);
}

static const char *const prefix = "SPECIAL_KEY: ";
static const char *pointer = prefix;

int flowers_key(void)
{
char data;
int n;

if (ioctl(flowers, FIONREAD, &n) != 0)
return -1;
if (n < 1)
return -1;
if (read(flowers, &data, 1) != 1)
return -1;

if (*pointer == 0) {
pointer = prefix;
return data;
}

if (data != *pointer)
pointer = prefix;
if (data == *pointer)
pointer++;

return -1;
}
23 changes: 23 additions & 0 deletions vt100/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ static SDL_SpinLock kbd_lock;

static void scanning (void);
static EVENT (scan_event, scanning);
static void check_flowers (void);
static EVENT (flowers_event, check_flowers);

uint8_t keymap (SDL_Scancode key)
{
Expand Down Expand Up @@ -122,6 +124,8 @@ static void keyboard_out (u8 port, u8 data)
u8 changed = previous ^ data;
if ((vt100_flags & 0x80) == 0)
return;
if (changed & 0x3F)
flowers_leds(data);
if (changed & ~0x40)
LOG (KEY, "LED:%c%c%c%c %s %s%s",
(data & 0x08) ? '1' : '-',
Expand Down Expand Up @@ -180,11 +184,30 @@ static void scanning (void)
SDL_AtomicUnlock (&kbd_lock);
}

static void check_flowers (void)
{
int key = flowers_key ();
add_event (1000, &flowers_event);
SDL_AtomicLock (&kbd_lock);
switch (key) {
case '2': // SETUP
down[0x7B] ^= 1;
break;
case '3': // BREAK
down[0x23] ^= 1;
break;
}
SDL_AtomicUnlock (&kbd_lock);
}

void reset_keyboard (void)
{
register_port (0x82, keyboard_in, keyboard_out);
vt100_flags |= 0x80;
memset (down, 0, sizeof down);
down[0x7F] = 1;
scan = 0x80;
flowers_leds(0);
if (flowers > 0)
add_event (1000, &flowers_event);
}
6 changes: 5 additions & 1 deletion vt100/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void help(void)
" -B Treat backspace as rubout (currently not implemented).\n"
" -R PROG Run CP/M binary file [path/to/]PROG.\n"
" -D Debug mode.\n"
" -F DEV Open DEV to talk to Trevor Flowers' mini VT100\n"
"\n"
"Project page: https://github.com/larsbrinkhoff/terminal-simulator\n"
, argv0);
Expand All @@ -157,7 +158,7 @@ int main (int argc, char **argv)
sdl_capslock (0x7E); //Default is capslock.

argv0 = argv[0];
while ((opt = getopt (argc, argv, "aghB2fR:DCQN:c:")) != -1) {
while ((opt = getopt (argc, argv, "aghB2fF:R:DCQN:c:")) != -1) {
switch (opt) {
case 'g':
pixcolor = 1;
Expand Down Expand Up @@ -195,6 +196,9 @@ int main (int argc, char **argv)
case 'c':
curvature = atof (optarg);
break;
case 'F':
flowers_init(optarg);
break;
default:
usage();
break;
Expand Down
7 changes: 7 additions & 0 deletions vt100/vt100.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ typedef uint8_t u8;
#define RST6 0xF7
#define RST7 0xFF

extern void panic (char *fmt, ...);

extern u8 memory[0x10000];
extern u16 starta;
extern unsigned long long get_cycles (void);
Expand Down Expand Up @@ -62,3 +64,8 @@ extern void reset_sound (void);
extern void nvr_clock (void);
extern void key_down (u8 code);
extern void key_up (u8 code);

extern int flowers;
extern void flowers_init(const char *device);
extern void flowers_leds(u8 data);
extern int flowers_key(void);

0 comments on commit c8c340a

Please sign in to comment.