diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2020-11-20 11:50:47 -0500 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2020-11-20 11:50:47 -0500 |
commit | dc7ebb9d424bb39d59f09b8498746beb871c46f4 (patch) | |
tree | 69b6e2f4bd1fd488ce85e680c3d550e56fa40572 /programs/sub-suite/libc.s | |
parent | 6a88d1af2ee5894365a56af89a6e97140f3e804d (diff) |
- 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.
Diffstat (limited to 'programs/sub-suite/libc.s')
-rw-r--r-- | programs/sub-suite/libc.s | 31 |
1 files changed, 31 insertions, 0 deletions
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. |