1 /*---------------------------------------------------------------------------*
2 Project: Basic pad demo
3 File: basic.c
4
5 Copyright (C) 1998-2006 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: basic.c,v $
14 Revision 1.1 02/02/2006 06:11:49 yasuh-to
15 Initial import
16
17
18 9 03/04/16 21:15 Hashida
19 Added a caution for controller hot-swap.
20
21 8 8/20/02 21:58:00 Shiki
22 Added a call to PADClampCircle().
23
24 7 5/21/01 10:53a Shiki
25 Removed analog A/B outputs.
26
27 6 01/04/11 12:46:00 Shiki
28 Revised using escape sequences for smoother screen update.
29
30 5 01/04/11 11:36:00 Shiki
31 Fixed report message.
32
33 4 01/03/27 13:19 Shiki
34 Bug fix.
35
36 3 01/03/23 15:01 Shiki
37 Fixed resetBits handling code.
38
39 2 01/03/22 21:09:00 Shiki
40 Revised.
41
42 1 3/01/00 11:48p Shiki
43 Initial check-in.
44 $NoKeywords: $
45 *---------------------------------------------------------------------------*/
46
47 #include <string.h>
48 #include <revolution.h>
49
50 /*
51 * NOTES:
52 * This program supports controller hot-swap only for the controller
53 * ports where a controller was connected to when booted.
54 * As for how to support hot-swap for all the controller ports,
55 * see libraries/demo/src/DEMOPad.c.
56 */
57
58 PADStatus Pads[PAD_MAX_CONTROLLERS];
59
PrintPads(void)60 static void PrintPads(void)
61 {
62 int chan;
63
64 OSReport("Port AB XY S ZLR +Pad Left Right Trigger\n");
65 // 1[-2] AB XY S ZLR <>^v (1234, 1234) (1234, 1234) (123, 123)
66 for (chan = 0; chan < PAD_MAX_CONTROLLERS; ++chan)
67 {
68 OSReport("%d[%-2d] %c%c %c%c %c %c%c%c %c%c%c%c (%4d, %4d) (%4d, %4d) (%3d, %3d)\n",
69 chan,
70 Pads[chan].err,
71 (Pads[chan].button & PAD_BUTTON_A) ? 'O' : '_',
72 (Pads[chan].button & PAD_BUTTON_B) ? 'O' : '_',
73 (Pads[chan].button & PAD_BUTTON_X) ? 'O' : '_',
74 (Pads[chan].button & PAD_BUTTON_Y) ? 'O' : '_',
75 (Pads[chan].button & PAD_BUTTON_START) ? 'O' : '_',
76 (Pads[chan].button & PAD_TRIGGER_Z) ? 'O' : '_',
77 (Pads[chan].button & PAD_TRIGGER_L) ? 'O' : '_',
78 (Pads[chan].button & PAD_TRIGGER_R) ? 'O' : '_',
79
80 (Pads[chan].button & PAD_BUTTON_LEFT) ? '<' : '_',
81 (Pads[chan].button & PAD_BUTTON_RIGHT) ? '>' : '_',
82 (Pads[chan].button & PAD_BUTTON_UP) ? '^' : '_',
83 (Pads[chan].button & PAD_BUTTON_DOWN) ? 'v' : '_',
84
85 Pads[chan].stickX,
86 Pads[chan].stickY,
87 Pads[chan].substickX,
88 Pads[chan].substickY,
89 Pads[chan].triggerLeft,
90 Pads[chan].triggerRight);
91 }
92 }
93
main(void)94 void main(void)
95 {
96 u32 padBit;
97 u32 resetBits;
98 u32 connectedBits;
99 int chan;
100
101 VIInit();
102 PADInit();
103 OSReport("\033c"); // Resets the terminal
104
105 connectedBits = 0x0;
106
107 for (;;)
108 {
109 PADRead(Pads);
110
111 resetBits = 0x0;
112 for (chan = 0; chan < PAD_MAX_CONTROLLERS; ++chan)
113 {
114 padBit = PAD_CHAN0_BIT >> chan;
115 switch (Pads[chan].err)
116 {
117 case PAD_ERR_NONE:
118 case PAD_ERR_TRANSFER:
119 connectedBits |= padBit;
120 break;
121 case PAD_ERR_NO_CONTROLLER:
122 resetBits |= padBit;
123 break;
124 case PAD_ERR_NOT_READY:
125 default:
126 break;
127 }
128 }
129 if (connectedBits)
130 {
131 resetBits &= connectedBits;
132 }
133 if (resetBits)
134 {
135 PADReset(resetBits);
136 }
137
138 OSReport("\033[H"); // Home
139 if (connectedBits)
140 {
141 PADStatus org[PAD_MAX_CONTROLLERS];
142
143 OSReport("Attached Controllers: 0x%1x.\n", connectedBits);
144 PrintPads();
145
146 memcpy(org, Pads, sizeof org);
147 PADClamp(Pads);
148 OSReport("\nClamped\n");
149 PrintPads();
150
151 memcpy(Pads, org, sizeof org);
152 PADClampCircle(Pads);
153 OSReport("\nClamped (circle)\n");
154 PrintPads();
155 }
156 else
157 {
158 OSReport("Please connect controllers\n");
159 }
160
161 VIWaitForRetrace();
162 }
163 }
164