Memory Mapper
This page was last modified 16:18, 26 May 2023 by Mars2000you. Based on work by Gdx and Grauw and others.

Contents

Introduction

A memory mapper is a general term describing a mechanism to map different segments 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 and 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 "ROM mapper". See also "MegaROM" which are ROMs of 1Mbit or more with a "ROM mapper".

Memory mappers on MSX2 and higher

Examples

Internal

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

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

A memory mapper can also be integrated in any interface or game cartridge for example but in this case, the cartridge will only be usable in a primary cartridge slot.

Maximum size

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

I/O ports

Standard memory mappers have 4 registers accessible via 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 memory mapper registers of RAM expansions are specified by the standard as write-only. Internal MSX mapper registers can also be read but it is not recommended to read them in your programs. See the section on reading back for more details.

Initialisation

The MSX2 and above BIOS initialize the memory mapper segments 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 4 regular pages of 16 kB RAM each in its own slot.

RAM selection

The memory mapper RAM is only accessible by 16 kB page by the Z80 when the memory mapper’s slot is selected. 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 segment in several memory pages, in which case these pages will mirror each other. That is, the same 16kB RAM segment is visible in different memory pages.

Reading back mapper registers

The memory mapper registers of memory expansions are specified by the standard as write-only. That said, here are details on what can happen when you do it.

Some RAM expansions also allow reading to imitate an internal mapper, but given that internal mappers registers are also readable, it can causes wrong reading of the values, at best the result comes from the larger mapper, at worst deteriorate the components, when the expansion is used on an MSX computer with an internal mapper or another mappers with its registers readable. The reason is that the mappers does not handle all bits. So added bits can cause a short circuit depending on how the reading of bits is handled by the mapper circuitry.

Unfortunately software which reads the mapper registers does exist, especially certain European 128K software and ROM cracks.

Many of these software rely on the unhandled bits to define the size of the memory mapper because them are generally all put to 1, or 0. So this cannot be determined when these bits do not have the expected value or when the largest mapper is not selected as primary RAM.

See: List of software reliant on mapper read-back

Multiple memory mappers

It is possible to have multiple memory mappers in an MSX, theoretically up to 15, for a maximum of 60 MB! Some software exists that supports using all that RAM. On MSX2+ and MSX 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.

Note: Contrary to the popular idea that it is better to buy a Memory Mapper with its readable registers, prefer those with its registers write only to avoid any problem. You can use at most only one on MSXs without internal memory mapper for example.

Memory mappers on MSX1

The BIOS in MSX1 computers doesn’t initialize segments mapper. At power up, most memory mappers will have segment 0 selected for each of the 4 memory pages, which means a single 16 kB segment of RAM is mirrored in all pages. The machine will typically boot under BASIC, but as soon as a program larger than about 3 KB is loaded it will overwrite the system variables and work area.

There are several solutions to avoid this:

  • Initialization can be performed by hand or autoexec.bas, followed by a MSX computer reset.
  • Some CPLD or FPGA based memory mappers initialise its segments to 3-2-1-0 order at the MSX computer start/reset.
  • Path the Main-ROM as Yamaha did for the Yamaha CX5MII. It initialises the segments like on MSX2 and above. It is one of the few MSX1 computers with a memory mapper.
  • Some cartridges meant to be used on MSX1 may include code to initialize the segments into a ROM.
  • Booting with Nextor DOS (or its disk BASIC) will initialize the segments and select the larger 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. It can also create one or two RAM-Disk and select the CPU mode on MSX turbo R.
  • 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 kB (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.

How to know if Main-RAM is in a memory mapper

Use the Basic program DMM.BAS (listing below). It displays the size and the slot number. (Requires disk system)

5 'Display the main memory mapper size
10 S%=PEEK(&HF341) OR PEEK(&HF342) OR PEEK(&HF343) AND &H8F: IF S%<>PEEK(&HF344) AND &H8F THEN PRINT"Main-RAM is disposed in several slots!": BEEP: END
20 IF PEEK(&HF677)=&HC1 THEN 50
30 CLS: PRINT CHR$(13)+"DMMM v0.5 by GDX": PRINT "wait...";
40 POKE &HF676,1: POKE &HF677,&HC1: POKE &HC100,0: RUN"DMMM.BAS"
50 PRINT CHR$(13)+"wait...";STRING$(23,32);
60 FOR N=255 TO 0 STEP -1
70 OUT 254,N: POKE &H8000,N
80 NEXT N: SZ=0
90 FOR N=0 TO 255
100 OUT 254,N
110 OT=T: T=PEEK(&H8000)
120 IF N=255 AND OT=254 THEN SZ=255
130 IF T=N THEN IF N<128 THEN SZ=N
140 NEXT N
150 'OUT 254,1: POKE &HF676,1: POKE &HF677,&H80: POKE &H8000,0
160 IF SZ<4 THEN PRINT CHR$(13);"No mapper found!": BEEP: END
170 PRINT CHR$(13);"Main mapper size:"; SZ*16+16;"KB"
180 PRINT"Slot:"; S% AND 3;
190 IF S%>128 THEN PRINT"-";(S% AND 12)/4