( Music setup routines 9/12/83 )
4 mode
print " Compiling "Music" ... " cr
forget it
forget tune
5000 string tune
: it ;

: chruc dup 95 > if 32 - then ;

: locate.end 0 tune begin
  dup peek 0 <> while
  3 + repeat ;

: set.repeat
  0 tune ( address of beginning )
  locate.end 1 + ( address of end )
  pokew ; ( put address of beginning at end of music )

36 string dir.entry
36 string dir.fcb

: dir.namechar dir.entry peek putc ;

: dir.name 16 1 3 pick 3 mod 1 + color
  9 1 do i dir.namechar loop cr 1 + ;

: directory cr
 1 dir.fcb assign " ????????MUS "
 0 dir.entry -> dx
 hex 1A00 -> ax 21 int decimal
 0 dir.fcb -> dx
 hex 1100 -> ax 21 int decimal
 0 begin ax 255 and 0 = while
  dir.name
  hex 0 dir.fcb -> dx
  1200 -> ax 21 int decimal
 repeat drop cr ;

: music local segment
  begin
    4 mode print " GraFORTH PC music player " cr
    print " Here are the Available Selections: " cr
    directory
    16 1 3 color
    print " Enter Your Selection " cr
    print " (no entry = quit):  "
    pad readln
    pad peek
 13 <> while
    pad concat " .mus "
    0 tune 5000 memory
    pad -> read
    0 -> play
    cr print " Shall Music Play Repeatedly (Y/N) :  "
    pad readln pad peek chruc
    89 = if set.repeat then
    0 tune -> play
 repeat ;
close run
