diff --git a/qtBuildSystem/Mu/emuwrapper.cpp b/qtBuildSystem/Mu/emuwrapper.cpp index 30b7efd..42d7763 100644 --- a/qtBuildSystem/Mu/emuwrapper.cpp +++ b/qtBuildSystem/Mu/emuwrapper.cpp @@ -69,7 +69,6 @@ EmuWrapper::EmuWrapper(){ emuVideoWidth = 0; emuVideoHeight = 0; emuNewFrameReady = false; - emuDoubleBufferVideo = nullptr; frontendDebugString = new char[200]; frontendDebugStringSize = 200; @@ -89,11 +88,9 @@ void EmuWrapper::emuThreadRun(){ while(!emuThreadJoin){ if(emuRunning){ emuPaused = false; - palmInput = emuInput; - emulateFrame(); if(!emuNewFrameReady){ - memcpy(emuDoubleBufferVideo, emuVideoWidth == 320 ? palmExtendedFramebuffer : palmFramebuffer, emuVideoWidth * emuVideoHeight * sizeof(uint16_t)); - memcpy(emuDoubleBufferAudio, palmAudio, AUDIO_SAMPLES_PER_FRAME * 2/*channels*/ * sizeof(int16_t)); + palmInput = emuInput; + emulateFrame(); emuNewFrameReady = true; } } @@ -101,7 +98,7 @@ void EmuWrapper::emuThreadRun(){ emuPaused = true; } - std::this_thread::sleep_for(std::chrono::microseconds(16666)); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } @@ -206,8 +203,6 @@ uint32_t EmuWrapper::init(const QString& romPath, const QString& bootloaderPath, emuRunning = true; emuPaused = false; emuNewFrameReady = false; - emuDoubleBufferVideo = new uint16_t[emuVideoWidth * emuVideoHeight]; - emuDoubleBufferAudio = new int16_t[AUDIO_SAMPLES_PER_FRAME * 2/*channels*/]; emuThread = std::thread(&EmuWrapper::emuThreadRun, this); } else{ @@ -248,7 +243,6 @@ void EmuWrapper::exit(){ } } emulatorExit(); - delete[] emuDoubleBufferVideo; } } diff --git a/qtBuildSystem/Mu/emuwrapper.h b/qtBuildSystem/Mu/emuwrapper.h index c4ef551..2e5c67c 100644 --- a/qtBuildSystem/Mu/emuwrapper.h +++ b/qtBuildSystem/Mu/emuwrapper.h @@ -24,8 +24,6 @@ private: uint16_t emuVideoWidth; uint16_t emuVideoHeight; std::atomic emuNewFrameReady; - uint16_t* emuDoubleBufferVideo; - int16_t* emuDoubleBufferAudio; QString emuRamFilePath; QString emuSdCardFilePath; @@ -56,9 +54,11 @@ public: uint16_t screenWidth() const{return emuVideoWidth;} uint16_t screenHeight() const{return emuVideoHeight;} bool newFrameReady() const{return emuNewFrameReady;} - const QPixmap getFramebuffer(){return QPixmap::fromImage(QImage((uchar*)emuDoubleBufferVideo, emuVideoWidth, emuVideoHeight, emuVideoWidth * sizeof(uint16_t), QImage::Format_RGB16));} - const int16_t* getAudioSamples(){return emuDoubleBufferAudio;} void frameHandled(){emuNewFrameReady = false;} + + //calling these while newFrameReady() == false is undefined behavior, the other thread may be writing to them + const QPixmap getFramebuffer(){return QPixmap::fromImage(QImage((uchar*)(emuVideoWidth == 320 ? palmExtendedFramebuffer : palmFramebuffer), emuVideoWidth, emuVideoHeight, emuVideoWidth * sizeof(uint16_t), QImage::Format_RGB16));} + const int16_t* getAudioSamples() const{return palmAudio;} bool getPowerButtonLed() const{return palmMisc.powerButtonLed;} uint64_t getEmulatorMemory(uint32_t address, uint8_t size); diff --git a/qtBuildSystem/Mu/mainwindow.cpp b/qtBuildSystem/Mu/mainwindow.cpp index 87e4414..0d9437b 100644 --- a/qtBuildSystem/Mu/mainwindow.cpp +++ b/qtBuildSystem/Mu/mainwindow.cpp @@ -93,7 +93,7 @@ MainWindow::MainWindow(QWidget* parent) : #endif connect(refreshDisplay, SIGNAL(timeout()), this, SLOT(updateDisplay())); - refreshDisplay->start(16);//update display every 16.67miliseconds = 60 * second + refreshDisplay->start(1000 / EMU_FPS);//update display every X milliseconds } MainWindow::~MainWindow(){ diff --git a/src/hardwareRegisters.c b/src/hardwareRegisters.c index 94c676a..1dc3b29 100644 --- a/src/hardwareRegisters.c +++ b/src/hardwareRegisters.c @@ -1076,6 +1076,10 @@ void resetHwRegisters(){ spi1RxWritePosition = 0; spi1TxReadPosition = 0; spi1TxWritePosition = 0; + pwm1ClocksToNextSample = 0; + memset(pwm1Fifo, 0x00, sizeof(pwm1Fifo)); + pwm1ReadPosition = 0; + pwm1WritePosition = 0; memset(chips, 0x00, sizeof(chips)); //all chip selects are disabled at boot and CSA0 is mapped to 0x00000000 and covers the entire address range until CSA is set enabled