Update round_FAC1
This commit is contained in:
1 parent
7a37b76d10
commit
e56e1cf1ac
6 files changed
+37
-75
No files matched your search
@@ -237,7 +237,7 @@ Floating point mathematical routines - not official, but well known and broadly
|
||||
| `$BBFC` | `mov_FAC2_FAC1` | DONE | From the Microsoft BASIC, original name: MOVFA |
|
||||
| `$BC0C` | `mov_r_FAC1_FAC2` | DONE | From the Microsoft BASIC, original name: MOVAF |
|
||||
| `$BC0F` | `mov_FAC1_FAC2` | DONE | From the Microsoft BASIC, original name: MOVEF |
|
||||
| `$BC1B` | `round_FAC1` | PARTIAL | not fully tested yet |
|
||||
| `$BC1B` | `round_FAC1` | DONE | From the Microsoft BASIC, original name: ROUND |
|
||||
| `$BC2B` | `sgn_FAC1_A` | DONE | From the Microsoft BASIC, original name: SIGN |
|
||||
| `$BC39` | `sgn_FAC1` | DONE | From the Microsoft BASIC, original name: SGN |
|
||||
| `$BC3C` | `convert_A_to_FAC1` | DONE | From the Microsoft BASIC, original name: FLOAT |
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
; Just a compatibility jump - our routine is longer than original one
|
||||
|
||||
round_FAC1:
|
||||
jmp round_FAC1_impl
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
|
||||
|
||||
; This file is under the MIT license, it contains code released by Microsoft Corporation.
|
||||
; See LICENSE for more information.
|
||||
|
||||
; Math package - rounds FAC1 before copying
|
||||
;
|
||||
; This is verified to be identical to the original Microsoft implementation where it was named ROUND.
|
||||
;
|
||||
; Alternative entry point: INCRND to increment mantissa and normalize if carry
|
||||
;
|
||||
; See also:
|
||||
; - [CM64] Computes Mapping the Commodore 64 - page 115
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
;
|
||||
|
||||
|
||||
round_FAC1:
|
||||
|
||||
lda FAC1_exponent ; Zero?
|
||||
beq MOVRTS ; Yes. Done rounding
|
||||
asl FACOV ; ROUND?
|
||||
bcc MOVRTS ; No. MSB off.
|
||||
INCRND:
|
||||
jsr inc_FAC1 ; Yes, add one to LSB
|
||||
bne MOVRTS ; No carry means done
|
||||
jmp RNDSHF ; Squeeze MSB in and RTS
|
||||
; CF=1 since inc_FAC1 doesn't touch CF
|
||||
@@ -1,61 +0,0 @@
|
||||
;; #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_FAC1_impl:
|
||||
|
||||
; If number is 0, do not do anything
|
||||
|
||||
lda FAC1_exponent
|
||||
beq round_FAC1_done
|
||||
|
||||
lda FACOV
|
||||
bpl round_FAC1_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_FAC1_zero_FACOV
|
||||
inc FAC1_mantissa+2
|
||||
bne round_FAC1_zero_FACOV
|
||||
inc FAC1_mantissa+1
|
||||
bne round_FAC1_zero_FACOV
|
||||
inc FAC1_mantissa+0
|
||||
bne round_FAC1_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_FAC1_zero_FACOV
|
||||
|
||||
; If we are here, it means the exponent wrapped around to $00; put it back to $FF
|
||||
|
||||
dec FAC1_exponent
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
round_FAC1_zero_FACOV:
|
||||
|
||||
lda #$00
|
||||
sta FACOV
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
round_FAC1_done:
|
||||
|
||||
rts
|
||||
@@ -38,4 +38,5 @@ mov_FAC1_FAC2:
|
||||
dex
|
||||
bne @1
|
||||
stx FACOV ; Always zero
|
||||
MOVRTS:
|
||||
rts
|
||||
+2
-3
@@ -20,7 +20,7 @@ int matches[MAX_SIZE];
|
||||
|
||||
int phase_mask[MAX_SIZE+MAX_SIZE];
|
||||
|
||||
#define NUM_CHUNKS 7
|
||||
#define NUM_CHUNKS 6
|
||||
// Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC
|
||||
unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
|
||||
0xB391, 0xB39D,
|
||||
@@ -28,8 +28,7 @@ unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
|
||||
0xB849, 0xB97D,
|
||||
0xB983, 0xB9BB,
|
||||
0xBA8C, 0xBAB6,
|
||||
0xBB8F, 0xBC1A,
|
||||
0xBC2B, 0xBCF2,
|
||||
0xBB8F, 0xBCF2,
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user