//Lit un fichier entier vers la mémoire
void *oslReadEntireFileToMemory(VIRTUAL_FILE *f, int *fileSize)		{
   void *block = NULL;
   int add = 0;
   int size = 0, readSize, finalSize = 0;
   
   do		{
      size += BLOCK_SIZE;
      if (block)
		   block = realloc(block, size);
      else
		   block = malloc(size);

		//L'allocation a échoué?
		if (!block)
			return NULL;

      readSize = VirtualFileRead((char*)block + add, 1, BLOCK_SIZE, f);
	   add += BLOCK_SIZE;
	   finalSize += readSize;
   } while (readSize >= BLOCK_SIZE);
   
   if (fileSize)
   	*fileSize = finalSize;
   return block;
}
int vfsMemGetc(VIRTUAL_FILE *f)		{
	unsigned char car;
	//Pour la sécurité, quand même un cas à part pour les fichiers
	if (VirtualFileRead(&car, sizeof(car), 1, f) < 1)
		return -1;
	else
		return (int)car;
}
Esempio n. 3
0
int fnGifReadFunc(GifFileType* GifFile, GifByteType* buf, int count)
{
/*    char* ptr = (char*)GifFile->UserData;
    memcpy(buf, ptr, count);
    GifFile->UserData = ptr + count;*/
    VirtualFileRead(buf, 1, count, (VIRTUAL_FILE*)GifFile->UserData);

    return count;
}
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;
}
Esempio n. 5
0
File: SMS.c Progetto: wally4000/code
int gb_load_sram(VIRTUAL_FILE *fd, byte *buf, int bufsize)
{
	memset(buf, 0, bufsize);
	
	int ramsize = VirtualFileRead(buf, 1, bufsize, fd);
	if(ramsize & 4)
		renderer_set_timer_state(*(int*)(buf+ramsize-4));

	return ramsize;
}
Esempio n. 6
0
OSL_FONT *oslLoadFontFile(const char *filename)		{
	OSL_FONTINFO fi;
	OSL_FONT_FORMAT_HEADER fh;
	VIRTUAL_FILE *f;
	OSL_FONT *font = NULL;
	unsigned char tcTaillesCar[256], *tcCaracteres;

    char *start = (char *)filename + (strlen(filename) - 4);
    char *bwfon = (char *)filename + (strlen(filename) - 6);			//<-- STAS: BWFON intrafont support
    if (!strncmp(start, ".pgf", 4)   || !strncmp(start, ".PGF", 4) ||
        !strncmp(bwfon, ".bwfon", 6) || !strncmp(bwfon, ".BWFON", 6)) {
        font = oslLoadIntraFontFile(filename, intra_options);
    }else{
        f = VirtualFileOpen((void*)filename, 0, VF_AUTO, VF_O_READ);
        if (f)			{
            //Lit l'en-tête de la fonte
            VirtualFileRead(&fh, sizeof(fh), 1, f);
            //Vérifie l'en-tête
            if (!strcmp(fh.strVersion, "OSLFont v01"))		{
                fi.pixelFormat = fh.pixelFormat;
                //VERIFIER 1 <= PIXELFORMAT <= 4
                if (fh.variableWidth)		{
                    VirtualFileRead(tcTaillesCar, 256 * sizeof(unsigned char), 1, f);
                    fi.charWidths = tcTaillesCar;
                }
                else
                    fi.charWidths = NULL;
                fi.charWidth = fh.charWidth;
                fi.charHeight = fh.charHeight;
                fi.lineWidth = fh.lineWidth;
                fi.addedSpace = fh.addedSpace;
                //Lit les données des caractères
                tcCaracteres = (u8*)malloc(fh.lineWidth*fi.charHeight*256);
				if (!tcCaracteres)
					return NULL;
                if (VirtualFileRead(tcCaracteres, fh.lineWidth*fi.charHeight*256, 1, f) > 0)			{
                    fi.fontdata = tcCaracteres;
                    fi.paletteCount = fh.paletteCount;
                    fi.paletteData = NULL;
                    //Est-ce qu'il reste encore des couleurs à charger?
                    if (fi.paletteCount > 0)			{
                        fi.paletteData = (unsigned long*)malloc(fi.paletteCount * sizeof(unsigned long));
                        if (fi.paletteData)			{
                            //Lit les entrées de palette
                            if (VirtualFileRead(fi.paletteData, fi.paletteCount * sizeof(unsigned long), 1, f) == 0)			{
                                //Do not use these entries as they were not read correctly
                                fi.paletteCount = 0;
                            }
                        }
                    }
                    //On peut finalement la charger
                    font = oslLoadFont(&fi);
                    if (fi.paletteData){
                        free(fi.paletteData);
                        fi.paletteData = NULL;
                    }
                }
                free(tcCaracteres);
            }
            VirtualFileClose(f);
        }
        if (!font)
            oslHandleLoadNoFailError(filename);
        else
            font->fontType = OSL_FONT_OFT;
    }
	return font;
}
Esempio n. 7
0
File: SMS.c Progetto: wally4000/code
//force: 1 to always write, 0 to only if changed
int machine_manage_sram(int mode, int force)			{
    char name[MAX_PATH];
    VIRTUAL_FILE *fd;
	int ramsize = 0;

	if(menuConfig.file.filename[0] == '\0')
		return;

	pspGetStateName(name, STATE_SRAM);

    switch(mode)
    {
        case SRAM_SAVE:
			if (gblMachineType == EM_SMS)			{
				//Find out if something was written to the SRAM (which is zero initialized)
/*				int i, modified = 0;
				for (i=0;i<0x8000;i++)		{
					if (((u8*)cart.sram)[i] != 0)
						modified = 1;
				}
				if (!modified)
					break;*/

				//Determine if something has changed (using the CRC)
				uLong crc = crc32(0L, Z_NULL, 0);
				crc = crc32(crc, cart.sram, 0x8000);
				if (sram_crc == crc)
					break;

				sram_crc = crc;
			}
			else if (gblMachineType == EM_GBC)		{
				if (!(rom_get_loaded() && rom_has_battery()))
					break;

				//Determine if something has changed (using the CRC)
				const int sram_tbl[]={1,1,1,4,16,8};
				int sram_size = 0x2000 * sram_tbl[rom_get_info()->ram_size];

				if (rom_get_info()->cart_type>=0x0f && rom_get_info()->cart_type<=0x13)			{
					int tmp = renderer_get_timer_state();
					memcpy(get_sram() + sram_size, &tmp, sizeof(int));
					sram_size += sizeof(int);
				}

				uLong crc = crc32(0L, Z_NULL, 0);
				crc = crc32(crc, get_sram(), sram_size);

				if (sram_crc == crc)
					break;

				sram_crc = crc;
			}

			if (BatteryWarning("Your battery is low!\nDo you want to save the SRAM contents?\n(This might corrupt your Memory Stick if your PSP stops during this operation.)"))			{
				fd = VirtualFileOpen(name, 0, VF_GZFILE, VF_O_WRITE);
				if (fd)
				{
					if (gblMachineType == EM_SMS)
						VirtualFileWrite(cart.sram, 0x8000, 1, fd);
					else if (gblMachineType == EM_GBC)
						gb_save_sram(fd, get_sram(), rom_get_info()->ram_size);
					VirtualFileClose(fd);
				}
			}
            break;

        case SRAM_LOAD:
            fd = VirtualFileOpen(name, 0, VF_GZFILE, VF_O_READ);
			if (gblMachineType == EM_SMS)			{
				if(fd)			{
					sms.save = 1;
					VirtualFileRead(cart.sram, 0x8000, 1, fd);
					ramsize = 0x8000;
				}
				else
					/* No SRAM file, so initialize memory */
					memset(cart.sram, 0x00, 0x8000);

				sram_crc = crc32(0L, Z_NULL, 0);
				sram_crc = crc32(sram_crc, cart.sram, 0x8000);
			}
			else if (gblMachineType == EM_GBC)		{
				if (fd)
					ramsize = gb_load_sram(fd, sram_space, sizeof(sram_space));

				sram_crc = crc32(0L, Z_NULL, 0);
				sram_crc = crc32(sram_crc, sram_space, ramsize);
			}
			if (fd)
				VirtualFileClose(fd);
            break;
    }
	return ramsize;
}