From a94c6f4e8f18b4f8a523aae9a7718d32a8aef1b3 Mon Sep 17 00:00:00 2001 From: hugova Date: Sun, 13 Jul 2025 19:18:04 +0200 Subject: [PATCH] rewrite memset to make it 59523 cpu cycles faster in memset_test --- wip-hugo/routines/circle/circle.s | 3 +- wip-hugo/routines/circle/circle_test.s | 2 + .../routines/circle/circle_test_position.s | 51 ++++++++++--------- wip-hugo/routines/circle/circle_test_size.s | 42 +++++++-------- wip-hugo/routines/memory/memcpy.s | 4 +- wip-hugo/routines/memory/memset.s | 44 ++++++++++------ wip-hugo/source.s | 4 +- 7 files changed, 85 insertions(+), 65 deletions(-) diff --git a/wip-hugo/routines/circle/circle.s b/wip-hugo/routines/circle/circle.s index 4d891db..0f23e5c 100644 --- a/wip-hugo/routines/circle/circle.s +++ b/wip-hugo/routines/circle/circle.s @@ -23,8 +23,7 @@ .proc circle; user-procedure :clobbers (A X Y) :clobbers-arguments 3 -.include "circle.inc" - + .include "circle.inc" ;; X_math = radius (share the same address) ;;Y_math =0 LDA #$00 diff --git a/wip-hugo/routines/circle/circle_test.s b/wip-hugo/routines/circle/circle_test.s index a8d871a..17b6536 100644 --- a/wip-hugo/routines/circle/circle_test.s +++ b/wip-hugo/routines/circle/circle_test.s @@ -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 diff --git a/wip-hugo/routines/circle/circle_test_position.s b/wip-hugo/routines/circle/circle_test_position.s index f0f8b55..1c3ea74 100644 --- a/wip-hugo/routines/circle/circle_test_position.s +++ b/wip-hugo/routines/circle/circle_test_position.s @@ -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 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 diff --git a/wip-hugo/routines/circle/circle_test_size.s b/wip-hugo/routines/circle/circle_test_size.s index 0b08214..02f901b 100644 --- a/wip-hugo/routines/circle/circle_test_size.s +++ b/wip-hugo/routines/circle/circle_test_size.s @@ -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 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 diff --git a/wip-hugo/routines/memory/memcpy.s b/wip-hugo/routines/memory/memcpy.s index 28b0958..1c376a4 100644 --- a/wip-hugo/routines/memory/memcpy.s +++ b/wip-hugo/routines/memory/memcpy.s @@ -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 diff --git a/wip-hugo/routines/memory/memset.s b/wip-hugo/routines/memory/memset.s index 082e20f..4696260 100755 --- a/wip-hugo/routines/memory/memset.s +++ b/wip-hugo/routines/memory/memset.s @@ -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 diff --git a/wip-hugo/source.s b/wip-hugo/source.s index 3d64bb5..542565f 100644 --- a/wip-hugo/source.s +++ b/wip-hugo/source.s @@ -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