rewrite memset to make it 59523 cpu cycles faster in memset_test

This commit is contained in:
hugova 2025-07-13 19:18:04 +02:00
parent e187d4a244
commit a94c6f4e8f
7 changed files with 85 additions and 65 deletions

View file

@ -24,7 +24,6 @@
.proc circle; user-procedure :clobbers (A X Y) :clobbers-arguments 3 .proc circle; user-procedure :clobbers (A X Y) :clobbers-arguments 3
.include "circle.inc" .include "circle.inc"
;; X_math = radius (share the same address) ;; X_math = radius (share the same address)
;;Y_math =0 ;;Y_math =0
LDA #$00 LDA #$00

View file

@ -1,9 +1,11 @@
.scope circle_test .scope circle_test
.include "circle.inc" .include "circle.inc"
;; set initial values
LDA #$58 LDA #$58
STA X_pos STA X_pos
STA Y_pos STA Y_pos
LDA #$40 LDA #$40
STA radius STA radius
;; draw circle
JSR circle JSR circle
.endscope .endscope

View file

@ -1,6 +1,7 @@
.scope circle_test_position_x .scope circle_test_position_x
.include "circle.inc" .include "circle.inc"
;; Set initial parameters for circle
LDA #$50 LDA #$50
STA $AD STA $AD
LDA #$50 LDA #$50
@ -8,37 +9,39 @@
LDA #$40 LDA #$40
STA $AF STA $AF
loop:
;delay: ;lets delay the print
; LDX #$ff
; LDY #$ff
;delay_point:
; NOP
; NOP
; DEX
; BNE delay_point
; DEY
; BNE delay_point
;;clear screen
LDX #$ff
LDY #$ff
hihi:
NOP
NOP
DEX
BNE hihi
DEY
BNE hihi
INC $AD
LDA $AD
STA X_pos
LDA $AE
STA Y_pos
LDA $AF
STA radius
VIC_bank = $4000 VIC_bank = $4000
Mov_16 A_start, A_start + 1, #<VIC_bank, #>VIC_bank Mov_16 A_start, A_start + 1, #<VIC_bank, #>VIC_bank
Mov_16 length, length + 1, #<$1f40, #>$1f40 Mov_16 length, length + 1, #<$1f40, #>$1f40
LDA #$00 LDA #$00
jsr memset jsr memset
;;move circle
INC $AD
;; draw circle
LDA $AD
STA X_pos
LDA $AE
STA Y_pos
LDA $AF
STA radius
JSR circle JSR circle
LDX #$ff ;; end loop when x_pos = $70
LDY #$ff LDA $AD
CMP #$70
jmp hihi BNE loop
.endscope .endscope

View file

@ -1,45 +1,47 @@
.scope circle_test_size .scope circle_test_size
.include "circle.inc" .include "circle.inc"
LDA #$50
STA X_pos ;;Set initial parameters for circle
STA Y_pos
LDA #$01 LDA #$01
STA $AD STA $AD
loop:
;delay: ;lets delay the print
; LDX #$ff
; LDY #$ff
;delay_point:
; NOP
; NOP
; DEX
; BNE delay_point
; DEY
; BNE delay_point
LDX #$ff ;; set other parameters for circle
LDY #$ff
hihi:
NOP
NOP
DEX
BNE hihi
DEY
BNE hihi
LDA #$50 LDA #$50
STA X_pos STA X_pos
STA Y_pos STA Y_pos
;; make circle radius bigger
INC $AD INC $AD
LDA $AD LDA $AD
STA radius STA radius
;; clean the screen
VIC_bank = $4000 VIC_bank = $4000
Mov_16 A_start, A_start + 1, #<VIC_bank, #>VIC_bank Mov_16 A_start, A_start + 1, #<VIC_bank, #>VIC_bank
Mov_16 length, length + 1, #<$1f40, #>$1f40 Mov_16 length, length + 1, #<$1f40, #>$1f40
LDA #$00 LDA #$00
jsr memset jsr memset
;; draw the circle
JSR circle JSR circle
LDX #$ff ;; end loop if radius = $aa
LDY #$ff LDA $AD
CMP #$20
jmp hihi BNE loop
.endscope .endscope

View file

@ -1,6 +1,8 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;Move length bytes from A_start address to lenght bytes starting at B_start. ;;Moves data from buffer A to B.
;; Buffer A starts at 'A_start' and B starts att 'B_start'.
;; The data has length 'length'.
.proc memcpy .proc memcpy
.include "mem.inc" .include "mem.inc"
LDY #$00 LDY #$00

View file

@ -1,23 +1,35 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; Sets memory in A to all addresses from B_start to B_end ;; Sets memory in 'A'-registry to all addresses from 'A_start' until 'A_start' + 'length'
;; Modifies A, X and B_start ;; Modifies A, X and A_start
.proc memset .proc memset
.include "mem.inc" .include "mem.inc"
LDY #$00
loop:
STA (A_start), Y
INY
BEQ y_overflow
change_length:
DEC length
BNE loop
DEC length +1 ;; big_set sets the memory in $ff chunks.
BPL loop ;; skipp if length >= $ff
RTS LDX length +1
y_overflow: BEQ small_set
;; Y is now 0
big_set:
LDY #$ff
big_set_loop:
STA (A_start), Y
DEY
BNE big_set_loop
STA (A_start), Y ; don't forget Y=0
;;maybe move to next chunk
INC A_start + 1 INC A_start + 1
jmp change_length DEC length + 1
BNE big_set
;;sets the rest of the memory
small_set:
LDY length
small_set_loop:
STA (A_start), Y
DEY
BNE small_set_loop
STA (A_start), Y
RTS
.endproc .endproc

View file

@ -11,13 +11,13 @@
;.include "routines/arithmatic/mult_test.s" ;.include "routines/arithmatic/mult_test.s"
;.include "routines/arithmatic/div_test.s" ;.include "routines/arithmatic/div_test.s"
;.include "routines/circle/circle_test.s" ;.include "routines/circle/circle_test.s"
.include "routines/circle/circle_test_size.s" ;.include "routines/circle/circle_test_size.s"
;.include "routines/circle/circle_test_position.s" ;.include "routines/circle/circle_test_position.s"
;.include "routines/line/line_test.s" ;.include "routines/line/line_test.s"
;.include "routines/text/char_draw_test.s" ;.include "routines/text/char_draw_test.s"
;.include "routines/pixel/pixel_test.s" ;.include "routines/pixel/pixel_test.s"
;.include "routines/memory/memcpy_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" ;.include "routines/triangle/triangle_test.s"
exit: exit:
JMP exit JMP exit