< -->

Program MIDI_OUTPROBE;
const
  MIDI_port = $330;
  MIDI_File = 'F:\MIDI\Greatest\7Seconds.mid';
var
  f : File;
  Buff : array [1..100] of Byte;
  i : Word;
  LoTim, HiTim : Word;
  Cmd : Byte;
Function HexB(b : Byte) : String;
const
  HD: array[0..15] of Char = ('0','1','2','3','4','5','6','7',
  '8','9','A','B','C','D','E','F');
begin
  HexB := HD[b shr 4] + HD[b and $F];
end;
Procedure ResetTimer;Assembler;
asm
    mov      cx, 0
    mov      dx, 1
    mov      ah, $86
    int      $15
    jnc       @1
    mov ah, 83h
    mov al, 1
    int 15h
@1:
end;
Procedure Delay(V, W : Word); Assembler;
asm
  @1:
    mov      cx, Word Ptr V
    mov      dx, Word Ptr W
    mov      ah, $86
    int      $15
    jc       @1
end;
Function isDSP : Boolean;Assembler;
asm
  mov   ax, 1
  mov   dx, 226h
  push  dx
  out   dx, al

@1:
  mov   cx, 0
  mov   dx, 30
  mov   ah, $86
  int   $15
  jc    @1

  pop   dx

  xor   ax, ax
  out   dx, al

  mov   dx, 22Eh
  mov   cx, 0FFFFh
@wait:
  in    al, dx
  test  al, 80h
  jnz   @ex
  loop  @wait
@ex:
  mov   dx, 22Ah
  in    al, dx
  cmp   al, 0AAh        {0AAh = 170}
  mov   ax, 1
  je    @eqv
  mov   ax, 0
@eqv:
end;
Procedure DSPwrite(Bt : Byte); Assembler;
asm
  mov   dx, 22Ch
@wait:
  in    al, dx
  test  al, 80h
  jnz   @wait

  mov   al, byte ptr Bt
  out   dx, al
end;
Function DSPread : Byte; Assembler;
asm
  mov   dx, 22Eh
@wait:
  in    al, dx
  test  al, 80h
  jz   @wait

  mov  dx, 22Ah
  in   al, dx
end;
Function DSPversion : String;
var
  LoB , HiB : Byte;
begin
  DSPwrite($E1);
  HiB := DSPread;
  Lob := DSPread;
  DSPversion := HexB(HiB) + '.' + HexB(Lob);
end;
Function Copyright : String;
var
  k : Byte;
  S : String;
begin
  DSPwrite($E3);
  k := 1;
  S[k] := chr(DSPread);
  While S[k] <> #0 do
  begin
    inc(k);
    S[k] := chr(DSPread);
  end;
  S[0] := chr(k);
end;
Function DinamicState : Boolean;
begin
  DSPwrite($D8);
  DinamicState := DSPread = $FF;
end;
begin
  ResetTimer;
  if isDSP then
    Write('DPS присутствует ')
  else
    begin
      WriteLn('DPS отсутствует');
      Halt;
    end;
  WriteLn('версии ', DSPversion);
  Write('Состояние динамика: ');
  case DinamicState of
    False : WriteLn('выключен');
    True : WriteLn('включен');
  end;
  DSPwrite($D1);
  Write('Состояние динамика: ');
  case DinamicState of
    False : WriteLn('выключен');
    True : WriteLn('включен');
  end;
  Assign(f, MIDI_File);
  {$I-}
  Reset(f, 1);
  {$I+}
  if IOResult <> 0 then
   begin
    Write('Файл ', MIDI_File, ' не был открыт.');
    Halt;
   end;
  BlockRead(f, Buff, $60);
  for i := 1 to $60 do
   Write(HexB(Buff[i]): 4);
  HiTim := 0;
  While IOResult = 0 do
  begin
    {I-}
      BlockRead(f, HiTim, 1);
      BlockRead(f, LoTim, 2);
      BlockRead(f, Cmd, 1);
    {I+}
    Write(HexB(Cmd):4);
    DSPwrite($38);
    DSPwrite(Cmd);
    Delay(0, LoTim);
{    Delay();}
  end;
  DSPwrite($D3);
  Close(f);
end.

Назад