-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
101 lines (83 loc) · 2.03 KB
/
Copy pathmain.c
File metadata and controls
101 lines (83 loc) · 2.03 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
// Built against SGDK 1.62
// public domain.
#include <genesis.h>
static u16 TH_CONTROL_PHASE(vu8 *pb)
{
u16 val;
*pb = 0x00; /* TH (select) low */
asm volatile ("nop");
asm volatile ("nop");
val = *pb;
*pb = 0x40; /* TH (select) high */
val <<= 8;
val |= *pb;
return val;
}
int main()
{
vu8 *pb;
u16 v[4];
char buf[20] = {0};
u8 i = 0, j = 0;
pb = (vu8 *)0xa10003;
while(1)
{
JOY_init();
pb = (vu8 *)0xa10003;
SYS_disableInts();
v[0] = TH_CONTROL_PHASE(pb);
v[1] = TH_CONTROL_PHASE(pb);
v[2] = TH_CONTROL_PHASE(pb);
v[3] = TH_CONTROL_PHASE(pb);
SYS_enableInts();
VDP_drawText("P1", 6, 8);
VDP_drawText("P2", 6, 14);
for(i = 0; i < 4; i++)
{
for (j = 0; j < 8; j++)
{
if (v[i] & (1<<(15-j)))
buf[j] = '1';
else
buf[j] = '0';
}
buf[8] = ' ';
for (j = 8; j < 16; j++)
{
if (v[i] & (1<<(15-j)))
buf[j+1] = '1';
else
buf[j+1] = '0';
}
VDP_drawText(buf, 10, 8+i);
}
pb = (vu8 *)0xa10005;
SYS_disableInts();
v[0] = TH_CONTROL_PHASE(pb);
v[1] = TH_CONTROL_PHASE(pb);
v[2] = TH_CONTROL_PHASE(pb);
v[3] = TH_CONTROL_PHASE(pb);
SYS_enableInts();
for(i = 0; i < 4; i++)
{
for (j = 0; j < 8; j++)
{
if (v[i] & (1<<(15-j)))
buf[j] = '1';
else
buf[j] = '0';
}
buf[8] = ' ';
for (j = 8; j < 16; j++)
{
if (v[i] & (1<<(15-j)))
buf[j+1] = '1';
else
buf[j+1] = '0';
}
VDP_drawText(buf, 10, 14+i);
}
SYS_doVBlankProcess();
}
return (0);
}