{
  CMF Player - (c) vIRtECH 1996 Ansgar Scherp

  Version 3.1 - some major and minor bugfixes and some asm speed - up.

  PLAYING CMF-FILES WITHOUT USING THE SBFMDRV FROM CREATIVE LABS (R).
      FOR PROTECTED MODE and REAL MODE including FULL SOURCE CODE!

  (c) vIRTUAL tECHNOLOGIES 1996

  Based on the source by :
    Carl Eric Codere
    codc01@gel.usherb.ca
    http://www-edu.gel.usherb.ca/codc01
  Special thanks to you.

  Distribition via any media is explicit allowed.

  DISCLAIMER:

  We give no warranty for this code, because it was firstly coded for us,
  and not for the public.
  But after lot of people asking us for releasing the source, we decided,
  to make it now available.
  But however, I really don't think that there is a bug in this unit.

  You're not allowed to rerelase the source in a modified version of it.
  However, you can use it as it is for any (even commercial) projects, but
  you have to give credits to the authors.

  for more information contact us:

    Ansgar Scherp
    scherp.ansgar@informatik.uni-oldenburg.de

    http://www.informatik.uni-oldenburg.de/~virtech/

    Mailbox : + 49 (0) 4441 / 851887
    Hotline : + 49 (0) 4441 / 851717 (english, german)


  Please report, if you find any bugs in this source code.

}


{$M 8000, 100000, 100000 }

uses _CMFPLAY, crt, dos;


var
  CMFFileName : STRING;


procedure DisplayInfo;
var
  i : word;

begin
  write  ('Channels : ');
  For i:=0 to 15 do
    If Header.Channels[i] = 1 then Write(i,' ');
  writeln;
  write('CMFFileHeader:');
  with Header do
    begin
      write( CMFFileID ,'       ' );
      writeln('Version:', Version );
      write('Ticks per Quartet:', TicksPerQuartet , '    ' );
      writeln('Ticks per second:', TicksPerSecond );
      writeln('Tempo  :', Tempo );
    end;

  { control }
  writeln;
  writeln(' Controls: ');
  writeln('  ESC - exit player');
  writeln('   Q  - play faster');
  writeln('   A  - play slower');
  writeln('   R  - repeat song');
  writeln('   S  - stop song');
  writeln('   P  - pause / play');
  writeln('   D  - DOS command shell');
  writeln;
end;

var
  i   : word;
  key : char;

begin
  ClrScr;
  writeln('  Protected Mode / Real Mode CMF-Player WITHOUT SBFMDRV BY CREATIVE LABS(R) ');
  writeln('                        (c) vIRTUAL tECHNOLOGIES 1996                       ');
  writeln('-=########################################################################=-');
  writeln;

  CMFFileName := ParamStr(1);

  for i := 1 to length( CMFFileName ) do
    CMFFileName[ i ] := upcase( CMFFileName[ i ] );

  if CMFFileName = '' then
      CMFFileName := 'MUSIC4.CMF'
    else
      if pos( '.CMF', CMFFileName ) = 0 then
          CMFFileName := CMFFileName + '.CMF';

  writeln('FileName : ', CMFFileName );

  { initialise and load CMFFile }
  CMFInit( CMFFileName );

  CMFPausePlay;

  { Check for AdlibCard found  }
  if AdlibBoardInstalled = TRUE then
    begin
      DisplayInfo;

      { playing information }
      CMFSpeed := 1.0;
      Repeat
        WriteLn('Current Song Position: ',CurrentCMFPos:10);
        writeln('PlayingSpeed is 100 % * ',CMFSpeed:5:2);
        WriteLn('Repeat song : ', CMFRepeat  : 6 );
        writeln('Playing     : ', CMFPlaying : 6 );
        gotoxy(1,wherey-4);
        if keypressed then key := upcase(readkey) else key := #0;
        case key of
          'Q' : if CMFSpeed < 10.0 then CMFSpeed := CMFSpeed + 0.25;
          'A' : if CMFSpeed > 0.25 then CMFSpeed := CMFSpeed - 0.25;
          'R' : CMFRepeat := not CMFRepeat;
          'P' : CMFPausePlay;
          'S' : CMFStop;
          'D' :
            begin
              ClrScr;
              Writeln( 'DOS-Command Shell ... ' );
              swapvectors;
              exec( 'C:\COMMAND.COM', '' );
              swapvectors;
              ClrScr;
              Writeln( 'Back in PLAYCMF...' );
              Writeln;
              DisplayInfo;
            end;
        end;
      Until key = #27;
    end;
  Writeln;
  CMFClose;
  ClrScr;
end.