2 * UAE - The Un*x Amiga Emulator - CPU core
4 * Read 68000 CPU specs from file "table68k" and build table68k.c
6 * Copyright 1995,1996 Bernd Schmidt
8 * Adaptation to Hatari by Thomas Huth
10 * This file is distributed under the GNU Public License, version 3 or at
11 * your option any later version. Read the file GPLv3 for details.
13 //const char Build68k_fileid[] = "Hatari build68k.c : " __DATE__ " " __TIME__;
22 static int nextch = 0;
24 static void getnextch(void)
28 nextch = fgetc(tablef);
34 nextch = fgetc(tablef);
36 while (nextch != EOF && nextch != '\n');
39 while (nextch != EOF && isspace(nextch));
42 static int nextchtohex(void)
44 switch (isupper(nextch) ? tolower(nextch) : nextch)
66 int main(int argc, char ** argv)
70 /*printf("#include \"sysconfig.h\"\n");*/
71 printf("#include \"sysdeps.h\"\n");
72 printf("#include \"readcpu.h\"\n");
73 printf("const struct instr_def defs68k[] = {\n");
75 tablef = fopen("table68k","r");
77 fprintf(stderr, "table68k not found\n");
87 int cpulevel, plevel, sduse;
93 int flagset[5], flaguse[5];
95 unsigned int bitmask, bitpattern;
99 bitmask = bitpattern = 0;
100 memset(bitpos, 0, sizeof(bitpos));
110 case '0': currbit = bit0; bitmask |= 1; break;
111 case '1': currbit = bit1; bitmask |= 1; bitpattern |= 1; break;
112 case 'c': currbit = bitc; break;
113 case 'C': currbit = bitC; break;
114 case 'f': currbit = bitf; break;
115 case 'i': currbit = biti; break;
116 case 'I': currbit = bitI; break;
117 case 'j': currbit = bitj; break;
118 case 'J': currbit = bitJ; break;
119 case 'k': currbit = bitk; break;
120 case 'K': currbit = bitK; break;
121 case 's': currbit = bits; break;
122 case 'S': currbit = bitS; break;
123 case 'd': currbit = bitd; break;
124 case 'D': currbit = bitD; break;
125 case 'r': currbit = bitr; break;
126 case 'R': currbit = bitR; break;
127 case 'z': currbit = bitz; break;
128 case 'p': currbit = bitp; break;
134 bitpos[n_variable] = currbit;
138 if (nextch == '0' || nextch == '1')
148 while (isspace(nextch) || nextch == ':') /* Get CPU and privilege level */
153 case '0': cpulevel = 0; break;
154 case '1': cpulevel = 1; break;
155 case '2': cpulevel = 2; break;
156 case '3': cpulevel = 3; break;
157 case '4': cpulevel = 4; break;
165 case '0': plevel = 0; break;
166 case '1': plevel = 1; break;
167 case '2': plevel = 2; break;
168 case '3': plevel = 3; break;
174 while (isspace(nextch)) /* Get flag set information */
186 case '-': flagset[i] = fa_unset; break;
187 case '/': flagset[i] = fa_isjmp; break;
188 case '+': flagset[i] = fa_isbranch; break;
189 case '0': flagset[i] = fa_zero; break;
190 case '1': flagset[i] = fa_one; break;
191 case 'x': flagset[i] = fa_dontcare; break;
192 case '?': flagset[i] = fa_unknown; break;
193 default: flagset[i] = fa_set; break;
199 while (isspace(nextch))
202 if (nextch != ':') /* Get flag used information */
211 case '-': flaguse[i] = fu_unused; break;
212 case '/': flaguse[i] = fu_isjmp; break;
213 case '+': flaguse[i] = fu_maybecc; break;
214 case '?': flaguse[i] = fu_unknown; break;
215 default: flaguse[i] = fu_used; break;
221 while (isspace(nextch))
224 if (nextch != ':') /* Get source/dest usage information */
228 sduse = nextchtohex() << 4;
230 sduse |= nextchtohex();
233 while (isspace(nextch))
239 if (fgets(opcstr, 250, tablef) == NULL)
249 /* Remove superfluous spaces from the string */
250 char * opstrp = opcstr, * osendp;
253 while (isspace((unsigned)(*opstrp)))
260 if (!isspace ((unsigned)(*osendp)))
261 slen = osendp - opstrp + 1;
272 printf("{ %d, %d, {", bitpattern, n_variable);
276 printf("%d", bitpos[j]);
282 printf ("}, %d, %d, %d, { ", bitmask, cpulevel, plevel);
286 printf("{ %d, %d }%c ", flaguse[i], flagset[i], i == 4 ? ' ' : ',');
289 printf("}, %d, \"%s\"}", sduse, opstrp);
293 printf("};\nint n_defs68k = %d;\n", no_insns);