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

  1.  
  2. *******************************************************************************
  3. *
  4. *             !unpacker før zerø-packer v0.4!
  5. *
  6. *         VER: zerø-unpacker v0.1  by teuvo tursas (27/08/1993)
  7. *         VER: zerø-unpacker v0.2  by teuvo tursas (23/10/1993)
  8. *         VER: zerø-unpacker v0.3  by teuvo tursas (02/04/1994)
  9. *         VER: zerø-unpacker v0.31 by teuvo tursas (06/10/1994)
  10. *        $VER: zerø-unpacker v0.4  by teuvo tursas (25/02/1995)
  11. *
  12. *            v0.1    -    just unpacks zerøs.
  13. *            v0.2    -    reads alsø file's lenght.
  14. *            v0.3    -    optimized and fixed a major bug.
  15. *                    v0.2 was so full of bugs, that I wonder
  16. *                    how did it ever work!
  17. *            v0.31    -    optimized code. works little faster.
  18. *            v0.4    -    includes also file's original lenght.
  19. *
  20. *               a0 - pointer to data file
  21. *               a1 - pointer to packet's area
  22. *
  23. *               unpacked lenght can be found in packet's
  24. *               second longword [ .l 4(a0) ].
  25. *
  26. *               returns 0 in d0 if no error occured /
  27. *               1 in d0 if the packet was corrupted
  28. *
  29. *******************************************************************************
  30.  
  31. unpackbeginning:sub.l    d4,d4            ;faster output with this
  32. readlenght:    move.l    (a0)+,d0        ;file lenght (zpk)
  33.         move.l    (a0)+,d7        ;file lenght (bin)
  34. readheader:    move.b    (a0)+,d1        ;header
  35.         sub.l    #4+4+1,d0        ;4+4(lenght)+1(header)=9
  36. unpackloop:    tst.l    d0
  37.         beq.b    quitos
  38.         move.b    (a0)+,d2        ;move next byte
  39.         subq.l    #1,d7            ;sub binary lenght
  40.         cmp.l    d4,d7            ;overflow?
  41.         blt.b    overflow        ;yes
  42.         cmp.b    d2,d1            ;cmp it with header
  43.         beq.s    headerfound        ;it was equal
  44.         move.b    d2,(a1)+        ;something else, move on
  45.         subq.l    #1,d0            ;sub one from lenght
  46.         bra.b    unpackloop
  47. headerfound:    move.l    (a0)+,d3        ;move the lenght of da zeroes
  48. writezeros:    move.b    d4,(a1)+        ;write a zero-byte
  49.         subq.l    #1,d3            ;sub one from zeros
  50. ;        tst.l    d3            ;are all zeros gone?
  51.         beq.s    moveon            ;yes, all are written
  52.         subq.l    #1,d7            ;sub binary lenght
  53.         cmp.l    d4,d7            ;overflow?
  54.         blt.b    overflow        ;yes
  55.         bra.b    writezeros
  56. moveon:        subq.l    #4+1,d0            ;sub header and lenght of z's
  57.         cmp.l    d4,d0
  58.         blt.b    overflow
  59.         bra.b    unpackloop
  60. overflow:    moveq    #1,d0
  61.         rts
  62. quitos:        move.l    d4,d0
  63.         rts
  64.