From e8af787a7af30e7d132b40a278b1d131032f3b88 Mon Sep 17 00:00:00 2001 From: michaelh Date: Mon, 8 May 2000 03:12:19 +0000 Subject: [PATCH] Began adding float support git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@245 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/z80/support.c | 34 ++++++++++++++++++++++++++++++++++ src/z80/support.h | 18 ++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/z80/support.c create mode 100644 src/z80/support.h diff --git a/src/z80/support.c b/src/z80/support.c new file mode 100644 index 00000000..01bbe845 --- /dev/null +++ b/src/z80/support.c @@ -0,0 +1,34 @@ +/** @file z80/support.c + */ +#include "z80.h" +#include + +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 index 00000000..cb519126 --- /dev/null +++ b/src/z80/support.h @@ -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 -- 2.30.2