all repos — xyw @ ea20a204b8db7285bc073ff0bb1aef76bcb63f51

A minimal virtual machine and assembler for terminals.

Fixed sending data to device.
h3rald h3rald@h3rald.com
Fri, 30 Jan 2026 10:45:12 +0100
commit

ea20a204b8db7285bc073ff0bb1aef76bcb63f51

parent

91c5bb20892f4ce23273e1f8b729b7d49e105d1e

3 files changed, 7 insertions(+), 10 deletions(-)

jump to
M devices/terminal.cdevices/terminal.c

@@ -2,15 +2,15 @@ #include <stdio.h>

#include "../xyw.h" /* terminal device */ -#define terminal_INPUT 0x0 -#define terminal_OUTPUT 0x1 +#define TERMINAL_INPUT 0x0 +#define TERMINAL_OUTPUT 0x1 void terminal_output(xyw_byte *data, xyw_byte addr, xyw_byte *error) { (void)error; switch (addr) { - case terminal_OUTPUT: + case TERMINAL_OUTPUT: fputc(data[addr], stdout); fflush(stdout); break;
M xyw.hxyw.h

@@ -15,6 +15,7 @@

typedef unsigned char xyw_byte; typedef unsigned short xyw_word; +// Device contract typedef xyw_byte (*xyw_input)(xyw_byte *data, xyw_byte addr, xyw_byte *error); typedef void (*xyw_output)(xyw_byte *data, xyw_byte addr, xyw_byte *error); typedef void (*xyw_init)(xyw_byte *data);
M xywrun.cxywrun.c

@@ -69,9 +69,8 @@ }

static inline xyw_byte get_device_address(xyw_word addr) { - // Given $FF40, it should return $40 - // TODO: verify correctness - return (xyw_byte)(addr - DEVICE_AREA_START); + // Given $FF41, it should return $01 + return (xyw_byte)((addr - DEVICE_AREA_START) & 0x0F); } //// Read/write memory helpers

@@ -114,14 +113,11 @@ }

static inline void write(xyw_word addr, xyw_byte val) { - printf("Write to addr=%04X val=%02X\n", addr, val); xyw_memory[addr] = val; int dev_num = get_device(addr); - printf("Device number: %d\n", dev_num); if (dev_num >= 0 && xyw_devices[dev_num].output) { xyw_byte dev_addr = get_device_address(addr); - printf("Device address: %02X\n", dev_addr); xyw_devices[dev_num].output(get_device_data(addr), dev_addr, error); } }

@@ -251,7 +247,7 @@

xyw_device xyw_devices[XYW_TOTAL_DEVICES] = { // System device (not implemented yet) {&xyw_memory[0xff00], 0, 0, 0}, - // terminal device + // Terminal device {&xyw_memory[0xff10], 0, 0, terminal_output}, // Clock device {&xyw_memory[0xff20], clock_init, clock_input, 0},