2006-02-25 20:50:29 +00:00
/*
AppleWin : An Apple //e emulator for Windows
Copyright ( C ) 1994 - 1996 , Michael O ' Brien
Copyright ( C ) 1999 - 2001 , Oliver Schmidt
Copyright ( C ) 2002 - 2005 , Tom Charlesworth
2014-09-08 21:25:29 +00:00
Copyright ( C ) 2006 - 2014 , Tom Charlesworth , Michael Pohoreski
2006-02-25 20:50:29 +00:00
AppleWin is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
AppleWin is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with AppleWin ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/* Description: main
*
* Author : Various
*/
# include "StdAfx.h"
2014-08-13 20:30:35 +00:00
# include "AppleWin.h"
# include "CPU.h"
# include "Debug.h"
# include "Disk.h"
2010-01-03 18:43:08 +00:00
# include "DiskImage.h"
2014-08-13 20:30:35 +00:00
# include "Frame.h"
2010-01-03 18:43:08 +00:00
# include "Harddisk.h"
2014-09-14 20:23:54 +00:00
# include "Joystick.h"
2014-08-13 20:30:35 +00:00
# include "Log.h"
# include "Memory.h"
# include "Mockingboard.h"
2007-08-06 21:38:35 +00:00
# include "MouseInterface.h"
2014-08-13 20:30:35 +00:00
# include "ParallelPrinter.h"
# include "Registry.h"
# include "Riff.h"
# include "SaveState.h"
# include "SerialComms.h"
# include "SoundCore.h"
# include "Speaker.h"
2010-02-14 21:11:26 +00:00
# ifdef USE_SPEECH_API
# include "Speech.h"
# endif
2014-08-13 20:30:35 +00:00
# include "Video.h"
2013-08-08 21:13:31 +00:00
# include "Configuration\About.h"
2012-03-27 21:20:36 +00:00
# include "Configuration\PropertySheet.h"
# include "Tfe\Tfe.h"
2006-02-25 20:50:29 +00:00
2008-08-25 00:53:19 +00:00
char VERSIONSTRING [ 16 ] = " xx.yy.zz.ww " ;
2006-02-25 20:50:29 +00:00
2007-05-28 11:16:42 +00:00
TCHAR * g_pAppTitle = TITLE_APPLE_2E_ENHANCED ;
2006-06-27 02:34:46 +00:00
2012-09-16 21:53:07 +00:00
eApple2Type g_Apple2Type = A2TYPE_APPLE2EENHANCED ;
2006-06-12 22:06:50 +00:00
2006-02-25 20:50:29 +00:00
bool g_bFullSpeed = false ;
2006-07-02 09:56:50 +00:00
2008-06-20 23:47:25 +00:00
//Pravets 8A/C variables
bool P8CAPS_ON = false ;
bool P8Shift = false ;
//=================================================
2006-07-02 09:56:50 +00:00
// Win32
HINSTANCE g_hInstance = ( HINSTANCE ) 0 ;
2006-06-12 22:06:50 +00:00
AppMode_e g_nAppMode = MODE_LOGO ;
2013-04-26 21:55:45 +00:00
static bool g_bLoadedSaveState = false ;
2006-06-12 22:06:50 +00:00
2011-02-15 17:22:33 +00:00
TCHAR g_sProgramDir [ MAX_PATH ] = TEXT ( " " ) ; // Directory of where AppleWin executable resides
TCHAR g_sDebugDir [ MAX_PATH ] = TEXT ( " " ) ; // TODO: Not currently used
TCHAR g_sScreenShotDir [ MAX_PATH ] = TEXT ( " " ) ; // TODO: Not currently used
TCHAR g_sCurrentDir [ MAX_PATH ] = TEXT ( " " ) ; // Also Starting Dir. Debugger uses this when load/save
2006-02-25 20:50:29 +00:00
BOOL restart = 0 ;
DWORD g_dwSpeed = SPEED_NORMAL ; // Affected by Config dialog's speed slider bar
double g_fCurrentCLK6502 = CLK_6502 ; // Affected by Config dialog's speed slider bar
static double g_fMHz = 1.0 ; // Affected by Config dialog's speed slider bar
int g_nCpuCyclesFeedback = 0 ;
2006-03-12 09:05:39 +00:00
DWORD g_dwCyclesThisFrame = 0 ;
2006-02-25 20:50:29 +00:00
FILE * g_fh = NULL ;
2013-03-23 14:14:48 +00:00
bool g_bDisableDirectInput = false ;
2006-02-25 20:50:29 +00:00
bool g_bDisableDirectSound = false ;
2009-10-07 21:38:42 +00:00
bool g_bDisableDirectSoundMockingboard = false ;
2014-09-08 21:25:29 +00:00
int g_nMemoryClearType = MIP_FF_FF_00_00 ; // Note: -1 = random MIP in Memory.cpp MemReset()
2006-02-25 20:50:29 +00:00
2012-05-06 22:14:03 +00:00
IPropertySheet & sg_PropertySheet = * new CPropertySheet ;
2007-08-06 21:38:35 +00:00
CSuperSerialCard sg_SSC ;
CMouseInterface sg_Mouse ;
2012-01-22 13:46:36 +00:00
SS_CARDTYPE g_Slot4 = CT_Empty ;
SS_CARDTYPE g_Slot5 = CT_Empty ;
2009-01-06 22:02:31 +00:00
eCPU g_ActiveCPU = CPU_6502 ;
2008-02-22 21:28:35 +00:00
HANDLE g_hCustomRomF8 = INVALID_HANDLE_VALUE ; // Cmd-line specified custom ROM at $F800..$FFFF
static bool g_bCustomRomF8Failed = false ; // Set if custom ROM file failed
2007-05-28 11:16:42 +00:00
2010-02-14 21:11:26 +00:00
static bool g_bEnableSpeech = false ;
2010-11-24 22:39:20 +00:00
# ifdef USE_SPEECH_API
2010-02-14 21:11:26 +00:00
CSpeech g_Speech ;
2010-11-24 22:39:20 +00:00
# endif
2010-02-14 21:11:26 +00:00
2006-02-25 20:50:29 +00:00
//===========================================================================
2013-04-26 21:55:45 +00:00
bool GetLoadedSaveStateFlag ( void )
{
return g_bLoadedSaveState ;
}
void SetLoadedSaveStateFlag ( const bool bFlag )
{
g_bLoadedSaveState = bFlag ;
}
static void ResetToLogoMode ( void )
{
g_nAppMode = MODE_LOGO ;
SetLoadedSaveStateFlag ( false ) ;
}
//---------------------------------------------------------------------------
2009-06-20 13:43:12 +00:00
static bool g_bPriorityNormal = true ;
// Make APPLEWIN process higher priority
2013-03-28 22:28:42 +00:00
void SetPriorityAboveNormal ( void )
2009-06-20 13:43:12 +00:00
{
if ( ! g_bPriorityNormal )
return ;
if ( SetPriorityClass ( GetCurrentProcess ( ) , ABOVE_NORMAL_PRIORITY_CLASS ) )
{
SetThreadPriority ( GetCurrentThread ( ) , THREAD_PRIORITY_ABOVE_NORMAL ) ;
g_bPriorityNormal = false ;
}
}
// Make APPLEWIN process normal priority
2013-03-28 22:28:42 +00:00
void SetPriorityNormal ( void )
2009-06-20 13:43:12 +00:00
{
if ( g_bPriorityNormal )
return ;
if ( SetPriorityClass ( GetCurrentProcess ( ) , NORMAL_PRIORITY_CLASS ) )
{
SetThreadPriority ( GetCurrentThread ( ) , THREAD_PRIORITY_NORMAL ) ;
g_bPriorityNormal = true ;
}
}
//---------------------------------------------------------------------------
2013-03-28 22:28:42 +00:00
void ContinueExecution ( void )
2006-02-25 20:50:29 +00:00
{
const double fUsecPerSec = 1.e6 ;
# if 1
const UINT nExecutionPeriodUsec = 1000 ; // 1.0ms
// const UINT nExecutionPeriodUsec = 100; // 0.1ms
const double fExecutionPeriodClks = g_fCurrentCLK6502 * ( ( double ) nExecutionPeriodUsec / fUsecPerSec ) ;
# else
const double fExecutionPeriodClks = 1800.0 ;
const UINT nExecutionPeriodUsec = ( UINT ) ( fUsecPerSec * ( fExecutionPeriodClks / g_fCurrentCLK6502 ) ) ;
# endif
//
2012-03-27 21:20:36 +00:00
bool bScrollLock_FullSpeed = sg_PropertySheet . GetScrollLockToggle ( )
2007-08-06 21:38:35 +00:00
? g_bScrollLock_FullSpeed
: ( GetKeyState ( VK_SCROLL ) < 0 ) ;
2006-02-25 20:50:29 +00:00
g_bFullSpeed = ( ( g_dwSpeed = = SPEED_MAX ) | |
2007-08-06 21:38:35 +00:00
bScrollLock_FullSpeed | |
2006-02-25 20:50:29 +00:00
( DiskIsSpinning ( ) & & enhancedisk & & ! Spkr_IsActive ( ) & & ! MB_IsActive ( ) ) ) ;
2013-03-28 22:28:42 +00:00
if ( g_bFullSpeed )
2006-02-25 20:50:29 +00:00
{
// Don't call Spkr_Mute() - will get speaker clicks
MB_Mute ( ) ;
SysClk_StopTimer ( ) ;
2010-11-24 22:39:20 +00:00
# ifdef USE_SPEECH_API
2010-02-14 21:11:26 +00:00
g_Speech . Reset ( ) ; // TODO: Put this on a timer (in emulated cycles)... otherwise CATALOG cuts out
2010-11-24 22:39:20 +00:00
# endif
2006-02-25 20:50:29 +00:00
g_nCpuCyclesFeedback = 0 ; // For the case when this is a big -ve number
2009-06-20 13:43:12 +00:00
// Switch to normal priority so that APPLEWIN process doesn't hog machine!
//. EG: No disk in Drive-1, and boot Apple: Windows will start to crawl!
SetPriorityNormal ( ) ;
2006-02-25 20:50:29 +00:00
}
else
{
// Don't call Spkr_Demute()
MB_Demute ( ) ;
SysClk_StartTimerUsec ( nExecutionPeriodUsec ) ;
2009-06-20 13:43:12 +00:00
// Switch to higher priority, eg. for audio (BUG #015394)
SetPriorityAboveNormal ( ) ;
2006-02-25 20:50:29 +00:00
}
//
int nCyclesToExecute = ( int ) fExecutionPeriodClks + g_nCpuCyclesFeedback ;
2013-03-28 22:28:42 +00:00
if ( nCyclesToExecute < 0 )
2006-02-25 20:50:29 +00:00
nCyclesToExecute = 0 ;
2014-09-14 20:23:54 +00:00
const DWORD uActualCyclesExecuted = CpuExecute ( nCyclesToExecute ) ;
g_dwCyclesThisFrame + = uActualCyclesExecuted ;
2006-02-25 20:50:29 +00:00
2014-09-14 20:23:54 +00:00
DiskUpdatePosition ( uActualCyclesExecuted ) ;
JoyUpdateButtonLatch ( nExecutionPeriodUsec ) ; // Button latch time is independent of CPU clock frequency
2006-02-25 20:50:29 +00:00
2014-09-14 20:23:54 +00:00
SpkrUpdate ( uActualCyclesExecuted ) ;
sg_SSC . CommUpdate ( uActualCyclesExecuted ) ;
PrintUpdate ( uActualCyclesExecuted ) ;
2006-02-25 20:50:29 +00:00
//
2013-03-28 22:28:42 +00:00
if ( g_dwCyclesThisFrame > = dwClksPerFrame )
2006-02-25 20:50:29 +00:00
{
2006-03-12 09:05:39 +00:00
g_dwCyclesThisFrame - = dwClksPerFrame ;
Simplified and moved main-loop video update logic into Video.cpp.
Removed complex case below for:
. VideoHasRefreshed(), 'anyupdates'
. VideoCheckPage()
Detailed notes below.
---
Video updates in ContinueExecution() loop:
'anyupdates' gets set if there were any page-flip(s) in last ~17030 cycles:
anyupdates |= VideoHasRefreshed();
ie. VideoRefreshScreen() was called outside of this loop.
If there's been a call to VideoRefreshScreen() outside of this loop,
and then the video framebuffer gets written to, ie. VideoApparentlyDirty() returns TRUE,
then don't call VideoRefreshScreen() from this loop for 3 frames.
(If a VideoRefreshScreen() is called outside of this loop then restart the 3 frame count.)
So..
if the game is flipping, the VideoApparentlyDirty() will return FALSE (since game writes to other framebuffer).
if the game is not flipping, then VideoHasRefreshed() will return FALSE (since no flips occur).
Therefore this complex case above probably only arises at a boundary eg. when the game is transitioning between these 2 modes,
and so if the emulator does the very occasional screen update in this main loop, it is of no consequence.
(I guess this extra logic was to throttle video updates on very old slow machines)
---
VideoCheckPage(BOOL bForce) was called twice in main-loop:
UnexpectedPage if g_bVideoDisplayPage2 != SW_PAGE2
Once each time through the loop (ie. every 1ms), with bForce=0
if UnexpectedPage && >500ms since last flip then VideoRefreshScreen()
Once each video frame (ie. ~17030 cycles) when not flipping, with bForce=1
if UnexpectedPage then VideoRefreshScreen()
Basically this was all about supporting FullSpeed mode, and limiting the calls to VideoRefreshScreen().
2014-09-13 21:22:27 +00:00
VideoEndOfVideoFrame ( ) ;
2007-08-06 21:38:35 +00:00
MB_EndOfVideoFrame ( ) ;
2006-02-25 20:50:29 +00:00
}
2013-03-28 22:28:42 +00:00
if ( ! g_bFullSpeed )
2006-02-25 20:50:29 +00:00
{
SysClk_WaitTimer ( ) ;
}
}
//===========================================================================
2013-03-28 22:28:42 +00:00
void SetCurrentCLK6502 ( void )
2006-02-25 20:50:29 +00:00
{
static DWORD dwPrevSpeed = ( DWORD ) - 1 ;
if ( dwPrevSpeed = = g_dwSpeed )
return ;
dwPrevSpeed = g_dwSpeed ;
// SPEED_MIN = 0 = 0.50 MHz
// SPEED_NORMAL = 10 = 1.00 MHz
// 20 = 2.00 MHz
// SPEED_MAX-1 = 39 = 3.90 MHz
// SPEED_MAX = 40 = ???? MHz (run full-speed, /g_fCurrentCLK6502/ is ignored)
if ( g_dwSpeed < SPEED_NORMAL )
g_fMHz = 0.5 + ( double ) g_dwSpeed * 0.05 ;
else
g_fMHz = ( double ) g_dwSpeed / 10.0 ;
g_fCurrentCLK6502 = CLK_6502 * g_fMHz ;
//
// Now re-init modules that are dependent on /g_fCurrentCLK6502/
//
SpkrReinitialize ( ) ;
MB_Reinitialize ( ) ;
}
//===========================================================================
2013-03-28 22:28:42 +00:00
void EnterMessageLoop ( void )
2006-06-12 22:06:50 +00:00
{
MSG message ;
2007-03-27 20:46:14 +00:00
PeekMessage ( & message , NULL , 0 , 0 , PM_NOREMOVE ) ;
2006-07-05 21:23:13 +00:00
while ( message . message ! = WM_QUIT )
{
2007-03-27 20:46:14 +00:00
if ( PeekMessage ( & message , NULL , 0 , 0 , PM_REMOVE ) )
2006-06-12 22:06:50 +00:00
{
2007-03-27 20:46:14 +00:00
TranslateMessage ( & message ) ;
DispatchMessage ( & message ) ;
while ( ( g_nAppMode = = MODE_RUNNING ) | | ( g_nAppMode = = MODE_STEPPING ) )
2006-06-12 22:06:50 +00:00
{
2007-03-27 20:46:14 +00:00
if ( PeekMessage ( & message , 0 , 0 , 0 , PM_REMOVE ) )
{
if ( message . message = = WM_QUIT )
return ;
TranslateMessage ( & message ) ;
DispatchMessage ( & message ) ;
}
else if ( g_nAppMode = = MODE_STEPPING )
{
DebugContinueStepping ( ) ;
}
else
{
ContinueExecution ( ) ;
if ( g_nAppMode ! = MODE_DEBUG )
{
if ( g_bFullSpeed )
ContinueExecution ( ) ;
}
}
2006-06-12 22:06:50 +00:00
}
}
2007-03-27 20:46:14 +00:00
else
2007-03-23 22:26:35 +00:00
{
2007-03-27 20:46:14 +00:00
if ( g_nAppMode = = MODE_DEBUG )
DebuggerUpdate ( ) ;
2009-07-03 20:37:42 +00:00
else if ( ( g_nAppMode = = MODE_LOGO ) | | ( g_nAppMode = = MODE_PAUSED ) )
2007-03-27 20:46:14 +00:00
Sleep ( 100 ) ; // Stop process hogging CPU
2007-03-23 22:26:35 +00:00
}
2006-07-05 21:23:13 +00:00
}
}
2006-06-12 22:06:50 +00:00
2006-02-25 20:50:29 +00:00
//===========================================================================
2013-03-28 22:28:42 +00:00
void GetProgramDirectory ( void )
{
GetModuleFileName ( ( HINSTANCE ) 0 , g_sProgramDir , MAX_PATH ) ;
g_sProgramDir [ MAX_PATH - 1 ] = 0 ;
int loop = _tcslen ( g_sProgramDir ) ;
while ( loop - - )
{
if ( ( g_sProgramDir [ loop ] = = TEXT ( ' \\ ' ) ) | | ( g_sProgramDir [ loop ] = = TEXT ( ' : ' ) ) )
{
g_sProgramDir [ loop + 1 ] = 0 ;
break ;
}
}
2006-02-25 20:50:29 +00:00
}
//===========================================================================
2013-12-31 22:40:10 +00:00
// Backwards compatibility with AppleWin <1.24.0
static void LoadConfigOldJoystick ( const UINT uJoyNum )
{
DWORD dwOldJoyType ;
if ( ! REGLOAD ( TEXT ( uJoyNum = = 0 ? REGVALUE_OLD_JOYSTICK0_EMU_TYPE : REGVALUE_OLD_JOYSTICK1_EMU_TYPE ) , & dwOldJoyType ) )
return ; // EG. Old AppleWin never installed
UINT uNewJoyType ;
switch ( dwOldJoyType )
{
case 0 : // Disabled
default :
uNewJoyType = J0C_DISABLED ;
break ;
case 1 : // PC Joystick
uNewJoyType = J0C_JOYSTICK1 ;
break ;
case 2 : // Keyboard (standard)
uNewJoyType = J0C_KEYBD_NUMPAD ;
sg_PropertySheet . SetJoystickCenteringControl ( JOYSTICK_MODE_FLOATING ) ;
break ;
case 3 : // Keyboard (centering)
uNewJoyType = J0C_KEYBD_NUMPAD ;
sg_PropertySheet . SetJoystickCenteringControl ( JOYSTICK_MODE_CENTERING ) ;
break ;
case 4 : // Mouse
uNewJoyType = J0C_MOUSE ;
break ;
}
joytype [ uJoyNum ] = uNewJoyType ;
}
2008-06-20 23:47:25 +00:00
//Reads configuration from the registry entries
2013-03-28 22:28:42 +00:00
void LoadConfiguration ( void )
2007-05-28 11:16:42 +00:00
{
2012-03-20 23:17:06 +00:00
DWORD dwComputerType ;
2007-05-28 11:16:42 +00:00
2012-03-20 23:17:06 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_APPLE2_TYPE ) , & dwComputerType ) )
{
if ( ( dwComputerType > = A2TYPE_MAX ) | | ( dwComputerType > = A2TYPE_UNDEFINED & & dwComputerType < A2TYPE_CLONE ) )
2012-09-16 21:53:07 +00:00
dwComputerType = A2TYPE_APPLE2EENHANCED ;
2008-06-20 23:47:25 +00:00
2012-03-20 23:17:06 +00:00
g_Apple2Type = ( eApple2Type ) dwComputerType ;
}
else // Support older AppleWin registry entries
{
2013-12-31 22:40:10 +00:00
REGLOAD ( TEXT ( REGVALUE_OLD_APPLE2_TYPE ) , & dwComputerType ) ;
2012-03-20 23:17:06 +00:00
switch ( dwComputerType )
2008-06-20 23:47:25 +00:00
{
2012-03-20 23:17:06 +00:00
// NB. No A2TYPE_APPLE2E (this is correct)
case 0 : g_Apple2Type = A2TYPE_APPLE2 ;
case 1 : g_Apple2Type = A2TYPE_APPLE2PLUS ;
2012-09-16 21:53:07 +00:00
case 2 : g_Apple2Type = A2TYPE_APPLE2EENHANCED ;
default : g_Apple2Type = A2TYPE_APPLE2EENHANCED ;
2008-06-20 23:47:25 +00:00
}
}
2007-05-28 11:16:42 +00:00
2008-06-20 23:47:25 +00:00
switch ( g_Apple2Type ) //Sets the character set for the Apple model/clone
{
case A2TYPE_APPLE2 : g_nCharsetType = 0 ; break ;
case A2TYPE_APPLE2PLUS : g_nCharsetType = 0 ; break ;
case A2TYPE_APPLE2E : g_nCharsetType = 0 ; break ;
2012-09-16 21:53:07 +00:00
case A2TYPE_APPLE2EENHANCED : g_nCharsetType = 0 ; break ;
2008-06-20 23:47:25 +00:00
case A2TYPE_PRAVETS82 : g_nCharsetType = 1 ; break ;
case A2TYPE_PRAVETS8A : g_nCharsetType = 2 ; break ;
2013-12-31 22:40:10 +00:00
case A2TYPE_PRAVETS8M : g_nCharsetType = 3 ; break ; //This charset has a very small difference with the PRAVETS82 one an probably has some misplaced characters. Still the Pravets82 charset is used, because setting charset to 3 results in some problems.
2008-06-20 23:47:25 +00:00
}
2013-12-31 22:40:10 +00:00
//
if ( ! REGLOAD ( TEXT ( REGVALUE_JOYSTICK0_EMU_TYPE ) , & joytype [ JN_JOYSTICK0 ] ) )
LoadConfigOldJoystick ( JN_JOYSTICK0 ) ;
if ( ! REGLOAD ( TEXT ( REGVALUE_JOYSTICK1_EMU_TYPE ) , & joytype [ JN_JOYSTICK1 ] ) )
LoadConfigOldJoystick ( JN_JOYSTICK1 ) ;
2008-04-11 21:54:06 +00:00
2013-03-28 22:28:42 +00:00
REGLOAD ( TEXT ( " Sound Emulation " ) , & soundtype ) ;
2007-05-28 11:16:42 +00:00
2013-03-28 22:28:42 +00:00
char aySerialPortName [ CSuperSerialCard : : SIZEOF_SERIALCHOICE_ITEM ] ;
if ( RegLoadString ( TEXT ( " Configuration " ) ,
TEXT ( REGVALUE_SERIAL_PORT_NAME ) ,
TRUE ,
aySerialPortName ,
sizeof ( aySerialPortName ) ) )
{
sg_SSC . SetSerialPortName ( aySerialPortName ) ;
}
2007-05-28 11:16:42 +00:00
2013-03-28 22:28:42 +00:00
REGLOAD ( TEXT ( REGVALUE_EMULATION_SPEED ) , & g_dwSpeed ) ;
REGLOAD ( TEXT ( REGVALUE_ENHANCE_DISK_SPEED ) , ( DWORD * ) & enhancedisk ) ;
2009-02-14 04:05:15 +00:00
2013-03-28 22:28:42 +00:00
Config_Load_Video ( ) ;
2009-02-14 04:05:15 +00:00
2013-03-28 22:28:42 +00:00
REGLOAD ( TEXT ( " Uthernet Active " ) , ( DWORD * ) & tfe_enabled ) ;
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
SetCurrentCLK6502 ( ) ;
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
//
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
DWORD dwTmp ;
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_THE_FREEZES_F8_ROM ) , & dwTmp ) )
sg_PropertySheet . SetTheFreezesF8Rom ( dwTmp ) ;
2007-08-06 21:38:35 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_SPKR_VOLUME ) , & dwTmp ) )
SpkrSetVolume ( dwTmp , sg_PropertySheet . GetVolumeMax ( ) ) ;
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_MB_VOLUME ) , & dwTmp ) )
MB_SetVolume ( dwTmp , sg_PropertySheet . GetVolumeMax ( ) ) ;
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_SAVE_STATE_ON_EXIT ) , & dwTmp ) )
g_bSaveStateOnExit = dwTmp ? true : false ;
2006-02-25 20:50:29 +00:00
2009-01-09 21:59:22 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_DUMP_TO_PRINTER ) , & dwTmp ) )
g_bDumpToPrinter = dwTmp ? true : false ;
2009-01-09 21:59:22 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_CONVERT_ENCODING ) , & dwTmp ) )
g_bConvertEncoding = dwTmp ? true : false ;
2009-01-09 21:59:22 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_FILTER_UNPRINTABLE ) , & dwTmp ) )
g_bFilterUnprintable = dwTmp ? true : false ;
2009-01-09 21:59:22 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_PRINTER_APPEND ) , & dwTmp ) )
g_bPrinterAppend = dwTmp ? true : false ;
2009-01-09 21:59:22 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_HDD_ENABLED ) , & dwTmp ) )
HD_SetEnabled ( dwTmp ? true : false ) ;
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
char szHDVPathname [ MAX_PATH ] = { 0 } ;
if ( RegLoadString ( TEXT ( REG_PREFS ) , TEXT ( REGVALUE_PREF_LAST_HARDDISK_1 ) , 1 , szHDVPathname , sizeof ( szHDVPathname ) ) )
HD_InsertDisk ( HARDDISK_1 , szHDVPathname ) ;
if ( RegLoadString ( TEXT ( REG_PREFS ) , TEXT ( REGVALUE_PREF_LAST_HARDDISK_2 ) , 1 , szHDVPathname , sizeof ( szHDVPathname ) ) )
HD_InsertDisk ( HARDDISK_2 , szHDVPathname ) ;
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_PDL_XTRIM ) , & dwTmp ) )
JoySetTrim ( ( short ) dwTmp , true ) ;
if ( REGLOAD ( TEXT ( REGVALUE_PDL_YTRIM ) , & dwTmp ) )
JoySetTrim ( ( short ) dwTmp , false ) ;
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_SCROLLLOCK_TOGGLE ) , & dwTmp ) )
sg_PropertySheet . SetScrollLockToggle ( dwTmp ) ;
2007-08-06 21:38:35 +00:00
2013-12-06 21:10:41 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_CURSOR_CONTROL ) , & dwTmp ) )
2013-12-31 22:40:10 +00:00
sg_PropertySheet . SetJoystickCursorControl ( dwTmp ) ;
2013-12-06 21:10:41 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_AUTOFIRE ) , & dwTmp ) )
sg_PropertySheet . SetAutofire ( dwTmp ) ;
2013-12-31 22:40:10 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_CENTERING_CONTROL ) , & dwTmp ) )
sg_PropertySheet . SetJoystickCenteringControl ( dwTmp ) ;
2013-12-06 21:10:41 +00:00
2013-03-28 22:28:42 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_MOUSE_CROSSHAIR ) , & dwTmp ) )
sg_PropertySheet . SetMouseShowCrosshair ( dwTmp ) ;
if ( REGLOAD ( TEXT ( REGVALUE_MOUSE_RESTRICT_TO_WINDOW ) , & dwTmp ) )
sg_PropertySheet . SetMouseRestrictToWindow ( dwTmp ) ;
2008-08-19 21:36:31 +00:00
2012-03-20 23:17:06 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_SLOT4 ) , & dwTmp ) )
g_Slot4 = ( SS_CARDTYPE ) dwTmp ;
if ( REGLOAD ( TEXT ( REGVALUE_SLOT5 ) , & dwTmp ) )
g_Slot5 = ( SS_CARDTYPE ) dwTmp ;
2012-01-22 13:46:36 +00:00
2012-03-20 23:17:06 +00:00
if ( g_Slot4 = = CT_MockingboardC | | g_Slot4 = = CT_Phasor )
MB_SetSoundcardType ( g_Slot4 ) ;
2012-08-12 11:03:38 +00:00
else
MB_SetSoundcardType ( CT_Empty ) ;
2009-01-06 22:02:31 +00:00
2012-01-23 22:40:36 +00:00
//
2006-02-25 20:50:29 +00:00
2009-01-06 22:02:31 +00:00
char szFilename [ MAX_PATH ] = { 0 } ;
2009-01-09 21:59:22 +00:00
2009-01-06 22:02:31 +00:00
// Current/Starting Dir is the "root" of where the user keeps his disk images
2013-12-29 22:09:41 +00:00
RegLoadString ( TEXT ( REG_PREFS ) , TEXT ( REGVALUE_PREF_START_DIR ) , 1 , szFilename , MAX_PATH ) ;
if ( szFilename [ 0 ] = = 0 )
GetCurrentDirectory ( sizeof ( szFilename ) , szFilename ) ;
SetCurrentImageDir ( szFilename ) ;
2009-01-06 22:02:31 +00:00
2010-01-03 18:43:08 +00:00
Disk_LoadLastDiskImage ( DRIVE_1 ) ;
Disk_LoadLastDiskImage ( DRIVE_2 ) ;
2009-01-06 22:02:31 +00:00
2013-12-29 22:09:41 +00:00
//
szFilename [ 0 ] = 0 ;
RegLoadString ( TEXT ( REG_CONFIG ) , TEXT ( REGVALUE_SAVESTATE_FILENAME ) , 1 , szFilename , sizeof ( szFilename ) ) ;
Snapshot_SetFilename ( szFilename ) ; // If not in Registry than default will be used (ie. g_sCurrentDir + default filename)
szFilename [ 0 ] = 0 ;
RegLoadString ( TEXT ( REG_CONFIG ) , TEXT ( REGVALUE_PRINTER_FILENAME ) , 1 , szFilename , sizeof ( szFilename ) ) ;
Printer_SetFilename ( szFilename ) ; // If not in Registry than default will be used
2009-01-09 21:59:22 +00:00
dwTmp = 10 ;
2009-01-09 23:27:29 +00:00
REGLOAD ( TEXT ( REGVALUE_PRINTER_IDLE_LIMIT ) , & dwTmp ) ;
2009-01-09 21:59:22 +00:00
Printer_SetIdleLimit ( dwTmp ) ;
2009-01-06 22:02:31 +00:00
char szUthernetInt [ MAX_PATH ] = { 0 } ;
RegLoadString ( TEXT ( REG_CONFIG ) , TEXT ( " Uthernet Interface " ) , 1 , szUthernetInt , MAX_PATH ) ;
update_tfe_interface ( szUthernetInt , NULL ) ;
2012-12-29 14:53:52 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_WINDOW_SCALE ) , & dwTmp ) )
SetViewportScale ( dwTmp ) ;
2014-07-26 21:51:23 +00:00
2014-07-27 21:31:00 +00:00
if ( REGLOAD ( TEXT ( REGVALUE_CONFIRM_REBOOT ) , & dwTmp ) )
g_bConfirmReboot = dwTmp ;
2009-01-06 22:02:31 +00:00
}
2006-02-25 20:50:29 +00:00
2009-01-06 22:02:31 +00:00
//===========================================================================
2008-06-21 11:48:15 +00:00
2013-12-29 22:09:41 +00:00
void SetCurrentImageDir ( const char * pszImageDir )
2009-01-06 22:02:31 +00:00
{
2013-12-29 22:09:41 +00:00
strcpy ( g_sCurrentDir , pszImageDir ) ;
2014-09-02 15:48:46 +00:00
int nLen = strlen ( g_sCurrentDir ) ;
if ( g_sCurrentDir [ nLen - 1 ] ! = ' \\ ' )
{
2014-09-04 00:14:06 +00:00
g_sCurrentDir [ nLen + 0 ] = ' \\ ' ;
g_sCurrentDir [ nLen + 1 ] = 0 ;
2014-09-02 15:48:46 +00:00
}
2009-01-06 22:02:31 +00:00
SetCurrentDirectory ( g_sCurrentDir ) ;
2008-06-21 11:48:15 +00:00
}
2010-01-03 18:43:08 +00:00
//===========================================================================
2009-02-14 04:05:15 +00:00
// TODO: Added dialog option of which file extensions to registry
2013-03-28 22:28:42 +00:00
static bool g_bRegisterFileTypes = true ;
//static bool g_bRegistryFileBin = false;
static bool g_bRegistryFileDo = true ;
static bool g_bRegistryFileDsk = true ;
static bool g_bRegistryFileNib = true ;
static bool g_bRegistryFilePo = true ;
2009-02-14 04:05:15 +00:00
2013-03-28 22:28:42 +00:00
void RegisterExtensions ( void )
2006-05-02 21:56:28 +00:00
{
TCHAR szCommandTmp [ MAX_PATH ] ;
GetModuleFileName ( ( HMODULE ) 0 , szCommandTmp , MAX_PATH ) ;
2010-01-03 18:43:08 +00:00
# ifdef TEST_REG_BUG
2009-02-14 04:05:15 +00:00
TCHAR command [ MAX_PATH ] ;
wsprintf ( command , " %s " , szCommandTmp ) ; // Wrap path & filename in quotes & null terminate
TCHAR icon [ MAX_PATH ] ;
wsprintf ( icon , TEXT ( " \" %s,1 \" " ) , ( LPCTSTR ) command ) ;
# endif
2010-01-03 18:43:08 +00:00
2006-05-02 21:56:28 +00:00
TCHAR command [ MAX_PATH ] ;
wsprintf ( command , " \" %s \" " , szCommandTmp ) ; // Wrap path & filename in quotes & null terminate
TCHAR icon [ MAX_PATH ] ;
wsprintf ( icon , TEXT ( " %s,1 " ) , ( LPCTSTR ) command ) ;
_tcscat ( command , TEXT ( " \" %1 \" " ) ) ; // Append "%1"
2009-02-14 04:05:15 +00:00
// _tcscat(command,TEXT("-d1 %1\"")); // Append "%1"
// sprintf(command, "\"%s\" \"-d1 %%1\"", szCommandTmp); // Wrap path & filename in quotes & null terminate
2006-05-02 21:56:28 +00:00
2010-01-03 18:43:08 +00:00
// NB. Reflect extensions in DELREG.INF
// RegSetValue(HKEY_CLASSES_ROOT,".bin",REG_SZ,"DiskImage",10); // Removed as .bin is too generic
long Res = RegDeleteValue ( HKEY_CLASSES_ROOT , " .bin " ) ; // TODO: This isn't working :-/
2006-05-02 21:56:28 +00:00
RegSetValue ( HKEY_CLASSES_ROOT , " .do " , REG_SZ , " DiskImage " , 10 ) ;
RegSetValue ( HKEY_CLASSES_ROOT , " .dsk " , REG_SZ , " DiskImage " , 10 ) ;
RegSetValue ( HKEY_CLASSES_ROOT , " .nib " , REG_SZ , " DiskImage " , 10 ) ;
RegSetValue ( HKEY_CLASSES_ROOT , " .po " , REG_SZ , " DiskImage " , 10 ) ;
2010-01-03 18:43:08 +00:00
// RegSetValue(HKEY_CLASSES_ROOT,".2mg",REG_SZ,"DiskImage",10); // Don't grab this, as not all .2mg images are supported (so defer to CiderPress)
// RegSetValue(HKEY_CLASSES_ROOT,".2img",REG_SZ,"DiskImage",10); // Don't grab this, as not all .2mg images are supported (so defer to CiderPress)
2006-05-02 21:56:28 +00:00
// RegSetValue(HKEY_CLASSES_ROOT,".aws",REG_SZ,"DiskImage",10); // TO DO
// RegSetValue(HKEY_CLASSES_ROOT,".hdv",REG_SZ,"DiskImage",10); // TO DO
RegSetValue ( HKEY_CLASSES_ROOT ,
" DiskImage " ,
REG_SZ , " Disk Image " , 21 ) ;
RegSetValue ( HKEY_CLASSES_ROOT ,
" DiskImage \\ DefaultIcon " ,
REG_SZ , icon , _tcslen ( icon ) + 1 ) ;
2009-02-14 04:05:15 +00:00
// This key can interfere....
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExt\.dsk
2006-05-02 21:56:28 +00:00
RegSetValue ( HKEY_CLASSES_ROOT ,
" DiskImage \\ shell \\ open \\ command " ,
REG_SZ , command , _tcslen ( command ) + 1 ) ;
RegSetValue ( HKEY_CLASSES_ROOT ,
" DiskImage \\ shell \\ open \\ ddeexec " ,
REG_SZ , " %1 " , 3 ) ;
RegSetValue ( HKEY_CLASSES_ROOT ,
" DiskImage \\ shell \\ open \\ ddeexec \\ application " ,
2009-02-14 04:05:15 +00:00
REG_SZ , " applewin " , _tcslen ( " applewin " ) + 1 ) ;
// REG_SZ,szCommandTmp,_tcslen(szCommandTmp)+1);
2006-05-02 21:56:28 +00:00
RegSetValue ( HKEY_CLASSES_ROOT ,
" DiskImage \\ shell \\ open \\ ddeexec \\ topic " ,
2009-02-14 04:05:15 +00:00
REG_SZ , " system " , _tcslen ( " system " ) + 1 ) ;
2006-02-25 20:50:29 +00:00
}
2008-07-14 16:02:44 +00:00
//===========================================================================
2013-03-28 22:28:42 +00:00
void AppleWin_RegisterHotKeys ( void )
2009-01-06 22:02:31 +00:00
{
BOOL bStatus = true ;
2014-08-25 15:35:43 +00:00
bStatus & = RegisterHotKey (
g_hFrameWindow , // HWND hWnd
VK_SNAPSHOT_560 , // int id (user/custom id)
0 , // UINT fsModifiers
VK_SNAPSHOT // UINT vk = PrintScreen
2009-01-06 22:02:31 +00:00
) ;
2014-08-25 15:35:43 +00:00
bStatus & = RegisterHotKey (
g_hFrameWindow , // HWND hWnd
2009-01-06 22:02:31 +00:00
VK_SNAPSHOT_280 , // int id (user/custom id)
2014-08-25 15:35:43 +00:00
MOD_SHIFT , // UINT fsModifiers
VK_SNAPSHOT // UINT vk = PrintScreen
) ;
bStatus & = RegisterHotKey (
g_hFrameWindow , // HWND hWnd
VK_SNAPSHOT_TEXT , // int id (user/custom id)
MOD_CONTROL , // UINT fsModifiers
VK_SNAPSHOT // UINT vk = PrintScreen
2009-01-06 22:02:31 +00:00
) ;
2013-12-23 03:20:54 +00:00
if ( ! bStatus & & g_bShowPrintScreenWarningDialog )
2009-01-06 22:02:31 +00:00
{
MessageBox ( g_hFrameWindow , " Unable to capture PrintScreen key " , " Warning " , MB_OK ) ;
}
}
//===========================================================================
2008-02-22 21:28:35 +00:00
LPSTR GetCurrArg ( LPSTR lpCmdLine )
{
if ( * lpCmdLine = = ' \" ' )
lpCmdLine + + ;
return lpCmdLine ;
}
2006-02-25 20:50:29 +00:00
LPSTR GetNextArg ( LPSTR lpCmdLine )
{
int bInQuotes = 0 ;
while ( * lpCmdLine )
{
if ( * lpCmdLine = = ' \" ' )
{
bInQuotes ^ = 1 ;
if ( ! bInQuotes )
{
* lpCmdLine + + = 0x00 ; // Assume end-quote is end of this arg
continue ;
}
}
if ( ( * lpCmdLine = = ' ' ) & & ! bInQuotes )
{
* lpCmdLine + + = 0x00 ;
break ;
}
lpCmdLine + + ;
}
return lpCmdLine ;
}
//---------------------------------------------------------------------------
2010-01-17 18:43:06 +00:00
static int DoDiskInsert ( const int nDrive , LPCSTR szFileName )
2006-02-25 20:50:29 +00:00
{
2014-08-14 19:29:01 +00:00
std : : string strPathName ;
2010-01-17 18:43:06 +00:00
if ( szFileName [ 0 ] = = ' \\ ' | | szFileName [ 1 ] = = ' : ' )
{
// Abs pathname
strPathName = szFileName ;
}
else
{
// Rel pathname
char szCWD [ _MAX_PATH ] = { 0 } ;
if ( ! GetCurrentDirectory ( sizeof ( szCWD ) , szCWD ) )
return false ;
strPathName = szCWD ;
strPathName . append ( " \\ " ) ;
strPathName . append ( szFileName ) ;
}
ImageError_e Error = DiskInsert ( nDrive , strPathName . c_str ( ) , IMAGE_USE_FILES_WRITE_PROTECT_STATUS , IMAGE_DONT_CREATE ) ;
return Error = = eIMAGE_ERROR_NONE ;
2006-02-25 20:50:29 +00:00
}
//---------------------------------------------------------------------------
2013-03-28 22:28:42 +00:00
int APIENTRY WinMain ( HINSTANCE passinstance , HINSTANCE , LPSTR lpCmdLine , int )
2006-02-25 20:50:29 +00:00
{
bool bSetFullScreen = false ;
bool bBoot = false ;
LPSTR szImageName_drive1 = NULL ;
LPSTR szImageName_drive2 = NULL ;
2013-03-28 22:28:42 +00:00
const std : : string strCmdLine ( lpCmdLine ) ; // Keep a copy for log ouput
2006-02-25 20:50:29 +00:00
2013-03-28 22:28:42 +00:00
while ( * lpCmdLine )
2006-02-25 20:50:29 +00:00
{
LPSTR lpNextArg = GetNextArg ( lpCmdLine ) ;
2013-03-28 22:28:42 +00:00
if ( ( ( strcmp ( lpCmdLine , " -l " ) = = 0 ) | | ( strcmp ( lpCmdLine , " -log " ) = = 0 ) ) & & ( g_fh = = NULL ) )
{
g_fh = fopen ( " AppleWin.log " , " a+t " ) ; // Open log file (append & text mode)
setvbuf ( g_fh , NULL , _IONBF , 0 ) ; // No buffering (so implicit fflush after every fprintf)
CHAR aDateStr [ 80 ] , aTimeStr [ 80 ] ;
GetDateFormat ( LOCALE_SYSTEM_DEFAULT , 0 , NULL , NULL , ( LPTSTR ) aDateStr , sizeof ( aDateStr ) ) ;
GetTimeFormat ( LOCALE_SYSTEM_DEFAULT , 0 , NULL , NULL , ( LPTSTR ) aTimeStr , sizeof ( aTimeStr ) ) ;
fprintf ( g_fh , " *** Logging started: %s %s \n " , aDateStr , aTimeStr ) ;
}
else if ( strcmp ( lpCmdLine , " -noreg " ) = = 0 )
2009-02-14 04:05:15 +00:00
{
g_bRegisterFileTypes = false ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -d1 " ) = = 0 )
2006-02-25 20:50:29 +00:00
{
2008-02-22 21:28:35 +00:00
lpCmdLine = GetCurrArg ( lpNextArg ) ;
lpNextArg = GetNextArg ( lpNextArg ) ;
2006-02-25 20:50:29 +00:00
szImageName_drive1 = lpCmdLine ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -d2 " ) = = 0 )
2006-02-25 20:50:29 +00:00
{
2008-02-22 21:28:35 +00:00
lpCmdLine = GetCurrArg ( lpNextArg ) ;
lpNextArg = GetNextArg ( lpNextArg ) ;
2006-02-25 20:50:29 +00:00
szImageName_drive2 = lpCmdLine ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -f " ) = = 0 )
2006-02-25 20:50:29 +00:00
{
bSetFullScreen = true ;
}
2014-06-26 21:44:02 +00:00
else if ( strcmp ( lpCmdLine , " -fs8bit " ) = = 0 )
{
SetFullScreen32Bit ( false ) ; // Support old v1.24 fullscreen 8-bit palette mode
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -no-di " ) = = 0 )
2013-03-23 14:14:48 +00:00
{
g_bDisableDirectInput = true ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -m " ) = = 0 )
2006-02-25 20:50:29 +00:00
{
g_bDisableDirectSound = true ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -no-mb " ) = = 0 )
2009-10-07 21:38:42 +00:00
{
g_bDisableDirectSoundMockingboard = true ;
}
2014-07-18 03:18:59 +00:00
else if ( strcmp ( lpCmdLine , " -memclear " ) = = 0 )
{
lpCmdLine = GetCurrArg ( lpNextArg ) ;
lpNextArg = GetNextArg ( lpNextArg ) ;
g_nMemoryClearType = atoi ( lpCmdLine ) ;
if ( g_nMemoryClearType < 0 )
g_nMemoryClearType = 0 ;
else
if ( g_nMemoryClearType > = NUM_MIP )
g_nMemoryClearType = NUM_MIP - 1 ;
}
2006-02-25 20:50:29 +00:00
# ifdef RAMWORKS
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -r " ) = = 0 ) // RamWorks size [1..127]
2006-02-25 20:50:29 +00:00
{
2008-02-22 21:28:35 +00:00
lpCmdLine = GetCurrArg ( lpNextArg ) ;
lpNextArg = GetNextArg ( lpNextArg ) ;
2006-02-25 20:50:29 +00:00
g_uMaxExPages = atoi ( lpCmdLine ) ;
if ( g_uMaxExPages > 127 )
g_uMaxExPages = 128 ;
else if ( g_uMaxExPages < 1 )
g_uMaxExPages = 1 ;
}
# endif
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -f8rom " ) = = 0 ) // Use custom 2K ROM at [$F800..$FFFF]
2008-02-22 21:28:35 +00:00
{
lpCmdLine = GetCurrArg ( lpNextArg ) ;
lpNextArg = GetNextArg ( lpNextArg ) ;
g_hCustomRomF8 = CreateFile ( lpCmdLine , GENERIC_READ , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_READONLY , NULL ) ;
if ( ( g_hCustomRomF8 = = INVALID_HANDLE_VALUE ) | | ( GetFileSize ( g_hCustomRomF8 , NULL ) ! = 0x800 ) )
g_bCustomRomF8Failed = true ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -printscreen " ) = = 0 ) // Turn on display of the last filename print screen was saved to
2009-01-06 22:02:31 +00:00
{
g_bDisplayPrintScreenFileName = true ;
}
2013-12-23 03:20:54 +00:00
else if ( strcmp ( lpCmdLine , " -no-printscreen-dlg " ) = = 0 ) // Turn off the PrintScreen warning message dialog (if PrintScreen key can't be grabbed)
{
g_bShowPrintScreenWarningDialog = false ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -spkr-inc " ) = = 0 )
2009-10-07 21:38:42 +00:00
{
lpCmdLine = GetCurrArg ( lpNextArg ) ;
lpNextArg = GetNextArg ( lpNextArg ) ;
const int nErrorInc = atoi ( lpCmdLine ) ;
SoundCore_SetErrorInc ( nErrorInc ) ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -spkr-max " ) = = 0 )
2009-10-07 21:38:42 +00:00
{
lpCmdLine = GetCurrArg ( lpNextArg ) ;
lpNextArg = GetNextArg ( lpNextArg ) ;
const int nErrorMax = atoi ( lpCmdLine ) ;
SoundCore_SetErrorMax ( nErrorMax ) ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -use-real-printer " ) = = 0 ) // Enable control in Advanced config to allow dumping to a real printer
2009-01-17 15:10:00 +00:00
{
g_bEnableDumpToRealPrinter = true ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -speech " ) = = 0 )
2010-02-14 21:11:26 +00:00
{
g_bEnableSpeech = true ;
}
2013-03-28 22:28:42 +00:00
else if ( strcmp ( lpCmdLine , " -multimon " ) = = 0 )
2011-02-20 18:59:53 +00:00
{
g_bMultiMon = true ;
}
2013-03-28 22:28:42 +00:00
else // unsupported
{
LogFileOutput ( " Unsupported arg: %s \n " , lpCmdLine ) ;
}
2006-02-25 20:50:29 +00:00
lpCmdLine = lpNextArg ;
}
2013-03-28 22:28:42 +00:00
LogFileOutput ( " CmdLine: %s \n " , strCmdLine . c_str ( ) ) ;
2006-02-25 20:50:29 +00:00
#if 0
# ifdef RIFF_SPKR
RiffInitWriteFile ( " Spkr.wav " , SPKR_SAMPLE_RATE , 1 ) ;
# endif
# ifdef RIFF_MB
RiffInitWriteFile ( " Mockingboard.wav " , 44100 , 2 ) ;
# endif
# endif
//-----
char szPath [ _MAX_PATH ] ;
2013-03-28 22:28:42 +00:00
if ( 0 = = GetModuleFileName ( NULL , szPath , sizeof ( szPath ) ) )
2006-02-25 20:50:29 +00:00
{
strcpy ( szPath , __argv [ 0 ] ) ;
}
// Extract application version and store in a global variable
DWORD dwHandle , dwVerInfoSize ;
dwVerInfoSize = GetFileVersionInfoSize ( szPath , & dwHandle ) ;
2013-03-28 22:28:42 +00:00
if ( dwVerInfoSize > 0 )
2006-02-25 20:50:29 +00:00
{
char * pVerInfoBlock = new char [ dwVerInfoSize ] ;
2013-03-28 22:28:42 +00:00
if ( GetFileVersionInfo ( szPath , NULL , dwVerInfoSize , pVerInfoBlock ) )
2006-02-25 20:50:29 +00:00
{
VS_FIXEDFILEINFO * pFixedFileInfo ;
UINT pFixedFileInfoLen ;
VerQueryValue ( pVerInfoBlock , TEXT ( " \\ " ) , ( LPVOID * ) & pFixedFileInfo , ( PUINT ) & pFixedFileInfoLen ) ;
// Construct version string from fixed file info block
unsigned long major = pFixedFileInfo - > dwFileVersionMS > > 16 ;
unsigned long minor = pFixedFileInfo - > dwFileVersionMS & 0xffff ;
unsigned long fix = pFixedFileInfo - > dwFileVersionLS > > 16 ;
unsigned long fix_minor = pFixedFileInfo - > dwFileVersionLS & 0xffff ;
2009-01-06 22:02:31 +00:00
sprintf ( VERSIONSTRING , " %d.%d.%d.%d " , major , minor , fix , fix_minor ) ; // potential buffer overflow
2013-08-08 21:13:31 +00:00
}
2006-02-25 20:50:29 +00:00
}
2013-03-18 23:17:18 +00:00
LogFileOutput ( " AppleWin version: %s \n " , VERSIONSTRING ) ;
2006-02-25 20:50:29 +00:00
//-----
2008-02-22 21:28:35 +00:00
// Initialize COM - so we can use CoCreateInstance
2008-05-17 23:20:33 +00:00
// . NB. DSInit() & DIMouse::DirectInputInit are done when g_hFrameWindow is created (WM_CREATE)
2013-03-18 23:17:18 +00:00
HRESULT hr = CoInitializeEx ( NULL , COINIT_APARTMENTTHREADED ) ;
LogFileOutput ( " Init: CoInitializeEx(), hr=0x%08X \n " , hr ) ;
2010-12-30 20:10:48 +00:00
2013-03-18 23:17:18 +00:00
const bool bSysClkOK = SysClk_InitTimer ( ) ;
LogFileOutput ( " Init: SysClk_InitTimer(), res=%d \n " , bSysClkOK ? 1 : 0 ) ;
2010-02-14 21:11:26 +00:00
# ifdef USE_SPEECH_API
if ( g_bEnableSpeech )
{
2013-03-18 23:17:18 +00:00
const bool bSpeechOK = g_Speech . Init ( ) ;
LogFileOutput ( " Init: SysClk_InitTimer(), res=%d \n " , bSpeechOK ? 1 : 0 ) ;
2010-02-14 21:11:26 +00:00
}
# endif
2006-02-25 20:50:29 +00:00
// DO ONE-TIME INITIALIZATION
2006-07-02 09:56:50 +00:00
g_hInstance = passinstance ;
2006-02-25 20:50:29 +00:00
GdiSetBatchLimit ( 512 ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: GdiSetBatchLimit() \n " ) ;
2006-02-25 20:50:29 +00:00
GetProgramDirectory ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: GetProgramDirectory() \n " ) ;
2013-03-28 22:28:42 +00:00
if ( g_bRegisterFileTypes )
2009-02-14 04:05:15 +00:00
{
RegisterExtensions ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: RegisterExtensions() \n " ) ;
2009-02-14 04:05:15 +00:00
}
2013-03-18 23:17:18 +00:00
2006-02-25 20:50:29 +00:00
FrameRegisterClass ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: FrameRegisterClass() \n " ) ;
2006-02-25 20:50:29 +00:00
ImageInitialize ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: ImageInitialize() \n " ) ;
2006-02-25 20:50:29 +00:00
DiskInitialize ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: DiskInitialize() \n " ) ;
2010-07-07 15:23:16 +00:00
CreateColorMixMap ( ) ; // For tv emulation mode
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: CreateColorMixMap() \n " ) ;
2006-02-25 20:50:29 +00:00
2010-01-03 18:43:08 +00:00
int nError = 0 ; // TODO: Show error MsgBox if we get a DiskInsert error
2013-03-28 22:28:42 +00:00
if ( szImageName_drive1 )
2006-02-25 20:50:29 +00:00
{
2010-01-03 18:43:08 +00:00
nError = DoDiskInsert ( DRIVE_1 , szImageName_drive1 ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: DoDiskInsert(D1), res=%d \n " , nError ) ;
2009-02-14 04:05:15 +00:00
FrameRefreshStatus ( DRAW_LEDS | DRAW_BUTTON_DRIVES ) ;
2006-02-25 20:50:29 +00:00
bBoot = true ;
}
2013-03-28 22:28:42 +00:00
if ( szImageName_drive2 )
2006-02-25 20:50:29 +00:00
{
2010-01-03 18:43:08 +00:00
nError | = DoDiskInsert ( DRIVE_2 , szImageName_drive2 ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Init: DoDiskInsert(D2), res=%d \n " , nError ) ;
2006-02-25 20:50:29 +00:00
}
//
2009-05-09 14:37:08 +00:00
2006-02-25 20:50:29 +00:00
do
{
// DO INITIALIZATION THAT MUST BE REPEATED FOR A RESTART
restart = 0 ;
2013-04-26 21:55:45 +00:00
ResetToLogoMode ( ) ;
2013-03-18 23:17:18 +00:00
2006-02-25 20:50:29 +00:00
LoadConfiguration ( ) ;
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: LoadConfiguration() \n " ) ;
2013-03-18 23:17:18 +00:00
2006-02-25 20:50:29 +00:00
DebugInitialize ( ) ;
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: DebugInitialize() \n " ) ;
2013-03-18 23:17:18 +00:00
2006-02-25 20:50:29 +00:00
JoyInitialize ( ) ;
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: JoyInitialize() \n " ) ;
2013-03-18 23:17:18 +00:00
2006-02-25 20:50:29 +00:00
MemInitialize ( ) ;
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: MemInitialize() \n " ) ;
2013-03-18 23:17:18 +00:00
2009-02-16 19:18:34 +00:00
VideoInitialize ( ) ; // g_pFramebufferinfo been created now
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: VideoInitialize() \n " ) ;
2013-03-18 23:17:18 +00:00
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: FrameCreateWindow() - pre \n " ) ;
2013-08-08 21:13:31 +00:00
FrameCreateWindow ( ) ; // g_hFrameWindow is now valid
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: FrameCreateWindow() - post \n " ) ;
2013-03-18 23:17:18 +00:00
2013-08-08 21:13:31 +00:00
char szOldAppleWinVersion [ sizeof ( VERSIONSTRING ) ] = { 0 } ;
RegLoadString ( TEXT ( REG_CONFIG ) , TEXT ( REGVALUE_VERSION ) , 1 , szOldAppleWinVersion , sizeof ( szOldAppleWinVersion ) ) ;
const bool bShowAboutDlg = strcmp ( szOldAppleWinVersion , VERSIONSTRING ) ! = 0 ;
if ( bShowAboutDlg )
{
if ( ! AboutDlg ( ) )
PostMessage ( g_hFrameWindow , WM_DESTROY , 0 , 0 ) ; // Close everything down
else
RegSaveString ( TEXT ( REG_CONFIG ) , TEXT ( REGVALUE_VERSION ) , 1 , VERSIONSTRING ) ; // Only save version after user accepts license
}
2008-08-25 00:53:19 +00:00
// PrintScrn support
2009-01-06 22:02:31 +00:00
AppleWin_RegisterHotKeys ( ) ; // needs valid g_hFrameWindow
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: AppleWin_RegisterHotKeys() \n " ) ;
2008-07-14 16:02:44 +00:00
2008-02-22 21:28:35 +00:00
// Need to test if it's safe to call ResetMachineState(). In the meantime, just call DiskReset():
DiskReset ( ) ; // Switch from a booting A][+ to a non-autostart A][, so need to turn off floppy motor
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: DiskReset() \n " ) ;
2007-03-26 21:27:29 +00:00
if ( ! bSysClkOK )
{
MessageBox ( g_hFrameWindow , " DirectX failed to create SystemClock instance " , TEXT ( " AppleWin Error " ) , MB_OK ) ;
2007-03-27 20:46:14 +00:00
PostMessage ( g_hFrameWindow , WM_DESTROY , 0 , 0 ) ; // Close everything down
2007-03-26 21:27:29 +00:00
}
2008-02-22 21:28:35 +00:00
if ( g_bCustomRomF8Failed )
{
MessageBox ( g_hFrameWindow , " Failed to load custom F8 rom (not found or not exactly 2KB) " , TEXT ( " AppleWin Error " ) , MB_OK ) ;
PostMessage ( g_hFrameWindow , WM_DESTROY , 0 , 0 ) ; // Close everything down
}
2007-03-26 21:27:29 +00:00
tfe_init ( ) ;
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: tfe_init() \n " ) ;
2009-02-14 04:05:15 +00:00
Snapshot_Startup ( ) ; // Do this after everything has been init'ed
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: Snapshot_Startup() \n " ) ;
2009-02-14 04:05:15 +00:00
2013-03-28 22:28:42 +00:00
if ( bSetFullScreen )
2006-02-25 20:50:29 +00:00
{
2012-12-29 14:53:52 +00:00
PostMessage ( g_hFrameWindow , WM_USER_FULLSCREEN , 0 , 0 ) ;
2006-02-25 20:50:29 +00:00
bSetFullScreen = false ;
}
2013-03-28 22:28:42 +00:00
if ( bBoot )
2006-02-25 20:50:29 +00:00
{
2010-01-17 18:43:06 +00:00
PostMessage ( g_hFrameWindow , WM_USER_BOOT , 0 , 0 ) ;
2006-02-25 20:50:29 +00:00
bBoot = false ;
}
// ENTER THE MAIN MESSAGE LOOP
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: EnterMessageLoop() \n " ) ;
2006-02-25 20:50:29 +00:00
EnterMessageLoop ( ) ;
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: LeaveMessageLoop() \n " ) ;
2007-08-06 21:38:35 +00:00
2006-02-25 20:50:29 +00:00
MB_Reset ( ) ;
2013-03-28 22:28:42 +00:00
LogFileOutput ( " Main: MB_Reset() \n " ) ;
2013-03-18 23:17:18 +00:00
2013-03-28 22:28:42 +00:00
sg_Mouse . Uninitialize ( ) ; // Maybe restarting due to switching slot-4 card from MouseCard to Mockingboard
LogFileOutput ( " Main: sg_Mouse.Uninitialize() \n " ) ;
2006-02-25 20:50:29 +00:00
}
while ( restart ) ;
2013-03-28 22:28:42 +00:00
2006-02-25 20:50:29 +00:00
// Release COM
DSUninit ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Exit: DSUninit() \n " ) ;
2006-02-25 20:50:29 +00:00
SysClk_UninitTimer ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Exit: SysClk_UninitTimer() \n " ) ;
2006-02-25 20:50:29 +00:00
CoUninitialize ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Exit: CoUninitialize() \n " ) ;
2013-03-28 22:28:42 +00:00
2006-03-24 06:34:37 +00:00
tfe_shutdown ( ) ;
2013-03-18 23:17:18 +00:00
LogFileOutput ( " Exit: tfe_shutdown() \n " ) ;
2013-03-28 22:28:42 +00:00
2013-03-18 23:17:18 +00:00
if ( g_fh )
2006-02-25 20:50:29 +00:00
{
fprintf ( g_fh , " *** Logging ended \n \n " ) ;
fclose ( g_fh ) ;
2013-03-18 23:17:18 +00:00
g_fh = NULL ;
2006-02-25 20:50:29 +00:00
}
RiffFinishWriteFile ( ) ;
2008-02-22 21:28:35 +00:00
if ( g_hCustomRomF8 ! = INVALID_HANDLE_VALUE )
CloseHandle ( g_hCustomRomF8 ) ;
2006-02-25 20:50:29 +00:00
return 0 ;
}