mirror of
https://github.com/libretro/Mu.git
synced 2026-09-23 07:05:37 +00:00
Fix invalid value/divide by 0, cleanups
This commit is contained in:
@@ -141,23 +141,21 @@ void MainWindow::on_install_pressed(){
|
||||
|
||||
//display
|
||||
void MainWindow::updateDisplay(){
|
||||
if(emuOn){
|
||||
if(emuMutex.try_lock()){
|
||||
if(emuOn && emuMutex.try_lock()){
|
||||
#if defined(FRONTEND_DEBUG) && defined(EMU_DEBUG)
|
||||
if(emulateUntilDebugEventOrFrameEnd()){
|
||||
//debug event occured
|
||||
emuOn = false;
|
||||
ui->ctrlBtn->setText("Resume");
|
||||
}
|
||||
if(emulateUntilDebugEventOrFrameEnd()){
|
||||
//debug event occured
|
||||
emuOn = false;
|
||||
ui->ctrlBtn->setText("Resume");
|
||||
}
|
||||
#else
|
||||
emulateFrame();
|
||||
emulateFrame();
|
||||
#endif
|
||||
|
||||
video = QImage((unsigned char*)palmFramebuffer, screenWidth, screenHeight, QImage::Format_RGB16);//16 bit
|
||||
ui->display->setPixmap(QPixmap::fromImage(video).scaled(ui->display->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
ui->display->update();
|
||||
emuMutex.unlock();
|
||||
}
|
||||
video = QImage((unsigned char*)palmFramebuffer, screenWidth, screenHeight, QImage::Format_RGB16);//16 bit
|
||||
ui->display->setPixmap(QPixmap::fromImage(video).scaled(ui->display->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
ui->display->update();
|
||||
emuMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,10 +106,9 @@ static void recalculateCpuSpeed(){
|
||||
}
|
||||
|
||||
static inline void pllWakeCpuIfOff(){
|
||||
uint16_t pllcr = registerArrayRead16(PLLCR);
|
||||
if(!pllIsOn() && pllWakeWait == -1){
|
||||
//PLL is off and not already in the process of waking up
|
||||
switch(pllcr & 0x0003){
|
||||
switch(registerArrayRead16(PLLCR) & 0x0003){
|
||||
|
||||
case 0x0000:
|
||||
pllWakeWait = 32;
|
||||
|
||||
@@ -184,31 +184,67 @@ static inline void setIlcr(uint16_t value){
|
||||
uint16_t oldIlcr = registerArrayRead16(ILCR);
|
||||
uint16_t newIlcr = 0;
|
||||
|
||||
//SPI1
|
||||
//SPI1, interrupt level 0 an 7 are invalid values that cause the register not to update
|
||||
if((value & 0x7000) != 0x0000 && (value & 0x7000) != 0x7000)
|
||||
newIlcr |= value & 0x7000;
|
||||
else
|
||||
newIlcr |= oldIlcr & 0x7000;
|
||||
|
||||
//UART2
|
||||
//UART2, interrupt level 0 an 7 are invalid values that cause the register not to update
|
||||
if((value & 0x0700) != 0x0000 && (value & 0x0700) != 0x0700)
|
||||
newIlcr |= value & 0x0700;
|
||||
else
|
||||
newIlcr |= oldIlcr & 0x0700;
|
||||
|
||||
//PWM2
|
||||
//PWM2, interrupt level 0 an 7 are invalid values that cause the register not to update
|
||||
if((value & 0x0070) != 0x0000 && (value & 0x0070) != 0x0070)
|
||||
newIlcr |= value & 0x0070;
|
||||
else
|
||||
newIlcr |= oldIlcr & 0x0070;
|
||||
|
||||
//TMR2
|
||||
//TMR2, interrupt level 0 an 7 are invalid values that cause the register not to update
|
||||
if((value & 0x0007) != 0x0000 && (value & 0x0007) != 0x0007)
|
||||
newIlcr |= value & 0x0007;
|
||||
else
|
||||
newIlcr |= oldIlcr & 0x0007;
|
||||
}
|
||||
|
||||
/*
|
||||
static inline void setSpiData2(uint16_t value){
|
||||
//some sort of commands are sent from this register, most likly touchscreen
|
||||
|
||||
}
|
||||
|
||||
static inline void setSpiCont2(uint16_t value){
|
||||
//unsure if ENABLE can be set at the exact moment of write or must be set before write, currently allow both
|
||||
//important bits are ENABLE, XCH, IRQ, IRQEN and BITCOUNT
|
||||
//uint16_t oldSpiCont2 = registerArrayRead16(SPICONT2);
|
||||
|
||||
if(value & 0x0200 && value & 0x0200){
|
||||
//enabled and exchange set
|
||||
uint8_t bitCount = (value & 0x000F) + 1;
|
||||
uint16_t spi2Data = registerArrayRead16(SPIDATA2);
|
||||
uint16_t swap;
|
||||
|
||||
swap = spi2ExternalData << (16 - bitCount);
|
||||
spi2ExternalData >>= bitCount;
|
||||
spi2ExternalData |= spi2Data << (16 - bitCount);
|
||||
spi2Data |= swap;
|
||||
spi2ExchangedBits += bitCount;
|
||||
registerArrayWrite16(SPIDATA2, spi2Data);
|
||||
|
||||
//IRQEN set, send an interrupt after transfer
|
||||
if(value & 0x0040)
|
||||
setIprIsrBit(INT_SPI2);
|
||||
|
||||
//acknowledge transfer finished, transfers are instant since timing is not emulated
|
||||
value |= 0x0080;
|
||||
}
|
||||
|
||||
registerArrayWrite16(SPICONT2, value & 0xE3FF);
|
||||
}
|
||||
*/
|
||||
|
||||
//register getters
|
||||
static inline uint8_t getPortDValue(){
|
||||
uint8_t requestedRow = registerArrayRead8(PKDIR) & registerArrayRead8(PKDATA);//keys are requested on port k and read on port d
|
||||
|
||||
@@ -16,11 +16,9 @@ static inline double dmaclksPerClk32(){
|
||||
}
|
||||
|
||||
static inline double sysclksPerClk32(){
|
||||
uint16_t pllcr = registerArrayRead16(PLLCR);
|
||||
double sysclks = dmaclksPerClk32();
|
||||
uint16_t sysclkSelect = (pllcr >> 8) & 0x0003;
|
||||
double sysclks = dmaclksPerClk32();
|
||||
|
||||
switch(sysclkSelect){
|
||||
switch(registerArrayRead16(PLLCR) >> 8 & 0x0003){
|
||||
|
||||
case 0x0000:
|
||||
sysclks /= 2.0;
|
||||
@@ -93,16 +91,16 @@ static inline void rtiInterruptClk32(){
|
||||
static inline void timer12Clk32(){
|
||||
//this function is part of clk32();
|
||||
uint16_t timer1Control = registerArrayRead16(TCTL1);
|
||||
uint16_t timer1Prescaler = registerArrayRead16(TPRER1) & 0x00FF;
|
||||
uint16_t timer1Compare = registerArrayRead16(TCMP1);
|
||||
uint16_t timer1OldCount = registerArrayRead16(TCN1);
|
||||
uint16_t timer1Count = timer1OldCount;
|
||||
double timer1Prescaler = (registerArrayRead16(TPRER1) & 0x00FF) + 1;
|
||||
|
||||
uint16_t timer2Control = registerArrayRead16(TCTL2);
|
||||
uint16_t timer2Prescaler = registerArrayRead16(TPRER2) & 0x00FF;
|
||||
uint16_t timer2Compare = registerArrayRead16(TCMP2);
|
||||
uint16_t timer2OldCount = registerArrayRead16(TCN2);
|
||||
uint16_t timer2Count = timer2OldCount;
|
||||
double timer2Prescaler = (registerArrayRead16(TPRER2) & 0x00FF) + 1;
|
||||
|
||||
//timer 1
|
||||
if(timer1Control & 0x0001){
|
||||
@@ -116,16 +114,16 @@ static inline void timer12Clk32(){
|
||||
|
||||
case 0x0001://SYSCLK / timer prescaler
|
||||
if(pllIsOn())
|
||||
timer1CycleCounter += sysclksPerClk32() / (double)timer1Prescaler;
|
||||
timer1CycleCounter += sysclksPerClk32() / timer1Prescaler;
|
||||
break;
|
||||
|
||||
case 0x0002://SYSCLK / 16 / timer prescaler
|
||||
if(pllIsOn())
|
||||
timer1CycleCounter += sysclksPerClk32() / 16.0 / (double)timer1Prescaler;
|
||||
timer1CycleCounter += sysclksPerClk32() / 16.0 / timer1Prescaler;
|
||||
break;
|
||||
|
||||
default://CLK32 / timer prescaler
|
||||
timer1CycleCounter += 1.0 / (double)timer1Prescaler;
|
||||
timer1CycleCounter += 1.0 / timer1Prescaler;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -162,16 +160,16 @@ static inline void timer12Clk32(){
|
||||
|
||||
case 0x0001://SYSCLK / timer prescaler
|
||||
if(pllIsOn())
|
||||
timer2CycleCounter += sysclksPerClk32() / (double)timer2Prescaler;
|
||||
timer2CycleCounter += sysclksPerClk32() / timer2Prescaler;
|
||||
break;
|
||||
|
||||
case 0x0002://SYSCLK / 16 / timer prescaler
|
||||
if(pllIsOn())
|
||||
timer2CycleCounter += sysclksPerClk32() / 16.0 / (double)timer2Prescaler;
|
||||
timer2CycleCounter += sysclksPerClk32() / 16.0 / timer2Prescaler;
|
||||
break;
|
||||
|
||||
default://CLK32 / timer prescaler
|
||||
timer2CycleCounter += 1.0 / (double)timer2Prescaler;
|
||||
timer2CycleCounter += 1.0 / timer2Prescaler;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user