SuperH-based fx calculators
fx legacy: Number format

The format used by the calculator to store values.

The Alpha_GetData() function returns parts of its data in this format;
Floating point values are BCD encoded; 3 digits for exponent (100-biased), and 15 digits for the mantissa. Three byte seem to be used as some status bytes.
The structure consists of two 12-byte-values (real and imaginary, as the case may be).
You have to subtract 100 from the exponent, if you want to yield the real value. F. i. 100 = 0; 098 = -2 a.s.o..
If the mantissa is negative, 500 is added to the exponent.
Examples:
600123000000000000xxxxxx = -1.23
100230400000000000xxxxxx = 2.304
098456000000000000xxxxxx = 0.0456
597786000000000000xxxxxx = -0.00786

Fractions are stored using another format.
It starts with the sign-nibble (1=positive;6=negative), followed by the digit "A".
The next digit represents the length of the number minus one.
The number has the form a b/c, irrespective of Setup(0x57).
The parts a, b and c are BCD-coded and separated by the digit "A".

Examples:
6A62A33A5000000000xxxxxx = -2 33/50
1A62A33A5000000000xxxxxx = 2 33/50

System calls

0x4F0: int BCD_ToStrAsNumber0(char *data, char *string);
Converts to a number format. Based on syscall 0x4F7.
long zero = 0;
Num_DataToStr(data, string, &zero);
0x4F5: int BCD_ToStrAsNumber1(char *data, char *string);
Converts to a number format. Based on syscall 0x510.
0x4F6: int BCD_ToStrAsNumber2(char *data, char *string);
Converts to a number format. Based on syscall 0x510.
0x4F7: Num_DataToStr(char *data, char *string, int *unkown);

Can be used to convert the data retrieved by Alpha_GetData(), into a string. The meaning of unknown is.. unknown.
The function heeds for setup-entries 0x2B (number display format) and 0x17 (dec/hex/oct/bin). Hence it can be used as a syscall-based formatting function to replace the code consuming standard-library routines.
syscall-based BCD/double converters are not yet found. So this has to be provided for.

0x4F8: Num_DataToStrAsFrac(char *data, char *string);
Converts a BCD-value into a string using the frac-format. Setup-entry 0x57 controls the format.
0x4FA: Num_DataToStr_VARIANT5(char *data, char *string);
Converts to an angle format. Based on syscall 0x4F7.
 
long five = 5;
Num_DataToStr(data, string, &five);
0x500: int BCDtoInternal( TBCDinternal *target, TBCDvalue *source );

Can be used to convert a standard BCD-value into a special internal format, which helps saving code when converting a BCD-value to C-double.
Returns -1 on error, else returns 0.

(12.05.2012 15:22:50)