From 49a330d24c3b63fab8282c7b63055ae662bc3e2c Mon Sep 17 00:00:00 2001 From: hugova Date: Wed, 16 Jul 2025 20:18:53 +0200 Subject: [PATCH] reduse a STA instruction in circle code --- wip-hugo/routines/circle/circle.inc | 19 ++-- wip-hugo/routines/circle/circle.s | 2 +- wip-hugo/routines/memory/memset_alt.s | 150 +++++++++++++------------- 3 files changed, 85 insertions(+), 86 deletions(-) mode change 100755 => 100644 wip-hugo/routines/memory/memset_alt.s diff --git a/wip-hugo/routines/circle/circle.inc b/wip-hugo/routines/circle/circle.inc index 9fc2868..f354e24 100644 --- a/wip-hugo/routines/circle/circle.inc +++ b/wip-hugo/routines/circle/circle.inc @@ -5,16 +5,15 @@ ;; and others from pixel.inc ;; private args t1 = $E0 - t2 = $E1 X_math = radius - Y_math = $E2 - byte_to_paint_qaa = $E3 - byte_to_paint_qcb = $E4 - byte_to_paint_qca = $E5 - byte_to_paint_qdb = $E6 + Y_math = $E1 + byte_to_paint_qaa = $E2 + byte_to_paint_qcb = $E3 + byte_to_paint_qca = $E4 + byte_to_paint_qdb = $E5 btp_mem_pos_qaa = btp_mem_pos - btp_mem_pos_qcb = $E7 ; 16bit value (uses E8) + btp_mem_pos_qcb = $E6 ; 16bit value (uses E7) ; 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) @@ -24,9 +23,9 @@ btp_mem_pos_qbb = $D6 ; 16bit value (uses D7) Y_qda = $EF - Y_qdb = $D8 - Y_qbb = $D9 - Y_qaa = $DA + Y_qdb = $E8 + Y_qbb = $D8 + Y_qaa = $D9 ;;Reuse addresses, be carful here! temp__ = Y_qaa temp_ = Y_qda diff --git a/wip-hugo/routines/circle/circle.s b/wip-hugo/routines/circle/circle.s index f87eb93..81428b5 100644 --- a/wip-hugo/routines/circle/circle.s +++ b/wip-hugo/routines/circle/circle.s @@ -229,7 +229,7 @@ qcb_x_end: ;; t2 = t1 - x SEC SBC X_math - STA t2 + ;t2 do not need to be saved :) ;; if t2 < 0 then skip to endif ;; we can skipp CMP #$00 because SBC above do the same BPL if diff --git a/wip-hugo/routines/memory/memset_alt.s b/wip-hugo/routines/memory/memset_alt.s old mode 100755 new mode 100644 index deec825..40b7b50 --- a/wip-hugo/routines/memory/memset_alt.s +++ b/wip-hugo/routines/memory/memset_alt.s @@ -1,75 +1,75 @@ -;;; -*- 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 - LDX #$00 - STX length + 1 - ;; 3 bytes = STA DEY NOP = seting 1 byte of memory. - ;; So we need to calculate: length*3 - Mult_16 length, length + 1 - ; A= length_copy - ADC length - TAY - LDA length + 1 - ADC #$00 - STA length + 1 - - ;; Now RTS_pointer + Y = length*3 + big_set_label - LDA #big_set - ADC length + 1 - STA RTS_pointer + 1 - - ;; read data we will change to RTS - STY Y_copy - LDA (RTS_pointer), Y - TAX - - ;; 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 Y_copy - TXA - STA (RTS_pointer), Y - - RTS -.endproc +;;; -*- 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 + LDX #$00 + STX length + 1 + ;; 3 bytes = STA DEY NOP = seting 1 byte of memory. + ;; So we need to calculate: length*3 + Mult_16 length, length + 1 + ; A= length_copy + ADC length + TAY + LDA length + 1 + ADC #$00 + STA length + 1 + + ;; Now RTS_pointer + Y = length*3 + big_set_label + LDA #big_set + ADC length + 1 + STA RTS_pointer + 1 + + ;; read data we will change to RTS + STY Y_copy + LDA (RTS_pointer), Y + TAX + + ;; 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 Y_copy + TXA + STA (RTS_pointer), Y + + RTS +.endproc