From dc7ebb9d424bb39d59f09b8498746beb871c46f4 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 20 Nov 2020 11:50:47 -0500 Subject: - Cleaned up a bit of the code. - Made the debug print for the CPU flags more readable. - Started work on implementing line number support into SuBAsm. --- programs/sub-suite/libc.s | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'programs/sub-suite/libc.s') diff --git a/programs/sub-suite/libc.s b/programs/sub-suite/libc.s index 18c10db..74ad654 100644 --- a/programs/sub-suite/libc.s +++ b/programs/sub-suite/libc.s @@ -508,3 +508,34 @@ free: plb.q ; Restore B. pla.q ; Restore A. rts ; End of free. + + +; memcpy: memory to memory copy. +; Input: A = Destination pointer. B = Source pointer. Y = Number of bytes to copy. +; Output: A = Destination pointer. +; Caller preserved registers: none. +; Callie preserved registers: none. + +memcpy: + pha.q ; Preserve the return value. + pha.q ; Push the destination pointer on the stack. + phb.q ; Push the source pointer on the stack. + phy.q ; Push the size on the stack. + and #0 ; Reset A. + tab ; Reset B. + cpy #0 ; Is the size zero? + beq @end ; Yes, so we're done. +@loop: + lda (sp+9) ; Get a byte from the source. + sta (sp+17) ; Copy it to the destination. + inc.q sp+9 ; Increment the source pointer. + inc.q sp+17 ; Increment the destination pointer. + dey ; Decrement the size. + beq @end ; The size is zero, so we're done. + bra @loop ; Keep looping. +@end: + pla.q ; Clean up the stack frame. + pla.q ; + pla.q ; + pla.q ; Restore the return value. + rts ; End of memcpy. -- cgit v1.2.3-13-gbd6f