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

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

unix.superglobalmegacorp.com

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