From f8dbfd86f9fa8f615489779fd168316c712abefc Mon Sep 17 00:00:00 2001 From: hugova Date: Thu, 15 May 2025 16:11:51 +0200 Subject: [PATCH] rewrite memcpy to work more like c:s implementation --- wip-hugo/routines/memory/mem.inc | 3 +- wip-hugo/routines/memory/memcpy.s | 40 ++++++++++++-------------- wip-hugo/routines/memory/memcpy_test.s | 24 ++++------------ wip-hugo/source.s | 4 +-- 4 files changed, 29 insertions(+), 42 deletions(-) diff --git a/wip-hugo/routines/memory/mem.inc b/wip-hugo/routines/memory/mem.inc index 6d7e188..5ee149f 100644 --- a/wip-hugo/routines/memory/mem.inc +++ b/wip-hugo/routines/memory/mem.inc @@ -3,4 +3,5 @@ ;; public args A_start = $D0 ; 16-bit value (uses D1) B_start = $D2 ; 16-bit value (uses D3) - B_end = $D4 ; 16-bit value (uses D5) + length = $D4 ; 16-bit value (uses D5) + B_end = length + 0 diff --git a/wip-hugo/routines/memory/memcpy.s b/wip-hugo/routines/memory/memcpy.s index c9487e7..4001096 100644 --- a/wip-hugo/routines/memory/memcpy.s +++ b/wip-hugo/routines/memory/memcpy.s @@ -1,33 +1,31 @@ ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- -;;Move memory from B_start B_end to A_start , (implied address) -;;Modifies A,X and B_start gets modified +;;Move length bytes from A_start address to lenght bytes starting at B_start. .proc memcpy .include "mem.inc" - - ;; Let Y + A_start lower nibble represent A_start - ;; therefor: A_start = Y - A_start - ;; With Y we mean what Y will represent later aka >B_start - Sub_16 A_start, A_start + 1, B_start, #$00 - - ;;Lets move B_start lover-nibble to Y - LDY B_start - LDA #$00 - STA B_start + LDY #$00 loop: - Lag_16 B_end, B_end + 1, A, B_start, end_loop LDA (B_start), Y STA (A_start), Y - ;Tip save time by counting downward, fast to check if Y ==0 // hugo INY - TYA - CMP #$ff + BEQ y_overflow +change_length: + DEC length BNE loop - ;; Fix overflow - LDY #$00 - INC A_start + 1 - INC B_start + 1 + + ;;check if length hi byte is 0. if it is end this + LDA length + 1 + BEQ loop_end + + DEC length +1 JMP loop -end_loop: +y_overflow: + LDY #$00 + INC B_start + 1 + INC A_start + 1 + + jmp change_length +loop_end: + RTS .endproc diff --git a/wip-hugo/routines/memory/memcpy_test.s b/wip-hugo/routines/memory/memcpy_test.s index 83e9832..9d2e5a8 100644 --- a/wip-hugo/routines/memory/memcpy_test.s +++ b/wip-hugo/routines/memory/memcpy_test.s @@ -1,25 +1,13 @@ ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;; test for memcpy +;; Writes text to half the screen .scope memcpy_test - charset = $FB - code = $FE - petski_position = $FE ;16-bit value (uses FF), reuses code:s memory - screen_position = $FC ;16-bit value (uses FD) - - Mov_16 B_start, B_start + 1, #<$D000, #>$D000 - ;#### TEMP INIT DATA #### - Mov_16 B_end, B_end + 1, #<($D000+$1F3F), #>($D000 +$1F3F) - LDA #$10 - STA code - LDA #$10 - STA X_pos - STA Y_pos - + .include "mem.inc" VIC_bank = $4000 - VIC_bank_end = VIC_bank + $3FFF + Character_generator_ROM = $D000 + len = $1f40 Mov_16 A_start, A_start + 1, #VIC_bank - LDA #$00 + Mov_16 B_start, B_start + 1, #Character_generator_ROM + Mov_16 length, length + 1, #len JSR memcpy - STA petski_position - jmp exit .endscope diff --git a/wip-hugo/source.s b/wip-hugo/source.s index 961e672..66e0ec6 100755 --- a/wip-hugo/source.s +++ b/wip-hugo/source.s @@ -10,8 +10,8 @@ ;.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/pixel/pixel_test.s" +.include "routines/memory/memcpy_test.s" ;.include "routines/triangle/triangle_test.s" exit: JMP exit