implemented ROUND math routine, corrected some others
This commit is contained in:
1 parent
f104746ebc
commit
51064f6b70
10 files changed
+84
-8
No files matched your search
@@ -196,6 +196,7 @@ Floating point mathematical routines - not official, but well known and broadly
|
||||
| `$BBD4` | `MOVMF` | NOT DONE | copy FAC1 to memory location, rounds if asked |
|
||||
| `$BBFC` | `MOVEF` | NOT DONE | copy FAC2 to FAC1 |
|
||||
| `$BC0F` | `MOVFA` | NOT DONE | copy FAC1 to FAC2, skips rounding |
|
||||
| `$BC1B` | `ROUND` | PARTIAL | not tested |
|
||||
| `$BC2B` | `SIGN` | NOT DONE | evaluate FAC1 sign |
|
||||
| `$BC39` | `SGN` | NOT DONE | evaluate FAC1 sign, to FAC1 |
|
||||
| `$BC58` | `ABS` | NOT DONE | absolute value |
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
This is an important floating point math routine, documented in many places.
|
||||
|
||||
XXX - try to find real-life example
|
||||
Example code utilizing the routine:
|
||||
- https://www.lemon64.com/forum/viewtopic.php?t=67576&sid=d41e77cdddd28d6f9c9d52ce5b4e8dc3
|
||||
@@ -1,3 +1,4 @@
|
||||
This is an important floating point math routine, documented in many places.
|
||||
|
||||
XXX - try to find real-life example
|
||||
Example code utilizing the routine:
|
||||
- https://www.lemon64.com/forum/viewtopic.php?t=67576&sid=d41e77cdddd28d6f9c9d52ce5b4e8dc3
|
||||
@@ -1,3 +1,4 @@
|
||||
This is an important floating point math routine, documented in many places.
|
||||
|
||||
XXX - try to find real-life example
|
||||
Example code utilizing the routine:
|
||||
- https://www.lemon64.com/forum/viewtopic.php?t=67576&sid=d41e77cdddd28d6f9c9d52ce5b4e8dc3
|
||||
@@ -38,7 +38,7 @@ CONUPK:
|
||||
// Now copy the data from RAM to FAC2, for the format description see:
|
||||
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic#Representation_in_the_C-64
|
||||
|
||||
// Copy the mantissa - reverse byte order
|
||||
// Copy the mantissa
|
||||
|
||||
ldy #$04
|
||||
lda (INDEX), y
|
||||
|
||||
@@ -35,7 +35,7 @@ MOVMF:
|
||||
// Now copy the data from RAM to FAC2, for the format description see:
|
||||
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic#Representation_in_the_C-64
|
||||
|
||||
// Copy the mantissa - reverse byte order
|
||||
// Copy the mantissa
|
||||
|
||||
ldy #$04
|
||||
lda (INDEX), y
|
||||
|
||||
@@ -44,10 +44,10 @@ normal_by_bit:
|
||||
|
||||
clc
|
||||
rol FACOV
|
||||
rol FAC1_mantissa+0
|
||||
rol FAC1_mantissa+1
|
||||
rol FAC1_mantissa+2
|
||||
rol FAC1_mantissa+3
|
||||
rol FAC1_mantissa+2
|
||||
rol FAC1_mantissa+1
|
||||
rol FAC1_mantissa+0
|
||||
|
||||
bcc NORMAL // branch if next iteration needed
|
||||
rts
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// #LAYOUT# STD * #TAKE
|
||||
// #LAYOUT# * BASIC_0 #TAKE
|
||||
// #LAYOUT# * * #IGNORE
|
||||
|
||||
//
|
||||
// Math package - rounds FAC1 before copying
|
||||
//
|
||||
// See also:
|
||||
// - [CM64] Computes Mapping the Commodore 64 - page 115
|
||||
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
//
|
||||
|
||||
// XXX test this
|
||||
|
||||
ROUND:
|
||||
|
||||
// If number is 0, do not do anything
|
||||
|
||||
lda FAC1_exponent
|
||||
beq round_done
|
||||
|
||||
lda FACOV
|
||||
bpl round_zero_FACOV // branch if it is enough to clear FACOV
|
||||
|
||||
// Increment the 4 bytes of matissa
|
||||
|
||||
// Curse you, who invented this format! Had the mantissa been little endian,
|
||||
// we could have used INW on 65C02 and above, the code would have been smaller!
|
||||
|
||||
inc FAC1_mantissa+3
|
||||
bne round_zero_FACOV
|
||||
inc FAC1_mantissa+2
|
||||
bne round_zero_FACOV
|
||||
inc FAC1_mantissa+1
|
||||
bne round_zero_FACOV
|
||||
inc FAC1_mantissa+0
|
||||
bne round_zero_FACOV
|
||||
|
||||
// If we are here, it means mantissa is 0; put it to minimum allowed and increment exponent
|
||||
|
||||
lda #$80
|
||||
sta FAC1_mantissa+0
|
||||
inc FAC1_exponent
|
||||
bne round_zero_FACOV
|
||||
|
||||
// If w are here, it means the exponent wrapped around to $00; put it back to $FF
|
||||
|
||||
dec FAC1_exponent
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
round_zero_FACOV:
|
||||
|
||||
lda #$00
|
||||
sta FACOV
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
round_done:
|
||||
|
||||
rts
|
||||
@@ -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 ROUND
|
||||
@@ -0,0 +1,4 @@
|
||||
This is an important floating point math routine, documented in many places.
|
||||
|
||||
Example code utilizing the routine:
|
||||
- https://www.lemon64.com/forum/viewtopic.php?t=67576&sid=d41e77cdddd28d6f9c9d52ce5b4e8dc3
|
||||
Reference in new issue
Block a user