Realms of Chaos Masked Tileset Format
| Format type | Tileset |
|---|---|
| Hardware | VGA |
| Max tile count | 128 |
| Palette | External |
| Tile names? | No |
| Minimum tile size (pixels) | 16×16 |
| Maximum tile size (pixels) | 16×16 |
| Plane count | 1 |
| Plane arrangement | Linear |
| Transparent pixels? | Yes |
| Hitmap pixels? | No |
| Metadata? | None |
| Supports sub-tilesets? | No |
| Compressed tiles? | No |
| Hidden data? | No |
| Games |
The MBG Format is used in Realms of Chaos to store "masked" (partially transparent) tile graphics.
File format
Files in this Format contain the following header:
| Data type | Name | Description |
|---|---|---|
| UINT16LE[129] | offsets | Offsets to the start of the pixel data for each tile |
Each file can store the tile graphics for up to 128 tiles. The offsets are relative to the start of the pixel data; the pixel data starts at 258 (0x102). The last offset is an offset to the end of the pixel data. offsets[128]+258 should match the size of the file.
The pixel data contains of multiple records in the following format:
| Data type | Name | Description |
|---|---|---|
| UINT8 | type | Type flag for this block |
| UINT8 | count | Number of pixel rows covered by this block |
| BYTE[count*2] | pixels | 8bpp pixel values (only present if type is 1, 2 or 3) |
The order in which the pixels are read from the file is shown here as hexadecimal numbers:
00 20 40 60 01 21 41 61 80 A0 C0 E0 81 A1 C1 E1 02 22 42 62 03 23 43 63 82 A2 C2 E2 83 A3 C3 E3 04 24 44 64 05 25 45 65 84 A4 C4 E4 85 A5 C5 E5 06 26 46 66 07 27 47 67 86 A6 C6 E6 87 A7 C7 E7 08 28 48 68 09 29 49 69 88 A8 C8 E8 89 A9 C9 E9 0A 2A 4A 6A 0B 2B 4B 6B 8A AA CA EA 8B AB CB EB 0C 2C 4C 6C 0D 2D 4D 6D 8C AC CC EC 8D AD CD ED 0E 2E 4E 6E 0F 2F 4F 6F 8E AE CE EE 8F AF CF EF 10 30 50 70 11 31 51 71 90 B0 D0 F0 91 B1 D1 F1 12 32 52 72 13 33 53 73 92 B2 D2 F2 93 B3 D3 F3 14 34 54 74 15 35 55 75 94 B4 D4 F4 95 B5 D5 F5 16 36 56 76 17 37 57 77 96 B6 D6 F6 97 B7 D7 F7 18 38 58 78 19 39 59 79 98 B8 D8 F8 99 B9 D9 F9 1A 3A 5A 7A 1B 3B 5B 7B 9A BA DA FA 9B BB DB FB 1C 3C 5C 7C 1D 3D 5D 7D 9C BC DC FC 9D BD DD FD 1E 3E 5E 7E 1F 3F 5F 7F 9E BE DE FE 9F BF DF FF
This format appears to be optimized for drawing the masked tiles without needing to check whether or not a pixel is actually transparent. The algorithm to draw the tiles works like this:
0. set x and y to the screen-location of the tile image to be drawn
1. read type and count
2. IF type = 0
increase y by count
go back to 1.
IF type = 1
FOR i=1 TO count
read 2 bytes from file
write first byte to (x, y)
write second byte to (x+4, y)
increase y by 1
go back to 1.
IF type = 2
FOR i=1 TO count
read 2 bytes from file
write first byte to (x, y)
ignore second byte (pixel is transparent)
increase y by 1
go back to 1.
IF type = 3
FOR i=1 TO count
read 2 bytes from file
ignore first byte (pixel is transparent)
write second byte to (x+4, y)
increase y by 1
go back to 1.
IF type = 4
set y back to initial screen-location
increase x by 1
IF x = 4
set x to 8
go back to 1.
IF type = 5
* exit
Notes
Each tile seems to end with the following sequence of (type, count) pairs: (4, 0), (0, 0), (5, 0)
The first tile in a file should always be fully transparent, i.e. a sequence of (0, 16), (4, 0) pairs.
When the tileset is to be shown to the user, it should be displayed with a width of 20 tiles (320 pixels).
Credits
This file format was reverse engineered by K1n9_Duk3. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)