Search
lxdream.org :: lxdream/src/sh4/sh4core.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.c
changeset 626:a010e30a30e9
prev617:476a717a54f3
next641:afb9a42c61c6
author nkeynes
date Fri Feb 08 00:06:56 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Fix LDS/STS to FPUL/FPSCR to check the FPU disabled bit. Fixes
the linux 2.4.0-test8 kernel boot
(this wasn't exactly very well documented in the original manual)
file annotate diff log raw
nkeynes@23
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@23
     3
 * 
nkeynes@23
     4
 * SH4 emulation core, and parent module for all the SH4 peripheral
nkeynes@23
     5
 * modules.
nkeynes@23
     6
 *
nkeynes@23
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@23
     8
 *
nkeynes@23
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@23
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@23
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@23
    12
 * (at your option) any later version.
nkeynes@23
    13
 *
nkeynes@23
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@23
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@23
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@23
    17
 * GNU General Public License for more details.
nkeynes@23
    18
 */
nkeynes@23
    19
nkeynes@35
    20
#define MODULE sh4_module
nkeynes@586
    21
#include <assert.h>
nkeynes@1
    22
#include <math.h>
nkeynes@1
    23
#include "dream.h"
nkeynes@430
    24
#include "dreamcast.h"
nkeynes@430
    25
#include "eventq.h"
nkeynes@430
    26
#include "mem.h"
nkeynes@430
    27
#include "clock.h"
nkeynes@430
    28
#include "syscall.h"
nkeynes@84
    29
#include "sh4/sh4core.h"
nkeynes@84
    30
#include "sh4/sh4mmio.h"
nkeynes@84
    31
#include "sh4/intc.h"
nkeynes@1
    32
nkeynes@157
    33
#define SH4_CALLTRACE 1
nkeynes@157
    34
nkeynes@123
    35
#define MAX_INT 0x7FFFFFFF
nkeynes@123
    36
#define MIN_INT 0x80000000
nkeynes@123
    37
#define MAX_INTF 2147483647.0
nkeynes@123
    38
#define MIN_INTF -2147483648.0
nkeynes@123
    39
nkeynes@23
    40
/********************** SH4 Module Definition ****************************/
nkeynes@23
    41
nkeynes@30
    42
uint32_t sh4_run_slice( uint32_t nanosecs ) 
nkeynes@1
    43
{
nkeynes@23
    44
    int i;
nkeynes@265
    45
    sh4r.slice_cycle = 0;
nkeynes@23
    46
nkeynes@27
    47
    if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
nkeynes@617
    48
	sh4_sleep_run_slice(nanosecs);
nkeynes@23
    49
    }
nkeynes@27
    50
nkeynes@235
    51
    if( sh4_breakpoint_count == 0 ) {
nkeynes@265
    52
	for( ; sh4r.slice_cycle < nanosecs; sh4r.slice_cycle += sh4_cpu_period ) {
nkeynes@265
    53
	    if( SH4_EVENT_PENDING() ) {
nkeynes@265
    54
		if( sh4r.event_types & PENDING_EVENT ) {
nkeynes@265
    55
		    event_execute();
nkeynes@265
    56
		}
nkeynes@265
    57
		/* Eventq execute may (quite likely) deliver an immediate IRQ */
nkeynes@265
    58
		if( sh4r.event_types & PENDING_IRQ ) {
nkeynes@265
    59
		    sh4_accept_interrupt();
nkeynes@265
    60
		}
nkeynes@265
    61
	    }
nkeynes@235
    62
	    if( !sh4_execute_instruction() ) {
nkeynes@43
    63
		break;
nkeynes@43
    64
	    }
nkeynes@43
    65
	}
nkeynes@235
    66
    } else {
nkeynes@265
    67
	for( ;sh4r.slice_cycle < nanosecs; sh4r.slice_cycle += sh4_cpu_period ) {
nkeynes@265
    68
	    if( SH4_EVENT_PENDING() ) {
nkeynes@265
    69
		if( sh4r.event_types & PENDING_EVENT ) {
nkeynes@265
    70
		    event_execute();
nkeynes@265
    71
		}
nkeynes@265
    72
		/* Eventq execute may (quite likely) deliver an immediate IRQ */
nkeynes@265
    73
		if( sh4r.event_types & PENDING_IRQ ) {
nkeynes@265
    74
		    sh4_accept_interrupt();
nkeynes@265
    75
		}
nkeynes@265
    76
	    }
nkeynes@265
    77
                 
nkeynes@235
    78
	    if( !sh4_execute_instruction() )
nkeynes@235
    79
		break;
nkeynes@235
    80
#ifdef ENABLE_DEBUG_MODE
nkeynes@235
    81
	    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@235
    82
		if( sh4_breakpoints[i].address == sh4r.pc ) {
nkeynes@235
    83
		    break;
nkeynes@235
    84
		}
nkeynes@235
    85
	    }
nkeynes@235
    86
	    if( i != sh4_breakpoint_count ) {
nkeynes@235
    87
		dreamcast_stop();
nkeynes@235
    88
		if( sh4_breakpoints[i].type == BREAK_ONESHOT )
nkeynes@235
    89
		    sh4_clear_breakpoint( sh4r.pc, BREAK_ONESHOT );
nkeynes@235
    90
		break;
nkeynes@235
    91
	    }
nkeynes@235
    92
#endif	
nkeynes@43
    93
	}
nkeynes@27
    94
    }
nkeynes@30
    95
nkeynes@30
    96
    /* If we aborted early, but the cpu is still technically running,
nkeynes@30
    97
     * we're doing a hard abort - cut the timeslice back to what we
nkeynes@30
    98
     * actually executed
nkeynes@30
    99
     */
nkeynes@53
   100
    if( sh4r.slice_cycle != nanosecs && sh4r.sh4_state == SH4_STATE_RUNNING ) {
nkeynes@53
   101
	nanosecs = sh4r.slice_cycle;
nkeynes@27
   102
    }
nkeynes@27
   103
    if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
nkeynes@30
   104
	TMU_run_slice( nanosecs );
nkeynes@30
   105
	SCIF_run_slice( nanosecs );
nkeynes@27
   106
    }
nkeynes@30
   107
    return nanosecs;
nkeynes@1
   108
}
nkeynes@1
   109
nkeynes@23
   110
/********************** SH4 emulation core  ****************************/
nkeynes@23
   111
nkeynes@246
   112
#define UNDEF(ir) return sh4_raise_slot_exception(EXC_ILLEGAL, EXC_SLOT_ILLEGAL)
nkeynes@27
   113
#define UNIMP(ir) do{ ERROR( "Halted on unimplemented instruction at %08x, opcode = %04x", sh4r.pc, ir ); dreamcast_stop(); return FALSE; }while(0)
nkeynes@1
   114
nkeynes@157
   115
#if(SH4_CALLTRACE == 1)
nkeynes@157
   116
#define MAX_CALLSTACK 32
nkeynes@157
   117
static struct call_stack {
nkeynes@157
   118
    sh4addr_t call_addr;
nkeynes@157
   119
    sh4addr_t target_addr;
nkeynes@157
   120
    sh4addr_t stack_pointer;
nkeynes@157
   121
} call_stack[MAX_CALLSTACK];
nkeynes@157
   122
nkeynes@157
   123
static int call_stack_depth = 0;
nkeynes@157
   124
int sh4_call_trace_on = 0;
nkeynes@157
   125
nkeynes@430
   126
static inline void trace_call( sh4addr_t source, sh4addr_t dest ) 
nkeynes@157
   127
{
nkeynes@157
   128
    if( call_stack_depth < MAX_CALLSTACK ) {
nkeynes@157
   129
	call_stack[call_stack_depth].call_addr = source;
nkeynes@157
   130
	call_stack[call_stack_depth].target_addr = dest;
nkeynes@157
   131
	call_stack[call_stack_depth].stack_pointer = sh4r.r[15];
nkeynes@157
   132
    }
nkeynes@157
   133
    call_stack_depth++;
nkeynes@157
   134
}
nkeynes@157
   135
nkeynes@430
   136
static inline void trace_return( sh4addr_t source, sh4addr_t dest )
nkeynes@157
   137
{
nkeynes@157
   138
    if( call_stack_depth > 0 ) {
nkeynes@157
   139
	call_stack_depth--;
nkeynes@157
   140
    }
nkeynes@157
   141
}
nkeynes@157
   142
nkeynes@157
   143
void fprint_stack_trace( FILE *f )
nkeynes@157
   144
{
nkeynes@157
   145
    int i = call_stack_depth -1;
nkeynes@157
   146
    if( i >= MAX_CALLSTACK )
nkeynes@157
   147
	i = MAX_CALLSTACK - 1;
nkeynes@157
   148
    for( ; i >= 0; i-- ) {
nkeynes@157
   149
	fprintf( f, "%d. Call from %08X => %08X, SP=%08X\n", 
nkeynes@157
   150
		 (call_stack_depth - i), call_stack[i].call_addr,
nkeynes@157
   151
		 call_stack[i].target_addr, call_stack[i].stack_pointer );
nkeynes@157
   152
    }
nkeynes@157
   153
}
nkeynes@157
   154
nkeynes@157
   155
#define TRACE_CALL( source, dest ) trace_call(source, dest)
nkeynes@157
   156
#define TRACE_RETURN( source, dest ) trace_return(source, dest)
nkeynes@157
   157
#else
nkeynes@157
   158
#define TRACE_CALL( dest, rts ) 
nkeynes@157
   159
#define TRACE_RETURN( source, dest )
nkeynes@157
   160
#endif
nkeynes@157
   161
nkeynes@586
   162
#define MEM_READ_BYTE( addr, val ) memtmp = mmu_vma_to_phys_read(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { val = sh4_read_byte(memtmp); }
nkeynes@586
   163
#define MEM_READ_WORD( addr, val ) memtmp = mmu_vma_to_phys_read(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { val = sh4_read_word(memtmp); }
nkeynes@586
   164
#define MEM_READ_LONG( addr, val ) memtmp = mmu_vma_to_phys_read(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { val = sh4_read_long(memtmp); }
nkeynes@586
   165
#define MEM_WRITE_BYTE( addr, val ) memtmp = mmu_vma_to_phys_write(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { sh4_write_byte(memtmp, val); }
nkeynes@586
   166
#define MEM_WRITE_WORD( addr, val ) memtmp = mmu_vma_to_phys_write(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { sh4_write_word(memtmp, val); }
nkeynes@586
   167
#define MEM_WRITE_LONG( addr, val ) memtmp = mmu_vma_to_phys_write(addr); if( memtmp == MMU_VMA_ERROR ) { return TRUE; } else { sh4_write_long(memtmp, val); }
nkeynes@1
   168
nkeynes@1
   169
#define FP_WIDTH (IS_FPU_DOUBLESIZE() ? 8 : 4)
nkeynes@1
   170
nkeynes@124
   171
#define MEM_FP_READ( addr, reg ) sh4_read_float( addr, reg );
nkeynes@124
   172
#define MEM_FP_WRITE( addr, reg ) sh4_write_float( addr, reg );
nkeynes@84
   173
nkeynes@246
   174
#define CHECKPRIV() if( !IS_SH4_PRIVMODE() ) return sh4_raise_slot_exception( EXC_ILLEGAL, EXC_SLOT_ILLEGAL )
nkeynes@367
   175
#define CHECKRALIGN16(addr) if( (addr)&0x01 ) return sh4_raise_exception( EXC_DATA_ADDR_READ )
nkeynes@367
   176
#define CHECKRALIGN32(addr) if( (addr)&0x03 ) return sh4_raise_exception( EXC_DATA_ADDR_READ )
nkeynes@367
   177
#define CHECKWALIGN16(addr) if( (addr)&0x01 ) return sh4_raise_exception( EXC_DATA_ADDR_WRITE )
nkeynes@367
   178
#define CHECKWALIGN32(addr) if( (addr)&0x03 ) return sh4_raise_exception( EXC_DATA_ADDR_WRITE )
nkeynes@208
   179
nkeynes@367
   180
#define CHECKFPUEN() if( !IS_FPU_ENABLED() ) { if( ir == 0xFFFD ) { UNDEF(ir); } else { return sh4_raise_slot_exception( EXC_FPU_DISABLED, EXC_SLOT_FPU_DISABLED ); } }
nkeynes@84
   181
#define CHECKDEST(p) if( (p) == 0 ) { ERROR( "%08X: Branch/jump to NULL, CPU halted", sh4r.pc ); dreamcast_stop(); return FALSE; }
nkeynes@246
   182
#define CHECKSLOTILLEGAL() if(sh4r.in_delay_slot) return sh4_raise_exception(EXC_SLOT_ILLEGAL)
nkeynes@1
   183
nkeynes@124
   184
static void sh4_write_float( uint32_t addr, int reg )
nkeynes@124
   185
{
nkeynes@124
   186
    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@124
   187
	if( reg & 1 ) {
nkeynes@124
   188
	    sh4_write_long( addr, *((uint32_t *)&XF((reg)&0x0E)) );
nkeynes@124
   189
	    sh4_write_long( addr+4, *((uint32_t *)&XF(reg)) );
nkeynes@124
   190
	} else {
nkeynes@124
   191
	    sh4_write_long( addr, *((uint32_t *)&FR(reg)) ); 
nkeynes@124
   192
	    sh4_write_long( addr+4, *((uint32_t *)&FR((reg)|0x01)) );
nkeynes@124
   193
	}
nkeynes@124
   194
    } else {
nkeynes@124
   195
	sh4_write_long( addr, *((uint32_t *)&FR((reg))) );
nkeynes@124
   196
    }
nkeynes@124
   197
}
nkeynes@124
   198
nkeynes@124
   199
static void sh4_read_float( uint32_t addr, int reg )
nkeynes@124
   200
{
nkeynes@124
   201
    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@124
   202
	if( reg & 1 ) {
nkeynes@124
   203
	    *((uint32_t *)&XF((reg) & 0x0E)) = sh4_read_long(addr);
nkeynes@124
   204
	    *((uint32_t *)&XF(reg)) = sh4_read_long(addr+4);
nkeynes@124
   205
	} else {
nkeynes@124
   206
	    *((uint32_t *)&FR(reg)) = sh4_read_long(addr);
nkeynes@124
   207
	    *((uint32_t *)&FR((reg) | 0x01)) = sh4_read_long(addr+4);
nkeynes@124
   208
	}
nkeynes@124
   209
    } else {
nkeynes@124
   210
	*((uint32_t *)&FR(reg)) = sh4_read_long(addr);
nkeynes@124
   211
    }
nkeynes@124
   212
}
nkeynes@124
   213
nkeynes@27
   214
gboolean sh4_execute_instruction( void )
nkeynes@1
   215
{
nkeynes@84
   216
    uint32_t pc;
nkeynes@2
   217
    unsigned short ir;
nkeynes@1
   218
    uint32_t tmp;
nkeynes@123
   219
    float ftmp;
nkeynes@123
   220
    double dtmp;
nkeynes@586
   221
    int64_t memtmp; // temporary holder for memory reads
nkeynes@1
   222
    
nkeynes@1
   223
#define R0 sh4r.r[0]
nkeynes@2
   224
    pc = sh4r.pc;
nkeynes@84
   225
    if( pc > 0xFFFFFF00 ) {
nkeynes@84
   226
	/* SYSCALL Magic */
nkeynes@102
   227
	syscall_invoke( pc );
nkeynes@104
   228
	sh4r.in_delay_slot = 0;
nkeynes@84
   229
	pc = sh4r.pc = sh4r.pr;
nkeynes@84
   230
	sh4r.new_pc = sh4r.pc + 2;
nkeynes@84
   231
    }
nkeynes@208
   232
    CHECKRALIGN16(pc);
nkeynes@235
   233
nkeynes@235
   234
    /* Read instruction */
nkeynes@586
   235
    if( !IS_IN_ICACHE(pc) ) {
nkeynes@586
   236
	if( !mmu_update_icache(pc) ) {
nkeynes@586
   237
	    // Fault - look for the fault handler
nkeynes@586
   238
	    if( !mmu_update_icache(sh4r.pc) ) {
nkeynes@586
   239
		// double fault - halt
nkeynes@586
   240
		ERROR( "Double fault - halting" );
nkeynes@586
   241
		dreamcast_stop();
nkeynes@586
   242
		return FALSE;
nkeynes@586
   243
	    }
nkeynes@235
   244
	}
nkeynes@586
   245
	pc = sh4r.pc;
nkeynes@235
   246
    }
nkeynes@586
   247
    assert( IS_IN_ICACHE(pc) );
nkeynes@586
   248
    ir = *(uint16_t *)GET_ICACHE_PTR(sh4r.pc);
nkeynes@359
   249
        switch( (ir&0xF000) >> 12 ) {
nkeynes@359
   250
            case 0x0:
nkeynes@359
   251
                switch( ir&0xF ) {
nkeynes@359
   252
                    case 0x2:
nkeynes@359
   253
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
   254
                            case 0x0:
nkeynes@359
   255
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
   256
                                    case 0x0:
nkeynes@359
   257
                                        { /* STC SR, Rn */
nkeynes@359
   258
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   259
                                        CHECKPRIV();
nkeynes@359
   260
                                        sh4r.r[Rn] = sh4_read_sr();
nkeynes@359
   261
                                        }
nkeynes@359
   262
                                        break;
nkeynes@359
   263
                                    case 0x1:
nkeynes@359
   264
                                        { /* STC GBR, Rn */
nkeynes@359
   265
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   266
                                        CHECKPRIV();
nkeynes@359
   267
                                        sh4r.r[Rn] = sh4r.gbr;
nkeynes@359
   268
                                        }
nkeynes@359
   269
                                        break;
nkeynes@359
   270
                                    case 0x2:
nkeynes@359
   271
                                        { /* STC VBR, Rn */
nkeynes@359
   272
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   273
                                        CHECKPRIV();
nkeynes@359
   274
                                        sh4r.r[Rn] = sh4r.vbr;
nkeynes@359
   275
                                        }
nkeynes@359
   276
                                        break;
nkeynes@359
   277
                                    case 0x3:
nkeynes@359
   278
                                        { /* STC SSR, Rn */
nkeynes@359
   279
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   280
                                        CHECKPRIV();
nkeynes@359
   281
                                        sh4r.r[Rn] = sh4r.ssr;
nkeynes@359
   282
                                        }
nkeynes@359
   283
                                        break;
nkeynes@359
   284
                                    case 0x4:
nkeynes@359
   285
                                        { /* STC SPC, Rn */
nkeynes@359
   286
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   287
                                        CHECKPRIV();
nkeynes@359
   288
                                        sh4r.r[Rn] = sh4r.spc;
nkeynes@359
   289
                                        }
nkeynes@359
   290
                                        break;
nkeynes@359
   291
                                    default:
nkeynes@359
   292
                                        UNDEF();
nkeynes@359
   293
                                        break;
nkeynes@359
   294
                                }
nkeynes@359
   295
                                break;
nkeynes@359
   296
                            case 0x1:
nkeynes@359
   297
                                { /* STC Rm_BANK, Rn */
nkeynes@359
   298
                                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
nkeynes@359
   299
                                CHECKPRIV();
nkeynes@359
   300
                                sh4r.r[Rn] = sh4r.r_bank[Rm_BANK];
nkeynes@359
   301
                                }
nkeynes@359
   302
                                break;
nkeynes@359
   303
                        }
nkeynes@359
   304
                        break;
nkeynes@359
   305
                    case 0x3:
nkeynes@359
   306
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   307
                            case 0x0:
nkeynes@359
   308
                                { /* BSRF Rn */
nkeynes@359
   309
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   310
                                CHECKSLOTILLEGAL();
nkeynes@359
   311
                                CHECKDEST( pc + 4 + sh4r.r[Rn] );
nkeynes@359
   312
                                sh4r.in_delay_slot = 1;
nkeynes@359
   313
                                sh4r.pr = sh4r.pc + 4;
nkeynes@359
   314
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
   315
                                sh4r.new_pc = pc + 4 + sh4r.r[Rn];
nkeynes@359
   316
                                TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
   317
                                return TRUE;
nkeynes@359
   318
                                }
nkeynes@359
   319
                                break;
nkeynes@359
   320
                            case 0x2:
nkeynes@359
   321
                                { /* BRAF Rn */
nkeynes@359
   322
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   323
                                CHECKSLOTILLEGAL();
nkeynes@359
   324
                                CHECKDEST( pc + 4 + sh4r.r[Rn] );
nkeynes@359
   325
                                sh4r.in_delay_slot = 1;
nkeynes@359
   326
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
   327
                                sh4r.new_pc = pc + 4 + sh4r.r[Rn];
nkeynes@359
   328
                                return TRUE;
nkeynes@359
   329
                                }
nkeynes@359
   330
                                break;
nkeynes@359
   331
                            case 0x8:
nkeynes@359
   332
                                { /* PREF @Rn */
nkeynes@359
   333
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   334
                                tmp = sh4r.r[Rn];
nkeynes@359
   335
                                if( (tmp & 0xFC000000) == 0xE0000000 ) {
nkeynes@369
   336
                           	 sh4_flush_store_queue(tmp);
nkeynes@359
   337
                                }
nkeynes@359
   338
                                }
nkeynes@359
   339
                                break;
nkeynes@359
   340
                            case 0x9:
nkeynes@359
   341
                                { /* OCBI @Rn */
nkeynes@359
   342
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   343
                                }
nkeynes@359
   344
                                break;
nkeynes@359
   345
                            case 0xA:
nkeynes@359
   346
                                { /* OCBP @Rn */
nkeynes@359
   347
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   348
                                }
nkeynes@359
   349
                                break;
nkeynes@359
   350
                            case 0xB:
nkeynes@359
   351
                                { /* OCBWB @Rn */
nkeynes@359
   352
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   353
                                }
nkeynes@359
   354
                                break;
nkeynes@359
   355
                            case 0xC:
nkeynes@359
   356
                                { /* MOVCA.L R0, @Rn */
nkeynes@359
   357
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   358
                                tmp = sh4r.r[Rn];
nkeynes@359
   359
                                CHECKWALIGN32(tmp);
nkeynes@359
   360
                                MEM_WRITE_LONG( tmp, R0 );
nkeynes@359
   361
                                }
nkeynes@359
   362
                                break;
nkeynes@359
   363
                            default:
nkeynes@359
   364
                                UNDEF();
nkeynes@359
   365
                                break;
nkeynes@359
   366
                        }
nkeynes@359
   367
                        break;
nkeynes@359
   368
                    case 0x4:
nkeynes@359
   369
                        { /* MOV.B Rm, @(R0, Rn) */
nkeynes@359
   370
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   371
                        MEM_WRITE_BYTE( R0 + sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   372
                        }
nkeynes@359
   373
                        break;
nkeynes@359
   374
                    case 0x5:
nkeynes@359
   375
                        { /* MOV.W Rm, @(R0, Rn) */
nkeynes@359
   376
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   377
                        CHECKWALIGN16( R0 + sh4r.r[Rn] );
nkeynes@359
   378
                        MEM_WRITE_WORD( R0 + sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   379
                        }
nkeynes@359
   380
                        break;
nkeynes@359
   381
                    case 0x6:
nkeynes@359
   382
                        { /* MOV.L Rm, @(R0, Rn) */
nkeynes@359
   383
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   384
                        CHECKWALIGN32( R0 + sh4r.r[Rn] );
nkeynes@359
   385
                        MEM_WRITE_LONG( R0 + sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   386
                        }
nkeynes@359
   387
                        break;
nkeynes@359
   388
                    case 0x7:
nkeynes@359
   389
                        { /* MUL.L Rm, Rn */
nkeynes@359
   390
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   391
                        sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   392
                                               (sh4r.r[Rm] * sh4r.r[Rn]);
nkeynes@359
   393
                        }
nkeynes@359
   394
                        break;
nkeynes@359
   395
                    case 0x8:
nkeynes@359
   396
                        switch( (ir&0xFF0) >> 4 ) {
nkeynes@359
   397
                            case 0x0:
nkeynes@359
   398
                                { /* CLRT */
nkeynes@359
   399
                                sh4r.t = 0;
nkeynes@359
   400
                                }
nkeynes@359
   401
                                break;
nkeynes@359
   402
                            case 0x1:
nkeynes@359
   403
                                { /* SETT */
nkeynes@359
   404
                                sh4r.t = 1;
nkeynes@359
   405
                                }
nkeynes@359
   406
                                break;
nkeynes@359
   407
                            case 0x2:
nkeynes@359
   408
                                { /* CLRMAC */
nkeynes@359
   409
                                sh4r.mac = 0;
nkeynes@359
   410
                                }
nkeynes@359
   411
                                break;
nkeynes@359
   412
                            case 0x3:
nkeynes@359
   413
                                { /* LDTLB */
nkeynes@550
   414
                                MMU_ldtlb();
nkeynes@359
   415
                                }
nkeynes@359
   416
                                break;
nkeynes@359
   417
                            case 0x4:
nkeynes@359
   418
                                { /* CLRS */
nkeynes@359
   419
                                sh4r.s = 0;
nkeynes@359
   420
                                }
nkeynes@359
   421
                                break;
nkeynes@359
   422
                            case 0x5:
nkeynes@359
   423
                                { /* SETS */
nkeynes@359
   424
                                sh4r.s = 1;
nkeynes@359
   425
                                }
nkeynes@359
   426
                                break;
nkeynes@359
   427
                            default:
nkeynes@359
   428
                                UNDEF();
nkeynes@359
   429
                                break;
nkeynes@359
   430
                        }
nkeynes@359
   431
                        break;
nkeynes@359
   432
                    case 0x9:
nkeynes@359
   433
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   434
                            case 0x0:
nkeynes@359
   435
                                { /* NOP */
nkeynes@359
   436
                                /* NOP */
nkeynes@359
   437
                                }
nkeynes@359
   438
                                break;
nkeynes@359
   439
                            case 0x1:
nkeynes@359
   440
                                { /* DIV0U */
nkeynes@359
   441
                                sh4r.m = sh4r.q = sh4r.t = 0;
nkeynes@359
   442
                                }
nkeynes@359
   443
                                break;
nkeynes@359
   444
                            case 0x2:
nkeynes@359
   445
                                { /* MOVT Rn */
nkeynes@359
   446
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   447
                                sh4r.r[Rn] = sh4r.t;
nkeynes@359
   448
                                }
nkeynes@359
   449
                                break;
nkeynes@359
   450
                            default:
nkeynes@359
   451
                                UNDEF();
nkeynes@359
   452
                                break;
nkeynes@359
   453
                        }
nkeynes@359
   454
                        break;
nkeynes@359
   455
                    case 0xA:
nkeynes@359
   456
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   457
                            case 0x0:
nkeynes@359
   458
                                { /* STS MACH, Rn */
nkeynes@359
   459
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   460
                                sh4r.r[Rn] = (sh4r.mac>>32);
nkeynes@359
   461
                                }
nkeynes@359
   462
                                break;
nkeynes@359
   463
                            case 0x1:
nkeynes@359
   464
                                { /* STS MACL, Rn */
nkeynes@359
   465
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   466
                                sh4r.r[Rn] = (uint32_t)sh4r.mac;
nkeynes@359
   467
                                }
nkeynes@359
   468
                                break;
nkeynes@359
   469
                            case 0x2:
nkeynes@359
   470
                                { /* STS PR, Rn */
nkeynes@359
   471
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   472
                                sh4r.r[Rn] = sh4r.pr;
nkeynes@359
   473
                                }
nkeynes@359
   474
                                break;
nkeynes@359
   475
                            case 0x3:
nkeynes@359
   476
                                { /* STC SGR, Rn */
nkeynes@359
   477
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   478
                                CHECKPRIV();
nkeynes@359
   479
                                sh4r.r[Rn] = sh4r.sgr;
nkeynes@359
   480
                                }
nkeynes@359
   481
                                break;
nkeynes@359
   482
                            case 0x5:
nkeynes@359
   483
                                { /* STS FPUL, Rn */
nkeynes@359
   484
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@626
   485
                                CHECKFPUEN();
nkeynes@359
   486
                                sh4r.r[Rn] = sh4r.fpul;
nkeynes@359
   487
                                }
nkeynes@359
   488
                                break;
nkeynes@359
   489
                            case 0x6:
nkeynes@359
   490
                                { /* STS FPSCR, Rn */
nkeynes@359
   491
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@626
   492
                                CHECKFPUEN();
nkeynes@359
   493
                                sh4r.r[Rn] = sh4r.fpscr;
nkeynes@359
   494
                                }
nkeynes@359
   495
                                break;
nkeynes@359
   496
                            case 0xF:
nkeynes@359
   497
                                { /* STC DBR, Rn */
nkeynes@359
   498
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   499
                                CHECKPRIV(); sh4r.r[Rn] = sh4r.dbr;
nkeynes@359
   500
                                }
nkeynes@359
   501
                                break;
nkeynes@359
   502
                            default:
nkeynes@359
   503
                                UNDEF();
nkeynes@359
   504
                                break;
nkeynes@359
   505
                        }
nkeynes@359
   506
                        break;
nkeynes@359
   507
                    case 0xB:
nkeynes@359
   508
                        switch( (ir&0xFF0) >> 4 ) {
nkeynes@359
   509
                            case 0x0:
nkeynes@359
   510
                                { /* RTS */
nkeynes@359
   511
                                CHECKSLOTILLEGAL();
nkeynes@359
   512
                                CHECKDEST( sh4r.pr );
nkeynes@359
   513
                                sh4r.in_delay_slot = 1;
nkeynes@359
   514
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
   515
                                sh4r.new_pc = sh4r.pr;
nkeynes@359
   516
                                TRACE_RETURN( pc, sh4r.new_pc );
nkeynes@359
   517
                                return TRUE;
nkeynes@359
   518
                                }
nkeynes@359
   519
                                break;
nkeynes@359
   520
                            case 0x1:
nkeynes@359
   521
                                { /* SLEEP */
nkeynes@359
   522
                                if( MMIO_READ( CPG, STBCR ) & 0x80 ) {
nkeynes@359
   523
                            	sh4r.sh4_state = SH4_STATE_STANDBY;
nkeynes@359
   524
                                } else {
nkeynes@359
   525
                            	sh4r.sh4_state = SH4_STATE_SLEEP;
nkeynes@359
   526
                                }
nkeynes@359
   527
                                return FALSE; /* Halt CPU */
nkeynes@359
   528
                                }
nkeynes@359
   529
                                break;
nkeynes@359
   530
                            case 0x2:
nkeynes@359
   531
                                { /* RTE */
nkeynes@359
   532
                                CHECKPRIV();
nkeynes@359
   533
                                CHECKDEST( sh4r.spc );
nkeynes@359
   534
                                CHECKSLOTILLEGAL();
nkeynes@359
   535
                                sh4r.in_delay_slot = 1;
nkeynes@359
   536
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
   537
                                sh4r.new_pc = sh4r.spc;
nkeynes@374
   538
                                sh4_write_sr( sh4r.ssr );
nkeynes@359
   539
                                return TRUE;
nkeynes@359
   540
                                }
nkeynes@359
   541
                                break;
nkeynes@359
   542
                            default:
nkeynes@359
   543
                                UNDEF();
nkeynes@359
   544
                                break;
nkeynes@359
   545
                        }
nkeynes@359
   546
                        break;
nkeynes@359
   547
                    case 0xC:
nkeynes@359
   548
                        { /* MOV.B @(R0, Rm), Rn */
nkeynes@359
   549
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@586
   550
                        MEM_READ_BYTE( R0 + sh4r.r[Rm], sh4r.r[Rn] );
nkeynes@359
   551
                        }
nkeynes@359
   552
                        break;
nkeynes@359
   553
                    case 0xD:
nkeynes@359
   554
                        { /* MOV.W @(R0, Rm), Rn */
nkeynes@359
   555
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   556
                        CHECKRALIGN16( R0 + sh4r.r[Rm] );
nkeynes@586
   557
                           MEM_READ_WORD( R0 + sh4r.r[Rm], sh4r.r[Rn] );
nkeynes@359
   558
                        }
nkeynes@359
   559
                        break;
nkeynes@359
   560
                    case 0xE:
nkeynes@359
   561
                        { /* MOV.L @(R0, Rm), Rn */
nkeynes@359
   562
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   563
                        CHECKRALIGN32( R0 + sh4r.r[Rm] );
nkeynes@586
   564
                           MEM_READ_LONG( R0 + sh4r.r[Rm], sh4r.r[Rn] );
nkeynes@359
   565
                        }
nkeynes@359
   566
                        break;
nkeynes@359
   567
                    case 0xF:
nkeynes@359
   568
                        { /* MAC.L @Rm+, @Rn+ */
nkeynes@359
   569
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@587
   570
                        int64_t tmpl;
nkeynes@587
   571
                        if( Rm == Rn ) {
nkeynes@587
   572
                    	CHECKRALIGN32( sh4r.r[Rn] );
nkeynes@587
   573
                    	MEM_READ_LONG(sh4r.r[Rn], tmp);
nkeynes@587
   574
                    	tmpl = SIGNEXT32(tmp);
nkeynes@587
   575
                    	MEM_READ_LONG(sh4r.r[Rn]+4, tmp);
nkeynes@587
   576
                    	tmpl = tmpl * SIGNEXT32(tmp) + sh4r.mac;
nkeynes@587
   577
                    	sh4r.r[Rn] += 8;
nkeynes@587
   578
                        } else {
nkeynes@587
   579
                    	CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@587
   580
                    	CHECKRALIGN32( sh4r.r[Rn] );
nkeynes@587
   581
                    	MEM_READ_LONG(sh4r.r[Rn], tmp);
nkeynes@587
   582
                    	tmpl = SIGNEXT32(tmp);
nkeynes@587
   583
                    	MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@587
   584
                    	tmpl = tmpl * SIGNEXT32(tmp) + sh4r.mac;
nkeynes@587
   585
                    	sh4r.r[Rn] += 4;
nkeynes@587
   586
                    	sh4r.r[Rm] += 4;
nkeynes@587
   587
                        }
nkeynes@359
   588
                        if( sh4r.s ) {
nkeynes@359
   589
                            /* 48-bit Saturation. Yuch */
nkeynes@359
   590
                            if( tmpl < (int64_t)0xFFFF800000000000LL )
nkeynes@359
   591
                                tmpl = 0xFFFF800000000000LL;
nkeynes@359
   592
                            else if( tmpl > (int64_t)0x00007FFFFFFFFFFFLL )
nkeynes@359
   593
                                tmpl = 0x00007FFFFFFFFFFFLL;
nkeynes@359
   594
                        }
nkeynes@359
   595
                        sh4r.mac = tmpl;
nkeynes@359
   596
                        }
nkeynes@359
   597
                        break;
nkeynes@359
   598
                    default:
nkeynes@359
   599
                        UNDEF();
nkeynes@359
   600
                        break;
nkeynes@359
   601
                }
nkeynes@359
   602
                break;
nkeynes@359
   603
            case 0x1:
nkeynes@359
   604
                { /* MOV.L Rm, @(disp, Rn) */
nkeynes@359
   605
                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
nkeynes@359
   606
                tmp = sh4r.r[Rn] + disp;
nkeynes@359
   607
                CHECKWALIGN32( tmp );
nkeynes@359
   608
                MEM_WRITE_LONG( tmp, sh4r.r[Rm] );
nkeynes@359
   609
                }
nkeynes@359
   610
                break;
nkeynes@359
   611
            case 0x2:
nkeynes@359
   612
                switch( ir&0xF ) {
nkeynes@359
   613
                    case 0x0:
nkeynes@359
   614
                        { /* MOV.B Rm, @Rn */
nkeynes@359
   615
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   616
                        MEM_WRITE_BYTE( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   617
                        }
nkeynes@359
   618
                        break;
nkeynes@359
   619
                    case 0x1:
nkeynes@359
   620
                        { /* MOV.W Rm, @Rn */
nkeynes@359
   621
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   622
                        CHECKWALIGN16( sh4r.r[Rn] ); MEM_WRITE_WORD( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   623
                        }
nkeynes@359
   624
                        break;
nkeynes@359
   625
                    case 0x2:
nkeynes@359
   626
                        { /* MOV.L Rm, @Rn */
nkeynes@359
   627
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   628
                        CHECKWALIGN32( sh4r.r[Rn] ); MEM_WRITE_LONG( sh4r.r[Rn], sh4r.r[Rm] );
nkeynes@359
   629
                        }
nkeynes@359
   630
                        break;
nkeynes@359
   631
                    case 0x4:
nkeynes@359
   632
                        { /* MOV.B Rm, @-Rn */
nkeynes@359
   633
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@587
   634
                        MEM_WRITE_BYTE( sh4r.r[Rn]-1, sh4r.r[Rm] ); sh4r.r[Rn]--;
nkeynes@359
   635
                        }
nkeynes@359
   636
                        break;
nkeynes@359
   637
                    case 0x5:
nkeynes@359
   638
                        { /* MOV.W Rm, @-Rn */
nkeynes@359
   639
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@587
   640
                        CHECKWALIGN16( sh4r.r[Rn] ); MEM_WRITE_WORD( sh4r.r[Rn]-2, sh4r.r[Rm] ); sh4r.r[Rn] -= 2;
nkeynes@359
   641
                        }
nkeynes@359
   642
                        break;
nkeynes@359
   643
                    case 0x6:
nkeynes@359
   644
                        { /* MOV.L Rm, @-Rn */
nkeynes@359
   645
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@587
   646
                        CHECKWALIGN32( sh4r.r[Rn] ); MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.r[Rm] ); sh4r.r[Rn] -= 4;
nkeynes@359
   647
                        }
nkeynes@359
   648
                        break;
nkeynes@359
   649
                    case 0x7:
nkeynes@359
   650
                        { /* DIV0S Rm, Rn */
nkeynes@359
   651
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   652
                        sh4r.q = sh4r.r[Rn]>>31;
nkeynes@359
   653
                        sh4r.m = sh4r.r[Rm]>>31;
nkeynes@359
   654
                        sh4r.t = sh4r.q ^ sh4r.m;
nkeynes@359
   655
                        }
nkeynes@359
   656
                        break;
nkeynes@359
   657
                    case 0x8:
nkeynes@359
   658
                        { /* TST Rm, Rn */
nkeynes@359
   659
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   660
                        sh4r.t = (sh4r.r[Rn]&sh4r.r[Rm] ? 0 : 1);
nkeynes@359
   661
                        }
nkeynes@359
   662
                        break;
nkeynes@359
   663
                    case 0x9:
nkeynes@359
   664
                        { /* AND Rm, Rn */
nkeynes@359
   665
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   666
                        sh4r.r[Rn] &= sh4r.r[Rm];
nkeynes@359
   667
                        }
nkeynes@359
   668
                        break;
nkeynes@359
   669
                    case 0xA:
nkeynes@359
   670
                        { /* XOR Rm, Rn */
nkeynes@359
   671
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   672
                        sh4r.r[Rn] ^= sh4r.r[Rm];
nkeynes@359
   673
                        }
nkeynes@359
   674
                        break;
nkeynes@359
   675
                    case 0xB:
nkeynes@359
   676
                        { /* OR Rm, Rn */
nkeynes@359
   677
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   678
                        sh4r.r[Rn] |= sh4r.r[Rm];
nkeynes@359
   679
                        }
nkeynes@359
   680
                        break;
nkeynes@359
   681
                    case 0xC:
nkeynes@359
   682
                        { /* CMP/STR Rm, Rn */
nkeynes@359
   683
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   684
                        /* set T = 1 if any byte in RM & RN is the same */
nkeynes@359
   685
                        tmp = sh4r.r[Rm] ^ sh4r.r[Rn];
nkeynes@359
   686
                        sh4r.t = ((tmp&0x000000FF)==0 || (tmp&0x0000FF00)==0 ||
nkeynes@359
   687
                                 (tmp&0x00FF0000)==0 || (tmp&0xFF000000)==0)?1:0;
nkeynes@359
   688
                        }
nkeynes@359
   689
                        break;
nkeynes@359
   690
                    case 0xD:
nkeynes@359
   691
                        { /* XTRCT Rm, Rn */
nkeynes@359
   692
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   693
                        sh4r.r[Rn] = (sh4r.r[Rn]>>16) | (sh4r.r[Rm]<<16);
nkeynes@359
   694
                        }
nkeynes@359
   695
                        break;
nkeynes@359
   696
                    case 0xE:
nkeynes@359
   697
                        { /* MULU.W Rm, Rn */
nkeynes@359
   698
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   699
                        sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   700
                                   (uint32_t)((sh4r.r[Rm]&0xFFFF) * (sh4r.r[Rn]&0xFFFF));
nkeynes@359
   701
                        }
nkeynes@359
   702
                        break;
nkeynes@359
   703
                    case 0xF:
nkeynes@359
   704
                        { /* MULS.W Rm, Rn */
nkeynes@359
   705
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   706
                        sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@359
   707
                                   (uint32_t)(SIGNEXT32(sh4r.r[Rm]&0xFFFF) * SIGNEXT32(sh4r.r[Rn]&0xFFFF));
nkeynes@359
   708
                        }
nkeynes@359
   709
                        break;
nkeynes@359
   710
                    default:
nkeynes@359
   711
                        UNDEF();
nkeynes@359
   712
                        break;
nkeynes@359
   713
                }
nkeynes@359
   714
                break;
nkeynes@359
   715
            case 0x3:
nkeynes@359
   716
                switch( ir&0xF ) {
nkeynes@359
   717
                    case 0x0:
nkeynes@359
   718
                        { /* CMP/EQ Rm, Rn */
nkeynes@359
   719
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   720
                        sh4r.t = ( sh4r.r[Rm] == sh4r.r[Rn] ? 1 : 0 );
nkeynes@359
   721
                        }
nkeynes@359
   722
                        break;
nkeynes@359
   723
                    case 0x2:
nkeynes@359
   724
                        { /* CMP/HS Rm, Rn */
nkeynes@359
   725
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   726
                        sh4r.t = ( sh4r.r[Rn] >= sh4r.r[Rm] ? 1 : 0 );
nkeynes@359
   727
                        }
nkeynes@359
   728
                        break;
nkeynes@359
   729
                    case 0x3:
nkeynes@359
   730
                        { /* CMP/GE Rm, Rn */
nkeynes@359
   731
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   732
                        sh4r.t = ( ((int32_t)sh4r.r[Rn]) >= ((int32_t)sh4r.r[Rm]) ? 1 : 0 );
nkeynes@359
   733
                        }
nkeynes@359
   734
                        break;
nkeynes@359
   735
                    case 0x4:
nkeynes@359
   736
                        { /* DIV1 Rm, Rn */
nkeynes@359
   737
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@384
   738
                        /* This is derived from the sh4 manual with some simplifications */
nkeynes@359
   739
                        uint32_t tmp0, tmp1, tmp2, dir;
nkeynes@359
   740
                    
nkeynes@359
   741
                        dir = sh4r.q ^ sh4r.m;
nkeynes@359
   742
                        sh4r.q = (sh4r.r[Rn] >> 31);
nkeynes@359
   743
                        tmp2 = sh4r.r[Rm];
nkeynes@359
   744
                        sh4r.r[Rn] = (sh4r.r[Rn] << 1) | sh4r.t;
nkeynes@359
   745
                        tmp0 = sh4r.r[Rn];
nkeynes@359
   746
                        if( dir ) {
nkeynes@359
   747
                             sh4r.r[Rn] += tmp2;
nkeynes@359
   748
                             tmp1 = (sh4r.r[Rn]<tmp0 ? 1 : 0 );
nkeynes@359
   749
                        } else {
nkeynes@359
   750
                             sh4r.r[Rn] -= tmp2;
nkeynes@359
   751
                             tmp1 = (sh4r.r[Rn]>tmp0 ? 1 : 0 );
nkeynes@359
   752
                        }
nkeynes@359
   753
                        sh4r.q ^= sh4r.m ^ tmp1;
nkeynes@359
   754
                        sh4r.t = ( sh4r.q == sh4r.m ? 1 : 0 );
nkeynes@359
   755
                        }
nkeynes@359
   756
                        break;
nkeynes@359
   757
                    case 0x5:
nkeynes@359
   758
                        { /* DMULU.L Rm, Rn */
nkeynes@359
   759
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   760
                        sh4r.mac = ((uint64_t)sh4r.r[Rm]) * ((uint64_t)sh4r.r[Rn]);
nkeynes@359
   761
                        }
nkeynes@359
   762
                        break;
nkeynes@359
   763
                    case 0x6:
nkeynes@359
   764
                        { /* CMP/HI Rm, Rn */
nkeynes@359
   765
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   766
                        sh4r.t = ( sh4r.r[Rn] > sh4r.r[Rm] ? 1 : 0 );
nkeynes@359
   767
                        }
nkeynes@359
   768
                        break;
nkeynes@359
   769
                    case 0x7:
nkeynes@359
   770
                        { /* CMP/GT Rm, Rn */
nkeynes@359
   771
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   772
                        sh4r.t = ( ((int32_t)sh4r.r[Rn]) > ((int32_t)sh4r.r[Rm]) ? 1 : 0 );
nkeynes@359
   773
                        }
nkeynes@359
   774
                        break;
nkeynes@359
   775
                    case 0x8:
nkeynes@359
   776
                        { /* SUB Rm, Rn */
nkeynes@359
   777
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   778
                        sh4r.r[Rn] -= sh4r.r[Rm];
nkeynes@359
   779
                        }
nkeynes@359
   780
                        break;
nkeynes@359
   781
                    case 0xA:
nkeynes@359
   782
                        { /* SUBC Rm, Rn */
nkeynes@359
   783
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   784
                        tmp = sh4r.r[Rn];
nkeynes@359
   785
                        sh4r.r[Rn] = sh4r.r[Rn] - sh4r.r[Rm] - sh4r.t;
nkeynes@359
   786
                        sh4r.t = (sh4r.r[Rn] > tmp || (sh4r.r[Rn] == tmp && sh4r.t == 1));
nkeynes@359
   787
                        }
nkeynes@359
   788
                        break;
nkeynes@359
   789
                    case 0xB:
nkeynes@359
   790
                        UNIMP(ir); /* SUBV Rm, Rn */
nkeynes@359
   791
                        break;
nkeynes@359
   792
                    case 0xC:
nkeynes@359
   793
                        { /* ADD Rm, Rn */
nkeynes@359
   794
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   795
                        sh4r.r[Rn] += sh4r.r[Rm];
nkeynes@359
   796
                        }
nkeynes@359
   797
                        break;
nkeynes@359
   798
                    case 0xD:
nkeynes@359
   799
                        { /* DMULS.L Rm, Rn */
nkeynes@359
   800
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   801
                        sh4r.mac = SIGNEXT32(sh4r.r[Rm]) * SIGNEXT32(sh4r.r[Rn]);
nkeynes@359
   802
                        }
nkeynes@359
   803
                        break;
nkeynes@359
   804
                    case 0xE:
nkeynes@359
   805
                        { /* ADDC Rm, Rn */
nkeynes@359
   806
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   807
                        tmp = sh4r.r[Rn];
nkeynes@359
   808
                        sh4r.r[Rn] += sh4r.r[Rm] + sh4r.t;
nkeynes@359
   809
                        sh4r.t = ( sh4r.r[Rn] < tmp || (sh4r.r[Rn] == tmp && sh4r.t != 0) ? 1 : 0 );
nkeynes@359
   810
                        }
nkeynes@359
   811
                        break;
nkeynes@359
   812
                    case 0xF:
nkeynes@359
   813
                        { /* ADDV Rm, Rn */
nkeynes@359
   814
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
   815
                        tmp = sh4r.r[Rn] + sh4r.r[Rm];
nkeynes@359
   816
                        sh4r.t = ( (sh4r.r[Rn]>>31) == (sh4r.r[Rm]>>31) && ((sh4r.r[Rn]>>31) != (tmp>>31)) );
nkeynes@359
   817
                        sh4r.r[Rn] = tmp;
nkeynes@359
   818
                        }
nkeynes@359
   819
                        break;
nkeynes@359
   820
                    default:
nkeynes@359
   821
                        UNDEF();
nkeynes@359
   822
                        break;
nkeynes@359
   823
                }
nkeynes@359
   824
                break;
nkeynes@359
   825
            case 0x4:
nkeynes@359
   826
                switch( ir&0xF ) {
nkeynes@359
   827
                    case 0x0:
nkeynes@359
   828
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   829
                            case 0x0:
nkeynes@359
   830
                                { /* SHLL Rn */
nkeynes@359
   831
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   832
                                sh4r.t = sh4r.r[Rn] >> 31; sh4r.r[Rn] <<= 1;
nkeynes@359
   833
                                }
nkeynes@359
   834
                                break;
nkeynes@359
   835
                            case 0x1:
nkeynes@359
   836
                                { /* DT Rn */
nkeynes@359
   837
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   838
                                sh4r.r[Rn] --;
nkeynes@359
   839
                                sh4r.t = ( sh4r.r[Rn] == 0 ? 1 : 0 );
nkeynes@359
   840
                                }
nkeynes@359
   841
                                break;
nkeynes@359
   842
                            case 0x2:
nkeynes@359
   843
                                { /* SHAL Rn */
nkeynes@359
   844
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   845
                                sh4r.t = sh4r.r[Rn] >> 31;
nkeynes@359
   846
                                sh4r.r[Rn] <<= 1;
nkeynes@359
   847
                                }
nkeynes@359
   848
                                break;
nkeynes@359
   849
                            default:
nkeynes@359
   850
                                UNDEF();
nkeynes@359
   851
                                break;
nkeynes@359
   852
                        }
nkeynes@359
   853
                        break;
nkeynes@359
   854
                    case 0x1:
nkeynes@359
   855
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   856
                            case 0x0:
nkeynes@359
   857
                                { /* SHLR Rn */
nkeynes@359
   858
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   859
                                sh4r.t = sh4r.r[Rn] & 0x00000001; sh4r.r[Rn] >>= 1;
nkeynes@359
   860
                                }
nkeynes@359
   861
                                break;
nkeynes@359
   862
                            case 0x1:
nkeynes@359
   863
                                { /* CMP/PZ Rn */
nkeynes@359
   864
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   865
                                sh4r.t = ( ((int32_t)sh4r.r[Rn]) >= 0 ? 1 : 0 );
nkeynes@359
   866
                                }
nkeynes@359
   867
                                break;
nkeynes@359
   868
                            case 0x2:
nkeynes@359
   869
                                { /* SHAR Rn */
nkeynes@359
   870
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   871
                                sh4r.t = sh4r.r[Rn] & 0x00000001;
nkeynes@359
   872
                                sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> 1;
nkeynes@359
   873
                                }
nkeynes@359
   874
                                break;
nkeynes@359
   875
                            default:
nkeynes@359
   876
                                UNDEF();
nkeynes@359
   877
                                break;
nkeynes@359
   878
                        }
nkeynes@359
   879
                        break;
nkeynes@359
   880
                    case 0x2:
nkeynes@359
   881
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
   882
                            case 0x0:
nkeynes@359
   883
                                { /* STS.L MACH, @-Rn */
nkeynes@359
   884
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@587
   885
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   886
                                MEM_WRITE_LONG( sh4r.r[Rn]-4, (sh4r.mac>>32) );
nkeynes@359
   887
                                sh4r.r[Rn] -= 4;
nkeynes@359
   888
                                }
nkeynes@359
   889
                                break;
nkeynes@359
   890
                            case 0x1:
nkeynes@359
   891
                                { /* STS.L MACL, @-Rn */
nkeynes@359
   892
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@587
   893
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   894
                                MEM_WRITE_LONG( sh4r.r[Rn]-4, (uint32_t)sh4r.mac );
nkeynes@359
   895
                                sh4r.r[Rn] -= 4;
nkeynes@359
   896
                                }
nkeynes@359
   897
                                break;
nkeynes@359
   898
                            case 0x2:
nkeynes@359
   899
                                { /* STS.L PR, @-Rn */
nkeynes@359
   900
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@587
   901
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   902
                                MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.pr );
nkeynes@359
   903
                                sh4r.r[Rn] -= 4;
nkeynes@359
   904
                                }
nkeynes@359
   905
                                break;
nkeynes@359
   906
                            case 0x3:
nkeynes@359
   907
                                { /* STC.L SGR, @-Rn */
nkeynes@359
   908
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   909
                                CHECKPRIV();
nkeynes@587
   910
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   911
                                MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.sgr );
nkeynes@359
   912
                                sh4r.r[Rn] -= 4;
nkeynes@359
   913
                                }
nkeynes@359
   914
                                break;
nkeynes@359
   915
                            case 0x5:
nkeynes@359
   916
                                { /* STS.L FPUL, @-Rn */
nkeynes@359
   917
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@626
   918
                                CHECKFPUEN();
nkeynes@587
   919
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   920
                                MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.fpul );
nkeynes@359
   921
                                sh4r.r[Rn] -= 4;
nkeynes@359
   922
                                }
nkeynes@359
   923
                                break;
nkeynes@359
   924
                            case 0x6:
nkeynes@359
   925
                                { /* STS.L FPSCR, @-Rn */
nkeynes@359
   926
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@626
   927
                                CHECKFPUEN();
nkeynes@587
   928
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   929
                                MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.fpscr );
nkeynes@359
   930
                                sh4r.r[Rn] -= 4;
nkeynes@359
   931
                                }
nkeynes@359
   932
                                break;
nkeynes@359
   933
                            case 0xF:
nkeynes@359
   934
                                { /* STC.L DBR, @-Rn */
nkeynes@359
   935
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   936
                                CHECKPRIV();
nkeynes@587
   937
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   938
                                MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.dbr );
nkeynes@359
   939
                                sh4r.r[Rn] -= 4;
nkeynes@359
   940
                                }
nkeynes@359
   941
                                break;
nkeynes@359
   942
                            default:
nkeynes@359
   943
                                UNDEF();
nkeynes@359
   944
                                break;
nkeynes@359
   945
                        }
nkeynes@359
   946
                        break;
nkeynes@359
   947
                    case 0x3:
nkeynes@359
   948
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
   949
                            case 0x0:
nkeynes@359
   950
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
   951
                                    case 0x0:
nkeynes@359
   952
                                        { /* STC.L SR, @-Rn */
nkeynes@359
   953
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   954
                                        CHECKPRIV();
nkeynes@587
   955
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   956
                                        MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4_read_sr() );
nkeynes@359
   957
                                        sh4r.r[Rn] -= 4;
nkeynes@359
   958
                                        }
nkeynes@359
   959
                                        break;
nkeynes@359
   960
                                    case 0x1:
nkeynes@359
   961
                                        { /* STC.L GBR, @-Rn */
nkeynes@359
   962
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@587
   963
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   964
                                        MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.gbr );
nkeynes@359
   965
                                        sh4r.r[Rn] -= 4;
nkeynes@359
   966
                                        }
nkeynes@359
   967
                                        break;
nkeynes@359
   968
                                    case 0x2:
nkeynes@359
   969
                                        { /* STC.L VBR, @-Rn */
nkeynes@359
   970
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   971
                                        CHECKPRIV();
nkeynes@587
   972
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   973
                                        MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.vbr );
nkeynes@359
   974
                                        sh4r.r[Rn] -= 4;
nkeynes@359
   975
                                        }
nkeynes@359
   976
                                        break;
nkeynes@359
   977
                                    case 0x3:
nkeynes@359
   978
                                        { /* STC.L SSR, @-Rn */
nkeynes@359
   979
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   980
                                        CHECKPRIV();
nkeynes@587
   981
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   982
                                        MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.ssr );
nkeynes@359
   983
                                        sh4r.r[Rn] -= 4;
nkeynes@359
   984
                                        }
nkeynes@359
   985
                                        break;
nkeynes@359
   986
                                    case 0x4:
nkeynes@359
   987
                                        { /* STC.L SPC, @-Rn */
nkeynes@359
   988
                                        uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
   989
                                        CHECKPRIV();
nkeynes@587
   990
                                        CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
   991
                                        MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.spc );
nkeynes@359
   992
                                        sh4r.r[Rn] -= 4;
nkeynes@359
   993
                                        }
nkeynes@359
   994
                                        break;
nkeynes@359
   995
                                    default:
nkeynes@359
   996
                                        UNDEF();
nkeynes@359
   997
                                        break;
nkeynes@359
   998
                                }
nkeynes@359
   999
                                break;
nkeynes@359
  1000
                            case 0x1:
nkeynes@359
  1001
                                { /* STC.L Rm_BANK, @-Rn */
nkeynes@359
  1002
                                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm_BANK = ((ir>>4)&0x7); 
nkeynes@359
  1003
                                CHECKPRIV();
nkeynes@587
  1004
                                CHECKWALIGN32( sh4r.r[Rn] );
nkeynes@587
  1005
                                MEM_WRITE_LONG( sh4r.r[Rn]-4, sh4r.r_bank[Rm_BANK] );
nkeynes@359
  1006
                                sh4r.r[Rn] -= 4;
nkeynes@359
  1007
                                }
nkeynes@359
  1008
                                break;
nkeynes@359
  1009
                        }
nkeynes@359
  1010
                        break;
nkeynes@359
  1011
                    case 0x4:
nkeynes@359
  1012
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1013
                            case 0x0:
nkeynes@359
  1014
                                { /* ROTL Rn */
nkeynes@359
  1015
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1016
                                sh4r.t = sh4r.r[Rn] >> 31;
nkeynes@359
  1017
                                sh4r.r[Rn] <<= 1;
nkeynes@359
  1018
                                sh4r.r[Rn] |= sh4r.t;
nkeynes@359
  1019
                                }
nkeynes@359
  1020
                                break;
nkeynes@359
  1021
                            case 0x2:
nkeynes@359
  1022
                                { /* ROTCL Rn */
nkeynes@359
  1023
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1024
                                tmp = sh4r.r[Rn] >> 31;
nkeynes@359
  1025
                                sh4r.r[Rn] <<= 1;
nkeynes@359
  1026
                                sh4r.r[Rn] |= sh4r.t;
nkeynes@359
  1027
                                sh4r.t = tmp;
nkeynes@359
  1028
                                }
nkeynes@359
  1029
                                break;
nkeynes@359
  1030
                            default:
nkeynes@359
  1031
                                UNDEF();
nkeynes@359
  1032
                                break;
nkeynes@359
  1033
                        }
nkeynes@359
  1034
                        break;
nkeynes@359
  1035
                    case 0x5:
nkeynes@359
  1036
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1037
                            case 0x0:
nkeynes@359
  1038
                                { /* ROTR Rn */
nkeynes@359
  1039
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1040
                                sh4r.t = sh4r.r[Rn] & 0x00000001;
nkeynes@359
  1041
                                sh4r.r[Rn] >>= 1;
nkeynes@359
  1042
                                sh4r.r[Rn] |= (sh4r.t << 31);
nkeynes@359
  1043
                                }
nkeynes@359
  1044
                                break;
nkeynes@359
  1045
                            case 0x1:
nkeynes@359
  1046
                                { /* CMP/PL Rn */
nkeynes@359
  1047
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1048
                                sh4r.t = ( ((int32_t)sh4r.r[Rn]) > 0 ? 1 : 0 );
nkeynes@359
  1049
                                }
nkeynes@359
  1050
                                break;
nkeynes@359
  1051
                            case 0x2:
nkeynes@359
  1052
                                { /* ROTCR Rn */
nkeynes@359
  1053
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1054
                                tmp = sh4r.r[Rn] & 0x00000001;
nkeynes@359
  1055
                                sh4r.r[Rn] >>= 1;
nkeynes@359
  1056
                                sh4r.r[Rn] |= (sh4r.t << 31 );
nkeynes@359
  1057
                                sh4r.t = tmp;
nkeynes@359
  1058
                                }
nkeynes@359
  1059
                                break;
nkeynes@359
  1060
                            default:
nkeynes@359
  1061
                                UNDEF();
nkeynes@359
  1062
                                break;
nkeynes@359
  1063
                        }
nkeynes@359
  1064
                        break;
nkeynes@359
  1065
                    case 0x6:
nkeynes@359
  1066
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1067
                            case 0x0:
nkeynes@359
  1068
                                { /* LDS.L @Rm+, MACH */
nkeynes@359
  1069
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1070
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1071
                                MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@359
  1072
                                sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@586
  1073
                            	(((uint64_t)tmp)<<32);
nkeynes@359
  1074
                                sh4r.r[Rm] += 4;
nkeynes@359
  1075
                                }
nkeynes@359
  1076
                                break;
nkeynes@359
  1077
                            case 0x1:
nkeynes@359
  1078
                                { /* LDS.L @Rm+, MACL */
nkeynes@359
  1079
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1080
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1081
                                MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@359
  1082
                                sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@586
  1083
                                           (uint64_t)((uint32_t)tmp);
nkeynes@359
  1084
                                sh4r.r[Rm] += 4;
nkeynes@359
  1085
                                }
nkeynes@359
  1086
                                break;
nkeynes@359
  1087
                            case 0x2:
nkeynes@359
  1088
                                { /* LDS.L @Rm+, PR */
nkeynes@359
  1089
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1090
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1091
                                MEM_READ_LONG( sh4r.r[Rm], sh4r.pr );
nkeynes@359
  1092
                                sh4r.r[Rm] += 4;
nkeynes@359
  1093
                                }
nkeynes@359
  1094
                                break;
nkeynes@359
  1095
                            case 0x3:
nkeynes@359
  1096
                                { /* LDC.L @Rm+, SGR */
nkeynes@359
  1097
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1098
                                CHECKPRIV();
nkeynes@359
  1099
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1100
                                MEM_READ_LONG(sh4r.r[Rm], sh4r.sgr);
nkeynes@359
  1101
                                sh4r.r[Rm] +=4;
nkeynes@359
  1102
                                }
nkeynes@359
  1103
                                break;
nkeynes@359
  1104
                            case 0x5:
nkeynes@359
  1105
                                { /* LDS.L @Rm+, FPUL */
nkeynes@359
  1106
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@626
  1107
                                CHECKFPUEN();
nkeynes@359
  1108
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1109
                                MEM_READ_LONG(sh4r.r[Rm], sh4r.fpul);
nkeynes@359
  1110
                                sh4r.r[Rm] +=4;
nkeynes@359
  1111
                                }
nkeynes@359
  1112
                                break;
nkeynes@359
  1113
                            case 0x6:
nkeynes@359
  1114
                                { /* LDS.L @Rm+, FPSCR */
nkeynes@359
  1115
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@626
  1116
                                CHECKFPUEN();
nkeynes@359
  1117
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1118
                                MEM_READ_LONG(sh4r.r[Rm], sh4r.fpscr);
nkeynes@359
  1119
                                sh4r.r[Rm] +=4;
nkeynes@374
  1120
                                sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0];
nkeynes@359
  1121
                                }
nkeynes@359
  1122
                                break;
nkeynes@359
  1123
                            case 0xF:
nkeynes@359
  1124
                                { /* LDC.L @Rm+, DBR */
nkeynes@359
  1125
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1126
                                CHECKPRIV();
nkeynes@359
  1127
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1128
                                MEM_READ_LONG(sh4r.r[Rm], sh4r.dbr);
nkeynes@359
  1129
                                sh4r.r[Rm] +=4;
nkeynes@359
  1130
                                }
nkeynes@359
  1131
                                break;
nkeynes@359
  1132
                            default:
nkeynes@359
  1133
                                UNDEF();
nkeynes@359
  1134
                                break;
nkeynes@359
  1135
                        }
nkeynes@359
  1136
                        break;
nkeynes@359
  1137
                    case 0x7:
nkeynes@359
  1138
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
  1139
                            case 0x0:
nkeynes@359
  1140
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
  1141
                                    case 0x0:
nkeynes@359
  1142
                                        { /* LDC.L @Rm+, SR */
nkeynes@359
  1143
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1144
                                        CHECKSLOTILLEGAL();
nkeynes@359
  1145
                                        CHECKPRIV();
nkeynes@359
  1146
                                        CHECKWALIGN32( sh4r.r[Rm] );
nkeynes@586
  1147
                                        MEM_READ_LONG(sh4r.r[Rm], tmp);
nkeynes@586
  1148
                                        sh4_write_sr( tmp );
nkeynes@359
  1149
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1150
                                        }
nkeynes@359
  1151
                                        break;
nkeynes@359
  1152
                                    case 0x1:
nkeynes@359
  1153
                                        { /* LDC.L @Rm+, GBR */
nkeynes@359
  1154
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1155
                                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1156
                                        MEM_READ_LONG(sh4r.r[Rm], sh4r.gbr);
nkeynes@359
  1157
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1158
                                        }
nkeynes@359
  1159
                                        break;
nkeynes@359
  1160
                                    case 0x2:
nkeynes@359
  1161
                                        { /* LDC.L @Rm+, VBR */
nkeynes@359
  1162
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1163
                                        CHECKPRIV();
nkeynes@359
  1164
                                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1165
                                        MEM_READ_LONG(sh4r.r[Rm], sh4r.vbr);
nkeynes@359
  1166
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1167
                                        }
nkeynes@359
  1168
                                        break;
nkeynes@359
  1169
                                    case 0x3:
nkeynes@359
  1170
                                        { /* LDC.L @Rm+, SSR */
nkeynes@359
  1171
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1172
                                        CHECKPRIV();
nkeynes@359
  1173
                                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1174
                                        MEM_READ_LONG(sh4r.r[Rm], sh4r.ssr);
nkeynes@359
  1175
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1176
                                        }
nkeynes@359
  1177
                                        break;
nkeynes@359
  1178
                                    case 0x4:
nkeynes@359
  1179
                                        { /* LDC.L @Rm+, SPC */
nkeynes@359
  1180
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1181
                                        CHECKPRIV();
nkeynes@359
  1182
                                        CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1183
                                        MEM_READ_LONG(sh4r.r[Rm], sh4r.spc);
nkeynes@359
  1184
                                        sh4r.r[Rm] +=4;
nkeynes@359
  1185
                                        }
nkeynes@359
  1186
                                        break;
nkeynes@359
  1187
                                    default:
nkeynes@359
  1188
                                        UNDEF();
nkeynes@359
  1189
                                        break;
nkeynes@359
  1190
                                }
nkeynes@359
  1191
                                break;
nkeynes@359
  1192
                            case 0x1:
nkeynes@359
  1193
                                { /* LDC.L @Rm+, Rn_BANK */
nkeynes@359
  1194
                                uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
nkeynes@359
  1195
                                CHECKPRIV();
nkeynes@359
  1196
                                CHECKRALIGN32( sh4r.r[Rm] );
nkeynes@586
  1197
                                MEM_READ_LONG( sh4r.r[Rm], sh4r.r_bank[Rn_BANK] );
nkeynes@359
  1198
                                sh4r.r[Rm] += 4;
nkeynes@359
  1199
                                }
nkeynes@359
  1200
                                break;
nkeynes@359
  1201
                        }
nkeynes@359
  1202
                        break;
nkeynes@359
  1203
                    case 0x8:
nkeynes@359
  1204
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1205
                            case 0x0:
nkeynes@359
  1206
                                { /* SHLL2 Rn */
nkeynes@359
  1207
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1208
                                sh4r.r[Rn] <<= 2;
nkeynes@359
  1209
                                }
nkeynes@359
  1210
                                break;
nkeynes@359
  1211
                            case 0x1:
nkeynes@359
  1212
                                { /* SHLL8 Rn */
nkeynes@359
  1213
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1214
                                sh4r.r[Rn] <<= 8;
nkeynes@359
  1215
                                }
nkeynes@359
  1216
                                break;
nkeynes@359
  1217
                            case 0x2:
nkeynes@359
  1218
                                { /* SHLL16 Rn */
nkeynes@359
  1219
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1220
                                sh4r.r[Rn] <<= 16;
nkeynes@359
  1221
                                }
nkeynes@359
  1222
                                break;
nkeynes@359
  1223
                            default:
nkeynes@359
  1224
                                UNDEF();
nkeynes@359
  1225
                                break;
nkeynes@359
  1226
                        }
nkeynes@359
  1227
                        break;
nkeynes@359
  1228
                    case 0x9:
nkeynes@359
  1229
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1230
                            case 0x0:
nkeynes@359
  1231
                                { /* SHLR2 Rn */
nkeynes@359
  1232
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1233
                                sh4r.r[Rn] >>= 2;
nkeynes@359
  1234
                                }
nkeynes@359
  1235
                                break;
nkeynes@359
  1236
                            case 0x1:
nkeynes@359
  1237
                                { /* SHLR8 Rn */
nkeynes@359
  1238
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1239
                                sh4r.r[Rn] >>= 8;
nkeynes@359
  1240
                                }
nkeynes@359
  1241
                                break;
nkeynes@359
  1242
                            case 0x2:
nkeynes@359
  1243
                                { /* SHLR16 Rn */
nkeynes@359
  1244
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1245
                                sh4r.r[Rn] >>= 16;
nkeynes@359
  1246
                                }
nkeynes@359
  1247
                                break;
nkeynes@359
  1248
                            default:
nkeynes@359
  1249
                                UNDEF();
nkeynes@359
  1250
                                break;
nkeynes@359
  1251
                        }
nkeynes@359
  1252
                        break;
nkeynes@359
  1253
                    case 0xA:
nkeynes@359
  1254
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1255
                            case 0x0:
nkeynes@359
  1256
                                { /* LDS Rm, MACH */
nkeynes@359
  1257
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1258
                                sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@359
  1259
                                           (((uint64_t)sh4r.r[Rm])<<32);
nkeynes@359
  1260
                                }
nkeynes@359
  1261
                                break;
nkeynes@359
  1262
                            case 0x1:
nkeynes@359
  1263
                                { /* LDS Rm, MACL */
nkeynes@359
  1264
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1265
                                sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@359
  1266
                                           (uint64_t)((uint32_t)(sh4r.r[Rm]));
nkeynes@359
  1267
                                }
nkeynes@359
  1268
                                break;
nkeynes@359
  1269
                            case 0x2:
nkeynes@359
  1270
                                { /* LDS Rm, PR */
nkeynes@359
  1271
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1272
                                sh4r.pr = sh4r.r[Rm];
nkeynes@359
  1273
                                }
nkeynes@359
  1274
                                break;
nkeynes@359
  1275
                            case 0x3:
nkeynes@359
  1276
                                { /* LDC Rm, SGR */
nkeynes@359
  1277
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1278
                                CHECKPRIV();
nkeynes@359
  1279
                                sh4r.sgr = sh4r.r[Rm];
nkeynes@359
  1280
                                }
nkeynes@359
  1281
                                break;
nkeynes@359
  1282
                            case 0x5:
nkeynes@359
  1283
                                { /* LDS Rm, FPUL */
nkeynes@359
  1284
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@626
  1285
                                CHECKFPUEN();
nkeynes@359
  1286
                                sh4r.fpul = sh4r.r[Rm];
nkeynes@359
  1287
                                }
nkeynes@359
  1288
                                break;
nkeynes@359
  1289
                            case 0x6:
nkeynes@359
  1290
                                { /* LDS Rm, FPSCR */
nkeynes@359
  1291
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@626
  1292
                                CHECKFPUEN();
nkeynes@374
  1293
                                sh4r.fpscr = sh4r.r[Rm]; 
nkeynes@374
  1294
                                sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0];
nkeynes@359
  1295
                                }
nkeynes@359
  1296
                                break;
nkeynes@359
  1297
                            case 0xF:
nkeynes@359
  1298
                                { /* LDC Rm, DBR */
nkeynes@359
  1299
                                uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1300
                                CHECKPRIV();
nkeynes@359
  1301
                                sh4r.dbr = sh4r.r[Rm];
nkeynes@359
  1302
                                }
nkeynes@359
  1303
                                break;
nkeynes@359
  1304
                            default:
nkeynes@359
  1305
                                UNDEF();
nkeynes@359
  1306
                                break;
nkeynes@359
  1307
                        }
nkeynes@359
  1308
                        break;
nkeynes@359
  1309
                    case 0xB:
nkeynes@359
  1310
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1311
                            case 0x0:
nkeynes@359
  1312
                                { /* JSR @Rn */
nkeynes@359
  1313
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1314
                                CHECKDEST( sh4r.r[Rn] );
nkeynes@359
  1315
                                CHECKSLOTILLEGAL();
nkeynes@359
  1316
                                sh4r.in_delay_slot = 1;
nkeynes@359
  1317
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
  1318
                                sh4r.new_pc = sh4r.r[Rn];
nkeynes@359
  1319
                                sh4r.pr = pc + 4;
nkeynes@359
  1320
                                TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
  1321
                                return TRUE;
nkeynes@359
  1322
                                }
nkeynes@359
  1323
                                break;
nkeynes@359
  1324
                            case 0x1:
nkeynes@359
  1325
                                { /* TAS.B @Rn */
nkeynes@359
  1326
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@586
  1327
                                MEM_READ_BYTE( sh4r.r[Rn], tmp );
nkeynes@359
  1328
                                sh4r.t = ( tmp == 0 ? 1 : 0 );
nkeynes@359
  1329
                                MEM_WRITE_BYTE( sh4r.r[Rn], tmp | 0x80 );
nkeynes@359
  1330
                                }
nkeynes@359
  1331
                                break;
nkeynes@359
  1332
                            case 0x2:
nkeynes@359
  1333
                                { /* JMP @Rn */
nkeynes@359
  1334
                                uint32_t Rn = ((ir>>8)&0xF); 
nkeynes@359
  1335
                                CHECKDEST( sh4r.r[Rn] );
nkeynes@359
  1336
                                CHECKSLOTILLEGAL();
nkeynes@359
  1337
                                sh4r.in_delay_slot = 1;
nkeynes@359
  1338
                                sh4r.pc = sh4r.new_pc;
nkeynes@359
  1339
                                sh4r.new_pc = sh4r.r[Rn];
nkeynes@359
  1340
                                return TRUE;
nkeynes@359
  1341
                                }
nkeynes@359
  1342
                                break;
nkeynes@359
  1343
                            default:
nkeynes@359
  1344
                                UNDEF();
nkeynes@359
  1345
                                break;
nkeynes@359
  1346
                        }
nkeynes@359
  1347
                        break;
nkeynes@359
  1348
                    case 0xC:
nkeynes@359
  1349
                        { /* SHAD Rm, Rn */
nkeynes@359
  1350
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1351
                        tmp = sh4r.r[Rm];
nkeynes@359
  1352
                        if( (tmp & 0x80000000) == 0 ) sh4r.r[Rn] <<= (tmp&0x1f);
nkeynes@359
  1353
                        else if( (tmp & 0x1F) == 0 )  
nkeynes@359
  1354
                            sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> 31;
nkeynes@359
  1355
                        else 
nkeynes@359
  1356
                    	sh4r.r[Rn] = ((int32_t)sh4r.r[Rn]) >> (((~sh4r.r[Rm]) & 0x1F)+1);
nkeynes@359
  1357
                        }
nkeynes@359
  1358
                        break;
nkeynes@359
  1359
                    case 0xD:
nkeynes@359
  1360
                        { /* SHLD Rm, Rn */
nkeynes@359
  1361
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1362
                        tmp = sh4r.r[Rm];
nkeynes@359
  1363
                        if( (tmp & 0x80000000) == 0 ) sh4r.r[Rn] <<= (tmp&0x1f);
nkeynes@359
  1364
                        else if( (tmp & 0x1F) == 0 ) sh4r.r[Rn] = 0;
nkeynes@359
  1365
                        else sh4r.r[Rn] >>= (((~tmp) & 0x1F)+1);
nkeynes@359
  1366
                        }
nkeynes@359
  1367
                        break;
nkeynes@359
  1368
                    case 0xE:
nkeynes@359
  1369
                        switch( (ir&0x80) >> 7 ) {
nkeynes@359
  1370
                            case 0x0:
nkeynes@359
  1371
                                switch( (ir&0x70) >> 4 ) {
nkeynes@359
  1372
                                    case 0x0:
nkeynes@359
  1373
                                        { /* LDC Rm, SR */
nkeynes@359
  1374
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1375
                                        CHECKSLOTILLEGAL();
nkeynes@359
  1376
                                        CHECKPRIV();
nkeynes@374
  1377
                                        sh4_write_sr( sh4r.r[Rm] );
nkeynes@359
  1378
                                        }
nkeynes@359
  1379
                                        break;
nkeynes@359
  1380
                                    case 0x1:
nkeynes@359
  1381
                                        { /* LDC Rm, GBR */
nkeynes@359
  1382
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1383
                                        sh4r.gbr = sh4r.r[Rm];
nkeynes@359
  1384
                                        }
nkeynes@359
  1385
                                        break;
nkeynes@359
  1386
                                    case 0x2:
nkeynes@359
  1387
                                        { /* LDC Rm, VBR */
nkeynes@359
  1388
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1389
                                        CHECKPRIV();
nkeynes@359
  1390
                                        sh4r.vbr = sh4r.r[Rm];
nkeynes@359
  1391
                                        }
nkeynes@359
  1392
                                        break;
nkeynes@359
  1393
                                    case 0x3:
nkeynes@359
  1394
                                        { /* LDC Rm, SSR */
nkeynes@359
  1395
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1396
                                        CHECKPRIV();
nkeynes@359
  1397
                                        sh4r.ssr = sh4r.r[Rm];
nkeynes@359
  1398
                                        }
nkeynes@359
  1399
                                        break;
nkeynes@359
  1400
                                    case 0x4:
nkeynes@359
  1401
                                        { /* LDC Rm, SPC */
nkeynes@359
  1402
                                        uint32_t Rm = ((ir>>8)&0xF); 
nkeynes@359
  1403
                                        CHECKPRIV();
nkeynes@359
  1404
                                        sh4r.spc = sh4r.r[Rm];
nkeynes@359
  1405
                                        }
nkeynes@359
  1406
                                        break;
nkeynes@359
  1407
                                    default:
nkeynes@359
  1408
                                        UNDEF();
nkeynes@359
  1409
                                        break;
nkeynes@359
  1410
                                }
nkeynes@359
  1411
                                break;
nkeynes@359
  1412
                            case 0x1:
nkeynes@359
  1413
                                { /* LDC Rm, Rn_BANK */
nkeynes@359
  1414
                                uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7); 
nkeynes@359
  1415
                                CHECKPRIV();
nkeynes@359
  1416
                                sh4r.r_bank[Rn_BANK] = sh4r.r[Rm];
nkeynes@359
  1417
                                }
nkeynes@359
  1418
                                break;
nkeynes@359
  1419
                        }
nkeynes@359
  1420
                        break;
nkeynes@359
  1421
                    case 0xF:
nkeynes@359
  1422
                        { /* MAC.W @Rm+, @Rn+ */
nkeynes@359
  1423
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@587
  1424
                        int32_t stmp;
nkeynes@587
  1425
                        if( Rm == Rn ) {
nkeynes@587
  1426
                    	CHECKRALIGN16(sh4r.r[Rn]);
nkeynes@587
  1427
                    	MEM_READ_WORD( sh4r.r[Rn], tmp );
nkeynes@587
  1428
                    	stmp = SIGNEXT16(tmp);
nkeynes@587
  1429
                    	MEM_READ_WORD( sh4r.r[Rn]+2, tmp );
nkeynes@587
  1430
                    	stmp *= SIGNEXT16(tmp);
nkeynes@587
  1431
                    	sh4r.r[Rn] += 4;
nkeynes@587
  1432
                        } else {
nkeynes@587
  1433
                    	CHECKRALIGN16( sh4r.r[Rn] );
nkeynes@587
  1434
                    	CHECKRALIGN16( sh4r.r[Rm] );
nkeynes@587
  1435
                    	MEM_READ_WORD(sh4r.r[Rn], tmp);
nkeynes@587
  1436
                    	stmp = SIGNEXT16(tmp);
nkeynes@587
  1437
                    	MEM_READ_WORD(sh4r.r[Rm], tmp);
nkeynes@587
  1438
                    	stmp = stmp * SIGNEXT16(tmp);
nkeynes@587
  1439
                    	sh4r.r[Rn] += 2;
nkeynes@587
  1440
                    	sh4r.r[Rm] += 2;
nkeynes@587
  1441
                        }
nkeynes@359
  1442
                        if( sh4r.s ) {
nkeynes@359
  1443
                    	int64_t tmpl = (int64_t)((int32_t)sh4r.mac) + (int64_t)stmp;
nkeynes@359
  1444
                    	if( tmpl > (int64_t)0x000000007FFFFFFFLL ) {
nkeynes@359
  1445
                    	    sh4r.mac = 0x000000017FFFFFFFLL;
nkeynes@359
  1446
                    	} else if( tmpl < (int64_t)0xFFFFFFFF80000000LL ) {
nkeynes@359
  1447
                    	    sh4r.mac = 0x0000000180000000LL;
nkeynes@359
  1448
                    	} else {
nkeynes@359
  1449
                    	    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@359
  1450
                    		((uint32_t)(sh4r.mac + stmp));
nkeynes@359
  1451
                    	}
nkeynes@359
  1452
                        } else {
nkeynes@359
  1453
                    	sh4r.mac += SIGNEXT32(stmp);
nkeynes@359
  1454
                        }
nkeynes@359
  1455
                        }
nkeynes@359
  1456
                        break;
nkeynes@359
  1457
                }
nkeynes@359
  1458
                break;
nkeynes@359
  1459
            case 0x5:
nkeynes@359
  1460
                { /* MOV.L @(disp, Rm), Rn */
nkeynes@359
  1461
                uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2; 
nkeynes@359
  1462
                tmp = sh4r.r[Rm] + disp;
nkeynes@359
  1463
                CHECKRALIGN32( tmp );
nkeynes@586
  1464
                MEM_READ_LONG( tmp, sh4r.r[Rn] );
nkeynes@359
  1465
                }
nkeynes@359
  1466
                break;
nkeynes@359
  1467
            case 0x6:
nkeynes@359
  1468
                switch( ir&0xF ) {
nkeynes@359
  1469
                    case 0x0:
nkeynes@359
  1470
                        { /* MOV.B @Rm, Rn */
nkeynes@359
  1471
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@586
  1472
                        MEM_READ_BYTE( sh4r.r[Rm], sh4r.r[Rn] );
nkeynes@359
  1473
                        }
nkeynes@359
  1474
                        break;
nkeynes@359
  1475
                    case 0x1:
nkeynes@359
  1476
                        { /* MOV.W @Rm, Rn */
nkeynes@359
  1477
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@586
  1478
                        CHECKRALIGN16( sh4r.r[Rm] ); MEM_READ_WORD( sh4r.r[Rm], sh4r.r[Rn] );
nkeynes@359
  1479
                        }
nkeynes@359
  1480
                        break;
nkeynes@359
  1481
                    case 0x2:
nkeynes@359
  1482
                        { /* MOV.L @Rm, Rn */
nkeynes@359
  1483
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@586
  1484
                        CHECKRALIGN32( sh4r.r[Rm] ); MEM_READ_LONG( sh4r.r[Rm], sh4r.r[Rn] );
nkeynes@359
  1485
                        }
nkeynes@359
  1486
                        break;
nkeynes@359
  1487
                    case 0x3:
nkeynes@359
  1488
                        { /* MOV Rm, Rn */
nkeynes@359
  1489
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1490
                        sh4r.r[Rn] = sh4r.r[Rm];
nkeynes@359
  1491
                        }
nkeynes@359
  1492
                        break;
nkeynes@359
  1493
                    case 0x4:
nkeynes@359
  1494
                        { /* MOV.B @Rm+, Rn */
nkeynes@359
  1495
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@586
  1496
                        MEM_READ_BYTE( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] ++;
nkeynes@359
  1497
                        }
nkeynes@359
  1498
                        break;
nkeynes@359
  1499
                    case 0x5:
nkeynes@359
  1500
                        { /* MOV.W @Rm+, Rn */
nkeynes@359
  1501
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@586
  1502
                        CHECKRALIGN16( sh4r.r[Rm] ); MEM_READ_WORD( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] += 2;
nkeynes@359
  1503
                        }
nkeynes@359
  1504
                        break;
nkeynes@359
  1505
                    case 0x6:
nkeynes@359
  1506
                        { /* MOV.L @Rm+, Rn */
nkeynes@359
  1507
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@586
  1508
                        CHECKRALIGN32( sh4r.r[Rm] ); MEM_READ_LONG( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] += 4;
nkeynes@359
  1509
                        }
nkeynes@359
  1510
                        break;
nkeynes@359
  1511
                    case 0x7:
nkeynes@359
  1512
                        { /* NOT Rm, Rn */
nkeynes@359
  1513
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1514
                        sh4r.r[Rn] = ~sh4r.r[Rm];
nkeynes@359
  1515
                        }
nkeynes@359
  1516
                        break;
nkeynes@359
  1517
                    case 0x8:
nkeynes@359
  1518
                        { /* SWAP.B Rm, Rn */
nkeynes@359
  1519
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1520
                        sh4r.r[Rn] = (sh4r.r[Rm]&0xFFFF0000) | ((sh4r.r[Rm]&0x0000FF00)>>8) | ((sh4r.r[Rm]&0x000000FF)<<8);
nkeynes@359
  1521
                        }
nkeynes@359
  1522
                        break;
nkeynes@359
  1523
                    case 0x9:
nkeynes@359
  1524
                        { /* SWAP.W Rm, Rn */
nkeynes@359
  1525
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1526
                        sh4r.r[Rn] = (sh4r.r[Rm]>>16) | (sh4r.r[Rm]<<16);
nkeynes@359
  1527
                        }
nkeynes@359
  1528
                        break;
nkeynes@359
  1529
                    case 0xA:
nkeynes@359
  1530
                        { /* NEGC Rm, Rn */
nkeynes@359
  1531
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1532
                        tmp = 0 - sh4r.r[Rm];
nkeynes@359
  1533
                        sh4r.r[Rn] = tmp - sh4r.t;
nkeynes@359
  1534
                        sh4r.t = ( 0<tmp || tmp<sh4r.r[Rn] ? 1 : 0 );
nkeynes@359
  1535
                        }
nkeynes@359
  1536
                        break;
nkeynes@359
  1537
                    case 0xB:
nkeynes@359
  1538
                        { /* NEG Rm, Rn */
nkeynes@359
  1539
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1540
                        sh4r.r[Rn] = 0 - sh4r.r[Rm];
nkeynes@359
  1541
                        }
nkeynes@359
  1542
                        break;
nkeynes@359
  1543
                    case 0xC:
nkeynes@359
  1544
                        { /* EXTU.B Rm, Rn */
nkeynes@359
  1545
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1546
                        sh4r.r[Rn] = sh4r.r[Rm]&0x000000FF;
nkeynes@359
  1547
                        }
nkeynes@359
  1548
                        break;
nkeynes@359
  1549
                    case 0xD:
nkeynes@359
  1550
                        { /* EXTU.W Rm, Rn */
nkeynes@359
  1551
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1552
                        sh4r.r[Rn] = sh4r.r[Rm]&0x0000FFFF;
nkeynes@359
  1553
                        }
nkeynes@359
  1554
                        break;
nkeynes@359
  1555
                    case 0xE:
nkeynes@359
  1556
                        { /* EXTS.B Rm, Rn */
nkeynes@359
  1557
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1558
                        sh4r.r[Rn] = SIGNEXT8( sh4r.r[Rm]&0x000000FF );
nkeynes@359
  1559
                        }
nkeynes@359
  1560
                        break;
nkeynes@359
  1561
                    case 0xF:
nkeynes@359
  1562
                        { /* EXTS.W Rm, Rn */
nkeynes@359
  1563
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1564
                        sh4r.r[Rn] = SIGNEXT16( sh4r.r[Rm]&0x0000FFFF );
nkeynes@359
  1565
                        }
nkeynes@359
  1566
                        break;
nkeynes@359
  1567
                }
nkeynes@359
  1568
                break;
nkeynes@359
  1569
            case 0x7:
nkeynes@359
  1570
                { /* ADD #imm, Rn */
nkeynes@359
  1571
                uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
nkeynes@359
  1572
                sh4r.r[Rn] += imm;
nkeynes@359
  1573
                }
nkeynes@359
  1574
                break;
nkeynes@359
  1575
            case 0x8:
nkeynes@359
  1576
                switch( (ir&0xF00) >> 8 ) {
nkeynes@359
  1577
                    case 0x0:
nkeynes@359
  1578
                        { /* MOV.B R0, @(disp, Rn) */
nkeynes@359
  1579
                        uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
nkeynes@359
  1580
                        MEM_WRITE_BYTE( sh4r.r[Rn] + disp, R0 );
nkeynes@359
  1581
                        }
nkeynes@359
  1582
                        break;
nkeynes@359
  1583
                    case 0x1:
nkeynes@359
  1584
                        { /* MOV.W R0, @(disp, Rn) */
nkeynes@359
  1585
                        uint32_t Rn = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
nkeynes@359
  1586
                        tmp = sh4r.r[Rn] + disp;
nkeynes@359
  1587
                        CHECKWALIGN16( tmp );
nkeynes@359
  1588
                        MEM_WRITE_WORD( tmp, R0 );
nkeynes@359
  1589
                        }
nkeynes@359
  1590
                        break;
nkeynes@359
  1591
                    case 0x4:
nkeynes@359
  1592
                        { /* MOV.B @(disp, Rm), R0 */
nkeynes@359
  1593
                        uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF); 
nkeynes@586
  1594
                        MEM_READ_BYTE( sh4r.r[Rm] + disp, R0 );
nkeynes@359
  1595
                        }
nkeynes@359
  1596
                        break;
nkeynes@359
  1597
                    case 0x5:
nkeynes@359
  1598
                        { /* MOV.W @(disp, Rm), R0 */
nkeynes@359
  1599
                        uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1; 
nkeynes@359
  1600
                        tmp = sh4r.r[Rm] + disp;
nkeynes@359
  1601
                        CHECKRALIGN16( tmp );
nkeynes@586
  1602
                        MEM_READ_WORD( tmp, R0 );
nkeynes@359
  1603
                        }
nkeynes@359
  1604
                        break;
nkeynes@359
  1605
                    case 0x8:
nkeynes@359
  1606
                        { /* CMP/EQ #imm, R0 */
nkeynes@359
  1607
                        int32_t imm = SIGNEXT8(ir&0xFF); 
nkeynes@359
  1608
                        sh4r.t = ( R0 == imm ? 1 : 0 );
nkeynes@359
  1609
                        }
nkeynes@359
  1610
                        break;
nkeynes@359
  1611
                    case 0x9:
nkeynes@359
  1612
                        { /* BT disp */
nkeynes@359
  1613
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@359
  1614
                        CHECKSLOTILLEGAL();
nkeynes@359
  1615
                        if( sh4r.t ) {
nkeynes@359
  1616
                            CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@359
  1617
                            sh4r.pc += disp + 4;
nkeynes@359
  1618
                            sh4r.new_pc = sh4r.pc + 2;
nkeynes@27
  1619
                            return TRUE;
nkeynes@359
  1620
                        }
nkeynes@359
  1621
                        }
nkeynes@359
  1622
                        break;
nkeynes@359
  1623
                    case 0xB:
nkeynes@359
  1624
                        { /* BF disp */
nkeynes@359
  1625
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@359
  1626
                        CHECKSLOTILLEGAL();
nkeynes@359
  1627
                        if( !sh4r.t ) {
nkeynes@359
  1628
                            CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@359
  1629
                            sh4r.pc += disp + 4;
nkeynes@359
  1630
                            sh4r.new_pc = sh4r.pc + 2;
nkeynes@359
  1631
                            return TRUE;
nkeynes@359
  1632
                        }
nkeynes@359
  1633
                        }
nkeynes@359
  1634
                        break;
nkeynes@359
  1635
                    case 0xD:
nkeynes@359
  1636
                        { /* BT/S disp */
nkeynes@359
  1637
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@359
  1638
                        CHECKSLOTILLEGAL();
nkeynes@359
  1639
                        if( sh4r.t ) {
nkeynes@359
  1640
                            CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@2
  1641
                            sh4r.in_delay_slot = 1;
nkeynes@1
  1642
                            sh4r.pc = sh4r.new_pc;
nkeynes@359
  1643
                            sh4r.new_pc = pc + disp + 4;
nkeynes@359
  1644
                            sh4r.in_delay_slot = 1;
nkeynes@27
  1645
                            return TRUE;
nkeynes@359
  1646
                        }
nkeynes@359
  1647
                        }
nkeynes@359
  1648
                        break;
nkeynes@359
  1649
                    case 0xF:
nkeynes@359
  1650
                        { /* BF/S disp */
nkeynes@359
  1651
                        int32_t disp = SIGNEXT8(ir&0xFF)<<1; 
nkeynes@359
  1652
                        CHECKSLOTILLEGAL();
nkeynes@359
  1653
                        if( !sh4r.t ) {
nkeynes@359
  1654
                            CHECKDEST( sh4r.pc + disp + 4 )
nkeynes@2
  1655
                            sh4r.in_delay_slot = 1;
nkeynes@1
  1656
                            sh4r.pc = sh4r.new_pc;
nkeynes@359
  1657
                            sh4r.new_pc = pc + disp + 4;
nkeynes@27
  1658
                            return TRUE;
nkeynes@359
  1659
                        }
nkeynes@359
  1660
                        }
nkeynes@359
  1661
                        break;
nkeynes@359
  1662
                    default:
nkeynes@359
  1663
                        UNDEF();
nkeynes@359
  1664
                        break;
nkeynes@359
  1665
                }
nkeynes@359
  1666
                break;
nkeynes@359
  1667
            case 0x9:
nkeynes@359
  1668
                { /* MOV.W @(disp, PC), Rn */
nkeynes@359
  1669
                uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<1; 
nkeynes@359
  1670
                CHECKSLOTILLEGAL();
nkeynes@359
  1671
                tmp = pc + 4 + disp;
nkeynes@586
  1672
                MEM_READ_WORD( tmp, sh4r.r[Rn] );
nkeynes@359
  1673
                }
nkeynes@359
  1674
                break;
nkeynes@359
  1675
            case 0xA:
nkeynes@359
  1676
                { /* BRA disp */
nkeynes@359
  1677
                int32_t disp = SIGNEXT12(ir&0xFFF)<<1; 
nkeynes@359
  1678
                CHECKSLOTILLEGAL();
nkeynes@359
  1679
                CHECKDEST( sh4r.pc + disp + 4 );
nkeynes@359
  1680
                sh4r.in_delay_slot = 1;
nkeynes@359
  1681
                sh4r.pc = sh4r.new_pc;
nkeynes@359
  1682
                sh4r.new_pc = pc + 4 + disp;
nkeynes@359
  1683
                return TRUE;
nkeynes@359
  1684
                }
nkeynes@359
  1685
                break;
nkeynes@359
  1686
            case 0xB:
nkeynes@359
  1687
                { /* BSR disp */
nkeynes@359
  1688
                int32_t disp = SIGNEXT12(ir&0xFFF)<<1; 
nkeynes@359
  1689
                CHECKDEST( sh4r.pc + disp + 4 );
nkeynes@359
  1690
                CHECKSLOTILLEGAL();
nkeynes@359
  1691
                sh4r.in_delay_slot = 1;
nkeynes@359
  1692
                sh4r.pr = pc + 4;
nkeynes@359
  1693
                sh4r.pc = sh4r.new_pc;
nkeynes@359
  1694
                sh4r.new_pc = pc + 4 + disp;
nkeynes@359
  1695
                TRACE_CALL( pc, sh4r.new_pc );
nkeynes@359
  1696
                return TRUE;
nkeynes@359
  1697
                }
nkeynes@359
  1698
                break;
nkeynes@359
  1699
            case 0xC:
nkeynes@359
  1700
                switch( (ir&0xF00) >> 8 ) {
nkeynes@359
  1701
                    case 0x0:
nkeynes@359
  1702
                        { /* MOV.B R0, @(disp, GBR) */
nkeynes@359
  1703
                        uint32_t disp = (ir&0xFF); 
nkeynes@359
  1704
                        MEM_WRITE_BYTE( sh4r.gbr + disp, R0 );
nkeynes@359
  1705
                        }
nkeynes@359
  1706
                        break;
nkeynes@359
  1707
                    case 0x1:
nkeynes@359
  1708
                        { /* MOV.W R0, @(disp, GBR) */
nkeynes@359
  1709
                        uint32_t disp = (ir&0xFF)<<1; 
nkeynes@359
  1710
                        tmp = sh4r.gbr + disp;
nkeynes@359
  1711
                        CHECKWALIGN16( tmp );
nkeynes@359
  1712
                        MEM_WRITE_WORD( tmp, R0 );
nkeynes@359
  1713
                        }
nkeynes@359
  1714
                        break;
nkeynes@359
  1715
                    case 0x2:
nkeynes@359
  1716
                        { /* MOV.L R0, @(disp, GBR) */
nkeynes@359
  1717
                        uint32_t disp = (ir&0xFF)<<2; 
nkeynes@359
  1718
                        tmp = sh4r.gbr + disp;
nkeynes@359
  1719
                        CHECKWALIGN32( tmp );
nkeynes@359
  1720
                        MEM_WRITE_LONG( tmp, R0 );
nkeynes@359
  1721
                        }
nkeynes@359
  1722
                        break;
nkeynes@359
  1723
                    case 0x3:
nkeynes@359
  1724
                        { /* TRAPA #imm */
nkeynes@359
  1725
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1726
                        CHECKSLOTILLEGAL();
nkeynes@359
  1727
                        sh4r.pc += 2;
nkeynes@586
  1728
                        sh4_raise_trap( imm );
nkeynes@586
  1729
                        return TRUE;
nkeynes@359
  1730
                        }
nkeynes@359
  1731
                        break;
nkeynes@359
  1732
                    case 0x4:
nkeynes@359
  1733
                        { /* MOV.B @(disp, GBR), R0 */
nkeynes@359
  1734
                        uint32_t disp = (ir&0xFF); 
nkeynes@586
  1735
                        MEM_READ_BYTE( sh4r.gbr + disp, R0 );
nkeynes@359
  1736
                        }
nkeynes@359
  1737
                        break;
nkeynes@359
  1738
                    case 0x5:
nkeynes@359
  1739
                        { /* MOV.W @(disp, GBR), R0 */
nkeynes@359
  1740
                        uint32_t disp = (ir&0xFF)<<1; 
nkeynes@359
  1741
                        tmp = sh4r.gbr + disp;
nkeynes@359
  1742
                        CHECKRALIGN16( tmp );
nkeynes@586
  1743
                        MEM_READ_WORD( tmp, R0 );
nkeynes@359
  1744
                        }
nkeynes@359
  1745
                        break;
nkeynes@359
  1746
                    case 0x6:
nkeynes@359
  1747
                        { /* MOV.L @(disp, GBR), R0 */
nkeynes@359
  1748
                        uint32_t disp = (ir&0xFF)<<2; 
nkeynes@359
  1749
                        tmp = sh4r.gbr + disp;
nkeynes@359
  1750
                        CHECKRALIGN32( tmp );
nkeynes@586
  1751
                        MEM_READ_LONG( tmp, R0 );
nkeynes@359
  1752
                        }
nkeynes@359
  1753
                        break;
nkeynes@359
  1754
                    case 0x7:
nkeynes@359
  1755
                        { /* MOVA @(disp, PC), R0 */
nkeynes@359
  1756
                        uint32_t disp = (ir&0xFF)<<2; 
nkeynes@359
  1757
                        CHECKSLOTILLEGAL();
nkeynes@359
  1758
                        R0 = (pc&0xFFFFFFFC) + disp + 4;
nkeynes@359
  1759
                        }
nkeynes@359
  1760
                        break;
nkeynes@359
  1761
                    case 0x8:
nkeynes@359
  1762
                        { /* TST #imm, R0 */
nkeynes@359
  1763
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1764
                        sh4r.t = (R0 & imm ? 0 : 1);
nkeynes@359
  1765
                        }
nkeynes@359
  1766
                        break;
nkeynes@359
  1767
                    case 0x9:
nkeynes@359
  1768
                        { /* AND #imm, R0 */
nkeynes@359
  1769
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1770
                        R0 &= imm;
nkeynes@359
  1771
                        }
nkeynes@359
  1772
                        break;
nkeynes@359
  1773
                    case 0xA:
nkeynes@359
  1774
                        { /* XOR #imm, R0 */
nkeynes@359
  1775
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1776
                        R0 ^= imm;
nkeynes@359
  1777
                        }
nkeynes@359
  1778
                        break;
nkeynes@359
  1779
                    case 0xB:
nkeynes@359
  1780
                        { /* OR #imm, R0 */
nkeynes@359
  1781
                        uint32_t imm = (ir&0xFF); 
nkeynes@359
  1782
                        R0 |= imm;
nkeynes@359
  1783
                        }
nkeynes@359
  1784
                        break;
nkeynes@359
  1785
                    case 0xC:
nkeynes@359
  1786
                        { /* TST.B #imm, @(R0, GBR) */
nkeynes@359
  1787
                        uint32_t imm = (ir&0xFF); 
nkeynes@586
  1788
                        MEM_READ_BYTE(R0+sh4r.gbr, tmp); sh4r.t = ( tmp & imm ? 0 : 1 );
nkeynes@359
  1789
                        }
nkeynes@359
  1790
                        break;
nkeynes@359
  1791
                    case 0xD:
nkeynes@359
  1792
                        { /* AND.B #imm, @(R0, GBR) */
nkeynes@359
  1793
                        uint32_t imm = (ir&0xFF); 
nkeynes@586
  1794
                        MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm & tmp );
nkeynes@359
  1795
                        }
nkeynes@359
  1796
                        break;
nkeynes@359
  1797
                    case 0xE:
nkeynes@359
  1798
                        { /* XOR.B #imm, @(R0, GBR) */
nkeynes@359
  1799
                        uint32_t imm = (ir&0xFF); 
nkeynes@586
  1800
                        MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm ^ tmp );
nkeynes@359
  1801
                        }
nkeynes@359
  1802
                        break;
nkeynes@359
  1803
                    case 0xF:
nkeynes@359
  1804
                        { /* OR.B #imm, @(R0, GBR) */
nkeynes@359
  1805
                        uint32_t imm = (ir&0xFF); 
nkeynes@586
  1806
                        MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm | tmp );
nkeynes@359
  1807
                        }
nkeynes@359
  1808
                        break;
nkeynes@359
  1809
                }
nkeynes@359
  1810
                break;
nkeynes@359
  1811
            case 0xD:
nkeynes@359
  1812
                { /* MOV.L @(disp, PC), Rn */
nkeynes@359
  1813
                uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<2; 
nkeynes@359
  1814
                CHECKSLOTILLEGAL();
nkeynes@359
  1815
                tmp = (pc&0xFFFFFFFC) + disp + 4;
nkeynes@586
  1816
                MEM_READ_LONG( tmp, sh4r.r[Rn] );
nkeynes@359
  1817
                }
nkeynes@359
  1818
                break;
nkeynes@359
  1819
            case 0xE:
nkeynes@359
  1820
                { /* MOV #imm, Rn */
nkeynes@359
  1821
                uint32_t Rn = ((ir>>8)&0xF); int32_t imm = SIGNEXT8(ir&0xFF); 
nkeynes@359
  1822
                sh4r.r[Rn] = imm;
nkeynes@359
  1823
                }
nkeynes@359
  1824
                break;
nkeynes@359
  1825
            case 0xF:
nkeynes@359
  1826
                switch( ir&0xF ) {
nkeynes@359
  1827
                    case 0x0:
nkeynes@359
  1828
                        { /* FADD FRm, FRn */
nkeynes@359
  1829
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1830
                        CHECKFPUEN();
nkeynes@359
  1831
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1832
                    	DR(FRn) += DR(FRm);
nkeynes@359
  1833
                        } else {
nkeynes@359
  1834
                    	FR(FRn) += FR(FRm);
nkeynes@359
  1835
                        }
nkeynes@359
  1836
                        }
nkeynes@359
  1837
                        break;
nkeynes@359
  1838
                    case 0x1:
nkeynes@359
  1839
                        { /* FSUB FRm, FRn */
nkeynes@359
  1840
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1841
                        CHECKFPUEN();
nkeynes@359
  1842
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1843
                    	DR(FRn) -= DR(FRm);
nkeynes@359
  1844
                        } else {
nkeynes@359
  1845
                    	FR(FRn) -= FR(FRm);
nkeynes@359
  1846
                        }
nkeynes@359
  1847
                        }
nkeynes@359
  1848
                        break;
nkeynes@359
  1849
                    case 0x2:
nkeynes@359
  1850
                        { /* FMUL FRm, FRn */
nkeynes@359
  1851
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1852
                        CHECKFPUEN();
nkeynes@359
  1853
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1854
                    	DR(FRn) *= DR(FRm);
nkeynes@359
  1855
                        } else {
nkeynes@359
  1856
                    	FR(FRn) *= FR(FRm);
nkeynes@359
  1857
                        }
nkeynes@359
  1858
                        }
nkeynes@359
  1859
                        break;
nkeynes@359
  1860
                    case 0x3:
nkeynes@359
  1861
                        { /* FDIV FRm, FRn */
nkeynes@359
  1862
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1863
                        CHECKFPUEN();
nkeynes@359
  1864
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1865
                    	DR(FRn) /= DR(FRm);
nkeynes@359
  1866
                        } else {
nkeynes@359
  1867
                    	FR(FRn) /= FR(FRm);
nkeynes@359
  1868
                        }
nkeynes@359
  1869
                        }
nkeynes@359
  1870
                        break;
nkeynes@359
  1871
                    case 0x4:
nkeynes@359
  1872
                        { /* FCMP/EQ FRm, FRn */
nkeynes@359
  1873
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1874
                        CHECKFPUEN();
nkeynes@359
  1875
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1876
                    	sh4r.t = ( DR(FRn) == DR(FRm) ? 1 : 0 );
nkeynes@359
  1877
                        } else {
nkeynes@359
  1878
                    	sh4r.t = ( FR(FRn) == FR(FRm) ? 1 : 0 );
nkeynes@359
  1879
                        }
nkeynes@359
  1880
                        }
nkeynes@359
  1881
                        break;
nkeynes@359
  1882
                    case 0x5:
nkeynes@359
  1883
                        { /* FCMP/GT FRm, FRn */
nkeynes@359
  1884
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1885
                        CHECKFPUEN();
nkeynes@359
  1886
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  1887
                    	sh4r.t = ( DR(FRn) > DR(FRm) ? 1 : 0 );
nkeynes@359
  1888
                        } else {
nkeynes@359
  1889
                    	sh4r.t = ( FR(FRn) > FR(FRm) ? 1 : 0 );
nkeynes@359
  1890
                        }
nkeynes@359
  1891
                        }
nkeynes@359
  1892
                        break;
nkeynes@359
  1893
                    case 0x6:
nkeynes@359
  1894
                        { /* FMOV @(R0, Rm), FRn */
nkeynes@359
  1895
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1896
                        MEM_FP_READ( sh4r.r[Rm] + R0, FRn );
nkeynes@359
  1897
                        }
nkeynes@359
  1898
                        break;
nkeynes@359
  1899
                    case 0x7:
nkeynes@359
  1900
                        { /* FMOV FRm, @(R0, Rn) */
nkeynes@359
  1901
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1902
                        MEM_FP_WRITE( sh4r.r[Rn] + R0, FRm );
nkeynes@359
  1903
                        }
nkeynes@359
  1904
                        break;
nkeynes@359
  1905
                    case 0x8:
nkeynes@359
  1906
                        { /* FMOV @Rm, FRn */
nkeynes@359
  1907
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1908
                        MEM_FP_READ( sh4r.r[Rm], FRn );
nkeynes@359
  1909
                        }
nkeynes@359
  1910
                        break;
nkeynes@359
  1911
                    case 0x9:
nkeynes@359
  1912
                        { /* FMOV @Rm+, FRn */
nkeynes@359
  1913
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); 
nkeynes@359
  1914
                        MEM_FP_READ( sh4r.r[Rm], FRn ); sh4r.r[Rm] += FP_WIDTH;
nkeynes@359
  1915
                        }
nkeynes@359
  1916
                        break;
nkeynes@359
  1917
                    case 0xA:
nkeynes@359
  1918
                        { /* FMOV FRm, @Rn */
nkeynes@359
  1919
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1920
                        MEM_FP_WRITE( sh4r.r[Rn], FRm );
nkeynes@359
  1921
                        }
nkeynes@359
  1922
                        break;
nkeynes@359
  1923
                    case 0xB:
nkeynes@359
  1924
                        { /* FMOV FRm, @-Rn */
nkeynes@359
  1925
                        uint32_t Rn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@587
  1926
                        MEM_FP_WRITE( sh4r.r[Rn] - FP_WIDTH, FRm ); sh4r.r[Rn] -= FP_WIDTH;
nkeynes@359
  1927
                        }
nkeynes@359
  1928
                        break;
nkeynes@359
  1929
                    case 0xC:
nkeynes@359
  1930
                        { /* FMOV FRm, FRn */
nkeynes@359
  1931
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  1932
                        if( IS_FPU_DOUBLESIZE() )
nkeynes@359
  1933
                    	DR(FRn) = DR(FRm);
nkeynes@359
  1934
                        else
nkeynes@359
  1935
                    	FR(FRn) = FR(FRm);
nkeynes@359
  1936
                        }
nkeynes@359
  1937
                        break;
nkeynes@359
  1938
                    case 0xD:
nkeynes@359
  1939
                        switch( (ir&0xF0) >> 4 ) {
nkeynes@359
  1940
                            case 0x0:
nkeynes@359
  1941
                                { /* FSTS FPUL, FRn */
nkeynes@359
  1942
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  1943
                                CHECKFPUEN(); FR(FRn) = FPULf;
nkeynes@359
  1944
                                }
nkeynes@359
  1945
                                break;
nkeynes@359
  1946
                            case 0x1:
nkeynes@359
  1947
                                { /* FLDS FRm, FPUL */
nkeynes@359
  1948
                                uint32_t FRm = ((ir>>8)&0xF); 
nkeynes@359
  1949
                                CHECKFPUEN(); FPULf = FR(FRm);
nkeynes@359
  1950
                                }
nkeynes@359
  1951
                                break;
nkeynes@359
  1952
                            case 0x2:
nkeynes@359
  1953
                                { /* FLOAT FPUL, FRn */
nkeynes@359
  1954
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  1955
                                CHECKFPUEN();
nkeynes@374
  1956
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@374
  1957
                            	if( FRn&1 ) { // No, really...
nkeynes@374
  1958
                            	    dtmp = (double)FPULi;
nkeynes@374
  1959
                            	    FR(FRn) = *(((float *)&dtmp)+1);
nkeynes@374
  1960
                            	} else {
nkeynes@374
  1961
                            	    DRF(FRn>>1) = (double)FPULi;
nkeynes@374
  1962
                            	}
nkeynes@374
  1963
                                } else {
nkeynes@359
  1964
                            	FR(FRn) = (float)FPULi;
nkeynes@359
  1965
                                }
nkeynes@374
  1966
                                }
nkeynes@359
  1967
                                break;
nkeynes@359
  1968
                            case 0x3:
nkeynes@359
  1969
                                { /* FTRC FRm, FPUL */
nkeynes@359
  1970
                                uint32_t FRm = ((ir>>8)&0xF); 
nkeynes@359
  1971
                                CHECKFPUEN();
nkeynes@359
  1972
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@374
  1973
                            	if( FRm&1 ) {
nkeynes@374
  1974
                            	    dtmp = 0;
nkeynes@374
  1975
                            	    *(((float *)&dtmp)+1) = FR(FRm);
nkeynes@374
  1976
                            	} else {
nkeynes@374
  1977
                            	    dtmp = DRF(FRm>>1);
nkeynes@374
  1978
                            	}
nkeynes@359
  1979
                                    if( dtmp >= MAX_INTF )
nkeynes@359
  1980
                                        FPULi = MAX_INT;
nkeynes@359
  1981
                                    else if( dtmp <= MIN_INTF )
nkeynes@359
  1982
                                        FPULi = MIN_INT;
nkeynes@359
  1983
                                    else 
nkeynes@359
  1984
                                        FPULi = (int32_t)dtmp;
nkeynes@359
  1985
                                } else {
nkeynes@359
  1986
                            	ftmp = FR(FRm);
nkeynes@359
  1987
                            	if( ftmp >= MAX_INTF )
nkeynes@359
  1988
                            	    FPULi = MAX_INT;
nkeynes@359
  1989
                            	else if( ftmp <= MIN_INTF )
nkeynes@359
  1990
                            	    FPULi = MIN_INT;
nkeynes@359
  1991
                            	else
nkeynes@359
  1992
                            	    FPULi = (int32_t)ftmp;
nkeynes@359
  1993
                                }
nkeynes@359
  1994
                                }
nkeynes@359
  1995
                                break;
nkeynes@359
  1996
                            case 0x4:
nkeynes@359
  1997
                                { /* FNEG FRn */
nkeynes@359
  1998
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  1999
                                CHECKFPUEN();
nkeynes@359
  2000
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2001
                            	DR(FRn) = -DR(FRn);
nkeynes@359
  2002
                                } else {
nkeynes@359
  2003
                                    FR(FRn) = -FR(FRn);
nkeynes@359
  2004
                                }
nkeynes@359
  2005
                                }
nkeynes@359
  2006
                                break;
nkeynes@359
  2007
                            case 0x5:
nkeynes@359
  2008
                                { /* FABS FRn */
nkeynes@359
  2009
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2010
                                CHECKFPUEN();
nkeynes@359
  2011
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2012
                            	DR(FRn) = fabs(DR(FRn));
nkeynes@359
  2013
                                } else {
nkeynes@359
  2014
                                    FR(FRn) = fabsf(FR(FRn));
nkeynes@359
  2015
                                }
nkeynes@359
  2016
                                }
nkeynes@359
  2017
                                break;
nkeynes@359
  2018
                            case 0x6:
nkeynes@359
  2019
                                { /* FSQRT FRn */
nkeynes@359
  2020
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2021
                                CHECKFPUEN();
nkeynes@359
  2022
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2023
                            	DR(FRn) = sqrt(DR(FRn));
nkeynes@359
  2024
                                } else {
nkeynes@359
  2025
                                    FR(FRn) = sqrtf(FR(FRn));
nkeynes@359
  2026
                                }
nkeynes@359
  2027
                                }
nkeynes@359
  2028
                                break;
nkeynes@359
  2029
                            case 0x7:
nkeynes@359
  2030
                                { /* FSRRA FRn */
nkeynes@359
  2031
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2032
                                CHECKFPUEN();
nkeynes@359
  2033
                                if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2034
                            	FR(FRn) = 1.0/sqrtf(FR(FRn));
nkeynes@359
  2035
                                }
nkeynes@359
  2036
                                }
nkeynes@359
  2037
                                break;
nkeynes@359
  2038
                            case 0x8:
nkeynes@359
  2039
                                { /* FLDI0 FRn */
nkeynes@359
  2040
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2041
                                CHECKFPUEN();
nkeynes@359
  2042
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2043
                            	DR(FRn) = 0.0;
nkeynes@359
  2044
                                } else {
nkeynes@359
  2045
                                    FR(FRn) = 0.0;
nkeynes@359
  2046
                                }
nkeynes@359
  2047
                                }
nkeynes@359
  2048
                                break;
nkeynes@359
  2049
                            case 0x9:
nkeynes@359
  2050
                                { /* FLDI1 FRn */
nkeynes@359
  2051
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2052
                                CHECKFPUEN();
nkeynes@359
  2053
                                if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2054
                            	DR(FRn) = 1.0;
nkeynes@359
  2055
                                } else {
nkeynes@359
  2056
                                    FR(FRn) = 1.0;
nkeynes@359
  2057
                                }
nkeynes@359
  2058
                                }
nkeynes@359
  2059
                                break;
nkeynes@359
  2060
                            case 0xA:
nkeynes@359
  2061
                                { /* FCNVSD FPUL, FRn */
nkeynes@359
  2062
                                uint32_t FRn = ((ir>>8)&0xF); 
nkeynes@359
  2063
                                CHECKFPUEN();
nkeynes@359
  2064
                                if( IS_FPU_DOUBLEPREC() && !IS_FPU_DOUBLESIZE() ) {
nkeynes@359
  2065
                            	DR(FRn) = (double)FPULf;
nkeynes@359
  2066
                                }
nkeynes@359
  2067
                                }
nkeynes@359
  2068
                                break;
nkeynes@359
  2069
                            case 0xB:
nkeynes@359
  2070
                                { /* FCNVDS FRm, FPUL */
nkeynes@359
  2071
                                uint32_t FRm = ((ir>>8)&0xF); 
nkeynes@359
  2072
                                CHECKFPUEN();
nkeynes@359
  2073
                                if( IS_FPU_DOUBLEPREC() && !IS_FPU_DOUBLESIZE() ) {
nkeynes@359
  2074
                            	FPULf = (float)DR(FRm);
nkeynes@359
  2075
                                }
nkeynes@359
  2076
                                }
nkeynes@359
  2077
                                break;
nkeynes@359
  2078
                            case 0xE:
nkeynes@359
  2079
                                { /* FIPR FVm, FVn */
nkeynes@359
  2080
                                uint32_t FVn = ((ir>>10)&0x3); uint32_t FVm = ((ir>>8)&0x3); 
nkeynes@359
  2081
                                CHECKFPUEN();
nkeynes@359
  2082
                                if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2083
                                    int tmp2 = FVn<<2;
nkeynes@359
  2084
                                    tmp = FVm<<2;
nkeynes@359
  2085
                                    FR(tmp2+3) = FR(tmp)*FR(tmp2) +
nkeynes@359
  2086
                                        FR(tmp+1)*FR(tmp2+1) +
nkeynes@359
  2087
                                        FR(tmp+2)*FR(tmp2+2) +
nkeynes@359
  2088
                                        FR(tmp+3)*FR(tmp2+3);
nkeynes@359
  2089
                                }
nkeynes@359
  2090
                                }
nkeynes@359
  2091
                                break;
nkeynes@359
  2092
                            case 0xF:
nkeynes@359
  2093
                                switch( (ir&0x100) >> 8 ) {
nkeynes@359
  2094
                                    case 0x0:
nkeynes@359
  2095
                                        { /* FSCA FPUL, FRn */
nkeynes@359
  2096
                                        uint32_t FRn = ((ir>>9)&0x7)<<1; 
nkeynes@359
  2097
                                        CHECKFPUEN();
nkeynes@359
  2098
                                        if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@391
  2099
                                    	sh4_fsca( FPULi, &(DRF(FRn>>1)) );
nkeynes@391
  2100
                                    	/*
nkeynes@359
  2101
                                            float angle = (((float)(FPULi&0xFFFF))/65536.0) * 2 * M_PI;
nkeynes@359
  2102
                                            FR(FRn) = sinf(angle);
nkeynes@359
  2103
                                            FR((FRn)+1) = cosf(angle);
nkeynes@391
  2104
                                    	*/
nkeynes@359
  2105
                                        }
nkeynes@359
  2106
                                        }
nkeynes@359
  2107
                                        break;
nkeynes@359
  2108
                                    case 0x1:
nkeynes@359
  2109
                                        switch( (ir&0x200) >> 9 ) {
nkeynes@359
  2110
                                            case 0x0:
nkeynes@359
  2111
                                                { /* FTRV XMTRX, FVn */
nkeynes@359
  2112
                                                uint32_t FVn = ((ir>>10)&0x3); 
nkeynes@359
  2113
                                                CHECKFPUEN();
nkeynes@359
  2114
                                                if( !IS_FPU_DOUBLEPREC() ) {
nkeynes@391
  2115
                                            	sh4_ftrv(&(DRF(FVn<<1)), &sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21][0]);
nkeynes@391
  2116
                                            	/*
nkeynes@359
  2117
                                                    tmp = FVn<<2;
nkeynes@374
  2118
                                            	float *xf = &sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21][0];
nkeynes@359
  2119
                                                    float fv[4] = { FR(tmp), FR(tmp+1), FR(tmp+2), FR(tmp+3) };
nkeynes@374
  2120
                                                    FR(tmp) = xf[1] * fv[0] + xf[5]*fv[1] +
nkeynes@374
  2121
                                            	    xf[9]*fv[2] + xf[13]*fv[3];
nkeynes@374
  2122
                                                    FR(tmp+1) = xf[0] * fv[0] + xf[4]*fv[1] +
nkeynes@374
  2123
                                            	    xf[8]*fv[2] + xf[12]*fv[3];
nkeynes@374
  2124
                                                    FR(tmp+2) = xf[3] * fv[0] + xf[7]*fv[1] +
nkeynes@374
  2125
                                            	    xf[11]*fv[2] + xf[15]*fv[3];
nkeynes@374
  2126
                                                    FR(tmp+3) = xf[2] * fv[0] + xf[6]*fv[1] +
nkeynes@374
  2127
                                            	    xf[10]*fv[2] + xf[14]*fv[3];
nkeynes@391
  2128
                                            	*/
nkeynes@359
  2129
                                                }
nkeynes@359
  2130
                                                }
nkeynes@359
  2131
                                                break;
nkeynes@359
  2132
                                            case 0x1:
nkeynes@359
  2133
                                                switch( (ir&0xC00) >> 10 ) {
nkeynes@359
  2134
                                                    case 0x0:
nkeynes@359
  2135
                                                        { /* FSCHG */
nkeynes@359
  2136
                                                        CHECKFPUEN(); sh4r.fpscr ^= FPSCR_SZ;
nkeynes@359
  2137
                                                        }
nkeynes@359
  2138
                                                        break;
nkeynes@359
  2139
                                                    case 0x2:
nkeynes@359
  2140
                                                        { /* FRCHG */
nkeynes@374
  2141
                                                        CHECKFPUEN(); 
nkeynes@374
  2142
                                                        sh4r.fpscr ^= FPSCR_FR; 
nkeynes@374
  2143
                                                        sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0];
nkeynes@359
  2144
                                                        }
nkeynes@359
  2145
                                                        break;
nkeynes@359
  2146
                                                    case 0x3:
nkeynes@359
  2147
                                                        { /* UNDEF */
nkeynes@359
  2148
                                                        UNDEF(ir);
nkeynes@359
  2149
                                                        }
nkeynes@359
  2150
                                                        break;
nkeynes@359
  2151
                                                    default:
nkeynes@359
  2152
                                                        UNDEF();
nkeynes@359
  2153
                                                        break;
nkeynes@359
  2154
                                                }
nkeynes@359
  2155
                                                break;
nkeynes@359
  2156
                                        }
nkeynes@359
  2157
                                        break;
nkeynes@359
  2158
                                }
nkeynes@359
  2159
                                break;
nkeynes@359
  2160
                            default:
nkeynes@359
  2161
                                UNDEF();
nkeynes@359
  2162
                                break;
nkeynes@359
  2163
                        }
nkeynes@359
  2164
                        break;
nkeynes@359
  2165
                    case 0xE:
nkeynes@359
  2166
                        { /* FMAC FR0, FRm, FRn */
nkeynes@359
  2167
                        uint32_t FRn = ((ir>>8)&0xF); uint32_t FRm = ((ir>>4)&0xF); 
nkeynes@359
  2168
                        CHECKFPUEN();
nkeynes@359
  2169
                        if( IS_FPU_DOUBLEPREC() ) {
nkeynes@359
  2170
                            DR(FRn) += DR(FRm)*DR(0);
nkeynes@359
  2171
                        } else {
nkeynes@359
  2172
                    	FR(FRn) += FR(FRm)*FR(0);
nkeynes@359
  2173
                        }
nkeynes@359
  2174
                        }
nkeynes@359
  2175
                        break;
nkeynes@359
  2176
                    default:
nkeynes@359
  2177
                        UNDEF();
nkeynes@359
  2178
                        break;
nkeynes@359
  2179
                }
nkeynes@359
  2180
                break;
nkeynes@359
  2181
        }
nkeynes@1
  2182
nkeynes@1
  2183
    sh4r.pc = sh4r.new_pc;
nkeynes@1
  2184
    sh4r.new_pc += 2;
nkeynes@2
  2185
    sh4r.in_delay_slot = 0;
nkeynes@273
  2186
    return TRUE;
nkeynes@1
  2187
}
.