diff --git a/CREDITS.md b/CREDITS.md index 72143f5f..a1ebe654 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -6,6 +6,7 @@ * TWW/CTR - for his keyboard handling code * Graham - for his PAL/NTSC detection routine * enthusi/Onslaught - for his example Turbo Tape 64 compatible loader +* djmips - for fast 8x8 multiplication routine ## for documentation diff --git a/c64/basic/math/mul_FAC2_FAC1.s b/c64/basic/math/mul_FAC2_FAC1.s index 35b71b39..44c21c17 100644 --- a/c64/basic/math/mul_FAC2_FAC1.s +++ b/c64/basic/math/mul_FAC2_FAC1.s @@ -88,3 +88,63 @@ mul_FAC2_FAC1_sub_exp_bias: mul_FAC2_FAC1_done: rts + + +mul_8x8: // XXX we should probably move this subroutine to separate file + + // Routine based on code by djmips, taken from: + // - https://codebase64.org/doku.php?id=base:8bit_multiplication_16bit_product_fast_no_tables + // + // input: mul1, mul2 + // optput: .A (high byte), mul1 (low byte) + +.label mul1 = INDEX+2 +.label mul2 = INDEX+3 + + lda #$00 + + dec mul2 // decrement because we will be adding with carry set for speed (an extra one) + ror mul1 + bcc !+ + adc mul2 +!: + ror + ror mul1 + bcc !+ + adc mul2 +!: + ror + ror mul1 + bcc !+ + adc mul2 +!: + ror + ror mul1 + bcc !+ + adc mul2 +!: + ror + ror mul1 + bcc !+ + adc mul2 +!: + ror + ror mul1 + bcc !+ + adc mul2 +!: + ror + ror mul1 + bcc !+ + adc mul2 +!: + ror + ror mul1 + bcc !+ + adc mul2 +!: + ror + ror mul1 + inc mul2 + + rts