home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / QC25-10.ZIP / SAMPLES / COMMON.AS$ / COMMON.bin
Encoding:
Text File  |  1989-04-27  |  7.0 KB  |  235 lines

  1.     .MODEL    small, c
  2.     INCLUDE demo.inc
  3.     .CODE
  4.  
  5. ;* GetVer - Gets DOS version.
  6. ;*
  7. ;* Shows:   DOS Function - 30h (Get MS-DOS Version Number)
  8. ;*
  9. ;* Params:  None
  10. ;*
  11. ;* Return:  Short integer of form (M*100)+m, where M is major
  12. ;*        version number and m is minor version, or 0 if
  13. ;*        DOS version earlier than 2.0
  14.  
  15. GetVer    PROC
  16.  
  17.     mov    ah, 30h         ; DOS Function 30h
  18.     int    21h            ; Get MS-DOS Version Number
  19.     cmp    al, 0            ; DOS version 2.0 or later?
  20.     jne    @F            ; Yes?    Continue
  21.     sub    ax, ax            ; No?  Set AX = 0
  22.     jmp    SHORT exit        ;   and exit
  23. @@:    sub    ch, ch            ; Zero CH and move minor
  24.     mov    cl, ah            ;   version number into CX
  25.     mov    bl, 100
  26.     mul    bl            ; Multiply major by 10
  27.     add    ax, cx            ; Add minor to major*10
  28. exit:    ret                ; Return result in AX
  29.  
  30. GetVer    ENDP
  31.  
  32. ;* GetVidConfig - Determines current video configuration and initializes
  33. ;* the vconfig structure.
  34. ;*
  35. ;* Shows:   BIOS Interrupt - 10h, Function 0 (Set Video Mode)
  36. ;*                  10h, Function 0Fh (Get Video Mode)
  37. ;*                  10h, Function 1Ah (Get or Set Display
  38. ;*                    Combination Code)
  39. ;*
  40. ;* Uses:    vconfig - Video configuration structure, declared in the
  41. ;*        DEMO.INC include file.
  42. ;*
  43. ;* Params:  None
  44. ;*
  45. ;* Return:  None
  46.  
  47. GetVidConfig PROC
  48.  
  49.     mov    ax, 1A00h        ; Request video info for VGA
  50.     int    10h            ; Get Display Combination Code
  51.  
  52. chkVGA: cmp    al, 1Ah         ; Is VGA or MCGA present?
  53.     jne    chkEGA            ; No?  Then check for EGA
  54.  
  55.     cmp    bl, 2            ; If VGA exists as secondary adapter,
  56.     je    isCGA            ;   check for CGA and mono as primary
  57.     jb    isMONO
  58.     cmp    bl, 5            ; If EGA is primary, do normal
  59.     jbe    chkEGA            ;   EGA checking
  60.  
  61. chkMCGA:mov    vconfig.adapter, MCGA    ; Yes?    Assume MCGA
  62.     mov    vconfig.display, COLOR
  63.     cmp    bl, 8            ; Correct assumption?
  64.     ja    gmode            ; Yes?    Continue
  65. isVGA:    mov    vconfig.adapter, VGA    ; Assume it's VGA color
  66.     je    gmode            ; Yes?    Continue
  67.     mov    vconfig.display, MONO    ; No?  Must be VGA mono
  68.     jmp    SHORT gmode        ; Finished with VGA, so jump
  69.  
  70. chkEGA: mov    ah, 12h         ; Call EGA status function
  71.     mov    bl, 10h
  72.     sub    cx, cx            ; Clear status bits
  73.     int    10h            ; Get Configuration Information
  74.     jcxz    chkCGA            ; If CX is unchanged, not EGA
  75.  
  76. isEGA:    mov    vconfig.adapter, EGA    ; Set structure fields for EGA
  77.     mov    vconfig.display, MONO    ; Assume EGA mono
  78.     or    bh, bh            ; Correct assumption?
  79.     jnz    gmode            ; Yes?    Continue
  80.     mov    vconfig.display, COLOR    ; No?  Must be EGA color
  81.     jmp    SHORT gmode        ; Finished with EGA, so jump
  82.  
  83. chkCGA: int    11h            ; Get equipment list
  84.     and    al, 30h         ; If bits 4-5 set, monochrome
  85.     cmp    al, 30h         ; Monochrome text mode?
  86.     je    isMONO            ; Yes?    Continue
  87. isCGA:    mov    vconfig.adapter, CGA    ; No?  Must be CGA
  88.     mov    vconfig.display, COLOR
  89.     mov    vconfig.CGAvalue, 29h    ; Value for CGA 80x25 text,
  90.     jmp    SHORT gmode        ;   color, blink enable
  91.  
  92. isMONO: mov    vconfig.adapter, MDA    ; Set MONO
  93.     mov    vconfig.display, MONO
  94.  
  95. gmode:    mov    ah, 0Fh
  96.     int    10h            ; Get Video Mode
  97.     mov    vconfig.mode, al    ; Record mode
  98.     mov    vconfig.dpage, bh    ;   and current page
  99.     cmp    al, 7            ; Monochrome text mode?
  100.     je    @F            ; Yes?    Continue
  101.     cmp    al, 3            ; Color text mode?
  102.     je    @F            ; Yes?    Continue
  103.     cmp    al, 2            ; Black/white 80-col mode?
  104.     je    @F            ; Yes?    Continue
  105.     mov    ax, 0003h        ; If not 80-col text mode,
  106.     mov    vconfig.mode, al    ;   request Function 0, mode 3
  107.     int    10h            ; Set Video Mode to 80-col
  108.  
  109. @@:    mov    al, vconfig.display    ; Multiply display value
  110.     cbw                ;   (which is either 0 or 1)
  111.     mov    bx, 800h        ;   by 800h, then add to B000h
  112.     mul    bx            ;   for segment address of
  113.     add    ax, 0B000h        ;   video buffer
  114.     add    ah, vconfig.dpage    ; Adding display page gives
  115.     mov    vconfig.sgmnt, ax    ;   address of current page
  116.  
  117.     mov    vconfig.rows, 24    ; Assume bottom row # = 24
  118.     cmp    vconfig.adapter, EGA    ; EGA or VGA?
  119.     jl    exit            ; No?  Exit
  120.     mov    ax, 1130h        ; Yes?    Request character info
  121.     sub    bh, bh            ; Set BH to valid value
  122.     push    bp            ; BP will change, so save it
  123.     int    10h            ; Get number of rows/screen
  124.     mov    vconfig.rows, dl    ; Keep in structure
  125.     pop    bp            ; Restore BP
  126.  
  127. exit:    ret
  128.  
  129. GetVidConfig ENDP
  130.  
  131. ;* SetCurPos - Sets cursor position.
  132. ;*
  133. ;* Shows:   BIOS Interrupt - 10h, Function 2 (Set Cursor Position)
  134. ;*
  135. ;* Uses:    vconfig - Video configuration structure, declared in the
  136. ;*        DEMO.INC include file. The structure must first be
  137. ;*        initialized by calling the GetVidConfig procedure.
  138. ;*
  139. ;* Params:  row - Target row
  140. ;*        col - Target column
  141. ;*
  142. ;* Return:  None
  143.  
  144. SetCurPos PROC \
  145.     row:WORD, col:WORD
  146.  
  147.     mov    dx, col         ; DL = column
  148.     mov    dh, BYTE PTR row    ; DH = row
  149.     mov    ah, 2            ; Function 2
  150.     mov    bh, vconfig.dpage    ; Current page
  151.     int    10h            ; Set cursor position
  152.     ret
  153.  
  154. SetCurPos ENDP
  155.  
  156. ;* StrWrite - Writes ASCIIZ string to video memory at specified row/column.
  157. ;*
  158. ;* Shows:   Instructions - lodsb     stosb
  159. ;*
  160. ;* Uses:    vconfig - Video configuration structure, declared in the
  161. ;*        DEMO.INC include file. The structure must first be
  162. ;*        initialized by calling the GetVidConfig procedure.
  163. ;*
  164. ;* Params:  row - Row coordinate
  165. ;*        col - Column coordinate
  166. ;*        str - Pointer to string
  167. ;*
  168. ;* Return:  None
  169.  
  170. StrWrite PROC \
  171.     USES ds di si, \
  172.     row:WORD, col:WORD, str:PTR BYTE
  173.  
  174.     GetVidOffset row, col        ; Get offset in video segment
  175.     mov    di, ax            ; Copy to DI
  176.     LoadPtr ds, si, str        ; DS:SI points to string
  177.     mov    es, vconfig.sgmnt    ; ES:DI points to video RAM
  178. loop1:    lodsb                ; Get 1 character from string
  179.     or    al, al            ; Null terminator?
  180.     jz    exit            ; Yes?    Exit loop
  181.     cmp    vconfig.adapter, CGA    ; CGA adapter?
  182.     jne    pchar            ; No?  Skip next 10 lines
  183.  
  184. ; For CGA systems, StrWrite waits for the video to begin a horizontal
  185. ; retrace before writing a character to memory. This avoids the problem
  186. ; of video snow inherent with some (though not all) color/graphics adapters.
  187. ; It also demonstrates a somewhat different approach to the problem than the
  188. ; one taken in the WinOpen and WinClose procedures.
  189.  
  190.     push    ax            ; Save character
  191.     mov    dx, 3dah        ; Address of status register
  192.     cli                ; Disallow interruptions
  193. wait1:    in    al, dx            ; Read current video status
  194.     test    al, 1            ; Horizontal retrace active?
  195.     jnz    wait1            ; Yes?    Wait for it to end
  196. wait2:    in    al, dx            ; No?  Read status again
  197.     test    al, 1            ; Wait for retrace to start
  198.     jz    wait2
  199.     pop    ax            ; Recover character
  200. pchar:    stosb                ; Write char to video buffer
  201.     sti                ; Reenable interrupts
  202.     inc    di            ; Skip attribute byte
  203.     jmp    SHORT loop1        ; Loop back
  204. exit:    ret
  205.  
  206. StrWrite ENDP
  207.  
  208. ;* ClearBox - Clears portion of screen with specified fill attribute.
  209. ;*
  210. ;* Shows:   BIOS Interrupt - 10h, Function 6 (Scroll Up)
  211. ;*
  212. ;* Params:  attr - Fill attribute
  213. ;*        row1 - Top screen row of cleared section
  214. ;*        col1 - Left column of cleared section
  215. ;*        row2 - Bottom screen row of cleared section
  216. ;*        col2 - Right column of cleared section
  217. ;*
  218. ;* Return:  None
  219.  
  220. ClearBox PROC \
  221.     attr:WORD, row1:WORD, col1:WORD, row2:WORD, col2:WORD
  222.  
  223.     mov    ax, 0600h        ; Scroll service
  224.     mov    bh, BYTE PTR attr    ; BH = fill attribute
  225.     mov    ch, BYTE PTR row1    ; CH = top row of clear area
  226.     mov    cl, BYTE PTR col1    ; CL = left column 
  227.     mov    dh, BYTE PTR row2    ; DH = bottom row of clear area
  228.     mov    dl, BYTE PTR col2    ; DL = right column
  229.     int    10h            ; Clear screen by scrolling up
  230.     ret
  231.  
  232. ClearBox ENDP
  233.  
  234.     END
  235.