home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / CBGRX102 / ET4000.ASM < prev    next >
Assembly Source File  |  1992-08-12  |  12KB  |  420 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file ET4000.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. include grdriver.inc
  18. cseg    segment byte public 'code'
  19.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  20.  
  21.  
  22. ;--------------------------------------------------------------------------
  23. ; DRIVER HEADER
  24. ;  The following entries MUST match the structure and constant
  25. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  26. ;  The mode word should contain the following bitfields:
  27. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  28. ;     - the adapter type field should be specified
  29. ;     - the memory size field should be specified
  30. ;     - the paging mode field should be specified
  31. ;  The mode set routine will OR in the plane bitfield as it will
  32. ;  change when different color number modes are requested.
  33. ;--------------------------------------------------------------------------
  34.  
  35.     dw    offset mode_set_routine
  36.     dw    offset paging_routine
  37. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  38. ;
  39. ; The 'def_xx' fields are filled in by go32 from the corresponding
  40. ; fields of the 'GO32' environment variable
  41. ;
  42. def_tw  dw    80        ; text width
  43. def_th  dw    25        ; text height
  44. def_gw  dw    640        ; graphics width
  45. def_gh  dw    480        ; graphics height
  46. def_nc  dw    16        ; graphics colors
  47.     dw    offset driver_init_routine
  48.     dw    offset text_mode_table
  49.     dw    offset graphics_mode_table
  50.  
  51. ;
  52. ; Biggest text and graphics sizes
  53. ;
  54. Max_TW  equ    132
  55. Max_TH  equ    50
  56. Max_GWn equ    800        ; non interlaced!!!
  57. Max_GHn equ    600
  58. Max_GW  equ    1024        ; may be interlaced
  59. Max_GH  equ    768
  60.  
  61.  
  62. ;--------------------------------------------------------------------------
  63. ; TABLE OF SUPPORTED TEXT MODES
  64. ;    - keep sorted by size
  65. ;    - end with an all 0 entry
  66. ;    - BIOS field = 0xff disables it
  67. ;    - fields:
  68. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  69. ;--------------------------------------------------------------------------
  70. text_mode_table        label word
  71.     dw    80,    25,    2,    007h +  00000h
  72.     dw    40,    25,    16,    001h +  00000h
  73.     dw    80,    25,    16,    003h +  00000h
  74.     dw    80,    50,    16,    003h +  00100h
  75.     dw    100,    40,    16,    02ah +  00000h
  76.     dw    132,    25,    16,    023h +  00000h
  77.     dw    132,    28,    16,    024h +  00000h
  78.     dw    132,    44,    16,    022h +  00000h
  79. ;    dw    132,    50,    16,    061h +  00000h
  80.     dw    0,    0,    0,    000h +  00000h
  81.  
  82.  
  83. ;--------------------------------------------------------------------------
  84. ; TABLE OF SUPPORTED GRAPHICS MODES
  85. ;    - keep sorted first by colors then by size
  86. ;    - end with an all 0 entry
  87. ;    - BIOS field = 0xff disables it
  88. ;    - fields:
  89. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  90. ;--------------------------------------------------------------------------
  91. graphics_mode_table    label word
  92.     dw    320,    200,    16,    00dh +  00000h
  93.     dw    640,    200,    16,    00eh +  00000h
  94.     dw    640,    350,    16,    010h +  00000h
  95.     dw    640,    480,    16,    012h +  00000h
  96.     dw    800,    600,    16,    029h +  00000h
  97.     dw    1024,    768,    16,    037h +  00000h
  98.     dw    320,    200,    256,    013h +  00000h
  99.     dw    640,    350,    256,    02dh +  00000h
  100.     dw    640,    480,    256,    02eh +  00000h
  101.     dw    800,    600,    256,    030h +  00000h
  102.     dw    1024,    768,    256,    038h +  00000h
  103. ET4000_HiColor_Table    label word
  104.     dw    640,    350,    32768,  02dh +  00200h  ; HiColor
  105.     dw    640,    480,    32768,  02eh +  00200h  ; HiColor
  106.     dw    800,    600,    32768,  030h +  00200h  ; HiColor
  107. ET4000_HiColor_EndTable label word
  108.     dw    0,    0,    0,    000h +  00000h
  109.  
  110.  
  111. ;--------------------------------------------------------------------------
  112. ; TABLE OF SPECIAL SETUP PROCEDURES
  113. ;  You may need such procedures for:
  114. ;     -- reloading fonts on standard EGA or VGA for
  115. ;     higher resolution text modes
  116. ;     -- enable HiColor mode of some Super VGAs
  117. ;     -- Handle the parameter passing conventions of the VESA BIOS
  118. ;     -- put VGA into 256 color plane mode ("MODE X")
  119. ;     -- etc...
  120. ;  There should be one entry in the table for every non-zero
  121. ;  'setup_procedure_index' in the text and graphics mode tables.
  122. ;  The first entry in the table belongs to index 100h, and so on.
  123. ;  The special setup procedure is invoked via a near call.
  124. ;
  125. ;  Entry: DI=address of the mode record from the text or graphics
  126. ;      table to set up.
  127. ;
  128. ;  Exit:  Adapter configured
  129. ;      BX=driver mode word as it should be returned by the mode set
  130. ;         routine. Typically it involves picking up the mode word
  131. ;         from the header and OR-ing in the appropriate bitplane mode
  132. ;         bitfield. (This is not needed for text modes)
  133. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  134. ;
  135. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  136. ;--------------------------------------------------------------------------
  137. special_setup_table    label word
  138.     dw    offset  VGA_50row_mode_set
  139.     dw    offset  ET4000_HiColor_setup
  140.  
  141. ;
  142. ; Routine to set up VGA 50 row mode
  143. ; interface is described above
  144. ;
  145. VGA_50row_mode_set    proc    near
  146.     mov    ax,03h            ; set 80x25 mode
  147.     int    10h
  148.     xor    bx,bx
  149.     mov    ax,1112h        ; load 8x8 font
  150.     int    10h
  151.     ret
  152. VGA_50row_mode_set    endp
  153.  
  154. ;
  155. ; Routine to set up ET4000 HiColor modes
  156. ; interface is described above
  157. ;
  158. ET4000_HiColor_setup    proc    near
  159.     mov    al,BYTE PTR [di+6]    ; set up 256 colors w/ same WxH
  160.     xor    ah,ah
  161.     int    10h
  162.     mov    ax,10f0h
  163.     mov    bl,BYTE PTR [di+6]
  164.     int    10h            ; set up HiColor w/ same size
  165.     cmp    ax,10h            ; success ?
  166.     je    ET4000_HiColor_Success
  167.     mov    al,BYTE PTR [di+6]    ; go with the 256 color mode!
  168.     xor    ah,ah
  169.     int    10h
  170.     mov    BYTE PTR [di+6],0ffh;    ; disable this entry
  171.     mov    bx,GRD_8_PLANES
  172.     jmp    ET4000_HiColor_EndProc
  173. ET4000_HiColor_Success:
  174.     mov    bx,GRD_16_PLANES
  175. ET4000_HiColor_EndProc:
  176.     or    bx,mode_W
  177.     ret
  178. ET4000_HiColor_setup    endp
  179.  
  180.  
  181. ;--------------------------------------------------------------------------
  182. ; DRIVER INIT ROUTINE
  183. ;  called once after the driver is loaded
  184. ;  may do one or more of the followings:
  185. ;    - check for proper board type
  186. ;    - check amount of RAM on board, and:
  187. ;    -- update word in header to reflect correct amount
  188. ;    -- disable modes in the tables for which there is not enough RAM
  189. ;    - check for special equipment (HiColor DAC, etc...)
  190. ;
  191. ;  Entry: nothing
  192. ;
  193. ;  Exit:  AX=status:
  194. ;       non-zero: OK,
  195. ;       0: something went wrong (e.g. wrong adapter, etc..)
  196. ;      BX,CX,DX may be trashed
  197. ;
  198. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  199. ;--------------------------------------------------------------------------
  200. driver_init_routine    proc    far
  201.     mov    ax,10f1h        ; get DAC type
  202.     int    10h
  203.     cmp    ax,10h
  204.     jne    no_HiColor
  205.     cmp    bl,1
  206.     je    have_HiColor
  207. no_HiColor:
  208.     mov    bx,offset ET4000_HiColor_Table
  209. kill_HiColor:
  210.     mov    BYTE PTR [bx+6],0ffh;    ; invalidate mode entry
  211.     add    bx,8
  212.     cmp    bx,offset ET4000_HiColor_EndTable
  213.     jne    kill_HiColor
  214. have_HiColor:
  215.     mov    ax,1
  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: int    10h
  368.     mov    bx,GRD_1_PLANE
  369.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  370.     je    doFLAG
  371.     mov    bx,GRD_4_PLANES
  372.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  373.     je    doFLAG
  374.     mov    bx,GRD_8_PLANES
  375.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  376.     je    doFLAG
  377.     mov    bx,GRD_16_PLANES
  378.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  379.     je    doFLAG
  380.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  381. doFLAG: or    bx,mode_W
  382. RetVal: mov    cx,[di]
  383.     mov    dx,[di+2]
  384. Exit:    pop    si
  385.     pop    di
  386.     pop    ds
  387.     ret
  388. mode_set_routine    endp
  389.  
  390.  
  391. ;--------------------------------------------------------------------------
  392. ; PAGING ROUTINE
  393. ;
  394. ;  Entry: AH=read page
  395. ;      AL=write page
  396. ;
  397. ;  Exit: VGA configured.
  398. ;     AX,BX,CX,DX,SI,DI may be trashed
  399. ;
  400. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  401. ;     This code must be relocatable and may not reference any data!
  402. ;--------------------------------------------------------------------------
  403.     assume  ds:nothing, es:nothing
  404.  
  405. paging_routine  proc    far
  406.     and    al,0fh
  407.     mov    cl,4
  408.     shl    ah,cl
  409.     and    ah,0f0h
  410.     or    al,ah
  411.     mov    dx,03cdh
  412.     out    dx,al
  413.     ret
  414. paging_routine  endp
  415.  
  416.  
  417. cseg    ends
  418.     end
  419.  
  420.