all repos — xyw @ ac1f94ffa2f5688734e4b0cf1557c3ecba1a4608

A minimal virtual machine and assembler for terminals.

Simplified device management.
h3rald h3rald@h3rald.com
Thu, 04 Dec 2025 09:15:20 +0100
commit

ac1f94ffa2f5688734e4b0cf1557c3ecba1a4608

parent

7ef6eed3ff9ebdc20cb6fbfe95113d4c2abfe2f6

1 files changed, 20 insertions(+), 32 deletions(-)

jump to
M xywrun.cxywrun.c

@@ -55,7 +55,7 @@ xyw_word *xw = &xw_storage;

xyw_word *yw = &yw_storage; //// Helpers to retrieve device number and address within the device -static inline xyw_byte get_device(xyw_word addr) +static inline int get_device(xyw_word addr) { return (addr - DEVICE_AREA_START) / 16; }

@@ -81,17 +81,14 @@ //// Read/write memory helpers

static inline xyw_word readw(xyw_word addr) { - if (addr >= DEVICE_AREA_START) + int dev_num = get_device(addr); + if (dev_num >= 0 && xyw_devices[dev_num].input) { - xyw_byte dev_num = get_device(addr); - if (xyw_devices[dev_num].input) - { - xyw_byte dev_addr = get_device_address(addr); - // Read two bytes from device - xyw_byte high = xyw_devices[dev_num].input(get_device_data(addr), dev_addr, error); - xyw_byte low = xyw_devices[dev_num].input(get_device_data(addr), dev_addr + 1, error); - return (xyw_word)((high << 8) | low); - } + xyw_byte dev_addr = get_device_address(addr); + // Read two bytes from device + xyw_byte high = xyw_devices[dev_num].input(get_device_data(addr), dev_addr, error); + xyw_byte low = xyw_devices[dev_num].input(get_device_data(addr), dev_addr + 1, error); + return (xyw_word)((high << 8) | low); } return XYW_PEEKW(&xyw_memory[addr]); }

@@ -99,27 +96,21 @@

static inline void writew(xyw_word addr, xyw_word val) { XYW_POKEW(&xyw_memory[addr], val); - if (addr >= DEVICE_AREA_START) + int dev_num = get_device(addr); + if (dev_num >= 0 && xyw_devices[dev_num].output) { - xyw_byte dev_num = get_device(addr); - if (xyw_devices[dev_num].output) - { - xyw_byte dev_addr = get_device_address(addr); - xyw_devices[dev_num].output(get_device_data(addr), dev_addr, error); - } + xyw_byte dev_addr = get_device_address(addr); + xyw_devices[dev_num].output(get_device_data(addr), dev_addr, error); } } static inline xyw_byte read(xyw_word addr) { - if (addr >= DEVICE_AREA_START) + int dev_num = get_device(addr); + if (dev_num >= 0 && xyw_devices[dev_num].input) { - xyw_byte dev_num = get_device(addr); - if (xyw_devices[dev_num].input) - { - xyw_byte dev_addr = get_device_address(addr); - return xyw_devices[dev_num].input(get_device_data(addr), dev_addr, error); - } + xyw_byte dev_addr = get_device_address(addr); + return xyw_devices[dev_num].input(get_device_data(addr), dev_addr, error); } return xyw_memory[addr]; }

@@ -127,14 +118,11 @@

static inline void write(xyw_word addr, xyw_byte val) { xyw_memory[addr] = val; - if (addr >= DEVICE_AREA_START) + int dev_num = get_device(addr); + if (dev_num >= 0 && xyw_devices[dev_num].output) { - xyw_byte dev_num = get_device(addr); - if (xyw_devices[dev_num].output) - { - xyw_byte dev_addr = get_device_address(addr); - xyw_devices[dev_num].output(get_device_data(addr), dev_addr, error); - } + xyw_byte dev_addr = get_device_address(addr); + xyw_devices[dev_num].output(get_device_data(addr), dev_addr, error); } }