From 87fd6a1b9d284d80221c957d0eee1095165fa5af Mon Sep 17 00:00:00 2001 From: hugova Date: Thu, 15 May 2025 17:05:28 +0200 Subject: [PATCH] make memset work more like c:s implementation. --- wip-hugo/STARTUP.s | 9 +++--- wip-hugo/routines/line/line_test.s | 6 ++-- wip-hugo/routines/memory/mem.inc | 3 +- wip-hugo/routines/memory/memcpy.s | 7 ----- wip-hugo/routines/memory/memcpy_test.s | 2 +- wip-hugo/routines/memory/memset.s | 38 ++++++++++++-------------- wip-hugo/routines/memory/memset_test.s | 9 ++++++ wip-hugo/source.s | 5 ++-- 8 files changed, 37 insertions(+), 42 deletions(-) create mode 100644 wip-hugo/routines/memory/memset_test.s diff --git a/wip-hugo/STARTUP.s b/wip-hugo/STARTUP.s index 756e9c3..0067541 100755 --- a/wip-hugo/STARTUP.s +++ b/wip-hugo/STARTUP.s @@ -59,15 +59,14 @@ STA Screen_RAM_settings ;; Paint the bitmap black. More bitmap: https://www.c64-wiki.com/wiki/53272, https://www.c64-wiki.com/wiki/Screen_RAM#Moving_of_screen_RAM - Mov_16 B_start, B_start + 1, #VIC_bank - Mov_16 B_end, B_end + 1, #<$5f3f, #>$5f3f + Mov_16 A_start, A_start + 1, #VIC_bank + Mov_16 length, length + 1, #<$1f3f, #>$1f3f LDA #$00 jsr memset - ;; Sets the screen color to black and white - Mov_16 B_start, B_start + 1, #Screen_RAM - Mov_16 B_end, B_end + 1, #Screen_RAM_end + Mov_16 A_start, A_start + 1, #Screen_RAM + Mov_16 length, length + 1, #<$03E8, #>$03E8 LDA #%11110000 jsr memset diff --git a/wip-hugo/routines/line/line_test.s b/wip-hugo/routines/line/line_test.s index 0e67891..84876e9 100644 --- a/wip-hugo/routines/line/line_test.s +++ b/wip-hugo/routines/line/line_test.s @@ -50,10 +50,9 @@ end: ;;Long lines ;;Lets clear bitmap VIC_bank = $4000 - VIC_bank_end = VIC_bank + $3FFF ;;Paint the bitmap black. More bitmap: https://www.c64-wiki.com/wiki/53272, https://www.c64-wiki.com/wiki/Screen_RAM#Moving_of_screen_RAM - Mov_16 B_start, B_start + 1, #VIC_bank - Mov_16 B_end, B_end + 1, #<$5f3f, #>$5f3f + Mov_16 A_start, A_start + 1, #VIC_bank + Mov_16 length, length + 1, #<$1f40, #>$1f40 LDA #$00 jsr memset @@ -78,5 +77,4 @@ end: BEQ end_ jmp @loop end_: - jmp exit .endscope diff --git a/wip-hugo/routines/memory/mem.inc b/wip-hugo/routines/memory/mem.inc index 5ee149f..c7ea9ac 100644 --- a/wip-hugo/routines/memory/mem.inc +++ b/wip-hugo/routines/memory/mem.inc @@ -3,5 +3,4 @@ ;; public args A_start = $D0 ; 16-bit value (uses D1) B_start = $D2 ; 16-bit value (uses D3) - length = $D4 ; 16-bit value (uses D5) - B_end = length + 0 + length = $D4 ; 16-bit value (uses D5), this is the number of bytes diff --git a/wip-hugo/routines/memory/memcpy.s b/wip-hugo/routines/memory/memcpy.s index de752f6..c99a1ae 100644 --- a/wip-hugo/routines/memory/memcpy.s +++ b/wip-hugo/routines/memory/memcpy.s @@ -16,13 +16,6 @@ change_length: DEC length +1 BPL loop JMP loop_end - - ;;;;check if length hi byte is 0. if it is end this - ;;LDA length + 1 - ;;BEQ loop_end - - ;;DEC length +1 - ;;JMP loop y_overflow: LDY #$00 INC B_start + 1 diff --git a/wip-hugo/routines/memory/memcpy_test.s b/wip-hugo/routines/memory/memcpy_test.s index 9d2e5a8..a0845ed 100644 --- a/wip-hugo/routines/memory/memcpy_test.s +++ b/wip-hugo/routines/memory/memcpy_test.s @@ -1,6 +1,6 @@ ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;; test for memcpy -;; Writes text to half the screen +;; Writes text to the screen .scope memcpy_test .include "mem.inc" VIC_bank = $4000 diff --git a/wip-hugo/routines/memory/memset.s b/wip-hugo/routines/memory/memset.s index ea9d8cd..197bb02 100755 --- a/wip-hugo/routines/memory/memset.s +++ b/wip-hugo/routines/memory/memset.s @@ -4,28 +4,24 @@ ;; Modifies A, X and B_start .proc memset .include "mem.inc" - ;;put what to recursive write in Y. - LDX #$0 - TAY + LDY #$00 loop: - ;;write to byte - TYA - STA (B_start ,X) + STA (A_start), Y + INY + BEQ y_overflow +change_length: + DEC length + BNE loop - Add_16 B_start, B_start +1, #$01, #$00 + DEC length +1 + BPL loop + JMP loop_end +y_overflow: + LDY #$00 + INC B_start + 1 + INC A_start + 1 - LDA B_start - CMP B_end - BEQ test - jmp loop -test: - LDA B_start +1 - CMP B_end +1 - BEQ end - jmp loop -end: - ;;Dont forget to rewrite last byte - TYA - STA (B_start, X) - RTS + jmp change_length +loop_end: + RTS .endproc diff --git a/wip-hugo/routines/memory/memset_test.s b/wip-hugo/routines/memory/memset_test.s new file mode 100644 index 0000000..ff78baf --- /dev/null +++ b/wip-hugo/routines/memory/memset_test.s @@ -0,0 +1,9 @@ +.scope memset_test + .include "mem.inc" + VIC_bank = $4000 + len = $1f40 + Mov_16 A_start, A_start + 1, #VIC_bank + Mov_16 length, length + 1, #len + LDA #%01010101 + JSR memset +.endscope diff --git a/wip-hugo/source.s b/wip-hugo/source.s index 66e0ec6..aaf40c6 100755 --- a/wip-hugo/source.s +++ b/wip-hugo/source.s @@ -8,10 +8,11 @@ .include "STARTUP.s" ;.include "dubbel_buffer/raster_irqs.s" -;.include "routines/line/line_test.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/memcpy_test.s" +.include "routines/memory/memset_test.s" ;.include "routines/triangle/triangle_test.s" exit: JMP exit