Changed instructions to load/store bytes or words explicitly
h3rald h3rald@h3rald.com
Thu, 04 Dec 2025 13:56:44 +0100
M
xyw.c
→
xyw.c
@@ -6,8 +6,8 @@ int xyw_debug = 0;
// Instruction mnemonics definition const char xyw_instructions[][4] = { - "BRK", "PSH", "POP", "LDR", - "LDA", "STA", "LDD", "STD", + "BRK", "PSH", "POP", "???", + "LDB", "LDW", "STB", "STW", "INC", "DEC", "SHL", "SHR", "ADD", "SUB", "MUL", "DIV", "EQU", "NEQ", "GTH", "LTH",
M
xywrun.c
→
xywrun.c
@@ -295,10 +295,14 @@ // Push a value to stack
#define PUSH(n) do { if (w) { us_pushw(n); } else { us_push(n); } } while(0) // Pop value from stack #define POP() (w ? us_popw() : (xyw_word)us_pop()) -// Read value from address -#define READ(addr) (w ? readw(addr) : (xyw_byte)xyw_memory[addr]) -// Write value as word or byte depending on width flag 'w' -#define WRITE(addr, val) w ? writew(addr, val) : write(addr, (xyw_byte)(val)) +// Read a byte from absolute address or direct page +#define READB(addr) (w ? read(addr) : read(DIRECT_PAGE | addr)) +// Read a word from absolute address or direct page +#define READW(addr) (w ? readw(addr) : readw(DIRECT_PAGE | addr)) +// Write a byte to absolute address or direct page +#define WRITEB(addr, val) w ? write(addr, val) : write(DIRECT_PAGE | addr, val) +// Write a word to absolute address or direct page +#define WRITEW(addr, val) w ? writew(addr, val) : writew(DIRECT_PAGE | addr, val) //// Initialize devices@@ -328,16 +332,6 @@ fclose(fp);
return -1; } xyw_dbg("Loaded %zu bytes into memory\n", bytes_read); - // Print loaded bytes, including header, 16 per line - xyw_dbg("Memory dump:\n"); - for (size_t i = 0; i < bytes_read; i++) - { - xyw_dbg("%02X ", xyw_memory[USER_MEMORY_START + i]); - if ((i + 1) % 16 == 0) - { - xyw_dbg("\n"); - } - } fclose(fp); xyw_memory[SYSTEM_STATE] = 1; while (xyw_memory[SYSTEM_STATE] && *pc < SYSTEM_MEMORY_START)@@ -346,14 +340,14 @@ xyw_dbg("PC: %04X -> %02X (%s) [X:%02X|Y:%02X|XW:%04X|YW:%04X]\n", *pc, xyw_memory[*pc], xyw_instructions[xyw_memory[*pc] & 0x1F], *x, *y, *xw, *yw);
switch (xyw_memory[*pc]) { // clang-format off - /* BRK */ case 0x00: break; + /* BRK */ case 0x00: return 0; // Halting execution for now /* PSH */ OPC_PSH(0x01); /* POP */ OPC_POP(0x02); - /* LDR */ OPC_R1(0x03, PUSH(READ(a))); - /* LDA */ OPC_S(0x04, READ(us_popw())); - /* STA */ OPC_SR1(0x05, xyw_word a = us_popw(), WRITE(a, ARGXY)); - /* LDP */ OPC_S(0x06, READ(DIRECT_PAGE | us_pop())); - /* STP */ OPC_SR1(0x07, xyw_word a = DIRECT_PAGE | us_pop(), WRITE(a, ARGXY)); + ///* LDR */ OPC_R1(0x03, PUSH(READ(a))); // TBD + /* LDB */ OPC_SR1(0x04, , us_push(READB(ARGXY))); + /* LDW */ OPC_SR1(0x05, , us_pushw(READW(ARGXY))); + /* STB */ OPC_SR2(0x06, WRITEB(b, a)); + /* STW */ OPC_SR2(0x07, WRITEW(b, a)); /* INC */ OPC_IDC(0x08, +1); /* DEC */ OPC_IDC(0x09, -1); /* SHL */ OPC_SR2(0x0A, PUSH(b << a));