home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_01 / 3n01052a < prev    next >
Text File  |  1991-12-03  |  6KB  |  170 lines

  1. ;-----------------------------------------------------------------------;
  2. ; INITVID.ASM,    Written Sept 1991 by Jonathan Wood, SoftCircuits    ;
  3. ;                                    ;
  4. ; Routines to determine host display adapter. Assembled using MASM 6.0.    ;
  5. ; To assemble for different C memory models, modify the .MODEL        ;
  6. ; directive to the correct model and recompile. To interface with other    ;
  7. ; languages, change the language specifier on the same line. Depending    ;
  8. ; on the language, you may need to modify the way parameters are    ;
  9. ; accessed and which registers are saved.                ;
  10. ;-----------------------------------------------------------------------;
  11.  
  12.     .MODEL    small,c            ;Specify memory model/language
  13.  
  14. MONO_SEG    EQU    0B000h        ;Standard display segments
  15. COLOR_SEG    EQU    0B800h
  16.  
  17.     .DATA
  18. video_segment    DW    COLOR_SEG    ;Display memory segment address
  19. video_type    DB    0FFh        ;Display combination code
  20. video_iscolor    DB    01h        ;1 = color, 0 = mono
  21. video_mode    DB    03h        ;Video display mode
  22. video_page    DB    00h        ;Video display page
  23. video_rows    DB    25h        ;Number of text rows
  24. video_cols    DB    80h        ;Number of text columns
  25.  
  26.     .CODE
  27. ;-----------------------------------------------------------------------;
  28. ; Determines the active display adapter and various display parameters.    ;
  29. ;                                    ;
  30. ; Prototype:    void initvideo(void);                    ;
  31. ;                                    ;
  32. ;-----------------------------------------------------------------------;
  33. initvideo    PROC USES si di bp
  34.     mov    ah,0Fh            ;Read video information
  35.     int    10h
  36.     mov    video_mode,al        ;Video display mode
  37.     mov    video_page,bh        ;Video display page
  38.     mov    video_cols,ah        ;Number of text columns
  39.     mov    video_segment,MONO_SEG    ;Assume mono display for now
  40.     mov    video_iscolor,0
  41.     int    11h            ;Read equipment list
  42.     and    al,00110000b        ;Isolate video bits
  43.     cmp    al,00110000b        ;Was it mono?
  44.     je    find_adapter        ;Yes
  45.     mov    video_segment,COLOR_SEG    ;Else set color display
  46.     mov    video_iscolor,1
  47. find_adapter:
  48.     call    ps2_state        ;Read PS/2 video state
  49.     jnz    adapter_set        ;Done if supported
  50.     call    ega_state        ;Read EGA video state
  51.     jnz    adapter_Set        ;Done if supported
  52.     call    cga_state        ;Determine CGA or MDA
  53. adapter_set:
  54.     sub    ax,ax            ;Adjust display segment for
  55.     mov    es,ax            ; current video page
  56.     mov    ax,es:[044Eh]
  57.     mov    cl,4
  58.     shr    ax,cl
  59.     add    video_segment,ax
  60.     ret
  61. initvideo    ENDP
  62.  
  63. ;-----------------------------------------------------------------------;
  64. ; This procedure attempts to access PS/2 compatible ROM BIOS video    ;
  65. ; services. The zero flag is set if they aren't supported.        ;
  66. ;                                    ;
  67. ;    Output:    zf    Zero flag set if PS/2 compatible ROM BIOS is    ;
  68. ;            not present.                    ;
  69. ;                                    ;
  70. ;-----------------------------------------------------------------------;
  71. ps2_state    PROC    NEAR
  72.     mov    ax,1A00h        ;Read PS/2 display code
  73.     int    10h
  74.     cmp    al,1Ah            ;Was function supported?
  75.     lahf                ;Toggle zero flag (zf = 1 if
  76.     xor    ah,01000000b        ; al is not equal to 1Ah)
  77.     sahf
  78.     jz    no_ps2            ;PS/2 BIOS not present
  79.     mov    video_type,bl        ;Save active display code
  80.     mov    ax,1130h        ;Read font code
  81.     sub    bh,bh            ;Font code (not used)
  82.     int    10h
  83.     inc    dl            ;Adjust row count (clears zf)
  84.     mov    video_rows,dl        ; and save
  85. no_ps2:
  86.     ret
  87. ps2_state    ENDP
  88.  
  89. ;-----------------------------------------------------------------------;
  90. ; If PS/2 compatible ROM BIOS is not present, this procedure attempts    ;
  91. ; to access the EGA ROM BIOS video services.                ;
  92. ;                                    ;
  93. ;    Output:    zf    Zero flag set if EGA not active            ;
  94. ;                                    ;
  95. ;-----------------------------------------------------------------------;
  96. ega_state    PROC    NEAR
  97.     mov    ah,12h            ;Read EGA video state
  98.     mov    bl,10h
  99.     int    10h
  100.     cmp    bl,10h            ;Was function supported?
  101.     je    no_ega            ;No, EGA BIOS not present
  102.     cmp    video_iscolor,bh    ;Is EGA the active display
  103.     je    no_ega            ;No, find active display
  104.     add    bh,4            ;Else calculate display code
  105.     mov    video_type,bh        ; and save
  106.     mov    ax,1130h        ;Read font code
  107.     sub    bh,bh            ;Font code (not used)
  108.     int    10h
  109.     inc    dl            ;Adjust row count (clears zf)
  110.     mov    video_rows,dl        ; and save
  111. no_ega:
  112.     ret
  113. ega_state    ENDP
  114.  
  115. ;-----------------------------------------------------------------------;
  116. ; This procedure is called if neither PS/2 or EGA comaptible ROM BIOS    ;
  117. ; was active. It simply assumes 25 text rows and sets video_type to MDA    ;
  118. ; or CGA depending on the value of video_iscolor.            ;
  119. ;-----------------------------------------------------------------------;
  120. cga_state    PROC    NEAR
  121.     mov    video_rows,25        ;If we get here, must be 25 rows
  122.     mov    video_type,01h        ;Assume MDA display adapter for now
  123.     cmp    video_iscolor,0        ;Is it mono?
  124.     je    no_cga            ;Yes
  125.     mov    video_type,02h        ;Else set CGA display adapter
  126. no_cga:
  127.     ret
  128. cga_state    ENDP
  129.  
  130. ;-----------------------------------------------------------------------;
  131. ; This routine fills a buffer with the current video parameter values.    ;
  132. ; Note: initvideo() must be called first in order for this procedure to    ;
  133. ; return meaningful values.                        ;
  134. ;                                    ;
  135. ; Usage:    void getvconfig(struct video *);            ;
  136. ;                                    ;
  137. ; Where:    struct video {                        ;
  138. ;            int segment;                     ;
  139. ;            int type;                        ;
  140. ;            int iscolor;                        ;
  141. ;            int mode;                        ;
  142. ;            int page;                        ;
  143. ;            int rows;                        ;
  144. ;            int columns;                        ;
  145. ;        };                            ;
  146. ;                                    ;
  147. ;-----------------------------------------------------------------------;
  148. getvconfig    PROC USES si di, buffer:PTR
  149.     cld
  150.     IF @DataSize
  151.     les    di,buffer        ;Load far struct pointer into es:di
  152.     ELSE
  153.     mov    di,buffer        ;Load near struct pointer into es:di
  154.     push    ds
  155.     pop    es
  156.     ENDIF
  157.     mov    si,OFFSET video_segment    ;ds:si points to display variables
  158.     lodsw                ;Copy video segment to buffer
  159.     stosw
  160.     mov    cx,6            ;Copy 6 more byte values
  161.     sub    ah,ah            ;Clear high byte of ax
  162. copy_loop:
  163.     lodsb                ;Load byte value in al
  164.     stosw                ;Copy word value to buffer
  165.     loop    copy_loop
  166.     ret
  167. getvconfig    ENDP
  168.  
  169.     END
  170.