-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite-compression.txt
32 lines (28 loc) · 1.32 KB
/
sprite-compression.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
16x16 sprite "blocks" are 16x16 pixels x 4bit
sprite "block" data pointers/offsets are 23bit, stored at $ec0000+x
msbit set = compressed, msbit clear = uncompressed
actual data is at $d90000 + pointer/offset
uncompressed data: copy 128 byte block from rom
compressed data: will result in a 128 byte block written to ram
8x8 sprite "blocks" are 8x8 pixels x 4bit
works the same as 16x16, but only 32 bytes in size
they have different IDs (ie. we have 16x16 block 0 and 8x8 block 0)
offsets are stored at $d80000, data is at $d10000 + offset
Actual compression scheme:
read 1 byte "info":
8bit in input will result in 8 * 2byte (8 words) in output
lsbit ^= first word .. msbit ^= last word
bit value:
0 = read next 2 byte (1 word) and copy as-is (advance input stream by 2)
1 = next 2 byte (1 word) zero (don't advance input stream)
repeat 8 times -> 8*8 words = 128 B
In code:
1 byte "info":
4 * 2bit in input will result in 4 * 4byte in output
2 lsbit ^= first 4 byte .. 2 msbit ^= last 4 byte
2 bit value:
00 = read next 4 byte and copy as-is (advance input stream by 4)
01 = next 2 byte zero, next 2 byte copy as-is (advance input stream by 2)
10 = next 2 byte copy as-is, next 2 byte zero (advance input stream by 2)
11 = next 4 byte are all zero (don't advance input stream)
loop-unrolled 8 times -> 128 B