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

  1. ;«RM82»«TS8,16,24,32,40,48,56,64»
  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. .data
  16.     ;external data so all video routines can access
  17.     EVEN
  18.     EXTRN   B$DVIDEOSEG:WORD
  19.     EXTRN   B$DVIDEOPORT:WORD
  20.     EXTRN    B$DVIDEODI:WORD
  21.     EXTRN   B$DVIDEOINSTL:BYTE
  22. .code
  23.  
  24. INCLUDE NOWAIT.INC
  25. EXTRN   Get_Adapter:FAR
  26. EXTRN    SET_DI:FAR
  27.  
  28. .code
  29. EVEN
  30. VPageSize    dw      3998       ; default page size of 80 x 25
  31. VDI_Reset    dw      3840       ; default offset of Row 25, col 1
  32. VAttrib      db      7          ; default color of white on black
  33. VRow         db      24         ; default number of rows  (0 bias)
  34. VColumn      db      79         ; default number of columns (0 bias)
  35.  
  36. ;===========================================================================
  37. ; DECLARE SUB SETQP (BYVAL ROW%, BYVAL COLL%, BYVAL Attribute%)
  38. ;         CALL SETQP(ROW%, COLL%, Attribute%)
  39. ; Purpose:
  40. ;         Initializes varibles, and sets DI to target address.  This is the 
  41. ; initialization routine for QPRINTL.  Selects the attribute used to
  42. ; scroll the display upward.
  43. ; Assumes that user wants to set page size to full size of current dsp
  44. ; such as 80 x 25, 80 x 43, or 80 x 50
  45. ;===========================================================================
  46.  
  47. EVEN
  48. SETQP PROC FAR BASIC USES SI DI, ROW:WORD, COLL:WORD, ATTRIB:WORD
  49.     Assume  DS:@data
  50.  
  51.     Cmp     B$DVIDEOINSTL,1 ;See if we have done this before
  52.     JE      Didit        ; yep, so skip ahead
  53.     Call    Get_Adapter  ; call routine to find display type
  54.  
  55. Didit:
  56.     Mov     BX,ATTRIB    ; read attribute from stack
  57.     Or      BL,BL        ; make sure that BL <> 0
  58.     JNZ     @f           ; if BL <> 0 then skip ahead
  59.     Mov     BX,7         ; else give normal attribute
  60. @@:
  61.     Mov     VAttrib,BL   ; store attribute
  62.     Mov     BX,ROW       ; read value of Row
  63.     Dec     BX           ; convert to BIOS format
  64.     Cmp     BX,24        ; check if within range 1 to 25
  65.     JBE     @f           ; if w/in bounds o.k.
  66.     Xor    BL,BL        ; else make it Row 1
  67. @@:
  68.     Mov     DH,BL        ; store ROW (BL) in DH
  69.  
  70.     Mov     BX,COLL
  71.     Dec     BX           ; convert to BIOS format
  72.     Cmp     BX,79        ; check if within range 1 to 80
  73.     JBE     @f           ; if w/in bounds o.k.
  74.     Xor    BL,BL         ; else make it Column 1
  75. @@:    
  76.     Mov    DL,BL        ; store COLL (BL) in DL
  77.  
  78.     CALL    SET_DI       ; call routine to find video seg offset in DI
  79.     Mov     B$DVIDEODI,DI ; store DI
  80.  
  81.     Xor     AX,AX        ; read current bios values
  82.     Mov     ES,AX        ; set ES to BIOS ram area
  83.     Xor     BH,BH        ; clear high byte
  84.     Mov     BL,Byte Ptr ES:[0484h]  ; read ROW from BIOS ram
  85.     Or      BL,BL        ; is ROW 0? (i.e. is this CGA, HERC or MONO?)
  86.     JNZ     @f           ; nope, it is a EGA, MCGA or VGA
  87.     Mov     BL,24        ; set default ROW to 24
  88. @@:
  89.     Mov     VRow,BL      ; store number of ROW
  90.     Inc     BL           ; remove 0 bias of ROW
  91.     Mov     AX,ES:[044Ah]; read COLUMN from BIOS ram
  92.     Dec     AL           ; make it zero biased
  93.     Mov     VColumn,AL   ; store number of columns with 0 bias
  94.     Inc     AL           ; remove zero bias
  95.     Mul     BX           ; multiply ROW times COLUMN
  96.     Add     AX,AX        ; multiply AX by 2  (3 clocks on 8088)
  97.     Sub     AX,2         ; reduce by 2       (3 clocks on 8088)
  98.     Mov     VPageSize,AX ; store Page_Size in memory
  99.     Xor     AH,AH        ; clear AH
  100.     Mov     BH,AH        ; also clear BH
  101.     Mov     AL,VRow      ; get row in AL (it is 0 biased)
  102.                  ; the following shows the work necessary
  103.                  ; if you allow display widths other than 80
  104.     Mov     BL,VColumn   ; load number of columns into BL
  105.     Inc     BL           ; remove zero bias
  106.     Add     BX,BX        ; multipy Column times 2
  107.     Mul     BX           ; multiply Rows * (Columns * 2)
  108.     Mov     VDI_Reset,AX ; store result from AX in VDI_Reset
  109.                  ; this is offset of Last line, Column 1
  110.     Ret
  111. SETQP ENDP
  112.  
  113.  
  114. ;===========================================================================
  115. ; DECLARE SUB QPRINTL (Text$)
  116. ;         CALL QPRINTL(Text$)
  117. ; Usage: CALL SETQP(ROW%, COLL%, Attribute%) the first time to set
  118. ; the defaults to current display size.  Then QPRINTL on down the display.
  119. ; You should use SETQP to start, since scroll routine needs the proper
  120. ; attribute to scroll the screen up.
  121. ;
  122. ; Purpose:
  123. ;         To work similarly to PRINT Text$;
  124. ;
  125. ;         Major differences are:
  126. ;         a)  Assumes that a VIEW PRINT has been executed
  127. ;         b)  will not parse the Text$ and start a new line if length of
  128. ;           Text$ is longer than remaining space on current line.  PRINT
  129. ;           is designed for formatted column printing, while this
  130. ;           routine is not.
  131. ;         c) if at Last Row, Column 80, QPRINTL will scroll the display
  132. ;            can't stop it.
  133. ;
  134. ; Speed:
  135. ;       Varies with length of Text$ and length of display
  136. ;         for a color EGA on a 10 Mhz AT, the speed varies from 3% faster
  137. ;         (if LEN(Text$) = 80) to 48% faster.
  138. ;         Typical speed increase is 12%
  139. ;===========================================================================
  140. EVEN
  141. QPRINTL PROC FAR BASIC USES SI DI, TEXTSTRG:WORD
  142.  
  143.     Mov    ES,B$DVIDEOSEG    ; restore the initialized values
  144.     Mov    DX,B$DVIDEOPORT    ; puts 0 in DX if not CGA
  145.     Mov    BL,VAttrib    ; get attribute
  146.     Mov    AH,BL        ; store attribute in AH
  147.     Mov    BH,BL        ; store attribute in BH too for use in _Rollup
  148.     Mov    SI,TEXTSTRG     ; put descriptor to TEXT$ into SI
  149.     Mov    CX,[SI]         ; put Len(TEXT$) into CX for loop counter
  150.     JCXZ    Exit1           ; if CX is zero it's a null string, exit now
  151.     Mov    SI,[SI+02]      ; put address of first character in X$ into SI
  152.     Cld            ; clear the direction flag to move data forward
  153.     Mov    DI,B$DVIDEODI   ; set DI to reflect last call
  154.  
  155. Main_Loop:
  156.     Or    DX,DX        ; are we on a mono or EGA system (is DX = 0)?
  157.     JZ    Mono        ; yes, skip over the retrace stuff
  158.  
  159. EVEN
  160. CGA:
  161.     CLI            ; prevent interrupts to speed routine
  162.     Wait_CGA_Retrace    ; wait for CGA retrace MACRO
  163.     Lodsb                   ; get character from TEXT$ and increment SI
  164.     Stosw            ; store both the character and attribute
  165.     STI            ; allow interrupts again
  166.     Cmp     DI,3998         ; are we at last character? (80 * 25) display
  167.     JBE    @f        ; nope
  168.     Call    _Rollup        ; scroll up & reset to left column
  169. @@:
  170.     Loop    CGA        ; loop until CX is zero
  171.     Jmp    Short  Exit1
  172. EVEN
  173. Mono:
  174.     Lodsb                   ; get character from TEXT$ and increment SI
  175.     Stosw            ; store both the character and attribute
  176.     Cmp     DI,VPageSize    ; are we at last character?
  177.     JBE    @f        ; nope
  178.     Call    _Rollup        ; scroll up & reset to left column
  179. @@:
  180.     Loop    Mono        ; loop until CX is zero
  181.  
  182. Exit1:
  183.     Mov    B$DVIDEODI,DI    ; store DI for the future
  184.     Ret
  185. QPRINTL ENDP
  186.  
  187. ;===========================================================================
  188. ; DECLARE SUB VADDR (Row%, Column%)
  189. ;  CALL VADDR(Row%, Column%)
  190. ;  returns the current end of string address for the qprint routines
  191. ;===========================================================================
  192.  
  193. EVEN
  194. VADDR PROC FAR BASIC, ROW:WORD, COLL:WORD
  195.     Xor     DX,DX           ;clear DX
  196.     Mov     AX,B$DVIDEODI   ;get current DI
  197.     Mov     BX,160          ;set divisor at 160 for 80 column display
  198.     Div     BX              ;divide AX by BX.  Row in AX, remainder in DX
  199.     Inc     AX              ;remove zero bias
  200.     SHR     DX,1            ;divide remainder by 2 then increment
  201.     Inc     DX              ;to remove zero bias
  202.     Mov     BX,ROW          ;store values
  203.     Mov     [BX],AX
  204.     Mov     BX,COLL
  205.     Mov     [BX],DX
  206.     Ret
  207. VADDR ENDP
  208.  
  209. ;=======================================================================
  210. ; _Rollup: a local routine that scrolls up the last line of a display
  211. ;          using the attribute stored in BH. If SETQP is run, then
  212. ;          is sensitive to current display length.
  213. ; Input: 
  214. ;       Attribute in BH 
  215. ; Preserves: 
  216. ;          AX,BX,CX,DX
  217. ; Returns:
  218. ;          Screen scrolled up one line, DI reset to Last Line, Col 1
  219. ; About as fast as dedicated version below, and neatly handles snowy CGA's.
  220. ;
  221. ;=======================================================================
  222.  
  223. EVEN
  224. _Rollup Label   Near            ;Label used so routine name will not
  225.     Push    AX            ;be public.
  226.     Push    BX
  227.     Push    CX
  228.     Push    DX
  229.     Mov     AX,0601h            ;scroll up one row
  230.     Xor     CX,CX               ;window at 1,1
  231.     Mov     DH,VRow             ;put row in DH
  232.     Mov     DL,VColumn          ;put column in DL
  233.     Int     10h                 ; doit
  234.     Mov     DI,VDI_Reset        ; reset DI to Last Row, Col 1
  235.     Pop     DX
  236.     Pop     CX
  237.     Pop    BX
  238.     Pop     AX
  239.     Retn                ; routine is near!!
  240. ;end of routine
  241.  
  242. comment        |*
  243. ;=======================================================================
  244. ; _Rollup: a local routine that scrolls up the last line of a
  245. ;          80 x 25 display, using the attribute stored in BH
  246. ;          not yet corrected for snow on a CGA
  247. ;
  248. ; Input: 
  249. ;          Attribute in BH, Video Segment in ES, Direction flag cleared
  250. ; Preserves: 
  251. ;          AX,BX,CX,DX,DS,SI
  252. ; Returns:
  253. ;          Screen scrolled up one line, DI reset to Row 25, Col 1
  254. ;=======================================================================
  255.  
  256. _Rollup Label   Near            ;Label used so routine name will not
  257.     Push    AX            ;be public.
  258.     Push    CX                  ; save all registers used
  259.     Push    SI
  260.     Push    DS                  ; save DS
  261.     Mov     AX,ES
  262.     Mov     DS,AX               ; set DS == ES
  263.     Mov     SI,160              ; copy block of 2,1 to 25,80
  264.                     ; to 1,1 to 24,80
  265.     Mov     CX,2000-80          ; page size in words
  266.     Xor     DI,DI               ; destination of 1,1 (0 based)
  267.     Rep     Movsw               ; do scroll
  268.     Mov     CX,80               ; number of characters on bottom line
  269.     Mov     AH,BH               ; get attribute from BH
  270.     Mov     AL,32               ; put space character in AL
  271.     Rep     Stosw               ; clear bottom line
  272.     Mov     DI,3840             ; reset DI to Row 25, Col 1
  273.     Pop     DS                  ; get back DS
  274.     Pop     SI
  275.     Pop     CX                  ; restore all registers used
  276.     Pop     AX
  277.     Retn                ; routine is near!!
  278. ;end of routine
  279.         |*
  280.  
  281. ;===========================================================================
  282. ; DECLARE SUB CLREOL ()
  283. ;    CLREOL
  284. ; Purpose:
  285. ;       Clears to end of current display line w/o changing attribute
  286. ; Assumes:
  287. ;       80 Column mode, assumes that DI has been set by SETQP; QPRINT;
  288. ;       QPRINTL; or  QPRNT
  289. ;===========================================================================
  290.  
  291. EVEN
  292. CLREOL  PROC FAR BASIC
  293.     Cmp     B$DVIDEOINSTL,1 ; See if we have done this before
  294.     JE      Didit3          ; yep, so skip ahead
  295.     Call    Get_Adapter     ; call routine to find display type
  296.  
  297. Didit3:
  298.     Cld                     ; clear the direction flag to move data forward
  299.     Mov     AX,B$DVIDEODI   ; get DI from last call
  300.     Mov     DI,AX           ; set DI to reflect last call
  301.     Xor     DX,DX           ; clear DX
  302.     Mov     BX,160          ; set divisor at 160 for 80 column display
  303.     Div     BX              ; divide AX by BX.  COL*2 (remainder) in DX
  304.     SHR     DX,1            ; divide remainder by 2
  305.     Or      DX,DX           ; if column is 1
  306.     Jz      Exit2           ; exit as there is nothing to do
  307.     Mov     CX,80           ; Assume in 80 column Mode
  308.     Sub     CX,DX           ; this gives number of spaces to print
  309.  
  310.     Mov     ES,B$DVIDEOSEG  ; restore the initialized values
  311.     Mov     DX,B$DVIDEOPORT ; puts 0 in DX if not CGA, else CGA retrace
  312.     Mov     AL,20h          ; character to erase with (a space)
  313. Main:
  314.     Or      DX,DX           ; are we on a mono or EGA system (is DX = 0)?
  315.     JZ      Mono1           ; yes, skip over the retrace stuff
  316.     Mov     BL,AL           ; store in BL for rapid loading
  317.  
  318. EVEN
  319. CGA1:
  320.     CLI                     ; prevent interrupts to speed routine
  321.     Wait_CGA_Retrace        ; wait for CGA retrace MACRO
  322.     Mov     AL,BL           ; get character back again (MACRO destroys it)
  323.     Stosb                   ; store the character only
  324.     STI                     ; allow interrupts again
  325.     Inc     DI              ; skip to next cell
  326.     Loop    CGA1            ; loop until CX is zero
  327.     Jmp     Short  Exit2
  328.  
  329. EVEN
  330. Mono1:
  331.     Stosb                   ; store the character w/o changing attribute
  332.     Inc     DI              ; skip to next cell
  333.     Loop    Mono1           ; loop until CX is zero
  334.  
  335. Exit2:
  336.     Mov     B$DVIDEODI,DI   ; store DI for the future
  337.     Ret
  338. CLREOL  ENDP
  339. END
  340.