home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / VIDBASIC.ZIP / VCLEARA.ASM < prev    next >
Assembly Source File  |  1990-11-29  |  16KB  |  545 lines

  1. ;«RM83»«TS8,16,24,32,40,48»
  2. ; Updated 11/20/90
  3.  
  4. ;============================================================================
  5. ;   Copyright (C) Copr. 1990 by Sidney J. Kelly
  6. ;           All Rights Reserved.
  7. ;           Sidney J. Kelly
  8. ;           150 Woodhaven Drive
  9. ;           Pittsburgh, PA 15228
  10. ;           home phone 412-561-0950 (7pm to 9:30pm EST)
  11. ;============================================================================
  12.  
  13. DOSSEG
  14. .MODEL MEDIUM, BASIC
  15.  
  16. .data
  17.     ;external data so all video routines can access
  18.     EVEN
  19.     EXTRN  B$DVIDEOSEG:WORD
  20.     EXTRN  B$DVIDEOPORT:WORD
  21.     EXTRN  B$DVIDEOINSTL:BYTE
  22. .code
  23.  
  24. INCLUDE  NOWAIT.INC
  25. EXTRN    Get_Adapter:FAR
  26.  
  27. comment         |
  28. Calc_DI_Offset_Addr  macro
  29.     ;; standard routine
  30.     ;; Note destroys AX, BX, CL
  31.     ;;               ;8086  ;80286
  32.     Mov   AX,CurrRow   ;14     ;5
  33.     Dec   AX           ;3      ;2   ;;change from 1-25 to 0-24
  34.     Mov   cl,160       ;4      ;2
  35.     Mul   cl           ;77     ;13  ;;multiply CurrRow by 160
  36.     Mov   BX,BegCol    ;14     ;5   ;;get starting column
  37.     Dec   BX           ;3      ;2   ;;change from 1-80 to 0-79
  38.     Shl   BX,1         ;2      ;2   ;;multiply (CurrRow-1) by 2
  39.     Add   AX,BX        ;3      ;2   ;;get offset
  40.     Mov   DI,AX        ;3      ;2   ;;move to source index
  41.     endm               ;---------
  42.                ;123    ;35  ;;clocks
  43.         |
  44.  
  45. Calc_DI_Offset_Addr    macro
  46.     ;; This is slightly slower in the abstract
  47.     ;; sense on a 80286.  Cannot observe the difference
  48.     ;; on a 8088 with a CGA because of delay waiting for retrace.
  49.     ;; Though if have an 8088 with MONO or VGA/EGA it is faster
  50.     ;;
  51.     ;; Input:     Nothing
  52.     ;; Output:    DI = Memory Offset
  53.     ;; Destroys:  CX,AX
  54.     ;; Macro is used because inline code speeds routine
  55.     ;;               ;8088 ;80286
  56.     Xor     CL, CL     ;3    ;2   ;; Clear CL
  57.     Mov     AX,CurrRow ;14   ;5   ;; get starting Row
  58.     Dec     AX         ;3    ;2   ;; change from 1-25 to 0-24
  59.     Mov     CH, AL     ;2    ;2   ;; CX = Row * 256
  60.     Shr     CX, 1      ;2    ;2   ;; CX = Row * 128
  61.     Mov     DI, CX     ;2    ;2   ;; Store in DI
  62.     Shr     DI, 1      ;2    ;2   ;; DI = Row * 64
  63.     Shr     DI, 1      ;2    ;2   ;; DI = Row * 32
  64.     Add     DI, CX     ;3    ;2   ;; DI = (Row * 128)+(Row * 32)={Row*160}
  65.     Xor     CH, CH     ;3    ;2   ;; Clear CH register
  66.     Mov     AX,BegCol  ;14   ;5   ;; get starting Column
  67.     Dec     AX         ;3    ;2   ;; change from 1-80 to 0-79
  68.     Mov     CL, AL     ;2    ;2   ;; CX = Columns
  69.     Shl     CX, 1      ;2    ;2   ;; Account for attribute
  70.     Add     DI, CX     ;3    ;2   ;; DI = (Row * 160) + (Col * 2)
  71.               ;--------
  72.       endm                ;60    ;36  ;; clocks
  73.  
  74. .code
  75. ;=====================Some data variables==================================
  76. ;         Stored in Code segment to save space in DGROUP
  77.  
  78. EVEN
  79. CurrRow        DW    0           ;current CurrRow
  80. BegCol         DW    0           ;Starting Column
  81. Num_Cols       DW    0           ;words to copy per line
  82. EndingRow      DW    0           ;Ending Row
  83. BACKCOLOR      DW    0           ;store shadow color for MAKEBOXES
  84. Color          DB    0           ;Store color attribute
  85.  
  86.  
  87. ;===========================================================================
  88. ; DECLARE SUB
  89. ; CLEARAREA (BYVAL ULR%, BYVAL ULC%, BYVAL LRR%, BYVAL LRC%, BYVAL ATTRIB%)
  90. ; CALL CLEARAREA (ULR%, ULC%, LRR%, LRC%, ATTRIB%)
  91. ; Changes the attribute of an area on the screen in text mode
  92. ;===========================================================================
  93.  
  94. EVEN
  95. CLEARAREA Proc FAR BASIC USES SI DI, \
  96. ULR:Word, ULC:Word, LRR:Word, LRC:Word, ATTRIB:Word
  97.  
  98. comment |
  99.     Register usage when all done:
  100.     AH = Color attribute to change line to
  101.     AL = loading point for STOB, scratch.
  102.     CX = Number of characters to change on a line.
  103.     DX = Port for CGA video retrace check, if necessary.
  104.         0 means display is not a not a CGA display
  105.     DI = Offset of Screen for current character
  106.     ES = Segment of Video display, 0xB000 or 0xB800
  107.     BX = is used as a scratch variable register
  108.     DS & SI are not changed
  109.      |
  110.  
  111.     Cmp   B$DVIDEOINSTL,1
  112.     JE    Didit
  113.     Call  Get_Adapter       ;determine the display type routine
  114. Didit:
  115.     Mov   ES,B$DVIDEOSEG    ;store Video Segment in ES
  116.     Mov   DX,B$DVIDEOPORT   ;Get B$VDIDEOPORT
  117.  
  118.     Mov   BX,ULC           ;get first column
  119.     Mov   BegCol,BX
  120.  
  121.     Mov   BX,LRC           ;get last column
  122.     Cmp   BX,80
  123.     JBE   @f
  124.     Mov   BX,80            ; make sure right margin not > 80
  125.                    ; so no wrap around on left margin
  126. @@:
  127.     Sub   BX,BegCol        ;subtract last column from first column
  128.     Inc   BX               ;add 1 to get number of columns to print
  129.     Mov   Num_Cols,BX      ;BX equals number of words to copy per line
  130.  
  131.     Mov   BX,LRR           ;get last line
  132.     Mov   EndingRow,BX
  133.  
  134.     Mov   BX,ULR           ;get first line
  135.     Mov   CurrRow,BX       ;set current row to first line
  136.  
  137.     Calc_DI_Offset_Addr    ;calculate offset for line MACRO
  138.     Mov   CX,Num_Cols      ;load counter with words to copy
  139.     JCXZ  Exit2            ;if CX is zero it's a zero length line
  140.                    ;so exit now
  141.  
  142.     Mov   BX,ATTRIB        ;get the color ATTRIBUTE% that was passed
  143.     Mov   AX,BX            ;put it into AH for screen writing below
  144.     Mov   Color,AL
  145.     Cld                    ;clear the direction flag to move data forward
  146. EVEN
  147. Main2:
  148.     Mov   AH,Color         ;get attribute & put it in AH
  149.     Mov   AL,AH            ;get attribute & put it in AL
  150.     Or    DL,DL            ;are we on a mono or EGA system?
  151.     JZ    Mono2            ;yes, skip over the retrace stuff
  152. EVEN
  153. CGA2:
  154.     CLI                    ;prevent hardware interrupts
  155.     Wait_CGA_Retrace       ;wait for retrace on CGA MACRO
  156.     Mov   AL,AH            ;get attribute & put it in AL
  157.     Inc   DI
  158.     Stosb                  ;store the attribute
  159.     STI                    ;allow interrupts again
  160.     Loop  CGA2             ;loop until CX is zero
  161.     Jmp  Short Next_Line2
  162. EVEN
  163. Mono2:
  164.     Inc   DI               ;the increment before store allows one
  165.                    ;to change just the color attribute
  166.     Stosb                  ;store the attribute
  167.     Loop  Mono2            ;loop until CX is zero
  168. Next_Line2:
  169.     Mov   AX,EndingRow
  170.     Cmp   AX,CurrRow       ;Are we done restoring window?
  171.     Je    Exit2            ;exit if complete
  172.     INC   CurrRow          ;next line
  173.     Calc_DI_Offset_Addr    ;compute new offset address MACRO
  174.     Mov   CX,Num_Cols      ;set counter to # of words to copy
  175.     JMP Short Main2        ;jump to print next line
  176. Exit2:
  177.     Ret                    ;return skipping the passed parameters
  178. CLEARAREA   Endp
  179.  
  180. ;===========================================================================
  181. ; DECLARE SUB BACKFILL
  182. ;(BYVAL ULR%, BYVAL ULC%, BYVAL LRR%, BYVAL LRC%, BYVAL ATTRIB%, BYVAL TEXTCHAR%)
  183. ; CALL BACKFILL(ULR%, ULC%, LRR%, LRC%, ATTRIB%, TEXT$)
  184. ; Fills the display area with a character and a fixed text attribute
  185. ;===========================================================================
  186.  
  187. EVEN
  188. BACKFILL Proc FAR BASIC USES DI SI, \
  189. ULR:Word, ULC:Word, LRR:Word, LRC:Word, ATTRIB:Word, TEXTS:Word
  190.  
  191. comment |
  192.     Register usage when all done:
  193.     AH = Color attribute to change line to
  194.     AL = loading point for text character.
  195.     CX = Number of characters to change on a line.
  196.     DX = Port for CGA video retrace check, if necessary.
  197.          0 means display is not a not a CGA display
  198.     DI = Offset of Screen for current character
  199.     ES = Segment of Video display, 0xB000 or 0xB800
  200.     BX = is used as a scratch variable register
  201.     SI = holds the text & character attribute
  202.     DS  is not changed
  203.      |
  204.  
  205.     Cmp   B$DVIDEOINSTL,1
  206.     JE    Didit1
  207.     Call Get_Adapter        ;determine the display type routine
  208.  
  209. Didit1:
  210.     Mov   ES,B$DVIDEOSEG    ;store Video Segment in ES
  211.     Mov   DX,B$DVIDEOPORT   ;Get B$VDIDEOPORT
  212.  
  213.     Mov   BX,ULC           ;get first column
  214.     Mov   BegCol,BX
  215.  
  216.     Mov   BX,LRC           ;get last column
  217.     Cmp   BX,80
  218.     JBE   @f
  219.     Mov   BX,80            ; make sure right margin not > 80
  220.                    ; so no wrap around on left margin
  221. @@:
  222.     Sub   BX,BegCol        ;subtract first column from last column
  223.     Inc   BX               ;add 1 to get number of columns to print
  224.     Mov   Num_Cols,BX      ;BX equals number of words to copy per line
  225.  
  226.     Mov   BX,LRR           ;get last line
  227.     Mov   EndingRow,BX     ;store in EndingRow
  228.  
  229.     Mov   BX,ULR           ;get first line and
  230.     Mov   CurrRow,BX       ;store in CurrRow
  231.  
  232.     Calc_DI_Offset_Addr    ;calculate offset for line MACRO
  233.     Mov   CX,Num_Cols      ;load counter with words to copy
  234.     JCXZ  Exit3            ;if CX is zero it's a zero length line
  235.                    ;so exit now
  236.  
  237.     Mov   BX,ATTRIB        ;get the color ATTRIBUTE% that was passed
  238.     Mov   Color,BL         ;store BL temporarily in Color
  239.     Mov   BX,TEXTS         ;get text string character#
  240.     Or    BX,BX            ;see if string character is &H00
  241.     JZ    Exit3            ;it is zero so exit
  242.     Mov   AX,BX            ;store in AX
  243.     Mov   AH,Color         ;add Color to AH
  244.     Mov   SI,AX            ;store text & attribute in SI
  245.     Cld                    ;clear the direction flag to move data forward
  246. EVEN
  247. Main3:
  248.     Mov   AX,SI            ;get attribute & text chr# & put it in AX
  249.     Or    DL,DL            ;are we on a mono or EGA system (is DL = 0)?
  250.     JZ    Mono3            ;yes, skip over the retrace stuff
  251. EVEN
  252. CGA3:
  253.     CLI                    ;prevent hardware interrupts
  254.     Wait_CGA_Retrace       ;wait for CGA retrace MACRO
  255.     Mov  AX,SI             ;reload Attribute & Text$
  256.     Stosw
  257.     STI                    ;allow interrupts again
  258.     Loop  CGA3             ;loop until CX is zero
  259.     Jmp  Short Next_Line3
  260.  
  261. Mono3:
  262.     Rep Stosw              ;store the attribute & text$
  263.  
  264. Next_Line3:
  265.     Mov   AX,EndingRow
  266.     Cmp   AX,CurrRow       ;Are we done restoring window?
  267.     Je    Exit3            ;exit if complete
  268.     INC   CurrRow          ;next line
  269.     Calc_DI_Offset_Addr    ;compute new offset address MACRO
  270.     Mov   CX,Num_Cols      ;set counter to # of words to copy
  271.     JMP Short Main3        ;jump to print next line
  272. Exit3:
  273.     Ret                    ;return skipping the passed parameters
  274. BACKFILL   Endp
  275.  
  276. ;============================================================================
  277. ;DECLARE SUB MAKEBOXES _
  278. ;(BYVAL ULR%, BYVAL ULC%, BYVAL LRR%, BYVAL LRC%, BYVAL HASNO%, BYVAL BORDER%,_
  279. ; BYVAL ATTRIB%)
  280. ;CALL MAKEBOXES(ULR,ULC,LRR,LRC,HASHNO,BORDER,ATTRIB)
  281. ;
  282. ; Somewhat shorter and 1.0076 times faster than using the primitives
  283. ; in this .OBJ file to do the same thing
  284. ;============================================================================
  285. EVEN
  286. BOXD        LABEL    WORD
  287.         DB    '═║╔╗╚╝'
  288. BOXS        LABEL    WORD
  289.         DB    '─│┌┐└┘'
  290. BOXSVDH        LABEL    WORD
  291.         DB    '═│╒╕╘╛'
  292. BOXSHDV        LABEL    WORD
  293.         DB    '─║╓╖╙╜'
  294. BOXSOLID    LABEL    WORD
  295.         DB      '░░░░░░'
  296.  
  297. EVEN
  298. MAKEBOXES Proc FAR BASIC USES DS DI SI, \
  299. ULR:Word, ULC:Word, LRR:Word, LRC:Word, HASHNO:Word, BORDER:Word, ATTRIB:Word
  300.  
  301.     Mov     BX,HASHNO
  302.     Or      BX,BX
  303.     JZ      No_Background           ; no back fill so skip ahead
  304.  
  305. Fill_In_Background:
  306.     Mov     AX,BX                   ; push values on the stack
  307.     Mov     BX,ULR
  308.     Push    BX                      ; Push ULR
  309.     Mov     BX,ULC
  310.     Push    BX                      ; Push ULC
  311.     Mov     BX,LRR
  312.     Push    BX                      ; Push LRR
  313.     Mov     BX,LRC
  314.     Push    BX                      ; Push LRC
  315.     Mov     BX,ATTRIB
  316.     Push    BX                      ; push ATTRIB
  317.     Push    AX                      ; push the Hashno
  318.     CALL    BACKFILL
  319.  
  320. No_Background:                ; Draw Main Outline
  321.     Mov    BX,BORDER               ; see if we have a Border choice
  322.     Or    BL,BL                   ; if border not zero, do BORDER
  323.     JNZ    @f
  324.     JMP    DrawShadow              ; plain border
  325. @@:
  326.     Push    DS
  327.     Push    CS
  328.     Pop    DS
  329.  
  330.     ;Must keep this so the OFFSET is calculated correctly
  331.     Assume    ES:NOTHING, DS:NOTHING
  332.  
  333.         Cmp    BL,2
  334.     JNE    @f
  335.     Mov    SI,OFFSET BOXS        ; single sided
  336.     Jmp    Short    StartBorder
  337. @@:
  338.     Cmp    BL,3
  339.     JNE    @f
  340.     Mov    SI,OFFSET BOXSVDH       ; single vertical, double horizontal
  341.     Jmp    Short    StartBorder
  342. @@:
  343.     Cmp    BL,4
  344.     JNE    @f
  345.     Mov    SI,OFFSET BOXSHDV       ; double vertical, single horizontal
  346.         Jmp    Short    StartBorder
  347. @@:
  348.     Cmp    BL,5
  349.     JNE    @f
  350.     Mov    SI,OFFSET BOXSOLID      ; solid box
  351.         Jmp    Short    StartBorder
  352. @@:
  353.  
  354.         Mov    SI,OFFSET BOXD          ; default format, double sided
  355.  
  356. EVEN
  357. StartBorder:
  358.     Pop    DS                      ; reset DS to @data
  359.  
  360.     Assume    DS:@data
  361.  
  362.         ;Draw Top Row
  363.     Mov     BX,ULR
  364.     Push    BX                      ; Push ULR
  365.     Mov     BX,ULC
  366.     Push    BX                      ; Push ULC
  367.     Mov     BX,ULR
  368.     Push    BX                      ; Push ULR
  369.     Mov     BX,LRC
  370.     Push    BX                      ; Push LRC
  371.     Mov     BX,ATTRIB
  372.     Push    BX                      ; push ATTRIB
  373.     Mov     AL,CS:[SI]
  374.     Push    AX                      ; Push Top Row Character
  375.     CALL    BACKFILL
  376.  
  377.         ;Draw Left Side
  378.     Mov     BX,ULR
  379.     Push    BX                      ; Push ULR
  380.     Mov     BX,ULC
  381.     Push    BX
  382.     Mov     BX,LRR
  383.     Push    BX
  384.     Mov     BX,ULC
  385.     Push    BX
  386.     Mov     BX,ATTRIB
  387.     Push    BX                      ; Push ATTRIB
  388.     Mov     AL,CS:[SI+1]
  389.     Push    AX                      ; Push Bottom Row Character
  390.     CALL    BACKFILL
  391.  
  392.         ;Draw Right Side
  393.     Mov     BX,ULR
  394.     Push    BX
  395.     Mov     BX,LRC
  396.     Push    BX
  397.     Mov     BX,LRR
  398.     Push    BX
  399.     Mov     BX,LRC
  400.     Push    BX
  401.     Mov     BX,ATTRIB
  402.     Push    BX                      ; push ATTRIB
  403.     Mov     AL,CS:[SI+1]
  404.     Push    AX                      ; Push Right Side Character
  405.     CALL    BACKFILL
  406.  
  407.         ;Draw Bottom Row
  408.     Mov     BX,LRR
  409.     Push    BX
  410.     Mov     BX,ULC
  411.     Push    BX
  412.     Mov     BX,LRR
  413.     Push    BX
  414.     Mov     BX,LRC
  415.     Push    BX
  416.     Mov     BX,ATTRIB
  417.     Push    BX
  418.     Mov     AL,CS:[SI]
  419.     Push    AX
  420.     CALL    BACKFILL
  421.  
  422. ;Draw Border Edges
  423.         ;Draw Upper Left
  424.     Mov     BX,ULR
  425.     Mov     AX,BX
  426.     Push    BX
  427.     Mov     BX,ULC
  428.     Mov     CX,BX
  429.     Push    BX
  430.     Push    AX
  431.     Push    CX
  432.     Mov     BX,ATTRIB
  433.     Push    BX
  434.     Mov     AL,CS:[SI+2]
  435.     Push    AX
  436.     CALL    BACKFILL
  437.  
  438.         ;Draw Upper Right
  439.     Mov     BX,ULR
  440.     Mov     AX,BX
  441.     Push    BX
  442.     Mov     BX,LRC
  443.     Mov     CX,BX
  444.     Push    BX
  445.     Push    AX
  446.     Push    CX
  447.     Mov     BX,ATTRIB
  448.     Push    BX
  449.     Mov     AL,CS:[SI+3]
  450.     Push    AX
  451.     CALL    BACKFILL
  452.  
  453.         ;Draw Lower Right
  454.     Mov     BX,LRR
  455.     Mov     AX,BX
  456.     Push    BX
  457.     Mov     BX,LRC
  458.     Mov     CX,BX
  459.     Push    BX
  460.     Push    AX
  461.     Push    CX
  462.     Mov     BX,ATTRIB
  463.     Push    BX
  464.     Mov     AX,CS:[SI+5]
  465.     Push    AX
  466.     CALL    BACKFILL
  467.  
  468.         ;Draw Lower Left
  469.     Mov     BX,LRR
  470.     Mov     AX,BX
  471.     Push    BX
  472.     Mov     BX,ULC
  473.     Mov     CX,BX
  474.     Push    BX
  475.     Push    AX
  476.     Push    CX
  477.     Mov     BX,ATTRIB               ; push attribute
  478.     Push    BX
  479.     Mov     AL,CS:[SI+4]            ; draw bottom left
  480.     Push    AX
  481.     CALL    BACKFILL
  482.  
  483. DrawShadow:
  484. ;Select shadow color depending on MONO or COLOR display mode
  485.     Mov    BX,BORDER     ;get BORDER
  486.     Or    BH,BH         ;see if we must draw a Shadow
  487.     JZ      Quit          ;nope, so quit
  488.     Xor     BX,BX         ;set ES to Ram BIOS area
  489.     Mov     ES,BX
  490.     Mov     BX,ES:[0463h] ;look a port info stored in RAM bios
  491.                   ; at 0000:0463h
  492.     Mov     AX,17h        ;Assume a Mono Display
  493.     Cmp     BL,0B4h
  494.     Je      @f            ;test port address
  495.     Mov     AX,7          ;COLOR ADAPTER
  496. @@:
  497.     Mov     BACKCOLOR,AX  ;store shadow color
  498.     Mov     BX,LRC
  499.     Mov     CX,BX
  500.     Cmp     BX,77         ; can't draw a shadow if LRC > 77
  501.     JBE     @f
  502.     Jmp     Short  Quit
  503. @@:
  504.     Mov     BX,LRR
  505.     Mov     ES,BX         ; store temporarily in ES
  506.     Cmp     BX,24         ; can't draw a shadow if LRR >24
  507.     JBE     @f
  508.     Jmp     Short  Quit
  509. @@:
  510.         ;Draws bottom right shadow
  511.     Mov     BX,ULR
  512.     Inc     BX
  513.     Push    BX            ; push ULR+1
  514.     Inc     CX
  515.     Push    CX            ; push LRC+1
  516.     Mov     BX,ES
  517.     Inc     BX
  518.     Push    BX            ; push LRR+1
  519.     Inc     CX
  520.     Push    CX            ; push LRC+2
  521.     Mov     BX,BACKCOLOR
  522.     Push    BX
  523.     CALL    CLEARAREA
  524.  
  525.         ;draws bottom left shadow
  526.     Mov     BX,LRR
  527.     Inc     BX
  528.     Mov     CX,BX
  529.     Push    BX            ; push LRR+1
  530.     Mov     BX,ULC
  531.     Add     BX,2
  532.     Push    BX            ; push ULC+2
  533.     Push    CX            ; push LRR+1
  534.     Mov     BX,LRC
  535.     Inc     BX
  536.     Push    BX            ; push LRC+1
  537.     Mov     BX,BACKCOLOR
  538.     Push    BX            ; push shadow color
  539.     CALL    CLEARAREA
  540.  
  541. Quit:
  542.     Ret
  543. MAKEBOXES     ENDP
  544. END
  545.