home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / apps / dtp / pgsmodst / atariprt / img.s < prev    next >
Text File  |  1991-05-23  |  13KB  |  466 lines

  1.  include "pdlequ.h"
  2.  
  3. ***************************
  4. *   IMG File printer      *
  5. ***************************
  6.  
  7.  
  8.  SECTION printer,CODE,PUBLIC
  9. ************************************
  10.  
  11. dumbentry:
  12.     clr.l    d0
  13.     rts
  14.  
  15.     dc.l    "PRNT"
  16.     dc.w    200
  17.  
  18.  
  19.  
  20. ****************************************************
  21. * distribute the calls to the appropriate routines *
  22. ****************************************************
  23. fx80:    move.l    a0,table
  24.     lsl.w    #2,d0
  25.     lea    prntbl,a1
  26.     move.l    0(a1,d0.w),a1
  27.     jmp    (a1)
  28.  
  29.  
  30. *********************************************************
  31. * identify who I am, and set up who I like to speak to. *
  32. *********************************************************
  33. p_ident:
  34.     move.l    #driver,pdrvrnm(a0)    ;pointer to string for driver name
  35.     move.w    #DISK+ASCENDING,device(a0)
  36. prtok:    moveq    #1,d0
  37.     rts
  38.  
  39.  
  40. ******************************************************
  41. * initialize the table of printer specific routines  *
  42. ******************************************************
  43. p_init:    clr.b    pdl(a0)            ;no page description language
  44.     clr.b    pmult(a0)        ;automatically print mulitiple copies?
  45.     clr.b    pman(a0)        ;handle manual feed?
  46.     move.b    #PRT_BW,ptype(a0)    ;b&w file only
  47.  
  48.         move.l    sendout(a0),send+2    ;self-modifing code, tisk, tisk!
  49.  
  50. *
  51. * pminlft and pmaxw must be evenly divisible by 16
  52. * this is the part that should be worked out
  53. *
  54.  
  55.     move.w    pdensity(a0),d0
  56.     cmp.w    #7,d0
  57.     bcs    pint1
  58.     moveq    #6,d0
  59. pint1:    lsl.w    #1,d0
  60.  
  61.     lea    xdpi_tbl,a1
  62.     move.w    0(a1,d0.w),pxdpi(a0)    ;x resolution
  63.         move.w  0(a1,d0.w),xdpi         ;save for later
  64.     lea    ydpi_tbl,a1
  65.     move.w    0(a1,d0.w),pydpi(a0)    ;y resolution
  66.         move.w  0(a1,d0.w),ydpi         ;save for later
  67.     lea    minl_tbl,a1
  68.     move.w    0(a1,d0.w),pminlft(a0)    ;pixels from the left
  69.         lea    minr_tbl,a1
  70.     move.w    0(a1,d0.w),pminrht(a0)    ;pixels from the right
  71.     lea    maxw_tbl,a1
  72.     move.w    0(a1,d0.w),pmaxw(a0)    ;maximum # pixels across
  73.         lea    maxh_tbl,a1
  74.     move.l    0(a1,d0.w),pmaxh(a0)    ;maximum # pixels down
  75.     lea    mint_tbl,a1
  76.     move.w    0(a1,d0.w),pmintop(a0)    ;pixels down from top
  77.     lea    minb_tbl,a1
  78.     move.w    0(a1,d0.w),pminbot(a0)    ;pixels up from bottom
  79.     lea    xover_tbl,a1
  80.     move.w    0(a1,d0.w),pxover(a0)    ;percentage of x overlap of dots
  81.     lea    yover_tbl,a1
  82.     move.w    0(a1,d0.w),pyover(a0)    ;percentage of y overlap of dots
  83.     lea    rowht_tbl,a1
  84.     move.w    0(a1,d0.w),prowht(a0)    ;rows height modula
  85.     move.w    0(a1,d0.w),rowht
  86.     lea    rows_tbl,a1
  87.     move.w    0(a1,d0.w),rows
  88.         
  89.     bra    prtok
  90.  
  91.  
  92. **************************************
  93. * going to begin printing a document *
  94. **************************************
  95. p_bgndoc:
  96.     bra    prtok
  97.  
  98.  
  99. **************************************
  100. * about to start printing of a page  *
  101. **************************************
  102. p_bgnpage:
  103.         move.l  table,a0
  104.  
  105.         move.l  PPageWidth(a0),d0
  106.         move.l  d0,d1
  107.         addq.l  #7,d1
  108.         lsr.l   #3,d1
  109.         btst    #0,d1
  110.         beq     bp0
  111.         addq.l  #1,d1    
  112. bp0:    move.l  d0,imgx                 ;imgx = # bytes in row
  113.         move.l  PPageHeight(a0),imgy    ;imgy = # rows in page
  114.         
  115.         clr.l   cbuf
  116.         move.l  imgx,d0
  117.         lsl.l   #1,d0
  118.         clr.l   d1
  119.         clr.l   d2
  120.         move.l  m_alloc(a0),a0
  121.         jsr     (a0)
  122.         beq     bp1
  123.         move.l  a0,cbuf
  124.         
  125. bp1:    move.b  #0,d0                   ;Put IMG file header
  126.         bsr     send
  127.         move.b  #1,d0
  128.         bsr     send
  129.         move.b  #0,d0
  130.         bsr     send
  131.         move.b  #8,d0
  132.         bsr     send
  133.         move.b  #0,d0
  134.         bsr     send
  135.         move.b  #1,d0
  136.         bsr     send
  137.         
  138.         move.b  #0,d0                   ;code length (1=byte)
  139.         bsr     send
  140.         move.b  #1,d0
  141.         bsr     send
  142.         
  143.         clr.l   d0                      ;output width in microns
  144.         clr.l   d1
  145.         move.w  #25500,d0
  146.         move.w  xdpi,d1
  147.         divu    d1,d0
  148.         move.w  d0,whold
  149.         lsr.w   #8,d0
  150.         bsr     send
  151.         move.w  whold,d0
  152.         and.w   #$00ff,d0
  153.         bsr     send
  154.         
  155.         clr.l   d0                      ;output height in microns
  156.         clr.l   d1
  157.         move.w  #25500,d0
  158.         move.w  ydpi,d1
  159.         divu    d1,d0
  160.         move.w  d0,whold
  161.         lsr.w   #8,d0
  162.         bsr     send
  163.         move.w  whold,d0
  164.         and.w   #$00ff,d0
  165.         bsr     send
  166.         
  167.         move.l  table,a0
  168.         move.l  PPageWidth(a0),d0
  169.         move.l  d0,whold
  170.         lsr.w   #8,d0
  171.         bsr     send
  172.         move.l  whold,d0
  173.         and.l   #$000000ff,d0
  174.         bsr     send
  175.         
  176.         move.l  imgy,d0                 ;output image height in pixels
  177.         move.l  d0,whold
  178.         lsr.w   #8,d0
  179.         bsr     send
  180.         move.l  whold,d0
  181.         and.l   #$000000ff,d0
  182.         bsr     send                
  183.         
  184.     bra    prtok
  185.  
  186.  
  187. ******************************************
  188. * about to print a new tile for the page *
  189. ******************************************
  190. p_bgntile:
  191.     bra    prtok
  192.  
  193.  
  194. ********************************
  195. * print a block to the printer *
  196. ********************************
  197. p_block:
  198.     move.l    table,a0
  199.     move.l    pblockw(a0),width
  200.         move.l  pblockplane(a0),pplane
  201.     move.l    pblockptr(a0),a1
  202.     move.l    (a1),a1
  203.     add.l    pblockoff(a0),a1
  204.         move.l  a1,a0
  205.         
  206.         tst.l   cbuf                    ;is a compression buffer available?
  207.         beq     nocomp                  ;no, so don't compress output file
  208.         
  209.         clr.l   ulen
  210.         move.l  width,d0
  211.         bsr     compit
  212.         move.l  cbuf,a0
  213.         move.l  (a0),a0
  214.         move.l  d0,d1
  215.         
  216. cm1:    move.b  (a0)+,d0                ;output data in compression buffer
  217.         move.l  d1,-(sp)
  218.         move.l  a0,-(sp)
  219.         bsr     send
  220.         move.l  (sp)+,a0
  221.         move.l  (sp)+,d1
  222.         subq.l  #1,d1
  223.         bne     cm1
  224.         bra     putln1
  225.         
  226.         ;divu    #0,d7
  227.         
  228. nocomp:    move.l  a0,-(sp)
  229.         clr.l   d0
  230.         move.b  #$80,d0                 ;send packet header ($80)
  231.         bsr     send
  232.         move.l  #255,d0
  233.         cmp.l   #255,width              ;default length to 255
  234.         bcc     nc2                     ;is there that much left?
  235.         move.l  width,d0                ;no, so only do what is left
  236. nc2:    move.l  d0,-(sp)
  237.         bsr     send
  238.         move.l  (sp)+,d0
  239.         move.l  d0,d1
  240.         sub.l   d1,width
  241.         move.l  (sp)+,a0
  242.  
  243. nc3:    move.b    (a0)+,d0
  244.     move.l    a0,-(sp)
  245.         move.l  d1,-(sp)
  246.     bsr    send
  247.         move.l  (sp)+,d1
  248.     move.l    (sp)+,a0
  249.     subq.l    #1,d1
  250.     bne    nc3
  251.         
  252.         tst.l   width
  253.         bne     nocomp
  254.         
  255.         ;btst    #0,width
  256.         ;beq     putln4
  257.         ;move.b  #0,d0           ;make sure to end on a word
  258.         ;bsr     send
  259.                 
  260. putln1:    bra    prtok
  261.        
  262.  
  263. *****************************************  
  264. * just finished describing current tile *
  265. *****************************************
  266. p_endtile:
  267.         bra     prtok
  268.  
  269.  
  270. ****************************************************
  271. * just finished describing all tiles for this page *
  272. ****************************************************
  273. p_endpage:
  274.         tst.l   cbuf
  275.         beq     ep1
  276.         
  277.         move.l  table,a1
  278.         move.l  m_delete(a1),a1
  279.         move.l  cbuf,a0
  280.         jsr     (a1)
  281.         clr.l   cbuf
  282.         
  283. ep1:    bra    prtok
  284.  
  285.  
  286. ************************************
  287. * finished printing the document   *
  288. ************************************
  289. p_enddoc:
  290.     bra    prtok
  291.  
  292.  
  293. ***************************
  294. * user stopped printing   *
  295. ***************************
  296. p_break:
  297.     bra    p_endtile
  298.  
  299.  
  300. ***************************************************
  301. ***    these are the send routines for the    ***
  302. ***    dot matrix driver.            ***
  303. ***************************************************
  304. sendline:
  305.     move.b    (a0)+,d0
  306.     beq    prtok
  307.     move.l    a0,-(sp)
  308.     bsr    send
  309.     move.l    (sp)+,a0
  310.     bra    sendline
  311.         
  312. ************************************
  313. *  send byte in d0 out to printer  *
  314. ************************************
  315. send:    jmp    $ffffff         ;address is modified to be send(a0)
  316.                                 ;by init code
  317.  
  318.  
  319. ************************************************
  320. **   compress the data going to the file      **
  321. ************************************************
  322. compit:
  323.         ;divu    #0,d7
  324.         move.l  cbuf,a2         ;get address of compression buffer
  325.         move.l  (a2),a2
  326.         clr.l   d1              ;zero out the length counter
  327.         clr.l   d3              ;zero out the total length counter
  328.         
  329. cmpt2:  subq.l  #1,d0           ;am I out of data yet? (exit when d0 = -1)
  330.         bmi     cmpt3           ;yes
  331.         
  332.         move.b  (a0)+,d2        ;get a byte from the input data
  333.         cmp.b   #$ff,d2
  334.         beq     brun
  335.         
  336.         cmp.b   #$00,d2
  337.         beq     wrun
  338.         
  339.         ;uncompressed run
  340. urun:   lea     ubuf,a3         ;stuff uncompressed byte into ubuf
  341.         move.l  ulen,d4
  342.         move.b  d2,0(a3,d4.l)
  343.         addq.l  #1,ulen
  344.         cmp.l   #255,ulen       ;have I filled the ubuf?
  345.         bcs     cmpt2           ;no, so keep going
  346.         bsr     urun1           ;yes, so output the ubuf
  347.         btst    #31,d0          ;did I finish a row?
  348.         beq     cmpt2           ;no, so get another
  349.         bra     cmpt3           ;get out
  350.         
  351.         ;mini-subroutine to output the ubuf
  352. urun1:  tst.l   ulen            ;any data to output?
  353.         beq     urun3           ;no, so exit
  354.         move.b  #$80,(a2)+      ;output code for uncompressed run
  355.         move.l  ulen,d4         ;output length of uncompressed run
  356.         move.b  d4,(a2)+
  357.         subq.l  #1,d4
  358.         lea     ubuf,a3         ;output uncompressed run bytes
  359. urun2:  move.b  (a3)+,(a2)+
  360.         dbf     d4,urun2
  361.         add.l   #2,d3           ;add 2 for codes to total length
  362.         add.l   ulen,d3         ;add in for the bytes output to total length
  363.         clr.l   ulen            ;reset string length for next urun
  364. urun3:  rts
  365.  
  366.         ;$ff run
  367. brun:   bsr     urun1           ;output ubuf if any data is there
  368. brun0:  cmp.b   (a0),d2
  369.         bne.s   brun1
  370.         
  371.         subq.l  #1,d0
  372.         bmi     brun1
  373.         move.b  (a0)+,d2
  374.         
  375.         add.b   #1,d1           ;add 1 to the length
  376.         cmp.b   #126,d1         ;have i done the max count yet?
  377.         bcs.s   brun0           ;no, so keep checking
  378.  
  379. brun1:  add.b   #1,d1           ;output compressed data
  380.         or.b    #$80,d1
  381.         move.b  d1,(a2)+        ;output the code for a $FF run
  382.         addq.l  #1,d3           ;add one to the total length counter
  383.         clr.l   d1
  384.         btst    #31,d0
  385.         beq     cmpt2
  386.         bra     cmpt3
  387.  
  388.         ;$00 run
  389. wrun:   bsr     urun1           ;output ubuf if any data is there
  390. wrun0:  cmp.b   (a0),d2
  391.         bne.s   wrun1
  392.         
  393.         subq.l  #1,d0
  394.         bmi     wrun1
  395.         move.b  (a0)+,d2
  396.         
  397.         add.b   #1,d1           ;add 1 to the length
  398.         cmp.b   #126,d1         ;have i done the max count yet?
  399.         bcs.s   wrun0           ;no, so keep going
  400.  
  401. wrun1:  add.b   #1,d1           ;output compressed data
  402.         move.b  d1,(a2)+        ;output the code for a $00 run
  403.         addq.l  #1,d3           ;add one to the total length counter
  404.         clr.l   d1
  405.         btst    #31,d0
  406.         beq     cmpt2           ;go get another byte     
  407.         
  408. cmpt3:  bsr     urun1           ;output ubuf if any data is there
  409.         move.l  d3,d0
  410.         rts
  411.                                 
  412.  
  413. ***********************************
  414. ***                ***
  415. ***********************************
  416.  SECTION printer,DATA,PUBLIC
  417.  
  418. prntbl:    dc.l    prtok,prtok,prtok,prtok,p_init
  419.     dc.l    p_bgndoc,p_bgnpage,p_bgntile
  420.     dc.l    p_block
  421.     dc.l    p_endtile,p_endpage,p_enddoc
  422.     dc.l    p_break,p_ident
  423.  
  424. xdpi_tbl:       dc.w    72,75,100,150,200,300,2540
  425. ydpi_tbl:       dc.w    72,75,100,150,200,300,2540
  426. minl_tbl:    dc.w    0,0,0,0,0,0,0
  427. minr_tbl:    dc.w    0,0,0,0,0,0,0
  428. ;maxw_tbl:    dc.w    432,624,640,864,1280,1712,2560
  429. maxw_tbl:       dc.w    0,0,0,0,0,0,0
  430. maxh_tbl:       dc.w    0,0,0,0,0,0,0
  431. mint_tbl:    dc.w    0,0,0,0,0,0,0
  432. minb_tbl:    dc.w    0,0,0,0,0,0,0
  433. xover_tbl:    dc.w    0,0,0,0,0,0,0
  434. yover_tbl:    dc.w    0,0,0,0,0,0,0
  435. rowht_tbl:    dc.w    1,1,1,1,1,1,1
  436. rows_tbl:    dc.w    1,1,1,1,1,1,1
  437.  
  438. driver:        dc.b    "IMG File v2.0.0",0
  439.  
  440.  
  441.  SECTION printer,BSS,PUBLIC
  442. table:        ds.l    1
  443. twidth:        ds.w    1
  444. pixel:        ds.w    1
  445. lineptr:    ds.l    1
  446. width:        ds.l    1
  447. count:        ds.w    1
  448. rows:        ds.w    1
  449. rowht:        ds.w    1
  450. xdpi:           ds.w    1
  451. imgx:           ds.l    1
  452. imgy:           ds.l    1
  453. pplane:         ds.l    1
  454. whold:          ds.w    1
  455. ydpi:           ds.w    1
  456. cbuf:           ds.l    1
  457. ulen:           ds.l    1
  458. ubuf:           ds.b    256
  459.  
  460. ********************************** changes *****************************
  461. ;
  462. ;       version 2.0.0
  463. ;
  464. ;       - initial release
  465.  
  466.