*************************************
*             PlayMidi              *
* for Playing Midi-Files via GMPlay *
*                                   *
*       written by Dirk Busse       *
*            7. May. 1999           *
*************************************


   INCDIR   include:

   include  exec/execbase.i
   include  exec/memory.i
   include  dos/dos.i
   include  LVO.i


      movea.l  4.w,a6


      clr.l    d0
      lea      DosName(pc),a1
      jsr      _LVOOpenLibrary(a6)
      movea.l  d0,a5                 ; DosBase to a6
      bne      DosOK

Fail  moveq    #RETURN_FAIL,d0
      rts
DosOK

      exg.l    a5,a6                 ; DosBase to a6
      jsr      _LVOOutput(a6)
      move.l   d0,d5                 ; Output Handle to d5 (needed later)
      move.l   d0,d1                 ; Output Handle to d1
      move.l   #text,d2
      move.l   #textend-text,d3
      jsr      _LVOWrite(a6)

      move.l   #buff,d1
      move.l   #4*64,d2
      clr.l    d3
      jsr      _LVOReadItem(a6)       ; read filename

      lea      buff(pc),a4            ; buffer start address to a4
.loop move.b   (a4)+,d1
      bne.b    .loop                  ; search the end of the file name
      move.b   #'"',-(a4)

      move.l   #Execute,d1
      clr.l    d2
;      clr.l    d3
      move.l   d5,d3                 ; Output Handle to d3
      jsr      _LVOExecute(a6)

      move.l   #300,d1               ; so IBrowse doesn't delete the file
                                     ; before loading

      jsr      _LVODelay(a6)

      movea.l  a6,a1                 ; DosBase to a1
      movea.l  a5,a6                 ; ExecBase to a6
      jmp      _LVOCloseLibrary(a6)  ; faster then jsr & rts

DosName
      dc.b     "dos.library",0
   EVEN
text
      dc.b     "Playing now Midi file via GMPlay !",$0a
textend
   EVEN
Execute
      dc.b     "failat 21",$0a
      dc.b     "break >NIL: `status command $GMDIR/GMPlay`",$0a
      dc.b     "wait 1",$0a
      dc.b     'run $GMDIR/GMPlay $PlayMidiGMopts  "' ; there are two spaces,
buff  blk.l    64,$0                          ; because blk.l in long aligned
buffend
      dc.b     0,0

      dc.b     "$VER: PlayMidi 1.0 (07.05.99)",0

