home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / CTRLBEEP.OPL < prev    next >
Text File  |  1992-08-26  |  2KB  |  86 lines

  1. PROC ctrlbeep:
  2.     global pid%
  3.     global mstat%,maddr%
  4.     local kstat%,k%(2)
  5.     local bstate%
  6.  
  7.     telldie:
  8.     launchb:
  9.     print "Esc to quit"
  10.     print "Enter to toggle beep on/off"
  11.     while 1
  12.         keya(kstat%,k%(1))
  13.         iowait
  14.         if kstat%<>-46
  15.             if k%(1)=27
  16.                 exit:
  17.             elseif k%(1)=13
  18.                 if bstate%
  19.                     quiet:
  20.                 else
  21.                     noisy:
  22.                 endif
  23.                 bstate%=1-bstate%
  24.             elseif k%(1)>=%a and k%(1)<=%z
  25.                 at 1,5
  26.                 print "Received key",chr$(k%(1))
  27.             endif
  28.         else
  29.             exit:
  30.         endif
  31.     endwh
  32. ENDP
  33.  
  34. PROC telldie:
  35. REM ensure we are told we are going to die
  36.     call($0083,$1,0,0,0,0) :rem MessInit
  37.     call($0e88,1,0,0,0,0) :rem ProcOnTerminate
  38.     call($0183,addr(maddr%),0,0,0,addr(mstat%)) :rem MessReceiveAsynchronous
  39.     escape off
  40. ENDP
  41.  
  42. PROC launchb:
  43. REM launches beeper subprocess
  44.     local beepnm$(128),cmdl$(128)
  45.     local off%(6)
  46.     local ret%
  47.     beepnm$=parse$("beeper.opo",cmd$(1),off%())
  48.     if not exist(beepnm$)
  49.         print "File does not exist"
  50.         print beepnm$
  51.         get
  52.         stop
  53.     endif
  54.     cmdl$="ORunOpl"+chr$(0)+chr$(0)+beepnm$+chr$(0)
  55.     beepnm$="rom::sys$prgo"+chr$(0)
  56.     ret%=call($0187,addr(beepnm$)+1,addr(cmdl$),0,0,addr(pid%))
  57.     if ret%<0
  58.         print "Couldn't start beeper subprocess"
  59.         print err$(ret%)
  60.         get
  61.         stop
  62.     endif
  63.     call($0688,pid%,0,0,0,0) :rem ProcResume
  64.     call($998d,0,0,0,0) :rem come to foreground again
  65. ENDP
  66.  
  67. PROC noisy:
  68. REM Start beeps
  69.     local one%
  70.     one%=1
  71.     call($92,pid%,2,0,addr(one%),$28) :rem ProcCopyToById
  72.     call($0986,pid%,0,0,0,0) :rem IoSignalByPid
  73. ENDP
  74.  
  75. PROC quiet:
  76. REM Stop beeps
  77.     local zero%
  78.     call($92,pid%,2,0,addr(zero%),$28) :rem ProcCopyToById
  79. ENDP
  80.  
  81. PROC exit:
  82. REM Clean shutdown
  83.     call($0d88,pid%,0,0,0,0)
  84.     stop
  85. ENDP
  86.