2021-10-23 20:16:04 +01:00
|
|
|
#include "StdAfx.h"
|
2020-12-13 19:47:30 +00:00
|
|
|
#include "frontends/common2/utils.h"
|
2021-10-30 15:24:54 +01:00
|
|
|
#include "frontends/common2/programoptions.h"
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-05-05 15:56:10 +01:00
|
|
|
#include "linux/network/uthernet2.h"
|
2020-10-09 19:13:42 +01:00
|
|
|
|
|
|
|
#include "SaveState.h"
|
|
|
|
|
2020-12-13 19:47:30 +00:00
|
|
|
#include "Common.h"
|
|
|
|
#include "CardManager.h"
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Disk.h"
|
|
|
|
#include "Mockingboard.h"
|
|
|
|
#include "SoundCore.h"
|
|
|
|
#include "Harddisk.h"
|
|
|
|
#include "Speaker.h"
|
|
|
|
#include "Log.h"
|
|
|
|
#include "CPU.h"
|
|
|
|
#include "Memory.h"
|
|
|
|
#include "LanguageCard.h"
|
|
|
|
#include "MouseInterface.h"
|
|
|
|
#include "ParallelPrinter.h"
|
|
|
|
#include "Video.h"
|
|
|
|
#include "NTSC.h"
|
|
|
|
#include "SaveState.h"
|
|
|
|
#include "RGBMonitor.h"
|
|
|
|
#include "Riff.h"
|
2021-10-30 15:24:54 +01:00
|
|
|
#include "Registry.h"
|
2020-12-13 19:47:30 +00:00
|
|
|
#include "Utilities.h"
|
2020-12-27 20:25:42 +00:00
|
|
|
#include "Interface.h"
|
2021-03-07 20:32:24 +00:00
|
|
|
#include "Debugger/Debug.h"
|
2021-04-17 19:07:21 +01:00
|
|
|
#include "Tfe/tfe.h"
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2020-10-09 19:13:42 +01:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
namespace common2
|
2020-10-09 19:13:42 +01:00
|
|
|
{
|
2020-12-06 18:03:41 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
void setSnapshotFilename(const std::string & filename, const bool load)
|
|
|
|
{
|
|
|
|
// same logic as qapple
|
|
|
|
// setting chdir allows to load relative disks from the snapshot file (tests?)
|
|
|
|
// but if the snapshot file itself is relative, it wont work after a chdir
|
|
|
|
// so we convert to absolute first
|
|
|
|
char * absPath = realpath(filename.c_str(), nullptr);
|
|
|
|
if (absPath)
|
2020-12-06 18:03:41 +00:00
|
|
|
{
|
2021-02-25 16:04:50 +00:00
|
|
|
char * temp = strdup(absPath);
|
|
|
|
const char * dir = dirname(temp);
|
|
|
|
// dir points inside temp!
|
|
|
|
chdir(dir);
|
|
|
|
Snapshot_SetFilename(absPath);
|
|
|
|
|
|
|
|
free(temp);
|
|
|
|
free(absPath);
|
|
|
|
|
|
|
|
if (load)
|
|
|
|
{
|
|
|
|
Snapshot_LoadState();
|
|
|
|
}
|
2020-12-06 18:03:41 +00:00
|
|
|
}
|
2020-10-09 19:13:42 +01:00
|
|
|
}
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-10-23 20:16:04 +01:00
|
|
|
void LoadUthernet2()
|
|
|
|
{
|
|
|
|
CardManager & cardManager = GetCardMgr();
|
|
|
|
for (UINT slot = SLOT1; slot < NUM_SLOTS; slot++)
|
|
|
|
{
|
|
|
|
if (cardManager.QuerySlot(slot) == CT_Uthernet2)
|
|
|
|
{
|
|
|
|
// AppleWin does not know anything about this
|
|
|
|
registerUthernet2(slot);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-27 18:47:40 +00:00
|
|
|
void InitialiseEmulator()
|
2021-02-25 16:04:50 +00:00
|
|
|
{
|
2020-12-13 19:47:30 +00:00
|
|
|
#ifdef RIFF_SPKR
|
2021-02-25 16:04:50 +00:00
|
|
|
RiffInitWriteFile("/tmp/Spkr.wav", SPKR_SAMPLE_RATE, 1);
|
2020-12-13 19:47:30 +00:00
|
|
|
#endif
|
|
|
|
#ifdef RIFF_MB
|
2021-02-25 16:04:50 +00:00
|
|
|
RiffInitWriteFile("/tmp/Mockingboard.wav", 44100, 2);
|
2020-12-13 19:47:30 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
g_nAppMode = MODE_RUNNING;
|
|
|
|
LogFileOutput("Initialisation\n");
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
g_bFullSpeed = false;
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
LoadConfiguration();
|
2021-10-23 20:16:04 +01:00
|
|
|
LoadUthernet2();
|
2021-02-25 16:04:50 +00:00
|
|
|
SetCurrentCLK6502();
|
|
|
|
GetAppleWindowTitle();
|
|
|
|
GetFrame().FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES | DRAW_DISK_STATUS);
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
DSInit();
|
|
|
|
MB_Initialize();
|
|
|
|
SpkrInitialize();
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
MemInitialize();
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
GetCardMgr().GetDisk2CardMgr().Reset();
|
|
|
|
HD_Reset();
|
2021-05-05 15:56:10 +01:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
Snapshot_Startup();
|
2021-03-07 20:32:24 +00:00
|
|
|
|
|
|
|
DebugInitialize();
|
2021-02-25 16:04:50 +00:00
|
|
|
}
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-03-27 18:47:40 +00:00
|
|
|
void DestroyEmulator()
|
2020-12-13 19:47:30 +00:00
|
|
|
{
|
2021-02-25 16:04:50 +00:00
|
|
|
Snapshot_Shutdown();
|
|
|
|
CMouseInterface* pMouseCard = GetCardMgr().GetMouseCard();
|
|
|
|
if (pMouseCard)
|
|
|
|
{
|
|
|
|
pMouseCard->Reset();
|
|
|
|
}
|
|
|
|
MemDestroy();
|
|
|
|
|
|
|
|
SpkrDestroy();
|
|
|
|
MB_Destroy();
|
|
|
|
DSUninit();
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-05-05 15:56:10 +01:00
|
|
|
unRegisterUthernet2();
|
2021-04-17 19:07:21 +01:00
|
|
|
tfe_shutdown();
|
2021-02-25 16:04:50 +00:00
|
|
|
HD_Destroy();
|
|
|
|
PrintDestroy();
|
|
|
|
CpuDestroy();
|
2021-05-23 20:06:36 +01:00
|
|
|
DebugDestroy();
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
GetCardMgr().GetDisk2CardMgr().Destroy();
|
|
|
|
RiffFinishWriteFile();
|
|
|
|
}
|
2020-12-13 19:47:30 +00:00
|
|
|
|
2021-10-30 15:24:54 +01:00
|
|
|
void loadGeometryFromRegistry(const std::string §ion, Geometry & geometry)
|
|
|
|
{
|
|
|
|
if (geometry.empty) // otherwise it was user provided
|
|
|
|
{
|
|
|
|
const std::string path = section + "\\geometry";
|
|
|
|
const auto loadValue = [&path](const char * name, int & dest)
|
|
|
|
{
|
|
|
|
DWORD value;
|
|
|
|
if (RegLoadValue(path.c_str(), name, TRUE, &value))
|
|
|
|
{
|
2021-10-30 15:45:49 +01:00
|
|
|
// DWORD and int have the same size
|
|
|
|
// but if they did not, this would be necessary
|
|
|
|
typedef std::make_signed<DWORD>::type signed_t;
|
|
|
|
dest = static_cast<signed_t>(value);
|
2021-10-30 15:24:54 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
loadValue("width", geometry.width);
|
|
|
|
loadValue("height", geometry.height);
|
|
|
|
loadValue("x", geometry.x);
|
|
|
|
loadValue("y", geometry.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveGeometryToRegistry(const std::string §ion, const Geometry & geometry)
|
|
|
|
{
|
|
|
|
const std::string path = section + "\\geometry";
|
|
|
|
const auto saveValue = [&path](const char * name, const int source)
|
|
|
|
{
|
2021-10-30 15:45:49 +01:00
|
|
|
// this seems to already do the right thing for negative numbers
|
2021-10-30 15:24:54 +01:00
|
|
|
RegSaveValue(path.c_str(), name, TRUE, source);
|
|
|
|
};
|
|
|
|
saveValue("width", geometry.width);
|
|
|
|
saveValue("height", geometry.height);
|
|
|
|
saveValue("x", geometry.x);
|
|
|
|
saveValue("y", geometry.y);
|
|
|
|
}
|
|
|
|
|
2020-12-13 19:47:30 +00:00
|
|
|
}
|