home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / viewers / disp160 / drvsrc / atiultra.asm < prev    next >
Assembly Source File  |  1993-09-16  |  13KB  |  433 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file ATIULTRA.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ;
  7. ; This file is distributed under the terms listed in the document
  8. ; "copying.dj", available from DJ Delorie at the address above.
  9. ; A copy of "copying.dj" should accompany this file; if not, a copy
  10. ; should be available from where this file was obtained.  This file
  11. ; may not be distributed without a verbatim copy of "copying.dj".
  12. ;
  13. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  14. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. ;--------------------------------------------------------------------------
  16.  
  17. _TEXT    segment byte public 'CODE'
  18. _TEXT    ends
  19. DGROUP  group    _TEXT,_DATA,_BSS
  20.     assume  cs:_TEXT,ds:DGROUP
  21. _DATA    segment word public 'DATA'
  22. d@    label    byte
  23. d@w    label    word
  24. _DATA    ends
  25. _BSS    segment word public 'BSS'
  26. b@    label    byte
  27. b@w    label    word
  28. _BSS    ends
  29. _TEXT    segment byte public 'CODE'
  30.     assume  cs:_TEXT,ds:DGROUP
  31.  
  32. include grdriver.inc
  33.  
  34. ;--------------------------------------------------------------------------
  35. ; DRIVER HEADER
  36. ;  The following entries MUST match the structure and constant
  37. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  38. ;  The mode word should contain the following bitfields:
  39. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  40. ;     - the adapter type field should be specified
  41. ;     - the memory size field should be specified
  42. ;     - the paging mode field should be specified
  43. ;  The mode set routine will OR in the plane bitfield as it will
  44. ;  change when different color number modes are requested.
  45. ;--------------------------------------------------------------------------
  46.  
  47.     dw    offset mode_set_routine
  48.     dw    offset paging_routine
  49. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_256K+GRD_RW_64K
  50. ;
  51. ; The 'def_xx' fields are filled in by go32 from the corresponding
  52. ; fields of the 'GO32' environment variable
  53. ;
  54. def_tw  dw    80        ; text width
  55. def_th  dw    25        ; text height
  56. def_gw  dw    640        ; graphics width
  57. def_gh  dw    480        ; graphics height
  58. def_nc  dw    16        ; graphics colors
  59.     dw    offset driver_init_routine
  60.     dw    offset text_mode_table
  61.     dw    offset graphics_mode_table
  62.  
  63. ;
  64. ; Biggest text and graphics sizes
  65. ;
  66. Max_TW  equ    132
  67. Max_TH  equ    44
  68. Max_GWn equ    800        ; non interlaced!!!
  69. Max_GHn equ    600
  70. Max_GW  equ    1024        ; may be interlaced
  71. Max_GH  equ    768
  72.  
  73.  
  74. ;--------------------------------------------------------------------------
  75. ; TABLE OF SUPPORTED TEXT MODES
  76. ;    - keep sorted by size
  77. ;    - end with an all 0 entry
  78. ;    - BIOS field = 0xff disables it
  79. ;    - fields:
  80. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  81. ;--------------------------------------------------------------------------
  82. text_mode_table        label word
  83.     dw    80,    25,    2,    007h +  00000h
  84.     dw    40,    25,    16,    001h +  00000h
  85.     dw    80,    25,    16,    003h +  00000h
  86.     dw    80,    50,    16,    003h +  00100h
  87.     dw    132,    25,    16,    023h +  00000h
  88.     dw    132,    44,    16,    033h +  00000h
  89.     dw    0,    0,    0,    000h +  00000h
  90.  
  91. ;--------------------------------------------------------------------------
  92. ; TABLE OF SUPPORTED GRAPHICS MODES
  93. ;    - keep sorted first by colors then by size
  94. ;    - end with an all 0 entry
  95. ;    - BIOS field = 0xff disables it
  96. ;    - fields:
  97. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  98. ;--------------------------------------------------------------------------
  99. graphics_mode_table    label word
  100.     dw    320,    200,    16,    00dh +  00000h
  101.     dw    640,    200,    16,    00eh +  00000h
  102.     dw    640,    350,    16,    010h +  00000h
  103.     dw    640,    480,    16,    012h +  00000h
  104.     dw    800,    600,    16,    054h +  00000h
  105.     dw    1024,    768,    16,    055h +  00000h
  106.     dw    320,    200,    256,    013h +  00000h
  107.     dw    640,    400,    256,    061h +  00000h
  108. begin_8514_modes    label word
  109.     dw    640,    480,    256,    000h +  00300h     ; use 8514 mode
  110.     dw    1024,    768,    256,    001h +  00300h     ; use 8514 mode
  111.     dw    0,    0,    0,    000h +  00000h
  112.  
  113. ;--------------------------------------------------------------------------
  114. ; TABLE OF SPECIAL SETUP PROCEDURES
  115. ;  You may need such procedures for:
  116. ;     -- reloading fonts on standard EGA or VGA for
  117. ;     higher resolution text modes
  118. ;     -- enable HiColor mode of some Super VGAs
  119. ;     -- Handle the parameter passing conventions of the VESA BIOS
  120. ;     -- put VGA into 256 color plane mode ("MODE X")
  121. ;     -- etc...
  122. ;  There should be one entry in the table for every non-zero
  123. ;  'setup_procedure_index' in the text and graphics mode tables.
  124. ;  The first entry in the table belongs to index 100h, and so on.
  125. ;  The special setup procedure is invoked via a near call.
  126. ;
  127. ;  Entry: DI=address of the mode record from the text or graphics
  128. ;      table to set up.
  129. ;
  130. ;  Exit:  Adapter configured
  131. ;      BX=driver mode word as it should be returned by the mode set
  132. ;         routine. Typically it involves picking up the mode word
  133. ;         from the header and OR-ing in the appropriate bitplane mode
  134. ;         bitfield. (This is not needed for text modes)
  135. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  136. ;
  137. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  138. ;--------------------------------------------------------------------------
  139. special_setup_table    label word
  140.     dw    offset  VGA_50row_mode_set
  141.     dw    offset  VGA_MODE_X_set
  142.     dw    offset  IBM_8514_mode_set
  143.  
  144. ;
  145. ; Routine to set up VGA 50 row mode
  146. ; interface is described above
  147. ;
  148. VGA_50row_mode_set    proc    near
  149.     call    near ptr disable_8514A
  150.     mov    ax,03h            ; set 80x25 mode
  151.     int    10h
  152.     xor    bx,bx
  153.     mov    ax,1112h        ; load 8x8 font
  154.     int    10h
  155.     ret
  156. VGA_50row_mode_set    endp
  157.  
  158. ;
  159. ; Routine to set up VGA 256 color plane mode ("MODE X")
  160. ; interface is described above
  161. ; TO BE COMPLETED
  162. ;
  163. VGA_MODE_X_set        proc    near
  164.     mov    bx,mode_W
  165.     or    bx,GRD_8_X_PLANES
  166.     ret
  167. VGA_MODE_X_set        endp
  168.  
  169. ;
  170. ; Routine to set up 8514A 256 color mode
  171. ; interface is described above
  172. ;
  173. IBM_8514_mode_set    proc    near
  174.     mov    al,BYTE PTR [di+6]
  175.     xor    ah,ah
  176.     push    ax
  177.     call    near ptr setup_8514A_256_color_mode
  178.     pop    ax
  179.     mov    bx,GRD_NEW_DRIVER+GRD_8514A+GRD_8_PLANES
  180.     ret
  181. IBM_8514_mode_set    endp
  182.  
  183.  
  184. ;--------------------------------------------------------------------------
  185. ; DRIVER INIT ROUTINE
  186. ;  called once after the driver is loaded
  187. ;  may do one or more of the followings:
  188. ;    - check for proper board type
  189. ;    - check amount of RAM on board, and:
  190. ;    -- update word in header to reflect correct amount
  191. ;    -- disable modes in the tables for which there is not enough RAM
  192. ;    - check for special equipment (HiColor DAC, etc...)
  193. ;
  194. ;  Entry: nothing
  195. ;
  196. ;  Exit:  AX=status:
  197. ;       non-zero: OK,
  198. ;       0: something went wrong (e.g. wrong adapter, etc..)
  199. ;      BX,CX,DX may be trashed
  200. ;
  201. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  202. ;--------------------------------------------------------------------------
  203. driver_init_routine    proc    far
  204.     push    ds
  205.     mov    ax,cs
  206.     mov    ds,ax
  207.     call    near ptr check_8514A    ; test for 8514A
  208.     or    ax,ax
  209.     jne    have_8514A
  210.     mov    bx,offset begin_8514_modes
  211.     mov    WORD PTR [bx+6],062h    ; use SVGA mode for 640x480x256
  212.     mov    WORD PTR [bx+14],0ffh    ; invalidate 1024x768x256
  213. have_8514A:
  214.     mov    ax,1
  215.     pop    ds
  216.     ret
  217. driver_init_routine    endp
  218.  
  219.  
  220. ;--------------------------------------------------------------------------
  221. ; MODE SET ROUTINE
  222. ;  sets up a text or graphics mode as close as possible to the one
  223. ;  reguested by the user with regard to number of colors and size.
  224. ;
  225. ;  Entry: AX=mode selection
  226. ;     0 = 80x25 text
  227. ;     1 = default text
  228. ;     2 = text CX cols by DX rows
  229. ;     3 = biggest text
  230. ;     4 = 320x200 graphics
  231. ;     5 = default graphics
  232. ;     6 = graphics CX width by DX height
  233. ;     7 = biggest non-interlaced graphics
  234. ;     8 = biggest graphics
  235. ;     9 = graphics BX colors, CX width by DX height
  236. ;
  237. ;  Exit: BX=driver mode flag
  238. ;     CX=width (in pixels or characters)
  239. ;     DX=height
  240. ;
  241. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  242. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  243. ;     MUCH TABLE DRIVEN
  244. ;--------------------------------------------------------------------------
  245. mode_set_routine    proc    far
  246.     push    ds
  247.     push    di
  248.     push    si
  249.     mov    si,cs
  250.     mov    ds,si
  251.     cmp    ax,9
  252.     jbe    DoIt
  253.     jmp    Exit
  254. DoIt:    add    ax,ax
  255.     mov    si,ax
  256.     jmp    WORD PTR mode_set_table[si]
  257. mode_set_table  label    word
  258.     dw    offset mode_0
  259.     dw    offset mode_1
  260.     dw    offset mode_2
  261.     dw    offset mode_3
  262.     dw    offset mode_4
  263.     dw    offset mode_5
  264.     dw    offset mode_6
  265.     dw    offset mode_7
  266.     dw    offset mode_8
  267.     dw    offset mode_9
  268. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  269.     mov    bx,def_nc
  270.     mov    cx,80
  271.     mov    dx,25
  272.     jmp    Lookup
  273. mode_1: mov    si,offset text_mode_table    ; default text
  274.     mov    bx,def_nc
  275.     mov    cx,def_tw
  276.     mov    dx,def_th
  277.     jmp    Lookup
  278. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  279.     mov    bx,def_nc
  280.     jmp    Lookup
  281. mode_3: mov    si,offset text_mode_table    ; biggest text
  282.     mov    bx,def_nc
  283.     mov    cx,Max_TW
  284.     mov    dx,Max_TH
  285.     jmp    Lookup
  286. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  287.     mov    bx,def_nc
  288.     mov    cx,320
  289.     mov    dx,200
  290.     jmp    Lookup
  291. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  292.     mov    bx,def_nc
  293.     mov    cx,def_gw
  294.     mov    dx,def_gh
  295.     jmp    Lookup
  296. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  297.     mov    bx,def_nc
  298.     jmp    Lookup
  299. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  300.     mov    bx,def_nc
  301.     mov    cx,Max_GWn
  302.     mov    dx,Max_GHn
  303.     jmp    Lookup
  304. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  305.     mov    bx,def_nc
  306.     mov    cx,Max_GW
  307.     mov    dx,Max_GH
  308.     jmp    Lookup
  309. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  310. ;
  311. ; At this point:
  312. ;   SI points to the table to search (text or graphics)
  313. ;   BX has colors
  314. ;   CX has width
  315. ;   DX has height
  316. ;
  317. Lookup: xor    ax,ax                ; last color number seen
  318. Find_C: cmp    [si+4],ax            ; last color number == this?
  319.     je    Same_C
  320.     jb    Prev_C                ; end of table -- use last color
  321.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  322.     je    Prev_C                ; not -- use last color
  323.     mov    ax,[si+4]            ; record color number
  324.     mov    di,si                ; start of entries w/ this color
  325.     cmp    ax,bx                ; enough colors ?
  326.     jae    Find_S
  327. Same_C: add    si,8
  328.     jmp    Find_C
  329. Prev_C: or    ax,ax                ; found any color at all?
  330.     je    Exit
  331. ;
  332. ; At this point:
  333. ;   DI points into the table to the first entry with the desired color
  334. ;      number (either it has enough colors or it is the highest color
  335. ;      number supported by the driver). Additionally, at least the
  336. ;      first (= smallest size) entry for this color is valid (has a
  337. ;      valid BIOS number).
  338. ;   AX has the color number adjusted for the driver
  339. ;   CX has width
  340. ;   DX has height
  341. ;
  342. Find_S: cmp    [di+4],ax            ; still the same color #?
  343.     jne    Prev_S
  344.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  345.     je    Prev_S
  346.     cmp    [di],cx
  347.     jb    Next_S
  348.     cmp    [di+2],dx
  349.     jae    GotIt
  350. Next_S: add    di,8
  351.     jmp    Find_S
  352. Prev_S: sub    di,8
  353. ;
  354. ; At this point:
  355. ;   DI points to the table entry we want to set up
  356. ;
  357. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  358.     or    ah,ah                ; special ?
  359.     je    doBIOS
  360.     mov    al,ah
  361.     xor    ah,ah
  362.     dec    ax
  363.     add    ax,ax
  364.     mov    si,ax
  365.     call    WORD PTR special_setup_table[si]
  366.     jmp    RetVal
  367. doBIOS: push    ax                ; save BIOS mode #
  368.     call    near ptr disable_8514A
  369.     pop    ax
  370.     int    10h
  371.     mov    bx,GRD_1_PLANE
  372.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  373.     je    doFLAG
  374.     mov    bx,GRD_4_PLANES
  375.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  376.     je    doFLAG
  377.     mov    bx,GRD_8_PLANES
  378.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  379.     je    doFLAG
  380.     mov    bx,GRD_16_PLANES
  381.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  382.     je    doFLAG
  383.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  384. doFLAG: or    bx,mode_W
  385. RetVal: mov    cx,[di]
  386.     mov    dx,[di+2]
  387. Exit:    pop    si
  388.     pop    di
  389.     pop    ds
  390.     ret
  391. mode_set_routine    endp
  392.  
  393.  
  394. ;--------------------------------------------------------------------------
  395. ; PAGING ROUTINE
  396. ;
  397. ;  Entry: AH=read page
  398. ;      AL=write page
  399. ;
  400. ;  Exit: VGA configured.
  401. ;     AX,BX,CX,DX,SI,DI may be trashed
  402. ;
  403. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  404. ;     This code must be relocatable and may not reference any data!
  405. ;--------------------------------------------------------------------------
  406.     assume  ds:nothing, es:nothing
  407.  
  408. paging_routine  proc    far
  409.     and    ah,0fh        ; Read-plane on bits 7-6-5
  410.     ror    ah,1
  411.     ror    ah,1
  412.     ror    ah,1
  413.  
  414.     and    al,0fh        ; Write-plane on bits 3-2-1
  415.     shl    al,1
  416.  
  417.     or    ah,al        ; Combine Read and Write plane
  418.  
  419.     mov    dx,01ceh    ; ATI register
  420.     mov    al,0b2h        ; plane select
  421.     out    dx,ax
  422.     ret
  423. paging_routine  endp
  424.  
  425. _TEXT    ends
  426.  
  427.     extrn    setup_8514A_256_color_mode:near
  428.     extrn    disable_8514A:near
  429.     extrn    check_8514A:near
  430.  
  431.     end
  432.  
  433.