Пример #1
0
// ---------------------------------------------------------------------------
//	スナップショット保存
//
bool WinCore::SaveShapshot(const char* filename)
{
	LockObj lock(this);

	bool docomp = !!(config.flag2 & Config::compresssnapshot);

	uint size = devlist.GetStatusSize();
	uint8* buf = new uint8[docomp ? size * 129 / 64 + 20 : size];
	if (!buf)
		return false;
	memset(buf, 0, size);

	if (devlist.SaveStatus(buf))
	{
		ulong esize = size * 129 / 64 + 20-4;
		if (docomp)
		{
			if (Z_OK != compress(buf+size+4, &esize, buf, size))
			{
				delete[] buf;
				return false;
			}
			*(int32*) (buf+size) = -(long)esize;
			esize += 4;
		}

		SnapshotHeader ssh;
		memcpy(ssh.id, SNAPSHOT_ID, 16);

		ssh.major = ssmajor;
		ssh.minor = ssminor;
		ssh.datasize = size;
		ssh.basicmode = config.basicmode;
		ssh.clock = int16(config.clock);
		ssh.erambanks = uint16(config.erambanks);
		ssh.cpumode = int16(config.cpumode);
		ssh.mainsubratio = int16(config.mainsubratio);
		ssh.flags = config.flags | (esize < size ? 0x80000000 : 0);
		ssh.flag2 = config.flag2;
		for (uint i=0; i<2; i++)
			ssh.disk[i] = (int8) diskmgr->GetCurrentDisk(i);

		FileIO file;
		if (file.Open(filename, FileIO::create))
		{
			file.Write(&ssh, sizeof(ssh));
			if (esize < size)
				file.Write(buf+size, esize);
			else
				file.Write(buf, size);
		}
	}
	delete[] buf;
	return true;
}
Пример #2
0
/**
 * Loads a saved board from a file
 *
 * @param fname
 *  Name of the file to load
 * @return
 *  True if saved board is found and successfully loaded
 */
bool Board::Import(const string & fname) {
    FileIO file;

    file.SetFileName(fname);
    file.Open();
    FILEIO_TABLE table = file.GetTable();

    if (table.size() == 9) {
        FILEIO_TABLE::iterator tableIt = table.begin();
        FILEIO_ROW::iterator rowIt = tableIt->begin();

        for (int i = 0; i < 9; ++i) {
            for (int j = 0; j < 9; ++j) { // Read a row from the table
                m_board[j][i] = atoi(rowIt->c_str());
                rowIt++;
            }
            tableIt++;
            rowIt = tableIt->begin();
        }
        return true;
    }
    else
        return false;
}
Пример #3
0
// ---------------------------------------------------------------------------
//	スナップショット復元
//
bool WinCore::LoadShapshot(const char* filename, const char* diskname)
{
	LockObj lock(this);

	FileIO file;
	if (!file.Open(filename, FileIO::readonly))
		return false;

	SnapshotHeader ssh;
	if (file.Read(&ssh, sizeof(ssh)) != sizeof(ssh))
		return false;
	if (memcmp(ssh.id, SNAPSHOT_ID, 16))
		return false;
	if (ssh.major != ssmajor || ssh.minor > ssminor)
		return false;

	// applyconfig
	const uint fl1a = Config::subcpucontrol | Config::fullspeed 
					| Config::enableopna	| Config::enablepcg
					| Config::fv15k 		| Config::cpuburst 
					| Config::cpuclockmode	| Config::digitalpalette
					| Config::opnona8		| Config::opnaona8
					| Config::enablewait;
	const uint fl2a = Config::disableopn44;

	config.flags = (config.flags & ~fl1a) | (ssh.flags & fl1a);
	config.flag2 = (config.flag2 & ~fl2a) | (ssh.flag2 & fl2a);
	config.basicmode = ssh.basicmode;
	config.clock = ssh.clock;
	config.erambanks = ssh.erambanks;
	config.cpumode = ssh.cpumode;
	config.mainsubratio = ssh.mainsubratio;
	ApplyConfig(&config);
	
	// Reset
	PC88::Reset();

	// 読み込み

	uint8* buf = new uint8[ssh.datasize];
	bool r = false;

	if (buf)
	{
		bool read = false;
		if (ssh.flags & 0x80000000)
		{
			int32 csize;
			
			file.Read(&csize, 4);
			if (csize < 0)
			{
				csize = -csize;
				uint8* cbuf = new uint8[csize];
				
				if (cbuf)
				{
					ulong bufsize = ssh.datasize;
					file.Read(cbuf, csize);
					read = uncompress(buf, &bufsize, cbuf, csize) == Z_OK; 

					delete[] cbuf;
				}
			}
		}
		else
			read = file.Read(buf, ssh.datasize) == ssh.datasize;

		if (read)
		{
			r = devlist.LoadStatus(buf);
			if (r && diskname)
			{
				for (uint i=0; i<2; i++)
				{
					diskmgr->Unmount(i);
					diskmgr->Mount(i, diskname, false, ssh.disk[i], false);
				}
			}
			if (!r)
			{
				statusdisplay.Show(70, 3000, "バージョンが異なります");
				PC88::Reset();
			}
		}
		delete[] buf;
	}
	return r;
}
Пример #4
0
	/**
	* liest aus der betreffenden Datei die Gewichte raus,
	* falls diese nicht existiert wird eine Datei mit Startwerten erzeugt
	*/
	void CFunction::setInputs()
	{
		if(function == STEER)
		{
			char* dat = "steer.ai";
			FileIO* fIO = new FileIO();
	
			if(FUNCTION_NEW || !fIO->Open(dat, FILE_READ_MODE))
			{
			//	printf("\n###   make highsteer.ai\n");
				fIO->Open(dat, FILE_WRITE_MODE);
				fIO->PushHeader("steer");
				steer[0] = 0.f;
				steer[1] = 4.f;
				steer[2] = 0.f;
				fIO->PushRecord(steer, sizeof(float)*3);
			}
			else
			{
				//printf("\n###   read highsteer.ai\n");
				fIO->Open(dat, FILE_READ_MODE);
	
				fIO->GotoHeader("steer");
				fIO->PopRecord(steer);
			}
			//Test
			/*
			printf("steer[0]=%f  [1]=%f  [2]=%f\n",steer[0],steer[1],steer[2]);
			*/
		}
		
		if(function == HIGHSTEER)
		{
			char* dat = "highsteer.ai";
			FileIO* fIO = new FileIO();
	
			if(FUNCTION_NEW || !fIO->Open(dat, FILE_READ_MODE))
			{
			//	printf("\n###   make highsteer.ai\n");
				fIO->Open(dat, FILE_WRITE_MODE);
				fIO->PushHeader("highsteerAnd11");
				highsteerAnd11[0] = -1.f;
				highsteerAnd11[1] = 1.f;
				highsteerAnd11[2] = 1.f;
				fIO->PushRecord(highsteerAnd11, sizeof(float)*3);
	
				fIO->PushHeader("highsteerAndnot12");
				highsteerAndnot12[0] = 0.f;
				highsteerAndnot12[1] = 2.f;
				highsteerAndnot12[2] = -1.f;
				fIO->PushRecord(highsteerAndnot12, sizeof(float)*3);
	
				fIO->PushHeader("highsteerOr21");
				highsteerOr21[0] = 0.f;
				highsteerOr21[1] = 3.f;
				highsteerOr21[2] = 3.f;
				fIO->PushRecord(highsteerOr21, sizeof(float)*3);
			}
			else
			{
				//printf("\n###   read highsteer.ai\n");
				fIO->Open(dat, FILE_READ_MODE);
	
				fIO->GotoHeader("highsteerAnd11");
				fIO->PopRecord(highsteerAnd11);
	
				fIO->GotoHeader("highsteerAndnot12");
				fIO->PopRecord(highsteerAndnot12);
	
				fIO->GotoHeader("highsteerOr21");
				fIO->PopRecord(highsteerOr21);
			}
			//Test
			/*
			printf("highsteerAnd[0]=%f  [1]=%f  [2]=%f\n",highsteerAnd11[0],highsteerAnd11[1],highsteerAnd11[2]);
			printf("highsteerAndnot[0]=%f  [1]=%f  [2]=%f\n",highsteerAndnot12[0],highsteerAndnot12[1],highsteerAndnot12[2]);
			printf("highsteerOr[0]=%f  [1]=%f  [2]=%f\n",highsteerOr21[0],highsteerOr21[1],highsteerOr21[2]);
			*/
		}
		
		if(function == SPEED)
		{
			char* dat = "speed.ai";
			FileIO* fIO = new FileIO();
	
			if(FUNCTION_NEW || !fIO->Open(dat, FILE_READ_MODE))
			{
				//printf("\n###   make speed.ai\n");
				fIO->Open(dat, FILE_WRITE_MODE);
				fIO->PushHeader("speedAnd11");
				speedAnd11[0] = -50.f;
				speedAnd11[1] = 10.f;
				speedAnd11[2] = 1.f;
				fIO->PushRecord(speedAnd11, sizeof(float)*3);
	
				fIO->PushHeader("speedAndnot12");
				speedAndnot12[0] = -25.f;
				speedAndnot12[1] = 1.f;
				speedAndnot12[2] = -10.f;
				fIO->PushRecord(speedAndnot12, sizeof(float)*3);
	
				fIO->PushHeader("speedOr21");
				speedOr21[0] = 0.f;
				speedOr21[1] = 1.f;
				speedOr21[2] = 1.f;
				fIO->PushRecord(speedOr21, sizeof(float)*3);
			}
			else
			{
				//printf("\n###   read speed.ai\n");
				fIO->Open(dat, FILE_READ_MODE);
	
				fIO->GotoHeader("speedAnd11");
				fIO->PopRecord(speedAnd11);
				//printf("speedAnd[0]=%f  [1]=%f  [2]=%f\n",speedAnd11[0],speedAnd11[1],speedAnd11[2]);
	
				fIO->GotoHeader("speedAndnot12");
				fIO->PopRecord(speedAndnot12);
	
				fIO->GotoHeader("speedOr21");
				fIO->PopRecord(speedOr21);
			}
		}
	}