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 *),
void *arg);
197static int vCancelAlarm(
unsigned int (*alarm_cb)(
void *),
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);
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);
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);
2071 KPRINTF(
"Cdvd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
2077 if ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2084 g_cdvdman_sync_timeout = timeout;
2087 g_cdvdman_stream_timeout = timeout;
2100 VERBOSE_KPRINTF(1,
"sceCdSync: Call mode %d Com %x\n", mode, (u8)g_cdvdman_istruct.m_cdvdman_command);
2104 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2106 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2110 return !!(!sceCdCheckCmd() || (g_cdvdman_istruct.m_read2_flag));
2113 sysclk.lo = 0x9000 * g_cdvdman_sync_timeout;
2114 vSetAlarm(&sysclk, (
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
2115 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2117 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2119 vCancelAlarm((
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
2123 sysclk.lo = 0x41EB0000;
2124 vSetAlarm(&sysclk, (
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
2125 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2127 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2129 vCancelAlarm((
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
2132 while ( !sceCdCheckCmd() )
2134 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2139 sysclk.lo = 0x9000 * g_cdvdman_sync_timeout;
2140 vSetAlarm(&sysclk, (
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
2141 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2143 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2145 vCancelAlarm((
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
2148 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag || g_cdvdman_ee_rpc_fno
2149 || g_cdvdman_istruct.m_stream_flag )
2151 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2152 if ( g_cdvdman_ee_rpc_fno )
2160 !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag || g_cdvdman_ee_rpc_fno
2161 || (g_cdvdman_istruct.m_stream_flag));
2163 WaitEventFlag(g_cdvdman_intr_evfid, 0x21, WEF_OR, &efbits);
2164 ReferEventFlagStatus(g_cdvdman_intr_evfid, &efinfo);
2167 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
2169 SetEventFlag(g_cdvdman_intr_evfid, 0x20);
2173 WaitEventFlag(g_cdvdman_intr_evfid, 0x20, WEF_AND, &efbits);
2178 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2180 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2186 "sceCdSync: Command= %d Error= %d\n",
2187 (u8)g_cdvdman_istruct.m_cdvdman_command,
2188 (u8)g_cdvdman_istruct.m_last_error);
2194 VERBOSE_KPRINTF(1,
"sceCdSpinCtrlIOP speed= %d\n", speed);
2195 g_cdvdman_spinctl = speed;
2205 if ( PollEventFlag(g_sfile_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
2209 for ( i = 0; i < ((
sizeof(g_cdvdman_sfname) /
sizeof(g_cdvdman_sfname[0])) - 1) && path[i]; i += 1 )
2211 g_cdvdman_sfname[i] = path[i];
2213 g_cdvdman_sfname[i] = 0;
2214 g_cdvdman_srchspd = 1;
2216 vSetEventFlag(g_sfile_evfid, 1);
2227 return cdvdman_gettoc(
toc);
2233 USE_DEV5_MMIO_HWPORT();
2237 VERBOSE_KPRINTF(1,
"DISK READY call from iop %d\n", mode);
2238#ifdef CDVD_VARIANT_XOSD
2239 if ( g_cdvdman_istruct.m_cd_mode_ps2_atapi == 1 )
2241 return mode == 8 ? -1 : 6;
2243 switch ( get_disk_type_ex() )
2255 VERBOSE_KPRINTF(1,
"Wait Drive Ready %x\n", dev5_mmio_hwport->m_dev5_reg_005);
2256 while ( g_cdvdman_istruct.m_read2_flag )
2259#ifdef CDVD_VARIANT_XOSD
2260 switch ( get_disk_type_ex() )
2267 case SCECdDETCTDVDS:
2268 case SCECdDETCTDVDD:
2269 while ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) != 0x40 )
2272 WaitEventFlag(g_cdvdman_intr_evfid, 1, WEF_AND, &efbits);
2273#ifdef CDVD_VARIANT_XOSD
2274 if ( !get_disk_type_ex() )
2287 VERBOSE_KPRINTF(1,
"Wait Exit\n");
2290 return (u8)dev5_mmio_hwport->m_dev5_reg_005;
2293 if ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) == 0x40 && !g_cdvdman_istruct.m_read2_flag )
2297 VERBOSE_KPRINTF(1,
"Drive Not Ready\n");
2304#ifdef CDVD_VARIANT_XOSD
2307 VERBOSE_KPRINTF(1,
"sceCdGetDiskType Call\n");
2308 cdvd_register = get_cdvd_register(0x0F);
2309 VERBOSE_KPRINTF(1,
"sceCdGetDiskType 0x%02x\n", cdvd_register);
2310 return cdvd_register;
2312 USE_DEV5_MMIO_HWPORT();
2314 return (u8)dev5_mmio_hwport->m_dev5_reg_00F;
2318#ifdef CDVD_VARIANT_XOSD
2319static int get_disk_type_ex(
void)
2324 USE_DEV5_MMIO_HWPORT();
2331 retval = (g_cdvdman_istruct.m_cd_mode_ps2_atapi == 1) ? 257 : dev5_mmio_hwport->m_dev5_reg_00F;
2340#ifdef CDVD_VARIANT_XOSD
2343 int wakeup_reason_reg;
2345 VERBOSE_KPRINTF(1,
"sceCdGetWakeUpReason Call\n");
2346 wakeup_reason_reg = get_cdvd_register(0x15);
2347 if ( wakeup_reason_reg != -1 )
2349 wakeup_reason_reg &= 0xF;
2351 VERBOSE_KPRINTF(1,
"sceCdGetWakeUpReason 0x%02x\n", wakeup_reason_reg);
2352 return wakeup_reason_reg;
2359#ifndef CDVD_VARIANT_XOSD
2362#ifndef CDVD_VARIANT_XOSD
2363 USE_DEV5_MMIO_HWPORT();
2366#ifdef CDVD_VARIANT_XOSD
2367 reg_00A_tmp = get_cdvd_register(0x0A);
2369 reg_00A_tmp = dev5_mmio_hwport->m_dev5_reg_00A;
2371#ifndef CDVD_VARIANT_XOSD
2377 if ( !g_cdvdman_istruct.m_tray_is_open && cdvdman_scmd_sender_03_30(&rdata_tmp, &status_tmp) == 1 && !status_tmp )
2379 reg_00A_tmp &= ~SCECdStatShellOpen;
2380 if ( (rdata_tmp & 8) )
2385 if ( (reg_00A_tmp & 0x1E) )
2391 if ( g_cdvdman_istruct.m_use_toc )
2393 reg_00A_tmp &= ~SCECdStatShellOpen;
2395 if ( g_cdvdman_istruct.m_power_flag )
2402#ifdef CDVD_VARIANT_OSD
2405 USE_DEV5_MMIO_HWPORT();
2407 return !g_cdvdman_istruct.m_power_flag ? (u8)dev5_mmio_hwport->m_dev5_reg_00A : -1;
2413 p->sector = 16 * ((i + 150) % 75 / 10) + (i + 150) % 75 % 10;
2414 p->second = 16 * ((i + 150) / 75 % 60 / 10) + (i + 150) / 75 % 60 % 10;
2415 p->minute = 16 * ((i + 150) / 75 / 60 / 10) + (i + 150) / 75 / 60 % 10;
2422 return 75 * (60 * (10 * (p->minute >> 4) + (p->minute & 0xF)) + 10 * (p->second >> 4) + (p->second & 0xF))
2423 + 10 * (p->sector >> 4) + (p->sector & 0xF) - 150;
2426#ifdef CDVD_VARIANT_DNAS
2427static int read_id_from_rom(
int mode,
int *buf)
2437 for ( i = 0; i < (
sizeof(idinfo) /
sizeof(idinfo[0])); i += 1 )
2439 for ( j = 0; j <
sizeof(chksumstk); j += 1 )
2441 ((
char *)&idinfo)[(i * 4) + j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2442 ((
char *)&chksumstk)[j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2444 chksumint += chksumstk;
2446 for ( ; i < 0x4000; i += 1 )
2448 for ( j = 0; j <
sizeof(chksumstk); j += 1 )
2450 ((
char *)&chksumstk)[j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2452 chksumint += chksumstk;
2456 KPRINTF(
"# checksum error %d\n", chksumint);
2471static int query_boot_mode_6_nonzero(
void)
2475 BootMode = QueryBootMode(6);
2476 return !(!BootMode || (*(u16 *)BootMode & 0xFFFC) != 0x60);
2479static int query_boot_mode_6_zero(
void)
2481 return !QueryBootMode(6);
2484static int cdvdman_readID(
int mode,
int *buf)
2491 if ( query_boot_mode_6_nonzero() )
2493 if ( read_id_from_rom(mode, buf) && mode == 1 )
2505 if ( query_boot_mode_6_zero() )
2507 if ( !
sceCdRI(id_val, &id_result) || id_result )
2514 if ( !g_readid_systemtime.lo && !g_readid_systemtime.hi )
2516 GetSystemTime(&sysclk);
2517 g_readid_systemtime = sysclk;
2523 *buf = *(u32 *)id_val >> 8;
2527 *buf = id_val[0] | 0x8004600;
2528 buf[1] = *(u32 *)&id_val[4];
2536 return cdvdman_readID(0, (
int *)guid);
2541 return cdvdman_readID(1, (
int *)
id);
2545int sceCdStInit(u32 bufmax, u32 bankmax,
void *buffer)
2551 VERBOSE_KPRINTF(1,
"sceCdStInit call IOP\n");
2552 memset(&devctl_req, 0,
sizeof(devctl_req));
2553 devctl_req.m_cmdid = 5;
2554 devctl_req.m_posszarg1 = bufmax;
2555 devctl_req.m_posszarg2 = bankmax;
2556 devctl_req.m_buffer = buffer;
2557 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2567 VERBOSE_KPRINTF(1,
"sceCdStStart call IOP\n");
2568 memset(&devctl_req, 0,
sizeof(devctl_req));
2569 devctl_req.m_rmode.
datapattern = mode->datapattern;
2570 devctl_req.m_rmode.
spindlctrl = mode->spindlctrl;
2571 devctl_req.m_cmdid = 1;
2572 devctl_req.m_posszarg1 = lbn;
2573 devctl_req.m_rmode.
trycount = mode->trycount;
2574 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2583 VERBOSE_KPRINTF(1,
"sceCdStSeekF call IOP\n");
2584 memset(&devctl_req, 0,
sizeof(devctl_req));
2585 devctl_req.m_cmdid = 9;
2586 devctl_req.m_posszarg1 = lsn;
2587 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2596 VERBOSE_KPRINTF(1,
"sceCdStSeek call IOP\n");
2597 memset(&devctl_req, 0,
sizeof(devctl_req));
2598 devctl_req.m_posszarg1 = lbn;
2599 devctl_req.m_cmdid = 4;
2600 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2609 VERBOSE_KPRINTF(1,
"sceCdStStop call IOP\n");
2610 memset(&devctl_req, 0,
sizeof(devctl_req));
2611 devctl_req.m_cmdid = 3;
2612 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2615int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
2623 VERBOSE_KPRINTF(1,
"sceCdStRead call IOP\n");
2624 memset(&devctl_req, 0,
sizeof(devctl_req));
2625 devctl_req.m_cmdid = 1;
2626 devctl_req.m_posszarg2 = sectors;
2627 devctl_req.m_buffer = buffer;
2628 if ( devctl(
"cdrom_stm0:", 0x4394, &devctl_req,
sizeof(devctl_req), &buf, 4) < 0 )
2632 *error = devctl_req.m_error;
2642 VERBOSE_KPRINTF(1,
"sceCdStPause call IOP\n");
2643 memset(&devctl_req, 0,
sizeof(devctl_req));
2644 devctl_req.m_cmdid = 7;
2645 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2654 VERBOSE_KPRINTF(1,
"sceCdStResume call IOP\n");
2655 memset(&devctl_req, 0,
sizeof(devctl_req));
2656 devctl_req.m_cmdid = 8;
2657 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2666 VERBOSE_KPRINTF(1,
"sceCdStStat call IOP\n");
2667 memset(&devctl_req, 0,
sizeof(devctl_req));
2668 devctl_req.m_cmdid = 6;
2669 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2679 VERBOSE_PRINTF(1,
"CdSearchFile: start name= %s layer= %d\n", name, layer);
2680 if ( g_cdvdman_fs_layer != layer )
2682 g_cdvdman_fs_cache = 0;
2684 if ( !cdvdman_mediactl(0) && g_cdvdman_fs_cache )
2686 VERBOSE_KPRINTF(1,
"CdSearchFile: cache dir data used\n");
2690 VERBOSE_PRINTF(1,
"CdSearchFile Topen= %s\n", name);
2691 if ( !CD_newmedia(layer) )
2693 g_cdvdman_fs_cache = 0;
2696 g_cdvdman_fs_cache = 1;
2698 if ( *name !=
'\\' )
2705 for ( i = 0; i < 8 && name[i]; i += 1 )
2707 for ( j = 0; name[i + j] !=
'\\'; j += 1 )
2709 name_buf[j] = name[i + j];
2712 parent_level = cdvdman_finddir(parent_level, name_buf);
2713 if ( parent_level == -1 )
2721 VERBOSE_PRINTF(1,
"%s: path level (%d) error\n", name, i);
2726 VERBOSE_PRINTF(1,
"%s: dir was not found\n", name);
2730 if ( !CD_cachefile(parent_level, layer) )
2732 VERBOSE_PRINTF(1,
"CdSearchFile: disc error\n");
2735 VERBOSE_PRINTF(2,
"CdSearchFile: searching %s...\n", name_buf);
2737 j < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0])) && g_cdvdman_filetbl[j].m_file_struct.
name[0];
2740 VERBOSE_PRINTF(1,
"%d %s %s\n", (
int)j, g_cdvdman_filetbl[j].m_file_struct.name, name_buf);
2741 if ( cdvdman_cmpname(g_cdvdman_filetbl[j].m_file_struct.name, name_buf) )
2743 VERBOSE_PRINTF(2,
"%s:\t found\n", name_buf);
2746 fp->m_file_struct.lsn += layer ? g_cdvdman_fs_base2 : 0;
2750 VERBOSE_PRINTF(1,
"%s: not found\n", name_buf);
2754static int sceCdSearchDir(
char *dirname,
int layer)
2758 VERBOSE_PRINTF(1,
"_sceCdSearchDir: dir name %s layer %d\n", dirname, layer);
2762static int sceCdReadDir(
sceCdlFILE *fp,
int dsec,
int index,
int layer)
2764 VERBOSE_PRINTF(1,
"_sceCdReadDir: current= %d dsec= %d layer= %d\n", g_cdvdman_fs_cdsec, dsec, layer);
2765 if ( g_cdvdman_fs_cdsec != dsec || g_cdvdman_fs_layer != layer )
2767 if ( g_cdvdman_fs_layer != layer )
2769 if ( !CD_newmedia(layer) )
2773 g_cdvdman_fs_cache = 1;
2775 if ( !CD_cachefile(dsec, layer) )
2780 if ( g_cdvdman_filetbl[index].m_file_struct.name[0] )
2782 VERBOSE_PRINTF(1,
"%s:\t found dir_point %d\n", g_cdvdman_filetbl[index].m_file_struct.name, index);
2790static int cdvdman_cmpname(
const char *p,
const char *q)
2792 return !strncmp(p, q, 12);
2795static int CD_newmedia(
int arg)
2797 unsigned int DiskType;
2804#ifdef CDVD_VARIANT_XOSD
2805 DiskType = get_disk_type_ex();
2821 VERBOSE_PRINTF(1,
"CD_newmedia: Illegal disc media type =%d\n", (
int)DiskType);
2824 g_cdvdman_fs_base2 = 0;
2827 if ( !DvdDual_infochk() )
2829 VERBOSE_PRINTF(1,
"CD_newmedia: Get DvdDual_infochk fail\n");
2832 g_cdvdman_fs_base2 = arg ? g_cdvdman_istruct.m_layer_1_lsn : 0;
2834 if ( disc_read(1, g_cdvdman_fs_base2 + 0x10, g_cdvdman_fs_rbuf, arg) != 1 )
2836 VERBOSE_PRINTF(1,
"CD_newmedia: Read error in disc_read(PVD)\n");
2840 for ( i = 0; i < g_cdvdman_pathtblsize; i += 1 )
2842 g_cdvdman_pathtbl[i].m_cache_hit_count = 0;
2843 g_cdvdman_pathtbl[i].m_layer = 0;
2844 g_cdvdman_pathtbl[i].m_nsec = 0;
2845 g_cdvdman_pathtbl[i].m_lsn = 0;
2846 g_cdvdman_pathtbl[i].m_cache_path_sz = 0;
2850 g_cache_path_size = 0;
2852 if ( strncmp((
char *)((
iso9660_desc_t *)g_cdvdman_fs_rbuf)->m_id,
"CD001", 5) )
2854 VERBOSE_PRINTF(1,
"CD_newmedia: Disc format error in cd_read(PVD)\n");
2863 VERBOSE_PRINTF(1,
"CD_newmedia: CD Read mode\n");
2864 ptsector = *(u32 *)(((
iso9660_desc_t *)g_cdvdman_fs_rbuf)->m_type_l_path_table);
2869 VERBOSE_PRINTF(1,
"CD_newmedia: DVD Read mode\n");
2873 if ( disc_read(1, g_cdvdman_fs_base2 + ptsector, g_cdvdman_fs_rbuf, arg) != 1 )
2875 VERBOSE_PRINTF(1,
"CD_newmedia: Read error (PT:%08x)\n", ptsector);
2878 VERBOSE_PRINTF(2,
"CD_newmedia: sarching dir..\n");
2880 i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0]))
2881 && path_cur < (
iso9660_path_t *)&g_cdvdman_fs_rbuf[
sizeof(g_cdvdman_fs_rbuf)] && path_cur->m_name_len[0];
2883 path_cur = (
iso9660_path_t *)(((
char *)path_cur) + path_cur->m_name_len[0] + (path_cur->m_name_len[0] & 1)
2886 memcpy(&g_cdvdman_dirtbl[i].m_extent, path_cur->m_extent,
sizeof(path_cur->m_extent));
2887 g_cdvdman_dirtbl[i].m_number = i;
2888 memcpy(&g_cdvdman_dirtbl[i].m_parent, path_cur->m_parent,
sizeof(path_cur->m_parent));
2889 memcpy(g_cdvdman_dirtbl[i].m_name, path_cur->m_name, path_cur->m_name_len[0]);
2890 g_cdvdman_dirtbl[i].m_name[path_cur->m_name_len[0]] = 0;
2893 "\t%08x,%04x,%04x,%s\n",
2894 g_cdvdman_dirtbl[i].m_extent,
2895 g_cdvdman_dirtbl[i].m_number,
2896 g_cdvdman_dirtbl[i].m_parent,
2897 g_cdvdman_dirtbl[i].m_name);
2899 if ( i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0])) )
2901 g_cdvdman_dirtbl[i].m_parent = 0;
2903 g_cdvdman_fs_cdsec = 0;
2904 g_cdvdman_fs_layer = arg;
2905 VERBOSE_PRINTF(2,
"CD_newmedia: %d dir entries found\n", (
int)i);
2909static int cdvdman_finddir(
int target_parent,
const char *target_name)
2913 for ( i = 0; i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0])) && g_cdvdman_dirtbl[i].m_parent; i += 1 )
2915 if ( g_cdvdman_dirtbl[i].m_parent == target_parent && !strcmp(target_name, g_cdvdman_dirtbl[i].m_name) )
2923static int CD_cachefile(
int dsec,
int layer)
2928 if ( dsec == g_cdvdman_fs_cdsec )
2933 disc_read(1, g_cdvdman_dirtbl[dsec - 1].m_extent + (layer ? g_cdvdman_fs_base2 : 0), g_cdvdman_fs_rbuf, layer)
2936 VERBOSE_PRINTF(1,
"CD_cachefile: dir not found\n");
2937 g_cdvdman_fs_cdsec = 0;
2940 VERBOSE_PRINTF(2,
"CD_cachefile: searching...\n");
2942 i < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0]))
2943 && dirent_cur < (
iso9660_dirent_t *)&g_cdvdman_fs_rbuf[
sizeof(g_cdvdman_fs_rbuf)];
2944 i += 1, dirent_cur = (
iso9660_dirent_t *)((
char *)dirent_cur + dirent_cur->m_length[0]) )
2948 if ( !dirent_cur->m_length[0] )
2953 &g_cdvdman_filetbl[i].m_file_struct.lsn, dirent_cur->m_extent,
sizeof(g_cdvdman_filetbl[i].m_file_struct.lsn));
2955 &g_cdvdman_filetbl[i].m_file_struct.size, dirent_cur->m_size,
sizeof(g_cdvdman_filetbl[i].m_file_struct.size));
2956 file_year = dirent_cur->m_date[0] + 1900;
2957 g_cdvdman_filetbl[i].m_file_struct.
date[7] = file_year >> 8;
2958 g_cdvdman_filetbl[i].m_file_struct.
date[6] = file_year;
2959 g_cdvdman_filetbl[i].m_file_struct.
date[5] = dirent_cur->m_date[1];
2960 g_cdvdman_filetbl[i].m_file_struct.
date[4] = dirent_cur->m_date[2];
2961 g_cdvdman_filetbl[i].m_file_struct.
date[3] = dirent_cur->m_date[3];
2962 g_cdvdman_filetbl[i].m_file_struct.
date[2] = dirent_cur->m_date[4];
2963 g_cdvdman_filetbl[i].m_file_struct.
date[1] = dirent_cur->m_date[5];
2964 g_cdvdman_filetbl[i].m_flags = dirent_cur->m_flags[0];
2968 strcpy(g_cdvdman_filetbl[i].m_file_struct.name,
".");
2971 strcpy(g_cdvdman_filetbl[i].m_file_struct.name,
"..");
2974 memcpy(g_cdvdman_filetbl[i].m_file_struct.name, dirent_cur->m_name, dirent_cur->m_name_len[0]);
2975 g_cdvdman_filetbl[i].m_file_struct.
name[dirent_cur->m_name_len[0]] = 0;
2980 "\t lsn %d size %d name:%d:%s %d/%d/%d %d:%d:%d\n",
2981 (
int)(g_cdvdman_filetbl[i].m_file_struct.lsn),
2982 (
int)(g_cdvdman_filetbl[i].m_file_struct.size),
2983 dirent_cur->m_name_len[0],
2984 g_cdvdman_filetbl[i].m_file_struct.name,
2986 g_cdvdman_filetbl[i].m_file_struct.date[5],
2987 g_cdvdman_filetbl[i].m_file_struct.date[4],
2988 g_cdvdman_filetbl[i].m_file_struct.date[3],
2989 g_cdvdman_filetbl[i].m_file_struct.date[2],
2990 g_cdvdman_filetbl[i].m_file_struct.date[1]);
2992 g_cdvdman_fs_cdsec = dsec;
2993 if ( i < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0])) )
2995 g_cdvdman_filetbl[i].m_file_struct.
name[0] = 0;
2997 VERBOSE_PRINTF(2,
"CD_cachefile: %d files found\n", (
int)i);
3001static int disc_read(
int size,
int loc,
void *buffer,
int layer)
3011 VERBOSE_PRINTF(1,
"cd_read:lsn= %d size= %d layer= %d\n", loc, size, layer);
3012 if ( cdvdman_l0check(layer) )
3014 g_cdvdman_srchspd = 0;
3016 switch ( g_cdvdman_srchspd )
3032 if ( !g_cdvdman_pathtblflag )
3040 pathcachecnt = (g_cache_count < g_cdvdman_pathtblsize) ? g_cache_count : g_cdvdman_pathtblsize;
3041 for ( i = 0; i < pathcachecnt; i += 1 )
3045 "Path table Cache Search lsn:%d:%d nsec:%d:%d layer%d:%d\n",
3046 g_cdvdman_pathtbl[i].m_lsn,
3048 g_cdvdman_pathtbl[i].m_nsec,
3050 g_cdvdman_pathtbl[i].m_layer,
3053 g_cdvdman_pathtbl[i].m_lsn == loc && g_cdvdman_pathtbl[i].m_nsec == (
unsigned int)size
3054 && g_cdvdman_pathtbl[i].m_layer == layer )
3059 if ( i != pathcachecnt )
3061 VERBOSE_KPRINTF(1,
"Path table Cache ON:%d\n", g_cdvdman_pathtbl[i].m_cache_path_sz);
3062 if ( lseek(g_cache_path_fd, g_cdvdman_pathtbl[i].m_cache_path_sz, 0) >= 0 )
3064 read(g_cache_path_fd, buffer, size << 11);
3066 g_cdvdman_pathtbl[i].m_cache_hit_count += 1;
3072 if ( !
sceCdRE(loc, size, buffer, &rmode) )
3083 if ( g_cache_count >= g_cdvdman_pathtblsize )
3086 unsigned int cacheblo2;
3089 if ( g_cache_table >= g_cdvdman_pathtblsize )
3093 cachetblo1 = g_cache_table;
3094 cacheblo2 = cachetblo1;
3095 for ( i = 0; (
unsigned int)i < g_cache_count; i += 1 )
3097 if ( cacheblo2 >= g_cdvdman_pathtblsize )
3102 g_cdvdman_pathtbl[cacheblo2].m_nsec >= (
unsigned int)size
3103 && g_cdvdman_pathtbl[cacheblo2].m_cache_hit_count
3104 < (
unsigned int)g_cdvdman_pathtbl[cachetblo1].m_cache_hit_count )
3106 cachetblo1 = cacheblo2;
3110 cache_path_sz = g_cdvdman_pathtbl[cachetblo1].m_cache_path_sz;
3111 g_cache_table = cachetblo1;
3115 cache_path_sz = g_cache_path_size;
3116 g_cache_table = g_cache_count;
3119 if ( lseek(g_cache_path_fd, cache_path_sz, 0) >= 0 )
3121 int ptbl_wcache_write_res;
3123 ptbl_wcache_write_res = write(g_cache_path_fd, buffer, size << 11);
3124 if ( ptbl_wcache_write_res == size << 11 )
3127 g_cdvdman_pathtbl[g_cache_table].m_cache_path_sz = cache_path_sz;
3128 g_cdvdman_pathtbl[g_cache_table].m_lsn = loc;
3129 g_cdvdman_pathtbl[g_cache_table].m_nsec = size;
3130 g_cdvdman_pathtbl[g_cache_table].m_layer = layer;
3131 g_cdvdman_pathtbl[g_cache_table].m_cache_hit_count = 0;
3132 g_cache_path_size += (g_cache_count < g_cdvdman_pathtblsize) ? ptbl_wcache_write_res : 0;
3136 VERBOSE_KPRINTF(1,
"Ptbl_WCache:write %d", ptbl_wcache_write_res);
3137 g_cdvdman_pathtbl[g_cache_table].m_cache_hit_count = 0;
3138 g_cdvdman_pathtbl[g_cache_table].m_layer = 0;
3139 g_cdvdman_pathtbl[g_cache_table].m_nsec = 0;
3140 g_cdvdman_pathtbl[g_cache_table].m_lsn = 0;
3151 if ( !
sceCdRE(loc, size, buffer, &rmode) )
3161 VERBOSE_KPRINTF(1,
"cd_read: error code %x\n",
sceCdGetError());
3165static int path_tbl_init(u32 blocks,
char *fname,
int action)
3179 if ( !g_cdvdman_pathtbl )
3182 g_cdvdman_pathtblflag = 0;
3186 sprintf(cachedir,
"%sCache_Path", fname);
3187 v = open(cachedir, O_TRUNC | O_CREAT | O_RDWR, 0x1ff );
3192 g_cache_path_fd = v;
3193 if ( !strncmp(cachedir,
"pfs", 3) )
3195 blocksbs = blocks << 11;
3196 ioctl2(g_cache_path_fd, PIOCALLOC, &blocksbs,
sizeof(blocksbs), 0, 0);
3198 for ( i = 0; i < blocks; i += 1 )
3200 v = write(g_cache_path_fd, g_cdvdman_fs_rbuf,
sizeof(g_cdvdman_fs_rbuf));
3209 g_cdvdman_pathtblsize = blocks;
3210 for ( i = 0; i < blocks; i += 1 )
3212 g_cdvdman_pathtbl[i].m_cache_hit_count = 0;
3213 g_cdvdman_pathtbl[i].m_layer = 0;
3214 g_cdvdman_pathtbl[i].m_nsec = 0;
3215 g_cdvdman_pathtbl[i].m_lsn = 0;
3216 g_cdvdman_pathtbl[i].m_cache_path_sz = 0;
3218 g_cache_path_size = 0;
3221 g_cdvdman_pathtblflag = 1;
3227 if ( g_cache_path_fd != -1 )
3229 num = close(g_cache_path_fd);
3232 if ( !strncmp(cachedir,
"pfs", 3) )
3234 num = remove(cachedir);
3236 else if ( !strncmp(cachedir,
"host", 4) )
3244 g_cache_path_fd = -1;
3247 g_cache_path_size = 0;
3248 g_cdvdman_pathtblflag = 0;
3249 g_cdvdman_pathtblsize = 0;
3250 FreeSysMemory(g_cdvdman_pathtbl);
3251 g_cdvdman_pathtbl = 0;
3255 VERBOSE_KPRINTF(1,
"path_tbl_init Error %d\n", v);
3257 return (!action) ? num : v;
3264 "\t" ".set push" "\n"
3265 "\t" ".set noat" "\n"
3266 "\t" ".set noreorder" "\n"
3267 "\t" ".global optimized_memcpy" "\n"
3268 "\t" "optimized_memcpy:" "\n"
3269 "\t" " srl $a3, $a2, 2" "\n"
3270 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3271 "\t" " or $a3, $a0, $a1" "\n"
3272 "\t" " andi $a3, $a3, 0x3" "\n"
3273 "\t" " bnez $a3, .Loptimized_memcpy_3" "\n"
3275 "\t" " srl $a3, $a2, 2" "\n"
3276 "\t" " addiu $at, $zero, 0xC" "\n"
3277 "\t" " div $zero, $a3, $at" "\n"
3278 "\t" " mflo $a3" "\n"
3279 "\t" " mfhi $v1" "\n"
3280 "\t" " beqz $v1, .Loptimized_memcpy_2" "\n"
3282 "\t" ".Loptimized_memcpy_1:" "\n"
3283 "\t" " lw $v0, 0x0($a1)" "\n"
3284 "\t" " addiu $v1, $v1, -0x1" "\n"
3285 "\t" " sw $v0, 0x0($a0)" "\n"
3286 "\t" " addiu $a1, $a1, 0x4" "\n"
3287 "\t" " bnez $v1, .Loptimized_memcpy_1" "\n"
3288 "\t" " addiu $a0, $a0, 0x4" "\n"
3289 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3291 "\t" ".Loptimized_memcpy_2:" "\n"
3292 "\t" " lw $v0, 0x0($a1)" "\n"
3293 "\t" " lw $v1, 0x4($a1)" "\n"
3294 "\t" " lw $t0, 0x8($a1)" "\n"
3295 "\t" " lw $t1, 0xC($a1)" "\n"
3296 "\t" " lw $t2, 0x10($a1)" "\n"
3297 "\t" " lw $t3, 0x14($a1)" "\n"
3298 "\t" " lw $t4, 0x18($a1)" "\n"
3299 "\t" " lw $t5, 0x1C($a1)" "\n"
3300 "\t" " lw $t6, 0x20($a1)" "\n"
3301 "\t" " lw $t7, 0x24($a1)" "\n"
3302 "\t" " lw $t8, 0x28($a1)" "\n"
3303 "\t" " lw $t9, 0x2C($a1)" "\n"
3304 "\t" " addiu $a3, $a3, -0x1" "\n"
3305 "\t" " sw $v0, 0x0($a0)" "\n"
3306 "\t" " sw $v1, 0x4($a0)" "\n"
3307 "\t" " sw $t0, 0x8($a0)" "\n"
3308 "\t" " sw $t1, 0xC($a0)" "\n"
3309 "\t" " sw $t2, 0x10($a0)" "\n"
3310 "\t" " sw $t3, 0x14($a0)" "\n"
3311 "\t" " sw $t4, 0x18($a0)" "\n"
3312 "\t" " sw $t5, 0x1C($a0)" "\n"
3313 "\t" " sw $t6, 0x20($a0)" "\n"
3314 "\t" " sw $t7, 0x24($a0)" "\n"
3315 "\t" " sw $t8, 0x28($a0)" "\n"
3316 "\t" " sw $t9, 0x2C($a0)" "\n"
3317 "\t" " addiu $a1, $a1, 0x30" "\n"
3318 "\t" " bnez $a3, .Loptimized_memcpy_2" "\n"
3319 "\t" " addiu $a0, $a0, 0x30" "\n"
3320 "\t" " j .Loptimized_memcpy_12" "\n"
3322 "\t" ".Loptimized_memcpy_3:" "\n"
3323 "\t" " andi $a3, $a0, 0x3" "\n"
3324 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3325 "\t" " andi $a3, $a1, 0x3" "\n"
3326 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3328 "\t" " srl $a3, $a2, 2" "\n"
3329 "\t" " addiu $at, $zero, 0xC" "\n"
3330 "\t" " div $zero, $a3, $at" "\n"
3331 "\t" " mflo $a3" "\n"
3332 "\t" " mfhi $v1" "\n"
3333 "\t" " beqz $v1, .Loptimized_memcpy_5" "\n"
3335 "\t" ".Loptimized_memcpy_4:" "\n"
3336 "\t" " lwl $v0, 0x3($a1)" "\n"
3337 "\t" " lwr $v0, 0x0($a1)" "\n"
3338 "\t" " addiu $v1, $v1, -0x1" "\n"
3339 "\t" " swl $v0, 0x3($a0)" "\n"
3340 "\t" " swr $v0, 0x0($a0)" "\n"
3341 "\t" " addiu $a1, $a1, 0x4" "\n"
3342 "\t" " bnez $v1, .Loptimized_memcpy_4" "\n"
3343 "\t" " addiu $a0, $a0, 0x4" "\n"
3344 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3346 "\t" ".Loptimized_memcpy_5:" "\n"
3347 "\t" " lwl $v0, 0x3($a1)" "\n"
3348 "\t" " lwr $v0, 0x0($a1)" "\n"
3349 "\t" " lwl $v1, 0x7($a1)" "\n"
3350 "\t" " lwr $v1, 0x4($a1)" "\n"
3351 "\t" " lwl $t0, 0xB($a1)" "\n"
3352 "\t" " lwr $t0, 0x8($a1)" "\n"
3353 "\t" " lwl $t1, 0xF($a1)" "\n"
3354 "\t" " lwr $t1, 0xC($a1)" "\n"
3355 "\t" " lwl $t2, 0x13($a1)" "\n"
3356 "\t" " lwr $t2, 0x10($a1)" "\n"
3357 "\t" " lwl $t3, 0x17($a1)" "\n"
3358 "\t" " lwr $t3, 0x14($a1)" "\n"
3359 "\t" " lwl $t4, 0x1B($a1)" "\n"
3360 "\t" " lwr $t4, 0x18($a1)" "\n"
3361 "\t" " lwl $t5, 0x1F($a1)" "\n"
3362 "\t" " lwr $t5, 0x1C($a1)" "\n"
3363 "\t" " lwl $t6, 0x23($a1)" "\n"
3364 "\t" " lwr $t6, 0x20($a1)" "\n"
3365 "\t" " lwl $t7, 0x27($a1)" "\n"
3366 "\t" " lwr $t7, 0x24($a1)" "\n"
3367 "\t" " lwl $t8, 0x2B($a1)" "\n"
3368 "\t" " lwr $t8, 0x28($a1)" "\n"
3369 "\t" " lwl $t9, 0x2F($a1)" "\n"
3370 "\t" " lwr $t9, 0x2C($a1)" "\n"
3371 "\t" " addiu $a3, $a3, -0x1" "\n"
3372 "\t" " swl $v0, 0x3($a0)" "\n"
3373 "\t" " swr $v0, 0x0($a0)" "\n"
3374 "\t" " swl $v1, 0x7($a0)" "\n"
3375 "\t" " swr $v1, 0x4($a0)" "\n"
3376 "\t" " swl $t0, 0xB($a0)" "\n"
3377 "\t" " swr $t0, 0x8($a0)" "\n"
3378 "\t" " swl $t1, 0xF($a0)" "\n"
3379 "\t" " swr $t1, 0xC($a0)" "\n"
3380 "\t" " swl $t2, 0x13($a0)" "\n"
3381 "\t" " swr $t2, 0x10($a0)" "\n"
3382 "\t" " swl $t3, 0x17($a0)" "\n"
3383 "\t" " swr $t3, 0x14($a0)" "\n"
3384 "\t" " swl $t4, 0x1B($a0)" "\n"
3385 "\t" " swr $t4, 0x18($a0)" "\n"
3386 "\t" " swl $t5, 0x1F($a0)" "\n"
3387 "\t" " swr $t5, 0x1C($a0)" "\n"
3388 "\t" " swl $t6, 0x23($a0)" "\n"
3389 "\t" " swr $t6, 0x20($a0)" "\n"
3390 "\t" " swl $t7, 0x27($a0)" "\n"
3391 "\t" " swr $t7, 0x24($a0)" "\n"
3392 "\t" " swl $t8, 0x2B($a0)" "\n"
3393 "\t" " swr $t8, 0x28($a0)" "\n"
3394 "\t" " swl $t9, 0x2F($a0)" "\n"
3395 "\t" " swr $t9, 0x2C($a0)" "\n"
3396 "\t" " addiu $a1, $a1, 0x30" "\n"
3397 "\t" " bnez $a3, .Loptimized_memcpy_5" "\n"
3398 "\t" " addiu $a0, $a0, 0x30" "\n"
3399 "\t" " j .Loptimized_memcpy_12" "\n"
3401 "\t" ".Loptimized_memcpy_6:" "\n"
3402 "\t" " andi $a3, $a0, 0x3" "\n"
3403 "\t" " beqz $a3, .Loptimized_memcpy_9" "\n"
3405 "\t" " srl $a3, $a2, 2" "\n"
3406 "\t" " addiu $at, $zero, 0xC" "\n"
3407 "\t" " div $zero, $a3, $at" "\n"
3408 "\t" " mflo $a3" "\n"
3409 "\t" " mfhi $v1" "\n"
3410 "\t" " beqz $v1, .Loptimized_memcpy_8" "\n"
3412 "\t" ".Loptimized_memcpy_7:" "\n"
3413 "\t" " lw $v0, 0x0($a1)" "\n"
3414 "\t" " addiu $v1, $v1, -0x1" "\n"
3415 "\t" " swl $v0, 0x3($a0)" "\n"
3416 "\t" " swr $v0, 0x0($a0)" "\n"
3417 "\t" " addiu $a1, $a1, 0x4" "\n"
3418 "\t" " bnez $v1, .Loptimized_memcpy_7" "\n"
3419 "\t" " addiu $a0, $a0, 0x4" "\n"
3420 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3422 "\t" ".Loptimized_memcpy_8:" "\n"
3423 "\t" " lw $v0, 0x0($a1)" "\n"
3424 "\t" " lw $v1, 0x4($a1)" "\n"
3425 "\t" " lw $t0, 0x8($a1)" "\n"
3426 "\t" " lw $t1, 0xC($a1)" "\n"
3427 "\t" " lw $t2, 0x10($a1)" "\n"
3428 "\t" " lw $t3, 0x14($a1)" "\n"
3429 "\t" " lw $t4, 0x18($a1)" "\n"
3430 "\t" " lw $t5, 0x1C($a1)" "\n"
3431 "\t" " lw $t6, 0x20($a1)" "\n"
3432 "\t" " lw $t7, 0x24($a1)" "\n"
3433 "\t" " lw $t8, 0x28($a1)" "\n"
3434 "\t" " lw $t9, 0x2C($a1)" "\n"
3435 "\t" " addiu $a3, $a3, -0x1" "\n"
3436 "\t" " swl $v0, 0x3($a0)" "\n"
3437 "\t" " swr $v0, 0x0($a0)" "\n"
3438 "\t" " swl $v1, 0x7($a0)" "\n"
3439 "\t" " swr $v1, 0x4($a0)" "\n"
3440 "\t" " swl $t0, 0xB($a0)" "\n"
3441 "\t" " swr $t0, 0x8($a0)" "\n"
3442 "\t" " swl $t1, 0xF($a0)" "\n"
3443 "\t" " swr $t1, 0xC($a0)" "\n"
3444 "\t" " swl $t2, 0x13($a0)" "\n"
3445 "\t" " swr $t2, 0x10($a0)" "\n"
3446 "\t" " swl $t3, 0x17($a0)" "\n"
3447 "\t" " swr $t3, 0x14($a0)" "\n"
3448 "\t" " swl $t4, 0x1B($a0)" "\n"
3449 "\t" " swr $t4, 0x18($a0)" "\n"
3450 "\t" " swl $t5, 0x1F($a0)" "\n"
3451 "\t" " swr $t5, 0x1C($a0)" "\n"
3452 "\t" " swl $t6, 0x23($a0)" "\n"
3453 "\t" " swr $t6, 0x20($a0)" "\n"
3454 "\t" " swl $t7, 0x27($a0)" "\n"
3455 "\t" " swr $t7, 0x24($a0)" "\n"
3456 "\t" " swl $t8, 0x2B($a0)" "\n"
3457 "\t" " swr $t8, 0x28($a0)" "\n"
3458 "\t" " swl $t9, 0x2F($a0)" "\n"
3459 "\t" " swr $t9, 0x2C($a0)" "\n"
3460 "\t" " addiu $a1, $a1, 0x30" "\n"
3461 "\t" " bnez $a3, .Loptimized_memcpy_8" "\n"
3462 "\t" " addiu $a0, $a0, 0x30" "\n"
3463 "\t" " j .Loptimized_memcpy_12" "\n"
3465 "\t" ".Loptimized_memcpy_9:" "\n"
3466 "\t" " srl $a3, $a2, 2" "\n"
3467 "\t" " addiu $at, $zero, 0xC" "\n"
3468 "\t" " div $zero, $a3, $at" "\n"
3469 "\t" " mflo $a3" "\n"
3470 "\t" " mfhi $v1" "\n"
3471 "\t" " beqz $v1, .Loptimized_memcpy_11" "\n"
3473 "\t" ".Loptimized_memcpy_10:" "\n"
3474 "\t" " lwl $v0, 0x3($a1)" "\n"
3475 "\t" " lwr $v0, 0x0($a1)" "\n"
3476 "\t" " addiu $v1, $v1, -0x1" "\n"
3477 "\t" " sw $v0, 0x0($a0)" "\n"
3478 "\t" " addiu $a1, $a1, 0x4" "\n"
3479 "\t" " bnez $v1, .Loptimized_memcpy_10" "\n"
3480 "\t" " addiu $a0, $a0, 0x4" "\n"
3481 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3483 "\t" ".Loptimized_memcpy_11:" "\n"
3484 "\t" " lwl $v0, 0x3($a1)" "\n"
3485 "\t" " lwr $v0, 0x0($a1)" "\n"
3486 "\t" " lwl $v1, 0x7($a1)" "\n"
3487 "\t" " lwr $v1, 0x4($a1)" "\n"
3488 "\t" " lwl $t0, 0xB($a1)" "\n"
3489 "\t" " lwr $t0, 0x8($a1)" "\n"
3490 "\t" " lwl $t1, 0xF($a1)" "\n"
3491 "\t" " lwr $t1, 0xC($a1)" "\n"
3492 "\t" " lwl $t2, 0x13($a1)" "\n"
3493 "\t" " lwr $t2, 0x10($a1)" "\n"
3494 "\t" " lwl $t3, 0x17($a1)" "\n"
3495 "\t" " lwr $t3, 0x14($a1)" "\n"
3496 "\t" " lwl $t4, 0x1B($a1)" "\n"
3497 "\t" " lwr $t4, 0x18($a1)" "\n"
3498 "\t" " lwl $t5, 0x1F($a1)" "\n"
3499 "\t" " lwr $t5, 0x1C($a1)" "\n"
3500 "\t" " lwl $t6, 0x23($a1)" "\n"
3501 "\t" " lwr $t6, 0x20($a1)" "\n"
3502 "\t" " lwl $t7, 0x27($a1)" "\n"
3503 "\t" " lwr $t7, 0x24($a1)" "\n"
3504 "\t" " lwl $t8, 0x2B($a1)" "\n"
3505 "\t" " lwr $t8, 0x28($a1)" "\n"
3506 "\t" " lwl $t9, 0x2F($a1)" "\n"
3507 "\t" " lwr $t9, 0x2C($a1)" "\n"
3508 "\t" " addiu $a3, $a3, -0x1" "\n"
3509 "\t" " sw $v0, 0x0($a0)" "\n"
3510 "\t" " sw $v1, 0x4($a0)" "\n"
3511 "\t" " sw $t0, 0x8($a0)" "\n"
3512 "\t" " sw $t1, 0xC($a0)" "\n"
3513 "\t" " sw $t2, 0x10($a0)" "\n"
3514 "\t" " sw $t3, 0x14($a0)" "\n"
3515 "\t" " sw $t4, 0x18($a0)" "\n"
3516 "\t" " sw $t5, 0x1C($a0)" "\n"
3517 "\t" " sw $t6, 0x20($a0)" "\n"
3518 "\t" " sw $t7, 0x24($a0)" "\n"
3519 "\t" " sw $t8, 0x28($a0)" "\n"
3520 "\t" " sw $t9, 0x2C($a0)" "\n"
3521 "\t" " addiu $a1, $a1, 0x30" "\n"
3522 "\t" " bnez $a3, .Loptimized_memcpy_11" "\n"
3523 "\t" " addiu $a0, $a0, 0x30" "\n"
3524 "\t" ".Loptimized_memcpy_12:" "\n"
3525 "\t" " andi $v1, $a2, 0x3" "\n"
3526 "\t" " beqz $v1, .Loptimized_memcpy_14" "\n"
3528 "\t" ".Loptimized_memcpy_13:" "\n"
3529 "\t" " lb $v0, 0x0($a1)" "\n"
3530 "\t" " addiu $v1, $v1, -0x1" "\n"
3531 "\t" " sb $v0, 0x0($a0)" "\n"
3532 "\t" " addiu $a1, $a1, 0x1" "\n"
3533 "\t" " bnez $v1, .Loptimized_memcpy_13" "\n"
3534 "\t" " addiu $a0, $a0, 0x1" "\n"
3535 "\t" ".Loptimized_memcpy_14:" "\n"
3536 "\t" " addu $v0, $a2, $zero" "\n"
3539 "\t" ".set pop" "\n"
3544void hex_dump(u8 *addr_start,
int length)
3548 KPRINTF(
"Hex Dump addr %08x\n", addr_start);
3549 for ( i = 0; i < length; i += 1 )
3551 if ( !(i & 0xF) && i )
3555 KPRINTF(
" %02x", addr_start[i]);
3561static int cdvdman_initcfg(
void)
3568 for ( i = 0; i <= 100; i += 1 )
3570 unsigned int mvored;
3572#ifdef CDVD_VARIANT_XOSD
3573 if ( !
sceCdMV(m_version, &eflag) )
3575 if ( !
sceCdMV(m_version, &eflag) && (eflag & 0x80) )
3579 VERBOSE_KPRINTF(1,
"_sceCdMV error\n");
3581 mvored = m_version[3] | (m_version[2] << 8) | (m_version[1] << 16);
3582 g_cdvdman_emudvd9 = m_version[2] & 1;
3583 VERBOSE_KPRINTF(1,
"MV %02x %02x %02x %02x\n", m_version[0], m_version[1], m_version[2], m_version[3]);
3584 g_cdvdman_minver_10700 = mvored >= 0x10700;
3585 g_cdvdman_minver_20200 = mvored >= 0x20200;
3586 g_cdvdman_minver_20400 = mvored >= 0x20400;
3587 g_cdvdman_minver_20800 = mvored >= 0x20800;
3588 g_cdvdman_minver_50000 = mvored >= 0x50000;
3589 g_cdvdman_minver_50200 = mvored >= 0x50200;
3590 g_cdvdman_minver_50400 = mvored >= 0x50400;
3591 g_cdvdman_minver_50600 = mvored >= 0x50600;
3592#ifdef CDVD_VARIANT_XOSD
3593 VERBOSE_KPRINTF(0,
"M Version %02x %02x %02x %02x\n", m_version[0], m_version[1], m_version[2], m_version[3]);
3594 if ( cdvdman_get_renewal_date(m_version, &eflag) )
3598 "M Renewal Date 20%02x/%02x/%02x %02x:%02x\n",
3605 g_cdvdman_vernotxxx1x = 0;
3606 if ( g_cdvdman_minver_50600 )
3609 KPRINTF(
"X_model ");
3610 switch ( mvored & 0xF0 )
3613 KPRINTF(
"量産 OR 量産試作機\n");
3617 g_cdvdman_vernotxxx1x = 1;
3620 KPRINTF(
"手作り試作機\n");
3626 KPRINTF(
"Unkown\n");
3632 KPRINTF(
"X_model 旧原理試作機 Ver5.6未満 Found\n");
3635 g_cdvdman_minver_x_model_15 = (mvored & 0xF) == 1;
3636 g_cdvdman_minver_60000 = mvored >= 0x60000;
3637 g_cdvdman_minver_60200 = mvored >= 0x60200;
3638#ifdef CDVD_VARIANT_OSD
3639 g_cdvdman_minver_60600 = mvored >= 0x60600;
3646static int vSetAlarm(
iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *),
void *arg)
3648 return (
QueryIntrContext() ? iSetAlarm : SetAlarm)(sys_clock, alarm_cb, arg);
3651static int vCancelAlarm(
unsigned int (*alarm_cb)(
void *),
void *arg)
3657s32 vSignalSema(s32 sema_id)
3663static int vSetEventFlag(
int ef, u32 bits)
3668static int vClearEventFlag(
int ef, u32 bits)
3678static int vPollEventFlag(
int ef, u32 bits,
int mode, u32 *efbits)
3680#ifdef CDVD_VARIANT_XOSD
3686 return PollEventFlag(ef, bits, mode, efbits);
3688 retres = iReferEventFlagStatus(ef, &efinfo);
3694 if ( (mode & 1) ? !(efinfo.
currBits & bits) : ((efinfo.
currBits & bits) != bits) )
3700 iClearEventFlag(ef, ~bits);
3704 return PollEventFlag(ef, bits, mode, efbits);
3708static int vDelayThread(
int usec)
3718#ifdef CDVD_VARIANT_XOSD
3719static int get_cdvd_register(
int regnr)
3731 if ( !IntrContext && !intrres )
3733 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3740 iReferEventFlagStatus(g_cdvdman_csys_evfid, &efinfo);
3744 ReferEventFlagStatus(g_cdvdman_csys_evfid, &efinfo);
3751 if ( update_cd_mode_ps2_atapi() != 1 )
3753 regval = ((vu8 *)(0xBF402000))[regnr];
3757 if ( !IntrContext && !intrres )
3760 if ( g_cd_atapi_evfid != -1 )
3762 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
3764 if ( g_adma_evfid != -1 )
3766 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3768 if ( g_acmd_evfid != -1 )
3770 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
3776 if ( g_cd_atapi_evfid != -1 )
3780 iReferEventFlagStatus(g_cd_atapi_evfid, &efinfo);
3784 ReferEventFlagStatus(g_cd_atapi_evfid, &efinfo);
3791 if ( g_adma_evfid != -1 )
3795 iReferEventFlagStatus(g_adma_evfid, &efinfo);
3799 ReferEventFlagStatus(g_adma_evfid, &efinfo);
3806 if ( g_acmd_evfid != -1 )
3810 iReferEventFlagStatus(g_acmd_evfid, &efinfo);
3814 ReferEventFlagStatus(g_acmd_evfid, &efinfo);
3822 set_cdvd_dev5_base_addr_atapi(2);
3823 regval = ((vu8 *)(0xBF402000))[regnr];
3824 set_cdvd_dev5_base_addr_atapi(1);
3825 if ( !IntrContext && !intrres )
3827 if ( g_acmd_evfid != -1 )
3829 SetEventFlag(g_acmd_evfid, 1);
3831 if ( g_adma_evfid != -1 )
3833 SetEventFlag(g_adma_evfid, 1);
3835 if ( g_cd_atapi_evfid != -1 )
3837 SetEventFlag(g_cd_atapi_evfid, 3);
3841 if ( !IntrContext && !intrres )
3844 SetEventFlag(g_cdvdman_csys_evfid, 1);
3851static unsigned int read_timeout_alarm_cb(
void *userdata)
3857 read_timeout = sys_clock->lo / 0x9000;
3858 KPRINTF(
"Read Time Out %d(msec)\n", read_timeout);
3859 sceCdSC(0xFFFFFFEE, &read_timeout);
3868 if (
sceCdSync(1) || PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
3872 rc = g_cdvdman_user_cb;
3873 g_cdvdman_user_cb = function;
3874 vSetEventFlag(g_ncmd_evfid, 1);
3885 old_cb = g_cdvdman_power_off_callback;
3886 g_cdvdman_power_off_callback = func;
3887 g_cdvdman_power_off_callback_userdata = userdata;
3892#ifdef CDVD_VARIANT_XOSD
3899 old_cb = g_cdvdman_atapi_eject_bs_power_callback;
3900 g_cdvdman_atapi_eject_bs_power_callback = func;
3901 g_cdvdman_atapi_eject_bs_power_callback_userdata = userdata;
3907int sceCdstm0Cb(
void (*p)(
int))
3909 g_cdvdman_cdstm0cb = p;
3913int sceCdstm1Cb(
void (*p)(
int))
3915 g_cdvdman_cdstm1cb = p;
3923 int ext_passthrough;
3924 USE_DEV5_MMIO_HWPORT();
3926 ext_passthrough = 0;
3927 s->m_wait_flag = s->m_waf_set_test;
3928 iSetEventFlag(g_cdvdman_intr_evfid, 0x29);
3930 if ( s->m_cdvdman_command == SCECdFuncStandby && s->m_last_error ==
SCECdErTRMOPN )
3939 1,
"Intr call func_num: %d Err= %02x OnTout= %d\n", g_cdvdman_cmdfunc, (u8)s->m_last_error, s->m_last_read_timeout);
3940 if ( !s->m_scmd_flag )
3942 cdvdman_write_scmd(s);
3945 (((u8)s->m_last_error ==
SCECdErREAD && g_cdvdman_cmdfunc == SCECdFuncRead)
3946 || ((u8)s->m_last_error ==
SCECdErABRT && s->m_last_read_timeout && g_cdvdman_last_cmdfunc == SCECdFuncRead))
3947 && !g_cdvdman_minver_20200 && !s->m_stream_flag && !s->m_dvd_flag && !s->m_recover_status
3950 s->m_sync_error = 0;
3951 s->m_interupt_read_state = 0;
3952 if ( s->m_dec_mode_set )
3954 s->m_dec_mode_last_set = 1;
3958 VERBOSE_KPRINTF(1,
"dec mode 0x00\n");
3959 s->m_read_chunk_reprocial_32 = 1 + (0x20 / ((!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk));
3960 s->m_dintrlsn = (s->m_read_lsn < 0x61) ? (s->m_read_lsn + s->m_read_sectors + 48) : (s->m_read_lsn - 80);
3962 if ( !sceCdRead0_Rty(
3964 (!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk,
3967 (u8)s->m_cdvdman_command,
3972 s->m_recover_status = 0;
3976 ext_passthrough = 1;
3980 if ( !ext_passthrough )
3982 char dev5_reg_013_masked;
3984 VERBOSE_KPRINTF(1,
"Recover_Stat:%d\n", s->m_recover_status);
3985 dev5_reg_013_masked = dev5_mmio_hwport->m_dev5_reg_013 & 0xF;
3986 if ( dev5_reg_013_masked )
3990 && !s->m_recover_status && !s->m_stream_flag && g_cdvdman_cmdfunc != 9 && g_cdvdman_cmdfunc != SCECdFuncReadCDDA
3991 && (
unsigned int)s->m_read_mode.
trycount - 1 >= 4 )
3993 s->m_sync_error = 0;
3994 s->m_interupt_read_state = 0;
3995 if ( s->m_dec_mode_set )
3997 s->m_dec_mode_last_set = 2;
4001 VERBOSE_KPRINTF(1,
"dec mode 0x01\n");
4003 cdrmode.
spindlctrl = dev5_reg_013_masked + 13;
4005 if ( sceCdRead0_Rty(
4010 (u8)s->m_cdvdman_command,
4012 s->m_read_callback) )
4021 s->m_last_read_timeout = 0;
4022 switch ( s->m_recover_status )
4025 s->m_sync_error = 0;
4026 s->m_interupt_read_state = 0;
4031 (!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk,
4034 (u8)s->m_cdvdman_command,
4039 s->m_recover_status = 0;
4043 ext_passthrough = 1;
4047 s->m_sync_error = 0;
4048 s->m_interupt_read_state = 0;
4050 s->m_read_lsn, s->m_read_sectors, s->m_read_buf, &s->m_read_mode, s->m_read_chunk, s->m_read_callback) )
4053 s->m_recover_status = 3;
4057 s->m_recover_status = 0;
4060 s->m_recover_status = 0;
4066 if ( ext_passthrough )
4069 s->m_dintrlsn += s->m_read_sectors;
4070 s->m_read_chunk_reprocial_32 -= 1;
4071 s->m_recover_status = (!s->m_read_chunk_reprocial_32) ? 2 : 1;
4074 if ( s->m_dec_state )
4078 if ( (s->m_read2_flag == 1 || s->m_read2_flag == 3) && !s->m_use_toc )
4080 VERBOSE_KPRINTF(1,
"call Read2intrCDVD()\n");
4081 Read2intrCDVD(s->m_read2_flag);
4083 s->m_sync_error = 0;
4084 s->m_interupt_read_state = 0;
4085 if ( s->m_dec_state == 2 )
4089 if ( s->m_stream_flag == 1 && !s->m_use_toc && !s->m_read2_flag )
4091 if ( g_cdvdman_cdstm0cb )
4093 g_cdvdman_cdstm0cb(1);
4097 VERBOSE_KPRINTF(1,
"Intr func0 no seting");
4100 if ( !s->m_read2_flag )
4102 if ( s->m_stream_flag == 2 && !s->m_use_toc )
4104 if ( g_cdvdman_cdstm1cb )
4106 g_cdvdman_cdstm1cb(1);
4110 VERBOSE_KPRINTF(1,
"Intr func1 no seting");
4115 g_cdvdman_readptr = 0;
4120 1,
"Intr call user callback func_addr %08x num %d flg %d\n", g_cdvdman_user_cb, g_cdvdman_cmdfunc, s->m_read2_flag);
4121 if ( g_cdvdman_user_cb && g_cdvdman_cmdfunc && !s->m_read2_flag && !s->m_use_toc )
4125 cmdfunc_tmp = g_cdvdman_cmdfunc;
4126 g_cdvdman_cmdfunc = 0;
4127 if ( cmdfunc_tmp == 14 || cmdfunc_tmp == 9 )
4129 cmdfunc_tmp = SCECdFuncRead;
4131 g_cdvdman_user_cb(cmdfunc_tmp);
4133 if ( !g_cdvdman_user_cb )
4135 g_cdvdman_cmdfunc = 0;
4140static int intrh_cdrom(
void *userdata)
4144#ifdef CDVD_VARIANT_XOSD
4149 USE_DEV5_MMIO_HWPORT();
4153#ifdef CDVD_VARIANT_XOSD
4154 if ( s->m_cd_mode_ps2_atapi == 1 )
4156 int spd_intr_stat_cur;
4157 int atapi_intr_reason;
4159 VERBOSE_KPRINTF(1,
"Atapi Intr Called %d\n", g_cdvdman_debug_atapi_intr++);
4160 condaddr5 = (
unsigned int)GetBaseAddress(5) == 0x1F402000;
4161 set_cdvd_dev5_base_addr_atapi(1);
4162 (void)*(vu16 *)0xBF410028;
4163 set_cdvd_dev5_base_addr_atapi(2);
4164 atapi_intr_reason = dev5_mmio_hwport->m_dev5_reg_008;
4165 if ( (atapi_intr_reason & 1) )
4168 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4169 VERBOSE_KPRINTF(1,
"ATAPI DRAGON CMDCMPL Interrupt\n");
4171 if ( atapi_intr_reason & 4 )
4173 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4175 iSetEventFlag(g_cdvdman_intr_evfid, 4);
4176 iSetEventFlag(g_cdvdman_intr_evfid, 0x10);
4177 set_cdvd_dev5_base_addr_atapi(1);
4178 VERBOSE_KPRINTF(1,
"ATAPI POFFRDY Interrupt\n");
4179 if ( g_cdvdman_power_off_callback )
4181 g_cdvdman_power_off_callback(g_cdvdman_power_off_callback_userdata);
4183 set_cdvd_dev5_base_addr_atapi(2);
4185 if ( (atapi_intr_reason & 8) )
4188 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4189 if ( !s->m_medium_removal_state )
4191 s->m_atapi_disk_ejected = 0;
4193 set_cdvd_dev5_base_addr_atapi(1);
4194 VERBOSE_KPRINTF(1,
"ATAPI EJECT Interrupt\n");
4195 if ( s->m_cd_atapi_intr_callback && !s->m_medium_removal_state )
4197 VERBOSE_KPRINTF(1,
"EJECT Stop Call\n");
4198 s->m_cd_atapi_intr_callback(1);
4200 iSetEventFlag(g_cdvdman_intr_evfid, 0x40);
4201 if ( g_cdvdman_atapi_eject_bs_power_callback )
4203 VERBOSE_KPRINTF(1,
"ATAPI EJECT Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4204 g_cdvdman_atapi_eject_bs_power_callback(1, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4206 set_cdvd_dev5_base_addr_atapi(2);
4208 if ( (atapi_intr_reason & 0x10) )
4210 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4212 set_cdvd_dev5_base_addr_atapi(1);
4213 VERBOSE_KPRINTF(1,
"ATAPI BS_Power DET Interrupt\n");
4214 iSetEventFlag(g_cdvdman_intr_evfid, 0x80);
4215 if ( g_cdvdman_atapi_eject_bs_power_callback )
4217 VERBOSE_KPRINTF(1,
"ATAPI BS_Power Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4218 g_cdvdman_atapi_eject_bs_power_callback(2, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4221 set_cdvd_dev5_base_addr_atapi(1);
4222 if ( g_cdvdman_vernotxxx1x && conds1 )
4224 *(vu16 *)0xBF41002A &= ~0x100;
4225 *(vu16 *)0xBF41002A |= 0x100;
4226 (void)*(vu16 *)0xBF41002A;
4228 spd_intr_stat_cur = *(vu16 *)0xBF410028;
4231 "Atapi Intr Mode:%d addr:%08x Reason:%02x SPD_INTR_STAT %x\n",
4232 s->m_cd_mode_ps2_atapi,
4233 s->m_cd_atapi_intr_callback,
4236 if ( (spd_intr_stat_cur & 3) && (*g_cdvdreg_bf80146c & 4) )
4238 if ( s->m_cd_atapi_intr_callback )
4240 s->m_cd_atapi_intr_callback(0);
4241 VERBOSE_KPRINTF(1,
"Atapi Intr called\n");
4243 if ( !s->m_scmd_flag )
4245 VERBOSE_KPRINTF(1,
"Intr call set_prev_command.\n");
4246 set_cdvd_dev5_base_addr_atapi(2);
4247 cdvdman_write_scmd(s);
4248 set_cdvd_dev5_base_addr_atapi(1);
4253 if ( (*g_cdvdreg_bf80146c & 4) )
4255 VERBOSE_KPRINTF(1,
"No_Reason Intr\n");
4259 VERBOSE_KPRINTF(1,
"already 9611 Power Off Intr\n");
4264 set_cdvd_dev5_base_addr_atapi(2);
4265 VERBOSE_KPRINTF(1,
"Cur PS2 IO Intr Called\n");
4269 VERBOSE_KPRINTF(1,
"Dragon Intr Called\n");
4270 condaddr5 = (
unsigned int)GetBaseAddress(5) == 0xBF410000;
4273 set_cdvd_dev5_base_addr_atapi(2);
4276 s->m_waf_set_test = s->m_wait_flag;
4279 s->m_last_error = dev5_mmio_hwport->m_dev5_reg_006;
4281 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 1) )
4283 s->m_waf_set_test = (!(dev5_mmio_hwport->m_dev5_reg_005 & 1)) ? 1 : -1;
4284 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4287 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 4) )
4289 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4290 iSetEventFlag(g_cdvdman_intr_evfid, 4);
4291 iSetEventFlag(g_cdvdman_intr_evfid, 0x10);
4293 VERBOSE_KPRINTF(1,
"PS2 POWER OFF Interrupt\n");
4294 if ( g_cdvdman_power_off_callback )
4296 g_cdvdman_power_off_callback(g_cdvdman_power_off_callback_userdata);
4305 s->m_waf_set_test = 1;
4306 s->m_ncmd_intr_count += 1;
4307 dev5_mmio_hwport->m_dev5_reg_008 = 2;
4309#ifdef CDVD_VARIANT_XOSD
4310 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 8) )
4312 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4313 VERBOSE_KPRINTF(1,
"PS2 EJECT Interrupt\n");
4314 iSetEventFlag(g_cdvdman_intr_evfid, 0x40);
4315 if ( !s->m_medium_removal_state )
4317 s->m_atapi_disk_ejected = 0;
4319 if ( g_cdvdman_atapi_eject_bs_power_callback )
4321 VERBOSE_KPRINTF(1,
"PS2 EJECT Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4322 g_cdvdman_atapi_eject_bs_power_callback(1, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4325 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 0x10) )
4327 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4328 VERBOSE_KPRINTF(1,
"PS2 BS_Power DET Interrupt\n");
4329 iSetEventFlag(g_cdvdman_intr_evfid, 0x80);
4330 if ( g_cdvdman_atapi_eject_bs_power_callback )
4332 VERBOSE_KPRINTF(1,
"PS2 BS_Power Callback %p\n", g_cdvdman_atapi_eject_bs_power_callback);
4333 g_cdvdman_atapi_eject_bs_power_callback(2, g_cdvdman_atapi_eject_bs_power_callback_userdata);
4337 iReferEventFlagStatus(g_cdvdman_intr_evfid, &efinfo);
4341 VERBOSE_KPRINTF(1,
"Now DMA Working evfid:%08x\n", efinfo.
currBits);
4344 s->m_drive_interupt_request = 1;
4345#ifdef CDVD_VARIANT_XOSD
4348 set_cdvd_dev5_base_addr_atapi(1);
4358 intr_cb_res = cdvdman_intr_cb(s);
4359#ifdef CDVD_VARIANT_XOSD
4362 set_cdvd_dev5_base_addr_atapi(1);
4368static u32 cdvdman_l1start(
const u8 *
toc)
4370 return toc[23] + (
toc[22] << 8) + (
toc[21] << 16) - 0x30000 + 1;
4373static int DvdDual_infochk(
void)
4375#ifdef CDVD_VARIANT_OSD
4377 if (
QueryIntrContext() || !(cdvdman_mediactl(3) || (u8)g_cdvdman_istruct.m_opo_or_para == 0xFF) )
4379 if (
QueryIntrContext() || !(cdvdman_mediactl(4) || (u8)g_cdvdman_istruct.m_opo_or_para == 0xFF) )
4384 g_cdvdman_istruct.m_use_toc = 1;
4385 if ( !cdvdman_gettoc(g_cdvdman_ptoc) )
4387 g_cdvdman_istruct.m_use_toc = 0;
4388 g_cdvdman_istruct.m_opo_or_para = -1;
4391 g_cdvdman_istruct.m_use_toc = 0;
4392 g_cdvdman_istruct.m_layer_1_lsn = cdvdman_l1start(g_cdvdman_ptoc);
4393 g_cdvdman_istruct.m_opo_or_para = ((g_cdvdman_ptoc[14] & 0x60)) ? (((g_cdvdman_ptoc[14] & 0x10)) ? 2 : 1) : 0;
4394 if ( g_cdvdman_istruct.m_dual_layer_emulation )
4396 VERBOSE_KPRINTF(1,
"CDVD:DualEmuON\n");
4397 g_cdvdman_istruct.m_layer_1_lsn = g_cdvdman_istruct.m_current_dvd_lsn;
4398 g_cdvdman_istruct.m_opo_or_para = 0;
4402 "DvdDual_info: %02x\tLayer1_LSN:%d opo_or_para %d\n",
4404 g_cdvdman_istruct.m_layer_1_lsn,
4405 (u8)g_cdvdman_istruct.m_opo_or_para);
4409static u32 sceCdLsnDualChg(u32 lsn)
4411 int layer_disk_needed;
4416 layer_disk_needed = 2;
4418 if ( cdvdman_isdvd() && DvdDual_infochk() )
4420 if ( g_cdvdman_istruct.m_dual_layer_emulation )
4422 if ( !g_cdvdman_istruct.m_current_dvd && lsn >= g_cdvdman_istruct.m_current_dvd_lsn )
4424 layer_disk_needed = 1;
4426 if ( g_cdvdman_istruct.m_current_dvd && lsn < g_cdvdman_istruct.m_current_dvd_lsn )
4428 layer_disk_needed = 0;
4430 if ( layer_disk_needed == 2 )
4432 change_lsn = lsn - ((g_cdvdman_istruct.m_current_dvd) ? g_cdvdman_istruct.m_current_dvd_lsn : 0);
4439 VERBOSE_KPRINTF(0,
"CDVD: Exchange it for the Layer_%d_Disk Please.\n", layer_disk_needed);
4447 g_cdvdman_istruct.m_use_toc = 1;
4448 while ( layer_disk_needed != 2 )
4450 if ( cdvdman_isdvd() )
4454 read0_result = sceCdRead0(0xE, 1, g_cdvdman_ptoc, &cdrmode, 0, 0);
4456 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO || read0_result )
4460 for ( i = 0; i < 20; i += 1 )
4462 if ( g_cdvdman_ptoc[i + 104] != g_masterdisc_header[i] )
4467 if ( i == 20 && g_cdvdman_ptoc[131] == 2 && (g_cdvdman_ptoc[132] & 2) )
4469 if ( layer_disk_needed == g_cdvdman_ptoc[133] )
4471 g_cdvdman_istruct.m_current_dvd = layer_disk_needed;
4472 layer_disk_needed = 2;
4476 VERBOSE_KPRINTF(0,
"CDVD: Layer_%d Disk not Found\n", layer_disk_needed);
4477 VERBOSE_KPRINTF(0,
"CDVD: Exchange it for the Layer_%d_Disk Please.\n", layer_disk_needed);
4478 if ( !g_cdvdman_istruct.m_current_dvd && lsn >= g_cdvdman_istruct.m_current_dvd_lsn )
4480 layer_disk_needed = 1;
4490 VERBOSE_KPRINTF(0,
"CDVD: Not Master Disk %s\n", (
const char *)&g_cdvdman_ptoc[i + 104]);
4499 VERBOSE_KPRINTF(1,
"CDVD: LsnDualChg Read Error %02x, %d\n", (u8)g_cdvdman_istruct.m_last_error, 0);
4504 vDelayThread(16000);
4507 change_lsn = lsn - ((g_cdvdman_istruct.m_current_dvd) ? g_cdvdman_istruct.m_current_dvd_lsn : 0);
4508 g_cdvdman_istruct.m_use_toc = 0;
4515 lsn - ((g_cdvdman_istruct.m_opo_or_para && (lsn >= (u32)g_cdvdman_istruct.m_layer_1_lsn)) ? 0x10 : 0);
4519 if ( has_change_lsn )
4521 VERBOSE_KPRINTF(1,
"CDVD: sceCdLsnDualChg lsn %d: change lsn %d\n", lsn, change_lsn);
4523 return has_change_lsn ? change_lsn : lsn;
4534 g_cdvdman_istruct.m_dual_layer_emulation = 0;
4535#ifndef CDVD_VARIANT_XOSD
4536 if ( !cdvdman_isdvd() )
4541 if ( !g_cdvdman_emudvd9 )
4543 if ( !DvdDual_infochk() )
4547 *on_dual = !!g_cdvdman_istruct.m_opo_or_para;
4548 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4551#ifdef CDVD_VARIANT_OSD
4552 if ( !cdvdman_isdvd() )
4557#ifndef CDVD_VARIANT_XOSD
4558 if ( g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF )
4566 read0_result = sceCdRead0(0xE, 1, g_cdvdman_ptoc, &cdrmode, 0, 0);
4568 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO && !read0_result )
4570 VERBOSE_KPRINTF(1,
"CDVD: ReadDvdDualInfo Read Error %02x, %d\n", (u8)g_cdvdman_istruct.m_last_error, 0);
4573 for ( i = 0; i < 20; i += 1 )
4575 if ( g_cdvdman_ptoc[i + 104] != g_masterdisc_header[i] )
4582 if ( !DvdDual_infochk() )
4586 *on_dual = !!g_cdvdman_istruct.m_opo_or_para;
4587 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4590 if ( g_cdvdman_ptoc[131] != 2 || !(g_cdvdman_ptoc[132] & 2) )
4594 g_cdvdman_istruct.m_current_dvd = g_cdvdman_ptoc[133];
4595 g_cdvdman_istruct.m_current_dvd_lsn =
4596 g_cdvdman_ptoc[134] + (g_cdvdman_ptoc[135] << 8) + (g_cdvdman_ptoc[136] << 16) + (g_cdvdman_ptoc[137] << 24) + 1;
4597 g_cdvdman_istruct.m_opo_or_para = 0;
4598 g_cdvdman_istruct.m_layer_1_lsn = g_cdvdman_istruct.m_current_dvd_lsn;
4599 g_cdvdman_istruct.m_dual_layer_emulation = 1;
4601 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
4604 "sceCdReadDvdDualInfo():Cur_Disk %d layer1_start %d\n",
4605 (u8)g_cdvdman_istruct.m_current_dvd,
4606 g_cdvdman_istruct.m_current_dvd_lsn);
4610int sceCdSC(
int code,
int *param)
4616#ifdef CDVD_VARIANT_XOSD
4622#ifdef CDVD_VARIANT_XOSD
4625 set_cdvd_dev5_base_addr_atapi(2);
4626 regval = ((vu8 *)(0xBF402000))[*param];
4627 set_cdvd_dev5_base_addr_atapi(1);
4632 *param = (int)&g_cdvdman_istruct.m_chgsys_writer_drive_shell_is_open;
4636 return sc_ffffffd8((u32 *)param);
4639 *param = (int)&g_cdvdman_istruct.m_atapi_disk_ejected;
4643 return get_disk_type_ex();
4646 *(&g_cdvdman_istruct.m_var_sc_ffffffdb) = (
int)param;
4650 return g_cdvdman_vernotxxx1x;
4652 return get_cdvd_register(*param);
4654 g_adma_evfid = *param;
4657 g_acmd_evfid = *param;
4661 g_cdvdman_istruct.m_chgsys_callback = (
void *)(
int)param;
4665 g_cd_atapi_evfid = *param;
4669 g_cdvdman_istruct.m_cd_atapi_intr_callback = (
void *)(
int)param;
4675 *param = (int)g_cdvdman_power_off_callback;
4676 poffarg_tmp = g_cdvdman_power_off_callback_userdata;
4678 return (
int)poffarg_tmp;
4680 return g_scmd_evfid;
4682 return sceCdLsnDualChg(*param);
4684 return DvdDual_infochk();
4686 g_cdvdman_istruct.m_last_read_timeout = *param;
4689 return g_cdvdman_stream_timeout;
4691 *param = (int)&g_verbose_level;
4694 return g_cdvdman_sync_timeout;
4696 *param = (int)&g_cdvdman_istruct;
4699 BootMode = QueryBootMode(4);
4700 switch ( BootMode ? *(u8 *)BootMode : 0xFF )
4705 g_cdvdman_mmode = 0xFF;
4708 g_cdvdman_mmode = SCECdMmodeCd;
4715#ifdef CDVD_VARIANT_OSD
4725 return g_cdvdman_mmode == SCECdMmodeCd || g_cdvdman_mmode == 0xFF;
4727 return g_cdvdman_mmode == SCECdMmodeDvd || g_cdvdman_mmode == 0xFF;
4729 return g_cdvdman_mmode == 0xFF;
4735 return g_cdvdman_intr_evfid;
4739 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
4743 SetEventFlag(g_fio_fsv_evfid, 1);
4745 g_cdvdman_ee_rpc_fno = *param;
4746 VERBOSE_KPRINTF(1,
"EE_ncmd_working code= %d\n", *param);
4747 return g_cdvdman_ee_rpc_fno;
4749 return (u16)_irx_id.v;
4751 g_cdvdman_spinctl = *param;
4754 return g_cdvdman_cd36key;
4756 return g_cdvdman_istruct.m_read2_flag;
4758 g_cdvdman_istruct.m_last_error = *(u8 *)param;
4759 return (u8)g_cdvdman_istruct.m_last_error;
4764 *param = (u8)g_cdvdman_istruct.m_last_error;
4767 g_cdvdman_istruct.m_stream_flag = code;
4769 return g_cdvdman_istruct.m_stream_flag;
4771 VERBOSE_KPRINTF(1,
"sceCdSC func_num Not found %d\n", code);
4776static void cdvdman_init(
void)
4782#ifdef CDVD_VARIANT_XOSD
4785 USE_DEV5_MMIO_HWPORT();
4787#ifdef CDVD_VARIANT_XOSD
4791 g_cdvdman_istruct.m_cd_mode_ps2_atapi = 2;
4792 cdvdman_change_drive(2);
4796 g_cdvdman_user_cb = 0;
4797 g_cdvdman_power_off_callback = 0;
4798 g_cdvdman_cmdfunc = 0;
4799 g_cdvdman_istruct.m_drive_interupt_request = 0;
4803 sceCdSC(0xFFFFFFF3, &scres_unused);
4804 dmac_set_dpcr(dmac_get_dpcr() | 0x8000);
4805 dmac_ch_set_chcr(3, 0);
4806#ifdef CDVD_VARIANT_XOSD
4807 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 0x10) )
4809 dev5_mmio_hwport->m_dev5_reg_008 = 0x10;
4811 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 8) )
4813 dev5_mmio_hwport->m_dev5_reg_008 = 8;
4816 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 4) )
4818 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4820 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 1) )
4822 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4824#ifndef CDVD_VARIANT_XOSD
4827 g_cdvdman_istruct.m_tray_is_open = !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen);
4828#ifdef CDVD_VARIANT_XOSD
4832 BootMode = QueryBootMode(6);
4833 g_cdvdman_istruct.m_no_dec_flag = BootMode ? ((*(u16 *)BootMode & 0xFFFC) == 0x60) : 0;
4838#ifdef CDVD_VARIANT_XOSD
4847 for ( i = 0; i <= 60 && (!(MediumRemoval =
sceCdGetMediumRemoval(&medium_res, &argres)) || argres); i += 1 )
4851 g_cdvdman_istruct.m_medium_removal_state = (MediumRemoval && !argres) ? medium_res : 0;
4857 g_cdvdman_istruct.m_cd_mode_ps2_atapi =
4858 (chgsys_tmp || (!(dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && dev5_mmio_hwport->m_dev5_reg_00F != 6)) ? 2 : 1;
4859 cdvdman_change_drive(g_cdvdman_istruct.m_cd_mode_ps2_atapi);
4872 VERBOSE_PRINTF(1,
"sceCdInit called mode= %d\n", mode);
4877 g_cdvdman_istruct.m_cd_inited = 0;
4878#ifndef CDVD_VARIANT_XOSD
4881 cdvdman_ncmd_sender_06();
4884 VERBOSE_PRINTF(1,
"Cdvdman Exit\n");
4892 VERBOSE_PRINTF(1,
"Cdvdman Init\n");
4893 g_cdvdman_istruct.m_read2_flag = 0;
4894 g_cdvdman_istruct.m_dec_shift = 0;
4895 g_cdvdman_istruct.m_check_version = 0;
4896 g_cdvdman_istruct.m_dec_state = 0;
4897#ifdef CDVD_VARIANT_XOSD
4898 if ( update_cd_mode_ps2_atapi() != 1 )
4904 g_cdvdman_istruct.m_cd_inited = 1;
4908 u8 ready_status_tmp;
4911 ready_status_tmp = 0;
4912 VERBOSE_PRINTF(1,
"sceCdInit Ready check start.\n");
4914 while ( (ready_status & 0xC0) != 0x40 )
4916#ifdef CDVD_VARIANT_XOSD
4919 g_cdvdman_istruct.m_field_0DC = 0;
4924 vDelayThread(10000);
4925 if ( ready_status != ready_status_tmp )
4927 ready_status_tmp = ready_status;
4928 VERBOSE_PRINTF(1,
"sceCdInit Dev5 Status %x\n", ready_status);
4931 VERBOSE_PRINTF(1,
"sceCdInit Ready check %x\n", ready_status);
4933 VERBOSE_PRINTF(1,
"sceCdInit Ready check end.\n");
4935 g_cdvdman_istruct.m_wait_flag = 1;
4936 g_cdvdman_istruct.m_scmd_flag = 1;
4937 g_cdvdman_istruct.m_last_error =
SCECdErNO;
4938 g_cdvdman_istruct.m_last_read_timeout = 0;
4939 g_cdvdman_spinctl = -1;
4940 SetEventFlag(g_cdvdman_intr_evfid, 0x29);
4941 SetEventFlag(g_ncmd_evfid, 1);
4942 SetEventFlag(g_scmd_evfid, 1);
4943 SetEventFlag(g_sfile_evfid, 1);
4947static int set_prev_command(
int cmd,
const char *sdata,
int sdlen,
char *rdata,
int rdlen,
int check_sef)
4953#ifdef CDVD_VARIANT_XOSD
4957#ifdef CDVD_VARIANT_XOSD
4965 VERBOSE_KPRINTF(1,
"set_prev_command cmd %02x call\n", cmd);
4968 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
4971 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
4974 VERBOSE_KPRINTF(1,
"set_prev_command Double Booking\n");
4975#ifdef CDVD_VARIANT_XOSD
4978 SetEventFlag(g_cdvdman_csys_evfid, 1);
4983 g_cdvdman_istruct.m_scmd = cmd;
4984 g_cdvdman_istruct.m_sdlen = sdlen;
4985 g_cdvdman_istruct.m_rdlen = rdlen;
4986 for ( i = 0; i < sdlen; i += 1 )
4988 g_cdvdman_istruct.m_scmd_sd[i] = sdata[i];
4990#ifdef CDVD_VARIANT_XOSD
4991 if ( update_cd_mode_ps2_atapi() != 1 )
4994 if ( g_cdvdman_istruct.m_wait_flag )
4996 g_cdvdman_istruct.m_scmd_flag = 1;
4997 cdvdman_write_scmd(&g_cdvdman_istruct);
5001 while ( (dmac_ch_get_chcr(3) & 0x1000000) && !g_cdvdman_istruct.m_wait_flag )
5003 VERBOSE_KPRINTF(1,
"set_prev_command: DMA Wait\n");
5005 g_cdvdman_istruct.m_scmd_flag = 1;
5006 cdvdman_write_scmd(&g_cdvdman_istruct);
5010 g_cdvdman_istruct.m_scmd_flag = 0;
5013#ifdef CDVD_VARIANT_XOSD
5018 if ( g_cd_atapi_evfid != -1 )
5020 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
5022 if ( g_adma_evfid != -1 )
5024 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5026 if ( g_acmd_evfid != -1 )
5028 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5035 set_cdvd_dev5_base_addr_atapi(2);
5036 g_cdvdman_istruct.m_scmd_flag = 1;
5037 VERBOSE_KPRINTF(1,
"do_set_prev_command %02x\n", cmd);
5038 cdvdman_write_scmd(&g_cdvdman_istruct);
5039 set_cdvd_dev5_base_addr_atapi(1);
5044 if ( g_acmd_evfid != -1 )
5046 SetEventFlag(g_acmd_evfid, 1);
5048 if ( g_adma_evfid != -1 )
5050 SetEventFlag(g_adma_evfid, 1);
5052 if ( g_cd_atapi_evfid != -1 )
5054 SetEventFlag(g_cd_atapi_evfid, 3);
5060 for ( i = 0; i < 500; i += delaybackoff )
5062 if ( g_cdvdman_istruct.m_scmd_flag )
5064 for ( j = 0; j < rdlen; j += 1 )
5066 rdata[j] = g_cdvdman_istruct.m_scmd_rd[j];
5068 if ( check_sef == 1 )
5070 vSetEventFlag(g_scmd_evfid, 1);
5072#ifdef CDVD_VARIANT_XOSD
5073 VERBOSE_KPRINTF(1,
"set_prev_command end :%02x\n", (u8)g_cdvdman_istruct.m_scmd);
5076 SetEventFlag(g_cdvdman_csys_evfid, 1);
5079 return (u8)g_cdvdman_istruct.m_scmd;
5081 vDelayThread(1000 * delaybackoff);
5082 if ( (i & 1) && delaybackoff < 16 )
5087 g_cdvdman_istruct.m_scmd_flag = 1;
5088 if ( check_sef == 1 )
5090 vSetEventFlag(g_scmd_evfid, 1);
5101 USE_DEV5_MMIO_HWPORT();
5104 VERBOSE_KPRINTF(1,
"in:%d out_size:%d \n", (u8)s->m_sdlen, (u8)s->m_rdlen);
5106 VERBOSE_KPRINTF(1,
"cmd:%02x pram:%02x\n", (u8)s->m_scmd, (u8)s->m_scmd_sd[0]);
5107 for ( i = 0; i <= 0; i += 1 )
5110#ifdef CDVD_VARIANT_XOSD
5114 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5119 VERBOSE_KPRINTF(1,
"do_set_prev_command BUSY ABNORM END %08x\n", dev5_mmio_hwport->m_dev5_reg_017);
5122 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5126 for ( j = 0; j < (u8)s->m_sdlen; j += 1 )
5128 dev5_mmio_hwport->m_dev5_reg_017 = s->m_scmd_sd[j];
5130 dev5_mmio_hwport->m_dev5_reg_016 = s->m_scmd;
5131#ifdef CDVD_VARIANT_XOSD
5139#ifdef CDVD_VARIANT_XOSD
5145 for ( j = 0; dev5_mmio_hwport->m_dev5_reg_017 & 0x80; j += 1 )
5157 for ( j = 0; dev5_mmio_hwport->m_dev5_reg_017 & 0x80; j += 1 )
5163 VERBOSE_KPRINTF(1,
"Mecacon Scmd TIMEOUT CMD= %02x\n", (u8)s->m_scmd);
5171 for ( j = 0; j < (u8)s->m_rdlen; j += 1 )
5173 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5177 rdptr1[j] = dev5_mmio_hwport->m_dev5_reg_018;
5179 if ( j >= (u8)s->m_rdlen )
5182 VERBOSE_KPRINTF(1,
"Prev Cmd Result Over Flow\n", rdptr1);
5185 if ( (!overflowcond && j >= (u8)s->m_rdlen) || s->m_rdlen == 16 )
5189 VERBOSE_KPRINTF(1,
"Prev Cmd Result Illegal Size Try count:%d\n", i);
5198 for ( j = 0; j < (
sizeof(s->m_scmd_rd) /
sizeof(s->m_scmd_rd[0])); j += 1 )
5200 s->m_scmd_rd[j] = 0;
5202 if ( s->m_rdlen != (
sizeof(s->m_scmd_rd) /
sizeof(s->m_scmd_rd[0])) )
5204 rdcnt = (u8)s->m_rdlen;
5206 for ( j = 0; j < rdcnt; j += 1 )
5208 s->m_scmd_rd[j] = rdptr1[j];
5215#ifdef CDVD_VARIANT_XOSD
5216static int cdvdman_write_scmd_swap_dev5(
char cmd,
const char *wdata,
int sdlen,
char *rdata,
int rdlen,
int check_sef)
5224 USE_DEV5_MMIO_HWPORT();
5226 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5231 atapi_check = update_cd_mode_ps2_atapi() == 1;
5234 set_cdvd_dev5_base_addr_atapi(2);
5236 for ( i = 0; i <= 0; i += 1 )
5240 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5244 set_cdvd_dev5_base_addr_atapi(1);
5247 if ( check_sef == 1 )
5249 vSetEventFlag(g_scmd_evfid, 1);
5253 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5257 for ( j = 0; j < sdlen; j += 1 )
5259 dev5_mmio_hwport->m_dev5_reg_017 = wdata[j];
5261 dev5_mmio_hwport->m_dev5_reg_016 = cmd;
5262 while ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5267 for ( j = 0; !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40); j += 1 )
5272 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Over Flow\n");
5275 rdstart[j] = dev5_mmio_hwport->m_dev5_reg_018;
5277 if ( (!cmdresoverflow && j >= rdlen) || rdlen == 16 )
5281 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Illegal Size Try count:%d\n", i);
5282 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x20) )
5286 for ( j = 0; j < 16 - rdlen; j += 1 )
5294 set_cdvd_dev5_base_addr_atapi(1);
5297 if ( check_sef == 1 )
5299 vSetEventFlag(g_scmd_evfid, 1);
5303 for ( j = 0; j < rdlen; j += 1 )
5305 rdata[j] = rdstart[j];
5309 set_cdvd_dev5_base_addr_atapi(1);
5312 if ( check_sef == 1 )
5314 vSetEventFlag(g_scmd_evfid, 1);
5320static int cdvdman_send_scmd2(
int cmd,
const void *sdata,
int sdlen,
void *rdata,
int rdlen,
int check_sef)
5326 USE_DEV5_MMIO_HWPORT();
5328 if ( check_sef == 1 && vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5332 for ( i = 0; i <= 0; i += 1 )
5336 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5338 if ( check_sef == 1 )
5340 vSetEventFlag(g_scmd_evfid, 1);
5344 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
5348 for ( j = 0; j < sdlen; j += 1 )
5350 dev5_mmio_hwport->m_dev5_reg_017 = ((u8 *)sdata)[j];
5352 dev5_mmio_hwport->m_dev5_reg_016 = cmd;
5353 while ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
5355#ifndef CDVD_VARIANT_XOSD
5360 for ( j = 0; !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40); j += 1 )
5366 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Over Flow\n");
5369 rdstart[j] = dev5_mmio_hwport->m_dev5_reg_018;
5371 if ( (!cmdresoverflow && j >= rdlen) || rdlen == 16 )
5376 VERBOSE_KPRINTF(1,
"Prev Cmd2 Result Illegal Size Try count:%d\n", i);
5377 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x20) )
5381 for ( j = 0; j < 16 - rdlen; j += 1 )
5386 if ( check_sef == 1 )
5388 vSetEventFlag(g_scmd_evfid, 1);
5392 for ( i = 0; i < rdlen; i += 1 )
5394 ((
char *)rdata)[i] = rdstart[i];
5396 if ( check_sef == 1 )
5398 vSetEventFlag(g_scmd_evfid, 1);
5403#ifdef CDVD_VARIANT_OSD
5404static unsigned int signal_sema_timeout_callback(
void *userdata)
5408 sema_id = (int)(u32)(uiptr)userdata;
5409 iSignalSema(sema_id);
5418#ifdef CDVD_VARIANT_OSD
5419 if ( g_cdvdman_minver_50000 )
5421 WaitSema(g_cdvdman_apply_scmd_sema);
5424 for ( i = 0; i <= 2500; i += 1 )
5426 if ( set_prev_command(cmdNum, (
const char *)inBuff, inBuffSize, (
char *)outBuff, 16, 1) )
5428#ifdef CDVD_VARIANT_OSD
5429 if ( g_cdvdman_minver_50000 )
5435 SetAlarm(&sysclk, signal_sema_timeout_callback, (
void *)g_cdvdman_apply_scmd_sema);
5446 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5450int sceCdApplySCmd2(u8 cmdNum,
const void *inBuff,
unsigned long int inBuffSize,
void *outBuff)
5452#ifdef CDVD_VARIANT_XOSD
5457 for ( i = 0; i <= 2500; i += 1 )
5459 if ( cdvdman_send_scmd2(cmdNum, inBuff, inBuffSize, outBuff, 16, 1) )
5465 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5470#ifdef CDVD_VARIANT_OSD
5471int sceCdApplySCmd3(u8 cmdNum,
const void *inBuff,
unsigned long int inBuffSize,
void *outBuff)
5475 for ( i = 0; i <= 2500; i += 1 )
5478 if ( set_prev_command((u8)cmdNum, inBuff, inBuffSize, outBuff, 16, 1) )
5484 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
5494 USE_DEV5_MMIO_HWPORT();
5496 if ( PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5504 "Break call: read2_flg= %d func= %d lsn= %d csec= %d nsec= %d %rsec= %d addr= %p waitflg= %d, DriveIntrReq= %d "
5505 "stmflg= %d recover= %d\n",
5506 g_cdvdman_istruct.m_read2_flag,
5508 g_cdvdman_istruct.m_cdvdman_lsn,
5509 g_cdvdman_istruct.m_cdvdman_csec,
5510 g_cdvdman_istruct.m_cdvdman_nsec,
5511 g_cdvdman_istruct.m_cdvdman_rsec,
5512 g_cdvdman_istruct.m_read_buf,
5513 g_cdvdman_istruct.m_wait_flag,
5514 g_cdvdman_istruct.m_drive_interupt_request,
5515 g_cdvdman_istruct.m_stream_flag,
5516 g_cdvdman_istruct.m_recover_status);
5517 if ( g_cdvdman_istruct.m_last_read_timeout )
5519 g_cdvdman_istruct.m_read2_flag = 0;
5522 g_cdvdman_istruct.m_thread_id = GetThreadId();
5523 g_cdvdman_istruct.m_break_cdvdfsv_readchain = 1;
5524 if ( g_cdvdman_istruct.m_dec_state )
5526 g_cdvdman_istruct.m_dec_shift = 0;
5527 g_cdvdman_istruct.m_check_version = 0;
5528 g_cdvdman_istruct.m_dec_state = 0;
5531 g_cdvdman_istruct.m_recover_status = 0;
5534 iSetEventFlag(g_cdvdman_intr_evfid, 0x29);
5535 iCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
5539 SetEventFlag(g_cdvdman_intr_evfid, 0x29);
5540 CancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
5542 if ( !g_cdvdman_istruct.m_wait_flag || g_cdvdman_istruct.m_last_read_timeout )
5547 VERBOSE_KPRINTF(1,
"cdvd: NonInter END\n");
5548 g_cdvdman_istruct.m_wait_flag = 1;
5550 g_cdvdman_last_cmdfunc = g_cdvdman_cmdfunc;
5551 g_cdvdman_cmdfunc = SCECdFuncBreak;
5552 dev5_mmio_hwport->m_dev5_reg_007 = 1;
5553 if ( g_cdvdman_istruct.m_last_read_timeout )
5557 g_cdvdman_istruct.m_drive_interupt_request = 0;
5558 VERBOSE_KPRINTF(1,
"cdvd: Abort command On\n");
5560 vSetEventFlag(g_ncmd_evfid, 1);
5565static unsigned int ncmd_timeout_alarm_cb(
void *userdata)
5570 KPRINTF(
"Cmd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
5575static int intrh_dma_3(
void *userdata)
5582 s->m_dma3_param.m_dma3_msectors -= s->m_dma3_param.m_dma3_csectors;
5586 "_sceCdDmaIntr wk %d: func_num: %d nsec %d cnt %d cdid:%08x\n",
5589 s->m_dma3_param.m_dma3_msectors,
5590 s->m_cdvdman_dma3sec,
5591 &g_cdvdman_istruct);
5592 dmacbres = s->m_dma3_param.m_dma3_callback ? s->m_dma3_param.m_dma3_callback() : 1;
5593 s->m_cdvdman_dma3sec += s->m_dma3_param.m_dma3_csectors;
5594 s->m_dma3_param.m_dma3_csectors = ((u32)s->m_read_chunk > (u32)s->m_dma3_param.m_dma3_msectors) ?
5595 (u32)s->m_dma3_param.m_dma3_msectors :
5596 (u32)s->m_read_chunk;
5599 if ( s->m_dma3_param.m_dma3_msectors )
5601 dmac_ch_set_chcr(3, 0);
5602 dmac_ch_get_chcr(3);
5603 dmac_ch_set_madr(3, (u32)s->m_dma3_param.m_dma3_maddress);
5606 ((s->m_dma3_param.m_dma3_blkcount * s->m_dma3_param.m_dma3_csectors) << 16) | s->m_dma3_param.m_dma3_blkwords);
5607 dmac_ch_set_chcr(3, 0x41000200);
5608 dmac_ch_get_chcr(3);
5609 iClearEventFlag(g_cdvdman_intr_evfid, ~0x20);
5614 iSetEventFlag(g_cdvdman_intr_evfid, 0x20);
5617 if ( !s->m_dma3_param.m_dma3_msectors && s->m_drive_interupt_request )
5620 s->m_drive_interupt_request = 0;
5627 USE_DEV5_MMIO_HWPORT();
5629 if ( (dmac_ch_get_chcr(3) & 0x1000000) )
5631 dev5_mmio_hwport->m_dev5_reg_007 = 1;
5633 g_cdvdman_istruct.m_drive_interupt_request = 0;
5634 g_cdvdman_istruct.m_dma3_param.m_dma3_blkwords = dma3_param->m_dma3_blkwords;
5635 g_cdvdman_istruct.m_dma3_param.m_dma3_blkcount = dma3_param->m_dma3_blkcount;
5636 g_cdvdman_istruct.m_dma3_param.m_dma3_maddress = dma3_param->m_dma3_maddress;
5637 g_cdvdman_istruct.m_dma3_param.m_dma3_callback = dma3_param->m_dma3_callback;
5638 g_cdvdman_istruct.m_dma3_param.m_dma3_csectors = dma3_param->m_dma3_csectors;
5639 g_cdvdman_istruct.m_dma3_param.m_cdvdreg_howto = dma3_param->m_cdvdreg_howto;
5640 g_cdvdman_istruct.m_dma3_param.m_dma3_msectors = dma3_param->m_dma3_msectors;
5641 g_cdvdman_istruct.m_cdvdman_dma3sec = 0;
5642 dmac_ch_set_chcr(3, 0);
5643 dmac_ch_get_chcr(3);
5644 if ( dma3_param->m_dma3_csectors )
5646 vClearEventFlag(g_cdvdman_intr_evfid, ~0x20);
5649 dev5_mmio_hwport->m_dev5_reg_006 = dma3_param->m_cdvdreg_howto;
5650 dmac_ch_set_madr(3, (u32)dma3_param->m_dma3_maddress);
5653 (dma3_param->m_dma3_blkcount * (dma3_param->m_dma3_csectors ? dma3_param->m_dma3_csectors : 1)) << 16
5654 | dma3_param->m_dma3_blkwords);
5655 dmac_ch_set_chcr(3, 0x41000200);
5656 return dmac_ch_get_chcr(3);
5659#ifdef CDVD_VARIANT_XOSD
5660static int update_cd_mode_ps2_atapi(
void)
5662 int is_intr_context;
5663 int saved_cd_mode_ps2_atapi;
5667 if ( is_intr_context )
5671 saved_cd_mode_ps2_atapi = g_cdvdman_istruct.m_cd_mode_ps2_atapi;
5672 if ( saved_cd_mode_ps2_atapi == 1 )
5674 if ( !(*g_cdvdreg_bf801460 & 2) || (
unsigned int)GetBaseAddress(5) != (
unsigned int)0xBF410000 )
5676 set_cdvd_dev5_base_addr_atapi(1);
5681 if ( (*g_cdvdreg_bf801460 & 2) || (
unsigned int)GetBaseAddress(5) != (
unsigned int)0x1F402000 )
5683 set_cdvd_dev5_base_addr_atapi(2);
5686 if ( is_intr_context )
5690 return saved_cd_mode_ps2_atapi;
5694#ifdef CDVD_VARIANT_XOSD
5695static int set_cdvd_dev5_base_addr_atapi(
int mode)
5697 int is_intr_context;
5701 if ( is_intr_context )
5707 SetBaseAddress(5, 0xBF410000);
5708 VERBOSE_KPRINTF(1,
"DEV5-addr : 0x%08lx\n", GetBaseAddress(5));
5709 SetDelay(5, 0xEF101043);
5710 VERBOSE_KPRINTF(1,
"DEV5-dely : 0x%08lx\n", GetDelay(5));
5711 *g_cdvdreg_bf801464 |= 0xC;
5712 *g_cdvdreg_bf801460 |= 0x40;
5713 *g_cdvdreg_bf801460 |= 2;
5717 SetBaseAddress(5, 0x1F402000);
5718 VERBOSE_KPRINTF(1,
"DEV5-addr : 0x%08lx\n", GetBaseAddress(5));
5719 SetDelay(5, 0x6F060011);
5720 VERBOSE_KPRINTF(1,
"DEV5-dely : 0x%08lx\n", GetDelay(5));
5721 *g_cdvdreg_bf801460 &= ~2;
5722 *g_cdvdreg_bf801460 &= ~0x40;
5723 *g_cdvdreg_bf801464 &= 0xF3;
5725 if ( is_intr_context )
5733#ifdef CDVD_VARIANT_XOSD
5734static int cdvdman_change_drive(
int mode)
5736 ClearEventFlag(g_cdvdman_csys_evfid, ~1);
5739 VERBOSE_KPRINTF(1,
"Init Go SCECdChgWriDrv\n");
5740 ClearEventFlag(g_fio_fsv_evfid, ~1);
5741 ClearEventFlag(g_sfile_evfid, ~1);
5742 ClearEventFlag(g_scmd_evfid, ~1);
5743 ClearEventFlag(g_ncmd_evfid, ~1);
5744 set_cdvd_dev5_base_addr_atapi(1);
5745 if ( g_cd_atapi_evfid != -1 )
5747 SetEventFlag(g_cd_atapi_evfid, 3);
5749 if ( g_adma_evfid != -1 )
5751 SetEventFlag(g_adma_evfid, 1);
5753 if ( g_acmd_evfid != -1 )
5755 SetEventFlag(g_acmd_evfid, 1);
5757 SetEventFlag(g_scmd_evfid, 1);
5758 VERBOSE_KPRINTF(1,
"Init Go SCECdChgWriDrv End.\n");
5759 SetEventFlag(g_fio_fsv_evfid, 1);
5763 VERBOSE_KPRINTF(1,
"Init Go SCECdChgPs2Drv\n");
5764 ClearEventFlag(g_scmd_evfid, ~1);
5765 if ( g_acmd_evfid != -1 )
5767 ClearEventFlag(g_acmd_evfid, ~1);
5769 if ( g_adma_evfid != -1 )
5771 ClearEventFlag(g_adma_evfid, ~1);
5773 if ( g_cd_atapi_evfid != -1 )
5775 ClearEventFlag(g_cd_atapi_evfid, ~3);
5777 set_cdvd_dev5_base_addr_atapi(mode);
5778 SetEventFlag(g_ncmd_evfid, 1);
5779 SetEventFlag(g_scmd_evfid, 1);
5780 SetEventFlag(g_sfile_evfid, 1);
5781 SetEventFlag(g_fio_fsv_evfid, 1);
5782 VERBOSE_KPRINTF(1,
"Init Go SCECdChgPs2Drv End.\n");
5784 SetEventFlag(g_cdvdman_csys_evfid, 1);
5789#ifdef CDVD_VARIANT_XOSD
5795 USE_DEV5_MMIO_HWPORT();
5797 VERBOSE_KPRINTF(1,
"sceCdChgSys(%d) start.\n", use_writer_drive);
5802 WaitEventFlag(g_cdvdman_csys_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5803 current_mode = update_cd_mode_ps2_atapi();
5805 1,
"sceCdChgSys %d call mode:%d->%d\n", use_writer_drive, current_mode, g_cdvdman_istruct.m_cd_mode_ps2_atapi);
5806 if ( !use_writer_drive )
5808 g_cdvdman_istruct.m_cd_mode_ps2_atapi = current_mode;
5812 && (use_writer_drive != (u32)current_mode || g_cdvdman_istruct.m_cd_mode_ps2_atapi != current_mode) )
5816 if ( use_writer_drive == 1 )
5818 VERBOSE_KPRINTF(1,
"Go SCECdChgWriDrv\n");
5819 VERBOSE_KPRINTF(1,
"fio_fsv_evfid\n");
5820 WaitEventFlag(g_fio_fsv_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5821 VERBOSE_KPRINTF(1,
"sfile_evfid\n");
5822 WaitEventFlag(g_sfile_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5823 VERBOSE_KPRINTF(1,
"sceCdSync\n");
5825 VERBOSE_KPRINTF(1,
"scmd_evfid\n");
5826 WaitEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5827 VERBOSE_KPRINTF(1,
"ncmd_evfid\n");
5828 WaitEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5829 set_cdvd_dev5_base_addr_atapi(2);
5830 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5831 if ( g_cdvdman_vernotxxx1x )
5835 g_cdvdman_istruct.m_chgsys_writer_drive_shell_is_open = 1;
5838 (!(dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen))
5846 VERBOSE_KPRINTF(1,
"GO->Atapi sceCdChgSpdlCtrl Call %d\n", 0);
5847 while ( !sceCdChgSpdlCtrl(0) )
5855 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl ERR 0x%02x\n", last_err);
5856 DelayThread(250000);
5859 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl OK\n", last_err);
5862 set_cdvd_dev5_base_addr_atapi(1);
5863 g_cdvdman_istruct.m_cd_mode_ps2_atapi = 1;
5865 g_cdvdman_vernotxxx1x && disc_type !=
SCECdNODISC && g_cdvdman_istruct.m_chgsys_callback_next_disktype_last
5866 && g_cdvdman_istruct.m_chgsys_callback )
5871 i < 10 && g_cdvdman_istruct.m_chgsys_callback(&g_cdvdman_istruct.m_chgsys_callback_next_disktype, 1);
5876 g_cdvdman_istruct.m_chgsys_callback_next_disktype_last =
SCECdNODISC;
5878 if ( g_cd_atapi_evfid != -1 )
5880 SetEventFlag(g_cd_atapi_evfid, 3);
5882 if ( g_adma_evfid != -1 )
5884 SetEventFlag(g_adma_evfid, 1);
5886 if ( g_acmd_evfid != -1 )
5888 SetEventFlag(g_acmd_evfid, 1);
5890 SetEventFlag(g_scmd_evfid, 1);
5891 SetEventFlag(g_fio_fsv_evfid, 1);
5892 VERBOSE_KPRINTF(1,
"Go SCECdChgWriDrv End.\n");
5896 VERBOSE_KPRINTF(1,
"Go SCECdChgPs2Drv\n");
5897 VERBOSE_KPRINTF(1,
"scmd_evfid\n");
5898 WaitEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5899 if ( g_acmd_evfid != -1 )
5901 VERBOSE_KPRINTF(1,
"g_acmd_evfid Wait\n");
5902 WaitEventFlag(g_acmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5904 if ( g_adma_evfid != -1 )
5906 VERBOSE_KPRINTF(1,
"g_adma_evfid Wait\n");
5907 WaitEventFlag(g_adma_evfid, 1, WEF_AND | WEF_CLEAR, &efbits);
5909 if ( g_cd_atapi_evfid != -1 )
5911 VERBOSE_KPRINTF(1,
"g_cd_atapi_evfid Wait\n");
5912 WaitEventFlag(g_cd_atapi_evfid, 3, WEF_AND | WEF_CLEAR, &efbits);
5914 VERBOSE_KPRINTF(1,
"evflg Ok\n");
5915 set_cdvd_dev5_base_addr_atapi(1);
5916 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5917 if ( g_cdvdman_vernotxxx1x )
5919 set_cdvd_dev5_base_addr_atapi(2);
5920 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5921 set_cdvd_dev5_base_addr_atapi(1);
5922 VERBOSE_KPRINTF(1,
"GO->PS2 STOP ATAPI SPINDL\n");
5923 if ( disc_type == 6 && g_cdvdman_istruct.m_chgsys_callback )
5928 i < 10 && g_cdvdman_istruct.m_chgsys_callback(&g_cdvdman_istruct.m_chgsys_callback_next_disktype, 0);
5935 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5937 VERBOSE_KPRINTF(1,
"Atapi Set -> Dragon Media %d\n", g_cdvdman_istruct.m_chgsys_callback_next_disktype);
5938 if ( g_cdvdman_istruct.m_chgsys_callback_next_disktype == 256 )
5940 g_cdvdman_istruct.m_chgsys_callback_next_disktype_last = g_cdvdman_istruct.m_chgsys_callback_next_disktype;
5941 g_cdvdman_istruct.m_chgsys_callback_next_disktype = SCECdDETCTDVDD;
5945 set_cdvd_dev5_base_addr_atapi(use_writer_drive);
5946 g_cdvdman_istruct.m_cd_mode_ps2_atapi = use_writer_drive;
5947 disc_type = dev5_mmio_hwport->m_dev5_reg_00F;
5948 if ( g_cdvdman_vernotxxx1x )
5951 ((dev5_mmio_hwport->m_dev5_reg_015 & 0x80) && !(dev5_mmio_hwport->m_dev5_reg_00A &
SCECdStatShellOpen))
5961 g_cdvdman_istruct.m_chgsys_callback_next_disktype =
SCECdDETCT;
5965 "GO->DRAGON sceCdChgSpdlCtrl Call %d Ps2MediaType %02x\n",
5966 g_cdvdman_istruct.m_chgsys_callback_next_disktype,
5968 while ( !sceCdChgSpdlCtrl(g_cdvdman_istruct.m_chgsys_callback_next_disktype) )
5976 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl ERR 0x%02x\n", last_err);
5977 DelayThread(250000);
5980 VERBOSE_KPRINTF(1,
"** sceCdChgSpdlCtrl OK\n");
5985 VERBOSE_KPRINTF(1,
" -> Ps2 May be No media %08x\n", disc_type);
5987 SetEventFlag(g_ncmd_evfid, 1);
5988 SetEventFlag(g_scmd_evfid, 1);
5989 SetEventFlag(g_sfile_evfid, 1);
5990 SetEventFlag(g_fio_fsv_evfid, 1);
5991 VERBOSE_KPRINTF(1,
"Go SCECdChgPs2Drv End.\n");
5994 SetEventFlag(g_cdvdman_csys_evfid, 1);
5995 return current_mode;
6000cdvdman_send_ncmd(
int ncmd,
const void *ndata,
int ndlen,
int func,
cdvdman_dma3_parameter_t *dma3_param,
int check_cb)
6004 USE_DEV5_MMIO_HWPORT();
6006 if ( check_cb == 1 && PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6012 (
sceCdDiskReady(8) & 0xC0) != 0x40 || !g_cdvdman_istruct.m_wait_flag
6013 || !(g_cdvdman_istruct.m_read2_flag != 1 || ncmd == 8) || !(g_cdvdman_istruct.m_read2_flag != 2 || ncmd == 6) )
6015 if ( check_cb == 1 )
6017 vSetEventFlag(g_ncmd_evfid, 1);
6020 VERBOSE_KPRINTF(1,
"set_cd_commnad Error\tstat %02x\n", (u8)
sceCdDiskReady(8));
6023 g_cdvdman_iocache = 0;
6026 cdvdman_setdma3(dma3_param);
6028 g_cdvdman_cmdfunc = func;
6031 !g_cdvdman_minver_10700 && g_cdvdman_ncmd == 0x06 && ncmd && ncmd != g_cdvdman_ncmd && ncmd != 0x07 && ncmd != 0x0E
6033#ifdef CDVD_VARIANT_XOSD
6038 g_cdvdman_ncmd_timeout.hi = 0;
6039 g_cdvdman_ncmd_timeout.lo = 0x6978000;
6040 vSetAlarm(&g_cdvdman_ncmd_timeout, ncmd_timeout_alarm_cb, &g_cdvdman_ncmd_timeout);
6043 VERBOSE_KPRINTF(1,
"Read Pause 1 chk status 0x%02x\n", dev5_mmio_hwport->m_dev5_reg_00A);
6044 if ( !g_cdvdman_ncmd_timeout.lo )
6046 g_cdvdman_ncmd = ncmd;
6047 if ( check_cb == 1 )
6049 vSetEventFlag(g_ncmd_evfid, 1);
6051 KPRINTF(
"Time Out Pause WAIT set_cd_commnad\n");
6056 vCancelAlarm(ncmd_timeout_alarm_cb, &g_cdvdman_ncmd_timeout);
6058 g_cdvdman_ncmd = ncmd;
6059 if ( g_cdvdman_istruct.m_dec_state )
6061 sceCdDecSet(!!g_cdvdman_istruct.m_dec_shift, 1, g_cdvdman_istruct.m_dec_shift);
6063 g_cdvdman_istruct.m_last_read_timeout = 0;
6064 g_cdvdman_istruct.m_cdvdman_command = ncmd;
6065 g_cdvdman_istruct.m_last_error =
SCECdErNO;
6066 g_cdvdman_istruct.m_wait_flag = 0;
6067 g_cdvdman_istruct.m_thread_id = GetThreadId();
6070 iClearEventFlag(g_cdvdman_intr_evfid, ~1);
6074 ClearEventFlag(g_cdvdman_intr_evfid, ~1);
6076 for ( i = 0; i < ndlen; i += 1 )
6078 dev5_mmio_hwport->m_dev5_reg_005 = ((u8 *)ndata)[i];
6080 dev5_mmio_hwport->m_dev5_reg_004 = ncmd;
6081 if ( check_cb == 1 )
6083 vSetEventFlag(g_ncmd_evfid, 1);
6090 VERBOSE_KPRINTF(1,
"Apply NCmd call cmd= 0x%02x\n", cmdNum);
6091 while ( cdvdman_send_ncmd(cmdNum, inBuff, inBuffSize, 0, 0, 1) < 0 )
6099int sceCdCheckCmd(
void)
6101 return g_cdvdman_istruct.m_wait_flag;
6104static int cdvdman_mediactl(
int code)
6110#ifndef CDVD_VARIANT_XOSD
6111 USE_DEV5_MMIO_HWPORT();
6115 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6119#ifdef CDVD_VARIANT_XOSD
6124 if ( reg_00B_tmp_1 == g_cdvdman_chmedia )
6127 if ( g_cdvdman_chflags[code] )
6129 g_cdvdman_chflags[code] = 0;
6137 for ( i = 0; i < (
sizeof(g_cdvdman_chflags) /
sizeof(g_cdvdman_chflags[0])); i += 1 )
6139 g_cdvdman_chflags[i] = i != (
unsigned int)code;
6143#ifdef CDVD_VARIANT_XOSD
6149 while ( !set_prev_command(0x05, NULL, 0, rdata,
sizeof(rdata), 0) || rdata[0] )
6154#ifdef CDVD_VARIANT_XOSD
6155 g_cdvdman_chmedia = get_cdvd_register(0x0B) & 1;
6159 vSetEventFlag(g_scmd_evfid, 1);
6165 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
6167 VERBOSE_KPRINTF(1,
"sceCdGetError: 0x%02x\n", (u8)g_cdvdman_istruct.m_last_error);
6169 return (u8)g_cdvdman_istruct.m_last_error;
6173int cdvdman_get_last_command(
void)
6175 return (u8)g_cdvdman_istruct.m_cdvdman_command;
6181 return cdvdman_send_ncmd(0x00, NULL, 0, 0, 0, 1) >= 0;
6185int cdvdman_ncmd_sender_01(
void)
6187 return cdvdman_send_ncmd(0x01, NULL, 0, 0, 0, 1) >= 0;
6191#ifndef CDVD_VARIANT_XOSD
6192static int cdvdman_ncmd_sender_06(
void)
6203 for ( i = 0; i < 48; i += 8 )
6206 KPRINTF(
"CMD_READP call\n");
6218 dma3_param.m_cdvdreg_howto = 128;
6219 dma3_param.m_dma3_blkwords = 32;
6220 dma3_param.m_dma3_blkcount = 128;
6221 dma3_param.m_dma3_csectors = 0;
6222 dma3_param.m_dma3_msectors = 0;
6223 dma3_param.m_dma3_callback = 0;
6224 dma3_param.m_dma3_maddress = g_cdvdman_ptoc;
6225 if ( cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 5, &dma3_param, 1) < 0 )
6240#ifdef CDVD_VARIANT_XOSD
6241 switch ( get_disk_type_ex() )
6255 dma3_param.m_cdvdreg_howto = 128;
6256 dma3_param.m_dma3_blkwords = 32;
6257 dma3_param.m_dma3_blkcount = 16;
6266 dma3_param.m_dma3_csectors = 0;
6267 dma3_param.m_dma3_msectors = 0;
6268 dma3_param.m_dma3_callback = 0;
6269 dma3_param.m_dma3_maddress = g_cdvdman_ptoc;
6270 return cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 5, &dma3_param, 1) >= 0;
6272 return cdvdman_send_ncmd(0x02, NULL, 0, 5, 0, 1) >= 0;
6278 return cdvdman_send_ncmd(0x03, NULL, 0, 6, 0, 1) >= 0;
6283 return cdvdman_send_ncmd(0x04, NULL, 0, 7, 0, 1) >= 0;
6287int cdvdman_ncmd_sender_0B(
void)
6292 return cdvdman_send_ncmd(0x0B, ndata,
sizeof(ndata), 0, 0, 1) >= 0;
6296static unsigned int readtoc_timeout_alarm_cb(
void *userdata)
6299 USE_DEV5_MMIO_HWPORT();
6302 KPRINTF(
"Cmd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
6303 dev5_mmio_hwport->m_dev5_reg_007 = 1;
6308static int cdvdman_readtoc(u8 *
toc,
int param,
int func)
6315#ifdef CDVD_VARIANT_XOSD
6316 switch ( get_disk_type_ex() )
6325 dma3_param.m_cdvdreg_howto = 132;
6326 dma3_param.m_dma3_blkwords = 4;
6327 dma3_param.m_dma3_blkcount = 129;
6328 dma3_param.m_dma3_maddress =
toc;
6329 dma3_param.m_dma3_msectors = 0;
6330 dma3_param.m_dma3_csectors = 0;
6331 dma3_param.m_dma3_callback = 0;
6339 dma3_param.m_cdvdreg_howto = 128;
6340 dma3_param.m_dma3_blkwords = 32;
6341 dma3_param.m_dma3_blkcount = 8;
6342 dma3_param.m_dma3_maddress =
toc;
6343 dma3_param.m_dma3_msectors = 0;
6344 dma3_param.m_dma3_csectors = 0;
6345 dma3_param.m_dma3_callback = 0;
6351 if ( cdvdman_send_ncmd(0x09, ndata,
sizeof(ndata), func, &dma3_param, 1) < 0 )
6356 sysclk.lo = 0x15F90000;
6357 vSetAlarm(&sysclk, readtoc_timeout_alarm_cb, &sysclk);
6359 vCancelAlarm(readtoc_timeout_alarm_cb, &sysclk);
6361 if ( g_cdvdman_minver_10700 && !
sceCdPause() )
6369static int cdvdman_gettoc(u8 *
toc)
6372 VERBOSE_KPRINTF(1,
"sceCdReadToc() call 0x%p\n",
toc);
6373 return cdvdman_readtoc(
toc, 0, 3);
6376#ifdef CDVD_VARIANT_OSD
6382 dma3_param.m_cdvdreg_howto = 140;
6383 dma3_param.m_dma3_blkwords = 12;
6384 dma3_param.m_dma3_blkcount = 43;
6385 dma3_param.m_dma3_maddress =
toc;
6386 dma3_param.m_dma3_msectors = 0;
6387 dma3_param.m_dma3_csectors = 0;
6388 dma3_param.m_dma3_callback = 0;
6390 return cdvdman_send_ncmd(0x09, ndata,
sizeof(ndata), 0, &dma3_param, 1) >= 0;
6396 int sector_sizes[4];
6398 sector_sizes[0] = 0x800;
6399 sector_sizes[1] = 0x918;
6400 sector_sizes[2] = 0x924;
6401 if ( g_cdvdman_istruct.m_recover_status && g_cdvdman_istruct.m_recover_status != 3 )
6405 if ( g_cdvdman_cmdfunc == SCECdFuncReadCDDA || g_cdvdman_cmdfunc == 12 )
6407 return dmac_ch_get_madr(3) - (uiptr)g_cdvdman_readbuf;
6409 if ( g_cdvdman_istruct.m_read2_flag )
6411 return g_cdvdman_readptr * sector_sizes[g_cdvdman_istruct.m_cdvdman_pattern];
6413 if ( g_cdvdman_cmdfunc == SCECdFuncRead )
6415 return dmac_ch_get_madr(3) - (uiptr)g_cdvdman_readbuf;
6420static int cdvdman_speedctl(u32 spindlctrl,
int dvdflag, u32 maxlsn)
6424 switch ( spindlctrl )
6427 return dvdflag ? 2 : 4;
6433 if ( g_cdvdman_minver_10700 )
6437#ifdef CDVD_VARIANT_OSD
6439 maxlsn_chk = 0x1C9000;
6441 maxlsn_chk = 0x128000;
6443 if ( g_cdvdman_istruct.m_opo_or_para )
6445 maxlsn -= (maxlsn >= (u32)g_cdvdman_istruct.m_layer_1_lsn) ? g_cdvdman_istruct.m_layer_1_lsn : 0;
6446#ifdef CDVD_VARIANT_OSD
6448 maxlsn_chk = 0x197000;
6450 maxlsn_chk = 0x165000;
6453 if ( maxlsn >= maxlsn_chk )
6455 VERBOSE_KPRINTF(1,
"Kprob Spd D lsn= %d\n", maxlsn);
6465 return dvdflag ? 2 : 131;
6467 return dvdflag ? 3 : 4;
6471 return dvdflag ? 4 : 2;
6475 return dvdflag ? 130 : 131;
6477 return dvdflag ? 130 : 132;
6479 return dvdflag ? 1 : 131;
6481 return dvdflag ? 3 : 5;
6483 return dvdflag ? 131 : 133;
6487static int cdvdman_isdvd(
void)
6490#ifdef CDVD_VARIANT_XOSD
6491 switch ( get_disk_type_ex() )
6501 g_cdvdman_istruct.m_tray_is_open = 1;
6506 g_cdvdman_istruct.m_tray_is_open = 1;
6513static int sceCdRead0_Rty(u32 lsn, u32 nsec,
void *buf,
const sceCdRMode *mode,
int ncmd,
int dintrsec,
void *func)
6518 g_cdvdman_readbuf = buf;
6519 VERBOSE_KPRINTF(1,
"sceCdRead0_Rty Lsn:%d nsec:%d dintrnsec %d func %08x\n", lsn, nsec, dintrsec, func);
6520 *(u32 *)ndata = lsn;
6521 *(u32 *)&ndata[4] = nsec;
6522 ndata[8] = mode->trycount;
6523 ndata[9] = cdvdman_speedctl(mode->spindlctrl, cdvdman_isdvd(), lsn + nsec);
6524 dma3_param.m_dma3_csectors = dintrsec;
6525 dma3_param.m_dma3_callback = (int (*)(void))func;
6526 dma3_param.m_dma3_msectors = nsec;
6527 dma3_param.m_dma3_maddress = buf;
6528 dma3_param.m_dma3_blkcount = (!(u16)dintrsec) ? nsec : 1;
6532 ndata[10] = mode->datapattern;
6533 switch ( mode->datapattern )
6536 dma3_param.m_dma3_blkwords = 6;
6537 dma3_param.m_dma3_blkcount *= 97;
6538 dma3_param.m_cdvdreg_howto = 134;
6541 dma3_param.m_dma3_blkwords = 15;
6542 dma3_param.m_dma3_blkcount *= 39;
6543 dma3_param.m_cdvdreg_howto = 143;
6547 dma3_param.m_dma3_blkwords = 32;
6548 dma3_param.m_dma3_blkcount *= 16;
6549 dma3_param.m_cdvdreg_howto = 128;
6554 dma3_param.m_dma3_blkwords = 12;
6555 dma3_param.m_dma3_blkcount *= 43;
6556 dma3_param.m_cdvdreg_howto = 140;
6562 return cdvdman_send_ncmd(ncmd, ndata,
sizeof(ndata), ncmd == 0x06 ? 1 : 14, &dma3_param, 0) >= 0;
6565int sceCdRead0(u32 lsn, u32 sectors,
void *buffer,
sceCdRMode *mode,
int csec,
void *callback)
6571 if ( PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
6577 "DVD/CD sceCdRead0 sec %d num %d spin %d trycnt %d dptn %d adr %08x\n",
6584 g_cdvdman_readbuf = buffer;
6585 dma3_param.m_dma3_csectors = (csec && (sectors < (u32)csec)) ? sectors : (u32)csec;
6586 dma3_param.m_dma3_callback = (int (*)(void))callback;
6587 dma3_param.m_dma3_msectors = sectors;
6588 dma3_param.m_dma3_blkcount = (!csec) ? sectors : 1;
6589 switch ( mode->datapattern )
6592 dma3_param.m_dma3_blkwords = 6;
6593 dma3_param.m_dma3_blkcount *= 97;
6594 dma3_param.m_cdvdreg_howto = 134;
6597 dma3_param.m_dma3_blkwords = 15;
6598 dma3_param.m_dma3_blkcount *= 39;
6599 dma3_param.m_cdvdreg_howto = 143;
6603 dma3_param.m_dma3_blkwords = 32;
6604 dma3_param.m_dma3_blkcount *= 16;
6605 dma3_param.m_cdvdreg_howto = 128;
6609#ifdef CDVD_VARIANT_OSD
6610 g_cdvdman_istruct.m_dvd_flag = cdvdman_isdvd();
6618 if ( g_cdvdman_mmode != SCECdMmodeCd && g_cdvdman_mmode != 0xFF )
6620 vSetEventFlag(g_ncmd_evfid, 1);
6623 g_cdvdman_istruct.m_dvd_flag = 0;
6626 if ( g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF )
6628 vSetEventFlag(g_ncmd_evfid, 1);
6631 g_cdvdman_istruct.m_dvd_flag = 1;
6634 vSetEventFlag(g_ncmd_evfid, 1);
6638 g_cdvdman_istruct.m_read_mode = *mode;
6639 g_cdvdman_istruct.m_read_callback = callback;
6640 g_cdvdman_istruct.m_read_chunk = dma3_param.m_dma3_csectors;
6641 g_cdvdman_istruct.m_read_lsn = lsn;
6642 g_cdvdman_istruct.m_read_sectors = sectors;
6643 *(u32 *)ndata = lsn;
6644 *(u32 *)&ndata[4] = sectors;
6645 ndata[8] = mode->trycount;
6646 ndata[9] = cdvdman_speedctl(mode->spindlctrl, g_cdvdman_istruct.m_dvd_flag, lsn + sectors);
6647 g_cdvdman_istruct.m_read_buf = buffer;
6648 ndata[10] = mode->datapattern;
6649 dma3_param.m_dma3_maddress = buffer;
6650 VERBOSE_KPRINTF(1,
"Read Command call\n");
6651 if ( cdvdman_send_ncmd(0x06, ndata,
sizeof(ndata), 1, &dma3_param, 0) < 0 )
6653 vSetEventFlag(g_ncmd_evfid, 1);
6656 vSetEventFlag(g_ncmd_evfid, 1);
6669 for ( i = 0; i < common->m_dma3_param.m_dma3_csectors; i += 1 )
6675 if ( common->m_read2_flag == 3 )
6678 cdrloc.
minute = cdvdman_syncdec(
6679 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock)]);
6680 cdrloc.
second = cdvdman_syncdec(
6681 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 1]);
6682 cdrloc.
sector = cdvdman_syncdec(
6683 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 2]);
6689 syncdec_res_1 = (u8)cdvdman_syncdec(
6690 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 3]);
6692 (u8)cdvdman_syncdec(
6693 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 2])
6696 (u8)cdvdman_syncdec(
6697 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 1])
6699 syncdec_res_4 = cdvdman_syncdec(
6700 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock)]);
6701 if ( !common->m_cdvdman_dma3sec && !common->m_interupt_read_state )
6703 common->m_interupt_read_state = (syncdec_res_4 & 0xC) | (((syncdec_res_4 & 0xC) && i) ? 0x80 : 0);
6705 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);
6707 errlsn = common->m_cdvdman_lsn + common->m_cdvdman_csec + common->m_cdvdman_dma3sec + i;
6708 if ( cdreadlsn != (u32)errlsn )
6711 1,
"Read_IOP Sector_ID error lsn= %d readlsn= %d layer= %d\n", errlsn, cdreadlsn, (syncdec_res_4 & 1));
6715 if ( i == common->m_dma3_param.m_dma3_csectors )
6720 switch ( common->m_cdvdman_pattern )
6731 &((
char *)(common->m_cdvdman_rbuffer))[0x924 * common->m_cdvdman_dma3sec],
6732 (
const char *)g_cdvdman_ptoc,
6738 for ( i = 0; i < common->m_dma3_param.m_dma3_csectors; i += 1 )
6741 &((
char *)(common->m_cdvdman_rbuffer))[(common->m_cdvdman_dma3sec + i) * size],
6742 (
const char *)&g_cdvdman_ptoc[12 + (i * sblock)],
6746 g_cdvdman_readptr = common->m_cdvdman_csec + common->m_cdvdman_dma3sec;
6750 common->m_sync_error += 1;
6755static int cdvdman_read(u32 lsn, u32 sectors,
void *buf,
sceCdRMode *mode,
int decflag,
int shift,
int ef1,
int ef2)
6763 dvd = cdvdman_isdvd();
6766 if ( !DvdDual_infochk() )
6770 vSetEventFlag(ef1, ef2);
6774 lsn = sceCdLsnDualChg(lsn);
6776 else if ( mode->datapattern == SCECdSecS2328 || (g_cdvdman_cd36key && !g_cdvdman_istruct.m_dec_state) )
6780 if ( g_cdvdman_cd36key && !g_cdvdman_istruct.m_dec_state && mode->spindlctrl ==
SCECdSpinNom )
6785 read0_res = sceCdRead0(lsn, sectors, buf, mode, 0, 0);
6788 vSetEventFlag(ef1, ef2);
6795 if ( ready != 0x40 || g_cdvdman_istruct.m_read2_flag )
6800 "sceCdRead: Double Booking error r2f= %d waf= %d rdy= %02x\n",
6801 g_cdvdman_istruct.m_read2_flag,
6802 g_cdvdman_istruct.m_wait_flag,
6806 vSetEventFlag(ef1, ef2);
6813 g_cdvdman_istruct.m_dec_shift = shift;
6814 g_cdvdman_istruct.m_dec_state = 1;
6816 g_cdvdman_readbuf = buf;
6817 g_cdvdman_readptr = 0;
6818 g_cdvdman_istruct.m_cdvdman_lsn = lsn;
6819 g_cdvdman_istruct.m_cdvdman_csec = 0;
6820 g_cdvdman_istruct.m_cdvdman_nsec = sectors;
6821 g_cdvdman_istruct.m_cdvdman_rbuffer = (int)buf;
6822 g_cdvdman_istruct.m_cdvdman_pattern = dvd ? SCECdSecS2048 : mode->datapattern;
6823 g_cdvdman_istruct.m_cdvdman_cdrmode.
trycount = mode->trycount;
6824 g_cdvdman_istruct.m_cdvdman_cdrmode.
spindlctrl = mode->spindlctrl;
6825 g_cdvdman_istruct.m_cdvdman_cdrmode.
datapattern = dvd ? SCECdSecS2048 : SCECdSecS2340;
6826 g_cdvdman_istruct.m_read2_flag = dvd ? 1 : 3;
6827 g_cdvdman_istruct.m_sync_error = 0;
6828 g_cdvdman_istruct.m_interupt_read_state = 0;
6829 g_cdvdman_istruct.m_cdvdman_rsec = (sectors >= 0x41) ? (((lsn & 0xF)) ? (0x10 - (lsn & 0xF)) : 0x40) : sectors;
6830 g_cdvdman_read_alarm_cb_timeout.hi = 0;
6831 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
6832 vSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6833 read_res = (dvd ?
sceCdRV : sceCdRead0)(
6835 g_cdvdman_istruct.m_cdvdman_rsec,
6837 dvd ? mode : &g_cdvdman_istruct.m_cdvdman_cdrmode,
6838 g_cdvdman_cache_sector_count,
6843 g_cdvdman_istruct.m_cdvdman_rsec = 0;
6844 g_cdvdman_istruct.m_read2_flag = 0;
6845 if ( g_cdvdman_istruct.m_dec_state )
6847 g_cdvdman_istruct.m_dec_shift = 0;
6848 g_cdvdman_istruct.m_check_version = 0;
6849 g_cdvdman_istruct.m_dec_state = 0;
6852 vCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6856 vSetEventFlag(ef1, ef2);
6864 return cdvdman_read(lsn, sectors, buf, mode, 0, 0, 0, 0);
6873 memset(&efinfo, 0,
sizeof(efinfo));
6875 vReferEventFlagStatus(g_fio_fsv_evfid, &efinfo);
6881 vClearEventFlag(g_fio_fsv_evfid, ~1);
6883 return cdvdman_read(lbn, sectors, buffer, mode, 0, 0, g_fio_fsv_evfid, 1);
6886static int cdvdman_syncdec(
int decflag,
int decxor,
int shift, u32 data)
6888 return decflag ? ((u8)(((u8)data << (shift % 8)) | ((u8)data >> (8 - shift % 8))) ^ (u8)decxor) : (u8)data;
6891static void Read2intrCDVD(
int read2_flag)
6893 iCancelAlarm(read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6894 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO || g_cdvdman_retries >= 5 )
6896 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO )
6900 g_cdvdman_istruct.m_read2_flag = 0;
6901 g_cdvdman_retries = 0;
6902 g_cdvdman_rtindex = 0;
6903 g_cdvdman_readptr = 0;
6904 if ( g_cdvdman_istruct.m_dec_state )
6906 g_cdvdman_istruct.m_dec_shift = 0;
6907 g_cdvdman_istruct.m_check_version = 0;
6908 g_cdvdman_istruct.m_dec_state = 0;
6910 g_cdvdman_istruct.m_interupt_read_state = 0;
6912 else if ( !g_cdvdman_istruct.m_interupt_read_state || g_cdvdman_istruct.m_cdvdman_csec )
6916 g_cdvdman_istruct.m_interupt_read_state = 0;
6917 if ( g_cdvdman_istruct.m_sync_error )
6921 if ( !g_cdvdman_rtindex )
6923 g_cdvdman_rtindex = 3;
6924 g_cdvdman_retries += 1;
6926 g_cdvdman_istruct.m_sync_error = 0;
6927 lsn_tmp = g_cdvdman_istruct.m_cdvdman_lsn + g_cdvdman_istruct.m_cdvdman_csec;
6928 if ( lsn_tmp >= 0x30 )
6930 lsn_tmp -= 0x10 * (g_cdvdman_rtindex - 1);
6934 lsn_tmp += 0x10 * (g_cdvdman_rtindex - 1);
6936 if ( ((read2_flag == 3) ? sceCdRead0 : sceCdRV)(
6938 g_cdvdman_istruct.m_cdvdman_rsec,
6940 &g_cdvdman_istruct.m_cdvdman_cdrmode,
6941 g_cdvdman_cache_sector_count,
6944 g_cdvdman_read_alarm_cb_timeout.hi = 0;
6945 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
6946 iSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
6950 VERBOSE_KPRINTF(1,
"Retry Read Fatal Error\n");
6952 g_cdvdman_istruct.m_read2_flag = 0;
6953 g_cdvdman_retries = 0;
6954 g_cdvdman_rtindex = 0;
6955 g_cdvdman_readptr = 0;
6956 if ( g_cdvdman_istruct.m_dec_state )
6958 g_cdvdman_istruct.m_dec_shift = 0;
6959 g_cdvdman_istruct.m_check_version = 0;
6960 g_cdvdman_istruct.m_dec_state = 0;
6963 g_cdvdman_rtindex -= !!g_cdvdman_rtindex;
6969 g_cdvdman_retries = 0;
6970 switch ( g_cdvdman_istruct.m_cdvdman_pattern )
6983 g_cdvdman_istruct.m_cdvdman_rbuffer += cdsectorsz * g_cdvdman_istruct.m_cdvdman_rsec;
6984 g_cdvdman_istruct.m_cdvdman_csec += g_cdvdman_istruct.m_cdvdman_rsec;
6985 if ( (
unsigned int)g_cdvdman_istruct.m_cdvdman_csec < (
unsigned int)g_cdvdman_istruct.m_cdvdman_nsec )
6987 g_cdvdman_istruct.m_cdvdman_rsec =
6988 ((
unsigned int)(g_cdvdman_istruct.m_cdvdman_csec + 0x40) < (
unsigned int)g_cdvdman_istruct.m_cdvdman_nsec) ?
6990 (g_cdvdman_istruct.m_cdvdman_nsec - g_cdvdman_istruct.m_cdvdman_csec);
6991 if ( ((read2_flag == 3) ? sceCdRead0 : sceCdRV)(
6992 g_cdvdman_istruct.m_cdvdman_lsn + g_cdvdman_istruct.m_cdvdman_csec,
6993 g_cdvdman_istruct.m_cdvdman_rsec,
6995 &g_cdvdman_istruct.m_cdvdman_cdrmode,
6996 g_cdvdman_cache_sector_count,
6999 g_cdvdman_read_alarm_cb_timeout.hi = 0;
7000 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
7001 iSetAlarm(&g_cdvdman_read_alarm_cb_timeout, read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
7005 g_cdvdman_istruct.m_last_error = SCECdErNORDY;
7006 g_cdvdman_istruct.m_read2_flag = 0;
7007 g_cdvdman_readptr = 0;
7008 if ( g_cdvdman_istruct.m_dec_state )
7010 g_cdvdman_istruct.m_dec_shift = 0;
7011 g_cdvdman_istruct.m_check_version = 0;
7012 g_cdvdman_istruct.m_dec_state = 0;
7018 g_cdvdman_istruct.m_read2_flag = 0;
7019 g_cdvdman_readptr = 0;
7020 if ( g_cdvdman_istruct.m_dec_state )
7022 g_cdvdman_istruct.m_dec_shift = 0;
7023 g_cdvdman_istruct.m_check_version = 0;
7024 g_cdvdman_istruct.m_dec_state = 0;
7031 g_cdvdman_istruct.m_last_error = ((g_cdvdman_istruct.m_interupt_read_state & 0x80)) ?
SCECdErREADCF :
SCECdErIPI;
7032 g_cdvdman_istruct.m_interupt_read_state = 0;
7033 VERBOSE_KPRINTF(1,
"IPIerr emu Hit Dummy Err %02x\n", (u8)g_cdvdman_istruct.m_last_error);
7034 g_cdvdman_istruct.m_read2_flag = 0;
7035 g_cdvdman_retries = 0;
7036 g_cdvdman_rtindex = 0;
7037 g_cdvdman_readptr = 0;
7038 if ( g_cdvdman_istruct.m_dec_state )
7040 g_cdvdman_istruct.m_dec_shift = 0;
7041 g_cdvdman_istruct.m_check_version = 0;
7042 g_cdvdman_istruct.m_dec_state = 0;
7055static int cdvdman_readfull(u32 lsn, u32 sectors,
void *buf,
const sceCdRMode *mode,
int flag)
7060 VERBOSE_KPRINTF(1,
"lsn:%d nsec:%d buf:% cmdmode:%d\n", lsn, sectors, buf, flag);
7062 VERBOSE_KPRINTF(1,
"DA Read lsn= %d nsec= %d datapattern= %d\n", lsn, sectors, mode->datapattern);
7063 g_cdvdman_readbuf = buf;
7064#ifdef CDVD_VARIANT_XOSD
7065 dma3_param.m_dma3_csectors = sectors;
7066 dma3_param.m_dma3_msectors = (u16)sectors;
7068 dma3_param.m_dma3_csectors = 0;
7069 dma3_param.m_dma3_msectors = 0;
7071 dma3_param.m_dma3_callback = 0;
7072 dma3_param.m_dma3_blkcount = sectors;
7073 switch ( mode->datapattern )
7076 dma3_param.m_dma3_blkwords = 8;
7077 dma3_param.m_dma3_blkcount *= 74;
7078 dma3_param.m_cdvdreg_howto = 136;
7081 dma3_param.m_dma3_blkwords = 12;
7082 dma3_param.m_dma3_blkcount *= 51;
7083 dma3_param.m_cdvdreg_howto = 140;
7087 dma3_param.m_dma3_blkwords = 12;
7088 dma3_param.m_dma3_blkcount *= 49;
7089 dma3_param.m_cdvdreg_howto = 140;
7093#ifdef CDVD_VARIANT_XOSD
7094 switch ( get_disk_type_ex() )
7106#ifndef CDVD_VARIANT_OSD
7107 if ( g_cdvdman_mmode != SCECdMmodeCd && g_cdvdman_mmode != 0xFF )
7112 *(u32 *)ndata = lsn;
7113 *(u32 *)&ndata[4] = sectors;
7114 ndata[8] = mode->trycount;
7115 ndata[9] = cdvdman_speedctl(mode->spindlctrl, 0, lsn + sectors);
7116 dma3_param.m_dma3_maddress = buf;
7117 ndata[10] = mode->datapattern;
7118 return cdvdman_send_ncmd((!flag) ? 0x07 : 0x0E, ndata,
sizeof(ndata), (!flag) ? 2 : 12, &dma3_param, 1) >= 0;
7122int sceCdReadCDDA(u32 lbn, u32 sectors,
void *buffer,
sceCdRMode *mode)
7124 return cdvdman_readfull(lbn, sectors, buffer, mode, 0);
7127#ifdef CDVD_VARIANT_OSD
7131 return g_cdvdman_minver_20800 ? cdvdman_readfull(lsn, sectors, buf, mode, 1) :
7132 cdvdman_readfull(lsn, sectors, buf, mode, 0);
7143#ifdef CDVD_VARIANT_XOSD
7149#ifndef CDVD_VARIANT_OSD
7150 || (g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF)
7152 || (PollEventFlag(g_ncmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND) )
7157 1,
"RV read: sec %d num %d spin %d trycnt %d addr %08x\n", lsn, sectors, mode->spindlctrl, mode->trycount, buf);
7158 g_cdvdman_readbuf = buf;
7159 g_cdvdman_istruct.m_dvd_flag = cdvdman_isdvd();
7160 g_cdvdman_istruct.m_read_mode = *mode;
7161 g_cdvdman_istruct.m_read_lsn = lsn;
7162 g_cdvdman_istruct.m_read_sectors = sectors;
7163 *(u32 *)ndata = lsn;
7164 *(u32 *)&ndata[4] = sectors;
7165 ndata[8] = mode->trycount;
7166 ndata[9] = cdvdman_speedctl(mode->spindlctrl, 1, lsn + sectors);
7168 dma3_param.m_dma3_csectors = (arg5 && (sectors < (u32)arg5)) ? sectors : (u32)arg5;
7169 g_cdvdman_istruct.m_read_chunk = dma3_param.m_dma3_csectors;
7170 dma3_param.m_cdvdreg_howto = 140;
7171 dma3_param.m_dma3_blkwords = 12;
7172 g_cdvdman_istruct.m_read_buf = buf;
7173 dma3_param.m_dma3_blkcount = (!arg5) ? sectors : 1;
7174 dma3_param.m_dma3_blkcount *= 43;
7175 dma3_param.m_dma3_msectors = sectors;
7176 dma3_param.m_dma3_callback = (int (*)(void))cb;
7177 g_cdvdman_istruct.m_read_callback = cb;
7178 dma3_param.m_dma3_maddress = buf;
7179 if ( cdvdman_send_ncmd(0x08, ndata,
sizeof(ndata), 14, &dma3_param, 0) < 0 )
7181 vSetEventFlag(g_ncmd_evfid, 1);
7184 vSetEventFlag(g_ncmd_evfid, 1);
7188#ifdef CDVD_VARIANT_OSD
7190int sceCdReadDVDV(u32 lbn, u32 sectors,
void *buffer,
sceCdRMode *mode)
7195#ifdef CDVD_VARIANT_XOSD
7196 switch ( get_disk_type_ex() )
7209 switch ( mode->spindlctrl )
7232 *(u32 *)ndata = lbn;
7233 *(u32 *)&ndata[4] = sectors;
7234 dma3_param.m_cdvdreg_howto = 140;
7235 dma3_param.m_dma3_blkwords = 12;
7236 dma3_param.m_dma3_blkcount = 43 * sectors;
7238 dma3_param.m_dma3_maddress = buffer;
7239 dma3_param.m_dma3_msectors = 0;
7240 dma3_param.m_dma3_csectors = 0;
7241 dma3_param.m_dma3_callback = 0;
7242 ndata[8] = mode->trycount;
7243 return cdvdman_send_ncmd(0x08, ndata,
sizeof(ndata), 9, &dma3_param, 1) >= 0;
7251 *(u32 *)ndata = lbn;
7252 if ( cdvdman_isdvd() )
7254 if ( !DvdDual_infochk() )
7258 *(u32 *)ndata = sceCdLsnDualChg(lbn);
7260 return cdvdman_send_ncmd(0x05, ndata,
sizeof(ndata), 4, 0, 1) >= 0;
7263#ifdef CDVD_VARIANT_XOSD
7264static unsigned int sceCdChgSpdlCtrl(
int mode)
7266 unsigned int retval;
7270 retval = ~cdvdman_send_ncmd(0x0F, ndata,
sizeof(ndata), 0xF, 0, 0);
7271 VERBOSE_KPRINTF(1,
"Called sceCdChgSpdlCtrl mode:%d ret= %d\n", mode & 0xFF, retval >> 31);
7272 return retval >> 31;
7282 retval = set_prev_command(0x12, NULL, 0, rdata,
sizeof(rdata), 1);
7284 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7297 if (
sceCdMV((u8 *)rdata, status) != 1 || (
unsigned int)(rdata[3] | (rdata[2] << 8) | (rdata[1] << 16)) < 0x10500 )
7299 strcpy(buffer,
"M_NAME_UNKNOWN");
7304 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
7310 retval = set_prev_command(0x17, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
7312 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7315 cmd_tmp2 = set_prev_command(0x17, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
7316 *status |= rdata[0];
7317 memcpy(&buffer[8], &rdata[1],
sizeof(rdata) - 1);
7318 vSetEventFlag(g_scmd_evfid, 1);
7319 return retval ? (!!cmd_tmp2) : 0;
7322#ifdef CDVD_VARIANT_OSD
7325int sceCdWI(
const u8 *buffer, u32 *status)
7331 retres = set_prev_command(0x13, (
const char *)buffer, 8, (
char *)status, 1, 1);
7337int sceCdWM(
const char *buffer, u32 *status)
7344 if (
sceCdMV((u8 *)wdata, status) != 1 || (
unsigned int)(wdata[3] | (wdata[2] << 8) | (wdata[1] << 16)) < 0x10500 )
7352 memcpy(&wdata[1], &buffer[0],
sizeof(wdata) - 1);
7353 retres = set_prev_command(0x18, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7358 memcpy(&wdata[1], &buffer[8],
sizeof(wdata) - 1);
7359 retres = set_prev_command(0x18, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && retres;
7360 *status |= rdata[0];
7373 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7375 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7388 memcpy(&wdata[1], buffer, 8);
7389 retval = set_prev_command(0x03, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7402 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7403#ifdef CDVD_VARIANT_XOSD
7406 *status = rdata[0] & 0x80;
7408 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]);
7409#ifndef CDVD_VARIANT_XOSD
7412 memcpy(buffer, rdata,
sizeof(rdata));
7416#ifdef CDVD_VARIANT_XOSD
7417static int cdvdman_get_renewal_date(u8 *buffer, u32 *status)
7425 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7428 *status = (u8)rdata[0];
7430 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7435#ifndef CDVD_VARIANT_XOSD
7436static int cdvdman_scmd_sender_03_30(u8 *buf, u32 *status)
7442 if ( g_cdvdman_minver_50000 )
7448 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7449 *status = (u8)rdata[0];
7455#ifdef CDVD_VARIANT_OSD
7465 USE_DEV5_MMIO_HWPORT();
7467 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
7471 dev5_mmio_hwport->m_dev5_reg_009 = 0;
7472 retval = cdvdman_send_scmd2(0x02, NULL, 0, rdata,
sizeof(rdata), 0);
7473 memcpy(buffer, &rdata[1],
sizeof(rdata) - 1);
7474 for ( i = 0; i < 10; i += 1 )
7480 dev5_reg_00E = dev5_mmio_hwport->m_dev5_reg_00E;
7481 dev5_reg_00D = dev5_mmio_hwport->m_dev5_reg_00D;
7482 dev5_reg_00C = dev5_mmio_hwport->m_dev5_reg_00C;
7483 tmp00E = dev5_mmio_hwport->m_dev5_reg_00E;
7484 tmp00D = dev5_mmio_hwport->m_dev5_reg_00D;
7485 tmp00C = dev5_mmio_hwport->m_dev5_reg_00C;
7486 if ( dev5_reg_00E == tmp00E && dev5_reg_00D == tmp00D && dev5_reg_00C == tmp00C )
7493 *((u8 *)buffer + 9) = dev5_reg_00E;
7494 *((u8 *)buffer + 8) = dev5_reg_00D;
7495 *((u8 *)buffer + 7) = dev5_reg_00C;
7498 vSetEventFlag(g_scmd_evfid, 1);
7509 retval = set_prev_command(0x15, NULL, 0, rdata,
sizeof(rdata), 1);
7510 *status = (u8)rdata[0];
7517 g_cdvdman_mmode = media;
7521#ifdef CDVD_VARIANT_OSD
7527 return set_prev_command(0x19, NULL, 0, (
char *)status, 1, 1);
7534 VERBOSE_KPRINTF(1,
"BC %d %d %d %d\n", *romname, romname[1], romname[2], romname[3]);
7535 return set_prev_command(0x1A, (
const char *)romname, 4, rdata,
sizeof(rdata), 1);
7544 return g_cdvdman_minver_20400 ? set_prev_command(0x1B, NULL, 0, (
char *)status, 1, 1) : 1;
7547#ifdef CDVD_VARIANT_OSD
7555 return set_prev_command(0x1C, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7559static unsigned int power_off_alarm_cb(
void *userdata)
7564 s->m_power_flag = 0;
7574 VERBOSE_KPRINTF(1,
"sceCdPowerOff Call\n");
7575#ifndef CDVD_VARIANT_XOSD
7576 if ( !g_cdvdman_minver_x_model_15 )
7583 vDelayThread(250000);
7587 retval = set_prev_command(0x0F, NULL, 0, (
char *)status, 1, 1);
7590 g_cdvdman_istruct.m_power_flag = 0;
7593 KPRINTF(
"PowerOff Start...\n");
7594 g_cdvdman_istruct.m_power_flag = 1;
7595 g_cdvdman_power_off_timeout.hi = 0;
7596 g_cdvdman_power_off_timeout.lo = 0xAFC8000;
7597 vSetAlarm(&g_cdvdman_power_off_timeout, power_off_alarm_cb, &g_cdvdman_istruct);
7607 VERBOSE_KPRINTF(1,
"Audio Digital Out: Set param %d\n", (u8)mode);
7609 return set_prev_command(0x14, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7612#ifdef CDVD_VARIANT_OSD
7620 VERBOSE_KPRINTF(1,
"Auto Adjust Ctrl: Set param %d\n", (u8)mode);
7622 return set_prev_command(0x16, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7628 unsigned int clkmonth;
7629 unsigned int clkday;
7632 if ( !g_cdvdman_minver_50000 )
7636 clkmonth = 10 * (clock->
month >> 4) + (clock->
month & 0xF);
7637 clkday = 10 * (clock->
day >> 4) + (clock->
day & 0xF);
7639 (10 * (clock->
second >> 4) + (clock->
second & 0xF) >= 0x3C
7640 || 10 * (clock->
minute >> 4) + (clock->
minute & 0xF) >= 0x3C
7641 || 10 * (clock->
hour >> 4) + (clock->
hour & 0xF) >= 0x18 || 10 * (clock->
year >> 4) + (clock->
year & 0xF) >= 0x64
7642 || clkmonth >= 0xD || !clkmonth || clkday >= 0x20 || !clkday)
7643 && flags != 255 && !(clock->
second & 0x80) && !(clock->
minute & 0x80) )
7647 wdata[0] = (flags == 255) ? 255 : clock->second;
7648 wdata[1] = clock->
minute | ((flags == 1) ? 0x80 : 0);
7649 wdata[2] = clock->
hour;
7650 wdata[3] = clock->
day;
7651 wdata[4] = clock->
month;
7652 wdata[5] = clock->
year;
7653 wdata[6] = userdata & 0xFF;
7654 wdata[7] = (userdata >> 8) & 0xFF;
7655 return set_prev_command(0x21, wdata,
sizeof(wdata), (
char *)&clock->
stat,
sizeof(clock->
stat), 1);
7674 if ( !g_cdvdman_minver_50000 )
7676 *wakeupreason = 256;
7679 retval = set_prev_command(0x22, NULL, 0, rdata,
sizeof(rdata), 1);
7684 clock->
stat = rdata[0];
7685 clock->
second = (u8)rdata[2] == 255 ? -1 : (rdata[2] & 0x7F);
7686 clock->
minute = rdata[3] & 0x7F;
7688 clock->
hour = rdata[4];
7689 clock->
day = rdata[5];
7690 clock->
month = rdata[6];
7691 clock->
year = rdata[7];
7692 *userdata = (u8)rdata[8] | ((u8)rdata[9] << 8);
7693 *wakeupreason = (u8)rdata[1];
7694 *flags = (((u8)rdata[2] >> 7) << 1) | (!!(rdata[3] & 0x80));
7698int sceCdSendSCmd1D(
int *arg1,
unsigned int *arg2,
unsigned int *arg3, u32 *status)
7707 if ( !g_cdvdman_minver_50000 )
7713 retval = set_prev_command(0x1D, NULL, 0, rdata,
sizeof(rdata), 1);
7718 *status = (u8)rdata[0];
7719 *arg1 = (u8)rdata[1];
7720 rdata2tmp = rdata[4] | (rdata[3] << 8) | (rdata[2] << 16);
7724 *arg2 = (rdata2tmp >> 17) & 0x7F;
7725 *arg3 = (rdata2tmp >> 12) & 0x1F;
7728 *arg2 = (rdata2tmp >> 17) & 0x7F;
7729 *arg3 = (rdata2tmp >> 9) & 0xFF;
7732 *arg2 = (rdata2tmp >> 17) & 0x7F;
7733 *arg3 = (rdata2tmp >> 4) & 0x1FFF;
7744 if ( !g_cdvdman_minver_50000 )
7750 wdata[0] = param & 0xFF;
7751 wdata[1] = (param >> 8) & 0xFF;
7752 return set_prev_command(0x1F, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7761 if ( !g_cdvdman_minver_50000 )
7767 retval = set_prev_command(0x26, NULL, 0, rdata,
sizeof(rdata), 1);
7768 *param = ((u8)rdata[2] << 8) | (u8)rdata[1];
7769 *status = (u8)rdata[0];
7780 if ( !g_cdvdman_minver_50200 )
7786 retval = set_prev_command(0x27, NULL, 0, (
char *)rdata,
sizeof(rdata), 1);
7787 memcpy(out, &rdata[1],
sizeof(rdata) - 2);
7799 if ( !g_cdvdman_minver_50400 )
7806 retval = set_prev_command(0x28, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7807 *status = (u8)rdata[0];
7811int cdvdman_152(u32 *param, u32 *status)
7817 if ( !g_cdvdman_minver_50400 )
7825 retval = set_prev_command(0x03, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7826 *param = 3125 * (((u8)rdata[2] | ((u8)rdata[1] << 8)) << 16 >> 18) / 100;
7827 *status = (u8)rdata[0];
7832#ifdef CDVD_VARIANT_XOSD
7840 if ( !g_cdvdman_minver_50400 )
7847 retval = set_prev_command(0x29, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7848 *status = (u8)rdata[0];
7849 if ( retval && !rdata[0] )
7851 g_cdvdman_istruct.m_medium_removal_state = 0;
7857#ifdef CDVD_VARIANT_OSD
7861 USE_IOP_MMIO_HWPORT();
7863 if ( mfc0(PRID) >= 0x23 )
7867 *(u32 *)&iop_mmio_hwport->sio2.unused[0] |= 1;
7871 *(u32 *)&iop_mmio_hwport->sio2.unused[0] &= ~1;
7876 if ( !g_cdvdman_minver_50000 )
7883 return set_prev_command(0x24, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7892 memset(param, 0, 15);
7893 if ( !g_cdvdman_minver_60000 )
7899 retval = set_prev_command(0x36, NULL, 0, rdata,
sizeof(rdata), 1);
7900 memcpy(param, &rdata[1],
sizeof(rdata) - 1);
7913 memset(wdata, 0,
sizeof(wdata));
7914 if ( !g_cdvdman_minver_60600 )
7921 memcpy(&wdata[1], arg2, 12);
7923 memcpy(&wdata[13], arg3, 2);
7924 return set_prev_command(0x3E, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7932 if ( !g_cdvdman_minver_50000 )
7939 return set_prev_command(0x25, wdata,
sizeof(wdata), (
char *)status, 1, 1);
7947 retval = set_prev_command(0x08, NULL, 0, (
char *)clock, 8, 1);
7949 clock->
month &= 0x7F;
7950 if ( retval && !clock->
stat )
7952 memcpy(&g_cdvdman_clock, clock,
sizeof(g_cdvdman_clock));
7953 g_cdvdman_clk_flg = 1;
7955 else if ( g_cdvdman_clk_flg )
7957 memcpy(clock, &g_cdvdman_clock,
sizeof(g_cdvdman_clock));
7973 return set_prev_command(0x08, NULL, 0, (
char *)clock, 8, 1);
7976#ifdef CDVD_VARIANT_OSD
7979 return set_prev_command(
7980 0x09, (
const char *)&clock->
second,
sizeof(clock) - 1, (
char *)&clock->
stat,
sizeof(clock->
second), 1);
7989 wdata[0] = (address >> 8) & 0xFF;
7990 wdata[1] = address & 0xFF;
7991 retval = set_prev_command(0x0A, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
7993 *data = (rdata[1] << 8) | rdata[2];
7994 VERBOSE_KPRINTF(1,
"RN_call addr= 0x%04x data= 0x%04x stat= 0x%02x\n", address, *data, *result);
8003 wdata[0] = (address >> 8) & 0xFF;
8004 wdata[1] = address & 0xFF;
8005 wdata[2] = (data >> 8) & 0xFF;
8006 wdata[3] = data & 0xFF;
8007 retval = set_prev_command(0x0B, wdata,
sizeof(wdata), (
char *)result, 1, 1);
8008 VERBOSE_KPRINTF(1,
"WN_call addr= 0x%04x data= 0x%04x stat= 0x%02x\n", address, data, *result);
8017#ifdef CDVD_VARIANT_XOSD
8023 *traychk = cdvdman_mediactl(1);
8024 VERBOSE_KPRINTF(1,
"Tray Req test = %d\n", *traychk);
8032 g_cdvdman_iocache = 0;
8033#ifdef CDVD_VARIANT_XOSD
8036 rdata[0] = !!set_prev_command(0x06, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0];
8037#ifdef CDVD_VARIANT_XOSD
8042#ifdef CDVD_VARIANT_XOSD
8045 g_cdvdman_istruct.m_medium_removal_state = 0;
8046 g_cdvdman_istruct.m_atapi_disk_ejected = 0;
8049 vDelayThread(11000);
8054static int cdvdman_scmd_sender_3B(
int arg1)
8059 if ( g_cdvdman_minver_x_model_15 && arg1 == 1 )
8063 g_cdvdman_iocache = 0;
8065 if ( set_prev_command(0x3B, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0] )
8067 vDelayThread(11000);
8073#ifdef CDVD_VARIANT_DNAS
8077 char sectbuf[0x800];
8079 USE_DEV5_MMIO_HWPORT();
8083#ifdef CDVD_VARIANT_XOSD
8084 switch ( get_disk_type_ex() )
8099 sceCdRead0(0x4B, 1, sectbuf, &rmode, 0, 0);
8101 if ( !cdvdman_ncmd_sender_0C(0, 0, 0x4B) )
8106 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8110 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8111 if ( !(dev5_mmio_hwport->m_dev5_reg_038 & 4) )
8113 vSetEventFlag(g_scmd_evfid, 1);
8116 *(u8 *)
id = dev5_mmio_hwport->m_dev5_reg_030 ^ dev5_mmio_hwport->m_dev5_reg_039;
8117 *((u8 *)
id + 1) = dev5_mmio_hwport->m_dev5_reg_031 ^ dev5_mmio_hwport->m_dev5_reg_039;
8118 *((u8 *)
id + 2) = dev5_mmio_hwport->m_dev5_reg_032 ^ dev5_mmio_hwport->m_dev5_reg_039;
8119 *((u8 *)
id + 3) = dev5_mmio_hwport->m_dev5_reg_033 ^ dev5_mmio_hwport->m_dev5_reg_039;
8120 *((u8 *)
id + 4) = dev5_mmio_hwport->m_dev5_reg_034 ^ dev5_mmio_hwport->m_dev5_reg_039;
8121 vSetEventFlag(g_scmd_evfid, 1);
8133 USE_DEV5_MMIO_HWPORT();
8135 if ( !g_cdvdman_istruct.m_cd_inited )
8141#ifdef CDVD_VARIANT_XOSD
8142 switch ( get_disk_type_ex() )
8159 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8171 dev5_mmio_hwport->m_dev5_reg_007 = 1;
8183 for ( i = 0; i < 20; i += 1 )
8185 sceCdRead0(0x4B + (0x10 * i), 0x10, g_cdvdman_ptoc, &rmode, 0, 0);
8194 sceCdRead0(0x4B, 1, g_cdvdman_ptoc, &rmode, 0, 0);
8198 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8200 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8204 vSetEventFlag(g_scmd_evfid, 1);
8208 memset(ndata, 0,
sizeof(ndata));
8210 if ( cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) < 0 )
8214 vSetEventFlag(g_scmd_evfid, 1);
8219 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8221 *status = (u8)g_cdvdman_istruct.m_last_error;
8222 vSetEventFlag(g_scmd_evfid, 1);
8225 dev5_reg_038 = dev5_mmio_hwport->m_dev5_reg_038;
8226 vSetEventFlag(g_scmd_evfid, 1);
8227 return (dev5_reg_038 & 5) == 5;
8231#ifdef CDVD_VARIANT_XOSD
8248 USE_DEV5_MMIO_HWPORT();
8250 memset(xorarea, 0,
sizeof(xorarea));
8251 memset(buffer, 0, 16);
8253 if ( shiftval >= 8 || xorval < 0 || xorval >= 256 )
8258 if ( !g_cdvdman_istruct.m_cd_inited )
8263 switch ( get_disk_type_ex() )
8277 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8285 dev5_mmio_hwport->m_dev5_reg_007 = 1;
8290 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8301 for ( i = 0; i < 0x14; i += 1 )
8303 sceCdRead0(75 + 16 * i, 0x10, g_cdvdman_ptoc, &rmode, 0, 0);
8312 sceCdRead0(0x4B, 1, g_cdvdman_ptoc, &rmode, 0, 0);
8316 WaitEventFlag(g_scmd_evfid, 1, 0, &efbits);
8318 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
8322 vSetEventFlag(g_scmd_evfid, 1);
8326 memset(ndata, 0,
sizeof(ndata));
8328 if ( cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) < 0 )
8332 vSetEventFlag(g_scmd_evfid, 1);
8337 if ( g_cdvdman_istruct.m_last_error !=
SCECdErNO )
8339 *status = (u8)g_cdvdman_istruct.m_last_error;
8340 vSetEventFlag(g_scmd_evfid, 1);
8350 if ( (dev5_mmio_hwport->m_dev5_reg_038 & 5) == 5 )
8357 dev5_reg_020 = dev5_mmio_hwport->m_dev5_reg_020;
8358 dev5_reg_039 = dev5_mmio_hwport->m_dev5_reg_039;
8359 xor_val_1_stk = dev5_reg_020 ^ dev5_reg_039;
8360 xor_val_2_stk = dev5_reg_039 ^ dev5_mmio_hwport->m_dev5_reg_021;
8361 dev5_reg_022 = dev5_mmio_hwport->m_dev5_reg_022;
8362 reg_039_tmp1 = dev5_mmio_hwport->m_dev5_reg_039;
8363 xor_val_3_stk = dev5_reg_022 ^ reg_039_tmp1;
8364 xor_val_4_stk = reg_039_tmp1 ^ dev5_mmio_hwport->m_dev5_reg_023;
8365 xor_val_1_xstk = dev5_mmio_hwport->m_dev5_reg_024 ^ dev5_mmio_hwport->m_dev5_reg_039;
8366 xor_val_2_xstk = dev5_mmio_hwport->m_dev5_reg_039 ^ dev5_mmio_hwport->m_dev5_reg_034;
8369 vSetEventFlag(g_scmd_evfid, 1);
8370 xorarea[0] = (xor_val_4_stk >> 4) | ((xor_val_1_xstk << 4) & 0x70);
8371 xorarea[1] = (xor_val_3_stk >> 5) | ((xor_val_4_stk << 3) & 0x78);
8372 xorarea[2] = (xor_val_2_stk >> 6) | ((xor_val_3_stk << 2) & 0x7C);
8373 xorarea[3] = (xor_val_1_stk >> 7) | ((xor_val_2_stk << 1) & 0x7E);
8374 sprintf(&xorarea[4],
"%d", ((xor_val_1_stk & 0x7F) << 10) | (xor_val_1_xstk >> 3) | ((xor_val_2_xstk >> 3) << 5));
8375 for ( i = 0; i < 9; i += 1 )
8377 xorarea[i] = xorarea[i] ^ xorval;
8381 for ( i = 0; i < 9; i += 1 )
8383 buffer[i] = (xorarea[i] << shiftval) | ((
int)(u8)xorarea[i ? i - 1 : 8] >> (8 - shiftval));
8389 memcpy(buffer, xorarea,
sizeof(xorarea));
8395#ifdef CDVD_VARIANT_OSD
8396int sceCdReadKey(u8 arg1, u8 arg2,
unsigned int command, u8 *key)
8401 char sectorbuf[0x800];
8403 USE_DEV5_MMIO_HWPORT();
8405 if ( cdvdman_isdvd() && !arg1 )
8407 if ( !DvdDual_infochk() )
8411 command = sceCdLsnDualChg(command);
8416 sceCdRead0(command, 1, sectorbuf, &rmode, 0, 0);
8418 for ( i = 0; i < 300; i += 1 )
8420 if ( !cdvdman_ncmd_sender_0C(arg1, arg2, command + i) )
8425 if ( g_cdvdman_istruct.m_last_error ==
SCECdErNO )
8430 WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
8433 dev5_reg_038 = dev5_mmio_hwport->m_dev5_reg_038;
8434 if ( (dev5_reg_038 & 1) )
8436 key[0] = dev5_mmio_hwport->m_dev5_reg_020 ^ dev5_mmio_hwport->m_dev5_reg_039;
8437 key[1] = dev5_mmio_hwport->m_dev5_reg_021 ^ dev5_mmio_hwport->m_dev5_reg_039;
8438 key[2] = dev5_mmio_hwport->m_dev5_reg_022 ^ dev5_mmio_hwport->m_dev5_reg_039;
8439 key[3] = dev5_mmio_hwport->m_dev5_reg_023 ^ dev5_mmio_hwport->m_dev5_reg_039;
8440 key[4] = dev5_mmio_hwport->m_dev5_reg_024 ^ dev5_mmio_hwport->m_dev5_reg_039;
8442 if ( (dev5_reg_038 & 2) )
8444 key[5] = dev5_mmio_hwport->m_dev5_reg_028 ^ dev5_mmio_hwport->m_dev5_reg_039;
8445 key[6] = dev5_mmio_hwport->m_dev5_reg_029 ^ dev5_mmio_hwport->m_dev5_reg_039;
8446 key[7] = dev5_mmio_hwport->m_dev5_reg_02A ^ dev5_mmio_hwport->m_dev5_reg_039;
8447 key[8] = dev5_mmio_hwport->m_dev5_reg_02B ^ dev5_mmio_hwport->m_dev5_reg_039;
8448 key[9] = dev5_mmio_hwport->m_dev5_reg_02C ^ dev5_mmio_hwport->m_dev5_reg_039;
8450 if ( (dev5_reg_038 & 4) )
8452 key[10] = dev5_mmio_hwport->m_dev5_reg_030 ^ dev5_mmio_hwport->m_dev5_reg_039;
8453 key[11] = dev5_mmio_hwport->m_dev5_reg_031 ^ dev5_mmio_hwport->m_dev5_reg_039;
8454 key[12] = dev5_mmio_hwport->m_dev5_reg_032 ^ dev5_mmio_hwport->m_dev5_reg_039;
8455 key[13] = dev5_mmio_hwport->m_dev5_reg_033 ^ dev5_mmio_hwport->m_dev5_reg_039;
8456 key[14] = dev5_mmio_hwport->m_dev5_reg_034 ^ dev5_mmio_hwport->m_dev5_reg_039;
8458 key[15] = dev5_reg_038 & 7;
8459 vSetEventFlag(g_scmd_evfid, 1);
8464#ifdef CDVD_VARIANT_DNAS
8465static int cdvdman_ncmd_sender_0C(
int arg1, u32 arg2, u32 arg3)
8471 ndata[2] = !!(arg2 >> 8);
8472 *(u32 *)&ndata[3] = !arg1 ? arg3 : 0;
8473 return cdvdman_send_ncmd(0x0C, ndata,
sizeof(ndata), 0, 0, 1) >= 0;
8479#ifdef CDVD_VARIANT_DNAS
8480 USE_DEV5_MMIO_HWPORT();
8482 g_cdvdman_cd36key = enable_shift | shiftval;
8483 dev5_mmio_hwport->m_dev5_reg_03A = ((shiftval & 7) << 4) | ((!!enable_xor) << 1) | (!!enable_shift);
8492#ifdef CDVD_VARIANT_OSD
8496#ifdef CDVD_VARIANT_XOSD
8501#ifdef CDVD_VARIANT_XOSD
8502 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8509 wdata[0] = (u8)mode;
8510 wdata[1] = (u8)block;
8511 wdata[2] = (u8)NumBlocks;
8512 retval = set_prev_command(0x40, wdata,
sizeof(wdata), (
char *)status, 1, 0);
8513#ifdef CDVD_VARIANT_XOSD
8517 g_cdvdman_config_numblocks = NumBlocks;
8519#ifdef CDVD_VARIANT_XOSD
8520 vSetEventFlag(g_scmd_evfid, 1);
8532 retval = set_prev_command(0x43, NULL, 0, (
char *)status, 1, 1);
8533 g_cdvdman_config_numblocks = 0;
8537static int read_config_process(
char *outval, u32 *status)
8543 retval = set_prev_command(0x41, NULL, 0, rdata,
sizeof(rdata), 0);
8544 *status = (u8)(rdata[14] + rdata[13] + rdata[12] + rdata[11] + rdata[10] + rdata[9] + rdata[8] + rdata[7] + rdata[6]
8545 + rdata[5] + rdata[4] + rdata[3] + rdata[2] + rdata[0] + rdata[1])
8547 memcpy(outval, rdata,
sizeof(rdata) - 1);
8557 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8561 for ( retval = 0; retval < g_cdvdman_config_numblocks; retval += 1 )
8563 if ( !read_config_process((
char *)buffer + 15 * retval, status) )
8565 VERBOSE_KPRINTF(1,
"RC_fail Command busy\n");
8570 VERBOSE_KPRINTF(1,
"RC_fail status: 0x%02x\n", *status);
8574 vSetEventFlag(g_scmd_evfid, 1);
8578static int write_config_process(
const char *inval, u32 *status)
8584 memcpy(wdata, inval, 15);
8585 wdata[15] = wdata[14] + wdata[13] + wdata[12] + wdata[11] + wdata[10] + wdata[9] + wdata[8] + wdata[7] + wdata[6]
8586 + wdata[5] + wdata[4] + wdata[3] + wdata[2] + wdata[0] + wdata[1];
8587 return set_prev_command(0x42, wdata,
sizeof(wdata), (
char *)status, 1, 0);
8596 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8600 for ( retval = 0; retval < g_cdvdman_config_numblocks; retval += 1 )
8602 if ( !write_config_process((
char *)buffer + 15 * retval, status) )
8604 VERBOSE_KPRINTF(1,
"WC_fail Command busy\n");
8609 VERBOSE_KPRINTF(1,
"WC_fail status: 0x%02x\n", *status);
8613 vSetEventFlag(g_scmd_evfid, 1);
8623 return set_prev_command(0x0C, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1) && !rdata[0];
8627#ifdef CDVD_VARIANT_XOSD
8629int sceCdXLEDCtl(u8 arg1, u8 arg2, u32 *param, u32 *status)
8636 if ( !g_cdvdman_minver_50600 )
8644 retval = set_prev_command(0x2D, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
8649 *status = (u8)rdata[0];
8650 *param = (u8)rdata[1];
8655#ifdef CDVD_VARIANT_XOSD
8659 if ( !g_cdvdman_minver_50600 )
8665 return set_prev_command(0x2E, NULL, 0, (
char *)status, 1, 1);
8669#ifdef CDVD_VARIANT_XOSD
8670int sceCdResetWakeupReason(u32 *inbuf, u32 *status)
8672 if ( !g_cdvdman_minver_50600 )
8678 return cdvdman_write_scmd_swap_dev5(0x2F, (
char *)inbuf, 16, (
char *)status, 1, 1);
8682#ifdef CDVD_VARIANT_XOSD
8683int cdvdman_169(u32 *arg1, u32 *status)
8691 if ( !g_cdvdman_minver_50600 )
8697 if ( vPollEventFlag(g_scmd_evfid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
8701 memset(arg1, 0, 16);
8704 vSetEventFlag(g_scmd_evfid, 1);
8708 for ( i = 0; i < 2 && !rdata[0]; i += 1 )
8715 retval = cdvdman_write_scmd_swap_dev5(0x30, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 0);
8716 memcpy(&arg1[i * 2], &rdata[1],
sizeof(rdata) - 1);
8724#ifdef CDVD_VARIANT_XOSD
8733 if ( !g_cdvdman_minver_50600 )
8741 retval = set_prev_command(0x2C, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
8746 *status = (u8)rdata[0];
8747 *param = (u8)rdata[1];
8752#ifdef CDVD_VARIANT_XOSD
8757 int saved_medium_removal_state;
8761 if ( !g_cdvdman_minver_50600 )
8768 saved_medium_removal_state = g_cdvdman_istruct.m_medium_removal_state;
8769 g_cdvdman_istruct.m_medium_removal_state = (u8)wanted_val;
8770 wdata[0] = wanted_val;
8771 retval = set_prev_command(0x31, wdata,
sizeof(wdata), (
char *)status, 1, 1);
8772 if ( !retval || *status )
8774 g_cdvdman_istruct.m_medium_removal_state = saved_medium_removal_state;
8781#ifdef CDVD_VARIANT_XOSD
8789 if ( !g_cdvdman_minver_50600 )
8795 retval = set_prev_command(0x32, NULL, 0, rdata,
sizeof(rdata), 1);
8800 *status = (u8)rdata[0];
8801 *param = (u8)rdata[1];
8804 g_cdvdman_istruct.m_medium_removal_state = *param;
8810#ifdef CDVD_VARIANT_XOSD
8816 if ( !g_cdvdman_minver_50600 )
8823 return set_prev_command(0x33, wdata,
sizeof(wdata), (
char *)status, 1, 1);
8827#ifdef CDVD_VARIANT_XOSD
8828static int sc_ffffffd8(u32 *status)
8832 if ( !g_cdvdman_minver_50600 )
8838 retval = set_prev_command(0x34, NULL, 0, (
char *)status, 1, 1);
8843 g_cdvdman_istruct.m_atapi_disk_ejected = 0;
8848#ifdef CDVD_VARIANT_XOSD
8850int cdvdman_scmd_sender_35(u32 *param, u32 *status)
8856 if ( !g_cdvdman_minver_50600 )
8862 retval = set_prev_command(0x35, NULL, 0, rdata,
sizeof(rdata), 1);
8867 *status = (u8)rdata[0];
8868 *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 RegisterIntrHandler(int irq, int mode, int(*handler)(void *), void *arg)
int ReleaseIntrHandler(int irq)
int QueryIntrContext(void)
int DisableIntr(int irq, int *res)
int CpuSuspendIntr(int *state)
int sceCdReadModelID(unsigned int *id)
int sceCdStSeekF(unsigned int lsn)
void * sceCdPOffCallback(void(*func)(void *), void *addr)
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)
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)