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
.include "circle.inc"
;; X_math = radius (share the same address)
;;Y_math =0
LDA #$00

View file

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

View file

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

View file

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

View file

@ -1,6 +1,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
.include "mem.inc"
LDY #$00

View file

@ -1,23 +1,35 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; Sets memory in A to all addresses from B_start to B_end
;; Modifies A, X and B_start
;; 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"
LDY #$00
loop:
STA (A_start), Y
INY
BEQ y_overflow
change_length:
DEC length
BNE loop
DEC length +1
BPL loop
RTS
y_overflow:
;; Y is now 0
;; big_set sets the memory in $ff chunks.
;; skipp if length >= $ff
LDX length +1
BEQ small_set
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
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

View file

@ -11,13 +11,13 @@
;.include "routines/arithmatic/mult_test.s"
;.include "routines/arithmatic/div_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/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