Hi.
I was thinking about a map compression for my game. Every map is 0xE0 bytes long in it's uncompressed state.
We'll be unpacking it to RAM(for various reasons). Also, keep in mind that number of meta tiles I use is 0x1D.
So here it is:
Game assumes that map is all 0x00 at start. Also, we assume that our first Metatile number to unpack is 0x01.
Byte0: Coordinates
bit7-bit4 are used as Y coordinate.
bit0-bit3 are used as X coordinate.
*note* If this byte is FF, then it is end of map unpacking routine.
*note* If this byte is EF, then next byte will not be a "Size" byte, but a "Control" byte.
Byte1: Size.
bit7-bit4 number of Metatiles to unpack vertically
bit0-bit3 number of Metatiles to unpack horizontally
Byte2: Control Byte. Do not appear unless called by Byte0.
bit7:Used as end of current Metatile ID. Uses AND on control byte (So we get rid of bit7) to draw the next Metatile ID number. Max metatile number is 0x7F.
bit6:Repeat last "Size" byte. AND Control byte and use bits 4-0 as number of repetition. Max number of repetition is 0x1F
bit5:Use vocabulary. AND and use bits 4-0 as X to read a small array from vocabulary. Max number of vocabulary entries is 0x1F.(more than enough, to be honest).
bits 4-0:Multi purpose bits.
Example:
Coordinate byte: 0xA0. Size byte: 0x3F.
Coordinate byte: 0xEF. Control Byte: 0x81
Coordinate byte: 0xA2. Size byte: 0x38
Coordinate byte: 0xEF. Control Byte: 0x82
Coordinate byte: 0xA5. Size Byte: 0x32
Coordinate byte: 0xAB. Size Byte: 0x32
Coordinate byte: 0xEF. Control Byte: 0x92
Coordinate byte: 0x91. Size Byte: 0x00
Coordinate byte: 0xEF. Control Byte: 0x86
Coordinate byte: 0x9E. Size Byte: 0x00
Will result in this:
So, results are like this:
Uncompressed: 0xE0 bytes.
RLE: 0x48 bytes.
My scheme: 0x14 bytes.
Yeah, results will vary from map to map.
The reason I'm writing this is that maybe can someone give me a hand with improving this..."compression" method?
It's unconventional to use "repetition flag" 'cause I'll need to call control byte for second time for example.
I was thinking about a map compression for my game. Every map is 0xE0 bytes long in it's uncompressed state.
We'll be unpacking it to RAM(for various reasons). Also, keep in mind that number of meta tiles I use is 0x1D.
So here it is:
Game assumes that map is all 0x00 at start. Also, we assume that our first Metatile number to unpack is 0x01.
Byte0: Coordinates
bit7-bit4 are used as Y coordinate.
bit0-bit3 are used as X coordinate.
*note* If this byte is FF, then it is end of map unpacking routine.
*note* If this byte is EF, then next byte will not be a "Size" byte, but a "Control" byte.
Byte1: Size.
bit7-bit4 number of Metatiles to unpack vertically
bit0-bit3 number of Metatiles to unpack horizontally
Byte2: Control Byte. Do not appear unless called by Byte0.
bit7:Used as end of current Metatile ID. Uses AND on control byte (So we get rid of bit7) to draw the next Metatile ID number. Max metatile number is 0x7F.
bit6:Repeat last "Size" byte. AND Control byte and use bits 4-0 as number of repetition. Max number of repetition is 0x1F
bit5:Use vocabulary. AND and use bits 4-0 as X to read a small array from vocabulary. Max number of vocabulary entries is 0x1F.(more than enough, to be honest).
bits 4-0:Multi purpose bits.
Example:
Coordinate byte: 0xA0. Size byte: 0x3F.
Coordinate byte: 0xEF. Control Byte: 0x81
Coordinate byte: 0xA2. Size byte: 0x38
Coordinate byte: 0xEF. Control Byte: 0x82
Coordinate byte: 0xA5. Size Byte: 0x32
Coordinate byte: 0xAB. Size Byte: 0x32
Coordinate byte: 0xEF. Control Byte: 0x92
Coordinate byte: 0x91. Size Byte: 0x00
Coordinate byte: 0xEF. Control Byte: 0x86
Coordinate byte: 0x9E. Size Byte: 0x00
Will result in this:
So, results are like this:
Uncompressed: 0xE0 bytes.
RLE: 0x48 bytes.
My scheme: 0x14 bytes.
Yeah, results will vary from map to map.
The reason I'm writing this is that maybe can someone give me a hand with improving this..."compression" method?
It's unconventional to use "repetition flag" 'cause I'll need to call control byte for second time for example.