home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / epsonq / transfer.asm < prev    next >
Encoding:
Assembly Source File  |  1980-02-03  |  6.4 KB  |  285 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)
  40. ; struct PrtInfo *PInfo        4-7
  41. ; UWORD y;            8-11
  42. ; UBYTE *ptr;            12-15
  43. ; UWORD *colors;        16-19
  44. ;
  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.  
  53.     moveq.l    #3,d2
  54.     and.w    d0,d2            ;d2 = y & 3
  55.     lsl.w    #2,d2            ;d2 = (y & 3) << 2
  56.     movea.l    pi_dmatrix(a0),a3    ;a3 = dmatrix
  57.     adda.l    d2,a3            ;a3 = dmatrix + ((y & 3) << 2)
  58.  
  59.     movea.l    _PED,a4            ;a4 = ptr to PED
  60.     divu.w    ped_NumRows(a4),d0    ;d0 = y / NumRows
  61.     swap.w    d0            ;d0 = y % NumRows
  62.     move.w    d0,d6
  63.     not.b    d6            ;d6 = bit to set
  64.     asr.w    #3,d0            ;d0 = ymod / 8
  65.     adda.w    d0,a1            ;ptr += ymod / 8
  66.  
  67.     movea.l    _PD,a4            ;a4 = ptr to PD
  68.     cmpi.w    #SHADE_COLOR,pd_Preferences+pf_PrintShade(a4)    ;color dump?
  69.     bne    not_color        ;no
  70.  
  71. color:
  72. ; a0 - PInfo
  73. ; a1 - ptr
  74. ; a2 - colors
  75. ; a3 - dmatrix ptr
  76. ; d0 - y
  77. ; d6 - bit to set
  78.  
  79.     movem.l    d7/a5-a6,-(sp)        ;save regs used
  80.  
  81.     movea.l    a1,a4
  82.     movea.l    a1,a5
  83.     movea.l    a1,a6
  84.     adda.w    (a2)+,a1        ;a1 = ptr + colors[0] (bptr)
  85.     adda.w    (a2)+,a4        ;a4 = ptr + colors[1] (yptr)
  86.     adda.w    (a2)+,a5        ;a5 = ptr + colors[2] (mptr)
  87.     adda.w    (a2)+,a6        ;a6 = ptr + colors[3] (cptr)
  88.  
  89.  
  90.     movea.l    pi_ColorInt(a0),a2    ;a2 = ColorInt ptr
  91.     move.w    pi_width(a0),width    ;# of pixels to do
  92.     move.w    pi_xpos(a0),d2        ;d2 = x
  93.     movea.l    pi_ScaleX(a0),a0    ;a0 = ScaleX (sxptr)
  94.     move.w    d2,d0
  95.     add.w    d2,d0
  96.     add.w    d2,d0            ;d0 = x * 3
  97.     move.w    d6,d7            ;d7 = bit to set
  98.  
  99. ; a0 - sxptr
  100. ; a1 - bptr
  101. ; a2 - ColorInt ptr
  102. ; a3 - dmatrix ptr
  103. ; a4 - yptr
  104. ; a5 - mptr
  105. ; a6 - cptr
  106. ; d0 - byte to set (x3 (x * 3))
  107. ; d1 - Black
  108. ; d2 - x
  109. ; d3 - dvalue (dmatrix[x & 3])
  110. ; d4 - Yellow
  111. ; d5 - Magenta
  112. ; d6 - Cyan
  113. ; d7 - bit to set
  114.  
  115. cwidth_loop:
  116.     move.b    PCMBLACK(a2),d1        ;d1 = Black
  117.     move.b    PCMYELLOW(a2),d4    ;d4 = Yellow
  118.     move.b    PCMMAGENTA(a2),d5    ;d5 = Magenta
  119.     move.b    PCMCYAN(a2),d6        ;d6 = Cyan
  120.     addq.l    #ce_SIZEOF,a2        ;advance to next entry
  121.  
  122.     move.w    (a0)+,sx        ;# of times to use this pixel
  123.  
  124. csx_loop:
  125.     moveq.l    #3,d3
  126.     and.w    d2,d3            ;d3 = x & 3    
  127.     move.b    0(a3,d3.w),d3        ;d3 = dmatrix[x & 3]
  128.  
  129. black:
  130.     cmp.b    d3,d1            ;render black?
  131.     ble.s    yellow            ;no, try ymc
  132.     bset.b    d7,0(a1,d0.w)        ;set black pixel
  133.     bra.s    csx_end
  134.  
  135. yellow:
  136.     cmp.b    d3,d4            ;render yellow pixel?
  137.     ble.s    magenta            ;no.
  138.     bset.b    d7,0(a4,d0.w)        ;set yellow pixel
  139.  
  140. magenta:
  141.     cmp.b    d3,d5            ;render magenta pixel?
  142.     ble.s    cyan            ;no.
  143.     bset.b    d7,0(a5,d0.w)        ;set magenta pixel
  144.  
  145. cyan:
  146.     cmp.b    d3,d6            ;render cyan pixel?
  147.     ble.s    csx_end            ;no, skip to next pixel.
  148.     bset.b    d7,0(a6,d0.w)        ;clear cyan pixel
  149.  
  150. csx_end
  151.     addq.w    #1,d2            ;x++
  152.     addq.w    #3,d0            ;x3 += 3
  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
  189.     adda.w    d2,a1
  190.     adda.w    d2,a1            ;ptr += x * 3
  191.  
  192. ; a0 - sxptr
  193. ; a1 - ptr
  194. ; a2 - ColorInt ptr
  195. ; a3 - dmatrix ptr (NOT USED)
  196. ; d1 - width
  197. ; d3 - dvalue
  198. ; d4 - Black
  199. ; d5 - sx
  200. ; d6 - bit to set
  201.  
  202. twidth_loop:
  203.     move.b    PCMBLACK(a2),d4        ;d4 = Black
  204.     addq.l    #ce_SIZEOF,a2        ;advance to next entry
  205.  
  206.     move.w    (a0)+,d5        ;d5 = # of times to use this pixel
  207.  
  208.     cmp.b    d3,d4            ;render this pixel?
  209.     ble.s    tsx_end            ;no, skip to next pixel.
  210.     subq.w    #1,d5            ;adjust for dbra
  211.  
  212. tsx_render:                ;yes, render this pixel sx times
  213.     bset.b    d6,(a1)            ;*(ptr) |= bit;
  214.  
  215.     adda.w    #3,a1            ;ptr += 3
  216.     dbra    d5,tsx_render        ;sx--
  217.     dbra    d1,twidth_loop        ;width--
  218.     bra.s    exit            ;all done
  219.     
  220. tsx_end:
  221.     adda.w    d5,a1
  222.     adda.w    d5,a1
  223.     adda.w    d5,a1            ;ptr += sx * 3
  224.     dbra    d1,twidth_loop        ;width--
  225.     bra.s    exit
  226.  
  227. grey_scale:
  228. ; a0 - PInfo
  229. ; a1 - ptr
  230. ; a3 - dmatrix ptr
  231. ; d0 - y
  232. ; d1 - width-1
  233. ; d6 - bit to set
  234.  
  235.     movea.l    pi_ColorInt(a0),a2    ;a2 = ColorInt ptr
  236.     move.w    pi_xpos(a0),d2        ;d2 = x
  237.     movea.l    pi_ScaleX(a0),a0    ;a0 = ScaleX (sxptr)
  238.     adda.w    d2,a1
  239.     adda.w    d2,a1
  240.     adda.w    d2,a1            ;ptr += x * 3
  241.  
  242. ; a0 - sxptr
  243. ; a1 - ptr
  244. ; a2 - ColorInt ptr
  245. ; a3 - dmatrix ptr
  246. ; d1 - width
  247. ; d2 - x
  248. ; d3 - dvalue (dmatrix[x & 3])
  249. ; d4 - Black
  250. ; d5 - sx
  251. ; d6 - bit to set
  252.  
  253. gwidth_loop:
  254.     move.b    PCMBLACK(a2),d4        ;d4 = Black
  255.     addq.l    #ce_SIZEOF,a2        ;advance to next entry
  256.  
  257.     move.w    (a0)+,d5        ;d5 = # of times to use this pixel
  258.     subq.w    #1,d5            ;adjust for dbra
  259.  
  260. gsx_loop:
  261.     moveq.l    #3,d3
  262.     and.w    d2,d3            ;d3 = x & 3    
  263.     move.b    0(a3,d3.w),d3        ;d3 = dmatrix[x & 3]
  264.  
  265.     cmp.b    d3,d4            ;render this pixel?
  266.     ble.s    gsx_end            ;no, skip to next pixel.
  267.  
  268.     bset.b    d6,(a1)            ;*ptr |= bit
  269.  
  270. gsx_end
  271.     adda.w    #3,a1            ;ptr += 3
  272.     addq.w    #1,d2            ;x++
  273.     dbra    d5,gsx_loop        ;sx--
  274.     dbra    d1,gwidth_loop        ;width--
  275.  
  276. exit:
  277.     movem.l    (sp)+,d2-d6/a2-a4    ;restore regs used
  278.     moveq.l    #0,d0            ;flag all ok
  279.     rts                ;goodbye
  280.  
  281. sx    dc.w    0
  282. width    dc.w    0
  283.  
  284.     END
  285.