Search
lxdream.org :: lxdream/src/sh4/sh4.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4.c
changeset 669:ab344e42bca9
prev638:d6dc39e935af
next671:a530ea88eebd
author nkeynes
date Mon May 12 10:00:13 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Cleanup most of the -Wall warnings (getting a bit sloppy...)
Convert FP code to use fixed banks rather than indirect pointer
(3-4% faster this way now)
file annotate diff log raw
1.1 --- a/src/sh4/sh4.c Fri Feb 15 09:36:38 2008 +0000
1.2 +++ b/src/sh4/sh4.c Mon May 12 10:00:13 2008 +0000
1.3 @@ -22,15 +22,16 @@
1.4 #include <assert.h>
1.5 #include "dream.h"
1.6 #include "dreamcast.h"
1.7 +#include "mem.h"
1.8 +#include "clock.h"
1.9 +#include "eventq.h"
1.10 +#include "syscall.h"
1.11 +#include "sh4/intc.h"
1.12 #include "sh4/sh4core.h"
1.13 #include "sh4/sh4mmio.h"
1.14 -#include "sh4/intc.h"
1.15 -#include "sh4/xltcache.h"
1.16 #include "sh4/sh4stat.h"
1.17 #include "sh4/sh4trans.h"
1.18 -#include "mem.h"
1.19 -#include "clock.h"
1.20 -#include "syscall.h"
1.21 +#include "sh4/xltcache.h"
1.22
1.23 void sh4_init( void );
1.24 void sh4_xlat_init( void );
1.25 @@ -61,7 +62,7 @@
1.26 #ifdef SH4_TRANSLATOR
1.27 if( use ) {
1.28 xlat_cache_init();
1.29 - sh4_x86_init();
1.30 + sh4_translate_init();
1.31 sh4_module.run_time_slice = sh4_xlat_run_slice;
1.32 } else {
1.33 sh4_module.run_time_slice = sh4_run_slice;
1.34 @@ -106,7 +107,6 @@
1.35 sh4r.vbr = 0x00000000;
1.36 sh4r.fpscr = 0x00040001;
1.37 sh4r.sr = 0x700000F0;
1.38 - sh4r.fr_bank = &sh4r.fr[0][0];
1.39
1.40 /* Mem reset will do this, but if we want to reset _just_ the SH4... */
1.41 MMIO_WRITE( MMU, EXPEVT, EXC_POWER_RESET );
1.42 @@ -151,7 +151,6 @@
1.43 xlat_flush_cache();
1.44 }
1.45 fread( &sh4r, sizeof(sh4r), 1, f );
1.46 - sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0]; // Fixup internal FR pointer
1.47 MMU_load_state( f );
1.48 INTC_load_state( f );
1.49 TMU_load_state( f );
1.50 @@ -218,6 +217,16 @@
1.51 memcpy( sh4r.r_bank, tmp, sizeof(uint32_t)*8 );
1.52 }
1.53
1.54 +void sh4_switch_fr_banks()
1.55 +{
1.56 + int i;
1.57 + for( i=0; i<16; i++ ) {
1.58 + float tmp = sh4r.fr[0][i];
1.59 + sh4r.fr[0][i] = sh4r.fr[1][i];
1.60 + sh4r.fr[1][i] = tmp;
1.61 + }
1.62 +}
1.63 +
1.64 void sh4_write_sr( uint32_t newval )
1.65 {
1.66 int oldbank = (sh4r.sr&SR_MDRB) == SR_MDRB;
1.67 @@ -232,6 +241,14 @@
1.68 intc_mask_changed();
1.69 }
1.70
1.71 +void sh4_write_fpscr( uint32_t newval )
1.72 +{
1.73 + if( (sh4r.fpscr ^ newval) & FPSCR_FR ) {
1.74 + sh4_switch_fr_banks();
1.75 + }
1.76 + sh4r.fpscr = newval;
1.77 +}
1.78 +
1.79 uint32_t sh4_read_sr( void )
1.80 {
1.81 /* synchronize sh4r.sr with the various bitflags */
1.82 @@ -286,6 +303,7 @@
1.83 sh4r.new_pc = sh4r.pc + 2;
1.84 sh4_write_sr( (sh4r.sr|SR_MD|SR_BL|SR_RB|SR_IMASK)
1.85 &(~SR_FD) );
1.86 + return TRUE;
1.87 }
1.88
1.89 gboolean sh4_raise_trap( int trap )
1.90 @@ -408,17 +426,17 @@
1.91 * Compute the matrix tranform of fv given the matrix xf.
1.92 * Both fv and xf are word-swapped as per the sh4r.fr banks
1.93 */
1.94 -void sh4_ftrv( float *target, float *xf )
1.95 +void sh4_ftrv( float *target )
1.96 {
1.97 float fv[4] = { target[1], target[0], target[3], target[2] };
1.98 - target[1] = xf[1] * fv[0] + xf[5]*fv[1] +
1.99 - xf[9]*fv[2] + xf[13]*fv[3];
1.100 - target[0] = xf[0] * fv[0] + xf[4]*fv[1] +
1.101 - xf[8]*fv[2] + xf[12]*fv[3];
1.102 - target[3] = xf[3] * fv[0] + xf[7]*fv[1] +
1.103 - xf[11]*fv[2] + xf[15]*fv[3];
1.104 - target[2] = xf[2] * fv[0] + xf[6]*fv[1] +
1.105 - xf[10]*fv[2] + xf[14]*fv[3];
1.106 + target[1] = sh4r.fr[1][1] * fv[0] + sh4r.fr[1][5]*fv[1] +
1.107 + sh4r.fr[1][9]*fv[2] + sh4r.fr[1][13]*fv[3];
1.108 + target[0] = sh4r.fr[1][0] * fv[0] + sh4r.fr[1][4]*fv[1] +
1.109 + sh4r.fr[1][8]*fv[2] + sh4r.fr[1][12]*fv[3];
1.110 + target[3] = sh4r.fr[1][3] * fv[0] + sh4r.fr[1][7]*fv[1] +
1.111 + sh4r.fr[1][11]*fv[2] + sh4r.fr[1][15]*fv[3];
1.112 + target[2] = sh4r.fr[1][2] * fv[0] + sh4r.fr[1][6]*fv[1] +
1.113 + sh4r.fr[1][10]*fv[2] + sh4r.fr[1][14]*fv[3];
1.114 }
1.115
1.116 gboolean sh4_has_page( sh4vma_t vma )
.