1 /*---------------------------------------------------------------------------*
2 Project: WPAD demo program
3 File: dummy_checker.c
4
5 Copyright (C) 2007 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: dummy_checker.c,v $
14 Revision 1.5.2.1 2007/12/11 01:14:55 tojo
15 Modified to handle the error code of WPADStatus.
16
17 Revision 1.5 2007/07/11 12:47:49 tojo
18 (none)
19
20 Revision 1.4 2007/07/10 12:14:46 tojo
21 (none)
22
23 Revision 1.3 2007/05/02 07:52:23 tojo
24 (none)
25
26 Revision 1.2 2007/04/23 08:16:09 tojo
27 (none)
28
29 Revision 1.1 2007/04/18 01:30:48 tojo
30 Initial check-in.
31
32
33 *---------------------------------------------------------------------------*/
34
35 #include <stdlib.h>
36 #include <string.h>
37 #include <stddef.h>
38 #include <stdarg.h>
39 #include <stdio.h>
40 #include <ctype.h>
41
42 #include <revolution.h>
43 #include <revolution/wpad.h>
44
45 #define DEMO_USE_MEMLIB=1 // This turns on the DEMO library's MEM heaps.
46 #include <demo.h>
47
48 /*---------------------------------------------------------------------------*
49 * Local Definitions
50 *---------------------------------------------------------------------------*/
51
52 #define SCREEN_WIDTH 320
53 #define SCREEN_HEIGHT 240
54 #define FONT_HEIGHT 8
55
56 /*---------------------------------------------------------------------------*
57 * Local Data
58 *---------------------------------------------------------------------------*/
59
60
61 #define SMPBUF_SIZE 100
62
63 static WPADCLStatus cl_ringbuffer[SMPBUF_SIZE];
64 static WPADFSStatus fs_ringbuffer[SMPBUF_SIZE];
65 static WPADStatus co_ringbuffer[SMPBUF_SIZE];
66
67
68 /*---------------------------------------------------------------------------*
69 * Function prototypes
70 *---------------------------------------------------------------------------*/
71
72
73 // MEM2 memory allocation routines. The application must provide these to
74 // WPAD, so it can setup the data transfer buffer. This buffer must reside
75 // in MEM2.
76 static void *myAlloc ( u32 size );
77 static u8 myFree ( void *ptr );
78
79 // callbacks
80 void connectCallback ( s32 chan, s32 reason );
81 void extensionCallback ( s32 chan, s32 result );
82 void samplingCallback ( s32 chan );
83
84 // internal functions
85 static void initialize ( void );
86 static void renderStatus ( void );
87 static void renderAimings ( void );
88 static void printIntro ( void );
89 static void printBuffer ( char *string, ... );
90 static u8 *get_dev_name ( u32 type );
91 static u8 *get_status_name ( s32 status );
92
93
94
95 /*===========================================================================*
96 * F U N C T I O N D E F I N I T I O N S
97 *===========================================================================*/
98 /*---------------------------------------------------------------------------*
99 * Name : printIntro()
100 * Description :
101 * Arguments : None.
102 * Returns : None.
103 *---------------------------------------------------------------------------*/
printIntro(void)104 static void printIntro( void )
105 {
106 #ifdef _DEBUG
107 OSReport("-------------------------------------------------------\n");
108 OSReport(" Dummy Extension Demo: \n");
109 OSReport(" Button A: Attach the future device. \n");
110 OSReport(" Button X: Attach the unsupported device. \n");
111 OSReport(" Button B: Detach the device. \n");
112 OSReport("-------------------------------------------------------\n");
113 #else
114 OSReport("-------------------------------------------------------\n");
115 OSReport(" \n");
116 OSReport(" Dummy Extension cannot be used in release build!!! \n");
117 OSReport(" \n");
118 OSReport("-------------------------------------------------------\n");
119 #endif
120 }
121
122 static u8 buffer[WPAD_MEM_GAMEDATA_LEN];
123
124 /*---------------------------------------------------------------------------*
125 * Name : main()
126 * Description :
127 * Arguments : None.
128 * Returns : None.
129 *---------------------------------------------------------------------------*/
main(void)130 int main( void )
131 {
132
133 int i;
134
135 initialize();
136
137 // - We must now register memory allocation/free functions
138 // for MEM2.
139 // - WPAD requires some memory in MEM2 for data transfers
140 // between the controller and WPAD driver stack.
141 // - Memory allocation only occurs once, at the initialization.
142 // - Memory usage is on the order of 1KB.
143 // - NOTE: We are using the MEM library allocators defined by
144 // the DEMO library.
145 //
146 WPADRegisterAllocator(myAlloc, myFree);
147
148 // Initialize WPAD!
149 WPADInit();
150
151 for (i=0; i<WPAD_MAX_CONTROLLERS; i++)
152 {
153 // Register a callback for each channel, for
154 // connect and disconnect events.
155 WPADSetConnectCallback(i, connectCallback);
156 }
157
158 // The WPAD initialization process is asynchronous.
159 // So we should wait until it's completed.
160 while(WPADGetStatus() != WPAD_STATE_SETUP)
161 {
162 ;
163 }
164
165 printIntro();
166
167 while(1)
168 {
169 #ifdef _DEBUG
170 DEMOPadRead();
171
172 if (DEMOPadGetButtonDown(0) & PAD_BUTTON_A)
173 {
174 if (WPADAttachDummyExtension( WPAD_CHAN0, WPAD_DEV_FUTURE ))
175 {
176 OSReport(" Attach dummy extension [WPAD_DEV_FUTURE]\n");
177 }
178 else
179 {
180 OSReport(" Something is already attached\n");
181 }
182 }
183 if (DEMOPadGetButtonDown(0) & PAD_BUTTON_X)
184 {
185 if (WPADAttachDummyExtension( WPAD_CHAN0, WPAD_DEV_NOT_SUPPORTED ))
186 {
187 OSReport(" Attach dummy extension [WPAD_DEV_NOT_SUPPORTED]\n");
188 }
189 else
190 {
191 OSReport(" Something is already attached\n");
192 }
193 }
194 if (DEMOPadGetButtonDown(0) & PAD_BUTTON_B)
195 {
196 if (WPADDetachDummyExtension( WPAD_CHAN0 ))
197 {
198 OSReport(" Detach dummy extension\n");
199 }
200 else
201 {
202 OSReport(" Nothing is attached\n");
203 }
204 }
205 #endif // _DEBUG
206
207 DEMOBeforeRender();
208 renderStatus();
209 renderAimings();
210 DEMODoneRender();
211 }
212
213 } // end main()
214
215 /*---------------------------------------------------------------------------*
216 * Name : connectCallback()
217 *
218 * Description : This callback is invoked when a controller is connected or
219 * disconnected.
220 *
221 * Arguments : The channel (chan) for which the event has occurred.
222 * The channel status (reason):
223 * WPAD_ERR_NONE means a controller has been connected.
224 * WPAD_ERR_NO_CONTROLLER means a controller disconnected.
225 *
226 * Returns : None.
227 *---------------------------------------------------------------------------*/
connectCallback(s32 chan,s32 reason)228 void connectCallback( s32 chan, s32 reason )
229 {
230 switch(reason)
231 {
232 case WPAD_ERR_NONE:
233 // Accept a connection to be asigned to CHAN0.
234 if (chan != WPAD_CHAN0)
235 {
236 WPADDisconnect(chan);
237 break;
238 }
239
240 // If we want to support dynamic attachment/detachment of an
241 // extension, we must register an extension callback.
242 WPADSetExtensionCallback(chan, extensionCallback);
243
244 // If we want to use the sampling callback, we need to register
245 // the callback when a device is connected.
246 WPADSetSamplingCallback(chan, samplingCallback);
247
248 // Turn on dpd and acc.
249 WPADControlDpd(chan, WPAD_DPD_EXP, NULL);
250 WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD);
251
252 // Note we must reset the auto-sampling buffer so that WPAD
253 // will write into the appropriate buffer
254 WPADSetAutoSamplingBuf(chan, (void *)(&co_ringbuffer[0]), SMPBUF_SIZE);
255
256 break;
257
258 case WPAD_ERR_NO_CONTROLLER:
259 // We don't have to do anything.
260 // Note that all callbacks and the autosampling buffer will be
261 // cleared on disconnect events.
262 //
263 // Of course, the connect callback will still be valid for this channel.
264
265 break;
266
267 default:
268 // unexpected result!
269 break;
270
271 } // end switch
272
273 } // end connectCallback()
274
275 /*---------------------------------------------------------------------------*
276 * Name : extensionCallback()
277 *
278 * Description : This callback is invoked when an Extension has been attached.
279 *
280 * Arguments : The channel (chan) for which the extension event occurred.
281 * The device type (result):
282 *
283 * WPAD_DEV_UNKNOWN means that something has been attached, but
284 * it's being initialized, and we won't know what it is until
285 * initialization is complete.
286 *
287 * WPAD_DEV_CORE means that an extension has been removed and
288 * we're back to just the core device.
289 *
290 * WPAD_DEV_FREESTYLE means that the "NUNCHAK" extension has
291 * been attached and initialized.
292 *
293 * WPAD_DEV_CLASSIC means that the "CLASSIC" extension has been
294 * attached and initialized.
295 *
296 * Returns : None.
297 *---------------------------------------------------------------------------*/
extensionCallback(s32 chan,s32 result)298 void extensionCallback( s32 chan, s32 result )
299 {
300 switch(result)
301 {
302 case WPAD_DEV_UNKNOWN:
303 // in this case, the extension has been attached by the user
304 // but we don't know what type it is yet. Initialization of
305 // the attachment may take a few seconds, during which time
306 // button presses, the DPD, and accelerometers will be affected.
307 // This event is provided so applications can notify the
308 // user of the interruption and/or pause the game.
309 break;
310
311 case WPAD_DEV_CORE:
312 // In this case, the user has disconnected an extension.
313 // So, the device type will revert to "core only".
314 WPADControlDpd(chan, WPAD_DPD_EXP, NULL);
315 WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD);
316
317 // Note we must reset the auto-sampling buffer so that WPAD
318 // will write into the appropriate buffer
319 WPADSetAutoSamplingBuf(chan, (void *)(&co_ringbuffer[0]), SMPBUF_SIZE);
320 break;
321
322 case WPAD_DEV_FREESTYLE:
323 // Now that we know the extension type, we must revise
324 // the data format and control the DPD accordingly.
325 WPADControlDpd(chan, WPAD_DPD_STD, NULL);
326 WPADSetDataFormat(chan, WPAD_FMT_FREESTYLE_ACC_DPD);
327
328 // Note we must reset the auto-sampling buffer so that WPAD
329 // will write into the appropriate buffer
330 WPADSetAutoSamplingBuf(chan, (void *)(&fs_ringbuffer[0]), SMPBUF_SIZE);
331 break;
332
333 case WPAD_DEV_CLASSIC:
334
335 // Now that we know the extension type, we must revise
336 // the data format and control the DPD accordingly.
337 WPADControlDpd(chan, WPAD_DPD_STD, NULL);
338 WPADSetDataFormat(chan, WPAD_FMT_CLASSIC_ACC_DPD);
339
340 // Note we must reset the auto-sampling buffer so that WPAD
341 // will write into the appropriate buffer
342 WPADSetAutoSamplingBuf(chan, (void *)(&cl_ringbuffer[0]), SMPBUF_SIZE);
343 break;
344
345 case WPAD_DEV_FUTURE:
346 // Now that we don't know the extension type, we should ignore the extension and
347 // we must revise the data format and control the DPD accordingly.
348 WPADControlDpd(chan, WPAD_DPD_EXP, NULL);
349 WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD);
350
351 // Note we must reset the auto-sampling buffer so that WPAD
352 // will write into the appropriate buffer
353 WPADSetAutoSamplingBuf(chan, (void *)(&co_ringbuffer[0]), SMPBUF_SIZE);
354 break;
355
356 case WPAD_DEV_NOT_SUPPORTED:
357 // The user plugged in something weird.
358 // The safe thing to do is revert to Core-only operation.
359 WPADControlDpd(chan, WPAD_DPD_EXP, NULL);
360 WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD);
361
362 // Note we must reset the auto-sampling buffer so that WPAD
363 // will write into the appropriate buffer
364 WPADSetAutoSamplingBuf(chan, (void *)(&co_ringbuffer[0]), SMPBUF_SIZE);
365 break;
366
367 default:
368 // Here is WPAD_DEV_NOT_FOUND.
369 // If the controller is disconnected while the extension is initializing
370 // it reaches here. There is nothing to do.
371 break;
372
373 } // end
374
375 } // end extensionCallback()
376
377 /*---------------------------------------------------------------------------*
378 * Name : samplingCallback()
379 * Description : Invoked by WPAD every time data is available for WPADRead().
380 * Arguments : Channel for which data is available.
381 * Returns : None.
382 *---------------------------------------------------------------------------*/
samplingCallback(s32 chan)383 void samplingCallback( s32 chan )
384 {
385 #pragma unused(chan)
386
387 // for this demo, we're not actually doing anything here.
388 // Normally, you can call WPADProbe() and WPADRead() to retrieve
389 // the WPAD Status block for the indicated channel.
390 //
391 // However, since we're using the auto sampling buffer, we won't bother.
392 //
393 // We are using this empty function to demonstrate how to handle
394 // registration of sampling callback during connect/attach events.
395 //
396
397
398 } // end sampling Callback
399
400
401
402 /*---------------------------------------------------------------------------*
403 * Name : myAlloc()
404 * Description : Callback needed by WPAD to allocate mem from MEM2 heap
405 * Arguments : size of block, in bytes.
406 * Returns : pointer to allocated block.
407 *---------------------------------------------------------------------------*/
myAlloc(u32 size)408 static void *myAlloc( u32 size )
409 {
410 void *ptr;
411
412 ptr = MEMAllocFromAllocator(&DemoAllocator2, size);
413 ASSERTMSG(ptr, "Memory allocation failed\n");
414
415 return(ptr);
416
417 } // myAlloc()
418
419 /*---------------------------------------------------------------------------*
420 * Name : myFree()
421 * Description : Callback needed by WPAD to free mem from MEM2 heap
422 * Arguments : None.
423 * Returns : Always 1.
424 *---------------------------------------------------------------------------*/
myFree(void * ptr)425 static u8 myFree( void *ptr )
426 {
427
428 MEMFreeToAllocator(&DemoAllocator2, ptr);
429
430 // we should ensure that memory is free'd properly, but oh well
431 return(1);
432
433 } // myFree()
434
435
436
437 /*===========================================================================*
438 * I N T E R N A L F U N C T I O N S
439 *===========================================================================*/
440 /*---------------------------------------------------------------------------*
441 * The following functions handle the status display of this demo.
442 * They aren't really relevant to the demonstration of the CONNECT
443 * and EXTENSION callbacks.
444 *---------------------------------------------------------------------------*/
445 /*---------------------------------------------------------------------------*
446 * Local Data
447 *---------------------------------------------------------------------------*/
448
449 #define COL_WIDTH 6*FONT_HEIGHT
450 #define X_START 10
451 #define Y_START 10
452
renderStatus(void)453 static void renderStatus( void )
454 {
455 WPADCLStatus status_block;
456 WPADStatus *wpad_ptr;
457 WPADCLStatus *cl_ptr;
458 WPADFSStatus *fs_ptr;
459
460 s32 status;
461 u32 type;
462
463 s16 x;
464 s16 y;
465
466 char buf[] = "___________";
467 char buf2[] = "__";
468 char buf3[] = "_______________";
469
470
471 // clear status block
472 memset((void *)(&status_block), 0, sizeof(WPADCLStatus));
473
474 x = X_START;
475 y = Y_START;
476
477 DEMOPrintf(x, y, 0, "WPAD Demo -- Dummy checker");
478 y+=FONT_HEIGHT;
479 y+=FONT_HEIGHT;
480 DEMOPrintf(x, y, 0, "Status :"); y+=FONT_HEIGHT;
481 DEMOPrintf(x, y, 0, "Type :"); y+=FONT_HEIGHT;
482 DEMOPrintf(x, y, 0, "Error :"); y+=FONT_HEIGHT;
483 DEMOPrintf(x, y, 0, "Buttons:"); y+=FONT_HEIGHT;
484 DEMOPrintf(x, y, 0, "DPD0-xy:"); y+=FONT_HEIGHT;
485 DEMOPrintf(x, y, 0, "DPD1-xy:"); y+=FONT_HEIGHT;
486 DEMOPrintf(x, y, 0, "ACC-XYZ:"); y+=FONT_HEIGHT;
487 DEMOPrintf(x, y, 0, "--------"); y+=FONT_HEIGHT;
488 DEMOPrintf(x, y, 0, "Buttons:"); y+=FONT_HEIGHT;
489 DEMOPrintf(x, y, 0, "StickXY:"); y+=FONT_HEIGHT;
490 DEMOPrintf(x, y, 0, "ACC-XYZ:"); y+=FONT_HEIGHT;
491 DEMOPrintf(x, y, 0, "--------"); y+=FONT_HEIGHT;
492 DEMOPrintf(x, y, 0, "Buttons:"); y+=FONT_HEIGHT;
493 DEMOPrintf(x, y, 0, "StickXY:"); y+=FONT_HEIGHT;
494 DEMOPrintf(x, y, 0, "StickXY:"); y+=FONT_HEIGHT;
495 DEMOPrintf(x, y, 0, "TrigLR :"); y+=FONT_HEIGHT;
496
497 x = (s16)(X_START + COL_WIDTH);
498 y = (s16)(Y_START + FONT_HEIGHT*2);
499
500 status = WPADProbe(WPAD_CHAN0, &type);
501
502 DEMOPrintf(x, y, 0, "%s", get_status_name(status)); y+= FONT_HEIGHT;
503 DEMOPrintf(x, y, 0, "%s", get_dev_name(type)); y+= FONT_HEIGHT;
504
505 if (WPAD_ERR_NO_CONTROLLER != status)
506 {
507 WPADRead(WPAD_CHAN0, &status_block);
508 wpad_ptr = (WPADStatus *)(&status_block);
509 cl_ptr = (WPADCLStatus *)(&status_block);
510 fs_ptr = (WPADFSStatus *)(&status_block);
511
512 DEMOPrintf(x, y, 0, "%s", get_status_name(wpad_ptr->err)); y+= FONT_HEIGHT;
513
514 if( wpad_ptr->err != WPAD_ERR_INVALID )
515 {
516 if( wpad_ptr->button & WPAD_BUTTON_LEFT ) buf[ 0] = '<';
517 if( wpad_ptr->button & WPAD_BUTTON_UP ) buf[ 1] = '^';
518 if( wpad_ptr->button & WPAD_BUTTON_DOWN ) buf[ 2] = 'v';
519 if( wpad_ptr->button & WPAD_BUTTON_RIGHT ) buf[ 3] = '>';
520 if( wpad_ptr->button & WPAD_BUTTON_A ) buf[ 4] = 'A';
521 if( wpad_ptr->button & WPAD_BUTTON_B ) buf[ 5] = 'B';
522 if( wpad_ptr->button & WPAD_BUTTON_1 ) buf[ 6] = '1';
523 if( wpad_ptr->button & WPAD_BUTTON_2 ) buf[ 7] = '2';
524 if( wpad_ptr->button & WPAD_BUTTON_MINUS ) buf[ 8] = '-';
525 if( wpad_ptr->button & WPAD_BUTTON_HOME ) buf[ 9] = 'H';
526 if( wpad_ptr->button & WPAD_BUTTON_PLUS ) buf[10] = '+';
527 }
528 DEMOPrintf(x, y, 0, " %s", buf); y+= FONT_HEIGHT;
529
530 if( wpad_ptr->err == WPAD_ERR_NONE || wpad_ptr->err == WPAD_ERR_CORRUPTED )
531 {
532 DEMOPrintf(x, y, 0, " %04X %04X", (u16)(wpad_ptr->obj[0].x), (u16)(wpad_ptr->obj[0].y)); y+= FONT_HEIGHT;
533 DEMOPrintf(x, y, 0, " %04X %04X", (u16)(wpad_ptr->obj[1].x), (u16)(wpad_ptr->obj[1].y)); y+= FONT_HEIGHT;
534 DEMOPrintf(x, y, 0, " %04X %04X %04X", (u16)(wpad_ptr->accX), (u16)(wpad_ptr->accY), (u16)(wpad_ptr->accZ)); y+= FONT_HEIGHT;
535 }
536 else
537 {
538 DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT;
539 DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT;
540 DEMOPrintf(x, y, 0, " ---- ---- ----"); y+= FONT_HEIGHT;
541 }
542 y+= FONT_HEIGHT;
543
544 if (WPAD_DEV_FREESTYLE == type)
545 {
546 if( fs_ptr->err == WPAD_ERR_NONE )
547 {
548 if( fs_ptr->button & WPAD_BUTTON_C) buf2[ 0] = 'C';
549 if( fs_ptr->button & WPAD_BUTTON_Z) buf2[ 1] = 'Z';
550 }
551 DEMOPrintf(x, y, 0, " %s", buf2); y+= FONT_HEIGHT;
552
553 if( fs_ptr->err == WPAD_ERR_NONE )
554 {
555 DEMOPrintf(x, y, 0, " %04X %04X", (u16)(fs_ptr->fsStickX), (u16)(fs_ptr->fsStickY)); y+= FONT_HEIGHT;
556 DEMOPrintf(x, y, 0, " %04X %04X %04X", (u16)(fs_ptr->fsAccX), (u16)(fs_ptr->fsAccY), (u16)(fs_ptr->fsAccZ)); y+= FONT_HEIGHT;
557 }
558 else
559 {
560 DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT;
561 DEMOPrintf(x, y, 0, " ---- ---- ----"); y+= FONT_HEIGHT;
562 }
563 }
564 else
565 {
566 y+= FONT_HEIGHT * 3;
567 }
568 y+= FONT_HEIGHT;
569
570 if (WPAD_DEV_CLASSIC == type)
571 {
572 if( cl_ptr->err == WPAD_ERR_NONE )
573 {
574 if( cl_ptr->clButton & WPAD_CL_BUTTON_LEFT ) buf3[ 0] = '<';
575 if( cl_ptr->clButton & WPAD_CL_BUTTON_UP ) buf3[ 1] = '^';
576 if( cl_ptr->clButton & WPAD_CL_BUTTON_DOWN ) buf3[ 2] = 'v';
577 if( cl_ptr->clButton & WPAD_CL_BUTTON_RIGHT ) buf3[ 3] = '>';
578 if( cl_ptr->clButton & WPAD_CL_BUTTON_A ) buf3[ 4] = 'A';
579 if( cl_ptr->clButton & WPAD_CL_BUTTON_B ) buf3[ 5] = 'B';
580 if( cl_ptr->clButton & WPAD_CL_BUTTON_X ) buf3[ 6] = 'X';
581 if( cl_ptr->clButton & WPAD_CL_BUTTON_Y ) buf3[ 7] = 'Y';
582 if( cl_ptr->clButton & WPAD_CL_TRIGGER_L ) buf3[ 8] = 'L';
583 if( cl_ptr->clButton & WPAD_CL_TRIGGER_R ) buf3[ 9] = 'R';
584 if( cl_ptr->clButton & WPAD_CL_TRIGGER_ZL ) buf3[10] = 'z';
585 if( cl_ptr->clButton & WPAD_CL_TRIGGER_ZR ) buf3[11] = 'Z';
586 if( cl_ptr->clButton & WPAD_CL_BUTTON_MINUS ) buf3[12] = '-';
587 if( cl_ptr->clButton & WPAD_CL_BUTTON_HOME ) buf3[13] = 'H';
588 if( cl_ptr->clButton & WPAD_CL_BUTTON_PLUS ) buf3[14] = '+';
589 }
590 DEMOPrintf(x, y, 0, " %s", buf3); y+= FONT_HEIGHT;
591
592 if( cl_ptr->err == WPAD_ERR_NONE )
593 {
594 DEMOPrintf(x, y, 0, " %04X %04X", (u16)(cl_ptr->clLStickX), (u16)(cl_ptr->clLStickY)); y+= FONT_HEIGHT;
595 DEMOPrintf(x, y, 0, " %04X %04X", (u16)(cl_ptr->clRStickX), (u16)(cl_ptr->clRStickY)); y+= FONT_HEIGHT;
596 DEMOPrintf(x, y, 0, " %04X %04X", (u16)(cl_ptr->clTriggerL), (u16)(cl_ptr->clTriggerR)); y+= FONT_HEIGHT;
597 }
598 else
599 {
600 DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT;
601 DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT;
602 DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT;
603 }
604 } // if classic
605
606 } // if no error
607
608 } // end renderStatus()
609
610
get_dev_name(u32 type)611 static u8 *get_dev_name( u32 type )
612 {
613
614 u8 str_dev_core [] = " Core ";
615 u8 str_dev_extn [] = " Extn ";
616 u8 str_dev_cl [] = " Classic ";
617 u8 str_dev_future [] = " Future ";
618 u8 str_dev_notsup [] = " Not sup ";
619 u8 str_dev_unknown[] = " Unknwon ";
620
621 u8 *ptr;
622
623 switch(type)
624 {
625 case WPAD_DEV_CORE: ptr = &str_dev_core[0]; break;
626 case WPAD_DEV_FREESTYLE: ptr = &str_dev_extn[0]; break;
627 case WPAD_DEV_CLASSIC: ptr = &str_dev_cl[0]; break;
628 case WPAD_DEV_FUTURE: ptr = &str_dev_future[0]; break;
629 case WPAD_DEV_NOT_SUPPORTED: ptr = &str_dev_notsup[0]; break;
630 case WPAD_DEV_UNKNOWN:
631 default: ptr = &str_dev_unknown[0]; break;
632
633 } // end switch
634
635 return(ptr);
636
637 } // end
638
639
get_status_name(s32 status)640 static u8 *get_status_name( s32 status )
641 {
642
643 u8 str_status_ok [] = " OK ";
644 u8 str_status_none[] = " NONE ";
645 u8 str_status_busy[] = " BUSY ";
646 u8 str_status_xfer[] = " Transfer ";
647 u8 str_status_inv [] = " INVALID ";
648 u8 str_status_crpt[] = " Corrupted";
649 u8 str_status_unk [] = " UNKNOWN ";
650
651 u8 *ptr;
652
653 switch(status)
654 {
655 case WPAD_ERR_NONE: ptr = &str_status_ok[0]; break;
656 case WPAD_ERR_NO_CONTROLLER: ptr = &str_status_none[0]; break;
657 case WPAD_ERR_BUSY: ptr = &str_status_busy[0]; break;
658 case WPAD_ERR_TRANSFER: ptr = &str_status_xfer[0]; break;
659 case WPAD_ERR_INVALID: ptr = &str_status_inv[0]; break;
660 case WPAD_ERR_CORRUPTED: ptr = &str_status_crpt[0]; break;
661 default: ptr = &str_status_unk[0]; break;
662
663 } // end switch
664
665 return(ptr);
666
667 } // end
668
669
initialize(void)670 static void initialize( void )
671 {
672 const GXColor DARKBLUE = { 0, 0, 40, 255 };
673
674 OSInit();
675
676 DEMOInit( &GXNtsc480IntDf );
677
678 GXSetCopyClear( DARKBLUE, GX_MAX_Z24 );
679 GXCopyDisp( DEMOGetCurrentBuffer(), GX_TRUE );
680 DEMOInitCaption( DM_FT_XLU, SCREEN_WIDTH, SCREEN_HEIGHT );
681 GXSetZMode( GX_ENABLE, GX_ALWAYS, GX_ENABLE ); // Set pixel processing mode
682 GXSetBlendMode( GX_BM_BLEND, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR ); // Translucent mode
683
684 DEMOPadInit();
685
686 } // end
687
688
689 /*---------------------------------------------------------------------------*
690 * Name : renderAimings()
691 * Description :
692 * Arguments : None.
693 * Returns : None.
694 *---------------------------------------------------------------------------*/
renderAimings(void)695 static void renderAimings( void )
696 {
697 u32 latest;
698 u32 index;
699
700 int i;
701 u32 fmt;
702
703 WPADStatus *co_ptr;
704 WPADFSStatus *fs_ptr;
705 WPADCLStatus *cl_ptr;
706
707 fmt = WPADGetDataFormat(WPAD_CHAN0);
708
709 switch (fmt)
710 {
711 case WPAD_FMT_CORE:
712 case WPAD_FMT_CORE_ACC:
713 case WPAD_FMT_CORE_ACC_DPD:
714
715 co_ptr = (WPADStatus *)(&co_ringbuffer[0]);
716
717 latest = WPADGetLatestIndexInBuf(WPAD_CHAN0);
718 index = ((latest - 1) + SMPBUF_SIZE) % SMPBUF_SIZE;
719
720 for (i=0; i<SMPBUF_SIZE-1; i++)
721 {
722 if (WPAD_ERR_NONE == co_ptr[index].err)
723 {
724 s16 x=(s16)(SCREEN_WIDTH -(co_ptr[index].obj[0].x+co_ptr[index].obj[1].x)/2*SCREEN_WIDTH /WPAD_DPD_IMG_RESO_WX);
725 s16 y=(s16)(SCREEN_HEIGHT-(co_ptr[index].obj[0].y+co_ptr[index].obj[1].y)/2*SCREEN_HEIGHT/WPAD_DPD_IMG_RESO_WY);
726 DEMOPrintf(x, y, 0, ".");
727 }
728 index = ((index - 1) + SMPBUF_SIZE) % SMPBUF_SIZE;
729 }
730 break;
731
732 case WPAD_FMT_FREESTYLE:
733 case WPAD_FMT_FREESTYLE_ACC:
734 case WPAD_FMT_FREESTYLE_ACC_DPD:
735
736 fs_ptr = (WPADFSStatus *)(&fs_ringbuffer[0]);
737
738 latest = WPADGetLatestIndexInBuf(WPAD_CHAN0);
739 index = ((latest - 1) + SMPBUF_SIZE) % SMPBUF_SIZE;
740
741 for (i=0; i<SMPBUF_SIZE-1; i++)
742 {
743 if (WPAD_ERR_NONE == fs_ptr[index].err || WPAD_ERR_CORRUPTED == fs_ptr[index].err)
744 {
745 s16 x=(s16)(SCREEN_WIDTH -(fs_ptr[index].obj[0].x+fs_ptr[index].obj[1].x)/2*SCREEN_WIDTH /WPAD_DPD_IMG_RESO_WX);
746 s16 y=(s16)(SCREEN_HEIGHT-(fs_ptr[index].obj[0].y+fs_ptr[index].obj[1].y)/2*SCREEN_HEIGHT/WPAD_DPD_IMG_RESO_WY);
747 DEMOPrintf(x, y, 0, ".");
748 }
749 index = ((index - 1) + SMPBUF_SIZE) % SMPBUF_SIZE;
750 }
751 break;
752
753 case WPAD_FMT_CLASSIC:
754 case WPAD_FMT_CLASSIC_ACC:
755 case WPAD_FMT_CLASSIC_ACC_DPD:
756
757 cl_ptr = (WPADCLStatus*)(&cl_ringbuffer[0]);
758
759 latest = WPADGetLatestIndexInBuf(WPAD_CHAN0);
760 index = ((latest - 1) + SMPBUF_SIZE) % SMPBUF_SIZE;
761
762 for(i=0; i<SMPBUF_SIZE-1; i++)
763 {
764 if (WPAD_ERR_NONE == cl_ptr[index].err || WPAD_ERR_CORRUPTED == cl_ptr[index].err)
765 {
766 s16 x=(s16)(SCREEN_WIDTH -(cl_ptr[index].obj[0].x+cl_ptr[index].obj[1].x)/2*SCREEN_WIDTH /WPAD_DPD_IMG_RESO_WX);
767 s16 y=(s16)(SCREEN_HEIGHT-(cl_ptr[index].obj[0].y+cl_ptr[index].obj[1].y)/2*SCREEN_HEIGHT/WPAD_DPD_IMG_RESO_WY);
768 DEMOPrintf(x, y, 0, ".");
769 }
770 index = ((index - 1) + SMPBUF_SIZE) % SMPBUF_SIZE;
771 }
772 break;
773
774 } // end switch
775
776 } // end
777