home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tel2305s.zip / ENGINE / INITVID.ASM < prev    next >
Assembly Source File  |  1992-01-16  |  8KB  |  262 lines

  1. ;
  2. ;  Video support routines
  3. ;****************************************************************************
  4. ;*                                                                          *
  5. ;*                                                                          *
  6. ;*      part of NCSA Telnet                                                 *
  7. ;*      by Tim Krauskopf, VT100 by Gaige Paulsen, Tek by Aaron Contorer     *
  8. ;*                                                                          *
  9. ;*      National Center for Supercomputing Applications                     *
  10. ;*      152 Computing Applications Building                                 *
  11. ;*      605 E. Springfield Ave.                                             *
  12. ;*      Champaign, IL  61820                                                *
  13. ;*                                                                          *
  14. ;****************************************************************************
  15. ;
  16.     NAME    INITVID
  17. ;Microsoft EQU 1
  18. ;Lattice EQU 1
  19. ifndef Microsoft
  20.     ifndef Lattice
  21.         if2
  22.             %out
  23.             %out ERROR: You have to specify "/DMicrosoft" or "/DLattice" on the
  24.             %out        MASM command line to determine the type of assembly.
  25.             %out
  26.         endif
  27.         end
  28.     endif
  29. endif
  30.  
  31.  X   EQU     6
  32.  MONO_SEG   EQU     0b000h          ; Standard display segments
  33.  COLOR_SEG  EQU     0b800h
  34.  
  35. ifdef Microsoft
  36. ;DGROUP  group _DATA
  37. ;_DATA segment public 'DATA'
  38. ;    assume DS:DGROUP
  39. .MODEL    LARGE
  40. .DATA
  41. else    
  42.     INCLUDE    DOS.MAC
  43.     SETX
  44.     DSEG
  45. endif
  46.  
  47.     video_segment   DW  COLOR_SEG   ; Display memory segment address
  48.     video_type      DB  0ffh        ; Display combination code
  49.     video_iscolor   DB  01h         ; 1=color, 0=monochrome
  50.     video_mode      DB  03h         ; Video display mode
  51.     video_page      DB  00h         ; Video Display Page
  52.     video_rows      DB  25          ; Number of Text rows
  53.     video_cols      DB  80          ; Number of Text columns
  54.  
  55. ifdef Microsoft
  56. ;_DATA ends
  57. ;
  58. ;_TEXT    segment public 'CODE'
  59. ;    assume CS:_TEXT
  60. .CODE
  61.     PUBLIC  _INITVIDEO,_GETVCONFIG
  62. else
  63.     ENDDS
  64.     PSEG
  65.     PUBLIC  INITVIDEO,GETVCONFIG
  66. endif    
  67. ;
  68. ;  Routines for general use
  69. ;
  70. ;
  71. ;************************************************************************
  72. ;  initvideo
  73. ;
  74. ;  Determines the active display adapter and various display parameters
  75. ;
  76. ifdef Microsoft
  77. _initvideo  proc    far
  78. else
  79. initvideo   proc    far
  80. endif
  81.  
  82.     PUSH    BP
  83.     MOV        BP, SP
  84.     PUSH    DS
  85.     PUSH    ES
  86.     PUSH     SI
  87.     PUSH     DI
  88.  
  89.     MOV     AH,0FH          ; Read Video information
  90.     INT     10H
  91.     MOV     video_mode,AL   ; Video Display Mode
  92.     MOV     video_page,BH   ; Video Display Page
  93.     MOV     video_cols,AH   ; Number of Text Columns
  94.     MOV     video_segment,MONO_SEG  ; Assume monochrome for now
  95.     MOV     video_iscolor,0 ;
  96.  
  97.     INT     11H             ; Read Equipment list
  98.     AND     AL,00110000b    ; Isolate Video bits
  99.     CMP     AL,00110000b    ; Was it mono?
  100.     JE      find_adapter    ; Yes
  101.     MOV     video_segment,COLOR_SEG ; Else, set color display
  102.     MOV     video_iscolor,1 ;
  103. find_adapter:
  104.     CALL    ps2_state       ; Read PS/2 video state
  105.     JNZ     adapter_set     ; Done, if supported
  106.     CALL    ega_state       ; Read EGA video state
  107.     JNZ     adapter_set     ; Done, is supported
  108.     CALL    cga_state       ; Determine CGA or mono
  109. adapter_set:
  110.     SUB     AX,AX           ; Adjust dsplay segment for current vide page
  111.     MOV     ES,AX           ;
  112.     MOV     AX,ES:[044EH]   ;
  113.     MOV     CL,4
  114.     SHR     AX,CL
  115.     ADD     video_segment,AX
  116.  
  117.     POP     DI
  118.     POP     SI
  119.     POP     ES
  120.     POP     DS
  121.     POP     BP
  122.     ret
  123. ifdef Microsoft
  124. _initvideo endp
  125. else
  126. initvideo endp
  127. endif
  128.  
  129. ;************************************************************************
  130. ;   ps2_state
  131. ;
  132. ;   This procedure attempts to access ps/2 compatible ROM BIOS video
  133. ;   services.  The zero flag is set if they aren't supported
  134. ;
  135. ps2_state   proc    near
  136.     MOV     AX,1A00H            ; Read PS/2 video state
  137.     INT     10H
  138.     CMP     AL,1AH              ; Was function supported?
  139.     LAHF                        ; Toggle zero flag (zf=1 if al is not equal to 1ah)
  140.     XOR     AH,01000000b        ;
  141.     SAHF
  142.     JZ      no_ps2              ; PS/2 BIOS not present
  143.     MOV     video_type,BL       ; Save active display code
  144.     MOV     AX,1130h            ; Read Font Code
  145.     SUB     BH,BH               ; Font Code (not used)
  146.     INT     10h                 ;
  147.     INC     DL                  ; Adjust row count (clear zf)
  148.     MOV     video_rows,DL       ;   and save
  149. no_ps2:
  150.     RET
  151. ps2_state endp
  152.  
  153. ;************************************************************************
  154. ;   ega_state
  155. ;
  156. ;   If PS/2 compatible ROM BIOS is not present, this procedure attempts
  157. ;   to access the EGA ROM BIOS video services
  158. ;
  159. ega_state proc near
  160.     MOV     AH,12H              ; Read EGA video state
  161.     MOV     BL,10H
  162.     INT     10H
  163.     CMP     BL,10H              ; Was Function supported?
  164.     JE      no_ega              ; No, EGA BIOS not present
  165.     CMP     video_iscolor,BH    ; Is EGA the active display?
  166.     JE      no_ega              ; No, find active display
  167.     ADD     BH,4                ; Else, calculate display code
  168.     MOV     video_type,BH       ;   and save
  169.     MOV     AX,1130H            ; Read Font code
  170.     SUB     BH,BH               ; Font Code (not used)
  171.     INT     10H
  172.     INC     DL                  ; Adjust row count (clear zf)
  173.     MOV     video_rows,DL       ;   and save
  174. no_ega:
  175.     RET
  176. ega_state endp
  177.  
  178. ;************************************************************************
  179. ;   cga_state
  180. ;
  181. ;   If neither PS/2 compatible ROM BIOS nor EGA ROM BIOS is present,
  182. ;   this procedure is called.  It simply assumes 25 text rows and sets
  183. ;   video_type to MDA or CGA depending on the value of  video_iscolor
  184. ;
  185. cga_state proc near
  186.     MOV     video_rows,25       ; If we get here, must be 25 rows
  187.     MOV     video_type,01H      ; Assume MDA adapter for now
  188.     CMP     video_iscolor,0     ; Is it mono?
  189.     JE      no_cga              ; Yes
  190.     MOV     video_type,02H      ; Else set CGA display adapter
  191. no_cga:
  192.     RET
  193. cga_state endp
  194.  
  195. ;************************************************************************
  196. ;   getvconfig
  197. ;
  198. ;   This routine fills a buffer with the current videio paremeter values.
  199. ;   Note: initvideo() must be called first in order for this procedure
  200. ;   to return meaningful values.
  201. ;
  202. ;   Usage:      void getvconfig(struct vidinfo *)
  203. ;
  204. ;   Where:  struct vidinfo {
  205. ;               int segment;
  206. ;               int type;
  207. ;               int iscolor;
  208. ;               int mode;
  209. ;               int page;
  210. ;               int rows;
  211. ;               int columns;
  212. ;           };
  213. ;
  214. ifdef Microsoft
  215. _getvconfig proc    far
  216. else
  217. getvconfig  proc    far
  218. endif
  219.     PUSH    BP
  220.     MOV     BP,SP
  221.     PUSH    ES
  222.     PUSH    DI
  223.     PUSH    SI
  224.     CLD                 ; All moves forward
  225. IF @DataSize
  226.     LES     DI,[BP+X]   ; Get the Pointer to the buffer
  227. ELSE
  228.     MOV     DI,[BP+X]   ; Get the Pointer to the buffer
  229.     PUSH    DS
  230.     POP     ES
  231. ENDIF
  232.  
  233.     MOV     SI,OFFSET video_segment ; Get the offset of the start of the videio information
  234.     MOVSW                   ; Copy the video segment
  235.  
  236.     MOV     CX,6            ; Copy six more byte values
  237.     XOR     AH,AH           ; Clear the top part of the transfer register
  238. Copy_Loop:
  239.     LODSB                   ; Move each byte from the video parameters
  240.     STOSW                   ; Into a word in the structure
  241.     LOOP    Copy_Loop
  242.  
  243.     POP     DI
  244.     POP     SI
  245.     POP     ES
  246.     POP     BP
  247.     RET
  248. ifdef Microsoft
  249. _getvconfig endp
  250. else
  251. getvconfig  endp
  252. endif
  253.  
  254. ifdef Microsoft
  255. ;_TEXT ends
  256.  
  257. else
  258.     ENDPS
  259. endif
  260.     END
  261.  
  262.