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