| User | Revision | Line number | New contents of line |
| emh203 |
0:76427232f435
|
1
|
#include "mbed.h"
|
| emh203 |
0:76427232f435
|
2
|
#include "DataTypes.h"
|
| emh203 |
0:76427232f435
|
3
|
|
| emh203 |
0:76427232f435
|
4
|
CHAR StringBuffer[256];
|
| emh203 |
0:76427232f435
|
5
|
|
| emh203 |
0:76427232f435
|
6
|
SIGNED_WORD ByteStackPush(ByteStack * Stack,BYTE Val) {
|
| emh203 |
0:76427232f435
|
7
|
if (Stack->Ptr == Stack->Size-1) {
|
| emh203 |
0:76427232f435
|
8
|
return STACK_FULL;
|
| emh203 |
0:76427232f435
|
9
|
} else {
|
| emh203 |
0:76427232f435
|
10
|
Stack->Ptr++;
|
| emh203 |
0:76427232f435
|
11
|
Stack->StackSpace[Stack->Ptr] = Val;
|
| emh203 |
0:76427232f435
|
12
|
return STACK_PUSH_OK;
|
| emh203 |
0:76427232f435
|
13
|
}
|
| emh203 |
0:76427232f435
|
14
|
}
|
| emh203 |
0:76427232f435
|
15
|
|
| emh203 |
0:76427232f435
|
16
|
SIGNED_WORD ByteStackPOP(ByteStack * Stack) {
|
| emh203 |
0:76427232f435
|
17
|
if (Stack->Ptr == 0) {
|
| emh203 |
0:76427232f435
|
18
|
return STACK_EMPTY;
|
| emh203 |
0:76427232f435
|
19
|
} else {
|
| emh203 |
0:76427232f435
|
20
|
Stack->Ptr--;
|
| emh203 |
0:76427232f435
|
21
|
return Stack->StackSpace[Stack->Ptr];
|
| emh203 |
0:76427232f435
|
22
|
}
|
| emh203 |
0:76427232f435
|
23
|
}
|
| emh203 |
0:76427232f435
|
24
|
|
| emh203 |
0:76427232f435
|
25
|
SIGNED_BYTE BitStackPush(BitStack * Stack,BOOL Val) {
|
| emh203 |
0:76427232f435
|
26
|
WORD Offset;
|
| emh203 |
0:76427232f435
|
27
|
BYTE Mask;
|
| emh203 |
0:76427232f435
|
28
|
|
| emh203 |
0:76427232f435
|
29
|
if (Stack->Ptr == Stack->Size-1) {
|
| emh203 |
0:76427232f435
|
30
|
return STACK_FULL;
|
| emh203 |
0:76427232f435
|
31
|
} else {
|
| emh203 |
0:76427232f435
|
32
|
|
| emh203 |
0:76427232f435
|
33
|
Stack->Ptr++;
|
| emh203 |
0:76427232f435
|
34
|
Offset = (Stack->Ptr)>>3;
|
| emh203 |
0:76427232f435
|
35
|
Mask = 0x01<<(Stack->Ptr&0x07);
|
| emh203 |
0:76427232f435
|
36
|
|
| emh203 |
0:76427232f435
|
37
|
if (Val) {
|
| emh203 |
0:76427232f435
|
38
|
Stack->StackSpace[Offset] |= Mask;
|
| emh203 |
0:76427232f435
|
39
|
} else {
|
| emh203 |
0:76427232f435
|
40
|
Stack->StackSpace[Offset] &= ~Mask;
|
| emh203 |
0:76427232f435
|
41
|
}
|
| emh203 |
0:76427232f435
|
42
|
|
| emh203 |
0:76427232f435
|
43
|
return STACK_PUSH_OK;
|
| emh203 |
0:76427232f435
|
44
|
}
|
| emh203 |
0:76427232f435
|
45
|
}
|
| emh203 |
0:76427232f435
|
46
|
|
| emh203 |
0:76427232f435
|
47
|
SIGNED_BYTE BitStackPop(BitStack * Stack) {
|
| emh203 |
0:76427232f435
|
48
|
WORD Offset;
|
| emh203 |
0:76427232f435
|
49
|
BYTE Mask;
|
| emh203 |
0:76427232f435
|
50
|
|
| emh203 |
0:76427232f435
|
51
|
if (Stack->Ptr == 0) {
|
| emh203 |
0:76427232f435
|
52
|
return STACK_EMPTY;
|
| emh203 |
0:76427232f435
|
53
|
} else {
|
| emh203 |
0:76427232f435
|
54
|
|
| emh203 |
0:76427232f435
|
55
|
Stack->Ptr++;
|
| emh203 |
0:76427232f435
|
56
|
Offset = (Stack->Ptr)>>3;
|
| emh203 |
0:76427232f435
|
57
|
Mask = 0x01<<(Stack->Ptr&0x07);
|
| emh203 |
0:76427232f435
|
58
|
|
| emh203 |
0:76427232f435
|
59
|
if (Stack->StackSpace[Offset] | Mask) {
|
| emh203 |
0:76427232f435
|
60
|
return TRUE;
|
| emh203 |
0:76427232f435
|
61
|
} else {
|
| emh203 |
0:76427232f435
|
62
|
return FALSE;
|
| emh203 |
0:76427232f435
|
63
|
}
|
| emh203 |
0:76427232f435
|
64
|
}
|
| emh203 |
0:76427232f435
|
65
|
}
|
| emh203 |
0:76427232f435
|
66
|
|
| emh203 |
0:76427232f435
|
67
|
#ifndef INLINE_BITPLANE_PUT
|
| emh203 |
0:76427232f435
|
68
|
void BitPlane_Put(BitPlane * BP, WORD X,WORD Y, BOOL Value)
|
| emh203 |
0:76427232f435
|
69
|
{
|
| emh203 |
0:76427232f435
|
70
|
WORD Offset;
|
| emh203 |
0:76427232f435
|
71
|
BYTE Mask;
|
| emh203 |
0:76427232f435
|
72
|
|
| emh203 |
0:76427232f435
|
73
|
Offset = (Y * ((BP->SizeX)>>3)) + (X>>3);
|
| emh203 |
0:76427232f435
|
74
|
Mask = 0x01 << (X & 0x07);
|
| emh203 |
0:76427232f435
|
75
|
|
| emh203 |
0:76427232f435
|
76
|
if(Value)
|
| emh203 |
0:76427232f435
|
77
|
{
|
| emh203 |
0:76427232f435
|
78
|
BP->BitPlaneSpace[Offset] |= Mask;
|
| emh203 |
0:76427232f435
|
79
|
}
|
| emh203 |
0:76427232f435
|
80
|
else
|
| emh203 |
0:76427232f435
|
81
|
{
|
| emh203 |
0:76427232f435
|
82
|
BP->BitPlaneSpace[Offset] &= ~Mask;
|
| emh203 |
0:76427232f435
|
83
|
}
|
| emh203 |
0:76427232f435
|
84
|
}
|
| emh203 |
0:76427232f435
|
85
|
#endif
|
| emh203 |
0:76427232f435
|
86
|
|
| emh203 |
0:76427232f435
|
87
|
#ifndef INLINE_BITPLANE_GET
|
| emh203 |
0:76427232f435
|
88
|
BOOL BitPlane_Get(BitPlane * BP, WORD X,WORD Y)
|
| emh203 |
0:76427232f435
|
89
|
{
|
| emh203 |
0:76427232f435
|
90
|
WORD Offset;
|
| emh203 |
0:76427232f435
|
91
|
BYTE Mask;
|
| emh203 |
0:76427232f435
|
92
|
|
| emh203 |
0:76427232f435
|
93
|
Offset = (Y * ((BP->SizeX)>>3)) + (X>>3);
|
| emh203 |
0:76427232f435
|
94
|
Mask = 0x01 << (X & 0x07);
|
| emh203 |
0:76427232f435
|
95
|
|
| emh203 |
0:76427232f435
|
96
|
if((BP->BitPlaneSpace[Offset])&Mask)
|
| emh203 |
0:76427232f435
|
97
|
{
|
| emh203 |
0:76427232f435
|
98
|
return TRUE;
|
| emh203 |
0:76427232f435
|
99
|
}
|
| emh203 |
0:76427232f435
|
100
|
else
|
| emh203 |
0:76427232f435
|
101
|
{
|
| emh203 |
0:76427232f435
|
102
|
return FALSE;
|
| emh203 |
0:76427232f435
|
103
|
}
|
| emh203 |
0:76427232f435
|
104
|
}
|
| emh203 |
0:76427232f435
|
105
|
#endif
|
| emh203 |
0:76427232f435
|
106
|
void BitPlane_Clear(BitPlane * BP) {
|
| emh203 |
0:76427232f435
|
107
|
WORD PlaneSpaceSize;
|
| emh203 |
0:76427232f435
|
108
|
WORD i;
|
| emh203 |
0:76427232f435
|
109
|
|
| emh203 |
0:76427232f435
|
110
|
PlaneSpaceSize = ((BP->SizeX)>>3) * BP->SizeY;
|
| emh203 |
0:76427232f435
|
111
|
|
| emh203 |
0:76427232f435
|
112
|
for (i=0;i<PlaneSpaceSize;i++) {
|
| emh203 |
0:76427232f435
|
113
|
BP->BitPlaneSpace[i] = 0;
|
| emh203 |
0:76427232f435
|
114
|
}
|
| emh203 |
0:76427232f435
|
115
|
}
|
| emh203 |
0:76427232f435
|
116
|
|
| emh203 |
0:76427232f435
|
117
|
|
| emh203 |
0:76427232f435
|
118
|
|
| emh203 |
0:76427232f435
|
119
|
void InitByteQueue(ByteQueue *BQ,WORD Size,BYTE * Storage) {
|
| emh203 |
0:76427232f435
|
120
|
WORD i;
|
| emh203 |
0:76427232f435
|
121
|
|
| emh203 |
0:76427232f435
|
122
|
BQ->QueueSize = Size;
|
| emh203 |
0:76427232f435
|
123
|
BQ->ReadPtr=0;
|
| emh203 |
0:76427232f435
|
124
|
BQ->WritePtr=0;
|
| emh203 |
0:76427232f435
|
125
|
BQ->QueueStorage = Storage;
|
| emh203 |
0:76427232f435
|
126
|
|
| emh203 |
0:76427232f435
|
127
|
for (i=0;i<BQ->QueueSize;i++) {
|
| emh203 |
0:76427232f435
|
128
|
BQ->QueueStorage[i] = 0;
|
| emh203 |
0:76427232f435
|
129
|
}
|
| emh203 |
0:76427232f435
|
130
|
}
|
| emh203 |
0:76427232f435
|
131
|
|
| emh203 |
0:76427232f435
|
132
|
WORD BytesInQueue(ByteQueue *BQ) {
|
| emh203 |
0:76427232f435
|
133
|
if (BQ->ReadPtr > BQ->WritePtr) {
|
| emh203 |
0:76427232f435
|
134
|
return (BQ->QueueSize - BQ->ReadPtr + BQ->WritePtr);
|
| emh203 |
0:76427232f435
|
135
|
} else if (BQ->WritePtr > BQ->ReadPtr) {
|
| emh203 |
0:76427232f435
|
136
|
return (BQ->WritePtr - BQ->ReadPtr);
|
| emh203 |
0:76427232f435
|
137
|
} else {
|
| emh203 |
0:76427232f435
|
138
|
return 0;
|
| emh203 |
0:76427232f435
|
139
|
}
|
| emh203 |
0:76427232f435
|
140
|
}
|
| emh203 |
0:76427232f435
|
141
|
|
| emh203 |
0:76427232f435
|
142
|
SIGNED_WORD ByteEnqueue(ByteQueue *BQ,BYTE Val) {
|
| emh203 |
0:76427232f435
|
143
|
if (BytesInQueue(BQ) == BQ->QueueSize) {
|
| emh203 |
0:76427232f435
|
144
|
return QUEUE_FULL;
|
| emh203 |
0:76427232f435
|
145
|
} else {
|
| emh203 |
0:76427232f435
|
146
|
BQ->QueueStorage[BQ->WritePtr] = Val;
|
| emh203 |
0:76427232f435
|
147
|
BQ->WritePtr++;
|
| emh203 |
0:76427232f435
|
148
|
|
| emh203 |
0:76427232f435
|
149
|
if (BQ->WritePtr >= BQ->QueueSize) {
|
| emh203 |
0:76427232f435
|
150
|
BQ->WritePtr = 0;
|
| emh203 |
0:76427232f435
|
151
|
}
|
| emh203 |
0:76427232f435
|
152
|
return QUEUE_OK;
|
| emh203 |
0:76427232f435
|
153
|
}
|
| emh203 |
0:76427232f435
|
154
|
}
|
| emh203 |
0:76427232f435
|
155
|
|
| emh203 |
0:76427232f435
|
156
|
SIGNED_WORD ByteArrayEnqueue(ByteQueue *BQ,BYTE *Buf,WORD Len) {
|
| emh203 |
0:76427232f435
|
157
|
WORD i;
|
| emh203 |
0:76427232f435
|
158
|
for (i=0;i<Len;i++) {
|
| emh203 |
0:76427232f435
|
159
|
ByteEnqueue(BQ,Buf[i]);
|
| emh203 |
0:76427232f435
|
160
|
}
|
| emh203 |
0:76427232f435
|
161
|
return QUEUE_OK;
|
| emh203 |
0:76427232f435
|
162
|
}
|
| emh203 |
0:76427232f435
|
163
|
|
| emh203 |
0:76427232f435
|
164
|
SIGNED_WORD PrintfEnqueue(ByteQueue *BQ, const char *FormatString,...)
|
| emh203 |
0:76427232f435
|
165
|
{
|
| emh203 |
0:76427232f435
|
166
|
|
| emh203 |
0:76427232f435
|
167
|
va_list argptr;
|
| emh203 |
0:76427232f435
|
168
|
va_start(argptr,FormatString);
|
| emh203 |
0:76427232f435
|
169
|
vsprintf((CHAR *)StringBuffer,FormatString,argptr);
|
| emh203 |
0:76427232f435
|
170
|
va_end(argptr);
|
| emh203 |
0:76427232f435
|
171
|
|
| emh203 |
0:76427232f435
|
172
|
ByteArrayEnqueue(BQ,(BYTE *)StringBuffer,strlen(StringBuffer));
|
| emh203 |
0:76427232f435
|
173
|
|
| emh203 |
0:76427232f435
|
174
|
return QUEUE_OK;
|
| emh203 |
0:76427232f435
|
175
|
}
|
| emh203 |
0:76427232f435
|
176
|
|
| emh203 |
0:76427232f435
|
177
|
|
| emh203 |
0:76427232f435
|
178
|
|
| emh203 |
0:76427232f435
|
179
|
|
| emh203 |
0:76427232f435
|
180
|
SIGNED_WORD ByteDequeue(ByteQueue *BQ,BYTE *Val) {
|
| emh203 |
0:76427232f435
|
181
|
|
| emh203 |
0:76427232f435
|
182
|
if (BytesInQueue(BQ) == 0) {
|
| emh203 |
0:76427232f435
|
183
|
return QUEUE_EMPTY;
|
| emh203 |
0:76427232f435
|
184
|
} else {
|
| emh203 |
0:76427232f435
|
185
|
*Val = BQ->QueueStorage[BQ->ReadPtr];
|
| emh203 |
0:76427232f435
|
186
|
|
| emh203 |
0:76427232f435
|
187
|
BQ->ReadPtr++;
|
| emh203 |
0:76427232f435
|
188
|
|
| emh203 |
0:76427232f435
|
189
|
if (BQ->ReadPtr >= BQ->QueueSize) {
|
| emh203 |
0:76427232f435
|
190
|
BQ->ReadPtr = 0;
|
| emh203 |
0:76427232f435
|
191
|
}
|
| emh203 |
0:76427232f435
|
192
|
return QUEUE_OK;
|
| emh203 |
0:76427232f435
|
193
|
}
|
| emh203 |
0:76427232f435
|
194
|
} |