base:using_a_byte_as_bitcounter_and_value_container_at_the_same_time
Differences
This shows you the differences between two versions of the page.
base:using_a_byte_as_bitcounter_and_value_container_at_the_same_time [2015-04-17 04:34] – external edit 127.0.0.1 | base:using_a_byte_as_bitcounter_and_value_container_at_the_same_time [2015-07-20 11:31] (current) – lft | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Using a byte as bitcounter and value container simultaneously ====== | ||
+ | This code was posted by Enthusi on the CSDb forum. Inventor uknown. The idea is to use the byte (in $bd in this case) as a " | ||
+ | |||
+ | The getbit routine is not included here since this article is intended to demonstrate a general concept, regardless of how the actual getbit routine is designed in each actual case. For a more elaborate example, see [[Decoding bitstreams]]. | ||
+ | |||
+ | < | ||
+ | getbyte: | ||
+ | lda #$01 ;This bit will be rotated to carry when a complete byte is read. | ||
+ | sta $bd | ||
+ | |||
+ | loop: | ||
+ | jsr getbit ;This subroutine reads one bit from the datastream and stores it in the carry flag. | ||
+ | rol $bd | ||
+ | bcc loop ;As long as the bit doesn' | ||
+ | lda $bd | ||
+ | rts | ||
+ | </ | ||
+ | |||
+ | From IRC: | ||
+ | Krillye: franticHT: that " |