home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / viewers / disp160 / drvsrc / acumos.asm next >
Assembly Source File  |  1993-05-09  |  14KB  |  381 lines

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