home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / printing / ghostscrip / source / specific / asm / gdevegaa next >
Encoding:
Text File  |  1991-10-26  |  6.2 KB  |  265 lines

  1. ;    Copyright (C) 1989, 1990 Aladdin Enterprises.  All rights reserved.
  2. ;    Distributed by Free Software Foundation, Inc.
  3. ;
  4. ; This file is part of Ghostscript.
  5. ;
  6. ; Ghostscript is distributed in the hope that it will be useful, but
  7. ; WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. ; to anyone for the consequences of using it or for whether it serves any
  9. ; particular purpose or works at all, unless he says so in writing.  Refer
  10. ; to the Ghostscript General Public License for full details.
  11. ;
  12. ; Everyone is granted permission to copy, modify and redistribute
  13. ; Ghostscript, but only under the conditions described in the Ghostscript
  14. ; General Public License.  A copy of this license is supposed to have been
  15. ; given to you along with Ghostscript so you can know your rights and
  16. ; responsibilities.  It should be in a file named COPYING.  Among other
  17. ; things, the copyright notice and this notice must be preserved on all
  18. ; copies.
  19.  
  20. ; gdevegaasm.asm
  21. ; Assembly code for GhostScript EGA driver
  22.  
  23. gdevegaasm_TEXT    SEGMENT    BYTE PUBLIC 'CODE'
  24.     ASSUME    CS:gdevegaasm_TEXT
  25.  
  26. ; Note: Turbo C uses si and di for register variables, so
  27. ; we have to preserve them.
  28.  
  29. ; Normal entry and exit.  Arguments are relative to bp.
  30. enterp    macro
  31.     push    bp
  32.     mov    bp,sp
  33.     x = 6                ; offset of arguments,
  34.                     ; large code model
  35.     endm
  36. leavep    macro
  37.     pop    bp
  38.     endm
  39. ; Fast entry and exit, for procedures that don't use bx until
  40. ; they've fetched all their arguments.  Arguments are relative to ss:bx.
  41. enterf    macro
  42.     mov    bx,sp
  43.     x = 4                ; offset of arguments,
  44.                     ; large code model
  45.     endm
  46. leavef    macro
  47.     endm
  48.  
  49. ; Structure for operation parameters.
  50. ; Note that this structure is shared with C code.
  51. ; Not all parameters are used for every operation.
  52. ; typedef struct rop_params_s {
  53. p_dest    equ    0    ; fb_ptr dest;    /* pointer to frame buffer */
  54. p_draster equ    4    ; int draster;    /* raster of frame buffer */
  55. p_src    equ    6    ; byte far *src; /* pointer to source data */
  56. p_sraster equ    10    ; int sraster;    /* source raster */
  57. p_width    equ    12    ; int width;    /* width in bytes */
  58. p_height equ    14    ; int height;    /* height in scan lines */
  59. p_shift equ    16    ; int shift;    /* amount to right shift source */
  60. p_invert equ    18    ; int invert;    /* 0 or -1 to invert source */
  61. p_data    equ    20    ; int data;    /* data for fill */
  62. ; } rop_params;
  63.  
  64. ; void memsetcol(rop_params _ss *rop)
  65. ; {    byte far *addr = rop->dest;
  66. ;    int yc = rop->height;
  67. ;    while ( yc-- )
  68. ;     { byte discard = *addr;
  69. ;       *addr = rop->data;
  70. ;       addr += rop->draster;
  71. ;     }
  72. ; }
  73.     PUBLIC    _memsetcol
  74. _memsetcol proc    far
  75.     enterf
  76.     push    ds
  77.     mov    ax,ss
  78.     mov    ds,ax
  79.     mov    bx,[bx+x]            ; rop
  80.     mov    cx,[bx].p_height
  81.     jcxz    msc0                ; height == 0
  82.     mov    ax,[bx].p_data
  83.     mov    dx,[bx].p_draster
  84.     lds    bx,[bx].p_dest
  85. ; Unroll the loop -- two copies.
  86.     inc    cx        ;round up to nearest word.  cx>=2 now.
  87.     shr    cx,1        ;make byte count into word count.
  88.     jnc    msc2        ;if it had been odd, do a half word first.
  89. msc1:    mov    ah,[bx]
  90.     mov    [bx],al
  91.     add    bx,dx
  92. msc2:    mov    ah,[bx]
  93.     mov    [bx],al
  94.     add    bx,dx
  95.     loop    msc1
  96.     pop    ds
  97. msc0:    leavef
  98.     ret
  99. _memsetcol ENDP
  100.  
  101. ; void memsetrect(rop_params _ss *rop)
  102. ; {    byte far *addr = rop->dest;
  103. ;    int yc = rop->height;
  104. ;    while ( yc-- )
  105. ;     { int cnt = rop->width;
  106. ;       while ( cnt-- ) *addr++ = rop->data;
  107. ;       addr += rop->drast - rop->width;
  108. ;     }
  109. ; }
  110.     PUBLIC    _memsetrect
  111. _memsetrect proc    far
  112.     enterf
  113.     push    ds
  114.     mov    ax,ss
  115.     mov    ds,ax
  116.     mov    bx,[bx+x]            ; rop
  117.     mov    cx,[bx].p_height
  118.     jcxz    msr0                ; height == 0
  119.     push    si
  120.     push    di
  121.     mov    ax,[bx].p_data
  122.     les    di,[bx].p_dest
  123.     cld
  124.     mov    dx,[bx].p_draster
  125.     mov    si,cx                ; si = height
  126.     mov    cx,[bx].p_width
  127.     sub    dx,cx
  128.     cmp    cx,10
  129.     ja    msrl                ; large count, use fast loop
  130. ; Small count, rep stosb is faster.
  131. msrs:    mov    cx,[bx].p_width
  132.     rep    stosb
  133.     add    di,dx
  134.     dec    si                ; count reps
  135.     jnz    msrs
  136.     pop    di
  137.     pop    si
  138. msr0:    pop    ds
  139.     leavef
  140.     ret
  141. ; Large count, loop by words rather than bytes.
  142. msrl:    mov    ah,al            ;we may be storing words...
  143. msr1:    mov    cx,[bx].p_width
  144.     test    di,1            ;test for an even address
  145.     je    msr2            ;if even, we can store words.
  146.     stosb                ;otherwise we need to even it out.
  147.     dec    cx            ;(cx is at least one here)
  148. msr2:    shr    cx,1            ;convert byte count into word count
  149.     rep    stosw            ;store them puppies as fast as we can.
  150.     jnc    msr3            ;if an odd number, store it, too.
  151.     stosb                ;(no need to dec cx here).
  152. msr3:    add    di,dx
  153.     dec    si            ; count reps
  154.     jnz    msr1
  155.     pop    di
  156.     pop    si
  157.     pop    ds
  158.     leavef
  159.     ret
  160. _memsetrect ENDP
  161.  
  162. ; void memrwcol(rop_params _ss *rop)
  163. ; {    byte far *dp = rop->dest, *sp = rop->src;
  164. ;    int yc = rop->height;
  165. ;    int shift = rop->shift;
  166. ;    while ( yc-- )
  167. ;     { byte discard = *dp;
  168. ;       *dp = ((*sp >> shift) + (*sp << (8 - shift))) ^ rop->invert;
  169. ;       dp += rop->draster, sp += rop->sraster;
  170. ;     }
  171. ; }
  172.     PUBLIC    _memrwcol
  173. _memrwcol proc far
  174.     enterp
  175.     push    ds
  176.     mov    ax,ss
  177.     mov    ds,ax
  178.     mov    bx,[bp+x]            ; rop
  179.     cmp    word ptr [bx].p_height,0
  180.     jz    short mrw0
  181.     push    si
  182.     push    di
  183. ; Register usage:
  184. ;   ds:si = sp, es:di = dp, bx = sraster, dx = draster, cl = shift,
  185. ;   ch = invert, ah = low byte of yc.
  186.     push    [bx].p_height
  187.     mov    dx,[bx].p_draster
  188.     mov    ax,[bx].p_sraster
  189.     mov    cl,[bx].p_shift
  190.     mov    ch,[bx].p_invert
  191.     les    di,[bx].p_dest
  192.     lds    si,[bx].p_src
  193.     mov    bx,ax
  194.     mov    ah,[bp-8]            ; low byte of yc
  195.     test    ah,ah
  196.     jz    mrw2
  197. mrw1:    mov    al,[si]
  198.     ror    al,cl
  199.     xor    al,ch
  200.     xchg    es:[di],al
  201.     add    si,bx
  202.     add    di,dx
  203.     dec    ah
  204.     jnz    mrw1
  205. mrw2:    dec    byte ptr [bp-7]            ; high byte of yc
  206.     jge    mrw1
  207.     add    sp,2                ; pop yc
  208.     pop    di
  209.     pop    si
  210. mrw0:    pop    ds
  211.     leavep
  212.     ret
  213. _memrwcol ENDP
  214.  
  215. ; void memrwcol2(rop_params _ss *rop)
  216. ; {    byte far *dp = rop->dest, *sp = rop->src;
  217. ;    int yc = rop->height;
  218. ;    int shift = rop->shift;
  219. ;    while ( yc-- )
  220. ;     { byte discard = *dp;
  221. ;       *dp = ((sp[1] >> shift) + (*sp << (8 - shift))) ^ rop->invert;
  222. ;       dp += rop->draster, sp += rop->sraster;
  223. ;     }
  224. ; }
  225.     PUBLIC    _memrwcol2
  226. _memrwcol2 proc far
  227.     enterp
  228.     push    ds
  229.     mov    ax,ss
  230.     mov    ds,ax
  231.     mov    bx,[bp+x]            ; rop
  232.     cmp    word ptr [bx].p_height,0
  233.     jz    short mrw20
  234.     push    si
  235.     push    di
  236. ; Register usage:
  237. ;   ds:si = sp, es:di = dp, bx = sraster, dx = draster, cl = shift,
  238. ;   ch = invert.
  239.     push    [bx].p_height
  240.     mov    dx,[bx].p_draster
  241.     mov    ax,[bx].p_sraster
  242.     mov    cl,[bx].p_shift
  243.     mov    ch,[bx].p_invert
  244.     les    di,[bx].p_dest
  245.     lds    si,[bx].p_src
  246.     mov    bx,ax
  247. mrw21:    mov    ax,[si]                ; bytes are in wrong order...
  248.     ror    ax,cl
  249.     xor    ah,ch                ; ... so result is in ah
  250.     xchg    es:[di],ah
  251.     add    si,bx
  252.     add    di,dx
  253.     dec    word ptr [bp-8]            ; yc
  254.     jg    mrw21
  255.     add    sp,2                ; pop yc
  256.     pop    di
  257.     pop    si
  258. mrw20:    pop    ds
  259.     leavep
  260.     ret
  261. _memrwcol2 ENDP
  262.  
  263. gdevegaasm_TEXT    ENDS
  264.     END
  265.