-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameOnDesigner - Copy (2).c
237 lines (187 loc) · 9.95 KB
/
GameOnDesigner - Copy (2).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
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
#include "Antares.h" //RJA implementing this gd2-lib code using Matrix Orbital's EVE driver
//I2C Bus Pins and Settings
#define I2C1_SCLPIN (basepin+9) //P2 pin used for SCL
#define I2C1_SDAPIN (basepin+8) //P2 pin used for SDA
#define I2C1_SPEED 100 //100 kHz
#define I2C1_PULLUP PU_15K
#include "i2c.h" //I2C driver for P2
#include "KenneyAssets.h" //Note: The .ant file referenced here must be in 8.3 filename format and reside on uSD card
i2c_Port* pI2C1;
uint8_t WiiRegs[6];
int tilex = 10;
int tiley = 10;
int8_t layer1_map[] = {
-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, -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, -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, -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, -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, -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, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, -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, -1, -1,
60, 60, 60, 79, 79, 60, 60, 60, 60, 60, 60, 60, 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, 57, 57, -1, -1, -1,
-1, -1, -1, 78, 78, -1, -1, -1, -1, -1, -1, -1, 80, 73, -1, -1, -1, -1, -1, -1, -1, -1, 56, 56, -1, -1, -1,
-1, -1, -1, 78, 78, -1, -1, -1, -1, -1, -1, -1, -1, 62, 80, -1, -1, -1, -1, 67, 67, -1, 56, 56, -1, -1, -1,
57, 57, -1, 78, 78, -1, -1, -1, -1, -1, -1, -1, -1, -1, 80, 73, -1, 114, 116, -1, -1, -1, 56, 56, -1, -1, -1,
56, 56, -1, 78, 78, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60, 60, 60, 80, 80, 80, 61, 61, -1, -1, -1,
56, 56, -1, 78, 78, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
56, 56, -1, 78, 78, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
20, 20, 20, 20, 20, 20, 84, 84, 84, 84, 84, 20, 20, 20, 20, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 20, 20, 20, 20, 20, 20, 20, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, -1, -1, -1, -1, -1, -1, -1, -1, -1,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, 82, 81, 82, 81, 82, 81, 82, 81,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80
};
//27x24 map
uint8_t layer2_map[] = { 61, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 79, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 78, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 78, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 78, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 16, 16, 16, 78, 16, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 16, 16, 16, 255, 255, 255, 255, 255, 20,
61, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20, 81, 81, 81, 81, 82, 20, 255, 255, 255, 20,
61, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20, 80, 80, 80, 80, 80, 20, 255, 255, 255, 20,
61, 0, 0, 0, 0, 255, 255, 255, 255, 255, 13, 255, 255, 255, 255, 255, 20, 20, 20, 20, 20, 20, 20, 255, 255, 255, 20,
61, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 15, 15, 15, 15, 255, 255, 79, 255, 255, 255, 89, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 11, 255, 255, 255, 78, 99, 95, 95, 95, 101, 255, 255, 14, 14, 14, 14, 1, 10, 1, 1, 255, 255, 20,
61, 255, 255, 255, 255, 255, 255, 255, 78, 255, 255, 255, 92, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 255, 79, 255, 78, 255, 255, 255, 94, 255, 255, 255, 255, 255, 255, 255, 17, 17, 17, 17, 255, 255, 20,
61, 255, 255, 255, 63, 60, 78, 60, 65, 255, 255, 255, 94, 255, 255, 21, 18, 18, 18, 23, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 255, 78, 255, 255, 255, 255, 255, 94, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 255, 255, 255, 78, 255, 255, 255, 255, 255, 94, 255, 55, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20,
61, 255, 255, 116, 255, 255, 78, 255, 255, 255, 255, 255, 94, 255, 54, 255, 255, 20, 20, 84, 84, 84, 84, 84, 20, 20, 20,
61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61 };
static void draw(int t)
{
int y = 1648 - t;
y = 1648;// stop tiles from moving
// finish(); long t0 = micros();
// ClearColorRGB(0xd0f4f7); Clear();
cmd_gradient(0, 0, 0xa0a4f7,
0, 272*2, 0xd0f4f7);
TranslateXY(0, 0);//rja
RestoreContext();
FormatVertex(VERTEX_FORMAT_ONE);
TranslateXY(20, -250);//rja
//BlendFunc(ONE, SRC_ALPHA);
//BlendFunc(ZERO, SRC_ALPHA);
Begin(BITMAPS);
//BitmapHandle(TILES_HANDLE);
BitmapHandle(Tiles_HANDLE);
//uint8_t* src = layer1_map +(y >> 5) * 15;
byte yo = y & 31;
for (byte j = 0; j < 24; j++)
for (byte i = 0; i < 27; i++) {
int8_t t = layer1_map[j * 27 + i];
if (t >0) {
Cell(t);// _rnd() % 117);// (t - 1);
Vertex2f(40 * i, ((40 * j)));
}
}
//draw box
TranslateXY(0, 0);//rja
Cmd_Color_RGB(0xffcc00);
Begin(LINES);
Vertex2f(tilex * 32*16, tiley * 32* 16);
Vertex2f(tilex * 32 * 16 , tiley * 32 * 16 + 32 * 16);
Vertex2f(tilex * 32 * 16, tiley * 32 * 16);
Vertex2f(tilex * 32 * 16 + 32 * 16, tiley * 32 * 16) ;
Vertex2f(tilex * 32 * 16 + 32 * 16, tiley * 32 * 16 + 32 * 16);
Vertex2f(tilex * 32 * 16 , tiley * 32 * 16 + 32 * 16);
Vertex2f(tilex * 32 * 16 + 32 * 16, tiley * 32 * 16 + 32 * 16);
Vertex2f(tilex * 32 * 16 + 32 * 16, tiley * 32 * 16 );
swap();
}
void setup()
{
begin();
Clear();
//LOAD_ASSETS();
printf("Loading Assets, please wait...\n");
LOAD_ASSETS(); //This loads an assets file into RAM_G
//ASTC_5x5 looks OK at 720p. 10x10 and 10x5 had errors.
Cmd_SetBitmap(0, COMPRESSED_RGBA_ASTC_5x5_KHR, 40, 40); //Don't need this for some formats because works automagically when just one bitmap handle in use...
printf("Assets loaded.\n");
// Handle Graphic
// 0 Tiles
byte hy[] = {36, 12, 144, 204, 216, 120, 48, 168, 192, 84, 72, 60, 24, 180, 0, 108, 228, 132, 156, 96};
i2c_Setup(pI2C1, I2C1_SCLPIN, I2C1_SDAPIN, I2C1_SPEED, I2C1_PULLUP); //setup(i2c_Port*, scl, sda, khz, pullup)
//Scan the I2C Bus I2CBus1
ScanI2CBus(pI2C1); //Wii classic controller shouls show up at A4
//Magic to get Wii classic controller talking
WiiRegs[0] = 0x55;
i2c_WriteRegisters(pI2C1, 0xA4,0xF0,1, WiiRegs);// (i2c_Port * pi2c, uint8_t add, int reg, int n, uint8_t * pBuff)
WiiRegs[0] = 0x00;
i2c_WriteRegisters(pI2C1, 0xA4, 0xFB, 1, WiiRegs);// (i2c_Port * pi2c, uint8_t add, int reg, int n, uint8_t * pBuff)
printf("I2C Driver started.\n");
}
void loop()
{
draw(0);
_waitms(5000);
i2c_ReadRegisters(pI2C1, 0xA4, 0, 6, WiiRegs);
//Combine button data into one word
uint16_t b = (1 << 15) | (WiiRegs[5] << 7) | (WiiRegs[4] >> 1);
b = ~b;
//Digital controller bits :
//0 : R fully pressed
// 1 : Start
// 2 : Home
// 3 : Select
// 4 : L fully pressed
// 5 : Down
// 6 : Right
// 7 : Up
// 8 : Left
// 9 : ZR
// 10 : x
// 11 : a
// 12 : y
// 13 : b
// 14 : ZL
bool bPushed = false;
if (b & (1 << 5))
{
printf("Down ");
tiley += 1;
bPushed = true;
}
if (b & (1 << 7))
{
printf("Up ");
tiley -= 1;
bPushed = true;
}
if (b & (1 << 8))
{
printf("Left ");
tilex -= 1;
bPushed = true;
}
if (b & (1 << 6))
{
printf("Right");
tilex += 1;
bPushed = true;
}
if (b!=0)
printf(" Buttons=%d\n",b);
}
void main()
{//RJA added this main function to act like Arduino
setup();
for (;;)
{
loop();
}
}