home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Cruncher / RRR-DR0.LHA / dR0 / Asm / zerø!packer!v0.4!safe.S next >
Encoding:
Text File  |  1995-03-20  |  3.0 KB  |  128 lines

  1.  
  2. *******************************************************************************
  3. *
  4. *         !a little data-packer før thøse whø can't dø their!
  5. *         !øwn packer ør whø just need a simple øne!
  6. *            !this uncanny versiøn can!
  7. *        !pack -belive ør nøt- ønly zerøes(!!!!!!!!)!
  8. *
  9. *          VER: zerø-packer v0.1  by teuvo tursas (29/08/1993)
  10. *          VER: zerø-packer v0.2  by teuvo tursas (23/10/1993)
  11. *          VER: zerø-packer v0.3  by teuvo tursas (02/04/1993)
  12. *          VER: zerø-packer v0.31 by teuvo tursas (24/02/1995)
  13. *         $VER: zerø-packer v0.4  by teuvo tursas (25/02/1995)
  14. *
  15. *        v0.1    -    started frøm a scratch
  16. *        v0.2    -    nøw writes file's lenght intø packet
  17. *        v0.3    -    works with unpacker v0.3
  18. *        v0.31    -    løts øf little øptimizatiøns
  19. *        v0.4    -    writes the øriginal lenght alsø
  20. *
  21. *               a5 - pointer to original file
  22. *               a6 - pointer to packet's room
  23. *
  24. *               returns packet's lenght in d7
  25. *               returns 0 in d0 if no error / 1 in d0 if could not
  26. *                       find any character for marking the packet /
  27. *                       2 in d0 if the packet grew too big
  28. *
  29. *******************************************************************************
  30.  
  31. testoptions:    moveq.l    #1,d3            ;faster output with this
  32.         move.l    a5,a0
  33.         move.l    lenghtoffile,d0
  34.         sub.b    d1,d1
  35.         sub.l    d6,d6            ;zeros
  36.         sub.l    d7,d7            ;addbytes
  37.  
  38. headersearch:    move.b    (a0)+,d2
  39.         cmp.b    d1,d2
  40.         beq.s    addoneandagain
  41.         sub.l    d3,d0
  42.         bne.s    headersearch
  43.         move.b    d1,d5            ;header found
  44.         bra.b    writeheader
  45.  
  46. addoneandagain:    cmp.b    #$ff,d1
  47.         beq.w    headeroverflow
  48.         add.b    d3,d1
  49.         move.l    lenghtoffile,d0
  50.         move.l    a5,a0
  51.         bra.b    headersearch
  52.  
  53. writeheader:    move.l    a6,a0
  54.  
  55. writelenght:    move.l    #0,(a0)+        ;nulls here, because in the
  56.         move.l    lenghtoffile,(a0)+    ;end we put the real values
  57.         move.b    d5,(a0)+        ;to the beginning of the packet
  58.         move.l    #4+4+1,d7        ;lenght of header and lenghts
  59.  
  60. beginning:    move.l    a5,a1
  61.         move.l    lenghtoffile,d0
  62.         move.l    d0,d1
  63.         asl.l    #1,d1            ;mulu #2,d1
  64.  
  65. packloop:    move.b    (a1)+,d2        ;main loop. pack all zeroes
  66.         beq.s    zerobytefound
  67.         sub.l    d3,d1
  68.         beq.s    sizeoverflow        ;size exceeds the limit
  69.         move.b    d2,(a0)+
  70.         add.l    d3,d7
  71.         sub.l    d3,d0
  72.         beq.s    quit
  73.         bra.b    packloop
  74.  
  75. zerobytefound:    add.l    d3,d6            ;at least one zero found
  76.  
  77.         sub.l    d3,d1
  78.         beq.s    sizeoverflow        ;size exceeds the limit
  79.  
  80.         move.b    d5,(a0)+
  81.         add.l    d3,d7
  82.         sub.l    d3,d0
  83.         beq.s    endoffile
  84.  
  85. searchloop:    tst.l    d0            ;search for more zeroes
  86.         beq.s    endoffile
  87.         sub.l    d3,d0
  88.         move.b    (a1)+,d2
  89.         bne.s    notzero
  90.         add.l    d3,d6
  91.         bra.b    searchloop
  92.  
  93. notzero:    sub.l    #4,d1
  94.         cmp.l    d3,d1
  95.         blt.s    sizeoverflow        ;size exceeds the limit
  96.  
  97.         move.l    d6,d4
  98.         move.l    d4,(a0)+
  99.         addq.l    #4,d7
  100.         sub.l    d6,d6
  101.  
  102.         sub.l    d3,d1
  103.         beq.s    sizeoverflow        ;size exceeds the limit
  104.  
  105.         move.b    d2,(a0)+
  106.         add.l    d3,d7
  107.         bra.w    packloop
  108.  
  109. endoffile:    move.l    d6,d4
  110.  
  111.         sub.l    #4,d1
  112.         cmp.l    d3,d1
  113.         blt.s    sizeoverflow        ;size exceeds the limit
  114.  
  115.         move.l    d4,(a0)+
  116.         addq.l    #4,d7
  117.  
  118. quit:        move.l    a6,a0
  119.         move.l    d7,(a0)+        ;here we put it!
  120.         sub.l    d0,d0            ;no error
  121.         rts
  122.  
  123. headeroverflow:    moveq.l    #1,d0            ;error! header-overflow
  124.         rts
  125.  
  126. sizeoverflow:    moveq.l    #2,d0            ;error! size is too high
  127.         rts
  128.