home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / printer / epsonx / transfer.asm < prev    next >
Assembly Source File  |  1992-09-03  |  10KB  |  301 lines

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