various multiplication fixes

This commit is contained in:
FeralChild64 committed 2020-02-27 18:28:57 +01:00
1 parent 55f1a1ae8a
commit a40b419b1f
5 files changed
+83 -75

No files matched your search

+3 -3
View File
@@ -198,11 +198,11 @@ Floating point mathematical routines - not official, but well known and broadly
| `$B8FE` | `normal_FAC1` | DONE | |
| `$B947` | `inv_FAC1_mantissa` | NOT DONE | |
| `$B9EA` | `log_FAC1` | NOT DONE | |
| `$BA28` | `mul_MEM_FAC1` | PARTIAL | needs `mul_FAC2_FAC1` |
| `$BA2B` | `mul_FAC2_FAC1` | PARTIAL | not testeed yet |
| `$BA28` | `mul_MEM_FAC1` | DONE | |
| `$BA2B` | `mul_FAC2_FAC1` | PARTIAL | very imprecise; not yet clear, why |
| `$BA8C` | `mov_MEM_FAC2` | DONE | |
| `$BA90` | `get_FAC2_via_INDEX` | NOT DONE | |
| `$BAE2` | `mul10_FAC1` | PARTIAL | not tested yet |
| `$BAE2` | `mul10_FAC1` | DONE | |
| `$BAFE` | `div10_FAC1_p` | PARTIAL | needs `div_FAC2_FAC1` |
| `$BB0F` | `div_MEM_FAC1` | PARTIAL | needs `div_FAC2_FAC1` |
| `$BB12` | `div_FAC2_FAC1` | NOT DONE | some work already started |
-2
View File
@@ -12,8 +12,6 @@
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX test this
mul10_FAC1:
// Handle special case of FAC1 equal 0
+1 -1
View File
@@ -11,6 +11,6 @@ mul10_FAC1_mul2:
// Increment the exponent
inc FAC1_exponent
bcs_16 set_FAC1_max
beq_16 set_FAC1_max
rts
+12 -69
View File
@@ -17,7 +17,7 @@
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
// XXX test this code
// XXX the code here is very imprecise, find out why
mul_FAC2_FAC1_done:
@@ -139,7 +139,13 @@ mul_FAC2_FAC1_sub_exp_bias:
lda RESHO+0
sta FAC1_mantissa+0
// XXX correction is probably needed
// Correct the exponent
lda FAC1_exponent
clc
adc #$08
bcs_16 set_FAC1_max // branch if overflow
sta FAC1_exponent
jmp normal_FAC1
@@ -153,7 +159,7 @@ mul_by_A: // XXX we should probably move this subroutine to a separate file
// Multiply FAC2_mantissa+3
lda FAC2_mantissa+3
jsr mul_8x8
jsr mul_FAC2_FAC1_8x8
adc RESHO+4
sta RESHO+4
@@ -170,7 +176,7 @@ mul_by_A: // XXX we should probably move this subroutine to a separate file
// Multiply FAC2_mantissa+2
lda FAC2_mantissa+2
jsr mul_8x8
jsr mul_FAC2_FAC1_8x8
adc RESHO+3
sta RESHO+3
@@ -185,7 +191,7 @@ mul_by_A: // XXX we should probably move this subroutine to a separate file
// Multiply FAC2_mantissa+1
lda FAC2_mantissa+1
jsr mul_8x8
jsr mul_FAC2_FAC1_8x8
adc RESHO+2
sta RESHO+2
@@ -198,7 +204,7 @@ mul_by_A: // XXX we should probably move this subroutine to a separate file
// Multiply FAC2_mantissa+0
lda FAC2_mantissa+0
jsr mul_8x8
jsr mul_FAC2_FAC1_8x8
adc RESHO+1
sta RESHO+1
txa
@@ -225,66 +231,3 @@ mul_shift_RESHO: // XXX we should probably move this subroutine to a separate fi
sta RESHO+0
rts
mul_8x8: // XXX we should probably move this subroutine to a separate file
sta INDEX+2
// Routine based on code by djmips, taken from:
// - https://codebase64.org/doku.php?id=base:8bit_multiplication_16bit_product_fast_no_tables
//
// input: INDEX+2, INDEX+3
// output: .X (high byte), .A and INDEX+2 (low byte), carry always clear
lda #$00
dec INDEX+3 // decrement because we will be adding with carry set for speed (an extra one)
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
inc INDEX+3
tax
lda INDEX+2
clc
rts
+67
View File
@@ -0,0 +1,67 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Helper routine, based on code by djmips from:
// - https://codebase64.org/doku.php?id=base:8bit_multiplication_16bit_product_fast_no_tables
//
// input: .A, INDEX+3
// output: .X (high byte), .A and INDEX+2 (low byte), carry always clear
//
mul_FAC2_FAC1_8x8:
sta INDEX+2
lda #$00
dec INDEX+3 // decrement because we will be adding with carry set for speed (an extra one)
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
bcc !+
adc INDEX+3
!:
ror
ror INDEX+2
inc INDEX+3
tax
lda INDEX+2
clc
rts