Annotation of uae/src/gencpu.c, revision 1.1.1.13

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.