view fluid-mnf/lz.h @ 402:1b83d07576bf

compal/boot/c123-boot.disasm: missed vector branch at 0x1c
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jan 2023 00:06:59 +0000
parents 9cecc930d78f
children
line wrap: on
line source

/******************************************************************************
 * FLUID (Flash Loader Utility Independent of Device)
 *
 * Simple LZ77 compressor (c) Texas Instruments, Jesper Pedersem TI-DK    
 *
 * $Id: lz.h 1.4 Thu, 31 Oct 2002 13:12:27 +0100 tsj $
 *
 ******************************************************************************/

#ifndef _LZ_H_
#define _LZ_H_ 1

// Algorithmn efficiency constants

// Don't compress unless we have a > THRESHOLD match
#define THRESHOLD 2

// Number of bits to use for position, when storing a match
#define POS_BITS 12
#define POS_MASK 0x0FFF

// Number of bits to use for length, when storing a match
#define LEN_BITS 4  
#define LEN_MASK 0xF000

// Size and size-mask of sliding window
#define WINDOW_SIZE (1 << POS_BITS)
#define WINDOW_MASK (WINDOW_SIZE - 1)

// Maximum match length
#define MAX_MATCH ((1 << LEN_BITS) + THRESHOLD)

// This structure is only being used by lzdecode/decompress().
struct lz_s {
    uint8 window[WINDOW_SIZE]; // Sliding window buffer
    int16 window_pos;          // Current window position

    // Static variables for get_bits()
    uint32 bitbuf;      // buffer for remaining bits
    uint8  bitbuf_size; // number of bits in buffer

    // Global input/output buffer pointers and sizes
    uint8  *buffer_in;
    uint32 buffer_in_size;
    uint32 total_in_size;
    uint8  *buffer_out;
    uint32 buffer_out_size;
    uint32 total_out_size;
};


void compress_init(void);
int compress(char *outbuf, char *inbuf, int size);

void decompress_init(struct lz_s *plz);
int  decompress(struct lz_s *plz,
                unsigned char *outbuf, unsigned char *inbuf, int size);

#endif