Skip to content

Commit

Permalink
Enable RAM saving and some menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottRichardsCG committed Jan 11, 2017
1 parent 19a7547 commit 4009fb0
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 26 deletions.
8 changes: 1 addition & 7 deletions forms/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</rect>
</property>
<property name="value">
<number>24</number>
<number>0</number>
</property>
<property name="textVisible">
<bool>true</bool>
Expand Down Expand Up @@ -154,7 +154,6 @@
<string>Help</string>
</property>
<addaction name="actionAbout"/>
<addaction name="actionDonate"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEmulator"/>
Expand Down Expand Up @@ -206,11 +205,6 @@
<string>About</string>
</property>
</action>
<action name="actionDonate">
<property name="text">
<string>Donate</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
Expand Down
1 change: 1 addition & 0 deletions inc/emucore.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class EmuCore

int load(std::string filename);
int analyseROM(std::string filename);
int save();
};

extern EmuCore *emucore;
Expand Down
2 changes: 2 additions & 0 deletions inc/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class MainWindow : public QMainWindow
void* getDrawingArea();

private slots:
void on_actionHardReset_triggered();
void on_actionLoad_ROM_triggered();
void on_actionSwitch_On_triggered();
void do_everySecond();
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
Expand Down
8 changes: 4 additions & 4 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ void Cpu::reset()
memory->writeDirect(0x0011, 0x20);
memory->writeDirect(0x0012, 0x00);
memory->writeDirect(0x0013, 0x00);
//BYTE ram = memory->readDirect(0x0014);
//ram &= 0x80;
//ram |= 0x7C;
//memory->writeDirect(0x0014, ram);
BYTE ram = memory->readDirect(0x0014);
ram &= 0x80;
ram |= 0x7C;
memory->writeDirect(0x0014, ram);
memory->writeDirect(0x0014, 0x7C);
//datapak->port6_DDR_W(0x00);
memory->writeDirect(0x0019, 0xFF);
Expand Down
30 changes: 17 additions & 13 deletions src/emucore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ int EmuCore::load(std::string filename) {

romPath = filename;
ramPath = filename + ".sav";
romLoaded = true;

INTERNAL_reset();
memory->clearROM();
Expand All @@ -304,21 +305,24 @@ int EmuCore::load(std::string filename) {
return romType;
}

/*

int EmuCore::save() {
if (!fileio.romLoaded) return FILEIO_SUCCESS;
if (!romLoaded)
return FILEIO_SUCCESS;

QFile file(fileio.ramPath);
if (!file.open(QIODevice::ReadWrite)) {
return FILEIO_RAM_SaveFail;
}
char ram[983040];
unsigned int len = settings[currentMode].maxRamBanks * 0x4000;
memory->readRAM(ram, len);
file.write(QByteArray(ram, len));
file.close();
return FILEIO_SUCCESS;
}*/
std::ofstream ramStream;
ramStream.open(ramPath, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
if (!ramStream.good())
return FILEIO_RAM_SaveFail;

unsigned int length = settings[currentMode].maxRamBanks * 0x4000;
char ram[98304];
memory->readRAM(ram, length);
ramStream.write(ram, length);
ramStream.close();

return FILEIO_SUCCESS;
}

// This function analyses a ROM file and returns its intended hardware setup
int EmuCore::analyseROM(std::string filename) {
Expand Down
56 changes: 54 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QFileDialog>
#include <iostream>
#include <QMessageBox>
#include <QTimer>
#include <QKeyEvent>
#include <QPushButton>

#include "emucore.h"
#include "keypad.h"

Expand Down Expand Up @@ -35,12 +37,43 @@ void* MainWindow::getDrawingArea()
void MainWindow::on_actionLoad_ROM_triggered()
{
emucore->pause(true);

if (emucore->isPowered()) {
QMessageBox msgBox;
msgBox.setText("The emulator is not switched off. Changes to RAM cannot be saved as this time.");
msgBox.setInformativeText("Are you sure you want to load a new ROM anyway?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
msgBox.setIcon(QMessageBox::Warning);
int ret = msgBox.exec();
if (ret == QMessageBox::Cancel) {
emucore->pause(false);
return;
}
}

int suc = emucore->save();
if (suc != FILEIO_SUCCESS) {
QMessageBox msgBox;
msgBox.setText("Problem saving the current RAM. Loading a new ROM with result in loss of data.");
msgBox.setInformativeText("Are you sure you want to load a new ROM anyway?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
msgBox.setIcon(QMessageBox::Warning);
int ret = msgBox.exec();
if (ret == QMessageBox::Cancel) {
emucore->pause(false);
return;
}
}

QString fileName = QFileDialog::getOpenFileName(this, "Select ROM file...", "", "Psion ROMs (*.bin *.rom *.dat);;All Files (*.*)");
if (fileName == "") {
emucore->pause(false);
return;
}
int suc = emucore->load(fileName.toStdString());

suc = emucore->load(fileName.toStdString());
if (suc == FILEIO_ROM_LoadFail) {
QMessageBox msgBox;
msgBox.setText("ROM could not be loaded");
Expand All @@ -58,6 +91,25 @@ void MainWindow::on_actionLoad_ROM_triggered()
emucore->pause(false);
}

void MainWindow::on_actionHardReset_triggered() {
emucore->pause(true);
QMessageBox msgBox;
msgBox.setText("This will completely erase all data in this ROM. This is unrecoverable!!");
msgBox.setInformativeText("Are you sure you want to hard reset the emulator?");
msgBox.setStandardButtons(QMessageBox::Cancel);
QPushButton *hardResetButton = msgBox.addButton("Hard Reset!", QMessageBox::ActionRole);
msgBox.setDefaultButton(QMessageBox::Cancel);
msgBox.exec();
if (msgBox.clickedButton() == hardResetButton) {
emucore->hardReset();
}
emucore->pause(false);
}

void MainWindow::on_actionSwitch_On_triggered() {
emucore->setPower(true);
}

void MainWindow::keyPressEvent(QKeyEvent *event) {
if (event->isAutoRepeat() == false) {
switch (event->key()) {
Expand Down

0 comments on commit 4009fb0

Please sign in to comment.