home *** CD-ROM | disk | FTP | other *** search
/ Colossal Cookbook / ColossalCookbook.cdr / misc / qb_box.zip / QB-BOX.ASM
Assembly Source File  |  1991-09-06  |  9KB  |  231 lines

  1. ; BOX0 - Copyright (c) 1989 by Chris May           (3/1/1989)
  2. ;┌──────────────────────────────────────────────────────────┐
  3. ;│ Subroutine to draw a Box on screen (writes to page zero) │
  4. ;│                                                          │
  5. ;│ Call Box0(ULRow%, ULCol%, LRRow%, LRCol%, Char%, Colr%)  │
  6. ;│                                                          │
  7. ;└──────────────────────────────────────────────────────────┘
  8.  
  9. ULRow EQU [BP+16]    ;upper left row
  10. ULCol EQU [BP+14]    ;upper left column
  11. LRRow EQU [BP+12]    ;lower right row
  12. LRCol EQU [BP+10]    ;lower right column
  13. Char  EQU [BP+08]    ;character to use
  14.                      ;  1 = single line                            
  15.                      ;  2 = double line                           
  16.                      ;  3 = double horiz line, single vert         
  17.                      ;  4 = double vert line, single horiz         
  18.                      ;  or ASCII code of character to use          
  19. Colr  EQU [BP+06]    ;box color, or -1 to use default
  20.  
  21. .MODEL medium
  22.  
  23. .DATA
  24.  
  25.    VLine           DB    ?    ;vertical line character
  26.    HLine           DB    ?    ;horizontal line character
  27.    TLC             DB    ?    ;top left corner character
  28.    TRC             DB    ?    ;top right corner character
  29.    BLC             DB    ?    ;bottom left corner character
  30.    BRC             DB    ?    ;bottom right corner character
  31.    Vert_Length     DW    ?    ; = LRRow - ULRow - 1
  32.    Horiz_Length    DW    ?    ; = LRCol - ULCol - 1
  33.    TLC_POS         DW    ?    ; = (ULRow - 1) * LineSize + ULCol + ULCol
  34.    BLC_POS         DW    ?    ; = (LRRow - 1) * LineSize + ULCol + ULCol
  35.    LineSize        DW    ?    ;length of a line in the current screen mode
  36.  
  37.    Extrn MonSeg:   Word       ;these are in Monitor.Asm
  38.    Extrn CGAPort:  Word
  39.  
  40. .CODE
  41.  
  42.    Extrn Monitor:  Proc       ;so we can access monitor type
  43.    Extrn StosbSub: Proc
  44.    Extrn StoswSub: Proc
  45.  
  46. Public Box0
  47. Box0 Proc Far
  48.  
  49.    Push   BP
  50.    Mov    BP,SP
  51.  
  52.    Cmp    MonSeg,0            ;has Monitor been used yet?
  53.    Jnz    MonOkay             ;yes, skip ahead
  54.    Call   Monitor             ;no, call it to set segment and retrace words
  55.  
  56. MonOkay:
  57.  
  58.    Mov    AH,0Fh              ;get the video mode through BIOS
  59.    Push   BP                  ;some old PC BIOS's trash BP during an Int10h
  60.    Int    10h                 ;returns current page in BH, columns in AH
  61.    Pop    BP                  ;restore BP
  62.    Mov    AL,AH               ;but we need the columns to be in AL
  63.    Add    AL,AL               ;double the width for the calculations below
  64.    Xor    AH,AH               ;make it a word
  65.    Mov    LineSize,AX         ;and remember it for later
  66.  
  67.    Mov    CX,MonSeg
  68.    Mov    ES,CX               ;destination address in ES
  69.  
  70.    Mov    SI,Char             ;get character to use
  71.    Mov    AH,[SI]
  72.    Cmp    AH,1                ;see if single line
  73.    Jne    Double_Line         ;no, see if double line
  74.    Mov    HLine,196           ;single line horizontal
  75.    Mov    VLine,179           ;single line vertical
  76.    Mov    TLC,218             ;top left corner
  77.    Mov    TRC,191             ;top right corner
  78.    Mov    BLC,192             ;bottom left corner
  79.    Mov    BRC,217             ;bottom right corner
  80.    Jmp    Calculate_Box
  81.  
  82. Double_Line:
  83.  
  84.    Cmp    AH,2                ;see if double line
  85.    Jne    DHSV_Line           ;no, see if double horiz, single vert
  86.    Mov    HLine,205           ;double line horizontal
  87.    Mov    VLine,186           ;double line vertical
  88.    Mov    TLC,201             ;top left corner
  89.    Mov    TRC,187             ;top right corner
  90.    Mov    BLC,200             ;bottom left corner
  91.    Mov    BRC,188             ;bottom right corner
  92.    Jmp    Short Calculate_Box
  93.  
  94. DHSV_Line:
  95.  
  96.    Cmp    AH,3                ;see if double horiz line, single vert
  97.    Jne    DVSH_Line           ;no, see if double vertical single horiz
  98.    Mov    HLine,205           ;double line horizontal
  99.    Mov    VLine,179           ;single line vertical
  100.    Mov    TLC,213             ;top left corner
  101.    Mov    TRC,184             ;top right corner
  102.    Mov    BLC,212             ;bottom left corner
  103.    Mov    BRC,190             ;bottom right corner
  104.    Jmp    Short Calculate_Box
  105.  
  106. DVSH_Line:
  107.  
  108.    Cmp    AH,4                ;see if double line
  109.    Jne    Use_ASCII           ;no, use passed character
  110.    Mov    HLine,196           ;single line horizontal
  111.    Mov    VLine,186           ;double line vertical
  112.    Mov    TLC,214             ;top left corner
  113.    Mov    TRC,183             ;top right corner
  114.    Mov    BLC,211             ;bottom left corner
  115.    Mov    BRC,189             ;bottom right corner
  116.    Jmp    Short Calculate_Box
  117.  
  118. Use_ASCII:
  119.  
  120.    Mov    HLine,AH            ;use ASCII value passed
  121.    Mov    VLine,AH
  122.    Mov    TLC,AH              ;upper left corner
  123.    Mov    TRC,AH              ;upper right corner
  124.    Mov    BLC,AH              ;bottom left corner
  125.    Mov    BRC,AH              ;bottom right corner
  126.  
  127. Calculate_Box:
  128.  
  129.    Mov    SI,LRRow            ;point to lower right row
  130.    Mov    AX,[SI]
  131.    Dec    AX                  ;convert 1-25 into 0-24
  132.    Mov    CX,AX               ;save for later determination of Vert_Length
  133.    Mov    DX,LineSize         ;number of bytes per line
  134.    Mul    DL                  ;convert row to offset
  135.    Mov    BLC_POS,AX
  136.    Mov    SI,ULRow            ;point to upper left row
  137.    Mov    AX,[SI]
  138.    Dec    AX                  ;convert 1-25 into 0-24
  139.    Sub    CX,AX
  140.    Dec    CX
  141.    Mov    Vert_Length,CX      ;length of vertical line
  142.    Mov    DX,LineSize         ;number of bytes per line
  143.    Mul    DL                  ;convert row to offset
  144.    Mov    TLC_POS,AX
  145.    Mov    SI,LRCol            ;point to lower right column
  146.    Mov    CX,[SI]
  147.    Dec    CX                  ;convert 1-80 into 0-79
  148.    Mov    SI,ULCol            ;point to upper left column
  149.    Mov    BX,[SI]
  150.    Sub    CX,BX
  151.    Mov    Horiz_Length,CX     ;length of horizontal line
  152.    Dec    BX                  ;convert 1-80 into 0-79
  153.    Add    BX,BX
  154.    Add    TLC_POS,BX
  155.    Add    BLC_POS,BX
  156.  
  157.    Mov    SI,Colr             ;get color of box
  158.    Mov    AH,[SI]             ;put in AH
  159.    Mov    DI,TLC_POS          ;set to top left corner destination
  160.    Mov    AL,TLC              ;load top left corner
  161.    Cld                        ;operations in forward direction
  162.    Call   Box0_Stosw          ;put it on screen
  163.  
  164.    Mov    AL,HLine            ;load horizontal line character
  165.    Mov    CX,Horiz_Length     ;load length of line
  166.  
  167. Repeat1:
  168.  
  169.    Call   Box0_Stosw          ;put it on screen
  170.    Loop   Repeat1             ;CX times
  171.  
  172.    Mov    AL,TRC              ;load top right corner
  173.    Call   Box0_Stosw          ;put it on screen
  174.  
  175.    Mov    AL,VLine            ;load vertical line character
  176.    Mov    DX,TLC_POS          ;set to top left destination again
  177.    Mov    CX,Vert_Length      ;no. of rows to be done
  178.  
  179. Sides:
  180.  
  181.    Add    DX,LineSize         ;get next row
  182.    Mov    DI,DX               ;load it
  183.    Call   Box0_Stosw          ;put left side on screen
  184.    Add    DI,Horiz_Length     ;once for character
  185.    Add    DI,Horiz_Length     ;once for attribute
  186.    Call   Box0_Stosw          ;put right side on screen
  187.    Loop   Sides               ;do CX times
  188.  
  189.    Mov    AL,BLC              ;load bottom left corner
  190.    Mov    DI,BLC_POS          ;load position of corner
  191.    Call   Box0_Stosw          ;put it on screen
  192.  
  193.    Mov    AL,HLine            ;load horizontal line character
  194.    Mov    CX,Horiz_Length     ;load length of line
  195.  
  196. Repeat2:
  197.  
  198.    Call   Box0_Stosw          ;put it on screen
  199.    Loop   Repeat2             ;CX times
  200.  
  201.    Mov    AL,BRC              ;load top right corner
  202.    Call   Box0_Stosw          ;put it on screen
  203.  
  204.    Pop    BP
  205.    Ret    12
  206.  
  207. ;----------------------------------------------------------------------------
  208. Box0_Stosw Proc Near
  209.  
  210.    Push   DX                  ;save DX on stack
  211.    Mov    DX,CGAPort          ;put port to check in DX
  212.    Cmp    AH,0FFh             ;are we using the colors already on the screen?
  213.    Jnz    DoColor             ;no, then do color
  214.  
  215.    Call   StosbSub            ;put byte on screen
  216.    Inc    DI                  ;skip over the color byte
  217.    Pop    DX                  ;restore contents of DX
  218.    Ret
  219.  
  220. DoColor:
  221.  
  222.    Call   StoswSub            ;put word on screen
  223.    Pop    DX
  224.    Ret
  225.  
  226. Box0_Stosw EndP
  227. ;----------------------------------------------------------------------------
  228. Box0 EndP
  229. End
  230.  
  231.