Debian Codegraph @

sramstream.h

raw symbols SCIP
1 /*
2 * PROPRIETARY INFORMATION. This software is proprietary to POWDER
3 * Development, and is not to be reproduced, transmitted, or disclosed
4 * in any way without written permission.
5 *
6 * Produced by: Jeff Lait
7 *
8 * POWDER Development
9 *
10 * NAME: sramstream.h ( POWDER Library, C++ )
11 *
12 * COMMENTS:
13 * This is an attempt to provide a bit level stream to the SRAM
14 * for backup & restoration.
15 */
16
17 #ifndef __sramstream_h__
18 #define __sramstream_h__
19
20 //
21 // Hamfake methods for accessing save data.
22 //
23 char *hamfake_readLockSRAM();
24 void hamfake_readUnlockSRAM(char *);
25
26 char *hamfake_writeLockSRAM();
27 void hamfake_writeUnlockSRAM(char *);
28
29 void hamfake_endWritingSession();
30
31 enum COMPRESS_TYPE
32 {
33 COMPRESS_NONE,
34 COMPRESS_CONSTANT,
35 COMPRESS_ZEROTABLE,
36 COMPRESS_RLE
37 };
38
39 enum PREPROCESS_TYPE
40 {
41 PREPROCESS_NONE,
42 PREPROCESS_BYTE,
43 PREPROCESS_SHORT,
44 PREPROCESS_INT
45 };
46
47 class SRAMSTREAM
48 {
49 public:
50 SRAMSTREAM(bool silent);
51 ~SRAMSTREAM();
52
53 // Rest read/write pointer to start of SRAM.
54 void rewind();
55
56 bool writeRaw(const char *data, int numbytes);
57 bool readRaw(char *data, int numbytes);
58
59 // Write given number of bits into stream. Returns false if failed.
60 bool write(int val, int bits);
61 // Reads a given number of bits. Also returns false if failed.
62 bool read(int &val, int bits);
63 // Unsigned read.
64 bool uread(int &val, int bits);
65
66 // Reads up to maxlen-1, then null terminates.
67 // false for failure.
68 // We have max len on both sides to ensure the two are in sync.
69 bool readString(char *dst, int maxlen);
70 bool writeString(const char *src, int maxlen);
71
72 // Flushes buffer into SRAM. Do at end of writes to guarantee last
73 // bit is written.
74 bool flush();
75
76 protected:
77 void writeToSRAM(char *data, int len);
78 void readFromSRAM(char *data, int len);
79
80 // Compression methods...
81 int compress(char *dst, char *src, int blocklen);
82 int compressConstant(char *dst, char *src);
83 int compressNone(char *dst, char *src, int len, bool header=true);
84 int compressZeroTable(char *dst, char *src, PREPROCESS_TYPE preprocess, int len);
85 int compressRLE(char *dst, char *src, int len, bool header=true);
86 int decompress(char *dst, char *src, int blocklen);
87 int decompressConstant(char *dst, char *src, int len);
88 int decompressNone(char *dst, char *src, int len);
89 int decompressZeroTable(char *dst, char *src, PREPROCESS_TYPE preprocess, int blocklen);
90 int decompressRLE(char *dst, char *src, int len);
91
92 private:
93 int mySRAMPtr; // char offset in SRAM
94 int myPos; // char offset in myBuffer
95 int myBit; // bit offset in myBuffer[myPos]
96 char myBuffer[1024];
97 int myNumBlocks;
98 bool mySilent;
99 };
100
101 #endif