Tool to convert between Motorola FFP and IEEE754 float formats?

Philip Pemberton classiccmp at philpem.me.uk
Sun Feb 14 19:47:38 CST 2016


On 14/02/16 23:56, Philip Pemberton wrote:
> Hi,
> 
> Does anyone know of a tool which can convert between Motorola's FFP
> (Fast Floating Point) float format and IEEE754?
> 
> I'm trying to reverse-engineer some ancient 68k code which uses the FFP
> library, but a load of the floating point constants have been hard-coded
> as hex constants, which is making things hard to interpret...
> 
> I've tried to convert the 68k assembler in FFPIEEE.SA to C, but I must
> have missed something because it just isn't working...


Naturally, I figured out what I was doing wrong an hour or so after I
hit send...

Enjoy!

// val is a FFP float, returns IEEE float format
// basically a direct conversion of the motorola FFPTIEEE function.
// comments are from there.
// you are not expected to understand this horrendous mess.
float ffpieee(const uint32_t val)
{
	uint32_t x = val;
	union {
		float f;
		uint32_t i;
	} _fcast;

	x = x + x;		// delete mantissa high bit
	if (x == 0) {
		// if zero, branch zero as finished
		return (float)x;
	}

	uint8_t k = x & 0xff;

	k ^= 0x80;	// to two's complement exponent
	k >>= 1;	// form 8-bit exponent
	k -= 0x82;	// adjust 64 to 127 and excessize

	x = (x & ~0xff) | k;

	x = (x << 16) | (x >> 16);	// swap for high byte placement
	x <<= 7;	// set sign+exp in high byte

	_fcast.i = x;

	return _fcast.f;
}




-- 
Phil.
classiccmp at philpem.me.uk
http://www.philpem.me.uk/


More information about the cctalk mailing list