Search
lxdream.org :: lxdream :: r123:2ad156e10657
lxdream 0.9.1
released Jun 29
Download Now
changeset123:2ad156e10657
parent122:3a557bc205d8
child124:ceb38f08619a
authornkeynes
dateWed Mar 22 11:58:01 2006 +0000 (14 years ago)
Fix FTRC - needs to clamp at min/max int
src/sh4/sh4core.c
1.1 --- a/src/sh4/sh4core.c Tue Mar 21 11:14:04 2006 +0000
1.2 +++ b/src/sh4/sh4core.c Wed Mar 22 11:58:01 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: sh4core.c,v 1.24 2006-03-21 11:14:04 nkeynes Exp $
1.6 + * $Id: sh4core.c,v 1.25 2006-03-22 11:58:01 nkeynes Exp $
1.7 *
1.8 * SH4 emulation core, and parent module for all the SH4 peripheral
1.9 * modules.
1.10 @@ -27,6 +27,11 @@
1.11 #include "clock.h"
1.12 #include "syscall.h"
1.13
1.14 +#define MAX_INT 0x7FFFFFFF
1.15 +#define MIN_INT 0x80000000
1.16 +#define MAX_INTF 2147483647.0
1.17 +#define MIN_INTF -2147483648.0
1.18 +
1.19 /* CPU-generated exception code/vector pairs */
1.20 #define EXC_POWER_RESET 0x000 /* vector special */
1.21 #define EXC_MANUAL_RESET 0x020
1.22 @@ -297,6 +302,8 @@
1.23 unsigned short ir;
1.24 uint32_t tmp;
1.25 uint64_t tmpl;
1.26 + float ftmp;
1.27 + double dtmp;
1.28
1.29 #define R0 sh4r.r[0]
1.30 #define FR0 FR(0)
1.31 @@ -1230,8 +1237,13 @@
1.32 DRN(ir) = (float)FPULi;
1.33 break;
1.34 case 3: /* FTRC FRn, FPUL */
1.35 - FPULi = (uint32_t)DRN(ir);
1.36 - /* FIXME: is this sufficient? */
1.37 + dtmp = DRN(ir);
1.38 + if( dtmp >= MAX_INTF )
1.39 + FPULi = MAX_INT;
1.40 + else if( dtmp <= MIN_INTF )
1.41 + FPULi = MIN_INT;
1.42 + else
1.43 + FPULi = (int32_t)dtmp;
1.44 break;
1.45 case 4: /* FNEG FRn */
1.46 DRN(ir) = -DRN(ir);
1.47 @@ -1349,8 +1361,13 @@
1.48 FRN(ir) = (float)FPULi;
1.49 break;
1.50 case 3: /* FTRC FRn, FPUL */
1.51 - FPULi = (uint32_t)FRN(ir);
1.52 - /* FIXME: is this sufficient? */
1.53 + ftmp = FRN(ir);
1.54 + if( ftmp >= MAX_INTF )
1.55 + FPULi = MAX_INT;
1.56 + else if( ftmp <= MIN_INTF )
1.57 + FPULi = MIN_INT;
1.58 + else
1.59 + FPULi = (int32_t)ftmp;
1.60 break;
1.61 case 4: /* FNEG FRn */
1.62 FRN(ir) = -FRN(ir);
.