BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
crunchlib.c File Reference
#include "blitzlib.h"
#include <stddef.h>

Data Structures

struct  imcode
struct  imwork
struct  crmbits
struct  ppbits

Macros

#define RB(p)
#define RW(p)
#define RL(p)
#define ID_IMP   0x494d5021UL /* "IMP!" */
#define ID_CRM   0x43724d21UL /* "CrM!" */
#define ID_CRM2   0x43724d32UL /* "CrM2" */
#define ID_PP20   0x50503230UL /* "PP20" */
#define WS   sizeof(struct imwork)
#define IMOFF(m)
#define ST(m)
#define IMELEM(m)
#define STA(m, i)
#define OCMPTAB   (offsetof(typeof(tabbs), cmptab) - 2)
#define OADDTAB   (offsetof(typeof(tabbs), addtab) - 2)
#define OREALTAB   (offsetof(typeof(tabbs), realtab) - 2)
#define OANZPERBITS   (offsetof(typeof(tabbs), anzperbits) - 2)

Typedefs

typedef LONG infofunc(ULONG gain)

Functions

ULONG _startcrunch (UBYTE *buf, ULONG len)
 Implode(Bufferadr,DataLen): crunches the data in place with the Imploder algorithm.
BB_BOOL _decrunch (UBYTE *buf)
 Deplode(Startadr): decrunches Imploder data in place.
void _crm (void)
void _crm2 (void)
void _ppdecrunch (void)
static LONG own (ULONG gain)
static int im26 (UBYTE *st)
static ULONG im37 (UBYTE *st, UBYTE nbits, ULONG value)
static int im28 (UBYTE *st)
static int im40 (UBYTE *st, ULONG len, ULONG offset)
static int im55 (UBYTE *st)
static void literal (UBYTE *st)
static ULONG implode (UBYTE *buf, ULONG len, infofunc *info, ULONG mode, UBYTE *tabout)
static int imbit (UBYTE *bitbuf, const UBYTE **src)
static BB_BOOL deplode (UBYTE *buf)
static ULONG ror32 (ULONG v, unsigned n)
static ULONG rol32 (ULONG v, unsigned n)
static int crmbit (struct crmbits *b)
static UWORD crmgetbits (struct crmbits *b, UWORD n)
static void crminit (struct crmbits *b, const UBYTE *end)
static void fastdecruncher (UBYTE *dst, const UBYTE *src, ULONG dstlen, ULONG srclen)
static BOOL readtab (struct crmbits *b, UWORD maxbits, UBYTE *counts, UBYTE *codes, UWORD room)
static void calccmptab (const UBYTE *counts, UBYTE *cmp)
static UWORD readit (struct crmbits *b, const UBYTE *cmp, const UBYTE *real)
static void lzhdecruncher (UBYTE *dst, const UBYTE *src, ULONG dstlen, ULONG srclen)
static void overlapdecrunch (const UBYTE *src, UBYTE *dst)
static void crm_c (const UBYTE *src)
 CrMDecrunch Bufferadr: decrunches Crunch-Mania data ("CrM!" or "CrM2") in place.
 BLITZ_ALIAS (_crm, crm_c)
static void crm2_c (const UBYTE *src, UBYTE *dst)
 CrMDecrunch Bufferadr,Destinationadr: decrunches Crunch-Mania data ("CrM!" or "CrM2") to a destination.
 BLITZ_ALIAS (_crm2, crm2_c)
static int ppbit (struct ppbits *b)
static UWORD ppread (struct ppbits *b, UWORD n)
static void ppdecrunch (const UBYTE *file, const UBYTE *end, UBYTE *dest)
static void ppdecrunch_c (const UBYTE *start, const UBYTE *end, UBYTE *dest)
 PPDecrunch Bufferadr,Bufferend,Destinationadr: decrunches a PowerPacker file ("PP20").
 BLITZ_ALIAS (_ppdecrunch, ppdecrunch_c)

Variables

static const ULONG imtab0 [12]
static const ULONG imtab1 [36]
static const ULONG imtab2 [2] = { 0x2060E, 0x1020304 }
static const ULONG imtab3 [3] = { 0x1010101, 0x2030304, 0x405070E }
static const ULONG imtab4 [6]
static const UBYTE I1F8C [4] = { 0x06, 0x0a, 0x0a, 0x12 }
static const UBYTE I1F90 [12]
struct { 
   UWORD   zero 
   UWORD   cmptab [32] 
   UWORD   addtab [32] 
   UWORD   realtab [527] 
   UWORD   anzperbits [32] 
} tabbs

Macro Definition Documentation

◆ ID_CRM

#define ID_CRM   0x43724d21UL /* "CrM!" */

◆ ID_CRM2

#define ID_CRM2   0x43724d32UL /* "CrM2" */

◆ ID_IMP

#define ID_IMP   0x494d5021UL /* "IMP!" */

◆ ID_PP20

#define ID_PP20   0x50503230UL /* "PP20" */

◆ IMELEM

#define IMELEM ( m)
Value:
__typeof__(((struct imwork *)0)->m[0])
Definition crunchlib.c:179

◆ IMOFF

#define IMOFF ( m)
Value:
((int)offsetof(struct imwork, m))

◆ OADDTAB

#define OADDTAB   (offsetof(typeof(tabbs), addtab) - 2)

◆ OANZPERBITS

#define OANZPERBITS   (offsetof(typeof(tabbs), anzperbits) - 2)

◆ OCMPTAB

#define OCMPTAB   (offsetof(typeof(tabbs), cmptab) - 2)

◆ OREALTAB

#define OREALTAB   (offsetof(typeof(tabbs), realtab) - 2)

◆ RB

#define RB ( p)
Value:
(*(UBYTE *)(p))

◆ RL

#define RL ( p)
Value:
(*(ULONG *)(p))

◆ RW

#define RW ( p)
Value:
(*(UWORD *)(p))

◆ ST

#define ST ( m)
Value:
(*(__typeof__(((struct imwork *)0)->m) *)(st + IMOFF(m)))
#define IMOFF(m)
Definition crunchlib.c:212
static struct @116141142274037024203205202074071112317221044374 st

◆ STA

#define STA ( m,
i )
Value:
(*(IMELEM(m) *)(st + (IMOFF(m) + (int)sizeof(IMELEM(m)) * (i))))
#define IMELEM(m)
Definition crunchlib.c:215

◆ WS

#define WS   sizeof(struct imwork)

Typedef Documentation

◆ infofunc

typedef LONG infofunc(ULONG gain)

Function Documentation

◆ _crm()

void _crm ( void )

◆ _crm2()

void _crm2 ( void )

◆ _decrunch()

BB_BOOL _decrunch ( UBYTE * buf)

Deplode(Startadr): decrunches Imploder data in place.

BUG(orig) (#119), won't fix (see the head comment): the data are not checked: corrupt data write outside the buffer.

Parameters
bufd0: the crunched data ("IMP!" header)
Returns
d0: BB_TRUE = ok, BB_FALSE = no "IMP!" header or the data did not end at the buffer start

◆ _ppdecrunch()

void _ppdecrunch ( void )

◆ _startcrunch()

ULONG _startcrunch ( UBYTE * buf,
ULONG len )

Implode(Bufferadr,DataLen): crunches the data in place with the Imploder algorithm.

_startcrunch: Imploder "mode" 8, i.e. table 0 (window 128 bytes), no explode table. The first 12 bytes of the buffer become "IMP!", the length and the crunched length. The info routine (own) runs before every step: it writes the low word of (source - destination) to COLOR00 (the background flickers) and breaks on the left mouse button. BUG(orig) (#112), won't fix (see the head comment): the match search reads up to 254 bytes behind the data. BUG(orig) (#114), won't fix (see the head comment): a result of 0 after at least 64 bytes, or -1, leaves the buffer partly crunched. Not a bug (#113): after $4012 literal bytes in a row the rest is stored uncrunched.

Parameters
bufd0: the buffer with the data
lend1: the data length
Returns
d0: -1 = break (left mouse button), 0 = error or not crunchable (< 64 bytes, crunched < 12 bytes or not at least 55 bytes shorter), else the crunched length (data + $2E bytes of tables)

◆ BLITZ_ALIAS() [1/3]

BLITZ_ALIAS ( _crm ,
crm_c  )

◆ BLITZ_ALIAS() [2/3]

BLITZ_ALIAS ( _crm2 ,
crm2_c  )

◆ BLITZ_ALIAS() [3/3]

BLITZ_ALIAS ( _ppdecrunch ,
ppdecrunch_c  )

◆ calccmptab()

void calccmptab ( const UBYTE * counts,
UBYTE * cmp )
static

◆ crm2_c()

void crm2_c ( const UBYTE * src,
UBYTE * dst )
static

CrMDecrunch Bufferadr,Destinationadr: decrunches Crunch-Mania data ("CrM!" or "CrM2") to a destination.

_crm2: OverlapDecrunch; if the crunched data plus MinSecDist reach behind the start of the destination (signed comparison) they are first copied to MinSecDist bytes before the destination. All registers kept. BUG(orig) (#116), won't fix: that copy overwrites memory in front of the destination. Fixed (#115), (#117); BUG(orig) (#119), won't fix: see the one argument form.

Parameters
srcd0: the crunched data (with header)
dstd1: the destination

◆ crm_c()

void crm_c ( const UBYTE * src)
static

CrMDecrunch Bufferadr: decrunches Crunch-Mania data ("CrM!" or "CrM2") in place.

_crm: OverlapDecrunch with destination = source: the crunched data are first copied to MinSecDist bytes before the buffer. Other data than "CrM!"/"CrM2" are left alone. All registers kept. BUG(orig) (#116), won't fix (see the head comment): up to MinSecDist bytes of memory in front of the buffer are overwritten. Fixed (#115): the copy of (CrLen>>2) longs ran 4 GB for a crunched length below 4. Fixed (#117): CrM2 tables with a count of 0 read 65536 entries (now the decrunch ends). BUG(orig) (#119), won't fix: no checks of the data.

Parameters
srcd0: the crunched data (with header), also the destination

◆ crmbit()

int crmbit ( struct crmbits * b)
static

◆ crmgetbits()

UWORD crmgetbits ( struct crmbits * b,
UWORD n )
static

◆ crminit()

void crminit ( struct crmbits * b,
const UBYTE * end )
static

◆ deplode()

BB_BOOL deplode ( UBYTE * buf)
static

◆ fastdecruncher()

void fastdecruncher ( UBYTE * dst,
const UBYTE * src,
ULONG dstlen,
ULONG srclen )
static

◆ im26()

int im26 ( UBYTE * st)
static

◆ im28()

int im28 ( UBYTE * st)
static

◆ im37()

ULONG im37 ( UBYTE * st,
UBYTE nbits,
ULONG value )
static

◆ im40()

int im40 ( UBYTE * st,
ULONG len,
ULONG offset )
static

◆ im55()

int im55 ( UBYTE * st)
static

◆ imbit()

int imbit ( UBYTE * bitbuf,
const UBYTE ** src )
static

◆ implode()

ULONG implode ( UBYTE * buf,
ULONG len,
infofunc * info,
ULONG mode,
UBYTE * tabout )
static

◆ literal()

void literal ( UBYTE * st)
static

◆ lzhdecruncher()

void lzhdecruncher ( UBYTE * dst,
const UBYTE * src,
ULONG dstlen,
ULONG srclen )
static

◆ overlapdecrunch()

void overlapdecrunch ( const UBYTE * src,
UBYTE * dst )
static

◆ own()

LONG own ( ULONG gain)
static

◆ ppbit()

int ppbit ( struct ppbits * b)
static

◆ ppdecrunch()

void ppdecrunch ( const UBYTE * file,
const UBYTE * end,
UBYTE * dest )
static

◆ ppdecrunch_c()

void ppdecrunch_c ( const UBYTE * start,
const UBYTE * end,
UBYTE * dest )
static

PPDecrunch Bufferadr,Bufferend,Destinationadr: decrunches a PowerPacker file ("PP20").

_ppdecrunch: the last long of the packed file holds the original length and the number of empty bits; other files than "PP20" are left alone. All registers kept. Fixed (#118): an efficiency value outside 1-15 unpacks nothing (the original read 65536 bits for a value of 0 and unpacked garbage). BUG(orig) (#119), won't fix: no other checks of the data.

Parameters
startd0: the packed file
endd1: the end of the packed file
destd2: the destination

◆ ppread()

UWORD ppread ( struct ppbits * b,
UWORD n )
static

◆ readit()

UWORD readit ( struct crmbits * b,
const UBYTE * cmp,
const UBYTE * real )
static

◆ readtab()

BOOL readtab ( struct crmbits * b,
UWORD maxbits,
UBYTE * counts,
UBYTE * codes,
UWORD room )
static

◆ rol32()

ULONG rol32 ( ULONG v,
unsigned n )
static

◆ ror32()

ULONG ror32 ( ULONG v,
unsigned n )
static

Variable Documentation

◆ addtab

UWORD addtab[32]

◆ anzperbits

UWORD anzperbits[32]

◆ cmptab

UWORD cmptab[32]

◆ I1F8C

const UBYTE I1F8C[4] = { 0x06, 0x0a, 0x0a, 0x12 }
static

◆ I1F90

const UBYTE I1F90[12]
static
Initial value:
= { 0x01, 0x01, 0x01, 0x01, 0x02, 0x03, 0x03,
0x04, 0x04, 0x05, 0x07, 0x0e }

◆ imtab0

const ULONG imtab0[12]
static
Initial value:
= {
128, 256, 512, 1024, 1792, 3328, 5376, 9472, 20736, 37376, 67840, 67840
}

◆ imtab1

const ULONG imtab1[36]
static
Initial value:
= {
0x5050505, 0x5050505, 0x6060606, 0x5060707, 0x6060606, 0x7070606,
0x5060707, 0x7070707, 0x8080808, 0x5060708, 0x7070808, 0x8080909,
0x6070708, 0x7080909, 0x8090A0A, 0x6070708, 0x709090A, 0x80A0B0B,
0x6070808, 0x709090A, 0x80A0B0C, 0x6070808, 0x709090A, 0x90A0C0D,
0x6070708, 0x709090C, 0x90A0C0E, 0x6070809, 0x7090A0C, 0x90B0D0F,
0x6070808, 0x70A0B0B, 0x90C0D10, 0x6080809, 0x70B0C0C, 0x90D0E11
}

◆ imtab2

const ULONG imtab2[2] = { 0x2060E, 0x1020304 }
static

◆ imtab3

const ULONG imtab3[3] = { 0x1010101, 0x2030304, 0x405070E }
static

◆ imtab4

const ULONG imtab4[6]
static
Initial value:
= { 0x20002, 0x20002, 0x6000A, 0xA0012,
0x16002A, 0x8A4012 }

◆ realtab

UWORD realtab[527]

◆ [struct]

struct { ... } tabbs

◆ zero

UWORD zero