added alternative, smaller 8x8 multiplication routine

This commit is contained in:
FeralChild64 committed 2020-07-29 17:17:41 +02:00
1 parent 8e2a91cbd6
commit 8769cc1657
2 files changed
+35 -2

No files matched your search

+34 -1
View File
@@ -3,8 +3,10 @@
// #LAYOUT# * * #IGNORE
//
// Helper routine, based on code by djmips from:
// Helper routine, based on code by djmips (fast version) from:
// - https://codebase64.org/doku.php?id=base:8bit_multiplication_16bit_product_fast_no_tables
// or by code by Graham (small version) from:
// - https://codebase64.org/doku.php?id=base:short_8bit_multiplication_16bit_product
//
// input: .A (and Zero flag set according to .A), INDEX+3
// output: .X (high byte), .A (low byte), carry always clear
@@ -22,6 +24,10 @@ mul_FAC2_FAC1_8x8:
// Multiply INDEX+2 * INDEX+3
#if !HAS_SMALL_BASIC
// Fast multiplication routine
lda #$00
dec INDEX+3 // decrement because we will be adding with carry set for speed (an extra one)
@@ -71,6 +77,33 @@ mul_FAC2_FAC1_8x8:
tax
lda INDEX+2
#else
// Small multiplication routine
lda #$00
ldx #$08
clc
!:
bcc !+
clc
adc INDEX+3
!:
ror
ror INDEX+2
dex
bpl !--
ldx INDEX+2
// Reverse return byte order, to match fast version
// (such order is easier top handle for the callers)
stx INDEX+2
tax
lda INDEX+2
#endif
clc
rts