home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bgi256-3.zip / SVESA.INC < prev    next >
Text File  |  1992-12-27  |  8KB  |  303 lines

  1. ;SVESA.INC - Copyright 1991,1992 Knight Software
  2. ;    History:
  3. ;       17 May 1991 - first release
  4. ;       19 Aug 1992 - fixed bug with seperate read/write windows. 
  5. ;                     Fixed push/pop bug in VesaBank select
  6. ;       22 Nov 1992 - adapted for protected mode operation
  7. ;
  8. ;----------------------------------------------------------
  9. ;This file provides VESA support
  10.  
  11. ;----------------------------------------------------------
  12. ;DetectCard detects whether the VESA support is out there.
  13. ;If VESA support is found, then the highest supported 
  14. ;256 color mode is determined. If no VESA support is found, 
  15. ;we default to standard VGA mode. 
  16. ;Assumed: DS=data segment 
  17. ;Enter: Nothing
  18. ;Return: NZ=error, Z=valid display/mode  and card is setup
  19. DetectCard PROC NEAR
  20.     PUSH    ES
  21.     PUSH    DI
  22.     PUSH    SI
  23.     PUSH    DX
  24.     PUSH    CX
  25.     PUSH    BX
  26.     PUSH    AX
  27.  
  28.     MOV    BX,DS:[SEGA000]       ;init video segment/selector
  29.     MOV    DS:[VideoSegment],BX
  30.  
  31.     MOV    BX,0
  32.     MOV    DS:[VidMode],BX       ;init VESA mode to zero
  33.     MOV    DS:[NumberModes],BX   ;and max mode
  34.     MOV    DS:[ModeErrorFlag],BL ;preclear error flag
  35.     MOV    AX,4F00H    ;get VESA display info
  36.     LEA    DI,TempWork
  37.     CALL    VESAInt
  38.     JC    @NoVESA        ;dpmi call failed - sigh
  39.     CMP    WORD PTR ES:[DI],"EV"
  40.     JNZ    @NoVESA        ;error out if not VESA
  41.     CMP    WORD PTR ES:[DI+2],"AS"
  42.     JZ    @IsVESA
  43. @NoVESA:
  44.     JMP    @NotVESA
  45.  
  46. @IsVESA:
  47.     MOV    SI,ES:[DI+0EH]    ;BX:SI = ptr to table of avail modes
  48.     MOV    CX,ES:[DI+10H]
  49.  
  50.     CMP DS:[CurOpMode],0      ;if CurOpMode is zero,
  51.     JZ    @IsVESAchk    ;no need to convert it
  52.  
  53.     PUSH    SI
  54.     MOV    AX,0002H    ;is prot mode, so gotta convert
  55.     MOV    BX,CX        ;real segment to a selector
  56.     INT    31H
  57.     POP    SI
  58.     JC    @NoVESA        ;ack, something went wrong
  59.     MOV    CX,AX        ;stick selector value in CX
  60.  
  61. @IsVESAchk:
  62.     MOV    ES,CX        ;ES:SI now points to mode table
  63.     SUB    SI,2        ;preadj pointer
  64. @NextMode:
  65.     ADD    SI,2
  66.     MOV    AX,ES:[SI]    ;get item from vesa list
  67.     CMP    AX,-1        ;last item?
  68.     JZ    @LastMode
  69.     MOV    CX,VESAmodeSize    ;CX=our table length
  70.     LEA    DI,VESAmodes    ;DS:DI = modes we use
  71.     MOV    BX,0        ;BX=test mode number
  72. @ModeLoop:
  73.     CMP    AX,CS:[DI]    ;Is the item in our list?
  74.     JZ    @GoodMode
  75.     ADD    DI,2        ;try everything in our list
  76.     INC    BX
  77.     LOOP    @ModeLoop
  78.     JMP    SHORT @NextMode     ;go try next vesa mode
  79. @GoodMode:
  80.     MOV    BH,0
  81.     CMP    BL,DS:[ModeSelect]
  82.     JNZ    @NotOurMode
  83.     MOV    DS:[VidMode],AX ;Save VESA mode number
  84. @NotOurMode:
  85.     CMP    BX,DS:[NumberModes] ;is mode higher than last one? 
  86.     JL    @NextMode
  87.     MOV    DS:[NumberModes],BX ;update max mode if higher
  88.     JMP    SHORT @NextMode  ;check on next vesa mode
  89.  
  90. @LastMode:
  91.     MOV    CX,DS:[VidMode]
  92.     OR    CX,CX         ;if Zero is not a valid
  93.     JNZ    @ModeOK         ;VESA mode 
  94.     CMP    BYTE PTR DS:[ModeSelect],0 ;if mode zero
  95.     JZ    @NotVESA     ;is OK not to be VESA mode
  96.     MOV    AH,grInvalidMode ;set error flag
  97.     MOV    DS:[StatBlock.stat],AH
  98.     MOV    BYTE PTR DS:[ModeErrorFlag],0FFH ;mark as mode error
  99.     JMP    @NotVESA     ;and go to default mode
  100.  
  101. @ModeOK:
  102.     MOV    AX,4F01H    ;get mode info
  103.     LEA    DI,TempWork    ;(mode is in CX)
  104.     CALL    VESAInt        ;buffer of data is 
  105.     JC    @NotVESA    ; returned in ES:DI
  106.     MOV    CX,ES:[DI+4]    ;Get window granularity
  107.     OR    CX,CX        ;if zero, not a valid value
  108.     JZ    @NotVESA
  109.     MOV    AX,64        ;convert to 64K multiplier
  110.     XOR    DX,DX        ;for bank selects
  111.     DIV    CX
  112.     MOV    DS:[WinGran],AX    ;Save it for later
  113.     OR    AX,AX
  114.     JZ    @NotVESA    ;bad window granularity
  115.     MOV    BX,ES:[DI+16]    ;get real scan line length
  116.     MOV    DS:[ScanLineLength],BX
  117.  
  118.     LEA    DI,VESAbank    ;everything looks good
  119.     MOV    DS:[BankSelectProc],DI ;so init pointers
  120.     LEA    DI,VESAinit
  121.     MOV    DS:[InitDisplayProc],DI
  122.     INC    WORD PTR [NumberModes] ;adj number modes
  123.     MOV    BX,8        ;Analog color display type 
  124.     MOV    DS:[DisplayType],BX
  125.     LEA    DI,VESAname
  126.     MOV    DS:[CardNamePtr],DI
  127.     XOR    AX,AX
  128.     JMP    SHORT @DetectExit
  129.  
  130. ;Couldn't find VESA, so fall back on standard VGA
  131. @NotVESA:
  132.     LEA    DI,VGABankSelect ;allow select mode 13H only
  133.     MOV    DS:[BankSelectProc],DI
  134.     LEA    DI,VGA320x200Init
  135.     MOV    DS:[InitDisplayProc],DI
  136.     MOV    BX,64         ;default window granularity = 64K
  137.     MOV    DS:[WinGran],BX
  138.     MOV    BX,0
  139.     MOV    DS:[ModeSelect],BL  ;def select mode
  140.     INC    WORD PTR DS:[NumberModes] ;adj number modes
  141.  
  142.     MOV    AX,1A00H
  143.     INT    10H        ;check if VGA type display
  144.     CMP    AL,1AH
  145.     JNZ    @NotVGA
  146.     MOV    DS:[DisplayType],BX
  147.     CMP    BL,6        ;allow MCGA or VGA support
  148.     JC    @NotVGA
  149.     CMP    BL,0AH        ;but not digital MCGA
  150.     JZ    @NotVGA
  151.  
  152.     LEA    DI,VGAcard
  153.     MOV    DS:[CardNamePtr],DI
  154.     XOR    AX,AX
  155.     JMP    SHORT @DetectExit
  156.  
  157. ;Couldn't find VGA/MCGA, so just error out
  158. @NotVGA:
  159.     MOV    BYTE PTR DS:[ModeErrorFlag],0FFH ;mark as mode error
  160.     MOV    AH,grNoInitGraph ;set error flag
  161.     MOV    DS:[StatBlock.stat],AH
  162.     LEA    DI,DummyCard
  163.     MOV    DS:[CardNamePtr],DI
  164.     MOV    BYTE PTR DS:[ModeSelect],0 ;force mode to 0
  165.     OR    AL,255
  166. @DetectExit:
  167.     OR    AX,AX
  168.     POP    AX
  169.     POP    BX
  170.     POP    CX
  171.     POP    DX
  172.     POP    SI
  173.     POP    DI
  174.     POP    ES
  175.     RET
  176. DetectCard ENDP
  177.  
  178.  
  179. ;--------------------------------------------------
  180. ;code segment placment variables and stuff
  181.  
  182. VESAmodeSize EQU 6    ;number of modes in table
  183. VESAmodes:
  184.      DW 13H        ;0: 320X200X256
  185.      DW 100H    ;1: 640x400x256
  186.      DW 101H    ;2: 640x480x256
  187.      DW 103H    ;3: 800x600x256
  188.      DW 105H    ;4: 1024x768x256
  189.      DW 107H    ;5: 1280x1024x256
  190.  
  191. MaxModes EQU 6    ;maximum available modes we can use
  192. ;VESAmode DW 0    ;VESA mode we will be using
  193.  
  194. VESAname DB 7
  195.      DB 'VESA256',0        ;VESA driver name
  196.  
  197. VGAcard     DB 8
  198.      DB 'VGA/MCGA',0    ;default VGA id
  199.  
  200.  
  201. ;----------------------------------------------------------------------
  202. ;Set screen mode to desired value
  203. ;Assume:  DS = data segment
  204. ;Enter:   mode to select in VidMode
  205. ;Return:  selected mode; Rets Z if selected, NZ if bad
  206. ;Destory: AX,BX
  207.  
  208. VESAinit PROC NEAR
  209.     PUSH    AX
  210.     PUSH    BX
  211.     MOV    AX,04F02H
  212.     MOV    BX,DS:[VidMode]
  213.     INT    10H
  214.     CMP    AX,004FH    ;ret Z if good
  215.     POP    BX
  216.     POP    AX
  217.     RET
  218. VESAinit ENDP
  219.  
  220. ;----------------------------------------------------------------------
  221. ;select new display memory bank via Vesa calls
  222. ;Assume:  DS = data segment
  223. ;Enter:   DX = 64K bank to select
  224. ;Return:  Bank is selected 
  225. ;Destory: None
  226.  
  227. VESAbank PROC NEAR
  228.     PUSH    AX
  229.     PUSH    BX
  230.     PUSH    DX
  231.     MOV    AX,DS:[WinGran]
  232.     MUL    DX
  233.     MOV    DX,AX
  234.     PUSH    DX
  235.     MOV    AX,04F05H
  236.     MOV    BX,0
  237.     INT    10H
  238.     POP    DX
  239.     MOV    AX,04F05H
  240.     MOV    BX,1
  241.     INT    10H
  242.     POP    DX
  243.     POP    BX
  244.     POP    AX
  245.     RET
  246. VESAbank ENDP
  247.  
  248.  
  249. ;----------------------------------------------------------------------
  250. ;This processes the Vesa interupt $10 call to manage the protected
  251. ;verses real mode TSR calling problem with selectors via the DPMI
  252. ;Assume:  DS = data segment
  253. ;Enter:   registers as needed
  254. ;Return:  registers as needed    C=failed, NC=ok
  255. ;Destory: None
  256.  
  257. VESAInt:
  258.     CMP DS:[CurOpMode],0      ;if CurOpMode is zero
  259.     JNZ @VesaProt           ;just manage the INT 10 call 
  260.     PUSH DS
  261.     POP ES             ;point ES:DI at temp buffer
  262.     INT 10H               ;normally
  263.     CMP AX,004FH
  264.     JZ @VESAintOK
  265.     STC            ;ret carry set if function fails
  266. @VESAintOK:
  267.     RET
  268.  
  269. ;process VESA int $10 call via DPMI protected mode operation
  270. @VesaProt:
  271.     PUSH DS
  272.     POP ES
  273.     PUSH DI
  274.     PUSH ES
  275.     MOV word ptr DS:[SimInt.RealAX],AX ;pass command number 
  276.     MOV word ptr DS:[SimInt.RealCX],CX ;vid mode where used
  277.     MOV word ptr DS:[SimInt.RealDI],DI ;buf adr in DI
  278.     MOV AX,DS:[RealModeDS]
  279.     MOV DS:[SimInt.RealES],AX    ;pass the real mode segment
  280.     MOV DS:[SimInt.RealDS],AX
  281.     MOV word ptr DS:[SimInt.RealSS],0    ;let DPMI make it's own stack
  282.     MOV word ptr DS:[SimInt.RealSP],0
  283.     MOV word ptr DS:[SimInt.RealXX],0
  284.     MOV word ptr DS:[SimInt.RealXX+2],0
  285.     LEA DI,SimInt
  286.     MOV AX,0300H
  287.     MOV BL,10H
  288.     MOV BH,0
  289.     MOV CX,0
  290.     INT 31H
  291.     POP ES
  292.     POP DI        ;returns ES:DI pointing at temp work 
  293.     JC @VesaProtRet ;eek! dpmi call failed
  294.     MOV AX,word ptr DS:[SimInt.RealAX]
  295.     CMP AX,004FH    ;check on vesa call status
  296.     JZ @VesaProtRet ;good, it made it
  297.     STC        ;urg. ret carry set on failure
  298. @VesaProtRet:
  299.     RET
  300.  
  301.  
  302. ;=====================================================================
  303.