-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.c
119 lines (97 loc) · 2.71 KB
/
main.c
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
#include <stdio.h>
#include <string.h>
#include <kernel.h>
#include <hdd-ioctl.h>
#include <sys/fcntl.h>
#include <libgs.h>
#include "main.h"
#include "iop.h"
#include "hdst.h"
#include "system.h"
#include "UI.h"
#include "menu.h"
#include "pad.h"
int VBlankStartSema;
int InstallLockSema;
static int VBlankStartHandler(int cause)
{
ee_sema_t sema;
iReferSemaStatus(VBlankStartSema, &sema);
if (sema.count < sema.max_count)
iSignalSema(VBlankStartSema);
return 0;
}
static void DeinitServices(void)
{
DisableIntc(kINTC_VBLANK_START);
RemoveIntcHandler(kINTC_VBLANK_START, 0);
DeleteSema(VBlankStartSema);
DeleteSema(InstallLockSema);
IopDeinit();
}
int main(int argc, char *argv[])
{
unsigned char PadStatus, done;
unsigned int FrameNum;
ee_sema_t ThreadSema;
int result, InitSemaID, BootDevice;
chdir("mass:/HDDChecker/");
// chdir("hdd0:__system:pfs:/HDDChecker/");
// chdir("hdd0:__system:pfs:/fsck/"); // For testing the standalone FSCK tool.
if ((BootDevice = GetBootDeviceID()) == BOOT_DEVICE_UNKNOWN)
Exit(ENODEV);
#ifdef FSCK
InitSemaID = IopInitStart(IOP_MODSET_SA_INIT);
#else
InitSemaID = IopInitStart(IOP_MODSET_INIT);
#endif
ThreadSema.init_count = 0;
ThreadSema.max_count = 1;
ThreadSema.attr = ThreadSema.option = 0;
VBlankStartSema = CreateSema(&ThreadSema);
ThreadSema.init_count = 1;
ThreadSema.max_count = 1;
ThreadSema.attr = ThreadSema.option = 0;
InstallLockSema = CreateSema(&ThreadSema);
AddIntcHandler(kINTC_VBLANK_START, &VBlankStartHandler, 0);
EnableIntc(kINTC_VBLANK_START);
if (BootDevice != BOOT_DEVICE_HDD) {
if (SysBootDeviceInit() != 0) {
WaitSema(InitSemaID);
DeinitServices();
Exit(-1);
}
if (InitializeUI(0) != 0) {
DeinitializeUI();
WaitSema(InitSemaID);
DeinitServices();
Exit(-1);
}
FrameNum = 0;
/* Draw something nice here while waiting... */
do {
RedrawLoadingScreen(FrameNum);
FrameNum++;
} while (PollSema(InitSemaID) != InitSemaID);
} else
WaitSema(InitSemaID);
DeleteSema(InitSemaID);
if (BootDevice == BOOT_DEVICE_HDD) {
if (SysBootDeviceInit() != 0) {
DeinitServices();
Exit(-1);
}
if (InitializeUI(1) != 0) {
DeinitializeUI();
fileXioUmount("pfs0:");
DeinitServices();
Exit(-1);
}
}
MainMenu();
DeinitializeUI();
if (BootDevice == BOOT_DEVICE_HDD)
fileXioUmount("pfs0:");
DeinitServices();
return 0;
}