/* 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 #include 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 (;;); }