Jump to content
IGNORED

Compression: help needed writing to bit stream


Recommended Posts

You keep two state variables, a "bit buffer" and a "counter" that takes care of the number of free bits in the buffer (i.e. initially 8 for a byte-buffer). On writing a bit, you decrement the bit-counter and shift your input left by the number of bits indicated in the bit-counter. Then or the bits into the bit buffer. If the bit counter is now zero, write out the byte, zero the bit buffer and reset the bit counter to 8.

 

If you are only writing single bits, then instead of left-shifting with a loop, use a look-up table that gives you the value indexed by the bit counter, and only use the table if the input bit is 0.

 

Alternative solution:

 

Every time a bit arrives, shift the bit buffer left by one bit, put the new bit into the LSB, decrement the bit counter. If the bit-counter is 0, write out the bit buffer, zero the bit buffer and reset the bit counter to 8.

Link to comment
Share on other sites

7 hours ago, Harry Potter said:

Currently, I am writing output in the wrong direction: I'm starting at bit 0 instead of 7.  How do I write and align information starting at bit 7?

you need basic tools to solve this problem. That tool is knowing the 6502's commands ... unfortunately

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...