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; }
//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; }