From 64e0dae30fa8273a0d2ef658be6040a5dd6b6fb2 Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 11:52:24 +1100 Subject: [PATCH 1/9] [Project64] Change Dma.cpp to use standard types --- Source/Project64/N64 System/Mips/Dma.cpp | 620 +++++++++++------------ Source/Project64/N64 System/Mips/Dma.h | 31 +- 2 files changed, 326 insertions(+), 325 deletions(-) diff --git a/Source/Project64/N64 System/Mips/Dma.cpp b/Source/Project64/N64 System/Mips/Dma.cpp index 092e8e458..332adf42f 100644 --- a/Source/Project64/N64 System/Mips/Dma.cpp +++ b/Source/Project64/N64 System/Mips/Dma.cpp @@ -11,355 +11,353 @@ #include "stdafx.h" CDMA::CDMA(CFlashram & FlashRam, CSram & Sram) : - m_FlashRam(FlashRam), - m_Sram(Sram) +m_FlashRam(FlashRam), +m_Sram(Sram) { - } void CDMA::OnFirstDMA() { - switch (g_Rom->CicChipID()) - { - case CIC_NUS_6101: *(DWORD *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; - case CIC_NUS_5167: *(DWORD *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; - case CIC_UNKNOWN: - case CIC_NUS_6102: *(DWORD *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; - case CIC_NUS_6103: *(DWORD *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; - case CIC_NUS_6105: *(DWORD *)&((g_MMU->Rdram())[0x3F0]) = g_MMU->RdramSize(); break; - case CIC_NUS_6106: *(DWORD *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; - default: g_Notify->DisplayError(stdstr_f("Unhandled CicChip(%d) in first DMA",g_Rom->CicChipID()).ToUTF16().c_str()); - } + switch (g_Rom->CicChipID()) + { + case CIC_NUS_6101: *(uint32_t *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; + case CIC_NUS_5167: *(uint32_t *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; + case CIC_UNKNOWN: + case CIC_NUS_6102: *(uint32_t *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; + case CIC_NUS_6103: *(uint32_t *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; + case CIC_NUS_6105: *(uint32_t *)&((g_MMU->Rdram())[0x3F0]) = g_MMU->RdramSize(); break; + case CIC_NUS_6106: *(uint32_t *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; + default: g_Notify->DisplayError(stdstr_f("Unhandled CicChip(%d) in first DMA", g_Rom->CicChipID()).ToUTF16().c_str()); + } } void CDMA::PI_DMA_READ() { -// PI_STATUS_REG |= PI_STATUS_DMA_BUSY; - DWORD PI_RD_LEN_REG = ((g_Reg->PI_RD_LEN_REG) & 0x00FFFFFFul) + 1; + // PI_STATUS_REG |= PI_STATUS_DMA_BUSY; + uint32_t PI_RD_LEN_REG = ((g_Reg->PI_RD_LEN_REG) & 0x00FFFFFFul) + 1; - if ((PI_RD_LEN_REG & 1) != 0) - { - PI_RD_LEN_REG += 1; - } - - if ( g_Reg->PI_DRAM_ADDR_REG + PI_RD_LEN_REG > g_MMU->RdramSize()) - { - if (bHaveDebugger()) - { - g_Notify->DisplayError(stdstr_f("PI_DMA_READ not in Memory: %08X", g_Reg->PI_DRAM_ADDR_REG + PI_RD_LEN_REG).ToUTF16().c_str()); - } - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } + if ((PI_RD_LEN_REG & 1) != 0) + { + PI_RD_LEN_REG += 1; + } - //Write ROM Area (for 64DD Convert) - if (g_Reg->PI_CART_ADDR_REG >= 0x10000000 && g_Reg->PI_CART_ADDR_REG <= 0x1FBFFFFF && g_Settings->LoadBool(Game_AllowROMWrites)) - { - DWORD i; - BYTE * ROM = g_Rom->GetRomAddress(); - BYTE * RDRAM = g_MMU->Rdram(); + if (g_Reg->PI_DRAM_ADDR_REG + PI_RD_LEN_REG > g_MMU->RdramSize()) + { + if (bHaveDebugger()) + { + g_Notify->DisplayError(stdstr_f("PI_DMA_READ not in Memory: %08X", g_Reg->PI_DRAM_ADDR_REG + PI_RD_LEN_REG).ToUTF16().c_str()); + } + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + return; + } - DWORD OldProtect; - VirtualProtect(ROM, g_Rom->GetRomSize(), PAGE_READWRITE, &OldProtect); + //Write ROM Area (for 64DD Convert) + if (g_Reg->PI_CART_ADDR_REG >= 0x10000000 && g_Reg->PI_CART_ADDR_REG <= 0x1FBFFFFF && g_Settings->LoadBool(Game_AllowROMWrites)) + { + uint32_t i; + uint8_t * ROM = g_Rom->GetRomAddress(); + uint8_t * RDRAM = g_MMU->Rdram(); - g_Reg->PI_CART_ADDR_REG -= 0x10000000; - if (g_Reg->PI_CART_ADDR_REG + PI_RD_LEN_REG < g_Rom->GetRomSize()) - { - for (i = 0; i < PI_RD_LEN_REG; i++) - { - *(ROM + ((g_Reg->PI_CART_ADDR_REG + i) ^ 3)) = *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)); - } - } - else - { - DWORD Len; - Len = g_Rom->GetRomSize() - g_Reg->PI_CART_ADDR_REG; - for (i = 0; i < Len; i++) - { - *(ROM + ((g_Reg->PI_CART_ADDR_REG + i) ^ 3)) = *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)); - } - } - g_Reg->PI_CART_ADDR_REG += 0x10000000; + DWORD OldProtect; + VirtualProtect(ROM, g_Rom->GetRomSize(), PAGE_READWRITE, &OldProtect); - if (!g_System->DmaUsed()) - { - g_System->SetDmaUsed(true); - OnFirstDMA(); - } - if (g_Recompiler && g_System->bSMM_PIDMA()) - { - g_Recompiler->ClearRecompCode_Phys(g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_WR_LEN_REG, CRecompiler::Remove_DMA); - } + g_Reg->PI_CART_ADDR_REG -= 0x10000000; + if (g_Reg->PI_CART_ADDR_REG + PI_RD_LEN_REG < g_Rom->GetRomSize()) + { + for (i = 0; i < PI_RD_LEN_REG; i++) + { + *(ROM + ((g_Reg->PI_CART_ADDR_REG + i) ^ 3)) = *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)); + } + } + else + { + uint32_t Len; + Len = g_Rom->GetRomSize() - g_Reg->PI_CART_ADDR_REG; + for (i = 0; i < Len; i++) + { + *(ROM + ((g_Reg->PI_CART_ADDR_REG + i) ^ 3)) = *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)); + } + } + g_Reg->PI_CART_ADDR_REG += 0x10000000; - VirtualProtect(ROM, g_Rom->GetRomSize(), PAGE_READONLY, &OldProtect); - - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } + if (!g_System->DmaUsed()) + { + g_System->SetDmaUsed(true); + OnFirstDMA(); + } + if (g_Recompiler && g_System->bSMM_PIDMA()) + { + g_Recompiler->ClearRecompCode_Phys(g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_WR_LEN_REG, CRecompiler::Remove_DMA); + } - if ( g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08088000) - { - if (g_System->m_SaveUsing == SaveChip_Auto) - { - g_System->m_SaveUsing = SaveChip_Sram; - } - if (g_System->m_SaveUsing == SaveChip_Sram) - { - m_Sram.DmaToSram( - g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, - g_Reg->PI_CART_ADDR_REG - 0x08000000, - PI_RD_LEN_REG - ); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } - if (g_System->m_SaveUsing == SaveChip_FlashRam) - { - m_FlashRam.DmaToFlashram( - g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG, - g_Reg->PI_CART_ADDR_REG - 0x08000000, - PI_RD_LEN_REG - ); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } - } - if (g_System->m_SaveUsing == SaveChip_FlashRam) - { - g_Notify->DisplayError(stdstr_f("**** FLashRam DMA Read address %08X *****",g_Reg->PI_CART_ADDR_REG).ToUTF16().c_str()); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } - if (bHaveDebugger()) - { - g_Notify->DisplayError(stdstr_f("PI_DMA_READ where are you dmaing to ? : %08X", g_Reg->PI_CART_ADDR_REG).ToUTF16().c_str()); - } - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; + VirtualProtect(ROM, g_Rom->GetRomSize(), PAGE_READONLY, &OldProtect); + + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + return; + } + + if (g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08010000) + { + if (g_System->m_SaveUsing == SaveChip_Auto) + { + g_System->m_SaveUsing = SaveChip_Sram; + } + if (g_System->m_SaveUsing == SaveChip_Sram) + { + m_Sram.DmaToSram( + g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, + g_Reg->PI_CART_ADDR_REG - 0x08000000, + PI_RD_LEN_REG + ); + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + return; + } + if (g_System->m_SaveUsing == SaveChip_FlashRam) + { + m_FlashRam.DmaToFlashram( + g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, + g_Reg->PI_CART_ADDR_REG - 0x08000000, + PI_RD_LEN_REG + ); + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + return; + } + } + if (g_System->m_SaveUsing == SaveChip_FlashRam) + { + g_Notify->DisplayError(stdstr_f("**** FLashRam DMA Read address %08X *****", g_Reg->PI_CART_ADDR_REG).ToUTF16().c_str()); + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + return; + } + if (bHaveDebugger()) + { + g_Notify->DisplayError(stdstr_f("PI_DMA_READ where are you dmaing to ? : %08X", g_Reg->PI_CART_ADDR_REG).ToUTF16().c_str()); + } + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + return; } void CDMA::PI_DMA_WRITE() { - DWORD PI_WR_LEN_REG = ((g_Reg->PI_WR_LEN_REG) & 0x00FFFFFFul) + 1; + uint32_t PI_WR_LEN_REG = ((g_Reg->PI_WR_LEN_REG) & 0x00FFFFFFul) + 1; - if ((PI_WR_LEN_REG & 1) != 0) - { - PI_WR_LEN_REG += 1; /* fixes AI Shougi 3, Doraemon 3, etc. */ - } + if ((PI_WR_LEN_REG & 1) != 0) + { + PI_WR_LEN_REG += 1; /* fixes AI Shougi 3, Doraemon 3, etc. */ + } - g_Reg->PI_STATUS_REG |= PI_STATUS_DMA_BUSY; - if ( g_Reg->PI_DRAM_ADDR_REG + PI_WR_LEN_REG > g_MMU->RdramSize()) - { - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(stdstr_f("PI_DMA_WRITE not in Memory: %08X", g_Reg->PI_DRAM_ADDR_REG + PI_WR_LEN_REG).ToUTF16().c_str()); } - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } + g_Reg->PI_STATUS_REG |= PI_STATUS_DMA_BUSY; + if (g_Reg->PI_DRAM_ADDR_REG + PI_WR_LEN_REG > g_MMU->RdramSize()) + { + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(stdstr_f("PI_DMA_WRITE not in Memory: %08X", g_Reg->PI_DRAM_ADDR_REG + PI_WR_LEN_REG).ToUTF16().c_str()); } + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + return; + } - if ( g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08088000) - { - if (g_System->m_SaveUsing == SaveChip_Auto) - { - g_System->m_SaveUsing = SaveChip_Sram; - } - if (g_System->m_SaveUsing == SaveChip_Sram) - { - m_Sram.DmaFromSram( - g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG, - g_Reg->PI_CART_ADDR_REG - 0x08000000, - PI_WR_LEN_REG - ); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } - if (g_System->m_SaveUsing == SaveChip_FlashRam) - { - m_FlashRam.DmaFromFlashram( - g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG, - g_Reg->PI_CART_ADDR_REG - 0x08000000, - PI_WR_LEN_REG - ); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - } - return; - } + if (g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08088000) + { + if (g_System->m_SaveUsing == SaveChip_Auto) + { + g_System->m_SaveUsing = SaveChip_Sram; + } + if (g_System->m_SaveUsing == SaveChip_Sram) + { + m_Sram.DmaFromSram( + g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, + g_Reg->PI_CART_ADDR_REG - 0x08000000, + PI_WR_LEN_REG + ); + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + return; + } + if (g_System->m_SaveUsing == SaveChip_FlashRam) + { + m_FlashRam.DmaFromFlashram( + g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, + g_Reg->PI_CART_ADDR_REG - 0x08000000, + PI_WR_LEN_REG + ); + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + } + return; + } - if ( g_Reg->PI_CART_ADDR_REG >= 0x10000000 && g_Reg->PI_CART_ADDR_REG <= 0x1FFFFFFF) - { - DWORD i; + if (g_Reg->PI_CART_ADDR_REG >= 0x10000000 && g_Reg->PI_CART_ADDR_REG <= 0x1FFFFFFF) + { + uint32_t i; #ifdef tofix #ifdef ROM_IN_MAPSPACE - if (WrittenToRom) - { - DWORD OldProtect; - VirtualProtect(ROM,m_RomFileSize,PAGE_READONLY, &OldProtect); - } + if (WrittenToRom) + { + uint32_t OldProtect; + VirtualProtect(ROM,m_RomFileSize,PAGE_READONLY, &OldProtect); + } #endif #endif - BYTE * ROM = g_Rom->GetRomAddress(); - BYTE * RDRAM = g_MMU->Rdram(); - g_Reg->PI_CART_ADDR_REG -= 0x10000000; - if (g_Reg->PI_CART_ADDR_REG + PI_WR_LEN_REG < g_Rom->GetRomSize()) - { - for (i = 0; i < PI_WR_LEN_REG; i ++) - { - *(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((g_Reg->PI_CART_ADDR_REG + i) ^ 3)); - } - } - else if (g_Reg->PI_CART_ADDR_REG >= g_Rom->GetRomSize()) - { - DWORD cart = g_Reg->PI_CART_ADDR_REG - g_Rom->GetRomSize(); - while (cart >= g_Rom->GetRomSize()) - { - cart -= g_Rom->GetRomSize(); - } - for (i = 0; i < PI_WR_LEN_REG; i++) - { - *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM + ((cart + i) ^ 3)); - } - } - else - { - DWORD Len; - Len = g_Rom->GetRomSize() - g_Reg->PI_CART_ADDR_REG; - for (i = 0; i < Len; i ++) - { - *(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((g_Reg->PI_CART_ADDR_REG + i) ^ 3)); - } - for (i = Len; i < PI_WR_LEN_REG - Len; i ++) - { - *(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = 0; - } - } - g_Reg->PI_CART_ADDR_REG += 0x10000000; + uint8_t * ROM = g_Rom->GetRomAddress(); + uint8_t * RDRAM = g_MMU->Rdram(); + g_Reg->PI_CART_ADDR_REG -= 0x10000000; + if (g_Reg->PI_CART_ADDR_REG + PI_WR_LEN_REG < g_Rom->GetRomSize()) + { + for (i = 0; i < PI_WR_LEN_REG; i++) + { + *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM + ((g_Reg->PI_CART_ADDR_REG + i) ^ 3)); + } + } + else if (g_Reg->PI_CART_ADDR_REG >= g_Rom->GetRomSize()) + { + uint32_t cart = g_Reg->PI_CART_ADDR_REG - g_Rom->GetRomSize(); + while (cart >= g_Rom->GetRomSize()) + { + cart -= g_Rom->GetRomSize(); + } + for (i = 0; i < PI_WR_LEN_REG; i++) + { + *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM + ((cart + i) ^ 3)); + } + } + else + { + uint32_t Len; + Len = g_Rom->GetRomSize() - g_Reg->PI_CART_ADDR_REG; + for (i = 0; i < Len; i++) + { + *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM + ((g_Reg->PI_CART_ADDR_REG + i) ^ 3)); + } + for (i = Len; i < PI_WR_LEN_REG - Len; i++) + { + *(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = 0; + } + } + g_Reg->PI_CART_ADDR_REG += 0x10000000; - if (!g_System->DmaUsed()) - { - g_System->SetDmaUsed(true); - OnFirstDMA(); - } - if (g_Recompiler && g_System->bSMM_PIDMA()) - { - g_Recompiler->ClearRecompCode_Phys(g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_WR_LEN_REG,CRecompiler::Remove_DMA); - } - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - //ChangeTimer(PiTimer,(int)(PI_WR_LEN_REG * 8.9) + 50); - //ChangeTimer(PiTimer,(int)(PI_WR_LEN_REG * 8.9)); - return; - } - - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) - { - g_Notify->DisplayError(stdstr_f("PI_DMA_WRITE not in ROM: %08X", g_Reg->PI_CART_ADDR_REG).ToUTF16().c_str()); - } - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); + if (!g_System->DmaUsed()) + { + g_System->SetDmaUsed(true); + OnFirstDMA(); + } + if (g_Recompiler && g_System->bSMM_PIDMA()) + { + g_Recompiler->ClearRecompCode_Phys(g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_WR_LEN_REG, CRecompiler::Remove_DMA); + } + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); + //ChangeTimer(PiTimer,(int32_t)(PI_WR_LEN_REG * 8.9) + 50); + //ChangeTimer(PiTimer,(int32_t)(PI_WR_LEN_REG * 8.9)); + return; + } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(stdstr_f("PI_DMA_WRITE not in ROM: %08X", g_Reg->PI_CART_ADDR_REG).ToUTF16().c_str()); + } + g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + g_Reg->MI_INTR_REG |= MI_INTR_PI; + g_Reg->CheckInterrupts(); } void CDMA::SP_DMA_READ() -{ - g_Reg->SP_DRAM_ADDR_REG &= 0x1FFFFFFF; +{ + g_Reg->SP_DRAM_ADDR_REG &= 0x1FFFFFFF; - if (g_Reg->SP_DRAM_ADDR_REG > g_MMU->RdramSize()) - { - if (bHaveDebugger()) - { - g_Notify->DisplayError(stdstr_f(__FUNCTION__ "\nSP_DRAM_ADDR_REG not in RDRam space : % 08X", g_Reg->SP_DRAM_ADDR_REG).ToUTF16().c_str()); - } - g_Reg->SP_DMA_BUSY_REG = 0; - g_Reg->SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; - return; - } - - if (g_Reg->SP_RD_LEN_REG + 1 + (g_Reg->SP_MEM_ADDR_REG & 0xFFF) > 0x1000) - { - if (bHaveDebugger()) - { - g_Notify->DisplayError(__FUNCTIONW__ L"\nCould not fit copy in memory segment"); - } - return; - } - - if ((g_Reg->SP_MEM_ADDR_REG & 3) != 0) - { - g_Notify->BreakPoint(__FILEW__,__LINE__); - } - if ((g_Reg->SP_DRAM_ADDR_REG & 3) != 0) - { - g_Notify->BreakPoint(__FILEW__,__LINE__); - } - if (((g_Reg->SP_RD_LEN_REG + 1) & 3) != 0) - { - g_Notify->BreakPoint(__FILEW__,__LINE__); - } + if (g_Reg->SP_DRAM_ADDR_REG > g_MMU->RdramSize()) + { + if (bHaveDebugger()) + { + g_Notify->DisplayError(stdstr_f(__FUNCTION__ "\nSP_DRAM_ADDR_REG not in RDRam space : % 08X", g_Reg->SP_DRAM_ADDR_REG).ToUTF16().c_str()); + } + g_Reg->SP_DMA_BUSY_REG = 0; + g_Reg->SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; + return; + } - memcpy( g_MMU->Dmem() + (g_Reg->SP_MEM_ADDR_REG & 0x1FFF), g_MMU->Rdram() + g_Reg->SP_DRAM_ADDR_REG, - g_Reg->SP_RD_LEN_REG + 1 ); - - g_Reg->SP_DMA_BUSY_REG = 0; - g_Reg->SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; + if (g_Reg->SP_RD_LEN_REG + 1 + (g_Reg->SP_MEM_ADDR_REG & 0xFFF) > 0x1000) + { + if (bHaveDebugger()) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\nCould not fit copy in memory segment"); + } + return; + } + + if ((g_Reg->SP_MEM_ADDR_REG & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + if ((g_Reg->SP_DRAM_ADDR_REG & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + if (((g_Reg->SP_RD_LEN_REG + 1) & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + + memcpy(g_MMU->Dmem() + (g_Reg->SP_MEM_ADDR_REG & 0x1FFF), g_MMU->Rdram() + g_Reg->SP_DRAM_ADDR_REG, + g_Reg->SP_RD_LEN_REG + 1); + + g_Reg->SP_DMA_BUSY_REG = 0; + g_Reg->SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; } -void CDMA::SP_DMA_WRITE() -{ - if (g_Reg->SP_DRAM_ADDR_REG > g_MMU->RdramSize()) - { - if (bHaveDebugger()) - { - g_Notify->DisplayError(stdstr_f(__FUNCTION__ "\nSP_DRAM_ADDR_REG not in RDRam space : % 08X", g_Reg->SP_DRAM_ADDR_REG).ToUTF16().c_str()); - } - return; - } - - if (g_Reg->SP_WR_LEN_REG + 1 + (g_Reg->SP_MEM_ADDR_REG & 0xFFF) > 0x1000) - { - if (bHaveDebugger()) - { - g_Notify->DisplayError(L"SP DMA WRITE\ncould not fit copy in memory segement"); - } - return; - } +void CDMA::SP_DMA_WRITE() +{ + if (g_Reg->SP_DRAM_ADDR_REG > g_MMU->RdramSize()) + { + if (bHaveDebugger()) + { + g_Notify->DisplayError(stdstr_f(__FUNCTION__ "\nSP_DRAM_ADDR_REG not in RDRam space : % 08X", g_Reg->SP_DRAM_ADDR_REG).ToUTF16().c_str()); + } + return; + } - if ((g_Reg->SP_MEM_ADDR_REG & 3) != 0) - { - g_Notify->BreakPoint(__FILEW__,__LINE__); - } - - if ((g_Reg->SP_DRAM_ADDR_REG & 3) != 0) - { - g_Notify->BreakPoint(__FILEW__,__LINE__); - } - if (((g_Reg->SP_WR_LEN_REG + 1) & 3) != 0) - { - g_Notify->BreakPoint(__FILEW__,__LINE__); - } + if (g_Reg->SP_WR_LEN_REG + 1 + (g_Reg->SP_MEM_ADDR_REG & 0xFFF) > 0x1000) + { + if (bHaveDebugger()) + { + g_Notify->DisplayError(L"SP DMA WRITE\ncould not fit copy in memory segement"); + } + return; + } - memcpy( g_MMU->Rdram() + g_Reg->SP_DRAM_ADDR_REG, g_MMU->Dmem() + (g_Reg->SP_MEM_ADDR_REG & 0x1FFF), - g_Reg->SP_WR_LEN_REG + 1); - - g_Reg->SP_DMA_BUSY_REG = 0; - g_Reg->SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; -} + if ((g_Reg->SP_MEM_ADDR_REG & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + + if ((g_Reg->SP_DRAM_ADDR_REG & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + if (((g_Reg->SP_WR_LEN_REG + 1) & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + + memcpy(g_MMU->Rdram() + g_Reg->SP_DRAM_ADDR_REG, g_MMU->Dmem() + (g_Reg->SP_MEM_ADDR_REG & 0x1FFF), + g_Reg->SP_WR_LEN_REG + 1); + + g_Reg->SP_DMA_BUSY_REG = 0; + g_Reg->SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; +} \ No newline at end of file diff --git a/Source/Project64/N64 System/Mips/Dma.h b/Source/Project64/N64 System/Mips/Dma.h index 635e2596e..0c148a348 100644 --- a/Source/Project64/N64 System/Mips/Dma.h +++ b/Source/Project64/N64 System/Mips/Dma.h @@ -9,27 +9,30 @@ * * ****************************************************************************/ #pragma once +#include +#include +#include class CDMA : - private CDebugSettings + private CDebugSettings { - CDMA(); + CDMA(); public: - void SP_DMA_READ(); - void SP_DMA_WRITE(); - void PI_DMA_READ(); - void PI_DMA_WRITE(); + void SP_DMA_READ(); + void SP_DMA_WRITE(); + void PI_DMA_READ(); + void PI_DMA_WRITE(); protected: - CDMA (CFlashram & FlashRam, CSram & Sram); - - //void SI_DMA_READ(); - //void SI_DMA_WRITE(); + CDMA(CFlashram & FlashRam, CSram & Sram); private: - CFlashram & m_FlashRam; - CSram & m_Sram; - - void OnFirstDMA(); + CDMA(const CDMA&); // Disable copy constructor + CDMA& operator=(const CDMA&); // Disable assignment + + CFlashram & m_FlashRam; + CSram & m_Sram; + + void OnFirstDMA(); }; From d740aaf350d1ce6a696205ae82b1a7746b0aaaed Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 13:20:18 +1100 Subject: [PATCH 2/9] [Project64] Use standard types in Eeprom.cpp --- Source/Project64/N64 System/Mips/Eeprom.cpp | 317 ++++++++++---------- Source/Project64/N64 System/Mips/Eeprom.h | 25 +- 2 files changed, 175 insertions(+), 167 deletions(-) diff --git a/Source/Project64/N64 System/Mips/Eeprom.cpp b/Source/Project64/N64 System/Mips/Eeprom.cpp index 0e74ec3e9..5c7036288 100644 --- a/Source/Project64/N64 System/Mips/Eeprom.cpp +++ b/Source/Project64/N64 System/Mips/Eeprom.cpp @@ -9,190 +9,193 @@ * * ****************************************************************************/ #include "stdafx.h" +#include "Eeprom.h" +#include +#include #include -CEeprom::CEeprom(bool ReadOnly): - m_ReadOnly(ReadOnly), - m_hFile(NULL) +CEeprom::CEeprom(bool ReadOnly) : +m_ReadOnly(ReadOnly), +m_hFile(NULL) { - memset(m_EEPROM,0xFF,sizeof(m_EEPROM)); + memset(m_EEPROM, 0xFF, sizeof(m_EEPROM)); } CEeprom::~CEeprom() { - if (m_hFile) - { - CloseHandle(m_hFile); - m_hFile = NULL; - } + if (m_hFile) + { + CloseHandle(m_hFile); + m_hFile = NULL; + } } -unsigned char byte2bcd(int n) +uint8_t byte2bcd(int32_t n) { - n %= 100; - return (unsigned char)(((n / 10) << 4) | (n % 10)); + n %= 100; + return (uint8_t)(((n / 10) << 4) | (n % 10)); } -void CEeprom::EepromCommand ( BYTE * Command) +void CEeprom::EepromCommand(uint8_t * Command) { - time_t curtime_time; - struct tm curtime; + time_t curtime_time; + struct tm curtime; - if (g_System->m_SaveUsing == SaveChip_Auto) - { - g_System->m_SaveUsing = SaveChip_Eeprom_4K; - } + if (g_System->m_SaveUsing == SaveChip_Auto) + { + g_System->m_SaveUsing = SaveChip_Eeprom_4K; + } - switch (Command[2]) - { - case 0: // check - if (g_System->m_SaveUsing != SaveChip_Eeprom_4K && g_System->m_SaveUsing != SaveChip_Eeprom_16K) - { - Command[1] |= 0x80; - break; - } - if (Command[1] != 3) - { - Command[1] |= 0x40; - if ((Command[1] & 3) > 0) - Command[3] = 0x00; - if ((Command[1] & 3) > 1) - Command[4] = (g_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0; - if ((Command[1] & 3) > 2) - Command[5] = 0x00; - } - else - { - Command[3] = 0x00; - Command[4] = g_System->m_SaveUsing == SaveChip_Eeprom_4K?0x80:0xC0; - Command[5] = 0x00; - } - break; - case 4: // Read from Eeprom - if (Command[0] != 2 && bHaveDebugger()) - { - g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); - } - if (Command[1] != 8 && bHaveDebugger()) - { - g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); - } - ReadFrom(&Command[4],Command[3]); - break; - case 5: //Write to Eeprom - if (Command[0] != 10 && bHaveDebugger()) - { - g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); - } - if (Command[1] != 1 && bHaveDebugger()) - { - g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); - } - WriteTo(&Command[4],Command[3]); - break; - case 6: //RTC Status query - Command[3] = 0x00; - Command[4] = 0x10; - Command[5] = 0x00; - break; - case 7: //Read RTC block - switch (Command[3]) - { - case 0: //Block number - Command[4] = 0x00; - Command[5] = 0x02; - Command[12] = 0x00; - break; - case 1: - //read block, Command[2], Unimplemented - break; - case 2: //Set RTC Time - time(&curtime_time); - memcpy(&curtime, localtime(&curtime_time), sizeof(curtime)); // fd's fix - Command[4] = byte2bcd(curtime.tm_sec); - Command[5] = byte2bcd(curtime.tm_min); - Command[6] = 0x80 + byte2bcd(curtime.tm_hour); - Command[7] = byte2bcd(curtime.tm_mday); - Command[8] = byte2bcd(curtime.tm_wday); - Command[9] = byte2bcd(curtime.tm_mon + 1); - Command[10] = byte2bcd(curtime.tm_year); - Command[11] = byte2bcd(curtime.tm_year / 100); - Command[12] = 0x00; // status - break; - } - break; - case 8: - //Write RTC, unimplemented - if (g_Settings->LoadDword(Debugger_ShowPifErrors)) - { - g_Notify->DisplayError(L"Write RTC, unimplemented"); - } - break; - default: - if (g_Settings->LoadDword(Debugger_ShowPifErrors)) - { - g_Notify->DisplayError(stdstr_f("Unknown EepromCommand %d",Command[2]).ToUTF16().c_str()); - } - } + switch (Command[2]) + { + case 0: // check + if (g_System->m_SaveUsing != SaveChip_Eeprom_4K && g_System->m_SaveUsing != SaveChip_Eeprom_16K) + { + Command[1] |= 0x80; + break; + } + if (Command[1] != 3) + { + Command[1] |= 0x40; + if ((Command[1] & 3) > 0) + Command[3] = 0x00; + if ((Command[1] & 3) > 1) + Command[4] = (g_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0; + if ((Command[1] & 3) > 2) + Command[5] = 0x00; + } + else + { + Command[3] = 0x00; + Command[4] = g_System->m_SaveUsing == SaveChip_Eeprom_4K ? 0x80 : 0xC0; + Command[5] = 0x00; + } + break; + case 4: // Read from Eeprom + if (Command[0] != 2 && bHaveDebugger()) + { + g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); + } + if (Command[1] != 8 && bHaveDebugger()) + { + g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); + } + ReadFrom(&Command[4], Command[3]); + break; + case 5: //Write to Eeprom + if (Command[0] != 10 && bHaveDebugger()) + { + g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); + } + if (Command[1] != 1 && bHaveDebugger()) + { + g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); + } + WriteTo(&Command[4], Command[3]); + break; + case 6: //RTC Status query + Command[3] = 0x00; + Command[4] = 0x10; + Command[5] = 0x00; + break; + case 7: //Read RTC block + switch (Command[3]) + { + case 0: //Block number + Command[4] = 0x00; + Command[5] = 0x02; + Command[12] = 0x00; + break; + case 1: + //read block, Command[2], Unimplemented + break; + case 2: //Set RTC Time + time(&curtime_time); + memcpy(&curtime, localtime(&curtime_time), sizeof(curtime)); // fd's fix + Command[4] = byte2bcd(curtime.tm_sec); + Command[5] = byte2bcd(curtime.tm_min); + Command[6] = 0x80 + byte2bcd(curtime.tm_hour); + Command[7] = byte2bcd(curtime.tm_mday); + Command[8] = byte2bcd(curtime.tm_wday); + Command[9] = byte2bcd(curtime.tm_mon + 1); + Command[10] = byte2bcd(curtime.tm_year); + Command[11] = byte2bcd(curtime.tm_year / 100); + Command[12] = 0x00; // status + break; + } + break; + case 8: + //Write RTC, unimplemented + if (g_Settings->LoadDword(Debugger_ShowPifErrors)) + { + g_Notify->DisplayError(L"Write RTC, unimplemented"); + } + break; + default: + if (g_Settings->LoadDword(Debugger_ShowPifErrors)) + { + g_Notify->DisplayError(stdstr_f("Unknown EepromCommand %d", Command[2]).ToUTF16().c_str()); + } + } } void CEeprom::LoadEeprom() { - CPath FileName; - DWORD dwRead; + CPath FileName; + DWORD dwRead; - memset(m_EEPROM,0xFF,sizeof(m_EEPROM)); + memset(m_EEPROM, 0xFF, sizeof(m_EEPROM)); - FileName.SetDriveDirectory( g_Settings->LoadStringVal(Directory_NativeSave).c_str()); - FileName.SetName(g_Settings->LoadStringVal(Game_GameName).c_str()); - FileName.SetExtension("eep"); + FileName.SetDriveDirectory(g_Settings->LoadStringVal(Directory_NativeSave).c_str()); + FileName.SetName(g_Settings->LoadStringVal(Game_GameName).c_str()); + FileName.SetExtension("eep"); - if (!FileName.DirectoryExists()) - { - FileName.DirectoryCreate(); - } + if (!FileName.DirectoryExists()) + { + FileName.DirectoryCreate(); + } - m_hFile = CreateFile(FileName,m_ReadOnly ? GENERIC_READ : GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); - if (m_hFile == INVALID_HANDLE_VALUE) - { - WriteTraceF(TraceError,__FUNCTION__ ": Failed to open (%s), ReadOnly = %d, LastError = %X",(LPCTSTR)FileName, m_ReadOnly, GetLastError()); - g_Notify->DisplayError(GS(MSG_FAIL_OPEN_EEPROM)); - return; - } - SetFilePointer(m_hFile,0,NULL,FILE_BEGIN); - ReadFile(m_hFile,m_EEPROM,sizeof(m_EEPROM),&dwRead,NULL); + m_hFile = CreateFile(FileName, m_ReadOnly ? GENERIC_READ : GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + if (m_hFile == INVALID_HANDLE_VALUE) + { + WriteTraceF(TraceError, __FUNCTION__ ": Failed to open (%s), ReadOnly = %d, LastError = %X", (LPCTSTR)FileName, m_ReadOnly, GetLastError()); + g_Notify->DisplayError(GS(MSG_FAIL_OPEN_EEPROM)); + return; + } + SetFilePointer(m_hFile, 0, NULL, FILE_BEGIN); + ReadFile(m_hFile, m_EEPROM, sizeof(m_EEPROM), &dwRead, NULL); } -void CEeprom::ReadFrom(BYTE * Buffer, int line) +void CEeprom::ReadFrom(uint8_t * Buffer, int32_t line) { - int i; - - if (m_hFile == NULL) - { - LoadEeprom(); - } - - for (i=0; i < 8; i++) - { - Buffer[i] = m_EEPROM[line*8+i]; - } + int32_t i; + + if (m_hFile == NULL) + { + LoadEeprom(); + } + + for (i = 0; i < 8; i++) + { + Buffer[i] = m_EEPROM[line * 8 + i]; + } } -void CEeprom::WriteTo(BYTE * Buffer, int line) +void CEeprom::WriteTo(uint8_t * Buffer, int32_t line) { - DWORD dwWritten; - int i; + DWORD dwWritten; + int32_t i; - if (m_hFile == NULL) - { - LoadEeprom(); - } - for (i=0;i<8;i++) - { - m_EEPROM[line*8+i]=Buffer[i]; - } - SetFilePointer(m_hFile,line*8,NULL,FILE_BEGIN); - WriteFile( m_hFile,Buffer,8,&dwWritten,NULL ); - FlushFileBuffers(m_hFile); -} + if (m_hFile == NULL) + { + LoadEeprom(); + } + for (i = 0; i < 8; i++) + { + m_EEPROM[line * 8 + i] = Buffer[i]; + } + SetFilePointer(m_hFile, line * 8, NULL, FILE_BEGIN); + WriteFile(m_hFile, Buffer, 8, &dwWritten, NULL); + FlushFileBuffers(m_hFile); +} \ No newline at end of file diff --git a/Source/Project64/N64 System/Mips/Eeprom.h b/Source/Project64/N64 System/Mips/Eeprom.h index fe739445b..e334dc4c6 100644 --- a/Source/Project64/N64 System/Mips/Eeprom.h +++ b/Source/Project64/N64 System/Mips/Eeprom.h @@ -9,22 +9,27 @@ * * ****************************************************************************/ #pragma once +#include class CEeprom : - private CDebugSettings + private CDebugSettings { public: - CEeprom ( bool ReadOnly ); - ~CEeprom(); + CEeprom ( bool ReadOnly ); + ~CEeprom(); - void EepromCommand ( BYTE * Command ); + void EepromCommand ( uint8_t * Command ); private: - void LoadEeprom (); - void ReadFrom ( BYTE * Buffer, int line ); - void WriteTo ( BYTE * Buffer, int line ); + CEeprom(void); // Disable default constructor + CEeprom(const CEeprom&); // Disable copy constructor + CEeprom& operator=(const CEeprom&); // Disable assignment - BYTE m_EEPROM[0x800]; - bool m_ReadOnly; - HANDLE m_hFile; + void LoadEeprom (); + void ReadFrom ( uint8_t * Buffer, int32_t line ); + void WriteTo ( uint8_t * Buffer, int32_t line ); + + uint8_t m_EEPROM[0x800]; + bool m_ReadOnly; + void * m_hFile; }; From ec31d79c232c21e9602cdcc754627d1b0bdc249d Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 13:27:06 +1100 Subject: [PATCH 3/9] [Project64] Cleanup Code Section.cpp --- .../N64 System/Recompiler/Code Section.cpp | 4062 ++++++++--------- .../N64 System/Recompiler/Code Section.h | 100 +- 2 files changed, 2081 insertions(+), 2081 deletions(-) diff --git a/Source/Project64/N64 System/Recompiler/Code Section.cpp b/Source/Project64/N64 System/Recompiler/Code Section.cpp index cc3128e58..94c145873 100644 --- a/Source/Project64/N64 System/Recompiler/Code Section.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Section.cpp @@ -16,84 +16,84 @@ bool DelaySlotEffectsCompare(uint32_t PC, uint32_t Reg1, uint32_t Reg2); static bool DelaySlotEffectsJump(uint32_t JumpPC) { - OPCODE Command; + OPCODE Command; - if (!g_MMU->LW_VAddr(JumpPC, Command.Hex)) - return true; + if (!g_MMU->LW_VAddr(JumpPC, Command.Hex)) + return true; - switch (Command.op) - { - case R4300i_SPECIAL: - switch (Command.funct) - { - case R4300i_SPECIAL_JR: return DelaySlotEffectsCompare(JumpPC, Command.rs, 0); - case R4300i_SPECIAL_JALR: return DelaySlotEffectsCompare(JumpPC, Command.rs, 31); - } - break; - case R4300i_REGIMM: - switch (Command.rt) - { - case R4300i_REGIMM_BLTZ: - case R4300i_REGIMM_BGEZ: - case R4300i_REGIMM_BLTZL: - case R4300i_REGIMM_BGEZL: - case R4300i_REGIMM_BLTZAL: - case R4300i_REGIMM_BGEZAL: - return DelaySlotEffectsCompare(JumpPC, Command.rs, 0); - } - break; - case R4300i_JAL: - case R4300i_SPECIAL_JALR: return DelaySlotEffectsCompare(JumpPC, 31, 0); break; - case R4300i_J: return false; - case R4300i_BEQ: - case R4300i_BNE: - case R4300i_BLEZ: - case R4300i_BGTZ: - return DelaySlotEffectsCompare(JumpPC, Command.rs, Command.rt); - case R4300i_CP1: - switch (Command.fmt) - { - case R4300i_COP1_BC: - switch (Command.ft) - { - case R4300i_COP1_BC_BCF: - case R4300i_COP1_BC_BCT: - case R4300i_COP1_BC_BCFL: - case R4300i_COP1_BC_BCTL: - { - bool EffectDelaySlot = false; - OPCODE NewCommand; + switch (Command.op) + { + case R4300i_SPECIAL: + switch (Command.funct) + { + case R4300i_SPECIAL_JR: return DelaySlotEffectsCompare(JumpPC, Command.rs, 0); + case R4300i_SPECIAL_JALR: return DelaySlotEffectsCompare(JumpPC, Command.rs, 31); + } + break; + case R4300i_REGIMM: + switch (Command.rt) + { + case R4300i_REGIMM_BLTZ: + case R4300i_REGIMM_BGEZ: + case R4300i_REGIMM_BLTZL: + case R4300i_REGIMM_BGEZL: + case R4300i_REGIMM_BLTZAL: + case R4300i_REGIMM_BGEZAL: + return DelaySlotEffectsCompare(JumpPC, Command.rs, 0); + } + break; + case R4300i_JAL: + case R4300i_SPECIAL_JALR: return DelaySlotEffectsCompare(JumpPC, 31, 0); break; + case R4300i_J: return false; + case R4300i_BEQ: + case R4300i_BNE: + case R4300i_BLEZ: + case R4300i_BGTZ: + return DelaySlotEffectsCompare(JumpPC, Command.rs, Command.rt); + case R4300i_CP1: + switch (Command.fmt) + { + case R4300i_COP1_BC: + switch (Command.ft) + { + case R4300i_COP1_BC_BCF: + case R4300i_COP1_BC_BCT: + case R4300i_COP1_BC_BCFL: + case R4300i_COP1_BC_BCTL: + { + bool EffectDelaySlot = false; + OPCODE NewCommand; - if (!g_MMU->LW_VAddr(JumpPC + 4, NewCommand.Hex)) - { - return true; - } + if (!g_MMU->LW_VAddr(JumpPC + 4, NewCommand.Hex)) + { + return true; + } - if (NewCommand.op == R4300i_CP1) - { - if (NewCommand.fmt == R4300i_COP1_S && (NewCommand.funct & 0x30) == 0x30) - { - EffectDelaySlot = true; - } - if (NewCommand.fmt == R4300i_COP1_D && (NewCommand.funct & 0x30) == 0x30) - { - EffectDelaySlot = true; - } - } - return EffectDelaySlot; - } - break; - } - break; - } - break; - case R4300i_BEQL: - case R4300i_BNEL: - case R4300i_BLEZL: - case R4300i_BGTZL: - return DelaySlotEffectsCompare(JumpPC, Command.rs, Command.rt); - } - return true; + if (NewCommand.op == R4300i_CP1) + { + if (NewCommand.fmt == R4300i_COP1_S && (NewCommand.funct & 0x30) == 0x30) + { + EffectDelaySlot = true; + } + if (NewCommand.fmt == R4300i_COP1_D && (NewCommand.funct & 0x30) == 0x30) + { + EffectDelaySlot = true; + } + } + return EffectDelaySlot; + } + break; + } + break; + } + break; + case R4300i_BEQL: + case R4300i_BNEL: + case R4300i_BLEZL: + case R4300i_BGTZL: + return DelaySlotEffectsCompare(JumpPC, Command.rs, Command.rt); + } + return true; } CCodeSection::CCodeSection(CCodeBlock * CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed) : @@ -111,7 +111,7 @@ m_CompiledLocation(NULL), m_InLoop(false), m_DelaySlot(false) { - CPU_Message(__FUNCTION__ ": ID %d EnterPC 0x%08X", ID, EnterPC); + CPU_Message(__FUNCTION__ ": ID %d EnterPC 0x%08X", ID, EnterPC); } CCodeSection::~CCodeSection() @@ -120,861 +120,861 @@ CCodeSection::~CCodeSection() void CCodeSection::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, bool CompileNow, void(*x86Jmp)(const char * Label, uint32_t Value)) { - if (!CompileNow) - { - char String[100]; - sprintf(String, "Exit_%d", m_BlockInfo->m_ExitInfo.size()); - if (x86Jmp == NULL) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - return; - } - x86Jmp(String, 0); + if (!CompileNow) + { + char String[100]; + sprintf(String, "Exit_%d", m_BlockInfo->m_ExitInfo.size()); + if (x86Jmp == NULL) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + return; + } + x86Jmp(String, 0); - CExitInfo ExitInfo; - ExitInfo.ID = m_BlockInfo->m_ExitInfo.size(); - ExitInfo.TargetPC = TargetPC; - ExitInfo.ExitRegSet = ExitRegSet; - ExitInfo.reason = reason; - ExitInfo.NextInstruction = m_NextInstruction; - ExitInfo.JumpLoc = (uint32_t *)(m_RecompPos - 4); - m_BlockInfo->m_ExitInfo.push_back(ExitInfo); - return; - } + CExitInfo ExitInfo; + ExitInfo.ID = m_BlockInfo->m_ExitInfo.size(); + ExitInfo.TargetPC = TargetPC; + ExitInfo.ExitRegSet = ExitRegSet; + ExitInfo.reason = reason; + ExitInfo.NextInstruction = m_NextInstruction; + ExitInfo.JumpLoc = (uint32_t *)(m_RecompPos - 4); + m_BlockInfo->m_ExitInfo.push_back(ExitInfo); + return; + } - //CPU_Message("CompileExit: %d",reason); - ExitRegSet.WriteBackRegisters(); + //CPU_Message("CompileExit: %d",reason); + ExitRegSet.WriteBackRegisters(); - if (TargetPC != (uint32_t)-1) - { - MoveConstToVariable(TargetPC, &g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER"); - UpdateCounters(ExitRegSet, TargetPC <= JumpPC && JumpPC != -1, reason == CExitInfo::Normal); - } - else - { - UpdateCounters(ExitRegSet, false, reason == CExitInfo::Normal); - } + if (TargetPC != (uint32_t)-1) + { + MoveConstToVariable(TargetPC, &g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER"); + UpdateCounters(ExitRegSet, TargetPC <= JumpPC && JumpPC != -1, reason == CExitInfo::Normal); + } + else + { + UpdateCounters(ExitRegSet, false, reason == CExitInfo::Normal); + } - switch (reason) - { - case CExitInfo::Normal: case CExitInfo::Normal_NoSysCheck: - ExitRegSet.SetBlockCycleCount(0); - if (TargetPC != (uint32_t)-1) - { - if (TargetPC <= JumpPC && reason == CExitInfo::Normal) - { - CPU_Message("CompileSystemCheck 1"); - CompileSystemCheck((uint32_t)-1, ExitRegSet); - } - } - else - { - if (reason == CExitInfo::Normal) - { - CPU_Message("CompileSystemCheck 2"); - CompileSystemCheck((uint32_t)-1, ExitRegSet); - } - } - if (g_SyncSystem) - { - MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } + switch (reason) + { + case CExitInfo::Normal: case CExitInfo::Normal_NoSysCheck: + ExitRegSet.SetBlockCycleCount(0); + if (TargetPC != (uint32_t)-1) + { + if (TargetPC <= JumpPC && reason == CExitInfo::Normal) + { + CPU_Message("CompileSystemCheck 1"); + CompileSystemCheck((uint32_t)-1, ExitRegSet); + } + } + else + { + if (reason == CExitInfo::Normal) + { + CPU_Message("CompileSystemCheck 2"); + CompileSystemCheck((uint32_t)-1, ExitRegSet); + } + } + if (g_SyncSystem) + { + MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } #ifdef LinkBlocks - if (bSMM_ValidFunc == false) - { - if (LookUpMode() == FuncFind_ChangeMemory) - { - g_Notify->BreakPoint(__FILEW__,__LINE__); - // uint8_t * Jump, * Jump2; - // if (TargetPC >= 0x80000000 && TargetPC < 0xC0000000) { - // uint32_t pAddr = TargetPC & 0x1FFFFFFF; - // - // MoveVariableToX86reg((uint8_t *)RDRAM + pAddr,"RDRAM + pAddr",x86_EAX); - // Jump2 = NULL; - // } else { - // MoveConstToX86reg((TargetPC >> 12),x86_ECX); - // MoveConstToX86reg(TargetPC,x86_EBX); - // MoveVariableDispToX86Reg(TLB_ReadMap,"TLB_ReadMap",x86_ECX,x86_ECX,4); - // TestX86RegToX86Reg(x86_ECX,x86_ECX); - // JeLabel8("NoTlbEntry",0); - // Jump2 = m_RecompPos - 1; - // MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_EAX); - // } - // MoveX86RegToX86Reg(x86_EAX,x86_ECX); - // AndConstToX86Reg(x86_ECX,0xFFFF0000); - // CompConstToX86reg(x86_ECX,0x7C7C0000); - // JneLabel8("NoCode",0); - // Jump = m_RecompPos - 1; - // AndConstToX86Reg(x86_EAX,0xFFFF); - // ShiftLeftSignImmed(x86_EAX,4); - // AddConstToX86Reg(x86_EAX,0xC); - // MoveVariableDispToX86Reg(OrigMem,"OrigMem",x86_ECX,x86_EAX,1); - // JmpDirectReg(x86_ECX); - // CPU_Message(" NoCode:"); - // *((uint8_t *)(Jump))=(uint8_t)(m_RecompPos - Jump - 1); - // if (Jump2 != NULL) { - // CPU_Message(" NoTlbEntry:"); - // *((uint8_t *)(Jump2))=(uint8_t)(m_RecompPos - Jump2 - 1); - // } - } - else if (LookUpMode() == FuncFind_VirtualLookup) - { - MoveConstToX86reg(TargetPC,x86_EDX); - MoveConstToX86reg((uint32_t)&m_Functions,x86_ECX); - Call_Direct(AddressOf(&CFunctionMap::CompilerFindFunction), "CFunctionMap::CompilerFindFunction"); - MoveX86RegToX86Reg(x86_EAX,x86_ECX); - JecxzLabel8("NullPointer",0); - uint8_t * Jump = m_RecompPos - 1; - MoveX86PointerToX86regDisp(x86_EBX,x86_ECX,0xC); - JmpDirectReg(x86_EBX); - CPU_Message(" NullPointer:"); - *((uint8_t *)(Jump))=(uint8_t)(m_RecompPos - Jump - 1); - } - else if (LookUpMode() == FuncFind_PhysicalLookup) - { - uint8_t * Jump2 = NULL; - if (TargetPC >= 0x80000000 && TargetPC < 0x90000000) - { - uint32_t pAddr = TargetPC & 0x1FFFFFFF; - MoveVariableToX86reg((uint8_t *)JumpTable + pAddr,"JumpTable + pAddr",x86_ECX); - } - else if (TargetPC >= 0x90000000 && TargetPC < 0xC0000000) - { - } - else - { - MoveConstToX86reg((TargetPC >> 12),x86_ECX); - MoveConstToX86reg(TargetPC,x86_EBX); - MoveVariableDispToX86Reg(TLB_ReadMap,"TLB_ReadMap",x86_ECX,x86_ECX,4); - TestX86RegToX86Reg(x86_ECX,x86_ECX); - JeLabel8("NoTlbEntry",0); - Jump2 = m_RecompPos - 1; - AddConstToX86Reg(x86_ECX,(uint32_t)JumpTable - (uint32_t)RDRAM); - MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_ECX); - } - if (TargetPC < 0x90000000 || TargetPC >= 0xC0000000) - { - JecxzLabel8("NullPointer",0); - uint8_t * Jump = m_RecompPos - 1; - MoveX86PointerToX86regDisp(x86_EAX,x86_ECX,0xC); - JmpDirectReg(x86_EAX); - CPU_Message(" NullPointer:"); - *((uint8_t *)(Jump))=(uint8_t)(m_RecompPos - Jump - 1); - if (Jump2 != NULL) - { - CPU_Message(" NoTlbEntry:"); - *((uint8_t *)(Jump2))=(uint8_t)(m_RecompPos - Jump2 - 1); - } - } - } - } - ExitCodeBlock(); + if (bSMM_ValidFunc == false) + { + if (LookUpMode() == FuncFind_ChangeMemory) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + // uint8_t * Jump, * Jump2; + // if (TargetPC >= 0x80000000 && TargetPC < 0xC0000000) { + // uint32_t pAddr = TargetPC & 0x1FFFFFFF; + // + // MoveVariableToX86reg((uint8_t *)RDRAM + pAddr,"RDRAM + pAddr",x86_EAX); + // Jump2 = NULL; + // } else { + // MoveConstToX86reg((TargetPC >> 12),x86_ECX); + // MoveConstToX86reg(TargetPC,x86_EBX); + // MoveVariableDispToX86Reg(TLB_ReadMap,"TLB_ReadMap",x86_ECX,x86_ECX,4); + // TestX86RegToX86Reg(x86_ECX,x86_ECX); + // JeLabel8("NoTlbEntry",0); + // Jump2 = m_RecompPos - 1; + // MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_EAX); + // } + // MoveX86RegToX86Reg(x86_EAX,x86_ECX); + // AndConstToX86Reg(x86_ECX,0xFFFF0000); + // CompConstToX86reg(x86_ECX,0x7C7C0000); + // JneLabel8("NoCode",0); + // Jump = m_RecompPos - 1; + // AndConstToX86Reg(x86_EAX,0xFFFF); + // ShiftLeftSignImmed(x86_EAX,4); + // AddConstToX86Reg(x86_EAX,0xC); + // MoveVariableDispToX86Reg(OrigMem,"OrigMem",x86_ECX,x86_EAX,1); + // JmpDirectReg(x86_ECX); + // CPU_Message(" NoCode:"); + // *((uint8_t *)(Jump))=(uint8_t)(m_RecompPos - Jump - 1); + // if (Jump2 != NULL) { + // CPU_Message(" NoTlbEntry:"); + // *((uint8_t *)(Jump2))=(uint8_t)(m_RecompPos - Jump2 - 1); + // } + } + else if (LookUpMode() == FuncFind_VirtualLookup) + { + MoveConstToX86reg(TargetPC,x86_EDX); + MoveConstToX86reg((uint32_t)&m_Functions,x86_ECX); + Call_Direct(AddressOf(&CFunctionMap::CompilerFindFunction), "CFunctionMap::CompilerFindFunction"); + MoveX86RegToX86Reg(x86_EAX,x86_ECX); + JecxzLabel8("NullPointer",0); + uint8_t * Jump = m_RecompPos - 1; + MoveX86PointerToX86regDisp(x86_EBX,x86_ECX,0xC); + JmpDirectReg(x86_EBX); + CPU_Message(" NullPointer:"); + *((uint8_t *)(Jump))=(uint8_t)(m_RecompPos - Jump - 1); + } + else if (LookUpMode() == FuncFind_PhysicalLookup) + { + uint8_t * Jump2 = NULL; + if (TargetPC >= 0x80000000 && TargetPC < 0x90000000) + { + uint32_t pAddr = TargetPC & 0x1FFFFFFF; + MoveVariableToX86reg((uint8_t *)JumpTable + pAddr,"JumpTable + pAddr",x86_ECX); + } + else if (TargetPC >= 0x90000000 && TargetPC < 0xC0000000) + { + } + else + { + MoveConstToX86reg((TargetPC >> 12),x86_ECX); + MoveConstToX86reg(TargetPC,x86_EBX); + MoveVariableDispToX86Reg(TLB_ReadMap,"TLB_ReadMap",x86_ECX,x86_ECX,4); + TestX86RegToX86Reg(x86_ECX,x86_ECX); + JeLabel8("NoTlbEntry",0); + Jump2 = m_RecompPos - 1; + AddConstToX86Reg(x86_ECX,(uint32_t)JumpTable - (uint32_t)RDRAM); + MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_ECX); + } + if (TargetPC < 0x90000000 || TargetPC >= 0xC0000000) + { + JecxzLabel8("NullPointer",0); + uint8_t * Jump = m_RecompPos - 1; + MoveX86PointerToX86regDisp(x86_EAX,x86_ECX,0xC); + JmpDirectReg(x86_EAX); + CPU_Message(" NullPointer:"); + *((uint8_t *)(Jump))=(uint8_t)(m_RecompPos - Jump - 1); + if (Jump2 != NULL) + { + CPU_Message(" NoTlbEntry:"); + *((uint8_t *)(Jump2))=(uint8_t)(m_RecompPos - Jump2 - 1); + } + } + } + } + ExitCodeBlock(); #else - ExitCodeBlock(); + ExitCodeBlock(); #endif - break; - case CExitInfo::DoCPU_Action: - MoveConstToX86reg((uint32_t)g_SystemEvents, x86_ECX); - Call_Direct(AddressOf(&CSystemEvents::ExecuteEvents), "CSystemEvents::ExecuteEvents"); - if (g_SyncSystem) - { - MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - //g_System->SyncCPU(g_SyncSystem); - ExitCodeBlock(); - break; - case CExitInfo::DoSysCall: - { - bool bDelay = m_NextInstruction == JUMP || m_NextInstruction == DELAY_SLOT; - PushImm32(bDelay ? "true" : "false", bDelay); - MoveConstToX86reg((uint32_t)g_Reg, x86_ECX); - Call_Direct(AddressOf(&CRegisters::DoSysCallException), "CRegisters::DoSysCallException"); - if (g_SyncSystem) - { - MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - ExitCodeBlock(); - } - break; - case CExitInfo::COP1_Unuseable: - { - bool bDelay = m_NextInstruction == JUMP || m_NextInstruction == DELAY_SLOT; - PushImm32("1", 1); - PushImm32(bDelay ? "true" : "false", bDelay); - MoveConstToX86reg((uint32_t)g_Reg, x86_ECX); - Call_Direct(AddressOf(&CRegisters::DoCopUnusableException), "CRegisters::DoCopUnusableException"); - if (g_SyncSystem) - { - MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - ExitCodeBlock(); - } - break; - case CExitInfo::ExitResetRecompCode: - g_Notify->BreakPoint(__FILEW__, __LINE__); + break; + case CExitInfo::DoCPU_Action: + MoveConstToX86reg((uint32_t)g_SystemEvents, x86_ECX); + Call_Direct(AddressOf(&CSystemEvents::ExecuteEvents), "CSystemEvents::ExecuteEvents"); + if (g_SyncSystem) + { + MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + //g_System->SyncCPU(g_SyncSystem); + ExitCodeBlock(); + break; + case CExitInfo::DoSysCall: + { + bool bDelay = m_NextInstruction == JUMP || m_NextInstruction == DELAY_SLOT; + PushImm32(bDelay ? "true" : "false", bDelay); + MoveConstToX86reg((uint32_t)g_Reg, x86_ECX); + Call_Direct(AddressOf(&CRegisters::DoSysCallException), "CRegisters::DoSysCallException"); + if (g_SyncSystem) + { + MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + ExitCodeBlock(); + } + break; + case CExitInfo::COP1_Unuseable: + { + bool bDelay = m_NextInstruction == JUMP || m_NextInstruction == DELAY_SLOT; + PushImm32("1", 1); + PushImm32(bDelay ? "true" : "false", bDelay); + MoveConstToX86reg((uint32_t)g_Reg, x86_ECX); + Call_Direct(AddressOf(&CRegisters::DoCopUnusableException), "CRegisters::DoCopUnusableException"); + if (g_SyncSystem) + { + MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + ExitCodeBlock(); + } + break; + case CExitInfo::ExitResetRecompCode: + g_Notify->BreakPoint(__FILEW__, __LINE__); #ifdef tofix - if (m_NextInstruction == JUMP || m_NextInstruction == DELAY_SLOT) - { - X86BreakPoint(__FILEW__,__LINE__); - } - if (g_SyncSystem) - { - MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - X86BreakPoint(__FILEW__,__LINE__); - MoveVariableToX86reg(this,"this",x86_ECX); - Call_Direct(AddressOf(ResetRecompCode), "ResetRecompCode"); + if (m_NextInstruction == JUMP || m_NextInstruction == DELAY_SLOT) + { + X86BreakPoint(__FILEW__,__LINE__); + } + if (g_SyncSystem) + { + MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + X86BreakPoint(__FILEW__,__LINE__); + MoveVariableToX86reg(this,"this",x86_ECX); + Call_Direct(AddressOf(ResetRecompCode), "ResetRecompCode"); #endif - ExitCodeBlock(); - break; - case CExitInfo::TLBReadMiss: - MoveVariableToX86reg(g_TLBLoadAddress, "g_TLBLoadAddress", x86_EDX); - Push(x86_EDX); - PushImm32(m_NextInstruction == JUMP || m_NextInstruction == DELAY_SLOT); - MoveConstToX86reg((uint32_t)g_Reg, x86_ECX); - Call_Direct(AddressOf(&CRegisters::DoTLBReadMiss), "CRegisters::DoTLBReadMiss"); - if (g_SyncSystem) - { - MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - ExitCodeBlock(); - break; - case CExitInfo::TLBWriteMiss: - X86BreakPoint(__FILEW__, __LINE__); - ExitCodeBlock(); - break; - case CExitInfo::DivByZero: - AddConstToVariable(4, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); - if (!g_System->b32BitCore()) - { - MoveConstToVariable(0, &_RegHI->UW[1], "_RegHI->UW[1]"); - MoveConstToVariable(0, &_RegLO->UW[1], "_RegLO->UW[1]"); - } - MoveConstToVariable(0, &_RegHI->UW[0], "_RegHI->UW[0]"); - MoveConstToVariable(0, &_RegLO->UW[0], "_RegLO->UW[0]"); - if (g_SyncSystem) - { - MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - ExitCodeBlock(); - break; - default: - WriteTraceF(TraceError, __FUNCTION__ ": how did you want to exit on reason (%d) ???", reason); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } + ExitCodeBlock(); + break; + case CExitInfo::TLBReadMiss: + MoveVariableToX86reg(g_TLBLoadAddress, "g_TLBLoadAddress", x86_EDX); + Push(x86_EDX); + PushImm32(m_NextInstruction == JUMP || m_NextInstruction == DELAY_SLOT); + MoveConstToX86reg((uint32_t)g_Reg, x86_ECX); + Call_Direct(AddressOf(&CRegisters::DoTLBReadMiss), "CRegisters::DoTLBReadMiss"); + if (g_SyncSystem) + { + MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + ExitCodeBlock(); + break; + case CExitInfo::TLBWriteMiss: + X86BreakPoint(__FILEW__, __LINE__); + ExitCodeBlock(); + break; + case CExitInfo::DivByZero: + AddConstToVariable(4, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); + if (!g_System->b32BitCore()) + { + MoveConstToVariable(0, &_RegHI->UW[1], "_RegHI->UW[1]"); + MoveConstToVariable(0, &_RegLO->UW[1], "_RegLO->UW[1]"); + } + MoveConstToVariable(0, &_RegHI->UW[0], "_RegHI->UW[0]"); + MoveConstToVariable(0, &_RegLO->UW[0], "_RegLO->UW[0]"); + if (g_SyncSystem) + { + MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + ExitCodeBlock(); + break; + default: + WriteTraceF(TraceError, __FUNCTION__ ": how did you want to exit on reason (%d) ???", reason); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } } void CCodeSection::GenerateSectionLinkage() { - CCodeSection * TargetSection[] = { m_ContinueSection, m_JumpSection }; - CJumpInfo * JumpInfo[] = { &m_Cont, &m_Jump }; - int i; + CCodeSection * TargetSection[] = { m_ContinueSection, m_JumpSection }; + CJumpInfo * JumpInfo[] = { &m_Cont, &m_Jump }; + int i; - for (i = 0; i < 2; i++) - { - if (JumpInfo[i]->LinkLocation == NULL && - JumpInfo[i]->FallThrough == false) - { - JumpInfo[i]->TargetPC = (uint32_t)-1; - } - } + for (i = 0; i < 2; i++) + { + if (JumpInfo[i]->LinkLocation == NULL && + JumpInfo[i]->FallThrough == false) + { + JumpInfo[i]->TargetPC = (uint32_t)-1; + } + } - if ((CompilePC() & 0xFFC) == 0xFFC) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); + if ((CompilePC() & 0xFFC) == 0xFFC) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); #ifdef tofix - //Handle Fall througth - uint8_t * Jump = NULL; - for (i = 0; i < 2; i ++) - { - if (!JumpInfo[i]->FallThrough) { continue; } - JumpInfo[i]->FallThrough = false; - if (JumpInfo[i]->LinkLocation != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation,(uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation = NULL; - if (JumpInfo[i]->LinkLocation2 != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation2,(uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation2 = NULL; - } - } - PushImm32(stdstr_f("0x%08X",JumpInfo[i]->TargetPC).c_str(),JumpInfo[i]->TargetPC); - if (JumpInfo[(i + 1) & 1]->LinkLocation == NULL) { break; } - JmpLabel8("FinishBlock",0); - Jump = m_RecompPos - 1; - } - for (i = 0; i < 2; i ++) - { - if (JumpInfo[i]->LinkLocation == NULL) { continue; } - JumpInfo[i]->FallThrough = false; - if (JumpInfo[i]->LinkLocation != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation,(uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation = NULL; - if (JumpInfo[i]->LinkLocation2 != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation2,(uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation2 = NULL; - } - } - PushImm32(stdstr_f("0x%08X",JumpInfo[i]->TargetPC).c_str(),JumpInfo[i]->TargetPC); - if (JumpInfo[(i + 1) & 1]->LinkLocation == NULL) { break; } - JmpLabel8("FinishBlock",0); - Jump = m_RecompPos - 1; - } - if (Jump != NULL) - { - CPU_Message(" $FinishBlock:"); - SetJump8(Jump,m_RecompPos); - } - //MoveConstToVariable(CompilePC() + 4,_PROGRAM_COUNTER,"PROGRAM_COUNTER"); - m_RegWorkingSet.WriteBackRegisters(); - UpdateCounters(m_RegWorkingSet,false,true); - // WriteBackRegisters(Section); - // if (g_SyncSystem) { - MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - // MoveConstToVariable(DELAY_SLOT,&m_NextInstruction,"m_NextInstruction"); - PushImm32(stdstr_f("0x%08X",CompilePC() + 4).c_str(),CompilePC() + 4); + //Handle Fall througth + uint8_t * Jump = NULL; + for (i = 0; i < 2; i ++) + { + if (!JumpInfo[i]->FallThrough) { continue; } + JumpInfo[i]->FallThrough = false; + if (JumpInfo[i]->LinkLocation != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation,(uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation = NULL; + if (JumpInfo[i]->LinkLocation2 != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation2,(uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation2 = NULL; + } + } + PushImm32(stdstr_f("0x%08X",JumpInfo[i]->TargetPC).c_str(),JumpInfo[i]->TargetPC); + if (JumpInfo[(i + 1) & 1]->LinkLocation == NULL) { break; } + JmpLabel8("FinishBlock",0); + Jump = m_RecompPos - 1; + } + for (i = 0; i < 2; i ++) + { + if (JumpInfo[i]->LinkLocation == NULL) { continue; } + JumpInfo[i]->FallThrough = false; + if (JumpInfo[i]->LinkLocation != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation,(uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation = NULL; + if (JumpInfo[i]->LinkLocation2 != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation2,(uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation2 = NULL; + } + } + PushImm32(stdstr_f("0x%08X",JumpInfo[i]->TargetPC).c_str(),JumpInfo[i]->TargetPC); + if (JumpInfo[(i + 1) & 1]->LinkLocation == NULL) { break; } + JmpLabel8("FinishBlock",0); + Jump = m_RecompPos - 1; + } + if (Jump != NULL) + { + CPU_Message(" $FinishBlock:"); + SetJump8(Jump,m_RecompPos); + } + //MoveConstToVariable(CompilePC() + 4,_PROGRAM_COUNTER,"PROGRAM_COUNTER"); + m_RegWorkingSet.WriteBackRegisters(); + UpdateCounters(m_RegWorkingSet,false,true); + // WriteBackRegisters(Section); + // if (g_SyncSystem) { + MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + // MoveConstToVariable(DELAY_SLOT,&m_NextInstruction,"m_NextInstruction"); + PushImm32(stdstr_f("0x%08X",CompilePC() + 4).c_str(),CompilePC() + 4); - // check if there is an existing section + // check if there is an existing section - MoveConstToX86reg((uint32_t)g_Recompiler,x86_ECX); - Call_Direct(AddressOf(&CRecompiler::CompileDelaySlot), "CRecompiler::CompileDelaySlot"); - JmpDirectReg(x86_EAX); - ExitCodeBlock(); - return; + MoveConstToX86reg((uint32_t)g_Recompiler,x86_ECX); + Call_Direct(AddressOf(&CRecompiler::CompileDelaySlot), "CRecompiler::CompileDelaySlot"); + JmpDirectReg(x86_EAX); + ExitCodeBlock(); + return; #endif - } + } - // Handle Perm Loop - if (CRecompilerOps::m_CompilePC == m_Jump.TargetPC && (m_Cont.FallThrough == false)) - { - if (!DelaySlotEffectsJump(CompilePC())) - { - MoveConstToVariable(CompilePC(), _PROGRAM_COUNTER, "PROGRAM_COUNTER"); - m_Jump.RegSet.WriteBackRegisters(); - UpdateCounters(m_Jump.RegSet, false, true); - Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); - MoveConstToX86reg((uint32_t)g_SystemTimer, x86_ECX); - Call_Direct(AddressOf(&CSystemTimer::TimerDone), "CSystemTimer::TimerDone"); - CPU_Message("CompileSystemCheck 3"); - CompileSystemCheck((uint32_t)-1, m_Jump.RegSet); - } - } - if (TargetSection[0] != TargetSection[1] || TargetSection[0] == NULL) - { - for (i = 0; i < 2; i++) - { - if (JumpInfo[i]->LinkLocation == NULL && JumpInfo[i]->FallThrough == false) - { - if (TargetSection[i]) - { - TargetSection[i]->UnlinkParent(this, i == 0); - TargetSection[i] = NULL; - } - } - else if (TargetSection[i] == NULL && JumpInfo[i]->FallThrough) - { - if (JumpInfo[i]->LinkLocation != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation = NULL; - if (JumpInfo[i]->LinkLocation2 != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation2 = NULL; - } - } - CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason, true, NULL); - JumpInfo[i]->FallThrough = false; - } - else if (TargetSection[i] != NULL && JumpInfo[i] != NULL) - { - if (!JumpInfo[i]->FallThrough) { continue; } - if (JumpInfo[i]->TargetPC == TargetSection[i]->m_EnterPC) { continue; } - if (JumpInfo[i]->LinkLocation != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation = NULL; - if (JumpInfo[i]->LinkLocation2 != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation2 = NULL; - } - } - CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason, true, NULL); - //FreeSection(TargetSection[i],Section); - } - } - } - else - { - if (m_Cont.LinkLocation == NULL && m_Cont.FallThrough == false) { m_ContinueSection = NULL; } - if (m_Jump.LinkLocation == NULL && m_Jump.FallThrough == false) { m_JumpSection = NULL; } - if (m_JumpSection == NULL && m_ContinueSection == NULL) - { - //FreeSection(TargetSection[0],Section); - } - } + // Handle Perm Loop + if (CRecompilerOps::m_CompilePC == m_Jump.TargetPC && (m_Cont.FallThrough == false)) + { + if (!DelaySlotEffectsJump(CompilePC())) + { + MoveConstToVariable(CompilePC(), _PROGRAM_COUNTER, "PROGRAM_COUNTER"); + m_Jump.RegSet.WriteBackRegisters(); + UpdateCounters(m_Jump.RegSet, false, true); + Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); + MoveConstToX86reg((uint32_t)g_SystemTimer, x86_ECX); + Call_Direct(AddressOf(&CSystemTimer::TimerDone), "CSystemTimer::TimerDone"); + CPU_Message("CompileSystemCheck 3"); + CompileSystemCheck((uint32_t)-1, m_Jump.RegSet); + } + } + if (TargetSection[0] != TargetSection[1] || TargetSection[0] == NULL) + { + for (i = 0; i < 2; i++) + { + if (JumpInfo[i]->LinkLocation == NULL && JumpInfo[i]->FallThrough == false) + { + if (TargetSection[i]) + { + TargetSection[i]->UnlinkParent(this, i == 0); + TargetSection[i] = NULL; + } + } + else if (TargetSection[i] == NULL && JumpInfo[i]->FallThrough) + { + if (JumpInfo[i]->LinkLocation != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation = NULL; + if (JumpInfo[i]->LinkLocation2 != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation2 = NULL; + } + } + CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason, true, NULL); + JumpInfo[i]->FallThrough = false; + } + else if (TargetSection[i] != NULL && JumpInfo[i] != NULL) + { + if (!JumpInfo[i]->FallThrough) { continue; } + if (JumpInfo[i]->TargetPC == TargetSection[i]->m_EnterPC) { continue; } + if (JumpInfo[i]->LinkLocation != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation = NULL; + if (JumpInfo[i]->LinkLocation2 != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation2 = NULL; + } + } + CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason, true, NULL); + //FreeSection(TargetSection[i],Section); + } + } + } + else + { + if (m_Cont.LinkLocation == NULL && m_Cont.FallThrough == false) { m_ContinueSection = NULL; } + if (m_Jump.LinkLocation == NULL && m_Jump.FallThrough == false) { m_JumpSection = NULL; } + if (m_JumpSection == NULL && m_ContinueSection == NULL) + { + //FreeSection(TargetSection[0],Section); + } + } - TargetSection[0] = m_ContinueSection; - TargetSection[1] = m_JumpSection; + TargetSection[0] = m_ContinueSection; + TargetSection[1] = m_JumpSection; - for (i = 0; i < 2; i++) { - if (TargetSection[i] == NULL) { continue; } - if (!JumpInfo[i]->FallThrough) { continue; } + for (i = 0; i < 2; i++) { + if (TargetSection[i] == NULL) { continue; } + if (!JumpInfo[i]->FallThrough) { continue; } - if (TargetSection[i]->m_CompiledLocation != NULL) - { - char Label[100]; - sprintf(Label, "Section_%d", TargetSection[i]->m_SectionID); - JumpInfo[i]->FallThrough = false; - if (JumpInfo[i]->LinkLocation != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation = NULL; - if (JumpInfo[i]->LinkLocation2 != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation2 = NULL; - } - } - if (JumpInfo[i]->TargetPC <= CompilePC()) - { - if (JumpInfo[i]->PermLoop) - { - CPU_Message("PermLoop *** 1"); - MoveConstToVariable(JumpInfo[i]->TargetPC, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); - UpdateCounters(JumpInfo[i]->RegSet, false, true); - if (g_SyncSystem) - { - MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } + if (TargetSection[i]->m_CompiledLocation != NULL) + { + char Label[100]; + sprintf(Label, "Section_%d", TargetSection[i]->m_SectionID); + JumpInfo[i]->FallThrough = false; + if (JumpInfo[i]->LinkLocation != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation = NULL; + if (JumpInfo[i]->LinkLocation2 != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation2 = NULL; + } + } + if (JumpInfo[i]->TargetPC <= CompilePC()) + { + if (JumpInfo[i]->PermLoop) + { + CPU_Message("PermLoop *** 1"); + MoveConstToVariable(JumpInfo[i]->TargetPC, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); + UpdateCounters(JumpInfo[i]->RegSet, false, true); + if (g_SyncSystem) + { + MoveConstToX86reg((uint32_t)g_BaseSystem, x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } - //JumpInfo[i]->RegSet.BlockCycleCount() -= g_System->CountPerOp(); - Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); - //JumpInfo[i]->RegSet.BlockCycleCount() += g_System->CountPerOp(); - UpdateCounters(JumpInfo[i]->RegSet, true, true); - CPU_Message("CompileSystemCheck 4"); - CompileSystemCheck((uint32_t)-1, JumpInfo[i]->RegSet); - } - else - { - UpdateCounters(JumpInfo[i]->RegSet, true, true); - CPU_Message("CompileSystemCheck 5"); - CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet); - } - } - else - { - UpdateCounters(JumpInfo[i]->RegSet, false, true); - } + //JumpInfo[i]->RegSet.BlockCycleCount() -= g_System->CountPerOp(); + Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); + //JumpInfo[i]->RegSet.BlockCycleCount() += g_System->CountPerOp(); + UpdateCounters(JumpInfo[i]->RegSet, true, true); + CPU_Message("CompileSystemCheck 4"); + CompileSystemCheck((uint32_t)-1, JumpInfo[i]->RegSet); + } + else + { + UpdateCounters(JumpInfo[i]->RegSet, true, true); + CPU_Message("CompileSystemCheck 5"); + CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet); + } + } + else + { + UpdateCounters(JumpInfo[i]->RegSet, false, true); + } - JumpInfo[i]->RegSet.SetBlockCycleCount(0); - m_RegWorkingSet = JumpInfo[i]->RegSet; - SyncRegState(TargetSection[i]->m_RegEnter); - JmpLabel32(Label, 0); - SetJump32((uint32_t *)m_RecompPos - 1, (uint32_t *)(TargetSection[i]->m_CompiledLocation)); - } - } + JumpInfo[i]->RegSet.SetBlockCycleCount(0); + m_RegWorkingSet = JumpInfo[i]->RegSet; + SyncRegState(TargetSection[i]->m_RegEnter); + JmpLabel32(Label, 0); + SetJump32((uint32_t *)m_RecompPos - 1, (uint32_t *)(TargetSection[i]->m_CompiledLocation)); + } + } - for (i = 0; i < 2; i++) - { - if (TargetSection[i] == NULL) { continue; } - if (TargetSection[i]->m_ParentSection.empty()) { continue; } - for (SECTION_LIST::iterator iter = TargetSection[i]->m_ParentSection.begin(); iter != TargetSection[i]->m_ParentSection.end(); iter++) - { - CCodeSection * Parent = *iter; + for (i = 0; i < 2; i++) + { + if (TargetSection[i] == NULL) { continue; } + if (TargetSection[i]->m_ParentSection.empty()) { continue; } + for (SECTION_LIST::iterator iter = TargetSection[i]->m_ParentSection.begin(); iter != TargetSection[i]->m_ParentSection.end(); iter++) + { + CCodeSection * Parent = *iter; - if (Parent->m_CompiledLocation != NULL) { continue; } - if (Parent->m_InLoop) { continue; } - if (JumpInfo[i]->PermLoop) - { - CPU_Message("PermLoop *** 2"); - MoveConstToVariable(JumpInfo[i]->TargetPC, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); - UpdateCounters(JumpInfo[i]->RegSet, false, true); - Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); - UpdateCounters(JumpInfo[i]->RegSet, true, true); - CPU_Message("CompileSystemCheck 6"); - CompileSystemCheck((uint32_t)-1, JumpInfo[i]->RegSet); - } - if (JumpInfo[i]->FallThrough) - { - JumpInfo[i]->FallThrough = false; - JmpLabel32(JumpInfo[i]->BranchLabel.c_str(), 0); - JumpInfo[i]->LinkLocation = (uint32_t*)(m_RecompPos - 4); - } - } - } + if (Parent->m_CompiledLocation != NULL) { continue; } + if (Parent->m_InLoop) { continue; } + if (JumpInfo[i]->PermLoop) + { + CPU_Message("PermLoop *** 2"); + MoveConstToVariable(JumpInfo[i]->TargetPC, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); + UpdateCounters(JumpInfo[i]->RegSet, false, true); + Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); + UpdateCounters(JumpInfo[i]->RegSet, true, true); + CPU_Message("CompileSystemCheck 6"); + CompileSystemCheck((uint32_t)-1, JumpInfo[i]->RegSet); + } + if (JumpInfo[i]->FallThrough) + { + JumpInfo[i]->FallThrough = false; + JmpLabel32(JumpInfo[i]->BranchLabel.c_str(), 0); + JumpInfo[i]->LinkLocation = (uint32_t*)(m_RecompPos - 4); + } + } + } - for (i = 0; i < 2; i++) - { - if (JumpInfo[i]->FallThrough) - { - if (JumpInfo[i]->TargetPC < CompilePC()) - { - UpdateCounters(JumpInfo[i]->RegSet, true, true); - CPU_Message("CompileSystemCheck 7"); - CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet); - } - } - } + for (i = 0; i < 2; i++) + { + if (JumpInfo[i]->FallThrough) + { + if (JumpInfo[i]->TargetPC < CompilePC()) + { + UpdateCounters(JumpInfo[i]->RegSet, true, true); + CPU_Message("CompileSystemCheck 7"); + CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet); + } + } + } - CPU_Message("====== End of Section %d ======", m_SectionID); + CPU_Message("====== End of Section %d ======", m_SectionID); - for (i = 0; i < 2; i++) - { - if (JumpInfo[i]->FallThrough && !TargetSection[i]->GenerateX86Code(m_BlockInfo->NextTest())) - { - JumpInfo[i]->FallThrough = false; - JmpLabel32(JumpInfo[i]->BranchLabel.c_str(), 0); - JumpInfo[i]->LinkLocation = (uint32_t *)(m_RecompPos - 4); - } - } + for (i = 0; i < 2; i++) + { + if (JumpInfo[i]->FallThrough && !TargetSection[i]->GenerateX86Code(m_BlockInfo->NextTest())) + { + JumpInfo[i]->FallThrough = false; + JmpLabel32(JumpInfo[i]->BranchLabel.c_str(), 0); + JumpInfo[i]->LinkLocation = (uint32_t *)(m_RecompPos - 4); + } + } - //CPU_Message("Section %d",m_SectionID); - for (i = 0; i < 2; i++) - { - if (JumpInfo[i]->LinkLocation == NULL) { continue; } - if (TargetSection[i] == NULL) - { - CPU_Message("ExitBlock (from %d):", m_SectionID); - SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation = NULL; - if (JumpInfo[i]->LinkLocation2 != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation2 = NULL; - } - CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason, true, NULL); - continue; - } - if (JumpInfo[i]->TargetPC != TargetSection[i]->m_EnterPC) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - if (TargetSection[i]->m_CompiledLocation == NULL) - { - TargetSection[i]->GenerateX86Code(m_BlockInfo->NextTest()); - } - else - { - stdstr_f Label("Section_%d (from %d):", TargetSection[i]->m_SectionID, m_SectionID); + //CPU_Message("Section %d",m_SectionID); + for (i = 0; i < 2; i++) + { + if (JumpInfo[i]->LinkLocation == NULL) { continue; } + if (TargetSection[i] == NULL) + { + CPU_Message("ExitBlock (from %d):", m_SectionID); + SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation = NULL; + if (JumpInfo[i]->LinkLocation2 != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation2 = NULL; + } + CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason, true, NULL); + continue; + } + if (JumpInfo[i]->TargetPC != TargetSection[i]->m_EnterPC) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + if (TargetSection[i]->m_CompiledLocation == NULL) + { + TargetSection[i]->GenerateX86Code(m_BlockInfo->NextTest()); + } + else + { + stdstr_f Label("Section_%d (from %d):", TargetSection[i]->m_SectionID, m_SectionID); - CPU_Message(Label.c_str()); - SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation = NULL; - if (JumpInfo[i]->LinkLocation2 != NULL) - { - SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); - JumpInfo[i]->LinkLocation2 = NULL; - } - m_RegWorkingSet = JumpInfo[i]->RegSet; - if (JumpInfo[i]->TargetPC <= JumpInfo[i]->JumpPC) - { - UpdateCounters(JumpInfo[i]->RegSet, true, true); - if (JumpInfo[i]->PermLoop) - { - CPU_Message("PermLoop *** 3"); - MoveConstToVariable(JumpInfo[i]->TargetPC, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); - Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); - CPU_Message("CompileSystemCheck 8"); - CompileSystemCheck((uint32_t)-1, JumpInfo[i]->RegSet); - } - else - { - CPU_Message("CompileSystemCheck 9"); - CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet); - } - } - else - { - UpdateCounters(m_RegWorkingSet, false, true); - } - m_RegWorkingSet = JumpInfo[i]->RegSet; - SyncRegState(TargetSection[i]->m_RegEnter); - JmpLabel32(Label.c_str(), 0); - SetJump32((uint32_t *)m_RecompPos - 1, (uint32_t *)(TargetSection[i]->m_CompiledLocation)); - } - } + CPU_Message(Label.c_str()); + SetJump32(JumpInfo[i]->LinkLocation, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation = NULL; + if (JumpInfo[i]->LinkLocation2 != NULL) + { + SetJump32(JumpInfo[i]->LinkLocation2, (uint32_t *)m_RecompPos); + JumpInfo[i]->LinkLocation2 = NULL; + } + m_RegWorkingSet = JumpInfo[i]->RegSet; + if (JumpInfo[i]->TargetPC <= JumpInfo[i]->JumpPC) + { + UpdateCounters(JumpInfo[i]->RegSet, true, true); + if (JumpInfo[i]->PermLoop) + { + CPU_Message("PermLoop *** 3"); + MoveConstToVariable(JumpInfo[i]->TargetPC, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); + Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); + CPU_Message("CompileSystemCheck 8"); + CompileSystemCheck((uint32_t)-1, JumpInfo[i]->RegSet); + } + else + { + CPU_Message("CompileSystemCheck 9"); + CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet); + } + } + else + { + UpdateCounters(m_RegWorkingSet, false, true); + } + m_RegWorkingSet = JumpInfo[i]->RegSet; + SyncRegState(TargetSection[i]->m_RegEnter); + JmpLabel32(Label.c_str(), 0); + SetJump32((uint32_t *)m_RecompPos - 1, (uint32_t *)(TargetSection[i]->m_CompiledLocation)); + } + } } void CCodeSection::SyncRegState(const CRegInfo & SyncTo) { - ResetX86Protection(); + ResetX86Protection(); - bool changed = false; - UnMap_AllFPRs(); - if (m_RegWorkingSet.GetRoundingModel() != SyncTo.GetRoundingModel()) { m_RegWorkingSet.SetRoundingModel(CRegInfo::RoundUnknown); } - x86Reg MemStackReg = Get_MemoryStack(); - x86Reg TargetStackReg = SyncTo.Get_MemoryStack(); + bool changed = false; + UnMap_AllFPRs(); + if (m_RegWorkingSet.GetRoundingModel() != SyncTo.GetRoundingModel()) { m_RegWorkingSet.SetRoundingModel(CRegInfo::RoundUnknown); } + x86Reg MemStackReg = Get_MemoryStack(); + x86Reg TargetStackReg = SyncTo.Get_MemoryStack(); - //CPU_Message("MemoryStack for Original State = %s",MemStackReg > 0?x86_Name(MemStackReg):"Not Mapped"); - if (MemStackReg != TargetStackReg) - { - if (TargetStackReg == x86_Unknown) - { - UnMap_X86reg(MemStackReg); - } - else if (MemStackReg == x86_Unknown) - { - UnMap_X86reg(TargetStackReg); - CPU_Message(" regcache: allocate %s as Memory Stack", x86_Name(TargetStackReg)); - m_RegWorkingSet.SetX86Mapped(TargetStackReg, CRegInfo::Stack_Mapped); - MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", TargetStackReg); - } - else - { - UnMap_X86reg(TargetStackReg); - CPU_Message(" regcache: change allocation of Memory Stack from %s to %s", x86_Name(MemStackReg), x86_Name(TargetStackReg)); - m_RegWorkingSet.SetX86Mapped(TargetStackReg, CRegInfo::Stack_Mapped); - m_RegWorkingSet.SetX86Mapped(MemStackReg, CRegInfo::NotMapped); - MoveX86RegToX86Reg(MemStackReg, TargetStackReg); - } - } + //CPU_Message("MemoryStack for Original State = %s",MemStackReg > 0?x86_Name(MemStackReg):"Not Mapped"); + if (MemStackReg != TargetStackReg) + { + if (TargetStackReg == x86_Unknown) + { + UnMap_X86reg(MemStackReg); + } + else if (MemStackReg == x86_Unknown) + { + UnMap_X86reg(TargetStackReg); + CPU_Message(" regcache: allocate %s as Memory Stack", x86_Name(TargetStackReg)); + m_RegWorkingSet.SetX86Mapped(TargetStackReg, CRegInfo::Stack_Mapped); + MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", TargetStackReg); + } + else + { + UnMap_X86reg(TargetStackReg); + CPU_Message(" regcache: change allocation of Memory Stack from %s to %s", x86_Name(MemStackReg), x86_Name(TargetStackReg)); + m_RegWorkingSet.SetX86Mapped(TargetStackReg, CRegInfo::Stack_Mapped); + m_RegWorkingSet.SetX86Mapped(MemStackReg, CRegInfo::NotMapped); + MoveX86RegToX86Reg(MemStackReg, TargetStackReg); + } + } - for (int i = 1; i < 32; i++) - { - if (GetMipsRegState(i) == SyncTo.GetMipsRegState(i) || - (g_System->b32BitCore() && GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_ZERO && SyncTo.GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_SIGN) || - (g_System->b32BitCore() && GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_SIGN && SyncTo.GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_ZERO)) - { - switch (GetMipsRegState(i)) { - case CRegInfo::STATE_UNKNOWN: continue; - case CRegInfo::STATE_MAPPED_64: - if (GetMipsRegMapHi(i) == SyncTo.GetMipsRegMapHi(i) && - GetMipsRegMapLo(i) == SyncTo.GetMipsRegMapLo(i)) - { - continue; - } - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - case CRegInfo::STATE_MAPPED_32_SIGN: - if (GetMipsRegMapLo(i) == SyncTo.GetMipsRegMapLo(i)) - { - continue; - } - break; - case CRegInfo::STATE_CONST_64: - if (GetMipsReg(i) != SyncTo.GetMipsReg(i)) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - continue; - case CRegInfo::STATE_CONST_32_SIGN: - if (GetMipsRegLo(i) != SyncTo.GetMipsRegLo(i)) - { - CPU_Message("Value of const is different Reg %d (%s) Value: 0x%08X to 0x%08X", i, CRegName::GPR[i], GetMipsRegLo(i), SyncTo.GetMipsRegLo(i)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - continue; - default: - CPU_Message("Unhandled Reg state %d\nin SyncRegState", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - } - changed = true; + for (int i = 1; i < 32; i++) + { + if (GetMipsRegState(i) == SyncTo.GetMipsRegState(i) || + (g_System->b32BitCore() && GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_ZERO && SyncTo.GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_SIGN) || + (g_System->b32BitCore() && GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_SIGN && SyncTo.GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_ZERO)) + { + switch (GetMipsRegState(i)) { + case CRegInfo::STATE_UNKNOWN: continue; + case CRegInfo::STATE_MAPPED_64: + if (GetMipsRegMapHi(i) == SyncTo.GetMipsRegMapHi(i) && + GetMipsRegMapLo(i) == SyncTo.GetMipsRegMapLo(i)) + { + continue; + } + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + case CRegInfo::STATE_MAPPED_32_SIGN: + if (GetMipsRegMapLo(i) == SyncTo.GetMipsRegMapLo(i)) + { + continue; + } + break; + case CRegInfo::STATE_CONST_64: + if (GetMipsReg(i) != SyncTo.GetMipsReg(i)) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + continue; + case CRegInfo::STATE_CONST_32_SIGN: + if (GetMipsRegLo(i) != SyncTo.GetMipsRegLo(i)) + { + CPU_Message("Value of const is different Reg %d (%s) Value: 0x%08X to 0x%08X", i, CRegName::GPR[i], GetMipsRegLo(i), SyncTo.GetMipsRegLo(i)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + continue; + default: + CPU_Message("Unhandled Reg state %d\nin SyncRegState", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + } + changed = true; - switch (SyncTo.GetMipsRegState(i)) - { - case CRegInfo::STATE_UNKNOWN: UnMap_GPR(i, true); break; - case CRegInfo::STATE_MAPPED_64: - { - x86Reg Reg = SyncTo.GetMipsRegMapLo(i); - x86Reg x86RegHi = SyncTo.GetMipsRegMapHi(i); - UnMap_X86reg(Reg); - UnMap_X86reg(x86RegHi); - switch (GetMipsRegState(i)) - { - case CRegInfo::STATE_UNKNOWN: - MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); - MoveVariableToX86reg(&_GPR[i].UW[1], CRegName::GPR_Hi[i], x86RegHi); - break; - case CRegInfo::STATE_MAPPED_64: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - MoveX86RegToX86Reg(GetMipsRegMapHi(i), x86RegHi); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapHi(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_MAPPED_32_SIGN: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), x86RegHi); - ShiftRightSignImmed(x86RegHi, 31); - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - XorX86RegToX86Reg(x86RegHi, x86RegHi); - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_CONST_64: - MoveConstToX86reg(GetMipsRegHi(i), x86RegHi); - MoveConstToX86reg(GetMipsRegLo(i), Reg); - break; - case CRegInfo::STATE_CONST_32_SIGN: - MoveConstToX86reg(GetMipsRegLo_S(i) >> 31, x86RegHi); - MoveConstToX86reg(GetMipsRegLo(i), Reg); - break; - default: - CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_64\n%d", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - continue; - } - m_RegWorkingSet.SetMipsRegMapLo(i, Reg); - m_RegWorkingSet.SetMipsRegMapHi(i, x86RegHi); - m_RegWorkingSet.SetMipsRegState(i, CRegInfo::STATE_MAPPED_64); - m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); - m_RegWorkingSet.SetX86Mapped(x86RegHi, CRegInfo::GPR_Mapped); - m_RegWorkingSet.SetX86MapOrder(Reg, 1); - m_RegWorkingSet.SetX86MapOrder(x86RegHi, 1); - } - break; - case CRegInfo::STATE_MAPPED_32_SIGN: - { - x86Reg Reg = SyncTo.GetMipsRegMapLo(i); - UnMap_X86reg(Reg); - switch (GetMipsRegState(i)) - { - case CRegInfo::STATE_UNKNOWN: MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); break; - case CRegInfo::STATE_CONST_32_SIGN: MoveConstToX86reg(GetMipsRegLo(i), Reg); break; - case CRegInfo::STATE_MAPPED_32_SIGN: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - if (GetMipsRegMapLo(i) != Reg) - { - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - } - break; - case CRegInfo::STATE_MAPPED_64: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapHi(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_CONST_64: - CPU_Message("hi %X\nLo %X", GetMipsRegHi(i), GetMipsRegLo(i)); - default: - CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_SIGN\n%d", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - m_RegWorkingSet.SetMipsRegMapLo(i, Reg); - m_RegWorkingSet.SetMipsRegState(i, CRegInfo::STATE_MAPPED_32_SIGN); - m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); - m_RegWorkingSet.SetX86MapOrder(Reg, 1); - } - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - { - x86Reg Reg = SyncTo.GetMipsRegMapLo(i); - UnMap_X86reg(Reg); - switch (GetMipsRegState(i)) - { - case CRegInfo::STATE_MAPPED_64: - case CRegInfo::STATE_UNKNOWN: - MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_MAPPED_32_SIGN: - if (g_System->b32BitCore()) - { - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - } - else - { - CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - break; - case CRegInfo::STATE_CONST_32_SIGN: - if (!g_System->b32BitCore() && GetMipsRegLo_S(i) < 0) - { - CPU_Message("Sign Problems in SyncRegState\nSTATE_MAPPED_32_ZERO"); - CPU_Message("%s: %X", CRegName::GPR[i], GetMipsRegLo_S(i)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - MoveConstToX86reg(GetMipsRegLo(i), Reg); - break; - default: - CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - m_RegWorkingSet.SetMipsRegMapLo(i, Reg); - m_RegWorkingSet.SetMipsRegState(i, SyncTo.GetMipsRegState(i)); - m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); - m_RegWorkingSet.SetX86MapOrder(Reg, 1); - } - break; - default: - CPU_Message("%d - %d reg: %s (%d)", SyncTo.GetMipsRegState(i), GetMipsRegState(i), CRegName::GPR[i], i); - g_Notify->BreakPoint(__FILEW__, __LINE__); - changed = false; - } - } + switch (SyncTo.GetMipsRegState(i)) + { + case CRegInfo::STATE_UNKNOWN: UnMap_GPR(i, true); break; + case CRegInfo::STATE_MAPPED_64: + { + x86Reg Reg = SyncTo.GetMipsRegMapLo(i); + x86Reg x86RegHi = SyncTo.GetMipsRegMapHi(i); + UnMap_X86reg(Reg); + UnMap_X86reg(x86RegHi); + switch (GetMipsRegState(i)) + { + case CRegInfo::STATE_UNKNOWN: + MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); + MoveVariableToX86reg(&_GPR[i].UW[1], CRegName::GPR_Hi[i], x86RegHi); + break; + case CRegInfo::STATE_MAPPED_64: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + MoveX86RegToX86Reg(GetMipsRegMapHi(i), x86RegHi); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapHi(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_MAPPED_32_SIGN: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), x86RegHi); + ShiftRightSignImmed(x86RegHi, 31); + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + XorX86RegToX86Reg(x86RegHi, x86RegHi); + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_CONST_64: + MoveConstToX86reg(GetMipsRegHi(i), x86RegHi); + MoveConstToX86reg(GetMipsRegLo(i), Reg); + break; + case CRegInfo::STATE_CONST_32_SIGN: + MoveConstToX86reg(GetMipsRegLo_S(i) >> 31, x86RegHi); + MoveConstToX86reg(GetMipsRegLo(i), Reg); + break; + default: + CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_64\n%d", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + continue; + } + m_RegWorkingSet.SetMipsRegMapLo(i, Reg); + m_RegWorkingSet.SetMipsRegMapHi(i, x86RegHi); + m_RegWorkingSet.SetMipsRegState(i, CRegInfo::STATE_MAPPED_64); + m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); + m_RegWorkingSet.SetX86Mapped(x86RegHi, CRegInfo::GPR_Mapped); + m_RegWorkingSet.SetX86MapOrder(Reg, 1); + m_RegWorkingSet.SetX86MapOrder(x86RegHi, 1); + } + break; + case CRegInfo::STATE_MAPPED_32_SIGN: + { + x86Reg Reg = SyncTo.GetMipsRegMapLo(i); + UnMap_X86reg(Reg); + switch (GetMipsRegState(i)) + { + case CRegInfo::STATE_UNKNOWN: MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); break; + case CRegInfo::STATE_CONST_32_SIGN: MoveConstToX86reg(GetMipsRegLo(i), Reg); break; + case CRegInfo::STATE_MAPPED_32_SIGN: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + if (GetMipsRegMapLo(i) != Reg) + { + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + } + break; + case CRegInfo::STATE_MAPPED_64: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapHi(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_CONST_64: + CPU_Message("hi %X\nLo %X", GetMipsRegHi(i), GetMipsRegLo(i)); + default: + CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_SIGN\n%d", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + m_RegWorkingSet.SetMipsRegMapLo(i, Reg); + m_RegWorkingSet.SetMipsRegState(i, CRegInfo::STATE_MAPPED_32_SIGN); + m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); + m_RegWorkingSet.SetX86MapOrder(Reg, 1); + } + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + { + x86Reg Reg = SyncTo.GetMipsRegMapLo(i); + UnMap_X86reg(Reg); + switch (GetMipsRegState(i)) + { + case CRegInfo::STATE_MAPPED_64: + case CRegInfo::STATE_UNKNOWN: + MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_MAPPED_32_SIGN: + if (g_System->b32BitCore()) + { + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + } + else + { + CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + break; + case CRegInfo::STATE_CONST_32_SIGN: + if (!g_System->b32BitCore() && GetMipsRegLo_S(i) < 0) + { + CPU_Message("Sign Problems in SyncRegState\nSTATE_MAPPED_32_ZERO"); + CPU_Message("%s: %X", CRegName::GPR[i], GetMipsRegLo_S(i)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + MoveConstToX86reg(GetMipsRegLo(i), Reg); + break; + default: + CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + m_RegWorkingSet.SetMipsRegMapLo(i, Reg); + m_RegWorkingSet.SetMipsRegState(i, SyncTo.GetMipsRegState(i)); + m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); + m_RegWorkingSet.SetX86MapOrder(Reg, 1); + } + break; + default: + CPU_Message("%d - %d reg: %s (%d)", SyncTo.GetMipsRegState(i), GetMipsRegState(i), CRegName::GPR[i], i); + g_Notify->BreakPoint(__FILEW__, __LINE__); + changed = false; + } + } } void CCodeSection::SetDelaySlot() { - m_DelaySlot = true; + m_DelaySlot = true; } void CCodeSection::SetJumpAddress(uint32_t JumpPC, uint32_t TargetPC, bool PermLoop) { - m_Jump.JumpPC = JumpPC; - m_Jump.TargetPC = TargetPC; - m_Jump.BranchLabel.Format("0x%08X", TargetPC); - m_Jump.PermLoop = PermLoop; + m_Jump.JumpPC = JumpPC; + m_Jump.TargetPC = TargetPC; + m_Jump.BranchLabel.Format("0x%08X", TargetPC); + m_Jump.PermLoop = PermLoop; } void CCodeSection::SetContinueAddress(uint32_t JumpPC, uint32_t TargetPC) { - m_Cont.JumpPC = JumpPC; - m_Cont.TargetPC = TargetPC; - m_Cont.BranchLabel.Format("0x%08X", TargetPC); + m_Cont.JumpPC = JumpPC; + m_Cont.TargetPC = TargetPC; + m_Cont.BranchLabel.Format("0x%08X", TargetPC); } void CCodeSection::CompileCop1Test() { - if (m_RegWorkingSet.FpuBeenUsed()) - return; + if (m_RegWorkingSet.FpuBeenUsed()) + return; - TestVariable(STATUS_CU1, &g_Reg->STATUS_REGISTER, "STATUS_REGISTER"); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::COP1_Unuseable, false, JeLabel32); - m_RegWorkingSet.FpuBeenUsed() = true; + TestVariable(STATUS_CU1, &g_Reg->STATUS_REGISTER, "STATUS_REGISTER"); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::COP1_Unuseable, false, JeLabel32); + m_RegWorkingSet.FpuBeenUsed() = true; } bool CCodeSection::ParentContinue() { - if (m_ParentSection.size() > 0) - { - for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) - { - CCodeSection * Parent = *iter; - if (Parent->m_CompiledLocation != NULL) { continue; } - if (IsAllParentLoops(Parent, true, m_BlockInfo->NextTest())) { continue; } - return false; - } - if (!InheritParentInfo()) - { - return false; - } - } - return true; + if (m_ParentSection.size() > 0) + { + for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) + { + CCodeSection * Parent = *iter; + if (Parent->m_CompiledLocation != NULL) { continue; } + if (IsAllParentLoops(Parent, true, m_BlockInfo->NextTest())) { continue; } + return false; + } + if (!InheritParentInfo()) + { + return false; + } + } + return true; } /*int TestValue = 0; @@ -989,1280 +989,1280 @@ g_Notify->BreakPoint(__FILEW__,__LINE__); bool CCodeSection::GenerateX86Code(uint32_t Test) { - if (this == NULL) { return false; } + if (this == NULL) { return false; } - if (m_CompiledLocation != NULL) - { - if (m_Test == Test) - { - return false; - } - m_Test = Test; - if (m_ContinueSection->GenerateX86Code(Test)) { return true; } - if (m_JumpSection->GenerateX86Code(Test)) { return true; } - return false; - } + if (m_CompiledLocation != NULL) + { + if (m_Test == Test) + { + return false; + } + m_Test = Test; + if (m_ContinueSection->GenerateX86Code(Test)) { return true; } + if (m_JumpSection->GenerateX86Code(Test)) { return true; } + return false; + } - if (!ParentContinue()) - { - return false; - } - m_CompiledLocation = m_RecompPos; - m_RegWorkingSet = m_RegEnter; - m_CompilePC = m_EnterPC; - m_NextInstruction = m_DelaySlot ? JUMP : NORMAL; - m_Section = this; + if (!ParentContinue()) + { + return false; + } + m_CompiledLocation = m_RecompPos; + m_RegWorkingSet = m_RegEnter; + m_CompilePC = m_EnterPC; + m_NextInstruction = m_DelaySlot ? JUMP : NORMAL; + m_Section = this; - if (m_CompilePC < m_BlockInfo->VAddrFirst()) - { - m_BlockInfo->SetVAddrFirst(m_CompilePC); - } + if (m_CompilePC < m_BlockInfo->VAddrFirst()) + { + m_BlockInfo->SetVAddrFirst(m_CompilePC); + } - uint32_t ContinueSectionPC = m_ContinueSection ? m_ContinueSection->m_EnterPC : (uint32_t)-1; + uint32_t ContinueSectionPC = m_ContinueSection ? m_ContinueSection->m_EnterPC : (uint32_t)-1; - do - { - __try - { - if (!g_MMU->LW_VAddr(m_CompilePC, m_Opcode.Hex)) - { - g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD)); - } - } - __except (g_MMU->MemoryFilter(GetExceptionCode(), GetExceptionInformation())) - { - g_Notify->FatalError(GS(MSG_UNKNOWN_MEM_ACTION)); - } + do + { + __try + { + if (!g_MMU->LW_VAddr(m_CompilePC, m_Opcode.Hex)) + { + g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD)); + } + } + __except (g_MMU->MemoryFilter(GetExceptionCode(), GetExceptionInformation())) + { + g_Notify->FatalError(GS(MSG_UNKNOWN_MEM_ACTION)); + } - if (m_CompilePC > m_BlockInfo->VAddrLast()) - { - m_BlockInfo->SetVAddrLast(m_CompilePC); - } - /*if (m_CompilePC == 0x803245C4) - { - X86BreakPoint(__FILEW__,__LINE__); - //m_RegWorkingSet.UnMap_AllFPRs(); - }*/ + if (m_CompilePC > m_BlockInfo->VAddrLast()) + { + m_BlockInfo->SetVAddrLast(m_CompilePC); + } + /*if (m_CompilePC == 0x803245C4) + { + X86BreakPoint(__FILEW__,__LINE__); + //m_RegWorkingSet.UnMap_AllFPRs(); + }*/ - /*if (m_CompilePC >= 0x80000000 && m_CompilePC <= 0x80400000 && m_NextInstruction == NORMAL) - { - m_RegWorkingSet.WriteBackRegisters(); - UpdateCounters(m_RegWorkingSet,false,true); - MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); - if (g_SyncSystem) { - MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - }*/ + /*if (m_CompilePC >= 0x80000000 && m_CompilePC <= 0x80400000 && m_NextInstruction == NORMAL) + { + m_RegWorkingSet.WriteBackRegisters(); + UpdateCounters(m_RegWorkingSet,false,true); + MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); + if (g_SyncSystem) { + MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + }*/ - /*if ((m_CompilePC == 0x8031C0E4 || m_CompilePC == 0x8031C118 || - m_CompilePC == 0x8031CD88 || m_CompilePC == 0x8031CE24 || - m_CompilePC == 0x8031CE30 || m_CompilePC == 0x8031CE40) && m_NextInstruction == NORMAL) - { - m_RegWorkingSet.WriteBackRegisters(); - UpdateCounters(m_RegWorkingSet,false,true); - MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); - if (g_SyncSystem) { - MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - }*/ + /*if ((m_CompilePC == 0x8031C0E4 || m_CompilePC == 0x8031C118 || + m_CompilePC == 0x8031CD88 || m_CompilePC == 0x8031CE24 || + m_CompilePC == 0x8031CE30 || m_CompilePC == 0x8031CE40) && m_NextInstruction == NORMAL) + { + m_RegWorkingSet.WriteBackRegisters(); + UpdateCounters(m_RegWorkingSet,false,true); + MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); + if (g_SyncSystem) { + MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + }*/ - /*if (m_CompilePC == 0x801C1B88) - { - BeforeCallDirect(m_RegWorkingSet); - Call_Direct(AddressOf(TestFunc), "TestFunc"); - AfterCallDirect(m_RegWorkingSet); - }*/ + /*if (m_CompilePC == 0x801C1B88) + { + BeforeCallDirect(m_RegWorkingSet); + Call_Direct(AddressOf(TestFunc), "TestFunc"); + AfterCallDirect(m_RegWorkingSet); + }*/ - /*if (m_CompilePC >= 0x801C1AF8 && m_CompilePC <= 0x801C1C00 && m_NextInstruction == NORMAL) - { - UpdateCounters(m_RegWorkingSet,false,true); - MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); - if (g_SyncSystem) { - BeforeCallDirect(m_RegWorkingSet); - MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystemPC), "CN64System::SyncSystemPC"); - AfterCallDirect(m_RegWorkingSet); - } - }*/ + /*if (m_CompilePC >= 0x801C1AF8 && m_CompilePC <= 0x801C1C00 && m_NextInstruction == NORMAL) + { + UpdateCounters(m_RegWorkingSet,false,true); + MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); + if (g_SyncSystem) { + BeforeCallDirect(m_RegWorkingSet); + MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystemPC), "CN64System::SyncSystemPC"); + AfterCallDirect(m_RegWorkingSet); + } + }*/ - /*if ((m_CompilePC == 0x80263900) && m_NextInstruction == NORMAL) - { - X86BreakPoint(__FILEW__,__LINE__); - }*/ + /*if ((m_CompilePC == 0x80263900) && m_NextInstruction == NORMAL) + { + X86BreakPoint(__FILEW__,__LINE__); + }*/ - /*if ((m_CompilePC >= 0x80325D80 && m_CompilePC <= 0x80325DF0) && m_NextInstruction == NORMAL) - { - m_RegWorkingSet.WriteBackRegisters(); - UpdateCounters(m_RegWorkingSet,false,true); - MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); - if (g_SyncSystem) { - MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - }*/ - /*if ((m_CompilePC == 0x80324E14) && m_NextInstruction == NORMAL) - { - X86BreakPoint(__FILEW__,__LINE__); - }*/ + /*if ((m_CompilePC >= 0x80325D80 && m_CompilePC <= 0x80325DF0) && m_NextInstruction == NORMAL) + { + m_RegWorkingSet.WriteBackRegisters(); + UpdateCounters(m_RegWorkingSet,false,true); + MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); + if (g_SyncSystem) { + MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + }*/ + /*if ((m_CompilePC == 0x80324E14) && m_NextInstruction == NORMAL) + { + X86BreakPoint(__FILEW__,__LINE__); + }*/ - /*if (m_CompilePC == 0x80324E18 && m_NextInstruction == NORMAL) - { - m_RegWorkingSet.WriteBackRegisters(); - UpdateCounters(m_RegWorkingSet,false,true); - MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); - if (g_SyncSystem) { - MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - }*/ - /*if (m_CompilePC >= 0x80324E00 && m_CompilePC <= 0x80324E18 && m_NextInstruction == NORMAL) - { - m_RegWorkingSet.WriteBackRegisters(); - UpdateCounters(m_RegWorkingSet,false,true); - MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); - if (g_SyncSystem) { - MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); - Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); - } - }*/ - /* if (m_CompilePC == 0x803245CC && m_NextInstruction == NORMAL) - { - //m_RegWorkingSet.UnMap_AllFPRs(); - g_Notify->BreakPoint(__FILEW__,__LINE__); - //X86HardBreakPoint(); - //X86BreakPoint(__FILEW__,__LINE__); - //m_RegWorkingSet.UnMap_AllFPRs(); - }*/ - /*if (m_CompilePC >= 0x80179DC4 && m_CompilePC <= 0x80179DF0 && m_NextInstruction == NORMAL) - { - m_RegWorkingSet.UnMap_AllFPRs(); - }*/ + /*if (m_CompilePC == 0x80324E18 && m_NextInstruction == NORMAL) + { + m_RegWorkingSet.WriteBackRegisters(); + UpdateCounters(m_RegWorkingSet,false,true); + MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); + if (g_SyncSystem) { + MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + }*/ + /*if (m_CompilePC >= 0x80324E00 && m_CompilePC <= 0x80324E18 && m_NextInstruction == NORMAL) + { + m_RegWorkingSet.WriteBackRegisters(); + UpdateCounters(m_RegWorkingSet,false,true); + MoveConstToVariable(m_CompilePC,&g_Reg->m_PROGRAM_COUNTER,"PROGRAM_COUNTER"); + if (g_SyncSystem) { + MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); + Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + } + }*/ + /* if (m_CompilePC == 0x803245CC && m_NextInstruction == NORMAL) + { + //m_RegWorkingSet.UnMap_AllFPRs(); + g_Notify->BreakPoint(__FILEW__,__LINE__); + //X86HardBreakPoint(); + //X86BreakPoint(__FILEW__,__LINE__); + //m_RegWorkingSet.UnMap_AllFPRs(); + }*/ + /*if (m_CompilePC >= 0x80179DC4 && m_CompilePC <= 0x80179DF0 && m_NextInstruction == NORMAL) + { + m_RegWorkingSet.UnMap_AllFPRs(); + }*/ - m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - m_RegWorkingSet.ResetX86Protection(); + m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); + m_RegWorkingSet.ResetX86Protection(); - switch (m_Opcode.op) - { - case R4300i_SPECIAL: - switch (m_Opcode.funct) - { - case R4300i_SPECIAL_SLL: SPECIAL_SLL(); break; - case R4300i_SPECIAL_SRL: SPECIAL_SRL(); break; - case R4300i_SPECIAL_SRA: SPECIAL_SRA(); break; - case R4300i_SPECIAL_SLLV: SPECIAL_SLLV(); break; - case R4300i_SPECIAL_SRLV: SPECIAL_SRLV(); break; - case R4300i_SPECIAL_SRAV: SPECIAL_SRAV(); break; - case R4300i_SPECIAL_JR: SPECIAL_JR(); break; - case R4300i_SPECIAL_JALR: SPECIAL_JALR(); break; - case R4300i_SPECIAL_MFLO: SPECIAL_MFLO(); break; - case R4300i_SPECIAL_SYSCALL: SPECIAL_SYSCALL(); break; - case R4300i_SPECIAL_MTLO: SPECIAL_MTLO(); break; - case R4300i_SPECIAL_MFHI: SPECIAL_MFHI(); break; - case R4300i_SPECIAL_MTHI: SPECIAL_MTHI(); break; - case R4300i_SPECIAL_DSLLV: SPECIAL_DSLLV(); break; - case R4300i_SPECIAL_DSRLV: SPECIAL_DSRLV(); break; - case R4300i_SPECIAL_DSRAV: SPECIAL_DSRAV(); break; - case R4300i_SPECIAL_MULT: SPECIAL_MULT(); break; - case R4300i_SPECIAL_DIV: SPECIAL_DIV(); break; - case R4300i_SPECIAL_DIVU: SPECIAL_DIVU(); break; - case R4300i_SPECIAL_MULTU: SPECIAL_MULTU(); break; - case R4300i_SPECIAL_DMULT: SPECIAL_DMULT(); break; - case R4300i_SPECIAL_DMULTU: SPECIAL_DMULTU(); break; - case R4300i_SPECIAL_DDIV: SPECIAL_DDIV(); break; - case R4300i_SPECIAL_DDIVU: SPECIAL_DDIVU(); break; - case R4300i_SPECIAL_ADD: SPECIAL_ADD(); break; - case R4300i_SPECIAL_ADDU: SPECIAL_ADDU(); break; - case R4300i_SPECIAL_SUB: SPECIAL_SUB(); break; - case R4300i_SPECIAL_SUBU: SPECIAL_SUBU(); break; - case R4300i_SPECIAL_AND: SPECIAL_AND(); break; - case R4300i_SPECIAL_OR: SPECIAL_OR(); break; - case R4300i_SPECIAL_XOR: SPECIAL_XOR(); break; - case R4300i_SPECIAL_NOR: SPECIAL_NOR(); break; - case R4300i_SPECIAL_SLT: SPECIAL_SLT(); break; - case R4300i_SPECIAL_SLTU: SPECIAL_SLTU(); break; - case R4300i_SPECIAL_DADD: SPECIAL_DADD(); break; - case R4300i_SPECIAL_DADDU: SPECIAL_DADDU(); break; - case R4300i_SPECIAL_DSUB: SPECIAL_DSUB(); break; - case R4300i_SPECIAL_DSUBU: SPECIAL_DSUBU(); break; - case R4300i_SPECIAL_DSLL: SPECIAL_DSLL(); break; - case R4300i_SPECIAL_DSRL: SPECIAL_DSRL(); break; - case R4300i_SPECIAL_DSRA: SPECIAL_DSRA(); break; - case R4300i_SPECIAL_DSLL32: SPECIAL_DSLL32(); break; - case R4300i_SPECIAL_DSRL32: SPECIAL_DSRL32(); break; - case R4300i_SPECIAL_DSRA32: SPECIAL_DSRA32(); break; - default: - UnknownOpcode(); break; - } - break; - case R4300i_REGIMM: - switch (m_Opcode.rt) - { - case R4300i_REGIMM_BLTZ:Compile_Branch(BLTZ_Compare, BranchTypeRs, false); break; - case R4300i_REGIMM_BGEZ:Compile_Branch(BGEZ_Compare, BranchTypeRs, false); break; - case R4300i_REGIMM_BLTZL:Compile_BranchLikely(BLTZ_Compare, false); break; - case R4300i_REGIMM_BGEZL:Compile_BranchLikely(BGEZ_Compare, false); break; - case R4300i_REGIMM_BLTZAL:Compile_Branch(BLTZ_Compare, BranchTypeRs, true); break; - case R4300i_REGIMM_BGEZAL:Compile_Branch(BGEZ_Compare, BranchTypeRs, true); break; - default: - UnknownOpcode(); break; - } - break; - case R4300i_BEQ: Compile_Branch(BEQ_Compare, BranchTypeRsRt, false); break; - case R4300i_BNE: Compile_Branch(BNE_Compare, BranchTypeRsRt, false); break; - case R4300i_BGTZ:Compile_Branch(BGTZ_Compare, BranchTypeRs, false); break; - case R4300i_BLEZ:Compile_Branch(BLEZ_Compare, BranchTypeRs, false); break; - case R4300i_J: J(); break; - case R4300i_JAL: JAL(); break; - case R4300i_ADDI: ADDI(); break; - case R4300i_ADDIU: ADDIU(); break; - case R4300i_SLTI: SLTI(); break; - case R4300i_SLTIU: SLTIU(); break; - case R4300i_ANDI: ANDI(); break; - case R4300i_ORI: ORI(); break; - case R4300i_XORI: XORI(); break; - case R4300i_LUI: LUI(); break; - case R4300i_CP0: - switch (m_Opcode.rs) - { - case R4300i_COP0_MF: COP0_MF(); break; - case R4300i_COP0_MT: COP0_MT(); break; - default: - if ((m_Opcode.rs & 0x10) != 0) - { - switch (m_Opcode.funct) - { - case R4300i_COP0_CO_TLBR: COP0_CO_TLBR(); break; - case R4300i_COP0_CO_TLBWI: COP0_CO_TLBWI(); break; - case R4300i_COP0_CO_TLBWR: COP0_CO_TLBWR(); break; - case R4300i_COP0_CO_TLBP: COP0_CO_TLBP(); break; - case R4300i_COP0_CO_ERET: COP0_CO_ERET(); break; - default: UnknownOpcode(); break; - } - } - else - { - UnknownOpcode(); - } - } - break; - case R4300i_CP1: - switch (m_Opcode.rs) - { - case R4300i_COP1_MF: COP1_MF(); break; - case R4300i_COP1_DMF: COP1_DMF(); break; - case R4300i_COP1_CF: COP1_CF(); break; - case R4300i_COP1_MT: COP1_MT(); break; - case R4300i_COP1_DMT: COP1_DMT(); break; - case R4300i_COP1_CT: COP1_CT(); break; - case R4300i_COP1_BC: - switch (m_Opcode.ft) - { - case R4300i_COP1_BC_BCF: Compile_Branch(COP1_BCF_Compare, BranchTypeCop1, false); break; - case R4300i_COP1_BC_BCT: Compile_Branch(COP1_BCT_Compare, BranchTypeCop1, false); break; - case R4300i_COP1_BC_BCFL: Compile_BranchLikely(COP1_BCF_Compare, false); break; - case R4300i_COP1_BC_BCTL: Compile_BranchLikely(COP1_BCT_Compare, false); break; - default: - UnknownOpcode(); break; - } - break; - case R4300i_COP1_S: - switch (m_Opcode.funct) - { - case R4300i_COP1_FUNCT_ADD: COP1_S_ADD(); break; - case R4300i_COP1_FUNCT_SUB: COP1_S_SUB(); break; - case R4300i_COP1_FUNCT_MUL: COP1_S_MUL(); break; - case R4300i_COP1_FUNCT_DIV: COP1_S_DIV(); break; - case R4300i_COP1_FUNCT_ABS: COP1_S_ABS(); break; - case R4300i_COP1_FUNCT_NEG: COP1_S_NEG(); break; - case R4300i_COP1_FUNCT_SQRT: COP1_S_SQRT(); break; - case R4300i_COP1_FUNCT_MOV: COP1_S_MOV(); break; - case R4300i_COP1_FUNCT_TRUNC_L: COP1_S_TRUNC_L(); break; - case R4300i_COP1_FUNCT_CEIL_L: COP1_S_CEIL_L(); break; //added by Witten - case R4300i_COP1_FUNCT_FLOOR_L: COP1_S_FLOOR_L(); break; //added by Witten - case R4300i_COP1_FUNCT_ROUND_W: COP1_S_ROUND_W(); break; - case R4300i_COP1_FUNCT_TRUNC_W: COP1_S_TRUNC_W(); break; - case R4300i_COP1_FUNCT_CEIL_W: COP1_S_CEIL_W(); break; //added by Witten - case R4300i_COP1_FUNCT_FLOOR_W: COP1_S_FLOOR_W(); break; - case R4300i_COP1_FUNCT_CVT_D: COP1_S_CVT_D(); break; - case R4300i_COP1_FUNCT_CVT_W: COP1_S_CVT_W(); break; - case R4300i_COP1_FUNCT_CVT_L: COP1_S_CVT_L(); break; - case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: - case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: - case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: - case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: - case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: - case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: - case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: - case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: - COP1_S_CMP(); break; - default: - UnknownOpcode(); break; - } - break; - case R4300i_COP1_D: - switch (m_Opcode.funct) - { - case R4300i_COP1_FUNCT_ADD: COP1_D_ADD(); break; - case R4300i_COP1_FUNCT_SUB: COP1_D_SUB(); break; - case R4300i_COP1_FUNCT_MUL: COP1_D_MUL(); break; - case R4300i_COP1_FUNCT_DIV: COP1_D_DIV(); break; - case R4300i_COP1_FUNCT_ABS: COP1_D_ABS(); break; - case R4300i_COP1_FUNCT_NEG: COP1_D_NEG(); break; - case R4300i_COP1_FUNCT_SQRT: COP1_D_SQRT(); break; - case R4300i_COP1_FUNCT_MOV: COP1_D_MOV(); break; - case R4300i_COP1_FUNCT_TRUNC_L: COP1_D_TRUNC_L(); break; //added by Witten - case R4300i_COP1_FUNCT_CEIL_L: COP1_D_CEIL_L(); break; //added by Witten - case R4300i_COP1_FUNCT_FLOOR_L: COP1_D_FLOOR_L(); break; //added by Witten - case R4300i_COP1_FUNCT_ROUND_W: COP1_D_ROUND_W(); break; - case R4300i_COP1_FUNCT_TRUNC_W: COP1_D_TRUNC_W(); break; - case R4300i_COP1_FUNCT_CEIL_W: COP1_D_CEIL_W(); break; //added by Witten - case R4300i_COP1_FUNCT_FLOOR_W: COP1_D_FLOOR_W(); break; //added by Witten - case R4300i_COP1_FUNCT_CVT_S: COP1_D_CVT_S(); break; - case R4300i_COP1_FUNCT_CVT_W: COP1_D_CVT_W(); break; - case R4300i_COP1_FUNCT_CVT_L: COP1_D_CVT_L(); break; - case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: - case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: - case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: - case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: - case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: - case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: - case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: - case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: - COP1_D_CMP(); break; - default: - UnknownOpcode(); break; - } - break; - case R4300i_COP1_W: - switch (m_Opcode.funct) - { - case R4300i_COP1_FUNCT_CVT_S: COP1_W_CVT_S(); break; - case R4300i_COP1_FUNCT_CVT_D: COP1_W_CVT_D(); break; - default: - UnknownOpcode(); break; - } - break; - case R4300i_COP1_L: - switch (m_Opcode.funct) - { - case R4300i_COP1_FUNCT_CVT_S: COP1_L_CVT_S(); break; - case R4300i_COP1_FUNCT_CVT_D: COP1_L_CVT_D(); break; - default: - UnknownOpcode(); break; - } - break; - default: - UnknownOpcode(); break; - } - break; - case R4300i_BEQL: Compile_BranchLikely(BEQ_Compare, false); break; - case R4300i_BNEL: Compile_BranchLikely(BNE_Compare, false); break; - case R4300i_BGTZL:Compile_BranchLikely(BGTZ_Compare, false); break; - case R4300i_BLEZL:Compile_BranchLikely(BLEZ_Compare, false); break; - case R4300i_DADDIU: DADDIU(); break; - case R4300i_LDL: g_MMU->Compile_LDL(); break; - case R4300i_LDR: g_MMU->Compile_LDR(); break; - case R4300i_LB: g_MMU->Compile_LB(); break; - case R4300i_LH: g_MMU->Compile_LH(); break; - case R4300i_LWL: g_MMU->Compile_LWL(); break; - case R4300i_LW: g_MMU->Compile_LW(); break; - case R4300i_LBU: g_MMU->Compile_LBU(); break; - case R4300i_LHU: g_MMU->Compile_LHU(); break; - case R4300i_LWR: g_MMU->Compile_LWR(); break; - case R4300i_LWU: g_MMU->Compile_LWU(); break; //added by Witten - case R4300i_SB: g_MMU->Compile_SB(); break; - case R4300i_SH: g_MMU->Compile_SH(); break; - case R4300i_SWL: g_MMU->Compile_SWL(); break; - case R4300i_SW: g_MMU->Compile_SW(); break; - case R4300i_SWR: g_MMU->Compile_SWR(); break; - case R4300i_SDL: g_MMU->Compile_SDL(); break; - case R4300i_SDR: g_MMU->Compile_SDR(); break; - case R4300i_CACHE: CACHE(); break; - case R4300i_LL: g_MMU->Compile_LL(); break; - case R4300i_LWC1: g_MMU->Compile_LWC1(); break; - case R4300i_LDC1: g_MMU->Compile_LDC1(); break; - case R4300i_SC: g_MMU->Compile_SC(); break; - case R4300i_LD: g_MMU->Compile_LD(); break; - case R4300i_SWC1: g_MMU->Compile_SWC1(); break; - case R4300i_SDC1: g_MMU->Compile_SDC1(); break; - case R4300i_SD: g_MMU->Compile_SD(); break; - default: - UnknownOpcode(); break; - } + switch (m_Opcode.op) + { + case R4300i_SPECIAL: + switch (m_Opcode.funct) + { + case R4300i_SPECIAL_SLL: SPECIAL_SLL(); break; + case R4300i_SPECIAL_SRL: SPECIAL_SRL(); break; + case R4300i_SPECIAL_SRA: SPECIAL_SRA(); break; + case R4300i_SPECIAL_SLLV: SPECIAL_SLLV(); break; + case R4300i_SPECIAL_SRLV: SPECIAL_SRLV(); break; + case R4300i_SPECIAL_SRAV: SPECIAL_SRAV(); break; + case R4300i_SPECIAL_JR: SPECIAL_JR(); break; + case R4300i_SPECIAL_JALR: SPECIAL_JALR(); break; + case R4300i_SPECIAL_MFLO: SPECIAL_MFLO(); break; + case R4300i_SPECIAL_SYSCALL: SPECIAL_SYSCALL(); break; + case R4300i_SPECIAL_MTLO: SPECIAL_MTLO(); break; + case R4300i_SPECIAL_MFHI: SPECIAL_MFHI(); break; + case R4300i_SPECIAL_MTHI: SPECIAL_MTHI(); break; + case R4300i_SPECIAL_DSLLV: SPECIAL_DSLLV(); break; + case R4300i_SPECIAL_DSRLV: SPECIAL_DSRLV(); break; + case R4300i_SPECIAL_DSRAV: SPECIAL_DSRAV(); break; + case R4300i_SPECIAL_MULT: SPECIAL_MULT(); break; + case R4300i_SPECIAL_DIV: SPECIAL_DIV(); break; + case R4300i_SPECIAL_DIVU: SPECIAL_DIVU(); break; + case R4300i_SPECIAL_MULTU: SPECIAL_MULTU(); break; + case R4300i_SPECIAL_DMULT: SPECIAL_DMULT(); break; + case R4300i_SPECIAL_DMULTU: SPECIAL_DMULTU(); break; + case R4300i_SPECIAL_DDIV: SPECIAL_DDIV(); break; + case R4300i_SPECIAL_DDIVU: SPECIAL_DDIVU(); break; + case R4300i_SPECIAL_ADD: SPECIAL_ADD(); break; + case R4300i_SPECIAL_ADDU: SPECIAL_ADDU(); break; + case R4300i_SPECIAL_SUB: SPECIAL_SUB(); break; + case R4300i_SPECIAL_SUBU: SPECIAL_SUBU(); break; + case R4300i_SPECIAL_AND: SPECIAL_AND(); break; + case R4300i_SPECIAL_OR: SPECIAL_OR(); break; + case R4300i_SPECIAL_XOR: SPECIAL_XOR(); break; + case R4300i_SPECIAL_NOR: SPECIAL_NOR(); break; + case R4300i_SPECIAL_SLT: SPECIAL_SLT(); break; + case R4300i_SPECIAL_SLTU: SPECIAL_SLTU(); break; + case R4300i_SPECIAL_DADD: SPECIAL_DADD(); break; + case R4300i_SPECIAL_DADDU: SPECIAL_DADDU(); break; + case R4300i_SPECIAL_DSUB: SPECIAL_DSUB(); break; + case R4300i_SPECIAL_DSUBU: SPECIAL_DSUBU(); break; + case R4300i_SPECIAL_DSLL: SPECIAL_DSLL(); break; + case R4300i_SPECIAL_DSRL: SPECIAL_DSRL(); break; + case R4300i_SPECIAL_DSRA: SPECIAL_DSRA(); break; + case R4300i_SPECIAL_DSLL32: SPECIAL_DSLL32(); break; + case R4300i_SPECIAL_DSRL32: SPECIAL_DSRL32(); break; + case R4300i_SPECIAL_DSRA32: SPECIAL_DSRA32(); break; + default: + UnknownOpcode(); break; + } + break; + case R4300i_REGIMM: + switch (m_Opcode.rt) + { + case R4300i_REGIMM_BLTZ:Compile_Branch(BLTZ_Compare, BranchTypeRs, false); break; + case R4300i_REGIMM_BGEZ:Compile_Branch(BGEZ_Compare, BranchTypeRs, false); break; + case R4300i_REGIMM_BLTZL:Compile_BranchLikely(BLTZ_Compare, false); break; + case R4300i_REGIMM_BGEZL:Compile_BranchLikely(BGEZ_Compare, false); break; + case R4300i_REGIMM_BLTZAL:Compile_Branch(BLTZ_Compare, BranchTypeRs, true); break; + case R4300i_REGIMM_BGEZAL:Compile_Branch(BGEZ_Compare, BranchTypeRs, true); break; + default: + UnknownOpcode(); break; + } + break; + case R4300i_BEQ: Compile_Branch(BEQ_Compare, BranchTypeRsRt, false); break; + case R4300i_BNE: Compile_Branch(BNE_Compare, BranchTypeRsRt, false); break; + case R4300i_BGTZ:Compile_Branch(BGTZ_Compare, BranchTypeRs, false); break; + case R4300i_BLEZ:Compile_Branch(BLEZ_Compare, BranchTypeRs, false); break; + case R4300i_J: J(); break; + case R4300i_JAL: JAL(); break; + case R4300i_ADDI: ADDI(); break; + case R4300i_ADDIU: ADDIU(); break; + case R4300i_SLTI: SLTI(); break; + case R4300i_SLTIU: SLTIU(); break; + case R4300i_ANDI: ANDI(); break; + case R4300i_ORI: ORI(); break; + case R4300i_XORI: XORI(); break; + case R4300i_LUI: LUI(); break; + case R4300i_CP0: + switch (m_Opcode.rs) + { + case R4300i_COP0_MF: COP0_MF(); break; + case R4300i_COP0_MT: COP0_MT(); break; + default: + if ((m_Opcode.rs & 0x10) != 0) + { + switch (m_Opcode.funct) + { + case R4300i_COP0_CO_TLBR: COP0_CO_TLBR(); break; + case R4300i_COP0_CO_TLBWI: COP0_CO_TLBWI(); break; + case R4300i_COP0_CO_TLBWR: COP0_CO_TLBWR(); break; + case R4300i_COP0_CO_TLBP: COP0_CO_TLBP(); break; + case R4300i_COP0_CO_ERET: COP0_CO_ERET(); break; + default: UnknownOpcode(); break; + } + } + else + { + UnknownOpcode(); + } + } + break; + case R4300i_CP1: + switch (m_Opcode.rs) + { + case R4300i_COP1_MF: COP1_MF(); break; + case R4300i_COP1_DMF: COP1_DMF(); break; + case R4300i_COP1_CF: COP1_CF(); break; + case R4300i_COP1_MT: COP1_MT(); break; + case R4300i_COP1_DMT: COP1_DMT(); break; + case R4300i_COP1_CT: COP1_CT(); break; + case R4300i_COP1_BC: + switch (m_Opcode.ft) + { + case R4300i_COP1_BC_BCF: Compile_Branch(COP1_BCF_Compare, BranchTypeCop1, false); break; + case R4300i_COP1_BC_BCT: Compile_Branch(COP1_BCT_Compare, BranchTypeCop1, false); break; + case R4300i_COP1_BC_BCFL: Compile_BranchLikely(COP1_BCF_Compare, false); break; + case R4300i_COP1_BC_BCTL: Compile_BranchLikely(COP1_BCT_Compare, false); break; + default: + UnknownOpcode(); break; + } + break; + case R4300i_COP1_S: + switch (m_Opcode.funct) + { + case R4300i_COP1_FUNCT_ADD: COP1_S_ADD(); break; + case R4300i_COP1_FUNCT_SUB: COP1_S_SUB(); break; + case R4300i_COP1_FUNCT_MUL: COP1_S_MUL(); break; + case R4300i_COP1_FUNCT_DIV: COP1_S_DIV(); break; + case R4300i_COP1_FUNCT_ABS: COP1_S_ABS(); break; + case R4300i_COP1_FUNCT_NEG: COP1_S_NEG(); break; + case R4300i_COP1_FUNCT_SQRT: COP1_S_SQRT(); break; + case R4300i_COP1_FUNCT_MOV: COP1_S_MOV(); break; + case R4300i_COP1_FUNCT_TRUNC_L: COP1_S_TRUNC_L(); break; + case R4300i_COP1_FUNCT_CEIL_L: COP1_S_CEIL_L(); break; //added by Witten + case R4300i_COP1_FUNCT_FLOOR_L: COP1_S_FLOOR_L(); break; //added by Witten + case R4300i_COP1_FUNCT_ROUND_W: COP1_S_ROUND_W(); break; + case R4300i_COP1_FUNCT_TRUNC_W: COP1_S_TRUNC_W(); break; + case R4300i_COP1_FUNCT_CEIL_W: COP1_S_CEIL_W(); break; //added by Witten + case R4300i_COP1_FUNCT_FLOOR_W: COP1_S_FLOOR_W(); break; + case R4300i_COP1_FUNCT_CVT_D: COP1_S_CVT_D(); break; + case R4300i_COP1_FUNCT_CVT_W: COP1_S_CVT_W(); break; + case R4300i_COP1_FUNCT_CVT_L: COP1_S_CVT_L(); break; + case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: + case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: + case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: + case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: + case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: + case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: + case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: + case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: + COP1_S_CMP(); break; + default: + UnknownOpcode(); break; + } + break; + case R4300i_COP1_D: + switch (m_Opcode.funct) + { + case R4300i_COP1_FUNCT_ADD: COP1_D_ADD(); break; + case R4300i_COP1_FUNCT_SUB: COP1_D_SUB(); break; + case R4300i_COP1_FUNCT_MUL: COP1_D_MUL(); break; + case R4300i_COP1_FUNCT_DIV: COP1_D_DIV(); break; + case R4300i_COP1_FUNCT_ABS: COP1_D_ABS(); break; + case R4300i_COP1_FUNCT_NEG: COP1_D_NEG(); break; + case R4300i_COP1_FUNCT_SQRT: COP1_D_SQRT(); break; + case R4300i_COP1_FUNCT_MOV: COP1_D_MOV(); break; + case R4300i_COP1_FUNCT_TRUNC_L: COP1_D_TRUNC_L(); break; //added by Witten + case R4300i_COP1_FUNCT_CEIL_L: COP1_D_CEIL_L(); break; //added by Witten + case R4300i_COP1_FUNCT_FLOOR_L: COP1_D_FLOOR_L(); break; //added by Witten + case R4300i_COP1_FUNCT_ROUND_W: COP1_D_ROUND_W(); break; + case R4300i_COP1_FUNCT_TRUNC_W: COP1_D_TRUNC_W(); break; + case R4300i_COP1_FUNCT_CEIL_W: COP1_D_CEIL_W(); break; //added by Witten + case R4300i_COP1_FUNCT_FLOOR_W: COP1_D_FLOOR_W(); break; //added by Witten + case R4300i_COP1_FUNCT_CVT_S: COP1_D_CVT_S(); break; + case R4300i_COP1_FUNCT_CVT_W: COP1_D_CVT_W(); break; + case R4300i_COP1_FUNCT_CVT_L: COP1_D_CVT_L(); break; + case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: + case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: + case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: + case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: + case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: + case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: + case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: + case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: + COP1_D_CMP(); break; + default: + UnknownOpcode(); break; + } + break; + case R4300i_COP1_W: + switch (m_Opcode.funct) + { + case R4300i_COP1_FUNCT_CVT_S: COP1_W_CVT_S(); break; + case R4300i_COP1_FUNCT_CVT_D: COP1_W_CVT_D(); break; + default: + UnknownOpcode(); break; + } + break; + case R4300i_COP1_L: + switch (m_Opcode.funct) + { + case R4300i_COP1_FUNCT_CVT_S: COP1_L_CVT_S(); break; + case R4300i_COP1_FUNCT_CVT_D: COP1_L_CVT_D(); break; + default: + UnknownOpcode(); break; + } + break; + default: + UnknownOpcode(); break; + } + break; + case R4300i_BEQL: Compile_BranchLikely(BEQ_Compare, false); break; + case R4300i_BNEL: Compile_BranchLikely(BNE_Compare, false); break; + case R4300i_BGTZL:Compile_BranchLikely(BGTZ_Compare, false); break; + case R4300i_BLEZL:Compile_BranchLikely(BLEZ_Compare, false); break; + case R4300i_DADDIU: DADDIU(); break; + case R4300i_LDL: g_MMU->Compile_LDL(); break; + case R4300i_LDR: g_MMU->Compile_LDR(); break; + case R4300i_LB: g_MMU->Compile_LB(); break; + case R4300i_LH: g_MMU->Compile_LH(); break; + case R4300i_LWL: g_MMU->Compile_LWL(); break; + case R4300i_LW: g_MMU->Compile_LW(); break; + case R4300i_LBU: g_MMU->Compile_LBU(); break; + case R4300i_LHU: g_MMU->Compile_LHU(); break; + case R4300i_LWR: g_MMU->Compile_LWR(); break; + case R4300i_LWU: g_MMU->Compile_LWU(); break; //added by Witten + case R4300i_SB: g_MMU->Compile_SB(); break; + case R4300i_SH: g_MMU->Compile_SH(); break; + case R4300i_SWL: g_MMU->Compile_SWL(); break; + case R4300i_SW: g_MMU->Compile_SW(); break; + case R4300i_SWR: g_MMU->Compile_SWR(); break; + case R4300i_SDL: g_MMU->Compile_SDL(); break; + case R4300i_SDR: g_MMU->Compile_SDR(); break; + case R4300i_CACHE: CACHE(); break; + case R4300i_LL: g_MMU->Compile_LL(); break; + case R4300i_LWC1: g_MMU->Compile_LWC1(); break; + case R4300i_LDC1: g_MMU->Compile_LDC1(); break; + case R4300i_SC: g_MMU->Compile_SC(); break; + case R4300i_LD: g_MMU->Compile_LD(); break; + case R4300i_SWC1: g_MMU->Compile_SWC1(); break; + case R4300i_SDC1: g_MMU->Compile_SDC1(); break; + case R4300i_SD: g_MMU->Compile_SD(); break; + default: + UnknownOpcode(); break; + } - if (!g_System->bRegCaching()) { m_RegWorkingSet.WriteBackRegisters(); } - m_RegWorkingSet.UnMap_AllFPRs(); + if (!g_System->bRegCaching()) { m_RegWorkingSet.WriteBackRegisters(); } + m_RegWorkingSet.UnMap_AllFPRs(); - if ((m_CompilePC & 0xFFC) == 0xFFC) - { - if (m_NextInstruction == DO_DELAY_SLOT) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - if (m_NextInstruction == NORMAL) - { - if (m_DelaySlot) - { - CompileExit(m_CompilePC, m_Jump.TargetPC, m_RegWorkingSet, CExitInfo::Normal, true, NULL); - } - else - { - CompileExit(m_CompilePC, m_CompilePC + 4, m_RegWorkingSet, CExitInfo::Normal, true, NULL); - } - m_NextInstruction = END_BLOCK; - } - } + if ((m_CompilePC & 0xFFC) == 0xFFC) + { + if (m_NextInstruction == DO_DELAY_SLOT) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + if (m_NextInstruction == NORMAL) + { + if (m_DelaySlot) + { + CompileExit(m_CompilePC, m_Jump.TargetPC, m_RegWorkingSet, CExitInfo::Normal, true, NULL); + } + else + { + CompileExit(m_CompilePC, m_CompilePC + 4, m_RegWorkingSet, CExitInfo::Normal, true, NULL); + } + m_NextInstruction = END_BLOCK; + } + } - switch (m_NextInstruction) - { - case NORMAL: - m_CompilePC += 4; - break; - case DO_DELAY_SLOT: - m_NextInstruction = DELAY_SLOT; - m_CompilePC += 4; - break; - case DELAY_SLOT: - m_NextInstruction = DELAY_SLOT_DONE; - m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); - m_CompilePC -= 4; - break; - } + switch (m_NextInstruction) + { + case NORMAL: + m_CompilePC += 4; + break; + case DO_DELAY_SLOT: + m_NextInstruction = DELAY_SLOT; + m_CompilePC += 4; + break; + case DELAY_SLOT: + m_NextInstruction = DELAY_SLOT_DONE; + m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); + m_CompilePC -= 4; + break; + } - if (m_DelaySlot) - { - if ((CompilePC() & 0xFFC) != 0xFFC && m_Jump.JumpPC != (uint32_t)-1) - { - m_CompilePC = m_Jump.JumpPC; - m_Jump.RegSet = m_RegWorkingSet; - m_Jump.FallThrough = true; - GenerateSectionLinkage(); - } - else - { - CompileExit(m_Jump.JumpPC, m_Jump.TargetPC, m_RegWorkingSet, CExitInfo::Normal, true, NULL); - } - m_NextInstruction = END_BLOCK; - } - else if (m_NextInstruction != END_BLOCK && m_CompilePC == ContinueSectionPC) - { - if (m_NextInstruction != NORMAL) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - m_CompilePC -= 4; - m_Cont.RegSet = m_RegWorkingSet; - m_Cont.FallThrough = true; - m_Cont.JumpPC = m_CompilePC; - GenerateSectionLinkage(); - m_NextInstruction = END_BLOCK; - } - } while (m_NextInstruction != END_BLOCK); - return true; + if (m_DelaySlot) + { + if ((CompilePC() & 0xFFC) != 0xFFC && m_Jump.JumpPC != (uint32_t)-1) + { + m_CompilePC = m_Jump.JumpPC; + m_Jump.RegSet = m_RegWorkingSet; + m_Jump.FallThrough = true; + GenerateSectionLinkage(); + } + else + { + CompileExit(m_Jump.JumpPC, m_Jump.TargetPC, m_RegWorkingSet, CExitInfo::Normal, true, NULL); + } + m_NextInstruction = END_BLOCK; + } + else if (m_NextInstruction != END_BLOCK && m_CompilePC == ContinueSectionPC) + { + if (m_NextInstruction != NORMAL) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + m_CompilePC -= 4; + m_Cont.RegSet = m_RegWorkingSet; + m_Cont.FallThrough = true; + m_Cont.JumpPC = m_CompilePC; + GenerateSectionLinkage(); + m_NextInstruction = END_BLOCK; + } + } while (m_NextInstruction != END_BLOCK); + return true; } void CCodeSection::AddParent(CCodeSection * Parent) { - if (this == NULL) { return; } - if (Parent == NULL) - { - m_RegWorkingSet = m_RegEnter; - return; - } + if (this == NULL) { return; } + if (Parent == NULL) + { + m_RegWorkingSet = m_RegEnter; + return; + } - // check to see if we already have the parent in the list - for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) - { - if (*iter == Parent) - { - return; - } - } - m_ParentSection.push_back(Parent); + // check to see if we already have the parent in the list + for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) + { + if (*iter == Parent) + { + return; + } + } + m_ParentSection.push_back(Parent); - if (m_ParentSection.size() == 1) - { - if (Parent->m_ContinueSection == this) - { - m_RegEnter = Parent->m_Cont.RegSet; - } - else if (Parent->m_JumpSection == this) - { - m_RegEnter = Parent->m_Jump.RegSet; - } - else - { - g_Notify->DisplayError(L"How are these sections joined?????"); - } - m_RegWorkingSet = m_RegEnter; - } - else { - if (Parent->m_ContinueSection == this) - { - TestRegConstantStates(Parent->m_Cont.RegSet, m_RegEnter); - } - if (Parent->m_JumpSection == this) - { - TestRegConstantStates(Parent->m_Jump.RegSet, m_RegEnter); - } - m_RegWorkingSet = m_RegEnter; - } + if (m_ParentSection.size() == 1) + { + if (Parent->m_ContinueSection == this) + { + m_RegEnter = Parent->m_Cont.RegSet; + } + else if (Parent->m_JumpSection == this) + { + m_RegEnter = Parent->m_Jump.RegSet; + } + else + { + g_Notify->DisplayError(L"How are these sections joined?????"); + } + m_RegWorkingSet = m_RegEnter; + } + else { + if (Parent->m_ContinueSection == this) + { + TestRegConstantStates(Parent->m_Cont.RegSet, m_RegEnter); + } + if (Parent->m_JumpSection == this) + { + TestRegConstantStates(Parent->m_Jump.RegSet, m_RegEnter); + } + m_RegWorkingSet = m_RegEnter; + } } void CCodeSection::SwitchParent(CCodeSection * OldParent, CCodeSection * NewParent) { - if (this == NULL) { return; } + if (this == NULL) { return; } - bool bFoundOldParent = false; - for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) - { - if (*iter != OldParent) - { - continue; - } - bFoundOldParent = true; - m_ParentSection.erase(iter); - break; - } + bool bFoundOldParent = false; + for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) + { + if (*iter != OldParent) + { + continue; + } + bFoundOldParent = true; + m_ParentSection.erase(iter); + break; + } - if (!bFoundOldParent) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - m_ParentSection.push_back(NewParent); + if (!bFoundOldParent) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + m_ParentSection.push_back(NewParent); } void CCodeSection::TestRegConstantStates(CRegInfo & Base, CRegInfo & Reg) { - for (int i = 0; i < 32; i++) - { - if (Reg.GetMipsRegState(i) != Base.GetMipsRegState(i)) - { - Reg.SetMipsRegState(i, CRegInfo::STATE_UNKNOWN); - } - if (Reg.IsConst(i)) - { - if (Reg.Is32Bit(i)) - { - if (Reg.GetMipsRegLo(i) != Base.GetMipsRegLo(i)) - { - Reg.SetMipsRegState(i, CRegInfo::STATE_UNKNOWN); - } - } - else - { - if (Reg.GetMipsReg(i) != Base.GetMipsReg(i)) - { - Reg.SetMipsRegState(i, CRegInfo::STATE_UNKNOWN); - } - } - } - } + for (int i = 0; i < 32; i++) + { + if (Reg.GetMipsRegState(i) != Base.GetMipsRegState(i)) + { + Reg.SetMipsRegState(i, CRegInfo::STATE_UNKNOWN); + } + if (Reg.IsConst(i)) + { + if (Reg.Is32Bit(i)) + { + if (Reg.GetMipsRegLo(i) != Base.GetMipsRegLo(i)) + { + Reg.SetMipsRegState(i, CRegInfo::STATE_UNKNOWN); + } + } + else + { + if (Reg.GetMipsReg(i) != Base.GetMipsReg(i)) + { + Reg.SetMipsRegState(i, CRegInfo::STATE_UNKNOWN); + } + } + } + } } void CCodeSection::DetermineLoop(uint32_t Test, uint32_t Test2, uint32_t TestID) { - if (this == NULL) { return; } + if (this == NULL) { return; } - if (m_SectionID == TestID) - { - if (m_Test2 != Test2) - { - m_Test2 = Test2; - m_ContinueSection->DetermineLoop(Test, Test2, TestID); - m_JumpSection->DetermineLoop(Test, Test2, TestID); + if (m_SectionID == TestID) + { + if (m_Test2 != Test2) + { + m_Test2 = Test2; + m_ContinueSection->DetermineLoop(Test, Test2, TestID); + m_JumpSection->DetermineLoop(Test, Test2, TestID); - if (m_Test != Test) - { - m_Test = Test; - if (m_ContinueSection != NULL) - { - m_ContinueSection->DetermineLoop(Test, m_BlockInfo->NextTest(), m_ContinueSection->m_SectionID); - } - if (m_JumpSection != NULL) - { - m_JumpSection->DetermineLoop(Test, m_BlockInfo->NextTest(), m_JumpSection->m_SectionID); - } - } - } - else - { - m_InLoop = true; - } - } - else - { - if (m_Test2 != Test2) - { - m_Test2 = Test2; - m_ContinueSection->DetermineLoop(Test, Test2, TestID); - m_JumpSection->DetermineLoop(Test, Test2, TestID); - } - } + if (m_Test != Test) + { + m_Test = Test; + if (m_ContinueSection != NULL) + { + m_ContinueSection->DetermineLoop(Test, m_BlockInfo->NextTest(), m_ContinueSection->m_SectionID); + } + if (m_JumpSection != NULL) + { + m_JumpSection->DetermineLoop(Test, m_BlockInfo->NextTest(), m_JumpSection->m_SectionID); + } + } + } + else + { + m_InLoop = true; + } + } + else + { + if (m_Test2 != Test2) + { + m_Test2 = Test2; + m_ContinueSection->DetermineLoop(Test, Test2, TestID); + m_JumpSection->DetermineLoop(Test, Test2, TestID); + } + } } CCodeSection * CCodeSection::ExistingSection(uint32_t Addr, uint32_t Test) { - if (this == NULL) { return NULL; } - if (m_EnterPC == Addr && m_LinkAllowed) - { - return this; - } - if (m_Test == Test) { return NULL; } - m_Test = Test; + if (this == NULL) { return NULL; } + if (m_EnterPC == Addr && m_LinkAllowed) + { + return this; + } + if (m_Test == Test) { return NULL; } + m_Test = Test; - CCodeSection * Section = m_JumpSection->ExistingSection(Addr, Test); - if (Section != NULL) { return Section; } - Section = m_ContinueSection->ExistingSection(Addr, Test); - if (Section != NULL) { return Section; } + CCodeSection * Section = m_JumpSection->ExistingSection(Addr, Test); + if (Section != NULL) { return Section; } + Section = m_ContinueSection->ExistingSection(Addr, Test); + if (Section != NULL) { return Section; } - return NULL; + return NULL; } bool CCodeSection::SectionAccessible(uint32_t SectionId, uint32_t Test) { - if (this == NULL) { return false; } - if (m_SectionID == SectionId) - { - return true; - } + if (this == NULL) { return false; } + if (m_SectionID == SectionId) + { + return true; + } - if (m_Test == Test) { return false; } - m_Test = Test; + if (m_Test == Test) { return false; } + m_Test = Test; - if (m_ContinueSection->SectionAccessible(SectionId, Test)) - { - return true; - } - return m_JumpSection->SectionAccessible(SectionId, Test); + if (m_ContinueSection->SectionAccessible(SectionId, Test)) + { + return true; + } + return m_JumpSection->SectionAccessible(SectionId, Test); } void CCodeSection::UnlinkParent(CCodeSection * Parent, bool ContinueSection) { - if (this == NULL) - { - return; - } + if (this == NULL) + { + return; + } - CPU_Message(__FUNCTION__ ": Section %d Parent: %d ContinueSection = %s", m_SectionID, Parent->m_SectionID, ContinueSection ? "Yes" : "No"); - if (Parent->m_ContinueSection == this && Parent->m_JumpSection == this) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } + CPU_Message(__FUNCTION__ ": Section %d Parent: %d ContinueSection = %s", m_SectionID, Parent->m_SectionID, ContinueSection ? "Yes" : "No"); + if (Parent->m_ContinueSection == this && Parent->m_JumpSection == this) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } - SECTION_LIST::iterator iter = m_ParentSection.begin(); - while (iter != m_ParentSection.end()) - { - CCodeSection * ParentIter = *iter; - if (ParentIter == Parent && (Parent->m_ContinueSection != this || Parent->m_JumpSection != this)) - { - m_ParentSection.erase(iter); - iter = m_ParentSection.begin(); - } - else - { - iter++; - } - } + SECTION_LIST::iterator iter = m_ParentSection.begin(); + while (iter != m_ParentSection.end()) + { + CCodeSection * ParentIter = *iter; + if (ParentIter == Parent && (Parent->m_ContinueSection != this || Parent->m_JumpSection != this)) + { + m_ParentSection.erase(iter); + iter = m_ParentSection.begin(); + } + else + { + iter++; + } + } - if (ContinueSection && Parent->m_ContinueSection == this) - { - Parent->m_ContinueSection = NULL; - } + if (ContinueSection && Parent->m_ContinueSection == this) + { + Parent->m_ContinueSection = NULL; + } - if (!ContinueSection && Parent->m_JumpSection == this) - { - Parent->m_JumpSection = NULL; - } + if (!ContinueSection && Parent->m_JumpSection == this) + { + Parent->m_JumpSection = NULL; + } - bool bRemove = false; - if (m_ParentSection.size() > 0) - { - if (!m_BlockInfo->SectionAccessible(m_SectionID)) - { - for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) - { - CCodeSection * ParentIter = *iter; - if (ParentIter->m_ContinueSection == this) - { - if (ParentIter->m_CompiledLocation) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - ParentIter->m_ContinueSection = NULL; - } + bool bRemove = false; + if (m_ParentSection.size() > 0) + { + if (!m_BlockInfo->SectionAccessible(m_SectionID)) + { + for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) + { + CCodeSection * ParentIter = *iter; + if (ParentIter->m_ContinueSection == this) + { + if (ParentIter->m_CompiledLocation) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + ParentIter->m_ContinueSection = NULL; + } - if (ParentIter->m_JumpSection == this) - { - if (ParentIter->m_CompiledLocation) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - ParentIter->m_JumpSection = NULL; - } - } - bRemove = true; - } - } - else - { - bRemove = true; - } - if (bRemove) - { - if (m_JumpSection != NULL) - { - m_JumpSection->UnlinkParent(this, false); - } - if (m_ContinueSection != NULL) - { - m_ContinueSection->UnlinkParent(this, true); - } - } + if (ParentIter->m_JumpSection == this) + { + if (ParentIter->m_CompiledLocation) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + ParentIter->m_JumpSection = NULL; + } + } + bRemove = true; + } + } + else + { + bRemove = true; + } + if (bRemove) + { + if (m_JumpSection != NULL) + { + m_JumpSection->UnlinkParent(this, false); + } + if (m_ContinueSection != NULL) + { + m_ContinueSection->UnlinkParent(this, true); + } + } } bool CCodeSection::IsAllParentLoops(CCodeSection * Parent, bool IgnoreIfCompiled, uint32_t Test) { - if (IgnoreIfCompiled && Parent->m_CompiledLocation != NULL) { return true; } - if (!m_InLoop) { return false; } - if (!Parent->m_InLoop) { return false; } - if (Parent->m_ParentSection.empty()) { return false; } - if (this == Parent) { return true; } - if (Parent->m_Test == Test) { return true; } - Parent->m_Test = Test; + if (IgnoreIfCompiled && Parent->m_CompiledLocation != NULL) { return true; } + if (!m_InLoop) { return false; } + if (!Parent->m_InLoop) { return false; } + if (Parent->m_ParentSection.empty()) { return false; } + if (this == Parent) { return true; } + if (Parent->m_Test == Test) { return true; } + Parent->m_Test = Test; - for (SECTION_LIST::iterator iter = Parent->m_ParentSection.begin(); iter != Parent->m_ParentSection.end(); iter++) - { - CCodeSection * ParentSection = *iter; - if (!IsAllParentLoops(ParentSection, IgnoreIfCompiled, Test)) { return false; } - } - return true; + for (SECTION_LIST::iterator iter = Parent->m_ParentSection.begin(); iter != Parent->m_ParentSection.end(); iter++) + { + CCodeSection * ParentSection = *iter; + if (!IsAllParentLoops(ParentSection, IgnoreIfCompiled, Test)) { return false; } + } + return true; } bool CCodeSection::SetupRegisterForLoop() { - CRegInfo OriginalReg = m_RegWorkingSet; - if (!LoopAnalysis(m_BlockInfo, this).SetupRegisterForLoop()) - { - return false; - } - for (int i = 1; i < 32; i++) - { - if (OriginalReg.GetMipsRegState(i) != m_RegEnter.GetMipsRegState(i)) - { - UnMap_GPR(i, true); - } - } - return true; + CRegInfo OriginalReg = m_RegWorkingSet; + if (!LoopAnalysis(m_BlockInfo, this).SetupRegisterForLoop()) + { + return false; + } + for (int i = 1; i < 32; i++) + { + if (OriginalReg.GetMipsRegState(i) != m_RegEnter.GetMipsRegState(i)) + { + UnMap_GPR(i, true); + } + } + return true; } bool CCodeSection::InheritParentInfo() { - if (m_CompiledLocation == NULL) - { - m_CompiledLocation = m_RecompPos; - DisplaySectionInformation(); - m_CompiledLocation = NULL; - } - else - { - DisplaySectionInformation(); - } + if (m_CompiledLocation == NULL) + { + m_CompiledLocation = m_RecompPos; + DisplaySectionInformation(); + m_CompiledLocation = NULL; + } + else + { + DisplaySectionInformation(); + } - if (m_ParentSection.empty()) - { - m_RegWorkingSet = m_RegEnter; - return true; - } + if (m_ParentSection.empty()) + { + m_RegWorkingSet = m_RegEnter; + return true; + } - if (m_ParentSection.size() == 1) - { - CCodeSection * Parent = *(m_ParentSection.begin()); - if (Parent->m_CompiledLocation == NULL) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - CJumpInfo * JumpInfo = this == Parent->m_ContinueSection ? &Parent->m_Cont : &Parent->m_Jump; + if (m_ParentSection.size() == 1) + { + CCodeSection * Parent = *(m_ParentSection.begin()); + if (Parent->m_CompiledLocation == NULL) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + CJumpInfo * JumpInfo = this == Parent->m_ContinueSection ? &Parent->m_Cont : &Parent->m_Jump; - m_RegEnter = JumpInfo->RegSet; - if (JumpInfo->LinkLocation != NULL) - { - CPU_Message(" Section_%d:", m_SectionID); - SetJump32(JumpInfo->LinkLocation, (uint32_t *)m_RecompPos); - if (JumpInfo->LinkLocation2 != NULL) - { - SetJump32(JumpInfo->LinkLocation2, (uint32_t *)m_RecompPos); - } - } - m_RegWorkingSet = m_RegEnter; - return true; - } + m_RegEnter = JumpInfo->RegSet; + if (JumpInfo->LinkLocation != NULL) + { + CPU_Message(" Section_%d:", m_SectionID); + SetJump32(JumpInfo->LinkLocation, (uint32_t *)m_RecompPos); + if (JumpInfo->LinkLocation2 != NULL) + { + SetJump32(JumpInfo->LinkLocation2, (uint32_t *)m_RecompPos); + } + } + m_RegWorkingSet = m_RegEnter; + return true; + } - //Multiple Parents - BLOCK_PARENT_LIST ParentList; - SECTION_LIST::iterator iter; - for (iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) - { - CCodeSection * Parent = *iter; - BLOCK_PARENT BlockParent; + //Multiple Parents + BLOCK_PARENT_LIST ParentList; + SECTION_LIST::iterator iter; + for (iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) + { + CCodeSection * Parent = *iter; + BLOCK_PARENT BlockParent; - if (Parent->m_CompiledLocation == NULL) { continue; } - if (Parent->m_JumpSection != Parent->m_ContinueSection) - { - BlockParent.Parent = Parent; - BlockParent.JumpInfo = this == Parent->m_ContinueSection ? &Parent->m_Cont : &Parent->m_Jump; - ParentList.push_back(BlockParent); - } - else - { - BlockParent.Parent = Parent; - BlockParent.JumpInfo = &Parent->m_Cont; - ParentList.push_back(BlockParent); - BlockParent.Parent = Parent; - BlockParent.JumpInfo = &Parent->m_Jump; - ParentList.push_back(BlockParent); - } - } - size_t NoOfCompiledParents = ParentList.size(); - if (NoOfCompiledParents == 0) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - return false; - } + if (Parent->m_CompiledLocation == NULL) { continue; } + if (Parent->m_JumpSection != Parent->m_ContinueSection) + { + BlockParent.Parent = Parent; + BlockParent.JumpInfo = this == Parent->m_ContinueSection ? &Parent->m_Cont : &Parent->m_Jump; + ParentList.push_back(BlockParent); + } + else + { + BlockParent.Parent = Parent; + BlockParent.JumpInfo = &Parent->m_Cont; + ParentList.push_back(BlockParent); + BlockParent.Parent = Parent; + BlockParent.JumpInfo = &Parent->m_Jump; + ParentList.push_back(BlockParent); + } + } + size_t NoOfCompiledParents = ParentList.size(); + if (NoOfCompiledParents == 0) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + return false; + } - // Add all the uncompiled blocks to the end of the list - for (iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) - { - CCodeSection * Parent = *iter; - BLOCK_PARENT BlockParent; + // Add all the uncompiled blocks to the end of the list + for (iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) + { + CCodeSection * Parent = *iter; + BLOCK_PARENT BlockParent; - if (Parent->m_CompiledLocation != NULL) { continue; } - if (Parent->m_JumpSection != Parent->m_ContinueSection) - { - BlockParent.Parent = Parent; - BlockParent.JumpInfo = this == Parent->m_ContinueSection ? &Parent->m_Cont : &Parent->m_Jump; - ParentList.push_back(BlockParent); - } - else - { - BlockParent.Parent = Parent; - BlockParent.JumpInfo = &Parent->m_Cont; - ParentList.push_back(BlockParent); - BlockParent.Parent = Parent; - BlockParent.JumpInfo = &Parent->m_Jump; - ParentList.push_back(BlockParent); - } - } - int FirstParent = -1; - for (size_t i = 0; i < NoOfCompiledParents; i++) - { - if (!ParentList[i].JumpInfo->FallThrough) - { - continue; - } - if (FirstParent != -1) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - FirstParent = i; - } - if (FirstParent == -1) - { - FirstParent = 0; - } + if (Parent->m_CompiledLocation != NULL) { continue; } + if (Parent->m_JumpSection != Parent->m_ContinueSection) + { + BlockParent.Parent = Parent; + BlockParent.JumpInfo = this == Parent->m_ContinueSection ? &Parent->m_Cont : &Parent->m_Jump; + ParentList.push_back(BlockParent); + } + else + { + BlockParent.Parent = Parent; + BlockParent.JumpInfo = &Parent->m_Cont; + ParentList.push_back(BlockParent); + BlockParent.Parent = Parent; + BlockParent.JumpInfo = &Parent->m_Jump; + ParentList.push_back(BlockParent); + } + } + int FirstParent = -1; + for (size_t i = 0; i < NoOfCompiledParents; i++) + { + if (!ParentList[i].JumpInfo->FallThrough) + { + continue; + } + if (FirstParent != -1) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + FirstParent = i; + } + if (FirstParent == -1) + { + FirstParent = 0; + } - //Link First Parent to start - CCodeSection * Parent = ParentList[FirstParent].Parent; - CJumpInfo * JumpInfo = ParentList[FirstParent].JumpInfo; + //Link First Parent to start + CCodeSection * Parent = ParentList[FirstParent].Parent; + CJumpInfo * JumpInfo = ParentList[FirstParent].JumpInfo; - m_RegWorkingSet = JumpInfo->RegSet; - m_RegWorkingSet.ResetX86Protection(); + m_RegWorkingSet = JumpInfo->RegSet; + m_RegWorkingSet.ResetX86Protection(); - if (JumpInfo->LinkLocation != NULL) - { - CPU_Message(" Section_%d (from %d):", m_SectionID, Parent->m_SectionID); - SetJump32(JumpInfo->LinkLocation, (uint32_t *)m_RecompPos); - JumpInfo->LinkLocation = NULL; - if (JumpInfo->LinkLocation2 != NULL) - { - SetJump32(JumpInfo->LinkLocation2, (uint32_t *)m_RecompPos); - JumpInfo->LinkLocation2 = NULL; - } - } + if (JumpInfo->LinkLocation != NULL) + { + CPU_Message(" Section_%d (from %d):", m_SectionID, Parent->m_SectionID); + SetJump32(JumpInfo->LinkLocation, (uint32_t *)m_RecompPos); + JumpInfo->LinkLocation = NULL; + if (JumpInfo->LinkLocation2 != NULL) + { + SetJump32(JumpInfo->LinkLocation2, (uint32_t *)m_RecompPos); + JumpInfo->LinkLocation2 = NULL; + } + } - if (JumpInfo->ExitReason == CExitInfo::Normal_NoSysCheck) - { - if (JumpInfo->RegSet.GetBlockCycleCount() != 0) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - if (JumpInfo->JumpPC != (uint32_t)-1) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - } - else - { - UpdateCounters(m_RegWorkingSet, m_EnterPC < JumpInfo->JumpPC, true); - if (JumpInfo->JumpPC == (uint32_t)-1) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - if (m_EnterPC <= JumpInfo->JumpPC) - { - CPU_Message("CompileSystemCheck 10"); - CompileSystemCheck(m_EnterPC, m_RegWorkingSet); - } - } - JumpInfo->FallThrough = false; + if (JumpInfo->ExitReason == CExitInfo::Normal_NoSysCheck) + { + if (JumpInfo->RegSet.GetBlockCycleCount() != 0) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + if (JumpInfo->JumpPC != (uint32_t)-1) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + } + else + { + UpdateCounters(m_RegWorkingSet, m_EnterPC < JumpInfo->JumpPC, true); + if (JumpInfo->JumpPC == (uint32_t)-1) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + if (m_EnterPC <= JumpInfo->JumpPC) + { + CPU_Message("CompileSystemCheck 10"); + CompileSystemCheck(m_EnterPC, m_RegWorkingSet); + } + } + JumpInfo->FallThrough = false; - //Fix up initial state - UnMap_AllFPRs(); + //Fix up initial state + UnMap_AllFPRs(); - //determine loop reg usage - if (m_InLoop && ParentList.size() > 1) - { - if (!SetupRegisterForLoop()) { return false; } - m_RegWorkingSet.SetRoundingModel(CRegInfo::RoundUnknown); - } + //determine loop reg usage + if (m_InLoop && ParentList.size() > 1) + { + if (!SetupRegisterForLoop()) { return false; } + m_RegWorkingSet.SetRoundingModel(CRegInfo::RoundUnknown); + } - for (size_t i = 0; i < ParentList.size(); i++) - { - x86Reg MemoryStackPos; - int i2; + for (size_t i = 0; i < ParentList.size(); i++) + { + x86Reg MemoryStackPos; + int i2; - if (i == (size_t)FirstParent) { continue; } - Parent = ParentList[i].Parent; - if (Parent->m_CompiledLocation == NULL) - { - continue; - } - CRegInfo * RegSet = &ParentList[i].JumpInfo->RegSet; + if (i == (size_t)FirstParent) { continue; } + Parent = ParentList[i].Parent; + if (Parent->m_CompiledLocation == NULL) + { + continue; + } + CRegInfo * RegSet = &ParentList[i].JumpInfo->RegSet; - if (m_RegWorkingSet.GetRoundingModel() != RegSet->GetRoundingModel()) { m_RegWorkingSet.SetRoundingModel(CRegInfo::RoundUnknown); } + if (m_RegWorkingSet.GetRoundingModel() != RegSet->GetRoundingModel()) { m_RegWorkingSet.SetRoundingModel(CRegInfo::RoundUnknown); } - //Find Parent MapRegState - MemoryStackPos = x86_Unknown; - for (i2 = 0; i2 < sizeof(x86_Registers) / sizeof(x86_Registers[0]); i2++) - { - if (RegSet->GetX86Mapped(x86_Registers[i2]) == CRegInfo::Stack_Mapped) - { - MemoryStackPos = x86_Registers[i2]; - break; - } - } - if (MemoryStackPos == x86_Unknown) - { - // if the memory stack position is not mapped then unmap it - x86Reg MemStackReg = Get_MemoryStack(); - if (MemStackReg != x86_Unknown) - { - UnMap_X86reg(MemStackReg); - } - } + //Find Parent MapRegState + MemoryStackPos = x86_Unknown; + for (i2 = 0; i2 < sizeof(x86_Registers) / sizeof(x86_Registers[0]); i2++) + { + if (RegSet->GetX86Mapped(x86_Registers[i2]) == CRegInfo::Stack_Mapped) + { + MemoryStackPos = x86_Registers[i2]; + break; + } + } + if (MemoryStackPos == x86_Unknown) + { + // if the memory stack position is not mapped then unmap it + x86Reg MemStackReg = Get_MemoryStack(); + if (MemStackReg != x86_Unknown) + { + UnMap_X86reg(MemStackReg); + } + } - for (i2 = 1; i2 < 32; i2++) - { - if (Is32BitMapped(i2)) - { - switch (RegSet->GetMipsRegState(i2)) - { - case CRegInfo::STATE_MAPPED_64: Map_GPR_64bit(i2, i2); break; - case CRegInfo::STATE_MAPPED_32_ZERO: break; - case CRegInfo::STATE_MAPPED_32_SIGN: - if (IsUnsigned(i2)) - { - m_RegWorkingSet.SetMipsRegState(i2, CRegInfo::STATE_MAPPED_32_SIGN); - } - break; - case CRegInfo::STATE_CONST_64: Map_GPR_64bit(i2, i2); break; - case CRegInfo::STATE_CONST_32_SIGN: - if ((RegSet->GetMipsRegLo_S(i2) < 0) && IsUnsigned(i2)) - { - m_RegWorkingSet.SetMipsRegState(i2, CRegInfo::STATE_MAPPED_32_SIGN); - } - break; - case CRegInfo::STATE_UNKNOWN: - if (g_System->b32BitCore()) - { - Map_GPR_32bit(i2, true, i2); - } - else - { - //Map_GPR_32bit(i2,true,i2); - Map_GPR_64bit(i2, i2); //?? - //UnMap_GPR(Section,i2,true); ?? - } - break; - default: - CPU_Message("Unknown CPU State(%d) in InheritParentInfo", GetMipsRegState(i2)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - } - if (IsConst(i2)) { - if (GetMipsRegState(i2) != RegSet->GetMipsRegState(i2)) - { - switch (RegSet->GetMipsRegState(i2)) - { - case CRegInfo::STATE_MAPPED_64: - Map_GPR_64bit(i2, i2); - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - if (Is32Bit(i2)) - { - Map_GPR_32bit(i2, (GetMipsRegLo(i2) & 0x80000000) != 0, i2); - } - else - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - break; - case CRegInfo::STATE_MAPPED_32_SIGN: - if (Is32Bit(i2)) - { - Map_GPR_32bit(i2, true, i2); - } - else - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - break; - case CRegInfo::STATE_UNKNOWN: - if (g_System->b32BitCore()) - { - Map_GPR_32bit(i2, true, i2); - } - else - { - Map_GPR_64bit(i2, i2); - } - break; - default: - CPU_Message("Unknown CPU State(%d) in InheritParentInfo", RegSet->GetMipsRegState(i2)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - break; - } - } - else if (Is32Bit(i2) && GetMipsRegLo(i2) != RegSet->GetMipsRegLo(i2)) - { - Map_GPR_32bit(i2, true, i2); - } - else if (Is64Bit(i2) && GetMipsReg(i2) != RegSet->GetMipsReg(i2)) - { - Map_GPR_32bit(i2, true, i2); - } - } - ResetX86Protection(); - } + for (i2 = 1; i2 < 32; i2++) + { + if (Is32BitMapped(i2)) + { + switch (RegSet->GetMipsRegState(i2)) + { + case CRegInfo::STATE_MAPPED_64: Map_GPR_64bit(i2, i2); break; + case CRegInfo::STATE_MAPPED_32_ZERO: break; + case CRegInfo::STATE_MAPPED_32_SIGN: + if (IsUnsigned(i2)) + { + m_RegWorkingSet.SetMipsRegState(i2, CRegInfo::STATE_MAPPED_32_SIGN); + } + break; + case CRegInfo::STATE_CONST_64: Map_GPR_64bit(i2, i2); break; + case CRegInfo::STATE_CONST_32_SIGN: + if ((RegSet->GetMipsRegLo_S(i2) < 0) && IsUnsigned(i2)) + { + m_RegWorkingSet.SetMipsRegState(i2, CRegInfo::STATE_MAPPED_32_SIGN); + } + break; + case CRegInfo::STATE_UNKNOWN: + if (g_System->b32BitCore()) + { + Map_GPR_32bit(i2, true, i2); + } + else + { + //Map_GPR_32bit(i2,true,i2); + Map_GPR_64bit(i2, i2); //?? + //UnMap_GPR(Section,i2,true); ?? + } + break; + default: + CPU_Message("Unknown CPU State(%d) in InheritParentInfo", GetMipsRegState(i2)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + } + if (IsConst(i2)) { + if (GetMipsRegState(i2) != RegSet->GetMipsRegState(i2)) + { + switch (RegSet->GetMipsRegState(i2)) + { + case CRegInfo::STATE_MAPPED_64: + Map_GPR_64bit(i2, i2); + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + if (Is32Bit(i2)) + { + Map_GPR_32bit(i2, (GetMipsRegLo(i2) & 0x80000000) != 0, i2); + } + else + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + break; + case CRegInfo::STATE_MAPPED_32_SIGN: + if (Is32Bit(i2)) + { + Map_GPR_32bit(i2, true, i2); + } + else + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + break; + case CRegInfo::STATE_UNKNOWN: + if (g_System->b32BitCore()) + { + Map_GPR_32bit(i2, true, i2); + } + else + { + Map_GPR_64bit(i2, i2); + } + break; + default: + CPU_Message("Unknown CPU State(%d) in InheritParentInfo", RegSet->GetMipsRegState(i2)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + break; + } + } + else if (Is32Bit(i2) && GetMipsRegLo(i2) != RegSet->GetMipsRegLo(i2)) + { + Map_GPR_32bit(i2, true, i2); + } + else if (Is64Bit(i2) && GetMipsReg(i2) != RegSet->GetMipsReg(i2)) + { + Map_GPR_32bit(i2, true, i2); + } + } + ResetX86Protection(); + } - if (MemoryStackPos > 0) - { - Map_MemoryStack(MemoryStackPos, true); - } - } - m_RegEnter = m_RegWorkingSet; + if (MemoryStackPos > 0) + { + Map_MemoryStack(MemoryStackPos, true); + } + } + m_RegEnter = m_RegWorkingSet; - //Sync registers for different blocks - stdstr_f Label("Section_%d", m_SectionID); - int CurrentParent = FirstParent; - bool NeedSync = false; - for (size_t i = 0; i < NoOfCompiledParents; i++) - { - CRegInfo * RegSet; - int i2; + //Sync registers for different blocks + stdstr_f Label("Section_%d", m_SectionID); + int CurrentParent = FirstParent; + bool NeedSync = false; + for (size_t i = 0; i < NoOfCompiledParents; i++) + { + CRegInfo * RegSet; + int i2; - if (i == (size_t)FirstParent) { continue; } - Parent = ParentList[i].Parent; - JumpInfo = ParentList[i].JumpInfo; - RegSet = &ParentList[i].JumpInfo->RegSet; + if (i == (size_t)FirstParent) { continue; } + Parent = ParentList[i].Parent; + JumpInfo = ParentList[i].JumpInfo; + RegSet = &ParentList[i].JumpInfo->RegSet; - if (JumpInfo->RegSet.GetBlockCycleCount() != 0) { NeedSync = true; } + if (JumpInfo->RegSet.GetBlockCycleCount() != 0) { NeedSync = true; } - for (i2 = 0; !NeedSync && i2 < 8; i2++) - { - if (m_RegWorkingSet.FpuMappedTo(i2) == (uint32_t)-1) - { - NeedSync = true; - } - } + for (i2 = 0; !NeedSync && i2 < 8; i2++) + { + if (m_RegWorkingSet.FpuMappedTo(i2) == (uint32_t)-1) + { + NeedSync = true; + } + } - for (i2 = 0; !NeedSync && i2 < sizeof(x86_Registers) / sizeof(x86_Registers[0]); i2++) - { - if (m_RegWorkingSet.GetX86Mapped(x86_Registers[i2]) == CRegInfo::Stack_Mapped) - { - if (m_RegWorkingSet.GetX86Mapped(x86_Registers[i2]) != RegSet->GetX86Mapped(x86_Registers[i2])) - { - NeedSync = true; - } - break; - } - } - for (i2 = 0; !NeedSync && i2 < 32; i2++) - { - if (NeedSync == true) { break; } - if (m_RegWorkingSet.GetMipsRegState(i2) != RegSet->GetMipsRegState(i2)) - { - NeedSync = true; - continue; - } - switch (m_RegWorkingSet.GetMipsRegState(i2)) - { - case CRegInfo::STATE_UNKNOWN: break; - case CRegInfo::STATE_MAPPED_64: - if (GetMipsRegMapHi(i2) != RegSet->GetMipsRegMapHi(i2) || - GetMipsRegMapLo(i2) != RegSet->GetMipsRegMapLo(i2)) - { - NeedSync = true; - } - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - case CRegInfo::STATE_MAPPED_32_SIGN: - if (GetMipsRegMapLo(i2) != RegSet->GetMipsRegMapLo(i2)) - { - //DisplayError(L"Parent: %d",Parent->SectionID); - NeedSync = true; - } - break; - case CRegInfo::STATE_CONST_32_SIGN: - if (GetMipsRegLo(i2) != RegSet->GetMipsRegLo(i2)) - { - g_Notify->BreakPoint(__FILEW__, __LINE__); - NeedSync = true; - } - break; - default: - WriteTraceF(TraceError, __FUNCTION__ ": Unhandled Reg state %d\nin InheritParentInfo", GetMipsRegState(i2)); - g_Notify->BreakPoint(__FILEW__, __LINE__); - } - } - if (NeedSync == false) { continue; } - Parent = ParentList[CurrentParent].Parent; - JumpInfo = ParentList[CurrentParent].JumpInfo; - JmpLabel32(Label.c_str(), 0); - JumpInfo->LinkLocation = (uint32_t *)(m_RecompPos - 4); - JumpInfo->LinkLocation2 = NULL; + for (i2 = 0; !NeedSync && i2 < sizeof(x86_Registers) / sizeof(x86_Registers[0]); i2++) + { + if (m_RegWorkingSet.GetX86Mapped(x86_Registers[i2]) == CRegInfo::Stack_Mapped) + { + if (m_RegWorkingSet.GetX86Mapped(x86_Registers[i2]) != RegSet->GetX86Mapped(x86_Registers[i2])) + { + NeedSync = true; + } + break; + } + } + for (i2 = 0; !NeedSync && i2 < 32; i2++) + { + if (NeedSync == true) { break; } + if (m_RegWorkingSet.GetMipsRegState(i2) != RegSet->GetMipsRegState(i2)) + { + NeedSync = true; + continue; + } + switch (m_RegWorkingSet.GetMipsRegState(i2)) + { + case CRegInfo::STATE_UNKNOWN: break; + case CRegInfo::STATE_MAPPED_64: + if (GetMipsRegMapHi(i2) != RegSet->GetMipsRegMapHi(i2) || + GetMipsRegMapLo(i2) != RegSet->GetMipsRegMapLo(i2)) + { + NeedSync = true; + } + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + case CRegInfo::STATE_MAPPED_32_SIGN: + if (GetMipsRegMapLo(i2) != RegSet->GetMipsRegMapLo(i2)) + { + //DisplayError(L"Parent: %d",Parent->SectionID); + NeedSync = true; + } + break; + case CRegInfo::STATE_CONST_32_SIGN: + if (GetMipsRegLo(i2) != RegSet->GetMipsRegLo(i2)) + { + g_Notify->BreakPoint(__FILEW__, __LINE__); + NeedSync = true; + } + break; + default: + WriteTraceF(TraceError, __FUNCTION__ ": Unhandled Reg state %d\nin InheritParentInfo", GetMipsRegState(i2)); + g_Notify->BreakPoint(__FILEW__, __LINE__); + } + } + if (NeedSync == false) { continue; } + Parent = ParentList[CurrentParent].Parent; + JumpInfo = ParentList[CurrentParent].JumpInfo; + JmpLabel32(Label.c_str(), 0); + JumpInfo->LinkLocation = (uint32_t *)(m_RecompPos - 4); + JumpInfo->LinkLocation2 = NULL; - CurrentParent = i; - Parent = ParentList[CurrentParent].Parent; - JumpInfo = ParentList[CurrentParent].JumpInfo; - CPU_Message(" Section_%d (from %d):", m_SectionID, Parent->m_SectionID); - if (JumpInfo->LinkLocation != NULL) - { - SetJump32(JumpInfo->LinkLocation, (uint32_t *)m_RecompPos); - JumpInfo->LinkLocation = NULL; - if (JumpInfo->LinkLocation2 != NULL) - { - SetJump32(JumpInfo->LinkLocation2, (uint32_t *)m_RecompPos); - JumpInfo->LinkLocation2 = NULL; - } - } - //if (m_EnterPC == 0x8031CE44 && m_SectionID == 6) - //{ - // g_Notify->BreakPoint(__FILEW__,__LINE__); - //} - m_RegWorkingSet = JumpInfo->RegSet; - if (m_EnterPC < JumpInfo->JumpPC) - { - UpdateCounters(m_RegWorkingSet, true, true); - CPU_Message("CompileSystemCheck 11"); - CompileSystemCheck(m_EnterPC, m_RegWorkingSet); - } - else - { - UpdateCounters(m_RegWorkingSet, false, true); - } - SyncRegState(m_RegEnter); //Sync - m_RegEnter = m_RegWorkingSet; - } + CurrentParent = i; + Parent = ParentList[CurrentParent].Parent; + JumpInfo = ParentList[CurrentParent].JumpInfo; + CPU_Message(" Section_%d (from %d):", m_SectionID, Parent->m_SectionID); + if (JumpInfo->LinkLocation != NULL) + { + SetJump32(JumpInfo->LinkLocation, (uint32_t *)m_RecompPos); + JumpInfo->LinkLocation = NULL; + if (JumpInfo->LinkLocation2 != NULL) + { + SetJump32(JumpInfo->LinkLocation2, (uint32_t *)m_RecompPos); + JumpInfo->LinkLocation2 = NULL; + } + } + //if (m_EnterPC == 0x8031CE44 && m_SectionID == 6) + //{ + // g_Notify->BreakPoint(__FILEW__,__LINE__); + //} + m_RegWorkingSet = JumpInfo->RegSet; + if (m_EnterPC < JumpInfo->JumpPC) + { + UpdateCounters(m_RegWorkingSet, true, true); + CPU_Message("CompileSystemCheck 11"); + CompileSystemCheck(m_EnterPC, m_RegWorkingSet); + } + else + { + UpdateCounters(m_RegWorkingSet, false, true); + } + SyncRegState(m_RegEnter); //Sync + m_RegEnter = m_RegWorkingSet; + } - for (size_t i = 0; i < NoOfCompiledParents; i++) - { - Parent = ParentList[i].Parent; - JumpInfo = ParentList[i].JumpInfo; + for (size_t i = 0; i < NoOfCompiledParents; i++) + { + Parent = ParentList[i].Parent; + JumpInfo = ParentList[i].JumpInfo; - if (JumpInfo->LinkLocation != NULL) - { - SetJump32(JumpInfo->LinkLocation, (uint32_t *)m_RecompPos); - JumpInfo->LinkLocation = NULL; - if (JumpInfo->LinkLocation2 != NULL) - { - SetJump32(JumpInfo->LinkLocation2, (uint32_t *)m_RecompPos); - JumpInfo->LinkLocation2 = NULL; - } - } - } + if (JumpInfo->LinkLocation != NULL) + { + SetJump32(JumpInfo->LinkLocation, (uint32_t *)m_RecompPos); + JumpInfo->LinkLocation = NULL; + if (JumpInfo->LinkLocation2 != NULL) + { + SetJump32(JumpInfo->LinkLocation2, (uint32_t *)m_RecompPos); + JumpInfo->LinkLocation2 = NULL; + } + } + } - CPU_Message(" Section_%d:", m_SectionID); - m_RegWorkingSet.SetBlockCycleCount(0); - return true; + CPU_Message(" Section_%d:", m_SectionID); + m_RegWorkingSet.SetBlockCycleCount(0); + return true; } bool CCodeSection::DisplaySectionInformation(uint32_t ID, uint32_t Test) { - if (!bX86Logging) - { - return false; - } - if (this == NULL) { return false; } - if (m_Test == Test) { return false; } - m_Test = Test; - if (m_SectionID != ID) - { - if (m_ContinueSection->DisplaySectionInformation(ID, Test)) { return true; } - if (m_JumpSection->DisplaySectionInformation(ID, Test)) { return true; } - return false; - } - DisplaySectionInformation(); - return true; + if (!bX86Logging) + { + return false; + } + if (this == NULL) { return false; } + if (m_Test == Test) { return false; } + m_Test = Test; + if (m_SectionID != ID) + { + if (m_ContinueSection->DisplaySectionInformation(ID, Test)) { return true; } + if (m_JumpSection->DisplaySectionInformation(ID, Test)) { return true; } + return false; + } + DisplaySectionInformation(); + return true; } void CCodeSection::DisplaySectionInformation() { - if (m_SectionID == 0) - { - return; - } + if (m_SectionID == 0) + { + return; + } - CPU_Message("====== Section %d ======", m_SectionID); - CPU_Message("Start PC: %X", m_EnterPC); - CPU_Message("End PC: %X", m_EndPC); - CPU_Message("CompiledLocation: %X", m_CompiledLocation); - if (!m_ParentSection.empty()) - { - stdstr ParentList; - for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) - { - CCodeSection * Parent = *iter; - if (!ParentList.empty()) - { - ParentList += ", "; - } - ParentList += stdstr_f("%d", Parent->m_SectionID); - } - CPU_Message("Number of parents: %d (%s)", m_ParentSection.size(), ParentList.c_str()); - } + CPU_Message("====== Section %d ======", m_SectionID); + CPU_Message("Start PC: %X", m_EnterPC); + CPU_Message("End PC: %X", m_EndPC); + CPU_Message("CompiledLocation: %X", m_CompiledLocation); + if (!m_ParentSection.empty()) + { + stdstr ParentList; + for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) + { + CCodeSection * Parent = *iter; + if (!ParentList.empty()) + { + ParentList += ", "; + } + ParentList += stdstr_f("%d", Parent->m_SectionID); + } + CPU_Message("Number of parents: %d (%s)", m_ParentSection.size(), ParentList.c_str()); + } - CPU_Message("Jump Address: 0x%08X", m_Jump.JumpPC); - CPU_Message("Jump Target Address: 0x%08X", m_Jump.TargetPC); - if (m_JumpSection != NULL) - { - CPU_Message("Jump Section: %d", m_JumpSection->m_SectionID); - } - else - { - CPU_Message("Jump Section: None"); - } - CPU_Message("Continue Address: 0x%08X", m_Cont.JumpPC); - CPU_Message("Continue Target Address: 0x%08X", m_Cont.TargetPC); - if (m_ContinueSection != NULL) { - CPU_Message("Continue Section: %d", m_ContinueSection->m_SectionID); - } - else - { - CPU_Message("Continue Section: None"); - } - CPU_Message("In Loop: %s", m_InLoop ? "Yes" : "No"); - CPU_Message("======================="); + CPU_Message("Jump Address: 0x%08X", m_Jump.JumpPC); + CPU_Message("Jump Target Address: 0x%08X", m_Jump.TargetPC); + if (m_JumpSection != NULL) + { + CPU_Message("Jump Section: %d", m_JumpSection->m_SectionID); + } + else + { + CPU_Message("Jump Section: None"); + } + CPU_Message("Continue Address: 0x%08X", m_Cont.JumpPC); + CPU_Message("Continue Target Address: 0x%08X", m_Cont.TargetPC); + if (m_ContinueSection != NULL) { + CPU_Message("Continue Section: %d", m_ContinueSection->m_SectionID); + } + else + { + CPU_Message("Continue Section: None"); + } + CPU_Message("In Loop: %s", m_InLoop ? "Yes" : "No"); + CPU_Message("======================="); } \ No newline at end of file diff --git a/Source/Project64/N64 System/Recompiler/Code Section.h b/Source/Project64/N64 System/Recompiler/Code Section.h index 1e192d60f..fdc115ecc 100644 --- a/Source/Project64/N64 System/Recompiler/Code Section.h +++ b/Source/Project64/N64 System/Recompiler/Code Section.h @@ -13,64 +13,64 @@ class CCodeBlock; class CCodeSection : - private CRecompilerOps + private CRecompilerOps { public: - typedef std::list SECTION_LIST; + typedef std::list SECTION_LIST; - CCodeSection(CCodeBlock * CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed); - ~CCodeSection(); + CCodeSection(CCodeBlock * CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed); + ~CCodeSection(); - void SetDelaySlot(); - void SetJumpAddress(uint32_t JumpPC, uint32_t TargetPC, bool PermLoop); - void SetContinueAddress(uint32_t JumpPC, uint32_t TargetPC); - void CompileCop1Test(); - bool GenerateX86Code(uint32_t Test); - void GenerateSectionLinkage(); - void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, bool CompileNow, void(*x86Jmp)(const char * Label, uint32_t Value)); - void DetermineLoop(uint32_t Test, uint32_t Test2, uint32_t TestID); - bool FixConstants(uint32_t Test); - CCodeSection * ExistingSection(uint32_t Addr, uint32_t Test); - bool SectionAccessible(uint32_t SectionId, uint32_t Test); - bool DisplaySectionInformation(uint32_t ID, uint32_t Test); - void DisplaySectionInformation(); - void AddParent(CCodeSection * Parent); - void SwitchParent(CCodeSection * OldParent, CCodeSection * NewParent); + void SetDelaySlot(); + void SetJumpAddress(uint32_t JumpPC, uint32_t TargetPC, bool PermLoop); + void SetContinueAddress(uint32_t JumpPC, uint32_t TargetPC); + void CompileCop1Test(); + bool GenerateX86Code(uint32_t Test); + void GenerateSectionLinkage(); + void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, bool CompileNow, void(*x86Jmp)(const char * Label, uint32_t Value)); + void DetermineLoop(uint32_t Test, uint32_t Test2, uint32_t TestID); + bool FixConstants(uint32_t Test); + CCodeSection * ExistingSection(uint32_t Addr, uint32_t Test); + bool SectionAccessible(uint32_t SectionId, uint32_t Test); + bool DisplaySectionInformation(uint32_t ID, uint32_t Test); + void DisplaySectionInformation(); + void AddParent(CCodeSection * Parent); + void SwitchParent(CCodeSection * OldParent, CCodeSection * NewParent); - /* Block Connection info */ - SECTION_LIST m_ParentSection; - CCodeBlock * const m_BlockInfo; - const uint32_t m_SectionID; - const uint32_t m_EnterPC; - uint32_t m_EndPC; - CCodeSection * m_ContinueSection; - CCodeSection * m_JumpSection; - bool m_EndSection; // if this section does not link - bool m_LinkAllowed; // are other sections allowed to find block to link to it - uint32_t m_Test; - uint32_t m_Test2; - uint8_t * m_CompiledLocation; - bool m_InLoop; - bool m_DelaySlot; + /* Block Connection info */ + SECTION_LIST m_ParentSection; + CCodeBlock * const m_BlockInfo; + const uint32_t m_SectionID; + const uint32_t m_EnterPC; + uint32_t m_EndPC; + CCodeSection * m_ContinueSection; + CCodeSection * m_JumpSection; + bool m_EndSection; // if this section does not link + bool m_LinkAllowed; // are other sections allowed to find block to link to it + uint32_t m_Test; + uint32_t m_Test2; + uint8_t * m_CompiledLocation; + bool m_InLoop; + bool m_DelaySlot; - /* Register Info */ - CRegInfo m_RegEnter; + /* Register Info */ + CRegInfo m_RegEnter; - /* Jump Info */ - CJumpInfo m_Jump; - CJumpInfo m_Cont; + /* Jump Info */ + CJumpInfo m_Jump; + CJumpInfo m_Cont; private: - CCodeSection(void); // Disable default constructor - CCodeSection(const CCodeSection&); // Disable copy constructor - CCodeSection& operator=(const CCodeSection&); // Disable assignment + CCodeSection(void); // Disable default constructor + CCodeSection(const CCodeSection&); // Disable copy constructor + CCodeSection& operator=(const CCodeSection&); // Disable assignment - void UnlinkParent(CCodeSection * Parent, bool ContinueSection); - void InheritConstants(); - void TestRegConstantStates(CRegInfo & Base, CRegInfo & Reg); - void SyncRegState(const CRegInfo & SyncTo); - bool IsAllParentLoops(CCodeSection * Parent, bool IgnoreIfCompiled, uint32_t Test); - bool ParentContinue(); - bool InheritParentInfo(); - bool SetupRegisterForLoop(); + void UnlinkParent(CCodeSection * Parent, bool ContinueSection); + void InheritConstants(); + void TestRegConstantStates(CRegInfo & Base, CRegInfo & Reg); + void SyncRegState(const CRegInfo & SyncTo); + bool IsAllParentLoops(CCodeSection * Parent, bool IgnoreIfCompiled, uint32_t Test); + bool ParentContinue(); + bool InheritParentInfo(); + bool SetupRegisterForLoop(); }; From d7c7882244e58fc050daecb79b6f07aaa36d81c8 Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 14:27:59 +1100 Subject: [PATCH 4/9] [Project64] Fix up headers --- Source/Project64/N64 System/Mips/Eeprom.h | 11 +++++------ .../Project64/N64 System/Recompiler/Code Section.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/Project64/N64 System/Mips/Eeprom.h b/Source/Project64/N64 System/Mips/Eeprom.h index e334dc4c6..86705fbcc 100644 --- a/Source/Project64/N64 System/Mips/Eeprom.h +++ b/Source/Project64/N64 System/Mips/Eeprom.h @@ -9,25 +9,24 @@ * * ****************************************************************************/ #pragma once -#include class CEeprom : private CDebugSettings { public: - CEeprom ( bool ReadOnly ); + CEeprom(bool ReadOnly); ~CEeprom(); - void EepromCommand ( uint8_t * Command ); + void EepromCommand(uint8_t * Command); private: CEeprom(void); // Disable default constructor CEeprom(const CEeprom&); // Disable copy constructor CEeprom& operator=(const CEeprom&); // Disable assignment - void LoadEeprom (); - void ReadFrom ( uint8_t * Buffer, int32_t line ); - void WriteTo ( uint8_t * Buffer, int32_t line ); + void LoadEeprom(); + void ReadFrom(uint8_t * Buffer, int32_t line); + void WriteTo(uint8_t * Buffer, int32_t line); uint8_t m_EEPROM[0x800]; bool m_ReadOnly; diff --git a/Source/Project64/N64 System/Recompiler/Code Section.cpp b/Source/Project64/N64 System/Recompiler/Code Section.cpp index 94c145873..f9c2afa0e 100644 --- a/Source/Project64/N64 System/Recompiler/Code Section.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Section.cpp @@ -9,6 +9,16 @@ * * ****************************************************************************/ #include "stdafx.h" +#include "Code Section.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include void InPermLoop(); @@ -442,6 +452,7 @@ void CCodeSection::GenerateSectionLinkage() // if (g_SyncSystem) { MoveConstToX86reg((uint32_t)g_BaseSystem,x86_ECX); Call_Direct(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); + //} // MoveConstToVariable(DELAY_SLOT,&m_NextInstruction,"m_NextInstruction"); PushImm32(stdstr_f("0x%08X",CompilePC() + 4).c_str(),CompilePC() + 4); From a0b25444f77cb217dbe1340d05024655da73255f Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 14:45:09 +1100 Subject: [PATCH 5/9] [Project64] Clean up Reg Info.cpp --- .../N64 System/Recompiler/Reg Info.cpp | 568 +++++++++--------- .../N64 System/Recompiler/Reg Info.h | 136 ++--- 2 files changed, 352 insertions(+), 352 deletions(-) diff --git a/Source/Project64/N64 System/Recompiler/Reg Info.cpp b/Source/Project64/N64 System/Recompiler/Reg Info.cpp index 3bde33a10..d214b1449 100644 --- a/Source/Project64/N64 System/Recompiler/Reg Info.cpp +++ b/Source/Project64/N64 System/Recompiler/Reg Info.cpp @@ -12,33 +12,33 @@ unsigned int CRegInfo::m_fpuControl = 0; -char *Format_Name[] = {"Unknown","dword","qword","float","double"}; +char *Format_Name[] = { "Unknown", "dword", "qword", "float", "double" }; CRegInfo::CRegInfo() : - m_CycleCount(0), - m_Stack_TopPos(0), - m_Fpu_Used(false), - m_RoundingModel(RoundUnknown) +m_CycleCount(0), +m_Stack_TopPos(0), +m_Fpu_Used(false), +m_RoundingModel(RoundUnknown) { m_MIPS_RegState[0] = STATE_CONST_32_SIGN; m_MIPS_RegVal[0].DW = 0; m_RegMapLo[0] = x86_Unknown; m_RegMapHi[0] = x86_Unknown; - for (int32_t i = 1; i < 32; i++ ) + for (int32_t i = 1; i < 32; i++) { - m_MIPS_RegState[i] = STATE_UNKNOWN; + m_MIPS_RegState[i] = STATE_UNKNOWN; m_MIPS_RegVal[i].DW = 0; m_RegMapLo[i] = x86_Unknown; m_RegMapHi[i] = x86_Unknown; } - for (int32_t i = 0, n = sizeof(m_x86reg_MappedTo) / sizeof(m_x86reg_MappedTo[0]); i < n; i++ ) + for (int32_t i = 0, n = sizeof(m_x86reg_MappedTo) / sizeof(m_x86reg_MappedTo[0]); i < n; i++) { - m_x86reg_MappedTo[i] = NotMapped; + m_x86reg_MappedTo[i] = NotMapped; m_x86reg_Protected[i] = false; - m_x86reg_MapOrder[i] = 0; + m_x86reg_MapOrder[i] = 0; } - for (int32_t i = 0, n = sizeof(m_x86fpu_MappedTo) / sizeof(m_x86fpu_MappedTo[0]); i < n; i++ ) + for (int32_t i = 0, n = sizeof(m_x86fpu_MappedTo) / sizeof(m_x86fpu_MappedTo[0]); i < n; i++) { m_x86fpu_MappedTo[i] = -1; m_x86fpu_State[i] = FPU_Unknown; @@ -63,23 +63,23 @@ CRegInfo& CRegInfo::operator=(const CRegInfo& right) m_Fpu_Used = right.m_Fpu_Used; m_RoundingModel = right.m_RoundingModel; - memcpy(&m_MIPS_RegState,&right.m_MIPS_RegState,sizeof(m_MIPS_RegState)); - memcpy(&m_MIPS_RegVal,&right.m_MIPS_RegVal,sizeof(m_MIPS_RegVal)); - memcpy(&m_RegMapLo,&right.m_RegMapLo,sizeof(m_RegMapLo)); - memcpy(&m_RegMapHi,&right.m_RegMapHi,sizeof(m_RegMapHi)); - memcpy(&m_x86reg_MappedTo,&right.m_x86reg_MappedTo,sizeof(m_x86reg_MappedTo)); - memcpy(&m_x86reg_Protected,&right.m_x86reg_Protected,sizeof(m_x86reg_Protected)); - memcpy(&m_x86reg_MapOrder,&right.m_x86reg_MapOrder,sizeof(m_x86reg_MapOrder)); + memcpy(&m_MIPS_RegState, &right.m_MIPS_RegState, sizeof(m_MIPS_RegState)); + memcpy(&m_MIPS_RegVal, &right.m_MIPS_RegVal, sizeof(m_MIPS_RegVal)); + memcpy(&m_RegMapLo, &right.m_RegMapLo, sizeof(m_RegMapLo)); + memcpy(&m_RegMapHi, &right.m_RegMapHi, sizeof(m_RegMapHi)); + memcpy(&m_x86reg_MappedTo, &right.m_x86reg_MappedTo, sizeof(m_x86reg_MappedTo)); + memcpy(&m_x86reg_Protected, &right.m_x86reg_Protected, sizeof(m_x86reg_Protected)); + memcpy(&m_x86reg_MapOrder, &right.m_x86reg_MapOrder, sizeof(m_x86reg_MapOrder)); - memcpy(&m_x86fpu_MappedTo,&right.m_x86fpu_MappedTo,sizeof(m_x86fpu_MappedTo)); - memcpy(&m_x86fpu_State,&right.m_x86fpu_State,sizeof(m_x86fpu_State)); - memcpy(&m_x86fpu_StateChanged,&right.m_x86fpu_StateChanged,sizeof(m_x86fpu_StateChanged)); - memcpy(&m_x86fpu_RoundingModel,&right.m_x86fpu_RoundingModel,sizeof(m_x86fpu_RoundingModel)); + memcpy(&m_x86fpu_MappedTo, &right.m_x86fpu_MappedTo, sizeof(m_x86fpu_MappedTo)); + memcpy(&m_x86fpu_State, &right.m_x86fpu_State, sizeof(m_x86fpu_State)); + memcpy(&m_x86fpu_StateChanged, &right.m_x86fpu_StateChanged, sizeof(m_x86fpu_StateChanged)); + memcpy(&m_x86fpu_RoundingModel, &right.m_x86fpu_RoundingModel, sizeof(m_x86fpu_RoundingModel)); #ifdef _DEBUG if (*this != right) { - g_Notify->BreakPoint(__FILEW__,__LINE__); + g_Notify->BreakPoint(__FILEW__, __LINE__); } #endif return *this; @@ -89,8 +89,8 @@ bool CRegInfo::operator==(const CRegInfo& right) const { int32_t count; - for (count = 0; count < 32; count ++ ) - { + for (count = 0; count < 32; count++) + { if (m_MIPS_RegState[count] != right.m_MIPS_RegState[count]) { return false; @@ -104,20 +104,20 @@ bool CRegInfo::operator==(const CRegInfo& right) const return false; } } - for (count = 0; count < 10; count ++ ) - { + for (count = 0; count < 10; count++) + { if (m_x86reg_MappedTo[count] != right.m_x86reg_MappedTo[count]) { return false; } if (m_x86reg_Protected[count] != right.m_x86reg_Protected[count]) { return false; } - if (m_x86reg_MapOrder[count] != right.m_x86reg_MapOrder[count]) { return false; } + if (m_x86reg_MapOrder[count] != right.m_x86reg_MapOrder[count]) { return false; } } if (m_CycleCount != right.m_CycleCount) { return false; } if (m_Stack_TopPos != right.m_Stack_TopPos) { return false; } - for (count = 0; count < 8; count ++ ) - { - if (m_x86fpu_MappedTo[count] != right.m_x86fpu_MappedTo[count]) { return false; } - if (m_x86fpu_State[count] != right.m_x86fpu_State[count]) { return false; } - if (m_x86fpu_RoundingModel[count] != right.m_x86fpu_RoundingModel[count]) { return false; } + for (count = 0; count < 8; count++) + { + if (m_x86fpu_MappedTo[count] != right.m_x86fpu_MappedTo[count]) { return false; } + if (m_x86fpu_State[count] != right.m_x86fpu_State[count]) { return false; } + if (m_x86fpu_RoundingModel[count] != right.m_x86fpu_RoundingModel[count]) { return false; } } if (m_Fpu_Used != right.m_Fpu_Used) { return false; } if (GetRoundingModel() != right.GetRoundingModel()) { return false; } @@ -129,20 +129,20 @@ bool CRegInfo::operator!=(const CRegInfo& right) const return !(right == *this); } -CRegInfo::REG_STATE CRegInfo::ConstantsType (int64_t Value) +CRegInfo::REG_STATE CRegInfo::ConstantsType(int64_t Value) { if (((Value >> 32) == -1) && ((Value & 0x80000000) != 0)) { return STATE_CONST_32_SIGN; } if (((Value >> 32) == 0) && ((Value & 0x80000000) == 0)) { return STATE_CONST_32_SIGN; } return STATE_CONST_64; } -void CRegInfo::FixRoundModel(FPU_ROUND RoundMethod ) +void CRegInfo::FixRoundModel(FPU_ROUND RoundMethod) { if (GetRoundingModel() == RoundMethod) { return; } - CPU_Message(" FixRoundModel: CurrentRoundingModel: %s targetRoundModel: %s",RoundingModelName(GetRoundingModel()),RoundingModelName(RoundMethod)); + CPU_Message(" FixRoundModel: CurrentRoundingModel: %s targetRoundModel: %s", RoundingModelName(GetRoundingModel()), RoundingModelName(RoundMethod)); m_fpuControl = 0; fpuStoreControl(&m_fpuControl, "m_fpuControl"); @@ -153,15 +153,15 @@ void CRegInfo::FixRoundModel(FPU_ROUND RoundMethod ) if (RoundMethod == RoundDefault) { x86Reg RoundReg = Map_TempReg(x86_Any, -1, false); - MoveVariableToX86reg(&g_Reg->m_RoundingModel,"m_RoundingModel", RoundReg); - ShiftLeftSignImmed(RoundReg,2); - OrX86RegToX86Reg(reg,RoundReg); - SetX86Protected(RoundReg,false); + MoveVariableToX86reg(&g_Reg->m_RoundingModel, "m_RoundingModel", RoundReg); + ShiftLeftSignImmed(RoundReg, 2); + OrX86RegToX86Reg(reg, RoundReg); + SetX86Protected(RoundReg, false); } - else - { + else + { switch (RoundMethod) - { + { case RoundTruncate: OrConstToX86Reg(0x0C00, reg); break; case RoundNearest: /*OrConstToX86Reg(0x0000, reg);*/ break; case RoundDown: OrConstToX86Reg(0x0400, reg); break; @@ -171,12 +171,12 @@ void CRegInfo::FixRoundModel(FPU_ROUND RoundMethod ) } } MoveX86regToVariable(reg, &m_fpuControl, "m_fpuControl"); - SetX86Protected(reg,false); + SetX86Protected(reg, false); fpuLoadControl(&m_fpuControl, "m_fpuControl"); SetRoundingModel(RoundMethod); } -void CRegInfo::ChangeFPURegFormat (int32_t Reg, FPU_STATE OldFormat, FPU_STATE NewFormat, FPU_ROUND RoundingModel) +void CRegInfo::ChangeFPURegFormat(int32_t Reg, FPU_STATE OldFormat, FPU_STATE NewFormat, FPU_ROUND RoundingModel) { for (uint32_t i = 0; i < 8; i++) { @@ -187,11 +187,11 @@ void CRegInfo::ChangeFPURegFormat (int32_t Reg, FPU_STATE OldFormat, FPU_STATE N if (m_x86fpu_State[i] != OldFormat || m_x86fpu_StateChanged[i]) { UnMap_FPR(Reg, true); - Load_FPR_ToTop(Reg,Reg,OldFormat); + Load_FPR_ToTop(Reg, Reg, OldFormat); } - else - { - CPU_Message(" regcache: Changed format of ST(%d) from %s to %s", (i - StackTopPos() + 8) & 7,Format_Name[OldFormat],Format_Name[NewFormat]); + else + { + CPU_Message(" regcache: Changed format of ST(%d) from %s to %s", (i - StackTopPos() + 8) & 7, Format_Name[OldFormat], Format_Name[NewFormat]); } FpuRoundingModel(i) = RoundingModel; m_x86fpu_State[i] = NewFormat; @@ -205,13 +205,13 @@ void CRegInfo::ChangeFPURegFormat (int32_t Reg, FPU_STATE OldFormat, FPU_STATE N } } -void CRegInfo::Load_FPR_ToTop ( int32_t Reg, int32_t RegToLoad, FPU_STATE Format) +void CRegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Format) { if (GetRoundingModel() != RoundDefault) { FixRoundModel(RoundDefault); } - CPU_Message("CurrentRoundingModel: %s FpuRoundingModel(StackTopPos()): %s",RoundingModelName(GetRoundingModel()),RoundingModelName(FpuRoundingModel(StackTopPos()))); + CPU_Message("CurrentRoundingModel: %s FpuRoundingModel(StackTopPos()): %s", RoundingModelName(GetRoundingModel()), RoundingModelName(FpuRoundingModel(StackTopPos()))); int32_t i; if (RegToLoad < 0) { g_Notify->DisplayError(L"Load_FPR_ToTop\nRegToLoad < 0 ???"); return; } @@ -279,12 +279,12 @@ void CRegInfo::Load_FPR_ToTop ( int32_t Reg, int32_t RegToLoad, FPU_STATE Format { continue; } - UnMap_FPR(Reg,m_x86fpu_State[i] != Format); + UnMap_FPR(Reg, m_x86fpu_State[i] != Format); break; } } - if (RegInStack(RegToLoad,Format)) + if (RegInStack(RegToLoad, Format)) { if (Reg != RegToLoad) { @@ -292,16 +292,16 @@ void CRegInfo::Load_FPR_ToTop ( int32_t Reg, int32_t RegToLoad, FPU_STATE Format { UnMap_FPR(m_x86fpu_MappedTo[(StackTopPos() - 1) & 7], true); CPU_Message(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]); - fpuLoadReg(&StackTopPos(),StackPosition(RegToLoad)); - FpuRoundingModel(StackTopPos()) = RoundDefault; - m_x86fpu_MappedTo[StackTopPos()] = Reg; - m_x86fpu_State[StackTopPos()] = Format; + fpuLoadReg(&StackTopPos(), StackPosition(RegToLoad)); + FpuRoundingModel(StackTopPos()) = RoundDefault; + m_x86fpu_MappedTo[StackTopPos()] = Reg; + m_x86fpu_State[StackTopPos()] = Format; m_x86fpu_StateChanged[StackTopPos()] = false; } else { UnMap_FPR(m_x86fpu_MappedTo[(StackTopPos() - 1) & 7], true); - Load_FPR_ToTop (Reg, RegToLoad, Format); + Load_FPR_ToTop(Reg, RegToLoad, Format); } } else @@ -323,18 +323,18 @@ void CRegInfo::Load_FPR_ToTop ( int32_t Reg, int32_t RegToLoad, FPU_STATE Format x86FpuValues StackPos = StackPosition(Reg); FpuRoundingModel(RegPos) = FpuRoundingModel(StackTopPos()); - m_x86fpu_MappedTo[RegPos] = m_x86fpu_MappedTo[StackTopPos()]; - m_x86fpu_State[RegPos] = m_x86fpu_State[StackTopPos()]; + m_x86fpu_MappedTo[RegPos] = m_x86fpu_MappedTo[StackTopPos()]; + m_x86fpu_State[RegPos] = m_x86fpu_State[StackTopPos()]; m_x86fpu_StateChanged[RegPos] = m_x86fpu_StateChanged[StackTopPos()]; - CPU_Message(" regcache: allocate ST(%d) to %s", StackPos,CRegName::FPR[m_x86fpu_MappedTo[RegPos]]); + CPU_Message(" regcache: allocate ST(%d) to %s", StackPos, CRegName::FPR[m_x86fpu_MappedTo[RegPos]]); CPU_Message(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]); fpuExchange(StackPos); FpuRoundingModel(StackTopPos()) = RoundDefault; - m_x86fpu_MappedTo[StackTopPos()] = Reg; - m_x86fpu_State[StackTopPos()] = Format; - m_x86fpu_StateChanged[StackTopPos()] = false; + m_x86fpu_MappedTo[StackTopPos()] = Reg; + m_x86fpu_State[StackTopPos()] = Format; + m_x86fpu_StateChanged[StackTopPos()] = false; } } else @@ -356,37 +356,37 @@ void CRegInfo::Load_FPR_ToTop ( int32_t Reg, int32_t RegToLoad, FPU_STATE Format switch (Format) { case FPU_Dword: - sprintf(Name,"m_FPR_S[%d]",RegToLoad); - MoveVariableToX86reg(&g_Reg->m_FPR_S[RegToLoad],Name,TempReg); - fpuLoadIntegerDwordFromX86Reg(&StackTopPos(),TempReg); + sprintf(Name, "m_FPR_S[%d]", RegToLoad); + MoveVariableToX86reg(&g_Reg->m_FPR_S[RegToLoad], Name, TempReg); + fpuLoadIntegerDwordFromX86Reg(&StackTopPos(), TempReg); break; case FPU_Qword: - sprintf(Name,"m_FPR_D[%d]",RegToLoad); - MoveVariableToX86reg(&g_Reg->m_FPR_D[RegToLoad],Name,TempReg); - fpuLoadIntegerQwordFromX86Reg(&StackTopPos(),TempReg); + sprintf(Name, "m_FPR_D[%d]", RegToLoad); + MoveVariableToX86reg(&g_Reg->m_FPR_D[RegToLoad], Name, TempReg); + fpuLoadIntegerQwordFromX86Reg(&StackTopPos(), TempReg); break; case FPU_Float: - sprintf(Name,"m_FPR_S[%d]",RegToLoad); - MoveVariableToX86reg(&g_Reg->m_FPR_S[RegToLoad],Name,TempReg); - fpuLoadDwordFromX86Reg(&StackTopPos(),TempReg); + sprintf(Name, "m_FPR_S[%d]", RegToLoad); + MoveVariableToX86reg(&g_Reg->m_FPR_S[RegToLoad], Name, TempReg); + fpuLoadDwordFromX86Reg(&StackTopPos(), TempReg); break; case FPU_Double: - sprintf(Name,"m_FPR_D[%d]",RegToLoad); - MoveVariableToX86reg(&g_Reg->m_FPR_D[RegToLoad],Name,TempReg); - fpuLoadQwordFromX86Reg(&StackTopPos(),TempReg); + sprintf(Name, "m_FPR_D[%d]", RegToLoad); + MoveVariableToX86reg(&g_Reg->m_FPR_D[RegToLoad], Name, TempReg); + fpuLoadQwordFromX86Reg(&StackTopPos(), TempReg); break; default: - if (bHaveDebugger()) { g_Notify->DisplayError(stdstr_f("Load_FPR_ToTop\nUnkown format to load %d",Format).ToUTF16().c_str()); } + if (bHaveDebugger()) { g_Notify->DisplayError(stdstr_f("Load_FPR_ToTop\nUnkown format to load %d", Format).ToUTF16().c_str()); } } SetX86Protected(TempReg, false); FpuRoundingModel(StackTopPos()) = RoundDefault; - m_x86fpu_MappedTo[StackTopPos()] = Reg; - m_x86fpu_State[StackTopPos()] = Format; - m_x86fpu_StateChanged[StackTopPos()] = false; + m_x86fpu_MappedTo[StackTopPos()] = Reg; + m_x86fpu_State[StackTopPos()] = Format; + m_x86fpu_StateChanged[StackTopPos()] = false; } } -CRegInfo::x86FpuValues CRegInfo::StackPosition (int32_t Reg) +CRegInfo::x86FpuValues CRegInfo::StackPosition(int32_t Reg) { int32_t i; @@ -415,34 +415,34 @@ CX86Ops::x86Reg CRegInfo::FreeX86Reg() int32_t count, MapCount[10]; x86Reg MapReg[10]; - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { MapCount[count] = GetX86MapOrder((x86Reg)count); MapReg[count] = (x86Reg)count; } - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { int32_t i; - for (i = 0; i < 9; i ++) + for (i = 0; i < 9; i++) { x86Reg tempReg; uint32_t temp; - if (MapCount[i] < MapCount[i+1]) + if (MapCount[i] < MapCount[i + 1]) { temp = MapCount[i]; - MapCount[i] = MapCount[i+1]; - MapCount[i+1] = temp; + MapCount[i] = MapCount[i + 1]; + MapCount[i + 1] = temp; tempReg = MapReg[i]; - MapReg[i] = MapReg[i+1]; - MapReg[i+1] = tempReg; + MapReg[i] = MapReg[i + 1]; + MapReg[i + 1] = tempReg; } } } x86Reg StackReg = x86_Unknown; - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { if (MapCount[count] > 0 && GetX86Mapped(MapReg[count]) != Stack_Mapped) { @@ -464,47 +464,47 @@ CX86Ops::x86Reg CRegInfo::FreeX86Reg() CX86Ops::x86Reg CRegInfo::Free8BitX86Reg() { - if (GetX86Mapped(x86_EBX) == NotMapped && !GetX86Protected(x86_EBX)) {return x86_EBX; } - if (GetX86Mapped(x86_EAX) == NotMapped && !GetX86Protected(x86_EAX)) {return x86_EAX; } - if (GetX86Mapped(x86_EDX) == NotMapped && !GetX86Protected(x86_EDX)) {return x86_EDX; } - if (GetX86Mapped(x86_ECX) == NotMapped && !GetX86Protected(x86_ECX)) {return x86_ECX; } + if (GetX86Mapped(x86_EBX) == NotMapped && !GetX86Protected(x86_EBX)) { return x86_EBX; } + if (GetX86Mapped(x86_EAX) == NotMapped && !GetX86Protected(x86_EAX)) { return x86_EAX; } + if (GetX86Mapped(x86_EDX) == NotMapped && !GetX86Protected(x86_EDX)) { return x86_EDX; } + if (GetX86Mapped(x86_ECX) == NotMapped && !GetX86Protected(x86_ECX)) { return x86_ECX; } x86Reg Reg = UnMap_8BitTempReg(); if (Reg > 0) - { - return Reg; - } + { + return Reg; + } int32_t count, MapCount[10], MapReg[10]; - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { MapCount[count] = GetX86MapOrder((x86Reg)count); MapReg[count] = count; } - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { int32_t i; - for (i = 0; i < 9; i ++) + for (i = 0; i < 9; i++) { int32_t temp; - if (MapCount[i] < MapCount[i+1]) + if (MapCount[i] < MapCount[i + 1]) { temp = MapCount[i]; - MapCount[i] = MapCount[i+1]; - MapCount[i+1] = temp; + MapCount[i] = MapCount[i + 1]; + MapCount[i + 1] = temp; temp = MapReg[i]; - MapReg[i] = MapReg[i+1]; - MapReg[i+1] = temp; + MapReg[i] = MapReg[i + 1]; + MapReg[i + 1] = temp; } } } - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { if (MapCount[count] > 0) { - if (!Is8BitReg((x86Reg)count)) { continue; } + if (!Is8BitReg((x86Reg)count)) { continue; } if (UnMap_X86reg((x86Reg)count)) { return (x86Reg)count; @@ -518,14 +518,14 @@ CX86Ops::x86Reg CRegInfo::UnMap_8BitTempReg() { int32_t count; - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { if (!Is8BitReg((x86Reg)count)) { continue; } if (GetMipsRegState((x86Reg)count) == Temp_Mapped) { if (GetX86Protected((x86Reg)count) == false) { - CPU_Message(" regcache: unallocate %s from temp storage",x86_Name((x86Reg)count)); + CPU_Message(" regcache: unallocate %s from temp storage", x86_Name((x86Reg)count)); SetX86Mapped((x86Reg)count, CRegInfo::NotMapped); return (x86Reg)count; } @@ -536,7 +536,7 @@ CX86Ops::x86Reg CRegInfo::UnMap_8BitTempReg() CRegInfo::x86Reg CRegInfo::Get_MemoryStack() const { - for (int32_t i = 0, n = sizeof(x86_Registers)/ sizeof(x86_Registers[0]); i < n; i++) + for (int32_t i = 0, n = sizeof(x86_Registers) / sizeof(x86_Registers[0]); i < n; i++) { if (GetX86Mapped(x86_Registers[i]) == Stack_Mapped) { @@ -546,7 +546,7 @@ CRegInfo::x86Reg CRegInfo::Get_MemoryStack() const return x86_Unknown; } -CRegInfo::x86Reg CRegInfo::Map_MemoryStack ( x86Reg Reg, bool bMapRegister, bool LoadValue) +CRegInfo::x86Reg CRegInfo::Map_MemoryStack(x86Reg Reg, bool bMapRegister, bool LoadValue) { x86Reg CurrentMap = Get_MemoryStack(); if (!bMapRegister) @@ -571,13 +571,13 @@ CRegInfo::x86Reg CRegInfo::Map_MemoryStack ( x86Reg Reg, bool bMapRegister, bool if (Reg == x86_Unknown) { g_Notify->DisplayError(L"Map_MemoryStack\n\nOut of registers"); - g_Notify->BreakPoint(__FILEW__,__LINE__); + g_Notify->BreakPoint(__FILEW__, __LINE__); } - SetX86Mapped(Reg,CRegInfo::Stack_Mapped); - CPU_Message(" regcache: allocate %s as Memory Stack",x86_Name(Reg)); + SetX86Mapped(Reg, CRegInfo::Stack_Mapped); + CPU_Message(" regcache: allocate %s as Memory Stack", x86_Name(Reg)); if (LoadValue) { - MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(),"MemoryStack",Reg); + MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", Reg); } return Reg; } @@ -586,31 +586,31 @@ CRegInfo::x86Reg CRegInfo::Map_MemoryStack ( x86Reg Reg, bool bMapRegister, bool UnMap_X86reg(Reg); if (CurrentMap != x86_Unknown) { - CPU_Message(" regcache: change allocation of Memory Stack from %s to %s",x86_Name(CurrentMap),x86_Name(Reg)); + CPU_Message(" regcache: change allocation of Memory Stack from %s to %s", x86_Name(CurrentMap), x86_Name(Reg)); SetX86Mapped(Reg, CRegInfo::Stack_Mapped); - SetX86Mapped(CurrentMap,CRegInfo::NotMapped); - MoveX86RegToX86Reg(CurrentMap,Reg); + SetX86Mapped(CurrentMap, CRegInfo::NotMapped); + MoveX86RegToX86Reg(CurrentMap, Reg); } - else - { - SetX86Mapped(Reg,CRegInfo::Stack_Mapped); - CPU_Message(" regcache: allocate %s as Memory Stack",x86_Name(Reg)); + else + { + SetX86Mapped(Reg, CRegInfo::Stack_Mapped); + CPU_Message(" regcache: allocate %s as Memory Stack", x86_Name(Reg)); if (LoadValue) { - MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(),"MemoryStack",Reg); + MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", Reg); } } return Reg; } -void CRegInfo::Map_GPR_32bit (int32_t MipsReg, bool SignValue, int32_t MipsRegToLoad) +void CRegInfo::Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t MipsRegToLoad) { int32_t count; x86Reg Reg; if (MipsReg == 0) { - g_Notify->BreakPoint(__FILEW__,__LINE__); + g_Notify->BreakPoint(__FILEW__, __LINE__); return; } @@ -620,62 +620,62 @@ void CRegInfo::Map_GPR_32bit (int32_t MipsReg, bool SignValue, int32_t MipsRegTo if (Reg < 0) { if (bHaveDebugger()) { g_Notify->DisplayError(L"Map_GPR_32bit\n\nOut of registers"); } - g_Notify->BreakPoint(__FILEW__,__LINE__); + g_Notify->BreakPoint(__FILEW__, __LINE__); return; } - CPU_Message(" regcache: allocate %s to %s",x86_Name(Reg),CRegName::GPR[MipsReg]); + CPU_Message(" regcache: allocate %s to %s", x86_Name(Reg), CRegName::GPR[MipsReg]); } else { if (Is64Bit(MipsReg)) { - CPU_Message(" regcache: unallocate %s from high 32bit of %s",x86_Name(GetMipsRegMapHi(MipsReg)),CRegName::GPR_Hi[MipsReg]); - SetX86MapOrder(GetMipsRegMapHi(MipsReg),0); - SetX86Mapped(GetMipsRegMapHi(MipsReg),NotMapped); + CPU_Message(" regcache: unallocate %s from high 32bit of %s", x86_Name(GetMipsRegMapHi(MipsReg)), CRegName::GPR_Hi[MipsReg]); + SetX86MapOrder(GetMipsRegMapHi(MipsReg), 0); + SetX86Mapped(GetMipsRegMapHi(MipsReg), NotMapped); SetX86Protected(GetMipsRegMapHi(MipsReg), false); - SetMipsRegHi(MipsReg,0); + SetMipsRegHi(MipsReg, 0); } Reg = GetMipsRegMapLo(MipsReg); } - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { uint32_t Count = GetX86MapOrder((x86Reg)count); - if ( Count > 0) + if (Count > 0) { - SetX86MapOrder((x86Reg)count,Count + 1); + SetX86MapOrder((x86Reg)count, Count + 1); } } - SetX86MapOrder(Reg,1); + SetX86MapOrder(Reg, 1); if (MipsRegToLoad > 0) { if (IsUnknown(MipsRegToLoad)) { - MoveVariableToX86reg(&_GPR[MipsRegToLoad].UW[0],CRegName::GPR_Lo[MipsRegToLoad],Reg); + MoveVariableToX86reg(&_GPR[MipsRegToLoad].UW[0], CRegName::GPR_Lo[MipsRegToLoad], Reg); } else if (IsMapped(MipsRegToLoad)) { if (MipsReg != MipsRegToLoad) { - MoveX86RegToX86Reg(GetMipsRegMapLo(MipsRegToLoad),Reg); + MoveX86RegToX86Reg(GetMipsRegMapLo(MipsRegToLoad), Reg); } } - else - { - MoveConstToX86reg(GetMipsRegLo(MipsRegToLoad),Reg); + else + { + MoveConstToX86reg(GetMipsRegLo(MipsRegToLoad), Reg); } } else if (MipsRegToLoad == 0) { - XorX86RegToX86Reg(Reg,Reg); + XorX86RegToX86Reg(Reg, Reg); } - SetX86Mapped(Reg,GPR_Mapped); + SetX86Mapped(Reg, GPR_Mapped); SetX86Protected(Reg, true); - SetMipsRegMapLo(MipsReg,Reg); - SetMipsRegState(MipsReg,SignValue ? STATE_MAPPED_32_SIGN : STATE_MAPPED_32_ZERO); + SetMipsRegMapLo(MipsReg, Reg); + SetMipsRegState(MipsReg, SignValue ? STATE_MAPPED_32_SIGN : STATE_MAPPED_32_ZERO); } -void CRegInfo::Map_GPR_64bit ( int32_t MipsReg, int32_t MipsRegToLoad) +void CRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad) { x86Reg x86Hi, x86lo; int32_t count; @@ -698,11 +698,11 @@ void CRegInfo::Map_GPR_64bit ( int32_t MipsReg, int32_t MipsRegToLoad) SetX86Protected(x86Hi, true); x86lo = FreeX86Reg(); - if (x86lo < 0) { g_Notify->DisplayError(L"Map_GPR_64bit\n\nOut of registers"); return; } + if (x86lo < 0) { g_Notify->DisplayError(L"Map_GPR_64bit\n\nOut of registers"); return; } SetX86Protected(x86lo, true); - CPU_Message(" regcache: allocate %s to hi word of %s",x86_Name(x86Hi),CRegName::GPR[MipsReg]); - CPU_Message(" regcache: allocate %s to low word of %s",x86_Name(x86lo),CRegName::GPR[MipsReg]); + CPU_Message(" regcache: allocate %s to hi word of %s", x86_Name(x86Hi), CRegName::GPR[MipsReg]); + CPU_Message(" regcache: allocate %s to low word of %s", x86_Name(x86lo), CRegName::GPR[MipsReg]); } else { @@ -713,12 +713,12 @@ void CRegInfo::Map_GPR_64bit ( int32_t MipsReg, int32_t MipsRegToLoad) x86Hi = FreeX86Reg(); if (x86Hi == x86_Unknown) { - g_Notify->BreakPoint(__FILEW__,__LINE__); + g_Notify->BreakPoint(__FILEW__, __LINE__); return; } SetX86Protected(x86Hi, true); - CPU_Message(" regcache: allocate %s to hi word of %s",x86_Name(x86Hi),CRegName::GPR[MipsReg]); + CPU_Message(" regcache: allocate %s to hi word of %s", x86_Name(x86Hi), CRegName::GPR[MipsReg]); } else { @@ -726,23 +726,23 @@ void CRegInfo::Map_GPR_64bit ( int32_t MipsReg, int32_t MipsRegToLoad) } } - for (count = 0; count < 10; count ++) + for (count = 0; count < 10; count++) { int32_t MapOrder = GetX86MapOrder((x86Reg)count); if (MapOrder > 0) { - SetX86MapOrder((x86Reg)count,MapOrder + 1); + SetX86MapOrder((x86Reg)count, MapOrder + 1); } } - SetX86MapOrder(x86Hi,1); - SetX86MapOrder(x86lo,1); + SetX86MapOrder(x86Hi, 1); + SetX86MapOrder(x86lo, 1); if (MipsRegToLoad > 0) { if (IsUnknown(MipsRegToLoad)) { - MoveVariableToX86reg(&_GPR[MipsRegToLoad].UW[1],CRegName::GPR_Hi[MipsRegToLoad],x86Hi); - MoveVariableToX86reg(&_GPR[MipsRegToLoad].UW[0],CRegName::GPR_Lo[MipsRegToLoad],x86lo); + MoveVariableToX86reg(&_GPR[MipsRegToLoad].UW[1], CRegName::GPR_Hi[MipsRegToLoad], x86Hi); + MoveVariableToX86reg(&_GPR[MipsRegToLoad].UW[0], CRegName::GPR_Lo[MipsRegToLoad], x86lo); } else if (IsMapped(MipsRegToLoad)) { @@ -750,24 +750,24 @@ void CRegInfo::Map_GPR_64bit ( int32_t MipsReg, int32_t MipsRegToLoad) { if (IsSigned(MipsRegToLoad)) { - MoveX86RegToX86Reg(GetMipsRegMapLo(MipsRegToLoad),x86Hi); - ShiftRightSignImmed(x86Hi,31); + MoveX86RegToX86Reg(GetMipsRegMapLo(MipsRegToLoad), x86Hi); + ShiftRightSignImmed(x86Hi, 31); } else { - XorX86RegToX86Reg(x86Hi,x86Hi); + XorX86RegToX86Reg(x86Hi, x86Hi); } if (MipsReg != MipsRegToLoad) { - MoveX86RegToX86Reg(GetMipsRegMapLo(MipsRegToLoad),x86lo); + MoveX86RegToX86Reg(GetMipsRegMapLo(MipsRegToLoad), x86lo); } } else { if (MipsReg != MipsRegToLoad) { - MoveX86RegToX86Reg(GetMipsRegMapHi(MipsRegToLoad),x86Hi); - MoveX86RegToX86Reg(GetMipsRegMapLo(MipsRegToLoad),x86lo); + MoveX86RegToX86Reg(GetMipsRegMapHi(MipsRegToLoad), x86Hi); + MoveX86RegToX86Reg(GetMipsRegMapLo(MipsRegToLoad), x86lo); } } } @@ -778,33 +778,33 @@ void CRegInfo::Map_GPR_64bit ( int32_t MipsReg, int32_t MipsRegToLoad) { if (IsSigned(MipsRegToLoad)) { - MoveConstToX86reg(GetMipsRegLo_S(MipsRegToLoad) >> 31,x86Hi); + MoveConstToX86reg(GetMipsRegLo_S(MipsRegToLoad) >> 31, x86Hi); } else { - MoveConstToX86reg(0,x86Hi); + MoveConstToX86reg(0, x86Hi); } } else { - MoveConstToX86reg(GetMipsRegHi(MipsRegToLoad),x86Hi); + MoveConstToX86reg(GetMipsRegHi(MipsRegToLoad), x86Hi); } - MoveConstToX86reg(GetMipsRegLo(MipsRegToLoad),x86lo); + MoveConstToX86reg(GetMipsRegLo(MipsRegToLoad), x86lo); } } else if (MipsRegToLoad == 0) { - XorX86RegToX86Reg(x86Hi,x86Hi); - XorX86RegToX86Reg(x86lo,x86lo); + XorX86RegToX86Reg(x86Hi, x86Hi); + XorX86RegToX86Reg(x86lo, x86lo); } - SetX86Mapped(x86Hi,GPR_Mapped); - SetX86Mapped(x86lo,GPR_Mapped); - SetMipsRegMapHi(MipsReg,x86Hi); - SetMipsRegMapLo(MipsReg,x86lo); - SetMipsRegState(MipsReg,STATE_MAPPED_64); + SetX86Mapped(x86Hi, GPR_Mapped); + SetX86Mapped(x86lo, GPR_Mapped); + SetMipsRegMapHi(MipsReg, x86Hi); + SetMipsRegMapLo(MipsReg, x86lo); + SetMipsRegState(MipsReg, STATE_MAPPED_64); } -CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, bool LoadHiWord) +CX86Ops::x86Reg CRegInfo::Map_TempReg(CX86Ops::x86Reg Reg, int32_t MipsReg, bool LoadHiWord) { int32_t count; @@ -824,8 +824,8 @@ CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, boo Reg = FreeX86Reg(); if (Reg == x86_Unknown) { - WriteTrace(TraceError,__FUNCTION__ ": Failed to find a free register"); - g_Notify->BreakPoint(__FILEW__,__LINE__); + WriteTrace(TraceError, __FUNCTION__ ": Failed to find a free register"); + g_Notify->BreakPoint(__FILEW__, __LINE__); return x86_Unknown; } } @@ -842,8 +842,8 @@ CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, boo Reg = Free8BitX86Reg(); if (Reg < 0) { - WriteTrace(TraceError,__FUNCTION__ ": Failed to find a free 8 bit register"); - g_Notify->BreakPoint(__FILEW__,__LINE__); + WriteTrace(TraceError, __FUNCTION__ ": Failed to find a free 8 bit register"); + g_Notify->BreakPoint(__FILEW__, __LINE__); return x86_Unknown; } } @@ -852,14 +852,14 @@ CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, boo { if (GetX86Protected(Reg)) { - WriteTrace(TraceError,__FUNCTION__ ": Register is protected"); - g_Notify->BreakPoint(__FILEW__,__LINE__); + WriteTrace(TraceError, __FUNCTION__ ": Register is protected"); + g_Notify->BreakPoint(__FILEW__, __LINE__); return x86_Unknown; } - SetX86Protected(Reg,true); + SetX86Protected(Reg, true); x86Reg NewReg = FreeX86Reg(); - for (count = 1; count < 32; count ++) + for (count = 1; count < 32; count++) { if (!IsMapped(count)) { @@ -872,11 +872,11 @@ CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, boo UnMap_GPR(count, true); break; } - CPU_Message(" regcache: change allocation of %s from %s to %s",CRegName::GPR[count],x86_Name(Reg),x86_Name(NewReg)); - SetX86Mapped(NewReg,GPR_Mapped); - SetX86MapOrder(NewReg,GetX86MapOrder(Reg)); - SetMipsRegMapLo(count,NewReg); - MoveX86RegToX86Reg(Reg,NewReg); + CPU_Message(" regcache: change allocation of %s from %s to %s", CRegName::GPR[count], x86_Name(Reg), x86_Name(NewReg)); + SetX86Mapped(NewReg, GPR_Mapped); + SetX86MapOrder(NewReg, GetX86MapOrder(Reg)); + SetMipsRegMapLo(count, NewReg); + MoveX86RegToX86Reg(Reg, NewReg); if (MipsReg == count && !LoadHiWord) { MipsReg = -1; @@ -890,15 +890,15 @@ CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, boo UnMap_GPR(count, true); break; } - CPU_Message(" regcache: change allocation of %s from %s to %s",CRegName::GPR_Hi[count],x86_Name(Reg),x86_Name(NewReg)); - SetX86Mapped(NewReg,GPR_Mapped); - SetX86MapOrder(NewReg,GetX86MapOrder(Reg)); - SetMipsRegMapHi(count,NewReg); - MoveX86RegToX86Reg(Reg,NewReg); + CPU_Message(" regcache: change allocation of %s from %s to %s", CRegName::GPR_Hi[count], x86_Name(Reg), x86_Name(NewReg)); + SetX86Mapped(NewReg, GPR_Mapped); + SetX86MapOrder(NewReg, GetX86MapOrder(Reg)); + SetMipsRegMapHi(count, NewReg); + MoveX86RegToX86Reg(Reg, NewReg); if (MipsReg == count && LoadHiWord) - { + { MipsReg = -1; - } + } break; } } @@ -907,7 +907,7 @@ CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, boo { UnMap_X86reg(Reg); } - CPU_Message(" regcache: allocate %s as temp storage",x86_Name(Reg)); + CPU_Message(" regcache: allocate %s as temp storage", x86_Name(Reg)); if (MipsReg >= 0) { @@ -915,33 +915,33 @@ CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, boo { if (IsUnknown(MipsReg)) { - MoveVariableToX86reg(&_GPR[MipsReg].UW[1],CRegName::GPR_Hi[MipsReg],Reg); + MoveVariableToX86reg(&_GPR[MipsReg].UW[1], CRegName::GPR_Hi[MipsReg], Reg); } else if (IsMapped(MipsReg)) { if (Is64Bit(MipsReg)) { - MoveX86RegToX86Reg(GetMipsRegMapHi(MipsReg),Reg); + MoveX86RegToX86Reg(GetMipsRegMapHi(MipsReg), Reg); } else if (IsSigned(MipsReg)) { - MoveX86RegToX86Reg(GetMipsRegMapLo(MipsReg),Reg); - ShiftRightSignImmed(Reg,31); + MoveX86RegToX86Reg(GetMipsRegMapLo(MipsReg), Reg); + ShiftRightSignImmed(Reg, 31); } else { - MoveConstToX86reg(0,Reg); + MoveConstToX86reg(0, Reg); } } else { if (Is64Bit(MipsReg)) { - MoveConstToX86reg(GetMipsRegHi(MipsReg),Reg); + MoveConstToX86reg(GetMipsRegHi(MipsReg), Reg); } else { - MoveConstToX86reg(GetMipsRegLo_S(MipsReg) >> 31,Reg); + MoveConstToX86reg(GetMipsRegLo_S(MipsReg) >> 31, Reg); } } } @@ -949,29 +949,29 @@ CX86Ops::x86Reg CRegInfo::Map_TempReg (CX86Ops::x86Reg Reg, int32_t MipsReg, boo { if (IsUnknown(MipsReg)) { - MoveVariableToX86reg(&_GPR[MipsReg].UW[0],CRegName::GPR_Lo[MipsReg],Reg); + MoveVariableToX86reg(&_GPR[MipsReg].UW[0], CRegName::GPR_Lo[MipsReg], Reg); } else if (IsMapped(MipsReg)) { - MoveX86RegToX86Reg(GetMipsRegMapLo(MipsReg),Reg); + MoveX86RegToX86Reg(GetMipsRegMapLo(MipsReg), Reg); } else { - MoveConstToX86reg(GetMipsRegLo(MipsReg),Reg); + MoveConstToX86reg(GetMipsRegLo(MipsReg), Reg); } } } - SetX86Mapped(Reg,Temp_Mapped); + SetX86Mapped(Reg, Temp_Mapped); SetX86Protected(Reg, true); for (count = 0; count < 10; count++) { int32_t MapOrder = GetX86MapOrder((x86Reg)count); if (MapOrder > 0) { - SetX86MapOrder((x86Reg)count,MapOrder + 1); + SetX86MapOrder((x86Reg)count, MapOrder + 1); } } - SetX86MapOrder(Reg,1); + SetX86MapOrder(Reg, 1); return Reg; } @@ -998,18 +998,18 @@ void CRegInfo::UnProtectGPR(uint32_t Reg) { SetX86Protected(GetMipsRegMapHi(Reg), false); } - SetX86Protected(GetMipsRegMapLo(Reg),false); + SetX86Protected(GetMipsRegMapLo(Reg), false); } void CRegInfo::ResetX86Protection() { - for (int32_t count = 0; count < 10; count ++) + for (int32_t count = 0; count < 10; count++) { SetX86Protected((x86Reg)count, false); } } -bool CRegInfo::RegInStack( int32_t Reg, FPU_STATE Format) +bool CRegInfo::RegInStack(int32_t Reg, FPU_STATE Format) { for (int32_t i = 0; i < 8; i++) { @@ -1030,7 +1030,7 @@ void CRegInfo::UnMap_AllFPRs() for (;;) { int32_t StackPos = StackTopPos(); - if (m_x86fpu_MappedTo[StackPos] != -1 ) + if (m_x86fpu_MappedTo[StackPos] != -1) { UnMap_FPR(m_x86fpu_MappedTo[StackPos], true); continue; @@ -1039,14 +1039,14 @@ void CRegInfo::UnMap_AllFPRs() int32_t StartPos = StackTopPos(); for (int32_t i = 0; i < 8; i++) { - if (m_x86fpu_MappedTo[(StartPos + i) & 7] != -1 ) { fpuIncStack(&StackTopPos()); } + if (m_x86fpu_MappedTo[(StartPos + i) & 7] != -1) { fpuIncStack(&StackTopPos()); } } if (StackPos != StackTopPos()) { continue; } return; } } -void CRegInfo::UnMap_FPR (int32_t Reg, bool WriteBackValue ) +void CRegInfo::UnMap_FPR(int32_t Reg, bool WriteBackValue) { char Name[50]; int32_t i; @@ -1055,7 +1055,7 @@ void CRegInfo::UnMap_FPR (int32_t Reg, bool WriteBackValue ) for (i = 0; i < 8; i++) { if (m_x86fpu_MappedTo[i] != Reg) { continue; } - CPU_Message(" regcache: unallocate %s from ST(%d)",CRegName::FPR[Reg],(i - StackTopPos() + 8) & 7); + CPU_Message(" regcache: unallocate %s from ST(%d)", CRegName::FPR[Reg], (i - StackTopPos() + 8) & 7); if (WriteBackValue) { int32_t RegPos; @@ -1069,17 +1069,17 @@ void CRegInfo::UnMap_FPR (int32_t Reg, bool WriteBackValue ) else { CRegInfo::FPU_ROUND RoundingModel = FpuRoundingModel(StackTopPos()); - FPU_STATE RegState = m_x86fpu_State[StackTopPos()]; - bool Changed = m_x86fpu_StateChanged[StackTopPos()]; - uint32_t MappedTo = m_x86fpu_MappedTo[StackTopPos()]; + FPU_STATE RegState = m_x86fpu_State[StackTopPos()]; + bool Changed = m_x86fpu_StateChanged[StackTopPos()]; + uint32_t MappedTo = m_x86fpu_MappedTo[StackTopPos()]; FpuRoundingModel(StackTopPos()) = FpuRoundingModel(i); - m_x86fpu_MappedTo[StackTopPos()] = m_x86fpu_MappedTo[i]; - m_x86fpu_State[StackTopPos()] = m_x86fpu_State[i]; + m_x86fpu_MappedTo[StackTopPos()] = m_x86fpu_MappedTo[i]; + m_x86fpu_State[StackTopPos()] = m_x86fpu_State[i]; m_x86fpu_StateChanged[StackTopPos()] = m_x86fpu_StateChanged[i]; FpuRoundingModel(i) = RoundingModel; - m_x86fpu_MappedTo[i] = MappedTo; - m_x86fpu_State[i] = RegState; - m_x86fpu_StateChanged[i] = Changed; + m_x86fpu_MappedTo[i] = MappedTo; + m_x86fpu_State[i] = RegState; + m_x86fpu_StateChanged[i] = Changed; fpuExchange((x86FpuValues)((i - StackTopPos()) & 7)); } } @@ -1091,27 +1091,27 @@ void CRegInfo::UnMap_FPR (int32_t Reg, bool WriteBackValue ) switch (m_x86fpu_State[StackTopPos()]) { case FPU_Dword: - sprintf(Name,"_FPR_S[%d]",m_x86fpu_MappedTo[StackTopPos()]); - MoveVariableToX86reg(&_FPR_S[m_x86fpu_MappedTo[StackTopPos()]],Name,TempReg); - fpuStoreIntegerDwordFromX86Reg(&StackTopPos(),TempReg, true); + sprintf(Name, "_FPR_S[%d]", m_x86fpu_MappedTo[StackTopPos()]); + MoveVariableToX86reg(&_FPR_S[m_x86fpu_MappedTo[StackTopPos()]], Name, TempReg); + fpuStoreIntegerDwordFromX86Reg(&StackTopPos(), TempReg, true); break; case FPU_Qword: - sprintf(Name,"_FPR_D[%d]",m_x86fpu_MappedTo[StackTopPos()]); - MoveVariableToX86reg(&_FPR_D[m_x86fpu_MappedTo[StackTopPos()]],Name,TempReg); - fpuStoreIntegerQwordFromX86Reg(&StackTopPos(),TempReg, true); + sprintf(Name, "_FPR_D[%d]", m_x86fpu_MappedTo[StackTopPos()]); + MoveVariableToX86reg(&_FPR_D[m_x86fpu_MappedTo[StackTopPos()]], Name, TempReg); + fpuStoreIntegerQwordFromX86Reg(&StackTopPos(), TempReg, true); break; case FPU_Float: - sprintf(Name,"_FPR_S[%d]",m_x86fpu_MappedTo[StackTopPos()]); - MoveVariableToX86reg(&_FPR_S[m_x86fpu_MappedTo[StackTopPos()]],Name,TempReg); - fpuStoreDwordFromX86Reg(&StackTopPos(),TempReg, true); + sprintf(Name, "_FPR_S[%d]", m_x86fpu_MappedTo[StackTopPos()]); + MoveVariableToX86reg(&_FPR_S[m_x86fpu_MappedTo[StackTopPos()]], Name, TempReg); + fpuStoreDwordFromX86Reg(&StackTopPos(), TempReg, true); break; case FPU_Double: - sprintf(Name,"_FPR_D[%d]",m_x86fpu_MappedTo[StackTopPos()]); - MoveVariableToX86reg(&_FPR_D[m_x86fpu_MappedTo[StackTopPos()]],Name,TempReg); - fpuStoreQwordFromX86Reg(&StackTopPos(),TempReg, true); + sprintf(Name, "_FPR_D[%d]", m_x86fpu_MappedTo[StackTopPos()]); + MoveVariableToX86reg(&_FPR_D[m_x86fpu_MappedTo[StackTopPos()]], Name, TempReg); + fpuStoreQwordFromX86Reg(&StackTopPos(), TempReg, true); break; default: - if (bHaveDebugger()) { g_Notify->DisplayError(stdstr_f(__FUNCTION__ "\nUnknown format to load %d",m_x86fpu_State[StackTopPos()]).ToUTF16().c_str()); } + if (bHaveDebugger()) { g_Notify->DisplayError(stdstr_f(__FUNCTION__ "\nUnknown format to load %d", m_x86fpu_State[StackTopPos()]).ToUTF16().c_str()); } } SetX86Protected(TempReg, false); FpuRoundingModel(RegPos) = RoundDefault; @@ -1131,7 +1131,7 @@ void CRegInfo::UnMap_FPR (int32_t Reg, bool WriteBackValue ) } } -void CRegInfo::UnMap_GPR (uint32_t Reg, bool WriteBackValue) +void CRegInfo::UnMap_GPR(uint32_t Reg, bool WriteBackValue) { if (Reg == 0) { @@ -1145,48 +1145,48 @@ void CRegInfo::UnMap_GPR (uint32_t Reg, bool WriteBackValue) { if (!WriteBackValue) { - SetMipsRegState(Reg,STATE_UNKNOWN); + SetMipsRegState(Reg, STATE_UNKNOWN); return; } if (Is64Bit(Reg)) { - MoveConstToVariable(GetMipsRegHi(Reg),&_GPR[Reg].UW[1],CRegName::GPR_Hi[Reg]); - MoveConstToVariable(GetMipsRegLo(Reg),&_GPR[Reg].UW[0],CRegName::GPR_Lo[Reg]); - SetMipsRegState(Reg,STATE_UNKNOWN); + MoveConstToVariable(GetMipsRegHi(Reg), &_GPR[Reg].UW[1], CRegName::GPR_Hi[Reg]); + MoveConstToVariable(GetMipsRegLo(Reg), &_GPR[Reg].UW[0], CRegName::GPR_Lo[Reg]); + SetMipsRegState(Reg, STATE_UNKNOWN); return; } if ((GetMipsRegLo(Reg) & 0x80000000) != 0) { - MoveConstToVariable(0xFFFFFFFF,&_GPR[Reg].UW[1],CRegName::GPR_Hi[Reg]); + MoveConstToVariable(0xFFFFFFFF, &_GPR[Reg].UW[1], CRegName::GPR_Hi[Reg]); } else { - MoveConstToVariable(0,&_GPR[Reg].UW[1],CRegName::GPR_Hi[Reg]); + MoveConstToVariable(0, &_GPR[Reg].UW[1], CRegName::GPR_Hi[Reg]); } - MoveConstToVariable(GetMipsRegLo(Reg),&_GPR[Reg].UW[0],CRegName::GPR_Lo[Reg]); - SetMipsRegState(Reg,STATE_UNKNOWN); + MoveConstToVariable(GetMipsRegLo(Reg), &_GPR[Reg].UW[0], CRegName::GPR_Lo[Reg]); + SetMipsRegState(Reg, STATE_UNKNOWN); return; } if (Is64Bit(Reg)) { - CPU_Message(" regcache: unallocate %s from %s",x86_Name(GetMipsRegMapHi(Reg)),CRegName::GPR_Hi[Reg]); - SetX86Mapped(GetMipsRegMapHi(Reg),NotMapped); + CPU_Message(" regcache: unallocate %s from %s", x86_Name(GetMipsRegMapHi(Reg)), CRegName::GPR_Hi[Reg]); + SetX86Mapped(GetMipsRegMapHi(Reg), NotMapped); SetX86Protected(GetMipsRegMapHi(Reg), false); } - CPU_Message(" regcache: unallocate %s from %s",x86_Name(GetMipsRegMapLo(Reg)),CRegName::GPR_Lo[Reg]); - SetX86Mapped(GetMipsRegMapLo(Reg),NotMapped); + CPU_Message(" regcache: unallocate %s from %s", x86_Name(GetMipsRegMapLo(Reg)), CRegName::GPR_Lo[Reg]); + SetX86Mapped(GetMipsRegMapLo(Reg), NotMapped); SetX86Protected(GetMipsRegMapLo(Reg), false); if (!WriteBackValue) { - SetMipsRegState(Reg,STATE_UNKNOWN); + SetMipsRegState(Reg, STATE_UNKNOWN); return; } - MoveX86regToVariable(GetMipsRegMapLo(Reg),&_GPR[Reg].UW[0],CRegName::GPR_Lo[Reg]); + MoveX86regToVariable(GetMipsRegMapLo(Reg), &_GPR[Reg].UW[0], CRegName::GPR_Lo[Reg]); if (Is64Bit(Reg)) { SetMipsRegMapLo(Reg, x86_Unknown); - MoveX86regToVariable(GetMipsRegMapHi(Reg),&_GPR[Reg].UW[1],CRegName::GPR_Hi[Reg]); - SetMipsRegMapHi(Reg,x86_Unknown); + MoveX86regToVariable(GetMipsRegMapHi(Reg), &_GPR[Reg].UW[1], CRegName::GPR_Hi[Reg]); + SetMipsRegMapHi(Reg, x86_Unknown); } else { @@ -1194,17 +1194,17 @@ void CRegInfo::UnMap_GPR (uint32_t Reg, bool WriteBackValue) { if (IsSigned(Reg)) { - ShiftRightSignImmed(GetMipsRegMapLo(Reg),31); - MoveX86regToVariable(GetMipsRegMapLo(Reg),&_GPR[Reg].UW[1],CRegName::GPR_Hi[Reg]); + ShiftRightSignImmed(GetMipsRegMapLo(Reg), 31); + MoveX86regToVariable(GetMipsRegMapLo(Reg), &_GPR[Reg].UW[1], CRegName::GPR_Hi[Reg]); } else { - MoveConstToVariable(0,&_GPR[Reg].UW[1],CRegName::GPR_Hi[Reg]); + MoveConstToVariable(0, &_GPR[Reg].UW[1], CRegName::GPR_Hi[Reg]); } } SetMipsRegMapLo(Reg, x86_Unknown); } - SetMipsRegState(Reg,STATE_UNKNOWN); + SetMipsRegState(Reg, STATE_UNKNOWN); } CX86Ops::x86Reg CRegInfo::UnMap_TempReg() @@ -1224,9 +1224,9 @@ CX86Ops::x86Reg CRegInfo::UnMap_TempReg() { if (GetX86Mapped(Reg) == Temp_Mapped) { - CPU_Message(" regcache: unallocate %s from temp storage",x86_Name(Reg)); + CPU_Message(" regcache: unallocate %s from temp storage", x86_Name(Reg)); } - SetX86Mapped(Reg,NotMapped); + SetX86Mapped(Reg, NotMapped); } return Reg; } @@ -1244,7 +1244,7 @@ bool CRegInfo::UnMap_X86reg(CX86Ops::x86Reg Reg) } else if (GetX86Mapped(Reg) == CRegInfo::GPR_Mapped) { - for (count = 1; count < 32; count ++) + for (count = 1; count < 32; count++) { if (!IsMapped(count)) { @@ -1275,16 +1275,16 @@ bool CRegInfo::UnMap_X86reg(CX86Ops::x86Reg Reg) { if (!GetX86Protected(Reg)) { - CPU_Message(" regcache: unallocate %s from temp storage",x86_Name(Reg)); - SetX86Mapped(Reg,NotMapped); + CPU_Message(" regcache: unallocate %s from temp storage", x86_Name(Reg)); + SetX86Mapped(Reg, NotMapped); return true; } } else if (GetX86Mapped(Reg) == CRegInfo::Stack_Mapped) { - CPU_Message(" regcache: unallocate %s from Memory Stack",x86_Name(Reg)); - MoveX86regToVariable(Reg,&(g_Recompiler->MemoryStackPos()),"MemoryStack"); - SetX86Mapped(Reg,NotMapped); + CPU_Message(" regcache: unallocate %s from Memory Stack", x86_Name(Reg)); + MoveX86regToVariable(Reg, &(g_Recompiler->MemoryStackPos()), "MemoryStack"); + SetX86Mapped(Reg, NotMapped); return true; } @@ -1299,13 +1299,13 @@ void CRegInfo::WriteBackRegisters() bool bEdiZero = false; bool bEsiSign = false; - int32_t X86RegCount = sizeof(x86_Registers)/ sizeof(x86_Registers[0]); + int32_t X86RegCount = sizeof(x86_Registers) / sizeof(x86_Registers[0]); for (int32_t i = 0; i < X86RegCount; i++) { SetX86Protected(x86_Registers[i], false); } for (int32_t i = 0; i < X86RegCount; i++) { UnMap_X86reg(x86_Registers[i]); } /*************************************/ - for (count = 1; count < 32; count ++) + for (count = 1; count < 32; count++) { switch (GetMipsRegState(count)) { @@ -1325,11 +1325,11 @@ void CRegInfo::WriteBackRegisters() } if ((GetMipsRegLo(count) & 0x80000000) != 0) { - MoveX86regToVariable(x86_ESI,&_GPR[count].UW[1],CRegName::GPR_Hi[count]); + MoveX86regToVariable(x86_ESI, &_GPR[count].UW[1], CRegName::GPR_Hi[count]); } else { - MoveX86regToVariable(x86_EDI,&_GPR[count].UW[1],CRegName::GPR_Hi[count]); + MoveX86regToVariable(x86_EDI, &_GPR[count].UW[1], CRegName::GPR_Hi[count]); } } @@ -1343,7 +1343,7 @@ void CRegInfo::WriteBackRegisters() bEdiZero = true; } } - MoveX86regToVariable(x86_EDI,&_GPR[count].UW[0],CRegName::GPR_Lo[count]); + MoveX86regToVariable(x86_EDI, &_GPR[count].UW[0], CRegName::GPR_Lo[count]); } else if (GetMipsRegLo(count) == 0xFFFFFFFF) { @@ -1355,11 +1355,11 @@ void CRegInfo::WriteBackRegisters() bEsiSign = true; } } - MoveX86regToVariable(x86_ESI,&_GPR[count].UW[0],CRegName::GPR_Lo[count]); + MoveX86regToVariable(x86_ESI, &_GPR[count].UW[0], CRegName::GPR_Lo[count]); } else { - MoveConstToVariable(GetMipsRegLo(count),&_GPR[count].UW[0],CRegName::GPR_Lo[count]); + MoveConstToVariable(GetMipsRegLo(count), &_GPR[count].UW[0], CRegName::GPR_Lo[count]); } SetMipsRegState(count, CRegInfo::STATE_UNKNOWN); @@ -1372,7 +1372,7 @@ void CRegInfo::WriteBackRegisters() XorX86RegToX86Reg(x86_EDI, x86_EDI); bEdiZero = true; } - MoveX86regToVariable(x86_EDI,&_GPR[count].UW[1],CRegName::GPR_Hi[count]); + MoveX86regToVariable(x86_EDI, &_GPR[count].UW[1], CRegName::GPR_Hi[count]); } if (GetMipsRegLo(count) == 0) @@ -1385,11 +1385,11 @@ void CRegInfo::WriteBackRegisters() bEdiZero = true; } } - MoveX86regToVariable(x86_EDI,&_GPR[count].UW[0],CRegName::GPR_Lo[count]); + MoveX86regToVariable(x86_EDI, &_GPR[count].UW[0], CRegName::GPR_Lo[count]); } else { - MoveConstToVariable(GetMipsRegLo(count),&_GPR[count].UW[0],CRegName::GPR_Lo[count]); + MoveConstToVariable(GetMipsRegLo(count), &_GPR[count].UW[0], CRegName::GPR_Lo[count]); } SetMipsRegState(count, CRegInfo::STATE_UNKNOWN); break; @@ -1407,39 +1407,39 @@ void CRegInfo::WriteBackRegisters() if (GetMipsRegHi(count) == 0) { - MoveX86regToVariable(x86_EDI,&_GPR[count].UW[1],CRegName::GPR_Hi[count]); + MoveX86regToVariable(x86_EDI, &_GPR[count].UW[1], CRegName::GPR_Hi[count]); } else if (GetMipsRegLo(count) == 0xFFFFFFFF) { - MoveX86regToVariable(x86_ESI,&_GPR[count].UW[1],CRegName::GPR_Hi[count]); + MoveX86regToVariable(x86_ESI, &_GPR[count].UW[1], CRegName::GPR_Hi[count]); } else { - MoveConstToVariable(GetMipsRegHi(count),&_GPR[count].UW[1],CRegName::GPR_Hi[count]); + MoveConstToVariable(GetMipsRegHi(count), &_GPR[count].UW[1], CRegName::GPR_Hi[count]); } if (GetMipsRegLo(count) == 0) { - MoveX86regToVariable(x86_EDI,&_GPR[count].UW[0],CRegName::GPR_Lo[count]); + MoveX86regToVariable(x86_EDI, &_GPR[count].UW[0], CRegName::GPR_Lo[count]); } else if (GetMipsRegLo(count) == 0xFFFFFFFF) { - MoveX86regToVariable(x86_ESI,&_GPR[count].UW[0],CRegName::GPR_Lo[count]); + MoveX86regToVariable(x86_ESI, &_GPR[count].UW[0], CRegName::GPR_Lo[count]); } else { - MoveConstToVariable(GetMipsRegLo(count),&_GPR[count].UW[0],CRegName::GPR_Lo[count]); + MoveConstToVariable(GetMipsRegLo(count), &_GPR[count].UW[0], CRegName::GPR_Lo[count]); } SetMipsRegState(count, CRegInfo::STATE_UNKNOWN); break; default: - CPU_Message(__FUNCTION__ ": Unknown State: %d reg %d (%s)",GetMipsRegState(count),count,CRegName::GPR[count]); - g_Notify->BreakPoint(__FILEW__,__LINE__); + CPU_Message(__FUNCTION__ ": Unknown State: %d reg %d (%s)", GetMipsRegState(count), count, CRegName::GPR[count]); + g_Notify->BreakPoint(__FILEW__, __LINE__); } } } -const char * CRegInfo::RoundingModelName ( FPU_ROUND RoundType ) +const char * CRegInfo::RoundingModelName(FPU_ROUND RoundType) { switch (RoundType) { diff --git a/Source/Project64/N64 System/Recompiler/Reg Info.h b/Source/Project64/N64 System/Recompiler/Reg Info.h index 5ed26b813..a16cfbebc 100644 --- a/Source/Project64/N64 System/Recompiler/Reg Info.h +++ b/Source/Project64/N64 System/Recompiler/Reg Info.h @@ -19,48 +19,48 @@ public: //enums enum REG_STATE { - STATE_UNKNOWN = 0x00, - STATE_KNOWN_VALUE = 0x01, - STATE_X86_MAPPED = 0x02, - STATE_SIGN = 0x04, - STATE_32BIT = 0x08, - STATE_MODIFIED = 0x10, + STATE_UNKNOWN = 0x00, + STATE_KNOWN_VALUE = 0x01, + STATE_X86_MAPPED = 0x02, + STATE_SIGN = 0x04, + STATE_32BIT = 0x08, + STATE_MODIFIED = 0x10, - STATE_MAPPED_64 = (STATE_KNOWN_VALUE | STATE_X86_MAPPED), // = 3 + STATE_MAPPED_64 = (STATE_KNOWN_VALUE | STATE_X86_MAPPED), // = 3 STATE_MAPPED_32_ZERO = (STATE_KNOWN_VALUE | STATE_X86_MAPPED | STATE_32BIT), // = 11 STATE_MAPPED_32_SIGN = (STATE_KNOWN_VALUE | STATE_X86_MAPPED | STATE_32BIT | STATE_SIGN), // = 15 - STATE_CONST_32_ZERO = (STATE_KNOWN_VALUE | STATE_32BIT), // = 9 - STATE_CONST_32_SIGN = (STATE_KNOWN_VALUE | STATE_32BIT | STATE_SIGN), // = 13 - STATE_CONST_64 = (STATE_KNOWN_VALUE), // = 1 + STATE_CONST_32_ZERO = (STATE_KNOWN_VALUE | STATE_32BIT), // = 9 + STATE_CONST_32_SIGN = (STATE_KNOWN_VALUE | STATE_32BIT | STATE_SIGN), // = 13 + STATE_CONST_64 = (STATE_KNOWN_VALUE), // = 1 }; enum REG_MAPPED { - NotMapped = 0, - GPR_Mapped = 1, - Temp_Mapped = 2, - Stack_Mapped = 3, + NotMapped = 0, + GPR_Mapped = 1, + Temp_Mapped = 2, + Stack_Mapped = 3, }; enum FPU_STATE { - FPU_Any = -1, + FPU_Any = -1, FPU_Unknown = 0, - FPU_Dword = 1, - FPU_Qword = 2, - FPU_Float = 3, - FPU_Double = 4, + FPU_Dword = 1, + FPU_Qword = 2, + FPU_Float = 3, + FPU_Double = 4, }; enum FPU_ROUND { - RoundUnknown = -1, - RoundDefault = 0, + RoundUnknown = -1, + RoundDefault = 0, RoundTruncate = 1, - RoundNearest = 2, - RoundDown = 3, - RoundUp = 4, + RoundNearest = 2, + RoundDown = 3, + RoundUp = 4, }; public: @@ -73,30 +73,30 @@ public: bool operator==(const CRegInfo& right) const; bool operator!=(const CRegInfo& right) const; - static REG_STATE ConstantsType ( int64_t Value ); + static REG_STATE ConstantsType(int64_t Value); - void FixRoundModel ( FPU_ROUND RoundMethod ); - void ChangeFPURegFormat ( int32_t Reg, FPU_STATE OldFormat, FPU_STATE NewFormat, FPU_ROUND RoundingModel ); - void Load_FPR_ToTop ( int32_t Reg, int32_t RegToLoad, FPU_STATE Format); - bool RegInStack ( int32_t Reg, FPU_STATE Format ); - void UnMap_AllFPRs (); - void UnMap_FPR ( int32_t Reg, bool WriteBackValue ); - x86FpuValues StackPosition( int32_t Reg ); + void FixRoundModel(FPU_ROUND RoundMethod); + void ChangeFPURegFormat(int32_t Reg, FPU_STATE OldFormat, FPU_STATE NewFormat, FPU_ROUND RoundingModel); + void Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Format); + bool RegInStack(int32_t Reg, FPU_STATE Format); + void UnMap_AllFPRs(); + void UnMap_FPR(int32_t Reg, bool WriteBackValue); + x86FpuValues StackPosition(int32_t Reg); - x86Reg FreeX86Reg (); - x86Reg Free8BitX86Reg (); - void Map_GPR_32bit ( int32_t MipsReg, bool SignValue, int32_t MipsRegToLoad ); - void Map_GPR_64bit ( int32_t MipsReg, int32_t MipsRegToLoad ); - x86Reg Get_MemoryStack () const; - x86Reg Map_MemoryStack ( x86Reg Reg, bool bMapRegister, bool LoadValue = true ); - x86Reg Map_TempReg ( x86Reg Reg, int32_t MipsReg, bool LoadHiWord ); - void ProtectGPR ( uint32_t Reg ); - void UnProtectGPR ( uint32_t Reg ); - void ResetX86Protection (); - x86Reg UnMap_TempReg (); - void UnMap_GPR ( uint32_t Reg, bool WriteBackValue ); - bool UnMap_X86reg ( x86Reg Reg ); - void WriteBackRegisters (); + x86Reg FreeX86Reg(); + x86Reg Free8BitX86Reg(); + void Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t MipsRegToLoad); + void Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad); + x86Reg Get_MemoryStack() const; + x86Reg Map_MemoryStack(x86Reg Reg, bool bMapRegister, bool LoadValue = true); + x86Reg Map_TempReg(x86Reg Reg, int32_t MipsReg, bool LoadHiWord); + void ProtectGPR(uint32_t Reg); + void UnProtectGPR(uint32_t Reg); + void ResetX86Protection(); + x86Reg UnMap_TempReg(); + void UnMap_GPR(uint32_t Reg, bool WriteBackValue); + bool UnMap_X86reg(x86Reg Reg); + void WriteBackRegisters(); bool IsKnown(int32_t Reg) const { return ((GetMipsRegState(Reg) & STATE_KNOWN_VALUE) != 0); } bool IsUnknown(int32_t Reg) const { return ((GetMipsRegState(Reg) & STATE_KNOWN_VALUE) == 0); } @@ -114,33 +114,33 @@ public: bool Is32BitMapped(int32_t Reg) const { return ((GetMipsRegState(Reg) & (STATE_KNOWN_VALUE | STATE_32BIT | STATE_X86_MAPPED)) == (STATE_KNOWN_VALUE | STATE_32BIT | STATE_X86_MAPPED)); } bool Is64BitMapped(int32_t Reg) const { return ((GetMipsRegState(Reg) & (STATE_KNOWN_VALUE | STATE_32BIT | STATE_X86_MAPPED)) == (STATE_KNOWN_VALUE | STATE_X86_MAPPED)); } - REG_STATE GetMipsRegState ( int32_t Reg ) const { return m_MIPS_RegState[Reg]; } - uint64_t GetMipsReg ( int32_t Reg ) const { return m_MIPS_RegVal[Reg].UDW; } - int64_t GetMipsReg_S ( int32_t Reg ) const { return m_MIPS_RegVal[Reg].DW; } - uint32_t GetMipsRegLo ( int32_t Reg ) const { return m_MIPS_RegVal[Reg].UW[0]; } - int32_t GetMipsRegLo_S ( int32_t Reg ) const { return m_MIPS_RegVal[Reg].W[0]; } - uint32_t GetMipsRegHi ( int32_t Reg ) const { return m_MIPS_RegVal[Reg].UW[1]; } - int32_t GetMipsRegHi_S ( int32_t Reg ) const { return m_MIPS_RegVal[Reg].W[1]; } - CX86Ops::x86Reg GetMipsRegMapLo ( int32_t Reg ) const { return m_RegMapLo[Reg]; } - CX86Ops::x86Reg GetMipsRegMapHi ( int32_t Reg ) const { return m_RegMapHi[Reg]; } + REG_STATE GetMipsRegState(int32_t Reg) const { return m_MIPS_RegState[Reg]; } + uint64_t GetMipsReg(int32_t Reg) const { return m_MIPS_RegVal[Reg].UDW; } + int64_t GetMipsReg_S(int32_t Reg) const { return m_MIPS_RegVal[Reg].DW; } + uint32_t GetMipsRegLo(int32_t Reg) const { return m_MIPS_RegVal[Reg].UW[0]; } + int32_t GetMipsRegLo_S(int32_t Reg) const { return m_MIPS_RegVal[Reg].W[0]; } + uint32_t GetMipsRegHi(int32_t Reg) const { return m_MIPS_RegVal[Reg].UW[1]; } + int32_t GetMipsRegHi_S(int32_t Reg) const { return m_MIPS_RegVal[Reg].W[1]; } + CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) const { return m_RegMapLo[Reg]; } + CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) const { return m_RegMapHi[Reg]; } - uint32_t GetX86MapOrder ( x86Reg Reg ) const { return m_x86reg_MapOrder[Reg]; } - bool GetX86Protected ( x86Reg Reg ) const { return m_x86reg_Protected[Reg]; } - REG_MAPPED GetX86Mapped ( x86Reg Reg ) const { return m_x86reg_MappedTo[Reg]; } + uint32_t GetX86MapOrder(x86Reg Reg) const { return m_x86reg_MapOrder[Reg]; } + bool GetX86Protected(x86Reg Reg) const { return m_x86reg_Protected[Reg]; } + REG_MAPPED GetX86Mapped(x86Reg Reg) const { return m_x86reg_MappedTo[Reg]; } uint32_t GetBlockCycleCount() const { return m_CycleCount; } - void SetMipsReg ( int32_t Reg, uint64_t Value ) { m_MIPS_RegVal[Reg].UDW = Value; } - void SetMipsReg_S ( int32_t Reg, int64_t Value) { m_MIPS_RegVal[Reg].DW = Value; } - void SetMipsRegLo ( int32_t Reg, uint32_t Value ) { m_MIPS_RegVal[Reg].UW[0] = Value; } - void SetMipsRegHi ( int32_t Reg, uint32_t Value ) { m_MIPS_RegVal[Reg].UW[1] = Value; } - void SetMipsRegMapLo ( int32_t GetMipsReg, x86Reg Reg ) { m_RegMapLo[GetMipsReg] = Reg; } - void SetMipsRegMapHi ( int32_t GetMipsReg, x86Reg Reg ) { m_RegMapHi[GetMipsReg] = Reg; } - void SetMipsRegState ( int32_t GetMipsReg, REG_STATE State ) { m_MIPS_RegState[GetMipsReg] = State; } + void SetMipsReg(int32_t Reg, uint64_t Value) { m_MIPS_RegVal[Reg].UDW = Value; } + void SetMipsReg_S(int32_t Reg, int64_t Value) { m_MIPS_RegVal[Reg].DW = Value; } + void SetMipsRegLo(int32_t Reg, uint32_t Value) { m_MIPS_RegVal[Reg].UW[0] = Value; } + void SetMipsRegHi(int32_t Reg, uint32_t Value) { m_MIPS_RegVal[Reg].UW[1] = Value; } + void SetMipsRegMapLo(int32_t GetMipsReg, x86Reg Reg) { m_RegMapLo[GetMipsReg] = Reg; } + void SetMipsRegMapHi(int32_t GetMipsReg, x86Reg Reg) { m_RegMapHi[GetMipsReg] = Reg; } + void SetMipsRegState(int32_t GetMipsReg, REG_STATE State) { m_MIPS_RegState[GetMipsReg] = State; } - void SetX86MapOrder ( x86Reg Reg, uint32_t Order ) { m_x86reg_MapOrder[Reg] = Order; } - void SetX86Protected ( x86Reg Reg, bool Protected ) { m_x86reg_Protected[Reg] = Protected; } - void SetX86Mapped ( x86Reg Reg, REG_MAPPED Mapping ) { m_x86reg_MappedTo[Reg] = Mapping; } + void SetX86MapOrder(x86Reg Reg, uint32_t Order) { m_x86reg_MapOrder[Reg] = Order; } + void SetX86Protected(x86Reg Reg, bool Protected) { m_x86reg_Protected[Reg] = Protected; } + void SetX86Mapped(x86Reg Reg, REG_MAPPED Mapping) { m_x86reg_MappedTo[Reg] = Mapping; } void SetBlockCycleCount(uint32_t CyleCount) { m_CycleCount = CyleCount; } From 2f3998d9a6c93c04a6caa9d0702dde4566afdb06 Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 14:50:05 +1100 Subject: [PATCH 6/9] [Project64] more fix up of Reg Info.cpp --- Source/Project64/N64 System/Recompiler/Reg Info.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/Project64/N64 System/Recompiler/Reg Info.cpp b/Source/Project64/N64 System/Recompiler/Reg Info.cpp index d214b1449..1b0126713 100644 --- a/Source/Project64/N64 System/Recompiler/Reg Info.cpp +++ b/Source/Project64/N64 System/Recompiler/Reg Info.cpp @@ -10,7 +10,7 @@ ****************************************************************************/ #include "stdafx.h" -unsigned int CRegInfo::m_fpuControl = 0; +uint32_t CRegInfo::m_fpuControl = 0; char *Format_Name[] = { "Unknown", "dword", "qword", "float", "double" }; @@ -470,10 +470,7 @@ CX86Ops::x86Reg CRegInfo::Free8BitX86Reg() if (GetX86Mapped(x86_ECX) == NotMapped && !GetX86Protected(x86_ECX)) { return x86_ECX; } x86Reg Reg = UnMap_8BitTempReg(); - if (Reg > 0) - { - return Reg; - } + if (Reg > 0) { return Reg; } int32_t count, MapCount[10], MapReg[10]; for (count = 0; count < 10; count++) From 8aa5b6ef470f26203b384fcbd37824cfd5174c1c Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 14:51:21 +1100 Subject: [PATCH 7/9] [Project64] fix up spaces in CN64System::StartEmulationThread --- Source/Project64/N64 System/N64 Class.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Project64/N64 System/N64 Class.cpp b/Source/Project64/N64 System/N64 Class.cpp index 050a23f86..4412185de 100644 --- a/Source/Project64/N64 System/N64 Class.cpp +++ b/Source/Project64/N64 System/N64 Class.cpp @@ -375,10 +375,10 @@ void CN64System::StartEmulation(bool NewThread) void CN64System::StartEmulationThread(ThreadInfo * Info) { - if (g_Settings->LoadBool(Setting_CN64TimeCritical)) - { - SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL); - } + if (g_Settings->LoadBool(Setting_CN64TimeCritical)) + { + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); + } CoInitialize(NULL); @@ -2035,4 +2035,4 @@ void CN64System::TLB_Changed() { g_Debugger->TLBChanged(); } -} +} \ No newline at end of file From 7d7026c33d8726be747d0410f04661a3063bc28e Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 15:44:40 +1100 Subject: [PATCH 8/9] [Project64] Add ability to monitor Game Cpu Running to Gui --- Source/Project64/N64 System/N64 Class.cpp | 57 +++++------------ Source/Project64/User Interface/Gui Class.cpp | 63 ++++++++++++++++++- Source/Project64/User Interface/Gui Class.h | 7 ++- 3 files changed, 84 insertions(+), 43 deletions(-) diff --git a/Source/Project64/N64 System/N64 Class.cpp b/Source/Project64/N64 System/N64 Class.cpp index 4412185de..2bd8a0816 100644 --- a/Source/Project64/N64 System/N64 Class.cpp +++ b/Source/Project64/N64 System/N64 Class.cpp @@ -321,40 +321,25 @@ void CN64System::StartEmulation2(bool NewThread) { g_Settings->SaveBool(GameRunning_LoadingInProgress, false); g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT); - - Notify().ShowRomBrowser(); } + else + { + ThreadInfo * Info = new ThreadInfo; + HANDLE * hThread = new HANDLE; + *hThread = NULL; - Notify().MakeWindowOnTop(g_Settings->LoadBool(UserInterface_AlwaysOnTop)); + //create the needed info into a structure to pass as one parameter + //for creating a thread + Info->ThreadHandle = hThread; - ThreadInfo * Info = new ThreadInfo; - HANDLE * hThread = new HANDLE; - *hThread = NULL; - - //create the needed info into a structure to pass as one parameter - //for creating a thread - Info->ThreadHandle = hThread; - - *hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartEmulationThread, Info, 0, &Info->ThreadID); + *hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartEmulationThread, Info, 0, &Info->ThreadID); + } } else { //mark the emulation as starting and fix up menus g_Notify->DisplayMessage(5, MSG_EMULATION_STARTED); - if (g_Settings->LoadBool(Setting_AutoFullscreen)) - { - WriteTrace(TraceDebug, __FUNCTION__ " 15"); - CIniFile RomIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); - stdstr Status = g_Settings->LoadStringVal(Rdb_Status); - - char String[100]; - RomIniFile.GetString("Rom Status", stdstr_f("%s.AutoFullScreen", Status.c_str()).c_str(), "true", String, sizeof(String)); - if (_stricmp(String, "true") == 0) - { - Notify().ChangeFullScreen(); - } - } ExecuteCPU(); } } @@ -887,23 +872,15 @@ void CN64System::ExecuteRecompiler() void CN64System::ExecuteSyncCPU() { - Notify().BringToTop(); m_Recomp->Run(); } void CN64System::CpuStopped() { - g_Settings->SaveBool(GameRunning_CPU_Running, (DWORD)false); - Notify().WindowMode(); if (!m_InReset) { - Notify().RefreshMenu(); - Notify().MakeWindowOnTop(false); + g_Settings->SaveBool(GameRunning_CPU_Running, (uint32_t)false); g_Notify->DisplayMessage(5, MSG_EMULATION_ENDED); - if (g_Settings->LoadDword(RomBrowser_Enabled)) - { - Notify().ShowRomBrowser(); - } } if (m_SyncCPU) { @@ -963,7 +940,7 @@ void CN64System::SyncCPU(CN64System * const SecondCPU) #ifdef TEST_SP_TRACKING if (m_CurrentSP != GPR[29].UW[0]) { ErrorFound = true; - } +} #endif if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) { @@ -1082,7 +1059,7 @@ void CN64System::SyncCPU(CN64System * const SecondCPU) // if (PROGRAM_COUNTER == 0x8009BBD8) { // g_Notify->BreakPoint(__FILEW__,__LINE__); // } -} + } void CN64System::SyncSystem() { @@ -1110,7 +1087,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) #ifdef TEST_SP_TRACKING if (m_CurrentSP != GPR[29].UW[0]) { Error.Log("m_CurrentSP,%X,%X\r\n", m_CurrentSP, GPR[29].UW[0]); - } + } #endif if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) { Error.LogF("PROGRAM_COUNTER 0x%X, 0x%X\r\n", m_Reg.m_PROGRAM_COUNTER, SecondCPU->m_Reg.m_PROGRAM_COUNTER); @@ -1324,7 +1301,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) Error.LogF("%X: %s\r\n", Addr, R4300iOpcodeName(OpcodeValue, Addr)); } } - } +} g_Notify->DisplayError(L"Sync Error"); g_Notify->BreakPoint(__FILEW__, __LINE__); @@ -2011,9 +1988,9 @@ bool CN64System::WriteToProtectedMemory(uint32_t Address, int length) #ifdef tofix return m_Recomp->ClearRecompCode_Phys(Address, length, CRecompiler::Remove_ProtectedMem); #endif - } - return false; } + return false; + } void CN64System::TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly) { diff --git a/Source/Project64/User Interface/Gui Class.cpp b/Source/Project64/User Interface/Gui Class.cpp index 79ccc8513..b0fc31f1e 100644 --- a/Source/Project64/User Interface/Gui Class.cpp +++ b/Source/Project64/User Interface/Gui Class.cpp @@ -50,6 +50,7 @@ m_ResetInfo(NULL) g_Settings->RegisterChangeCB(RomBrowser_ColoumnsChanged, this, (CSettings::SettingChangedFunc)RomBowserColoumnsChanged); g_Settings->RegisterChangeCB(RomBrowser_Recursive, this, (CSettings::SettingChangedFunc)RomBrowserRecursiveChanged); g_Settings->RegisterChangeCB(GameRunning_LoadingInProgress, this, (CSettings::SettingChangedFunc)LoadingInProgressChanged); + g_Settings->RegisterChangeCB(GameRunning_CPU_Running, this, (CSettings::SettingChangedFunc)GameCpuRunning); g_Settings->RegisterChangeCB(GameRunning_CPU_Paused, this, (CSettings::SettingChangedFunc)GamePaused); g_Settings->RegisterChangeCB(Game_File, this, (CSettings::SettingChangedFunc)GameLoaded); } @@ -68,6 +69,7 @@ CMainGui::~CMainGui(void) g_Settings->UnregisterChangeCB(RomBrowser_ColoumnsChanged, this, (CSettings::SettingChangedFunc)RomBowserColoumnsChanged); g_Settings->UnregisterChangeCB(RomBrowser_Recursive, this, (CSettings::SettingChangedFunc)RomBrowserRecursiveChanged); g_Settings->UnregisterChangeCB(GameRunning_LoadingInProgress, this, (CSettings::SettingChangedFunc)LoadingInProgressChanged); + g_Settings->UnregisterChangeCB(GameRunning_CPU_Running, this, (CSettings::SettingChangedFunc)GameCpuRunning); g_Settings->UnregisterChangeCB(GameRunning_CPU_Paused, this, (CSettings::SettingChangedFunc)GamePaused); g_Settings->UnregisterChangeCB(Game_File, this, (CSettings::SettingChangedFunc)GameLoaded); } @@ -150,6 +152,15 @@ void CMainGui::SetWindowCaption(const wchar_t * title) Caption(WinTitle); } +void CMainGui::ShowRomBrowser(void) +{ + if (g_Settings->LoadDword(RomBrowser_Enabled)) + { + ShowRomList(); + HighLightLastRom(); + } +} + void RomBowserEnabledChanged(CMainGui * Gui) { if (Gui && g_Settings->LoadBool(RomBrowser_Enabled)) @@ -171,6 +182,15 @@ void RomBowserEnabledChanged(CMainGui * Gui) void CMainGui::LoadingInProgressChanged(CMainGui * Gui) { Gui->RefreshMenu(); + if (!g_Settings->LoadBool(GameRunning_LoadingInProgress) && g_Settings->LoadStringVal(Game_File).length() == 0) + { + Notify().WindowMode(); + if (g_Settings->LoadDword(RomBrowser_Enabled)) + { + Gui->ShowRomBrowser(); + } + Gui->MakeWindowOnTop(false); + } } void CMainGui::GameLoaded(CMainGui * Gui) @@ -181,7 +201,6 @@ void CMainGui::GameLoaded(CMainGui * Gui) WriteTrace(TraceDebug, __FUNCTION__ ": Add Recent Rom"); Gui->AddRecentRom(FileLoc.c_str()); Gui->SetWindowCaption(g_Settings->LoadStringVal(Game_GoodName).ToUTF16().c_str()); - Gui->HideRomList(); } } @@ -191,6 +210,33 @@ void CMainGui::GamePaused(CMainGui * Gui) Gui->RefreshMenu(); } +void CMainGui::GameCpuRunning(CMainGui * Gui) +{ + if (g_Settings->LoadBool(GameRunning_CPU_Running)) + { + Gui->MakeWindowOnTop(g_Settings->LoadBool(UserInterface_AlwaysOnTop)); + if (g_Settings->LoadBool(Setting_AutoFullscreen)) + { + WriteTrace(TraceDebug, __FUNCTION__ " 15"); + CIniFile RomIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); + stdstr Status = g_Settings->LoadStringVal(Rdb_Status); + + char String[100]; + RomIniFile.GetString("Rom Status", stdstr_f("%s.AutoFullScreen", Status.c_str()).c_str(), "true", String, sizeof(String)); + if (_stricmp(String, "true") == 0) + { + g_Notify->ChangeFullScreen(); + } + } + Gui->RefreshMenu(); + Gui->BringToTop(); + } + else + { + PostMessage(Gui->m_hMainWindow, WM_GAME_CLOSED, 0, 0); + } +} + void RomBowserColoumnsChanged(CMainGui * Gui) { Gui->ResetRomBrowserColomuns(); @@ -375,6 +421,7 @@ bool CMainGui::ResetPluginsInUiThread(CPlugins * plugins, CN64System * System) WriteTrace(TraceError, __FUNCTION__ ": Failed to create event"); bRes = false; } + Notify().RefreshMenu(); return bRes; } @@ -908,6 +955,20 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO _this->m_ResetPlugins = true; } break; + case WM_GAME_CLOSED: + { + CMainGui * _this = (CMainGui *)GetProp((HWND)hWnd, "Class"); + Notify().WindowMode(); + if (g_Settings->LoadDword(RomBrowser_Enabled)) + { + _this->ShowRomBrowser(); + } + _this->RefreshMenu(); + _this->MakeWindowOnTop(false); + _this->SetStatusText(0, L""); + _this->SetStatusText(1, L""); + } + break; case WM_COMMAND: { CMainGui * _this = (CMainGui *)GetProp((HWND)hWnd, "Class"); diff --git a/Source/Project64/User Interface/Gui Class.h b/Source/Project64/User Interface/Gui Class.h index 11f93006f..41f7e9702 100644 --- a/Source/Project64/User Interface/Gui Class.h +++ b/Source/Project64/User Interface/Gui Class.h @@ -25,8 +25,9 @@ enum { WM_HIDE_CUROSR = WM_USER + 10, WM_MAKE_FOCUS = WM_USER + 17, - WM_RESET_PLUGIN = WM_USER + 18, - WM_BORWSER_TOP = WM_USER + 40, + WM_RESET_PLUGIN = WM_USER + 18, + WM_GAME_CLOSED = WM_USER + 19, + WM_BORWSER_TOP = WM_USER + 40, }; class CMainGui : @@ -105,6 +106,7 @@ private: void Resize(DWORD fwSizeType, WORD nWidth, WORD nHeight); //responding to WM_SIZE void AddRecentRom(const char * ImagePath); void SetWindowCaption(const wchar_t * Caption); + void ShowRomBrowser(void); friend DWORD CALLBACK AboutBoxProc(HWND, DWORD, DWORD, DWORD); friend DWORD CALLBACK AboutIniBoxProc(HWND, DWORD, DWORD, DWORD); @@ -116,6 +118,7 @@ private: static void LoadingInProgressChanged(CMainGui * Gui); static void GameLoaded(CMainGui * Gui); static void GamePaused(CMainGui * Gui); + static void GameCpuRunning(CMainGui * Gui); CBaseMenu * m_Menu; From 3024d7c524fccb06a5cef15fbc54476f4dcc60da Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 15 Nov 2015 16:20:22 +1100 Subject: [PATCH 9/9] [Project64] Get N64 Class.cpp to use standard types --- Source/Project64/N64 System/N64 Class.cpp | 250 +++++++++++----------- Source/Project64/N64 System/N64 Class.h | 45 ++-- 2 files changed, 149 insertions(+), 146 deletions(-) diff --git a/Source/Project64/N64 System/N64 Class.cpp b/Source/Project64/N64 System/N64 Class.cpp index 2bd8a0816..192694e36 100644 --- a/Source/Project64/N64 System/N64 Class.cpp +++ b/Source/Project64/N64 System/N64 Class.cpp @@ -9,6 +9,7 @@ * * ****************************************************************************/ #include "stdafx.h" +#include #pragma warning(disable:4355) // Disable 'this' : used in base member initializer list @@ -44,7 +45,7 @@ m_CPU_ThreadID(0), m_hPauseEvent(true), m_CheatsSlectionChanged(false) { - DWORD gameHertz = g_Settings->LoadDword(Game_ScreenHertz); + uint32_t gameHertz = g_Settings->LoadDword(Game_ScreenHertz); if (gameHertz == 0) { gameHertz = (SystemType() == SYSTEM_PAL) ? 50 : 60; @@ -180,10 +181,10 @@ bool CN64System::RunFileImage(const char * FileLoc) { return false; } - WriteTrace(TraceDebug, __FUNCTION__ ": Mark Rom as loading"); - g_Settings->SaveString(Game_File, ""); //Mark the rom as loading + WriteTrace(TraceDebug, __FUNCTION__ ": Mark Rom as loading"); + g_Settings->SaveString(Game_File, ""); g_Settings->SaveBool(GameRunning_LoadingInProgress, true); //Try to load the passed N64 rom @@ -236,7 +237,7 @@ void CN64System::CloseSystem() } } -bool CN64System::EmulationStarting(HANDLE hThread, DWORD ThreadId) +bool CN64System::EmulationStarting(void * hThread, uint32_t ThreadId) { bool bRes = true; @@ -268,7 +269,7 @@ bool CN64System::EmulationStarting(HANDLE hThread, DWORD ThreadId) return bRes; } -void CN64System::StartEmulation2(bool NewThread) +void CN64System::StartEmulation2(bool NewThread) { if (NewThread) { @@ -280,7 +281,7 @@ void CN64System::StartEmulation2(bool NewThread) CInterpreterCPU::BuildCPU(); - DWORD CpuType = g_Settings->LoadDword(Game_CpuType); + uint32_t CpuType = g_Settings->LoadDword(Game_CpuType); if (CpuType == CPU_SyncCores && !g_Settings->LoadBool(Debugger_Enabled)) { @@ -332,7 +333,7 @@ void CN64System::StartEmulation2(bool NewThread) //for creating a thread Info->ThreadHandle = hThread; - *hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartEmulationThread, Info, 0, &Info->ThreadID); + *hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartEmulationThread, Info, 0, (LPDWORD)&Info->ThreadID); } } else @@ -352,9 +353,9 @@ void CN64System::StartEmulation(bool NewThread) } __except (g_MMU->MemoryFilter(GetExceptionCode(), GetExceptionInformation())) { - char Message[600]; - sprintf(Message, "Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__); - MessageBox(NULL, Message, "Exception", MB_OK); + wchar_t message[400]; + swprintf(message, sizeof(message), L"Exception caught\nFile: %s\nLine: %d", __FILEW__, __LINE__); + g_Notify->DisplayError(message); } } @@ -367,7 +368,7 @@ void CN64System::StartEmulationThread(ThreadInfo * Info) CoInitialize(NULL); - EmulationStarting(*Info->ThreadHandle, Info->ThreadID); + EmulationStarting(Info->ThreadHandle, Info->ThreadID); delete Info->ThreadHandle; delete Info; @@ -443,8 +444,8 @@ void CN64System::Pause() g_Notify->DisplayMessage(5, MSG_CPU_PAUSED); m_hPauseEvent.IsTriggered(SyncEvent::INFINITE_TIMEOUT); m_hPauseEvent.Reset(); - g_Settings->SaveBool(GameRunning_CPU_Paused, false); - Notify().DisplayMessage(5, MSG_CPU_RESUMED); + g_Settings->SaveBool(GameRunning_CPU_Paused, (uint32_t)false); + g_Notify->DisplayMessage(5, MSG_CPU_RESUMED); } void CN64System::GameReset() @@ -480,7 +481,6 @@ void CN64System::PluginReset() } } } - Notify().RefreshMenu(); if (m_Recomp) { m_Recomp->Reset(); @@ -812,22 +812,22 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemory & MMU) m_Reg.m_PROGRAM_COUNTER = 0xBFC00000; /* PIF_Ram[36] = 0x00; PIF_Ram[39] = 0x3F; //common pif ram start values - switch (g_Rom->CicChipID()) { - case CIC_NUS_6101: PIF_Ram[37] = 0x06; PIF_Ram[38] = 0x3F; break; - case CIC_UNKNOWN: - case CIC_NUS_6102: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x3F; break; - case CIC_NUS_6103: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x78; break; - case CIC_NUS_6105: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x91; break; - case CIC_NUS_6106: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x85; break; - }*/ + switch (g_Rom->CicChipID()) { + case CIC_NUS_6101: PIF_Ram[37] = 0x06; PIF_Ram[38] = 0x3F; break; + case CIC_UNKNOWN: + case CIC_NUS_6102: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x3F; break; + case CIC_NUS_6103: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x78; break; + case CIC_NUS_6105: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x91; break; + case CIC_NUS_6106: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x85; break; + }*/ } } void CN64System::ExecuteCPU() { //reset code - g_Settings->SaveBool(GameRunning_CPU_Running, true); g_Settings->SaveBool(GameRunning_CPU_Paused, false); + g_Settings->SaveBool(GameRunning_CPU_Running, true); g_Notify->DisplayMessage(5, MSG_EMULATION_STARTED); m_EndEmulation = false; @@ -850,8 +850,7 @@ void CN64System::ExecuteCPU() #endif default: ExecuteInterpret(); break; } - g_Settings->SaveBool(GameRunning_CPU_Running, (DWORD)false); - Notify().WindowMode(); + g_Settings->SaveBool(GameRunning_CPU_Running, (uint32_t)false); m_Plugins->RomClosed(); if (m_SyncCPU) { @@ -886,9 +885,10 @@ void CN64System::CpuStopped() { m_SyncCPU->CpuStopped(); } + m_CPU_Handle = NULL; } -void CN64System::UpdateSyncCPU(CN64System * const SecondCPU, DWORD const Cycles) +void CN64System::UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycles) { int CyclesToExecute = Cycles - m_CyclesToSkip; @@ -940,7 +940,7 @@ void CN64System::SyncCPU(CN64System * const SecondCPU) #ifdef TEST_SP_TRACKING if (m_CurrentSP != GPR[29].UW[0]) { ErrorFound = true; -} + } #endif if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) { @@ -1015,7 +1015,7 @@ void CN64System::SyncCPU(CN64System * const SecondCPU) if (bFastSP() && m_Recomp) { - if (m_Recomp->MemoryStackPos() != (DWORD)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))) + if (m_Recomp->MemoryStackPos() != (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))) { ErrorFound = true; } @@ -1059,7 +1059,7 @@ void CN64System::SyncCPU(CN64System * const SecondCPU) // if (PROGRAM_COUNTER == 0x8009BBD8) { // g_Notify->BreakPoint(__FILEW__,__LINE__); // } - } +} void CN64System::SyncSystem() { @@ -1087,7 +1087,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) #ifdef TEST_SP_TRACKING if (m_CurrentSP != GPR[29].UW[0]) { Error.Log("m_CurrentSP,%X,%X\r\n", m_CurrentSP, GPR[29].UW[0]); - } + } #endif if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) { Error.LogF("PROGRAM_COUNTER 0x%X, 0x%X\r\n", m_Reg.m_PROGRAM_COUNTER, SecondCPU->m_Reg.m_PROGRAM_COUNTER); @@ -1174,7 +1174,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) if (m_NextTimer != SecondCPU->m_NextTimer) { - Error.LogF("Current Time: %X %X\r\n", (DWORD)m_NextTimer, (DWORD)SecondCPU->m_NextTimer); + Error.LogF("Current Time: %X %X\r\n", (uint32_t)m_NextTimer, (uint32_t)SecondCPU->m_NextTimer); } m_TLB.RecordDifference(Error, SecondCPU->m_TLB); m_SystemTimer.RecordDifference(Error, SecondCPU->m_SystemTimer); @@ -1184,13 +1184,13 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) } if (bFastSP() && m_Recomp) { - if (m_Recomp->MemoryStackPos() != (DWORD)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))) + if (m_Recomp->MemoryStackPos() != (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))) { - Error.LogF("MemoryStack = %X should be: %X\r\n", m_Recomp->MemoryStackPos(), (DWORD)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))); + Error.LogF("MemoryStack = %X should be: %X\r\n", m_Recomp->MemoryStackPos(), (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))); } } - DWORD * Rdram = (DWORD *)m_MMU_VM.Rdram(), *Rdram2 = (DWORD *)SecondCPU->m_MMU_VM.Rdram(); + uint32_t * Rdram = (uint32_t *)m_MMU_VM.Rdram(), *Rdram2 = (uint32_t *)SecondCPU->m_MMU_VM.Rdram(); for (int z = 0, n = (RdramSize() >> 2); z < n; z++) { if (Rdram[z] != Rdram2[z]) @@ -1199,7 +1199,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) } } - DWORD * Imem = (DWORD *)m_MMU_VM.Imem(), *Imem2 = (DWORD *)SecondCPU->m_MMU_VM.Imem(); + uint32_t * Imem = (uint32_t *)m_MMU_VM.Imem(), *Imem2 = (uint32_t *)SecondCPU->m_MMU_VM.Imem(); for (int z = 0; z < (0x1000 >> 2); z++) { if (Imem[z] != Imem2[z]) @@ -1207,7 +1207,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) Error.LogF("Imem[%X]: %X %X\r\n", z << 2, Imem[z], Imem2[z]); } } - DWORD * Dmem = (DWORD *)m_MMU_VM.Dmem(), *Dmem2 = (DWORD *)SecondCPU->m_MMU_VM.Dmem(); + uint32_t * Dmem = (uint32_t *)m_MMU_VM.Dmem(), *Dmem2 = (uint32_t *)SecondCPU->m_MMU_VM.Dmem(); for (int z = 0; z < (0x1000 >> 2); z++) { if (Dmem[z] != Dmem2[z]) @@ -1285,8 +1285,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) Error.Log("Code at PC:\r\n"); for (count = -10; count < 10; count++) { - DWORD OpcodeValue, Addr = m_Reg.m_PROGRAM_COUNTER + (count << 2); - if (g_MMU->LW_VAddr(Addr, (uint32_t &)OpcodeValue)) + uint32_t OpcodeValue, Addr = m_Reg.m_PROGRAM_COUNTER + (count << 2); + if (g_MMU->LW_VAddr(Addr, OpcodeValue)) { Error.LogF("%X: %s\r\n", Addr, R4300iOpcodeName(OpcodeValue, Addr)); } @@ -1295,13 +1295,13 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU) Error.Log("Code at Last Sync PC:\r\n"); for (count = 0; count < 50; count++) { - DWORD OpcodeValue, Addr = m_LastSuccessSyncPC[0] + (count << 2); - if (g_MMU->LW_VAddr(Addr, (uint32_t &)OpcodeValue)) + uint32_t OpcodeValue, Addr = m_LastSuccessSyncPC[0] + (count << 2); + if (g_MMU->LW_VAddr(Addr, OpcodeValue)) { Error.LogF("%X: %s\r\n", Addr, R4300iOpcodeName(OpcodeValue, Addr)); } } -} + } g_Notify->DisplayError(L"Sync Error"); g_Notify->BreakPoint(__FILEW__, __LINE__); @@ -1370,10 +1370,10 @@ bool CN64System::SaveState() } } - DWORD dwWritten, SaveID_0 = 0x23D8A6C8, SaveID_1 = 0x56D2CD23; - DWORD RdramSize = g_Settings->LoadDword(Game_RDRamSize); - DWORD MiInterReg = g_Reg->MI_INTR_REG; - DWORD NextViTimer = m_SystemTimer.GetTimer(CSystemTimer::ViTimer); + uint32_t SaveID_0 = 0x23D8A6C8, SaveID_1 = 0x56D2CD23; + uint32_t RdramSize = g_Settings->LoadDword(Game_RDRamSize); + uint32_t MiInterReg = g_Reg->MI_INTR_REG; + uint32_t NextViTimer = m_SystemTimer.GetTimer(CSystemTimer::ViTimer); if (g_Settings->LoadDword(Setting_AutoZipInstantSave)) { zipFile file; @@ -1381,25 +1381,25 @@ bool CN64System::SaveState() file = zipOpen(FileName.c_str(), 0); zipOpenNewFileInZip(file, CurrentSaveName.c_str(), NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION); zipWriteInFileInZip(file, &SaveID_0, sizeof(SaveID_0)); - zipWriteInFileInZip(file, &RdramSize, sizeof(DWORD)); + zipWriteInFileInZip(file, &RdramSize, sizeof(uint32_t)); zipWriteInFileInZip(file, g_Rom->GetRomAddress(), 0x40); - zipWriteInFileInZip(file, &NextViTimer, sizeof(DWORD)); + zipWriteInFileInZip(file, &NextViTimer, sizeof(uint32_t)); zipWriteInFileInZip(file, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER)); - zipWriteInFileInZip(file, m_Reg.m_GPR, sizeof(__int64) * 32); - zipWriteInFileInZip(file, m_Reg.m_FPR, sizeof(__int64) * 32); - zipWriteInFileInZip(file, m_Reg.m_CP0, sizeof(DWORD) * 32); - zipWriteInFileInZip(file, m_Reg.m_FPCR, sizeof(DWORD) * 32); - zipWriteInFileInZip(file, &m_Reg.m_HI, sizeof(__int64)); - zipWriteInFileInZip(file, &m_Reg.m_LO, sizeof(__int64)); - zipWriteInFileInZip(file, m_Reg.m_RDRAM_Registers, sizeof(DWORD) * 10); - zipWriteInFileInZip(file, m_Reg.m_SigProcessor_Interface, sizeof(DWORD) * 10); - zipWriteInFileInZip(file, m_Reg.m_Display_ControlReg, sizeof(DWORD) * 10); - zipWriteInFileInZip(file, m_Reg.m_Mips_Interface, sizeof(DWORD) * 4); - zipWriteInFileInZip(file, m_Reg.m_Video_Interface, sizeof(DWORD) * 14); - zipWriteInFileInZip(file, m_Reg.m_Audio_Interface, sizeof(DWORD) * 6); - zipWriteInFileInZip(file, m_Reg.m_Peripheral_Interface, sizeof(DWORD) * 13); - zipWriteInFileInZip(file, m_Reg.m_RDRAM_Interface, sizeof(DWORD) * 8); - zipWriteInFileInZip(file, m_Reg.m_SerialInterface, sizeof(DWORD) * 4); + zipWriteInFileInZip(file, m_Reg.m_GPR, sizeof(int64_t) * 32); + zipWriteInFileInZip(file, m_Reg.m_FPR, sizeof(int64_t) * 32); + zipWriteInFileInZip(file, m_Reg.m_CP0, sizeof(uint32_t) * 32); + zipWriteInFileInZip(file, m_Reg.m_FPCR, sizeof(uint32_t) * 32); + zipWriteInFileInZip(file, &m_Reg.m_HI, sizeof(int64_t)); + zipWriteInFileInZip(file, &m_Reg.m_LO, sizeof(int64_t)); + zipWriteInFileInZip(file, m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10); + zipWriteInFileInZip(file, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10); + zipWriteInFileInZip(file, m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10); + zipWriteInFileInZip(file, m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4); + zipWriteInFileInZip(file, m_Reg.m_Video_Interface, sizeof(uint32_t) * 14); + zipWriteInFileInZip(file, m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6); + zipWriteInFileInZip(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13); + zipWriteInFileInZip(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8); + zipWriteInFileInZip(file, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4); zipWriteInFileInZip(file, (void *const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32); zipWriteInFileInZip(file, m_MMU_VM.PifRam(), 0x40); zipWriteInFileInZip(file, m_MMU_VM.Rdram(), RdramSize); @@ -1427,26 +1427,27 @@ bool CN64System::SaveState() //Write info to file SetFilePointer(hSaveFile, 0, NULL, FILE_BEGIN); - WriteFile(hSaveFile, &SaveID_0, sizeof(DWORD), &dwWritten, NULL); - WriteFile(hSaveFile, &RdramSize, sizeof(DWORD), &dwWritten, NULL); + DWORD dwWritten; + WriteFile(hSaveFile, &SaveID_0, sizeof(uint32_t), &dwWritten, NULL); + WriteFile(hSaveFile, &RdramSize, sizeof(uint32_t), &dwWritten, NULL); WriteFile(hSaveFile, g_Rom->GetRomAddress(), 0x40, &dwWritten, NULL); - WriteFile(hSaveFile, &NextViTimer, sizeof(DWORD), &dwWritten, NULL); + WriteFile(hSaveFile, &NextViTimer, sizeof(uint32_t), &dwWritten, NULL); WriteFile(hSaveFile, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER), &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_GPR, sizeof(__int64) * 32, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_FPR, sizeof(__int64) * 32, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_CP0, sizeof(DWORD) * 32, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_FPCR, sizeof(DWORD) * 32, &dwWritten, NULL); - WriteFile(hSaveFile, &m_Reg.m_HI, sizeof(__int64), &dwWritten, NULL); - WriteFile(hSaveFile, &m_Reg.m_LO, sizeof(__int64), &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_RDRAM_Registers, sizeof(DWORD) * 10, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_SigProcessor_Interface, sizeof(DWORD) * 10, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_Display_ControlReg, sizeof(DWORD) * 10, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_Mips_Interface, sizeof(DWORD) * 4, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_Video_Interface, sizeof(DWORD) * 14, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_Audio_Interface, sizeof(DWORD) * 6, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_Peripheral_Interface, sizeof(DWORD) * 13, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_RDRAM_Interface, sizeof(DWORD) * 8, &dwWritten, NULL); - WriteFile(hSaveFile, m_Reg.m_SerialInterface, sizeof(DWORD) * 4, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_GPR, sizeof(int64_t) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_FPR, sizeof(int64_t) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_CP0, sizeof(uint32_t) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_FPCR, sizeof(uint32_t) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, &m_Reg.m_HI, sizeof(int64_t), &dwWritten, NULL); + WriteFile(hSaveFile, &m_Reg.m_LO, sizeof(int64_t), &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Video_Interface, sizeof(uint32_t) * 14, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4, &dwWritten, NULL); WriteFile(hSaveFile, &g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32, &dwWritten, NULL); WriteFile(hSaveFile, g_MMU->PifRam(), 0x40, &dwWritten, NULL); WriteFile(hSaveFile, g_MMU->Rdram(), RdramSize, &dwWritten, NULL); @@ -1511,9 +1512,9 @@ bool CN64System::LoadState() return LoadState(FileName); } -bool CN64System::LoadState(LPCSTR FileName) +bool CN64System::LoadState(const char * FileName) { - DWORD dwRead, Value, SaveRDRAMSize, NextVITimer = 0, old_status, old_width, old_dacrate; + uint32_t Value, SaveRDRAMSize, NextVITimer = 0, old_status, old_width, old_dacrate; bool LoadedZipFile = false, AudioResetOnLoad; old_status = g_Reg->VI_STATUS_REG; old_width = g_Reg->VI_WIDTH_REG; @@ -1538,7 +1539,7 @@ bool CN64System::LoadState(LPCSTR FileName) { port = unzGoToFirstFile(file); } - DWORD Value; + uint32_t Value; while (port == UNZ_OK) { unz_file_info info; @@ -1569,7 +1570,7 @@ bool CN64System::LoadState(LPCSTR FileName) unzReadCurrentFile(file, &SaveRDRAMSize, sizeof(SaveRDRAMSize)); //Check header - BYTE LoadHeader[64]; + uint8_t LoadHeader[64]; unzReadCurrentFile(file, LoadHeader, 0x40); if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0) { @@ -1587,21 +1588,21 @@ bool CN64System::LoadState(LPCSTR FileName) g_Settings->SaveDword(Game_RDRamSize, SaveRDRAMSize); unzReadCurrentFile(file, &NextVITimer, sizeof(NextVITimer)); unzReadCurrentFile(file, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER)); - unzReadCurrentFile(file, m_Reg.m_GPR, sizeof(__int64) * 32); - unzReadCurrentFile(file, m_Reg.m_FPR, sizeof(__int64) * 32); - unzReadCurrentFile(file, m_Reg.m_CP0, sizeof(DWORD) * 32); - unzReadCurrentFile(file, m_Reg.m_FPCR, sizeof(DWORD) * 32); - unzReadCurrentFile(file, &m_Reg.m_HI, sizeof(__int64)); - unzReadCurrentFile(file, &m_Reg.m_LO, sizeof(__int64)); - unzReadCurrentFile(file, m_Reg.m_RDRAM_Registers, sizeof(DWORD) * 10); - unzReadCurrentFile(file, m_Reg.m_SigProcessor_Interface, sizeof(DWORD) * 10); - unzReadCurrentFile(file, m_Reg.m_Display_ControlReg, sizeof(DWORD) * 10); - unzReadCurrentFile(file, m_Reg.m_Mips_Interface, sizeof(DWORD) * 4); - unzReadCurrentFile(file, m_Reg.m_Video_Interface, sizeof(DWORD) * 14); - unzReadCurrentFile(file, m_Reg.m_Audio_Interface, sizeof(DWORD) * 6); - unzReadCurrentFile(file, m_Reg.m_Peripheral_Interface, sizeof(DWORD) * 13); - unzReadCurrentFile(file, m_Reg.m_RDRAM_Interface, sizeof(DWORD) * 8); - unzReadCurrentFile(file, m_Reg.m_SerialInterface, sizeof(DWORD) * 4); + unzReadCurrentFile(file, m_Reg.m_GPR, sizeof(int64_t) * 32); + unzReadCurrentFile(file, m_Reg.m_FPR, sizeof(int64_t) * 32); + unzReadCurrentFile(file, m_Reg.m_CP0, sizeof(uint32_t) * 32); + unzReadCurrentFile(file, m_Reg.m_FPCR, sizeof(uint32_t) * 32); + unzReadCurrentFile(file, &m_Reg.m_HI, sizeof(int64_t)); + unzReadCurrentFile(file, &m_Reg.m_LO, sizeof(int64_t)); + unzReadCurrentFile(file, m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10); + unzReadCurrentFile(file, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10); + unzReadCurrentFile(file, m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10); + unzReadCurrentFile(file, m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4); + unzReadCurrentFile(file, m_Reg.m_Video_Interface, sizeof(uint32_t) * 14); + unzReadCurrentFile(file, m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6); + unzReadCurrentFile(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13); + unzReadCurrentFile(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8); + unzReadCurrentFile(file, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4); unzReadCurrentFile(file, (void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32); unzReadCurrentFile(file, m_MMU_VM.PifRam(), 0x40); unzReadCurrentFile(file, m_MMU_VM.Rdram(), SaveRDRAMSize); @@ -1632,22 +1633,24 @@ bool CN64System::LoadState(LPCSTR FileName) } SetFilePointer(hSaveFile, 0, NULL, FILE_BEGIN); + DWORD dwRead; ReadFile(hSaveFile, &Value, sizeof(Value), &dwRead, NULL); if (Value != 0x23D8A6C8) return false; ReadFile(hSaveFile, &SaveRDRAMSize, sizeof(SaveRDRAMSize), &dwRead, NULL); //Check header - BYTE LoadHeader[64]; + uint8_t LoadHeader[64]; ReadFile(hSaveFile, LoadHeader, 0x40, &dwRead, NULL); if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0) { //if (inFullScreen) { return false; } - int result = MessageBoxW(NULL, GS(MSG_SAVE_STATE_HEADER), GS(MSG_MSGBOX_TITLE), - MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2); + int result = MessageBoxW(NULL, GS(MSG_SAVE_STATE_HEADER), GS(MSG_MSGBOX_TITLE), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2); if (result == IDNO) + { return false; + } } Reset(false, true); m_MMU_VM.UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4); @@ -1656,21 +1659,21 @@ bool CN64System::LoadState(LPCSTR FileName) ReadFile(hSaveFile, &NextVITimer, sizeof(NextVITimer), &dwRead, NULL); ReadFile(hSaveFile, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER), &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_GPR, sizeof(__int64) * 32, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_FPR, sizeof(__int64) * 32, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_CP0, sizeof(DWORD) * 32, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_FPCR, sizeof(DWORD) * 32, &dwRead, NULL); - ReadFile(hSaveFile, &m_Reg.m_HI, sizeof(__int64), &dwRead, NULL); - ReadFile(hSaveFile, &m_Reg.m_LO, sizeof(__int64), &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_RDRAM_Registers, sizeof(DWORD) * 10, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_SigProcessor_Interface, sizeof(DWORD) * 10, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_Display_ControlReg, sizeof(DWORD) * 10, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_Mips_Interface, sizeof(DWORD) * 4, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_Video_Interface, sizeof(DWORD) * 14, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_Audio_Interface, sizeof(DWORD) * 6, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_Peripheral_Interface, sizeof(DWORD) * 13, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_RDRAM_Interface, sizeof(DWORD) * 8, &dwRead, NULL); - ReadFile(hSaveFile, m_Reg.m_SerialInterface, sizeof(DWORD) * 4, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_GPR, sizeof(int64_t) * 32, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_FPR, sizeof(int64_t) * 32, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_CP0, sizeof(uint32_t) * 32, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_FPCR, sizeof(uint32_t) * 32, &dwRead, NULL); + ReadFile(hSaveFile, &m_Reg.m_HI, sizeof(int64_t), &dwRead, NULL); + ReadFile(hSaveFile, &m_Reg.m_LO, sizeof(int64_t), &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Video_Interface, sizeof(uint32_t) * 14, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4, &dwRead, NULL); ReadFile(hSaveFile, (void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32, &dwRead, NULL); ReadFile(hSaveFile, m_MMU_VM.PifRam(), 0x40, &dwRead, NULL); ReadFile(hSaveFile, m_MMU_VM.Rdram(), SaveRDRAMSize, &dwRead, NULL); @@ -1774,10 +1777,10 @@ void CN64System::RunRSP() { SPECIAL_TIMERS CPU_UsageAddr = Timer_None/*, ProfileAddr = Timer_None*/; - DWORD Task = 0; + uint32_t Task = 0; if (m_RspBroke) { - g_MMU->LW_VAddr(0xA4000FC0, (uint32_t &)Task); + g_MMU->LW_VAddr(0xA4000FC0, Task); if (Task == 1 && (m_Reg.DPC_STATUS_REG & DPC_STATUS_FREEZE) != 0) { WriteTrace(TraceRSP, __FUNCTION__ ": Dlist that is frozen"); @@ -1871,7 +1874,7 @@ void CN64System::SyncToAudio() WriteTraceF(TraceAudio, __FUNCTION__ ": Audio Interrupt done (%d)", i); break; } - Sleep(1); + pjutil::Sleep(1); } if (bShowCPUPer()) { @@ -1882,7 +1885,7 @@ void CN64System::SyncToAudio() void CN64System::RefreshScreen() { SPECIAL_TIMERS CPU_UsageAddr = Timer_None/*, ProfilingAddr = Timer_None*/; - DWORD VI_INTR_TIME = 500000; + uint32_t VI_INTR_TIME = 500000; if (bShowCPUPer()) { CPU_UsageAddr = m_CPU_Usage.StartTimer(Timer_RefreshScreen); } //if (bProfiling) { ProfilingAddr = m_Profile.StartTimer(Timer_RefreshScreen); } @@ -1931,7 +1934,6 @@ void CN64System::RefreshScreen() WriteTrace(TraceGfxPlugin, __FUNCTION__ ": Exception caught"); WriteTrace(TraceError, __FUNCTION__ ": Exception caught"); } - g_MMU->UpdateFieldSerration((m_Reg.VI_STATUS_REG & 0x40) != 0); if ((bBasicMode() || bLimitFPS()) && !bSyncToAudio()) @@ -1988,9 +1990,9 @@ bool CN64System::WriteToProtectedMemory(uint32_t Address, int length) #ifdef tofix return m_Recomp->ClearRecompCode_Phys(Address, length, CRecompiler::Remove_ProtectedMem); #endif -} - return false; } + return false; +} void CN64System::TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly) { diff --git a/Source/Project64/N64 System/N64 Class.h b/Source/Project64/N64 System/N64 Class.h index b770e9e05..9baa3b9e8 100644 --- a/Source/Project64/N64 System/N64 Class.h +++ b/Source/Project64/N64 System/N64 Class.h @@ -15,7 +15,7 @@ typedef std::list EVENT_LIST; -typedef std::map FUNC_CALLS; +typedef std::map FUNC_CALLS; class CPlugins; class CRSP_Plugin; @@ -36,11 +36,6 @@ public: CN64System(CPlugins * Plugins, bool SavesReadOnly); virtual ~CN64System(void); - struct ThreadInfo { - HANDLE * ThreadHandle; - DWORD ThreadID; - }; - CProfiling m_Profile; CCheats m_Cheats; bool m_EndEmulation; @@ -64,21 +59,21 @@ public: void Pause(); void RunRSP(); bool SaveState(); - bool LoadState(LPCSTR FileName); + bool LoadState(const char * FileName); bool LoadState(); bool DmaUsed() const { return m_DMAUsed; } void SetDmaUsed(bool DMAUsed) { m_DMAUsed = DMAUsed; } void SetCheatsSlectionChanged(bool changed) { m_CheatsSlectionChanged = changed; } bool HasCheatsSlectionChanged(void) const { return m_CheatsSlectionChanged; } - DWORD GetButtons(int Control) const { return m_Buttons[Control]; } + uint32_t GetButtons(int32_t Control) const { return m_Buttons[Control]; } //Variable used to track that the SP is being handled and stays the same as the real SP in sync core #ifdef TEST_SP_TRACKING - DWORD m_CurrentSP; + uint32_t m_CurrentSP; #endif //For Sync CPU - void UpdateSyncCPU(CN64System * const SecondCPU, DWORD const Cycles); + void UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycles); void SyncCPU(CN64System * const SecondCPU); void SyncCPUPC(CN64System * const SecondCPU); void SyncSystem(); @@ -94,8 +89,14 @@ private: friend CSystemTimer; //Used for loading and potentially executing the CPU in its own thread. + struct ThreadInfo + { + void * ThreadHandle; + uint32_t ThreadID; + }; + static void StartEmulationThread(ThreadInfo * Info); - static bool EmulationStarting(HANDLE hThread, DWORD ThreadId); + static bool EmulationStarting(void * hThread, uint32_t ThreadId); void ExecuteCPU(); void RefreshScreen(); @@ -114,7 +115,7 @@ private: void CpuStopped(); //Function in CMipsMemory_CallBack - virtual bool WriteToProtectedMemory(uint32_t Address, int length); + virtual bool WriteToProtectedMemory(uint32_t Address, int32_t length); //Functions in CTLB_CB void TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly); @@ -133,34 +134,34 @@ private: CAudio m_Audio; CSpeedLimitor m_Limitor; bool m_InReset; - int m_NextTimer; + int32_t m_NextTimer; CSystemTimer m_SystemTimer; bool m_bCleanFrameBox; bool m_bInitialized; bool m_RspBroke; bool m_DMAUsed; - DWORD m_Buttons[4]; + uint32_t m_Buttons[4]; bool m_TestTimer; - DWORD m_NextInstruction; - DWORD m_JumpToLocation; + uint32_t m_NextInstruction; + uint32_t m_JumpToLocation; uint32_t m_TLBLoadAddress; uint32_t m_TLBStoreAddress; - DWORD m_SyncCount; + uint32_t m_SyncCount; bool m_CheatsSlectionChanged; //When Syncing cores this is the PC where it last Sync'ed correctly - DWORD m_LastSuccessSyncPC[10]; - int m_CyclesToSkip; + uint32_t m_LastSuccessSyncPC[10]; + int32_t m_CyclesToSkip; //Handle to the cpu thread - HANDLE m_CPU_Handle; - DWORD m_CPU_ThreadID; + void * m_CPU_Handle; + uint32_t m_CPU_ThreadID; //Handle to pause mutex SyncEvent m_hPauseEvent; //No of Alist and Dlist sent to the RSP - DWORD m_AlistCount, m_DlistCount, m_UnknownCount; + uint32_t m_AlistCount, m_DlistCount, m_UnknownCount; //list of function that have been called .. used in profiling FUNC_CALLS m_FunctionCalls;