1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "DemoBufferObject.h"
7 // static void Class_Terminate();
8 // static int RemoveLastDemoKey();
10 // --- VERSION 1.0 CLASS
12 // --- MultiUse = -1 'True // True
13 // --- Persistable = 0 'NotPersistable // NotPersistable
14 // --- DataBindingBehavior = 0 'vbNone // vbNone
15 // --- DataSourceBehavior = 0 'vbNone // vbNone
16 // --- MTSTransactionMode = 0 'NotAnMTSObject // NotAnMTSObject
19 // static char *VB_Name = "DemoBufferObject";
20 // static boolean VB_GlobalNameSpace = False;
21 // static boolean VB_Creatable = True;
22 // static boolean VB_PredeclaredId = False;
23 // static boolean VB_Exposed = False;
25 // --- Option Explicit
27 #define MaxPos ((long)1024)
29 // Private Const MaxPos& = 20& 'debug only
30 byte DemoByte[MaxPos + 1];
31 DemoBufferObject SubBuffer;
36 boolean bSignatureAvailable;
45 static void Class_Initialize()
49 Trace("DemoBufferObject", "Construction");
50 DemoBufferObject_Reset();
51 if (! IS_NOTHING(&DemoBuffer, sizeof(DemoBuffer)))
53 lSize = DemoBuffer_Size();
54 Trace("DemoBufferObject", "Size == ...");
55 Trace("DemoBufferObject", "BufferCount == ...");
56 Trace("DemoBufferObject", "TimerVar == ...");
60 static void Class_Terminate()
62 SET_TO_NOTHING(&SubBuffer, sizeof(SubBuffer));
67 void DemoBufferObject_Reset()
74 bSignatureAvailable = False;
76 SET_TO_NOTHING(&SubBuffer, sizeof(SubBuffer));
79 long DemoBufferObject_Get_Size()
83 Size = (nSize < 1 ? 0 : nSize);
84 if (! IS_NOTHING(&SubBuffer, sizeof(SubBuffer)))
85 Size = Size + SubBuffer.Size;
90 byte DemoBufferObject_Get_CheckSumByte()
94 CheckSumByte = CheckSum & 0xFF;
99 byte DemoBufferObject_Get_FirstByte()
103 FirstByte = nFirstByte;
108 void DemoBufferObject_Let_FirstByte(byte NewVal)
114 // Public Property Get DemoAvailable() As Boolean
115 // DemoAvailable = (0 < nSize)
118 // Public Property Get Signature() As String
119 // If SubBuffer Is Nothing Then
120 // Signature = mSignature
122 // Signature = SubBuffer.Signature
126 // Public Property Let Signature(NewSig$)
127 // If SubBuffer Is Nothing Then
128 // Signature = NewSig
130 // SubBuffer.Signature = NewSig
134 // Public Property Get SignatureAvailable() As Boolean
135 // If SubBuffer Is Nothing Then
136 // SignatureAvailable = (mSignature <> "")
138 // SignatureAvailable = SubBuffer
142 boolean DemoBufferObject_Serialize(FILE *FNum)
149 if (! IS_NOTHING(&SubBuffer, sizeof(SubBuffer)))
150 Serialize = SubBuffer.Serialize(FNum);
155 // LKey = RemoveLastDemoKey()
156 if (! nSize < MaxPos) // this buffer is full
159 // --- On Error GoTo SerializeEH
160 FILE_PUT(FNum, -1, &DemoByte, sizeof(DemoByte));
161 // --- On Error GoTo 0
164 else // this is the last buffer in the recursive chain
167 // --- On Error GoTo SerializeEH
168 for (i = 1; i <= WritePos; i++)
170 FILE_PUT(FNum, -1, &DemoByte[i], sizeof(DemoByte[i]));
173 // --- On Error GoTo 0
186 void DemoBufferObject_AddDemoKey(int KeyCode)
188 CheckSum = (CheckSum + 1) & 0xFF; // increment checksum
189 // If Not SubBuffer Is Nothing Then 'delegate
190 // Debug.Assert False
191 // 'SubBuffer.AddDemoKey KeyCode
194 if (LastKey == KeyCode)
196 DemoByte[WritePos] = DemoByte[WritePos] + 0x10;
197 if (0xEF < DemoByte[WritePos])
201 else // LastKey <> KeyCode
203 WritePos = WritePos + 1;
205 if (MaxPos < WritePos) // if overflow then create new buffer, hang myself in list
207 DemoBufferObject Tmp;
209 // Tmp = New DemoBufferObject; // (handle this later, if needed)
210 Tmp.SetSubBuffer(&VB_OBJECT_SELF);
211 Tmp.AddDemoKey(KeyCode); // and delegate
216 nSize = nSize + 1; // increment size
217 DemoByte[WritePos] = KeyCode;
223 void DemoBufferObject_SetSubBuffer(DemoBufferObject SBuf)
230 static int RemoveLastDemoKey()
232 static int RemoveLastDemoKey;
234 RemoveLastDemoKey = (DemoByte[WritePos] & 0xF);
235 if (DemoByte[WritePos] < 0x10)
237 WritePos = WritePos - 1;
243 DemoByte[WritePos] = DemoByte[WritePos] - 0x10;
246 return RemoveLastDemoKey;