Example #1
0
static bool render_font_create_temporaryfile(render_font &font, const char *filename)
{
	total_numchars = 0;
	m_chartable.clear();

	core_file *file;
	astring tmp_filename(filename, ".tmp");
	file_error filerr = core_fopen(tmp_filename.cstr(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
	if (filerr != FILERR_NONE)
		return true;
	core_fclose(file);

	return false;
}
Example #2
0
inline bool semaphore_unlink(const char *semname)
{
   try{
      std::string sem_str;
      #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
      add_leading_slash(semname, sem_str);
      #else
      tmp_filename(semname, sem_str);
      #endif
      return 0 == sem_unlink(sem_str.c_str());
   }
   catch(...){
      return false;
   }
}
Example #3
0
inline void create_tmp_and_clean_old_and_get_filename(const char *filename, std::string &tmp_name)
{
   create_tmp_and_clean_old(tmp_name);
   tmp_filename(filename, tmp_name);
}
/*===========================================================================*/
static bool sortFwBinfileOrder(std::vector<std::string> & filenames)
{
    int bin_files_num = filenames.size();
    int slave_num = 0;
    int multichip_selective_id = 0;
    int num_master_cnt = 0;

    std::vector<int> chip_order(0);

    chip_order.clear();

    for (int idx = 0; idx < bin_files_num; idx++) {
        FILE *fp = NULL;

        if ((fp = fopen(filenames[idx].c_str(), "rb")) != NULL) {

#           define MULTICHIP_SELECTIVE_ID_ADDR (0xc027)
            if (0!=fseek(fp, MULTICHIP_SELECTIVE_ID_ADDR, SEEK_SET)) {
                printf( "file %s is not correct sis firmware file\n", filenames[idx].c_str() );
                return false;
            }
#           undef MULTICHIP_SELECTIVE_ID_ADDR
            multichip_selective_id = fgetc(fp);

            switch (multichip_selective_id) {
                case ID_INVALID:
                    printf( "%s: old firmware, cannot check multi-chip relation\n", filenames[idx].c_str() );
                    return false;
                    break;

                case ID_NONE:
                    printf( "%s: single chip firmware\n", filenames[idx].c_str() );
                    chip_order.push_back(multichip_selective_id);
                    break;

                case ID_MASTER:
                case ID_BRIDGE:
                    chip_order.push_back(0);
                    slave_num = fgetc(fp);
                    num_master_cnt++;
                    break;

                case 0x5:
                case 0x6:
                case 0x7:
                case 0x8:
                case 0x9:
                case 0xa:
                    chip_order.push_back(multichip_selective_id-4);
                    break;

                default:
                    printf( "%s: FW format error, slave id of FW = %d\n", filenames[idx].c_str(), multichip_selective_id);
                    return false;
                    break;
            }
        } else {
            fprintf(stderr, "can't open file ");
            perror(filenames[idx].c_str());
            exit(-1);
        }

        fclose(fp);
    }

    if (multichip_selective_id==ID_SINGLE) {
        return true;
    }

    // false if more than one master fw bin file
    if (num_master_cnt>1) {
        printf( "number of master FW = %d > 1\n", num_master_cnt);
        return false;
    }

    // only update master

    if ((num_master_cnt==1)&&(chip_order.size()==1)) {
        return true;
    }


    std::vector<std::string> tmp_filename(filenames);

    if ((chip_order.size()!=0)&&(slave_num==0)) {
        printf( "number of FW file doesn't not match\n");
        return false;
    }

    if (slave_num!=(bin_files_num-1)) {
	    printf( "number of FW file doesn't not match\n");
	    return false;
    }
    // sort chip order to Master->Slave0->...->SlaveN
    for (int idx = 0; idx < bin_files_num; idx++) {
        filenames[chip_order[idx]] = tmp_filename[idx];
    }

    return true;
}
Example #5
0
static bool render_font_save_cached(render_font &font, const char *filename, UINT32 hash)
{
	// attempt to open the file
	core_file *file;
	file_error filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
	if (filerr != FILERR_NONE)
		return true;
	core_file *tmp_file;
	astring tmp_filename(filename, ".tmp");
	filerr = core_fopen(tmp_filename.cstr(), OPEN_FLAG_WRITE | OPEN_FLAG_READ, &tmp_file);
	if (filerr != FILERR_NONE)
		return true;
	core_fseek(tmp_file, 0, SEEK_END);

	try
	{
		// determine the number of characters
		int numchars = 0;
		for (int chnum = 0; chnum < 65536; chnum++)
			if (font.chars[chnum].width > 0)
				numchars++;
		total_numchars += numchars;

		// write the header
		dynamic_buffer tempbuffer(65536);
		UINT8 *dest = &tempbuffer[0];
		*dest++ = 'f';
		*dest++ = 'o';
		*dest++ = 'n';
		*dest++ = 't';
		*dest++ = hash >> 24;
		*dest++ = hash >> 16;
		*dest++ = hash >> 8;
		*dest++ = hash & 0xff;
		*dest++ = font.height >> 8;
		*dest++ = font.height & 0xff;
		*dest++ = font.yoffs >> 8;
		*dest++ = font.yoffs & 0xff;
		*dest++ = total_numchars >> 24;
		*dest++ = total_numchars >> 16;
		*dest++ = total_numchars >> 8;
		*dest++ = total_numchars & 0xff;
		write_data(*file, tempbuffer, dest);

		// write the empty table to the beginning of the file
		//m_chartable.resize_keep(total_numchars * CACHED_CHAR_SIZE + 1);
		//write_data(*file, &m_chartable[0], &m_chartable[total_numchars * CACHED_CHAR_SIZE]);

		// loop over all characters
		int tableindex = total_numchars - numchars;
		for (int chnum = 0; chnum < 65536; chnum++)
		{
			render_font_char &ch = font.chars[chnum];
			if (ch.width > 0)
			{
				// write out a bit-compressed bitmap if we have one
				if (ch.bitmap != NULL)
				{
					// write the data to the tempbuffer
					dest = tempbuffer;
					UINT8 accum = 0;
					UINT8 accbit = 7;

					// bit-encode the character data
					for (int y = 0; y < ch.bmheight; y++)
					{
						int desty = y + font.height + font.yoffs - ch.yoffs - ch.bmheight;
						const UINT32 *src = (desty >= 0 && desty < font.height) ? &ch.bitmap->pix32(desty) : NULL;
						for (int x = 0; x < ch.bmwidth; x++)
						{
							if (src != NULL && src[x] != 0)
								accum |= 1 << accbit;
							if (accbit-- == 0)
							{
								*dest++ = accum;
								accum = 0;
								accbit = 7;
							}
						}
					}

					// flush any extra
					if (accbit != 7)
						*dest++ = accum;

					// write the data
					write_data(*tmp_file, tempbuffer, dest);

					// free the bitmap and texture
					global_free(ch.bitmap);
					ch.bitmap = NULL;
				}

				// compute the table entry
				dest = &m_chartable[tableindex++ * CACHED_CHAR_SIZE];
				*dest++ = chnum >> 8;
				*dest++ = chnum & 0xff;
				*dest++ = ch.width >> 8;
				*dest++ = ch.width & 0xff;
				*dest++ = ch.xoffs >> 8;
				*dest++ = ch.xoffs & 0xff;
				*dest++ = ch.yoffs >> 8;
				*dest++ = ch.yoffs & 0xff;
				*dest++ = ch.bmwidth >> 8;
				*dest++ = ch.bmwidth & 0xff;
				*dest++ = ch.bmheight >> 8;
				*dest++ = ch.bmheight & 0xff;

				ch.width = 0;
			}
		}

		// seek back to the beginning and rewrite the table
		core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET);
		write_data(*file, &m_chartable[0], &m_chartable[total_numchars * CACHED_CHAR_SIZE]);

		// mamep:copy from temporary file
		UINT32 filesize = (UINT32)core_fsize(tmp_file);
		tempbuffer.resize(filesize);
		tempbuffer.clear();
		core_fseek(tmp_file, 0, SEEK_SET);
		core_fread(tmp_file, tempbuffer, filesize);
		core_fwrite(file, tempbuffer, filesize);

		// all done
		core_fclose(file);
		core_fclose(tmp_file);
		return false;
	}
	catch (...)
	{
		core_fclose(file);
		core_fclose(tmp_file);
		osd_rmfile(filename);
		osd_rmfile(tmp_filename.cstr());
		return true;
	}
}