@@ 39,6 39,28 @@ connected to which pins on the Gameboy:
Subsignal('clk', Pins('B:2')),
Subsignal('pixel', Pins('B:0', 'B:1')))])
+# Compressed video format
+
+Compression is line based. Each line starts with a config byte. If the byte is
+`0xFF` then the line is not compressed and the next 40 bytes in the stream are
+the raw line pixel data. Otherwise the byte describes two things: the
+most-significant bit is set if the line is an exact match, not otherwise. The
+lower 7 bits encode a pixel offset in x & y in the range -4..4, in the form ((x
++ 4) * 9) + (y + 4) (i.e. x/y offsets are biased by 4 to make them in the range
+0..9). The offset selects the line in the previous frame (relative to the
+current line's y coordinate) and an x shift (in pixels, i.e. multiples of 2
+bits). 0s are always shifted in to fill the whole line when shifting in x. This
+shifted line is the reference line. For an exact match there is no more data in
+the compressed stream for the current line - the output line is just the
+reference line verbatim. For a non-exact match the next 5 bytes in the
+compressed stream are a bitmask of which reference line bytes to output. For any
+0 in the bitmask a byte is read from the compressed stream and output instead of
+using the byte from the reference line. For any 1 there is no data in the
+compressed stream for that byte, the byte from the reference line is output.
+
+See `compress_ref.py` for a reference implementation of the
+compressor/decompressor.
+
# UART testing
./run uart_echo build