示例#1
0
文件: file.c 项目: smiley22/myPS2
int FileRead( FHANDLE handle, void *buffer, int size )
{
	int ret = 0;

	if( handle.dt == DT_CD ) {
		ret = fioRead( handle.fh, buffer, size );
	}
	else if( handle.dt == DT_HDD ) {
		ret = fileXioRead( handle.fh, buffer, size );
	}
	else if( handle.dt == DT_MC ) {
		ret = fioRead( handle.fh, buffer, size );
	}
	else if( handle.dt == DT_USB ) {
		ret = fioRead( handle.fh, buffer, size );
	}
	else if( handle.dt == DT_HOST ) {
		ret = fioRead( handle.fh, buffer, size );
	}
	else if( handle.dt == DT_SMB_SHARE ) {
		ret = smbc_read( handle.fh, buffer, size );
	}

	return ret;
}
示例#2
0
int fioGets(int fd, char* buff, int n)
{
	// Rather than doing a slow byte-at-a-time read
	// read upto the max langth, then re-position file afterwards
	int read;
	int i;

	read = fioRead(fd, buff, n);

    for (i=0; i<(read-1); i++)
	{
		switch (buff[i])
		{
		case '\n':
			fioLseek(fd, (i + 1) - read, SEEK_CUR);
			buff[i]=0;	// terminate after newline
			return i;

		case 0:
			fioLseek(fd, i-read, SEEK_CUR);
            return i;
		}
	}

	// if we reached here, then we havent found the end of a string
	return i;
}
示例#3
0
int CD_ReadCNF()
{
	int fd,n,m;
    fd=fioOpen("cdrom0:\\SYSTEM.CNF;1",1);
	if(fd>=0)
		{
		m=fioLseek(fd,0,2);
		fioLseek(fd,0,0);
		if(m>=4095) m=4094;
		fioRead(fd,systemcnf,m);
		systemcnf[m+1]=0;
		m=0;
        while(systemcnf[m]!=0)
			{
			if(systemcnf[m]=='B' && systemcnf[m+1]=='O' && systemcnf[m+2]=='O' && systemcnf[m+3]=='T' && systemcnf[m+4]=='2')
				{m+=5;break;}
			m++;
			}
		while(systemcnf[m]!=0 && systemcnf[m]==32) m++;
		if(systemcnf[m]!=0 )m++; // salta '='
		while(systemcnf[m]!=0 && systemcnf[m]==32) m++;
		if(systemcnf[m]==0) return 0;
		for(n=0;n<255;n++)
			{
			CD_DIRELF[n]=systemcnf[m];
			if(systemcnf[m]==0) break;
			if(n>2) if(CD_DIRELF[n-1]==';' && CD_DIRELF[n]=='1')  {CD_DIRELF[n+1]=0;break;}
            m++;
			}
		CD_DIRELF[255]=0;
		fioClose(fd);
		return 1;
		}
    return 0;
}
示例#4
0
int fioGetc(int fd)
{
	int c;

	fioRead(fd,&c,1);
	return c;
}
示例#5
0
int PS2KbdReadRaw(PS2KbdRawKey *key)
/* Reads 1 raw character from the keyboard */
{
  if((kbd_fd >= 0) && (curr_readmode == PS2KBD_READMODE_RAW))
    {
      return fioRead(kbd_fd, key, 2) / 2;
    }

  return 0;
}
示例#6
0
int PS2KbdRead(char *key)
/* Reads 1 character from the keyboard */
{
  if((kbd_fd >= 0) && (curr_readmode == PS2KBD_READMODE_NORMAL))
    {
      return fioRead(kbd_fd, key, 1);
    }

  return 0;
}
示例#7
0
文件: file.c 项目: AzagraMac/PS2_SDK
/****************************************************************************
 * Universal file reading function.  Returns the amount of bytes read.		*
 ****************************************************************************/
int ReadFile(int handle, unsigned char *buffer, int size, int media)
{
	int sr =0;
//	printf ("ReadFile(%d, %p, %d, %d)\n", handle, buffer, size, media);
	switch (media)
	{
	case 0:
		{
			sr = fileXioRead(handle, buffer, size);
			break;
		}
	case 1:
		{
			sr = fioRead(handle, buffer, size);
			break;
		}
	case 2:
		{
			//sr = fioRead(handle, buffer, size);
			sr = fileXioRead(handle, buffer, size);
			break;
		}
	case 3:
		{
			//sr = fioRead(handle, buffer, size);
			sr = fileXioRead(handle, buffer, size);
			break;
		}
	case 4:
		{
			sr = fioRead(handle, buffer, size);
			break;
		}
	case 5:
		{
			sr = fileXioRead(handle, buffer, size);
			break;
		}
	}
	return sr;
}
示例#8
0
unsigned short int detect_bios_version(void)
{

	int fd;
	char romver_buffer[5];

	fd=fioOpen("rom0:ROMVER", O_RDONLY);

	// Read the PS2's BIOS version from rom0:ROMVER.
	fioRead(fd, romver_buffer, 4);

	fioClose(fd);

	// Null terminate the string.
	romver_buffer[4]='\0';

	// Return the PS2's BIOS version.
	return(strtoul(romver_buffer, NULL, 16));
}
示例#9
0
文件: main.c 项目: shorti006/CN-Cheat
char *parseSystemCnf()
{
	char *buffer;
	int fd, fdSize;
	int i;

	// Open SYSTEM.CNF on the cdrom, allocate memory for it, terminate the array
	fd = fioOpen("cdrom0:\\SYSTEM.CNF;1", O_RDONLY);
	if(fd < 0) return (char *)ERROR_SYSTEMCNF_FILEIO;

	fdSize = fioLseek(fd, 0, SEEK_END);
	fioLseek(fd, 0, SEEK_SET);

	buffer = malloc(fdSize + 1);
	if(!buffer) return (char *)ERROR_SYSTEMCNF_MEMORY;

	if(fioRead(fd, buffer, fdSize) != fdSize) return (char *)ERROR_SYSTEMCNF_FILEIO;
	fioClose(fd);
	buffer[fdSize] = '\0';

	// Find boot file substring
	buffer = strstr(buffer, "BOOT2");
	buffer += 5;
	while((*buffer == ' ') || (*buffer == '\t')) buffer++;
	buffer++; // bypass '=' character
	while((*buffer == ' ') || (*buffer == '\t')) buffer++;

	i = 0;
	while((buffer[i] != '\n') && (buffer[i] != '\r')) i++;

	// Terminate string at end of boot elf filename
	buffer[i] = '\0';

	// Return pointer to boot elf filename string
	return buffer;
}
示例#10
0
static void _load_font ( unsigned int anIndex ) {

 int lFD = fioOpen ( s_pFontNames[ anIndex ], O_RDONLY );

 if ( lFD >= 0 ) {

  long lSize = fioLseek ( lFD, 0, SEEK_END );

  if ( lSize > 0 ) {

   unsigned char* lpBuff = ( unsigned char* )malloc ( lSize );

   fioLseek ( lFD, 0, SEEK_SET );
   fioRead ( lFD, lpBuff, lSize );

   GSFont_Set ( anIndex, lpBuff );

  }  /* end if */

  fioClose ( lFD );

 }  /* end if */

}  /* end LoadFont */
示例#11
0
int main()
{
	int xpos=20;
	int ypos=20;
	int xdir=1;
	int ydir=1;


	gsFontTex* fontTex;


	// Create a gsDriver with default settings
	// (320x240 32bit, double-buffer, zbuffer allocated, alpha enabled)
	gsDriver myGsDriver(NTSC);

	// Change to hi-res so can fit more of our 16x16 font on screen
	myGsDriver.setDisplayMode(640, 480,
				  NTSC, FIELD,
				  GS_PSMCT32,
				  GS_ENABLE, GS_PSMZ32,
				  2);

	gsFont myFont;

	// Won't bother creating our own gsPipe, since we can use the one created by our gsDriver
	// gsPipe myGsPipe;

	// Assign a gsPipe to the font handler
	myFont.assignPipe(&myGsDriver.drawPipe);

	// Enable alpha blending
	myGsDriver.drawPipe.setAlphaEnable(GS_ENABLE);


	// Open the file
	int filehandle = fioOpen("host:arial.fnt",O_RDONLY);

	// Get the size of the file
	int filesize = fioLseek( filehandle, 0, SEEK_END);

	// allocate space to load the file into EE mem
	fontTex = (gsFontTex*)memalign(64,filesize);

	//seek back to the start of the file
	fioLseek(filehandle, 0, SEEK_SET);

	if (fioRead(filehandle,fontTex,filesize) <= 0)
	{
		printf("Could not load texfont.fnt\n");
		while(1);
	}

	fioClose(filehandle);

	// Upload into the beginning of texture mem (with texture-buffer width set to 256)
	myFont.uploadFont(fontTex, myGsDriver.getTextureBufferBase(), 
		fontTex->TexWidth, // Use the fontTex width as texbuffer width (can use diff width)
		0, 0 );

	while (1)
	{
        // Clear the screen (with ZBuffer Disabled)
		myGsDriver.drawPipe.setZTestEnable(GS_DISABLE);
		myGsDriver.drawPipe.RectFlat(0,0,640,480,0,GS_SET_RGBA(0x00,0x00,0x00,0x80));
		myGsDriver.drawPipe.setZTestEnable(GS_ENABLE);


		// WHY IS THIS FUBAR IF DRAWN OUT OF SEQUENCE ? (Z-Test should make it okay)

		// Draw a static, solid red rectangle in the background (z=1)
		myGsDriver.drawPipe.RectFlat(
			120, 60, 120+120, 60+80,
			1, GS_SET_RGBA(0xFF,0x00,0x00,0x7F));


		// Print some text behind the moving transparent rectangle, but in-front of the static solid one

		myFont.Print(20, 400, 40, 2, GS_SET_RGBA(0xFF,0xFF,0xFF,0x80), GSFONT_ALIGN_LEFT,
			"This is some left-aligned text on the first line,\n"
			"and this is some more text.\n"
			"Don't get too excited, this is just even more text to prove that line-wrap works properly.");

		myFont.Print(140, 500, 200, 2, GS_SET_RGBA(0x20,0x20,0xFF,0x80), GSFONT_ALIGN_CENTRE,
			"This is some blue centred text.\n"
			"You can do some nice \aunderlining\a if you want to!\n"
			"It's easy, just use \\a to turn it on or off");

		myFont.Print(20, 620, 360, 2, GS_SET_RGBA(0xFF,0x20,0x20,0x80), GSFONT_ALIGN_RIGHT,
			"This is some red right-aligned text.\n"
			"You can do some nice \bbold\b text too if you want!\n"
			"Just use \\b to turn bold text on or off");



		// Draw a moving, semi-transparent, rectangle (at z=3)
		myGsDriver.drawPipe.RectFlat(
			xpos, ypos, xpos+160, ypos+120,
			3, GS_SET_RGBA(0x00,0xFF,0x00,0x40));



		// Flush the pipe, to draw the prims
		myGsDriver.drawPipe.Flush();



		// Wait for VSync and then swap buffers
		myGsDriver.WaitForVSync();

		myGsDriver.swapBuffers();

		// move the green rectangle
		xpos+=xdir;
		ypos+=ydir;

		// change dir if it hits the limits
		if (xpos>((640-160)-1)) xdir=-1;
		if (xpos<1) xdir=1;

		if (ypos>((480-120)-1)) ydir=-1;
		if (ypos<1) ydir=1;

	}
}
示例#12
0
文件: file.c 项目: AzagraMac/PS2_SDK
int RunElf(char *name)
{
	int fd,size,i;
	u8 *boot_elf = (u8 *) 0;//&_end;
	elf_header_t *eh = &elfh;
	elf_pheader_t *eph;
	char *argv[1];
	void *pdata;
	fd=-1;
	if(name[0]=='m' && name[1]=='c') // if mc, test mc0 and mc1
	{
		if((fd = fioOpen(name,1)) < 0) 
		{
			name[2]='1';
		}
	}
	if(fd < 0)
		if((fd = fioOpen(name,1)) < 0) 
		{
			return -1;
		}
		size = fioLseek(fd, 0, SEEK_END);
		if(!size) {
			fioClose(fd);
			return -2;
		}

		fioLseek(fd, 0, 0);
		fioRead(fd, eh, sizeof(elf_header_t)); // read the elf header

		// crazy code for crazy man :P
		boot_elf=(u8 *)0x1800000-size-256; 
		//if((eh->entry+size)>=boot_elf) boot_elf=(u8 *)eh->entry-size-256;
		boot_elf=(u8 *) (((unsigned)boot_elf) &0xfffffff0);

		// read rest file elf
		fioRead(fd, boot_elf+sizeof(elf_header_t), size-sizeof(elf_header_t));
		fioClose(fd);

		// mrbrown machine gun ;)
		eph = (elf_pheader_t *)(boot_elf + eh->phoff);
		// Scan through the ELF's program headers and copy them into RAM, then
		// zero out any non-loaded regions.
		for (i = 0; i < eh->phnum; i++) {
	   	   if (eph[i].type != ELF_PT_LOAD)
			   continue;
			   
		pdata = (void *)(boot_elf + eph[i].offset);
		memcpy2((unsigned char *)eph[i].vaddr, (unsigned char *)pdata, (int)eph[i].filesz);

		if (eph[i].memsz > eph[i].filesz)
			memset2((unsigned char *)eph[i].vaddr + eph[i].filesz, (unsigned char)0, (int)eph[i].memsz - eph[i].filesz);
	}

	// Let's go.
	argv[0] = name;

	fioExit();
	Reset();
	FlushCache(0);
	FlushCache(2);
	ExecPS2((void *)eh->entry, 0, 1, argv);
	return 0;
}
示例#13
0
int Sys_FileRead (int handle, void *dest, int count)
{
	return fioRead(sys_handles[handle], dest, count);
}
示例#14
0
文件: irxboot.cpp 项目: bgK/scummvm
int loadIrxModules(int device, const char *irxPath, IrxReference **modules) {

	IrxReference *resModules = (IrxReference *)malloc(numIrxFiles * sizeof(IrxReference));
	IrxReference *curModule = resModules;

	for (int i = 0; i < numIrxFiles; i++) {
		curModule->fileRef = irxFiles + i;
		if ((device == HOST_DEV) && (irxFiles[i].flags & NOT_HOST))
			continue;

		if ((irxFiles[i].flags & TYPEMASK) == BIOS) {
			curModule->loc = IRX_FILE;
			curModule->path = (char *)malloc(32);
			sprintf(curModule->path, "rom0:%s", irxFiles[i].name);
			curModule->buffer = NULL;
			curModule->size = 0;
			curModule->argSize = 0;
			curModule->args = NULL;
			curModule->errorCode = 0;
		} else {
			curModule->loc = IRX_BUFFER;
			curModule->path = (char *)malloc(256);

			sprintf(curModule->path, "%s%s%s", irxPath, irxFiles[i].name, (device == CD_DEV) ? ";1" : "");
			int fd = fioOpen(curModule->path, O_RDONLY);
			if (fd < 0) {
				// IRX not found
				sioprintf("Can't open %s: %d\n", curModule->path, fd);
				// we keep the error code of the path where we originally expected the file
				curModule->errorCode = fd;

				// try cdrom root directory
				sprintf(curModule->path, "cdrom0:\\%s;1", irxFiles[i].name);
				fd = fioOpen(curModule->path, O_RDONLY);
				if (fd < 0) {
					// still not found, try host:
					sioprintf("Can't open %s: %d\n", curModule->path, fd);
					sprintf(curModule->path, "host:%s", irxFiles[i].name);
					fd = fioOpen(curModule->path, O_RDONLY);
					if (fd < 0) {
						// we simply can't find it.
						sioprintf("Can't open %s: %d\n", curModule->path, fd);
						// restore the path where we originally expected the file, for error message (later, after boot up)
						sprintf(curModule->path, "%s%s%s", irxPath, irxFiles[i].name, (device == CD_DEV) ? ";1" : "");
					}
				}
			}

			if (fd >= 0) {
				curModule->size = fioLseek(fd, 0, SEEK_END);
				fioLseek(fd, 0, SEEK_SET);
				curModule->buffer = (uint8 *)memalign(64, (curModule->size + 63) & ~63);
				fioRead(fd, curModule->buffer, curModule->size);

				curModule->argSize = irxFiles[i].argSize;
				curModule->args = irxFiles[i].args;
				curModule->errorCode = 0;
				fioClose(fd);
			} else {
				if (irxFiles[i].flags & DEPENDANCY) {
					// other modules depend on this one.
					// kill the modules we already loaded, if they depend on the one that failed.
					IrxReference *pos = resModules;
					while (pos < curModule) {
						if ((pos->fileRef->flags & TYPEMASK) == (irxFiles[i].flags & TYPEMASK)) {
							free(pos->path);
							free(pos->buffer);

							IrxReference *copyPos = pos;
							while (copyPos < curModule) {
								copyPos[0] = copyPos[1];
								copyPos++;
							}
							curModule--;
						} else
							pos++;
					}
					// and skip any remaining modules that depend on the missing one, too.
					while ((i < numIrxFiles - 1) && ((irxFiles[i + 1].flags & TYPEMASK) == (curModule->fileRef->flags & TYPEMASK)))
						i++;
					// the module that actually failed (curModule) is kept in the array for displaying an error message
				}
				curModule->size = 0;
				curModule->buffer = NULL;
				curModule->argSize = 0;
				curModule->args = NULL;
			}
		}
		curModule++;
	}

	*modules = resModules;
	sioprintf("List of %d modules:\n", curModule - resModules);
	for (int i = 0; i < curModule - resModules; i++)
		sioprintf("%s\n", resModules[i].path);
	return curModule - resModules;
}
示例#15
0
int CreateSave(void)
{
	int mc_fd;
	int icon_fd,icon_size;
	char* icon_buffer;
	mcIcon icon_sys;

	static iconIVECTOR bgcolor[4] = {
		{  68,  23, 116,  0 }, // top left
		{ 255, 255, 255,  0 }, // top right
		{ 255, 255, 255,  0 }, // bottom left
		{  68,  23, 116,  0 }, // bottom right
	};

	static iconFVECTOR lightdir[3] = {
		{ 0.5, 0.5, 0.5, 0.0 },
		{ 0.0,-0.4,-0.1, 0.0 },
		{-0.5,-0.5, 0.5, 0.0 },
	};

	static iconFVECTOR lightcol[3] = {
		{ 0.3, 0.3, 0.3, 0.00 },
		{ 0.4, 0.4, 0.4, 0.00 },
		{ 0.5, 0.5, 0.5, 0.00 },
	};

	static iconFVECTOR ambient = { 0.50, 0.50, 0.50, 0.00 };


	if(fioMkdir("mc0:PS2DEV") < 0) return -1;

	// Set up icon.sys. This is the file which controls how our memory card save looks
	// in the PS2 browser screen. It contains info on the bg colour, lighting, save name
	// and icon filenames. Please note that the save name is sjis encoded.

	memset(&icon_sys, 0, sizeof(mcIcon));
	strcpy(icon_sys.head, "PS2D");
	strcpy_sjis((short *)&icon_sys.title, "Memcard Example\nPS2Dev r0x0rs");
	icon_sys.nlOffset = 16;
	icon_sys.trans = 0x60;
	memcpy(icon_sys.bgCol, bgcolor, sizeof(bgcolor));
	memcpy(icon_sys.lightDir, lightdir, sizeof(lightdir));
	memcpy(icon_sys.lightCol, lightcol, sizeof(lightcol));
	memcpy(icon_sys.lightAmbient, ambient, sizeof(ambient));
	strcpy(icon_sys.view, "ps2dev.icn"); // these filenames are relative to the directory
	strcpy(icon_sys.copy, "ps2dev.icn"); // in which icon.sys resides.
	strcpy(icon_sys.del, "ps2dev.icn");

	// Write icon.sys to the memory card (Note that this filename is fixed)
	mc_fd = fioOpen("mc0:PS2DEV/icon.sys",O_WRONLY | O_CREAT);
	if(mc_fd < 0) return -2;

	fioWrite(mc_fd, &icon_sys, sizeof(icon_sys));
	fioClose(mc_fd);
	printf("icon.sys written sucessfully.\n");

	// Write icon file to the memory card.
	// Note: The icon file was created with my bmp2icon tool, available for download at
	//       http://www.ps2dev.org
	icon_fd = fioOpen("host:ps2dev.icn",O_RDONLY);
	if(icon_fd < 0) return -3;

	icon_size = fioLseek(icon_fd,0,SEEK_END);
	fioLseek(icon_fd,0,SEEK_SET);

	icon_buffer = malloc(icon_size);
	if(icon_buffer == NULL) return -4;
	if(fioRead(icon_fd, icon_buffer, icon_size) != icon_size) return -5;
	fioClose(icon_fd);

	icon_fd = fioOpen("mc0:PS2DEV/ps2dev.icn",O_WRONLY | O_CREAT);
	if(icon_fd < 0) return -6;

	fioWrite(icon_fd,icon_buffer,icon_size);
	fioClose(icon_fd);
	printf("ps2dev.icn written sucessfully.\n");

	return 0;
}
示例#16
0
文件: fontx.c 项目: AKuHAK2/ps2sdk
int fontx_load_double_krom(fontx_t *fontx)
{

	fontx_hdr *fontx_header;

	int size;
	int fd = 0;

	// Font characteristics for double-byte font
	int header_size = 18;
	int table_num = 51;
	int table_size = 4;
	int char_size = 30;
	int char_num = 3489;

	fd = fioOpen("rom0:KROM", O_RDONLY);

	if (fd < 0)
	{

		printf("Error opening KROM font.\n");

	}

	size = header_size + table_num*table_size +  char_num*char_size;

	fontx->font = (char*)malloc(size);

	if (fontx->font == NULL)
	{

		printf("Error allocating memory.\n");
		fioClose(fd);

		return -1;
	}

	// Clear memory
	memset(fontx->font,0,size);

	// Make sure we're at the beginning
	fioLseek(fd, 0, SEEK_SET);

	// Read in 95 characters
	if (fioRead(fd, fontx->font+header_size+table_num*table_size, char_size*char_num) < 0)
	{

		printf("Error reading font.\n");
		free(fontx->font);
		fioClose(fd);

		return -1;

	}

	fioClose(fd);

	fontx_header = (fontx_hdr*)fontx->font;

	// define the header as double-byte font
	strncpy(fontx_header->id, "FONTX2", 6);
	fontx_header->id[6] = '\0';
	strncpy(fontx_header->name, "KROM", 8);
	fontx_header->name[8] = '\0';

	fontx_header->width = 16;
	fontx_header->height = 15;
	fontx_header->type = DOUBLE_BYTE;
	fontx_header->table_num = table_num;

	// Add the SJIS tables to the font
	memcpy(fontx->font+header_size,sjis_table,table_num*table_size);

	// Save it as a font
	//fd=fioOpen("host:KROM_kanji.fnt",O_WRONLY | O_TRUNC | O_CREAT);
	//fioWrite(fd, fontx->font, size);
	//fioClose(fd);

	return 0;

}
示例#17
0
文件: fontx.c 项目: AKuHAK2/ps2sdk
int fontx_load_single_krom(fontx_t *fontx)
{

	fontx_hdr *fontx_header;

	int header_size = 17;
	int char_size = 15;

	int fd = 0;
	int size;

	fd = fioOpen("rom0:KROM", O_RDONLY);

	if (fd < 0)
	{

		printf("Error opening KROM font.\n");
		return -1;

	}

	// header without table pointer + size of a character * 256 characters
	size = header_size + char_size * 256;

	fontx->font = (char*)malloc(size);

	if (fontx->font == NULL)
	{

		printf("Error allocating %d bytes of memory.\n", size);
		fioClose(fd);

		return -1;
	}

	// Clear the memory
	memset(fontx->font,0,size);

	// The offset for the ASCII characters
	fioLseek(fd, 0x198DE, SEEK_SET);

	// 17 bytes of header and 15 bytes per 33 characters
	// Read in 95 characters
	if (fioRead(fd,fontx->font + header_size+char_size*33, char_size*95) < 0)
	{

		printf("Error reading rom0:KROM.\n");

		free(fontx->font);
		fioClose(fd);

		return -1;

	}

	fioClose(fd);

	fontx_header = (fontx_hdr*)fontx->font;

	// define header as single-byte font
	strncpy(fontx_header->id, "FONTX2", 6);
	fontx_header->id[6] = '\0';
	strncpy(fontx_header->name, "KROM", 8);
	fontx_header->name[8] = '\0';

	fontx_header->width = 8;
	fontx_header->height = 15;
	fontx_header->type = SINGLE_BYTE;

	// Save it as a font
	//fd=fioOpen("host:KROM_ascii.fnt",O_WRONLY | O_TRUNC | O_CREAT);
	//fioWrite(fd, fontx->font, size);
	//fioClose(fd);

	return 0;

}
示例#18
0
文件: loader.c 项目: dyzz/hdldumb
int /* "192.168.0.10 255.255.255.0 192.168.0.1" */
setup_ip (const char *ipconfig_dat_path,
	  char outp [IPCONF_MAX_LEN], size_t *length)
{
  int result = 0;
  int conf_ok = 0;
#if defined (LOAD_SIOMAN_AND_MC)
  int fd = fioOpen (ipconfig_dat_path, O_RDONLY);
  if (!(fd < 0))
    { /* configuration file found */
      char tmp [IPCONF_MAX_LEN];
      int len = fioRead (fd, tmp, IPCONF_MAX_LEN - 1);
      fioClose (fd);

      if (len > 0)
	{
	  int data_ok = 1;
	  int i;
	  tmp [len] = '\0';
	  for (i=0; data_ok && i<len; ++i)
	    if (isdigit (tmp [i]) || tmp [i] == '.')
	      ;
	    else if (isspace (tmp [i]))
	      tmp [i] = '\0';
	    else
	      data_ok = 0;

	  if (data_ok)
	    {
	      memcpy (outp, tmp, IPCONF_MAX_LEN);
	      conf_ok = 1;
	      *length = len;
	    }
	  else
	    /* bad format */
	    result = -2;
	}
    }
  else
    /* not found */
    result = -1;
#endif /* LOAD_SIOMAN_AND_MC? */

  if (!conf_ok)
    { /* configuration file not found; use hard-coded defaults */
      int len, pos = 0;

      len = strlen (default_ip);
      memcpy (outp + pos, default_ip, len); pos += len;
      *(outp + pos++) = '\0';

      len = strlen (default_mask);
      memcpy (outp + pos, default_mask, len); pos += len;
      *(outp + pos++) = '\0';

      len = strlen (default_gateway);
      memcpy (outp + pos, default_gateway, len); pos += len;
      *(outp + pos++) = '\0';
      *length = pos;
    }

  return (result);
}
示例#19
0
文件: mpeg.c 项目: AzagraMac/PS2_SDK
int main ( void ) {
/* read file (or part of it ) into memory */
 PACKET      *lPck = malloc(sizeof(PACKET));
 QWORD       *q;
 FRAMEBUFFER frame;
 ZBUFFER z;
 InitCBParam lInfo;
 int         lFD = fioOpen ( MPEG_BITSTREAM_FILE, O_RDONLY );
 long        lSize;
 long        lPTS, lCurPTS;

 frame.width = 640;
 frame.height = 512;
 frame.mask = 0;
 frame.psm = GS_PSM_32;
 frame.address = graph_vram_allocate(frame.width,frame.height, frame.psm, GRAPH_ALIGN_PAGE);

 z.enable = 0;
 z.mask = 0;
 z.method = 0;
 z.zsm = 0;
 z.address = 0;

 packet_allocate(lPck, 100, 0, 0);

 if ( lFD < 0 ) {
  printf ( "test_mpeg: could not open '%s'\n", MPEG_BITSTREAM_FILE );
  goto end;
 }  /* end if */

 lSize = fioLseek ( lFD, 0, SEEK_END );
 fioLseek ( lFD, 0, SEEK_SET );

 if ( lSize <= 0 ) {
  printf ( "test_mpeg: could not obtain file size (%ld)\n", lSize );
  goto end;
 }  /* end if */

 s_pMPEGData = ( unsigned char* )malloc ( lSize = lSize > MAX_SIZE ? MAX_SIZE : lSize );

 if ( !s_pMPEGData ) {
  printf ( "test_mpeg: could not allocate enough memory (%ld)\n", lSize );
  goto end;
 }  /* end if */

 if (  fioRead (
        lFD, s_pTransferPtr = s_pMPEGData, s_MPEGDataSize = lSize
       ) != lSize
 ) {
  printf ( "test_mpeg: could not read file\n" );
  goto end;
 }  /* end if */

 fioClose ( lFD );

/* initialize DMAC (I have no idea what this code does as */
/* I'm not quite familiar with ps2sdk)                    */
 dma_channel_initialize ( DMA_CHANNEL_toIPU, NULL, 0 );
 dma_channel_initialize ( DMA_CHANNEL_GIF,   NULL, 0 );
 dma_channel_fast_waits( DMA_CHANNEL_GIF );

/* initialize graphics synthesizer */
 graph_initialize(0,640,512,GS_PSM_32,0,0);

/* setup texture buffer address just after the framebuffer */
 lInfo.m_TexAddr = graph_vram_allocate(0,0,GS_PSM_32,GRAPH_ALIGN_BLOCK);

 q = lPck->data;
 q = draw_setup_environment(q,0,&frame,&z);

/* clear screen */
 q = draw_clear(q,0,0,0,640.0f,512.0f,0,0,0);

 dma_channel_send_normal(DMA_CHANNEL_GIF, lPck->data, q - lPck->data, 0, 0);

/* now it's time to initialize MPEG decoder (though it can be   */
/* initialized any time). Just make sure that DMA transfers     */
/* to and from IPU (and DRAM -> SPR) are not active, otherwise  */
/* unpredicted things will happen. Initialization code is also  */
/* allocating some memory using 'memalign' function and no      */
/* check is performed whether the allocation was successful or  */
/* not, so, before calling this make sure that at least WxHx4x3 */
/* bytes are avaliable for dynamic allocation (possibly using   */
/* ps2_sbrk ( 0 ) call) where W and H are picture dimensions in */
/* units of pixels.                                             */
 MPEG_Initialize ( SetDMA, NULL, InitCB, &lInfo, &lCurPTS );
/* during decoding scratchpad RAM from address 0x0000 to 0x3C00 */
/* is used by the decoder.                                      */
/* let's go                                                     */
 while ( 1 ) {
/* try decode picture into "lInfo.m_pData" area. It's allowed     */
/* to supply different area each time, just make sure that        */
/* there're no conflicts with data cache, as decoder doesn't do   */
/* anything to synchronize/flush/invalidate data cache.           */
/* RGB -> YUV colorspace conversion is pefromed automatically     */
/* using interrupt hahdler/semaphore, so, multithreaded           */
/* application can benefit from it. Usage of IPU and DMA channels */
/* to/from IPU and DRAM -> SPR is strictly forbidden during       */
/* decoding :).                                                   */
  if (  !MPEG_Picture ( lInfo.m_pData, &lPTS )  ) {
/* MPEG_Picture returns nonzero if the picture was successfully */
/* decoded. Zero return means one of the following:             */
/* - end of stream was detected (SetDMA function returned zero) */
/* - MPEG sequence end code (0x000001B7) was detected           */
/* this test just finishes in both cases                        */
   if ( lInfo.m_pInfo -> m_fEOF  ) break;
/* ...instead of 'break' we can continue to the next sequence...*/
/* ...but I'm too lazy to handle second call of 'InitCB' :D     */
   else break;
  }  /* end if */
/* now transfer decoded picture data into texture area of GS RAM */
  dma_wait_fast();
  dma_channel_send_chain( DMA_CHANNEL_GIF, lInfo.m_XFerPck.data, lInfo.m_XFerPck.qwc, 0, 0);
/* wait for vsync 2 times (we have interlaced frame mode)  */
  graph_wait_vsync ();
  graph_wait_vsync ();
/* no need to wait for DMA transfer completion since vsyncs above */
/* have enough lattency...                                        */
/* ...and finally draw decoded picture...                         */
  dma_channel_send_normal( DMA_CHANNEL_GIF, lInfo.m_DrawPck.data, lInfo.m_DrawPck.qwc, 0, 0);
/* ...and go back for the next one */
 }  /* end while */
/* free memory and other resources */
 MPEG_Destroy ();

end:
 printf ( "test_mpeg: test finished\n" );
 return SleepThread (), 0;

}  /* end main */
示例#20
0
static tsize_t
_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
{
	return ((tsize_t) fioRead((int) fd, buf, (size_t) size));
}
示例#21
0
int load_rom(char *filename)
{
    
     unsigned long file_length;
      int fd,fd_size;  
      int n;	
      int ret = 0;
      int ok=0;
      char tmpnom[0x100];    
  
 if(check_zip(filename))
    { 
        unzFile fd2=unzOpen(filename);        
         
        if(fd2==NULL)return (1);
                
        // Go to first file in archive 
        ret = unzGoToFirstFile(fd2);
        if(ret != UNZ_OK) {
            unzClose(fd2);
            return (1);
        }
        // Get information on the file 
        ret = unzGetCurrentFileInfo(fd2, &info, tmpnom, 0x100, NULL, 0, NULL, 0);
        if(ret != UNZ_OK) {
            unzClose(fd2);
            return (1);
        }
      
        //Open the file for reading 
        ret = unzOpenCurrentFile(fd2);
        if(ret != UNZ_OK) {
            unzClose(fd2);
            return (1);
        }       
        // Allocate file data buffer 
        fd_size = info.uncompressed_size;
       
        // Read (decompress) the file 
       // cartridge_rom = (unsigned char *)malloc(fd_size);
        cartridge_rom = (u8 *)memalign(64, fd_size);
        ret = unzReadCurrentFile(fd2,/*(char *)*/cartridge_rom, info.uncompressed_size);
        if(ret != info.uncompressed_size)
        {
            //free(buf2);
            unzCloseCurrentFile(fd2);
            unzClose(fd2);
            return (1);
        }
        //printf("zip decomp %d \n",(int)info.uncompressed_size);

        // Close the current file 
        ret = unzCloseCurrentFile(fd2);
        if(ret != UNZ_OK) {           
            unzClose(fd2);
            return (1);
        }
        // printf("zip close file\n");

        // Close the archive 
        ret = unzClose(fd2);
        if(ret != UNZ_OK) {            
            return (1);
        }
        // printf("zip close archive\n");

    // Check for 512-byte header    
   // ok=0;
   // cartridge_rom = (unsigned char *)malloc(fd_size);
   // for(n = 0; n <fd_size;n++)cartridge_rom[n]=buf[n+ok];  
    printf("zip header / rom copy %d %d %s \n",fd_size,ok,tmpnom);
    
 } 
 else{
  
   fd = fioOpen(filename, O_RDONLY);
   if(fd <= 0) {
	//	display_error("Error opening file.",0);
      printf("%s not found.\n",filename);
		return 0;
	}
 
	file_length = fioLseek(fd,0,SEEK_END);
	fioLseek(fd,0,SEEK_SET);

    cartridge_rom = (unsigned char *)malloc(file_length);
	fioRead(fd, (char *)cartridge_rom, file_length);

    fioClose(fd);
    
 }
 
 // traitement du fich rom ....
 
 return 0; 
 
 }