UZE File format

From Uzebox Wiki
Jump to navigation Jump to search

UZE files are game binaries which the Uzebox Game Loader can use: you can copy these onto an SD card to use with your Uzebox or run them by emulators. They have a 512 byte (one SD card sector) header describing their contents.

The Header

This is the first 512 bytes of the file, describing the game and the further contents of the file. Following the individual bytes of it are described (Ld.: Marks whether there are loaders which use it):

Byte range Ld. Description
0x000-0x005 X "UZEBOX" File format marker sequence (binary: 0x55 0x5A 0x45 0x42 0x4F 0x58)
0x006 - Header version. Must be 0x01.
0x007 - Target. Must be 0x00 indicating ATmega644. 0x01 is reserved for ATmega1284.
0x008-0x00B X Program size in bytes, Little Endian (low byte first). Maximal allowed value is 61440 (60 KBytes).
0x00C-0x00D X Release year, Little Endian (low byte first). Game loaders may display it as information.
0x00E-0x02D X Name of game, padded with zeros. Game loaders display it in their game selector.
0x02E-0x04D X Author, padded with zeros. Game loaders may display it as information.
0x04E-0x14D - 16 x 16 icon using the Uzebox BBGGGRRR palette. Currently no game fills this, nor it is displayed.
0x14E-0x151 X CRC32 of Header & Game binary, Little Endian (low byte first). The 0.4.5 Game Loader uses it as a hash to identify whether the selected game differs from the one currently programmed.
0x152 - SNES Mouse marker. Should be 0x01 if the game requires an SNES Mouse.
0x153-0x192 - Game description, padded with zeros. Currently no game fills this, nor it is displayed.

The CRC field is not used by any currently existing software to actually check the integrity of the file. It is generated by the Packrom tool, claculated with zeroes on the CRC field, then written on this field. Checking should be done by copying off the CRC value, then zeroing the area before calculating it.

The Game Loaders before version 5.0.00 use it to identify the game programmed it into the ATmega's ROM, by writing the CRC field's value into EEPROM for comparison. They refuse to program a game if the CRC in the header matches that within the EEPROM.

The File format marker ("UZEBOX") is used by some software (particularly the CUzeBox emulator) to check whether the file is valid. Some early games lacked this marker, thus making these unable to recognize them as UZE files.

The Target byte is intended to specify target MCU, however only ATmega644 is valid. Smaller MCUs weren't used in Uzebox and the ATmega1284 is unable to run reliably at the required ~28.6MHz frequency (which is way above the official specification of 20MHz for the ATmegas).

The Game binary

The Game binary always starts at address 0x200 in the file (the second SD card sector). It takes as many bytes as specified in the Header's Program Size field.

This Game binary is being programmed into the ATmega's Flash by the Game Loaders or ran by emulators.

The Flash contents beyond the Game binary within the ATmega remain undefined (typically they will contain earlier data as Game Loaders only program as many pages as necessary).