Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Run length decoder written by Oerg866
- ;
- ; ARGUMENTS: A6 = SOURCE (the stuff you want to decode)
- ; A5 = DESTINATION (the location where you want
- ; the decompressed data to be in RAM)
- RunLengthDecoding:
- moveq #0, d0 ; Clear out d0
- move.b (a6)+, d0 ; Read one byte, in case compressed data is unaligned
- lsl.w #8, d0 ; Make it the upper byte inside a word
- move.b (a6)+, d0 ; move next byte into the lower byte of that word, which is the size word
- move.b (a6)+, d1 ; Initialize "last read" byte
- subq.w #1, d0 ; Decrease remaining size counter
- RunLengthDecoding_LOOP: ; DECODING LOOP START
- subq.w #1, d0 ; Decrease remaining size counter
- beq.s RLD_End ; If remaining size counter is 0, quit
- move.b (a6)+, d2 ; Fetch next byte into d2
- move.b d1,(a5)+ ; Write the old byte to destination (since one occurance gets written no matter what)
- cmp.b d2, d1 ; Check if the old and new byte are identical
- beq.s RLD_Identical ; If yes, branch
- RLD_NotIdentical: ; if not, leave it at that
- move.b d2, d1 ; and make d2 the old byte.
- bra.s RunLengthDecoding_LOOP ; Go back to main loop
- RLD_Identical: ; if the bytes are identical...
- moveq #0, d2 ; Clearing out d2 here is practical since it will only be done if we have a loop (dbra)
- move.b (a6)+, d2 ; Grab the amount of bytes to be written in succession into d2 (saves a few cycles...)
- subq.w #1, d0 ; decrease remaining size counter
- RLD_WriteLoop: ; Start writing the sequence into the destination...
- move.b d1, (a5)+ ; Write the amount of bytes in succession...
- dbra d2, RLD_WriteLoop ; Looping until d2 is 0....
- move.b (a6)+, d1 ; Grab the next byte
- subq.w #1, d0 ; decrease remaining size counter
- bra.s RunLengthDecoding_LOOP ; and go back to the loop.
- RLD_End:
- rts
Add Comment
Please, Sign In to add comment