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