home *** CD-ROM | disk | FTP | other *** search
/ World of Graphics / WOGRAPH.BIN / 478.SV_MAXPG.ASM < prev    next >
Assembly Source File  |  1993-03-19  |  9KB  |  312 lines

  1. ;****************************************************************************
  2. ;*
  3. ;*                        MegaGraph Graphics Library
  4. ;*
  5. ;*                  Copyright (C) 1993 Kendall Bennett.
  6. ;*                            All rights reserved.
  7. ;*
  8. ;* Filename:    $RCSfile: sv_maxpg.asm $
  9. ;* Version:        $Revision: 1.2 $
  10. ;*
  11. ;* Language:    80386 Assembler
  12. ;* Environment:    IBM PC (MS DOS)
  13. ;*
  14. ;* Description:    Module to compute the maximum number of available video
  15. ;*                pages for specific video mode.
  16. ;*
  17. ;* $Id: sv_maxpg.asm 1.2 1993/03/07 04:04:13 kjb Exp $
  18. ;*
  19. ;* Revision History:
  20. ;* -----------------
  21. ;*
  22. ;* $Log: sv_maxpg.asm $
  23. ;* Revision 1.2  1993/03/07  04:04:13  kjb
  24. ;* Bug fixes.
  25. ;*
  26. ;* Revision 1.1  1993/03/03  10:46:57  kjb
  27. ;* Initial revision
  28. ;*
  29. ;****************************************************************************
  30.  
  31. ; Table of standard video mode information (bytesPerLine,
  32. ; vertical resolution and number of colors) used to compute the number of
  33. ; pages and page size for the specified video mode. This table can be
  34. ; modified at initialisation time for video cards that have non-standard
  35. ; bytes per line values (S3 cards and VESA cards).
  36.  
  37. PageInfo:        dw    grEGA_320x200x16,         40, 200
  38.                 dw    grEGA_640x200x16,         80, 200
  39.                 dw    grEGA_640x350x16,         80, 350
  40.                 dw    grVGA_640x400x16,         80, 400
  41.                 dw    grVGA_640x480x16,         80, 480
  42.                 dw    grSVGA_800x600x16,        100, 600
  43.                 dw    grSVGA_1024x768x16,        128, 768
  44.                 dw    grSVGA_1280x1024x16,    160, 1024
  45.                 dw    grVGA_320x200x256,        320, 200
  46.                 dw    grSVGA_640x350x256,        640, 350
  47.                 dw    grSVGA_640x400x256,        640, 400
  48.                 dw    grSVGA_640x480x256,        640, 480
  49.                 dw    grSVGA_800x600x256,        800, 600
  50.                 dw    grSVGA_1024x768x256,    1024, 768
  51.                 dw    grSVGA_1280x1024x256,    1280, 1024
  52.                 dw    grSVGA_320x200x32k,        640, 200
  53.                 dw    grSVGA_640x350x32k,        1280, 350
  54.                 dw    grSVGA_640x400x32k,        1280, 400
  55.                 dw    grSVGA_640x480x32k,        1280, 480
  56.                 dw    grSVGA_800x600x32k,        1600, 600
  57.                 dw    grSVGA_1024x768x32k,    2048, 768
  58.                 dw    grSVGA_1280x1024x32k,    2560, 1024
  59.                 dw    grSVGA_320x200x16m,     960, 200
  60.                 dw    grSVGA_640x350x16m,        1920, 350
  61.                 dw    grSVGA_640x400x16m,        1920, 400
  62.                 dw    grSVGA_640x480x16m,        1920, 480
  63.                 dw    grSVGA_800x600x16m,        2400, 600
  64.                 dw    grSVGA_1024x768x16m,    3072, 768
  65.                 dw    grSVGA_1280x1024x16m,    3840, 1024
  66.                 dw    -1
  67.  
  68. ;----------------------------------------------------------------------------
  69. ; numPages
  70. ;----------------------------------------------------------------------------
  71. ;
  72. ; Computes the number of pages in a specified video mode
  73. ;
  74. ; Entry:        AX        - Video mode number
  75. ;                EBX        - Video memory size
  76. ;
  77. ; Exit:            AX        - Number of video pages
  78. ;                EBX        - Page size for video mode
  79. ;                CX        - BytesPerLine value
  80. ;
  81. ; Registers:    EAX,EBX,ECX,EDX
  82. ;
  83. ;----------------------------------------------------------------------------
  84. PROC    numPages
  85.  
  86.         mov        edx,ebx                ; EDX := video memory size
  87.         mov        bx,offset PageInfo - 6
  88.  
  89. @@FindMode:
  90.         add        bx,6
  91.         mov        cx,[WORD cs:bx]
  92.         cmp        cx,-1
  93.         je        @@NotFound
  94.         cmp        cx,ax
  95.         jne        @@FindMode            ; Loop till desired mode is found
  96.  
  97.         push    edx
  98.         xor        eax,eax
  99.         mov        ax,[WORD cs:bx+2]
  100.         mul        [WORD cs:bx+4]        ; DX:AX := bytesPerLine * yres
  101.         shl        edx,16
  102.         or        eax,edx                ; EAX := bytesPerLine * yre
  103.         pop        edx
  104.  
  105.         cmp        cx,grSVGA_640x350x256
  106.         jge        @@Colors256
  107.         cmp        cx,grVGA_320x200x256
  108.         je        @@Colors256
  109.  
  110. ; We have a 16 color video mode. We round up the page size depending on
  111. ; how large it is, either to 8k, 16k, 32k or 64k boundaries.
  112.  
  113. @@Colors16:
  114.         shr        edx,2                ; EDX := video memory / 4
  115.         add        eax,1FFFh            ; Round to next 8k
  116.         and        eax,0FFFFE000h
  117.         cmp        eax,2000h            ; Page size = 8k?
  118.         je        @@Done                ; Yes, we are done
  119.         add        eax,3FFFh            ; Round to next 16k
  120.         and        eax,0FFFFC000h
  121.         cmp        eax,4000h            ; Page size = 16k?
  122.         je        @@Done                ; Yes, we are done
  123.         add        eax,7FFFh            ; Round to next 32k
  124.         and        eax,0FFFF8000h
  125.         cmp        eax,8000h            ; Page size = 32k?
  126.         je        @@Done                ; Yes, we are done
  127.  
  128. ; We have a 16 color video mode with > 64k per page, or a 256, 32k or
  129. ; 16 million color video mode. We thus ensure that the video page size is
  130. ; rounded up to the nearest 64k, to ensure pages always begin on bank
  131. ; boundaries.
  132.  
  133. @@Colors256:
  134.         add        eax,0FFFFh            ; Round to next 64k
  135.         and        eax,0FFFF0000h
  136.  
  137. @@Done:
  138.         mov        cx,[WORD cs:bx+2]    ; Load bytes per line value
  139.         mov        ebx,eax                ; EBX := video page size
  140.         mov        eax,edx
  141.         xor        edx,edx                ; EDX:EAX := video memory size
  142.         div        ebx                    ; EAX := number of video pages
  143.         ret
  144.  
  145. @@NotFound:
  146.         xor        ax,ax
  147.         xor        ebx,ebx
  148.         ret
  149.  
  150. ENDP    numPages
  151.  
  152. ;----------------------------------------------------------------------------
  153. ; setBytesPerLine
  154. ;----------------------------------------------------------------------------
  155. ;
  156. ; Changes the bytesPerLine value for a specified video mode.
  157. ;
  158. ; Entry:        AX        - Video mode number
  159. ;                BX        - New bytes per line value
  160. ;
  161. ; Exit:            BX        - New bytes per line value
  162. ;
  163. ; Registers:    AX,BX
  164. ;
  165. ;----------------------------------------------------------------------------
  166. PROC    setBytesPerLine
  167.  
  168.         push    cx
  169.         push    dx
  170.         mov        dx,bx                ; BX := new bytesPerLine value
  171.         mov        bx,offset PageInfo - 6
  172.  
  173. @@FindMode:
  174.         add        bx,6
  175.         mov        cx,[WORD cs:bx]
  176.         cmp        cx,-1
  177.         je        @@NotFound
  178.         cmp        cx,ax
  179.         jne        @@FindMode            ; Loop till desired mode is found
  180.  
  181. ; Change the bytesPerLine value for the mode.
  182. ;
  183. ; Some VESA Video BIOS's are screwed and return invalid values for the
  184. ; bytes per line (Such as S3 based boards like the STB WIND/X). Generally
  185. ; they give us half the expected value, which is naturally less than the
  186. ; amount that is _physically_ required for the mode to operate. If this
  187. ; is the case we double the specified value :-)
  188.  
  189.         cmp        dx,[WORD cs:bx+2]
  190.         jge        @@1
  191.         shl        dx,1                ; Value is too small, so double it!
  192. @@1:    mov        [WORD cs:bx+2],dx
  193.         mov        bx,dx                ; Restore value in BX
  194.  
  195. @@NotFound:
  196.         pop        dx
  197.         pop        cx
  198.         ret
  199.  
  200. ENDP    setBytesPerLine
  201.  
  202. ;----------------------------------------------------------------------------
  203. ; checkVESAPageFlip
  204. ;----------------------------------------------------------------------------
  205. ;
  206. ; Checks to see if the VESA board supports extended page flipping.
  207. ;
  208. ; Exit:            carry    - Clear if VESA page flipping is supported
  209. ;
  210. ; Registers:    AX,BX,CX,DX
  211. ;
  212. ;----------------------------------------------------------------------------
  213. PROC    checkVESAPageFlip
  214.  
  215.         mov        ax,4F07h            ; Set display start service
  216.         xor        bx,bx                ; BH := 0, BL := 0 (set display start)
  217.         xor        cx,cx                ; Left most pixel in line
  218.         xor        dx,dx                ; First displayed scan line
  219.         int        10h
  220.         cmp        al,4Fh
  221.         jne        @@Invalid            ; Function not supported, no page flip
  222.         or        ah,ah
  223.         jnz        @@Invalid            ; Function not successful, no page flip
  224.  
  225.         mov        ax,4F07h            ; Get display start service
  226.         mov        bx,1                ; BH := 0, BL := 1 (get display start)
  227.         int        10h
  228.         cmp        al,4Fh
  229.         jne        @@Invalid            ; Function not supported, no page flip
  230.         or        ah,ah
  231.         jnz        @@Invalid            ; Function not successful, no page flip
  232.         or        bh,bh
  233.         jnz        @@Invalid            ; BH should be zero if supported also
  234.         or        cx,cx
  235.         jnz        @@Invalid            ; CX should be zero (from above call)
  236.         or        dx,dx
  237.         jnz        @@Invalid            ; DX should be zero (from above call)
  238.  
  239. ; Horrah! We have page flipping on a VESA board.
  240.  
  241.         clc
  242.         ret
  243.  
  244. @@Invalid:
  245.         stc
  246.         ret
  247.  
  248. ENDP    checkVESAPageFlip
  249.  
  250. ;----------------------------------------------------------------------------
  251. ; GetVESABytesPerLine    - Gets the VESA bytes per line value for a mode
  252. ;----------------------------------------------------------------------------
  253. ;
  254. ; Calls a VESA compatible BIOS to get the bytes per line value for a mode,
  255. ; and updates the internal tables accordingly.
  256. ;
  257. ; Entry:        AX        - MGL Mode number
  258. ;                CX        - VESA Mode Number
  259. ;
  260. ; Registers:    None.
  261. ;
  262. ;----------------------------------------------------------------------------
  263. PROC    GetVESABytesPerLine
  264.  
  265.         pusha
  266.  
  267.         push    ax
  268.         push    cs
  269.         pop        es
  270.         mov        di,offset VesaBuf    ; ES:DI -> Buffer for VESA info
  271.         mov        ax,4F01h
  272.         int        10h                    ; Call the video BIOS to get info
  273.         pop        bx
  274.         cmp        ax,004Fh
  275.         jne        @@Exit                ; Call failed
  276.  
  277.         mov        ax,bx
  278.         mov        bx,[WORD VesaBuf+16]
  279.         call    setBytesPerLine
  280.  
  281. @@Exit:    popa
  282.         ret
  283.  
  284. ENDP    GetVESABytesPerLine
  285.  
  286. ;----------------------------------------------------------------------------
  287. ; ModifyS3BytesPerLine    - Modifies the BytesPerLine for S3 cards.
  288. ;----------------------------------------------------------------------------
  289. PROC    ModifyS3BytesPerLine
  290.  
  291.         mov        ax,grSVGA_800x600x16
  292.         mov        cx,102h
  293.         call    GetVESABytesPerLine
  294.         mov        ax,grSVGA_1024x768x16
  295.         mov        cx,104h
  296.         call    GetVESABytesPerLine
  297.         mov        ax,grSVGA_640x480x256
  298.         mov        cx,101h
  299.         call    GetVESABytesPerLine
  300.         mov        ax,grSVGA_800x600x256
  301.         mov        cx,103h
  302.         call    GetVESABytesPerLine
  303.         mov        ax,grSVGA_1024x768x256
  304.         mov        cx,105h
  305.         call    GetVESABytesPerLine
  306.         mov        ax,grSVGA_640x480x32k
  307.         mov        bx,2048
  308.         call    setBytesPerLine
  309.         ret
  310.  
  311. ENDP    ModifyS3BytesPerLine
  312.