initial fce ultra 0.81 import
[fceu.git] / Documentation / tech / UNIF_current.txt
CommitLineData
c62d2810 1****************************************************************************
2 UNIF file format specifications
3 (Universal NES Image) file format
4
5 Created by Tennessee Carmel-Veilleux (veilleux@ameth.org)
6 REV 7b, November 28th, 2000
7
8
9***********THIS IS AN OPEN STANDARD. IT IS OPEN TO SUGGESTIONS**************
10
11Overview
12--------
13The UNIF format is a portable, flexible REPLACEMENT of the NES standard
14(Designed by Marat Fayzullin). It is a chunked file format in the lines of
15the Amiga IFF (LBM), Microsoft RIFF (WAV) and Autodesk 3D studio mesh
16files (3DS). The goal of having a chunked definition is to provide
17flexibility and ease of implementation, as data is described in blocks
18with type IDs referring to them and header information to provide a
19selective data reading. The format uses symetric data conversion for
20numerical compatibility between the different platforms' byte ordering.
21The ordering used is the 6502 Byte order (Intel), so that no more
22bickering arrises from people who do not appreciate Network Byte Ordering
23(Motorola).
24
25***
26The extension suggested for use with this format is .UNF (.UNIF under Operating
27systems which support longer extensions).
28***
29
30Byte ordering
31-------------
32Byte ordering used throughout the file for DWORDs and WORDs is 6502 Byte
33order. The 6502 byte order is LSB, least significant byte first
34(Little-endian):
35
36 3 2 1 0 <- Byte order for MSB (Network Byte order, m68k, PowerPC)
37 0 1 2 3 <- Byte order for LSB (80x86, 6502, Z80)
38
39Care must be taken to convert the WORDs and DWORDs if you are using a
40non-LSB platform (Mac, Amiga, some others).
41
42File format
43-----------
4400h-1Fh : Header
4520h-EOF : Chunks
46
47I can not think of an easier format to describe :)
48
49Header
50------
51The 4-byte header contains the string "UNIF" , NON null-terminated, case
52as written. This is for identification purposes, a little like .NES' "NES^Z"
53It is followed by Revision number and reserved bytes.
54
55Format: 00h-03h: "UNIF" tag identifier
56 04h-07h: DWORD -> Revision number, currently 4
57 08h-1Fh: Reserved for future usage
58
59Sample structure:
60
61structure UNIF_header [
62 char identification[4]; /* MUST be "UNIF" */
63 dword revision; /* Revision number */
64 byte expansion[24];
65];
66
67Chunks
68------
69Each chunks is composed of 3 distinct elements:
70 00h-03h: Chunk ID string
71 04h-07h: DWORD -> Block Length of Data
72 08h-?? : Data
73
74All the chunks are written sequentially in the file. If you do not understand
75a chunk by its ID, simply jump over it using the data length information.
76*** ALL THE CHUNKS ARE OPTIONAL ***
77That means that there are NO mandatory chunks, and you support only the
78ONES YOU WISH, passing over the others while you are interpreting the
79file.
80
81Sample structure:
82
83structure UNIF_chunk [
84 char chunk_ID[4]; /* Chunk identification string. Can also be considered a
85 number. ASCII format */
86 dword length; /* Data length, in little-endian format */
87];
88
89The different chunks:
90---------------------
91*******************************************************************************
92How chunks are described:
93ID field: Contains the 4-characters string identifier for the chunk
94
95Length: Length of the block. If it is "??", then the block may have
96 variable data size depending on the cartridge.
97
98Revision: First revision in which the chunk appeared. If your reader supports
99 a lower revision, you might be unable to read the chunk, simply pass
100 over it. The Revision used by the cart is written in the header. The
101 number represents the Revision Number of the most recent chunk
102 contained in the file. Example : If you have 5 chunks of revision 1
103 and 2 chunks of revision 4 in the file, the Revision number in the
104 header will be 4.
105
106Description: Complete description of the contents and encoding of the chunk
107*******************************************************************************
108
109ID: [MAPR]
110Length: ?? (Suggested max: 32 chars)
111Revision: 1
112Description: This is supplemental information about the mapper. DO NOT USE
113 A MAPPER NUMBER HERE ! Rather use the BOARD NAME. There is
114 already a list in progress describing each NES cart and the
115 board it uses. The string is NULL-TERMINATED.
116
117examples: N,R,O,M,,0 -> This "No mapper"
118 U,N,R,O,M,0 -> This is (LS161+LS32)
119
120NOTA: This mapper organization suggests that emulators must be rewritten
121to emulate the ACTUAL CARTRIDGE HARDWARE, and not solely a case of another
122mapper number. That means you have to make for UNROM:
1231- Mapper handler (74LS161+74LS32)
1242- CHR-RAM Handler
125
126Those components can be reused, since many boards only have a slight
127difference in them compared to similar ones.
128
129**IT SHOULD BE NOTED THAT**: A board name tells you EVERYTHING there is to
130know about a board. You do not need other chunks to tell you how much RAM
131there is, or if it is VRAM. It is all implied by the board name. A list
132will soon be distributed containing board name information.
133
134Address of board table for North American Games and Board Names description:
135http://www.parodius.com/~veilleux/boardtable.txt
136http://www.parodius.com/~veilleux/boardnames
137
138ID: [READ]
139Length: ??
140Revision: 1
141Description: Commentaries for the user of the ROM image. In the case of a
142homebrew game, this can be very useful to store credit and maker
143information. *** This could be "Incitation to littering". Please do not
144put garbage in there. It is meant for either mapper information or
145licensing information for homebrew games.***
146
147
148ID: [NAME]
149Length: ??
150Revision: 1
151Description: NULL-terminated string containing the name of the game. If not
152 present, use the filename as the name.
153
154ID: [TVCI]
155Length: BYTE
156Revision: 6
157Description: Television Standards Compatability Information set to:
1580- Originally NTSC cartridge
1591- Originally PAL cartridge
1602- Does not matter
161NOTE: ALL North American carts that are dumps of the North American
162Version are NTSC. All licensed famicom games are NTSC.
163
164ID: [DINF]
165Length: 204
166Revision: 2
167Description: Dumper information block:
168 structure dumper_info [
169
170 char dumper_name[100]; /* NULL-terminated string containing the name
171 of the person who dumped the cart. */
172 byte day; /* Day of the month when cartridge was dumped */
173 byte month; /* Month of the year when cartridge was dumped */
174 word year; /* Year during which the cartridge was dumped */
175 char dumper_agent[100]; /* NULL-terminated string containing the name of
176 the ROM-dumping means used */
177 ]
178
179ID: [CTRL]
180Length: BYTE
181Revision: 7
182Description: Bitfield containing information about the controllers used by the
183cartridge.
184
185Bit 0: Regular Joypad
186Bit 1: Zapper
187Bit 2: R.O.B
188Bit 3: Arkanoid Controller
189Bit 4: Power Pad
190Bit 5: Four-Score adapter
191Bit 6: Expansion (Do not touch)
192Bit 7: Expansion (Do not touch)
193
194ID: [PCK0] through [PCKF]
195Length: DWORD
196Reivision: 5
197Description: This block contains a 32-bit CRC which can be used to make
198sure that the ROM content matches a checksum when burning on EPROM. This
199block provides a checksum for [PRG0] through [PRGF] inclusively
200
201ID: [CCK0] through [CCKF]
202Length: DWORD
203Reivision: 5
204Description: This block contains a 32-bit CRC which can be used to make
205sure that the ROM content matches a checksum when burning on EPROM. This
206block provides a checksum for [CHR0] through [CHRF] inclusively
207
208ID: [PRG0] through [PRGF]
209Length: ??
210Revision: 4
211Description: Chunks containing the Binary data of the PRG ROM. If there
212are more than 1 PRG chips on the PRG bus, use PRG1, PRG2, PRG4, etc.
213The way PRGs are handled depends on the mapper and emulator. Most generaly
214(99%), only use PRG0. (Some carts have been witnessed with 8 PRG ROMs).
215
216ID: [CHR0] through [CHRF]
217Length: ??
218Revision: 4
219Description: Chunks containing the binary data of the CHR ROM. If there
220are more than 1 CHR chips on the CHR bus, use CHR1, CHR2, CHR4, etc. The
221way CHRs are handled depends on the mapper and emulator. Most generaly
222(99%), only CHR0 is used.
223
224ID: [BATR]
225Length: BYTE
226Revision: 5
227Description: The presence of this block indicates that the board indeed
228contains a battery. This is necessary because many boards have the
229capability of a battery (the traces and holes are there), but they only
230use RAM and don't add the battery at manufacturing time. Examples:
231 * SAROM: MMC1B, PRG ROM, CHR ROM, optional 8k of RAM (battery)
232 * SKROM: MMC1B, PRG ROM, CHR ROM, 8k optional RAM (battery)
233
234Both these boards (SAROM and SKROM) can have a battery, but usually they
235don't have it.
236
237ID: [VROR]
238Length: BYTE
239Revision: 5
240Description: This is a VRAM Override. If this chunk is present, then the
241CHR-ROM area will be considered as RAM even if ROM is present. This
242overrides board identification. This is present so that homemade carts
243which use NROM or others and replace the CHR-ROM with CHR-RAM can still be
244interpreted (since NROM is always CHR-ROM in commercial games).
245
246ID: [MIRR]
247Length: BYTE
248Revision: 5
249Description: This chunk tells you how the hardwired mirroring is setup on
250the board. The board name CANNOT tell you (in most cases) what the
251mirroring is, since the all have solder pads to select the mirroring at
252manufacturing time. The following values are legal:
253
254 * $00 - Horizontal Mirroring (Hard Wired)
255 * $01 - Vertical Mirroring (Hard Wired)
256 * $02 - Mirror All Pages From $2000 (Hard Wired)
257 * $03 - Mirror All Pages From $2400 (Hard Wired)
258 * $04 - Four Screens of VRAM (Hard Wired)
259 * $05 - Mirroring Controlled By Mapper Hardware
260
261Conclusion
262----------
263This ends the specification for Revision 6 of UNIF. If you have ANY
264suggestions to make regarding the UNIF file format, such as chunk ideas or
265modifications, or would like to collaborate to the elaboration and design
266process, e-mail me at veilleux@ameth.org.
267
268A multi-platform C Code Library for UNIF support was made by Evan Teran. It
269is available at http://www.pretendo.org/~proxy/.
270
271[References]
272{.NES file format specifications} by Marat Fayzullin (fms@cs.umd.edu)
273{NESDEV mailing list} by Various authors
274{NES technical documentation} by Jeremy Chadwick (yoshi@parodius.com)
275
276[Credits]
277Neal Tew for his neat emulator and great contribution to the NESdev
278community.
279
280Jeremy Chadwick (yoshi@parodius.com) for his contribution to the NESdev
281community and great advice over the time.
282
283Mark Knibbs (mark_k@iname.com) for his excellent web site as well as his
284more than honorable contribution to the NES world
285
286Matthew Conte (itsbroke@classicgaming.com) for his CajoNES and Nofrendo
287programs
288
289Michael Iwaniec (mrbananmos@yahoo.com) for his interest in UNIF and
290constructive criticism.
291
292Kevin Horton (khorton@iquest.net) for his proposals and support of
293UNIF. He's also been a fantastic help to me in my learning curve of the
294NES's hardware aspects.
295
296/Firebug/ (firebug@cfl.rr.com) for the ideas brought with NIFF
297
298T. Alex Reed {W1k} (rizen@netzero.net) for suggestions of additions
299to UNIF. He also pointed out some mistakes in the original specifications.
300
301Evan Teran {PrOxY} (emt3734@rit.edu) for making suggestions as well as
302writing a .NES->UNIF converter and the LIB_UNIF library.