Skip to content

Commit

Permalink
qt version: add super chip support
Browse files Browse the repository at this point in the history
  • Loading branch information
btimofeev committed Apr 9, 2012
1 parent 839f7dc commit d258996
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 57 deletions.
38 changes: 21 additions & 17 deletions src/qt/displaywidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* emuChip - CHIP-8 emulator.
* Copyright (C) 2009 Boris Timofeev <[email protected]>
* Copyright (C) 2009-2012 Boris Timofeev <[email protected]> <http://www.emunix.org>
*
* 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
Expand All @@ -25,35 +25,39 @@ 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 *)
{
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);
}
}
}
7 changes: 4 additions & 3 deletions src/qt/displaywidget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* emuChip - CHIP-8 emulator.
* Copyright (C) 2009 Boris Timofeev <[email protected]>
* Copyright (C) 2009-2012 Boris Timofeev <[email protected]> <http://www.emunix.org>
*
* 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
Expand All @@ -27,6 +27,7 @@ class DisplayWidget : public QWidget

public:
DisplayWidget();
~DisplayWidget();

void setResolution(int r) { resolution = r; }
int getResolution() { return resolution; }
Expand All @@ -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:
Expand All @@ -47,7 +48,7 @@ class DisplayWidget : public QWidget
QColor bgColor;
QColor fgColor;

unsigned char screen[64*32];
unsigned char screen[128][64];
};

#endif
56 changes: 21 additions & 35 deletions src/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void MainWindow::emulation()
QElapsedTimer et;
et.start();

while (emuStart)
while (emuStart == true)
{
QCoreApplication::processEvents ( QEventLoop::AllEvents );

Expand All @@ -81,6 +81,7 @@ void MainWindow::emulation()

opcode_count = 0;
}
if (emu->stop) closeRom();
}
}

Expand Down Expand Up @@ -134,120 +135,106 @@ 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);
}

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"), "<center><h3>emuChip v"+QCoreApplication::applicationVersion()+"</h3></center>"+tr("<center><p>emuChip is cross-platform CHIP-8 emulator.</p><b>Homepage: </b> <a href=\"http://emuchip.googlecode.com\">http://emuchip.googlecode.com</a>.<small><p>Copyright &copy; 2009-2012 Boris Timofeev (<a href=\"mailto:[email protected]\">[email protected]</a>).</p></small></center>"));
QMessageBox::about(this, tr("About"), "<center><h3>emuChip v"+QCoreApplication::applicationVersion()+"</h3></center>"+tr("<center><p>emuChip is cross-platform CHIP-8 emulator.</p><b>Homepage: </b> <a href=\"http://code.google.com/p/emuchip\">http://code.google.com/p/emuchip/</a>.<small><p>Copyright &copy; 2009-2012 Boris Timofeev (<a href=\"mailto:[email protected]\">[email protected]</a>).</p></small></center>"));
}

void MainWindow::writeSettings()
Expand All @@ -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();

Expand Down
2 changes: 0 additions & 2 deletions src/qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ private slots:
void set2x();
void set4x();
void set8x();
void set16x();
void bgColorDialog();
void fgColorDialog();
void about();
Expand Down Expand Up @@ -74,7 +73,6 @@ private slots:
QAction *set2xAction;
QAction *set4xAction;
QAction *set8xAction;
QAction *set16xAction;
QAction *bgColorDialogAction;
QAction *fgColorDialogAction;
QAction *aboutAction;
Expand Down

0 comments on commit d258996

Please sign in to comment.