From e21aae6d08b05e8d4fceb0d32d96ea85c1277861 Mon Sep 17 00:00:00 2001 From: ry755 Date: Fri, 11 Feb 2022 19:39:33 -0800 Subject: [PATCH] fox32rom: Add some convenience routines for copying memory --- main.asm | 1 + memory.asm | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 memory.asm diff --git a/main.asm b/main.asm index 93fa623..706c425 100644 --- a/main.asm +++ b/main.asm @@ -165,6 +165,7 @@ mount_boot_disk: #include "boot.asm" #include "background.asm" #include "overlay.asm" + #include "memory.asm" #include "menu.asm" #include "submenu.asm" #include "event.asm" diff --git a/memory.asm b/memory.asm new file mode 100644 index 0000000..a94efa7 --- /dev/null +++ b/memory.asm @@ -0,0 +1,51 @@ +; memory copy routines + +; copy specified number of bytes from source pointer to destination pointer +; if the source and destination overlap, the behavior is undefined +; inputs: +; r0: pointer to source +; r1: pointer to destinaton +; r2: number of bytes to copy +; outputs: +; none +copy_memory_bytes: + push r0 + push r1 + push r31 + + mov r31, r2 +copy_memory_bytes_loop: + mov.8 [r1], [r0] + inc r0 + inc r1 + loop copy_memory_bytes_loop + + pop r31 + pop r1 + pop r0 + ret + +; copy specified number of words from source pointer to destination pointer +; if the source and destination overlap, the behavior is undefined +; inputs: +; r0: pointer to source +; r1: pointer to destinaton +; r2: number of words to copy +; outputs: +; none +copy_memory_words: + push r0 + push r1 + push r31 + + mov r31, r2 +copy_memory_words_loop: + mov [r1], [r0] + add r0, 4 + add r1, 4 + loop copy_memory_words_loop + + pop r31 + pop r1 + pop r0 + ret \ No newline at end of file