Hi!
Below you'll find a description of the generic mapper: how it works and the
syntax we use to store its parameters in the INI file. This description is
intended to become part of the standard describing .msx files. Please correct
any mistake I may have made.
Bye,
Maarten
Generic Mapper Specification
============================
* Intro
The generic mapper is a single algorithm that can handle all the different
ROM configurations in MSX cartridges. It handles both cartridges with and
without a MegaROM mapper.
By specifying parameters to the generic mapper it can be used to emulate a
specific cartridge. Those parameters are stored in the info file of a .msx
file. Three keywords are used: "Banksize", "Initial" and "Register".
* "Banksize" parameter
Format:
Banksize=<N>
Where <N> is the bank size in kilobytes. Only powers of two are allowed, so
the only possible values for Banksize are 1, 2, 4, 8, 16, 32 and 64.
Banksize is a mandatory parameter.
The 64K address range of the Z80 is split into 64/Banksize banks. For each
bank it's possible to specify which part of the ROM (if any) is mapped to
that area. The ROM itself is divided into blocks that are also Banksize
kilobytes long. The block numbers are used by the Initial statement and by
the mapper registers of MegaROMs.
Example:
Banksize=8
This specifies a bank size of 8 kilobytes (8192 bytes).
* "Initial" parameter
Format:
Initial[<bank>]=<block>
Where <bank> identifies the bank and <block> is the number of the initial
block for that bank. A bank is identified by the lowest address in it's
address range, the address is notated as a 4-digit hexadecimal number.
If a bank doesn't have a corresponding Initial parameter, it is considered
not connected to the ROM and reading memory in that bank will return the
value #FF (the data bus is pulled up). For banks without a mapper register
associated with them, the initial block will be mapped there forever. For
banks with a mapper register associated with them the initial block is the
block selected after power-on or reset.
Example:
Initial[4000]=0
This specifies the bank starting at address 4000h to have block 0 of the
ROM mapped to it initially.
* "Register" parameter
Format:
Register[{*}<addr>{/<mask>}]=<bank>
Where <addr> is the base address where the mapper register is located at,
<mask> specifies through which other addresses this register can be
accessed and <bank> specifies which bank is switched by this mapper
register. If "/<mask>" is omitted, the mapper register can only be accessed
at its base address. The optional asterix indicates that this mapper
register can be accessed from any slot. The format for address, mask and
bank is a 4-digit hexadecimal number.
The base address of of a mapper register is the lowest address in the
address range that this register can be accessed through. The mask is the
complement of the AND mask that specifies which bits of the base address
are connected. The following test is True if an address X accesses the
mapper register and False otherwise:
( X & ~mask ) == addr
Where "&" is bitwise AND, "~" is complement and "==" is equals.
It is possible to implement the absense of a mask as a zero mask. The
complement of zero is all ones and the test will therefore return True
if and only if X equals addr.
Some cartridges have mapper registers that ignore slot select. Those mapper
registers will react to any write in their address range, no matter the
slot that is currently active in that address range. This is bad design and
fortunately it's very rare (at the moment Super Lode Runner is the only
cartridge known that works this way). So don't use the asterix unless you
are very sure the cartridge has this behaviour.
Example 1:
Register[7000/07FF]=6000
This specifies the bank starting at address 6000h to be switched by a
mapper register that is accessed by writing to any addresses in the range
7000h-77FFh in the slot of the cartridge.
Example 2:
Register[*0000]=8000
This specifies the bank starting at address 0000h to be switched by a
mapper register that is accessed by writing to address 0000h in any slot
of the MSX.
* Mirroring
Block N in the ROM is located at address N * Banksize. It's possible that
this address is higher than the length of the ROM image. In these cases,
a part of the ROM is mirrored at this address. Use this formula for
mirroring:
address_in_ROM = address_accessed & (size_of_ROM - 1)
Where size_of_ROM is the size of the ROM image in bytes, therefore
"size_of_ROM - 1" is the last address located inside the ROM image.
Using this formula makes sure the mirroring effect of real MSX cartridges
is correctly reproduced and it also guards emulators against out-of-bounds
array indexing. An emulator author could use this formula on every memory
read from a cartridge. But it's faster to use a two-step approach: first
use mirroring to make the ROM size a multiple of the block size, then only
perform mirroring on block switches (including the initial block
selection).
--
For info, see http://www.stack.nl/~wynke/MSX/listinfo.html