PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
cdi.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "accdvd_internal.h"
12
13static char *argv_20[2] = {"sceCdInit", 0};
14static struct cdi_softc Cdic;
15
17{
18 sceCdCBFunc result;
19
20 result = (sceCdCBFunc)Cdic.done;
21 Cdic.done = (cdc_done_t)func;
22 return (sceCdCBFunc)result;
23}
24
26{
27 return 0;
28}
29
30int sceCdDiskReady(int mode)
31{
32 return cdc_ready(mode);
33}
34
36{
37 return cdc_medium();
38}
39
41{
42 return cdc_error();
43}
44
46{
47 return cdc_getpos() / 16;
48}
49
50static int cdi_xfer(void *dst, void *src, int len, enum cdc_xfer_dir dir)
51{
52 if ( dir )
53 memcpy(dst, src, len);
54 return len;
55}
56
57int sceCdGetToc(unsigned char *toc)
58{
59 if ( !toc )
60 return cdc_seterrno(34);
61 return cdc_readtoc(toc, cdi_xfer);
62}
63
64int sceCdInit(int mode)
65{
66 if ( mode < 0 )
67 return 0;
68 if ( mode >= 2 )
69 return mode == 5 && cdc_module_stop() >= 0;
70 if ( cdc_module_status() > 0 && cdc_module_stop() < 0 )
71 {
72 return 0;
73 }
74 if ( cdc_module_start(1, argv_20) < 0 )
75 {
76 return 0;
77 }
78 memset(&Cdic, 0, sizeof(Cdic));
79 if ( !mode )
80 {
81 cdc_ready(0);
82 }
83 return 1;
84}
85
86int sceCdMmode(int media)
87{
88 (void)media;
89
90 return 1;
91}
92
94{
95 return cdc_pause(Cdic.done);
96}
97
98int sceCdRead(u32 lbn, u32 sectors, void *buffer, sceCdRMode *mode)
99{
100 if ( !mode || !buffer || ((uiptr)buffer & 3) != 0 )
101 {
102 return cdc_seterrno(34);
103 }
104 if ( !sectors )
105 return cdc_seterrno(0);
106 return cdc_read(lbn, buffer, sectors, mode, 0, Cdic.done);
107}
108
109int sceCdSync(int mode)
110{
111 return cdc_sync(mode != 0);
112}
113
114int sceCdSearchFile(sceCdlFILE *file, const char *name)
115{
116 int namlen;
117
118 namlen = 0;
119 if ( file && name )
120 {
121 const char *v3;
122
123 v3 = name;
124 while ( 1 )
125 {
126 if ( *v3 == 0 )
127 break;
128 v3 = &name[++namlen];
129 if ( namlen >= 1024 )
130 {
131 break;
132 }
133 }
134 if ( namlen >= 1024 )
135 namlen = 0;
136 }
137 if ( !namlen )
138 return cdc_seterrno(34);
139 return cdc_lookup(file, name, namlen, cdi_xfer);
140}
141
142int sceCdSeek(u32 lbn)
143{
144 return cdc_seek(lbn, Cdic.done);
145}
146
148{
149 return cdc_standby(Cdic.done);
150}
151
153{
154 return cdc_stat();
155}
156
158{
159 return cdc_stop(Cdic.done);
160}
161
162int sceCdTrayReq(int param, u32 *traychk)
163{
164 return cdc_tray(param, traychk);
165}
166
167int sceCdStInit(u32 bufmax, u32 bankmax, void *buffer)
168{
169 unsigned int v4;
170
171 if ( !bufmax || !bankmax || !buffer || ((uiptr)buffer & 3) != 0 )
172 return cdc_seterrno(34);
173 v4 = bufmax / bankmax;
174 if ( !(bufmax / bankmax) )
175 v4 = 1;
176 return cdc_inits((void *)buffer, bufmax, v4);
177}
178
179int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
180{
181 if ( mode >= 2 )
182 buffer = 0;
183 if ( !buffer || ((uiptr)buffer & 3) != 0 || !error )
184 {
185 if ( error )
186 *error = 34;
187 return cdc_seterrno(34);
188 }
189 if ( !sectors )
190 {
191 *error = 0;
192 return 0;
193 }
194 return cdc_reads(buffer, sectors, mode, (int *)error, cdc_xfer);
195}
196
197int sceCdStSeek(u32 lbn)
198{
199 return cdc_seeks(lbn);
200}
201
202int sceCdStStart(u32 lbn, sceCdRMode *mode)
203{
204 if ( !mode )
205 return cdc_seterrno(34);
206 return cdc_starts(lbn, mode);
207}
208
210{
211 return cdc_stats();
212}
213
215{
216 return cdc_stops();
217}
218
220{
221 return cdc_pauses();
222}
223
225{
226 return cdc_resumes();
227}
static cdda_toc toc
Definition cdrom.c:52
int sceCdBreak(void)
Definition cdi.c:25
int sceCdStStop(void)
Definition cdi.c:214
int sceCdSearchFile(sceCdlFILE *file, const char *name)
Definition cdi.c:114
int sceCdGetError(void)
Definition cdi.c:40
int sceCdStPause(void)
Definition cdi.c:219
int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
Definition cdi.c:179
int sceCdGetToc(u8 *toc)
Definition cdi.c:57
int sceCdInit(int mode)
Definition cdi.c:64
sceCdCBFunc sceCdCallback(sceCdCBFunc function)
Definition cdi.c:16
int sceCdStInit(u32 bufmax, u32 bankmax, void *buffer)
Definition cdi.c:167
int sceCdStatus(void)
Definition cdi.c:152
int sceCdDiskReady(int mode)
Definition cdi.c:30
int sceCdPause(void)
Definition cdi.c:93
u32 sceCdGetReadPos(void)
Definition cdi.c:45
int sceCdGetDiskType(void)
Definition cdi.c:35
int sceCdMmode(int media)
Definition cdi.c:86
int sceCdSync(int mode)
Definition cdi.c:109
int sceCdStResume(void)
Definition cdi.c:224
int sceCdSeek(u32 lbn)
Definition cdi.c:142
int sceCdStStart(u32 lbn, sceCdRMode *mode)
Definition cdi.c:202
int sceCdStStat(void)
Definition cdi.c:209
void(* sceCdCBFunc)(int reason)
int sceCdRead(u32 lbn, u32 sectors, void *buffer, sceCdRMode *mode)
Definition cdi.c:98
int sceCdStandby(void)
Definition cdi.c:147
int sceCdStSeek(u32 lbn)
Definition cdi.c:197
int sceCdStop(void)
Definition cdi.c:157
int sceCdTrayReq(int param, u32 *traychk)
Definition cdi.c:162