示例#1
0
文件: main.c 项目: ErikPshat/cxmb
int parseDiff( const char * file, tSceModule * mod )
{
	int off = inCtf( file );
	if ( off < 0 )
	{
		log( "there's no patch for %s\n", file );
		return 0;
	}
	
	int ctf = sceIoOpen( cxmb_theme_file, PSP_O_RDONLY, 0644 );
	if ( ctf < 0 )
	{
		log( "no ctf file found!\n" );
		return -1;
	}
	sceIoLseek( ctf, ctf_header[off].start, PSP_SEEK_SET );
	
	log( "patch %s!\nstart: %08x\nsize: %08x\n", file, ctf_header[off].start, ctf_header[off].size );
	
	unsigned int attr[2];
	int i = 0;
	while( i < ctf_header[off].size )
	{
		sceIoRead( ctf, attr, 8 );
		sceIoRead( ctf, ( void * )( mod->text_addr + attr[0] ), attr[1] );
		i ++;
	}
	sceIoClose( ctf );
	
	sceKernelIcacheInvalidateAll();
	sceKernelDcacheWritebackInvalidateAll();
	
	log( "%s patched!\n", file );
	return 0;
}
示例#2
0
static int neogeo_init(void)
{
	SceUID fd;
	char path[MAX_PATH];


   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));

   return 1;
}
示例#3
0
frame_cfg_t *frame_factory_read_cfg(SceUID fd)
{
    int bytes = 0;
    int cfg_size = 0;
    frame_cfg_t *cfg = NULL;

    if (fd == -1) {
        goto error;
    }
    bytes = sceIoRead(fd, &cfg_size, sizeof(cfg_size));
    if (bytes != sizeof(cfg_size)) {
        printf("can't read file size\n");
        goto error;
    }
    //printf("cfg size %d\n", cfg_size);
    cfg = (frame_cfg_t *)malloc(cfg_size);
    if (cfg == NULL) {
        printf("not enough mem!\n");
        goto error;
    }
    cfg->size = cfg_size;
    bytes = sceIoRead(fd, (void*)cfg+sizeof(cfg_size), cfg_size-sizeof(cfg_size));
    if (bytes != cfg_size-sizeof(cfg_size)) {
        printf("size check fail %d/%d\n", cfg_size, bytes);
        goto error;
    }
    return cfg;
error:
    if (cfg != NULL) {
        free(cfg);
    }
    return NULL;    
}
示例#4
0
文件: sceio.c 项目: Rolen47/prxpatch
int mhp3_read(SceUID fd, void *data, SceSize size) {
    u32 k1;
    int res;
    u32 cur;
    SceOff pos;
    SceSize offset;

    if (fd == datafd) {
        pos = sceIoLseek(fd, 0, PSP_SEEK_CUR);
        cur = 0;
        offset = data_start;
        while (cur < patch_count) {
            if (pos < patch_offset[cur] + patch_size[cur] && pos + size > patch_offset[cur]) {
                k1 = pspSdkSetK1(0);
                reopen_translation();
                sceIoLseek(transfd, offset + (pos - patch_offset[cur]), PSP_SEEK_SET);
                res = sceIoRead(transfd, data, size);
                if (res != (int) size) {
                    kprintf("failed to read translation data\n");
                }
                pspSdkSetK1(k1);
                sceIoLseek(fd, size, PSP_SEEK_CUR);
                return res;
            }
            offset += patch_size[cur];
            cur++;
        }
    } else {
        res = read_install(fd, data, size);
        return res;
    }
    res = sceIoRead(fd, data, size);
    return res;
}
示例#5
0
文件: sceio.c 项目: Rolen47/prxpatch
int fill_tables(SceUID fd) {
    if (fd < 0)
        return -1;
    sceIoLseek(fd, 0, PSP_SEEK_SET);
    sceIoRead(fd, &patch_count, 4);
    // max permitted: 6KiB
    if (patch_count > 6144) {
        patch_count = 6144;
    }
    kprintf("Allocating %i bytes\n", patch_count * 4 * 3);
    memid = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_KERNEL, "mhp3tbl", PSP_SMEM_High, patch_count * 4 * 3, NULL);
    if (memid < 0) {
        kprintf("Mamory alloc failed\n");
        return -1;
    }
    patch_offset = sceKernelGetBlockHeadAddr(memid);
    kprintf("patch_offset addr: %08X\n", (u32)patch_offset);
    patch_size = &patch_offset[patch_count];
    kprintf("patch_size addr: %08X\n", (u32)patch_size);
    for (u32 i = 0; i < patch_count; i++) {
        sceIoRead(fd, &patch_offset[i], 4);
        sceIoRead(fd, &patch_size[i], 4);
    }
    data_start = ((patch_count + 1) * 8);
    if (data_start % 16 > 0) {
        data_start += 16 - (data_start % 16);
    }
    return 0;
}
示例#6
0
void checkIo(int doDispatch) {
	char temp[128];
	SceUID fd = sceIoOpen("dispatch.prx", PSP_O_RDONLY, 0777);
	dispatchCheckpoint("sceIoOpen: %08x", fd >= 0 ? 1 : fd);
	dispatchCheckpoint("sceIoRead: %08x", sceIoRead(fd, temp, sizeof(temp)));
	dispatchCheckpoint("sceIoClose: %08x", sceIoClose(fd));

	int state;
	if (doDispatch) {
		++ignoreResched;
		state = sceKernelSuspendDispatchThread();
		dispatchCheckpoint("sceKernelSuspendDispatchThread: %08x", state);
	}
	fd = sceIoOpen("dispatch.prx", PSP_O_RDONLY, 0777);
	dispatchCheckpoint("sceIoOpen: %08x", fd >= 0 ? 1 : fd);
	dispatchCheckpoint("sceIoRead: %08x", sceIoRead(fd, temp, sizeof(temp)));
	dispatchCheckpoint("sceIoClose: %08x", sceIoClose(fd));
	if (doDispatch) {
		dispatchCheckpoint("sceKernelResumeDispatchThread: %08x", sceKernelResumeDispatchThread(state));
		--ignoreResched;
	}

	SceInt64 res = -1;
	int result = -1;
	fd = sceIoOpenAsync("dispatch.prx", PSP_O_RDONLY, 0777);
	dispatchCheckpoint("sceIoOpenAsync: %08x", fd >= 0 ? 1 : fd);
	if (doDispatch) {
		++ignoreResched;
		state = sceKernelSuspendDispatchThread();
		dispatchCheckpoint("sceKernelSuspendDispatchThread: %08x", state);
	}
	result = sceIoPollAsync(fd, &res);
	dispatchCheckpoint("sceIoPollAsync: %08x / %016llx", result, res >= 0 ? 1LL : res);
	result = sceIoGetAsyncStat(fd, 1, &res);
	dispatchCheckpoint("sceIoGetAsyncStat: %08x / %016llx", result, res >= 0 ? 1LL : res);
	result = sceIoGetAsyncStat(fd, 0, &res);
	dispatchCheckpoint("sceIoGetAsyncStat: %08x / %016llx", result, res >= 0 ? 1LL : res);
	result = sceIoWaitAsync(fd, &res);
	dispatchCheckpoint("sceIoWaitAsync: %08x / %016llx", result, res >= 0 ? 1LL : res);
	if (doDispatch) {
		dispatchCheckpoint("sceKernelResumeDispatchThread: %08x", sceKernelResumeDispatchThread(state));
		--ignoreResched;
	}
	result = sceIoWaitAsync(fd, &res);
	dispatchCheckpoint("sceIoWaitAsync: %08x / %016llx", result, res >= 0 ? 1LL : res);
	if (doDispatch) {
		++ignoreResched;
		state = sceKernelSuspendDispatchThread();
		dispatchCheckpoint("sceKernelSuspendDispatchThread: %08x", state);
	}
	dispatchCheckpoint("sceIoRead: %08x", sceIoRead(fd, temp, sizeof(temp)));
	dispatchCheckpoint("sceIoWrite: %08x", sceIoWrite(1, "Hello.", sizeof("Hello.")));
	if (doDispatch) {
		dispatchCheckpoint("sceKernelResumeDispatchThread: %08x", sceKernelResumeDispatchThread(state));
		--ignoreResched;
	}
	dispatchCheckpoint("sceIoCloseAsync: %08x", sceIoCloseAsync(fd));
	result = sceIoWaitAsync(fd, &res);
	dispatchCheckpoint("sceIoWaitAsync: %08x / %016llx", result, res);
}
示例#7
0
int colorconfig_read(ColorConfig* prConfig, SceUID fd) {
    if (prConfig == NULL) {
        return COLORCONFIG_NULLPTR;
    }
    sceIoRead(fd, &prConfig->background, sizeof(u32));
    sceIoRead(fd, &prConfig->text, sizeof(u32));
    return COLORCONFIG_SUCCESS;
}
示例#8
0
void PBPParse::Parse(const char *file){
	fid = sceIoOpen(file, PSP_O_RDONLY, 0777);

	sceIoMkdir("ms0:/TMP", 0777);
	if (fid >= 0)
	{
		if (sceIoRead(fid, &header, sizeof(PBPHeader)) == sizeof(PBPHeader)){

			char *temp = (char*)malloc(header.icon0 - header.sfo);
			sceIoLseek(fid, header.sfo, PSP_SEEK_SET);
			sceIoRead(fid, temp, header.icon0 - header.sfo);
			SceUID sfoFile = sceIoOpen("ms0:/TMP/PARAM.SFO", PSP_O_CREAT | PSP_O_WRONLY, 0777);
			sceIoWrite(sfoFile, temp, header.icon0 - header.sfo);
			sceIoClose(sfoFile);
			free(temp);
			sfo.Parse("ms0:/TMP/PARAM.SFO");

			temp = (char*)malloc(header.icon1 - header.icon0);
			sceIoLseek(fid, header.icon0, PSP_SEEK_SET);
			sceIoRead(fid, temp, header.icon1 - header.icon0);
			SceUID icoFile = sceIoOpen("ms0:/TMP/ICON0.PNG", PSP_O_CREAT | PSP_O_WRONLY, 0777);
			sceIoWrite(icoFile, temp, header.icon1 - header.icon0);
			sceIoClose(icoFile);
			if (header.icon1 - header.icon0 > 0){
				OSL_IMAGE *ico = oslLoadImageFilePNG("ms0:/TMP/ICON0.PNG", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_5650);
				icon = oslScaleImageCreate(ico, OSL_IN_RAM, 64, 64, OSL_PF_5650);
				oslDeleteImage(ico);
				oslWriteImageFilePNG(icon, "ms0:/TMP/ICON0.PNG", 0);
			}
			else{
				icon = oslCreateImageCopy(defaultUNKN, OSL_IN_RAM);
			}
			free(temp);

			temp = (char*)malloc(header.snd - header.pic1);
			sceIoLseek(fid, header.pic1, PSP_SEEK_SET);
			sceIoRead(fid, temp, header.snd - header.pic1);
			SceUID picFile = sceIoOpen("ms0:/TMP/PIC1.PNG", PSP_O_CREAT | PSP_O_WRONLY, 0777);
			sceIoWrite(picFile, temp, header.snd - header.pic1);
			sceIoClose(picFile);
			if (header.snd - header.pic1 > 0){
				pic = oslLoadImageFilePNG("ms0:/TMP/PIC1.PNG", OSL_IN_RAM, OSL_PF_8888);

				OSL_IMAGE *tmpPic = oslScaleImageCreate(pic, OSL_IN_RAM, 128, 128, OSL_PF_8888);
				oslUnswizzleImage(tmpPic);
				oslWriteImageFilePNG(tmpPic, "ms0:/TMP/PIC1SC.PNG", 0);
				oslDeleteImage(tmpPic);
				oslDeleteImage(pic);	//Get rid of the pic file for now, we don't need it
			}
			free(temp);

			sceIoClose(fid);
		}
	}
}
示例#9
0
//Seek next valid frame
//NOTE: this function comes from Music prx 0.55 source
//      all credits goes to joek2100.
int MP3ME_SeekNextFrameMP3(SceUID fd)
{
    int offset = 0;
    unsigned char buf[1024];
    unsigned char *pBuffer;
    int i;
    int size = 0;

    offset = sceIoLseek32(fd, 0, PSP_SEEK_CUR);
    sceIoRead(fd, buf, sizeof(buf));
    if (!strncmp((char*)buf, "ID3", 3) || !strncmp((char*)buf, "ea3", 3)) //skip past id3v2 header, which can cause a false sync to be found
    {
        //get the real size from the syncsafe int
        size = buf[6];
        size = (size<<7) | buf[7];
        size = (size<<7) | buf[8];
        size = (size<<7) | buf[9];

        size += 10;

        if (buf[5] & 0x10) //has footer
            size += 10;
    }

    sceIoLseek32(fd, offset, PSP_SEEK_SET); //now seek for a sync
    while(1)
    {
        offset = sceIoLseek32(fd, 0, PSP_SEEK_CUR);
        size = sceIoRead(fd, buf, sizeof(buf));

        if (size <= 2)//at end of file
            return -1;

        if (!strncmp((char*)buf, "EA3", 3))//oma mp3 files have non-safe ints in the EA3 header
        {
            sceIoLseek32(fd, (buf[4]<<8)+buf[5], PSP_SEEK_CUR);
            continue;
        }

        pBuffer = buf;
        for( i = 0; i < size; i++)
        {
            //if this is a valid frame sync (0xe0 is for mpeg version 2.5,2+1)
            if ( (pBuffer[i] == 0xff) && ((pBuffer[i+1] & 0xE0) == 0xE0))
            {
                offset += i;
                sceIoLseek32(fd, offset, PSP_SEEK_SET);
                return offset;
            }
        }
       //go back two bytes to catch any syncs that on the boundary
        sceIoLseek32(fd, -2, PSP_SEEK_CUR);
    }
}
示例#10
0
void loadTheme()
{
	int i, bytesRead;

	SceUID fp;
	fp = sceIoOpen("ms0:/lockdown.thm", PSP_O_RDONLY, 0777);

	if (fp < 0)
	{
		fp = sceIoOpen("flash0:/lockdown.thm", PSP_O_RDONLY, 0777);

		if (fp < 0)
		{
			printTextScreen(0, 0, "Error loading flash0:/lockdown.thm.", RGB(255, 0, 0));
			printTextScreen(0, 8, "Place theme at ms0:/lockdown.thm to load from memory stick.", RGB(255, 0, 0));
			sceDisplayWaitVblankStart();
			flipScreen();
			sceKernelSleepThread();
		}
	}

	for (i = 0; i < NUMFILES; i++)
	{
		bytesRead = sceIoRead(fp, &images[i].hdr, sizeof(imagehdr));
		if (bytesRead != sizeof(imagehdr))
		{
			printTextScreen(0, 0, "Unexpected end of header.", RGB(255, 0, 0));
			sceDisplayWaitVblankStart();
			flipScreen();
			sceKernelSleepThread();
		}
		images[i].blockid = sceKernelAllocPartitionMemory(2, "block", 0, (sizeof(unsigned char) * images[i].hdr.size), NULL);
		if (images[i].blockid < 0)
		{
			printTextScreen(0, 0, "Memory allocation error.", RGB(255, 0, 0));
			sceDisplayWaitVblankStart();
			flipScreen();
			sceKernelSleepThread();
		}
		images[i].data = (unsigned char*) sceKernelGetBlockHeadAddr(images[i].blockid);
		bytesRead = sceIoRead(fp, images[i].data, images[i].hdr.size);
		if (bytesRead != images[i].hdr.size)
		{
			printTextScreen(0, 0, "Unexpected end of data.", RGB(255, 0, 0));
			sceDisplayWaitVblankStart();
			flipScreen();
			sceKernelSleepThread();
		}
	}

	sceIoClose(fp);
}
示例#11
0
int compare_file_buffer(const char *path, void *file_buf, int size) 
{
	SceUID fd = -1;
	int ret;
	SceIoStat srcstat;

	ret = sceIoGetstat(path, &srcstat);
	
	if (ret != 0) {
		goto not_equal;
	}

	if (srcstat.st_size != size) {
		goto not_equal;
	}

	ret = sceIoOpen(path, PSP_O_RDONLY, 0777);

	if (ret < 0) {
		goto not_equal;
	}

	fd = ret;

	ret = sizeof(g_buf);
	ret = sceIoRead(fd, g_buf, ret);

	while (ret > 0) {
		if (memcmp(g_buf, file_buf, ret)) {
			goto not_equal;
		}

		file_buf += ret;
		ret = sceIoRead(fd, g_buf, ret);
	}

	if (ret < 0) {
		goto not_equal;
	}

	sceIoClose(fd);

	return 0;

not_equal:
	if (fd >= 0)
		sceIoClose(fd);

	return 1;
}
示例#12
0
static int get_icon0_status(void)
{
	u32 icon0_offset = 0;
	int result = ICON0_MISSING;
	SceUID fd = -1;;
	const char *filename;
	u8 p[40 + 64], *header;
	
	header = (u8*)((((u32)p) & ~(64-1)) + 64);
	filename = sceKernelInitFileName();

	if(filename == NULL) {
		goto exit;
	}
	
	fd = sceIoOpen(filename, PSP_O_RDONLY, 0777);

	if(fd < 0) {
		printk("%s: sceIoOpen %s -> 0x%08X\n", __func__, filename, fd);
		goto exit;
	}
	
	sceIoRead(fd, header, 40);
	icon0_offset = *(u32*)(header+0x0c);
	sceIoLseek32(fd, icon0_offset, PSP_SEEK_SET);
	sceIoRead(fd, header, 40);

	if(*(u32*)(header+4) == 0xA1A0A0D) {
		if ( *(u32*)(header+0xc) == 0x52444849 && // IHDR
				*(u32*)(header+0x10) == 0x50000000 && // 
				*(u32*)(header+0x14) == *(u32*)(header+0x10)
		   ) {
			result = ICON0_OK;
		} else {
			result = ICON0_CORRUPTED;
		}
	} else {
		result = ICON0_MISSING;
	}

	printk("%s: PNG file status -> %d\n", __func__, result);

exit:
	if(fd >= 0) {
		sceIoClose(fd);
	}

	return result;
}
示例#13
0
int copy_file(const char *src, const char *dst)
{
	SceUID fd = -1, fdw = -1;
	int ret;

	ret = sceIoOpen(src, PSP_O_RDONLY, 0777);

	if (ret < 0) {
		goto error;
	}

	fd = ret;

	ret = sceIoOpen(dst, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);

	if (ret < 0) {
		goto error;
	}

	fdw = ret;
	ret = sizeof(g_buf);
	ret = sceIoRead(fd, g_buf, ret);

	while (ret > 0) {
		ret = sceIoWrite(fdw, g_buf, ret);

		if (ret < 0) {
			goto error;
		}

		ret = sceIoRead(fd, g_buf, ret);
	}

	if (ret < 0) {
		goto error;
	}

	sceIoClose(fd);
	sceIoClose(fdw);

	return 0;

error:
	sceIoClose(fd);
	sceIoClose(fdw);

	return ret;
}
示例#14
0
pgeObj *pgeObjLoad(const char *filename)
{	
	int fd = sceIoOpen(filename, 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);
	
	pgeObj *obj = pgeObjLoadInternal(data, filesize);
	
	if(data)
		pgeFree(data);
	
	return obj;
}
示例#15
0
文件: conf.c 项目: smiky/psvdev
int sctrlSEGetConfig(TNConfig *config)
{
	int k1 = pspSdkSetK1(0);

	memset(config, 0, sizeof(TNConfig));

	/* Default settings */
	strcpy(config->nickname, "CEF User");
	config->exit_button_1 = 2; //PSP_CTRL_START
	config->exit_hold_duration = 2;
	config->button_assign = 1; //CROSS
	config->show_pic1 = 1; //enabled

	SceUID fd = sceIoOpen("ms0:/PSP/SYSTEM/CONFIG.TN", PSP_O_RDONLY, 0);
	if(fd < 0)
	{
		pspSdkSetK1(k1);
		return fd;
	}

	int read = sceIoRead(fd, config, sizeof(TNConfig));
	sceIoClose(fd);

	pspSdkSetK1(k1);
	return read;
}
示例#16
0
static int check_file_is_encrypted(int fd)
{
	int ret;
	u32 k1;
	char p[8 + 64], *buf;

	k1 = pspSdkSetK1(0);
	buf = (char*)((((u32)p) & ~(64-1)) + 64);
	ret = sceIoRead(fd, buf, 8);
	pspSdkSetK1(k1);
	sceIoLseek32(fd, 0, PSP_SEEK_SET);

	if (ret != 8)
		return 0;

	if (!memcmp(buf, g_drm_magic_1, sizeof(g_drm_magic_1))) {
		return 1;
	}

	if (!memcmp(buf, g_drm_magic_2, sizeof(g_drm_magic_2))) {
		return 1;
	}

#if 0
	printk("%s: buf:\n", __func__);
	hexdump(buf, 8);
#endif

	return 0;
}
示例#17
0
static int load_key(const char *keypath, u8 *key, int size)
{
	SceUID keys; 
	int ret;

	keys = sceIoOpen(keypath, PSP_O_RDONLY, 0777);

	if (keys < 0) {
		printk("%s: sceIoOpen %s -> 0x%08X\n", __func__, keypath, keys);

		return -1;
	}

	ret = sceIoRead(keys, key, size); 

	if (ret == size) {
		ret = 0;
	} else {
		ret = -2;
	}

	sceIoClose(keys);

	return ret;
}
示例#18
0
文件: JMP3.cpp 项目: 173210/w-menu
int JMP3::GetID3TagSize(char *fname) 
{ 
    SceUID fd; 
    char header[10]; 
    int size = 0; 
    fd = sceIoOpen(fname, PSP_O_RDONLY, 0777); 
    if (fd < 0) 
        return 0; 

    sceIoRead(fd, header, sizeof(header)); 
    sceIoClose(fd); 

    if (!strncmp((char*)header, "ea3", 3) || !strncmp((char*)header, "EA3", 3) 
      ||!strncmp((char*)header, "ID3", 3)) 
    { 
        //get the real size from the syncsafe int 
        size = header[6]; 
        size = (size<<7) | header[7]; 
        size = (size<<7) | header[8]; 
        size = (size<<7) | header[9]; 

        size += 10; 

        if (header[5] & 0x10) //has footer 
            size += 10; 
         return size; 
    } 
    return 0; 
}
示例#19
0
static void send_file(ClientInfo *client, const char *path)
{
	unsigned char *buffer;
	SceUID fd;
	unsigned int bytes_read;

	DEBUG("Opening: %s\n", path);

	if ((fd = sceIoOpen(path, PSP2_O_RDONLY, 0777)) >= 0) {

		buffer = malloc(FILE_BUF_SIZE);
		if (buffer == NULL) {
			client_send_ctrl_msg(client, "550 Could not allocate memory.\n");
			return;
		}

		client_open_data_connection(client);
		client_send_ctrl_msg(client, "150 Opening Image mode data transfer.\n");

		while ((bytes_read = sceIoRead (fd, buffer, FILE_BUF_SIZE)) > 0) {
			client_send_data_raw(client, buffer, bytes_read);
		}

		sceIoClose(fd);
		free(buffer);
		client_send_ctrl_msg(client, "226 Transfer completed.\n");
		client_close_data_connection(client);

	} else {
		client_send_ctrl_msg(client, "550 File not found.\n");
	}
}
示例#20
0
static int read_ADIF_header(SceUID file, unsigned long filesize, struct fileInfo *info)
{
    int bitstream;
    unsigned char buffer[ADIF_MAX_SIZE];
    int skip_size = 0;
    int sf_idx;

    /* Get ADIF header data */
    if (sceIoRead(file, buffer, ADIF_MAX_SIZE) != ADIF_MAX_SIZE)
        return -1;

    /* copyright string */
    if(buffer[0] & 0x80)
        skip_size += 9; /* skip 9 bytes */

    bitstream = buffer[0 + skip_size] & 0x10;
    /*info->bitrate = ((unsigned int)(buffer[0 + skip_size] & 0x0F)<<19)|
        ((unsigned int)buffer[1 + skip_size]<<11)|
        ((unsigned int)buffer[2 + skip_size]<<3)|
        ((unsigned int)buffer[3 + skip_size] & 0xE0);*/
    int bitrate = ((unsigned int)(buffer[0 + skip_size] & 0x0F)<<19)|
                  ((unsigned int)buffer[1 + skip_size]<<11)|
                  ((unsigned int)buffer[2 + skip_size]<<3)|
                  ((unsigned int)buffer[3 + skip_size] & 0xE0);
    info->kbit = bitrate / 1000;
    if (bitstream == 0)
    {
        //info->object_type =  ((buffer[6 + skip_size]&0x01)<<1)|((buffer[7 + skip_size]&0x80)>>7);
        sf_idx = (buffer[7 + skip_size]&0x78)>>3;
    } else {
示例#21
0
int LPP_UtilsGameShareInit(const char *filepath, const char *name)
{
    sceNetAdhocMatchingInit(32*1024);

    memset(&lpp_UtilsGameShareParams, 0, sizeof(lpp_UtilsGameShareParams));
    lpp_UtilsGameShareParams.base.size = sizeof(lpp_UtilsGameShareParams);

    sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &lpp_UtilsGameShareParams.base.language);
    sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &lpp_UtilsGameShareParams.base.buttonSwap);

    lpp_UtilsGameShareParams.base.graphicsThread = 17;
    lpp_UtilsGameShareParams.base.accessThread = 19;
    lpp_UtilsGameShareParams.base.fontThread = 18;
    lpp_UtilsGameShareParams.base.soundThread = 16;

    size_t lsize = 0;

    SceUID fd = sceIoOpen(filepath, PSP_O_RDONLY, 0777);
    if(fd < 0) return -1;

    lsize = sceIoLseek32(fd, 0, PSP_SEEK_END);

    u8 *buffer = (u8*)malloc(lsize);

    if(buffer == null)
    {
        sceIoClose(fd);
        return -1;
    }

    sceIoLseek32(fd, 0, PSP_SEEK_SET);

    int read = sceIoRead(fd, buffer,lsize);

    if(read < lsize)
    {
        sceIoClose(fd);
        free(buffer);
        return -1;
    }

    sceIoClose(fd);

    buffer[276] = 0x57;
    strncpy((char *)&buffer[320], name, 127);

    kuKernelMemcpy(&lpp_UtilsGameShareParams.name, "GameShar", 8);

    lpp_UtilsGameShareParams.mode = 1;
    lpp_UtilsGameShareParams.datatype = 2;

    lpp_UtilsGameShareParams.data = buffer;
    lpp_UtilsGameShareParams.datasize = lsize;

    int res = sceUtilityGameSharingInitStart(&lpp_UtilsGameShareParams);

    if(res == 0) return 1;

    return (res);
}
示例#22
0
文件: init.c 项目: BackupGGCode/aemu
/**
 * Read Line from File
 * @param fd File Descriptor to read line from
 * @param buffer Buffer to read line into
 * @param buflen Length of Buffer in Bytes
 * @return Length of Line or... 0
 */
uint32_t _readLine(int fd, char * buffer, uint32_t buflen)
{
	// Erase Buffer
	memset(buffer, 0, buflen);
	
	// Length of Line
	uint32_t length = 0;
	
	// Read Line
	while(length < buflen - 1)
	{
		// Read Character
		int b = sceIoRead(fd, buffer + length, 1);
		
		// Read Failure
		if(b <= 0) break;
		
		// Move Pointer
		length++;		
		
		// End of Line Symbol
		if(buffer[length - 1] == '\n') break;
	}
	
	// Remove End of Line Symbols
	int i = 0; for(; i < length; i++) if(buffer[i] == '\r' || buffer[i] == '\n') buffer[i] = 0;
	
	// Return true Length
	return strlen(buffer);
}
示例#23
0
文件: main.c 项目: 173210/ppsspp
int FileCopy(char* srcPath, char* destPath, char* fileName)
{
	SceIoStat fileStat;
	char path[258];
	sprintf(path,"%s/%s",srcPath, fileName);
	
	if(sceIoGetstat(path, &fileStat) < 0)
		return -1;
	u8* data = malloc(fileStat.st_size);
	
	SceUID fileId = sceIoOpen(path, PSP_O_RDONLY, 0777);
	if(fileId < 0) 
	{
		printf("Fail opening %s\n",path);
		free(data);
		return -1;
	}
	sceIoRead(fileId, data, fileStat.st_size);
	sceIoClose(fileId);
	
	sprintf(path,"%s/%s",destPath, fileName);
	
	fileId = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT, 0777);
	if(fileId < 0) 
	{
		printf("Fail opening %s\n",path);
		return -1;
	}
	sceIoWrite(fileId, data, fileStat.st_size);
	sceIoClose(fileId);
	
	free(data);
	return 0;
}
示例#24
0
int 
MP3_Load(char *filename)
{
  int fd;

  if (!strcmp(mp3_curr_filename, filename)) {
    // already loaded !
  } else
  if ((fd = sceIoOpen(filename, PSP_O_RDONLY, 0777)) > 0) {
    //  opened file, so get size now
    size = sceIoLseek(fd, 0, PSP_SEEK_END);
    sceIoLseek(fd, 0, PSP_SEEK_SET);
    if (mp3_data) { free(mp3_data); mp3_data = 0; }
    mp3_data = (unsigned char *) malloc(size + 8);
    if (mp3_data) memset(mp3_data, 0, size + 8);
    if (mp3_data != 0) {        // Read file in
      sceIoRead(fd, mp3_data, size);
    } else {
      //printf("Error allocing\n");
      sceIoClose(fd);
      return 0;
    }
    // Close file
    sceIoClose(fd);
    strcpy(mp3_curr_filename, filename);

  } else {
    return 0;
  }
  isPlaying = 0;
  FrameCount = 0;

  MP3_getInfo();
  return 1;
}
示例#25
0
size_t fread(void *buf, size_t size, size_t n, FILE *fp){
	int		ret;

	ret = sceIoRead( (int)fp, buf, size * n );

	return ret / size;
}
示例#26
0
int locate_umd_img1(const char *umdfile, size_t file_offset, SceUID * pfd)
{
	int ret = -1;
	char buf[9] = { 0 };
	size_t stread = 0;

	if (!umdfile || !pfd || file_offset < 0)
		return -1;
	*pfd = -1;
	do {
		struct UMDHeaderDataEx *pEx;

		if ((*pfd = sceIoOpen(umdfile, PSP_O_RDONLY, 0777)) < 0) {
			return -2;
		}
		if (0 < sceIoLseek(*pfd, file_offset, SEEK_SET))
			return -3;
		if ((stread = sceIoRead(*pfd, buf, 9)) < 0) {
			dbg_printf(d, "%s read umd file head chunk error!", __func__);
			break;
		}

		pEx = (struct UMDHeaderDataEx *) &buf;

		if (!pEx || pEx->Mark != '$' || pEx->Length < 9)
			break;
		return pEx->Length - 9;
	} while (false);
	if (*pfd) {
		sceIoClose(*pfd);
		*pfd = -1;
	}
	return ret;
}
示例#27
0
int copy_file(char *input, char *output)
{
	SceUID i = sceIoOpen(input, PSP_O_RDONLY, 0777);	

	if (i < 0)
		return -1;

	sceIoRemove(output);

	SceUID o = sceIoOpen(output, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);

	if (o < 0)
		return -1;

	int read;

	while ((read = sceIoRead(i, buf, 16384)) > 0)
	{
		sceIoWrite(o, buf, read);
	}

	sceIoClose(i);
	sceIoClose(o);

	return 0;
}
示例#28
0
ssize_t filestream_read(RFILE *stream, void *s, size_t len)
{
   if (!stream || !s)
      goto error;
#if  defined(PSP)
   return sceIoRead(stream->fd, s, len);
#else
#if defined(HAVE_BUFFERED_IO)
   if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
      return fread(s, 1, len, stream->fp);
#endif
#ifdef HAVE_MMAP
   if (stream->hints & RFILE_HINT_MMAP)
   {
      if (stream->mappos > stream->mapsize)
         goto error;

      if (stream->mappos + len > stream->mapsize)
         len = stream->mapsize - stream->mappos;

      memcpy(s, &stream->mapped[stream->mappos], len);
      stream->mappos += len;

      return len;
   }
#endif
   return read(stream->fd, s, len);
#endif

error:
   return -1;
}
示例#29
0
文件: Red3dIO.c 项目: RedHate/Red3d
void *Red3dLoadFile(const char *path, int mempart)
{
	void *ptr, *readbuffer;
	
	int c = Red3dCheckFile(path);
	if(c >= 0) return DirIndex[c]->address;
	
	int fd = sceIoOpen(path, PSP_O_RDONLY, 0777);
	if(fd >= 0)
	{
		
		u32 size = sceIoLseek(fd, 0, SEEK_END); 
		sceIoLseek(fd, 0, SEEK_SET);
		
		readbuffer = malloc(size);
		sceIoRead(fd, readbuffer, size);
		
		ptr = Red3dLoadBuf(readbuffer, size, mempart);
		
		free(readbuffer);
		sceKernelDcacheWritebackInvalidateAll();
		sceIoClose(fd);
		
		return ptr;

	}
	return NULL;
}
示例#30
0
int fgetc(FILE *fp){
	char	c;

	sceIoRead( (int)fp, &c, sizeof(char) );

	return (int)c;
}