Slots
This page was last modified 12:45, 7 February 2019 by Gdx. Based on work by Mars2000you and Zeilemaker54 and others.

Contents

Description

Slots is a system to expand the memory. This system has been standardized from the beginning. It allows to route the memory placed in the slots to the CPU by pages of 16KB. It is necessary because Z80 can only address at most 64KB.

Slots can contain RAM, ROM or other devices (e.g. mappers). They can also be empty. Each slot can address 64KB of RAM or ROM. This is split into four pages located in the following areas: 0000h-3FFFh, 4000h-07FFFh, 8000h-BFFFh, C000h-FFFFh.

There are two types of slots, primary slots and secondary slots. There are 4 primary slots, each of which can be expanded into 4 secondary slots, providing up to 16 slots in total. Typically two of the primary slots are exposed to the user as external cartridge slots, the others are for internal use. The internal slots are often expanded, however the external slots are not. Expanding the external slots is left to the user, by using a slot expander. Secondary slots are usually numbered as follows:

Slot <primary slot number> - <seconary slot number>.

All MSXs have Main-ROM in primary slot 0 or in secondary slot 0-0 (see variable EXPTBL below for more details). Cartridge slot that is on top of computer is typically slot 1. If there is another expansion port then this is often slot 2. Although the internal RAM should preferably be in slot 3, this is often not the case for MSX1s.

In MSX2 slot 0 is usually expanded. Same goes with slot 3. This is because these computers need to point more memory because they need Sub-ROM and maybe also disk drive, Kanji ROM, firmware etc. In these computers main BIOS is in slot 0-0 and Sub-ROM in secondary slot 0-X or 3-X.

Please note: I just explained how things are TYPICALLY, don't trust this info as fact!

Programming

I/O port A8h allows to access the primary slots register. It selects the slot that the Z80 can address on the corresponding page. Each pair of bits represent one page and the value of the bits represent the slot number. I/O port A8h can also be read.

To access the secondary slots, you must first select the corresponding primary slot in page 3 (C000h-FFFFh) to be able to access the secondary slot register (of this primary slot) via the FFFFh address. Address FFFFh can be read, but it returns all the bits inverted, for the purpose of detection of expanded slots by the BIOS. This means that you need to execute "CPL" in assembler or "XOR 255" in BASIC to get the value that was written to this address.

BIOS automatically handles these primary slots and secondary slots, and the routines related to slot handling require you to give a Slot ID as parameter. This is a byte where bits 0 & 1 represent the primary slot number, bit 7 tells if slot is expanded or not and bits 2 & 3 represent the secondary slot number if bit 7 is set.


Slots Registers format

bits 7-6 bits 5-4 bits 3-2 bits 1-0
Slot of page C000h~FFFFh Slot of page 8000h~BFFFh Slot of page 4000h~7FFFh Slot of page 0000h~3FFFh

Available BIOS routines for slots

000Ch (RDSLT)

Function: Reads one byte from memory of the slot specified.
Entry: A = Slot ID to read (F000EEPP format)
HL = Address of byte to read (from 0000h to BFFFh)
Output: A = Byte read
Modify: AF, BC, DE
Notes:
  • This routine disables the interrupts.
  • This routine also exists under MSX-DOS.

0014h (WRSLT)

Function: Writes one byte to memory of the slot specified.
Entry: A = Slot ID
E = Byte to write
HL = Writing address (from 0000h to BFFFh)
Output: None
Modify: AF, BC, D
Notes:
  • This routine disables the interrupts.
  • Call the hook H.OUTD (0FEE4h).
  • This routine also exists under MSX-DOS.

001Ch (CALSLT)

Function: Calls the routine in another slot (inter-slot call)
Entry: IX = Address to call
IY = Slot ID
Output: Depends on the calling routine.
Modify: AF, IX, IY, auxiliary registers, and other registers depending on thecalling routine
Notes:
  • Interrupts are disabled by the routine.
  • Can not call another extended slot of the same primary slot where the BIOS is located.
  • This routine also exists under MSX-DOS.

0024h (ENASLT)

Function: Selects the specified slot.
Entry: HL = Page to select the slot
A = Slot ID to select
Output: None
Modify: All Registers
Notes:
  • Unlike the RDSLT, WRSLT and CALSLT routines, the primary slot switching is performed directly in page 0, thus, addresses in page 0 (0000H to 3FFFh) will cause a system crash.
  • This routine also exists under MSX-DOS, where it will work also for page 0, with the sole limit that it cannot call another extended slot of the same primary slot where the BIOS is located.
  • This routine disables the interrupts.
Example:
; Back to Basic from MSX-DOS 

MNROM	equ	0FCC1h
ENASLT 	equ	00024h
RETURN	equ	0409Bh

	org	0D000h
DEBUT:
	ld	a,(MNROM)
	ld	hl,0
	call	ENASLT	; Select main ROM on page 0 (0000h~3FFFh)
	ld	a,(MNROM)
	ld	hl,04000h
	call	ENASLT	; Select main ROM on page 1 (4000h~7FFFh)
	jp	RETURN	; 

0030h (CALLF)

Function: Calls the routine in another slot.
Entry: Calling sequence:
	RST	30H
	DB	n	;n is the slot number (same as RDSLT)
	DW	nn	;nn is the called address
Output: Depends on the calling routine
Modify: AF, IX, IY, auxiliary registers, and other registers depending on thecalling routine
Notes:
  • Interrupts are disabled by the routine.
  • Can not call another extended slot of the same primary slot where the BIOS is located.
  • This routine also exists under MSX-DOS.

0138h (RSLREG)

Function: Reads a byte from I/O port 0A8h to register A
Entry: ---
Output: A
Modify: A

013Bh (WSLREG)

Function: Writes register A to I/O port 0A8h
Entry: A
Output: ---
Modify: ---

015Ch (SUBROM)

Function: Executes inter-slot call to SUB-ROM (MSX2~)
Entry: IX for the calling address and, at the same time, pushes IX on the stack
Output: Depends on the called routine
Modify: Background registers and IY are reserved

015Fh (EXTROM)

Function: Executes inter-slot call to SUB-ROM (MSX2~)
Entry: IX for the calling address
Output: Depends on the called routine
Modify: Background registers and IY are reserved

System Variables and Work Area for slots

Address Name Length Description
Subroutines For Inter-Slot Read/Write/Call:
F380h RDPRIM 5 Read from primary slot, used by RDSLT (000Ch) routine from Main-ROM
F385h WRPRIM 7 Write to primary slot, used by WRSLT (0014h) routine from Main-ROM
F38Ch CLPRIM 14 Call primary slot, used by CALSLT (001Ch) routine from Main-ROM
FAF8h EXBRSA 1 SUB-ROM Slot ID. (MSX2~)
F348h MASTER 1 Disk Master ROM Slot ID. (Disk System Only)
FB21h DRVINV 8 Slot ID and number of drives connected to disk interfaces
DRVINV+0 = Slot ID of disk interface 1 
(in most cases this is also the master disk rom)
DRVINV+1 = Number of drives connected to disk interface 1
DRVINV+2 = Slot ID of disk interface 2
DRVINV+3 = Number of drives connected to disk interface 2
DRVINV+4 = Slot ID of disk interface 3
DRVINV+5 = Number of drives connected to disk interface 3
DRVINV+6 = Slot ID of disk interface 4
DRVINV+7 = Number of drives connected to disk interface 4
FCC1h EXPTBL 4 Bit 7 of these variables is a flag for each primary slot to indicate if the slot is expanded or not. The other bits are reset. The first variable (also called MNROM) indicates the Slot ID of the Main-ROM. This implies that the Main-ROM of an MSX is always in primary slot 0, or secondary slot 0-0.
EXPTBL+0 = Flag for slot 0 (also Slot ID of the Main-ROM!)
EXPTBL+1 = Flag for slot 1
EXPTBL+2 = Flag for slot 2
EXPTBL+3 = Flag for slot 3

Note: MSX2 upgrade MA-20 for MSX1 moves the Main-ROM to another Slot. It changes the first variable to 0FCC1h (also called MNROM) to indicate the new Slot ID of the Main-ROM. This has the effect that it is no longer possible to determine whether the slot 0 is extended or not. The variable MINROM (0FFF7h) should be able to solve this problem but the extension also modifies MINROM.

FCC5h SLTTBL 4 Saves the state of the 4 secondary slot registers of each extended primary slot.
SLTTBL+0 = Value for slot 0
SLTTBL+1 = Value for slot 1
SLTTBL+2 = Value for slot 2
SLTTBL+3 = Value for slot 3
 Format:
  Bits 1-0 = Extended slot on page 0 (0000h~3FFFh)
  Bits 3-2 = Extended slot on page 1 (4000h~7FFFh)
  Bits 5-4 = Extended slot on page 2 (8000h~BFFFh)
  Bits 7-6 = Extended slot on page 3 (C000h~FFFFh)
FCC9h SLTATR 64 Slot attributes given during MSX boot process.
Bit 7 = 1 if Basic program, else 0
Bit 6 = 1 if device extension, else 0
Bit 5 = 1 if statement extension, else 0
Bits 4~0 = Unused
FD09h SLTWRK 128 SLTWRK is a 128-byte array for storing temporary data or reserving a RAM work area for ROM applications. This array is composed of 8 bytes per slot (4 x 2 bytes per memory page) as follows.
SLTWRK+0 = Work area for slot 0-0, page 0 (0000h~3FFFh)
SLTWRK+2 = Work area for slot 0-0, page 1 (4000h~7FFFh)
SLTWRK+4 = Work area for slot 0-0, page 2 (8000h~BFFFh)
SLTWRK+6 = Work area for slot 0-0, page 3 (C000h~FFFFh)
SLTWRK+8 = Work area for slot 0-1, page 0
  .
  .
  .
SLTWRK+124 = Work area for slot 3-3, page 2
SLTWRK+126 = Work area for slot 3-3, page 3

You can use the two bytes that correspond to the application location to store any values, but if you need more RAM than these two bytes, use them to place an Slot ID (in the format describe below) on the first byte or a pointer to the work area of the application.

The pointer indicates the first address of the zone to be reserved in the free area whose beginning is indicated by the variable BOTTOM (0FC48h) and the end by MEMSIZ (0F672h). (Caution: Take into account that stack size that is variable.)

The slot ID is used to reserve a work area on the pages 0 and 1 (0000h~7FFFh).
Slot ID format used in table SLTWRK:

Bit:   7    6     5     4     3     2     1     0
Name:  F   RMD   APP   RES   SS1   SS0   PS1   PS0

  PS = Primary slot number
  SS = Secondary slot number
  RES = Reserved
  APP = Set if the RAM used by an application, 0 otherwise
  RMD = Set if the RAM is used by instruction CALL MEMINI, 0 otherwise
    F = Set if secondary slot, 0 if primary slot.

Perform the following calculation to find the location reserved for your application in ROM.

Address = SLTWRK + 32*primary slot + 8*expanded slot + 2*page number

Note: The array is not valid for the first 7 bytes because the system reserves them in the following way.

SLTWRK = Slot ID for the area reserved by CALL MEMINI. (MSX2~)
SLTWRK+1 = 2 * 3 bytes for Kanji or Hangul modes of Japanese or Korean MSXs.
           (SLTWRK + 4 indicates the Kanji Basic ROM Slot)
FFF7h MINROM 1 Slot address of Main-ROM.
Use EXPTBL+0 to know Slot ID of the internal Main-ROM. (MSX2~)
FFFFh SLTSL 1 Access address to selection register of secondary slots. (Available in extended slots only.)
Format:
 Bits 1-0 = Extended slot on page 0 (0000h~3FFFh)
 Bits 3-2 = Extended slot on page 1 (4000h~7FFFh)
 Bits 5-4 = Extended slot on page 2 (8000h~BFFFh)
 Bits 7-6 = Extended slot on page 3 (C000h~FFFFh)

Note: Read value has the INVERTED bits of previous written value.

Program samples

; Select the slot 2-1 for page 1 (4000h-07FFFh) using BIOS routine

ENASLT	equ	0024h

	ld	h,040h
	ld	a,08Fh	;Slot ID
	call	ENASLT
; Select the slot 2-1 for page 1 (4000h-07FFFh) using direct accesses

	in	a,(0A8h)	;Read primary slots register
	ld	b,a		;Store current configuration
	and	00110011b	;Resets the bits of pages 4000h-07FFFh and C000h-0FFFFh
	or	10001000b	;Sets the bits of pages 4000h-07FFFh and C000h-0FFFF to 2
	di
	out	(0A8h),a	;Select primary slot 2 for the pages 4000h-07FFFh and C000h-0FFFFh

	ld	a,(0FFFFh)	;Read secondary slots register of selected primary slot
	cpl			;Reverses the bits
	and	11110011b	;Resets the bits of page 4000h-07FFFh 
	or	00000100b	;Sets the bits of page 4000h-07FFFh to 1
	ld	(0FFFFh),a	;Select secondary slot 2-1

	ld	a,b		;Restore initial configuration of primary slots to A
	and	11000000b	;Keep only the bits of page C000h-0FFFFh
	ld	b,a		;Store the bits of page C000h-0FFFFh to B
	in	a,(0A8h)	;Read primary slots register
	and	00111111b	;Resets the bits of page C000h-0FFFFh
	or	b		;Sets the bits of page C000h-0FFFF to initial value
	out	(0A8h),a	;Select initial primary slot for the page C000h-0FFFFh
	ei