11#include "irx_imports.h"
24IRX_ID(
"cdvd_driver", 2, 38);
29#ifdef CDVD_VARIANT_OSD
35 __asm__ volatile("mfc0 %0, " #reg : "=r"(val)); \
39#define mfc0(reg) _mfc0(reg)
62 int m_sector_count_total;
72 unsigned int m_cache_hit_count;
84 unsigned char m_type[1];
85 unsigned char m_id[5];
87 unsigned char m_version[1];
89 unsigned char m_unused1[1];
91 unsigned char m_system_id[32];
93 unsigned char m_volume_id[32];
95 unsigned char m_unused2[8];
97 unsigned char m_volume_space_size[8];
99 unsigned char m_unused3[32];
101 unsigned char m_volume_set_size[4];
103 unsigned char m_volume_sequence_number[4];
105 unsigned char m_logical_block_size[4];
107 unsigned char m_path_table_size[8];
108 unsigned char m_type_l_path_table[4];
110 unsigned char m_opt_type_l_path_table[4];
112 unsigned char m_type_m_path_table[4];
114 unsigned char m_opt_type_m_path_table[4];
116 unsigned char m_root_directory_record[34];
118 unsigned char m_volume_set_id[128];
120 unsigned char m_publisher_id[128];
122 unsigned char m_preparer_id[128];
124 unsigned char m_application_id[128];
126 unsigned char m_copyright_file_id[37];
128 unsigned char m_abstract_file_id[37];
130 unsigned char m_bibliographic_file_id[37];
132 unsigned char m_creation_date[17];
134 unsigned char m_modification_date[17];
136 unsigned char m_expiration_date[17];
138 unsigned char m_effective_date[17];
140 unsigned char m_file_structure_version[1];
142 unsigned char m_unused4[1];
144 unsigned char m_application_data[512];
146 unsigned char m_unused5[653];
151 unsigned char m_name_len[2];
152 unsigned char m_extent[4];
153 unsigned char m_parent[2];
154 unsigned char m_name[];
159 unsigned char m_length[1];
160 unsigned char m_ext_attr_length[1];
161 unsigned char m_extent[8];
162 unsigned char m_size[8];
163 unsigned char m_date[7];
164 unsigned char m_flags[1];
165 unsigned char m_file_unit_size[1];
166 unsigned char m_interleave[1];
167 unsigned char m_volume_sequence_number[4];
168 unsigned char m_name_len[1];
169 unsigned char m_name[];
173extern void cdvdman_termcall(
int with_stop);
175static int cdrom_dopen(
iop_file_t *f,
const char *dirname);
178static int cdrom_open(
iop_file_t *f,
const char *name,
int mode,
int arg4);
180static int cdrom_read(
iop_file_t *f,
void *buf,
int nbytes);
181static int cdrom_ioctl(
iop_file_t *f,
int arg,
void *param);
182static int cdrom_ioctl2(
iop_file_t *f,
int request,
void *argp,
size_t arglen,
void *bufp,
size_t buflen);
184cdrom_devctl(
iop_file_t *f,
const char *,
int cmd,
void *argp,
unsigned int arglen,
void *bufp,
unsigned int buflen);
185static int cdrom_lseek(
iop_file_t *f,
int offset,
int pos);
187static int sceCdSearchDir(
char *dirname,
int layer);
188static int sceCdReadDir(
sceCdlFILE *fp,
int dsec,
int index,
int layer);
189static int cdvdman_cmpname(
const char *p,
const char *q);
190static int CD_newmedia(
int arg);
191static int cdvdman_finddir(
int target_parent,
const char *target_name);
192static int CD_cachefile(
int dsec,
int layer);
193static int disc_read(
int size,
int loc,
void *buffer,
int layer);
194static int path_tbl_init(u32 blocks,
char *fname,
int action);
195extern unsigned int optimized_memcpy(
char *dst,
const char *src,
unsigned int n);
196static int vSetAlarm(
iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *arg),
void *arg);
197static int vCancelAlarm(
unsigned int (*alarm_cb)(
void *arg),
void *arg);
198static int vSetEventFlag(
int ef, u32 bits);
199static int vDelayThread(
int usec);
200static int DvdDual_infochk();
201static void cdvdman_init();
203static int intrh_dma_3(
void *userdata);
204static int cdvdman_mediactl(
int code);
205#ifndef CDVD_VARIANT_XOSD
206static int cdvdman_ncmd_sender_06();
208static int cdvdman_gettoc(u8 *
toc);
209static int cdvdman_isdvd();
210static int sceCdRead0_Rty(u32 lsn, u32 nsec,
void *buf,
const sceCdRMode *mode,
int ncmd,
int dintrsec,
void *func);
211static int cdvdman_syncdec(
int decflag,
int decxor,
int shift, u32 data);
212static void Read2intrCDVD(
int read2_flag);
213#ifndef CDVD_VARIANT_XOSD
214static int cdvdman_scmd_sender_03_30(u8 *buf, u32 *status);
216static int cdvdman_scmd_sender_3B(
int arg1);
217#ifdef CDVD_VARIANT_DNAS
218static int cdvdman_ncmd_sender_0C(
int arg1, u32 arg2, u32 arg3);
220#ifdef CDVD_VARIANT_XOSD
221static unsigned int sceCdChgSpdlCtrl(
int mode);
223#ifdef CDVD_VARIANT_XOSD
224static int cdvdman_change_drive(
int mode);
225static int cdvdman_get_renewal_date(u8 *buffer, u32 *status);
226static int get_cdvd_register(
int regnr);
227static int get_disk_type_ex();
228static int sc_ffffffd8(u32 *status);
229static int set_cdvd_dev5_base_addr_atapi(
int mode);
230static int update_cd_mode_ps2_atapi(
void);
233static char g_cdvdman_cache_name[256] =
"host0:";
234static int g_cdvdman_cache_sector_size_count = 1;
235static int g_cdvdman_srchspd = 0;
236static int g_cdvdman_spinctl = -1;
237static int g_cdvdman_spinnom = -1;
238static int g_cdvdman_trycnt = -1;
239static int g_cdvdman_iocache = 0;
240static unsigned int g_cdvdman_lcn_offset = 0;
241static unsigned int g_cdvdman_numbytes_offset = 0;
242static int g_cdvdman_strmerr = 0;
244IOMANX_RETURN_VALUE_IMPL(
EIO);
249 IOMANX_RETURN_VALUE(
EIO),
253 IOMANX_RETURN_VALUE(
EIO),
256 IOMANX_RETURN_VALUE(
EIO),
257 IOMANX_RETURN_VALUE(
EIO),
258 IOMANX_RETURN_VALUE(
EIO),
263 IOMANX_RETURN_VALUE(
EIO),
264 IOMANX_RETURN_VALUE(
EIO),
265 IOMANX_RETURN_VALUE(
EIO),
266 IOMANX_RETURN_VALUE(
EIO),
267 IOMANX_RETURN_VALUE(
EIO),
268 IOMANX_RETURN_VALUE(
EIO),
269 IOMANX_RETURN_VALUE_S64(
EIO),
271 IOMANX_RETURN_VALUE(
EIO),
272 IOMANX_RETURN_VALUE(
EIO),
276static int g_cdvdman_sync_timeout = 15000;
277static int g_cdvdman_stream_timeout = 5000;
278#ifdef CDVD_VARIANT_DNAS
281static int g_verbose_level = 0;
283static unsigned int g_cache_count = 0;
284static unsigned int g_cache_table = 0;
285static unsigned int g_cdvdman_pathtblsize = 0;
286static int g_cache_path_size = 0;
287static int g_cache_path_fd = -1;
288static int g_cdvdman_fs_cdsec = 0;
289static int g_cdvdman_fs_layer = -1;
290static int g_cdvdman_fs_cache = 0;
291static int g_cdvdman_fs_base2 = 0;
292#ifdef CDVD_VARIANT_XOSD
293static vu8 *g_cdvdreg_bf801460 = (vu8 *)0xBF801460;
295static vu8 *g_cdvdreg_bf801464 = (vu8 *)0xBF801464;
296static vu8 *g_cdvdreg_bf80146c = (vu8 *)0xBF80146C;
298static int g_cd_atapi_evfid = 0xFFFFFFFF;
299static int g_acmd_evfid = 0xFFFFFFFF;
300static int g_adma_evfid = 0xFFFFFFFF;
302static int g_cdvdman_clk_flg = 0;
303static int g_cdvdman_cd36key = 0;
304static int g_cdvdman_ee_rpc_fno = 0;
305static int g_cdvdman_mmode = 0;
306static int g_cdvdman_last_cmdfunc = 0;
307static int g_cdvdman_minver_10700 = 0;
308static int g_cdvdman_minver_20200 = 0;
309static int g_cdvdman_minver_20400 = 0;
310static int g_cdvdman_minver_20800 = 0;
311static int g_cdvdman_emudvd9 = 0;
312static int g_cdvdman_minver_50000 = 0;
313static int g_cdvdman_minver_50200 = 0;
314static int g_cdvdman_minver_50400 = 0;
315static int g_cdvdman_minver_50600 = 0;
316static int g_cdvdman_minver_60000 = 0;
317static int g_cdvdman_minver_60200 = 0;
318#ifdef CDVD_VARIANT_OSD
319static int g_cdvdman_minver_60600 = 0;
321#ifdef CDVD_VARIANT_XOSD
322static int g_cdvdman_vernotxxx1x = 0;
324static int g_cdvdman_minver_x_model_15 = 0;
325#ifdef CDVD_VARIANT_XOSD
326static int g_cdvdman_debug_atapi_intr = 0;
328static const char *g_masterdisc_header =
"PlayStation Master Disc";
329static char g_cdvdman_ncmd = 0x06;
330static int g_cdvdman_chmedia = 0;
331static int g_cdvdman_chflags[4] = {1, 1, 1, 1};
332static int g_cdvdman_rtindex = 0;
333static int g_cdvdman_retries = 0;
334static u8 *g_cdvdman_ptoc;
335#ifdef CDVD_VARIANT_XOSD
336static int g_cdvdman_csys_evfid;
338static int g_scmd_evfid;
339static void *g_cdvdman_temp_buffer_ptr;
340static int g_sfile_evfid;
341static int g_ncmd_evfid;
342#ifdef CDVD_VARIANT_OSD
343static s32 g_cdvdman_apply_scmd_sema;
345static int g_fio_fsv_evfid;
346static int g_cdvdman_intr_evfid;
347#ifdef CDVD_VARIANT_XOSD
348static int (*g_cdvdman_atapi_eject_bs_power_callback)(
int interrupt_nr,
void *userdata);
351static void *g_cdvdman_power_off_callback_userdata;
352static void (*g_cdvdman_cdstm0cb)(
int val);
354static void (*g_cdvdman_power_off_callback)(
void *userdata);
355#ifdef CDVD_VARIANT_XOSD
356static void *g_cdvdman_atapi_eject_bs_power_callback_userdata;
358static void (*g_cdvdman_cdstm1cb)(
int val);
359static int g_cdvdman_cmdfunc;
361static char g_cdvdman_sfname[1024];
364static int g_cdvdman_pathtblflag;
365static char g_cdvdman_fs_rbuf[0x800];
366static int g_cdvdman_readptr;
369static void *g_cdvdman_readbuf;
371#ifdef CDVD_VARIANT_OSD
372static int g_cdvdman_config_numblocks;
374static char g_cdvdman_fsvrbuf[42128];
376static const int g_cdvdman_cache_sector_count = 16;
378int _start(
int ac,
char **av)
383 if ( RegisterLibraryEntries(&_exp_cdvdman) )
385 return MODULE_NO_RESIDENT_END;
387 DelDrv(g_cdvdman_cddev.name);
388 if ( AddDrv(&g_cdvdman_cddev) )
390 cdrom_deinit(&g_cdvdman_cddev);
391 return MODULE_NO_RESIDENT_END;
393 g_cdvdman_ptoc = (u8 *)&g_cdvdman_fsvrbuf[0x924];
394 g_cdvdman_temp_buffer_ptr = g_cdvdman_fsvrbuf;
397 SetRebootTimeLibraryHandlingMode(&_exp_cdvdman, 2);
400 _exp_cdvdman.mode &= ~6;
401 _exp_cdvdman.mode |= 2;
403 return MODULE_RESIDENT_END;
406void *sceGetFsvRbuf(
void)
408 return g_cdvdman_fsvrbuf;
415#ifdef CDVD_VARIANT_OSD
418#ifdef CDVD_VARIANT_XOSD
419 USE_DEV5_MMIO_HWPORT();
425 PRINTF(
"cdvdman Init\n");
426 g_cdvdman_istruct.m_wait_flag = 1;
427 g_cdvdman_istruct.m_scmd_flag = 1;
428 g_cdvdman_istruct.m_read2_flag = 0;
429 g_cdvdman_istruct.m_stream_flag = 0;
430 g_cdvdman_istruct.m_last_error =
SCECdErNO;
431 g_cdvdman_istruct.m_layer_1_lsn = 0;
432 g_cdvdman_istruct.m_use_toc = 0;
433 g_cdvdman_istruct.m_last_read_timeout = 0;
434 g_cdvdman_istruct.m_power_flag = 0;
435 g_cdvdman_istruct.m_current_dvd = 0;
436 g_cdvdman_istruct.m_dual_layer_emulation = 0;
437 g_cdvdman_istruct.m_dec_state = 0;
438 g_cdvdman_istruct.m_check_version = 0;
439 g_cdvdman_istruct.m_dec_shift = 0;
440 g_cdvdman_istruct.m_opo_or_para = -1;
441 g_cdvdman_istruct.m_no_dec_flag = 0;
442#ifdef CDVD_VARIANT_XOSD
443 g_cdvdman_istruct.m_atapi_disk_ejected = 0;
445 g_cdvdman_istruct.m_cd_inited = 0;
446#ifdef CDVD_VARIANT_XOSD
447 g_cdvdman_istruct.m_chgsys_callback_next_disktype_last = 0;
448 g_cdvdman_istruct.m_chgsys_writer_drive_shell_is_open = 1;
450 g_cdvdman_istruct.m_tray_is_open = 0;
451 g_cdvdman_ee_rpc_fno = 0;
452 g_cdvdman_spinctl = -1;
456 g_cdvdman_intr_evfid = CreateEventFlag(&
event);
457 g_scmd_evfid = CreateEventFlag(&
event);
458 g_ncmd_evfid = CreateEventFlag(&
event);
459 g_sfile_evfid = CreateEventFlag(&
event);
460 g_fio_fsv_evfid = CreateEventFlag(&
event);
461#ifdef CDVD_VARIANT_XOSD
462 g_cdvdman_csys_evfid = CreateEventFlag(&
event);
464 ClearEventFlag(g_cdvdman_intr_evfid, ~0x4);
465 ClearEventFlag(g_cdvdman_intr_evfid, ~0x10);
466 SetEventFlag(g_cdvdman_intr_evfid, 0x29);
467 SetEventFlag(g_ncmd_evfid, 1);
468 SetEventFlag(g_scmd_evfid, 1);
469 SetEventFlag(g_sfile_evfid, 1);
470 SetEventFlag(g_fio_fsv_evfid, 1);
471#ifdef CDVD_VARIANT_XOSD
472 SetEventFlag(g_cdvdman_csys_evfid, 1);
474#ifdef CDVD_VARIANT_OSD
479 g_cdvdman_apply_scmd_sema = CreateSema(&sema);
481 g_cdvdman_spinnom = -1;
482 g_cdvdman_trycnt = -1;
483 sceCdSC(0xFFFFFFF3, &scres_unused);
484 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
486 g_cdvdman_fhinfo[i].m_fd_flags = 0;
488#ifdef CDVD_VARIANT_XOSD
489 set_cdvd_dev5_base_addr_atapi(2);
491 for ( i = 0; i < 600 && !dev5_mmio_hwport->m_dev5_reg_015; i += 1 )
495 g_cdvdman_istruct.m_cd_mode_ps2_atapi =
496 (!(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen) && !(dev5_mmio_hwport->m_dev5_reg_015 & 0x80)
497 && dev5_mmio_hwport->m_dev5_reg_00F != 6) ?
500 KPRINTF(
"Mode %s Drive\n", g_cdvdman_istruct.m_cd_mode_ps2_atapi == 1 ?
"Atapi" :
"PS2");
501 set_cdvd_dev5_base_addr_atapi(g_cdvdman_istruct.m_cd_mode_ps2_atapi);
506void cdvdman_termcall(
int with_stop)
510 USE_DEV5_MMIO_HWPORT();
512 VERBOSE_KPRINTF(1,
"CDVD:library Terminate Call %d\n", with_stop);
513#ifdef CDVD_VARIANT_XOSD
514 if ( update_cd_mode_ps2_atapi() == 1 )
516 set_cdvd_dev5_base_addr_atapi(2);
525#ifndef CDVD_VARIANT_XOSD
526 if ( g_cdvdman_istruct.m_cd_inited )
528 cdvdman_ncmd_sender_06();
531 for ( i = 0; i < 50000 && (dev5_mmio_hwport->m_dev5_reg_017 & 0x80); i += 1 )
536 if ( (dmac_ch_get_chcr(3) & 0x1000000) )
538 dev5_mmio_hwport->m_dev5_reg_007 = 1;
540 dmac_ch_set_chcr(3, 0);
553 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
555 g_cdvdman_fhinfo[i].m_fd_flags = 0;
557 DeleteEventFlag(g_fio_fsv_evfid);
558 DeleteEventFlag(g_cdvdman_intr_evfid);
559 DeleteEventFlag(g_ncmd_evfid);
560 DeleteEventFlag(g_scmd_evfid);
561 DeleteEventFlag(g_sfile_evfid);
562#ifdef CDVD_VARIANT_XOSD
563 DeleteEventFlag(g_cdvdman_csys_evfid);
568static int cdvdman_devready(
void)
572 for ( i = 0; i < 100; i += 1 )
577 g_cdvdman_iocache = 0;
581 if ( (
sceCdDiskReady(8) & 0xC0) == 0x40 && !g_cdvdman_istruct.m_read2_flag && !g_cdvdman_ee_rpc_fno )
590static int cdvdman_l0check(
int layer)
593 && (g_cdvdman_istruct.m_dual_layer_emulation || g_cdvdman_istruct.m_opo_or_para == 1 || g_cdvdman_istruct.m_opo_or_para == 2);
596static void cdvdman_iormode(
sceCdRMode *rmode,
int fmode,
int layer)
599 rmode->
trycount = (g_cdvdman_trycnt == -1) ? 16 : g_cdvdman_trycnt;
600 if ( cdvdman_l0check(layer) )
602 if ( g_cdvdman_spinnom == -1 )
614 else if ( g_cdvdman_spinnom == -1 )
646static int cdrom_dopen(
iop_file_t *f,
const char *dirname)
650 size_t path_name_ind;
655 VERBOSE_PRINTF(1,
"fileIO DOPEN name= %s layer %d\n", dirname, f->
unit);
656 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
657 for ( i = 0; (i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0]))) && g_cdvdman_fhinfo[i].m_fd_flags;
661 if ( i == (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])) )
663 SetEventFlag(g_fio_fsv_evfid, 1);
667 is_devready = cdvdman_devready();
668 if ( is_devready < 0 )
670 SetEventFlag(g_fio_fsv_evfid, 1);
673 strncpy(path_name, dirname,
sizeof(path_name));
674 if ( !strcmp(path_name,
".") )
676 strcpy(path_name,
"\\.");
678 path_name_ind = strlen(path_name);
679 path_name_ind -= (path_name_ind >= 2) ? 2 : 0;
680 if ( strcmp(&path_name[path_name_ind],
"\\.") )
682 strcat(path_name,
"\\.");
684 if ( (
unsigned int)(f->
unit) >= 2 )
686 PRINTF(
"open fail name %s\n", path_name);
687 SetEventFlag(g_fio_fsv_evfid, 1);
690 g_cdvdman_fhinfo[i].m_file_lsn = 0;
691 g_cdvdman_srchspd = 0;
692 file_lsn_tmp = sceCdSearchDir(path_name, f->
unit);
693 if ( file_lsn_tmp < 0 )
695 PRINTF(
"open fail directory %s\n", path_name);
696 SetEventFlag(g_fio_fsv_evfid, 1);
699 g_cdvdman_fhinfo[i].m_file_lsn = file_lsn_tmp;
700 g_cdvdman_fhinfo[i].m_read_pos = 0;
701 g_cdvdman_fhinfo[i].m_filemode = 0;
702 g_cdvdman_fhinfo[i].m_fd_flags = 1;
703 g_cdvdman_fhinfo[i].m_fd_layer = f->
unit;
704 SetEventFlag(g_fio_fsv_evfid, 1);
722 for ( i = 0; i < (
sizeof(buf->mtime) /
sizeof(buf->mtime[0])); i += 1 )
724 buf->mtime[i] = fp->m_file_struct.date[i];
725 buf->atime[i] = fp->m_file_struct.date[i];
726 buf->ctime[i] = fp->m_file_struct.date[i];
728 buf->size = fp->m_file_struct.size;
733static int cdvdman_cdfname(
char *filename)
737 filename_len = strlen(filename);
738 if ( filename_len >= 3 && !(filename[filename_len - 2] !=
';' && filename[filename_len - 1] !=
'1') )
742 strcat(filename,
";1");
753 VERBOSE_PRINTF(1,
"fileIO GETSTAT name= %s layer= %d\n", name, f->
unit);
754 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
755 devready_tmp = cdvdman_devready();
756 if ( devready_tmp < 0 )
758 SetEventFlag(g_fio_fsv_evfid, 1);
761 strncpy(filename, name,
sizeof(filename));
762 if ( !strcmp(filename,
".") )
764 strcpy(filename,
"\\.");
766 if ( !strcmp(filename,
"\\") )
768 strcpy(filename,
"\\.");
770 if ( !strlen(filename) )
772 strcpy(filename,
"\\.");
774 g_cdvdman_srchspd = 0;
776 memset(&fp, 0,
sizeof(fp));
781 PRINTF(
"open fail name %s\n", name);
782 SetEventFlag(g_fio_fsv_evfid, 1);
785 cdvdman_fillstat(filename, buf, &fp);
786 SetEventFlag(g_fio_fsv_evfid, 1);
798 memset(&fp, 0,
sizeof(fp));
799 VERBOSE_PRINTF(1,
"fileIO DREAD\n");
800 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
801 devready_tmp = cdvdman_devready();
802 if ( devready_tmp < 0 )
804 SetEventFlag(g_fio_fsv_evfid, 1);
807 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
808 g_cdvdman_srchspd = 0;
809 devready_tmp = sceCdReadDir(&fp.m_file_struct, fh->m_file_lsn, fh->m_read_pos, fh->m_fd_layer);
810 if ( devready_tmp < 0 )
812 SetEventFlag(g_fio_fsv_evfid, 1);
818 devready_tmp = strlen(fp.m_file_struct.name);
820 strncpy(buf->name, fp.m_file_struct.name,
sizeof(buf->name));
821 cdvdman_fillstat(fp.m_file_struct.name, &buf->stat, &fp);
822 SetEventFlag(g_fio_fsv_evfid, 1);
828 int cache_remove_result;
830 int cache_file_fd_new;
832 unsigned int file_size_bsr_17;
833 char cache_filename[512];
835 unsigned int ioctl_arg;
837 g_cdvdman_iocache = 0;
840 "%sCache_%d_%d_%d_%d",
841 g_cdvdman_cache_name,
844 (
int)fh->m_file_size,
846 cache_remove_result = 0;
847 VERBOSE_KPRINTF(1,
"Cachefile:%s Open_or_Close:%d\n", cache_filename, open_or_close);
854 fh->m_fd_rbsize = g_cdvdman_cache_sector_size_count ? (g_cdvdman_cache_sector_size_count << 11) : 0x800;
855 fh->m_fd_rcvbuf = (u8 *)AllocSysMemory(ALLOC_LAST, fh->m_fd_rbsize, 0);
856 if ( !fh->m_fd_rcvbuf )
858 VERBOSE_KPRINTF(1,
"Rcvbuf MemAlloc Fail\n");
863 fh->m_cache_file_fd = -1;
864 cache_result = open(cache_filename, O_TRUNC | O_CREAT | O_RDWR, 0x1ff );
865 cache_file_fd_new = cache_result;
866 if ( cache_result >= 0 )
868 u32 file_size_sectors;
869 unsigned int file_size_bsr_6;
871 file_size_sectors = (fh->m_file_size >> 11) + ((!!((fh->m_file_size & 0x7FF))));
872 file_size_bsr_3 = (file_size_sectors >> 3) + (!!(file_size_sectors & 7));
873 file_size_bsr_6 = (file_size_bsr_3 >> 3) + (!!((file_size_bsr_3 & 7)));
874 file_size_bsr_17 = (file_size_bsr_6 >> 11) + (!!((file_size_bsr_6 & 0x7FF)));
875 ioctl_arg = (file_size_bsr_17 + file_size_sectors + 8) << 11;
876 for ( i = 0; i < fh->m_fd_rbsize; i += 1 )
878 fh->m_fd_rcvbuf[i] = 0;
880 if ( !strncmp(cache_filename,
"pfs", 3) )
882 cache_result = ioctl2(cache_file_fd_new, PIOCALLOC, &ioctl_arg, 4, 0, 0);
885 if ( cache_result >= 0 )
887 cache_result = lseek(cache_file_fd_new, 0, 0);
889 if ( cache_result >= 0 )
891 if ( !g_cdvdman_cache_sector_count )
893 for ( i = 0; (int)i < (int)(g_cdvdman_cache_sector_count << 11); i += 1 )
895 ((
char *)g_cdvdman_temp_buffer_ptr)[i] = 0;
897 for ( i = 0; (int)i < (int)((ioctl_arg >> 11) / g_cdvdman_cache_sector_count); i += 1 )
899 cache_result = write(cache_file_fd_new, g_cdvdman_temp_buffer_ptr, g_cdvdman_cache_sector_count << 11);
900 if ( cache_result != (g_cdvdman_cache_sector_count << 11) )
902 if ( cache_result >= 0 )
910 if ( cache_result >= 0 )
912 for ( i = 0; (int)i < (int)((ioctl_arg >> 11)
913 - g_cdvdman_cache_sector_count * ((ioctl_arg >> 11) / g_cdvdman_cache_sector_count));
916 cache_result = write(cache_file_fd_new, fh->m_fd_rcvbuf, 0x800);
917 if ( cache_result != 0x800 )
919 if ( cache_result >= 0 )
928 if ( !open_or_close || cache_result < 0 )
930 if ( fh->m_cache_file_fd != -1 )
932 cache_remove_result = close(fh->m_cache_file_fd);
933 VERBOSE_KPRINTF(1,
"Cache File Close: %d\n", cache_remove_result);
934 if ( cache_remove_result >= 0 )
936 if ( !strncmp(cache_filename,
"pfs", 3) )
938 cache_remove_result = remove(cache_filename);
940 else if ( !strncmp(cache_filename,
"host", 4) )
942 cache_remove_result = 0;
943 remove(cache_filename);
945 VERBOSE_KPRINTF(1,
"Cache File %s remove: %d\n", cache_filename, cache_remove_result);
948 fh->m_cache_file_fd = -1;
949 fh->m_max_cluster = 0;
950 fh->m_cluster_cur = -1;
951 fh->m_sector_count_total = 0;
953 FreeSysMemory(fh->m_fd_rcvbuf);
956 if ( cache_result < 0 )
958 VERBOSE_KPRINTF(1,
"cdvd_odcinit Open Error %d\n", cache_result);
960 if ( cache_remove_result < 0 )
962 VERBOSE_KPRINTF(1,
"cdvd_odcinit Close Error %d\n", cache_remove_result);
964 return (!open_or_close) ? cache_remove_result : cache_result;
966 fh->m_sector_count_total = file_size_bsr_17 << 11;
967 fh->m_cache_file_fd = cache_file_fd_new;
968 fh->m_max_cluster = (
void *)file_size_bsr_3;
969 fh->m_cluster_cur = -1;
970 VERBOSE_KPRINTF(1,
"Cache File Maked\n");
979 if ( fh->m_cluster_cur == -1 )
983 fh->m_cluster_cur = -1;
984 for ( i = 0; i < fh->m_fd_rbsize; i += 1 )
986 fh->m_fd_rcvbuf[i] = 0;
988 fileio_res = lseek(fh->m_cache_file_fd, 0, 0);
989 if ( fileio_res >= 0 )
991 for ( i = 0; i < ((
unsigned int)fh->m_sector_count_total >> 11); i += 1 )
993 fileio_res = write(fh->m_cache_file_fd, fh->m_fd_rcvbuf, 0x800);
994 if ( fileio_res < 0 )
1000 if ( fileio_res >= 0 )
1004 fh->m_fd_flags &= ~4;
1005 cdvd_odcinit(fh, 0, index);
1009static int cdvdman_invcaches(
void)
1013 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
1015 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 4) )
1017 cdvdman_cache_invalidate(&g_cdvdman_fhinfo[i], i);
1023static int cdrom_internal_cache_read(
const iop_file_t *f,
int nbytes)
1026 s16 readpos_plus_nbytes;
1027 unsigned int readpos_plus_nbytes_bsr_14;
1032 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1033 if ( cdvdman_devready() < 0 )
1035 g_cdvdman_iocache = 0;
1038 if ( fh->m_cluster_cur == -1 )
1040 if ( (
void *)(8 * fh->m_fd_rbsize) < fh->m_max_cluster )
1042 fh->m_cluster_cur = (fh->m_read_pos >> 14) & ~0x7;
1044 lseek(fh->m_cache_file_fd, fh->m_cluster_cur >> 3, 0) < 0
1045 || read(fh->m_cache_file_fd, fh->m_fd_rcvbuf, fh->m_fd_rbsize) < 0 )
1047 fh->m_cluster_cur = -1;
1053 fh->m_cluster_cur = -2;
1056 readpos_plus_nbytes = fh->m_read_pos + nbytes;
1057 readpos_plus_nbytes_bsr_14 = (readpos_plus_nbytes >> 14) - (!(readpos_plus_nbytes & 0x3FFF));
1058 readpos_bsr_14 = fh->m_read_pos >> 14;
1060 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);
1061 cluster_cur = fh->m_cluster_cur;
1062 if ( cluster_cur < 0 )
1067 (
unsigned int)readpos_bsr_14 < (
unsigned int)cluster_cur
1068 || readpos_plus_nbytes_bsr_14 >= cluster_cur + 8 * fh->m_fd_rbsize )
1070 int cluster_write_tmp2;
1071 unsigned int readpos_band;
1073 if ( lseek(fh->m_cache_file_fd, cluster_cur >> 3, 0) < 0 )
1075 fh->m_cluster_cur = -1;
1078 cluster_write_tmp2 = (
unsigned int)fh->m_max_cluster >= fh->m_cluster_cur + 8 * fh->m_fd_rbsize ?
1080 ((unsigned int)fh->m_max_cluster - fh->m_cluster_cur + 7) >> 3;
1081 if ( write(fh->m_cache_file_fd, fh->m_fd_rcvbuf, cluster_write_tmp2) != cluster_write_tmp2 )
1083 fh->m_cluster_cur = -1;
1086 readpos_band = readpos_bsr_14 & ~0x7;
1087 fh->m_cluster_cur = readpos_band;
1088 readpos_band += (readpos_bsr_14 < 0) ? 7 : 0;
1089 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) )
1091 fh->m_cluster_cur = -1;
1094 cluster_cur = fh->m_cluster_cur;
1096 for ( i = readpos_bsr_14; i <= readpos_plus_nbytes_bsr_14; i += 1 )
1098 if ( !(((
int)fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] >> ((i - cluster_cur) & 7)) & 1) )
1103 return i <= readpos_plus_nbytes_bsr_14;
1106static int cdrom_internal_write_cache(
const iop_file_t *f,
unsigned int nbytes)
1119 g_cdvdman_iocache = 0;
1120 if ( cdvdman_devready() < 0 )
1124 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1125 if ( nbytes > fh->m_file_size - fh->m_read_pos )
1127 nbytes = fh->m_file_size - fh->m_read_pos;
1133 VERBOSE_KPRINTF(1,
"_cdvdfile_cache_read %d<->%d\n", fh->m_read_pos, fh->m_read_pos + nbytes);
1134 cur = ((fh->m_read_pos + nbytes) >> 14) - (!((fh->m_read_pos + nbytes) & 0x3FFF));
1135 rst = fh->m_read_pos >> 14;
1136 cluster_cur = (fh->m_cluster_cur >= 0) ? fh->m_cluster_cur : 0;
1137 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1139 VERBOSE_KPRINTF(1,
"cache_fill rst:%d<->%d cur:%d cnt:%d\n", rst, cur, fh->m_read_pos, nbytes);
1140 for ( i = rst; i <= cur; i += 1 )
1144 "FIO Usr addr LSN:%d SEC:%d ADDR:%08x cpos= %d\n",
1145 fh->m_file_lsn + 8 * i,
1147 g_cdvdman_temp_buffer_ptr,
1148 (i * 0x4000) + fh->m_sector_count_total);
1149 if ( !(((
int)fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] >> ((i - cluster_cur) & 7)) & 1) )
1152 while ( !
sceCdRE(fh->m_file_lsn + 8 * i, 8, g_cdvdman_temp_buffer_ptr, &rmode) )
1156 g_cdvdman_iocache = 0;
1164 if ( last_err !=
SCECdErNO || tray_open )
1167 VERBOSE_KPRINTF(0,
"Read Error= 0x%02x Tray open %d\n", last_err, tray_open);
1170 lseek_result = lseek(fh->m_cache_file_fd, (i * 0x4000) + fh->m_sector_count_total, 0);
1171 if ( lseek_result < 0 )
1173 return lseek_result;
1175 write_ret = write(fh->m_cache_file_fd, g_cdvdman_temp_buffer_ptr, 0x4000);
1176 if ( write_ret != 0x4000 )
1178 VERBOSE_KPRINTF(1,
"write: ret:%d\n", write_ret);
1179 if ( write_ret >= 0 )
1185 fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] |= 1 << ((i - cluster_cur) & 7);
1191static int cdvdfile_cache_read(
const iop_file_t *f,
void *buf,
int nbyte)
1201 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1203 ((
unsigned int)nbyte > fh->m_file_size - fh->m_read_pos) ? fh->m_file_size - fh->m_read_pos : (unsigned int)nbyte;
1204 VERBOSE_KPRINTF(1,
"_cdvdfile_cache_read %d<->%d\n", fh->m_read_pos, fh->m_read_pos + nbyte_tmp);
1206 if ( nbyte_tmp > 0 )
1208 fd_result = lseek(fh->m_cache_file_fd, fh->m_read_pos + fh->m_sector_count_total, 0);
1209 if ( fd_result >= 0 )
1211 fd_result = read(fh->m_cache_file_fd, buf, nbyte_tmp);
1212 fh->m_read_pos += (fd_result >= 0) ? fd_result : 0;
1218static int cdvdfile_cache_fill_read(
const iop_file_t *f,
void *buf,
int nbytes)
1222 op_result = cdvdman_devready();
1223 if ( op_result >= 0 )
1225 op_result = cdrom_internal_write_cache(f, nbytes);
1229 g_cdvdman_iocache = 0;
1231 if ( op_result >= 0 )
1233 op_result = cdvdfile_cache_read(f, buf, nbytes);
1238static int cdrom_open(
iop_file_t *f,
const char *name,
int mode,
int arg4)
1253 VERBOSE_PRINTF(1,
"fileIO OPEN name= %s mode= 0x%08x layer %d\n", name, mode, f->
unit);
1254 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1257 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
1259 if ( !g_cdvdman_fhinfo[i].m_fd_flags && !emptyfdfound )
1264 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 8) )
1269 if ( !emptyfdfound || streamfdfound )
1271 PRINTF(
"open fail name %s\n", name);
1272 SetEventFlag(g_fio_fsv_evfid, 1);
1276 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1277 strncpy(filename, name,
sizeof(filename));
1278 cdvdman_cdfname(filename);
1279 g_cdvdman_srchspd = (!(mode & 0x40000000) && !cdvdman_l0check(f->
unit)) ?
1280 ((g_cdvdman_spinnom == -1) ? (u16)mode : g_cdvdman_spinnom !=
SCECdSpinStm) :
1282 if ( (
unsigned int)(f->
unit) >= 2u )
1288 if ( !strncmp(name,
"sce_cdvd_lsn", 12) )
1290 strncpy(filename, name,
sizeof(filename));
1292 for ( i = 12; i < (
sizeof(filename) - 5) && filename[i] && filename[i] !=
'_'; i += 1 )
1294 if ( !filename[i] || i >= (
sizeof(filename) - 5) )
1300 fp.size = strtol(&filename[i + 5], 0, 10);
1302 fp.lsn = strtol(&filename[12], 0, 10);
1305 if ( cdvdman_devready() < 0 || !DvdDual_infochk() )
1311 fp.lsn += g_cdvdman_istruct.m_layer_1_lsn;
1316#ifdef CDVD_VARIANT_OSD
1317 else if ( !strcmp(filename,
"sce_dev5;1") )
1325 devready_tmp = cdvdman_devready();
1326 if ( devready_tmp < 0 )
1328 SetEventFlag(g_fio_fsv_evfid, 1);
1329 return devready_tmp;
1337 if ( devready_tmp < 0 )
1339 PRINTF(
"open fail name %s\n", filename);
1340 SetEventFlag(g_fio_fsv_evfid, 1);
1341 return devready_tmp;
1344 g_cdvdman_srchspd = 0;
1345 if ( (mode & 0x40000000) )
1348 memset(&rmode, 0,
sizeof(rmode));
1351 rmode.
trycount = (g_cdvdman_trycnt != -1) ? g_cdvdman_trycnt : 0;
1356 SetEventFlag(g_fio_fsv_evfid, 1);
1359 g_cdvdman_strmerr = 0;
1360 fh->m_fd_flags |= 8;
1362 fh->m_file_lsn = fp.lsn;
1364 fh->m_filemode = mode & ~0x40000000;
1365 fh->m_file_size = fp.size;
1366 fh->m_fd_layer = f->
unit;
1367 if ( (mode & 0x50000000) == 0x10000000 )
1370 if ( g_cache_path_fd != -1 )
1372 devready_tmp = cdvd_odcinit(fh, 1, (
int)f->
privdata);
1373 if ( devready_tmp >= 0 )
1375 fh->m_fd_flags |= 4;
1379 if ( devready_tmp < 0 )
1385 fh->m_file_size = 0;
1387 SetEventFlag(g_fio_fsv_evfid, 1);
1388 return devready_tmp;
1392 VERBOSE_KPRINTF(1,
"open end file_lbn= %d size= %d fds= %d\n", fh->m_file_lsn, fh->m_file_size, fds1);
1393 SetEventFlag(g_fio_fsv_evfid, 1);
1402 VERBOSE_PRINTF(1,
"fileIO CLOSE\n");
1403 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1404 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1405 if ( (fh->m_fd_flags & 8) )
1407 g_cdvdman_strmerr = 0;
1411 SetEventFlag(g_fio_fsv_evfid, 1);
1415 if ( ((fh->m_fd_flags & 0xC) == 4 && cdvd_odcinit(fh, 0, (
int)f->
privdata) < 0) )
1417 SetEventFlag(g_fio_fsv_evfid, 1);
1421 fh->m_file_size = 0;
1427 SetEventFlag(g_fio_fsv_evfid, 1);
1431static int cdrom_internal_read(
const iop_file_t *f,
char *addr,
int nbytes)
1433 unsigned int sectors;
1436 int nbytes_div_2048;
1438 unsigned int sectors_count;
1442 unsigned int filesize_bsr_11;
1447 VERBOSE_PRINTF(1,
"cdvd fileIO read start\n");
1448 op_result = cdvdman_devready();
1449 if ( op_result < 0 )
1451 g_cdvdman_iocache = 0;
1454 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1455 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1460 if ( (
unsigned int)nbytes > fh->m_file_size - fh->m_read_pos )
1462 nbytes = fh->m_file_size - fh->m_read_pos;
1464 filesize_bsr_11 = (fh->m_file_size >> 11) + (!!((fh->m_file_size & 0x7FF))) + fh->m_file_lsn;
1466 1,
"fds= %d read file_lbn= %d offset= %d\n", (
int)(uiptr)f->
privdata, (
int)fh->m_file_lsn, (
int)fh->m_read_pos);
1468 for ( i = 0; i < nbytes; i += nbytes_segment )
1476 nbytes_cur = nbytes - i;
1477 if ( g_cdvdman_spinctl != -1 )
1480 switch ( g_cdvdman_spinctl )
1506 lbn = fh->m_file_lsn + ((fh->m_read_pos + i) >> 11);
1508 pos_extra = (fh->m_read_pos + i) & 0x7FF;
1509 if ( nbytes_cur <= 0x4000 )
1511 nbytes_segment = nbytes_cur;
1512 nbytes_div_2048 = (nbytes_cur / 0x800) + (!!((nbytes_cur & 0x7FF)));
1513 sectors = nbytes_div_2048 + (!!pos_extra);
1517 nbytes_segment = 0x4000;
1518 if ( buf && ((fh->m_read_pos + i) & 0x7FF) && g_cdvdman_iocache )
1521 pos_sub_2048 = 0x800 - pos_extra;
1523 &addr[i], &((
const char *)g_cdvdman_temp_buffer_ptr)[0x800 * (sectors - 1) + pos_extra], 0x800 - pos_extra);
1524 g_cdvdman_iocache = 0;
1529 sectors = 8 + (!!(((fh->m_read_pos + i) & 0x7FF)));
1532 buf = g_cdvdman_temp_buffer_ptr;
1533 if ( (
unsigned int)(sectors) > filesize_bsr_11 - lbn )
1535 sectors = filesize_bsr_11 - lbn;
1537 VERBOSE_PRINTF(1,
"sce_Read LBN= %d sectors= %d\n", (
int)lbn, (
int)sectors);
1539 g_cdvdman_iocache && (lbn >= g_cdvdman_lcn_offset)
1540 && (g_cdvdman_lcn_offset + g_cdvdman_numbytes_offset >= lbn + sectors) )
1542 optimized_memcpy(&addr[i], &((
char *)buf)[0x800 * (lbn - g_cdvdman_lcn_offset) + pos_extra], nbytes_segment);
1544 else if ( ((uiptr)(addr + i) & 3) || pos_extra || (nbytes_segment != 0x4000) )
1546 sec = (sectors >= 8) ? sectors : 8;
1547 if ( sec > filesize_bsr_11 - lbn )
1549 sec = filesize_bsr_11 - lbn;
1551 VERBOSE_PRINTF(1,
"FIO Cache LSN:%d SEC:%d ADDR:%08x\n", (
int)lbn, (
int)sec, (
unsigned int)(uiptr)buf);
1552 sectors_count = (sec >= 9) ? (sec - 8) : 0;
1553 if ( sectors_count )
1555 while ( !
sceCdRE(lbn, sectors_count, buf, &rmode) )
1557 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1560 g_cdvdman_iocache = 0;
1561 g_cdvdman_spinctl = -1;
1570 PRINTF(
"Read Error= 0x%02x\n", last_err);
1571 g_cdvdman_iocache = 0;
1575 while ( !
sceCdRE(lbn + sectors_count, sec - sectors_count, (
char *)buf + 0x800 * sectors_count, &rmode) )
1577 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1580 g_cdvdman_iocache = 0;
1581 g_cdvdman_spinctl = -1;
1590 PRINTF(
"Read Error= 0x%02x\n", last_err);
1591 g_cdvdman_iocache = 0;
1594 g_cdvdman_lcn_offset = lbn_tmp;
1595 g_cdvdman_numbytes_offset = sec;
1596 g_cdvdman_iocache = 1;
1598 &addr[pos_sub_2048 + i],
1599 &((
const char *)g_cdvdman_temp_buffer_ptr)[!pos_sub_2048 ? pos_extra : 0],
1600 nbytes_segment - pos_sub_2048);
1605 1,
"FIO Usr addr LSN:%d SEC:%d ADDR:%08x\n", (
int)lbn, (
int)sectors, (
unsigned int)(uiptr)(addr + i));
1606 while ( !
sceCdRE(lbn, sectors, addr + i, &rmode) )
1608 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1611 g_cdvdman_iocache = 0;
1612 g_cdvdman_spinctl = -1;
1619 g_cdvdman_iocache = 0;
1622 PRINTF(
"Read Error= 0x%02x\n", last_err);
1626 if ( nbytes_segment <= 0 )
1628 g_cdvdman_spinctl = -1;
1629 return nbytes_segment;
1632 fh->m_read_pos += i;
1633 VERBOSE_PRINTF(1,
"fileIO read ended\n");
1634 g_cdvdman_spinctl = -1;
1638static int cdrom_stream_read(
const iop_file_t *f,
char *bbuf,
int nbytes)
1644 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1645 g_cdvdman_strmerr = 0;
1646 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1651 fh->m_read_pos += buf << 11;
1656static int cdrom_read(
iop_file_t *f,
void *buf,
int nbytes)
1666 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1667 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1668 if ( cdvdman_mediactl(2) )
1670 g_cdvdman_iocache = 0;
1671 cdvdman_invcaches();
1673 if ( (fh->m_fd_flags & 8) )
1675 rc = cdrom_stream_read(f, (
char *)buf, nbytes);
1679 if ( !(fh->m_fd_flags & 4) )
1681 rc = cdrom_internal_read(f, (
char *)buf, nbytes);
1685 rc = cdrom_internal_cache_read(f, nbytes);
1692 fh->m_fd_flags &= ~4;
1694 cdvd_odcinit(fh, 0, (
int)f->
privdata);
1698 rc = cdvdfile_cache_fill_read(f, buf, nbytes);
1699 VERBOSE_KPRINTF(1,
"called _cdvdfile_cache_fill_read %d\n", rc);
1705 rc = cdvdfile_cache_read(f, buf, nbytes);
1706 VERBOSE_KPRINTF(1,
"called _cdvdfile_cache_read %d\n", rc);
1710 cdvdman_cache_invalidate(fh, (
int)f->
privdata);
1711 KPRINTF(
"_cdvdfile_cache Read_err OR Drive_not_ready\n", rc);
1715 rc = cdrom_internal_read(f, (
char *)buf, nbytes);
1719 SetEventFlag(g_fio_fsv_evfid, 1);
1723static int cdrom_ioctl(
iop_file_t *f,
int arg,
void *param)
1725#ifdef CDVD_VARIANT_OSD
1726 USE_IOP_MMIO_HWPORT();
1733#ifdef CDVD_VARIANT_OSD
1737 if ( mfc0(PRID) < 35 )
1741 if ( *(u32 *)param )
1743 *(u32 *)&iop_mmio_hwport->sio2.unused[0] |= 1;
1747 *(u32 *)&iop_mmio_hwport->sio2.unused[0] &= ~1;
1751 return mfc0(PRID) >= 35 ? (int)( *(u32 *)&iop_mmio_hwport->sio2.unused[0] & 1) : -22;
1754 g_cdvdman_spinnom = -1;
1757#ifdef CDVD_VARIANT_OSD
1759 sceCdDecSet(*(u32 *)param, *((u32 *)param + 1), *((u32 *)param + 2));
1762 return sceCdReadKey(*(u32 *)param, *((u32 *)param + 1), *((u32 *)param + 2), (u8 *)param + 12) ? 1 : -16;
1772static int cdrom_ioctl2(
iop_file_t *f,
int request,
void *argp,
size_t arglen,
void *bufp,
size_t buflen)
1783 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1784 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1786 if ( (fh->m_fd_flags & 8) )
1790 case CIOCSTREAMPAUSE:
1797 case CIOCSTREAMRESUME:
1804 case CIOCSTREAMSTAT:
1813 SetEventFlag(g_fio_fsv_evfid, 1);
1818cdrom_devctl(
iop_file_t *f,
const char *name,
int cmd,
void *argp,
unsigned int arglen,
void *bufp,
unsigned int buflen)
1823 unsigned int sc_tmp_3;
1833 if ( cmd != CDIOC_BREAK )
1835 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
1839 case CDIOC_READCLOCK:
1840 for ( i = 0; i < 3 && !retval2; i += 1 )
1842 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1845 retval2 = (retval2 != 1) ? -
EIO : 0;
1847#ifdef CDVD_VARIANT_DNAS
1849 for ( i = 0; i < 3 && !retval2; i += 1 )
1851 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1854 retval2 = (retval2 != 1) ? -
EIO : 0;
1860 case CDIOC_GETDISKTYP:
1863 case CDIOC_GETERROR:
1864 *(u32 *)bufp = g_cdvdman_strmerr ? g_cdvdman_strmerr :
sceCdGetError();
1872 case CDIOC_POWEROFF:
1873 for ( i = 0; i < 3 && !retval2; i += 1 )
1875 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1878 retval2 = (retval2 != 1) ? -
EIO : 0;
1886#ifdef CDVD_VARIANT_DNAS
1888 for ( i = 0; i < 3 && !retval2; i += 1 )
1890 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1893 retval2 = (retval2 != 1) ? -
EIO : 0;
1896 case CDIOC_STREAMINIT:
1898 retval2 = (!
sceCdStInit(*(u32 *)argp, *((u32 *)argp + 1), (
void *)*((u32 *)argp + 2))) ? -
EIO : 0;
1904#ifdef CDVD_VARIANT_XOSD
1906 sc_tmp_3 = *(u32 *)argp;
1907 retval2 = (sc_tmp_3 - 4 >= 0x15) ? -22 : sceCdSC(0xFFFFFFDD, (int *)&sc_tmp_3);
1917 g_cdvdman_trycnt = *(u8 *)argp;
1948 case CDIOC_SETTIMEOUT:
1951 case CDIOC_READDVDDUALINFO:
1974 *(u32 *)bufp = sceCdSC(0xFFFFFFF5, &scres_unused);
1977 retval2 = (
sceCdApplySCmd(*(u8 *)argp, (
char *)argp + 4, arglen - 4, bufp) != 1) ? -
EIO : 0;
1979 case CDIOC_FSCACHEINIT:
1981 if ( g_cache_path_fd != -1 )
1986 sc_tmp_2 = (
char *)argp;
1987 for ( i = 0; i < arglen && sc_tmp_2[i] && sc_tmp_2[i] !=
','; i += 1 )
1989 g_cdvdman_cache_name[i] = sc_tmp_2[i];
1995 for ( ; (i < arglen) && sc_tmp_2[i] && sc_tmp_2[i] !=
','; i += 1 )
2002 g_cdvdman_cache_sector_size_count = strtol((
const char *)argp + sc_tmp_3, 0, 10);
2003 retval2 = path_tbl_init(strtol(&sc_tmp_2[i + 1], 0, 10), g_cdvdman_cache_name, 1);
2006 case CDIOC_FSCACHEDELETE:
2007 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
2009 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 4) )
2014 retval2 = (i == (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0]))) ? path_tbl_init(0, 0, 0) : -
EBUSY;
2020 if ( cmd != CDIOC_BREAK )
2022 SetEventFlag(g_fio_fsv_evfid, 1);
2028static int cdrom_lseek(
iop_file_t *f,
int offset,
int pos)
2035 VERBOSE_PRINTF(1,
"fileIO SEEK\n");
2036 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
2037 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
2044 retval = fh->m_read_pos + offset;
2047 retval = fh->m_file_size - offset;
2052 if ( retval > (
int)(fh->m_file_size) )
2054 retval = fh->m_file_size;
2056 fh->m_read_pos = retval;
2057 if ( (fh->m_fd_flags & 8) )
2065 SetEventFlag(g_fio_fsv_evfid, 1);
2069static unsigned int sync_timeout_alarm_cb(
void *userdata)
2074 KPRINTF(
"Cdvd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
2080 if ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2087 g_cdvdman_sync_timeout = timeout;
2090 g_cdvdman_stream_timeout = timeout;
2103 VERBOSE_KPRINTF(1,
"sceCdSync: Call mode %d Com %x\n", mode, (u8)g_cdvdman_istruct.m_cdvdman_command);
2107 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2109 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2113 return !!(!sceCdCheckCmd() || (g_cdvdman_istruct.m_read2_flag));
2116 sysclk.lo = 0x9000 * g_cdvdman_sync_timeout;
2117 vSetAlarm(&sysclk, sync_timeout_alarm_cb, &sysclk);
2118 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2120 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2122 vCancelAlarm(sync_timeout_alarm_cb, &sysclk);
2126 sysclk.lo = 0x41EB0000;
2127 vSetAlarm(&sysclk, sync_timeout_alarm_cb, &sysclk);
2128 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2130 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2132 vCancelAlarm(sync_timeout_alarm_cb, &sysclk);
2135 while ( !sceCdCheckCmd() )
2137 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2142 sysclk.lo = 0x9000 * g_cdvdman_sync_timeout;
2143 vSetAlarm(&sysclk, sync_timeout_alarm_cb, &sysclk);
2144 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2146 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2148 vCancelAlarm(sync_timeout_alarm_cb, &sysclk);
2151 while ( !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, 1, WEF_AND, &efbits);
2155 if ( g_cdvdman_ee_rpc_fno )
2163 !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag || g_cdvdman_ee_rpc_fno
2164 || (g_cdvdman_istruct.m_stream_flag));
2166 WaitEventFlag(g_cdvdman_intr_evfid, 0x21, WEF_OR, &efbits);
2167 ReferEventFlagStatus(g_cdvdman_intr_evfid, &efinfo);
2170 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
2172 SetEventFlag(g_cdvdman_intr_evfid, 0x20);
2176 WaitEventFlag(g_cdvdman_intr_evfid, 0x20, WEF_AND, &efbits);
2181 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2183 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2189 "sceCdSync: Command= %d Error= %d\n",
2190 (u8)g_cdvdman_istruct.m_cdvdman_command,
2191 (u8)g_cdvdman_istruct.m_last_error);
2197 VERBOSE_KPRINTF(1,
"sceCdSpinCtrlIOP speed= %d\n", speed);
2198 g_cdvdman_spinctl = speed;
2208 if ( PollEventFlag(g_sfile_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
2212 for ( i = 0; i < ((
sizeof(g_cdvdman_sfname) /
sizeof(g_cdvdman_sfname[0])) - 1) && path[i]; i += 1 )
2214 g_cdvdman_sfname[i] = path[i];
2216 g_cdvdman_sfname[i] = 0;
2217 g_cdvdman_srchspd = 1;
2219 vSetEventFlag(g_sfile_evfid, 1);
2230 return cdvdman_gettoc(
toc);
2236 USE_DEV5_MMIO_HWPORT();
2240 VERBOSE_KPRINTF(1,
"DISK READY call from iop %d\n", mode);
2241#ifdef CDVD_VARIANT_XOSD
2242 if ( g_cdvdman_istruct.m_cd_mode_ps2_atapi == 1 )
2244 return mode == 8 ? -1 : 6;
2246 switch ( get_disk_type_ex() )
2258 VERBOSE_KPRINTF(1,
"Wait Drive Ready %x\n", dev5_mmio_hwport->m_dev5_reg_005);
2259 while ( g_cdvdman_istruct.m_read2_flag )
2262#ifdef CDVD_VARIANT_XOSD
2263 switch ( get_disk_type_ex() )
2270 case SCECdDETCTDVDS:
2271 case SCECdDETCTDVDD:
2272 while ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) != 0x40 )
2275 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2276#ifdef CDVD_VARIANT_XOSD
2277 if ( !get_disk_type_ex() )
2290 VERBOSE_KPRINTF(1,
"Wait Exit\n");
2293 return (u8)dev5_mmio_hwport->m_dev5_reg_005;
2296 if ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) == 0x40 && !g_cdvdman_istruct.m_read2_flag )
2300 VERBOSE_KPRINTF(1,
"Drive Not Ready\n");
2307#ifdef CDVD_VARIANT_XOSD
2310 VERBOSE_KPRINTF(1,
"sceCdGetDiskType Call\n");
2311 cdvd_register = get_cdvd_register(0x0F);
2312 VERBOSE_KPRINTF(1,
"sceCdGetDiskType 0x%02x\n", cdvd_register);
2313 return cdvd_register;
2315 USE_DEV5_MMIO_HWPORT();
2317 return (u8)dev5_mmio_hwport->m_dev5_reg_00F;
2321#ifdef CDVD_VARIANT_XOSD
2322static int get_disk_type_ex(
void)
2327 USE_DEV5_MMIO_HWPORT();
2334 retval = (g_cdvdman_istruct.m_cd_mode_ps2_atapi == 1) ? 257 : dev5_mmio_hwport->m_dev5_reg_00F;
2343#ifdef CDVD_VARIANT_XOSD
2346 int wakeup_reason_reg;
2348 VERBOSE_KPRINTF(1,
"sceCdGetWakeUpReason Call\n");
2349 wakeup_reason_reg = get_cdvd_register(0x15);
2350 if ( wakeup_reason_reg != -1 )
2352 wakeup_reason_reg &= 0xF;
2354 VERBOSE_KPRINTF(1,
"sceCdGetWakeUpReason 0x%02x\n", wakeup_reason_reg);
2355 return wakeup_reason_reg;
2362#ifndef CDVD_VARIANT_XOSD
2365#ifndef CDVD_VARIANT_XOSD
2366 USE_DEV5_MMIO_HWPORT();
2369#ifdef CDVD_VARIANT_XOSD
2370 reg_00A_tmp = get_cdvd_register(0x0A);
2372 reg_00A_tmp = dev5_mmio_hwport->m_dev5_reg_00A;
2374#ifndef CDVD_VARIANT_XOSD
2380 if ( !g_cdvdman_istruct.m_tray_is_open && cdvdman_scmd_sender_03_30(&rdata_tmp, &status_tmp) == 1 && !status_tmp )
2382 reg_00A_tmp &= ~SCECdStatShellOpen;
2383 if ( (rdata_tmp & 8) )
2388 if ( (reg_00A_tmp & 0x1E) )
2394 if ( g_cdvdman_istruct.m_use_toc )
2396 reg_00A_tmp &= ~SCECdStatShellOpen;
2398 if ( g_cdvdman_istruct.m_power_flag )
2405#ifdef CDVD_VARIANT_OSD
2408 USE_DEV5_MMIO_HWPORT();
2410 return !g_cdvdman_istruct.m_power_flag ? (u8)dev5_mmio_hwport->m_dev5_reg_00A : -1;
2416 p->sector = 16 * ((i + 150) % 75 / 10) + (i + 150) % 75 % 10;
2417 p->second = 16 * ((i + 150) / 75 % 60 / 10) + (i + 150) / 75 % 60 % 10;
2418 p->minute = 16 * ((i + 150) / 75 / 60 / 10) + (i + 150) / 75 / 60 % 10;
2425 return 75 * (60 * (10 * (p->minute >> 4) + (p->minute & 0xF)) + 10 * (p->second >> 4) + (p->second & 0xF))
2426 + 10 * (p->sector >> 4) + (p->sector & 0xF) - 150;
2429#ifdef CDVD_VARIANT_DNAS
2430static int read_id_from_rom(
int mode,
int *buf)
2440 for ( i = 0; i < (
sizeof(idinfo) /
sizeof(idinfo[0])); i += 1 )
2442 for ( j = 0; j <
sizeof(chksumstk); j += 1 )
2444 ((
char *)&idinfo)[(i * 4) + j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2445 ((
char *)&chksumstk)[j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2447 chksumint += chksumstk;
2449 for ( ; i < 0x4000; i += 1 )
2451 for ( j = 0; j <
sizeof(chksumstk); j += 1 )
2453 ((
char *)&chksumstk)[j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2455 chksumint += chksumstk;
2459 KPRINTF(
"# checksum error %d\n", chksumint);
2474static int query_boot_mode_6_nonzero(
void)
2478 BootMode = QueryBootMode(6);
2479 return !(!BootMode || (*(u16 *)BootMode & 0xFFFC) != 0x60);
2482static int query_boot_mode_6_zero(
void)
2484 return !QueryBootMode(6);
2487static int cdvdman_readID(
int mode,
int *buf)
2494 if ( query_boot_mode_6_nonzero() )
2496 if ( read_id_from_rom(mode, buf) && mode == 1 )
2508 if ( query_boot_mode_6_zero() )
2510 if ( !
sceCdRI(id_val, &id_result) || id_result )
2517 if ( !g_readid_systemtime.lo && !g_readid_systemtime.hi )
2519 GetSystemTime(&sysclk);
2520 g_readid_systemtime = sysclk;
2526 *buf = *(u32 *)id_val >> 8;
2530 *buf = id_val[0] | 0x8004600;
2531 buf[1] = *(u32 *)&id_val[4];
2539 return cdvdman_readID(0, (
int *)guid);
2544 return cdvdman_readID(1, (
int *)
id);
2548int sceCdStInit(u32 bufmax, u32 bankmax,
void *buffer)
2554 VERBOSE_KPRINTF(1,
"sceCdStInit call IOP\n");
2555 memset(&devctl_req, 0,
sizeof(devctl_req));
2556 devctl_req.m_cmdid = 5;
2557 devctl_req.m_posszarg1 = bufmax;
2558 devctl_req.m_posszarg2 = bankmax;
2559 devctl_req.m_buffer = buffer;
2560 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2570 VERBOSE_KPRINTF(1,
"sceCdStStart call IOP\n");
2571 memset(&devctl_req, 0,
sizeof(devctl_req));
2572 devctl_req.m_rmode.
datapattern = mode->datapattern;
2573 devctl_req.m_rmode.
spindlctrl = mode->spindlctrl;
2574 devctl_req.m_cmdid = 1;
2575 devctl_req.m_posszarg1 = lbn;
2576 devctl_req.m_rmode.
trycount = mode->trycount;
2577 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2586 VERBOSE_KPRINTF(1,
"sceCdStSeekF call IOP\n");
2587 memset(&devctl_req, 0,
sizeof(devctl_req));
2588 devctl_req.m_cmdid = 9;
2589 devctl_req.m_posszarg1 = lsn;
2590 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2599 VERBOSE_KPRINTF(1,
"sceCdStSeek call IOP\n");
2600 memset(&devctl_req, 0,
sizeof(devctl_req));
2601 devctl_req.m_posszarg1 = lbn;
2602 devctl_req.m_cmdid = 4;
2603 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2612 VERBOSE_KPRINTF(1,
"sceCdStStop call IOP\n");
2613 memset(&devctl_req, 0,
sizeof(devctl_req));
2614 devctl_req.m_cmdid = 3;
2615 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2618int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
2626 VERBOSE_KPRINTF(1,
"sceCdStRead call IOP\n");
2627 memset(&devctl_req, 0,
sizeof(devctl_req));
2628 devctl_req.m_cmdid = 1;
2629 devctl_req.m_posszarg2 = sectors;
2630 devctl_req.m_buffer = buffer;
2631 if ( devctl(
"cdrom_stm0:", 0x4394, &devctl_req,
sizeof(devctl_req), &buf, 4) < 0 )
2635 *error = devctl_req.m_error;
2645 VERBOSE_KPRINTF(1,
"sceCdStPause call IOP\n");
2646 memset(&devctl_req, 0,
sizeof(devctl_req));
2647 devctl_req.m_cmdid = 7;
2648 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2657 VERBOSE_KPRINTF(1,
"sceCdStResume call IOP\n");
2658 memset(&devctl_req, 0,
sizeof(devctl_req));
2659 devctl_req.m_cmdid = 8;
2660 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2669 VERBOSE_KPRINTF(1,
"sceCdStStat call IOP\n");
2670 memset(&devctl_req, 0,
sizeof(devctl_req));
2671 devctl_req.m_cmdid = 6;
2672 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2682 VERBOSE_PRINTF(1,
"CdSearchFile: start name= %s layer= %d\n", name, layer);
2683 if ( g_cdvdman_fs_layer != layer )
2685 g_cdvdman_fs_cache = 0;
2687 if ( !cdvdman_mediactl(0) && g_cdvdman_fs_cache )
2689 VERBOSE_KPRINTF(1,
"CdSearchFile: cache dir data used\n");
2693 VERBOSE_PRINTF(1,
"CdSearchFile Topen= %s\n", name);
2694 if ( !CD_newmedia(layer) )
2696 g_cdvdman_fs_cache = 0;
2699 g_cdvdman_fs_cache = 1;
2701 if ( *name !=
'\\' )
2708 for ( i = 0; i < 8 && name[i]; i += 1 )
2710 for ( j = 0; name[i + j] !=
'\\'; j += 1 )
2712 name_buf[j] = name[i + j];
2715 parent_level = cdvdman_finddir(parent_level, name_buf);
2716 if ( parent_level == -1 )
2724 VERBOSE_PRINTF(1,
"%s: path level (%d) error\n", name, i);
2729 VERBOSE_PRINTF(1,
"%s: dir was not found\n", name);
2733 if ( !CD_cachefile(parent_level, layer) )
2735 VERBOSE_PRINTF(1,
"CdSearchFile: disc error\n");
2738 VERBOSE_PRINTF(2,
"CdSearchFile: searching %s...\n", name_buf);
2740 j < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0])) && g_cdvdman_filetbl[j].m_file_struct.
name[0];
2743 VERBOSE_PRINTF(1,
"%d %s %s\n", (
int)j, g_cdvdman_filetbl[j].m_file_struct.name, name_buf);
2744 if ( cdvdman_cmpname(g_cdvdman_filetbl[j].m_file_struct.name, name_buf) )
2746 VERBOSE_PRINTF(2,
"%s:\t found\n", name_buf);
2749 fp->m_file_struct.lsn += layer ? g_cdvdman_fs_base2 : 0;
2753 VERBOSE_PRINTF(1,
"%s: not found\n", name_buf);
2757static int sceCdSearchDir(
char *dirname,
int layer)
2761 VERBOSE_PRINTF(1,
"_sceCdSearchDir: dir name %s layer %d\n", dirname, layer);
2765static int sceCdReadDir(
sceCdlFILE *fp,
int dsec,
int index,
int layer)
2767 VERBOSE_PRINTF(1,
"_sceCdReadDir: current= %d dsec= %d layer= %d\n", g_cdvdman_fs_cdsec, dsec, layer);
2768 if ( g_cdvdman_fs_cdsec != dsec || g_cdvdman_fs_layer != layer )
2770 if ( g_cdvdman_fs_layer != layer )
2772 if ( !CD_newmedia(layer) )
2776 g_cdvdman_fs_cache = 1;
2778 if ( !CD_cachefile(dsec, layer) )
2783 if ( g_cdvdman_filetbl[index].m_file_struct.name[0] )
2785 VERBOSE_PRINTF(1,
"%s:\t found dir_point %d\n", g_cdvdman_filetbl[index].m_file_struct.name, index);
2793static int cdvdman_cmpname(
const char *p,
const char *q)
2795 return !strncmp(p, q, 12);
2798static int CD_newmedia(
int arg)
2800 unsigned int DiskType;
2807#ifdef CDVD_VARIANT_XOSD
2808 DiskType = get_disk_type_ex();
2824 VERBOSE_PRINTF(1,
"CD_newmedia: Illegal disc media type =%d\n", (
int)DiskType);
2827 g_cdvdman_fs_base2 = 0;
2830 if ( !DvdDual_infochk() )
2832 VERBOSE_PRINTF(1,
"CD_newmedia: Get DvdDual_infochk fail\n");
2835 g_cdvdman_fs_base2 = arg ? g_cdvdman_istruct.m_layer_1_lsn : 0;
2837 if ( disc_read(1, g_cdvdman_fs_base2 + 0x10, g_cdvdman_fs_rbuf, arg) != 1 )
2839 VERBOSE_PRINTF(1,
"CD_newmedia: Read error in disc_read(PVD)\n");
2843 for ( i = 0; i < g_cdvdman_pathtblsize; i += 1 )
2845 g_cdvdman_pathtbl[i].m_cache_hit_count = 0;
2846 g_cdvdman_pathtbl[i].m_layer = 0;
2847 g_cdvdman_pathtbl[i].m_nsec = 0;
2848 g_cdvdman_pathtbl[i].m_lsn = 0;
2849 g_cdvdman_pathtbl[i].m_cache_path_sz = 0;
2853 g_cache_path_size = 0;
2855 if ( strncmp((
char *)((
iso9660_desc_t *)g_cdvdman_fs_rbuf)->m_id,
"CD001", 5) )
2857 VERBOSE_PRINTF(1,
"CD_newmedia: Disc format error in cd_read(PVD)\n");
2866 VERBOSE_PRINTF(1,
"CD_newmedia: CD Read mode\n");
2867 ptsector = *(u32 *)(((
iso9660_desc_t *)g_cdvdman_fs_rbuf)->m_type_l_path_table);
2872 VERBOSE_PRINTF(1,
"CD_newmedia: DVD Read mode\n");
2876 if ( disc_read(1, g_cdvdman_fs_base2 + ptsector, g_cdvdman_fs_rbuf, arg) != 1 )
2878 VERBOSE_PRINTF(1,
"CD_newmedia: Read error (PT:%08x)\n", ptsector);
2881 VERBOSE_PRINTF(2,
"CD_newmedia: sarching dir..\n");
2883 i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0]))
2884 && path_cur < (
iso9660_path_t *)&g_cdvdman_fs_rbuf[
sizeof(g_cdvdman_fs_rbuf)] && path_cur->m_name_len[0];
2886 path_cur = (
iso9660_path_t *)(((
char *)path_cur) + path_cur->m_name_len[0] + (path_cur->m_name_len[0] & 1)
2889 memcpy(&g_cdvdman_dirtbl[i].m_extent, path_cur->m_extent,
sizeof(path_cur->m_extent));
2890 g_cdvdman_dirtbl[i].m_number = i;
2891 memcpy(&g_cdvdman_dirtbl[i].m_parent, path_cur->m_parent,
sizeof(path_cur->m_parent));
2892 memcpy(g_cdvdman_dirtbl[i].m_name, path_cur->m_name, path_cur->m_name_len[0]);
2893 g_cdvdman_dirtbl[i].m_name[path_cur->m_name_len[0]] = 0;
2896 "\t%08x,%04x,%04x,%s\n",
2897 g_cdvdman_dirtbl[i].m_extent,
2898 g_cdvdman_dirtbl[i].m_number,
2899 g_cdvdman_dirtbl[i].m_parent,
2900 g_cdvdman_dirtbl[i].m_name);
2902 if ( i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0])) )
2904 g_cdvdman_dirtbl[i].m_parent = 0;
2906 g_cdvdman_fs_cdsec = 0;
2907 g_cdvdman_fs_layer = arg;
2908 VERBOSE_PRINTF(2,
"CD_newmedia: %d dir entries found\n", (
int)i);
2912static int cdvdman_finddir(
int target_parent,
const char *target_name)
2916 for ( i = 0; i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0])) && g_cdvdman_dirtbl[i].m_parent; i += 1 )
2918 if ( g_cdvdman_dirtbl[i].m_parent == target_parent && !strcmp(target_name, g_cdvdman_dirtbl[i].m_name) )
2926static int CD_cachefile(
int dsec,
int layer)
2931 if ( dsec == g_cdvdman_fs_cdsec )
2936 disc_read(1, g_cdvdman_dirtbl[dsec - 1].m_extent + (layer ? g_cdvdman_fs_base2 : 0), g_cdvdman_fs_rbuf, layer)
2939 VERBOSE_PRINTF(1,
"CD_cachefile: dir not found\n");
2940 g_cdvdman_fs_cdsec = 0;
2943 VERBOSE_PRINTF(2,
"CD_cachefile: searching...\n");
2945 i < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0]))
2946 && dirent_cur < (
iso9660_dirent_t *)&g_cdvdman_fs_rbuf[
sizeof(g_cdvdman_fs_rbuf)];
2947 i += 1, dirent_cur = (
iso9660_dirent_t *)((
char *)dirent_cur + dirent_cur->m_length[0]) )
2951 if ( !dirent_cur->m_length[0] )
2956 &g_cdvdman_filetbl[i].m_file_struct.lsn, dirent_cur->m_extent,
sizeof(g_cdvdman_filetbl[i].m_file_struct.lsn));
2958 &g_cdvdman_filetbl[i].m_file_struct.size, dirent_cur->m_size,
sizeof(g_cdvdman_filetbl[i].m_file_struct.size));
2959 file_year = dirent_cur->m_date[0] + 1900;
2960 g_cdvdman_filetbl[i].m_file_struct.
date[7] = file_year >> 8;
2961 g_cdvdman_filetbl[i].m_file_struct.
date[6] = file_year;
2962 g_cdvdman_filetbl[i].m_file_struct.
date[5] = dirent_cur->m_date[1];
2963 g_cdvdman_filetbl[i].m_file_struct.
date[4] = dirent_cur->m_date[2];
2964 g_cdvdman_filetbl[i].m_file_struct.
date[3] = dirent_cur->m_date[3];
2965 g_cdvdman_filetbl[i].m_file_struct.
date[2] = dirent_cur->m_date[4];
2966 g_cdvdman_filetbl[i].m_file_struct.
date[1] = dirent_cur->m_date[5];
2967 g_cdvdman_filetbl[i].m_flags = dirent_cur->m_flags[0];
2971 strcpy(g_cdvdman_filetbl[i].m_file_struct.name,
".");
2974 strcpy(g_cdvdman_filetbl[i].m_file_struct.name,
"..");
2977 memcpy(g_cdvdman_filetbl[i].m_file_struct.name, dirent_cur->m_name, dirent_cur->m_name_len[0]);
2978 g_cdvdman_filetbl[i].m_file_struct.
name[dirent_cur->m_name_len[0]] = 0;
2983 "\t lsn %d size %d name:%d:%s %d/%d/%d %d:%d:%d\n",
2984 (
int)(g_cdvdman_filetbl[i].m_file_struct.lsn),
2985 (
int)(g_cdvdman_filetbl[i].m_file_struct.size),
2986 dirent_cur->m_name_len[0],
2987 g_cdvdman_filetbl[i].m_file_struct.name,
2989 g_cdvdman_filetbl[i].m_file_struct.date[5],
2990 g_cdvdman_filetbl[i].m_file_struct.date[4],
2991 g_cdvdman_filetbl[i].m_file_struct.date[3],
2992 g_cdvdman_filetbl[i].m_file_struct.date[2],
2993 g_cdvdman_filetbl[i].m_file_struct.date[1]);
2995 g_cdvdman_fs_cdsec = dsec;
2996 if ( i < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0])) )
2998 g_cdvdman_filetbl[i].m_file_struct.
name[0] = 0;
3000 VERBOSE_PRINTF(2,
"CD_cachefile: %d files found\n", (
int)i);
3004static int disc_read(
int size,
int loc,
void *buffer,
int layer)
3014 VERBOSE_PRINTF(1,
"cd_read:lsn= %d size= %d layer= %d\n", loc, size, layer);
3015 if ( cdvdman_l0check(layer) )
3017 g_cdvdman_srchspd = 0;
3019 switch ( g_cdvdman_srchspd )
3035 if ( !g_cdvdman_pathtblflag )
3043 pathcachecnt = (g_cache_count < g_cdvdman_pathtblsize) ? g_cache_count : g_cdvdman_pathtblsize;
3044 for ( i = 0; i < pathcachecnt; i += 1 )
3048 "Path table Cache Search lsn:%d:%d nsec:%d:%d layer%d:%d\n",
3049 g_cdvdman_pathtbl[i].m_lsn,
3051 g_cdvdman_pathtbl[i].m_nsec,
3053 g_cdvdman_pathtbl[i].m_layer,
3056 g_cdvdman_pathtbl[i].m_lsn == loc && g_cdvdman_pathtbl[i].m_nsec == (
unsigned int)size
3057 && g_cdvdman_pathtbl[i].m_layer == layer )
3062 if ( i != pathcachecnt )
3064 VERBOSE_KPRINTF(1,
"Path table Cache ON:%d\n", g_cdvdman_pathtbl[i].m_cache_path_sz);
3065 if ( lseek(g_cache_path_fd, g_cdvdman_pathtbl[i].m_cache_path_sz, 0) >= 0 )
3067 read(g_cache_path_fd, buffer, size << 11);
3069 g_cdvdman_pathtbl[i].m_cache_hit_count += 1;
3075 if ( !
sceCdRE(loc, size, buffer, &rmode) )
3086 if ( g_cache_count >= g_cdvdman_pathtblsize )
3089 unsigned int cacheblo2;
3092 if ( g_cache_table >= g_cdvdman_pathtblsize )
3096 cachetblo1 = g_cache_table;
3097 cacheblo2 = cachetblo1;
3098 for ( i = 0; (
unsigned int)i < g_cache_count; i += 1 )
3100 if ( cacheblo2 >= g_cdvdman_pathtblsize )
3105 g_cdvdman_pathtbl[cacheblo2].m_nsec >= (
unsigned int)size
3106 && g_cdvdman_pathtbl[cacheblo2].m_cache_hit_count
3107 < (
unsigned int)g_cdvdman_pathtbl[cachetblo1].m_cache_hit_count )
3109 cachetblo1 = cacheblo2;
3113 cache_path_sz = g_cdvdman_pathtbl[cachetblo1].m_cache_path_sz;
3114 g_cache_table = cachetblo1;
3118 cache_path_sz = g_cache_path_size;
3119 g_cache_table = g_cache_count;
3122 if ( lseek(g_cache_path_fd, cache_path_sz, 0) >= 0 )
3124 int ptbl_wcache_write_res;
3126 ptbl_wcache_write_res = write(g_cache_path_fd, buffer, size << 11);
3127 if ( ptbl_wcache_write_res == size << 11 )
3130 g_cdvdman_pathtbl[g_cache_table].m_cache_path_sz = cache_path_sz;
3131 g_cdvdman_pathtbl[g_cache_table].m_lsn = loc;
3132 g_cdvdman_pathtbl[g_cache_table].m_nsec = size;
3133 g_cdvdman_pathtbl[g_cache_table].m_layer = layer;
3134 g_cdvdman_pathtbl[g_cache_table].m_cache_hit_count = 0;
3135 g_cache_path_size += (g_cache_count < g_cdvdman_pathtblsize) ? ptbl_wcache_write_res : 0;
3139 VERBOSE_KPRINTF(1,
"Ptbl_WCache:write %d", ptbl_wcache_write_res);
3140 g_cdvdman_pathtbl[g_cache_table].m_cache_hit_count = 0;
3141 g_cdvdman_pathtbl[g_cache_table].m_layer = 0;
3142 g_cdvdman_pathtbl[g_cache_table].m_nsec = 0;
3143 g_cdvdman_pathtbl[g_cache_table].m_lsn = 0;
3154 if ( !
sceCdRE(loc, size, buffer, &rmode) )
3164 VERBOSE_KPRINTF(1,
"cd_read: error code %x\n",
sceCdGetError());
3168static int path_tbl_init(u32 blocks,
char *fname,
int action)
3182 if ( !g_cdvdman_pathtbl )
3185 g_cdvdman_pathtblflag = 0;
3189 sprintf(cachedir,
"%sCache_Path", fname);
3190 v = open(cachedir, O_TRUNC | O_CREAT | O_RDWR, 0x1ff );
3195 g_cache_path_fd = v;
3196 if ( !strncmp(cachedir,
"pfs", 3) )
3198 blocksbs = blocks << 11;
3199 ioctl2(g_cache_path_fd, PIOCALLOC, &blocksbs,
sizeof(blocksbs), 0, 0);
3201 for ( i = 0; i < blocks; i += 1 )
3203 v = write(g_cache_path_fd, g_cdvdman_fs_rbuf,
sizeof(g_cdvdman_fs_rbuf));
3212 g_cdvdman_pathtblsize = blocks;
3213 for ( i = 0; i < blocks; i += 1 )
3215 g_cdvdman_pathtbl[i].m_cache_hit_count = 0;
3216 g_cdvdman_pathtbl[i].m_layer = 0;
3217 g_cdvdman_pathtbl[i].m_nsec = 0;
3218 g_cdvdman_pathtbl[i].m_lsn = 0;
3219 g_cdvdman_pathtbl[i].m_cache_path_sz = 0;
3221 g_cache_path_size = 0;
3224 g_cdvdman_pathtblflag = 1;
3230 if ( g_cache_path_fd != -1 )
3232 num = close(g_cache_path_fd);
3235 if ( !strncmp(cachedir,
"pfs", 3) )
3237 num = remove(cachedir);
3239 else if ( !strncmp(cachedir,
"host", 4) )
3247 g_cache_path_fd = -1;
3250 g_cache_path_size = 0;
3251 g_cdvdman_pathtblflag = 0;
3252 g_cdvdman_pathtblsize = 0;
3253 FreeSysMemory(g_cdvdman_pathtbl);
3254 g_cdvdman_pathtbl = 0;
3258 VERBOSE_KPRINTF(1,
"path_tbl_init Error %d\n", v);
3260 return (!action) ? num : v;
3267 "\t" ".set push" "\n"
3268 "\t" ".set noat" "\n"
3269 "\t" ".set noreorder" "\n"
3270 "\t" ".global optimized_memcpy" "\n"
3271 "\t" "optimized_memcpy:" "\n"
3272 "\t" " srl $a3, $a2, 2" "\n"
3273 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3274 "\t" " or $a3, $a0, $a1" "\n"
3275 "\t" " andi $a3, $a3, 0x3" "\n"
3276 "\t" " bnez $a3, .Loptimized_memcpy_3" "\n"
3278 "\t" " srl $a3, $a2, 2" "\n"
3279 "\t" " addiu $at, $zero, 0xC" "\n"
3280 "\t" " div $zero, $a3, $at" "\n"
3281 "\t" " mflo $a3" "\n"
3282 "\t" " mfhi $v1" "\n"
3283 "\t" " beqz $v1, .Loptimized_memcpy_2" "\n"
3285 "\t" ".Loptimized_memcpy_1:" "\n"
3286 "\t" " lw $v0, 0x0($a1)" "\n"
3287 "\t" " addiu $v1, $v1, -0x1" "\n"
3288 "\t" " sw $v0, 0x0($a0)" "\n"
3289 "\t" " addiu $a1, $a1, 0x4" "\n"
3290 "\t" " bnez $v1, .Loptimized_memcpy_1" "\n"
3291 "\t" " addiu $a0, $a0, 0x4" "\n"
3292 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3294 "\t" ".Loptimized_memcpy_2:" "\n"
3295 "\t" " lw $v0, 0x0($a1)" "\n"
3296 "\t" " lw $v1, 0x4($a1)" "\n"
3297 "\t" " lw $t0, 0x8($a1)" "\n"
3298 "\t" " lw $t1, 0xC($a1)" "\n"
3299 "\t" " lw $t2, 0x10($a1)" "\n"
3300 "\t" " lw $t3, 0x14($a1)" "\n"
3301 "\t" " lw $t4, 0x18($a1)" "\n"
3302 "\t" " lw $t5, 0x1C($a1)" "\n"
3303 "\t" " lw $t6, 0x20($a1)" "\n"
3304 "\t" " lw $t7, 0x24($a1)" "\n"
3305 "\t" " lw $t8, 0x28($a1)" "\n"
3306 "\t" " lw $t9, 0x2C($a1)" "\n"
3307 "\t" " addiu $a3, $a3, -0x1" "\n"
3308 "\t" " sw $v0, 0x0($a0)" "\n"
3309 "\t" " sw $v1, 0x4($a0)" "\n"
3310 "\t" " sw $t0, 0x8($a0)" "\n"
3311 "\t" " sw $t1, 0xC($a0)" "\n"
3312 "\t" " sw $t2, 0x10($a0)" "\n"
3313 "\t" " sw $t3, 0x14($a0)" "\n"
3314 "\t" " sw $t4, 0x18($a0)" "\n"
3315 "\t" " sw $t5, 0x1C($a0)" "\n"
3316 "\t" " sw $t6, 0x20($a0)" "\n"
3317 "\t" " sw $t7, 0x24($a0)" "\n"
3318 "\t" " sw $t8, 0x28($a0)" "\n"
3319 "\t" " sw $t9, 0x2C($a0)" "\n"
3320 "\t" " addiu $a1, $a1, 0x30" "\n"
3321 "\t" " bnez $a3, .Loptimized_memcpy_2" "\n"
3322 "\t" " addiu $a0, $a0, 0x30" "\n"
3323 "\t" " j .Loptimized_memcpy_12" "\n"
3325 "\t" ".Loptimized_memcpy_3:" "\n"
3326 "\t" " andi $a3, $a0, 0x3" "\n"
3327 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3328 "\t" " andi $a3, $a1, 0x3" "\n"
3329 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3331 "\t" " srl $a3, $a2, 2" "\n"
3332 "\t" " addiu $at, $zero, 0xC" "\n"
3333 "\t" " div $zero, $a3, $at" "\n"
3334 "\t" " mflo $a3" "\n"
3335 "\t" " mfhi $v1" "\n"
3336 "\t" " beqz $v1, .Loptimized_memcpy_5" "\n"
3338 "\t" ".Loptimized_memcpy_4:" "\n"
3339 "\t" " lwl $v0, 0x3($a1)" "\n"
3340 "\t" " lwr $v0, 0x0($a1)" "\n"
3341 "\t" " addiu $v1, $v1, -0x1" "\n"
3342 "\t" " swl $v0, 0x3($a0)" "\n"
3343 "\t" " swr $v0, 0x0($a0)" "\n"
3344 "\t" " addiu $a1, $a1, 0x4" "\n"
3345 "\t" " bnez $v1, .Loptimized_memcpy_4" "\n"
3346 "\t" " addiu $a0, $a0, 0x4" "\n"
3347 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3349 "\t" ".Loptimized_memcpy_5:" "\n"
3350 "\t" " lwl $v0, 0x3($a1)" "\n"
3351 "\t" " lwr $v0, 0x0($a1)" "\n"
3352 "\t" " lwl $v1, 0x7($a1)" "\n"
3353 "\t" " lwr $v1, 0x4($a1)" "\n"
3354 "\t" " lwl $t0, 0xB($a1)" "\n"
3355 "\t" " lwr $t0, 0x8($a1)" "\n"
3356 "\t" " lwl $t1, 0xF($a1)" "\n"
3357 "\t" " lwr $t1, 0xC($a1)" "\n"
3358 "\t" " lwl $t2, 0x13($a1)" "\n"
3359 "\t" " lwr $t2, 0x10($a1)" "\n"
3360 "\t" " lwl $t3, 0x17($a1)" "\n"
3361 "\t" " lwr $t3, 0x14($a1)" "\n"
3362 "\t" " lwl $t4, 0x1B($a1)" "\n"
3363 "\t" " lwr $t4, 0x18($a1)" "\n"
3364 "\t" " lwl $t5, 0x1F($a1)" "\n"
3365 "\t" " lwr $t5, 0x1C($a1)" "\n"
3366 "\t" " lwl $t6, 0x23($a1)" "\n"
3367 "\t" " lwr $t6, 0x20($a1)" "\n"
3368 "\t" " lwl $t7, 0x27($a1)" "\n"
3369 "\t" " lwr $t7, 0x24($a1)" "\n"
3370 "\t" " lwl $t8, 0x2B($a1)" "\n"
3371 "\t" " lwr $t8, 0x28($a1)" "\n"
3372 "\t" " lwl $t9, 0x2F($a1)" "\n"
3373 "\t" " lwr $t9, 0x2C($a1)" "\n"
3374 "\t" " addiu $a3, $a3, -0x1" "\n"
3375 "\t" " swl $v0, 0x3($a0)" "\n"
3376 "\t" " swr $v0, 0x0($a0)" "\n"
3377 "\t" " swl $v1, 0x7($a0)" "\n"
3378 "\t" " swr $v1, 0x4($a0)" "\n"
3379 "\t" " swl $t0, 0xB($a0)" "\n"
3380 "\t" " swr $t0, 0x8($a0)" "\n"
3381 "\t" " swl $t1, 0xF($a0)" "\n"
3382 "\t" " swr $t1, 0xC($a0)" "\n"
3383 "\t" " swl $t2, 0x13($a0)" "\n"
3384 "\t" " swr $t2, 0x10($a0)" "\n"
3385 "\t" " swl $t3, 0x17($a0)" "\n"
3386 "\t" " swr $t3, 0x14($a0)" "\n"
3387 "\t" " swl $t4, 0x1B($a0)" "\n"
3388 "\t" " swr $t4, 0x18($a0)" "\n"
3389 "\t" " swl $t5, 0x1F($a0)" "\n"
3390 "\t" " swr $t5, 0x1C($a0)" "\n"
3391 "\t" " swl $t6, 0x23($a0)" "\n"
3392 "\t" " swr $t6, 0x20($a0)" "\n"
3393 "\t" " swl $t7, 0x27($a0)" "\n"
3394 "\t" " swr $t7, 0x24($a0)" "\n"
3395 "\t" " swl $t8, 0x2B($a0)" "\n"
3396 "\t" " swr $t8, 0x28($a0)" "\n"
3397 "\t" " swl $t9, 0x2F($a0)" "\n"
3398 "\t" " swr $t9, 0x2C($a0)" "\n"
3399 "\t" " addiu $a1, $a1, 0x30" "\n"
3400 "\t" " bnez $a3, .Loptimized_memcpy_5" "\n"
3401 "\t" " addiu $a0, $a0, 0x30" "\n"
3402 "\t" " j .Loptimized_memcpy_12" "\n"
3404 "\t" ".Loptimized_memcpy_6:" "\n"
3405 "\t" " andi $a3, $a0, 0x3" "\n"
3406 "\t" " beqz $a3, .Loptimized_memcpy_9" "\n"
3408 "\t" " srl $a3, $a2, 2" "\n"
3409 "\t" " addiu $at, $zero, 0xC" "\n"
3410 "\t" " div $zero, $a3, $at" "\n"
3411 "\t" " mflo $a3" "\n"
3412 "\t" " mfhi $v1" "\n"
3413 "\t" " beqz $v1, .Loptimized_memcpy_8" "\n"
3415 "\t" ".Loptimized_memcpy_7:" "\n"
3416 "\t" " lw $v0, 0x0($a1)" "\n"
3417 "\t" " addiu $v1, $v1, -0x1" "\n"
3418 "\t" " swl $v0, 0x3($a0)" "\n"
3419 "\t" " swr $v0, 0x0($a0)" "\n"
3420 "\t" " addiu $a1, $a1, 0x4" "\n"
3421 "\t" " bnez $v1, .Loptimized_memcpy_7" "\n"
3422 "\t" " addiu $a0, $a0, 0x4" "\n"
3423 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3425 "\t" ".Loptimized_memcpy_8:" "\n"
3426 "\t" " lw $v0, 0x0($a1)" "\n"
3427 "\t" " lw $v1, 0x4($a1)" "\n"
3428 "\t" " lw $t0, 0x8($a1)" "\n"
3429 "\t" " lw $t1, 0xC($a1)" "\n"
3430 "\t" " lw $t2, 0x10($a1)" "\n"
3431 "\t" " lw $t3, 0x14($a1)" "\n"
3432 "\t" " lw $t4, 0x18($a1)" "\n"
3433 "\t" " lw $t5, 0x1C($a1)" "\n"
3434 "\t" " lw $t6, 0x20($a1)" "\n"
3435 "\t" " lw $t7, 0x24($a1)" "\n"
3436 "\t" " lw $t8, 0x28($a1)" "\n"
3437 "\t" " lw $t9, 0x2C($a1)" "\n"
3438 "\t" " addiu $a3, $a3, -0x1" "\n"
3439 "\t" " swl $v0, 0x3($a0)" "\n"
3440 "\t" " swr $v0, 0x0($a0)" "\n"
3441 "\t" " swl $v1, 0x7($a0)" "\n"
3442 "\t" " swr $v1, 0x4($a0)" "\n"
3443 "\t" " swl $t0, 0xB($a0)" "\n"
3444 "\t" " swr $t0, 0x8($a0)" "\n"
3445 "\t" " swl $t1, 0xF($a0)" "\n"
3446 "\t" " swr $t1, 0xC($a0)" "\n"
3447 "\t" " swl $t2, 0x13($a0)" "\n"
3448 "\t" " swr $t2, 0x10($a0)" "\n"
3449 "\t" " swl $t3, 0x17($a0)" "\n"
3450 "\t" " swr $t3, 0x14($a0)" "\n"
3451 "\t" " swl $t4, 0x1B($a0)" "\n"
3452 "\t" " swr $t4, 0x18($a0)" "\n"
3453 "\t" " swl $t5, 0x1F($a0)" "\n"
3454 "\t" " swr $t5, 0x1C($a0)" "\n"
3455 "\t" " swl $t6, 0x23($a0)" "\n"
3456 "\t" " swr $t6, 0x20($a0)" "\n"
3457 "\t" " swl $t7, 0x27($a0)" "\n"
3458 "\t" " swr $t7, 0x24($a0)" "\n"
3459 "\t" " swl $t8, 0x2B($a0)" "\n"
3460 "\t" " swr $t8, 0x28($a0)" "\n"
3461 "\t" " swl $t9, 0x2F($a0)" "\n"
3462 "\t" " swr $t9, 0x2C($a0)" "\n"
3463 "\t" " addiu $a1, $a1, 0x30" "\n"
3464 "\t" " bnez $a3, .Loptimized_memcpy_8" "\n"
3465 "\t" " addiu $a0, $a0, 0x30" "\n"
3466 "\t" " j .Loptimized_memcpy_12" "\n"
3468 "\t" ".Loptimized_memcpy_9:" "\n"
3469 "\t" " srl $a3, $a2, 2" "\n"
3470 "\t" " addiu $at, $zero, 0xC" "\n"
3471 "\t" " div $zero, $a3, $at" "\n"
3472 "\t" " mflo $a3" "\n"
3473 "\t" " mfhi $v1" "\n"
3474 "\t" " beqz $v1, .Loptimized_memcpy_11" "\n"
3476 "\t" ".Loptimized_memcpy_10:" "\n"
3477 "\t" " lwl $v0, 0x3($a1)" "\n"
3478 "\t" " lwr $v0, 0x0($a1)" "\n"
3479 "\t" " addiu $v1, $v1, -0x1" "\n"
3480 "\t" " sw $v0, 0x0($a0)" "\n"
3481 "\t" " addiu $a1, $a1, 0x4" "\n"
3482 "\t" " bnez $v1, .Loptimized_memcpy_10" "\n"
3483 "\t" " addiu $a0, $a0, 0x4" "\n"
3484 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3486 "\t" ".Loptimized_memcpy_11:" "\n"
3487 "\t" " lwl $v0, 0x3($a1)" "\n"
3488 "\t" " lwr $v0, 0x0($a1)" "\n"
3489 "\t" " lwl $v1, 0x7($a1)" "\n"
3490 "\t" " lwr $v1, 0x4($a1)" "\n"
3491 "\t" " lwl $t0, 0xB($a1)" "\n"
3492 "\t" " lwr $t0, 0x8($a1)" "\n"
3493 "\t" " lwl $t1, 0xF($a1)" "\n"
3494 "\t" " lwr $t1, 0xC($a1)" "\n"
3495 "\t" " lwl $t2, 0x13($a1)" "\n"
3496 "\t" " lwr $t2, 0x10($a1)" "\n"
3497 "\t" " lwl $t3, 0x17($a1)" "\n"
3498 "\t" " lwr $t3, 0x14($a1)" "\n"
3499 "\t" " lwl $t4, 0x1B($a1)" "\n"
3500 "\t" " lwr $t4, 0x18($a1)" "\n"
3501 "\t" " lwl $t5, 0x1F($a1)" "\n"
3502 "\t" " lwr $t5, 0x1C($a1)" "\n"
3503 "\t" " lwl $t6, 0x23($a1)" "\n"
3504 "\t" " lwr $t6, 0x20($a1)" "\n"
3505 "\t" " lwl $t7, 0x27($a1)" "\n"
3506 "\t" " lwr $t7, 0x24($a1)" "\n"
3507 "\t" " lwl $t8, 0x2B($a1)" "\n"
3508 "\t" " lwr $t8, 0x28($a1)" "\n"
3509 "\t" " lwl $t9, 0x2F($a1)" "\n"
3510 "\t" " lwr $t9, 0x2C($a1)" "\n"
3511 "\t" " addiu $a3, $a3, -0x1" "\n"
3512 "\t" " sw $v0, 0x0($a0)" "\n"
3513 "\t" " sw $v1, 0x4($a0)" "\n"
3514 "\t" " sw $t0, 0x8($a0)" "\n"
3515 "\t" " sw $t1, 0xC($a0)" "\n"
3516 "\t" " sw $t2, 0x10($a0)" "\n"
3517 "\t" " sw $t3, 0x14($a0)" "\n"
3518 "\t" " sw $t4, 0x18($a0)" "\n"
3519 "\t" " sw $t5, 0x1C($a0)" "\n"
3520 "\t" " sw $t6, 0x20($a0)" "\n"
3521 "\t" " sw $t7, 0x24($a0)" "\n"
3522 "\t" " sw $t8, 0x28($a0)" "\n"
3523 "\t" " sw $t9, 0x2C($a0)" "\n"
3524 "\t" " addiu $a1, $a1, 0x30" "\n"
3525 "\t" " bnez $a3, .Loptimized_memcpy_11" "\n"
3526 "\t" " addiu $a0, $a0, 0x30" "\n"
3527 "\t" ".Loptimized_memcpy_12:" "\n"
3528 "\t" " andi $v1, $a2, 0x3" "\n"
3529 "\t" " beqz $v1, .Loptimized_memcpy_14" "\n"
3531 "\t" ".Loptimized_memcpy_13:" "\n"
3532 "\t" " lb $v0, 0x0($a1)" "\n"
3533 "\t" " addiu $v1, $v1, -0x1" "\n"
3534 "\t" " sb $v0, 0x0($a0)" "\n"
3535 "\t" " addiu $a1, $a1, 0x1" "\n"
3536 "\t" " bnez $v1, .Loptimized_memcpy_13" "\n"
3537 "\t" " addiu $a0, $a0, 0x1" "\n"
3538 "\t" ".Loptimized_memcpy_14:" "\n"
3539 "\t" " addu $v0, $a2, $zero" "\n"
3542 "\t" ".set pop" "\n"
3547void hex_dump(u8 *addr_start,
int length)
3551 KPRINTF(
"Hex Dump addr %08x\n", addr_start);
3552 for ( i = 0; i < length; i += 1 )
3554 if ( !(i & 0xF) && i )
3558 KPRINTF(
" %02x", addr_start[i]);
3564static int cdvdman_initcfg(
void)
3571 for ( i = 0; i <= 100; i += 1 )
3573 unsigned int mvored;
3575#ifdef CDVD_VARIANT_XOSD
3576 if ( !
sceCdMV(m_version, &eflag) )
3578 if ( !
sceCdMV(m_version, &eflag) && (eflag & 0x80) )
3582 VERBOSE_KPRINTF(1,
"_sceCdMV error\n");
3584 mvored = m_version[3] | (m_version[2] << 8) | (m_version[1] << 16);
3585 g_cdvdman_emudvd9 = m_version[2] & 1;
3586 VERBOSE_KPRINTF(1,
"MV %02x %02x %02x %02x\n", m_version[0], m_version[1], m_version[2], m_version[3]);
3587 g_cdvdman_minver_10700 = mvored >= 0x10700;
3588 g_cdvdman_minver_20200 = mvored >= 0x20200;
3589 g_cdvdman_minver_20400 = mvored >= 0x20400;
3590 g_cdvdman_minver_20800 = mvored >= 0x20800;
3591 g_cdvdman_minver_50000 = mvored >= 0x50000;
3592 g_cdvdman_minver_50200 = mvored >= 0x50200;
3593 g_cdvdman_minver_50400 = mvored >= 0x50400;
3594 g_cdvdman_minver_50600 = mvored >= 0x50600;
3595#ifdef CDVD_VARIANT_XOSD
3596 VERBOSE_KPRINTF(0,
"M Version %02x %02x %02x %02x\n", m_version[0], m_version[1], m_version[2], m_version[3]);
3597 if ( cdvdman_get_renewal_date(m_version, &eflag) )
3601 "M Renewal Date 20%02x/%02x/%02x %02x:%02x\n",
3608 g_cdvdman_vernotxxx1x = 0;
3609 if ( g_cdvdman_minver_50600 )
3612 KPRINTF(
"X_model ");
3613 switch ( mvored & 0xF0 )
3616 KPRINTF(
"量産 OR 量産試作機\n");
3620 g_cdvdman_vernotxxx1x = 1;
3623 KPRINTF(
"手作り試作機\n");
3629 KPRINTF(
"Unkown\n");
3635 KPRINTF(
"X_model 旧原理試作機 Ver5.6未満 Found\n");
3638 g_cdvdman_minver_x_model_15 = (mvored & 0xF) == 1;
3639 g_cdvdman_minver_60000 = mvored >= 0x60000;
3640 g_cdvdman_minver_60200 = mvored >= 0x60200;
3641#ifdef CDVD_VARIANT_OSD
3642 g_cdvdman_minver_60600 = mvored >= 0x60600;
3649static int vSetAlarm(
iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *arg),
void *arg)
3651 return (
QueryIntrContext() ? iSetAlarm : SetAlarm)(sys_clock, alarm_cb, arg);
3654static int vCancelAlarm(
unsigned int (*alarm_cb)(
void *arg),
void *arg)
3660s32 vSignalSema(s32 sema_id)
3666static int vSetEventFlag(
int ef, u32 bits)
3671static int vClearEventFlag(
int ef, u32 bits)
3681static int vPollEventFlag(
int ef, u32 bits,
int mode, u32 *efbits)
3683#ifdef CDVD_VARIANT_XOSD
3689 return PollEventFlag(ef, bits, mode, efbits);
3691 retres = iReferEventFlagStatus(ef, &efinfo);
3697 if ( (mode & 1) ? !(efinfo.
currBits & bits) : ((efinfo.
currBits & bits) != bits) )
3703 iClearEventFlag(ef, ~bits);
3707 return PollEventFlag(ef, bits, mode, efbits);
3711static int vDelayThread(
int usec)
3721#ifdef CDVD_VARIANT_XOSD
3722static int get_cdvd_register(
int regnr)
3734 if ( !IntrContext && !intrres )
3736 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3743 iReferEventFlagStatus(g_cdvdman_csys_evfid, &efinfo);
3747 ReferEventFlagStatus(g_cdvdman_csys_evfid, &efinfo);
3754 if ( update_cd_mode_ps2_atapi() != 1 )
3756 regval = ((vu8 *)(0xBF402000))[regnr];
3760 if ( !IntrContext && !intrres )
3763 if ( g_cd_atapi_evfid != -1 )
3765 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
3767 if ( g_adma_evfid != -1 )
3769 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3771 if ( g_acmd_evfid != -1 )
3773 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3779 if ( g_cd_atapi_evfid != -1 )
3783 iReferEventFlagStatus(g_cd_atapi_evfid, &efinfo);
3787 ReferEventFlagStatus(g_cd_atapi_evfid, &efinfo);
3794 if ( g_adma_evfid != -1 )
3798 iReferEventFlagStatus(g_adma_evfid, &efinfo);
3802 ReferEventFlagStatus(g_adma_evfid, &efinfo);
3809 if ( g_acmd_evfid != -1 )
3813 iReferEventFlagStatus(g_acmd_evfid, &efinfo);
3817 ReferEventFlagStatus(g_acmd_evfid, &efinfo);
3825 set_cdvd_dev5_base_addr_atapi(2);
3826 regval = ((vu8 *)(0xBF402000))[regnr];
3827 set_cdvd_dev5_base_addr_atapi(1);
3828 if ( !IntrContext && !intrres )
3830 if ( g_acmd_evfid != -1 )
3832 SetEventFlag(g_acmd_evfid, 1);
3834 if ( g_adma_evfid != -1 )
3836 SetEventFlag(g_adma_evfid, 1);
3838 if ( g_cd_atapi_evfid != -1 )
3840 SetEventFlag(g_cd_atapi_evfid, 3);
3844 if ( !IntrContext && !intrres )
3847 SetEventFlag(g_cdvdman_csys_evfid, 1);
3854static unsigned int read_timeout_alarm_cb(
void *userdata)
3860 read_timeout = sys_clock->lo / 0x9000;
3861 KPRINTF(
"Read Time Out %d(msec)\n", read_timeout);
3862 sceCdSC(0xFFFFFFEE, &read_timeout);
3871 if (
sceCdSync(1) || PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
3875 rc = g_cdvdman_user_cb;
3876 g_cdvdman_user_cb = function;
3877 vSetEventFlag(g_ncmd_evfid, 1);
3888 old_cb = g_cdvdman_power_off_callback;
3889 g_cdvdman_power_off_callback = func;
3890 g_cdvdman_power_off_callback_userdata = userdata;
3895#ifdef CDVD_VARIANT_XOSD
3902 old_cb = g_cdvdman_atapi_eject_bs_power_callback;
3903 g_cdvdman_atapi_eject_bs_power_callback = func;
3904 g_cdvdman_atapi_eject_bs_power_callback_userdata = userdata;
3910int sceCdstm0Cb(
void (*p)(
int val))
3912 g_cdvdman_cdstm0cb = p;
3916int sceCdstm1Cb(
void (*p)(
int val))
3918 g_cdvdman_cdstm1cb = p;
3926 int ext_passthrough;
3927 USE_DEV5_MMIO_HWPORT();
3929 ext_passthrough = 0;
3930 s->m_wait_flag = s->m_waf_set_test;
3931 iSetEventFlag(g_cdvdman_intr_evfid, 0x29);
3933 if ( s->m_cdvdman_command == SCECdFuncStandby && s->m_last_error ==
SCECdErTRMOPN )
3942 1,
"Intr call func_num: %d Err= %02x OnTout= %d\n", g_cdvdman_cmdfunc, (u8)s->m_last_error, s->m_last_read_timeout);
3943 if ( !s->m_scmd_flag )
3945 cdvdman_write_scmd(s);
3948 (((u8)s->m_last_error ==
SCECdErREAD && g_cdvdman_cmdfunc == SCECdFuncRead)
3949 || ((u8)s->m_last_error ==
SCECdErABRT && s->m_last_read_timeout && g_cdvdman_last_cmdfunc == SCECdFuncRead))
3950 && !g_cdvdman_minver_20200 && !s->m_stream_flag && !s->m_dvd_flag && !s->m_recover_status
3953 s->m_sync_error = 0;
3954 s->m_interupt_read_state = 0;
3955 if ( s->m_dec_mode_set )
3957 s->m_dec_mode_last_set = 1;
3961 VERBOSE_KPRINTF(1,
"dec mode 0x00\n");
3962 s->m_read_chunk_reprocial_32 = 1 + (0x20 / ((!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk));
3963 s->m_dintrlsn = (s->m_read_lsn < 0x61) ? (s->m_read_lsn + s->m_read_sectors + 48) : (s->m_read_lsn - 80);
3965 if ( !sceCdRead0_Rty(
3967 (!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk,
3970 (u8)s->m_cdvdman_command,
3975 s->m_recover_status = 0;
3979 ext_passthrough = 1;
3983 if ( !ext_passthrough )
3985 char dev5_reg_013_masked;
3987 VERBOSE_KPRINTF(1,
"Recover_Stat:%d\n", s->m_recover_status);
3988 dev5_reg_013_masked = dev5_mmio_hwport->m_dev5_reg_013 & 0xF;
3989 if ( dev5_reg_013_masked )
3993 && !s->m_recover_status && !s->m_stream_flag && g_cdvdman_cmdfunc != 9 && g_cdvdman_cmdfunc != SCECdFuncReadCDDA
3994 && (
unsigned int)s->m_read_mode.
trycount - 1 >= 4 )
3996 s->m_sync_error = 0;
3997 s->m_interupt_read_state = 0;
3998 if ( s->m_dec_mode_set )
4000 s->m_dec_mode_last_set = 2;
4004 VERBOSE_KPRINTF(1,
"dec mode 0x01\n");
4006 cdrmode.
spindlctrl = dev5_reg_013_masked + 13;
4008 if ( sceCdRead0_Rty(
4013 (u8)s->m_cdvdman_command,
4015 s->m_read_callback) )
4024 s->m_last_read_timeout = 0;
4025 switch ( s->m_recover_status )
4028 s->m_sync_error = 0;
4029 s->m_interupt_read_state = 0;
4034 (!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk,
4037 (u8)s->m_cdvdman_command,
4042 s->m_recover_status = 0;
4046 ext_passthrough = 1;
4050 s->m_sync_error = 0;
4051 s->m_interupt_read_state = 0;
4053 s->m_read_lsn, s->m_read_sectors, s->m_read_buf, &s->m_read_mode, s->m_read_chunk, s->m_read_callback) )
4056 s->m_recover_status = 3;
4060 s->m_recover_status = 0;
4063 s->m_recover_status = 0;
4069 if ( ext_passthrough )
4072 s->m_dintrlsn += s->m_read_sectors;
4073 s->m_read_chunk_reprocial_32 -= 1;
4074 s->m_recover_status = (!s->m_read_chunk_reprocial_32) ? 2 : 1;
4077 if ( s->m_dec_state )
4081 if ( (s->m_read2_flag == 1 || s->m_read2_flag == 3) && !s->m_use_toc )
4083 VERBOSE_KPRINTF(1,
"call Read2intrCDVD()\n");
4084 Read2intrCDVD(s->m_read2_flag);
4086 s->m_sync_error = 0;
4087 s->m_interupt_read_state = 0;
4088 if ( s->m_dec_state == 2 )
4092 if ( s->m_stream_flag == 1 && !s->m_use_toc && !s->m_read2_flag )
4094 if ( g_cdvdman_cdstm0cb )
4096 g_cdvdman_cdstm0cb(1);
4100 VERBOSE_KPRINTF(1,
"Intr func0 no seting");
4103 if ( !s->m_read2_flag )
4105 if ( s->m_stream_flag == 2 && !s->m_use_toc )
4107 if ( g_cdvdman_cdstm1cb )
4109 g_cdvdman_cdstm1cb(1);
4113 VERBOSE_KPRINTF(1,
"Intr func1 no seting");
4118 g_cdvdman_readptr = 0;
4123 1,
"Intr call user callback func_addr %08x num %d flg %d\n", g_cdvdman_user_cb, g_cdvdman_cmdfunc, s->m_read2_flag);
4124 if ( g_cdvdman_user_cb && g_cdvdman_cmdfunc && !s->m_read2_flag && !s->m_use_toc )
4128 cmdfunc_tmp = g_cdvdman_cmdfunc;
4129 g_cdvdman_cmdfunc = 0;
4130 if ( cmdfunc_tmp == 14 || cmdfunc_tmp == 9 )
4132 cmdfunc_tmp = SCECdFuncRead;
4134 g_cdvdman_user_cb(cmdfunc_tmp);
4136 if ( !g_cdvdman_user_cb )
4138 g_cdvdman_cmdfunc = 0;
4143static int intrh_cdrom(
void *userdata)
4147#ifdef CDVD_VARIANT_XOSD
4152 USE_DEV5_MMIO_HWPORT();
4156#ifdef CDVD_VARIANT_XOSD
4157 if ( s->m_cd_mode_ps2_atapi == 1 )
4159 int spd_intr_stat_cur;
4160 int atapi_intr_reason;
4162 VERBOSE_KPRINTF(1,
"Atapi Intr Called %d\n", g_cdvdman_debug_atapi_intr++);
4163 condaddr5 = (
unsigned int)GetBaseAddress(5) == 0x1F402000;
4164 set_cdvd_dev5_base_addr_atapi(1);
4165 (void)*(vu16 *)0xBF410028;
4166 set_cdvd_dev5_base_addr_atapi(2);
4167 atapi_intr_reason = dev5_mmio_hwport->m_dev5_reg_008;
4168 if ( (atapi_intr_reason & 1) )
4171 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4172 VERBOSE_KPRINTF(1,
"ATAPI DRAGON CMDCMPL Interrupt\n");
4174 if ( atapi_intr_reason & 4 )
4176 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4178 iSetEventFlag(g_cdvdman_intr_evfid, 4);
4179 iSetEventFlag(g_cdvdman_intr_evfid, 0x10);
4180 set_cdvd_dev5_base_addr_atapi(1);
4181 VERBOSE_KPRINTF(1,
"ATAPI POFFRDY Interrupt\n");
4182 if ( g_cdvdman_power_off_callback )
4184 g_cdvdman_power_off_callback(g_cdvdman_power_off_callback_userdata);
4186 set_cdvd_dev5_base_addr_atapi(2);
4188 if ( (atapi_intr_reason & 8) )
4191 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4192 if ( !s->m_medium_removal_state )
4194 s->m_atapi_disk_ejected = 0;
4196 set_cdvd_dev5_base_addr_atapi(1);
4197 VERBOSE_KPRINTF(1,
"ATAPI EJECT Interrupt\n");
4198 if ( s->m_cd_atapi_intr_callback && !s->m_medium_removal_state )
4200 VERBOSE_KPRINTF(1,
"EJECT Stop Call\n");
4201 s->m_cd_atapi_intr_callback(1);
4203 iSetEventFlag(g_cdvdman_intr_evfid, 0x40);
4204 if ( g_cdvdman_atapi_eject_bs_power_callback )
4206 VERBOSE_KPRINTF(1,
"ATAPI EJECT Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4207 g_cdvdman_atapi_eject_bs_power_callback(1, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4209 set_cdvd_dev5_base_addr_atapi(2);
4211 if ( (atapi_intr_reason & 0x10) )
4213 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4215 set_cdvd_dev5_base_addr_atapi(1);
4216 VERBOSE_KPRINTF(1,
"ATAPI BS_Power DET Interrupt\n");
4217 iSetEventFlag(g_cdvdman_intr_evfid, 0x80);
4218 if ( g_cdvdman_atapi_eject_bs_power_callback )
4220 VERBOSE_KPRINTF(1,
"ATAPI BS_Power Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4221 g_cdvdman_atapi_eject_bs_power_callback(2, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4224 set_cdvd_dev5_base_addr_atapi(1);
4225 if ( g_cdvdman_vernotxxx1x && conds1 )
4227 *(vu16 *)0xBF41002A &= ~0x100;
4228 *(vu16 *)0xBF41002A |= 0x100;
4229 (void)*(vu16 *)0xBF41002A;
4231 spd_intr_stat_cur = *(vu16 *)0xBF410028;
4234 "Atapi Intr Mode:%d addr:%08x Reason:%02x SPD_INTR_STAT %x\n",
4235 s->m_cd_mode_ps2_atapi,
4236 s->m_cd_atapi_intr_callback,
4239 if ( (spd_intr_stat_cur & 3) && (*g_cdvdreg_bf80146c & 4) )
4241 if ( s->m_cd_atapi_intr_callback )
4243 s->m_cd_atapi_intr_callback(0);
4244 VERBOSE_KPRINTF(1,
"Atapi Intr called\n");
4246 if ( !s->m_scmd_flag )
4248 VERBOSE_KPRINTF(1,
"Intr call set_prev_command.\n");
4249 set_cdvd_dev5_base_addr_atapi(2);
4250 cdvdman_write_scmd(s);
4251 set_cdvd_dev5_base_addr_atapi(1);
4256 if ( (*g_cdvdreg_bf80146c & 4) )
4258 VERBOSE_KPRINTF(1,
"No_Reason Intr\n");
4262 VERBOSE_KPRINTF(1,
"already 9611 Power Off Intr\n");
4267 set_cdvd_dev5_base_addr_atapi(2);
4268 VERBOSE_KPRINTF(1,
"Cur PS2 IO Intr Called\n");
4272 VERBOSE_KPRINTF(1,
"Dragon Intr Called\n");
4273 condaddr5 = (
unsigned int)GetBaseAddress(5) == 0xBF410000;
4276 set_cdvd_dev5_base_addr_atapi(2);
4279 s->m_waf_set_test = s->m_wait_flag;
4282 s->m_last_error = dev5_mmio_hwport->m_dev5_reg_006;
4284 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 1) )
4286 s->m_waf_set_test = (!(dev5_mmio_hwport->m_dev5_reg_005 & 1)) ? 1 : -1;
4287 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4290 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 4) )
4292 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4293 iSetEventFlag(g_cdvdman_intr_evfid, 4);
4294 iSetEventFlag(g_cdvdman_intr_evfid, 0x10);
4296 VERBOSE_KPRINTF(1,
"PS2 POWER OFF Interrupt\n");
4297 if ( g_cdvdman_power_off_callback )
4299 g_cdvdman_power_off_callback(g_cdvdman_power_off_callback_userdata);
4308 s->m_waf_set_test = 1;
4309 s->m_ncmd_intr_count += 1;
4310 dev5_mmio_hwport->m_dev5_reg_008 = 2;
4312#ifdef CDVD_VARIANT_XOSD
4313 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 8) )
4315 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4316 VERBOSE_KPRINTF(1,
"PS2 EJECT Interrupt\n");
4317 iSetEventFlag(g_cdvdman_intr_evfid, 0x40);
4318 if ( !s->m_medium_removal_state )
4320 s->m_atapi_disk_ejected = 0;
4322 if ( g_cdvdman_atapi_eject_bs_power_callback )
4324 VERBOSE_KPRINTF(1,
"PS2 EJECT Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4325 g_cdvdman_atapi_eject_bs_power_callback(1, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4328 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 0x10) )
4330 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4331 VERBOSE_KPRINTF(1,
"PS2 BS_Power DET Interrupt\n");
4332 iSetEventFlag(g_cdvdman_intr_evfid, 0x80);
4333 if ( g_cdvdman_atapi_eject_bs_power_callback )
4335 VERBOSE_KPRINTF(1,
"PS2 BS_Power Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4336 g_cdvdman_atapi_eject_bs_power_callback(2, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4340 iReferEventFlagStatus(g_cdvdman_intr_evfid, &efinfo);
4344 VERBOSE_KPRINTF(1,
"Now DMA Working evfid:%08x\n", efinfo.
currBits);
4347 s->m_drive_interupt_request = 1;
4348#ifdef CDVD_VARIANT_XOSD
4351 set_cdvd_dev5_base_addr_atapi(1);
4361 intr_cb_res = cdvdman_intr_cb(s);
4362#ifdef CDVD_VARIANT_XOSD
4365 set_cdvd_dev5_base_addr_atapi(1);
4371static u32 cdvdman_l1start(
const u8 *
toc)
4373 return toc[23] + (
toc[22] << 8) + (
toc[21] << 16) - 0x30000 + 1;
4376static int DvdDual_infochk(
void)
4378#ifdef CDVD_VARIANT_OSD
4380 if (
QueryIntrContext() || !(cdvdman_mediactl(3) || (u8)g_cdvdman_istruct.m_opo_or_para == 0xFF) )
4382 if (
QueryIntrContext() || !(cdvdman_mediactl(4) || (u8)g_cdvdman_istruct.m_opo_or_para == 0xFF) )
4387 g_cdvdman_istruct.m_use_toc = 1;
4388 if ( !cdvdman_gettoc(g_cdvdman_ptoc) )
4390 g_cdvdman_istruct.m_use_toc = 0;
4391 g_cdvdman_istruct.m_opo_or_para = -1;
4394 g_cdvdman_istruct.m_use_toc = 0;
4395 g_cdvdman_istruct.m_layer_1_lsn = cdvdman_l1start(g_cdvdman_ptoc);
4396 g_cdvdman_istruct.m_opo_or_para = ((g_cdvdman_ptoc[14] & 0x60)) ? (((g_cdvdman_ptoc[14] & 0x10)) ? 2 : 1) : 0;
4397 if ( g_cdvdman_istruct.m_dual_layer_emulation )
4399 VERBOSE_KPRINTF(1,
"CDVD:DualEmuON\n");
4400 g_cdvdman_istruct.m_layer_1_lsn = g_cdvdman_istruct.m_current_dvd_lsn;
4401 g_cdvdman_istruct.m_opo_or_para = 0;
4405 "DvdDual_info: %02x\tLayer1_LSN:%d opo_or_para %d\n",
4407 g_cdvdman_istruct.m_layer_1_lsn,
4408 (u8)g_cdvdman_istruct.m_opo_or_para);
4412static u32 sceCdLsnDualChg(u32 lsn)
4414 int layer_disk_needed;
4419 layer_disk_needed = 2;
4421 if ( cdvdman_isdvd() && DvdDual_infochk() )
4423 if ( g_cdvdman_istruct.m_dual_layer_emulation )
4425 if ( !g_cdvdman_istruct.m_current_dvd && lsn >= g_cdvdman_istruct.m_current_dvd_lsn )
4427 layer_disk_needed = 1;
4429 if ( g_cdvdman_istruct.m_current_dvd && lsn < g_cdvdman_istruct.m_current_dvd_lsn )
4431 layer_disk_needed = 0;
4433 if ( layer_disk_needed == 2 )
4435 change_lsn = lsn - ((g_cdvdman_istruct.m_current_dvd) ? g_cdvdman_istruct.m_current_dvd_lsn : 0);
4442 VERBOSE_KPRINTF(0,
"CDVD: Exchange it for the Layer_%d_Disk Please.\n", layer_disk_needed);
4450 g_cdvdman_istruct.m_use_toc = 1;
4451 while ( layer_disk_needed != 2 )
4453 if ( cdvdman_isdvd() )
4457 read0_result = sceCdRead0(0xE, 1, g_cdvdman_ptoc, &cdrmode, 0, 0);
4459 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO || read0_result )
4463 for ( i = 0; i < 20; i += 1 )
4465 if ( g_cdvdman_ptoc[i + 104] != g_masterdisc_header[i] )
4470 if ( i == 20 && g_cdvdman_ptoc[131] == 2 && (g_cdvdman_ptoc[132] & 2) )
4472 if ( layer_disk_needed == g_cdvdman_ptoc[133] )
4474 g_cdvdman_istruct.m_current_dvd = layer_disk_needed;
4475 layer_disk_needed = 2;
4479 VERBOSE_KPRINTF(0,
"CDVD: Layer_%d Disk not Found\n", layer_disk_needed);
4480 VERBOSE_KPRINTF(0,
"CDVD: Exchange it for the Layer_%d_Disk Please.\n", layer_disk_needed);
4481 if ( !g_cdvdman_istruct.m_current_dvd && lsn >= g_cdvdman_istruct.m_current_dvd_lsn )
4483 layer_disk_needed = 1;
4493 VERBOSE_KPRINTF(0,
"CDVD: Not Master Disk %s\n", (
const char *)&g_cdvdman_ptoc[i + 104]);
4502 VERBOSE_KPRINTF(1,
"CDVD: LsnDualChg Read Error %02x, %d\n", (u8)g_cdvdman_istruct.m_last_error, 0);
4507 vDelayThread(16000);
4510 change_lsn = lsn - ((g_cdvdman_istruct.m_current_dvd) ? g_cdvdman_istruct.m_current_dvd_lsn : 0);
4511 g_cdvdman_istruct.m_use_toc = 0;
4518 lsn - ((g_cdvdman_istruct.m_opo_or_para && (lsn >= (u32)g_cdvdman_istruct.m_layer_1_lsn)) ? 0x10 : 0);
4522 if ( has_change_lsn )
4524 VERBOSE_KPRINTF(1,
"CDVD: sceCdLsnDualChg lsn %d: change lsn %d\n", lsn, change_lsn);
4526 return has_change_lsn ? change_lsn : lsn;
4537 g_cdvdman_istruct.m_dual_layer_emulation = 0;
4538#ifndef CDVD_VARIANT_XOSD
4539 if ( !cdvdman_isdvd() )
4544 if ( !g_cdvdman_emudvd9 )
4546 if ( !DvdDual_infochk() )
4550 *on_dual = !!g_cdvdman_istruct.m_opo_or_para;
4551 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4554#ifdef CDVD_VARIANT_OSD
4555 if ( !cdvdman_isdvd() )
4560#ifndef CDVD_VARIANT_XOSD
4561 if ( g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF )
4569 read0_result = sceCdRead0(0xE, 1, g_cdvdman_ptoc, &cdrmode, 0, 0);
4571 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO && !read0_result )
4573 VERBOSE_KPRINTF(1,
"CDVD: ReadDvdDualInfo Read Error %02x, %d\n", (u8)g_cdvdman_istruct.m_last_error, 0);
4576 for ( i = 0; i < 20; i += 1 )
4578 if ( g_cdvdman_ptoc[i + 104] != g_masterdisc_header[i] )
4585 if ( !DvdDual_infochk() )
4589 *on_dual = !!g_cdvdman_istruct.m_opo_or_para;
4590 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4593 if ( g_cdvdman_ptoc[131] != 2 || !(g_cdvdman_ptoc[132] & 2) )
4597 g_cdvdman_istruct.m_current_dvd = g_cdvdman_ptoc[133];
4598 g_cdvdman_istruct.m_current_dvd_lsn =
4599 g_cdvdman_ptoc[134] + (g_cdvdman_ptoc[135] << 8) + (g_cdvdman_ptoc[136] << 16) + (g_cdvdman_ptoc[137] << 24) + 1;
4600 g_cdvdman_istruct.m_opo_or_para = 0;
4601 g_cdvdman_istruct.m_layer_1_lsn = g_cdvdman_istruct.m_current_dvd_lsn;
4602 g_cdvdman_istruct.m_dual_layer_emulation = 1;
4604 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4607 "sceCdReadDvdDualInfo():Cur_Disk %d layer1_start %d\n",
4608 (u8)g_cdvdman_istruct.m_current_dvd,
4609 g_cdvdman_istruct.m_current_dvd_lsn);
4613int sceCdSC(
int code,
int *param)
4619#ifdef CDVD_VARIANT_XOSD
4625#ifdef CDVD_VARIANT_XOSD
4628 set_cdvd_dev5_base_addr_atapi(2);
4629 regval = ((vu8 *)(0xBF402000))[*param];
4630 set_cdvd_dev5_base_addr_atapi(1);
4635 *param = (int)&g_cdvdman_istruct.m_chgsys_writer_drive_shell_is_open;
4639 return sc_ffffffd8((u32 *)param);
4642 *param = (int)&g_cdvdman_istruct.m_atapi_disk_ejected;
4646 return get_disk_type_ex();
4649 *(&g_cdvdman_istruct.m_var_sc_ffffffdb) = (
int)param;
4653 return g_cdvdman_vernotxxx1x;
4655 return get_cdvd_register(*param);
4657 g_adma_evfid = *param;
4660 g_acmd_evfid = *param;
4664 g_cdvdman_istruct.m_chgsys_callback = (
void *)(
int)param;
4668 g_cd_atapi_evfid = *param;
4672 g_cdvdman_istruct.m_cd_atapi_intr_callback = (
void *)(
int)param;
4678 *param = (int)g_cdvdman_power_off_callback;
4679 poffarg_tmp = g_cdvdman_power_off_callback_userdata;
4681 return (
int)poffarg_tmp;
4683 return g_scmd_evfid;
4685 return sceCdLsnDualChg(*param);
4687 return DvdDual_infochk();
4689 g_cdvdman_istruct.m_last_read_timeout = *param;
4692 return g_cdvdman_stream_timeout;
4694 *param = (int)&g_verbose_level;
4697 return g_cdvdman_sync_timeout;
4699 *param = (int)&g_cdvdman_istruct;
4702 BootMode = QueryBootMode(4);
4703 switch ( BootMode ? *(u8 *)BootMode : 0xFF )
4708 g_cdvdman_mmode = 0xFF;
4711 g_cdvdman_mmode = SCECdMmodeCd;
4718#ifdef CDVD_VARIANT_OSD
4728 return g_cdvdman_mmode == SCECdMmodeCd || g_cdvdman_mmode == 0xFF;
4730 return g_cdvdman_mmode == SCECdMmodeDvd || g_cdvdman_mmode == 0xFF;
4732 return g_cdvdman_mmode == 0xFF;
4738 return g_cdvdman_intr_evfid;
4742 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
4746 SetEventFlag(g_fio_fsv_evfid, 1);
4748 g_cdvdman_ee_rpc_fno = *param;
4749 VERBOSE_KPRINTF(1,
"EE_ncmd_working code= %d\n", *param);
4750 return g_cdvdman_ee_rpc_fno;
4752 return (u16)_irx_id.v;
4754 g_cdvdman_spinctl = *param;
4757 return g_cdvdman_cd36key;
4759 return g_cdvdman_istruct.m_read2_flag;
4761 g_cdvdman_istruct.m_last_error = *(u8 *)param;
4762 return (u8)g_cdvdman_istruct.m_last_error;
4767 *param = (u8)g_cdvdman_istruct.m_last_error;
4770 g_cdvdman_istruct.m_stream_flag = code;
4772 return g_cdvdman_istruct.m_stream_flag;
4774 VERBOSE_KPRINTF(1,
"sceCdSC func_num Not found %d\n", code);
4779static void cdvdman_init(
void)
4785#ifdef CDVD_VARIANT_XOSD
4788 USE_DEV5_MMIO_HWPORT();
4790#ifdef CDVD_VARIANT_XOSD
4794 g_cdvdman_istruct.m_cd_mode_ps2_atapi = 2;
4795 cdvdman_change_drive(2);
4799 g_cdvdman_user_cb = 0;
4800 g_cdvdman_power_off_callback = 0;
4801 g_cdvdman_cmdfunc = 0;
4802 g_cdvdman_istruct.m_drive_interupt_request = 0;
4806 sceCdSC(0xFFFFFFF3, &scres_unused);
4807 dmac_set_dpcr(dmac_get_dpcr() | 0x8000);
4808 dmac_ch_set_chcr(3, 0);
4809#ifdef CDVD_VARIANT_XOSD
4810 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 0x10) )
4812 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4814 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 8) )
4816 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4819 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 4) )
4821 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4823 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 1) )
4825 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4827#ifndef CDVD_VARIANT_XOSD
4830 g_cdvdman_istruct.m_tray_is_open = !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen);
4831#ifdef CDVD_VARIANT_XOSD
4835 BootMode = QueryBootMode(6);
4836 g_cdvdman_istruct.m_no_dec_flag = BootMode ? ((*(u16 *)BootMode & 0xFFFC) == 0x60) : 0;
4841#ifdef CDVD_VARIANT_XOSD
4850 for ( i = 0; i <= 60 && (!(MediumRemoval =
sceCdGetMediumRemoval(&medium_res, &argres)) || argres); i += 1 )
4854 g_cdvdman_istruct.m_medium_removal_state = (MediumRemoval && !argres) ? medium_res : 0;
4860 g_cdvdman_istruct.m_cd_mode_ps2_atapi =
4861 (chgsys_tmp || (!(dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && dev5_mmio_hwport->m_dev5_reg_00F != 6)) ? 2 : 1;
4862 cdvdman_change_drive(g_cdvdman_istruct.m_cd_mode_ps2_atapi);
4875 VERBOSE_PRINTF(1,
"sceCdInit called mode= %d\n", mode);
4880 g_cdvdman_istruct.m_cd_inited = 0;
4881#ifndef CDVD_VARIANT_XOSD
4884 cdvdman_ncmd_sender_06();
4887 VERBOSE_PRINTF(1,
"Cdvdman Exit\n");
4895 VERBOSE_PRINTF(1,
"Cdvdman Init\n");
4896 g_cdvdman_istruct.m_read2_flag = 0;
4897 g_cdvdman_istruct.m_dec_shift = 0;
4898 g_cdvdman_istruct.m_check_version = 0;
4899 g_cdvdman_istruct.m_dec_state = 0;
4900#ifdef CDVD_VARIANT_XOSD
4901 if ( update_cd_mode_ps2_atapi() != 1 )
4907 g_cdvdman_istruct.m_cd_inited = 1;
4911 u8 ready_status_tmp;
4914 ready_status_tmp = 0;
4915 VERBOSE_PRINTF(1,
"sceCdInit Ready check start.\n");
4917 while ( (ready_status & 0xC0) != 0x40 )
4919#ifdef CDVD_VARIANT_XOSD
4922 g_cdvdman_istruct.m_field_0DC = 0;
4927 vDelayThread(10000);
4928 if ( ready_status != ready_status_tmp )
4930 ready_status_tmp = ready_status;
4931 VERBOSE_PRINTF(1,
"sceCdInit Dev5 Status %x\n", ready_status);
4934 VERBOSE_PRINTF(1,
"sceCdInit Ready check %x\n", ready_status);
4936 VERBOSE_PRINTF(1,
"sceCdInit Ready check end.\n");
4938 g_cdvdman_istruct.m_wait_flag = 1;
4939 g_cdvdman_istruct.m_scmd_flag = 1;
4940 g_cdvdman_istruct.m_last_error =
SCECdErNO;
4941 g_cdvdman_istruct.m_last_read_timeout = 0;
4942 g_cdvdman_spinctl = -1;
4943 SetEventFlag(g_cdvdman_intr_evfid, 0x29);
4944 SetEventFlag(g_ncmd_evfid, 1);
4945 SetEventFlag(g_scmd_evfid, 1);
4946 SetEventFlag(g_sfile_evfid, 1);
4950static int set_prev_command(
int cmd,
const char *sdata,
int sdlen,
char *rdata,
int rdlen,
int check_sef)
4956#ifdef CDVD_VARIANT_XOSD
4960#ifdef CDVD_VARIANT_XOSD
4968 VERBOSE_KPRINTF(1,
"set_prev_command cmd %02x call\n", cmd);
4971 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
4974 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
4977 VERBOSE_KPRINTF(1,
"set_prev_command Double Booking\n");
4978#ifdef CDVD_VARIANT_XOSD
4981 SetEventFlag(g_cdvdman_csys_evfid, 1);
4986 g_cdvdman_istruct.m_scmd = cmd;
4987 g_cdvdman_istruct.m_sdlen = sdlen;
4988 g_cdvdman_istruct.m_rdlen = rdlen;
4989 for ( i = 0; i < sdlen; i += 1 )
4991 g_cdvdman_istruct.m_scmd_sd[i] = sdata[i];
4993#ifdef CDVD_VARIANT_XOSD
4994 if ( update_cd_mode_ps2_atapi() != 1 )
4997 if ( g_cdvdman_istruct.m_wait_flag )
4999 g_cdvdman_istruct.m_scmd_flag = 1;
5000 cdvdman_write_scmd(&g_cdvdman_istruct);
5004 while ( (dmac_ch_get_chcr(3) & 0x1000000) && !g_cdvdman_istruct.m_wait_flag )
5006 VERBOSE_KPRINTF(1,
"set_prev_command: DMA Wait\n");
5008 g_cdvdman_istruct.m_scmd_flag = 1;
5009 cdvdman_write_scmd(&g_cdvdman_istruct);
5013 g_cdvdman_istruct.m_scmd_flag = 0;
5016#ifdef CDVD_VARIANT_XOSD
5021 if ( g_cd_atapi_evfid != -1 )
5023 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
5025 if ( g_adma_evfid != -1 )
5027 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5029 if ( g_acmd_evfid != -1 )
5031 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5038 set_cdvd_dev5_base_addr_atapi(2);
5039 g_cdvdman_istruct.m_scmd_flag = 1;
5040 VERBOSE_KPRINTF(1,
"do_set_prev_command %02x\n", cmd);
5041 cdvdman_write_scmd(&g_cdvdman_istruct);
5042 set_cdvd_dev5_base_addr_atapi(1);
5047 if ( g_acmd_evfid != -1 )
5049 SetEventFlag(g_acmd_evfid, 1);
5051 if ( g_adma_evfid != -1 )
5053 SetEventFlag(g_adma_evfid, 1);
5055 if ( g_cd_atapi_evfid != -1 )
5057 SetEventFlag(g_cd_atapi_evfid, 3);
5063 for ( i = 0; i < 500; i += delaybackoff )
5065 if ( g_cdvdman_istruct.m_scmd_flag )
5067 for ( j = 0; j < rdlen; j += 1 )
5069 rdata[j] = g_cdvdman_istruct.m_scmd_rd[j];
5071 if ( check_sef == 1 )
5073 vSetEventFlag(g_scmd_evfid, 1);
5075#ifdef CDVD_VARIANT_XOSD
5076 VERBOSE_KPRINTF(1,
"set_prev_command end :%02x\n", (u8)g_cdvdman_istruct.m_scmd);
5079 SetEventFlag(g_cdvdman_csys_evfid, 1);
5082 return (u8)g_cdvdman_istruct.m_scmd;
5084 vDelayThread(1000 * delaybackoff);
5085 if ( (i & 1) && delaybackoff < 16 )
5090 g_cdvdman_istruct.m_scmd_flag = 1;
5091 if ( check_sef == 1 )
5093 vSetEventFlag(g_scmd_evfid, 1);
5104 USE_DEV5_MMIO_HWPORT();
5107 VERBOSE_KPRINTF(1,
"in:%d out_size:%d \n", (u8)s->m_sdlen, (u8)s->m_rdlen);
5109 VERBOSE_KPRINTF(1,
"cmd:%02x pram:%02x\n", (u8)s->m_scmd, (u8)s->m_scmd_sd[0]);
5110 for ( i = 0; i <= 0; i += 1 )
5113#ifdef CDVD_VARIANT_XOSD
5117 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5122 VERBOSE_KPRINTF(1,
"do_set_prev_command BUSY ABNORM END %08x\n", dev5_mmio_hwport->m_dev5_reg_017);
5125 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5129 for ( j = 0; j < (u8)s->m_sdlen; j += 1 )
5131 dev5_mmio_hwport->m_dev5_reg_017 = s->m_scmd_sd[j];
5133 dev5_mmio_hwport->m_dev5_reg_016 = s->m_scmd;
5134#ifdef CDVD_VARIANT_XOSD
5142#ifdef CDVD_VARIANT_XOSD
5148 for ( j = 0; dev5_mmio_hwport->m_dev5_reg_017 & 0x80; j += 1 )
5160 for ( j = 0; dev5_mmio_hwport->m_dev5_reg_017 & 0x80; j += 1 )
5166 VERBOSE_KPRINTF(1,
"Mecacon Scmd TIMEOUT CMD= %02x\n", (u8)s->m_scmd);
5174 for ( j = 0; j < (u8)s->m_rdlen; j += 1 )
5176 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5180 rdptr1[j] = dev5_mmio_hwport->m_dev5_reg_018;
5182 if ( j >= (u8)s->m_rdlen )
5185 VERBOSE_KPRINTF(1,
"Prev Cmd Result Over Flow\n", rdptr1);
5188 if ( (!overflowcond && j >= (u8)s->m_rdlen) || s->m_rdlen == 16 )
5192 VERBOSE_KPRINTF(1,
"Prev Cmd Result Illegal Size Try count:%d\n", i);
5201 for ( j = 0; j < (
sizeof(s->m_scmd_rd) /
sizeof(s->m_scmd_rd[0])); j += 1 )
5203 s->m_scmd_rd[j] = 0;
5205 if ( s->m_rdlen != (
sizeof(s->m_scmd_rd) /
sizeof(s->m_scmd_rd[0])) )
5207 rdcnt = (u8)s->m_rdlen;
5209 for ( j = 0; j < rdcnt; j += 1 )
5211 s->m_scmd_rd[j] = rdptr1[j];
5218#ifdef CDVD_VARIANT_XOSD
5219static int cdvdman_write_scmd_swap_dev5(
char cmd,
const char *wdata,
int sdlen,
char *rdata,
int rdlen,
int check_sef)
5227 USE_DEV5_MMIO_HWPORT();
5229 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5234 atapi_check = update_cd_mode_ps2_atapi() == 1;
5237 set_cdvd_dev5_base_addr_atapi(2);
5239 for ( i = 0; i <= 0; i += 1 )
5243 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5247 set_cdvd_dev5_base_addr_atapi(1);
5250 if ( check_sef == 1 )
5252 vSetEventFlag(g_scmd_evfid, 1);
5256 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5260 for ( j = 0; j < sdlen; j += 1 )
5262 dev5_mmio_hwport->m_dev5_reg_017 = wdata[j];
5264 dev5_mmio_hwport->m_dev5_reg_016 = cmd;
5265 while ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5270 for ( j = 0; !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40); j += 1 )
5275 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Over Flow\n");
5278 rdstart[j] = dev5_mmio_hwport->m_dev5_reg_018;
5280 if ( (!cmdresoverflow && j >= rdlen) || rdlen == 16 )
5284 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Illegal Size Try count:%d\n", i);
5285 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x20) )
5289 for ( j = 0; j < 16 - rdlen; j += 1 )
5297 set_cdvd_dev5_base_addr_atapi(1);
5300 if ( check_sef == 1 )
5302 vSetEventFlag(g_scmd_evfid, 1);
5306 for ( j = 0; j < rdlen; j += 1 )
5308 rdata[j] = rdstart[j];
5312 set_cdvd_dev5_base_addr_atapi(1);
5315 if ( check_sef == 1 )
5317 vSetEventFlag(g_scmd_evfid, 1);
5323static int cdvdman_send_scmd2(
int cmd,
const void *sdata,
int sdlen,
void *rdata,
int rdlen,
int check_sef)
5329 USE_DEV5_MMIO_HWPORT();
5331 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5335 for ( i = 0; i <= 0; i += 1 )
5339 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5341 if ( check_sef == 1 )
5343 vSetEventFlag(g_scmd_evfid, 1);
5347 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5351 for ( j = 0; j < sdlen; j += 1 )
5353 dev5_mmio_hwport->m_dev5_reg_017 = ((u8 *)sdata)[j];
5355 dev5_mmio_hwport->m_dev5_reg_016 = cmd;
5356 while ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5358#ifndef CDVD_VARIANT_XOSD
5363 for ( j = 0; !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40); j += 1 )
5369 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Over Flow\n");
5372 rdstart[j] = dev5_mmio_hwport->m_dev5_reg_018;
5374 if ( (!cmdresoverflow && j >= rdlen) || rdlen == 16 )
5379 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Illegal Size Try count:%d\n", i);
5380 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x20) )
5384 for ( j = 0; j < 16 - rdlen; j += 1 )
5389 if ( check_sef == 1 )
5391 vSetEventFlag(g_scmd_evfid, 1);
5395 for ( i = 0; i < rdlen; i += 1 )
5397 ((
char *)rdata)[i] = rdstart[i];
5399 if ( check_sef == 1 )
5401 vSetEventFlag(g_scmd_evfid, 1);
5406#ifdef CDVD_VARIANT_OSD
5407static unsigned int signal_sema_timeout_callback(
void *userdata)
5411 sema_id = (int)(u32)(uiptr)userdata;
5412 iSignalSema(sema_id);
5421#ifdef CDVD_VARIANT_OSD
5422 if ( g_cdvdman_minver_50000 )
5424 WaitSema(g_cdvdman_apply_scmd_sema);
5427 for ( i = 0; i <= 2500; i += 1 )
5429 if ( set_prev_command(cmdNum, (
const char *)inBuff, inBuffSize, (
char *)outBuff, 16, 1) )
5431#ifdef CDVD_VARIANT_OSD
5432 if ( g_cdvdman_minver_50000 )
5438 SetAlarm(&sysclk, signal_sema_timeout_callback, (
void *)g_cdvdman_apply_scmd_sema);
5449 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5453int sceCdApplySCmd2(u8 cmdNum,
const void *inBuff,
unsigned long int inBuffSize,
void *outBuff)
5455#ifdef CDVD_VARIANT_XOSD
5460 for ( i = 0; i <= 2500; i += 1 )
5462 if ( cdvdman_send_scmd2(cmdNum, inBuff, inBuffSize, outBuff, 16, 1) )
5468 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5473#ifdef CDVD_VARIANT_OSD
5474int sceCdApplySCmd3(u8 cmdNum,
const void *inBuff,
unsigned long int inBuffSize,
void *outBuff)
5478 for ( i = 0; i <= 2500; i += 1 )
5481 if ( set_prev_command((u8)cmdNum, inBuff, inBuffSize, outBuff, 16, 1) )
5487 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5497 USE_DEV5_MMIO_HWPORT();
5499 if ( PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5507 "Break call: read2_flg= %d func= %d lsn= %d csec= %d nsec= %d %rsec= %d addr= %p waitflg= %d, DriveIntrReq= %d "
5508 "stmflg= %d recover= %d\n",
5509 g_cdvdman_istruct.m_read2_flag,
5511 g_cdvdman_istruct.m_cdvdman_lsn,
5512 g_cdvdman_istruct.m_cdvdman_csec,
5513 g_cdvdman_istruct.m_cdvdman_nsec,
5514 g_cdvdman_istruct.m_cdvdman_rsec,
5515 g_cdvdman_istruct.m_read_buf,
5516 g_cdvdman_istruct.m_wait_flag,
5517 g_cdvdman_istruct.m_drive_interupt_request,
5518 g_cdvdman_istruct.m_stream_flag,
5519 g_cdvdman_istruct.m_recover_status);
5520 if ( g_cdvdman_istruct.m_last_read_timeout )
5522 g_cdvdman_istruct.m_read2_flag = 0;
5525 g_cdvdman_istruct.m_thread_id = GetThreadId();
5526 g_cdvdman_istruct.m_break_cdvdfsv_readchain = 1;
5527 if ( g_cdvdman_istruct.m_dec_state )
5529 g_cdvdman_istruct.m_dec_shift = 0;
5530 g_cdvdman_istruct.m_check_version = 0;
5531 g_cdvdman_istruct.m_dec_state = 0;
5534 g_cdvdman_istruct.m_recover_status = 0;
5537 iSetEventFlag(g_cdvdman_intr_evfid, 0x29);
5538 iCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
5542 SetEventFlag(g_cdvdman_intr_evfid, 0x29);
5543 CancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
5545 if ( !g_cdvdman_istruct.m_wait_flag || g_cdvdman_istruct.m_last_read_timeout )
5550 VERBOSE_KPRINTF(1,
"cdvd: NonInter END\n");
5551 g_cdvdman_istruct.m_wait_flag = 1;
5553 g_cdvdman_last_cmdfunc = g_cdvdman_cmdfunc;
5554 g_cdvdman_cmdfunc = SCECdFuncBreak;
5555 dev5_mmio_hwport->m_dev5_reg_007 = 1;
5556 if ( g_cdvdman_istruct.m_last_read_timeout )
5560 g_cdvdman_istruct.m_drive_interupt_request = 0;
5561 VERBOSE_KPRINTF(1,
"cdvd: Abort command On\n");
5563 vSetEventFlag(g_ncmd_evfid, 1);
5568static unsigned int ncmd_timeout_alarm_cb(
void *userdata)
5573 KPRINTF(
"Cmd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
5578static int intrh_dma_3(
void *userdata)
5585 s->m_dma3_param.m_dma3_msectors -= s->m_dma3_param.m_dma3_csectors;
5589 "_sceCdDmaIntr wk %d: func_num: %d nsec %d cnt %d cdid:%08x\n",
5592 s->m_dma3_param.m_dma3_msectors,
5593 s->m_cdvdman_dma3sec,
5594 &g_cdvdman_istruct);
5595 dmacbres = s->m_dma3_param.m_dma3_callback ? s->m_dma3_param.m_dma3_callback() : 1;
5596 s->m_cdvdman_dma3sec += s->m_dma3_param.m_dma3_csectors;
5597 s->m_dma3_param.m_dma3_csectors = ((u32)s->m_read_chunk > (u32)s->m_dma3_param.m_dma3_msectors) ?
5598 (u32)s->m_dma3_param.m_dma3_msectors :
5599 (u32)s->m_read_chunk;
5602 if ( s->m_dma3_param.m_dma3_msectors )
5604 dmac_ch_set_chcr(3, 0);
5605 dmac_ch_get_chcr(3);
5606 dmac_ch_set_madr(3, (u32)s->m_dma3_param.m_dma3_maddress);
5609 ((s->m_dma3_param.m_dma3_blkcount * s->m_dma3_param.m_dma3_csectors) << 16) | s->m_dma3_param.m_dma3_blkwords);
5610 dmac_ch_set_chcr(3, 0x41000200);
5611 dmac_ch_get_chcr(3);
5612 iClearEventFlag(g_cdvdman_intr_evfid, ~0x20);
5617 iSetEventFlag(g_cdvdman_intr_evfid, 0x20);
5620 if ( !s->m_dma3_param.m_dma3_msectors && s->m_drive_interupt_request )
5623 s->m_drive_interupt_request = 0;
5630 USE_DEV5_MMIO_HWPORT();
5632 if ( (dmac_ch_get_chcr(3) & 0x1000000) )
5634 dev5_mmio_hwport->m_dev5_reg_007 = 1;
5636 g_cdvdman_istruct.m_drive_interupt_request = 0;
5637 g_cdvdman_istruct.m_dma3_param.m_dma3_blkwords = dma3_param->m_dma3_blkwords;
5638 g_cdvdman_istruct.m_dma3_param.m_dma3_blkcount = dma3_param->m_dma3_blkcount;
5639 g_cdvdman_istruct.m_dma3_param.m_dma3_maddress = dma3_param->m_dma3_maddress;
5640 g_cdvdman_istruct.m_dma3_param.m_dma3_callback = dma3_param->m_dma3_callback;
5641 g_cdvdman_istruct.m_dma3_param.m_dma3_csectors = dma3_param->m_dma3_csectors;
5642 g_cdvdman_istruct.m_dma3_param.m_cdvdreg_howto = dma3_param->m_cdvdreg_howto;
5643 g_cdvdman_istruct.m_dma3_param.m_dma3_msectors = dma3_param->m_dma3_msectors;
5644 g_cdvdman_istruct.m_cdvdman_dma3sec = 0;
5645 dmac_ch_set_chcr(3, 0);
5646 dmac_ch_get_chcr(3);
5647 if ( dma3_param->m_dma3_csectors )
5649 vClearEventFlag(g_cdvdman_intr_evfid, ~0x20);
5652 dev5_mmio_hwport->m_dev5_reg_006 = dma3_param->m_cdvdreg_howto;
5653 dmac_ch_set_madr(3, (u32)dma3_param->m_dma3_maddress);
5656 (dma3_param->m_dma3_blkcount * (dma3_param->m_dma3_csectors ? dma3_param->m_dma3_csectors : 1)) << 16
5657 | dma3_param->m_dma3_blkwords);
5658 dmac_ch_set_chcr(3, 0x41000200);
5659 return dmac_ch_get_chcr(3);
5662#ifdef CDVD_VARIANT_XOSD
5663static int update_cd_mode_ps2_atapi(
void)
5665 int is_intr_context;
5666 int saved_cd_mode_ps2_atapi;
5670 if ( is_intr_context )
5674 saved_cd_mode_ps2_atapi = g_cdvdman_istruct.m_cd_mode_ps2_atapi;
5675 if ( saved_cd_mode_ps2_atapi == 1 )
5677 if ( !(*g_cdvdreg_bf801460 & 2) || (
unsigned int)GetBaseAddress(5) != (
unsigned int)0xBF410000 )
5679 set_cdvd_dev5_base_addr_atapi(1);
5684 if ( (*g_cdvdreg_bf801460 & 2) || (
unsigned int)GetBaseAddress(5) != (
unsigned int)0x1F402000 )
5686 set_cdvd_dev5_base_addr_atapi(2);
5689 if ( is_intr_context )
5693 return saved_cd_mode_ps2_atapi;
5697#ifdef CDVD_VARIANT_XOSD
5698static int set_cdvd_dev5_base_addr_atapi(
int mode)
5700 int is_intr_context;
5704 if ( is_intr_context )
5710 SetBaseAddress(5, 0xBF410000);
5711 VERBOSE_KPRINTF(1,
"DEV5-addr : 0x%08lx\n", GetBaseAddress(5));
5712 SetDelay(5, 0xEF101043);
5713 VERBOSE_KPRINTF(1,
"DEV5-dely : 0x%08lx\n", GetDelay(5));
5714 *g_cdvdreg_bf801464 |= 0xC;
5715 *g_cdvdreg_bf801460 |= 0x40;
5716 *g_cdvdreg_bf801460 |= 2;
5720 SetBaseAddress(5, 0x1F402000);
5721 VERBOSE_KPRINTF(1,
"DEV5-addr : 0x%08lx\n", GetBaseAddress(5));
5722 SetDelay(5, 0x6F060011);
5723 VERBOSE_KPRINTF(1,
"DEV5-dely : 0x%08lx\n", GetDelay(5));
5724 *g_cdvdreg_bf801460 &= ~2;
5725 *g_cdvdreg_bf801460 &= ~0x40;
5726 *g_cdvdreg_bf801464 &= 0xF3;
5728 if ( is_intr_context )
5736#ifdef CDVD_VARIANT_XOSD
5737static int cdvdman_change_drive(
int mode)
5739 ClearEventFlag(g_cdvdman_csys_evfid, ~1);
5742 VERBOSE_KPRINTF(1,
"Init Go SCECdChgWriDrv\n");
5743 ClearEventFlag(g_fio_fsv_evfid, ~1);
5744 ClearEventFlag(g_sfile_evfid, ~1);
5745 ClearEventFlag(g_scmd_evfid, ~1);
5746 ClearEventFlag(g_ncmd_evfid, ~1);
5747 set_cdvd_dev5_base_addr_atapi(1);
5748 if ( g_cd_atapi_evfid != -1 )
5750 SetEventFlag(g_cd_atapi_evfid, 3);
5752 if ( g_adma_evfid != -1 )
5754 SetEventFlag(g_adma_evfid, 1);
5756 if ( g_acmd_evfid != -1 )
5758 SetEventFlag(g_acmd_evfid, 1);
5760 SetEventFlag(g_scmd_evfid, 1);
5761 VERBOSE_KPRINTF(1,
"Init Go SCECdChgWriDrv End.\n");
5762 SetEventFlag(g_fio_fsv_evfid, 1);
5766 VERBOSE_KPRINTF(1,
"Init Go SCECdChgPs2Drv\n");
5767 ClearEventFlag(g_scmd_evfid, ~1);
5768 if ( g_acmd_evfid != -1 )
5770 ClearEventFlag(g_acmd_evfid, ~1);
5772 if ( g_adma_evfid != -1 )
5774 ClearEventFlag(g_adma_evfid, ~1);
5776 if ( g_cd_atapi_evfid != -1 )
5778 ClearEventFlag(g_cd_atapi_evfid, ~3);
5780 set_cdvd_dev5_base_addr_atapi(mode);
5781 SetEventFlag(g_ncmd_evfid, 1);
5782 SetEventFlag(g_scmd_evfid, 1);
5783 SetEventFlag(g_sfile_evfid, 1);
5784 SetEventFlag(g_fio_fsv_evfid, 1);
5785 VERBOSE_KPRINTF(1,
"Init Go SCECdChgPs2Drv End.\n");
5787 SetEventFlag(g_cdvdman_csys_evfid, 1);
5792#ifdef CDVD_VARIANT_XOSD
5798 USE_DEV5_MMIO_HWPORT();
5800 VERBOSE_KPRINTF(1,
"sceCdChgSys(%d) start.\n", use_writer_drive);
5805 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5806 current_mode = update_cd_mode_ps2_atapi();
5808 1,
"sceCdChgSys %d call mode:%d->%d\n", use_writer_drive, current_mode, g_cdvdman_istruct.m_cd_mode_ps2_atapi);
5809 if ( !use_writer_drive )
5811 g_cdvdman_istruct.m_cd_mode_ps2_atapi = current_mode;
5815 && (use_writer_drive != (u32)current_mode || g_cdvdman_istruct.m_cd_mode_ps2_atapi != current_mode) )
5819 if ( use_writer_drive == 1 )
5821 VERBOSE_KPRINTF(1,
"Go SCECdChgWriDrv\n");
5822 VERBOSE_KPRINTF(1,
"fio_fsv_evfid\n");
5823 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5824 VERBOSE_KPRINTF(1,
"sfile_evfid\n");
5825 WaitEventFlag(g_sfile_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5826 VERBOSE_KPRINTF(1,
"sceCdSync\n");
5828 VERBOSE_KPRINTF(1,
"scmd_evfid\n");
5829 WaitEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5830 VERBOSE_KPRINTF(1,
"ncmd_evfid\n");
5831 WaitEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5832 set_cdvd_dev5_base_addr_atapi(2);
5833 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5834 if ( g_cdvdman_vernotxxx1x )
5838 g_cdvdman_istruct.m_chgsys_writer_drive_shell_is_open = 1;
5841 (!(dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen))
5849 VERBOSE_KPRINTF(1,
"GO->Atapi sceCdChgSpdlCtrl Call %d\n", 0);
5850 while ( !sceCdChgSpdlCtrl(0) )
5858 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl ERR 0x%02x\n", last_err);
5859 DelayThread(250000);
5862 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl OK\n", last_err);
5865 set_cdvd_dev5_base_addr_atapi(1);
5866 g_cdvdman_istruct.m_cd_mode_ps2_atapi = 1;
5868 g_cdvdman_vernotxxx1x && disc_type !=
SCECdNODISC && g_cdvdman_istruct.m_chgsys_callback_next_disktype_last
5869 && g_cdvdman_istruct.m_chgsys_callback )
5874 i < 10 && g_cdvdman_istruct.m_chgsys_callback(&g_cdvdman_istruct.m_chgsys_callback_next_disktype, 1);
5879 g_cdvdman_istruct.m_chgsys_callback_next_disktype_last =
SCECdNODISC;
5881 if ( g_cd_atapi_evfid != -1 )
5883 SetEventFlag(g_cd_atapi_evfid, 3);
5885 if ( g_adma_evfid != -1 )
5887 SetEventFlag(g_adma_evfid, 1);
5889 if ( g_acmd_evfid != -1 )
5891 SetEventFlag(g_acmd_evfid, 1);
5893 SetEventFlag(g_scmd_evfid, 1);
5894 SetEventFlag(g_fio_fsv_evfid, 1);
5895 VERBOSE_KPRINTF(1,
"Go SCECdChgWriDrv End.\n");
5899 VERBOSE_KPRINTF(1,
"Go SCECdChgPs2Drv\n");
5900 VERBOSE_KPRINTF(1,
"scmd_evfid\n");
5901 WaitEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5902 if ( g_acmd_evfid != -1 )
5904 VERBOSE_KPRINTF(1,
"g_acmd_evfid Wait\n");
5905 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5907 if ( g_adma_evfid != -1 )
5909 VERBOSE_KPRINTF(1,
"g_adma_evfid Wait\n");
5910 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5912 if ( g_cd_atapi_evfid != -1 )
5914 VERBOSE_KPRINTF(1,
"g_cd_atapi_evfid Wait\n");
5915 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
5917 VERBOSE_KPRINTF(1,
"evflg Ok\n");
5918 set_cdvd_dev5_base_addr_atapi(1);
5919 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5920 if ( g_cdvdman_vernotxxx1x )
5922 set_cdvd_dev5_base_addr_atapi(2);
5923 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5924 set_cdvd_dev5_base_addr_atapi(1);
5925 VERBOSE_KPRINTF(1,
"GO->PS2 STOP ATAPI SPINDL\n");
5926 if ( disc_type == 6 && g_cdvdman_istruct.m_chgsys_callback )
5931 i < 10 && g_cdvdman_istruct.m_chgsys_callback(&g_cdvdman_istruct.m_chgsys_callback_next_disktype, 0);
5938 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5940 VERBOSE_KPRINTF(1,
"Atapi Set -> Dragon Media %d\n", g_cdvdman_istruct.m_chgsys_callback_next_disktype);
5941 if ( g_cdvdman_istruct.m_chgsys_callback_next_disktype == 256 )
5943 g_cdvdman_istruct.m_chgsys_callback_next_disktype_last = g_cdvdman_istruct.m_chgsys_callback_next_disktype;
5944 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5948 set_cdvd_dev5_base_addr_atapi(use_writer_drive);
5949 g_cdvdman_istruct.m_cd_mode_ps2_atapi = use_writer_drive;
5950 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5951 if ( g_cdvdman_vernotxxx1x )
5954 ((dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen))
5964 g_cdvdman_istruct.m_chgsys_callback_next_disktype =
SCECdDETCT;
5968 "GO->DRAGON sceCdChgSpdlCtrl Call %d Ps2MediaType %02x\n",
5969 g_cdvdman_istruct.m_chgsys_callback_next_disktype,
5971 while ( !sceCdChgSpdlCtrl(g_cdvdman_istruct.m_chgsys_callback_next_disktype) )
5979 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl ERR 0x%02x\n", last_err);
5980 DelayThread(250000);
5983 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl OK\n");
5988 VERBOSE_KPRINTF(1,
" -> Ps2 May be No media %08x\n", disc_type);
5990 SetEventFlag(g_ncmd_evfid, 1);
5991 SetEventFlag(g_scmd_evfid, 1);
5992 SetEventFlag(g_sfile_evfid, 1);
5993 SetEventFlag(g_fio_fsv_evfid, 1);
5994 VERBOSE_KPRINTF(1,
"Go SCECdChgPs2Drv End.\n");
5997 SetEventFlag(g_cdvdman_csys_evfid, 1);
5998 return current_mode;
6003cdvdman_send_ncmd(
int ncmd,
const void *ndata,
int ndlen,
int func,
cdvdman_dma3_parameter_t *dma3_param,
int check_cb)
6007 USE_DEV5_MMIO_HWPORT();
6009 if ( check_cb == 1 && PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6015 (
sceCdDiskReady(8) & 0xC0) != 0x40 || !g_cdvdman_istruct.m_wait_flag
6016 || !(g_cdvdman_istruct.m_read2_flag != 1 || ncmd == 8) || !(g_cdvdman_istruct.m_read2_flag != 2 || ncmd == 6) )
6018 if ( check_cb == 1 )
6020 vSetEventFlag(g_ncmd_evfid, 1);
6023 VERBOSE_KPRINTF(1,
"set_cd_commnad Error\tstat %02x\n", (u8)
sceCdDiskReady(8));
6026 g_cdvdman_iocache = 0;
6029 cdvdman_setdma3(dma3_param);
6031 g_cdvdman_cmdfunc = func;
6034 !g_cdvdman_minver_10700 && g_cdvdman_ncmd == 0x06 && ncmd && ncmd != g_cdvdman_ncmd && ncmd != 0x07 && ncmd != 0x0E
6036#ifdef CDVD_VARIANT_XOSD
6041 g_cdvdman_ncmd_timeout.hi = 0;
6042 g_cdvdman_ncmd_timeout.lo = 0x6978000;
6043 vSetAlarm(&g_cdvdman_ncmd_timeout, ncmd_timeout_alarm_cb, &g_cdvdman_ncmd_timeout);
6046 VERBOSE_KPRINTF(1,
"Read Pause 1 chk status 0x%02x\n", dev5_mmio_hwport->m_dev5_reg_00A);
6047 if ( !g_cdvdman_ncmd_timeout.lo )
6049 g_cdvdman_ncmd = ncmd;
6050 if ( check_cb == 1 )
6052 vSetEventFlag(g_ncmd_evfid, 1);
6054 KPRINTF(
"Time Out Pause WAIT set_cd_commnad\n");
6059 vCancelAlarm(ncmd_timeout_alarm_cb, &g_cdvdman_ncmd_timeout);
6061 g_cdvdman_ncmd = ncmd;
6062 if ( g_cdvdman_istruct.m_dec_state )
6064 sceCdDecSet(!!g_cdvdman_istruct.m_dec_shift, 1, g_cdvdman_istruct.m_dec_shift);
6066 g_cdvdman_istruct.m_last_read_timeout = 0;
6067 g_cdvdman_istruct.m_cdvdman_command = ncmd;
6068 g_cdvdman_istruct.m_last_error =
SCECdErNO;
6069 g_cdvdman_istruct.m_wait_flag = 0;
6070 g_cdvdman_istruct.m_thread_id = GetThreadId();
6073 iClearEventFlag(g_cdvdman_intr_evfid, ~1);
6077 ClearEventFlag(g_cdvdman_intr_evfid, ~1);
6079 for ( i = 0; i < ndlen; i += 1 )
6081 dev5_mmio_hwport->m_dev5_reg_005 = ((u8 *)ndata)[i];
6083 dev5_mmio_hwport->m_dev5_reg_004 = ncmd;
6084 if ( check_cb == 1 )
6086 vSetEventFlag(g_ncmd_evfid, 1);
6093 VERBOSE_KPRINTF(1,
"Apply NCmd call cmd= 0x%02x\n", cmdNum);
6094 while ( cdvdman_send_ncmd(cmdNum, inBuff, inBuffSize, 0, 0, 1) < 0 )
6102int sceCdCheckCmd(
void)
6104 return g_cdvdman_istruct.m_wait_flag;
6107static int cdvdman_mediactl(
int code)
6113#ifndef CDVD_VARIANT_XOSD
6114 USE_DEV5_MMIO_HWPORT();
6118 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6122#ifdef CDVD_VARIANT_XOSD
6127 if ( reg_00B_tmp_1 == g_cdvdman_chmedia )
6130 if ( g_cdvdman_chflags[code] )
6132 g_cdvdman_chflags[code] = 0;
6140 for ( i = 0; i < (
sizeof(g_cdvdman_chflags) /
sizeof(g_cdvdman_chflags[0])); i += 1 )
6142 g_cdvdman_chflags[i] = i != (
unsigned int)code;
6146#ifdef CDVD_VARIANT_XOSD
6152 while ( !set_prev_command(0x05, NULL, 0, rdata,
sizeof(rdata), 0) || rdata[0] )
6157#ifdef CDVD_VARIANT_XOSD
6158 g_cdvdman_chmedia = get_cdvd_register(0x0B) & 1;
6162 vSetEventFlag(g_scmd_evfid, 1);
6168 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
6170 VERBOSE_KPRINTF(1,
"sceCdGetError: 0x%02x\n", (u8)g_cdvdman_istruct.m_last_error);
6172 return (u8)g_cdvdman_istruct.m_last_error;
6176int cdvdman_get_last_command(
void)
6178 return (u8)g_cdvdman_istruct.m_cdvdman_command;
6184 return cdvdman_send_ncmd(0x00, NULL, 0, 0, 0, 1) >= 0;
6188int cdvdman_ncmd_sender_01(
void)
6190 return cdvdman_send_ncmd(0x01, NULL, 0, 0, 0, 1) >= 0;
6194#ifndef CDVD_VARIANT_XOSD
6195static int cdvdman_ncmd_sender_06(
void)
6206 for ( i = 0; i < 48; i += 8 )
6209 KPRINTF(
"CMD_READP call\n");
6221 dma3_param.m_cdvdreg_howto = 128;
6222 dma3_param.m_dma3_blkwords = 32;
6223 dma3_param.m_dma3_blkcount = 128;
6224 dma3_param.m_dma3_csectors = 0;
6225 dma3_param.m_dma3_msectors = 0;
6226 dma3_param.m_dma3_callback = 0;
6227 dma3_param.m_dma3_maddress = g_cdvdman_ptoc;
6228 if ( cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 5, &dma3_param, 1) < 0 )
6243#ifdef CDVD_VARIANT_XOSD
6244 switch ( get_disk_type_ex() )
6258 dma3_param.m_cdvdreg_howto = 128;
6259 dma3_param.m_dma3_blkwords = 32;
6260 dma3_param.m_dma3_blkcount = 16;
6269 dma3_param.m_dma3_csectors = 0;
6270 dma3_param.m_dma3_msectors = 0;
6271 dma3_param.m_dma3_callback = 0;
6272 dma3_param.m_dma3_maddress = g_cdvdman_ptoc;
6273 return cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 5, &dma3_param, 1) >= 0;
6275 return cdvdman_send_ncmd(0x02, NULL, 0, 5, 0, 1) >= 0;
6281 return cdvdman_send_ncmd(0x03, NULL, 0, 6, 0, 1) >= 0;
6286 return cdvdman_send_ncmd(0x04, NULL, 0, 7, 0, 1) >= 0;
6290int cdvdman_ncmd_sender_0B(
void)
6295 return cdvdman_send_ncmd(0x0B, ndata,
sizeof(ndata), 0, 0, 1) >= 0;
6299static unsigned int readtoc_timeout_alarm_cb(
void *userdata)
6302 USE_DEV5_MMIO_HWPORT();
6305 KPRINTF(
"Cmd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
6306 dev5_mmio_hwport->m_dev5_reg_007 = 1;
6311static int cdvdman_readtoc(u8 *
toc,
int param,
int func)
6318#ifdef CDVD_VARIANT_XOSD
6319 switch ( get_disk_type_ex() )
6328 dma3_param.m_cdvdreg_howto = 132;
6329 dma3_param.m_dma3_blkwords = 4;
6330 dma3_param.m_dma3_blkcount = 129;
6331 dma3_param.m_dma3_maddress =
toc;
6332 dma3_param.m_dma3_msectors = 0;
6333 dma3_param.m_dma3_csectors = 0;
6334 dma3_param.m_dma3_callback = 0;
6342 dma3_param.m_cdvdreg_howto = 128;
6343 dma3_param.m_dma3_blkwords = 32;
6344 dma3_param.m_dma3_blkcount = 8;
6345 dma3_param.m_dma3_maddress =
toc;
6346 dma3_param.m_dma3_msectors = 0;
6347 dma3_param.m_dma3_csectors = 0;
6348 dma3_param.m_dma3_callback = 0;
6354 if ( cdvdman_send_ncmd(0x09, ndata,
sizeof(ndata), func, &dma3_param, 1) < 0 )
6359 sysclk.lo = 0x15F90000;
6360 vSetAlarm(&sysclk, readtoc_timeout_alarm_cb, &sysclk);
6362 vCancelAlarm(readtoc_timeout_alarm_cb, &sysclk);
6364 if ( g_cdvdman_minver_10700 && !
sceCdPause() )
6372static int cdvdman_gettoc(u8 *
toc)
6375 VERBOSE_KPRINTF(1,
"sceCdReadToc() call 0x%p\n",
toc);
6376 return cdvdman_readtoc(
toc, 0, 3);
6379#ifdef CDVD_VARIANT_OSD
6385 dma3_param.m_cdvdreg_howto = 140;
6386 dma3_param.m_dma3_blkwords = 12;
6387 dma3_param.m_dma3_blkcount = 43;
6388 dma3_param.m_dma3_maddress =
toc;
6389 dma3_param.m_dma3_msectors = 0;
6390 dma3_param.m_dma3_csectors = 0;
6391 dma3_param.m_dma3_callback = 0;
6393 return cdvdman_send_ncmd(0x09, ndata,
sizeof(ndata), 0, &dma3_param, 1) >= 0;
6399 int sector_sizes[4];
6401 sector_sizes[0] = 0x800;
6402 sector_sizes[1] = 0x918;
6403 sector_sizes[2] = 0x924;
6404 if ( g_cdvdman_istruct.m_recover_status && g_cdvdman_istruct.m_recover_status != 3 )
6408 if ( g_cdvdman_cmdfunc == SCECdFuncReadCDDA || g_cdvdman_cmdfunc == 12 )
6410 return dmac_ch_get_madr(3) - (uiptr)g_cdvdman_readbuf;
6412 if ( g_cdvdman_istruct.m_read2_flag )
6414 return g_cdvdman_readptr * sector_sizes[g_cdvdman_istruct.m_cdvdman_pattern];
6416 if ( g_cdvdman_cmdfunc == SCECdFuncRead )
6418 return dmac_ch_get_madr(3) - (uiptr)g_cdvdman_readbuf;
6423static int cdvdman_speedctl(u32 spindlctrl,
int dvdflag, u32 maxlsn)
6427 switch ( spindlctrl )
6430 return dvdflag ? 2 : 4;
6436 if ( g_cdvdman_minver_10700 )
6440#ifdef CDVD_VARIANT_OSD
6442 maxlsn_chk = 0x1C9000;
6444 maxlsn_chk = 0x128000;
6446 if ( g_cdvdman_istruct.m_opo_or_para )
6448 maxlsn -= (maxlsn >= (u32)g_cdvdman_istruct.m_layer_1_lsn) ? g_cdvdman_istruct.m_layer_1_lsn : 0;
6449#ifdef CDVD_VARIANT_OSD
6451 maxlsn_chk = 0x197000;
6453 maxlsn_chk = 0x165000;
6456 if ( maxlsn >= maxlsn_chk )
6458 VERBOSE_KPRINTF(1,
"Kprob Spd D lsn= %d\n", maxlsn);
6468 return dvdflag ? 2 : 131;
6470 return dvdflag ? 3 : 4;
6474 return dvdflag ? 4 : 2;
6478 return dvdflag ? 130 : 131;
6480 return dvdflag ? 130 : 132;
6482 return dvdflag ? 1 : 131;
6484 return dvdflag ? 3 : 5;
6486 return dvdflag ? 131 : 133;
6490static int cdvdman_isdvd(
void)
6493#ifdef CDVD_VARIANT_XOSD
6494 switch ( get_disk_type_ex() )
6504 g_cdvdman_istruct.m_tray_is_open = 1;
6509 g_cdvdman_istruct.m_tray_is_open = 1;
6516static int sceCdRead0_Rty(u32 lsn, u32 nsec,
void *buf,
const sceCdRMode *mode,
int ncmd,
int dintrsec,
void *func)
6521 g_cdvdman_readbuf = buf;
6522 VERBOSE_KPRINTF(1,
"sceCdRead0_Rty Lsn:%d nsec:%d dintrnsec %d func %08x\n", lsn, nsec, dintrsec, func);
6523 *(u32 *)ndata = lsn;
6524 *(u32 *)&ndata[4] = nsec;
6525 ndata[8] = mode->trycount;
6526 ndata[9] = cdvdman_speedctl(mode->spindlctrl, cdvdman_isdvd(), lsn + nsec);
6527 dma3_param.m_dma3_csectors = dintrsec;
6528 dma3_param.m_dma3_callback = (int (*)(void))func;
6529 dma3_param.m_dma3_msectors = nsec;
6530 dma3_param.m_dma3_maddress = buf;
6531 dma3_param.m_dma3_blkcount = (!(u16)dintrsec) ? nsec : 1;
6535 ndata[10] = mode->datapattern;
6536 switch ( mode->datapattern )
6539 dma3_param.m_dma3_blkwords = 6;
6540 dma3_param.m_dma3_blkcount *= 97;
6541 dma3_param.m_cdvdreg_howto = 134;
6544 dma3_param.m_dma3_blkwords = 15;
6545 dma3_param.m_dma3_blkcount *= 39;
6546 dma3_param.m_cdvdreg_howto = 143;
6550 dma3_param.m_dma3_blkwords = 32;
6551 dma3_param.m_dma3_blkcount *= 16;
6552 dma3_param.m_cdvdreg_howto = 128;
6557 dma3_param.m_dma3_blkwords = 12;
6558 dma3_param.m_dma3_blkcount *= 43;
6559 dma3_param.m_cdvdreg_howto = 140;
6565 return cdvdman_send_ncmd(ncmd, ndata,
sizeof(ndata), ncmd == 0x06 ? 1 : 14, &dma3_param, 0) >= 0;
6568int sceCdRead0(u32 lsn, u32 sectors,
void *buffer,
sceCdRMode *mode,
int csec,
void *callback)
6574 if ( PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6580 "DVD/CD sceCdRead0 sec %d num %d spin %d trycnt %d dptn %d adr %08x\n",
6587 g_cdvdman_readbuf = buffer;
6588 dma3_param.m_dma3_csectors = (csec && (sectors < (u32)csec)) ? sectors : (u32)csec;
6589 dma3_param.m_dma3_callback = (int (*)(void))callback;
6590 dma3_param.m_dma3_msectors = sectors;
6591 dma3_param.m_dma3_blkcount = (!csec) ? sectors : 1;
6592 switch ( mode->datapattern )
6595 dma3_param.m_dma3_blkwords = 6;
6596 dma3_param.m_dma3_blkcount *= 97;
6597 dma3_param.m_cdvdreg_howto = 134;
6600 dma3_param.m_dma3_blkwords = 15;
6601 dma3_param.m_dma3_blkcount *= 39;
6602 dma3_param.m_cdvdreg_howto = 143;
6606 dma3_param.m_dma3_blkwords = 32;
6607 dma3_param.m_dma3_blkcount *= 16;
6608 dma3_param.m_cdvdreg_howto = 128;
6612#ifdef CDVD_VARIANT_OSD
6613 g_cdvdman_istruct.m_dvd_flag = cdvdman_isdvd();
6621 if ( g_cdvdman_mmode != SCECdMmodeCd && g_cdvdman_mmode != 0xFF )
6623 vSetEventFlag(g_ncmd_evfid, 1);
6626 g_cdvdman_istruct.m_dvd_flag = 0;
6629 if ( g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF )
6631 vSetEventFlag(g_ncmd_evfid, 1);
6634 g_cdvdman_istruct.m_dvd_flag = 1;
6637 vSetEventFlag(g_ncmd_evfid, 1);
6641 g_cdvdman_istruct.m_read_mode = *mode;
6642 g_cdvdman_istruct.m_read_callback = callback;
6643 g_cdvdman_istruct.m_read_chunk = dma3_param.m_dma3_csectors;
6644 g_cdvdman_istruct.m_read_lsn = lsn;
6645 g_cdvdman_istruct.m_read_sectors = sectors;
6646 *(u32 *)ndata = lsn;
6647 *(u32 *)&ndata[4] = sectors;
6648 ndata[8] = mode->trycount;
6649 ndata[9] = cdvdman_speedctl(mode->spindlctrl, g_cdvdman_istruct.m_dvd_flag, lsn + sectors);
6650 g_cdvdman_istruct.m_read_buf = buffer;
6651 ndata[10] = mode->datapattern;
6652 dma3_param.m_dma3_maddress = buffer;
6653 VERBOSE_KPRINTF(1,
"Read Command call\n");
6654 if ( cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 1, &dma3_param, 0) < 0 )
6656 vSetEventFlag(g_ncmd_evfid, 1);
6659 vSetEventFlag(g_ncmd_evfid, 1);
6672 for ( i = 0; i < common->m_dma3_param.m_dma3_csectors; i += 1 )
6678 if ( common->m_read2_flag == 3 )
6681 cdrloc.
minute = cdvdman_syncdec(
6682 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock)]);
6683 cdrloc.
second = cdvdman_syncdec(
6684 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 1]);
6685 cdrloc.
sector = cdvdman_syncdec(
6686 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 2]);
6692 syncdec_res_1 = (u8)cdvdman_syncdec(
6693 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 3]);
6695 (u8)cdvdman_syncdec(
6696 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 2])
6699 (u8)cdvdman_syncdec(
6700 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 1])
6702 syncdec_res_4 = cdvdman_syncdec(
6703 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock)]);
6704 if ( !common->m_cdvdman_dma3sec && !common->m_interupt_read_state )
6706 common->m_interupt_read_state = (syncdec_res_4 & 0xC) | (((syncdec_res_4 & 0xC) && i) ? 0x80 : 0);
6708 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);
6710 errlsn = common->m_cdvdman_lsn + common->m_cdvdman_csec + common->m_cdvdman_dma3sec + i;
6711 if ( cdreadlsn != (u32)errlsn )
6714 1,
"Read_IOP Sector_ID error lsn= %d readlsn= %d layer= %d\n", errlsn, cdreadlsn, (syncdec_res_4 & 1));
6718 if ( i == common->m_dma3_param.m_dma3_csectors )
6723 switch ( common->m_cdvdman_pattern )
6734 &((
char *)(common->m_cdvdman_rbuffer))[0x924 * common->m_cdvdman_dma3sec],
6735 (
const char *)g_cdvdman_ptoc,
6741 for ( i = 0; i < common->m_dma3_param.m_dma3_csectors; i += 1 )
6744 &((
char *)(common->m_cdvdman_rbuffer))[(common->m_cdvdman_dma3sec + i) * size],
6745 (
const char *)&g_cdvdman_ptoc[12 + (i * sblock)],
6749 g_cdvdman_readptr = common->m_cdvdman_csec + common->m_cdvdman_dma3sec;
6753 common->m_sync_error += 1;
6758static int cdvdman_read(u32 lsn, u32 sectors,
void *buf,
sceCdRMode *mode,
int decflag,
int shift,
int ef1,
int ef2)
6766 dvd = cdvdman_isdvd();
6769 if ( !DvdDual_infochk() )
6773 vSetEventFlag(ef1, ef2);
6777 lsn = sceCdLsnDualChg(lsn);
6779 else if ( mode->datapattern == SCECdSecS2328 || (g_cdvdman_cd36key && !g_cdvdman_istruct.m_dec_state) )
6783 if ( g_cdvdman_cd36key && !g_cdvdman_istruct.m_dec_state && mode->spindlctrl ==
SCECdSpinNom )
6788 read0_res = sceCdRead0(lsn, sectors, buf, mode, 0, 0);
6791 vSetEventFlag(ef1, ef2);
6798 if ( ready != 0x40 || g_cdvdman_istruct.m_read2_flag )
6803 "sceCdRead: Double Booking error r2f= %d waf= %d rdy= %02x\n",
6804 g_cdvdman_istruct.m_read2_flag,
6805 g_cdvdman_istruct.m_wait_flag,
6809 vSetEventFlag(ef1, ef2);
6816 g_cdvdman_istruct.m_dec_shift = shift;
6817 g_cdvdman_istruct.m_dec_state = 1;
6819 g_cdvdman_readbuf = buf;
6820 g_cdvdman_readptr = 0;
6821 g_cdvdman_istruct.m_cdvdman_lsn = lsn;
6822 g_cdvdman_istruct.m_cdvdman_csec = 0;
6823 g_cdvdman_istruct.m_cdvdman_nsec = sectors;
6824 g_cdvdman_istruct.m_cdvdman_rbuffer = (int)buf;
6825 g_cdvdman_istruct.m_cdvdman_pattern = dvd ? SCECdSecS2048 : mode->datapattern;
6826 g_cdvdman_istruct.m_cdvdman_cdrmode.
trycount = mode->trycount;
6827 g_cdvdman_istruct.m_cdvdman_cdrmode.
spindlctrl = mode->spindlctrl;
6828 g_cdvdman_istruct.m_cdvdman_cdrmode.
datapattern = dvd ? SCECdSecS2048 : SCECdSecS2340;
6829 g_cdvdman_istruct.m_read2_flag = dvd ? 1 : 3;
6830 g_cdvdman_istruct.m_sync_error = 0;
6831 g_cdvdman_istruct.m_interupt_read_state = 0;
6832 g_cdvdman_istruct.m_cdvdman_rsec = (sectors >= 0x41) ? (((lsn & 0xF)) ? (0x10 - (lsn & 0xF)) : 0x40) : sectors;
6833 g_cdvdman_read_alarm_cb_timeout.hi = 0;
6834 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
6835 vSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6836 read_res = (dvd ?
sceCdRV : sceCdRead0)(
6838 g_cdvdman_istruct.m_cdvdman_rsec,
6840 dvd ? mode : &g_cdvdman_istruct.m_cdvdman_cdrmode,
6841 g_cdvdman_cache_sector_count,
6846 g_cdvdman_istruct.m_cdvdman_rsec = 0;
6847 g_cdvdman_istruct.m_read2_flag = 0;
6848 if ( g_cdvdman_istruct.m_dec_state )
6850 g_cdvdman_istruct.m_dec_shift = 0;
6851 g_cdvdman_istruct.m_check_version = 0;
6852 g_cdvdman_istruct.m_dec_state = 0;
6855 vCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6859 vSetEventFlag(ef1, ef2);
6867 return cdvdman_read(lsn, sectors, buf, mode, 0, 0, 0, 0);
6876 memset(&efinfo, 0,
sizeof(efinfo));
6878 vReferEventFlagStatus(g_fio_fsv_evfid, &efinfo);
6884 vClearEventFlag(g_fio_fsv_evfid, ~1);
6886 return cdvdman_read(lbn, sectors, buffer, mode, 0, 0, g_fio_fsv_evfid, 1);
6889static int cdvdman_syncdec(
int decflag,
int decxor,
int shift, u32 data)
6891 return decflag ? ((u8)(((u8)data << (shift % 8)) | ((u8)data >> (8 - shift % 8))) ^ (u8)decxor) : (u8)data;
6894static void Read2intrCDVD(
int read2_flag)
6896 iCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6897 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO || g_cdvdman_retries >= 5 )
6899 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO )
6903 g_cdvdman_istruct.m_read2_flag = 0;
6904 g_cdvdman_retries = 0;
6905 g_cdvdman_rtindex = 0;
6906 g_cdvdman_readptr = 0;
6907 if ( g_cdvdman_istruct.m_dec_state )
6909 g_cdvdman_istruct.m_dec_shift = 0;
6910 g_cdvdman_istruct.m_check_version = 0;
6911 g_cdvdman_istruct.m_dec_state = 0;
6913 g_cdvdman_istruct.m_interupt_read_state = 0;
6915 else if ( !g_cdvdman_istruct.m_interupt_read_state || g_cdvdman_istruct.m_cdvdman_csec )
6919 g_cdvdman_istruct.m_interupt_read_state = 0;
6920 if ( g_cdvdman_istruct.m_sync_error )
6924 if ( !g_cdvdman_rtindex )
6926 g_cdvdman_rtindex = 3;
6927 g_cdvdman_retries += 1;
6929 g_cdvdman_istruct.m_sync_error = 0;
6930 lsn_tmp = g_cdvdman_istruct.m_cdvdman_lsn + g_cdvdman_istruct.m_cdvdman_csec;
6931 if ( lsn_tmp >= 0x30 )
6933 lsn_tmp -= 0x10 * (g_cdvdman_rtindex - 1);
6937 lsn_tmp += 0x10 * (g_cdvdman_rtindex - 1);
6939 if ( ((read2_flag == 3) ? sceCdRead0 : sceCdRV)(
6941 g_cdvdman_istruct.m_cdvdman_rsec,
6943 &g_cdvdman_istruct.m_cdvdman_cdrmode,
6944 g_cdvdman_cache_sector_count,
6947 g_cdvdman_read_alarm_cb_timeout.hi = 0;
6948 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
6949 iSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6953 VERBOSE_KPRINTF(1,
"Retry Read Fatal Error\n");
6955 g_cdvdman_istruct.m_read2_flag = 0;
6956 g_cdvdman_retries = 0;
6957 g_cdvdman_rtindex = 0;
6958 g_cdvdman_readptr = 0;
6959 if ( g_cdvdman_istruct.m_dec_state )
6961 g_cdvdman_istruct.m_dec_shift = 0;
6962 g_cdvdman_istruct.m_check_version = 0;
6963 g_cdvdman_istruct.m_dec_state = 0;
6966 g_cdvdman_rtindex -= !!g_cdvdman_rtindex;
6972 g_cdvdman_retries = 0;
6973 switch ( g_cdvdman_istruct.m_cdvdman_pattern )
6986 g_cdvdman_istruct.m_cdvdman_rbuffer += cdsectorsz * g_cdvdman_istruct.m_cdvdman_rsec;
6987 g_cdvdman_istruct.m_cdvdman_csec += g_cdvdman_istruct.m_cdvdman_rsec;
6988 if ( (
unsigned int)g_cdvdman_istruct.m_cdvdman_csec < (
unsigned int)g_cdvdman_istruct.m_cdvdman_nsec )
6990 g_cdvdman_istruct.m_cdvdman_rsec =
6991 ((
unsigned int)(g_cdvdman_istruct.m_cdvdman_csec + 0x40) < (
unsigned int)g_cdvdman_istruct.m_cdvdman_nsec) ?
6993 (g_cdvdman_istruct.m_cdvdman_nsec - g_cdvdman_istruct.m_cdvdman_csec);
6994 if ( ((read2_flag == 3) ? sceCdRead0 : sceCdRV)(
6995 g_cdvdman_istruct.m_cdvdman_lsn + g_cdvdman_istruct.m_cdvdman_csec,
6996 g_cdvdman_istruct.m_cdvdman_rsec,
6998 &g_cdvdman_istruct.m_cdvdman_cdrmode,
6999 g_cdvdman_cache_sector_count,
7002 g_cdvdman_read_alarm_cb_timeout.hi = 0;
7003 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
7004 iSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
7008 g_cdvdman_istruct.m_last_error = SCECdErNORDY;
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;
7021 g_cdvdman_istruct.m_read2_flag = 0;
7022 g_cdvdman_readptr = 0;
7023 if ( g_cdvdman_istruct.m_dec_state )
7025 g_cdvdman_istruct.m_dec_shift = 0;
7026 g_cdvdman_istruct.m_check_version = 0;
7027 g_cdvdman_istruct.m_dec_state = 0;
7034 g_cdvdman_istruct.m_last_error = ((g_cdvdman_istruct.m_interupt_read_state & 0x80)) ?
SCECdErREADCF :
SCECdErIPI;
7035 g_cdvdman_istruct.m_interupt_read_state = 0;
7036 VERBOSE_KPRINTF(1,
"IPIerr emu Hit Dummy Err %02x\n", (u8)g_cdvdman_istruct.m_last_error);
7037 g_cdvdman_istruct.m_read2_flag = 0;
7038 g_cdvdman_retries = 0;
7039 g_cdvdman_rtindex = 0;
7040 g_cdvdman_readptr = 0;
7041 if ( g_cdvdman_istruct.m_dec_state )
7043 g_cdvdman_istruct.m_dec_shift = 0;
7044 g_cdvdman_istruct.m_check_version = 0;
7045 g_cdvdman_istruct.m_dec_state = 0;
7058static int cdvdman_readfull(u32 lsn, u32 sectors,
void *buf,
const sceCdRMode *mode,
int flag)
7063 VERBOSE_KPRINTF(1,
"lsn:%d nsec:%d buf:% cmdmode:%d\n", lsn, sectors, buf, flag);
7065 VERBOSE_KPRINTF(1,
"DA Read lsn= %d nsec= %d datapattern= %d\n", lsn, sectors, mode->datapattern);
7066 g_cdvdman_readbuf = buf;
7067#ifdef CDVD_VARIANT_XOSD
7068 dma3_param.m_dma3_csectors = sectors;
7069 dma3_param.m_dma3_msectors = (u16)sectors;
7071 dma3_param.m_dma3_csectors = 0;
7072 dma3_param.m_dma3_msectors = 0;
7074 dma3_param.m_dma3_callback = 0;
7075 dma3_param.m_dma3_blkcount = sectors;
7076 switch ( mode->datapattern )
7079 dma3_param.m_dma3_blkwords = 8;
7080 dma3_param.m_dma3_blkcount *= 74;
7081 dma3_param.m_cdvdreg_howto = 136;
7084 dma3_param.m_dma3_blkwords = 12;
7085 dma3_param.m_dma3_blkcount *= 51;
7086 dma3_param.m_cdvdreg_howto = 140;
7090 dma3_param.m_dma3_blkwords = 12;
7091 dma3_param.m_dma3_blkcount *= 49;
7092 dma3_param.m_cdvdreg_howto = 140;
7096#ifdef CDVD_VARIANT_XOSD
7097 switch ( get_disk_type_ex() )
7109#ifndef CDVD_VARIANT_OSD
7110 if ( g_cdvdman_mmode != SCECdMmodeCd && g_cdvdman_mmode != 0xFF )
7115 *(u32 *)ndata = lsn;
7116 *(u32 *)&ndata[4] = sectors;
7117 ndata[8] = mode->trycount;
7118 ndata[9] = cdvdman_speedctl(mode->spindlctrl, 0, lsn + sectors);
7119 dma3_param.m_dma3_maddress = buf;
7120 ndata[10] = mode->datapattern;
7121 return cdvdman_send_ncmd((!flag) ? 0x07 : 0x0E, ndata,
sizeof(ndata), (!flag) ? 2 : 12, &dma3_param, 1) >= 0;
7125int sceCdReadCDDA(u32 lbn, u32 sectors,
void *buffer,
sceCdRMode *mode)
7127 return cdvdman_readfull(lbn, sectors, buffer, mode, 0);
7130#ifdef CDVD_VARIANT_OSD
7134 return g_cdvdman_minver_20800 ? cdvdman_readfull(lsn, sectors, buf, mode, 1) :
7135 cdvdman_readfull(lsn, sectors, buf, mode, 0);
7146#ifdef CDVD_VARIANT_XOSD
7152#ifndef CDVD_VARIANT_OSD
7153 || (g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF)
7155 || (PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND) )
7160 1,
"RV read: sec %d num %d spin %d trycnt %d addr %08x\n", lsn, sectors, mode->spindlctrl, mode->trycount, buf);
7161 g_cdvdman_readbuf = buf;
7162 g_cdvdman_istruct.m_dvd_flag = cdvdman_isdvd();
7163 g_cdvdman_istruct.m_read_mode = *mode;
7164 g_cdvdman_istruct.m_read_lsn = lsn;
7165 g_cdvdman_istruct.m_read_sectors = sectors;
7166 *(u32 *)ndata = lsn;
7167 *(u32 *)&ndata[4] = sectors;
7168 ndata[8] = mode->trycount;
7169 ndata[9] = cdvdman_speedctl(mode->spindlctrl, 1, lsn + sectors);
7171 dma3_param.m_dma3_csectors = (arg5 && (sectors < (u32)arg5)) ? sectors : (u32)arg5;
7172 g_cdvdman_istruct.m_read_chunk = dma3_param.m_dma3_csectors;
7173 dma3_param.m_cdvdreg_howto = 140;
7174 dma3_param.m_dma3_blkwords = 12;
7175 g_cdvdman_istruct.m_read_buf = buf;
7176 dma3_param.m_dma3_blkcount = (!arg5) ? sectors : 1;
7177 dma3_param.m_dma3_blkcount *= 43;
7178 dma3_param.m_dma3_msectors = sectors;
7179 dma3_param.m_dma3_callback = (int (*)(void))cb;
7180 g_cdvdman_istruct.m_read_callback = cb;
7181 dma3_param.m_dma3_maddress = buf;
7182 if ( cdvdman_send_ncmd(0x08, ndata,
sizeof(ndata), 14, &dma3_param, 0) < 0 )
7184 vSetEventFlag(g_ncmd_evfid, 1);
7187 vSetEventFlag(g_ncmd_evfid, 1);
7191#ifdef CDVD_VARIANT_OSD
7193int sceCdReadDVDV(u32 lbn, u32 sectors,
void *buffer,
sceCdRMode *mode)
7198#ifdef CDVD_VARIANT_XOSD
7199 switch ( get_disk_type_ex() )
7212 switch ( mode->spindlctrl )
7235 *(u32 *)ndata = lbn;
7236 *(u32 *)&ndata[4] = sectors;
7237 dma3_param.m_cdvdreg_howto = 140;
7238 dma3_param.m_dma3_blkwords = 12;
7239 dma3_param.m_dma3_blkcount = 43 * sectors;
7241 dma3_param.m_dma3_maddress = buffer;
7242 dma3_param.m_dma3_msectors = 0;
7243 dma3_param.m_dma3_csectors = 0;
7244 dma3_param.m_dma3_callback = 0;
7245 ndata[8] = mode->trycount;
7246 return cdvdman_send_ncmd(0x08, ndata,
sizeof(ndata), 9, &dma3_param, 1) >= 0;
7254 *(u32 *)ndata = lbn;
7255 if ( cdvdman_isdvd() )
7257 if ( !DvdDual_infochk() )
7261 *(u32 *)ndata = sceCdLsnDualChg(lbn);
7263 return cdvdman_send_ncmd(0x05, ndata,
sizeof(ndata), 4, 0, 1) >= 0;
7266#ifdef CDVD_VARIANT_XOSD
7267static unsigned int sceCdChgSpdlCtrl(
int mode)
7269 unsigned int retval;
7273 retval = ~cdvdman_send_ncmd(0x0F, ndata,
sizeof(ndata), 0xF, 0, 0);
7274 VERBOSE_KPRINTF(1,
"Called sceCdChgSpdlCtrl mode:%d ret= %d\n", mode & 0xFF, retval >> 31);
7275 return retval >> 31;
7285 retval = set_prev_command(0x12, NULL, 0, rdata,
sizeof(rdata), 1);
7287 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7300 if (
sceCdMV((u8 *)rdata, status) != 1 || (
unsigned int)(rdata[3] | (rdata[2] << 8) | (rdata[1] << 16)) < 0x10500 )
7302 strcpy(buffer,
"M_NAME_UNKNOWN");
7307 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
7313 retval = set_prev_command(0x17, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
7315 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7318 cmd_tmp2 = set_prev_command(0x17, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
7319 *status |= rdata[0];
7320 memcpy(&buffer[8], &rdata[1],
sizeof(rdata) - 1);
7321 vSetEventFlag(g_scmd_evfid, 1);
7322 return retval ? (!!cmd_tmp2) : 0;
7325#ifdef CDVD_VARIANT_OSD
7328int sceCdWI(
const u8 *buffer, u32 *status)
7334 retres = set_prev_command(0x13, (
const char *)buffer, 8, (
char *)status, 1, 1);
7340int sceCdWM(
const char *buffer, u32 *status)
7347 if (
sceCdMV((u8 *)wdata, status) != 1 || (
unsigned int)(wdata[3] | (wdata[2] << 8) | (wdata[1] << 16)) < 0x10500 )
7355 memcpy(&wdata[1], &buffer[0],
sizeof(wdata) - 1);
7356 retres = set_prev_command(0x18, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7361 memcpy(&wdata[1], &buffer[8],
sizeof(wdata) - 1);
7362 retres = set_prev_command(0x18, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && retres;
7363 *status |= rdata[0];
7376 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7378 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7391 memcpy(&wdata[1], buffer, 8);
7392 retval = set_prev_command(0x03, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7405 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7406#ifdef CDVD_VARIANT_XOSD
7409 *status = rdata[0] & 0x80;
7411 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]);
7412#ifndef CDVD_VARIANT_XOSD
7415 memcpy(buffer, rdata,
sizeof(rdata));
7419#ifdef CDVD_VARIANT_XOSD
7420static int cdvdman_get_renewal_date(u8 *buffer, u32 *status)
7428 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7431 *status = (u8)rdata[0];
7433 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7438#ifndef CDVD_VARIANT_XOSD
7439static int cdvdman_scmd_sender_03_30(u8 *buf, u32 *status)
7445 if ( g_cdvdman_minver_50000 )
7451 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7452 *status = (u8)rdata[0];
7458#ifdef CDVD_VARIANT_OSD
7468 USE_DEV5_MMIO_HWPORT();
7470 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
7474 dev5_mmio_hwport->m_dev5_reg_009 = 0;
7475 retval = cdvdman_send_scmd2(0x02, NULL, 0, rdata,
sizeof(rdata), 0);
7476 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7477 for ( i = 0; i < 10; i += 1 )
7483 dev5_reg_00E = dev5_mmio_hwport->m_dev5_reg_00E;
7484 dev5_reg_00D = dev5_mmio_hwport->m_dev5_reg_00D;
7485 dev5_reg_00C = dev5_mmio_hwport->m_dev5_reg_00C;
7486 tmp00E = dev5_mmio_hwport->m_dev5_reg_00E;
7487 tmp00D = dev5_mmio_hwport->m_dev5_reg_00D;
7488 tmp00C = dev5_mmio_hwport->m_dev5_reg_00C;
7489 if ( dev5_reg_00E == tmp00E && dev5_reg_00D == tmp00D && dev5_reg_00C == tmp00C )
7496 *((u8 *)buffer + 9) = dev5_reg_00E;
7497 *((u8 *)buffer + 8) = dev5_reg_00D;
7498 *((u8 *)buffer + 7) = dev5_reg_00C;
7501 vSetEventFlag(g_scmd_evfid, 1);
7512 retval = set_prev_command(0x15, NULL, 0, rdata,
sizeof(rdata), 1);
7513 *status = (u8)rdata[0];
7520 g_cdvdman_mmode = media;
7524#ifdef CDVD_VARIANT_OSD
7530 return set_prev_command(0x19, NULL, 0, (
char *)status, 1, 1);
7537 VERBOSE_KPRINTF(1,
"BC %d %d %d %d\n", *romname, romname[1], romname[2], romname[3]);
7538 return set_prev_command(0x1A, (
const char *)romname, 4, rdata,
sizeof(rdata), 1);
7547 return g_cdvdman_minver_20400 ? set_prev_command(0x1B, NULL, 0, (
char *)status, 1, 1) : 1;
7550#ifdef CDVD_VARIANT_OSD
7558 return set_prev_command(0x1C, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7562static unsigned int power_off_alarm_cb(
void *userdata)
7567 s->m_power_flag = 0;
7577 VERBOSE_KPRINTF(1,
"sceCdPowerOff Call\n");
7578#ifndef CDVD_VARIANT_XOSD
7579 if ( !g_cdvdman_minver_x_model_15 )
7586 vDelayThread(250000);
7590 retval = set_prev_command(0x0F, NULL, 0, (
char *)status, 1, 1);
7593 g_cdvdman_istruct.m_power_flag = 0;
7596 KPRINTF(
"PowerOff Start...\n");
7597 g_cdvdman_istruct.m_power_flag = 1;
7598 g_cdvdman_power_off_timeout.hi = 0;
7599 g_cdvdman_power_off_timeout.lo = 0xAFC8000;
7600 vSetAlarm(&g_cdvdman_power_off_timeout, power_off_alarm_cb, &g_cdvdman_istruct);
7610 VERBOSE_KPRINTF(1,
"Audio Digital Out: Set param %d\n", (u8)mode);
7612 return set_prev_command(0x14, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7615#ifdef CDVD_VARIANT_OSD
7623 VERBOSE_KPRINTF(1,
"Auto Adjust Ctrl: Set param %d\n", (u8)mode);
7625 return set_prev_command(0x16, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7631 unsigned int clkmonth;
7632 unsigned int clkday;
7635 if ( !g_cdvdman_minver_50000 )
7639 clkmonth = 10 * (clock->
month >> 4) + (clock->
month & 0xF);
7640 clkday = 10 * (clock->
day >> 4) + (clock->
day & 0xF);
7642 (10 * (clock->
second >> 4) + (clock->
second & 0xF) >= 0x3C
7643 || 10 * (clock->
minute >> 4) + (clock->
minute & 0xF) >= 0x3C
7644 || 10 * (clock->
hour >> 4) + (clock->
hour & 0xF) >= 0x18 || 10 * (clock->
year >> 4) + (clock->
year & 0xF) >= 0x64
7645 || clkmonth >= 0xD || !clkmonth || clkday >= 0x20 || !clkday)
7646 && flags != 255 && !(clock->
second & 0x80) && !(clock->
minute & 0x80) )
7650 wdata[0] = (flags == 255) ? 255 : clock->second;
7651 wdata[1] = clock->
minute | ((flags == 1) ? 0x80 : 0);
7652 wdata[2] = clock->
hour;
7653 wdata[3] = clock->
day;
7654 wdata[4] = clock->
month;
7655 wdata[5] = clock->
year;
7656 wdata[6] = userdata & 0xFF;
7657 wdata[7] = (userdata >> 8) & 0xFF;
7658 return set_prev_command(0x21, wdata,
sizeof(wdata), (
char *)&clock->
stat,
sizeof(clock->
stat), 1);
7677 if ( !g_cdvdman_minver_50000 )
7679 *wakeupreason = 256;
7682 retval = set_prev_command(0x22, NULL, 0, rdata,
sizeof(rdata), 1);
7687 clock->
stat = rdata[0];
7688 clock->
second = (u8)rdata[2] == 255 ? -1 : (rdata[2] & 0x7F);
7689 clock->
minute = rdata[3] & 0x7F;
7691 clock->
hour = rdata[4];
7692 clock->
day = rdata[5];
7693 clock->
month = rdata[6];
7694 clock->
year = rdata[7];
7695 *userdata = (u8)rdata[8] | ((u8)rdata[9] << 8);
7696 *wakeupreason = (u8)rdata[1];
7697 *flags = (((u8)rdata[2] >> 7) << 1) | (!!(rdata[3] & 0x80));
7701int sceCdSendSCmd1D(
int *arg1,
unsigned int *arg2,
unsigned int *arg3, u32 *status)
7710 if ( !g_cdvdman_minver_50000 )
7716 retval = set_prev_command(0x1D, NULL, 0, rdata,
sizeof(rdata), 1);
7721 *status = (u8)rdata[0];
7722 *arg1 = (u8)rdata[1];
7723 rdata2tmp = rdata[4] | (rdata[3] << 8) | (rdata[2] << 16);
7727 *arg2 = (rdata2tmp >> 17) & 0x7F;
7728 *arg3 = (rdata2tmp >> 12) & 0x1F;
7731 *arg2 = (rdata2tmp >> 17) & 0x7F;
7732 *arg3 = (rdata2tmp >> 9) & 0xFF;
7735 *arg2 = (rdata2tmp >> 17) & 0x7F;
7736 *arg3 = (rdata2tmp >> 4) & 0x1FFF;
7747 if ( !g_cdvdman_minver_50000 )
7753 wdata[0] = param & 0xFF;
7754 wdata[1] = (param >> 8) & 0xFF;
7755 return set_prev_command(0x1F, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7764 if ( !g_cdvdman_minver_50000 )
7770 retval = set_prev_command(0x26, NULL, 0, rdata,
sizeof(rdata), 1);
7771 *param = ((u8)rdata[2] << 8) | (u8)rdata[1];
7772 *status = (u8)rdata[0];
7783 if ( !g_cdvdman_minver_50200 )
7789 retval = set_prev_command(0x27, NULL, 0, (
char *)rdata,
sizeof(rdata), 1);
7790 memcpy(out, &rdata[1],
sizeof(rdata) - 2);
7802 if ( !g_cdvdman_minver_50400 )
7809 retval = set_prev_command(0x28, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7810 *status = (u8)rdata[0];
7814int cdvdman_152(u32 *param, u32 *status)
7820 if ( !g_cdvdman_minver_50400 )
7828 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7829 *param = 3125 * (((u8)rdata[2] | ((u8)rdata[1] << 8)) << 16 >> 18) / 100;
7830 *status = (u8)rdata[0];
7835#ifdef CDVD_VARIANT_XOSD
7843 if ( !g_cdvdman_minver_50400 )
7850 retval = set_prev_command(0x29, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7851 *status = (u8)rdata[0];
7852 if ( retval && !rdata[0] )
7854 g_cdvdman_istruct.m_medium_removal_state = 0;
7860#ifdef CDVD_VARIANT_OSD
7864 USE_IOP_MMIO_HWPORT();
7866 if ( mfc0(PRID) >= 0x23 )
7870 *(u32 *)&iop_mmio_hwport->sio2.unused[0] |= 1;
7874 *(u32 *)&iop_mmio_hwport->sio2.unused[0] &= ~1;
7879 if ( !g_cdvdman_minver_50000 )
7886 return set_prev_command(0x24, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7895 memset(param, 0, 15);
7896 if ( !g_cdvdman_minver_60000 )
7902 retval = set_prev_command(0x36, NULL, 0, rdata,
sizeof(rdata), 1);
7903 memcpy(param, &rdata[1],
sizeof(rdata) - 1);
7916 memset(wdata, 0,
sizeof(wdata));
7917 if ( !g_cdvdman_minver_60600 )
7924 memcpy(&wdata[1], arg2, 12);
7926 memcpy(&wdata[13], arg3, 2);
7927 return set_prev_command(0x3E, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7935 if ( !g_cdvdman_minver_50000 )
7942 return set_prev_command(0x25, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7950 retval = set_prev_command(0x08, NULL, 0, (
char *)clock, 8, 1);
7952 clock->
month &= 0x7F;
7953 if ( retval && !clock->
stat )
7955 memcpy(&g_cdvdman_clock, clock,
sizeof(g_cdvdman_clock));
7956 g_cdvdman_clk_flg = 1;
7958 else if ( g_cdvdman_clk_flg )
7960 memcpy(clock, &g_cdvdman_clock,
sizeof(g_cdvdman_clock));
7976 return set_prev_command(0x08, NULL, 0, (
char *)clock, 8, 1);
7979#ifdef CDVD_VARIANT_OSD
7982 return set_prev_command(
7983 0x09, (
const char *)&clock->
second,
sizeof(clock) - 1, (
char *)&clock->
stat,
sizeof(clock->
second), 1);
7992 wdata[0] = (address >> 8) & 0xFF;
7993 wdata[1] = address & 0xFF;
7994 retval = set_prev_command(0x0A, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7996 *data = (rdata[1] << 8) | rdata[2];
7997 VERBOSE_KPRINTF(1,
"RN_call addr= 0x%04x data= 0x%04x stat= 0x%02x\n", address, *data, *result);
8006 wdata[0] = (address >> 8) & 0xFF;
8007 wdata[1] = address & 0xFF;
8008 wdata[2] = (data >> 8) & 0xFF;
8009 wdata[3] = data & 0xFF;
8010 retval = set_prev_command(0x0B, wdata,
sizeof(wdata), (
char *)result, 1, 1);
8011 VERBOSE_KPRINTF(1,
"WN_call addr= 0x%04x data= 0x%04x stat= 0x%02x\n", address, data, *result);
8020#ifdef CDVD_VARIANT_XOSD
8026 *traychk = cdvdman_mediactl(1);
8027 VERBOSE_KPRINTF(1,
"Tray Req test = %d\n", *traychk);
8035 g_cdvdman_iocache = 0;
8036#ifdef CDVD_VARIANT_XOSD
8039 rdata[0] = !!set_prev_command(0x06, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0];
8040#ifdef CDVD_VARIANT_XOSD
8045#ifdef CDVD_VARIANT_XOSD
8048 g_cdvdman_istruct.m_medium_removal_state = 0;
8049 g_cdvdman_istruct.m_atapi_disk_ejected = 0;
8052 vDelayThread(11000);
8057static int cdvdman_scmd_sender_3B(
int arg1)
8062 if ( g_cdvdman_minver_x_model_15 && arg1 == 1 )
8066 g_cdvdman_iocache = 0;
8068 if ( set_prev_command(0x3B, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0] )
8070 vDelayThread(11000);
8076#ifdef CDVD_VARIANT_DNAS
8080 char sectbuf[0x800];
8082 USE_DEV5_MMIO_HWPORT();
8086#ifdef CDVD_VARIANT_XOSD
8087 switch ( get_disk_type_ex() )
8102 sceCdRead0(0x4B, 1, sectbuf, &rmode, 0, 0);
8104 if ( !cdvdman_ncmd_sender_0C(0, 0, 0x4B) )
8109 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8113 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8114 if ( !(dev5_mmio_hwport->m_dev5_reg_038 & 4) )
8116 vSetEventFlag(g_scmd_evfid, 1);
8119 *(u8 *)
id = dev5_mmio_hwport->m_dev5_reg_030 ^ dev5_mmio_hwport->m_dev5_reg_039;
8120 *((u8 *)
id + 1) = dev5_mmio_hwport->m_dev5_reg_031 ^ dev5_mmio_hwport->m_dev5_reg_039;
8121 *((u8 *)
id + 2) = dev5_mmio_hwport->m_dev5_reg_032 ^ dev5_mmio_hwport->m_dev5_reg_039;
8122 *((u8 *)
id + 3) = dev5_mmio_hwport->m_dev5_reg_033 ^ dev5_mmio_hwport->m_dev5_reg_039;
8123 *((u8 *)
id + 4) = dev5_mmio_hwport->m_dev5_reg_034 ^ dev5_mmio_hwport->m_dev5_reg_039;
8124 vSetEventFlag(g_scmd_evfid, 1);
8136 USE_DEV5_MMIO_HWPORT();
8138 if ( !g_cdvdman_istruct.m_cd_inited )
8144#ifdef CDVD_VARIANT_XOSD
8145 switch ( get_disk_type_ex() )
8162 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8174 dev5_mmio_hwport->m_dev5_reg_007 = 1;
8186 for ( i = 0; i < 20; i += 1 )
8188 sceCdRead0(0x4B + (0x10 * i), 0x10, g_cdvdman_ptoc, &rmode, 0, 0);
8197 sceCdRead0(0x4B, 1, g_cdvdman_ptoc, &rmode, 0, 0);
8201 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8203 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8207 vSetEventFlag(g_scmd_evfid, 1);
8211 memset(ndata, 0,
sizeof(ndata));
8213 if ( cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) < 0 )
8217 vSetEventFlag(g_scmd_evfid, 1);
8222 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8224 *status = (u8)g_cdvdman_istruct.m_last_error;
8225 vSetEventFlag(g_scmd_evfid, 1);
8228 dev5_reg_038 = dev5_mmio_hwport->m_dev5_reg_038;
8229 vSetEventFlag(g_scmd_evfid, 1);
8230 return (dev5_reg_038 & 5) == 5;
8234#ifdef CDVD_VARIANT_XOSD
8251 USE_DEV5_MMIO_HWPORT();
8253 memset(xorarea, 0,
sizeof(xorarea));
8254 memset(buffer, 0, 16);
8256 if ( shiftval >= 8 || xorval < 0 || xorval >= 256 )
8261 if ( !g_cdvdman_istruct.m_cd_inited )
8266 switch ( get_disk_type_ex() )
8280 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8288 dev5_mmio_hwport->m_dev5_reg_007 = 1;
8293 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8304 for ( i = 0; i < 0x14; i += 1 )
8306 sceCdRead0(75 + 16 * i, 0x10, g_cdvdman_ptoc, &rmode, 0, 0);
8315 sceCdRead0(0x4B, 1, g_cdvdman_ptoc, &rmode, 0, 0);
8319 WaitEventFlag(g_scmd_evfid, 1, 0, &efbits);
8321 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8325 vSetEventFlag(g_scmd_evfid, 1);
8329 memset(ndata, 0,
sizeof(ndata));
8331 if ( cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) < 0 )
8335 vSetEventFlag(g_scmd_evfid, 1);
8340 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8342 *status = (u8)g_cdvdman_istruct.m_last_error;
8343 vSetEventFlag(g_scmd_evfid, 1);
8353 if ( (dev5_mmio_hwport->m_dev5_reg_038 & 5) == 5 )
8360 dev5_reg_020 = dev5_mmio_hwport->m_dev5_reg_020;
8361 dev5_reg_039 = dev5_mmio_hwport->m_dev5_reg_039;
8362 xor_val_1_stk = dev5_reg_020 ^ dev5_reg_039;
8363 xor_val_2_stk = dev5_reg_039 ^ dev5_mmio_hwport->m_dev5_reg_021;
8364 dev5_reg_022 = dev5_mmio_hwport->m_dev5_reg_022;
8365 reg_039_tmp1 = dev5_mmio_hwport->m_dev5_reg_039;
8366 xor_val_3_stk = dev5_reg_022 ^ reg_039_tmp1;
8367 xor_val_4_stk = reg_039_tmp1 ^ dev5_mmio_hwport->m_dev5_reg_023;
8368 xor_val_1_xstk = dev5_mmio_hwport->m_dev5_reg_024 ^ dev5_mmio_hwport->m_dev5_reg_039;
8369 xor_val_2_xstk = dev5_mmio_hwport->m_dev5_reg_039 ^ dev5_mmio_hwport->m_dev5_reg_034;
8372 vSetEventFlag(g_scmd_evfid, 1);
8373 xorarea[0] = (xor_val_4_stk >> 4) | ((xor_val_1_xstk << 4) & 0x70);
8374 xorarea[1] = (xor_val_3_stk >> 5) | ((xor_val_4_stk << 3) & 0x78);
8375 xorarea[2] = (xor_val_2_stk >> 6) | ((xor_val_3_stk << 2) & 0x7C);
8376 xorarea[3] = (xor_val_1_stk >> 7) | ((xor_val_2_stk << 1) & 0x7E);
8377 sprintf(&xorarea[4],
"%d", ((xor_val_1_stk & 0x7F) << 10) | (xor_val_1_xstk >> 3) | ((xor_val_2_xstk >> 3) << 5));
8378 for ( i = 0; i < 9; i += 1 )
8380 xorarea[i] = xorarea[i] ^ xorval;
8384 for ( i = 0; i < 9; i += 1 )
8386 buffer[i] = (xorarea[i] << shiftval) | ((
int)(u8)xorarea[i ? i - 1 : 8] >> (8 - shiftval));
8392 memcpy(buffer, xorarea,
sizeof(xorarea));
8398#ifdef CDVD_VARIANT_OSD
8399int sceCdReadKey(u8 arg1, u8 arg2,
unsigned int command, u8 *key)
8404 char sectorbuf[0x800];
8406 USE_DEV5_MMIO_HWPORT();
8408 if ( cdvdman_isdvd() && !arg1 )
8410 if ( !DvdDual_infochk() )
8414 command = sceCdLsnDualChg(command);
8419 sceCdRead0(command, 1, sectorbuf, &rmode, 0, 0);
8421 for ( i = 0; i < 300; i += 1 )
8423 if ( !cdvdman_ncmd_sender_0C(arg1, arg2, command + i) )
8428 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO )
8433 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8436 dev5_reg_038 = dev5_mmio_hwport->m_dev5_reg_038;
8437 if ( (dev5_reg_038 & 1) )
8439 key[0] = dev5_mmio_hwport->m_dev5_reg_020 ^ dev5_mmio_hwport->m_dev5_reg_039;
8440 key[1] = dev5_mmio_hwport->m_dev5_reg_021 ^ dev5_mmio_hwport->m_dev5_reg_039;
8441 key[2] = dev5_mmio_hwport->m_dev5_reg_022 ^ dev5_mmio_hwport->m_dev5_reg_039;
8442 key[3] = dev5_mmio_hwport->m_dev5_reg_023 ^ dev5_mmio_hwport->m_dev5_reg_039;
8443 key[4] = dev5_mmio_hwport->m_dev5_reg_024 ^ dev5_mmio_hwport->m_dev5_reg_039;
8445 if ( (dev5_reg_038 & 2) )
8447 key[5] = dev5_mmio_hwport->m_dev5_reg_028 ^ dev5_mmio_hwport->m_dev5_reg_039;
8448 key[6] = dev5_mmio_hwport->m_dev5_reg_029 ^ dev5_mmio_hwport->m_dev5_reg_039;
8449 key[7] = dev5_mmio_hwport->m_dev5_reg_02A ^ dev5_mmio_hwport->m_dev5_reg_039;
8450 key[8] = dev5_mmio_hwport->m_dev5_reg_02B ^ dev5_mmio_hwport->m_dev5_reg_039;
8451 key[9] = dev5_mmio_hwport->m_dev5_reg_02C ^ dev5_mmio_hwport->m_dev5_reg_039;
8453 if ( (dev5_reg_038 & 4) )
8455 key[10] = dev5_mmio_hwport->m_dev5_reg_030 ^ dev5_mmio_hwport->m_dev5_reg_039;
8456 key[11] = dev5_mmio_hwport->m_dev5_reg_031 ^ dev5_mmio_hwport->m_dev5_reg_039;
8457 key[12] = dev5_mmio_hwport->m_dev5_reg_032 ^ dev5_mmio_hwport->m_dev5_reg_039;
8458 key[13] = dev5_mmio_hwport->m_dev5_reg_033 ^ dev5_mmio_hwport->m_dev5_reg_039;
8459 key[14] = dev5_mmio_hwport->m_dev5_reg_034 ^ dev5_mmio_hwport->m_dev5_reg_039;
8461 key[15] = dev5_reg_038 & 7;
8462 vSetEventFlag(g_scmd_evfid, 1);
8467#ifdef CDVD_VARIANT_DNAS
8468static int cdvdman_ncmd_sender_0C(
int arg1, u32 arg2, u32 arg3)
8474 ndata[2] = !!(arg2 >> 8);
8475 *(u32 *)&ndata[3] = !arg1 ? arg3 : 0;
8476 return cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) >= 0;
8482#ifdef CDVD_VARIANT_DNAS
8483 USE_DEV5_MMIO_HWPORT();
8485 g_cdvdman_cd36key = enable_shift | shiftval;
8486 dev5_mmio_hwport->m_dev5_reg_03A = ((shiftval & 7) << 4) | ((!!enable_xor) << 1) | (!!enable_shift);
8495#ifdef CDVD_VARIANT_OSD
8499#ifdef CDVD_VARIANT_XOSD
8504#ifdef CDVD_VARIANT_XOSD
8505 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8512 wdata[0] = (u8)mode;
8513 wdata[1] = (u8)block;
8514 wdata[2] = (u8)NumBlocks;
8515 retval = set_prev_command(0x40, wdata,
sizeof(wdata), (
char *)status, 1, 0);
8516#ifdef CDVD_VARIANT_XOSD
8520 g_cdvdman_config_numblocks = NumBlocks;
8522#ifdef CDVD_VARIANT_XOSD
8523 vSetEventFlag(g_scmd_evfid, 1);
8535 retval = set_prev_command(0x43, NULL, 0, (
char *)status, 1, 1);
8536 g_cdvdman_config_numblocks = 0;
8540static int read_config_process(
char *outval, u32 *status)
8546 retval = set_prev_command(0x41, NULL, 0, rdata,
sizeof(rdata), 0);
8547 *status = (u8)(rdata[14] + rdata[13] + rdata[12] + rdata[11] + rdata[10] + rdata[9] + rdata[8] + rdata[7] + rdata[6]
8548 + rdata[5] + rdata[4] + rdata[3] + rdata[2] + rdata[0] + rdata[1])
8550 memcpy(outval, rdata,
sizeof(rdata) - 1);
8560 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8564 for ( retval = 0; retval < g_cdvdman_config_numblocks; retval += 1 )
8566 if ( !read_config_process((
char *)buffer + 15 * retval, status) )
8568 VERBOSE_KPRINTF(1,
"RC_fail Command busy\n");
8573 VERBOSE_KPRINTF(1,
"RC_fail status: 0x%02x\n", *status);
8577 vSetEventFlag(g_scmd_evfid, 1);
8581static int write_config_process(
const char *inval, u32 *status)
8587 memcpy(wdata, inval, 15);
8588 wdata[15] = wdata[14] + wdata[13] + wdata[12] + wdata[11] + wdata[10] + wdata[9] + wdata[8] + wdata[7] + wdata[6]
8589 + wdata[5] + wdata[4] + wdata[3] + wdata[2] + wdata[0] + wdata[1];
8590 return set_prev_command(0x42, wdata,
sizeof(wdata), (
char *)status, 1, 0);
8599 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8603 for ( retval = 0; retval < g_cdvdman_config_numblocks; retval += 1 )
8605 if ( !write_config_process((
char *)buffer + 15 * retval, status) )
8607 VERBOSE_KPRINTF(1,
"WC_fail Command busy\n");
8612 VERBOSE_KPRINTF(1,
"WC_fail status: 0x%02x\n", *status);
8616 vSetEventFlag(g_scmd_evfid, 1);
8626 return set_prev_command(0x0C, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0];
8630#ifdef CDVD_VARIANT_XOSD
8632int sceCdXLEDCtl(u8 arg1, u8 arg2, u32 *param, u32 *status)
8639 if ( !g_cdvdman_minver_50600 )
8647 retval = set_prev_command(0x2D, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
8652 *status = (u8)rdata[0];
8653 *param = (u8)rdata[1];
8658#ifdef CDVD_VARIANT_XOSD
8662 if ( !g_cdvdman_minver_50600 )
8668 return set_prev_command(0x2E, NULL, 0, (
char *)status, 1, 1);
8672#ifdef CDVD_VARIANT_XOSD
8673int sceCdResetWakeupReason(u32 *inbuf, u32 *status)
8675 if ( !g_cdvdman_minver_50600 )
8681 return cdvdman_write_scmd_swap_dev5(0x2F, (
char *)inbuf, 16, (
char *)status, 1, 1);
8685#ifdef CDVD_VARIANT_XOSD
8686int cdvdman_169(u32 *arg1, u32 *status)
8694 if ( !g_cdvdman_minver_50600 )
8700 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8704 memset(arg1, 0, 16);
8707 vSetEventFlag(g_scmd_evfid, 1);
8711 for ( i = 0; i < 2 && !rdata[0]; i += 1 )
8718 retval = cdvdman_write_scmd_swap_dev5(0x30, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
8719 memcpy(&arg1[i * 2], &rdata[1],
sizeof(rdata) - 1);
8727#ifdef CDVD_VARIANT_XOSD
8736 if ( !g_cdvdman_minver_50600 )
8744 retval = set_prev_command(0x2C, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
8749 *status = (u8)rdata[0];
8750 *param = (u8)rdata[1];
8755#ifdef CDVD_VARIANT_XOSD
8760 int saved_medium_removal_state;
8764 if ( !g_cdvdman_minver_50600 )
8771 saved_medium_removal_state = g_cdvdman_istruct.m_medium_removal_state;
8772 g_cdvdman_istruct.m_medium_removal_state = (u8)wanted_val;
8773 wdata[0] = wanted_val;
8774 retval = set_prev_command(0x31, wdata,
sizeof(wdata), (
char *)status, 1, 1);
8775 if ( !retval || *status )
8777 g_cdvdman_istruct.m_medium_removal_state = saved_medium_removal_state;
8784#ifdef CDVD_VARIANT_XOSD
8792 if ( !g_cdvdman_minver_50600 )
8798 retval = set_prev_command(0x32, NULL, 0, rdata,
sizeof(rdata), 1);
8803 *status = (u8)rdata[0];
8804 *param = (u8)rdata[1];
8807 g_cdvdman_istruct.m_medium_removal_state = *param;
8813#ifdef CDVD_VARIANT_XOSD
8819 if ( !g_cdvdman_minver_50600 )
8826 return set_prev_command(0x33, wdata,
sizeof(wdata), (
char *)status, 1, 1);
8830#ifdef CDVD_VARIANT_XOSD
8831static int sc_ffffffd8(u32 *status)
8835 if ( !g_cdvdman_minver_50600 )
8841 retval = set_prev_command(0x34, NULL, 0, (
char *)status, 1, 1);
8846 g_cdvdman_istruct.m_atapi_disk_ejected = 0;
8851#ifdef CDVD_VARIANT_XOSD
8853int cdvdman_scmd_sender_35(u32 *param, u32 *status)
8859 if ( !g_cdvdman_minver_50600 )
8865 retval = set_prev_command(0x35, NULL, 0, rdata,
sizeof(rdata), 1);
8870 *status = (u8)rdata[0];
8871 *param = (u8)rdata[1];
int sceCdRV(u32 lsn, u32 sectors, void *buf, sceCdRMode *mode, int arg5, void *cb)
int sceCdApplySCmd2(u8 cmdNum, const void *inBuff, unsigned long int inBuffSize, void *outBuff)
int sceCdApplySCmd3(u8 cmdNum, const void *inBuff, unsigned long int inBuffSize, void *outBuff)
int sceCdSpinCtrlIOP(u32 speed)
int sceCdReadDiskID(unsigned int *id)
int sceCdDeobfuscateUsingUniqueKey(u8 *buffer, unsigned int shiftval, int xorval, u32 *status)
void * sceCdSetAtapiEjectCallback(int(*cb)(int reason, void *userdata), void *userdata)
int CpuResumeIntr(int state)
int ReleaseIntrHandler(int irq)
int QueryIntrContext(void)
int DisableIntr(int irq, int *res)
int CpuSuspendIntr(int *state)
int RegisterIntrHandler(int irq, int mode, int(*handler)(void *arg), void *arg)
int sceCdReadModelID(unsigned int *id)
int sceCdStSeekF(unsigned int lsn)
int sceCdSearchFile(sceCdlFILE *file, const char *name)
int sceCdXLEDCtl(u8 arg1, u8 arg2, u32 *result1, u32 *result2)
int sceCdRcBypassCtl(int mode, u32 *status)
int sceCdCancelPOffRdy(u32 *result)
int sceCdReadRegionParams(u32 *arg1, u32 *result)
int sceCdPowerOff(u32 *result)
int sceRemote2_7(u16 param, u32 *status)
int sceCdSetFanProfile(u8 param, u32 *result)
int sceCdDoesUniqueKeyExist(u32 *status)
int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
int sceCdGetMediumRemoval(u32 *result1, u32 *result2)
int sceCdReadSUBQ(void *buffer, u32 *status)
int sceCdSetHDMode(u32 mode)
int sceCdReadKey(unsigned char arg1, unsigned char arg2, unsigned int command, unsigned char *key)
int sceCdReadNVM(u32 address, u16 *data, u8 *result)
sceCdCBFunc sceCdCallback(sceCdCBFunc function)
int sceCdReadPS1BootParam(u8 *out, u32 *result)
int sceCdXDVRPReset(u8 arg1, u32 *result)
int sceCdSetMediumRemoval(u8 arg1, u32 *result)
int sceCdSendSCmd1D(int *arg1, unsigned int *arg2, unsigned int *arg3, u32 *status)
int sceCdReadDvdDualInfo(int *on_dual, unsigned int *layer1_start)
int sceCdCloseConfig(u32 *result)
int sceCdStInit(u32 bufmax, u32 bankmax, void *buffer)
int sceCdGetToc2(u8 *toc, int param)
int sceCdReadGUID(u64 *guid)
int sceCdDiskReady(int mode)
int sceCdForbidRead(u32 *result)
int sceCdRM(char *buffer, u32 *status)
u32 sceCdPosToInt(sceCdlLOCCD *p)
int sceCdReadConsoleID(u8 *buffer, u32 *result)
int sceCdLayerSearchFile(sceCdlFILE *fp, const char *path, int layer)
int sceCdReadClock(sceCdCLOCK *clock)
int sceCdWriteConfig(const void *buffer, u32 *result)
int sceCdWM(const char *buffer, u32 *status)
int sceCdWriteConsoleID(const u8 *buffer, u32 *status)
u32 sceCdGetReadPos(void)
int sceCdGetDiskType(void)
sceCdlLOCCD * sceCdIntToPos(u32 i, sceCdlLOCCD *p)
int sceCdGetWakeUpReason(void)
int sceCdMmode(int media)
int sceCdWI(const u8 *buffer, u32 *result)
int sceCdAutoAdjustCtrl(int mode, u32 *result)
int sceCdApplySCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize, void *outBuff)
int sceCdXBSPowerCtl(u8 arg1, u8 arg2, u32 *result1, u32 *result2)
int sceRemote2_7Get(u32 *param, u32 *status)
int sceCdSetTimeout(int param, int timeout)
int sceCdStStart(u32 lbn, sceCdRMode *mode)
void * sceCdPOffCallback(void(*func)(void *userdata), void *userdata)
int sceCdBootCertify(const u8 *romname)
int sceCdChgSys(u32 arg1)
int sceCdReadConfig(void *buffer, u32 *result)
int sceCdMV(u8 *buffer, u32 *status)
void(* sceCdCBFunc)(int reason)
int sceCdWriteNVM(u32 address, u16 data, u8 *result)
int sceCdReadFull(unsigned int lsn, unsigned int sectors, void *buf, sceCdRMode *mode)
int sceCdDecSet(unsigned char enable_xor, unsigned char enable_shift, unsigned char shiftval)
int sceCdBuzzerCtl(u32 *result)
int sceCdRI(u8 *buffer, u32 *result)
int sceCdNoticeGameStart(u8 arg1, u32 *result)
int sceCdReadWakeUpTime(sceCdCLOCK *clock, u16 *userdata, u32 *wakeupreason, int *flags)
int sceCdForbidDVDP(u32 *result)
int sceCdRead(u32 lbn, u32 sectors, void *buffer, sceCdRMode *mode)
int sceCdApplyNCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize)
int sceCdWriteWakeUpTime(const sceCdCLOCK *clock, u16 userdata, int flags)
int sceCdRE(unsigned int lsn, unsigned int sectors, void *buf, sceCdRMode *mode)
int sceCdReadChain(sceCdRChain *tag, sceCdRMode *mode)
int sceCdOpenConfig(int block, int mode, int NumBlocks, u32 *status)
int sceCdTrayReq(int param, u32 *traychk)
int sceCdSetLEDsMode(u32 param, u32 *result)
int sceCdWriteClock(sceCdCLOCK *clock)
int sceCdWriteRegionParams(u8 arg1, u32 *arg2, u8 *arg3, u32 *result)
int sceCdBlueLEDCtl(u8 control, u32 *result)
int sceCdCtrlADout(int mode, u32 *status)