Just to suplement Andrew's excellent explanations.
Fixed point math is no different than ordinary multi-byte math. So if you
have an 8 bit integer and an 8 bit fraction the math is the same as a 16 bit
integer (the values are just effectively divided by 256).
So $0101 = 257, $01.01 = 257/256 = 1 + 1/256
And $FFFF = -1, $FF.FF = -1/256
Now say you only want/need to store the fractional portion, but you want to
add it to an 8.8 fixed point value.
An example which limits the fractional portion to +/- 127/128 since the most
significant bit is the sign. This would be termed "sign extend" on later
CPUs.
clc
lda fracvel
bmi .negvel
adc fracpos
sta fracpos
lda intpos
adc #0
; check for overflow & jump to staint
.negvel
adc fracpos
sta fracpos
lda intpos
adc #-1
; check for underflow & jump to .staint
.staint
sta intpos
Two options to increase the range of fracvel are to shift out the msbit or
invert it. Both options will change the range of values fracvel.
There is also no reason to limit yourself to 8.8 fixed point. If you're
dealing with accelerations you may want to go to 8.16.
----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/