implemented NORMAL math routine, added more stubs

This commit is contained in:
FeralChild64 committed 2020-01-30 21:26:01 +01:00
1 parent 4de080cd90
commit 1b300aa39b
31 files changed
+414 -14

No files matched your search

+14 -12
View File
@@ -177,13 +177,14 @@ Floating point mathematical routines - not official, but well known and broadly
| Address | Name | Status | Remarks |
| :-------: | :----------- | :------: | :------------------------------------------------: |
| `$B1AA` | `FACINX` | NOT DONE | convert FAC1 to 16-bit signed integer |
| `$B391` | `GIVAYF` | NOT DONE | XXX - no stub added yet |
| `$B7B5` | `STRVAL` | NOT DONE | XXX - no stub added yet |
| `$B391` | `GIVAYF` | NOT DONE | 16-bit signed integer to FAC1 |
| `$B7B5` | `STRVAL` | NOT DONE | imports string to FAC1 |
| `$B850` | `FSUB` | PARTIAL | needs `FSUBT` |
| `$B853` | `FSUBT` | NOT DONE | subtract FAC1 from FAC2 |
| `$B867` | `FADD` | PARTIAL | needs `FADDT` |
| `$B86A` | `FADDT` | NOT DONE | add FAC2 to FAC1 |
| `$B9EA` | `LOG` | NOT DONE | XXX - no stub added yet |
| `$B8FE` | `NORMAL` | PARTIAL | not tested yet |
| `$B9EA` | `LOG` | NOT DONE | natural logarigthm |
| `$BA28` | `FMUL` | PARTIAL | needs `FMULT` |
| `$BA2B` | `FMULT` | NOT DONE | multiplies FAC1 by FAC2 |
| `$BA8C` | `CONUPK` | PARTIAL | not fully tested yet |
@@ -196,24 +197,25 @@ Floating point mathematical routines - not official, but well known and broadly
| `$BBFC` | `MOVEF` | NOT DONE | copy FAC2 to FAC1 |
| `$BC0F` | `MOVFA` | NOT DONE | copy FAC1 to FAC2, skips rounding |
| `$BC2B` | `SIGN` | NOT DONE | evaluate FAC1 sign |
| `$BC39` | `SGN` | NOT DONE | XXX - no stub added yet |
| `$BC58` | `ABS` | NOT DONE | XXX - no stub added yet |
| `$BC39` | `SGN` | NOT DONE | evaluate FAC1 sign, to FAC1 |
| `$BC58` | `ABS` | NOT DONE | absolute value |
| `$BC5B` | `FCOMP` | NOT DONE | compare FAC1 with RAM location |
| `$BC9B` | `QINT` | NOT DONE | XXX - no stub added yet |
| `$BCCC` | `INT` | NOT DONE | XXX - no stub added yet |
| `$BCF3` | `FIN` | NOT DONE | XXX - no stub added yet |
| `$BDDD` | `FOUT` | NOT DONE | XXX - no stub added yet |
| `$BF71` | `SQR` | NOT DONE | XXX - no stub added yet |
| `$BC9B` | `QINT` | NOT DONE | convert FAC1 to 32 bit signed integer |
| `$BCCC` | `INT` | NOT DONE | rounds away the decimal to make an integer |
| `$BCF3` | `FIN` | NOT DONE | imports string to FAC1, ignores spaces |
| `$BDDD` | `FOUT` | NOT DONE | outputs FAC1 to string at $0100 |
| `$BF71` | `SQR` | NOT DONE | square root of FAC1 |
| `$BF74` | `SQR2` | NOT DONE | square root of FAC2 |
| `$BF78` | `FPWR` | NOT DONE | set FAC1 as RAM raised to the power of FAC1 |
| `$BF7B` | `FPWRT` | NOT DONE | set FAC1 as FAC2 raised to the power of FAC1 |
| `$BFB4` | `NEGOP` | DONE | |
| `$BFED` | `EXP` | NOT DONE | XXX - no stub added yet |
| `$BFED` | `EXP` | NOT DONE | exponential function, e raised to FAC1 power |
| `$E043` | `POLY1` | NOT DONE | evaluate polynomial with odd powers only |
| `$E059` | `POLY2` | NOT DONE | evaluate polynomial with odd and even powers |
| `$E264` | `COS` | NOT DONE | cosine of FAC1 in radians |
| `$E26B` | `SIN` | NOT DONE | sine of FAC1 in radians |
| `$E2B4` | `TAN` | NOT DONE | tangent of FAC1 in radians |
| `$E30E` | `ATN` | NOT DONE | XXX - no stub added yet |
| `$E30E` | `ATN` | NOT DONE | arc tangent of FAC1 |
<br />
+20
View File
@@ -0,0 +1,20 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - 16-bit signed integer to FAC1
//
// Output:
// - .A - address high byte (XXX really, not the opposite?)
// - .Y - address low byte
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 107
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
//
// XXX provide implementation
GIVAYF:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+19
View File
@@ -0,0 +1,19 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - imports string to FAC1 - XXX: what about spaces?
//
// Input:
// - .A needs to be loaded with string length
// - string address in $22/$23
//
// See also:
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
//
// XXX provide implementation
STRVAL:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+18
View File
@@ -0,0 +1,18 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - natural logarigthm
//
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 113
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
LOG:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+2 -2
View File
@@ -3,10 +3,10 @@
// #LAYOUT# * * #IGNORE
//
// Math package - evaluate FAC1 sign
// Math package - evaluate FAC1 sign, to .A
//
// Output:
// - .A - $00 for equal, $01 for FAC1 > RAM, $FF for FAC1 < RAM
// - .A - 0 for FAC1 equal 0, 1 for FAC1 > 0, -1 for FAC1 < 0
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 115
+20
View File
@@ -0,0 +1,20 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - evaluate FAC1 sign, to FAC1
//
// Output:
// - FAC1 - 0 for FAC1 equal 0, 1 for FAC1 > 0, -1 for FAC1 < 0
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 115
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
SGN:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+17
View File
@@ -0,0 +1,17 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - absolute value
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 115
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
ABS:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+19
View File
@@ -0,0 +1,19 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - convert FAC1 to 32 bit signed integer
//
// Output:
// - $62-$65, big-endian order
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 115
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
//
// XXX provide implementation
QINT:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+17
View File
@@ -0,0 +1,17 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - rounds away the decimal to make an integer
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 116
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
INT:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+23
View File
@@ -0,0 +1,23 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - imports string to FAC1, ignores spaces
//
//
// Input:
// - .A needs to be loaded with first char of the string
// - Carry flag must be clear
// - string address in $7A/$7B
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 116
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
FIN:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+21
View File
@@ -0,0 +1,21 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - outputs FAC1 to string at $0100
//
// Output:
// - .A - address low byte
// - .Y - address high byte
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 116
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
FOUT:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+20
View File
@@ -0,0 +1,20 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - square root of FAC1
//
// Note:
// - transfers FAC1 to FAC2 and falls through to SQR2
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 117
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
SQR:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+20
View File
@@ -0,0 +1,20 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - square root of FAC2
//
// Note:
// - loads .5 into FAC1 and falling through to the exponentiation routine
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 117
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
SQR2:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+18
View File
@@ -0,0 +1,18 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - exponential function, e raised to FAC1 power
//
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 117
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
EXP:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+17
View File
@@ -0,0 +1,17 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - arc tangent of FAC1
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 211
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
ATN:
STUB_IMPLEMENTATION()
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example
+100
View File
@@ -0,0 +1,100 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - normalize FAC1
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 113
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX test this
NORMAL:
lda FAC1_exponent
beq normal_end // branch if our float is 0
lda FAC1_mantissa+3
beq normal_by_byte // branch if we can move the whole byte
and #$80
bne normal_end // branch if already normalized
// FALLTROUGH
normal_by_bit:
// First check the current exponent
lda FAC1_exponent
cmp #$01
bne !+
// Exponent is 1 - just mark the whole number as 0 and finish
lda #$00
sta FAC1_exponent
rts
!:
// Multiply the mantissa by 2
clc
rol FACOV
rol FAC1_mantissa+0
rol FAC1_mantissa+1
rol FAC1_mantissa+2
rol FAC1_mantissa+3
bcc NORMAL // branch if next iteration needed
rts
normal_by_byte:
// First decrement the exponent by 8, but not below 0
lda FAC1_exponent
sec
sbc #$08
bcs !+
lda #$00
!:
sta FAC1_exponent
beq normal_end // branch if our float reached 0
// Now multiply the mantissa by 8 by moving the whole bytes
lda FAC1_mantissa+2
sta FAC1_mantissa+3
lda FAC1_mantissa+1
sta FAC1_mantissa+2
lda FAC1_mantissa+0
sta FAC1_mantissa+1
lda FACOV
sta FAC1_mantissa+0
lda #$00
sta FACOV
// Now check if mantissa is not 0
ora FAC1_mantissa+0
ora FAC1_mantissa+1
ora FAC1_mantissa+2
ora FAC1_mantissa+3
bne NORMAL // not 0 - branch to next iteration
// Our mantissa reached 0 - mark exponent as 0 and finish
sta FAC1_exponent
// FALLTROUGH
normal_end:
rts
+7
View File
@@ -0,0 +1,7 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
// Just a compatibility jump - our routine is longer than original one
jmp NORMAL
+3
View File
@@ -0,0 +1,3 @@
This is an important floating point math routine, documented in many places.
XXX - try to find real-life example