Dandaman955

Flicky ASCII compression?

Oct 25th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ======================================================================
  2. ; Compression subroutine that can be used to deompress colours that use
  3. ; two palette entries. Used in Flicky for ASCII and TODO.
  4. ; INPUT
  5. ; d0 - Palette entry IDs. Each nybble represents a palette entry.
  6. ; d1 - Size of compressed art, divided by 8.
  7. ; a0 - Source of compressed art.
  8. ;
  9. ; OUTPUT
  10. ; a4 - Source of decompressed graphics if the write to RAM mode was used.
  11. ; ======================================================================
  12. loc_cc0:
  13.                movem.l d0-d6/a0/a4,-(sp)        ; Push register values onto the stack.
  14.                 moveq   #0,d4                    ; Clear d4 (Set address increment to 0).
  15.                 lea     ($C00000).l,a4           ; Load the VDP data port into a4.
  16.                 bra.s   loc_cd4                  ; Jump to the actual handling subroutine.
  17.  
  18. ; ----------------------------------------------------------------------
  19.  
  20. loc_cce:                                        ; Unused. Used to write to RAM. Note that this means that a RAN
  21.                                                  ; address is expected to be written to a4.
  22.                 movem.l d0-d6/a0/a4,-(sp)        ; Push register values onto the stack.
  23.                 moveq   #4,d4                    ; Set as address increment (for longwords).
  24. loc_cd4:
  25.                asl.w   #3,d1                    ; Multiply by 8 (each pass decompresses a longword, and 8 longwords make a tile).
  26.                 subq.w  #1,d1                    ; Subtract 1 for the dbf loop.
  27.                 move.b  d0,d2                    ; Load the palette entries into d2.
  28.                 move.b  d2,d3                    ; Copy to d3.
  29.                 lsr.b   #4,d2                    ; Get upper nybble of the byte, in this case entry 1.
  30.                 andi.b  #$F,d3                   ; Get lower nybble of the byte, in this case entry 2.
  31. loc_CE2:
  32.                moveq   #7,d6                    ; Set bit counter value as 7.
  33.                 move.b  (a0)+,d0                 ; Move the first byte of the compressed art into d0.
  34. loc_ce6:
  35.                lsl.l   #4,d5                    ; Clear the first nybble.
  36.                 btst    d6,d0                    ; Is it set to a 0 or 1?
  37.                 beq.s   loc_cf0                  ; If it is set to a 0, branch.
  38.                 or.b    d2,d5                    ; Set the pixel as using palette entry 1.
  39.                 bra.s   loc_cf2                  ; Branch to check the rest of the bits.
  40.  
  41. loc_cf0:
  42.                or.b    d3,d5                    ; Set the pixel as using palette entry 2.
  43. loc_cf2:
  44.                dbf     d6,loc_ce6               ; Repeat for the rest of the bits.
  45.                 move.l  d5,(a4)                  ; Move 8 pixels into VRAM.
  46.                 adda.l  d4,a4                    ; Add address increment. Useful only for RAM.
  47.                 dbf     d1,loc_ce2               ; Repeat for the rest of the compressed art source.
  48.                 movem.l (sp)+,d0-d6/a0/a4        ; Restore register values.
  49.                 rts                              ; Return.
Advertisement
Add Comment
Please, Sign In to add comment