ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/gencpu.c
Revision: 1.25
Committed: 2007-06-30T08:00:31Z (17 years, 4 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.24: +38 -6 lines
Log Message:
Fix xBCD instruction for 68040 emulation: the NV flags shall not be affected.

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * UAE - The Un*x Amiga Emulator
3     *
4     * MC68000 emulation generator
5     *
6     * This is a fairly stupid program that generates a lot of case labels that
7     * can be #included in a switch statement.
8     * As an alternative, it can generate functions that handle specific
9     * MC68000 instructions, plus a prototype header file and a function pointer
10     * array to look up the function for an opcode.
11     * Error checking is bad, an illegal table68k file will cause the program to
12     * call abort().
13     * The generated code is sometimes sub-optimal, an optimizing compiler should
14     * take care of this.
15     *
16     * Copyright 1995, 1996 Bernd Schmidt
17     */
18    
19     #include <ctype.h>
20     #include <stdio.h>
21     #include <stdlib.h>
22     #include <string.h>
23    
24     #include "sysdeps.h"
25     #include "readcpu.h"
26    
27 cebix 1.2 #if defined(SPARC_V8_ASSEMBLY) || defined(SPARC_V9_ASSEMBLY)
28     #define SPARC_ASSEMBLY 0
29     #endif
30    
31 cebix 1.1 #define BOOL_TYPE "int"
32    
33 gbeauche 1.25 /* Define the minimal 680x0 where NV flags are not affected by xBCD instructions. */
34     #define xBCD_KEEPS_NV_FLAGS 4
35    
36 cebix 1.1 static FILE *headerfile;
37     static FILE *stblfile;
38    
39     static int using_prefetch;
40     static int using_exception_3;
41     static int cpu_level;
42    
43     /* For the current opcode, the next lower level that will have different code.
44     * Initialized to -1 for each opcode. If it remains unchanged, indicates we
45     * are done with that opcode. */
46     static int next_cpu_level;
47    
48     static int *opcode_map;
49     static int *opcode_next_clev;
50     static int *opcode_last_postfix;
51     static unsigned long *counts;
52    
53     static void read_counts (void)
54     {
55     FILE *file;
56     unsigned long opcode, count, total;
57     char name[20];
58     int nr = 0;
59     memset (counts, 0, 65536 * sizeof *counts);
60    
61     file = fopen ("frequent.68k", "r");
62     if (file) {
63     fscanf (file, "Total: %lu\n", &total);
64     while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3) {
65 cebix 1.6 opcode_next_clev[nr] = 4;
66 cebix 1.1 opcode_last_postfix[nr] = -1;
67     opcode_map[nr++] = opcode;
68     counts[opcode] = count;
69     }
70     fclose (file);
71     }
72     if (nr == nr_cpuop_funcs)
73     return;
74     for (opcode = 0; opcode < 0x10000; opcode++) {
75     if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG
76     && counts[opcode] == 0)
77     {
78 cebix 1.6 opcode_next_clev[nr] = 4;
79 cebix 1.1 opcode_last_postfix[nr] = -1;
80     opcode_map[nr++] = opcode;
81     counts[opcode] = count;
82     }
83     }
84     if (nr != nr_cpuop_funcs)
85     abort ();
86     }
87    
88     static char endlabelstr[80];
89     static int endlabelno = 0;
90     static int need_endlabel;
91    
92     static int n_braces = 0;
93     static int m68k_pc_offset = 0;
94     static int insn_n_cycles;
95    
96     static void start_brace (void)
97     {
98     n_braces++;
99     printf ("{");
100     }
101    
102     static void close_brace (void)
103     {
104     assert (n_braces > 0);
105     n_braces--;
106     printf ("}");
107     }
108    
109     static void finish_braces (void)
110     {
111     while (n_braces > 0)
112     close_brace ();
113     }
114    
115     static void pop_braces (int to)
116     {
117     while (n_braces > to)
118     close_brace ();
119     }
120    
121     static int bit_size (int size)
122     {
123     switch (size) {
124     case sz_byte: return 8;
125     case sz_word: return 16;
126     case sz_long: return 32;
127     default: abort ();
128     }
129     return 0;
130     }
131    
132     static const char *bit_mask (int size)
133     {
134     switch (size) {
135     case sz_byte: return "0xff";
136     case sz_word: return "0xffff";
137     case sz_long: return "0xffffffff";
138     default: abort ();
139     }
140     return 0;
141     }
142    
143     static const char *gen_nextilong (void)
144     {
145     static char buffer[80];
146     int r = m68k_pc_offset;
147     m68k_pc_offset += 4;
148    
149     insn_n_cycles += 4;
150    
151     if (using_prefetch)
152     sprintf (buffer, "get_ilong_prefetch(%d)", r);
153     else
154     sprintf (buffer, "get_ilong(%d)", r);
155     return buffer;
156     }
157    
158     static const char *gen_nextiword (void)
159     {
160     static char buffer[80];
161     int r = m68k_pc_offset;
162     m68k_pc_offset += 2;
163    
164     insn_n_cycles += 2;
165    
166     if (using_prefetch)
167     sprintf (buffer, "get_iword_prefetch(%d)", r);
168     else
169     sprintf (buffer, "get_iword(%d)", r);
170     return buffer;
171     }
172    
173     static const char *gen_nextibyte (void)
174     {
175     static char buffer[80];
176     int r = m68k_pc_offset;
177     m68k_pc_offset += 2;
178    
179     insn_n_cycles += 2;
180    
181     if (using_prefetch)
182     sprintf (buffer, "get_ibyte_prefetch(%d)", r);
183     else
184     sprintf (buffer, "get_ibyte(%d)", r);
185     return buffer;
186     }
187    
188     static void fill_prefetch_0 (void)
189     {
190     if (using_prefetch)
191     printf ("fill_prefetch_0 ();\n");
192     }
193    
194     static void fill_prefetch_2 (void)
195     {
196     if (using_prefetch)
197     printf ("fill_prefetch_2 ();\n");
198     }
199    
200     static void swap_opcode (void)
201     {
202     printf ("#ifdef HAVE_GET_WORD_UNSWAPPED\n");
203     printf ("\topcode = ((opcode << 8) & 0xFF00) | ((opcode >> 8) & 0xFF);\n");
204     printf ("#endif\n");
205     }
206    
207     static void sync_m68k_pc (void)
208     {
209     if (m68k_pc_offset == 0)
210     return;
211     printf ("m68k_incpc(%d);\n", m68k_pc_offset);
212     switch (m68k_pc_offset) {
213     case 0:
214     /*fprintf (stderr, "refilling prefetch at 0\n"); */
215     break;
216     case 2:
217     fill_prefetch_2 ();
218     break;
219     default:
220     fill_prefetch_0 ();
221     break;
222     }
223     m68k_pc_offset = 0;
224     }
225    
226     /* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0,
227 gbeauche 1.12 * the calling routine handles Apdi and Aipi modes.
228     * gb-- movem == 2 means the same thing but for a MOVE16 instruction */
229 cebix 1.1 static void genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem)
230     {
231     start_brace ();
232     switch (mode) {
233     case Dreg:
234     if (movem)
235     abort ();
236     if (getv == 1)
237     switch (size) {
238     case sz_byte:
239 cebix 1.10 #if defined(AMIGA) && !defined(WARPUP)
240 cebix 1.1 /* sam: I don't know why gcc.2.7.2.1 produces a code worse */
241     /* if it is not done like that: */
242     printf ("\tuae_s8 %s = ((uae_u8*)&m68k_dreg(regs, %s))[3];\n", name, reg);
243     #else
244     printf ("\tuae_s8 %s = m68k_dreg(regs, %s);\n", name, reg);
245     #endif
246     break;
247     case sz_word:
248 cebix 1.10 #if defined(AMIGA) && !defined(WARPUP)
249 cebix 1.1 printf ("\tuae_s16 %s = ((uae_s16*)&m68k_dreg(regs, %s))[1];\n", name, reg);
250     #else
251     printf ("\tuae_s16 %s = m68k_dreg(regs, %s);\n", name, reg);
252     #endif
253     break;
254     case sz_long:
255     printf ("\tuae_s32 %s = m68k_dreg(regs, %s);\n", name, reg);
256     break;
257     default:
258     abort ();
259     }
260     return;
261     case Areg:
262     if (movem)
263     abort ();
264     if (getv == 1)
265     switch (size) {
266     case sz_word:
267     printf ("\tuae_s16 %s = m68k_areg(regs, %s);\n", name, reg);
268     break;
269     case sz_long:
270     printf ("\tuae_s32 %s = m68k_areg(regs, %s);\n", name, reg);
271     break;
272     default:
273     abort ();
274     }
275     return;
276     case Aind:
277     printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg);
278     break;
279     case Aipi:
280     printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg);
281     break;
282     case Apdi:
283     switch (size) {
284     case sz_byte:
285     if (movem)
286     printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg);
287     else
288     printf ("\tuaecptr %sa = m68k_areg(regs, %s) - areg_byteinc[%s];\n", name, reg, reg);
289     break;
290     case sz_word:
291     printf ("\tuaecptr %sa = m68k_areg(regs, %s) - %d;\n", name, reg, movem ? 0 : 2);
292     break;
293     case sz_long:
294     printf ("\tuaecptr %sa = m68k_areg(regs, %s) - %d;\n", name, reg, movem ? 0 : 4);
295     break;
296     default:
297     abort ();
298     }
299     break;
300     case Ad16:
301     printf ("\tuaecptr %sa = m68k_areg(regs, %s) + (uae_s32)(uae_s16)%s;\n", name, reg, gen_nextiword ());
302     break;
303     case Ad8r:
304     if (cpu_level > 1) {
305     if (next_cpu_level < 1)
306     next_cpu_level = 1;
307     sync_m68k_pc ();
308     start_brace ();
309     printf ("\tuaecptr %sa = get_disp_ea_020(m68k_areg(regs, %s), next_iword());\n", name, reg);
310     } else
311     printf ("\tuaecptr %sa = get_disp_ea_000(m68k_areg(regs, %s), %s);\n", name, reg, gen_nextiword ());
312    
313     break;
314     case PC16:
315     printf ("\tuaecptr %sa = m68k_getpc () + %d;\n", name, m68k_pc_offset);
316     printf ("\t%sa += (uae_s32)(uae_s16)%s;\n", name, gen_nextiword ());
317     break;
318     case PC8r:
319     if (cpu_level > 1) {
320     if (next_cpu_level < 1)
321     next_cpu_level = 1;
322     sync_m68k_pc ();
323     start_brace ();
324     printf ("\tuaecptr tmppc = m68k_getpc();\n");
325     printf ("\tuaecptr %sa = get_disp_ea_020(tmppc, next_iword());\n", name);
326     } else {
327     printf ("\tuaecptr tmppc = m68k_getpc() + %d;\n", m68k_pc_offset);
328     printf ("\tuaecptr %sa = get_disp_ea_000(tmppc, %s);\n", name, gen_nextiword ());
329     }
330    
331     break;
332     case absw:
333     printf ("\tuaecptr %sa = (uae_s32)(uae_s16)%s;\n", name, gen_nextiword ());
334     break;
335     case absl:
336     printf ("\tuaecptr %sa = %s;\n", name, gen_nextilong ());
337     break;
338     case imm:
339     if (getv != 1)
340     abort ();
341     switch (size) {
342     case sz_byte:
343     printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte ());
344     break;
345     case sz_word:
346     printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword ());
347     break;
348     case sz_long:
349     printf ("\tuae_s32 %s = %s;\n", name, gen_nextilong ());
350     break;
351     default:
352     abort ();
353     }
354     return;
355     case imm0:
356     if (getv != 1)
357     abort ();
358     printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte ());
359     return;
360     case imm1:
361     if (getv != 1)
362     abort ();
363     printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword ());
364     return;
365     case imm2:
366     if (getv != 1)
367     abort ();
368     printf ("\tuae_s32 %s = %s;\n", name, gen_nextilong ());
369     return;
370     case immi:
371     if (getv != 1)
372     abort ();
373     printf ("\tuae_u32 %s = %s;\n", name, reg);
374     return;
375     default:
376     abort ();
377     }
378    
379     /* We get here for all non-reg non-immediate addressing modes to
380     * actually fetch the value. */
381    
382     if (using_exception_3 && getv != 0 && size != sz_byte) {
383     printf ("\tif ((%sa & 1) != 0) {\n", name);
384     printf ("\t\tlast_fault_for_exception_3 = %sa;\n", name);
385     printf ("\t\tlast_op_for_exception_3 = opcode;\n");
386     printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + %d;\n", m68k_pc_offset);
387     printf ("\t\tException(3, 0);\n");
388     printf ("\t\tgoto %s;\n", endlabelstr);
389     printf ("\t}\n");
390     need_endlabel = 1;
391     start_brace ();
392     }
393    
394     if (getv == 1) {
395     switch (size) {
396     case sz_byte: insn_n_cycles += 2; break;
397     case sz_word: insn_n_cycles += 2; break;
398     case sz_long: insn_n_cycles += 4; break;
399     default: abort ();
400     }
401     start_brace ();
402     switch (size) {
403     case sz_byte: printf ("\tuae_s8 %s = get_byte(%sa);\n", name, name); break;
404     case sz_word: printf ("\tuae_s16 %s = get_word(%sa);\n", name, name); break;
405     case sz_long: printf ("\tuae_s32 %s = get_long(%sa);\n", name, name); break;
406     default: abort ();
407     }
408     }
409    
410     /* We now might have to fix up the register for pre-dec or post-inc
411     * addressing modes. */
412     if (!movem)
413     switch (mode) {
414     case Aipi:
415     switch (size) {
416     case sz_byte:
417     printf ("\tm68k_areg(regs, %s) += areg_byteinc[%s];\n", reg, reg);
418     break;
419     case sz_word:
420     printf ("\tm68k_areg(regs, %s) += 2;\n", reg);
421     break;
422     case sz_long:
423     printf ("\tm68k_areg(regs, %s) += 4;\n", reg);
424     break;
425     default:
426     abort ();
427     }
428     break;
429     case Apdi:
430     printf ("\tm68k_areg (regs, %s) = %sa;\n", reg, name);
431     break;
432     default:
433     break;
434     }
435     }
436    
437     static void genastore (char *from, amodes mode, char *reg, wordsizes size, char *to)
438     {
439     switch (mode) {
440     case Dreg:
441     switch (size) {
442     case sz_byte:
443     printf ("\tm68k_dreg(regs, %s) = (m68k_dreg(regs, %s) & ~0xff) | ((%s) & 0xff);\n", reg, reg, from);
444     break;
445     case sz_word:
446     printf ("\tm68k_dreg(regs, %s) = (m68k_dreg(regs, %s) & ~0xffff) | ((%s) & 0xffff);\n", reg, reg, from);
447     break;
448     case sz_long:
449     printf ("\tm68k_dreg(regs, %s) = (%s);\n", reg, from);
450     break;
451     default:
452     abort ();
453     }
454     break;
455     case Areg:
456     switch (size) {
457     case sz_word:
458     fprintf (stderr, "Foo\n");
459     printf ("\tm68k_areg(regs, %s) = (uae_s32)(uae_s16)(%s);\n", reg, from);
460     break;
461     case sz_long:
462     printf ("\tm68k_areg(regs, %s) = (%s);\n", reg, from);
463     break;
464     default:
465     abort ();
466     }
467     break;
468     case Aind:
469     case Aipi:
470     case Apdi:
471     case Ad16:
472     case Ad8r:
473     case absw:
474     case absl:
475     case PC16:
476     case PC8r:
477     if (using_prefetch)
478     sync_m68k_pc ();
479     switch (size) {
480     case sz_byte:
481     insn_n_cycles += 2;
482     printf ("\tput_byte(%sa,%s);\n", to, from);
483     break;
484     case sz_word:
485     insn_n_cycles += 2;
486     if (cpu_level < 2 && (mode == PC16 || mode == PC8r))
487     abort ();
488     printf ("\tput_word(%sa,%s);\n", to, from);
489     break;
490     case sz_long:
491     insn_n_cycles += 4;
492     if (cpu_level < 2 && (mode == PC16 || mode == PC8r))
493     abort ();
494     printf ("\tput_long(%sa,%s);\n", to, from);
495     break;
496     default:
497     abort ();
498     }
499     break;
500     case imm:
501     case imm0:
502     case imm1:
503     case imm2:
504     case immi:
505     abort ();
506     break;
507     default:
508     abort ();
509     }
510     }
511    
512     static void genmovemel (uae_u16 opcode)
513     {
514     char getcode[100];
515     int size = table68k[opcode].size == sz_long ? 4 : 2;
516    
517     if (table68k[opcode].size == sz_long) {
518     strcpy (getcode, "get_long(srca)");
519     } else {
520     strcpy (getcode, "(uae_s32)(uae_s16)get_word(srca)");
521     }
522    
523     printf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
524     printf ("\tunsigned int dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n");
525     genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
526     start_brace ();
527     printf ("\twhile (dmask) { m68k_dreg(regs, movem_index1[dmask]) = %s; srca += %d; dmask = movem_next[dmask]; }\n",
528     getcode, size);
529     printf ("\twhile (amask) { m68k_areg(regs, movem_index1[amask]) = %s; srca += %d; amask = movem_next[amask]; }\n",
530     getcode, size);
531    
532     if (table68k[opcode].dmode == Aipi)
533     printf ("\tm68k_areg(regs, dstreg) = srca;\n");
534     }
535    
536     static void genmovemle (uae_u16 opcode)
537     {
538     char putcode[100];
539     int size = table68k[opcode].size == sz_long ? 4 : 2;
540     if (table68k[opcode].size == sz_long) {
541     strcpy (putcode, "put_long(srca,");
542     } else {
543     strcpy (putcode, "put_word(srca,");
544     }
545    
546     printf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
547     genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
548     if (using_prefetch)
549     sync_m68k_pc ();
550    
551     start_brace ();
552     if (table68k[opcode].dmode == Apdi) {
553     printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n");
554     printf ("\twhile (amask) { srca -= %d; %s m68k_areg(regs, movem_index2[amask])); amask = movem_next[amask]; }\n",
555     size, putcode);
556     printf ("\twhile (dmask) { srca -= %d; %s m68k_dreg(regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n",
557     size, putcode);
558     printf ("\tm68k_areg(regs, dstreg) = srca;\n");
559     } else {
560     printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n");
561     printf ("\twhile (dmask) { %s m68k_dreg(regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n",
562     putcode, size);
563     printf ("\twhile (amask) { %s m68k_areg(regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n",
564     putcode, size);
565     }
566     }
567    
568     static void duplicate_carry (void)
569     {
570     printf ("\tCOPY_CARRY;\n");
571     }
572    
573     typedef enum {
574 gbeauche 1.25 flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_z, flag_zn,
575 cebix 1.1 flag_av, flag_sv
576     } flagtypes;
577    
578     static void genflags_normal (flagtypes type, wordsizes size, char *value, char *src, char *dst)
579     {
580     char vstr[100], sstr[100], dstr[100];
581     char usstr[100], udstr[100];
582     char unsstr[100], undstr[100];
583    
584     switch (size) {
585     case sz_byte:
586     strcpy (vstr, "((uae_s8)(");
587     strcpy (usstr, "((uae_u8)(");
588     break;
589     case sz_word:
590     strcpy (vstr, "((uae_s16)(");
591     strcpy (usstr, "((uae_u16)(");
592     break;
593     case sz_long:
594     strcpy (vstr, "((uae_s32)(");
595     strcpy (usstr, "((uae_u32)(");
596     break;
597     default:
598     abort ();
599     }
600     strcpy (unsstr, usstr);
601    
602     strcpy (sstr, vstr);
603     strcpy (dstr, vstr);
604     strcat (vstr, value);
605     strcat (vstr, "))");
606     strcat (dstr, dst);
607     strcat (dstr, "))");
608     strcat (sstr, src);
609     strcat (sstr, "))");
610    
611     strcpy (udstr, usstr);
612     strcat (udstr, dst);
613     strcat (udstr, "))");
614     strcat (usstr, src);
615     strcat (usstr, "))");
616    
617     strcpy (undstr, unsstr);
618     strcat (unsstr, "-");
619     strcat (undstr, "~");
620     strcat (undstr, dst);
621     strcat (undstr, "))");
622     strcat (unsstr, src);
623     strcat (unsstr, "))");
624    
625     switch (type) {
626     case flag_logical_noclobber:
627     case flag_logical:
628 gbeauche 1.25 case flag_z:
629 cebix 1.1 case flag_zn:
630     case flag_av:
631     case flag_sv:
632     case flag_addx:
633     case flag_subx:
634     break;
635    
636     case flag_add:
637     start_brace ();
638     printf ("uae_u32 %s = %s + %s;\n", value, dstr, sstr);
639     break;
640     case flag_sub:
641     case flag_cmp:
642     start_brace ();
643     printf ("uae_u32 %s = %s - %s;\n", value, dstr, sstr);
644     break;
645     }
646    
647     switch (type) {
648     case flag_logical_noclobber:
649     case flag_logical:
650 gbeauche 1.25 case flag_z:
651 cebix 1.1 case flag_zn:
652     break;
653    
654     case flag_add:
655     case flag_sub:
656     case flag_addx:
657     case flag_subx:
658     case flag_cmp:
659     case flag_av:
660     case flag_sv:
661     start_brace ();
662     printf ("\t" BOOL_TYPE " flgs = %s < 0;\n", sstr);
663     printf ("\t" BOOL_TYPE " flgo = %s < 0;\n", dstr);
664     printf ("\t" BOOL_TYPE " flgn = %s < 0;\n", vstr);
665     break;
666     }
667    
668     switch (type) {
669     case flag_logical:
670     printf ("\tCLEAR_CZNV;\n");
671     printf ("\tSET_ZFLG (%s == 0);\n", vstr);
672     printf ("\tSET_NFLG (%s < 0);\n", vstr);
673     break;
674     case flag_logical_noclobber:
675     printf ("\tSET_ZFLG (%s == 0);\n", vstr);
676     printf ("\tSET_NFLG (%s < 0);\n", vstr);
677     break;
678     case flag_av:
679     printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n");
680     break;
681     case flag_sv:
682     printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
683     break;
684 gbeauche 1.25 case flag_z:
685     printf ("\tSET_ZFLG (GET_ZFLG & (%s == 0));\n", vstr);
686     break;
687 cebix 1.1 case flag_zn:
688     printf ("\tSET_ZFLG (GET_ZFLG & (%s == 0));\n", vstr);
689     printf ("\tSET_NFLG (%s < 0);\n", vstr);
690     break;
691     case flag_add:
692     printf ("\tSET_ZFLG (%s == 0);\n", vstr);
693     printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n");
694     printf ("\tSET_CFLG (%s < %s);\n", undstr, usstr);
695     duplicate_carry ();
696     printf ("\tSET_NFLG (flgn != 0);\n");
697     break;
698     case flag_sub:
699     printf ("\tSET_ZFLG (%s == 0);\n", vstr);
700     printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
701     printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr);
702     duplicate_carry ();
703     printf ("\tSET_NFLG (flgn != 0);\n");
704     break;
705     case flag_addx:
706     printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); /* minterm SON: 0x42 */
707     printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgo) & (flgo ^ flgn)));\n"); /* minterm SON: 0xD4 */
708     duplicate_carry ();
709     break;
710     case flag_subx:
711     printf ("\tSET_VFLG ((flgs ^ flgo) & (flgo ^ flgn));\n"); /* minterm SON: 0x24 */
712     printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgn) & (flgo ^ flgn)));\n"); /* minterm SON: 0xB2 */
713     duplicate_carry ();
714     break;
715     case flag_cmp:
716     printf ("\tSET_ZFLG (%s == 0);\n", vstr);
717     printf ("\tSET_VFLG ((flgs != flgo) && (flgn != flgo));\n");
718     printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr);
719     printf ("\tSET_NFLG (flgn != 0);\n");
720     break;
721     }
722     }
723    
724     static void genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst)
725     {
726 gbeauche 1.14 /* Temporarily deleted 68k/ARM flag optimizations. I'd prefer to have
727     them in the appropriate m68k.h files and use just one copy of this
728     code here. The API can be changed if necessary. */
729     #ifdef OPTIMIZED_FLAGS
730 cebix 1.1 switch (type) {
731     case flag_add:
732     case flag_sub:
733     start_brace ();
734     printf ("\tuae_u32 %s;\n", value);
735     break;
736     default:
737     break;
738     }
739    
740     /* At least some of those casts are fairly important! */
741     switch (type) {
742     case flag_logical_noclobber:
743 gbeauche 1.14 printf ("\t{uae_u32 oldcznv = GET_CZNV & ~(FLAGVAL_Z | FLAGVAL_N);\n");
744 cebix 1.1 if (strcmp (value, "0") == 0) {
745 gbeauche 1.14 printf ("\tSET_CZNV (olcznv | FLAGVAL_Z);\n");
746 cebix 1.1 } else {
747     switch (size) {
748 gbeauche 1.14 case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
749     case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
750     case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
751 cebix 1.1 }
752 gbeauche 1.14 printf ("\tIOR_CZNV (oldcznv);\n");
753 cebix 1.1 }
754     printf ("\t}\n");
755     return;
756 gbeauche 1.17
757 cebix 1.1 case flag_logical:
758     if (strcmp (value, "0") == 0) {
759 gbeauche 1.14 printf ("\tSET_CZNV (FLAGVAL_Z);\n");
760 cebix 1.1 } else {
761     switch (size) {
762 gbeauche 1.14 case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
763     case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
764     case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
765 cebix 1.1 }
766     }
767     return;
768    
769     case flag_add:
770     switch (size) {
771 gbeauche 1.14 case sz_byte: printf ("\toptflag_addb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
772     case sz_word: printf ("\toptflag_addw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
773     case sz_long: printf ("\toptflag_addl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
774 cebix 1.1 }
775     return;
776    
777     case flag_sub:
778     switch (size) {
779 gbeauche 1.14 case sz_byte: printf ("\toptflag_subb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
780     case sz_word: printf ("\toptflag_subw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
781     case sz_long: printf ("\toptflag_subl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
782 cebix 1.1 }
783     return;
784    
785     case flag_cmp:
786     switch (size) {
787 gbeauche 1.14 case sz_byte: printf ("\toptflag_cmpb ((uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break;
788     case sz_word: printf ("\toptflag_cmpw ((uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break;
789     case sz_long: printf ("\toptflag_cmpl ((uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break;
790 cebix 1.1 }
791     return;
792    
793     default:
794     break;
795     }
796 gbeauche 1.14 #endif
797 cebix 1.1 genflags_normal (type, size, value, src, dst);
798     }
799    
800     static void force_range_for_rox (const char *var, wordsizes size)
801     {
802     /* Could do a modulo operation here... which one is faster? */
803     switch (size) {
804     case sz_long:
805     printf ("\tif (%s >= 33) %s -= 33;\n", var, var);
806     break;
807     case sz_word:
808     printf ("\tif (%s >= 34) %s -= 34;\n", var, var);
809     printf ("\tif (%s >= 17) %s -= 17;\n", var, var);
810     break;
811     case sz_byte:
812     printf ("\tif (%s >= 36) %s -= 36;\n", var, var);
813     printf ("\tif (%s >= 18) %s -= 18;\n", var, var);
814     printf ("\tif (%s >= 9) %s -= 9;\n", var, var);
815     break;
816     }
817     }
818    
819     static const char *cmask (wordsizes size)
820     {
821     switch (size) {
822     case sz_byte: return "0x80";
823     case sz_word: return "0x8000";
824     case sz_long: return "0x80000000";
825     default: abort ();
826     }
827     }
828    
829     static int source_is_imm1_8 (struct instr *i)
830     {
831     return i->stype == 3;
832     }
833    
834     static void gen_opcode (unsigned long int opcode)
835     {
836     struct instr *curi = table68k + opcode;
837     insn_n_cycles = 2;
838    
839     start_brace ();
840     #if 0
841     printf ("uae_u8 *m68k_pc = regs.pc_p;\n");
842     #endif
843     m68k_pc_offset = 2;
844     switch (curi->plev) {
845     case 0: /* not privileged */
846     break;
847     case 1: /* unprivileged only on 68000 */
848     if (cpu_level == 0)
849     break;
850     if (next_cpu_level < 0)
851     next_cpu_level = 0;
852    
853     /* fall through */
854     case 2: /* priviledged */
855     printf ("if (!regs.s) { Exception(8,0); goto %s; }\n", endlabelstr);
856     need_endlabel = 1;
857     start_brace ();
858     break;
859     case 3: /* privileged if size == word */
860     if (curi->size == sz_byte)
861     break;
862     printf ("if (!regs.s) { Exception(8,0); goto %s; }\n", endlabelstr);
863     need_endlabel = 1;
864     start_brace ();
865     break;
866     }
867     switch (curi->mnemo) {
868     case i_OR:
869     case i_AND:
870     case i_EOR:
871     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
872     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
873     printf ("\tsrc %c= dst;\n", curi->mnemo == i_OR ? '|' : curi->mnemo == i_AND ? '&' : '^');
874     genflags (flag_logical, curi->size, "src", "", "");
875     genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
876     break;
877     case i_ORSR:
878     case i_EORSR:
879     printf ("\tMakeSR();\n");
880     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
881     if (curi->size == sz_byte) {
882     printf ("\tsrc &= 0xFF;\n");
883     }
884     printf ("\tregs.sr %c= src;\n", curi->mnemo == i_EORSR ? '^' : '|');
885     printf ("\tMakeFromSR();\n");
886     break;
887     case i_ANDSR:
888     printf ("\tMakeSR();\n");
889     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
890     if (curi->size == sz_byte) {
891     printf ("\tsrc |= 0xFF00;\n");
892     }
893     printf ("\tregs.sr &= src;\n");
894     printf ("\tMakeFromSR();\n");
895     break;
896     case i_SUB:
897     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
898     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
899     start_brace ();
900     genflags (flag_sub, curi->size, "newv", "src", "dst");
901     genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
902     break;
903     case i_SUBA:
904     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
905     genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
906     start_brace ();
907     printf ("\tuae_u32 newv = dst - src;\n");
908     genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
909     break;
910     case i_SUBX:
911     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
912     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
913     start_brace ();
914     printf ("\tuae_u32 newv = dst - src - (GET_XFLG ? 1 : 0);\n");
915     genflags (flag_subx, curi->size, "newv", "src", "dst");
916     genflags (flag_zn, curi->size, "newv", "", "");
917     genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
918     break;
919     case i_SBCD:
920     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
921     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
922     start_brace ();
923     printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG ? 1 : 0);\n");
924     printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n");
925 gbeauche 1.15 printf ("\tuae_u16 newv, tmp_newv;\n");
926     printf ("\tint bcd = 0;\n");
927     printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
928     printf ("\tif (newv_lo & 0xF0) { newv -= 6; bcd = 6; };\n");
929     printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n");
930     printf ("\tSET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG ? 1 : 0)) & 0x300) > 0xFF);\n");
931 cebix 1.1 duplicate_carry ();
932 gbeauche 1.25 /* Manual says bits NV are undefined though a real 68040 don't change them */
933     if (cpu_level >= xBCD_KEEPS_NV_FLAGS) {
934     if (next_cpu_level < xBCD_KEEPS_NV_FLAGS)
935     next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1;
936     genflags (flag_z, curi->size, "newv", "", "");
937     }
938     else {
939     genflags (flag_zn, curi->size, "newv", "", "");
940     printf ("\tSET_VFLG ((tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n");
941     }
942 cebix 1.1 genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
943     break;
944     case i_ADD:
945     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
946     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
947     start_brace ();
948     genflags (flag_add, curi->size, "newv", "src", "dst");
949     genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
950     break;
951     case i_ADDA:
952     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
953     genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
954     start_brace ();
955     printf ("\tuae_u32 newv = dst + src;\n");
956     genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
957     break;
958     case i_ADDX:
959     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
960     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
961     start_brace ();
962     printf ("\tuae_u32 newv = dst + src + (GET_XFLG ? 1 : 0);\n");
963     genflags (flag_addx, curi->size, "newv", "src", "dst");
964     genflags (flag_zn, curi->size, "newv", "", "");
965     genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
966     break;
967     case i_ABCD:
968     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
969     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
970     start_brace ();
971     printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG ? 1 : 0);\n");
972     printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n");
973 gbeauche 1.15 printf ("\tuae_u16 newv, tmp_newv;\n");
974 cebix 1.1 printf ("\tint cflg;\n");
975 gbeauche 1.17 printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
976 gbeauche 1.15 printf ("\tif (newv_lo > 9) { newv += 6; }\n");
977     printf ("\tcflg = (newv & 0x3F0) > 0x90;\n");
978     printf ("\tif (cflg) newv += 0x60;\n");
979 gbeauche 1.14 printf ("\tSET_CFLG (cflg);\n");
980 cebix 1.1 duplicate_carry ();
981 gbeauche 1.25 /* Manual says bits NV are undefined though a real 68040 don't change them */
982     if (cpu_level >= xBCD_KEEPS_NV_FLAGS) {
983     if (next_cpu_level < xBCD_KEEPS_NV_FLAGS)
984     next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1;
985     genflags (flag_z, curi->size, "newv", "", "");
986     }
987     else {
988     genflags (flag_zn, curi->size, "newv", "", "");
989     printf ("\tSET_VFLG ((tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n");
990     }
991 cebix 1.1 genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
992     break;
993     case i_NEG:
994     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
995     start_brace ();
996     genflags (flag_sub, curi->size, "dst", "src", "0");
997     genastore ("dst", curi->smode, "srcreg", curi->size, "src");
998     break;
999     case i_NEGX:
1000     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1001     start_brace ();
1002     printf ("\tuae_u32 newv = 0 - src - (GET_XFLG ? 1 : 0);\n");
1003     genflags (flag_subx, curi->size, "newv", "src", "0");
1004     genflags (flag_zn, curi->size, "newv", "", "");
1005     genastore ("newv", curi->smode, "srcreg", curi->size, "src");
1006     break;
1007     case i_NBCD:
1008     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1009     start_brace ();
1010     printf ("\tuae_u16 newv_lo = - (src & 0xF) - (GET_XFLG ? 1 : 0);\n");
1011     printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n");
1012     printf ("\tuae_u16 newv;\n");
1013     printf ("\tint cflg;\n");
1014 gbeauche 1.15 printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n");
1015 gbeauche 1.17 printf ("\tnewv = newv_hi + newv_lo;\n");
1016 gbeauche 1.15 printf ("\tcflg = (newv & 0x1F0) > 0x90;\n");
1017     printf ("\tif (cflg) newv -= 0x60;\n");
1018 gbeauche 1.14 printf ("\tSET_CFLG (cflg);\n");
1019 cebix 1.1 duplicate_carry();
1020 gbeauche 1.25 /* Manual says bits NV are undefined though a real 68040 don't change them */
1021     if (cpu_level >= xBCD_KEEPS_NV_FLAGS) {
1022     if (next_cpu_level < xBCD_KEEPS_NV_FLAGS)
1023     next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1;
1024     genflags (flag_z, curi->size, "newv", "", "");
1025     }
1026     else {
1027     genflags (flag_zn, curi->size, "newv", "", "");
1028     }
1029 cebix 1.1 genastore ("newv", curi->smode, "srcreg", curi->size, "src");
1030     break;
1031     case i_CLR:
1032     genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
1033     genflags (flag_logical, curi->size, "0", "", "");
1034     genastore ("0", curi->smode, "srcreg", curi->size, "src");
1035     break;
1036     case i_NOT:
1037     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1038     start_brace ();
1039     printf ("\tuae_u32 dst = ~src;\n");
1040     genflags (flag_logical, curi->size, "dst", "", "");
1041     genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1042     break;
1043     case i_TST:
1044     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1045     genflags (flag_logical, curi->size, "src", "", "");
1046     break;
1047     case i_BTST:
1048     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1049     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1050     if (curi->size == sz_byte)
1051     printf ("\tsrc &= 7;\n");
1052     else
1053     printf ("\tsrc &= 31;\n");
1054     printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
1055     break;
1056     case i_BCHG:
1057     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1058     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1059     if (curi->size == sz_byte)
1060     printf ("\tsrc &= 7;\n");
1061     else
1062     printf ("\tsrc &= 31;\n");
1063     printf ("\tdst ^= (1 << src);\n");
1064 gbeauche 1.14 printf ("\tSET_ZFLG (((uae_u32)dst & (1 << src)) >> src);\n");
1065 cebix 1.1 genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1066     break;
1067     case i_BCLR:
1068     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1069     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1070     if (curi->size == sz_byte)
1071     printf ("\tsrc &= 7;\n");
1072     else
1073     printf ("\tsrc &= 31;\n");
1074     printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
1075     printf ("\tdst &= ~(1 << src);\n");
1076     genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1077     break;
1078     case i_BSET:
1079     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1080     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1081     if (curi->size == sz_byte)
1082     printf ("\tsrc &= 7;\n");
1083     else
1084     printf ("\tsrc &= 31;\n");
1085     printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
1086     printf ("\tdst |= (1 << src);\n");
1087     genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1088     break;
1089     case i_CMPM:
1090     case i_CMP:
1091     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1092     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1093     start_brace ();
1094     genflags (flag_cmp, curi->size, "newv", "src", "dst");
1095     break;
1096     case i_CMPA:
1097     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1098     genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1099     start_brace ();
1100     genflags (flag_cmp, sz_long, "newv", "src", "dst");
1101     break;
1102     /* The next two are coded a little unconventional, but they are doing
1103     * weird things... */
1104     case i_MVPRM:
1105     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1106    
1107     printf ("\tuaecptr memp = m68k_areg(regs, dstreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword ());
1108     if (curi->size == sz_word) {
1109     printf ("\tput_byte(memp, src >> 8); put_byte(memp + 2, src);\n");
1110     } else {
1111     printf ("\tput_byte(memp, src >> 24); put_byte(memp + 2, src >> 16);\n");
1112     printf ("\tput_byte(memp + 4, src >> 8); put_byte(memp + 6, src);\n");
1113     }
1114     break;
1115     case i_MVPMR:
1116     printf ("\tuaecptr memp = m68k_areg(regs, srcreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword ());
1117     genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1118     if (curi->size == sz_word) {
1119     printf ("\tuae_u16 val = (get_byte(memp) << 8) + get_byte(memp + 2);\n");
1120     } else {
1121     printf ("\tuae_u32 val = (get_byte(memp) << 24) + (get_byte(memp + 2) << 16)\n");
1122     printf (" + (get_byte(memp + 4) << 8) + get_byte(memp + 6);\n");
1123     }
1124     genastore ("val", curi->dmode, "dstreg", curi->size, "dst");
1125     break;
1126     case i_MOVE:
1127     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1128     genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1129     genflags (flag_logical, curi->size, "src", "", "");
1130     genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
1131     break;
1132     case i_MOVEA:
1133     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1134     genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1135     if (curi->size == sz_word) {
1136     printf ("\tuae_u32 val = (uae_s32)(uae_s16)src;\n");
1137     } else {
1138     printf ("\tuae_u32 val = src;\n");
1139     }
1140     genastore ("val", curi->dmode, "dstreg", sz_long, "dst");
1141     break;
1142     case i_MVSR2:
1143     genamode (curi->smode, "srcreg", sz_word, "src", 2, 0);
1144     printf ("\tMakeSR();\n");
1145     if (curi->size == sz_byte)
1146     genastore ("regs.sr & 0xff", curi->smode, "srcreg", sz_word, "src");
1147     else
1148     genastore ("regs.sr", curi->smode, "srcreg", sz_word, "src");
1149     break;
1150     case i_MV2SR:
1151     genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1152     if (curi->size == sz_byte)
1153     printf ("\tMakeSR();\n\tregs.sr &= 0xFF00;\n\tregs.sr |= src & 0xFF;\n");
1154     else {
1155     printf ("\tregs.sr = src;\n");
1156     }
1157     printf ("\tMakeFromSR();\n");
1158     break;
1159     case i_SWAP:
1160     genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1161     start_brace ();
1162     printf ("\tuae_u32 dst = ((src >> 16)&0xFFFF) | ((src&0xFFFF)<<16);\n");
1163     genflags (flag_logical, sz_long, "dst", "", "");
1164     genastore ("dst", curi->smode, "srcreg", sz_long, "src");
1165     break;
1166     case i_EXG:
1167     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1168     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1169     genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1170     genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
1171     break;
1172     case i_EXT:
1173     genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1174     start_brace ();
1175     switch (curi->size) {
1176     case sz_byte: printf ("\tuae_u32 dst = (uae_s32)(uae_s8)src;\n"); break;
1177     case sz_word: printf ("\tuae_u16 dst = (uae_s16)(uae_s8)src;\n"); break;
1178     case sz_long: printf ("\tuae_u32 dst = (uae_s32)(uae_s16)src;\n"); break;
1179     default: abort ();
1180     }
1181     genflags (flag_logical,
1182     curi->size == sz_word ? sz_word : sz_long, "dst", "", "");
1183     genastore ("dst", curi->smode, "srcreg",
1184     curi->size == sz_word ? sz_word : sz_long, "src");
1185     break;
1186     case i_MVMEL:
1187     genmovemel (opcode);
1188     break;
1189     case i_MVMLE:
1190     genmovemle (opcode);
1191     break;
1192     case i_TRAP:
1193     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1194     sync_m68k_pc ();
1195     printf ("\tException(src+32,0);\n");
1196     m68k_pc_offset = 0;
1197     break;
1198     case i_MVR2USP:
1199     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1200     printf ("\tregs.usp = src;\n");
1201     break;
1202     case i_MVUSP2R:
1203     genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
1204     genastore ("regs.usp", curi->smode, "srcreg", curi->size, "src");
1205     break;
1206     case i_RESET:
1207     break;
1208     case i_NOP:
1209     break;
1210     case i_STOP:
1211     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1212     printf ("\tregs.sr = src;\n");
1213     printf ("\tMakeFromSR();\n");
1214     printf ("\tm68k_setstopped(1);\n");
1215     break;
1216     case i_RTE:
1217     if (cpu_level == 0) {
1218     genamode (Aipi, "7", sz_word, "sr", 1, 0);
1219     genamode (Aipi, "7", sz_long, "pc", 1, 0);
1220     printf ("\tregs.sr = sr; m68k_setpc_rte(pc);\n");
1221     fill_prefetch_0 ();
1222     printf ("\tMakeFromSR();\n");
1223     } else {
1224     int old_brace_level = n_braces;
1225     if (next_cpu_level < 0)
1226     next_cpu_level = 0;
1227     printf ("\tuae_u16 newsr; uae_u32 newpc; for (;;) {\n");
1228     genamode (Aipi, "7", sz_word, "sr", 1, 0);
1229     genamode (Aipi, "7", sz_long, "pc", 1, 0);
1230     genamode (Aipi, "7", sz_word, "format", 1, 0);
1231     printf ("\tnewsr = sr; newpc = pc;\n");
1232     printf ("\tif ((format & 0xF000) == 0x0000) { break; }\n");
1233     printf ("\telse if ((format & 0xF000) == 0x1000) { ; }\n");
1234     printf ("\telse if ((format & 0xF000) == 0x2000) { m68k_areg(regs, 7) += 4; break; }\n");
1235 gbeauche 1.17 /* gb-- the next two lines are deleted in Bernie's gencpu.c */
1236 cebix 1.6 printf ("\telse if ((format & 0xF000) == 0x3000) { m68k_areg(regs, 7) += 4; break; }\n");
1237     printf ("\telse if ((format & 0xF000) == 0x7000) { m68k_areg(regs, 7) += 52; break; }\n");
1238 cebix 1.1 printf ("\telse if ((format & 0xF000) == 0x8000) { m68k_areg(regs, 7) += 50; break; }\n");
1239     printf ("\telse if ((format & 0xF000) == 0x9000) { m68k_areg(regs, 7) += 12; break; }\n");
1240     printf ("\telse if ((format & 0xF000) == 0xa000) { m68k_areg(regs, 7) += 24; break; }\n");
1241     printf ("\telse if ((format & 0xF000) == 0xb000) { m68k_areg(regs, 7) += 84; break; }\n");
1242     printf ("\telse { Exception(14,0); goto %s; }\n", endlabelstr);
1243     printf ("\tregs.sr = newsr; MakeFromSR();\n}\n");
1244     pop_braces (old_brace_level);
1245     printf ("\tregs.sr = newsr; MakeFromSR();\n");
1246     printf ("\tm68k_setpc_rte(newpc);\n");
1247     fill_prefetch_0 ();
1248     need_endlabel = 1;
1249     }
1250     /* PC is set and prefetch filled. */
1251     m68k_pc_offset = 0;
1252     break;
1253     case i_RTD:
1254     genamode (Aipi, "7", sz_long, "pc", 1, 0);
1255     genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0);
1256     printf ("\tm68k_areg(regs, 7) += offs;\n");
1257     printf ("\tm68k_setpc_rte(pc);\n");
1258     fill_prefetch_0 ();
1259     /* PC is set and prefetch filled. */
1260     m68k_pc_offset = 0;
1261     break;
1262     case i_LINK:
1263     genamode (Apdi, "7", sz_long, "old", 2, 0);
1264     genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1265     genastore ("src", Apdi, "7", sz_long, "old");
1266     genastore ("m68k_areg(regs, 7)", curi->smode, "srcreg", sz_long, "src");
1267     genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0);
1268     printf ("\tm68k_areg(regs, 7) += offs;\n");
1269     break;
1270     case i_UNLK:
1271     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1272     printf ("\tm68k_areg(regs, 7) = src;\n");
1273     genamode (Aipi, "7", sz_long, "old", 1, 0);
1274     genastore ("old", curi->smode, "srcreg", curi->size, "src");
1275     break;
1276     case i_RTS:
1277     printf ("\tm68k_do_rts();\n");
1278     fill_prefetch_0 ();
1279     m68k_pc_offset = 0;
1280     break;
1281     case i_TRAPV:
1282     sync_m68k_pc ();
1283     printf ("\tif (GET_VFLG) { Exception(7,m68k_getpc()); goto %s; }\n", endlabelstr);
1284     need_endlabel = 1;
1285     break;
1286     case i_RTR:
1287     printf ("\tMakeSR();\n");
1288     genamode (Aipi, "7", sz_word, "sr", 1, 0);
1289     genamode (Aipi, "7", sz_long, "pc", 1, 0);
1290     printf ("\tregs.sr &= 0xFF00; sr &= 0xFF;\n");
1291     printf ("\tregs.sr |= sr; m68k_setpc(pc);\n");
1292     fill_prefetch_0 ();
1293     printf ("\tMakeFromSR();\n");
1294     m68k_pc_offset = 0;
1295     break;
1296     case i_JSR:
1297     genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1298     printf ("\tm68k_do_jsr(m68k_getpc() + %d, srca);\n", m68k_pc_offset);
1299     fill_prefetch_0 ();
1300     m68k_pc_offset = 0;
1301     break;
1302     case i_JMP:
1303     genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1304     printf ("\tm68k_setpc(srca);\n");
1305     fill_prefetch_0 ();
1306     m68k_pc_offset = 0;
1307     break;
1308     case i_BSR:
1309     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1310     printf ("\tuae_s32 s = (uae_s32)src + 2;\n");
1311     if (using_exception_3) {
1312     printf ("\tif (src & 1) {\n");
1313     printf ("\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n");
1314     printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + s;\n");
1315     printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr);
1316     printf ("\t}\n");
1317     need_endlabel = 1;
1318     }
1319     printf ("\tm68k_do_bsr(m68k_getpc() + %d, s);\n", m68k_pc_offset);
1320     fill_prefetch_0 ();
1321     m68k_pc_offset = 0;
1322     break;
1323     case i_Bcc:
1324 gbeauche 1.17 if (0 && !using_prefetch && !using_exception_3 && (cpu_level >= 2)) {
1325     /* gb-- variant probably more favorable to compiler optimizations
1326     also assumes no prefetch buffer is used
1327     Hmm, that would make sense with processors capable of conditional moves */
1328     if (curi->size == sz_long && next_cpu_level < 1)
1329     next_cpu_level = 1;
1330     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1331     printf ("\tm68k_incpc (cctrue(%d) ? ((uae_s32)src + 2) : %d);\n", curi->cc, m68k_pc_offset);
1332     m68k_pc_offset = 0;
1333     }
1334     else {
1335     /* original code for branch instructions */
1336 cebix 1.1 if (curi->size == sz_long) {
1337     if (cpu_level < 2) {
1338     printf ("\tm68k_incpc(2);\n");
1339     printf ("\tif (!cctrue(%d)) goto %s;\n", curi->cc, endlabelstr);
1340     printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n");
1341     printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + 1;\n");
1342     printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr);
1343     need_endlabel = 1;
1344     } else {
1345     if (next_cpu_level < 1)
1346     next_cpu_level = 1;
1347     }
1348     }
1349     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1350     printf ("\tif (!cctrue(%d)) goto didnt_jump;\n", curi->cc);
1351     if (using_exception_3) {
1352     printf ("\tif (src & 1) {\n");
1353     printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n");
1354     printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + 2 + (uae_s32)src;\n");
1355     printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr);
1356     printf ("\t}\n");
1357     need_endlabel = 1;
1358     }
1359     printf ("\tm68k_incpc ((uae_s32)src + 2);\n");
1360     fill_prefetch_0 ();
1361 gbeauche 1.20 printf ("return;\n");
1362 cebix 1.1 printf ("didnt_jump:;\n");
1363     need_endlabel = 1;
1364 gbeauche 1.17 }
1365 cebix 1.1 break;
1366     case i_LEA:
1367     genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1368     genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1369     genastore ("srca", curi->dmode, "dstreg", curi->size, "dst");
1370     break;
1371     case i_PEA:
1372     genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1373     genamode (Apdi, "7", sz_long, "dst", 2, 0);
1374     genastore ("srca", Apdi, "7", sz_long, "dst");
1375     break;
1376     case i_DBcc:
1377     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1378     genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0);
1379    
1380     printf ("\tif (!cctrue(%d)) {\n", curi->cc);
1381     genastore ("(src-1)", curi->smode, "srcreg", curi->size, "src");
1382    
1383     printf ("\t\tif (src) {\n");
1384     if (using_exception_3) {
1385     printf ("\t\t\tif (offs & 1) {\n");
1386     printf ("\t\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n");
1387     printf ("\t\t\tlast_fault_for_exception_3 = m68k_getpc() + 2 + (uae_s32)offs + 2;\n");
1388     printf ("\t\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr);
1389     printf ("\t\t}\n");
1390     need_endlabel = 1;
1391     }
1392     printf ("\t\t\tm68k_incpc((uae_s32)offs + 2);\n");
1393     fill_prefetch_0 ();
1394 gbeauche 1.20 printf ("return;\n");
1395 cebix 1.1 printf ("\t\t}\n");
1396     printf ("\t}\n");
1397     need_endlabel = 1;
1398     break;
1399     case i_Scc:
1400     genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
1401     start_brace ();
1402     printf ("\tint val = cctrue(%d) ? 0xff : 0;\n", curi->cc);
1403     genastore ("val", curi->smode, "srcreg", curi->size, "src");
1404     break;
1405     case i_DIVU:
1406     printf ("\tuaecptr oldpc = m68k_getpc();\n");
1407     genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1408     genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1409 gbeauche 1.14 sync_m68k_pc ();
1410     /* Clear V flag when dividing by zero - Alcatraz Odyssey demo depends
1411     * on this (actually, it's doing a DIVS). */
1412     printf ("\tif (src == 0) { SET_VFLG (0); Exception (5, oldpc); goto %s; } else {\n", endlabelstr);
1413 cebix 1.1 printf ("\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n");
1414     printf ("\tuae_u32 rem = (uae_u32)dst %% (uae_u32)(uae_u16)src;\n");
1415     /* The N flag appears to be set each time there is an overflow.
1416     * Weird. */
1417     printf ("\tif (newv > 0xffff) { SET_VFLG (1); SET_NFLG (1); SET_CFLG (0); } else\n\t{\n");
1418     genflags (flag_logical, sz_word, "newv", "", "");
1419     printf ("\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n");
1420     genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1421     printf ("\t}\n");
1422     printf ("\t}\n");
1423     insn_n_cycles += 68;
1424     need_endlabel = 1;
1425     break;
1426     case i_DIVS:
1427     printf ("\tuaecptr oldpc = m68k_getpc();\n");
1428     genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1429     genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1430 gbeauche 1.14 sync_m68k_pc ();
1431     printf ("\tif (src == 0) { SET_VFLG (0); Exception(5,oldpc); goto %s; } else {\n", endlabelstr);
1432 cebix 1.1 printf ("\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n");
1433     printf ("\tuae_u16 rem = (uae_s32)dst %% (uae_s32)(uae_s16)src;\n");
1434     printf ("\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) { SET_VFLG (1); SET_NFLG (1); SET_CFLG (0); } else\n\t{\n");
1435     printf ("\tif (((uae_s16)rem < 0) != ((uae_s32)dst < 0)) rem = -rem;\n");
1436     genflags (flag_logical, sz_word, "newv", "", "");
1437     printf ("\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n");
1438     genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1439     printf ("\t}\n");
1440     printf ("\t}\n");
1441     insn_n_cycles += 72;
1442     need_endlabel = 1;
1443     break;
1444     case i_MULU:
1445     genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1446     genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0);
1447     start_brace ();
1448     printf ("\tuae_u32 newv = (uae_u32)(uae_u16)dst * (uae_u32)(uae_u16)src;\n");
1449     genflags (flag_logical, sz_long, "newv", "", "");
1450     genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1451     insn_n_cycles += 32;
1452     break;
1453     case i_MULS:
1454     genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1455     genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0);
1456     start_brace ();
1457     printf ("\tuae_u32 newv = (uae_s32)(uae_s16)dst * (uae_s32)(uae_s16)src;\n");
1458     genflags (flag_logical, sz_long, "newv", "", "");
1459     genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1460     insn_n_cycles += 32;
1461     break;
1462     case i_CHK:
1463     printf ("\tuaecptr oldpc = m68k_getpc();\n");
1464     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1465     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1466     printf ("\tif ((uae_s32)dst < 0) { SET_NFLG (1); Exception(6,oldpc); goto %s; }\n", endlabelstr);
1467     printf ("\telse if (dst > src) { SET_NFLG (0); Exception(6,oldpc); goto %s; }\n", endlabelstr);
1468     need_endlabel = 1;
1469     break;
1470    
1471     case i_CHK2:
1472     printf ("\tuaecptr oldpc = m68k_getpc();\n");
1473     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1474     genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1475     printf ("\t{uae_s32 upper,lower,reg = regs.regs[(extra >> 12) & 15];\n");
1476     switch (curi->size) {
1477     case sz_byte:
1478     printf ("\tlower=(uae_s32)(uae_s8)get_byte(dsta); upper = (uae_s32)(uae_s8)get_byte(dsta+1);\n");
1479     printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s8)reg;\n");
1480     break;
1481     case sz_word:
1482     printf ("\tlower=(uae_s32)(uae_s16)get_word(dsta); upper = (uae_s32)(uae_s16)get_word(dsta+2);\n");
1483     printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s16)reg;\n");
1484     break;
1485     case sz_long:
1486     printf ("\tlower=get_long(dsta); upper = get_long(dsta+4);\n");
1487     break;
1488     default:
1489     abort ();
1490     }
1491     printf ("\tSET_ZFLG (upper == reg || lower == reg);\n");
1492 gbeauche 1.17 printf ("\tSET_CFLG_ALWAYS (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n");
1493 cebix 1.1 printf ("\tif ((extra & 0x800) && GET_CFLG) { Exception(6,oldpc); goto %s; }\n}\n", endlabelstr);
1494     need_endlabel = 1;
1495     break;
1496    
1497     case i_ASR:
1498     genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1499     genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1500     start_brace ();
1501     switch (curi->size) {
1502     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1503     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1504     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1505     default: abort ();
1506     }
1507     printf ("\tuae_u32 sign = (%s & val) >> %d;\n", cmask (curi->size), bit_size (curi->size) - 1);
1508     printf ("\tcnt &= 63;\n");
1509     printf ("\tCLEAR_CZNV;\n");
1510     printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
1511     printf ("\t\tval = %s & (uae_u32)-sign;\n", bit_mask (curi->size));
1512     printf ("\t\tSET_CFLG (sign);\n");
1513     duplicate_carry ();
1514     if (source_is_imm1_8 (curi))
1515     printf ("\t} else {\n");
1516     else
1517     printf ("\t} else if (cnt > 0) {\n");
1518     printf ("\t\tval >>= cnt - 1;\n");
1519     printf ("\t\tSET_CFLG (val & 1);\n");
1520     duplicate_carry ();
1521     printf ("\t\tval >>= 1;\n");
1522     printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-sign;\n",
1523     bit_mask (curi->size),
1524     bit_size (curi->size));
1525     printf ("\t\tval &= %s;\n", bit_mask (curi->size));
1526     printf ("\t}\n");
1527     genflags (flag_logical_noclobber, curi->size, "val", "", "");
1528     genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1529     break;
1530     case i_ASL:
1531     genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1532     genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1533     start_brace ();
1534     switch (curi->size) {
1535     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1536     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1537     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1538     default: abort ();
1539     }
1540     printf ("\tcnt &= 63;\n");
1541     printf ("\tCLEAR_CZNV;\n");
1542     printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
1543     printf ("\t\tSET_VFLG (val != 0);\n");
1544     printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n",
1545     bit_size (curi->size));
1546     duplicate_carry ();
1547     printf ("\t\tval = 0;\n");
1548     if (source_is_imm1_8 (curi))
1549     printf ("\t} else {\n");
1550     else
1551     printf ("\t} else if (cnt > 0) {\n");
1552     printf ("\t\tuae_u32 mask = (%s << (%d - cnt)) & %s;\n",
1553     bit_mask (curi->size),
1554     bit_size (curi->size) - 1,
1555     bit_mask (curi->size));
1556     printf ("\t\tSET_VFLG ((val & mask) != mask && (val & mask) != 0);\n");
1557     printf ("\t\tval <<= cnt - 1;\n");
1558     printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
1559     duplicate_carry ();
1560     printf ("\t\tval <<= 1;\n");
1561     printf ("\t\tval &= %s;\n", bit_mask (curi->size));
1562     printf ("\t}\n");
1563     genflags (flag_logical_noclobber, curi->size, "val", "", "");
1564     genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1565     break;
1566     case i_LSR:
1567     genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1568     genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1569     start_brace ();
1570     switch (curi->size) {
1571     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1572     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1573     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1574     default: abort ();
1575     }
1576     printf ("\tcnt &= 63;\n");
1577     printf ("\tCLEAR_CZNV;\n");
1578     printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
1579     printf ("\t\tSET_CFLG ((cnt == %d) & (val >> %d));\n",
1580     bit_size (curi->size), bit_size (curi->size) - 1);
1581     duplicate_carry ();
1582     printf ("\t\tval = 0;\n");
1583     if (source_is_imm1_8 (curi))
1584     printf ("\t} else {\n");
1585     else
1586     printf ("\t} else if (cnt > 0) {\n");
1587     printf ("\t\tval >>= cnt - 1;\n");
1588     printf ("\t\tSET_CFLG (val & 1);\n");
1589     duplicate_carry ();
1590     printf ("\t\tval >>= 1;\n");
1591     printf ("\t}\n");
1592     genflags (flag_logical_noclobber, curi->size, "val", "", "");
1593     genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1594     break;
1595     case i_LSL:
1596     genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1597     genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1598     start_brace ();
1599     switch (curi->size) {
1600     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1601     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1602     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1603     default: abort ();
1604     }
1605     printf ("\tcnt &= 63;\n");
1606     printf ("\tCLEAR_CZNV;\n");
1607     printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
1608     printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n",
1609     bit_size (curi->size));
1610     duplicate_carry ();
1611     printf ("\t\tval = 0;\n");
1612     if (source_is_imm1_8 (curi))
1613     printf ("\t} else {\n");
1614     else
1615     printf ("\t} else if (cnt > 0) {\n");
1616     printf ("\t\tval <<= (cnt - 1);\n");
1617     printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
1618     duplicate_carry ();
1619     printf ("\t\tval <<= 1;\n");
1620     printf ("\tval &= %s;\n", bit_mask (curi->size));
1621     printf ("\t}\n");
1622     genflags (flag_logical_noclobber, curi->size, "val", "", "");
1623     genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1624     break;
1625     case i_ROL:
1626     genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1627     genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1628     start_brace ();
1629     switch (curi->size) {
1630     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1631     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1632     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1633     default: abort ();
1634     }
1635     printf ("\tcnt &= 63;\n");
1636     printf ("\tCLEAR_CZNV;\n");
1637     if (source_is_imm1_8 (curi))
1638     printf ("{");
1639     else
1640     printf ("\tif (cnt > 0) {\n");
1641     printf ("\tuae_u32 loval;\n");
1642     printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1);
1643     printf ("\tloval = val >> (%d - cnt);\n", bit_size (curi->size));
1644     printf ("\tval <<= cnt;\n");
1645     printf ("\tval |= loval;\n");
1646     printf ("\tval &= %s;\n", bit_mask (curi->size));
1647     printf ("\tSET_CFLG (val & 1);\n");
1648     printf ("}\n");
1649     genflags (flag_logical_noclobber, curi->size, "val", "", "");
1650     genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1651     break;
1652     case i_ROR:
1653     genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1654     genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1655     start_brace ();
1656     switch (curi->size) {
1657     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1658     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1659     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1660     default: abort ();
1661     }
1662     printf ("\tcnt &= 63;\n");
1663     printf ("\tCLEAR_CZNV;\n");
1664     if (source_is_imm1_8 (curi))
1665     printf ("{");
1666     else
1667     printf ("\tif (cnt > 0) {");
1668     printf ("\tuae_u32 hival;\n");
1669     printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1);
1670     printf ("\thival = val << (%d - cnt);\n", bit_size (curi->size));
1671     printf ("\tval >>= cnt;\n");
1672     printf ("\tval |= hival;\n");
1673     printf ("\tval &= %s;\n", bit_mask (curi->size));
1674     printf ("\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
1675     printf ("\t}\n");
1676     genflags (flag_logical_noclobber, curi->size, "val", "", "");
1677     genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1678     break;
1679     case i_ROXL:
1680     genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1681     genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1682     start_brace ();
1683     switch (curi->size) {
1684     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1685     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1686     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1687     default: abort ();
1688     }
1689     printf ("\tcnt &= 63;\n");
1690     printf ("\tCLEAR_CZNV;\n");
1691     if (source_is_imm1_8 (curi))
1692     printf ("{");
1693 gbeauche 1.14 else {
1694     force_range_for_rox ("cnt", curi->size);
1695 cebix 1.1 printf ("\tif (cnt > 0) {\n");
1696 gbeauche 1.14 }
1697 cebix 1.1 printf ("\tcnt--;\n");
1698     printf ("\t{\n\tuae_u32 carry;\n");
1699     printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1);
1700     printf ("\tcarry = loval & 1;\n");
1701     printf ("\tval = (((val << 1) | GET_XFLG) << cnt) | (loval >> 1);\n");
1702     printf ("\tSET_XFLG (carry);\n");
1703     printf ("\tval &= %s;\n", bit_mask (curi->size));
1704     printf ("\t} }\n");
1705     printf ("\tSET_CFLG (GET_XFLG);\n");
1706     genflags (flag_logical_noclobber, curi->size, "val", "", "");
1707     genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1708     break;
1709     case i_ROXR:
1710     genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1711     genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1712     start_brace ();
1713     switch (curi->size) {
1714     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1715     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1716     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1717     default: abort ();
1718     }
1719     printf ("\tcnt &= 63;\n");
1720     printf ("\tCLEAR_CZNV;\n");
1721     if (source_is_imm1_8 (curi))
1722     printf ("{");
1723 gbeauche 1.14 else {
1724     force_range_for_rox ("cnt", curi->size);
1725 cebix 1.1 printf ("\tif (cnt > 0) {\n");
1726 gbeauche 1.14 }
1727 cebix 1.1 printf ("\tcnt--;\n");
1728     printf ("\t{\n\tuae_u32 carry;\n");
1729     printf ("\tuae_u32 hival = (val << 1) | GET_XFLG;\n");
1730     printf ("\thival <<= (%d - cnt);\n", bit_size (curi->size) - 1);
1731     printf ("\tval >>= cnt;\n");
1732     printf ("\tcarry = val & 1;\n");
1733     printf ("\tval >>= 1;\n");
1734     printf ("\tval |= hival;\n");
1735     printf ("\tSET_XFLG (carry);\n");
1736     printf ("\tval &= %s;\n", bit_mask (curi->size));
1737     printf ("\t} }\n");
1738     printf ("\tSET_CFLG (GET_XFLG);\n");
1739     genflags (flag_logical_noclobber, curi->size, "val", "", "");
1740     genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1741     break;
1742     case i_ASRW:
1743     genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1744     start_brace ();
1745     switch (curi->size) {
1746     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1747     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1748     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1749     default: abort ();
1750     }
1751     printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size));
1752     printf ("\tuae_u32 cflg = val & 1;\n");
1753     printf ("\tval = (val >> 1) | sign;\n");
1754     genflags (flag_logical, curi->size, "val", "", "");
1755     printf ("\tSET_CFLG (cflg);\n");
1756     duplicate_carry ();
1757     genastore ("val", curi->smode, "srcreg", curi->size, "data");
1758     break;
1759     case i_ASLW:
1760     genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1761     start_brace ();
1762     switch (curi->size) {
1763     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1764     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1765     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1766     default: abort ();
1767     }
1768     printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size));
1769     printf ("\tuae_u32 sign2;\n");
1770     printf ("\tval <<= 1;\n");
1771     genflags (flag_logical, curi->size, "val", "", "");
1772     printf ("\tsign2 = %s & val;\n", cmask (curi->size));
1773     printf ("\tSET_CFLG (sign != 0);\n");
1774     duplicate_carry ();
1775    
1776     printf ("\tSET_VFLG (GET_VFLG | (sign2 != sign));\n");
1777     genastore ("val", curi->smode, "srcreg", curi->size, "data");
1778     break;
1779     case i_LSRW:
1780     genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1781     start_brace ();
1782     switch (curi->size) {
1783     case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
1784     case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
1785     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1786     default: abort ();
1787     }
1788     printf ("\tuae_u32 carry = val & 1;\n");
1789     printf ("\tval >>= 1;\n");
1790     genflags (flag_logical, curi->size, "val", "", "");
1791     printf ("SET_CFLG (carry);\n");
1792     duplicate_carry ();
1793     genastore ("val", curi->smode, "srcreg", curi->size, "data");
1794     break;
1795     case i_LSLW:
1796     genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1797     start_brace ();
1798     switch (curi->size) {
1799     case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
1800     case sz_word: printf ("\tuae_u16 val = data;\n"); break;
1801     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1802     default: abort ();
1803     }
1804     printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
1805     printf ("\tval <<= 1;\n");
1806     genflags (flag_logical, curi->size, "val", "", "");
1807     printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
1808     duplicate_carry ();
1809     genastore ("val", curi->smode, "srcreg", curi->size, "data");
1810     break;
1811     case i_ROLW:
1812     genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1813     start_brace ();
1814     switch (curi->size) {
1815     case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
1816     case sz_word: printf ("\tuae_u16 val = data;\n"); break;
1817     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1818     default: abort ();
1819     }
1820     printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
1821     printf ("\tval <<= 1;\n");
1822     printf ("\tif (carry) val |= 1;\n");
1823     genflags (flag_logical, curi->size, "val", "", "");
1824     printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
1825     genastore ("val", curi->smode, "srcreg", curi->size, "data");
1826     break;
1827     case i_RORW:
1828     genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1829     start_brace ();
1830     switch (curi->size) {
1831     case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
1832     case sz_word: printf ("\tuae_u16 val = data;\n"); break;
1833     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1834     default: abort ();
1835     }
1836     printf ("\tuae_u32 carry = val & 1;\n");
1837     printf ("\tval >>= 1;\n");
1838     printf ("\tif (carry) val |= %s;\n", cmask (curi->size));
1839     genflags (flag_logical, curi->size, "val", "", "");
1840     printf ("SET_CFLG (carry);\n");
1841     genastore ("val", curi->smode, "srcreg", curi->size, "data");
1842     break;
1843     case i_ROXLW:
1844     genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1845     start_brace ();
1846     switch (curi->size) {
1847     case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
1848     case sz_word: printf ("\tuae_u16 val = data;\n"); break;
1849     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1850     default: abort ();
1851     }
1852     printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
1853     printf ("\tval <<= 1;\n");
1854     printf ("\tif (GET_XFLG) val |= 1;\n");
1855     genflags (flag_logical, curi->size, "val", "", "");
1856     printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
1857     duplicate_carry ();
1858     genastore ("val", curi->smode, "srcreg", curi->size, "data");
1859     break;
1860     case i_ROXRW:
1861     genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1862     start_brace ();
1863     switch (curi->size) {
1864     case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
1865     case sz_word: printf ("\tuae_u16 val = data;\n"); break;
1866     case sz_long: printf ("\tuae_u32 val = data;\n"); break;
1867     default: abort ();
1868     }
1869     printf ("\tuae_u32 carry = val & 1;\n");
1870     printf ("\tval >>= 1;\n");
1871     printf ("\tif (GET_XFLG) val |= %s;\n", cmask (curi->size));
1872     genflags (flag_logical, curi->size, "val", "", "");
1873     printf ("SET_CFLG (carry);\n");
1874     duplicate_carry ();
1875     genastore ("val", curi->smode, "srcreg", curi->size, "data");
1876     break;
1877     case i_MOVEC2:
1878     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1879     start_brace ();
1880     printf ("\tint regno = (src >> 12) & 15;\n");
1881     printf ("\tuae_u32 *regp = regs.regs + regno;\n");
1882 gbeauche 1.14 printf ("\tif (! m68k_movec2(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
1883 cebix 1.1 break;
1884     case i_MOVE2C:
1885     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1886     start_brace ();
1887     printf ("\tint regno = (src >> 12) & 15;\n");
1888     printf ("\tuae_u32 *regp = regs.regs + regno;\n");
1889 gbeauche 1.14 printf ("\tif (! m68k_move2c(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
1890 cebix 1.1 break;
1891     case i_CAS:
1892     {
1893     int old_brace_level;
1894     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1895     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1896     start_brace ();
1897     printf ("\tint ru = (src >> 6) & 7;\n");
1898     printf ("\tint rc = src & 7;\n");
1899     genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, rc)", "dst");
1900     printf ("\tif (GET_ZFLG)");
1901     old_brace_level = n_braces;
1902     start_brace ();
1903     genastore ("(m68k_dreg(regs, ru))", curi->dmode, "dstreg", curi->size, "dst");
1904     pop_braces (old_brace_level);
1905     printf ("else");
1906     start_brace ();
1907     printf ("m68k_dreg(regs, rc) = dst;\n");
1908     pop_braces (old_brace_level);
1909     }
1910     break;
1911     case i_CAS2:
1912     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1913     printf ("\tuae_u32 rn1 = regs.regs[(extra >> 28) & 15];\n");
1914     printf ("\tuae_u32 rn2 = regs.regs[(extra >> 12) & 15];\n");
1915     if (curi->size == sz_word) {
1916     int old_brace_level = n_braces;
1917     printf ("\tuae_u16 dst1 = get_word(rn1), dst2 = get_word(rn2);\n");
1918     genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, (extra >> 16) & 7)", "dst1");
1919     printf ("\tif (GET_ZFLG) {\n");
1920     genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, extra & 7)", "dst2");
1921     printf ("\tif (GET_ZFLG) {\n");
1922     printf ("\tput_word(rn1, m68k_dreg(regs, (extra >> 22) & 7));\n");
1923     printf ("\tput_word(rn1, m68k_dreg(regs, (extra >> 6) & 7));\n");
1924     printf ("\t}}\n");
1925     pop_braces (old_brace_level);
1926     printf ("\tif (! GET_ZFLG) {\n");
1927     printf ("\tm68k_dreg(regs, (extra >> 22) & 7) = (m68k_dreg(regs, (extra >> 22) & 7) & ~0xffff) | (dst1 & 0xffff);\n");
1928     printf ("\tm68k_dreg(regs, (extra >> 6) & 7) = (m68k_dreg(regs, (extra >> 6) & 7) & ~0xffff) | (dst2 & 0xffff);\n");
1929     printf ("\t}\n");
1930     } else {
1931     int old_brace_level = n_braces;
1932     printf ("\tuae_u32 dst1 = get_long(rn1), dst2 = get_long(rn2);\n");
1933     genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, (extra >> 16) & 7)", "dst1");
1934     printf ("\tif (GET_ZFLG) {\n");
1935     genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, extra & 7)", "dst2");
1936     printf ("\tif (GET_ZFLG) {\n");
1937     printf ("\tput_long(rn1, m68k_dreg(regs, (extra >> 22) & 7));\n");
1938     printf ("\tput_long(rn1, m68k_dreg(regs, (extra >> 6) & 7));\n");
1939     printf ("\t}}\n");
1940     pop_braces (old_brace_level);
1941     printf ("\tif (! GET_ZFLG) {\n");
1942     printf ("\tm68k_dreg(regs, (extra >> 22) & 7) = dst1;\n");
1943     printf ("\tm68k_dreg(regs, (extra >> 6) & 7) = dst2;\n");
1944     printf ("\t}\n");
1945     }
1946     break;
1947     case i_MOVES: /* ignore DFC and SFC because we have no MMU */
1948     {
1949     int old_brace_level;
1950     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1951     printf ("\tif (extra & 0x800)\n");
1952     old_brace_level = n_braces;
1953     start_brace ();
1954     printf ("\tuae_u32 src = regs.regs[(extra >> 12) & 15];\n");
1955     genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1956     genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
1957     pop_braces (old_brace_level);
1958     printf ("else");
1959     start_brace ();
1960     genamode (curi->dmode, "dstreg", curi->size, "src", 1, 0);
1961     printf ("\tif (extra & 0x8000) {\n");
1962     switch (curi->size) {
1963     case sz_byte: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = (uae_s32)(uae_s8)src;\n"); break;
1964     case sz_word: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = (uae_s32)(uae_s16)src;\n"); break;
1965     case sz_long: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = src;\n"); break;
1966     default: abort ();
1967     }
1968     printf ("\t} else {\n");
1969     genastore ("src", Dreg, "(extra >> 12) & 7", curi->size, "");
1970     printf ("\t}\n");
1971     pop_braces (old_brace_level);
1972     }
1973     break;
1974     case i_BKPT: /* only needed for hardware emulators */
1975     sync_m68k_pc ();
1976     printf ("\top_illg(opcode);\n");
1977     break;
1978     case i_CALLM: /* not present in 68030 */
1979     sync_m68k_pc ();
1980     printf ("\top_illg(opcode);\n");
1981     break;
1982     case i_RTM: /* not present in 68030 */
1983     sync_m68k_pc ();
1984     printf ("\top_illg(opcode);\n");
1985     break;
1986     case i_TRAPcc:
1987     if (curi->smode != am_unknown && curi->smode != am_illg)
1988     genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0);
1989     printf ("\tif (cctrue(%d)) { Exception(7,m68k_getpc()); goto %s; }\n", curi->cc, endlabelstr);
1990     need_endlabel = 1;
1991     break;
1992     case i_DIVL:
1993     sync_m68k_pc ();
1994     start_brace ();
1995     printf ("\tuaecptr oldpc = m68k_getpc();\n");
1996     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1997     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1998     sync_m68k_pc ();
1999     printf ("\tm68k_divl(opcode, dst, extra, oldpc);\n");
2000     break;
2001     case i_MULL:
2002     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2003     genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
2004     sync_m68k_pc ();
2005     printf ("\tm68k_mull(opcode, dst, extra);\n");
2006     break;
2007     case i_BFTST:
2008     case i_BFEXTU:
2009     case i_BFCHG:
2010     case i_BFEXTS:
2011     case i_BFCLR:
2012     case i_BFFFO:
2013     case i_BFSET:
2014     case i_BFINS:
2015     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2016     genamode (curi->dmode, "dstreg", sz_long, "dst", 2, 0);
2017     start_brace ();
2018     printf ("\tuae_s32 offset = extra & 0x800 ? m68k_dreg(regs, (extra >> 6) & 7) : (extra >> 6) & 0x1f;\n");
2019     printf ("\tint width = (((extra & 0x20 ? m68k_dreg(regs, extra & 7) : extra) -1) & 0x1f) +1;\n");
2020     if (curi->dmode == Dreg) {
2021     printf ("\tuae_u32 tmp = m68k_dreg(regs, dstreg) << (offset & 0x1f);\n");
2022     } else {
2023     printf ("\tuae_u32 tmp,bf0,bf1;\n");
2024     printf ("\tdsta += (offset >> 3) | (offset & 0x80000000 ? ~0x1fffffff : 0);\n");
2025     printf ("\tbf0 = get_long(dsta);bf1 = get_byte(dsta+4) & 0xff;\n");
2026     printf ("\ttmp = (bf0 << (offset & 7)) | (bf1 >> (8 - (offset & 7)));\n");
2027     }
2028     printf ("\ttmp >>= (32 - width);\n");
2029 gbeauche 1.17 printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width-1)) ? 1 : 0);\n");
2030 cebix 1.1 printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n");
2031     switch (curi->mnemo) {
2032     case i_BFTST:
2033     break;
2034     case i_BFEXTU:
2035     printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = tmp;\n");
2036     break;
2037     case i_BFCHG:
2038     printf ("\ttmp = ~tmp;\n");
2039     break;
2040     case i_BFEXTS:
2041     printf ("\tif (GET_NFLG) tmp |= width == 32 ? 0 : (-1 << width);\n");
2042     printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = tmp;\n");
2043     break;
2044     case i_BFCLR:
2045     printf ("\ttmp = 0;\n");
2046     break;
2047     case i_BFFFO:
2048     printf ("\t{ uae_u32 mask = 1 << (width-1);\n");
2049     printf ("\twhile (mask) { if (tmp & mask) break; mask >>= 1; offset++; }}\n");
2050     printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = offset;\n");
2051     break;
2052     case i_BFSET:
2053     printf ("\ttmp = 0xffffffff;\n");
2054     break;
2055     case i_BFINS:
2056     printf ("\ttmp = m68k_dreg(regs, (extra >> 12) & 7);\n");
2057 gbeauche 1.17 printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width - 1)) ? 1 : 0);\n");
2058 gbeauche 1.16 printf ("\tSET_ZFLG (tmp == 0);\n");
2059 cebix 1.1 break;
2060     default:
2061     break;
2062     }
2063     if (curi->mnemo == i_BFCHG
2064     || curi->mnemo == i_BFCLR
2065     || curi->mnemo == i_BFSET
2066     || curi->mnemo == i_BFINS)
2067     {
2068     printf ("\ttmp <<= (32 - width);\n");
2069     if (curi->dmode == Dreg) {
2070     printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & ((offset & 0x1f) == 0 ? 0 :\n");
2071     printf ("\t\t(0xffffffff << (32 - (offset & 0x1f))))) |\n");
2072     printf ("\t\t(tmp >> (offset & 0x1f)) |\n");
2073     printf ("\t\t(((offset & 0x1f) + width) >= 32 ? 0 :\n");
2074     printf (" (m68k_dreg(regs, dstreg) & ((uae_u32)0xffffffff >> ((offset & 0x1f) + width))));\n");
2075     } else {
2076     printf ("\tbf0 = (bf0 & (0xff000000 << (8 - (offset & 7)))) |\n");
2077     printf ("\t\t(tmp >> (offset & 7)) |\n");
2078     printf ("\t\t(((offset & 7) + width) >= 32 ? 0 :\n");
2079     printf ("\t\t (bf0 & ((uae_u32)0xffffffff >> ((offset & 7) + width))));\n");
2080     printf ("\tput_long(dsta,bf0 );\n");
2081     printf ("\tif (((offset & 7) + width) > 32) {\n");
2082     printf ("\t\tbf1 = (bf1 & (0xff >> (width - 32 + (offset & 7)))) |\n");
2083     printf ("\t\t\t(tmp << (8 - (offset & 7)));\n");
2084     printf ("\t\tput_byte(dsta+4,bf1);\n");
2085     printf ("\t}\n");
2086     }
2087     }
2088     break;
2089     case i_PACK:
2090     if (curi->smode == Dreg) {
2091     printf ("\tuae_u16 val = m68k_dreg(regs, srcreg) + %s;\n", gen_nextiword ());
2092     printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & 0xffffff00) | ((val >> 4) & 0xf0) | (val & 0xf);\n");
2093     } else {
2094     printf ("\tuae_u16 val;\n");
2095     printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n");
2096     printf ("\tval = (uae_u16)get_byte(m68k_areg(regs, srcreg));\n");
2097     printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n");
2098     printf ("\tval = (val | ((uae_u16)get_byte(m68k_areg(regs, srcreg)) << 8)) + %s;\n", gen_nextiword ());
2099     printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n");
2100     printf ("\tput_byte(m68k_areg(regs, dstreg),((val >> 4) & 0xf0) | (val & 0xf));\n");
2101     }
2102     break;
2103     case i_UNPK:
2104     if (curi->smode == Dreg) {
2105     printf ("\tuae_u16 val = m68k_dreg(regs, srcreg);\n");
2106     printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword ());
2107     printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & 0xffff0000) | (val & 0xffff);\n");
2108     } else {
2109     printf ("\tuae_u16 val;\n");
2110     printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n");
2111     printf ("\tval = (uae_u16)get_byte(m68k_areg(regs, srcreg));\n");
2112     printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword ());
2113     printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n");
2114     printf ("\tput_byte(m68k_areg(regs, dstreg),val);\n");
2115     printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n");
2116     printf ("\tput_byte(m68k_areg(regs, dstreg),val >> 8);\n");
2117     }
2118     break;
2119     case i_TAS:
2120     genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
2121     genflags (flag_logical, curi->size, "src", "", "");
2122     printf ("\tsrc |= 0x80;\n");
2123     genastore ("src", curi->smode, "srcreg", curi->size, "src");
2124     break;
2125     case i_FPP:
2126     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2127     sync_m68k_pc ();
2128     swap_opcode ();
2129 gbeauche 1.18 printf ("\tfpuop_arithmetic(opcode, extra);\n");
2130 cebix 1.1 break;
2131     case i_FDBcc:
2132     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2133     sync_m68k_pc ();
2134     swap_opcode ();
2135 gbeauche 1.18 printf ("\tfpuop_dbcc(opcode, extra);\n");
2136 cebix 1.1 break;
2137     case i_FScc:
2138     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2139     sync_m68k_pc ();
2140     swap_opcode ();
2141 gbeauche 1.18 printf ("\tfpuop_scc(opcode,extra);\n");
2142 cebix 1.1 break;
2143     case i_FTRAPcc:
2144     sync_m68k_pc ();
2145     start_brace ();
2146     printf ("\tuaecptr oldpc = m68k_getpc();\n");
2147     if (curi->smode != am_unknown && curi->smode != am_illg)
2148     genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0);
2149     sync_m68k_pc ();
2150     swap_opcode ();
2151 gbeauche 1.18 printf ("\tfpuop_trapcc(opcode,oldpc);\n");
2152 cebix 1.1 break;
2153     case i_FBcc:
2154     sync_m68k_pc ();
2155     start_brace ();
2156     printf ("\tuaecptr pc = m68k_getpc();\n");
2157     genamode (curi->dmode, "srcreg", curi->size, "extra", 1, 0);
2158     sync_m68k_pc ();
2159     swap_opcode ();
2160 gbeauche 1.18 printf ("\tfpuop_bcc(opcode,pc,extra);\n");
2161 cebix 1.1 break;
2162     case i_FSAVE:
2163     sync_m68k_pc ();
2164     swap_opcode ();
2165 gbeauche 1.18 printf ("\tfpuop_save(opcode);\n");
2166 cebix 1.1 break;
2167     case i_FRESTORE:
2168     sync_m68k_pc ();
2169     swap_opcode ();
2170 gbeauche 1.18 printf ("\tfpuop_restore(opcode);\n");
2171 cebix 1.1 break;
2172 cebix 1.6 case i_CINVL:
2173     case i_CINVP:
2174     case i_CINVA:
2175 gbeauche 1.19 /* gb-- srcreg now contains the cache field */
2176     printf ("\tif (srcreg&0x2)\n");
2177     printf ("\t\tflush_icache(%d);\n", 30 + ((opcode >> 3) & 3));
2178     break;
2179 cebix 1.6 case i_CPUSHL:
2180     case i_CPUSHP:
2181     case i_CPUSHA:
2182 gbeauche 1.19 /* gb-- srcreg now contains the cache field */
2183     printf ("\tif (srcreg&0x2)\n");
2184     printf ("\t\tflush_icache(%d);\n", 40 + ((opcode >> 3) & 3));
2185 cebix 1.6 break;
2186     case i_MOVE16:
2187 gbeauche 1.12 if ((opcode & 0xfff8) == 0xf620) {
2188     /* MOVE16 (Ax)+,(Ay)+ */
2189     printf ("\tuaecptr mems = m68k_areg(regs, srcreg) & ~15, memd;\n");
2190     printf ("\tdstreg = (%s >> 12) & 7;\n", gen_nextiword());
2191     printf ("\tmemd = m68k_areg(regs, dstreg) & ~15;\n");
2192     printf ("\tput_long(memd, get_long(mems));\n");
2193     printf ("\tput_long(memd+4, get_long(mems+4));\n");
2194     printf ("\tput_long(memd+8, get_long(mems+8));\n");
2195     printf ("\tput_long(memd+12, get_long(mems+12));\n");
2196     printf ("\tif (srcreg != dstreg)\n");
2197     printf ("\tm68k_areg(regs, srcreg) += 16;\n");
2198     printf ("\tm68k_areg(regs, dstreg) += 16;\n");
2199     }
2200     else {
2201     /* Other variants */
2202     genamode (curi->smode, "srcreg", curi->size, "mems", 0, 2);
2203     genamode (curi->dmode, "dstreg", curi->size, "memd", 0, 2);
2204     printf ("\tmemsa &= ~15;\n");
2205     printf ("\tmemda &= ~15;\n");
2206     printf ("\tput_long(memda, get_long(memsa));\n");
2207     printf ("\tput_long(memda+4, get_long(memsa+4));\n");
2208     printf ("\tput_long(memda+8, get_long(memsa+8));\n");
2209     printf ("\tput_long(memda+12, get_long(memsa+12));\n");
2210     if ((opcode & 0xfff8) == 0xf600)
2211     printf ("\tm68k_areg(regs, srcreg) += 16;\n");
2212     else if ((opcode & 0xfff8) == 0xf608)
2213     printf ("\tm68k_areg(regs, dstreg) += 16;\n");
2214     }
2215 cebix 1.6 break;
2216 cebix 1.1 case i_MMUOP:
2217     genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2218     sync_m68k_pc ();
2219     swap_opcode ();
2220     printf ("\tmmu_op(opcode,extra);\n");
2221     break;
2222 gbeauche 1.17
2223     case i_EMULOP_RETURN:
2224     printf ("\tm68k_emulop_return();\n");
2225     m68k_pc_offset = 0;
2226     break;
2227    
2228     case i_EMULOP:
2229     printf ("\n");
2230     swap_opcode ();
2231     printf ("\tm68k_emulop(opcode);\n");
2232     break;
2233    
2234 cebix 1.1 default:
2235     abort ();
2236     break;
2237     }
2238     finish_braces ();
2239     sync_m68k_pc ();
2240     }
2241    
2242     static void generate_includes (FILE * f)
2243     {
2244     fprintf (f, "#include \"sysdeps.h\"\n");
2245 gbeauche 1.17
2246 cebix 1.1 fprintf (f, "#include \"m68k.h\"\n");
2247     fprintf (f, "#include \"memory.h\"\n");
2248     fprintf (f, "#include \"readcpu.h\"\n");
2249     fprintf (f, "#include \"newcpu.h\"\n");
2250 gbeauche 1.19 fprintf (f, "#include \"compiler/compemu.h\"\n");
2251 gbeauche 1.18 fprintf (f, "#include \"fpu/fpu.h\"\n");
2252 cebix 1.1 fprintf (f, "#include \"cputbl.h\"\n");
2253 gbeauche 1.17
2254     fprintf (f, "#define SET_CFLG_ALWAYS(x) SET_CFLG(x)\n");
2255     fprintf (f, "#define SET_NFLG_ALWAYS(x) SET_NFLG(x)\n");
2256     fprintf (f, "#define CPUFUNC_FF(x) x##_ff\n");
2257     fprintf (f, "#define CPUFUNC_NF(x) x##_nf\n");
2258     fprintf (f, "#define CPUFUNC(x) CPUFUNC_FF(x)\n");
2259    
2260     fprintf (f, "#ifdef NOFLAGS\n");
2261     fprintf (f, "# include \"noflags.h\"\n");
2262     fprintf (f, "#endif\n");
2263 cebix 1.1 }
2264    
2265     static int postfix;
2266    
2267     static void generate_one_opcode (int rp)
2268     {
2269     uae_u16 smsk, dmsk;
2270     long int opcode = opcode_map[rp];
2271 gbeauche 1.24 const char *opcode_str;
2272 cebix 1.1
2273     if (table68k[opcode].mnemo == i_ILLG
2274     || table68k[opcode].clev > cpu_level)
2275     return;
2276    
2277     if (table68k[opcode].handler != -1)
2278     return;
2279    
2280 gbeauche 1.24 opcode_str = get_instruction_string (opcode);
2281    
2282 cebix 1.1 if (opcode_next_clev[rp] != cpu_level) {
2283 gbeauche 1.23 if (table68k[opcode].flagdead == 0)
2284     /* force to the "ff" variant since the instruction doesn't set at all the condition codes */
2285     fprintf (stblfile, "{ CPUFUNC_FF(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
2286 gbeauche 1.24 opcode, opcode_str);
2287 gbeauche 1.23 else
2288 gbeauche 1.17 fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
2289 gbeauche 1.24 opcode, opcode_str);
2290 cebix 1.1 return;
2291     }
2292 gbeauche 1.17
2293     if (table68k[opcode].flagdead == 0)
2294     /* force to the "ff" variant since the instruction doesn't set at all the condition codes */
2295 gbeauche 1.24 fprintf (stblfile, "{ CPUFUNC_FF(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, opcode_str);
2296 gbeauche 1.17 else
2297 gbeauche 1.24 fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, opcode_str);
2298 gbeauche 1.17
2299     fprintf (headerfile, "extern cpuop_func op_%lx_%d_nf;\n", opcode, postfix);
2300     fprintf (headerfile, "extern cpuop_func op_%lx_%d_ff;\n", opcode, postfix);
2301    
2302     /* gb-- The "nf" variant for an instruction that doesn't set the condition
2303     codes at all is the same as the "ff" variant, so we don't need the "nf"
2304     variant to be compiled since it is mapped to the "ff" variant in the
2305     smalltbl. */
2306     if (table68k[opcode].flagdead == 0)
2307     printf ("#ifndef NOFLAGS\n");
2308 cebix 1.1
2309 gbeauche 1.24 printf ("void REGPARAM2 CPUFUNC(op_%lx_%d)(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, opcode_str);
2310 gbeauche 1.23 printf ("\tcpuop_begin();\n");
2311    
2312 cebix 1.1 switch (table68k[opcode].stype) {
2313     case 0: smsk = 7; break;
2314     case 1: smsk = 255; break;
2315     case 2: smsk = 15; break;
2316     case 3: smsk = 7; break;
2317     case 4: smsk = 7; break;
2318     case 5: smsk = 63; break;
2319 gbeauche 1.17 case 6: smsk = 255; break;
2320 gbeauche 1.12 case 7: smsk = 3; break;
2321 cebix 1.1 default: abort ();
2322     }
2323     dmsk = 7;
2324    
2325     next_cpu_level = -1;
2326     if (table68k[opcode].suse
2327     && table68k[opcode].smode != imm && table68k[opcode].smode != imm0
2328     && table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2
2329     && table68k[opcode].smode != absw && table68k[opcode].smode != absl
2330 gbeauche 1.17 && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16
2331     /* gb-- We don't want to fetch the EmulOp code since the EmulOp()
2332     routine uses the whole opcode value. Maybe all the EmulOps
2333     could be expanded out but I don't think it is an improvement */
2334     && table68k[opcode].stype != 6
2335     )
2336 cebix 1.1 {
2337     if (table68k[opcode].spos == -1) {
2338     if (((int) table68k[opcode].sreg) >= 128)
2339     printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].sreg);
2340     else
2341     printf ("\tuae_u32 srcreg = %d;\n", (int) table68k[opcode].sreg);
2342     } else {
2343     char source[100];
2344     int pos = table68k[opcode].spos;
2345    
2346     #if 0
2347     /* Check that we can do the little endian optimization safely. */
2348     if (pos < 8 && (smsk >> (8 - pos)) != 0)
2349     abort ();
2350     #endif
2351     printf ("#ifdef HAVE_GET_WORD_UNSWAPPED\n");
2352    
2353     if (pos < 8 && (smsk >> (8 - pos)) != 0)
2354     sprintf (source, "(((opcode >> %d) | (opcode << %d)) & %d)",
2355     pos ^ 8, 8 - pos, dmsk);
2356     else if (pos != 8)
2357     sprintf (source, "((opcode >> %d) & %d)", pos ^ 8, smsk);
2358     else
2359     sprintf (source, "(opcode & %d)", smsk);
2360    
2361     if (table68k[opcode].stype == 3)
2362     printf ("\tuae_u32 srcreg = imm8_table[%s];\n", source);
2363     else if (table68k[opcode].stype == 1)
2364     printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source);
2365     else
2366     printf ("\tuae_u32 srcreg = %s;\n", source);
2367    
2368     printf ("#else\n");
2369    
2370     if (pos)
2371     sprintf (source, "((opcode >> %d) & %d)", pos, smsk);
2372     else
2373     sprintf (source, "(opcode & %d)", smsk);
2374    
2375     if (table68k[opcode].stype == 3)
2376     printf ("\tuae_u32 srcreg = imm8_table[%s];\n", source);
2377     else if (table68k[opcode].stype == 1)
2378     printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source);
2379     else
2380     printf ("\tuae_u32 srcreg = %s;\n", source);
2381    
2382     printf ("#endif\n");
2383     }
2384     }
2385     if (table68k[opcode].duse
2386     /* Yes, the dmode can be imm, in case of LINK or DBcc */
2387     && table68k[opcode].dmode != imm && table68k[opcode].dmode != imm0
2388     && table68k[opcode].dmode != imm1 && table68k[opcode].dmode != imm2
2389     && table68k[opcode].dmode != absw && table68k[opcode].dmode != absl)
2390     {
2391     if (table68k[opcode].dpos == -1) {
2392     if (((int) table68k[opcode].dreg) >= 128)
2393     printf ("\tuae_u32 dstreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].dreg);
2394     else
2395     printf ("\tuae_u32 dstreg = %d;\n", (int) table68k[opcode].dreg);
2396     } else {
2397     int pos = table68k[opcode].dpos;
2398     #if 0
2399     /* Check that we can do the little endian optimization safely. */
2400     if (pos < 8 && (dmsk >> (8 - pos)) != 0)
2401     abort ();
2402     #endif
2403     printf ("#ifdef HAVE_GET_WORD_UNSWAPPED\n");
2404    
2405     if (pos < 8 && (dmsk >> (8 - pos)) != 0)
2406     printf ("\tuae_u32 dstreg = ((opcode >> %d) | (opcode << %d)) & %d;\n",
2407     pos ^ 8, 8 - pos, dmsk);
2408     else if (pos != 8)
2409     printf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n",
2410     pos ^ 8, dmsk);
2411     else
2412     printf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk);
2413    
2414     printf ("#else\n");
2415    
2416     if (pos)
2417     printf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n",
2418     pos, dmsk);
2419     else
2420     printf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk);
2421    
2422     printf ("#endif\n");
2423     }
2424     }
2425     need_endlabel = 0;
2426     endlabelno++;
2427     sprintf (endlabelstr, "endlabel%d", endlabelno);
2428     gen_opcode (opcode);
2429     if (need_endlabel)
2430     printf ("%s: ;\n", endlabelstr);
2431 gbeauche 1.23 printf ("\tcpuop_end();\n");
2432     printf ("}\n");
2433 gbeauche 1.17 if (table68k[opcode].flagdead == 0)
2434     printf ("\n#endif\n");
2435 cebix 1.1 opcode_next_clev[rp] = next_cpu_level;
2436     opcode_last_postfix[rp] = postfix;
2437     }
2438    
2439     static void generate_func (void)
2440     {
2441     int i, j, rp;
2442    
2443     using_prefetch = 0;
2444     using_exception_3 = 0;
2445 gbeauche 1.11 #if !USE_PREFETCH_BUFFER
2446     /* gb-- No need for a prefetch buffer, nor exception 3 handling */
2447     /* Anyway, Basilisk2 does not use the op_smalltbl_5 table... */
2448     for (i = 0; i <= 4; i++) {
2449     #else
2450 cebix 1.6 for (i = 0; i < 6; i++) {
2451 gbeauche 1.11 #endif
2452 cebix 1.6 cpu_level = 4 - i;
2453     if (i == 5) {
2454 cebix 1.1 cpu_level = 0;
2455     using_prefetch = 1;
2456     using_exception_3 = 1;
2457     for (rp = 0; rp < nr_cpuop_funcs; rp++)
2458     opcode_next_clev[rp] = 0;
2459     }
2460     postfix = i;
2461 gbeauche 1.17 fprintf (stblfile, "struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix);
2462 cebix 1.1
2463     /* sam: this is for people with low memory (eg. me :)) */
2464     printf ("\n"
2465     "#if !defined(PART_1) && !defined(PART_2) && "
2466     "!defined(PART_3) && !defined(PART_4) && "
2467     "!defined(PART_5) && !defined(PART_6) && "
2468     "!defined(PART_7) && !defined(PART_8)"
2469     "\n"
2470     "#define PART_1 1\n"
2471     "#define PART_2 1\n"
2472     "#define PART_3 1\n"
2473     "#define PART_4 1\n"
2474     "#define PART_5 1\n"
2475     "#define PART_6 1\n"
2476     "#define PART_7 1\n"
2477     "#define PART_8 1\n"
2478     "#endif\n\n");
2479    
2480     rp = 0;
2481     for(j=1;j<=8;++j) {
2482     int k = (j*nr_cpuop_funcs)/8;
2483     printf ("#ifdef PART_%d\n",j);
2484     for (; rp < k; rp++)
2485     generate_one_opcode (rp);
2486     printf ("#endif\n\n");
2487     }
2488    
2489     fprintf (stblfile, "{ 0, 0, 0 }};\n");
2490     }
2491     }
2492    
2493     int main (int argc, char **argv)
2494     {
2495 gbeauche 1.22 FILE *out;
2496 cebix 1.1 read_table68k ();
2497     do_merges ();
2498    
2499     opcode_map = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
2500     opcode_last_postfix = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
2501     opcode_next_clev = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
2502     counts = (unsigned long *) malloc (65536 * sizeof (unsigned long));
2503     read_counts ();
2504    
2505     /* It would be a lot nicer to put all in one file (we'd also get rid of
2506     * cputbl.h that way), but cpuopti can't cope. That could be fixed, but
2507     * I don't dare to touch the 68k version. */
2508    
2509 gbeauche 1.21 headerfile = fopen ("cputbl.h", "w");
2510     stblfile = fopen ("cpustbl.cpp", "w");
2511 gbeauche 1.22 out = freopen ("cpuemu.cpp", "w", stdout);
2512 cebix 1.1
2513     generate_includes (stdout);
2514     generate_includes (stblfile);
2515    
2516     generate_func ();
2517    
2518     free (table68k);
2519 gbeauche 1.21 fclose (headerfile);
2520     fclose (stblfile);
2521     fflush (out);
2522 cebix 1.1 return 0;
2523     }