home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l360 / 3.ddi / SORTDEMO.@EM / SORTDEMO.CBL next >
Encoding:
Text File  |  1991-04-08  |  82.0 KB  |  2,014 lines

  1.       $set ans85 vsc2 nobound noqual noalter norw mf noms
  2.       ************************************************************
  3.       *                                                          *
  4.       *                     SORTDEMO.CBL                         *
  5.       *                                                          *
  6.       *    This program demonstrates using API function calls    *
  7.       *    in a COBOL program. A number of sort routines are     *
  8.       *    also demonstrated:                                    *
  9.       *        COBOL table, COBOL file, exchange, shell,         *
  10.       *        insertion, heap, quick and bubble sorts.          *
  11.       *                                                          *
  12.       ************************************************************
  13.       * Version: 1.5.5 (phase 4)
  14.       *
  15.       * Called Routines: DosBeep           - sounds the speaker
  16.       *                  DosSleep          - delays program execution
  17.       *                  VioGetConfig      - gets the hardware video
  18.       *                                      configuration
  19.       *                  VioGetMode        - gets the video mode
  20.       *                  VioSetMode        - dets the video mode
  21.       *                  VioWrtCharStrAtt  - writes a character string and
  22.       *                                      attributes to the screen
  23.       *                  VioWrtNCell       - writes one character and its
  24.       *                                      attribute to the screen
  25.       *                  KbdFlushBuffer    - flushes the keyboard buffer
  26.       *                  KbdCharIn         - reads one character from the
  27.       *                                      keyboard buffer
  28.       *
  29.       *****************************************************************
  30.       *
  31.       *
  32.       * System Requirements:  IBM PC or compatible
  33.       *                           running DOS 3.x
  34.       *                       IBM PS/2 Model 30
  35.       *                       IBM PC/AT or compatible
  36.       *                       IBM PS/2 Model 50,60,70,80
  37.       *                           running DOS 3.x or OS/2
  38.       *
  39.       *****************************************************************
  40.       *
  41.       * Compile and link notes: This program must be BOUND to run under
  42.       *                         DOS.
  43.       *
  44.       *  Assuming the files for the COBOL compiler and Animator are
  45.       *  correctly installed:
  46.       *
  47.       *    To compile, the following files must be present:
  48.       *    ------------------------------------------------
  49.       *        SORTDEMO.CBL
  50.       *
  51.       *    To link, the following files must be present:
  52.       *    ---------------------------------------------
  53.       *        LCOBOL.LIB   )(Must be in current directory, or available
  54.       *        OS2.LIB      )(on the path defined by the LIB environment
  55.       *                      (variable.
  56.       *        LINK.EXE (OS/2 Linker)
  57.       *
  58.       *
  59.       *    To bind (for use on DOS), the following files must be present:
  60.       *    --------------------------------------------------------------
  61.       *        API.LIB       (must be in current directory)
  62.       *        BIND.EXE
  63.       *        CBLBIND.LIB  )(can be in any directory which must be
  64.       *        CBLBIND.NOT  )(specified on the BIND command line
  65.       *        OS2.LIB      )
  66.       *
  67.       *
  68.       *    For DOS
  69.       *    -------
  70.       *      compile the program as shown below:
  71.       *           COBOL SORTDEMO.CBL OPTSPEED NOTRICKLE ;
  72.       *
  73.       *      then link (using OS/2 linker):
  74.       *           LINK SORTDEMO/NOD,,,COBLIB+OS2;
  75.       *      or
  76.       *           LINK SORTDEMO/NOD,,,LCOBOL+OS2;
  77.       *
  78.       *      and bind (assuming all files in current directory):
  79.       *           BIND SORTDEMO CBLBIND.LIB OS2.LIB -N @CBLBIND.NOT
  80.       *
  81.       *
  82.       *    For OS/2,
  83.       *    ---------
  84.       *      compile the program as shown below:
  85.       *           COBOL SORTDEMO.CBL OPTSPEED NOTRICKLE ;
  86.       *
  87.       *      then link:
  88.       *           LINK SORTDEMO/NOD,,,COBLIB+OS2 ;
  89.       *      or
  90.       *           LINK SORTDEMO/NOD,,,LCOBOL+OS2 ;
  91.       *
  92.       *    To run on DOS or OS/2,
  93.       *        SORTDEMO
  94.       *
  95.       *****************************************************************
  96.       *
  97.       * Animation notes:
  98.       * ----------------
  99.       *    When animating VIO API function calls, it is necessary to
  100.       *    use the FLASH-CALLS directive to ensure that the user screen
  101.       *    is written to by the VIO calls rather than the Animator
  102.       *    screen. Try Animating with and without this directive to see
  103.       *    the effect.
  104.       *
  105.       *-----------------------------------------------------------------
  106.       *
  107.       * To Animate the program (OS/2 only),
  108.       * ----------------------------------
  109.       *
  110.       *      compile the program as shown below:
  111.       *           COBOL SORTDEMO.CBL ANIM ;
  112.       *
  113.       *      Then, to animate:
  114.       *           ANIMATE SORTDEMO FLASH-CALLS
  115.       *
  116.       *
  117.       /
  118.       *****************************************************************
  119.        environment division.
  120.        configuration section.
  121.        special-names.
  122.            call-convention 3 is api.
  123.  
  124.        input-output section.
  125.        file-control.
  126.            select sort-file assign to "sorttemp"
  127.                sort status is sort-status.
  128.        data division.
  129.        file section.
  130.        sd  sort-file.
  131.        01  sort-rec.
  132.            05  sort-key                pic 99.
  133.            05  sort-color              pic x.
  134.            05  sort-bar                pic x(50).
  135.  
  136.       *****************************************************************
  137.        working-storage section.
  138.       *****************************************************************
  139.       *
  140.       * Constants section
  141.       *
  142.  
  143.        78  escape-key-pressed          value x"1b".
  144.        78  up-arrow-scan-code          value 72.
  145.        78  down-arrow-scan-code        value 80.
  146.  
  147.        78  cobol-table-line-number     value 4.
  148.        78  cobol-line-number           value 5.
  149.        78  exchange-line-number        value 6.
  150.        78  quick-line-number           value 7.
  151.        78  shell-line-number           value 8.
  152.        78  heap-line-number            value 9.
  153.        78  insert-line-number          value 10.
  154.        78  bubble-line-number          value 11.
  155.        78  randomize-line-number       value 13.
  156.        78  sound-sw-line-number        value 15.
  157.        78  speed-up-line-number        value 16.
  158.        78  slow-down-line-number       value 17.
  159.        78  speed-counter-line-number   value 19.
  160.        78  prompt-line-number          value 22.
  161.        78  message-line-number         value 25.
  162.  
  163.        78  cobol-table-literal         value "Cobol table".
  164.        78  cobol-literal               value "cobol File".
  165.        78  exchange-literal            value "Exchange".
  166.        78  quick-literal               value "Quick".
  167.        78  shell-literal               value "Shell".
  168.        78  heap-literal                value "Heap".
  169.        78  insert-literal              value "Insert".
  170.        78  bubble-literal              value "Bubble".
  171.        78  randomize-literal           value "Randomize".
  172.       *
  173.       * End of constants section
  174.       *
  175.  
  176.        01  seed                        pic 9(12)   comp-5.
  177.        01  mod                         pic 9(12)   comp-5.
  178.        01  rand                        pic 9v9(11) comp-5.
  179.        01  integer                     pic 999     comp-5.
  180.        01  sort-status                 pic xx.
  181.  
  182.        01  stack-sub                   pic 9(4)    comp-5.
  183.        01  upper-stack occurs 6 times  pic 9(4)    comp-5.
  184.        01  lower-stack occurs 6 times  pic 9(4)    comp-5.
  185.        01  pivot-element               pic 99      comp-5.
  186.  
  187.        01  array.
  188.            05  a-data                  occurs      50 times.
  189.                10  a-length            pic 99      comp-5.
  190.                10  a-color             pic x.
  191.                10  a-string            pic x(50).
  192.        01  backup-array.
  193.            05  ba-data                 occurs      50 times.
  194.                10  ba-length           pic 99      comp-5.
  195.                10  ba-color            pic x.
  196.                10  ba-string           pic x(50).
  197.        01  array-max                   pic 99      comp-5.
  198.        01  sub                         pic 99      comp-5.
  199.        01  sub-1                       pic 99      comp-5.
  200.        01  sub-2                       pic 99      comp-5.
  201.        01  sub-x                       redefines sub-2 pic x.
  202.        01  max-loop                    pic 99      comp-5.
  203.        01  last-element-saved          pic 99      comp-5.
  204.        01  last-choice                 pic x       value space.
  205.  
  206.        01  swap-line                   pic 99      comp-5.
  207.        01  swap-line-1                 pic 99      comp-5.
  208.        01  temp-sub                    pic 99      comp-5.
  209.        01  max-limit                   pic 99      comp-5.
  210.        01  parent                      pic 99      comp-5.
  211.        01  child                       pic 99      comp-5.
  212.        01  smallest-line               pic 9(4)    comp-5.
  213.        01  offset                      pic 99      comp-5.
  214.  
  215.        01  bar                         pic x(50)   value all x"dc".
  216.  
  217.        01  hold-array-element.
  218.            05  h-length                pic 99      comp-5.
  219.            05  h-color                 pic x.
  220.            05  h-string                pic x(50).
  221.  
  222.        01  start-time.
  223.            05  start-hr                pic 99.
  224.            05  start-min               pic 99.
  225.            05  start-sec               pic 99.
  226.            05  start-hsec              pic 99.
  227.            05  start-decimal           redefines   start-hsec pic v99.
  228.        01  end-time.
  229.            05  end-hr                  pic 99.
  230.            05  end-min                 pic 99.
  231.            05  end-sec                 pic 99.
  232.            05  end-hsec                pic 99.
  233.            05  end-decimal             redefines   end-hsec   pic v99.
  234.  
  235.        01  start-time-secs             pic 9(4)v99.
  236.        01  end-time-secs               pic 9(4)v99.
  237.        01  elapsed                     pic 9999v99.
  238.  
  239.        01  pause                       pic 9(4)    comp-5.
  240.        01  pause-dword                 pic 9(8)    comp-5.
  241.        01  frequency                   pic 9(4)    comp-5  value zeros.
  242.        01  freq                        pic 9(4)    comp-5.
  243.  
  244.        01  time-screen-line            pic 99.
  245.  
  246.        01  updated-screen-sw           pic xxx     value "OFF".
  247.        01  halt-sw                     pic xxx.
  248.        01  auto-sound-toggle-sw        pic xxx     value "ON".
  249.  
  250.        01  hilite-screen-data-item.
  251.            05  filler                  pic xx      value spaces.
  252.            05  hilite-item             pic x(12).
  253.            05  filler                  pic x       value space.
  254.            05  disp-elapsed            pic x(7).
  255.            05  filler                  pic x(6)    value spaces.
  256.  
  257.        01  edited-elapsed              pic zzzz.zz.
  258.        01  edited-elapsed-red redefines edited-elapsed pic x(7).
  259.  
  260.        01  menu-screen-buffer-data.
  261.         02 filler.
  262.             05 filler  pic x(30) value "╔════════════════════════════╗".
  263.             05 filler  pic x(30) value "║    COBOL SORTING DEMO      ║".
  264.             05 filler  pic x(30) value "║                            ║".
  265.             05 filler  pic x(30) value "║  Cobol table               ║".
  266.             05 filler  pic x(30) value "║  cobol File                ║".
  267.             05 filler  pic x(30) value "║  Exchange                  ║".
  268.             05 filler  pic x(30) value "║  Quick                     ║".
  269.             05 filler  pic x(30) value "║  Shell                     ║".
  270.             05 filler  pic x(30) value "║  Heap                      ║".
  271.             05 filler  pic x(30) value "║  Insertion                 ║".
  272.             05 filler  pic x(30) value "║  Bubble                    ║".
  273.             05 filler  pic x(30) value "║                            ║".
  274.             05 filler  pic x(30) value "║  Randomize                 ║".
  275.             05 filler  pic x(30) value "║                            ║".
  276.             05 filler  pic x(3)  value "║  ".
  277.             05 ms-toggle-sound-var
  278.                        pic x(6)  value    "Toggle".
  279.             05 filler  pic x(8)  value          " sound: ".
  280.             05 sound-sw pic xxx value "OFF".
  281.             05 filler  pic x(10) value                     "         ║".
  282.       *     05 filler  pic x(30) value "║                            ║".
  283.         02 menu-screen-speed-up-line.
  284.             05 filler  pic x(3)  value "║  ".
  285.             05 ms-speed-up-var pic x(24).
  286.             05 filler  pic x(3)  value                            "  ║".
  287.         02 menu-screen-slow-down-line.
  288.             05 filler  pic x(3)  value "║  ".
  289.             05 ms-slow-down-var pic x(25).
  290.             05 filler  pic xx    value                             " ║".
  291.         02 filler.
  292.             05 filler  pic x(30) value "║                            ║".
  293.             05 filler  pic x(23) value "║  Speed (X/100 sec.): ".
  294.             05 disp-pause pic zzz9.
  295.             05 filler  pic x(3)  value                            "  ║".
  296.             05 filler  pic x(30) value "║                            ║".
  297.             05 filler  pic x(30) value "║ Type first character of    ║".
  298.         02 menu-screen-choice-line.
  299.             05 filler  pic x(19) value "║ choice (CFEQSHIBR".
  300.             05 ms-speed-up-char     pic x.
  301.             05 ms-slow-down-char    pic x.
  302.             05 ms-toggle-sound-char pic x.
  303.             05 filler  pic x(8)  value                       "):     ║".
  304.         02 filler.
  305.             05 filler  pic x(30) value "║ or ESC key to end program: ║".
  306.             05 filler  pic x(30) value "╚════════════════════════════╝".
  307.  
  308.        01  menu-screen-buffer redefines menu-screen-buffer-data
  309.                                        occurs 24 times.
  310.            05 menu-screen-line         pic x(30).
  311.        01  menu-screen-sub-max         pic 99       comp-5 value 24.
  312.        01  menu-screen-sub             pic 99       comp-5.
  313.        01  menu-screen-hilite-attr     pic x        value x"0f".
  314.        01  menu-screen-normal-attr     pic x        value x"07".
  315.        01  menu-screen-revvid-attr     pic x        value x"70".
  316.        01  menu-screen-speed-up-msg    pic x(24)    value
  317.                "< Will speed up the sort".
  318.        01  menu-screen-slow-down-msg   pic x(25)    value
  319.                "> Will slow down the sort".
  320.        01  menu-screen-toggle-sound-msg pic x(6)    value
  321.                "Toggle".
  322.        01  menu-screen-speed-up-lit    pic x        value "<".
  323.        01  menu-screen-toggle-sound-lit pic x        value "T".
  324.        01  menu-screen-slow-down-lit   pic x        value ">".
  325.        01  menu-screen-cobol-lit-tab   pic x(11)    value "Cobol table".
  326.        01  menu-screen-cobol-lit       pic x(10)    value "cobol File".
  327.  
  328.        01  msg-line                    pic x(30).
  329.        01  msg-attr                    pic x       value x"87".
  330.        01  cobol-msg                   pic x(30)    value
  331.                "Cobol sort only when speed = 0".
  332.        01  wait-msg                    pic x(30)    value
  333.                "        Please standby".
  334.  
  335.       /
  336.       *****************************************************************
  337.       *
  338.       * General OS/2 parameters
  339.       *
  340.       *****************************************************************
  341.  
  342.        01  handle-zeros pic 9(4)       comp-5       value 0.
  343.       *
  344.       * screen-line = row, on screen, starting from 0.
  345.       * screen-col  = Column, on screen, starting from 0.
  346.       *
  347.        01  screen-line                 pic 9(4) comp-5.
  348.        01  screen-col                  pic 9(4) comp-5.
  349.       *
  350.       *****************************************************************
  351.       * Parameters for VioWerNCell
  352.       *****************************************************************
  353.       *
  354.       * VioWrtNCell writes one character and one attribute to the
  355.       *    screen 'n' number of times.
  356.       *
  357.       * The field "NUM-CHARS-ON-SCREEN" = the number of times
  358.       *                                   to write the character/
  359.       *                                   attribute to the
  360.       *                                   screen.
  361.       *
  362.        01  viowrtncell-data.
  363.            05  viowrtncell-char        pic x        value space.
  364.            05  viowrtncell-attr        pic x        value x"07".
  365.        01  viowrtncell-count           pic 9(4)     comp-5.
  366.        01  num-chars-on-screen         pic 9(4)     comp-5.
  367.       *
  368.       *****************************************************************
  369.       * Parameters for VioWrtCharStrAtt
  370.       *****************************************************************
  371.       *
  372.       * VioWrtCharStrAtt writes a string and its attributes to the
  373.       *    screen.
  374.       *
  375.       * The data item "VIOWRTCHARSTRATT-LENGTH" = the number of
  376.       *                                           characters and
  377.       *                                           attributes to
  378.       *                                           write.
  379.       *
  380.        01  viowrtcharstratt-data       pic x(50).
  381.        01  viowrtcharstratt-attr       pic x.
  382.        01  viowrtcharstratt-length     pic 9(4) comp-5 value 50.
  383.       *
  384.       *****************************************************************
  385.       * Parameter for VioGetConfig
  386.       *****************************************************************
  387.       *
  388.       * VioGetConfig identifies the type of video card and video
  389.       *    monitor on the target machine.
  390.       *
  391.       * The field "VIOGETCONFIG-LENGTH" specifies the length,
  392.       *    in words, of the group item "VIOGETCONFIG".
  393.       *
  394.       * The field "VIOGETCONFIG-ADAPTER" specifies the type of
  395.       *    video card you have:
  396.       *                        = 0 = monochrome
  397.       *                        = 1 = CGA
  398.       *                        = 2 = EGA
  399.       *                        = 3 = VGA
  400.       *                        = 7 = PS/2 adapter 8514/A
  401.       *
  402.       * The field "VIOGETCONFIG-DISPLAY specifies the type of
  403.       *    computer monitor you have:
  404.       *                        = 0 = monochrome
  405.       *                        = 1 = CGA
  406.       *                        = 2 = EGA
  407.       *                        = 3 = PS/2 monochrome 8503
  408.       *                        = 4 = PS/2 color 8512/8513
  409.       *                        = 9 = PS/2 color 8514
  410.       *
  411.        01  viogetconfig-data.
  412.            05  viogetconfig-length     pic 9(4) comp-5 value 10.
  413.            05  viogetconfig-adapter    pic 9(4) comp-5.
  414.            05  viogetconfig-display    pic 9(4) comp-5.
  415.            05  filler                  pic 9(8) comp-5.
  416.       *
  417.       *****************************************************************
  418.       * Parameters for VioGetMode and VioSetMode
  419.       *****************************************************************
  420.       *
  421.       * This parameter to the routine (VioGetMode and VioSetMode) that
  422.       *    identifies the software video mode.
  423.       * This information is needed to determine
  424.       *    how many columns, rows and colors the video adapter and
  425.       *    monitor can handle.
  426.       *                                                                 .
  427.       * The field "VIOMODE-LENGTH" specifies the length,
  428.       *    in words, of the group item "VIOMODE-DATA".
  429.       *
  430.       * The fields returned are as follows:
  431.       * -----------------------------------
  432.       *
  433.       *       VIOMODE-MODE will = 1 if the target machine is in color mode.
  434.       *                         = 0 if the target machine in monochrome mode.
  435.       *       VIOMODE-COLORS will = 0 if the number of available colors = 2
  436.       *                           = 2 if the number of available colors = 16
  437.       *                  The number of colors available is controlled
  438.       *                    by the type of adapter and monitor.
  439.       *                    A monochrome adapter has only 2 available
  440.       *                    colors; a color graphics system can have
  441.       *                    a maximum of 16 colors.
  442.       *
  443.       *       VIOMODE-COLS = the number of text columns available to the
  444.       *                    program.
  445.       *       VIOMODE-ROWS = the number of text rows available to the
  446.       *                    program.
  447.       *
  448.        01  viomode-data.
  449.            05  viomode-length          pic 9(4) comp-5 value 8.
  450.            05  viomode-mode            pic 99 comp-5.
  451.            05  viomode-colors          pic 99 comp-5.
  452.            05  viomode-cols            pic 9(4) comp-5.
  453.            05  viomode-rows            pic 9(4) comp-5.
  454.       *
  455.       *****************************************************************
  456.       * This area saves the original video mode data. After the
  457.       *   program is finished,the user's video mode will be restored.
  458.       *****************************************************************
  459.       *
  460.        01  viomode-save-data           pic x(16).
  461.       *
  462.       *****************************************************************
  463.       * Parameters for KbdCharIn
  464.       *****************************************************************
  465.       *
  466.       * KbdCharIn gets one character from the keyboard buffer with no
  467.       *   echo.
  468.       *
  469.       * KBDCHARIN-CHAR = the character from the keyboard buffer.
  470.       *
  471.       * KBDCHARIN-SCAN = the scan code of the character.
  472.       *
  473.       * KBDCHARIN-WAIT-FLAG = 0 = instructs the function to wait
  474.       *                            until there is character
  475.       *                            available.
  476.       *                     = 1 = don't wait for a character if
  477.        01  kbdcharin-wait-flag         pic 9(4)    comp-5  value 0.
  478.        01  kbdcharin-data.
  479.            05  kbdcharin-char          pic x.
  480.            05  kbdcharin-scan          pic 99      comp-5.
  481.            05  kbdcharin-status        pic 99      comp-5.
  482.            05  filler                  pic 9(14)   comp-5.
  483.  
  484.  
  485.       /
  486.       *****************************************************************
  487.        procedure division.
  488.       *****************************************************************
  489.        10000-start-section section.
  490.        10000-start.
  491.            perform 20000-initialize
  492.            perform 21000-get-character
  493.            perform 30000-sort-and-input-loop thru 30000-exit
  494.               until kbdcharin-char = escape-key-pressed
  495.            perform 40000-restore-users-video-mode
  496.            perform 20400-clear-the-screen
  497.            stop run.
  498.        10000-exit.
  499.            exit.
  500.  
  501.       /
  502.       *****************************************************************
  503.        20000-initialize.
  504.       *****************************************************************
  505.            move 0 to pause
  506.            move pause to disp-pause
  507.            move spaces to ms-speed-up-var
  508.            move spaces to ms-toggle-sound-var
  509.            move menu-screen-slow-down-msg to ms-slow-down-var
  510.            move space to ms-speed-up-char
  511.            move space to ms-toggle-sound-char
  512.            move menu-screen-slow-down-lit to ms-slow-down-char
  513.            perform 20100-get-video-config-info
  514.            perform 20200-get-video-mode
  515.            perform 20300-set-video-mode
  516.            perform 20400-clear-the-screen
  517.            perform 20500-flush-kbd-buffer
  518.            perform 20600-init-unsorted-array
  519.            perform 20700-display-unsorted-bars
  520.            perform 20800-display-menu-screen.
  521.        20000-exit.
  522.            exit.
  523.       *****************************************************************
  524.        20100-get-video-config-info.
  525.       *****************************************************************
  526.       *
  527.       * Get the video configuration of the machine. This determines
  528.       *   whether or not to use color display attributes and how many
  529.       *   bars can be displayed.
  530.       *
  531.       * All OS/2 API functions are called like far PASCAL routines:
  532.       * i.e. you must supply the parameters in reverse order or use
  533.       * call-convention 3. We use call-convention 3, having called it
  534.       * api. Also, the API names must be LITLINKED so that they will be
  535.       * satisfied at link time by referencing OS2.LIB. In order to
  536.       * force this for each name, the name must be prefixed by
  537.       * double-underscore ("__").
  538.       *
  539.            call api "__VioGetConfig" using
  540.                by value     handle-zeros
  541.                by reference viogetconfig-data
  542.                by value     handle-zeros
  543.            if return-code not = zeros
  544.                display "ERROR IN VioGetConfig"
  545.                go to 99999-os2-error-abort.
  546.        20100-exit.
  547.            exit.
  548.  
  549.       *****************************************************************
  550.        20200-get-video-mode.
  551.       *****************************************************************
  552.       *
  553.       * Get the current video mode.
  554.       *
  555.            call api "__VioGetMode" using
  556.                by reference viomode-data
  557.                by value     handle-zeros
  558.            if return-code not = zeros
  559.                display "ERROR IN VioGetMode"
  560.                go to 99999-os2-error-abort
  561.            end-if
  562.       *
  563.       * Save the current mode data to restore the user's
  564.       *    mode at the end of the job.
  565.       *
  566.            move viomode-data to viomode-save-data.
  567.        20200-exit.
  568.            exit.
  569.  
  570.       *****************************************************************
  571.        20300-set-video-mode.
  572.       *****************************************************************
  573.       *
  574.       * Set the video mode.
  575.       *
  576.            evaluate viogetconfig-adapter
  577.                when 0 perform 20322-set-mono-video-mode
  578.                when 1 perform 20324-set-cga-video-mode
  579.                when 2 perform 20326-set-ega-video-mode
  580.                when 3 perform 20328-set-vga-video-mode
  581.                when 7 perform 20328-set-vga-video-mode
  582.                when other
  583.                    display "ERROR - UNRECOGNISED VIDEO ADAPTER"
  584.                    go to 99999-os2-error-abort
  585.            end-evaluate
  586.            move 80 to viomode-cols
  587.            perform 20330-call-viosetmode
  588.            if return-code not = zeros
  589.                display "ERROR IN SETTING VIDEO MODE"
  590.                go to 99999-os2-error-abort
  591.            end-if.
  592.        20300-exit.
  593.            exit.
  594.  
  595.       *****************************************************************
  596.        20322-set-mono-video-mode.
  597.       *****************************************************************
  598.            move 25 to viomode-rows
  599.            move 0 to viomode-mode
  600.            move 0 to viomode-colors
  601.            move 2000 to num-chars-on-screen.
  602.        20322-exit.
  603.            exit.
  604.  
  605.       *****************************************************************
  606.        20324-set-cga-video-mode.
  607.       *****************************************************************
  608.       *
  609.       * If a CGA adapter but a monochrome screen, setup
  610.       *    in monochrome mode.
  611.       *
  612.            if viogetconfig-display = zeros
  613.                perform 20322-set-mono-video-mode
  614.            else
  615.                move 25 to viomode-rows
  616.                move 1 to viomode-mode
  617.                move 4 to viomode-colors
  618.                move 2000 to num-chars-on-screen
  619.            end-if.
  620.        20324-exit.
  621.            exit.
  622.  
  623.       *****************************************************************
  624.        20326-set-ega-video-mode.
  625.       *****************************************************************
  626.       *
  627.       * If a EGA adapter but a monochrome screen, setup
  628.       *    in monochrome mode.
  629.       *
  630.            if viogetconfig-display = zeros
  631.                perform 20322-set-mono-video-mode
  632.            else
  633.                move 43 to viomode-rows
  634.                move 1 to viomode-mode
  635.                move 4 to viomode-colors
  636.                move 3440 to num-chars-on-screen
  637.            end-if.
  638.        20326-exit.
  639.            exit.
  640.  
  641.       *****************************************************************
  642.        20328-set-vga-video-mode.
  643.       *****************************************************************
  644.       *
  645.       * If a VGA adapter but a monochrome screen, setup
  646.       *    in monochrome mode.
  647.       *
  648.            if viogetconfig-display = zeros
  649.                perform 20322-set-mono-video-mode
  650.            else
  651.                move 50 to viomode-rows
  652.                move 1 to viomode-mode
  653.                move 4 to viomode-colors
  654.                move 4000 to num-chars-on-screen
  655.            end-if.
  656.        20328-exit.
  657.            exit.
  658.  
  659.       *****************************************************************
  660.        20330-call-viosetmode.
  661.       *****************************************************************
  662.       *
  663.       * Sets the video mode.
  664.       *
  665.       * Inputs to the routine are the following:
  666.       *
  667.       *    viomode-data = Contains the video mode data
  668.       *
  669.            call api "__VioSetMode" using
  670.                by reference viomode-data
  671.                by value     handle-zeros.
  672.        20330-exit.
  673.            exit.
  674.  
  675.       *****************************************************************
  676.        20400-clear-the-screen.
  677.       *****************************************************************
  678.       *
  679.       * Clear the screen by writing 1 space to every character position
  680.       *    on the screen.
  681.       *
  682.            move 0 to screen-line
  683.            move 0 to screen-col
  684.            move num-chars-on-screen to viowrtncell-count
  685.       *
  686.       * VioWrtNCell writes one character and attribute, (a single
  687.       *    character and its attribute are refered to as a "cell")
  688.       *    to the screen 'viowrtncell-count' times.
  689.       *
  690.            call api "__VioWrtNCell" using
  691.                by reference viowrtncell-data
  692.                by value     viowrtncell-count
  693.                by value     screen-line
  694.                by value     screen-col
  695.                by value     handle-zeros
  696.            if return-code not = zeros
  697.                display "ERROR IN CLEARING THE SCREEN"
  698.                go to 99999-os2-error-abort
  699.            end-if.
  700.        20400-exit.
  701.            exit.
  702.  
  703.       *****************************************************************
  704.        20500-flush-kbd-buffer.
  705.       *****************************************************************
  706.       *
  707.       * Flushes the keyboard buffer.
  708.       *
  709.            call api "__KbdFlushBuffer" using
  710.                by value handle-zeros
  711.            if return-code not = zeros
  712.                display "ERROR IN FLUSHING THE KEYBOARD BUFFER"
  713.                go to 99999-os2-error-abort.
  714.        20500-exit.
  715.            exit.
  716.  
  717.       /
  718.       *****************************************************************
  719.        20600-init-unsorted-array.
  720.       *****************************************************************
  721.       *
  722.       * Initialize the arrays "ARRAY" and "BACKUP-ARRAY" with
  723.       *    the length of each bar on the screen, and the color of
  724.       *    each bar.
  725.       *
  726.       * "Array" is used as a scratch area. Each entry in the array
  727.       *    is initialized with a value from 1 to the maximum number
  728.       *    screen lines. When we picking random numbers, they must
  729.       *    be between 1 and the maximum number of screen lines. In
  730.       *    picking a random number, use the random number as an
  731.       *    index into "array" and zero out that entry. In this way, it
  732.       *    will be known that the random number is chosen.
  733.       *    For example, if random number "5" is picked, zeros are moved
  734.       *    to "a-length (5)". If random number "5" is picked
  735.       *    again, it can seen that "a-length (5)" = zeros and it is
  736.       *    therefore known that the number "5" has been
  737.       *    previously chosen and another must be generated.
  738.       *
  739.            move viomode-rows to array-max
  740.            perform varying sub from 1 by 1
  741.                    until sub > array-max
  742.                move sub to a-length (sub)
  743.            end-perform
  744.       *
  745.       * Initialize the random number seed.
  746.       *
  747.            perform 20610-get-starting-time
  748.            compute seed = start-time-secs / 86400 * 259199
  749.       *
  750.            perform varying sub from 1 by 1
  751.                    until sub > array-max
  752.       *
  753.       * Pick a random number (integer).
  754.       *
  755.                perform 20620-get-random-integer
  756.       *
  757.       * Continue to generate random numbers until one is generated
  758.       *    that has not been picked before.
  759.       *
  760.                perform 20620-get-random-integer thru 20620-exit
  761.                    until a-length (integer) not = zeros
  762.       *
  763.       * A unique random number (integer) is chosen. Initialize
  764.       *    length and color fields of the backup array.
  765.       *
  766.                move a-length (integer) to ba-length (sub)
  767.                move zero to a-length (integer)
  768.                move ba-length (sub) to sub-2
  769.                move bar (1:sub-2) to ba-string (sub)
  770.                if viomode-colors = 0
  771.                    move x"07" to sub-x
  772.                end-if
  773.                perform until sub-2 < 16
  774.                    subtract 15 from sub-2
  775.                end-perform
  776.                inspect ba-color (sub)
  777.                    replacing characters by sub-x
  778.            end-perform.
  779.        20600-exit.
  780.            exit.
  781.  
  782.       *****************************************************************
  783.        20610-get-starting-time.
  784.       *****************************************************************
  785.       *
  786.       * Accepts the system time and computes the number of seconds
  787.       *   since midnight.
  788.       *
  789.            accept start-time from time
  790.            compute start-time-secs = ((start-hr * 60) * 60)
  791.                                         + (start-min * 60)
  792.                                         + start-sec
  793.                                         + start-decimal.
  794.        20610-exit.
  795.            exit.
  796.  
  797.  
  798.       *****************************************************************
  799.        20620-get-random-integer.
  800.       *****************************************************************
  801.       *
  802.       * Compute a random number integer (integer).
  803.       *
  804.            compute mod = seed * 7141 + 54773
  805.            divide mod by 259119 giving mod remainder seed
  806.            compute rand = seed / 259119
  807.            compute integer = 1 + (array-max) * rand.
  808.        20620-exit.
  809.            exit.
  810.  
  811.       *****************************************************************
  812.        20700-display-unsorted-bars.
  813.       *****************************************************************
  814.       *
  815.       * Displays the unsorted bars on the screen.
  816.       *
  817.            move 50 to viowrtcharstratt-length
  818.            move 0 to screen-col
  819.            perform varying sub from 1 by 1
  820.                    until sub > array-max
  821.                move ba-data (sub) to a-data (sub)
  822.                compute screen-line = sub - 1
  823.                move a-string (sub) to viowrtcharstratt-data
  824.                move a-color (sub) to viowrtcharstratt-attr
  825.                perform 20710-call-viowrtcharstratt
  826.            end-perform
  827.            if msg-line not = spaces
  828.                move spaces to msg-line
  829.                perform 30110-update-message-line
  830.            end-if.
  831.        20700-exit.
  832.            exit.
  833.  
  834.       *****************************************************************
  835.        20705-display-sorted-bars.
  836.       *****************************************************************
  837.       *
  838.       * Displays the sorted bars on the screen.
  839.       *
  840.            move 50 to viowrtcharstratt-length
  841.            move 0 to screen-col
  842.            perform varying sub from 1 by 1
  843.                    until sub > array-max
  844.                compute screen-line = sub - 1
  845.                move a-string (sub) to viowrtcharstratt-data
  846.                move a-color (sub) to viowrtcharstratt-attr
  847.                perform 20710-call-viowrtcharstratt
  848.            end-perform
  849.            if msg-line not = spaces
  850.                move spaces to msg-line
  851.                perform 30110-update-message-line
  852.            end-if.
  853.        20705-exit.
  854.            exit.
  855.  
  856.       *****************************************************************
  857.        20710-call-viowrtcharstratt.
  858.       *****************************************************************
  859.       *
  860.       * Writes a string and its attributes the the screen.
  861.       *
  862.       * The following inputs must be initialized:
  863.       *
  864.       *               : viowrtcharstratt-data with the
  865.       *                    string one wants to write
  866.       *               : viowrtcharstratt-att with the
  867.       *                    attribute characters one wants
  868.       *                    to write. Note that the first
  869.       *                    attribute is used for every
  870.       *                    character to write.
  871.       *               : viowrtcharstratt-length =
  872.       *                    length of the string (and
  873.       *                    attribute) to write.
  874.       *               : screen-line = the screen row to
  875.       *                    to write on, starting from 0.
  876.       *               : screen-col = the screen column to
  877.       *                    write on starting from 0.
  878.       *
  879.            call api "__VioWrtCharStrAtt" using
  880.                 by reference viowrtcharstratt-data
  881.                 by value     viowrtcharstratt-length
  882.                 by value     screen-line
  883.                 by value     screen-col
  884.                 by reference viowrtcharstratt-attr
  885.                 by value     handle-zeros
  886.            if return-code not = zeros
  887.                display "ERROR IN VioWrtCharStrAtt"
  888.                go to 99999-os2-error-abort.
  889.        20710-exit.
  890.            exit.
  891.  
  892.       *****************************************************************
  893.        20800-display-menu-screen.
  894.       *****************************************************************
  895.       *
  896.       * Displays the menu screen.
  897.       *
  898.            move 50 to screen-col
  899.            move 30 to viowrtcharstratt-length
  900.            move menu-screen-hilite-attr to viowrtcharstratt-attr
  901.            perform varying menu-screen-sub from 1 by 1
  902.                    until menu-screen-sub > menu-screen-sub-max
  903.                compute screen-line = menu-screen-sub - 1
  904.                move menu-screen-line (menu-screen-sub) to
  905.                        viowrtcharstratt-data
  906.                perform 20710-call-viowrtcharstratt
  907.            end-perform
  908.       *
  909.       * Write the "COBOL" sort line in a different attribute, if
  910.       *    necessary.
  911.       *
  912.            if pause not = 0
  913.                perform 20810-unhilite-cobol-sort
  914.            end-if
  915.       *
  916.       * Clear the message line.
  917.       *
  918.            move spaces to viowrtcharstratt-data
  919.            compute screen-line = message-line-number - 1
  920.            perform 20710-call-viowrtcharstratt.
  921.        20800-exit.
  922.            exit.
  923.  
  924.       ******************************************************************
  925.        20810-unhilite-cobol-sort.
  926.       *****************************************************************
  927.       *
  928.       * Print "Cobol" on the menu, in dim attributes. Because
  929.       *    it is printed with dim attributes, this indicates
  930.       *    that the option may not chosen.
  931.       *
  932.  
  933.            compute screen-line = cobol-table-line-number - 1
  934.            move 51 to screen-col
  935.            move spaces to hilite-screen-data-item
  936.            move menu-screen-cobol-lit-tab to hilite-item
  937.            move menu-screen-normal-attr to viowrtcharstratt-attr
  938.            move hilite-screen-data-item to viowrtcharstratt-data
  939.            move 28 to viowrtcharstratt-length
  940.            perform 20710-call-viowrtcharstratt.
  941.            compute screen-line = cobol-line-number - 1
  942.            move 51 to screen-col
  943.            move spaces to hilite-screen-data-item
  944.            move menu-screen-cobol-lit to hilite-item
  945.            move menu-screen-normal-attr to viowrtcharstratt-attr
  946.            move hilite-screen-data-item to viowrtcharstratt-data
  947.            move 28 to viowrtcharstratt-length
  948.            perform 20710-call-viowrtcharstratt.
  949.        20810-exit.
  950.            exit.
  951.  
  952.       *****************************************************************
  953.        21000-get-character.
  954.       *****************************************************************
  955.       *
  956.       * Get a character from the keyboard (with no echo).
  957.       *
  958.            call api "__KbdCharIn" using
  959.                by reference kbdcharin-data
  960.                by value     kbdcharin-wait-flag
  961.                by value     handle-zeros
  962.            if return-code not = zeros
  963.                display "ERROR IN KbdCharIn"
  964.                go to 99999-os2-error-abort.
  965.        21000-exit.
  966.            exit.
  967.  
  968.       /
  969.       *****************************************************************
  970.        30000-sort-and-input-loop.
  971.       *****************************************************************
  972.       *
  973.       * A character (kbdcharin-char) has been input. If it is a
  974.       *    recognized character, act on it; else, get another.
  975.       *
  976.       * Performed until kbdcharin-char = hex 1B
  977.       *    (i.e. the ESCAPE key is pressed).
  978.       *
  979.            evaluate true
  980.                when kbdcharin-char = "C" or "c"
  981.                    perform 30150-cobol-table-sort
  982.                when kbdcharin-char = "F" or "f"
  983.                    perform 30100-cobol-sort
  984.                when kbdcharin-char = "E" or = "e"
  985.                    perform 30200-exchange-sort
  986.                when kbdcharin-char = "Q" or = "q"
  987.                    perform 30300-quick-sort
  988.                when kbdcharin-char = "S" or = "s"
  989.                    perform 30400-shell-sort
  990.                when kbdcharin-char = "H" or = "h"
  991.                    perform 30500-heap-sort
  992.                when kbdcharin-char = "I" or = "i"
  993.                    perform 30600-insert-sort
  994.                when kbdcharin-char = "B" or = "b"
  995.                    perform 30700-bubble-sort
  996.                when kbdcharin-char = ">" or = "."
  997.                    perform 30800-slow-down-the-sort
  998.                when kbdcharin-char = "<" or = ","
  999.                    perform 30900-speed-up-the-sort
  1000.                when kbdcharin-char = "T" or = "t"
  1001.                    perform 31000-toggle-sound
  1002.                when kbdcharin-char = "R" or "r"
  1003.                    perform 31100-randomize-array
  1004.            end-evaluate
  1005.       *
  1006.       * Check for up arrow and down arrow keystrokes.
  1007.       *
  1008.            evaluate true
  1009.             also true
  1010.                when kbdcharin-char = x"00" or = x"e0"
  1011.                 also kbdcharin-scan = up-arrow-scan-code
  1012.                    perform 31200-select-previous-choice
  1013.                when kbdcharin-char = x"00" or = x"e0"
  1014.                 also kbdcharin-scan = down-arrow-scan-code
  1015.                    perform 31300-select-next-choice
  1016.            end-evaluate
  1017.       *
  1018.       * Get next keystroke from the user
  1019.       *
  1020.            perform 21000-get-character.
  1021.        30000-exit.
  1022.            exit.
  1023.  
  1024.       ****************************************************************
  1025.        30100-cobol-sort.
  1026.       ****************************************************************
  1027.       *
  1028.       * This routine will perform a COBOL file sort.
  1029.       *
  1030.       * Note that a COBOL sort will only be performed if the program is
  1031.       *    running at full speed, i.e., pause = 0 (the "<" key was
  1032.       *    typed until the speed, as displayed on the menu screen, =
  1033.       *    zeros).
  1034.       *
  1035.            if pause not = 0
  1036.                move cobol-msg to msg-line
  1037.                perform 30110-update-message-line
  1038.            else
  1039.                move kbdcharin-char to last-choice
  1040.                if msg-line not = spaces
  1041.                    move spaces to msg-line
  1042.                    perform 30110-update-message-line
  1043.                end-if
  1044.       *
  1045.       * Highlight the entry.
  1046.       *
  1047.                move spaces to hilite-screen-data-item
  1048.                move zeros to elapsed
  1049.                move cobol-line-number to time-screen-line
  1050.                move cobol-literal to hilite-item
  1051.                move menu-screen-revvid-attr to viowrtcharstratt-attr
  1052.                perform 30120-write-time-on-screen
  1053.                move "ON" to updated-screen-sw
  1054.                perform 20700-display-unsorted-bars
  1055.                perform 20610-get-starting-time
  1056.       *
  1057.                sort sort-file
  1058.                    on ascending key sort-key
  1059.                    input procedure is sort-input-procedure-section
  1060.                    output procedure is sort-output-procedure-section
  1061.       *
  1062.       * The sort has completed.  Now, clear the highlight around
  1063.       *    the elapsed time.
  1064.       *
  1065.                perform 30140-clear-time-hilight
  1066.            end-if.
  1067.        30100-exit.
  1068.            exit.
  1069.  
  1070.       *****************************************************************
  1071.        30110-update-message-line.
  1072.       *****************************************************************
  1073.       *
  1074.       * This section of code writes the "error msg" line to the screen.
  1075.       *
  1076.            move msg-attr to viowrtcharstratt-attr
  1077.            move msg-line to viowrtcharstratt-data
  1078.            move 30 to viowrtcharstratt-length
  1079.            compute screen-line = message-line-number - 1
  1080.            move 50 to screen-col
  1081.            perform 20710-call-viowrtcharstratt.
  1082.        30110-exit.
  1083.            exit.
  1084.  
  1085.       *****************************************************************
  1086.        30120-write-time-on-screen.
  1087.       *****************************************************************
  1088.       *
  1089.       * Writes the elapsed time to the screen.
  1090.       *
  1091.       * Inputs to this routine are the following:
  1092.       *
  1093.       *    elapsed = the elapsed time in seconds.
  1094.       *    viowrtcharstratt-attr = the attribute to use when the
  1095.       *                                elapsed time is written to the
  1096.       *                                screen.
  1097.       *    time-screen-line = the screen line to write on.
  1098.       *
  1099.            move 28 to viowrtcharstratt-length
  1100.            move elapsed to edited-elapsed
  1101.            move edited-elapsed-red to disp-elapsed
  1102.            compute screen-line = time-screen-line - 1
  1103.            move 51 to screen-col
  1104.            move hilite-screen-data-item to viowrtcharstratt-data
  1105.            perform 20710-call-viowrtcharstratt.
  1106.        30120-exit.
  1107.            exit.
  1108.  
  1109.       *****************************************************************
  1110.        30130-update-time-on-screen.
  1111.       *****************************************************************
  1112.       *
  1113.       * Updates the screen with the elapsed time.
  1114.       *
  1115.       * Inputs to this routine are the following:
  1116.       *
  1117.       *    start-time-secs = The start time, in seconds.
  1118.       *    time-screen-line = The screen line (relative from 0) to
  1119.       *                          write the elapsed time on.
  1120.       *
  1121.            accept end-time from time
  1122.            compute end-time-secs = ((end-hr * 60) * 60)
  1123.                                       + (end-min * 60)
  1124.                                       + end-sec
  1125.                                       + end-decimal
  1126.            compute elapsed = end-time-secs - start-time-secs
  1127.            move menu-screen-revvid-attr to viowrtcharstratt-attr
  1128.            perform 30120-write-time-on-screen.
  1129.        30130-exit.
  1130.            exit.
  1131.  
  1132.       *****************************************************************
  1133.        30140-clear-time-hilight.
  1134.       *****************************************************************
  1135.       *
  1136.       * Clears the highlight attribute around the elapsed time.
  1137.       *
  1138.            move menu-screen-hilite-attr to viowrtcharstratt-attr
  1139.            perform 30120-write-time-on-screen.
  1140.        30140-exit.
  1141.            exit.
  1142.       /
  1143.       ******************************************************************
  1144.        30150-cobol-table-sort.
  1145.       ******************************************************************
  1146.       *
  1147.       * This routine will perform a sort using the MF table sort.
  1148.       *
  1149.       * The program must be running at full speed for this option to be
  1150.       *    accepted.
  1151.       *
  1152.            if pause not = 0
  1153.                move cobol-msg to msg-line
  1154.                perform 30110-update-message-line
  1155.            else
  1156.                move kbdcharin-char to last-choice
  1157.                if msg-line not = spaces
  1158.                    move spaces to msg-line
  1159.                    perform 30110-update-message-line
  1160.                end-if
  1161.       *
  1162.       * Highlight the entry
  1163.       *
  1164.                move spaces to hilite-screen-data-item
  1165.                move zeros to elapsed
  1166.                move cobol-table-line-number to time-screen-line
  1167.                move cobol-table-literal to hilite-item
  1168.                move menu-screen-revvid-attr to viowrtcharstratt-attr
  1169.                perform 30120-write-time-on-screen
  1170.                move "ON" to updated-screen-sw
  1171.                perform 20700-display-unsorted-bars
  1172.                perform 20610-get-starting-time
  1173.       *
  1174.                sort a-data on ascending a-length
  1175.       *
  1176.                perform 20705-display-sorted-bars
  1177.                perform 30130-update-time-on-screen
  1178.                perform 30140-clear-time-hilight
  1179.            end-if.
  1180.        30150-exit.
  1181.            exit.
  1182.       /
  1183.       *****************************************************************
  1184.        30200-exchange-sort.
  1185.       *****************************************************************
  1186.       *
  1187.       * The exchange sort (starting with the first element in the
  1188.       *    array) compares each element of array with every
  1189.       *    following element. If any of the following elements are
  1190.       *    smaller the the current element, swap the 2 elements.
  1191.       *    Continue through the array to the end.
  1192.       *
  1193.            move kbdcharin-char to last-choice
  1194.            move exchange-line-number to time-screen-line
  1195.            move exchange-literal to hilite-item
  1196.            move "ON" to updated-screen-sw
  1197.            perform 20700-display-unsorted-bars
  1198.            perform 20610-get-starting-time
  1199.            perform varying sub from 1 by 1
  1200.                    until sub > array-max
  1201.                move sub to smallest-line
  1202.                compute temp-sub = sub + 1
  1203.                perform varying sub-1 from temp-sub by 1
  1204.                        until sub-1 > array-max
  1205.                    if a-length (sub-1) <
  1206.                            a-length (smallest-line)
  1207.                        move sub-1 to smallest-line
  1208.                    end-if
  1209.                end-perform
  1210.                if smallest-line > sub
  1211.                    move sub to swap-line
  1212.                    move smallest-line to swap-line-1
  1213.                    perform 30210-swap-two-bars
  1214.                end-if
  1215.            end-perform
  1216.       *
  1217.       * The sort is complete. Clear the screen highlight
  1218.       *    around the elapsed time.
  1219.       *
  1220.            perform 30140-clear-time-hilight.
  1221.        30200-exit.
  1222.            exit.
  1223.  
  1224.       *****************************************************************
  1225.        30210-swap-two-bars.
  1226.       *****************************************************************
  1227.       *
  1228.       * Swaps two elements in array and updatesthe screen.
  1229.       *
  1230.       * Inputs to this routine are the following:
  1231.       *
  1232.       *    swap-line
  1233.       *       = specifies the subscript of one member to swap.
  1234.       *    swap-line-1
  1235.       *       = specifies the subscript of the other member to
  1236.       *            swap.
  1237.       *
  1238.            move a-data (swap-line) to hold-array-element
  1239.            move a-data (swap-line-1) to a-data (swap-line)
  1240.            move hold-array-element to a-data (swap-line-1)
  1241.  
  1242.            compute screen-line = swap-line - 1
  1243.            move 0 to screen-col
  1244.            move swap-line to freq
  1245.            perform 30220-write-one-bar-to-screen
  1246.  
  1247.            compute screen-line = swap-line-1 - 1
  1248.            move 0 to screen-col
  1249.            move swap-line-1 to freq
  1250.            perform 30220-write-one-bar-to-screen.
  1251.        30210-exit.
  1252.            exit.
  1253.  
  1254.       *****************************************************************
  1255.        30220-write-one-bar-to-screen.
  1256.       *****************************************************************
  1257.       *
  1258.       * Writes one bar to the screen.
  1259.       *
  1260.       * Inputs to this routine are the following:
  1261.       *
  1262.       *       array = contains one element to be written
  1263.       *       freq = subscript into the array
  1264.       *       screen-col = col number, minus 1, on screen to write to
  1265.       *       screen-line = line number, minus 1, to write to
  1266.       *
  1267.            move 50 to viowrtcharstratt-length
  1268.            move a-string (freq) to viowrtcharstratt-data
  1269.            move a-color (freq) to viowrtcharstratt-attr
  1270.            perform 20710-call-viowrtcharstratt
  1271.            perform 30230-call-dos-beep
  1272.            perform 30130-update-time-on-screen.
  1273.        30220-exit.
  1274.            exit.
  1275.  
  1276.       *****************************************************************
  1277.        30230-call-dos-beep.
  1278.       *****************************************************************
  1279.       *
  1280.       * Beeps the speaker.
  1281.       *
  1282.       * Inputs to this routine are the following:
  1283.       *
  1284.       *       PAUSE = The number of 1/100 second increments to sound
  1285.       *                    the speaker.
  1286.       *       FREQ  = The frequency in hertz to beep.
  1287.       *
  1288.            if pause not = zeros
  1289.                move pause to pause-dword
  1290.                if sound-sw = "ON "
  1291.                    compute frequency = 50 * a-length (freq)
  1292.                    multiply 8 by pause
  1293.                    call api "__DosBeep" using
  1294.                        by value frequency
  1295.                        by value pause
  1296.                    move pause-dword to pause
  1297.                else
  1298.                    multiply 8 by pause-dword
  1299.                    call api "__DosSleep" using by value pause-dword
  1300.                end-if
  1301.            end-if.
  1302.        30230-exit.
  1303.            exit.
  1304.  
  1305.       /
  1306.       *****************************************************************
  1307.        30300-quick-sort.
  1308.       *****************************************************************
  1309.       *
  1310.       * The quick sort routine works by picking a "pivot" element in
  1311.       *    the array. It will move all larger elements to one
  1312.       *    side of the pivot and all smaller elements to the other
  1313.       *    side. The subscript information of the 2 members just
  1314.       *    swapped then is saved on a stack; the routine is entered
  1315.       *    again. This is repeated until the stack is exhasted.
  1316.       *
  1317.            move kbdcharin-char to last-choice
  1318.            move quick-line-number to time-screen-line
  1319.            move quick-literal to hilite-item
  1320.            move "ON" to updated-screen-sw
  1321.            perform 20700-display-unsorted-bars
  1322.            perform 20610-get-starting-time
  1323.            move 1 to lower-stack (1)
  1324.            move array-max to upper-stack (1)
  1325.            move 1 to stack-sub
  1326.            perform until stack-sub = zeros
  1327.                if lower-stack (stack-sub) not <
  1328.                                  upper-stack (stack-sub)
  1329.                    subtract 1 from stack-sub
  1330.                else
  1331.                    move lower-stack (stack-sub) to sub
  1332.                    move upper-stack (stack-sub) to sub-1
  1333.                    move a-length (sub-1) to pivot-element
  1334.                    perform 30310-select-member-to-swap thru 30310-exit
  1335.                        until sub not < sub-1
  1336.                    move upper-stack (stack-sub) to sub-1
  1337.                    move upper-stack (stack-sub) to swap-line
  1338.                    move sub to swap-line-1
  1339.                    perform 30210-swap-two-bars
  1340.                    perform 30320-adjust-stack
  1341.                    add 1 to stack-sub
  1342.                end-if
  1343.            end-perform
  1344.       *
  1345.       *    The sort is completed. Clear the screen highlight around
  1346.       *      the elapsed time.
  1347.       *
  1348.            perform 30140-clear-time-hilight.
  1349.        30300-exit.
  1350.            exit.
  1351.  
  1352.       *****************************************************************
  1353.        30310-select-member-to-swap.
  1354.       *****************************************************************
  1355.       *
  1356.       * performed until sub not < sub-1
  1357.       *
  1358.            perform until ((sub not < sub-1)
  1359.                        or (a-length (sub) > pivot-element))
  1360.                add 1 to sub
  1361.            end-perform
  1362.            perform until ((sub not < sub-1)
  1363.                        or (a-length (sub-1) < pivot-element))
  1364.                subtract 1 from sub-1
  1365.            end-perform
  1366.            if sub < sub-1
  1367.                move sub to swap-line
  1368.                move sub-1 to swap-line-1
  1369.                perform 30210-swap-two-bars
  1370.            end-if.
  1371.        30310-exit.
  1372.            exit.
  1373.  
  1374.       *****************************************************************
  1375.        30320-adjust-stack.
  1376.       *****************************************************************
  1377.            if (sub - lower-stack (stack-sub)) <
  1378.                       (upper-stack (stack-sub) - sub)
  1379.                move lower-stack (stack-sub) to
  1380.                     lower-stack (stack-sub + 1)
  1381.                compute upper-stack (stack-sub + 1) = sub - 1
  1382.                compute lower-stack (stack-sub) = sub + 1
  1383.            else
  1384.                compute lower-stack (stack-sub + 1) = sub + 1
  1385.                move upper-stack (stack-sub) to
  1386.                     upper-stack (stack-sub + 1)
  1387.                compute upper-stack (stack-sub) = sub - 1
  1388.            end-if.
  1389.        30320-exit.
  1390.            exit.
  1391.  
  1392.       /
  1393.       *****************************************************************
  1394.        30400-shell-sort.
  1395.       *****************************************************************
  1396.       *
  1397.       * The shell sort begins by (1) comparing far-apart elements
  1398.       *    (separated by the value of the offset variable, which is
  1399.       *    initially half the distance between the first and the last
  1400.       *    elements), and then by (2) comparing closer elements.
  1401.       *    When offset = 1, a bubble sort is being performed.
  1402.       *
  1403.            move kbdcharin-char to last-choice
  1404.            move shell-line-number to time-screen-line
  1405.            move shell-literal to hilite-item
  1406.            move "ON" to updated-screen-sw
  1407.            perform 20700-display-unsorted-bars
  1408.            perform 20610-get-starting-time
  1409.            compute offset = array-max / 2
  1410.            perform until offset < 1
  1411.                compute max-limit = array-max - offset
  1412.                move 1 to sub-2
  1413.                perform until sub-2 < 1
  1414.                    move zeros to sub-2
  1415.                    perform varying sub-1 from 1 by 1
  1416.                            until sub-1 > max-limit
  1417.                        compute swap-line-1 = sub-1 + offset
  1418.                        if a-length (sub-1) >
  1419.                                 a-length (swap-line-1)
  1420.                            move sub-1 to swap-line
  1421.                            perform 30210-swap-two-bars
  1422.                            move sub-1 to sub-2
  1423.                        end-if
  1424.                    end-perform
  1425.                    compute max-limit = sub-1 - offset
  1426.                end-perform
  1427.                compute offset = offset / 2
  1428.            end-perform
  1429.       *
  1430.       * The sort has completed. Clear the screen highlight
  1431.       *    around the elapsed time.
  1432.       *
  1433.            perform 30140-clear-time-hilight.
  1434.        30400-exit.
  1435.            exit.
  1436.  
  1437.       /
  1438.       *****************************************************************
  1439.        30500-heap-sort.
  1440.       *****************************************************************
  1441.       *
  1442.       * The heap sort calls two other procedures: "30510-percolate-up"
  1443.       *    and "30520-percolate-down".
  1444.       * The percolate-up procedure turns array into a "heap" as shown
  1445.       *    below:
  1446.       *
  1447.       *                          array(1)
  1448.       *                         /        \
  1449.       *                 array(2)          array(3)
  1450.       *                 /      \          /      \
  1451.       *            array(4)  array(5)  array(6)  array(7)
  1452.       *            /      \  /      \  /      \  /      \
  1453.       *          ...     ......    ......    ......     ...
  1454.       *
  1455.       *     where each "PARENT" (e.g. array(1), array(2)...) is larger
  1456.       *          than its "CHILD" [e.g. array(1) is a parent for
  1457.       *          array(2)].
  1458.       *
  1459.       *     Therefore, after the first "PERFORM VARYING", the largest
  1460.       *          array member will be in array(1).
  1461.       *
  1462.       * The second "PERFORM VARYING" swaps the element in array(1) with
  1463.       *    the element in the variable "ARRAY-MAX", rebuilds the
  1464.       *    heap with percolate-down for array-max - 1 and loops.
  1465.       *    This is continued until the array is sorted.
  1466.       *
  1467.            move kbdcharin-char to last-choice
  1468.            move heap-line-number to time-screen-line
  1469.            move heap-literal to hilite-item
  1470.            move "ON" to updated-screen-sw
  1471.            perform 20700-display-unsorted-bars
  1472.            perform 20610-get-starting-time
  1473.            perform varying sub from 2 by 1
  1474.                    until sub > array-max
  1475.                perform 30510-percolate-up
  1476.            end-perform
  1477.            perform varying sub from array-max by -1
  1478.                    until sub < 2
  1479.                move sub to swap-line
  1480.                move 1 to swap-line-1
  1481.                perform 30210-swap-two-bars
  1482.                compute sub-1 = sub - 1
  1483.                perform 30520-percolate-down
  1484.            end-perform
  1485.       *
  1486.       * The sort is completed. now, clear the screen highlight
  1487.       *    around the elapsed time.
  1488.       *
  1489.            perform 30140-clear-time-hilight.
  1490.        30500-exit.
  1491.            exit.
  1492.  
  1493.       *****************************************************************
  1494.        30510-percolate-up.
  1495.       *****************************************************************
  1496.            move sub to sub-2
  1497.            move "OFF" to halt-sw
  1498.            perform until ((sub-2 = 1)
  1499.                        or (halt-sw = "ON"))
  1500.                compute parent = sub-2 / 2
  1501.                if a-length (sub-2) > a-length (parent)
  1502.                    move parent to swap-line
  1503.                    move sub-2 to swap-line-1
  1504.                    perform 30210-swap-two-bars
  1505.                    move parent to sub-2
  1506.                else
  1507.                    move "ON" to halt-sw
  1508.                end-if
  1509.            end-perform.
  1510.        30510-exit.
  1511.            exit.
  1512.  
  1513.       *****************************************************************
  1514.        30520-percolate-down.
  1515.       *****************************************************************
  1516.            move 1 to sub-2
  1517.            move "OFF" to halt-sw
  1518.            perform until halt-sw = "ON"
  1519.                compute child = 2 * sub-2
  1520.                if child > sub-1
  1521.                    move "ON" to halt-sw
  1522.                else
  1523.                    compute swap-line = child + 1
  1524.                    if swap-line not > sub-1
  1525.                        if a-length (swap-line) >
  1526.                                 a-length (child)
  1527.                            compute child = child + 1
  1528.                        end-if
  1529.                    end-if
  1530.                    if a-length (sub-2) < a-length (child)
  1531.                        move sub-2 to swap-line
  1532.                        move child to swap-line-1
  1533.                        perform 30210-swap-two-bars
  1534.                        move child to sub-2
  1535.                    else
  1536.                        move "ON" to halt-sw
  1537.                    end-if
  1538.                end-if
  1539.            end-perform.
  1540.        30520-exit.
  1541.            exit.
  1542.  
  1543.       /
  1544.       *****************************************************************
  1545.        30600-insert-sort.
  1546.       *****************************************************************
  1547.       *
  1548.       * The insert sort compares the length of each successive element
  1549.       *    in array with the lengths of all the preceding elements.
  1550.       *    When the proper place in the array for the element is
  1551.       *    found insert the element and move all following elements
  1552.       *    down one place.
  1553.       *
  1554.            move kbdcharin-char to last-choice
  1555.            move insert-line-number to time-screen-line
  1556.            move insert-literal to hilite-item
  1557.            move "ON" to updated-screen-sw
  1558.            perform 20700-display-unsorted-bars
  1559.            perform 20610-get-starting-time
  1560.            perform varying sub from 2 by 1
  1561.                    until sub > array-max
  1562.                move "OFF" to halt-sw
  1563.                move a-data (sub) to hold-array-element
  1564.                move sub to sub-1
  1565.                perform until ((sub-1 < 2)
  1566.                           or (halt-sw = "ON"))
  1567.                    if a-length (sub-1 - 1) > h-length
  1568.                        move a-data (sub-1 - 1) to
  1569.                             a-data (sub-1)
  1570.                        compute screen-line = sub-1 - 1
  1571.                        move 0 to screen-col
  1572.                        move sub-1 to freq
  1573.                        perform 30220-write-one-bar-to-screen
  1574.                        subtract 1 from sub-1
  1575.                    else
  1576.                        move "ON" to halt-sw
  1577.                    end-if
  1578.                end-perform
  1579.                move hold-array-element to a-data (sub-1)
  1580.                compute screen-line = sub-1 - 1
  1581.                move 0 to screen-col
  1582.                move sub-1 to freq
  1583.                perform 30220-write-one-bar-to-screen
  1584.            end-perform
  1585.       *
  1586.       * The sort is completed. Clear the screen highlight
  1587.       *    around the elapsed time.
  1588.       *
  1589.            perform 30140-clear-time-hilight.
  1590.        30600-exit.
  1591.            exit.
  1592.  
  1593.       /
  1594.       *****************************************************************
  1595.        30700-bubble-sort.
  1596.       *****************************************************************
  1597.       *
  1598.       * The bubble sort will search through array and compare
  1599.       *    adjacent elements with the current element. If the
  1600.       *    adjacent element is less than the current element, they
  1601.       *    will be swapped. This is done until no more elements are
  1602.       *    swapped.
  1603.       *
  1604.            move kbdcharin-char to last-choice
  1605.            move bubble-line-number to time-screen-line
  1606.            move bubble-literal to hilite-item
  1607.            move "ON" to updated-screen-sw
  1608.            perform 20700-display-unsorted-bars
  1609.            perform 20610-get-starting-time
  1610.            move array-max to max-loop
  1611.            move 99 to last-element-saved
  1612.            perform until last-element-saved = zeros
  1613.                move zeros to last-element-saved
  1614.                perform varying sub from 1 by 1
  1615.                        until sub > (max-loop - 1)
  1616.                    if a-length (sub) > a-length (sub + 1)
  1617.                        move sub to swap-line swap-line-1
  1618.                        add 1 to swap-line-1
  1619.                        perform 30210-swap-two-bars
  1620.                        move sub to last-element-saved
  1621.                    end-if
  1622.                end-perform
  1623.                move last-element-saved to max-loop
  1624.            end-perform
  1625.       *
  1626.       * The sort is completed. Clear the screen highlight
  1627.       *    around the elapsed time.
  1628.       *
  1629.            perform 30140-clear-time-hilight.
  1630.        30700-exit.
  1631.            exit.
  1632.  
  1633.       /
  1634.       *****************************************************************
  1635.        30800-slow-down-the-sort.
  1636.       *****************************************************************
  1637.       *
  1638.       * User typed the ">" key, increase the time the beep sounds.
  1639.       *
  1640.            if pause not = 30
  1641.                add 1 to pause
  1642.                if pause = 1
  1643.                    if auto-sound-toggle-sw = "ON"
  1644.                        move "ON " to sound-sw
  1645.                        move "ON" to updated-screen-sw
  1646.                        move "OFF" to auto-sound-toggle-sw
  1647.                    end-if
  1648.                end-if
  1649.                move pause to disp-pause
  1650.                perform 30810-update-speed-variables
  1651.                if updated-screen-sw = "ON"
  1652.                    move "OFF" to updated-screen-sw
  1653.                    perform 20700-display-unsorted-bars
  1654.                    perform 20800-display-menu-screen
  1655.                else
  1656.                    perform 30820-update-screen-speed
  1657.                    perform 30830-update-screen-prompts
  1658.                end-if
  1659.            end-if.
  1660.        30800-exit.
  1661.            exit.
  1662.  
  1663.       *****************************************************************
  1664.        30810-update-speed-variables.
  1665.       *****************************************************************
  1666.            evaluate pause
  1667.                when 30 move spaces to ms-slow-down-var
  1668.                        move space to ms-slow-down-char
  1669.                when 29 move menu-screen-slow-down-msg to
  1670.                            ms-slow-down-var
  1671.                        move menu-screen-slow-down-lit to
  1672.                            ms-slow-down-char
  1673.                when 1  move menu-screen-speed-up-msg
  1674.                            to ms-speed-up-var
  1675.                        move menu-screen-speed-up-lit
  1676.                            to ms-speed-up-char
  1677.                        move menu-screen-toggle-sound-msg
  1678.                            to ms-toggle-sound-var
  1679.                        move menu-screen-toggle-sound-lit
  1680.                            to ms-toggle-sound-char
  1681.                when 0  move spaces to ms-speed-up-var
  1682.                        move space to ms-speed-up-char
  1683.                        move space to ms-toggle-sound-var
  1684.                        move space to ms-toggle-sound-char
  1685.            end-evaluate.
  1686.        30810-exit.
  1687.            exit.
  1688.  
  1689.       *****************************************************************
  1690.        30820-update-screen-speed.
  1691.       *****************************************************************
  1692.       *
  1693.       * Updates the speed counter on the screen.
  1694.       *
  1695.            move 30 to viowrtcharstratt-length
  1696.            compute screen-line = speed-counter-line-number - 1
  1697.            move 50 to screen-col
  1698.            move menu-screen-line (speed-counter-line-number) to
  1699.                viowrtcharstratt-data
  1700.            move menu-screen-hilite-attr to viowrtcharstratt-attr
  1701.            perform 20710-call-viowrtcharstratt.
  1702.        30820-exit.
  1703.            exit.
  1704.  
  1705.       *****************************************************************
  1706.        30830-update-screen-prompts.
  1707.       *****************************************************************
  1708.       *
  1709.       * This routine updates the prompts on the screen that inform the
  1710.       *    user that they can speed up or slow down the sort at will by
  1711.       *    using the "<" and ">" keys.
  1712.       *
  1713.       * Also updated is the "Cobol" sort menu entry. If the speed of
  1714.       *    the sort is zero, "Cobol" is printed in bold characters,
  1715.       *    otherwise, it is printed in dim characters (indicating the
  1716.       *    the option can not be chosen).
  1717.       *
  1718.            move 30 to viowrtcharstratt-length
  1719.            move menu-screen-hilite-attr to viowrtcharstratt-attr
  1720.            move 50 to screen-col
  1721.            evaluate true
  1722.                when pause = 30 or = 29
  1723.                    perform 30840-write-slow-down-prompts
  1724.                when pause = 0
  1725.                    perform 30850-write-speed-up-prompts
  1726.                    perform 30860-hilite-cobol-sort
  1727.                when pause = 1
  1728.                    perform 30850-write-speed-up-prompts
  1729.                    perform 20810-unhilite-cobol-sort
  1730.            end-evaluate
  1731.            if msg-line not = spaces
  1732.                move spaces to msg-line
  1733.                perform 30110-update-message-line
  1734.            end-if.
  1735.        30830-exit.
  1736.            exit.
  1737.  
  1738.       *****************************************************************
  1739.        30840-write-slow-down-prompts.
  1740.       *****************************************************************
  1741.       *
  1742.       * This routine writes the prompts that tells the user how to
  1743.       *    use the ">" key.
  1744.       *
  1745.            move menu-screen-slow-down-line to
  1746.                viowrtcharstratt-data
  1747.            compute screen-line = slow-down-line-number - 1
  1748.            perform 20710-call-viowrtcharstratt
  1749.            move menu-screen-choice-line to viowrtcharstratt-data
  1750.            compute screen-line = prompt-line-number - 1
  1751.            perform 20710-call-viowrtcharstratt.
  1752.        30840-exit.
  1753.            exit.
  1754.  
  1755.       *****************************************************************
  1756.        30850-write-speed-up-prompts.
  1757.       *****************************************************************
  1758.       *
  1759.       * This routine writes the prompts that tells the user how to
  1760.       *    use the "<" key.
  1761.       *
  1762.            move menu-screen-speed-up-line to
  1763.                viowrtcharstratt-data
  1764.            compute screen-line = speed-up-line-number - 1
  1765.            perform 20710-call-viowrtcharstratt
  1766.            move menu-screen-choice-line to viowrtcharstratt-data
  1767.            compute screen-line = prompt-line-number - 1
  1768.            perform 20710-call-viowrtcharstratt.
  1769.        30850-exit.
  1770.            exit.
  1771.  
  1772.       *****************************************************************
  1773.        30860-hilite-cobol-sort.
  1774.       *****************************************************************
  1775.       *
  1776.       * Print "Cobol" on the menu, in highlighted attributes. Because
  1777.       *    it is printed in highlighted attributes, this indicates
  1778.       *    that the option may chosen.
  1779.       *
  1780.            move 28 to viowrtcharstratt-length
  1781.            compute screen-line = cobol-table-line-number - 1
  1782.            move 51 to screen-col
  1783.            move spaces to hilite-screen-data-item
  1784.            move menu-screen-cobol-lit-tab to hilite-item
  1785.            move menu-screen-hilite-attr to viowrtcharstratt-attr
  1786.            move hilite-screen-data-item to viowrtcharstratt-data
  1787.            perform 20710-call-viowrtcharstratt.
  1788.            move 28 to viowrtcharstratt-length
  1789.            compute screen-line = cobol-line-number - 1
  1790.            move 51 to screen-col
  1791.            move spaces to hilite-screen-data-item
  1792.            move menu-screen-cobol-lit to hilite-item
  1793.            move menu-screen-hilite-attr to viowrtcharstratt-attr
  1794.            move hilite-screen-data-item to viowrtcharstratt-data
  1795.            perform 20710-call-viowrtcharstratt.
  1796.        30860-exit.
  1797.            exit.
  1798.  
  1799.       *****************************************************************
  1800.        30900-speed-up-the-sort.
  1801.       *****************************************************************
  1802.       *
  1803.       * User typed the "<" key, decrease the time the beep sounds.
  1804.       *
  1805.            if pause not = zeros
  1806.                subtract 1 from pause
  1807.                if pause = zeros
  1808.                    if sound-sw = "ON "
  1809.                        move "OFF" to sound-sw
  1810.                        move "ON" to auto-sound-toggle-sw
  1811.                        move "ON" to updated-screen-sw
  1812.                    end-if
  1813.                end-if
  1814.                move pause to disp-pause
  1815.                perform 30810-update-speed-variables
  1816.                if updated-screen-sw = "ON"
  1817.                    move "OFF" to updated-screen-sw
  1818.                    perform 20700-display-unsorted-bars
  1819.                    perform 20800-display-menu-screen
  1820.                else
  1821.                    perform 30820-update-screen-speed
  1822.                    perform 30830-update-screen-prompts
  1823.                end-if
  1824.            end-if.
  1825.        30900-exit.
  1826.            exit.
  1827.  
  1828.       *****************************************************************
  1829.        31000-toggle-sound.
  1830.       *****************************************************************
  1831.       *
  1832.       * Toggle the sound on or off.
  1833.       *
  1834.            if pause not = zeros
  1835.                move "OFF" to auto-sound-toggle-sw
  1836.                if sound-sw = "OFF"
  1837.                    move "ON " to sound-sw
  1838.                else
  1839.                    move "OFF" to sound-sw
  1840.                end-if
  1841.                move 30 to viowrtcharstratt-length
  1842.                compute screen-line = sound-sw-line-number - 1
  1843.                move 50 to screen-col
  1844.                move menu-screen-line (sound-sw-line-number) to
  1845.                    viowrtcharstratt-data
  1846.                move menu-screen-hilite-attr to viowrtcharstratt-attr
  1847.                perform 20710-call-viowrtcharstratt
  1848.                if msg-line not = spaces
  1849.                    move spaces to msg-line
  1850.                    perform 30110-update-message-line
  1851.                end-if
  1852.            end-if.
  1853.        31000-exit.
  1854.            exit.
  1855.  
  1856.       ****************************************************************
  1857.        31100-randomize-array.
  1858.       ****************************************************************
  1859.       *
  1860.       * Re-randomize the bars on the screen.
  1861.       *
  1862.            move spaces to hilite-screen-data-item
  1863.            move randomize-literal to hilite-item
  1864.            move randomize-line-number to time-screen-line
  1865.            move zeros to elapsed
  1866.            move menu-screen-revvid-attr to viowrtcharstratt-attr
  1867.            perform 30120-write-time-on-screen
  1868.            move spaces to msg-line
  1869.            move wait-msg to msg-line
  1870.            perform 30110-update-message-line
  1871.            perform 20600-init-unsorted-array
  1872.            perform 20700-display-unsorted-bars
  1873.            perform 20800-display-menu-screen.
  1874.        31100-exit.
  1875.            exit.
  1876.  
  1877.       *****************************************************************
  1878.        31200-select-previous-choice.
  1879.       *****************************************************************
  1880.       *
  1881.       * The up-arrow key was typed. Depending on the last choice
  1882.       *    taken, perform the proper sort.
  1883.       *
  1884.            evaluate true
  1885.                when last-choice = space
  1886.                    perform 30700-bubble-sort
  1887.                    move "B" to last-choice
  1888.                when last-choice = "F" or = "f"
  1889.                    perform 30100-cobol-sort
  1890.                    move "C" to last-choice
  1891.                when last-choice = "E" or = "e"
  1892.                    perform 30100-cobol-sort
  1893.                    move "F" to last-choice
  1894.                when last-choice = "Q" or = "q"
  1895.                    perform 30200-exchange-sort
  1896.                    move "E" to last-choice
  1897.                when last-choice = "S" or = "s"
  1898.                    perform 30300-quick-sort
  1899.                    move "Q" to last-choice
  1900.                when last-choice = "H" or = "h"
  1901.                    perform 30400-shell-sort
  1902.                    move "S" to last-choice
  1903.                when last-choice = "I" or = "i"
  1904.                    perform 30500-heap-sort
  1905.                    move "H" to last-choice
  1906.                when last-choice = "B" or = "b"
  1907.                    perform 30600-insert-sort
  1908.                    move "I" to last-choice
  1909.                when last-choice = "C" or "c"
  1910.                    perform 30700-bubble-sort
  1911.                    move "B" to last-choice
  1912.            end-evaluate.
  1913.        31200-exit.
  1914.            exit.
  1915.  
  1916.       *****************************************************************
  1917.        31300-select-next-choice.
  1918.       *****************************************************************
  1919.       *
  1920.       * The down-arrow key was typed. Depending on the last sort
  1921.       *    execute the proper sort.
  1922.       *
  1923.            evaluate true
  1924.                when last-choice = space
  1925.                    perform 30100-cobol-sort
  1926.                    move "C" to last-choice
  1927.                when last-choice = "C" or "c"
  1928.                    perform 30100-cobol-sort
  1929.                    move "F" to last-choice
  1930.                when last-choice = "F" or "f"
  1931.                    perform 30200-exchange-sort
  1932.                    move "E" to last-choice
  1933.                when last-choice = "E" or = "e"
  1934.                    perform 30300-quick-sort
  1935.                    move "Q" to last-choice
  1936.                when last-choice = "Q" or = "q"
  1937.                    perform 30400-shell-sort
  1938.                    move "S" to last-choice
  1939.                when last-choice = "S" or = "s"
  1940.                    perform 30500-heap-sort
  1941.                    move "H" to last-choice
  1942.                when last-choice = "H" or = "h"
  1943.                    perform 30600-insert-sort
  1944.                    move "I" to last-choice
  1945.                when last-choice = "I" or = "i"
  1946.                    perform 30700-bubble-sort
  1947.                    move "B" to last-choice
  1948.                when last-choice = "B" or = "b"
  1949.                    perform 30100-cobol-sort
  1950.                    move "C" to last-choice
  1951.            end-evaluate.
  1952.        31300-exit.
  1953.            exit.
  1954.  
  1955.       *****************************************************************
  1956.        40000-restore-users-video-mode.
  1957.       *****************************************************************
  1958.       *
  1959.       * Restore the original video mode before quitting.
  1960.       *
  1961.            move viomode-save-data to viomode-data.
  1962.            perform 20330-call-viosetmode.
  1963.        40000-exit.
  1964.            exit.
  1965.  
  1966.       *****************************************************************
  1967.        99999-os2-error-abort.
  1968.       *****************************************************************
  1969.       *
  1970.       * Reports an OS/2 API error.
  1971.       *
  1972.       * Inputs to the routine are the following:
  1973.       *
  1974.       *    RETURN-CODE = OS/2 error code returned from the OS/2
  1975.       *                   routine.
  1976.       *
  1977.            display "AX = " , return-code
  1978.            display "PROGRAM IS ABORTING"
  1979.            stop run.
  1980.        99999-exit.
  1981.            exit.
  1982.  
  1983.       /
  1984.       *****************************************************************
  1985.        sort-input-procedure-section section.
  1986.        sort-input-start.
  1987.       *****************************************************************
  1988.            perform varying sub from 1 by 1
  1989.                    until sub > array-max
  1990.                release sort-rec from a-data (sub)
  1991.            end-perform.
  1992.        sort-input-exit.
  1993.            exit.
  1994.  
  1995.       *****************************************************************
  1996.        sort-output-procedure-section section.
  1997.        sort-output-start.
  1998.       *****************************************************************
  1999.            perform varying sub from 1 by 1
  2000.                    until sub > array-max
  2001.                return sort-file into a-data (sub)
  2002.                compute screen-line = sub - 1
  2003.                move sub to freq
  2004.                move 0 to screen-col
  2005.                move 50 to viowrtcharstratt-length
  2006.                move a-string (freq) to viowrtcharstratt-data
  2007.                move a-color (freq) to viowrtcharstratt-attr
  2008.                perform 20710-call-viowrtcharstratt
  2009.            end-perform
  2010.            perform 30130-update-time-on-screen.
  2011.        sort-output-exit.
  2012.            exit.
  2013.  
  2014.