Playing Midi Files in TP 5.5

Would someone please help me!?

I would like a midi player for Turbo Pascal 5.5.

I have attached my Adlib Unit.

Alter it as you need.

___  _  _ ____ _
|  \ |  |  ||  |
|__/ |__|  ||  |
|    |  |  ||  |
|    |  |  ||  |___

  tra...@epix.net

Unit Adlib;

INTERFACE

Uses Crt,Dos;
Const ADLIB_FM_ADDRESS =   $388;
      ADLIB_FM_DATA    =   $389;

      FreqTable :array[0..107] of Word =
      (   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
          0,   0,   0,   0,   0,   0,   0, 516, 547, 580, 614, 651,
        689, 730, 774, 820, 869, 920, 975,1540,1571,1604,1638,1675,
       1713,1754,1798,1844,1893,1944,1999,2564,2595,2628,2662,2699,
       2737,2778,2822,2868,2917,2968,3023,3588,3619,3652,3686,3723,
       3761,3802,3846,3892,3941,3992,4047,4612,4643,4676,4710,4747,
       4785,4826,4870,4916,4965,5016,5071,5636,5667,5700,5734,5771,
       5809,5850,5894,5940,5989,6040,6095,6660,6691,6724,6758,6795,
       6833,6874,6918,6964,7013,7064,7119,7684,7715,7748,7782,7819);

Type FMInstrument = record
       SoundChar :array[0..1]of Byte;
       Level     :array[0..1]of Byte;
       AD,SR,WS  :array[0..1]of Byte;
       Feedback  :Byte;
     End;

  Procedure WriteFM(Reg, Value :Byte);
  Function ReadFM :Byte;
  Function AdlibExists :Boolean;
  Procedure FMReset;
  Procedure FMKeyOff(Voice :Byte);
  Procedure FMKeyOn(Voice :Byte;  Freq :Word);
  Procedure FMVoiceVolume(Voice,Vol :Byte);
  Procedure FMSetVoice(VoiceNum :Byte;  FM :FMInstrument);

IMPLEMENTATION

Procedure WriteFM(Reg, Value :Byte);
Var I    :Word;
    T,T2 :Byte;
Begin
  Port[ADLIB_FM_ADDRESS] := Reg;
  For T := 0 to 5 do T2 := Port[ADLIB_FM_ADDRESS];
  Port[ADLIB_FM_DATA] := Value;
  For T := 0 to 35 do T2 := Port[ADLIB_FM_ADDRESS];
End;

Function ReadFM :Byte;
Begin
  ReadFM := Port[ADLIB_FM_ADDRESS];
End;

Function AdlibExists :Boolean;
Var State1, State2 :Byte;
Begin
  WriteFM($4, $60);
  WriteFM($4, $80);
  State1 := ReadFM;
  WriteFM($2, $FF);
  WriteFM($4, $21);
  Delay(800);
  State2 := ReadFM;
  WriteFM($4, $60);
  WriteFM($4, $80);
  If ((State1 and $E0) = 0) and ((State2 and $E0) = $C0) then
    AdlibExists := True  ELSE  AdlibExists := False;
End;

Procedure FMReset;
Var I: Byte;
Begin
  For I := $1 to $F5 do WriteFM(i, 0);
  WriteFM($1, $20);
  WriteFM($BD, $00);
End;

Procedure FMKeyOff(Voice :Byte);
Var RegNum :Byte;
Begin
  RegNum := $B0 + (voice mod 11);
  WriteFM(RegNum, 0);
End;

Procedure FMKeyOn(Voice :Byte;  Freq :Word);
Var RegNum, Tmp :Word;
Begin
  RegNum := $A0 + (voice mod 11);
  WriteFM(RegNum, (freq and $ff));
  RegNum := $B0 + (voice mod 11);
  Tmp := ((Freq shr 8) or $20);
  WriteFM(RegNum, Tmp);
End;

Procedure FMVoiceVolume(Voice,Vol :Byte);
Var RegNum :Byte;
Begin
  RegNum := $40 + (Voice mod 11);
  WriteFM(RegNum, Vol);
End;

Procedure FMSetVoice(VoiceNum :Byte;  FM :FMInstrument);
Var OpCellNum, CellOffset :Byte;
Begin
  CellOffset := (VoiceNum mod 11) mod 3 + (((VoiceNum mod 11) div 3) shl 3);
  OpCellNum := $20 + CellOffset;
  WriteFM(OpCellNum, FM.SoundChar[0]);
  Inc(OpCellNum,3);
  WriteFM(OpCellNum, FM.SoundChar[1]);
  OpCellNum := $40 + CellOffset;
  WriteFM(OpCellNum, FM.Level[0]);
  Inc(OpCellNum,3);
  WriteFM(OpCellNum, FM.Level[1]);
  OpCellNum := $60 + CellOffset;
  WriteFM(OpCellNum, FM.AD[0]);
  Inc(opCellNum,3);
  WriteFM(opCellNum, FM.AD[1]);
  opCellNum := $80 + cellOffset;
  WriteFM(opCellNum, FM.SR[0]);
  Inc(opCellNum,3);
  WriteFM(opCellNum, FM.SR[1]);
  opCellNum := $E0 + cellOffset;
  WriteFM(opCellNum, FM.WS[0]);
  Inc(opCellNum,3);
  WriteFM(opCellNum, FM.WS[1]);
  opCellNum := $C0 + VoiceNum;
  WriteFM(opCellNum, FM.Feedback);
End;

Begin
  If not AdlibExists then
  Begin
    Writeln('Adlib NOT FOUND!');
    Exit;
  End;
  FMReset;
End.