home *** CD-ROM | disk | FTP | other *** search
- { Copyright 1986, 1987, 1988 Carter Scholz}
-
- unit MPU;
-
- interface
-
- uses Crt;
-
- procedure PutData (MidiData:byte); { Puts one byte to MPU. }
- procedure GetData (var MidiData:byte); { Gets one byte from MPU. }
- procedure PutCmd (cmd:byte); { Sends command to MPU. }
- procedure ResetMPU; { Resets MPU to power-up state. }
-
- const
- dataport=$330; { These are port addresses for the }
- statport=$331; { IBM version of the MPU-401. }
- drs=$80; { They must be changed for other }
- drr=$40; { machines. }
- ack=$fe;
- TooLong=$4000; { timeout value }
-
- var
- MPUdone, TimeOut : boolean;
-
- implementation
-
- procedure PutData (MidiData:byte); { Puts one byte to MPU. }
- var
- j: byte;
- k: word;
- begin
- j := 0; k:=0;
- TimeOut:=false;
- repeat
- j := port [statport];
- if (j and drs)=0 then k:=port[dataport];
- inc(k);
- if k>TooLong then Timeout:=true;
- until ((j and drr)=0) or Timeout;
- port [dataport] := MidiData;
- end;
-
- procedure GetData (var MidiData:byte); { Gets one byte from MPU. }
- var
- j: byte;
- k: word;
- begin
- j := 0; k:=0;
- Timeout:=false;
- repeat
- inc(k);
- j := port [statport];
- if k>=TooLong then TimeOut:=true;
- if keypressed then halt;
- until ((j and drs)=0) or TimeOut;
- MidiData := port [dataport];
- end;
-
- procedure PutCmd (cmd:byte); { Sends command to MPU. }
- var
- j: byte;
- k: word;
- begin
- j := 0; k:=0;
- TimeOut := false;
- repeat
- k:=succ(k);
- j := port [statport];
- if k>TooLong then
- Timeout:=true;
- until ((j and drr)=0) or Timeout;
- port [statport] := cmd;
- k:=0;
- repeat
- inc(k);
- GetData(j);
- if k>TooLong then Timeout:=true;
- until (j=ack) or Timeout;
- end;
-
- procedure ResetMPU; { Resets MPU to power-up state. }
- var
- j: byte;
- k: word;
- begin
- k:=0; Timeout:=false;
- repeat
- j := port [statport];
- if (j and drr) = 0 then port [statport] := $ff;
- j := port [dataport];
- inc(k);
- if k>TooLong then Timeout:=true;
- until (j=ack) or Timeout;
- end;
-
- end.