This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
MaxVT103


Member


Joined: 24 Aug 2003
Posts: 109

Posted: 04 Oct 2003 01:28:07 pm    Post subject:

Ok, once again I am back asking for help. I know what RLE does and how it works but I haven't been able to find a decompressor that you put into your code to use it. So if anyone knows the code or where I can get it it would be very helpfull.

Donald
Back to top
NETWizz
Byte by bit


Bandwidth Hog


Joined: 20 May 2003
Posts: 2369

Posted: 04 Oct 2003 02:27:48 pm    Post subject:

You would have to write it.

Basically, you just encode how many similar bytes.
Back to top
omni


Member


Joined: 14 Jun 2003
Posts: 115

Posted: 04 Oct 2003 02:41:49 pm    Post subject:

would you like me to post my decompressor? I don't know if you can incorporate it into your code, but ya you're better off making your own.
Back to top
MaxVT103


Member


Joined: 24 Aug 2003
Posts: 109

Posted: 04 Oct 2003 07:49:24 pm    Post subject:

Would you please so I can look at it and figure out how to write one.
Back to top
NETWizz
Byte by bit


Bandwidth Hog


Joined: 20 May 2003
Posts: 2369

Posted: 05 Oct 2003 02:32:15 am    Post subject:

I have never written one, but when I have 3 hours with nothing better to do, I will.

Here is how a good implementation would work.

You would set up a 512 byte table

0 to 255 is 256 * 2 so you can store big numbers

Now, you would read throguh the program code and count the number of times each byte shows up.

I.e.

how many 0's how many 1's... how many FF's

each time, you would update your table.

Next you would create a 256 byte table and store 00, 01, ...FF in it

This would represent your 512 byte table.

Now, let us say your 512 byte table looked like this:

01 02 00 CD ....

01 02 would represent the number of times 00 showed up

00 CD would represent the number of times 01 showed up

...


Now you would create an excange loop (complicated and big)

What it would do is determin 01 02 (16-bit number) is bigger than 00 CD (16 bit number)

So it would switch the 00 and the 01 in the 256 byte table.

And the loop would continue in a bublesort pattern...

Eventually, you would have a 256 bit table with in the order of how many times each byte occurs in the program.

I.e

C9 09 04...

If C9 were in spot 00 of the 256 byte table, it would have occured less than any other byte thus, would be a good candidate for our toden of compressed runs

Note: If a byte gets detected as not existing in the program, the sort routine will stop becasue you cannot get better than not existing for your token.

Now, we go back to our 512 byte table and determine if any byte exists in excess of 256 times.

Note in RLE 1=1...255=255... 256=0

If not, we do 8 bit encoding to save a byte with each run else, we do 16 bit encoding to accomidate long runs.


In our example, we have already stated that the numbers for 00 were 01 02 which would amount to 258 (bigger than a byte) so we will use 16-bit encoding

and C9 exists the least number of times so it will be our token


So in our rle we need to state types for the decompressor

I.e.

C9 01

C9 is token 00 = 8-bit 01=16bit (basically the designation for which represents which is trivial)


Now we can encode

So let us say we have

38 38 38 38 38 38

that would encode to C9 00 06 38

basically C9 says I am a flag

00 06 says 6 times

had we used 8-bit encoding C9 06 38; however, had we had more than 256 consecutive 38's we woud not beable to encode it into one run

38 says the number to repeat


Then we have 78 34 55

Which do not repeat


So we just put them after our run

C9 01 C9 00 06 38 78 34 55


Now, here comes the triky part

When the program comes to a flag

If we see only one instance of C9 in the program and that is our flag, it must be encoded

C9 00 01 C9

Decode to one C9

else the C9 will be though of as a flag for a run of something else...bad

Maybe our program will squish using 8 bit and then 16 bit and compare sizes and select the best

Still, we are more likely to use 8 bit squishing becasue finding more than 256 instances of the same byte usually does not happen! unless we are talking about a picture that is 1/4 blank or filled or something.

Basically, you just have to decide how you are going to do it. To be less complex, you can skip the tables and risk using a heavily used byte through as the flag.

If this happens, the progrma will not shirnk as much...
Back to top
omni


Member


Joined: 14 Jun 2003
Posts: 115

Posted: 05 Oct 2003 04:12:45 pm    Post subject:

how my decompressor works is you first going to ahve to change your data around a bit. My compressed data is the the form of:

flag byte,the compressed byte,how many times the compressed byte ran

ex: $FF,$FF,$FF,$FF -> $11,$FF,$04

the flag byte you can change to whatever you want it to be as long as you change it in the decompressor. And to stop decompressing data, you put the flag byte $EE, which will stop decompressing and continue with your program. So put $EE at the end of your data.

#input hl-source
de-destination

CHECK:
ld a,(hl);hl contains whatever in the data array
cp $11 ;the flag byte to tell compressor that a byte is compressed
jr z,decompress
cp $EE ;the flag byte to tell compressor to stop
ret z,exit
ldi ; otherwise if data isn't compressed, move data to destination anyway
inc bc; since ldi decreases bc, increasing it will make bc stay the same
jr check
DECOMPRESS:
inc hl ;(hl) contains compressed byte
push hl ;storing hl temporarly, the stack now contains the compressed byte
inc hl
ld b,(hl);b contains the amount of times compressed byte is compressed
pop hl ;(hl) is the compressed byte once again, the stack is empty now
DECOMPRESSLOOP:
ldi ;move (hl) to (de)
inc bc
dec hl ;dec hl because we want the address of the compressed byte to stay the same
djnz decompressloop
inc hl ;advancing 2 bytes..
inc hl ;(hl) now contains the next byte in the data array
jp check


Last edited by Guest on 05 Oct 2003 04:15:16 pm; edited 1 time in total
Back to top
tr1p1ea


Elite


Joined: 03 Aug 2003
Posts: 870

Posted: 07 Oct 2003 01:22:58 pm    Post subject:

Here is my routine ... just in case Smile.


Code:
;Input:
;HL = Compress From
;DE = Compress To
;BC = Bytes to Decompress
;Compression Syntax = Runflag, RunLength, Data
Decompress:
  ld a, (hl)
  cp $FF              ;byte that indicates a run
  jr z,RLERun
  ldi
RLEC:
  ret po
  jr Decompress
RLERun:
  inc hl   
  ld a,(hl)
  inc hl
  inc hl
RLERunL:
  dec hl
  dec a
  ldi
  jr nz,RLERunL
  jr RLEC


$FF (255) is the runflag as you can see.....


Last edited by Guest on 07 Oct 2003 01:25:36 pm; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement