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 208a638
Show file tree
Hide file tree
Showing 5 changed files with 83 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
50 changes: 50 additions & 0 deletions vt100/flowers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <unistd.h>
#include <sys/ioctl.h>
#include "vt100.h"

int flowers = 0; // Trevor Flowers' mini VT100.

void flowers_leds(u8 data)
{
char command[100];
int n;
if (!flowers)
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 = "\nSPECIAL_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;
}
21 changes: 21 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,28 @@ static void scanning (void)
SDL_AtomicUnlock (&kbd_lock);
}

static void check_flowers (void)
{
int key = flowers_key ();
add_event (100, &flowers_event);
switch (key) {
case '2': // SET-UP
down[0x7B] ^= 1;
break;
case '3': // BREAK
down[0x23] ^= 1;
break;
}
}

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)
add_event (1000, &flowers_event);
}
8 changes: 7 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,11 @@ int main (int argc, char **argv)
case 'c':
curvature = atof (optarg);
break;
case 'F':
flowers = open(optarg, O_RDWR);
if (flowers == -1)
panic("Couldn't open %s: %s", optarg, strerror (errno));
break;
default:
usage();
break;
Expand Down
4 changes: 4 additions & 0 deletions vt100/vt100.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern u8 vt100_flags;
extern int pty;
extern int sound_scope;
extern int field_rate;
extern int flowers;

extern int quick;
extern int pixcolor;
Expand Down Expand Up @@ -62,3 +63,6 @@ extern void reset_sound (void);
extern void nvr_clock (void);
extern void key_down (u8 code);
extern void key_up (u8 code);

extern void flowers_leds(u8 data);
extern int flowers_key(void);

0 comments on commit 208a638

Please sign in to comment.