all repos — xyw @ 8b28522294cec55794d1bc8a7698830d72db009e

A minimal virtual machine and assembler for terminals.

Updated instructions. Still not working right though + macros need heavy refactoring.
h3rald h3rald@h3rald.com
Thu, 04 Dec 2025 15:00:24 +0100
commit

8b28522294cec55794d1bc8a7698830d72db009e

parent

52409605a05c1facf8527cbe6cae6dd43f0de8e7

2 files changed, 12 insertions(+), 10 deletions(-)

jump to
M xyw.cxyw.c

@@ -7,7 +7,7 @@

// Instruction mnemonics definition const char xyw_instructions[][4] = { "BRK", "PSH", "POP", "???", - "LDP", "LDR", "STP", "STR", + "LDB", "LDW", "STB", "STW", "INC", "DEC", "SHL", "SHR", "ADD", "SUB", "MUL", "DIV", "EQU", "NEQ", "GTH", "LTH",
M xywrun.cxywrun.c

@@ -288,23 +288,25 @@ //// "Microcode" similar to Uxn's, to be used with above macros

// Get argument from x or stack #define ARGX rx ? (w ? *xw : *x) : (w ? us_popw() : us_pop()) // Get a byte argument from x or stack -#define ARGXB rx ? *x : us_pop() +#define ARGXB (rx && !!a && !!b) ? *x : us_pop() // Get a word argument from x or stack -#define ARGXW rx ? *xw : us_popw() +#define ARGXW (rx && !!a && !!b) ? *xw : us_popw() // Get argument from y or stack #define ARGY ry ? (w ? *yw : *y) : (w ? us_popw() : us_pop()) // Get arguments from x/y or stack #define ARGXY rx ? (rx ? (w ? *xw : *x) : (w ? us_popw() : us_pop())) : (ry ? (w ? *yw : *y) : (w ? us_popw() : us_pop())) // Get a byte argument from x/y or stack -#define ARGXYB rx ? (rx ? *x : *y) : us_pop() +#define ARGXYB (rx && !!ry) ? (rx ? *x : *y) : us_pop() // Get a word argument from x/y or stack -#define ARGXYW rx ? (rx ? *xw : *yw) : us_popw() +#define ARGXYW (rx && !!ry) ? (rx ? *xw : *yw) : us_popw() // Push a value to stack #define PUSH(n) do { if (w && !!rx && !!ry) { us_pushw(n); } else { us_push(n); } } while(0) // Pop value from stack #define POP() (w ? us_popw() : (xyw_word)us_pop()) // Write a byte or word to the specified direct page or absolute address -#define WRITE(addr, val) ((w && !!a && !!b)? writew(addr, val) : write(addr, val)) +#define WRITE(addr, val) ((w)? writew(addr, val) : write(addr, val)) +// Read a byte or word (depending on w) from the specified direct page or absolute address +#define READ(addr) ((w)? readw(addr) : read(addr)) //// Initialize devices

@@ -347,10 +349,10 @@ /* BRK */ case 0x00: return 0; // Halting execution for now

/* PSH */ OPC_PSH(0x01); /* POP */ OPC_POP(0x02); ///* LDR */ OPC_R1(0x03, PUSH(READ(a))); // TBD - /* LDP */ OPC_SR1(0x04, , PUSH(read(ARGXYB))); - /* LDR */ OPC_SR1(0x05, , PUSH(readw(ARGXYW))); - /* STP */ OPC_SR2(0x06, WRITE(DIRECT_PAGE | ARGXB, ARGY)); - /* STR */ OPC_SR2(0x07, WRITE(ARGXW, ARGY)); + /* LDB */ OPC_SR1(0x04, , us_push(w ? READ(ARGXYW) : READ(DIRECT_PAGE | ARGXYB))); + /* LDW */ OPC_SR1(0x05, , us_pushw(w ? READ(ARGXYW) : READ(DIRECT_PAGE | ARGXYB))); + /* STB */ OPC_SR2(0x06, write(DIRECT_PAGE | ARGXB, ARGY)); + /* STW */ OPC_SR2(0x07, writew(ARGXW, ARGY)); /* INC */ OPC_IDC(0x08, +1); /* DEC */ OPC_IDC(0x09, -1); /* SHL */ OPC_SR2(0x0A, PUSH(b << a));