home *** CD-ROM | disk | FTP | other *** search
-
- ; Mini cruncher
-
- ; By Fredrik Juto 1989
- ; This software is public domain,
- ; you may freely distribute, modify or sell it.
- ; (See `decrunch.s' for decrunch routine)
-
- ; FROM A0
- ; TO A1
- ; LENGTH D0
-
- crunch:
- movem.l d0-d3/a0-a3,-(sp) ; push the registers we are going to use on stack
- movea.l a0,a3
- adda.l d0,a3 ; a3 points to source end
- moveq #0,d1
-
- cr_main:
- cmpa.l a0,a3 ; source = source end?
- beq.s cr_end ; Yep, exit.
- move.b #-1,d2 ; Start counting on -1 (both crunch & dump)
- move.b 1(a0),d1
- cmp.b (a0),d1 ; Are the two next chars equal?
- beq.s cr_crunch ; Yes, crunch them.
-
- *** Dump ***
- move.l a1,a2 ; A2 points to control byte
- addq.l #1,a1 ; Make room for it
- cr_dump:
- move.b (a0)+,(a1)+ ; Dumping...
- addq.b #1,d2 ; Increase counter
- cmp.b #$7f,d2 ; Max length reached?
- beq.s cr_enddump ; Yes, stop dumping.
- cmpa.l a0,a3 ; Are we done crunching?
- beq.s cr_enddump ; Yes, stop dumping (main will exit)
- move.b 1(a0),d1 ; See if we can crunch the two
- cmp.b (a0),d1 ; next chars.
- bne.s cr_dump ; No, continue crunching...
- cr_enddump:
- move.b d2,(a2) ; Write control byte,
- bra.s cr_main ; and jump to main.
-
- *** Crunch ***
- cr_crunch:
- addq.b #1,d2 ; Increase byte counter
- cmp.b #$7f,d2 ; No room for more bytes in counter?
- beq.s cr_endcrunch ; Yep, stop crunching.
- cmpa.l a0,a3 ; Is the job done yet?
- beq.s cr_doendcrunch ; Yeah! we stop crunching and main will return for us.
- move.b 1(a0),d3
- cmp.b (a0)+,d3 ; Is it possible to continue crunching?
- beq.s cr_crunch ; Yes, we can continue.
- bra.s cr_doendcrunch ; Nope, jump to cr_doendcrunch
- cr_endcrunch:
- addq.l #1,a0 ; increase source ptr.
- cr_doendcrunch:
- bset #7,d2 ; set bit #7 of byte counter.
- move.b d2,(a1)+ ; save counter to destination.
- move.b d1,(a1)+ ; save byte to destination.
- bra.s cr_main ; and goto main
-
- cr_end:
- movem.l (sp)+,d0-d3/a0-a3 ; push the callers registers back from stack.
- rts ; return to caller
-
- end ; end of assembly
-