Quantcast

Results 1 to 3 of 3

Thread: Oerg's Tools (RLE Compression, tile operations etc)

  1. #1
    Wildside Expert Oerg866's Avatar
    Join Date
    Dec 2009
    Location
    Frankfurt am Main (Germany)
    Age
    19
    Posts
    167
    Rep Power
    5

    Default Oerg's Tools (RLE Compression, tile operations etc)

    Hey guys.

    While writing MDEM's first, I wrote tons of little scripts to do stuff. So I thought I'd just post some of those tools here since they might be of use.

    ColorReplace

    ColorReplace is a color replacing program for tiles. It takes a file full of tiles and replaces all instances of color X with color Y.

    DOWNLOAD BINARY

    DOWNLOAD SOURCE

    ColorSwap

    Same as colorreplace but it swaps. Meaning that color x will be y, and y will be x. It also supports swapping those colors inside a file with a 32-byte long (meaning one) palette for convenience (it's entirely optional though so if you want to swap stuff only in the tiles itself leave the 4th parameter empty).

    DOWNLOAD BINARY

    DOWNLOAD SOURCE

    Run Length Encoding

    This is a flavor of RLE that jorge created. This is some tools and stuff I did for it. The file format works like this.

    Code:
    Header is a word. This word contains the size of compressed content. 
    
    The next are RLE streams. There are two "special" cases:
    
    Single byte, next byte is not the same. RLE output would be just that single byte.
    
    Two identical bytes following each other. RLE output would actually be three bytes. n is the byte: n n $0. that means two times n with 0 following repetitions.
    
    The rest (longer ocurrances of repeated bytes) will be compressed as such:
    
    n n (length of how many repetitions - 2)
    
    what if there are more than 257 bytes in succession? Well this is what you do:
    
    n n $FF (repeat that as many times as 257 fits in the length count) + n n (rest).
    I hope that made..sense?

    Anyway, here are:

    RLEComp

    RLE Compressor for Windows. Works fine as far as I am aware. (Tested with ~ 400 images...). Source nicely commented because I was bored.

    DOWNLOAD BINARY

    DOWNLOAD SOURCE

    RLEDecomp

    RLE Decompressor for Windows.

    Code:
    Usage: rledec.exe <source> <destination>
    
    Example: rledec.exe test.rle test.bin
    DOWNLOAD BINARY

    DOWNLOAD SOURCE

    RLEDecomp68K

    Of course if you have RLE Compressed tiles you would want to use them on the MD, wouldn't you? Well this is my attempt at an efficient decompressor for this file format. This should work perfectly. If it doesn't, I might have screwed up while reverting a special modification I've made for a special thingy....

    Code:
    ; 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
    After decompression, just load them into VRAM as usual.

    Spriter

    Spriter takes an image (tiles) which are in normal direction (meaning tiles go in X direction first) and produces an image file suitable for making sprites. Sprites work the opposite way (Y direction first). You must know the width and height in tiles.

    Might be very useful for some

    DOWNLOAD BINARY

    DOWNLOAD SOURCE

    All tools are console programs written in PBCC5 and don't need any runtimes to run them .

    NEW (2011/04/25): TILES2BMP



    Converts tiles with given height and width and a palette to BMP. Ideal for exctracting graphics out of ROMS into editable BMP files.

    DOWNLOAD BINARY



    Please, if you used these tools, mention it somewhere

    Cheers,
    Oerg866

  2. #2
    YM2612+SN76489 = eargasm! ESWAT Veteran Christuserloeser's Avatar
    Join Date
    Mar 2008
    Location
    Cologne, FRG
    Posts
    6,085
    Rep Power
    48

    Default

    Sweet! Thanks a lot for sharing!

  3. #3
    Wildside Expert E.J.'s Avatar
    Join Date
    Feb 2010
    Location
    Middle of Nowhere
    Posts
    205
    Rep Power
    5

    Default

    Interesting.

    Have you considered uploading this to the Romhacking.net database?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •