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