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

+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