startmacro/nmq=128 u:func[BOGUS] a:filename[testfile] l:nn[10]

res RFFREQ 1000
res RFGAIN 20

res ramqual "(AUX=RAMAUX)(DET=1)"
res picflags "MUXCLK=P,VHS"

if filename fexists then
  status filename xd=fxd
  if (1/fxd) ge 200e6
    res picflags "^picflags,QDRX"
  endif
endif

if func eqs "GEN" then
  waveform filename CI 50M SIN 30e3 1e6 0 0 1/50e6

elseif func eqs "PLAY" then

  picd/flags=(^picflags) reset pic2auto
  erase ramfile1
  noop filename ramfile1^ramqual
  sinkpic/replay=-nn/stats/flags=(^picflags,MUXCLK=P,RFGAIN=^RFGAIN,RFFREQ=^RFFREQ)/port=module1 ramfile1 ramfile1 pic2auto
  erase ramfile1

elseif func eqs "PLAY2" then

  picd/flags=(^picflags) reset pic2auto
  erase ramfile1 ramfile2
  noop filename ramfile1^ramqual
  noop filename ramfile2^ramqual
  sinkpic/bg/replay=-nn/stats/flags=(^picflags,SGO,RFGAIN=^RFGAIN,RFFREQ=^RFFREQ-250)/port=module2 ramfile2 ramfile2 pic2auto
  sinkpic/replay=-nn/stats/flags=(^picflags,RFGAIN=^RFGAIN,RFFREQ=^RFFREQ+250)/port=module1 ramfile1 ramfile1 pic2auto
  erase ramfile1 ramfile2

elseif func eqs "PIPE" then

  picd/flags=(^picflags) reset pic2auto
  erase ramfile1
  xpipe/controls on
  xpipe off
  erase ramfile1

else
  say "Unknown func=^func"
endif

endmacro

startcontrols

label initialentry
xcontrol/lab=lgo menu igo  0 "Go;Start,Stop,GainUp,GainDn,FreqUp,FreqDn,Exit"
return

label lgo
if igo eq 1 then
  noop filename ramfile1^ramqual	! runs to completion before sinkpic
  sinkpic/bg/id=9/replay=2/stats/flags=(^picflags,MUXCLK=P,RFGAIN=^RFGAIN,RFFREQ=^RFFREQ)/port=module1 ramfile1 ramfile1 pic2auto
elseif igo eq 2 then
  message send "REPLAY" 9 8

elseif igo eq 3 then
  res l:RFGAIN RFGAIN+3
  say "RFGAIN=^RFGAIN"
  message send "RFGAIN" 9 ,, 1 L ^RFGAIN
elseif igo eq 4 then
  res l:RFGAIN RFGAIN-3
  say "RFGAIN=^RFGAIN"
  message send "RFGAIN" 9 ,, 1 L ^RFGAIN

elseif igo eq 5 then
  res l:RFFREQ RFFREQ+10
  message send "RFFREQ" 9 ,, 1 D ^RFFREQ
elseif igo eq 6 then
  res l:RFFREQ RFFREQ-10
  message send "RFFREQ" 9 ,, 1 D ^RFFREQ

elseif igo eq 7 then
  stop
endif
return

endcontrols
