2019-12-17 14:46:50 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "linux/interface.h"
|
|
|
|
#include "linux/windows/misc.h"
|
|
|
|
#include "linux/data.h"
|
2020-10-11 10:20:22 +01:00
|
|
|
#include "linux/paddle.h"
|
|
|
|
|
2020-10-09 19:13:42 +01:00
|
|
|
#include "frontends/common2/configuration.h"
|
|
|
|
#include "frontends/common2/utils.h"
|
|
|
|
#include "frontends/common2/programoptions.h"
|
2020-10-11 16:34:19 +01:00
|
|
|
#include "frontends/sa2/emulator.h"
|
2020-10-15 12:55:27 +01:00
|
|
|
#include "frontends/sa2/gamepad.h"
|
2020-10-20 15:32:45 +01:00
|
|
|
#include "frontends/sa2/sdirectsound.h"
|
2019-12-17 14:46:50 +00:00
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "Common.h"
|
2020-10-06 20:05:48 +01:00
|
|
|
#include "CardManager.h"
|
2019-12-17 14:46:50 +00:00
|
|
|
#include "Applewin.h"
|
|
|
|
#include "Disk.h"
|
2020-10-20 15:32:45 +01:00
|
|
|
#include "Mockingboard.h"
|
|
|
|
#include "SoundCore.h"
|
2019-12-17 14:46:50 +00:00
|
|
|
#include "Harddisk.h"
|
2020-10-20 15:32:45 +01:00
|
|
|
#include "Speaker.h"
|
2019-12-17 14:46:50 +00:00
|
|
|
#include "Log.h"
|
|
|
|
#include "CPU.h"
|
|
|
|
#include "Frame.h"
|
|
|
|
#include "Memory.h"
|
|
|
|
#include "LanguageCard.h"
|
|
|
|
#include "MouseInterface.h"
|
|
|
|
#include "ParallelPrinter.h"
|
|
|
|
#include "Video.h"
|
|
|
|
#include "NTSC.h"
|
|
|
|
#include "SaveState.h"
|
2020-10-09 09:46:15 +01:00
|
|
|
#include "RGBMonitor.h"
|
2020-10-20 15:32:45 +01:00
|
|
|
#include "Riff.h"
|
2019-12-17 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void initialiseEmulator()
|
|
|
|
{
|
|
|
|
LogFileOutput("Initialisation\n");
|
|
|
|
|
|
|
|
ImageInitialize();
|
|
|
|
g_bFullSpeed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadEmulator()
|
|
|
|
{
|
|
|
|
LoadConfiguration();
|
|
|
|
CheckCpu();
|
|
|
|
SetWindowTitle();
|
|
|
|
FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES);
|
|
|
|
ResetDefaultMachineMemTypes();
|
|
|
|
|
2020-10-20 15:32:45 +01:00
|
|
|
DSInit();
|
|
|
|
MB_Initialize();
|
|
|
|
SpkrInitialize();
|
|
|
|
|
2019-12-17 14:46:50 +00:00
|
|
|
MemInitialize();
|
|
|
|
VideoInitialize();
|
2020-10-09 09:46:15 +01:00
|
|
|
VideoSwitchVideocardPalette(RGB_GetVideocard(), GetVideoType());
|
2019-12-17 14:46:50 +00:00
|
|
|
|
2020-10-12 20:58:32 +01:00
|
|
|
GetCardMgr().GetDisk2CardMgr().Reset();
|
2019-12-17 14:46:50 +00:00
|
|
|
HD_Reset();
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:13:42 +01:00
|
|
|
void applyOptions(const EmulatorOptions & options)
|
|
|
|
{
|
|
|
|
if (options.log)
|
|
|
|
{
|
|
|
|
LogInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool disksOk = true;
|
|
|
|
if (!options.disk1.empty())
|
|
|
|
{
|
|
|
|
const bool ok = DoDiskInsert(SLOT6, DRIVE_1, options.disk1, options.createMissingDisks);
|
|
|
|
disksOk = disksOk && ok;
|
|
|
|
LogFileOutput("Init: DoDiskInsert(D1), res=%d\n", ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.disk2.empty())
|
|
|
|
{
|
|
|
|
const bool ok = DoDiskInsert(SLOT6, DRIVE_2, options.disk2, options.createMissingDisks);
|
|
|
|
disksOk = disksOk && ok;
|
|
|
|
LogFileOutput("Init: DoDiskInsert(D2), res=%d\n", ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.snapshot.empty())
|
|
|
|
{
|
|
|
|
setSnapshotFilename(options.snapshot);
|
|
|
|
}
|
|
|
|
|
2020-10-17 19:19:46 +01:00
|
|
|
Paddle::setSquaring(options.squaring);
|
2020-10-09 19:13:42 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 14:46:50 +00:00
|
|
|
void stopEmulator()
|
|
|
|
{
|
2020-10-12 20:58:32 +01:00
|
|
|
CMouseInterface* pMouseCard = GetCardMgr().GetMouseCard();
|
2020-10-06 20:05:48 +01:00
|
|
|
if (pMouseCard)
|
|
|
|
{
|
|
|
|
pMouseCard->Reset();
|
|
|
|
}
|
2019-12-17 14:46:50 +00:00
|
|
|
MemDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void uninitialiseEmulator()
|
|
|
|
{
|
2020-10-20 15:32:45 +01:00
|
|
|
SpkrDestroy();
|
|
|
|
MB_Destroy();
|
|
|
|
DSUninit();
|
|
|
|
|
2019-12-17 14:46:50 +00:00
|
|
|
HD_Destroy();
|
|
|
|
PrintDestroy();
|
|
|
|
CpuDestroy();
|
|
|
|
|
2020-10-12 20:58:32 +01:00
|
|
|
GetCardMgr().GetDisk2CardMgr().Destroy();
|
2019-12-17 14:46:50 +00:00
|
|
|
ImageDestroy();
|
2020-10-11 09:49:50 +01:00
|
|
|
LogDone();
|
2020-10-20 15:32:45 +01:00
|
|
|
RiffFinishWriteFile();
|
2019-12-17 14:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int MessageBox(HWND, const char * text, const char * caption, UINT type)
|
|
|
|
{
|
|
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, caption, text, nullptr);
|
|
|
|
return IDOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameDrawDiskLEDS(HDC x)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameDrawDiskStatus(HDC x)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameRefreshStatus(int x, bool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:13:42 +01:00
|
|
|
void run_sdl(int argc, const char * argv [])
|
2019-12-17 14:46:50 +00:00
|
|
|
{
|
2020-10-09 19:13:42 +01:00
|
|
|
EmulatorOptions options;
|
|
|
|
options.memclear = g_nMemoryClearType;
|
|
|
|
const bool run = getEmulatorOptions(argc, argv, "SDL2", options);
|
|
|
|
|
|
|
|
if (!run)
|
|
|
|
return;
|
2019-12-17 14:46:50 +00:00
|
|
|
|
2020-10-11 09:49:50 +01:00
|
|
|
|
|
|
|
if (options.log)
|
|
|
|
{
|
|
|
|
LogInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeRegistry(options);
|
|
|
|
|
2020-10-15 12:55:27 +01:00
|
|
|
Paddle::instance().reset(new Gamepad(0));
|
|
|
|
|
2020-10-11 09:49:50 +01:00
|
|
|
g_nMemoryClearType = options.memclear;
|
2020-10-11 08:26:42 +01:00
|
|
|
|
2020-10-20 15:32:45 +01:00
|
|
|
#ifdef RIFF_SPKR
|
|
|
|
RiffInitWriteFile("/tmp/Spkr.wav", SPKR_SAMPLE_RATE, 1);
|
|
|
|
#endif
|
|
|
|
#ifdef RIFF_MB
|
|
|
|
RiffInitWriteFile("/tmp/Mockingboard.wav", 44100, 2);
|
|
|
|
#endif
|
|
|
|
|
2019-12-17 14:46:50 +00:00
|
|
|
initialiseEmulator();
|
|
|
|
loadEmulator();
|
|
|
|
|
2020-10-09 19:29:33 +01:00
|
|
|
applyOptions(options);
|
|
|
|
|
2019-12-17 14:46:50 +00:00
|
|
|
const int width = GetFrameBufferWidth();
|
|
|
|
const int height = GetFrameBufferHeight();
|
|
|
|
const int sx = GetFrameBufferBorderWidth();
|
|
|
|
const int sy = GetFrameBufferBorderHeight();
|
|
|
|
const int sw = GetFrameBufferBorderlessWidth();
|
|
|
|
const int sh = GetFrameBufferBorderlessHeight();
|
|
|
|
|
|
|
|
std::shared_ptr<SDL_Window> win(SDL_CreateWindow(g_pAppTitle.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, sw, sh, SDL_WINDOW_SHOWN), SDL_DestroyWindow);
|
|
|
|
if (!win)
|
|
|
|
{
|
|
|
|
std::cerr << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<SDL_Renderer> ren(SDL_CreateRenderer(win.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), SDL_DestroyRenderer);
|
|
|
|
if (!ren)
|
|
|
|
{
|
|
|
|
std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Uint32 format = SDL_PIXELFORMAT_BGRA32;
|
|
|
|
std::shared_ptr<SDL_Texture> tex(SDL_CreateTexture(ren.get(), format, SDL_TEXTUREACCESS_STREAMING, width, height), SDL_DestroyTexture);
|
|
|
|
|
2020-10-11 16:34:19 +01:00
|
|
|
Emulator emulator(win, ren, tex);
|
2020-10-09 11:50:59 +01:00
|
|
|
|
2019-12-17 14:46:50 +00:00
|
|
|
bool quit = false;
|
|
|
|
do
|
|
|
|
{
|
2020-10-20 15:32:45 +01:00
|
|
|
SDirectSound::writeAudio();
|
2020-10-11 16:34:19 +01:00
|
|
|
emulator.processEvents(quit);
|
|
|
|
emulator.executeOneFrame();
|
2019-12-17 14:46:50 +00:00
|
|
|
} while (!quit);
|
|
|
|
|
2020-10-20 15:32:45 +01:00
|
|
|
SDirectSound::stop();
|
2019-12-17 14:46:50 +00:00
|
|
|
stopEmulator();
|
|
|
|
uninitialiseEmulator();
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:13:42 +01:00
|
|
|
int main(int argc, const char * argv [])
|
2019-12-17 14:46:50 +00:00
|
|
|
{
|
|
|
|
//First we need to start up SDL, and make sure it went ok
|
2020-10-20 15:32:45 +01:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) != 0)
|
2019-12-17 14:46:50 +00:00
|
|
|
{
|
|
|
|
std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int exit = 0;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-10-09 19:13:42 +01:00
|
|
|
run_sdl(argc, argv);
|
2019-12-17 14:46:50 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception & e)
|
|
|
|
{
|
|
|
|
exit = 2;
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
}
|
|
|
|
|
2020-10-15 12:55:27 +01:00
|
|
|
|
|
|
|
// this must happen BEFORE the SDL_Quit() as otherwise we have a double free (of the game controller).
|
|
|
|
Paddle::instance().reset();
|
2019-12-17 14:46:50 +00:00
|
|
|
SDL_Quit();
|
|
|
|
|
|
|
|
return exit;
|
|
|
|
}
|