diff --git a/src/qt/displaywidget.cpp b/src/qt/displaywidget.cpp index 752ccd0..692b64b 100644 --- a/src/qt/displaywidget.cpp +++ b/src/qt/displaywidget.cpp @@ -1,6 +1,6 @@ /* * emuChip - CHIP-8 emulator. - * Copyright (C) 2009 Boris Timofeev + * Copyright (C) 2009-2012 Boris Timofeev * * 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 @@ -25,16 +25,22 @@ DisplayWidget::DisplayWidget() repaint(); } +DisplayWidget::~DisplayWidget() +{ +} + void DisplayWidget::clear() { - for (int i = 0; i < 2048; i++) - screen[i] = 0; + for (int y = 0; y < 64; y++) + for (int x = 0; x < 128; x++) + screen[x][y] = 0; } -void DisplayWidget::setScreen(unsigned char arr[64*32]) +void DisplayWidget::setScreen(unsigned char arr[128][64]) { - for (int i = 0; i < 2048; i++) - screen[i] = arr[i]; + for (int y = 0; y < 64; y++) + for (int x = 0; x < 128; x++) + screen[x][y] = arr[x][y]; } void DisplayWidget::paintEvent(QPaintEvent *) @@ -42,18 +48,16 @@ void DisplayWidget::paintEvent(QPaintEvent *) QPainter painter(this); painter.scale ( resolution, resolution ); QBrush brush(bgColor, Qt::SolidPattern); - painter.fillRect(0, 0, 64, 32, brush); + painter.fillRect(0, 0, 128, 64, brush); + + painter.setPen(fgColor); + painter.setBrush(fgColor); - int t = 0; - for (int i = 0; i < 32; i++) - for (int j = 0; j < 64; j++) - { - if (screen[t++] == 1) + for (int y = 0; y < 64; y++) + for (int x = 0; x < 128; x++) + if (screen[x][y] == 1) { - painter.setPen(fgColor); - painter.setBrush(fgColor); - if (resolution > 1) painter.drawRect ( j, i, 1, 1 ); - else painter.drawPoint(j, i); + if (resolution > 1) painter.drawRect ( x, y, 1, 1 ); + else painter.drawPoint(x, y); } - } } diff --git a/src/qt/displaywidget.h b/src/qt/displaywidget.h index 3252efb..e0bdbf1 100644 --- a/src/qt/displaywidget.h +++ b/src/qt/displaywidget.h @@ -1,6 +1,6 @@ /* * emuChip - CHIP-8 emulator. - * Copyright (C) 2009 Boris Timofeev + * Copyright (C) 2009-2012 Boris Timofeev * * 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 @@ -27,6 +27,7 @@ class DisplayWidget : public QWidget public: DisplayWidget(); + ~DisplayWidget(); void setResolution(int r) { resolution = r; } int getResolution() { return resolution; } @@ -35,7 +36,7 @@ class DisplayWidget : public QWidget QColor getBgColor() { return bgColor; } QColor getFgColor() { return fgColor; } - void setScreen(unsigned char [64*32]); + void setScreen(unsigned char [128][64]); void clear(); protected: @@ -47,7 +48,7 @@ class DisplayWidget : public QWidget QColor bgColor; QColor fgColor; - unsigned char screen[64*32]; + unsigned char screen[128][64]; }; #endif diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 0b7f92b..ce05beb 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -60,7 +60,7 @@ void MainWindow::emulation() QElapsedTimer et; et.start(); - while (emuStart) + while (emuStart == true) { QCoreApplication::processEvents ( QEventLoop::AllEvents ); @@ -81,6 +81,7 @@ void MainWindow::emulation() opcode_count = 0; } + if (emu->stop) closeRom(); } } @@ -134,79 +135,72 @@ void MainWindow::keyReleaseEvent(QKeyEvent *event) void MainWindow::closeEvent(QCloseEvent *event) { - emuStart = false; + closeRom(); writeSettings(); - delete display; - delete emu; event->accept(); } void MainWindow::createActions() { - openRomAction = new QAction(tr("&Open ROM.."), this); + openRomAction = new QAction(tr("Open ROM.."), this); openRomAction->setShortcut(tr("Ctrl+O")); connect(openRomAction, SIGNAL(triggered()), this, SLOT(openRom())); - closeRomAction = new QAction(tr("&Close ROM.."), this); + closeRomAction = new QAction(tr("Close ROM.."), this); closeRomAction->setShortcut(tr("Ctrl+C")); connect(closeRomAction, SIGNAL(triggered()), this, SLOT(closeRom())); - exitAction = new QAction(tr("E&xit"), this); + exitAction = new QAction(tr("Exit"), this); exitAction->setShortcut(tr("Alt+F4")); connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); - set1xAction = new QAction(tr("64x32"), this); + set1xAction = new QAction(tr("128x64"), this); set1xAction->setCheckable(true); connect(set1xAction, SIGNAL(triggered()), this, SLOT(set1x())); - set2xAction = new QAction(tr("128x64"), this); + set2xAction = new QAction(tr("256x128"), this); set2xAction->setCheckable(true); connect(set2xAction, SIGNAL(triggered()), this, SLOT(set2x())); - set4xAction = new QAction(tr("256x128"), this); + set4xAction = new QAction(tr("512x256"), this); set4xAction->setCheckable(true); connect(set4xAction, SIGNAL(triggered()), this, SLOT(set4x())); - set8xAction = new QAction(tr("512x256"), this); + set8xAction = new QAction(tr("1024x512"), this); set8xAction->setCheckable(true); connect(set8xAction, SIGNAL(triggered()), this, SLOT(set8x())); - set16xAction = new QAction(tr("1024x512"), this); - set16xAction->setCheckable(true); - connect(set16xAction, SIGNAL(triggered()), this, SLOT(set16x())); resolutionGroup = new QActionGroup(this); resolutionGroup->addAction(set1xAction); resolutionGroup->addAction(set2xAction); resolutionGroup->addAction(set4xAction); resolutionGroup->addAction(set8xAction); - resolutionGroup->addAction(set16xAction); - bgColorDialogAction = new QAction(tr("&Background color.."), this); + bgColorDialogAction = new QAction(tr("Background color.."), this); connect(bgColorDialogAction, SIGNAL(triggered()), this, SLOT(bgColorDialog())); - fgColorDialogAction = new QAction(tr("&Foreground color.."), this); + fgColorDialogAction = new QAction(tr("Foreground color.."), this); connect(fgColorDialogAction, SIGNAL(triggered()), this, SLOT(fgColorDialog())); - aboutAction = new QAction(tr("&About.."), this); + aboutAction = new QAction(tr("About.."), this); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); } void MainWindow::createMenu() { - fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu = menuBar()->addMenu(tr("File")); fileMenu->addAction(openRomAction); fileMenu->addAction(closeRomAction); fileMenu->addSeparator(); fileMenu->addAction(exitAction); - videoMenu = menuBar()->addMenu(tr("&Video")); - resolutionMenu = videoMenu->addMenu(tr("&Window size")); + videoMenu = menuBar()->addMenu(tr("Video")); + resolutionMenu = videoMenu->addMenu(tr("Window size")); resolutionMenu->addAction(set1xAction); resolutionMenu->addAction(set2xAction); resolutionMenu->addAction(set4xAction); resolutionMenu->addAction(set8xAction); - resolutionMenu->addAction(set16xAction); videoMenu->addSeparator(); videoMenu->addAction(bgColorDialogAction); videoMenu->addAction(fgColorDialogAction); - helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu = menuBar()->addMenu(tr("Help")); helpMenu->addAction(aboutAction); } @@ -214,40 +208,33 @@ void MainWindow::set1x() { display->setResolution(1); display->repaint(); - setFixedSize (64, 32 + menuBar()->height()); + setFixedSize (128, 64 + menuBar()->height()); } void MainWindow::set2x() { display->setResolution(2); display->repaint(); - setFixedSize (128, 64 + menuBar()->height()); + setFixedSize (256, 128 + menuBar()->height()); } void MainWindow::set4x() { display->setResolution(4); display->repaint(); - setFixedSize (256, 128 + menuBar()->height()); + setFixedSize (512, 256 + menuBar()->height()); } void MainWindow::set8x() { display->setResolution(8); display->repaint(); - setFixedSize (512, 256 + menuBar()->height()); -} - -void MainWindow::set16x() -{ - display->setResolution(16); - display->repaint(); setFixedSize (1024, 512 + menuBar()->height()); } void MainWindow::about() { - QMessageBox::about(this, tr("About"), "

emuChip v"+QCoreApplication::applicationVersion()+"

"+tr("

emuChip is cross-platform CHIP-8 emulator.

Homepage: http://emuchip.googlecode.com.

Copyright © 2009-2012 Boris Timofeev (mashin87@gmail.com).

")); + QMessageBox::about(this, tr("About"), "

emuChip v"+QCoreApplication::applicationVersion()+"

"+tr("

emuChip is cross-platform CHIP-8 emulator.

Homepage: http://code.google.com/p/emuchip/.

Copyright © 2009-2012 Boris Timofeev (mashin87@gmail.com).

")); } void MainWindow::writeSettings() @@ -271,7 +258,6 @@ void MainWindow::readSettings() case 2: set2xAction->setChecked(true); set2x(); break; case 4: set4xAction->setChecked(true); set4x(); break; case 8: set8xAction->setChecked(true); set8x(); break; - case 16: set16xAction->setChecked(true); set16x(); break; } lastDir = settings.value("lastDir", ".").toString(); diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index c943e14..1904b61 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -40,7 +40,6 @@ private slots: void set2x(); void set4x(); void set8x(); - void set16x(); void bgColorDialog(); void fgColorDialog(); void about(); @@ -74,7 +73,6 @@ private slots: QAction *set2xAction; QAction *set4xAction; QAction *set8xAction; - QAction *set16xAction; QAction *bgColorDialogAction; QAction *fgColorDialogAction; QAction *aboutAction;