-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RLE compression and decompression macros/subs.
- Loading branch information
1 parent
2da8e14
commit 53acb79
Showing
8 changed files
with
219 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 "compress.asm" | ||
#importonce | ||
|
||
.filenamespace c64lib | ||
|
||
.macro @c64lib_compressRLE(data) { compressRLE(data) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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. | ||
*/ | ||
#importonce | ||
.filenamespace c64lib | ||
|
||
/* | ||
* Performs RLE (Running Length Encoding) compression of given binary data (kick assembler data type). | ||
* The compressed result is placed as is in the result file starting from the place where this macro is called. | ||
*/ | ||
.macro compressRLE(binaryData) { | ||
.var runLength = 0 | ||
.var runValue = 0 | ||
.var crunchedLength = 0 | ||
.for(var i = 0; i < binaryData.getSize(); i++) { | ||
.if(runLength > 0 && (binaryData.get(i) != runValue || runLength == $ff)) { | ||
.byte runLength | ||
.byte runValue | ||
.eval runLength = 0 | ||
.eval crunchedLength = crunchedLength + 2 | ||
} | ||
.if(runLength == 0) { | ||
.eval runValue = binaryData.get(i) | ||
.eval runLength = 1 | ||
} else { | ||
.eval runLength++ | ||
} | ||
} | ||
.byte runLength | ||
.byte runValue | ||
.byte $00 // end mark | ||
.eval crunchedLength++ | ||
.print "Crunched from " + binaryData.getSize() + " to " + crunchedLength + " (" + round((crunchedLength/binaryData.getSize())*100) + "%)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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" | ||
|
||
.namespace c64lib { | ||
|
||
/* | ||
* Stack: | ||
* source address (2 bytes) | ||
* dest address (2 bytes) | ||
*/ | ||
decompressRLE: { | ||
invokeStackBegin(returnPtr) | ||
pullParamW(destination) | ||
pullParamW(source) | ||
invokeStackEnd(returnPtr) | ||
|
||
nextSequence: | ||
jsr loadSource | ||
cmp #0 | ||
beq end // end mark | ||
tax // x <- run length | ||
jsr loadSource // a <- run value | ||
decrunch: | ||
sta destination:$ffff | ||
inc destination | ||
bne !+ | ||
inc destination + 1 | ||
!: | ||
dex | ||
bne decrunch | ||
jmp nextSequence | ||
|
||
end: | ||
rts | ||
loadSource: | ||
lda source:$ffff | ||
inc source | ||
bne !+ | ||
inc source + 1 | ||
!: | ||
rts | ||
// locals | ||
returnPtr: .word 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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/compress-global.asm" | ||
#import "../lib/invoke-global.asm" | ||
|
||
.var testData = LoadBinary("decompress-rle.test-data.txt") | ||
|
||
sfspec: init_spec() | ||
describe("decompressRLE") | ||
|
||
it("decompress data"); { | ||
c64lib_pushParamW(compressedData) | ||
c64lib_pushParamW(targetData) | ||
jsr decompressRLE | ||
|
||
assert_bytes_equal testData.getSize(): targetData: originalData | ||
} | ||
finish_spec() | ||
|
||
* = * "Data" | ||
decompressRLE: | ||
#import "../lib/sub/decompress-rle.asm" | ||
|
||
originalData: | ||
.fill testData.getSize(), testData.get(i) | ||
originalDataEnd: | ||
|
||
compressedData: | ||
c64lib_compressRLE(testData) | ||
compressedDataEnd: | ||
|
||
targetData: | ||
.fill testData.getSize(), 0 | ||
targetDataEnd: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
wegiel drogi to i atari nie dziala |