The floating point package reference
The floating point package (hereinafter referred to as the FPP) uses a different RST call from the main system calls, the format of a floating point call is as follows:
RST $18
DEFB <function code>
so apart from the different restart number, much the same as the OS calls. In the text we will assume a macro has been defined and use the following:
FPP <function mnemonic>
Parameters are passed to and from the FPP in a rather bizarre collection of registers. The main register group is HLhlC (remember, lower case for alternate set), and where a second parameter is required it is passed in DEdeB. These divide into mantissa and exponent as follows:
Parameter 1 | Parameter 2 | Significance |
|---|---|---|
H | D | Most significant byte of mantissa |
L | E |
|
h | d |
|
l | e | Least significant byte of mantissa |
C | B | Exponent byte |
There are certain exceptions, which are explained where relevant (for instance one operation returns the numeric value of a string, so takes a pointer to the string in HL as its parameter). Here is the full list of parameter bytes and the FPP functions which they invoke. First number is the index number of the operation for FP_BAS. Second number is the RST 18H function code:
Mnemonic | Function Index Number | Function Code | Functionality | Description |
|---|---|---|---|---|
FP_AND | 0 | $21 |
| (Integer only) Input parameters in HLhlC and DEdeB. Result in HLhlC. |
FP_IDV | 1 | $24 |
| (Integer only) Input parameters in HLhlC and DEdeB (returns HLhlC / DEdeB). Result in HLhlC. |
FP_EOR | 2 | $27 |
| (Integer only) Input parameters in HLhlC and DEdeB. Result in HLhlC. |
FP_MOD | 3 | $2A |
| (Integer only) Input parameters in HLhlC and DEdeB (returns the remainder of HLhlC / DEdeB). Result in HLhlC. |
FP_OR | 4 | $2D |
| (Integer only) Input parameters in HLhlC and DEdeB. Result in HLhlC. |
FP_LEQ | 5 | $30 |
| Input parameters in HLhlC and DEdeB (test is HLhlC <= DEdeB). Result in HLhlC (-1 for TRUE; 0 for FALSE). |
FP_NEQ | 6 | $33 |
| Input parameters in HLhlC and DEdeB. Result in HLhlC (-1 for TRUE; 0 for FALSE). |
FP_GEQ | 7 | $36 |
| Input parameters in HLhlC and DEdeB (test is HLhlC >= DEdeB). Result in HLhlC (-1 for TRUE; 0 for FALSE). |
FP_LT | 8 | $39 |
| Input parameters in HLhlC and DEdeB (test is HLhlC < DEdeB). Result in HLhlC (-1 for TRUE; 0 for FALSE). |
FP_EQ | 9 | $3C |
| Input parameters in HLhlC and DEdeB. Result in HLhlC (-1 for TRUE; 0 for FALSE). |
FP_MUL | 10 | $3F |
| Input parameters in HLhlC and DEdeB. Result in HLhlC. |
FP_ADD | 11 | $42 |
| Input parameters in HLhlC and DEdeB. Result in HLhlC. |
FP_GT | 12 | $45 |
| Input parameters in HLhlC and DEdeB (test is HLhlC > DEdeB). Result in HLhlC (-1 for TRUE; 0 for FALSE). |
FP_SUB | 13 | $48 |
| Input parameters in HLhlC and DEdeB (returns HLhlC - DEdeB). Result in HLhlC. |
FP_PWR | 14 | $4B |
| Input parameters in HLhlC and DEdeB (returns HLhlC ^ DEdeB). Result in HLhlC. |
FP_DIV | 15 | $4E |
| Input parameters in HLhlC and DEdeB (returns HLhlC / DEdeB). Result in HLhlC. |
FP_ABS | 16 | $51 |
| Input parameters in HLhlC. Result in HLhlC. |
FP_ACS | 17 | $54 |
| Input parameters in HLhlC. Result in HLhlC, in radians. |
FP_ASN | 18 | $57 |
| Input parameters in HLhlC. Result in HLhlC, in radians. |
FP_ATN | 19 | $5A |
| Input parameters in HLhlC. Result in HLhlC, in radians. |
FP_COS | 20 | $5D |
| Input parameters in HLhlC, in radians. Result in HLhlC. |
FP_DEG | 21 | $60 |
| Input parameters in HLhlC, in radians. Result in HLhlC, in degrees. |
FP_EXP | 22 | $63 |
| Raise 'e' [2.718...] to power of. Input parameters in HLhlC. Result in HLhlC. |
FP_INT | 23 | $66 |
| (floor truncation, not rounding) Input parameters in HLhlC. Result in HLhlC. |
FP_LN | 24 | $69 |
| (Naperian or base 'e') Input parameters in HLhlC. Result in HLhlC. |
FP_LOG | 25 | $6C |
| Input parameters in HLhlC. Result in HLhlC. |
FP_NOT | 26 | $6F |
| (Integer only) Input parameters in HLhlC. Result in HLhlC. |
FP_RAD | 27 | $72 |
| Input parameters in HLhlC, in degrees. Result in HLhlC, in radians. |
FP_SGN | 28 | $75 |
| Input parameters in HLhlC. Result in HLhlC. |
FP_SIN | 29 | $78 |
| Input parameters in HLhlC, in radians. Result in HLhlC. |
FP_SQR | 30 | $7B |
| Input parameters in HLhlC. Result in HLhlC. |
FP_TAN | 31 | $7E |
| Input parameters in HLhlC, in radians. Result in HLhlC. |
FP_ZER | 32 | $81 |
| (as an integer) Input irrelevant. Result in HLhlC (all zero). |
FP_ONE | 33 | $84 |
| Input irrelevant. Result in HLhlC (HL=hl=0, C=$80) |
FP_TRU | 34 | $87 |
| Input irrelevant. Result in HLhlC (HL=hl=$FFFF, C=$00) |
FP_PI | 35 | $8A |
| (the floating point representation of pi) Input irrelevant. Result in HLhlC. |
FP_VAL | 36 | $8D |
| HL points to start of string (null-terminated). Result in HLhlC, and DE points to last character read; if the call succeeded, this will be the terminator byte. If the call failed, HLhlC = 0. |
FP_STR | 37 | $90 |
| Number to convert to string, in in HLhlC. DE points to space to insert string. DE points to character after string when call returns. The de (alternate) register pair contains a format control variable which has the effect of the two middle bytes of the BBC BASIC format control variable @%:
|
FP_FIX | 38 | $93 |
| Input parameters in HLhlC (the call has no effect with C=0). Result in HLhlC. |
FP_FLT | 39 | $96 |
| Input parameters in HLhlC (the call has no effect with C<>0). Result in HLhlC. |
FP_TST | 40 | $99 |
| Input parameters in HLhlC. Result in A (0 for zero; $40 for positive; $C0 for negative). |
FP_CMP | 41 | $9C |
| Input parameters in HLhlC (left) and DEdeB (right). Result in A:
|
FP_NEG | 42 | $9F |
| Input parameters in HLhlC. Result in HLhlC. |
FP_BAS |
| $A2 |
| Perform one of the above functions using the operation index number in A, eg.:
should call FP_ONE and return 1 (floating point). This facility can be useful if the operation depends on some parameter, to avoid writing selfmodifying code. |