-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiiClassiController.c
165 lines (123 loc) · 3.23 KB
/
WiiClassiController.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
#include "Antares.h" //RJA implementing this gd2-lib code using Matrix Orbital's EVE driver
#include "kenney_assets.h"
i2c_Port* pI2C1;
uint8_t WiiRegs[6];
int tilex = 10;
int tiley = 10;
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
Begin(BITMAPS);
RestoreContext();
TranslateXY(300, 400);//rja
BlendFunc(ONE, ONE_MINUS_SRC_ALPHA);
Begin(BITMAPS);
BitmapHandle(TILES_HANDLE);
uint8_t* src = layer1_map +(y >> 5) * 15;
byte yo = y & 31;
for (byte j = 0; j < 10; j++)
for (byte i = 0; i < 15; i++) {
byte t = (byte)*(src++);
if (t != 0) {
Cell(t - 1);
Vertex2f(16 * 32 * i, 16 * ((32 * j) - yo));
}
}
//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();
// 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(100);
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();
}
}