/*===================================================================*/
/* */
/* InfoNES_System_Win.cpp : The function which depends on a system */
/* (for Windows) */
/* */
/* 2000/05/12 InfoNES Project */
/* */
/*===================================================================*/
/*-------------------------------------------------------------------*/
/* Include files */
/*-------------------------------------------------------------------*/
#include <windows.h>
#include <mmsystem.h>
#include <limits.h>
#include <stdio.h>
#include <crtdbg.h>
#include <stdarg.h>
#include "../InfoNES.h"
#include "../InfoNES_System.h"
#include "InfoNES_Resource_Win.h"
#include "InfoNES_Sound_Win.h"
#include "../InfoNES_pAPU.h"
/*-------------------------------------------------------------------*/
/* ROM image file information */
/*-------------------------------------------------------------------*/
char szRomName[ 256 ];
char szSaveName[ 256 ];
int nSRAM_SaveFlag;
/*-------------------------------------------------------------------*/
/* Variables for Windows */
/*-------------------------------------------------------------------*/
#define APP_NAME "InfoNES v0.93J"
HWND hWndMain;
WNDCLASS wc;
HACCEL hAccel;
byte *pScreenMem;
HBITMAP hScreenBmp;
LOGPALETTE *plpal;
BITMAPINFO *bmi;
// Palette data
WORD NesPalette[ 64 ] =
{
0x39ce, 0x1071, 0x0015, 0x2013, 0x440e, 0x5402, 0x5000, 0x3c20,
0x20a0, 0x0100, 0x0140, 0x00e2, 0x0ceb, 0x0000, 0x0000, 0x0000,
0x5ef7, 0x01dd, 0x10fd, 0x401e, 0x5c17, 0x700b, 0x6ca0, 0x6521,
0x45c0, 0x0240, 0x02a0, 0x0247, 0x0211, 0x0000, 0x0000, 0x0000,
0x7fff, 0x1eff, 0x2e5f, 0x223f, 0x79ff, 0x7dd6, 0x7dcc, 0x7e67,
0x7ae7, 0x4342, 0x2769, 0x2ff3, 0x03bb, 0x0000, 0x0000, 0x0000,
0x7fff, 0x579f, 0x635f, 0x6b3f, 0x7f1f, 0x7f1b, 0x7ef6, 0x7f75,
0x7f94, 0x73f4, 0x57d7, 0x5bf9, 0x4ffe, 0x0000, 0x0000, 0x0000
};
// Screen Size Magnification
WORD wScreenMagnification = 1;
#define NES_MENU_HEIGHT 54
#define NES_MENU_WIDTH 8
/*-------------------------------------------------------------------*/
/* Variables for Emulation Thread */
/*-------------------------------------------------------------------*/
HANDLE m_hThread;
DWORD m_ThreadID = NULL;
/*-------------------------------------------------------------------*/
/* Variables for Timer & Wait loop */
/*-------------------------------------------------------------------*/
#define LINE_PER_TIMER 789
#define TIMER_PER_LINE 50
WORD wLines;
WORD wLinePerTimer;
MMRESULT uTimerID;
BOOL bWaitFlag;
CRITICAL_SECTION WaitFlagCriticalSection;
BOOL bAutoFrameskip = TRUE;
/*-------------------------------------------------------------------*/
/* Variables for Sound Emulation */
/*-------------------------------------------------------------------*/
DIRSOUND* lpSndDevice = NULL;
/*-------------------------------------------------------------------*/
/* Variables for Expiration */
/*-------------------------------------------------------------------*/
#define EXPIRED_YEAR 2001
#define EXPIRED_MONTH 3
#define EXPIRED_MSG "This software has been expired.\nPlease download newer one."
/*-------------------------------------------------------------------*/
/* Function prototypes ( Windows specific ) */
/*-------------------------------------------------------------------*/
LRESULT CALLBACK MainWndproc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
#if 0
LRESULT CALLBACK AboutDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
#endif
void ShowTitle( HWND hWnd );
void SetWindowSize( WORD wMag );
int LoadSRAM();
int SaveSRAM();
int CreateScreen( HWND hWnd );
void DestroyScreen();
static void InfoNES_StartTimer();
static void InfoNES_StopTimer();
static void CALLBACK TimerFunc( UINT nID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2);
/*===================================================================*/
/* */
/* WinMain() : Application main */
/* */
/*===================================================================*/
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
/*-------------------------------------------------------------------*/
/* Create a window */
/*-------------------------------------------------------------------*/
wc.style = 0;
wc.lpfnWndProc = MainWndproc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_ICON) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = "InfoNESClass";
if ( !RegisterClass( &wc ) )
return FALSE;
hWndMain = CreateWindowEx( 0,
"InfoNESClass",
APP_NAME,
WS_VISIBLE | WS_POPUP | WS_OVERLAPPEDWINDOW,
200,
120,
NES_DISP_WIDTH * wScreenMagnification + NES_MENU_WIDTH,
NES_DISP_HEIGHT * wScreenMagnification + NES_MENU_HEIGHT,
NULL,
NULL,
hInstance,
NULL );
if ( !hWndMain )
return FALSE;
ShowWindow( hWndMain, nCmdShow );
UpdateWindow( hWndMain );
#if 0
/*-------------------------------------------------------------------*/
/* Expired or Not? */
/*-------------------------------------------------------------------*/
SYSTEMTIME st;
GetLocalTime( &st );
if ( st.wYear > EXPIRED_YEAR || st.wMonth > EXPIRED_MONTH)
{
InfoNES_MessageBox( EXPIRED_MSG );
exit( -1 );
}
#endif
/*-------------------------------------------------------------------*/
/* Init Resources */
/*-------------------------------------------------------------------*/
InfoNES_StartTimer();
CreateScreen( hWndMain );
ShowTitle( hWndMain );
/*-------------------------------------------------------------------*/
/* For Drag and Drop Function */
/*-------------------------------------------------------------------*/
if ( lpCmdLine[ 0 ] != '\0' )
{
// If included space characters, strip dobule quote marks
if ( lpCmdLine[ 0 ] == '"' )
{
lpCmdLine[ strlen( lpCmdLine ) - 1 ] = '\0';
lpCmdLine++;
}
// Load cassette
if ( InfoNES_Load( lpCmdLine ) == 0 )
{
// Set a ROM image name
strcpy( szRomName, lpCmdLine );
// Load SRAM
LoadSRAM();
// Create Emulation Thread
m_hThread = CreateThread( (LPSECURITY_ATTRIBUTES)NULL, (DWORD)0,
(LPTHREAD_START_ROUTINE)InfoNES_Main, (LPVOID)NULL, (DWORD)0, &m_ThreadID);
}
}
/*-------------------------------------------------------------------*/
/* The Mess
- 1
- 2
- 3
前往页