The floating point package reference

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

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

Mnemonic

Function Index Number

Function Code

Functionality

Description

FP_AND

0

$21

Bitwise logical AND

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

FP_IDV

1

$24

Quotient after division

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

FP_EOR

2

$27

Bitwise logical excusive OR

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

FP_MOD

3

$2A

Remainder after division

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

FP_OR

4

$2D

Bitwise logical OR

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

FP_LEQ

5

$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_NEQ

6

$33

Test for not equal to

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

FP_GEQ

7

$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_LT

8

$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_EQ

9

$3C

Test for equality

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

FP_MUL

10

$3F

Multiplication

Input parameters in HLhlC and DEdeB. Result in HLhlC.

FP_ADD

11

$42

Addition

Input parameters in HLhlC and DEdeB. Result in HLhlC.

FP_GT

12

$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_SUB

13

$48

Subtraction

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

FP_PWR

14

$4B

Raise to power

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

FP_DIV

15

$4E

Division

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

FP_ABS

16

$51

Magnitude (ABSolute value)

Input parameters in HLhlC. Result in HLhlC.

FP_ACS

17

$54

Inverse cosine (Arc CoSine)

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

FP_ASN

18

$57

Inverse sine (Arc SiNe)

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

FP_ATN

19

$5A

Inverse tangent (Arc TaNgent)

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

FP_COS

20

$5D

Cosine

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

FP_DEG

21

$60

Convert radians to degrees

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

FP_EXP

22

$63

Exponentiation

Raise 'e' [2.718...] to power of. Input parameters in HLhlC. Result in HLhlC.

FP_INT

23

$66

Integer truncation

(floor truncation, not rounding) Input parameters in HLhlC. Result in HLhlC.

FP_LN

24

$69

Natural logarithm

(Naperian or base 'e') Input parameters in HLhlC. Result in HLhlC.

FP_LOG

25

$6C

Common (base 10) logarithm

Input parameters in HLhlC. Result in HLhlC.

FP_NOT

26

$6F

Bitwise logical NOT

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

FP_RAD

27

$72

Convert degrees to radians

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

FP_SGN

28

$75

Sign (signum)

Input parameters in HLhlC. Result in HLhlC.

FP_SIN

29

$78

Sine

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

FP_SQR

30

$7B

Square root

Input parameters in HLhlC. Result in HLhlC.

FP_TAN

31

$7E

Tangent

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

FP_ZER

32

$81

Return the constant zero

(as an integer) Input irrelevant. Result in HLhlC (all zero).

FP_ONE

33

$84

Return the floating point constant 1

Input irrelevant. Result in HLhlC (HL=hl=0, C=$80)

FP_TRU

34

$87

Return the integer constant -1

Input irrelevant. Result in HLhlC (HL=hl=$FFFF, C=$00)

FP_PI

35

$8A

Returns pi

(the floating point representation of pi) Input irrelevant. Result in HLhlC.

FP_VAL

36

$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_STR

37

$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_FIX

38

$93

Round a number to integer

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

FP_FLT

39

$96

Convert from integer to floating point

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

FP_TST

40

$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_CMP

41

$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_NEG

42

$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