uses crt,dos,vocplay,design;

var ch : char;
    next_voc : integer;
    Vocname : string;

procedure Write_Helptext;
begin;
  textcolor(lightgray);
  textbackground(black);
  clrscr;
  writeln(' ABACUS VOC-Player      Version 1.0, (c) 1995',
	        '      Author: Boris Bertelsons');
  writeln;
  writeln(' Usage: Vocdemo <Filename[.VOC]> [options]');
  writeln;
  writeln(' Options are:');
	writeln(' -H        : This screen');
  writeln(' -In       : Use interrupt n');
	writeln(' -Dn       : Use DMA channel n');
  writeln(' -Pxxx     : Use base address xxx');
  writeln;
  Cursor_On;
  halt(0);
end;

procedure interpret_commandline;
var cs,hs : string;
    li,code : integer;
    Datnm : boolean;
begin;
  for li := 1 to 10 do begin;
    cs := paramstr(li);
    Datnm := true;
    { Help requested ? }
    if (pos('-h',cs) <> 0) or (pos('/h',cs) <> 0) or
       (pos('-H',cs) <> 0) or (pos('/H',cs) <> 0) or
       (pos('-?',cs) <> 0) or (pos('/?',cs) <> 0) then begin;
       write_Helptext;
      Datnm := false;
    end;
    { force irq }
    if (pos('-i',cs) <> 0) or (pos('/i',cs) <> 0) or
       (pos('-I',cs) <> 0) or (pos('/I',cs) <> 0) then begin;
      force_irq := true;
      hs := copy(cs,3,length(cs)-2);
      val(hs,dsp_irq,code);
      Datnm := false;
    end;
    { Force DMA ? }
    if (pos('-d',cs) <> 0) or (pos('/d',cs) <> 0) or
       (pos('-D',cs) <> 0) or (pos('/D',cs) <> 0) then begin;
      force_dma := true;
      hs := copy(cs,3,length(cs)-2);
      val(hs,dma_ch,code);
      Datnm := false;
    end;
    { Force Base ? }
    if (pos('-p',cs) <> 0) or (pos('/p',cs) <> 0) or
       (pos('-P',cs) <> 0) or (pos('/P',cs) <> 0) then begin;
       hs := copy(cs,3,length(cs)-2);
       if hs = '200' then dsp_addr := $200;
       if hs = '210' then dsp_addr := $210;
       if hs = '220' then dsp_addr := $220;
       if hs = '230' then dsp_addr := $230;
       if hs = '240' then dsp_addr := $240;
       if hs = '250' then dsp_addr := $250;
       if hs = '260' then dsp_addr := $260;
       if hs = '270' then dsp_addr := $270;
       if hs = '280' then dsp_addr := $280;
       Startport := dsp_addr;
       Endport   := dsp_addr;
      Datnm := false;
    end;
    if Datnm then begin;
      Vocname := cs;
    end;
  end;
end;

procedure Games_Vocfile(datname : string);
var li : integer;
    ch : char;
    loopcounter : word;
begin;
  loopcounter := 0;
  repeat
    inc(loopcounter);
    clrscr;
    writexy(10,08,'Warning !  VOC looping relentlessly !!!');
    writexy(10,10,'To exit, press   >>  Q  <<');
    writexy(10,14,'If possible, remove Smartdrv, because it is slooooooow !');
    gotoxy(10,17);
    write('Pass no. ',loopcounter);
    Init_Voc(datname);
    ch := #0;
    repeat
      if keypressed then ch := readkey;
    until VOC_READY or (upcase(ch) = 'Q');
    VOC_DONE;
  until upcase(ch) = 'Q';
end;


begin;
 cursor_off;
 interpret_commandline;
 Init_SB;
 textcolor(lightgray);
 textbackground(black);
 write_sbconfig;
 delay(1333);
 repeat
   textcolor(15);
   textbackground(1);
   clrscr;
   Vocname := select_file('*.voc','*.voc','','');
   if Vocname = 'xxxx' then next_voc := 255
   else Games_Vocfile(Vocname);
 until next_voc = 255;
 cursor_on;
 textmode(3);
end.
