home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / grap / util / 015 / svga16m.asm < prev    next >
Assembly Source File  |  1993-03-07  |  16KB  |  584 lines

  1. ;****************************************************************************
  2. ;*
  3. ;*                           SuperVGA Test Library
  4. ;*
  5. ;*                  Copyright (C) 1993 Kendall Bennett.
  6. ;*                            All rights reserved.
  7. ;*
  8. ;* Filename:    $RCSfile: svga16m.asm $
  9. ;* Version:        $Revision: 1.2 $
  10. ;*
  11. ;* Language:    80386 Assembler
  12. ;* Environment:    IBM PC (MS DOS)
  13. ;*
  14. ;* Description:    This source file contains code to initialise the SuperVGA
  15. ;*                for bank switching and extended page flipping.
  16. ;*
  17. ;*                It also contains code to draw pixels, clear the display
  18. ;*                and perform page flipping for SuperVGA 16m color modes.
  19. ;*
  20. ;* $Id: svga16m.asm 1.2 1993/03/07 04:05:36 kjb Exp $
  21. ;*
  22. ;* Revision History:
  23. ;* -----------------
  24. ;*
  25. ;* $Log: svga16m.asm $
  26. ;* Revision 1.2  1993/03/07  04:05:36  kjb
  27. ;* Bug fixes.
  28. ;*
  29. ;* Revision 1.1  1993/03/03  10:26:06  kjb
  30. ;* Initial revision
  31. ;*
  32. ;****************************************************************************
  33.  
  34.         IDEAL
  35.         JUMPS
  36.         P386                    ; Use 80386 instructions
  37.  
  38. INCLUDE "model.mac"                ; Memory model macros
  39.  
  40. header        init
  41.  
  42. INCLUDE    "MGRAPH.EQU"            ; Include Equates for Mgraph Routines
  43.  
  44. CRTC            EQU    3D4h        ; Port of CRTC registers
  45. VGABufferSeg    EQU    0A000h        ; Segment of VGA display memory
  46. FIRSTMODE        EQU    grSVGA_320x200x16m
  47. MAXMODE            EQU    grSVGA_1280x1024x16m
  48.  
  49. begcodeseg    svga16m
  50.  
  51. ; Globals used by driver
  52.  
  53. OldBIOSMode            db    0            ; Old video mode before graphics
  54. Old50Lines            db    0            ; 1 if old mode was 50 line VGA
  55. CntDriver            dw    0            ; Graphics driver number
  56. CntMode                dw    0            ; Graphics mode number
  57. CntChipID            dw    0            ; Graphics driver chip ID
  58. CntColors            dw    gr16MColor    ; This is a 16 million color driver
  59.  
  60. ; The following information held in the status status area changes depending
  61. ; on which mode the driver is set up to be used in:
  62.  
  63. StatusArea:
  64.  
  65. XRes                dw    0            ; Device resolution in x direction - 1
  66. YRes                dw    0            ; Device resolution in y direction - 1
  67. BytesPerLine        dw    0            ; Number of bytes in a line
  68. PageSize            dd    0            ; Graphics page size
  69.  
  70. MaxPage                dw    0            ; Maximum number of video pages
  71. OriginOffset        dw    0            ; Offset of 0,0 into buffer
  72.  
  73. ; Here we set up a series of tables that can be used to fill in the start of
  74. ; the status area for each mode supported by this driver, and the address's
  75. ; of the routines required for each particular driver mode:
  76.  
  77. ModeTabStart:
  78.  
  79. ModeSVGA_320x200:    dw    319            ; XRes
  80.                     dw    199            ; YRes
  81.                     dw    960            ; BytesPerLine
  82. ModeSVGA_640x350:    dw    639            ; XRes
  83.                     dw    349            ; YRes
  84.                     dw    2048        ; BytesPerLine
  85. ModeSVGA_640x400:    dw    639            ; XRes
  86.                     dw    399            ; YRes
  87.                     dw    2048        ; BytesPerLine
  88. ModeSVGA_640x480:    dw    639            ; XRes
  89.                     dw    479            ; YRes
  90.                     dw    2048        ; BytesPerLine
  91. ModeSVGA_800x600:    dw    799            ; XRes
  92.                     dw    599            ; YRes
  93.                     dw    2400        ; BytesPerLine
  94. ModeSVGA_1024x768:    dw    1023        ; XRes
  95.                     dw    767            ; YRes
  96.                     dw    3072        ; BytesPerLine
  97. ModeSVGA_1280x1024:    dw    1279        ; XRes
  98.                     dw    1023        ; YRes
  99.                     dw    3840        ; BytesPerLine
  100. ModeTabSize            =    ($-ModeSVGA_1280x1024)    ; Size of table in bytes
  101.  
  102. INCLUDE "SV_PORTS.ASM"
  103. INCLUDE "SV_BANKS.ASM"
  104. INCLUDE "SV_MODES.ASM"
  105. INCLUDE "SV_PAGE.ASM"
  106. INCLUDE "SV_MAXPG.ASM"
  107.  
  108. ;----------------------------------------------------------------------------
  109. ; int _initSuperVGA(int driver,int chipID,int mode,int memory)
  110. ;----------------------------------------------------------------------------
  111. ; Routine to initialise the bank switching code for the SuperVGA, and setup
  112. ; internal tables of information about the video mode. If the video mode
  113. ; is not supported, we return -1.
  114. ;
  115. ; The value returned is a status number, where bit 0 represents extended
  116. ; page flipping is available, bit 1 that separate read/write banks are
  117. ; available.
  118. ;----------------------------------------------------------------------------
  119. procstart    __initSuperVGA
  120.  
  121.         ARG        driver:WORD, ChipID:WORD, mode:WORD, memory:WORD
  122.  
  123.         enter    0,0
  124.         push    si
  125.         push    di
  126.  
  127. ; Save the driver number and chip ID for later
  128.  
  129.         mov        ax,[ChipID]
  130.         mov        [CntChipID],ax
  131.         mov        ax,[driver]
  132.         mov        [CntDriver],ax
  133.  
  134. ; Load the Status area with info for the currently selected mode:
  135.  
  136.         mov        ax,[mode]
  137.         mov        [CntMode],ax
  138.         cmp        ax,MAXMODE            ; AX := desired mode
  139.         jg        @@Invalid            ; invalid if greater than maximum
  140.         cmp        ax,FIRSTMODE
  141.         jl        @@Invalid            ; invalid if less than first mode
  142.  
  143.         mov        cx,ModeTabSize        ; Put size of table into cx
  144.         sub        ax,FIRSTMODE
  145.         mul        cl                    ; AX := Mode * ModeTabSize
  146.         mov        si,ax
  147.         lea        si,[ModeTabStart + si]
  148.         push    cs
  149.         pop        es                    ; Set up es to point to code seg
  150.         lea        di,[StatusArea]        ; DI := Start of status area
  151.  
  152.         cld
  153.     rep    movs     [BYTE es:di],[BYTE es:si]
  154.  
  155.         mov        ax,[driver]
  156.         mov        bx,[mode]
  157.         call    loadSVGAMode        ; Load the SuperVGA video mode
  158.         or        ax,ax
  159.         jz        @@Invalid            ; Mode not supported on this adapter!
  160.  
  161.         mov        [maxpage],0            ; Clear maxpage variable
  162.         call    SetupBanks            ; Setup SuperVGA bank switching
  163.         call    [InitSVGA]            ; Setup bank switching code
  164.         call    SetupPaging            ; Setup SuperVGA page flipping
  165.         mov        ax,0                ; Assume no paging available
  166.         jc        @@Done                ; Extended page flipping not available
  167.  
  168. ; Determine the number of pages available for the mode and the video page
  169. ; size.
  170.  
  171.         xor        ebx,ebx
  172.         mov        bx,[memory]
  173.         shl        ebx,10                ; EBX := video memory in bytes
  174.         mov        ax,[mode]
  175.         call    numPages            ; Calculate the number of video pages
  176.         dec        ax
  177.         mov        [MaxPage],ax        ; Save maximum page number
  178.         mov        [DWORD pageSize],ebx
  179.         mov        [WORD bytesPerLine],cx
  180.         mov        ax,1                ; Extended paging is available
  181.  
  182. @@Done:
  183.         mov        bx,[TwoBanks]
  184.         shl        bx,1
  185.         or        ax,bx                ; Set the two banks flag
  186.         jmp        @@Exit
  187.  
  188. @@Invalid:
  189.         mov        ax,-1                ; Return failure!
  190.  
  191. @@Exit:
  192.         pop        di
  193.         pop        si
  194.         leave
  195.         ret
  196.  
  197. procend        __initSuperVGA
  198.  
  199. ;----------------------------------------------------------------------------
  200. ; int _setSuperVGAMode(void);
  201. ;----------------------------------------------------------------------------
  202. ; Routine sets the system into the SuperVGA graphics mode setup by the
  203. ; initSuperVGA routine. Note that this routine remembers if the EGA/VGA
  204. ; 43/50 line mode was set.
  205. ;
  206. ; If the video mode was not correctly set, we return false.
  207. ;----------------------------------------------------------------------------
  208. procstart    __setSuperVGAMode
  209.  
  210.         push    bp                    ; INT 10h Kills this!!!
  211.         push    si                    ; so save all regs...
  212.         push    di
  213.         push    ds
  214.  
  215.         mov        ah,0Fh                ; Get current video mode service
  216.         int        10h
  217.         mov        [OldBIOSMode],al    ; Save old video mode
  218.         mov        [Old50Lines],0        ; Default to non-50 line mode
  219.  
  220.         mov        ax,1130h            ; AH := INT 10h function number
  221.                                     ; AL := Get character gen information
  222.         mov        bh,00                ; Get contents of INT 1Fh
  223.         xor        dl,dl                ; Clear dl
  224.         int        10h                    ; Determine number of lines (in dl)
  225.         cmp        dl,49                ; 50 line mode?
  226.         jne        @@SetMode            ; No, must have been 25 lines
  227.         mov        [Old50Lines],1        ; Yes, 50 line mode was on
  228.  
  229. @@SetMode:
  230.         mov        ax,[CntDriver]
  231.         mov        bx,[CntMode]
  232.         call    loadSVGAMode        ; AX,BX := correct values for mode
  233.         int        10h                    ; Set the video mode
  234.  
  235.         mov        ax,40h
  236.         mov        es,ax
  237.         xor        ax,ax
  238.         cmp        [BYTE es:49h],3        ; Mode is still text mode, did not set
  239.         jbe        @@Exit
  240.  
  241.         call    [InitSVGA]            ; Initialise bank switching on SuperVGA's
  242.         mov        ax,1                ; Mode was correctly set
  243.  
  244. @@Exit:
  245.         pop        ds
  246.         pop        di                    ; Restore regs
  247.         pop        si
  248.         pop        bp                    ; Restore bp (after INT 10 trashes it)
  249.         ret
  250.  
  251. procend        __setSuperVGAMode
  252.  
  253. ;----------------------------------------------------------------------------
  254. ; void restoreMode(void)
  255. ;----------------------------------------------------------------------------
  256. ; Routine restores the original video mode that was set before graphics mode
  257. ; was entered.
  258. ;----------------------------------------------------------------------------
  259. procstart    _restoreMode
  260.  
  261.         push    bp                    ; INT 10h kills bp sometimes
  262.         push    si                    ; Save all regs...
  263.         push    di
  264.  
  265.         call    [ExitSVGA]            ; Uninitialise the SuperVGA
  266.  
  267.         mov        ah,0                ; Set video mode service
  268.         mov        al,[OldBIOSMode]    ; Get old BIOS mode number
  269.         int        10h                    ; Set the video mode
  270.  
  271.         cmp        [Old50Lines],0        ; Was 50 line mode set?
  272.         je