home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / qb_lib / drawbox.asm < prev    next >
Encoding:
Assembly Source File  |  1990-09-02  |  11.0 KB  |  408 lines

  1. ;*****************************************************************************                                                      
  2. ;
  3. ;       Name :  DrawBox.ASM
  4. ;
  5. ;    Revised :  09/02/90 03:24pm            
  6. ;
  7. ;    Purpose :  - Draws a box on the display screen of a size and in a format 
  8. ;               defined by the user.
  9. ;
  10. ;               - This routine should be DECLAREd in your program as an 
  11. ;               external SUB routine, via the QuickBASIC statement -
  12. ;
  13. ;DECLARE SUB DrawBox(Ulr%, Ulc%, Lrr%, Lrc%, BAttrib%, BType%, WAttrib%, Shadow%)
  14. ;
  15. ;  Parameters : - In this case, there will be 8 parameters, any or all of may be
  16. ;               either pre-defined INTEGER VARIABLES, IMMEDIATE INTEGER VALUES,
  17. ;               or CONSTs.
  18. ;               - These parameters are defined as follows :
  19. ;
  20. ;               Ulr             = Upper Left Row # for Box
  21. ;               Ulc             = Upper Left Column # for Box
  22. ;               Lrr             = Lower Right Row # for Box
  23. ;               Lrc             = Lower Right Column # for Box
  24. ;               BAttrib = Color attribute for box, as per the table below
  25. ;               BType   = which type of Box to draw  -
  26. ;                       1 = Straight Single Line Box
  27. ;                       2 = Straight Double Line Box
  28. ;                       3 = Single HLine Box, Double VLine Box
  29. ;                       4 = Double HLine Box, Single VLine Box
  30. ;                       5 = Solid Line box (100% dots)
  31. ;                       6 = Solid Line box (75% dots)
  32. ;                       7 = Solid Line box (50% dots)
  33. ;                       8 = Solid Line box (25% dots)
  34. ;               WAttrib = Color to first clear the window area to - if this
  35. ;                       parm = 0, then the area will NOT be cleared prior to 
  36. ;                       use (you can clear to black using attrib = 7)
  37. ;               Shadow  = If this parm = 0 then NO shadow box will be drawn
  38. ;                       around the box; otherwise, a shadow box will be drawn.
  39. ;
  40. ;     Returns : None - also, this routine does NO ERROR CHECKING for the 
  41. ;               parm values you pass, so be careful.
  42. ;
  43. ;                            COLOR VALUES TO USE
  44. ;
  45. ;       Color           Foreground Value                Background Value
  46. ;
  47. ;       BLACK                   0                                0
  48. ;       BLUE                    1                               16
  49. ;       GREEN                   2                               32
  50. ;       CYAN                    3                               48
  51. ;       RED                     4                               64
  52. ;       MAGENTA                 5                               80
  53. ;       YELLOW                  6                               96
  54. ;       WHITE                   7                              112
  55. ;       
  56. ;       To get INTENSE foreground color, add 8 to foreground value.
  57. ;    To get BLINKING attribute, add 128 to the total combined color value.
  58. ;
  59. ;=============================================================================                                              
  60.  
  61.     .MODEL    MEDIUM, BASIC
  62.     .CODE
  63.  
  64. DrawBox proc ULR:word, ULC:word, LRR:word, LRC:word, BATTRIB:word, BOXTYPE:word, WATTRIB:word, SHADOW:word
  65. LOCAL   VLine:WORD, HLine:WORD, UlcChar:WORD, UrcChar:WORD, LlcChar:WORD, LrcChar:WORD, ULRow:word ,ULCol:word ,LRRow:word ,LRCol:word
  66.  
  67.         mov     VLine,179               ; If invalid value is in BOXTYPE,                                              
  68.         mov     HLine,196               ;    assume we will use straight,       
  69.         mov     UlcChar,218             ;    single line box
  70.     mov    UrcChar,191
  71.     mov    LlcChar,192
  72.     mov    LrcChar,217
  73.  
  74.     mov    BX,BOXTYPE
  75.     mov    AX,[BX]
  76.         cmp     AX,1                    ; Should we draw a single line box?
  77.         jne     Not_Type_One_Box        ;   No - check next possibility
  78.     jmp    Draw_The_Box
  79.  
  80. Not_Type_One_Box:
  81.  
  82.         cmp     AX,2                    ; Should we draw a double line box?
  83.         jne     Not_Type_Two_Box        ;   No - check the next possibility
  84.     mov    VLine,186
  85.     mov    HLine,205
  86.     mov    UlcChar,201
  87.     mov    UrcChar,187
  88.     mov    LlcChar,200
  89.     mov    LrcChar,188
  90.     jmp    Draw_The_Box
  91.  
  92. Not_Type_Two_Box:
  93.  
  94.         cmp     AX,3                    ; Should we draw single HLine, Double VLine Box?
  95.         jne     Not_Type_Three_Box      ;   No - Check the last possibility
  96.     mov    VLine,186
  97.     mov    HLine,196
  98.     mov    UlcChar,214
  99.     mov    UrcChar,183
  100.     mov    LlcChar,211
  101.     mov    LrcChar,189
  102.     jmp    Draw_The_Box
  103.  
  104. Not_Type_Three_Box:
  105.  
  106.         cmp     AX,4                    ; Should we draw a double HLine, Single VLine Box?
  107.         jne     Not_Type_Four_Box       ;       No - try next type
  108.     mov    VLine, 179
  109.     mov    HLine, 205
  110.     mov    UlcChar, 213
  111.     mov    UrcChar, 184
  112.     mov    LlcChar, 212
  113.     mov    LrcChar, 190
  114.     jmp    Draw_The_Box
  115.  
  116. Not_Type_Four_Box:
  117.  
  118.         cmp     AX,5                    ; Should we draw a solid box (100% dots)
  119.         jne     Not_Type_Five_Box       ;       No - try next type
  120.     mov    VLine, 219
  121.     mov    HLine, 219
  122.     mov    UlcChar, 219
  123.     mov    UrcChar, 219
  124.     mov    LlcChar, 219
  125.     mov    LrcChar, 219
  126.     jmp    short Draw_The_Box
  127.  
  128. Not_Type_Five_Box:
  129.  
  130.         cmp     AX,6                    ; Should we draw solid box, 3/4 dots?
  131.         jne     Not_Type_Six_Box        ;   No - try next type
  132.     mov    HLine, 178
  133.     mov    VLine, 178
  134.     mov    UlcChar, 178
  135.     mov    UrcChar, 178
  136.     mov    LlcChar, 178
  137.     mov    LrcChar, 178
  138.     jmp    short Draw_The_Box
  139.  
  140. Not_Type_Six_Box:
  141.  
  142.         cmp     AX,7                    ; Should we draw solid box, 1/2 dots on?
  143.         jne     Not_Type_Seven_Box      ;       No - try next type
  144.     mov    HLine, 177
  145.     mov    VLine, 177
  146.     mov    UlcChar, 177
  147.     mov    UrcChar, 177
  148.     mov    LlcChar, 177
  149.     mov    LrcChar, 177
  150.     jmp    short Draw_The_Box
  151.  
  152. Not_Type_Seven_Box:
  153.  
  154.         cmp     AX, 8                   ; Should we draw solid box, 1/4 dots?
  155.         jne     Draw_The_Box            ; If not, use default = single line box
  156.         mov     VLine, 176
  157.         mov     HLine, 176
  158.         mov     UlcChar, 176
  159.         mov     UrcChar, 176
  160.         mov     LlcChar, 176
  161.         mov     LrcChar, 176
  162.  
  163. Draw_The_Box:
  164.  
  165.         mov     BX,ULC                  ; Put address of the ULC value into BX
  166.         mov     CX,[BX]                 ; Put actual ULC value into CL
  167.     mov    ULCol,CX
  168.         dec     CX                      ; Adjust for BASIC screen definitions
  169.         shl     CX,1                    ; Remember there are 2 bytes / position
  170.  
  171.         mov     BX,ULR                  ; Put address of the ULR value into BX
  172.         mov     AX,[BX]                 ; Put the ULR value into AX
  173.     mov    ULRow,AX
  174.         dec     AX                      ; Adjust for BASIC screen definitions
  175.         mov     DX,160                  ; Multiply by # bytes per row
  176.     mul    DL
  177.         add     AX,CX                   ; Here,AX = total offset to start of box
  178.         mov     SI,CX                   ; CX = column displacement only
  179.  
  180.         mov     BX,LRC                  ; Repeat proc for Lower left corner
  181.     mov    CX,[BX]
  182.     mov    LRCol,CX
  183.     dec    CX
  184.     shl    CX,1
  185.     sub    CX,SI
  186.     shr    CX,1
  187.     push    CX
  188.  
  189.         mov     SI,AX                   ; Here, SI = total offset to box start
  190.     mov    BX,LRR
  191.     mov    AX,[BX]
  192.     mov    LRRow,AX
  193.     dec    AX
  194.     mov    DX,160
  195.     mul    DL
  196.     dec    AX
  197.     push    AX
  198.  
  199.     mov    BX,WATTRIB
  200.     mov    AX,[BX]
  201.         mov     BH,AL                   ; Put Window Attrib value into BH for scroll
  202.     cmp    AX,0
  203.     je    NoClearFirst
  204.  
  205.         push    CX
  206.     mov    DX,LRCol
  207.     dec    DX
  208.     mov    AX,LRRow
  209.     dec    AX
  210.         mov     DH,AL                   ; DH:DL = LRR:LRC
  211.     mov    CX,ULCol
  212.     dec    CL
  213.     mov    AX,ULRow
  214.     dec    AL
  215.         mov     CH,AL                   ; CH:CL = ULR:ULC
  216.         mov     AX,0700h                ; Prepare for scroll down entire window
  217.     int    10h
  218.  
  219.     pop    CX
  220.  
  221. NoClearFirst:
  222.  
  223.     mov    BX,BATTRIB
  224.     mov    AX,[BX]         ; Now the color attrib is in AL
  225.  
  226.     mov    DX,0B800h        ; Address of Video RAM memory
  227.     mov    ES,DX
  228.     mov    DI,SI
  229.  
  230.     push    AX
  231.     mov    AX,HLine
  232.         mov     DL,AL                   ; Load box drawing chars
  233.     mov    AX, VLine
  234.     mov    DH,AL
  235.     mov    AX,UlcChar
  236.     mov    BH,AL
  237.     mov    AX,UrcChar
  238.     mov    BL,AL
  239.     pop    AX
  240.  
  241.     pop    SI
  242.     push    SI
  243.     cmp    SI,DI
  244.     jne    STEP_ONE
  245.     mov    BH,DL
  246.     mov    BL,DL
  247.  
  248. Step_One:
  249.  
  250.     mov    SI,DI
  251.     mov    ES:[SI],BH
  252.     jmp    short    Step_Three
  253.  
  254. Step_Two:
  255.  
  256.     mov    ES:[SI],DL
  257.  
  258. Step_Three:
  259.  
  260.     inc    SI
  261.     cmp    AL,0
  262.     je    Step_Four
  263.     mov    ES:[SI],AL
  264.  
  265. Step_Four:
  266.  
  267.     inc    SI
  268.     loop    Step_Two
  269.     mov    ES:[SI],BL
  270.     inc    SI
  271.     cmp    AL,0
  272.     je    Step_Five
  273.     mov    ES:[SI],AL
  274.  
  275. Step_Five:
  276.  
  277.     pop    BX
  278.     pop    CX
  279.     cmp    SI,BX
  280.     jge    DrawBox_Exit
  281.  
  282. Step_Six:
  283.  
  284.     add    DI,160
  285.     mov    SI,DI
  286.     cmp    SI,BX
  287.     jge    Step_Ten
  288.  
  289. Step_Seven:
  290.  
  291.     mov    ES:[SI],DH
  292.     inc    SI
  293.     cmp    AL,0
  294.     je    Step_Eight
  295.     mov    ES:[SI],AL
  296.  
  297. Step_Eight:
  298.  
  299.     dec    SI
  300.     add    SI,CX
  301.     add    SI,CX
  302.     mov    ES:[SI],DH
  303.     inc    SI
  304.     cmp    AL,0
  305.     je    Step_Nine
  306.     mov    ES:[SI],AL
  307.  
  308. Step_Nine:
  309.  
  310.     jmp    short    Step_Six
  311.  
  312. Step_Ten:
  313.     push    AX
  314.     mov    AX,LlcChar
  315.     mov    BH,AL
  316.     mov    AX,LrcChar
  317.     mov    BL,AL
  318.     pop    AX
  319.  
  320. Step_Eleven:
  321.  
  322.     push    BX
  323.     push    CX
  324.     jmp    short    Step_One
  325.  
  326. DrawBox_Exit:
  327.  
  328.     mov    BX,SHADOW
  329.     mov    AX,[BX]
  330.     cmp    AX,0
  331.     je    LeaveDrawBox
  332.  
  333.         mov     CX,ULCol                ; Put COLUMN value into CX (do NOT adjust, since we want 1 column to the right)
  334.         shl     CX,1                    ;       and for 2 bytes per position
  335.  
  336.         mov     AX,LRRow                ; Put ROW value into AX
  337.         mov     DX,160                  
  338.         mul     DL                      ; Multiply AX by # bytes per ROW
  339.         add     AX,CX                   ;       and add in the COLUMN offset
  340.  
  341.         mov     SI,AX                   ; SI = screen position to start at, but
  342.         inc     SI                      ;       add 1 to skip over char to attrib.
  343.  
  344.     mov    CX,LRCol
  345.     mov    AX,ULCol
  346.         sub     CX,AX                   ; CX = length of row to change
  347.         mov     AL,08                   ; AL now has the color attribute
  348.     inc    CX
  349.     inc    CX
  350.  
  351.         mov     DX,0B800h               ; Put address of Video RAM into DX, and from there,
  352.         mov     ES,DX                   ;       into ES register
  353.  
  354. ChangeDBottom:
  355.  
  356.         mov     ES:[SI],AL              ; Put new color attrib onto screen
  357.     inc    SI
  358.         inc     SI                      ; Skip over char to next attrib byte
  359.         loop    ChangeDBottom
  360.  
  361.     mov    AX,LRCol
  362.     mov    DL,AL
  363.     mov    AX,ULRow
  364.         mov     DH,AL                   ; Row and Column are in DH:DL
  365.     mov    CX,LRRow
  366.     sub    CX,AX
  367.     inc    CX
  368.  
  369. DoShadowDEdge:
  370.  
  371.     mov    AH,02
  372.     xor    BH,BH
  373.         int     10h                     ; SetCursorPosition in BIOS
  374.  
  375.     mov    AH,08
  376.         int     10h                     ; Read Char W/attribute at cursor
  377.  
  378.         mov     BL,08                   ; Put color attribute into BL
  379.     mov    AH,09
  380.         push    CX
  381.     mov    CX,01
  382.     int    10h
  383.  
  384.     inc    DL
  385.     mov    AH,02
  386.     xor    BH,BH
  387.         int     10h                     ; SetCursorPosition in BIOS
  388.  
  389.     mov    AH,08
  390.         int     10h                     ; Read Char W/attribute at cursor
  391.     mov    BL,08
  392.     mov    AH,09
  393.     int    10h
  394.  
  395.     pop    CX
  396.     dec    DL
  397.     inc    DH
  398.         loop    DoShadowDEdge
  399.  
  400. LeaveDrawBox:
  401.  
  402.     ret
  403.  
  404. DrawBox     ENDP
  405.  
  406.         END
  407.  
  408. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++