1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: arg.cpp
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd. 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 $Rev:$
14 *---------------------------------------------------------------------------*/
15
16 #include <nn.h>
17 #include <string.h>
18
19 //----------------------------------------------------------------
20 // Show arguments
showArgv(void)21 static void showArgv( void )
22 {
23 int argc = nn::dbg::CTR::GetArgc();
24 NN_LOG("argc = %d\n", argc );
25
26 for( int n=0; n<argc; n++ )
27 {
28 NN_LOG("argv[%d] = [%s]\n", n, nn::dbg::CTR::GetArgv(n) );
29 }
30 }
31
32 //----------------------------------------------------------------
33 // Show sample for function that corresponds to the getopt function
showGetOptSample(void)34 static void showGetOptSample( void )
35 {
36 int c;
37 while( (c = nn::dbg::CTR::GetOpt("AB:C::")) > 0 )
38 {
39 switch (c)
40 {
41 case 'A':
42 {
43 NN_LOG("*** found option A\n");
44 }
45 break;
46 case 'B':
47 {
48 const char* str = nn::dbg::CTR::GetOptArg();
49 NN_UNUSED_VAR(str); // To avoid release build warnings
50 NN_LOG("*** found option B with [%s]\n", str? str: "(null)");
51 }
52 break;
53 case 'C':
54 {
55 const char* str = nn::dbg::CTR::GetOptArg();
56 NN_UNUSED_VAR(str); // To avoid release build warnings
57 NN_LOG("*** found option C with [%s]\n", str? str: "(null)");
58 }
59 break;
60 case '?':
61 default:
62 NN_LOG("*** Unknown option '%c'\n", nn::dbg::CTR::GetOptOpt());
63 break;
64 }
65 }
66 }
67
68 //----------------------------------------------------------------
69 // Binary dump
dump(const void * pBuffer,size_t size)70 static void dump( const void* pBuffer, size_t size )
71 {
72 if ( pBuffer )
73 {
74 const char* p = static_cast<const char*>(pBuffer);
75 NN_UNUSED_VAR(p); // To avoid release build warnings
76 for ( int n=0; n<size; n++ )
77 {
78 if ( (n & 0xf) == 0 )
79 {
80 NN_LOG("%05x : ", n);
81 }
82 NN_LOG("%02x %s", (*p++ & 0xff), ((n&0xf)==0xf)?"\n":"" );
83 }
84 NN_LOG("\n");
85 }
86 }
87
88 //----------------------------------------------------------------
89 // Show arguments
showArgumentData(void)90 static void showArgumentData( void )
91 {
92 // Show argument information
93 showArgv();
94
95 // Show binary information
96 const void* pArea = nn::dbg::CTR::GetArgBinary();
97 size_t size = nn::dbg::CTR::GetArgBinarySize();
98 NN_LOG("Argument binary buffer 0x%x size 0x%x\n", pArea, size);
99 dump( pArea, size );
100 }
101
102 //----------------------------------------------------------------
103 // Sample
nnMain()104 extern "C" void nnMain()
105 {
106 NN_LOG("==== Argument sample starts.\n");
107
108 // information display
109 showArgumentData();
110
111 // getopt sample
112 NN_LOG("---- Getopt sample\n" );
113 showGetOptSample();
114
115 NN_LOG("==== Argument sample end.\n");
116 while(1){}
117 }
118