c64-livecoding/wip-hugo/routines/memory/memcpy.s

39 lines
1.2 KiB
ArmAsm

;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;############ HANDLES BIG MEMORY MANAGMENTS ############
;;Move memory from B_start B_end to A_start , (implied address)
;; B_start and B_end gets modified under execution.
.proc memcpy
A_start = $FAFB
B_start = $FCFD
B_end = $FEFF
;; 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, >B_start, #$00
;;Lets move B_start lover-nibble to Y
LDY >B_start
LDA #$00
STA >B_start
loop:
;Lag_16 >B_end, <B_end, >B_start, <B_start, end_loop
Lag_16y >B_end, <B_end, <B_start, end_loop
;Lag_16y <B_start, >B_end, <B_end, end_loop ; IF B_end >B_start stop the 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
BNE loop
;BPL loop; Branch if Y dont overflow
;; Fix overflow
LDY #$00
INC <A_start
INC <B_start
JMP loop
end_loop:
RTS
.endproc