├── .circleci └── config.yml ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib ├── common-global.asm ├── common.asm ├── compress-global.asm ├── compress.asm ├── invoke-global.asm ├── invoke.asm ├── math-global.asm ├── math.asm ├── mem-global.asm ├── mem.asm └── sub │ ├── copy-large-mem-backward.asm │ ├── copy-large-mem-forward.asm │ ├── decompress-rle.asm │ ├── fill-mem.asm │ ├── fill-screen.asm │ └── rotate-mem-right.asm ├── settings.gradle └── spec ├── copy-large-mem-backward.spec.asm ├── copy-large-mem-forward.spec.asm ├── decompress-rle.spec.asm ├── decompress-rle.test-data.txt ├── math-add16.spec.asm ├── math-dec16.spec.asm ├── mem-cmp16.spec.asm └── rotate-mem-right.spec.asm /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Java Gradle CircleCI 2.0 configuration file 2 | version: 2 3 | jobs: 4 | build: 5 | branches: 6 | only: 7 | - master 8 | - develop 9 | docker: 10 | - image: maciejmalecki/c64libci:0.1.7 11 | 12 | working_directory: ~/repo 13 | 14 | environment: 15 | JVM_OPTS: -Xmx3200m 16 | TERM: dumb 17 | 18 | steps: 19 | - checkout 20 | 21 | - run: ./gradlew licenseAsm build 22 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | gradlew text eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # KickAssembler out files 2 | *.prg 3 | *.sym 4 | *.dbg 5 | *.vs 6 | *.specOut 7 | .asminfo.txt 8 | .source.txt 9 | 10 | # Gradle files 11 | .gradle 12 | 13 | # IDE and tool files 14 | .idea 15 | .ra 16 | .vscode 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2023 c64lib 4 | Copyright (c) 2017-2023 Maciej Małecki 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # c64lib/common 2 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 3 | [![CircleCI](https://circleci.com/gh/c64lib/common/tree/master.svg?style=shield)](https://circleci.com/gh/c64lib/common/tree/master) 4 | [![CircleCI](https://circleci.com/gh/c64lib/common/tree/develop.svg?style=shield)](https://circleci.com/gh/c64lib/common/tree/develop) 5 | [![Gitter](https://badges.gitter.im/c64lib/community.svg)](https://gitter.im/c64lib/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 6 | 7 | Check our [User's Manual](https://c64lib.github.io/user-manual/#_common) for more documentation on this library. 8 | 9 | ## Change log 10 | 11 | ### Changes in version 0.5.0 12 | 13 | * New macro exposed: `c64lib_copy8` 14 | * New macro exposed: `c64lib_copy16` 15 | * New subroutine: `copy-large-mem-backward.asm` 16 | 17 | ### Changes in version 0.4.0 18 | 19 | * New macro: `compress.asm\compressRLE`. 20 | * New subroutine: `decompress-rle.asm`. 21 | 22 | ### Changes in version 0.3.0 23 | 24 | * New macro: `math.asm/mulAndAdd` - multiple two numbers and add result to memory location. 25 | 26 | ### Changes in version 0.2.0 27 | 28 | * Public elements of library are also declared as global symbols in "-global.asm" files using `c64lib_` name prefix. 29 | 30 | * New macro: `common.asm/fbne` - far bne. 31 | * New macro: `common.asm/fbmi` - far bmi. 32 | * New macro: `common.asm/ch` - to define single line of hires character. 33 | * New macro: `common.asm/cm` - to define single line of multicolor character. 34 | 35 | * New pseudocommand: `math.asm/add16` - add two 16-bit values. 36 | * New pseudocommand: `math.asm/sub16` - subtract two 16-bit values. 37 | * New pseudocommand: `math.asm/asl16` - 16-bit asl operation. 38 | * New pseudocommand: `math.asm/inc16` - increment 16-bit number. 39 | * New pseudocommand: `math.asm/dec16` - decrement 16-bit number. 40 | 41 | * New pseudocommand: `mem.asm/copy16` - copies 16-bit number. 42 | * New pseudocommand: `mem.asm/copy8` - copies 8-bit number. 43 | * New pseudocommand: `mem.asm/set8` - sets 8-bit number to given value. 44 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "com.github.c64lib.retro-assembler" version "1.6.0" 3 | id "com.github.hierynomus.license" version "0.16.1" 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | license { 11 | header = file("LICENSE") 12 | excludes([".ra"]) 13 | include "**/*.asm" 14 | mapping { 15 | asm = 'SLASHSTAR_STYLE' 16 | } 17 | } 18 | 19 | task licenseFormatAsm(type: com.hierynomus.gradle.license.tasks.LicenseFormat) { 20 | source = fileTree(dir: ".").include("**/*.asm").exclude(".ra") 21 | } 22 | task licenseAsm(type: com.hierynomus.gradle.license.tasks.LicenseCheck) { 23 | source = fileTree(dir: ".").include("**/*.asm").exclude(".ra") 24 | } 25 | licenseFormat.dependsOn licenseFormatAsm 26 | 27 | retroProject { 28 | dialect = "KickAssembler" 29 | dialectVersion = "5.25" 30 | libDirs = [".ra/deps/c64lib"] 31 | srcDirs = ["lib"] 32 | libFromGitHub "c64lib/64spec", "0.7.0pr" 33 | } 34 | 35 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c64lib/common/0385f54e5a772cdf673081206e27d4ff949dd0a6/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c64lib/common/0385f54e5a772cdf673081206e27d4ff949dd0a6/gradlew -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /lib/common-global.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "common.asm" 26 | #importonce 27 | 28 | .filenamespace c64lib 29 | 30 | .macro @c64lib_ch(data) { ch(data) } 31 | .macro @c64lib_cm(data) { cm(data) } 32 | -------------------------------------------------------------------------------- /lib/common.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #importonce 26 | .filenamespace c64lib 27 | 28 | /* 29 | * Why Kickassembler does not support bitwise negation on numerical values? 30 | * 31 | * Params: 32 | * value: byte to be negated 33 | */ 34 | .function neg(value) { 35 | .return value ^ $FF 36 | } 37 | .assert "neg($00) gives $FF", neg($00), $FF 38 | .assert "neg($FF) gives $00", neg($FF), $00 39 | .assert "neg(%10101010) gives %01010101", neg(%10101010), %01010101 40 | 41 | /* 42 | * Increases argument by one preserving its type (addressing mode). To be used in pseudocommands. 43 | * 44 | * Params: 45 | * arg: mnemonic argument 46 | */ 47 | .function incArgument(arg) { 48 | .return CmdArgument(arg.getType(), arg.getValue() + 1) 49 | } 50 | 51 | /* 52 | * "Far" bne branch. Depending on the jump length it either does bne or beq/jmp trick. 53 | */ 54 | .macro fbne(label) { 55 | here: // we have to add 2 to "here", because relative jump is counted right after bne xx, and this instruction takes 2 bytes 56 | .if (here > label) { 57 | // jump back 58 | .if (here + 2 - label <= 128) { 59 | bne label 60 | } else { 61 | beq skip 62 | jmp label 63 | skip: 64 | } 65 | } else { 66 | // jump forward 67 | .if (label - here - 2 <= 127) { 68 | bne label 69 | } else { 70 | beq skip 71 | jmp label 72 | skip: 73 | } 74 | } 75 | } 76 | 77 | /* 78 | * "Far" bmi branch. Depending on the jump length it either does bne or beq/jmp trick. 79 | */ 80 | .macro fbmi(label) { 81 | here: // we have to add 2 to "here", because relative jump is counted right after bne xx, and this instruction takes 2 bytes 82 | .if (here > label) { 83 | // jump back 84 | .if (here + 2 - label <= 128) { 85 | bmi label 86 | } else { 87 | bpl skip 88 | beq skip 89 | jmp label 90 | skip: 91 | } 92 | } else { 93 | // jump forward 94 | .if (label - here - 2 <= 127) { 95 | bmi label 96 | } else { 97 | bpl skip 98 | beq skip 99 | jmp label 100 | skip: 101 | } 102 | } 103 | } 104 | 105 | /* 106 | * Convert kbytes to bytes. 107 | */ 108 | .function toBytes(value) { 109 | .return value * 1024 110 | } 111 | 112 | .function convertHires(data) { 113 | .var result = "" 114 | .for(var i = 0; i < data.size(); i++) { 115 | .var ch = data.charAt(i) 116 | .if (ch == '.') { 117 | .eval result = result + '0' 118 | } else { 119 | .eval result = result + '1' 120 | } 121 | } 122 | .return result.asNumber(2) 123 | } 124 | .assert @"convertHires(\"........\") = 0", convertHires("........"), 0 125 | .assert @"convertHires(\".......#\") = 1", convertHires(".......#"), 1 126 | .assert @"convertHires(\"########\") = 255", convertHires("########"), 255 127 | 128 | .function convertMultic(data) { 129 | .var result = "" 130 | .for(var i = 0; i < data.size(); i++) { 131 | .var ch = data.charAt(i) 132 | .if (ch == '.') .eval result = result + "00" 133 | .if (ch == '#') .eval result = result + "11" 134 | .if (ch == '+') .eval result = result + "01" 135 | .if (ch == 'o') .eval result = result + "10" 136 | } 137 | .return result.asNumber(2) 138 | } 139 | .assert @"convertMultic(\"....\") = 0", convertMultic("...."), 0 140 | .assert @"convertMultic(\"...#\") = 3", convertMultic("...#"), 3 141 | .assert @"convertMultic(\"####\") = 255", convertMultic("####"), 255 142 | 143 | .macro ch(data) { 144 | .byte convertHires(data.substring(0, 8)) 145 | } 146 | 147 | .macro cm(data) { 148 | .byte convertMultic(data.substring(0, 4)) 149 | } 150 | -------------------------------------------------------------------------------- /lib/compress-global.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "compress.asm" 26 | #importonce 27 | 28 | .filenamespace c64lib 29 | 30 | .macro @c64lib_compressRLE(data) { compressRLE(data) } 31 | -------------------------------------------------------------------------------- /lib/compress.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #importonce 26 | .filenamespace c64lib 27 | 28 | /* 29 | * Performs RLE (Running Length Encoding) compression of given binary data (kick assembler data type). 30 | * The compressed result is placed as is in the result file starting from the place where this macro is called. 31 | */ 32 | .macro compressRLE(binaryData) { 33 | .var runLength = 0 34 | .var runValue = 0 35 | .var crunchedLength = 0 36 | .for(var i = 0; i < binaryData.getSize(); i++) { 37 | .if(runLength > 0 && (binaryData.get(i) != runValue || runLength == $ff)) { 38 | .byte runLength 39 | .byte runValue 40 | .eval runLength = 0 41 | .eval crunchedLength = crunchedLength + 2 42 | } 43 | .if(runLength == 0) { 44 | .eval runValue = binaryData.get(i) 45 | .eval runLength = 1 46 | } else { 47 | .eval runLength++ 48 | } 49 | } 50 | .byte runLength 51 | .byte runValue 52 | .byte $00 // end mark 53 | .eval crunchedLength++ 54 | .print "Crunched from " + binaryData.getSize() + " to " + crunchedLength + " (" + round((crunchedLength/binaryData.getSize())*100) + "%)" 55 | } 56 | -------------------------------------------------------------------------------- /lib/invoke-global.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "mem.asm" 26 | #importonce 27 | .filenamespace c64lib 28 | 29 | .macro @c64lib_invokeStackBegin(placeholderPtr) { invokeStackBegin(placeholderPtr) } 30 | .macro @c64lib_invokeStackEnd(placeholderPtr) { invokeStackEnd(placeholderPtr) } 31 | .macro @c64lib_pushParamB(value) { pushParamB(value) } 32 | .macro @c64lib_pushParamW(value) { pushParamW(value) } 33 | .macro @c64lib_pushParamBInd(ptr) { pushParamBInd(ptr) } 34 | .macro @c64lib_pushParamWInd(ptr) { pushParamWInd(ptr) } 35 | .macro @c64lib_pullParamB(placeholderPtr) { pullParamB(placeholderPtr) } 36 | .macro @c64lib_pullParamW(placeholderPtr) { pullParamW(placeholderPtr) } 37 | .macro @c64lib_pullParamWList(placeholderPtrList) { pullParamWList(placeholderPtrList) } 38 | -------------------------------------------------------------------------------- /lib/invoke.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | /* 26 | * Set of KickAssembler macros for subroutine implementation. 27 | * 28 | * With these macros one can realize communication with subroutines using stack. This approach 29 | * is following: 30 | * 1) subroutine caller prepares input parameters and pushes them to the stack using push*() macros 31 | * 2) subroutine is then called using JSR 32 | * 3) subroutine first preserves return address in local variable using invokeStackBegin(variablePtr) macro 33 | * 4) subroutine then pulls all pushed parameters in opposite order using pull*() macros 34 | * 5) when subroutine is about to end, just before RTS is called, it must restore return address with invokeStackEnd(varPtr) macro 35 | * 36 | * Requires KickAssembler v4.x 37 | * (c) 2017-2018 Maciej Malecki 38 | */ 39 | #importonce 40 | .filenamespace c64lib 41 | 42 | /* 43 | * Preserves return address that is used with JSR. 44 | * Should be called at beginning of subroutine. 45 | * 46 | * Params: 47 | * placeholderPtr - pointer to the memory location (that is local variable of the subroutine) 48 | * where return address will be preserved. 49 | */ 50 | .macro invokeStackBegin(placeholderPtr) { 51 | pla 52 | sta placeholderPtr 53 | pla 54 | sta placeholderPtr + 1 55 | } 56 | 57 | /* 58 | * Restores return address that will be then used with RTS. 59 | * Should be called at the very end of subroutine just before RTS. 60 | * 61 | * Params: 62 | * placeholderPtr - pointer to the memory location (that is local variable of the subroutine) 63 | * from where return address will be restored. 64 | */ 65 | .macro invokeStackEnd(placeholderPtr) { 66 | lda placeholderPtr + 1 67 | pha 68 | lda placeholderPtr 69 | pha 70 | } 71 | 72 | /* 73 | * Pushes byte value as a parameter to the subroutine. 74 | * Such value should be then pulled in subroutine in opposite order. 75 | * 76 | * Params: 77 | * value - byte value of the parameter for subroutine 78 | */ 79 | .macro pushParamB(value) { 80 | lda #value 81 | pha 82 | } 83 | 84 | /* 85 | * Pushes two bytes value as a parameter to the subroutine. 86 | * Such value should be then pulled in subroutine in opposite order. 87 | * 88 | * Params: 89 | * value - word value of the parameter for subroutine 90 | */ 91 | .macro pushParamW(value) { 92 | pushParamB(value) 94 | } 95 | 96 | /* 97 | * Pushes byte pointed by an address as a parameter to the subroutine. 98 | * Such value should be then pulled in subroutine in opposite order. 99 | * 100 | * Params: 101 | * ptr - pointer to the byte value of the parameter for subroutine 102 | */ 103 | .macro pushParamBInd(ptr) { 104 | lda ptr 105 | pha 106 | } 107 | 108 | /* 109 | * Pushes two bytes value pointed by an address as a parameter to the subroutine. 110 | * Such value should be then pulled in subroutine in opposite order. 111 | * 112 | * Params: 113 | * ptr - pointer to the two bytes value of the parameter for subroutine 114 | */ 115 | .macro pushParamWInd(ptr) { 116 | pushParamBInd(ptr) 117 | pushParamBInd(ptr + 1) 118 | } 119 | 120 | /* 121 | * Pulls byte value from the stack and stores it under given address. 122 | * 123 | * Params: 124 | * placeholderPtr - pointer to the memory location where given byte will be pulled to 125 | */ 126 | .macro pullParamB(placeholderPtr) { 127 | pla 128 | sta placeholderPtr 129 | } 130 | 131 | /* 132 | * Pulls two bytes value from the stack and stores it under given address. 133 | * 134 | * Params: 135 | * placeholderPtr - pointer to the beginning of memory location where given two bytes will be pulled to 136 | */ 137 | .macro pullParamW(placeholderPtr) { 138 | pullParamB(placeholderPtr + 1) 139 | pullParamB(placeholderPtr) 140 | } 141 | 142 | /* 143 | * Pulls two bytes value from the stack and stores it under provided addresses. 144 | * 145 | * Params: 146 | * placeholderPtrList - List of memory locations, where given two byte value will be stored 147 | */ 148 | .macro pullParamWList(placeholderPtrList) { 149 | .assert "list must be non empty", placeholderPtrList.size() > 0, true 150 | pla 151 | .for (var i = 0; i < placeholderPtrList.size(); i++) sta placeholderPtrList.get(i) + 1 152 | pla 153 | .for (var i = 0; i < placeholderPtrList.size(); i++) sta placeholderPtrList.get(i) 154 | } 155 | .assert "pullParamWList([$aaaa, $bbbb])", {pullParamWList(List().add($aaaa, $bbbb))}, 156 | {pla;sta $aaaa + 1; sta $bbbb + 1; pla; sta $aaaa; sta $bbbb} 157 | -------------------------------------------------------------------------------- /lib/math-global.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "math.asm" 26 | #importonce 27 | .filenamespace c64lib 28 | 29 | .macro @c64lib_add16(value, low) { add16(value, low) } 30 | .pseudocommand @c64lib_add16 value : low { add16 value : low } 31 | .macro @c64lib_sub16(value, low) { sub16(value, low) } 32 | .macro @c64lib_addMem16(source, destination) { addMem16(source, destination ) } 33 | .macro @c64lib_asl16(low) { asl16(low) } 34 | .macro @c64lib_inc16(destination) { inc16(destination) } 35 | .macro @c64lib_dec16(destination) { dec16(destination) } 36 | .macro @c64lib_mulAndAdd(left, right, targetAddr) { mulAndAdd(left, right, targetAddr) } 37 | -------------------------------------------------------------------------------- /lib/math.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "common.asm" 26 | #importonce 27 | .filenamespace c64lib 28 | 29 | /* 30 | * Adds 16 bit number "value" to given memory cell specified by "low" address. 31 | * 32 | * MOD: A, C 33 | */ 34 | .macro add16(value, dest) { 35 | clc 36 | lda dest 37 | adc #value 41 | sta dest + 1 42 | } 43 | .assert "add16($0102, $A000) ", { add16($0102, $A000) }, { 44 | clc; lda $A000; adc #$02; sta $A000 45 | lda $A001; adc #$01; sta $A001 46 | } 47 | 48 | /* 49 | * Subtracts 16 bit number "value" from given memory cell specified by "low" address. 50 | * 51 | * MOD: A, C 52 | */ 53 | .macro sub16(value, low) { 54 | sec 55 | lda low 56 | sbc #value 60 | sta low + 1 61 | } 62 | .assert "sub16($0102, $A000)", { sub16($0102, $A000) }, { 63 | sec; lda $A000; sbc #$02; sta $A000 64 | lda $A001; sbc #$01; sta $A001 65 | } 66 | .assert "sub16(256, $A000)", { sub16(256, $A000) }, { 67 | sec; lda $A000; sbc #0; sta $A000 68 | lda $A001; sbc #1; sta $A001 69 | } 70 | 71 | /* 72 | * Adds value from "source" memory location to value in "destination" memory location. 73 | * 74 | * MOD: A, C 75 | */ 76 | .macro addMem16(source, destination) { 77 | add16 source:destination 78 | } 79 | .assert "addMem16($A000, $B000)", { addMem16($A000, $B000) }, { 80 | clc; lda $A000; adc $B000; sta $B000 81 | lda $A001; adc $B001; sta $B001 82 | } 83 | 84 | /* 85 | * Adds value from "source" memory location to value in "destination" memory location. 86 | * 87 | * MOD: A, C 88 | */ 89 | .pseudocommand add16 source : destination { 90 | clc 91 | lda source 92 | adc destination 93 | sta destination 94 | lda incArgument(source) 95 | adc incArgument(destination) 96 | sta incArgument(destination) 97 | } 98 | 99 | /* 100 | * Subtracts value from "source" memory location from value in "destination" memory location. 101 | * 102 | * MOD: A, C 103 | */ 104 | .macro subMem16(source, destination) { 105 | sub16 source : destination 106 | } 107 | .assert "subMem16($A000, $B000)", { subMem16($A000, $B000) }, { 108 | sec; lda $B000; sbc $A000; sta $B000 109 | lda $B001; sbc $A001; sta $B001 110 | } 111 | 112 | /* 113 | * Subtracts value from "source" memory location from value in "destination" memory location. 114 | * 115 | * MOD: A, C 116 | */ 117 | .pseudocommand sub16 source : destination { 118 | sec 119 | lda destination 120 | sbc source 121 | sta destination 122 | lda incArgument(destination) 123 | sbc incArgument(source) 124 | sta incArgument(destination) 125 | } 126 | 127 | /* 128 | * Shifts left 2 byte number specified with "low" address. Carry flag indicates last bit that has been "shifted out". 129 | * 130 | * MOD: A, C 131 | */ 132 | .macro asl16(low) { 133 | asl16 low 134 | } 135 | 136 | /* 137 | * Shifts left 2 byte number specified with "low" address. Carry flag indicates last bit that has been "shifted out". 138 | * 139 | * MOD: A, C 140 | */ 141 | .pseudocommand asl16 low { 142 | clc 143 | asl low 144 | bcc !+ 145 | lda incArgument(low) 146 | asl 147 | ora #%1 148 | sta incArgument(low) 149 | !: 150 | } 151 | 152 | /* 153 | * Increments 16 bit number located in memory address starting from "destination". 154 | * 155 | * MOD: - 156 | */ 157 | .macro inc16(destination) { 158 | inc16 destination 159 | } 160 | 161 | /* 162 | * Increments 16 bit number located in memory address starting from "destination". 163 | * 164 | * MOD: - 165 | */ 166 | .pseudocommand inc16 destination { 167 | inc destination 168 | bne !+ 169 | inc incArgument(destination) 170 | !: 171 | } 172 | 173 | /* 174 | * Decrements 16 bit number located in memory address starting from "destination". 175 | * 176 | * MOD: - 177 | */ 178 | .macro dec16(destination) { 179 | dec16 destination 180 | } 181 | 182 | /* 183 | * Decrements 16 bit number located in memory address starting from "destination". 184 | * 185 | * MOD: - 186 | */ 187 | .pseudocommand dec16 destination { 188 | dec destination 189 | lda destination 190 | cmp #$ff 191 | bne !+ 192 | dec incArgument(destination) 193 | !: 194 | } 195 | 196 | /* 197 | * Multiplies left times right. Target value will be added to the value stored in targetAddr. 198 | * Mod: A, X 199 | */ 200 | .macro mulAndAdd(left, right, targetAddr) { 201 | ldx #right 202 | !: 203 | clc 204 | lda #left 205 | adc targetAddr 206 | sta targetAddr 207 | lda #0 208 | adc targetAddr + 1 209 | sta targetAddr + 1 210 | dex 211 | bne !- 212 | } 213 | -------------------------------------------------------------------------------- /lib/mem-global.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "mem.asm" 26 | #importonce 27 | .filenamespace c64lib 28 | 29 | .macro @c64lib_copyFast(source, destination, count) { copyFast(source, destination, count) } 30 | .macro @c64lib_fillScreen(address, value) { fillScreen(address, value) } 31 | .macro @c64lib_set8(value, mem) { set8(value, mem) } 32 | .pseudocommand @c64lib_set8 value : mem { set8 value : mem } 33 | .pseudocommand @c64lib_copy8 source: dest { copy8 source: dest } 34 | .pseudocommand @c64lib_copy16 source: dest { copy16 source: dest } 35 | .macro @c64lib_set16(value, mem) { set16(value, mem) } 36 | .macro @c64lib_copyWordIndirect(source, destinationPointer) { copyWordIndirect(source, destinationPointer) } 37 | .macro @c64lib_cmp16(value, low) { cmp16(value, low) } 38 | .macro @c64lib_rotateMemRightFast(startPtr, count) { rotateMemRightFast(startPtr, count) } 39 | -------------------------------------------------------------------------------- /lib/mem.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "invoke.asm" 26 | #import "math.asm" 27 | #importonce 28 | .filenamespace c64lib 29 | 30 | 31 | /* 32 | * MOS 650X Vector table constants. 33 | */ 34 | .label NMI_LO = $FFFA 35 | .label NMI_HI = $FFFB 36 | .label RESET_LO = $FFFC 37 | .label RESET_HI = $FFFD 38 | .label IRQ_LO = $FFFE 39 | .label IRQ_HI = $FFFF 40 | 41 | /* 42 | * Copies "count" bytes from memory location starting in "source" to memory location starting from "destination". 43 | * 44 | * MOD: A 45 | */ 46 | .macro copyFast(source, destination, count) { 47 | .for(var i = 0; i < count; i++) { 48 | lda source + i 49 | sta destination + i 50 | } 51 | } 52 | .assert "copyFast($A000, $B000, 0) copies nothing", { :copyFast($A000, $B000, 0) }, {} 53 | .assert "copyFast($A000, $B000, 1) copies one byte", { :copyFast($A000, $B000, 1) }, { 54 | lda $A000; sta $B000 55 | } 56 | .assert "copyFast($A000, $B000, 2) copies two bytes", { :copyFast($A000, $B000, 2) }, { 57 | lda $A000; sta $B000 58 | lda $A001; sta $B001 59 | } 60 | 61 | .pseudocommand copy16 source:destination { 62 | lda source 63 | sta destination 64 | lda incArgument(source) 65 | sta incArgument(destination) 66 | } 67 | 68 | .pseudocommand copy8 source:destination { 69 | lda source 70 | sta destination 71 | } 72 | 73 | /* 74 | * Fills 1kb of memory (screen) starting from "address" with given "value". 75 | * 76 | * MOD: A, X 77 | */ 78 | .macro fillScreen(address, value) { 79 | lda #value 80 | ldx #$00 81 | loop: 82 | sta address, x 83 | sta address + $0100, x 84 | sta address + $0200, x 85 | sta address + $0300, x 86 | inx 87 | bne loop 88 | } 89 | 90 | /* 91 | * Fills byte located in memory address "mem" with byte "value". 92 | * 93 | * MOD: A 94 | */ 95 | .macro set8(value, mem) { 96 | set8 #value : mem 97 | } 98 | 99 | .pseudocommand set8 value : mem { 100 | lda value 101 | sta mem 102 | } 103 | 104 | /* 105 | * Fills word located in memory address "mem" with byte "value". 106 | * 107 | * MOD: A 108 | */ 109 | .macro set16(value, mem) { 110 | :set8(value, mem + 1) 112 | } 113 | .assert "set16($1234, $A000) stores $34 under $A000 and $12 under $A001", { :set16($3412, $A000) }, { 114 | lda #$12 115 | sta $A000 116 | lda #$34 117 | sta $A001 118 | } 119 | 120 | .macro copyWordIndirect(source, destinationPointer) { 121 | ldy #0 122 | lda source 123 | sta (destinationPointer), y 124 | iny 125 | lda source + 1 126 | sta (destinationPointer), y 127 | } 128 | 129 | .macro cmp16(value, low) { 130 | lda #value 134 | cmp low + 1 135 | end: 136 | } 137 | 138 | .macro rotateMemRightFast(startPtr, count) { 139 | lda startPtr 140 | pha 141 | 142 | .for(var i = 0; i < count - 1; i++) { 143 | lda startPtr + i + 1 144 | sta startPtr + i 145 | } 146 | 147 | pla 148 | sta startPtr + count - 1 149 | } 150 | .assert "rotateMemRightFast($A000, 1) does (almost) nothing", { rotateMemRightFast($A000, 1) }, { 151 | lda $A000; pha 152 | pla; sta $A000 153 | } 154 | .assert "rotateMemRightFast($A000, 2) swaps values", { rotateMemRightFast($A000, 2) }, { 155 | lda $A000; pha 156 | lda $A001 157 | sta $A000 158 | pla; sta $A001 159 | } 160 | .assert "rotateMemRightFast($A000, 3) rotates 3 values", { rotateMemRightFast($A000, 3) }, { 161 | lda $A000; pha 162 | lda $A001 163 | sta $A000 164 | lda $A002 165 | sta $A001 166 | pla; sta $A002 167 | } 168 | .assert "rotateMemRightFast($A000, 7) rotates 7 values", { rotateMemRightFast($A000, 7) }, { 169 | lda $A000; pha 170 | lda $A001 171 | sta $A000 172 | lda $A002 173 | sta $A001 174 | lda $A003 175 | sta $A002 176 | lda $A004 177 | sta $A003 178 | lda $A005 179 | sta $A004 180 | lda $A006 181 | sta $A005 182 | pla; sta $A006 183 | } 184 | -------------------------------------------------------------------------------- /lib/sub/copy-large-mem-backward.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "../invoke.asm" 26 | #import "../mem.asm" 27 | #import "../math.asm" 28 | 29 | /* 30 | * Copies block of memory backward. Both source and target memory block can overlap as long as target 31 | * block is located lower than source block. 32 | * 33 | * IN: 34 | * Stack WORD - source address 35 | * Stack WORD - target address 36 | * Stack WORD - size 37 | * MOD: A, X 38 | */ 39 | .namespace c64lib { 40 | copyLargeMemBackward: { 41 | 42 | invokeStackBegin(returnPtr) 43 | pullParamW(copyCounter) 44 | pullParamW(staNext) 45 | pullParamW(ldaNext) 46 | 47 | // addMem16(copyCounter, staNext) 48 | // addMem16(copyCounter, ldaNext) 49 | copyNextPage: 50 | ldx #0 51 | copyNext: 52 | lda ldaNext:$ffff, x 53 | sta staNext:$ffff, x 54 | dec16(copyCounter) 55 | cmp16(0, copyCounter) 56 | beq end 57 | inx 58 | cpx #0 59 | bne copyNext 60 | add16(256, ldaNext) 61 | add16(256, staNext) 62 | jmp copyNextPage 63 | end: 64 | 65 | invokeStackEnd(returnPtr) 66 | rts 67 | // local vars 68 | returnPtr: .word 0 69 | copyCounter: .word 0 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/sub/copy-large-mem-forward.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "../invoke.asm" 26 | #import "../mem.asm" 27 | #import "../math.asm" 28 | 29 | /* 30 | * Copies block of memory forward. Both source and target memory block can overlap as long as target 31 | * block is located higher than source block. 32 | * 33 | * IN: 34 | * Stack WORD - source address 35 | * Stack WORD - target address 36 | * Stack WORD - size 37 | * MOD: A, X 38 | */ 39 | .namespace c64lib { 40 | copyLargeMemForward: { 41 | 42 | invokeStackBegin(returnPtr) 43 | pullParamW(copyCounter) 44 | pullParamW(staNext) 45 | pullParamW(ldaNext) 46 | 47 | addMem16(copyCounter, staNext) 48 | addMem16(copyCounter, ldaNext) 49 | copyNextPage: 50 | sub16(256, ldaNext) 51 | sub16(256, staNext) 52 | ldx #$ff 53 | copyNext: 54 | lda ldaNext:$ffff, x 55 | sta staNext:$ffff, x 56 | dec16(copyCounter) 57 | cmp16(0, copyCounter) 58 | beq end 59 | dex 60 | cpx #$ff 61 | bne copyNext 62 | jmp copyNextPage 63 | end: 64 | 65 | invokeStackEnd(returnPtr) 66 | rts 67 | // local vars 68 | returnPtr: .word 0 69 | copyCounter: .word 0 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/sub/decompress-rle.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "../invoke.asm" 26 | 27 | .namespace c64lib { 28 | 29 | /* 30 | * Stack: 31 | * source address (2 bytes) 32 | * dest address (2 bytes) 33 | */ 34 | decompressRLE: { 35 | invokeStackBegin(returnPtr) 36 | pullParamW(destination) 37 | pullParamW(source) 38 | invokeStackEnd(returnPtr) 39 | 40 | nextSequence: 41 | jsr loadSource 42 | cmp #0 43 | beq end // end mark 44 | tax // x <- run length 45 | jsr loadSource // a <- run value 46 | decrunch: 47 | sta destination:$ffff 48 | inc destination 49 | bne !+ 50 | inc destination + 1 51 | !: 52 | dex 53 | bne decrunch 54 | jmp nextSequence 55 | 56 | end: 57 | rts 58 | loadSource: 59 | lda source:$ffff 60 | inc source 61 | bne !+ 62 | inc source + 1 63 | !: 64 | rts 65 | // locals 66 | returnPtr: .word 0 67 | } 68 | } -------------------------------------------------------------------------------- /lib/sub/fill-mem.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "../invoke.asm" 26 | 27 | /* 28 | * Fills memory at given address with given value. 29 | * IN: 30 | * A - value 31 | * X - count 32 | * Stack WORD - address 33 | * OUT: 34 | * none 35 | * MOD: A, X 36 | */ 37 | .namespace c64lib { 38 | fillMem: { 39 | 40 | sta value + 1 // preserve A for later usage 41 | invokeStackBegin(returnPtr) 42 | pullParamW(address + 1) 43 | 44 | value: lda #$00 45 | loop: 46 | dex 47 | address: sta $ffff, x 48 | bne loop 49 | 50 | invokeStackEnd(returnPtr) 51 | rts 52 | // local vars 53 | returnPtr: .word 0 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/sub/fill-screen.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "../invoke.asm" 26 | #import "../math.asm" 27 | 28 | /* 29 | * Fills given 1024 bytes of memory with given byte. 30 | * IN: 31 | * A - value 32 | * Stack WORD - address 33 | * OUT: 34 | * none 35 | * MOD: A, X 36 | */ 37 | .namespace c64lib { 38 | fillScreen: { 39 | 40 | sta value + 1 41 | invokeStackBegin(returnPtr) 42 | pullParamWList(List().add(sta0 + 1, sta1 + 1, sta2 + 1, sta3 + 1)) 43 | add16($0100, sta1 + 1) 44 | add16($0200, sta2 + 1) 45 | add16($0300, sta3 + 1) 46 | 47 | value: lda #$00 48 | ldx #$00 49 | loop: 50 | sta0: sta $ffff, x 51 | sta1: sta $ffff, x 52 | sta2: sta $ffff, x 53 | sta3: sta $ffff, x 54 | inx 55 | bne loop 56 | 57 | invokeStackEnd(returnPtr) 58 | rts 59 | // local vars 60 | returnPtr: .word 0 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lib/sub/rotate-mem-right.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "../invoke.asm" 26 | 27 | /* 28 | * Rotates content of given memory area to the right. 29 | * IN: 30 | * X - count 31 | * Stack WORD - address 32 | * OUT: 33 | * none 34 | * MOD: 35 | * A, X 36 | */ 37 | .namespace c64lib { 38 | rotateMemRight: { 39 | 40 | invokeStackBegin(returnPtr) 41 | pullParamWList(List().add(loadFirst, loadNext, staNext, staLast)) 42 | 43 | lda loadFirst:$ffff, x 44 | sta preserve 45 | loop: 46 | dex 47 | lda loadNext:$ffff, x 48 | inx 49 | sta staNext:$ffff, x 50 | dex 51 | bne loop 52 | lda preserve 53 | sta staLast:$ffff 54 | 55 | invokeStackEnd(returnPtr) 56 | rts 57 | // local vars 58 | returnPtr: .word 0 59 | preserve: .byte 0 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | // pluginManagement { 2 | // resolutionStrategy { 3 | // eachPlugin { 4 | // if (requested.id.namespace == "org.github.c64lib.retro-assembler") { 5 | // useModule("org.github.c64lib.retro-assembler:com.github.c64lib.retro-assembler.gradle.plugin:${requested.version}") 6 | // } 7 | // } 8 | // } 9 | // repositories { 10 | // mavenLocal() 11 | // mavenCentral() 12 | // } 13 | // } 14 | -------------------------------------------------------------------------------- /spec/copy-large-mem-backward.spec.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "64spec/lib/64spec.asm" 26 | #import "../lib/invoke-global.asm" 27 | 28 | 29 | sfspec: init_spec() 30 | 31 | describe("copyLargeMemBackward") 32 | 33 | it("copies 7 bytes forward non overlapping"); { 34 | c64lib_pushParamW(dataToBeMoved) 35 | c64lib_pushParamW(targetLocation) 36 | c64lib_pushParamW(7) 37 | jsr copyLargeMemForward 38 | 39 | assert_bytes_equal 7: targetLocation: dataToBeMoved 40 | } 41 | 42 | it("copies 260 bytes forward non overlapping"); { 43 | c64lib_pushParamW(largeDataToBeMoved) 44 | c64lib_pushParamW(largeTargetLocation) 45 | c64lib_pushParamW(260) 46 | jsr copyLargeMemForward 47 | 48 | assert_bytes_equal 19: largeTargetLocation: largeDataToBeMoved 49 | } 50 | 51 | finish_spec() 52 | 53 | * = * "Data" 54 | copyLargeMemForward: 55 | #import "../lib/sub/copy-large-mem-forward.asm" 56 | dataToBeMoved: .text "foo bar" 57 | targetLocation: .text " " 58 | 59 | largeDataToBeMoved: .fill 260, 127.5 + sin(toRadians(i*360/256)) 60 | largeTargetLocation: .fill 260, 0 61 | -------------------------------------------------------------------------------- /spec/copy-large-mem-forward.spec.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "64spec/lib/64spec.asm" 26 | #import "../lib/invoke-global.asm" 27 | 28 | 29 | sfspec: init_spec() 30 | 31 | describe("copyLargeMemForward") 32 | 33 | it("copies 7 bytes forward non overlapping"); { 34 | c64lib_pushParamW(dataToBeMoved) 35 | c64lib_pushParamW(targetLocation) 36 | c64lib_pushParamW(7) 37 | jsr copyLargeMemForward 38 | 39 | assert_bytes_equal 7: targetLocation: dataToBeMoved 40 | } 41 | 42 | it("copies 260 bytes forward non overlapping"); { 43 | c64lib_pushParamW(largeDataToBeMoved) 44 | c64lib_pushParamW(largeTargetLocation) 45 | c64lib_pushParamW(260) 46 | jsr copyLargeMemForward 47 | 48 | assert_bytes_equal 19: largeTargetLocation: largeDataToBeMoved 49 | } 50 | 51 | finish_spec() 52 | 53 | * = * "Data" 54 | copyLargeMemForward: 55 | #import "../lib/sub/copy-large-mem-forward.asm" 56 | dataToBeMoved: .text "foo bar" 57 | targetLocation: .text " " 58 | 59 | largeDataToBeMoved: .fill 260, 127.5 + sin(toRadians(i*360/256)) 60 | largeTargetLocation: .fill 260, 0 61 | -------------------------------------------------------------------------------- /spec/decompress-rle.spec.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "64spec/lib/64spec.asm" 26 | #import "../lib/compress-global.asm" 27 | #import "../lib/invoke-global.asm" 28 | 29 | .var testData = LoadBinary("decompress-rle.test-data.txt") 30 | 31 | sfspec: init_spec() 32 | describe("decompressRLE") 33 | 34 | it("decompress data"); { 35 | c64lib_pushParamW(compressedData) 36 | c64lib_pushParamW(targetData) 37 | jsr decompressRLE 38 | 39 | assert_bytes_equal testData.getSize(): targetData: originalData 40 | } 41 | finish_spec() 42 | 43 | * = * "Data" 44 | decompressRLE: 45 | #import "../lib/sub/decompress-rle.asm" 46 | 47 | originalData: 48 | .fill testData.getSize(), testData.get(i) 49 | originalDataEnd: 50 | 51 | compressedData: 52 | c64lib_compressRLE(testData) 53 | compressedDataEnd: 54 | 55 | targetData: 56 | .fill testData.getSize(), 0 57 | targetDataEnd: 58 | -------------------------------------------------------------------------------- /spec/decompress-rle.test-data.txt: -------------------------------------------------------------------------------- 1 | wegiel drogi to i atari nie dziala -------------------------------------------------------------------------------- /spec/math-add16.spec.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "64spec/lib/64spec.asm" 26 | #import "../lib/math-global.asm" 27 | #import "../lib/mem-global.asm" 28 | 29 | sfspec: init_spec() 30 | describe("add16") 31 | 32 | it("0 + 0 = 0"); { 33 | c64lib_set16(0, operand) 34 | c64lib_set16(0, result) 35 | c64lib_set16(0, expected) 36 | c64lib_add16 operand : result 37 | assert_c_cleared 38 | assert_equal16 result : expected 39 | } 40 | 41 | it("1 + 0 = 1"); { 42 | c64lib_set16(1, operand) 43 | c64lib_set16(0, result) 44 | c64lib_set16(1, expected) 45 | c64lib_add16 operand : result 46 | assert_c_cleared 47 | assert_equal16 result : expected 48 | } 49 | 50 | it("255 + 1 = 256"); { 51 | c64lib_set16(255, operand) 52 | c64lib_set16(1, result) 53 | c64lib_set16(256, expected) 54 | c64lib_add16 operand : result 55 | assert_equal16 result : expected 56 | } 57 | 58 | it("1 + 255 = 256"); { 59 | c64lib_set16(1, operand) 60 | c64lib_set16(255, result) 61 | c64lib_set16(256, expected) 62 | c64lib_add16 operand : result 63 | assert_c_cleared 64 | assert_equal16 result : expected 65 | } 66 | 67 | it("256 + 0 = 256"); { 68 | c64lib_set16(256, operand) 69 | c64lib_set16(0, result) 70 | c64lib_set16(256, expected) 71 | c64lib_add16 operand : result 72 | assert_c_cleared 73 | assert_equal16 result : expected 74 | } 75 | 76 | it("0 + 256 = 256"); { 77 | c64lib_set16(0, operand) 78 | c64lib_set16(256, result) 79 | c64lib_set16(256, expected) 80 | c64lib_add16 operand : result 81 | assert_c_cleared 82 | assert_equal16 result : expected 83 | } 84 | 85 | it("65535 + 0 = 65535"); { 86 | c64lib_set16(65535, operand) 87 | c64lib_set16(0, result) 88 | c64lib_set16(65535, expected) 89 | c64lib_add16 operand : result 90 | assert_c_cleared 91 | assert_equal16 result : expected 92 | } 93 | 94 | it("0 + 65535 = 65535"); { 95 | c64lib_set16(0, operand) 96 | c64lib_set16(65535, result) 97 | c64lib_set16(65535, expected) 98 | c64lib_add16 operand : result 99 | assert_c_cleared 100 | assert_equal16 result : expected 101 | } 102 | 103 | it("1 + 65535 = 0"); { 104 | c64lib_set16(1, operand) 105 | c64lib_set16(65535, result) 106 | c64lib_set16(0, expected) 107 | c64lib_add16 operand : result 108 | assert_c_set 109 | assert_equal16 result : expected 110 | } 111 | 112 | it("65535 + 1 = 0"); { 113 | c64lib_set16(65535, operand) 114 | c64lib_set16(1, result) 115 | c64lib_set16(0, expected) 116 | c64lib_add16 operand : result 117 | assert_c_set 118 | assert_equal16 result : expected 119 | } 120 | finish_spec() 121 | 122 | * = * "Data" 123 | result: .word 0 124 | expected: .word 0 125 | operand: .word 0 126 | 127 | .print "result=$" + toHexString(result, 4) 128 | .print "expected=$" + toHexString(expected, 4) 129 | .print "operand=$" + toHexString(operand, 4) 130 | -------------------------------------------------------------------------------- /spec/math-dec16.spec.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "64spec/lib/64spec.asm" 26 | #import "../lib/math-global.asm" 27 | 28 | sfspec: init_spec() 29 | describe("dec16") 30 | 31 | it("of 0 gives 65535"); { 32 | c64lib_dec16(dec16ZeroActual) 33 | assert_equal16 dec16ZeroActual: dec16ZeroExpected 34 | } 35 | 36 | it("of 5 gives 4"); { 37 | c64lib_dec16(dec16Actual) 38 | assert_equal16 dec16Actual: dec16Expected 39 | } 40 | 41 | it("of 256 gives 255"); { 42 | c64lib_dec16(dec16WordActual) 43 | assert_equal16 dec16WordActual: dec16WordActual 44 | } 45 | 46 | finish_spec() 47 | 48 | * = * "Data" 49 | dec16Actual: .word 5 50 | dec16Expected: .word 4 51 | dec16WordActual: .word 256 52 | dec16WordExpected: .word 255 53 | dec16ZeroActual: .word 0 54 | dec16ZeroExpected: .word $ffff -------------------------------------------------------------------------------- /spec/mem-cmp16.spec.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "64spec/lib/64spec.asm" 26 | #import "../lib/mem-global.asm" 27 | 28 | sfspec: init_spec() 29 | 30 | describe("cmp16") 31 | 32 | it("of 256 and 256 gives true"); { 33 | c64lib_cmp16(256, _256) 34 | assert_z_set 35 | } 36 | 37 | it("of 0 and 256 gives false"); { 38 | c64lib_cmp16(0, _256) 39 | assert_z_cleared 40 | } 41 | 42 | it("of 7 and 7 gives true"); { 43 | c64lib_cmp16(7, _7) 44 | assert_z_set 45 | } 46 | 47 | it("of 0 and 0 gives true"); { 48 | c64lib_cmp16(0, _0) 49 | assert_z_set 50 | } 51 | 52 | finish_spec() 53 | 54 | * = * "Data" 55 | _256: .word 256 56 | _7: .word 7 57 | _0: .word 0 58 | -------------------------------------------------------------------------------- /spec/rotate-mem-right.spec.asm: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2023 c64lib 5 | * Copyright (c) 2017-2023 Maciej Małecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | #import "64spec/lib/64spec.asm" 26 | #import "../lib/invoke-global.asm" 27 | 28 | 29 | sfspec: init_spec() 30 | 31 | describe("rotate-mem-right") 32 | 33 | it("rotates 7 bytes of data"); { 34 | c64lib_pushParamW(dataToBeRotated) 35 | ldx #7 36 | jsr rotateMemRight 37 | 38 | assert_bytes_equal 7: dataToBeRotated: dataToBeCompared 39 | } 40 | 41 | finish_spec() 42 | 43 | * = * "Data" 44 | rotateMemRight: 45 | #import "../lib/sub/rotate-mem-right.asm" 46 | dataToBeRotated: .text "foo bar" 47 | dataToBeCompared: .text "rfoo ba" 48 | --------------------------------------------------------------------------------