Began adding float support
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 8 May 2000 03:12:19 +0000 (03:12 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 8 May 2000 03:12:19 +0000 (03:12 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@245 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/z80/support.c [new file with mode: 0644]
src/z80/support.h [new file with mode: 0644]

diff --git a/src/z80/support.c b/src/z80/support.c
new file mode 100644 (file)
index 0000000..01bbe84
--- /dev/null
@@ -0,0 +1,34 @@
+/** @file z80/support.c
+ */
+#include "z80.h"
+#include <math.h>
+
+int convertFloat(Z80_FLOAT *f, double native)
+{
+    unsigned long mantissa, exponent;
+    double f2;
+    wassert(f);
+    if (native!=0) {
+       f2 = floor(log(fabs(native))/log(2))+1;
+       mantissa = 0x1000000*fabs(native)/exp(f2*log(2));
+       mantissa &= 0xffffff;
+       exponent = f2 + 0x40;
+       if (native<0)
+           exponent |= 0x80;
+    }
+    else {
+       mantissa = 0;
+       exponent = 0;
+    }
+
+    f->w[0] = (WORD)mantissa;
+    f->w[1] = (BYTE)(mantissa>>16);
+    f->w[1] |= exponent << 8;
+    
+    f->b[0] = (BYTE)f->w[0];
+    f->b[1] = (BYTE)(f->w[0]>>8);
+    f->b[2] = (BYTE)f->w[1];
+    f->b[3] = (BYTE)(f->w[1]>>8);
+
+    return 0;
+}
diff --git a/src/z80/support.h b/src/z80/support.h
new file mode 100644 (file)
index 0000000..cb51912
--- /dev/null
@@ -0,0 +1,18 @@
+/** @file z80/support.h
+    Support functions for the z80 port.
+*/
+#ifndef Z80_SUPPORT_INCLUDE
+#define Z80_SUPPORT_INCLUDE
+
+typedef unsigned short WORD;
+typedef unsigned char BYTE;
+
+typedef struct {
+    WORD w[2];
+    BYTE b[4];
+} Z80_FLOAT;
+
+/** Convert a native float into 'z80' format */
+int convertFloat(Z80_FLOAT *f, double native);
+
+#endif