home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / DRIVERS / IBMPC / EGACHAR.ASM < prev    next >
Assembly Source File  |  2000-02-11  |  7KB  |  279 lines

  1.     TITLE    EGA/VGA Fast character drawing routines.
  2.     NAME    EGACHAR
  3.     PAGE    55,132
  4.  
  5.     COMMENT    $
  6.  
  7.     Name:    egaschar, egalchar
  8.  
  9.     Function: Draws characters from the BIOS character set
  10.           to the video buffer in EGA and VGA graphics modes.
  11.  
  12.         egaschar()    - 8 x 8 character cell
  13.         egalchar()    - 8 x 14 character cell
  14.  
  15.     Caller:        Microsoft C
  16.  
  17.             void egaschar(x, y, c, n);
  18.             void egalchar(x, y, c, n);
  19.  
  20.             int    x, y;    /* co-ords of upper left pixel of char */
  21.             int    c;    /* the character */
  22.             int    n;    /* its colour */
  23.  
  24.  
  25.     Notes:
  26.         The code in these routines has been optimized for speed,
  27.         not readibility. As much as possible is put into registers.
  28.         Replication of large blocks of code has been used in some
  29.         places to avoid calling subroutines. 
  30.         Taken from J.D. MacDonald's Fastega package.
  31.  
  32.         $
  33.  
  34. EGA_DATA    segment  word public 'DATA'
  35. first8      dw        0
  36. first14        dw        0
  37. EGA_DATA    ends
  38.  
  39.  
  40. _CONST        segment  word public 'CONST'
  41. fourt        dw        14
  42. _CONST        ends
  43.  
  44.  
  45. _BSS        segment  word public 'BSS'
  46. es8        dw        ?
  47. bp8        dw        ?
  48. es14        dw        ?
  49. bp14        dw        ?      
  50. _BSS        ends
  51.  
  52. argbase        equ    2
  53.  
  54. DGROUP        GROUP    _CONST, _BSS, EGA_DATA
  55.         assume    cs:VEGA_TEXT, ds: DGROUP, ss: DGROUP, es: DGROUP
  56.  
  57.         extrn    __buffer_segment:word
  58.  
  59. VEGA_TEXT    SEGMENT    BYTE PUBLIC    'CODE'
  60.  
  61.         public    _egaschar
  62. _egaschar    proc    far
  63.  
  64.         push    bp
  65.         mov     bp,sp
  66.         push    di
  67.         push    si
  68.         cmp     first8,0        ;get address of bios table of characters
  69.         jne     sec8
  70.         inc     first8          ;done only first time this routine is called
  71.         mov     ah, 011h
  72.         mov     al, 030h
  73.         mov     bh, 03
  74.         push    bp              ;(gasp)Bios call destroys BP
  75.         int     010h
  76.         mov     ax,es
  77.         mov     es8,ax
  78.         mov     bp8,bp
  79.         pop     bp
  80. sec8:
  81.         xor     ax,ax
  82.         mov     al,byte ptr [bp+argbase+8]   ;this is the character
  83.                     ;look up location of ascii characters
  84.         mov     cl,3
  85.         shl     ax,cl            ;in bios 
  86.         add     ax,bp8             
  87.         mov     si,ax              
  88.         mov     ax,word ptr [bp+argbase+4]      ;this is x
  89.         mov     dx,ax
  90.         and     dx,7             ;break into bit and byte
  91.         mov     cl,3
  92.         sar     ax,cl
  93.         mov     [bp+argbase+8],ax  ;byte #
  94.         mov     [bp+argbase+4],dx  ;bit in byte     
  95.         mov     ax, __buffer_segment       ; segment of display buffer
  96.         mov     es,ax               
  97.         push    ds
  98.         mov     ax,es8          ; segment for bios reference
  99.         mov     ds,ax           ; used to 
  100.         mov     bx,8            ;find character
  101.         jmp     commonl
  102.  
  103. _egaschar    endp
  104.  
  105.  
  106.         public    _egalchar
  107. _egalchar    proc    far
  108.         push    bp
  109.         mov     bp,sp
  110.         push    di
  111.         push    si
  112.  
  113.         cmp     first14,0       ;works just like slettr : done again for speed
  114.         jne     sec14
  115.         inc     first14
  116.         mov     ah, 011h
  117.         mov     al, 030h
  118.         mov     bh, 02
  119.         push    bp
  120.         int     010h
  121.         mov     ax,es
  122.         mov     es14,ax
  123.         mov     bp14,bp
  124.         pop     bp
  125. sec14:
  126.  
  127.         xor     ax,ax
  128.         mov     al,byte ptr [bp+argbase+8]    
  129.         mul     fourt        
  130.         add     ax,bp14           
  131.         mov     si,ax              
  132.         mov     ax,word ptr [bp+argbase+4]  
  133.         mov     dx,ax
  134.         and     dx,7
  135.         mov     cl,3
  136.         sar     ax,cl
  137.         mov     [bp+argbase+8],ax
  138.         mov     [bp+argbase+4],dx              
  139.  
  140.         mov     ax, __buffer_segment     
  141.         mov     es,ax               
  142.         push    ds
  143.         mov     ax,es14       
  144.         mov     ds,ax      
  145.         mov     bx,14       
  146.  
  147.  
  148. commonl:
  149.             ; symbol, slettr, and llettr the same after this
  150.             ; compute location of byte to change
  151.  
  152.         mov     ax,word ptr [bp+argbase+6]         ;this is y
  153.         mov     dx,ax
  154.         shl     dx,1
  155.         shl     dx,1
  156.         add     ax,dx
  157.         mov     cl,4
  158.         shl     ax,cl
  159.         add     ax,[bp+argbase+8]  ;this is horiz byte number
  160.         mov     di,ax
  161.  
  162.         mov     dx,3ceh         ; change SET/RESET register
  163.         mov     al,00h          ; to contain the color to write.
  164.         out     dx,al
  165.         mov     dx,3cfh
  166.         mov     ax,word ptr [bp+argbase+10]     ; <-- color
  167.         out     dx,al
  168.  
  169.         mov     dx,3ceh         ;point controller to bit mask register
  170.         mov     al,08h
  171.         out     dx,al
  172.         mov     dx,3cfh
  173.         cmp     word ptr [bp+argbase+8],0ffffh  ;special case:partially off
  174.                             ;left edge of screen
  175.         je      loop2m1
  176.         cmp     word ptr [bp+argbase+8],79      ;Partially off right edge
  177.         je      loop2p1
  178.         cmp     word ptr [bp+argbase+8],80  ;totally off screen horizontally
  179.         jae     commf
  180. loop2:
  181.  
  182.         xor     ax,ax
  183.         mov     ah,ds:[si+0]            ;get pattern of current row
  184.         mov     cx,[bp+argbase+4]
  185.         shr     ax,cl                   ;shr to get two bytes
  186.         out     dx,al    
  187.         inc     byte ptr es:[di+1]      ;actual screen write
  188.         mov     al,ah
  189.         out     dx,al
  190.         inc     byte ptr es:[di]        ;write second byte
  191.         add     di,80                   ;next row
  192.         inc     si
  193.         dec     bx
  194.         jg      loop2
  195.         jmp     commf
  196. loop2m1:
  197.  
  198.         xor     ax,ax                   ;leftmost byte is off screen
  199.         mov     ah,ds:[si+0]            ;get current row pattern
  200.         mov     cx,[bp+argbase+4]
  201.         shr     ax,cl                   ;shr to get two bytes
  202.         out     dx,al    
  203.         inc     byte ptr es:[di+1]      ;actual screen write
  204.         add     di,80
  205.         inc     si
  206.         dec     bx
  207.         jg      loop2m1
  208.         jmp     commf
  209. loop2p1:
  210.  
  211.         xor     ax,ax                  ;rightmost byte is off screen
  212.         mov     ah,ds:[si+0]           ;get current row pattern
  213.         mov     cx,[bp+argbase+4]
  214.         shr     ax,cl                  ;shr to get two bytes
  215.         mov     al,ah
  216.         out     dx,al
  217.         inc     byte ptr es:[di]
  218.         add     di,80
  219.         inc     si
  220.         dec     bx
  221.         jg      loop2p1
  222.  
  223. commf:
  224.         pop     ds
  225.         pop     si
  226.         pop     di
  227.         pop     bp
  228.         ret
  229.  
  230. _egalchar    endp
  231.  
  232.     public    _zsetup
  233. _zsetup    proc    far
  234.         push    dx
  235.         push    ax
  236.  
  237.         mov     dx,3c4h         ; allow writing to all planes
  238.         mov     al,02h          ; can be changed by setmask
  239.         out     dx,al
  240.         mov     dx,3c5h
  241.         mov     al,0fh
  242.         out     dx,al
  243.  
  244.         mov     dx,3ceh         ; change ENABLE SET/RESET register
  245.         mov     al,01h          ; to use SET/RESET feature
  246.         out     dx,al
  247.         mov     dx,3cfh
  248.         mov     al,0fh
  249.         out     dx,al
  250.         pop     ax
  251.         pop     dx
  252.         ret
  253. _zsetup    endp
  254.  
  255.     public    _setmask
  256. _setmask     proc    far
  257. ;  set mask register     setmask(mask)
  258.  
  259.         push    bp
  260.         mov     bp,sp
  261.  
  262.         mov     cx,word ptr [bp+argbase+4]
  263.         mov     dx,03c4h
  264.         mov     al,2
  265.         out     dx,al
  266.         mov     dx,03c5h
  267.         mov     al,cl
  268.         out     dx,al
  269.         pop     bp
  270.         ret    
  271.  
  272. _setmask    endp
  273.  
  274.  
  275. VEGA_TEXT    ENDS
  276.  
  277.         end
  278.  
  279.