Guest User

Untitled

a guest
Jul 22nd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Run length decoder written by Oerg866
  2. ;
  3. ; ARGUMENTS: A6 = SOURCE (the stuff you want to decode)
  4. ;            A5 = DESTINATION (the location where you want
  5. ;                              the decompressed data to be in RAM)
  6.  
  7. RunLengthDecoding:
  8.        moveq #0, d0                   ; Clear out d0
  9.         move.b (a6)+, d0               ; Read one byte, in case compressed data is unaligned
  10.         lsl.w #8, d0                   ; Make it the upper byte inside a word
  11.         move.b (a6)+, d0               ; move next byte into the lower byte of that word, which is the size word
  12.         move.b (a6)+, d1               ; Initialize "last read" byte
  13.         subq.w #1, d0                  ; Decrease remaining size counter
  14. RunLengthDecoding_LOOP:               ; DECODING LOOP START            
  15.         subq.w #1, d0                  ; Decrease remaining size counter
  16.         beq.s RLD_End                  ; If remaining size counter is 0, quit
  17.         move.b (a6)+, d2               ; Fetch next byte into d2
  18.         move.b d1,(a5)+                ; Write the old byte to destination (since one occurance gets written no matter what)
  19.         cmp.b d2, d1                   ; Check if the old and new byte are identical
  20.         beq.s RLD_Identical            ; If yes, branch
  21. RLD_NotIdentical:                     ; if not, leave it at that
  22.         move.b d2, d1                  ; and make d2 the old byte.
  23.         bra.s RunLengthDecoding_LOOP   ; Go back to main loop
  24. RLD_Identical:                        ; if the bytes are identical...
  25.         moveq #0, d2                   ; Clearing out d2 here is practical since it will only be done if we have a loop (dbra)
  26.         move.b (a6)+, d2               ; Grab the amount of bytes to be written in succession into d2 (saves a few cycles...)
  27.         subq.w #1, d0                  ; decrease remaining size counter
  28. RLD_WriteLoop:                        ; Start writing the sequence into the destination...              
  29.         move.b d1, (a5)+               ; Write the amount of bytes in succession...
  30.         dbra d2, RLD_WriteLoop         ; Looping until d2 is 0....
  31.         move.b (a6)+, d1               ; Grab the next byte
  32.         subq.w #1, d0                  ; decrease remaining size counter
  33.         bra.s RunLengthDecoding_LOOP   ; and go back to the loop.
  34. RLD_End:
  35.        rts
Add Comment
Please, Sign In to add comment