home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / epsonx_transfer.asm < prev    next >
Encoding:
Assembly Source File  |  1992-08-20  |  8.1 KB  |  278 lines

  1. **********************************************************************
  2. *
  3. * Transfer routine for EpsonX
  4. *
  5. **********************************************************************
  6.  
  7.         INCLUDE "exec/types.i"
  8.  
  9.         INCLUDE "intuition/intuition.i"
  10.         INCLUDE "devices/printer.i"
  11.         INCLUDE "devices/prtbase.i"
  12.         INCLUDE "devices/prtgfx.i"
  13.  
  14.         XREF    _PD
  15.         XREF    _PED
  16.         XREF    _LVODebug
  17.         XREF    _AbsExecBase
  18.  
  19.         XDEF    _Transfer
  20.  
  21.         SECTION         printer,CODE
  22. _Transfer:
  23. ; Transfer(PInfo, y, ptr, colors, BufOffset)
  24. ; struct PrtInfo *PInfo         4-7
  25. ; UWORD y;                      8-11
  26. ; UBYTE *ptr;                   12-15
  27. ; UWORD *colors;                16-19
  28. ; ULONG BufOffset               20-23
  29.  
  30.         movem.l d2-d6/a2-a4,-(sp)       ;save regs used
  31.  
  32.         movea.l 36(sp),a0               ;a0 = PInfo
  33.         move.l  40(sp),d0               ;d0 = y
  34.         movea.l 44(sp),a1               ;a1 = ptr
  35.         movea.l 48(sp),a2               ;a2 = colors
  36.         move.l  52(sp),d1               ;d1 = BufOffset
  37.  
  38.         move.l  d0,d3                   ;save y
  39.         moveq.l #3,d2
  40.         and.w   d0,d2                   ;d2 = y & 3
  41.         lsl.w   #2,d2                   ;d2 = (y & 3) << 2
  42.         movea.l pi_dmatrix(a0),a3       ;a3 = dmatrix
  43.         adda.l  d2,a3                   ;a3 = dmatrix + ((y & 3) << 2)
  44.  
  45.         movea.l _PED,a4                 ;a4 = ptr to PED
  46.         cmpi.w  #216,ped_YDotsInch(a4)  ;triple interleaving?
  47.         bne.s   10$                     ;no
  48.         divu.w  #3,d0                   ;y /= 3
  49.         swap.w  d0                      ;d0 = y % 3
  50.         mulu.w  d0,d1                   ;BufOffset *= y % 3
  51.         swap.w  d0                      ;d0 = y / 3
  52.         bra.s   30$
  53.  
  54. 10$:    cmpi.w  #144,ped_YDotsInch(a4)  ;double interleaving?
  55.         bne.s   20$                     ;no, clear BufOffset
  56.         asr.w   #1,d0                   ;y /= 2
  57.         btst    #0,d3                   ;odd pass?
  58.         bne.s   30$                     ;no, dont clear BufOffset
  59.  
  60. 20$:    moveq.l #0,d1                   ;BufOffset = 0
  61.  
  62. 30$:    move.w  d0,d6
  63.         not.b   d6                      ;d6 = bit to set
  64.         adda.l  d1,a1                   ;ptr += BufOffset
  65.  
  66.         movea.l _PD,a4                  ;a4 = ptr to PD
  67.         cmpi.w  #SHADE_COLOR,pd_Preferences+pf_PrintShade(a4)   ;color dump?
  68.         bne     not_color               ;no
  69.  
  70. color:
  71.  
  72. ; a0 - PInfo
  73. ; a1 - ptr (ptr + BufOffset)
  74. ; a2 - colors
  75. ; a3 - dmatrix ptr
  76. ; d0 - y
  77. ; d1 - BufOffset
  78. ; d6 - bit to set
  79.  
  80.         movem.l d7/a5-a6,-(sp)          ;save regs used
  81.  
  82.         movea.l a1,a4
  83.         movea.l a1,a5
  84.         movea.l a1,a6
  85.         adda.w  (a2)+,a1                ;a1 = ptr + colors[0] (bptr)
  86.         adda.w  (a2)+,a4                ;a4 = ptr + colors[1] (yptr)
  87.         adda.w  (a2)+,a5                ;a5 = ptr + colors[2] (mptr)
  88.         adda.w  (a2)+,a6                ;a6 = ptr + colors[3] (cptr)
  89.  
  90. ;       move.l  a6,-(sp)
  91. ;       move.l  _AbsExecBase,a6
  92. ;       jsr     _LVODebug(a6)
  93. ;       move.l  (sp)+,a6
  94.  
  95.         movea.l pi_ColorInt(a0),a2      ;a2 = ColorInt ptr
  96.         move.w  pi_width(a0),width      ;# of pixels to do
  97.         move.w  pi_xpos(a0),d2          ;d2 = x
  98.         movea.l pi_ScaleX(a0),a0        ;a0 = ScaleX (sxptr)
  99.         move.b  d6,d7                   ;d7 = bit to set
  100.  
  101. ; a0 - sxptr
  102. ; a1 - bptr
  103. ; a2 - ColorInt ptr
  104. ; a3 - dmatrix ptr
  105. ; a4 - yptr
  106. ; a5 - mptr
  107. ; a6 - cptr
  108. ; d1 - Black
  109. ; d2 - x
  110. ; d3 - dvalue (dmatrix[x & 3])
  111. ; d4 - Yellow
  112. ; d5 - Magenta
  113. ; d6 - Cyan
  114. ; d7 - bit to set
  115.  
  116. cwidth_loop:
  117.         move.b  PCMBLACK(a2),d1         ;d1 = Black
  118.         move.b  PCMYELLOW(a2),d4        ;d4 = Yellow
  119.         move.b  PCMMAGENTA(a2),d5       ;d5 = Magenta
  120.         move.b  PCMCYAN(a2),d6          ;d6 = Cyan
  121.         addq.l  #ce_SIZEOF,a2           ;advance to next entry
  122.  
  123.         move.w  (a0)+,sx                ;# of times to use this pixel
  124.  
  125. csx_loop:
  126.         moveq.l #3,d3
  127.         and.w   d2,d3                   ;d3 = x & 3
  128.         move.b  0(a3,d3.w),d3           ;d3 = dmatrix[x & 3]
  129.  
  130. black:
  131.         cmp.b   d3,d1                   ;render black?
  132.         ble.s   yellow                  ;no, try ymc
  133.         bset.b  d7,0(a1,d2.w)           ;set black pixel
  134.         bra.s   csx_end
  135.  
  136. yellow:
  137.         cmp.b   d3,d4                   ;render yellow pixel?
  138.         ble.s   magenta                 ;no.
  139.         bset.b  d7,0(a4,d2.w)           ;set yellow pixel
  140.  
  141. magenta:
  142.         cmp.b   d3,d5                   ;render magenta pixel?
  143.         ble.s   cyan                    ;no.
  144.         bset.b  d7,0(a5,d2.w)           ;set magenta pixel
  145.  
  146. cyan:
  147.         cmp.b   d3,d6                   ;render cyan pixel?
  148.         ble.s   csx_end                 ;no, skip to next pixel.
  149.         bset.b  d7,0(a6,d2.w)           ;clear cyan pixel
  150.  
  151. csx_end:
  152.         addq.w  #1,d2                   ;x++
  153.         subq.w  #1,sx                   ;sx--
  154.         bne.s   csx_loop
  155.         subq.w  #1,width                ;width--
  156.         bne.s   cwidth_loop
  157.  
  158.         movem.l (sp)+,d7/a5-a6          ;restore regs used
  159.         bra     exit
  160.  
  161. not_color:
  162. ; a0 - PInfo
  163. ; a1 - ptr
  164. ; a2 - colors
  165. ; a3 - dmatrix ptr
  166. ; d0 - y
  167. ; d6 - bit to set
  168.  
  169.         adda.w  (a2),a1                 ;a1 = ptr + colors[0]
  170.         move.w  pi_width(a0),d1         ;d1 = width
  171.         subq.w  #1,d1                   ;adjust for dbra
  172.  
  173.         move.w  pi_threshold(a0),d3     ;d3 = threshold, thresholding?
  174.         beq.s   grey_scale              ;no, grey-scaling
  175.  
  176. threshold:
  177. ; a0 - PInfo
  178. ; a1 - ptr
  179. ; a3 - dmatrix ptr
  180. ; d1 - width-1
  181. ; d3 - threshold
  182. ; d6 - bit to set
  183.  
  184.         eori.b  #15,d3                  ;d3 = dvalue
  185.         movea.l pi_ColorInt(a0),a2      ;a2 = ColorInt ptr
  186.         move.w  pi_xpos(a0),d2          ;d2 = x
  187.         movea.l pi_ScaleX(a0),a0        ;a0 = ScaleX (sxptr)
  188.         adda.w  d2,a1                   ;ptr += x
  189.  
  190. ; a0 - sxptr
  191. ; a1 - ptr
  192. ; a2 - ColorInt ptr
  193. ; a3 - dmatrix ptr (NOT USED)
  194. ; d1 - width
  195. ; d3 - dvalue
  196. ; d4 - Black
  197. ; d5 - sx
  198. ; d6 - bit to set
  199.  
  200. twidth_loop:
  201.         move.b  PCMBLACK(a2),d4         ;d4 = Black
  202.         addq.l  #ce_SIZEOF,a2           ;advance to next entry
  203.  
  204.         move.w  (a0)+,d5                ;d5 = # of times to use this pixel
  205.  
  206.         cmp.b   d3,d4                   ;render this pixel?
  207.         ble.s   tsx_end                 ;no, skip to next pixel.
  208.         subq.w  #1,d5                   ;adjust for dbra
  209.  
  210. tsx_render:                             ;yes, render this pixel sx times
  211.         bset.b  d6,(a1)                 ;*(ptr) |= bit;
  212.  
  213.         adda.w  #1,a1                   ;ptr++
  214.         dbra    d5,tsx_render           ;sx--
  215.         dbra    d1,twidth_loop          ;width--
  216.         bra.s   exit                    ;all done
  217.  
  218. tsx_end:
  219.         adda.w  d5,a1                   ;ptr += sx
  220.         dbra    d1,twidth_loop          ;width--
  221.         bra.s   exit
  222.  
  223. grey_scale:
  224. ; a0 - PInfo
  225. ; a1 - ptr
  226. ; a3 - dmatrix ptr
  227. ; d0 - y
  228. ; d1 - width-1
  229. ; d6 - bit to set
  230.  
  231.         movea.l pi_ColorInt(a0),a2      ;a2 = ColorInt ptr
  232.         move.w  pi_xpos(a0),d2          ;d2 = x
  233.         movea.l pi_ScaleX(a0),a0        ;a0 = ScaleX (sxptr)
  234.  
  235. ; a0 - sxptr
  236. ; a1 - ptr
  237. ; a2 - ColorInt ptr
  238. ; a3 - dmatrix ptr
  239. ; d1 - width
  240. ; d2 - x
  241. ; d3 - dvalue (dmatrix[x & 3])
  242. ; d4 - Black
  243. ; d5 - sx
  244. ; d6 - bit to set
  245.  
  246. gwidth_loop:
  247.         move.b  PCMBLACK(a2),d4         ;d4 = Black
  248.         addq.l  #ce_SIZEOF,a2           ;advance to next entry
  249.  
  250.         move.w  (a0)+,d5                ;d5 = # of times to use this pixel
  251.         subq.w  #1,d5                   ;adjust for dbra
  252.  
  253. gsx_loop:
  254.         moveq.l #3,d3
  255.         and.w   d2,d3                   ;d3 = x & 3
  256.         move.b  0(a3,d3.w),d3           ;d3 = dmatrix[x & 3]
  257.  
  258.         cmp.b   d3,d4                   ;render this pixel?
  259.         ble.s   gsx_end                 ;no, skip to next pixel.
  260.  
  261.         bset.b  d6,0(a1,d2.w)           ;*(ptr + x) |= bit
  262.  
  263. gsx_end
  264.         addq.w  #1,d2                   ;x++
  265.         dbra    d5,gsx_loop             ;sx--
  266.         dbra    d1,gwidth_loop          ;width--
  267.  
  268. exit:
  269.         movem.l (sp)+,d2-d6/a2-a4       ;restore regs used
  270.         moveq.l #0,d0                   ;flag all ok
  271.         rts                             ;goodbye
  272.  
  273. sx      dc.w    0
  274. width   dc.w    0
  275.  
  276.         END
  277.  
  278.