From 1cfb207d62eda89b7ffd186724f078a6c8a62f6a Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Sat, 25 Jun 2022 01:22:32 +0200 Subject: [PATCH] Get rid of some logs --- src/core/bus.cpp | 388 +++++------------------------- src/core/dma.cpp | 66 +---- src/core/gpu_backend.cpp | 4 - src/core/interrupt_controller.cpp | 15 +- src/core/spu.cpp | 49 ++-- src/core/timers.cpp | 17 +- src/core/timing_event.cpp | 8 - 7 files changed, 80 insertions(+), 467 deletions(-) diff --git a/src/core/bus.cpp b/src/core/bus.cpp index 60630976..d3fcc68c 100644 --- a/src/core/bus.cpp +++ b/src/core/bus.cpp @@ -2,7 +2,6 @@ #include "cdrom.h" #include "common/align.h" #include "common/assert.h" -#include "common/log.h" #include "common/make_array.h" #include "common/state_wrapper.h" #include "cpu_code_cache.h" @@ -20,7 +19,6 @@ #include #include #include -Log_SetChannel(Bus); namespace Bus { @@ -205,13 +203,8 @@ void SetExpansionROM(std::vector data) void SetBIOS(const std::vector& image) { - if (image.size() != static_cast(BIOS_SIZE)) - { - Panic("Incorrect BIOS image size"); - return; - } - - std::memcpy(g_bios, image.data(), BIOS_SIZE); + if (image.size() == static_cast(BIOS_SIZE)) + std::memcpy(g_bios, image.data(), BIOS_SIZE); } std::tuple CalculateMemoryTiming(MEMDELAY mem_delay, COMDELAY common_delay) @@ -258,41 +251,23 @@ void RecalculateMemoryTimings() CalculateMemoryTiming(m_MEMCTRL.cdrom_delay_size, m_MEMCTRL.common_delay); std::tie(m_spu_access_time[0], m_spu_access_time[1], m_spu_access_time[2]) = CalculateMemoryTiming(m_MEMCTRL.spu_delay_size, m_MEMCTRL.common_delay); - - Log_TracePrintf("BIOS Memory Timing: %u bit bus, byte=%d, halfword=%d, word=%d", - m_MEMCTRL.bios_delay_size.data_bus_16bit ? 16 : 8, m_bios_access_time[0] + 1, - m_bios_access_time[1] + 1, m_bios_access_time[2] + 1); - Log_TracePrintf("CDROM Memory Timing: %u bit bus, byte=%d, halfword=%d, word=%d", - m_MEMCTRL.cdrom_delay_size.data_bus_16bit ? 16 : 8, m_cdrom_access_time[0] + 1, - m_cdrom_access_time[1] + 1, m_cdrom_access_time[2] + 1); - Log_TracePrintf("SPU Memory Timing: %u bit bus, byte=%d, halfword=%d, word=%d", - m_MEMCTRL.spu_delay_size.data_bus_16bit ? 16 : 8, m_spu_access_time[0] + 1, m_spu_access_time[1] + 1, - m_spu_access_time[2] + 1); } bool AllocateMemory(bool enable_8mb_ram) { if (!m_memory_arena.Create(MEMORY_ARENA_SIZE, true, false)) - { - Log_ErrorPrint("Failed to create memory arena"); return false; - } // Create the base views. const u32 ram_size = enable_8mb_ram ? RAM_8MB_SIZE : RAM_2MB_SIZE; const u32 ram_mask = enable_8mb_ram ? RAM_8MB_MASK : RAM_2MB_MASK; g_ram = static_cast(m_memory_arena.CreateViewPtr(MEMORY_ARENA_RAM_OFFSET, ram_size, true, false)); if (!g_ram) - { - Log_ErrorPrintf("Failed to create base views of memory (%u bytes RAM)", ram_size); return false; - } g_ram_mask = ram_mask; g_ram_size = ram_size; m_ram_code_page_count = enable_8mb_ram ? RAM_8MB_CODE_PAGE_COUNT : RAM_2MB_CODE_PAGE_COUNT; - - Log_InfoPrintf("RAM is %u bytes at %p", g_ram_size, g_ram); return true; } @@ -367,22 +342,14 @@ void UpdateFastmemViews(CPUFastmemMode mode) { m_fastmem_base = static_cast(m_memory_arena.FindBaseAddressForMapping(FASTMEM_REGION_SIZE)); if (!m_fastmem_base) - { - Log_ErrorPrint("Failed to find base address for fastmem"); return; - } - - Log_InfoPrintf("Fastmem base: %p", m_fastmem_base); } auto MapRAM = [](u32 base_address) { u8* map_address = m_fastmem_base + base_address; auto view = m_memory_arena.CreateView(MEMORY_ARENA_RAM_OFFSET, g_ram_size, true, false, map_address); if (!view) - { - Log_ErrorPrintf("Failed to map RAM at fastmem area %p (offset 0x%08X)", map_address, g_ram_size); return; - } // mark all pages with code as non-writable for (u32 i = 0; i < m_ram_code_page_count; i++) @@ -391,10 +358,7 @@ void UpdateFastmemViews(CPUFastmemMode mode) { u8* page_address = map_address + (i * HOST_PAGE_SIZE); if (!m_memory_arena.SetPageProtection(page_address, HOST_PAGE_SIZE, true, false, false)) - { - Log_ErrorPrintf("Failed to write-protect code page at %p", page_address); return; - } } } @@ -408,11 +372,7 @@ void UpdateFastmemViews(CPUFastmemMode mode) u8* map_address = m_fastmem_base + start_address; auto view = m_memory_arena.CreateReservedView(end_address_inclusive - start_address + 1, map_address); if (!view) - { - Log_ErrorPrintf("Failed to map reserved region %p (size 0x%08X)", map_address, - end_address_inclusive - start_address + 1); return; - } m_fastmem_reserved_views.push_back(std::move(view.value())); #endif @@ -442,8 +402,6 @@ void UpdateFastmemViews(CPUFastmemMode mode) { m_fastmem_lut = static_cast(std::calloc(FASTMEM_LUT_NUM_SLOTS, sizeof(u8*))); Assert(m_fastmem_lut); - - Log_InfoPrintf("Fastmem base (software): %p", m_fastmem_lut); } auto MapRAM = [](u32 base_address) { @@ -480,12 +438,10 @@ bool CanUseFastmemForAddress(VirtualMemoryAddress address) switch (m_fastmem_mode) { #ifdef WITH_MMAP_FASTMEM + // Currently since we don't map the mirrors, don't use fastmem for them. + // This is because the swapping of page code bits for SMC is too expensive. case CPUFastmemMode::MMap: - { - // Currently since we don't map the mirrors, don't use fastmem for them. - // This is because the swapping of page code bits for SMC is too expensive. return (paddr < RAM_MIRROR_END); - } #endif case CPUFastmemMode::LUT: @@ -493,8 +449,10 @@ bool CanUseFastmemForAddress(VirtualMemoryAddress address) case CPUFastmemMode::Disabled: default: - return false; + break; } + + return false; } bool IsRAMCodePage(u32 index) @@ -531,11 +489,7 @@ void SetCodePageFastmemProtection(u32 page_index, bool writable) for (const auto& view : m_fastmem_ram_views) { u8* page_address = static_cast(view.GetBasePointer()) + (page_index * HOST_PAGE_SIZE); - if (!m_memory_arena.SetPageProtection(page_address, HOST_PAGE_SIZE, true, writable, false)) - { - Log_ErrorPrintf("Failed to %s code page %u (0x%08X) @ %p", writable ? "unprotect" : "protect", page_index, - page_index * static_cast(HOST_PAGE_SIZE), page_address); - } + m_memory_arena.SetPageProtection(page_address, HOST_PAGE_SIZE, true, writable, false); } return; @@ -560,12 +514,7 @@ void ClearRAMCodePageFlags() { // unprotect fastmem pages for (const auto& view : m_fastmem_ram_views) - { - if (!m_memory_arena.SetPageProtection(view.GetBasePointer(), view.GetMappingSize(), true, true, false)) - { - Log_ErrorPrintf("Failed to unprotect code pages for fastmem view @ %p", view.GetBasePointer()); - } - } + m_memory_arena.SetPageProtection(view.GetBasePointer(), view.GetMappingSize(), true, true, false); } #endif @@ -659,9 +608,6 @@ u8* GetMemoryRegionPointer(MemoryRegion region) case MemoryRegion::RAMMirror3: return (g_ram + ((RAM_8MB_SIZE * 3) & g_ram_mask)); - case MemoryRegion::EXP1: - return nullptr; - case MemoryRegion::Scratchpad: return CPU::g_state.dcache.data(); @@ -669,8 +615,11 @@ u8* GetMemoryRegionPointer(MemoryRegion region) return g_bios; default: - return nullptr; + case MemoryRegion::EXP1: + break; } + + return nullptr; } static ALWAYS_INLINE_RELEASE bool MaskedMemoryCompare(const u8* pattern, const u8* mask, u32 pattern_length, @@ -733,28 +682,8 @@ std::optional SearchMemory(PhysicalMemoryAddress start_ad static TickCount DoInvalidAccess(MemoryAccessType type, MemoryAccessSize size, PhysicalMemoryAddress address, u32& value) { - SmallString str; - str.AppendString("Invalid bus "); - if (size == MemoryAccessSize::Byte) - str.AppendString("byte"); - if (size == MemoryAccessSize::HalfWord) - str.AppendString("word"); - if (size == MemoryAccessSize::Word) - str.AppendString("dword"); - str.AppendCharacter(' '); - if (type == MemoryAccessType::Read) - str.AppendString("read"); - else - str.AppendString("write"); - - str.AppendFormattedString(" at address 0x%08X", address); - if (type == MemoryAccessType::Write) - str.AppendFormattedString(" (value 0x%08X)", value); - - Log_ErrorPrint(str); if (type == MemoryAccessType::Read) value = UINT32_C(0xFFFFFFFF); - return (type == MemoryAccessType::Read) ? 1 : 0; } @@ -849,9 +778,7 @@ ALWAYS_INLINE static TickCount DoBIOSAccess(u32 offset, u32& value) { offset &= UINT32_C(0x7FFFF); if constexpr (size == MemoryAccessSize::Byte) - { value = ZeroExtend32(g_bios[offset]); - } else if constexpr (size == MemoryAccessSize::HalfWord) { u16 temp; @@ -859,13 +786,7 @@ ALWAYS_INLINE static TickCount DoBIOSAccess(u32 offset, u32& value) value = ZeroExtend32(temp); } else - { std::memcpy(&value, &g_bios[offset], sizeof(u32)); - } - } - else - { - // Writes are ignored. } return m_bios_access_time[static_cast(size)]; @@ -876,29 +797,21 @@ static TickCount DoEXP1Access(u32 offset, u32& value) { if constexpr (type == MemoryAccessType::Read) { + // EXP1 not present. if (m_exp1_rom.empty()) - { - // EXP1 not present. value = UINT32_C(0xFFFFFFFF); - } + // Bit 0 - Action Replay On/Off else if (offset == 0x20018) - { - // Bit 0 - Action Replay On/Off value = UINT32_C(1); - } else { const u32 transfer_size = u32(1) << static_cast(size); if ((offset + transfer_size) > m_exp1_rom.size()) - { value = UINT32_C(0); - } else { if constexpr (size == MemoryAccessSize::Byte) - { value = ZeroExtend32(m_exp1_rom[offset]); - } else if constexpr (size == MemoryAccessSize::HalfWord) { u16 halfword; @@ -906,21 +819,13 @@ static TickCount DoEXP1Access(u32 offset, u32& value) value = ZeroExtend32(halfword); } else - { std::memcpy(&value, &m_exp1_rom[offset], sizeof(value)); - } - - // Log_DevPrintf("EXP1 read: 0x%08X -> 0x%08X", EXP1_BASE | offset, value); } } return m_exp1_access_time[static_cast(size)]; } - else - { - Log_WarningPrintf("EXP1 write: 0x%08X <- 0x%08X", EXP1_BASE | offset, value); - return 0; - } + return 0; } template @@ -930,91 +835,40 @@ static TickCount DoEXP2Access(u32 offset, u32& value) { // rx/tx buffer empty if (offset == 0x21) - { value = 0x04 | 0x08; - } + // nocash expansion area else if (offset >= 0x60 && offset <= 0x67) - { - // nocash expansion area value = UINT32_C(0xFFFFFFFF); - } else - { - Log_WarningPrintf("EXP2 read: 0x%08X", EXP2_BASE | offset); value = UINT32_C(0xFFFFFFFF); - } return m_exp2_access_time[static_cast(size)]; } - else + if (offset == 0x23 || offset == 0x80) { - if (offset == 0x23 || offset == 0x80) - { - if (value == '\r') - { - } - else if (value == '\n') - { - if (!m_tty_line_buffer.empty()) - { - Log_InfoPrintf("TTY: %s", m_tty_line_buffer.c_str()); - } - m_tty_line_buffer.clear(); - } - else - { - m_tty_line_buffer += static_cast(Truncate8(value)); - } - } - else if (offset == 0x41 || offset == 0x42) - { - Log_DevPrintf("BIOS POST status: %02X", value & UINT32_C(0x0F)); - } - else if (offset == 0x70) - { - Log_DevPrintf("BIOS POST2 status: %02X", value & UINT32_C(0x0F)); - } + if (value == '\r') { } + else if (value == '\n') + m_tty_line_buffer.clear(); else - { - Log_WarningPrintf("EXP2 write: 0x%08X <- 0x%08X", EXP2_BASE | offset, value); - } - - return 0; + m_tty_line_buffer += static_cast(Truncate8(value)); } + return 0; } template ALWAYS_INLINE static TickCount DoEXP3Access(u32 offset, u32& value) { if constexpr (type == MemoryAccessType::Read) - { - Log_WarningPrintf("EXP3 read: 0x%08X -> 0x%08X", offset, EXP3_BASE | offset); value = UINT32_C(0xFFFFFFFF); - - return 0; - } - else - { - if (offset == 0) - Log_WarningPrintf("BIOS POST3 status: %02X", value & UINT32_C(0x0F)); - - return 0; - } + return 0; } template ALWAYS_INLINE static TickCount DoUnknownEXPAccess(u32 address, u32& value) { if constexpr (type == MemoryAccessType::Read) - { - Log_ErrorPrintf("Unknown EXP read: 0x%08X", address); return -1; - } - else - { - Log_WarningPrintf("Unknown EXP write: 0x%08X <- 0x%08X", address, value); - return 0; - } + return 0; } template @@ -1038,8 +892,8 @@ ALWAYS_INLINE static TickCount DoMemoryControlAccess(u32 offset, u32& value) m_MEMCTRL.regs[index] = new_value; RecalculateMemoryTimings(); } - return 0; } + return 0; } template @@ -1047,30 +901,15 @@ ALWAYS_INLINE static TickCount DoMemoryControl2Access(u32 offset, u32& value) { if constexpr (type == MemoryAccessType::Read) { - if (offset == 0x00) - { - value = m_ram_size_reg; - } - else - { + if (offset != 0x00) return DoInvalidAccess(type, size, MEMCTRL2_BASE | offset, value); - } - + value = m_ram_size_reg; return 2; } - else - { - if (offset == 0x00) - { - m_ram_size_reg = value; - } - else - { - return DoInvalidAccess(type, size, MEMCTRL2_BASE | offset, value); - } - - return 0; - } + if (offset != 0x00) + return DoInvalidAccess(type, size, MEMCTRL2_BASE | offset, value); + m_ram_size_reg = value; + return 0; } template @@ -1082,11 +921,8 @@ ALWAYS_INLINE static TickCount DoPadAccess(u32 offset, u32& value) value = FIXUP_HALFWORD_READ_VALUE(size, offset, value); return 2; } - else - { - g_pad.WriteRegister(FIXUP_HALFWORD_OFFSET(size, offset), FIXUP_HALFWORD_WRITE_VALUE(size, offset, value)); - return 0; - } + g_pad.WriteRegister(FIXUP_HALFWORD_OFFSET(size, offset), FIXUP_HALFWORD_WRITE_VALUE(size, offset, value)); + return 0; } template @@ -1098,11 +934,8 @@ ALWAYS_INLINE static TickCount DoSIOAccess(u32 offset, u32& value) value = FIXUP_HALFWORD_READ_VALUE(size, offset, value); return 2; } - else - { - g_sio.WriteRegister(FIXUP_HALFWORD_OFFSET(size, offset), FIXUP_HALFWORD_WRITE_VALUE(size, offset, value)); - return 0; - } + g_sio.WriteRegister(FIXUP_HALFWORD_OFFSET(size, offset), FIXUP_HALFWORD_WRITE_VALUE(size, offset, value)); + return 0; } template @@ -1140,19 +973,15 @@ ALWAYS_INLINE static TickCount DoCDROMAccess(u32 offset, u32& value) switch (size) { case MemoryAccessSize::Word: - { g_cdrom.WriteRegister(offset, Truncate8(value & 0xFFu)); g_cdrom.WriteRegister(offset + 1u, Truncate8((value >> 8) & 0xFFu)); g_cdrom.WriteRegister(offset + 2u, Truncate8((value >> 16) & 0xFFu)); g_cdrom.WriteRegister(offset + 3u, Truncate8((value >> 24) & 0xFFu)); - } break; case MemoryAccessSize::HalfWord: - { g_cdrom.WriteRegister(offset, Truncate8(value & 0xFFu)); g_cdrom.WriteRegister(offset + 1u, Truncate8((value >> 8) & 0xFFu)); - } break; case MemoryAccessSize::Byte: @@ -1160,9 +989,8 @@ ALWAYS_INLINE static TickCount DoCDROMAccess(u32 offset, u32& value) g_cdrom.WriteRegister(offset, Truncate8(value)); break; } - - return 0; } + return 0; } template @@ -1174,11 +1002,8 @@ ALWAYS_INLINE static TickCount DoGPUAccess(u32 offset, u32& value) value = FIXUP_WORD_READ_VALUE(size, offset, value); return 2; } - else - { - g_gpu->WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); - return 0; - } + g_gpu->WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); + return 0; } template @@ -1190,11 +1015,8 @@ ALWAYS_INLINE static TickCount DoMDECAccess(u32 offset, u32& value) value = FIXUP_WORD_READ_VALUE(size, offset, value); return 2; } - else - { - g_mdec.WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); - return 0; - } + g_mdec.WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); + return 0; } template @@ -1206,11 +1028,8 @@ ALWAYS_INLINE static TickCount DoAccessInterruptController(u32 offset, u32& valu value = FIXUP_WORD_READ_VALUE(size, offset, value); return 2; } - else - { - g_interrupt_controller.WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); - return 0; - } + g_interrupt_controller.WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); + return 0; } template @@ -1222,11 +1041,8 @@ ALWAYS_INLINE static TickCount DoAccessTimers(u32 offset, u32& value) value = FIXUP_WORD_READ_VALUE(size, offset, value); return 2; } - else - { - g_timers.WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); - return 0; - } + g_timers.WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); + return 0; } template @@ -1246,9 +1062,7 @@ ALWAYS_INLINE static TickCount DoAccessSPU(u32 offset, u32& value) break; case MemoryAccessSize::HalfWord: - { value = ZeroExtend32(g_spu.ReadRegister(offset)); - } break; case MemoryAccessSize::Byte: @@ -1262,7 +1076,6 @@ ALWAYS_INLINE static TickCount DoAccessSPU(u32 offset, u32& value) return m_spu_access_time[static_cast(size)]; } - else { // 32-bit writes are written as two 16-bit writes. // TODO: Ignore if address is not aligned. @@ -1290,9 +1103,8 @@ ALWAYS_INLINE static TickCount DoAccessSPU(u32 offset, u32& value) break; } } - - return 0; } + return 0; } template @@ -1304,11 +1116,8 @@ ALWAYS_INLINE static TickCount DoDMAAccess(u32 offset, u32& value) value = FIXUP_WORD_READ_VALUE(size, offset, value); return 2; } - else - { - g_dma.WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); - return 0; - } + g_dma.WriteRegister(FIXUP_WORD_OFFSET(size, offset), FIXUP_WORD_WRITE_VALUE(size, offset, value)); + return 0; } } // namespace Bus @@ -1338,14 +1147,11 @@ ALWAYS_INLINE_RELEASE bool DoInstructionRead(PhysicalMemoryAddress address, void return true; } - else - { - if (raise_exceptions) - CPU::RaiseException(address, Cop0Registers::CAUSE::MakeValueForException(Exception::IBE, false, false, 0)); + if (raise_exceptions) + CPU::RaiseException(address, Cop0Registers::CAUSE::MakeValueForException(Exception::IBE, false, false, 0)); - std::memset(data, 0, sizeof(u32) * word_count); - return false; - } + std::memset(data, 0, sizeof(u32) * word_count); + return false; } TickCount GetInstructionReadTicks(VirtualMemoryAddress address) @@ -1355,17 +1161,10 @@ TickCount GetInstructionReadTicks(VirtualMemoryAddress address) address &= PHYSICAL_MEMORY_ADDRESS_MASK; if (address < RAM_MIRROR_END) - { return RAM_READ_TICKS; - } else if (address >= BIOS_BASE && address < (BIOS_BASE + BIOS_SIZE)) - { return m_bios_access_time[static_cast(MemoryAccessSize::Word)]; - } - else - { - return 0; - } + return 0; } TickCount GetICacheFillTicks(VirtualMemoryAddress address) @@ -1375,18 +1174,11 @@ TickCount GetICacheFillTicks(VirtualMemoryAddress address) address &= PHYSICAL_MEMORY_ADDRESS_MASK; if (address < RAM_MIRROR_END) - { return 1 * ((ICACHE_LINE_SIZE - (address & (ICACHE_LINE_SIZE - 1))) / sizeof(u32)); - } else if (address >= BIOS_BASE && address < (BIOS_BASE + BIOS_SIZE)) - { return m_bios_access_time[static_cast(MemoryAccessSize::Word)] * ((ICACHE_LINE_SIZE - (address & (ICACHE_LINE_SIZE - 1))) / sizeof(u32)); - } - else - { - return 0; - } + return 0; } void CheckAndUpdateICacheTags(u32 line_count, TickCount uncached_ticks) @@ -1409,9 +1201,7 @@ void CheckAndUpdateICacheTags(u32 line_count, TickCount uncached_ticks) g_state.pending_ticks += ticks; } else - { g_state.pending_ticks += uncached_ticks; - } } u32 FillICache(VirtualMemoryAddress address) @@ -1473,7 +1263,6 @@ ALWAYS_INLINE_RELEASE static void WriteICache(VirtualMemoryAddress address, u32 static void WriteCacheControl(u32 value) { - Log_DevPrintf("Cache control <- 0x%08X", value); g_state.cache_control.bits = value; } @@ -1557,7 +1346,6 @@ static ALWAYS_INLINE TickCount DoMemoryAccess(VirtualMemoryAddress address, u32& case 0x06: // KSEG2 case 0x07: // KSEG2 - { if (address == 0xFFFE0130) { if constexpr (type == MemoryAccessType::Read) @@ -1567,108 +1355,56 @@ static ALWAYS_INLINE TickCount DoMemoryAccess(VirtualMemoryAddress address, u32& return 0; } - else - { - if constexpr (type == MemoryAccessType::Read) - value = UINT32_C(0xFFFFFFFF); - - return -1; - } - } + if constexpr (type == MemoryAccessType::Read) + value = UINT32_C(0xFFFFFFFF); + return -1; } if (address < RAM_MIRROR_END) - { return DoRAMAccess(address, value); - } else if (address >= BIOS_BASE && address < (BIOS_BASE + BIOS_SIZE)) - { return DoBIOSAccess(static_cast(address - BIOS_BASE), value); - } else if (address < EXP1_BASE) - { return DoInvalidAccess(type, size, address, value); - } else if (address < (EXP1_BASE + EXP1_SIZE)) - { return DoEXP1Access(address & EXP1_MASK, value); - } else if (address < MEMCTRL_BASE) - { return DoInvalidAccess(type, size, address, value); - } else if (address < (MEMCTRL_BASE + MEMCTRL_SIZE)) - { return DoMemoryControlAccess(address & MEMCTRL_MASK, value); - } else if (address < (PAD_BASE + PAD_SIZE)) - { return DoPadAccess(address & PAD_MASK, value); - } else if (address < (SIO_BASE + SIO_SIZE)) - { return DoSIOAccess(address & SIO_MASK, value); - } else if (address < (MEMCTRL2_BASE + MEMCTRL2_SIZE)) - { return DoMemoryControl2Access(address & MEMCTRL2_MASK, value); - } else if (address < (INTERRUPT_CONTROLLER_BASE + INTERRUPT_CONTROLLER_SIZE)) - { return DoAccessInterruptController(address & INTERRUPT_CONTROLLER_MASK, value); - } else if (address < (DMA_BASE + DMA_SIZE)) - { return DoDMAAccess(address & DMA_MASK, value); - } else if (address < (TIMERS_BASE + TIMERS_SIZE)) - { return DoAccessTimers(address & TIMERS_MASK, value); - } else if (address < CDROM_BASE) - { return DoInvalidAccess(type, size, address, value); - } else if (address < (CDROM_BASE + GPU_SIZE)) - { return DoCDROMAccess(address & CDROM_MASK, value); - } else if (address < (GPU_BASE + GPU_SIZE)) - { return DoGPUAccess(address & GPU_MASK, value); - } else if (address < (MDEC_BASE + MDEC_SIZE)) - { return DoMDECAccess(address & MDEC_MASK, value); - } else if (address < SPU_BASE) - { return DoInvalidAccess(type, size, address, value); - } else if (address < (SPU_BASE + SPU_SIZE)) - { return DoAccessSPU(address & SPU_MASK, value); - } else if (address < EXP2_BASE) - { return DoInvalidAccess(type, size, address, value); - } else if (address < (EXP2_BASE + EXP2_SIZE)) - { return DoEXP2Access(address & EXP2_MASK, value); - } else if (address < EXP3_BASE) - { return DoUnknownEXPAccess(address, value); - } else if (address < (EXP3_BASE + EXP3_SIZE)) - { return DoEXP3Access(address & EXP3_MASK, value); - } - else - { - return DoInvalidAccess(type, size, address, value); - } + return DoInvalidAccess(type, size, address, value); } template @@ -1786,21 +1522,17 @@ bool SafeReadInstruction(VirtualMemoryAddress addr, u32* value) case 0x00: // KUSEG 0M-512M case 0x04: // KSEG0 - physical memory cached case 0x05: // KSEG1 - physical memory uncached - { // TODO: Check icache. return DoInstructionRead(addr, value); - } - case 0x01: // KUSEG 512M-1024M case 0x02: // KUSEG 1024M-1536M case 0x03: // KUSEG 1536M-2048M case 0x06: // KSEG2 case 0x07: // KSEG2 default: - { - return false; - } + break; } + return false; } bool ReadMemoryByte(VirtualMemoryAddress addr, u8* value) diff --git a/src/core/dma.cpp b/src/core/dma.cpp index 24b0121d..1782b383 100644 --- a/src/core/dma.cpp +++ b/src/core/dma.cpp @@ -1,7 +1,6 @@ #include "dma.h" #include "bus.h" #include "cdrom.h" -#include "common/log.h" #include "common/state_wrapper.h" #include "common/string_util.h" #include "cpu_code_cache.h" @@ -12,7 +11,6 @@ #include "pad.h" #include "spu.h" #include "system.h" -Log_SetChannel(DMA); static u32 GetAddressMask() { @@ -103,20 +101,11 @@ u32 DMA::ReadRegister(u32 offset) switch (offset & UINT32_C(0x0F)) { case 0x00: - { - Log_TracePrintf("DMA%u base address -> 0x%08X", channel_index, m_state[channel_index].base_address); return m_state[channel_index].base_address; - } case 0x04: - { - Log_TracePrintf("DMA%u block control -> 0x%08X", channel_index, m_state[channel_index].block_control.bits); return m_state[channel_index].block_control.bits; - } case 0x08: - { - Log_TracePrintf("DMA%u channel control -> 0x%08X", channel_index, m_state[channel_index].channel_control.bits); return m_state[channel_index].channel_control.bits; - } default: break; } @@ -124,18 +113,11 @@ u32 DMA::ReadRegister(u32 offset) else { if (offset == 0x70) - { - Log_TracePrintf("DPCR -> 0x%08X", m_DPCR.bits); return m_DPCR.bits; - } else if (offset == 0x74) - { - Log_TracePrintf("DPCR -> 0x%08X", m_DPCR.bits); return m_DICR.bits; - } } - Log_ErrorPrintf("Unhandled register read: %02X", offset); return UINT32_C(0xFFFFFFFF); } @@ -150,12 +132,10 @@ void DMA::WriteRegister(u32 offset, u32 value) case 0x00: { state.base_address = value & BASE_ADDRESS_MASK; - Log_TracePrintf("DMA channel %u base address <- 0x%08X", channel_index, state.base_address); return; } case 0x04: { - Log_TracePrintf("DMA channel %u block control <- 0x%08X", channel_index, value); state.block_control.bits = value; return; } @@ -170,7 +150,6 @@ void DMA::WriteRegister(u32 offset, u32 value) state.channel_control.bits = (state.channel_control.bits & ~ChannelState::ChannelControl::WRITE_MASK) | (value & ChannelState::ChannelControl::WRITE_MASK); - Log_TracePrintf("DMA channel %u channel control <- 0x%08X", channel_index, state.channel_control.bits); // start/trigger bit must be enabled for OTC if (static_cast(channel_index) == Channel::OTC) @@ -191,7 +170,6 @@ void DMA::WriteRegister(u32 offset, u32 value) { case 0x70: { - Log_TracePrintf("DPCR <- 0x%08X", value); m_DPCR.bits = value; for (u32 i = 0; i < NUM_CHANNELS; i++) @@ -208,7 +186,6 @@ void DMA::WriteRegister(u32 offset, u32 value) case 0x74: { - Log_TracePrintf("DCIR <- 0x%08X", value); m_DICR.bits = (m_DICR.bits & ~DICR_WRITE_MASK) | (value & DICR_WRITE_MASK); m_DICR.bits = m_DICR.bits & ~(value & DICR_RESET_MASK); m_DICR.UpdateMasterFlag(); @@ -219,8 +196,6 @@ void DMA::WriteRegister(u32 offset, u32 value) break; } } - - Log_ErrorPrintf("Unhandled register write: %02X <- %08X", offset, value); } void DMA::SetRequest(Channel channel, bool request) @@ -258,10 +233,7 @@ void DMA::UpdateIRQ() { m_DICR.UpdateMasterFlag(); if (m_DICR.master_flag) - { - Log_TracePrintf("Firing DMA master interrupt"); g_interrupt_controller.InterruptRequest(InterruptController::IRQ::DMA); - } } // Plenty of games seem to suffer from this issue where they have a linked list DMA going while polling the @@ -276,14 +248,6 @@ enum : u32 TickCount DMA::GetTransferSliceTicks() const { -#ifdef _DEBUG - if (g_pad.IsTransmitting()) - { - Log_DebugPrintf("DMA transfer while transmitting pad - using lower slice size of %u vs %u", - SLICE_SIZE_WHEN_TRANSMITTING_PAD, m_max_slice_ticks); - } -#endif - return g_pad.IsTransmitting() ? SLICE_SIZE_WHEN_TRANSMITTING_PAD : m_max_slice_ticks; } @@ -309,9 +273,6 @@ bool DMA::TransferChannel(Channel channel) case SyncMode::Manual: { const u32 word_count = cs.block_control.manual.GetWordCount(); - Log_DebugPrintf("DMA%u: Copying %u words %s 0x%08X", static_cast(channel), word_count, - copy_to_device ? "from" : "to", current_address & mask); - TickCount used_ticks; if (copy_to_device) used_ticks = TransferMemoryToDevice(channel, current_address & mask, increment, word_count); @@ -325,13 +286,7 @@ bool DMA::TransferChannel(Channel channel) case SyncMode::LinkedList: { if (!copy_to_device) - { - Panic("Linked list not implemented for DMA reads"); return true; - } - - Log_DebugPrintf("DMA%u: Copying linked list starting at 0x%08X to device", static_cast(channel), - current_address & mask); u8* ram_pointer = Bus::g_ram; TickCount remaining_ticks = GetTransferSliceTicks(); @@ -344,8 +299,6 @@ bool DMA::TransferChannel(Channel channel) const u32 word_count = header >> 24; const u32 next_address = header & UINT32_C(0x00FFFFFF); - Log_TracePrintf(" .. linked list entry at 0x%08X size=%u(%u words) next=0x%08X", current_address & mask, - word_count * UINT32_C(4), word_count, next_address); if (word_count > 0) { CPU::AddPendingTicks(5); @@ -373,21 +326,12 @@ bool DMA::TransferChannel(Channel channel) HaltTransfer(GetTransferHaltTicks()); return false; } - else - { - // linked list not yet complete - return true; - } + // linked list not yet complete } - break; + return true; case SyncMode::Request: { - Log_DebugPrintf("DMA%u: Copying %u blocks of size %u (%u total words) %s 0x%08X", static_cast(channel), - cs.block_control.request.GetBlockCount(), cs.block_control.request.GetBlockSize(), - cs.block_control.request.GetBlockCount() * cs.block_control.request.GetBlockSize(), - copy_to_device ? "from" : "to", current_address & mask); - const u32 block_size = cs.block_control.request.GetBlockSize(); u32 blocks_remaining = cs.block_control.request.GetBlockCount(); TickCount ticks_remaining = GetTransferSliceTicks(); @@ -440,7 +384,6 @@ bool DMA::TransferChannel(Channel channel) break; default: - Panic("Unimplemented sync mode"); break; } @@ -448,7 +391,6 @@ bool DMA::TransferChannel(Channel channel) cs.channel_control.enable_busy = false; if (m_DICR.IsIRQEnabled(channel)) { - Log_DebugPrintf("Set DMA interrupt for channel %u", static_cast(channel)); m_DICR.SetIRQFlag(channel); UpdateIRQ(); } @@ -459,7 +401,6 @@ bool DMA::TransferChannel(Channel channel) void DMA::HaltTransfer(TickCount duration) { m_halt_ticks_remaining += duration; - Log_DebugPrintf("Halting DMA for %d ticks", m_halt_ticks_remaining); if (m_unhalt_event->IsActive()) return; @@ -469,7 +410,6 @@ void DMA::HaltTransfer(TickCount duration) void DMA::UnhaltTransfer(TickCount ticks) { - Log_DebugPrintf("Resuming DMA after %d ticks, %d ticks late", ticks, -(m_halt_ticks_remaining - ticks)); m_halt_ticks_remaining -= ticks; m_unhalt_event->Deactivate(); @@ -539,7 +479,6 @@ TickCount DMA::TransferMemoryToDevice(Channel channel, u32 address, u32 incremen case Channel::MDECout: case Channel::PIO: default: - Log_ErrorPrintf("Unhandled DMA channel %u for device write", static_cast(channel)); break; } @@ -597,7 +536,6 @@ TickCount DMA::TransferDeviceToMemory(Channel channel, u32 address, u32 incremen break; default: - Log_ErrorPrintf("Unhandled DMA channel %u for device read", static_cast(channel)); std::fill_n(dest_pointer, word_count, UINT32_C(0xFFFFFFFF)); break; } diff --git a/src/core/gpu_backend.cpp b/src/core/gpu_backend.cpp index 50718e2c..55ebbb8e 100644 --- a/src/core/gpu_backend.cpp +++ b/src/core/gpu_backend.cpp @@ -1,10 +1,8 @@ #include "gpu_backend.h" #include "common/align.h" -#include "common/log.h" #include "common/state_wrapper.h" #include "common/timer.h" #include "settings.h" -Log_SetChannel(GPUBackend); std::unique_ptr g_gpu_backend; @@ -174,7 +172,6 @@ void GPUBackend::StartGPUThread() m_gpu_loop_done.store(false); m_use_gpu_thread = true; m_gpu_thread = std::thread(&GPUBackend::RunGPULoop, this); - Log_InfoPrint("GPU thread started."); } void GPUBackend::StopGPUThread() @@ -186,7 +183,6 @@ void GPUBackend::StopGPUThread() WakeGPUThread(); m_gpu_thread.join(); m_use_gpu_thread = false; - Log_InfoPrint("GPU thread stopped."); } void GPUBackend::Sync(bool allow_sleep) diff --git a/src/core/interrupt_controller.cpp b/src/core/interrupt_controller.cpp index 91747a4b..895d9b83 100644 --- a/src/core/interrupt_controller.cpp +++ b/src/core/interrupt_controller.cpp @@ -1,8 +1,6 @@ #include "interrupt_controller.h" -#include "common/log.h" #include "common/state_wrapper.h" #include "cpu_core.h" -Log_SetChannel(InterruptController); InterruptController g_interrupt_controller; @@ -49,9 +47,9 @@ u32 InterruptController::ReadRegister(u32 offset) return m_interrupt_mask_register; default: - Log_ErrorPrintf("Invalid read at offset 0x%08X", offset); - return UINT32_C(0xFFFFFFFF); + break; } + return UINT32_C(0xFFFFFFFF); } void InterruptController::WriteRegister(u32 offset, u32 value) @@ -59,25 +57,16 @@ void InterruptController::WriteRegister(u32 offset, u32 value) switch (offset) { case 0x00: // I_STATUS - { - if ((m_interrupt_status_register & ~value) != 0) - Log_DebugPrintf("Clearing bits 0x%08X", (m_interrupt_status_register & ~value)); - m_interrupt_status_register = m_interrupt_status_register & (value & REGISTER_WRITE_MASK); UpdateCPUInterruptRequest(); - } break; case 0x04: // I_MASK - { - Log_DebugPrintf("Interrupt mask <- 0x%08X", value); m_interrupt_mask_register = value & REGISTER_WRITE_MASK; UpdateCPUInterruptRequest(); - } break; default: - Log_ErrorPrintf("Invalid write at offset 0x%08X", offset); break; } } diff --git a/src/core/spu.cpp b/src/core/spu.cpp index 660db312..02457f22 100644 --- a/src/core/spu.cpp +++ b/src/core/spu.cpp @@ -984,8 +984,10 @@ SPU::ADSRPhase SPU::GetNextADSRPhase(ADSRPhase phase) default: case ADSRPhase::Release: // end of release disables the voice - return ADSRPhase::Off; + break; } + + return ADSRPhase::Off; } struct ADSRTableEntry @@ -1055,21 +1057,15 @@ s16 SPU::VolumeEnvelope::Tick(s16 current_level) if (exponential) { if (decreasing) - { this_step = (this_step * current_level) >> 15; - } else { if (current_level >= 0x6000) { if (rate < 40) - { this_step >>= 2; - } else if (rate >= 44) - { counter >>= 2; - } else { this_step >>= 1; @@ -1327,9 +1323,7 @@ ALWAYS_INLINE_RELEASE std::tuple SPU::SampleVoice(u32 voice_index) volume = ApplyVolume(sample, voice.regs.adsr_volume); } else - { volume = 0; - } voice.last_volume = volume; @@ -1439,8 +1433,6 @@ void SPU::ReverbWrite(u32 address, s16 data) static constexpr std::array s_reverb_resample_coefficients = { -1, 2, -10, 35, -103, 266, -616, 1332, -2960, 10246, 10246, -2960, 1332, -616, 266, -103, 35, -10, 2, -1, }; -static s16 s_last_reverb_input[2]; -static s32 s_last_reverb_output[2]; ALWAYS_INLINE static s32 Reverb4422(const s16* src) { @@ -1457,22 +1449,14 @@ ALWAYS_INLINE static s32 Reverb4422(const s16* src) template ALWAYS_INLINE static s32 Reverb2244(const s16* src) { - s32 out; // 32-bits is adequate(it won't overflow) + s32 out = 0; // 32-bits is adequate(it won't overflow) + // Middle non-zero if (phase) - { - // Middle non-zero - out = src[9]; - } - else - { - out = 0; - for (u32 i = 0; i < 20; i++) - out += s_reverb_resample_coefficients[i] * src[i]; - - out >>= 14; - out = std::clamp(out, -32768, 32767); - } - + return src[9]; + for (u32 i = 0; i < 20; i++) + out += s_reverb_resample_coefficients[i] * src[i]; + out >>= 14; + out = std::clamp(out, -32768, 32767); return out; } @@ -1485,7 +1469,6 @@ ALWAYS_INLINE static s16 ReverbNeg(s16 samp) { if (samp == -32768) return 0x7FFF; - return -samp; } @@ -1495,17 +1478,13 @@ ALWAYS_INLINE static s32 IIASM(const s16 IIR_ALPHA, const s16 insamp) { if (insamp == -32768) return 0; - else - return insamp * -65536; + return insamp * -65536; } - else - return insamp * (32768 - IIR_ALPHA); + return insamp * (32768 - IIR_ALPHA); } void SPU::ProcessReverb(s16 left_in, s16 right_in, s32* left_out, s32* right_out) { - s_last_reverb_input[0] = left_in; - s_last_reverb_input[1] = right_in; m_reverb_downsample_buffer[0][m_reverb_resample_buffer_position | 0x00] = left_in; m_reverb_downsample_buffer[0][m_reverb_resample_buffer_position | 0x40] = left_in; m_reverb_downsample_buffer[1][m_reverb_resample_buffer_position | 0x00] = right_in; @@ -1582,8 +1561,8 @@ void SPU::ProcessReverb(s16 left_in, s16 right_in, s32* left_out, s32* right_out m_reverb_resample_buffer_position = (m_reverb_resample_buffer_position + 1) & 0x3F; - s_last_reverb_output[0] = *left_out = ApplyVolume(out[0], m_reverb_registers.vLOUT); - s_last_reverb_output[1] = *right_out = ApplyVolume(out[1], m_reverb_registers.vROUT); + *left_out = ApplyVolume(out[0], m_reverb_registers.vLOUT); + *right_out = ApplyVolume(out[1], m_reverb_registers.vROUT); } void SPU::Execute(TickCount ticks) diff --git a/src/core/timers.cpp b/src/core/timers.cpp index a583c77b..e3a39af3 100644 --- a/src/core/timers.cpp +++ b/src/core/timers.cpp @@ -1,10 +1,8 @@ #include "timers.h" -#include "common/log.h" #include "common/state_wrapper.h" #include "gpu.h" #include "interrupt_controller.h" #include "system.h" -Log_SetChannel(Timers); Timers g_timers; @@ -193,10 +191,7 @@ u32 Timers::ReadRegister(u32 offset) const u32 timer_index = (offset >> 4) & u32(0x03); const u32 port_offset = offset & u32(0x0F); if (timer_index >= 3) - { - Log_ErrorPrintf("Timer read out of range: offset 0x%02X", offset); return UINT32_C(0xFFFFFFFF); - } CounterState& cs = m_states[timer_index]; @@ -237,9 +232,9 @@ u32 Timers::ReadRegister(u32 offset) return cs.target; default: - Log_ErrorPrintf("Read unknown register in timer %u (offset 0x%02X)", timer_index, offset); - return UINT32_C(0xFFFFFFFF); + break; } + return UINT32_C(0xFFFFFFFF); } void Timers::WriteRegister(u32 offset, u32 value) @@ -247,10 +242,7 @@ void Timers::WriteRegister(u32 offset, u32 value) const u32 timer_index = (offset >> 4) & u32(0x03); const u32 port_offset = offset & u32(0x0F); if (timer_index >= 3) - { - Log_ErrorPrintf("Timer write out of range: offset 0x%02X value 0x%08X", offset, value); return; - } CounterState& cs = m_states[timer_index]; @@ -269,7 +261,6 @@ void Timers::WriteRegister(u32 offset, u32 value) case 0x00: { const u32 old_counter = cs.counter; - Log_DebugPrintf("Timer %u write counter %u", timer_index, value); cs.counter = value & u32(0xFFFF); CheckForIRQ(timer_index, old_counter); if (timer_index == 2 || !cs.external_counting_enabled) @@ -281,7 +272,6 @@ void Timers::WriteRegister(u32 offset, u32 value) { static constexpr u32 WRITE_MASK = 0b1110001111111111; - Log_DebugPrintf("Timer %u write mode register 0x%04X", timer_index, value); cs.mode.bits = (value & WRITE_MASK) | (cs.mode.bits & ~WRITE_MASK); cs.use_external_clock = (cs.mode.clock_source & (timer_index == 2 ? 2 : 1)) != 0; cs.counter = 0; @@ -296,7 +286,6 @@ void Timers::WriteRegister(u32 offset, u32 value) case 0x08: { - Log_DebugPrintf("Timer %u write target 0x%04X", timer_index, ZeroExtend32(Truncate16(value))); cs.target = value & u32(0xFFFF); CheckForIRQ(timer_index, cs.counter); if (timer_index == 2 || !cs.external_counting_enabled) @@ -305,7 +294,6 @@ void Timers::WriteRegister(u32 offset, u32 value) break; default: - Log_ErrorPrintf("Write unknown register in timer %u (offset 0x%02X, value 0x%X)", timer_index, offset, value); break; } } @@ -344,7 +332,6 @@ void Timers::UpdateIRQ(u32 index) if (cs.mode.interrupt_request_n || (!cs.mode.irq_repeat && cs.irq_done)) return; - Log_DebugPrintf("Raising timer %u IRQ", index); cs.irq_done = true; g_interrupt_controller.InterruptRequest( static_cast(static_cast(InterruptController::IRQ::TMR0) + index)); diff --git a/src/core/timing_event.cpp b/src/core/timing_event.cpp index b83e8283..2af1d0f7 100644 --- a/src/core/timing_event.cpp +++ b/src/core/timing_event.cpp @@ -1,11 +1,9 @@ #include "timing_event.h" #include "common/assert.h" -#include "common/log.h" #include "common/state_wrapper.h" #include "cpu_core.h" #include "cpu_core_private.h" #include "system.h" -Log_SetChannel(TimingEvents); namespace TimingEvents { @@ -326,10 +324,7 @@ bool DoState(StateWrapper& sw) TimingEvent* event = FindActiveEvent(event_name.c_str()); if (!event) - { - Log_WarningPrintf("Save state has event '%s', but couldn't find this event when loading.", event_name.c_str()); continue; - } // Using reschedule is safe here since we call sort afterwards. event->m_downcount = downcount; @@ -344,7 +339,6 @@ bool DoState(StateWrapper& sw) sw.Do(&last_event_run_time); } - Log_DevPrintf("Loaded %u events from save state.", event_count); SortEvents(); } else @@ -360,8 +354,6 @@ bool DoState(StateWrapper& sw) sw.Do(&event->m_period); sw.Do(&event->m_interval); } - - Log_DevPrintf("Wrote %u events to save state.", s_active_event_count); } return !sw.HasError();