implemented several simple floating point routines

This commit is contained in:
FeralChild64 committed 2020-02-02 11:04:39 +01:00
1 parent 4673f825af
commit c62f53058e
17 files changed
+227 -28

No files matched your search

-17
View File
@@ -1,17 +0,0 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - copy FAC2 to FAC1
//
// 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
MOVEF:
STUB_IMPLEMENTATION()
File renamed without changes.
+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 mov_r_FAC1_TMP2
File renamed without changes.
+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 mov_r_FAC1_TMP1
+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 - move FAC1 (rounds) to memory variable
//
// Input:
// - FORPNT ($49/$4A) - variable address
//
// See also:
// - https://www.c64-wiki.com/wiki/BASIC-ROM
//
mov_r_FAC1_VAR:
ldy #FORPNT+1
ldx #FORPNT+0
// FALLTROUGH to mov_r_FAC1_MEM
+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
@@ -3,12 +3,11 @@
// #LAYOUT# * * #IGNORE
//
// Math package - copy FAC1 to memory location, rounds if asked
// Math package - copy FAC1 to memory location, do not round
//
// Input:
// - .X - address low byte
// - .Y - address high byte
// - $70 - if MSB is set performs rouding
//
// Output:
// - .A - FAC1 exponent
@@ -18,7 +17,9 @@
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX provide implementation
mov_r_FAC1_MEM:
// Start by rounding FAC1
MOVFM2:
STUB_IMPLEMENTATION()
jsr round_FAC1
jmp mov_FAC1_MEM
+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
+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 mov_FAC2_FAC1
+1 -1
View File
@@ -14,7 +14,7 @@
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
//
movr_FAC1_FAC2:
mov_r_FAC1_FAC2:
// First round FAC1
jsr round_FAC1
+77
View File
@@ -0,0 +1,77 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - copy FAC1 to memory location, do not round
//
// Input:
// - .X - address low byte
// - .Y - address high byte
//
// Output:
// - .A - FAC1 exponent
//
// See also:
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
mov_FAC1_MEM:
// Checked in the available documentation:
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://www.lemon64.com/forum/viewtopic.php?t=67576&sid=d41e77cdddd28d6f9c9d52ce5b4e8dc3
// that $22/$23 (INDEX+0 and INDEX+1) are at least sometimes used for pointer storage.
// Confirmed by experimenting with original ROM that this is the case here too.
sty INDEX+1
stx INDEX+0
ldy #$00
// Copy exponent
lda FAC1_exponent
sta (INDEX), y
beq mov_FAC1_MEM_end // for 0 no need to copy anything more
// Copy first byte of mantissa
iny
lda FAC2_mantissa+3
sta (INDEX), y
// Copy the sign XXX try to optimize this part
lda FAC1_sign
bne !+
lda FAC2_mantissa+3
and #$7F
sta (INDEX), y
!:
// Copy remaining parts of mantissa
iny
lda FAC2_mantissa+2
sta (INDEX), y
iny
lda FAC2_mantissa+1
sta (INDEX), y
iny
lda FAC2_mantissa+0
sta (INDEX), y
// Checked, that mov_FAC1_MEM works on real ROM too (at $BBD7),
// and clears FACOV in a similar way as mov_FAC1_FAC2 does (not surprising)
ldy #$00
sty FACOV
mov_FAC1_MEM_end:
lda FAC1_exponent
rts
+49
View File
@@ -0,0 +1,49 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - copy FAC2 to FAC1
//
// Output (found by experimentation):
// - .A - FAC1 exponent
// - .X - always 0
//
// Preserves:
// - .Y
//
// 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
//
mov_FAC2_FAC1:
// Copy the mantissa
lda FAC2_mantissa+3
sta FAC1_mantissa+3
lda FAC2_mantissa+2
sta FAC1_mantissa+2
lda FAC2_mantissa+1
sta FAC1_mantissa+1
lda FAC2_mantissa+0
sta FAC1_mantissa+0
// Copy the sign
lda FAC2_sign
sta FAC1_sign
// Copy the exponent
lda FAC2_exponent
sta FAC1_exponent
// Clear FACOV
ldx #$00
stx FACOV
rts
+18
View File
@@ -0,0 +1,18 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - store FAC1 (rounds) in TEMPF1
//
// See also:
// - https://www.c64-wiki.com/wiki/BASIC-ROM
// - https://sta.c64.org/cbm64basconv.html
//
mov_r_FAC1_TMP1:
ldy #$00
ldx #$5C
jmp mov_r_FAC1_MEM
+18
View File
@@ -0,0 +1,18 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - store FAC1 (rounds) in TEMPF2
//
// See also:
// - https://www.c64-wiki.com/wiki/BASIC-ROM
// - https://sta.c64.org/cbm64basconv.html
//
mov_r_FAC1_TMP2:
ldy #$00
ldx #$57
jmp mov_r_FAC1_MEM