How cartidge works

By MicBert75@yahoo.com

Supporter (8)

MicBert75@yahoo.com's picture

12-10-2016, 12:49

Are any MSX guru out there?
I would like to understand how the expansion slot works. I mean, when you insert a cartidge in the upper slot, and you turn on the computer, it start to execute the code on the cartidge rom, instead of the usual one. Thus there must be an "electrical way" to detect if there is something, and then some kind of standard of how such rom is organized (starting from the address space).
Do anyone know about a source of technical documentation about that?
The purpose is to self develop a cartidge working as a digital and analog signal interface.

Login or register to post comments

By Metalion

Paragon (1451)

Metalion's picture

12-10-2016, 13:30

At boot, the ROM checks every slots and search for a combination of bytes that indicates the presence of a cartridge. If the bytes are present, then it transfer the execution to the address specified in the cartridge header.

Specifically, you should start your code at $4000 with bytes $41, $42 and then the start address of your code. For example : $41, $42, $10, $40 for a code located at $4010.

By MicBert75@yahoo.com

Supporter (8)

MicBert75@yahoo.com's picture

12-10-2016, 16:06

I think I have to understand better also the "slot" mechanism...

By hit9918

Prophet (2911)

hit9918's picture

12-10-2016, 22:15

in one part there is a hardware detection: a slot expander can be detected at address FFFF. independant of whether cartridges are inserted.
there are up to 4 different registers at FFFF. toggeled by primary slot selection port A8, page 3.
and everything built into the MSX works with the same sheme, as if it was cartridges plugged into slots.

By RetroTechie

Paragon (1563)

RetroTechie's picture

13-10-2016, 08:39

Welcome to the MRC, MicBert75! Smile

From a hardware point of view, an MSX cartridge slot is basically a Z80 pinout with a few signals and power supply pins added. And can be used as such.

From a logical (programmer's) point of view, the MSX slot mechanism is a way to map Z80's 64K address space onto different memory areas where expansions may be found. In this context, there is no difference between internal or external slots.

The documentation you seek is the MSX Technical Data Book. Try here (OCR-ed, text searchable) or here (scanned PDF) for example.

Paragraphs 1.4.9 "Slots" and 1.5.2 "Cartridge Bus" have the hardware details. In the circuit diagram in paragraph 1.4.9, 8255's PA0..PA7 can be read/written via Z80 I/O port A8h. But in general you should use the BIOS routines for this.

Paragraph 2.2.3 "Slot Control" describes the slot mechanism's layout, cartridges and RAM search procedure. This is the info needed to program your own ROM cartridge(s).

Many MSX(2) machines have a single, internal slot expanded, read: slots 0 (internal), slot 1 (external), slot 2 (external) and slot 3-0 through 3-3 (internal).
Some have slot 0 expanded, so slots 0-0...0-3, 1, 2, 3.
Some have both slot 0 and 3 expanded. And many MSX1 machines only have primary slots 0..3.
But other configurations exist, and no assumptions about this are safe to make for a programmer.

MicBert75@yahoo.com wrote:

The purpose is to self develop a cartidge working as a digital and analog signal interface.

Aaaannnd there's also the Z80 I/O ports that can be used for this. Both memory mapped I/O and Z80 I/O-ports have their pro's and cons. So this should be weighed carefully depending on your intended uses.

By MicBert75@yahoo.com

Supporter (8)

MicBert75@yahoo.com's picture

19-10-2016, 14:51

Metalion wrote:

At boot, the ROM checks every slots and search for a combination of bytes that indicates the presence of a cartridge. If the bytes are present, then it transfer the execution to the address specified in the cartridge header.

Question: is the BIOS calls always available? Are they stored in a sort of fixed address space, not involved in the slot management?

By l_oliveira

Hero (532)

l_oliveira's picture

05-11-2016, 16:04

MicBert75@yahoo.com wrote:
Metalion wrote:

At boot, the ROM checks every slots and search for a combination of bytes that indicates the presence of a cartridge. If the bytes are present, then it transfer the execution to the address specified in the cartridge header.

Question: is the BIOS calls always available? Are they stored in a sort of fixed address space, not involved in the slot management?

The SLOT system actually allows you to use the BIOS or simply map the BIOS out and have RAM on all 64KB of Z80 address space.

That's how you can have MSX DOS (CP/M clone) run on the computer. You need 64KB of RAM to be able to run MSX DOS.

Most games in cartridge leave the BIOS (1st half of system ROM) selected at 0x0000-0x7FFF, have a 32KB window (0x4000-0xBFFF) selected for it's own slot and have the slot which has the system RAM selected at 0xC000-0xFFFF.

You see, it's complex but it allows you to reconfigure the machine the way you need or want.

By NYYRIKKI

Enlighted (5889)

NYYRIKKI's picture

05-11-2016, 19:41

The slot handling is the worst part of MSX standard, so I can't suggest starting by going too deep in to hardware handling from the start. As a fair warning many have done so and then suddenly the program has all kinds of compatibility problems.

How ever it is important to understand how Z80 see the address space in MSX:
- Memory can be assigned from 4 slots (0-3)
- All of these 4 slots CAN be divided in to 4 subslots (0-3)
- Z80 address space (64KB) is divided to 4 parts, 16KB each and all of them can have own control for above mentioned slot selecting system

We usually write the slots like "slot 3-2" that means extended slot 3, subslot 2.

MSX is very democratic about slots... With this I mean that any slot is not "more important" than another and there is not really rules, what devices (such as RAM, disk drive or game) needs to be on certain slot.

When power to the machine is applied the computer is pretty lost... The code execution is started from address 0 on slot 0 or if the slot is extended then from slot 0-0... So this is the place where the BIOS must be in... Other than that the slot layout is not very important. First the BIOS code goes trough all available slots and searches for biggest RAM it can find and selects it to #C000-#FFFF block. If it is MSX2 it is next like "Where the heck is rest of my ROM", it goes trough the slots to search it and saves the SlotID information to RAM... After this it is like "Ok, I'm ready, does anybody else have something to say?" and it starts to go trough the slots once again and when it hits the described header it will let the program to execute initialization code / game / what ever the cartridge / device / ROM wants to execute. This is how devices like HDD, music extensions etc. get initialized. Game is naturally a bit different as usually game routine does not exit unless it needs some extension that is not yet initialized (such as disk)

When MSX jumps to the starting address you defined there are two options for the memory layout:
If your starting address is between #4000-#7FFF the addresses #0000-#3FFF contain BIOS, #4000-#7FFF contains your code and #8000-#FFFF contains RAM. If your starting address is between #8000-#BFFF then #0000-#7FFF contain BIOS + BASIC, #8000-#BFFF contain your code and #C000-#FFFF contain RAM.

Typical situation is that you want to switch from the defaults to so that 32KB of your ROM is visible. In this case I suggest that you copy/paste "Where the heck am I located"-code from the MSX2 Technical handbook listing 5.11 to your project template. It uses the ENASLT routine in address #24 to switch the slots... SlotID and ENASLT is practically enough you need to know about slots for a long time... Later you can deepen your knowledge a bit more if that is required.