From 350627e09c308121f271da150512b18d97c2a6a4 Mon Sep 17 00:00:00 2001 From: spacy51 Date: Sun, 24 Feb 2008 00:10:53 +0000 Subject: [PATCH] Qt: ADDED ROM file loading --- project/qmake/vba-m.pro | 5 +++ project/vc2008/vba-m.vcproj | 12 ++++++ src/qt/EmuManager.cpp | 85 +++++++++++++++++++++++++++++++++++++ src/qt/EmuManager.h | 41 ++++++++++++++++++ src/qt/MainWnd.cpp | 26 ++++++++++-- src/qt/MainWnd.h | 3 ++ src/qt/precompile.h | 1 + 7 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 src/qt/EmuManager.cpp create mode 100644 src/qt/EmuManager.h diff --git a/project/qmake/vba-m.pro b/project/qmake/vba-m.pro index b6d5d2f1..bc87ec10 100644 --- a/project/qmake/vba-m.pro +++ b/project/qmake/vba-m.pro @@ -14,6 +14,8 @@ TRANSLATIONS += ../../lang/spanish.ts PRECOMPILED_HEADER = ../../src/qt/precompile.h +HEADERS += ../../src/qt/version.h + HEADERS += ../../src/qt/main.h SOURCES += ../../src/qt/main.cpp @@ -32,3 +34,6 @@ SOURCES += ../../src/qt/MainOptions.cpp HEADERS += ../../src/qt/configdialog.h SOURCES += ../../src/qt/configdialog.cpp + +HEADERS += ../../src/qt/EmuManager.h +SOURCES += ../../src/qt/EmuManager.cpp diff --git a/project/vc2008/vba-m.vcproj b/project/vc2008/vba-m.vcproj index 968064bf..f4697cd4 100644 --- a/project/vc2008/vba-m.vcproj +++ b/project/vc2008/vba-m.vcproj @@ -174,6 +174,18 @@ > + + + + + + diff --git a/src/qt/EmuManager.cpp b/src/qt/EmuManager.cpp new file mode 100644 index 00000000..8c0896b5 --- /dev/null +++ b/src/qt/EmuManager.cpp @@ -0,0 +1,85 @@ +// VBA-M, A Nintendo Handheld Console Emulator +// Copyright (C) 2008 VBA-M development team +// +// This program 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 2, or(at your option) +// any later version. +// +// This program 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 this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#include "EmuManager.h" + + +EmuManager::EmuManager() +: romBuffer( 0 ) +{ +} + + +EmuManager::~EmuManager() +{ + if( romBuffer != 0 ) { + free( romBuffer ); + romBuffer = 0; + } +} + + +void EmuManager::setROM( QString &file ) +{ + romPath = file; +} + + +QString &EmuManager::getROM() +{ + return romPath; +} + + +bool EmuManager::loadROM() +{ + // validate ROM + if( romPath.isEmpty() ) return false; + + QFile file( romPath ); + + if( !file.exists() ) return false; + + qint64 size = file.size(); + if( ( size == 0 ) || ( size > 0x2000000 /* 32MB */ ) ) return false; + + // TODO: add further validation + + // read ROM into memory + if( !file.open( QIODevice::ReadOnly ) ) return false; + + if( romBuffer != 0 ) { + // resize the buffer + unsigned char *temp; + temp = (unsigned char *)realloc( romBuffer, size ); + if( temp == 0 ) { + free( romBuffer ); + return false; + } else { + romBuffer = temp; + } + } else { + // create the buffer + romBuffer = (unsigned char *)malloc( size ); + if( romBuffer == 0 ) return false; + } + + if( -1 == file.read( (char *)romBuffer, size ) ) return false; + + return true; +} diff --git a/src/qt/EmuManager.h b/src/qt/EmuManager.h new file mode 100644 index 00000000..b49b842d --- /dev/null +++ b/src/qt/EmuManager.h @@ -0,0 +1,41 @@ +// VBA-M, A Nintendo Handheld Console Emulator +// Copyright (C) 2008 VBA-M development team +// +// This program 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 2, or(at your option) +// any later version. +// +// This program 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 this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifndef EMUMANAGER_H +#define EMUMANAGER_H + +#include "precompile.h" + +// class to abstract emulation control +class EmuManager +{ +public: + EmuManager(); + ~EmuManager(); + + void setROM( QString &file ); + QString &getROM(); + + bool loadROM(); + +private: + QString romPath; + unsigned char *romBuffer; +}; + +#endif // #ifndef EMUMANAGER_H diff --git a/src/qt/MainWnd.cpp b/src/qt/MainWnd.cpp index 0ced8d24..0ecacb6f 100644 --- a/src/qt/MainWnd.cpp +++ b/src/qt/MainWnd.cpp @@ -33,7 +33,8 @@ MainWnd::MainWnd( QTranslator **trans, QSettings *settings, QWidget *parent ) toolsMenu( 0 ), helpMenu( 0 ), enableTranslationAct( 0 ), - dockWidget_cheats( 0 ) + dockWidget_cheats( 0 ), + emuManager( 0 ) { createDisplay(); setMinimumSize( 320, 240 ); @@ -44,11 +45,17 @@ MainWnd::MainWnd( QTranslator **trans, QSettings *settings, QWidget *parent ) createMenus(); loadSettings(); + + emuManager = new EmuManager(); } MainWnd::~MainWnd() { + if( emuManager != 0 ) { + delete emuManager; + emuManager = 0; + } } @@ -290,10 +297,21 @@ void MainWnd::showAbout() void MainWnd::showOpenROM() { - QString info; - info += tr ( "Enter ROM loader code here." ); + QString file = QFileDialog::getOpenFileName( + this, + tr( "Select ROM" ), + "", + tr( "Game Boy Advance ROMs (*.gba);;All Files (*.*)" ) ); - QMessageBox::about( this, tr( "Status" ), info ); + if( file.isNull() ) return; + + emuManager->setROM( file ); + if( !emuManager->loadROM() ) { + QMessageBox::critical( this, tr( "Error!" ), tr( "Can not load ROM!" ) ); + return; + } + + // TODO: start emulation } diff --git a/src/qt/MainWnd.h b/src/qt/MainWnd.h index 30d29168..124e03ec 100644 --- a/src/qt/MainWnd.h +++ b/src/qt/MainWnd.h @@ -21,6 +21,8 @@ #include "precompile.h" +#include "EmuManager.h" + class MainWnd : public QMainWindow { Q_OBJECT @@ -50,6 +52,7 @@ private: QMenu *toolsMenu; QMenu *helpMenu; QDockWidget *dockWidget_cheats; + EmuManager *emuManager; private slots: bool selectLanguage(); diff --git a/src/qt/precompile.h b/src/qt/precompile.h index 3abe2a67..9f92b4c7 100644 --- a/src/qt/precompile.h +++ b/src/qt/precompile.h @@ -23,6 +23,7 @@ // Add C++ includes here #include #include +#include #endif #endif // #ifndef PRECOMPILE_H