All Projects → pfusik → zlib6502

pfusik / zlib6502

Licence: other
6502 inflate routine

Programming Languages

Makefile
30231 projects

Projects that are alternatives of or similar to zlib6502

pakkero
Pakkero is a binary packer written in Go made for fun and educational purpose. Its main goal is to take in input a program file (elf binary, script, even appimage) and compress it, protect it from tampering and intrusion.
Stars: ✭ 143 (+57.14%)
Mutual labels:  compression
libcaesium
The Caesium compression library written in Rust
Stars: ✭ 58 (-36.26%)
Mutual labels:  compression
naps
An experiment for building gateware for the axiom micro / beta using nmigen and yosys
Stars: ✭ 28 (-69.23%)
Mutual labels:  compression
rangecoder
a fast range coder in C++, using SSE
Stars: ✭ 50 (-45.05%)
Mutual labels:  compression
compress-net-notes
No description or website provided.
Stars: ✭ 20 (-78.02%)
Mutual labels:  compression
smallz4
Optimal LZ4 compression
Stars: ✭ 24 (-73.63%)
Mutual labels:  compression
pyrus-cramjam
Thin Python wrapper to de/compression algorithms in Rust - lightweight & no dependencies
Stars: ✭ 40 (-56.04%)
Mutual labels:  compression
EasyCompressor
⚡ A compression library that implements many compression algorithms such as LZ4, Zstd, LZMA, Snappy, Brotli, GZip, and Deflate. It helps you to improve performance by reducing Memory Usage and Network Traffic for caching.
Stars: ✭ 167 (+83.52%)
Mutual labels:  compression
VTEnc
VTEnc C library
Stars: ✭ 31 (-65.93%)
Mutual labels:  compression
Competitive-Feature-Learning
Online feature-extraction and classification algorithm that learns representations of input patterns.
Stars: ✭ 32 (-64.84%)
Mutual labels:  compression
image-optimizer
Smart image optimization
Stars: ✭ 15 (-83.52%)
Mutual labels:  compression
bzip2-rs
Pure Rust bzip2 decoder
Stars: ✭ 28 (-69.23%)
Mutual labels:  compression
PLzmaSDK
PLzmaSDK is (Portable, Patched, Package, cross-P-latform) Lzma SDK.
Stars: ✭ 28 (-69.23%)
Mutual labels:  compression
lz4-napi
Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex.
Stars: ✭ 29 (-68.13%)
Mutual labels:  compression
wrender
Image compression and transformation reverse-proxy for Express apps
Stars: ✭ 14 (-84.62%)
Mutual labels:  compression
zopflipy
A Python bindings for Zopfli
Stars: ✭ 17 (-81.32%)
Mutual labels:  compression
minformat
gominfmt makes the Go code more compact to aid further compression; revert with gofmt
Stars: ✭ 19 (-79.12%)
Mutual labels:  compression
fpzip
Lossless compressor of multidimensional floating-point arrays
Stars: ✭ 58 (-36.26%)
Mutual labels:  compression
xdelta-sharp
Decompressor for delta encoding VCDIFF (RFC-3284) -- xdelta3 compatible.
Stars: ✭ 27 (-70.33%)
Mutual labels:  compression
nim-snappy
Nim implementation of Snappy compression algorithm
Stars: ✭ 14 (-84.62%)
Mutual labels:  compression

Build Status

6502 inflate routine

DEFLATE is a popular compression format, used in ZIP, gzip, PNG and many other formats.

In 2000 I wrote a DEFLATE decompression routine (called "inflate") in the 6502 assembly language. In 2007 I optimized it so it is about 30% shorter and 10% faster than before. In 2017 I fixed bugs causing invalid expansion of some streams. These were edge cases, unlikely to encounter unless intentionally triggerred.

Compilation

Use xasm.

The routine uses three memory areas:

  • inflate - code and constants (508 bytes)
  • inflate_data - uninitialized data (765 bytes)
  • inflate_zp - variables on zero page (10 bytes)

You must select these locations at compile time, for example:

xasm -d inflate=$b700 -d inflate_data=$b900 -d inflate_zp=$f0 inflate.asx

(escape the dollars if in Unix shell or Makefile).

Usage

The inflate routine assumes that the compressed and the uncompressed data fit in the memory. Before calling inflate, set the locations of the compressed and the uncompressed data in the zero-page variables:

mwa #compressedData inflate_zp
mwa #uncompressedData inflate_zp+2
jsr inflate

As the compressed data is read sequentially and only once, it is possible to overlap the compressed and uncompressed data. That is, the data being uncompressed can be stored in place of some compressed data which has been already read.

It is also possible to get the compressed data from any forward-only stream. In this case, modify the getBit routine to use your readByte:

getBit
    lsr getBit_buffer
    bne getBit_return
    pha
    stx getBit_buffer
    jsr readByte
    ldx getBit_buffer
    ldy #0
    sec
    ror @
    sta getBit_buffer
    pla
getBit_return
    rts

Compression

There are several ways to get DEFLATE compressed data.

If you are looking for maximum compression, use Zopfli. For example:

zopfli --deflate --i1000 INPUT_FILE

will compress to INPUT_FILE.deflate. I have compiled a Windows exe for you. Increasing the number passed to the --i option can improve the compression by a few bytes at the cost of increased compression time.

Historically, I have used:

  • my programs using the Deflater Java class
  • my deflater program written with the zlib library.
  • my gzip2deflate program that extracted the DEFLATE stream from a GZ file created with gzip or 7-Zip
  • my zip2deflate program that extracted the DEFLATE stream from a ZIP created with KZIP

zlib?

This project is named zlib6502, but only supports DEFLATE decompression. Someday I'm going to include more functions, including compression.

Meanwhile, you may look at cc65 zlib.h. In addition to inflate, it supports zlib-compatible uncompress, adler32 and crc32.

License

This code is licensed under the standard zlib license.

Copyright (C) 2000-2017 Piotr Fusik

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

  3. This notice may not be removed or altered from any source distribution.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].