SFG05 Access

Pagina 1/5
| 2 | 3 | 4 | 5

Door erwinmusik

Master (140)

afbeelding van erwinmusik

01-06-2012, 19:59

I´m starting to check the functionality of the SFG05 in my CX5MII-128.

After weeks of reading all stuff I found in the web and first steps with assembler (after 25 years) I have a some questions:

when I read the example of basic access to the SFG here:


I wonder about the access to the SFG with change the A8H Register only. Whats about the Expansion Memory in FFFFh?
The SFG sits on Primary 3 and Expansion 3.
So far I understand this Register have to change too?
If I check these Position in a dissambler (BasDis), it takes a 55h, after CPL 2-2-2-2.
And the Primary Slot Register shows all "3"

On my blueMSX I started a small code from basic and let me show these registers:
Primary 3-3-0-0

Aangemeld of registreer om reacties te plaatsen

Van erwinmusik

Master (140)

afbeelding van erwinmusik

01-06-2012, 21:45

(cant't edit the first post)
Secondary 2-2-0-1

I have changed all memory locations in the machine Editor to the same configuration like the CX5MII
All Memory in 3-2
DiskRom in Slot 1 4000h ( is that correct?)
SFG05 in 3-3

How can the author of these MidiCode be shure to access the SFG05 only with write to the A8h port?

Van hit9918

Prophet (2932)

afbeelding van hit9918

02-06-2012, 04:24

Secondary slot pitfalls: Every primary slot got its own FFFF, there are multiple of them!

This means first in A8 set page 3 to that slot, then write FFFF.
Do it under disabled interrupts, because page 3 is system RAM.

"How can the author of these MidiCode be shure to access the SFG05 only with write to the A8h port?"
Maybe it was set up somewhere before, and because there are multiple FFFF, it was not trashed later. Just guessing.

Van erwinmusik

Master (140)

afbeelding van erwinmusik

02-06-2012, 11:58

These code based on an example from Yamaha, Göteborg in 1985.
Here is more of example code:

The author used the first CX5M and maybe these one comes up with a "3" at FFFFh in Primary Slot 3.
So it is enough to switch page 0 from Primary 0 to 3 for accessing the SFG.
In this model it seems that all is in Slot 0, except the SFG. In the later CX5MII the complete RAM is in Subslot 2 of Primary 3.

For me and my model, I have to use A8h and FFFFh to select the SFG, thats what I understand.

What is the better way: Interslotcalls via BIOS or switching pages, access and switch back to BIOS?
I guess what I plan more to use; more BIOS or more routines in the SFG.
Do I have to EI the interrupts everytime I come back from a BIOS to my code?
Some Call´s do not switch it on

Van erwinmusik

Master (140)

afbeelding van erwinmusik

11-06-2012, 19:58

A question to NYYRIKKI or someone who has expieriences with the SFG05:

I found a lot of informations about the SFG05, some code (see the post above)
but no detailed informations about the exactly handling of the two MIDI registers

MIDSTA: EQU 3FF6h ; MIDI Statusregister

I checked both with my own code (it´s not a real "sniffer"), found present data if I put MIDI in the input but I can´t catch what really happens.
All data is too fast to sort out what exactly occurs.

Do You have informations about the Bits of the Statusregister?
I saw bit 0 is always set, bit 2 and 5 some times, I guess one of them say: "there is data".
In the code for ESQ Sysex I found two MIDI Reset commands, but no explanation.

I´m familiar with MIDI in all kinds and the meaning of MIDI Data as well, ASM programming: I´m learning again (comes slowly back in my memory after 25 years)

Van Manuel

Ascended (19470)

afbeelding van Manuel

11-06-2012, 21:39

Maybe the source code of blueMSX helps here?

Van erwinmusik

Master (140)

afbeelding van erwinmusik

12-06-2012, 16:00

The idea is very good, I love to read C-Code, I mean I hate it.

But anyway, there´s a lot of #include files to crosscheck.

I´m not shure how to find the right "registers", because read/write isn´t over the UART and I/O , it´s reading memory.
I found many functions around the 8251, but MIDI from the SFG isn´t direct from it, I´m right?
The SFG05 have two main chips, the 2151 (FM) and the 2148 for MIDI, Keyboard and controls
Access only over #3FF0-#3FF7 Slot 3/Expanded 3 in my CX5MII

Thus I´m not shure BlueMSX haven´t always the right mechanism. Ít´s an emulation for all machines...

Van mars2000you

Enlighted (6502)

afbeelding van mars2000you

12-06-2012, 17:13


Excerpts :

static UInt8 read(RomMapperSfg05* rm, UInt16 address) 
    if (address < 0x3ff0 || address >= 0x3ff8) {
    	return rm->romData[address & rm->sizeMask];

    switch (address & 0x3fff) {
    case 0x3ff0:
        return ym2151Read(rm->ym2151, 0);
    case 0x3ff1:
        return ym2151Read(rm->ym2151, 1);
    case 0x3ff2:
        return getKbdStatus(rm);
    case 0x3ff5:
        return ym2148ReadData(rm->ym2148);
    case 0x3ff6:
        return ym2148ReadStatus(rm->ym2148);

    return 0xff;
static void write(RomMapperSfg05* rm, UInt16 address, UInt8 value) 
    if (address < 0x3ff0 || address >= 0x3ff8) {

    switch (address & 0x3fff) {
    case 0x3ff0:
        ym2151Write(rm->ym2151, 0, value);
    case 0x3ff1:
        ym2151Write(rm->ym2151, 1, value);
    case 0x3ff2:
        rm->kbdLatch = value;
    case 0x3ff3:
        ym2148SetVector(rm->ym2148, value);
    case 0x3ff4:
        boardSetDataBus(value, value, 1);
        ym2151SetIrqVector(rm->ym2151, value);
    case 0x3ff5:
        ym2148WriteData(rm->ym2148, value);
    case 0x3ff6:
        ym2148WriteCommand(rm->ym2148, value);

Van mars2000you

Enlighted (6502)

afbeelding van mars2000you

12-06-2012, 17:32

Here's the translation of a French technical doc :


SFG I/O Addresses

5 addresses are available in the memory space to program the SFG, at the end of page 0 from 0000H to 3FFFFH when they are connected to the Z80 bus :

3FF0H command port for the processors YM2151/2164
3FF1H data port for the processors YM2151/2164

3FF2H port for the YK keyboard controller

3FF5H data port for the MIDI interface
3FF6H command port for the MIDI interface

Besides these 5 addresses you have also

3FF3H register for the low address of the interruption's vector in Z80's IM2 mode for a MIDI interruption
3FF4H like 3FF3H, but for the timers or undefined interruptions


3FF5H and 3FF6H
Both addresses concern the MIDI interface and work also as input/output.

3FF5H is only used to read or write data in the 8bit MIDI format, but as this port combines data input and output, you need always to test if they are valid by reading of the status register.

3FF6H is used as command port in writing mode and as status register in reading mode. Infos about the status register are not yet completed. Rreception of MIDI data requests to use interruptions routines if you want to write a performing program. You can simply re-use the routines of the Yamaha software as they are used in the MIDI recorder (YRM301) for example. The description of the 3FF6H registers can only be viewed as a possible example.

The command register 3FF6H (only in writing mode)

7       6       5        4      3         2      1      0    bits
Init    x       x      RstEr  IrqON       1      0      1

Bit 7 is for initialisation of the MIDI interface and is used alone.

ex :

       LD A,80H
       LD(3FF6H),A    Initialisation of the MIDI port
       LD A,5
       LD(3FF6H),A    Starting of the interface in emission/reception mode
                              without provoking an interruption 

The second part of the routine loads 5 on the same port and starts the interface while masking the interruptions. Bit 3 is used actually to validate the interruptions in reception mode. When making our tests in Z80's IM1 mode, we have loaded the value 0DH after the initialisation to allow MIDI handling without interruptions. Yamaha uses the Z80's IM2 mode (vectorised interruptions) and loads the value 6DH. A test of this value in IM1 mode gives the same results than with 0DH. Role of bits 5 and 6 has not been defined, but they should be useful in IM2 mode.

Bit 1 is used in the Yamaha software after a reading of the data port to apparently revalidate the interruptions of the MIDI input, if no any "error" flag is positioned. In IM2 mode, the soft sends therefore the value 6FH.

Finally, bit 4 is just used to make a reset when an error flag appears on the status register.

The status register 3FF6H (only in reading mode)

7       6       5        4       3         2      1         0         bits
-       -       Err 1   Err 2   -         x      INrcv  OUTok 

Bit 0 has value 1 when it mentions that MIDI data can be sended

Bit 1 has value 1 when new data are received

Role of bit 2 has not been defined

Error bits :
- Err 1 has value 1 when the reception buffer is saturated
- Err 2 has value 1 when there's a transmission error or an incorrected signal

When one error bit or both error bits have value 1, a reset is made on bit 4 of the command register.


Additionnal note on the MIDI interface

Using of the MIDI interface in the Yamaha software is always made by using the Z80's IM2 mode, what means by vectorised interruptions.

Theorically, the MIDI interface is able to provoke an interruption when data are received, but also when the transmission buffer is empty and therefore ready to receive new data.

The status register does not mention by a bit a transmission interruption, although in reception mode, bit 1 is positioned for a reception. In the Yamaha software, an interruption caused by the MIDI interface in IM2 mode will be connected to the routine of the MIDI interruptions. If the bit of the status register, which mentions usually data have been yet received, has value 0, it will imply that the interruption corresponds to the transmission. It justifies using of IM2 mode, as in IM1 mode, it should be impossible to know if the interruption comes from the transmission module of the MIDI interface or from another unidentifiable peripherical.

Procedures used in the Yamaha software are as following :

Data reception ? Bit 1 of status register 3FF6H

        No                      Yes

Therefore IRQ Tx         Data Reading

Data sending               Reinitialisation in 3FF6H
                                  with 6FH or 7DH
                                  if an error bit is positioned

Reinitialisation in 3FF6H
with 6DH value


Van erwinmusik

Master (140)

afbeelding van erwinmusik

12-06-2012, 19:24

Thanks so much. That´s exactly what I need, it explains almost everything.
The rest is try and error.
I´ll take the 0Dh after reset ....that seems the best for first attempts.

Greetings from Berlin

Van erwinmusik

Master (140)

afbeelding van erwinmusik

14-06-2012, 19:38

(With the 0Dh after reset MIDI it hangs, ok, try without 0Dh)

Since I do not have expieriences with realtime programming, there are some questions left.

My code runs, I see changing the registers, but I´m not shure my code is in the right order.

Do I have to read the Data Register as long as the Bit 1 is set in the Status?
Or if bit 1 is set I do a loop as long as data comes from the 3FF5H?

I dont understand the Procedure for Data reception above, especcialy the reinitialisation.

Bit 5 is always set if I press only one key on my MIDI Keyboard.
What does this mean? How big is the reception buffer?

Pagina 1/5
| 2 | 3 | 4 | 5