import math
def cbm2float(e, m):
if m==0:
return 0
m2 = (1 + ((m & 0x7FFFFFFF) / 0x80000000))
e2 = (2 ** (e-129))
print (m2, e2)
if m & 0x80000000:
return -(m2 * e2)
else:
return m2 * e2
def float2cbm(f):
if f == 0: return (0, 0)
e = int(math.log(f, 2))
e2 = e + 129
m2 = int(((f / (2 ** e))-1) * 0x80000000)
if f < 0:
return (e2, m2 + 0x80000000)
else:
return (e2, m2)
print(cbm2float(0x84, 0x20000000))
print("%x %x" % float2cbm(10))
print("PI in the C64 rom is at AEA8: $82,$49,$0F,$DA,$A1")
print("PI found by this program is: %x %x" % float2cbm(math.pi))
no subject
Date: 2013-01-15 02:11 am (UTC)no subject
Date: 2013-01-15 07:43 am (UTC)i'm a few days from doing anything of substance with that, though. I'm still trying to get the startup text to display.
no subject
Date: 2013-01-15 01:38 pm (UTC)no subject
Date: 2013-01-16 04:59 pm (UTC)I also figured out how to easily convert an integer to this format:
* set the exponent byte to 0x81 plus the number of bits in your integer
* shift the integer left and subtract 1 from the exponent byte
* repeat the previous step until the first 1 bit falls off the left side
no subject
Date: 2013-01-15 04:01 pm (UTC)no subject
Date: 2013-01-20 08:56 am (UTC)