VOGONS


First post, by thp

User metadata
Rank Member
Rank
Member

I've recently added support for MPU-401 to my game-in-development (Vogons thread), but it does not work properly on real hardware, so I thought I'd post here in the audio forum with some programming-related questions.

I followed Programming the MPU-401 and the MIDI Specification as reference for implementing support.

This works fine on DOSBox with MPU-401 emulation, backed by Apple's SoftSynth on macOS. However, on real hardware (SB16 + Roland SCB-7 WaveBlaster daughterboard) I get weird results (missing/wrong notes?).

Is there any additional initialisation that needs to be done in this case? Here's what I do:

Wait for 0x40 bit to be cleared reading from 0x331 ("DATA READ READY" bit cleared).
Send command 0xFF to port 0x331.
Wait for 0x80 bit to be cleared reading from 0x331 ("DATA SET READY" bit cleared).
Read from 0x330 and check if it's 0xFE (acknowledgement), if not, redo last step and this step.
Wait for 0x40 bit to be cleared (see first step).
Send command 0x3F to port 0x331.

At this stage, the MPU-401 should be in UART mode, right?

Then I write bytes (one byte at a time) of MIDI data, to port 0x330, without any delay (except of course for waiting between events).

For the drums/percussion I just write notes to MIDI channel 10 (index 9), for everything else, I send a program change (0xC0-0xC9) for each channel I want to play music on. Also, something that might be important in my case: Every instrument (usually two, a voice and a bass) is fixed to a MIDI channel and only gets the program change at the beginning of the song, and then I just do note on events and note on events with velocity zero (which should be the same as note off?).

Is it kind of guaranteed that a WaveBlaster daughterboard can play multiple notes (different MIDI note) simultaneously on a given channel, or would I need to make sure that when playing notes simultaneously, I distribute them among the 16 MIDI channels?

Reply 1 of 6, by Scali

User metadata
Rank l33t
Rank
l33t
thp wrote:

Then I write bytes (one byte at a time) of MIDI data, to port 0x330, without any delay (except of course for waiting between events).

I don't think that is correct. I believe you *always* need to poll the status at port 0x331 to see if you are allowed to send a byte. And I do mean byte, so not a MIDI command (which may be more than 1 byte).
The same goes for most MIDI interfaces, including the Sound Blaster and IBM Music Feature Card.

http://scalibq.wordpress.com/just-keeping-it- … ro-programming/

Reply 2 of 6, by Tiido

User metadata
Rank l33t
Rank
l33t

Yes, you must wait for the ready bits when reading or writing data bytes.

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜

Reply 3 of 6, by thp

User metadata
Rank Member
Rank
Member

I'll try that. I think I remember reading somewhere that the 0x331 port isn't used in UART except for resetting it to Intelligent Mode, but I guess that only applies to writing, not reading then. Will fix this and retry with real hardware, thanks so far!

Reply 4 of 6, by thp

User metadata
Rank Member
Rank
Member

Yep, that was it, after waiting for the 0x40 bit to be cleared before writing each byte to the MPU-401, it works fine on real hardware as well 😀 Working fine now, thanks a lot! In case anyone wants to have a look at the result, the game thread has a build now supporting General MIDI via MPU-401 UART mode.

Reply 5 of 6, by LABS

User metadata
Rank Member
Rank
Member

Doom-engine's DMX sound library has a similar bug. When it writes DMA buf length to Sound Blaster's DSP it should issue command 0x48 followed by 2 bytes of length, but it does not poll status byte before writing 2nd byte and issues it immediately after the 1st, so it is lost if DSP is not ready to read.

Blasterboard: DIY SB2-compatible sound card on ATmega MCU
Sonic Buster 8: New 8-bit ISA sound card

Reply 6 of 6, by jxalex

User metadata
Rank Member
Rank
Member

very good effort if actually to make from the scratch the programs for DOS with MIDI.

So far, what are so far the ancient history programs (dos/win3x) which support waveblaster extension (except games)?

Current project: DOS ISA soundcard with 24bit/96Khz digital I/O, SB16 compatible switchable.
newly made SB-clone ...with 24bit and AES/EBU... join in development!