FLOATING POINT PACKAGE

Locations 55296 through 57343 hold the floating point package, a series of routines to do floating point math. For an explanation of how the Atari stores floating point numbers, see VVTP at locations 134 and 135. For information on the floating point registers, see locations 212 through 255. Finally, for information on the input and output buffers see INBUFF at 243 and 244, and LBUFF at 1408 through 1535.

The following is a list of some of the more useful routines in the package. The trigonometric functions are in the BASIC cartridge starting at location 48551.

Note that in routines that use the carry bit (as indicated), if the carry is set at the end of the routine, then an error occurred. If it's clear, then everything is OK.

AFP
55296         D800

This routine takes an ATASCII representation of a number (i.e., "12345") and converts it to floating point (with carry). INBUFF points to the ATASCII number, floating point register zero (FR0) will hold the result.

You may be wondering why such a routine would be needed, and that's a very good thing to wonder. Suppose you had the following line in BASIC:

250 X =3.14159*37.5

lab



When you type in such a line, BASIC sees the numbers as nothing more than a bunch of ATASCII characters. Before it can do the math, it must convert those characters into numbers it can understand. That's what AFP is for. BASIC will use AFP on both numbers (moving one of them to FR1), do the multiplication, and then store the result in X. AFP is also needed for BASIC's STR$ function.

FASC
55526         D8E6

FASC does just the opposite of AFP. It takes a floating point number from FR0 and stores the ATASCII representation in LBUFF. This is necessary when a number needs to be printed on the screen, and also for BASIC's VAL function.

IFP
55722         D9AA

IFP is used to convert integers to floating point. It expects to see the integer in the first two bytes of FR0 (locations 212 and 213) and will store the result in FR0.

FPI
55762         D9D2

This does the exact opposite of IFP (with carry).

ZFR0
55876         DA44

ZFR0 sets all the bytes in FR0 to zero.

ZFI or AFI
55878         DA46

Sets FRx to zero, where x is the value in the X register.

FSUB
55904         DA60

FSUB subtracts FR1 from FR0 (with carry) and stores the result in FR0.

treasure



FADD
55910         DA66

Adds FR1 to FR0 (with carry) and stores the result in FR0 (notice that FADD is actually a part of FSUB).

FMUL
56027         DADB

Multiplies FR0 by FR1 (with carry) and stores the result in FR0.

FDIV
56104         DB28

Divides FR0 by FR1 (with carry) and stores the result in FR0.

PLYEVL
56640         DD40

This one is a little complicated, so bear with me. PLYEVL evaluates a polynomial, such as 5*Z^4+10*Z^2+2*Z+1 (read "five Z to the fourth plus ten Z squared plus two Z plus one"). For the sake of this routine, we'll write such a polynomial as

SUM (I=N to 0) (A(I)*Z^I)

So in the preceding example, N=4, A(0)=1, A(1)=2, A(2)=10, A(3)=0 (since there is no Z cubed), and A(4)=5.

Why are we doing all of this? When you call PLYEVL, it expects you to provide the following information:

Somewhere in memory: a list of the A( ) values, in floating point format (BCD), starting with A(0).

X register: low byte of the starting address of the preceding list.

Y register: high byte of the starting address of the preceding list.

Accumulator: N+1

FR0: Z

PLYEVL will take all of this and use it to evaluate the polynomial (with carry). The result will be stored in FR0.

FLD0R
56713         DD89

FLD0R will load FR0 with the floating point number pointed to by the X and Y registers. X should hold the low byte of the address of this number, Y the high.

FLD0P
56717         DD8D

FLD0P will load FR0 with the floating point number pointed to by FLPTR (252).

FLD1R
56728         DD98

FLD1R will load FR1 with the floating point number pointed to by the X and Y registers. X should hold the low byte of the address of this number, Y the high.

FLD1P
56732         DD9C

FLD1P will load FR1 with the floating point number pointed to by FLPTR (252).

FST0R
56743         DDA7

FST0R will store FR0 in memory, starting at the address pointed to by the X and Y registers. X should hold the low byte of this address, Y the high.

FST0P
56747         DDAB

FST0P will store FR0 in memory, starting at the address pointed to by FLPTR (252).

FMOVE
56758         DDB6

FMOVE moves the floating point number in FR0 to FR1.

EXP
56768         DDCO

EXP raises "e" to the FR0 power and stores the result in FR0 (FR0 = e^FR0).

EXP10
56780         DDCC

EXP10, as you may have guessed, raises 10 to the FR0 power and stores the result in FR0 (FR0= 10^ FR0). Notice that it is actually part of the EXP routine.

LOG
57037         DECD

LOG figures out the natural logarithm (base e) of FR0 and stores it back in FR0.

LOG10
57041         DED1

LOG10 figures out the base 10 logarithm of FR0 and stores it back in FR0. Notice that it is part of the LOG routine.


Return to Table of Contents | Previous Chapter | Next Chapter