コード例 #1
0
void Snapshot_LoadState()
{
	char szMessage[32 + MAX_PATH];

	APPLEWIN_SNAPSHOT* pSS = (APPLEWIN_SNAPSHOT*) new char[sizeof(APPLEWIN_SNAPSHOT)];

	try
	{
		if(pSS == NULL)
			throw(0);

		memset(pSS, 0, sizeof(APPLEWIN_SNAPSHOT));

		//

		HANDLE hFile = CreateFile(	g_szSaveStateFilename,
									GENERIC_READ,
									0,
									NULL,
									OPEN_EXISTING,
									FILE_ATTRIBUTE_NORMAL,
									NULL);

		if(hFile == INVALID_HANDLE_VALUE)
		{
			strcpy(szMessage, "File not found: ");
			strcpy(szMessage + strlen(szMessage), g_szSaveStateFilename);
			throw(0);
		}

		DWORD dwBytesRead;
		BOOL bRes = ReadFile(	hFile,
								pSS,
								sizeof(APPLEWIN_SNAPSHOT),
								&dwBytesRead,
								NULL);

		CloseHandle(hFile);

		if(!bRes || (dwBytesRead != sizeof(APPLEWIN_SNAPSHOT)))
		{
			// File size wrong: probably because of version mismatch or corrupt file
			strcpy(szMessage, "File size mismatch");
			throw(0);
		}

		if(pSS->Hdr.dwTag != AW_SS_TAG)
		{
			strcpy(szMessage, "File corrupt");
			throw(0);
		}

		if(pSS->Hdr.dwVersion != MAKE_VERSION(1,0,0,1))
		{
			strcpy(szMessage, "Version mismatch");
			throw(0);
		}

		// TO DO: Verify checksum

		//
		// Reset all sub-systems
		MemReset();

		if (apple2e)
			MemResetPaging();

		DiskReset();
		KeybReset();
		VideoResetState();
		MB_Reset();

		//
		// Apple2 uint
		//

		CpuSetSnapshot(&pSS->Apple2Unit.CPU6502);
		CommSetSnapshot(&pSS->Apple2Unit.Comms);
		JoySetSnapshot(&pSS->Apple2Unit.Joystick);
		KeybSetSnapshot(&pSS->Apple2Unit.Keyboard);
		SpkrSetSnapshot(&pSS->Apple2Unit.Speaker);
		VideoSetSnapshot(&pSS->Apple2Unit.Video);
		MemSetSnapshot(&pSS->Apple2Unit.Memory);

		//

		//
		// Slot4: Mockingboard
		MB_SetSnapshot(&pSS->Mockingboard1, 4);

		//
		// Slot5: Mockingboard
		MB_SetSnapshot(&pSS->Mockingboard2, 5);

		//
		// Slot6: Disk][
		DiskSetSnapshot(&pSS->Disk2, 6);
	}
	catch(int)
	{
		MessageBox(	g_hFrameWindow,
					szMessage,
					TEXT("Load State"),
					MB_ICONEXCLAMATION | MB_SETFOREGROUND);
	}

	delete [] pSS;
}
コード例 #2
0
ファイル: SaveState.cpp プロジェクト: catseye/linapple
void Snapshot_LoadState()
{
  char szMessage[32 + MAX_PATH];

  APPLEWIN_SNAPSHOT* pSS = (APPLEWIN_SNAPSHOT*) new char[sizeof(APPLEWIN_SNAPSHOT)];

  try
  {
    if(pSS == NULL)
      throw(0);

    memset(pSS, 0, sizeof(APPLEWIN_SNAPSHOT));

    //

/*    HANDLE hFile = CreateFile(  g_szSaveStateFilename,
                  GENERIC_READ,
                  0,
                  NULL,
                  OPEN_EXISTING,
                  FILE_ATTRIBUTE_NORMAL,
                  NULL);*/
    HANDLE hFile = (FILE*)fopen(g_szSaveStateFilename, "rb");

    if(hFile == INVALID_HANDLE_VALUE)
    {
      strcpy(szMessage, "File not found: ");
      strcpy(szMessage + strlen(szMessage), g_szSaveStateFilename);
      throw(0);
    }

    DWORD dwBytesRead;
    BOOL bRes = ReadFile(  hFile,
                pSS,
                sizeof(APPLEWIN_SNAPSHOT),
                &dwBytesRead,
                NULL);

    CloseHandle(hFile);

    if(!bRes || (dwBytesRead != sizeof(APPLEWIN_SNAPSHOT)))
    {
      // File size wrong: probably because of version mismatch or corrupt file
      strcpy(szMessage, "File size mismatch");
      throw(0);
    }

    if(pSS->Hdr.dwTag != (DWORD) AW_SS_TAG)
    {
      strcpy(szMessage, "File corrupt");
      throw(0);
    }

/* Let it be any version, never mind it! ^_^ */
     if(pSS->Hdr.dwVersion != MAKE_VERSION(1,0,0,1))
     {
       strcpy(szMessage, "Version mismatch");
       throw(0);
     }

    // TO DO: Verify checksum

    //
    // Reset all sub-systems
    MemReset();

    if (!IS_APPLE2)
      MemResetPaging();

    DiskReset();
    KeybReset();
    VideoResetState();
    MB_Reset();

    //
    // Apple2 uint
    //

    CpuSetSnapshot(&pSS->Apple2Unit.CPU6502);
    sg_SSC.CommSetSnapshot(&pSS->Apple2Unit.Comms);
    JoySetSnapshot(&pSS->Apple2Unit.Joystick);
    KeybSetSnapshot(&pSS->Apple2Unit.Keyboard);
    SpkrSetSnapshot(&pSS->Apple2Unit.Speaker);
    VideoSetSnapshot(&pSS->Apple2Unit.Video);
    MemSetSnapshot(&pSS->Apple2Unit.Memory);

    //

    //
    // Slot4: Mockingboard
    MB_SetSnapshot(&pSS->Mockingboard1, 4);

    //
    // Slot5: Mockingboard
    MB_SetSnapshot(&pSS->Mockingboard2, 5);

    //
    // Slot6: Disk][
    DiskSetSnapshot(&pSS->Disk2, 6);

    // Hmmm. And SLOT 7 (HDD1 and HDD2)? Where are they??? -- beom beotiger ^_^
  }
  catch(int)
  {
/*    MessageBox(  g_hFrameWindow,
          szMessage,
          TEXT("Load State"),
          MB_ICONEXCLAMATION | MB_SETFOREGROUND);*/
    fprintf(stderr, "%s\n", szMessage); // instead of wndzoooe messagebox let's use powerful stderr
  }

  delete [] pSS;
}