{ R.PAS - Demo of music and drum routines for Tandy 1000 and/or PCJr }

uses drums,noiz;

var
  cnt,i,j,k: integer;
  parm1: string;

function value(st: string): integer;
var n,n1: integer;
begin
  val(st,n,n1);
  if (n1 <> 0) then
  begin
    st:=copy(st,1,n1-1);
    val(st,n,n1)
  end;
  value:=n;
  if (st = '') then value:=0;
end;

procedure melody(v: voices;s: styles);
begin
  sound(e2);
  play(e4,20,v,s); play(b4,20,v,s);
  play(a4,20,v,s); play(d4,20,v,s);
end;

procedure scale1;
begin
  sound(e2);
  play(e4,23,0,2); play(fs4,23,0,2);
  play(g4,23,1,2); play(a5, 23,1,2);
  play(b5,23,0,2); play(cs5,23,0,2);
  play(d5,23,1,2); play(e5, 23,1,2);
end;

begin
  quiet;
  cnt:=0;
  parm1:=paramstr(1);
  writeln('Strike Any Key to End');
  writeln('Note: if you enter a number <1..9 etc.> as a parameter');
  writeln('      the song will repeat that many times unless hey hit');
  crash(1,55);
  repeat
    inc(cnt);
    scale1; quiet;
    melody(1,1);
    quiet;
    sound(e2);  chord(e5,b5,fs5,12,15);
    sound(fs2); chord(fs5,cs5,fs5,12,15);
    sound(b2);  chord(b5,fs5,g5,12,15);
    sound(d2);  chord(d5,g5,fs5,12,15);
    sound(a2);  chord(a5,e5,g5,12,15);
    sound(e2);  chord(e6,b6,fs6,12,15);
    melody(1,4);
    sound(a2);  chord(a5,e5,a4,12,12);
    sound(c1);  chord(a5,fs5,c4,12,16);
    sound(d1);  chord(a5,g5,d4,12,12);
    sound(e1);  chord(a5,a5,e4,12,16);
    sound(g1);  chord(a5,b5,g4,12,12);
    sound(a3);  chord(a6,c6,a5,12,16);
    melody(1,3);
    sound(e2);  chord(e3,b4,fs4,55,15);
    sound(d2);  play(d4,20,1,4);
    sound(g2);  play(g4,20,1,4);
    sound(cs2); play(cs4,20,1,4);
    sound(fs2); play(fs4,20,1,4);
    sound(e2);
    scale(e3,cs4,fs4,fs2,e2,g2,a2,as2,b2,cs2,d2);
    quiet;
    sound(e2); chord(e3,b4,g4,55,16);
    crash(1,22); crash(1,37);
    quiet;
  until (cnt = value(parm1)) or keyhit;
  quiet;
end.
