use faster memset algoritm.

This commit is contained in:
hugova 2025-07-26 14:50:23 +02:00
parent 7f136b9ed2
commit ef22e5a2ff
2 changed files with 80 additions and 41 deletions

56
wip-hugo/routines/memory/memset.s Executable file → Normal file
View file

@ -25,16 +25,54 @@ big_set_end:
BEQ small_set
JMP big_set
;; Note that cpu cykels total: cy_tot = 66 to 69
;; But we skipp a BNE (cy = 2*) * [length (mod 255)]
;; The BNE case has an avrige of 2*255/2 = 255 so this is faster (on avrige.)
;;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 ; cy = 3
LDA length ; cy = 3
STA length_copy ; cy = 3
;; calculate rts-position
LDX #$00 ; cy = 2
STX length + 1 ; cy = 3
;; 3 bytes = STA DEY NOP = seting 1 byte of memory.
;; So we need to calculate: length*3
Mult_16 A, length + 1 ; cy = 7
; A= length
ADC length_copy ; cy = 3
TAY
LDA length + 1 ; cy = 3
ADC #$00 ; cy = 2
STA length + 1 ; cy = 3
;; Now RTS_pointer + Y = length*3 + big_set_label
LDA #<big_set ; cy = 2
STA RTS_pointer ; cy = 3
LDA #>big_set ; cy = 2
ADC length + 1 ; cy = 3
STA RTS_pointer + 1 ; cy = 3
;; read data we will change to RTS
STY Y_copy ; cy = 3
LDA (RTS_pointer), Y ; cy = 5*
TAX ; cy = 2
;; set RTS in big_set
LDA #$60 ; cy = 2
STA (RTS_pointer), Y ; cy = 5*
;; JSR to modified big_set
LDY length_copy ; cy = 3
DEY ; because we want to count to Y=0 :)
LDA data_to_write ; cy = 3
JSR big_set ; cy = 6
;; revert changes
LDY Y_copy ; cy = 3
TXA ; cy = 2
STA (RTS_pointer), Y ; cy = 5*
RTS
.endproc

View file

@ -33,7 +33,8 @@ JMP exit
.include "routines/pixel/pixel_draw.s"
.include "routines/pixel/pixel_calc.s"
.include "routines/text/char_draw.s"
.include "routines/memory/memset_alt.s"
.include "routines/memory/memset.s"
;.include "routines/memory/clear_screen.s"
.include "routines/memory/memcpy.s"
.include "routines/arithmatic/mult.s"
.include "routines/arithmatic/div.s"