Compare commits

...

3 Commits

20 changed files with 167 additions and 111 deletions

View File

@ -144,8 +144,8 @@ bool E2wxApp::OnInit() {
InitBoostLog(); InitBoostLog();
// TODO investigate redirecting wxLogs to boost // TODO investigate redirecting wxLogs to boost
// wxLog* logger = new wxLogStream(&std::cerr); wxLog* logger = new wxLogStream(&std::cerr);
// wxLog::SetActiveTarget(logger); wxLog::SetActiveTarget(logger);
// wxLogWarning("%s", "a warning has occurred"); // wxLogWarning("%s", "a warning has occurred");
// wxLogInfo("%s", "informational"); // wxLogInfo("%s", "informational");
// wxLogVerbose("%s", "verbose"); // wxLogVerbose("%s", "verbose");
@ -186,19 +186,18 @@ bool E2wxApp::OnInit() {
BOOST_LOG_TRIVIAL(info) << "Resource directory path: " << this->resdir; BOOST_LOG_TRIVIAL(info) << "Resource directory path: " << this->resdir;
wxXmlResource::Get()->InitAllHandlers(); wxXmlResource::Get()->InitAllHandlers();
if (!wxXmlResource::Get()->LoadAllFiles(this->resdir.c_str())) { wxXmlResource::Get()->LoadAllFiles(this->resdir.c_str());
return false;
}
// note: the frame is responsible for deleting itself (via Destroy())
frame = new E2wxFrame(); frame = new E2wxFrame();
frame->DoInit(); frame->DoInit();
frame->Show(); frame->Show();
StartEmulator(); // TODO option? or use last-state? StartEmulator();
@ -237,31 +236,39 @@ void E2wxApp::OnFnKeyPressed(const SDL_Keycode k) {
bool E2wxApp::CloseMainFrame() { bool E2wxApp::CloseMainFrame() {
bool r = false; bool r = false;
BOOST_LOG_TRIVIAL(info) << "Received request to close main frame.";
if (this->frame) { if (this->frame) {
if (this->frame->Close(false)) { if (this->frame->Close(false)) {
delete this->frame; BOOST_LOG_TRIVIAL(info) << "Main frame successfully deleted.";
this->frame = nullptr; this->frame = nullptr;
wxApp::ExitMainLoop();
r = true; r = true;
} else {
BOOST_LOG_TRIVIAL(info) << "User cancelled application shutdown.";
} }
} else {
BOOST_LOG_TRIVIAL(warning) << "No main frame found.";
} }
return r; return r;
} }
int E2wxApp::OnExit() { int E2wxApp::OnExit() {
if (this->emu_timer) { BOOST_LOG_TRIVIAL(info) << "Begin application OnExit...";
delete this->emu_timer;
this->emu_timer = nullptr; delete wxXmlResource::Set(nullptr);
}
if (this->emu) { BOOST_LOG_TRIVIAL(info) << "Deleting emulator instance...";
delete this->emu; StopEmulator();
this->emu = nullptr;
} BOOST_LOG_TRIVIAL(info) << "Application OnExit complete.";
return 0; return 0;
} }
void E2wxApp::OnFatalException() { void E2wxApp::OnFatalException() {
BOOST_LOG_TRIVIAL(info) << "Application will handle fatal exception...";
wxDebugReport report; wxDebugReport report;
report.AddAll(); report.AddAll();
@ -383,13 +390,21 @@ void E2wxApp::InitBoostLog() {
void E2wxApp::StopEmulator() {
if (EnsureCanQuit()) {
if (this->emu_timer) {
delete this->emu_timer;
this->emu_timer = nullptr;
}
if (this->emu) {
delete this->emu;
this->emu = nullptr;
}
}
}
void E2wxApp::StartEmulator() { void E2wxApp::StartEmulator() {
if (this->emu_timer) { StopEmulator();
delete this->emu_timer;
}
if (this->emu) {
delete this->emu;
}
this->emu = new Emulator(); this->emu = new Emulator();
E2Config cfg{this->arg_configfile, this->opt_config_from_prefs_only}; E2Config cfg{this->arg_configfile, this->opt_config_from_prefs_only};

View File

@ -70,7 +70,6 @@ class E2wxApp : public wxApp {
const std::filesystem::path BuildLogFilePath() const; const std::filesystem::path BuildLogFilePath() const;
void InitBoostLog(); void InitBoostLog();
void StartEmulator();
public: public:
E2wxApp(); E2wxApp();
@ -84,6 +83,9 @@ public:
const std::filesystem::path GetConfigDir() const; const std::filesystem::path GetConfigDir() const;
const std::filesystem::path GetDocumentsDir() const; const std::filesystem::path GetDocumentsDir() const;
void StartEmulator();
void StopEmulator();
void OnFnKeyPressed(const SDL_Keycode k); void OnFnKeyPressed(const SDL_Keycode k);
bool CloseMainFrame(); bool CloseMainFrame();

View File

@ -22,12 +22,16 @@
#include "E2wxApp.h" #include "E2wxApp.h"
#include "PreferencesDialog.h" #include "PreferencesDialog.h"
#include "gui.h" #include "gui.h"
#include <wx/menu.h> #include <wx/menu.h>
#include <wx/accel.h> #include <wx/accel.h>
#include <wx/msgdlg.h> #include <wx/msgdlg.h>
#include <wx/event.h> #include <wx/event.h>
#include <wx/persist/toplevel.h> #include <wx/persist/toplevel.h>
#include <boost/log/trivial.hpp>
enum E2MenuID { enum E2MenuID {
ID_MENUITEM_POWER = wxID_HIGHEST+1, ID_MENUITEM_POWER = wxID_HIGHEST+1,
@ -37,11 +41,13 @@ enum E2MenuID {
ID_MENUITEM_RESET, ID_MENUITEM_RESET,
ID_MENUITEM_SCREEN_SHOT, ID_MENUITEM_SCREEN_SHOT,
ID_MENUITEM_TOGGLE_BUFFERED, ID_MENUITEM_TOGGLE_BUFFERED,
ID_MENUITEM_START_EMULATOR,
ID_MENUITEM_STOP_EMULATOR,
}; };
wxBEGIN_EVENT_TABLE(E2wxFrame, wxFrame) wxBEGIN_EVENT_TABLE(E2wxFrame, wxFrame)
EVT_CLOSE(E2wxFrame::HandleUserQuitRequest) EVT_CLOSE(E2wxFrame::HandleUserQuitRequest)
EVT_MENU(wxID_EXIT, E2wxFrame::OnExit) EVT_MENU(wxID_EXIT, E2wxFrame::OnFileExitCommand)
EVT_MENU(wxID_PREFERENCES, E2wxFrame::OnPreferences) EVT_MENU(wxID_PREFERENCES, E2wxFrame::OnPreferences)
EVT_MENU(wxID_ABOUT, E2wxFrame::OnAbout) EVT_MENU(wxID_ABOUT, E2wxFrame::OnAbout)
EVT_MENU(ID_MENUITEM_POWER, E2wxFrame::OnTogglePower) EVT_MENU(ID_MENUITEM_POWER, E2wxFrame::OnTogglePower)
@ -52,6 +58,8 @@ wxBEGIN_EVENT_TABLE(E2wxFrame, wxFrame)
EVT_MENU(wxID_PASTE, E2wxFrame::OnPaste) EVT_MENU(wxID_PASTE, E2wxFrame::OnPaste)
EVT_MENU(ID_MENUITEM_SCREEN_SHOT, E2wxFrame::OnScreenShot) EVT_MENU(ID_MENUITEM_SCREEN_SHOT, E2wxFrame::OnScreenShot)
EVT_MENU(ID_MENUITEM_TOGGLE_BUFFERED, E2wxFrame::OnToggleBuffered) EVT_MENU(ID_MENUITEM_TOGGLE_BUFFERED, E2wxFrame::OnToggleBuffered)
EVT_MENU(ID_MENUITEM_START_EMULATOR, E2wxFrame::OnStartEmulator)
EVT_MENU(ID_MENUITEM_STOP_EMULATOR, E2wxFrame::OnStopEmulator)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
@ -80,6 +88,11 @@ void E2wxFrame::InitMenuBar() {
wxMenu *menuFile = new wxMenu(); wxMenu *menuFile = new wxMenu();
menuBar->Append(menuFile, "&File"); menuBar->Append(menuFile, "&File");
wxMenuItem *miStart = menuFile->Append(ID_MENUITEM_START_EMULATOR, "Open Emulator");
miStart->SetAccel(new wxAcceleratorEntry(wxACCEL_CTRL, 'O'));
wxMenuItem *miStop = menuFile->Append(ID_MENUITEM_STOP_EMULATOR, "Close Emulator");
miStop->SetAccel(new wxAcceleratorEntry(wxACCEL_CTRL, 'W'));
menuFile->AppendSeparator();
wxMenuItem *miExit = menuFile->Append(wxID_EXIT); wxMenuItem *miExit = menuFile->Append(wxID_EXIT);
miExit->AddExtraAccel(wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F9)); miExit->AddExtraAccel(wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F9));
@ -128,24 +141,35 @@ void E2wxFrame::InitStatusBar() {
void E2wxFrame::HandleUserQuitRequest(wxCloseEvent& event) { void E2wxFrame::HandleUserQuitRequest(wxCloseEvent& event) {
// TODO how to handle event.CanVeto() ? I'd like to auto-save everything BOOST_LOG_TRIVIAL(info) << "Main frame will handle request to close application...";
if (wxGetApp().EnsureCanQuit()) { if (!event.CanVeto()) {
event.Skip(); BOOST_LOG_TRIVIAL(warning) << "Application is being forced to quit; any unsaved changes will be discarded.";
// TODO how to handle !event.CanVeto() ?
// I'd like to auto-save everything
Destroy();
} else if (wxGetApp().EnsureCanQuit()) {
BOOST_LOG_TRIVIAL(info) << "Destroying main frame now...";
Destroy();
} else { } else {
BOOST_LOG_TRIVIAL(info) << "User cancelled closing main frame.";
event.Veto(); event.Veto();
} }
} }
void E2wxFrame::OnExit(wxCommandEvent& event) { void E2wxFrame::OnFileExitCommand(wxCommandEvent& event) {
Close(false); Close(false);
} }
void E2wxFrame::OnPreferences(wxCommandEvent& event) { void E2wxFrame::OnPreferences(wxCommandEvent& event) {
PreferencesDialog *dlg = new PreferencesDialog(this); PreferencesDialog *dlg = new PreferencesDialog(this);
dlg->OnInit(); if (dlg->OnInit()) {
dlg->ShowModal(); dlg->ShowModal();
dlg->Destroy();
}
// TODO re-configure emulator here
wxGetApp().StartEmulator();
} }
void E2wxFrame::OnAbout(wxCommandEvent& event) { void E2wxFrame::OnAbout(wxCommandEvent& event) {
@ -164,7 +188,7 @@ void E2wxFrame::OnAbout(wxCommandEvent& event) {
void E2wxFrame::OnTogglePower(wxCommandEvent& event) { void E2wxFrame::OnTogglePower(wxCommandEvent& event) {
GUI::queueTogglePower(); wxGetApp().TogglePower();
} }
void E2wxFrame::OnCycleMonitor(wxCommandEvent& event) { void E2wxFrame::OnCycleMonitor(wxCommandEvent& event) {
@ -194,3 +218,11 @@ void E2wxFrame::OnScreenShot(wxCommandEvent& event) {
void E2wxFrame::OnToggleBuffered(wxCommandEvent& event) { void E2wxFrame::OnToggleBuffered(wxCommandEvent& event) {
wxGetApp().ToggleBuffered(); wxGetApp().ToggleBuffered();
} }
void E2wxFrame::OnStartEmulator(wxCommandEvent& event) {
wxGetApp().StartEmulator();
}
void E2wxFrame::OnStopEmulator(wxCommandEvent& event){
wxGetApp().StopEmulator();
}

View File

@ -38,7 +38,7 @@ private:
void HandleUserQuitRequest(wxCloseEvent& event); void HandleUserQuitRequest(wxCloseEvent& event);
void OnExit(wxCommandEvent& event); void OnFileExitCommand(wxCommandEvent& event);
void OnPreferences(wxCommandEvent& event); void OnPreferences(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
@ -50,6 +50,8 @@ private:
void OnPaste(wxCommandEvent& event); void OnPaste(wxCommandEvent& event);
void OnScreenShot(wxCommandEvent& event); void OnScreenShot(wxCommandEvent& event);
void OnToggleBuffered(wxCommandEvent& event); void OnToggleBuffered(wxCommandEvent& event);
void OnStartEmulator(wxCommandEvent& event);
void OnStopEmulator(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };

View File

@ -16,14 +16,15 @@
#include "TransNetwork.h" #include "TransNetwork.h"
#include "TransCache.h" #include "TransCache.h"
#include "SegmentCache.h" #include "SegmentCache.h"
#include <istream>
#include <filesystem>
class AddressBus; class AddressBus;
class Emu6502 : public AbstractCpu { class Emu6502 : public AbstractCpu {
public: public:
Emu6502(std::istream& transistors, AddressBus& mem) : tn(transistors, segs, transes), c(tn), trace(segs, transes, c), cpu(mem, trace, c), cpuhelper(cpu, c) { Emu6502(std::filesystem::path& transistors, AddressBus& mem) : tn(transistors, segs, transes), c(tn), trace(segs, transes, c), cpu(mem, trace, c), cpuhelper(cpu, c) {
} }
virtual ~Emu6502() { virtual ~Emu6502() {

View File

@ -132,10 +132,14 @@ void PreferencesDialog::BuildItemTree() {
this->GetSizer()->Layout(); this->GetSizer()->Layout();
} }
void PreferencesDialog::OnInit() { bool PreferencesDialog::OnInit() {
wxConfigBase::Get()->Read("/ActivePreferences/name", &this->active, ""); wxConfigBase::Get()->Read("/ActivePreferences/name", &this->active, "");
wxXmlResource::Get()->LoadDialog(this, this->parent, "Preferences"); const bool loaded = wxXmlResource::Get()->LoadDialog(this, this->parent, "Preferences");
if (!loaded) {
BOOST_LOG_TRIVIAL(error) << "Could not load Preferences dialog resources.";
return false;
}
SetSize(SIZ_DLG); SetSize(SIZ_DLG);
@ -144,6 +148,8 @@ void PreferencesDialog::OnInit() {
CTRL(wxTreeCtrl, treItems); CTRL(wxTreeCtrl, treItems);
treItems->SetFocus(); treItems->SetFocus();
treItems->SelectItem(treItems->GetRootItem()); treItems->SelectItem(treItems->GetRootItem());
return true;
} }
void PreferencesDialog::Save(const std::filesystem::path& to) { void PreferencesDialog::Save(const std::filesystem::path& to) {

View File

@ -29,7 +29,7 @@ public:
PreferencesDialog(wxWindow *parent); PreferencesDialog(wxWindow *parent);
~PreferencesDialog(); ~PreferencesDialog();
void OnInit(); bool OnInit();
}; };
#endif /* PREFERENCESDIALOG_H */ #endif /* PREFERENCESDIALOG_H */

View File

@ -1,7 +1,7 @@
/* /*
* File: TransNetwork.cpp * File: TransNetwork.cpp
* Author: cmosher * Author: cmosher
* *
* Created on December 11, 2013, 10:44 AM * Created on December 11, 2013, 10:44 AM
*/ */
@ -10,12 +10,20 @@
#include "SegmentCache.h" #include "SegmentCache.h"
#include "StateCalculator.h" #include "StateCalculator.h"
#include "trans.h" #include "trans.h"
#include "E2wxApp.h"
#include "e2filesystem.h"
#include <iostream> #include <iostream>
#include <set> #include <set>
#include <string> #include <string>
#include <memory> #include <memory>
#include <fstream>
TransNetwork::TransNetwork(std::filesystem::path& p, SegmentCache& segs, TransCache& transes) : segs(segs), transes(transes) {
std::filesystem::path inpath = valid_input_file(p, wxGetApp().GetResDir());
std::ifstream in(inpath);
TransNetwork::TransNetwork(std::istream& in, SegmentCache& segs, TransCache& transes) : segs(segs), transes(transes) {
std::string c1, gate, c2; std::string c1, gate, c2;
in >> c1 >> gate >> c2; in >> c1 >> gate >> c2;
while (in.good()) { while (in.good()) {

View File

@ -8,7 +8,7 @@
#ifndef TRANSNETWORK_H #ifndef TRANSNETWORK_H
#define TRANSNETWORK_H #define TRANSNETWORK_H
#include <istream> #include <filesystem>
#include <set> #include <set>
#include <memory> #include <memory>
@ -20,7 +20,7 @@ class Trans;
class TransNetwork final { class TransNetwork final {
public: public:
TransNetwork(std::istream& readFromHere, SegmentCache& segs, TransCache& transes); TransNetwork(std::filesystem::path& readFromHere, SegmentCache& segs, TransCache& transes);
private: private:

View File

@ -48,24 +48,27 @@ cassetteOut(gui),
addressBus(gui, revision, ram, rom, kbd, videoMode, paddles, paddleButtonStates, speaker, cassetteIn, cassetteOut, slts), addressBus(gui, revision, ram, rom, kbd, videoMode, paddles, paddleButtonStates, speaker, cassetteIn, cassetteOut, slts),
picgen(tv, videoMode, revision), picgen(tv, videoMode, revision),
video(videoMode, addressBus, picgen, textRows), video(videoMode, addressBus, picgen, textRows),
transistors("transistors"), // TODO load file from resources transistors("transistors"),
cpu(NULL), cpu(nullptr),
powerUpReset(*this), powerUpReset(*this),
revision(1) { revision(1) {
} }
Apple2::~Apple2() { Apple2::~Apple2() {
if (this->cpu) {
delete this->cpu;
}
} }
void Apple2::useEpple2Cpu() { void Apple2::useEpple2Cpu() {
if (this->cpu == NULL) { if (this->cpu == nullptr) {
std::cout << "Using fast Epple2 CPU emulator" << std::endl; std::cout << "Using fast Epple2 CPU emulator" << std::endl;
this->cpu = new CPU(this->addressBus); this->cpu = new CPU(this->addressBus);
} }
} }
void Apple2::useVisual6502Cpu() { void Apple2::useVisual6502Cpu() {
if (this->cpu == NULL) { if (this->cpu == nullptr) {
std::cout << "Using http://www.visual6502.org/ CPU emulation (which will be slow)." << std::endl; std::cout << "Using http://www.visual6502.org/ CPU emulation (which will be slow)." << std::endl;
this->cpu = new Emu6502(this->transistors, this->addressBus); this->cpu = new Emu6502(this->transistors, this->addressBus);
} }

View File

@ -38,7 +38,9 @@
#include "cassettein.h" #include "cassettein.h"
#include "cassetteout.h" #include "cassetteout.h"
#include "Emu6502.h" #include "Emu6502.h"
#include <fstream>
#include <filesystem>
class Emulator; class Emulator;
class ScreenImage; class ScreenImage;
@ -57,7 +59,7 @@ class Apple2 : public Timable
PictureGenerator picgen; PictureGenerator picgen;
TextCharacters textRows; TextCharacters textRows;
Video video; Video video;
std::ifstream transistors; std::filesystem::path transistors;
AbstractCpu* cpu; AbstractCpu* cpu;
PowerUpReset powerUpReset; PowerUpReset powerUpReset;
int revision; int revision;

View File

@ -186,6 +186,7 @@ void E2Command::tryParseLine(const std::string& line, MemoryRandomAccess& ram, M
trim(file); trim(file);
std::ifstream *memfile = new std::ifstream(file.c_str(), std::ios::binary); std::ifstream *memfile = new std::ifstream(file.c_str(), std::ios::binary);
if (!memfile->is_open()) { if (!memfile->is_open()) {
delete memfile;
std::filesystem::path f = wxGetApp().GetResDir(); std::filesystem::path f = wxGetApp().GetResDir();
f /= file; f /= file;
memfile = new std::ifstream(f, std::ios::binary); memfile = new std::ifstream(f, std::ios::binary);
@ -216,6 +217,7 @@ void E2Command::tryParseLine(const std::string& line, MemoryRandomAccess& ram, M
throw ConfigException("error at \"" + romtype + "\"; expected rom, rom7, or rombank"); throw ConfigException("error at \"" + romtype + "\"; expected rom, rom7, or rombank");
} }
memfile->close(); memfile->close();
delete memfile;
} else if (cmd == "load" || cmd == "save" || cmd == "unload") { } else if (cmd == "load" || cmd == "save" || cmd == "unload") {
std::string slotk; std::string slotk;
tok >> slotk; tok >> slotk;

View File

@ -25,6 +25,8 @@
#include <SDL.h> #include <SDL.h>
#include <boost/log/trivial.hpp>
#include <ctime> #include <ctime>
@ -222,6 +224,7 @@ static bool translateKeysToAppleModernized(SDL_Keycode keycode, SDL_Keymod modif
// Take real-world keystrokes from SDL and filter them to emulate the Apple ][ keyboard // Take real-world keystrokes from SDL and filter them to emulate the Apple ][ keyboard
void Emulator::dispatchKeyDown(const SDL_KeyboardEvent& keyEvent) { void Emulator::dispatchKeyDown(const SDL_KeyboardEvent& keyEvent) {
if (keyEvent.repeat) { if (keyEvent.repeat) {
// To repeat on the real Apple ][, you need to use the REPT key (emulated below by F10)
return; return;
} }
@ -235,22 +238,19 @@ void Emulator::dispatchKeyDown(const SDL_KeyboardEvent& keyEvent) {
} }
if (sym == SDLK_F10) { if (sym == SDLK_F10) {
// ...start auto-repeat // handle REPT key
this->repeat = true; this->repeat = true;
this->rept = CYCLES_PER_REPT; this->rept = CYCLES_PER_REPT;
return;
} else if (SDLK_F1 <= sym && sym <= SDLK_F12) { } else if (SDLK_F1 <= sym && sym <= SDLK_F12) {
wxGetApp().OnFnKeyPressed(sym); wxGetApp().OnFnKeyPressed(sym);
return; } else {
} unsigned char key;
const bool sendKey = translateKeysToAppleModernized(sym, mod, &key);
unsigned char key; if (sendKey) {
const bool sendKey = translateKeysToAppleModernized(sym, mod, &key); //printf(" sending to apple as ASCII ------------------------------> %02X (%02X) (%d)\n", key, key | 0x80, key | 0x80);
this->keypresses.push(key);
if (sendKey) { this->lastKeyDown = key;
//printf(" sending to apple as ASCII ------------------------------> %02X (%02X) (%d)\n", key, key | 0x80, key | 0x80); }
this->keypresses.push(key);
this->lastKeyDown = key;
} }
} }
@ -296,6 +296,8 @@ static int askSave() {
} }
bool Emulator::isSafeToQuit() { bool Emulator::isSafeToQuit() {
BOOST_LOG_TRIVIAL(info) << "Checking for any unsaved changes...";
this->screenImage.exitFullScreen(); this->screenImage.exitFullScreen();
if (!this->apple2.cassetteOut.eject()) { if (!this->apple2.cassetteOut.eject()) {

View File

@ -51,14 +51,16 @@ class Emulator {
unsigned char lastKeyDown; unsigned char lastKeyDown;
Uint32 prev_ms; Uint32 prev_ms;
void dispatchKeyDown(const SDL_KeyboardEvent& keyEvent);
void dispatchKeyUp(const SDL_KeyboardEvent& keyEvent);
void powerOnComputer(); void powerOnComputer();
void powerOffComputer(); void powerOffComputer();
void handleRepeatKey();
void handleAnyPendingEvents(); void handleAnyPendingEvents();
void dispatchKeyDown(const SDL_KeyboardEvent& keyEvent);
void dispatchKeyUp(const SDL_KeyboardEvent& keyEvent);
void handleRepeatKey();
public: public:
Emulator(); Emulator();
virtual ~Emulator(); virtual ~Emulator();

View File

@ -15,18 +15,15 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <iostream>
#include "gui.h" #include "gui.h"
#include <SDL.h> #include <SDL.h>
/*
* Initialize SDL 2
*/
GUI::GUI() { GUI::GUI() {
const int result = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO); const int result = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO);
if (result != 0) { if (result != 0) {
std::cerr << "Failed to initialize SDL: " << SDL_GetError() << std::endl;
throw GUI::NotInitException(); throw GUI::NotInitException();
} }
} }
@ -35,40 +32,9 @@ GUI::~GUI() {
SDL_Quit(); SDL_Quit();
} }
static void pushSdlEvent(SDL_Event *e) {
const int r = SDL_PushEvent(e);
if (r < 0) {
std::cerr << "SDL reported error: " << SDL_GetError() << std::endl;
} else if (r == 0) {
std::cerr << "SDL filtered event, sorry" << std::endl;
} else if (r == 1) {
std::cerr << "Pushed event to SDL" << std::endl;
} else {
std::cerr << "SDL reported unexpected error code: " << r << std::endl;
}
}
void GUI::queueTogglePower() {
SDL_Event *e = new SDL_Event(); // note: creating struct on the stack doesn't seem to work
e->type = SDL_KEYDOWN;
e->key.keysym.sym = SDLK_F1;
pushSdlEvent(e);
delete e;
}
void GUI::queueQuit() {
SDL_Event *e = new SDL_Event();
e->type = SDL_KEYDOWN;
e->key.keysym.sym = SDLK_F9;
pushSdlEvent(e);
delete e;
}
GUI::NotInitException::NotInitException() : runtime_error(SDL_GetError()) {
GUI::NotInitException::NotInitException() : runtime_error("Unable to initialize SDL") {
SDL_GetError();
} }
GUI::NotInitException::~NotInitException() { GUI::NotInitException::~NotInitException() {

View File

@ -25,9 +25,6 @@ public:
GUI(); GUI();
virtual ~GUI(); virtual ~GUI();
static void queueQuit();
static void queueTogglePower();
class NotInitException : public std::runtime_error { class NotInitException : public std::runtime_error {
public: public:
NotInitException(); NotInitException();

View File

@ -34,6 +34,9 @@ LanguageCard::LanguageCard(ScreenImage& gui, int slot):
LanguageCard::~LanguageCard() LanguageCard::~LanguageCard()
{ {
for (Memory* m : this->ramBank) {
delete m;
}
} }

View File

@ -57,15 +57,19 @@ class ScreenException {
}; };
ScreenImage::ScreenImage() : ScreenImage::ScreenImage() :
fullscreen(false), fullscreen(false),
buffer(true), buffer(true),
display(AnalogTV::TV_OLD_COLOR), display(AnalogTV::TV_OLD_COLOR),
slotnames(8), slotnames(8),
cassInName(32, ' '), cassInName(32, ' '),
cassOutName(32, ' ') { cassOutName(32, ' ') {
createScreen(); createScreen();
} }
ScreenImage::~ScreenImage() {
destroyScreen();
}
void ScreenImage::exitFullScreen() { void ScreenImage::exitFullScreen() {
if (this->fullscreen) { if (this->fullscreen) {
toggleFullScreen(); toggleFullScreen();
@ -106,6 +110,12 @@ void ScreenImage::createScreen() {
notifyObservers(); notifyObservers();
} }
void ScreenImage::destroyScreen() {
SDL_DestroyTexture(this->texture);
SDL_DestroyRenderer(this->renderer);
SDL_DestroyWindow(this->window);
}
void ScreenImage::drawLabels() { void ScreenImage::drawLabels() {
drawText("EPPLE ][", 0, 141); drawText("EPPLE ][", 0, 141);
drawText("ANNUNCIATORS: 0: 1: 2: 3:", 65, 17); drawText("ANNUNCIATORS: 0: 1: 2: 3:", 65, 17);
@ -275,9 +285,6 @@ void ScreenImage::drawPower(bool on) {
notifyObservers(); notifyObservers();
} }
ScreenImage::~ScreenImage() {
}
void ScreenImage::notifyObservers() { void ScreenImage::notifyObservers() {
const int e = SDL_UpdateTexture(this->texture, NULL, this->pixels, SCRW * sizeof (unsigned int)); const int e = SDL_UpdateTexture(this->texture, NULL, this->pixels, SCRW * sizeof (unsigned int));
if (e) { if (e) {

View File

@ -39,6 +39,7 @@ private:
bool buffer; bool buffer;
AnalogTV::DisplayType display; AnalogTV::DisplayType display;
void createScreen(); void createScreen();
void destroyScreen();
std::vector<std::string> slotnames; std::vector<std::string> slotnames;
std::string cassInName; std::string cassInName;
std::string cassOutName; std::string cassOutName;

View File

@ -29,6 +29,11 @@ Slots::Slots(ScreenImage& gui):
Slots::~Slots() Slots::~Slots()
{ {
for (Card *card : this->cards) {
if (card != &this->empty) {
delete card;
}
}
} }
unsigned char Slots::io(const int islot, const int iswch, const unsigned char b, const bool writing) unsigned char Slots::io(const int islot, const int iswch, const unsigned char b, const bool writing)