home *** CD-ROM | disk | FTP | other *** search
/ GRIPS 2: Government Rast…rocessing Software & Data / GRIPS_2.cdr / dos / imdisp / source / ativga.asm next >
Encoding:
Assembly Source File  |  1990-07-30  |  7.0 KB  |  299 lines

  1. ;    ATIVGA module for IMDISP
  2. ;
  3. ;       ATIVGA contains the device dependent display routines for
  4. ;       ATI VGA Wonder graphics card with 512K memory.  These routines
  5. ;       were written specifically to support the 640x480x256, 800x600x256,
  6. ;       and 1024x768x16 modes.
  7. ;       This module was adapted, coded and tested by:
  8. ;
  9. ;                  Ron Baalke
  10. ;                  Jet Propulsion Lab
  11. ;                  M/S 301-355
  12. ;                  4800 Oak Grove Dr.
  13. ;                  Pasadena, CA 91109
  14. ;
  15. ;       These routines were written to support the IMDISP program.  There are
  16. ;       four routines which are called directly by IMDISP:
  17. ;
  18. ;              ATI_Init         - Initializes the graphics board.
  19. ;              ATI_WritePalette - Writes the color palette out to the board.
  20. ;              ATI_ReadPixel    - Reads a pixel value given x,y coordinates
  21. ;              ATI_WritePixel   - Writes a pixel value to gvin x,y coordinate.
  22. ;              ATI_Bank         - Sets the card to one of its 8 banks
  23. ;
  24. ;       Two external variables are used by this routines to indicate which
  25. ;       video is being used.  They must be initialized before any of the
  26. ;       routines in this file are called. They are:
  27. ;
  28. ;              dispns - Number of samples (columns)
  29. ;              dispnl - Number of lines (rows)
  30. ;
  31. ;       dispns = 640 selects the 640x480x256 mode
  32. ;       dispns = 800 selects the 800x500x256 mode
  33. ;       dispsn = 1024 select the 1024x768x16 mode
  34. ;
  35. ;       Also, another external variable, atibank, is used in conjunction
  36. ;       with the ATI_Bank routine to force the card to be a particular
  37. ;       bank (optional, but handy to use for clearing the screen)
  38. ;
  39.  
  40.  
  41. .model    large,c
  42. .data
  43. OSEG    equ    DS:            ;segment override for variable access
  44.  
  45. bankadr    dw    ?
  46. if @Codesize
  47. bankseg    dw    ?
  48. endif
  49.  
  50. atibank    dw    ?
  51. ativga    dw    ?
  52. retval    dw    ?        ;first return value from ATI_Init()
  53. dispns    dw    ?
  54. dispnl    dw    ?
  55. public  dispns,dispnl           ;these variables tells the routines which
  56.                                 ;graphics mode to use
  57. public  atibank
  58.  
  59. .code
  60.  
  61.     public    ATI_Init
  62.     public    ATI_WritePalette
  63.     public    ATI_WritePixel
  64.         public  ATI_ReadPixel
  65.         public  ATI_Bank
  66.  
  67. ;  ATI_Bank is used internally to select between one of 8 video banks on
  68. ;  the ATI card.
  69.  
  70. ATI_Bank    proc            ;bank number is in AX
  71.     cli
  72.     mov    OSEG[atibank],ax
  73. if @Codesize
  74.     jmp    dword ptr OSEG[bankadr]
  75. else
  76.     jmp    word ptr OSEG[bankadr]
  77. endif
  78.  
  79.  
  80.  
  81. _ativga::                        ;ATI VGA Wonder
  82.     push    ax
  83.     push    dx
  84.     mov    ah,al
  85.     mov    dx,1ceh
  86.     mov    al,0b2h
  87.     out    dx,al
  88.     inc    dl
  89.     in    al,dx
  90.     shl    ah,1
  91.     and    al,0e1h
  92.     or    ah,al
  93.     mov    al,0b2h
  94.     dec    dl
  95.     out    dx,ax
  96.     sti
  97.     pop    dx
  98.     pop    ax
  99.     ret
  100.  
  101. ATI_Bank    endp
  102.  
  103. ; ATI_Mode select the correct video mode
  104.  
  105. ATI_Mode proc
  106.         mov     ah,0h
  107.         cmp     [dispns],1024
  108.         jz      m1024                ;1024x768x16
  109.         cmp     [dispns],800
  110.         jz      m800                 ;800x600x256
  111.         mov     ax,62h               ;640x480x256
  112.         jmp     godo
  113. m800:   mov     ax,63h
  114.         jmp     godo
  115. m1024:  mov     ax,65h
  116. godo:    int    10h
  117.  
  118.     mov    [atibank],-1
  119.  
  120. nots:    ret
  121. ATI_Mode endp
  122.  
  123. ;  ATI_WritePalette writes out the color palette (256 array) out to
  124. ;  the board.
  125.  
  126. ATI_WritePalette proc    palbuf:ptr byte,begcol:word,numcol:word
  127. if @Datasize
  128.     les    dx,[palbuf]
  129. else
  130.     mov    ax,ds
  131.     mov    es,ax
  132.     mov    dx,[palbuf]
  133. endif
  134.     mov    bx,[begcol]
  135.     mov    cx,[numcol]
  136.     mov    ax,1012h
  137.     int    10h
  138.     ret
  139. ATI_WritePalette endp
  140.  
  141. ; ATI_1024addr is used internally and computes the correct address
  142. ; (1024x768x16 mode only).
  143.  
  144. ATI_1024addr    proc
  145.         clc                ; clear carry flag
  146.     push    ax            ; save this for a tad
  147.     mov    ax,dispns         ; this many dots / line
  148.     mul    dx            ; times this many lines - ans in dx:ax
  149.     add    ax,cx            ; plus this many x-dots
  150.         adc     dx,0            ; answer in dx:ax
  151.     shr    dx,1            ; shift the answer right one bit
  152.     rcr    ax,1            ;  .. in the 32-bit DX:AX combo
  153.     mov    bx,ax            ; save this in BX
  154.         cmp    dx,atibank        ; see if bank changed
  155.         je    atisame_bank        ; jump if old bank ok
  156.         mov    ax,dx            ; ATI_Bank expects bank in al
  157.         call    ATI_Bank
  158. atisame_bank:
  159.     pop    ax            ; restore AX
  160.     ret
  161. ATI_1024addr    endp
  162.  
  163. ; ATI_WritePixel writes out the color pixel at the x,y coordinate
  164.  
  165. ATI_WritePixel    proc    xpos:word,ypos:word,color:word
  166.         cmp     [dispns],1024
  167.         jz      w1024
  168.         jmp     wskip
  169. w1024:  mov     ax,0a000h
  170.         mov     es,ax
  171.     mov    cx,[xpos]
  172.     mov    dx,[ypos]
  173.     mov    ax,[color]
  174.     call    ATI_1024addr        ; calculate the address
  175.     mov    dl,es:[bx]        ; get the byte the pixel is in
  176.     and    al,00fh            ; zero out the high-order color bits
  177.     test    cl,1            ; is X odd?
  178.     jz    atiwritehigh        ;  Nope.  Use the high bits
  179.     and    dl,0f0h            ; zero out the low-order video bits
  180.     or    dl,al            ; add the two together
  181.     mov    es:[bx],dl        ; and write the results
  182.     ret
  183. atiwritehigh:
  184.     mov    cl,4            ; shift the color bits
  185.     shl    al,cl            ;  ...
  186.     and    dl,0fh            ; zero out the high-order video bits
  187.     or    dl,al            ; add the two together
  188.     mov    es:[bx],dl        ; and write the results
  189.     ret
  190. wskip:    mov    bx,[xpos]
  191.     mov    ax,[ypos]
  192.     mov    dx,[dispns]
  193.     cmp    bx,0
  194.     jl    nope1
  195.     cmp    bx,dx
  196.     jge    nope1
  197.     cmp    ax,0
  198.     jl    nope1
  199.     cmp    ax,[dispnl]
  200.     jge    nope1
  201.     mul    dx            ;800 dots wide
  202.     add    bx,ax
  203.     adc    dx,0
  204.     mov    ax,dx
  205.     cmp    ax,[atibank]
  206.     jz    nonew
  207.     call    ATI_Bank        ;switch banks if a new bank entered
  208. nonew:    mov    ax,0a000h        ;setup screen segment A000
  209.     mov    es,ax
  210.     mov    al,byte ptr [color]    ;get color of pixel to plot
  211.     mov    es:[bx],al
  212. nope1:    ret
  213. ATI_WritePixel endp
  214.  
  215. ; ATI_ReadPixel reads the pixel value at the given x,y coordinate
  216.  
  217. ATI_ReadPixel    proc    xpos:word,ypos:word
  218.         cmp     [dispns],1024
  219.         jz      r1024
  220.         jmp     rskip
  221. r1024:  mov     ax,0a000h
  222.         mov     es,ax
  223.     mov    cx,[xpos]
  224.     mov    dx,[ypos]
  225.     call    ATI_1024addr        ; calculate the address
  226.     mov    al,es:[bx]        ; get the byte the pixel is in
  227.     test    cl,1            ; is X odd?
  228.     jz    atireadhigh        ;  Nope.  Use the high bits
  229.     and    ax,0fh            ; zero out the high-order bits
  230.         mov     [retval],ax
  231.     ret
  232. atireadhigh:
  233.     and    ax,0f0h            ; zero out the low-order bits
  234.     mov    cl,4            ; shift the results
  235.     shr    al,cl            ;  ...
  236.     mov    [retval],ax
  237.         ret
  238. rskip:    mov    bx,[xpos]
  239.     mov    ax,[ypos]
  240.     mov    dx,[dispns]
  241.     cmp    bx,0
  242.     jl    nope
  243.     cmp    bx,dx
  244.     jge    nope
  245.     cmp    ax,0
  246.     jl    nope
  247.     cmp    ax,[dispnl]
  248.     jge    nope
  249.     mul    dx            ;800 dots wide
  250.     add    bx,ax
  251.     adc    dx,0
  252.     mov    ax,dx
  253.     cmp    ax,[atibank]
  254.     jz    nobank
  255.     call    ATI_Bank        ;switch banks if a new bank entered
  256. nobank:    mov    ax,0a000h        ;setup screen segment A000
  257.     mov    es,ax
  258.         mov     ax, byte ptr es:[bx]    ;get color pixel
  259.     mov    [retval],ax
  260. nope:    ret
  261. ATI_ReadPixel endp
  262.  
  263.  
  264. bkadr    macro    func
  265.     mov    [func],1
  266.     mov    [bankadr],offset _&func
  267. if @Codesize
  268.     mov    [bankseg],seg _&func
  269. endif
  270.     endm
  271.  
  272. nojmp    macro
  273.     local    lbl
  274.     jmp    lbl
  275. lbl:
  276.     endm
  277.  
  278.  
  279. ATI_Init proc    uses si
  280.     mov    [atibank],0
  281.     mov    [ativga],0
  282.     bkadr    ativga
  283.     cli
  284.     mov    dx,1ceh
  285.     mov    al,0bbh
  286.     out    dx,al
  287.     inc    dl
  288.     in    al,dx
  289.     sti
  290.     and    al,20h
  291.         call    ATI_Mode
  292. fini:    mov    ax,si
  293.     mov    [retval],ax
  294.     ret
  295. ATI_Init endp
  296.  
  297.     end
  298.  
  299.