home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12780.ZIP / UIASM.BAS < prev    next >
BASIC Source File  |  1990-10-25  |  8KB  |  272 lines

  1.  
  2. '| =========================================================================
  3. '|
  4. '| UIASM.BAS
  5. '|
  6. '| This BASIC source file will contain the BASIC source code for the
  7. '| UIASM.ASM routines provided with the BASIC 7.00 and 7.10 user-toolbox.
  8. '|
  9. '| These routines are currently written an assembler for speed.  This file
  10. '| contains the equvilent BASIC routines using OS/2 VIO API calls.
  11. '|
  12. '| The OS/2 VIO API calls are written in assembler and still provide a
  13. '| comparable exection time.  Even-though the majority if the code has
  14. '| been rewritten into BASIC.
  15. '|
  16. '| The routine names and prototypes are as follows :
  17. '|
  18. '|     GetCopyBox : Gets screen box info and places the info into a string
  19. '|                  variable.
  20. '|
  21. '|       DECLARE SUB GetCopyBox (ULRow%, ULCow%, LRRow%, LRCol%, buffer$)
  22. '|
  23. '|
  24. '|     PutCopyBox : Puts screen box info back on the screen from a string
  25. '|                  variable.
  26. '|
  27. '|       DECLARE SUB PutCopyBox (ULRow%, ULCow%, buffer$)
  28. '|
  29. '|
  30. '|     AttrBox    : Canges the color attibutes of all characters with a box
  31. '|
  32. '|       DECLARE SUB AttrBox    (ULRow%, ULCow%, LRRow%, LRCol%, NewAttr%)
  33. '|
  34. '| In the above parameter list the beginning two characters specify the
  35. '| portion of the rectangle of the box being refered to.
  36. '|
  37. '|      UL = Upper-Left corner of the rectangle/box
  38. '|      LR = Lower-Right corner of the rectangle/box
  39. '|
  40. '| =========================================================================
  41.  
  42.  
  43. '| =========================================================================
  44. '|
  45. '| COMMON Statements used by the three routines
  46. '|
  47. '| =========================================================================
  48.  
  49. COMMON SHARED /VioUIASM/    VideoHandle%
  50.  
  51.  
  52. '| =========================================================================
  53. '|
  54. '| DECLARE Statements for the VIO routines
  55. '|
  56. '| =========================================================================
  57.  
  58. DECLARE FUNCTION VioReadCellStr% ( BYVAL CellAdd&, _
  59.                    SEG     NumCells%, _
  60.                    BYVAL SRow%,     _
  61.                    BYVAL SCol%,     _
  62.                    BYVAL VidHandle% _
  63.                  )
  64.  
  65. DECLARE FUNCTION VioWrtCellStr%  ( BYVAL CellAdd&,     _
  66.                    BYVAL    NumCells%,     _
  67.                    BYVAL    SRow%,         _
  68.                    BYVAL    SCol%,         _
  69.                    BYVAL    VidHandle%     _
  70.                  )
  71.  
  72.  
  73. '| =========================================================================
  74.  
  75. SUB GetCopyBox (ULRow%, ULCol%, LRRow%, LRCol%, ScreenBuffer$)
  76.  
  77.     '| Subtract 1 from all screen coordinates to reflect the difference
  78.     '| between BASIC's screen BASE 1 and the VIO API BASE 0.
  79.     '|
  80.     '| We also make a copy of the variables, since we do not force the
  81.     '| caller to use BYVAL or by reference calling convention.
  82.     '|
  83.     '| UL = Upper-Left corner of the rectangle/box
  84.     '| LR = Lower-Right corner of the rectangle/box
  85.  
  86.     URow% = ULRow% - 1
  87.     UCol% = ULCol% - 1
  88.  
  89.     LRow% = LRRow% - 1
  90.     LCol% = LRCol% - 1
  91.  
  92.     '| Find width and height of the Box
  93.  
  94.     BoxHeigth% = LRow% - URow% + 1
  95.     BoxWidth% = LCol% - UCol% + 1
  96.  
  97.     '| Calculate the actual width of the line before the For-loop
  98.     '| thus performing the operation once.  We need a copy of the
  99.     '| results, since the function call changes the value of
  100.     '| parameter passed to it.
  101.  
  102.     ActualWidth% = BoxWidth% * 2
  103.     OldBoxWidth% = ActualWidth%
  104.  
  105.     For i% = URow% to LRow%
  106.  
  107.         Work$ = Space$ (ActualWidth%)
  108.  
  109.         '| Read a one line from the Box of BoxWidth% long into
  110.         '| a Work String.  The format of the string is
  111.         '| character + attribute (every two bytes make a cell)
  112.  
  113.         VIORt% = VioReadCellStr ( SSEGADD (Work$), _
  114.                       ActualWidth%,       _
  115.                       i%,               _
  116.                       UCol%,           _
  117.                       VideoHandle%       _
  118.                     )
  119.  
  120.         '| VioReadCellStr changes the value "ActualWidth%" to reflect
  121.         '| how many characters where actual placed in to the buffer.
  122.         '|
  123.         '| We reset the value after every call, so we don't lose one
  124.         '| character and attribute each type through the For-Loop.
  125.  
  126.         ActualWidth% = OldBoxWidth%
  127.  
  128.         '| We calculate the offset into the string where we
  129.         '| will place the line of text.
  130.  
  131.         ScrnOff% = ActualWidth% * (i% - URow%) + 3
  132.  
  133.         '| By using the Mid$ statement, we can place the information
  134.         '| over the existing information with little work on our part.
  135.  
  136.         Mid$ (ScreenBuffer$, ScrnOff%, Len (Work$) ) = Work$
  137.  
  138.     Next i%
  139.  
  140.     '| Store the Width and Height of the BOX in the first
  141.     '| two characters of the buffer.  The Height will be on the
  142.     '| BASE of ONE, and PutCopyBox will convert it to a BASE zero.
  143.  
  144.     Mid$(ScreenBuffer$, 1, 1) = chr$(BoxWidth%)
  145.     Mid$(ScreenBuffer$, 2, 1) = chr$(BoxHeigth%)
  146.  
  147. END SUB
  148.  
  149. SUB PutCopyBox (ULRow%, ULCol%, ScreenBuffer$)
  150.  
  151.     '| Subtract 1 from all screen coordinates to reflect the difference
  152.     '| between BASIC's screen BASE 1 and the VIO API BASE 0.
  153.     '|
  154.     '| We also make a copy of the variables, since we do not force the
  155.     '| caller to use BYVAL or by reference calling convention.
  156.     '|
  157.     '| UL = Upper-Left corner of the rectangle/box
  158.     '| LR = Lower-Right corner of the rectangle/box
  159.  
  160.     URow% = ULRow% - 1
  161.     UCol% = ULCol% - 1
  162.  
  163.     '| The first two bytes are the Width and Heigth used by GetCopyBox.
  164.     '| Where the Heigth is from BASE 1 rather then ZERO
  165.  
  166.     BoxWidth%  = ASC(Mid$ (ScreenBuffer$, 1, 1))
  167.     BoxHeigth% = ASC(Mid$ (ScreenBuffer$, 2, 1)) - 1
  168.  
  169.     '| We calculate the actual width of the line before the loop,
  170.     '| rather then inside the loop.
  171.  
  172.     ActualWidth% = BoxWidth% * 2
  173.  
  174.     For i% = 0 to BoxHeigth%
  175.  
  176.         '| Calculate the offset into the string for each line of
  177.         '| the box.
  178.  
  179.         ScrnOff% = ActualWidth% * i% + 3
  180.  
  181.         '| The actual row on the screen that we a printing to
  182.  
  183.         NewRow% = URow% + i%
  184.  
  185.         '| We extract a line of text with the attibutes in a
  186.         '| similar manner to how we placed them in the string.
  187.  
  188.         Work$ = Mid$ (ScreenBuffer$, ScrnOff%, ActualWidth%)
  189.  
  190.         '| Write the line of text and attributes to the screen
  191.  
  192.         VIORt% = VioWrtCellStr ( SSEGADD (Work$), _
  193.                      ActualWidth%,      _
  194.                      NewRow%,          _
  195.                      UCol%,              _
  196.                      VideoHandle%      _
  197.                        )
  198.  
  199.     Next i%
  200.  
  201. END SUB
  202.  
  203. SUB AttrBox (ULRow%, ULCol%, LRRow%, LRCol%, NewAttr%)
  204.  
  205.     '| Subtract 1 from all screen coordinates to reflect the difference
  206.     '| between BASIC's screen BASE 1 and the VIO API BASE 0.
  207.     '|
  208.     '| We also make a copy of the variables, since we do not force the
  209.     '| caller to use BYVAL or by reference calling convention.
  210.     '|
  211.     '| UL = Upper-Left corner of the rectangle/box
  212.     '| LR = Lower-Right corner of the rectangle/box
  213.  
  214.     URow% = ULRow% - 1
  215.     UCol% = ULCol% - 1
  216.  
  217.     LRow% = LRRow% - 1
  218.     LCol% = LRCol% - 1
  219.  
  220.     '| Find width and height of the Box
  221.  
  222.     BoxHeigth% = LRow% - URow% + 1
  223.     BoxWidth% = LCol% - UCol% + 1
  224.  
  225.     '| Calculate the actual width of the line before the For-loop
  226.     '| thus performing the operation once.  We need a copy of the
  227.     '| results, since the function call changes the value of
  228.     '| parameter passed to it.
  229.  
  230.     ActualWidth% = BoxWidth% * 2
  231.     OldBoxWidth% = ActualWidth%
  232.  
  233.     For i% = URow% to LRow%
  234.  
  235.         Work$ = Space$ (ActualWidth%)
  236.  
  237.         '| Read a one line from the Box of BoxWidth% long into
  238.         '| a Work String.  The format of the string is
  239.         '| character + attribute (every two bytes make a cell)
  240.  
  241.         VIORt% = VioReadCellStr ( SSEGADD (Work$), _
  242.                       ActualWidth%,       _
  243.                       i%,               _
  244.                       UCol%,           _
  245.                       VideoHandle%       _
  246.                     )
  247.  
  248.         '| VioReadCellStr changes the value "ActualWidth%" to reflect
  249.         '| how many characters where actual placed in to the buffer.
  250.         '|
  251.         '| We reset the value after every call, so we don't lose one
  252.         '| character and attribute each type through the For-Loop.
  253.  
  254.         ActualWidth% = OldBoxWidth%
  255.  
  256.         For j% = 2 to ActualWidth% STEP 2
  257.  
  258.             Mid$(Work$, j%, 1) = chr$ (NewAttr%)
  259.  
  260.         Next j%
  261.  
  262.         VIORt% = VioWrtCellStr ( SSEGADD (Work$), _
  263.                      ActualWidth%,      _
  264.                      i%,              _
  265.                      UCol%,              _
  266.                      VideoHandle%      _
  267.                    )
  268.  
  269.     Next i%
  270.  
  271. END SUB
  272.