From 8769cc16576589d2802c794ca61fa7fd3294dfa8 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Wed, 29 Jul 2020 17:17:41 +0200 Subject: [PATCH] added alternative, smaller 8x8 multiplication routine --- CREDITS.md | 2 +- src/basic/math/mul_FAC2_FAC1_8x8.s | 35 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CREDITS.md b/CREDITS.md index c1cfb957..c1a3082a 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -5,7 +5,7 @@ * Retrofan - for his Mega65 banner artwork and PXLfont * 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 * djmips - for fast 8x8 multiplication routine * Verz - for the integer division routine diff --git a/src/basic/math/mul_FAC2_FAC1_8x8.s b/src/basic/math/mul_FAC2_FAC1_8x8.s index bfc0730c..ff06c0c2 100644 --- a/src/basic/math/mul_FAC2_FAC1_8x8.s +++ b/src/basic/math/mul_FAC2_FAC1_8x8.s @@ -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