added FAC1 denormalization code, for division

This commit is contained in:
FeralChild64 committed 2020-03-03 19:37:56 +01:00
1 parent b346cc85c5
commit 998807c078
3 files changed
+71 -7

No files matched your search

-2
View File
@@ -9,8 +9,6 @@
// - [CM64] Computes Mapping the Commodore 64 - page 115
// - https://www.c64-wiki.com/wiki/BASIC-ROM
// XXX finish and test this
add_align_exponents:
// XXX assume here none of the exponents is 0, check if this is true for orignal ROMs
+1 -5
View File
@@ -66,6 +66,7 @@ div_FAC2_FAC1:
// Divide the mantissas
jsr div_FAC1_denorm
jsr muldiv_RESHO_set_0
// XXX
@@ -74,8 +75,3 @@ div_FAC2_FAC1:
STUB_IMPLEMENTATION()
// XXX use 8-bit divide from here: https://codebase64.org/doku.php?id=base:8bit_divide_8bit_product
+70
View File
@@ -0,0 +1,70 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Math package - denormalize FAC1 mantissa and adapt its exponent accordingly,
// so that division is more precise
//
// XXX test this
div_FAC1_denorm:
// Start by moving whole bytes, if possible
lda FACOV
bne div_FAC1_denorm_by_bit // branch if last byte of mantissa is non-zero
lda FAC1_exponent
cmp #$09
bcc div_FAC1_denorm_by_bit // branch if not suitable to decrement exponent by 8
// Decrement exponent
sbc #$08 // Carry already set here
sta FAC1_exponent
// Move mantissa bytes
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 div_FAC1_denorm // branch always
div_FAC1_denorm_by_bit:
lda FACOV
and #$01
bne div_FAC1_denorm_done // branch if lowest bit of mantissa is already 1
lda FAC1_exponent
cmp #$02
bcc div_FAC1_denorm_done // branch if not suitable to decrement exponent
// Decrement exponent
dec FAC1_exponent
// Move mantissa bits
clc
ror FAC1_mantissa+0
ror FAC1_mantissa+1
ror FAC1_mantissa+2
ror FAC1_mantissa+3
ror FACOV
bcc div_FAC1_denorm_done // branch always
div_FAC1_denorm_done:
rts