Update add_align_exponents
This commit is contained in:
1 parent
ab4615bb3e
commit
3c483446be
5 files changed
+23
-178
No files matched your search
@@ -207,7 +207,7 @@ Floating point mathematical routines - not official, but well known and broadly
|
||||
| `$B849` | `add_HALF_FAC1` | DONE | From the Microsoft BASIC, original name: FADDH |
|
||||
| `$B850` | `sub_MEM_FAC1` | DONE | From the Microsoft BASIC, original name: FSUB |
|
||||
| `$B853` | `sub_FAC2_FAC1` | DONE | From the Microsoft BASIC, original name: FSUBT |
|
||||
| `$B862` | `add_align_exponents` | DONE | |
|
||||
| `$B862` | `add_align_exponents` | DONE | From the Microsoft BASIC, original name: FADD5 |
|
||||
| `$B867` | `add_MEM_FAC1` | DONE | |
|
||||
| `$B86A` | `add_FAC2_FAC1` | DONE | |
|
||||
| `$B8D2` | `abs_and_normal_FAC` | DONE | From the Microsoft BASIC, original name: FADFLT |
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - align FAC1 and FAC2 exponents for addition
|
||||
;
|
||||
; See also:
|
||||
; - [CM64] Computes Mapping the Commodore 64 - page 115
|
||||
; - https://www.c64-wiki.com/wiki/BASIC-ROM
|
||||
|
||||
add_align_exponents:
|
||||
|
||||
; XXX assume here none of the exponents is 0, check if this is true for orignal ROMs
|
||||
|
||||
lda FAC1_exponent
|
||||
cmp FAC2_exponent
|
||||
beq add_align_exponents_done ; branch if exponents the same
|
||||
bcs add_align_exponent_FAC2
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
add_align_exponent_FAC1:
|
||||
|
||||
; First check the exponent difference
|
||||
|
||||
lda FAC2_exponent
|
||||
sec
|
||||
sbc FAC1_exponent
|
||||
|
||||
cmp #$28
|
||||
bcs add_align_exponent_FAC1_zero ; branch if difference is very high
|
||||
|
||||
cmp #$08
|
||||
bcc add_align_exponent_FAC1_bit
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
add_align_exponent_FAC1_byte:
|
||||
|
||||
; Add 8 to exponent, divide mantissa by 256
|
||||
|
||||
lda FAC1_exponent
|
||||
clc
|
||||
adc #$08
|
||||
sta FAC1_exponent
|
||||
|
||||
lda FAC1_mantissa+3
|
||||
sta FACOV
|
||||
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 #$00
|
||||
sta FAC1_mantissa+0
|
||||
|
||||
beq add_align_exponent_FAC1 ; branch always - next iteration
|
||||
|
||||
add_align_exponent_FAC1_bit:
|
||||
|
||||
; Increment exponent, divide mantissa by 2
|
||||
|
||||
inc FAC1_exponent
|
||||
|
||||
clc
|
||||
ror FAC1_mantissa+0
|
||||
ror FAC1_mantissa+1
|
||||
ror FAC1_mantissa+2
|
||||
ror FAC1_mantissa+3
|
||||
ror FACOV
|
||||
|
||||
lda FAC1_exponent
|
||||
cmp FAC2_exponent
|
||||
bne add_align_exponent_FAC1_bit ; branch if next iteration needed
|
||||
|
||||
rts
|
||||
|
||||
add_align_exponent_FAC1_zero:
|
||||
|
||||
lda #$00
|
||||
|
||||
sta FAC1_mantissa+0
|
||||
sta FAC1_mantissa+1
|
||||
sta FAC1_mantissa+2
|
||||
sta FAC1_mantissa+3
|
||||
sta FACOV
|
||||
|
||||
lda FAC2_exponent
|
||||
sta FAC1_exponent
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
add_align_exponents_done:
|
||||
|
||||
rts
|
||||
|
||||
|
||||
|
||||
add_align_exponent_FAC2:
|
||||
|
||||
; First check the exponent difference, Carry already set here
|
||||
|
||||
lda FAC1_exponent
|
||||
sbc FAC2_exponent
|
||||
|
||||
cmp #$20
|
||||
bcs add_align_exponent_FAC2_zero ; branch if difference is very high
|
||||
|
||||
cmp #$08
|
||||
bcc add_align_exponent_FAC2_bit
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
add_align_exponent_FAC2_byte:
|
||||
|
||||
; Add 8 to exponent, divide mantissa by 256
|
||||
|
||||
lda FAC2_exponent
|
||||
clc
|
||||
adc #$08
|
||||
sta FAC2_exponent
|
||||
|
||||
lda FAC2_mantissa+2
|
||||
sta FAC2_mantissa+3
|
||||
lda FAC2_mantissa+1
|
||||
sta FAC2_mantissa+2
|
||||
lda FAC2_mantissa+0
|
||||
sta FAC2_mantissa+1
|
||||
lda #$00
|
||||
sta FAC2_mantissa+0
|
||||
|
||||
beq add_align_exponent_FAC2 ; branch always - next iteration
|
||||
|
||||
add_align_exponent_FAC2_bit:
|
||||
|
||||
; Increment exponent, divide mantissa by 2
|
||||
|
||||
inc FAC2_exponent
|
||||
|
||||
clc
|
||||
ror FAC2_mantissa+0
|
||||
ror FAC2_mantissa+1
|
||||
ror FAC2_mantissa+2
|
||||
ror FAC2_mantissa+3
|
||||
|
||||
lda FAC1_exponent
|
||||
cmp FAC2_exponent
|
||||
bne add_align_exponent_FAC2_bit ; branch if next iteration needed
|
||||
|
||||
rts
|
||||
|
||||
|
||||
add_align_exponent_FAC2_zero:
|
||||
|
||||
lda #$00
|
||||
|
||||
sta FAC2_mantissa+0
|
||||
sta FAC2_mantissa+1
|
||||
sta FAC2_mantissa+2
|
||||
sta FAC2_mantissa+3
|
||||
|
||||
lda FAC1_exponent
|
||||
sta FAC2_exponent
|
||||
|
||||
rts
|
||||
@@ -1,9 +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
|
||||
|
||||
|
||||
jmp add_align_exponents
|
||||
@@ -0,0 +1,21 @@
|
||||
;; #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 - align FAC1 and FAC2 exponents for addition
|
||||
;
|
||||
; This is verified to be identical to the original Microsoft implementation where it was named FADD5.
|
||||
;
|
||||
; See also:
|
||||
; - [CM64] Computes Mapping the Commodore 64 - page 115
|
||||
; - https://www.c64-wiki.com/wiki/BASIC-ROM
|
||||
|
||||
add_align_exponents:
|
||||
jsr shiftr_FAC
|
||||
bcc FADD4
|
||||
|
||||
; Fallthrough to add_MEM_FAC1
|
||||
+1
-1
@@ -25,7 +25,7 @@ int phase_mask[MAX_SIZE+MAX_SIZE];
|
||||
unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
|
||||
0xB391, 0xB39D,
|
||||
0xB3A2, 0xB3A5,
|
||||
0xB849, 0xB861,
|
||||
0xB849, 0xB866,
|
||||
0xB8D2, 0xB8D5,
|
||||
0xB947, 0xB97D,
|
||||
0xB983, 0xB9BB,
|
||||
|
||||
Reference in new issue
Block a user