forked from nba-emu/NanoBoyAdvance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
327 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
project(NanoboyAdvance C CXX) | ||
project(NanoboyAdvance CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) | ||
|
||
set(PLATFORM "sdl" CACHE STRING "Build Target (sdl, ...)") | ||
option(FRONTEND_QT "Enable Qt5 frontend" ON) | ||
option(FRONTEND_SDL "Enable SDL2 frontend" ON) | ||
|
||
set(COMPILE_FLAGS "${COMPILE_FLAGS} -Ofast") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILE_FLAGS}") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}") | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast") | ||
|
||
option(PROFILE_GPROF "Profile with gprof" OFF) | ||
if (PROFILE) | ||
add_definitions(-pg) | ||
set(CMAKE_EXE_LINKER_FLAGS -pg) | ||
endif() | ||
endif() | ||
|
||
if (CMAKE_CXX_COMPILER_ID STREQUAL Clang) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") | ||
endif() | ||
|
||
#add_definitions(-pg) | ||
#set(CMAKE_EXE_LINKER_FLAGS -pg) | ||
|
||
add_subdirectory(source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
include_directories(.) | ||
|
||
option(PLATFORM_QT "Enable Qt5 frontend" ON) | ||
option(PLATFORM_SDL "Enable SDL2 frontend" ON) | ||
|
||
add_subdirectory(gba) | ||
add_subdirectory("platform/${PLATFORM}") | ||
|
||
if (PLATFORM_QT) | ||
add_subdirectory("platform/qt") | ||
endif() | ||
|
||
if (PLATFORM_SDL) | ||
add_subdirectory("platform/sdl") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
SET(SOURCES | ||
main.cpp | ||
mainwindow.cpp | ||
screen.cpp | ||
) | ||
|
||
SET(HEADERS | ||
mainwindow.hpp | ||
screen.hpp | ||
) | ||
|
||
# TODO: do we really need this line? | ||
set(CMAKE_AUTOMOC ON) | ||
|
||
find_package(OpenGL REQUIRED) | ||
find_package(Qt5Gui REQUIRED) | ||
find_package(Qt5Widgets REQUIRED) | ||
find_package(Qt5OpenGL REQUIRED) | ||
set(QT_DEPS Qt5::Gui Qt5::Widgets Qt5::OpenGL) | ||
|
||
ADD_EXECUTABLE(NanoboyAdvance ${SOURCES} ${HEADERS}) | ||
TARGET_LINK_LIBRARIES(NanoboyAdvance gba ${QT_DEPS} ${OPENGL_gl_LIBRARY}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <QApplication> | ||
#include "mainwindow.hpp" | ||
|
||
int main(int argc, char** argv) { | ||
QApplication app{ argc, argv }; | ||
MainWindow window{ &app }; | ||
|
||
QCoreApplication::setOrganizationName("fleroviux"); | ||
QCoreApplication::setApplicationName("NanoboyAdvance"); | ||
|
||
window.show(); | ||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright (C) 2020 fleroviux (Frederic Meyer) | ||
* | ||
* This file is part of NanoboyAdvance. | ||
* | ||
* NanoboyAdvance is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* NanoboyAdvance is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with NanoboyAdvance. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// TEST | ||
#include <gba/emulator.hpp> | ||
#include <thread> | ||
|
||
#include <QApplication> | ||
#include <QMenuBar> | ||
|
||
#include "mainwindow.hpp" | ||
|
||
MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) { | ||
setWindowTitle("NanoboyAdvance"); | ||
app->installEventFilter(this); | ||
|
||
/* Setup OpenGL widget */ | ||
screen = std::make_shared<Screen>(this); | ||
setCentralWidget(screen.get()); | ||
|
||
/* Create menu bar */ | ||
auto menubar = new QMenuBar(this); | ||
setMenuBar(menubar); | ||
|
||
/* Create file menu */ | ||
auto file_menu = menubar->addMenu(tr("&File")); | ||
auto file_open = file_menu->addAction(tr("&Open")); | ||
auto file_close = file_menu->addAction(tr("&Close")); | ||
|
||
/* Create help menu */ | ||
auto help_menu = menubar->addMenu(tr("&?")); | ||
|
||
connect(file_open, &QAction::triggered, this, [this] { | ||
//auto config = std::make_shared<GameBoyAdvance::Config>(); | ||
//config->video_dev = screen; | ||
|
||
//auto emulator = std::make_unique<GameBoyAdvance::Emulator>(config); | ||
//emulator->LoadGame("violet.gba"); | ||
//emulator->Reset(); | ||
//for (int i = 0; i < 20000; i++) { | ||
// emulator->Frame(); | ||
//} | ||
|
||
std::thread test([&] { | ||
auto config = std::make_shared<GameBoyAdvance::Config>(); | ||
config->video_dev = screen; | ||
|
||
auto emulator = std::make_unique<GameBoyAdvance::Emulator>(config); | ||
emulator->LoadGame("violet.gba"); | ||
emulator->Reset(); | ||
|
||
while (true) { | ||
emulator->Frame(); | ||
} | ||
}); | ||
|
||
test.detach(); | ||
}); | ||
} | ||
|
||
MainWindow::~MainWindow() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (C) 2020 fleroviux (Frederic Meyer) | ||
* | ||
* This file is part of NanoboyAdvance. | ||
* | ||
* NanoboyAdvance is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* NanoboyAdvance is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with NanoboyAdvance. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <QMainWindow> | ||
|
||
#include "screen.hpp" | ||
|
||
class MainWindow : public QMainWindow { | ||
Q_OBJECT | ||
|
||
public: | ||
MainWindow(QApplication* app, QWidget* parent = 0); | ||
~MainWindow(); | ||
|
||
private: | ||
std::shared_ptr<Screen> screen; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright (C) 2020 fleroviux (Frederic Meyer) | ||
* | ||
* This file is part of NanoboyAdvance. | ||
* | ||
* NanoboyAdvance is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* NanoboyAdvance is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with NanoboyAdvance. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "screen.hpp" | ||
|
||
void Screen::Draw(std::uint32_t* buffer) { | ||
emit SignalDraw(buffer); | ||
} | ||
|
||
void Screen::DrawSlot(std::uint32_t* buffer) { | ||
glBindTexture(GL_TEXTURE_2D, texture); | ||
|
||
/* Update texture pixels */ | ||
glTexImage2D( | ||
GL_TEXTURE_2D, | ||
0, | ||
GL_RGBA, | ||
240, /* TODO: do not hardcode the dimensions? */ | ||
160, | ||
0, | ||
GL_BGRA, | ||
GL_UNSIGNED_BYTE, | ||
buffer | ||
); | ||
|
||
/* Redraw screen */ | ||
update(); | ||
} | ||
|
||
void Screen::initializeGL() { | ||
glMatrixMode(GL_PROJECTION); | ||
glLoadIdentity(); | ||
|
||
glMatrixMode(GL_MODELVIEW); | ||
glLoadIdentity(); | ||
|
||
glEnable(GL_TEXTURE_2D); | ||
glGenTextures(1, &texture); | ||
glBindTexture(GL_TEXTURE_2D, texture); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||
|
||
glClearColor(0, 0, 0, 1); | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
} | ||
|
||
void Screen::paintGL() { | ||
glViewport(viewport_x, 0, viewport_width, viewport_height); | ||
glBindTexture(GL_TEXTURE_2D, texture); | ||
|
||
glBegin(GL_QUADS); | ||
{ | ||
glTexCoord2f(0, 0); | ||
glVertex2f(-1.0f, 1.0f); | ||
|
||
glTexCoord2f(1.0f, 0); | ||
glVertex2f(1.0f, 1.0f); | ||
|
||
glTexCoord2f(1.0f, 1.0f); | ||
glVertex2f(1.0f, -1.0f); | ||
|
||
glTexCoord2f(0, 1.0f); | ||
glVertex2f(-1.0f, -1.0f); | ||
} | ||
glEnd(); | ||
} | ||
|
||
void Screen::resizeGL(int width, int height) { | ||
viewport_width = height + height / 2; | ||
viewport_height = height; | ||
viewport_x = (width - viewport_width) / 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (C) 2020 fleroviux (Frederic Meyer) | ||
* | ||
* This file is part of NanoboyAdvance. | ||
* | ||
* NanoboyAdvance is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* NanoboyAdvance is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with NanoboyAdvance. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <QGLWidget> | ||
#include <QOpenGLWidget> | ||
#include <gba/config/device/video_device.hpp> | ||
|
||
class Screen : public QOpenGLWidget, | ||
public GameBoyAdvance::VideoDevice { | ||
Q_OBJECT | ||
|
||
public: | ||
Screen(QWidget* parent) : QOpenGLWidget(parent) { | ||
QSurfaceFormat format; | ||
format.setSwapInterval(0); | ||
setFormat(format); | ||
|
||
connect(this, &Screen::SignalDraw, this, &Screen::DrawSlot); | ||
} | ||
|
||
~Screen() override { glDeleteTextures(1, &texture); } | ||
|
||
void Draw(std::uint32_t* buffer) final; | ||
|
||
auto sizeHint() const -> QSize { | ||
return QSize{ 480, 320 }; | ||
} | ||
|
||
protected: | ||
void initializeGL() override; | ||
void paintGL() override; | ||
void resizeGL(int width, int height) override; | ||
|
||
private slots: | ||
void DrawSlot(std::uint32_t* buffer); | ||
|
||
signals: | ||
void SignalDraw(std::uint32_t* buffer); | ||
|
||
private: | ||
int viewport_x = 0; | ||
int viewport_width = 0; | ||
int viewport_height = 0; | ||
|
||
GLuint texture; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters