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
|
// Thanks to:
// SD Card Directory Listing Demo
// Updated 12/19/2008 by PunMaster
#include <gccore.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <ogcsys.h>
#include <time.h>
#include <sys/time.h>
#include <wiiuse/wpad.h>
#include <fat.h>
#include <dirent.h>
#include <iostream>
#include <debug.h>
#include <math.h>
static void *xfb = NULL;
u32 first_frame = 1;
GXRModeObj *rmode;
void Initialise()
{
// Initialise the video system
VIDEO_Init();
// This function initialises the attached controllers
PAD_Init();
WPAD_Init();
// Obtain the preferred video mode from the system
// This will correspond to the settings in the Wii menu
rmode = VIDEO_GetPreferredMode(NULL);
// Allocate memory for the display in the uncached region
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
// Initialise the console, required for printf
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
// Set up the video registers with the chosen mode
VIDEO_Configure(rmode);
// Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(xfb);
// Make the display visible
VIDEO_SetBlack(FALSE);
// Flush the video register changes to the hardware
VIDEO_Flush();
// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
}
void dirlist(char* path)
{
DIR* pdir = opendir(path);
if (pdir != NULL)
{
u32 sentinel = 0;
while(true)
{
struct dirent* pent = readdir(pdir);
if(pent == NULL) break;
if(strcmp(".", pent->d_name) != 0 && strcmp("..", pent->d_name) != 0)
{
char dnbuf[260];
sprintf(dnbuf, "%s/%s", path, pent->d_name);
struct stat statbuf;
stat(dnbuf, &statbuf);
if(S_ISDIR(statbuf.st_mode))
{
printf("%s <DIR>\n", dnbuf);
dirlist(dnbuf);
}
else
{
printf("%s (%d)\n", dnbuf, (int)statbuf.st_size);
}
sentinel++;
}
}
if (sentinel == 0)
printf("empty\n");
closedir(pdir);
printf("\n");
}
else
{
printf("opendir() failure.\n");
}
}
int main()
{
bool canList = false;
Initialise();
printf("\x1b[10;0H");
if(fatInitDefault())
{
printf("\nPress A to list dirs\n");
canList = true;
}
else
printf("\nfatInitDefault() failure.\n");
while(1)
{
// Call WPAD_ScanPads each loop, this reads the latest controller states
PAD_ScanPads();
WPAD_ScanPads();
// WPAD_ButtonsDown tells us which buttons were wpressed in this loop
// this is a "one shot" state which will not fire again until the button has been released
u32 pressed = PAD_ButtonsDown(0);
u32 wpressed = WPAD_ButtonsDown(0);
if ((wpressed & WPAD_BUTTON_A || pressed & PAD_BUTTON_A) && canList)
dirlist("/");
// We return to the launcher application via exit
if (wpressed & WPAD_BUTTON_HOME || pressed & PAD_BUTTON_START)
exit(0);
// Wait for the next frame
VIDEO_WaitVSync();
}
return 0;
}
|