-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGLCD.c
More file actions
293 lines (257 loc) · 6.96 KB
/
Copy pathGLCD.c
File metadata and controls
293 lines (257 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include "glcd.h"
#include "spritesheet.h"
#include<math.h>
U8 displayBuffer[DISPLAY_WIDTH*DISPLAY_HEIGHT];
void delay_us(U32 count)
{
U32 i,j;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of APPROX 1 us */
for(i=0;i<4;i++);
}
}
void glcdInit(void)
{
IO0DIR|=(1<<GLCD_RS|1<<GLCD_RW|1<<GLCD_EN|1<<GLCD_RST|1<<GLCD_CS1|1<<GLCD_CS2);
IO0DIR|=0xFF<<DATASHIFT;
IO0SET|=1<<GLCD_RST;
IO0CLR|=1<<GLCD_EN;
glcdSelectPage0();
glcdSendCommand(0x3F);//LCD ON
glcdSendCommand(0xC0);//START FROM LEFTMOST
glcdSendCommand(0xB8);//LINE 0
glcdSendCommand(0x40);//CURSOR 0
glcdSelectPage1();
glcdSendCommand(0x3F);//LCD ON
glcdSendCommand(0xC0);//START FROM LEFTMOST
glcdSendCommand(0xB8);//LINE 0
glcdSendCommand(0x40);//CURSOR 0
}
void glcdBusy(void)
{
IO0DIR&=~(1<<BUSYBIT);//SET BUSY_BIT AS INPUT
delay_us(1);
IO0SET|=1<<GLCD_RW;//SET RW FOR READ MODE
IO0CLR|=1<<GLCD_RS;//CLR RS FOR COMMAND MODE
delay_us(1);
IO0SET|=1<<GLCD_EN;
delay_us(1);
while(IO0PIN&(1<<BUSYBIT));//WAIT FOR INTERNAL OPERATION
IO0CLR|=1<<GLCD_EN;
IO0DIR|=1<<BUSYBIT;
}
void glcdSendCommand(U8 command)
{
glcdBusy();//WAIT
IO0CLR|=1<<GLCD_RS;
IO0CLR|=1<<GLCD_RW;
IO0CLR|=0xFF<<DATASHIFT;
IO0SET|=command<<DATASHIFT;
delay_us(5);
IO0SET|=1<<GLCD_EN;
delay_us(5);
IO0CLR|=1<<GLCD_EN;
}
void glcdSendData(U8 data)
{
glcdBusy();//WAIT
IO0SET|=1<<GLCD_RS;
IO0CLR|=1<<GLCD_RW;
IO0CLR|=0xFF<<DATASHIFT;
IO0SET|=data<<DATASHIFT;
delay_us(5);
IO0SET|=1<<GLCD_EN;
delay_us(5);
IO0CLR|=1<<GLCD_EN;
}
void glcdDisplay()
{
S16 line,cursor;
for(line=0;line<8;++line)
{
glcdSelectPage0();
glcdSendCommand(0x40);
glcdSendCommand(0xB8+line);
for(cursor=0;cursor<128;++cursor)
{
glcdSendData(displayBuffer[128*line+cursor]);
if(cursor==63)
{
glcdSelectPage1();
glcdSendCommand(0x40);
glcdSendCommand(0xB8+line);
}
}
}
}
void modifyBuffer(U8 command)
{
U16 index;
switch(command)
{
case CLEAR:for(index=0;index<128*64;++index)
displayBuffer[index]=0x00;
break;
case HOME:for(index=0;index<128*64;++index)
displayBuffer[index]=home1971[index];
break;
case VICTORY:for(index=0;index<128*64;++index)
displayBuffer[index]=victory[index];
break;
case DEFEAT:for(index=0;index<128*64;++index)
displayBuffer[index]=defeat[index];
break;
default:break;
}
}
void addBufferUnit(U8 command,S16 line,S16 cursor)
{
U16 index;
switch(command)
{
case RM_IND_R:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=rm00[index];
break;
case RM_IND_L:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=rm01[index];
break;
case RM_PAK_R:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=rm10[index];
break;
case RM_PAK_L:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=rm11[index];
break;
case TK_IND_R:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=tk00[index];
break;
case TK_IND_L:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=tk01[index];
break;
case TK_IND_U:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=tk02[index];
break;
case TK_IND_D:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=tk03[index];
break;
case TK_PAK_R:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=tk10[index];
break;
case TK_PAK_L:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=tk11[index];
break;
case TK_PAK_U:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=tk12[index];
break;
case TK_PAK_D:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=tk13[index];
break;
case HZ_IND_R:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=hz00[index];
break;
case HZ_IND_L:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=hz01[index];
break;
case HZ_IND_U:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=hz02[index];
break;
case HZ_IND_D:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=hz03[index];
break;
case HZ_PAK_R:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=hz10[index];
break;
case HZ_PAK_L:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=hz11[index];
break;
case HZ_PAK_U:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=hz12[index];
break;
case HZ_PAK_D:for(index=0;index<8;++index)
displayBuffer[line*128+cursor+index]=hz13[index];
break;
default:break;
}
}
void addBufferChar(U16 letter,S16 line,S16 cursor)
{
U16 index,index2;
for(index=0;index<8*letter;index+=8);
for(index2=index;index2<8+index;++index2)
displayBuffer[line*128+cursor+index2-index]=cga8[index2];
}
void addBufferString(U8 word[],U8 length,S16 line,S16 cursor)
{
U16 index;
for(index=0;index<length;++index)
addBufferChar(word[index],line,cursor+8*index);
}
void addBufferSmallChar(U8 letter,S16 line,S16 cursor)
{
U16 index,index2;
if(letter==' ')
letter=26;
else if(letter=='.')
letter=27;
else
letter-=65;
for(index=0;index<5*letter;index+=5);
for(index2=index;index2<5+index;++index2)
displayBuffer[line*128+cursor+index2-index]=cgaSmall[index2];
}
void addBufferSmallString(U8 word[],U8 length,S16 line,S16 cursor)
{
U16 index;
for(index=0;index<length;++index)
addBufferSmallChar(word[index],line,cursor+6*index);
}
void addBufferBoldChar(U8 letter,S16 line,S16 cursor)
{
addBufferChar(letter+32*8,line,cursor);
}
void addBufferBoldString(U8 word[],U8 length,S16 line,S16 cursor)
{
U16 index;
for(index=0;index<length;++index)
addBufferBoldChar(word[index],line,cursor+8*index);
}
void addBufferNumber(U16 number,S16 line,S16 cursor)
{
U16 index;
cursor+=16;
if(number==0)
addBufferChar(number+48,line,cursor);
else
{
for(index=0;index<3;number/=10,cursor-=8,++index)
addBufferChar(number%10+48,line,cursor);//+256
}
}
void addBufferSelection(S16 line,S16 cursor)
{
displayBuffer[128*line+cursor]|=129;
displayBuffer[128*line+cursor+7]|=129;
}
void addBufferEnemyHPBar(S16 line,S16 cursor,S16 hp,S16 maxhp)
{
S16 life=ceil(hp*8.0/maxhp);
switch(life)
{
case 8:displayBuffer[128*line+cursor+7]|=1;
case 7:displayBuffer[128*line+cursor+6]|=1;
case 6:displayBuffer[128*line+cursor+5]|=1;
case 5:displayBuffer[128*line+cursor+4]|=1;
case 4:displayBuffer[128*line+cursor+3]|=1;
case 3:displayBuffer[128*line+cursor+2]|=1;
case 2:displayBuffer[128*line+cursor+1]|=1;
case 1:displayBuffer[128*line+cursor]|=1;break;
default:break;
}
}
void addBufferDestruction(S16 line,S16 cursor)
{
U16 index;
for(index=0;index<8;++index)
displayBuffer[128*line+cursor+index]=0;
}