home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / epsonx / transfer.asm < prev    next >
Encoding:
Assembly Source File  |  1980-02-03  |  6.6 KB  |  289 lines

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