home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / SCREENDD / SVGABANK.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-04-14  |  70.9 KB  |  1,548 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT (C) Microsoft Corporation, 1989
  4. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  5. ;
  6. ;    The following IBM OS/2 WARP source code is provided to you solely for
  7. ;    the purpose of assisting you in your development of OS/2 WARP device
  8. ;    drivers. You may use this code in accordance with the IBM License
  9. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  10. ;    Copyright statement may not be removed.;
  11. ;*****************************************************************************/
  12. ;       SCCSID = @(#)svgabank.asm       1.0 92/12/25
  13. ; ****************************************************************************
  14. ; *                                                                          *
  15. ; *                                                                          *
  16. ; *                                                                          *
  17. ; ****************************************************************************
  18.         PAGE    58,132
  19.         TITLE   Screen Device Driver - (svgabank.Asm)
  20.         .286p                                                           ;@T30
  21.  
  22. ;/***********************************************************************/
  23. ;/*                                                                     */
  24. ;/* SOURCE FILE NAME: svgabank.asm      STATUS: Version 1.1             */
  25. ;/*                                                                     */
  26. ;/* DESCRIPTIVE NAME:  Base Video Subsystem Screen Device Driver        */
  27. ;/*                                                                     */
  28. ;/* FUNCTION:   Provide SVGA bank routines, called by routines          */
  29. ;/*               GetSVGABank and                                       */
  30. ;/*               SetSVGABank                                           */
  31. ;/*                                                                     */
  32. ;/* NOTES:  Executes on Level 0                                         */
  33. ;/*                                                                     */
  34. ;/* ENTRY POINT:                                                        */
  35. ;/*   LINKAGE: Far Call                                                 */
  36. ;/*                                                                     */
  37. ;/* INPUT:  ES:BX = request packet address                              */
  38. ;/*       DS = BIODATA                                                  */
  39. ;/*                                                                     */
  40. ;/* EXIT-NORMAL:                                                        */
  41. ;/*                                                                     */
  42. ;/* EFFECTS:  None                                                      */
  43. ;/*                                                                     */
  44. ;/*   ROUTINES:                                                         */
  45. ;/*                                                                     */
  46. ;/************************ END OF SPECIFICATIONS ************************/
  47. .xlist
  48.         INCLUDE basemaca.inc            ;;;;;; 2.0 unique (dosmac replacement)
  49.         INCLUDE devhlp.inc              ; Define DevHlp functions
  50.         INCLUDE devsym.inc              ; Define DOS equates
  51.         INCLUDE error.inc               ; Define Error Messages
  52.         INCLUDE struc.inc               ; Define STRUC macros
  53. ;        include iodelay.inc            ;                       /*          */
  54.         include bsedev.inc              ;@senja
  55.         include svgadefs.inc            ;                       /*          */
  56. .list
  57.  
  58. ;@senja READ_BANK               EQU    0H
  59. ;WRITE_BANK              EQU    1H
  60.  
  61. ;MODE_TEXT               EQU    0H
  62. ;MODE_PLANAR             EQU    1H
  63. ;MODE_LINEAR             EQU    2H
  64.  
  65. ;SEQ_LOCKED              EQU    1H      ;                       /*          */
  66. ;GDC_LOCKED              EQU    2H      ;                       /*          */
  67.  
  68. BioData SEGMENT WORD PUBLIC 'DATA'
  69.         ASSUME  DS:BioData
  70.  
  71.         EXTRN   _sSVGA : WORD           ;                       /*          */
  72.         EXTRN   _XGAInstance : WORD     ;Speedway XGA instance  /*          */
  73.         EXTRN   SvgaOEMInfo : WORD      ;                       /*          */
  74.  
  75.         EXTRN   SVGA_SET_BANK_TABLE : WORD      ;               /*          */
  76.         EXTRN   SVGA_GET_BANK_TABLE : WORD      ;               /*          */
  77.  
  78. BioData ENDS
  79.  
  80.  
  81. BiosSeg SEGMENT WORD Public 'CODE'
  82.         ASSUME  CS:BiosSeg
  83.  
  84. PUBLIC  NOPSetBank
  85. PUBLIC  ATISetBank
  86. PUBLIC  CirrusSetBank
  87. PUBLIC  IBMSetBank
  88. PUBLIC  S3SetBank                     ;           
  89. PUBLIC  TridentSetBank
  90. PUBLIC  TsengSetBank
  91. PUBLIC  Video7SetBank
  92. PUBLIC  WDSetBank
  93. PUBLIC  WeitekSetBank
  94.  
  95. PUBLIC  NOPGetBank
  96. PUBLIC  ATIGetBank
  97. PUBLIC  CirrusGetBank
  98. PUBLIC  IBMGetBank
  99. PUBLIC  S3GetBank                     ;           
  100. PUBLIC  TridentGetBank
  101. PUBLIC  TsengGetBank
  102. PUBLIC  Video7GetBank
  103. PUBLIC  WDGetBank
  104. PUBLIC  WeitekGetBank
  105.  
  106. ;!!svgaxfer too!
  107.  
  108.         EXTRN  SVGAPhysToUVirt   : Near
  109.         EXTRN  SVGAUnPhysToUVirt : Near
  110.  
  111. ;/***************************************************************************
  112. ;*
  113. ;* FUNCTION NAME = GetTridentRegDef
  114. ;*
  115. ;* DESCRIPTION   = Return the current definition of the extended sequencer
  116. ;*                 registers.
  117. ;*
  118. ;* INPUT         = None
  119. ;*
  120. ;* OUTPUT        = AX = TRUE  - registers are in 'new' mode
  121. ;*                     = FALSE - registers are in 'old' mode
  122. ;* RETURN-NORMAL =
  123. ;* RETURN-ERROR  =
  124. ;*
  125. ;* CLOBBERS      = DX
  126. ;*
  127. ;**************************************************************************/
  128.  
  129. GetTridentRegDef      PROC      NEAR
  130.  
  131.         mov     dx, 03c4h               ;SEQ index address
  132. ;                                                               /*          */
  133. ;       Let the calling routine save this index!                /*          */
  134. ;                                                               /*          */
  135. ;       in      al, dx                  ;Get current SEQ index  /*          */
  136. ;       mov     cl, al                  ;Save SEQ index.        /*          */
  137.         mov     al, 00eh                ;Mode Ctrl Reg 1 index
  138.         cli
  139.         out     dx, al                  ;select Mode Control Reg 1
  140.         inc     dx                      ;SEQ data address
  141.         in      al, dx                  ;get current contents
  142.         mov     ah, al                  ; 
  143.         out     dx, al                  ;write out again
  144.         in      al, dx                  ;get contents
  145.         out     dx, al                  ;guarantee the same
  146.         cmp     al, ah                  ;reverse page bit ?
  147.         mov     ah, 001h                ;Assume new             /*          */
  148.         .if     < z >                   ;reverse page bit ?
  149.             dec     ah                  ;Not new, old instead.  /*          */
  150. ;
  151. ;               You could do the following read unconditionally.
  152. ;               It is not a toggle, but forces new definitions.
  153. ;
  154.             mov     al, 00bh            ;read version => set 64K mode
  155.             dec     dx                  ;SEQ index address
  156.             out     dx, al              ; 
  157.             inc     dx                  ;SEQ data address
  158.             in      al, dx              ;Dummy read to set 64K mode.
  159.         .endif                          ;                       /*          */
  160. ;       dec     dx                      ;SEQ index address      /*          */
  161. ;       mov     al, cl                  ;Restore SEQ index      /*          */
  162. ;       out     dx, al                  ;                       /*          */
  163.         mov     dl, 0cch                ;Misc Output Read addr
  164.         in      al, dx                  ; 
  165. ;       mov     ah, al                  ;                       /*          */
  166.         mov     dl, 0c2h                ;Misc Output Write addr
  167.         or      al, 020h                ;select low page memory
  168.         out     dx, al                  ;set Misc Output
  169.         sti                             ; 
  170.         mov     al, ah                  ;1 if new, 0 if old.
  171.         cbw                             ;                       /*          */
  172.  
  173. ;/****************************************************************************
  174. ;*
  175. ;* FUNCTION NAME = NOPSetBank
  176. ;*
  177. ;* DESCRIPTION   = Set bank. No error checking or indication.
  178. ;*
  179. ;* INPUT         = CX Bank, DX Direction and DI video mode
  180. ;* OUTPUT        = NONE
  181. ;*
  182. ;* RETURN-NORMAL = NONE.
  183. ;* RETURN-ERROR  = NONE
  184. ;*
  185. ;****************************************************************************/
  186.  
  187. NOPSetBank      PROC    NEAR
  188.  
  189.         ret
  190.  
  191. NOPSetBank      ENDP
  192.  
  193. GetTridentRegDef         ENDP
  194.  
  195. ;/****************************************************************************
  196. ;*
  197. ;* FUNCTION NAME = ATISetBank
  198. ;*
  199. ;* DESCRIPTION   = Set bank. No error checking or indication.
  200. ;*
  201. ;* INPUT         = CX Bank, DX Direction and DI video mode
  202. ;* OUTPUT        = NONE
  203. ;*
  204. ;* RETURN-NORMAL = NONE.
  205. ;* RETURN-ERROR  = NONE
  206. ;*
  207. ;* CLOBBERS      = AX, CX, DX
  208. ;*
  209. ;****************************************************************************/
  210.  
  211. ATISetBank      PROC    NEAR
  212.         shl     cl, 001h                ;Convert to 32K page num/*          */
  213.         .if     <[_sSVGA.ChipType] ae ATI_88800_CHIP> ;         /*          */
  214.             mov     al, cl              ;Get the bank           /*          */
  215.             cbw                         ;Extend to fullword     /*          */
  216.             mov     dx, 056ech          ;MEM_VGA_WPS0           /*          */
  217.             out     dx, ax              ;Set the bank           /*          */
  218.             mov     dx, 05aech          ;MEM_VGA_RPS0           /*          */
  219.             out     dx, ax              ;Set the bank           /*          */
  220.             inc     al                  ;Use 2nd 32K page num   /*          */
  221.             mov     dx, 056eeh          ;MEM_VGA_WPS1           /*          */
  222.             out     dx, ax              ;Set the bank           /*          */
  223.             mov     dx, 05aeeh          ;MEM_VGA_RPS1           /*          */
  224.             out     dx, ax              ;Set the bank           /*          */
  225.         .endif                          ;                       /*          */
  226. ;       Do always because 88800 needs this in 16 color modes!   /*          */
  227. ;!!Does 2M require 128K pages?
  228. ;
  229. ;       Note: ATI index register value does not remain the same after use!
  230. ;       So there is no use saving and restoring it.
  231. ;       And you must re-index to re-write a read value.
  232. ;
  233.         and     cl, not 0e1h            ;Prevent bank overrun.  /*          */
  234.         mov     al, 0beh                ;ATI3E Miscellaneous register.
  235.         mov     ah, al
  236.         mov     dx, 01ceh               ;ATI index address
  237.         out     dx, al
  238.         inc     dl                      ;ATI data address
  239.         in      al, dx                  ;get current contents
  240.         dec     dl                      ;ATI index address
  241.         and     al, not 008h            ;clear bit 3
  242.         xchg    ah, al
  243.         out     dx, ax                  ;set single bank mode
  244.         mov     al, 0b2h                ;ATI32 memory page select reg.
  245.         mov     ah, al
  246.         out     dx, al                  ;memory page select
  247.         inc     dl                      ;ATI data address
  248.         in      al, dx
  249.         dec     dl                      ;ATI index address
  250.         and     al, 0e1h                ;Remove old bank select bits (4:1).
  251.         or      al, cl                  ;Add in new bank select
  252.         xchg    ah, al
  253.         out     dx, ax                  ;Set the bank
  254.         ret
  255.  
  256. ATISetBank      ENDP
  257.  
  258. ;/****************************************************************************
  259. ;*
  260. ;* FUNCTION NAME = CirrusSetBank
  261. ;*
  262. ;* DESCRIPTION   = Set bank. No error checking or indication.
  263. ;*
  264. ;* INPUT         = CX Bank, DX Direction and DI video mode
  265. ;* OUTPUT        = NONE
  266. ;*
  267. ;* RETURN-NORMAL = NONE.
  268. ;* RETURN-ERROR  = NONE
  269. ;*
  270. ;* CLOBBERS      = AX, CX, DX
  271. ;*
  272. ;****************************************************************************/
  273.  
  274. CirrusSetBank   PROC    NEAR
  275. ;                                       ;Up to 2M should be OK!
  276.  
  277.         mov     dx, 03c4h               ;SEQ index address
  278.         in      al, dx
  279.         mov     ah, al                  ;Save SEQ index.
  280. ;*
  281.         mov     al, 006h                ;Get lock index.
  282.         out     dx, al
  283.         inc     dx                      ;SEQ data address
  284.         in      al, dx                  ;Get lock value.
  285.         push    ax                      ;Save lock & SEQ index  /*          */
  286.         mov     al, 012h                ;Unlock it now.         /*          */
  287.         out     dx, al                  ;                       /*          */
  288. ;*
  289.         mov     dl, 0ceh                ;GDC address            /*          */
  290.         in      al, dx
  291.         mov     ah, al                  ;Save GDC index.
  292. ;*
  293. ;*!!            Make sure GRB 3ce.0b has bit 5 set!             /*          */
  294. ;*!!            Make sure GRB 3ce.00 has bit 0 reset!           /*          */
  295. ;*
  296.         mov     al, 00bh                ;GRB Mode Extensions reg/*          */
  297.         out     dx, al                  ;                       /*          */
  298.         inc     dx                      ;GDC data address       /*          */
  299.         in      al, dx                  ;                       /*          */
  300.         and     al, 0deh                ;Set Offset Register 0  /*          */
  301.         or      al, 020h                ;Set Offset Granularity /*          */
  302.         out     dx, al                  ;Set GR[B]              /*          */
  303. ;*
  304.         mov     al, 009h
  305.         dec     dx                      ;GDC index              /*          */
  306.         out     dx, al
  307.  
  308.         shl     cl, 2                   ;Shift bank select to 7:2.
  309.         mov     al, cl
  310.         inc     dx                      ;GDC data address
  311.         out     dx, al                  ;Set the bank
  312.         dec     dx                      ;GDC index address
  313. ;*
  314.         mov     al, ah                  ;Restore GDC index.
  315.         out     dx, al
  316. ;*
  317.         pop     ax                      ;Restore SEQ idx&(un)lck/*          */
  318.         mov     dl, 0c4h + 001h         ;SEQ data address       /*          */
  319.         out     dx, al                  ;Index still set!
  320.         dec     dx                      ;SEQ index address      /*          */
  321. ;*
  322.         mov     al, ah                  ;Restore SEQ index      /*          */
  323.         out     dx, al
  324.         ret
  325.  
  326. CirrusSetBank   ENDP
  327.  
  328. ;/****************************************************************************
  329. ;*
  330. ;* FUNCTION NAME = IBMSetBank
  331. ;*
  332. ;* DESCRIPTION   = Set bank. No error checking or indication.
  333. ;*
  334. ;* INPUT         = CX Bank, DX Direction and DI video mode
  335. ;* OUTPUT        = NONE
  336. ;*
  337. ;* RETURN-NORMAL = NONE.
  338. ;* RETURN-ERROR  = NONE
  339. ;*
  340. ;* CLOBBERS      = AX, CX, DX
  341. ;*
  342. ;****************************************************************************/
  343.  
  344. IBMSetBank      PROC    NEAR
  345.  
  346.         mov     al, cl                  ;set the bank           /*          */
  347.         mov     dx, [_XGAInstance]      ;                       /*          */
  348.         add     dx, 008h                ;offset register
  349.         out     dx, al
  350.         ret
  351.  
  352. IBMSetBank      ENDP
  353.  
  354. ;/****************************************************************************
  355. ;*
  356. ;* FUNCTION NAME = S3SetBank                                   
  357. ;*
  358. ;* DESCRIPTION   = Set bank. No error checking or indication.
  359. ;*
  360. ;* INPUT         = CX Bank, DX Direction and DI video mode
  361. ;* OUTPUT        = NONE
  362. ;*
  363. ;* RETURN-NORMAL = NONE.
  364. ;* RETURN-ERROR  = NONE
  365. ;*
  366. ;* CLOBBERS      = AX, CX, DX
  367. ;*
  368. ;****************************************************************************/
  369.  
  370. S3SetBank       PROC    NEAR                       ;           
  371. ;                                       ;Up to 4M should be OK!
  372. ;!!What about monochrome displays!? 3b4?
  373.  
  374.         mov     dx, 03d4h               ;CRTC index address
  375.         in      al, dx
  376.         mov     ch, al                  ;Save CRTC index        /*          */
  377. ;*
  378.         mov     ax, 04838h              ;CR38 lock/unlock index /*          */
  379.         out     dx, al
  380.         inc     dx                      ;CRTC data address
  381.         in      al, dx
  382.         xchg    ah, al                  ;Save (un)lock/get unlck/*          */
  383.         out     dx, al                  ;Unlock ext regs        /*          */
  384.         dec     dx                      ;CRTC index address
  385. ;*
  386. ;       and     cx, 03fh                ;prevent overrun.       /*          */
  387.         mov     al, 035h
  388. ;       mov     dl, 0d4h                ;CRTC index address     /*          */
  389.         out     dx, al                  ;Output both index&data
  390.         mov     al, cl                  ; supports up to 4 MB
  391.         and     al, 00fh
  392.         inc     dx                      ;CRTC data address
  393.         out     dx, al
  394.         dec     dx                      ;CRTC index address
  395. ;*
  396.         mov     al, 031h                ;CR31 mem config reg.   /*          */
  397.         out     dx, al                  ; 
  398.         inc     dx                      ;CRTC data address
  399.         in      al, dx                  ; 
  400.         or      al, 001h                ;Enable 64K page addr.
  401.         out     dx, al                  ;                       /*          */
  402.         dec     dx                      ;CRTC index address
  403. ;*
  404.         mov     al, 038h                ;CR38 lock/unlock index /*          */
  405.         out     dx, ax                  ;Restore lock/unlock    /*          */
  406. ;*
  407.         mov     ax, 0a039h              ;CR39 lock/unlock index /*          */
  408.         out     dx, al
  409.         inc     dx                      ;CRTC data address
  410.         in      al, dx
  411.         xchg    ah, al                  ;Save (un)lock/get unlck/*          */
  412.         out     dx, al                  ;Unlock ext regs        /*          */
  413.         dec     dx                      ;CRTC index address
  414. ;*
  415. ;*      Do we need to check chiptype? Why not just write?
  416. ;*      Does the index register wrap?
  417.         .if     <[_sSVGA.ChipType] ae S3_86C864_CHIP>
  418.             mov     al, 06ah            ;Ext System Ctrl Reg 4.
  419.             out     dx, al
  420.             inc     dx                  ;CRTC data address
  421.             mov     al, cl              ;Extend the bank number.
  422.             out     dx, al              ;write ext system cntl reg
  423.             dec     dx                  ;CRTC index address     /*          */
  424.         .endif
  425.         and     cl, 030h                ;get bits 5:4
  426.         shr     cl, 4-2                 ;bits 5:4 of the bank into bits 3:2
  427.         mov     al, 051h
  428.         out     dx, al
  429.         inc     dx                      ;CRTC data address
  430.         in      al, dx
  431.         and     al, not 00ch            ;clear bits 3:2
  432.         or      al, cl                  ;set the extended bank bits
  433.         out     dx, al                  ;write it
  434.         dec     dx                      ;CRTC index address     /*          */
  435. ;*
  436.         mov     al, 039h                ;CR39 lock/unlock index /*          */
  437.         out     dx, ax                  ;Restore lock/unlock    /*          */
  438. ;*
  439. ;                                                               /*           end */
  440. ;       mov     dl, 0d4h                ;CRTC index address     /*          */
  441.         mov     al, ch                  ;Restore CRTC index
  442.         out     dx, al
  443.         ret
  444.  
  445. S3SetBank       ENDP
  446.  
  447. ;/****************************************************************************
  448. ;*
  449. ;* FUNCTION NAME = TridentSetBank
  450. ;*
  451. ;* DESCRIPTION   = Set bank. No error checking or indication.
  452. ;*
  453. ;*                 Register 0bh at port 3c4h (Hardware Version Register) is
  454. ;*                 read-only.
  455. ;*
  456. ;*                 BUT, By writing to the register the Mode Control
  457. ;*                      registers will assume their 'old' definitions.
  458. ;*                      Reading the register causes the Mode Control
  459. ;*                      registers to assume 'new' definitions.  The
  460. ;*                      register's previous state therefore can't be
  461. ;*                      restored.  All we need in a multi-tasking
  462. ;*                      environment......  Note also that Page bit (bit 1)
  463. ;*                      is inverted when setting the write bank and doesn't
  464. ;*                      read back as written.
  465. ;*
  466. ;*                 Mode Control registers 1 & 2 are at 3c4/5 index
  467. ;*                 0Dh and 0Eh.
  468. ;*
  469. ;*                 Write operations require bit 1 (Page Select) to be
  470. ;*                 inverted.
  471. ;*
  472. ;* INPUT         = CX Bank, DX Direction and DI video mode
  473. ;* OUTPUT        = NONE
  474. ;*
  475. ;* RETURN-NORMAL = NONE.
  476. ;* RETURN-ERROR  = NONE
  477. ;*
  478. ;* CLOBBERS      = AX, CX, DX
  479. ;*
  480. ;****************************************************************************/
  481.  
  482. TridentSetBank  PROC    NEAR
  483.  
  484.         .if <di ae MODE_PLANAR>         ;Only grafix modes handled /*          */
  485.             mov     dx, 03ceh           ;GDC index address
  486.             in      al, dx
  487.             mov     ah, al              ;Save GDC index.        /*          */
  488. ;*
  489.             mov     al, 006h            ;Misc reg index         /*          */
  490.             out     dx, al
  491.             inc     dx                  ;GDC data address
  492.             in      al, dx              ;Read GDC misc reg
  493.             test    al, 008h
  494.             .if     < z >               ;Exit if A0000 not referenced
  495.                 mov     dl, 0c4h        ;SEQ index address      /*          */
  496.                 in      al, dx
  497.                 push    ax              ;Save GDC&SEQ indices   /*          */
  498. ;               push    cx              ;Save bank              /*          */
  499.                 call    GETTRIDENTREGDEF ; this destroys ax, dx, cx.
  500. ;               pop     cx              ;Restore bank           /*          */
  501.                 mov     ch, al          ;save the result AX=1 new mode.
  502. ;                                                               /*          */
  503. ;               GDC index still points to miscellaneus reg!     /*          */
  504. ;                                                               /*          */
  505. ;               mov     al, 006h        ;Misc reg index         /*          */
  506. ;               mov     dl, 0ceh        ;GDC index address      /*          */
  507. ;               out     dx, al                                  /*          */
  508.                 mov     al, 005h        ;Mem addr mode to 64K   /*          */
  509.                 mov     dl, 0ceh + 001h ;GDC data address       /*          */
  510.                 out     dx, al
  511. ;*
  512.                 mov     al, 00bh        ;                       /*          */
  513.                 mov     dl, 0c4h        ;SEQ index address      /*          */
  514.                 out     dx, al
  515.                 inc     dx              ;SEQ data address
  516.                 in      al, dx          ;Chgs mode ctrl to new definition.
  517.                 dec     dx              ;SEQ index address      /*          */
  518. ;*
  519.                 mov     ah, cl          ;Get bank               /*          */
  520.                 xor     ah, 002h        ;Invert bank bit        /*          */
  521.                 mov     al, 00eh        ;Mode Ctrl 1 reg index
  522.                 out     dx, ax          ;Output both index&data /*          */
  523. ;               mov     al, ah                                  /*          */
  524. ;               inc     dx              ;SEQ data address       /*          */
  525. ;               out     dx, al                                  /*          */
  526. ;               dec     dx              ;SEQ index address.     /*          */
  527. ;*
  528.                 and     ch, ch          ;Test reg definition    /*          */
  529.                 .if     < z >           ;Is definition old? Restore it
  530.                     mov     al, 00bh    ;AH doesn't matter!     /*          */
  531. ;                   mov     dl, 0c4h    ;SEQ index address      /*          */
  532.                     out     dx, ax      ;Output both index&data /*          */
  533. ;                   mov     al, ah                              /*          */
  534. ;                   inc     dx          ;SEQ data address       /*          */
  535. ;                   out     dx, al                              /*          */
  536. ;                   dec     dx          ;SEQ index address.     /*          */
  537.                 .endif
  538. ;*
  539.                 pop     ax              ;Restore GDC&SEQ indices/*          */
  540. ;               mov     dl, 0c4h        ;SEQ index address      /*          */
  541.                 out     dx, al
  542.             .endif
  543. ;*
  544.             mov     al, ah              ;Restore GDC index      /*          */
  545.             mov     dl, 0ceh            ;GDC index address      /*          */
  546.             out     dx, al
  547.         .endif
  548. ExitTrident:
  549.         ret
  550.  
  551. TridentSetBank  ENDP
  552.  
  553. ;/****************************************************************************
  554. ;*
  555. ;* FUNCTION NAME = TsengSetBank
  556. ;*
  557. ;* DESCRIPTION   = Set bank. No error checking or indication.
  558. ;*                                                              /*          */
  559. ;*      Set read and write bank to same values.
  560. ;*      Read bank 5:0 @ 5:4 of 3CB, 7:4 of 3CD
  561. ;*      Write bank 5:0 @ 1:0 of 3CB, 3:0 of 3CD
  562. ;*      ET4000/ET3000 do not have a 3CB.
  563. ;*      ET3000 has read bank in 5:3 of 3CD and write bank in 2:0.
  564. ;*
  565. ;* INPUT         = CX Bank, DX Direction and DI video mode
  566. ;* OUTPUT        = NONE
  567. ;*
  568. ;* RETURN-NORMAL = NONE.
  569. ;* RETURN-ERROR  = NONE
  570. ;*
  571. ;* CLOBBERS      = AX, CX, DX
  572. ;*
  573. ;****************************************************************************/
  574.  
  575. TsengSetBank    PROC    NEAR
  576. ;                                       ;Up to 4M should be OK!
  577.  
  578.         mov     ch, cl
  579.         and     cx, 00f30h              ;Prevent bank overrun.
  580.         mov     ax, cx
  581.         mov     dx, [_sSVGA.ChipType] ;                         /*          */
  582.         rol     al, 4
  583.         shl     ah, 3                   ;Get read bank.
  584.         .if     <dx ae TSENG_ET4000_CHIP> ; adjust for ET4000   /*          */
  585.             shl     ah, 1
  586.         .endif
  587.         or      ax, cx
  588.         .if     <dx a TSENG_ET4000_CHIP>; adjust for ET4000W32  /*          */
  589.             mov     dx, 003cbh          ;Get GDC Segment Select 2 addr.
  590.             out     dx, al              ;Output bits 4:5 of read/write banks.
  591.         .endif                          ;Does not exist on ET4000/ET3000.
  592.         mov     dx, 003cdh              ;Get GDC Segment Select 1 addr.
  593.         mov     al, ah
  594.         out     dx, al                  ;Output bits 0:3 of read/write banks.
  595.         ret
  596.  
  597. TsengSetBank    ENDP
  598.  
  599. ;/****************************************************************************
  600. ;*
  601. ;* FUNCTION NAME = Video7SetBank
  602. ;*
  603. ;* DESCRIPTION   = Set bank. No error checking or indication.
  604. ;*
  605. ;*     We have two scenarios here, one for the HT205 chip
  606. ;*     (Version 3) and another for HT208/HT209 (Version 4/5)
  607. ;*     chips.
  608. ;*
  609. ;*     Version 4/5 are easy, a single register is dedicated to
  610. ;*     selecting the read bank and another to the write bank.
  611. ;*     The chip should first be set into single bank mode before
  612. ;*     setting these registers.
  613. ;*
  614. ;*     Version 3 chips are a nightmare.  There are different
  615. ;*     registers to be set according to whether the mode is
  616. ;*     16/256 colour and also for read/write bank selection.
  617. ;*
  618. ;* INPUT         = CX Bank, DX Direction and DI video mode
  619. ;* OUTPUT        = NONE
  620. ;*
  621. ;* RETURN-NORMAL = NONE.
  622. ;* RETURN-ERROR  = NONE
  623. ;*
  624. ;* CLOBBERS      = AX, CX, DX
  625. ;*
  626. ;****************************************************************************/
  627.  
  628. Video7SetBank   PROC    NEAR
  629.  
  630.         mov     dx, 03c4h               ;SEQ index address
  631.         in      al, dx
  632.         mov     ch, al                  ;Save SEQ index         /*          */
  633. ;*
  634.         mov     ax, 00606h              ;Lock reg index (twice) /*          */
  635.         out     dx, al
  636.         inc     dx                      ;SEQ data address
  637.         in      al, dx                  ;Not read as written    /*          */
  638.         and     al, 001h                ;0=locked, 1=unlocked   /*          */
  639.         mov     al, 0eah                ;Assume unlocked        /*          */
  640.         out     dx, al                  ;Unlock it now.         /*          */
  641.         dec     dx                      ;SEQ index address      /*          */
  642.         .if     < z >                                           /*@V2.1MNH13*/
  643.             mov     al, 0aeh            ;Locked instead         /*          */
  644.         .endif                          ;0aeh=lock, 0eah=unlock /*          */
  645.         xchg    al, ah                  ;Xchg index&unlock      /*          */
  646.         push    ax                      ;Save lock index&(un)lck/*          */
  647. ;*
  648.         .if     <[_sSVGA.ChipType] eq VIDEO7_HT205_CHIP> ;HT_205/*          */
  649.             .if     <di ne MODE_PLANAR> ;other than planar mode /*          */
  650.                 mov     al, 0f9h
  651.                 mov     ah, cl          ;                       /*          */
  652.                 and     ah, 001h        ;Get first bit of bank  /*          */
  653. ;               mov     dl, 0c4h        ;SEQ index address      /*          */
  654.                 out     dx, ax          ;Output both index&data /*          */
  655. ;               mov     al, ah          ;                       /*          */
  656. ;               inc     dx              ;SEQ data address       /*          */
  657. ;               out     dx, al          ;                       /*          */
  658. ;               dec     dx              ;SEQ index address.     /*          */
  659. ;*
  660.                 mov     dl, 0cch        ;Misc Output Read addr
  661.                 in      al, dx
  662.                 and     al, 0dfh        ;Clear bit 5 of misc.
  663.                 mov     ah, cl          ;Bank that needs to be set.
  664.                 and     ah, 002h        ;Move second bit into bit 5
  665.                 shl     ah, 4
  666.                 or      al, ah
  667.                 mov     dl, 0c2h        ;Misc Output Write addr
  668.                 out     dx, al          ;Write new Misc Output reg value
  669. ;*
  670.                 mov     dl, 0c4h        ;SEQ index address      /*          */
  671.                 shr     cl, 2           ;Now save next 2 bits
  672.             .endif                      ;End if non-planar
  673. ;*
  674.             mov     al, 0f6h            ;Get Bank select        /*          */
  675. ;           mov     dl, 0c4h            ;SEQ index address      /*          */
  676.             out     dx, al
  677.             inc     dx                  ;SEQ data address
  678.             in      al, dx              ;Read bank select register
  679.             and     al, 0f0h            ;Reset bit 0:1 for write & 2:3 for read
  680.             and     cl, 003h            ;Prevent bank overrun.
  681.             mov     ah, cl
  682.             shl     ah, 2
  683.             or      ah, cl
  684.             or      al, ah              ;Set read=write bank.
  685.             out     dx, al
  686.             dec     dx                  ;SEQ index address.     /*          */
  687.         .else                           ;Else HT_208 or HT_209
  688.             mov     al, 0e0h            ;                       /*          */
  689. ;           mov     dl, 0c4h            ;SEQ index address      /*          */
  690.             out     dx, al              ;Misc Ctrl
  691.             inc     dx                  ;SEQ data address
  692.             in      al, dx
  693.             and     al, 07fh
  694.             out     dx, al              ;Set single bank mode
  695.             dec     dx                  ;SEQ index address      /*          */
  696. ;*
  697.             mov     ah, cl
  698.             shl     ah, 4
  699.             .if <di eq MODE_TEXT>
  700.                 or      ah, 020h
  701.             .endif
  702.             mov     al, 0e8h            ;Write bank select reg
  703. ;           mov     dl, 0c4h            ;SEQ index address      /*          */
  704.             out     dx, ax              ;Output both index&data /*          */
  705. ;           mov     al, ah                                      /*          */
  706. ;           inc     dx                  ;SEQ data address       /*          */
  707. ;           out     dx, al                                      /*          */
  708. ;           dec     dx                  ;SEQ index address.     /*          */
  709. ;           mov     al, 0e9h            ;Read bank select reg   /*          */
  710. ;*
  711.             inc     al                  ;Read bank select reg   /*          */
  712. ;           mov     dl, 0c4h            ;SEQ index address      /*          */
  713.             out     dx, ax              ;Output both index&data /*          */
  714. ;           mov     al, ah                                      /*          */
  715. ;           inc     dx                  ;SEQ data address       /*          */
  716. ;           out     dx, al                                      /*          */
  717. ;           dec     dx                  ;SEQ index address.     /*          */
  718.         .endif                          ;HT_208 or HT_209       /*          */
  719. Video7EndSetBank:
  720. ;*
  721. ;       mov     dl, 0c4h                ;SEQ index address.     /*          */
  722. ;       mov     al, 006h                ;Lock register index    /*          */
  723.         pop     ax                      ;Restore lock idx&unlock/*          */
  724.         out     dx, ax                  ;Output both index&data /*          */
  725. ;       mov     al, ah                  ;                       /*          */
  726. ;       inc     dx                      ;SEQ data address       /*          */
  727. ;       out     dx, al                  ;                       /*          */
  728. ;       dec     dx                      ;SEQ index address.     /*          */
  729. ;*
  730.         mov     al, ch                  ;Restore SEQ index.     /*          */
  731. ;       mov     dl, 0c4h                ;SEQ index address.     /*          */
  732.         out     dx, al                  ;Restore SEQ index
  733.         ret
  734.  
  735. Video7SetBank   ENDP
  736.  
  737. ;/****************************************************************************
  738. ;*
  739. ;* FUNCTION NAME = WDSetBank
  740. ;*
  741. ;* DESCRIPTION   = Set bank. No error checking or indication.
  742. ;*
  743. ;* INPUT         = CX Bank, DX Direction and DI video mode
  744. ;* OUTPUT        = NONE
  745. ;*
  746. ;* RETURN-NORMAL = NONE.
  747. ;* RETURN-ERROR  = NONE
  748. ;*
  749. ;****************************************************************************/
  750.  
  751. WDSetBank       PROC    NEAR
  752.  
  753.         mov     dx, 03c4h               ;SEQ index address
  754.         in      al, dx
  755.         mov     ch, al                  ;Save SEQ index         /*          */
  756. ;
  757.         mov     ax, 04048h              ;Test index.
  758.         out     dx, al                  ;Write 7 bit index.
  759.         in      al, dx                  ;Read 3 bits locked, 6 bits unlocked
  760.         or      ah, al                  ;Add in required for (un)lock.
  761.         mov     al, 006h                ;PR20 index             /*          */
  762.         push    ax                      ;Save PR20index&(un)lock/*          */
  763. ;*
  764.         mov     ah, 048h                ;Unlock SEQ             /*          */
  765.         out     dx, ax                  ;Output both index&data /*          */
  766. ;       mov     al, ah                                          /*          */
  767. ;       inc     dx                      ;SEQ data address       /*          */
  768. ;       out     dx, al                                          /*          */
  769. ;       dec     dx                      ;SEQ index address.     /*          */
  770. ;*
  771.         mov     al, 011h                ;PR31 index             /*          */
  772. ;       mov     dl, 0c4h                ;SEQ index address      /*          */
  773.         out     dx, al                  ;Fix System Interface reg
  774.         inc     dx                      ;SEQ data address
  775.         in      al, dx
  776.         and     al, 07fh                ;clear bit 7
  777.         out     dx, al                  ;restore reg
  778.         dec     dx                      ;SEQ index address      /*          */
  779. ;*
  780.         mov     al, 014h                ;PR34 index Dsp Mem Map /*          */
  781. ;       mov     dl, 0c4h                ;SEQ index address      /*          */
  782.         out     dx, al                  ;Idx Display Mem Map reg/*          */
  783.         inc     dx                      ;SEQ data address       /*          */
  784.         in      al, dx                  ;Get Display Mem Map reg/*          */
  785.         and     al, 0bfh                ;clear bit 6=PR0A bit 8 /*          */
  786.         mov     ah, cl                  ;Get bank               /*          */
  787.         and     ah, 010h                ;Get 4th bit of bank    /*          */
  788.         shl     ah, 2                   ;Move to PR0A bit 8     /*          */
  789.         or      al, ah                  ;Add in new PR0A bit 8  /*          */
  790.         out     dx, al                  ;restore reg            /*          */
  791.         dec     dx                      ;SEQ index address      /*          */
  792. ;*
  793.         pop     ax                      ;Restore PR20index&unlck/*          */
  794. ;       mov     dl, 0c4h                ;SEQ index address      /*          */
  795.         out     dx, ax                  ;Output both index&data /*          */
  796. ;       mov     al, ah                                          /*          */
  797. ;       inc     dx                      ;SEQ data address       /*          */
  798. ;       out     dx, al                  ;SEQ (un)lock           /*          */
  799. ;       dec     dx                      ;SEQ index address      /*          */
  800. ;*
  801.         mov     al, ch                  ;Restore SEQ index      /*          */
  802.         out     dx, al
  803. ;*
  804.         mov     dl, 0ceh                ;GDC index address      /*          */
  805.         in      al, dx
  806.         mov     ch, al                  ;Save GDC index         /*          */
  807. ;*
  808.         mov     ax, 00f0fh              ;PR05 index (twice)
  809.         out     dx, al                  ;Are GDC's locked?
  810.         inc     dx                      ;GDC data address
  811.         in      al, dx                  ;Get (un)lock
  812.         xchg    al, ah                  ;Xchg index&unlock      /*          */
  813.         push    ax                      ;Save PR05index&(un)lock/*          */
  814.         mov     al, 005h                ;Unlock GDC             /*          */
  815.         out     dx, al                  ;                       /*          */
  816.         dec     dx                      ;GDC index address      /*          */
  817. ;*
  818.         mov     al, 00bh                ;                       /*          */
  819. ;       mov     dl, 0ceh                ;GDC index address      /*          */
  820.         out     dx, al                  ;fix memory size reg
  821.         inc     dx                      ;GDC data address
  822.         in      al, dx
  823.         and     al, 0f7h                ;clear bit 3            /*          */
  824.         out     dx, al
  825.         dec     dx                      ;GDC index address      /*          */
  826. ;*
  827.         mov     ah, cl                  ;                       /*          */
  828.         shl     ah, 4                   ;Get the bank           /*          */
  829.         mov     al, 009h                ;PROA index
  830. ;       mov     dl, 0ceh                ;GDC index address      /*          */
  831.         out     dx, ax                  ;Output both index&data /*          */
  832. ;       mov     al, ah                  ;                       /*          */
  833. ;       inc     dx                      ;GDC data address       /*          */
  834. ;       out     dx, al                  ;                       /*          */
  835. ;       dec     dx                      ;GDC index address      /*          */
  836. ;*
  837. ;       mov     al, 00fh                ;PR05 index             /*          */
  838.         pop     ax                      ;Restore PR05index&unlck/*          */
  839. ;       mov     dl, 0ceh
  840.         out     dx, ax                  ;Output both index&data /*          */
  841. ;       mov     al, ah                  ;                       /*          */
  842. ;       inc     dx                      ;GDC data address       /*          */
  843. ;       out     dx, al                  ;GDC (un)lock
  844. ;       dec     dx                      ;GDC index address      /*          */
  845. ;*
  846.         mov     al, ch                  ;Restore GDC index
  847. ;       mov     dl, 0ceh                ;GDC index address      /*          */
  848.         out     dx, al
  849.         ret
  850.  
  851. WDSetBank       ENDP
  852.  
  853. ;*                                                              /*          */
  854. ;/****************************************************************************
  855. ;*
  856. ;* FUNCTION NAME = WeitekSetBank
  857. ;*
  858. ;* DESCRIPTION   = Set bank. No error checking or indication.
  859. ;*
  860. ;* INPUT         = CX Bank, DX Direction and DI video mode
  861. ;* OUTPUT        = NONE
  862. ;*
  863. ;* RETURN-NORMAL = NONE.
  864. ;* RETURN-ERROR  = NONE
  865. ;*
  866. ;****************************************************************************/
  867.  
  868. WeitekSetBank   PROC    NEAR
  869.  
  870.         .if     <[_sSVGA.ChipType] e WEITEK_P9000_CHIP>
  871.             push    bx
  872.             push    [_sSVGA.ChipType]
  873.             mov     ax, word ptr [SvgaOEMInfo.ManufacturerData][1*word]
  874.             mov     [_sSVGA.ChipType], ax
  875.             mov     bx, word ptr [SvgaOEMInfo.ManufacturerData][0*word]
  876.             shl     bx, 1
  877.             call    [SVGA_SET_BANK_TABLE][bx]
  878.             pop     [_sSVGA.ChipType]
  879.             pop     bx
  880.         .else                           ;Just VGA, not coprocessor:
  881.             mov     dx, 003c5h          ;SEQ index address.
  882.             mov     al, 011h            ;SEQ Misc Reg.
  883.             out     dx, al
  884.             inc     dx                  ;SEQ data address.
  885.             in      al, dx              ;Get possibly FAKE current contents.
  886.             out     dx, al              ;Write out twice to unlock.
  887.             out     dx, al              ;Write out twice to unlock.
  888.             in      al, dx              ;Get REAL current contents.
  889. ;
  890. ;!!         Don't really have to set control register lock!?
  891. ;
  892.             and     al, not 040h        ;Turn off Bank Switch Disable.
  893.             out     dx, al              ;Write out again.
  894.             and     cl, 00fh            ;Prevent bank overrun.
  895.             mov     al, cl              ;Get the bank.
  896.             shl     al, 4               ;Shift to read bank position (7:4).
  897.             or      al, cl              ;Merge read & write banks.
  898.             mov     dl, 0cdh            ;WEITEK Bank Select address.
  899.             out     dx, al              ;Set the banks.
  900.         .endif
  901.         ret
  902.  
  903. WeitekSetBank   ENDP
  904.  
  905. ;/****************************************************************************
  906. ;*
  907. ;* FUNCTION NAME = NOPGetBank
  908. ;*
  909. ;* DESCRIPTION   = Get bank. No error checking or indication.
  910. ;*
  911. ;* INPUT         = DX Direction and DI video mode
  912. ;* OUTPUT        = AX Bank
  913. ;*
  914. ;* RETURN-NORMAL = NONE.
  915. ;* RETURN-ERROR  = NONE
  916. ;*
  917. ;****************************************************************************/
  918.  
  919. NOPGetBank      PROC    NEAR
  920.  
  921.         xor     ax, ax
  922.         ret
  923.  
  924. NOPGetBank      ENDP
  925.  
  926. ;/****************************************************************************
  927. ;*
  928. ;* FUNCTION NAME = ATIGetBank
  929. ;*
  930. ;* DESCRIPTION   = Get bank. No error checking or indication.
  931. ;*
  932. ;* INPUT         = DX Direction and DI video mode
  933. ;* OUTPUT        = AX Bank
  934. ;*
  935. ;* RETURN-NORMAL = NONE.
  936. ;* RETURN-ERROR  = NONE
  937. ;*
  938. ;****************************************************************************/
  939.  
  940. ATIGetBank      PROC    NEAR
  941.         mov     cl, dl                  ;Remember the direction /*          */
  942.         .if     <[_sSVGA.ChipType] ae ATI_88800_CHIP> ;         /*          */
  943.             mov     dx, 056ech          ;MEM_VGA_WPS0           /*          */
  944.             .if     <cl e READ_BANK>    ;                       /*          */
  945.                 mov     dx, 05aech      ;MEM_VGA_RPS0           /*          */
  946.             .endif                      ;                       /*          */
  947.             in      ax, dx              ;                       /*          */
  948.             shr     al, 001h            ;Convert to 64K page num/*          */
  949.             cbw                         ;Extend to fullword     /*          */
  950.         .else                           ;                       /*          */
  951. ;
  952. ;       Note: ATI index register value does not remain the same after use!
  953. ;       So there is no use saving and restoring it.
  954. ;       And you must re-index to re-write a read value.
  955. ;
  956.             mov     al, 0beh            ;ATI3D Miscellaneous register.
  957.             mov     dx, 001ceh
  958.             out     dx, al              ;misc register
  959.             inc     dx
  960.             in      al, dx              ;Get bank mode.
  961.             dec     dx
  962.             mov     ch, al
  963. ;*
  964.             mov     al, 0b2h            ;ATI32 Memory Page Select register.
  965.             out     dx, al              ; memory page select
  966.             inc     dx
  967.             in      al, dx
  968.             ror     al, 1
  969.             test    ch, 008h            ;if bit set, dual page mode
  970.             .if     < ne >
  971.                 .if     <cl e READ_BANK>
  972.                     ror     al, 4
  973.                 .endif
  974.             .endif
  975.             and     ax, 00fh
  976.         .endif                          ;                       /*          */
  977.         ret
  978.  
  979. ATIGetBank      ENDP
  980.  
  981. ;/****************************************************************************
  982. ;*
  983. ;* FUNCTION NAME = CirrusGetBank
  984. ;*
  985. ;* DESCRIPTION   = Get bank. No error checking or indication.
  986. ;*
  987. ;* INPUT         = DX Direction and DI video mode
  988. ;* OUTPUT        = AX Bank
  989. ;*
  990. ;* RETURN-NORMAL = NONE.
  991. ;* RETURN-ERROR  = NONE
  992. ;*
  993. ;****************************************************************************/
  994.  
  995. CirrusGetBank   PROC    NEAR
  996.  
  997.         mov     dx, 03c4h
  998.         in      al, dx
  999.         mov     ah, al                  ;Save SEQ index.
  1000. ;*
  1001.         mov     al, 006h                ;Get lock index.
  1002.         out     dx, al
  1003.         inc     dx                      ;SEQ data address
  1004.         in      al, dx                  ;Get lock value.
  1005.         push    ax                      ;Save lock & SEQ index  /*          */
  1006.         mov     al, 012h                ;Unlock it now.         /*          */
  1007.         out     dx, al                  ;                       /*          */
  1008. ;*
  1009.         mov     dl, 0ceh                ;GDC address            /*          */
  1010.         in      al, dx
  1011.         mov     ah, al                  ;Save GDC index.
  1012. ;*
  1013.         mov     al, 00bh                ;Mode extn register
  1014.         out     dx, al
  1015.         inc     dx                      ;GDC data address       /*          */
  1016.         in      al, dx
  1017.         dec     dx                      ;GDC index address      /*          */
  1018.         mov     ch, al                  ;Remember granularity.  /*          */
  1019. ;*
  1020.         and     al, 001h                ;Get offset register.   /*          */
  1021.         add     al, 009h                ;Offset reg 0@9, 1@10   /*          */
  1022.         out     dx, al                  ;Address the offset reg
  1023.         inc     dx                      ;GDC data address
  1024.         in      al, dx
  1025.         dec     dx                      ;GDC index address      /*          */
  1026.         test    ch, 020h                ;2MB Addressing?        /*          */
  1027.         .if     < nz >                  ;If yes:                /*          */
  1028.             and     al, 07fh
  1029.             shr     al, 2
  1030.         .else
  1031.             shr     al, 4
  1032.         .endif
  1033.         mov     cl, al                  ;Save current bank.     /*          */
  1034. ;*
  1035.         mov     al, ah                  ;Restore GDC index.
  1036.         out     dx, al                  ; 
  1037. ;*
  1038.         pop     ax                      ;Restore SEQ idx&(un)lck/*          */
  1039.         mov     dl, 0c4h + 001h         ;SEQ data address       /*          */
  1040.         out     dx, al                  ;Index still set!
  1041.         dec     dx                      ;SEQ index address      /*          */
  1042. ;*
  1043.         mov     al, ah                  ;Restore SEQ index      /*          */
  1044.         out     dx, al                  ; 
  1045. ;*
  1046.         mov     al, cl                  ;                       /*          */
  1047.         cbw                             ;                       /*          */
  1048.         ret
  1049.  
  1050. CirrusGetBank   ENDP
  1051.  
  1052. ;/****************************************************************************
  1053. ;*
  1054. ;* FUNCTION NAME = IBMGetBank
  1055. ;*
  1056. ;* DESCRIPTION   = Get bank. No error checking or indication.
  1057. ;*
  1058. ;* INPUT         = DX Direction and DI video mode
  1059. ;* OUTPUT        = AX Bank
  1060. ;*
  1061. ;* RETURN-NORMAL = NONE.
  1062. ;* RETURN-ERROR  = NONE
  1063. ;*
  1064. ;****************************************************************************/
  1065.  
  1066. IBMGetBank      PROC    NEAR
  1067.  
  1068.         mov     dx, [_XGAInstance]      ;                       /*          */
  1069.         add     dx, 008h                ;aperture index reg
  1070.         in      al, dx                  ;return current index value
  1071.         and     ah, ah
  1072.         ret
  1073.  
  1074. IBMGetBank      ENDP
  1075.  
  1076. ;/****************************************************************************
  1077. ;*
  1078. ;* FUNCTION NAME = S3GetBank                                   
  1079. ;*
  1080. ;* DESCRIPTION   = Get bank. No error checking or indication.
  1081. ;*
  1082. ;* INPUT         = DX Direction and DI video mode
  1083. ;* OUTPUT        = AX Bank
  1084. ;*
  1085. ;* RETURN-NORMAL = NONE.
  1086. ;* RETURN-ERROR  = NONE
  1087. ;*
  1088. ;****************************************************************************/
  1089.  
  1090. S3GetBank       PROC    NEAR                       ;           
  1091.  
  1092. ;*
  1093. ;*      Save the CRTC register index so as not to disturb applications!
  1094. ;*
  1095. ;!!What about monochrome displays!? 3b4?
  1096.         mov     dx, 03d4h
  1097.         in      al, dx
  1098.         mov     ch, al                  ;Save the current index.
  1099. ;*
  1100. ;                                                               /*           end */
  1101.         mov     ax, 0a039h              ;CR39 lock/unlock index /*          */
  1102.         out     dx, al
  1103.         inc     dx                      ;CRTC data address
  1104.         in      al, dx
  1105.         xchg    ah, al                  ;Save lock/get unlock   /*          */
  1106.         out     dx, al
  1107.         dec     dx                      ;CRTC index address
  1108. ;*
  1109.         xor     cl, cl
  1110.         .if     <[_sSVGA.ChipType] ae S3_86C864_CHIP>
  1111.             mov     al, 06ah            ;Ext System Ctrl Reg 4.
  1112.             out     dx, al
  1113.             inc     dx                  ;CRTC data address
  1114.             in      al, dx              ;read ext system cntl reg
  1115.             dec     dx                  ;CRTC index address     /*          */
  1116.             mov     cl, al              ;Extend the bank number.
  1117.         .endif
  1118. ;*
  1119.         mov     al, 039h                ;CR39 lock/unlock index /*          */
  1120.         .if     <zero cl>
  1121.             mov     al, 051h            ;Ext System Ctrl Reg 2.
  1122.             out     dx, al
  1123.             inc     dx                  ;CRTC data address
  1124.             in      al, dx              ;read ext system cntl reg
  1125.             dec     dx                  ;CRTC index address     /*          */
  1126.             and     al, 00ch            ;Is extended bank bit set?
  1127.             shl     al, 2               ;Shift bit 2 (004h) to bit 4 (010h).
  1128.             mov     cl, al              ;Extend the bank number.
  1129. ;*
  1130.             mov     al, 039h            ;CR39 lock/unlock index /*          */
  1131.             out     dx, ax              ;Restore lock/unlock    /*          */
  1132. ;
  1133. ;!!Do we really need to avoid reading the Ext System Ctrl Reg?  /*          */
  1134. ;                                                               /*           start */
  1135.             mov     ax, 04838h          ;CR38 lock/unlock index /*          */
  1136.             out     dx, al
  1137.             inc     dx                  ;CRTC data address
  1138.             in      al, dx
  1139.             xchg    ah, al              ;Save lock/get unlock   /*          */
  1140.             out     dx, al
  1141.             dec     dx                  ;CRTC index address
  1142. ;*
  1143.             mov     al, 035h            ;Bank Select register.
  1144.             out     dx, al
  1145.             inc     dx                  ;CRTC data address
  1146.             in      al, dx              ;read bank select register
  1147.             dec     dx                  ;CRTC index address
  1148.             and     al, 00fh
  1149.             or      cl, al              ;Save bank in cl.
  1150. ;*
  1151.             mov     al, 038h            ;CR38 lock/unlock index /*          */
  1152.         .endif
  1153.         out     dx, ax                  ;Restore lock/unlock    /*          */
  1154. ;*
  1155.         mov     al, ch                  ;Restore original CRTC index.
  1156.         out     dx, al
  1157. ;*
  1158.         mov     al, cl                  ;Get back current bank.
  1159.         cbw                             ;Extend to word.
  1160.         ret
  1161.  
  1162. S3GetBank       ENDP
  1163.  
  1164. ;/****************************************************************************
  1165. ;*
  1166. ;* FUNCTION NAME = TridentGetBank
  1167. ;*
  1168. ;* DESCRIPTION   = Get bank. No error checking or indication.
  1169. ;*
  1170. ;* INPUT         = DX Direction and DI video mode
  1171. ;* OUTPUT        = AX Bank
  1172. ;*
  1173. ;* RETURN-NORMAL = NONE.
  1174. ;* RETURN-ERROR  = NONE
  1175. ;*
  1176. ;****************************************************************************/
  1177.  
  1178. TridentGetBank  PROC    NEAR
  1179.  
  1180.         xor     ax, ax                  ;Text mode current bank /*          */
  1181.         .if     <di ge MODE_PLANAR>     ;We process only graphic modes
  1182.             mov     dx, 03c4h           ;SEQ index address
  1183.             in      al, dx
  1184.             push    ax                  ;Save SEQ index         /*          */
  1185. ;*
  1186.             call    GETTRIDENTREGDEF
  1187.             mov     cx, ax              ;TRUE new def, FALSE old/*          */
  1188. ;*
  1189.             mov     al, 00bh            ;                       /*          */
  1190.             mov     dl, 0c4h            ;SEQ index address      /*          */
  1191.             out     dx, al
  1192.             inc     dx                  ;SEQ data address
  1193.             in      al, dx              ;Mode ctrl reg changed to new def
  1194.             dec     dx                  ;SEQ index address      /*          */
  1195. ;*
  1196.             mov     al, 00eh
  1197. ;           mov     dl, 0c4h            ;SEQ index address      /*          */
  1198.             out     dx, al              ; select mode ctrl reg #1
  1199.             inc     dx                  ;SEQ data address
  1200.             in      al, dx
  1201.             dec     dx                  ;SEQ index address      /*          */
  1202.             and     ax, 00fh            ;Extract current bank   /*          */
  1203. ;*
  1204.             xchg    cx, ax              ;Save current bank      /*          */
  1205.             and     ax, ax              ;Test new/old def
  1206.             .if     < z >               ;If old def: restore old def
  1207.                 mov     al, 00bh        ;AH doesn't matter!     /*          */
  1208. ;               mov     dl, 0c4h        ;SEQ index address      /*          */
  1209.                 out     dx, ax          ;Output both index&data /*          */
  1210. ;               mov     al, ah                                  /*          */
  1211. ;               inc     dx              ;SEQ data address       /*          */
  1212. ;               out     dx, al                                  /*          */
  1213. ;               dec     dx              ;SEQ index address.     /*          */
  1214.             .endif
  1215. ;*
  1216.             pop     ax                  ;Restore SEQ index.     /*          */
  1217. ;           mov     dl, 0c4h            ;SEQ index address      /*          */
  1218.             out     dx, al              ;Restore SEQ index
  1219. ;*
  1220.             mov     ax, cx              ;Restore current bank.  /*          */
  1221.         .endif
  1222.         ret
  1223.  
  1224. TridentGetBank  ENDP
  1225.  
  1226. ;/****************************************************************************
  1227. ;*
  1228. ;* FUNCTION NAME = TsengGetBank
  1229. ;*
  1230. ;* DESCRIPTION   = Get bank. No error checking or indication.
  1231. ;*
  1232. ;* INPUT         = DX Direction and DI video mode
  1233. ;* OUTPUT        = AX Bank
  1234. ;*
  1235. ;* RETURN-NORMAL = NONE.
  1236. ;* RETURN-ERROR  = NONE
  1237. ;*
  1238. ;****************************************************************************/
  1239.  
  1240. TsengGetBank    PROC    NEAR
  1241.  
  1242.         xor     al, al                  ;Assume no bank sel high.
  1243.         mov     ch, dl                  ;Save direction.
  1244.         mov     cl, byte ptr [_sSVGA.ChipType] ;                /*          */
  1245.         .if     <cl ae TSENG_ET4000W32_CHIP> ; 
  1246.             mov     dx, 003cbh          ;Get GDC Segment Select 2.
  1247.             in      al, dx              ;Read bank select high register.
  1248.             .if     <ch ne READ_BANK>   ;                       /*          */
  1249.                 shl     al, 4           ;Get write bank (1:0) instead.
  1250.             .endif                      ;                       /*          */
  1251.             and     al, 030h            ;Extract bank 5:4.
  1252.         .endif                          ; 
  1253.         mov     ah, al                  ;Save bank 5:4.
  1254.         mov     dx, 003cdh              ;Get GDC Segment Select 1.
  1255.         in      al, dx                  ;Read bank select low register.
  1256.         .if     <ch e READ_BANK>        ; 
  1257.             .if     <cl be TSENG_ET3000_CHIP> ; 
  1258.                 shl     al, 1           ;Shift 5:3 to 6:4.
  1259.             .endif                      ; 
  1260.             shr     al, 4               ;Shift 7:4 to 3:0.
  1261.         .endif                          ; 
  1262.         and     al, 00fh                ;on ET4000 bits 0-3 write bank
  1263.         .if     <cl be TSENG_ET3000_CHIP> ; 
  1264.             and     al, 007h            ;on ET3000 bits 0-2 write bank
  1265.         .endif                          ; 
  1266.         or      al, ah                  ;Add 5:4 to 3:0.
  1267.         cbw                             ;Extend to full word.
  1268.         ret                             ; 
  1269.  
  1270. TsengGetBank    ENDP
  1271.  
  1272. ;/****************************************************************************
  1273. ;*
  1274. ;* FUNCTION NAME = Video7GetBank
  1275. ;*
  1276. ;* DESCRIPTION   = Get bank. No error checking or indication.
  1277. ;*
  1278. ;* INPUT         = DX Direction and DI video mode
  1279. ;* OUTPUT        = AX Bank
  1280. ;*
  1281. ;* RETURN-NORMAL = NONE.
  1282. ;* RETURN-ERROR  = NONE
  1283. ;*
  1284. ;****************************************************************************/
  1285.  
  1286. Video7GetBank   PROC    NEAR
  1287.  
  1288.         mov     ch, dl                  ;Save the direction     /*          */
  1289.         mov     dx, 03c4h               ;SEQ index address
  1290.         in      al, dx
  1291.         push    ax                      ;Save SEQ index         /*          */
  1292. ;*
  1293.         mov     al, 006h                ;Lock register index
  1294.         out     dx, al
  1295.         inc     dx                      ;SEQ data address
  1296.         in      al, dx                  ;Not read as written    /*          */
  1297.         and     al, 001h                ;0=locked, 1=unlocked   /*          */
  1298.         mov     al, 0eah                ;Assume unlocked        /*          */
  1299.         out     dx, al                  ;Unlock it now.         /*          */
  1300.         dec     dx                      ;SEQ index address      /*          */
  1301.         .if     < z >                                           /*@V2.1MNH13*/
  1302.             mov     al, 0aeh            ;Locked instead         /*          */
  1303.         .endif                          ;0aeh=lock, 0eah=unlock /*          */
  1304.         xchg    al, ah                  ;Xchg index&unlock      /*          */
  1305.         push    ax                      ;Save lock index&(un)lck/*          */
  1306. ;*
  1307.                                         ; chipset specific
  1308. ;                                       ;HT205 or HT208         /*          */
  1309.         .if     <[_sSVGA.ChipType] be VIDEO7_HT208_CHIP>        /*@V2.1MNH13*/
  1310.             mov     al, 0f6h
  1311. ;           mov     dl, 0c4h            ;SEQ index address      /*          */
  1312.             out     dx, al
  1313.             inc     dx                  ;SEQ data address
  1314.             in      al, dx              ;Read bank select register
  1315.             dec     dx                  ;SEQ index address      /*          */
  1316.             .if     <ch e READ_BANK>                            /*@V2.1MNH13*/
  1317.                 shr     al, 2           ;Read bank bits are 2:3 /*          */
  1318.             .endif
  1319.             and     al, 003h            ;Extract the bits 1:0   /*          */
  1320.             .if     <di ne MODE_PLANAR> ;256 color bank select
  1321.                 shl     al, 2           ;Bank bits are 2:3      /*          */
  1322.                 mov     ah, al
  1323.                 mov     al, 0f9h
  1324. ;               mov     dl, 0c4h        ;SEQ index address      /*          */
  1325.                 out     dx, al
  1326.                 inc     dx              ;SEQ data address
  1327.                 in      al, dx          ;Read extended page select register
  1328.                 and     al, 001h        ;Get first bit
  1329.                 or      ah, al          ;                       /*          */
  1330.                 mov     dl, 0cch        ;Misc Output Read addr  /*          */
  1331.                 in      al, dx
  1332.                 and     al, 020h        ;Bit 5 in Misc. Output Reg is bit
  1333.                 shr     al, 4
  1334.                 or      al, ah          ;Merge bank bits.       /*          */
  1335.            .endif
  1336.         .else
  1337. ;                                       ;HT 209 chip            /*          */
  1338.             .if     <[_sSVGA.ChipType] eq VIDEO7_HT209_CHIP>    /*@V2.1MNH13*/
  1339.                 mov     al, 0e9h        ;Read bank sel
  1340.                 sub     al, ch          ;May convert to write   /*          */
  1341. ;               mov     dl, 0c4h        ;SEQ index address      /*          */
  1342.                 out     dx, al
  1343.                 inc     dx              ;SEQ data address
  1344.                 in      al, dx          ;Get bank
  1345.                 shr     al, 4           ;                       /*          */
  1346.                 .if <di b MODE_PLANAR>   ;text mode, bit 1 must be reset
  1347. ;!!                 This seems odd! Not "and al, 001h"?
  1348.                     and     al, 0fdh
  1349.                 .endif
  1350. ;               xor     ah, ah                                  /*          */
  1351.             .endif
  1352.         .endif
  1353.         mov     cl, al                  ;Save the bank          /*          */
  1354.         mov     dl, 0c4h                ;SEQ index address      /*          */
  1355. ;       mov     al, 006h                ;Lock register index    /*          */
  1356.         pop     ax                      ;Restore lock idx&unlock/*          */
  1357.         out     dx, ax                  ;Output both index&data /*          */
  1358. ;       mov     al, ah                  ;                       /*          */
  1359. ;       inc     dx                      ;SEQ data address       /*          */
  1360. ;       out     dx, al                  ;                       /*          */
  1361. ;       dec     dx                      ;SEQ index address.     /*          */
  1362. ;*
  1363.         pop     ax                      ;Restore SEQ index.     /*          */
  1364. ;       mov     dl, 0c4h                ;SEQ index address      /*          */
  1365.         out     dx, al                  ;Restore SEQ index
  1366. ;*
  1367.         mov     al, cl                  ;Return the bank        /*          */
  1368.         cbw                             ;Extend to word         /*          */
  1369.         ret
  1370.  
  1371. Video7GetBank   ENDP
  1372.  
  1373. ;/****************************************************************************
  1374. ;*
  1375. ;* FUNCTION NAME = WDGetBank
  1376. ;*
  1377. ;* DESCRIPTION   = Get bank. No error checking or indication.
  1378. ;*
  1379. ;* INPUT         = DX Direction and DI video mode
  1380. ;* OUTPUT        = AX Bank
  1381. ;*
  1382. ;* RETURN-NORMAL = NONE.
  1383. ;* RETURN-ERROR  = NONE
  1384. ;*
  1385. ;****************************************************************************/
  1386.  
  1387. WDGetBank       PROC    NEAR
  1388.  
  1389.         mov     dx, 03ceh               ;GDC index address      /*          */
  1390.         in      al, dx
  1391.         mov     ch, al                  ;Save GDC index         /*          */
  1392. ;*
  1393.         mov     ax, 00f0fh              ;PR05 index (twice)     /*          */
  1394.         out     dx, al                  ;Are GDC's locked?
  1395.         inc     dx                      ;GDC data address
  1396.         in      al, dx                  ;Get (un)lock
  1397.         xchg    al, ah                  ;Xchg index&unlock      /*          */
  1398.         push    ax                      ;Save PR05index&(un)lock/*          */
  1399.         mov     al, 005h                ;Unlock GDC             /*          */
  1400.         out     dx, al                  ;                       /*          */
  1401.         dec     dx                      ;GDC index address      /*          */
  1402. ;*
  1403.         mov     al, 009h                ;PROA index             /*          */
  1404. ;       mov     dl, 0ceh                ;GDC index address      /*          */
  1405.         out     dx, al
  1406.         inc     dx                      ;GDC data address
  1407.         in      al, dx                  ;Read bank select reg
  1408.         dec     dx                      ;GDC index address      /*          */
  1409.         shr     al, 4
  1410.         mov     cl, al                  ;Save bank
  1411. ;*
  1412. ;       mov     al, 00fh                ;PR05 index             /*          */
  1413.         pop     ax                      ;Restore PR05index&unlck/*          */
  1414. ;       mov     dl, 0ceh
  1415.         out     dx, ax                  ;Output both index&data /*          */
  1416. ;       mov     al, ah                                          /*          */
  1417. ;       inc     dx                      ;GDC data address       /*          */
  1418. ;       out     dx, al                  ;GDC (un)lock
  1419. ;       dec     dx                      ;GDC index address      /*          */
  1420. ;*
  1421.         mov     al, ch                  ;Restore GDC index
  1422. ;       mov     dl, 0ceh                ;GDC index address      /*          */
  1423.         out     dx, al
  1424. ;*
  1425.         mov     dl, 0c4h                ;SEQ index address
  1426.         in      al, dx
  1427.         mov     ch, al                  ;Save SEQ index         /*          */
  1428. ;*
  1429.         mov     ax, 04048h              ;Test index.
  1430.         out     dx, al                  ;Write 7 bit index.
  1431.         in      al, dx                  ;Read 3 bits locked, 6 bits unlocked
  1432.         or      ah, al                  ;Add in required for (un)lock.
  1433.         mov     al, 006h                ;PR20 index             /*          */
  1434.         push    ax                      ;Save PR20index&(un)lock/*          */
  1435. ;*
  1436.         mov     ah, 048h                ;Unlock SEQ             /*          */
  1437.         out     dx, ax                  ;Output both index&data /*          */
  1438. ;       mov     al, ah                                          /*          */
  1439. ;       inc     dx                      ;SEQ data address       /*          */
  1440. ;       out     dx, al                                          /*          */
  1441. ;       dec     dx                      ;SEQ index address.     /*          */
  1442. ;*
  1443.         mov     al, 014h                ;PR34 index Dsp Mem Map /*          */
  1444. ;       mov     dl, 0c4h                ;SEQ index address      /*          */
  1445.         out     dx, al                  ;Idx Display Mem Map reg/*          */
  1446.         inc     dx                      ;SEQ data address       /*          */
  1447.         in      al, dx                  ;Get Display Mem Map reg/*          */
  1448.         dec     dx                      ;SEQ index address      /*          */
  1449.         and     al, 040h                ;get bit 6=PR0A bit 8   /*          */
  1450.         shr     al, 2                   ;Move to bank bit 4     /*          */
  1451.         or      cl, al                  ;Add in new bank bit 4  /*          */
  1452. ;*
  1453.         pop     ax                      ;Restore PR20index&unlck/*          */
  1454. ;       mov     dl, 0c4h                ;SEQ index address      /*          */
  1455.         out     dx, ax                  ;Output both index&data /*          */
  1456. ;       mov     al, ah                                          /*          */
  1457. ;       inc     dx                      ;SEQ data address       /*          */
  1458. ;       out     dx, al                  ;SEQ (un)lock           /*          */
  1459. ;       dec     dx                      ;SEQ index address      /*          */
  1460. ;*
  1461.         mov     al, ch                  ;Restore SEQ index      /*          */
  1462.         out     dx, al
  1463. ;*
  1464.         mov     al, cl                  ;Restore bank           /*          */
  1465.         cbw                             ;Extend to word         /*          */
  1466.         ret
  1467.  
  1468. WDGetBank       ENDP
  1469.  
  1470. ;*                                                              /*          */
  1471. ;/****************************************************************************
  1472. ;*
  1473. ;* FUNCTION NAME = WeitekGetBank
  1474. ;*
  1475. ;* DESCRIPTION   = Get bank. No error checking or indication.
  1476. ;*
  1477. ;* INPUT         = DX Direction and DI video mode
  1478. ;* OUTPUT        = AX Bank
  1479. ;*
  1480. ;* RETURN-NORMAL = NONE.
  1481. ;* RETURN-ERROR  = NONE
  1482. ;*
  1483. ;****************************************************************************/
  1484.  
  1485. WeitekGetBank   PROC    NEAR
  1486.  
  1487.         .if     <[_sSVGA.ChipType] e WEITEK_P9000_CHIP>
  1488. ;!!         Do we call the coprocessor?                         /*          */
  1489.             push    es
  1490.             push    bx                  ;!!Do we need to?
  1491.             mov     ax, WEITEK_P9000_REGISTERS  ;High word of physical addr.
  1492.             xor     bx, bx              ;Low word of physical address.
  1493.             mov     cx, WEITEK_P9000_REGLENGTH  ;Length of area selected
  1494.             call    SVGAPhysToUVirt
  1495.             mov     ax, 00000h          ;Assume first bank.
  1496.             .if     <nc>                ;If selector returned:
  1497.                 mov     ax, word ptr es:[bx][WEITEK_P9000_SYSCONFIG]
  1498.                 shr     ax, 9
  1499.                 mov     cl, dl          ;Get direction.
  1500.                 xor     cl, WRITE_BANK  ;0 iff WRITE_BANK, 1 iff READ_BANK.
  1501.                 shr     ax, cl
  1502.                 and     ax, 00001h      ;Get actual bank number.
  1503.                 call    SVGAUnPhysToUVirt ;ES=selector to free.
  1504.             .endif                      ;Else some type of system failure!
  1505.             pop     bx
  1506.             pop     es
  1507.         .else                           ;Just VGA, not coprocessor:
  1508.             mov     ah, dl              ;Save direction.
  1509.             mov     dx, 003c5h          ;SEQ index address.
  1510.             mov     al, 011h            ;SEQ Misc Reg.
  1511.             out     dx, al
  1512.             inc     dx                  ;SEQ data address.
  1513.             in      al, dx              ;Get possibly FAKE current contents.
  1514.             out     dx, al              ;Write out twice to unlock.
  1515.             out     dx, al              ;Write out twice to unlock.
  1516.             in      al, dx              ;Get REAL current contents.
  1517.             and     al, 040h            ;Turn off Bank Switch Disable.
  1518.             .if     < nz >              ;If banking disabled:
  1519.                 xor     al, al          ;First bank!
  1520.             .else                       ;If banking enabled:
  1521.                 mov     dl, 0cdh        ;WEITEK Bank Select address.
  1522.                 in      al, dx          ;Get the banks.
  1523.                 .if     <ah e READ_BANK>
  1524.                     shr     al, 4       ;Shift from read bank position (7:4).
  1525.                 .endif
  1526.                 and     ax, 00fh        ;Prevent bank overrun.
  1527.             .endif
  1528.         .endif
  1529.         ret
  1530.  
  1531. WeitekGetBank   ENDP
  1532.  
  1533. BiosSeg ends
  1534.  
  1535.         end
  1536. ;           12/28/92 SVGA support. File created.
  1537. ;           06/04/93 F69306 Add support for S3
  1538. ;           11/01/93 D75458 Merge r206v, r206, r207 S3 code.
  1539. ;           11/05/93 D74047 Add support for S3 911/924
  1540. ;           11/05/93        Merge S3 911/924 Support
  1541. ;           03/01/94 D79562 Add support for 2M WDs
  1542. ;           05/13/94 F74819 ATI Mach8/32 check in files
  1543. ;           05/17/94        TSENGW32 fix get/setbank
  1544. ;           06/15/94        Fix Cirrus setbank
  1545. ;           07/31/94  87887 Fix Cirrus setbank to always use 16Kbyte granularity
  1546. ;           08/02/94 D89681 ATI Mach64 Get/Set Bank differs from Mach8/32
  1547. ;*   08/25/94             D       Add PCI detection via a BIOS call.
  1548.