MSX Assembly Page

Section 5 MSX-MIDI

From MSX Datapack Vol. 3

Translated by Laurens Holst

Attached files: thru.mac, thru.doc,

Chapter 1: About MSX-MIDI

With MSX-MIDI, MIDI functionality and BASIC extensions were added to MSX-MUSIC to enable it to use MIDI. Unlike MSX-MUSIC, there is no BIOS. Non-BASIC MSX-MIDI programs directly access the hardware from the I/O ports.

MSX-MIDI can be both built into the machine body, or an external cartridge. MSX MIDI is only available to MSX turbo R and later. It can not be used on MSX, MSX2 and MSX2+.

MSX-MIDI is organized as follows:

Chapter 2: Hardware

Between internal or external MSX-MIDI, the hardware configuration and access methods and such is different. What follows is a description of the MSX MIDI hardware configuration.

Additionally, regardless of whether timer IC 8253 or 8254 is used, it will henceforth be referred to as “8253”.

2.1 Block Diagram

The MSX-MIDI hardware is organised as follows:

MSX-MIDI block diagram

Figure 4.1 MSX-MIDI block diagram

2.2 Internal MIDI interface

The I/O ports of the built-in MSX-MIDI interface are assigned as follows:

2.3 External MIDI Interface

The external MSX-MIDI interface’s I/O port address can be changed by setting a value to I/O port 0E2H.

2.4 Method to distinguish internal from external type

In case bit 0 of MAIN ROM address 002EH is 1, the MSX-MIDI is internal.

In models whose MAIN ROM version number (002DH) is 03H or more, the features of the MSX-MIDI can be used with an external cartridge.

In the internal type and the external type, the hook is different. This distinction is important in order to create an application. For hooks, please see 3.2 “Hooks” and chapter 4 “Application development”.

To make the distinction between internal type and external type, examine the string starting at MSX MIDI ROM address 4018H.

Table 4.1 String to distinguish MSX-MIDI
Address Internal External
4018H41H (A)??H (?)
4019H50H (P)??H (?)
401AH52H (R)??H (?)
401BH4CH (L)??H (?)
401CH4FH (O)4DH (M)
401DH50H (P)49H (I)
401EH4CH (L)44H (D)
401FH4CH (L)49H (I)

In external cartridges, the 4 unspecified bytes at 4018H are different for each manufacturer. The data at 401CH consists of “MIDI”.

2.5 Method to detect presence of MIDI interface

The presence or absence of the MIDI interface can be determined in the following manner:

  1. In case MAIN ROM address 002EH bit 0 is 1, the MIDI interface is internal.

  2. In case the MAIN ROM version number (002DH) is 03H or more, look for a slot which contains the following in 401CH-401FH:

        DB "MIDI"

    If it exists, the external cartridge is inserted.

  3. When the above cases do not apply, since there is no MIDI interface, the MIDI function can not be used.

  4. In case the ROM version number is 02H or less, the MIDI interface can not be used.

Chapter 3: Interrupts

3.1 Interrupts in BASIC

1/60 sec (NTSC) or 1/50 sec (PAL) interrupts have been used for the MSX-MUSIC, but in the MSX-MIDI BASIC extensions 5 ms interrupts from the 8253 are used.

3.2 Hooks

The MSX turbo R built-in MSX-MIDI’s hooks are as follows:

Table 4.2 Internal MSX-MIDI hooks
Address Name Former name Content
0FF93H H.MDTM H.FRQINT 8253 timer interrupt

In case of external cartridge, because these hooks can not be used, please use H.KEYI. Usage details are described in chapter 4 “Application Development”.

Table 4.3 External MSX-MIDI hooks
Address Name

Chapter 4: Application Development

4.1 Notes regarding application development

When creating an application program that supports MSX-MIDI, please note the following points:

  1. The hooks are different depending on whether MIDI is built-in or external. When setting up a hook, please check if the type is internal or external.

  2. When enabling interrupts, such as after MIDI interface initialization, because there is a possibility that the interrupt flag has already been set, the interrupt flag must be reset.

    Interrupt flags are as follows:

    Table 4.4 MIDI interface interrupt flags
    Interrupt type Interrupt distinction Interrupt clear method
    Timer Bit 7 (DSR) of 0E9H or 0E1H Write any value to 0EAH
    MIDI IN Bit 0 (RRDY) of 0E9H or 0E1H Read 0E8H with IN instruction
  3. With the external cartridge, other interrupts besides MIDI IN and 8253 timer also come from H.KEYI. Therefore, the interrupt handling routine must detect what kind of interrupt the current interrupt is.

    Whether or not it is a MIDI IN interrupt can be checked in bit 1 of I/O port address 0E9H.

    Whether or not it is an interrupt from the 8253 timer can be checked in bit 7 of I/O port address 0E9H.

  4. At the shortest, the MIDI IN receive interrupt occurs at 320 µs intervals. When calling an interrupt handling routine from the hook with the RST 30H instruction, the inter-slot call takes time to process and will not complete in time for 320 µs interval reception.

    For that reason, set up interrupts as follows:

    • Place the interrupt handling routine in page 3

    • Jump from the hook to the interrupt handling routine with the JP instruction

4.2 Sample program

For MIDI interface and hook set up / tear down, please refer to the included sample program (THRU.MAC).

Chapter 5: BASIC Extensions