int userIoOpen(const char *s, int flags, int permissions) { return sceIoOpen(s, flags, permissions); }
//Get info on file: //Uso LibMad per calcolare la durata del pezzo perché //altrimenti dovrei gestire il buffer anche nella seekNextFrame (senza è troppo lenta). //E' una porcheria ma è più semplice. :) int MP3MEgetInfo(){ unsigned long FrameCount = 0; int fd = -1; int bufferSize = 1024*496; u8 *localBuffer; long singleDataRed = 0; struct mad_stream stream; struct mad_header header; int timeFromID3 = 0; float mediumBitrate = 0.0f; int has_xing = 0; struct xing xing; memset(&xing, 0, sizeof(xing)); if (!MP3ME_tagRead) getMP3METagInfo(MP3ME_fileName, &MP3ME_info); mad_stream_init (&stream); mad_header_init (&header); fd = sceIoOpen(MP3ME_fileName, PSP_O_RDONLY, 0777); if (fd < 0) return -1; long size = sceIoLseek(fd, 0, PSP_SEEK_END); sceIoLseek(fd, 0, PSP_SEEK_SET); MP3ME_tagsize = ID3v2TagSize(MP3ME_fileName); double startPos = MP3ME_tagsize; sceIoLseek32(fd, startPos, PSP_SEEK_SET); //Check for xing frame: unsigned char *xing_buffer; xing_buffer = (unsigned char *)malloc(XING_BUFFER_SIZE); if (xing_buffer != NULL) { sceIoRead(fd, xing_buffer, XING_BUFFER_SIZE); if(parse_xing(xing_buffer, 0, &xing)) { if (xing.flags & XING_FRAMES && xing.frames){ has_xing = 1; bufferSize = 50 * 1024; } } free(xing_buffer); xing_buffer = NULL; } size -= startPos; if (size < bufferSize * 3) bufferSize = size; localBuffer = (unsigned char *) malloc(sizeof(unsigned char) * bufferSize); unsigned char *buff = localBuffer; MP3ME_info.fileType = MP3_TYPE; MP3ME_info.defaultCPUClock = MP3ME_defaultCPUClock; MP3ME_info.needsME = 1; MP3ME_info.fileSize = size; MP3ME_filesize = size; MP3ME_info.framesDecoded = 0; double totalBitrate = 0; int i = 0; for (i=0; i<3; i++){ memset(localBuffer, 0, bufferSize); singleDataRed = sceIoRead(fd, localBuffer, bufferSize); mad_stream_buffer (&stream, localBuffer, singleDataRed); while (1){ if (mad_header_decode (&header, &stream) == -1){ if (stream.buffer == NULL || stream.error == MAD_ERROR_BUFLEN) break; else if (MAD_RECOVERABLE(stream.error)){ continue; }else{ break; } } //Informazioni solo dal primo frame: if (FrameCount++ == 0){ switch (header.layer) { case MAD_LAYER_I: strcpy(MP3ME_info.layer,"I"); break; case MAD_LAYER_II: strcpy(MP3ME_info.layer,"II"); break; case MAD_LAYER_III: strcpy(MP3ME_info.layer,"III"); break; default: strcpy(MP3ME_info.layer,"unknown"); break; } MP3ME_info.kbit = header.bitrate / 1000; MP3ME_info.instantBitrate = header.bitrate; MP3ME_info.hz = header.samplerate; switch (header.mode) { case MAD_MODE_SINGLE_CHANNEL: strcpy(MP3ME_info.mode, "single channel"); break; case MAD_MODE_DUAL_CHANNEL: strcpy(MP3ME_info.mode, "dual channel"); break; case MAD_MODE_JOINT_STEREO: strcpy(MP3ME_info.mode, "joint (MS/intensity) stereo"); break; case MAD_MODE_STEREO: strcpy(MP3ME_info.mode, "normal LR stereo"); break; default: strcpy(MP3ME_info.mode, "unknown"); break; } switch (header.emphasis) { case MAD_EMPHASIS_NONE: strcpy(MP3ME_info.emphasis,"no"); break; case MAD_EMPHASIS_50_15_US: strcpy(MP3ME_info.emphasis,"50/15 us"); break; case MAD_EMPHASIS_CCITT_J_17: strcpy(MP3ME_info.emphasis,"CCITT J.17"); break; case MAD_EMPHASIS_RESERVED: strcpy(MP3ME_info.emphasis,"reserved(!)"); break; default: strcpy(MP3ME_info.emphasis,"unknown"); break; } //Check if lenght found in tag info: if (MP3ME_info.length > 0){ timeFromID3 = 1; break; } if (has_xing) break; } totalBitrate += header.bitrate; } if (size == bufferSize) break; else if (i==0) sceIoLseek(fd, startPos + size/3, PSP_SEEK_SET); else if (i==1) sceIoLseek(fd, startPos + 2 * size/3, PSP_SEEK_SET); if (timeFromID3 || has_xing) break; } mad_header_finish (&header); mad_stream_finish (&stream); if (buff){ free(buff); buff = NULL; } sceIoClose(fd); int secs = 0; if (has_xing) { /* modify header.duration since we don't need it anymore */ mad_timer_multiply(&header.duration, xing.frames); secs = mad_timer_count(header.duration, MAD_UNITS_SECONDS); MP3ME_info.length = secs; } else if (!MP3ME_info.length){ mediumBitrate = totalBitrate / (float)FrameCount; secs = size * 8 / mediumBitrate; MP3ME_info.length = secs; }else{ secs = MP3ME_info.length; } //Formatto in stringa la durata totale: int h = secs / 3600; int m = (secs - h * 3600) / 60; int s = secs - h * 3600 - m * 60; snprintf(MP3ME_info.strLength, sizeof(MP3ME_info.strLength), "%2.2i:%2.2i:%2.2i", h, m, s); return 0; }
int compare_file(const char *src, const char *dst) { SceUID fd = -1, fdd = -1; int ret, ret2; SceIoStat srcstat, dststat; ret = sceIoGetstat(src, &srcstat); if (ret != 0) { goto not_equal; } ret = sceIoGetstat(dst, &dststat); if (ret != 0) { goto not_equal; } if (dststat.st_size != srcstat.st_size) { goto not_equal; } ret = sceIoOpen(src, PSP_O_RDONLY, 0777); if (ret < 0) { goto not_equal; } fd = ret; ret = sceIoOpen(dst, PSP_O_RDONLY, 0777); if (ret < 0) { goto not_equal; } fdd = ret; ret = sizeof(g_buf); ret = sceIoRead(fd, g_buf, ret); while (ret > 0) { ret2 = sceIoRead(fdd, g_buf2, ret); if (ret2 != ret) { goto not_equal; } if (memcmp(g_buf, g_buf2, ret)) { goto not_equal; } ret = sceIoRead(fd, g_buf, ret); } if (ret < 0) { goto not_equal; } sceIoClose(fd); sceIoClose(fdd); return 0; not_equal: if (fd >= 0) sceIoClose(fd); if (fdd >= 0) sceIoClose(fdd); return 1; }
char *mp4_read_open(struct mp4_read_struct *p, char *s) { mp4_read_safe_constructor(p); char *result = mp4_file_open(&p->file, s); if (result != 0) { mp4_read_close(p); return(result); } p->video_handle = sceIoOpen(s, PSP_O_RDONLY, 0777); if (p->video_handle < 0) { mp4_read_close(p); return("mp4_read_open: can't open file"); } if (sceIoChangeAsyncPriority(p->video_handle, 0x10) < 0) { mp4_read_close(p); return("mp4_read_open: sceIoChangeAsyncPriority failed"); } p->audio_handle = sceIoOpen(s, PSP_O_RDONLY, 0777); if (p->audio_handle < 0) { mp4_read_close(p); return("mp4_read_open: can't open file"); } if (sceIoChangeAsyncPriority(p->audio_handle, 0x10) < 0) { mp4_read_close(p); return("mp4_read_open: sceIoChangeAsyncPriority failed"); } p->video_buffer_0 = malloc_64(p->file.maximum_video_trunk_size); if (p->video_buffer_0 == 0) { mp4_read_close(p); return("mp4_read_open: malloc_64 failed on buffer_0"); } memset(p->video_buffer_0, 0, p->file.maximum_video_trunk_size); p->video_buffer_1 = malloc_64(p->file.maximum_video_trunk_size); if (p->video_buffer_1 == 0) { mp4_read_close(p); return("mp4_read_open: malloc_64 failed on buffer_1"); } memset(p->video_buffer_1, 0, p->file.maximum_video_trunk_size); p->audio_buffer_0 = malloc_64(p->file.maximum_audio_trunk_size); if (p->audio_buffer_0== 0) { mp4_read_close(p); return("mp4_read_open: malloc_64 failed on buffer_0"); } memset(p->audio_buffer_0, 0, p->file.maximum_audio_trunk_size); p->audio_buffer_1 = malloc_64(p->file.maximum_audio_trunk_size); if (p->audio_buffer_1== 0) { mp4_read_close(p); return("mp4_read_open: malloc_64 failed on buffer_0"); } memset(p->audio_buffer_1, 0, p->file.maximum_audio_trunk_size); p->audio_cache_buffer = malloc_64((sizeof(unsigned int)+p->file.maximum_audio_sample_size) * p->file.maximun_audio_sample_number); if (p->audio_cache_buffer== 0) { mp4_read_close(p); } memset(p->audio_cache_buffer, 0, (sizeof(unsigned int)+p->file.maximum_audio_sample_size) * p->file.maximun_audio_sample_number); p->audio_output_length = (unsigned int*)p->audio_cache_buffer; p->audio_output_buffer = p->audio_cache_buffer + sizeof(unsigned int)*p->file.maximun_audio_sample_number; p->video_asynchronous_buffer_0.buffer = p->video_buffer_0; p->video_asynchronous_buffer_1.buffer = p->video_buffer_1; p->video_current_asynchronous_buffer = &p->video_asynchronous_buffer_0; p->video_next_asynchronous_buffer = &p->video_asynchronous_buffer_1; p->audio_asynchronous_buffer_0.buffer = p->audio_buffer_0; p->audio_asynchronous_buffer_1.buffer = p->audio_buffer_1; p->audio_current_asynchronous_buffer = &p->audio_asynchronous_buffer_0; p->audio_next_asynchronous_buffer = &p->audio_asynchronous_buffer_1; time_math_interleaving_constructor(&p->interleaving, p->file.video_rate, p->file.video_scale, p->file.audio_rate, p->file.audio_resample_scale); time_math_interleaving_get(&p->interleaving); result = video_fill_current_and_next_asynchronous_buffer(p, 0); if (result != 0) { mp4_read_close(p); return(result); } result = audio_fill_current_and_next_asynchronous_buffer(p, 0); if (result != 0) { mp4_read_close(p); return(result); } return(0); }
int read_umd_chapter_content(const char *umdfile, u_int index, p_umd_chapter pchapter /*,size_t file_offset,size_t length */ , buffer ** pbuf) { int ret = -1; SceUID fd = -1; SceIoStat sta; char buf[9] = { 0 }; size_t stlen = 0; size_t stoutlen = 0; size_t stUnzipSize = 0; buffer *pzbuf = NULL; buffer *puzbuf = NULL; bool bok = false; struct t_chapter *pchap; size_t chunk_pos; size_t chunk_offset; size_t length; if (!umdfile || !pchapter || index + 1 > pchapter->chapter_count || !pchapter->pchapters || !(pchapter->pchapters + index) || !pbuf || !(*pbuf)) return -1; pchap = pchapter->pchapters + index; chunk_pos = pchap->chunk_pos; chunk_offset = pchap->chunk_offset; length = pchap->length; do { char *p; struct UMDHeaderDataEx *pEx; if (sceIoGetstat(umdfile, &sta) < 0 || sta.st_size < chunk_pos) { return -1; } if ((fd = sceIoOpen(umdfile, PSP_O_RDONLY, 0777)) < 0) { return -2; } if (sceIoLseek(fd, chunk_pos, PSP_SEEK_SET) < 0) { break; } if ((stlen = sceIoRead(fd, buf, 9)) < 0) { //dbg_printf(d, "%s read umd file head chunk error!",__func__); break; } p = &buf[0]; pzbuf = buffer_init(); if (pzbuf == NULL) break; puzbuf = buffer_init(); if (puzbuf == NULL) break; pEx = (struct UMDHeaderDataEx *) p; if (!pEx || pEx->Mark != '$' || pEx->Length < 9) break; stlen = pEx->Length - 9; stoutlen = stlen * 2; buf_offset = 0; umdfile_offset = chunk_pos + 9; umdfile_remain = sta.st_size - umdfile_offset; if (stlen < length + chunk_offset) { bool bfirst_chunk = true; size_t stHeadSize = sizeof(struct UMDHeaderData); size_t stHeadExSize = sizeof(struct UMDHeaderDataEx); //buffer_prepare_copy(pzbuf,stlen); buffer_prepare_copy(pzbuf, umdfile_remain); pzbuf->used = pzbuf->size; if (0 > read_umd_buf(fd, &pzbuf)) { //dbg_printf(d, "%s not start with 0xde9a9b89,that umd must be corrupted!",__func__); break; } buffer_prepare_copy(*pbuf, length); while (*p == '$') { bok = false; pEx = (struct UMDHeaderDataEx *) p; stlen = pEx->Length; if (stlen < 9) { ////dbg_printf(d,"%s zipLength %d < 9",__func__,ZipLength); break; } //pchap[i++].pos = umdfile_offset - 9; stlen -= 9; stoutlen = stlen * 2; buffer_prepare_copy(puzbuf, stoutlen); if (0 > get_chunk_buf(fd, &pzbuf, &p, stlen)) break; stUnzipSize = umd_inflate((Byte *) p, (Byte *) puzbuf->ptr, stlen, stoutlen); if (stUnzipSize < 0 || stUnzipSize > stoutlen) { printf("stUnzipSize %d not in limit size:%d", stUnzipSize, stoutlen); break; } if (bfirst_chunk) { if (length <= stUnzipSize - chunk_offset) { buffer_append_memory(*pbuf, puzbuf->ptr + chunk_offset, length); ret = length; bok = true; break; } buffer_append_memory(*pbuf, puzbuf->ptr + chunk_offset, stUnzipSize - chunk_offset); length -= (stUnzipSize - chunk_offset); chunk_offset = 0; bfirst_chunk = false; } else if (length > stUnzipSize) { buffer_append_memory(*pbuf, puzbuf->ptr, stUnzipSize); length -= stUnzipSize; } else { buffer_append_memory(*pbuf, puzbuf->ptr + chunk_offset, stUnzipSize - chunk_offset); ret = pchap->length; bok = true; break; } if (*(pzbuf->ptr + buf_offset) == '#') { bok = true; while (*(pzbuf->ptr + buf_offset) == '#') { struct UMDHeaderData *pHead; if (0 > get_chunk_buf(fd, &pzbuf, &p, stHeadSize)) { bok = false; break; } pHead = (struct UMDHeaderData *) p; if (pHead->hdType == 0xf1 || pHead->hdType == 10) { if (*(pzbuf->ptr + buf_offset + pHead->Length - stHeadSize) == '#') { if (0 > get_chunk_buf(fd, &pzbuf, &p, pHead->Length - stHeadSize)) { bok = false; break; } } else { if (0 > get_offset_chunk_buf(fd, &pzbuf, &p, pHead->Length - stHeadSize, stHeadExSize)) bok = false; break; } } else if (pHead->hdType == 0x81) { printf("you should never come here fileoffset:%d\n", umdfile_offset); if (pzbuf) buffer_free(pzbuf); if (puzbuf) buffer_free(puzbuf); sceIoClose(fd); return 0; } } if (!bok) break; } else { if (0 > get_chunk_buf(fd, &pzbuf, &p, stHeadExSize)) break; } } } else { buffer_prepare_copy(pzbuf, stlen); pzbuf->used = pzbuf->size; if (0 > read_umd_buf(fd, &pzbuf)) { //dbg_printf(d, "%s not start with 0xde9a9b89,that umd must be corrupted!",__func__); break; } if (0 > get_chunk_buf(fd, &pzbuf, &p, stlen)) break; buffer_prepare_copy(puzbuf, stoutlen); stUnzipSize = umd_inflate((Byte *) p, (Byte *) puzbuf->ptr, stlen, stoutlen); if (stUnzipSize < 0 || stUnzipSize > stoutlen) { printf("stUnzipSize %d not in limit size:%d", stUnzipSize, stoutlen); break; } buffer_copy_string_len(*pbuf, puzbuf->ptr + chunk_offset, length); ret = length; } } while (false); if (pzbuf) buffer_free(pzbuf); if (puzbuf) buffer_free(puzbuf); if (fd) sceIoClose(fd); return ret; }
int main() { char vita_ip[16]; unsigned short int vita_port = 0; vita2d_init(); vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF)); clr_color = 0x000000FF; SceCtrlData pad; SceCtrlData oldpad; while (1) { // Load main script SceUID main_file = sceIoOpen("ux0:/data/lpp/menu.lua", SCE_O_RDONLY, 0777); if (main_file < 0) errMsg = "menu.lua not found."; else{ SceOff size = sceIoLseek(main_file, 0, SEEK_END); if (size < 1) errMsg = "Invalid main script."; else{ sceIoLseek(main_file, 0, SEEK_SET); script = (unsigned char*)malloc(size + 1); sceIoRead(main_file, script, size); script[size] = 0; sceIoClose(main_file); errMsg = runScript((const char*)script, true); free(script); } } if (errMsg != NULL){ if (strstr(errMsg, "lpp_shutdown")) break; else{ int restore = 0; bool s = true; while (restore == 0){ vita2d_start_drawing(); vita2d_clear_screen(); font_draw_string(10, 10, RGBA8(255, 255, 255, 255), "An error occurred:"); font_draw_string(10, 30, RGBA8(255, 255, 255, 255), errMsg); font_draw_string(10, 70, RGBA8(255, 255, 255, 255), "Press X to restart."); font_draw_string(10, 90, RGBA8(255, 255, 255, 255), "Press O to enable/disable FTP."); if (vita_port != 0){ font_draw_stringf(10, 150, RGBA8(255, 255, 255, 255), "PSVITA listening on IP %s , Port %u", vita_ip, vita_port); } vita2d_end_drawing(); vita2d_swap_buffers(); if (s){ sceKernelDelayThread(800000); s = false; } sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & SCE_CTRL_CROSS) { errMsg = NULL; restore = 1; if (vita_port != 0){ ftp_fini(); vita_port = 0; } sceKernelDelayThread(800000); }else if ((pad.buttons & SCE_CTRL_CIRCLE) && (!(oldpad.buttons & SCE_CTRL_CIRCLE))){ if (vita_port == 0) ftp_init(vita_ip, &vita_port); else{ ftp_fini(); vita_port = 0; } } oldpad = pad; } } } } vita2d_fini(); return 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Private functions: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Decode thread: int AACdecodeThread(SceSize args, void *argp){ u8* aac_data_buffer = NULL; u32 aac_data_start; u8 aac_getEDRAM; u32 aac_channels; u32 aac_samplerate; sceAudiocodecReleaseEDRAM(aac_codec_buffer); sceIoChdir(audioCurrentDir); AAC_threadActive = 1; AAC_handle = sceIoOpen(AAC_fileName, PSP_O_RDONLY, 0777); if ( ! AAC_handle ){ AAC_threadActive = 0; goto end; } aac_output_index = 0; aac_channels = 2; aac_samplerate = AAC_info.hz; aac_data_start = 0; if (AAC_tagsize > 0) aac_data_start = AAC_tagsize + 10; sceIoLseek32(AAC_handle, aac_data_start, PSP_SEEK_SET); aac_data_start = SeekNextFrameMP3(AAC_handle); memset(aac_codec_buffer, 0, sizeof(aac_codec_buffer)); if ( sceAudiocodecCheckNeedMem(aac_codec_buffer, 0x1003) < 0 ){ AAC_threadActive = 0; goto end; } if ( sceAudiocodecGetEDRAM(aac_codec_buffer, 0x1003) < 0 ){ AAC_threadActive = 0; goto end; } aac_getEDRAM = 1; aac_codec_buffer[10] = aac_samplerate; if ( sceAudiocodecInit(aac_codec_buffer, 0x1003) < 0 ){ AAC_threadActive = 0; goto end; } int samplesdecoded; AAC_eof = 0; unsigned char aac_header_buf[7]; int skip = 0; while (AAC_threadActive){ while( !AAC_eof && AAC_isPlaying ){ memset(aac_mix_buffer, 0, aac_sample_per_frame*2*2); if ( sceIoRead( AAC_handle, aac_header_buf, 7 ) != 7 ) { AAC_eof = 1; continue; } int aac_header = aac_header_buf[3]; aac_header = (aac_header<<8) | aac_header_buf[4]; aac_header = (aac_header<<8) | aac_header_buf[5]; aac_header = (aac_header<<8) | aac_header_buf[6]; int frame_size = aac_header & 67100672; frame_size = frame_size >> 13; frame_size = frame_size - 7; if ( aac_data_buffer ){ free(aac_data_buffer); aac_data_buffer = NULL; } aac_data_buffer = (u8*)memalign(64, frame_size); if (AAC_newFilePos >= 0) { if (!AAC_newFilePos) AAC_newFilePos = AAC_tagsize + 10; u32 old_start = aac_data_start; if (sceIoLseek32(AAC_handle, AAC_newFilePos, PSP_SEEK_SET) != old_start){ aac_data_start = SeekNextFrameMP3(AAC_handle); if(aac_data_start < 0){ AAC_eof = 1; } AAC_playingTime = (float)aac_data_start / (float)frame_size / (float)aac_samplerate / 1000.0f; } AAC_newFilePos = -1; continue; } //Check for playing speed: if (AAC_playingSpeed){ if (skip){ u32 old_start = aac_data_start; if (sceIoLseek32(AAC_handle, frame_size / 4 * AAC_playingSpeed, PSP_SEEK_CUR) != old_start){ aac_data_start = SeekNextFrameMP3(AAC_handle); if(aac_data_start < 0){ AAC_eof = 1; continue; } AAC_filePos = aac_data_start; float framesSkipped = (float)aac_data_start / (float)frame_size; AAC_playingTime = framesSkipped * (float)aac_sample_per_frame/(float)aac_samplerate; }else AAC_setPlayingSpeed(0); skip = !skip; continue; } skip = !skip; } if ( sceIoRead( AAC_handle, aac_data_buffer, frame_size ) != frame_size ) { AAC_eof = 1; continue; } aac_data_start += (frame_size+7); AAC_filePos = aac_data_start; aac_codec_buffer[6] = (unsigned long)aac_data_buffer; aac_codec_buffer[8] = (unsigned long)aac_mix_buffer; aac_codec_buffer[7] = frame_size; aac_codec_buffer[9] = aac_sample_per_frame * 4; int res = sceAudiocodecDecode(aac_codec_buffer, 0x1003); if ( res < 0 ) { AAC_eof = 1; continue; } memcpy(aac_output_buffer[aac_output_index], aac_mix_buffer, aac_sample_per_frame*4); //Volume Boost: if (AAC_volume_boost){ int i; for (i=0; i<aac_sample_per_frame * 2; i++){ aac_output_buffer[aac_output_index][i] = volume_boost(&aac_output_buffer[aac_output_index][i], &AAC_volume_boost); } } audioOutput(AAC_volume, aac_output_buffer[aac_output_index]); aac_output_index = (aac_output_index+1)%4; samplesdecoded = aac_sample_per_frame; AAC_playingTime += (float)aac_sample_per_frame/(float)aac_samplerate; AAC_info.framesDecoded++; } sceKernelDelayThread(10000); } end: if ( AAC_handle ) sceIoClose(AAC_handle); if ( aac_data_buffer) { free(aac_data_buffer); aac_data_buffer = NULL; } if ( aac_getEDRAM ) sceAudiocodecReleaseEDRAM(aac_codec_buffer); sceKernelExitThread(0); return 0; }
int state_save(int slot) { SceUID fd = -1; pspTime nowtime; char path[MAX_PATH]; char error_mes[128]; char buf[128]; #if (EMU_SYSTEM == NCDZ) UINT8 *inbuf, *outbuf; unsigned long insize, outsize; #else #ifndef ADHOC UINT8 *state_buffer_base; #endif UINT32 size; #endif sprintf(path, "%sstate/%s.sv%d", launchDir, game_name, slot); sceIoRemove(path); sprintf(buf, TEXT(STATE_SAVING), game_name, slot); init_progress(6, buf); sceRtcGetCurrentClockLocalTime(&nowtime); if ((fd = sceIoOpen(path, PSP_O_WRONLY|PSP_O_CREAT, 0777)) >= 0) #if (EMU_SYSTEM == NCDZ) { if ((inbuf = memalign(MEM_ALIGN, STATE_BUFFER_SIZE)) == NULL) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); goto error; } memset(inbuf, 0, STATE_BUFFER_SIZE); state_buffer = inbuf; state_save_byte(current_version_str, 8); state_save_byte(&nowtime, 16); update_progress(); save_thumbnail(); update_progress(); sceIoWrite(fd, inbuf, (UINT32)state_buffer - (UINT32)inbuf); update_progress(); memset(inbuf, 0, STATE_BUFFER_SIZE); state_buffer = inbuf; state_save_memory(); state_save_m68000(); state_save_z80(); state_save_input(); state_save_timer(); state_save_driver(); state_save_video(); state_save_ym2610(); state_save_cdda(); state_save_cdrom(); update_progress(); insize = (UINT32)state_buffer - (UINT32)inbuf; outsize = insize * 1.1 + 12; if ((outbuf = memalign(MEM_ALIGN, outsize)) == NULL) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); free(inbuf); goto error; } memset(outbuf, 0, outsize); if (compress(outbuf, &outsize, inbuf, insize) != Z_OK) { strcpy(error_mes, TEXT(COULD_NOT_COMPRESS_STATE_DATA)); free(inbuf); free(outbuf); goto error; } free(inbuf); update_progress(); sceIoWrite(fd, &outsize, 4); sceIoWrite(fd, outbuf, outsize); sceIoClose(fd); free(outbuf); update_progress(); show_progress(buf); return 1; } #else { #ifdef ADHOC state_buffer = state_buffer_base; #else #if (EMU_SYSTEM == CPS1 || (EMU_SYSTEM == CPS2 && defined(PSP_SLIM))) state_buffer = state_buffer_base = memalign(MEM_ALIGN, STATE_BUFFER_SIZE); #else state_buffer = state_buffer_base = cache_alloc_state_buffer(STATE_BUFFER_SIZE); #endif if (!state_buffer) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); goto error; } #endif memset(state_buffer, 0, STATE_BUFFER_SIZE); update_progress(); state_save_byte(current_version_str, 8); state_save_byte(&nowtime, 16); update_progress(); save_thumbnail(); update_progress(); state_save_memory(); state_save_m68000(); state_save_z80(); state_save_input(); state_save_timer(); state_save_driver(); state_save_video(); #if (EMU_SYSTEM == CPS1) state_save_coin(); switch (machine_driver_type) { case MACHINE_qsound: state_save_qsound(); state_save_eeprom(); break; case MACHINE_pang3: state_save_eeprom(); default: state_save_ym2151(); break; } #elif (EMU_SYSTEM == CPS2) state_save_coin(); state_save_qsound(); state_save_eeprom(); #elif (EMU_SYSTEM == MVS) state_save_ym2610(); state_save_pd4990a(); #endif update_progress(); size = (UINT32)state_buffer - (UINT32)state_buffer_base; sceIoWrite(fd, state_buffer_base, size); sceIoClose(fd); update_progress(); #ifndef ADHOC #if (EMU_SYSTEM == CPS1 || (EMU_SYSTEM == CPS2 && defined(PSP_SLIM))) free(state_buffer_base); #else cache_free_state_buffer(STATE_BUFFER_SIZE); #endif #endif update_progress(); show_progress(buf); return 1; } #endif else {
int extractArchivePath(char *src, char *dst, FileProcessParam *param) { if (!uf) return -1; SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); if (archiveFileGetstat(src, &stat) < 0) { FileList list; memset(&list, 0, sizeof(FileList)); fileListGetArchiveEntries(&list, src, SORT_NONE); int ret = sceIoMkdir(dst, 0777); if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) { fileListEmpty(&list); return ret; } if (param) { if (param->value) (*param->value) += DIRECTORY_SIZE; if (param->SetProgress) param->SetProgress(param->value ? *param->value : 0, param->max); if (param->cancelHandler && param->cancelHandler()) { fileListEmpty(&list); return 0; } } FileListEntry *entry = list.head->next; // Ignore .. int i; for (i = 0; i < list.length - 1; i++) { char *src_path = malloc(strlen(src) + strlen(entry->name) + 2); snprintf(src_path, MAX_PATH_LENGTH, "%s%s", src, entry->name); char *dst_path = malloc(strlen(dst) + strlen(entry->name) + 2); snprintf(dst_path, MAX_PATH_LENGTH, "%s%s", dst, entry->name); int ret = extractArchivePath(src_path, dst_path, param); free(dst_path); free(src_path); if (ret <= 0) { fileListEmpty(&list); return ret; } entry = entry->next; } fileListEmpty(&list); } else { SceUID fdsrc = archiveFileOpen(src, SCE_O_RDONLY, 0); if (fdsrc < 0) return fdsrc; SceUID fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777); if (fddst < 0) { archiveFileClose(fdsrc); return fddst; } void *buf = malloc(TRANSFER_SIZE); uint64_t seek = 0; while (1) { int read = archiveFileRead(fdsrc, buf, TRANSFER_SIZE); if (read < 0) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return read; } if (read == 0) break; int written = sceIoWrite(fddst, buf, read); if (written == SCE_ERROR_ERRNO_ENODEV) { fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT, 0777); if (fddst >= 0) { sceIoLseek(fddst, seek, SCE_SEEK_SET); written = sceIoWrite(fddst, buf, read); } } if (written < 0) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return written; } seek += written; if (param) { if (param->value) (*param->value) += read; if (param->SetProgress) param->SetProgress(param->value ? *param->value : 0, param->max); if (param->cancelHandler && param->cancelHandler()) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return 0; } } } free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); } return 1; }
int initialise(SceSize args, void *argp) { int len; int fd; Elf32_Ehdr hdr; memset(&g_context, 0, sizeof(g_context)); if(argp == NULL) { return 0; } len = strlen((char*) argp)+1; argp += len; args -= len; if(args <= 0) { return 0; } g_context.argp = argp; g_context.args = args; fd = sceIoOpen((char*) argp, PSP_O_RDONLY, 0777); if(fd < 0) { printf("%s does not exist\n", (char*) argp); return 0; } len = sceIoRead(fd, &hdr, sizeof(hdr)); sceIoClose(fd); if(len != sizeof(hdr)) { printf("Could not read in ELF header\n"); return 0; } if(hdr.e_magic != ELF_MAGIC) { printf("Invalid ELF magic\n"); return 0; } if(hdr.e_type == ELF_MIPS_TYPE) { g_context.elf = 1; } else if(hdr.e_type != ELF_PRX_TYPE) { printf("Invalid ELF type code\n"); return 0; } g_context.uid = sceKernelLoadModule(argp, 0, NULL); sceIoClose(fd); if(g_context.uid < 0) { printf("Could not load module %s (0x%08X)\n", (char*) argp, g_context.uid); return 0; } if(!psplinkReferModule(g_context.uid, &g_context.info)) { printf("Could not refer module info\n"); return 0; } g_context.ctx.regs.epc = g_context.info.entry_addr; g_context.ctx.regs.cause = 9 << 2; printf("Loaded %s - UID 0x%08X, Entry 0x%08X\n", (char*)argp, g_context.uid, g_context.info.entry_addr); int t_pommel; int t_result = sceSysconGetPommelVersion(&t_pommel); if ((t_pommel >= 0x123) && (t_result == 0)) // If PSP 2000 or newer allow 64MB to be peeked and poked instead of 32MB g_userend = 0x0C000000; else g_userend = 0x0A000000; return 1; }
int makeCxmbThemeFile( unsigned int cxmb_magic, const char * cxmb_theme_file ) { const char * folders_name[] = { "/data/cert", "/dic", "/font", "/kd", "/kd/resource", "/vsh/etc", "/vsh/module", "/vsh/resource" }; int folders_count = 8; const char * support_exts[] = { ".prx", ".rco", ".bmp", ".pmf", ".res", ".pgf", ".bwfon", ".rsc", ".dat", ".img", ".bin", ".cet", ".dic" }; int exts_count = 13; int dfd, heap_id, fd, i, bytes, file_count = 0; unsigned int ptf_h[5]; char path[128], file[128], preview[64]; u8 * buf; // dectect if theme file in conf exist int ctf = sceIoOpen( cxmb_theme_file, PSP_O_RDONLY, 0644 ); if ( ctf >= 0 ) { log( "theme file exist!\n" ); sceIoClose( ctf ); return 0; } dfd = sceIoDopen( "ms0:/cxmb" ); if ( dfd < 0 ) { log( "no cxmb folder found!\n" ); return 0; } sceIoDclose( dfd ); sprintf( preview, "ms0:/cxmb%s", &cxmb_theme_file[14] ); preview[strlen( preview ) - 3] = 'p'; log( "preview: %s\n", preview ); fd = sceIoOpen( preview, PSP_O_RDONLY, 0644 ); if ( fd < 0 ) { log( "no preview ptf file found!\n" ); return 0; } sceIoLseek( fd, 0x100, PSP_SEEK_SET ); sceIoRead( fd, ptf_h, 20 ); // create CXMB_MKCTF_BUF_SIZE + 32kb heap heap_id = sceKernelCreateHeap( 2, CXMB_MKCTF_BUF_SIZE + 1024 * 32 , 1, "cxmb_tmp_heap"); if ( heap_id < 0 ) { log( "failed in create heap in making cxmb theme file!\n" ); return -1; } CtfHeader * ch = ( CtfHeader * )sceKernelAllocHeapMemory( heap_id, sizeof( CtfHeader ) * 64 ); memset( ch, 0, sizeof( CtfHeader ) * 64 ); SceIoDirent * ent = ( SceIoDirent * )sceKernelAllocHeapMemory( heap_id, sizeof( SceIoDirent ) ); memset( ent, 0, sizeof( SceIoDirent ) ); sceIoMkdir( "ms0:/PSP/THEME", 0777 ); ctf = sceIoOpen( cxmb_theme_file, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC, 0777 ); if ( ctf < 0 ) { log( "failed in opening %s\n", cxmb_theme_file ); sceKernelFreeHeapMemory( heap_id, ent ); sceKernelFreeHeapMemory( heap_id, ch ); sceKernelDeleteHeap( heap_id ); return -1; } else { if ( ptf_h[2] == 0 ) ptf_h[2] = sceIoLseek( fd, 0, PSP_SEEK_END ); log( "ptf sections size %08x\n", ptf_h[2] ); buf = sceKernelAllocHeapMemory( heap_id, ptf_h[2] ); if ( buf ) { sceIoLseek( fd, 0, PSP_SEEK_SET ); sceIoRead( fd, buf, ptf_h[2] ); sceIoWrite( ctf, buf, ptf_h[2] ); sceIoClose( fd ); sceKernelFreeHeapMemory( heap_id, buf ); sceIoLseek( ctf, 0x10, PSP_SEEK_SET ); sceIoWrite( ctf, &cxmb_magic, 4 ); sceIoLseek( ctf, 0x1C, PSP_SEEK_SET ); sceIoWrite( ctf, &ptf_h[2], 4 ); memset( &ptf_h[2], 0, 12 ); sceIoLseek( ctf, 0x100, PSP_SEEK_SET ); sceIoWrite( ctf, ptf_h, 20 ); sceIoLseek( ctf, 0, PSP_SEEK_END ); for ( i = 0; i < folders_count; i ++ ) { sprintf( path, "ms0:/cxmb%s", folders_name[i] ); dfd = sceIoDopen( path ); if ( dfd < 0 ) { log( "folder %s not found!\n", path ); continue; } log( "parsing %s\n", path ); while ( sceIoDread( dfd, ent ) > 0 ) { log( "found %s\n", ent->d_name ); if ( ( ent->d_stat.st_attr & FIO_SO_IFDIR ) || ent->d_name[0] == '.' ) { log( "ignore %s\n", ent->d_name ); continue; } if ( endwithistrs( ent->d_name, support_exts, exts_count ) ) { sprintf( file, "%s/%s", path, ent->d_name ); sprintf( ch[file_count].name, "%s/%s", folders_name[i], ent->d_name ); ch[file_count].start = sceIoLseek( ctf, 0, PSP_SEEK_CUR ); ch[file_count].size = 0; if ( cmpistrs( ent->d_name, diff_files, diff_count ) ) { char ori_file[128]; sprintf( ori_file, "%s/%s", CXMB_SUPPORT_FOLDER, ent->d_name ); ch[file_count].size = makeDiff( file, ori_file, heap_id, ctf ); } else { log( "dealing with %s\n", ent->d_name ); fd = sceIoOpen( file, PSP_O_RDONLY, 0644 ); if ( fd < 0 ) { log( "failed in opening %s\n", file ); continue; } buf = ( u8 * )sceKernelAllocHeapMemory( heap_id, CXMB_MKCTF_BUF_SIZE ); bytes = sceIoRead( fd, buf, CXMB_MKCTF_BUF_SIZE ); while( bytes > 0 ) { ch[file_count].size += sceIoWrite( ctf, buf, bytes ); bytes = sceIoRead( fd, buf, CXMB_MKCTF_BUF_SIZE ); } sceKernelFreeHeapMemory( heap_id, buf ); sceIoClose( fd ); } if ( ch[file_count].size > 0 && ch[file_count].size < CXMB_MAX_FILE_SIZE ) { log( "start: %08x size: %08x\n", ch[file_count].start, ch[file_count].size ); file_count ++; } } else { log( "ignore %s\n", ent->d_name ); } } sceIoDclose( dfd ); } } else { log( "failed in allocating %08x heap\n", ptf_h[2] ); } } log( "file_count: %d\n", file_count ); if ( file_count > 0 ) { u8 sha1[20]; sceKernelUtilsSha1Digest( ( u8 * )ch, sizeof( CtfHeader ) * file_count, sha1 ); sceIoWrite( ctf, ch, sizeof( CtfHeader ) * file_count ); sceIoLseek( ctf, 0x14, PSP_SEEK_SET ); sceIoWrite( ctf, &sha1[0], 4 ); sceIoWrite( ctf, &file_count, 4 ); sceIoClose( ctf ); } else { sceIoClose( ctf ); sceIoRemove( cxmb_theme_file ); } sceKernelFreeHeapMemory( heap_id, ent ); sceKernelFreeHeapMemory( heap_id, ch ); sceKernelDeleteHeap( heap_id ); return 0; }
int main(void) { SetupCallbacks(); int result = pspSdkLoadStartModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL); pspSdkFixupImports(result); SceUID aa3_handle = sceIoOpen("ms0:/Test.AA3", PSP_O_RDONLY, 0777); // or ms0:/Test.OMA if ( ! aa3_handle ) goto wait; sceIoLseek32(aa3_handle, 0x0C00, PSP_SEEK_SET); u8 ea3_header[0x60]; if ( sceIoRead( aa3_handle, ea3_header, 0x60 ) != 0x60 ) goto wait; if ( ea3_header[0] != 0x45 || ea3_header[1] != 0x41 || ea3_header[2] != 0x33 || ea3_header[3] != 0x01 ) goto wait; aa3_at3plus_flagdata[0] = ea3_header[0x22]; aa3_at3plus_flagdata[1] = ea3_header[0x23]; aa3_type = (ea3_header[0x22] == 0x20) ? TYPE_ATRAC3 : ((ea3_header[0x22] == 0x28) ? TYPE_ATRAC3PLUS : 0x0); if ( aa3_type != TYPE_ATRAC3 && aa3_type != TYPE_ATRAC3PLUS ) goto wait; aa3_channels = 2; aa3_samplerate = 44100; if ( aa3_type == TYPE_ATRAC3 ) aa3_data_align = ea3_header[0x23]*8; else aa3_data_align = (ea3_header[0x23]+1)*8; aa3_data_start = 0x0C60; aa3_data_size = sceIoLseek32(aa3_handle, 0, PSP_SEEK_END) - aa3_data_start; if ( aa3_data_size % aa3_data_align != 0 ) goto wait; sceIoLseek32(aa3_handle, aa3_data_start, PSP_SEEK_SET); memset(aa3_codec_buffer, 0, sizeof(aa3_codec_buffer)); if ( aa3_type == TYPE_ATRAC3 ) { aa3_channel_mode = 0x0; if ( aa3_data_align == 0xC0 ) // atract3 have 3 bitrate, 132k,105k,66k, 132k align=0x180, 105k align = 0x130, 66k align = 0xc0 aa3_channel_mode = 0x1; aa3_sample_per_frame = 1024; aa3_data_buffer = (u8*)memalign(64, 0x180); if ( aa3_data_buffer == NULL) goto wait; aa3_codec_buffer[26] = 0x20; if ( sceAudiocodecCheckNeedMem(aa3_codec_buffer, 0x1001) < 0 ) goto wait; if ( sceAudiocodecGetEDRAM(aa3_codec_buffer, 0x1001) < 0 ) goto wait; aa3_getEDRAM = 1; aa3_codec_buffer[10] = 4; aa3_codec_buffer[44] = 2; if ( aa3_data_align == 0x130 ) aa3_codec_buffer[10] = 6; if ( sceAudiocodecInit(aa3_codec_buffer, 0x1001) < 0 ) { goto wait; } } else if ( aa3_type == TYPE_ATRAC3PLUS ) { aa3_sample_per_frame = 2048; int temp_size = aa3_data_align+8; int mod_64 = temp_size & 0x3f; if (mod_64 != 0) temp_size += 64 - mod_64; aa3_data_buffer = (u8*)memalign(64, temp_size); if ( aa3_data_buffer == NULL) goto wait; aa3_codec_buffer[5] = 0x1; aa3_codec_buffer[10] = aa3_at3plus_flagdata[1]; aa3_codec_buffer[10] = (aa3_codec_buffer[10] << 8 ) | aa3_at3plus_flagdata[0]; aa3_codec_buffer[12] = 0x1; aa3_codec_buffer[14] = 0x1; if ( sceAudiocodecCheckNeedMem(aa3_codec_buffer, 0x1000) < 0 ) goto wait; if ( sceAudiocodecGetEDRAM(aa3_codec_buffer, 0x1000) < 0 ) goto wait; aa3_getEDRAM = 1; if ( sceAudiocodecInit(aa3_codec_buffer, 0x1000) < 0 ) { goto wait; } } else goto wait; int eof = 0; while( !eof ) { int samplesdecoded; memset(aa3_mix_buffer, 0, 2048*2*2); unsigned long decode_type = 0x1001; if ( aa3_type == TYPE_ATRAC3 ) { memset( aa3_data_buffer, 0, 0x180); if (sceIoRead( aa3_handle, aa3_data_buffer, aa3_data_align ) != aa3_data_align) { eof = 1; continue; } if ( aa3_channel_mode ) { memcpy(aa3_data_buffer+aa3_data_align, aa3_data_buffer, aa3_data_align); } decode_type = 0x1001; } else { memset( aa3_data_buffer, 0, aa3_data_align+8); aa3_data_buffer[0] = 0x0F; aa3_data_buffer[1] = 0xD0; aa3_data_buffer[2] = aa3_at3plus_flagdata[0]; aa3_data_buffer[3] = aa3_at3plus_flagdata[1]; if (sceIoRead( aa3_handle, aa3_data_buffer+8, aa3_data_align ) != aa3_data_align) { eof = 1; continue; } decode_type = 0x1000; } aa3_codec_buffer[6] = (unsigned long)aa3_data_buffer; aa3_codec_buffer[8] = (unsigned long)aa3_mix_buffer; int res = sceAudiocodecDecode(aa3_codec_buffer, decode_type); if ( res < 0 ) { eof = 1; continue; } samplesdecoded = aa3_sample_per_frame; } wait: if ( aa3_handle ) { sceIoClose(aa3_handle); } if ( aa3_data_buffer) { free(aa3_data_buffer); } if ( aa3_getEDRAM ) { sceAudiocodecReleaseEDRAM(aa3_codec_buffer); } sceCtrlReadBufferPositive(&input, 1); while(!(input.Buttons & PSP_CTRL_TRIANGLE)) { sceKernelDelayThread(10000); // wait 10 milliseconds sceCtrlReadBufferPositive(&input, 1); } sceKernelExitGame(); return 0; }
//decrypt void decrypt(int mappadacar) { char fpath[50]; sprintf(fpath,"Mappe/mappa%i.txt",mappadacar); memset(ris,0,sizeof(ris)); int fd; int flen; //apre e legge la mappa poi salva in ris if(!(fd = sceIoOpen(fpath, PSP_O_RDONLY, 0777))) { } else { flen = sceIoRead(fd, ris, sizeof(ris)); if(flen <= 0) { } else { } } sceIoClose(fd); //decript la mappa e salva in ris 2 XORs(ris,KEY,ris2,strlen(ris)); int i=0; for(i=0; i<4; i++) { attbordo[i]=0; } i=0; resultatt = strtok( ris2, delimatt ); while( resultatt != NULL ) { sprintf(valorimappa[i],"%s", resultatt ); resultatt = strtok( NULL, delimatt ); i++; } sprintf(attributit,"%s",valorimappa[1]); i=0; resultval = strtok(attributit, "&"); while( resultval != NULL ) { attbordo[i]=atoi(resultval); resultval = strtok( NULL, "&" ); i++; } i=0; resulty = strtok( valorimappa[0] ,delimy ); while( resulty != NULL ) { sprintf(lineay[i],"%s", resulty ); resulty = strtok( NULL, delimy ); i++; } //variabili per prossimo split int x; int y; int j; int g; for(y=0; y<34; y++) { //for y j=0; resultx = strtok( lineay[y], delimx ); while( resultx != NULL ) { sprintf(lineax[j],"%s", resultx ); resultx = strtok( NULL, delimx ); j++; } //fine split x for(x=0; x<60; x++) { //split att g=0; resulta = strtok( lineax[x], delima ); while( resulta != NULL ) { mappe[0][0][y][x][g]=atoi(resulta); resulta = strtok( NULL,delima); g++; } //fine split att } } }
global void ini_file_save(void) { // FILE *fp; // char buf[128];/*64 50*/ strcpy(my_file_common_name, "./" FILE_NAME_SETTING_TXT); // fp = fopen(buf, "w"); SceUID fd = sceIoOpen((char *)my_file_common_name, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); // if (0 > fd) // { // /*"セーブデータがない。"*/ // } // if (NULL == fp) { return; } // /* 巧くいくけど off. */ #define USE_MEMO (0) #if (1==USE_MEMO) // 'CR'=='\r' というのは carrige Return (改行)の省略形。 '\r' の意味は(改行)コード。 // 'LF'=='\n' というのは New line (新行)の省略形。 '\n' の意味は(新規に次の行にする)コード。 // 'LF' は、 Line Feed (行変え)の省略形。行を変えるのだから、意味は新行と全く同じ。 // これは元々端末用語ではなく、プリンタ(印字)用語。これが端末(Terminal)用語に継承された。 //--------------------------- // MS-DOS/Windows では、テキストファイルの行末に[CR+LF]形式を採用している。 // "メモ帳"やms-dosの"edit"で新規ファイルを作成し、適当に改行を入れて保存するとこの形式。 //--------------------------- // Unix(Linux/FreeBSD等)では、テキストファイルの行末に[LF]形式を採用している。 // "vi"等"editer"で新規ファイルを作成し、適当に改行を入れて保存するとこの形式。 //--------------------------- // インターネットのサーバーでは、標準的にテキストファイルの行末に[LF]形式を採用している。 //--------------------------- // [Windows系 PC]->[サーバー]のupload時に、テキストファイルを[CR+LF]->[LF]変換し、 // [Windows系 PC]<-[サーバー]のdownload時に、テキストファイルを[LF]->[CR+LF]変換している。 // サーバーの相手が[Unix系 PC]の場合は、何も変換しない。 //--------------------------- // 但し、テキストファイルでないものをテキストファイルと認識した場合、変換機能があるとファイルが破壊される為、 // テキストファイルを強制的に"バイナリファイル"として扱い、変換しないサーバーもある。 // 逆に明らかに".png"画像なのに、(Windows系 PCでdownload時に)勝手に[LF]->[CR+LF]形式に変換し、 // 読めなくなっちゃうサーバーもある。(もちろん管理者の設定が悪い)。何処とは言わないが。 //--------------------------- #define KAIGYOU_CR_LF "\r\n" strcpy(my_file_line_buffer256, ";-------------------------------------" KAIGYOU_CR_LF "; 東方模倣風(r35) configuration file." KAIGYOU_CR_LF ";-------------------------------------" KAIGYOU_CR_LF KAIGYOU_CR_LF "; キーコンフィグ設定" KAIGYOU_CR_LF ); write_line_buffer_to_file(fd);/*fp*/ #endif /* (USE_MEMO) */ // { unsigned int i; for (i=0; i<KINOU_08_WARIATE_MAX; i++) { sprintf(my_file_line_buffer256, "K0%c,%d", ('a'+i), (signed)pad_config[i]); write_line_buffer_to_file(fd);/*fp*/ } } //--------------------------- #if (1==USE_MEMO) #define TITLE_OPTION_SETTEI KAIGYOU_CR_LF "; オプション設定" KAIGYOU_CR_LF strcpy(my_file_line_buffer256, TITLE_OPTION_SETTEI ); write_line_buffer_to_file(fd);/*fp*/ #endif /* (USE_MEMO) */ option_config[OPTION_CONFIG_04_CURRENT_DIFFICULTY] = (cg.game_difficulty); option_config[OPTION_CONFIG_05_CURRENT_PLAYER] = (cg_game_select_player); { unsigned int i; for (i=0; i<OPTION_CONFIG_08_MAX; i++) { sprintf(my_file_line_buffer256, "%s,%d", my_config_title[i], option_config[i]); write_line_buffer_to_file(fd);/*fp*/ } } //--------------------------- #if (1==USE_MEMO) #define TITLE_YUME_NO_KIROKU KAIGYOU_CR_LF "; 夢の記録" KAIGYOU_CR_LF strcpy(my_file_line_buffer256, TITLE_YUME_NO_KIROKU ); write_line_buffer_to_file(fd);/*fp*/ #endif /* (USE_MEMO) */ /* high_score save */ { unsigned int j; for (j=0; j<MAX_8_SAVE_PLAYERS; j++) { unsigned int i; for (i=0; i<MAX_5_RANKING; i++) { sprintf(my_file_line_buffer256, "SCORE" /* == dummy */ "%c" /* player number */ "%c" /* rank number */ "," /* == 区切り dummy */ "0" /* practice mode */ "%c" /* final stage */ "%8s" /* name */ "%09d"/*"0"*/, /* score */ // (j+'0'), /* player number */ (i+'0'), /* score rank number */ /* practice mode */ (high_score_table[j][i].final_stage+'0'),/* final stage */ high_score_table[j][i].name, (int)high_score_table[j][i].score/* gcc 4.3.5 */ ); write_line_buffer_to_file(fd);/*fp*/ } } } sceIoClose(fd);/*fclose(fp);*/ }
int initialise(SceSize args, void *argp) { int len; int fd; Elf32_Ehdr hdr; memset(&g_context, 0, sizeof(g_context)); if(argp == NULL) { return 0; } len = strlen((char*) argp)+1; argp += len; args -= len; if(args <= 0) { return 0; } g_context.argp = argp; g_context.args = args; fd = sceIoOpen((char*) argp, PSP_O_RDONLY, 0777); if(fd < 0) { printf("%s does not exist\n", (char*) argp); return 0; } len = sceIoRead(fd, &hdr, sizeof(hdr)); sceIoClose(fd); if(len != sizeof(hdr)) { printf("Could not read in ELF header\n"); return 0; } if(hdr.e_magic != ELF_MAGIC) { printf("Invalid ELF magic\n"); return 0; } if(hdr.e_type == ELF_MIPS_TYPE) { g_context.elf = 1; } else if(hdr.e_type != ELF_PRX_TYPE) { printf("Invalid ELF type code\n"); return 0; } g_context.uid = sceKernelLoadModule(argp, 0, NULL); sceIoClose(fd); if(g_context.uid < 0) { printf("Could not load module %s (0x%08X)\n", (char*) argp, g_context.uid); return 0; } if(!psplinkReferModule(g_context.uid, &g_context.info)) { printf("Could not refer module info\n"); return 0; } g_context.ctx.regs.epc = g_context.info.entry_addr; g_context.ctx.regs.cause = 9 << 2; printf("Loaded %s - UID 0x%08X, Entry 0x%08X\n", (char*)argp, g_context.uid, g_context.info.entry_addr); return 1; }
/* Helper function for file io. */ int fileExist(const char* sFilePath) { int fileCheck, fileExists; fileCheck = sceIoOpen(sFilePath, PSP_O_RDONLY, 0); if (fileCheck > 0) { fileExists = 1; } else { fileExists = 0; } sceIoClose(fileCheck); return fileExists; }
static int load_rom_info(const char *game_name) { SceUID fd; char path[MAX_PATH]; char *buf; char linebuf[256]; int i, size; int rom_start = 0; int region = 0; num_cpu1rom = 0; num_cpu2rom = 0; num_gfx1rom = 0; num_snd1rom = 0; machine_driver_type = 0; machine_input_type = 0; machine_init_type = 0; machine_screen_type = 0; sprintf(path, "%srominfo.cps1", launchDir); if ((fd = sceIoOpen(path, PSP_O_RDONLY, 0777)) >= 0) { size = sceIoLseek(fd, 0, SEEK_END); sceIoLseek(fd, 0, SEEK_SET); if ((buf = (char *)malloc(size)) == NULL) { sceIoClose(fd); return 3; // 手抜き } sceIoRead(fd, buf, size); sceIoClose(fd); i = 0; while (i < size) { char *p = &buf[i]; while (buf[i] != '\n' && buf[i] != EOF) i++; buf[i++] = '\0'; strcpy(linebuf, p); strcat(linebuf, "\n"); if (linebuf[0] == '/' && linebuf[1] == '/') continue; if (linebuf[0] != '\t') { if (linebuf[0] == '\r' || linebuf[0] == '\n') { // 改行 continue; } else if (str_cmp(linebuf, "FILENAME(") == 0) { char *name, *parent; char *machine, *input, *init, *rotate; strtok(linebuf, " "); name = strtok(NULL, " ,"); parent = strtok(NULL, " ,"); machine = strtok(NULL, " ,"); input = strtok(NULL, " ,"); init = strtok(NULL, " ,"); rotate = strtok(NULL, " "); if (stricmp(name, game_name) == 0) { if (str_cmp(parent, "cps1") == 0) parent_name[0] = '\0'; else strcpy(parent_name, parent); sscanf(machine, "%d", &machine_driver_type); sscanf(input, "%d", &machine_input_type); sscanf(init, "%d", &machine_init_type); sscanf(rotate, "%d", &machine_screen_type); rom_start = 1; } } else if (rom_start && str_cmp(linebuf, "END") == 0) { free(buf); return 0; } } else if (rom_start) { if (str_cmp(&linebuf[1], "REGION(") == 0) { char *size, *type, *flag; strtok(&linebuf[1], " "); size = strtok(NULL, " ,"); type = strtok(NULL, " ,"); flag = strtok(NULL, " "); if (strcmp(type, "CPU1") == 0) { sscanf(size, "%x", &memory_length_cpu1); region = REGION_CPU1; } else if (strcmp(type, "CPU2") == 0) { sscanf(size, "%x", &memory_length_cpu2); region = REGION_CPU2; } else if (strcmp(type, "GFX1") == 0) { sscanf(size, "%x", &memory_length_gfx1); region = REGION_GFX1; } else if (strcmp(type, "SOUND1") == 0) { sscanf(size, "%x", &memory_length_sound1); region = REGION_SOUND1; } else if (strcmp(type, "USER1") == 0) { sscanf(size, "%x", &memory_length_user1); region = REGION_USER1; } else { region = REGION_SKIP; } } else if (str_cmp(&linebuf[1], "ROM(") == 0) { char *type, *name, *offset, *length, *crc; strtok(&linebuf[1], " "); type = strtok(NULL, " ,"); if (type[0] != '1') name = strtok(NULL, " ,"); else name = NULL; offset = strtok(NULL, " ,"); length = strtok(NULL, " ,"); crc = strtok(NULL, " "); switch (region) { case REGION_CPU1: sscanf(type, "%x", &cpu1rom[num_cpu1rom].type); sscanf(offset, "%x", &cpu1rom[num_cpu1rom].offset); sscanf(length, "%x", &cpu1rom[num_cpu1rom].length); sscanf(crc, "%x", &cpu1rom[num_cpu1rom].crc); if (name) strcpy(cpu1rom[num_cpu1rom].name, name); cpu1rom[num_cpu1rom].group = 0; cpu1rom[num_cpu1rom].skip = 0; num_cpu1rom++; break; case REGION_CPU2: sscanf(type, "%x", &cpu2rom[num_cpu2rom].type); sscanf(offset, "%x", &cpu2rom[num_cpu2rom].offset); sscanf(length, "%x", &cpu2rom[num_cpu2rom].length); sscanf(crc, "%x", &cpu2rom[num_cpu2rom].crc); if (name) strcpy(cpu2rom[num_cpu2rom].name, name); cpu2rom[num_cpu2rom].group = 0; cpu2rom[num_cpu2rom].skip = 0; num_cpu2rom++; break; case REGION_GFX1: sscanf(type, "%x", &gfx1rom[num_gfx1rom].type); sscanf(offset, "%x", &gfx1rom[num_gfx1rom].offset); sscanf(length, "%x", &gfx1rom[num_gfx1rom].length); sscanf(crc, "%x", &gfx1rom[num_gfx1rom].crc); if (name) strcpy(gfx1rom[num_gfx1rom].name, name); gfx1rom[num_gfx1rom].group = 0; gfx1rom[num_gfx1rom].skip = 0; num_gfx1rom++; break; case REGION_SOUND1: sscanf(type, "%x", &snd1rom[num_snd1rom].type); sscanf(offset, "%x", &snd1rom[num_snd1rom].offset); sscanf(length, "%x", &snd1rom[num_snd1rom].length); sscanf(crc, "%x", &snd1rom[num_snd1rom].crc); if (name) strcpy(snd1rom[num_snd1rom].name, name); snd1rom[num_snd1rom].group = 0; snd1rom[num_snd1rom].skip = 0; num_snd1rom++; break; } } else if (str_cmp(&linebuf[1], "ROMX(") == 0) { char *type, *name, *offset, *length, *crc; char *group, *skip; strtok(&linebuf[1], " "); type = strtok(NULL, " ,"); if (type[0] != '1') name = strtok(NULL, " ,"); else name = NULL; offset = strtok(NULL, " ,"); length = strtok(NULL, " ,"); crc = strtok(NULL, " ,"); group = strtok(NULL, " ,"); skip = strtok(NULL, " "); switch (region) { case REGION_CPU1: sscanf(type, "%x", &cpu1rom[num_cpu1rom].type); sscanf(offset, "%x", &cpu1rom[num_cpu1rom].offset); sscanf(length, "%x", &cpu1rom[num_cpu1rom].length); sscanf(crc, "%x", &cpu1rom[num_cpu1rom].crc); sscanf(group, "%x", &cpu1rom[num_cpu1rom].group); sscanf(skip, "%x", &cpu1rom[num_cpu1rom].skip); if (name) strcpy(cpu1rom[num_cpu1rom].name, name); num_cpu1rom++; break; case REGION_GFX1: sscanf(type, "%x", &gfx1rom[num_gfx1rom].type); sscanf(offset, "%x", &gfx1rom[num_gfx1rom].offset); sscanf(length, "%x", &gfx1rom[num_gfx1rom].length); sscanf(crc, "%x", &gfx1rom[num_gfx1rom].crc); sscanf(group, "%x", &gfx1rom[num_gfx1rom].group); sscanf(skip, "%x", &gfx1rom[num_gfx1rom].skip); if (name) strcpy(gfx1rom[num_gfx1rom].name, name); num_gfx1rom++; break; } } } } free(buf); return 2; } return 3; }
int main() { SceCtrlData pad; int cancel = 0, uninstall = 0, reinstall = 0, lftv = 0, ok = 0, installed = 0, uninstalled = 0, autoExit = 0; SetupCallbacks(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_LTRIGGER) { quickinstall = 1; lftv = 1; } else if (pad.Buttons & PSP_CTRL_RTRIGGER) { quickinstall = 1; } if (fileExist(PRX_LFTVBACKUP) | fileExist(PRX_RPLYBACKUP)) uninstall = 1; sceGuInit(); sceGuStart(GU_DIRECT, list); sceGuClearColor(0xFFFFFFFF); sceGuDrawBuffer(GU_PSM_8888, (void*)0, BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH); sceGuDepthBuffer((void*)0x110000, BUF_WIDTH); sceGuOffset(2048 - (SCR_WIDTH / 2), 2048 - (SCR_HEIGHT / 2)); sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT); sceGuDepthRange(0xc350, 0x2710); sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuDisable(GU_DEPTH_TEST); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, 256, 128, 256, font); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuTexEnvColor(0x0); sceGuTexOffset(0.0f, 0.0f); sceGuTexScale(1.0f / 256.0f, 1.0f / 128.0f); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuFinish(); sceGuSync(0,0); sceGuDisplay(GU_TRUE); // Check for low battery. if ((scePowerGetBatteryLifePercent() < 25) & !scePowerIsPowerOnline()) { sceGuStart(GU_DIRECT, list); sceGuClear(GU_COLOR_BUFFER_BIT); drawStringCenter("Battery charge should be at least 25% when modifying flash!", 40 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("Connect the AC adapter to ignore this warning and continue!", 40 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter(uninstall ? "Press any button to cancel uninstallation of warPSP." : "Press any button to cancel installation of warPSP.", 50 + (10 * i), 0xFF0000FF, 8); i += 2; drawObjects(); while (!scePowerIsPowerOnline()) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) { cancel = 1; break; } } } if (!cancel) { float c = 0.0; for (c = 10.0; c <= 100.0; c++) { unsigned int col = 0xFF000000 | (unsigned int)((c / 100.0) * 255.0f) << 16 | (unsigned int)((c / 100.0) * 255.0f) << 8 | (unsigned int)((c / 100.0) * 255.0f) << 0; sceGuClearColor(col); clearScreenPrintHeader(90); if (quickinstall & (c > 50)) drawStringCenter("Quick Install Activated!", 250, 0xFF006600, 8); drawObjects(); } sceKernelDelayThread(3000000); for (c = 100.0; c >= 10.0; c--) { unsigned int col = 0xFF000000 | (unsigned int)((c / 100.0) * 255.0f) << 16 | (unsigned int)((c / 100.0) * 255.0f) << 8 | (unsigned int)((c / 100.0) * 255.0f) << 0; sceGuClearColor(col); clearScreenPrintHeader(90); drawObjects(); } } sceGuClearColor(0xFFFFFFFF); // Show disclaimer and options. if (!cancel & !quickinstall) { sceGuStart(GU_DIRECT, list); sceGuClear(GU_COLOR_BUFFER_BIT); drawStringCenter("!!! DISCLAIMER !!!", 40 + (10 * i), 0xFF0000FF, 10); i += 2; drawStringCenter("This program modifies the flash drive of your Sony PSP.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("You accept the risk when running this installation app.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("DO NOT REMOVE THE MEMORY STICK WHEN ORANGE LED FLASHES.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("DO NOT TURN OFF THE PSP SYSTEM WHEN ORANGE LED FLASHES.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("Press START to acknowledge and to continue to briefing.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("Press SELECT to decline and to abort installing warPSP.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("THE AUTHOR DOES NOT HOLD RESPONSIBILITY FOR ANY DAMAGE.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("THIS SOFTWARE IS PRESENTED WITHOUT WARRANTY/GUARANTEES.", 60 + (10 * i), 0xFF0000FF, 8); i += 4; drawObjects(); while (1) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_START) { break; } if (pad.Buttons & PSP_CTRL_SELECT) { cancel = 1; break; } } } // Check if backup file exists. if (!cancel & !quickinstall) { swapBuffers(); clearScreenPrintHeader(0); drawObjects(); clearScreenPrintHeader(0); drawStringCenter("Briefing", 50 + (10 * i), 0xFF000000, 0); i+= 2; drawStringCenter("Thanks for your interest in the warPSP Software Suite!", 50 + (10 * i), 0xFF006600, 0); i += 2; drawStringCenter("warPSP is an advanced warXing utility for the Sony PSP.", 50 + (10 * i), 0xFF000000, 8); i += 2; drawStringCenter("Please see the README.TXT file for more information.", 50 + (10 * i), 0xFF660000, 8); i += 3; drawStringCenter("Options", 50 + (10 * i), 0xFF000000, 0); i += 2; if (uninstall) { drawStringCenter("Press SQUARE to uninstall warPSP and restore backup files.", 50 + (10 * i), 0xFF000000, 8); i++; drawStringCenter("Press CIRCLE to reinstall warPSP to the last slot selected.", 50 + (10 * i), 0xFF000000, 8); i++; } else { drawStringCenter("Press SQUARE to install warPSP to the LFTV Player slot.", 50 + (10 * i), 0xFF000000, 8); i++; drawStringCenter("Press CIRCLE to install warPSP to the Remote Play slot.", 50 + (10 * i), 0xFF000000, 8); i++; } drawStringCenter(uninstall ? "Press SELECT to cancel uninstallation of warPSP and exit." : "Press SELECT to cancel installation of warPSP and exit.", 50 + (10 * i), 0xFF000099, 8); i += 2; drawObjects(); while (1) { sceCtrlReadBufferPositive(&pad, 1); if (uninstall) { if (pad.Buttons & PSP_CTRL_SQUARE) { break; } if (pad.Buttons & PSP_CTRL_CIRCLE) { uninstall = 0; reinstall = 1; if (fileExist(PRX_LFTVBACKUP)) lftv = 1; else lftv = 0; break; } } else { if (pad.Buttons & PSP_CTRL_SQUARE) { lftv = 1; break; } if (pad.Buttons & PSP_CTRL_CIRCLE) { lftv = 0; break; } } if (pad.Buttons & PSP_CTRL_SELECT) { cancel = 1; break; } } } if (!cancel) { if ((scePowerGetBatteryLifePercent() < 25) & !scePowerIsPowerOnline()) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter(" Battery is below 25%% and AC adapter is not connected!", 50 + (10 * i), 0xFF000099, 0); i += 2; cancel = 1; drawObjects(); } } if (cancel) { swapBuffers(); sceGuStart(GU_DIRECT, list); sprintf(buffer, "%sstallation cancelled!", uninstall ? "Unin" : "In"); drawStringCenter(buffer, 50 + (10 * i), 0xFF0000FF, 0); i += 2; drawObjects(); sceKernelDelayThread(1000000); } // Perform installation, uninstallation or reinstallation. if (!cancel) { scePowerLock(0); swapBuffers(); clearScreenPrintHeader(0); drawObjects(); clearScreenPrintHeader(0); drawObjects(); swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter(uninstall ? "Uninstallation" : "Installation", 50 + (10 * i), 0xFF990000, 0); i += 2; if (quickinstall) { drawStringCenter("Quick installing warPSP to the location free player slot.", 50 + (10 * i), 0xFF990000, 0); i += 2; } drawObjects(); swapBuffers(); sceGuStart(GU_DIRECT, list); if (uninstall) { if (fileExist(PRX_LFTVBACKUP)) { lftv = 1; ok = 1; } else if (fileExist(PRX_RPLYBACKUP)) { lftv = 0; ok = 1; } if (ok) { drawStringCenter("Backup prx found. Ok to uninstall!", 50 + (10 * i), 0xFF990000, 8); i++; drawStringCenter("The backup prx will be copied to the flash drive of your PSP!", 50 + (10 * i), 0xFF000000, 8); i += 2; drawObjects(); if (fileCopy(lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP, lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Backup file reinstalled successfully!", 50 + (10 * i), 0xFF006600, 8); sceIoRemove(lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP); uninstalled = 1; } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Backup file reinstallation failed!", 50 + (10 * i), 0xFF000099, 8); } i += 2; drawObjects(); if (uninstalled) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("To reinstall warPSP, rerun the Easy Installation Program.", 50 + (10 * i), 0xFF990000, 8); i += 2; drawObjects(); } } } else { if (fileExist(PRX_WARPSP_XMB)) { sceIoRemove(PRX_WARPSP_XMB); sceKernelDelayThread(1000000); } drawStringCenter("Extracting warPSP.prx to the root of the memory stick.", 50 + (10 * i), 0xFF000000, 8); i += 2; drawObjects(); sceKernelDelayThread(2000000); // Open PBP file and read contents into the buffer. int pbpFile, prxFile, pkgSize = 0, prxSize = 0; char buf[1024*1024]; pbpFile = sceIoOpen(PBP_WARPSP_EIP, PSP_O_RDONLY, 0); sceKernelDelayThread(1000000); if (pbpFile) { // Get size of entire package. pkgSize = sceIoRead(pbpFile, buf, sizeof(buf)); sceKernelDelayThread(1000000); if (pkgSize > 0) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("EBOOT.PBP loaded into memory successfully!", 50 + (10 * i), 0xFF006600, 8); i += 2; drawObjects(); // Calculate size of prx to extract (size of entire package - size of eboot.pbp). prxSize = pkgSize - pbpSize; // Open PRX file and write buffer into the contents. prxFile = sceIoOpen(PRX_WARPSP_XMB, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); sceKernelDelayThread(100000); if (prxFile) { // Write prx file from end of eboot.pbp. sceIoWrite(prxFile, buf + pbpSize, prxSize); sceKernelDelayThread(1000000); sceIoClose(prxFile); sceKernelDelayThread(1000000); swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP.prx extracted from memory successfully!", 50 + (10 * i), 0xFF006600, 8); drawObjects(); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP.prx extraction from memory failed!", 50 + (10 * i), 0xFF000099, 8); drawObjects(); } i += 2; } sceIoClose(pbpFile); sceKernelDelayThread(1000000); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("EBOOT.PBP load into memory failed!", 50 + (10 * i), 0xFF000099, 8); i += 2; drawObjects(); } buf[0] = (char)"\0"; swapBuffers(); sceGuStart(GU_DIRECT, list); if (!fileExist(PRX_WARPSP_XMB)) { drawStringCenter("warPSP.prx not found! Install cancelled!", 50 + (10 * i), 0xFF000099, 8); } else { drawStringCenter("warPSP.prx found. Ok to install!", 50 + (10 * i), 0xFF006600, 8); ok = 1; } i += 2; drawObjects(); // Create backup of original file and install warPSP. if (ok) { if (!reinstall) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("The backup file will be copied to the memory stick!", 50 + (10 * i), 0xFF990000, 8); i++; drawObjects(); if (fileCopy(lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY, lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Original prx file backed up successfully!", 50 + (10 * i), 0xFF006600, 8); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Original prx file back up failed!", 50 + (10 * i), 0xFF000099, 8); } i += 2; drawObjects(); } if (fileCopy(PRX_WARPSP_XMB, lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP^xmb installed successfully!", 50 + (10 * i), 0xFF006600, 8); sceIoRemove(PRX_WARPSP_XMB); installed = 1; } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP^xmb installation failed!", 50 + (10 * i), 0xFF000099, 8); installed = 0; } i += 2; drawObjects(); } } scePowerUnlock(0); } if (installed | uninstalled) { sceKernelDelayThread(1000000); } if (!quickinstall) { swapBuffers(); sceGuStart(GU_DIRECT, list); sprintf(buffer, "Press any button to %s! (Auto-Exit in 10s).", (installed | uninstalled) ? "restart the PSP" : "return to the xmb"); drawStringCenter(buffer, 50 + (10 * i), 0xFF000000, 8); i++; if (installed) { drawStringCenter("Happy warXing!", 50 + (10 * i), 0xFF006600, 8); i++; } else if (uninstalled) { drawStringCenter("Thank you for using warPSP", 50 + (10 * i), 0xFF990000, 8); i++; } drawObjects(); // Wait for exit. while (1) { if (autoExit >= 1000) break; sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) break; sceKernelDelayThread(10000); autoExit++; } } if (quickinstall) { sceKernelDelayThread(1000000); } swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Exiting!", 50 + (10 * i), (installed | uninstalled) ? 0xFF990000 : 0xFF0000FF, 8); drawObjects(); if (installed | uninstalled) { sceKernelExitGame(); scePower_0442D852(50000); } else { sceKernelExitGame(); } return 0; }
int LPP_UtilsSavedataInit(int type, void *data, u32 datasize, const char *cPath, const char *gamename, const char *key, const char *title, const char *subtitle, const char *detail) { lpp_UtilsSaveDataData = data; PspUtilitySavedataListSaveNewData newData; memset(&newData, 0, sizeof(newData)); memset(&lpp_UtilsSavedataParams, 0, sizeof(lpp_UtilsSavedataParams)); lpp_UtilsSavedataParams.base.size = sizeof(lpp_UtilsSavedataParams); void *icon0data = null; size_t icon0size = 0; void *pic1data = null; size_t pic1size = 0; void* snd0data = null; size_t snd0size = 0; char *titleshow = "New Save"; sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &lpp_UtilsSavedataParams.base.language); sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &lpp_UtilsSavedataParams.base.buttonSwap); lpp_UtilsSavedataParams.base.graphicsThread = 17; lpp_UtilsSavedataParams.base.accessThread = 19; lpp_UtilsSavedataParams.base.fontThread = 18; lpp_UtilsSavedataParams.base.soundThread = 16; lpp_UtilsSavedataParams.mode = type; lpp_UtilsSavedataParams.overwrite = 1; if(type == LPP_UTILS_SAVEDATA_TYPE_LISTLOAD) { lpp_UtilsSavedataParams.focus = PSP_UTILITY_SAVEDATA_FOCUS_LATEST; } else { lpp_UtilsSavedataParams.focus = PSP_UTILITY_SAVEDATA_FOCUS_FIRSTEMPTY; } strncpy(lpp_UtilsSavedataParams.key, key, 16); strncpy(lpp_UtilsSavedataParams.gameName, gamename, 9); strcpy(lpp_UtilsSavedataParams.saveName, "<>"); if(type == LPP_UTILS_SAVEDATA_TYPE_AUTOLOAD || type == LPP_UTILS_SAVEDATA_TYPE_AUTOSAVE) { strcpy(lpp_UtilsSavedataParams.saveName, lpp_UtilsSavedataSaveName); } else { lpp_UtilsSavedataParams.saveNameList = lpp_UtilsSaveNameMultiple; } strcpy(lpp_UtilsSavedataParams.fileName, "DATA.BIN"); lpp_UtilsSavedataParams.dataBuf = malloc(datasize); lpp_UtilsSavedataParams.dataBufSize = datasize; lpp_UtilsSavedataParams.dataSize = datasize; if(type == LPP_UTILS_SAVEDATA_TYPE_AUTOSAVE || type == LPP_UTILS_SAVEDATA_TYPE_LISTSAVE) { memset(lpp_UtilsSavedataParams.dataBuf, 0, datasize); strncpy(lpp_UtilsSavedataParams.dataBuf, data, datasize); strcpy(lpp_UtilsSavedataParams.sfoParam.title, title); strcpy(lpp_UtilsSavedataParams.sfoParam.savedataTitle, subtitle); strcpy(lpp_UtilsSavedataParams.sfoParam.detail, detail); lpp_UtilsSavedataParams.sfoParam.parentalLevel = 0; if(type != LPP_UTILS_SAVEDATA_TYPE_AUTOSAVE) { if(strcmp(cPath, "EBOOT.PBP") == 0 || strcmp(cPath, "EBOOT.PBP/") == 0 || strcmp(cPath, "EBOOT.PBP\\") == 0) { SceUID fd = sceIoOpen(cPath, PSP_O_RDONLY, 0777); if(fd >= 0) { EBOOT_HEADER pbpHeader; memset(&pbpHeader, 0, sizeof(pbpHeader)); sceIoRead(fd, &pbpHeader, sizeof(pbpHeader)); u32 filesize = pbpHeader.offset[2] - pbpHeader.offset[1]; if(filesize > 0) { sceIoLseek32(fd, pbpHeader.offset[1], PSP_SEEK_SET); icon0data = malloc(filesize); icon0size = filesize; sceIoRead(fd, icon0data, filesize); } filesize = pbpHeader.offset[5] - pbpHeader.offset[4]; if(filesize) { sceIoLseek32(fd, pbpHeader.offset[4], PSP_SEEK_SET); pic1data = malloc(filesize); pic1size = filesize; sceIoRead(fd, pic1data, filesize); } filesize = pbpHeader.offset[6] - pbpHeader.offset[5]; if(filesize) { sceIoLseek32(fd, pbpHeader.offset[5], PSP_SEEK_SET); snd0data = malloc(filesize); snd0size = filesize; sceIoRead(fd, snd0data, filesize); } sceIoClose(fd); } } else { char fname[512]; u8 o = cPath[strlen(cPath) - 1] == '/' || cPath[strlen(cPath) - 1] == '\\'; sprintf(fname, o ? "%sICON0.PNG" : "%s/ICON0.PNG", cPath); if(LPP_FileExists(fname)) { SceUID fd = sceIoOpen(fname, PSP_O_RDONLY, 0777); icon0size = sceIoLseek32(fd, 0, PSP_SEEK_END); sceIoLseek32(fd, 0, PSP_SEEK_SET); icon0data = malloc(icon0size); sceIoRead(fd, icon0data, icon0size); sceIoClose(fd); } sprintf(fname, o ? "%sPIC1.PNG" : "%s/PIC1.PNG", cPath); if(LPP_FileExists(fname)) { SceUID fd = sceIoOpen(fname, PSP_O_RDONLY, 0777); pic1size = sceIoLseek32(fd, 0, PSP_SEEK_END); sceIoLseek32(fd, 0, PSP_SEEK_SET); pic1data = malloc(pic1size); sceIoRead(fd, pic1data, pic1size); sceIoClose(fd); } sprintf(fname, o ? "%sSND0.AT3" : "%s/SND0.AT3", cPath); if(LPP_FileExists(fname)) { SceUID fd = sceIoOpen(fname, PSP_O_RDONLY, 0777); snd0size = sceIoLseek32(fd, 0, PSP_SEEK_END); sceIoLseek32(fd, 0, PSP_SEEK_SET); snd0data = malloc(snd0size); sceIoRead(fd, snd0data, snd0size); sceIoClose(fd); } } } lpp_UtilsSavedataParams.icon1FileData.buf = null; lpp_UtilsSavedataParams.icon1FileData.bufSize = 0; lpp_UtilsSavedataParams.icon1FileData.size = 0; lpp_UtilsSavedataParams.pic1FileData.buf = pic1data; lpp_UtilsSavedataParams.pic1FileData.bufSize = pic1size; lpp_UtilsSavedataParams.pic1FileData.size = pic1size; lpp_UtilsSavedataParams.icon0FileData.buf = icon0data; lpp_UtilsSavedataParams.icon0FileData.bufSize = icon0size; lpp_UtilsSavedataParams.icon0FileData.size = icon0size; lpp_UtilsSavedataParams.snd0FileData.buf = snd0data; lpp_UtilsSavedataParams.snd0FileData.bufSize = snd0size; lpp_UtilsSavedataParams.snd0FileData.size = snd0size; newData.title = titleshow; lpp_UtilsSavedataParams.newData = &newData; } int res = sceUtilitySavedataInitStart(&lpp_UtilsSavedataParams); if(res == 0) return 1; return(res); }
RFILE *filestream_open(const char *path, unsigned mode, ssize_t len) { int flags = 0; int mode_int = 0; #if defined(HAVE_BUFFERED_IO) const char *mode_str = NULL; #endif RFILE *stream = (RFILE*)calloc(1, sizeof(*stream)); if (!stream) return NULL; (void)mode_int; (void)flags; stream->hints = mode; #ifdef HAVE_MMAP if (stream->hints & RFILE_HINT_MMAP && (stream->hints & 0xff) == RFILE_MODE_READ) stream->hints |= RFILE_HINT_UNBUFFERED; else #endif stream->hints &= ~RFILE_HINT_MMAP; switch (mode & 0xff) { case RFILE_MODE_READ: #if defined(VITA) || defined(PSP) mode_int = 0777; flags = PSP_O_RDONLY; #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) mode_str = "rb"; #endif /* No "else" here */ flags = O_RDONLY; #endif break; case RFILE_MODE_WRITE: #if defined(VITA) || defined(PSP) mode_int = 0777; flags = PSP_O_CREAT | PSP_O_WRONLY | PSP_O_TRUNC; #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) mode_str = "wb"; #endif else { flags = O_WRONLY | O_CREAT | O_TRUNC; #ifndef _WIN32 flags |= S_IRUSR | S_IWUSR; #endif } #endif break; case RFILE_MODE_READ_WRITE: #if defined(VITA) || defined(PSP) mode_int = 0777; flags = PSP_O_RDWR; #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) mode_str = "w+"; #endif else { flags = O_RDWR; #ifdef _WIN32 flags |= O_BINARY; #endif } #endif break; } #if defined(VITA) || defined(PSP) stream->fd = sceIoOpen(path, flags, mode_int); #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) { stream->fp = fopen(path, mode_str); if (!stream->fp) goto error; } else #endif { stream->fd = open(path, flags); if (stream->fd == -1) goto error; #ifdef HAVE_MMAP if (stream->hints & RFILE_HINT_MMAP) { stream->mappos = 0; stream->mapped = NULL; stream->mapsize = filestream_seek(stream, 0, SEEK_END); if (stream->mapsize == (uint64_t)-1) goto error; filestream_rewind(stream); stream->mapped = (uint8_t*)mmap((void*)0, stream->mapsize, PROT_READ, MAP_SHARED, stream->fd, 0); if (stream->mapped == MAP_FAILED) stream->hints &= ~RFILE_HINT_MMAP; } #endif } #endif #if defined(VITA) || defined(PSP) if (stream->fd == -1) goto error; #endif return stream; error: filestream_close(stream); return NULL; }
int main(int argc, char *argv[]) { int fd = -1; CURL *curl = NULL; double speed = 0.0; double size = 0.0; printf("WebGet v0.1 (uses the CURL library)\n"); if(argc < 3) { printf("Usage: webget.prx URL output\n"); return 1; } do { fd = sceIoOpen(argv[2], PSP_O_WRONLY | PSP_O_TRUNC | PSP_O_CREAT, 0777); if(fd < 0) { printf("Couldn't open file %s, 0x%08X\n", argv[2], fd); break; } curl = curl_easy_init(); if(curl == NULL) { printf("Couldn't initialise curl library\n"); break; } if(curl_easy_setopt(curl, CURLOPT_URL, argv[1]) != CURLE_OK) { printf("Could not set curl URL\n"); break; } if(curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &fd) != CURLE_OK) { printf("Could not set write file pointer\n"); break; } if(curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback) != CURLE_OK) { printf("Could not set write callback\n"); break; } if(curl_easy_perform(curl) != CURLE_OK) { printf("Could not read data from URL\n"); break; } if(g_writebufpos > 0) { sceIoWrite(fd, g_writebuf, g_writebufpos); } if(curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &size) != CURLE_OK) { printf("Couldn't get the data size\n"); } if(curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed) != CURLE_OK) { printf("Couldn't get the download speed\n"); } printf("Download %d bytes, %fKb/s\n", (int) size, speed / 1024.0); } while(0); if(curl) { curl_easy_cleanup(curl); } if(fd >= 0) { sceIoClose(fd); } return 0; }
void lprintf(const char *fmt, ...) { va_list vl; #ifdef LPRINTF_STDIO va_start(vl, fmt); vprintf(fmt, vl); va_end(vl); #else static SceUID logfd = -1; static int msg_count = 0; char buff[256]; log_entry *le, *le1; if (logfd == -2) return; // disabled va_start(vl, fmt); vsnprintf(buff, sizeof(buff), fmt, vl); va_end(vl); // note: this is still unsafe code if (main_thread_id != sceKernelGetThreadId()) { le = malloc(sizeof(*le)); if (le == NULL) return; le->next = NULL; strcpy(le->buff, buff); if (le_root == NULL) le_root = le; else { for (le1 = le_root; le1->next != NULL; le1 = le1->next); le1->next = le; } return; } logfd = sceIoOpen(LOG_FILE, PSP_O_WRONLY|PSP_O_APPEND, 0777); if (logfd < 0) { if (msg_count == 0) logfd = -2; return; } if (le_root != NULL) { le1 = le_root; le_root = NULL; sceKernelDelayThread(1000); while (le1 != NULL) { le = le1; le1 = le->next; sceIoWrite(logfd, le->buff, strlen(le->buff)); free(le); msg_count++; } } sceIoWrite(logfd, buff, strlen(buff)); msg_count++; // make sure it gets flushed sceIoClose(logfd); logfd = -1; #endif }
static int neogeo_init(void) { SceUID fd; char path[MAX_PATH]; #ifdef ADHOC if (!adhoc_enable) #endif { sprintf(path, "%smemcard/%s.bin", launchDir, game_name); if ((fd = sceIoOpen(path, PSP_O_RDONLY, 0777)) >= 0) { sceIoRead(fd, neogeo_memcard, 0x800); sceIoClose(fd); } sprintf(path, "%snvram/%s.nv", launchDir, game_name); if ((fd = sceIoOpen(path, PSP_O_RDONLY, 0777)) >= 0) { sceIoRead(fd, neogeo_sram16, 0x2000); sceIoClose(fd); swab(neogeo_sram16, neogeo_sram16, 0x2000); } } neogeo_driver_init(); neogeo_video_init(); msg_printf(TEXT(DONE2)); msg_screen_clear(); video_clear_screen(); #ifdef ADHOC if (adhoc_enable) { sprintf(adhoc_matching, "%s_%s_%s", PBPNAME_STR, game_name, bios[neogeo_bios]); if (adhocInit(adhoc_matching) == 0) { if ((adhoc_server = adhocSelect()) >= 0) { video_clear_screen(); if (adhoc_server) { option_controller = INPUT_PLAYER1; return adhoc_send_state(NULL); } else { option_controller = INPUT_PLAYER2; return adhoc_recv_state(NULL); } } } Loop = LOOP_BROWSER; return 0; } #endif return 1; }
extern bool extract_archive_file(const char *archname, const char *archpath, const char *dest, t_copy_cb cb, t_copy_overwritecb ocb, void *data) { t_fs_filetype ft; SceUID fd; bool result = false; buffer *archdata = NULL; int buffer_cache; char *ptr; if (archname == NULL || archpath == NULL || dest == NULL) return false; ft = get_archive_type(archname); if (ft == fs_filetype_unknown) return false; if (ocb != NULL) { SceUID fd; fd = sceIoOpen(dest, PSP_O_RDONLY, 0777); if (fd >= 0) { if (!ocb(dest, data)) { sceIoClose(fd); return false; } sceIoClose(fd); } } dbg_printf(d, "extract_archive_file: %s %s %s, ft = %d", archname, archpath, dest, ft); fd = sceIoOpen(dest, PSP_O_CREAT | PSP_O_RDWR, 0777); if (fd < 0) return false; extract_archive_file_into_buffer(&archdata, archname, archpath, ft); if (archdata == NULL || archdata->ptr == NULL) goto exit; buffer_cache = archdata->used >= 1024 * 1024 ? 1024 * 1024 : archdata->used; ptr = archdata->ptr; while (buffer_cache > 0) { int bytes = sceIoWrite(fd, ptr, buffer_cache); if (bytes < 0) { goto exit; } buffer_cache = archdata->used - bytes >= 1024 * 1024 ? 1024 * 1024 : archdata->used - bytes; ptr += bytes; } result = true; exit: sceIoClose(fd); if (archdata != NULL) { buffer_free(archdata); } return result; }
int parse_umd_chapters(const char *umdfile, p_umd_chapter * pchapter) { //int ret = -1; SceUID fd = -1; SceIoStat sta; buffer *pRaw = NULL; buffer *pzbuf = NULL; do { size_t stHeadSize = sizeof(struct UMDHeaderData); size_t stHeadExSize = sizeof(struct UMDHeaderDataEx); char *p; int Reserve; struct UMDHeaderData *pHead; struct UMDHeaderDataEx *pHeadEx; u_int i; size_t stlen; if (!umdfile || !pchapter || !(*pchapter)) break; if (sceIoGetstat(umdfile, &sta) < 0) { return -1; } if ((fd = sceIoOpen(umdfile, PSP_O_RDONLY, 0777)) < 0) { return -2; } pRaw = buffer_init(); if (pRaw == NULL) break; buffer_prepare_copy(pRaw, (10240 > sta.st_size) ? sta.st_size : 10240); pRaw->used = pRaw->size; if (0 > read_umd_buf(fd, &pRaw)) { //dbg_printf(d, "%s not start with 0xde9a9b89,that umd must be corrupted!",__func__); break; } p = pRaw->ptr; Reserve = *(int *) p; if (Reserve != (int) 0xde9a9b89 || *(p + sizeof(int)) != '#') { //dbg_printf(d, "%s not start with 0xde9a9b89,or not start with '#',that umd must be corrupted!",__func__); buffer_free(pRaw); break; } (*pchapter)->filesize = sta.st_size; buf_offset = sizeof(int); umdfile_offset = buf_offset; umdfile_remain = sta.st_size - buf_offset; pHead = NULL; pHeadEx = NULL; ////dbg_printf(d,"%s start to parse\n",__func__); while (umdfile_remain > 0) { if (0 > get_chunk_buf(fd, &pRaw, &p, stHeadSize)) break; pHead = (struct UMDHeaderData *) p; if (pHead->Mark != '#' || pHead->Length < stHeadSize) { //dbg_printf(d, "%s head corrupted,flag:%c,length:%d!",__func__,pHead->Flag,pHead->Length); break; } if (pHead->hdType == 0x0e || pHead->hdType == 0x0f) { size_t stChapterCount; bool bchapterless; //no chapters listed struct t_chapter *pchap; /*if((14 == hdType && 2 != (*pchapter)->umd_mode) || (15 == hdType && 3 != (*pchapter)->umd_mode) || *(*pSe) != '$') { ////dbg_printf(d,"%s umd mode:%d not fit for hdType %d or not start from $\n",__func__,(*pchapter)->umd_mode,hdType); break; } */ if (0 > get_chunk_buf(fd, &pRaw, &p, pHead->Length - stHeadSize)) break; memcpy(&(*pchapter)->umd_mode, p, 1); //cout << "umd mode:" << (*pchapter)->umd_mode << endl; if (0 > get_chunk_buf(fd, &pRaw, &p, stHeadExSize)) break; stChapterCount = (*pchapter)->chapter_count; bchapterless = false; //no chapters listed pchap = (*pchapter)->pchapters; if (1 > stChapterCount) { bchapterless = true; stChapterCount = 16; (*pchapter)->pchapters = (struct t_chapter *) calloc(stChapterCount, sizeof(struct t_chapter)); if (!(*pchapter)->pchapters) break; pchap = (*pchapter)->pchapters; for (i = 0; i < stChapterCount; i++) { if (!(pchap[i].name = buffer_init())) return -4; pchap[i].length = 1; } } else if (!(*pchapter)->pchapters) break; if (*p == '$') (*pchapter)->content_pos = umdfile_offset - 9; i = 0; while (*p == '$') { if (bchapterless) { if (i >= stChapterCount) { stChapterCount += 16; (*pchapter)->pchapters = (struct t_chapter *) realloc((*pchapter)->pchapters, stChapterCount * sizeof(struct t_chapter)); if (!(*pchapter)->pchapters) break; pchap = (*pchapter)->pchapters; } if (!(pchap[i].name = buffer_init())) break; buffer_prepare_copy(pchap[i].name, 7); memcpy(pchap[i].name->ptr, "i\0m\0g\0", 6); pchap[i].name->ptr[6] = '\0'; pchap[i].name->used = 7; } else if (i >= stChapterCount) { //dbg_printf(d,"%s get img chapters %d more than list %d",__func__,i,stChapterCount); buffer_free(pRaw); sceIoClose(fd); return i + 1; } pHeadEx = (struct UMDHeaderDataEx *) p; stlen = pHeadEx->Length; if (stlen < 9) { ////dbg_printf(d,"%s zipLength %d < 9",__func__,ZipLength); break; } printf("img:%d pos:%d\n", i, umdfile_offset - 9); pchap[i++].chunk_pos = umdfile_offset - 9; stlen -= 9; if (0 > get_chunk_buf(fd, &pRaw, &p, stlen)) break; //cout << "img:" << i++ << " len:" << stlen << endl; if (*(pRaw->ptr + buf_offset) == '#') { if (0 > get_chunk_buf(fd, &pRaw, &p, stHeadSize)) break; pHead = (struct UMDHeaderData *) p; if (pHead->hdType == 10) { if (0 > get_offset_chunk_buf(fd, &pRaw, &p, pHead->Length - stHeadSize, stHeadExSize)) break; //cout << "skip chunk" << endl; } else if (pHead->hdType == 0x81) { if (bchapterless && i < stChapterCount) { stChapterCount = i; (*pchapter)->pchapters = (struct t_chapter *) realloc((*pchapter)->pchapters, stChapterCount * sizeof(struct t_chapter)); if (!(*pchapter)->pchapters) break; (*pchapter)->chapter_count = i; } //cout << "parse done" << endl; buffer_free(pRaw); sceIoClose(fd); return i + 1; } } else { if (0 > get_chunk_buf(fd, &pRaw, &p, stHeadExSize)) break; } } buffer_free(pRaw); sceIoClose(fd); return -1; } else if (pHead->hdType == 0x83) { size_t stChapterCount; if (0 > get_offset_chunk_buf(fd, &pRaw, &p, pHead->Length - stHeadSize, stHeadExSize)) break; pHeadEx = (struct UMDHeaderDataEx *) p; if (pHeadEx->Length < stHeadExSize) break; stChapterCount = (pHeadEx->Length - stHeadExSize) / 4; if (0 < stChapterCount) { struct t_chapter *pchap; if (0 > get_chunk_buf(fd, &pRaw, &p, pHeadEx->Length - stHeadExSize)) break; (*pchapter)->chapter_count = stChapterCount; (*pchapter)->pchapters = (struct t_chapter *) calloc(stChapterCount, sizeof(struct t_chapter)); if (!(*pchapter)->pchapters) break; pchap = (*pchapter)->pchapters; for (i = 0; i < stChapterCount; i++) { if (!(pchap[i].name = buffer_init())) return -4; memcpy(&pchap[i].length, p, sizeof(u_int)); p += 4; } } else continue; } else if (pHead->hdType == 0x84) { struct t_chapter *pchap; size_t stChapterCount; size_t stcontent_length = 0; bool bok = true; size_t stoutlen = 0; size_t stUnzipSize = 0; if (0 > get_offset_chunk_buf(fd, &pRaw, &p, pHead->Length - stHeadSize, stHeadExSize)) break; pHeadEx = (struct UMDHeaderDataEx *) p; if (pHeadEx->Length < stHeadExSize) break; if (0 > get_chunk_buf(fd, &pRaw, &p, pHeadEx->Length - stHeadExSize)) break; pchap = (*pchapter)->pchapters; stChapterCount = (*pchapter)->chapter_count; if (0 < stChapterCount) { for (i = 0; i < stChapterCount; i++) { stlen = *(u8 *) p; p += 1; buffer_copy_string_len(pchap[i].name, p, stlen); ////dbg_printf(d,"%dth chapter name:%s\n",i,pchap[i].name->ptr); p += stlen; } } if (0x01 != (*pchapter)->umd_type) continue; if (0 > get_chunk_buf(fd, &pRaw, &p, stHeadExSize)) break; i = 0; if (*p == '$') (*pchapter)->content_pos = umdfile_offset - 9; pchap = (*pchapter)->pchapters; pzbuf = buffer_init(); if (!pzbuf) break; while (*p == '$') { bok = false; pHeadEx = (struct UMDHeaderDataEx *) p; stlen = pHeadEx->Length; if (stlen < 9) { ////dbg_printf(d,"%s zipLength %d < 9",__func__,ZipLength); break; } //pchap[i++].pos = umdfile_offset - 9; stlen -= 9; stoutlen = stlen * 2; buffer_prepare_copy(pzbuf, stoutlen); if (0 > get_chunk_buf(fd, &pRaw, &p, stlen)) break; stUnzipSize = umd_inflate((Byte *) p, (Byte *) pzbuf->ptr, stlen, stoutlen); if (stUnzipSize < 0 || stUnzipSize > stoutlen) { printf("stUnzipSize %d not in limit size:%d", stUnzipSize, stoutlen); break; } //stcontent_length += stlen; //for(;i < stChapterCount;i++) while (i < stChapterCount && pchap[i].length <= stcontent_length + stUnzipSize) { pchap[i].chunk_pos = umdfile_offset - 9 - stlen; pchap[i].chunk_offset = pchap[i].length - stcontent_length; if (i > 0) pchap[i - 1].length = pchap[i].length - pchap[i - 1].length; printf("%dth pos:%d offset:%d,cur len:%d\n", i, pchap[i].chunk_pos, pchap[i].length, stcontent_length); ++i; } stcontent_length += stUnzipSize; if (i >= stChapterCount) { pchap[stChapterCount - 1].length = (*pchapter)->filesize - pchap[stChapterCount - 1].length; printf("x total %d pos fileoffset:%d\n", i, umdfile_offset); if (pzbuf) buffer_free(pzbuf); buffer_free(pRaw); sceIoClose(fd); return stChapterCount + 1; } if (*(pRaw->ptr + buf_offset) == '#') { bok = true; while (*(pRaw->ptr + buf_offset) == '#') { if (0 > get_chunk_buf(fd, &pRaw, &p, stHeadSize)) { bok = false; break; } pHead = (struct UMDHeaderData *) p; if (pHead->hdType == 0xf1 || pHead->hdType == 10) { if (*(pRaw->ptr + buf_offset + pHead->Length - stHeadSize) == '#') { if (0 > get_chunk_buf(fd, &pRaw, &p, pHead->Length - stHeadSize)) { bok = false; break; } } else { if (0 > get_offset_chunk_buf(fd, &pRaw, &p, pHead->Length - stHeadSize, stHeadExSize)) bok = false; break; } } else if (pHead->hdType == 0x81) { printf("total %d pos fileoffset:%d\n", i, umdfile_offset); if (pzbuf) buffer_free(pzbuf); buffer_free(pRaw); sceIoClose(fd); return stChapterCount + 1; } } if (!bok) break; } else { if (0 > get_chunk_buf(fd, &pRaw, &p, stHeadExSize)) break; } } } else { if (0 > get_chunk_buf(fd, &pRaw, &p, pHead->Length - stHeadSize)) break; if (0x01 == pHead->hdType) memcpy(&(*pchapter)->umd_type, p, 1); else if (0x0b == pHead->hdType) memcpy(&(*pchapter)->filesize, p, 4); } if (*p == '$') { //stbuf_offset += stHeadSize; //pRaw->used = 4; if (0 > get_chunk_buf(fd, &pRaw, &p, 4)) break; //pHeadEx->Length = *(u_int*)p; //memcpy((char*)&pHeadEx->Length ,p,sizeof(u_int)); memcpy((char *) &i, p, sizeof(u_int)); if (9 > i || 0 > get_chunk_buf(fd, &pRaw, &p, i - stHeadExSize)) break; } } } while (false); if (pRaw) buffer_free(pRaw); if (fd > 0) sceIoClose(fd); return 1; }
static pgeObjMtl *pgeObjLoadMaterial(const char *matname) { int fd = sceIoOpen(matname, PSP_O_RDONLY, 0777); if(fd < 0) return NULL; long filesize; filesize = sceIoLseek32(fd, 0, PSP_SEEK_END); sceIoLseek32(fd, 0, PSP_SEEK_SET); unsigned char *data = pgeMalloc(filesize); if(!data) return NULL; sceIoRead(fd, data, filesize); sceIoClose(fd); unsigned char *currentpos, *endpos; unsigned int position = 0; unsigned int numnewmtl = 0; unsigned int newmtlpos = 0, kapos = 0, kdpos = 0, kspos = 0, nspos = 0; char readbuffer[512]; currentpos = data; endpos = currentpos + filesize; while(currentpos != endpos) { position = 0; while((isdeadspace(*currentpos)) && (currentpos != endpos)) currentpos++; while((!iseol(*currentpos)) && (currentpos != endpos) && (position < 512)) { readbuffer[position++] = *currentpos; currentpos++; } readbuffer[position] = 0; if(strequal(readbuffer, "newmtl", &readbuffer[position], 6)) numnewmtl++; } // Allocate what we need pgeObjMtl *mtl = pgeMalloc(sizeof(pgeObjMtl)); if(!mtl) { pgeFree(data); return NULL; } mtl->materials = (pgeObjMtlEntry *)pgeMalloc(sizeof(pgeObjMtlEntry) * numnewmtl); if(!mtl->materials) { pgeFree(mtl); pgeFree(data); return NULL; } mtl->nummaterials = numnewmtl; // Read back through and populate currentpos = data; char namebuffer[128]; while(currentpos != endpos) { position = 0; while((isdeadspace(*currentpos)) && (currentpos != endpos)) currentpos++; while((!iseol(*currentpos)) && (currentpos != endpos) && (position < 512)) { readbuffer[position++] = *currentpos; currentpos++; } readbuffer[position] = 0; if(strequal(readbuffer, "newmtl", &readbuffer[position], 6)) { sscanf(readbuffer, "newmtl %s", namebuffer); mtl->materials[newmtlpos].name = pgeMalloc(strlen(namebuffer) + 1); if(!mtl->materials[newmtlpos].name) { pgeFree(mtl->materials); pgeFree(mtl); pgeFree(data); return NULL; } strcpy(mtl->materials[newmtlpos].name, namebuffer); newmtlpos++; } else if(strequal(readbuffer, "Ka", &readbuffer[position], 2)) { sscanf(readbuffer, "Ka %f %f %f", &mtl->materials[kapos].ambient[0], &mtl->materials[kapos].ambient[1], &mtl->materials[kapos].ambient[2]); kapos++; } else if(strequal(readbuffer, "Kd", &readbuffer[position], 2)) { sscanf(readbuffer, "Kd %f %f %f", &mtl->materials[kdpos].diffuse[0], &mtl->materials[kdpos].diffuse[1], &mtl->materials[kdpos].diffuse[2]); kdpos++; } else if(strequal(readbuffer, "Ks", &readbuffer[position], 2)) { sscanf(readbuffer, "Ks %f %f %f", &mtl->materials[kspos].specular[0], &mtl->materials[kspos].specular[1], &mtl->materials[kspos].specular[2]); kspos++; } else if(strequal(readbuffer, "Ns", &readbuffer[position], 2)) { sscanf(readbuffer, "Ns %f", &mtl->materials[nspos].shinyness); nspos++; } } return mtl; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Private functions: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Decode thread: int decodeThread(SceSize args, void *argp){ int res; unsigned char MP3ME_header_buf[4]; int MP3ME_header; int version; int bitrate; int padding; int frame_size; int size; int total_size; int offset = 0; sceAudiocodecReleaseEDRAM(MP3ME_codec_buffer); //Fix: ReleaseEDRAM at the end is not enough to play another mp3. MP3ME_threadActive = 1; OutputBuffer_flip = 0; OutputPtrME = OutputBuffer[0]; sceIoChdir(audioCurrentDir); MP3ME_handle = sceIoOpen(MP3ME_fileName, PSP_O_RDONLY, 0777); if (MP3ME_handle < 0) MP3ME_threadActive = 0; //now search for the first sync byte, tells us where the mp3 stream starts total_size = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_END); size = total_size; sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_SET); data_start = ID3v2TagSize(MP3ME_fileName); sceIoLseek32(MP3ME_handle, data_start, PSP_SEEK_SET); data_start = SeekNextFrameMP3(MP3ME_handle); if (data_start < 0) MP3ME_threadActive = 0; size -= data_start; memset(MP3ME_codec_buffer, 0, sizeof(MP3ME_codec_buffer)); memset(MP3ME_input_buffer, 0, sizeof(MP3ME_input_buffer)); memset(MP3ME_output_buffer, 0, sizeof(MP3ME_output_buffer)); if ( sceAudiocodecCheckNeedMem(MP3ME_codec_buffer, 0x1002) < 0 ) MP3ME_threadActive = 0; if ( sceAudiocodecGetEDRAM(MP3ME_codec_buffer, 0x1002) < 0 ) MP3ME_threadActive = 0; getEDRAM = 1; if ( sceAudiocodecInit(MP3ME_codec_buffer, 0x1002) < 0 ) MP3ME_threadActive = 0; MP3ME_eof = 0; MP3ME_info.framesDecoded = 0; while (MP3ME_threadActive){ while( !MP3ME_eof && MP3ME_isPlaying ) { MP3ME_filePos = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_CUR); if ( sceIoRead( MP3ME_handle, MP3ME_header_buf, 4 ) != 4 ){ MP3ME_isPlaying = 0; MP3ME_threadActive = 0; continue; } MP3ME_header = MP3ME_header_buf[0]; MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[1]; MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[2]; MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[3]; bitrate = (MP3ME_header & 0xf000) >> 12; padding = (MP3ME_header & 0x200) >> 9; version = (MP3ME_header & 0x180000) >> 19; samplerate = samplerates[version][ (MP3ME_header & 0xC00) >> 10 ]; if ((bitrate > 14) || (version == 1) || (samplerate == 0) || (bitrate == 0))//invalid frame, look for the next one { data_start = SeekNextFrameMP3(MP3ME_handle); if(data_start < 0) { MP3ME_eof = 1; continue; } size -= (data_start - offset); offset = data_start; continue; } if (version == 3) //mpeg-1 { sample_per_frame = 1152; frame_size = 144000*bitrates[bitrate]/samplerate + padding; MP3ME_info.instantBitrate = bitrates[bitrate] * 1000; }else{ sample_per_frame = 576; frame_size = 72000*bitrates_v2[bitrate]/samplerate + padding; MP3ME_info.instantBitrate = bitrates_v2[bitrate] * 1000; } sceIoLseek32(MP3ME_handle, data_start, PSP_SEEK_SET); //seek back if (MP3ME_newFilePos >= 0) { if (!MP3ME_newFilePos) MP3ME_newFilePos = ID3v2TagSize(MP3ME_fileName); long old_start = data_start; if (sceIoLseek32(MP3ME_handle, MP3ME_newFilePos, PSP_SEEK_SET) != old_start){ data_start = SeekNextFrameMP3(MP3ME_handle); if(data_start < 0){ MP3ME_eof = 1; } MP3ME_playingTime = (float)data_start / (float)frame_size / (float)samplerate / 1000.0f; offset = data_start; size = total_size - data_start; } MP3ME_newFilePos = -1; continue; } size -= frame_size; if ( size <= 0) { MP3ME_eof = 1; continue; } //since we check for eof above, this can only happen when the file // handle has been invalidated by syspend/resume/usb if ( sceIoRead( MP3ME_handle, MP3ME_input_buffer, frame_size ) != frame_size ){ //Resume from suspend: if ( MP3ME_handle >= 0 ){ sceIoClose(MP3ME_handle); MP3ME_handle = -1; } MP3ME_handle = sceIoOpen(MP3ME_fileName, PSP_O_RDONLY, 0777); if (MP3ME_handle < 0){ MP3ME_isPlaying = 0; MP3ME_threadActive = 0; continue; } size = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_END); sceIoLseek32(MP3ME_handle, offset, PSP_SEEK_SET); data_start = offset; continue; } data_start += frame_size; offset = data_start; MP3ME_codec_buffer[6] = (unsigned long)MP3ME_input_buffer; MP3ME_codec_buffer[8] = (unsigned long)MP3ME_output_buffer; MP3ME_codec_buffer[7] = MP3ME_codec_buffer[10] = frame_size; MP3ME_codec_buffer[9] = sample_per_frame * 4; res = sceAudiocodecDecode(MP3ME_codec_buffer, 0x1002); if ( res < 0 ) { //instead of quitting see if the next frame can be decoded //helps play files with an invalid frame //we must look for a valid frame, the offset above may be wrong data_start = SeekNextFrameMP3(MP3ME_handle); if(data_start < 0) { MP3ME_eof = 1; continue; } size -= (data_start - offset); offset = data_start; continue; } MP3ME_playingTime += (float)sample_per_frame/(float)samplerate; MP3ME_info.framesDecoded++; //Output: memcpy( OutputPtrME, MP3ME_output_buffer, sample_per_frame*4); OutputPtrME += (sample_per_frame * 4); if( OutputPtrME + (sample_per_frame * 4) > &OutputBuffer[OutputBuffer_flip][OUTPUT_BUFFER_SIZE]) { //Volume Boost: if (MP3ME_volume_boost){ int i; for (i=0; i<OUTPUT_BUFFER_SIZE; i++){ OutputBuffer[OutputBuffer_flip][i] = volume_boost(&OutputBuffer[OutputBuffer_flip][i], &MP3ME_volume_boost); } } audioOutput(MP3ME_volume, OutputBuffer[OutputBuffer_flip]); OutputBuffer_flip ^= 1; OutputPtrME = OutputBuffer[OutputBuffer_flip]; //Check for playing speed: if (MP3ME_playingSpeed){ long old_start = data_start; if (sceIoLseek32(MP3ME_handle, frame_size * MP3ME_playingSpeed, PSP_SEEK_CUR) != old_start){ data_start = SeekNextFrameMP3(MP3ME_handle); if(data_start < 0){ MP3ME_eof = 1; continue; } float framesSkipped = (float)abs(old_start - data_start) / (float)frame_size; if (MP3ME_playingSpeed > 0) MP3ME_playingTime += framesSkipped * (float)sample_per_frame/(float)samplerate; else MP3ME_playingTime -= framesSkipped * (float)sample_per_frame/(float)samplerate; offset = data_start; size = total_size - data_start; }else MP3ME_setPlayingSpeed(0); } } } sceKernelDelayThread(10000); } if (getEDRAM) sceAudiocodecReleaseEDRAM(MP3ME_codec_buffer); if ( MP3ME_handle >= 0){ sceIoClose(MP3ME_handle); MP3ME_handle = -1; } sceKernelExitThread(0); return 0; }
RFILE *filestream_open(const char *path, unsigned mode, ssize_t len) { int flags = 0; int mode_int = 0; #if defined(HAVE_BUFFERED_IO) const char *mode_str = NULL; #endif RFILE *stream = (RFILE*)calloc(1, sizeof(*stream)); if (!stream) return NULL; (void)mode_int; (void)flags; stream->hints = mode; #ifdef HAVE_MMAP if (stream->hints & RFILE_HINT_MMAP && (stream->hints & 0xff) == RFILE_MODE_READ) stream->hints |= RFILE_HINT_UNBUFFERED; else #endif stream->hints &= ~RFILE_HINT_MMAP; switch (mode & 0xff) { case RFILE_MODE_READ_TEXT: #if defined(PSP) mode_int = 0666; flags = PSP_O_RDONLY; #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) mode_str = MODE_STR_READ; #endif /* No "else" here */ flags = O_RDONLY; #endif break; case RFILE_MODE_READ: #if defined(PSP) mode_int = 0666; flags = PSP_O_RDONLY; #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) mode_str = MODE_STR_READ_UNBUF; #endif /* No "else" here */ flags = O_RDONLY; #endif break; case RFILE_MODE_WRITE: #if defined(PSP) mode_int = 0666; flags = PSP_O_CREAT | PSP_O_WRONLY | PSP_O_TRUNC; #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) mode_str = MODE_STR_WRITE_UNBUF; #endif else { flags = O_WRONLY | O_CREAT | O_TRUNC; #ifndef _WIN32 flags |= S_IRUSR | S_IWUSR; #endif } #endif break; case RFILE_MODE_READ_WRITE: #if defined(PSP) mode_int = 0666; flags = PSP_O_RDWR; #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) mode_str = MODE_STR_WRITE_PLUS; #endif else { flags = O_RDWR; #ifdef _WIN32 flags |= O_BINARY; #endif } #endif break; } #if defined(PSP) stream->fd = sceIoOpen(path, flags, mode_int); #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0 && mode_str) { stream->fp = fopen(path, mode_str); if (!stream->fp) goto error; } else #endif { /* FIXME: HAVE_BUFFERED_IO is always 1, but if it is ever changed, open() needs to be changed to _wopen() for WIndows. */ stream->fd = open(path, flags, mode_int); if (stream->fd == -1) goto error; #ifdef HAVE_MMAP if (stream->hints & RFILE_HINT_MMAP) { stream->mappos = 0; stream->mapped = NULL; stream->mapsize = filestream_seek(stream, 0, SEEK_END); if (stream->mapsize == (uint64_t)-1) goto error; filestream_rewind(stream); stream->mapped = (uint8_t*)mmap((void*)0, stream->mapsize, PROT_READ, MAP_SHARED, stream->fd, 0); if (stream->mapped == MAP_FAILED) stream->hints &= ~RFILE_HINT_MMAP; } #endif } #endif #if defined(PSP) if (stream->fd == -1) goto error; #endif { const char *ld = (const char*)strrchr(path, '.'); stream->ext = strdup(ld ? ld + 1 : ""); } filestream_set_size(stream); return stream; error: filestream_close(stream); return NULL; }
int main_thread(SceSize args, void *argp) { sceKernelDelayThread(3000000); u32 keycombination; SceCtrlData pad; u32 oldButtons = 0; int extra = 0; keycombination = PSP_CTRL_RTRIGGER; //Button to start interpreter (Basic) u32 keycombination2 = PSP_CTRL_RTRIGGER + PSP_CTRL_LTRIGGER; // Button to start interpreter (Extra PSP Go) while(1){ oldButtons = pad.Buttons; if (go==0){ sceCtrlPeekBufferPositive(&pad, 1); if(oldButtons != pad.Buttons) { if(pad.Buttons & keycombination2) { pauseGame(thid1); go=1; extra=1; pspDebugScreenInit(); pspDebugScreenClear(); oldButtons = pad.Buttons; }else if(pad.Buttons & keycombination) { pauseGame(thid1); go=1; pspDebugScreenInit(); pspDebugScreenClear(); oldButtons = pad.Buttons; } } } if (go ==1){ pspDebugScreenSetXY(0,0); pspDebugScreenSetTextColor(0xffffff); int go2=1; SceUID id; if (((kuKernelGetModel() + 1) == 4) || ((kuKernelGetModel() + 1) == 5)){ if (extra==1){ id = sceIoDopen("ms0:/seplugins/script"); //PSP Go MS Support }else{ id = sceIoDopen("ef0:/seplugins/script"); //PSP Go Internal HD Support } }else{ id = sceIoDopen("ms0:/seplugins/script"); } SceIoDirent entry; int script_files = -2; memset(&entry, 0, sizeof(SceIoDirent)); while (sceIoDread(id, &entry) > 0) { script_files = script_files+1; memset(&entry, 0, sizeof(SceIoDirent)); } sceIoDclose(id); char script[256]; if (((kuKernelGetModel() + 1) == 4) || ((kuKernelGetModel() + 1) == 5)){ if (extra==1){ strcpy(script,"ms0:/seplugins/script/index.lua"); //PSP Go MS Support }else{ strcpy(script,"ef0:/seplugins/script/index.lua"); //PSP Go Internal HD Support } }else{ strcpy(script,"ms0:/seplugins/script/index.lua"); } while(go2==1) { const char *errMsg; if (script_files>1){ errMsg = runScript(extralibs, true); }else{ SceUID fp = sceIoOpen(script, PSP_O_RDONLY,0777); int size = sceIoLseek(fp, 0, SEEK_END); sceIoLseek(fp, 0, SEEK_SET); unsigned char *buffer; buffer = malloc((size+1) * sizeof (char)); sceIoRead(fp, buffer, size); buffer[size]=0; sceIoClose(fp); errMsg = runScript(buffer, true); free(buffer); } // System.restart sourcecode if (strstr(errMsg, "lpp_restart")){ go2=0; // End System.restart sources // Temp replacing for loadfile/dofile functions: System.protodofile }else if (strstr(errMsg, "lpp_open")){ char dum1[20], dum2[20], dum3[20]; char script_path2[256]; sscanf( errMsg, "%s %s %s %s", dum1, dum2, dum3, script_path2 ); strcpy(script,script_path2); script_files=1; // End System.protodofile sources }else if (strstr(errMsg, "resumeThread")){ go=0; go2=0; }else{ if (errMsg != NULL); { pspDebugScreenClear(); pspDebugScreenSetTextColor(0xffffff); debugOutput("\nError: %s\n", errMsg); } debugOutput("\nPress start to restart\nPress select to resume thread\n"); SceCtrlData pad; int restore = 0; while(restore==0){ sceCtrlPeekBufferPositive(&pad, 1); if (pad.Buttons&PSP_CTRL_START){ restore=1; go2=0; } if (pad.Buttons&PSP_CTRL_SELECT){ resumeGame(thid1); restore=1; go=0; go2=0; } } } } } sceDisplayWaitVblankStart(); } sceKernelSleepThread(); return 0; }
int main(int argc, char *argv[]) { SceCtrlData pad; int oldButtons = 0; #define SECOND 1000000 #define REPEAT_START (1 * SECOND) #define REPEAT_DELAY (SECOND / 5) struct timeval repeatStart; struct timeval repeatDelay; repeatStart.tv_sec = 0; repeatStart.tv_usec = 0; repeatDelay.tv_sec = 0; repeatDelay.tv_usec = 0; logFd = sceIoOpen("compilerPerf.log", PSP_O_WRONLY | PSP_O_CREAT, 0777); // pspDebugScreenInit(); // pspDebugScreenPrintf("Press Cross to start the Performance Test\n"); // pspDebugScreenPrintf("Press Circle to change the CPU Clock\n"); while(!done) { /*sceCtrlReadBufferPositive(&pad, 1); int buttonDown = (oldButtons ^ pad.Buttons) & pad.Buttons; if (pad.Buttons == oldButtons) { struct timeval now; gettimeofday(&now, NULL); if (repeatStart.tv_sec == 0) { repeatStart.tv_sec = now.tv_sec; repeatStart.tv_usec = now.tv_usec; repeatDelay.tv_sec = 0; repeatDelay.tv_usec = 0; } else { long usec = (now.tv_sec - repeatStart.tv_sec) * SECOND; usec += (now.tv_usec - repeatStart.tv_usec); if (usec >= REPEAT_START) { if (repeatDelay.tv_sec != 0) { usec = (now.tv_sec - repeatDelay.tv_sec) * SECOND; usec += (now.tv_usec - repeatDelay.tv_usec); if (usec >= REPEAT_DELAY) { repeatDelay.tv_sec = 0; } } if (repeatDelay.tv_sec == 0) { buttonDown = pad.Buttons; repeatDelay.tv_sec = now.tv_sec; repeatDelay.tv_usec = now.tv_usec; } } } } else {*/ repeatStart.tv_sec = 0; /*} if (buttonDown & PSP_CTRL_CROSS) {*/ runTest(); /*}*/ /*if (buttonDown & PSP_CTRL_CIRCLE) { cpuFreq += 111; if (cpuFreq > 333) { cpuFreq = 111; } int result = scePowerSetCpuClockFrequency(cpuFreq); if (result == 0) { pspDebugScreenPrintf("CPU Clock set to %d MHz\n", cpuFreq); } else { pspDebugScreenPrintf("Could not set CPU Clock set to %d MHz\n", cpuFreq); } } if (buttonDown & PSP_CTRL_TRIANGLE) {*/ done = 1; /*} oldButtons = pad.Buttons;*/ } // sceGuTerm(); sceIoClose(logFd); sceKernelExitGame(); return 0; }