I believe you want to use them in assembler.
Assuming you know the floating point format of the C64 and what the
FAC, the ARG, etc. are (if not, just drop me a note), you can use the
following functions:
Name Addr. Const. Prep. FAC changed performs
MEMARG $BA8C A/Y - ARG := constant
FACARG $BBFC + FAC := ARG
DIV $BB12 A = EXP + FAC := ARG / FAC
MEMDIV $BB0F A/Y + FAC := const / FAC
MULT10 $BAE2 + FAC := FAC * 10
DIV10 $BAFE + FAC := FAC / 10
PLUS05 $B849 + FAC := FAC + 0.5
MEMFAC $BBA2 A/Y + FAC := constant
FACARG $BC0C - ARG := FAC
FACMEM $BBD4 X/Y - constant := FAC
MINUS $B853 A = EXP + FAC := ARG - FAC
MEMMIN $B850 A/Y + FAC := constant -
FAC
MULT $BA2B A = EXP + FAC := ARG * FAC
MEMMULT $BA28 A/Y + FAC := constant *
FAC
PLUS $B86A A = EXP + FAC := ARG + FAC
MEMPLUS $B867 A/Y + FAC := constant +
FAC
POWER $BF7B A = EXP + FAC := ARG ^ FAC
POWERMEM $BF78 A/Y + FAC := ARG ^
constant
POLY $E059 A/Y + FAC := polynomial
[1]
POLY2 $E043 A/Y + FAC := polynomial2
[2]
OR $AFE6 + FAC := ARG OR FAC
[3]
AND $AFE9 + FAC := ARG AND FAC
[3]
NOT $AED4 + FAC := NOT FAC
[3]
COMP $BC5B A/Y - compare FAC with
constant [4]
ROUND $BC1B + round FAC
CHRSGN $BFB4 + FAC := -FAC
(taken from Lothar English, "Das Maschinensprache Buch für
Fortgeschrittene
zum Commodore 64", Data Becker, 1984)
[1] the function POLY calculates a polynomial of the form
f(x) = a_n * x^n + a_{n-1} * x^{n-1} + ... + a_1 * x^1 + a_0.
The memory are contains the following information:
1. n, the degree of the polynomial (1 Byte)
2. coefficient a_n
3. coefficient a_{n-1}
...
x. coefficient a_0
[2] the function POLY2 calculates a polynomial of the form
f(x) = a_n * x^{2n+1} + a_{n-1} * x^{2n-1} + ... + a_1 * x^3 + a_0
* x.
The memory are contains the following information:
1. n, the number of coefficents (1 Byte)
2. coefficient a_n
3. coefficient a_{n-1}
...
x. coefficient a_0
[3] with OR, AND and NOT, the arguments (FAC and ARG, if appliable) is
first converted to 16 bit integer, the operation is performed, and
the result if converted back to floating point.
[4] if both values are equal, then the accu (_not_ the FAC!) contains
zero
at termination and Z is 1. If MEM < FAC, then A = $FF and N is set
1.
If MEM > FAC, then A = $01 and N is zero.
The registers mentioned under "constant" contain the address where
that
constant (or, we should say "memory area") is stored.
You might also want to look at the following functions which implement
to corresponding BASIC function:
ABS $BC58
ATN $E30E
COS $E264
EXP $BFED
FRE $B37D
INT $BCCC
LOG $B9EA
POS $B39E
END $E097
SGN $BC39
SIN $E26B
SQR $BF71
TAN $E2B4
If you have any further questions, please feel free to ask.
Spiro.
--
Spiro Trikaliotis
"How do I use the floating-point routines in the C64's ROMs, or do I have
to create my own? Also, how do I perform squares, [cube] roots,
logarithms of a user-specified base and the normal bases (2, 10, e), and
exponents? I need the latter in a step-by-step format I can use off the
computer and on both the C64 and PC. Thanks.'.
I hope that you saw Spiro's reply. If you can get a hold of ANY of the
early Data Becker books (distributed in the USA by Abacus Software), I
strongly recommend that you do so. The routines that Spiro mentioned for
calculating polynomials, are used for the Y^X, SIN, COS, TAN, ATN, LOG, EXP,
and SQR functions. Y^X is done as EXP(X*LOG(Y)), and SQR(Y) is done as Y^0.5.
For the other functions mentioned above, polynomial approximations are used.
Of course the arguments for the trigonometric functions are in radians, and
LOG(X) is the natural (Napierian) logarithm. For cube root of X, you would do
X^(1/3). And for the Nth root, X^(1/N). For logarithm of X to base B, do
LOG(X)/LOG(B).
--
123 456
789 *0#
If you see a telephone keypad above, you're probably using a Commodore 64.
Spiro Trikaliotis wrote:
> Hi Joseph,
>
> On Sat, 18 Mar 2000 18:23:29 -0500, Joseph Rose wrote:
>
> >How do I use the floating-point routines in the C64's ROMs, or do I have
> >to create my own? Also, how do I perform squares, [cube] roots,
> >logarithms of a user-specified base and the normal bases (2, 10, e), and
> >exponents? I need the latter in a step-by-step format I can use off the
> >computer and on both the C64 and PC. Thanks.
>
John Iannetta wrote:
> Joseph Rose <jor...@pop.gis.net> said:
>
> "How do I use the floating-point routines in the C64's ROMs, or do I have
> to create my own? Also, how do I perform squares, [cube] roots,
> logarithms of a user-specified base and the normal bases (2, 10, e), and
> exponents? I need the latter in a step-by-step format I can use off the
> computer and on both the C64 and PC. Thanks.'.
>
> I hope that you saw Spiro's reply. If you can get a hold of ANY of the
> early Data Becker books (distributed in the USA by Abacus Software), I
> strongly recommend that you do so. The routines that Spiro mentioned for
> calculating polynomials, are used for the Y^X, SIN, COS, TAN, ATN, LOG, EXP,
> and SQR functions. Y^X is done as EXP(X*LOG(Y)), and SQR(Y) is done as Y^0.5.
> For the other functions mentioned above, polynomial approximations are used.
> Of course the arguments for the trigonometric functions are in radians, and
> LOG(X) is the natural (Napierian) logarithm. For cube root of X, you would do
> X^(1/3). And for the Nth root, X^(1/N). For logarithm of X to base B, do
> LOG(X)/LOG(B).
> --
> 123 456
> 789 *0#
>
> If you see a telephone keypad above, you're probably using a Commodore 64.
I have SQRT(), SIN and COS, and TAN is SIN/COS. So, how do I do LOG and EXP, and
the arctrig functions? Also, there must be a way to do x^2 without EXP!
>I assume the first 1-bit is left-aligned and not assumed like Intel's design,
>right?
I've been away from this group for some time, so this answer is a
little late.
Well, the first 1-bit is left from the decimal point (is this
left-aligned?). There is no denormalized format (as in IEEE 754). The
first 1 is not stored in memory, it's replaced by the sign of the
number. Notice that this is not true when the value is stored in the
FAC or ARG.
With Intel's design, do you mean the 8087/287, the 387, or the later
ones? The early ones used an intel format, the 387 could use that old
format (I don't know in more detail) or the IEEE 754-format, all newer
(487SX or 486DX and Pentiums, K6, ...) know only the IEEE format. So,
which one did you mean? (BTW: In the early days, there were even a
Microsoft FP format, so there were three formats on PCs to deal with!)
--
Spiro Trikaliotis
>I have SQRT(), SIN and COS, and TAN is SIN/COS. So, how do I do LOG and EXP, and
>the arctrig functions? Also, there must be a way to do x^2 without EXP!
LOG and EXP can be approximated by polynomials (as it is done in the
C64). Look at the ROM routines for the coefficients.
BTW: x^2 can be calculated by x*x (which should be quicker and
possibly more accurate than using EXP).
--
Spiro Trikaliotis