added alternative, smaller 8x8 multiplication routine
This commit is contained in:
1 parent
8e2a91cbd6
commit
8769cc1657
2 files changed
+35
-2
No files matched your search
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
* Retrofan - for his Mega65 banner artwork and PXLfont
|
* Retrofan - for his Mega65 banner artwork and PXLfont
|
||||||
* TWW/CTR - for his keyboard handling code
|
* TWW/CTR - for his keyboard handling code
|
||||||
* Graham - for his PAL/NTSC detection routine
|
* Graham - for his PAL/NTSC detection code and compact 8x8 multiplication routine
|
||||||
* enthusi/Onslaught - for his example Turbo Tape 64 compatible loader
|
* enthusi/Onslaught - for his example Turbo Tape 64 compatible loader
|
||||||
* djmips - for fast 8x8 multiplication routine
|
* djmips - for fast 8x8 multiplication routine
|
||||||
* Verz - for the integer division routine
|
* Verz - for the integer division routine
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
// #LAYOUT# * * #IGNORE
|
// #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
|
// - 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
|
// input: .A (and Zero flag set according to .A), INDEX+3
|
||||||
// output: .X (high byte), .A (low byte), carry always clear
|
// output: .X (high byte), .A (low byte), carry always clear
|
||||||
@@ -22,6 +24,10 @@ mul_FAC2_FAC1_8x8:
|
|||||||
|
|
||||||
// Multiply INDEX+2 * INDEX+3
|
// Multiply INDEX+2 * INDEX+3
|
||||||
|
|
||||||
|
#if !HAS_SMALL_BASIC
|
||||||
|
|
||||||
|
// Fast multiplication routine
|
||||||
|
|
||||||
lda #$00
|
lda #$00
|
||||||
|
|
||||||
dec INDEX+3 // decrement because we will be adding with carry set for speed (an extra one)
|
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
|
tax
|
||||||
lda INDEX+2
|
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
|
clc
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user