Search
lxdream.org :: lxdream/src/sh4/sh4core.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.c
changeset 124:ceb38f08619a
prev123:2ad156e10657
next157:fbe03268ad8a
author nkeynes
date Wed Mar 22 14:27:40 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Fix FMOV for writes to the back bank (ie FMOV @R1, XD2)
file annotate diff log raw
nkeynes@23
     1
/**
nkeynes@124
     2
 * $Id: sh4core.c,v 1.26 2006-03-22 14:27:40 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@123
    30
#define MAX_INT 0x7FFFFFFF
nkeynes@123
    31
#define MIN_INT 0x80000000
nkeynes@123
    32
#define MAX_INTF 2147483647.0
nkeynes@123
    33
#define MIN_INTF -2147483648.0
nkeynes@123
    34
nkeynes@27
    35
/* CPU-generated exception code/vector pairs */
nkeynes@27
    36
#define EXC_POWER_RESET  0x000 /* vector special */
nkeynes@27
    37
#define EXC_MANUAL_RESET 0x020
nkeynes@27
    38
#define EXC_SLOT_ILLEGAL 0x1A0
nkeynes@27
    39
#define EXC_ILLEGAL      0x180
nkeynes@27
    40
#define EXV_ILLEGAL      0x100
nkeynes@27
    41
#define EXC_TRAP         0x160
nkeynes@27
    42
#define EXV_TRAP         0x100
nkeynes@27
    43
#define EXC_FPDISABLE    0x800
nkeynes@27
    44
#define EXV_FPDISABLE    0x100
nkeynes@27
    45
nkeynes@23
    46
/********************** SH4 Module Definition ****************************/
nkeynes@23
    47
nkeynes@23
    48
void sh4_init( void );
nkeynes@23
    49
void sh4_reset( void );
nkeynes@30
    50
uint32_t sh4_run_slice( uint32_t );
nkeynes@23
    51
void sh4_start( void );
nkeynes@23
    52
void sh4_stop( void );
nkeynes@23
    53
void sh4_save_state( FILE *f );
nkeynes@23
    54
int sh4_load_state( FILE *f );
nkeynes@16
    55
nkeynes@15
    56
struct dreamcast_module sh4_module = { "SH4", sh4_init, sh4_reset, 
nkeynes@23
    57
				       NULL, sh4_run_slice, sh4_stop,
nkeynes@23
    58
				       sh4_save_state, sh4_load_state };
nkeynes@15
    59
nkeynes@1
    60
struct sh4_registers sh4r;
nkeynes@1
    61
nkeynes@1
    62
void sh4_init(void)
nkeynes@1
    63
{
nkeynes@1
    64
    register_io_regions( mmio_list_sh4mmio );
nkeynes@10
    65
    mmu_init();
nkeynes@27
    66
    sh4_reset();
nkeynes@1
    67
}
nkeynes@1
    68
nkeynes@1
    69
void sh4_reset(void)
nkeynes@1
    70
{
nkeynes@19
    71
    /* zero everything out, for the sake of having a consistent state. */
nkeynes@19
    72
    memset( &sh4r, 0, sizeof(sh4r) );
nkeynes@27
    73
nkeynes@27
    74
    /* Resume running if we were halted */
nkeynes@27
    75
    sh4r.sh4_state = SH4_STATE_RUNNING;
nkeynes@27
    76
nkeynes@1
    77
    sh4r.pc    = 0xA0000000;
nkeynes@1
    78
    sh4r.new_pc= 0xA0000002;
nkeynes@1
    79
    sh4r.vbr   = 0x00000000;
nkeynes@1
    80
    sh4r.fpscr = 0x00040001;
nkeynes@1
    81
    sh4r.sr    = 0x700000F0;
nkeynes@27
    82
nkeynes@27
    83
    /* Mem reset will do this, but if we want to reset _just_ the SH4... */
nkeynes@27
    84
    MMIO_WRITE( MMU, EXPEVT, EXC_POWER_RESET );
nkeynes@27
    85
nkeynes@27
    86
    /* Peripheral modules */
nkeynes@1
    87
    intc_reset();
nkeynes@32
    88
    SCIF_reset();
nkeynes@1
    89
}
nkeynes@1
    90
nkeynes@43
    91
static struct breakpoint_struct sh4_breakpoints[MAX_BREAKPOINTS];
nkeynes@43
    92
static int sh4_breakpoint_count = 0;
nkeynes@43
    93
nkeynes@43
    94
void sh4_set_breakpoint( uint32_t pc, int type )
nkeynes@43
    95
{
nkeynes@43
    96
    sh4_breakpoints[sh4_breakpoint_count].address = pc;
nkeynes@43
    97
    sh4_breakpoints[sh4_breakpoint_count].type = type;
nkeynes@43
    98
    sh4_breakpoint_count++;
nkeynes@43
    99
}
nkeynes@43
   100
nkeynes@43
   101
gboolean sh4_clear_breakpoint( uint32_t pc, int type )
nkeynes@43
   102
{
nkeynes@43
   103
    int i;
nkeynes@43
   104
nkeynes@43
   105
    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@43
   106
	if( sh4_breakpoints[i].address == pc && 
nkeynes@43
   107
	    sh4_breakpoints[i].type == type ) {
nkeynes@43
   108
	    while( ++i < sh4_breakpoint_count ) {
nkeynes@43
   109
		sh4_breakpoints[i-1].address = sh4_breakpoints[i].address;
nkeynes@43
   110
		sh4_breakpoints[i-1].type = sh4_breakpoints[i].type;
nkeynes@43
   111
	    }
nkeynes@43
   112
	    sh4_breakpoint_count--;
nkeynes@43
   113
	    return TRUE;
nkeynes@43
   114
	}
nkeynes@43
   115
    }
nkeynes@43
   116
    return FALSE;
nkeynes@43
   117
}
nkeynes@43
   118
nkeynes@43
   119
int sh4_get_breakpoint( uint32_t pc )
nkeynes@43
   120
{
nkeynes@43
   121
    int i;
nkeynes@43
   122
    for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@43
   123
	if( sh4_breakpoints[i].address == pc )
nkeynes@43
   124
	    return sh4_breakpoints[i].type;
nkeynes@43
   125
    }
nkeynes@43
   126
    return 0;
nkeynes@43
   127
}
nkeynes@43
   128
nkeynes@30
   129
uint32_t sh4_run_slice( uint32_t nanosecs ) 
nkeynes@1
   130
{
nkeynes@30
   131
    int target = sh4r.icount + nanosecs / sh4_cpu_period;
nkeynes@27
   132
    int start = sh4r.icount;
nkeynes@23
   133
    int i;
nkeynes@23
   134
nkeynes@27
   135
    if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
nkeynes@27
   136
	if( sh4r.int_pending != 0 )
nkeynes@27
   137
	    sh4r.sh4_state = SH4_STATE_RUNNING;;
nkeynes@23
   138
    }
nkeynes@27
   139
nkeynes@53
   140
    for( sh4r.slice_cycle = 0; sh4r.slice_cycle < nanosecs; sh4r.slice_cycle += sh4_cpu_period ) {
nkeynes@27
   141
	if( !sh4_execute_instruction() )
nkeynes@27
   142
	    break;
nkeynes@43
   143
#ifdef ENABLE_DEBUG_MODE
nkeynes@43
   144
	for( i=0; i<sh4_breakpoint_count; i++ ) {
nkeynes@43
   145
	    if( sh4_breakpoints[i].address == sh4r.pc ) {
nkeynes@43
   146
		break;
nkeynes@43
   147
	    }
nkeynes@43
   148
	}
nkeynes@43
   149
	if( i != sh4_breakpoint_count ) {
nkeynes@43
   150
	    dreamcast_stop();
nkeynes@43
   151
	    if( sh4_breakpoints[i].type == BREAK_ONESHOT )
nkeynes@43
   152
		sh4_clear_breakpoint( sh4r.pc, BREAK_ONESHOT );
nkeynes@43
   153
	    break;
nkeynes@43
   154
	}
nkeynes@43
   155
#endif	
nkeynes@27
   156
    }
nkeynes@30
   157
nkeynes@30
   158
    /* If we aborted early, but the cpu is still technically running,
nkeynes@30
   159
     * we're doing a hard abort - cut the timeslice back to what we
nkeynes@30
   160
     * actually executed
nkeynes@30
   161
     */
nkeynes@53
   162
    if( sh4r.slice_cycle != nanosecs && sh4r.sh4_state == SH4_STATE_RUNNING ) {
nkeynes@53
   163
	nanosecs = sh4r.slice_cycle;
nkeynes@27
   164
    }
nkeynes@27
   165
    if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
nkeynes@30
   166
	TMU_run_slice( nanosecs );
nkeynes@30
   167
	SCIF_run_slice( nanosecs );
nkeynes@27
   168
    }
nkeynes@53
   169
    sh4r.icount += sh4r.slice_cycle / sh4_cpu_period;
nkeynes@30
   170
    return nanosecs;
nkeynes@1
   171
}
nkeynes@1
   172
nkeynes@1
   173
void sh4_stop(void)
nkeynes@1
   174
{
nkeynes@27
   175
nkeynes@1
   176
}
nkeynes@1
   177
nkeynes@23
   178
void sh4_save_state( FILE *f )
nkeynes@16
   179
{
nkeynes@16
   180
    fwrite( &sh4r, sizeof(sh4r), 1, f );
nkeynes@53
   181
    TMU_save_state( f );
nkeynes@23
   182
    SCIF_save_state( f );
nkeynes@16
   183
}
nkeynes@16
   184
nkeynes@23
   185
int sh4_load_state( FILE * f )
nkeynes@16
   186
{
nkeynes@18
   187
    fread( &sh4r, sizeof(sh4r), 1, f );
nkeynes@53
   188
    TMU_load_state( f );
nkeynes@23
   189
    return SCIF_load_state( f );
nkeynes@16
   190
}
nkeynes@16
   191
nkeynes@23
   192
/********************** SH4 emulation core  ****************************/
nkeynes@23
   193
nkeynes@23
   194
void sh4_set_pc( int pc )
nkeynes@23
   195
{
nkeynes@23
   196
    sh4r.pc = pc;
nkeynes@23
   197
    sh4r.new_pc = pc+2;
nkeynes@23
   198
}
nkeynes@23
   199
nkeynes@104
   200
#define UNDEF(ir) do{ ERROR( "Raising exception on undefined instruction at %08x, opcode = %04x", sh4r.pc, ir ); dreamcast_stop();  return FALSE; }while(0)
nkeynes@27
   201
#define UNIMP(ir) do{ ERROR( "Halted on unimplemented instruction at %08x, opcode = %04x", sh4r.pc, ir ); dreamcast_stop(); return FALSE; }while(0)
nkeynes@1
   202
nkeynes@1
   203
#define RAISE( x, v ) do{ \
nkeynes@1
   204
    if( sh4r.vbr == 0 ) { \
nkeynes@1
   205
        ERROR( "%08X: VBR not initialized while raising exception %03X, halting", sh4r.pc, x ); \
nkeynes@104
   206
        dreamcast_stop(); return FALSE;	\
nkeynes@1
   207
    } else { \
nkeynes@1
   208
        sh4r.spc = sh4r.pc + 2; \
nkeynes@1
   209
        sh4r.ssr = sh4_read_sr(); \
nkeynes@1
   210
        sh4r.sgr = sh4r.r[15]; \
nkeynes@1
   211
        MMIO_WRITE(MMU,EXPEVT,x); \
nkeynes@1
   212
        sh4r.pc = sh4r.vbr + v; \
nkeynes@1
   213
        sh4r.new_pc = sh4r.pc + 2; \
nkeynes@1
   214
        sh4_load_sr( sh4r.ssr |SR_MD|SR_BL|SR_RB ); \
nkeynes@1
   215
    } \
nkeynes@27
   216
    return TRUE; } while(0)
nkeynes@1
   217
nkeynes@10
   218
#define MEM_READ_BYTE( addr ) sh4_read_byte(addr)
nkeynes@10
   219
#define MEM_READ_WORD( addr ) sh4_read_word(addr)
nkeynes@10
   220
#define MEM_READ_LONG( addr ) sh4_read_long(addr)
nkeynes@10
   221
#define MEM_WRITE_BYTE( addr, val ) sh4_write_byte(addr, val)
nkeynes@10
   222
#define MEM_WRITE_WORD( addr, val ) sh4_write_word(addr, val)
nkeynes@10
   223
#define MEM_WRITE_LONG( addr, val ) sh4_write_long(addr, val)
nkeynes@1
   224
nkeynes@1
   225
#define FP_WIDTH (IS_FPU_DOUBLESIZE() ? 8 : 4)
nkeynes@1
   226
nkeynes@124
   227
#define MEM_FP_READ( addr, reg ) sh4_read_float( addr, reg );
nkeynes@84
   228
nkeynes@124
   229
#define MEM_FP_WRITE( addr, reg ) sh4_write_float( addr, reg );
nkeynes@84
   230
nkeynes@1
   231
#define CHECK( x, c, v ) if( !x ) RAISE( c, v )
nkeynes@1
   232
#define CHECKPRIV() CHECK( IS_SH4_PRIVMODE(), EXC_ILLEGAL, EXV_ILLEGAL )
nkeynes@1
   233
#define CHECKFPUEN() CHECK( IS_FPU_ENABLED(), EXC_FPDISABLE, EXV_FPDISABLE )
nkeynes@84
   234
#define CHECKDEST(p) if( (p) == 0 ) { ERROR( "%08X: Branch/jump to NULL, CPU halted", sh4r.pc ); dreamcast_stop(); return FALSE; }
nkeynes@2
   235
#define CHECKSLOTILLEGAL() if(sh4r.in_delay_slot) { RAISE(EXC_SLOT_ILLEGAL,EXV_ILLEGAL); }
nkeynes@1
   236
nkeynes@1
   237
static void sh4_switch_banks( )
nkeynes@1
   238
{
nkeynes@1
   239
    uint32_t tmp[8];
nkeynes@1
   240
nkeynes@1
   241
    memcpy( tmp, sh4r.r, sizeof(uint32_t)*8 );
nkeynes@1
   242
    memcpy( sh4r.r, sh4r.r_bank, sizeof(uint32_t)*8 );
nkeynes@1
   243
    memcpy( sh4r.r_bank, tmp, sizeof(uint32_t)*8 );
nkeynes@1
   244
}
nkeynes@1
   245
nkeynes@1
   246
static void sh4_load_sr( uint32_t newval )
nkeynes@1
   247
{
nkeynes@1
   248
    if( (newval ^ sh4r.sr) & SR_RB )
nkeynes@1
   249
        sh4_switch_banks();
nkeynes@1
   250
    sh4r.sr = newval;
nkeynes@1
   251
    sh4r.t = (newval&SR_T) ? 1 : 0;
nkeynes@1
   252
    sh4r.s = (newval&SR_S) ? 1 : 0;
nkeynes@1
   253
    sh4r.m = (newval&SR_M) ? 1 : 0;
nkeynes@1
   254
    sh4r.q = (newval&SR_Q) ? 1 : 0;
nkeynes@1
   255
    intc_mask_changed();
nkeynes@1
   256
}
nkeynes@1
   257
nkeynes@124
   258
static void sh4_write_float( uint32_t addr, int reg )
nkeynes@124
   259
{
nkeynes@124
   260
    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@124
   261
	if( reg & 1 ) {
nkeynes@124
   262
	    sh4_write_long( addr, *((uint32_t *)&XF((reg)&0x0E)) );
nkeynes@124
   263
	    sh4_write_long( addr+4, *((uint32_t *)&XF(reg)) );
nkeynes@124
   264
	} else {
nkeynes@124
   265
	    sh4_write_long( addr, *((uint32_t *)&FR(reg)) ); 
nkeynes@124
   266
	    sh4_write_long( addr+4, *((uint32_t *)&FR((reg)|0x01)) );
nkeynes@124
   267
	}
nkeynes@124
   268
    } else {
nkeynes@124
   269
	sh4_write_long( addr, *((uint32_t *)&FR((reg))) );
nkeynes@124
   270
    }
nkeynes@124
   271
}
nkeynes@124
   272
nkeynes@124
   273
static void sh4_read_float( uint32_t addr, int reg )
nkeynes@124
   274
{
nkeynes@124
   275
    if( IS_FPU_DOUBLESIZE() ) {
nkeynes@124
   276
	if( reg & 1 ) {
nkeynes@124
   277
	    *((uint32_t *)&XF((reg) & 0x0E)) = sh4_read_long(addr);
nkeynes@124
   278
	    *((uint32_t *)&XF(reg)) = sh4_read_long(addr+4);
nkeynes@124
   279
	} else {
nkeynes@124
   280
	    *((uint32_t *)&FR(reg)) = sh4_read_long(addr);
nkeynes@124
   281
	    *((uint32_t *)&FR((reg) | 0x01)) = sh4_read_long(addr+4);
nkeynes@124
   282
	}
nkeynes@124
   283
    } else {
nkeynes@124
   284
	*((uint32_t *)&FR(reg)) = sh4_read_long(addr);
nkeynes@124
   285
    }
nkeynes@124
   286
}
nkeynes@124
   287
nkeynes@1
   288
static uint32_t sh4_read_sr( void )
nkeynes@1
   289
{
nkeynes@1
   290
    /* synchronize sh4r.sr with the various bitflags */
nkeynes@1
   291
    sh4r.sr &= SR_MQSTMASK;
nkeynes@1
   292
    if( sh4r.t ) sh4r.sr |= SR_T;
nkeynes@1
   293
    if( sh4r.s ) sh4r.sr |= SR_S;
nkeynes@1
   294
    if( sh4r.m ) sh4r.sr |= SR_M;
nkeynes@1
   295
    if( sh4r.q ) sh4r.sr |= SR_Q;
nkeynes@1
   296
    return sh4r.sr;
nkeynes@1
   297
}
nkeynes@1
   298
/* function for external use */
nkeynes@1
   299
void sh4_raise_exception( int code, int vector )
nkeynes@1
   300
{
nkeynes@1
   301
    RAISE(code, vector);
nkeynes@1
   302
}
nkeynes@1
   303
nkeynes@1
   304
static void sh4_accept_interrupt( void )
nkeynes@1
   305
{
nkeynes@1
   306
    uint32_t code = intc_accept_interrupt();
nkeynes@1
   307
    sh4r.ssr = sh4_read_sr();
nkeynes@1
   308
    sh4r.spc = sh4r.pc;
nkeynes@1
   309
    sh4r.sgr = sh4r.r[15];
nkeynes@1
   310
    sh4_load_sr( sh4r.ssr|SR_BL|SR_MD|SR_RB );
nkeynes@1
   311
    MMIO_WRITE( MMU, INTEVT, code );
nkeynes@1
   312
    sh4r.pc = sh4r.vbr + 0x600;
nkeynes@1
   313
    sh4r.new_pc = sh4r.pc + 2;
nkeynes@92
   314
    //    WARN( "Accepting interrupt %03X, from %08X => %08X", code, sh4r.spc, sh4r.pc );
nkeynes@1
   315
}
nkeynes@1
   316
nkeynes@27
   317
gboolean sh4_execute_instruction( void )
nkeynes@1
   318
{
nkeynes@84
   319
    uint32_t pc;
nkeynes@2
   320
    unsigned short ir;
nkeynes@1
   321
    uint32_t tmp;
nkeynes@1
   322
    uint64_t tmpl;
nkeynes@123
   323
    float ftmp;
nkeynes@123
   324
    double dtmp;
nkeynes@1
   325
    
nkeynes@1
   326
#define R0 sh4r.r[0]
nkeynes@84
   327
#define FR0 FR(0)
nkeynes@84
   328
#define DR0 DR(0)
nkeynes@1
   329
#define RN(ir) sh4r.r[(ir&0x0F00)>>8]
nkeynes@1
   330
#define RN_BANK(ir) sh4r.r_bank[(ir&0x0070)>>4]
nkeynes@1
   331
#define RM(ir) sh4r.r[(ir&0x00F0)>>4]
nkeynes@1
   332
#define DISP4(ir) (ir&0x000F) /* 4-bit displacements are *NOT* sign-extended */
nkeynes@1
   333
#define DISP8(ir) (ir&0x00FF)
nkeynes@1
   334
#define PCDISP8(ir) SIGNEXT8(ir&0x00FF)
nkeynes@1
   335
#define IMM8(ir) SIGNEXT8(ir&0x00FF)
nkeynes@1
   336
#define UIMM8(ir) (ir&0x00FF) /* Unsigned immmediate */
nkeynes@1
   337
#define DISP12(ir) SIGNEXT12(ir&0x0FFF)
nkeynes@84
   338
#define FRNn(ir) ((ir&0x0F00)>>8)
nkeynes@84
   339
#define FRMn(ir) ((ir&0x00F0)>>4)
nkeynes@84
   340
#define DRNn(ir) ((ir&0x0E00)>>9)
nkeynes@84
   341
#define DRMn(ir) ((ir&0x00E0)>>5)
nkeynes@2
   342
#define FVN(ir) ((ir&0x0C00)>>8)
nkeynes@2
   343
#define FVM(ir) ((ir&0x0300)>>6)
nkeynes@84
   344
#define FRN(ir) FR(FRNn(ir))
nkeynes@84
   345
#define FRM(ir) FR(FRMn(ir))
nkeynes@84
   346
#define FRNi(ir) (*((uint32_t *)&FR(FRNn(ir))))
nkeynes@84
   347
#define FRMi(ir) (*((uint32_t *)&FR(FRMn(ir))))
nkeynes@95
   348
#define DRN(ir) DRb(DRNn(ir), ir&0x0100)
nkeynes@95
   349
#define DRM(ir) DRb(DRMn(ir),ir&0x0010)
nkeynes@84
   350
#define DRNi(ir) (*((uint64_t *)&DR(FRNn(ir))))
nkeynes@84
   351
#define DRMi(ir) (*((uint64_t *)&DR(FRMn(ir))))
nkeynes@1
   352
#define FPULf   *((float *)&sh4r.fpul)
nkeynes@1
   353
#define FPULi    (sh4r.fpul)
nkeynes@1
   354
nkeynes@2
   355
    if( SH4_INT_PENDING() ) 
nkeynes@2
   356
        sh4_accept_interrupt();
nkeynes@1
   357
                 
nkeynes@2
   358
    pc = sh4r.pc;
nkeynes@84
   359
    if( pc > 0xFFFFFF00 ) {
nkeynes@84
   360
	/* SYSCALL Magic */
nkeynes@102
   361
	syscall_invoke( pc );
nkeynes@104
   362
	sh4r.in_delay_slot = 0;
nkeynes@84
   363
	pc = sh4r.pc = sh4r.pr;
nkeynes@84
   364
	sh4r.new_pc = sh4r.pc + 2;
nkeynes@84
   365
    }
nkeynes@2
   366
    ir = MEM_READ_WORD(pc);
nkeynes@1
   367
    sh4r.icount++;
nkeynes@1
   368
    
nkeynes@1
   369
    switch( (ir&0xF000)>>12 ) {
nkeynes@1
   370
        case 0: /* 0000nnnnmmmmxxxx */
nkeynes@1
   371
            switch( ir&0x000F ) {
nkeynes@1
   372
                case 2:
nkeynes@1
   373
                    switch( (ir&0x00F0)>>4 ) {
nkeynes@1
   374
                        case 0: /* STC     SR, Rn */
nkeynes@1
   375
                            CHECKPRIV();
nkeynes@1
   376
                            RN(ir) = sh4_read_sr();
nkeynes@1
   377
                            break;
nkeynes@1
   378
                        case 1: /* STC     GBR, Rn */
nkeynes@1
   379
                            RN(ir) = sh4r.gbr;
nkeynes@1
   380
                            break;
nkeynes@1
   381
                        case 2: /* STC     VBR, Rn */
nkeynes@1
   382
                            CHECKPRIV();
nkeynes@1
   383
                            RN(ir) = sh4r.vbr;
nkeynes@1
   384
                            break;
nkeynes@1
   385
                        case 3: /* STC     SSR, Rn */
nkeynes@1
   386
                            CHECKPRIV();
nkeynes@1
   387
                            RN(ir) = sh4r.ssr;
nkeynes@1
   388
                            break;
nkeynes@1
   389
                        case 4: /* STC     SPC, Rn */
nkeynes@1
   390
                            CHECKPRIV();
nkeynes@1
   391
                            RN(ir) = sh4r.spc;
nkeynes@1
   392
                            break;
nkeynes@1
   393
                        case 8: case 9: case 10: case 11: case 12: case 13:
nkeynes@1
   394
                        case 14: case 15:/* STC     Rm_bank, Rn */
nkeynes@1
   395
                            CHECKPRIV();
nkeynes@1
   396
                            RN(ir) = RN_BANK(ir);
nkeynes@1
   397
                            break;
nkeynes@1
   398
                        default: UNDEF(ir);
nkeynes@1
   399
                    }
nkeynes@1
   400
                    break;
nkeynes@1
   401
                case 3:
nkeynes@1
   402
                    switch( (ir&0x00F0)>>4 ) {
nkeynes@1
   403
                        case 0: /* BSRF    Rn */
nkeynes@1
   404
                            CHECKDEST( pc + 4 + RN(ir) );
nkeynes@2
   405
                            CHECKSLOTILLEGAL();
nkeynes@2
   406
                            sh4r.in_delay_slot = 1;
nkeynes@1
   407
                            sh4r.pr = sh4r.pc + 4;
nkeynes@1
   408
                            sh4r.pc = sh4r.new_pc;
nkeynes@1
   409
                            sh4r.new_pc = pc + 4 + RN(ir);
nkeynes@27
   410
                            return TRUE;
nkeynes@1
   411
                        case 2: /* BRAF    Rn */
nkeynes@1
   412
                            CHECKDEST( pc + 4 + RN(ir) );
nkeynes@2
   413
                            CHECKSLOTILLEGAL();
nkeynes@2
   414
                            sh4r.in_delay_slot = 1;
nkeynes@1
   415
                            sh4r.pc = sh4r.new_pc;
nkeynes@1
   416
                            sh4r.new_pc = pc + 4 + RN(ir);
nkeynes@27
   417
                            return TRUE;
nkeynes@1
   418
                        case 8: /* PREF    [Rn] */
nkeynes@2
   419
                            tmp = RN(ir);
nkeynes@2
   420
                            if( (tmp & 0xFC000000) == 0xE0000000 ) {
nkeynes@2
   421
                                /* Store queue operation */
nkeynes@2
   422
                                int queue = (tmp&0x20)>>2;
nkeynes@2
   423
                                int32_t *src = &sh4r.store_queue[queue];
nkeynes@2
   424
                                uint32_t hi = (MMIO_READ( MMU, (queue == 0 ? QACR0 : QACR1) ) & 0x1C) << 24;
nkeynes@2
   425
                                uint32_t target = tmp&0x03FFFFE0 | hi;
nkeynes@2
   426
                                mem_copy_to_sh4( target, src, 32 );
nkeynes@92
   427
				//if( (target &0xFF000000) != 0x04000000 ) 
nkeynes@92
   428
				//    WARN( "Executed SQ%c => %08X",
nkeynes@92
   429
				//	  (queue == 0 ? '0' : '1'), target );
nkeynes@2
   430
                            }
nkeynes@2
   431
                            break;
nkeynes@1
   432
                        case 9: /* OCBI    [Rn] */
nkeynes@1
   433
                        case 10:/* OCBP    [Rn] */
nkeynes@1
   434
                        case 11:/* OCBWB   [Rn] */
nkeynes@1
   435
                            /* anything? */
nkeynes@1
   436
                            break;
nkeynes@1
   437
                        case 12:/* MOVCA.L R0, [Rn] */
nkeynes@1
   438
                            UNIMP(ir);
nkeynes@1
   439
                        default: UNDEF(ir);
nkeynes@1
   440
                    }
nkeynes@1
   441
                    break;
nkeynes@1
   442
                case 4: /* MOV.B   Rm, [R0 + Rn] */
nkeynes@1
   443
                    MEM_WRITE_BYTE( R0 + RN(ir), RM(ir) );
nkeynes@1
   444
                    break;
nkeynes@1
   445
                case 5: /* MOV.W   Rm, [R0 + Rn] */
nkeynes@1
   446
                    MEM_WRITE_WORD( R0 + RN(ir), RM(ir) );
nkeynes@1
   447
                    break;
nkeynes@1
   448
                case 6: /* MOV.L   Rm, [R0 + Rn] */
nkeynes@1
   449
                    MEM_WRITE_LONG( R0 + RN(ir), RM(ir) );
nkeynes@1
   450
                    break;
nkeynes@1
   451
                case 7: /* MUL.L   Rm, Rn */
nkeynes@2
   452
                    sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@1
   453
                        (RM(ir) * RN(ir));
nkeynes@1
   454
                    break;
nkeynes@1
   455
                case 8: 
nkeynes@1
   456
                    switch( (ir&0x0FF0)>>4 ) {
nkeynes@1
   457
                        case 0: /* CLRT    */
nkeynes@1
   458
                            sh4r.t = 0;
nkeynes@1
   459
                            break;
nkeynes@1
   460
                        case 1: /* SETT    */
nkeynes@1
   461
                            sh4r.t = 1;
nkeynes@1
   462
                            break;
nkeynes@1
   463
                        case 2: /* CLRMAC  */
nkeynes@1
   464
                            sh4r.mac = 0;
nkeynes@1
   465
                            break;
nkeynes@1
   466
                        case 3: /* LDTLB   */
nkeynes@1
   467
                            break;
nkeynes@1
   468
                        case 4: /* CLRS    */
nkeynes@1
   469
                            sh4r.s = 0;
nkeynes@1
   470
                            break;
nkeynes@1
   471
                        case 5: /* SETS    */
nkeynes@1
   472
                            sh4r.s = 1;
nkeynes@1
   473
                            break;
nkeynes@1
   474
                        default: UNDEF(ir);
nkeynes@1
   475
                    }
nkeynes@1
   476
                    break;
nkeynes@1
   477
                case 9: 
nkeynes@1
   478
                    if( (ir&0x00F0) == 0x20 ) /* MOVT    Rn */
nkeynes@1
   479
                        RN(ir) = sh4r.t;
nkeynes@1
   480
                    else if( ir == 0x0019 ) /* DIV0U   */
nkeynes@1
   481
                        sh4r.m = sh4r.q = sh4r.t = 0;
nkeynes@1
   482
                    else if( ir == 0x0009 )
nkeynes@1
   483
                        /* NOP     */;
nkeynes@1
   484
                    else UNDEF(ir);
nkeynes@1
   485
                    break;
nkeynes@1
   486
                case 10:
nkeynes@1
   487
                    switch( (ir&0x00F0) >> 4 ) {
nkeynes@1
   488
                        case 0: /* STS     MACH, Rn */
nkeynes@1
   489
                            RN(ir) = sh4r.mac >> 32;
nkeynes@1
   490
                            break;
nkeynes@1
   491
                        case 1: /* STS     MACL, Rn */
nkeynes@1
   492
                            RN(ir) = (uint32_t)sh4r.mac;
nkeynes@1
   493
                            break;
nkeynes@1
   494
                        case 2: /* STS     PR, Rn */
nkeynes@1
   495
                            RN(ir) = sh4r.pr;
nkeynes@1
   496
                            break;
nkeynes@1
   497
                        case 3: /* STC     SGR, Rn */
nkeynes@1
   498
                            CHECKPRIV();
nkeynes@1
   499
                            RN(ir) = sh4r.sgr;
nkeynes@1
   500
                            break;
nkeynes@1
   501
                        case 5:/* STS      FPUL, Rn */
nkeynes@1
   502
                            RN(ir) = sh4r.fpul;
nkeynes@1
   503
                            break;
nkeynes@1
   504
                        case 6: /* STS     FPSCR, Rn */
nkeynes@1
   505
                            RN(ir) = sh4r.fpscr;
nkeynes@1
   506
                            break;
nkeynes@1
   507
                        case 15:/* STC     DBR, Rn */
nkeynes@1
   508
                            CHECKPRIV();
nkeynes@1
   509
                            RN(ir) = sh4r.dbr;
nkeynes@1
   510
                            break;
nkeynes@1
   511
                        default: UNDEF(ir);
nkeynes@1
   512
                    }
nkeynes@1
   513
                    break;
nkeynes@1
   514
                case 11:
nkeynes@1
   515
                    switch( (ir&0x0FF0)>>4 ) {
nkeynes@1
   516
                        case 0: /* RTS     */
nkeynes@1
   517
                            CHECKDEST( sh4r.pr );
nkeynes@2
   518
                            CHECKSLOTILLEGAL();
nkeynes@2
   519
                            sh4r.in_delay_slot = 1;
nkeynes@1
   520
                            sh4r.pc = sh4r.new_pc;
nkeynes@1
   521
                            sh4r.new_pc = sh4r.pr;
nkeynes@27
   522
                            return TRUE;
nkeynes@1
   523
                        case 1: /* SLEEP   */
nkeynes@27
   524
			    if( MMIO_READ( CPG, STBCR ) & 0x80 ) {
nkeynes@27
   525
				sh4r.sh4_state = SH4_STATE_STANDBY;
nkeynes@27
   526
			    } else {
nkeynes@27
   527
				sh4r.sh4_state = SH4_STATE_SLEEP;
nkeynes@27
   528
			    }
nkeynes@27
   529
			    return FALSE; /* Halt CPU */
nkeynes@1
   530
                        case 2: /* RTE     */
nkeynes@1
   531
                            CHECKPRIV();
nkeynes@1
   532
                            CHECKDEST( sh4r.spc );
nkeynes@2
   533
                            CHECKSLOTILLEGAL();
nkeynes@2
   534
                            sh4r.in_delay_slot = 1;
nkeynes@1
   535
                            sh4r.pc = sh4r.new_pc;
nkeynes@1
   536
                            sh4r.new_pc = sh4r.spc;
nkeynes@1
   537
                            sh4_load_sr( sh4r.ssr );
nkeynes@27
   538
                            return TRUE;
nkeynes@1
   539
                        default:UNDEF(ir);
nkeynes@1
   540
                    }
nkeynes@1
   541
                    break;
nkeynes@1
   542
                case 12:/* MOV.B   [R0+R%d], R%d */
nkeynes@1
   543
                    RN(ir) = MEM_READ_BYTE( R0 + RM(ir) );
nkeynes@1
   544
                    break;
nkeynes@1
   545
                case 13:/* MOV.W   [R0+R%d], R%d */
nkeynes@1
   546
                    RN(ir) = MEM_READ_WORD( R0 + RM(ir) );
nkeynes@1
   547
                    break;
nkeynes@1
   548
                case 14:/* MOV.L   [R0+R%d], R%d */
nkeynes@1
   549
                    RN(ir) = MEM_READ_LONG( R0 + RM(ir) );
nkeynes@1
   550
                    break;
nkeynes@1
   551
                case 15:/* MAC.L   [Rm++], [Rn++] */
nkeynes@1
   552
                    tmpl = ( SIGNEXT32(MEM_READ_LONG(RM(ir))) *
nkeynes@1
   553
                                  SIGNEXT32(MEM_READ_LONG(RN(ir))) );
nkeynes@1
   554
                    if( sh4r.s ) {
nkeynes@1
   555
                        /* 48-bit Saturation. Yuch */
nkeynes@1
   556
                        tmpl += SIGNEXT48(sh4r.mac);
nkeynes@2
   557
                        if( tmpl < 0xFFFF800000000000LL )
nkeynes@2
   558
                            tmpl = 0xFFFF800000000000LL;
nkeynes@2
   559
                        else if( tmpl > 0x00007FFFFFFFFFFFLL )
nkeynes@2
   560
                            tmpl = 0x00007FFFFFFFFFFFLL;
nkeynes@2
   561
                        sh4r.mac = (sh4r.mac&0xFFFF000000000000LL) |
nkeynes@2
   562
                            (tmpl&0x0000FFFFFFFFFFFFLL);
nkeynes@1
   563
                    } else sh4r.mac = tmpl;
nkeynes@1
   564
                    
nkeynes@1
   565
                    RM(ir) += 4;
nkeynes@1
   566
                    RN(ir) += 4;
nkeynes@1
   567
                    
nkeynes@1
   568
                    break;
nkeynes@1
   569
                default: UNDEF(ir);
nkeynes@1
   570
            }
nkeynes@1
   571
            break;
nkeynes@1
   572
        case 1: /* 0001nnnnmmmmdddd */
nkeynes@1
   573
            /* MOV.L   Rm, [Rn + disp4*4] */
nkeynes@1
   574
            MEM_WRITE_LONG( RN(ir) + (DISP4(ir)<<2), RM(ir) );
nkeynes@1
   575
            break;
nkeynes@1
   576
        case 2: /* 0010nnnnmmmmxxxx */
nkeynes@1
   577
            switch( ir&0x000F ) {
nkeynes@1
   578
                case 0: /* MOV.B   Rm, [Rn] */
nkeynes@1
   579
                    MEM_WRITE_BYTE( RN(ir), RM(ir) );
nkeynes@1
   580
                    break;
nkeynes@1
   581
                case 1: /* MOV.W   Rm, [Rn] */
nkeynes@1
   582
                    MEM_WRITE_WORD( RN(ir), RM(ir) );
nkeynes@1
   583
                    break;
nkeynes@1
   584
                case 2: /* MOV.L   Rm, [Rn] */
nkeynes@1
   585
                    MEM_WRITE_LONG( RN(ir), RM(ir) );
nkeynes@1
   586
                    break;
nkeynes@1
   587
                case 3: UNDEF(ir);
nkeynes@1
   588
                    break;
nkeynes@1
   589
                case 4: /* MOV.B   Rm, [--Rn] */
nkeynes@1
   590
                    RN(ir) --;
nkeynes@1
   591
                    MEM_WRITE_BYTE( RN(ir), RM(ir) );
nkeynes@1
   592
                    break;
nkeynes@1
   593
                case 5: /* MOV.W   Rm, [--Rn] */
nkeynes@1
   594
                    RN(ir) -= 2;
nkeynes@1
   595
                    MEM_WRITE_WORD( RN(ir), RM(ir) );
nkeynes@1
   596
                    break;
nkeynes@1
   597
                case 6: /* MOV.L   Rm, [--Rn] */
nkeynes@1
   598
                    RN(ir) -= 4;
nkeynes@1
   599
                    MEM_WRITE_LONG( RN(ir), RM(ir) );
nkeynes@1
   600
                    break;
nkeynes@1
   601
                case 7: /* DIV0S   Rm, Rn */
nkeynes@1
   602
                    sh4r.q = RN(ir)>>31;
nkeynes@1
   603
                    sh4r.m = RM(ir)>>31;
nkeynes@1
   604
                    sh4r.t = sh4r.q ^ sh4r.m;
nkeynes@1
   605
                    break;
nkeynes@1
   606
                case 8: /* TST     Rm, Rn */
nkeynes@1
   607
                    sh4r.t = (RN(ir)&RM(ir) ? 0 : 1);
nkeynes@1
   608
                    break;
nkeynes@1
   609
                case 9: /* AND     Rm, Rn */
nkeynes@1
   610
                    RN(ir) &= RM(ir);
nkeynes@1
   611
                    break;
nkeynes@1
   612
                case 10:/* XOR     Rm, Rn */
nkeynes@1
   613
                    RN(ir) ^= RM(ir);
nkeynes@1
   614
                    break;
nkeynes@1
   615
                case 11:/* OR      Rm, Rn */
nkeynes@1
   616
                    RN(ir) |= RM(ir);
nkeynes@1
   617
                    break;
nkeynes@1
   618
                case 12:/* CMP/STR Rm, Rn */
nkeynes@1
   619
                    /* set T = 1 if any byte in RM & RN is the same */
nkeynes@1
   620
                    tmp = RM(ir) ^ RN(ir);
nkeynes@1
   621
                    sh4r.t = ((tmp&0x000000FF)==0 || (tmp&0x0000FF00)==0 ||
nkeynes@1
   622
                              (tmp&0x00FF0000)==0 || (tmp&0xFF000000)==0)?1:0;
nkeynes@1
   623
                    break;
nkeynes@1
   624
                case 13:/* XTRCT   Rm, Rn */
nkeynes@1
   625
                    RN(ir) = (RN(ir)>>16) | (RM(ir)<<16);
nkeynes@1
   626
                    break;
nkeynes@1
   627
                case 14:/* MULU.W  Rm, Rn */
nkeynes@2
   628
                    sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@1
   629
                        (uint32_t)((RM(ir)&0xFFFF) * (RN(ir)&0xFFFF));
nkeynes@1
   630
                    break;
nkeynes@1
   631
                case 15:/* MULS.W  Rm, Rn */
nkeynes@2
   632
                    sh4r.mac = (sh4r.mac&0xFFFFFFFF00000000LL) |
nkeynes@1
   633
                        (uint32_t)(SIGNEXT32(RM(ir)&0xFFFF) * SIGNEXT32(RN(ir)&0xFFFF));
nkeynes@1
   634
                    break;
nkeynes@1
   635
            }
nkeynes@1
   636
            break;
nkeynes@1
   637
        case 3: /* 0011nnnnmmmmxxxx */
nkeynes@1
   638
            switch( ir&0x000F ) {
nkeynes@1
   639
                case 0: /* CMP/EQ  Rm, Rn */
nkeynes@1
   640
                    sh4r.t = ( RM(ir) == RN(ir) ? 1 : 0 );
nkeynes@1
   641
                    break;
nkeynes@1
   642
                case 2: /* CMP/HS  Rm, Rn */
nkeynes@1
   643
                    sh4r.t = ( RN(ir) >= RM(ir) ? 1 : 0 );
nkeynes@1
   644
                    break;
nkeynes@1
   645
                case 3: /* CMP/GE  Rm, Rn */
nkeynes@1
   646
                    sh4r.t = ( ((int32_t)RN(ir)) >= ((int32_t)RM(ir)) ? 1 : 0 );
nkeynes@1
   647
                    break;
nkeynes@1
   648
                case 4: { /* DIV1    Rm, Rn */
nkeynes@1
   649
                    /* This is just from the sh4p manual with some
nkeynes@1
   650
                     * simplifications (someone want to check it's correct? :)
nkeynes@1
   651
                     * Why they couldn't just provide a real DIV instruction...
nkeynes@1
   652
                     * Please oh please let the translator batch these things
nkeynes@1
   653
                     * up into a single DIV... */
nkeynes@1
   654
                    uint32_t tmp0, tmp1, tmp2, dir;
nkeynes@1
   655
nkeynes@1
   656
                    dir = sh4r.q ^ sh4r.m;
nkeynes@1
   657
                    sh4r.q = (RN(ir) >> 31);
nkeynes@1
   658
                    tmp2 = RM(ir);
nkeynes@1
   659
                    RN(ir) = (RN(ir) << 1) | sh4r.t;
nkeynes@1
   660
                    tmp0 = RN(ir);
nkeynes@1
   661
                    if( dir ) {
nkeynes@1
   662
                        RN(ir) += tmp2;
nkeynes@1
   663
                        tmp1 = (RN(ir)<tmp0 ? 1 : 0 );
nkeynes@1
   664
                    } else {
nkeynes@1
   665
                        RN(ir) -= tmp2;
nkeynes@1
   666
                        tmp1 = (RN(ir)>tmp0 ? 1 : 0 );
nkeynes@1
   667
                    }
nkeynes@1
   668
                    sh4r.q ^= sh4r.m ^ tmp1;
nkeynes@1
   669
                    sh4r.t = ( sh4r.q == sh4r.m ? 1 : 0 );
nkeynes@1
   670
                    break; }
nkeynes@1
   671
                case 5: /* DMULU.L Rm, Rn */
nkeynes@1
   672
                    sh4r.mac = ((uint64_t)RM(ir)) * ((uint64_t)RN(ir));
nkeynes@1
   673
                    break;
nkeynes@1
   674
                case 6: /* CMP/HI  Rm, Rn */
nkeynes@1
   675
                    sh4r.t = ( RN(ir) > RM(ir) ? 1 : 0 );
nkeynes@1
   676
                    break;
nkeynes@1
   677
                case 7: /* CMP/GT  Rm, Rn */
nkeynes@1
   678
                    sh4r.t = ( ((int32_t)RN(ir)) > ((int32_t)RM(ir)) ? 1 : 0 );
nkeynes@1
   679
                    break;
nkeynes@1
   680
                case 8: /* SUB     Rm, Rn */
nkeynes@1
   681
                    RN(ir) -= RM(ir);
nkeynes@1
   682
                    break;
nkeynes@1
   683
                case 10:/* SUBC    Rm, Rn */
nkeynes@1
   684
                    tmp = RN(ir);
nkeynes@1
   685
                    RN(ir) = RN(ir) - RM(ir) - sh4r.t;
nkeynes@1
   686
                    sh4r.t = (RN(ir) > tmp || (RN(ir) == tmp && sh4r.t == 1));
nkeynes@1
   687
                    break;
nkeynes@1
   688
                case 11:/* SUBV    Rm, Rn */
nkeynes@1
   689
                    UNIMP(ir);
nkeynes@1
   690
                    break;
nkeynes@1
   691
                case 12:/* ADD     Rm, Rn */
nkeynes@1
   692
                    RN(ir) += RM(ir);
nkeynes@1
   693
                    break;
nkeynes@1
   694
                case 13:/* DMULS.L Rm, Rn */
nkeynes@1
   695
                    sh4r.mac = SIGNEXT32(RM(ir)) * SIGNEXT32(RN(ir));
nkeynes@1
   696
                    break;
nkeynes@1
   697
                case 14:/* ADDC    Rm, Rn */
nkeynes@1
   698
                    tmp = RN(ir);
nkeynes@1
   699
                    RN(ir) += RM(ir) + sh4r.t;
nkeynes@1
   700
                    sh4r.t = ( RN(ir) < tmp || (RN(ir) == tmp && sh4r.t != 0) ? 1 : 0 );
nkeynes@1
   701
                    break;
nkeynes@1
   702
                case 15:/* ADDV    Rm, Rn */
nkeynes@1
   703
                    UNIMP(ir);
nkeynes@1
   704
                    break;
nkeynes@1
   705
                default: UNDEF(ir);
nkeynes@1
   706
            }
nkeynes@1
   707
            break;
nkeynes@1
   708
        case 4: /* 0100nnnnxxxxxxxx */
nkeynes@1
   709
            switch( ir&0x00FF ) {
nkeynes@1
   710
                case 0x00: /* SHLL    Rn */
nkeynes@1
   711
                    sh4r.t = RN(ir) >> 31;
nkeynes@1
   712
                    RN(ir) <<= 1;
nkeynes@1
   713
                    break;
nkeynes@1
   714
                case 0x01: /* SHLR    Rn */
nkeynes@1
   715
                    sh4r.t = RN(ir) & 0x00000001;
nkeynes@1
   716
                    RN(ir) >>= 1;
nkeynes@1
   717
                    break;
nkeynes@1
   718
                case 0x02: /* STS.L   MACH, [--Rn] */
nkeynes@1
   719
                    RN(ir) -= 4;
nkeynes@1
   720
                    MEM_WRITE_LONG( RN(ir), (sh4r.mac>>32) );
nkeynes@1
   721
                    break;
nkeynes@1
   722
                case 0x03: /* STC.L   SR, [--Rn] */
nkeynes@1
   723
                    CHECKPRIV();
nkeynes@1
   724
                    RN(ir) -= 4;
nkeynes@1
   725
                    MEM_WRITE_LONG( RN(ir), sh4_read_sr() );
nkeynes@1
   726
                    break;
nkeynes@1
   727
                case 0x04: /* ROTL    Rn */
nkeynes@1
   728
                    sh4r.t = RN(ir) >> 31;
nkeynes@1
   729
                    RN(ir) <<= 1;
nkeynes@1
   730
                    RN(ir) |= sh4r.t;
nkeynes@1
   731
                    break;
nkeynes@1
   732
                case 0x05: /* ROTR    Rn */
nkeynes@1
   733
                    sh4r.t = RN(ir) & 0x00000001;
nkeynes@1
   734
                    RN(ir) >>= 1;
nkeynes@1
   735
                    RN(ir) |= (sh4r.t << 31);
nkeynes@1
   736
                    break;
nkeynes@1
   737
                case 0x06: /* LDS.L   [Rn++], MACH */
nkeynes@1
   738
                    sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@1
   739
                        (((uint64_t)MEM_READ_LONG(RN(ir)))<<32);
nkeynes@1
   740
                    RN(ir) += 4;
nkeynes@1
   741
                    break;
nkeynes@1
   742
                case 0x07: /* LDC.L   [Rn++], SR */
nkeynes@1
   743
                    CHECKPRIV();
nkeynes@1
   744
                    sh4_load_sr( MEM_READ_LONG(RN(ir)) );
nkeynes@1
   745
                    RN(ir) +=4;
nkeynes@1
   746
                    break;
nkeynes@1
   747
                case 0x08: /* SHLL2   Rn */
nkeynes@1
   748
                    RN(ir) <<= 2;
nkeynes@1
   749
                    break;
nkeynes@1
   750
                case 0x09: /* SHLR2   Rn */
nkeynes@1
   751
                    RN(ir) >>= 2;
nkeynes@1
   752
                    break;
nkeynes@1
   753
                case 0x0A: /* LDS     Rn, MACH */
nkeynes@1
   754
                    sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
nkeynes@1
   755
                        (((uint64_t)RN(ir))<<32);
nkeynes@1
   756
                    break;
nkeynes@1
   757
                case 0x0B: /* JSR     [Rn] */
nkeynes@1
   758
                    CHECKDEST( RN(ir) );
nkeynes@2
   759
                    CHECKSLOTILLEGAL();
nkeynes@2
   760
                    sh4r.in_delay_slot = 1;
nkeynes@1
   761
                    sh4r.pc = sh4r.new_pc;
nkeynes@1
   762
                    sh4r.new_pc = RN(ir);
nkeynes@1
   763
                    sh4r.pr = pc + 4;
nkeynes@27
   764
                    return TRUE;
nkeynes@1
   765
                case 0x0E: /* LDC     Rn, SR */
nkeynes@1
   766
                    CHECKPRIV();
nkeynes@1
   767
                    sh4_load_sr( RN(ir) );
nkeynes@1
   768
                    break;
nkeynes@1
   769
                case 0x10: /* DT      Rn */
nkeynes@1
   770
                    RN(ir) --;
nkeynes@1
   771
                    sh4r.t = ( RN(ir) == 0 ? 1 : 0 );
nkeynes@1
   772
                    break;
nkeynes@1
   773
                case 0x11: /* CMP/PZ  Rn */
nkeynes@1
   774
                    sh4r.t = ( ((int32_t)RN(ir)) >= 0 ? 1 : 0 );
nkeynes@1
   775
                    break;
nkeynes@1
   776
                case 0x12: /* STS.L   MACL, [--Rn] */
nkeynes@1
   777
                    RN(ir) -= 4;
nkeynes@1
   778
                    MEM_WRITE_LONG( RN(ir), (uint32_t)sh4r.mac );
nkeynes@1
   779
                    break;
nkeynes@1
   780
                case 0x13: /* STC.L   GBR, [--Rn] */
nkeynes@1
   781
                    RN(ir) -= 4;
nkeynes@1
   782
                    MEM_WRITE_LONG( RN(ir), sh4r.gbr );
nkeynes@1
   783
                    break;
nkeynes@1
   784
                case 0x15: /* CMP/PL  Rn */
nkeynes@1
   785
                    sh4r.t = ( ((int32_t)RN(ir)) > 0 ? 1 : 0 );
nkeynes@1
   786
                    break;
nkeynes@1
   787
                case 0x16: /* LDS.L   [Rn++], MACL */
nkeynes@2
   788
                    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@1
   789
                        (uint64_t)((uint32_t)MEM_READ_LONG(RN(ir)));
nkeynes@1
   790
                    RN(ir) += 4;
nkeynes@1
   791
                    break;
nkeynes@1
   792
                case 0x17: /* LDC.L   [Rn++], GBR */
nkeynes@1
   793
                    sh4r.gbr = MEM_READ_LONG(RN(ir));
nkeynes@1
   794
                    RN(ir) +=4;
nkeynes@1
   795
                    break;
nkeynes@1
   796
                case 0x18: /* SHLL8   Rn */
nkeynes@1
   797
                    RN(ir) <<= 8;
nkeynes@1
   798
                    break;
nkeynes@1
   799
                case 0x19: /* SHLR8   Rn */
nkeynes@1
   800
                    RN(ir) >>= 8;
nkeynes@1
   801
                    break;
nkeynes@1
   802
                case 0x1A: /* LDS     Rn, MACL */
nkeynes@2
   803
                    sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
nkeynes@1
   804
                        (uint64_t)((uint32_t)(RN(ir)));
nkeynes@1
   805
                    break;
nkeynes@1
   806
                case 0x1B: /* TAS.B   [Rn] */
nkeynes@1
   807
                    tmp = MEM_READ_BYTE( RN(ir) );
nkeynes@1
   808
                    sh4r.t = ( tmp == 0 ? 1 : 0 );
nkeynes@1
   809
                    MEM_WRITE_BYTE( RN(ir), tmp | 0x80 );
nkeynes@1
   810
                    break;
nkeynes@1
   811
                case 0x1E: /* LDC     Rn, GBR */
nkeynes@1
   812
                    sh4r.gbr = RN(ir);
nkeynes@1
   813
                    break;
nkeynes@1
   814
                case 0x20: /* SHAL    Rn */
nkeynes@1
   815
                    sh4r.t = RN(ir) >> 31;
nkeynes@1
   816
                    RN(ir) <<= 1;
nkeynes@1
   817
                    break;
nkeynes@1
   818
                case 0x21: /* SHAR    Rn */
nkeynes@1
   819
                    sh4r.t = RN(ir) & 0x00000001;
nkeynes@1
   820
                    RN(ir) = ((int32_t)RN(ir)) >> 1;
nkeynes@1
   821
                    break;
nkeynes@1
   822
                case 0x22: /* STS.L   PR, [--Rn] */
nkeynes@1
   823
                    RN(ir) -= 4;
nkeynes@1
   824
                    MEM_WRITE_LONG( RN(ir), sh4r.pr );
nkeynes@1
   825
                    break;
nkeynes@1
   826
                case 0x23: /* STC.L   VBR, [--Rn] */
nkeynes@1
   827
                    CHECKPRIV();
nkeynes@1
   828
                    RN(ir) -= 4;
nkeynes@2
   829
                    MEM_WRITE_LONG( RN(ir), sh4r.vbr );
nkeynes@1
   830
                    break;
nkeynes@1
   831
                case 0x24: /* ROTCL   Rn */
nkeynes@1
   832
                    tmp = RN(ir) >> 31;
nkeynes@1
   833
                    RN(ir) <<= 1;
nkeynes@1
   834
                    RN(ir) |= sh4r.t;
nkeynes@1
   835
                    sh4r.t = tmp;
nkeynes@1
   836
                    break;
nkeynes@1
   837
                case 0x25: /* ROTCR   Rn */
nkeynes@1
   838
                    tmp = RN(ir) & 0x00000001;
nkeynes@1
   839
                    RN(ir) >>= 1;
nkeynes@1
   840
                    RN(ir) |= (sh4r.t << 31 );
nkeynes@1
   841
                    sh4r.t = tmp;
nkeynes@1
   842
                    break;
nkeynes@1
   843
                case 0x26: /* LDS.L   [Rn++], PR */
nkeynes@1
   844
                    sh4r.pr = MEM_READ_LONG( RN(ir) );
nkeynes@1
   845
                    RN(ir) += 4;
nkeynes@1
   846
                    break;
nkeynes@1
   847
                case 0x27: /* LDC.L   [Rn++], VBR */
nkeynes@1
   848
                    CHECKPRIV();
nkeynes@1
   849
                    sh4r.vbr = MEM_READ_LONG(RN(ir));
nkeynes@1
   850
                    RN(ir) +=4;
nkeynes@1
   851
                    break;
nkeynes@1
   852
                case 0x28: /* SHLL16  Rn */
nkeynes@1
   853
                    RN(ir) <<= 16;
nkeynes@1
   854
                    break;
nkeynes@1
   855
                case 0x29: /* SHLR16  Rn */
nkeynes@1
   856
                    RN(ir) >>= 16;
nkeynes@1
   857
                    break;
nkeynes@1
   858
                case 0x2A: /* LDS     Rn, PR */
nkeynes@1
   859
                    sh4r.pr = RN(ir);
nkeynes@1
   860
                    break;
nkeynes@1
   861
                case 0x2B: /* JMP     [Rn] */
nkeynes@1
   862
                    CHECKDEST( RN(ir) );
nkeynes@2
   863
                    CHECKSLOTILLEGAL();
nkeynes@2
   864
                    sh4r.in_delay_slot = 1;
nkeynes@1
   865
                    sh4r.pc = sh4r.new_pc;
nkeynes@1
   866
                    sh4r.new_pc = RN(ir);
nkeynes@27
   867
                    return TRUE;
nkeynes@1
   868
                case 0x2E: /* LDC     Rn, VBR */
nkeynes@1
   869
                    CHECKPRIV();
nkeynes@1
   870
                    sh4r.vbr = RN(ir);
nkeynes@1
   871
                    break;
nkeynes@1
   872
                case 0x32: /* STC.L   SGR, [--Rn] */
nkeynes@1
   873
                    CHECKPRIV();
nkeynes@1
   874
                    RN(ir) -= 4;
nkeynes@1
   875
                    MEM_WRITE_LONG( RN(ir), sh4r.sgr );
nkeynes@1
   876
                    break;
nkeynes@1
   877
                case 0x33: /* STC.L   SSR, [--Rn] */
nkeynes@1
   878
                    CHECKPRIV();
nkeynes@1
   879
                    RN(ir) -= 4;
nkeynes@1
   880
                    MEM_WRITE_LONG( RN(ir), sh4r.ssr );
nkeynes@1
   881
                    break;
nkeynes@1
   882
                case 0x37: /* LDC.L   [Rn++], SSR */
nkeynes@1
   883
                    CHECKPRIV();
nkeynes@1
   884
                    sh4r.ssr = MEM_READ_LONG(RN(ir));
nkeynes@1
   885
                    RN(ir) +=4;
nkeynes@1
   886
                    break;
nkeynes@1
   887
                case 0x3E: /* LDC     Rn, SSR */
nkeynes@1
   888
                    CHECKPRIV();
nkeynes@1
   889
                    sh4r.ssr = RN(ir);
nkeynes@1
   890
                    break;
nkeynes@1
   891
                case 0x43: /* STC.L   SPC, [--Rn] */
nkeynes@1
   892
                    CHECKPRIV();
nkeynes@1
   893
                    RN(ir) -= 4;
nkeynes@1
   894
                    MEM_WRITE_LONG( RN(ir), sh4r.spc );
nkeynes@1
   895
                    break;
nkeynes@1
   896
                case 0x47: /* LDC.L   [Rn++], SPC */
nkeynes@1
   897
                    CHECKPRIV();
nkeynes@1
   898
                    sh4r.spc = MEM_READ_LONG(RN(ir));
nkeynes@1
   899
                    RN(ir) +=4;
nkeynes@1
   900
                    break;
nkeynes@1
   901
                case 0x4E: /* LDC     Rn, SPC */
nkeynes@1
   902
                    CHECKPRIV();
nkeynes@1
   903
                    sh4r.spc = RN(ir);
nkeynes@1
   904
                    break;
nkeynes@1
   905
                case 0x52: /* STS.L   FPUL, [--Rn] */
nkeynes@1
   906
                    RN(ir) -= 4;
nkeynes@1
   907
                    MEM_WRITE_LONG( RN(ir), sh4r.fpul );
nkeynes@1
   908
                    break;
nkeynes@1
   909
                case 0x56: /* LDS.L   [Rn++], FPUL */
nkeynes@1
   910
                    sh4r.fpul = MEM_READ_LONG(RN(ir));
nkeynes@1
   911
                    RN(ir) +=4;
nkeynes@1
   912
                    break;
nkeynes@1
   913
                case 0x5A: /* LDS     Rn, FPUL */
nkeynes@1
   914
                    sh4r.fpul = RN(ir);
nkeynes@1
   915
                    break;
nkeynes@1
   916
                case 0x62: /* STS.L   FPSCR, [--Rn] */
nkeynes@1
   917
                    RN(ir) -= 4;
nkeynes@1
   918
                    MEM_WRITE_LONG( RN(ir), sh4r.fpscr );
nkeynes@1
   919
                    break;
nkeynes@1
   920
                case 0x66: /* LDS.L   [Rn++], FPSCR */
nkeynes@1
   921
                    sh4r.fpscr = MEM_READ_LONG(RN(ir));
nkeynes@1
   922
                    RN(ir) +=4;
nkeynes@1
   923
                    break;
nkeynes@1
   924
                case 0x6A: /* LDS     Rn, FPSCR */
nkeynes@1
   925
                    sh4r.fpscr = RN(ir);
nkeynes@1
   926
                    break;
nkeynes@1
   927
                case 0xF2: /* STC.L   DBR, [--Rn] */
nkeynes@1
   928
                    CHECKPRIV();
nkeynes@1
   929
                    RN(ir) -= 4;
nkeynes@1
   930
                    MEM_WRITE_LONG( RN(ir), sh4r.dbr );
nkeynes@1
   931
                    break;
nkeynes@1
   932
                case 0xF6: /* LDC.L   [Rn++], DBR */
nkeynes@1
   933
                    CHECKPRIV();
nkeynes@1
   934
                    sh4r.dbr = MEM_READ_LONG(RN(ir));
nkeynes@1
   935
                    RN(ir) +=4;
nkeynes@1
   936
                    break;
nkeynes@1
   937
                case 0xFA: /* LDC     Rn, DBR */
nkeynes@1
   938
                    CHECKPRIV();
nkeynes@1
   939
                    sh4r.dbr = RN(ir);
nkeynes@1
   940
                    break;
nkeynes@1
   941
                case 0x83: case 0x93: case 0xA3: case 0xB3: case 0xC3:
nkeynes@1
   942
                case 0xD3: case 0xE3: case 0xF3: /* STC.L   Rn_BANK, [--Rn] */
nkeynes@1
   943
                    CHECKPRIV();
nkeynes@1
   944
                    RN(ir) -= 4;
nkeynes@1
   945
                    MEM_WRITE_LONG( RN(ir), RN_BANK(ir) );
nkeynes@1
   946
                    break;
nkeynes@1
   947
                case 0x87: case 0x97: case 0xA7: case 0xB7: case 0xC7:
nkeynes@1
   948
                case 0xD7: case 0xE7: case 0xF7: /* LDC.L   [Rn++], Rn_BANK */
nkeynes@1
   949
                    CHECKPRIV();
nkeynes@1
   950
                    RN_BANK(ir) = MEM_READ_LONG( RN(ir) );
nkeynes@1
   951
                    RN(ir) += 4;
nkeynes@1
   952
                    break;
nkeynes@1
   953
                case 0x8E: case 0x9E: case 0xAE: case 0xBE: case 0xCE:
nkeynes@1
   954
                case 0xDE: case 0xEE: case 0xFE: /* LDC     Rm, Rn_BANK */
nkeynes@1
   955
                    CHECKPRIV();
nkeynes@1
   956
                    RN_BANK(ir) = RM(ir);
nkeynes@1
   957
                    break;
nkeynes@1
   958
                default:
nkeynes@1
   959
                    if( (ir&0x000F) == 0x0F ) {
nkeynes@1
   960
                        /* MAC.W   [Rm++], [Rn++] */
nkeynes@1
   961
                        tmp = SIGNEXT16(MEM_READ_WORD(RM(ir))) *
nkeynes@1
   962
                            SIGNEXT16(MEM_READ_WORD(RN(ir)));
nkeynes@1
   963
                        if( sh4r.s ) {
nkeynes@1
   964
                            /* FIXME */
nkeynes@1
   965
                            UNIMP(ir);
nkeynes@1
   966
                        } else sh4r.mac += SIGNEXT32(tmp);
nkeynes@1
   967
                        RM(ir) += 2;
nkeynes@1
   968
                        RN(ir) += 2;
nkeynes@1
   969
                    } else if( (ir&0x000F) == 0x0C ) {
nkeynes@1
   970
                        /* SHAD    Rm, Rn */
nkeynes@1
   971
                        tmp = RM(ir);
nkeynes@1
   972
                        if( (tmp & 0x80000000) == 0 ) RN(ir) <<= (tmp&0x1f);
nkeynes@9
   973
                        else if( (tmp & 0x1F) == 0 )  
nkeynes@9
   974
			  RN(ir) = ((int32_t)RN(ir)) >> 31;
nkeynes@9
   975
                        else 
nkeynes@9
   976
			  RN(ir) = ((int32_t)RN(ir)) >> (((~RM(ir)) & 0x1F)+1);
nkeynes@1
   977
                    } else if( (ir&0x000F) == 0x0D ) {
nkeynes@1
   978
                        /* SHLD    Rm, Rn */
nkeynes@1
   979
                        tmp = RM(ir);
nkeynes@1
   980
                        if( (tmp & 0x80000000) == 0 ) RN(ir) <<= (tmp&0x1f);
nkeynes@1
   981
                        else if( (tmp & 0x1F) == 0 ) RN(ir) = 0;
nkeynes@1
   982
                        else RN(ir) >>= (((~tmp) & 0x1F)+1);
nkeynes@1
   983
                    } else UNDEF(ir);
nkeynes@1
   984
            }
nkeynes@1
   985
            break;
nkeynes@1
   986
        case 5: /* 0101nnnnmmmmdddd */
nkeynes@1
   987
            /* MOV.L   [Rm + disp4*4], Rn */
nkeynes@1
   988
            RN(ir) = MEM_READ_LONG( RM(ir) + (DISP4(ir)<<2) );
nkeynes@1
   989
            break;
nkeynes@1
   990
        case 6: /* 0110xxxxxxxxxxxx */
nkeynes@1
   991
            switch( ir&0x000f ) {
nkeynes@1
   992
                case 0: /* MOV.B   [Rm], Rn */
nkeynes@1
   993
                    RN(ir) = MEM_READ_BYTE( RM(ir) );
nkeynes@1
   994
                    break;
nkeynes@1
   995
                case 1: /* MOV.W   [Rm], Rn */
nkeynes@1
   996
                    RN(ir) = MEM_READ_WORD( RM(ir) );
nkeynes@1
   997
                    break;
nkeynes@1
   998
                case 2: /* MOV.L   [Rm], Rn */
nkeynes@1
   999
                    RN(ir) = MEM_READ_LONG( RM(ir) );
nkeynes@1
  1000
                    break;
nkeynes@1
  1001
                case 3: /* MOV     Rm, Rn */
nkeynes@1
  1002
                    RN(ir) = RM(ir);
nkeynes@1
  1003
                    break;
nkeynes@1
  1004
                case 4: /* MOV.B   [Rm++], Rn */
nkeynes@1
  1005
                    RN(ir) = MEM_READ_BYTE( RM(ir) );
nkeynes@1
  1006
                    RM(ir) ++;
nkeynes@1
  1007
                    break;
nkeynes@1
  1008
                case 5: /* MOV.W   [Rm++], Rn */
nkeynes@1
  1009
                    RN(ir) = MEM_READ_WORD( RM(ir) );
nkeynes@1
  1010
                    RM(ir) += 2;
nkeynes@1
  1011
                    break;
nkeynes@1
  1012
                case 6: /* MOV.L   [Rm++], Rn */
nkeynes@1
  1013
                    RN(ir) = MEM_READ_LONG( RM(ir) );
nkeynes@1
  1014
                    RM(ir) += 4;
nkeynes@1
  1015
                    break;
nkeynes@1
  1016
                case 7: /* NOT     Rm, Rn */
nkeynes@1
  1017
                    RN(ir) = ~RM(ir);
nkeynes@1
  1018
                    break;
nkeynes@1
  1019
                case 8: /* SWAP.B  Rm, Rn */
nkeynes@1
  1020
                    RN(ir) = (RM(ir)&0xFFFF0000) | ((RM(ir)&0x0000FF00)>>8) |
nkeynes@1
  1021
                        ((RM(ir)&0x000000FF)<<8);
nkeynes@1
  1022
                    break;
nkeynes@1
  1023
                case 9: /* SWAP.W  Rm, Rn */
nkeynes@1
  1024
                    RN(ir) = (RM(ir)>>16) | (RM(ir)<<16);
nkeynes@1
  1025
                    break;
nkeynes@1
  1026
                case 10:/* NEGC    Rm, Rn */
nkeynes@1
  1027
                    tmp = 0 - RM(ir);
nkeynes@1
  1028
                    RN(ir) = tmp - sh4r.t;
nkeynes@1
  1029
                    sh4r.t = ( 0<tmp || tmp<RN(ir) ? 1 : 0 );
nkeynes@1
  1030
                    break;
nkeynes@1
  1031
                case 11:/* NEG     Rm, Rn */
nkeynes@1
  1032
                    RN(ir) = 0 - RM(ir);
nkeynes@1
  1033
                    break;
nkeynes@1
  1034
                case 12:/* EXTU.B  Rm, Rn */
nkeynes@1
  1035
                    RN(ir) = RM(ir)&0x000000FF;
nkeynes@1
  1036
                    break;
nkeynes@1
  1037
                case 13:/* EXTU.W  Rm, Rn */
nkeynes@1
  1038
                    RN(ir) = RM(ir)&0x0000FFFF;
nkeynes@1
  1039
                    break;
nkeynes@1
  1040
                case 14:/* EXTS.B  Rm, Rn */
nkeynes@1
  1041
                    RN(ir) = SIGNEXT8( RM(ir)&0x000000FF );
nkeynes@1
  1042
                    break;
nkeynes@1
  1043
                case 15:/* EXTS.W  Rm, Rn */
nkeynes@1
  1044
                    RN(ir) = SIGNEXT16( RM(ir)&0x0000FFFF );
nkeynes@1
  1045
                    break;
nkeynes@1
  1046
            }
nkeynes@1
  1047
            break;
nkeynes@1
  1048
        case 7: /* 0111nnnniiiiiiii */
nkeynes@1
  1049
            /* ADD    imm8, Rn */
nkeynes@1
  1050
            RN(ir) += IMM8(ir);
nkeynes@1
  1051
            break;
nkeynes@1
  1052
        case 8: /* 1000xxxxxxxxxxxx */
nkeynes@1
  1053
            switch( (ir&0x0F00) >> 8 ) {
nkeynes@1
  1054
                case 0: /* MOV.B   R0, [Rm + disp4] */
nkeynes@1
  1055
                    MEM_WRITE_BYTE( RM(ir) + DISP4(ir), R0 );
nkeynes@1
  1056
                    break;
nkeynes@1
  1057
                case 1: /* MOV.W   R0, [Rm + disp4*2] */
nkeynes@1
  1058
                    MEM_WRITE_WORD( RM(ir) + (DISP4(ir)<<1), R0 );
nkeynes@1
  1059
                    break;
nkeynes@1
  1060
                case 4: /* MOV.B   [Rm + disp4], R0 */
nkeynes@1
  1061
                    R0 = MEM_READ_BYTE( RM(ir) + DISP4(ir) );
nkeynes@1
  1062
                    break;
nkeynes@1
  1063
                case 5: /* MOV.W   [Rm + disp4*2], R0 */
nkeynes@1
  1064
                    R0 = MEM_READ_WORD( RM(ir) + (DISP4(ir)<<1) );
nkeynes@1
  1065
                    break;
nkeynes@1
  1066
                case 8: /* CMP/EQ  imm, R0 */
nkeynes@1
  1067
                    sh4r.t = ( R0 == IMM8(ir) ? 1 : 0 );
nkeynes@1
  1068
                    break;
nkeynes@1
  1069
                case 9: /* BT      disp8 */
nkeynes@2
  1070
                    CHECKSLOTILLEGAL()
nkeynes@1
  1071
                    if( sh4r.t ) {
nkeynes@1
  1072
                        CHECKDEST( sh4r.pc + (PCDISP8(ir)<<1) + 4 )
nkeynes@1
  1073
                        sh4r.pc += (PCDISP8(ir)<<1) + 4;
nkeynes@1
  1074
                        sh4r.new_pc = sh4r.pc + 2;
nkeynes@27
  1075
                        return TRUE;
nkeynes@1
  1076
                    }
nkeynes@1
  1077
                    break;
nkeynes@1
  1078
                case 11:/* BF      disp8 */
nkeynes@2
  1079
                    CHECKSLOTILLEGAL()
nkeynes@1
  1080
                    if( !sh4r.t ) {
nkeynes@1
  1081
                        CHECKDEST( sh4r.pc + (PCDISP8(ir)<<1) + 4 )
nkeynes@1
  1082
                        sh4r.pc += (PCDISP8(ir)<<1) + 4;
nkeynes@1
  1083
                        sh4r.new_pc = sh4r.pc + 2;
nkeynes@27
  1084
                        return TRUE;
nkeynes@1
  1085
                    }
nkeynes@1
  1086
                    break;
nkeynes@1
  1087
                case 13:/* BT/S    disp8 */
nkeynes@2
  1088
                    CHECKSLOTILLEGAL()
nkeynes@1
  1089
                    if( sh4r.t ) {
nkeynes@1
  1090
                        CHECKDEST( sh4r.pc + (PCDISP8(ir)<<1) + 4 )
nkeynes@2
  1091
                        sh4r.in_delay_slot = 1;
nkeynes@1
  1092
                        sh4r.pc = sh4r.new_pc;
nkeynes@1
  1093
                        sh4r.new_pc = pc + (PCDISP8(ir)<<1) + 4;
nkeynes@2
  1094
                        sh4r.in_delay_slot = 1;
nkeynes@27
  1095
                        return TRUE;
nkeynes@1
  1096
                    }
nkeynes@1
  1097
                    break;
nkeynes@1
  1098
                case 15:/* BF/S    disp8 */
nkeynes@2
  1099
                    CHECKSLOTILLEGAL()
nkeynes@1
  1100
                    if( !sh4r.t ) {
nkeynes@1
  1101
                        CHECKDEST( sh4r.pc + (PCDISP8(ir)<<1) + 4 )
nkeynes@2
  1102
                        sh4r.in_delay_slot = 1;
nkeynes@1
  1103
                        sh4r.pc = sh4r.new_pc;
nkeynes@1
  1104
                        sh4r.new_pc = pc + (PCDISP8(ir)<<1) + 4;
nkeynes@27
  1105
                        return TRUE;
nkeynes@1
  1106
                    }
nkeynes@1
  1107
                    break;
nkeynes@1
  1108
                default: UNDEF(ir);
nkeynes@1
  1109
            }
nkeynes@1
  1110
            break;
nkeynes@1
  1111
        case 9: /* 1001xxxxxxxxxxxx */
nkeynes@1
  1112
            /* MOV.W   [disp8*2 + pc + 4], Rn */
nkeynes@1
  1113
            RN(ir) = MEM_READ_WORD( pc + 4 + (DISP8(ir)<<1) );
nkeynes@1
  1114
            break;
nkeynes@1
  1115
        case 10:/* 1010dddddddddddd */
nkeynes@1
  1116
            /* BRA     disp12 */
nkeynes@2
  1117
            CHECKDEST( sh4r.pc + (DISP12(ir)<<1) + 4 )
nkeynes@2
  1118
            CHECKSLOTILLEGAL()
nkeynes@2
  1119
            sh4r.in_delay_slot = 1;
nkeynes@1
  1120
            sh4r.pc = sh4r.new_pc;
nkeynes@1
  1121
            sh4r.new_pc = pc + 4 + (DISP12(ir)<<1);
nkeynes@27
  1122
            return TRUE;
nkeynes@1
  1123
        case 11:/* 1011dddddddddddd */
nkeynes@1
  1124
            /* BSR     disp12 */
nkeynes@1
  1125
            CHECKDEST( sh4r.pc + (DISP12(ir)<<1) + 4 )
nkeynes@2
  1126
            CHECKSLOTILLEGAL()
nkeynes@2
  1127
            sh4r.in_delay_slot = 1;
nkeynes@1
  1128
            sh4r.pr = pc + 4;
nkeynes@1
  1129
            sh4r.pc = sh4r.new_pc;
nkeynes@1
  1130
            sh4r.new_pc = pc + 4 + (DISP12(ir)<<1);
nkeynes@27
  1131
            return TRUE;
nkeynes@1
  1132
        case 12:/* 1100xxxxdddddddd */
nkeynes@1
  1133
        switch( (ir&0x0F00)>>8 ) {
nkeynes@1
  1134
                case 0: /* MOV.B  R0, [GBR + disp8] */
nkeynes@1
  1135
                    MEM_WRITE_BYTE( sh4r.gbr + DISP8(ir), R0 );
nkeynes@1
  1136
                    break;
nkeynes@1
  1137
                case 1: /* MOV.W  R0, [GBR + disp8*2] */
nkeynes@1
  1138
                    MEM_WRITE_WORD( sh4r.gbr + (DISP8(ir)<<1), R0 );
nkeynes@1
  1139
                    break;
nkeynes@1
  1140
                case  2: /*MOV.L   R0, [GBR + disp8*4] */
nkeynes@1
  1141
                    MEM_WRITE_LONG( sh4r.gbr + (DISP8(ir)<<2), R0 );
nkeynes@1
  1142
                    break;
nkeynes@1
  1143
                case 3: /* TRAPA   imm8 */
nkeynes@2
  1144
                    CHECKSLOTILLEGAL()
nkeynes@2
  1145
                    sh4r.in_delay_slot = 1;
nkeynes@116
  1146
                    MMIO_WRITE( MMU, TRA, UIMM8(ir)<<2 );
nkeynes@1
  1147
                    RAISE( EXC_TRAP, EXV_TRAP );
nkeynes@1
  1148
                    break;
nkeynes@1
  1149
                case 4: /* MOV.B   [GBR + disp8], R0 */
nkeynes@1
  1150
                    R0 = MEM_READ_BYTE( sh4r.gbr + DISP8(ir) );
nkeynes@1
  1151
                    break;
nkeynes@1
  1152
                case 5: /* MOV.W   [GBR + disp8*2], R0 */
nkeynes@1
  1153
                    R0 = MEM_READ_WORD( sh4r.gbr + (DISP8(ir)<<1) );
nkeynes@1
  1154
                    break;
nkeynes@1
  1155
                case 6: /* MOV.L   [GBR + disp8*4], R0 */
nkeynes@1
  1156
                    R0 = MEM_READ_LONG( sh4r.gbr + (DISP8(ir)<<2) );
nkeynes@1
  1157
                    break;
nkeynes@1
  1158
                case 7: /* MOVA    disp8 + pc&~3 + 4, R0 */
nkeynes@1
  1159
                    R0 = (pc&0xFFFFFFFC) + (DISP8(ir)<<2) + 4;
nkeynes@1
  1160
                    break;
nkeynes@1
  1161
                case 8: /* TST     imm8, R0 */
nkeynes@1
  1162
                    sh4r.t = (R0 & UIMM8(ir) ? 0 : 1);
nkeynes@1
  1163
                    break;
nkeynes@1
  1164
                case 9: /* AND     imm8, R0 */
nkeynes@1
  1165
                    R0 &= UIMM8(ir);
nkeynes@1
  1166
                    break;
nkeynes@1
  1167
                case 10:/* XOR     imm8, R0 */
nkeynes@1
  1168
                    R0 ^= UIMM8(ir);
nkeynes@1
  1169
                    break;
nkeynes@1
  1170
                case 11:/* OR      imm8, R0 */
nkeynes@1
  1171
                    R0 |= UIMM8(ir);
nkeynes@1
  1172
                    break;
nkeynes@1
  1173
                case 12:/* TST.B   imm8, [R0+GBR] */
nkeynes@1
  1174
                    sh4r.t = ( MEM_READ_BYTE(R0 + sh4r.gbr) & UIMM8(ir) ? 0 : 1 );
nkeynes@1
  1175
                    break;
nkeynes@1
  1176
                case 13:/* AND.B   imm8, [R0+GBR] */
nkeynes@1
  1177
                    MEM_WRITE_BYTE( R0 + sh4r.gbr,
nkeynes@1
  1178
                                    UIMM8(ir) & MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@1
  1179
                    break;
nkeynes@1
  1180
                case 14:/* XOR.B   imm8, [R0+GBR] */
nkeynes@1
  1181
                    MEM_WRITE_BYTE( R0 + sh4r.gbr,
nkeynes@1
  1182
                                    UIMM8(ir) ^ MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@1
  1183
                    break;
nkeynes@1
  1184
                case 15:/* OR.B    imm8, [R0+GBR] */
nkeynes@1
  1185
                    MEM_WRITE_BYTE( R0 + sh4r.gbr,
nkeynes@1
  1186
                                    UIMM8(ir) | MEM_READ_BYTE(R0 + sh4r.gbr) );
nkeynes@1
  1187
                    break;
nkeynes@1
  1188
            }
nkeynes@1
  1189
            break;
nkeynes@1
  1190
        case 13:/* 1101nnnndddddddd */
nkeynes@1
  1191
            /* MOV.L   [disp8*4 + pc&~3 + 4], Rn */
nkeynes@1
  1192
            RN(ir) = MEM_READ_LONG( (pc&0xFFFFFFFC) + (DISP8(ir)<<2) + 4 );
nkeynes@1
  1193
            break;
nkeynes@1
  1194
        case 14:/* 1110nnnniiiiiiii */
nkeynes@1
  1195
            /* MOV     imm8, Rn */
nkeynes@1
  1196
            RN(ir) = IMM8(ir);
nkeynes@1
  1197
            break;
nkeynes@1
  1198
        case 15:/* 1111xxxxxxxxxxxx */
nkeynes@1
  1199
            CHECKFPUEN();
nkeynes@84
  1200
	    if( IS_FPU_DOUBLEPREC() ) {
nkeynes@84
  1201
		switch( ir&0x000F ) {
nkeynes@84
  1202
                case 0: /* FADD    FRm, FRn */
nkeynes@84
  1203
                    DRN(ir) += DRM(ir);
nkeynes@84
  1204
                    break;
nkeynes@84
  1205
                case 1: /* FSUB    FRm, FRn */
nkeynes@84
  1206
                    DRN(ir) -= DRM(ir);
nkeynes@84
  1207
                    break;
nkeynes@84
  1208
                case 2: /* FMUL    FRm, FRn */
nkeynes@84
  1209
                    DRN(ir) = DRN(ir) * DRM(ir);
nkeynes@84
  1210
                    break;
nkeynes@84
  1211
                case 3: /* FDIV    FRm, FRn */
nkeynes@84
  1212
                    DRN(ir) = DRN(ir) / DRM(ir);
nkeynes@84
  1213
                    break;
nkeynes@84
  1214
                case 4: /* FCMP/EQ FRm, FRn */
nkeynes@84
  1215
                    sh4r.t = ( DRN(ir) == DRM(ir) ? 1 : 0 );
nkeynes@84
  1216
                    break;
nkeynes@84
  1217
                case 5: /* FCMP/GT FRm, FRn */
nkeynes@84
  1218
                    sh4r.t = ( DRN(ir) > DRM(ir) ? 1 : 0 );
nkeynes@84
  1219
                    break;
nkeynes@84
  1220
                case 6: /* FMOV.S  [Rm+R0], FRn */
nkeynes@84
  1221
                    MEM_FP_READ( RM(ir) + R0, FRNn(ir) );
nkeynes@84
  1222
                    break;
nkeynes@84
  1223
                case 7: /* FMOV.S  FRm, [Rn+R0] */
nkeynes@84
  1224
                    MEM_FP_WRITE( RN(ir) + R0, FRMn(ir) );
nkeynes@84
  1225
                    break;
nkeynes@84
  1226
                case 8: /* FMOV.S  [Rm], FRn */
nkeynes@84
  1227
                    MEM_FP_READ( RM(ir), FRNn(ir) );
nkeynes@84
  1228
                    break;
nkeynes@84
  1229
                case 9: /* FMOV.S  [Rm++], FRn */
nkeynes@84
  1230
                    MEM_FP_READ( RM(ir), FRNn(ir) );
nkeynes@84
  1231
                    RM(ir) += FP_WIDTH;
nkeynes@84
  1232
                    break;
nkeynes@84
  1233
                case 10:/* FMOV.S  FRm, [Rn] */
nkeynes@84
  1234
                    MEM_FP_WRITE( RN(ir), FRMn(ir) );
nkeynes@84
  1235
                    break;
nkeynes@84
  1236
                case 11:/* FMOV.S  FRm, [--Rn] */
nkeynes@84
  1237
                    RN(ir) -= FP_WIDTH;
nkeynes@84
  1238
                    MEM_FP_WRITE( RN(ir), FRMn(ir) );
nkeynes@84
  1239
                    break;
nkeynes@84
  1240
                case 12:/* FMOV    FRm, FRn */
nkeynes@84
  1241
		    if( IS_FPU_DOUBLESIZE() )
nkeynes@84
  1242
			DRN(ir) = DRM(ir);
nkeynes@84
  1243
		    else
nkeynes@84
  1244
			FRN(ir) = FRM(ir);
nkeynes@84
  1245
                    break;
nkeynes@84
  1246
                case 13:
nkeynes@84
  1247
                    switch( (ir&0x00F0) >> 4 ) {
nkeynes@84
  1248
		    case 0: /* FSTS    FPUL, FRn */
nkeynes@84
  1249
			FRN(ir) = FPULf;
nkeynes@84
  1250
			break;
nkeynes@84
  1251
		    case 1: /* FLDS    FRn,FPUL */
nkeynes@84
  1252
			FPULf = FRN(ir);
nkeynes@84
  1253
			break;
nkeynes@84
  1254
		    case 2: /* FLOAT   FPUL, FRn */
nkeynes@84
  1255
			DRN(ir) = (float)FPULi;
nkeynes@84
  1256
			break;
nkeynes@84
  1257
		    case 3: /* FTRC    FRn, FPUL */
nkeynes@123
  1258
			dtmp = DRN(ir);
nkeynes@123
  1259
			if( dtmp >= MAX_INTF )
nkeynes@123
  1260
			    FPULi = MAX_INT;
nkeynes@123
  1261
			else if( dtmp <= MIN_INTF )
nkeynes@123
  1262
			    FPULi = MIN_INT;
nkeynes@123
  1263
			else 
nkeynes@123
  1264
			    FPULi = (int32_t)dtmp;
nkeynes@84
  1265
			break;
nkeynes@84
  1266
		    case 4: /* FNEG    FRn */
nkeynes@84
  1267
			DRN(ir) = -DRN(ir);
nkeynes@84
  1268
			break;
nkeynes@84
  1269
		    case 5: /* FABS    FRn */
nkeynes@84
  1270
			DRN(ir) = fabs(DRN(ir));
nkeynes@84
  1271
			break;
nkeynes@84
  1272
		    case 6: /* FSQRT   FRn */
nkeynes@84
  1273
			DRN(ir) = sqrt(DRN(ir));
nkeynes@84
  1274
			break;
nkeynes@84
  1275
		    case 7: /* FSRRA FRn */
nkeynes@84
  1276
			DRN(ir) = 1.0/sqrt(DRN(ir));
nkeynes@84
  1277
			break;
nkeynes@84
  1278
		    case 8: /* FLDI0   FRn */
nkeynes@84
  1279
			DRN(ir) = 0.0;
nkeynes@84
  1280
			break;
nkeynes@84
  1281
		    case 9: /* FLDI1   FRn */
nkeynes@84
  1282
			DRN(ir) = 1.0;
nkeynes@84
  1283
			break;
nkeynes@84
  1284
		    case 10: /* FCNVSD FPUL, DRn */
nkeynes@84
  1285
			DRN(ir) = (double)FPULf;
nkeynes@84
  1286
			break;
nkeynes@84
  1287
		    case 11: /* FCNVDS DRn, FPUL */
nkeynes@84
  1288
			FPULf = (float)DRN(ir);
nkeynes@84
  1289
			break;
nkeynes@84
  1290
		    case 14:/* FIPR    FVm, FVn */
nkeynes@84
  1291
			UNDEF(ir);
nkeynes@84
  1292
			break;
nkeynes@84
  1293
		    case 15:
nkeynes@84
  1294
			if( (ir&0x0300) == 0x0100 ) { /* FTRV    XMTRX,FVn */
nkeynes@84
  1295
			    break;
nkeynes@84
  1296
			}
nkeynes@84
  1297
			else if( (ir&0x0100) == 0 ) { /* FSCA    FPUL, DRn */
nkeynes@84
  1298
			    float angle = (((float)(short)(FPULi>>16)) +
nkeynes@84
  1299
					   ((float)(FPULi&16)/65536.0)) *
nkeynes@84
  1300
				2 * M_PI;
nkeynes@84
  1301
			    int reg = DRNn(ir);
nkeynes@84
  1302
			    DR(reg) = sinf(angle);
nkeynes@84
  1303
			    DR(reg+1) = cosf(angle);
nkeynes@84
  1304
			    break;
nkeynes@84
  1305
			}
nkeynes@84
  1306
			else if( ir == 0xFBFD ) {
nkeynes@84
  1307
			    /* FRCHG   */
nkeynes@84
  1308
			    sh4r.fpscr ^= FPSCR_FR;
nkeynes@84
  1309
			    break;
nkeynes@84
  1310
			}
nkeynes@84
  1311
			else if( ir == 0xF3FD ) {
nkeynes@84
  1312
			    /* FSCHG   */
nkeynes@84
  1313
			    sh4r.fpscr ^= FPSCR_SZ;
nkeynes@84
  1314
			    break;
nkeynes@84
  1315
			}
nkeynes@84
  1316
		    default: UNDEF(ir);
nkeynes@84
  1317
                    }
nkeynes@84
  1318
                    break;
nkeynes@84
  1319
                case 14:/* FMAC    FR0, FRm, FRn */
nkeynes@84
  1320
                    DRN(ir) += DRM(ir)*DR0;
nkeynes@84
  1321
                    break;
nkeynes@84
  1322
                default: UNDEF(ir);
nkeynes@84
  1323
		}
nkeynes@122
  1324
	    } else { /* Single precision */
nkeynes@84
  1325
		switch( ir&0x000F ) {
nkeynes@1
  1326
                case 0: /* FADD    FRm, FRn */
nkeynes@1
  1327
                    FRN(ir) += FRM(ir);
nkeynes@1
  1328
                    break;
nkeynes@1
  1329
                case 1: /* FSUB    FRm, FRn */
nkeynes@1
  1330
                    FRN(ir) -= FRM(ir);
nkeynes@1
  1331
                    break;
nkeynes@1
  1332
                case 2: /* FMUL    FRm, FRn */
nkeynes@1
  1333
                    FRN(ir) = FRN(ir) * FRM(ir);
nkeynes@1
  1334
                    break;
nkeynes@1
  1335
                case 3: /* FDIV    FRm, FRn */
nkeynes@1
  1336
                    FRN(ir) = FRN(ir) / FRM(ir);
nkeynes@1
  1337
                    break;
nkeynes@1
  1338
                case 4: /* FCMP/EQ FRm, FRn */
nkeynes@1
  1339
                    sh4r.t = ( FRN(ir) == FRM(ir) ? 1 : 0 );
nkeynes@1
  1340
                    break;
nkeynes@1
  1341
                case 5: /* FCMP/GT FRm, FRn */
nkeynes@1
  1342
                    sh4r.t = ( FRN(ir) > FRM(ir) ? 1 : 0 );
nkeynes@1
  1343
                    break;
nkeynes@1
  1344
                case 6: /* FMOV.S  [Rm+R0], FRn */
nkeynes@1
  1345
                    MEM_FP_READ( RM(ir) + R0, FRNn(ir) );
nkeynes@1
  1346
                    break;
nkeynes@1
  1347
                case 7: /* FMOV.S  FRm, [Rn+R0] */
nkeynes@1
  1348
                    MEM_FP_WRITE( RN(ir) + R0, FRMn(ir) );
nkeynes@1
  1349
                    break;
nkeynes@1
  1350
                case 8: /* FMOV.S  [Rm], FRn */
nkeynes@1
  1351
                    MEM_FP_READ( RM(ir), FRNn(ir) );
nkeynes@1
  1352
                    break;
nkeynes@1
  1353
                case 9: /* FMOV.S  [Rm++], FRn */
nkeynes@1
  1354
                    MEM_FP_READ( RM(ir), FRNn(ir) );
nkeynes@1
  1355
                    RM(ir) += FP_WIDTH;
nkeynes@1
  1356
                    break;
nkeynes@1
  1357
                case 10:/* FMOV.S  FRm, [Rn] */
nkeynes@1
  1358
                    MEM_FP_WRITE( RN(ir), FRMn(ir) );
nkeynes@1
  1359
                    break;
nkeynes@1
  1360
                case 11:/* FMOV.S  FRm, [--Rn] */
nkeynes@1
  1361
                    RN(ir) -= FP_WIDTH;
nkeynes@1
  1362
                    MEM_FP_WRITE( RN(ir), FRMn(ir) );
nkeynes@1
  1363
                    break;
nkeynes@1
  1364
                case 12:/* FMOV    FRm, FRn */
nkeynes@84
  1365
		    if( IS_FPU_DOUBLESIZE() )
nkeynes@84
  1366
			DRN(ir) = DRM(ir);
nkeynes@84
  1367
		    else
nkeynes@84
  1368
			FRN(ir) = FRM(ir);
nkeynes@1
  1369
                    break;
nkeynes@1
  1370
                case 13:
nkeynes@1
  1371
                    switch( (ir&0x00F0) >> 4 ) {
nkeynes@84
  1372
		    case 0: /* FSTS    FPUL, FRn */
nkeynes@84
  1373
			FRN(ir) = FPULf;
nkeynes@84
  1374
			break;
nkeynes@84
  1375
		    case 1: /* FLDS    FRn,FPUL */
nkeynes@84
  1376
			FPULf = FRN(ir);
nkeynes@84
  1377
			break;
nkeynes@84
  1378
		    case 2: /* FLOAT   FPUL, FRn */
nkeynes@84
  1379
			FRN(ir) = (float)FPULi;
nkeynes@84
  1380
			break;
nkeynes@84
  1381
		    case 3: /* FTRC    FRn, FPUL */
nkeynes@123
  1382
			ftmp = FRN(ir);
nkeynes@123
  1383
			if( ftmp >= MAX_INTF )
nkeynes@123
  1384
			    FPULi = MAX_INT;
nkeynes@123
  1385
			else if( ftmp <= MIN_INTF )
nkeynes@123
  1386
			    FPULi = MIN_INT;
nkeynes@123
  1387
			else
nkeynes@123
  1388
			    FPULi = (int32_t)ftmp;
nkeynes@84
  1389
			break;
nkeynes@84
  1390
		    case 4: /* FNEG    FRn */
nkeynes@84
  1391
			FRN(ir) = -FRN(ir);
nkeynes@84
  1392
			break;
nkeynes@84
  1393
		    case 5: /* FABS    FRn */
nkeynes@84
  1394
			FRN(ir) = fabsf(FRN(ir));
nkeynes@84
  1395
			break;
nkeynes@84
  1396
		    case 6: /* FSQRT   FRn */
nkeynes@84
  1397
			FRN(ir) = sqrtf(FRN(ir));
nkeynes@84
  1398
			break;
nkeynes@84
  1399
		    case 7: /* FSRRA FRn */
nkeynes@84
  1400
			FRN(ir) = 1.0/sqrtf(FRN(ir));
nkeynes@84
  1401
			break;
nkeynes@84
  1402
		    case 8: /* FLDI0   FRn */
nkeynes@84
  1403
			FRN(ir) = 0.0;
nkeynes@84
  1404
			break;
nkeynes@84
  1405
		    case 9: /* FLDI1   FRn */
nkeynes@84
  1406
			FRN(ir) = 1.0;
nkeynes@84
  1407
			break;
nkeynes@84
  1408
		    case 10: /* FCNVSD FPUL, DRn */
nkeynes@84
  1409
			UNDEF(ir);
nkeynes@84
  1410
			break;
nkeynes@84
  1411
		    case 11: /* FCNVDS DRn, FPUL */
nkeynes@84
  1412
			UNDEF(ir);
nkeynes@84
  1413
			break;
nkeynes@84
  1414
		    case 14:/* FIPR    FVm, FVn */
nkeynes@2
  1415
                            /* FIXME: This is not going to be entirely accurate
nkeynes@2
  1416
                             * as the SH4 instruction is less precise. Also
nkeynes@2
  1417
                             * need to check for 0s and infinities.
nkeynes@2
  1418
                             */
nkeynes@2
  1419
                        {
nkeynes@2
  1420
                            int tmp2 = FVN(ir);
nkeynes@2
  1421
                            tmp = FVM(ir);
nkeynes@84
  1422
                            FR(tmp2+3) = FR(tmp)*FR(tmp2) +
nkeynes@84
  1423
                                FR(tmp+1)*FR(tmp2+1) +
nkeynes@84
  1424
                                FR(tmp+2)*FR(tmp2+2) +
nkeynes@84
  1425
                                FR(tmp+3)*FR(tmp2+3);
nkeynes@1
  1426
                            break;
nkeynes@2
  1427
                        }
nkeynes@84
  1428
		    case 15:
nkeynes@84
  1429
			if( (ir&0x0300) == 0x0100 ) { /* FTRV    XMTRX,FVn */
nkeynes@84
  1430
			    tmp = FVN(ir);
nkeynes@84
  1431
			    float fv[4] = { FR(tmp), FR(tmp+1), FR(tmp+2), FR(tmp+3) };
nkeynes@84
  1432
			    FR(tmp) = XF(0) * fv[0] + XF(4)*fv[1] +
nkeynes@84
  1433
				XF(8)*fv[2] + XF(12)*fv[3];
nkeynes@84
  1434
			    FR(tmp+1) = XF(1) * fv[0] + XF(5)*fv[1] +
nkeynes@84
  1435
				XF(9)*fv[2] + XF(13)*fv[3];
nkeynes@84
  1436
			    FR(tmp+2) = XF(2) * fv[0] + XF(6)*fv[1] +
nkeynes@84
  1437
				XF(10)*fv[2] + XF(14)*fv[3];
nkeynes@84
  1438
			    FR(tmp+3) = XF(3) * fv[0] + XF(7)*fv[1] +
nkeynes@84
  1439
				XF(11)*fv[2] + XF(15)*fv[3];
nkeynes@84
  1440
			    break;
nkeynes@84
  1441
			}
nkeynes@84
  1442
			else if( (ir&0x0100) == 0 ) { /* FSCA    FPUL, DRn */
nkeynes@84
  1443
			    float angle = (((float)(short)(FPULi>>16)) +
nkeynes@122
  1444
					   (((float)(FPULi&0xFFFF))/65536.0)) *
nkeynes@84
  1445
				2 * M_PI;
nkeynes@84
  1446
			    int reg = FRNn(ir);
nkeynes@84
  1447
			    FR(reg) = sinf(angle);
nkeynes@84
  1448
			    FR(reg+1) = cosf(angle);
nkeynes@84
  1449
			    break;
nkeynes@84
  1450
			}
nkeynes@84
  1451
			else if( ir == 0xFBFD ) {
nkeynes@84
  1452
			    /* FRCHG   */
nkeynes@84
  1453
			    sh4r.fpscr ^= FPSCR_FR;
nkeynes@84
  1454
			    break;
nkeynes@84
  1455
			}
nkeynes@84
  1456
			else if( ir == 0xF3FD ) {
nkeynes@84
  1457
			    /* FSCHG   */
nkeynes@84
  1458
			    sh4r.fpscr ^= FPSCR_SZ;
nkeynes@84
  1459
			    break;
nkeynes@84
  1460
			}
nkeynes@84
  1461
		    default: UNDEF(ir);
nkeynes@1
  1462
                    }
nkeynes@1
  1463
                    break;
nkeynes@1
  1464
                case 14:/* FMAC    FR0, FRm, FRn */
nkeynes@1
  1465
                    FRN(ir) += FRM(ir)*FR0;
nkeynes@1
  1466
                    break;
nkeynes@1
  1467
                default: UNDEF(ir);
nkeynes@84
  1468
		}
nkeynes@84
  1469
	    }
nkeynes@84
  1470
	    break;
nkeynes@1
  1471
    }
nkeynes@1
  1472
    sh4r.pc = sh4r.new_pc;
nkeynes@1
  1473
    sh4r.new_pc += 2;
nkeynes@2
  1474
    sh4r.in_delay_slot = 0;
nkeynes@1
  1475
}
.