From 0385f54e5a772cdf673081206e27d4ff949dd0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Wed, 27 Sep 2023 09:28:13 +0200 Subject: [PATCH] Develop (#14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adding more stuff to global * copy large mem backward sub added * update README.md --------- Co-authored-by: Maciej Małecki --- README.md | 8 ++- lib/mem-global.asm | 2 + lib/sub/copy-large-mem-backward.asm | 71 +++++++++++++++++++++++++++ spec/copy-large-mem-backward.spec.asm | 60 ++++++++++++++++++++++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 lib/sub/copy-large-mem-backward.asm create mode 100644 spec/copy-large-mem-backward.spec.asm diff --git a/README.md b/README.md index 514acf1..6fd6c21 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,16 @@ Check our [User's Manual](https://c64lib.github.io/user-manual/#_common) for mor ## Change log +### Changes in version 0.5.0 + +* New macro exposed: `c64lib_copy8` +* New macro exposed: `c64lib_copy16` +* New subroutine: `copy-large-mem-backward.asm` + ### Changes in version 0.4.0 * New macro: `compress.asm\compressRLE`. -* New subroutine: `decompress_rle.asm`. +* New subroutine: `decompress-rle.asm`. ### Changes in version 0.3.0 diff --git a/lib/mem-global.asm b/lib/mem-global.asm index 6a90cee..a80137a 100644 --- a/lib/mem-global.asm +++ b/lib/mem-global.asm @@ -30,6 +30,8 @@ .macro @c64lib_fillScreen(address, value) { fillScreen(address, value) } .macro @c64lib_set8(value, mem) { set8(value, mem) } .pseudocommand @c64lib_set8 value : mem { set8 value : mem } +.pseudocommand @c64lib_copy8 source: dest { copy8 source: dest } +.pseudocommand @c64lib_copy16 source: dest { copy16 source: dest } .macro @c64lib_set16(value, mem) { set16(value, mem) } .macro @c64lib_copyWordIndirect(source, destinationPointer) { copyWordIndirect(source, destinationPointer) } .macro @c64lib_cmp16(value, low) { cmp16(value, low) } diff --git a/lib/sub/copy-large-mem-backward.asm b/lib/sub/copy-large-mem-backward.asm new file mode 100644 index 0000000..0ed5ed0 --- /dev/null +++ b/lib/sub/copy-large-mem-backward.asm @@ -0,0 +1,71 @@ +/* + * MIT License + * + * Copyright (c) 2017-2023 c64lib + * Copyright (c) 2017-2023 Maciej Małecki + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#import "../invoke.asm" +#import "../mem.asm" +#import "../math.asm" + +/* + * Copies block of memory backward. Both source and target memory block can overlap as long as target + * block is located lower than source block. + * + * IN: + * Stack WORD - source address + * Stack WORD - target address + * Stack WORD - size + * MOD: A, X + */ +.namespace c64lib { + copyLargeMemBackward: { + + invokeStackBegin(returnPtr) + pullParamW(copyCounter) + pullParamW(staNext) + pullParamW(ldaNext) + + // addMem16(copyCounter, staNext) + // addMem16(copyCounter, ldaNext) + copyNextPage: + ldx #0 + copyNext: + lda ldaNext:$ffff, x + sta staNext:$ffff, x + dec16(copyCounter) + cmp16(0, copyCounter) + beq end + inx + cpx #0 + bne copyNext + add16(256, ldaNext) + add16(256, staNext) + jmp copyNextPage + end: + + invokeStackEnd(returnPtr) + rts + // local vars + returnPtr: .word 0 + copyCounter: .word 0 + } +} diff --git a/spec/copy-large-mem-backward.spec.asm b/spec/copy-large-mem-backward.spec.asm new file mode 100644 index 0000000..3859fa8 --- /dev/null +++ b/spec/copy-large-mem-backward.spec.asm @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2017-2023 c64lib + * Copyright (c) 2017-2023 Maciej Małecki + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#import "64spec/lib/64spec.asm" +#import "../lib/invoke-global.asm" + + +sfspec: init_spec() + + describe("copyLargeMemBackward") + + it("copies 7 bytes forward non overlapping"); { + c64lib_pushParamW(dataToBeMoved) + c64lib_pushParamW(targetLocation) + c64lib_pushParamW(7) + jsr copyLargeMemForward + + assert_bytes_equal 7: targetLocation: dataToBeMoved + } + + it("copies 260 bytes forward non overlapping"); { + c64lib_pushParamW(largeDataToBeMoved) + c64lib_pushParamW(largeTargetLocation) + c64lib_pushParamW(260) + jsr copyLargeMemForward + + assert_bytes_equal 19: largeTargetLocation: largeDataToBeMoved + } + +finish_spec() + +* = * "Data" +copyLargeMemForward: + #import "../lib/sub/copy-large-mem-forward.asm" +dataToBeMoved: .text "foo bar" +targetLocation: .text " " + +largeDataToBeMoved: .fill 260, 127.5 + sin(toRadians(i*360/256)) +largeTargetLocation: .fill 260, 0