|
@@ -15,121 +15,204 @@ static const char* LOG_TAG = "Main";
|
15
|
15
|
static uint16_t gFramebuffer[LCD_WIDTH * LCD_HEIGHT];
|
16
|
16
|
|
17
|
17
|
|
18
|
|
-void app_main(void)
|
|
18
|
+static const uint16_t palette[4] =
|
19
|
19
|
{
|
20
|
|
- Odroid_InitializeInput();
|
21
|
|
- Odroid_InitializeDisplay();
|
22
|
|
- Odroid_InitializeSdcard();
|
23
|
|
- Odroid_InitializeBatteryReader();
|
24
|
|
- Odroid_InitializeAudio();
|
|
20
|
+ 0xFFFF,
|
|
21
|
+ 0x55AD,
|
|
22
|
+ 0xAA52,
|
|
23
|
+ 0x0000,
|
|
24
|
+};
|
25
|
25
|
|
26
|
|
- // Load sprite
|
27
|
|
- uint16_t* sprite = (uint16_t*)malloc(64 * 64 * sizeof(uint16_t));
|
|
26
|
+static const uint8_t tiles[][16*16] =
|
|
27
|
+{
|
|
28
|
+ // White
|
28
|
29
|
{
|
29
|
|
- FILE* spriteFile = fopen("/sdcard/key", "r");
|
30
|
|
- assert(spriteFile);
|
31
|
|
-
|
32
|
|
- for (int i = 0; i < 64; ++i)
|
33
|
|
- {
|
34
|
|
- for (int j = 0; j < 64; ++j)
|
35
|
|
- {
|
36
|
|
- fread(sprite, sizeof(uint16_t), 64 * 64, spriteFile);
|
37
|
|
- }
|
38
|
|
- }
|
39
|
|
-
|
40
|
|
- fclose(spriteFile);
|
41
|
|
- }
|
42
|
|
-
|
43
|
|
- // Load sound effect
|
44
|
|
- uint16_t* soundBuffer;
|
45
|
|
- int soundEffectLength = 1441;
|
|
30
|
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
31
|
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
32
|
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
33
|
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
34
|
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,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, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0},
|
|
121
|
+ {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
|
122
|
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
|
123
|
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
|
124
|
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
|
125
|
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
|
126
|
+};
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+void DrawTile(int index, int x, int y)
|
|
130
|
+{
|
|
131
|
+ int startX = x * 16;
|
|
132
|
+ int startY = y * 16;
|
49
|
133
|
|
50
|
|
- uint8_t* soundEffect = malloc(soundEffectLength);
|
51
|
|
- assert(soundEffect);
|
|
134
|
+ for (int row = 0; row < 16; ++row)
|
|
135
|
+ {
|
|
136
|
+ for (int col = 0; col < 16; ++col)
|
|
137
|
+ {
|
|
138
|
+ uint8_t paletteIndex = tiles[index][row * 16 + col];
|
52
|
139
|
|
53
|
|
- soundBuffer = malloc(soundEffectLength*2);
|
54
|
|
- assert(soundBuffer);
|
|
140
|
+ int screenY = startY + row;
|
|
141
|
+ int screenX = startX + col;
|
55
|
142
|
|
56
|
|
- fread(soundEffect, soundEffectLength, 1, soundFile);
|
|
143
|
+ uint16_t color = palette[paletteIndex];
|
57
|
144
|
|
58
|
|
- for (int i = 0; i < soundEffectLength; ++i)
|
59
|
|
- {
|
60
|
|
- // 16 bits required but only MSB is actually sent to the DAC
|
61
|
|
- soundBuffer[i] = (soundEffect[i] << 8u);
|
|
145
|
+ gFramebuffer[screenY * LCD_WIDTH + screenX] = color;
|
62
|
146
|
}
|
63
|
147
|
}
|
|
148
|
+}
|
64
|
149
|
|
65
|
150
|
|
66
|
|
- ESP_LOGI(LOG_TAG, "Odroid initialization complete - entering main loop");
|
|
151
|
+void app_main(void)
|
|
152
|
+{
|
|
153
|
+ Odroid_InitializeInput();
|
|
154
|
+ Odroid_InitializeDisplay();
|
|
155
|
+ Odroid_InitializeSdcard();
|
|
156
|
+ Odroid_InitializeBatteryReader();
|
|
157
|
+ Odroid_InitializeAudio();
|
67
|
158
|
|
68
|
|
- int x = 0;
|
69
|
|
- int y = 0;
|
|
159
|
+ ESP_LOGI(LOG_TAG, "Odroid initialization complete - entering main loop");
|
70
|
160
|
|
71
|
|
- uint16_t color = 0xffff;
|
72
|
161
|
|
73
|
|
- int lastState = 0;
|
|
162
|
+ uint8_t frameIndex = 0;
|
|
163
|
+ char snapFilename[20];
|
|
164
|
+ int xLeft = 0;
|
74
|
165
|
|
75
|
166
|
for (;;)
|
76
|
167
|
{
|
77
|
|
- memset(gFramebuffer, 0, 320 * 240 * 2);
|
|
168
|
+ memset(gFramebuffer, 0xff, 320*240*2);
|
78
|
169
|
|
79
|
170
|
Odroid_Input input = Odroid_PollInput();
|
80
|
171
|
|
81
|
|
- if (input.left) { x -= 20; }
|
82
|
|
- else if (input.right) { x += 20; }
|
83
|
|
-
|
84
|
|
- if (input.up) { y -= 20; }
|
85
|
|
- else if (input.down) { y += 20; }
|
86
|
|
-
|
87
|
|
- if (input.a) { color = SWAP_ENDIAN_16(RGB565(0xff, 0, 0)); }
|
88
|
|
- else if (input.b) { color = SWAP_ENDIAN_16(RGB565(0, 0xff, 0)); }
|
89
|
|
- else if (input.start) { color = SWAP_ENDIAN_16(RGB565(0, 0, 0xff)); }
|
90
|
|
- else if (input.select) { color = SWAP_ENDIAN_16(RGB565(0xff, 0xff, 0xff)); }
|
91
|
|
-
|
92
|
|
-
|
93
|
|
- int thisState = input.volume;
|
94
|
|
-
|
95
|
|
- if ((thisState == 1) && (thisState != lastState))
|
|
172
|
+ if (input.left)
|
96
|
173
|
{
|
97
|
|
- Odroid_PlayAudio(soundBuffer, soundEffectLength*2);
|
98
|
|
- }
|
99
|
|
-
|
100
|
|
- lastState = thisState;
|
|
174
|
+ xLeft -= 1;
|
101
|
175
|
|
|
176
|
+ if (xLeft < 0)
|
|
177
|
+ {
|
|
178
|
+ xLeft = 39;
|
|
179
|
+ }
|
|
180
|
+ }
|
102
|
181
|
|
103
|
|
- DrawText(gFramebuffer, "The Quick Brown Fox", 19, 0, 5, SWAP_ENDIAN_16(RGB565(0xFF, 0, 0)));
|
104
|
|
- DrawText(gFramebuffer, "Jumped Over The:", 16, 0, 6, SWAP_ENDIAN_16(RGB565(0, 0xFF, 0)));
|
105
|
|
- DrawText(gFramebuffer, "Lazy Dog?!", 10, 0, 7, SWAP_ENDIAN_16(RGB565(0, 0, 0xFF)));
|
106
|
|
-
|
|
182
|
+ else if (input.right)
|
|
183
|
+ {
|
|
184
|
+ xLeft += 1;
|
107
|
185
|
|
108
|
|
- int spriteRow = 0;
|
109
|
|
- int spriteCol = 0;
|
|
186
|
+ if (xLeft > 39)
|
|
187
|
+ {
|
|
188
|
+ xLeft = 0;
|
|
189
|
+ }
|
|
190
|
+ }
|
110
|
191
|
|
111
|
|
- for (int row = y; row < y + 64; ++row)
|
|
192
|
+ for (int tileY = 0; tileY < 15; ++tileY)
|
112
|
193
|
{
|
113
|
|
- spriteCol = 0;
|
114
|
|
-
|
115
|
|
- for (int col = x; col < x + 64; ++col)
|
|
194
|
+ for (int tileX = xLeft; tileX < xLeft + 20; ++tileX)
|
116
|
195
|
{
|
117
|
|
- uint16_t pixelColor = sprite[64 * spriteRow + spriteCol];
|
|
196
|
+ int tile = tileX % 40;
|
118
|
197
|
|
119
|
|
- if (pixelColor != 0)
|
120
|
|
- {
|
121
|
|
- gFramebuffer[row * LCD_WIDTH + col] = color;
|
122
|
|
- }
|
|
198
|
+ int tileIndex = tileBuffer[tileY][tile];
|
123
|
199
|
|
124
|
|
- ++spriteCol;
|
|
200
|
+ DrawTile(tileIndex, tileX - xLeft, tileY);
|
125
|
201
|
}
|
126
|
|
-
|
127
|
|
- ++spriteRow;
|
128
|
202
|
}
|
129
|
203
|
|
|
204
|
+
|
|
205
|
+ char string[5];
|
|
206
|
+ snprintf(string, 5, "%02d", xLeft);
|
|
207
|
+ DrawText(gFramebuffer, string, 2, 0, 0, palette[3]);
|
|
208
|
+
|
|
209
|
+ int tileRight = (xLeft + 20) % 40;
|
|
210
|
+ snprintf(string, 5, "%02d", tileRight);
|
|
211
|
+ DrawText(gFramebuffer, string, 2, 18, 0, palette[3]);
|
|
212
|
+
|
130
|
213
|
if (input.menu)
|
131
|
214
|
{
|
132
|
|
- const char* snapFilename = "/sdcard/framebuf";
|
|
215
|
+ snprintf(snapFilename, 20, "/sdcard/frame%02d", frameIndex);
|
133
|
216
|
|
134
|
217
|
ESP_LOGI(LOG_TAG, "Writing snapshot to %s", snapFilename);
|
135
|
218
|
|
|
@@ -139,19 +222,8 @@ void app_main(void)
|
139
|
222
|
fwrite(gFramebuffer, 1, LCD_WIDTH * LCD_HEIGHT * sizeof(gFramebuffer[0]), snapFile);
|
140
|
223
|
|
141
|
224
|
fclose(snapFile);
|
142
|
|
- }
|
143
|
|
-
|
144
|
|
-
|
145
|
|
- uint32_t batteryLevel = Odroid_ReadBatteryLevel();
|
146
|
|
- ESP_LOGI(LOG_TAG, "Battery level: %u\n", batteryLevel);
|
147
|
225
|
|
148
|
|
- if (batteryLevel < 3600)
|
149
|
|
- {
|
150
|
|
- Odroid_EnableBatteryLight();
|
151
|
|
- }
|
152
|
|
- else
|
153
|
|
- {
|
154
|
|
- Odroid_DisableBatteryLight();
|
|
226
|
+ ++frameIndex;
|
155
|
227
|
}
|
156
|
228
|
|
157
|
229
|
|