Reset the PWM1 variables on boot

Also use newFrameReady() instead of double buffering for threads, less useless copying.
This commit is contained in:
meepingsnesroms
2018-10-19 11:48:19 -07:00
parent 4ce4beef6d
commit a769afe99b
4 changed files with 12 additions and 14 deletions

View File

@@ -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;
}
}

View File

@@ -24,8 +24,6 @@ private:
uint16_t emuVideoWidth;
uint16_t emuVideoHeight;
std::atomic<bool> 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);

View File

@@ -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(){

View File

@@ -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