Memory Mapper
This page was last modified 09:39, 12 August 2017 by Gdx. Based on work by Mars2000you and Msxholder and others.

Contents

Introduction

A "memory mapper" is a general term describing a mechanism to 'map' blocks of memory into specific memory ranges (like what's addressed by a CPU). It can apply to RAM, ROM or some combination of those. Often such a mechanism is used to let a CPU address more memory than it supports natively. Memory mappers are used on many different systems, and come in many different shapes & sizes.

In MSX context, it normally refers to a RAM memory mapper as introduced with the MSX2 standard. Memory mappers are also used in some ROM cartridges, usually these are referred to as a "MegaROM" or "ROM mapper".

Memory Mappers on MSX2 and higher

Examples

Internal

  • Yamaha S1985 MSX2 engine IC supports a 512 KiB memory mapper. As a result of a shared pin, it depends on the type of keyboard whether maximum supported size is 256 or 512 KiB.
  • Toshiba T9769 MSX2+ engine supports a 512 KiB memory mapper.
  • Daewoo DW64MX1 MSX2 engine supports a 256 KiB memory mapper in slot 0-2.

Usually not the fully supported size is present. Expansion up to the supported size is relatively easy. Expansion to bigger sizes requires adding more electronics (logic IC's).

The Yamaha S3527 MSX engine does not include support for a memory mapper. Some MSX models include a memory mapper built using discrete logic IC's. Often one or more 74LS670 IC's are used as the actual mapper registers.

External

Maximum size

An MSX memory mapper contains up to 256 (2^8) blocks of 16 KiB (16384 bytes) each. Thus the maximum size for a mapper is 4 MiB (4096 KiB).

I/O ports

It occupies a single cartridge slot, which can be a primary or secondary slot, internal or external. Its configuration is controlled via 4 I/O ports:

  • A write to I/O port 252 (FCh) determines which block is accessible in address range 0000-3FFFh of the cartridge slot.
  • A write to I/O port 253 (FDh) determines which block is accessible in address range 4000-7FFFh of the cartridge slot.
  • A write to I/O port 254 (FEh) determines which block is accessible in address range 8000-BFFFh of the cartridge slot.
  • A write to I/O port 255 (FFh) determines which block is accessible in address range C000-FFFFh of the cartridge slot.

Initialisation

During bootup, the MSX2 bios initializes memory mapper(s) by writing to these I/O ports. Default configuration is as follows:

  • Block 3 is selected for 0000-3FFFh area.
  • Block 2 is selected for 4000-7FFFh area.
  • Block 1 is selected for 8000-BFFFh area.
  • Block 0 is selected for C000-FFFFh area.

For software that's unaware of the memory mapper concept, the default configuration above appears like a regular 64 KiB block of RAM.

RAM selection

It is possible to select the same RAM block for several memory ranges, in which case these ranges will mirror each other (= visible through different memory ranges, but the same RAM is accessed). It is not possible to select multiple blocks in one 16 KiB memory range at the same time; they can be accessed sequentially by switching the mapper blocks using the I/O ports.

In any case, the memory mapper RAM is only accessible in a 16 KiB 'page' of the Z80's address space, if the memory mapper's slot is selected for that page. So one could consider the memory mapper a mechanism that is layered on top of the MSX (sub)slot mechanism.

Reading back mapper registers

Mapper registers written via I/O ports FC-FFh can usually be read back. A programmer should not rely on this, as the results can be confusing, erroneous, or garbage. Especially if multiple memory mappers are present in a system.

Unfortunately it's not uncommon for software to read the mapper registers. For this reason, most memory mappers support read-back of the mapper registers. But not all: a memory mapper that doesn't support read-back, is simpler to construct & thus quite a few memory mappers were built that way.

Multiple memory mappers

It is possible to have multiple memory mappers in an MSX (theoretically up to 15, for a maximum of 60 MiB!). This is not a problem, and some software exists that supports using all that RAM. On MSX2+ and Turbo R computers, the total amount of RAM (excluding video RAM) is displayed under the boot logo.

Each memory mapper has its own copy of the mapper registers. But depending on mapper size, each mapper may only store a limited number of bits for each mapper register. When writing to these registers (I/O ports FC-FFh), all memory mappers present will update their copy at the same time. For example if there are 3 memory mappers present, there will be 3 copies of the mapper registers which are updated simultaneously. When reading back a mapper register in such a configuration, the result may come from the biggest mapper. Or from a built-in mapper. Or in some cases, correspond to a 'floating data bus'. Or some mix thereof. Therefore (as stated above) results are unreliable and programmers should not (ever!) read the mapper registers.

Memory Mappers on MSX1

The BIOS in MSX1 computers doesn't initialize memory mappers. At power up, most memory mappers will have block 0 selected for each of the 4 memory pages, and be recognised as a 16 KiB block of RAM that's mirrored in all pages. There are several solutions to this:

  • Initialization can be performed by hand, followed by a reset (NOT a power cycle!).
  • Some CPLD- or FPGA-based memory mappers do support starting in an MSX-standard configuration (either on power-up, or using hardware /RESET signal).
  • In theory an MSX1 bios ROM could be altered to do mapper initialization like on MSX2 and above.
  • Some cartridges meant to be used on MSX1, may include code to initialize memory mappers.
  • The Yamaha CX5MII is the exception.

Software support

In most cases, it's problematic (or at least difficult) to have multiple pieces of software share the RAM in an MSX. Memory mappers are no exception to this rule. Following software exists to make this easier:

  • MemMan: this is loaded separately from disk, before running software that uses it.
  • MSX-DOS2: its memory mapper support (residing in ROM) includes routines that enables multiple application software to use the same memory mapper(s) without overwriting each others' RAM.

Also a few MSX1 machines and all MSX2 and higher machines have MSX-BASIC support for RAM disk of up to ~216 KiB (see CALL MEMINI). This built-in RAM disk is not aware of MemMan or MSX-DOS2 mapper support, so this RAM disk should not be used in combination with MemMan or MSX-DOS2.