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>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-11-28 16:42:42 -08:00
1 parent 88b5942da5
commit fe1daf180d
16 files changed
+14320 -13257

No files matched your search

+410
View File
@@ -0,0 +1,410 @@
/* Z-80 assembler for the monitor (included by monitor.c).
*
* Zilog syntax, as the disassembler prints it. A line is
* [line number] [label:] [instruction or directive] [; comment]
* (the line number is there when the source was typed into BASIC). Numbers:
* 123, 0FFH, $FF, 0x1F, 1010B, 'A'; $ alone is the current address.
* Expressions use + - * / & | and parentheses; an operand that is all in
* parentheses is a memory reference: LD A,(LABEL+1).
* Directives: ORG, EQU (NAME EQU value), DB/DEFB/DEFM (numbers and "strings"),
* DW/DEFW, DS/DEFS n, END. Labels are up to 8 characters.
*
* Instructions are found in asm_tab (asmtab.h, generated from the
* disassembler by tools/gen-asmtab.py): mnemonic and operand pattern give the
* prefix and opcode; displacement and immediate bytes follow.
*/
#include "asmtab.h"
#define MAXSYM 300
struct sym { char name[8]; u16 val; };
static struct sym syms[MAXSYM];
static u16 nsym;
static u16 a_pc; /* address of the line being assembled */
static u16 a_lo, a_hi; /* lowest and highest byte written */
static u8 a_pass; /* 1: sizes and labels, 2: bytes */
static u8 a_undef; /* the expression used an undefined symbol */
static u8 a_end; /* END seen */
static const char *a_err; /* this line's error */
static const char *ap; /* parse pointer */
static void a_out(u16 addr, u8 b); /* write one byte (pass 2) */
static void a_fail(const char *m) { if (!a_err) a_err = m; }
static void a_sp(void) { while (*ap == ' ' || *ap == '\t') ap++; }
static u8 a_alpha(char c) { return (c >= 'A' && c <= 'Z') || c == '_' || c == '.'; }
static u8 a_alnum(char c) { return a_alpha(c) || (c >= '0' && c <= '9'); }
static void a_emit(u8 b)
{
if (a_pass == 2) {
a_out(a_pc, b);
if (a_pc < a_lo) a_lo = a_pc;
if (a_pc > a_hi) a_hi = a_pc;
}
a_pc++;
}
static i16 sym_find(const char *n)
{
u16 i;
for (i = 0; i < nsym; i++)
if (!strncmp(syms[i].name, n, 8)) return i;
return -1;
}
static void sym_def(const char *n, u16 v)
{
i16 i = sym_find(n);
if (a_pass == 2) {
if (i >= 0 && syms[i].val != v) a_fail("PHASE ERROR");
return;
}
if (i >= 0) { a_fail("DUPLICATE LABEL"); return; }
if (nsym == MAXSYM) { a_fail("TOO MANY LABELS"); return; }
strncpy(syms[nsym].name, n, 8);
syms[nsym++].val = v;
}
/* a name at ap (up to 8 characters kept) */
static void a_name(char *n)
{
u8 k = 0;
memset(n, 0, 8);
while (a_alnum(*ap)) { if (k < 8) n[k++] = *ap; ap++; }
}
/* ---------------------------------------------------------- expressions */
static u16 a_expr(void);
static u16 a_number(void)
{
const char *s = ap;
u16 v = 0;
u8 base = 10, n = 0;
if (s[0] == '0' && s[1] == 'X') { base = 16; s += 2; }
else {
while (a_alnum(s[n])) n++;
if (s[n - 1] == 'H') base = 16;
else if (s[n - 1] == 'B') {
u8 k;
for (k = 0; k < n - 1 && (s[k] == '0' || s[k] == '1'); k++);
if (k == n - 1) base = 2;
}
}
for (; a_alnum(*s); s++) {
char c = *s;
u8 d = c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'F' ? c - 'A' + 10 : 99;
if ((c == 'H' && base == 16) || (c == 'B' && base == 2 && !a_alnum(s[1]))) { s++; break; }
if (d >= base) { a_fail("BAD NUMBER"); break; }
v = v * base + d;
}
ap = s;
return v;
}
static u16 a_factor(void)
{
u16 v;
a_sp();
if (*ap == '-') { ap++; return -a_factor(); }
if (*ap == '+') { ap++; return a_factor(); }
if (*ap == '(') {
ap++;
v = a_expr();
a_sp();
if (*ap == ')') ap++; else a_fail("MISSING )");
return v;
}
if (*ap == '\'' && ap[1] && ap[2] == '\'') { v = (u8)ap[1]; ap += 3; return v; }
if (*ap == '$') {
ap++;
if ((*ap >= '0' && *ap <= '9') || (*ap >= 'A' && *ap <= 'F')) {
v = 0;
while ((*ap >= '0' && *ap <= '9') || (*ap >= 'A' && *ap <= 'F'))
v = v * 16 + (*ap <= '9' ? *ap - '0' : *ap - 'A' + 10), ap++;
return v;
}
return a_pc;
}
if (*ap >= '0' && *ap <= '9') return a_number();
if (a_alpha(*ap)) {
char n[8];
i16 i;
a_name(n);
i = sym_find(n);
if (i >= 0) return syms[i].val;
a_undef = 1;
if (a_pass == 2) a_fail("UNDEFINED LABEL");
return 0;
}
a_fail("BAD EXPRESSION");
return 0;
}
static u16 a_term(void)
{
u16 v = a_factor(), w;
for (;;) {
a_sp();
if (*ap == '*') { ap++; v *= a_factor(); }
else if (*ap == '/') { ap++; w = a_factor(); if (w) v /= w; else a_fail("DIVIDE BY 0"); }
else return v;
}
}
static u16 a_expr(void)
{
u16 v = a_term();
for (;;) {
a_sp();
if (*ap == '+') { ap++; v += a_term(); }
else if (*ap == '-') { ap++; v -= a_term(); }
else if (*ap == '&') { ap++; v &= a_term(); }
else if (*ap == '|') { ap++; v |= a_term(); }
else return v;
}
}
/* ------------------------------------------------------------- operands */
#define OC_FIXED 0 /* a register, condition or (HL) etc. */
#define OC_IMM 1 /* a value */
#define OC_MEM 2 /* (value) */
#define OC_IXD 3 /* (IX+d) */
#define OC_IYD 4
struct opnd { u8 cls, kind; u16 val; };
/* Classify the operand in s (n characters, no surrounding blanks). */
static void a_operand(const char *s, u8 n, struct opnd *o)
{
char t[24];
u8 k;
if (n >= sizeof t) n = sizeof t - 1;
memcpy(t, s, n); t[n] = 0;
o->val = 0;
for (k = 1; k < ASM_KN; k++) {
if (k == K_N || k == K_NN || k == K_E || k == K_MN || k == K_MNN || k == K_IXD || k == K_IYD)
continue;
if (!strcmp(t, asm_kn[k])) { o->cls = OC_FIXED; o->kind = k; return; }
}
if (t[0] == '(' && t[n - 1] == ')' && t[1] == 'I' && (t[2] == 'X' || t[2] == 'Y') &&
(t[3] == '+' || t[3] == '-')) {
o->cls = t[2] == 'X' ? OC_IXD : OC_IYD;
t[n - 1] = 0;
ap = t + 3;
o->val = a_expr();
if (*ap) a_fail("BAD OPERAND");
return;
}
if (t[0] == '(' && t[n - 1] == ')') {
/* (a)+(b) is an expression, not memory: the brackets must pair up */
u8 d = 0, j, whole = 1;
for (j = 0; j < n; j++) {
if (t[j] == '(') d++;
else if (t[j] == ')' && --d == 0 && j != n - 1) whole = 0;
}
if (whole) {
t[n - 1] = 0;
ap = t + 1;
o->cls = OC_MEM;
o->val = a_expr();
if (*ap) a_fail("BAD OPERAND");
return;
}
}
ap = t;
o->cls = OC_IMM;
o->val = a_expr();
if (*ap) a_fail("BAD OPERAND");
}
/* Does source operand o fit pattern kind k? */
static u8 a_fits(const struct opnd *o, u8 k, u8 given)
{
if (!k) return !given;
if (!given) return 0;
if (k & 0x80) return o->cls == OC_IMM && o->val == (k & 0x7F);
if (k == K_N || k == K_NN || k == K_E) return o->cls == OC_IMM;
if (k == K_MN || k == K_MNN) return o->cls == OC_MEM;
/* (IX) alone is (IX+0) */
if (k == K_IXD) return o->cls == OC_IXD || (o->cls == OC_FIXED && !strcmp(asm_kn[o->kind], "(IX)"));
if (k == K_IYD) return o->cls == OC_IYD || (o->cls == OC_FIXED && !strcmp(asm_kn[o->kind], "(IY)"));
return o->cls == OC_FIXED && o->kind == k;
}
/* Assemble one instruction: mnemonic m, operands o[0..n-1]. */
static void a_instr(u8 m, struct opnd *o, u8 n)
{
u16 i;
u8 k1, k2, pf, op, len, j;
const struct opnd *imm = 0, *dsp = 0;
u8 ik = 0;
for (i = 0; i < ASM_N; i++) {
if (asm_tab[i][0] != m) continue;
if (a_fits(&o[0], asm_tab[i][1], n > 0) && a_fits(&o[1], asm_tab[i][2], n > 1)) break;
}
if (i == ASM_N) { a_fail("BAD OPERANDS"); return; }
k1 = asm_tab[i][1]; k2 = asm_tab[i][2]; pf = asm_tab[i][3]; op = asm_tab[i][4];
for (j = 0; j < 2; j++) {
u8 k = j ? k2 : k1;
if (k == K_IXD || k == K_IYD) dsp = &o[j];
else if (k == K_N || k == K_NN || k == K_E || k == K_MN || k == K_MNN) { imm = &o[j]; ik = k; }
}
len = pf == 0 ? 1 : pf >= 5 ? 4 : 2;
if (dsp && pf < 5) len++;
if (imm) len += ik == K_NN || ik == K_MNN ? 2 : 1;
if (dsp && (i16)dsp->val != (int8_t)dsp->val) a_fail("OFFSET OUT OF RANGE");
if (imm && (ik == K_N || ik == K_MN) && imm->val > 255 && imm->val < 0xFF80) a_fail("VALUE OVER 255");
switch (pf) {
case 1: a_emit(0xCB); break;
case 2: a_emit(0xED); break;
case 3: a_emit(0xDD); break;
case 4: a_emit(0xFD); break;
case 5: a_emit(0xDD); a_emit(0xCB); a_emit(dsp->val); break;
case 6: a_emit(0xFD); a_emit(0xCB); a_emit(dsp->val); break;
}
a_emit(op);
if (dsp && pf < 5) a_emit(dsp->val);
if (imm) {
u16 v = imm->val;
if (ik == K_E) {
i16 d = (i16)(v - (a_pc + 1));
if (a_pass == 2 && (d < -128 || d > 127)) a_fail("JUMP TOO FAR");
a_emit(d);
} else {
a_emit(v);
if (ik == K_NN || ik == K_MNN) a_emit(v >> 8);
}
}
(void)len;
}
/* the operands at ap, split at commas outside brackets and quotes */
static u8 a_split(struct opnd *o)
{
u8 n = 0;
a_sp();
while (*ap && n < 3) {
const char *s = ap;
u8 d = 0, q = 0, len;
while (*ap && (d || q || *ap != ',')) {
if (*ap == '\'' && !q && ap[1] && ap[2] == '\'') ap += 2;
else if (*ap == '"') q = !q;
else if (*ap == '(') d++;
else if (*ap == ')' && d) d--;
ap++;
}
len = ap - s;
while (len && (s[len - 1] == ' ' || s[len - 1] == '\t')) len--;
if (n < 2) {
const char *keep = ap;
a_operand(s, len, &o[n]);
ap = keep;
}
n++;
if (*ap == ',') { ap++; a_sp(); }
}
return n;
}
/* DB/DW items: numbers and strings */
static void a_data(u8 words)
{
for (;;) {
a_sp();
if (*ap == '"' && !words) {
ap++;
while (*ap && *ap != '"') a_emit(*ap++);
if (*ap) ap++;
} else {
u16 v = a_expr();
a_emit(v);
if (words) a_emit(v >> 8);
}
a_sp();
if (*ap != ',') break;
ap++;
}
if (*ap) a_fail("BAD DATA");
}
/* Assemble one source line (uppercase except in quotes). */
static void a_line(char *s)
{
char w[8], lab[8];
struct opnd o[2];
u8 m, n, has_lab = 0;
char *c;
u8 q = 0;
a_err = 0;
/* cut the comment */
for (c = s; *c; c++) {
if (*c == '"') q = !q;
else if (*c == '\'' && !q && c[1] && c[2] == '\'') c += 2;
else if (*c == ';' && !q) { *c = 0; break; }
}
ap = s;
a_sp();
if (*ap >= '0' && *ap <= '9') { /* a BASIC line number */
const char *t = ap;
while (*t >= '0' && *t <= '9') t++;
if (*t == ' ' || !*t) ap = t;
}
a_sp();
if (!*ap) return;
if (!a_alpha(*ap)) { a_fail("SYNTAX ERROR"); return; }
a_name(w);
a_sp();
if (*ap == ':') { /* LABEL: */
ap++;
memcpy(lab, w, 8); has_lab = 1;
a_sp();
if (!*ap) { sym_def(lab, a_pc); return; }
if (!a_alpha(*ap)) { a_fail("SYNTAX ERROR"); return; }
a_name(w);
a_sp();
} else if (!strncmp(ap, "EQU", 3) && !a_alnum(ap[3])) {
memcpy(lab, w, 8); has_lab = 1;
memcpy(w, "EQU\0\0\0\0\0", 8);
ap += 3;
}
if (!strncmp(w, "EQU", 8)) {
u16 v = a_expr();
if (!has_lab) a_fail("EQU NEEDS A NAME");
else if (a_undef && a_pass == 1) a_fail("EQU BEFORE ITS VALUE");
else sym_def(lab, v);
return;
}
if (has_lab) sym_def(lab, a_pc);
if (!strncmp(w, "ORG", 8)) { a_pc = a_expr(); return; }
if (!strncmp(w, "END", 8)) { a_end = 1; return; }
if (!strncmp(w, "DB", 8) || !strncmp(w, "DEFB", 8) || !strncmp(w, "DEFM", 8)) { a_data(0); return; }
if (!strncmp(w, "DW", 8) || !strncmp(w, "DEFW", 8)) { a_data(1); return; }
if (!strncmp(w, "DS", 8) || !strncmp(w, "DEFS", 8)) { a_pc += a_expr(); return; }
for (m = 0; m < ASM_MN; m++)
if (!strncmp(w, asm_mn[m], 8) && strlen(asm_mn[m]) <= 8) break;
if (m == ASM_MN) { a_fail("UNKNOWN INSTRUCTION"); return; }
memset(o, 0, sizeof o);
n = a_split(o);
if (a_err) return;
if (n > 2) { a_fail("TOO MANY OPERANDS"); return; }
/* SUB A,n and friends: the A is optional */
if (n == 2 && o[0].cls == OC_FIXED && !strcmp(asm_kn[o[0].kind], "A") &&
(!strcmp(asm_mn[m], "SUB") || !strcmp(asm_mn[m], "AND") || !strcmp(asm_mn[m], "XOR") ||
!strcmp(asm_mn[m], "OR") || !strcmp(asm_mn[m], "CP"))) {
o[0] = o[1]; n = 1;
}
a_instr(m, o, n);
}
/* Upper-case a source line outside quotes, in place. */
static void a_upper(char *s)
{
u8 q = 0;
for (; *s; s++) {
if (*s == '"') q = !q;
else if (*s == '\'' && !q && s[1] && s[2] == '\'') s += 2;
else if (!q && *s >= 'a' && *s <= 'z') *s -= 32;
if (*s == '\t') *s = ' ';
}
}
+173
View File
@@ -0,0 +1,173 @@
/* Generated by tools/gen-asmtab.py from the disassembler: do not edit. */
/* {mnemonic, operand 1, operand 2, prefix, opcode}; operand 0x80|v is the
literal number v; prefix 0 none, 1 CB, 2 ED, 3 DD, 4 FD, 5 DDCB, 6 FDCB */
#define ASM_MN 68
static const char *const asm_mn[] = {
"NOP", "LD", "INC", "DEC", "RLCA", "EX", "ADD", "RRCA", "DJNZ", "RLA", "JR", "RRA", "DAA", "CPL", "SCF", "CCF", "HALT", "ADC", "SUB", "SBC", "AND", "XOR", "OR", "CP", "RET", "POP", "JP", "CALL", "PUSH", "RST", "RL", "OUT", "EXX", "IN", "DI", "EI", "RLC", "RRC", "RR", "SLA", "SRA", "SLL", "SRL", "BIT", "RES", "SET", "NEG", "RETN", "IM", "RETI", "RRD", "RLD", "LDI", "CPI", "INI", "OUTI", "LDD", "CPD", "IND", "OUTD", "LDIR", "CPIR", "INIR", "OTIR", "LDDR", "CPDR", "INDR", "OTDR"
};
#define ASM_KN 43
static const char *const asm_kn[] = {
"", "BC", "nn", "(BC)", "A", "B", "n", "AF", "AF'", "HL", "C", "e", "DE", "(DE)", "D", "E", "NZ", "(nn)", "H", "Z", "L", "NC", "SP", "(HL)", "(n)", "PO", "(SP)", "PE", "P", "M", "(C)", "I", "R", "IX", "IXH", "IXL", "(IX+d)", "(IX)", "IY", "IYH", "IYL", "(IY+d)", "(IY)"
};
#define K_N 6
#define K_NN 2
#define K_E 11
#define K_MN 24
#define K_MNN 17
#define K_IXD 36
#define K_IYD 41
#define ASM_N 912
static const u8 asm_tab[][5] = {
{0,0,0,0,0x00}, {1,1,2,0,0x01}, {1,3,4,0,0x02}, {2,1,0,0,0x03}, {2,5,0,0,0x04}, {3,5,0,0,0x05},
{1,5,6,0,0x06}, {4,0,0,0,0x07}, {5,7,8,0,0x08}, {6,9,1,0,0x09}, {1,4,3,0,0x0A}, {3,1,0,0,0x0B},
{2,10,0,0,0x0C}, {3,10,0,0,0x0D}, {1,10,6,0,0x0E}, {7,0,0,0,0x0F}, {8,11,0,0,0x10}, {1,12,2,0,0x11},
{1,13,4,0,0x12}, {2,12,0,0,0x13}, {2,14,0,0,0x14}, {3,14,0,0,0x15}, {1,14,6,0,0x16}, {9,0,0,0,0x17},
{10,11,0,0,0x18}, {6,9,12,0,0x19}, {1,4,13,0,0x1A}, {3,12,0,0,0x1B}, {2,15,0,0,0x1C}, {3,15,0,0,0x1D},
{1,15,6,0,0x1E}, {11,0,0,0,0x1F}, {10,16,11,0,0x20}, {1,9,2,0,0x21}, {1,17,9,0,0x22}, {2,9,0,0,0x23},
{2,18,0,0,0x24}, {3,18,0,0,0x25}, {1,18,6,0,0x26}, {12,0,0,0,0x27}, {10,19,11,0,0x28}, {6,9,9,0,0x29},
{1,9,17,0,0x2A}, {3,9,0,0,0x2B}, {2,20,0,0,0x2C}, {3,20,0,0,0x2D}, {1,20,6,0,0x2E}, {13,0,0,0,0x2F},
{10,21,11,0,0x30}, {1,22,2,0,0x31}, {1,17,4,0,0x32}, {2,22,0,0,0x33}, {2,23,0,0,0x34}, {3,23,0,0,0x35},
{1,23,6,0,0x36}, {14,0,0,0,0x37}, {10,10,11,0,0x38}, {6,9,22,0,0x39}, {1,4,17,0,0x3A}, {3,22,0,0,0x3B},
{2,4,0,0,0x3C}, {3,4,0,0,0x3D}, {1,4,6,0,0x3E}, {15,0,0,0,0x3F}, {1,5,5,0,0x40}, {1,5,10,0,0x41},
{1,5,14,0,0x42}, {1,5,15,0,0x43}, {1,5,18,0,0x44}, {1,5,20,0,0x45}, {1,5,23,0,0x46}, {1,5,4,0,0x47},
{1,10,5,0,0x48}, {1,10,10,0,0x49}, {1,10,14,0,0x4A}, {1,10,15,0,0x4B}, {1,10,18,0,0x4C}, {1,10,20,0,0x4D},
{1,10,23,0,0x4E}, {1,10,4,0,0x4F}, {1,14,5,0,0x50}, {1,14,10,0,0x51}, {1,14,14,0,0x52}, {1,14,15,0,0x53},
{1,14,18,0,0x54}, {1,14,20,0,0x55}, {1,14,23,0,0x56}, {1,14,4,0,0x57}, {1,15,5,0,0x58}, {1,15,10,0,0x59},
{1,15,14,0,0x5A}, {1,15,15,0,0x5B}, {1,15,18,0,0x5C}, {1,15,20,0,0x5D}, {1,15,23,0,0x5E}, {1,15,4,0,0x5F},
{1,18,5,0,0x60}, {1,18,10,0,0x61}, {1,18,14,0,0x62}, {1,18,15,0,0x63}, {1,18,18,0,0x64}, {1,18,20,0,0x65},
{1,18,23,0,0x66}, {1,18,4,0,0x67}, {1,20,5,0,0x68}, {1,20,10,0,0x69}, {1,20,14,0,0x6A}, {1,20,15,0,0x6B},
{1,20,18,0,0x6C}, {1,20,20,0,0x6D}, {1,20,23,0,0x6E}, {1,20,4,0,0x6F}, {1,23,5,0,0x70}, {1,23,10,0,0x71},
{1,23,14,0,0x72}, {1,23,15,0,0x73}, {1,23,18,0,0x74}, {1,23,20,0,0x75}, {16,0,0,0,0x76}, {1,23,4,0,0x77},
{1,4,5,0,0x78}, {1,4,10,0,0x79}, {1,4,14,0,0x7A}, {1,4,15,0,0x7B}, {1,4,18,0,0x7C}, {1,4,20,0,0x7D},
{1,4,23,0,0x7E}, {1,4,4,0,0x7F}, {6,4,5,0,0x80}, {6,4,10,0,0x81}, {6,4,14,0,0x82}, {6,4,15,0,0x83},
{6,4,18,0,0x84}, {6,4,20,0,0x85}, {6,4,23,0,0x86}, {6,4,4,0,0x87}, {17,4,5,0,0x88}, {17,4,10,0,0x89},
{17,4,14,0,0x8A}, {17,4,15,0,0x8B}, {17,4,18,0,0x8C}, {17,4,20,0,0x8D}, {17,4,23,0,0x8E}, {17,4,4,0,0x8F},
{18,5,0,0,0x90}, {18,10,0,0,0x91}, {18,14,0,0,0x92}, {18,15,0,0,0x93}, {18,18,0,0,0x94}, {18,20,0,0,0x95},
{18,23,0,0,0x96}, {18,4,0,0,0x97}, {19,4,5,0,0x98}, {19,4,10,0,0x99}, {19,4,14,0,0x9A}, {19,4,15,0,0x9B},
{19,4,18,0,0x9C}, {19,4,20,0,0x9D}, {19,4,23,0,0x9E}, {19,4,4,0,0x9F}, {20,5,0,0,0xA0}, {20,10,0,0,0xA1},
{20,14,0,0,0xA2}, {20,15,0,0,0xA3}, {20,18,0,0,0xA4}, {20,20,0,0,0xA5}, {20,23,0,0,0xA6}, {20,4,0,0,0xA7},
{21,5,0,0,0xA8}, {21,10,0,0,0xA9}, {21,14,0,0,0xAA}, {21,15,0,0,0xAB}, {21,18,0,0,0xAC}, {21,20,0,0,0xAD},
{21,23,0,0,0xAE}, {21,4,0,0,0xAF}, {22,5,0,0,0xB0}, {22,10,0,0,0xB1}, {22,14,0,0,0xB2}, {22,15,0,0,0xB3},
{22,18,0,0,0xB4}, {22,20,0,0,0xB5}, {22,23,0,0,0xB6}, {22,4,0,0,0xB7}, {23,5,0,0,0xB8}, {23,10,0,0,0xB9},
{23,14,0,0,0xBA}, {23,15,0,0,0xBB}, {23,18,0,0,0xBC}, {23,20,0,0,0xBD}, {23,23,0,0,0xBE}, {23,4,0,0,0xBF},
{24,16,0,0,0xC0}, {25,1,0,0,0xC1}, {26,16,2,0,0xC2}, {26,2,0,0,0xC3}, {27,16,2,0,0xC4}, {28,1,0,0,0xC5},
{6,4,6,0,0xC6}, {29,128,0,0,0xC7}, {24,19,0,0,0xC8}, {24,0,0,0,0xC9}, {26,19,2,0,0xCA}, {30,14,0,1,0x12},
{27,19,2,0,0xCC}, {27,2,0,0,0xCD}, {17,4,6,0,0xCE}, {29,136,0,0,0xCF}, {24,21,0,0,0xD0}, {25,12,0,0,0xD1},
{26,21,2,0,0xD2}, {31,24,4,0,0xD3}, {27,21,2,0,0xD4}, {28,12,0,0,0xD5}, {18,6,0,0,0xD6}, {29,144,0,0,0xD7},
{24,10,0,0,0xD8}, {32,0,0,0,0xD9}, {26,10,2,0,0xDA}, {33,4,24,0,0xDB}, {27,10,2,0,0xDC}, {19,4,6,0,0xDE},
{29,152,0,0,0xDF}, {24,25,0,0,0xE0}, {25,9,0,0,0xE1}, {26,25,2,0,0xE2}, {5,26,9,0,0xE3}, {27,25,2,0,0xE4},
{28,9,0,0,0xE5}, {20,6,0,0,0xE6}, {29,160,0,0,0xE7}, {24,27,0,0,0xE8}, {26,23,0,0,0xE9}, {26,27,2,0,0xEA},
{5,12,9,0,0xEB}, {27,27,2,0,0xEC}, {21,6,0,0,0xEE}, {29,168,0,0,0xEF}, {24,28,0,0,0xF0}, {25,7,0,0,0xF1},
{26,28,2,0,0xF2}, {34,0,0,0,0xF3}, {27,28,2,0,0xF4}, {28,7,0,0,0xF5}, {22,6,0,0,0xF6}, {29,176,0,0,0xF7},
{24,29,0,0,0xF8}, {1,22,9,0,0xF9}, {26,29,2,0,0xFA}, {35,0,0,0,0xFB}, {27,29,2,0,0xFC}, {23,6,0,0,0xFE},
{29,184,0,0,0xFF}, {36,5,0,1,0x00}, {36,10,0,1,0x01}, {36,14,0,1,0x02}, {36,15,0,1,0x03}, {36,18,0,1,0x04},
{36,20,0,1,0x05}, {36,23,0,1,0x06}, {36,4,0,1,0x07}, {37,5,0,1,0x08}, {37,10,0,1,0x09}, {37,14,0,1,0x0A},
{37,15,0,1,0x0B}, {37,18,0,1,0x0C}, {37,20,0,1,0x0D}, {37,23,0,1,0x0E}, {37,4,0,1,0x0F}, {30,5,0,1,0x10},
{30,10,0,1,0x11}, {30,15,0,1,0x13}, {30,18,0,1,0x14}, {30,20,0,1,0x15}, {30,23,0,1,0x16}, {30,4,0,1,0x17},
{38,5,0,1,0x18}, {38,10,0,1,0x19}, {38,14,0,1,0x1A}, {38,15,0,1,0x1B}, {38,18,0,1,0x1C}, {38,20,0,1,0x1D},
{38,23,0,1,0x1E}, {38,4,0,1,0x1F}, {39,5,0,1,0x20}, {39,10,0,1,0x21}, {39,14,0,1,0x22}, {39,15,0,1,0x23},
{39,18,0,1,0x24}, {39,20,0,1,0x25}, {39,23,0,1,0x26}, {39,4,0,1,0x27}, {40,5,0,1,0x28}, {40,10,0,1,0x29},
{40,14,0,1,0x2A}, {40,15,0,1,0x2B}, {40,18,0,1,0x2C}, {40,20,0,1,0x2D}, {40,23,0,1,0x2E}, {40,4,0,1,0x2F},
{41,5,0,1,0x30}, {41,10,0,1,0x31}, {41,14,0,1,0x32}, {41,15,0,1,0x33}, {41,18,0,1,0x34}, {41,20,0,1,0x35},
{41,23,0,1,0x36}, {41,4,0,1,0x37}, {42,5,0,1,0x38}, {42,10,0,1,0x39}, {42,14,0,1,0x3A}, {42,15,0,1,0x3B},
{42,18,0,1,0x3C}, {42,20,0,1,0x3D}, {42,23,0,1,0x3E}, {42,4,0,1,0x3F}, {43,128,5,1,0x40}, {43,128,10,1,0x41},
{43,128,14,1,0x42}, {43,128,15,1,0x43}, {43,128,18,1,0x44}, {43,128,20,1,0x45}, {43,128,23,1,0x46}, {43,128,4,1,0x47},
{43,129,5,1,0x48}, {43,129,10,1,0x49}, {43,129,14,1,0x4A}, {43,129,15,1,0x4B}, {43,129,18,1,0x4C}, {43,129,20,1,0x4D},
{43,129,23,1,0x4E}, {43,129,4,1,0x4F}, {43,130,5,1,0x50}, {43,130,10,1,0x51}, {43,130,14,1,0x52}, {43,130,15,1,0x53},
{43,130,18,1,0x54}, {43,130,20,1,0x55}, {43,130,23,1,0x56}, {43,130,4,1,0x57}, {43,131,5,1,0x58}, {43,131,10,1,0x59},
{43,131,14,1,0x5A}, {43,131,15,1,0x5B}, {43,131,18,1,0x5C}, {43,131,20,1,0x5D}, {43,131,23,1,0x5E}, {43,131,4,1,0x5F},
{43,132,5,1,0x60}, {43,132,10,1,0x61}, {43,132,14,1,0x62}, {43,132,15,1,0x63}, {43,132,18,1,0x64}, {43,132,20,1,0x65},
{43,132,23,1,0x66}, {43,132,4,1,0x67}, {43,133,5,1,0x68}, {43,133,10,1,0x69}, {43,133,14,1,0x6A}, {43,133,15,1,0x6B},
{43,133,18,1,0x6C}, {43,133,20,1,0x6D}, {43,133,23,1,0x6E}, {43,133,4,1,0x6F}, {43,134,5,1,0x70}, {43,134,10,1,0x71},
{43,134,14,1,0x72}, {43,134,15,1,0x73}, {43,134,18,1,0x74}, {43,134,20,1,0x75}, {43,134,23,1,0x76}, {43,134,4,1,0x77},
{43,135,5,1,0x78}, {43,135,10,1,0x79}, {43,135,14,1,0x7A}, {43,135,15,1,0x7B}, {43,135,18,1,0x7C}, {43,135,20,1,0x7D},
{43,135,23,1,0x7E}, {43,135,4,1,0x7F}, {44,128,5,1,0x80}, {44,128,10,1,0x81}, {44,128,14,1,0x82}, {44,128,15,1,0x83},
{44,128,18,1,0x84}, {44,128,20,1,0x85}, {44,128,23,1,0x86}, {44,128,4,1,0x87}, {44,129,5,1,0x88}, {44,129,10,1,0x89},
{44,129,14,1,0x8A}, {44,129,15,1,0x8B}, {44,129,18,1,0x8C}, {44,129,20,1,0x8D}, {44,129,23,1,0x8E}, {44,129,4,1,0x8F},
{44,130,5,1,0x90}, {44,130,10,1,0x91}, {44,130,14,1,0x92}, {44,130,15,1,0x93}, {44,130,18,1,0x94}, {44,130,20,1,0x95},
{44,130,23,1,0x96}, {44,130,4,1,0x97}, {44,131,5,1,0x98}, {44,131,10,1,0x99}, {44,131,14,1,0x9A}, {44,131,15,1,0x9B},
{44,131,18,1,0x9C}, {44,131,20,1,0x9D}, {44,131,23,1,0x9E}, {44,131,4,1,0x9F}, {44,132,5,1,0xA0}, {44,132,10,1,0xA1},
{44,132,14,1,0xA2}, {44,132,15,1,0xA3}, {44,132,18,1,0xA4}, {44,132,20,1,0xA5}, {44,132,23,1,0xA6}, {44,132,4,1,0xA7},
{44,133,5,1,0xA8}, {44,133,10,1,0xA9}, {44,133,14,1,0xAA}, {44,133,15,1,0xAB}, {44,133,18,1,0xAC}, {44,133,20,1,0xAD},
{44,133,23,1,0xAE}, {44,133,4,1,0xAF}, {44,134,5,1,0xB0}, {44,134,10,1,0xB1}, {44,134,14,1,0xB2}, {44,134,15,1,0xB3},
{44,134,18,1,0xB4}, {44,134,20,1,0xB5}, {44,134,23,1,0xB6}, {44,134,4,1,0xB7}, {44,135,5,1,0xB8}, {44,135,10,1,0xB9},
{44,135,14,1,0xBA}, {44,135,15,1,0xBB}, {44,135,18,1,0xBC}, {44,135,20,1,0xBD}, {44,135,23,1,0xBE}, {44,135,4,1,0xBF},
{45,128,5,1,0xC0}, {45,128,10,1,0xC1}, {45,128,14,1,0xC2}, {45,128,15,1,0xC3}, {45,128,18,1,0xC4}, {45,128,20,1,0xC5},
{45,128,23,1,0xC6}, {45,128,4,1,0xC7}, {45,129,5,1,0xC8}, {45,129,10,1,0xC9}, {45,129,14,1,0xCA}, {45,129,15,1,0xCB},
{45,129,18,1,0xCC}, {45,129,20,1,0xCD}, {45,129,23,1,0xCE}, {45,129,4,1,0xCF}, {45,130,5,1,0xD0}, {45,130,10,1,0xD1},
{45,130,14,1,0xD2}, {45,130,15,1,0xD3}, {45,130,18,1,0xD4}, {45,130,20,1,0xD5}, {45,130,23,1,0xD6}, {45,130,4,1,0xD7},
{45,131,5,1,0xD8}, {45,131,10,1,0xD9}, {45,131,14,1,0xDA}, {45,131,15,1,0xDB}, {45,131,18,1,0xDC}, {45,131,20,1,0xDD},
{45,131,23,1,0xDE}, {45,131,4,1,0xDF}, {45,132,5,1,0xE0}, {45,132,10,1,0xE1}, {45,132,14,1,0xE2}, {45,132,15,1,0xE3},
{45,132,18,1,0xE4}, {45,132,20,1,0xE5}, {45,132,23,1,0xE6}, {45,132,4,1,0xE7}, {45,133,5,1,0xE8}, {45,133,10,1,0xE9},
{45,133,14,1,0xEA}, {45,133,15,1,0xEB}, {45,133,18,1,0xEC}, {45,133,20,1,0xED}, {45,133,23,1,0xEE}, {45,133,4,1,0xEF},
{45,134,5,1,0xF0}, {45,134,10,1,0xF1}, {45,134,14,1,0xF2}, {45,134,15,1,0xF3}, {45,134,18,1,0xF4}, {45,134,20,1,0xF5},
{45,134,23,1,0xF6}, {45,134,4,1,0xF7}, {45,135,5,1,0xF8}, {45,135,10,1,0xF9}, {45,135,14,1,0xFA}, {45,135,15,1,0xFB},
{45,135,18,1,0xFC}, {45,135,20,1,0xFD}, {45,135,23,1,0xFE}, {45,135,4,1,0xFF}, {33,5,30,2,0x40}, {31,30,5,2,0x41},
{19,9,1,2,0x42}, {1,17,1,2,0x43}, {46,0,0,2,0x44}, {47,0,0,2,0x45}, {48,128,0,2,0x46}, {1,31,4,2,0x47},
{33,10,30,2,0x48}, {31,30,10,2,0x49}, {17,9,1,2,0x4A}, {1,1,17,2,0x4B}, {49,0,0,2,0x4D}, {1,32,4,2,0x4F},
{33,14,30,2,0x50}, {31,30,14,2,0x51}, {19,9,12,2,0x52}, {1,17,12,2,0x53}, {48,129,0,2,0x56}, {1,4,31,2,0x57},
{33,15,30,2,0x58}, {31,30,15,2,0x59}, {17,9,12,2,0x5A}, {1,12,17,2,0x5B}, {48,130,0,2,0x5E}, {1,4,32,2,0x5F},
{33,18,30,2,0x60}, {31,30,18,2,0x61}, {19,9,9,2,0x62}, {50,0,0,2,0x67}, {33,20,30,2,0x68}, {31,30,20,2,0x69},
{17,9,9,2,0x6A}, {51,0,0,2,0x6F}, {33,30,0,2,0x70}, {31,30,128,2,0x71}, {19,9,22,2,0x72}, {1,17,22,2,0x73},
{33,4,30,2,0x78}, {31,30,4,2,0x79}, {17,9,22,2,0x7A}, {1,22,17,2,0x7B}, {52,0,0,2,0xA0}, {53,0,0,2,0xA1},
{54,0,0,2,0xA2}, {55,0,0,2,0xA3}, {56,0,0,2,0xA8}, {57,0,0,2,0xA9}, {58,0,0,2,0xAA}, {59,0,0,2,0xAB},
{60,0,0,2,0xB0}, {61,0,0,2,0xB1}, {62,0,0,2,0xB2}, {63,0,0,2,0xB3}, {64,0,0,2,0xB8}, {65,0,0,2,0xB9},
{66,0,0,2,0xBA}, {67,0,0,2,0xBB}, {6,33,1,3,0x09}, {6,33,12,3,0x19}, {1,33,2,3,0x21}, {1,17,33,3,0x22},
{2,33,0,3,0x23}, {2,34,0,3,0x24}, {3,34,0,3,0x25}, {1,34,6,3,0x26}, {6,33,33,3,0x29}, {1,33,17,3,0x2A},
{3,33,0,3,0x2B}, {2,35,0,3,0x2C}, {3,35,0,3,0x2D}, {1,35,6,3,0x2E}, {2,36,0,3,0x34}, {3,36,0,3,0x35},
{1,36,6,3,0x36}, {6,33,22,3,0x39}, {1,5,34,3,0x44}, {1,5,35,3,0x45}, {1,5,36,3,0x46}, {1,10,34,3,0x4C},
{1,10,35,3,0x4D}, {1,10,36,3,0x4E}, {1,14,34,3,0x54}, {1,14,35,3,0x55}, {1,14,36,3,0x56}, {1,15,34,3,0x5C},
{1,15,35,3,0x5D}, {1,15,36,3,0x5E}, {1,34,5,3,0x60}, {1,34,10,3,0x61}, {1,34,14,3,0x62}, {1,34,15,3,0x63},
{1,34,34,3,0x64}, {1,34,35,3,0x65}, {1,18,36,3,0x66}, {1,34,4,3,0x67}, {1,35,5,3,0x68}, {1,35,10,3,0x69},
{1,35,14,3,0x6A}, {1,35,15,3,0x6B}, {1,35,34,3,0x6C}, {1,35,35,3,0x6D}, {1,20,36,3,0x6E}, {1,35,4,3,0x6F},
{1,36,5,3,0x70}, {1,36,10,3,0x71}, {1,36,14,3,0x72}, {1,36,15,3,0x73}, {1,36,18,3,0x74}, {1,36,20,3,0x75},
{1,36,4,3,0x77}, {1,4,34,3,0x7C}, {1,4,35,3,0x7D}, {1,4,36,3,0x7E}, {6,4,34,3,0x84}, {6,4,35,3,0x85},
{6,4,36,3,0x86}, {17,4,34,3,0x8C}, {17,4,35,3,0x8D}, {17,4,36,3,0x8E}, {18,34,0,3,0x94}, {18,35,0,3,0x95},
{18,36,0,3,0x96}, {19,4,34,3,0x9C}, {19,4,35,3,0x9D}, {19,4,36,3,0x9E}, {20,34,0,3,0xA4}, {20,35,0,3,0xA5},
{20,36,0,3,0xA6}, {21,34,0,3,0xAC}, {21,35,0,3,0xAD}, {21,36,0,3,0xAE}, {22,34,0,3,0xB4}, {22,35,0,3,0xB5},
{22,36,0,3,0xB6}, {23,34,0,3,0xBC}, {23,35,0,3,0xBD}, {23,36,0,3,0xBE}, {25,33,0,3,0xE1}, {5,26,33,3,0xE3},
{28,33,0,3,0xE5}, {26,37,0,3,0xE9}, {1,22,33,3,0xF9}, {6,38,1,4,0x09}, {6,38,12,4,0x19}, {1,38,2,4,0x21},
{1,17,38,4,0x22}, {2,38,0,4,0x23}, {2,39,0,4,0x24}, {3,39,0,4,0x25}, {1,39,6,4,0x26}, {6,38,38,4,0x29},
{1,38,17,4,0x2A}, {3,38,0,4,0x2B}, {2,40,0,4,0x2C}, {3,40,0,4,0x2D}, {1,40,6,4,0x2E}, {2,41,0,4,0x34},
{3,41,0,4,0x35}, {1,41,6,4,0x36}, {6,38,22,4,0x39}, {1,5,39,4,0x44}, {1,5,40,4,0x45}, {1,5,41,4,0x46},
{1,10,39,4,0x4C}, {1,10,40,4,0x4D}, {1,10,41,4,0x4E}, {1,14,39,4,0x54}, {1,14,40,4,0x55}, {1,14,41,4,0x56},
{1,15,39,4,0x5C}, {1,15,40,4,0x5D}, {1,15,41,4,0x5E}, {1,39,5,4,0x60}, {1,39,10,4,0x61}, {1,39,14,4,0x62},
{1,39,15,4,0x63}, {1,39,39,4,0x64}, {1,39,40,4,0x65}, {1,18,41,4,0x66}, {1,39,4,4,0x67}, {1,40,5,4,0x68},
{1,40,10,4,0x69}, {1,40,14,4,0x6A}, {1,40,15,4,0x6B}, {1,40,39,4,0x6C}, {1,40,40,4,0x6D}, {1,20,41,4,0x6E},
{1,40,4,4,0x6F}, {1,41,5,4,0x70}, {1,41,10,4,0x71}, {1,41,14,4,0x72}, {1,41,15,4,0x73}, {1,41,18,4,0x74},
{1,41,20,4,0x75}, {1,41,4,4,0x77}, {1,4,39,4,0x7C}, {1,4,40,4,0x7D}, {1,4,41,4,0x7E}, {6,4,39,4,0x84},
{6,4,40,4,0x85}, {6,4,41,4,0x86}, {17,4,39,4,0x8C}, {17,4,40,4,0x8D}, {17,4,41,4,0x8E}, {18,39,0,4,0x94},
{18,40,0,4,0x95}, {18,41,0,4,0x96}, {19,4,39,4,0x9C}, {19,4,40,4,0x9D}, {19,4,41,4,0x9E}, {20,39,0,4,0xA4},
{20,40,0,4,0xA5}, {20,41,0,4,0xA6}, {21,39,0,4,0xAC}, {21,40,0,4,0xAD}, {21,41,0,4,0xAE}, {22,39,0,4,0xB4},
{22,40,0,4,0xB5}, {22,41,0,4,0xB6}, {23,39,0,4,0xBC}, {23,40,0,4,0xBD}, {23,41,0,4,0xBE}, {25,38,0,4,0xE1},
{5,26,38,4,0xE3}, {28,38,0,4,0xE5}, {26,42,0,4,0xE9}, {1,22,38,4,0xF9}, {36,36,5,5,0x00}, {36,36,10,5,0x01},
{36,36,14,5,0x02}, {36,36,15,5,0x03}, {36,36,18,5,0x04}, {36,36,20,5,0x05}, {36,36,0,5,0x06}, {36,36,4,5,0x07},
{37,36,5,5,0x08}, {37,36,10,5,0x09}, {37,36,14,5,0x0A}, {37,36,15,5,0x0B}, {37,36,18,5,0x0C}, {37,36,20,5,0x0D},
{37,36,0,5,0x0E}, {37,36,4,5,0x0F}, {30,36,5,5,0x10}, {30,36,10,5,0x11}, {30,36,14,5,0x12}, {30,36,15,5,0x13},
{30,36,18,5,0x14}, {30,36,20,5,0x15}, {30,36,0,5,0x16}, {30,36,4,5,0x17}, {38,36,5,5,0x18}, {38,36,10,5,0x19},
{38,36,14,5,0x1A}, {38,36,15,5,0x1B}, {38,36,18,5,0x1C}, {38,36,20,5,0x1D}, {38,36,0,5,0x1E}, {38,36,4,5,0x1F},
{39,36,5,5,0x20}, {39,36,10,5,0x21}, {39,36,14,5,0x22}, {39,36,15,5,0x23}, {39,36,18,5,0x24}, {39,36,20,5,0x25},
{39,36,0,5,0x26}, {39,36,4,5,0x27}, {40,36,5,5,0x28}, {40,36,10,5,0x29}, {40,36,14,5,0x2A}, {40,36,15,5,0x2B},
{40,36,18,5,0x2C}, {40,36,20,5,0x2D}, {40,36,0,5,0x2E}, {40,36,4,5,0x2F}, {41,36,5,5,0x30}, {41,36,10,5,0x31},
{41,36,14,5,0x32}, {41,36,15,5,0x33}, {41,36,18,5,0x34}, {41,36,20,5,0x35}, {41,36,0,5,0x36}, {41,36,4,5,0x37},
{42,36,5,5,0x38}, {42,36,10,5,0x39}, {42,36,14,5,0x3A}, {42,36,15,5,0x3B}, {42,36,18,5,0x3C}, {42,36,20,5,0x3D},
{42,36,0,5,0x3E}, {42,36,4,5,0x3F}, {43,128,36,5,0x40}, {43,129,36,5,0x48}, {43,130,36,5,0x50}, {43,131,36,5,0x58},
{43,132,36,5,0x60}, {43,133,36,5,0x68}, {43,134,36,5,0x70}, {43,135,36,5,0x78}, {44,128,36,5,0x86}, {44,129,36,5,0x8E},
{44,130,36,5,0x96}, {44,131,36,5,0x9E}, {44,132,36,5,0xA6}, {44,133,36,5,0xAE}, {44,134,36,5,0xB6}, {44,135,36,5,0xBE},
{45,128,36,5,0xC6}, {45,129,36,5,0xCE}, {45,130,36,5,0xD6}, {45,131,36,5,0xDE}, {45,132,36,5,0xE6}, {45,133,36,5,0xEE},
{45,134,36,5,0xF6}, {45,135,36,5,0xFE}, {36,41,5,6,0x00}, {36,41,10,6,0x01}, {36,41,14,6,0x02}, {36,41,15,6,0x03},
{36,41,18,6,0x04}, {36,41,20,6,0x05}, {36,41,0,6,0x06}, {36,41,4,6,0x07}, {37,41,5,6,0x08}, {37,41,10,6,0x09},
{37,41,14,6,0x0A}, {37,41,15,6,0x0B}, {37,41,18,6,0x0C}, {37,41,20,6,0x0D}, {37,41,0,6,0x0E}, {37,41,4,6,0x0F},
{30,41,5,6,0x10}, {30,41,10,6,0x11}, {30,41,14,6,0x12}, {30,41,15,6,0x13}, {30,41,18,6,0x14}, {30,41,20,6,0x15},
{30,41,0,6,0x16}, {30,41,4,6,0x17}, {38,41,5,6,0x18}, {38,41,10,6,0x19}, {38,41,14,6,0x1A}, {38,41,15,6,0x1B},
{38,41,18,6,0x1C}, {38,41,20,6,0x1D}, {38,41,0,6,0x1E}, {38,41,4,6,0x1F}, {39,41,5,6,0x20}, {39,41,10,6,0x21},
{39,41,14,6,0x22}, {39,41,15,6,0x23}, {39,41,18,6,0x24}, {39,41,20,6,0x25}, {39,41,0,6,0x26}, {39,41,4,6,0x27},
{40,41,5,6,0x28}, {40,41,10,6,0x29}, {40,41,14,6,0x2A}, {40,41,15,6,0x2B}, {40,41,18,6,0x2C}, {40,41,20,6,0x2D},
{40,41,0,6,0x2E}, {40,41,4,6,0x2F}, {41,41,5,6,0x30}, {41,41,10,6,0x31}, {41,41,14,6,0x32}, {41,41,15,6,0x33},
{41,41,18,6,0x34}, {41,41,20,6,0x35}, {41,41,0,6,0x36}, {41,41,4,6,0x37}, {42,41,5,6,0x38}, {42,41,10,6,0x39},
{42,41,14,6,0x3A}, {42,41,15,6,0x3B}, {42,41,18,6,0x3C}, {42,41,20,6,0x3D}, {42,41,0,6,0x3E}, {42,41,4,6,0x3F},
{43,128,41,6,0x40}, {43,129,41,6,0x48}, {43,130,41,6,0x50}, {43,131,41,6,0x58}, {43,132,41,6,0x60}, {43,133,41,6,0x68},
{43,134,41,6,0x70}, {43,135,41,6,0x78}, {44,128,41,6,0x86}, {44,129,41,6,0x8E}, {44,130,41,6,0x96}, {44,131,41,6,0x9E},
{44,132,41,6,0xA6}, {44,133,41,6,0xAE}, {44,134,41,6,0xB6}, {44,135,41,6,0xBE}, {45,128,41,6,0xC6}, {45,129,41,6,0xCE},
{45,130,41,6,0xD6}, {45,131,41,6,0xDE}, {45,132,41,6,0xE6}, {45,133,41,6,0xEE}, {45,134,41,6,0xF6}, {45,135,41,6,0xFE},
};
+1 -1
View File
@@ -5,7 +5,7 @@ cd "$(dirname "$0")"
mkdir -p out
sdasz80 -plosgff out/crt0.rel crt0.s
sdcc -mz80 --opt-code-size --max-allocs-per-node 20000 --std-sdcc11 -c -o out/monitor.rel monitor.c
sdcc -mz80 --no-std-crt0 --code-loc 0x0180 --data-loc 0x7000 -o out/monitor.ihx out/crt0.rel out/monitor.rel
sdcc -mz80 --no-std-crt0 --code-loc 0x0180 --data-loc 0x6000 -o out/monitor.ihx out/crt0.rel out/monitor.rel
python3 ../tools/ihx2mem.py out/monitor.ihx out/monitor-full.bin out/monitor-full.mem
head -c 32768 out/monitor-full.bin > monitor.bin
head -n 32768 out/monitor-full.mem > monitor.mem
+2 -2
View File
@@ -1,5 +1,5 @@
;; Monitor start-up. The monitor's bank holds ROM at 0000-6FFF and RAM at
;; 7000-7FFF. It is entered through the trampoline at 0066h (shared with
;; Monitor start-up. The monitor's bank holds ROM at 0000-5FFF and RAM at
;; 6000-7FFF. It is entered through the trampoline at 0066h (shared with
;; BASIC) with the program's AF and PC pushed on the program's stack.
.module crt0
.globl _mon_main
Binary file not shown.
+204 -9
View File
@@ -71,6 +71,11 @@ static void putc_(char c) { putchar(c); }
static u8 rd(u16 a) { return hostmem[a]; }
#endif
/* SDCC 4.5 expands strcpy inline with A as scratch, and can lose a value it
had parked in A (seen as a wrong pointer to the next call), so copy with a
real function. */
static void s_copy(char *d, const char *s) { while ((*d++ = *s++)); }
/* ------------------------------------------------------------ text out */
static char line[96];
static char *lp;
@@ -81,8 +86,17 @@ static const char hexd[] = "0123456789ABCDEF";
static void s_h2(u8 v) { s_ch(hexd[v >> 4]); s_ch(hexd[v & 15]); }
static void s_h4(u16 v) { s_h2(v >> 8); s_h2(v); }
/* assembler style: 3EH, 0FFH, 1234H, 0C000H */
static void s_n8(u8 v) { if (v >= 0xA0) s_ch('0'); s_h2(v); s_ch('H'); }
static void s_lit8(u8 v) { if (v >= 0xA0) s_ch('0'); s_h2(v); s_ch('H'); }
#ifdef __SDCC
#define s_n8 s_lit8
static void s_n16(u16 v) { if (v >= 0xA000) s_ch('0'); s_h4(v); s_ch('H'); }
#else
/* host build: symbolic mode prints operand kinds (n, nn, e, d) instead of
numbers, for tools/gen-asmtab.py */
static u8 symb;
static void s_n8(u8 v) { if (symb) s_ch('n'); else s_lit8(v); }
static void s_n16(u16 v) { if (symb) s_str("nn"); else { if (v >= 0xA000) s_ch('0'); s_h4(v); s_ch('H'); } }
#endif
/* ---------------------------------------------------------- disassembler */
static u16 da; /* next byte to decode */
@@ -103,8 +117,11 @@ static void s_hl(void) { s_str(ixm == 0 ? "HL" : ixm == 1 ? "IX" : "IY"); }
static void s_disp(u8 d)
{
#ifndef __SDCC
if (symb) { s_str("+d"); return; }
#endif
if (d & 0x80) { s_ch('-'); d = -d; } else s_ch('+');
s_n8(d);
s_lit8(d);
}
static void s_ind(void) /* (HL) or (IX+d), reading d */
@@ -124,7 +141,14 @@ static void s_r8(u8 r, u8 mem)
static void s_rp(u8 p) { if (p == 2) s_hl(); else s_str(p == 0 ? "BC" : p == 1 ? "DE" : "SP"); }
static void s_rp2(u8 p) { if (p == 3) s_str("AF"); else s_rp(p); }
static void s_nn(void) { u16 v = nb(); v |= (u16)nb() << 8; s_n16(v); }
static void s_rel(void) { i16 d = (int8_t)nb(); s_n16(da + d); }
static void s_rel(void)
{
i16 d = (int8_t)nb();
#ifndef __SDCC
if (symb) { s_ch('e'); return; }
#endif
s_n16(da + d);
}
static void dis_cb(u8 op)
{
@@ -230,7 +254,7 @@ static void dis_main(u8 op)
else { s_str("CALL "); s_nn(); }
return;
case 6: s_str(alun[y]); s_n8(nb()); return;
default: s_str("RST "); s_n8(y * 8); return;
default: s_str("RST "); s_lit8(y * 8); return;
}
}
}
@@ -259,13 +283,67 @@ static u8 disasm(u16 a)
return da - a;
}
#include "asm.c"
#ifndef __SDCC
static void a_out(u16 addr, u8 b) { hostmem[addr] = b; }
/* Host test of the assembler: "line" assembles each stdin line alone at
address 0 and prints its bytes; "file" assembles stdin as one program in
two passes and prints address and bytes per line, or the error. */
static int asm_test(int file)
{
static char src[2000][128];
u16 n = 0, i;
u8 p;
while (n < 2000 && fgets(src[n], sizeof src[n], stdin)) {
src[n][strcspn(src[n], "\r\n")] = 0;
a_upper(src[n]);
n++;
}
if (!file) {
a_pass = 2;
for (i = 0; i < n; i++) {
char t[128];
u16 j;
strcpy(t, src[i]);
a_pc = 0; a_lo = 0xFFFF; a_hi = 0; a_undef = 0;
a_line(t);
if (a_err) printf("ERROR %s\n", a_err);
else { for (j = 0; j < a_pc; j++) printf("%02X", hostmem[j]); printf("\n"); }
}
return 0;
}
nsym = 0;
for (p = 1; p <= 2; p++) {
a_pass = p; a_pc = 0xF000; a_end = 0; a_lo = 0xFFFF; a_hi = 0;
for (i = 0; i < n && !a_end; i++) {
char t[128];
u16 at = a_pc, j;
strcpy(t, src[i]);
a_undef = 0;
a_line(t);
if (a_err && (p == 2 || !a_undef)) { printf("LINE %u: %s\n", i + 1, a_err); if (p == 1) return 1; }
if (p == 2) {
printf("%04X ", at);
for (j = at; j < a_pc; j++) printf("%02X", hostmem[j]);
printf("\t%s\n", src[i]);
}
}
}
printf("%u symbols, %04X-%04X\n", nsym, a_lo, a_hi);
return 0;
}
/* Host test: disassemble every opcode form, one per line, for the round trip
through sdasz80 in monitor/test-disasm.sh. Format: hex bytes TAB text. */
int main(void)
int main(int argc, char **argv)
{
static const u8 pre[][2] = { {0, 0}, {0xCB, 0}, {0xED, 0}, {0xDD, 0}, {0xFD, 0}, {0xDD, 0xCB}, {0xFD, 0xCB} };
u16 k, i;
if (argc > 1 && !strcmp(argv[1], "line")) return asm_test(0);
if (argc > 1 && !strcmp(argv[1], "file")) return asm_test(1);
symb = argc > 1;
for (k = 0; k < 7; k++)
for (i = 0; i < 256; i++) {
u8 n = 0, len, j;
@@ -470,12 +548,13 @@ static void show_msg(void)
/* Read a command into cmd. Returns 1 for a line, or a key code for a key
that acts at once on an empty line: 'U', 'N' (up, down), 'P', 'Q' (page). */
static const char *prompt = "> ";
static u8 read_cmd(void)
{
u8 n = 0, c;
at(29, 0); puts_("> "); clr_eol();
at(29, 0); puts_(prompt); clr_eol();
show_msg();
at(29, 2);
at(29, strlen(prompt));
puts_("\033[?25h");
for (;;) {
c = getk();
@@ -772,6 +851,108 @@ static void mem_dir(void)
if (!n) { at(MEM_TOP, 1); puts_("NO FILES"); }
}
/* ------------------------------------------------------------ assembler */
static void a_out(u16 addr, u8 b) { if (!wr(addr, b)) a_fail("CAN'T WRITE BELOW 8000H"); }
static u8 dis_shows(u16 pc);
static char a_src[128];
static u8 a_nerr;
static void s_dec(u16 v)
{
char b[6], *q = b + 5;
*q = 0;
do *--q = '0' + v % 10; while (v /= 10);
s_str(q);
}
/* one error, in the memory window (six fit) */
static void a_report(u16 ln)
{
if (a_nerr < MEM_ROWS) {
lp = line;
s_str(" LINE "); s_dec(ln);
s_str(": "); s_str(a_err);
*lp = 0;
at(MEM_TOP + a_nerr, 0); flush_line(); clr_eol();
}
a_nerr++;
}
/* ASM "NAME": assemble a source file from flash into memory */
static void mem_asm(void)
{
char nm[8];
i16 f;
u16 len, pos, ln;
u8 n, p, r;
get_fname(nm);
fs_mount();
f = find_file(nm);
if (f < 0) fs_fail("FILE NOT FOUND");
len = dir.e[f].len;
nsym = 0;
a_nerr = 0;
for (r = 0; r < MEM_ROWS; r++) { at(MEM_TOP + r, 0); clr_eol(); }
for (p = 1; p <= 2 && !a_nerr; p++) {
a_pass = p; a_pc = 0xF000; a_end = 0; a_lo = 0xFFFF; a_hi = 0;
n = 0; ln = 0;
for (pos = 0; pos <= len && !a_end; pos++) {
u8 c = '\n';
if (pos < len) {
if (!(pos & 255))
fl_read(blk_addr(dir.e[f].blk[pos >> 12]) + (pos & 4095), page, 256);
c = page[pos & 255];
}
if (c != '\n') { if (n < sizeof a_src - 1) a_src[n++] = c; continue; }
a_src[n] = 0;
n = 0;
ln++;
{
u16 num = 0; /* report BASIC's line number if there is one */
char *t = a_src;
while (*t == ' ') t++;
while (*t >= '0' && *t <= '9') num = num * 10 + (*t++ - '0');
a_upper(a_src);
a_undef = 0;
a_line(a_src);
if (a_err) a_report(num ? num : ln);
}
}
}
if (a_nerr) {
lp = line; s_dec(a_nerr); s_str(a_nerr == 1 ? " ERROR" : " ERRORS"); *lp = 0;
s_copy(load_msg, line);
fs_fail(load_msg);
}
if (a_lo > a_hi) fs_fail("NOTHING ASSEMBLED");
lp = line; s_str("ASSEMBLED "); s_h4(a_lo); s_ch('-'); s_h4(a_hi); *lp = 0;
s_copy(load_msg, line);
dis_a = mem_a = a_lo;
draw_mem(); draw_dis();
}
/* A addr: assemble lines typed at the bottom, one after another */
static void line_asm(u16 a)
{
static char pr[10];
for (;;) {
lp = pr; s_ch('A'); s_ch(' '); s_h4(a); s_str(": "); *lp = 0;
prompt = pr;
if (read_cmd() != 1) continue;
prompt = "> ";
if (!cmd[0]) { msg = 0; return; }
s_copy(a_src, cmd);
a_pass = 2; a_pc = a; a_undef = 0; a_lo = 0xFFFF; a_hi = 0;
a_line(a_src);
if (a_err) { msg = a_err; msg_err = 1; continue; }
msg = 0;
if (a < dis_a || !dis_shows(a)) dis_a = a;
a = a_pc;
draw_dis(); draw_mem();
}
}
/* ---------------------------------------------------------- commands */
static u8 op_is_call(u16 a)
{
@@ -824,6 +1005,20 @@ static u8 command(void)
cp = cmd;
skip_sp();
msg = 0; msg_err = 0;
if (!memcmp(cp, "ASM", 3)) {
cp += 3;
if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; }
mem_asm();
msg = load_msg;
return 0;
}
if (cp[0] == 'A' && (cp[1] == ' ' || !cp[1])) {
u16 a;
cp++;
if (!get_hex(&a)) { msg = "A ADDR, THEN INSTRUCTIONS; EMPTY LINE ENDS"; msg_err = 1; return 0; }
line_asm(a);
return 0;
}
if (!memcmp(cp, "SAVE", 4) || !memcmp(cp, "LOAD", 4) || !memcmp(cp, "DIR", 3)) {
c = *cp;
cp += c == 'D' ? 3 : 4;
@@ -832,7 +1027,7 @@ static u8 command(void)
else if (c == 'L') {
mem_load();
lp = line; s_str("LOADED "); s_h4(ld_first); s_ch('-'); s_h4(ld_last); *lp = 0;
strcpy(load_msg, line);
s_copy(load_msg, line);
msg = load_msg;
mem_a = ld_first;
draw_mem(); draw_dis();
@@ -888,7 +1083,7 @@ static u8 command(void)
return 0;
case '?':
case 'H':
msg = "SAVE \"N\" A B LOAD \"N\" [A] DIR";
msg = "ASM \"N\" A ADDR SAVE \"N\" A B LOAD \"N\" [A] DIR";
return 0;
default:
msg = "? TYPE ? FOR HELP"; msg_err = 1;
+13239 -13239
View File
File diff suppressed because it is too large. Load diff
+23
View File
@@ -0,0 +1,23 @@
#!/bin/bash
# Check the assembler as SDCC compiles it for the Z-80 (it has had code
# generation bugs, see s_copy in monitor.c): assemble every opcode form with
# monitor/test/asm-z80.c in tools/z80emu.py and compare with the PC build.
# Takes about two minutes.
set -e
cd "$(dirname "$0")"
T=$(mktemp -d)
sdasz80 -o $T/crt0.rel ../basic/crt0.s
cp asm.c asmtab.h $T/ && cp test/asm-z80.c $T/t.c
(cd $T && sdcc -mz80 --opt-code-size --max-allocs-per-node 20000 --std-sdcc11 -c t.c 2>/dev/null &&
sdcc -mz80 --no-std-crt0 --code-loc 0x0080 --data-loc 0x8000 -o t.ihx crt0.rel t.rel)
python3 ../tools/ihx2mem.py $T/t.ihx $T/t.bin $T/t.mem >/dev/null
gcc -O1 -w -o $T/mon monitor.c
$T/mon | awk -F'\t' '$2 != "NOP*" && $2 !~ /^DB /{print $2}' > $T/lines.txt
(cat $T/lines.txt; echo) > $T/input.txt
$T/mon line < $T/lines.txt > $T/host.txt
python3 ../tools/z80emu.py $T/t.bin --input $T/input.txt --max 400000000 2>&1 | grep -v '^\[' | tr -d '\r' | tail -n +2 > $T/z80.txt
if diff $T/z80.txt $T/host.txt > /dev/null; then
echo "Z-80 build matches the PC build on $(wc -l < $T/lines.txt) lines"
else
echo "Z-80 BUILD DIFFERS:"; diff $T/z80.txt $T/host.txt | head; exit 1
fi
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
"""Check the monitor's assembler against its disassembler: disassemble every
opcode form, assemble each line back (host build of monitor.c) and compare
the bytes. Undocumented duplicates come back as their documented encoding;
the three-operand DDCB register copies aren't supported.
monitor/test-asm.py
"""
import os
import subprocess
import sys
import tempfile
here = os.path.dirname(os.path.abspath(__file__))
exe = os.path.join(tempfile.mkdtemp(), "mon")
subprocess.check_call(["gcc", "-O1", "-w", "-o", exe, os.path.join(here, "monitor.c")])
forms = [l.split("\t") for l in subprocess.check_output([exe], text=True).splitlines()]
forms = [(h, t) for h, t in forms if t != "NOP*" and not t.startswith("DB ")]
out = subprocess.run([exe, "line"], input="\n".join(t for _, t in forms) + "\n",
capture_output=True, text=True).stdout.splitlines()
first = {}
for hexb, text in forms:
first.setdefault(text, hexb) # the documented encoding comes first
ok = alias = copies = bad = 0
for (hexb, text), got in zip(forms, out):
if got == hexb:
ok += 1
elif text.count(",") == 2: # RES 0,(IX+d),B and friends
copies += 1
elif got == first[text]: # a duplicate of an earlier form
alias += 1
elif hexb[:2] in ("DD", "FD") and text.split()[0] in ("JR", "DJNZ") and \
got == hexb[2:4] + "%02X" % (int(hexb[4:6], 16) + 1):
alias += 1 # a dead prefix made the jump a byte longer
else:
bad += 1
print("FAIL %-10s %-24s -> %s" % (hexb, text, got))
print("%d exact, %d duplicates assembled to the documented encoding, %d DDCB copies skipped, %d failures"
% (ok, alias, copies, bad))
sys.exit(1 if bad else 0)
+32
View File
@@ -0,0 +1,32 @@
/* 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 (;;);
}