-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot.c
194 lines (189 loc) · 7.61 KB
/
dot.c
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
/************************************************************************************************************************
* [FILE NAME] : <dot.c> *
* [AUTHOR] : <Eslam EL-Naggar> *
* [DATE CREATED]: <JAN 1, 2020> *
* [Description} : <Source file for the dot functions> *
************************************************************************************************************************/
/*-------------------------------------------------INCLUDES-------------------------------------------------------------*/
#include "glcd.h"
#include "dot.h"
/*--------------------------------------------FUNCTIONS DEFINITIONS-----------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------
[Function Name]: dotEliminator
[Description] : This function is responsible for dot erasing
[Args] :
[IN] :
uint8 *const column_Ptr
this argument shall contain the address of column variable which indicate Dot X coordinate
uint8 *const page_Ptr
this argument shall contain the address of column variable which indicate Dot Y coordinate
uint8 *const i_Ptr
this argument shall contain the address of column variable which indicate Dot Level coordinate
[Returns] : This function returns void
------------------------------------------------------------------------------------------------------------------------*/
void dotEliminator(uint8 *const column_Ptr, uint8 *const page_Ptr,
uint8 *const i_Ptr) {
uint8 state;
uint8 columnTemp;
uint8 n;
cli();
if (*column_Ptr < 64) {
columnTemp = *column_Ptr;
GLCD_CTRL_PORT |= (1 << CS1); /* Select Left half of display */
GLCD_CTRL_PORT &= ~(1 << CS2);
} else if (*column_Ptr >= 64) {
columnTemp = *column_Ptr - 64;
GLCD_CTRL_PORT |= (1 << CS2); /* Select Right half of display */
GLCD_CTRL_PORT &= ~(1 << CS1);
}
GLCD_sendCommand(0x40 + columnTemp); /* Set column address (column=0) */
GLCD_sendCommand(0xB8 + *page_Ptr); /* Set page address (page=0) */
for (n = 0; n < 2; n++) {
state = GLCD_readData();
}
GLCD_sendCommand(0x40 + columnTemp); /* Set column address (column=0) */
GLCD_sendCommand(0xB8 + *page_Ptr); /* Set page address (page=0) */
GLCD_sendData(state & ~(0x80 >> *i_Ptr));
sei();
}
/*----------------------------------------------------------------------------------------------------
[Function Name]: dotCreator
[Description] : This function is responsible for dot creator
[Args] :
[IN] :
uint8 *const column_Ptr
this argument shall contain the address of column variable which indicate Dot X coordinate
uint8 *const page_Ptr
this argument shall contain the address of column variable which indicate Dot Y coordinate
uint8 *const i_Ptr
this argument shall contain the address of column variable which indicate Dot Level coordinate
uint8 *const directions_Ptr
this argument shall contain the address of direction variable
uint8 *const flagSlider_Ptr
this argument shall contain the address of flagSlider check variable
uint16 *const score_Ptr
this argument shall contain the address of score variable
[Returns] : This function returns void
----------------------------------------------------------------------------------------------------*/
void dotCreator(uint8 *const flagSlider_Ptr, uint8 *const column_Ptr,
uint8 *const page_Ptr, uint8 *const directions_Ptr, uint8 *const i_Ptr,
uint16 *const score_Ptr) {
uint8 state;
uint8 columnTemp;
uint8 n;
cli();
if (*column_Ptr < 64) {
columnTemp = *column_Ptr;
GLCD_CTRL_PORT |= (1 << CS1); /* Select Left half of display */
GLCD_CTRL_PORT &= ~(1 << CS2);
} else if (*column_Ptr >= 64) {
columnTemp = *column_Ptr - 64;
GLCD_CTRL_PORT |= (1 << CS2); /* Select Right half of display */
GLCD_CTRL_PORT &= ~(1 << CS1);
}
GLCD_sendCommand(0x40 + columnTemp); /* Set column address (column=0) */
GLCD_sendCommand(0xB8 + *page_Ptr); /* Set page address (page=0) */
for (n = 0; n < 2; n++) {
state = GLCD_readData();
}
if ((state & (0x80 >> (*i_Ptr)))) {
if (*page_Ptr == 7) {
*flagSlider_Ptr = 1;
} else {
(*score_Ptr)++;
}
switch (*directions_Ptr) {
case UPPER_RIGHT:
*directions_Ptr = DOWN_RIGHT;
break;
case UPPER_LEFT:
*directions_Ptr = DOWN_LEFT;
break;
case DOWN_LEFT:
*directions_Ptr = UPPER_LEFT;
break;
case DOWN_RIGHT:
*directions_Ptr = UPPER_RIGHT;
break;
}
}
GLCD_sendCommand(0x40 + columnTemp); /* Set column address (column=0) */
GLCD_sendCommand(0xB8 + *page_Ptr); /* Set page address (page=0) */
GLCD_sendData((state & ~(0x80 >> *i_Ptr)) | 0x80 >> (*i_Ptr));
sei();
}
/*----------------------------------------------------------------------------------------------------
[Function Name]: locationGenerator
[Description] : This function is responsible for location of the dot
[Args] :
[IN] :
uint8 *const column_Ptr
this argument shall contain the address of column variable which indicate Dot X coordinate
uint8 *const page_Ptr
this argument shall contain the address of column variable which indicate Dot Y coordinate
uint8 *const i_Ptr
this argument shall contain the address of column variable which indicate Dot Level coordinate
uint8 *const directions_Ptr
this argument shall contain the address of direction variable
uint8 *const loseFlag_Ptr
this argument shall contain the address of loseFlag check Variable
[Returns] : This function returns void
----------------------------------------------------------------------------------------------------*/
void locationGenerator(uint8 *const column_Ptr, uint8 *const page_Ptr,
uint8 *const directions_Ptr, uint8 *const i_Ptr,
uint8 *const loseFlag_Ptr) {
cli();
switch (*directions_Ptr) {
case DOWN_RIGHT: //DOWN_RIGHT Direction
*column_Ptr = *column_Ptr + 1;
(*i_Ptr)--;
if (*column_Ptr == 127) {
*directions_Ptr = DOWN_LEFT;
}
if ((*i_Ptr) > 7) {
(*i_Ptr) = 7;
(*page_Ptr)++;
}
if (*page_Ptr == 8) {
(*loseFlag_Ptr) = 1;
}
break;
case DOWN_LEFT: //DOWN_LEFT Direction
*column_Ptr = *column_Ptr - 1;
(*i_Ptr)--;
if (*column_Ptr == 0) {
*directions_Ptr = DOWN_RIGHT;
}
if ((*i_Ptr) > 7) {
(*i_Ptr) = 7;
(*page_Ptr)++;
}
if (*page_Ptr == 8) {
(*loseFlag_Ptr) = 1;
}
break;
case UPPER_LEFT: //UPPER_LEFT Direction
*column_Ptr = *column_Ptr - 1;
(*i_Ptr)++;
if (*column_Ptr == 0) {
*directions_Ptr = UPPER_RIGHT;
}
if ((*i_Ptr) == 8) {
(*i_Ptr) = 0;
(*page_Ptr)--;
}
break;
case UPPER_RIGHT: //UPPER_RIGHT Direction
*column_Ptr = *column_Ptr + 1;
(*i_Ptr)++;
if (*column_Ptr == 127) {
*directions_Ptr = UPPER_LEFT;
}
if ((*i_Ptr) == 8) {
*i_Ptr = 0;
(*page_Ptr)--;
}
break;
}
sei();
}