home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pds.zip / BOUNCE2.CMD < prev    next >
OS/2 REXX Batch file  |  1994-03-09  |  6KB  |  332 lines

  1. /*REXX*/
  2.  
  3.   signal on HALT    name HaltExit
  4.   /***
  5.   signal on ERROR   name ErrorExit
  6.   signal on FAILURE name FailureExit
  7.   signal on SYNTAX  name SyntaxExit
  8.   ***/
  9.  
  10. main:
  11. parse arg p1
  12.   fInit    ='N'
  13.   fDebug   = 'N'
  14.   fDispStax= 'N'
  15.   fDispHelp= 'N'
  16.  
  17.   CALL rParseParms p1
  18.  
  19.   if fDebug = 'Y' then
  20.    do
  21.     trace ?r
  22.    end
  23.  
  24.   if fDispStax = 'Y' then
  25.    do
  26.     CALL rDispSyntax 0, 0
  27.    end
  28.  
  29.   if fDispHelp = 'Y' then
  30.    do
  31.     CALL rDispSyntax 1, 0
  32.    end
  33.  
  34.   /* Actual routine */
  35.   rc   = rLoadFuncs('rxPDLoadFuncs', 'HSSPD', 'rxPDLoadFuncs')
  36.   if rc <> 0 then
  37.    do
  38.     Call rSiren 1, 1
  39.     say 'BOUNCE2 - Unable to initialize the "RXPD" subsystem'
  40.     exit 8
  41.    end
  42.  
  43.   sGlobal.iMaxR = 25
  44.   sGlobal.iMaxC = 80
  45.   sGlobal.fDebug=fDebug
  46.  
  47.   bid = rxPDInit('BOUNCE2','GREENHI','RED','REDHI',,25,80)
  48.   if bid = x2c(00000000) then
  49.    do
  50.     Call rSiren 2, 3
  51.     say 'BOUNCE2 - Error to initializing the "RXPD" subsystem'
  52.     exit 8
  53.    end
  54.  
  55.   fInit    ='Y'
  56.  
  57.   Call rxPDZVarDefine
  58.   do i = 1 to sGlobal.iMaxR
  59.    sRow.i  = ''
  60.   end /* do i = 1 to sGlobal.iMaxR */
  61.  
  62.   akey = rxPDDisplay(bid,'PANEL000')
  63.   do while 0 = rDoBOUNCE(bid)
  64.   end /* do while 0 = rDoBOUNCE() */
  65.  
  66.   rc = rxPDTerm(bid)
  67.  
  68.   exit 0
  69.  
  70. /**********************************************************************\
  71.  rDoBOUNCE:
  72.   This routine displays a dialog panel that bounces a ball
  73. \**********************************************************************/
  74. rDoBOUNCE:
  75. parse arg bid
  76.  
  77.   r = 1
  78.   c = 1
  79.   rd = +1
  80.   cd = +1
  81.  
  82.   r2 = TRUNC(sGlobal.iMaxR/3)
  83.   c2 = TRUNC(sGlobal.iMaxC/3)
  84.   r2d = -1
  85.   c2d = +1
  86.  
  87.   do FOREVER
  88.  
  89.    if r = r2 then                      /* Same row needs extra work */
  90.     do
  91.      if c < c2 then
  92.       do
  93.        cw1 = c
  94.        cw2 = c2
  95.       end
  96.      else
  97.       do
  98.        cw2 = c
  99.        cw1 = c2
  100.       end
  101.      if cw1 > 1 then
  102.       do
  103.        sWrk = LEFT(' ',cw1-1,' ')'DB'x
  104.       end
  105.      else
  106.       do
  107.        sWrk = 'DB'x
  108.       end
  109.      if cw2 <> cw1 then
  110.       do
  111.        sWrk = sWrk||LEFT(' ',cw2-cw1,' ')'DB'x
  112.       end
  113.      sRow.r  = sWrk
  114.      akey = rxPDDisplay(bid, 'PANEL'RIGHT(r,3,'0'))
  115.      sRow.r  = ''
  116.     end
  117.    else
  118.     do
  119.      if c > 1 then
  120.       do
  121.        sWrk = LEFT(' ',c-1,' ')'DB'x
  122.       end
  123.      else
  124.       do
  125.        sWrk = 'DB'x
  126.       end
  127.      if c2 > 1 then
  128.       do
  129.        sWrk2 = LEFT(' ',c2-1,' ')'DB'x
  130.       end
  131.      else
  132.       do
  133.        sWrk2 = 'DB'x
  134.       end
  135.      sRow.r  = sWrk
  136.      sRow.r2 = sWrk2
  137.      akey = rxPDDisplay(bid, 'PANEL'RIGHT(r,3,'0'))
  138.      akey = rxPDDisplay(bid, 'PANEL'RIGHT(r2,3,'0'))
  139.      sRow.r  = ''
  140.      sRow.r2 = ''
  141.     end
  142.  
  143.    akey = rxPDDisplay(bid, 'PANEL999')
  144.  
  145.    r = r + rd
  146.    if r < 1 then
  147.     do
  148.      Call BEEP 1024, 25
  149.      r = 2
  150.      rd = +1
  151.     end
  152.    else
  153.    if r > sGlobal.iMaxR then
  154.     do
  155.      Call BEEP 1024, 25
  156.      r = sGlobal.iMaxR - 1
  157.      rd = -1
  158.     end
  159.  
  160.    c = c + cd
  161.    if c < 1 then
  162.     do
  163.      Call BEEP 1024, 25
  164.      c = 2
  165.      cd = +1
  166.     end
  167.    else
  168.    if c > sGlobal.iMaxC then
  169.     do
  170.      Call BEEP 1024, 25
  171.      c = sGlobal.iMaxC - 1
  172.      cd = -1
  173.     end
  174.  
  175.    r2 = r2 + r2d
  176.    if r2 < 1 then
  177.     do
  178.      Call BEEP 1024, 25
  179.      r2 = 2
  180.      r2d = +1
  181.     end
  182.    else
  183.    if r2 > sGlobal.iMaxR then
  184.     do
  185.      Call BEEP 1024, 25
  186.      r2 = sGlobal.iMaxR - 1
  187.      r2d = -1
  188.     end
  189.  
  190.    c2 = c2 + c2d
  191.    if c2 < 1 then
  192.     do
  193.      Call BEEP 1024, 25
  194.      c2 = 2
  195.      c2d = +1
  196.     end
  197.    else
  198.    if c2 > sGlobal.iMaxC then
  199.     do
  200.      Call BEEP 1024, 25
  201.      c2 = sGlobal.iMaxC - 1
  202.      c2d = -1
  203.     end
  204.  
  205.   end /*do FOREVER */
  206.  
  207.   return 0;
  208.  
  209. HaltExit:
  210.   if fInit = 'Y' then
  211.    do
  212.     rc = rxPDTerm(bid)
  213.    end
  214.   Call BEEP 882, 40
  215.   Call BEEP 882, 40
  216.   say ''
  217.   say 'BOUNCE2 processing halted by request;'
  218.   exit 0
  219.  
  220. ErrorExit:
  221.   Call BEEP 882, 40
  222.   Call BEEP 882, 40
  223.   say 'BOUNCE2 processing failed due to unknown error;'
  224.   exit 24
  225.  
  226. FailureExit:
  227.   Call BEEP 882, 40
  228.   Call BEEP 882, 40
  229.   say 'BOUNCE2 processing failed due to unknown failure;'
  230.   exit 32
  231.  
  232. SyntaxExit:
  233.   Call BEEP 882, 40
  234.   Call BEEP 882, 40
  235.   say 'BOUNCE2 processing failed due to syntax error;'
  236.   exit 64
  237.  
  238. rParseParms:
  239. parse arg p1
  240.  
  241.   do Forever
  242.    w1 = word(p1,1)
  243.    parse var w1 with "/" f1 ":" v1
  244.    select
  245.     when (w1 = '') then
  246.      do
  247.       return 0
  248.      end
  249.     when TRANSLATE(w1) = '/DEBUG' then
  250.      do
  251.       fDebug='Y'
  252.       p1 = SUBWORD(p1,2)
  253.      end
  254.     when TRANSLATE(f1) = 'D' then
  255.      do
  256.       fDebug = TRANSLATE(v1)
  257.       p1 = SUBWORD(p1,2)
  258.      end
  259.     when TRANSLATE(f1) = '?' then
  260.      do
  261.       fDispStax='Y'
  262.       fDispHelp='N'
  263.       p1 = SUBWORD(p1,2)
  264.      end
  265.     when TRANSLATE(f1) = 'H' then
  266.      do
  267.       fDispStax='N'
  268.       fDispHelp='Y'
  269.       p1 = SUBWORD(p1,2)
  270.      end
  271.     otherwise
  272.      do
  273.       Call rSiren 8, 1
  274.       say 'BOUNCE2 - Invalid parm specified; Parm "'w1'" unknown;'
  275.       CALL rDispSyntax 0 8
  276.      end
  277.    end
  278.   end
  279.  
  280.   return 0
  281.  
  282. rDispSyntax: Procedure
  283. parse upper arg iHelp iExit
  284.  
  285.   say ' Syntax  : BOUNCE2 {<options>} '
  286.   say '           BOUNCE2 {/?|/h}'
  287.   if iHelp > 0 then
  288.    do
  289.     CALL rDispHelp
  290.    end
  291.  
  292.   exit iExit
  293.  
  294. rDispHelp: Procedure
  295.  
  296.   say ' Options : /?         - Display command syntax.'
  297.   say '           /h         - Display this help info.'
  298.   say ' Examples:'
  299.   say '    BOUNCE2 /h'
  300.   say ' '
  301.   say '    BOUNCE2'
  302.  
  303.   return ''
  304.  
  305. /* rSiren: does the siren bit by running the scale based upon a       */
  306. /*    frequency specified by the caller.                              */
  307. rSiren: Procedure
  308.    Parse Arg freq, cycle
  309.    note.1 = 262 * freq /* middle C */
  310.    note.2 = 294 * freq /* D */
  311.    note.3 = 330 * freq /* E */
  312.    note.4 = 349 * freq /* F */
  313.    note.5 = 392 * freq /* G */
  314.    note.6 = 440 * freq /* A */
  315.    note.7 = 494 * freq /* B */
  316.    note.8 = 524 * freq /* C */
  317.    do j = 1 to cycle
  318.     call beep note.8,250 /* hold each note for a 1/4 second */
  319.     call beep note.1,250 /* hold each note for a 1/4 second */
  320.    end j
  321.    Return
  322.  
  323. rLoadFuncs:
  324. parse arg sREP, sDll, sRtn
  325.   rxrc = RxFuncAdd(sREP, sDll, sRtn)
  326.   signal on syntax name xLoadFuncs
  327.   interpret 'Call 'sRtn
  328.   return 0
  329.  
  330. xLoadFuncs:
  331.   return 127
  332.