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

  1. **********************************************************************
  2. *
  3. * Transfer routine for HP_LaserJet
  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.  
  16.         XDEF    _Transfer
  17.  
  18.         SECTION         printer,CODE
  19. _Transfer:
  20. ; Transfer(PInfo, y, ptr)
  21. ; struct PrtInfo *PInfo         4-7
  22. ; UWORD y;                      8-11
  23. ; UBYTE *ptr;                   12-15
  24. ;
  25.  
  26.         movem.l d2-d6/a2-a3,-(sp)       ;save regs used
  27.  
  28.         movea.l 32(sp),a0               ;a0 = PInfo
  29.         move.l  36(sp),d0               ;d0 = y
  30.         movea.l 40(sp),a1               ;a1 = ptr
  31.  
  32.         move.w  pi_width(a0),d1         ;d1 = width
  33.         subq.w  #1,d1                   ;adjust for dbra
  34.  
  35.         move.w  pi_threshold(a0),d3     ;d3 = threshold, thresholding?
  36.         beq.s   grey_scale              ;no, grey-scale
  37.  
  38. threshold:
  39. ; a0 - PInfo
  40. ; a1 - ptr
  41. ; d0 - y
  42. ; d1 - width
  43. ; d3 - threshold
  44.  
  45.         eori.b  #15,d3                  ;d3 = dvalue
  46.         movea.l pi_ColorInt(a0),a2      ;a2 = ColorInt ptr
  47.         move.w  pi_xpos(a0),d2          ;d2 = x
  48.         movea.l pi_ScaleX(a0),a0        ;a0 = ScaleX (sxptr)
  49.  
  50. ; a0 - sxptr
  51. ; a1 - ptr
  52. ; a2 - ColorInt ptr
  53. ; a3 - dmatrix ptr (NOT USED)
  54. ; d0 - byte to set (x >> 3)
  55. ; d1 - width
  56. ; d2 - x
  57. ; d3 - dvalue
  58. ; d4 - Black
  59. ; d5 - sx
  60. ; d6 - bit to set
  61.  
  62. twidth_loop:
  63.         move.b  PCMBLACK(a2),d4         ;d4 = Black
  64.         addq.l  #ce_SIZEOF,a2           ;advance to next entry
  65.  
  66.         move.w  (a0)+,d5                ;d5 = # of times to use this pixel (sx)
  67.  
  68.         cmp.b   d3,d4                   ;render this pixel?
  69.         ble.s   tsx_end                 ;no, skip to next pixel.
  70.         subq.w  #1,d5                   ;adjust for dbra
  71.  
  72. tsx_render:                             ;yes, render this pixel sx times
  73.         move.w  d2,d0
  74.         lsr.w   #3,d0                   ;compute byte to set
  75.         move.w  d2,d6
  76.         not.w   d6                      ;compute bit to set
  77.         bset.b  d6,0(a1,d0.w)           ;*(ptr + x >> 3) |= 2 ^ x
  78.  
  79.         addq.w  #1,d2                   ;x++
  80.         dbra    d5,tsx_render           ;sx--
  81.         dbra    d1,twidth_loop          ;width--
  82.         bra.s   exit                    ;all done
  83.  
  84. tsx_end:
  85.         add.w   d5,d2                   ;x += sx
  86.         dbra    d1,twidth_loop          ;width--
  87.         bra.s   exit
  88.  
  89. grey_scale:
  90. ; a0 - PInfo
  91. ; a1 - ptr
  92. ; d0 - y
  93. ; d1 - width
  94.  
  95.         movea.l pi_ColorInt(a0),a2      ;a2 = ColorInt ptr
  96.         moveq.l #3,d2
  97.         and.w   d0,d2                   ;d2 = y & 3
  98.         lsl.w   #2,d2                   ;d2 = (y & 3) << 2
  99.         movea.l pi_dmatrix(a0),a3       ;a3 = dmatrix
  100.         adda.l  d2,a3                   ;a3 = dmatrix + ((y & 3) << 2)
  101.         move.w  pi_xpos(a0),d2          ;d2 = x
  102.         movea.l pi_ScaleX(a0),a0        ;a0 = ScaleX (sxptr)
  103.  
  104. ; a0 - sxptr
  105. ; a1 - ptr
  106. ; a2 - ColorInt ptr
  107. ; a3 - dmatrix ptr
  108. ; d0 - byte to set (x >> 3)
  109. ; d1 - width
  110. ; d2 - x
  111. ; d3 - dvalue (dmatrix[x & 3])
  112. ; d4 - Black
  113. ; d5 - sx
  114. ; d6 - bit to set
  115.  
  116. gwidth_loop:
  117.         move.b  PCMBLACK(a2),d4         ;d4 = Black
  118.         addq.l  #ce_SIZEOF,a2           ;advance to next entry
  119.  
  120.         move.w  (a0)+,d5                ;d5 = # of times to use this pixel (sx)
  121.         subq.w  #1,d5                   ;adjust for dbra
  122.  
  123. gsx_loop:
  124.         moveq.l #3,d3
  125.         and.w   d2,d3                   ;d3 = x & 3
  126.         move.b  0(a3,d3.w),d3           ;d3 = dmatrix[x & 3]
  127.  
  128.         cmp.b   d3,d4                   ;render this pixel?
  129.         ble.s   gsx_end                 ;no, skip to next pixel.
  130.  
  131.         move.w  d2,d0
  132.         lsr.w   #3,d0                   ;compute byte to set
  133.         move.w  d2,d6
  134.         not.w   d6                      ;compute bit to set
  135.         bset.b  d6,0(a1,d0.w)           ;*(ptr + x >> 3) |= 2 ^ x
  136.  
  137. gsx_end
  138.         addq.w  #1,d2                   ;x++
  139.         dbra    d5,gsx_loop             ;sx--
  140.         dbra    d1,gwidth_loop          ;width--
  141.  
  142. exit:
  143.         movem.l (sp)+,d2-d6/a2-a3       ;restore regs used
  144.         moveq.l #0,d0                   ;flag all ok
  145.         rts                             ;goodbye
  146.  
  147.         END
  148.  
  149.  
  150.