Files
Basys3Terminal/monitor/test/asm-z80.c
T
brad ArantandClaude Opus 5.5 fe1daf180d Monitor: Z-80 assembler (ASM "file", A addr)
Two-pass table-driven assembler in the monitor: assembles BASIC-saved
source files from the file system, or one line at a time with A addr.
Labels, EQU/ORG/DB/DW/DS/END, expressions. Table generated from the
disassembler (tools/gen-asmtab.py); round-trip and sdasz80 tests, plus a
Z-80 build run in z80emu. Monitor RAM grows to 6000-7FFF for the symbol
table. Works around an SDCC 4.5 inline strcpy bug with s_copy().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 16:42:42 -08:00

33 lines
1.2 KiB
C

/* Z-80 build of the assembler alone, for monitor/test-asm-z80.sh: assembles
each console line at address 0 and prints its bytes (or ERROR ...). */
#include <stdint.h>
#include <string.h>
typedef uint8_t u8; typedef uint16_t u16; typedef int16_t i16; typedef uint32_t u32; typedef int32_t i32;
__sfr __at 0x00 con_stat;
__sfr __at 0x01 con_data;
static void putc_(char c) { while (!(con_stat & 2)); con_data = c; }
static u8 getk(void) { while (!(con_stat & 1)); return con_data; }
static u8 mem[64];
#include "asm.c"
static void a_out(u16 addr, u8 b) { mem[addr & 63] = b; }
static const char hx[] = "0123456789ABCDEF";
static char b[128];
void main(void)
{
u16 i;
u8 n, c;
for (;;) {
n = 0;
while ((c = getk()) != '\n') if (n < 127) b[n++] = c;
b[n] = 0;
if (!n) break;
a_upper(b);
a_pass = 2; a_pc = 0; a_undef = 0;
a_line(b);
if (a_err) { const char *t = a_err; putc_('E'); putc_('R'); putc_('R'); putc_('O'); putc_('R'); putc_(' '); while (*t) putc_(*t++); }
else for (i = 0; i < a_pc; i++) { putc_(hx[mem[i] >> 4]); putc_(hx[mem[i] & 15]); }
putc_('\n');
}
for (;;);
}