;
; Program Example: Usage of "system-player.o"
; SKELETON for system-compatible version
; Written in 1989 by DIRE CRACKS Inc.

; Linking Info:
; You must also link "sysplayer.o" (containing all the below labels)
; to your executable ! (And not forgetting your Sound-Files !)

; xrefs
; These labels are contained in the MusicMaker-created object files
  xref _PINSDAT ; when instrs are crunched      }
; xref _INSTDAT ; when instrs are not crunched  } (created using "O")
  xref _MELODAT ;                               }

; ROUTINES
  xref _soundon,_soundoff,_generalsndinit,_generalsndremove,_generalsndreset
  xref _fadesnd,_waitfade,_loadandinit,_removeloaded,_waitoneshotfin
  xref _decrunchinstrs,_setvolume


; CODE START

; EXAMPLE for calling decruncher (not required when instrs are not packed)
  lea.l _PINSDAT,a0
  lea.l $50000,a1      ; this is nuts again ! (thou shalt AllocMem !)
  jsr _decrunchinstrs

; EXAMPLE for calling sound initialization
  moveq.l #-1,d0       ; play 0=cont, <>0=oneshot
  lea.l $50000,a1      ; when instrs are not crunched: lea.l _INSTDAT,a1
  lea.l _MELODAT,a2
  suba.l a3,a3         ; no routine here !!! (elsewhere set a3 to your
  jsr _generalsndinit                     ; codestart-see Non-system !)

; SWITCHING sound ON
  jsr _soundon

waitmouse:

; IN CASE OF ONESHOT: WAIT FOR CHANNELS TO FINISH
    jsr _waitoneshotfin
    tst.l d0
    bne.s soundfinished

    btst.b #6,$bfe001
  bne.s waitmouse

;  IN CASE YOU WANT TO SET A NEW GENERAL VOLUME LEVEL FOR THE MUSIC
; moveq.l #63,d0
; jsr _setvolume
;  THIS SET THE GENERAL VOLUME LEVEL TO THE HALF OF THE ORIGINAL
;  TO RESET IT TO MAXIMUM, SET IT TO 127.
;  THE GIVEN VALUE'S RANGE GOES FROM 0 TO 127.
;  !!! YOU SHOULD CALL THIS ROUTINE ONLY (!) WHEN THE PLAYER IS RUNNING !!!

; FADE SOUND OUT
  moveq.l #120,d0
  jsr _fadesnd        ; fadespeed 1(=very fast) - 127 (slow)

; WAIT FOR FADE TO FINISH
waitforfade:
   jsr _waitfade
   tst.l d0
  beq.s waitforfade

soundfinished:
; SWITCHING SOUND OFF IMMEDIATLY
  jsr _soundoff

; SWITCHING LOW PASS FILTER TO ORIG STATE
  bclr.b #1,$bfe001

; IF YOU WANT TO START SAME SOUND AGAIN DO THE FOLLOWING
; moveq.l #0,d0        for loop (or moveq.l #1,d0 for oneshot)
; jsr _generalsndreset
; jsr _soundon

; IF YOU WANT TO PLAY ANOTHER SOUND, YOU MUST FIRST CALL
; jsr _generalsndremove
; AND THEN DO LIKE FAR ABOVE (STARTING WITH jsr _generalsndinit)


; REMOVING THE MusicMakerV8 PRIVATE INT SERVER
  jsr _generalsndremove
  moveq.l #0,d0
  rts

 END

