#include #include #include #include "linux/interface.h" #include "linux/windows/misc.h" #include "linux/data.h" #include "linux/paddle.h" #include "frontends/common2/configuration.h" #include "frontends/common2/utils.h" #include "frontends/common2/programoptions.h" #include "frontends/sa2/emulator.h" #include "StdAfx.h" #include "Common.h" #include "CardManager.h" #include "Applewin.h" #include "Disk.h" #include "Harddisk.h" #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" #include "RGBMonitor.h" namespace { void initialiseEmulator() { LogFileOutput("Initialisation\n"); ImageInitialize(); g_bFullSpeed = false; } void loadEmulator() { LoadConfiguration(); CheckCpu(); SetWindowTitle(); FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES); ResetDefaultMachineMemTypes(); MemInitialize(); VideoInitialize(); VideoSwitchVideocardPalette(RGB_GetVideocard(), GetVideoType()); g_CardMgr.GetDisk2CardMgr().Reset(); HD_Reset(); } 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); } } void stopEmulator() { CMouseInterface* pMouseCard = g_CardMgr.GetMouseCard(); if (pMouseCard) { pMouseCard->Reset(); } MemDestroy(); } void uninitialiseEmulator() { HD_Destroy(); PrintDestroy(); CpuDestroy(); g_CardMgr.GetDisk2CardMgr().Destroy(); ImageDestroy(); LogDone(); } } 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) { } BYTE SpkrToggle (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG uExecutedCycles) { return MemReadFloatingBus(uExecutedCycles); } // Mockingboard void registerSoundBuffer(IDirectSoundBuffer * buffer) { } void unregisterSoundBuffer(IDirectSoundBuffer * buffer) { } void run_sdl(int argc, const char * argv []) { EmulatorOptions options; options.memclear = g_nMemoryClearType; const bool run = getEmulatorOptions(argc, argv, "SDL2", options); if (!run) return; if (options.log) { LogInit(); } InitializeRegistry(options); g_nMemoryClearType = options.memclear; initialiseEmulator(); loadEmulator(); applyOptions(options); 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 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 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 tex(SDL_CreateTexture(ren.get(), format, SDL_TEXTUREACCESS_STREAMING, width, height), SDL_DestroyTexture); Emulator emulator(win, ren, tex); bool quit = false; do { emulator.processEvents(quit); emulator.executeOneFrame(); } while (!quit); stopEmulator(); uninitialiseEmulator(); } int main(int argc, const char * argv []) { //First we need to start up SDL, and make sure it went ok if (SDL_Init(SDL_INIT_VIDEO) != 0) { std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl; return 1; } int exit = 0; try { run_sdl(argc, argv); } catch (const std::exception & e) { exit = 2; std::cerr << e.what() << std::endl; } SDL_Quit(); return exit; }