Memory Mapper
This page was last modified 23:58, 12 December 2018 by Grauw. Based on work by Gdx and PAC and others.

Contents

Introduction

A memory mapper is a general term describing a mechanism to map different blocks of memory into specific pages of the memory addressable by the 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 the MSX context, it normally refers to a RAM Memory Mapper as introduced optionally 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 supports a 512 KiB memory mapper. Due to a shared pin, it depends on the type of keyboard whether the 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 less than the fully supported size is installed. Expansion up to the supported size is relatively easy, expansion to bigger sizes requires adding more logic.

The Yamaha S3527 MSX engine does not include support for a memory mapper. Some MSX models include a memory mapper built using discrete logic ICs, often one or more 74LS670s.

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

Memory mappers have 4 write-only registers on the following I/O ports:

  • Port FCh (252) selects the segment in page 0 (0000-3FFFh).
  • Port FDh (253) selects the segment in page 1 (4000-7FFFh).
  • Port FEh (254) selects the segment in page 2 (8000-BFFFh).
  • Port FFh (255) selects the segment in page 3 (C000-FFFFh).

If multiple memory mappers are installed on the system, the registers will act on all of them at the same time.

The mapper registers are specified in the standard as write-only. Although on several mappers they can also be read, software must not make use of this, it will not be interoperable. See the section on reading back for more details.

Initialisation

The MSX2 BIOS initializes memory mappers by setting up the following configuration:

  • Segment 3 is set on page 0 (0000-3FFFh).
  • Segment 2 is set on page 1 (4000-7FFFh).
  • Segment 1 is set on page 2 (8000-BFFFh).
  • Segment 0 is set on page 3 (C000-FFFFh).

For software unaware of memory mappers, the default configuration above appears like a regular 64 KiB block of RAM.

RAM selection

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 the memory mapper mechanism is layered on top of the MSX (sub)slot mechanism.

It is recommended to use the MSX-DOS2 extended BIOS mapper support routines when available. This will improve the compatibility and interoperability of your software in the MSX-DOS2 environment. Using MU or MemMan can be an alternative when DOS2 is not available. Otherwise, the mapper registers can be accessed directly, but this is only suitable when your software uses the mapper exclusively.

When using the MSX-DOS2 mapper support routines, it is recommended to allocate from all slots (B=20h), store the slot ID along with the segment number, and when selecting the mapper page also select its slot (if changed). This will enable you to use all of the available memory rather than only the primary mapper. This is especially relevant for the MSX Turbo R, where the internal memory is always the primary mapper, and only 256K in the ST, partly used by MSX-DOS2 and DRAM mode.

It is possible to select the same RAM block in several memory pages, in which case these pages will mirror each other. That is, the same 16K RAM block is visible in different memory pages.

Reading back mapper registers

The mapper registers are specified in the standard as write-only. Although on several mappers they can also be read, software must not make use of this, it will not be interoperable, especially if multiple memory mappers are present. That said, here are some details on what can happen when you do.

Firstly, not all memory mappers support read-back. A memory mapper without readable registers is simpler to construct, and thus quite a few memory mappers were built that way.

When a mapper has readable registers, they indicate the current segment selected on the corresponding memory page. Most memory mappers do not store all eight bits, the unused bits can be mirrors of the used bits, or remain either high or low or floating. As such, reading can cause bus conflicts when several mappers are present.

The amount of bits stored also needs not correspond to the amount of memory installed in the machine, e.g. the Panasonic FS-A1 (a 64K machine) stores values up to 3Fh (1024K), bits 6-7 always stay 1 or 0. The number of bits stored can indicate the amount of memory the MSX can be easily internally expanded to without adding additional logic.

Additionally some MSX machines block external cartridge slots from responding to I/O read requests to the mapper ports and other system ports. This is for example the case on Panasonic MSX2+ models and the Turbo R ST / GT.

As a result, when reading a mapper register in a configuration with multiple mappers, 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.

Unfortunately software which reads the mapper registers does exist, especially certain European 128K software. For this reason most memory mappers support read-back of the mapper registers. This does not always help though, e.g. Pumpkin Adventure 2 will not work on a Panasonic MSX2+ with external memory mapper cartridge, no matter if it has read-back. For that software, either a software patch or an internal memory expansion is the only solution.

Multiple Memory Mappers

It is possible to have multiple memory mappers in an MSX, theoretically up to 15, for a maximum of 60 MiB! 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. Depending on the mapper size, each may store a different number of bits. When writing to these registers, 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.

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 segments, which means a single 16 KiB block of RAM is mirrored in all segments. The machine will typically boot, but as soon as a program larger than a few KiB is loaded it will overwrite the system area.

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 initialise to the standard 3-2-1-0 configuration.
  • The Yamaha CX5MII BIOS is patched by Yamaha to initialise the memory mapper like on MSX2 and above. It is one of the few MSX1 computers with a memory mapper.
  • An MSX1 BIOS ROM can be modified to do mapper initialization like on MSX2 and above.
  • Some cartridges meant to be used on MSX1 may include code to initialize memory mappers.
  • Booting with Nextor DOS will initialise the mapper.

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. The following solutions exists to make this easier:

  • MSX-DOS2: Provides extended BIOS mapper support routines which enable multiple applications to use the same memory mappers without overwriting each other’s RAM.
  • MU: Provides MSX-DOS2 compatible extended BIOS mapper support routines on MSX-DOS1. Software must explicitly free allocated memory on program termination though.
  • MemMan: Provides memory mapper and TSR support routines for software in both MSX-DOS1 and MSX-DOS2.

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