rewrite memcpy to work more like c:s implementation

This commit is contained in:
hugova 2025-05-15 16:11:51 +02:00
parent 3295b71f6b
commit f8dbfd86f9
4 changed files with 29 additions and 42 deletions

View file

@ -3,4 +3,5 @@
;; public args ;; public args
A_start = $D0 ; 16-bit value (uses D1) A_start = $D0 ; 16-bit value (uses D1)
B_start = $D2 ; 16-bit value (uses D3) 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

View file

@ -1,33 +1,31 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;Move memory from B_start B_end to A_start , (implied address) ;;Move length bytes from A_start address to lenght bytes starting at B_start.
;;Modifies A,X and B_start gets modified
.proc memcpy .proc memcpy
.include "mem.inc" .include "mem.inc"
LDY #$00
;; 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
loop: loop:
Lag_16 B_end, B_end + 1, A, B_start, end_loop
LDA (B_start), Y LDA (B_start), Y
STA (A_start), Y STA (A_start), Y
;Tip save time by counting downward, fast to check if Y ==0 // hugo
INY INY
TYA BEQ y_overflow
CMP #$ff change_length:
DEC length
BNE loop BNE loop
;; Fix overflow
LDY #$00 ;;check if length hi byte is 0. if it is end this
INC A_start + 1 LDA length + 1
INC B_start + 1 BEQ loop_end
DEC length +1
JMP loop JMP loop
end_loop: y_overflow:
LDY #$00
INC B_start + 1
INC A_start + 1
jmp change_length
loop_end:
RTS RTS
.endproc .endproc

View file

@ -1,25 +1,13 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; test for memcpy ;; test for memcpy
;; Writes text to half the screen
.scope memcpy_test .scope memcpy_test
charset = $FB .include "mem.inc"
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
VIC_bank = $4000 VIC_bank = $4000
VIC_bank_end = VIC_bank + $3FFF Character_generator_ROM = $D000
len = $1f40
Mov_16 A_start, A_start + 1, #<VIC_bank, #>VIC_bank Mov_16 A_start, A_start + 1, #<VIC_bank, #>VIC_bank
LDA #$00 Mov_16 B_start, B_start + 1, #<Character_generator_ROM, #>Character_generator_ROM
Mov_16 length, length + 1, #<len, #>len
JSR memcpy JSR memcpy
STA petski_position
jmp exit
.endscope .endscope

View file

@ -10,8 +10,8 @@
;.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/triangle/triangle_test.s" ;.include "routines/triangle/triangle_test.s"
exit: exit:
JMP exit JMP exit