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

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

unix.superglobalmegacorp.com

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