Re: A82: OP1 stuff, I guess


[Prev][Next][Index][Thread]

Re: A82: OP1 stuff, I guess




>Is it possible to store a decimal to the OP things?

Yep.  I'll have to explain the format of the OP vars, however.  It's really
much simpler than you'd expect, since it's binary coded decimal and not
something annoying like IEEE.  The OP vars are 11 bytes so that any type
of variable's name can be stored in OP1. I don't see why 11, but that's what
they use.  The format is basically this:

00 80 12 34 56 78 90 00 00 00 00
^  ^  ^                    ^ Extended digits (used only rarely)
|  |  |- Mantissa
|  |- Biased exponent
|- Sign/type byte

Extended digits: These digits are only used in intermittent results are part
of some complex calculations.  However, these digits are not stored in
variables so they really don't make much of a difference...

Mantissa: Binary coded decimal - the hex digits represent decimal digits.
In the op data above, the mantissa is 1.23456789000.  The decimal point is
assumed to be always after the first digit of the mantissa (basically numbers
are ALWAYS in scientific notation).  If the first digit is 0, the whole thing
is assumed to be zero regardless of additional digits and the exponent.  For
numbers like .000000001 you'd basically use 1.0000000000000 with -9 as the
exponent.  (Special note: you can do weird things if you have hex numbers A-F
in floating point numbers.)

Biased exponent: Biased just refers to how it's encoded.  It's not difficult,
though.  This value is NOT binary coded decimal - it's a normal 8 bit value.
It represents the power of *10* to multiply by.  $80 is 0.  That means that
$90 is 16 and $7D is -3 and stuff like that.  In other words, add $80 to the
exponent to get the value for this.  (Special note: You can use exponents
higher than 99 and lower than -99 with this system, and the system will work
correctly with these numbers.  However, most calculations will error (IE
display an error message) if the end result is out of range.  This is NOT
good for crash because of relocation, so don't let this happen.)

Sign/type: For floating point numbers on the 82 (but not other calcs), this
number is either $00 or $80.  $00 = positive mantissa, $80 = negative
mantissa.  (Special note: Because they didn't fully remove complex number
support from the 82, it may be possible to use this byte to set the complex
mode bit.  Since it's not fully supported, don't do this.  Also, the reason
it's called type is because this byte is used for var names as well. It uses
this byte to determine whether the register contains a var name or a real
number).

For real vars stored in memory, the format is the same, except the extra
digit bytes are not there.

-- Barubary