11#include "irx_imports.h"
21IRX_ID(
"cdvd_driver", 2, 38);
46 int m_sector_count_total;
56 unsigned int m_cache_hit_count;
68 unsigned char m_type[1];
69 unsigned char m_id[5];
71 unsigned char m_version[1];
73 unsigned char m_unused1[1];
75 unsigned char m_system_id[32];
77 unsigned char m_volume_id[32];
79 unsigned char m_unused2[8];
81 unsigned char m_volume_space_size[8];
83 unsigned char m_unused3[32];
85 unsigned char m_volume_set_size[4];
87 unsigned char m_volume_sequence_number[4];
89 unsigned char m_logical_block_size[4];
91 unsigned char m_path_table_size[8];
92 unsigned char m_type_l_path_table[4];
94 unsigned char m_opt_type_l_path_table[4];
96 unsigned char m_type_m_path_table[4];
98 unsigned char m_opt_type_m_path_table[4];
100 unsigned char m_root_directory_record[34];
102 unsigned char m_volume_set_id[128];
104 unsigned char m_publisher_id[128];
106 unsigned char m_preparer_id[128];
108 unsigned char m_application_id[128];
110 unsigned char m_copyright_file_id[37];
112 unsigned char m_abstract_file_id[37];
114 unsigned char m_bibliographic_file_id[37];
116 unsigned char m_creation_date[17];
118 unsigned char m_modification_date[17];
120 unsigned char m_expiration_date[17];
122 unsigned char m_effective_date[17];
124 unsigned char m_file_structure_version[1];
126 unsigned char m_unused4[1];
128 unsigned char m_application_data[512];
130 unsigned char m_unused5[653];
135 unsigned char m_name_len[2];
136 unsigned char m_extent[4];
137 unsigned char m_parent[2];
138 unsigned char m_name[];
143 unsigned char m_length[1];
144 unsigned char m_ext_attr_length[1];
145 unsigned char m_extent[8];
146 unsigned char m_size[8];
147 unsigned char m_date[7];
148 unsigned char m_flags[1];
149 unsigned char m_file_unit_size[1];
150 unsigned char m_interleave[1];
151 unsigned char m_volume_sequence_number[4];
152 unsigned char m_name_len[1];
153 unsigned char m_name[];
157void cdvdman_termcall(
int with_stop);
158static int cdrom_deinit();
159static int cdrom_dopen(
iop_file_t *f,
const char *dirname);
162static int cdrom_open(
iop_file_t *f,
const char *name,
int mode,
int arg4);
164static int cdrom_read(
iop_file_t *f,
void *buf,
int nbytes);
165static int cdrom_ioctl(
iop_file_t *f,
int arg,
void *param);
166static int cdrom_ioctl2(
iop_file_t *f,
int request,
void *argp,
size_t arglen,
void *bufp,
size_t buflen);
168cdrom_devctl(
iop_file_t *f,
const char *,
int cmd,
void *argp,
unsigned int arglen,
void *bufp,
unsigned int buflen);
169static int cdrom_lseek(
iop_file_t *f,
int offset,
int pos);
170static int cdrom_nulldev();
171static s64 cdrom_nulldev64();
173static int sceCdSearchDir(
char *dirname,
int layer);
174static int sceCdReadDir(
sceCdlFILE *fp,
int dsec,
int index,
int layer);
175static int cdvdman_cmpname(
const char *p,
const char *q);
176static int CD_newmedia(
int arg);
177static int cdvdman_finddir(
int target_parent,
const char *target_name);
178static int CD_cachefile(
int dsec,
int layer);
179static int disc_read(
int size,
int loc,
void *buffer,
int layer);
180static int path_tbl_init(u32 blocks,
char *fname,
int action);
181unsigned int optimized_memcpy(
char *dst,
const char *src,
unsigned int n);
182static int vSetAlarm(
iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *),
void *arg);
183static int vCancelAlarm(
unsigned int (*alarm_cb)(
void *),
void *arg);
184static int vSetEventFlag(
int ef, u32 bits);
185static int vDelayThread(
int usec);
186static int DvdDual_infochk();
187static void cdvdman_init();
190static int cdvdman_mediactl(
int code);
191static int cdvdman_ncmd_sender_06();
192static int cdvdman_gettoc(u8 *
toc);
193static int cdvdman_isdvd();
194static int sceCdRead0_Rty(u32 lsn, u32 nsec,
void *buf,
const sceCdRMode *mode,
int ncmd,
int dintrsec,
void *func);
195static int cdvdman_syncdec(
int decflag,
int decxor,
int shift, u32 data);
196static void Read2intrCDVD(
int read2_flag);
197static int sceCdGetMVersion(u8 *buffer, u32 *status);
198static int cdvdman_scmd_sender_03_48(u8 *buf, u32 *status);
199static int cdvdman_scmd_sender_3B(
int arg1);
200#ifdef CDVD_VARIANT_DNAS
201static int cdvdman_ncmd_sender_0C(
int arg1, u32 arg2, u32 arg3);
204static char g_cdvdman_cache_name[256] =
"host0:";
205static int g_cdvdman_cache_sector_size_count = 1;
206static int g_cdvdman_srchspd = 0;
207static int g_cdvdman_spinctl = -1;
208static int g_cdvdman_spinnom = -1;
209static int g_cdvdman_trycnt = -1;
210static int g_cdvdman_iocache = 0;
211static unsigned int g_cdvdman_lcn_offset = 0;
212static unsigned int g_cdvdman_numbytes_offset = 0;
213static int g_cdvdman_strmerr = 0;
217 (
void *)&cdrom_nulldev,
221 (
void *)&cdrom_nulldev,
224 (
void *)&cdrom_nulldev,
225 (
void *)&cdrom_nulldev,
226 (
void *)&cdrom_nulldev,
231 (
void *)&cdrom_nulldev,
232 (
void *)&cdrom_nulldev,
233 (
void *)&cdrom_nulldev,
234 (
void *)&cdrom_nulldev,
235 (
void *)&cdrom_nulldev,
236 (
void *)&cdrom_nulldev,
237 (
void *)&cdrom_nulldev64,
239 (
void *)&cdrom_nulldev,
240 (
void *)&cdrom_nulldev,
244static int g_cdvdman_sync_timeout = 15000;
245static int g_cdvdman_stream_timeout = 5000;
246#ifdef CDVD_VARIANT_DNAS
249static int g_verbose_level = 0;
251static unsigned int g_cache_count = 0;
252static unsigned int g_cache_table = 0;
253static unsigned int g_cdvdman_pathtblsize = 0;
254static int g_cache_path_size = 0;
255static int g_cache_path_fd = -1;
256static int g_cdvdman_fs_cdsec = 0;
257static int g_cdvdman_fs_layer = -1;
258static int g_cdvdman_fs_cache = 0;
259static int g_cdvdman_fs_base2 = 0;
260static int g_cdvdman_clk_flg = 0;
261static int g_cdvdman_cd36key = 0;
262static int g_cdvdman_ee_rpc_fno = 0;
263static int g_cdvdman_mmode = 0;
264static int g_cdvdman_last_cmdfunc = 0;
265static int g_cdvdman_minver_10700 = 0;
266static int g_cdvdman_minver_20200 = 0;
267static int g_cdvdman_minver_20400 = 0;
268static int g_cdvdman_minver_20800 = 0;
269static int g_cdvdman_emudvd9 = 0;
270static int g_cdvdman_minver_50000 = 0;
271static int g_cdvdman_minver_50200 = 0;
272static int g_cdvdman_minver_50400 = 0;
273static int g_cdvdman_minver_50600 = 0;
274static int g_cdvdman_minver_60000 = 0;
275static int g_cdvdman_minver_60200 = 0;
276static int g_cdvdman_minver_x_model_15 = 0;
277static char *g_masterdisc_header =
"PlayStation Master Disc";
278static char g_cdvdman_ncmd = 6;
279static int g_cdvdman_chmedia = 0;
280static int g_cdvdman_chflags[4] = {1, 1, 1, 1};
281static int g_cdvdman_rtindex = 0;
282static int g_cdvdman_retries = 0;
283static u8 *g_cdvdman_ptoc;
284static int g_scmd_evid;
285static void *g_cdvdman_temp_buffer_ptr;
286static int g_sfile_evid;
287static int g_ncmd_evid;
288static int g_fio_fsv_evid;
289static int g_cdvdman_intr_efid;
291static void *g_cdvdman_poffarg;
292static void (*g_cdvdman_cdstm0cb)(int);
294static void (*g_cdvdman_poff_cb)(
void *userdata);
295static void (*g_cdvdman_cdstm1cb)(int);
296static int g_cdvdman_cmdfunc;
298static char g_cdvdman_sfname[1024];
301static int g_cdvdman_pathtblflag;
302static char g_cdvdman_fs_rbuf[2048];
303static int g_cdvdman_readptr;
306static void *g_cdvdman_readbuf;
308static char g_cdvdman_fsvrbuf[42128];
311int _start(
int ac,
char **av)
316 if ( RegisterLibraryEntries(&_exp_cdvdman) )
318 return MODULE_NO_RESIDENT_END;
320 DelDrv(g_cdvdman_cddev.name);
321 if ( AddDrv(&g_cdvdman_cddev) )
324 return MODULE_NO_RESIDENT_END;
326 g_cdvdman_ptoc = (u8 *)&g_cdvdman_fsvrbuf[0x924];
327 g_cdvdman_temp_buffer_ptr = g_cdvdman_fsvrbuf;
330 SetRebootTimeLibraryHandlingMode(&_exp_cdvdman, 2);
333 _exp_cdvdman.mode &= ~6;
334 _exp_cdvdman.mode |= 2;
336 return MODULE_RESIDENT_END;
339void *sceGetFsvRbuf(
void)
341 return g_cdvdman_fsvrbuf;
352 PRINTF(
"cdvdman Init\n");
353 g_cdvdman_istruct.m_wait_flag = 1;
354 g_cdvdman_istruct.m_scmd_flag = 1;
355 g_cdvdman_istruct.m_read2_flag = 0;
356 g_cdvdman_istruct.m_stream_flag = 0;
357 g_cdvdman_istruct.m_last_error = 0;
358 g_cdvdman_istruct.m_layer_1_lsn = 0;
359 g_cdvdman_istruct.m_use_toc = 0;
360 g_cdvdman_istruct.m_last_read_timeout = 0;
361 g_cdvdman_istruct.m_power_flag = 0;
362 g_cdvdman_istruct.m_current_dvd = 0;
363 g_cdvdman_istruct.m_dual_layer_emulation = 0;
364 g_cdvdman_istruct.m_dec_state = 0;
365 g_cdvdman_istruct.m_check_version = 0;
366 g_cdvdman_istruct.m_dec_shift = 0;
367 g_cdvdman_istruct.m_opo_or_para = -1;
368 g_cdvdman_istruct.m_no_dec_flag = 0;
369 g_cdvdman_istruct.m_cd_inited = 0;
370 g_cdvdman_istruct.m_tray_is_open = 0;
371 g_cdvdman_ee_rpc_fno = 0;
372 g_cdvdman_spinctl = -1;
376 g_cdvdman_intr_efid = CreateEventFlag(&
event);
377 g_scmd_evid = CreateEventFlag(&
event);
378 g_ncmd_evid = CreateEventFlag(&
event);
379 g_sfile_evid = CreateEventFlag(&
event);
380 g_fio_fsv_evid = CreateEventFlag(&
event);
381 ClearEventFlag(g_cdvdman_intr_efid, ~0x4);
382 ClearEventFlag(g_cdvdman_intr_efid, ~0x10);
383 SetEventFlag(g_cdvdman_intr_efid, 0x29);
384 SetEventFlag(g_ncmd_evid, 1);
385 SetEventFlag(g_scmd_evid, 1);
386 SetEventFlag(g_sfile_evid, 1);
387 SetEventFlag(g_fio_fsv_evid, 1);
388 g_cdvdman_spinnom = -1;
389 g_cdvdman_trycnt = -1;
390 sceCdSC(0xFFFFFFF3, &scres_unused);
391 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
393 g_cdvdman_fhinfo[i].m_fd_flags = 0;
398void cdvdman_termcall(
int with_stop)
402 USE_DEV5_MMIO_HWPORT();
404 VERBOSE_KPRINTF(1,
"CDVD:library Terminate Call %d\n", with_stop);
411 if ( g_cdvdman_istruct.m_cd_inited )
413 cdvdman_ncmd_sender_06();
415 for ( i = 0; i < 50000; i += 1 )
417 if ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
424 if ( (dmac_ch_get_chcr(3) & 0x1000000) )
426 dev5_mmio_hwport->m_dev5_reg_007 = 1;
428 dmac_ch_set_chcr(3, 0);
435static int cdrom_deinit()
439 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
441 g_cdvdman_fhinfo[i].m_fd_flags = 0;
443 DeleteEventFlag(g_fio_fsv_evid);
444 DeleteEventFlag(g_cdvdman_intr_efid);
445 DeleteEventFlag(g_ncmd_evid);
446 DeleteEventFlag(g_scmd_evid);
447 DeleteEventFlag(g_sfile_evid);
451static int cdvdman_devready()
454 USE_DEV5_MMIO_HWPORT();
456 for ( i = 0; i < 100; i += 1 )
458 if ( (dev5_mmio_hwport->m_dev5_reg_00A & 1) )
460 g_cdvdman_iocache = 0;
463 if ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) == 0x40 && !g_cdvdman_istruct.m_read2_flag && !g_cdvdman_ee_rpc_fno )
472static int cdvdman_l0check(
int layer)
475 && (g_cdvdman_istruct.m_dual_layer_emulation || g_cdvdman_istruct.m_opo_or_para == 1 || g_cdvdman_istruct.m_opo_or_para == 2);
478static void cdvdman_iormode(
sceCdRMode *rmode,
int fmode,
int layer)
481 rmode->
trycount = (g_cdvdman_trycnt == -1) ? 16 : g_cdvdman_trycnt;
482 if ( cdvdman_l0check(layer) )
484 if ( g_cdvdman_spinnom == -1 )
495 else if ( g_cdvdman_spinnom == -1 )
529static int cdrom_dopen(
iop_file_t *f,
const char *dirname)
533 size_t path_name_ind;
538 VERBOSE_PRINTF(1,
"fileIO DOPEN name= %s layer %d\n", dirname, f->
unit);
539 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
540 for ( i = 0; (i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0]))) && g_cdvdman_fhinfo[i].m_fd_flags;
544 if ( i == (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])) )
546 SetEventFlag(g_fio_fsv_evid, 1);
550 is_devready = cdvdman_devready();
551 if ( is_devready < 0 )
553 SetEventFlag(g_fio_fsv_evid, 1);
556 strncpy(path_name, dirname,
sizeof(path_name));
557 if ( !strcmp(path_name,
".") )
559 strcpy(path_name,
"\\.");
561 path_name_ind = strlen(path_name);
562 path_name_ind -= (path_name_ind >= 2) ? 2 : 0;
563 if ( strcmp(&path_name[path_name_ind],
"\\.") )
565 strcat(path_name,
"\\.");
567 if ( (
unsigned int)(f->
unit) >= 2 )
569 PRINTF(
"open fail name %s\n", path_name);
570 SetEventFlag(g_fio_fsv_evid, 1);
573 g_cdvdman_fhinfo[i].m_file_lsn = 0;
574 g_cdvdman_srchspd = 0;
575 file_lsn_tmp = sceCdSearchDir(path_name, f->
unit);
576 if ( file_lsn_tmp < 0 )
578 PRINTF(
"open fail directory %s\n", path_name);
579 SetEventFlag(g_fio_fsv_evid, 1);
582 g_cdvdman_fhinfo[i].m_file_lsn = file_lsn_tmp;
583 g_cdvdman_fhinfo[i].m_read_pos = 0;
584 g_cdvdman_fhinfo[i].m_filemode = 0;
585 g_cdvdman_fhinfo[i].m_fd_flags = 1;
586 g_cdvdman_fhinfo[i].m_fd_layer = f->
unit;
587 SetEventFlag(g_fio_fsv_evid, 1);
605 for ( i = 0; i < (
sizeof(buf->mtime) /
sizeof(buf->mtime[0])); i += 1 )
607 buf->mtime[i] = fp->m_file_struct.date[i];
608 buf->atime[i] = fp->m_file_struct.date[i];
609 buf->ctime[i] = fp->m_file_struct.date[i];
611 buf->size = fp->m_file_struct.size;
616static int cdvdman_cdfname(
char *filename)
620 filename_len = strlen(filename);
621 if ( filename_len >= 3 && !(filename[filename_len - 2] !=
';' && filename[filename_len - 1] !=
'1') )
625 strcat(filename,
";1");
636 VERBOSE_PRINTF(1,
"fileIO GETSTAT name= %s layer= %d\n", name, f->
unit);
637 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
638 devready_tmp = cdvdman_devready();
639 if ( devready_tmp < 0 )
641 SetEventFlag(g_fio_fsv_evid, 1);
644 strncpy(filename, name,
sizeof(filename));
645 if ( !strcmp(filename,
".") )
647 strcpy(filename,
"\\.");
649 if ( !strcmp(filename,
"\\") )
651 strcpy(filename,
"\\.");
653 if ( !strlen(filename) )
655 strcpy(filename,
"\\.");
657 g_cdvdman_srchspd = 0;
659 memset(&fp, 0,
sizeof(fp));
664 PRINTF(
"open fail name %s\n", name);
665 SetEventFlag(g_fio_fsv_evid, 1);
668 cdvdman_fillstat(filename, buf, &fp);
669 SetEventFlag(g_fio_fsv_evid, 1);
680 memset(&fp, 0,
sizeof(fp));
681 VERBOSE_PRINTF(1,
"fileIO DREAD\n");
682 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
683 devready_tmp = cdvdman_devready();
684 if ( devready_tmp < 0 )
686 SetEventFlag(g_fio_fsv_evid, 1);
689 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
690 g_cdvdman_srchspd = 0;
691 devready_tmp = sceCdReadDir(&fp.m_file_struct, fh->m_file_lsn, fh->m_read_pos, fh->m_fd_layer);
692 if ( devready_tmp < 0 )
694 SetEventFlag(g_fio_fsv_evid, 1);
700 devready_tmp = strlen(fp.m_file_struct.name);
702 strncpy(buf->name, fp.m_file_struct.name,
sizeof(buf->name));
703 cdvdman_fillstat(fp.m_file_struct.name, &buf->stat, &fp);
704 SetEventFlag(g_fio_fsv_evid, 1);
710 int cache_remove_result;
712 int cache_file_fd_new;
714 unsigned int file_size_bsr_17;
715 char cache_filename[512];
717 unsigned int ioctl_arg;
719 g_cdvdman_iocache = 0;
722 "%sCache_%d_%d_%d_%d",
723 g_cdvdman_cache_name,
726 (
int)fh->m_file_size,
728 cache_remove_result = 0;
729 VERBOSE_KPRINTF(1,
"Cachefile:%s Open_or_Close:%d\n", cache_filename, open_or_close);
736 fh->m_fd_rbsize = g_cdvdman_cache_sector_size_count ? (g_cdvdman_cache_sector_size_count << 11) : 0x800;
737 fh->m_fd_rcvbuf = (u8 *)AllocSysMemory(ALLOC_LAST, fh->m_fd_rbsize, 0);
738 if ( !fh->m_fd_rcvbuf )
740 VERBOSE_KPRINTF(1,
"Rcvbuf MemAlloc Fail\n");
745 fh->m_cache_file_fd = -1;
746 cache_result = open(cache_filename, O_TRUNC | O_CREAT | O_RDWR, 0x1ff );
747 cache_file_fd_new = cache_result;
748 if ( cache_result >= 0 )
750 u32 file_size_sectors;
751 unsigned int file_size_bsr_6;
753 file_size_sectors = (fh->m_file_size >> 11) + ((!!((fh->m_file_size & 0x7FF))));
754 file_size_bsr_3 = (file_size_sectors >> 3) + (!!(file_size_sectors & 7));
755 file_size_bsr_6 = (file_size_bsr_3 >> 3) + (!!((file_size_bsr_3 & 7)));
756 file_size_bsr_17 = (file_size_bsr_6 >> 11) + (!!((file_size_bsr_6 & 0x7FF)));
757 ioctl_arg = (file_size_bsr_17 + file_size_sectors + 8) << 11;
758 for ( i = 0; i < fh->m_fd_rbsize; i += 1 )
760 fh->m_fd_rcvbuf[i] = 0;
762 if ( !strncmp(cache_filename,
"pfs", 3) )
764 cache_result = ioctl2(cache_file_fd_new, PIOCALLOC, &ioctl_arg, 4, 0, 0);
767 if ( cache_result >= 0 )
769 cache_result = lseek(cache_file_fd_new, 0, 0);
771 if ( cache_result >= 0 )
773 for ( i = 0; i <= 0x7FFF; i += 1 )
775 ((
char *)g_cdvdman_temp_buffer_ptr)[i] = 0;
777 for ( i = 0; (int)i < (
int)(ioctl_arg >> 15); i += 1 )
779 cache_result = write(cache_file_fd_new, g_cdvdman_temp_buffer_ptr, 0x8000);
780 if ( cache_result != 0x8000 )
782 if ( cache_result >= 0 )
790 if ( cache_result >= 0 )
792 for ( i = 0; (int)i < (
int)((ioctl_arg >> 11) - 0x10 * (ioctl_arg >> 15)); i += 1 )
794 cache_result = write(cache_file_fd_new, fh->m_fd_rcvbuf, 0x800);
795 if ( cache_result != 0x800 )
797 if ( cache_result >= 0 )
806 if ( !open_or_close || cache_result < 0 )
808 if ( fh->m_cache_file_fd != -1 )
810 cache_remove_result = close(fh->m_cache_file_fd);
811 VERBOSE_KPRINTF(1,
"Cache File Close: %d\n", cache_remove_result);
812 if ( cache_remove_result >= 0 )
814 if ( !strncmp(cache_filename,
"pfs", 3) )
816 cache_remove_result = remove(cache_filename);
818 else if ( !strncmp(cache_filename,
"host", 4) )
820 cache_remove_result = 0;
821 remove(cache_filename);
823 VERBOSE_KPRINTF(1,
"Cache File %s remove: %d\n", cache_filename, cache_remove_result);
826 fh->m_cache_file_fd = -1;
827 fh->m_max_cluster = 0;
828 fh->m_cluster_cur = -1;
829 fh->m_sector_count_total = 0;
831 FreeSysMemory(fh->m_fd_rcvbuf);
834 if ( cache_result < 0 )
836 VERBOSE_KPRINTF(1,
"cdvd_odcinit Open Error %d\n", cache_result);
838 if ( cache_remove_result < 0 )
840 VERBOSE_KPRINTF(1,
"cdvd_odcinit Close Error %d\n", cache_remove_result);
842 return (!open_or_close) ? cache_remove_result : cache_result;
844 fh->m_sector_count_total = file_size_bsr_17 << 11;
845 fh->m_cache_file_fd = cache_file_fd_new;
846 fh->m_max_cluster = (
void *)file_size_bsr_3;
847 fh->m_cluster_cur = -1;
848 VERBOSE_KPRINTF(1,
"Cache File Maked\n");
857 if ( fh->m_cluster_cur == -1 )
861 fh->m_cluster_cur = -1;
862 for ( i = 0; i < fh->m_fd_rbsize; i += 1 )
864 fh->m_fd_rcvbuf[i] = 0;
866 fileio_res = lseek(fh->m_cache_file_fd, 0, 0);
867 if ( fileio_res >= 0 )
869 for ( i = 0; i < ((
unsigned int)fh->m_sector_count_total >> 11); i += 1 )
871 fileio_res = write(fh->m_cache_file_fd, fh->m_fd_rcvbuf, 0x800);
872 if ( fileio_res < 0 )
878 if ( fileio_res >= 0 )
882 fh->m_fd_flags &= ~4;
883 cdvd_odcinit(fh, 0, index);
887static int cdvdman_invcaches()
891 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
893 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 4) )
895 cdvdman_cache_invalidate(&g_cdvdman_fhinfo[i], i);
901static int cdrom_internal_cache_read(
const iop_file_t *f,
int nbytes)
904 s16 readpos_plus_nbytes;
905 unsigned int readpos_plus_nbytes_bsr_14;
910 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
911 if ( cdvdman_devready() < 0 )
913 g_cdvdman_iocache = 0;
916 if ( fh->m_cluster_cur == -1 )
918 if ( (
void *)(8 * fh->m_fd_rbsize) < fh->m_max_cluster )
920 fh->m_cluster_cur = (fh->m_read_pos >> 14) & ~0x7;
922 lseek(fh->m_cache_file_fd, fh->m_cluster_cur >> 3, 0) < 0
923 || read(fh->m_cache_file_fd, fh->m_fd_rcvbuf, fh->m_fd_rbsize) < 0 )
925 fh->m_cluster_cur = -1;
931 fh->m_cluster_cur = -2;
934 readpos_plus_nbytes = fh->m_read_pos + nbytes;
935 readpos_plus_nbytes_bsr_14 = (readpos_plus_nbytes >> 14) - (!(readpos_plus_nbytes & 0x3FFF));
936 readpos_bsr_14 = fh->m_read_pos >> 14;
938 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);
939 cluster_cur = fh->m_cluster_cur;
940 if ( cluster_cur < 0 )
945 (
unsigned int)readpos_bsr_14 < (
unsigned int)cluster_cur
946 || readpos_plus_nbytes_bsr_14 >= cluster_cur + 8 * fh->m_fd_rbsize )
948 int cluster_write_tmp2;
949 unsigned int readpos_band;
951 if ( lseek(fh->m_cache_file_fd, cluster_cur >> 3, 0) < 0 )
953 fh->m_cluster_cur = -1;
956 cluster_write_tmp2 = (
unsigned int)fh->m_max_cluster >= fh->m_cluster_cur + 8 * fh->m_fd_rbsize ?
958 ((unsigned int)fh->m_max_cluster - fh->m_cluster_cur + 7) >> 3;
959 if ( write(fh->m_cache_file_fd, fh->m_fd_rcvbuf, cluster_write_tmp2) != cluster_write_tmp2 )
961 fh->m_cluster_cur = -1;
964 readpos_band = readpos_bsr_14 & ~0x7;
965 fh->m_cluster_cur = readpos_band;
966 readpos_band += (readpos_bsr_14 < 0) ? 7 : 0;
967 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) )
969 fh->m_cluster_cur = -1;
972 cluster_cur = fh->m_cluster_cur;
974 for ( i = readpos_bsr_14; i <= readpos_plus_nbytes_bsr_14; i += 1 )
976 if ( !(((
int)fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] >> ((i - cluster_cur) & 7)) & 1) )
981 return i <= readpos_plus_nbytes_bsr_14;
984static int cdrom_internal_write_cache(
const iop_file_t *f,
unsigned int nbytes)
997 g_cdvdman_iocache = 0;
998 if ( cdvdman_devready() < 0 )
1002 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
1003 if ( nbytes > fh->m_file_size - fh->m_read_pos )
1005 nbytes = fh->m_file_size - fh->m_read_pos;
1011 VERBOSE_KPRINTF(1,
"_cdvdfile_cache_read %d<->%d\n", fh->m_read_pos, fh->m_read_pos + nbytes);
1012 cur = ((fh->m_read_pos + nbytes) >> 14) - (!((fh->m_read_pos + nbytes) & 0x3FFF));
1013 rst = fh->m_read_pos >> 14;
1014 cluster_cur = (fh->m_cluster_cur >= 0) ? fh->m_cluster_cur : 0;
1015 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1017 VERBOSE_KPRINTF(1,
"cache_fill rst:%d<->%d cur:%d cnt:%d\n", rst, cur, fh->m_read_pos, nbytes);
1018 for ( i = rst; i <= cur; i += 1 )
1022 "FIO Usr addr LSN:%d SEC:%d ADDR:%08x cpos= %d\n",
1023 fh->m_file_lsn + 8 * i,
1025 g_cdvdman_temp_buffer_ptr,
1026 (i * 0x4000) + fh->m_sector_count_total);
1027 if ( !(((
int)fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] >> ((i - cluster_cur) & 7)) & 1) )
1030 while ( !
sceCdRE(fh->m_file_lsn + 8 * i, 8u, g_cdvdman_temp_buffer_ptr, &rmode) )
1034 g_cdvdman_iocache = 0;
1042 if ( Error || tray_open )
1044 VERBOSE_KPRINTF(0,
"Read Error= 0x%02x\n", Error);
1047 lseek_result = lseek(fh->m_cache_file_fd, (i * 0x4000) + fh->m_sector_count_total, 0);
1048 if ( lseek_result < 0 )
1050 return lseek_result;
1052 write_ret = write(fh->m_cache_file_fd, g_cdvdman_temp_buffer_ptr, 0x4000);
1053 if ( write_ret != 0x4000 )
1055 VERBOSE_KPRINTF(1,
"write: ret:%d\n", write_ret);
1056 if ( write_ret >= 0 )
1062 fh->m_fd_rcvbuf[(i - cluster_cur) >> 3] |= 1 << ((i - cluster_cur) & 7);
1068static int cdvdfile_cache_read(
const iop_file_t *f,
void *buf,
int nbyte)
1078 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
1080 ((
unsigned int)nbyte > fh->m_file_size - fh->m_read_pos) ? fh->m_file_size - fh->m_read_pos : (
unsigned int)nbyte;
1081 VERBOSE_KPRINTF(1,
"_cdvdfile_cache_read %d<->%d\n", fh->m_read_pos, fh->m_read_pos + nbyte_tmp);
1083 if ( nbyte_tmp > 0 )
1085 fd_result = lseek(fh->m_cache_file_fd, fh->m_read_pos + fh->m_sector_count_total, 0);
1086 if ( fd_result >= 0 )
1088 fd_result = read(fh->m_cache_file_fd, buf, nbyte_tmp);
1089 fh->m_read_pos += (fd_result >= 0) ? fd_result : 0;
1095static int cdvdfile_cache_fill_read(
const iop_file_t *f,
void *buf,
int nbytes)
1099 op_result = cdvdman_devready();
1100 if ( op_result >= 0 )
1102 op_result = cdrom_internal_write_cache(f, nbytes);
1106 g_cdvdman_iocache = 0;
1108 if ( op_result >= 0 )
1110 op_result = cdvdfile_cache_read(f, buf, nbytes);
1115static int cdrom_open(
iop_file_t *f,
const char *name,
int mode,
int arg4)
1130 VERBOSE_PRINTF(1,
"fileIO OPEN name= %s mode= 0x%08x layer %d\n", name, mode, f->
unit);
1131 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
1134 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
1136 if ( !g_cdvdman_fhinfo[i].m_fd_flags && !emptyfdfound )
1141 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 8) )
1146 if ( !emptyfdfound || streamfdfound )
1148 PRINTF(
"open fail name %s\n", name);
1149 SetEventFlag(g_fio_fsv_evid, 1);
1153 fh = &g_cdvdman_fhinfo[fds1];
1154 strncpy(filename, name,
sizeof(filename));
1155 cdvdman_cdfname(filename);
1156 g_cdvdman_srchspd = (!(mode & 0x40000000) && !cdvdman_l0check(f->
unit)) ?
1157 ((g_cdvdman_spinnom == -1) ? (u16)mode : g_cdvdman_spinnom !=
SCECdSpinStm) :
1159 if ( (
unsigned int)(f->
unit) >= 2u )
1165 if ( !strncmp(name,
"sce_cdvd_lsn", 12) )
1167 strncpy(filename, name,
sizeof(filename));
1169 for ( i = 12; i < (
sizeof(filename) - 5) && filename[i] && filename[i] !=
'_'; i += 1 )
1171 if ( !filename[i] || i >= (
sizeof(filename) - 5) )
1177 fp.size = strtol(&filename[i + 5], 0, 10);
1179 fp.lsn = strtol(&filename[12], 0, 10);
1182 if ( cdvdman_devready() < 0 || !DvdDual_infochk() )
1188 fp.lsn += g_cdvdman_istruct.m_layer_1_lsn;
1195 devready_tmp = cdvdman_devready();
1196 if ( devready_tmp < 0 )
1198 SetEventFlag(g_fio_fsv_evid, 1);
1199 return devready_tmp;
1207 if ( devready_tmp < 0 )
1209 PRINTF(
"open fail name %s\n", filename);
1210 SetEventFlag(g_fio_fsv_evid, 1);
1211 return devready_tmp;
1214 g_cdvdman_srchspd = 0;
1215 if ( (mode & 0x40000000) )
1218 memset(&rmode, 0,
sizeof(rmode));
1221 rmode.
trycount = (g_cdvdman_trycnt != -1) ? g_cdvdman_trycnt : 0;
1226 SetEventFlag(g_fio_fsv_evid, 1);
1229 g_cdvdman_strmerr = 0;
1230 fh->m_fd_flags |= 8;
1232 fh->m_file_lsn = fp.lsn;
1234 fh->m_filemode = mode & ~0x40000000;
1235 fh->m_file_size = fp.size;
1236 fh->m_fd_layer = f->
unit;
1237 if ( (mode & 0x50000000) == 0x10000000 )
1240 if ( g_cache_path_fd != -1 )
1242 devready_tmp = cdvd_odcinit(fh, 1, (
int)f->
privdata);
1243 if ( devready_tmp >= 0 )
1245 fh->m_fd_flags |= 4;
1249 if ( devready_tmp < 0 )
1255 fh->m_file_size = 0;
1257 SetEventFlag(g_fio_fsv_evid, 1);
1258 return devready_tmp;
1261 SetEventFlag(g_fio_fsv_evid, 1);
1270 VERBOSE_PRINTF(1,
"fileIO CLOSE\n");
1271 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
1272 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
1273 if ( (fh->m_fd_flags & 8) )
1275 g_cdvdman_strmerr = 0;
1279 SetEventFlag(g_fio_fsv_evid, 1);
1283 if ( ((fh->m_fd_flags & 0xC) == 4 && cdvd_odcinit(fh, 0, (
int)f->
privdata) < 0) )
1285 SetEventFlag(g_fio_fsv_evid, 1);
1289 fh->m_file_size = 0;
1295 SetEventFlag(g_fio_fsv_evid, 1);
1299static int cdrom_internal_read(
const iop_file_t *f,
char *addr,
int nbytes)
1301 unsigned int sectors;
1304 int nbytes_div_2048;
1307 unsigned int sectors_count;
1311 unsigned int filesize_bsr_11;
1316 VERBOSE_PRINTF(1,
"cdvd fileIO read start\n");
1317 op_result = cdvdman_devready();
1318 if ( op_result < 0 )
1320 g_cdvdman_iocache = 0;
1323 fh = &g_cdvdman_fhinfo[(uiptr)f->
privdata];
1324 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1329 if ( (
unsigned int)nbytes > fh->m_file_size - fh->m_read_pos )
1331 nbytes = fh->m_file_size - fh->m_read_pos;
1333 filesize_bsr_11 = (fh->m_file_size >> 11) + (!!((fh->m_file_size & 0x7FF))) + fh->m_file_lsn;
1335 1,
"fds= %d read file_lbn= %d offset= %d\n", (
int)(uiptr)f->
privdata, (
int)fh->m_file_lsn, (
int)fh->m_read_pos);
1337 for ( i = 0; i < nbytes; i += nbytes_segment )
1345 nbytes_cur = nbytes - i;
1346 if ( g_cdvdman_spinctl != -1 )
1349 switch ( g_cdvdman_spinctl )
1375 lbn = fh->m_file_lsn + ((fh->m_read_pos + i) >> 11);
1377 pos_extra = (fh->m_read_pos + i) & 0x7FF;
1378 if ( nbytes_cur <= 0x4000 )
1380 nbytes_segment = nbytes_cur;
1381 nbytes_div_2048 = (nbytes_cur / 0x800) + (!!((nbytes_cur & 0x7FF)));
1382 sectors = nbytes_div_2048 + (!!pos_extra);
1386 nbytes_segment = 0x4000;
1387 if ( buf && ((fh->m_read_pos + i) & 0x7FF) && g_cdvdman_iocache )
1390 pos_sub_2048 = 0x800 - pos_extra;
1392 &addr[i], &((
const char *)g_cdvdman_temp_buffer_ptr)[0x800 * (sectors - 1) + pos_extra], 0x800 - pos_extra);
1393 g_cdvdman_iocache = 0;
1398 sectors = 8 + (!!(((fh->m_read_pos + i) & 0x7FF)));
1401 buf = g_cdvdman_temp_buffer_ptr;
1402 if ( (
unsigned int)(sectors) > filesize_bsr_11 - lbn )
1404 sectors = filesize_bsr_11 - lbn;
1406 VERBOSE_PRINTF(1,
"sce_Read LBN= %d sectors= %d\n", (
int)lbn, (
int)sectors);
1408 g_cdvdman_iocache && (lbn >= g_cdvdman_lcn_offset)
1409 && (g_cdvdman_lcn_offset + g_cdvdman_numbytes_offset >= lbn + sectors) )
1411 optimized_memcpy(&addr[i], &((
char *)buf)[0x800 * (lbn - g_cdvdman_lcn_offset) + pos_extra], nbytes_segment);
1413 else if ( ((uiptr)(addr + i) & 3) || pos_extra || (nbytes_segment != 0x4000) )
1415 sec = (sectors >= 8) ? sectors : 8;
1416 if ( sec > filesize_bsr_11 - lbn )
1418 sec = filesize_bsr_11 - lbn;
1420 VERBOSE_PRINTF(1,
"FIO Cache LSN:%d SEC:%d ADDR:%08x\n", (
int)lbn, (
int)sec, (
unsigned int)(uiptr)buf);
1421 sectors_count = (sec >= 9) ? (sec - 8) : 0;
1422 if ( sectors_count )
1424 while ( !
sceCdRE(lbn, sectors_count, buf, &rmode) )
1426 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1429 g_cdvdman_iocache = 0;
1430 g_cdvdman_spinctl = -1;
1439 PRINTF(
"Read Error= 0x%02x\n", Error);
1440 g_cdvdman_iocache = 0;
1444 while ( !
sceCdRE(lbn + sectors_count, sec - sectors_count, (
char *)buf + 0x800 * sectors_count, &rmode) )
1446 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1449 g_cdvdman_iocache = 0;
1450 g_cdvdman_spinctl = -1;
1459 PRINTF(
"Read Error= 0x%02x\n", Error);
1460 g_cdvdman_iocache = 0;
1463 g_cdvdman_lcn_offset = lbn_tmp;
1464 g_cdvdman_numbytes_offset = sec;
1465 g_cdvdman_iocache = 1;
1467 &addr[pos_sub_2048 + i],
1468 &((
const char *)g_cdvdman_temp_buffer_ptr)[!pos_sub_2048 ? pos_extra : 0],
1469 nbytes_segment - pos_sub_2048);
1474 1,
"FIO Usr addr LSN:%d SEC:%d ADDR:%08x\n", (
int)lbn, (
int)sectors, (
unsigned int)(uiptr)(addr + i));
1475 while ( !
sceCdRE(lbn, sectors, addr + i, &rmode) )
1477 VERBOSE_PRINTF(1,
"sce_Read ON Delay\n");
1480 g_cdvdman_iocache = 0;
1481 g_cdvdman_spinctl = -1;
1488 g_cdvdman_iocache = 0;
1491 PRINTF(
"Read Error= 0x%02x\n", read_error);
1495 if ( nbytes_segment <= 0 )
1497 g_cdvdman_spinctl = -1;
1498 return nbytes_segment;
1501 fh->m_read_pos += i;
1502 VERBOSE_PRINTF(1,
"fileIO read ended\n");
1503 g_cdvdman_spinctl = -1;
1507static int cdrom_stream_read(
const iop_file_t *f,
char *bbuf,
int nbytes)
1513 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
1514 g_cdvdman_strmerr = 0;
1515 cdvdman_iormode(&rmode, fh->m_filemode, f->
unit);
1520 fh->m_read_pos += buf << 11;
1524static int cdrom_read(
iop_file_t *f,
void *buf,
int nbytes)
1534 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
1535 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
1536 if ( cdvdman_mediactl(2) )
1538 g_cdvdman_iocache = 0;
1539 cdvdman_invcaches();
1541 if ( (fh->m_fd_flags & 8) )
1543 rc = cdrom_stream_read(f, (
char *)buf, nbytes);
1547 if ( !(fh->m_fd_flags & 4) )
1549 rc = cdrom_internal_read(f, (
char *)buf, nbytes);
1553 rc = cdrom_internal_cache_read(f, nbytes);
1560 fh->m_fd_flags &= ~4;
1562 cdvd_odcinit(fh, 0, (
int)f->
privdata);
1566 rc = cdvdfile_cache_fill_read(f, buf, nbytes);
1567 VERBOSE_KPRINTF(1,
"called _cdvdfile_cache_fill_read %d\n", rc);
1573 rc = cdvdfile_cache_read(f, buf, nbytes);
1574 VERBOSE_KPRINTF(1,
"called _cdvdfile_cache_read %d\n", rc);
1578 cdvdman_cache_invalidate(fh, (
int)f->
privdata);
1579 KPRINTF(
"_cdvdfile_cache Read_err OR Drive_not_ready\n", rc);
1583 rc = cdrom_internal_read(f, (
char *)buf, nbytes);
1587 SetEventFlag(g_fio_fsv_evid, 1);
1591static int cdrom_ioctl(
iop_file_t *f,
int arg,
void *param)
1598 g_cdvdman_spinnom = -1;
1606static int cdrom_ioctl2(
iop_file_t *f,
int request,
void *argp,
size_t arglen,
void *bufp,
size_t buflen)
1617 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
1618 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
1620 if ( (fh->m_fd_flags & 8) )
1624 case CIOCSTREAMPAUSE:
1631 case CIOCSTREAMRESUME:
1638 case CIOCSTREAMSTAT:
1647 SetEventFlag(g_fio_fsv_evid, 1);
1652cdrom_devctl(
iop_file_t *f,
const char *name,
int cmd,
void *argp,
unsigned int arglen,
void *bufp,
unsigned int buflen)
1657 unsigned int sc_tmp_3;
1667 if ( cmd != CDIOC_BREAK )
1669 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
1673 case CDIOC_READCLOCK:
1674 for ( i = 0; i < 3 && !retval2; i += 1 )
1676 WaitEventFlag(g_scmd_evid, 1, WEF_AND, &efbits);
1679 retval2 = (retval2 != 1) ? -
EIO : 0;
1681#ifdef CDVD_VARIANT_DNAS
1683 for ( i = 0; i < 3 && !retval2; i += 1 )
1685 WaitEventFlag(g_scmd_evid, 1, WEF_AND, &efbits);
1688 retval2 = (retval2 != 1) ? -
EIO : 0;
1694 case CDIOC_GETDISKTYP:
1697 case CDIOC_GETERROR:
1698 *(u32 *)bufp = g_cdvdman_strmerr ? g_cdvdman_strmerr :
sceCdGetError();
1706 case CDIOC_POWEROFF:
1707 for ( i = 0; i < 3 && !retval2; i += 1 )
1709 WaitEventFlag(g_scmd_evid, 1, WEF_AND, &efbits);
1712 retval2 = (retval2 != 1) ? -
EIO : 0;
1720#ifdef CDVD_VARIANT_DNAS
1722 for ( i = 0; i < 3 && !retval2; i += 1 )
1724 WaitEventFlag(g_scmd_evid, 1, WEF_AND, &efbits);
1727 retval2 = (retval2 != 1) ? -
EIO : 0;
1730 case CDIOC_STREAMINIT:
1732 retval2 = (!
sceCdStInit(*(u32 *)argp, *((u32 *)argp + 1), (
void *)*((u32 *)argp + 2))) ? -
EIO : 0;
1745 g_cdvdman_trycnt = *(u8 *)argp;
1776 case CDIOC_SETTIMEOUT:
1779 case CDIOC_READDVDDUALINFO:
1802 *(u32 *)bufp = sceCdSC(0xFFFFFFF5, &scres_unused);
1805 retval2 = (
sceCdApplySCmd(*(u8 *)argp, (
char *)argp + 4, arglen - 4, bufp) != 1) ? -
EIO : 0;
1807 case CDIOC_FSCACHEINIT:
1809 if ( g_cache_path_fd != -1 )
1814 sc_tmp_2 = (
char *)argp;
1815 for ( i = 0; i < arglen && sc_tmp_2[i] && sc_tmp_2[i] !=
','; i += 1 )
1817 g_cdvdman_cache_name[i] = sc_tmp_2[i];
1823 for ( ; (i < arglen) && sc_tmp_2[i] && sc_tmp_2[i] !=
','; i += 1 )
1830 g_cdvdman_cache_sector_size_count = strtol((
const char *)argp + sc_tmp_3, 0, 10);
1831 retval2 = path_tbl_init(strtol(&sc_tmp_2[i + 1], 0, 10), g_cdvdman_cache_name, 1);
1834 case CDIOC_FSCACHEDELETE:
1835 for ( i = 0; i < (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0])); i += 1 )
1837 if ( (g_cdvdman_fhinfo[i].m_fd_flags & 4) )
1842 retval2 = (i == (
sizeof(g_cdvdman_fhinfo) /
sizeof(g_cdvdman_fhinfo[0]))) ? path_tbl_init(0, 0, 0) : -
EBUSY;
1848 if ( cmd != CDIOC_BREAK )
1850 SetEventFlag(g_fio_fsv_evid, 1);
1855static int cdrom_lseek(
iop_file_t *f,
int offset,
int pos)
1862 VERBOSE_PRINTF(1,
"fileIO SEEK\n");
1863 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
1864 fh = &g_cdvdman_fhinfo[(int)f->
privdata];
1871 retval = fh->m_read_pos + offset;
1874 retval = fh->m_file_size - offset;
1879 if ( retval > (
int)(fh->m_file_size) )
1881 retval = fh->m_file_size;
1883 fh->m_read_pos = retval;
1884 if ( (fh->m_fd_flags & 8) )
1892 SetEventFlag(g_fio_fsv_evid, 1);
1896static int cdrom_nulldev()
1898 PRINTF(
"nulldev0 call\n");
1902static s64 cdrom_nulldev64()
1904 PRINTF(
"nulldev0 call\n");
1910 KPRINTF(
"Cdvd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
1916 if ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
1923 g_cdvdman_sync_timeout = timeout;
1926 g_cdvdman_stream_timeout = timeout;
1939 VERBOSE_KPRINTF(1,
"sceCdSync: Call mode %d Com %x\n", mode, (u8)g_cdvdman_istruct.m_cdvdman_command);
1943 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
1945 WaitEventFlag(g_cdvdman_intr_efid, 1, WEF_AND, &efbits);
1949 return !!(!sceCdCheckCmd() || (g_cdvdman_istruct.m_read2_flag));
1952 sysclk.lo = 0x9000 * g_cdvdman_sync_timeout;
1953 vSetAlarm(&sysclk, (
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
1954 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
1956 WaitEventFlag(g_cdvdman_intr_efid, 1, WEF_AND, &efbits);
1958 vCancelAlarm((
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
1962 sysclk.lo = 0x41EB0000;
1963 vSetAlarm(&sysclk, (
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
1964 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
1966 WaitEventFlag(g_cdvdman_intr_efid, 1, WEF_AND, &efbits);
1968 vCancelAlarm((
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
1971 while ( !sceCdCheckCmd() )
1973 WaitEventFlag(g_cdvdman_intr_efid, 1, WEF_AND, &efbits);
1978 sysclk.lo = 0x9000 * g_cdvdman_sync_timeout;
1979 vSetAlarm(&sysclk, (
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
1980 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
1982 WaitEventFlag(g_cdvdman_intr_efid, 1, WEF_AND, &efbits);
1984 vCancelAlarm((
unsigned int (*)(
void *))sync_timeout_alarm_cb, &sysclk);
1987 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag || g_cdvdman_ee_rpc_fno
1988 || g_cdvdman_istruct.m_stream_flag )
1990 WaitEventFlag(g_cdvdman_intr_efid, 1, WEF_AND, &efbits);
1991 if ( g_cdvdman_ee_rpc_fno )
1999 !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag || g_cdvdman_ee_rpc_fno
2000 || (g_cdvdman_istruct.m_stream_flag));
2002 WaitEventFlag(g_cdvdman_intr_efid, 0x21, WEF_OR, &efbits);
2003 ReferEventFlagStatus(g_cdvdman_intr_efid, &efinfo);
2006 if ( g_cdvdman_istruct.m_last_error )
2008 SetEventFlag(g_cdvdman_intr_efid, 0x20);
2012 WaitEventFlag(g_cdvdman_intr_efid, 0x20, WEF_AND, &efbits);
2017 while ( !sceCdCheckCmd() || g_cdvdman_istruct.m_read2_flag )
2019 WaitEventFlag(g_cdvdman_intr_efid, 1, WEF_AND, &efbits);
2025 "sceCdSync: Command= %d Error= %d\n",
2026 (u8)g_cdvdman_istruct.m_cdvdman_command,
2027 (u8)g_cdvdman_istruct.m_last_error);
2033 VERBOSE_KPRINTF(1,
"sceCdSpinCtrlIOP speed= %d\n", speed);
2034 g_cdvdman_spinctl = speed;
2044 if ( PollEventFlag(g_sfile_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
2048 for ( i = 0; i < ((
sizeof(g_cdvdman_sfname) /
sizeof(g_cdvdman_sfname[0])) - 1) && path[i]; i += 1 )
2050 g_cdvdman_sfname[i] = path[i];
2052 g_cdvdman_sfname[i] = 0;
2053 g_cdvdman_srchspd = 1;
2055 vSetEventFlag(g_sfile_evid, 1);
2066 return cdvdman_gettoc(
toc);
2072 USE_DEV5_MMIO_HWPORT();
2075 VERBOSE_KPRINTF(1,
"DISK READY call from iop\n");
2079 VERBOSE_KPRINTF(1,
"Wait Drive Ready %x\n", dev5_mmio_hwport->m_dev5_reg_005);
2082 if ( !g_cdvdman_istruct.m_read2_flag )
2091 case SCECdDETCTDVDS:
2092 case SCECdDETCTDVDD:
2097 while ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) != 0x40 )
2100 WaitEventFlag(g_cdvdman_intr_efid, 1, WEF_AND, &efbits);
2105 return (u8)dev5_mmio_hwport->m_dev5_reg_005;
2108 if ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) == 0x40 && !g_cdvdman_istruct.m_read2_flag )
2112 VERBOSE_KPRINTF(1,
"Drive Not Ready\n");
2119 USE_DEV5_MMIO_HWPORT();
2121 return (u8)dev5_mmio_hwport->m_dev5_reg_00F;
2128 USE_DEV5_MMIO_HWPORT();
2130 reg_00A_tmp = dev5_mmio_hwport->m_dev5_reg_00A;
2136 if ( !g_cdvdman_istruct.m_tray_is_open && cdvdman_scmd_sender_03_48(&rdata_tmp, &status_tmp) == 1 && !status_tmp )
2138 reg_00A_tmp &= ~SCECdStatShellOpen;
2139 if ( (rdata_tmp & 8) )
2144 if ( (reg_00A_tmp & 0x1E) )
2149 if ( g_cdvdman_istruct.m_use_toc )
2151 reg_00A_tmp &= ~SCECdStatShellOpen;
2153 if ( g_cdvdman_istruct.m_power_flag )
2162 p->sector = 16 * ((i + 150) % 75 / 10) + (i + 150) % 75 % 10;
2163 p->second = 16 * ((i + 150) / 75 % 60 / 10) + (i + 150) / 75 % 60 % 10;
2164 p->minute = 16 * ((i + 150) / 75 / 60 / 10) + (i + 150) / 75 / 60 % 10;
2170 return 75 * (60 * (10 * (p->minute >> 4) + (p->minute & 0xF)) + 10 * (p->second >> 4) + (p->second & 0xF))
2171 + 10 * (p->sector >> 4) + (p->sector & 0xF) - 150;
2174#ifdef CDVD_VARIANT_DNAS
2175static int read_id_from_rom(
int mode,
int *buf)
2185 for ( i = 0; i < (
sizeof(idinfo) /
sizeof(idinfo[0])); i += 1 )
2187 for ( j = 0; j <
sizeof(chksumstk); j += 1 )
2189 ((
char *)&idinfo)[(i * 4) + j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2190 ((
char *)&chksumstk)[j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2192 chksumint += chksumstk;
2194 for ( ; i < 0x4000; i += 1 )
2196 for ( j = 0; j <
sizeof(chksumstk); j += 1 )
2198 ((
char *)&chksumstk)[j] = ((
char *)0xBFBF0000)[(i * 4) + j];
2200 chksumint += chksumstk;
2204 KPRINTF(
"# checksum error %d\n", chksumint);
2219static int query_boot_mode_6_nonzero()
2223 BootMode = QueryBootMode(6);
2224 return !(!BootMode || (*(u16 *)BootMode & 0xFFFC) != 0x60);
2227static int query_boot_mode_6_zero()
2229 return !QueryBootMode(6);
2232static int cdvdman_readID(
int mode,
int *buf)
2239 if ( query_boot_mode_6_nonzero() )
2241 if ( read_id_from_rom(mode, buf) && mode == 1 )
2253 if ( query_boot_mode_6_zero() )
2255 if ( !
sceCdRI(id_val, &id_result) || id_result )
2262 if ( !g_readid_systemtime.lo && !g_readid_systemtime.hi )
2264 GetSystemTime(&sysclk);
2265 g_readid_systemtime = sysclk;
2271 *buf = *(u32 *)id_val >> 8;
2275 *buf = id_val[0] | 0x8004600;
2276 buf[1] = *(u32 *)&id_val[4];
2284 return cdvdman_readID(0, (
int *)guid);
2289 return cdvdman_readID(1, (
int *)
id);
2293int sceCdStInit(u32 bufmax, u32 bankmax,
void *buffer)
2298 memset(&devctl_req, 0,
sizeof(devctl_req));
2299 devctl_req.m_cmdid = 5;
2300 devctl_req.m_posszarg1 = bufmax;
2301 devctl_req.m_posszarg2 = bankmax;
2302 devctl_req.m_buffer = buffer;
2303 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2311 memset(&devctl_req, 0,
sizeof(devctl_req));
2312 devctl_req.m_rmode.
datapattern = mode->datapattern;
2313 devctl_req.m_rmode.
spindlctrl = mode->spindlctrl;
2314 devctl_req.m_cmdid = 1;
2315 devctl_req.m_posszarg1 = lbn;
2316 devctl_req.m_rmode.
trycount = mode->trycount;
2317 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2325 memset(&devctl_req, 0,
sizeof(devctl_req));
2326 devctl_req.m_cmdid = 9;
2327 devctl_req.m_posszarg1 = lsn;
2328 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2336 memset(&devctl_req, 0,
sizeof(devctl_req));
2337 devctl_req.m_posszarg1 = lbn;
2338 devctl_req.m_cmdid = 4;
2339 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2347 memset(&devctl_req, 0,
sizeof(devctl_req));
2348 devctl_req.m_cmdid = 3;
2349 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2352int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
2359 memset(&devctl_req, 0,
sizeof(devctl_req));
2360 devctl_req.m_cmdid = 1;
2361 devctl_req.m_posszarg2 = sectors;
2362 devctl_req.m_buffer = buffer;
2363 if ( devctl(
"cdrom_stm0:", 0x4394, &devctl_req,
sizeof(devctl_req), &buf, 4) < 0 )
2367 *error = devctl_req.m_error;
2376 memset(&devctl_req, 0,
sizeof(devctl_req));
2377 devctl_req.m_cmdid = 7;
2378 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2386 memset(&devctl_req, 0,
sizeof(devctl_req));
2387 devctl_req.m_cmdid = 8;
2388 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2396 memset(&devctl_req, 0,
sizeof(devctl_req));
2397 devctl_req.m_cmdid = 6;
2398 return (devctl(
"cdrom_stm0:", 0x4393, &devctl_req,
sizeof(devctl_req), &buf, 4) >= 0) ? buf : 0;
2408 VERBOSE_PRINTF(1,
"CdSearchFile: start name= %s layer= %d\n", name, layer);
2409 if ( g_cdvdman_fs_layer != layer )
2411 g_cdvdman_fs_cache = 0;
2413 if ( !cdvdman_mediactl(0) && g_cdvdman_fs_cache )
2415 VERBOSE_KPRINTF(1,
"CdSearchFile: cache dir data used\n");
2419 VERBOSE_PRINTF(1,
"CdSearchFile Topen= %s\n", name);
2420 if ( !CD_newmedia(layer) )
2422 g_cdvdman_fs_cache = 0;
2425 g_cdvdman_fs_cache = 1;
2427 if ( *name !=
'\\' )
2434 for ( i = 0; i < 8 && name[i]; i += 1 )
2436 for ( j = 0; name[i + j] !=
'\\'; j += 1 )
2438 name_buf[j] = name[i + j];
2441 parent_level = cdvdman_finddir(parent_level, name_buf);
2442 if ( parent_level == -1 )
2450 VERBOSE_PRINTF(1,
"%s: path level (%d) error\n", name, i);
2455 VERBOSE_PRINTF(1,
"%s: dir was not found\n", name);
2459 if ( !CD_cachefile(parent_level, layer) )
2461 VERBOSE_PRINTF(1,
"CdSearchFile: disc error\n");
2464 VERBOSE_PRINTF(2,
"CdSearchFile: searching %s...\n", name_buf);
2466 j < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0])) && g_cdvdman_filetbl[j].m_file_struct.name[0];
2469 VERBOSE_PRINTF(1,
"%d %s %s\n", (
int)j, g_cdvdman_filetbl[j].m_file_struct.name, name_buf);
2470 if ( cdvdman_cmpname(g_cdvdman_filetbl[j].m_file_struct.name, name_buf) )
2472 VERBOSE_PRINTF(2,
"%s:\t found\n", name_buf);
2475 fp->m_file_struct.lsn += layer ? g_cdvdman_fs_base2 : 0;
2479 VERBOSE_PRINTF(1,
"%s: not found\n", name_buf);
2483static int sceCdSearchDir(
char *dirname,
int layer)
2487 VERBOSE_PRINTF(1,
"_sceCdSearchDir: dir name %s layer %d\n", dirname, layer);
2491static int sceCdReadDir(
sceCdlFILE *fp,
int dsec,
int index,
int layer)
2493 VERBOSE_PRINTF(1,
"_sceCdReadDir: current= %d dsec= %d layer= %d\n", g_cdvdman_fs_cdsec, dsec, layer);
2494 if ( g_cdvdman_fs_cdsec != dsec || g_cdvdman_fs_layer != layer )
2496 if ( g_cdvdman_fs_layer != layer )
2498 if ( !CD_newmedia(layer) )
2502 g_cdvdman_fs_cache = 1;
2504 if ( !CD_cachefile(dsec, layer) )
2509 if ( g_cdvdman_filetbl[index].m_file_struct.name[0] )
2511 VERBOSE_PRINTF(1,
"%s:\t found dir_point %d\n", g_cdvdman_filetbl[index].m_file_struct.name, index);
2519static int cdvdman_cmpname(
const char *p,
const char *q)
2521 return !strncmp(p, q, 12);
2524static int CD_newmedia(
int arg)
2526 unsigned int DiskType;
2546 VERBOSE_PRINTF(1,
"CD_newmedia: Illegal disc media type =%d\n", (
int)DiskType);
2549 g_cdvdman_fs_base2 = 0;
2552 if ( !DvdDual_infochk() )
2554 VERBOSE_PRINTF(1,
"CD_newmedia: Get DvdDual_infochk fail\n");
2557 g_cdvdman_fs_base2 = arg ? g_cdvdman_istruct.m_layer_1_lsn : 0;
2559 if ( disc_read(1, g_cdvdman_fs_base2 + 0x10, g_cdvdman_fs_rbuf, arg) != 1 )
2561 VERBOSE_PRINTF(1,
"CD_newmedia: Read error in disc_read(PVD)\n");
2565 for ( i = 0; i < g_cdvdman_pathtblsize; i += 1 )
2567 g_cdvdman_pathtbl[i].m_cache_hit_count = 0;
2568 g_cdvdman_pathtbl[i].m_layer = 0;
2569 g_cdvdman_pathtbl[i].m_nsec = 0;
2570 g_cdvdman_pathtbl[i].m_lsn = 0;
2571 g_cdvdman_pathtbl[i].m_cache_path_sz = 0;
2575 g_cache_path_size = 0;
2577 if ( strncmp((
char *)((
iso9660_desc_t *)g_cdvdman_fs_rbuf)->m_id,
"CD001", 5) )
2579 VERBOSE_PRINTF(1,
"CD_newmedia: Disc format error in cd_read(PVD)\n");
2588 VERBOSE_PRINTF(1,
"CD_newmedia: CD Read mode\n");
2589 ptsector = *(u32 *)(((
iso9660_desc_t *)g_cdvdman_fs_rbuf)->m_type_l_path_table);
2594 VERBOSE_PRINTF(1,
"CD_newmedia: DVD Read mode\n");
2598 if ( disc_read(1, g_cdvdman_fs_base2 + ptsector, g_cdvdman_fs_rbuf, arg) != 1 )
2600 VERBOSE_PRINTF(1,
"CD_newmedia: Read error (PT:%08x)\n", ptsector);
2603 VERBOSE_PRINTF(2,
"CD_newmedia: sarching dir..\n");
2605 i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0]))
2606 && path_cur < (
iso9660_path_t *)&g_cdvdman_fs_rbuf[
sizeof(g_cdvdman_fs_rbuf)] && path_cur->m_name_len[0];
2608 path_cur = (
iso9660_path_t *)(((
char *)path_cur) + path_cur->m_name_len[0] + (path_cur->m_name_len[0] & 1)
2611 memcpy(&g_cdvdman_dirtbl[i].m_extent, path_cur->m_extent,
sizeof(path_cur->m_extent));
2612 g_cdvdman_dirtbl[i].m_number = i;
2613 memcpy(&g_cdvdman_dirtbl[i].m_parent, path_cur->m_parent,
sizeof(path_cur->m_parent));
2614 memcpy(g_cdvdman_dirtbl[i].m_name, path_cur->m_name, path_cur->m_name_len[0]);
2615 g_cdvdman_dirtbl[i].m_name[path_cur->m_name_len[0]] = 0;
2618 "\t%08x,%04x,%04x,%s\n",
2619 g_cdvdman_dirtbl[i].m_extent,
2620 g_cdvdman_dirtbl[i].m_number,
2621 g_cdvdman_dirtbl[i].m_parent,
2622 g_cdvdman_dirtbl[i].m_name);
2624 if ( i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0])) )
2626 g_cdvdman_dirtbl[i].m_parent = 0;
2628 g_cdvdman_fs_cdsec = 0;
2629 g_cdvdman_fs_layer = arg;
2630 VERBOSE_PRINTF(2,
"CD_newmedia: %d dir entries found\n", (
int)i);
2634static int cdvdman_finddir(
int target_parent,
const char *target_name)
2638 for ( i = 0; i < (
sizeof(g_cdvdman_dirtbl) /
sizeof(g_cdvdman_dirtbl[0])) && g_cdvdman_dirtbl[i].m_parent; i += 1 )
2640 if ( g_cdvdman_dirtbl[i].m_parent == target_parent && !strcmp(target_name, g_cdvdman_dirtbl[i].m_name) )
2648static int CD_cachefile(
int dsec,
int layer)
2653 if ( dsec == g_cdvdman_fs_cdsec )
2658 disc_read(1, g_cdvdman_dirtbl[dsec - 1].m_extent + (layer ? g_cdvdman_fs_base2 : 0), g_cdvdman_fs_rbuf, layer)
2661 VERBOSE_PRINTF(1,
"CD_cachefile: dir not found\n");
2662 g_cdvdman_fs_cdsec = 0;
2665 VERBOSE_PRINTF(2,
"CD_cachefile: searching...\n");
2667 i < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0]))
2668 && dirent_cur < (
iso9660_dirent_t *)&g_cdvdman_fs_rbuf[
sizeof(g_cdvdman_fs_rbuf)];
2669 i += 1, dirent_cur = (
iso9660_dirent_t *)((
char *)dirent_cur + dirent_cur->m_length[0]) )
2673 if ( !dirent_cur->m_length[0] )
2678 &g_cdvdman_filetbl[i].m_file_struct.lsn, dirent_cur->m_extent,
sizeof(g_cdvdman_filetbl[i].m_file_struct.lsn));
2680 &g_cdvdman_filetbl[i].m_file_struct.size, dirent_cur->m_size,
sizeof(g_cdvdman_filetbl[i].m_file_struct.size));
2681 file_year = dirent_cur->m_date[0] + 1900;
2682 g_cdvdman_filetbl[i].m_file_struct.
date[7] = file_year >> 8;
2683 g_cdvdman_filetbl[i].m_file_struct.
date[6] = file_year;
2684 g_cdvdman_filetbl[i].m_file_struct.
date[5] = dirent_cur->m_date[1];
2685 g_cdvdman_filetbl[i].m_file_struct.
date[4] = dirent_cur->m_date[2];
2686 g_cdvdman_filetbl[i].m_file_struct.
date[3] = dirent_cur->m_date[3];
2687 g_cdvdman_filetbl[i].m_file_struct.
date[2] = dirent_cur->m_date[4];
2688 g_cdvdman_filetbl[i].m_file_struct.
date[1] = dirent_cur->m_date[5];
2689 g_cdvdman_filetbl[i].m_flags = dirent_cur->m_flags[0];
2693 strcpy(g_cdvdman_filetbl[i].m_file_struct.name,
".");
2696 strcpy(g_cdvdman_filetbl[i].m_file_struct.name,
"..");
2699 memcpy(g_cdvdman_filetbl[i].m_file_struct.name, dirent_cur->m_name, dirent_cur->m_name_len[0]);
2700 g_cdvdman_filetbl[i].m_file_struct.
name[dirent_cur->m_name_len[0]] = 0;
2705 "\t lsn %d size %d name:%d:%s %d/%d/%d %d:%d:%d\n",
2706 (
int)(g_cdvdman_filetbl[i].m_file_struct.lsn),
2707 (
int)(g_cdvdman_filetbl[i].m_file_struct.size),
2708 dirent_cur->m_name_len[0],
2709 g_cdvdman_filetbl[i].m_file_struct.name,
2711 g_cdvdman_filetbl[i].m_file_struct.date[5],
2712 g_cdvdman_filetbl[i].m_file_struct.date[4],
2713 g_cdvdman_filetbl[i].m_file_struct.date[3],
2714 g_cdvdman_filetbl[i].m_file_struct.date[2],
2715 g_cdvdman_filetbl[i].m_file_struct.date[1]);
2717 g_cdvdman_fs_cdsec = dsec;
2718 if ( i < (
sizeof(g_cdvdman_filetbl) /
sizeof(g_cdvdman_filetbl[0])) )
2720 g_cdvdman_filetbl[i].m_file_struct.
name[0] = 0;
2722 VERBOSE_PRINTF(2,
"CD_cachefile: %d files found\n", (
int)i);
2726static int disc_read(
int size,
int loc,
void *buffer,
int layer)
2736 VERBOSE_PRINTF(1,
"cd_read:lsn= %d size= %d layer= %d\n", loc, size, layer);
2737 if ( cdvdman_l0check(layer) )
2739 g_cdvdman_srchspd = 0;
2741 switch ( g_cdvdman_srchspd )
2757 if ( !g_cdvdman_pathtblflag )
2765 pathcachecnt = (g_cache_count < g_cdvdman_pathtblsize) ? g_cache_count : g_cdvdman_pathtblsize;
2766 for ( i = 0; i < pathcachecnt; i += 1 )
2770 "Path table Cache Search lsn:%d:%d nsec:%d:%d layer%d:%d\n",
2771 g_cdvdman_pathtbl[i].m_lsn,
2773 g_cdvdman_pathtbl[i].m_nsec,
2775 g_cdvdman_pathtbl[i].m_layer,
2778 g_cdvdman_pathtbl[i].m_lsn == loc && g_cdvdman_pathtbl[i].m_nsec == (
unsigned int)size
2779 && g_cdvdman_pathtbl[i].m_layer == layer )
2784 if ( i != pathcachecnt )
2786 VERBOSE_KPRINTF(1,
"Path table Cache ON:%d\n", g_cdvdman_pathtbl[i].m_cache_path_sz);
2787 if ( lseek(g_cache_path_fd, g_cdvdman_pathtbl[i].m_cache_path_sz, 0) >= 0 )
2789 read(g_cache_path_fd, buffer, size << 11);
2791 g_cdvdman_pathtbl[i].m_cache_hit_count += 1;
2797 if ( !
sceCdRE(loc, size, buffer, &rmode) )
2808 if ( g_cache_count >= g_cdvdman_pathtblsize )
2811 unsigned int cacheblo2;
2814 if ( g_cache_table >= g_cdvdman_pathtblsize )
2818 cachetblo1 = g_cache_table;
2819 cacheblo2 = cachetblo1;
2820 for ( i = 0; (
unsigned int)i < g_cache_count; i += 1 )
2822 if ( cacheblo2 >= g_cdvdman_pathtblsize )
2827 g_cdvdman_pathtbl[cacheblo2].m_nsec >= (
unsigned int)size
2828 && g_cdvdman_pathtbl[cacheblo2].m_cache_hit_count
2829 < (
unsigned int)g_cdvdman_pathtbl[cachetblo1].m_cache_hit_count )
2831 cachetblo1 = cacheblo2;
2835 cache_path_sz = g_cdvdman_pathtbl[cachetblo1].m_cache_path_sz;
2836 g_cache_table = cachetblo1;
2840 cache_path_sz = g_cache_path_size;
2841 g_cache_table = g_cache_count;
2844 if ( lseek(g_cache_path_fd, cache_path_sz, 0) >= 0 )
2846 int ptbl_wcache_write_res;
2848 ptbl_wcache_write_res = write(g_cache_path_fd, buffer, size << 11);
2849 if ( ptbl_wcache_write_res == size << 11 )
2852 g_cdvdman_pathtbl[g_cache_table].m_cache_path_sz = cache_path_sz;
2853 g_cdvdman_pathtbl[g_cache_table].m_lsn = loc;
2854 g_cdvdman_pathtbl[g_cache_table].m_nsec = size;
2855 g_cdvdman_pathtbl[g_cache_table].m_layer = layer;
2856 g_cdvdman_pathtbl[g_cache_table].m_cache_hit_count = 0;
2857 g_cache_path_size += (g_cache_count < g_cdvdman_pathtblsize) ? ptbl_wcache_write_res : 0;
2861 VERBOSE_KPRINTF(1,
"Ptbl_WCache:write %d", ptbl_wcache_write_res);
2862 g_cdvdman_pathtbl[g_cache_table].m_cache_hit_count = 0;
2863 g_cdvdman_pathtbl[g_cache_table].m_layer = 0;
2864 g_cdvdman_pathtbl[g_cache_table].m_nsec = 0;
2865 g_cdvdman_pathtbl[g_cache_table].m_lsn = 0;
2876 if ( !
sceCdRE(loc, size, buffer, &rmode) )
2886 VERBOSE_KPRINTF(1,
"cd_read: error code %x\n",
sceCdGetError());
2890static int path_tbl_init(u32 blocks,
char *fname,
int action)
2904 if ( !g_cdvdman_pathtbl )
2907 g_cdvdman_pathtblflag = 0;
2911 sprintf(cachedir,
"%sCache_Path", fname);
2912 v = open(cachedir, O_TRUNC | O_CREAT | O_RDWR, 0x1ff );
2917 g_cache_path_fd = v;
2918 if ( !strncmp(cachedir,
"pfs", 3) )
2920 blocksbs = blocks << 11;
2921 ioctl2(g_cache_path_fd, PIOCALLOC, &blocksbs, 4, 0, 0);
2923 for ( i = 0; i < blocks; i += 1 )
2925 v = write(g_cache_path_fd, g_cdvdman_fs_rbuf,
sizeof(g_cdvdman_fs_rbuf));
2934 g_cdvdman_pathtblsize = blocks;
2935 for ( i = 0; i < blocks; i += 1 )
2937 g_cdvdman_pathtbl[i].m_cache_hit_count = 0;
2938 g_cdvdman_pathtbl[i].m_layer = 0;
2939 g_cdvdman_pathtbl[i].m_nsec = 0;
2940 g_cdvdman_pathtbl[i].m_lsn = 0;
2941 g_cdvdman_pathtbl[i].m_cache_path_sz = 0;
2943 g_cache_path_size = 0;
2946 g_cdvdman_pathtblflag = 1;
2952 if ( g_cache_path_fd != -1 )
2954 num = close(g_cache_path_fd);
2957 if ( !strncmp(cachedir,
"pfs", 3) )
2959 num = remove(cachedir);
2961 else if ( !strncmp(cachedir,
"host", 4) )
2969 g_cache_path_fd = -1;
2972 g_cache_path_size = 0;
2973 g_cdvdman_pathtblflag = 0;
2974 g_cdvdman_pathtblsize = 0;
2975 FreeSysMemory(g_cdvdman_pathtbl);
2976 g_cdvdman_pathtbl = 0;
2980 VERBOSE_KPRINTF(1,
"path_tbl_init Error %d\n", v);
2982 return (!action) ? num : v;
2989 "\t" ".set push" "\n"
2990 "\t" ".set noat" "\n"
2991 "\t" ".set noreorder" "\n"
2992 "\t" ".global optimized_memcpy" "\n"
2993 "\t" "optimized_memcpy:" "\n"
2994 "\t" " srl $a3, $a2, 2" "\n"
2995 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
2996 "\t" " or $a3, $a0, $a1" "\n"
2997 "\t" " andi $a3, $a3, 0x3" "\n"
2998 "\t" " bnez $a3, .Loptimized_memcpy_3" "\n"
3000 "\t" " srl $a3, $a2, 2" "\n"
3001 "\t" " addiu $at, $zero, 0xC" "\n"
3002 "\t" " div $zero, $a3, $at" "\n"
3003 "\t" " mflo $a3" "\n"
3004 "\t" " mfhi $v1" "\n"
3005 "\t" " beqz $v1, .Loptimized_memcpy_2" "\n"
3007 "\t" ".Loptimized_memcpy_1:" "\n"
3008 "\t" " lw $v0, 0x0($a1)" "\n"
3009 "\t" " addiu $v1, $v1, -0x1" "\n"
3010 "\t" " sw $v0, 0x0($a0)" "\n"
3011 "\t" " addiu $a1, $a1, 0x4" "\n"
3012 "\t" " bnez $v1, .Loptimized_memcpy_1" "\n"
3013 "\t" " addiu $a0, $a0, 0x4" "\n"
3014 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3016 "\t" ".Loptimized_memcpy_2:" "\n"
3017 "\t" " lw $v0, 0x0($a1)" "\n"
3018 "\t" " lw $v1, 0x4($a1)" "\n"
3019 "\t" " lw $t0, 0x8($a1)" "\n"
3020 "\t" " lw $t1, 0xC($a1)" "\n"
3021 "\t" " lw $t2, 0x10($a1)" "\n"
3022 "\t" " lw $t3, 0x14($a1)" "\n"
3023 "\t" " lw $t4, 0x18($a1)" "\n"
3024 "\t" " lw $t5, 0x1C($a1)" "\n"
3025 "\t" " lw $t6, 0x20($a1)" "\n"
3026 "\t" " lw $t7, 0x24($a1)" "\n"
3027 "\t" " lw $t8, 0x28($a1)" "\n"
3028 "\t" " lw $t9, 0x2C($a1)" "\n"
3029 "\t" " addiu $a3, $a3, -0x1" "\n"
3030 "\t" " sw $v0, 0x0($a0)" "\n"
3031 "\t" " sw $v1, 0x4($a0)" "\n"
3032 "\t" " sw $t0, 0x8($a0)" "\n"
3033 "\t" " sw $t1, 0xC($a0)" "\n"
3034 "\t" " sw $t2, 0x10($a0)" "\n"
3035 "\t" " sw $t3, 0x14($a0)" "\n"
3036 "\t" " sw $t4, 0x18($a0)" "\n"
3037 "\t" " sw $t5, 0x1C($a0)" "\n"
3038 "\t" " sw $t6, 0x20($a0)" "\n"
3039 "\t" " sw $t7, 0x24($a0)" "\n"
3040 "\t" " sw $t8, 0x28($a0)" "\n"
3041 "\t" " sw $t9, 0x2C($a0)" "\n"
3042 "\t" " addiu $a1, $a1, 0x30" "\n"
3043 "\t" " bnez $a3, .Loptimized_memcpy_2" "\n"
3044 "\t" " addiu $a0, $a0, 0x30" "\n"
3045 "\t" " j .Loptimized_memcpy_12" "\n"
3047 "\t" ".Loptimized_memcpy_3:" "\n"
3048 "\t" " andi $a3, $a0, 0x3" "\n"
3049 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3050 "\t" " andi $a3, $a1, 0x3" "\n"
3051 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3053 "\t" " srl $a3, $a2, 2" "\n"
3054 "\t" " addiu $at, $zero, 0xC" "\n"
3055 "\t" " div $zero, $a3, $at" "\n"
3056 "\t" " mflo $a3" "\n"
3057 "\t" " mfhi $v1" "\n"
3058 "\t" " beqz $v1, .Loptimized_memcpy_5" "\n"
3060 "\t" ".Loptimized_memcpy_4:" "\n"
3061 "\t" " lwl $v0, 0x3($a1)" "\n"
3062 "\t" " lwr $v0, 0x0($a1)" "\n"
3063 "\t" " addiu $v1, $v1, -0x1" "\n"
3064 "\t" " swl $v0, 0x3($a0)" "\n"
3065 "\t" " swr $v0, 0x0($a0)" "\n"
3066 "\t" " addiu $a1, $a1, 0x4" "\n"
3067 "\t" " bnez $v1, .Loptimized_memcpy_4" "\n"
3068 "\t" " addiu $a0, $a0, 0x4" "\n"
3069 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3071 "\t" ".Loptimized_memcpy_5:" "\n"
3072 "\t" " lwl $v0, 0x3($a1)" "\n"
3073 "\t" " lwr $v0, 0x0($a1)" "\n"
3074 "\t" " lwl $v1, 0x7($a1)" "\n"
3075 "\t" " lwr $v1, 0x4($a1)" "\n"
3076 "\t" " lwl $t0, 0xB($a1)" "\n"
3077 "\t" " lwr $t0, 0x8($a1)" "\n"
3078 "\t" " lwl $t1, 0xF($a1)" "\n"
3079 "\t" " lwr $t1, 0xC($a1)" "\n"
3080 "\t" " lwl $t2, 0x13($a1)" "\n"
3081 "\t" " lwr $t2, 0x10($a1)" "\n"
3082 "\t" " lwl $t3, 0x17($a1)" "\n"
3083 "\t" " lwr $t3, 0x14($a1)" "\n"
3084 "\t" " lwl $t4, 0x1B($a1)" "\n"
3085 "\t" " lwr $t4, 0x18($a1)" "\n"
3086 "\t" " lwl $t5, 0x1F($a1)" "\n"
3087 "\t" " lwr $t5, 0x1C($a1)" "\n"
3088 "\t" " lwl $t6, 0x23($a1)" "\n"
3089 "\t" " lwr $t6, 0x20($a1)" "\n"
3090 "\t" " lwl $t7, 0x27($a1)" "\n"
3091 "\t" " lwr $t7, 0x24($a1)" "\n"
3092 "\t" " lwl $t8, 0x2B($a1)" "\n"
3093 "\t" " lwr $t8, 0x28($a1)" "\n"
3094 "\t" " lwl $t9, 0x2F($a1)" "\n"
3095 "\t" " lwr $t9, 0x2C($a1)" "\n"
3096 "\t" " addiu $a3, $a3, -0x1" "\n"
3097 "\t" " swl $v0, 0x3($a0)" "\n"
3098 "\t" " swr $v0, 0x0($a0)" "\n"
3099 "\t" " swl $v1, 0x7($a0)" "\n"
3100 "\t" " swr $v1, 0x4($a0)" "\n"
3101 "\t" " swl $t0, 0xB($a0)" "\n"
3102 "\t" " swr $t0, 0x8($a0)" "\n"
3103 "\t" " swl $t1, 0xF($a0)" "\n"
3104 "\t" " swr $t1, 0xC($a0)" "\n"
3105 "\t" " swl $t2, 0x13($a0)" "\n"
3106 "\t" " swr $t2, 0x10($a0)" "\n"
3107 "\t" " swl $t3, 0x17($a0)" "\n"
3108 "\t" " swr $t3, 0x14($a0)" "\n"
3109 "\t" " swl $t4, 0x1B($a0)" "\n"
3110 "\t" " swr $t4, 0x18($a0)" "\n"
3111 "\t" " swl $t5, 0x1F($a0)" "\n"
3112 "\t" " swr $t5, 0x1C($a0)" "\n"
3113 "\t" " swl $t6, 0x23($a0)" "\n"
3114 "\t" " swr $t6, 0x20($a0)" "\n"
3115 "\t" " swl $t7, 0x27($a0)" "\n"
3116 "\t" " swr $t7, 0x24($a0)" "\n"
3117 "\t" " swl $t8, 0x2B($a0)" "\n"
3118 "\t" " swr $t8, 0x28($a0)" "\n"
3119 "\t" " swl $t9, 0x2F($a0)" "\n"
3120 "\t" " swr $t9, 0x2C($a0)" "\n"
3121 "\t" " addiu $a1, $a1, 0x30" "\n"
3122 "\t" " bnez $a3, .Loptimized_memcpy_5" "\n"
3123 "\t" " addiu $a0, $a0, 0x30" "\n"
3124 "\t" " j .Loptimized_memcpy_12" "\n"
3126 "\t" ".Loptimized_memcpy_6:" "\n"
3127 "\t" " andi $a3, $a0, 0x3" "\n"
3128 "\t" " beqz $a3, .Loptimized_memcpy_9" "\n"
3130 "\t" " srl $a3, $a2, 2" "\n"
3131 "\t" " addiu $at, $zero, 0xC" "\n"
3132 "\t" " div $zero, $a3, $at" "\n"
3133 "\t" " mflo $a3" "\n"
3134 "\t" " mfhi $v1" "\n"
3135 "\t" " beqz $v1, .Loptimized_memcpy_8" "\n"
3137 "\t" ".Loptimized_memcpy_7:" "\n"
3138 "\t" " lw $v0, 0x0($a1)" "\n"
3139 "\t" " addiu $v1, $v1, -0x1" "\n"
3140 "\t" " swl $v0, 0x3($a0)" "\n"
3141 "\t" " swr $v0, 0x0($a0)" "\n"
3142 "\t" " addiu $a1, $a1, 0x4" "\n"
3143 "\t" " bnez $v1, .Loptimized_memcpy_7" "\n"
3144 "\t" " addiu $a0, $a0, 0x4" "\n"
3145 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3147 "\t" ".Loptimized_memcpy_8:" "\n"
3148 "\t" " lw $v0, 0x0($a1)" "\n"
3149 "\t" " lw $v1, 0x4($a1)" "\n"
3150 "\t" " lw $t0, 0x8($a1)" "\n"
3151 "\t" " lw $t1, 0xC($a1)" "\n"
3152 "\t" " lw $t2, 0x10($a1)" "\n"
3153 "\t" " lw $t3, 0x14($a1)" "\n"
3154 "\t" " lw $t4, 0x18($a1)" "\n"
3155 "\t" " lw $t5, 0x1C($a1)" "\n"
3156 "\t" " lw $t6, 0x20($a1)" "\n"
3157 "\t" " lw $t7, 0x24($a1)" "\n"
3158 "\t" " lw $t8, 0x28($a1)" "\n"
3159 "\t" " lw $t9, 0x2C($a1)" "\n"
3160 "\t" " addiu $a3, $a3, -0x1" "\n"
3161 "\t" " swl $v0, 0x3($a0)" "\n"
3162 "\t" " swr $v0, 0x0($a0)" "\n"
3163 "\t" " swl $v1, 0x7($a0)" "\n"
3164 "\t" " swr $v1, 0x4($a0)" "\n"
3165 "\t" " swl $t0, 0xB($a0)" "\n"
3166 "\t" " swr $t0, 0x8($a0)" "\n"
3167 "\t" " swl $t1, 0xF($a0)" "\n"
3168 "\t" " swr $t1, 0xC($a0)" "\n"
3169 "\t" " swl $t2, 0x13($a0)" "\n"
3170 "\t" " swr $t2, 0x10($a0)" "\n"
3171 "\t" " swl $t3, 0x17($a0)" "\n"
3172 "\t" " swr $t3, 0x14($a0)" "\n"
3173 "\t" " swl $t4, 0x1B($a0)" "\n"
3174 "\t" " swr $t4, 0x18($a0)" "\n"
3175 "\t" " swl $t5, 0x1F($a0)" "\n"
3176 "\t" " swr $t5, 0x1C($a0)" "\n"
3177 "\t" " swl $t6, 0x23($a0)" "\n"
3178 "\t" " swr $t6, 0x20($a0)" "\n"
3179 "\t" " swl $t7, 0x27($a0)" "\n"
3180 "\t" " swr $t7, 0x24($a0)" "\n"
3181 "\t" " swl $t8, 0x2B($a0)" "\n"
3182 "\t" " swr $t8, 0x28($a0)" "\n"
3183 "\t" " swl $t9, 0x2F($a0)" "\n"
3184 "\t" " swr $t9, 0x2C($a0)" "\n"
3185 "\t" " addiu $a1, $a1, 0x30" "\n"
3186 "\t" " bnez $a3, .Loptimized_memcpy_8" "\n"
3187 "\t" " addiu $a0, $a0, 0x30" "\n"
3188 "\t" " j .Loptimized_memcpy_12" "\n"
3190 "\t" ".Loptimized_memcpy_9:" "\n"
3191 "\t" " srl $a3, $a2, 2" "\n"
3192 "\t" " addiu $at, $zero, 0xC" "\n"
3193 "\t" " div $zero, $a3, $at" "\n"
3194 "\t" " mflo $a3" "\n"
3195 "\t" " mfhi $v1" "\n"
3196 "\t" " beqz $v1, .Loptimized_memcpy_11" "\n"
3198 "\t" ".Loptimized_memcpy_10:" "\n"
3199 "\t" " lwl $v0, 0x3($a1)" "\n"
3200 "\t" " lwr $v0, 0x0($a1)" "\n"
3201 "\t" " addiu $v1, $v1, -0x1" "\n"
3202 "\t" " sw $v0, 0x0($a0)" "\n"
3203 "\t" " addiu $a1, $a1, 0x4" "\n"
3204 "\t" " bnez $v1, .Loptimized_memcpy_10" "\n"
3205 "\t" " addiu $a0, $a0, 0x4" "\n"
3206 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3208 "\t" ".Loptimized_memcpy_11:" "\n"
3209 "\t" " lwl $v0, 0x3($a1)" "\n"
3210 "\t" " lwr $v0, 0x0($a1)" "\n"
3211 "\t" " lwl $v1, 0x7($a1)" "\n"
3212 "\t" " lwr $v1, 0x4($a1)" "\n"
3213 "\t" " lwl $t0, 0xB($a1)" "\n"
3214 "\t" " lwr $t0, 0x8($a1)" "\n"
3215 "\t" " lwl $t1, 0xF($a1)" "\n"
3216 "\t" " lwr $t1, 0xC($a1)" "\n"
3217 "\t" " lwl $t2, 0x13($a1)" "\n"
3218 "\t" " lwr $t2, 0x10($a1)" "\n"
3219 "\t" " lwl $t3, 0x17($a1)" "\n"
3220 "\t" " lwr $t3, 0x14($a1)" "\n"
3221 "\t" " lwl $t4, 0x1B($a1)" "\n"
3222 "\t" " lwr $t4, 0x18($a1)" "\n"
3223 "\t" " lwl $t5, 0x1F($a1)" "\n"
3224 "\t" " lwr $t5, 0x1C($a1)" "\n"
3225 "\t" " lwl $t6, 0x23($a1)" "\n"
3226 "\t" " lwr $t6, 0x20($a1)" "\n"
3227 "\t" " lwl $t7, 0x27($a1)" "\n"
3228 "\t" " lwr $t7, 0x24($a1)" "\n"
3229 "\t" " lwl $t8, 0x2B($a1)" "\n"
3230 "\t" " lwr $t8, 0x28($a1)" "\n"
3231 "\t" " lwl $t9, 0x2F($a1)" "\n"
3232 "\t" " lwr $t9, 0x2C($a1)" "\n"
3233 "\t" " addiu $a3, $a3, -0x1" "\n"
3234 "\t" " sw $v0, 0x0($a0)" "\n"
3235 "\t" " sw $v1, 0x4($a0)" "\n"
3236 "\t" " sw $t0, 0x8($a0)" "\n"
3237 "\t" " sw $t1, 0xC($a0)" "\n"
3238 "\t" " sw $t2, 0x10($a0)" "\n"
3239 "\t" " sw $t3, 0x14($a0)" "\n"
3240 "\t" " sw $t4, 0x18($a0)" "\n"
3241 "\t" " sw $t5, 0x1C($a0)" "\n"
3242 "\t" " sw $t6, 0x20($a0)" "\n"
3243 "\t" " sw $t7, 0x24($a0)" "\n"
3244 "\t" " sw $t8, 0x28($a0)" "\n"
3245 "\t" " sw $t9, 0x2C($a0)" "\n"
3246 "\t" " addiu $a1, $a1, 0x30" "\n"
3247 "\t" " bnez $a3, .Loptimized_memcpy_11" "\n"
3248 "\t" " addiu $a0, $a0, 0x30" "\n"
3249 "\t" ".Loptimized_memcpy_12:" "\n"
3250 "\t" " andi $v1, $a2, 0x3" "\n"
3251 "\t" " beqz $v1, .Loptimized_memcpy_14" "\n"
3253 "\t" ".Loptimized_memcpy_13:" "\n"
3254 "\t" " lb $v0, 0x0($a1)" "\n"
3255 "\t" " addiu $v1, $v1, -0x1" "\n"
3256 "\t" " sb $v0, 0x0($a0)" "\n"
3257 "\t" " addiu $a1, $a1, 0x1" "\n"
3258 "\t" " bnez $v1, .Loptimized_memcpy_13" "\n"
3259 "\t" " addiu $a0, $a0, 0x1" "\n"
3260 "\t" ".Loptimized_memcpy_14:" "\n"
3261 "\t" " addu $v0, $a2, $zero" "\n"
3264 "\t" ".set pop" "\n"
3269void hex_dump(u8 *addr_start,
int length)
3273 KPRINTF(
"Hex Dump addr %08x\n", addr_start);
3274 for ( i = 0; i < length; i += 1 )
3276 if ( !(i & 0xF) && i )
3280 KPRINTF(
" %02x", addr_start[i]);
3286static int cdvdman_initcfg()
3293 for ( i = 0; i <= 100; i += 1 )
3295 unsigned int mvored;
3297 if ( !sceCdGetMVersion(m_version, &eflag) && (eflag & 0x80) )
3300 VERBOSE_KPRINTF(1,
"_sceCdMV error\n");
3302 mvored = m_version[3] | (m_version[2] << 8) | (m_version[1] << 16);
3303 g_cdvdman_emudvd9 = m_version[2] & 1;
3304 VERBOSE_KPRINTF(1,
"MV %02x %02x %02x %02x\n", m_version[0], m_version[1], m_version[2], m_version[3]);
3305 g_cdvdman_minver_10700 = mvored >= 0x10700;
3306 g_cdvdman_minver_20200 = mvored >= 0x20200;
3307 g_cdvdman_minver_20400 = mvored >= 0x20400;
3308 g_cdvdman_minver_20800 = mvored >= 0x20800;
3309 g_cdvdman_minver_50000 = mvored >= 0x50000;
3310 g_cdvdman_minver_50200 = mvored >= 0x50200;
3311 g_cdvdman_minver_50400 = mvored >= 0x50400;
3312 g_cdvdman_minver_50600 = mvored >= 0x50600;
3313 g_cdvdman_minver_x_model_15 = (mvored & 0xF) == 1;
3314 g_cdvdman_minver_60000 = mvored >= 0x60000;
3315 g_cdvdman_minver_60200 = mvored >= 0x60200;
3321static int vSetAlarm(
iop_sys_clock_t *sys_clock,
unsigned int (*alarm_cb)(
void *),
void *arg)
3323 return (
QueryIntrContext() ? iSetAlarm : SetAlarm)(sys_clock, alarm_cb, arg);
3326static int vCancelAlarm(
unsigned int (*alarm_cb)(
void *),
void *arg)
3332s32 vSignalSema(s32 sema_id)
3338static int vSetEventFlag(
int ef, u32 bits)
3343static int vClearEventFlag(
int ef, u32 bits)
3353static int vDelayThread(
int usec)
3367 read_timeout = sys_clock->lo / 0x9000;
3368 KPRINTF(
"Read Time Out %d(msec)\n", read_timeout);
3369 sceCdSC(0xFFFFFFEE, &read_timeout);
3378 if (
sceCdSync(1) || PollEventFlag(g_ncmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
3382 rc = g_cdvdman_user_cb;
3383 g_cdvdman_user_cb = function;
3384 vSetEventFlag(g_ncmd_evid, 1);
3390 void (*old_cb)(
void *);
3394 old_cb = g_cdvdman_poff_cb;
3395 g_cdvdman_poff_cb = func;
3396 g_cdvdman_poffarg = addr;
3401int sceCdstm0Cb(
void (*p)(
int))
3403 g_cdvdman_cdstm0cb = p;
3407int sceCdstm1Cb(
void (*p)(
int))
3409 g_cdvdman_cdstm1cb = p;
3417 int ext_passthrough;
3418 USE_DEV5_MMIO_HWPORT();
3420 ext_passthrough = 0;
3421 s->m_wait_flag = s->m_waf_set_test;
3422 iSetEventFlag(g_cdvdman_intr_efid, 0x29);
3424 if ( *(u16 *)&s->m_cdvdman_command == 0x3105 )
3430 s->m_last_error = 0;
3433 1,
"Intr call func_num: %d Err= %02x OnTout= %d\n", g_cdvdman_cmdfunc, (u8)s->m_last_error, s->m_last_read_timeout);
3434 if ( !s->m_scmd_flag )
3436 cdvdman_write_scmd(s);
3439 (((u8)s->m_last_error ==
SCECdErREAD && g_cdvdman_cmdfunc == SCECdFuncRead)
3440 || ((u8)s->m_last_error == 1 && s->m_last_read_timeout && g_cdvdman_last_cmdfunc == 1))
3441 && !g_cdvdman_minver_20200 && !s->m_stream_flag && !s->m_dvd_flag && !s->m_recover_status
3444 s->m_sync_error = 0;
3445 s->m_interupt_read_state = 0;
3446 if ( s->m_dec_mode_set )
3448 s->m_dec_mode_last_set = 1;
3452 VERBOSE_KPRINTF(1,
"dec mode 0x00\n");
3453 s->m_read_chunk_reprocial_32 = 1 + (0x20 / ((!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk));
3454 s->m_dintrlsn = (s->m_read_lsn < 0x61) ? (s->m_read_lsn + s->m_read_sectors + 48) : (s->m_read_lsn - 80);
3456 if ( !sceCdRead0_Rty(
3458 (!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk,
3461 (u8)s->m_cdvdman_command,
3466 s->m_recover_status = 0;
3470 ext_passthrough = 1;
3474 if ( !ext_passthrough )
3476 char dev5_reg_013_masked;
3478 VERBOSE_KPRINTF(1,
"Recover_Stat:%d\n", s->m_recover_status);
3479 dev5_reg_013_masked = dev5_mmio_hwport->m_dev5_reg_013 & 0xF;
3480 if ( dev5_reg_013_masked )
3483 ((u8)s->m_last_error == 48 || ((u8)s->m_last_error == 1 && s->m_last_read_timeout)) && !s->m_recover_status
3484 && !s->m_stream_flag && g_cdvdman_cmdfunc != 9 && g_cdvdman_cmdfunc != SCECdFuncReadCDDA
3485 && (
unsigned int)s->m_read_mode.
trycount - 1 >= 4 )
3487 s->m_sync_error = 0;
3488 s->m_interupt_read_state = 0;
3489 if ( s->m_dec_mode_set )
3491 s->m_dec_mode_last_set = 2;
3495 VERBOSE_KPRINTF(1,
"dec mode 0x01\n");
3497 cdrmode.
spindlctrl = dev5_reg_013_masked + 13;
3499 if ( sceCdRead0_Rty(
3504 (u8)s->m_cdvdman_command,
3506 s->m_read_callback) )
3508 s->m_last_error = 0;
3515 s->m_last_read_timeout = 0;
3516 switch ( s->m_recover_status )
3519 s->m_sync_error = 0;
3520 s->m_interupt_read_state = 0;
3525 (!s->m_read_chunk) ? s->m_read_sectors : s->m_read_chunk,
3528 (u8)s->m_cdvdman_command,
3533 s->m_recover_status = 0;
3537 ext_passthrough = 1;
3541 s->m_sync_error = 0;
3542 s->m_interupt_read_state = 0;
3544 s->m_read_lsn, s->m_read_sectors, s->m_read_buf, &s->m_read_mode, s->m_read_chunk, s->m_read_callback) )
3546 s->m_last_error = 0;
3547 s->m_recover_status = 3;
3551 s->m_recover_status = 0;
3554 s->m_recover_status = 0;
3560 if ( ext_passthrough )
3562 s->m_last_error = 0;
3563 s->m_dintrlsn += s->m_read_sectors;
3564 s->m_read_chunk_reprocial_32 -= 1;
3565 s->m_recover_status = (!s->m_read_chunk_reprocial_32) ? 2 : 1;
3568 if ( s->m_dec_state )
3572 if ( (s->m_read2_flag == 1 || s->m_read2_flag == 3) && !s->m_use_toc )
3574 VERBOSE_KPRINTF(1,
"call Read2intrCDVD()\n");
3575 Read2intrCDVD(s->m_read2_flag);
3577 s->m_sync_error = 0;
3578 s->m_interupt_read_state = 0;
3579 if ( s->m_dec_state == 2 )
3583 if ( s->m_stream_flag == 1 && !s->m_use_toc && !s->m_read2_flag )
3585 if ( g_cdvdman_cdstm0cb )
3587 g_cdvdman_cdstm0cb(1);
3591 VERBOSE_KPRINTF(1,
"Intr func0 no seting");
3594 if ( s->m_stream_flag == 2 && !s->m_use_toc )
3596 if ( !s->m_read2_flag )
3598 if ( g_cdvdman_cdstm1cb )
3600 g_cdvdman_cdstm1cb(1);
3604 VERBOSE_KPRINTF(1,
"Intr func1 no seting");
3610 if ( !s->m_read2_flag )
3612 g_cdvdman_readptr = 0;
3616 1,
"Intr call user callback func_addr %08x num %d flg %d\n", g_cdvdman_user_cb, g_cdvdman_cmdfunc, s->m_read2_flag);
3617 if ( g_cdvdman_user_cb && g_cdvdman_cmdfunc && !s->m_read2_flag && !s->m_use_toc )
3621 cmdfunc_tmp = g_cdvdman_cmdfunc;
3622 g_cdvdman_cmdfunc = 0;
3623 if ( cmdfunc_tmp == 14 || cmdfunc_tmp == 9 )
3625 cmdfunc_tmp = SCECdFuncRead;
3627 g_cdvdman_user_cb(cmdfunc_tmp);
3629 if ( !g_cdvdman_user_cb )
3631 g_cdvdman_cmdfunc = 0;
3640 USE_DEV5_MMIO_HWPORT();
3643 s->m_waf_set_test = s->m_wait_flag;
3644 if ( (u8)s->m_last_error != 1 )
3646 s->m_last_error = dev5_mmio_hwport->m_dev5_reg_006;
3648 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 1) )
3650 s->m_waf_set_test = (!(dev5_mmio_hwport->m_dev5_reg_005 & 1)) ? 1 : -1;
3651 dev5_mmio_hwport->m_dev5_reg_008 = 1;
3654 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 4) )
3656 dev5_mmio_hwport->m_dev5_reg_008 = 4;
3657 iSetEventFlag(g_cdvdman_intr_efid, 4);
3658 iSetEventFlag(g_cdvdman_intr_efid, 0x10);
3659 if ( g_cdvdman_poff_cb )
3661 g_cdvdman_poff_cb(g_cdvdman_poffarg);
3670 s->m_waf_set_test = 1;
3671 s->m_ncmd_intr_count += 1;
3672 dev5_mmio_hwport->m_dev5_reg_008 = 2;
3674 iReferEventFlagStatus(g_cdvdman_intr_efid, &efinfo);
3677 if ( !s->m_last_error )
3679 s->m_drive_interupt_request = 1;
3687 return cdvdman_intr_cb(s);
3690static u32 cdvdman_l1start(
const u8 *
toc)
3692 return toc[23] + (
toc[22] << 8) + (
toc[21] << 16) - 0x30000 + 1;
3695static int DvdDual_infochk()
3697 if (
QueryIntrContext() || !(cdvdman_mediactl(3) || (u8)g_cdvdman_istruct.m_opo_or_para == 0xFF) )
3701 g_cdvdman_istruct.m_use_toc = 1;
3702 if ( !cdvdman_gettoc(g_cdvdman_ptoc) )
3704 g_cdvdman_istruct.m_use_toc = 0;
3705 g_cdvdman_istruct.m_opo_or_para = -1;
3708 g_cdvdman_istruct.m_use_toc = 0;
3709 g_cdvdman_istruct.m_layer_1_lsn = cdvdman_l1start(g_cdvdman_ptoc);
3710 g_cdvdman_istruct.m_opo_or_para = ((g_cdvdman_ptoc[14] & 0x60)) ? (((g_cdvdman_ptoc[14] & 0x10)) ? 2 : 1) : 0;
3711 if ( g_cdvdman_istruct.m_dual_layer_emulation )
3713 VERBOSE_KPRINTF(1,
"CDVD:DualEmuON\n");
3714 g_cdvdman_istruct.m_layer_1_lsn = g_cdvdman_istruct.m_current_dvd_lsn;
3715 g_cdvdman_istruct.m_opo_or_para = 0;
3719 "DvdDual_info: %02x\tLayer1_LSN:%d opo_or_para %d\n",
3721 g_cdvdman_istruct.m_layer_1_lsn,
3722 (u8)g_cdvdman_istruct.m_opo_or_para);
3726static u32 sceCdLsnDualChg(u32 lsn)
3728 int layer_disk_needed;
3733 layer_disk_needed = 2;
3735 if ( cdvdman_isdvd() && DvdDual_infochk() )
3737 if ( g_cdvdman_istruct.m_dual_layer_emulation )
3739 if ( !g_cdvdman_istruct.m_current_dvd && lsn >= g_cdvdman_istruct.m_current_dvd_lsn )
3741 layer_disk_needed = 1;
3743 if ( g_cdvdman_istruct.m_current_dvd && lsn < g_cdvdman_istruct.m_current_dvd_lsn )
3745 layer_disk_needed = 0;
3747 if ( layer_disk_needed == 2 )
3749 change_lsn = lsn - ((g_cdvdman_istruct.m_current_dvd) ? g_cdvdman_istruct.m_current_dvd_lsn : 0);
3756 VERBOSE_KPRINTF(0,
"CDVD: Exchange it for the Layer_%d_Disk Please.\n", layer_disk_needed);
3764 g_cdvdman_istruct.m_use_toc = 1;
3765 while ( layer_disk_needed != 2 )
3767 if ( cdvdman_isdvd() )
3771 read0_result = sceCdRead0(0xE, 1, g_cdvdman_ptoc, &cdrmode, 0, 0);
3773 if ( !g_cdvdman_istruct.m_last_error || read0_result )
3777 for ( i = 0; i < 20; i += 1 )
3779 if ( g_cdvdman_ptoc[i + 104] != g_masterdisc_header[i] )
3784 if ( i == 20 && g_cdvdman_ptoc[131] == 2 && (g_cdvdman_ptoc[132] & 2) )
3786 if ( layer_disk_needed == g_cdvdman_ptoc[133] )
3788 g_cdvdman_istruct.m_current_dvd = layer_disk_needed;
3789 layer_disk_needed = 2;
3793 VERBOSE_KPRINTF(0,
"CDVD: Layer_%d Disk not Found\n", layer_disk_needed);
3794 VERBOSE_KPRINTF(0,
"CDVD: Exchange it for the Layer_%d_Disk Please.\n", layer_disk_needed);
3795 if ( !g_cdvdman_istruct.m_current_dvd && lsn >= g_cdvdman_istruct.m_current_dvd_lsn )
3797 layer_disk_needed = 1;
3807 VERBOSE_KPRINTF(0,
"CDVD: Not Master Disk %s\n", (
const char *)&g_cdvdman_ptoc[i + 104]);
3816 VERBOSE_KPRINTF(1,
"CDVD: LsnDualChg Read Error %02x, %d\n", (u8)g_cdvdman_istruct.m_last_error, 0);
3821 vDelayThread(16000);
3824 change_lsn = lsn - ((g_cdvdman_istruct.m_current_dvd) ? g_cdvdman_istruct.m_current_dvd_lsn : 0);
3825 g_cdvdman_istruct.m_use_toc = 0;
3832 lsn - ((g_cdvdman_istruct.m_opo_or_para && (lsn >= (u32)g_cdvdman_istruct.m_layer_1_lsn)) ? 0x10 : 0);
3836 if ( has_change_lsn )
3838 VERBOSE_KPRINTF(1,
"CDVD: sceCdLsnDualChg lsn %d: change lsn %d\n", lsn, change_lsn);
3840 return has_change_lsn ? change_lsn : lsn;
3851 g_cdvdman_istruct.m_dual_layer_emulation = 0;
3852 if ( !cdvdman_isdvd() )
3856 if ( !g_cdvdman_emudvd9 )
3858 if ( !DvdDual_infochk() )
3862 *on_dual = !!g_cdvdman_istruct.m_opo_or_para;
3863 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
3866 if ( g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF )
3873 read0_result = sceCdRead0(0xE, 1, g_cdvdman_ptoc, &cdrmode, 0, 0);
3875 if ( g_cdvdman_istruct.m_last_error && !read0_result )
3877 VERBOSE_KPRINTF(1,
"CDVD: ReadDvdDualInfo Read Error %02x, %d\n", (u8)g_cdvdman_istruct.m_last_error, 0);
3880 for ( i = 0; i < 20; i += 1 )
3882 if ( g_cdvdman_ptoc[i + 104] != g_masterdisc_header[i] )
3889 if ( !DvdDual_infochk() )
3893 *on_dual = !!g_cdvdman_istruct.m_opo_or_para;
3894 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
3897 if ( g_cdvdman_ptoc[131] != 2 || !(g_cdvdman_ptoc[132] & 2) )
3901 g_cdvdman_istruct.m_current_dvd = g_cdvdman_ptoc[133];
3902 g_cdvdman_istruct.m_current_dvd_lsn =
3903 g_cdvdman_ptoc[134] + (g_cdvdman_ptoc[135] << 8) + (g_cdvdman_ptoc[136] << 16) + (g_cdvdman_ptoc[137] << 24) + 1;
3904 g_cdvdman_istruct.m_opo_or_para = 0;
3905 g_cdvdman_istruct.m_layer_1_lsn = g_cdvdman_istruct.m_current_dvd_lsn;
3906 g_cdvdman_istruct.m_dual_layer_emulation = 1;
3908 *layer1_start = g_cdvdman_istruct.m_layer_1_lsn;
3911 "sceCdReadDvdDualInfo():Cur_Disk %d layer1_start %d\n",
3912 (u8)g_cdvdman_istruct.m_current_dvd,
3913 g_cdvdman_istruct.m_current_dvd_lsn);
3917int sceCdSC(
int code,
int *param)
3928 *param = (int)g_cdvdman_poff_cb;
3929 poffarg_tmp = g_cdvdman_poffarg;
3931 return (
int)poffarg_tmp;
3935 return sceCdLsnDualChg(*param);
3937 return DvdDual_infochk();
3939 g_cdvdman_istruct.m_last_read_timeout = *param;
3942 return g_cdvdman_stream_timeout;
3944 *param = (int)&g_verbose_level;
3947 return g_cdvdman_sync_timeout;
3949 *param = (int)&g_cdvdman_istruct;
3952 BootMode = QueryBootMode(4);
3955 switch ( *(u8 *)BootMode )
3960 g_cdvdman_mmode = 0xFF;
3963 g_cdvdman_mmode = SCECdMmodeCd;
3976 return g_cdvdman_mmode == SCECdMmodeCd || g_cdvdman_mmode == 0xFF;
3978 return g_cdvdman_mmode == SCECdMmodeDvd || g_cdvdman_mmode == 0xFF;
3980 return g_cdvdman_mmode == 0xFF;
3985 return g_cdvdman_intr_efid;
3989 WaitEventFlag(g_fio_fsv_evid, 1, WEF_AND | WEF_CLEAR, &efbits);
3993 SetEventFlag(g_fio_fsv_evid, 1);
3995 g_cdvdman_ee_rpc_fno = *param;
3996 VERBOSE_KPRINTF(1,
"EE_ncmd_working code= %d\n", *param);
3997 return g_cdvdman_ee_rpc_fno;
3999 return (u16)_irx_id.v;
4001 g_cdvdman_spinctl = *param;
4004 return g_cdvdman_cd36key;
4006 return g_cdvdman_istruct.m_read2_flag;
4008 g_cdvdman_istruct.m_last_error = *(u8 *)param;
4009 return (u8)g_cdvdman_istruct.m_last_error;
4014 *param = (u8)g_cdvdman_istruct.m_last_error;
4017 g_cdvdman_istruct.m_stream_flag = code;
4019 return g_cdvdman_istruct.m_stream_flag;
4021 VERBOSE_KPRINTF(1,
"sceCdSC func_num Not found %d\n", code);
4026static void cdvdman_init()
4032 USE_DEV5_MMIO_HWPORT();
4034 g_cdvdman_user_cb = 0;
4035 g_cdvdman_poff_cb = 0;
4036 g_cdvdman_cmdfunc = 0;
4037 g_cdvdman_istruct.m_drive_interupt_request = 0;
4039 RegisterIntrHandler(IOP_IRQ_DMA_CDVD, 1, (
int (*)(
void *))intrh_dma_3, &g_cdvdman_istruct);
4041 sceCdSC(0xFFFFFFF3, &scres_unused);
4042 dmac_set_dpcr(dmac_get_dpcr() | 0x8000);
4043 dmac_ch_set_chcr(3, 0);
4044 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 4) )
4046 dev5_mmio_hwport->m_dev5_reg_008 = 4;
4048 if ( (dev5_mmio_hwport->m_dev5_reg_008 & 1) )
4050 dev5_mmio_hwport->m_dev5_reg_008 = 1;
4053 g_cdvdman_istruct.m_tray_is_open = (dev5_mmio_hwport->m_dev5_reg_00A ^ 1) & 1;
4055 BootMode = QueryBootMode(6);
4056 g_cdvdman_istruct.m_no_dec_flag = BootMode ? ((*(u16 *)BootMode & 0xFFFC) == 0x60) : 0;
4065 USE_DEV5_MMIO_HWPORT();
4067 VERBOSE_PRINTF(1,
"sceCdInit called mode= %d\n", mode);
4072 g_cdvdman_istruct.m_cd_inited = 0;
4075 cdvdman_ncmd_sender_06();
4077 VERBOSE_PRINTF(1,
"Cdvdman Exit\n");
4085 VERBOSE_PRINTF(1,
"Cdvdman Init\n");
4086 g_cdvdman_istruct.m_read2_flag = 0;
4087 g_cdvdman_istruct.m_dec_shift = 0;
4088 g_cdvdman_istruct.m_check_version = 0;
4089 g_cdvdman_istruct.m_dec_state = 0;
4092 g_cdvdman_istruct.m_cd_inited = 1;
4096 u8 ready_status_tmp;
4098 int ready_status_mask_c0h;
4100 ready_status_tmp = 0;
4101 VERBOSE_PRINTF(1,
"sceCdInit Ready check start.\n");
4102 for ( ready_status_mask_c0h = 0; ready_status_mask_c0h != 0x40; ready_status_mask_c0h = ready_status & 0xC0 )
4104 ready_status = dev5_mmio_hwport->m_dev5_reg_005;
4105 vDelayThread(10000);
4106 if ( ready_status != ready_status_tmp )
4108 ready_status_tmp = ready_status;
4109 VERBOSE_PRINTF(1,
"sceCdInit Dev5 Status %x\n", ready_status);
4112 VERBOSE_PRINTF(1,
"sceCdInit Ready check end.\n");
4114 g_cdvdman_istruct.m_wait_flag = 1;
4115 g_cdvdman_istruct.m_scmd_flag = 1;
4116 g_cdvdman_istruct.m_last_error = 0;
4117 g_cdvdman_istruct.m_last_read_timeout = 0;
4118 g_cdvdman_spinctl = -1;
4119 SetEventFlag(g_cdvdman_intr_efid, 0x29);
4120 SetEventFlag(g_ncmd_evid, 1);
4121 SetEventFlag(g_scmd_evid, 1);
4122 SetEventFlag(g_sfile_evid, 1);
4126static int set_prev_command(
int cmd,
const char *sdata,
int sdlen,
char *rdata,
int rdlen,
int check_sef)
4133 if ( check_sef == 1 && PollEventFlag(g_scmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
4137 g_cdvdman_istruct.m_scmd = cmd;
4138 g_cdvdman_istruct.m_sdlen = sdlen;
4139 g_cdvdman_istruct.m_rdlen = rdlen;
4140 for ( i = 0; i < sdlen; i += 1 )
4142 g_cdvdman_istruct.m_scmd_sd[i] = sdata[i];
4144 if ( g_cdvdman_istruct.m_wait_flag )
4146 g_cdvdman_istruct.m_scmd_flag = 1;
4147 cdvdman_write_scmd(&g_cdvdman_istruct);
4151 while ( (dmac_ch_get_chcr(3) & 0x1000000) && !g_cdvdman_istruct.m_wait_flag )
4153 VERBOSE_KPRINTF(1,
"set_prev_command: DMA Wait\n");
4155 g_cdvdman_istruct.m_scmd_flag = 1;
4156 cdvdman_write_scmd(&g_cdvdman_istruct);
4160 g_cdvdman_istruct.m_scmd_flag = 0;
4163 for ( i = 0; i < 500; i += delaybackoff )
4165 if ( g_cdvdman_istruct.m_scmd_flag )
4167 for ( j = 0; j < rdlen; j += 1 )
4169 rdata[j] = g_cdvdman_istruct.m_scmd_rd[j];
4171 if ( check_sef == 1 )
4173 vSetEventFlag(g_scmd_evid, 1);
4175 return (u8)g_cdvdman_istruct.m_scmd;
4177 vDelayThread(1000 * delaybackoff);
4178 if ( (i & 1) && delaybackoff < 16 )
4183 g_cdvdman_istruct.m_scmd_flag = 1;
4184 if ( check_sef == 1 )
4186 vSetEventFlag(g_scmd_evid, 1);
4197 USE_DEV5_MMIO_HWPORT();
4199 for ( i = 0; i <= 0; i += 1 )
4203 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
4205 *(u16 *)&s->m_scmd_flag = 1;
4208 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
4212 for ( j = 0; j < (u8)s->m_sdlen; j += 1 )
4214 dev5_mmio_hwport->m_dev5_reg_017 = s->m_scmd_sd[j];
4216 dev5_mmio_hwport->m_dev5_reg_016 = s->m_scmd;
4219 for ( j = 0; dev5_mmio_hwport->m_dev5_reg_017 & 0x80; j += 1 )
4223 *(u16 *)&s->m_scmd_flag = 1;
4230 for ( j = 0; dev5_mmio_hwport->m_dev5_reg_017 & 0x80; j += 1 )
4235 *(u16 *)&s->m_scmd_flag = 1;
4241 for ( j = 0; j < (u8)s->m_rdlen; j += 1 )
4243 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
4247 rdptr1[j] = dev5_mmio_hwport->m_dev5_reg_018;
4249 if ( j >= (u8)s->m_rdlen )
4252 VERBOSE_KPRINTF(1,
"Prev Cmd Result Over Flow\n", rdptr1);
4255 if ( (!overflowcond && j >= (u8)s->m_rdlen) || s->m_rdlen == 16 )
4259 VERBOSE_KPRINTF(1,
"Prev Cmd Result Illegal Size Try count:%d\n", i);
4263 *(u16 *)&s->m_scmd_flag = 1;
4267 for ( j = 0; j < (
sizeof(s->m_scmd_rd) /
sizeof(s->m_scmd_rd[0])); j += 1 )
4269 s->m_scmd_rd[j] = 0;
4271 if ( s->m_rdlen != (
sizeof(s->m_scmd_rd) /
sizeof(s->m_scmd_rd[0])) )
4273 rdcnt = (u8)s->m_rdlen;
4275 for ( j = 0; j < rdcnt; j += 1 )
4277 s->m_scmd_rd[j] = rdptr1[j];
4284static int cdvdman_send_scmd2(
int cmd,
const void *sdata,
int sdlen,
void *rdata,
int rdlen,
int check_sef)
4290 USE_DEV5_MMIO_HWPORT();
4292 if ( check_sef == 1 && PollEventFlag(g_scmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
4296 for ( i = 0; i <= 0; i += 1 )
4300 if ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
4302 if ( check_sef == 1 )
4304 vSetEventFlag(g_scmd_evid, 1);
4308 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40) )
4312 for ( j = 0; j < sdlen; j += 1 )
4314 dev5_mmio_hwport->m_dev5_reg_017 = ((u8 *)sdata)[j];
4316 dev5_mmio_hwport->m_dev5_reg_016 = cmd;
4317 while ( (dev5_mmio_hwport->m_dev5_reg_017 & 0x80) )
4322 for ( j = 0; !(dev5_mmio_hwport->m_dev5_reg_017 & 0x40); j += 1 )
4327 VERBOSE_KPRINTF(1,
"Prev Cmd Result Over Flow\n");
4330 rdstart[j] = dev5_mmio_hwport->m_dev5_reg_018;
4332 if ( (!cmdresoverflow && j >= rdlen) || rdlen == 16 )
4336 VERBOSE_KPRINTF(1,
"Prev Cmd Result Illegal Size Try count:%d\n", i);
4337 while ( !(dev5_mmio_hwport->m_dev5_reg_017 & 0x20) )
4341 for ( j = 0; j < 16 - rdlen; j += 1 )
4346 if ( check_sef == 1 )
4348 vSetEventFlag(g_scmd_evid, 1);
4352 for ( i = 0; i < rdlen; i += 1 )
4354 ((
char *)rdata)[i] = rdstart[i];
4356 if ( check_sef == 1 )
4358 vSetEventFlag(g_scmd_evid, 1);
4367 for ( i = 0; i <= 2500; i += 1 )
4369 if ( set_prev_command(cmdNum, (
const char *)inBuff, inBuffSize, (
char *)outBuff, 16, 1) )
4376 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
4380int sceCdApplySCmd2(u8 cmdNum,
const void *inBuff,
unsigned long int inBuffSize,
void *outBuff)
4384 for ( i = 0; i <= 2500; i += 1 )
4386 if ( cdvdman_send_scmd2(cmdNum, inBuff, inBuffSize, outBuff, 16, 1) )
4392 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
4397int sceCdApplySCmd3(u8 cmdNum,
const void *inBuff,
unsigned long int inBuffSize,
void *outBuff)
4401 for ( i = 0; i <= 2500; i += 1 )
4404 if ( set_prev_command((u8)cmdNum, inBuff, inBuffSize, outBuff, 16, 1) )
4410 KPRINTF(
"CDVD: set_prev_command TIMEOUT 5(SEC)\n");
4420 USE_DEV5_MMIO_HWPORT();
4422 if ( PollEventFlag(g_ncmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
4429 "Break call: read2_flg= %d func= %d lsn= %d csec= %d nsec= %d\n",
4430 g_cdvdman_istruct.m_read2_flag,
4432 g_cdvdman_istruct.m_cdvdman_lsn,
4433 g_cdvdman_istruct.m_cdvdman_csec,
4434 g_cdvdman_istruct.m_cdvdman_nsec);
4435 if ( g_cdvdman_istruct.m_last_read_timeout )
4437 g_cdvdman_istruct.m_read2_flag = 0;
4440 g_cdvdman_istruct.m_thread_id = GetThreadId();
4441 g_cdvdman_istruct.m_break_cdvdfsv_readchain = 1;
4442 if ( g_cdvdman_istruct.m_dec_state )
4444 g_cdvdman_istruct.m_dec_shift = 0;
4445 g_cdvdman_istruct.m_check_version = 0;
4446 g_cdvdman_istruct.m_dec_state = 0;
4449 g_cdvdman_istruct.m_recover_status = 0;
4452 iSetEventFlag(g_cdvdman_intr_efid, 0x29);
4453 iCancelAlarm((
unsigned int (*)(
void *))read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
4457 SetEventFlag(g_cdvdman_intr_efid, 0x29);
4458 CancelAlarm((
unsigned int (*)(
void *))read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
4460 if ( !g_cdvdman_istruct.m_wait_flag || g_cdvdman_istruct.m_last_read_timeout )
4462 if ( (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) == 0x40 )
4464 VERBOSE_KPRINTF(1,
"cdvd: NonInter END\n");
4465 g_cdvdman_istruct.m_wait_flag = 1;
4467 g_cdvdman_last_cmdfunc = g_cdvdman_cmdfunc;
4468 g_cdvdman_cmdfunc = SCECdFuncBreak;
4469 dev5_mmio_hwport->m_dev5_reg_007 = 1;
4470 if ( g_cdvdman_istruct.m_last_read_timeout )
4474 g_cdvdman_istruct.m_drive_interupt_request = 0;
4475 VERBOSE_KPRINTF(1,
"cdvd: Abort command On\n");
4477 vSetEventFlag(g_ncmd_evid, 1);
4484 KPRINTF(
"Cmd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
4494 s->m_dma3_param.m_dma3_msectors -= s->m_dma3_param.m_dma3_csectors;
4495 dmacbres = s->m_dma3_param.m_dma3_callback ? s->m_dma3_param.m_dma3_callback() : 1;
4496 s->m_cdvdman_dma3sec += s->m_dma3_param.m_dma3_csectors;
4497 s->m_dma3_param.m_dma3_csectors = ((u32)s->m_read_chunk > (u32)s->m_dma3_param.m_dma3_msectors) ?
4498 (u32)s->m_dma3_param.m_dma3_msectors :
4499 (u32)s->m_read_chunk;
4502 if ( s->m_dma3_param.m_dma3_msectors )
4504 dmac_ch_set_chcr(3, 0);
4505 dmac_ch_get_chcr(3);
4506 dmac_ch_set_madr(3, (u32)s->m_dma3_param.m_dma3_maddress);
4509 ((s->m_dma3_param.m_dma3_blkcount * s->m_dma3_param.m_dma3_csectors) << 16) | s->m_dma3_param.m_dma3_blkwords);
4510 dmac_ch_set_chcr(3, 0x41000200);
4511 dmac_ch_get_chcr(3);
4512 iClearEventFlag(g_cdvdman_intr_efid, ~0x20);
4517 iSetEventFlag(g_cdvdman_intr_efid, 0x20);
4520 if ( !s->m_dma3_param.m_dma3_msectors && s->m_drive_interupt_request )
4523 s->m_drive_interupt_request = 0;
4530 USE_DEV5_MMIO_HWPORT();
4532 if ( (dmac_ch_get_chcr(3) & 0x1000000) )
4534 dev5_mmio_hwport->m_dev5_reg_007 = 1;
4536 g_cdvdman_istruct.m_drive_interupt_request = 0;
4537 g_cdvdman_istruct.m_dma3_param.m_dma3_blkwords = dma3_param->m_dma3_blkwords;
4538 g_cdvdman_istruct.m_dma3_param.m_dma3_blkcount = dma3_param->m_dma3_blkcount;
4539 g_cdvdman_istruct.m_dma3_param.m_dma3_maddress = dma3_param->m_dma3_maddress;
4540 g_cdvdman_istruct.m_dma3_param.m_dma3_callback = dma3_param->m_dma3_callback;
4541 g_cdvdman_istruct.m_dma3_param.m_dma3_csectors = dma3_param->m_dma3_csectors;
4542 g_cdvdman_istruct.m_dma3_param.m_cdvdreg_howto = dma3_param->m_cdvdreg_howto;
4543 g_cdvdman_istruct.m_dma3_param.m_dma3_msectors = dma3_param->m_dma3_msectors;
4544 g_cdvdman_istruct.m_cdvdman_dma3sec = 0;
4545 dmac_ch_set_chcr(3, 0);
4546 dmac_ch_get_chcr(3);
4547 if ( dma3_param->m_dma3_csectors )
4549 vClearEventFlag(g_cdvdman_intr_efid, ~0x20);
4552 dev5_mmio_hwport->m_dev5_reg_006 = dma3_param->m_cdvdreg_howto;
4553 dmac_ch_set_madr(3, (u32)dma3_param->m_dma3_maddress);
4556 (dma3_param->m_dma3_blkcount * (dma3_param->m_dma3_csectors ? dma3_param->m_dma3_csectors : 1)) << 16
4557 | dma3_param->m_dma3_blkwords);
4558 dmac_ch_set_chcr(3, 0x41000200);
4559 return dmac_ch_get_chcr(3);
4563cdvdman_send_ncmd(
int ncmd,
const void *ndata,
int ndlen,
int func,
cdvdman_dma3_parameter_t *dma3_param,
int check_cb)
4567 USE_DEV5_MMIO_HWPORT();
4569 if ( check_cb == 1 && PollEventFlag(g_ncmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
4574 (dev5_mmio_hwport->m_dev5_reg_005 & 0xC0) != 0x40 || !g_cdvdman_istruct.m_wait_flag
4575 || !(g_cdvdman_istruct.m_read2_flag != 1 || ncmd == 8) || !(g_cdvdman_istruct.m_read2_flag != 2 || ncmd == 6) )
4577 if ( check_cb == 1 )
4579 vSetEventFlag(g_ncmd_evid, 1);
4581 VERBOSE_KPRINTF(1,
"set_cd_commnad Error\tstat %02x\n", (u8)dev5_mmio_hwport->m_dev5_reg_005);
4584 g_cdvdman_iocache = 0;
4587 cdvdman_setdma3(dma3_param);
4589 g_cdvdman_cmdfunc = func;
4592 !g_cdvdman_minver_10700 && g_cdvdman_ncmd == 6 && ncmd && ncmd != g_cdvdman_ncmd && ncmd != 7 && ncmd != 14
4595 g_cdvdman_ncmd_timeout.hi = 0;
4596 g_cdvdman_ncmd_timeout.lo = 0x6978000;
4597 vSetAlarm(&g_cdvdman_ncmd_timeout, (
unsigned int (*)(
void *))ncmd_timeout_alarm_cb, &g_cdvdman_ncmd_timeout);
4598 while ( dev5_mmio_hwport->m_dev5_reg_00A != 10 )
4600 VERBOSE_KPRINTF(1,
"Read Pause 1 chk status 0x%02x\n", dev5_mmio_hwport->m_dev5_reg_00A);
4601 if ( !g_cdvdman_ncmd_timeout.lo )
4603 g_cdvdman_ncmd = ncmd;
4604 if ( check_cb == 1 )
4606 vSetEventFlag(g_ncmd_evid, 1);
4608 KPRINTF(
"Time Out Pause WAIT set_cd_commnad\n");
4613 vCancelAlarm((
unsigned int (*)(
void *))ncmd_timeout_alarm_cb, &g_cdvdman_ncmd_timeout);
4615 g_cdvdman_ncmd = ncmd;
4616 if ( g_cdvdman_istruct.m_dec_state )
4618 sceCdDecSet(!!g_cdvdman_istruct.m_dec_shift, 1, g_cdvdman_istruct.m_dec_shift);
4620 g_cdvdman_istruct.m_last_read_timeout = 0;
4621 g_cdvdman_istruct.m_cdvdman_command = ncmd;
4622 g_cdvdman_istruct.m_last_error = 0;
4623 g_cdvdman_istruct.m_wait_flag = 0;
4624 g_cdvdman_istruct.m_thread_id = GetThreadId();
4627 iClearEventFlag(g_cdvdman_intr_efid, ~1);
4631 ClearEventFlag(g_cdvdman_intr_efid, ~1);
4633 for ( i = 0; i < ndlen; i += 1 )
4635 dev5_mmio_hwport->m_dev5_reg_005 = ((u8 *)ndata)[i];
4637 dev5_mmio_hwport->m_dev5_reg_004 = ncmd;
4638 if ( check_cb == 1 )
4640 vSetEventFlag(g_ncmd_evid, 1);
4647 VERBOSE_KPRINTF(1,
"Apply NCmd call cmd= 0x%02x\n", cmdNum);
4648 while ( cdvdman_send_ncmd(cmdNum, inBuff, inBuffSize, 0, 0, 1) < 0 )
4656int sceCdCheckCmd(
void)
4658 return g_cdvdman_istruct.m_wait_flag;
4661static int cdvdman_mediactl(
int code)
4667 USE_DEV5_MMIO_HWPORT();
4670 if ( PollEventFlag(g_scmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
4674 reg_00B_tmp_1 = dev5_mmio_hwport->m_dev5_reg_00B & 1;
4675 if ( reg_00B_tmp_1 == g_cdvdman_chmedia )
4678 if ( g_cdvdman_chflags[code] )
4680 g_cdvdman_chflags[code] = 0;
4688 for ( i = 0; i < (
sizeof(g_cdvdman_chflags) /
sizeof(g_cdvdman_chflags[0])); i += 1 )
4690 g_cdvdman_chflags[i] = i != (
unsigned int)code;
4694 if ( ((dev5_mmio_hwport->m_dev5_reg_00A) & 1) != reg_00B_tmp_1 )
4696 while ( !set_prev_command(5, 0, 0, (
char *)&rdata, 1, 0) || rdata )
4701 g_cdvdman_chmedia = dev5_mmio_hwport->m_dev5_reg_00B & 1;
4702 vSetEventFlag(g_scmd_evid, 1);
4708 if ( g_cdvdman_istruct.m_last_error )
4710 VERBOSE_KPRINTF(1,
"sceCdGetError: 0x%02x\n", (u8)g_cdvdman_istruct.m_last_error);
4712 return (u8)g_cdvdman_istruct.m_last_error;
4716int cdvdman_get_last_command()
4718 return (u8)g_cdvdman_istruct.m_cdvdman_command;
4724 return cdvdman_send_ncmd(0, 0, 0, 0, 0, 1) >= 0;
4728int cdvdman_ncmd_sender_01()
4730 return cdvdman_send_ncmd(1, 0, 0, 0, 0, 1) >= 0;
4734static int cdvdman_ncmd_sender_06()
4745 for ( i = 0; i < 48; i += 8 )
4747 KPRINTF(
"CMD_READP call\n");
4759 dma3_param.m_cdvdreg_howto = 128;
4760 dma3_param.m_dma3_blkwords = 32;
4761 dma3_param.m_dma3_blkcount = 128;
4762 dma3_param.m_dma3_csectors = 0;
4763 dma3_param.m_dma3_msectors = 0;
4764 dma3_param.m_dma3_callback = 0;
4765 dma3_param.m_dma3_maddress = g_cdvdman_ptoc;
4766 if ( cdvdman_send_ncmd(6, ndata,
sizeof(ndata), 5, &dma3_param, 1) < 0 )
4791 dma3_param.m_cdvdreg_howto = 128;
4792 dma3_param.m_dma3_blkwords = 32;
4793 dma3_param.m_dma3_blkcount = 16;
4802 dma3_param.m_dma3_csectors = 0;
4803 dma3_param.m_dma3_msectors = 0;
4804 dma3_param.m_dma3_callback = 0;
4805 dma3_param.m_dma3_maddress = g_cdvdman_ptoc;
4806 return cdvdman_send_ncmd(6, ndata,
sizeof(ndata), 5, &dma3_param, 1) >= 0;
4808 return cdvdman_send_ncmd(2, 0, 0, 5, 0, 1) >= 0;
4814 return cdvdman_send_ncmd(3, 0, 0, 6, 0, 1) >= 0;
4819 return cdvdman_send_ncmd(4, 0, 0, 7, 0, 1) >= 0;
4823int cdvdman_ncmd_sender_0B()
4828 return cdvdman_send_ncmd(11, &ndata,
sizeof(ndata), 0, 0, 1) >= 0;
4834 USE_DEV5_MMIO_HWPORT();
4836 KPRINTF(
"Cmd Time Out %d(msec)\n", sys_clock->lo / 0x9000);
4837 dev5_mmio_hwport->m_dev5_reg_007 = 1;
4842static int cdvdman_readtoc(u8 *
toc,
int param,
int func)
4855 dma3_param.m_cdvdreg_howto = 132;
4856 dma3_param.m_dma3_blkwords = 4;
4857 dma3_param.m_dma3_blkcount = 129;
4858 dma3_param.m_dma3_maddress =
toc;
4859 dma3_param.m_dma3_msectors = 0;
4860 dma3_param.m_dma3_csectors = 0;
4861 dma3_param.m_dma3_callback = 0;
4868 dma3_param.m_cdvdreg_howto = 128;
4869 dma3_param.m_dma3_blkwords = 32;
4870 dma3_param.m_dma3_blkcount = 8;
4871 dma3_param.m_dma3_maddress =
toc;
4872 dma3_param.m_dma3_msectors = 0;
4873 dma3_param.m_dma3_csectors = 0;
4874 dma3_param.m_dma3_callback = 0;
4882 if ( cdvdman_send_ncmd(9, &ndata,
sizeof(ndata), func, &dma3_param, 1) < 0 )
4887 sysclk.lo = 0x15F90000;
4888 vSetAlarm(&sysclk, (
unsigned int (*)(
void *))readtoc_timeout_alarm_cb, &sysclk);
4890 vCancelAlarm((
unsigned int (*)(
void *))readtoc_timeout_alarm_cb, &sysclk);
4892 if ( g_cdvdman_minver_10700 && !
sceCdPause() )
4900static int cdvdman_gettoc(u8 *
toc)
4902 return cdvdman_readtoc(
toc, 0, 3);
4907 int sector_sizes[4];
4909 sector_sizes[0] = 0x800;
4910 sector_sizes[1] = 0x918;
4911 sector_sizes[2] = 0x924;
4912 if ( g_cdvdman_istruct.m_recover_status && g_cdvdman_istruct.m_recover_status != 3 )
4916 if ( g_cdvdman_cmdfunc == SCECdFuncReadCDDA || g_cdvdman_cmdfunc == 12 )
4918 return dmac_ch_get_madr(3) - (uiptr)g_cdvdman_readbuf;
4920 if ( g_cdvdman_istruct.m_read2_flag )
4922 return g_cdvdman_readptr * sector_sizes[g_cdvdman_istruct.m_cdvdman_pattern];
4924 if ( g_cdvdman_cmdfunc == SCECdFuncRead )
4926 return dmac_ch_get_madr(3) - (uiptr)g_cdvdman_readbuf;
4931static int cdvdman_speedctl(u32 spindlctrl,
int dvdflag, u32 maxlsn)
4935 switch ( spindlctrl )
4938 return dvdflag ? 2 : 4;
4944 if ( g_cdvdman_minver_10700 )
4948 maxlsn_chk = 0x128000;
4949 if ( g_cdvdman_istruct.m_opo_or_para )
4951 maxlsn -= (maxlsn >= (u32)g_cdvdman_istruct.m_layer_1_lsn) ? g_cdvdman_istruct.m_layer_1_lsn : 0;
4952 maxlsn_chk = 0x165000;
4954 if ( maxlsn >= maxlsn_chk )
4956 VERBOSE_KPRINTF(1,
"Kprob Spd D lsn= %d\n", maxlsn);
4966 return dvdflag ? 2 : 131;
4968 return dvdflag ? 3 : 4;
4972 return dvdflag ? 4 : 2;
4976 return dvdflag ? 130 : 131;
4978 return dvdflag ? 130 : 132;
4980 return dvdflag ? 1 : 131;
4982 return dvdflag ? 3 : 5;
4984 return dvdflag ? 131 : 133;
4988static int cdvdman_isdvd()
4997 g_cdvdman_istruct.m_tray_is_open = 1;
5000 g_cdvdman_istruct.m_tray_is_open = 1;
5004 g_cdvdman_istruct.m_tray_is_open = 1;
5007 g_cdvdman_istruct.m_tray_is_open = 1;
5014static int sceCdRead0_Rty(u32 lsn, u32 nsec,
void *buf,
const sceCdRMode *mode,
int ncmd,
int dintrsec,
void *func)
5019 g_cdvdman_readbuf = buf;
5020 VERBOSE_KPRINTF(1,
"sceCdRead0_Rty Lsn:%d nsec:%d dintrnsec %d func %08x\n", lsn, nsec, dintrsec, func);
5021 *(u32 *)ndata = lsn;
5022 *(u32 *)&ndata[4] = nsec;
5023 ndata[8] = mode->trycount;
5024 ndata[9] = cdvdman_speedctl(mode->spindlctrl, cdvdman_isdvd(), lsn + nsec);
5025 dma3_param.m_dma3_csectors = dintrsec;
5026 dma3_param.m_dma3_callback = (int (*)(void))func;
5027 dma3_param.m_dma3_msectors = nsec;
5028 dma3_param.m_dma3_maddress = buf;
5029 dma3_param.m_dma3_blkcount = (!(u16)dintrsec) ? nsec : 1;
5032 ndata[10] = mode->datapattern;
5033 switch ( mode->datapattern )
5036 dma3_param.m_dma3_blkwords = 6;
5037 dma3_param.m_dma3_blkcount *= 97;
5038 dma3_param.m_cdvdreg_howto = 134;
5041 dma3_param.m_dma3_blkwords = 15;
5042 dma3_param.m_dma3_blkcount *= 39;
5043 dma3_param.m_cdvdreg_howto = 143;
5047 dma3_param.m_dma3_blkwords = 32;
5048 dma3_param.m_dma3_blkcount *= 16;
5049 dma3_param.m_cdvdreg_howto = 128;
5052 if ( cdvdman_send_ncmd(ncmd, ndata,
sizeof(ndata), 1, &dma3_param, 0) >= 0 )
5059 dma3_param.m_dma3_blkwords = 12;
5060 dma3_param.m_dma3_blkcount *= 43;
5061 dma3_param.m_cdvdreg_howto = 140;
5063 if ( cdvdman_send_ncmd(ncmd, ndata,
sizeof(ndata), 14, &dma3_param, 0) >= 0 )
5071int sceCdRead0(u32 lsn, u32 sectors,
void *buffer,
sceCdRMode *mode,
int csec,
void *callback)
5077 if ( PollEventFlag(g_ncmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5083 "DVD/CD sceCdRead0 sec %d num %d spin %d trycnt %d dptn %d adr %08x\n",
5090 g_cdvdman_readbuf = buffer;
5091 dma3_param.m_dma3_csectors = (csec && (sectors < (u32)csec)) ? sectors : (u32)csec;
5092 dma3_param.m_dma3_callback = (int (*)(void))callback;
5093 dma3_param.m_dma3_msectors = sectors;
5094 dma3_param.m_dma3_blkcount = (!csec) ? sectors : 1;
5095 switch ( mode->datapattern )
5098 dma3_param.m_dma3_blkwords = 6;
5099 dma3_param.m_dma3_blkcount *= 97;
5100 dma3_param.m_cdvdreg_howto = 134;
5103 dma3_param.m_dma3_blkwords = 15;
5104 dma3_param.m_dma3_blkcount *= 39;
5105 dma3_param.m_cdvdreg_howto = 143;
5109 dma3_param.m_dma3_blkwords = 32;
5110 dma3_param.m_dma3_blkcount *= 16;
5111 dma3_param.m_cdvdreg_howto = 128;
5121 if ( g_cdvdman_mmode != SCECdMmodeCd && g_cdvdman_mmode != 0xFF )
5123 vSetEventFlag(g_ncmd_evid, 1);
5126 g_cdvdman_istruct.m_dvd_flag = 0;
5129 if ( g_cdvdman_mmode != SCECdMmodeDvd && g_cdvdman_mmode != 0xFF )
5131 vSetEventFlag(g_ncmd_evid, 1);
5134 g_cdvdman_istruct.m_dvd_flag = 1;
5137 vSetEventFlag(g_ncmd_evid, 1);
5140 g_cdvdman_istruct.m_read_mode = *mode;
5141 g_cdvdman_istruct.m_read_callback = callback;
5142 g_cdvdman_istruct.m_read_chunk = dma3_param.m_dma3_csectors;
5143 g_cdvdman_istruct.m_read_lsn = lsn;
5144 g_cdvdman_istruct.m_read_sectors = sectors;
5145 *(u32 *)ndata = lsn;
5146 *(u32 *)&ndata[4] = sectors;
5147 ndata[8] = mode->trycount;
5148 ndata[9] = cdvdman_speedctl(mode->spindlctrl, g_cdvdman_istruct.m_dvd_flag, lsn + sectors);
5149 g_cdvdman_istruct.m_read_buf = buffer;
5150 ndata[10] = mode->datapattern;
5151 dma3_param.m_dma3_maddress = buffer;
5152 VERBOSE_KPRINTF(1,
"Read Command call\n");
5153 if ( cdvdman_send_ncmd(6, ndata,
sizeof(ndata), 1, &dma3_param, 0) < 0 )
5155 vSetEventFlag(g_ncmd_evid, 1);
5158 vSetEventFlag(g_ncmd_evid, 1);
5171 for ( i = 0; i < common->m_dma3_param.m_dma3_csectors; i += 1 )
5177 if ( common->m_read2_flag == 3 )
5180 cdrloc.
minute = cdvdman_syncdec(
5181 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock)]);
5182 cdrloc.
second = cdvdman_syncdec(
5183 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 1]);
5184 cdrloc.
sector = cdvdman_syncdec(
5185 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 2]);
5191 syncdec_res_1 = (u8)cdvdman_syncdec(
5192 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 3]);
5194 (u8)cdvdman_syncdec(
5195 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 2])
5198 (u8)cdvdman_syncdec(
5199 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock) + 1])
5201 syncdec_res_4 = cdvdman_syncdec(
5202 common->m_dec_state, common->m_check_version, common->m_dec_shift, g_cdvdman_ptoc[(i * sblock)]);
5203 if ( !common->m_cdvdman_dma3sec && !common->m_interupt_read_state )
5205 common->m_interupt_read_state = (syncdec_res_4 & 0xC) | (((syncdec_res_4 & 0xC) && i) ? 0x80 : 0);
5207 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);
5209 errlsn = common->m_cdvdman_lsn + common->m_cdvdman_csec + common->m_cdvdman_dma3sec + i;
5210 if ( cdreadlsn != (u32)errlsn )
5213 1,
"Read_IOP Sector_ID error lsn= %d readlsn= %d layer= %d\n", errlsn, cdreadlsn, (syncdec_res_4 & 1));
5217 if ( i == common->m_dma3_param.m_dma3_csectors )
5222 switch ( common->m_cdvdman_pattern )
5233 &((
char *)(common->m_cdvdman_rbuffer))[0x924 * common->m_cdvdman_dma3sec],
5234 (
const char *)g_cdvdman_ptoc,
5240 for ( i = 0; i < common->m_dma3_param.m_dma3_csectors; i += 1 )
5243 &((
char *)(common->m_cdvdman_rbuffer))[(common->m_cdvdman_dma3sec + i) * size],
5244 (
const char *)&g_cdvdman_ptoc[12 + (i * sblock)],
5248 g_cdvdman_readptr = common->m_cdvdman_csec + common->m_cdvdman_dma3sec;
5252 common->m_sync_error += 1;
5257static int cdvdman_read(u32 lsn, u32 sectors,
void *buf,
sceCdRMode *mode,
int decflag,
int shift,
int ef1,
int ef2)
5264 dvd = cdvdman_isdvd();
5267 if ( !DvdDual_infochk() )
5271 vSetEventFlag(ef1, ef2);
5275 lsn = sceCdLsnDualChg(lsn);
5277 else if ( mode->datapattern == SCECdSecS2328 || (g_cdvdman_cd36key && !g_cdvdman_istruct.m_dec_state) )
5281 if ( g_cdvdman_cd36key && !g_cdvdman_istruct.m_dec_state && mode->spindlctrl ==
SCECdSpinNom )
5286 read0_res = sceCdRead0(lsn, sectors, buf, mode, 0, 0);
5289 vSetEventFlag(ef1, ef2);
5295 if ( (
sceCdDiskReady(8) & 0xC0) != 0x40 || g_cdvdman_istruct.m_read2_flag )
5299 "sceCdRead: Double Booking error r2f= %d waf= %d\n",
5300 g_cdvdman_istruct.m_read2_flag,
5301 g_cdvdman_istruct.m_wait_flag);
5304 vSetEventFlag(ef1, ef2);
5311 g_cdvdman_istruct.m_dec_shift = shift;
5312 g_cdvdman_istruct.m_dec_state = 1;
5314 g_cdvdman_readbuf = buf;
5315 g_cdvdman_readptr = 0;
5316 g_cdvdman_istruct.m_cdvdman_lsn = lsn;
5317 g_cdvdman_istruct.m_cdvdman_csec = 0;
5318 g_cdvdman_istruct.m_cdvdman_nsec = sectors;
5319 g_cdvdman_istruct.m_cdvdman_rbuffer = (int)buf;
5320 g_cdvdman_istruct.m_cdvdman_pattern = dvd ? SCECdSecS2048 : mode->datapattern;
5321 g_cdvdman_istruct.m_cdvdman_cdrmode.
trycount = mode->trycount;
5322 g_cdvdman_istruct.m_cdvdman_cdrmode.
spindlctrl = mode->spindlctrl;
5323 g_cdvdman_istruct.m_cdvdman_cdrmode.
datapattern = dvd ? SCECdSecS2048 : SCECdSecS2340;
5324 g_cdvdman_istruct.m_read2_flag = dvd ? 1 : 3;
5325 g_cdvdman_istruct.m_sync_error = 0;
5326 g_cdvdman_istruct.m_interupt_read_state = 0;
5327 g_cdvdman_istruct.m_cdvdman_rsec = (sectors >= 0x41) ? (((lsn & 0xF)) ? (0x10 - (lsn & 0xF)) : 0x40) : sectors;
5328 g_cdvdman_read_alarm_cb_timeout.hi = 0;
5329 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
5331 &g_cdvdman_read_alarm_cb_timeout,
5332 (
unsigned int (*)(
void *))read_timeout_alarm_cb,
5333 &g_cdvdman_read_alarm_cb_timeout);
5334 read_res = (dvd ?
sceCdRV : sceCdRead0)(
5336 g_cdvdman_istruct.m_cdvdman_rsec,
5338 dvd ? mode : &g_cdvdman_istruct.m_cdvdman_cdrmode,
5344 g_cdvdman_istruct.m_cdvdman_rsec = 0;
5345 g_cdvdman_istruct.m_read2_flag = 0;
5346 if ( g_cdvdman_istruct.m_dec_state )
5348 g_cdvdman_istruct.m_dec_shift = 0;
5349 g_cdvdman_istruct.m_check_version = 0;
5350 g_cdvdman_istruct.m_dec_state = 0;
5353 vCancelAlarm((
unsigned int (*)(
void *))read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
5357 vSetEventFlag(ef1, ef2);
5365 return cdvdman_read(lsn, sectors, buf, mode, 0, 0, 0, 0);
5374 memset(&efinfo, 0,
sizeof(efinfo));
5376 vReferEventFlagStatus(g_fio_fsv_evid, &efinfo);
5382 vClearEventFlag(g_fio_fsv_evid, ~1);
5384 return cdvdman_read(lbn, sectors, buffer, mode, 0, 0, g_fio_fsv_evid, 1);
5387static int cdvdman_syncdec(
int decflag,
int decxor,
int shift, u32 data)
5389 return decflag ? ((u8)(((u8)data << (shift % 8)) | ((u8)data >> (8 - shift % 8))) ^ (u8)decxor) : (u8)data;
5392static void Read2intrCDVD(
int read2_flag)
5394 iCancelAlarm((
unsigned int (*)(
void *))read_timeout_alarm_cb, &g_cdvdman_read_alarm_cb_timeout);
5395 if ( g_cdvdman_istruct.m_last_error || g_cdvdman_retries >= 5 )
5397 if ( !g_cdvdman_istruct.m_last_error )
5401 g_cdvdman_istruct.m_read2_flag = 0;
5402 g_cdvdman_retries = 0;
5403 g_cdvdman_rtindex = 0;
5404 g_cdvdman_readptr = 0;
5405 if ( g_cdvdman_istruct.m_dec_state )
5407 g_cdvdman_istruct.m_dec_shift = 0;
5408 g_cdvdman_istruct.m_check_version = 0;
5409 g_cdvdman_istruct.m_dec_state = 0;
5411 g_cdvdman_istruct.m_interupt_read_state = 0;
5413 else if ( !g_cdvdman_istruct.m_interupt_read_state || g_cdvdman_istruct.m_cdvdman_csec )
5417 g_cdvdman_istruct.m_interupt_read_state = 0;
5418 if ( g_cdvdman_istruct.m_sync_error )
5422 if ( !g_cdvdman_rtindex )
5424 g_cdvdman_rtindex = 3;
5425 g_cdvdman_retries += 1;
5427 g_cdvdman_istruct.m_sync_error = 0;
5428 lsn_tmp = g_cdvdman_istruct.m_cdvdman_lsn + g_cdvdman_istruct.m_cdvdman_csec;
5429 if ( lsn_tmp >= 0x30 )
5431 lsn_tmp -= 0x10 * (g_cdvdman_rtindex - 1);
5435 lsn_tmp += 0x10 * (g_cdvdman_rtindex - 1);
5437 if ( ((read2_flag == 3) ? sceCdRead0 :
sceCdRV)(
5439 g_cdvdman_istruct.m_cdvdman_rsec,
5441 &g_cdvdman_istruct.m_cdvdman_cdrmode,
5445 g_cdvdman_read_alarm_cb_timeout.hi = 0;
5446 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
5448 &g_cdvdman_read_alarm_cb_timeout,
5449 (
unsigned int (*)(
void *))read_timeout_alarm_cb,
5450 &g_cdvdman_read_alarm_cb_timeout);
5454 VERBOSE_KPRINTF(1,
"Retry Read Fatal Error\n");
5456 g_cdvdman_istruct.m_read2_flag = 0;
5457 g_cdvdman_retries = 0;
5458 g_cdvdman_rtindex = 0;
5459 g_cdvdman_readptr = 0;
5460 if ( g_cdvdman_istruct.m_dec_state )
5462 g_cdvdman_istruct.m_dec_shift = 0;
5463 g_cdvdman_istruct.m_check_version = 0;
5464 g_cdvdman_istruct.m_dec_state = 0;
5467 g_cdvdman_rtindex -= !!g_cdvdman_rtindex;
5473 g_cdvdman_retries = 0;
5474 switch ( g_cdvdman_istruct.m_cdvdman_pattern )
5487 g_cdvdman_istruct.m_cdvdman_rbuffer += cdsectorsz * g_cdvdman_istruct.m_cdvdman_rsec;
5488 g_cdvdman_istruct.m_cdvdman_csec += g_cdvdman_istruct.m_cdvdman_rsec;
5489 if ( (
unsigned int)g_cdvdman_istruct.m_cdvdman_csec < (
unsigned int)g_cdvdman_istruct.m_cdvdman_nsec )
5491 g_cdvdman_istruct.m_cdvdman_rsec =
5492 ((
unsigned int)(g_cdvdman_istruct.m_cdvdman_csec + 0x40) < (
unsigned int)g_cdvdman_istruct.m_cdvdman_nsec) ?
5494 (g_cdvdman_istruct.m_cdvdman_nsec - g_cdvdman_istruct.m_cdvdman_csec);
5495 if ( ((read2_flag == 3) ? sceCdRead0 :
sceCdRV)(
5496 g_cdvdman_istruct.m_cdvdman_lsn + g_cdvdman_istruct.m_cdvdman_csec,
5497 g_cdvdman_istruct.m_cdvdman_rsec,
5499 &g_cdvdman_istruct.m_cdvdman_cdrmode,
5503 g_cdvdman_read_alarm_cb_timeout.hi = 0;
5504 g_cdvdman_read_alarm_cb_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
5506 &g_cdvdman_read_alarm_cb_timeout,
5507 (
unsigned int (*)(
void *))read_timeout_alarm_cb,
5508 &g_cdvdman_read_alarm_cb_timeout);
5513 g_cdvdman_istruct.m_read2_flag = 0;
5514 g_cdvdman_readptr = 0;
5515 if ( g_cdvdman_istruct.m_dec_state )
5517 g_cdvdman_istruct.m_dec_shift = 0;
5518 g_cdvdman_istruct.m_check_version = 0;
5519 g_cdvdman_istruct.m_dec_state = 0;
5525 g_cdvdman_istruct.m_read2_flag = 0;
5526 g_cdvdman_readptr = 0;
5527 if ( g_cdvdman_istruct.m_dec_state )
5529 g_cdvdman_istruct.m_dec_shift = 0;
5530 g_cdvdman_istruct.m_check_version = 0;
5531 g_cdvdman_istruct.m_dec_state = 0;
5538 g_cdvdman_istruct.m_last_error = ((g_cdvdman_istruct.m_interupt_read_state & 0x80)) ?
SCECdErREADCF :
SCECdErIPI;
5539 g_cdvdman_istruct.m_interupt_read_state = 0;
5540 VERBOSE_KPRINTF(1,
"IPIerr emu Hit Dummy Err %02x\n", (u8)g_cdvdman_istruct.m_last_error);
5541 g_cdvdman_istruct.m_read2_flag = 0;
5542 g_cdvdman_retries = 0;
5543 g_cdvdman_rtindex = 0;
5544 g_cdvdman_readptr = 0;
5545 if ( g_cdvdman_istruct.m_dec_state )
5547 g_cdvdman_istruct.m_dec_shift = 0;
5548 g_cdvdman_istruct.m_check_version = 0;
5549 g_cdvdman_istruct.m_dec_state = 0;
5562static int cdvdman_readfull(u32 lsn, u32 sectors,
void *buf,
const sceCdRMode *mode,
int flag)
5567 VERBOSE_KPRINTF(1,
"lsn:%d nsec:%d buf:% cmdmode:%d\n", lsn, sectors, buf, flag);
5568 g_cdvdman_readbuf = buf;
5569 dma3_param.m_dma3_csectors = 0;
5570 dma3_param.m_dma3_msectors = 0;
5571 dma3_param.m_dma3_callback = 0;
5572 dma3_param.m_dma3_blkcount = sectors;
5573 switch ( mode->datapattern )
5576 dma3_param.m_dma3_blkwords = 8;
5577 dma3_param.m_dma3_blkcount *= 74;
5578 dma3_param.m_cdvdreg_howto = 136;
5581 dma3_param.m_dma3_blkwords = 12;
5582 dma3_param.m_dma3_blkcount *= 51;
5583 dma3_param.m_cdvdreg_howto = 140;
5587 dma3_param.m_dma3_blkwords = 12;
5588 dma3_param.m_dma3_blkcount *= 49;
5589 dma3_param.m_cdvdreg_howto = 140;
5602 if ( g_cdvdman_mmode != SCECdMmodeCd && g_cdvdman_mmode != 0xFF )
5606 *(u32 *)ndata = lsn;
5607 *(u32 *)&ndata[4] = sectors;
5608 ndata[8] = mode->trycount;
5609 ndata[9] = cdvdman_speedctl(mode->spindlctrl, 0, lsn + sectors);
5610 dma3_param.m_dma3_maddress = buf;
5611 ndata[10] = mode->datapattern;
5612 return cdvdman_send_ncmd((!flag) ? 7 : 14, ndata, sizeof(ndata), (!flag) ? 2 : 12, &dma3_param, 1) >= 0;
5615int sceCdReadCDDA(u32 lbn, u32 sectors,
void *buffer,
sceCdRMode *mode)
5617 return cdvdman_readfull(lbn, sectors, buffer, mode, 0);
5629 || (PollEventFlag(g_ncmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND) )
5634 1,
"RV read: sec %d num %d spin %d trycnt %d addr %08x\n", lsn, sectors, mode->spindlctrl, mode->trycount, buf);
5635 g_cdvdman_readbuf = buf;
5636 g_cdvdman_istruct.m_dvd_flag = cdvdman_isdvd();
5637 g_cdvdman_istruct.m_read_mode = *mode;
5638 g_cdvdman_istruct.m_read_lsn = lsn;
5639 g_cdvdman_istruct.m_read_sectors = sectors;
5640 *(u32 *)ndata = lsn;
5641 *(u32 *)&ndata[4] = sectors;
5642 ndata[8] = mode->trycount;
5643 ndata[9] = cdvdman_speedctl(mode->spindlctrl, 1, lsn + sectors);
5645 dma3_param.m_dma3_csectors = (arg5 && (sectors < (u32)arg5)) ? sectors : (u32)arg5;
5646 g_cdvdman_istruct.m_read_chunk = dma3_param.m_dma3_csectors;
5647 dma3_param.m_cdvdreg_howto = 140;
5648 dma3_param.m_dma3_blkwords = 12;
5649 g_cdvdman_istruct.m_read_buf = buf;
5650 dma3_param.m_dma3_blkcount = (!arg5) ? sectors : 1;
5651 dma3_param.m_dma3_blkcount *= 43;
5652 dma3_param.m_dma3_msectors = sectors;
5653 dma3_param.m_dma3_callback = (int (*)(void))cb;
5654 g_cdvdman_istruct.m_read_callback = cb;
5655 dma3_param.m_dma3_maddress = buf;
5656 if ( cdvdman_send_ncmd(8, ndata,
sizeof(ndata), 14, &dma3_param, 0) < 0 )
5658 vSetEventFlag(g_ncmd_evid, 1);
5661 vSetEventFlag(g_ncmd_evid, 1);
5670 if ( cdvdman_isdvd() )
5672 if ( !DvdDual_infochk() )
5676 ndata = sceCdLsnDualChg(ndata);
5678 return cdvdman_send_ncmd(5, &ndata, 4, 4, 0, 1) >= 0;
5686 command = set_prev_command(18, 0, 0, (
char *)rdata,
sizeof(rdata), 1);
5688 memcpy(buffer, &rdata[1], 8);
5701 if ( sceCdGetMVersion(rdata, status) != 1 || (
unsigned int)(rdata[3] | (rdata[2] << 8) | (rdata[1] << 16)) < 0x10500 )
5703 strcpy(buffer,
"M_NAME_UNKNOWN");
5708 if ( PollEventFlag(g_scmd_evid, 1, WEF_AND | WEF_CLEAR, &efbits) == KE_EVF_COND )
5714 command = set_prev_command(0x17, &wdata,
sizeof(wdata), (
char *)rdata,
sizeof(rdata), 0);
5716 memcpy(buffer, &rdata[1], 8);
5719 cmd_tmp2 = set_prev_command(0x17, &wdata,
sizeof(wdata), (
char *)rdata,
sizeof(rdata), 0);
5720 *status |= rdata[0];
5721 memcpy(&buffer[8], &rdata[1], 8);
5722 vSetEventFlag(g_scmd_evid, 1);
5723 return command ? (!!cmd_tmp2) : 0;
5726static int sceCdGetMVersion(u8 *buffer, u32 *status)
5733 command = set_prev_command(3, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
5734 *status = rdata[0] & 0x80;
5735 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]);
5737 memcpy(buffer, rdata,
sizeof(rdata));
5741static int cdvdman_scmd_sender_03_48(u8 *buf, u32 *status)
5747 if ( g_cdvdman_minver_50000 )
5753 retval = set_prev_command(3, wdata,
sizeof(wdata), rdata,
sizeof(rdata), 1);
5754 *status = (u8)rdata[0];
5761 g_cdvdman_mmode = media;
5769 memset(wdata, 0,
sizeof(wdata));
5771 return g_cdvdman_minver_20400 ? set_prev_command(27, wdata, 0, (
char *)result, 1, 1) : 1;
5776 s->m_power_flag = 0;
5785 VERBOSE_KPRINTF(1,
"sceCdPowerOff Call\n");
5786 if ( !g_cdvdman_minver_x_model_15 )
5793 vDelayThread(250000);
5796 command = set_prev_command(0xF, 0, 0, (
char *)result, 1, 1);
5799 g_cdvdman_istruct.m_power_flag = 0;
5802 KPRINTF(
"PowerOff Start...\n");
5803 g_cdvdman_istruct.m_power_flag = 1;
5804 g_cdvdman_power_off_timeout.hi = 0;
5805 g_cdvdman_power_off_timeout.lo = 0xAFC8000;
5806 vSetAlarm(&g_cdvdman_power_off_timeout, (
unsigned int (*)(
void *))power_off_alarm_cb, &g_cdvdman_istruct);
5817 VERBOSE_KPRINTF(1,
"Audio Digital Out: Set param %d\n", wdata);
5818 return set_prev_command(20, &wdata,
sizeof(wdata), (
char *)status, 1, 1);
5825 retval = set_prev_command(8, 0, 0, (
char *)clock, 8, 1);
5827 clock->
month &= 0x7F;
5828 if ( retval && !clock->
stat )
5830 memcpy(&g_cdvdman_clock, clock,
sizeof(g_cdvdman_clock));
5831 g_cdvdman_clk_flg = 1;
5833 else if ( g_cdvdman_clk_flg )
5835 memcpy(clock, &g_cdvdman_clock,
sizeof(g_cdvdman_clock));
5851 return set_prev_command(8, 0, 0, (
char *)clock, 8, 1);
5861 *traychk = cdvdman_mediactl(1);
5862 VERBOSE_KPRINTF(1,
"Tray Req test = %d\n", *traychk);
5870 g_cdvdman_iocache = 0;
5871 if ( set_prev_command(6, &wdata,
sizeof(wdata), &rdata,
sizeof(rdata), 1) && !rdata )
5873 vDelayThread(11000);
5879static int cdvdman_scmd_sender_3B(
int arg1)
5884 if ( g_cdvdman_minver_x_model_15 && arg1 == 1 )
5889 g_cdvdman_iocache = 0;
5890 if ( set_prev_command(59, &wdata,
sizeof(wdata), &rdata,
sizeof(rdata), 1) && !rdata )
5892 vDelayThread(11000);
5898#ifdef CDVD_VARIANT_DNAS
5904 USE_DEV5_MMIO_HWPORT();
5906 *((u8 *)
id + 4) = 0;
5907 *((u8 *)
id + 3) = 0;
5908 *((u8 *)
id + 2) = 0;
5909 *((u8 *)
id + 1) = 0;
5923 sceCdRead0(0x4B, 1, sectbuf, &rmode, 0, 0);
5925 if ( !cdvdman_ncmd_sender_0C(0, 0, 0x4B) )
5930 if ( g_cdvdman_istruct.m_last_error )
5934 WaitEventFlag(g_scmd_evid, 1, WEF_AND, &efbits);
5935 if ( !(dev5_mmio_hwport->m_dev5_reg_038 & 4) )
5937 vSetEventFlag(g_scmd_evid, 1);
5940 *(u8 *)
id = dev5_mmio_hwport->m_dev5_reg_030 ^ dev5_mmio_hwport->m_dev5_reg_039;
5941 *((u8 *)
id + 1) = dev5_mmio_hwport->m_dev5_reg_031 ^ dev5_mmio_hwport->m_dev5_reg_039;
5942 *((u8 *)
id + 2) = dev5_mmio_hwport->m_dev5_reg_032 ^ dev5_mmio_hwport->m_dev5_reg_039;
5943 *((u8 *)
id + 3) = dev5_mmio_hwport->m_dev5_reg_033 ^ dev5_mmio_hwport->m_dev5_reg_039;
5944 *((u8 *)
id + 4) = dev5_mmio_hwport->m_dev5_reg_034 ^ dev5_mmio_hwport->m_dev5_reg_039;
5945 vSetEventFlag(g_scmd_evid, 1);
5957 USE_DEV5_MMIO_HWPORT();
5960 if ( !g_cdvdman_istruct.m_cd_inited )
5979 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
5991 dev5_mmio_hwport->m_dev5_reg_007 = 1;
6003 for ( i = 0; i < 20; i += 1 )
6005 sceCdRead0(0x4B + (0x10 * i), 0x10, g_cdvdman_ptoc, &rmode, 0, 0);
6014 sceCdRead0(0x4B, 1, g_cdvdman_ptoc, &rmode, 0, 0);
6018 WaitEventFlag(g_scmd_evid, 1, WEF_AND, &efbits);
6020 if ( g_cdvdman_istruct.m_stream_flag || g_cdvdman_istruct.m_read2_flag )
6024 vSetEventFlag(g_scmd_evid, 1);
6027 strcpy(&ndata[3],
"K");
6033 if ( cdvdman_send_ncmd(12, ndata,
sizeof(ndata), 0, 0, 1) < 0 )
6037 vSetEventFlag(g_scmd_evid, 1);
6042 if ( g_cdvdman_istruct.m_last_error )
6044 *status = (u8)g_cdvdman_istruct.m_last_error;
6045 vSetEventFlag(g_scmd_evid, 1);
6048 dev5_reg_038 = dev5_mmio_hwport->m_dev5_reg_038;
6049 vSetEventFlag(g_scmd_evid, 1);
6050 return (dev5_reg_038 & 5) == 5;
6053static int cdvdman_ncmd_sender_0C(
int arg1, u32 arg2, u32 arg3)
6059 ndata[2] = !!(arg2 >> 8);
6060 *(u32 *)&ndata[3] = !arg1 ? arg3 : 0;
6061 return cdvdman_send_ncmd(12, ndata,
sizeof(ndata), 0, 0, 1) >= 0;
6067#ifdef CDVD_VARIANT_DNAS
6068 USE_DEV5_MMIO_HWPORT();
6070 g_cdvdman_cd36key = enable_shift | shiftval;
6071 dev5_mmio_hwport->m_dev5_reg_03A = (16 * (shiftval & 7)) | ((!!enable_xor) << 1) | (!!enable_shift);
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 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 sceCdCancelPOffRdy(u32 *result)
int sceCdPowerOff(u32 *result)
int sceCdDoesUniqueKeyExist(u32 *status)
int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
sceCdCBFunc sceCdCallback(sceCdCBFunc function)
int sceCdReadDvdDualInfo(int *on_dual, unsigned int *layer1_start)
int sceCdStInit(u32 bufmax, u32 bankmax, void *buffer)
int sceCdReadGUID(u64 *guid)
int sceCdDiskReady(int mode)
int sceCdRM(char *buffer, u32 *status)
u32 sceCdPosToInt(sceCdlLOCCD *p)
int sceCdLayerSearchFile(sceCdlFILE *fp, const char *path, int layer)
int sceCdReadClock(sceCdCLOCK *clock)
u32 sceCdGetReadPos(void)
int sceCdGetDiskType(void)
sceCdlLOCCD * sceCdIntToPos(u32 i, sceCdlLOCCD *p)
int sceCdMmode(int media)
int sceCdApplySCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize, void *outBuff)
int sceCdSetTimeout(int param, int timeout)
int sceCdStStart(u32 lbn, sceCdRMode *mode)
void(* sceCdCBFunc)(int reason)
int sceCdDecSet(unsigned char enable_xor, unsigned char enable_shift, unsigned char shiftval)
int sceCdRI(u8 *buffer, u32 *result)
int sceCdRead(u32 lbn, u32 sectors, void *buffer, sceCdRMode *mode)
int sceCdApplyNCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize)
int sceCdRE(unsigned int lsn, unsigned int sectors, void *buf, sceCdRMode *mode)
int sceCdReadChain(sceCdRChain *tag, sceCdRMode *mode)
int sceCdTrayReq(int param, u32 *traychk)
int sceCdCtrlADout(int mode, u32 *status)