7 static const char *opcodes
[] = {
8 "LDIR", "LDDR", "LDI", "LDD", "CPIR", "CPDR", "CPI", "CPD", "INIR", "INDR", "INI", "IND", "OUTI", "OTIR", "OUTD", "OTDR",
9 "RETI", "RETN", "NEG", "RLD", "RRD", "PUSH", "POP", "ADD", "SUB", "ADC", "SBC", "AND", "OR", "XOR", "CP", "INC",
10 "DEC", "BIT", "RES", "SET", "RLC", "RRC", "RL", "RR", "SLA", "SRA", "SLI", "SRL", "LD", "EX", "IN", "OUT",
11 "IM", "RST", "DJNZ", "JP", "JR", "CALL", "RET", "EXX", "CPL", "DAA", "RLCA", "RRCA", "RLA", "RRA", "NOP", "HALT",
12 "DI", "EI", "SCF", "CCF", "ORG", "ENT", "EQU", "WORK", "DB", "DW", "DM", "DS", "!ASSM", "!CONT", "LTEXT", "LCODE",
13 "BC", "DE", "HL", "IX", "IY", "SP", "AF", "(C)", "B", "C", "D", "E", "H", "L", "(HL)", "A",
14 "(BC)", "(DE)", "HX", "LX", "HY", "LY", "I", "R", "NZ", "Z", "NC", "PO", "PE", "P", "M", "!ON",
15 "!OFF", "(SP)", "AF'", "USEL", "IFNZ", "IFZ", "MAKE" "?", "?", "?", "?", "?", "?", "?", "?", "?"
19 static uint8_t cyr (uint8_t b
) {
21 static const uint8_t cyr1
[] = {'ä', 'ö', 'é', 'ê', 'ì', 'ð', 'õ', 'æ', 'ã', 'þ', 'ù', 'ø', 'ü', 'à', 'ñ', 'ÿ'};
22 static const uint8_t cyr2
[] = {'û', 'ý', 'â', 'ç'};
24 if (b
>= 0x10 && b
<= 0x1f) return cyr1
[b
-0x10];
25 if (b
>= 0x7b && b
<= 0x7e) return cyr2
[b
-0x7b];
30 static uint8_t toLower (uint8_t b
) {
31 // convert all UPPERCASE letters to lowercase
32 if (b
>= 'A' && b
<= 'Z') return b
-'A'+'a';
38 static uint8_t transform (uint8_t b) {
46 #define GETBYTE(_dst) do { \
47 if (--buflen < 0) { free(buf); return -1; } \
52 #define PUTCH(_ch) do { \
53 uint8_t _xch = (uint8_t)(_ch); \
54 if (fwrite(&_xch, 1, 1, fo) != 1) { free(buf); return -1; } \
58 static int extract (FILE *fo
, FILE *fi
) {
65 if ((buf
= loadWholeFile(fi
, &buflen
)) == NULL
) return -1;
66 if ((buflen
-= sizeof(HOBHeader
)) < 1) { free(buf
); return -1; }
67 if ((buflen
-= 29+2+1+1+1+1+1) < 1) { free(buf
); return -1; }
69 p
= buf
+sizeof(HOBHeader
)+29+2+1+1+1+1+1;
70 while (buflen
> 0 && *p
) {
76 if (b
== 0x0d || b
== 0x0c || b
== 0x09) {
83 while (b
!= 0x0d && b
!= 0x0c && b
!= 0x09) {
85 if (buflen
< 1) break;
92 if (buflen
< 1) goto NEXT_LINE
;
100 from
= opcodes
[b
-0x80];
101 while (*from
) PUTCH(*from
++);
105 // loop foreach token
108 if (b
== 0x0d || b
== 0x0c || b
== 0x09) {
117 while (b
!= 0x0d && b
!= 0x0c && b
!= 0x09) {
119 if (buflen
< 1) goto NEXT_LINE
;
127 if (needComma
) PUTCH(',');
128 from
= opcodes
[b
-0x80];
129 while (*from
) PUTCH(*from
++);
135 if (needComma
) PUTCH(',');
140 from
= opcodes
[b
-0x80];
141 while (*from
) PUTCH(*from
++);
153 if (needComma
) PUTCH(',');
156 if (buflen
> 1 && p
[0] == '"' && p
[1] == '"') {
172 if (needComma
) PUTCH(',');
173 while (b
< 0x80 && b
!= '(' && b
!= ';' && b
!= 0x0d && b
!= 0x0c && b
!= 0x09) {
175 if (buflen
< 1) goto NEXT_LINE1
;
190 static const int detect (FILE *fi
, const char *fname
, const HOBHeader
*hdr
) {
191 if ((hdr
->type
!= 'X' && hdr
->type
!= 'x') ||
192 (hdr
->type1
!= 'A' && hdr
->type1
!= 'a') ||
193 hdr
->type2
!= 'S') return 0;
198 ////////////////////////////////////////////////////////////////////////////////
199 static CvtMethods mtlist
;
202 CvtMethods
*cvt_xas (void) {
203 mtlist
.name
= "XAS assembler";
204 mtlist
.fmtname
= "xas";
205 mtlist
.extract
= extract
;
206 mtlist
.detect
= detect
;