You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pxa compression snippets for PICO-8 0.2.0 cartridge format
3
+
pxa compression snippets for PICO-8 cartridge format (as of 0.2.4c)
4
4
5
5
author: joseph@lexaloffle.com
6
6
7
-
Copyright (c) 2020 Lexaloffle Games LLP
7
+
Copyright (c) 2020-22 Lexaloffle Games LLP
8
8
9
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
of this software and associated documentation files (the "Software"), to deal
@@ -66,6 +66,21 @@ static int src_pos = 0;
66
66
staticuint8*dest_buf=NULL;
67
67
staticuint8*src_buf=NULL;
68
68
69
+
// 0.2.0j
70
+
// encode / decode as an int
71
+
staticintget_write_pos()
72
+
{
73
+
intresult= (dest_pos << 16) | (byte << 8) | bit;
74
+
returnresult;
75
+
}
76
+
staticvoidset_write_pos(intval)
77
+
{
78
+
bit=val&0xff;
79
+
byte= (val >> 8) &0xff;
80
+
dest_pos= (val >> 16) &0x7fff;
81
+
}
82
+
83
+
69
84
70
85
staticintgetbit()
71
86
{
@@ -81,18 +96,18 @@ static int getbit()
81
96
returnret;
82
97
}
83
98
84
-
staticvoidputbit(intbval)
99
+
voidputbit(intbval)
85
100
{
86
-
if (bval) byte |= bit;
101
+
dest_buf[dest_pos] &= ~bit; // 0.2.0j: per-bit
102
+
if (bval) dest_buf[dest_pos] |= bit;
87
103
88
-
dest_buf[dest_pos] =byte;
89
104
bit <<= 1;
90
105
91
106
if (bit==256)
92
107
{
93
108
bit=1;
94
-
byte=0;
95
109
dest_pos++;
110
+
byte=dest_buf[dest_pos]; // 0.2.0j: so that don't clobber existing bits (can overwrite at bit level)
96
111
}
97
112
}
98
113
@@ -208,6 +223,9 @@ static int getnum()
208
223
209
224
val=getval(bits);
210
225
226
+
if (val==0&&bits==10)
227
+
return-1; // raw block marker
228
+
211
229
returnval;
212
230
}
213
231
@@ -228,7 +246,8 @@ static int pxa_find_repeatable_block(uint8 *dat, int pos, int data_len, int *blo
228
246
inthash;
229
247
intlast_pos;
230
248
intscore, dist, bit_cost, best_score=-1;
231
-
249
+
intlist_pos;
250
+
232
251
p=&dat[pos];
233
252
234
253
// block length can't be longer than remaining
@@ -241,12 +260,18 @@ static int pxa_find_repeatable_block(uint8 *dat, int pos, int data_len, int *blo
241
260
242
261
uint16*list=hash_list[hash];
243
262
244
-
for (intlist_pos=0;
263
+
/*
264
+
for (list_pos = 0;
245
265
list && list_pos < list[1] && // for each item of list
246
266
(list[2+list_pos] < pos
247
-
&&list[2+list_pos] >= pos-max_hist_len// where starting position in within range
267
+
&& list[2+list_pos] >= pos - max_hist_len // where starting position in within range 0.2.0e: commented. **wroooong**. don't want to exit iter here.
248
268
);
249
269
list_pos++)
270
+
*/
271
+
272
+
if (!list) return0; // 0.2.0e: exit early
273
+
for (list_pos=0; list_pos<list[1] &&list[2+list_pos] <pos; list_pos++) // 0.2.0e: can exit early if encounter future position (rest of list will also be)
274
+
if (list[2+list_pos] >= pos-max_hist_len) // not out of range 0.2.0e: moved here -- still want to try rest of list
250
275
{
251
276
intpos0=list[2+list_pos];
252
277
@@ -394,10 +419,12 @@ void pxa_build_hash_lookup(uint8 *in, int len)
0 commit comments