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