Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nnarain committed Nov 20, 2016
2 parents 7eb35f7 + 69c6f36 commit b69b816
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ before_build:
- qtenv2.bat
- call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %platform%

- git clone --depth=1 --branch=0.9.1 https://github.com/nnarain/gameboycore.git c:\tmp\gameboycore
- git clone --depth=1 --branch=0.11.0 https://github.com/nnarain/gameboycore.git c:\tmp\gameboycore
- cd c:\tmp\gameboycore
- mkdir build && cd build
- cmake .. -G "NMake Makefiles" -DBUILD_TESTS="OFF" -DBUILD_EXAMPLE="OFF" -DCMAKE_INSTALL_PREFIX=c:\libs\gameboycore
Expand Down
3 changes: 2 additions & 1 deletion include/core_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class CoreUpdater

void stop()
{
worker_->wait();
if(worker_)
worker_->wait();
}

bool isRunning()
Expand Down
9 changes: 2 additions & 7 deletions include/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Input
PRESSED, RELEASED
};

Input() : joy_(nullptr)
Input(gb::Joy::Ptr& joy) : joy_(joy)
{
// TODO: read key map from file
keymap_.insert({ Qt::Key_W, gb::Joy::Key::UP });
Expand All @@ -49,17 +49,12 @@ class Input
joy_->release(gbkey);
}

void setJoypad(gb::Joy::Ptr& joy)
{
joy_ = joy;
}

~Input()
{
}

private:
gb::Joy::Ptr joy_;
gb::Joy::Ptr& joy_;
std::map<int, gb::Joy::Key> keymap_;
};

Expand Down
4 changes: 3 additions & 1 deletion include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ private slots:
private:
Ui::MainWindow *ui;

gb::GameboyCore gameboycore_;

QTimer refresh_timer_;
Screen* screen_;
CoreUpdater updater_;
Input input_;

gb::GameboyCore gameboycore_;
QString save_file_name_;
};


Expand Down
46 changes: 38 additions & 8 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QDir>

#include <functional>

Expand All @@ -11,7 +13,9 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow),
refresh_timer_(this),
screen_(new Screen),
updater_(gameboycore_)
updater_(gameboycore_),
input_(gameboycore_.getJoypad()),
save_file_name_("")
{
ui->setupUi(this);

Expand Down Expand Up @@ -62,14 +66,32 @@ void MainWindow::loadROM(const QString& filename)
{
// read rom file
QFile file(filename);
std::vector<uint8_t> buffer;
buffer.resize(file.size());
std::vector<uint8_t> rom;
rom.resize(file.size());

file.open(QIODevice::ReadOnly);
file.read((char*)&buffer[0], file.size());
file.read((char*)&rom[0], file.size());

// load rom into the core
gameboycore_.loadROM(&buffer[0], buffer.size());
// load rom into the core
gameboycore_.loadROM(&rom[0], rom.size());

// Save file info
QFileInfo saveinfo(filename);
save_file_name_ = QDir::cleanPath(saveinfo.canonicalPath() + QDir::separator() + saveinfo.baseName() + ".sav");
QFile savefile(save_file_name_);

if (savefile.exists())
{
savefile.open(QIODevice::ReadOnly);
std::vector<uint8_t> ram;

if (savefile.size() > 0)
{
ram.resize(savefile.size());
savefile.read((char*)&ram[0], ram.size());
gameboycore_.getMMU()->setBatteryRam(ram);
}
}

gameboycore_.getGPU()->setRenderCallback(
std::bind(
Expand All @@ -79,15 +101,23 @@ void MainWindow::loadROM(const QString& filename)
)
);

input_.setJoypad(gameboycore_.getJoypad());

ui->statusBar->showMessage("Loaded " + filename);
}

void MainWindow::closeEvent(QCloseEvent *event)
{
updater_.stop();

// save battery ram
if (save_file_name_ != "")
{
auto ram = gameboycore_.getMMU()->getBatteryRam();

QFile file(save_file_name_);
file.open(QIODevice::WriteOnly);
file.write((char*)&ram[0], ram.size());
}

QMainWindow::closeEvent(event);
}

Expand Down

0 comments on commit b69b816

Please sign in to comment.