-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
176 lines (147 loc) · 4.27 KB
/
main.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
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "snesc.h"
#include "graph.h"
#include "input.h"
extern unsigned char tiles1[];
extern unsigned char tiles2[];
extern unsigned char bg1map[];
extern unsigned char bg2map[];
extern unsigned char palette[];
extern unsigned char backpal[];
unsigned int blockmap[0x400];
//unsigned int backmap[0x400];
unsigned int pal[0x100];
//unsigned char blocks[0x64];
static const char* LINE_BLANK = " ";
typedef enum { false, true } boolean;
unsigned int posTextInit = 0x080;
void capture_inputs()
{
unsigned int posText = posTextInit;
int i;
for(i = 0; i < 4; i++) // super multitap not handled for now
{
boolean joypadHasInput = false;
if(getjoystatus(i) & LEFT_BUTTON)
{
writestring("LEFT", blockmap, posText + 0x003, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & RIGHT_BUTTON)
{
writestring("RIGHT", blockmap, posText + 0x008, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & UP_BUTTON)
{
writestring("UP", blockmap, posText + 0x00E, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & DOWN_BUTTON)
{
writestring("DOWN", blockmap, posText + 0x011, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & A_BUTTON)
{
writestring("A", blockmap, posText + 0x016, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & B_BUTTON)
{
writestring("B", blockmap, posText + 0x018, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & X_BUTTON)
{
writestring("X", blockmap, posText + 0x01A, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & Y_BUTTON)
{
writestring("Y", blockmap, posText + 0x01C, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & START_BUTTON)
{
writestring("START", blockmap, posText + 0x020 + 0x003, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & SELECT_BUTTON)
{
writestring("SELECT", blockmap, posText + 0x020 + 0x009, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & TL_BUTTON)
{
writestring("LB", blockmap, posText + 0x020 + 0x010, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if(getjoystatus(i) & TR_BUTTON)
{
writestring("RB", blockmap, posText + 0x020 + 0x013, 0x3F6);
setmap(0, (unsigned char*)blockmap);
joypadHasInput = true;
}
if (joypadHasInput)
{
// get joypad number and status
char num[1];
char status[8];
sprintf(num, "%i", i + 1);
writestring("P", blockmap, posText, 0x3F6);
writestring(num, blockmap, posText + 1, 0x3F6);
setmap(0, (unsigned char*)blockmap);
sprintf(status, "%X", getjoystatus(i));
writestring(status, blockmap, posText + 0x040 + 0x003, 0x3F6);
setmap(0, (unsigned char*)blockmap);
}
else
{
writestring(LINE_BLANK, blockmap, posText, 0x3F6);
writestring(LINE_BLANK, blockmap, posText + 0x020, 0x3F6);
writestring(LINE_BLANK, blockmap, posText + 0x040, 0x3F6);
setmap(0, (unsigned char*)blockmap);
}
clearjoy(i);
// display next joypad inputs
posText += 0x080;
}
}
void idle()
{
resettimer();
capture_inputs();
sync(1);
}
int main()
{
snesc_init();
settiles(0, tiles1, 0xF00);
memcpy(pal, palette, 0x200);
// header
writestring("*** JOYPAD TEST v0.2 ***", blockmap, 0x020 + 0x004, 0x3F6);
// footer
writestring("by Modrigue", blockmap, 0x300, 0x3F6);
writestring("Made with Optixx\'s SNES SDK,", blockmap, 0x320, 0x3F6);
writestring("forked by Ace17.", blockmap, 0x340, 0x3F6);
writestring("Visit github.com/Ace17/snes-sdk", blockmap, 0x360, 0x3F6);
setpalette((unsigned char*)pal);
enablescreen();
setmap(0, (unsigned char*)blockmap);
while(1)
idle();
}