void vfsMemSeek(VIRTUAL_FILE *f, int offset, int whence)		{
//	int oldOffset = f->offset;
	if (f->ioPtr)		{
		if (whence == SEEK_SET)
			f->offset = offset;
		else if (whence == SEEK_CUR)
			f->offset += offset;
		else if (whence == SEEK_END)
			f->offset = f->maxSize + offset;
		f->offset = oslMax(oslMin(f->offset, f->maxSize), 0);
	}
//	return oldOffset;
}
int vfsMemWrite(const void *ptr, size_t size, size_t n, VIRTUAL_FILE* f)			{
	int realSize = size * n, writeSize = 0;
	if (f->ioPtr)		{
		//Débordement?
		writeSize = oslMin(realSize, f->maxSize - f->offset);
		if (writeSize > 0)		{
			memcpy((char*)f->ioPtr + f->offset, ptr, writeSize);
			//Brunni: ??? this is probably wrong ??? (08.07.2007)
//			f->offset += realSize;
			f->offset += writeSize;
		}
	}
	return writeSize;
}
int vfsMemRead(void *ptr, size_t size, size_t n, VIRTUAL_FILE* f)			{
	int readSize = 0, realSize = size * n;

	if (f->ioPtr)		{
		//min => pour éviter les débordements
		readSize = oslMin(realSize, f->maxSize - f->offset);
		if (readSize > 0)		{
			memcpy(ptr, (char*)f->ioPtr + f->offset, readSize);
			//Brunni: Removed (08.07.2007)
//			f->offset += realSize;
			f->offset += readSize;
		}
	}
	return readSize;
}
char *vfsMemGets(char *str, int maxLen, VIRTUAL_FILE *f)			{
	const int blockSize = 16;
	int offset = 0, i, size;
	while(1)			{
		size = VirtualFileRead(str + offset, 1, oslMin(maxLen - offset, blockSize), f);
		if (offset + size < maxLen)
			str[offset + size] = 0;
		for (i=offset;i<offset+blockSize;i++)		{
			if (str[i] == 0)
				return str;
			//\r\n (Windows)
			if (str[i] == '\r')			{
				str[i] = 0;
				//Dernier bloc de la liste?
				if (i + 1 >= offset + blockSize)			{
					char temp[1];
					int tempSize;
					tempSize = VirtualFileRead(temp, 1, 1, f);
					//Prochain caractère est un \n?
					if (!(tempSize > 0 && temp[0] == '\n'))
						//Sinon on annule
						i--;
				}
				else	{
					if (str[i + 1] == '\n')
						i++;
				}
				//Retourne le pointeur
				VirtualFileSeek(f, -size + (i - offset) + 1, SEEK_CUR);
				return str;
			}
			else if (str[i] == '\n')			{
				str[i] = 0;
				//ATTENTION: MODIFIE DE -blockSize + i à -blockSize + i + 1, à vérifier!!!
				VirtualFileSeek(f, -blockSize + i + 1, SEEK_CUR);
				//Retourne le pointeur
				return str;
			}
		}
		offset += blockSize;
	}
	return str;
}
Exemple #5
0
OSL_FONT *oslLoadFont(OSL_FONTINFO *fi)
{
	OSL_FONT *f;
	int i, x, y;
	int imageFormat;
	const int pixelplanewidth[4]={3, 2, 2, 1};

	f = (OSL_FONT*)malloc(sizeof(OSL_FONT));
	if (!f)
		return NULL;
	memset(f, 0, sizeof(OSL_FONT));					//<-- STAS: Initialize the OSL_FONT structure

    f->fontType = OSL_FONT_OFT;

	//Liste des tailles
	f->charWidths = (u8*)malloc(256*sizeof(char));
	if (!f->charWidths)		{
		free(f);
		return NULL;
	}
	if (fi->charWidths)		{
		//Réutilise les tailles fournies
		for (i=0;i<256;i++)
			f->charWidths[i] = fi->charWidths[i];
//		f->charWidths = fi->charWidths;
		f->isCharWidthConstant = 0;
	}
	else		{
		//Remplit la table avec les mêmes tailles
		for (i=0;i<256;i++)
			f->charWidths[i] = fi->charWidth;
		f->isCharWidthConstant = 1;
		f->charWidth = fi->charWidth;				//<-- STAS: Initialize f->charWidth somehow...
	}
	//Position des caractères (pour les fontes non proportionnelles)
	f->charPositions = (u16*)malloc(256*sizeof(short));
	if (!f->charPositions)		{
		free(f->charWidths);
		free(f);
		return NULL;
	}
	f->addedSpace = fi->addedSpace;
	x = y = 0;
	for (i=0;i<256;i++)
	{
		if (x + f->charWidths[i] + f->addedSpace >= OSL_TEXT_TEXWIDTH)			{
			//Prochaine ligne
			x = 0;
			y ++;
		}
		f->charPositions[i] = x + (y<<OSL_TEXT_TEXDECAL);
		x += f->charWidths[i] + f->addedSpace;
	}

	//16x16 caractères
	f->img = oslCreateImage(512, (y+1)*fi->charHeight, OSL_IN_RAM, OSL_PF_4BIT);
	//4 bit texture format
	imageFormat = 4;
	if (!f->img)		{
		free(f->charPositions);
		free(f->charWidths);
		free(f);
		return NULL;
	}
	//La palette
	f->img->palette = oslCreatePalette(16, OSL_PF_8888);
	if (!f->img->palette)		{
		oslDeleteImage(f->img);					//<-- STAS: It would beter to do it before free(f) :-)
		free(f->charPositions);
		free(f->charWidths);
		free(f);
		return NULL;
	}

	if (fi->paletteCount)		{
		for (i=0;i<oslMin(fi->paletteCount,f->img->palette->nElements);i++)		//<-- STAS: check i against oslMin(...) !
			((unsigned long*)f->img->palette->data)[i] = fi->paletteData[i];
	}
	else	{
		((unsigned long*)f->img->palette->data)[0] = RGBA(255,255,255, 0);
		((unsigned long*)f->img->palette->data)[1] = RGBA(255,255,255, 255);
	}

	//Vide directement le cache
	sceKernelDcacheWritebackInvalidateRange(f->img->palette->data, 16*4);

	f->charHeight = fi->charHeight;
	memset(f->img->data, 0, f->img->totalSize);
	//Dessine les caractères sur le buffer
	for (i=0;i<256;i++)		{
		oslDrawChar1BitToImage(f->img, OSL_TEXT_CHARPOSXY(f, i),
			f->charWidths[i] + f->addedSpace, f->charHeight, fi->lineWidth << pixelplanewidth[fi->pixelFormat - 1],
			fi->pixelFormat, imageFormat, (u8*)fi->fontdata+i*fi->lineWidth*fi->charHeight);
	}
	//Pareil, vide direct le cache
	sceKernelDcacheWritebackInvalidateRange(f->img->data, f->img->totalSize);
	return f;
}