Example #1
0
static int AppInit()
{
	int nRet=0;

	// Load config for the application
	nRet=ConfigAppLoad();
	if (nRet!=0)
	{
		ConfigAppSave();    // create initial config file
	}

	// Set the thread priority
	SetThreadPriority(GetCurrentThread(),nAppThreadPriority);

	ComputeGammaLUT();

	BurnLibInit(); // Init the Burn library

	MediaInit();

	//ayeye
	hAccel=LoadAccelerators(hAppInst, MAKEINTRESOURCE(IDR_ACCELERATOR));
	hImm32=LoadLibrary("imm32.dll");

	return 0;
}
Example #2
0
int MediaInit()
{
		dprintf(_T("s1\n"));
	if (ScrnInit()) {					// Init the Scrn Window
		FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_UI_WINDOW));
		FBAPopupDisplay(PUF_TYPE_ERROR);
		return 1;
	}
		dprintf(_T("s2\n"));
	if (!bInputOkay) {
		InputInit();					// Init Input
	}
		dprintf(_T("s3\n"));
	nAppVirtualFps = nBurnFPS;
		dprintf(_T("s4\n"));
	if (!bAudOkay) {
		AudSoundInit();					// Init Sound (not critical if it fails)
	}
		dprintf(_T("s5\n"));
	nBurnSoundRate = 0;					// Assume no sound
	pBurnSoundOut = NULL;
	if (bAudOkay) {
		nBurnSoundRate = nAudSampleRate[nAudSelect];
		nBurnSoundLen = nAudSegLen;
	}
		dprintf(_T("s6\n"));
	if (!bVidOkay) {
			dprintf(_T("s7\n"));
		// Reinit the video plugin
		VidInit();
		if (!bVidOkay && nVidFullscreen) {

			dprintf(_T("s8\n"));
			nVidFullscreen = 0;
			dprintf(_T("s9\n"));
			MediaExit();
			return (MediaInit());
		}
		if (!nVidFullscreen) {
			ScrnSize();
		}
		dprintf(_T("s10\n"));
		if (!bVidOkay) {
			// Make sure the error will be visible
			SplashDestroy(1);
			dprintf(_T("s11\n"));
			FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_UI_MODULE), VidGetModuleName());
			FBAPopupDisplay(PUF_TYPE_ERROR);
		}
		dprintf(_T("s12\n"));
		if (bVidOkay && ((bRunPause && bAltPause) || !bDrvOkay)) {
			VidRedraw();
		}
	}
	dprintf(_T("s13\n"));
	return 0;
}
Example #3
0
// The main message loop
int RunMessageLoop()
{
	int bRestartVideo;
	MSG Msg;

	do {
		bRestartVideo = 0;

		// Remove pending initialisation messages from the queue
		while (PeekMessage(&Msg, NULL, WM_APP + 0, WM_APP + 0, PM_NOREMOVE)) {
			if (Msg.message != WM_QUIT)	{
				PeekMessage(&Msg, NULL, WM_APP + 0, WM_APP + 0, PM_REMOVE);
			}
		}

		RunInit();

		ShowWindow(hScrnWnd, nAppShowCmd);												// Show the screen window
		nAppShowCmd = SW_NORMAL;

		SetForegroundWindow(hScrnWnd);

		GameInpCheckLeftAlt();
		GameInpCheckMouse();															// Hide the cursor

		while (1) {
			if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
				// A message is waiting to be processed
				if (Msg.message == WM_QUIT)	{											// Quit program
					break;
				}
				if (Msg.message == (WM_APP + 0)) {										// Restart video
					bRestartVideo = 1;
					break;
				}

				if (bMenuEnabled && nVidFullscreen == 0) {								// Handle keyboard messages for the menu
					if (MenuHandleKeyboard(&Msg)) {
						continue;
					}
				}

				if (Msg.message == WM_SYSKEYDOWN || Msg.message == WM_KEYDOWN) {
					if (Msg.lParam & 0x20000000) {
						// An Alt/AltGr-key was pressed
						switch (Msg.wParam) {

#if defined (FBA_DEBUG)
							case 'C': {
								static int count = 0;
								if (count == 0) {
									count++;
									{ char* p = NULL; if (*p) { printf("crash...\n"); } }
								}
								break;
							}
#endif

							case VK_OEM_PLUS: {
								TCHAR buffer[15];

								nAudVolume += 100;
								if (GetAsyncKeyState(VK_CONTROL) & 0x80000000) {
									nAudVolume += 900;
								}

								if (nAudVolume > 10000) {
									nAudVolume = 10000;
								}
								if (AudSoundSetVolume() == 0) {
									VidSNewShortMsg(FBALoadStringEx(hAppInst, IDS_SOUND_NOVOLUME, true));
								} else {
									_stprintf(buffer, FBALoadStringEx(hAppInst, IDS_SOUND_VOLUMESET, true), nAudVolume / 100);
									VidSNewShortMsg(buffer);
								}
								break;
							}
							case VK_OEM_MINUS: {
								TCHAR buffer[15];

								nAudVolume -= 100;
								if (GetAsyncKeyState(VK_CONTROL) & 0x80000000) {
									nAudVolume -= 900;
								}

								if (nAudVolume < 0) {
									nAudVolume = 0;
								}
								if (AudSoundSetVolume() == 0) {
									VidSNewShortMsg(FBALoadStringEx(hAppInst, IDS_SOUND_NOVOLUME, true));
								} else {
									_stprintf(buffer, FBALoadStringEx(hAppInst, IDS_SOUND_VOLUMESET, true), nAudVolume / 100);
									VidSNewShortMsg(buffer);
								}
								break;
							}
							case VK_MENU: {
								continue;
							}
						}
					} else {
						switch (Msg.wParam) {

#if defined (FBA_DEBUG)
							case 'N':
								counter--;
								bprintf(PRINT_IMPORTANT, _T("*** New counter value: %04X.\n"), counter);
								break;
							case 'M':
								counter++;
								bprintf(PRINT_IMPORTANT, _T("*** New counter value: %04X.\n"), counter);
								break;
#endif
							case VK_ESCAPE: {
								if (hwndChat) {
									DeActivateChat();
								} else {
									if (bCmdOptUsed) {
										PostQuitMessage(0);
									} else {
										if (nVidFullscreen) {
											nVidFullscreen = 0;
											POST_INITIALISE_MESSAGE;
										}
									}
								}
								break;
							}
							case VK_RETURN: {
								if (hwndChat) {
									int i = 0;
									while (EditText[i]) {
										if (EditText[i++] != 0x20) {
											break;
										}
									}
									if (i) {
										Kaillera_Chat_Send(TCHARToANSI(EditText, NULL, 0));
										//kailleraChatSend(TCHARToANSI(EditText, NULL, 0));
									}
									DeActivateChat();

									break;
								}
								if (GetAsyncKeyState(VK_CONTROL) & 0x80000000) {
									bMenuEnabled = !bMenuEnabled;
									POST_INITIALISE_MESSAGE;

									break;
								}

								break;
							}
							case VK_F1: {
								if (kNetGame) {
									break;
								}

								if (((GetAsyncKeyState(VK_CONTROL) | GetAsyncKeyState(VK_SHIFT)) & 0x80000000) == 0) {
									if (bRunPause) {
										bAppDoStep = 1;
									} else {
										bAppDoFast = 1;
									}
								}
								break;
							}

							case VK_BACK: {
								bShowFPS = !bShowFPS;
								if (bShowFPS) {
									DisplayFPS();
								} else {
									VidSKillShortMsg();
									VidSKillOSDMsg();
								}
								break;
							}
							case 'T': {
								if (kNetGame && hwndChat == NULL) {
									if (AppMessage(&Msg)) {
										ActivateChat();
									}
								}
								break;
							}
						}
					}
				} else {
					if (Msg.message == WM_SYSKEYUP || Msg.message == WM_KEYUP) {
						switch (Msg.wParam) {
							case VK_MENU:
								continue;
							case VK_F1:
								bAppDoFast = 0;
								break;
						}
					}
				}

				// Check for messages for dialogs etc.
				if (AppMessage(&Msg)) {
					if (TranslateAccelerator(hScrnWnd, hAccel, &Msg) == 0) {
						if (hwndChat) {
							TranslateMessage(&Msg);
						}
						DispatchMessage(&Msg);
					}
				}
			} else {
				// No messages are waiting
				SplashDestroy(0);
				RunIdle();
			}
		}

		RunExit();
		MediaExit();
		if (bRestartVideo) {
			MediaInit();
		}
	} while (bRestartVideo);

	return 0;
}
Example #4
0
int MediaInit()
{
/*
	if (ScrnInit()) {					// Init the Scrn Window
		FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_UI_WINDOW));
		FBAPopupDisplay(PUF_TYPE_ERROR);
		return 1;
	}
*/
	// Screen Size will go here via
	/*
		if (bDrvOkay) {
		if ((BurnDrvGetFlags() & BDF_ORIENTATION_VERTICAL) && (nVidRotationAdjust & 1)) {
			BurnDrvGetVisibleSize(&nBmapHeight, &nBmapWidth);
			BurnDrvGetAspect(&nGameAspectY, &nGameAspectX);
		} else {
			BurnDrvGetVisibleSize(&nBmapWidth, &nBmapHeight);
			BurnDrvGetAspect(&nGameAspectX, &nGameAspectY);
		}

		if (nBmapWidth <= 0 || nBmapHeight <= 0) {
			return 1;
		}
	}
	*/

	if (!bInputOkay) {	
		InputInit();					// Init Input
	}

//	nAppVirtualFps = nBurnFPS;

	if (!bAudOkay) {
		AudSoundInit();					// Init Sound (not critical if it fails)
	}

	nBurnSoundRate = 0;					// Assume no sound
	pBurnSoundOut = NULL;
	if (bAudOkay) {
		nBurnSoundRate = nAudSampleRate[nAudSelect];
		nBurnSoundLen = nAudSegLen;
	}

	if (!bVidOkay) {

		// Reinit the video plugin
		VidInit();
		if (!bVidOkay && nVidFullscreen) {

			nVidFullscreen = 0;

			MediaExit();
			return (MediaInit());
		}
		if (!nVidFullscreen) {
//			ScrnSize(); // dont' change any screens on the wii
		}

		if (!bVidOkay && (bDrvOkay || bVidUsePlaceholder)) {
			// Make sure the error will be visible
//			SplashDestroy(1);

	//		FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_UI_MODULE), VidGetModuleName());
	//		FBAPopupDisplay(PUF_TYPE_ERROR);
		}

		if (bVidOkay && ((bRunPause && bAltPause) || !bDrvOkay)) {
			VidRedraw();
		}
	}

	return 0;
}
Example #5
0
/*
 * Initialize recycler dat for each samfsdump file.  Generate the dat file
 * name and see if this file was created on a previous run of the recycler.
 */
void
DatInit(
    CsdDir_t *csdDir)
{
    int idx;
    struct stat sb;
    char *filename;
    CsdEntry_t *csdEntry;
    int fd;
    int rval;

    for (idx = 0; idx < csdDir->cd_count; idx++) {
        csdEntry = &csdDir->cd_entry[idx];

        if (csdEntry->ce_skip == B_TRUE) {
            continue;
        }
        filename = csdEntry->ce_path;	/* path to samfsdump file */

        /*
         * Build path to recycler's dat file for the samfsdump file.
         */
        SamMalloc(csdEntry->ce_datPath, sizeof (upath_t));
        (void) snprintf(csdEntry->ce_datPath, sizeof (upath_t), "%s%s",
                        filename, DAT_FILE_SUFFIX);

        if (stat(csdEntry->ce_datPath, &sb) == 0) {
            /*
             * Dat file exists.
             */

            if (RegenDatfiles == B_TRUE) {
                Trace(TR_MISC,
                      "Regenerating recycler dat file '%s'",
                      csdEntry->ce_datPath);

                (void) unlink(csdEntry->ce_datPath);
                continue;
            }

            /*
             * Read and validate header.
             */
            csdEntry->ce_exists = B_FALSE;

            fd = readOpen(csdEntry->ce_datPath);
            if (fd < 0) {
                Trace(TR_MISC,
                      "Failed to open dat file '%s' errno: %d",
                      csdEntry->ce_datPath, errno);
                continue;
            }

            rval = readHeader(fd, csdEntry->ce_datPath);
            if (rval == 0) {
                csdEntry->ce_exists = B_TRUE;
            } else {
                Trace(TR_MISC,
                      "Invalid recycler dat file '%s'",
                      csdEntry->ce_datPath);

                (void) unlink(csdEntry->ce_datPath);
            }
            (void) DatClose(fd);
        }

        /*
         * Allocate and initialize media table for samfsdump file.
         */
        SamMalloc(csdEntry->ce_table, sizeof (MediaTable_t));
        (void) memset(csdEntry->ce_table, 0, sizeof (MediaTable_t));

        if (MediaInit(csdEntry->ce_table, csdEntry->ce_path) != 0) {
            Trace(TR_MISC,
                  "Error: media table initialization failed");
            return;
        }
    }
}
Example #6
0
int ProcessCmdLine()
{
	unsigned int i;
	int nOptX = 0, nOptY = 0, nOptD = 0;
	int nOpt1Size;
	TCHAR szOpt2[64] = _T("");
	TCHAR szName[MAX_PATH];

	if (szCmdLine[0] == _T('\"')) {
		int nLen = _tcslen(szCmdLine);
		nOpt1Size = 1;
		while (szCmdLine[nOpt1Size] != _T('\"') && nOpt1Size < nLen) {
			nOpt1Size++;
		}
		if (nOpt1Size == nLen) {
			szName[0] = 0;
		} else {
			nOpt1Size++;
			_tcsncpy(szName, szCmdLine + 1, nOpt1Size - 2);
			szName[nOpt1Size - 2] = 0;
		}
	} else {
		int nLen = _tcslen(szCmdLine);
		nOpt1Size = 0;
		while (szCmdLine[nOpt1Size] != _T(' ') && nOpt1Size < nLen) {
			nOpt1Size++;
		}
		_tcsncpy(szName, szCmdLine, nOpt1Size);
		szName[nOpt1Size] = 0;
	}

	if (_tcslen(szName)) {
		if (_tcscmp(szName, _T("-listinfo")) == 0) {
			write_datfile(0, stdout);
			return 1;
		}
	}

	_stscanf(&szCmdLine[nOpt1Size], _T("%64s %i x %i x %i"), szOpt2, &nOptX, &nOptY, &nOptD);

	if (_tcslen(szName)) {
		bool bFullscreen = 1;
		bCmdOptUsed = 1;

		if (_tcscmp(szOpt2, _T("-r")) == 0) {
			if (nOptX && nOptY) {
				nVidWidth = nOptX;
				nVidHeight = nOptY;
			}
			if (nOptD) {
				nVidDepth = nOptD;
			}
		} else if (_tcscmp(szOpt2, _T("-a")) == 0) {
			bVidArcaderes = 1;
	   } else if (_tcscmp(szOpt2, _T("-w")) == 0) {
		   bCmdOptUsed = 0;
		   bFullscreen = 0;
		} else if (_tcsncmp(szOpt2, _T("-e"), 2) == 0) {
		   bCmdOptUsed = 0;
		   bFullscreen = 0;
         bHideLoadProgress = 1;
			nVidEmbeddedWindow = strtol(szOpt2 + 2, NULL, 16); /* Not unicode clean. =( */
         if (!IsWindow((HWND)nVidEmbeddedWindow)) {
            nVidEmbeddedWindow = NULL;
   		   bFullscreen = 0;
         }
      }

		if (bFullscreen) {
			nVidFullscreen = 1;
		}

		if (_tcscmp(&szName[_tcslen(szName) - 3], _T(".fs")) == 0) {
			if (BurnStateLoad(szName, 1, &DrvInitCallback)) {
				return 1;
			} else {
//				bRunPause = 1;
			}
		} else {
			if (_tcscmp(&szName[_tcslen(szName) - 3], _T(".fr")) == 0) {
				if (StartReplay(szName)) {
					return 1;
				}
         } else if (_tcsncmp(szName, _T("quark:"), 6) == 0) {
            QuarkInit(szName);
			} else {
				for (i = 0; i < nBurnDrvCount; i++) {
					nBurnDrvSelect = i;
					if (_tcscmp(BurnDrvGetText(DRV_NAME), szName) == 0) {
						MediaInit();
						DrvInit(i, true);
						break;
					}
				}
				if (i == nBurnDrvCount) {
					FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_UI_NOSUPPORT), szName, _T(APP_TITLE));
					FBAPopupDisplay(PUF_TYPE_ERROR);
					return 1;
				}
			}
		}
	}

	POST_INITIALISE_MESSAGE;

	if (!nVidFullscreen) {
		MenuEnableItems();
	}

	return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
//>  Name:          Main
//
//   Type:          Function
//
//   Description:   Main entry point
//
//   Inputs:        none
//
//   Outputs:       none
//
//   Notes:         none
//<
////////////////////////////////////////////////////////////////////////////////
void _reentrant Task0EntryPoint(void)
{
    WORD i,j, k;
    BOOL bComplete;
    RETCODE rtCode;
    WORD wTag;
    WORD wResourceDriveNumber;
    BOOL bFound;
    DWORD dwNumSectors;
    DWORD dwSectorCount;
    
    // Init the media
    if(MediaInit(0) != SUCCESS)
    {
        SystemHalt();
    }
    
    // Allocate the test drives
    if(MediaDiscoverAllocation(0) != SUCCESS)
    {
        SystemHalt();
    }
    
    // Init the drives
    for(i=0;i<g_wNumDrives;i++)
    {
        if(DriveInit(i) != SUCCESS)
        {
        }
    }
    
    // Find the resource.bin drive
    bFound = FALSE;
    wResourceDriveNumber = 0;
    for(i=0;i<g_wNumDrives;i++)
    {
        if(DriveGetInfo(i, DriveInfoTag, &wTag) != SUCCESS)
        {
            SystemHalt();
        }
        
        if(wTag == DRIVE_TAG_RESOURCE_BIN)
        {
            wResourceDriveNumber = (WORD)i;
            bFound = TRUE;
            break;
        }
    }
    
    if(!bFound)
        SystemHalt();
    
    //
    // Write & verify all the sectors of all drives
    //
    
    // First, loop through all drives & write patterns to all sectors
    dwSectorCount = 1;
    for(i=0;i<g_wNumDrives;i++)
    {
        // First get the total number of sectors for the drive
        if(DriveGetInfo(i, DriveInfoSizeInSectors, &dwNumSectors) != SUCCESS)
        {
            SystemHalt();
        }
    
        // Now loop through all sectors
        for(j=0;j<dwNumSectors;j++)
        {
            // Init the sector
//            for(k=0;k<171;k++)    //tt RAM_SECTOR_SIZE is actually 170
            for(k=0;k<RAM_SECTOR_SIZE_IN_WORDS;k++)
            {
                pWriteBuffer[k] = (WORD)(dwSectorCount*0x111111); 
            }
        
            // Write the sector
            if(DriveWriteSector(i, j, pWriteBuffer) != SUCCESS)
            {
                SystemHalt();
            }
            
            // Bump the sector count
            dwSectorCount++;
        }
    }
    
    // Now loop through all drives & verify each sector
    dwSectorCount = 1;
    for(i=0;i<g_wNumDrives;i++)
    {
        // First get the total number of sectors for the drive
        if(DriveGetInfo(i, DriveInfoSizeInSectors, &dwNumSectors) != SUCCESS)
        {
            SystemHalt();
        }
        
        // Now loop through all sectors
        for(j=0;j<dwNumSectors;j++)
        {
            // Init the read sector
//            for(k=0;k<171;k++)    //tt RAM_SECTOR_SIZE is actually 170
            for(k=0;k<RAM_SECTOR_SIZE_IN_WORDS;k++)
            {
                pReadBuffer[k] = 0; 
            }
    
            // Read the sector
            if(DriveReadSector(i, j, pReadBuffer) != SUCCESS)
            {
                SystemHalt();
            }
            
            // Verify the sector
//            for(k=0;k<171;k++)    //tt RAM_SECTOR_SIZE is actually 170
            for(k=0;k<RAM_SECTOR_SIZE_IN_WORDS;k++)
            {
                pWriteBuffer[k] = (WORD)(dwSectorCount*0x111111); 
            }

//            for(k=0;k<171;k++)    //tt RAM_SECTOR_SIZE is actually 170
            for(k=0;k<RAM_SECTOR_SIZE_IN_WORDS;k++)
            {
                if(pReadBuffer[k] != pWriteBuffer[k])
                {                  
                    SystemHalt();
                }
            }
            
            // Bump the sector count
            dwSectorCount++;
        }
    }    
    
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    // SUCCESS
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    SystemHalt();
}
Example #8
0
int ProcessCmdLine()
{
	unsigned int i;
	int nOptX = 0, nOptY = 0, nOptD = 0;
	int nOpt1Size;
	TCHAR szOpt2[3] = _T("");
	TCHAR szName[MAX_PATH];

	if (szCmdLine[0] == _T('\"')) {
		int nLen = _tcslen(szCmdLine);
		nOpt1Size = 1;
		while (szCmdLine[nOpt1Size] != _T('\"') && nOpt1Size < nLen) {
			nOpt1Size++;
		}
		if (nOpt1Size == nLen) {
			szName[0] = 0;
		} else {
			nOpt1Size++;
			_tcsncpy(szName, szCmdLine + 1, nOpt1Size - 2);
			szName[nOpt1Size - 2] = 0;
		}
	} else {
		int nLen = _tcslen(szCmdLine);
		nOpt1Size = 0;
		while (szCmdLine[nOpt1Size] != _T(' ') && nOpt1Size < nLen) {
			nOpt1Size++;
		}
		_tcsncpy(szName, szCmdLine, nOpt1Size);
		szName[nOpt1Size] = 0;
	}

	if (_tcslen(szName)) {
		if (_tcscmp(szName, _T("-listinfo")) == 0) {
			write_datfile(0, 0, stdout);
			return 1;
		}
		
		if (_tcscmp(szName, _T("-listinfowithmd")) == 0) {
			write_datfile(0, 1, stdout);
			return 1;
		}
		
		if (_tcscmp(szName, _T("-listinfomdonly")) == 0) {
			write_datfile(0, 2, stdout);
			return 1;
		}
		
		if (_tcscmp(szName, _T("-listextrainfo")) == 0) {
			int nWidth;
			int nHeight;
			int nAspectX;
			int nAspectY;
			for (i = 0; i < nBurnDrvCount; i++) {
				nBurnDrvSelect = i;
				BurnDrvGetVisibleSize(&nWidth, &nHeight);
				BurnDrvGetAspect(&nAspectX, &nAspectY);
				printf("%s\t%ix%i\t%i:%i\t0x%08X\t\"%s\"\t%i\t%i\t%x\t%x\t\"%s\"\n", BurnDrvGetTextA(DRV_NAME), nWidth, nHeight, nAspectX, nAspectY, BurnDrvGetHardwareCode(), BurnDrvGetTextA(DRV_SYSTEM), BurnDrvIsWorking(), BurnDrvGetMaxPlayers(), BurnDrvGetGenreFlags(), BurnDrvGetFamilyFlags(), BurnDrvGetTextA(DRV_COMMENT));
			}			
			return 1;
		}
	}

	_stscanf(&szCmdLine[nOpt1Size], _T("%2s %i x %i x %i"), szOpt2, &nOptX, &nOptY, &nOptD);

	if (_tcslen(szName)) {
		bool bFullscreen = 1;
		bCmdOptUsed = 1;

		if (_tcscmp(szOpt2, _T("-r")) == 0) {
			if (nOptX && nOptY) {
				nVidWidth = nOptX;
				nVidHeight = nOptY;
			}
			if (nOptD) {
				nVidDepth = nOptD;
			}
		} else {
			if (_tcscmp(szOpt2, _T("-a")) == 0) {
				bVidArcaderes = 1;
			} else {
				if (_tcscmp(szOpt2, _T("-w")) == 0) {
					bCmdOptUsed = 0;
					bFullscreen = 0;
				}
			}
		}

		if (bFullscreen) {
			nVidFullscreen = 1;
		}

		if (_tcscmp(&szName[_tcslen(szName) - 3], _T(".fs")) == 0) {
			if (BurnStateLoad(szName, 1, &DrvInitCallback)) {
				return 1;
			} else {
//				bRunPause = 1;
			}
		} else {
			if (_tcscmp(&szName[_tcslen(szName) - 3], _T(".fr")) == 0) {
				if (StartReplay(szName)) {
					return 1;
				}
			} else {
				for (i = 0; i < nBurnDrvCount; i++) {
					nBurnDrvSelect = i;
					if (_tcscmp(BurnDrvGetText(DRV_NAME), szName) == 0) {
						MediaInit();
						DrvInit(i, true);
						break;
					}
				}
				if (i == nBurnDrvCount) {
					FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_UI_NOSUPPORT), szName, _T(APP_TITLE));
					FBAPopupDisplay(PUF_TYPE_ERROR);
					return 1;
				}
			}
		}
	}

	POST_INITIALISE_MESSAGE;

	if (!nVidFullscreen) {
		MenuEnableItems();
	}

	return 0;
}
Example #9
0
// The main message loop
int RunMessageLoop()
{
	int bRestartVideo=0;

RunAgain:

	if (nVidFullscreen)
	{
		while (ShowCursor(0)>=0)
			;    // hide cursor in fullscreen
	}

	// Size the window for current game
	ScrnSize();

	RunInit();

	bRestartVideo = 0;

	for (;;)
	{
		MSG Msg;
		int nRet=0;
		nRet=PeekMessage(&Msg,NULL,0,0,PM_REMOVE);
		if (nRet!=0)
		{
			// A message is waiting to be processed
			if (Msg.message == WM_QUIT)
			{
				break;    // Quit program
			}
			if (Msg.message == WM_APP + 0)
			{
				bRestartVideo = 1;
				break;
			}

			if (Msg.message == WM_KEYDOWN)
			{

				// Escape key
				if (Msg.wParam == VK_ESCAPE)
				{
					if (bCmdOptUsed)
					{
						PostQuitMessage(0);
					}
					else
					{
						if (nVidFullscreen)
						{
							nVidFullscreen = 0;
							PostMessage(NULL, WM_APP + 0, 0, 0);
						}

					}
				}

				// Hotkeys for savestates
				if (Msg.wParam >= VK_F1 && Msg.wParam <= VK_F9)
				{
					if (GetAsyncKeyState(VK_CONTROL) & 0x80000000)
					{
						int nSlot = Msg.wParam + 1 - VK_F1;
						if (GetAsyncKeyState(VK_SHIFT) & 0x80000000)
							// Save state
						{
							StatedSave(nSlot);
						}
						else
							// Load state
						{
							StatedLoad(nSlot);
						}
					}
				}

			}


#ifdef _DEBUG
			// For the "counter"variable
			if ((Msg.message==WM_SYSKEYDOWN || Msg.message==WM_KEYDOWN))
			{
				switch (Msg.wParam)
				{
				case 'N':
					counter--;
					break;
				case 'M':
					counter++;
					break;
				}
			}
#endif

			if ((Msg.message==WM_SYSKEYDOWN || Msg.message==WM_KEYDOWN)&&(Msg.lParam&0x20000000))
			{
				// An Alt/AltGr-key was pressed
				switch (Msg.wParam)
				{
				case 'I':
					bAppFastForward=!bAppFastForward;
					break;
				case 'O':
					bAppStep=1;
					break;
				case 'P':
					bRunPause=!bRunPause;
					bAltPause=!bAltPause;
					MenuUpdate();
					break;
				case 13 :
				{
					nVidFullscreen=!nVidFullscreen;
					PostMessage(NULL,WM_APP+0,0,0);
					break;
				}
				case 0xBB:
				{
					if(nDSoundVol < 0L)
					{
						nDSoundVol+=100L;
					}

					break;
				}
				case 0xBD:
				{
					if(nDSoundVol > -4000L)
					{
						nDSoundVol-=100L;
					}

					break;
				}
				}
			}

			// Check for messages for dialogs etc.
			nRet=AppMessage(&Msg);
			if (nRet!=0)
			{
				if(TranslateAccelerator(hScrnWnd, hAccel, &Msg)==0)
				{
					DispatchMessage(&Msg);
				}
			}
		}
		else
		{
			HWND hActive=GetActiveWindow();

			bAppDoFast=bAppFastForward;

			if (APP_TAKE_INPUT(hActive))
			{
				if (KEY_DOWN(VK_F7))
				{
					bAppDoFast=1;
				}
			}
			// No messages are waiting
			RunIdle();
		}
	}

	if (nVidFullscreen==0)
	{
		while (ShowCursor(1)< 0);    // show cursor in windowed
	}

	RunExit();

	if (bRestartVideo)
	{
		int nRet=0;
		VidExit();
		MediaExit();

		MediaInit();

		// Reinit the video plugin
		nRet=VidInit();
		if (nRet!=0)
		{
			AppError("VidInit Failed",0);
		}
		if (bDrvOkay && bRunPause)
		{
			VidRedraw();
		}
		goto RunAgain;
	}

	return 0;
}
Example #10
0
int DrvInit(int nDrvNum, bool bRestore)
{
	int nStatus;
	
	DrvExit();						// Make sure exitted
	MediaExit();

	nBurnDrvActive = nDrvNum;		// Set the driver number
	
	if ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNK_MVS) {

		BurnExtCartridgeSetupCallback = DrvCartridgeAccess;

		if (SelMVSDialog()) {
			POST_INITIALISE_MESSAGE;
			return 0;
		}
	}

	if ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNK_NEOCD) {
		if (CDEmuInit()) {
			FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_CDEMU_INI_FAIL));
			FBAPopupDisplay(PUF_TYPE_ERROR);

			POST_INITIALISE_MESSAGE;
			return 0;
		}
	}

	MediaInit();

	// Define nMaxPlayers early; GameInpInit() needs it (normally defined in DoLibInit()).
	nMaxPlayers = BurnDrvGetMaxPlayers();
	GameInpInit();					// Init game input

	if(ConfigGameLoad(true)) {
		ConfigGameLoadHardwareDefaults();
	}	
	InputMake(true);
	GameInpDefault();

	if (kNetGame) {
		nBurnCPUSpeedAdjust = 0x0100;
	}

	nStatus = DoLibInit();			// Init the Burn library's driver
	if (nStatus) {
		if (nStatus & 2) {
			BurnDrvExit();			// Exit the driver

			ScrnTitle();

			FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_BURN_INIT), BurnDrvGetText(DRV_FULLNAME));
			FBAPopupDisplay(PUF_TYPE_WARNING);
		}

		POST_INITIALISE_MESSAGE;
		return 1;
	}

	BurnExtLoadRom = DrvLoadRom;

	bDrvOkay = 1;						// Okay to use all BurnDrv functions

	if (BurnDrvGetFlags() & BDF_ORIENTATION_VERTICAL) {
		nScreenSize = nScreenSizeVer;
		bVidArcaderes = bVidArcaderesVer;
		nVidWidth	= nVidVerWidth;
		nVidHeight	= nVidVerHeight;
	} else {
		nScreenSize = nScreenSizeHor;
		bVidArcaderes = bVidArcaderesHor;
		nVidWidth	= nVidHorWidth;
		nVidHeight	= nVidHorHeight;
	}

	bSaveRAM = false;
	if (kNetGame) {
		KailleraInitInput();
		KailleraGetInput();
	} else {
		if (bRestore) {
			StatedAuto(0);
			bSaveRAM = true;

			ConfigCheatLoad();
		}
	}

	nBurnLayer = 0xFF;				// show all layers
	
	// Reset the speed throttling code, so we don't 'jump' after the load
	RunReset();

	VidExit();
	POST_INITIALISE_MESSAGE;

	return 0;
}
///////////////////////////////////////////////////////////////////////////////
//
//>  Name:          MtpCheckExternalMedia
//
//   Type:          Function
//
//   Description:   Called by system task
//
//   Inputs:        none
//
//   Outputs:       none 
//
//   Notes:         MTP gets one chance to properly initialize an inserted external media card
//                  After usb has been initialized, if media is present, initialize it. Then StorInit() can run
//<
////////////////////////////////////////////////////////////////////////////////
void _reentrant MtpCheckExternalMedia(void)
{
    BOOL bExternalMediaChanged = FALSE;
    BOOL bMMCPresent = FALSE;
    WORD retCode = !SUCCESS;
    WORD i;

    // Find out if media presence has changed
    DriveGetInfo(MMC_DRIVE_NUM,DriveInfoMediaChange,&bExternalMediaChanged);
    
    // bExternalMediaChanged should be yes if it's started up inserted

    if(bMMCInit || bExternalMediaChanged)
    {
       // Debounce media insertion/removal
        SysDelayMs(MEDIA_INSERTION_DELAY);    

        // Is the media connected or disconnected?
        retCode = DriveGetInfo(MMC_DRIVE_NUM,DriveInfoMediaPresent,&bMMCPresent);
    }

    if(bMMCInit)
    {
        if((retCode == SUCCESS) && g_MtpArbitrationDone)
        {
            if((g_iHighPwrPeriphInitMode == USB_HIGH_CURRENT_GRANTED) && (bMMCPresent))
            {
                // Conditions are okay for MMC initialization to complete.
                // Initialize the MMC media, drive, and filesystem

                // Complete the final phase of MMC media init
                MediaInit(MMC_MEDIA_NUM);

                // Init filesystem for the MMC data drive
                FSDriveInit(MMC_DRIVE_NUM);

                // Load freecluster code resource
                SysLoadMtpBootInit();
                
                // Needed to complete MMC filesystem initialization
                Computefreeluster(MMC_DRIVE_NUM);

                // Reload the FS write resource
                SysLoadWrite();
            
                // Firmware can poll this global to check external media presence
                g_bExternalMediaConnected = TRUE;                        
            }
          
            else
            {
                g_bExternalMediaConnected = FALSE;
            }
        
            // StorInit() watches bMMCInit, and waits for it to become FALSE before carrying out its initialization
            bMMCInit = FALSE;
       }
    }
    else if(bExternalMediaChanged)
    {
        if((retCode == SUCCESS) && (bMMCPresent))
        {   
            // If, after the system has started and been initialized in MTP mode, external media is inserted, 
            // we can't notify the host, so do nothing.
            ; // Do nothing...
        }
        else
        {   
            // Signal firmware that media has been removed
            g_bExternalMediaConnected = FALSE;
        }
    }
}