0 | |
/*
|
1 | |
AppleWin : An Apple //e emulator for Windows
|
2 | |
|
3 | |
Copyright (C) 1994-1996, Michael O'Brien
|
4 | |
Copyright (C) 1999-2001, Oliver Schmidt
|
5 | |
Copyright (C) 2002-2005, Tom Charlesworth
|
6 | |
Copyright (C) 2006-2007, Tom Charlesworth, Michael Pohoreski
|
7 | |
|
8 | |
AppleWin is free software; you can redistribute it and/or modify
|
9 | |
it under the terms of the GNU General Public License as published by
|
10 | |
the Free Software Foundation; either version 2 of the License, or
|
11 | |
(at your option) any later version.
|
12 | |
|
13 | |
AppleWin is distributed in the hope that it will be useful,
|
14 | |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 | |
GNU General Public License for more details.
|
17 | |
|
18 | |
You should have received a copy of the GNU General Public License
|
19 | |
along with AppleWin; if not, write to the Free Software
|
20 | |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21 | |
*/
|
22 | |
|
23 | |
/* Description: main
|
24 | |
*
|
25 | |
* Author: Various
|
26 | |
*/
|
27 | |
|
28 | |
/* Adaptation for SDL and POSIX (l) by beom beotiger, Nov-Dec 2007, krez beotiger March 2012 AD */
|
29 | |
|
30 | |
#include "stdafx.h"
|
31 | |
//#pragma hdrstop
|
32 | |
#include "MouseInterface.h"
|
33 | |
|
34 | |
// for time logging
|
35 | |
#include <time.h>
|
36 | |
#include <sys/time.h>
|
37 | |
|
38 | |
#include <curl/curl.h>
|
39 | |
|
40 | |
#include <stdlib.h>
|
41 | |
|
42 | |
#include <iostream>
|
43 | |
#include <sys/types.h>
|
44 | |
#include <sys/stat.h>
|
45 | |
#include <fcntl.h>
|
46 | |
|
47 | |
//char VERSIONSTRING[] = "xx.yy.zz.ww";
|
48 | |
|
49 | |
TCHAR *g_pAppTitle = TITLE_APPLE_2E_ENHANCED;
|
50 | |
|
51 | |
eApple2Type g_Apple2Type = A2TYPE_APPLE2EEHANCED;
|
52 | |
|
53 | |
BOOL behind = 0; // Redundant
|
54 | |
DWORD cumulativecycles = 0; // Wraps after ~1hr 9mins
|
55 | |
DWORD cyclenum = 0; // Used by SpkrToggle() for non-wave sound
|
56 | |
DWORD emulmsec = 0;
|
57 | |
static DWORD emulmsec_frac = 0;
|
58 | |
bool g_bFullSpeed = false;
|
59 | |
bool hddenabled = false;
|
60 | |
static bool g_uMouseInSlot4 = false; // not any mouse in slot4??--bb
|
61 | |
// Win32
|
62 | |
//HINSTANCE g_hInstance = (HINSTANCE)0;
|
63 | |
|
64 | |
AppMode_e g_nAppMode = MODE_LOGO;
|
65 | |
|
66 | |
// Default screen sizes
|
67 | |
// SCREEN_WIDTH & SCREEN_HEIGHT defined in Frame.h
|
68 | |
UINT g_ScreenWidth = SCREEN_WIDTH;
|
69 | |
UINT g_ScreenHeight = SCREEN_HEIGHT;
|
70 | |
|
71 | |
//static int lastmode = MODE_LOGO; -- not used???
|
72 | |
DWORD needsprecision = 0; // Redundant
|
73 | |
//TCHAR g_sProgramDir[MAX_PATH] = TEXT("");
|
74 | |
TCHAR g_sCurrentDir[MAX_PATH] = TEXT(""); // Also Starting Dir for Slot6 disk images?? --bb
|
75 | |
TCHAR g_sHDDDir[MAX_PATH] = TEXT(""); // starting dir for HDV (Apple][ HDD) images?? --bb
|
76 | |
TCHAR g_sSaveStateDir[MAX_PATH] = TEXT(""); // starting dir for states --bb
|
77 | |
TCHAR g_sParallelPrinterFile[MAX_PATH] = TEXT("Printer.txt"); // default file name for Parallel printer
|
78 | |
|
79 | |
// FTP Variables
|
80 | |
TCHAR g_sFTPLocalDir[MAX_PATH] = TEXT(""); // FTP Local Dir, see linapple.conf for details
|
81 | |
TCHAR g_sFTPServer[MAX_PATH] = TEXT(""); // full path to default FTP server
|
82 | |
TCHAR g_sFTPServerHDD[MAX_PATH] = TEXT(""); // full path to default FTP server
|
83 | |
|
84 | |
//TCHAR g_sFTPUser[256] = TEXT("anonymous"); // user name
|
85 | |
//TCHAR g_sFTPPass[256] = TEXT("mymail@hotmail.com"); // password
|
86 | |
TCHAR g_sFTPUserPass[512] = TEXT("anonymous:mymail@hotmail.com"); // full login line
|
87 | |
|
88 | |
bool g_bResetTiming = false; // Redundant
|
89 | |
BOOL restart = 0;
|
90 | |
|
91 | |
// several parameters affecting the speed of emulated CPU
|
92 | |
DWORD g_dwSpeed = SPEED_NORMAL; // Affected by Config dialog's speed slider bar
|
93 | |
double g_fCurrentCLK6502 = CLK_6502; // Affected by Config dialog's speed slider bar
|
94 | |
static double g_fMHz = 1.0; // Affected by Config dialog's speed slider bar
|
95 | |
|
96 | |
int g_nCpuCyclesFeedback = 0;
|
97 | |
DWORD g_dwCyclesThisFrame = 0;
|
98 | |
|
99 | |
FILE* g_fh = NULL; // file for logging, let's use stderr instead?
|
100 | |
bool g_bDisableDirectSound = false; // direct sound, use SDL Sound, or SDL_mixer???
|
101 | |
|
102 | |
CSuperSerialCard sg_SSC;
|
103 | |
CMouseInterface sg_Mouse;
|
104 | |
|
105 | |
UINT g_Slot4 = CT_Mockingboard; // CT_Mockingboard or CT_MouseInterface
|
106 | |
|
107 | |
CURL *g_curl = NULL; // global easy curl resourse
|
108 | |
//===========================================================================
|
109 | |
|
110 | |
// ???? what is DBG_CALC_FREQ??? O_O --bb
|
111 | |
#define DBG_CALC_FREQ 0
|
112 | |
#if DBG_CALC_FREQ
|
113 | |
const UINT MAX_CNT = 256;
|
114 | |
double g_fDbg[MAX_CNT];
|
115 | |
UINT g_nIdx = 0;
|
116 | |
double g_fMeanPeriod,g_fMeanFreq;
|
117 | |
ULONG g_nPerfFreq = 0;
|
118 | |
#endif
|
119 | |
|
120 | |
|
121 | |
|
122 | |
//---------------------------------------------------------------------------
|
123 | |
|
124 | |
void ContinueExecution()
|
125 | |
{
|
126 | |
static BOOL pageflipping = 0; //?
|
127 | |
|
128 | |
const double fUsecPerSec = 1.e6;
|
129 | |
|
130 | |
const UINT nExecutionPeriodUsec = 1000; // 1.0ms
|
131 | |
const double fExecutionPeriodClks = g_fCurrentCLK6502 * ((double)nExecutionPeriodUsec / fUsecPerSec);
|
132 | |
|
133 | |
bool bScrollLock_FullSpeed = g_bScrollLock_FullSpeed; //g_uScrollLockToggle;
|
134 | |
|
135 | |
g_bFullSpeed = ( (g_dwSpeed == SPEED_MAX) ||
|
136 | |
bScrollLock_FullSpeed ||
|
137 | |
(DiskIsSpinning() && enhancedisk && !Spkr_IsActive() && !MB_IsActive()) );
|
138 | |
|
139 | |
if(g_bFullSpeed)
|
140 | |
{
|
141 | |
// Don't call Spkr_Mute() - will get speaker clicks
|
142 | |
MB_Mute();
|
143 | |
SysClk_StopTimer();
|
144 | |
g_nCpuCyclesFeedback = 0; // For the case when this is a big -ve number
|
145 | |
// SetPriorityNormal();
|
146 | |
}
|
147 | |
else
|
148 | |
{
|
149 | |
// Don't call Spkr_Demute()
|
150 | |
MB_Demute();
|
151 | |
SysClk_StartTimerUsec(nExecutionPeriodUsec);
|
152 | |
// Switch to higher priority, eg. for audio (BUG #015394)
|
153 | |
// SetPriorityAboveNormal();
|
154 | |
}
|
155 | |
|
156 | |
//
|
157 | |
|
158 | |
int nCyclesToExecute = (int) fExecutionPeriodClks + g_nCpuCyclesFeedback;
|
159 | |
if(nCyclesToExecute < 0)
|
160 | |
nCyclesToExecute = 0;
|
161 | |
|
162 | |
DWORD dwExecutedCycles = CpuExecute(nCyclesToExecute);
|
163 | |
g_dwCyclesThisFrame += dwExecutedCycles;
|
164 | |
|
165 | |
//
|
166 | |
|
167 | |
cyclenum = dwExecutedCycles;
|
168 | |
|
169 | |
DiskUpdatePosition(dwExecutedCycles);
|
170 | |
JoyUpdatePosition();
|
171 | |
// the next call does not present in current Applewin as on March 2012??
|
172 | |
VideoUpdateVbl(g_dwCyclesThisFrame);
|
173 | |
|
174 | |
SpkrUpdate(cyclenum);
|
175 | |
sg_SSC.CommUpdate(cyclenum);
|
176 | |
PrintUpdate(cyclenum);
|
177 | |
|
178 | |
//
|
179 | |
|
180 | |
const DWORD CLKS_PER_MS = (DWORD)g_fCurrentCLK6502 / 1000;
|
181 | |
|
182 | |
emulmsec_frac += dwExecutedCycles;
|
183 | |
if(emulmsec_frac > CLKS_PER_MS)
|
184 | |
{
|
185 | |
emulmsec += emulmsec_frac / CLKS_PER_MS;
|
186 | |
emulmsec_frac %= CLKS_PER_MS;
|
187 | |
}
|
188 | |
|
189 | |
//
|
190 | |
// DETERMINE WHETHER THE SCREEN WAS UPDATED, THE DISK WAS SPINNING,
|
191 | |
// OR THE KEYBOARD I/O PORTS WERE BEING EXCESSIVELY QUERIED THIS CLOCKTICK
|
192 | |
VideoCheckPage(0);
|
193 | |
BOOL screenupdated = VideoHasRefreshed();
|
194 | |
BOOL systemidle = 0; //(KeybGetNumQueries() > (clockgran << 2)); // && (!ranfinegrain); // TO DO
|
195 | |
|
196 | |
if(screenupdated)
|
197 | |
pageflipping = 3;
|
198 | |
|
199 | |
//
|
200 | |
|
201 | |
if(g_dwCyclesThisFrame >= dwClksPerFrame)
|
202 | |
{
|
203 | |
g_dwCyclesThisFrame -= dwClksPerFrame;
|
204 | |
|
205 | |
if(g_nAppMode != MODE_LOGO)
|
206 | |
{
|
207 | |
VideoUpdateFlash();
|
208 | |
|
209 | |
static BOOL anyupdates = 0;
|
210 | |
static DWORD lastcycles = 0;
|
211 | |
static BOOL lastupdates[2] = {0,0};
|
212 | |
|
213 | |
anyupdates |= screenupdated;
|
214 | |
|
215 | |
//
|
216 | |
|
217 | |
lastcycles = cumulativecycles;
|
218 | |
if ((!anyupdates) && (!lastupdates[0]) && (!lastupdates[1]) && VideoApparentlyDirty())
|
219 | |
{
|
220 | |
VideoCheckPage(1);
|
221 | |
static DWORD lasttime = 0;
|
222 | |
DWORD currtime = GetTickCount();
|
223 | |
if ((!g_bFullSpeed) ||
|
224 | |
(currtime-lasttime >= (DWORD)((graphicsmode || !systemidle) ? 100 : 25)))
|
225 | |
{
|
226 | |
VideoRefreshScreen();
|
227 | |
lasttime = currtime;
|
228 | |
}
|
229 | |
screenupdated = 1;
|
230 | |
}
|
231 | |
|
232 | |
lastupdates[1] = lastupdates[0];
|
233 | |
lastupdates[0] = anyupdates;
|
234 | |
anyupdates = 0;
|
235 | |
|
236 | |
if (pageflipping)
|
237 | |
pageflipping--;
|
238 | |
}
|
239 | |
|
240 | |
MB_EndOfVideoFrame();
|
241 | |
}
|
242 | |
|
243 | |
//
|
244 | |
|
245 | |
if(!g_bFullSpeed)
|
246 | |
{
|
247 | |
SysClk_WaitTimer();
|
248 | |
|
249 | |
#if DBG_CALC_FREQ
|
250 | |
if(g_nPerfFreq)
|
251 | |
{
|
252 | |
//QueryPerformanceCounter((LARGE_INTEGER*)&nTime1); QueryPerformanceFrequency
|
253 | |
LONG nTime1 = GetTickCount();//no QueryPerformanceCounter and alike
|
254 | |
LONG nTimeDiff = nTime1 - nTime0;
|
255 | |
double fTime = (double)nTimeDiff / (double)(LONG)g_nPerfFreq;
|
256 | |
|
257 | |
g_fDbg[g_nIdx] = fTime;
|
258 | |
g_nIdx = (g_nIdx+1) & (MAX_CNT-1);
|
259 | |
g_fMeanPeriod = 0.0;
|
260 | |
for(UINT n=0; n<MAX_CNT; n++)
|
261 | |
g_fMeanPeriod += g_fDbg[n];
|
262 | |
g_fMeanPeriod /= (double)MAX_CNT;
|
263 | |
g_fMeanFreq = 1.0 / g_fMeanPeriod;
|
264 | |
}
|
265 | |
#endif
|
266 | |
}
|
267 | |
}
|
268 | |
|
269 | |
//===========================================================================
|
270 | |
|
271 | |
void SetCurrentCLK6502()
|
272 | |
{
|
273 | |
static DWORD dwPrevSpeed = (DWORD) -1;
|
274 | |
|
275 | |
if(dwPrevSpeed == g_dwSpeed)
|
276 | |
return;
|
277 | |
|
278 | |
dwPrevSpeed = g_dwSpeed;
|
279 | |
|
280 | |
// SPEED_MIN = 0 = 0.50 MHz
|
281 | |
// SPEED_NORMAL = 10 = 1.00 MHz
|
282 | |
// 20 = 2.00 MHz
|
283 | |
// SPEED_MAX-1 = 39 = 3.90 MHz
|
284 | |
// SPEED_MAX = 40 = ???? MHz (run full-speed, /g_fCurrentCLK6502/ is ignored)
|
285 | |
|
286 | |
|
287 | |
if(g_dwSpeed < SPEED_NORMAL)
|
288 | |
g_fMHz = 0.5 + (double)g_dwSpeed * 0.05;
|
289 | |
else
|
290 | |
g_fMHz = (double)g_dwSpeed / 10.0;
|
291 | |
|
292 | |
g_fCurrentCLK6502 = CLK_6502 * g_fMHz;
|
293 | |
|
294 | |
//
|
295 | |
// Now re-init modules that are dependent on /g_fCurrentCLK6502/
|
296 | |
//
|
297 | |
|
298 | |
SpkrReinitialize();
|
299 | |
MB_Reinitialize();
|
300 | |
}
|
301 | |
|
302 | |
//===========================================================================
|
303 | |
void EnterMessageLoop ()
|
304 | |
{
|
305 | |
// MSG message;
|
306 | |
SDL_Event event;
|
307 | |
|
308 | |
// PeekMessage(&message, NULL, 0, 0, PM_NOREMOVE);
|
309 | |
while(true)
|
310 | |
|
311 | |
// while (message.message!=WM_QUIT)
|
312 | |
{
|
313 | |
if(SDL_PollEvent(&event))
|
314 | |
{
|
315 | |
if(event.type == SDL_QUIT && event.key.keysym.sym != SDLK_F4) return;
|
316 | |
FrameDispatchMessage(&event);
|
317 | |
|
318 | |
|
319 | |
|
320 | |
// if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
|
321 | |
// {
|
322 | |
// TranslateMessage(&message);
|
323 | |
// DispatchMessage(&message);
|
324 | |
|
325 | |
while ((g_nAppMode == MODE_RUNNING) || (g_nAppMode == MODE_STEPPING))
|
326 | |
{
|
327 | |
if(SDL_PollEvent(&event)) {
|
328 | |
if(event.type == SDL_QUIT && event.key.keysym.sym != SDLK_F4) return;
|
329 | |
FrameDispatchMessage(&event);
|
330 | |
}
|
331 | |
else if (g_nAppMode == MODE_STEPPING)
|
332 | |
{
|
333 | |
DebugContinueStepping();
|
334 | |
}
|
335 | |
else
|
336 | |
{
|
337 | |
ContinueExecution();
|
338 | |
if (g_nAppMode != MODE_DEBUG)
|
339 | |
{
|
340 | |
if (g_bFullSpeed)
|
341 | |
ContinueExecution();
|
342 | |
}
|
343 | |
}
|
344 | |
}
|
345 | |
}
|
346 | |
else
|
347 | |
{
|
348 | |
if (g_nAppMode == MODE_DEBUG)
|
349 | |
DebuggerUpdate();
|
350 | |
else if (g_nAppMode == MODE_LOGO || g_nAppMode == MODE_PAUSED)
|
351 | |
SDL_Delay(100); // Stop process hogging CPU
|
352 | |
}
|
353 | |
}
|
354 | |
}
|
355 | |
|
356 | |
//===========================================================================
|
357 | |
// void GetProgramDirectory () {
|
358 | |
// GetModuleFileName((HINSTANCE)0,g_sProgramDir,MAX_PATH);
|
359 | |
// g_sProgramDir[MAX_PATH-1] = 0;
|
360 | |
// int loop = _tcslen(g_sProgramDir);
|
361 | |
// while (loop--)
|
362 | |
// if ((g_sProgramDir[loop] == TEXT('\\')) ||
|
363 | |
// (g_sProgramDir[loop] == TEXT(':'))) {
|
364 | |
// g_sProgramDir[loop+1] = 0;
|
365 | |
// break;
|
366 | |
// }
|
367 | |
// }
|
368 | |
|
369 | |
|
370 | |
//---------------------------------------------------------------------------
|
371 | |
|
372 | |
int DoDiskInsert(int nDrive, LPSTR szFileName)
|
373 | |
{
|
374 | |
// DWORD dwAttributes = GetFileAttributes(szFileName);
|
375 | |
//
|
376 | |
//
|
377 | |
// if(dwAttributes == INVALID_FILE_ATTRIBUTES)
|
378 | |
// {
|
379 | |
// return -1;
|
380 | |
// }
|
381 | |
//
|
382 | |
// BOOL bWriteProtected = (dwAttributes & FILE_ATTRIBUTE_READONLY) ? TRUE : FALSE;
|
383 | |
|
384 | |
return DiskInsert(nDrive, szFileName, 0, 0);
|
385 | |
}
|
386 | |
|
387 | |
bool ValidateDirectory(char *dir)
|
388 | |
{
|
389 | |
bool ret = false;
|
390 | |
if (dir && *dir) {
|
391 | |
struct stat st;
|
392 | |
if(stat("/tmp",&st) == 0)
|
393 | |
if(st.st_mode & S_IFDIR != 0)
|
394 | |
ret = true;
|
395 | |
}
|
396 | |
printf("%s is dir? %d\n", dir, ret);
|
397 | |
return ret;
|
398 | |
}
|
399 | |
|
400 | |
void SetDiskImageDirectory( char *regKey, int driveNumber)
|
401 | |
{
|
402 | |
char *szHDFilename = NULL;
|
403 | |
if(RegLoadString(TEXT("Configuration"), TEXT(regKey), 1, &szHDFilename, MAX_PATH))
|
404 | |
{
|
405 | |
if(!ValidateDirectory(szHDFilename)) {
|
406 | |
RegSaveString(TEXT("Configuration"), TEXT(regKey), 1, "/");
|
407 | |
RegLoadString(TEXT("Configuration"), TEXT(regKey), 1, &szHDFilename, MAX_PATH);
|
408 | |
}
|
409 | |
|
410 | |
DoDiskInsert(driveNumber, szHDFilename);
|
411 | |
free(szHDFilename);
|
412 | |
}
|
413 | |
}
|
414 | |
|
415 | |
//===========================================================================
|
416 | |
// Let us load main configuration from config file. Y_Y --bb
|
417 | |
void LoadConfiguration ()
|
418 | |
{
|
419 | |
DWORD dwComputerType;
|
420 | |
|
421 | |
/* if (LOAD(TEXT(REGVALUE_APPLE2_TYPE),&dwComputerType))
|
422 | |
{
|
423 | |
if (dwComputerType >= A2TYPE_MAX)
|
424 | |
dwComputerType = A2TYPE_APPLE2EEHANCED;
|
425 | |
g_Apple2Type = (eApple2Type) dwComputerType;
|
426 | |
}
|
427 | |
else
|
428 | |
{*/
|
429 | |
LOAD(TEXT("Computer Emulation"),&dwComputerType);
|
430 | |
switch (dwComputerType)
|
431 | |
{
|
432 | |
// NB. No A2TYPE_APPLE2E
|
433 | |
|
434 | |
case 0: g_Apple2Type = A2TYPE_APPLE2;break;
|
435 | |
case 1: g_Apple2Type = A2TYPE_APPLE2PLUS;break;
|
436 | |
case 2: g_Apple2Type = A2TYPE_APPLE2EEHANCED;break;
|
437 | |
default: g_Apple2Type = A2TYPE_APPLE2EEHANCED;break;
|
438 | |
}
|
439 | |
// }
|
440 | |
// determine Apple type and set appropriate caption -- should be in (F9)switching modes?
|
441 | |
switch (g_Apple2Type)
|
442 | |
{
|
443 | |
case A2TYPE_APPLE2: g_pAppTitle = TITLE_APPLE_2; break;
|
444 | |
case A2TYPE_APPLE2PLUS: g_pAppTitle = TITLE_APPLE_2_PLUS; break;
|
445 | |
case A2TYPE_APPLE2E: g_pAppTitle = TITLE_APPLE_2E; break;
|
446 | |
case A2TYPE_APPLE2EEHANCED: g_pAppTitle = TITLE_APPLE_2E_ENHANCED; break;
|
447 | |
}
|
448 | |
|
449 | |
LOAD(TEXT("Joystick 0"),&joytype[0]);
|
450 | |
LOAD(TEXT("Joystick 1"),&joytype[1]);
|
451 | |
LOAD(TEXT("Sound Emulation") ,&soundtype);
|
452 | |
|
453 | |
DWORD dwSerialPort;
|
454 | |
LOAD(TEXT("Serial Port") ,&dwSerialPort);
|
455 | |
sg_SSC.SetSerialPort(dwSerialPort); // ----------- why it is here????
|
456 | |
|
457 | |
LOAD(TEXT("Emulation Speed") ,&g_dwSpeed);
|
458 | |
|
459 | |
LOAD(TEXT("Enhance Disk Speed"),(DWORD *)&enhancedisk);//
|
460 | |
LOAD(TEXT("Video Emulation") ,&g_videotype);
|
461 | |
// printf("Video Emulation = %d\n", videotype);
|
462 | |
|
463 | |
DWORD dwTmp = 0; // temp var
|
464 | |
|
465 | |
LOAD(TEXT("Fullscreen") ,&dwTmp); // load fullscreen flag
|
466 | |
fullscreen = (BOOL) dwTmp;
|
467 | |
dwTmp = 1;
|
468 | |
LOAD(TEXT(REGVALUE_SHOW_LEDS) ,&dwTmp); // load Show Leds flag
|
469 | |
g_ShowLeds = (BOOL) dwTmp;
|
470 | |
|
471 | |
//printf("Fullscreen = %d\n", fullscreen);
|
472 | |
// LOAD(TEXT("Uthernet Active") ,(DWORD *)&tfe_enabled);
|
473 | |
|
474 | |
SetCurrentCLK6502(); // set up real speed
|
475 | |
|
476 | |
//
|
477 | |
if(LOAD(TEXT(REGVALUE_MOUSE_IN_SLOT4), &dwTmp))
|
478 | |
g_uMouseInSlot4 = dwTmp;
|
479 | |
g_Slot4 = g_uMouseInSlot4 ? CT_MouseInterface : CT_Mockingboard;
|
480 | |
|
481 | |
// if(LOAD(TEXT(REGVALUE_SPKR_VOLUME), &dwTmp))
|
482 | |
// SpkrSetVolume(dwTmp, 100); // volume by default?
|
483 | |
//
|
484 | |
// if(LOAD(TEXT(REGVALUE_MB_VOLUME), &dwTmp))
|
485 | |
// MB_SetVolume(dwTmp, 100); // volume by default?? --bb
|
486 | |
|
487 | |
if(LOAD(TEXT(REGVALUE_SOUNDCARD_TYPE), &dwTmp))
|
488 | |
MB_SetSoundcardType((eSOUNDCARDTYPE)dwTmp);
|
489 | |
|
490 | |
if(LOAD(TEXT(REGVALUE_SAVE_STATE_ON_EXIT), &dwTmp))
|
491 | |
g_bSaveStateOnExit = dwTmp ? true : false;
|
492 | |
|
493 | |
if(LOAD(TEXT(REGVALUE_HDD_ENABLED), &dwTmp)) hddenabled = (bool) dwTmp;// after MemInitialize
|
494 | |
// HD_SetEnabled(dwTmp ? true : false);
|
495 | |
// printf("g_bHD_Enabled = %d\n", g_bHD_Enabled);
|
496 | |
|
497 | |
char *szHDFilename = NULL;
|
498 | |
|
499 | |
if(RegLoadString(TEXT("Configuration"), TEXT("Monochrome Color"), 1, &szHDFilename, 10))
|
500 | |
{
|
501 | |
if (!sscanf(szHDFilename, "#%X", &monochrome)) monochrome = 0xC0C0C0;
|
502 | |
free(szHDFilename);
|
503 | |
szHDFilename = NULL;
|
504 | |
}
|
505 | |
|
506 | |
dwTmp = 0;
|
507 | |
LOAD(TEXT("Boot at Startup") ,&dwTmp); //
|
508 | |
if(dwTmp) {
|
509 | |
// autostart
|
510 | |
SDL_Event user_ev;
|
511 | |
user_ev.type = SDL_USEREVENT;
|
512 | |
user_ev.user.code = 1; //restart?
|
513 | |
SDL_PushEvent(&user_ev);
|
514 | |
}
|
515 | |
|
516 | |
dwTmp = 0;
|
517 | |
LOAD(TEXT("Slot 6 Autoload") ,&dwTmp); // load autoinsert for Slot 6 flag
|
518 | |
if(dwTmp) {
|
519 | |
// Load floppy disk images and insert it automatically in slot 6 drive 1 and 2
|
520 | |
SetDiskImageDirectory(REGVALUE_DISK_IMAGE1, 0);
|
521 | |
SetDiskImageDirectory(REGVALUE_DISK_IMAGE1, 1);
|
522 | |
}
|
523 | |
else {
|
524 | |
#define MASTER_DISK "Master.dsk"
|
525 | |
DoDiskInsert(0, MASTER_DISK);
|
526 | |
}
|
527 | |
|
528 | |
// Load hard disk images and insert it automatically in slot 7
|
529 | |
if(RegLoadString(TEXT("Configuration"), TEXT(REGVALUE_HDD_IMAGE1), 1, &szHDFilename, MAX_PATH))
|
530 | |
{
|
531 | |
// printf("LoadConfiguration: returned string is: %s\n", szHDFilename);
|
532 | |
HD_InsertDisk2(0, szHDFilename);
|
533 | |
free(szHDFilename);
|
534 | |
szHDFilename = NULL;
|
535 | |
}
|
536 | |
if(RegLoadString(TEXT("Configuration"), TEXT(REGVALUE_HDD_IMAGE2), 1, &szHDFilename, MAX_PATH))
|
537 | |
{
|
538 | |
// printf("LoadConfiguration: returned string is: %s\n", szHDFilename);
|
539 | |
HD_InsertDisk2(1, szHDFilename);
|
540 | |
free(szHDFilename);
|
541 | |
szHDFilename = NULL;
|
542 | |
}
|
543 | |
|
544 | |
// file name for Parallel Printer
|
545 | |
if(RegLoadString(TEXT("Configuration"), TEXT(REGVALUE_PPRINTER_FILENAME), 1, &szHDFilename, MAX_PATH))
|
546 | |
{
|
547 | |
if(strlen(szHDFilename) > 1) strncpy(g_sParallelPrinterFile, szHDFilename, MAX_PATH);
|
548 | |
free(szHDFilename);
|
549 | |
szHDFilename = NULL;
|
550 | |
}
|
551 | |
|
552 | |
|
553 | |
// for joysticks use default Y-,X-trims
|
554 | |
// if(LOAD(TEXT(REGVALUE_PDL_XTRIM), &dwTmp))
|
555 | |
// JoySetTrim((short)dwTmp, true);
|
556 | |
// if(LOAD(TEXT(REGVALUE_PDL_YTRIM), &dwTmp))
|
557 | |
// JoySetTrim((short)dwTmp, false);
|
558 | |
// we do not use this, scroll lock ever toggling full-speed???
|
559 | |
// if(LOAD(TEXT(REGVALUE_SCROLLLOCK_TOGGLE), &dwTmp))
|
560 | |
// g_uScrollLockToggle = dwTmp;
|
561 | |
|
562 | |
//
|
563 | |
|
564 | |
char *szFilename = NULL;
|
565 | |
double scrFactor = 0.0;
|
566 | |
// Define screen sizes
|
567 | |
if (RegLoadString(TEXT("Configuration"),TEXT("Screen factor"),1, &szFilename,16)) {
|
568 | |
scrFactor = atof(szFilename);
|
569 | |
if(scrFactor > 0.1) {
|
570 | |
g_ScreenWidth = UINT(g_ScreenWidth * scrFactor);
|
571 | |
g_ScreenHeight = UINT(g_ScreenHeight * scrFactor);
|
572 | |
}
|
573 | |
free(szFilename);
|
574 | |
szFilename = NULL;
|
575 | |
}
|
576 | |
else { // Try to set Screen Width & Height directly
|
577 | |
dwTmp = 0;
|
578 | |
LOAD(TEXT("Screen Width") ,&dwTmp);
|
579 | |
if(dwTmp > 0) g_ScreenWidth = dwTmp;
|
580 | |
dwTmp = 0;
|
581 | |
LOAD(TEXT("Screen Height") ,&dwTmp);
|
582 | |
if(dwTmp > 0) g_ScreenHeight = dwTmp;
|
583 | |
}
|
584 | |
|
585 | |
if (RegLoadString(TEXT("Configuration"),TEXT(REGVALUE_SAVESTATE_FILENAME),1, &szFilename,MAX_PATH)) {
|
586 | |
Snapshot_SetFilename(szFilename); // If not in Registry than default will be used
|
587 | |
free(szFilename);
|
588 | |
szFilename = NULL;
|
589 | |
}
|
590 | |
|
591 | |
// Current/Starting Dir is the "root" of where the user keeps his disk images
|
592 | |
RegLoadString(TEXT("Preferences"), REGVALUE_PREF_START_DIR, 1, &szFilename, MAX_PATH);
|
593 | |
if (szFilename) {
|
594 | |
strcpy(g_sCurrentDir, szFilename);
|
595 | |
free(szFilename);
|
596 | |
szFilename = NULL;
|
597 | |
}
|
598 | |
// SetCurrentDirectory(g_sCurrentDir);
|
599 | |
if(strlen(g_sCurrentDir) == 0 || g_sCurrentDir[0] != '/') //something is wrong in dir name?
|
600 | |
{//
|
601 | |
char *tmp = getenv("HOME"); /* we don't have HOME? ^_^ 0_0 $_$ */
|
602 | |
if(tmp == NULL) strcpy(g_sCurrentDir, "/"); //begin from the root, then
|
603 | |
else strcpy(g_sCurrentDir, tmp);
|
604 | |
}
|
605 | |
// Load starting directory for HDV (Apple][ HDD) images
|
606 | |
RegLoadString(TEXT("Preferences"), REGVALUE_PREF_HDD_START_DIR, 1, &szFilename, MAX_PATH);
|
607 | |
if (szFilename) {
|
608 | |
strcpy(g_sHDDDir, szFilename);
|
609 | |
free(szFilename);
|
610 | |
szFilename = NULL;
|
611 | |
}
|
612 | |
// SetCurrentDirectory(g_sCurrentDir);
|
613 | |
if(strlen(g_sHDDDir) == 0 || g_sHDDDir[0] != '/') //something is wrong in dir name?
|
614 | |
{
|
615 | |
char *tmp = getenv("HOME"); /* we don't have HOME? ^_^ 0_0 $_$ */
|
616 | |
if(tmp == NULL) strcpy(g_sHDDDir, "/"); //begin from the root, then
|
617 | |
else strcpy(g_sHDDDir, tmp);
|
618 | |
}
|
619 | |
|
620 | |
|
621 | |
// Load starting directory for saving current states
|
622 | |
RegLoadString(TEXT("Preferences"), REGVALUE_PREF_SAVESTATE_DIR, 1, &szFilename, MAX_PATH);
|
623 | |
if (szFilename) {
|
624 | |
strcpy(g_sSaveStateDir, szFilename);
|
625 | |
free(szFilename);
|
626 | |
szFilename = NULL;
|
627 | |
}
|
628 | |
if(strlen(g_sSaveStateDir) == 0 || g_sSaveStateDir[0] != '/') //something is wrong in dir name?
|
629 | |
{
|
630 | |
char *tmp = getenv("HOME"); /* we don't have HOME? ^_^ 0_0 $_$ */
|
631 | |
if(tmp == NULL) strcpy(g_sSaveStateDir, "/"); //begin from the root, then
|
632 | |
else strcpy(g_sSaveStateDir, tmp);
|
633 | |
}
|
634 | |
|
635 | |
// Read and fill FTP variables - server, local dir, user name and password
|
636 | |
RegLoadString(TEXT("Preferences"), REGVALUE_FTP_DIR, 1, &szFilename, MAX_PATH);
|
637 | |
if (szFilename) {
|
638 | |
strcpy(g_sFTPServer, szFilename);
|
639 | |
free(szFilename);
|
640 | |
szFilename = NULL;
|
641 | |
}
|
642 | |
RegLoadString(TEXT("Preferences"), REGVALUE_FTP_HDD_DIR, 1, &szFilename, MAX_PATH);
|
643 | |
if (szFilename) {
|
644 | |
strcpy(g_sFTPServerHDD, szFilename);
|
645 | |
free(szFilename);
|
646 | |
szFilename = NULL;
|
647 | |
}
|
648 | |
|
649 | |
RegLoadString(TEXT("Preferences"), REGVALUE_FTP_LOCAL_DIR, 1, &szFilename, MAX_PATH);
|
650 | |
if (szFilename) {
|
651 | |
strcpy(g_sFTPLocalDir, szFilename);
|
652 | |
free(szFilename);
|
653 | |
szFilename = NULL;
|
654 | |
}
|
655 | |
RegLoadString(TEXT("Preferences"), REGVALUE_FTP_USERPASS, 1, &szFilename, 512);
|
656 | |
if (szFilename) {
|
657 | |
strcpy(g_sFTPUserPass, szFilename);
|
658 | |
free(szFilename);
|
659 | |
szFilename = NULL;
|
660 | |
}
|
661 | |
// Print some debug strings
|
662 | |
printf("Ready login = %s\n",g_sFTPUserPass);
|
663 | |
|
664 | |
//
|
665 | |
// ****By now we deal without Uthernet interface! --bb****
|
666 | |
// char szUthernetInt[MAX_PATH] = {0};
|
667 | |
// RegLoadString(TEXT("Configuration"),TEXT("Uthernet Interface"),1,szUthernetInt,MAX_PATH);
|
668 | |
// update_tfe_interface(szUthernetInt,NULL);
|
669 | |
|
670 | |
}
|
671 | |
|
672 | |
//===========================================================================
|
673 | |
void RegisterExtensions ()
|
674 | |
{ // TO DO: register extensions for KDE or GNOME desktops?? Do not know, if it is sane idea. He-he. --bb
|
675 | |
|
676 | |
|
677 | |
// TCHAR szCommandTmp[MAX_PATH];
|
678 | |
// GetModuleFileName((HMODULE)0,szCommandTmp,MAX_PATH);
|
679 | |
//
|
680 | |
// TCHAR command[MAX_PATH];
|
681 | |
// wsprintf(command, "\"%s\"", szCommandTmp); // Wrap path & filename in quotes & null terminate
|
682 | |
//
|
683 | |
// TCHAR icon[MAX_PATH];
|
684 | |
// wsprintf(icon,TEXT("%s,1"),(LPCTSTR)command);
|
685 | |
//
|
686 | |
// _tcscat(command,TEXT(" \"%1\"")); // Append "%1"
|
687 | |
//
|
688 | |
// RegSetValue(HKEY_CLASSES_ROOT,".bin",REG_SZ,"DiskImage",10);
|
689 | |
// RegSetValue(HKEY_CLASSES_ROOT,".do" ,REG_SZ,"DiskImage",10);
|
690 | |
// RegSetValue(HKEY_CLASSES_ROOT,".dsk",REG_SZ,"DiskImage",10);
|
691 | |
// RegSetValue(HKEY_CLASSES_ROOT,".nib",REG_SZ,"DiskImage",10);
|
692 | |
// RegSetValue(HKEY_CLASSES_ROOT,".po" ,REG_SZ,"DiskImage",10);
|
693 | |
// // RegSetValue(HKEY_CLASSES_ROOT,".aws",REG_SZ,"DiskImage",10); // TO DO
|
694 | |
// // RegSetValue(HKEY_CLASSES_ROOT,".hdv",REG_SZ,"DiskImage",10); // TO DO
|
695 | |
//
|
696 | |
// RegSetValue(HKEY_CLASSES_ROOT,
|
697 | |
// "DiskImage",
|
698 | |
// REG_SZ,"Disk Image",21);
|
699 | |
//
|
700 | |
// RegSetValue(HKEY_CLASSES_ROOT,
|
701 | |
// "DiskImage\\DefaultIcon",
|
702 | |
// REG_SZ,icon,_tcslen(icon)+1);
|
703 | |
//
|
704 | |
// RegSetValue(HKEY_CLASSES_ROOT,
|
705 | |
// "DiskImage\\shell\\open\\command",
|
706 | |
// REG_SZ,command,_tcslen(command)+1);
|
707 | |
//
|
708 | |
// RegSetValue(HKEY_CLASSES_ROOT,
|
709 | |
// "DiskImage\\shell\\open\\ddeexec",
|
710 | |
// REG_SZ,"%1",3);
|
711 | |
//
|
712 | |
// RegSetValue(HKEY_CLASSES_ROOT,
|
713 | |
// "DiskImage\\shell\\open\\ddeexec\\application",
|
714 | |
// REG_SZ,"applewin",9);
|
715 | |
//
|
716 | |
// RegSetValue(HKEY_CLASSES_ROOT,
|
717 | |
// "DiskImage\\shell\\open\\ddeexec\\topic",
|
718 | |
// REG_SZ,"system",7);
|
719 | |
}
|
720 | |
|
721 | |
//===========================================================================
|
722 | |
|
723 | |
//LPSTR GetNextArg(LPSTR lpCmdLine)
|
724 | |
//{
|
725 | |
// Sane idea: use getoptlong as command-line parameter preprocessor. Use it at your health. Ha. --bb
|
726 | |
|
727 | |
/*
|
728 | |
int bInQuotes = 0;
|
729 | |
|
730 | |
while(*lpCmdLine)
|
731 | |
{
|
732 | |
if(*lpCmdLine == '\"')
|
733 | |
{
|
734 | |
bInQuotes ^= 1;
|
735 | |
if(!bInQuotes)
|
736 | |
{
|
737 | |
*lpCmdLine++ = 0x00; // Assume end-quote is end of this arg
|
738 | |
continue;
|
739 | |
}
|
740 | |
}
|
741 | |
|
742 | |
if((*lpCmdLine == ' ') && !bInQuotes)
|
743 | |
{
|
744 | |
*lpCmdLine++ = 0x00;
|
745 | |
break;
|
746 | |
}
|
747 | |
|
748 | |
lpCmdLine++;
|
749 | |
}
|
750 | |
|
751 | |
return lpCmdLine;
|
752 | |
*/
|
753 | |
//}
|
754 | |
|
755 | |
//FILE *spMono, *spStereo;
|
756 | |
|
757 | |
//---------------------------------------------------------------------------
|
758 | |
|
759 | |
int main(int argc, char * lpCmdLine[])
|
760 | |
{
|
761 | |
// reading FullScreen and Boot from conf file?
|
762 | |
// bool bSetFullScreen = false;
|
763 | |
// bool bBoot = false;
|
764 | |
|
765 | |
registry = fopen(REGISTRY, "a+t"); // open conf file (linapple.conf by default)
|
766 | |
// spMono = fopen("speakersmono.pcm","wb");
|
767 | |
// spStereo = fopen("speakersstereo.pcm","wb");
|
768 | |
|
769 | |
// LPSTR szImageName_drive1 = NULL; // file names for images of drive1 and drive2
|
770 | |
// LPSTR szImageName_drive2 = NULL;
|
771 | |
|
772 | |
|
773 | |
bool bBenchMark = (argc > 1 &&
|
774 | |
!strcmp(lpCmdLine[1],"-b")); // if we should start benchmark (-b in command line string)
|
775 | |
|
776 | |
// I will remake this using getopt and getoptlong!
|
777 | |
/*
|
778 | |
while(*lpCmdLine)
|
779 | |
{
|
780 | |
LPSTR lpNextArg = GetNextArg(lpCmdLine);
|
781 | |
|
782 | |
if(strcmp(lpCmdLine, "-d1") == 0)
|
783 | |
{
|
784 | |
lpCmdLine = lpNextArg;
|
785 | |
lpNextArg = GetNextArg(lpCmdLine);
|
786 | |
szImageName_drive1 = lpCmdLine;
|
787 | |
if(*szImageName_drive1 == '\"')
|
788 | |
szImageName_drive1++;
|
789 | |
}
|
790 | |
else if(strcmp(lpCmdLine, "-d2") == 0)
|
791 | |
{
|
792 | |
lpCmdLine = lpNextArg;
|
793 | |
lpNextArg = GetNextArg(lpCmdLine);
|
794 | |
szImageName_drive2 = lpCmdLine;
|
795 | |
if(*szImageName_drive2 == '\"')
|
796 | |
szImageName_drive2++;
|
797 | |
}
|
798 | |
else if(strcmp(lpCmdLine, "-f") == 0)
|
799 | |
{
|
800 | |
bSetFullScreen = true;
|
801 | |
}
|
802 | |
else if((strcmp(lpCmdLine, "-l") == 0) && (g_fh == NULL))
|
803 | |
{
|
804 | |
g_fh = fopen("AppleWin.log", "a+t"); // Open log file (append & text g_nAppMode)
|
805 | |
// Start of Unix(tm) specific code
|
806 | |
struct timeval tv;
|
807 | |
struct tm * ptm;
|
808 | |
char time_str[40];
|
809 | |
gettimeofday(&tv, NULL);
|
810 | |
ptm = localtime(&tv.tvsec);
|
811 | |
strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", ptm);
|
812 | |
// end of Unix(tm) specific code
|
813 | |
fprintf(g_fh,"*** Logging started: %s\n",time_str);
|
814 | |
}
|
815 | |
else if(strcmp(lpCmdLine, "-m") == 0)
|
816 | |
{
|
817 | |
g_bDisableDirectSound = true; // without direct sound? U-u-u-u-uuuuuuuhhhhhhhhh --bb
|
818 | |
}
|
819 | |
#ifdef RAMWORKS
|
820 | |
else if(strcmp(lpCmdLine, "-r") == 0) // RamWorks size [1..127]
|
821 | |
{
|
822 | |
lpCmdLine = lpNextArg;
|
823 | |
lpNextArg = GetNextArg(lpCmdLine);
|
824 | |
g_uMaxExPages = atoi(lpCmdLine);
|
825 | |
if (g_uMaxExPages > 127)
|
826 | |
g_uMaxExPages = 128;
|
827 | |
else if (g_uMaxExPages < 1)
|
828 | |
g_uMaxExPages = 1;
|
829 | |
}
|
830 | |
#endif
|
831 | |
|
832 | |
lpCmdLine = lpNextArg;
|
833 | |
}
|
834 | |
*/
|
835 | |
|
836 | |
|
837 | |
// What is it???? RIFF support for sound saving during emulation in RIFF format.
|
838 | |
// Currently not used?
|
839 | |
#if 0
|
840 | |
#ifdef RIFF_SPKR
|
841 | |
RiffInitWriteFile("Spkr.wav", SPKR_SAMPLE_RATE, 1);
|
842 | |
#endif
|
843 | |
#ifdef RIFF_MB
|
844 | |
RiffInitWriteFile("Mockingboard.wav", 44100, 2);
|
845 | |
#endif
|
846 | |
#endif
|
847 | |
|
848 | |
//-----
|
849 | |
|
850 | |
// char szPath[_MAX_PATH];
|
851 | |
//
|
852 | |
// if(0 == GetModuleFileName(NULL, szPath, sizeof(szPath)))
|
853 | |
// {
|
854 | |
// strcpy(szPath, __argv[0]);
|
855 | |
// }
|
856 | |
|
857 | |
// Extract application version and store in a global variable
|
858 | |
// DWORD dwHandle, dwVerInfoSize;
|
859 | |
//
|
860 | |
// dwVerInfoSize = GetFileVersionInfoSize(szPath, &dwHandle);
|
861 | |
//
|
862 | |
// if(dwVerInfoSize > 0)
|
863 | |
// {
|
864 | |
// char* pVerInfoBlock = new char[dwVerInfoSize];
|
865 | |
//
|
866 | |
// if(GetFileVersionInfo(szPath, NULL, dwVerInfoSize, pVerInfoBlock))
|
867 | |
// {
|
868 | |
// VS_FIXEDFILEINFO* pFixedFileInfo;
|
869 | |
// UINT pFixedFileInfoLen;
|
870 | |
//
|
871 | |
// VerQueryValue(pVerInfoBlock, TEXT("\\"), (LPVOID*) &pFixedFileInfo, (PUINT) &pFixedFileInfoLen);
|
872 | |
//
|
873 | |
// // Construct version string from fixed file info block
|
874 | |
//
|
875 | |
// unsigned long major = pFixedFileInfo->dwFileVersionMS >> 16;
|
876 | |
// unsigned long minor = pFixedFileInfo->dwFileVersionMS & 0xffff;
|
877 | |
// unsigned long fix = pFixedFileInfo->dwFileVersionLS >> 16;
|
878 | |
// unsigned long fix_minor = pFixedFileInfo->dwFileVersionLS & 0xffff;
|
879 | |
//
|
880 | |
// sprintf(VERSIONSTRING, "%d.%d.%d.%d", major, minor, fix, fix_minor);
|
881 | |
// }
|
882 | |
// }
|
883 | |
|
884 | |
#if DBG_CALC_FREQ
|
885 | |
//QueryPerformanceFrequency((LARGE_INTEGER*)&g_nPerfFreq);
|
886 | |
g_nPerfFreq = 1000;//milliseconds?
|
887 | |
if(g_fh) fprintf(g_fh, "Performance frequency = %d\n",g_nPerfFreq);
|
888 | |
#endif
|
889 | |
|
890 | |
//-----
|
891 | |
|
892 | |
// Initialize COM
|
893 | |
// . NB. DSInit() is done when g_hFrameWindow is created (WM_CREATE)
|
894 | |
|
895 | |
if(InitSDL()) return 1; // init SDL subsystems, set icon
|
896 | |
// CoInitialize( NULL ); ------- what is it initializing?----------------------------------------
|
897 | |
|
898 | |
// CURL routines
|
899 | |
curl_global_init(CURL_GLOBAL_DEFAULT);
|
900 | |
g_curl = curl_easy_init();
|
901 | |
if(!g_curl) {
|
902 | |
printf("Could not initialize CURL easy interface");
|
903 | |
return 1;
|
904 | |
}
|
905 | |
/* Set user name and password to access FTP server */
|
906 | |
curl_easy_setopt(g_curl, CURLOPT_USERPWD, g_sFTPUserPass);
|
907 | |
//
|
908 | |
// just do not see why we need this timer???
|
909 | |
/*bool bSysClkOK =*/ SysClk_InitTimer();
|
910 | |
|
911 | |
// DO ONE-TIME INITIALIZATION
|
912 | |
// g_hInstance = passinstance;
|
913 | |
MemPreInitialize(); // Call before any of the slot devices are initialized
|
914 | |
// GdiSetBatchLimit(512);
|
915 | |
// GetProgramDirectory();
|
916 | |
// RegisterExtensions();
|
917 | |
// FrameRegisterClass();
|
918 | |
ImageInitialize();
|
919 | |
DiskInitialize();
|
920 | |
CreateColorMixMap(); // For tv emulation g_nAppMode
|
921 | |
|
922 | |
// int nError = 0;
|
923 | |
// if(szImageName_drive1)
|
924 | |
// {
|
925 | |
// nError = DoDiskInsert(0, szImageName_drive1);
|
926 | |
// bBoot = true;
|
927 | |
// }
|
928 | |
// if(szImageName_drive2)
|
929 | |
// {
|
930 | |
// nError |= DoDiskInsert(1, szImageName_drive2);
|
931 | |
// }
|
932 | |
|
933 | |
//
|
934 | |
|
935 | |
do
|
936 | |
{
|
937 | |
// DO INITIALIZATION THAT MUST BE REPEATED FOR A RESTART
|
938 | |
restart = 0;
|
939 | |
g_nAppMode = MODE_LOGO;
|
940 | |
fullscreen = false;
|
941 | |
|
942 | |
LoadConfiguration();
|
943 | |
FrameCreateWindow();
|
944 | |
|
945 | |
if (!DSInit()) soundtype = SOUND_NONE; // Direct Sound and Stuff
|
946 | |
|
947 | |
MB_Initialize(); // Mocking board
|
948 | |
SpkrInitialize(); // Speakers - of Apple][ ...grrrrrrrrrrr, I love them!--bb
|
949 | |
DebugInitialize();
|
950 | |
JoyInitialize();
|
951 | |
MemInitialize();
|
952 | |
HD_SetEnabled(hddenabled ? true : false);
|
953 | |
//printf("g_bHD_Enabled = %d\n", g_bHD_Enabled);
|
954 | |
|
955 | |
VideoInitialize();
|
956 | |
|
957 | |
|
958 | |
// if (!bSysClkOK)
|
959 | |
// {
|
960 | |
// MessageBox(g_hFrameWindow, "DirectX failed to create SystemClock instance", TEXT("AppleWin Error"), MB_OK);
|
961 | |
// PostMessage(g_hFrameWindow, WM_DESTROY, 0, 0); // Close everything down
|
962 | |
// }
|
963 | |
|
964 | |
// tfe_init();
|
965 | |
Snapshot_Startup(); // Do this after everything has been init'ed
|
966 | |
|
967 | |
|
968 | |
/* ------Will be fullscreened and booted later. I promise. --bb */
|
969 | |
// if(bSetFullScreen)
|
970 | |
// {
|
971 | |
// PostMessage(g_hFrameWindow, WM_KEYDOWN, VK_F1+BTN_FULLSCR, 0);
|
972 | |
// PostMessage(g_hFrameWindow, WM_KEYUP, VK_F1+BTN_FULLSCR, 0);
|
973 | |
// bSetFullScreen = false;
|
974 | |
// }
|
975 | |
//
|
976 | |
// if(bBoot)
|
977 | |
// {
|
978 | |
// PostMessage(g_hFrameWindow, WM_KEYDOWN, VK_F1+BTN_RUN, 0);
|
979 | |
// PostMessage(g_hFrameWindow, WM_KEYUP, VK_F1+BTN_RUN, 0);
|
980 | |
// bBoot = false;
|
981 | |
// }
|
982 | |
|
983 | |
JoyReset();
|
984 | |
SetUsingCursor(0);
|
985 | |
|
986 | |
// trying fullscreen
|
987 | |
if (!fullscreen) SetNormalMode();
|
988 | |
else SetFullScreenMode();
|
989 | |
|
990 | |
DrawFrameWindow(); // we do not have WM_PAINT?
|
991 | |
|
992 | |
|
993 | |
// ENTER THE MAIN MESSAGE LOOP
|
994 | |
if(bBenchMark) VideoBenchmark(); // start VideoBenchmark and exit
|
995 | |
else EnterMessageLoop(); // else we just start game
|
996 | |
// on WM_DESTROY event:
|
997 | |
|
998 | |
|
999 | |
Snapshot_Shutdown();
|
1000 | |
DebugDestroy();
|
1001 | |
// printf("Quitting. Snapshot_Shutdown-ed!\n");
|
1002 | |
if (!restart) {
|
1003 | |
DiskDestroy();
|
1004 | |
ImageDestroy();
|
1005 | |
HD_Cleanup();
|
1006 | |
}
|
1007 | |
// printf("Quitting. DiskDestroy, ImageDestroy and HD_Cleanup!\n");
|
1008 | |
PrintDestroy();
|
1009 | |
sg_SSC.CommDestroy();
|
1010 | |
CpuDestroy();
|
1011 | |
MemDestroy();
|
1012 | |
// printf("Quitting. PrintDestroy, sg_SSC.CommDestroy, CPU-MEMDestroy!\n");
|
1013 | |
SpkrDestroy();
|
1014 | |
// printf("Quitting. SpkrDestroy!!\n");
|
1015 | |
|
1016 | |
VideoDestroy();
|
1017 | |
// printf("Quitting. VideoDestroy!!\n");
|
1018 | |
MB_Destroy();
|
1019 | |
// printf("Quitting. MB_Destroy!\n");
|
1020 | |
// end of WM_DESTROY event
|
1021 | |
MB_Reset();
|
1022 | |
// printf("Quitting. MB_Reset!\n");
|
1023 | |
sg_Mouse.Uninitialize(); // Maybe restarting due to switching slot-4 card from mouse to MB
|
1024 | |
// printf("Quitting. Mouse.Uninitialize!!!\n");
|
1025 | |
JoyShutDown(); // close opened (if any) joysticks
|
1026 | |
}
|
1027 | |
while (restart);
|
1028 | |
|
1029 | |
// Release COM
|
1030 | |
DSUninit();
|
1031 | |
SysClk_UninitTimer();
|
1032 | |
// CoUninitialize();------------------------------- what is it uninitializing?--------------------------
|
1033 | |
|
1034 | |
// tfe_shutdown();
|
1035 | |
|
1036 | |
if(g_fh)
|
1037 | |
{
|
1038 | |
fprintf(g_fh,"*** Logging ended\n\n");
|
1039 | |
fclose(g_fh);
|
1040 | |
}
|
1041 | |
|
1042 | |
RiffFinishWriteFile();
|
1043 | |
fclose(registry); //close conf file (linapple.conf by default)
|
1044 | |
// fclose(spMono);
|
1045 | |
// fclose(spStereo);
|
1046 | |
|
1047 | |
SDL_Quit();
|
1048 | |
// CURL routines
|
1049 | |
curl_easy_cleanup(g_curl);
|
1050 | |
curl_global_cleanup();
|
1051 | |
//
|
1052 | |
printf("Linapple: successfully exited!\n");
|
1053 | |
return 0;
|
1054 | |
}
|