User:Zzo38/ines.map and unif.map

From NESdev Wiki
< User:Zzo38
Revision as of 19:42, 24 August 2012 by Zzo38 (talk | contribs)
Jump to navigationJump to search

This file describes the format of ines.map and unif.map files used with DotFami.

The file is a plain ASCII file which is preprocessed with the C preprocessor and uses a C-like syntax. All constant operators (other than sizeof) are the same as in C, including the same precedence.

All data is signed 64-bit integers. ASCII character constants can be used, and you can use decimal, hexadecimal, and octal constants, same as in C.

Keywords

crc
default
flags
function
if
local
mapper
parameter
procedure
rom
romsize
submapper
switch
use

Outer Codes

At the top (outer) level of the file, the following statements are allowed:

  • variable = expression ;
  • parameter expression = expression ;
  • use string ;
  • if( condition ) statement
  • if( condition ) statement else statement
  • { statements }
  • switch( expression ) { cases }
  • function name ( parameters ) { statements }
  • procedure name ( parameters ) { statements }
  • procedurename ( parameters );

Inner Codes

Where statement(s) are expected at inner level, the following is acceptable:

  • variable = expression ;
  • parameter expression = expression ;
  • use string ;
  • if( condition ) statement
  • if( condition ) statement else statement
  • { statements }
  • switch( expression ) { cases }
  • local variables (only inside a {} block)
  • procedurename ( parameters );

Cases

A case in a switch is formatted as either a string literal or a constant expression, followed by { statements }

The last case must be default instead of an expression and contains statements if none of the other cases match.

Variables

  • Each variable may only be assigned once and must be assigned before used.
  • Some variables can be local to a block, which case they are accessible only within that block.
  • If a condition or switch statement contains blocks which assign variables not local to those blocks, then all cases must assign the same set of variables (not counting variables local to those blocks).
  • A procedure may also assign global variables.
  • Variables store 64-bit values.
  • Parameters to procedures and functions are also acting like local variables which are already assigned.
  • Strings can also be assigned to variables although they cannot be used as a number if they do.

Procedures

  • Procedures must be declared before used.
  • Recursive calls are not allowed.
  • Same rules for variables, use statements, and parameter statements apply to procedures, just as if its contents are placed where the procedure is called from.

Functions

  • Functions must be declared before used.
  • Recursive calls are not allowed.
  • A function call is made inside of an expression.
  • Only local variables may be assigned in a function.
  • Procedure calls are not allowed in a function.
  • The use and parameter statements are not allowed in a function.
  • The last statement (even inside a if or switch) should be an expression by itself which is the return value of this function.

Expressions

  • mapper: For iNES, the mapper number. For UNIF, the mapper name (as a string).
  • submapper: NES 2.0 submapper number (0 for old iNES files).
  • flags: Used in both iNES and UNIF; includes flags such as battery RAM, mirroring, and so on. (TODO: Needs to document)
  • romsize expression: The expression a number 0 to 15 for PRG ROM, or 16 to 31 for CHR ROM. This indicates the size in bytes.
  • rom expression: The expression is address (starting at PRG ROM 0, ..., CHR ROM 15) and returns the data byte at that address.
  • crc expression: Expression is same as for romsize but result in CRC32 of ROM.
  • Strings can be compared using == and != only, and arithmetic may not be performed on strings.
  • name ( parameters ): Make a function call.

Miscellaneous

The parameter statement is optional and the first expression is the parameter number (0 to 255 only); each parameter can be assigned a maximum of one time, but it is not necessary that if it is assigned in one case that it must be assigned in the other cases as well.

The use statement must occur exactly once, using the same restrictions as assignment to variables. The string parameter can be a variable storing a string, or a string literal, which specifies the filename for a .cart file.

Errors

In case of division by zero or anything that violates the specifications here, there is no guarantee of what it will do, including it might crash. However, it might just display an error message instead.