2017-07-02 20:55:56 +01:00
|
|
|
#include "qapple.h"
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "Common.h"
|
|
|
|
#include "Applewin.h"
|
|
|
|
#include "Disk.h"
|
|
|
|
#include "Harddisk.h"
|
|
|
|
#include "Log.h"
|
|
|
|
#include "CPU.h"
|
|
|
|
#include "Frame.h"
|
|
|
|
#include "Memory.h"
|
|
|
|
#include "ParallelPrinter.h"
|
|
|
|
#include "Video.h"
|
|
|
|
#include "SaveState.h"
|
|
|
|
|
|
|
|
#include "linux/data.h"
|
2017-07-07 21:04:21 +01:00
|
|
|
#include "linux/benchmark.h"
|
2017-07-02 20:55:56 +01:00
|
|
|
|
2017-07-03 21:00:42 +01:00
|
|
|
#include "emulator.h"
|
2017-07-15 15:46:18 +01:00
|
|
|
#include "memorycontainer.h"
|
2017-11-21 16:10:58 +00:00
|
|
|
#include "configuration.h"
|
2017-07-03 21:00:42 +01:00
|
|
|
|
2017-07-04 14:05:06 +01:00
|
|
|
#include <QMdiSubWindow>
|
2017-07-07 21:13:17 +01:00
|
|
|
#include <QMessageBox>
|
2017-10-15 18:20:25 +01:00
|
|
|
#include <QFileDialog>
|
2017-07-04 14:05:06 +01:00
|
|
|
|
2017-07-02 20:55:56 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
void initialiseEmulator()
|
|
|
|
{
|
|
|
|
g_fh = fopen("/tmp/applewin.txt", "w");
|
|
|
|
setbuf(g_fh, NULL);
|
|
|
|
|
|
|
|
LogFileOutput("Initialisation\n");
|
|
|
|
|
|
|
|
ImageInitialize();
|
|
|
|
DiskInitialize();
|
|
|
|
}
|
|
|
|
|
2017-09-26 18:03:02 +01:00
|
|
|
void startEmulator(QWidget * window)
|
2017-07-02 20:55:56 +01:00
|
|
|
{
|
|
|
|
LoadConfiguration();
|
|
|
|
|
|
|
|
CheckCpu();
|
|
|
|
|
2017-07-04 14:05:06 +01:00
|
|
|
SetWindowTitle();
|
2017-09-26 18:03:02 +01:00
|
|
|
window->setWindowTitle(g_pAppTitle);
|
2017-07-04 14:05:06 +01:00
|
|
|
|
2017-07-02 20:55:56 +01:00
|
|
|
FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES);
|
|
|
|
|
|
|
|
MemInitialize();
|
|
|
|
VideoInitialize();
|
|
|
|
}
|
|
|
|
|
2017-07-15 15:46:18 +01:00
|
|
|
void stopEmulator()
|
|
|
|
{
|
|
|
|
MemDestroy();
|
|
|
|
}
|
|
|
|
|
2017-07-02 20:55:56 +01:00
|
|
|
void uninitialiseEmulator()
|
|
|
|
{
|
|
|
|
HD_Destroy();
|
|
|
|
PrintDestroy();
|
|
|
|
CpuDestroy();
|
|
|
|
MemDestroy();
|
|
|
|
|
|
|
|
DiskDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-04 12:14:04 +01:00
|
|
|
void FrameDrawDiskLEDS(HDC)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameDrawDiskStatus(HDC)
|
|
|
|
{
|
2017-07-02 20:55:56 +01:00
|
|
|
|
2017-07-04 12:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameRefreshStatus(int, bool)
|
|
|
|
{
|
2017-07-02 20:55:56 +01:00
|
|
|
|
2017-07-04 12:14:04 +01:00
|
|
|
}
|
2017-07-02 20:55:56 +01:00
|
|
|
|
|
|
|
// Speaker
|
|
|
|
|
2017-07-04 12:14:04 +01:00
|
|
|
BYTE __stdcall SpkrToggle (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft)
|
|
|
|
{
|
|
|
|
Q_UNUSED(pc)
|
|
|
|
Q_UNUSED(addr)
|
|
|
|
Q_UNUSED(bWrite)
|
|
|
|
Q_UNUSED(d)
|
|
|
|
Q_UNUSED(nCyclesLeft)
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-02 20:55:56 +01:00
|
|
|
|
|
|
|
void VideoInitialize() {}
|
|
|
|
|
2017-10-15 18:58:23 +01:00
|
|
|
// MessageBox
|
|
|
|
|
|
|
|
int MessageBox(HWND, const char * text, const char * caption, UINT type)
|
|
|
|
{
|
|
|
|
QMessageBox::StandardButtons buttons = QMessageBox::Ok;
|
|
|
|
if (type & MB_YESNO)
|
|
|
|
{
|
|
|
|
buttons = QMessageBox::Yes | QMessageBox::No;
|
|
|
|
}
|
|
|
|
else if (type & MB_YESNOCANCEL)
|
|
|
|
{
|
|
|
|
buttons = QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMessageBox::StandardButton result = QMessageBox::information(nullptr, caption, text, buttons);
|
|
|
|
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case QMessageBox::Ok:
|
|
|
|
return IDOK;
|
|
|
|
case QMessageBox::Yes:
|
|
|
|
return IDYES;
|
|
|
|
case QMessageBox::No:
|
|
|
|
return IDNO;
|
|
|
|
case QMessageBox::Cancel:
|
|
|
|
return IDCANCEL;
|
|
|
|
default:
|
|
|
|
return IDOK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-02 20:55:56 +01:00
|
|
|
QApple::QApple(QWidget *parent) :
|
2017-09-21 20:31:52 +01:00
|
|
|
QMainWindow(parent), myTimerID(0), myPreferences(this)
|
2017-07-02 20:55:56 +01:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2017-10-14 20:42:23 +01:00
|
|
|
actionStart->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
|
|
|
|
actionPause->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
|
2017-10-15 18:20:25 +01:00
|
|
|
actionReboot->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward));
|
|
|
|
|
|
|
|
actionSave_state->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
|
|
|
|
actionLoad_state->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
|
2017-10-14 20:42:23 +01:00
|
|
|
|
2017-07-03 21:00:42 +01:00
|
|
|
myEmulator = new Emulator(mdiArea);
|
2017-07-04 12:14:04 +01:00
|
|
|
myEmulatorWindow = mdiArea->addSubWindow(myEmulator, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
|
2017-07-02 20:55:56 +01:00
|
|
|
|
2017-07-09 16:49:11 +01:00
|
|
|
myMSGap = 5;
|
2017-07-02 20:55:56 +01:00
|
|
|
|
2017-10-14 20:42:23 +01:00
|
|
|
on_actionPause_triggered();
|
2017-07-02 20:55:56 +01:00
|
|
|
initialiseEmulator();
|
2017-09-26 18:03:02 +01:00
|
|
|
startEmulator(myEmulatorWindow);
|
2017-07-04 14:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QApple::closeEvent(QCloseEvent *)
|
|
|
|
{
|
2017-07-07 21:04:21 +01:00
|
|
|
stopTimer();
|
2017-07-04 14:05:06 +01:00
|
|
|
uninitialiseEmulator();
|
2017-07-02 20:55:56 +01:00
|
|
|
}
|
|
|
|
|
2017-07-09 16:49:11 +01:00
|
|
|
void QApple::on_timer()
|
2017-07-02 20:55:56 +01:00
|
|
|
{
|
2017-07-09 16:49:11 +01:00
|
|
|
const qint64 elapsed = myElapsedTimer.restart();
|
2017-07-02 20:55:56 +01:00
|
|
|
const double fUsecPerSec = 1.e6;
|
2017-07-09 16:49:11 +01:00
|
|
|
const UINT nExecutionPeriodUsec = 1000 * elapsed;
|
2017-07-02 20:55:56 +01:00
|
|
|
|
|
|
|
const double fExecutionPeriodClks = g_fCurrentCLK6502 * ((double)nExecutionPeriodUsec / fUsecPerSec);
|
|
|
|
const DWORD uCyclesToExecute = fExecutionPeriodClks;
|
|
|
|
|
|
|
|
const bool bVideoUpdate = false;
|
|
|
|
|
2017-07-09 16:49:11 +01:00
|
|
|
do
|
2017-07-02 20:55:56 +01:00
|
|
|
{
|
2017-07-09 16:49:11 +01:00
|
|
|
const DWORD uActualCyclesExecuted = CpuExecute(uCyclesToExecute, bVideoUpdate);
|
|
|
|
g_dwCyclesThisFrame += uActualCyclesExecuted;
|
|
|
|
if (g_dwCyclesThisFrame >= dwClksPerFrame)
|
|
|
|
{
|
|
|
|
g_dwCyclesThisFrame -= dwClksPerFrame;
|
2017-10-15 21:08:08 +01:00
|
|
|
myEmulator->updateVideo();
|
2017-07-09 16:49:11 +01:00
|
|
|
}
|
2017-07-02 20:55:56 +01:00
|
|
|
}
|
2017-07-09 16:49:11 +01:00
|
|
|
while (DiskIsSpinning());
|
2017-07-04 14:05:06 +01:00
|
|
|
}
|
|
|
|
|
2017-07-07 21:04:21 +01:00
|
|
|
void QApple::stopTimer()
|
|
|
|
{
|
|
|
|
if (myTimerID)
|
|
|
|
{
|
|
|
|
killTimer(myTimerID);
|
|
|
|
myTimerID = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-02 20:55:56 +01:00
|
|
|
void QApple::on_actionStart_triggered()
|
|
|
|
{
|
2017-07-04 14:05:06 +01:00
|
|
|
// always restart with the same timer gap that was last used
|
2017-07-09 16:49:11 +01:00
|
|
|
myTimerID = startTimer(myMSGap, Qt::PreciseTimer);
|
|
|
|
myElapsedTimer.start();
|
2017-07-02 20:55:56 +01:00
|
|
|
actionPause->setEnabled(true);
|
|
|
|
actionStart->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QApple::on_actionPause_triggered()
|
|
|
|
{
|
2017-07-07 21:04:21 +01:00
|
|
|
stopTimer();
|
2017-07-02 20:55:56 +01:00
|
|
|
actionPause->setEnabled(false);
|
|
|
|
actionStart->setEnabled(true);
|
|
|
|
}
|
2017-07-04 12:14:04 +01:00
|
|
|
|
|
|
|
void QApple::on_actionX1_triggered()
|
|
|
|
{
|
|
|
|
myEmulator->setZoom(myEmulatorWindow, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QApple::on_actionX2_triggered()
|
|
|
|
{
|
|
|
|
myEmulator->setZoom(myEmulatorWindow, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QApple::on_action4_3_triggered()
|
|
|
|
{
|
|
|
|
myEmulator->set43AspectRatio(myEmulatorWindow);
|
|
|
|
}
|
2017-07-04 19:25:10 +01:00
|
|
|
|
2017-07-04 21:17:40 +01:00
|
|
|
void QApple::on_actionReboot_triggered()
|
|
|
|
{
|
2017-07-15 15:46:18 +01:00
|
|
|
emit endEmulator();
|
|
|
|
stopEmulator();
|
2017-09-26 18:03:02 +01:00
|
|
|
startEmulator(myEmulatorWindow);
|
|
|
|
myEmulatorWindow->setWindowTitle(g_pAppTitle);
|
2017-07-04 21:17:40 +01:00
|
|
|
}
|
2017-07-07 21:04:21 +01:00
|
|
|
|
|
|
|
void QApple::on_actionBenchmark_triggered()
|
|
|
|
{
|
2017-10-15 21:08:08 +01:00
|
|
|
// call repaint as we really want to for a paintEvent() so we can time it properly
|
|
|
|
// if video is based on OpenGLWidget, this is not enough though,
|
|
|
|
// and benchmark results are bad.
|
|
|
|
VideoBenchmark([this]() { myEmulator->repaintVideo(); });
|
2017-07-07 21:04:21 +01:00
|
|
|
on_actionReboot_triggered();
|
|
|
|
}
|
2017-07-09 16:49:11 +01:00
|
|
|
|
|
|
|
void QApple::timerEvent(QTimerEvent *)
|
|
|
|
{
|
|
|
|
on_timer();
|
|
|
|
}
|
2017-07-15 15:46:18 +01:00
|
|
|
|
|
|
|
void QApple::on_actionMemory_triggered()
|
|
|
|
{
|
|
|
|
MemoryContainer * container = new MemoryContainer(mdiArea);
|
|
|
|
QMdiSubWindow * window = mdiArea->addSubWindow(container);
|
|
|
|
|
|
|
|
// need to close as it points to old memory
|
|
|
|
connect(this, SIGNAL(endEmulator()), window, SLOT(close()));
|
|
|
|
|
|
|
|
window->setWindowTitle("Memory viewer");
|
|
|
|
window->show();
|
|
|
|
}
|
2017-09-19 20:47:15 +01:00
|
|
|
|
|
|
|
void QApple::on_actionOptions_triggered()
|
|
|
|
{
|
2017-11-21 16:10:58 +00:00
|
|
|
const Preferences::Data currentOptions = getCurrentOptions(myGamepad);
|
2017-10-15 18:20:25 +01:00
|
|
|
|
2017-10-10 14:26:40 +01:00
|
|
|
QSettings settings; // the function will "modify" it
|
|
|
|
myPreferences.setup(currentOptions, settings);
|
2017-09-19 20:47:15 +01:00
|
|
|
|
2017-09-21 20:31:52 +01:00
|
|
|
if (myPreferences.exec())
|
2017-09-19 20:47:15 +01:00
|
|
|
{
|
2017-09-21 20:31:52 +01:00
|
|
|
const Preferences::Data newOptions = myPreferences.getData();
|
2017-11-21 16:10:58 +00:00
|
|
|
setNewOptions(currentOptions, newOptions, myGamepad);
|
2017-09-19 20:47:15 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-15 18:20:25 +01:00
|
|
|
|
|
|
|
void QApple::on_actionSave_state_triggered()
|
|
|
|
{
|
|
|
|
Snapshot_SaveState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QApple::on_actionLoad_state_triggered()
|
|
|
|
{
|
|
|
|
emit endEmulator();
|
|
|
|
Snapshot_LoadState();
|
|
|
|
myEmulatorWindow->setWindowTitle(g_pAppTitle);
|
2017-10-15 21:08:08 +01:00
|
|
|
myEmulator->updateVideo();
|
2017-10-15 18:20:25 +01:00
|
|
|
}
|
2017-10-15 18:58:40 +01:00
|
|
|
|
|
|
|
void QApple::on_actionAbout_Qt_triggered()
|
|
|
|
{
|
|
|
|
QMessageBox::aboutQt(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QApple::on_actionAbout_triggered()
|
|
|
|
{
|
|
|
|
QMessageBox::about(this, QApplication::applicationName(), "Apple ][ emulator\n\nBased on AppleWin\n");
|
|
|
|
}
|
2017-10-17 21:14:36 +01:00
|
|
|
|
|
|
|
QString getImageFilename()
|
|
|
|
{
|
|
|
|
QString filenameTemplate = getScreenshotTemplate();
|
|
|
|
static size_t counter = 0;
|
|
|
|
|
|
|
|
const size_t maximum = 10000;
|
|
|
|
while (counter < maximum)
|
|
|
|
{
|
|
|
|
const QString filename = filenameTemplate.arg(counter, 5, 10, QChar('0'));
|
|
|
|
if (!QFile(filename).exists())
|
|
|
|
{
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
++counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QApple::on_actionScreenshot_triggered()
|
|
|
|
{
|
|
|
|
const QString filename = getImageFilename();
|
|
|
|
if (filename.isEmpty())
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, "Screenshot", "Cannot determine the screenshot filename.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const bool ok = myEmulator->getScreen().save(filename);
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
const QString message = QString::fromUtf8("Cannot save screenshot to %1").arg(filename);
|
|
|
|
QMessageBox::warning(this, "Screenshot", message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|