How to use the MIDI-PAC as a MIDI-OUT device

By WORP3

Paladin (804)

WORP3's picture

26-12-2017, 14:16

For those interested in how to use the MIDI-PAC as a midi out device, below I've got some sources wich makes it possible to detect the MIDI-PAC, switch it's mode and how to send MIDI data to it's internal buffer.
I always wanted to make some nice manual about it but i just can;t find the time doing this. Probably the most can figuring out on how to do this just fine with the info below. The example is including a wait on MIDI-PAC, but you can skip this if you want, the MIDI-PAC can handle multiple transactions at once.

Have fun.

(Data send has to comply to the MIDI protocol, the midi-pac won't intervene with what you are transmitting)

Tjeerd.

#define DIRECT_MIDI 1
#define NORMAL_MODE 0

void SelectMode(Mode)
char Mode;
{
	MP_AddressOut(0xED);	/*Select required mode*/
	MP_DataOutWait(Mode);
}

void SendMidi()
{
#asm
SM_01:	
	IN		A,(07Ch)		;Get new handshake
	AND		1
	JR		NZ,SM_01		;Wait for midi to transmit if buffer is full
	LD		E,0EEH			;Write MIDI-PAC address
	PUSH	DE
	CALL	.MP_AddressOut
	POP		DE
	LD		A,(.Data)		;Write Data
	LD		E,A
	PUSH	DE
	call	.MP_DataOutWait
	POP		DE
#endasm
}

void MP_AddressOut(Address)
char Address;
{
#asm
	LD		HL,2				;Get stack pointer into HL and skip ret address
	ADD		HL,SP
	LD		A,(HL)				;Get Address
	OUT		(07Ch),A
	
	PUSH	BC					;4	Wait minimum 24 clock cycles to overcome turbo-r speed
	LD		B,8					;2
ATOADRWAIT:	
	DJNZ	ATOADRWAIT			;2
	POP		BC					;3	9+(8(loops)*2)=25 cycles
#endasm
}

/*Write data to special MIDI-PAC register and wait until action has finished*/
void MP_DataOutWait(Data)
char Data;
{
#asm
	LD		HL,2				;Get stack pointer into HL and skip ret address
	ADD		HL,SP
	LD		C,(HL)				;Get data
	IN  	A,(07Ch)			;Store current handshake
	AND		2
	LD		B,A
	LD		A,C					;Write new data to MIDI-PAC
	OUT		(07Dh),A
MP_006:	
	IN		A,(07Ch)			;Get new handshake
	AND		2
	CP		B					;Compare new handshake with old one
	JR		Z,MP_006			;Still the same so continue waiting for MDI-PAC
#endasm
}

char MP_Present()
{
#asm
	LD		HL,0				;Default return 0
	IN		A,(07Ch)			;Store last value of INT0 bit
	AND		004h
	XOR		004h
	LD		C,A
	LD		A,0F5h				;Write to WORP3 address 0xF5, which won't repply with handshake
	OUT		(07Ch),A
	IN		A,(07Ch)
	AND		004h
	CP		C
	RET		NZ
	IN		A,(07Ch)			;Store last value of INT1 bit
	AND		008h
	XOR		008h
	LD		C,A
	LD		A,0FFh				;Write to WORP3 data register 0xFF
	OUT		(07Dh),A
	IN		A,(07Ch)
	AND		008h
	CP		C
	RET		NZ
	LD		L,1					;Return 1 (successful)
#endasm
}
Login or register to post comments

By Louthrax

Prophet (2076)

Louthrax's picture

27-12-2017, 12:08

Mmmm... Seems like doing a patch for Illusion City to use the MIDI PAC is doable...

By WORP3

Paladin (804)

WORP3's picture

27-12-2017, 15:48

Great idea Big smile

By WORP3

Paladin (804)

WORP3's picture

27-12-2017, 15:55

Some additional information on the I/O Registers used by the MIDI-PAC

MSX I/O Address	Read/Write	Function
0x7C		Read 		Midi-Pac Readback register
0x7C		Write		Register address poort
0x7D		Write		Register data poort
		
 	Readback register	
Bit	Description	
0	Readback	
1	Handshake	
2	Change on 0x7C	
3	Change on 0x7D	
4	CPLD Version bit 0	
5	CPLD Version bit 1	
6	CPLD Version bit 2	
7	Change on 0xA1	

Mode register:
Switch to MIDI direct mode
Writing a 1 to this register will enable the MIDI direct mode. Selecting this mode will disable the rest of the MIDI-PAC, so no FM-PAC support during direct MIDI write.

Data != 1:Enter normal mode
Data== 1: Enter MIDI direct mode

ReadBack will function as a Buffer full status:
'0'=Midi buffer not full, data can be written
'1'=Midi buffer full, wait until '0' again.

By ToriHino

Champion (348)

ToriHino's picture

27-12-2017, 18:28

Any information about the available timers within the MIDI-PAC as well?

By Louthrax

Prophet (2076)

Louthrax's picture

27-12-2017, 20:51

ToriHino wrote:

Any information about the available timers within the MIDI-PAC as well?

Had the same question, Illusion City's code is using timers in lots of places (could maybe be replaced with turboR timers, but that project will probably not be so easy).

By WORP3

Paladin (804)

WORP3's picture

27-12-2017, 23:18

Louthrax wrote:
ToriHino wrote:

Any information about the available timers within the MIDI-PAC as well?

Had the same question, Illusion City's code is using timers in lots of places (could maybe be replaced with turboR timers, but that project will probably not be so easy).

Although there are several timers inside the MIDI-PAC, non of them can directly being used in this MIDI-OUT mode. Maybe something to look at if this is something more users like to use....

By sdsnatcher73

Champion (491)

sdsnatcher73's picture

24-07-2019, 07:29

Actually I was wondering if it would be possible to add MSX-MIDI compatible mode to MIDI PAC? Specifications seem to be simple enough and the 8251 seems available as vhdl code (but needs purchase?): Altera a8251 data sheet