home *** CD-ROM | disk | FTP | other *** search
/ GRIPS 2: Government Rast…rocessing Software & Data / GRIPS_2.cdr / dos / seq / src / pga.asm < prev    next >
Assembly Source File  |  1990-01-07  |  9KB  |  343 lines

  1. ;
  2. ;  National Center for Supercomputing Applications, University of Illinois
  3. ;  153 Water Resources Building
  4. ;  605 E. Springfield Ave.
  5. ;  Champaign, IL 61820
  6. ;
  7. ;  (217)244-0072
  8. ;
  9. ;  Code by Alex Wong  Spring 1986
  10. ;  C interface by Tim Krauskopf
  11. ;
  12.  
  13.         TITLE   PGA GRAPHICS RASTER DRIVER
  14.         NAME    PGA
  15.         INCLUDE DOS.MAC
  16.         SETX
  17.         DSEG
  18. ;
  19. otbase  equ     6000h           ;base location of output buffer
  20. otwptr  equ     6300h           ;output write pointer
  21. otrptr  equ     6301h           ;output read pointer
  22. pgaoff  equ     0c000h          ;offset to DMA location
  23. cboot   equ     6306h           ;cold restart flag location
  24. wboot   equ     6307h           ;warm restart flag location
  25. errf    equ     6308h           ;error enable flag
  26. ;
  27. hreset  db      43h,58h,20h,0dh ;CX--set to hex mode
  28. resetf  db      04h             ;RESETF--reset flags
  29. displa  db      0d0h,00h        ;DISPLAY--set display mode
  30. lutint  db      0ech            ;LUTINT--initialize color LUT
  31.         db      02h             ;state 2
  32. clears  db      0fh             ;CLEARS--clear screen
  33.         db      00h             ;black background
  34. normal  db      0d0h,01h
  35. ;
  36. temp    db      0               ;temporary storage
  37. buf     db      100 dup(0)
  38. ;
  39.  
  40.         ENDDS
  41.  
  42.         PSEG
  43.         PUBLIC  INITPGA,RESTPGA,PGALINEA,MAPCOLOR,PGACLEAR
  44. ;**************************************************************************
  45. ;  PGALINEA for the IBM PGA
  46. ;
  47. ;   Write a stream of colors (represented by bytes) to the PGA 
  48. ;
  49. ;   Usage:     pgalinea(x,y,colorbuffer,n,expansion)
  50. ;            x,y = point to start line
  51. ;            colorbuffer = 4 byte pointer to stream of 
  52. ;            n    bytes.
  53. ;            expansion = how much horizontal pixel expansion you want
  54. ;
  55.  
  56. PGALINEA    PROC    FAR
  57.         PUSH    BP
  58.         MOV        BP,SP
  59.         MOV     AX,[BP+X+6]       ; get color table segment
  60.         MOV     ES,AX             ; use it now
  61.  
  62.         MOV        BX,479
  63.         mov     ax,[BP+X+2]       ; get y value 0 < y < 480
  64.         sub     bx,ax
  65.         jnb     getx
  66.         xor        bx,bx             ; if less than 0, set = 0
  67. getx:
  68.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  69. ;
  70.         MOV     SI,[BP+X+4]       ; where to get the new colors
  71.  
  72.         MOV        CX,[BP+X+8]       ; number
  73.         MOV        DX,[BP+X+10]      ; expansion factor, must be >= 1
  74.  
  75.         CALL    PGALINE
  76.  
  77.         POP        BP
  78.         RET
  79. PGALINEA    ENDP
  80.         
  81. ;       
  82. ;
  83. ;       PGA routines
  84. ;
  85. ;       Alex Wong
  86. ;       March 1986
  87. ;
  88. ;
  89. ;       outspga
  90. ;
  91. ;       output a sting of bytes to the PGA buffer
  92. ;
  93. ;       INPUT:  si => start of data
  94. ;               cx =  number of bytes to send
  95. ;
  96. ;       OUTPUT: si => 1 byte past end of data
  97. ;
  98. outspga proc    near
  99.         push    bx              ;save regs
  100.         push    di
  101.         push    bp
  102.         push    es
  103.         push    dx
  104. ;
  105.         mov     bx,pgaoff
  106.         mov     es,bx           ;es = offset to pga i/o
  107.         mov     bp,otrptr       ;bp => output read pointer
  108.         mov     di,otwptr       ;di => output write pointer
  109. ;
  110. outs:   mov     bl,es:[di]      ;write pointer
  111.         inc     bl
  112.         cmp     bl,es:[bp]      ;compare write with read
  113.         je      outs            ;wait for buffer space if full
  114. ;
  115.         mov     bl,[si]         ;get the byte to output
  116. ;
  117.         push    bp
  118.         mov     bp,otbase
  119.         mov     dh,0
  120.         mov     dl,es:[di]
  121.         add     bp,dx
  122.         mov     es:[bp],bl      ;output to PGA buffer
  123.         pop     bp
  124. ;
  125.         inc     si              ;inc ptr to data
  126.         inc     byte ptr es:[di]   ;inc wptr MOD 255
  127.         loop    outs
  128. ;
  129.         pop     dx
  130.         pop     es 
  131.         pop     bp
  132.         pop     di
  133.         pop     bx
  134.         ret                     ;--return
  135. outspga endp   
  136.  
  137. ;
  138. ;
  139. ;       setpga
  140. ;
  141. ;       initializes the PGA display and sets default colors
  142. ;
  143. ;
  144. ;
  145. initpga proc    FAR
  146.         push    bx
  147.         push    cx
  148.         push    si
  149. ;
  150.         push    es
  151.         push    di
  152.         mov     bx,pgaoff
  153.         mov     es,bx
  154.         mov     di,wboot
  155.         mov     byte ptr es:[di],1      ;set warm boot flag
  156.         mov     di,errf
  157.         mov     byte ptr es:[di],1      ;set error enable flag
  158.         pop     di
  159.         pop     es
  160. ;
  161.         mov     cx,9000                 ;wait for initializations
  162. iwait:  mov     cx,cx                   ;delay loop
  163.         loop    iwait
  164. ;
  165.         mov     si,offset hreset
  166.         mov     cx,11
  167.         call    outspga                 ;clear screen, high function
  168. ;
  169.         pop     si
  170.         pop     cx
  171.         pop     bx
  172.         ret                             ;--return
  173. initpga endp
  174. ;
  175. ;       restpga
  176. ;
  177. ;       restores the PGA to the original (emulator) display
  178. ;
  179. restpga proc    FAR
  180.         mov     si,offset normal
  181.         mov     cx,2
  182.         call    outspga                 ;set to emulator screen
  183.         ret                             ;--return
  184. restpga endp
  185. ;
  186. ;       pgaline
  187. ;
  188. ;       output a line of pixels to the display
  189. ;
  190. ;       INPUT:  ax =  starting X location
  191. ;               bx =  starting Y location
  192. ;               cx =  number of pixels to write
  193. ;               dl =  expansion factor
  194. ;               es:si => sequence of pixel values in bytes, from 0-255
  195. ;                       (grey scale)   
  196. ;
  197. ;       OUTPUT: data sent to PGA
  198. ;
  199. ; note: image write command format:  D9 lline hline
  200. ;                                       lowx1 highx1
  201. ;                                       lowx2 highx2
  202. ;                                       data
  203. ;
  204. pgaline proc    near
  205.         push    si
  206.         push    di
  207.         push    ax
  208.         push    bx
  209.         push    cx
  210.         push    dx
  211. ;
  212.         push    si
  213.         push    cx
  214. ;
  215.         mov     si,offset buf
  216.         mov     byte ptr [si],0d9h       ;image write command
  217.         inc     si
  218.         mov     [si],bx         ;line number
  219.         inc     si
  220.         inc     si
  221.         mov     [si],ax         ;starting x
  222.         inc     si
  223.         inc     si
  224. multi:  add     ax,cx           ;ending x
  225.         dec     dl
  226.         jnz     multi           ;add if multiple occurances
  227.         dec     ax              ;still 1 too many
  228.         mov     [si],ax   
  229.         mov     si,offset buf   ;reset to beginning
  230.         mov     cx,7
  231.         call    outspga         ;send iwrite header
  232.         pop     dx              ;restore number of pixels
  233.         pop     di              ;di => pixel data
  234. newpix: mov     bl,es:[di]      ;get a pixel
  235.         mov     al,-1
  236. ;
  237. same:   inc     di              ;di => next pixel
  238.         inc     al              ;al = number of same pixels - 1
  239.         dec     dx
  240.         cmp     al,127
  241.         je      ddone           ;overflow
  242.         cmp     dx,0
  243.         jz      ddone           ;end of data
  244.         cmp     bl,es:[di]      ;compare current pixel with next pixel
  245.         je      same
  246. ;
  247. ddone:  mov     si,offset buf
  248.         inc     al              ;al = number of pixels to show
  249.         pop     cx              ;get expansion factor
  250.         push    cx              ;put it back on the stack
  251.         mul     cl              ;ax = total number of pixels
  252.         dec     ax              ;want count-1
  253. nxtblk: cmp     ax,128
  254.         jl      fits            ;just do it once if it fits
  255.         mov     byte ptr [si],127  ;block of 127+1 pixels
  256.         mov     [si+1],bl       ;pixel color
  257.         mov     cx,2
  258.         call    outspga         ;output to buffer
  259.         sub     ax,128
  260.         jmp     nxtblk
  261.  
  262. fits:   mov     [si],al         ;put count into buffer
  263.         mov     [si+1],bl       ;put pixel color into buffer
  264.         mov     cx,2
  265.         call    outspga         ;output this block
  266.         cmp     dx,0
  267.         jg      newpix
  268. ;
  269.         pop     dx
  270.         pop     cx
  271.         pop     bx
  272.         pop     ax
  273.         pop     di
  274.         pop     si
  275. ;
  276.         ret                     ;--return
  277. pgaline endp
  278. ;
  279. ;
  280. ;  C interface to mapcolor
  281. ;
  282. ;  usage:  mapcolor(entry,r,g,b)  all ints (0-15)
  283. ;
  284. MAPCOLOR  PROC  FAR
  285.     PUSH BP
  286.         MOV  BP,SP
  287.         MOV  CL,[BP+X]
  288.         MOV  CH,[BP+X+2]
  289.         MOV  DL,[BP+X+4]
  290.         MOV  DH,[BP+X+6]
  291.         CALL SETPAL
  292.         POP  BP
  293.         RET
  294.  
  295. MAPCOLOR        ENDP
  296.  
  297. ;       setpal
  298. ;
  299. ;       sets a color in the look up table
  300. ;
  301. ;       cl      table entry number (0-255)
  302. ;       ch      red intensity (0-15)
  303. ;       dl      green intensity (0-15)
  304. ;       dh      blue intensity (0-15)
  305. ;
  306. setpal  proc    near
  307.         push    si
  308.         push    cx
  309.  
  310.         mov     si,offset buf
  311.         mov     byte ptr [si],0eeh      ;LUT
  312.         mov     [si+1],cl               ;entry number
  313.         mov     [si+2],ch               ;red intensity
  314.         mov     [si+3],dl               ;green intensity
  315.         mov     [si+4],dh               ;blue intensity
  316.         mov     cx,5                    ;set count for outspga
  317.         call    outspga                 ;output LUT command
  318.  
  319.         pop     cx
  320.         pop     si
  321.         ret                             ;--return
  322. setpal  endp
  323.  
  324. PGACLEAR PROC FAR
  325. ;       clears the screen in high function mode
  326. ;
  327.         push  bp
  328.         mov  bp,sp
  329.         push    si
  330.         push    cx
  331.         mov     si,offset clears
  332.         mov     cx,2
  333.         call    outspga
  334.         pop     cx
  335.         pop     si
  336.         pop     bp
  337.         ret                     ;return
  338.  
  339. PGACLEAR ENDP
  340.  
  341.         ENDPS
  342.         END
  343.