11 #include "irx_imports.h"
25 IRX_ID(
"cdvd_driver", 2, 38);
50 int m_sector_count_total;
60 unsigned int m_cache_hit_count;
72 unsigned char m_type[1];
73 unsigned char m_id[5];
75 unsigned char m_version[1];
77 unsigned char m_unused1[1];
79 unsigned char m_system_id[32];
81 unsigned char m_volume_id[32];
83 unsigned char m_unused2[8];
85 unsigned char m_volume_space_size[8];
87 unsigned char m_unused3[32];
89 unsigned char m_volume_set_size[4];
91 unsigned char m_volume_sequence_number[4];
93 unsigned char m_logical_block_size[4];
95 unsigned char m_path_table_size[8];
96 unsigned char m_type_l_path_table[4];
98 unsigned char m_opt_type_l_path_table[4];
100 unsigned char m_type_m_path_table[4];
102 unsigned char m_opt_type_m_path_table[4];
104 unsigned char m_root_directory_record[34];
106 unsigned char m_volume_set_id[128];
108 unsigned char m_publisher_id[128];
110 unsigned char m_preparer_id[128];
112 unsigned char m_application_id[128];
114 unsigned char m_copyright_file_id[37];
116 unsigned char m_abstract_file_id[37];
118 unsigned char m_bibliographic_file_id[37];
120 unsigned char m_creation_date[17];
122 unsigned char m_modification_date[17];
124 unsigned char m_expiration_date[17];
126 unsigned char m_effective_date[17];
128 unsigned char m_file_structure_version[1];
130 unsigned char m_unused4[1];
132 unsigned char m_application_data[512];
134 unsigned char m_unused5[653];
139 unsigned char m_name_len[2];
140 unsigned char m_extent[4];
141 unsigned char m_parent[2];
142 unsigned char m_name[];
147 unsigned char m_length[1];
148 unsigned char m_ext_attr_length[1];
149 unsigned char m_extent[8];
150 unsigned char m_size[8];
151 unsigned char m_date[7];
152 unsigned char m_flags[1];
153 unsigned char m_file_unit_size[1];
154 unsigned char m_interleave[1];
155 unsigned char m_volume_sequence_number[4];
156 unsigned char m_name_len[1];
157 unsigned char m_name[];
161 extern void cdvdman_termcall(
int with_stop);
163 static int cdrom_dopen(
iop_file_t *f,
const char *dirname);
166 static int cdrom_open(
iop_file_t *f,
const char *name,
int mode,
int arg4);
168 static int cdrom_read(
iop_file_t *f,
void *buf,
int nbytes);
169 static int cdrom_ioctl(
iop_file_t *f,
int arg,
void *param);
170 static int cdrom_ioctl2(
iop_file_t *f,
int request,
void *argp,
size_t arglen,
void *bufp,
size_t buflen);
172 cdrom_devctl(
iop_file_t *f,
const char *,
int cmd,
void *argp,
unsigned int arglen,
void *bufp,
unsigned int buflen);
173 static int cdrom_lseek(
iop_file_t *f,
int offset,
int pos);
175 static int sceCdSearchDir(
char *dirname,
int layer);
176 static int sceCdReadDir(
sceCdlFILE *fp,
int dsec,
int index,
int layer);
177 static int cdvdman_cmpname(
const char *p,
const char *q);
178 static int CD_newmedia(
int arg);
179 static int cdvdman_finddir(
int target_parent,
const char *target_name);
180 static int CD_cachefile(
int dsec,
int layer);
181 static int disc_read(
int size,
int loc,
void *buffer,
int layer);
182 static int path_tbl_init(u32 blocks,
char *fname,
int action);
183 extern unsigned int optimized_memcpy(
char *dst,
const char *src,
unsigned int n);
184 static int vSetAlarm(
iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *arg),
void *arg);
185 static int vCancelAlarm(
unsigned int (*alarm_cb)(
void *arg),
void *arg);
186 static int vSetEventFlag(
int ef, u32 bits);
187 static int vDelayThread(
int usec);
188 static int DvdDual_infochk();
189 static void cdvdman_init();
191 static int intrh_dma_3(
void *userdata);
192 static int cdvdman_mediactl(
int code);
193 #ifndef CDVD_VARIANT_XOSD
194 static int cdvdman_ncmd_sender_06();
196 static int cdvdman_gettoc(u8 *
toc);
197 static int cdvdman_isdvd();
198 static int sceCdRead0_Rty(u32 lsn, u32 nsec,
void *buf,
const sceCdRMode *mode,
int ncmd,
int dintrsec,
void *func);
199 static int cdvdman_syncdec(
int decflag,
int decxor,
int shift, u32 data);
200 static void Read2intrCDVD(
int read2_flag);
201 #ifndef CDVD_VARIANT_XOSD
202 static int cdvdman_scmd_sender_03_30(u8 *buf, u32 *status);
204 static int cdvdman_scmd_sender_3B(
int arg1);
205 #ifdef CDVD_VARIANT_DNAS
206 static int cdvdman_ncmd_sender_0C(
int arg1, u32 arg2, u32 arg3);
208 #ifdef CDVD_VARIANT_XOSD
209 static unsigned int sceCdChgSpdlCtrl(
int mode);
211 #ifdef CDVD_VARIANT_XOSD
212 static int cdvdman_change_drive(
int mode);
213 static int cdvdman_get_renewal_date(u8 *buffer, u32 *status);
214 static int get_cdvd_register(
int regnr);
215 static int get_disk_type_ex();
216 static int sc_ffffffd8(u32 *status);
217 static int set_cdvd_dev5_base_addr_atapi(
int mode);
218 static int update_cd_mode_ps2_atapi(
void);
221 static char g_cdvdman_cache_name[256] =
"host0:";
222 static int g_cdvdman_cache_sector_size_count = 1;
223 static int g_cdvdman_srchspd = 0;
224 static int g_cdvdman_spinctl = -1;
225 static int g_cdvdman_spinnom = -1;
226 static int g_cdvdman_trycnt = -1;
227 static int g_cdvdman_iocache = 0;
228 static unsigned int g_cdvdman_lcn_offset = 0;
229 static unsigned int g_cdvdman_numbytes_offset = 0;
230 static int g_cdvdman_strmerr = 0;
232 IOMANX_RETURN_VALUE_IMPL(
EIO);
237 IOMANX_RETURN_VALUE(
EIO),
241 IOMANX_RETURN_VALUE(
EIO),
244 IOMANX_RETURN_VALUE(
EIO),
245 IOMANX_RETURN_VALUE(
EIO),
246 IOMANX_RETURN_VALUE(
EIO),
251 IOMANX_RETURN_VALUE(
EIO),
252 IOMANX_RETURN_VALUE(
EIO),
253 IOMANX_RETURN_VALUE(
EIO),
254 IOMANX_RETURN_VALUE(
EIO),
255 IOMANX_RETURN_VALUE(
EIO),
256 IOMANX_RETURN_VALUE(
EIO),
257 IOMANX_RETURN_VALUE_S64(
EIO),
259 IOMANX_RETURN_VALUE(
EIO),
260 IOMANX_RETURN_VALUE(
EIO),
264 static int g_cdvdman_sync_timeout = 15000;
265 static int g_cdvdman_stream_timeout = 5000;
266 #ifdef CDVD_VARIANT_DNAS
269 static int g_verbose_level = 0;
271 static unsigned int g_cache_count = 0;
272 static unsigned int g_cache_table = 0;
273 static unsigned int g_cdvdman_pathtblsize = 0;
274 static int g_cache_path_size = 0;
275 static int g_cache_path_fd = -1;
276 static int g_cdvdman_fs_cdsec = 0;
277 static int g_cdvdman_fs_layer = -1;
278 static int g_cdvdman_fs_cache = 0;
279 static int g_cdvdman_fs_base2 = 0;
280 #ifdef CDVD_VARIANT_XOSD
281 static vu8 *g_cdvdreg_bf801460 = (vu8 *)0xBF801460;
283 static vu8 *g_cdvdreg_bf801464 = (vu8 *)0xBF801464;
284 static vu8 *g_cdvdreg_bf80146c = (vu8 *)0xBF80146C;
286 static int g_cd_atapi_evfid = 0xFFFFFFFF;
287 static int g_acmd_evfid = 0xFFFFFFFF;
288 static int g_adma_evfid = 0xFFFFFFFF;
290 static int g_cdvdman_clk_flg = 0;
291 static int g_cdvdman_cd36key = 0;
292 static int g_cdvdman_ee_rpc_fno = 0;
293 static int g_cdvdman_mmode = 0;
294 static int g_cdvdman_last_cmdfunc = 0;
295 static int g_cdvdman_minver_10700 = 0;
296 static int g_cdvdman_minver_20200 = 0;
297 static int g_cdvdman_minver_20400 = 0;
298 static int g_cdvdman_minver_20800 = 0;
299 static int g_cdvdman_emudvd9 = 0;
300 static int g_cdvdman_minver_50000 = 0;
301 static int g_cdvdman_minver_50200 = 0;
302 static int g_cdvdman_minver_50400 = 0;
303 static int g_cdvdman_minver_50600 = 0;
304 static int g_cdvdman_minver_60000 = 0;
305 static int g_cdvdman_minver_60200 = 0;
306 #ifdef CDVD_VARIANT_OSD
307 static int g_cdvdman_minver_60600 = 0;
309 #ifdef CDVD_VARIANT_XOSD
310 static int g_cdvdman_vernotxxx1x = 0;
312 static int g_cdvdman_minver_x_model_15 = 0;
313 #ifdef CDVD_VARIANT_XOSD
314 static int g_cdvdman_debug_atapi_intr = 0;
316 static const char *g_masterdisc_header =
"PlayStation Master Disc";
317 static char g_cdvdman_ncmd = 0x06;
318 static int g_cdvdman_chmedia = 0;
319 static int g_cdvdman_chflags[4] = {1, 1, 1, 1};
320 static int g_cdvdman_rtindex = 0;
321 static int g_cdvdman_retries = 0;
322 static u8 *g_cdvdman_ptoc;
323 #ifdef CDVD_VARIANT_XOSD
324 static int g_cdvdman_csys_evfid;
326 static int g_scmd_evfid;
327 static void *g_cdvdman_temp_buffer_ptr;
328 static int g_sfile_evfid;
329 static int g_ncmd_evfid;
330 #ifdef CDVD_VARIANT_OSD
331 static s32 g_cdvdman_apply_scmd_sema;
333 static int g_fio_fsv_evfid;
334 static int g_cdvdman_intr_evfid;
335 #ifdef CDVD_VARIANT_XOSD
336 static int (*g_cdvdman_atapi_eject_bs_power_callback)(
int interrupt_nr,
void *userdata);
339 static void *g_cdvdman_power_off_callback_userdata;
340 static void (*g_cdvdman_cdstm0cb)(
int val);
342 static void (*g_cdvdman_power_off_callback)(
void *userdata);
343 #ifdef CDVD_VARIANT_XOSD
344 static void *g_cdvdman_atapi_eject_bs_power_callback_userdata;
346 static void (*g_cdvdman_cdstm1cb)(
int val);
347 static int g_cdvdman_cmdfunc;
349 static char g_cdvdman_sfname[1024];
352 static int g_cdvdman_pathtblflag;
353 static char g_cdvdman_fs_rbuf[0x800];
354 static int g_cdvdman_readptr;
357 static void *g_cdvdman_readbuf;
359 #ifdef CDVD_VARIANT_OSD
360 static int g_cdvdman_config_numblocks;
362 static char g_cdvdman_fsvrbuf[42128];
364 static const int g_cdvdman_cache_sector_count = 16;
366 int _start(
int ac,
char **av)
371 if ( RegisterLibraryEntries(&_exp_cdvdman) )
373 return MODULE_NO_RESIDENT_END;
375 DelDrv(g_cdvdman_cddev.name);
376 if ( AddDrv(&g_cdvdman_cddev) )
378 cdrom_deinit(&g_cdvdman_cddev);
379 return MODULE_NO_RESIDENT_END;
381 g_cdvdman_ptoc = (u8 *)&g_cdvdman_fsvrbuf[0x924];
382 g_cdvdman_temp_buffer_ptr = g_cdvdman_fsvrbuf;
385 SetRebootTimeLibraryHandlingMode(&_exp_cdvdman, 2);
388 _exp_cdvdman.mode &= ~6;
389 _exp_cdvdman.mode |= 2;
391 return MODULE_RESIDENT_END;
394 void *sceGetFsvRbuf(
void)
396 return g_cdvdman_fsvrbuf;
403 #ifdef CDVD_VARIANT_OSD
406 #ifdef CDVD_VARIANT_XOSD
407 USE_DEV5_MMIO_HWPORT();
413 PRINTF(
"cdvdman Init\n");
414 g_cdvdman_istruct.m_wait_flag = 1;
415 g_cdvdman_istruct.m_scmd_flag = 1;
416 g_cdvdman_istruct.m_read2_flag = 0;
417 g_cdvdman_istruct.m_stream_flag = 0;
418 g_cdvdman_istruct.m_last_error =
SCECdErNO;
419 g_cdvdman_istruct.m_layer_1_lsn = 0;
420 g_cdvdman_istruct.m_use_toc = 0;
421 g_cdvdman_istruct.m_last_read_timeout = 0;
422 g_cdvdman_istruct.m_power_flag = 0;
423 g_cdvdman_istruct.m_current_dvd = 0;
424 g_cdvdman_istruct.m_dual_layer_emulation = 0;
425 g_cdvdman_istruct.m_dec_state = 0;
426 g_cdvdman_istruct.m_check_version = 0;
427 g_cdvdman_istruct.m_dec_shift = 0;
428 g_cdvdman_istruct.m_opo_or_para = -1;
429 g_cdvdman_istruct.m_no_dec_flag = 0;
430 #ifdef CDVD_VARIANT_XOSD
431 g_cdvdman_istruct.m_atapi_disk_ejected = 0;
433 g_cdvdman_istruct.m_cd_inited = 0;
434 #ifdef CDVD_VARIANT_XOSD
435 g_cdvdman_istruct.m_chgsys_callback_next_disktype_last = 0;
436 g_cdvdman_istruct.m_chgsys_writer_drive_shell_is_open = 1;
438 g_cdvdman_istruct.m_tray_is_open = 0;
439 g_cdvdman_ee_rpc_fno = 0;
440 g_cdvdman_spinctl = -1;
444 g_cdvdman_intr_evfid = CreateEventFlag(&
event);
445 g_scmd_evfid = CreateEventFlag(&
event);
446 g_ncmd_evfid = CreateEventFlag(&
event);
447 g_sfile_evfid = CreateEventFlag(&
event);
448 g_fio_fsv_evfid = CreateEventFlag(&
event);
449 #ifdef CDVD_VARIANT_XOSD
450 g_cdvdman_csys_evfid = CreateEventFlag(&
event);
452 ClearEventFlag(g_cdvdman_intr_evfid, ~0x4);
453 ClearEventFlag(g_cdvdman_intr_evfid, ~0x10);
454 SetEventFlag(g_cdvdman_intr_evfid, 0x29);
455 SetEventFlag(g_ncmd_evfid, 1);
456 SetEventFlag(g_scmd_evfid, 1);
457 SetEventFlag(g_sfile_evfid, 1);
458 SetEventFlag(g_fio_fsv_evfid, 1);
459 #ifdef CDVD_VARIANT_XOSD
460 SetEventFlag(g_cdvdman_csys_evfid, 1);
462 #ifdef CDVD_VARIANT_OSD
467 g_cdvdman_apply_scmd_sema = CreateSema(&sema);
469 g_cdvdman_spinnom = -1;
470 g_cdvdman_trycnt = -1;
471 sceCdSC(0xFFFFFFF3, &scres_unused);
472 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
474 g_cdvdman_fhinfo[i].m_fd_flags = 0;
476 #ifdef CDVD_VARIANT_XOSD
477 set_cdvd_dev5_base_addr_atapi(2);
479 for ( i = 0; i < 600 && !dev5_mmio_hwport->m_dev5_reg_015; i += 1 )
483 g_cdvdman_istruct.m_cd_mode_ps2_atapi =
484 (!(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen) && !(dev5_mmio_hwport->m_dev5_reg_015 & 0x80)
485 && dev5_mmio_hwport->m_dev5_reg_00F != 6) ?
488 KPRINTF(
"Mode %s Drive\n", g_cdvdman_istruct.m_cd_mode_ps2_atapi == 1 ?
"Atapi" :
"PS2");
489 set_cdvd_dev5_base_addr_atapi(g_cdvdman_istruct.m_cd_mode_ps2_atapi);
494 void cdvdman_termcall(
int with_stop)
498 USE_DEV5_MMIO_HWPORT();
500 VERBOSE_KPRINTF(1,
"CDVD:library Terminate Call %d\n", with_stop);
501 #ifdef CDVD_VARIANT_XOSD
502 if ( update_cd_mode_ps2_atapi() == 1 )
504 set_cdvd_dev5_base_addr_atapi(2);
513 #ifndef CDVD_VARIANT_XOSD
514 if ( g_cdvdman_istruct.m_cd_inited )
516 cdvdman_ncmd_sender_06();
519 for ( i = 0; i < 50000 && (dev5_mmio_hwport->m_dev5_reg_017 & 0x80); i += 1 )
524 if ( (dmac_ch_get_chcr(3) & 0x1000000) )
526 dev5_mmio_hwport->m_dev5_reg_007 = 1;
528 dmac_ch_set_chcr(3, 0);
541 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
543 g_cdvdman_fhinfo[i].m_fd_flags = 0;
545 DeleteEventFlag(g_fio_fsv_evfid);
546 DeleteEventFlag(g_cdvdman_intr_evfid);
547 DeleteEventFlag(g_ncmd_evfid);
548 DeleteEventFlag(g_scmd_evfid);
549 DeleteEventFlag(g_sfile_evfid);
550 #ifdef CDVD_VARIANT_XOSD
551 DeleteEventFlag(g_cdvdman_csys_evfid);
556 static int cdvdman_devready(
void)
560 for ( i = 0; i < 100; i += 1 )
565 g_cdvdman_iocache = 0;
569 if ( (
sceCdDiskReady(8) & 0xC0) == 0x40 && !g_cdvdman_istruct.m_read2_flag && !g_cdvdman_ee_rpc_fno )
578 static int cdvdman_l0check(
int layer)
581 && (g_cdvdman_istruct.m_dual_layer_emulation || g_cdvdman_istruct.m_opo_or_para == 1 || g_cdvdman_istruct.m_opo_or_para == 2);
584 static void cdvdman_iormode(
sceCdRMode *rmode,
int fmode,
int layer)
587 rmode->
trycount = (g_cdvdman_trycnt == -1) ? 16 : g_cdvdman_trycnt;
588 if ( cdvdman_l0check(layer) )
590 if ( g_cdvdman_spinnom == -1 )
602 else if ( g_cdvdman_spinnom == -1 )
634 static int cdrom_dopen(
iop_file_t *f,
const char *dirname)
638 size_t path_name_ind;
643 VERBOSE_PRINTF(1,
"fileIO DOPEN name= %s layer %d\n", dirname, f->
unit);
644 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
645 for ( i = 0; (i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0]))) && g_cdvdman_fhinfo[i].m_fd_flags;
649 if ( i == (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])) )
651 SetEventFlag(g_fio_fsv_evfid, 1);
655 is_devready = cdvdman_devready();
656 if ( is_devready < 0 )
658 SetEventFlag(g_fio_fsv_evfid, 1);
661 strncpy(path_name, dirname,
sizeof(path_name));
662 if ( !strcmp(path_name,
".") )
664 strcpy(path_name,
"\\.");
666 path_name_ind = strlen(path_name);
667 path_name_ind -= (path_name_ind >= 2) ? 2 : 0;
668 if ( strcmp(&path_name[path_name_ind],
"\\.") )
670 strcat(path_name,
"\\.");
672 if ( (
unsigned int)(f->
unit) >= 2 )
674 PRINTF(
"open fail name %s\n", path_name);
675 SetEventFlag(g_fio_fsv_evfid, 1);
678 g_cdvdman_fhinfo[i].m_file_lsn = 0;
679 g_cdvdman_srchspd = 0;
680 file_lsn_tmp = sceCdSearchDir(path_name, f->
unit);
681 if ( file_lsn_tmp < 0 )
683 PRINTF(
"open fail directory %s\n", path_name);
684 SetEventFlag(g_fio_fsv_evfid, 1);
687 g_cdvdman_fhinfo[i].m_file_lsn = file_lsn_tmp;
688 g_cdvdman_fhinfo[i].m_read_pos = 0;
689 g_cdvdman_fhinfo[i].m_filemode = 0;
690 g_cdvdman_fhinfo[i].m_fd_flags = 1;
691 g_cdvdman_fhinfo[i].m_fd_layer = f->
unit;
692 SetEventFlag(g_fio_fsv_evfid, 1);
710 for ( i = 0; i < (
sizeof(buf->mtime) /
sizeof(buf->mtime[0])); i += 1 )
712 buf->mtime[i] = fp->m_file_struct.date[i];
713 buf->atime[i] = fp->m_file_struct.date[i];
714 buf->ctime[i] = fp->m_file_struct.date[i];
716 buf->size = fp->m_file_struct.size;
721 static int cdvdman_cdfname(
char *filename)
725 filename_len = strlen(filename);
726 if ( filename_len >= 3 && !(filename[filename_len - 2] !=
';' && filename[filename_len - 1] !=
'1') )
730 strcat(filename,
";1");
741 VERBOSE_PRINTF(1,
"fileIO GETSTAT name= %s layer= %d\n", name, f->
unit);
742 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
743 devready_tmp = cdvdman_devready();
744 if ( devready_tmp < 0 )
746 SetEventFlag(g_fio_fsv_evfid, 1);
749 strncpy(filename, name,
sizeof(filename));
750 if ( !strcmp(filename,
".") )
752 strcpy(filename,
"\\.");
754 if ( !strcmp(filename,
"\\") )
756 strcpy(filename,
"\\.");
758 if ( !strlen(filename) )
760 strcpy(filename,
"\\.");
762 g_cdvdman_srchspd = 0;
764 memset(&fp, 0,
sizeof(fp));
769 PRINTF(
"open fail name %s\n", name);
770 SetEventFlag(g_fio_fsv_evfid, 1);
773 cdvdman_fillstat(filename, buf, &fp);
774 SetEventFlag(g_fio_fsv_evfid, 1);
786 memset(&fp, 0,
sizeof(fp));
787 VERBOSE_PRINTF(1,
"fileIO DREAD\n");
788 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
789 devready_tmp = cdvdman_devready();
790 if ( devready_tmp < 0 )
792 SetEventFlag(g_fio_fsv_evfid, 1);
795 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
796 g_cdvdman_srchspd = 0;
797 devready_tmp = sceCdReadDir(&fp.m_file_struct, fh->m_file_lsn, fh->m_read_pos, fh->m_fd_layer);
798 if ( devready_tmp < 0 )
800 SetEventFlag(g_fio_fsv_evfid, 1);
806 devready_tmp = strlen(fp.m_file_struct.name);
808 strncpy(buf->name, fp.m_file_struct.name,
sizeof(buf->name));
809 cdvdman_fillstat(fp.m_file_struct.name, &buf->stat, &fp);
810 SetEventFlag(g_fio_fsv_evfid, 1);
816 int cache_remove_result;
818 int cache_file_fd_new;
820 unsigned int file_size_bsr_17;
821 char cache_filename[512];
823 unsigned int ioctl_arg;
825 g_cdvdman_iocache = 0;
828 "%sCache_%d_%d_%d_%d",
829 g_cdvdman_cache_name,
832 (
int)fh->m_file_size,
834 cache_remove_result = 0;
835 VERBOSE_KPRINTF(1,
"Cachefile:%s Open_or_Close:%d\n", cache_filename, open_or_close);
842 fh->m_fd_rbsize = g_cdvdman_cache_sector_size_count ? (g_cdvdman_cache_sector_size_count << 11) : 0x800;
843 fh->m_fd_rcvbuf = (u8 *)AllocSysMemory(ALLOC_LAST, fh->m_fd_rbsize, 0);
844 if ( !fh->m_fd_rcvbuf )
846 VERBOSE_KPRINTF(1,
"Rcvbuf MemAlloc Fail\n");
851 fh->m_cache_file_fd = -1;
852 cache_result = open(cache_filename, O_TRUNC | O_CREAT | O_RDWR, 0x1ff );
853 cache_file_fd_new = cache_result;
854 if ( cache_result >= 0 )
856 u32 file_size_sectors;
857 unsigned int file_size_bsr_6;
859 file_size_sectors = (fh->m_file_size >> 11) + ((!!((fh->m_file_size & 0x7FF))));
860 file_size_bsr_3 = (file_size_sectors >> 3) + (!!(file_size_sectors & 7));
861 file_size_bsr_6 = (file_size_bsr_3 >> 3) + (!!((file_size_bsr_3 & 7)));
862 file_size_bsr_17 = (file_size_bsr_6 >> 11) + (!!((file_size_bsr_6 & 0x7FF)));
863 ioctl_arg = (file_size_bsr_17 + file_size_sectors + 8) << 11;
864 for ( i = 0; i < fh->m_fd_rbsize; i += 1 )
866 fh->m_fd_rcvbuf[i] = 0;
868 if ( !strncmp(cache_filename,
"pfs", 3) )
870 cache_result = ioctl2(cache_file_fd_new, PIOCALLOC, &ioctl_arg, 4, 0, 0);
873 if ( cache_result >= 0 )
875 cache_result = lseek(cache_file_fd_new, 0, 0);
877 if ( cache_result >= 0 )
879 if ( !g_cdvdman_cache_sector_count )
881 for ( i = 0; (int)i < (
int)(g_cdvdman_cache_sector_count << 11); i += 1 )
883 ((
char *)g_cdvdman_temp_buffer_ptr)[i] = 0;
885 for ( i = 0; (int)i < (
int)((ioctl_arg >> 11) / g_cdvdman_cache_sector_count); i += 1 )
887 cache_result = write(cache_file_fd_new, g_cdvdman_temp_buffer_ptr, g_cdvdman_cache_sector_count << 11);
888 if ( cache_result != (g_cdvdman_cache_sector_count << 11) )
890 if ( cache_result >= 0 )
898 if ( cache_result >= 0 )
900 for ( i = 0; (int)i < (
int)((ioctl_arg >> 11)
901 - g_cdvdman_cache_sector_count * ((ioctl_arg >> 11) / g_cdvdman_cache_sector_count));
904 cache_result = write(cache_file_fd_new, fh->m_fd_rcvbuf, 0x800);
905 if ( cache_result != 0x800 )
907 if ( cache_result >= 0 )
916 if ( !open_or_close || cache_result < 0 )
918 if ( fh->m_cache_file_fd != -1 )
920 cache_remove_result = close(fh->m_cache_file_fd);
921 VERBOSE_KPRINTF(1,
"Cache File Close: %d\n", cache_remove_result);
922 if ( cache_remove_result >= 0 )
924 if ( !strncmp(cache_filename,
"pfs", 3) )
926 cache_remove_result = remove(cache_filename);
928 else if ( !strncmp(cache_filename,
"host", 4) )
930 cache_remove_result = 0;
931 remove(cache_filename);
933 VERBOSE_KPRINTF(1,
"Cache File %s remove: %d\n", cache_filename, cache_remove_result);
936 fh->m_cache_file_fd = -1;
937 fh->m_max_cluster = 0;
938 fh->m_cluster_cur = -1;
939 fh->m_sector_count_total = 0;
941 FreeSysMemory(fh->m_fd_rcvbuf);
944 if ( cache_result < 0 )
946 VERBOSE_KPRINTF(1,
"cdvd_odcinit Open Error %d\n", cache_result);
948 if ( cache_remove_result < 0 )
950 VERBOSE_KPRINTF(1,
"cdvd_odcinit Close Error %d\n", cache_remove_result);
952 return (!open_or_close) ? cache_remove_result : cache_result;
954 fh->m_sector_count_total = file_size_bsr_17 << 11;
955 fh->m_cache_file_fd = cache_file_fd_new;
956 fh->m_max_cluster = (
void *)file_size_bsr_3;
957 fh->m_cluster_cur = -1;
958 VERBOSE_KPRINTF(1,
"Cache File Maked\n");
967 if ( fh->m_cluster_cur == -1 )
971 fh->m_cluster_cur = -1;
972 for ( i = 0; i < fh->m_fd_rbsize; i += 1 )
974 fh->m_fd_rcvbuf[i] = 0;
976 fileio_res = lseek(fh->m_cache_file_fd, 0, 0);
977 if ( fileio_res >= 0 )
979 for ( i = 0; i < ((
unsigned int)fh->m_sector_count_total >> 11); i += 1 )
981 fileio_res = write(fh->m_cache_file_fd, fh->m_fd_rcvbuf, 0x800);
982 if ( fileio_res < 0 )
988 if ( fileio_res >= 0 )
992 fh->m_fd_flags &= ~4;
993 cdvd_odcinit(fh, 0, index);
997 static int cdvdman_invcaches(
void)
1001 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
1003 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 4) )
1005 cdvdman_cache_invalidate(&g_cdvdman_fhinfo[i], i);
1011 static int cdrom_internal_cache_read(
const iop_file_t *f,
int nbytes)
1014 s16 readpos_plus_nbytes;
1015 unsigned int readpos_plus_nbytes_bsr_14;
1020 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1021 if ( cdvdman_devready() < 0 )
1023 g_cdvdman_iocache = 0;
1026 if ( fh->m_cluster_cur == -1 )
1028 if ( (
void *)(8 * fh->m_fd_rbsize) < fh->m_max_cluster )
1030 fh->m_cluster_cur = (fh->m_read_pos >> 14) & ~0x7;
1032 lseek(fh->m_cache_file_fd, fh->m_cluster_cur >> 3, 0) < 0
1033 || read(fh->m_cache_file_fd, fh->m_fd_rcvbuf, fh->m_fd_rbsize) < 0 )
1035 fh->m_cluster_cur = -1;
1041 fh->m_cluster_cur = -2;
1044 readpos_plus_nbytes = fh->m_read_pos + nbytes;
1045 readpos_plus_nbytes_bsr_14 = (readpos_plus_nbytes >> 14) - (!(readpos_plus_nbytes & 0x3FFF));
1046 readpos_bsr_14 = fh->m_read_pos >> 14;
1048 1,
"max_claster %d meta_size_clst %d claster_cur %d\n", fh->m_max_cluster, 8 * fh->m_fd_rbsize, fh->m_cluster_cur);
1049 cluster_cur = fh->m_cluster_cur;
1050 if ( cluster_cur < 0 )
1055 (
unsigned int)readpos_bsr_14 < (
unsigned int)cluster_cur
1056 || readpos_plus_nbytes_bsr_14 >= cluster_cur + 8 * fh->m_fd_rbsize )
1058 int cluster_write_tmp2;
1059 unsigned int readpos_band;
1061 if ( lseek(fh->m_cache_file_fd, cluster_cur >> 3, 0) < 0 )
1063 fh->m_cluster_cur = -1;
1066 cluster_write_tmp2 = (
unsigned int)fh->m_max_cluster >= fh->m_cluster_cur + 8 * fh->m_fd_rbsize ?
1068 ((
unsigned int)fh->m_max_cluster - fh->m_cluster_cur + 7) >> 3;
1069 if ( write(fh->m_cache_file_fd, fh->m_fd_rcvbuf, cluster_write_tmp2) != cluster_write_tmp2 )
1071 fh->m_cluster_cur = -1;
1074 readpos_band = readpos_bsr_14 & ~0x7;
1075 fh->m_cluster_cur = readpos_band;
1076 readpos_band += (readpos_bsr_14 < 0) ? 7 : 0;
1077 if ( (lseek(fh->m_cache_file_fd, readpos_band >> 3, 0) < 0) || (read(fh->m_cache_file_fd, fh->m_fd_rcvbuf, ( (
unsigned int)fh->m_max_cluster < fh->m_cluster_cur + 8 * fh->m_fd_rbsize ) ? (((
unsigned int)fh->m_max_cluster - fh->m_cluster_cur + 7) >> 3) : (fh->m_fd_rbsize)) < 0) )
1079 fh->m_cluster_cur = -1;
1082 cluster_cur = fh->m_cluster_cur;
1084 for ( i = readpos_bsr_14; i <= readpos_plus_nbytes_bsr_14; i += 1 )
1086 if ( !(((
int)fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] >> ((i - cluster_cur) & 7)) & 1) )
1091 return i <= readpos_plus_nbytes_bsr_14;
1094 static int cdrom_internal_write_cache(
const iop_file_t *f,
unsigned int nbytes)
1107 g_cdvdman_iocache = 0;
1108 if ( cdvdman_devready() < 0 )
1112 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1113 if ( nbytes > fh->m_file_size - fh->m_read_pos )
1115 nbytes = fh->m_file_size - fh->m_read_pos;
1121 VERBOSE_KPRINTF(1,
"_cdvdfile_cache_read %d<->%d\n", fh->m_read_pos, fh->m_read_pos + nbytes);
1122 cur = ((fh->m_read_pos + nbytes) >> 14) - (!((fh->m_read_pos + nbytes) & 0x3FFF));
1123 rst = fh->m_read_pos >> 14;
1124 cluster_cur = (fh->m_cluster_cur >= 0) ? fh->m_cluster_cur : 0;
1125 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1127 VERBOSE_KPRINTF(1,
"cache_fill rst:%d<->%d cur:%d cnt:%d\n", rst, cur, fh->m_read_pos, nbytes);
1128 for ( i = rst; i <= cur; i += 1 )
1132 "FIO Usr addr LSN:%d SEC:%d ADDR:%08x cpos= %d\n",
1133 fh->m_file_lsn + 8 * i,
1135 g_cdvdman_temp_buffer_ptr,
1136 (i * 0x4000) + fh->m_sector_count_total);
1137 if ( !(((
int)fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] >> ((i - cluster_cur) & 7)) & 1) )
1140 while ( !
sceCdRE(fh->m_file_lsn + 8 * i, 8, g_cdvdman_temp_buffer_ptr, &rmode) )
1144 g_cdvdman_iocache = 0;
1152 if ( last_err !=
SCECdErNO || tray_open )
1155 VERBOSE_KPRINTF(0,
"Read Error= 0x%02x Tray open %d\n", last_err, tray_open);
1158 lseek_result = lseek(fh->m_cache_file_fd, (i * 0x4000) + fh->m_sector_count_total, 0);
1159 if ( lseek_result < 0 )
1161 return lseek_result;
1163 write_ret = write(fh->m_cache_file_fd, g_cdvdman_temp_buffer_ptr, 0x4000);
1164 if ( write_ret != 0x4000 )
1166 VERBOSE_KPRINTF(1,
"write: ret:%d\n", write_ret);
1167 if ( write_ret >= 0 )
1173 fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] |= 1 << ((i - cluster_cur) & 7);
1179 static int cdvdfile_cache_read(
const iop_file_t *f,
void *buf,
int nbyte)
1189 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1191 ((
unsigned int)nbyte > fh->m_file_size - fh->m_read_pos) ? fh->m_file_size - fh->m_read_pos : (
unsigned int)nbyte;
1192 VERBOSE_KPRINTF(1,
"_cdvdfile_cache_read %d<->%d\n", fh->m_read_pos, fh->m_read_pos + nbyte_tmp);
1194 if ( nbyte_tmp > 0 )
1196 fd_result = lseek(fh->m_cache_file_fd, fh->m_read_pos + fh->m_sector_count_total, 0);
1197 if ( fd_result >= 0 )
1199 fd_result = read(fh->m_cache_file_fd, buf, nbyte_tmp);
1200 fh->m_read_pos += (fd_result >= 0) ? fd_result : 0;
1206 static int cdvdfile_cache_fill_read(
const iop_file_t *f,
void *buf,
int nbytes)
1210 op_result = cdvdman_devready();
1211 if ( op_result >= 0 )
1213 op_result = cdrom_internal_write_cache(f, nbytes);
1217 g_cdvdman_iocache = 0;
1219 if ( op_result >= 0 )
1221 op_result = cdvdfile_cache_read(f, buf, nbytes);
1226 static int cdrom_open(
iop_file_t *f,
const char *name,
int mode,
int arg4)
1241 VERBOSE_PRINTF(1,
"fileIO OPEN name= %s mode= 0x%08x layer %d\n", name, mode, f->
unit);
1242 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1245 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
1247 if ( !g_cdvdman_fhinfo[i].m_fd_flags && !emptyfdfound )
1252 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 8) )
1257 if ( !emptyfdfound || streamfdfound )
1259 PRINTF(
"open fail name %s\n", name);
1260 SetEventFlag(g_fio_fsv_evfid, 1);
1264 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1265 strncpy(filename, name,
sizeof(filename));
1266 cdvdman_cdfname(filename);
1267 g_cdvdman_srchspd = (!(mode & 0x40000000) && !cdvdman_l0check(f->
unit)) ?
1268 ((g_cdvdman_spinnom == -1) ? (u16)mode : g_cdvdman_spinnom !=
SCECdSpinStm) :
1270 if ( (
unsigned int)(f->
unit) >= 2u )
1276 if ( !strncmp(name,
"sce_cdvd_lsn", 12) )
1278 strncpy(filename, name,
sizeof(filename));
1280 for ( i = 12; i < (
sizeof(filename) - 5) && filename[i] && filename[i] !=
'_'; i += 1 )
1282 if ( !filename[i] || i >= (
sizeof(filename) - 5) )
1288 fp.size = strtol(&filename[i + 5], 0, 10);
1290 fp.lsn = strtol(&filename[12], 0, 10);
1293 if ( cdvdman_devready() < 0 || !DvdDual_infochk() )
1299 fp.lsn += g_cdvdman_istruct.m_layer_1_lsn;
1304 #ifdef CDVD_VARIANT_OSD
1305 else if ( !strcmp(filename,
"sce_dev5;1") )
1313 devready_tmp = cdvdman_devready();
1314 if ( devready_tmp < 0 )
1316 SetEventFlag(g_fio_fsv_evfid, 1);
1317 return devready_tmp;
1325 if ( devready_tmp < 0 )
1327 PRINTF(
"open fail name %s\n", filename);
1328 SetEventFlag(g_fio_fsv_evfid, 1);
1329 return devready_tmp;
1332 g_cdvdman_srchspd = 0;
1333 if ( (mode & 0x40000000) )
1336 memset(&rmode, 0,
sizeof(rmode));
1339 rmode.
trycount = (g_cdvdman_trycnt != -1) ? g_cdvdman_trycnt : 0;
1344 SetEventFlag(g_fio_fsv_evfid, 1);
1347 g_cdvdman_strmerr = 0;
1348 fh->m_fd_flags |= 8;
1350 fh->m_file_lsn = fp.lsn;
1352 fh->m_filemode = mode & ~0x40000000;
1353 fh->m_file_size = fp.size;
1354 fh->m_fd_layer = f->
unit;
1355 if ( (mode & 0x50000000) == 0x10000000 )
1358 if ( g_cache_path_fd != -1 )
1360 devready_tmp = cdvd_odcinit(fh, 1, (
int)f->
privdata);
1361 if ( devready_tmp >= 0 )
1363 fh->m_fd_flags |= 4;
1367 if ( devready_tmp < 0 )
1373 fh->m_file_size = 0;
1375 SetEventFlag(g_fio_fsv_evfid, 1);
1376 return devready_tmp;
1380 VERBOSE_KPRINTF(1,
"open end file_lbn= %d size= %d fds= %d\n", fh->m_file_lsn, fh->m_file_size, fds1);
1381 SetEventFlag(g_fio_fsv_evfid, 1);
1390 VERBOSE_PRINTF(1,
"fileIO CLOSE\n");
1391 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1392 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1393 if ( (fh->m_fd_flags & 8) )
1395 g_cdvdman_strmerr = 0;
1399 SetEventFlag(g_fio_fsv_evfid, 1);
1403 if ( ((fh->m_fd_flags & 0xC) == 4 && cdvd_odcinit(fh, 0, (
int)f->
privdata) < 0) )
1405 SetEventFlag(g_fio_fsv_evfid, 1);
1409 fh->m_file_size = 0;
1415 SetEventFlag(g_fio_fsv_evfid, 1);
1419 static int cdrom_internal_read(
const iop_file_t *f,
char *addr,
int nbytes)
1421 unsigned int sectors;
1424 int nbytes_div_2048;
1426 unsigned int sectors_count;
1430 unsigned int filesize_bsr_11;
1435 VERBOSE_PRINTF(1,
"cdvd fileIO read start\n");
1436 op_result = cdvdman_devready();
1437 if ( op_result < 0 )
1439 g_cdvdman_iocache = 0;
1442 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1443 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1448 if ( (
unsigned int)nbytes > fh->m_file_size - fh->m_read_pos )
1450 nbytes = fh->m_file_size - fh->m_read_pos;
1452 filesize_bsr_11 = (fh->m_file_size >> 11) + (!!((fh->m_file_size & 0x7FF))) + fh->m_file_lsn;
1454 1,
"fds= %d read file_lbn= %d offset= %d\n", (
int)(uiptr)f->
privdata, (
int)fh->m_file_lsn, (int)fh->m_read_pos);
1456 for ( i = 0; i < nbytes; i += nbytes_segment )
1464 nbytes_cur = nbytes - i;
1465 if ( g_cdvdman_spinctl != -1 )
1468 switch ( g_cdvdman_spinctl )
1494 lbn = fh->m_file_lsn + ((fh->m_read_pos + i) >> 11);
1496 pos_extra = (fh->m_read_pos + i) & 0x7FF;
1497 if ( nbytes_cur <= 0x4000 )
1499 nbytes_segment = nbytes_cur;
1500 nbytes_div_2048 = (nbytes_cur / 0x800) + (!!((nbytes_cur & 0x7FF)));
1501 sectors = nbytes_div_2048 + (!!pos_extra);
1505 nbytes_segment = 0x4000;
1506 if ( buf && ((fh->m_read_pos + i) & 0x7FF) && g_cdvdman_iocache )
1509 pos_sub_2048 = 0x800 - pos_extra;
1511 &addr[i], &((
const char *)g_cdvdman_temp_buffer_ptr)[0x800 * (sectors - 1) + pos_extra], 0x800 - pos_extra);
1512 g_cdvdman_iocache = 0;
1517 sectors = 8 + (!!(((fh->m_read_pos + i) & 0x7FF)));
1520 buf = g_cdvdman_temp_buffer_ptr;
1521 if ( (
unsigned int)(sectors) > filesize_bsr_11 - lbn )
1523 sectors = filesize_bsr_11 - lbn;
1525 VERBOSE_PRINTF(1,
"sce_Read LBN= %d sectors= %d\n", (
int)lbn, (
int)sectors);
1527 g_cdvdman_iocache && (lbn >= g_cdvdman_lcn_offset)
1528 && (g_cdvdman_lcn_offset + g_cdvdman_numbytes_offset >= lbn + sectors) )
1530 optimized_memcpy(&addr[i], &((
char *)buf)[0x800 * (lbn - g_cdvdman_lcn_offset) + pos_extra], nbytes_segment);
1532 else if ( ((uiptr)(addr + i) & 3) || pos_extra || (nbytes_segment != 0x4000) )
1534 sec = (sectors >= 8) ? sectors : 8;
1535 if ( sec > filesize_bsr_11 - lbn )
1537 sec = filesize_bsr_11 - lbn;
1539 VERBOSE_PRINTF(1,
"FIO Cache LSN:%d SEC:%d ADDR:%08x\n", (
int)lbn, (
int)sec, (
unsigned int)(uiptr)buf);
1540 sectors_count = (sec >= 9) ? (sec - 8) : 0;
1541 if ( sectors_count )
1543 while ( !
sceCdRE(lbn, sectors_count, buf, &rmode) )
1545 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1548 g_cdvdman_iocache = 0;
1549 g_cdvdman_spinctl = -1;
1558 PRINTF(
"Read Error= 0x%02x\n", last_err);
1559 g_cdvdman_iocache = 0;
1563 while ( !
sceCdRE(lbn + sectors_count, sec - sectors_count, (
char *)buf + 0x800 * sectors_count, &rmode) )
1565 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1568 g_cdvdman_iocache = 0;
1569 g_cdvdman_spinctl = -1;
1578 PRINTF(
"Read Error= 0x%02x\n", last_err);
1579 g_cdvdman_iocache = 0;
1582 g_cdvdman_lcn_offset = lbn_tmp;
1583 g_cdvdman_numbytes_offset = sec;
1584 g_cdvdman_iocache = 1;
1586 &addr[pos_sub_2048 + i],
1587 &((
const char *)g_cdvdman_temp_buffer_ptr)[!pos_sub_2048 ? pos_extra : 0],
1588 nbytes_segment - pos_sub_2048);
1593 1,
"FIO Usr addr LSN:%d SEC:%d ADDR:%08x\n", (
int)lbn, (
int)sectors, (
unsigned int)(uiptr)(addr + i));
1594 while ( !
sceCdRE(lbn, sectors, addr + i, &rmode) )
1596 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1599 g_cdvdman_iocache = 0;
1600 g_cdvdman_spinctl = -1;
1607 g_cdvdman_iocache = 0;
1610 PRINTF(
"Read Error= 0x%02x\n", last_err);
1614 if ( nbytes_segment <= 0 )
1616 g_cdvdman_spinctl = -1;
1617 return nbytes_segment;
1620 fh->m_read_pos += i;
1621 VERBOSE_PRINTF(1,
"fileIO read ended\n");
1622 g_cdvdman_spinctl = -1;
1626 static int cdrom_stream_read(
const iop_file_t *f,
char *bbuf,
int nbytes)
1632 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1633 g_cdvdman_strmerr = 0;
1634 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1639 fh->m_read_pos += buf << 11;
1644 static int cdrom_read(
iop_file_t *f,
void *buf,
int nbytes)
1654 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1655 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1656 if ( cdvdman_mediactl(2) )
1658 g_cdvdman_iocache = 0;
1659 cdvdman_invcaches();
1661 if ( (fh->m_fd_flags & 8) )
1663 rc = cdrom_stream_read(f, (
char *)buf, nbytes);
1667 if ( !(fh->m_fd_flags & 4) )
1669 rc = cdrom_internal_read(f, (
char *)buf, nbytes);
1673 rc = cdrom_internal_cache_read(f, nbytes);
1680 fh->m_fd_flags &= ~4;
1682 cdvd_odcinit(fh, 0, (
int)f->
privdata);
1686 rc = cdvdfile_cache_fill_read(f, buf, nbytes);
1687 VERBOSE_KPRINTF(1,
"called _cdvdfile_cache_fill_read %d\n", rc);
1693 rc = cdvdfile_cache_read(f, buf, nbytes);
1694 VERBOSE_KPRINTF(1,
"called _cdvdfile_cache_read %d\n", rc);
1698 cdvdman_cache_invalidate(fh, (
int)f->
privdata);
1699 KPRINTF(
"_cdvdfile_cache Read_err OR Drive_not_ready\n", rc);
1703 rc = cdrom_internal_read(f, (
char *)buf, nbytes);
1707 SetEventFlag(g_fio_fsv_evfid, 1);
1711 static int cdrom_ioctl(
iop_file_t *f,
int arg,
void *param)
1713 #ifdef CDVD_VARIANT_OSD
1714 USE_IOP_MMIO_HWPORT();
1721 #ifdef CDVD_VARIANT_OSD
1729 if ( *(u32 *)param )
1731 *(u32 *)&iop_mmio_hwport->sio2.unused[0] |= 1;
1735 *(u32 *)&iop_mmio_hwport->sio2.unused[0] &= ~1;
1739 return get_mips_cop_reg(0,
COP0_REG_PRId) >= 35 ? (int)( *(u32 *)&iop_mmio_hwport->sio2.unused[0] & 1) : -22;
1742 g_cdvdman_spinnom = -1;
1745 #ifdef CDVD_VARIANT_OSD
1747 sceCdDecSet(*(u32 *)param, *((u32 *)param + 1), *((u32 *)param + 2));
1750 return sceCdReadKey(*(u32 *)param, *((u32 *)param + 1), *((u32 *)param + 2), (u8 *)param + 12) ? 1 : -16;
1760 static int cdrom_ioctl2(
iop_file_t *f,
int request,
void *argp,
size_t arglen,
void *bufp,
size_t buflen)
1771 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1772 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1774 if ( (fh->m_fd_flags & 8) )
1778 case CIOCSTREAMPAUSE:
1785 case CIOCSTREAMRESUME:
1792 case CIOCSTREAMSTAT:
1801 SetEventFlag(g_fio_fsv_evfid, 1);
1806 cdrom_devctl(
iop_file_t *f,
const char *name,
int cmd,
void *argp,
unsigned int arglen,
void *bufp,
unsigned int buflen)
1811 unsigned int sc_tmp_3;
1821 if ( cmd != CDIOC_BREAK )
1823 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1827 case CDIOC_READCLOCK:
1828 for ( i = 0; i < 3 && !retval2; i += 1 )
1830 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1833 retval2 = (retval2 != 1) ? -
EIO : 0;
1835 #ifdef CDVD_VARIANT_DNAS
1837 for ( i = 0; i < 3 && !retval2; i += 1 )
1839 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1842 retval2 = (retval2 != 1) ? -
EIO : 0;
1848 case CDIOC_GETDISKTYP:
1851 case CDIOC_GETERROR:
1852 *(u32 *)bufp = g_cdvdman_strmerr ? g_cdvdman_strmerr :
sceCdGetError();
1860 case CDIOC_POWEROFF:
1861 for ( i = 0; i < 3 && !retval2; i += 1 )
1863 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1866 retval2 = (retval2 != 1) ? -
EIO : 0;
1874 #ifdef CDVD_VARIANT_DNAS
1876 for ( i = 0; i < 3 && !retval2; i += 1 )
1878 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1881 retval2 = (retval2 != 1) ? -
EIO : 0;
1884 case CDIOC_STREAMINIT:
1886 retval2 = (!
sceCdStInit(*(u32 *)argp, *((u32 *)argp + 1), (
void *)*((u32 *)argp + 2))) ? -
EIO : 0;
1892 #ifdef CDVD_VARIANT_XOSD
1894 sc_tmp_3 = *(u32 *)argp;
1895 retval2 = (sc_tmp_3 - 4 >= 0x15) ? -22 : sceCdSC(0xFFFFFFDD, (
int *)&sc_tmp_3);
1905 g_cdvdman_trycnt = *(u8 *)argp;
1936 case CDIOC_SETTIMEOUT:
1939 case CDIOC_READDVDDUALINFO:
1962 *(u32 *)bufp = sceCdSC(0xFFFFFFF5, &scres_unused);
1965 retval2 = (
sceCdApplySCmd(*(u8 *)argp, (
char *)argp + 4, arglen - 4, bufp) != 1) ? -
EIO : 0;
1967 case CDIOC_FSCACHEINIT:
1969 if ( g_cache_path_fd != -1 )
1974 sc_tmp_2 = (
char *)argp;
1975 for ( i = 0; i < arglen && sc_tmp_2[i] && sc_tmp_2[i] !=
','; i += 1 )
1977 g_cdvdman_cache_name[i] = sc_tmp_2[i];
1983 for ( ; (i < arglen) && sc_tmp_2[i] && sc_tmp_2[i] !=
','; i += 1 )
1990 g_cdvdman_cache_sector_size_count = strtol((
const char *)argp + sc_tmp_3, 0, 10);
1991 retval2 = path_tbl_init(strtol(&sc_tmp_2[i + 1], 0, 10), g_cdvdman_cache_name, 1);
1994 case CDIOC_FSCACHEDELETE:
1995 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
1997 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 4) )
2002 retval2 = (i == (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0]))) ? path_tbl_init(0, 0, 0) : -
EBUSY;
2008 if ( cmd != CDIOC_BREAK )
2010 SetEventFlag(g_fio_fsv_evfid, 1);
2016 static int cdrom_lseek(
iop_file_t *f,
int offset,
int pos)
2023 VERBOSE_PRINTF(1,
"fileIO SEEK\n");
2024 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
2025 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
2032 retval = fh->m_read_pos + offset;
2035 retval = fh->m_file_size - offset;
2040 if ( retval > (
int)(fh->m_file_size) )
2042 retval = fh->m_file_size;
2044 fh->m_read_pos = retval;
2045 if ( (fh->m_fd_flags & 8) )
2053 SetEventFlag(g_fio_fsv_evfid, 1);
2057 static unsigned int sync_timeout_alarm_cb(
void *userdata)
2062 KPRINTF(
"Cdvd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
2068 if ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2075 g_cdvdman_sync_timeout = timeout;
2078 g_cdvdman_stream_timeout = timeout;
2091 VERBOSE_KPRINTF(1,
"sceCdSync: Call mode %d Com %x\n", mode, (u8)g_cdvdman_istruct.m_cdvdman_command);
2095 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2097 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2101 return !!(!sceCdCheckCmd() || (g_cdvdman_istruct.m_read2_flag));
2104 sysclk.lo = 0x9000 * g_cdvdman_sync_timeout;
2105 vSetAlarm(&sysclk, sync_timeout_alarm_cb, &sysclk);
2106 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2108 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2110 vCancelAlarm(sync_timeout_alarm_cb, &sysclk);
2114 sysclk.lo = 0x41EB0000;
2115 vSetAlarm(&sysclk, sync_timeout_alarm_cb, &sysclk);
2116 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2118 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2120 vCancelAlarm(sync_timeout_alarm_cb, &sysclk);
2123 while ( !sceCdCheckCmd() )
2125 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2130 sysclk.lo = 0x9000 * g_cdvdman_sync_timeout;
2131 vSetAlarm(&sysclk, sync_timeout_alarm_cb, &sysclk);
2132 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2134 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2136 vCancelAlarm(sync_timeout_alarm_cb, &sysclk);
2139 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag || g_cdvdman_ee_rpc_fno
2140 || g_cdvdman_istruct.m_stream_flag )
2142 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2143 if ( g_cdvdman_ee_rpc_fno )
2151 !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag || g_cdvdman_ee_rpc_fno
2152 || (g_cdvdman_istruct.m_stream_flag));
2154 WaitEventFlag(g_cdvdman_intr_evfid, 0x21, WEF_OR, &efbits);
2155 ReferEventFlagStatus(g_cdvdman_intr_evfid, &efinfo);
2158 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
2160 SetEventFlag(g_cdvdman_intr_evfid, 0x20);
2164 WaitEventFlag(g_cdvdman_intr_evfid, 0x20, WEF_AND, &efbits);
2169 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2171 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2177 "sceCdSync: Command= %d Error= %d\n",
2178 (u8)g_cdvdman_istruct.m_cdvdman_command,
2179 (u8)g_cdvdman_istruct.m_last_error);
2185 VERBOSE_KPRINTF(1,
"sceCdSpinCtrlIOP speed= %d\n", speed);
2186 g_cdvdman_spinctl = speed;
2196 if ( PollEventFlag(g_sfile_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
2200 for ( i = 0; i < ((
sizeof(g_cdvdman_sfname) /
sizeof(g_cdvdman_sfname[0])) - 1) && path[i]; i += 1 )
2202 g_cdvdman_sfname[i] = path[i];
2204 g_cdvdman_sfname[i] = 0;
2205 g_cdvdman_srchspd = 1;
2207 vSetEventFlag(g_sfile_evfid, 1);
2218 return cdvdman_gettoc(
toc);
2224 USE_DEV5_MMIO_HWPORT();
2228 VERBOSE_KPRINTF(1,
"DISK READY call from iop %d\n", mode);
2229 #ifdef CDVD_VARIANT_XOSD
2230 if ( g_cdvdman_istruct.m_cd_mode_ps2_atapi == 1 )
2232 return mode == 8 ? -1 : 6;
2234 switch ( get_disk_type_ex() )
2246 VERBOSE_KPRINTF(1,
"Wait Drive Ready %x\n", dev5_mmio_hwport->m_dev5_reg_005);
2247 while ( g_cdvdman_istruct.m_read2_flag )
2250 #ifdef CDVD_VARIANT_XOSD
2251 switch ( get_disk_type_ex() )
2258 case SCECdDETCTDVDS:
2259 case SCECdDETCTDVDD:
2260 while ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) != 0x40 )
2263 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2264 #ifdef CDVD_VARIANT_XOSD
2265 if ( !get_disk_type_ex() )
2278 VERBOSE_KPRINTF(1,
"Wait Exit\n");
2281 return (u8)dev5_mmio_hwport->m_dev5_reg_005;
2284 if ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) == 0x40 && !g_cdvdman_istruct.m_read2_flag )
2288 VERBOSE_KPRINTF(1,
"Drive Not Ready\n");
2295 #ifdef CDVD_VARIANT_XOSD
2298 VERBOSE_KPRINTF(1,
"sceCdGetDiskType Call\n");
2299 cdvd_register = get_cdvd_register(0x0F);
2300 VERBOSE_KPRINTF(1,
"sceCdGetDiskType 0x%02x\n", cdvd_register);
2301 return cdvd_register;
2303 USE_DEV5_MMIO_HWPORT();
2305 return (u8)dev5_mmio_hwport->m_dev5_reg_00F;
2309 #ifdef CDVD_VARIANT_XOSD
2310 static int get_disk_type_ex(
void)
2315 USE_DEV5_MMIO_HWPORT();
2322 retval = (g_cdvdman_istruct.m_cd_mode_ps2_atapi == 1) ? 257 : dev5_mmio_hwport->m_dev5_reg_00F;
2331 #ifdef CDVD_VARIANT_XOSD
2334 int wakeup_reason_reg;
2336 VERBOSE_KPRINTF(1,
"sceCdGetWakeUpReason Call\n");
2337 wakeup_reason_reg = get_cdvd_register(0x15);
2338 if ( wakeup_reason_reg != -1 )
2340 wakeup_reason_reg &= 0xF;
2342 VERBOSE_KPRINTF(1,
"sceCdGetWakeUpReason 0x%02x\n", wakeup_reason_reg);
2343 return wakeup_reason_reg;
2350 #ifndef CDVD_VARIANT_XOSD
2353 #ifndef CDVD_VARIANT_XOSD
2354 USE_DEV5_MMIO_HWPORT();
2357 #ifdef CDVD_VARIANT_XOSD
2358 reg_00A_tmp = get_cdvd_register(0x0A);
2360 reg_00A_tmp = dev5_mmio_hwport->m_dev5_reg_00A;
2362 #ifndef CDVD_VARIANT_XOSD
2368 if ( !g_cdvdman_istruct.m_tray_is_open && cdvdman_scmd_sender_03_30(&rdata_tmp, &status_tmp) == 1 && !status_tmp )
2371 if ( (rdata_tmp & 8) )
2376 if ( (reg_00A_tmp & 0x1E) )
2382 if ( g_cdvdman_istruct.m_use_toc )
2386 if ( g_cdvdman_istruct.m_power_flag )
2393 #ifdef CDVD_VARIANT_OSD
2396 USE_DEV5_MMIO_HWPORT();
2398 return !g_cdvdman_istruct.m_power_flag ? (u8)dev5_mmio_hwport->m_dev5_reg_00A : -1;
2404 p->sector = 16 * ((i + 150) % 75 / 10) + (i + 150) % 75 % 10;
2405 p->second = 16 * ((i + 150) / 75 % 60 / 10) + (i + 150) / 75 % 60 % 10;
2406 p->minute = 16 * ((i + 150) / 75 / 60 / 10) + (i + 150) / 75 / 60 % 10;
2413 return 75 * (60 * (10 * (p->minute >> 4) + (p->minute & 0xF)) + 10 * (p->second >> 4) + (p->second & 0xF))
2414 + 10 * (p->sector >> 4) + (p->sector & 0xF) - 150;
2417 #ifdef CDVD_VARIANT_DNAS
2418 static int read_id_from_rom(
int mode,
int *buf)
2428 for ( i = 0; i < (
sizeof(idinfo) /
sizeof(idinfo[0])); i += 1 )
2430 for ( j = 0; j <
sizeof(chksumstk); j += 1 )
2432 ((
char *)&idinfo)[(i * 4) + j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2433 ((
char *)&chksumstk)[j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2435 chksumint += chksumstk;
2437 for ( ; i < 0x4000; i += 1 )
2439 for ( j = 0; j <
sizeof(chksumstk); j += 1 )
2441 ((
char *)&chksumstk)[j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2443 chksumint += chksumstk;
2447 KPRINTF(
"# checksum error %d\n", chksumint);
2462 static int query_boot_mode_6_nonzero(
void)
2466 BootMode = QueryBootMode(6);
2467 return !(!BootMode || (*(u16 *)BootMode & 0xFFFC) != 0x60);
2470 static int query_boot_mode_6_zero(
void)
2472 return !QueryBootMode(6);
2475 static int cdvdman_readID(
int mode,
int *buf)
2482 if ( query_boot_mode_6_nonzero() )
2484 if ( read_id_from_rom(mode, buf) && mode == 1 )
2496 if ( query_boot_mode_6_zero() )
2498 if ( !
sceCdRI(id_val, &id_result) || id_result )
2505 if ( !g_readid_systemtime.lo && !g_readid_systemtime.hi )
2507 GetSystemTime(&sysclk);
2508 g_readid_systemtime = sysclk;
2514 *buf = *(u32 *)id_val >> 8;
2518 *buf = id_val[0] | 0x8004600;
2519 buf[1] = *(u32 *)&id_val[4];
2527 return cdvdman_readID(0, (
int *)guid);
2532 return cdvdman_readID(1, (
int *)
id);
2536 int sceCdStInit(u32 bufmax, u32 bankmax,
void *buffer)
2542 VERBOSE_KPRINTF(1,
"sceCdStInit call IOP\n");
2543 memset(&devctl_req, 0,
sizeof(devctl_req));
2544 devctl_req.m_cmdid = 5;
2545 devctl_req.m_posszarg1 = bufmax;
2546 devctl_req.m_posszarg2 = bankmax;
2547 devctl_req.m_buffer = buffer;
2548 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2558 VERBOSE_KPRINTF(1,
"sceCdStStart call IOP\n");
2559 memset(&devctl_req, 0,
sizeof(devctl_req));
2560 devctl_req.m_rmode.
datapattern = mode->datapattern;
2561 devctl_req.m_rmode.
spindlctrl = mode->spindlctrl;
2562 devctl_req.m_cmdid = 1;
2563 devctl_req.m_posszarg1 = lbn;
2564 devctl_req.m_rmode.
trycount = mode->trycount;
2565 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2574 VERBOSE_KPRINTF(1,
"sceCdStSeekF call IOP\n");
2575 memset(&devctl_req, 0,
sizeof(devctl_req));
2576 devctl_req.m_cmdid = 9;
2577 devctl_req.m_posszarg1 = lsn;
2578 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2587 VERBOSE_KPRINTF(1,
"sceCdStSeek call IOP\n");
2588 memset(&devctl_req, 0,
sizeof(devctl_req));
2589 devctl_req.m_posszarg1 = lbn;
2590 devctl_req.m_cmdid = 4;
2591 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2600 VERBOSE_KPRINTF(1,
"sceCdStStop call IOP\n");
2601 memset(&devctl_req, 0,
sizeof(devctl_req));
2602 devctl_req.m_cmdid = 3;
2603 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2606 int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
2614 VERBOSE_KPRINTF(1,
"sceCdStRead call IOP\n");
2615 memset(&devctl_req, 0,
sizeof(devctl_req));
2616 devctl_req.m_cmdid = 1;
2617 devctl_req.m_posszarg2 = sectors;
2618 devctl_req.m_buffer = buffer;
2619 if ( devctl(
"cdrom_stm0:", 0x4394, &devctl_req,
sizeof(devctl_req), &buf, 4) < 0 )
2623 *error = devctl_req.m_error;
2633 VERBOSE_KPRINTF(1,
"sceCdStPause call IOP\n");
2634 memset(&devctl_req, 0,
sizeof(devctl_req));
2635 devctl_req.m_cmdid = 7;
2636 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2645 VERBOSE_KPRINTF(1,
"sceCdStResume call IOP\n");
2646 memset(&devctl_req, 0,
sizeof(devctl_req));
2647 devctl_req.m_cmdid = 8;
2648 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2657 VERBOSE_KPRINTF(1,
"sceCdStStat call IOP\n");
2658 memset(&devctl_req, 0,
sizeof(devctl_req));
2659 devctl_req.m_cmdid = 6;
2660 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2670 VERBOSE_PRINTF(1,
"CdSearchFile: start name= %s layer= %d\n", name, layer);
2671 if ( g_cdvdman_fs_layer != layer )
2673 g_cdvdman_fs_cache = 0;
2675 if ( !cdvdman_mediactl(0) && g_cdvdman_fs_cache )
2677 VERBOSE_KPRINTF(1,
"CdSearchFile: cache dir data used\n");
2681 VERBOSE_PRINTF(1,
"CdSearchFile Topen= %s\n", name);
2682 if ( !CD_newmedia(layer) )
2684 g_cdvdman_fs_cache = 0;
2687 g_cdvdman_fs_cache = 1;
2689 if ( *name !=
'\\' )
2696 for ( i = 0; i < 8 && name[i]; i += 1 )
2698 for ( j = 0; name[i + j] !=
'\\'; j += 1 )
2700 name_buf[j] = name[i + j];
2703 parent_level = cdvdman_finddir(parent_level, name_buf);
2704 if ( parent_level == -1 )
2712 VERBOSE_PRINTF(1,
"%s: path level (%d) error\n", name, i);
2717 VERBOSE_PRINTF(1,
"%s: dir was not found\n", name);
2721 if ( !CD_cachefile(parent_level, layer) )
2723 VERBOSE_PRINTF(1,
"CdSearchFile: disc error\n");
2726 VERBOSE_PRINTF(2,
"CdSearchFile: searching %s...\n", name_buf);
2728 j < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0])) && g_cdvdman_filetbl[j].m_file_struct.name[0];
2731 VERBOSE_PRINTF(1,
"%d %s %s\n", (
int)j, g_cdvdman_filetbl[j].m_file_struct.name, name_buf);
2732 if ( cdvdman_cmpname(g_cdvdman_filetbl[j].m_file_struct.name, name_buf) )
2734 VERBOSE_PRINTF(2,
"%s:\t found\n", name_buf);
2737 fp->m_file_struct.lsn += layer ? g_cdvdman_fs_base2 : 0;
2741 VERBOSE_PRINTF(1,
"%s: not found\n", name_buf);
2745 static int sceCdSearchDir(
char *dirname,
int layer)
2749 VERBOSE_PRINTF(1,
"_sceCdSearchDir: dir name %s layer %d\n", dirname, layer);
2753 static int sceCdReadDir(
sceCdlFILE *fp,
int dsec,
int index,
int layer)
2755 VERBOSE_PRINTF(1,
"_sceCdReadDir: current= %d dsec= %d layer= %d\n", g_cdvdman_fs_cdsec, dsec, layer);
2756 if ( g_cdvdman_fs_cdsec != dsec || g_cdvdman_fs_layer != layer )
2758 if ( g_cdvdman_fs_layer != layer )
2760 if ( !CD_newmedia(layer) )
2764 g_cdvdman_fs_cache = 1;
2766 if ( !CD_cachefile(dsec, layer) )
2771 if ( g_cdvdman_filetbl[index].m_file_struct.name[0] )
2773 VERBOSE_PRINTF(1,
"%s:\t found dir_point %d\n", g_cdvdman_filetbl[index].m_file_struct.name, index);
2781 static int cdvdman_cmpname(
const char *p,
const char *q)
2783 return !strncmp(p, q, 12);
2786 static int CD_newmedia(
int arg)
2788 unsigned int DiskType;
2795 #ifdef CDVD_VARIANT_XOSD
2796 DiskType = get_disk_type_ex();
2812 VERBOSE_PRINTF(1,
"CD_newmedia: Illegal disc media type =%d\n", (
int)DiskType);
2815 g_cdvdman_fs_base2 = 0;
2818 if ( !DvdDual_infochk() )
2820 VERBOSE_PRINTF(1,
"CD_newmedia: Get DvdDual_infochk fail\n");
2823 g_cdvdman_fs_base2 = arg ? g_cdvdman_istruct.m_layer_1_lsn : 0;
2825 if ( disc_read(1, g_cdvdman_fs_base2 + 0x10, g_cdvdman_fs_rbuf, arg) != 1 )
2827 VERBOSE_PRINTF(1,
"CD_newmedia: Read error in disc_read(PVD)\n");
2831 for ( i = 0; i < g_cdvdman_pathtblsize; i += 1 )
2833 g_cdvdman_pathtbl[i].m_cache_hit_count = 0;
2834 g_cdvdman_pathtbl[i].m_layer = 0;
2835 g_cdvdman_pathtbl[i].m_nsec = 0;
2836 g_cdvdman_pathtbl[i].m_lsn = 0;
2837 g_cdvdman_pathtbl[i].m_cache_path_sz = 0;
2841 g_cache_path_size = 0;
2843 if ( strncmp((
char *)((
iso9660_desc_t *)g_cdvdman_fs_rbuf)->m_id,
"CD001", 5) )
2845 VERBOSE_PRINTF(1,
"CD_newmedia: Disc format error in cd_read(PVD)\n");
2854 VERBOSE_PRINTF(1,
"CD_newmedia: CD Read mode\n");
2855 ptsector = *(u32 *)(((
iso9660_desc_t *)g_cdvdman_fs_rbuf)->m_type_l_path_table);
2860 VERBOSE_PRINTF(1,
"CD_newmedia: DVD Read mode\n");
2864 if ( disc_read(1, g_cdvdman_fs_base2 + ptsector, g_cdvdman_fs_rbuf, arg) != 1 )
2866 VERBOSE_PRINTF(1,
"CD_newmedia: Read error (PT:%08x)\n", ptsector);
2869 VERBOSE_PRINTF(2,
"CD_newmedia: sarching dir..\n");
2871 i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0]))
2872 && path_cur < (
iso9660_path_t *)&g_cdvdman_fs_rbuf[
sizeof(g_cdvdman_fs_rbuf)] && path_cur->m_name_len[0];
2874 path_cur = (
iso9660_path_t *)(((
char *)path_cur) + path_cur->m_name_len[0] + (path_cur->m_name_len[0] & 1)
2877 memcpy(&g_cdvdman_dirtbl[i].m_extent, path_cur->m_extent,
sizeof(path_cur->m_extent));
2878 g_cdvdman_dirtbl[i].m_number = i;
2879 memcpy(&g_cdvdman_dirtbl[i].m_parent, path_cur->m_parent,
sizeof(path_cur->m_parent));
2880 memcpy(g_cdvdman_dirtbl[i].m_name, path_cur->m_name, path_cur->m_name_len[0]);
2881 g_cdvdman_dirtbl[i].m_name[path_cur->m_name_len[0]] = 0;
2884 "\t%08x,%04x,%04x,%s\n",
2885 g_cdvdman_dirtbl[i].m_extent,
2886 g_cdvdman_dirtbl[i].m_number,
2887 g_cdvdman_dirtbl[i].m_parent,
2888 g_cdvdman_dirtbl[i].m_name);
2890 if ( i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0])) )
2892 g_cdvdman_dirtbl[i].m_parent = 0;
2894 g_cdvdman_fs_cdsec = 0;
2895 g_cdvdman_fs_layer = arg;
2896 VERBOSE_PRINTF(2,
"CD_newmedia: %d dir entries found\n", (
int)i);
2900 static int cdvdman_finddir(
int target_parent,
const char *target_name)
2904 for ( i = 0; i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0])) && g_cdvdman_dirtbl[i].m_parent; i += 1 )
2906 if ( g_cdvdman_dirtbl[i].m_parent == target_parent && !strcmp(target_name, g_cdvdman_dirtbl[i].m_name) )
2914 static int CD_cachefile(
int dsec,
int layer)
2919 if ( dsec == g_cdvdman_fs_cdsec )
2924 disc_read(1, g_cdvdman_dirtbl[dsec - 1].m_extent + (layer ? g_cdvdman_fs_base2 : 0), g_cdvdman_fs_rbuf, layer)
2927 VERBOSE_PRINTF(1,
"CD_cachefile: dir not found\n");
2928 g_cdvdman_fs_cdsec = 0;
2931 VERBOSE_PRINTF(2,
"CD_cachefile: searching...\n");
2933 i < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0]))
2934 && dirent_cur < (
iso9660_dirent_t *)&g_cdvdman_fs_rbuf[
sizeof(g_cdvdman_fs_rbuf)];
2935 i += 1, dirent_cur = (
iso9660_dirent_t *)((
char *)dirent_cur + dirent_cur->m_length[0]) )
2939 if ( !dirent_cur->m_length[0] )
2944 &g_cdvdman_filetbl[i].m_file_struct.lsn, dirent_cur->m_extent,
sizeof(g_cdvdman_filetbl[i].m_file_struct.lsn));
2946 &g_cdvdman_filetbl[i].m_file_struct.size, dirent_cur->m_size,
sizeof(g_cdvdman_filetbl[i].m_file_struct.size));
2947 file_year = dirent_cur->m_date[0] + 1900;
2948 g_cdvdman_filetbl[i].m_file_struct.
date[7] = file_year >> 8;
2949 g_cdvdman_filetbl[i].m_file_struct.
date[6] = file_year;
2950 g_cdvdman_filetbl[i].m_file_struct.
date[5] = dirent_cur->m_date[1];
2951 g_cdvdman_filetbl[i].m_file_struct.
date[4] = dirent_cur->m_date[2];
2952 g_cdvdman_filetbl[i].m_file_struct.
date[3] = dirent_cur->m_date[3];
2953 g_cdvdman_filetbl[i].m_file_struct.
date[2] = dirent_cur->m_date[4];
2954 g_cdvdman_filetbl[i].m_file_struct.
date[1] = dirent_cur->m_date[5];
2955 g_cdvdman_filetbl[i].m_flags = dirent_cur->m_flags[0];
2959 strcpy(g_cdvdman_filetbl[i].m_file_struct.name,
".");
2962 strcpy(g_cdvdman_filetbl[i].m_file_struct.name,
"..");
2965 memcpy(g_cdvdman_filetbl[i].m_file_struct.name, dirent_cur->m_name, dirent_cur->m_name_len[0]);
2966 g_cdvdman_filetbl[i].m_file_struct.
name[dirent_cur->m_name_len[0]] = 0;
2971 "\t lsn %d size %d name:%d:%s %d/%d/%d %d:%d:%d\n",
2972 (
int)(g_cdvdman_filetbl[i].m_file_struct.lsn),
2973 (
int)(g_cdvdman_filetbl[i].m_file_struct.size),
2974 dirent_cur->m_name_len[0],
2975 g_cdvdman_filetbl[i].m_file_struct.name,
2977 g_cdvdman_filetbl[i].m_file_struct.date[5],
2978 g_cdvdman_filetbl[i].m_file_struct.date[4],
2979 g_cdvdman_filetbl[i].m_file_struct.date[3],
2980 g_cdvdman_filetbl[i].m_file_struct.date[2],
2981 g_cdvdman_filetbl[i].m_file_struct.date[1]);
2983 g_cdvdman_fs_cdsec = dsec;
2984 if ( i < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0])) )
2986 g_cdvdman_filetbl[i].m_file_struct.
name[0] = 0;
2988 VERBOSE_PRINTF(2,
"CD_cachefile: %d files found\n", (
int)i);
2992 static int disc_read(
int size,
int loc,
void *buffer,
int layer)
3002 VERBOSE_PRINTF(1,
"cd_read:lsn= %d size= %d layer= %d\n", loc, size, layer);
3003 if ( cdvdman_l0check(layer) )
3005 g_cdvdman_srchspd = 0;
3007 switch ( g_cdvdman_srchspd )
3023 if ( !g_cdvdman_pathtblflag )
3031 pathcachecnt = (g_cache_count < g_cdvdman_pathtblsize) ? g_cache_count : g_cdvdman_pathtblsize;
3032 for ( i = 0; i < pathcachecnt; i += 1 )
3036 "Path table Cache Search lsn:%d:%d nsec:%d:%d layer%d:%d\n",
3037 g_cdvdman_pathtbl[i].m_lsn,
3039 g_cdvdman_pathtbl[i].m_nsec,
3041 g_cdvdman_pathtbl[i].m_layer,
3044 g_cdvdman_pathtbl[i].m_lsn == loc && g_cdvdman_pathtbl[i].m_nsec == (
unsigned int)size
3045 && g_cdvdman_pathtbl[i].m_layer == layer )
3050 if ( i != pathcachecnt )
3052 VERBOSE_KPRINTF(1,
"Path table Cache ON:%d\n", g_cdvdman_pathtbl[i].m_cache_path_sz);
3053 if ( lseek(g_cache_path_fd, g_cdvdman_pathtbl[i].m_cache_path_sz, 0) >= 0 )
3055 read(g_cache_path_fd, buffer, size << 11);
3057 g_cdvdman_pathtbl[i].m_cache_hit_count += 1;
3063 if ( !
sceCdRE(loc, size, buffer, &rmode) )
3074 if ( g_cache_count >= g_cdvdman_pathtblsize )
3077 unsigned int cacheblo2;
3080 if ( g_cache_table >= g_cdvdman_pathtblsize )
3084 cachetblo1 = g_cache_table;
3085 cacheblo2 = cachetblo1;
3086 for ( i = 0; (
unsigned int)i < g_cache_count; i += 1 )
3088 if ( cacheblo2 >= g_cdvdman_pathtblsize )
3093 g_cdvdman_pathtbl[cacheblo2].m_nsec >= (
unsigned int)size
3094 && g_cdvdman_pathtbl[cacheblo2].m_cache_hit_count
3095 < (
unsigned int)g_cdvdman_pathtbl[cachetblo1].m_cache_hit_count )
3097 cachetblo1 = cacheblo2;
3101 cache_path_sz = g_cdvdman_pathtbl[cachetblo1].m_cache_path_sz;
3102 g_cache_table = cachetblo1;
3106 cache_path_sz = g_cache_path_size;
3107 g_cache_table = g_cache_count;
3110 if ( lseek(g_cache_path_fd, cache_path_sz, 0) >= 0 )
3112 int ptbl_wcache_write_res;
3114 ptbl_wcache_write_res = write(g_cache_path_fd, buffer, size << 11);
3115 if ( ptbl_wcache_write_res == size << 11 )
3118 g_cdvdman_pathtbl[g_cache_table].m_cache_path_sz = cache_path_sz;
3119 g_cdvdman_pathtbl[g_cache_table].m_lsn = loc;
3120 g_cdvdman_pathtbl[g_cache_table].m_nsec = size;
3121 g_cdvdman_pathtbl[g_cache_table].m_layer = layer;
3122 g_cdvdman_pathtbl[g_cache_table].m_cache_hit_count = 0;
3123 g_cache_path_size += (g_cache_count < g_cdvdman_pathtblsize) ? ptbl_wcache_write_res : 0;
3127 VERBOSE_KPRINTF(1,
"Ptbl_WCache:write %d", ptbl_wcache_write_res);
3128 g_cdvdman_pathtbl[g_cache_table].m_cache_hit_count = 0;
3129 g_cdvdman_pathtbl[g_cache_table].m_layer = 0;
3130 g_cdvdman_pathtbl[g_cache_table].m_nsec = 0;
3131 g_cdvdman_pathtbl[g_cache_table].m_lsn = 0;
3142 if ( !
sceCdRE(loc, size, buffer, &rmode) )
3152 VERBOSE_KPRINTF(1,
"cd_read: error code %x\n",
sceCdGetError());
3156 static int path_tbl_init(u32 blocks,
char *fname,
int action)
3170 if ( !g_cdvdman_pathtbl )
3173 g_cdvdman_pathtblflag = 0;
3177 sprintf(cachedir,
"%sCache_Path", fname);
3178 v = open(cachedir, O_TRUNC | O_CREAT | O_RDWR, 0x1ff );
3183 g_cache_path_fd = v;
3184 if ( !strncmp(cachedir,
"pfs", 3) )
3186 blocksbs = blocks << 11;
3187 ioctl2(g_cache_path_fd, PIOCALLOC, &blocksbs,
sizeof(blocksbs), 0, 0);
3189 for ( i = 0; i < blocks; i += 1 )
3191 v = write(g_cache_path_fd, g_cdvdman_fs_rbuf,
sizeof(g_cdvdman_fs_rbuf));
3200 g_cdvdman_pathtblsize = blocks;
3201 for ( i = 0; i < blocks; i += 1 )
3203 g_cdvdman_pathtbl[i].m_cache_hit_count = 0;
3204 g_cdvdman_pathtbl[i].m_layer = 0;
3205 g_cdvdman_pathtbl[i].m_nsec = 0;
3206 g_cdvdman_pathtbl[i].m_lsn = 0;
3207 g_cdvdman_pathtbl[i].m_cache_path_sz = 0;
3209 g_cache_path_size = 0;
3212 g_cdvdman_pathtblflag = 1;
3218 if ( g_cache_path_fd != -1 )
3220 num = close(g_cache_path_fd);
3223 if ( !strncmp(cachedir,
"pfs", 3) )
3225 num = remove(cachedir);
3227 else if ( !strncmp(cachedir,
"host", 4) )
3235 g_cache_path_fd = -1;
3238 g_cache_path_size = 0;
3239 g_cdvdman_pathtblflag = 0;
3240 g_cdvdman_pathtblsize = 0;
3241 FreeSysMemory(g_cdvdman_pathtbl);
3242 g_cdvdman_pathtbl = 0;
3246 VERBOSE_KPRINTF(1,
"path_tbl_init Error %d\n", v);
3248 return (!action) ? num : v;
3255 "\t" ".set push" "\n"
3256 "\t" ".set noat" "\n"
3257 "\t" ".set noreorder" "\n"
3258 "\t" ".global optimized_memcpy" "\n"
3259 "\t" "optimized_memcpy:" "\n"
3260 "\t" " srl $a3, $a2, 2" "\n"
3261 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3262 "\t" " or $a3, $a0, $a1" "\n"
3263 "\t" " andi $a3, $a3, 0x3" "\n"
3264 "\t" " bnez $a3, .Loptimized_memcpy_3" "\n"
3266 "\t" " srl $a3, $a2, 2" "\n"
3267 "\t" " addiu $at, $zero, 0xC" "\n"
3268 "\t" " div $zero, $a3, $at" "\n"
3269 "\t" " mflo $a3" "\n"
3270 "\t" " mfhi $v1" "\n"
3271 "\t" " beqz $v1, .Loptimized_memcpy_2" "\n"
3273 "\t" ".Loptimized_memcpy_1:" "\n"
3274 "\t" " lw $v0, 0x0($a1)" "\n"
3275 "\t" " addiu $v1, $v1, -0x1" "\n"
3276 "\t" " sw $v0, 0x0($a0)" "\n"
3277 "\t" " addiu $a1, $a1, 0x4" "\n"
3278 "\t" " bnez $v1, .Loptimized_memcpy_1" "\n"
3279 "\t" " addiu $a0, $a0, 0x4" "\n"
3280 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3282 "\t" ".Loptimized_memcpy_2:" "\n"
3283 "\t" " lw $v0, 0x0($a1)" "\n"
3284 "\t" " lw $v1, 0x4($a1)" "\n"
3285 "\t" " lw $t0, 0x8($a1)" "\n"
3286 "\t" " lw $t1, 0xC($a1)" "\n"
3287 "\t" " lw $t2, 0x10($a1)" "\n"
3288 "\t" " lw $t3, 0x14($a1)" "\n"
3289 "\t" " lw $t4, 0x18($a1)" "\n"
3290 "\t" " lw $t5, 0x1C($a1)" "\n"
3291 "\t" " lw $t6, 0x20($a1)" "\n"
3292 "\t" " lw $t7, 0x24($a1)" "\n"
3293 "\t" " lw $t8, 0x28($a1)" "\n"
3294 "\t" " lw $t9, 0x2C($a1)" "\n"
3295 "\t" " addiu $a3, $a3, -0x1" "\n"
3296 "\t" " sw $v0, 0x0($a0)" "\n"
3297 "\t" " sw $v1, 0x4($a0)" "\n"
3298 "\t" " sw $t0, 0x8($a0)" "\n"
3299 "\t" " sw $t1, 0xC($a0)" "\n"
3300 "\t" " sw $t2, 0x10($a0)" "\n"
3301 "\t" " sw $t3, 0x14($a0)" "\n"
3302 "\t" " sw $t4, 0x18($a0)" "\n"
3303 "\t" " sw $t5, 0x1C($a0)" "\n"
3304 "\t" " sw $t6, 0x20($a0)" "\n"
3305 "\t" " sw $t7, 0x24($a0)" "\n"
3306 "\t" " sw $t8, 0x28($a0)" "\n"
3307 "\t" " sw $t9, 0x2C($a0)" "\n"
3308 "\t" " addiu $a1, $a1, 0x30" "\n"
3309 "\t" " bnez $a3, .Loptimized_memcpy_2" "\n"
3310 "\t" " addiu $a0, $a0, 0x30" "\n"
3311 "\t" " j .Loptimized_memcpy_12" "\n"
3313 "\t" ".Loptimized_memcpy_3:" "\n"
3314 "\t" " andi $a3, $a0, 0x3" "\n"
3315 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3316 "\t" " andi $a3, $a1, 0x3" "\n"
3317 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3319 "\t" " srl $a3, $a2, 2" "\n"
3320 "\t" " addiu $at, $zero, 0xC" "\n"
3321 "\t" " div $zero, $a3, $at" "\n"
3322 "\t" " mflo $a3" "\n"
3323 "\t" " mfhi $v1" "\n"
3324 "\t" " beqz $v1, .Loptimized_memcpy_5" "\n"
3326 "\t" ".Loptimized_memcpy_4:" "\n"
3327 "\t" " lwl $v0, 0x3($a1)" "\n"
3328 "\t" " lwr $v0, 0x0($a1)" "\n"
3329 "\t" " addiu $v1, $v1, -0x1" "\n"
3330 "\t" " swl $v0, 0x3($a0)" "\n"
3331 "\t" " swr $v0, 0x0($a0)" "\n"
3332 "\t" " addiu $a1, $a1, 0x4" "\n"
3333 "\t" " bnez $v1, .Loptimized_memcpy_4" "\n"
3334 "\t" " addiu $a0, $a0, 0x4" "\n"
3335 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3337 "\t" ".Loptimized_memcpy_5:" "\n"
3338 "\t" " lwl $v0, 0x3($a1)" "\n"
3339 "\t" " lwr $v0, 0x0($a1)" "\n"
3340 "\t" " lwl $v1, 0x7($a1)" "\n"
3341 "\t" " lwr $v1, 0x4($a1)" "\n"
3342 "\t" " lwl $t0, 0xB($a1)" "\n"
3343 "\t" " lwr $t0, 0x8($a1)" "\n"
3344 "\t" " lwl $t1, 0xF($a1)" "\n"
3345 "\t" " lwr $t1, 0xC($a1)" "\n"
3346 "\t" " lwl $t2, 0x13($a1)" "\n"
3347 "\t" " lwr $t2, 0x10($a1)" "\n"
3348 "\t" " lwl $t3, 0x17($a1)" "\n"
3349 "\t" " lwr $t3, 0x14($a1)" "\n"
3350 "\t" " lwl $t4, 0x1B($a1)" "\n"
3351 "\t" " lwr $t4, 0x18($a1)" "\n"
3352 "\t" " lwl $t5, 0x1F($a1)" "\n"
3353 "\t" " lwr $t5, 0x1C($a1)" "\n"
3354 "\t" " lwl $t6, 0x23($a1)" "\n"
3355 "\t" " lwr $t6, 0x20($a1)" "\n"
3356 "\t" " lwl $t7, 0x27($a1)" "\n"
3357 "\t" " lwr $t7, 0x24($a1)" "\n"
3358 "\t" " lwl $t8, 0x2B($a1)" "\n"
3359 "\t" " lwr $t8, 0x28($a1)" "\n"
3360 "\t" " lwl $t9, 0x2F($a1)" "\n"
3361 "\t" " lwr $t9, 0x2C($a1)" "\n"
3362 "\t" " addiu $a3, $a3, -0x1" "\n"
3363 "\t" " swl $v0, 0x3($a0)" "\n"
3364 "\t" " swr $v0, 0x0($a0)" "\n"
3365 "\t" " swl $v1, 0x7($a0)" "\n"
3366 "\t" " swr $v1, 0x4($a0)" "\n"
3367 "\t" " swl $t0, 0xB($a0)" "\n"
3368 "\t" " swr $t0, 0x8($a0)" "\n"
3369 "\t" " swl $t1, 0xF($a0)" "\n"
3370 "\t" " swr $t1, 0xC($a0)" "\n"
3371 "\t" " swl $t2, 0x13($a0)" "\n"
3372 "\t" " swr $t2, 0x10($a0)" "\n"
3373 "\t" " swl $t3, 0x17($a0)" "\n"
3374 "\t" " swr $t3, 0x14($a0)" "\n"
3375 "\t" " swl $t4, 0x1B($a0)" "\n"
3376 "\t" " swr $t4, 0x18($a0)" "\n"
3377 "\t" " swl $t5, 0x1F($a0)" "\n"
3378 "\t" " swr $t5, 0x1C($a0)" "\n"
3379 "\t" " swl $t6, 0x23($a0)" "\n"
3380 "\t" " swr $t6, 0x20($a0)" "\n"
3381 "\t" " swl $t7, 0x27($a0)" "\n"
3382 "\t" " swr $t7, 0x24($a0)" "\n"
3383 "\t" " swl $t8, 0x2B($a0)" "\n"
3384 "\t" " swr $t8, 0x28($a0)" "\n"
3385 "\t" " swl $t9, 0x2F($a0)" "\n"
3386 "\t" " swr $t9, 0x2C($a0)" "\n"
3387 "\t" " addiu $a1, $a1, 0x30" "\n"
3388 "\t" " bnez $a3, .Loptimized_memcpy_5" "\n"
3389 "\t" " addiu $a0, $a0, 0x30" "\n"
3390 "\t" " j .Loptimized_memcpy_12" "\n"
3392 "\t" ".Loptimized_memcpy_6:" "\n"
3393 "\t" " andi $a3, $a0, 0x3" "\n"
3394 "\t" " beqz $a3, .Loptimized_memcpy_9" "\n"
3396 "\t" " srl $a3, $a2, 2" "\n"
3397 "\t" " addiu $at, $zero, 0xC" "\n"
3398 "\t" " div $zero, $a3, $at" "\n"
3399 "\t" " mflo $a3" "\n"
3400 "\t" " mfhi $v1" "\n"
3401 "\t" " beqz $v1, .Loptimized_memcpy_8" "\n"
3403 "\t" ".Loptimized_memcpy_7:" "\n"
3404 "\t" " lw $v0, 0x0($a1)" "\n"
3405 "\t" " addiu $v1, $v1, -0x1" "\n"
3406 "\t" " swl $v0, 0x3($a0)" "\n"
3407 "\t" " swr $v0, 0x0($a0)" "\n"
3408 "\t" " addiu $a1, $a1, 0x4" "\n"
3409 "\t" " bnez $v1, .Loptimized_memcpy_7" "\n"
3410 "\t" " addiu $a0, $a0, 0x4" "\n"
3411 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3413 "\t" ".Loptimized_memcpy_8:" "\n"
3414 "\t" " lw $v0, 0x0($a1)" "\n"
3415 "\t" " lw $v1, 0x4($a1)" "\n"
3416 "\t" " lw $t0, 0x8($a1)" "\n"
3417 "\t" " lw $t1, 0xC($a1)" "\n"
3418 "\t" " lw $t2, 0x10($a1)" "\n"
3419 "\t" " lw $t3, 0x14($a1)" "\n"
3420 "\t" " lw $t4, 0x18($a1)" "\n"
3421 "\t" " lw $t5, 0x1C($a1)" "\n"
3422 "\t" " lw $t6, 0x20($a1)" "\n"
3423 "\t" " lw $t7, 0x24($a1)" "\n"
3424 "\t" " lw $t8, 0x28($a1)" "\n"
3425 "\t" " lw $t9, 0x2C($a1)" "\n"
3426 "\t" " addiu $a3, $a3, -0x1" "\n"
3427 "\t" " swl $v0, 0x3($a0)" "\n"
3428 "\t" " swr $v0, 0x0($a0)" "\n"
3429 "\t" " swl $v1, 0x7($a0)" "\n"
3430 "\t" " swr $v1, 0x4($a0)" "\n"
3431 "\t" " swl $t0, 0xB($a0)" "\n"
3432 "\t" " swr $t0, 0x8($a0)" "\n"
3433 "\t" " swl $t1, 0xF($a0)" "\n"
3434 "\t" " swr $t1, 0xC($a0)" "\n"
3435 "\t" " swl $t2, 0x13($a0)" "\n"
3436 "\t" " swr $t2, 0x10($a0)" "\n"
3437 "\t" " swl $t3, 0x17($a0)" "\n"
3438 "\t" " swr $t3, 0x14($a0)" "\n"
3439 "\t" " swl $t4, 0x1B($a0)" "\n"
3440 "\t" " swr $t4, 0x18($a0)" "\n"
3441 "\t" " swl $t5, 0x1F($a0)" "\n"
3442 "\t" " swr $t5, 0x1C($a0)" "\n"
3443 "\t" " swl $t6, 0x23($a0)" "\n"
3444 "\t" " swr $t6, 0x20($a0)" "\n"
3445 "\t" " swl $t7, 0x27($a0)" "\n"
3446 "\t" " swr $t7, 0x24($a0)" "\n"
3447 "\t" " swl $t8, 0x2B($a0)" "\n"
3448 "\t" " swr $t8, 0x28($a0)" "\n"
3449 "\t" " swl $t9, 0x2F($a0)" "\n"
3450 "\t" " swr $t9, 0x2C($a0)" "\n"
3451 "\t" " addiu $a1, $a1, 0x30" "\n"
3452 "\t" " bnez $a3, .Loptimized_memcpy_8" "\n"
3453 "\t" " addiu $a0, $a0, 0x30" "\n"
3454 "\t" " j .Loptimized_memcpy_12" "\n"
3456 "\t" ".Loptimized_memcpy_9:" "\n"
3457 "\t" " srl $a3, $a2, 2" "\n"
3458 "\t" " addiu $at, $zero, 0xC" "\n"
3459 "\t" " div $zero, $a3, $at" "\n"
3460 "\t" " mflo $a3" "\n"
3461 "\t" " mfhi $v1" "\n"
3462 "\t" " beqz $v1, .Loptimized_memcpy_11" "\n"
3464 "\t" ".Loptimized_memcpy_10:" "\n"
3465 "\t" " lwl $v0, 0x3($a1)" "\n"
3466 "\t" " lwr $v0, 0x0($a1)" "\n"
3467 "\t" " addiu $v1, $v1, -0x1" "\n"
3468 "\t" " sw $v0, 0x0($a0)" "\n"
3469 "\t" " addiu $a1, $a1, 0x4" "\n"
3470 "\t" " bnez $v1, .Loptimized_memcpy_10" "\n"
3471 "\t" " addiu $a0, $a0, 0x4" "\n"
3472 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3474 "\t" ".Loptimized_memcpy_11:" "\n"
3475 "\t" " lwl $v0, 0x3($a1)" "\n"
3476 "\t" " lwr $v0, 0x0($a1)" "\n"
3477 "\t" " lwl $v1, 0x7($a1)" "\n"
3478 "\t" " lwr $v1, 0x4($a1)" "\n"
3479 "\t" " lwl $t0, 0xB($a1)" "\n"
3480 "\t" " lwr $t0, 0x8($a1)" "\n"
3481 "\t" " lwl $t1, 0xF($a1)" "\n"
3482 "\t" " lwr $t1, 0xC($a1)" "\n"
3483 "\t" " lwl $t2, 0x13($a1)" "\n"
3484 "\t" " lwr $t2, 0x10($a1)" "\n"
3485 "\t" " lwl $t3, 0x17($a1)" "\n"
3486 "\t" " lwr $t3, 0x14($a1)" "\n"
3487 "\t" " lwl $t4, 0x1B($a1)" "\n"
3488 "\t" " lwr $t4, 0x18($a1)" "\n"
3489 "\t" " lwl $t5, 0x1F($a1)" "\n"
3490 "\t" " lwr $t5, 0x1C($a1)" "\n"
3491 "\t" " lwl $t6, 0x23($a1)" "\n"
3492 "\t" " lwr $t6, 0x20($a1)" "\n"
3493 "\t" " lwl $t7, 0x27($a1)" "\n"
3494 "\t" " lwr $t7, 0x24($a1)" "\n"
3495 "\t" " lwl $t8, 0x2B($a1)" "\n"
3496 "\t" " lwr $t8, 0x28($a1)" "\n"
3497 "\t" " lwl $t9, 0x2F($a1)" "\n"
3498 "\t" " lwr $t9, 0x2C($a1)" "\n"
3499 "\t" " addiu $a3, $a3, -0x1" "\n"
3500 "\t" " sw $v0, 0x0($a0)" "\n"
3501 "\t" " sw $v1, 0x4($a0)" "\n"
3502 "\t" " sw $t0, 0x8($a0)" "\n"
3503 "\t" " sw $t1, 0xC($a0)" "\n"
3504 "\t" " sw $t2, 0x10($a0)" "\n"
3505 "\t" " sw $t3, 0x14($a0)" "\n"
3506 "\t" " sw $t4, 0x18($a0)" "\n"
3507 "\t" " sw $t5, 0x1C($a0)" "\n"
3508 "\t" " sw $t6, 0x20($a0)" "\n"
3509 "\t" " sw $t7, 0x24($a0)" "\n"
3510 "\t" " sw $t8, 0x28($a0)" "\n"
3511 "\t" " sw $t9, 0x2C($a0)" "\n"
3512 "\t" " addiu $a1, $a1, 0x30" "\n"
3513 "\t" " bnez $a3, .Loptimized_memcpy_11" "\n"
3514 "\t" " addiu $a0, $a0, 0x30" "\n"
3515 "\t" ".Loptimized_memcpy_12:" "\n"
3516 "\t" " andi $v1, $a2, 0x3" "\n"
3517 "\t" " beqz $v1, .Loptimized_memcpy_14" "\n"
3519 "\t" ".Loptimized_memcpy_13:" "\n"
3520 "\t" " lb $v0, 0x0($a1)" "\n"
3521 "\t" " addiu $v1, $v1, -0x1" "\n"
3522 "\t" " sb $v0, 0x0($a0)" "\n"
3523 "\t" " addiu $a1, $a1, 0x1" "\n"
3524 "\t" " bnez $v1, .Loptimized_memcpy_13" "\n"
3525 "\t" " addiu $a0, $a0, 0x1" "\n"
3526 "\t" ".Loptimized_memcpy_14:" "\n"
3527 "\t" " addu $v0, $a2, $zero" "\n"
3530 "\t" ".set pop" "\n"
3535 void hex_dump(u8 *addr_start,
int length)
3539 KPRINTF(
"Hex Dump addr %08x\n", addr_start);
3540 for ( i = 0; i < length; i += 1 )
3542 if ( !(i & 0xF) && i )
3546 KPRINTF(
" %02x", addr_start[i]);
3552 static int cdvdman_initcfg(
void)
3559 for ( i = 0; i <= 100; i += 1 )
3561 unsigned int mvored;
3563 #ifdef CDVD_VARIANT_XOSD
3564 if ( !
sceCdMV(m_version, &eflag) )
3566 if ( !
sceCdMV(m_version, &eflag) && (eflag & 0x80) )
3570 VERBOSE_KPRINTF(1,
"_sceCdMV error\n");
3572 mvored = m_version[3] | (m_version[2] << 8) | (m_version[1] << 16);
3573 g_cdvdman_emudvd9 = m_version[2] & 1;
3574 VERBOSE_KPRINTF(1,
"MV %02x %02x %02x %02x\n", m_version[0], m_version[1], m_version[2], m_version[3]);
3575 g_cdvdman_minver_10700 = mvored >= 0x10700;
3576 g_cdvdman_minver_20200 = mvored >= 0x20200;
3577 g_cdvdman_minver_20400 = mvored >= 0x20400;
3578 g_cdvdman_minver_20800 = mvored >= 0x20800;
3579 g_cdvdman_minver_50000 = mvored >= 0x50000;
3580 g_cdvdman_minver_50200 = mvored >= 0x50200;
3581 g_cdvdman_minver_50400 = mvored >= 0x50400;
3582 g_cdvdman_minver_50600 = mvored >= 0x50600;
3583 #ifdef CDVD_VARIANT_XOSD
3584 VERBOSE_KPRINTF(0,
"M Version %02x %02x %02x %02x\n", m_version[0], m_version[1], m_version[2], m_version[3]);
3585 if ( cdvdman_get_renewal_date(m_version, &eflag) )
3589 "M Renewal Date 20%02x/%02x/%02x %02x:%02x\n",
3596 g_cdvdman_vernotxxx1x = 0;
3597 if ( g_cdvdman_minver_50600 )
3600 KPRINTF(
"X_model ");
3601 switch ( mvored & 0xF0 )
3604 KPRINTF(
"量産 OR 量産試作機\n");
3608 g_cdvdman_vernotxxx1x = 1;
3611 KPRINTF(
"手作り試作機\n");
3617 KPRINTF(
"Unkown\n");
3623 KPRINTF(
"X_model 旧原理試作機 Ver5.6未満 Found\n");
3626 g_cdvdman_minver_x_model_15 = (mvored & 0xF) == 1;
3627 g_cdvdman_minver_60000 = mvored >= 0x60000;
3628 g_cdvdman_minver_60200 = mvored >= 0x60200;
3629 #ifdef CDVD_VARIANT_OSD
3630 g_cdvdman_minver_60600 = mvored >= 0x60600;
3637 static int vSetAlarm(
iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *arg),
void *arg)
3639 return (
QueryIntrContext() ? iSetAlarm : SetAlarm)(sys_clock, alarm_cb, arg);
3642 static int vCancelAlarm(
unsigned int (*alarm_cb)(
void *arg),
void *arg)
3648 s32 vSignalSema(s32 sema_id)
3654 static int vSetEventFlag(
int ef, u32 bits)
3659 static int vClearEventFlag(
int ef, u32 bits)
3669 static int vPollEventFlag(
int ef, u32 bits,
int mode, u32 *efbits)
3671 #ifdef CDVD_VARIANT_XOSD
3677 return PollEventFlag(ef, bits, mode, efbits);
3679 retres = iReferEventFlagStatus(ef, &efinfo);
3685 if ( (mode & 1) ? !(efinfo.
currBits & bits) : ((efinfo.
currBits & bits) != bits) )
3691 iClearEventFlag(ef, ~bits);
3695 return PollEventFlag(ef, bits, mode, efbits);
3699 static int vDelayThread(
int usec)
3709 #ifdef CDVD_VARIANT_XOSD
3710 static int get_cdvd_register(
int regnr)
3722 if ( !IntrContext && !intrres )
3724 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3731 iReferEventFlagStatus(g_cdvdman_csys_evfid, &efinfo);
3735 ReferEventFlagStatus(g_cdvdman_csys_evfid, &efinfo);
3742 if ( update_cd_mode_ps2_atapi() != 1 )
3744 regval = ((vu8 *)(0xBF402000))[regnr];
3748 if ( !IntrContext && !intrres )
3751 if ( g_cd_atapi_evfid != -1 )
3753 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
3755 if ( g_adma_evfid != -1 )
3757 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3759 if ( g_acmd_evfid != -1 )
3761 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3767 if ( g_cd_atapi_evfid != -1 )
3771 iReferEventFlagStatus(g_cd_atapi_evfid, &efinfo);
3775 ReferEventFlagStatus(g_cd_atapi_evfid, &efinfo);
3782 if ( g_adma_evfid != -1 )
3786 iReferEventFlagStatus(g_adma_evfid, &efinfo);
3790 ReferEventFlagStatus(g_adma_evfid, &efinfo);
3797 if ( g_acmd_evfid != -1 )
3801 iReferEventFlagStatus(g_acmd_evfid, &efinfo);
3805 ReferEventFlagStatus(g_acmd_evfid, &efinfo);
3813 set_cdvd_dev5_base_addr_atapi(2);
3814 regval = ((vu8 *)(0xBF402000))[regnr];
3815 set_cdvd_dev5_base_addr_atapi(1);
3816 if ( !IntrContext && !intrres )
3818 if ( g_acmd_evfid != -1 )
3820 SetEventFlag(g_acmd_evfid, 1);
3822 if ( g_adma_evfid != -1 )
3824 SetEventFlag(g_adma_evfid, 1);
3826 if ( g_cd_atapi_evfid != -1 )
3828 SetEventFlag(g_cd_atapi_evfid, 3);
3832 if ( !IntrContext && !intrres )
3835 SetEventFlag(g_cdvdman_csys_evfid, 1);
3842 static unsigned int read_timeout_alarm_cb(
void *userdata)
3848 read_timeout = sys_clock->lo / 0x9000;
3849 KPRINTF(
"Read Time Out %d(msec)\n", read_timeout);
3850 sceCdSC(0xFFFFFFEE, &read_timeout);
3859 if (
sceCdSync(1) || PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
3863 rc = g_cdvdman_user_cb;
3864 g_cdvdman_user_cb =
function;
3865 vSetEventFlag(g_ncmd_evfid, 1);
3876 old_cb = g_cdvdman_power_off_callback;
3877 g_cdvdman_power_off_callback = func;
3878 g_cdvdman_power_off_callback_userdata = userdata;
3883 #ifdef CDVD_VARIANT_XOSD
3890 old_cb = g_cdvdman_atapi_eject_bs_power_callback;
3891 g_cdvdman_atapi_eject_bs_power_callback = func;
3892 g_cdvdman_atapi_eject_bs_power_callback_userdata = userdata;
3898 int sceCdstm0Cb(
void (*p)(
int val))
3900 g_cdvdman_cdstm0cb = p;
3904 int sceCdstm1Cb(
void (*p)(
int val))
3906 g_cdvdman_cdstm1cb = p;
3914 int ext_passthrough;
3915 USE_DEV5_MMIO_HWPORT();
3917 ext_passthrough = 0;
3918 s->m_wait_flag = s->m_waf_set_test;
3919 iSetEventFlag(g_cdvdman_intr_evfid, 0x29);
3921 if ( s->m_cdvdman_command == SCECdFuncStandby && s->m_last_error ==
SCECdErTRMOPN )
3930 1,
"Intr call func_num: %d Err= %02x OnTout= %d\n", g_cdvdman_cmdfunc, (u8)s->m_last_error, s->m_last_read_timeout);
3931 if ( !s->m_scmd_flag )
3933 cdvdman_write_scmd(s);
3936 (((u8)s->m_last_error ==
SCECdErREAD && g_cdvdman_cmdfunc == SCECdFuncRead)
3937 || ((u8)s->m_last_error ==
SCECdErABRT && s->m_last_read_timeout && g_cdvdman_last_cmdfunc == SCECdFuncRead))
3938 && !g_cdvdman_minver_20200 && !s->m_stream_flag && !s->m_dvd_flag && !s->m_recover_status
3941 s->m_sync_error = 0;
3942 s->m_interupt_read_state = 0;
3943 if ( s->m_dec_mode_set )
3945 s->m_dec_mode_last_set = 1;
3949 VERBOSE_KPRINTF(1,
"dec mode 0x00\n");
3950 s->m_read_chunk_reprocial_32 = 1 + (0x20 / ((!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk));
3951 s->m_dintrlsn = (s->m_read_lsn < 0x61) ? (s->m_read_lsn + s->m_read_sectors + 48) : (s->m_read_lsn - 80);
3953 if ( !sceCdRead0_Rty(
3955 (!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk,
3958 (u8)s->m_cdvdman_command,
3963 s->m_recover_status = 0;
3967 ext_passthrough = 1;
3971 if ( !ext_passthrough )
3973 char dev5_reg_013_masked;
3975 VERBOSE_KPRINTF(1,
"Recover_Stat:%d\n", s->m_recover_status);
3976 dev5_reg_013_masked = dev5_mmio_hwport->m_dev5_reg_013 & 0xF;
3977 if ( dev5_reg_013_masked )
3981 && !s->m_recover_status && !s->m_stream_flag && g_cdvdman_cmdfunc != 9 && g_cdvdman_cmdfunc != SCECdFuncReadCDDA
3982 && (
unsigned int)s->m_read_mode.
trycount - 1 >= 4 )
3984 s->m_sync_error = 0;
3985 s->m_interupt_read_state = 0;
3986 if ( s->m_dec_mode_set )
3988 s->m_dec_mode_last_set = 2;
3992 VERBOSE_KPRINTF(1,
"dec mode 0x01\n");
3994 cdrmode.
spindlctrl = dev5_reg_013_masked + 13;
3996 if ( sceCdRead0_Rty(
4001 (u8)s->m_cdvdman_command,
4003 s->m_read_callback) )
4012 s->m_last_read_timeout = 0;
4013 switch ( s->m_recover_status )
4016 s->m_sync_error = 0;
4017 s->m_interupt_read_state = 0;
4022 (!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk,
4025 (u8)s->m_cdvdman_command,
4030 s->m_recover_status = 0;
4034 ext_passthrough = 1;
4038 s->m_sync_error = 0;
4039 s->m_interupt_read_state = 0;
4041 s->m_read_lsn, s->m_read_sectors, s->m_read_buf, &s->m_read_mode, s->m_read_chunk, s->m_read_callback) )
4044 s->m_recover_status = 3;
4048 s->m_recover_status = 0;
4051 s->m_recover_status = 0;
4057 if ( ext_passthrough )
4060 s->m_dintrlsn += s->m_read_sectors;
4061 s->m_read_chunk_reprocial_32 -= 1;
4062 s->m_recover_status = (!s->m_read_chunk_reprocial_32) ? 2 : 1;
4065 if ( s->m_dec_state )
4069 if ( (s->m_read2_flag == 1 || s->m_read2_flag == 3) && !s->m_use_toc )
4071 VERBOSE_KPRINTF(1,
"call Read2intrCDVD()\n");
4072 Read2intrCDVD(s->m_read2_flag);
4074 s->m_sync_error = 0;
4075 s->m_interupt_read_state = 0;
4076 if ( s->m_dec_state == 2 )
4080 if ( s->m_stream_flag == 1 && !s->m_use_toc && !s->m_read2_flag )
4082 if ( g_cdvdman_cdstm0cb )
4084 g_cdvdman_cdstm0cb(1);
4088 VERBOSE_KPRINTF(1,
"Intr func0 no seting");
4091 if ( !s->m_read2_flag )
4093 if ( s->m_stream_flag == 2 && !s->m_use_toc )
4095 if ( g_cdvdman_cdstm1cb )
4097 g_cdvdman_cdstm1cb(1);
4101 VERBOSE_KPRINTF(1,
"Intr func1 no seting");
4106 g_cdvdman_readptr = 0;
4111 1,
"Intr call user callback func_addr %08x num %d flg %d\n", g_cdvdman_user_cb, g_cdvdman_cmdfunc, s->m_read2_flag);
4112 if ( g_cdvdman_user_cb && g_cdvdman_cmdfunc && !s->m_read2_flag && !s->m_use_toc )
4116 cmdfunc_tmp = g_cdvdman_cmdfunc;
4117 g_cdvdman_cmdfunc = 0;
4118 if ( cmdfunc_tmp == 14 || cmdfunc_tmp == 9 )
4120 cmdfunc_tmp = SCECdFuncRead;
4122 g_cdvdman_user_cb(cmdfunc_tmp);
4124 if ( !g_cdvdman_user_cb )
4126 g_cdvdman_cmdfunc = 0;
4131 static int intrh_cdrom(
void *userdata)
4135 #ifdef CDVD_VARIANT_XOSD
4140 USE_DEV5_MMIO_HWPORT();
4144 #ifdef CDVD_VARIANT_XOSD
4145 if ( s->m_cd_mode_ps2_atapi == 1 )
4147 int spd_intr_stat_cur;
4148 int atapi_intr_reason;
4150 VERBOSE_KPRINTF(1,
"Atapi Intr Called %d\n", g_cdvdman_debug_atapi_intr++);
4151 condaddr5 = (
unsigned int)GetBaseAddress(5) == 0x1F402000;
4152 set_cdvd_dev5_base_addr_atapi(1);
4153 (void)*(vu16 *)0xBF410028;
4154 set_cdvd_dev5_base_addr_atapi(2);
4155 atapi_intr_reason = dev5_mmio_hwport->m_dev5_reg_008;
4156 if ( (atapi_intr_reason & 1) )
4159 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4160 VERBOSE_KPRINTF(1,
"ATAPI DRAGON CMDCMPL Interrupt\n");
4162 if ( atapi_intr_reason & 4 )
4164 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4166 iSetEventFlag(g_cdvdman_intr_evfid, 4);
4167 iSetEventFlag(g_cdvdman_intr_evfid, 0x10);
4168 set_cdvd_dev5_base_addr_atapi(1);
4169 VERBOSE_KPRINTF(1,
"ATAPI POFFRDY Interrupt\n");
4170 if ( g_cdvdman_power_off_callback )
4172 g_cdvdman_power_off_callback(g_cdvdman_power_off_callback_userdata);
4174 set_cdvd_dev5_base_addr_atapi(2);
4176 if ( (atapi_intr_reason & 8) )
4179 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4180 if ( !s->m_medium_removal_state )
4182 s->m_atapi_disk_ejected = 0;
4184 set_cdvd_dev5_base_addr_atapi(1);
4185 VERBOSE_KPRINTF(1,
"ATAPI EJECT Interrupt\n");
4186 if ( s->m_cd_atapi_intr_callback && !s->m_medium_removal_state )
4188 VERBOSE_KPRINTF(1,
"EJECT Stop Call\n");
4189 s->m_cd_atapi_intr_callback(1);
4191 iSetEventFlag(g_cdvdman_intr_evfid, 0x40);
4192 if ( g_cdvdman_atapi_eject_bs_power_callback )
4194 VERBOSE_KPRINTF(1,
"ATAPI EJECT Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4195 g_cdvdman_atapi_eject_bs_power_callback(1, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4197 set_cdvd_dev5_base_addr_atapi(2);
4199 if ( (atapi_intr_reason & 0x10) )
4201 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4203 set_cdvd_dev5_base_addr_atapi(1);
4204 VERBOSE_KPRINTF(1,
"ATAPI BS_Power DET Interrupt\n");
4205 iSetEventFlag(g_cdvdman_intr_evfid, 0x80);
4206 if ( g_cdvdman_atapi_eject_bs_power_callback )
4208 VERBOSE_KPRINTF(1,
"ATAPI BS_Power Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4209 g_cdvdman_atapi_eject_bs_power_callback(2, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4212 set_cdvd_dev5_base_addr_atapi(1);
4213 if ( g_cdvdman_vernotxxx1x && conds1 )
4215 *(vu16 *)0xBF41002A &= ~0x100;
4216 *(vu16 *)0xBF41002A |= 0x100;
4217 (void)*(vu16 *)0xBF41002A;
4219 spd_intr_stat_cur = *(vu16 *)0xBF410028;
4222 "Atapi Intr Mode:%d addr:%08x Reason:%02x SPD_INTR_STAT %x\n",
4223 s->m_cd_mode_ps2_atapi,
4224 s->m_cd_atapi_intr_callback,
4227 if ( (spd_intr_stat_cur & 3) && (*g_cdvdreg_bf80146c & 4) )
4229 if ( s->m_cd_atapi_intr_callback )
4231 s->m_cd_atapi_intr_callback(0);
4232 VERBOSE_KPRINTF(1,
"Atapi Intr called\n");
4234 if ( !s->m_scmd_flag )
4236 VERBOSE_KPRINTF(1,
"Intr call set_prev_command.\n");
4237 set_cdvd_dev5_base_addr_atapi(2);
4238 cdvdman_write_scmd(s);
4239 set_cdvd_dev5_base_addr_atapi(1);
4244 if ( (*g_cdvdreg_bf80146c & 4) )
4246 VERBOSE_KPRINTF(1,
"No_Reason Intr\n");
4250 VERBOSE_KPRINTF(1,
"already 9611 Power Off Intr\n");
4255 set_cdvd_dev5_base_addr_atapi(2);
4256 VERBOSE_KPRINTF(1,
"Cur PS2 IO Intr Called\n");
4260 VERBOSE_KPRINTF(1,
"Dragon Intr Called\n");
4261 condaddr5 = (
unsigned int)GetBaseAddress(5) == 0xBF410000;
4264 set_cdvd_dev5_base_addr_atapi(2);
4267 s->m_waf_set_test = s->m_wait_flag;
4270 s->m_last_error = dev5_mmio_hwport->m_dev5_reg_006;
4272 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 1) )
4274 s->m_waf_set_test = (!(dev5_mmio_hwport->m_dev5_reg_005 & 1)) ? 1 : -1;
4275 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4278 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 4) )
4280 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4281 iSetEventFlag(g_cdvdman_intr_evfid, 4);
4282 iSetEventFlag(g_cdvdman_intr_evfid, 0x10);
4284 VERBOSE_KPRINTF(1,
"PS2 POWER OFF Interrupt\n");
4285 if ( g_cdvdman_power_off_callback )
4287 g_cdvdman_power_off_callback(g_cdvdman_power_off_callback_userdata);
4296 s->m_waf_set_test = 1;
4297 s->m_ncmd_intr_count += 1;
4298 dev5_mmio_hwport->m_dev5_reg_008 = 2;
4300 #ifdef CDVD_VARIANT_XOSD
4301 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 8) )
4303 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4304 VERBOSE_KPRINTF(1,
"PS2 EJECT Interrupt\n");
4305 iSetEventFlag(g_cdvdman_intr_evfid, 0x40);
4306 if ( !s->m_medium_removal_state )
4308 s->m_atapi_disk_ejected = 0;
4310 if ( g_cdvdman_atapi_eject_bs_power_callback )
4312 VERBOSE_KPRINTF(1,
"PS2 EJECT Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4313 g_cdvdman_atapi_eject_bs_power_callback(1, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4316 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 0x10) )
4318 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4319 VERBOSE_KPRINTF(1,
"PS2 BS_Power DET Interrupt\n");
4320 iSetEventFlag(g_cdvdman_intr_evfid, 0x80);
4321 if ( g_cdvdman_atapi_eject_bs_power_callback )
4323 VERBOSE_KPRINTF(1,
"PS2 BS_Power Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4324 g_cdvdman_atapi_eject_bs_power_callback(2, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4328 iReferEventFlagStatus(g_cdvdman_intr_evfid, &efinfo);
4332 VERBOSE_KPRINTF(1,
"Now DMA Working evfid:%08x\n", efinfo.
currBits);
4335 s->m_drive_interupt_request = 1;
4336 #ifdef CDVD_VARIANT_XOSD
4339 set_cdvd_dev5_base_addr_atapi(1);
4349 intr_cb_res = cdvdman_intr_cb(s);
4350 #ifdef CDVD_VARIANT_XOSD
4353 set_cdvd_dev5_base_addr_atapi(1);
4359 static u32 cdvdman_l1start(
const u8 *
toc)
4361 return toc[23] + (
toc[22] << 8) + (
toc[21] << 16) - 0x30000 + 1;
4364 static int DvdDual_infochk(
void)
4366 #ifdef CDVD_VARIANT_OSD
4368 if (
QueryIntrContext() || !(cdvdman_mediactl(3) || (u8)g_cdvdman_istruct.m_opo_or_para == 0xFF) )
4370 if (
QueryIntrContext() || !(cdvdman_mediactl(4) || (u8)g_cdvdman_istruct.m_opo_or_para == 0xFF) )
4375 g_cdvdman_istruct.m_use_toc = 1;
4376 if ( !cdvdman_gettoc(g_cdvdman_ptoc) )
4378 g_cdvdman_istruct.m_use_toc = 0;
4379 g_cdvdman_istruct.m_opo_or_para = -1;
4382 g_cdvdman_istruct.m_use_toc = 0;
4383 g_cdvdman_istruct.m_layer_1_lsn = cdvdman_l1start(g_cdvdman_ptoc);
4384 g_cdvdman_istruct.m_opo_or_para = ((g_cdvdman_ptoc[14] & 0x60)) ? (((g_cdvdman_ptoc[14] & 0x10)) ? 2 : 1) : 0;
4385 if ( g_cdvdman_istruct.m_dual_layer_emulation )
4387 VERBOSE_KPRINTF(1,
"CDVD:DualEmuON\n");
4388 g_cdvdman_istruct.m_layer_1_lsn = g_cdvdman_istruct.m_current_dvd_lsn;
4389 g_cdvdman_istruct.m_opo_or_para = 0;
4393 "DvdDual_info: %02x\tLayer1_LSN:%d opo_or_para %d\n",
4395 g_cdvdman_istruct.m_layer_1_lsn,
4396 (u8)g_cdvdman_istruct.m_opo_or_para);
4400 static u32 sceCdLsnDualChg(u32 lsn)
4402 int layer_disk_needed;
4407 layer_disk_needed = 2;
4409 if ( cdvdman_isdvd() && DvdDual_infochk() )
4411 if ( g_cdvdman_istruct.m_dual_layer_emulation )
4413 if ( !g_cdvdman_istruct.m_current_dvd && lsn >= g_cdvdman_istruct.m_current_dvd_lsn )
4415 layer_disk_needed = 1;
4417 if ( g_cdvdman_istruct.m_current_dvd && lsn < g_cdvdman_istruct.m_current_dvd_lsn )
4419 layer_disk_needed = 0;
4421 if ( layer_disk_needed == 2 )
4423 change_lsn = lsn - ((g_cdvdman_istruct.m_current_dvd) ? g_cdvdman_istruct.m_current_dvd_lsn : 0);
4430 VERBOSE_KPRINTF(0,
"CDVD: Exchange it for the Layer_%d_Disk Please.\n", layer_disk_needed);
4438 g_cdvdman_istruct.m_use_toc = 1;
4439 while ( layer_disk_needed != 2 )
4441 if ( cdvdman_isdvd() )
4445 read0_result = sceCdRead0(0xE, 1, g_cdvdman_ptoc, &cdrmode, 0, 0);
4447 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO || read0_result )
4451 for ( i = 0; i < 20; i += 1 )
4453 if ( g_cdvdman_ptoc[i + 104] != g_masterdisc_header[i] )
4458 if ( i == 20 && g_cdvdman_ptoc[131] == 2 && (g_cdvdman_ptoc[132] & 2) )
4460 if ( layer_disk_needed == g_cdvdman_ptoc[133] )
4462 g_cdvdman_istruct.m_current_dvd = layer_disk_needed;
4463 layer_disk_needed = 2;
4467 VERBOSE_KPRINTF(0,
"CDVD: Layer_%d Disk not Found\n", layer_disk_needed);
4468 VERBOSE_KPRINTF(0,
"CDVD: Exchange it for the Layer_%d_Disk Please.\n", layer_disk_needed);
4469 if ( !g_cdvdman_istruct.m_current_dvd && lsn >= g_cdvdman_istruct.m_current_dvd_lsn )
4471 layer_disk_needed = 1;
4481 VERBOSE_KPRINTF(0,
"CDVD: Not Master Disk %s\n", (
const char *)&g_cdvdman_ptoc[i + 104]);
4490 VERBOSE_KPRINTF(1,
"CDVD: LsnDualChg Read Error %02x, %d\n", (u8)g_cdvdman_istruct.m_last_error, 0);
4495 vDelayThread(16000);
4498 change_lsn = lsn - ((g_cdvdman_istruct.m_current_dvd) ? g_cdvdman_istruct.m_current_dvd_lsn : 0);
4499 g_cdvdman_istruct.m_use_toc = 0;
4506 lsn - ((g_cdvdman_istruct.m_opo_or_para && (lsn >= (u32)g_cdvdman_istruct.m_layer_1_lsn)) ? 0x10 : 0);
4510 if ( has_change_lsn )
4512 VERBOSE_KPRINTF(1,
"CDVD: sceCdLsnDualChg lsn %d: change lsn %d\n", lsn, change_lsn);
4514 return has_change_lsn ? change_lsn : lsn;
4525 g_cdvdman_istruct.m_dual_layer_emulation = 0;
4526 #ifndef CDVD_VARIANT_XOSD
4527 if ( !cdvdman_isdvd() )
4532 if ( !g_cdvdman_emudvd9 )
4534 if ( !DvdDual_infochk() )
4538 *on_dual = !!g_cdvdman_istruct.m_opo_or_para;
4539 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4542 #ifdef CDVD_VARIANT_OSD
4543 if ( !cdvdman_isdvd() )
4548 #ifndef CDVD_VARIANT_XOSD
4549 if ( g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF )
4557 read0_result = sceCdRead0(0xE, 1, g_cdvdman_ptoc, &cdrmode, 0, 0);
4559 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO && !read0_result )
4561 VERBOSE_KPRINTF(1,
"CDVD: ReadDvdDualInfo Read Error %02x, %d\n", (u8)g_cdvdman_istruct.m_last_error, 0);
4564 for ( i = 0; i < 20; i += 1 )
4566 if ( g_cdvdman_ptoc[i + 104] != g_masterdisc_header[i] )
4573 if ( !DvdDual_infochk() )
4577 *on_dual = !!g_cdvdman_istruct.m_opo_or_para;
4578 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4581 if ( g_cdvdman_ptoc[131] != 2 || !(g_cdvdman_ptoc[132] & 2) )
4585 g_cdvdman_istruct.m_current_dvd = g_cdvdman_ptoc[133];
4586 g_cdvdman_istruct.m_current_dvd_lsn =
4587 g_cdvdman_ptoc[134] + (g_cdvdman_ptoc[135] << 8) + (g_cdvdman_ptoc[136] << 16) + (g_cdvdman_ptoc[137] << 24) + 1;
4588 g_cdvdman_istruct.m_opo_or_para = 0;
4589 g_cdvdman_istruct.m_layer_1_lsn = g_cdvdman_istruct.m_current_dvd_lsn;
4590 g_cdvdman_istruct.m_dual_layer_emulation = 1;
4592 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4595 "sceCdReadDvdDualInfo():Cur_Disk %d layer1_start %d\n",
4596 (u8)g_cdvdman_istruct.m_current_dvd,
4597 g_cdvdman_istruct.m_current_dvd_lsn);
4601 int sceCdSC(
int code,
int *param)
4607 #ifdef CDVD_VARIANT_XOSD
4613 #ifdef CDVD_VARIANT_XOSD
4616 set_cdvd_dev5_base_addr_atapi(2);
4617 regval = ((vu8 *)(0xBF402000))[*param];
4618 set_cdvd_dev5_base_addr_atapi(1);
4623 *param = (int)&g_cdvdman_istruct.m_chgsys_writer_drive_shell_is_open;
4627 return sc_ffffffd8((u32 *)param);
4630 *param = (int)&g_cdvdman_istruct.m_atapi_disk_ejected;
4634 return get_disk_type_ex();
4637 *(&g_cdvdman_istruct.m_var_sc_ffffffdb) = (
int)param;
4641 return g_cdvdman_vernotxxx1x;
4643 return get_cdvd_register(*param);
4645 g_adma_evfid = *param;
4648 g_acmd_evfid = *param;
4652 g_cdvdman_istruct.m_chgsys_callback = (
void *)(
int)param;
4656 g_cd_atapi_evfid = *param;
4660 g_cdvdman_istruct.m_cd_atapi_intr_callback = (
void *)(
int)param;
4666 *param = (int)g_cdvdman_power_off_callback;
4667 poffarg_tmp = g_cdvdman_power_off_callback_userdata;
4669 return (
int)poffarg_tmp;
4671 return g_scmd_evfid;
4673 return sceCdLsnDualChg(*param);
4675 return DvdDual_infochk();
4677 g_cdvdman_istruct.m_last_read_timeout = *param;
4680 return g_cdvdman_stream_timeout;
4682 *param = (int)&g_verbose_level;
4685 return g_cdvdman_sync_timeout;
4687 *param = (int)&g_cdvdman_istruct;
4690 BootMode = QueryBootMode(4);
4691 switch ( BootMode ? *(u8 *)BootMode : 0xFF )
4696 g_cdvdman_mmode = 0xFF;
4699 g_cdvdman_mmode = SCECdMmodeCd;
4706 #ifdef CDVD_VARIANT_OSD
4716 return g_cdvdman_mmode == SCECdMmodeCd || g_cdvdman_mmode == 0xFF;
4718 return g_cdvdman_mmode == SCECdMmodeDvd || g_cdvdman_mmode == 0xFF;
4720 return g_cdvdman_mmode == 0xFF;
4726 return g_cdvdman_intr_evfid;
4730 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
4734 SetEventFlag(g_fio_fsv_evfid, 1);
4736 g_cdvdman_ee_rpc_fno = *param;
4737 VERBOSE_KPRINTF(1,
"EE_ncmd_working code= %d\n", *param);
4738 return g_cdvdman_ee_rpc_fno;
4740 return (u16)_irx_id.v;
4742 g_cdvdman_spinctl = *param;
4745 return g_cdvdman_cd36key;
4747 return g_cdvdman_istruct.m_read2_flag;
4749 g_cdvdman_istruct.m_last_error = *(u8 *)param;
4750 return (u8)g_cdvdman_istruct.m_last_error;
4755 *param = (u8)g_cdvdman_istruct.m_last_error;
4758 g_cdvdman_istruct.m_stream_flag = code;
4760 return g_cdvdman_istruct.m_stream_flag;
4762 VERBOSE_KPRINTF(1,
"sceCdSC func_num Not found %d\n", code);
4767 static void cdvdman_init(
void)
4773 #ifdef CDVD_VARIANT_XOSD
4776 USE_DEV5_MMIO_HWPORT();
4778 #ifdef CDVD_VARIANT_XOSD
4782 g_cdvdman_istruct.m_cd_mode_ps2_atapi = 2;
4783 cdvdman_change_drive(2);
4787 g_cdvdman_user_cb = 0;
4788 g_cdvdman_power_off_callback = 0;
4789 g_cdvdman_cmdfunc = 0;
4790 g_cdvdman_istruct.m_drive_interupt_request = 0;
4794 sceCdSC(0xFFFFFFF3, &scres_unused);
4795 dmac_set_dpcr(dmac_get_dpcr() | 0x8000);
4796 dmac_ch_set_chcr(3, 0);
4797 #ifdef CDVD_VARIANT_XOSD
4798 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 0x10) )
4800 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4802 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 8) )
4804 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4807 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 4) )
4809 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4811 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 1) )
4813 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4815 #ifndef CDVD_VARIANT_XOSD
4818 g_cdvdman_istruct.m_tray_is_open = !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen);
4819 #ifdef CDVD_VARIANT_XOSD
4823 BootMode = QueryBootMode(6);
4824 g_cdvdman_istruct.m_no_dec_flag = BootMode ? ((*(u16 *)BootMode & 0xFFFC) == 0x60) : 0;
4829 #ifdef CDVD_VARIANT_XOSD
4838 for ( i = 0; i <= 60 && (!(MediumRemoval =
sceCdGetMediumRemoval(&medium_res, &argres)) || argres); i += 1 )
4842 g_cdvdman_istruct.m_medium_removal_state = (MediumRemoval && !argres) ? medium_res : 0;
4848 g_cdvdman_istruct.m_cd_mode_ps2_atapi =
4849 (chgsys_tmp || (!(dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && dev5_mmio_hwport->m_dev5_reg_00F != 6)) ? 2 : 1;
4850 cdvdman_change_drive(g_cdvdman_istruct.m_cd_mode_ps2_atapi);
4863 VERBOSE_PRINTF(1,
"sceCdInit called mode= %d\n", mode);
4868 g_cdvdman_istruct.m_cd_inited = 0;
4869 #ifndef CDVD_VARIANT_XOSD
4872 cdvdman_ncmd_sender_06();
4875 VERBOSE_PRINTF(1,
"Cdvdman Exit\n");
4883 VERBOSE_PRINTF(1,
"Cdvdman Init\n");
4884 g_cdvdman_istruct.m_read2_flag = 0;
4885 g_cdvdman_istruct.m_dec_shift = 0;
4886 g_cdvdman_istruct.m_check_version = 0;
4887 g_cdvdman_istruct.m_dec_state = 0;
4888 #ifdef CDVD_VARIANT_XOSD
4889 if ( update_cd_mode_ps2_atapi() != 1 )
4895 g_cdvdman_istruct.m_cd_inited = 1;
4899 u8 ready_status_tmp;
4902 ready_status_tmp = 0;
4903 VERBOSE_PRINTF(1,
"sceCdInit Ready check start.\n");
4905 while ( (ready_status & 0xC0) != 0x40 )
4907 #ifdef CDVD_VARIANT_XOSD
4910 g_cdvdman_istruct.m_field_0DC = 0;
4915 vDelayThread(10000);
4916 if ( ready_status != ready_status_tmp )
4918 ready_status_tmp = ready_status;
4919 VERBOSE_PRINTF(1,
"sceCdInit Dev5 Status %x\n", ready_status);
4922 VERBOSE_PRINTF(1,
"sceCdInit Ready check %x\n", ready_status);
4924 VERBOSE_PRINTF(1,
"sceCdInit Ready check end.\n");
4926 g_cdvdman_istruct.m_wait_flag = 1;
4927 g_cdvdman_istruct.m_scmd_flag = 1;
4928 g_cdvdman_istruct.m_last_error =
SCECdErNO;
4929 g_cdvdman_istruct.m_last_read_timeout = 0;
4930 g_cdvdman_spinctl = -1;
4931 SetEventFlag(g_cdvdman_intr_evfid, 0x29);
4932 SetEventFlag(g_ncmd_evfid, 1);
4933 SetEventFlag(g_scmd_evfid, 1);
4934 SetEventFlag(g_sfile_evfid, 1);
4938 static int set_prev_command(
int cmd,
const char *sdata,
int sdlen,
char *rdata,
int rdlen,
int check_sef)
4944 #ifdef CDVD_VARIANT_XOSD
4948 #ifdef CDVD_VARIANT_XOSD
4956 VERBOSE_KPRINTF(1,
"set_prev_command cmd %02x call\n", cmd);
4959 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
4962 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
4965 VERBOSE_KPRINTF(1,
"set_prev_command Double Booking\n");
4966 #ifdef CDVD_VARIANT_XOSD
4969 SetEventFlag(g_cdvdman_csys_evfid, 1);
4974 g_cdvdman_istruct.m_scmd = cmd;
4975 g_cdvdman_istruct.m_sdlen = sdlen;
4976 g_cdvdman_istruct.m_rdlen = rdlen;
4977 for ( i = 0; i < sdlen; i += 1 )
4979 g_cdvdman_istruct.m_scmd_sd[i] = sdata[i];
4981 #ifdef CDVD_VARIANT_XOSD
4982 if ( update_cd_mode_ps2_atapi() != 1 )
4985 if ( g_cdvdman_istruct.m_wait_flag )
4987 g_cdvdman_istruct.m_scmd_flag = 1;
4988 cdvdman_write_scmd(&g_cdvdman_istruct);
4992 while ( (dmac_ch_get_chcr(3) & 0x1000000) && !g_cdvdman_istruct.m_wait_flag )
4994 VERBOSE_KPRINTF(1,
"set_prev_command: DMA Wait\n");
4996 g_cdvdman_istruct.m_scmd_flag = 1;
4997 cdvdman_write_scmd(&g_cdvdman_istruct);
5001 g_cdvdman_istruct.m_scmd_flag = 0;
5004 #ifdef CDVD_VARIANT_XOSD
5009 if ( g_cd_atapi_evfid != -1 )
5011 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
5013 if ( g_adma_evfid != -1 )
5015 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5017 if ( g_acmd_evfid != -1 )
5019 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5026 set_cdvd_dev5_base_addr_atapi(2);
5027 g_cdvdman_istruct.m_scmd_flag = 1;
5028 VERBOSE_KPRINTF(1,
"do_set_prev_command %02x\n", cmd);
5029 cdvdman_write_scmd(&g_cdvdman_istruct);
5030 set_cdvd_dev5_base_addr_atapi(1);
5035 if ( g_acmd_evfid != -1 )
5037 SetEventFlag(g_acmd_evfid, 1);
5039 if ( g_adma_evfid != -1 )
5041 SetEventFlag(g_adma_evfid, 1);
5043 if ( g_cd_atapi_evfid != -1 )
5045 SetEventFlag(g_cd_atapi_evfid, 3);
5051 for ( i = 0; i < 500; i += delaybackoff )
5053 if ( g_cdvdman_istruct.m_scmd_flag )
5055 for ( j = 0; j < rdlen; j += 1 )
5057 rdata[j] = g_cdvdman_istruct.m_scmd_rd[j];
5059 if ( check_sef == 1 )
5061 vSetEventFlag(g_scmd_evfid, 1);
5063 #ifdef CDVD_VARIANT_XOSD
5064 VERBOSE_KPRINTF(1,
"set_prev_command end :%02x\n", (u8)g_cdvdman_istruct.m_scmd);
5067 SetEventFlag(g_cdvdman_csys_evfid, 1);
5070 return (u8)g_cdvdman_istruct.m_scmd;
5072 vDelayThread(1000 * delaybackoff);
5073 if ( (i & 1) && delaybackoff < 16 )
5078 g_cdvdman_istruct.m_scmd_flag = 1;
5079 if ( check_sef == 1 )
5081 vSetEventFlag(g_scmd_evfid, 1);
5092 USE_DEV5_MMIO_HWPORT();
5095 VERBOSE_KPRINTF(1,
"in:%d out_size:%d \n", (u8)s->m_sdlen, (u8)s->m_rdlen);
5097 VERBOSE_KPRINTF(1,
"cmd:%02x pram:%02x\n", (u8)s->m_scmd, (u8)s->m_scmd_sd[0]);
5098 for ( i = 0; i <= 0; i += 1 )
5101 #ifdef CDVD_VARIANT_XOSD
5105 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5110 VERBOSE_KPRINTF(1,
"do_set_prev_command BUSY ABNORM END %08x\n", dev5_mmio_hwport->m_dev5_reg_017);
5113 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5117 for ( j = 0; j < (u8)s->m_sdlen; j += 1 )
5119 dev5_mmio_hwport->m_dev5_reg_017 = s->m_scmd_sd[j];
5121 dev5_mmio_hwport->m_dev5_reg_016 = s->m_scmd;
5122 #ifdef CDVD_VARIANT_XOSD
5130 #ifdef CDVD_VARIANT_XOSD
5136 for ( j = 0; dev5_mmio_hwport->m_dev5_reg_017 & 0x80; j += 1 )
5148 for ( j = 0; dev5_mmio_hwport->m_dev5_reg_017 & 0x80; j += 1 )
5154 VERBOSE_KPRINTF(1,
"Mecacon Scmd TIMEOUT CMD= %02x\n", (u8)s->m_scmd);
5162 for ( j = 0; j < (u8)s->m_rdlen; j += 1 )
5164 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5168 rdptr1[j] = dev5_mmio_hwport->m_dev5_reg_018;
5170 if ( j >= (u8)s->m_rdlen )
5173 VERBOSE_KPRINTF(1,
"Prev Cmd Result Over Flow\n", rdptr1);
5176 if ( (!overflowcond && j >= (u8)s->m_rdlen) || s->m_rdlen == 16 )
5180 VERBOSE_KPRINTF(1,
"Prev Cmd Result Illegal Size Try count:%d\n", i);
5189 for ( j = 0; j < (
sizeof(s->m_scmd_rd) /
sizeof(s->m_scmd_rd[0])); j += 1 )
5191 s->m_scmd_rd[j] = 0;
5193 if ( s->m_rdlen != (
sizeof(s->m_scmd_rd) /
sizeof(s->m_scmd_rd[0])) )
5195 rdcnt = (u8)s->m_rdlen;
5197 for ( j = 0; j < rdcnt; j += 1 )
5199 s->m_scmd_rd[j] = rdptr1[j];
5206 #ifdef CDVD_VARIANT_XOSD
5207 static int cdvdman_write_scmd_swap_dev5(
char cmd,
const char *wdata,
int sdlen,
char *rdata,
int rdlen,
int check_sef)
5215 USE_DEV5_MMIO_HWPORT();
5217 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5222 atapi_check = update_cd_mode_ps2_atapi() == 1;
5225 set_cdvd_dev5_base_addr_atapi(2);
5227 for ( i = 0; i <= 0; i += 1 )
5231 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5235 set_cdvd_dev5_base_addr_atapi(1);
5238 if ( check_sef == 1 )
5240 vSetEventFlag(g_scmd_evfid, 1);
5244 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5248 for ( j = 0; j < sdlen; j += 1 )
5250 dev5_mmio_hwport->m_dev5_reg_017 = wdata[j];
5252 dev5_mmio_hwport->m_dev5_reg_016 = cmd;
5253 while ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5258 for ( j = 0; !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40); j += 1 )
5263 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Over Flow\n");
5266 rdstart[j] = dev5_mmio_hwport->m_dev5_reg_018;
5268 if ( (!cmdresoverflow && j >= rdlen) || rdlen == 16 )
5272 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Illegal Size Try count:%d\n", i);
5273 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x20) )
5277 for ( j = 0; j < 16 - rdlen; j += 1 )
5285 set_cdvd_dev5_base_addr_atapi(1);
5288 if ( check_sef == 1 )
5290 vSetEventFlag(g_scmd_evfid, 1);
5294 for ( j = 0; j < rdlen; j += 1 )
5296 rdata[j] = rdstart[j];
5300 set_cdvd_dev5_base_addr_atapi(1);
5303 if ( check_sef == 1 )
5305 vSetEventFlag(g_scmd_evfid, 1);
5311 static int cdvdman_send_scmd2(
int cmd,
const void *sdata,
int sdlen,
void *rdata,
int rdlen,
int check_sef)
5317 USE_DEV5_MMIO_HWPORT();
5319 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5323 for ( i = 0; i <= 0; i += 1 )
5327 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5329 if ( check_sef == 1 )
5331 vSetEventFlag(g_scmd_evfid, 1);
5335 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5339 for ( j = 0; j < sdlen; j += 1 )
5341 dev5_mmio_hwport->m_dev5_reg_017 = ((u8 *)sdata)[j];
5343 dev5_mmio_hwport->m_dev5_reg_016 = cmd;
5344 while ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5346 #ifndef CDVD_VARIANT_XOSD
5351 for ( j = 0; !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40); j += 1 )
5357 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Over Flow\n");
5360 rdstart[j] = dev5_mmio_hwport->m_dev5_reg_018;
5362 if ( (!cmdresoverflow && j >= rdlen) || rdlen == 16 )
5367 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Illegal Size Try count:%d\n", i);
5368 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x20) )
5372 for ( j = 0; j < 16 - rdlen; j += 1 )
5377 if ( check_sef == 1 )
5379 vSetEventFlag(g_scmd_evfid, 1);
5383 for ( i = 0; i < rdlen; i += 1 )
5385 ((
char *)rdata)[i] = rdstart[i];
5387 if ( check_sef == 1 )
5389 vSetEventFlag(g_scmd_evfid, 1);
5394 #ifdef CDVD_VARIANT_OSD
5395 static unsigned int signal_sema_timeout_callback(
void *userdata)
5399 sema_id = (int)(u32)(uiptr)userdata;
5400 iSignalSema(sema_id);
5409 #ifdef CDVD_VARIANT_OSD
5410 if ( g_cdvdman_minver_50000 )
5412 WaitSema(g_cdvdman_apply_scmd_sema);
5415 for ( i = 0; i <= 2500; i += 1 )
5417 if ( set_prev_command(cmdNum, (
const char *)inBuff, inBuffSize, (
char *)outBuff, 16, 1) )
5419 #ifdef CDVD_VARIANT_OSD
5420 if ( g_cdvdman_minver_50000 )
5426 SetAlarm(&sysclk, signal_sema_timeout_callback, (
void *)g_cdvdman_apply_scmd_sema);
5437 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5441 int sceCdApplySCmd2(u8 cmdNum,
const void *inBuff,
unsigned long int inBuffSize,
void *outBuff)
5443 #ifdef CDVD_VARIANT_XOSD
5448 for ( i = 0; i <= 2500; i += 1 )
5450 if ( cdvdman_send_scmd2(cmdNum, inBuff, inBuffSize, outBuff, 16, 1) )
5456 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5461 #ifdef CDVD_VARIANT_OSD
5462 int sceCdApplySCmd3(u8 cmdNum,
const void *inBuff,
unsigned long int inBuffSize,
void *outBuff)
5466 for ( i = 0; i <= 2500; i += 1 )
5469 if ( set_prev_command((u8)cmdNum, inBuff, inBuffSize, outBuff, 16, 1) )
5475 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5485 USE_DEV5_MMIO_HWPORT();
5487 if ( PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5495 "Break call: read2_flg= %d func= %d lsn= %d csec= %d nsec= %d %rsec= %d addr= %p waitflg= %d, DriveIntrReq= %d "
5496 "stmflg= %d recover= %d\n",
5497 g_cdvdman_istruct.m_read2_flag,
5499 g_cdvdman_istruct.m_cdvdman_lsn,
5500 g_cdvdman_istruct.m_cdvdman_csec,
5501 g_cdvdman_istruct.m_cdvdman_nsec,
5502 g_cdvdman_istruct.m_cdvdman_rsec,
5503 g_cdvdman_istruct.m_read_buf,
5504 g_cdvdman_istruct.m_wait_flag,
5505 g_cdvdman_istruct.m_drive_interupt_request,
5506 g_cdvdman_istruct.m_stream_flag,
5507 g_cdvdman_istruct.m_recover_status);
5508 if ( g_cdvdman_istruct.m_last_read_timeout )
5510 g_cdvdman_istruct.m_read2_flag = 0;
5513 g_cdvdman_istruct.m_thread_id = GetThreadId();
5514 g_cdvdman_istruct.m_break_cdvdfsv_readchain = 1;
5515 if ( g_cdvdman_istruct.m_dec_state )
5517 g_cdvdman_istruct.m_dec_shift = 0;
5518 g_cdvdman_istruct.m_check_version = 0;
5519 g_cdvdman_istruct.m_dec_state = 0;
5522 g_cdvdman_istruct.m_recover_status = 0;
5525 iSetEventFlag(g_cdvdman_intr_evfid, 0x29);
5526 iCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
5530 SetEventFlag(g_cdvdman_intr_evfid, 0x29);
5531 CancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
5533 if ( !g_cdvdman_istruct.m_wait_flag || g_cdvdman_istruct.m_last_read_timeout )
5538 VERBOSE_KPRINTF(1,
"cdvd: NonInter END\n");
5539 g_cdvdman_istruct.m_wait_flag = 1;
5541 g_cdvdman_last_cmdfunc = g_cdvdman_cmdfunc;
5542 g_cdvdman_cmdfunc = SCECdFuncBreak;
5543 dev5_mmio_hwport->m_dev5_reg_007 = 1;
5544 if ( g_cdvdman_istruct.m_last_read_timeout )
5548 g_cdvdman_istruct.m_drive_interupt_request = 0;
5549 VERBOSE_KPRINTF(1,
"cdvd: Abort command On\n");
5551 vSetEventFlag(g_ncmd_evfid, 1);
5556 static unsigned int ncmd_timeout_alarm_cb(
void *userdata)
5561 KPRINTF(
"Cmd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
5566 static int intrh_dma_3(
void *userdata)
5573 s->m_dma3_param.m_dma3_msectors -= s->m_dma3_param.m_dma3_csectors;
5577 "_sceCdDmaIntr wk %d: func_num: %d nsec %d cnt %d cdid:%08x\n",
5580 s->m_dma3_param.m_dma3_msectors,
5581 s->m_cdvdman_dma3sec,
5582 &g_cdvdman_istruct);
5583 dmacbres = s->m_dma3_param.m_dma3_callback ? s->m_dma3_param.m_dma3_callback() : 1;
5584 s->m_cdvdman_dma3sec += s->m_dma3_param.m_dma3_csectors;
5585 s->m_dma3_param.m_dma3_csectors = ((u32)s->m_read_chunk > (u32)s->m_dma3_param.m_dma3_msectors) ?
5586 (u32)s->m_dma3_param.m_dma3_msectors :
5587 (u32)s->m_read_chunk;
5590 if ( s->m_dma3_param.m_dma3_msectors )
5592 dmac_ch_set_chcr(3, 0);
5593 dmac_ch_get_chcr(3);
5594 dmac_ch_set_madr(3, (u32)s->m_dma3_param.m_dma3_maddress);
5597 ((s->m_dma3_param.m_dma3_blkcount * s->m_dma3_param.m_dma3_csectors) << 16) | s->m_dma3_param.m_dma3_blkwords);
5598 dmac_ch_set_chcr(3, 0x41000200);
5599 dmac_ch_get_chcr(3);
5600 iClearEventFlag(g_cdvdman_intr_evfid, ~0x20);
5605 iSetEventFlag(g_cdvdman_intr_evfid, 0x20);
5608 if ( !s->m_dma3_param.m_dma3_msectors && s->m_drive_interupt_request )
5611 s->m_drive_interupt_request = 0;
5618 USE_DEV5_MMIO_HWPORT();
5620 if ( (dmac_ch_get_chcr(3) & 0x1000000) )
5622 dev5_mmio_hwport->m_dev5_reg_007 = 1;
5624 g_cdvdman_istruct.m_drive_interupt_request = 0;
5625 g_cdvdman_istruct.m_dma3_param.m_dma3_blkwords = dma3_param->m_dma3_blkwords;
5626 g_cdvdman_istruct.m_dma3_param.m_dma3_blkcount = dma3_param->m_dma3_blkcount;
5627 g_cdvdman_istruct.m_dma3_param.m_dma3_maddress = dma3_param->m_dma3_maddress;
5628 g_cdvdman_istruct.m_dma3_param.m_dma3_callback = dma3_param->m_dma3_callback;
5629 g_cdvdman_istruct.m_dma3_param.m_dma3_csectors = dma3_param->m_dma3_csectors;
5630 g_cdvdman_istruct.m_dma3_param.m_cdvdreg_howto = dma3_param->m_cdvdreg_howto;
5631 g_cdvdman_istruct.m_dma3_param.m_dma3_msectors = dma3_param->m_dma3_msectors;
5632 g_cdvdman_istruct.m_cdvdman_dma3sec = 0;
5633 dmac_ch_set_chcr(3, 0);
5634 dmac_ch_get_chcr(3);
5635 if ( dma3_param->m_dma3_csectors )
5637 vClearEventFlag(g_cdvdman_intr_evfid, ~0x20);
5640 dev5_mmio_hwport->m_dev5_reg_006 = dma3_param->m_cdvdreg_howto;
5641 dmac_ch_set_madr(3, (u32)dma3_param->m_dma3_maddress);
5644 (dma3_param->m_dma3_blkcount * (dma3_param->m_dma3_csectors ? dma3_param->m_dma3_csectors : 1)) << 16
5645 | dma3_param->m_dma3_blkwords);
5646 dmac_ch_set_chcr(3, 0x41000200);
5647 return dmac_ch_get_chcr(3);
5650 #ifdef CDVD_VARIANT_XOSD
5651 static int update_cd_mode_ps2_atapi(
void)
5653 int is_intr_context;
5654 int saved_cd_mode_ps2_atapi;
5658 if ( is_intr_context )
5662 saved_cd_mode_ps2_atapi = g_cdvdman_istruct.m_cd_mode_ps2_atapi;
5663 if ( saved_cd_mode_ps2_atapi == 1 )
5665 if ( !(*g_cdvdreg_bf801460 & 2) || (
unsigned int)GetBaseAddress(5) != (
unsigned int)0xBF410000 )
5667 set_cdvd_dev5_base_addr_atapi(1);
5672 if ( (*g_cdvdreg_bf801460 & 2) || (
unsigned int)GetBaseAddress(5) != (
unsigned int)0x1F402000 )
5674 set_cdvd_dev5_base_addr_atapi(2);
5677 if ( is_intr_context )
5681 return saved_cd_mode_ps2_atapi;
5685 #ifdef CDVD_VARIANT_XOSD
5686 static int set_cdvd_dev5_base_addr_atapi(
int mode)
5688 int is_intr_context;
5692 if ( is_intr_context )
5698 SetBaseAddress(5, 0xBF410000);
5699 VERBOSE_KPRINTF(1,
"DEV5-addr : 0x%08lx\n", GetBaseAddress(5));
5700 SetDelay(5, 0xEF101043);
5701 VERBOSE_KPRINTF(1,
"DEV5-dely : 0x%08lx\n", GetDelay(5));
5702 *g_cdvdreg_bf801464 |= 0xC;
5703 *g_cdvdreg_bf801460 |= 0x40;
5704 *g_cdvdreg_bf801460 |= 2;
5708 SetBaseAddress(5, 0x1F402000);
5709 VERBOSE_KPRINTF(1,
"DEV5-addr : 0x%08lx\n", GetBaseAddress(5));
5710 SetDelay(5, 0x6F060011);
5711 VERBOSE_KPRINTF(1,
"DEV5-dely : 0x%08lx\n", GetDelay(5));
5712 *g_cdvdreg_bf801460 &= ~2;
5713 *g_cdvdreg_bf801460 &= ~0x40;
5714 *g_cdvdreg_bf801464 &= 0xF3;
5716 if ( is_intr_context )
5724 #ifdef CDVD_VARIANT_XOSD
5725 static int cdvdman_change_drive(
int mode)
5727 ClearEventFlag(g_cdvdman_csys_evfid, ~1);
5730 VERBOSE_KPRINTF(1,
"Init Go SCECdChgWriDrv\n");
5731 ClearEventFlag(g_fio_fsv_evfid, ~1);
5732 ClearEventFlag(g_sfile_evfid, ~1);
5733 ClearEventFlag(g_scmd_evfid, ~1);
5734 ClearEventFlag(g_ncmd_evfid, ~1);
5735 set_cdvd_dev5_base_addr_atapi(1);
5736 if ( g_cd_atapi_evfid != -1 )
5738 SetEventFlag(g_cd_atapi_evfid, 3);
5740 if ( g_adma_evfid != -1 )
5742 SetEventFlag(g_adma_evfid, 1);
5744 if ( g_acmd_evfid != -1 )
5746 SetEventFlag(g_acmd_evfid, 1);
5748 SetEventFlag(g_scmd_evfid, 1);
5749 VERBOSE_KPRINTF(1,
"Init Go SCECdChgWriDrv End.\n");
5750 SetEventFlag(g_fio_fsv_evfid, 1);
5754 VERBOSE_KPRINTF(1,
"Init Go SCECdChgPs2Drv\n");
5755 ClearEventFlag(g_scmd_evfid, ~1);
5756 if ( g_acmd_evfid != -1 )
5758 ClearEventFlag(g_acmd_evfid, ~1);
5760 if ( g_adma_evfid != -1 )
5762 ClearEventFlag(g_adma_evfid, ~1);
5764 if ( g_cd_atapi_evfid != -1 )
5766 ClearEventFlag(g_cd_atapi_evfid, ~3);
5768 set_cdvd_dev5_base_addr_atapi(mode);
5769 SetEventFlag(g_ncmd_evfid, 1);
5770 SetEventFlag(g_scmd_evfid, 1);
5771 SetEventFlag(g_sfile_evfid, 1);
5772 SetEventFlag(g_fio_fsv_evfid, 1);
5773 VERBOSE_KPRINTF(1,
"Init Go SCECdChgPs2Drv End.\n");
5775 SetEventFlag(g_cdvdman_csys_evfid, 1);
5780 #ifdef CDVD_VARIANT_XOSD
5786 USE_DEV5_MMIO_HWPORT();
5788 VERBOSE_KPRINTF(1,
"sceCdChgSys(%d) start.\n", use_writer_drive);
5793 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5794 current_mode = update_cd_mode_ps2_atapi();
5796 1,
"sceCdChgSys %d call mode:%d->%d\n", use_writer_drive, current_mode, g_cdvdman_istruct.m_cd_mode_ps2_atapi);
5797 if ( !use_writer_drive )
5799 g_cdvdman_istruct.m_cd_mode_ps2_atapi = current_mode;
5803 && (use_writer_drive != (u32)current_mode || g_cdvdman_istruct.m_cd_mode_ps2_atapi != current_mode) )
5807 if ( use_writer_drive == 1 )
5809 VERBOSE_KPRINTF(1,
"Go SCECdChgWriDrv\n");
5810 VERBOSE_KPRINTF(1,
"fio_fsv_evfid\n");
5811 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5812 VERBOSE_KPRINTF(1,
"sfile_evfid\n");
5813 WaitEventFlag(g_sfile_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5814 VERBOSE_KPRINTF(1,
"sceCdSync\n");
5816 VERBOSE_KPRINTF(1,
"scmd_evfid\n");
5817 WaitEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5818 VERBOSE_KPRINTF(1,
"ncmd_evfid\n");
5819 WaitEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5820 set_cdvd_dev5_base_addr_atapi(2);
5821 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5822 if ( g_cdvdman_vernotxxx1x )
5826 g_cdvdman_istruct.m_chgsys_writer_drive_shell_is_open = 1;
5829 (!(dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen))
5837 VERBOSE_KPRINTF(1,
"GO->Atapi sceCdChgSpdlCtrl Call %d\n", 0);
5838 while ( !sceCdChgSpdlCtrl(0) )
5846 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl ERR 0x%02x\n", last_err);
5847 DelayThread(250000);
5850 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl OK\n", last_err);
5853 set_cdvd_dev5_base_addr_atapi(1);
5854 g_cdvdman_istruct.m_cd_mode_ps2_atapi = 1;
5856 g_cdvdman_vernotxxx1x && disc_type !=
SCECdNODISC && g_cdvdman_istruct.m_chgsys_callback_next_disktype_last
5857 && g_cdvdman_istruct.m_chgsys_callback )
5862 i < 10 && g_cdvdman_istruct.m_chgsys_callback(&g_cdvdman_istruct.m_chgsys_callback_next_disktype, 1);
5867 g_cdvdman_istruct.m_chgsys_callback_next_disktype_last =
SCECdNODISC;
5869 if ( g_cd_atapi_evfid != -1 )
5871 SetEventFlag(g_cd_atapi_evfid, 3);
5873 if ( g_adma_evfid != -1 )
5875 SetEventFlag(g_adma_evfid, 1);
5877 if ( g_acmd_evfid != -1 )
5879 SetEventFlag(g_acmd_evfid, 1);
5881 SetEventFlag(g_scmd_evfid, 1);
5882 SetEventFlag(g_fio_fsv_evfid, 1);
5883 VERBOSE_KPRINTF(1,
"Go SCECdChgWriDrv End.\n");
5887 VERBOSE_KPRINTF(1,
"Go SCECdChgPs2Drv\n");
5888 VERBOSE_KPRINTF(1,
"scmd_evfid\n");
5889 WaitEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5890 if ( g_acmd_evfid != -1 )
5892 VERBOSE_KPRINTF(1,
"g_acmd_evfid Wait\n");
5893 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5895 if ( g_adma_evfid != -1 )
5897 VERBOSE_KPRINTF(1,
"g_adma_evfid Wait\n");
5898 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5900 if ( g_cd_atapi_evfid != -1 )
5902 VERBOSE_KPRINTF(1,
"g_cd_atapi_evfid Wait\n");
5903 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
5905 VERBOSE_KPRINTF(1,
"evflg Ok\n");
5906 set_cdvd_dev5_base_addr_atapi(1);
5907 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5908 if ( g_cdvdman_vernotxxx1x )
5910 set_cdvd_dev5_base_addr_atapi(2);
5911 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5912 set_cdvd_dev5_base_addr_atapi(1);
5913 VERBOSE_KPRINTF(1,
"GO->PS2 STOP ATAPI SPINDL\n");
5914 if ( disc_type == 6 && g_cdvdman_istruct.m_chgsys_callback )
5919 i < 10 && g_cdvdman_istruct.m_chgsys_callback(&g_cdvdman_istruct.m_chgsys_callback_next_disktype, 0);
5926 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5928 VERBOSE_KPRINTF(1,
"Atapi Set -> Dragon Media %d\n", g_cdvdman_istruct.m_chgsys_callback_next_disktype);
5929 if ( g_cdvdman_istruct.m_chgsys_callback_next_disktype == 256 )
5931 g_cdvdman_istruct.m_chgsys_callback_next_disktype_last = g_cdvdman_istruct.m_chgsys_callback_next_disktype;
5932 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5936 set_cdvd_dev5_base_addr_atapi(use_writer_drive);
5937 g_cdvdman_istruct.m_cd_mode_ps2_atapi = use_writer_drive;
5938 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5939 if ( g_cdvdman_vernotxxx1x )
5942 ((dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen))
5952 g_cdvdman_istruct.m_chgsys_callback_next_disktype =
SCECdDETCT;
5956 "GO->DRAGON sceCdChgSpdlCtrl Call %d Ps2MediaType %02x\n",
5957 g_cdvdman_istruct.m_chgsys_callback_next_disktype,
5959 while ( !sceCdChgSpdlCtrl(g_cdvdman_istruct.m_chgsys_callback_next_disktype) )
5967 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl ERR 0x%02x\n", last_err);
5968 DelayThread(250000);
5971 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl OK\n");
5976 VERBOSE_KPRINTF(1,
" -> Ps2 May be No media %08x\n", disc_type);
5978 SetEventFlag(g_ncmd_evfid, 1);
5979 SetEventFlag(g_scmd_evfid, 1);
5980 SetEventFlag(g_sfile_evfid, 1);
5981 SetEventFlag(g_fio_fsv_evfid, 1);
5982 VERBOSE_KPRINTF(1,
"Go SCECdChgPs2Drv End.\n");
5985 SetEventFlag(g_cdvdman_csys_evfid, 1);
5986 return current_mode;
5991 cdvdman_send_ncmd(
int ncmd,
const void *ndata,
int ndlen,
int func,
cdvdman_dma3_parameter_t *dma3_param,
int check_cb)
5995 USE_DEV5_MMIO_HWPORT();
5997 if ( check_cb == 1 && PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6003 (
sceCdDiskReady(8) & 0xC0) != 0x40 || !g_cdvdman_istruct.m_wait_flag
6004 || !(g_cdvdman_istruct.m_read2_flag != 1 || ncmd == 8) || !(g_cdvdman_istruct.m_read2_flag != 2 || ncmd == 6) )
6006 if ( check_cb == 1 )
6008 vSetEventFlag(g_ncmd_evfid, 1);
6011 VERBOSE_KPRINTF(1,
"set_cd_commnad Error\tstat %02x\n", (u8)
sceCdDiskReady(8));
6014 g_cdvdman_iocache = 0;
6017 cdvdman_setdma3(dma3_param);
6019 g_cdvdman_cmdfunc = func;
6022 !g_cdvdman_minver_10700 && g_cdvdman_ncmd == 0x06 && ncmd && ncmd != g_cdvdman_ncmd && ncmd != 0x07 && ncmd != 0x0E
6024 #ifdef CDVD_VARIANT_XOSD
6029 g_cdvdman_ncmd_timeout.hi = 0;
6030 g_cdvdman_ncmd_timeout.lo = 0x6978000;
6031 vSetAlarm(&g_cdvdman_ncmd_timeout, ncmd_timeout_alarm_cb, &g_cdvdman_ncmd_timeout);
6034 VERBOSE_KPRINTF(1,
"Read Pause 1 chk status 0x%02x\n", dev5_mmio_hwport->m_dev5_reg_00A);
6035 if ( !g_cdvdman_ncmd_timeout.lo )
6037 g_cdvdman_ncmd = ncmd;
6038 if ( check_cb == 1 )
6040 vSetEventFlag(g_ncmd_evfid, 1);
6042 KPRINTF(
"Time Out Pause WAIT set_cd_commnad\n");
6047 vCancelAlarm(ncmd_timeout_alarm_cb, &g_cdvdman_ncmd_timeout);
6049 g_cdvdman_ncmd = ncmd;
6050 if ( g_cdvdman_istruct.m_dec_state )
6052 sceCdDecSet(!!g_cdvdman_istruct.m_dec_shift, 1, g_cdvdman_istruct.m_dec_shift);
6054 g_cdvdman_istruct.m_last_read_timeout = 0;
6055 g_cdvdman_istruct.m_cdvdman_command = ncmd;
6056 g_cdvdman_istruct.m_last_error =
SCECdErNO;
6057 g_cdvdman_istruct.m_wait_flag = 0;
6058 g_cdvdman_istruct.m_thread_id = GetThreadId();
6061 iClearEventFlag(g_cdvdman_intr_evfid, ~1);
6065 ClearEventFlag(g_cdvdman_intr_evfid, ~1);
6067 for ( i = 0; i < ndlen; i += 1 )
6069 dev5_mmio_hwport->m_dev5_reg_005 = ((u8 *)ndata)[i];
6071 dev5_mmio_hwport->m_dev5_reg_004 = ncmd;
6072 if ( check_cb == 1 )
6074 vSetEventFlag(g_ncmd_evfid, 1);
6081 VERBOSE_KPRINTF(1,
"Apply NCmd call cmd= 0x%02x\n", cmdNum);
6082 while ( cdvdman_send_ncmd(cmdNum, inBuff, inBuffSize, 0, 0, 1) < 0 )
6090 int sceCdCheckCmd(
void)
6092 return g_cdvdman_istruct.m_wait_flag;
6095 static int cdvdman_mediactl(
int code)
6101 #ifndef CDVD_VARIANT_XOSD
6102 USE_DEV5_MMIO_HWPORT();
6106 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6110 #ifdef CDVD_VARIANT_XOSD
6115 if ( reg_00B_tmp_1 == g_cdvdman_chmedia )
6118 if ( g_cdvdman_chflags[code] )
6120 g_cdvdman_chflags[code] = 0;
6128 for ( i = 0; i < (
sizeof(g_cdvdman_chflags) /
sizeof(g_cdvdman_chflags[0])); i += 1 )
6130 g_cdvdman_chflags[i] = i != (
unsigned int)code;
6134 #ifdef CDVD_VARIANT_XOSD
6140 while ( !set_prev_command(0x05, NULL, 0, rdata,
sizeof(rdata), 0) || rdata[0] )
6145 #ifdef CDVD_VARIANT_XOSD
6146 g_cdvdman_chmedia = get_cdvd_register(0x0B) & 1;
6150 vSetEventFlag(g_scmd_evfid, 1);
6156 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
6158 VERBOSE_KPRINTF(1,
"sceCdGetError: 0x%02x\n", (u8)g_cdvdman_istruct.m_last_error);
6160 return (u8)g_cdvdman_istruct.m_last_error;
6164 int cdvdman_get_last_command(
void)
6166 return (u8)g_cdvdman_istruct.m_cdvdman_command;
6172 return cdvdman_send_ncmd(0x00, NULL, 0, 0, 0, 1) >= 0;
6176 int cdvdman_ncmd_sender_01(
void)
6178 return cdvdman_send_ncmd(0x01, NULL, 0, 0, 0, 1) >= 0;
6182 #ifndef CDVD_VARIANT_XOSD
6183 static int cdvdman_ncmd_sender_06(
void)
6194 for ( i = 0; i < 48; i += 8 )
6197 KPRINTF(
"CMD_READP call\n");
6209 dma3_param.m_cdvdreg_howto = 128;
6210 dma3_param.m_dma3_blkwords = 32;
6211 dma3_param.m_dma3_blkcount = 128;
6212 dma3_param.m_dma3_csectors = 0;
6213 dma3_param.m_dma3_msectors = 0;
6214 dma3_param.m_dma3_callback = 0;
6215 dma3_param.m_dma3_maddress = g_cdvdman_ptoc;
6216 if ( cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 5, &dma3_param, 1) < 0 )
6231 #ifdef CDVD_VARIANT_XOSD
6232 switch ( get_disk_type_ex() )
6246 dma3_param.m_cdvdreg_howto = 128;
6247 dma3_param.m_dma3_blkwords = 32;
6248 dma3_param.m_dma3_blkcount = 16;
6257 dma3_param.m_dma3_csectors = 0;
6258 dma3_param.m_dma3_msectors = 0;
6259 dma3_param.m_dma3_callback = 0;
6260 dma3_param.m_dma3_maddress = g_cdvdman_ptoc;
6261 return cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 5, &dma3_param, 1) >= 0;
6263 return cdvdman_send_ncmd(0x02, NULL, 0, 5, 0, 1) >= 0;
6269 return cdvdman_send_ncmd(0x03, NULL, 0, 6, 0, 1) >= 0;
6274 return cdvdman_send_ncmd(0x04, NULL, 0, 7, 0, 1) >= 0;
6278 int cdvdman_ncmd_sender_0B(
void)
6283 return cdvdman_send_ncmd(0x0B, ndata,
sizeof(ndata), 0, 0, 1) >= 0;
6287 static unsigned int readtoc_timeout_alarm_cb(
void *userdata)
6290 USE_DEV5_MMIO_HWPORT();
6293 KPRINTF(
"Cmd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
6294 dev5_mmio_hwport->m_dev5_reg_007 = 1;
6299 static int cdvdman_readtoc(u8 *
toc,
int param,
int func)
6306 #ifdef CDVD_VARIANT_XOSD
6307 switch ( get_disk_type_ex() )
6316 dma3_param.m_cdvdreg_howto = 132;
6317 dma3_param.m_dma3_blkwords = 4;
6318 dma3_param.m_dma3_blkcount = 129;
6319 dma3_param.m_dma3_maddress =
toc;
6320 dma3_param.m_dma3_msectors = 0;
6321 dma3_param.m_dma3_csectors = 0;
6322 dma3_param.m_dma3_callback = 0;
6330 dma3_param.m_cdvdreg_howto = 128;
6331 dma3_param.m_dma3_blkwords = 32;
6332 dma3_param.m_dma3_blkcount = 8;
6333 dma3_param.m_dma3_maddress =
toc;
6334 dma3_param.m_dma3_msectors = 0;
6335 dma3_param.m_dma3_csectors = 0;
6336 dma3_param.m_dma3_callback = 0;
6342 if ( cdvdman_send_ncmd(0x09, ndata,
sizeof(ndata), func, &dma3_param, 1) < 0 )
6347 sysclk.lo = 0x15F90000;
6348 vSetAlarm(&sysclk, readtoc_timeout_alarm_cb, &sysclk);
6350 vCancelAlarm(readtoc_timeout_alarm_cb, &sysclk);
6352 if ( g_cdvdman_minver_10700 && !
sceCdPause() )
6360 static int cdvdman_gettoc(u8 *
toc)
6363 VERBOSE_KPRINTF(1,
"sceCdReadToc() call 0x%p\n",
toc);
6364 return cdvdman_readtoc(
toc, 0, 3);
6367 #ifdef CDVD_VARIANT_OSD
6373 dma3_param.m_cdvdreg_howto = 140;
6374 dma3_param.m_dma3_blkwords = 12;
6375 dma3_param.m_dma3_blkcount = 43;
6376 dma3_param.m_dma3_maddress =
toc;
6377 dma3_param.m_dma3_msectors = 0;
6378 dma3_param.m_dma3_csectors = 0;
6379 dma3_param.m_dma3_callback = 0;
6381 return cdvdman_send_ncmd(0x09, ndata,
sizeof(ndata), 0, &dma3_param, 1) >= 0;
6387 int sector_sizes[4];
6389 sector_sizes[0] = 0x800;
6390 sector_sizes[1] = 0x918;
6391 sector_sizes[2] = 0x924;
6392 if ( g_cdvdman_istruct.m_recover_status && g_cdvdman_istruct.m_recover_status != 3 )
6396 if ( g_cdvdman_cmdfunc == SCECdFuncReadCDDA || g_cdvdman_cmdfunc == 12 )
6398 return dmac_ch_get_madr(3) - (uiptr)g_cdvdman_readbuf;
6400 if ( g_cdvdman_istruct.m_read2_flag )
6402 return g_cdvdman_readptr * sector_sizes[g_cdvdman_istruct.m_cdvdman_pattern];
6404 if ( g_cdvdman_cmdfunc == SCECdFuncRead )
6406 return dmac_ch_get_madr(3) - (uiptr)g_cdvdman_readbuf;
6411 static int cdvdman_speedctl(u32 spindlctrl,
int dvdflag, u32 maxlsn)
6415 switch ( spindlctrl )
6418 return dvdflag ? 2 : 4;
6424 if ( g_cdvdman_minver_10700 )
6428 #ifdef CDVD_VARIANT_OSD
6430 maxlsn_chk = 0x1C9000;
6432 maxlsn_chk = 0x128000;
6434 if ( g_cdvdman_istruct.m_opo_or_para )
6436 maxlsn -= (maxlsn >= (u32)g_cdvdman_istruct.m_layer_1_lsn) ? g_cdvdman_istruct.m_layer_1_lsn : 0;
6437 #ifdef CDVD_VARIANT_OSD
6439 maxlsn_chk = 0x197000;
6441 maxlsn_chk = 0x165000;
6444 if ( maxlsn >= maxlsn_chk )
6446 VERBOSE_KPRINTF(1,
"Kprob Spd D lsn= %d\n", maxlsn);
6456 return dvdflag ? 2 : 131;
6458 return dvdflag ? 3 : 4;
6462 return dvdflag ? 4 : 2;
6466 return dvdflag ? 130 : 131;
6468 return dvdflag ? 130 : 132;
6470 return dvdflag ? 1 : 131;
6472 return dvdflag ? 3 : 5;
6474 return dvdflag ? 131 : 133;
6478 static int cdvdman_isdvd(
void)
6481 #ifdef CDVD_VARIANT_XOSD
6482 switch ( get_disk_type_ex() )
6492 g_cdvdman_istruct.m_tray_is_open = 1;
6497 g_cdvdman_istruct.m_tray_is_open = 1;
6504 static int sceCdRead0_Rty(u32 lsn, u32 nsec,
void *buf,
const sceCdRMode *mode,
int ncmd,
int dintrsec,
void *func)
6509 g_cdvdman_readbuf = buf;
6510 VERBOSE_KPRINTF(1,
"sceCdRead0_Rty Lsn:%d nsec:%d dintrnsec %d func %08x\n", lsn, nsec, dintrsec, func);
6511 *(u32 *)ndata = lsn;
6512 *(u32 *)&ndata[4] = nsec;
6513 ndata[8] = mode->trycount;
6514 ndata[9] = cdvdman_speedctl(mode->spindlctrl, cdvdman_isdvd(), lsn + nsec);
6515 dma3_param.m_dma3_csectors = dintrsec;
6516 dma3_param.m_dma3_callback = (int (*)(void))func;
6517 dma3_param.m_dma3_msectors = nsec;
6518 dma3_param.m_dma3_maddress = buf;
6519 dma3_param.m_dma3_blkcount = (!(u16)dintrsec) ? nsec : 1;
6523 ndata[10] = mode->datapattern;
6524 switch ( mode->datapattern )
6527 dma3_param.m_dma3_blkwords = 6;
6528 dma3_param.m_dma3_blkcount *= 97;
6529 dma3_param.m_cdvdreg_howto = 134;
6532 dma3_param.m_dma3_blkwords = 15;
6533 dma3_param.m_dma3_blkcount *= 39;
6534 dma3_param.m_cdvdreg_howto = 143;
6538 dma3_param.m_dma3_blkwords = 32;
6539 dma3_param.m_dma3_blkcount *= 16;
6540 dma3_param.m_cdvdreg_howto = 128;
6545 dma3_param.m_dma3_blkwords = 12;
6546 dma3_param.m_dma3_blkcount *= 43;
6547 dma3_param.m_cdvdreg_howto = 140;
6553 return cdvdman_send_ncmd(ncmd, ndata,
sizeof(ndata), ncmd == 0x06 ? 1 : 14, &dma3_param, 0) >= 0;
6556 int sceCdRead0(u32 lsn, u32 sectors,
void *buffer,
sceCdRMode *mode,
int csec,
void *callback)
6562 if ( PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6568 "DVD/CD sceCdRead0 sec %d num %d spin %d trycnt %d dptn %d adr %08x\n",
6575 g_cdvdman_readbuf = buffer;
6576 dma3_param.m_dma3_csectors = (csec && (sectors < (u32)csec)) ? sectors : (u32)csec;
6577 dma3_param.m_dma3_callback = (int (*)(void))callback;
6578 dma3_param.m_dma3_msectors = sectors;
6579 dma3_param.m_dma3_blkcount = (!csec) ? sectors : 1;
6580 switch ( mode->datapattern )
6583 dma3_param.m_dma3_blkwords = 6;
6584 dma3_param.m_dma3_blkcount *= 97;
6585 dma3_param.m_cdvdreg_howto = 134;
6588 dma3_param.m_dma3_blkwords = 15;
6589 dma3_param.m_dma3_blkcount *= 39;
6590 dma3_param.m_cdvdreg_howto = 143;
6594 dma3_param.m_dma3_blkwords = 32;
6595 dma3_param.m_dma3_blkcount *= 16;
6596 dma3_param.m_cdvdreg_howto = 128;
6600 #ifdef CDVD_VARIANT_OSD
6601 g_cdvdman_istruct.m_dvd_flag = cdvdman_isdvd();
6609 if ( g_cdvdman_mmode != SCECdMmodeCd && g_cdvdman_mmode != 0xFF )
6611 vSetEventFlag(g_ncmd_evfid, 1);
6614 g_cdvdman_istruct.m_dvd_flag = 0;
6617 if ( g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF )
6619 vSetEventFlag(g_ncmd_evfid, 1);
6622 g_cdvdman_istruct.m_dvd_flag = 1;
6625 vSetEventFlag(g_ncmd_evfid, 1);
6629 g_cdvdman_istruct.m_read_mode = *mode;
6630 g_cdvdman_istruct.m_read_callback = callback;
6631 g_cdvdman_istruct.m_read_chunk = dma3_param.m_dma3_csectors;
6632 g_cdvdman_istruct.m_read_lsn = lsn;
6633 g_cdvdman_istruct.m_read_sectors = sectors;
6634 *(u32 *)ndata = lsn;
6635 *(u32 *)&ndata[4] = sectors;
6636 ndata[8] = mode->trycount;
6637 ndata[9] = cdvdman_speedctl(mode->spindlctrl, g_cdvdman_istruct.m_dvd_flag, lsn + sectors);
6638 g_cdvdman_istruct.m_read_buf = buffer;
6639 ndata[10] = mode->datapattern;
6640 dma3_param.m_dma3_maddress = buffer;
6641 VERBOSE_KPRINTF(1,
"Read Command call\n");
6642 if ( cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 1, &dma3_param, 0) < 0 )
6644 vSetEventFlag(g_ncmd_evfid, 1);
6647 vSetEventFlag(g_ncmd_evfid, 1);
6660 for ( i = 0; i < common->m_dma3_param.m_dma3_csectors; i += 1 )
6666 if ( common->m_read2_flag == 3 )
6669 cdrloc.
minute = cdvdman_syncdec(
6670 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock)]);
6671 cdrloc.
second = cdvdman_syncdec(
6672 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 1]);
6673 cdrloc.
sector = cdvdman_syncdec(
6674 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 2]);
6680 syncdec_res_1 = (u8)cdvdman_syncdec(
6681 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 3]);
6683 (u8)cdvdman_syncdec(
6684 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 2])
6687 (u8)cdvdman_syncdec(
6688 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 1])
6690 syncdec_res_4 = cdvdman_syncdec(
6691 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock)]);
6692 if ( !common->m_cdvdman_dma3sec && !common->m_interupt_read_state )
6694 common->m_interupt_read_state = (syncdec_res_4 & 0xC) | (((syncdec_res_4 & 0xC) && i) ? 0x80 : 0);
6696 cdreadlsn = (syncdec_res_1 - 0x30000) + (( common->m_opo_or_para && ((
unsigned int)(common->m_cdvdman_lsn + common->m_cdvdman_csec + i) >= common->m_layer_1_lsn && common->m_opo_or_para == 1) ) ? common->m_layer_1_lsn : 0);
6698 errlsn = common->m_cdvdman_lsn + common->m_cdvdman_csec + common->m_cdvdman_dma3sec + i;
6699 if ( cdreadlsn != (u32)errlsn )
6702 1,
"Read_IOP Sector_ID error lsn= %d readlsn= %d layer= %d\n", errlsn, cdreadlsn, (syncdec_res_4 & 1));
6706 if ( i == common->m_dma3_param.m_dma3_csectors )
6711 switch ( common->m_cdvdman_pattern )
6722 &((
char *)(common->m_cdvdman_rbuffer))[0x924 * common->m_cdvdman_dma3sec],
6723 (
const char *)g_cdvdman_ptoc,
6729 for ( i = 0; i < common->m_dma3_param.m_dma3_csectors; i += 1 )
6732 &((
char *)(common->m_cdvdman_rbuffer))[(common->m_cdvdman_dma3sec + i) * size],
6733 (
const char *)&g_cdvdman_ptoc[12 + (i * sblock)],
6737 g_cdvdman_readptr = common->m_cdvdman_csec + common->m_cdvdman_dma3sec;
6741 common->m_sync_error += 1;
6746 static int cdvdman_read(u32 lsn, u32 sectors,
void *buf,
sceCdRMode *mode,
int decflag,
int shift,
int ef1,
int ef2)
6754 dvd = cdvdman_isdvd();
6757 if ( !DvdDual_infochk() )
6761 vSetEventFlag(ef1, ef2);
6765 lsn = sceCdLsnDualChg(lsn);
6767 else if ( mode->datapattern == SCECdSecS2328 || (g_cdvdman_cd36key && !g_cdvdman_istruct.m_dec_state) )
6771 if ( g_cdvdman_cd36key && !g_cdvdman_istruct.m_dec_state && mode->spindlctrl ==
SCECdSpinNom )
6776 read0_res = sceCdRead0(lsn, sectors, buf, mode, 0, 0);
6779 vSetEventFlag(ef1, ef2);
6786 if ( ready != 0x40 || g_cdvdman_istruct.m_read2_flag )
6791 "sceCdRead: Double Booking error r2f= %d waf= %d rdy= %02x\n",
6792 g_cdvdman_istruct.m_read2_flag,
6793 g_cdvdman_istruct.m_wait_flag,
6797 vSetEventFlag(ef1, ef2);
6804 g_cdvdman_istruct.m_dec_shift = shift;
6805 g_cdvdman_istruct.m_dec_state = 1;
6807 g_cdvdman_readbuf = buf;
6808 g_cdvdman_readptr = 0;
6809 g_cdvdman_istruct.m_cdvdman_lsn = lsn;
6810 g_cdvdman_istruct.m_cdvdman_csec = 0;
6811 g_cdvdman_istruct.m_cdvdman_nsec = sectors;
6812 g_cdvdman_istruct.m_cdvdman_rbuffer = (int)buf;
6813 g_cdvdman_istruct.m_cdvdman_pattern = dvd ? SCECdSecS2048 : mode->datapattern;
6814 g_cdvdman_istruct.m_cdvdman_cdrmode.
trycount = mode->trycount;
6815 g_cdvdman_istruct.m_cdvdman_cdrmode.
spindlctrl = mode->spindlctrl;
6816 g_cdvdman_istruct.m_cdvdman_cdrmode.
datapattern = dvd ? SCECdSecS2048 : SCECdSecS2340;
6817 g_cdvdman_istruct.m_read2_flag = dvd ? 1 : 3;
6818 g_cdvdman_istruct.m_sync_error = 0;
6819 g_cdvdman_istruct.m_interupt_read_state = 0;
6820 g_cdvdman_istruct.m_cdvdman_rsec = (sectors >= 0x41) ? (((lsn & 0xF)) ? (0x10 - (lsn & 0xF)) : 0x40) : sectors;
6821 g_cdvdman_read_alarm_cb_timeout.hi = 0;
6822 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
6823 vSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6824 read_res = (dvd ?
sceCdRV : sceCdRead0)(
6826 g_cdvdman_istruct.m_cdvdman_rsec,
6828 dvd ? mode : &g_cdvdman_istruct.m_cdvdman_cdrmode,
6829 g_cdvdman_cache_sector_count,
6834 g_cdvdman_istruct.m_cdvdman_rsec = 0;
6835 g_cdvdman_istruct.m_read2_flag = 0;
6836 if ( g_cdvdman_istruct.m_dec_state )
6838 g_cdvdman_istruct.m_dec_shift = 0;
6839 g_cdvdman_istruct.m_check_version = 0;
6840 g_cdvdman_istruct.m_dec_state = 0;
6843 vCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6847 vSetEventFlag(ef1, ef2);
6855 return cdvdman_read(lsn, sectors, buf, mode, 0, 0, 0, 0);
6864 memset(&efinfo, 0,
sizeof(efinfo));
6866 vReferEventFlagStatus(g_fio_fsv_evfid, &efinfo);
6872 vClearEventFlag(g_fio_fsv_evfid, ~1);
6874 return cdvdman_read(lbn, sectors, buffer, mode, 0, 0, g_fio_fsv_evfid, 1);
6877 static int cdvdman_syncdec(
int decflag,
int decxor,
int shift, u32 data)
6879 return decflag ? ((u8)(((u8)data << (shift % 8)) | ((u8)data >> (8 - shift % 8))) ^ (u8)decxor) : (u8)data;
6882 static void Read2intrCDVD(
int read2_flag)
6884 iCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6885 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO || g_cdvdman_retries >= 5 )
6887 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO )
6891 g_cdvdman_istruct.m_read2_flag = 0;
6892 g_cdvdman_retries = 0;
6893 g_cdvdman_rtindex = 0;
6894 g_cdvdman_readptr = 0;
6895 if ( g_cdvdman_istruct.m_dec_state )
6897 g_cdvdman_istruct.m_dec_shift = 0;
6898 g_cdvdman_istruct.m_check_version = 0;
6899 g_cdvdman_istruct.m_dec_state = 0;
6901 g_cdvdman_istruct.m_interupt_read_state = 0;
6903 else if ( !g_cdvdman_istruct.m_interupt_read_state || g_cdvdman_istruct.m_cdvdman_csec )
6907 g_cdvdman_istruct.m_interupt_read_state = 0;
6908 if ( g_cdvdman_istruct.m_sync_error )
6912 if ( !g_cdvdman_rtindex )
6914 g_cdvdman_rtindex = 3;
6915 g_cdvdman_retries += 1;
6917 g_cdvdman_istruct.m_sync_error = 0;
6918 lsn_tmp = g_cdvdman_istruct.m_cdvdman_lsn + g_cdvdman_istruct.m_cdvdman_csec;
6919 if ( lsn_tmp >= 0x30 )
6921 lsn_tmp -= 0x10 * (g_cdvdman_rtindex - 1);
6925 lsn_tmp += 0x10 * (g_cdvdman_rtindex - 1);
6927 if ( ((read2_flag == 3) ? sceCdRead0 :
sceCdRV)(
6929 g_cdvdman_istruct.m_cdvdman_rsec,
6931 &g_cdvdman_istruct.m_cdvdman_cdrmode,
6932 g_cdvdman_cache_sector_count,
6935 g_cdvdman_read_alarm_cb_timeout.hi = 0;
6936 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
6937 iSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6941 VERBOSE_KPRINTF(1,
"Retry Read Fatal Error\n");
6943 g_cdvdman_istruct.m_read2_flag = 0;
6944 g_cdvdman_retries = 0;
6945 g_cdvdman_rtindex = 0;
6946 g_cdvdman_readptr = 0;
6947 if ( g_cdvdman_istruct.m_dec_state )
6949 g_cdvdman_istruct.m_dec_shift = 0;
6950 g_cdvdman_istruct.m_check_version = 0;
6951 g_cdvdman_istruct.m_dec_state = 0;
6954 g_cdvdman_rtindex -= !!g_cdvdman_rtindex;
6960 g_cdvdman_retries = 0;
6961 switch ( g_cdvdman_istruct.m_cdvdman_pattern )
6974 g_cdvdman_istruct.m_cdvdman_rbuffer += cdsectorsz * g_cdvdman_istruct.m_cdvdman_rsec;
6975 g_cdvdman_istruct.m_cdvdman_csec += g_cdvdman_istruct.m_cdvdman_rsec;
6976 if ( (
unsigned int)g_cdvdman_istruct.m_cdvdman_csec < (
unsigned int)g_cdvdman_istruct.m_cdvdman_nsec )
6978 g_cdvdman_istruct.m_cdvdman_rsec =
6979 ((
unsigned int)(g_cdvdman_istruct.m_cdvdman_csec + 0x40) < (
unsigned int)g_cdvdman_istruct.m_cdvdman_nsec) ?
6981 (g_cdvdman_istruct.m_cdvdman_nsec - g_cdvdman_istruct.m_cdvdman_csec);
6982 if ( ((read2_flag == 3) ? sceCdRead0 :
sceCdRV)(
6983 g_cdvdman_istruct.m_cdvdman_lsn + g_cdvdman_istruct.m_cdvdman_csec,
6984 g_cdvdman_istruct.m_cdvdman_rsec,
6986 &g_cdvdman_istruct.m_cdvdman_cdrmode,
6987 g_cdvdman_cache_sector_count,
6990 g_cdvdman_read_alarm_cb_timeout.hi = 0;
6991 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
6992 iSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6997 g_cdvdman_istruct.m_read2_flag = 0;
6998 g_cdvdman_readptr = 0;
6999 if ( g_cdvdman_istruct.m_dec_state )
7001 g_cdvdman_istruct.m_dec_shift = 0;
7002 g_cdvdman_istruct.m_check_version = 0;
7003 g_cdvdman_istruct.m_dec_state = 0;
7009 g_cdvdman_istruct.m_read2_flag = 0;
7010 g_cdvdman_readptr = 0;
7011 if ( g_cdvdman_istruct.m_dec_state )
7013 g_cdvdman_istruct.m_dec_shift = 0;
7014 g_cdvdman_istruct.m_check_version = 0;
7015 g_cdvdman_istruct.m_dec_state = 0;
7022 g_cdvdman_istruct.m_last_error = ((g_cdvdman_istruct.m_interupt_read_state & 0x80)) ?
SCECdErREADCF :
SCECdErIPI;
7023 g_cdvdman_istruct.m_interupt_read_state = 0;
7024 VERBOSE_KPRINTF(1,
"IPIerr emu Hit Dummy Err %02x\n", (u8)g_cdvdman_istruct.m_last_error);
7025 g_cdvdman_istruct.m_read2_flag = 0;
7026 g_cdvdman_retries = 0;
7027 g_cdvdman_rtindex = 0;
7028 g_cdvdman_readptr = 0;
7029 if ( g_cdvdman_istruct.m_dec_state )
7031 g_cdvdman_istruct.m_dec_shift = 0;
7032 g_cdvdman_istruct.m_check_version = 0;
7033 g_cdvdman_istruct.m_dec_state = 0;
7046 static int cdvdman_readfull(u32 lsn, u32 sectors,
void *buf,
const sceCdRMode *mode,
int flag)
7051 VERBOSE_KPRINTF(1,
"lsn:%d nsec:%d buf:% cmdmode:%d\n", lsn, sectors, buf, flag);
7053 VERBOSE_KPRINTF(1,
"DA Read lsn= %d nsec= %d datapattern= %d\n", lsn, sectors, mode->datapattern);
7054 g_cdvdman_readbuf = buf;
7055 #ifdef CDVD_VARIANT_XOSD
7056 dma3_param.m_dma3_csectors = sectors;
7057 dma3_param.m_dma3_msectors = (u16)sectors;
7059 dma3_param.m_dma3_csectors = 0;
7060 dma3_param.m_dma3_msectors = 0;
7062 dma3_param.m_dma3_callback = 0;
7063 dma3_param.m_dma3_blkcount = sectors;
7064 switch ( mode->datapattern )
7067 dma3_param.m_dma3_blkwords = 8;
7068 dma3_param.m_dma3_blkcount *= 74;
7069 dma3_param.m_cdvdreg_howto = 136;
7072 dma3_param.m_dma3_blkwords = 12;
7073 dma3_param.m_dma3_blkcount *= 51;
7074 dma3_param.m_cdvdreg_howto = 140;
7078 dma3_param.m_dma3_blkwords = 12;
7079 dma3_param.m_dma3_blkcount *= 49;
7080 dma3_param.m_cdvdreg_howto = 140;
7084 #ifdef CDVD_VARIANT_XOSD
7085 switch ( get_disk_type_ex() )
7097 #ifndef CDVD_VARIANT_OSD
7098 if ( g_cdvdman_mmode != SCECdMmodeCd && g_cdvdman_mmode != 0xFF )
7103 *(u32 *)ndata = lsn;
7104 *(u32 *)&ndata[4] = sectors;
7105 ndata[8] = mode->trycount;
7106 ndata[9] = cdvdman_speedctl(mode->spindlctrl, 0, lsn + sectors);
7107 dma3_param.m_dma3_maddress = buf;
7108 ndata[10] = mode->datapattern;
7109 return cdvdman_send_ncmd((!flag) ? 0x07 : 0x0E, ndata,
sizeof(ndata), (!flag) ? 2 : 12, &dma3_param, 1) >= 0;
7113 int sceCdReadCDDA(u32 lbn, u32 sectors,
void *buffer,
sceCdRMode *mode)
7115 return cdvdman_readfull(lbn, sectors, buffer, mode, 0);
7118 #ifdef CDVD_VARIANT_OSD
7122 return g_cdvdman_minver_20800 ? cdvdman_readfull(lsn, sectors, buf, mode, 1) :
7123 cdvdman_readfull(lsn, sectors, buf, mode, 0);
7134 #ifdef CDVD_VARIANT_XOSD
7140 #ifndef CDVD_VARIANT_OSD
7141 || (g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF)
7143 || (PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND) )
7148 1,
"RV read: sec %d num %d spin %d trycnt %d addr %08x\n", lsn, sectors, mode->spindlctrl, mode->trycount, buf);
7149 g_cdvdman_readbuf = buf;
7150 g_cdvdman_istruct.m_dvd_flag = cdvdman_isdvd();
7151 g_cdvdman_istruct.m_read_mode = *mode;
7152 g_cdvdman_istruct.m_read_lsn = lsn;
7153 g_cdvdman_istruct.m_read_sectors = sectors;
7154 *(u32 *)ndata = lsn;
7155 *(u32 *)&ndata[4] = sectors;
7156 ndata[8] = mode->trycount;
7157 ndata[9] = cdvdman_speedctl(mode->spindlctrl, 1, lsn + sectors);
7159 dma3_param.m_dma3_csectors = (arg5 && (sectors < (u32)arg5)) ? sectors : (u32)arg5;
7160 g_cdvdman_istruct.m_read_chunk = dma3_param.m_dma3_csectors;
7161 dma3_param.m_cdvdreg_howto = 140;
7162 dma3_param.m_dma3_blkwords = 12;
7163 g_cdvdman_istruct.m_read_buf = buf;
7164 dma3_param.m_dma3_blkcount = (!arg5) ? sectors : 1;
7165 dma3_param.m_dma3_blkcount *= 43;
7166 dma3_param.m_dma3_msectors = sectors;
7167 dma3_param.m_dma3_callback = (int (*)(void))cb;
7168 g_cdvdman_istruct.m_read_callback = cb;
7169 dma3_param.m_dma3_maddress = buf;
7170 if ( cdvdman_send_ncmd(0x08, ndata,
sizeof(ndata), 14, &dma3_param, 0) < 0 )
7172 vSetEventFlag(g_ncmd_evfid, 1);
7175 vSetEventFlag(g_ncmd_evfid, 1);
7179 #ifdef CDVD_VARIANT_OSD
7181 int sceCdReadDVDV(u32 lbn, u32 sectors,
void *buffer,
sceCdRMode *mode)
7186 #ifdef CDVD_VARIANT_XOSD
7187 switch ( get_disk_type_ex() )
7200 switch ( mode->spindlctrl )
7223 *(u32 *)ndata = lbn;
7224 *(u32 *)&ndata[4] = sectors;
7225 dma3_param.m_cdvdreg_howto = 140;
7226 dma3_param.m_dma3_blkwords = 12;
7227 dma3_param.m_dma3_blkcount = 43 * sectors;
7229 dma3_param.m_dma3_maddress = buffer;
7230 dma3_param.m_dma3_msectors = 0;
7231 dma3_param.m_dma3_csectors = 0;
7232 dma3_param.m_dma3_callback = 0;
7233 ndata[8] = mode->trycount;
7234 return cdvdman_send_ncmd(0x08, ndata,
sizeof(ndata), 9, &dma3_param, 1) >= 0;
7242 *(u32 *)ndata = lbn;
7243 if ( cdvdman_isdvd() )
7245 if ( !DvdDual_infochk() )
7249 *(u32 *)ndata = sceCdLsnDualChg(lbn);
7251 return cdvdman_send_ncmd(0x05, ndata,
sizeof(ndata), 4, 0, 1) >= 0;
7254 #ifdef CDVD_VARIANT_XOSD
7255 static unsigned int sceCdChgSpdlCtrl(
int mode)
7257 unsigned int retval;
7261 retval = ~cdvdman_send_ncmd(0x0F, ndata,
sizeof(ndata), 0xF, 0, 0);
7262 VERBOSE_KPRINTF(1,
"Called sceCdChgSpdlCtrl mode:%d ret= %d\n", mode & 0xFF, retval >> 31);
7263 return retval >> 31;
7273 retval = set_prev_command(0x12, NULL, 0, rdata,
sizeof(rdata), 1);
7275 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7288 if (
sceCdMV((u8 *)rdata, status) != 1 || (
unsigned int)(rdata[3] | (rdata[2] << 8) | (rdata[1] << 16)) < 0x10500 )
7290 strcpy(buffer,
"M_NAME_UNKNOWN");
7295 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
7301 retval = set_prev_command(0x17, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
7303 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7306 cmd_tmp2 = set_prev_command(0x17, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
7307 *status |= rdata[0];
7308 memcpy(&buffer[8], &rdata[1],
sizeof(rdata) - 1);
7309 vSetEventFlag(g_scmd_evfid, 1);
7310 return retval ? (!!cmd_tmp2) : 0;
7313 #ifdef CDVD_VARIANT_OSD
7316 int sceCdWI(
const u8 *buffer, u32 *status)
7322 retres = set_prev_command(0x13, (
const char *)buffer, 8, (
char *)status, 1, 1);
7328 int sceCdWM(
const char *buffer, u32 *status)
7335 if (
sceCdMV((u8 *)wdata, status) != 1 || (
unsigned int)(wdata[3] | (wdata[2] << 8) | (wdata[1] << 16)) < 0x10500 )
7343 memcpy(&wdata[1], &buffer[0],
sizeof(wdata) - 1);
7344 retres = set_prev_command(0x18, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7349 memcpy(&wdata[1], &buffer[8],
sizeof(wdata) - 1);
7350 retres = set_prev_command(0x18, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && retres;
7351 *status |= rdata[0];
7364 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7366 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7379 memcpy(&wdata[1], buffer, 8);
7380 retval = set_prev_command(0x03, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7393 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7394 #ifdef CDVD_VARIANT_XOSD
7397 *status = rdata[0] & 0x80;
7399 VERBOSE_KPRINTF(1,
"MV 0x%02x,0x%02x,0x%02x,0x%02x\n", (u8)rdata[0], (u8)rdata[1], (u8)rdata[2], (u8)rdata[3]);
7400 #ifndef CDVD_VARIANT_XOSD
7403 memcpy(buffer, rdata,
sizeof(rdata));
7407 #ifdef CDVD_VARIANT_XOSD
7408 static int cdvdman_get_renewal_date(u8 *buffer, u32 *status)
7416 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7419 *status = (u8)rdata[0];
7421 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7426 #ifndef CDVD_VARIANT_XOSD
7427 static int cdvdman_scmd_sender_03_30(u8 *buf, u32 *status)
7433 if ( g_cdvdman_minver_50000 )
7439 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7440 *status = (u8)rdata[0];
7446 #ifdef CDVD_VARIANT_OSD
7456 USE_DEV5_MMIO_HWPORT();
7458 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
7462 dev5_mmio_hwport->m_dev5_reg_009 = 0;
7463 retval = cdvdman_send_scmd2(0x02, NULL, 0, rdata,
sizeof(rdata), 0);
7464 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7465 for ( i = 0; i < 10; i += 1 )
7471 dev5_reg_00E = dev5_mmio_hwport->m_dev5_reg_00E;
7472 dev5_reg_00D = dev5_mmio_hwport->m_dev5_reg_00D;
7473 dev5_reg_00C = dev5_mmio_hwport->m_dev5_reg_00C;
7474 tmp00E = dev5_mmio_hwport->m_dev5_reg_00E;
7475 tmp00D = dev5_mmio_hwport->m_dev5_reg_00D;
7476 tmp00C = dev5_mmio_hwport->m_dev5_reg_00C;
7477 if ( dev5_reg_00E == tmp00E && dev5_reg_00D == tmp00D && dev5_reg_00C == tmp00C )
7484 *((u8 *)buffer + 9) = dev5_reg_00E;
7485 *((u8 *)buffer + 8) = dev5_reg_00D;
7486 *((u8 *)buffer + 7) = dev5_reg_00C;
7489 vSetEventFlag(g_scmd_evfid, 1);
7500 retval = set_prev_command(0x15, NULL, 0, rdata,
sizeof(rdata), 1);
7501 *status = (u8)rdata[0];
7508 g_cdvdman_mmode = media;
7512 #ifdef CDVD_VARIANT_OSD
7518 return set_prev_command(0x19, NULL, 0, (
char *)status, 1, 1);
7525 VERBOSE_KPRINTF(1,
"BC %d %d %d %d\n", *romname, romname[1], romname[2], romname[3]);
7526 return set_prev_command(0x1A, (
const char *)romname, 4, rdata,
sizeof(rdata), 1);
7535 return g_cdvdman_minver_20400 ? set_prev_command(0x1B, NULL, 0, (
char *)status, 1, 1) : 1;
7538 #ifdef CDVD_VARIANT_OSD
7546 return set_prev_command(0x1C, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7550 static unsigned int power_off_alarm_cb(
void *userdata)
7555 s->m_power_flag = 0;
7565 VERBOSE_KPRINTF(1,
"sceCdPowerOff Call\n");
7566 #ifndef CDVD_VARIANT_XOSD
7567 if ( !g_cdvdman_minver_x_model_15 )
7574 vDelayThread(250000);
7578 retval = set_prev_command(0x0F, NULL, 0, (
char *)status, 1, 1);
7581 g_cdvdman_istruct.m_power_flag = 0;
7584 KPRINTF(
"PowerOff Start...\n");
7585 g_cdvdman_istruct.m_power_flag = 1;
7586 g_cdvdman_power_off_timeout.hi = 0;
7587 g_cdvdman_power_off_timeout.lo = 0xAFC8000;
7588 vSetAlarm(&g_cdvdman_power_off_timeout, power_off_alarm_cb, &g_cdvdman_istruct);
7598 VERBOSE_KPRINTF(1,
"Audio Digital Out: Set param %d\n", (u8)mode);
7600 return set_prev_command(0x14, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7603 #ifdef CDVD_VARIANT_OSD
7611 VERBOSE_KPRINTF(1,
"Auto Adjust Ctrl: Set param %d\n", (u8)mode);
7613 return set_prev_command(0x16, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7619 unsigned int clkmonth;
7620 unsigned int clkday;
7623 if ( !g_cdvdman_minver_50000 )
7627 clkmonth = 10 * (clock->
month >> 4) + (clock->
month & 0xF);
7628 clkday = 10 * (clock->
day >> 4) + (clock->
day & 0xF);
7630 (10 * (clock->
second >> 4) + (clock->
second & 0xF) >= 0x3C
7631 || 10 * (clock->
minute >> 4) + (clock->
minute & 0xF) >= 0x3C
7632 || 10 * (clock->
hour >> 4) + (clock->
hour & 0xF) >= 0x18 || 10 * (clock->
year >> 4) + (clock->
year & 0xF) >= 0x64
7633 || clkmonth >= 0xD || !clkmonth || clkday >= 0x20 || !clkday)
7634 && flags != 255 && !(clock->
second & 0x80) && !(clock->
minute & 0x80) )
7638 wdata[0] = (flags == 255) ? 255 : clock->
second;
7639 wdata[1] = clock->
minute | ((flags == 1) ? 0x80 : 0);
7640 wdata[2] = clock->
hour;
7641 wdata[3] = clock->
day;
7642 wdata[4] = clock->
month;
7643 wdata[5] = clock->
year;
7644 wdata[6] = userdata & 0xFF;
7645 wdata[7] = (userdata >> 8) & 0xFF;
7646 return set_prev_command(0x21, wdata,
sizeof(wdata), (
char *)&clock->
stat,
sizeof(clock->
stat), 1);
7665 if ( !g_cdvdman_minver_50000 )
7667 *wakeupreason = 256;
7670 retval = set_prev_command(0x22, NULL, 0, rdata,
sizeof(rdata), 1);
7675 clock->
stat = rdata[0];
7676 clock->
second = (u8)rdata[2] == 255 ? -1 : (rdata[2] & 0x7F);
7677 clock->
minute = rdata[3] & 0x7F;
7679 clock->
hour = rdata[4];
7680 clock->
day = rdata[5];
7681 clock->
month = rdata[6];
7682 clock->
year = rdata[7];
7683 *userdata = (u8)rdata[8] | ((u8)rdata[9] << 8);
7684 *wakeupreason = (u8)rdata[1];
7685 *flags = (((u8)rdata[2] >> 7) << 1) | (!!(rdata[3] & 0x80));
7689 int sceCdSendSCmd1D(
int *arg1,
unsigned int *arg2,
unsigned int *arg3, u32 *status)
7698 if ( !g_cdvdman_minver_50000 )
7704 retval = set_prev_command(0x1D, NULL, 0, rdata,
sizeof(rdata), 1);
7709 *status = (u8)rdata[0];
7710 *arg1 = (u8)rdata[1];
7711 rdata2tmp = rdata[4] | (rdata[3] << 8) | (rdata[2] << 16);
7715 *arg2 = (rdata2tmp >> 17) & 0x7F;
7716 *arg3 = (rdata2tmp >> 12) & 0x1F;
7719 *arg2 = (rdata2tmp >> 17) & 0x7F;
7720 *arg3 = (rdata2tmp >> 9) & 0xFF;
7723 *arg2 = (rdata2tmp >> 17) & 0x7F;
7724 *arg3 = (rdata2tmp >> 4) & 0x1FFF;
7735 if ( !g_cdvdman_minver_50000 )
7741 wdata[0] = param & 0xFF;
7742 wdata[1] = (param >> 8) & 0xFF;
7743 return set_prev_command(0x1F, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7752 if ( !g_cdvdman_minver_50000 )
7758 retval = set_prev_command(0x26, NULL, 0, rdata,
sizeof(rdata), 1);
7759 *param = ((u8)rdata[2] << 8) | (u8)rdata[1];
7760 *status = (u8)rdata[0];
7771 if ( !g_cdvdman_minver_50200 )
7777 retval = set_prev_command(0x27, NULL, 0, (
char *)rdata,
sizeof(rdata), 1);
7778 memcpy(out, &rdata[1],
sizeof(rdata) - 2);
7790 if ( !g_cdvdman_minver_50400 )
7797 retval = set_prev_command(0x28, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7798 *status = (u8)rdata[0];
7808 if ( !g_cdvdman_minver_50400 )
7816 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7817 *param = 3125 * (((u8)rdata[2] | ((u8)rdata[1] << 8)) << 16 >> 18) / 100;
7818 *status = (u8)rdata[0];
7823 #ifdef CDVD_VARIANT_XOSD
7831 if ( !g_cdvdman_minver_50400 )
7838 retval = set_prev_command(0x29, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7839 *status = (u8)rdata[0];
7840 if ( retval && !rdata[0] )
7842 g_cdvdman_istruct.m_medium_removal_state = 0;
7848 #ifdef CDVD_VARIANT_OSD
7852 USE_IOP_MMIO_HWPORT();
7858 *(u32 *)&iop_mmio_hwport->sio2.unused[0] |= 1;
7862 *(u32 *)&iop_mmio_hwport->sio2.unused[0] &= ~1;
7867 if ( !g_cdvdman_minver_50000 )
7874 return set_prev_command(0x24, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7883 memset(param, 0, 15);
7884 if ( !g_cdvdman_minver_60000 )
7890 retval = set_prev_command(0x36, NULL, 0, rdata,
sizeof(rdata), 1);
7891 memcpy(param, &rdata[1],
sizeof(rdata) - 1);
7904 memset(wdata, 0,
sizeof(wdata));
7905 if ( !g_cdvdman_minver_60600 )
7912 memcpy(&wdata[1], arg2, 12);
7914 memcpy(&wdata[13], arg3, 2);
7915 return set_prev_command(0x3E, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7923 if ( !g_cdvdman_minver_50000 )
7930 return set_prev_command(0x25, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7938 retval = set_prev_command(0x08, NULL, 0, (
char *)clock, 8, 1);
7940 clock->month &= 0x7F;
7941 if ( retval && !clock->stat )
7943 memcpy(&g_cdvdman_clock, clock,
sizeof(g_cdvdman_clock));
7944 g_cdvdman_clk_flg = 1;
7946 else if ( g_cdvdman_clk_flg )
7948 memcpy(clock, &g_cdvdman_clock,
sizeof(g_cdvdman_clock));
7964 return set_prev_command(0x08, NULL, 0, (
char *)clock, 8, 1);
7967 #ifdef CDVD_VARIANT_OSD
7970 return set_prev_command(
7971 0x09, (
const char *)&clock->
second,
sizeof(clock) - 1, (
char *)&clock->
stat,
sizeof(clock->
second), 1);
7980 wdata[0] = (address >> 8) & 0xFF;
7981 wdata[1] = address & 0xFF;
7982 retval = set_prev_command(0x0A, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7984 *data = (rdata[1] << 8) | rdata[2];
7985 VERBOSE_KPRINTF(1,
"RN_call addr= 0x%04x data= 0x%04x stat= 0x%02x\n", address, *data, *result);
7994 wdata[0] = (address >> 8) & 0xFF;
7995 wdata[1] = address & 0xFF;
7996 wdata[2] = (data >> 8) & 0xFF;
7997 wdata[3] = data & 0xFF;
7998 retval = set_prev_command(0x0B, wdata,
sizeof(wdata), (
char *)result, 1, 1);
7999 VERBOSE_KPRINTF(1,
"WN_call addr= 0x%04x data= 0x%04x stat= 0x%02x\n", address, data, *result);
8008 #ifdef CDVD_VARIANT_XOSD
8014 *traychk = cdvdman_mediactl(1);
8015 VERBOSE_KPRINTF(1,
"Tray Req test = %d\n", *traychk);
8023 g_cdvdman_iocache = 0;
8024 #ifdef CDVD_VARIANT_XOSD
8027 rdata[0] = !!set_prev_command(0x06, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0];
8028 #ifdef CDVD_VARIANT_XOSD
8033 #ifdef CDVD_VARIANT_XOSD
8036 g_cdvdman_istruct.m_medium_removal_state = 0;
8037 g_cdvdman_istruct.m_atapi_disk_ejected = 0;
8040 vDelayThread(11000);
8045 static int cdvdman_scmd_sender_3B(
int arg1)
8050 if ( g_cdvdman_minver_x_model_15 && arg1 == 1 )
8054 g_cdvdman_iocache = 0;
8056 if ( set_prev_command(0x3B, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0] )
8058 vDelayThread(11000);
8064 #ifdef CDVD_VARIANT_DNAS
8068 char sectbuf[0x800];
8070 USE_DEV5_MMIO_HWPORT();
8074 #ifdef CDVD_VARIANT_XOSD
8075 switch ( get_disk_type_ex() )
8090 sceCdRead0(0x4B, 1, sectbuf, &rmode, 0, 0);
8092 if ( !cdvdman_ncmd_sender_0C(0, 0, 0x4B) )
8097 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8101 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8102 if ( !(dev5_mmio_hwport->m_dev5_reg_038 & 4) )
8104 vSetEventFlag(g_scmd_evfid, 1);
8107 *(u8 *)
id = dev5_mmio_hwport->m_dev5_reg_030 ^ dev5_mmio_hwport->m_dev5_reg_039;
8108 *((u8 *)
id + 1) = dev5_mmio_hwport->m_dev5_reg_031 ^ dev5_mmio_hwport->m_dev5_reg_039;
8109 *((u8 *)
id + 2) = dev5_mmio_hwport->m_dev5_reg_032 ^ dev5_mmio_hwport->m_dev5_reg_039;
8110 *((u8 *)
id + 3) = dev5_mmio_hwport->m_dev5_reg_033 ^ dev5_mmio_hwport->m_dev5_reg_039;
8111 *((u8 *)
id + 4) = dev5_mmio_hwport->m_dev5_reg_034 ^ dev5_mmio_hwport->m_dev5_reg_039;
8112 vSetEventFlag(g_scmd_evfid, 1);
8124 USE_DEV5_MMIO_HWPORT();
8126 if ( !g_cdvdman_istruct.m_cd_inited )
8132 #ifdef CDVD_VARIANT_XOSD
8133 switch ( get_disk_type_ex() )
8150 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8162 dev5_mmio_hwport->m_dev5_reg_007 = 1;
8174 for ( i = 0; i < 20; i += 1 )
8176 sceCdRead0(0x4B + (0x10 * i), 0x10, g_cdvdman_ptoc, &rmode, 0, 0);
8185 sceCdRead0(0x4B, 1, g_cdvdman_ptoc, &rmode, 0, 0);
8189 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8191 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8195 vSetEventFlag(g_scmd_evfid, 1);
8199 memset(ndata, 0,
sizeof(ndata));
8201 if ( cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) < 0 )
8205 vSetEventFlag(g_scmd_evfid, 1);
8210 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8212 *status = (u8)g_cdvdman_istruct.m_last_error;
8213 vSetEventFlag(g_scmd_evfid, 1);
8216 dev5_reg_038 = dev5_mmio_hwport->m_dev5_reg_038;
8217 vSetEventFlag(g_scmd_evfid, 1);
8218 return (dev5_reg_038 & 5) == 5;
8222 #ifdef CDVD_VARIANT_XOSD
8239 USE_DEV5_MMIO_HWPORT();
8241 memset(xorarea, 0,
sizeof(xorarea));
8242 memset(buffer, 0, 16);
8244 if ( shiftval >= 8 || xorval < 0 || xorval >= 256 )
8249 if ( !g_cdvdman_istruct.m_cd_inited )
8254 switch ( get_disk_type_ex() )
8268 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8276 dev5_mmio_hwport->m_dev5_reg_007 = 1;
8281 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8292 for ( i = 0; i < 0x14; i += 1 )
8294 sceCdRead0(75 + 16 * i, 0x10, g_cdvdman_ptoc, &rmode, 0, 0);
8303 sceCdRead0(0x4B, 1, g_cdvdman_ptoc, &rmode, 0, 0);
8307 WaitEventFlag(g_scmd_evfid, 1, 0, &efbits);
8309 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8313 vSetEventFlag(g_scmd_evfid, 1);
8317 memset(ndata, 0,
sizeof(ndata));
8319 if ( cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) < 0 )
8323 vSetEventFlag(g_scmd_evfid, 1);
8328 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8330 *status = (u8)g_cdvdman_istruct.m_last_error;
8331 vSetEventFlag(g_scmd_evfid, 1);
8341 if ( (dev5_mmio_hwport->m_dev5_reg_038 & 5) == 5 )
8348 dev5_reg_020 = dev5_mmio_hwport->m_dev5_reg_020;
8349 dev5_reg_039 = dev5_mmio_hwport->m_dev5_reg_039;
8350 xor_val_1_stk = dev5_reg_020 ^ dev5_reg_039;
8351 xor_val_2_stk = dev5_reg_039 ^ dev5_mmio_hwport->m_dev5_reg_021;
8352 dev5_reg_022 = dev5_mmio_hwport->m_dev5_reg_022;
8353 reg_039_tmp1 = dev5_mmio_hwport->m_dev5_reg_039;
8354 xor_val_3_stk = dev5_reg_022 ^ reg_039_tmp1;
8355 xor_val_4_stk = reg_039_tmp1 ^ dev5_mmio_hwport->m_dev5_reg_023;
8356 xor_val_1_xstk = dev5_mmio_hwport->m_dev5_reg_024 ^ dev5_mmio_hwport->m_dev5_reg_039;
8357 xor_val_2_xstk = dev5_mmio_hwport->m_dev5_reg_039 ^ dev5_mmio_hwport->m_dev5_reg_034;
8360 vSetEventFlag(g_scmd_evfid, 1);
8361 xorarea[0] = (xor_val_4_stk >> 4) | ((xor_val_1_xstk << 4) & 0x70);
8362 xorarea[1] = (xor_val_3_stk >> 5) | ((xor_val_4_stk << 3) & 0x78);
8363 xorarea[2] = (xor_val_2_stk >> 6) | ((xor_val_3_stk << 2) & 0x7C);
8364 xorarea[3] = (xor_val_1_stk >> 7) | ((xor_val_2_stk << 1) & 0x7E);
8365 sprintf(&xorarea[4],
"%d", ((xor_val_1_stk & 0x7F) << 10) | (xor_val_1_xstk >> 3) | ((xor_val_2_xstk >> 3) << 5));
8366 for ( i = 0; i < 9; i += 1 )
8368 xorarea[i] = xorarea[i] ^ xorval;
8372 for ( i = 0; i < 9; i += 1 )
8374 buffer[i] = (xorarea[i] << shiftval) | ((
int)(u8)xorarea[i ? i - 1 : 8] >> (8 - shiftval));
8380 memcpy(buffer, xorarea,
sizeof(xorarea));
8386 #ifdef CDVD_VARIANT_OSD
8387 int sceCdReadKey(u8 arg1, u8 arg2,
unsigned int command, u8 *key)
8392 char sectorbuf[0x800];
8394 USE_DEV5_MMIO_HWPORT();
8396 if ( cdvdman_isdvd() && !arg1 )
8398 if ( !DvdDual_infochk() )
8402 command = sceCdLsnDualChg(command);
8407 sceCdRead0(command, 1, sectorbuf, &rmode, 0, 0);
8409 for ( i = 0; i < 300; i += 1 )
8411 if ( !cdvdman_ncmd_sender_0C(arg1, arg2, command + i) )
8416 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO )
8421 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8424 dev5_reg_038 = dev5_mmio_hwport->m_dev5_reg_038;
8425 if ( (dev5_reg_038 & 1) )
8427 key[0] = dev5_mmio_hwport->m_dev5_reg_020 ^ dev5_mmio_hwport->m_dev5_reg_039;
8428 key[1] = dev5_mmio_hwport->m_dev5_reg_021 ^ dev5_mmio_hwport->m_dev5_reg_039;
8429 key[2] = dev5_mmio_hwport->m_dev5_reg_022 ^ dev5_mmio_hwport->m_dev5_reg_039;
8430 key[3] = dev5_mmio_hwport->m_dev5_reg_023 ^ dev5_mmio_hwport->m_dev5_reg_039;
8431 key[4] = dev5_mmio_hwport->m_dev5_reg_024 ^ dev5_mmio_hwport->m_dev5_reg_039;
8433 if ( (dev5_reg_038 & 2) )
8435 key[5] = dev5_mmio_hwport->m_dev5_reg_028 ^ dev5_mmio_hwport->m_dev5_reg_039;
8436 key[6] = dev5_mmio_hwport->m_dev5_reg_029 ^ dev5_mmio_hwport->m_dev5_reg_039;
8437 key[7] = dev5_mmio_hwport->m_dev5_reg_02A ^ dev5_mmio_hwport->m_dev5_reg_039;
8438 key[8] = dev5_mmio_hwport->m_dev5_reg_02B ^ dev5_mmio_hwport->m_dev5_reg_039;
8439 key[9] = dev5_mmio_hwport->m_dev5_reg_02C ^ dev5_mmio_hwport->m_dev5_reg_039;
8441 if ( (dev5_reg_038 & 4) )
8443 key[10] = dev5_mmio_hwport->m_dev5_reg_030 ^ dev5_mmio_hwport->m_dev5_reg_039;
8444 key[11] = dev5_mmio_hwport->m_dev5_reg_031 ^ dev5_mmio_hwport->m_dev5_reg_039;
8445 key[12] = dev5_mmio_hwport->m_dev5_reg_032 ^ dev5_mmio_hwport->m_dev5_reg_039;
8446 key[13] = dev5_mmio_hwport->m_dev5_reg_033 ^ dev5_mmio_hwport->m_dev5_reg_039;
8447 key[14] = dev5_mmio_hwport->m_dev5_reg_034 ^ dev5_mmio_hwport->m_dev5_reg_039;
8449 key[15] = dev5_reg_038 & 7;
8450 vSetEventFlag(g_scmd_evfid, 1);
8455 #ifdef CDVD_VARIANT_DNAS
8456 static int cdvdman_ncmd_sender_0C(
int arg1, u32 arg2, u32 arg3)
8462 ndata[2] = !!(arg2 >> 8);
8463 *(u32 *)&ndata[3] = !arg1 ? arg3 : 0;
8464 return cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) >= 0;
8470 #ifdef CDVD_VARIANT_DNAS
8471 USE_DEV5_MMIO_HWPORT();
8473 g_cdvdman_cd36key = enable_shift | shiftval;
8474 dev5_mmio_hwport->m_dev5_reg_03A = ((shiftval & 7) << 4) | ((!!enable_xor) << 1) | (!!enable_shift);
8483 #ifdef CDVD_VARIANT_OSD
8487 #ifdef CDVD_VARIANT_XOSD
8492 #ifdef CDVD_VARIANT_XOSD
8493 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8500 wdata[0] = (u8)mode;
8501 wdata[1] = (u8)block;
8502 wdata[2] = (u8)NumBlocks;
8503 retval = set_prev_command(0x40, wdata,
sizeof(wdata), (
char *)status, 1, 0);
8504 #ifdef CDVD_VARIANT_XOSD
8508 g_cdvdman_config_numblocks = NumBlocks;
8510 #ifdef CDVD_VARIANT_XOSD
8511 vSetEventFlag(g_scmd_evfid, 1);
8523 retval = set_prev_command(0x43, NULL, 0, (
char *)status, 1, 1);
8524 g_cdvdman_config_numblocks = 0;
8528 static int read_config_process(
char *outval, u32 *status)
8534 retval = set_prev_command(0x41, NULL, 0, rdata,
sizeof(rdata), 0);
8535 *status = (u8)(rdata[14] + rdata[13] + rdata[12] + rdata[11] + rdata[10] + rdata[9] + rdata[8] + rdata[7] + rdata[6]
8536 + rdata[5] + rdata[4] + rdata[3] + rdata[2] + rdata[0] + rdata[1])
8538 memcpy(outval, rdata,
sizeof(rdata) - 1);
8548 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8552 for ( retval = 0; retval < g_cdvdman_config_numblocks; retval += 1 )
8554 if ( !read_config_process((
char *)buffer + 15 * retval, status) )
8556 VERBOSE_KPRINTF(1,
"RC_fail Command busy\n");
8561 VERBOSE_KPRINTF(1,
"RC_fail status: 0x%02x\n", *status);
8565 vSetEventFlag(g_scmd_evfid, 1);
8569 static int write_config_process(
const char *inval, u32 *status)
8575 memcpy(wdata, inval, 15);
8576 wdata[15] = wdata[14] + wdata[13] + wdata[12] + wdata[11] + wdata[10] + wdata[9] + wdata[8] + wdata[7] + wdata[6]
8577 + wdata[5] + wdata[4] + wdata[3] + wdata[2] + wdata[0] + wdata[1];
8578 return set_prev_command(0x42, wdata,
sizeof(wdata), (
char *)status, 1, 0);
8587 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8591 for ( retval = 0; retval < g_cdvdman_config_numblocks; retval += 1 )
8593 if ( !write_config_process((
char *)buffer + 15 * retval, status) )
8595 VERBOSE_KPRINTF(1,
"WC_fail Command busy\n");
8600 VERBOSE_KPRINTF(1,
"WC_fail status: 0x%02x\n", *status);
8604 vSetEventFlag(g_scmd_evfid, 1);
8614 return set_prev_command(0x0C, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0];
8618 #ifdef CDVD_VARIANT_XOSD
8620 int sceCdXLEDCtl(u8 arg1, u8 arg2, u32 *param, u32 *status)
8627 if ( !g_cdvdman_minver_50600 )
8635 retval = set_prev_command(0x2D, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
8640 *status = (u8)rdata[0];
8641 *param = (u8)rdata[1];
8646 #ifdef CDVD_VARIANT_XOSD
8650 if ( !g_cdvdman_minver_50600 )
8656 return set_prev_command(0x2E, NULL, 0, (
char *)status, 1, 1);
8660 #ifdef CDVD_VARIANT_XOSD
8663 if ( !g_cdvdman_minver_50600 )
8669 return cdvdman_write_scmd_swap_dev5(0x2F, inbuf, 16, (
char *)status, 1, 1);
8673 #ifdef CDVD_VARIANT_XOSD
8682 if ( !g_cdvdman_minver_50600 )
8688 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8692 memset(outbuf, 0, 16);
8695 vSetEventFlag(g_scmd_evfid, 1);
8699 for ( i = 0; i < 2 && !rdata[0]; i += 1 )
8706 retval = cdvdman_write_scmd_swap_dev5(0x30, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
8707 memcpy(&outbuf[i * 8], &rdata[1],
sizeof(rdata) - 1);
8715 #ifdef CDVD_VARIANT_XOSD
8724 if ( !g_cdvdman_minver_50600 )
8732 retval = set_prev_command(0x2C, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
8737 *status = (u8)rdata[0];
8738 *param = (u8)rdata[1];
8743 #ifdef CDVD_VARIANT_XOSD
8748 int saved_medium_removal_state;
8752 if ( !g_cdvdman_minver_50600 )
8759 saved_medium_removal_state = g_cdvdman_istruct.m_medium_removal_state;
8760 g_cdvdman_istruct.m_medium_removal_state = (u8)wanted_val;
8761 wdata[0] = wanted_val;
8762 retval = set_prev_command(0x31, wdata,
sizeof(wdata), (
char *)status, 1, 1);
8763 if ( !retval || *status )
8765 g_cdvdman_istruct.m_medium_removal_state = saved_medium_removal_state;
8772 #ifdef CDVD_VARIANT_XOSD
8780 if ( !g_cdvdman_minver_50600 )
8786 retval = set_prev_command(0x32, NULL, 0, rdata,
sizeof(rdata), 1);
8791 *status = (u8)rdata[0];
8792 *param = (u8)rdata[1];
8795 g_cdvdman_istruct.m_medium_removal_state = *param;
8801 #ifdef CDVD_VARIANT_XOSD
8807 if ( !g_cdvdman_minver_50600 )
8814 return set_prev_command(0x33, wdata,
sizeof(wdata), (
char *)status, 1, 1);
8818 #ifdef CDVD_VARIANT_XOSD
8819 static int sc_ffffffd8(u32 *status)
8823 if ( !g_cdvdman_minver_50600 )
8829 retval = set_prev_command(0x34, NULL, 0, (
char *)status, 1, 1);
8834 g_cdvdman_istruct.m_atapi_disk_ejected = 0;
8839 #ifdef CDVD_VARIANT_XOSD
8841 int cdvdman_scmd_sender_35(u32 *param, u32 *status)
8847 if ( !g_cdvdman_minver_50600 )
8853 retval = set_prev_command(0x35, NULL, 0, rdata,
sizeof(rdata), 1);
8858 *status = (u8)rdata[0];
8859 *param = (u8)rdata[1];