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 1Parameter 2Significance
HDMost significant byte of mantissa
LE 
hd 
leLeast significant byte of mantissa
CBExponent 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:

 

MnemonicFunction Index NumberFunction CodeFunctionalityDescription
FP_AND0$21
Bitwise logical AND

(Integer only) Input parameters in HLhlC and DEdeB. Result in HLhlC.

FP_IDV1$24
Quotient after division

(Integer only) Input parameters in HLhlC and DEdeB (returns HLhlC / DEdeB). Result in HLhlC.

FP_EOR2$27
Bitwise logical excusive OR
(Integer only) Input parameters in HLhlC and DEdeB. Result in HLhlC.
FP_MOD3$2A
Remainder after division

(Integer only) Input parameters in HLhlC and DEdeB (returns the remainder of HLhlC / DEdeB). Result in HLhlC.

FP_OR4$2D
Bitwise logical OR
(Integer only) Input parameters in HLhlC and DEdeB. Result in HLhlC.
FP_LEQ5$30
Test for less than or equal to

Input parameters in HLhlC and DEdeB (test is HLhlC <= DEdeB). Result in HLhlC (-1 for TRUE; 0 for FALSE).

FP_NEQ6$33
Test for not equal to

Input parameters in HLhlC and DEdeB. Result in HLhlC (-1 for TRUE; 0 for FALSE).

FP_GEQ7$36
Test for greater than or equal to

Input parameters in HLhlC and DEdeB (test is HLhlC >= DEdeB). Result in HLhlC (-1 for TRUE; 0 for FALSE).

FP_LT8$39
Test for less than

Input parameters in HLhlC and DEdeB (test is HLhlC < DEdeB). Result in HLhlC (-1 for TRUE; 0 for FALSE).

FP_EQ9$3C
Test for equality

Input parameters in HLhlC and DEdeB. Result in HLhlC (-1 for TRUE; 0 for FALSE).

FP_MUL10$3F
Multiplication
Input parameters in HLhlC and DEdeB. Result in HLhlC.
FP_ADD11$42
Addition
Input parameters in HLhlC and DEdeB. Result in HLhlC.
FP_GT12$45
Test for greater than

Input parameters in HLhlC and DEdeB (test is HLhlC > DEdeB). Result in HLhlC (-1 for TRUE; 0 for FALSE).

FP_SUB13$48
Subtraction

Input parameters in HLhlC and DEdeB (returns HLhlC - DEdeB). Result in HLhlC.

FP_PWR14$4B
Raise to power

Input parameters in HLhlC and DEdeB (returns HLhlC ^ DEdeB). Result in HLhlC.

FP_DIV15$4E
Division

Input parameters in HLhlC and DEdeB (returns HLhlC / DEdeB). Result in HLhlC.

FP_ABS16$51
Magnitude (ABSolute value)
Input parameters in HLhlC. Result in HLhlC.
FP_ACS17$54
Inverse cosine (Arc CoSine)
Input parameters in HLhlC. Result in HLhlC, in radians.
FP_ASN18$57
Inverse sine (Arc SiNe)
Input parameters in HLhlC. Result in HLhlC, in radians.
FP_ATN19$5A
Inverse tangent (Arc TaNgent)
Input parameters in HLhlC. Result in HLhlC, in radians.
FP_COS20$5D
Cosine
Input parameters in HLhlC, in radians. Result in HLhlC.
FP_DEG21$60
Convert radians to degrees

Input parameters in HLhlC, in radians. Result in HLhlC, in degrees.

FP_EXP22$63
Exponentiation
Raise 'e' [2.718...] to power of. Input parameters in HLhlC. Result in HLhlC.
FP_INT23$66
Integer truncation
(floor truncation, not rounding) Input parameters in HLhlC. Result in HLhlC.
FP_LN24$69
Natural logarithm
(Naperian or base 'e') Input parameters in HLhlC. Result in HLhlC.
FP_LOG25$6C
Common (base 10) logarithm
Input parameters in HLhlC. Result in HLhlC.
FP_NOT26$6F
Bitwise logical NOT
(Integer only) Input parameters in HLhlC. Result in HLhlC.
FP_RAD27$72
Convert degrees to radians

Input parameters in HLhlC, in degrees. Result in HLhlC, in radians.

FP_SGN28$75
Sign (signum)
Input parameters in HLhlC. Result in HLhlC.
FP_SIN29$78
Sine
Input parameters in HLhlC, in radians. Result in HLhlC.
FP_SQR30$7B
Square root
Input parameters in HLhlC. Result in HLhlC.
FP_TAN31$7E
Tangent
Input parameters in HLhlC, in radians. Result in HLhlC.
FP_ZER32$81
Return the constant zero
(as an integer) Input irrelevant. Result in HLhlC (all zero).
FP_ONE33$84
Return the floating point constant 1
Input irrelevant. Result in HLhlC (HL=hl=0, C=$80)
FP_TRU34$87
Return the integer constant -1
Input irrelevant. Result in HLhlC (HL=hl=$FFFF, C=$00)
FP_PI35$8A
Returns pi
(the floating point representation of pi) Input irrelevant. Result in HLhlC.
FP_VAL36$8D
Returns the numeric value of a string

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_STR37$90
Return string representation of number

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 @%:

  1. The contents of e determine the maximum number of digits (ie. number of characters apart from decimal point or 'E') to be printed. The allowed range of values depends on the format selected (see below):
    1. General format
      1. Exponential format: 1-255 (leading zeros added beyond the 10th significant figure).
      2. Fixed format: 0-10 (in this case the number of digits printed after the decimal point).
  2. The contents of d determine the format of the resultant string for a given number; the options are:
    1. d=0: General format
      1. Integers are printed without a decimal point or exponent. Numbers between 0.1 and 1 will be printed with a decimal point but no exponent. Numbers less than 0.1 will be printed with a decimal point and exponent. Numbers greater than 1 will be printed without exponent unless this would involve more digits than allowed by the contents of the 'e' register (se above), and outside this range, will be printed with an exponent.
    2. d=1: Exponential format
      1. All numbers printed in exponential notation, eg. 1.0E0.
    3. d=2: Fixed format
      1. All numbers are printed with a fixed number of decimal places.
FP_FIX38$93
Round a number to integer

Input parameters in HLhlC (the call has no effect with C=0). Result in HLhlC.

FP_FLT39$96
Convert from integer to floating point

Input parameters in HLhlC (the call has no effect with C<>0). Result in HLhlC.

FP_TST40$99
Test a number for zero and sign

Input parameters in HLhlC. Result in A (0 for zero; $40 for positive; $C0 for negative).

FP_CMP41$9C
Compare two numeric values

Input parameters in HLhlC (left) and DEdeB (right). Result in A:

  • 0 if HLhlC = DEdeB.
  • $40 if HLhlC > DEdeB.
  • $C0 if HLhlC < DEdeB.
FP_NEG42$9F
Negate number, ie. result = -input
Input parameters in HLhlC. Result in HLhlC.
FP_BAS $A2
Execute operation using index number

Perform one of the above functions using the operation index number in A, eg.:

ld  a, 33
fpp FP_BAS

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.

web analytics