LZ77 decompression into RAM, screen on: lzssDecodeRam. More...
Macros | |
| #define | BANK7F(addr) |
| Bank $7F: the tiles at $7F:0000, the hand-built streams from $7F:9000. | |
| #define | FILL 0xA5 |
| What every destination holds before a decode. | |
| #define | GUARD 16 |
| Bytes checked after each output: the decoder must not write past its end. | |
| #define | TILES_SIZE 32768 |
| Size of the tile block, as converted without compression. | |
Functions | |
| static void | bench (u8 which) |
| One decode alone, for luna profile (see the README). | |
| static u16 | diff (const u8 *d, const u8 *ref, u16 n) |
| Bytes of d[0..n) that differ from ref[0..n). | |
| static u16 | diff_pattern (const u8 *d, u16 n, u16 period) |
| Bytes of d[0..n) that differ from P(k mod period), P(k) = k * 37 + 11. | |
| static void | fill (u8 FAR *d, u16 n) |
| Fill n bytes at d with FILL. | |
| int | main (void) |
| Run every test with the screen on, then show the verdicts. | |
| static void | show (u8 row, const char *name, u16 len, u16 bad) |
| Print one result line: name, bytes returned, verdict. | |
| static u16 | test_ovl (u8 FAR *d, u16 *len) |
| Decode the overlap stream into d (44 bytes). | |
| static u16 | test_ovlong (u8 FAR *d, u16 *len) |
| Decode the long overlap stream into d: 127 x 'A', 55 x "BC", 31 x "DEF". | |
| static u16 | test_refused (const u8 *s, u8 FAR *d, u16 *len) |
| Decode a stream that must be refused: 0 back, nothing written. | |
| static u16 | test_tiles (u8 FAR *d, u16 *len) |
| Decode the tiles into d; check the bytes and the guard after them. | |
| static u16 | touched (const u8 *d, u16 n) |
| Bytes of d[0..n) that are not FILL: what a refused decode or an overrun touched. | |
Variables | |
| u8 | bench_sel |
| Set by luna (–poke-at main –poke bench_sel=0N) to time one decode alone. | |
| FAR u8 | buf7e [32768+16] |
| Bank $7E destination: a FAR buffer, outside the 8 KB band. | |
| u8 | buf_low [330+16] |
| Low-RAM destination (bank $00): the decoder's byte-loop copy. | |
Hand-built streams (streams.asm) | |
| const u8 | big_lz [] |
| const u8 | clip_lz [] |
| const u8 | lit_lz [] |
| const u8 | ovl_expected [] |
| const u8 | ovl_lz [] |
| const u8 | ovlong_lz [] |
| const u8 | ref194_lz [] |
| const u8 | ref_lz [] |
| const u8 | tag_lz [] |
| const u8 | zero_lz [] |
Results, read by testing/manifests/memory_lzss_ram.toml | |
For each test: r_X_len = the return value, r_X_bad = bytes that differ from the expectation, guard bytes included (0 = pass). | |
| u16 | r_big_bad |
| u16 | r_big_len |
| u16 | r_clip_bad |
| u16 | r_clip_len |
| u16 | r_cross_bad |
| u16 | r_cross_len |
| u16 | r_done |
| u16 | r_edge_bad |
| u16 | r_edge_len |
| u16 | r_failed |
| u16 | r_lit_bad |
| u16 | r_lit_len |
| u16 | r_ovl7e_bad |
| u16 | r_ovl7e_len |
| u16 | r_ovl7f_bad |
| u16 | r_ovl7f_len |
| u16 | r_ovllo_bad |
| u16 | r_ovllo_len |
| u16 | r_ovlong7e_bad |
| u16 | r_ovlong7e_len |
| u16 | r_ovlong7f_bad |
| u16 | r_ovlong7f_len |
| u16 | r_ovlonglo_bad |
| u16 | r_ovlonglo_len |
| u16 | r_r194_bad |
| u16 | r_r194_len |
| u16 | r_ref_bad |
| u16 | r_ref_len |
| u16 | r_t7e_bad |
| u16 | r_t7e_len |
| u16 | r_t7f_bad |
| u16 | r_t7f_len |
| u16 | r_tag_bad |
| u16 | r_tag_len |
| u16 | r_zero_bad |
| u16 | r_zero_len |
LZ77 decompression into RAM, screen on: lzssDecodeRam.
lzssDecodeVram expands a compressed block straight into VRAM, which needs forced blank. lzssDecodeRam expands it into RAM instead, in any bank, with the screen on and the NMI running: the game decompresses its tiles while it plays, then sends them to VRAM by DMA in VBlank.
This example decodes, with the screen on, a 2 bpp tile block that opensnes-sprite compressed (32768 bytes from 17856) into bank $7F and into a FAR buffer of bank $7E, and compares each copy byte for byte with the same tiles converted without compression. Hand-built streams then check the edge cases: literals only, long references (also into the low 8 KB, the byte-loop copy), a reference cut at the end of the output, overlapping references (distance 1, distance shorter than the length) into $7F, $7E and the low 8 KB, a stream that ends exactly at the end of bank $7F, and four refused streams (length 0, length above 65535, a wrong tag, an output that would cross the end of the bank), each of which must return 0 and leave its destination as it was. The verdict of each test is in WRAM, for the luna manifest, and on screen.
| #define BANK7F | ( | addr | ) |
| #define FILL 0xA5 |
What every destination holds before a decode.
| #define GUARD 16 |
Bytes checked after each output: the decoder must not write past its end.
| #define TILES_SIZE 32768 |
Size of the tile block, as converted without compression.
|
static |
One decode alone, for luna profile (see the README).
Bytes of d[0..n) that differ from ref[0..n).
Bytes of d[0..n) that differ from P(k mod period), P(k) = k * 37 + 11.
| int main | ( | void | ) |
Run every test with the screen on, then show the verdicts.
Print one result line: name, bytes returned, verdict.
Decode the long overlap stream into d: 127 x 'A', 55 x "BC", 31 x "DEF".
Decode a stream that must be refused: 0 back, nothing written.
Decode the tiles into d; check the bytes and the guard after them.
Bytes of d[0..n) that are not FILL: what a refused decode or an overrun touched.
| u8 bench_sel |
Set by luna (–poke-at main –poke bench_sel=0N) to time one decode alone.
|
extern |
length 65536
| u8 buf_low[330+16] |
Low-RAM destination (bank $00): the decoder's byte-loop copy.
|
extern |
a reference that runs past the 5-byte end
|
extern |
4096 literals P(k)
|
extern |
what ovl_lz expands to
|
extern |
overlapping references, 44 bytes
|
extern |
overlapping references, 330 bytes (fast loop)
| u16 r_big_bad |
| u16 r_big_len |
| u16 r_clip_bad |
| u16 r_clip_len |
| u16 r_cross_bad |
| u16 r_cross_len |
| u16 r_done |
0xD0E5 once every test ran
| u16 r_edge_bad |
| u16 r_edge_len |
| u16 r_failed |
tests that failed
| u16 r_lit_bad |
| u16 r_lit_len |
| u16 r_ovl7e_bad |
| u16 r_ovl7e_len |
| u16 r_ovl7f_bad |
| u16 r_ovl7f_len |
| u16 r_ovllo_bad |
| u16 r_ovllo_len |
| u16 r_ovlong7e_bad |
| u16 r_ovlong7e_len |
| u16 r_ovlong7f_bad |
| u16 r_ovlong7f_len |
| u16 r_ovlonglo_bad |
| u16 r_ovlonglo_len |
| u16 r_r194_bad |
| u16 r_r194_len |
| u16 r_ref_bad |
| u16 r_ref_len |
| u16 r_t7e_bad |
| u16 r_t7e_len |
| u16 r_t7f_bad |
| u16 r_t7f_len |
| u16 r_tag_bad |
| u16 r_tag_len |
| u16 r_zero_bad |
| u16 r_zero_len |
|
extern |
the same, 194 bytes: 32 literals, 9 references
|
extern |
32 literals, then 224 references of 18 bytes at distance 32
|
extern |
tag $11
|
extern |
length 0