source: ps2launchargs/source/uLaunchELF/cd.c@ 1110

Last change on this file since 1110 was 1101, checked in by iritscen, 7 years ago

Added following to ps2launchargs:\n-Source code.\n-DLL needed to run ps2client.\n-Instructions for building uLaunchELF.

  • Property svn:executable set to *
File size: 4.3 KB
Line 
1//---------------------------------------------------------------------------
2//File name: cd.c
3//---------------------------------------------------------------------------
4#include "launchelf.h"
5
6#define CD_SERVER_INIT 0x80000592
7#define CD_SERVER_SCMD 0x80000593
8#define CD_SCMD_GETDISCTYPE 0x03
9
10SifRpcClientData_t clientInit __attribute__ ((aligned(64)));
11u32 initMode __attribute__ ((aligned(64)));
12s32 cdThreadId = 0;
13s32 bindSearchFile = -1;
14s32 bindDiskReady = -1;
15s32 bindInit = -1;
16s32 bindNCmd = -1;
17s32 bindSCmd = -1;
18s32 nCmdSemaId = -1; // n-cmd semaphore id
19s32 sCmdSemaId = -1; // s-cmd semaphore id
20s32 callbackSemaId = -1; // callback semaphore id
21s32 cdDebug = 0;
22s32 sCmdNum = 0;
23SifRpcClientData_t clientSCmd __attribute__ ((aligned(64)));
24u8 sCmdRecvBuff[48] __attribute__ ((aligned(64)));
25volatile s32 cbSema = 0;
26ee_thread_t cdThreadParam; // Iritscen: changed "ee_thread_status_t" (used in later ps2sdk versions) to earlier name "ee_thread_t"
27s32 callbackThreadId = 0;
28volatile s32 cdCallbackNum __attribute__ ((aligned(64)));
29
30void cdSemaInit(void);
31s32 cdCheckSCmd(s32 cur_cmd);
32s32 cdSyncS(s32 mode);
33void cdSemaExit(void);
34
35//---------------------------------------------------------------------------
36s32 cdInit(s32 mode)
37{
38 s32 i;
39
40 if (cdSyncS(1))
41 return 0;
42 SifInitRpc(0);
43 cdThreadId = GetThreadId();
44 bindSearchFile = -1;
45 bindNCmd = -1;
46 bindSCmd = -1;
47 bindDiskReady = -1;
48 bindInit = -1;
49
50 while (1) {
51 if (SifBindRpc(&clientInit, CD_SERVER_INIT, 0) >= 0)
52 if (clientInit.server != 0) break;
53 i = 0x10000;
54 while (i--);
55 }
56
57 bindInit = 0;
58 initMode = mode;
59 SifWriteBackDCache(&initMode, 4);
60 if (SifCallRpc(&clientInit, 0, 0, &initMode, 4, 0, 0, 0, 0) < 0)
61 return 0;
62 if (mode == CDVD_INIT_EXIT) {
63 cdSemaExit();
64 nCmdSemaId = -1;
65 sCmdSemaId = -1;
66 callbackSemaId = -1;
67 } else {
68 cdSemaInit();
69 }
70 return 1;
71}
72
73//---------------------------------------------------------------------------
74void cdSemaExit(void)
75{
76 if (callbackThreadId) {
77 cdCallbackNum = -1;
78 SignalSema(callbackSemaId);
79 }
80 DeleteSema(nCmdSemaId);
81 DeleteSema(sCmdSemaId);
82 DeleteSema(callbackSemaId);
83}
84
85//---------------------------------------------------------------------------
86void cdSemaInit(void)
87{
88 struct t_ee_sema semaParam;
89
90 // return if both semaphores are already inited
91 if (nCmdSemaId != -1 && sCmdSemaId != -1)
92 return;
93
94 semaParam.init_count = 1;
95 semaParam.max_count = 1;
96 semaParam.option = 0;
97 nCmdSemaId = CreateSema(&semaParam);
98 sCmdSemaId = CreateSema(&semaParam);
99
100 semaParam.init_count = 0;
101 callbackSemaId = CreateSema(&semaParam);
102
103 cbSema = 0;
104}
105
106//---------------------------------------------------------------------------
107s32 cdCheckSCmd(s32 cur_cmd)
108{
109 s32 i;
110 cdSemaInit();
111 if (PollSema(sCmdSemaId) != sCmdSemaId) {
112 if (cdDebug > 0)
113 printf("Scmd fail sema cur_cmd:%d keep_cmd:%d\n", cur_cmd, sCmdNum);
114 return 0;
115 }
116 sCmdNum = cur_cmd;
117 ReferThreadStatus(cdThreadId, &cdThreadParam);
118 if (cdSyncS(1)) {
119 SignalSema(sCmdSemaId);
120 return 0;
121 }
122
123 SifInitRpc(0);
124 if (bindSCmd >= 0)
125 return 1;
126 while (1) {
127 if (SifBindRpc(&clientSCmd, CD_SERVER_SCMD, 0) < 0) {
128 if (cdDebug > 0)
129 printf("Libcdvd bind err S cmd\n");
130 }
131 if (clientSCmd.server != 0)
132 break;
133
134 i = 0x10000;
135 while (i--)
136 ;
137 }
138
139 bindSCmd = 0;
140 return 1;
141}
142
143//---------------------------------------------------------------------------
144s32 cdSyncS(s32 mode)
145{
146 if (mode == 0) {
147 if (cdDebug > 0)
148 printf("S cmd wait\n");
149 while (SifCheckStatRpc(&clientSCmd))
150 ;
151 return 0;
152 }
153 return SifCheckStatRpc(&clientSCmd);
154}
155
156//---------------------------------------------------------------------------
157CdvdDiscType_t cdGetDiscType(void)
158{
159 if (cdCheckSCmd(CD_SCMD_GETDISCTYPE) == 0)
160 return 0;
161
162 if (SifCallRpc(&clientSCmd, CD_SCMD_GETDISCTYPE, 0, 0, 0, sCmdRecvBuff, 4, 0, 0) < 0) {
163 SignalSema(sCmdSemaId);
164 return 0;
165 }
166
167 SignalSema(sCmdSemaId);
168 return *(s32 *) UNCACHED_SEG(sCmdRecvBuff);
169}
170//------------------------------
171//endfunc cdGetDiscType
172//---------------------------------------------------------------------------
173//End of file: cd.c
174//---------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.