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

  1. ;
  2. ;  EGA GRAPHICS DRIVER 
  3. ;
  4. ;  supports raster graphics on the Enhanced Adapter
  5. ;
  6. ;      Tim Krauskopf               Spring 1986
  7. ;
  8. ;  National Center for Supercomputing Applications, University of Illinois
  9. ;  153 Water Resources Building
  10. ;  605 E. Springfield
  11. ;  Champaign, IL 61820
  12. ;  (217) 244-0072
  13. ;
  14. ;
  15.         TITLE   EGA GRAPHICS RASTER DRIVER
  16.         NAME    EGA
  17.         INCLUDE DOS.MAC
  18.         SETX
  19. ;
  20. ;  Define where the registers are
  21. ;
  22. SEQ        EQU        03C4H
  23. MAPREG    EQU        2
  24. MAPMASK    EQU        03C5H
  25. GCHIP    EQU        03CEH
  26. DRREG   EQU     3
  27. MODEREG EQU     5
  28. BITREG    EQU        8
  29. BITMASK    EQU        03CFH
  30. ;
  31.         DSEG
  32. FLAG    DB      0            ; HAVE WE SET REGS UP
  33.         ENDDS
  34.  
  35.         PSEG
  36.         PUBLIC  EGAPOINT,EGALINE,EGALINE2,EGALINEA
  37.         PUBLIC    INITEGA,RESETEGA,EGAPAL
  38. ;******************************************************************
  39. ;  INITEGA
  40. ;    use the BIOS to set mode 10 on the EGA board
  41. ;
  42. INITEGA    PROC    FAR
  43.         MOV        AX,10H            ; set to hi-res mode for EGA
  44.         INT     10h                ; video
  45.         RET
  46. INITEGA    ENDP
  47.  
  48. RESETEGA    PROC    FAR
  49.         MOV        AX,3            ; set to color character mode
  50.         INT        10h
  51.         RET
  52. RESETEGA    ENDP
  53.  
  54. ;*******************************************************************
  55. ;  PALETTE 
  56. ;     set one element of the EGA's palette select
  57. ;
  58. ;  usage:  egapal(reg,setting);
  59. ;             reg (0-15)        EGA's palette regs
  60. ;             setting            one byte, what to write there
  61. ;
  62. EGAPAL    PROC    FAR
  63.         PUSH    BP
  64.         MOV        BP,SP
  65.         MOV        BL,[BP+X]        ; register #
  66.         MOV        BH,[BP+X+2]        ; value
  67.         MOV        AX,01000H        ; set palette element
  68.         INT        10h
  69.         POP        BP
  70.         RET
  71. EGAPAL    ENDP
  72.  
  73. ;*****************************************************************
  74. ;  Puts an absolute pixel in the given color
  75. ;
  76. ;   usage:   egapoint(x,y,color,table)
  77. ;            x,y = point location
  78. ;            color = integer color number  0 to 255
  79. ;            table = translation table of 256 bytes for XLAT
  80. ;
  81. ;   BUG:  will only write on black background, see egaline for
  82. ;         clearing all four planes before writing to specified planes
  83. ;         in that color
  84. ;
  85. EGAPOINT    PROC    FAR
  86.         PUSH    BP
  87.         MOV        BP,SP
  88.         MOV     AL,FLAG  
  89.         OR      AL,AL
  90.         JNZ     NOSETUP
  91.         CALL    SETUPG            ; set up the mask regs
  92.         MOV     FLAG,1            ; set the flag
  93. NOSETUP:
  94.         MOV     CX,[BP+X+8]       ; get segment of transtable
  95.         MOV     BX,[BP+X+6]       ; get offset of transtable
  96.         MOV        AX,[BP+X+4]       ; get the color param = 3rd param
  97.         PUSH DS
  98.         MOV  DS,CX                ; set ds for the transtable
  99.         XLATB                     ; pick up translated color
  100.         POP     DS
  101.         MOV        DX,MAPMASK
  102.         OUT        DX,AL             ; set the mask to this color
  103.         MOV        AX,0A000H
  104.         MOV     ES,AX             ; set for addressing
  105.         MOV        AX,[BP+X+2]       ; get y value 0 < y < 350
  106.         MOV        BX,80
  107.         MUL     BX                ; multiply by 80 bytes/line
  108.         MOV     DI,AX             ; put in DI
  109.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  110.         MOV     BX,AX             ; save it
  111.         MOV     CL,3
  112.         SHR     AX,CL             ; divide by 8
  113.         ADD     DI,AX             ; add it to di = byte offset
  114.         ;
  115.         MOV     CX,BX
  116.         AND     CX,0007H          ; save only the right three bits
  117.         MOV     BL,80H            ; here's a bit
  118.         SHR        BL,CL             ; move it over some
  119.         MOV     DX,BITMASK        ; set the mask
  120.         MOV     AL,BL             
  121.         OUT     DX,AL             ;  send it
  122. ;
  123.         MOV        AL,0FFH           ; set all bits
  124.         MOV        AH,ES:[DI]        ; latch the bytes
  125.         STOSB                     ; place that bit on bit mask
  126.  
  127.         
  128.         POP        BP
  129.         RET
  130. EGAPOINT    ENDP
  131.  
  132. SETUPG:
  133.         MOV        DX,GCHIP
  134.         MOV        AL,MODEREG
  135.         OUT        DX,AL             ; choose write mode 0
  136.         INC        DX
  137.         MOV        AL,0
  138.         OUT        DX,AL             ; clear mode reg to 0
  139.         DEC     DX
  140.         MOV        AL,DRREG          ; clear function select = Replace
  141.         OUT        DX,AL
  142.         INC     DX
  143.         MOV        AL,0h             ; clear all
  144.         OUT        DX,AL
  145. ;
  146.         MOV        AL,MAPREG         ; want to access mapreg from 
  147.         MOV        DX,SEQ            ; sequencer set of regs
  148.         OUT        DX,AL
  149.         MOV        AL,BITREG         ; want to access bitreg from
  150.         MOV     DX,GCHIP          ; graphics chip's regs
  151.         OUT        DX,AL
  152.         MOV        DX,BITMASK        ; set up the bitmask = no masking
  153.         MOV        AL,0FFH           ; all bits on
  154.         OUT        DX,AL
  155.         RET
  156. ;
  157. ;**************************************************************************
  158. ;  EGALINE
  159. ;
  160. ;   Write a stream of colors (represented by bytes) to the EGA, with 
  161. ;   a translation table for the EGA color map.
  162. ;
  163. ;   Usage:     egaline(x,y,colorbuffer,n,table)
  164. ;            x,y = point to start line
  165. ;            colorbuffer = 4 byte pointer to stream of 
  166. ;            n    bytes.
  167. ;            table  = 4 byte pointer to translation table, 256 bytes
  168. ;                      long for XLAT instruction
  169.  
  170. EGALINE    PROC    FAR
  171.         PUSH    BP
  172.         MOV        BP,SP
  173.         MOV     AL,FLAG  
  174.         OR      AL,AL
  175.         JNZ     NOSETUP2
  176.         CALL    SETUPG            ; set up the mask regs
  177.         MOV     FLAG,1            ; set the flag
  178. NOSETUP2:
  179.         PUSH    DS                ; save our ds
  180.         MOV     AX,[BP+X+6]       ; get color table segment
  181.         MOV     DS,AX             ; use it now
  182.  
  183.         MOV        AX,0A000H
  184.         MOV     ES,AX             ; set for addressing
  185.         MOV        AX,[BP+X+2]       ; get y value 0 < y < 350
  186.         MOV        BX,80
  187.         MUL     BX                ; multiply by 80 bytes/line
  188.         MOV     DI,AX             ; put in DI
  189.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  190.         MOV     BX,AX             ; save it
  191.         MOV     CL,3
  192.         SHR     AX,CL             ; divide by 8
  193.         ADD     DI,AX             ; add it to di = byte offset
  194.         ;
  195.         MOV     CX,BX
  196.         AND     CX,0007H          ; save only the right three bits
  197.         MOV     BL,080H           ; here's a bit
  198.         ROR        BL,CL             ; move it over some
  199. ;
  200. ;  At this point, bl has the bit mask for the first bit in the line
  201. ;  Keep rotating it and set the mask for each bit to write
  202. ;
  203.         MOV     CX,[BP+X+8]       ; get count of bytes
  204.         MOV     SI,[BP+X+4]       ; where to get the new colors
  205.  
  206.         MOV     AH,BL             ; keep bit rotation in ah
  207.         MOV     DX,[BP+X+12]      ; get segment of transtable
  208.         MOV     BX,[BP+X+10]      ; get offset of transtable
  209.  
  210. NEXTBIT:
  211.         LODSB                     ; get the next color to al
  212.         PUSH DS
  213.         MOV  DS,DX                ; set ds for the transtable
  214.         XLATB                     ; pick up translated color to al
  215.         PUSH AX                   ; need it later
  216.  
  217.         MOV     DX,BITMASK        ; set the bitmask to current rotation
  218.         MOV     AL,AH
  219.         OUT     DX,AL             ;  send it
  220.  
  221.         MOV        DX,MAPMASK
  222.         MOV     AL,0FH            ; open all bit planes
  223.         OUT        DX,AL             ; send it
  224.  
  225.         MOV        AL,ES:[DI]        ; latch the whole set of bytes
  226.         MOV     BYTE PTR ES:[DI],0H  ; clear all four planes to 0 at this bit
  227.         POP        AX                ; get real color back
  228.         OUT        DX,AL              ; send it to set the color planes
  229.  
  230.         MOV     DX,DS             ;  recover what was in dx
  231.         POP     DS
  232. ;
  233.         MOV        AL,0FFH           ; set all bits
  234.         CMP     AH,01             ; see if we are at end of byte
  235.         JZ      INCSTORE
  236.  
  237. NONINC:
  238.         MOV     ES:[DI],AL        ; write the bit from bitmask
  239.         ROR     AH,1              ; rotate me
  240.         LOOP    NEXTBIT          ; go back for next one
  241.         JMP     LINEDONE
  242.  
  243. INCSTORE:
  244.         STOSB                     ; place that bit on bit mask and next byte
  245.         ROR     AH,1              ; rotate me
  246.         LOOP    NEXTBIT
  247.  
  248. LINEDONE:
  249.         POP     DS        
  250.         POP        BP
  251.         RET
  252. EGALINE    ENDP
  253.  
  254.         
  255. EGALINE2    PROC    FAR
  256.         PUSH    BP
  257.         MOV        BP,SP
  258.         MOV     AL,FLAG  
  259.         OR      AL,AL
  260.         JNZ     NO2SETUP2
  261.         CALL    SETUPG            ; set up the mask regs
  262.         MOV     FLAG,1            ; set the flag
  263. NO2SETUP2:
  264.         PUSH    DS                ; save our ds
  265.         MOV     AX,[BP+X+6]       ; get color table segment
  266.         MOV     DS,AX             ; use it now
  267.  
  268.         MOV        AX,0A000H
  269.         MOV     ES,AX             ; set for addressing
  270.         MOV        AX,[BP+X+2]       ; get y value 0 < y < 350
  271.         MOV        BX,80
  272.         MUL     BX                ; multiply by 80 bytes/line
  273.         MOV     DI,AX             ; put in DI
  274.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  275.         MOV     BX,AX             ; save it
  276.         MOV     CL,3
  277.         SHR     AX,CL             ; divide by 8
  278.         ADD     DI,AX             ; add it to di = byte offset
  279.         ;
  280.         MOV     CX,BX
  281.         AND     CX,0007H          ; save only the right three bits
  282.         MOV     BL,0C0H           ; here's 2 bits
  283.         ROR        BL,CL             ; move it over some
  284. ;
  285. ;  At this point, bl has the bit mask for the first bit in the line
  286. ;  Keep rotating it and set the mask for each bit to write
  287. ;
  288.         MOV     CX,[BP+X+8]       ; get count of bytes
  289.         MOV     SI,[BP+X+4]       ; where to get the new colors
  290.  
  291.         MOV     AH,BL             ; keep bit rotation in ah
  292.         MOV     DX,[BP+X+12]      ; get segment of transtable
  293.         MOV     BX,[BP+X+10]      ; get offset of transtable
  294.  
  295. NEXT2BIT:
  296.         LODSB                     ; get the next color to al
  297.         PUSH DS
  298.         MOV  DS,DX                ; set ds for the transtable
  299.         XLATB                     ; pick up translated color to al
  300.         PUSH AX                   ; need it later
  301.  
  302.         MOV     DX,BITMASK        ; set the bitmask to current rotation
  303.         MOV     AL,AH
  304.         OUT     DX,AL             ;  send it
  305.  
  306.         MOV        DX,MAPMASK
  307.         MOV     AL,0FH            ; open all bit planes
  308.         OUT        DX,AL             ; send it
  309.  
  310.         MOV        AL,ES:[DI]        ; latch the whole set of bytes
  311.         MOV     BYTE PTR ES:[DI],0H  ; clear all four planes to 0 at this bit
  312.         POP        AX                ; get real color back
  313.         OUT        DX,AL              ; send it to set the color planes
  314.  
  315.         MOV     DX,DS             ;  recover what was in dx
  316.         POP     DS
  317. ;
  318.         MOV        AL,0FFH           ; set all bits
  319.         CMP     AH,03             ; see if we are at end of byte
  320.         JZ      INC2STORE
  321.  
  322. NON2INC:
  323.         MOV     ES:[DI],AL        ; write the bit from bitmask
  324.         ROR     AH,1              ; rotate me
  325.         ROR     AH,1              ; rotate me
  326.         LOOP    NEXT2BIT          ; go back for next one
  327.         JMP     LINE2DONE
  328.  
  329. INC2STORE:
  330.         STOSB                     ; place that bit on bit mask and next byte
  331.         ROR     AH,1              ; rotate me
  332.         ROR     AH,1              ; again
  333.         LOOP    NEXT2BIT
  334.  
  335. LINE2DONE:
  336.         POP     DS        
  337.         POP        BP
  338.         RET
  339. EGALINE2    ENDP
  340.  
  341. ;**************************************************************************
  342. ;  EGALINEA
  343. ;
  344. ;   Write a stream of colors (represented by bytes) to the EGA, with 
  345. ;   a translation table for the EGA color map.  This one includes arbitrary
  346. ;   width expansion.
  347. ;
  348. ;   Usage:     egaline(x,y,colorbuffer,n,table,expansion)
  349. ;            x,y = point to start line
  350. ;            colorbuffer = 4 byte pointer to stream of 
  351. ;            n    bytes.
  352. ;            table  = 4 byte pointer to translation table, 256 bytes
  353. ;                      long for XLAT instruction
  354. ;            expansion = how much horizontal pixel expansion you want
  355. ;
  356.  
  357. EGALINEA    PROC    FAR
  358.         PUSH    BP
  359.         MOV        BP,SP
  360.         MOV     AL,FLAG  
  361.         OR      AL,AL
  362.         JNZ     NOSETA
  363.         CALL    SETUPG            ; set up the mask regs
  364.         MOV     FLAG,1            ; set the flag
  365. NOSETA:
  366.         PUSH    DS                ; save our ds
  367.         MOV     AX,[BP+X+6]       ; get color table segment
  368.         MOV     DS,AX             ; use it now
  369.  
  370.         MOV        AX,0A000H
  371.         MOV     ES,AX             ; set for addressing
  372.         MOV        AX,[BP+X+2]       ; get y value 0 < y < 350
  373.         MOV        BX,80
  374.         MUL     BX                ; multiply by 80 bytes/line
  375.         MOV     DI,AX             ; put in DI
  376.  
  377.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  378.         MOV     BX,AX             ; save it
  379.         MOV     CL,3
  380.         SHR     AX,CL             ; divide by 8
  381.         ADD     DI,AX             ; add it to di = byte offset
  382.         ;
  383.         MOV     CX,BX
  384.         AND     CX,0007H          ; save only the right three bits
  385.         MOV     BL,080H           ; here's a bit
  386.         ROR        BL,CL             ; move it over some
  387. ;
  388. ;  At this point, bl has the bit mask for the first bit in the line
  389. ;  Keep rotating it and set the mask for each bit to write
  390. ;
  391.         MOV     SI,[BP+X+4]       ; where to get the new colors
  392.  
  393.         MOV     AH,BL             ; keep bit rotation in ah
  394.         MOV     DX,[BP+X+12]      ; get segment of transtable
  395.         MOV     BX,[BP+X+10]      ; get offset of transtable
  396.  
  397. NEXTBYTE:
  398.         MOV        CX,[BP+X+14]      ; pixel expansion number
  399.         LODSB                     ; the next color to write
  400.         PUSH     DS
  401.          MOV        DS,DX             ; get the seg for xlat from dx
  402.         XLATB                      ; color translation
  403.         MOV        [BP+X],AL         ; used as a local var for translated color
  404.  
  405. NEXTP:
  406.         MOV     DX,BITMASK        ; set the bitmask to current rotation
  407.         MOV     AL,AH
  408.         OUT     DX,AL             ;  send it
  409.  
  410.         MOV        DX,MAPMASK
  411.         MOV     AL,0FH            ; open all bit planes
  412.         OUT        DX,AL             ; send it
  413.  
  414.         MOV        AL,ES:[DI]        ; latch the whole set of bytes
  415.         MOV     BYTE PTR ES:[DI],0H  ; clear all four planes to 0 at this bit
  416.         MOV        AL,[BP+X]         ; get real color from local var
  417.         OUT        DX,AL              ; send it to set the color planes
  418. ;
  419.         MOV        AL,0FFH           ; set all bits
  420.         MOV        ES:[DI],AL          ; set it!
  421.         CMP     AH,01             ; see if we are at end of byte
  422.         JNZ     SAMEBYTE
  423.         INC        DI                ; get us to the next destination byte
  424. SAMEBYTE:
  425.         ROR     AH,1              ; rotate me
  426.         LOOP    NEXTP             ; go back for next one
  427.  
  428.         MOV        DX,DS             ; reset xlat segment into dx
  429.         POP        DS                ; get data input seg back
  430.         DEC        WORD PTR [BP+X+8] ; number of data points
  431.         JNZ        NEXTBYTE          ; do another, if necessary
  432.  
  433.         POP     DS        
  434.         POP        BP
  435.         RET
  436. EGALINEA    ENDP
  437.  
  438.         
  439.         ENDPS
  440.         END
  441.