aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/lzp/bit.c
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-04-06 10:11:07 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-04-06 10:11:07 +0800
commitf3e040230772f978540a71aea43dfde200992922 (patch)
treebd8ca31b72dd01e24980b073854e263589530f56 /libpsn00b/lzp/bit.c
downloadpsn00bsdk-f3e040230772f978540a71aea43dfde200992922.tar.gz
First commit
Diffstat (limited to 'libpsn00b/lzp/bit.c')
-rw-r--r--libpsn00b/lzp/bit.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/libpsn00b/lzp/bit.c b/libpsn00b/lzp/bit.c
new file mode 100644
index 0000000..aefa45d
--- /dev/null
+++ b/libpsn00b/lzp/bit.c
@@ -0,0 +1,65 @@
+#include "bit.h"
+
+// Bit I/O
+//
+
+unsigned char* inPtr = 0;
+int inBytes = 0;
+unsigned char* outPtr = 0;
+int outBytes = 0;
+
+int bit_buf;
+int bit_count;
+
+void init_bits() {
+
+ bit_count = bit_buf=0;
+
+}
+
+void put_bits(int n, int x) {
+
+ bit_buf |= x<<bit_count;
+ bit_count += n;
+
+ while(bit_count >= 8) {
+
+ *outPtr = bit_buf;
+ outPtr++;
+ outBytes++;
+
+ bit_buf >>= 8;
+ bit_count -= 8;
+
+ }
+
+}
+
+void flush_bits() {
+
+ put_bits(7, 0);
+ bit_count = bit_buf = 0;
+
+}
+
+int get_bits(int n) {
+
+ int x;
+
+ while(bit_count < n) {
+
+ bit_buf |= *inPtr<<bit_count;
+ inPtr++;
+ inBytes++;
+
+ bit_count += 8;
+
+ }
+
+ x = bit_buf&((1<<n)-1);
+ bit_buf >>= n;
+ bit_count -= n;
+
+ return(x);
+
+}