From b8df5cb84b49aac5e2d9c149b7fcddf615c860e0 Mon Sep 17 00:00:00 2001 From: hugova Date: Tue, 15 Jul 2025 22:33:19 +0200 Subject: [PATCH] add alternate version of memset (probably slower (only for testing)) --- wip-hugo/routines/circle/circle.inc | 12 ++--- wip-hugo/routines/memory/mem.inc | 7 ++- wip-hugo/routines/memory/memset.s | 51 +++++++++++++++---- wip-hugo/routines/memory/memset_alt.s | 71 +++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 16 deletions(-) create mode 100755 wip-hugo/routines/memory/memset_alt.s diff --git a/wip-hugo/routines/circle/circle.inc b/wip-hugo/routines/circle/circle.inc index a55199c..9fc2868 100644 --- a/wip-hugo/routines/circle/circle.inc +++ b/wip-hugo/routines/circle/circle.inc @@ -8,14 +8,14 @@ t2 = $E1 X_math = radius Y_math = $E2 - ;; E9 - EA is used by pixel.inc - byte_to_paint_qaa = $E8 - byte_to_paint_qcb = $E3 - byte_to_paint_qca = $E4 - byte_to_paint_qdb = $E5 + byte_to_paint_qaa = $E3 + byte_to_paint_qcb = $E4 + byte_to_paint_qca = $E5 + byte_to_paint_qdb = $E6 btp_mem_pos_qaa = btp_mem_pos - btp_mem_pos_qcb = $E6 ; 16bit value (uses E7) + btp_mem_pos_qcb = $E7 ; 16bit value (uses E8) + ; E9 - EA is used by pixel.inc btp_mem_pos_qdb = $EB ; 16bit value (uses EC) btp_mem_pos_qda = $ED ; 16bit value (uses EE) btp_mem_pos_qab = $D0 ; 16bit value (uses D1) diff --git a/wip-hugo/routines/memory/mem.inc b/wip-hugo/routines/memory/mem.inc index c7ea9ac..2f301b1 100644 --- a/wip-hugo/routines/memory/mem.inc +++ b/wip-hugo/routines/memory/mem.inc @@ -3,4 +3,9 @@ ;; public args A_start = $D0 ; 16-bit value (uses D1) B_start = $D2 ; 16-bit value (uses D3) - length = $D4 ; 16-bit value (uses D5), this is the number of bytes + length = $D4 ; 16-bit value (uses D5), this is the number of bytes + + RTS_pointer = $D6 ; 16-bit value (uses D7) + data_to_write = $D8 + length_copy = $d9 ; 16-bit vale (uses da) + instruction_backup = $db diff --git a/wip-hugo/routines/memory/memset.s b/wip-hugo/routines/memory/memset.s index 55700e9..16e6af6 100755 --- a/wip-hugo/routines/memory/memset.s +++ b/wip-hugo/routines/memory/memset.s @@ -18,6 +18,8 @@ big_set: ;sets $ff of memory DEY .endrepeat STA (A_start), Y ; dont forget Y =0 + NOP + NOP big_set_end: ;;set all hole $ff memory chunks! INC A_start + 1 @@ -26,15 +28,46 @@ big_set_end: JMP big_set - -;;sets the rest of the memory -;; note that this can use code above (smc) or the same method. may implement later. small_set: - LDY length -small_set_loop: - STA (A_start), Y - DEY - BNE small_set_loop - STA (A_start), Y + STA data_to_write + LDA length + STA length_copy + + ;; calculate rts-position + LDA #$00 + STA length + 1 + ;; 4 bytes = STA DEY NOP = seting 1 byte of memory. + ;; So we need to calculate: length*4 + Mult_16 length, length + 1 + Add_16 length, length + 1, length_copy, #$00 + ;; Now RTS_pointer = length*4 + big_set_label + CLC + LDA #big_set + ADC length + 1 + STA RTS_pointer + 1 + + ;; read data we will change to RTS + LDY #$00 + LDA (RTS_pointer), Y + STA instruction_backup + + ;; set RTS in big_set + LDA #$60 + STA (RTS_pointer), Y + + ;; JSR to modified big_set + LDY length_copy + DEY ; because we want to count to Y=0 :) + LDA data_to_write + JSR big_set + + ;; revert changes + LDY #$00 + LDA instruction_backup + STA (RTS_pointer), Y + RTS .endproc diff --git a/wip-hugo/routines/memory/memset_alt.s b/wip-hugo/routines/memory/memset_alt.s new file mode 100755 index 0000000..4197d5b --- /dev/null +++ b/wip-hugo/routines/memory/memset_alt.s @@ -0,0 +1,71 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + +;; Sets memory in 'A'-registry to all addresses from 'A_start' until 'A_start' + 'length' +;; Modifies A, X and A_start +.proc memset + .include "mem.inc" + +;; big_set sets the memory in $ff chunks. +;; skipp if length >= $ff +LDX length +1 +BNE big_set +JMP small_set + +big_set: ;sets $ff of memory + ;; Y value do not matter, will go through all anyway! + .repeat $ff + STA (A_start), Y + DEY + .endrepeat + STA (A_start), Y ; dont forget Y =0 +big_set_end: + ;;set all hole $ff memory chunks! + INC A_start + 1 + DEX ;; length +1 -- + BEQ small_set + JMP big_set + + +small_set: + STA data_to_write + LDA length + STA length_copy + + ;; calculate rts-position + LDA #$00 + STA length + 1 + ;; 4 bytes = STA DEY NOP = seting 1 byte of memory. + ;; So we need to calculate: length*4 + Mult_16 length, length + 1 + Add_16 length, length + 1, length_copy, #$00 + ;; Now RTS_pointer = length*4 + big_set_label + CLC + LDA #big_set + ADC length + 1 + STA RTS_pointer + 1 + + ;; read data we will change to RTS + LDY #$00 + LDA (RTS_pointer), Y + STA instruction_backup + + ;; set RTS in big_set + LDA #$60 + STA (RTS_pointer), Y + + ;; JSR to modified big_set + LDY length_copy + DEY ; because we want to count to Y=0 :) + LDA data_to_write + JSR big_set + + ;; revert changes + LDY #$00 + LDA instruction_backup + STA (RTS_pointer), Y + + RTS +.endproc