From 9a06f770c23c72e7b0299a9f91c4831f90d1e9ea Mon Sep 17 00:00:00 2001 From: hugova Date: Fri, 16 May 2025 10:40:55 +0200 Subject: [PATCH] add general multiplication implementation --- wip-hugo/routines/arithmatic/arithmatic.inc | 4 +++ wip-hugo/routines/arithmatic/mult.s | 27 +++++++++++++++++++++ wip-hugo/routines/arithmatic/mult_test.s | 10 ++++++++ wip-hugo/routines/pixel/pixel_test.s | 1 + wip-hugo/routines/text/char.inc | 3 ++- wip-hugo/routines/text/char_draw_test.s | 1 + wip-hugo/source.s | 4 ++- 7 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 wip-hugo/routines/arithmatic/arithmatic.inc create mode 100644 wip-hugo/routines/arithmatic/mult.s create mode 100644 wip-hugo/routines/arithmatic/mult_test.s diff --git a/wip-hugo/routines/arithmatic/arithmatic.inc b/wip-hugo/routines/arithmatic/arithmatic.inc new file mode 100644 index 0000000..02ebd5a --- /dev/null +++ b/wip-hugo/routines/arithmatic/arithmatic.inc @@ -0,0 +1,4 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- +;; public args +VAL_A = ARGVEC + 0 +VAL_B = ARGVEC + 1 diff --git a/wip-hugo/routines/arithmatic/mult.s b/wip-hugo/routines/arithmatic/mult.s new file mode 100644 index 0000000..b0c7056 --- /dev/null +++ b/wip-hugo/routines/arithmatic/mult.s @@ -0,0 +1,27 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + ;;I thoughtout russan thing + ;;X * %1111001 + ;;= X + X*%1111000 + ;;= X + X*%1000 *%11111 + ;; to remember this for later, for duuqnds papper + +.proc mult; user-procedure :clobbers A :clobbers-arguments 2 + + ;; https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication#Russian_peasant_multiplication + + .include "arithmatic.inc" + + LDA #$00 +loop: + ASL VAL_B + ROR VAL_A; add to awnser if VAL_A is odd + BCC loop + + LSR VAL_B + ADC VAL_B; add val_b because val_a was odd. + ASL VAL_B + + BNE loop +endloop: + RTS +.endproc diff --git a/wip-hugo/routines/arithmatic/mult_test.s b/wip-hugo/routines/arithmatic/mult_test.s new file mode 100644 index 0000000..2095ef2 --- /dev/null +++ b/wip-hugo/routines/arithmatic/mult_test.s @@ -0,0 +1,10 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- +;;Calculates $11 * $0E = $EE +.scope mult_test + .include "arithmatic.inc" + LDA #$0F + STA VAL_A + LDA #$07 + STA VAL_B + JSR mult; A = $69 if it works as it should +.endscope diff --git a/wip-hugo/routines/pixel/pixel_test.s b/wip-hugo/routines/pixel/pixel_test.s index 2839703..164a634 100644 --- a/wip-hugo/routines/pixel/pixel_test.s +++ b/wip-hugo/routines/pixel/pixel_test.s @@ -1,3 +1,4 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- .scope pixel_test .include "pixel.inc" LDA #$40 diff --git a/wip-hugo/routines/text/char.inc b/wip-hugo/routines/text/char.inc index 5f80983..ea4b70a 100644 --- a/wip-hugo/routines/text/char.inc +++ b/wip-hugo/routines/text/char.inc @@ -1,4 +1,5 @@ - ;; public args +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + ;; public args X_pos = ARGVEC + 0 Y_pos = ARGVEC + 1 code = ARGVEC + 2 diff --git a/wip-hugo/routines/text/char_draw_test.s b/wip-hugo/routines/text/char_draw_test.s index 2a54446..63d5361 100644 --- a/wip-hugo/routines/text/char_draw_test.s +++ b/wip-hugo/routines/text/char_draw_test.s @@ -1,3 +1,4 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- .scope char_draw_test .include "char.inc" LDA #$10 diff --git a/wip-hugo/source.s b/wip-hugo/source.s index 70912de..7f640b6 100755 --- a/wip-hugo/source.s +++ b/wip-hugo/source.s @@ -8,11 +8,12 @@ .include "STARTUP.s" ;.include "dubbel_buffer/raster_irqs.s" +.include "routines/arithmatic/mult_test.s" ;.include "routines/line/line_test.s" ;.include "routines/text/char_draw_test.s" ;.include "routines/pixel/pixel_test.s" ;.include "routines/memory/memcpy_test.s" -.include "routines/memory/memset_test.s" +;.include "routines/memory/memset_test.s" ;.include "routines/triangle/triangle_test.s" exit: JMP exit @@ -23,4 +24,5 @@ JMP exit .include "routines/text/char_draw.s" .include "routines/memory/memset.s" .include "routines/memory/memcpy.s" +.include "routines/arithmatic/mult.s" .include "END.s"