diff --git a/app/src/main/cpp/cosmic/common/types.h b/app/src/main/cpp/cosmic/common/types.h index aa5bcc7..b064e51 100644 --- a/app/src/main/cpp/cosmic/common/types.h +++ b/app/src/main/cpp/cosmic/common/types.h @@ -42,8 +42,8 @@ namespace cosmic { using FileStat = struct stat; DescriptorRaii() : hld(-1) {} - DescriptorRaii(i32 fd, bool isManaged = false) - : hld(fd), closeAtDestroy(!isManaged) { + DescriptorRaii(i32 fd, bool isManaged = false) : + hld(fd), closeAtDestroy(!isManaged) { if (fd != invFile) fstat(hld, &lastState); } diff --git a/app/src/main/cpp/cosmic/ee/cop_cache.cpp b/app/src/main/cpp/cosmic/ee/cop_cache.cpp index afb0a71..602abd9 100644 --- a/app/src/main/cpp/cosmic/ee/cop_cache.cpp +++ b/app/src/main/cpp/cosmic/ee/cop_cache.cpp @@ -136,16 +136,16 @@ namespace cosmic::ee { cacheIndex = (mem >> 6) & 0x3f; cacheBank = dataCache; } - Wrapper roCache{cacheBank[cacheIndex]}; - const auto firstWayLayer{roCache->tags[0]}; - const auto secondWayLayer{roCache->tags[1]}; + CopCacheLine& roCache{cacheBank[cacheIndex]}; + const auto firstWayLayer{roCache.tags[0]}; + const auto secondWayLayer{roCache.tags[1]}; - std::array, 2> maps{ - Wrapper(virtMap[firstWayLayer >> 12]), - Wrapper(virtMap[secondWayLayer >> 12]) + std::array maps{ + virtMap[firstWayLayer >> 12], + virtMap[secondWayLayer >> 12] }; - const auto firstLrf{roCache->lrf[0]}; - const auto secondLrf{roCache->lrf[1]}; + const auto firstLrf{roCache.lrf[0]}; + const auto secondLrf{roCache.lrf[1]}; for (u32 layers{}; layers < 2; layers++) { if (maps[0] == virtMap[mem >> 12] && layers == 0 ? firstLrf : secondLrf) @@ -156,15 +156,15 @@ namespace cosmic::ee { way == 0 ? firstWayLayer & dirtyBit : secondWayLayer & dirtyBit)}; if (write && mode == Data && isDirty) { - auto wrBack{(*maps[way]) + (mem & 0xfc0)}; - BitCast(wrBack)[0] = roCache->ways[way].large[0]; - BitCast(wrBack)[1] = roCache->ways[way].large[1]; - BitCast(wrBack)[2] = roCache->ways[way].large[2]; - BitCast(wrBack)[3] = roCache->ways[way].large[3]; - BitCast(wrBack)[4] = roCache->ways[way].large[4]; - BitCast(wrBack)[5] = roCache->ways[way].large[5]; - BitCast(wrBack)[6] = roCache->ways[way].large[6]; - BitCast(wrBack)[7] = roCache->ways[way].large[7]; + auto wrBack{maps[way] + (mem & 0xfc0)}; + BitCast(wrBack)[0] = roCache.ways[way].large[0]; + BitCast(wrBack)[1] = roCache.ways[way].large[1]; + BitCast(wrBack)[2] = roCache.ways[way].large[2]; + BitCast(wrBack)[3] = roCache.ways[way].large[3]; + BitCast(wrBack)[4] = roCache.ways[way].large[4]; + BitCast(wrBack)[5] = roCache.ways[way].large[5]; + BitCast(wrBack)[6] = roCache.ways[way].large[6]; + BitCast(wrBack)[7] = roCache.ways[way].large[7]; } if (write) { // If we are writing to the cache, the dirty bit must be set diff --git a/app/src/main/cpp/cosmic/ee/ee_intc.cpp b/app/src/main/cpp/cosmic/ee/ee_intc.cpp index 1f7e0c3..9ab58f3 100644 --- a/app/src/main/cpp/cosmic/ee/ee_intc.cpp +++ b/app/src/main/cpp/cosmic/ee/ee_intc.cpp @@ -3,18 +3,16 @@ namespace cosmic::ee { EeIntC::EeIntC(std::shared_ptr& mips, std::shared_ptr& sq) : - ee(mips), - sched(sq) { + ee(mips), sched(sq) { intcStat = {}; intcMask = {}; - check0Id = sched->createSchedTick(true, - [this](u64 unused0, bool unused1) { - int0Check(); - }); } void EeIntC::resetEeInterrupt() { intcStat = {}; intcMask = {}; + check0Id = sched->createSchedTick(true, [this](u64 unused0, bool unused1) { + int0Check(); + }); } void EeIntC::raiseIrq(u8 id) { @@ -25,6 +23,5 @@ namespace cosmic::ee { sched->placeTickedTask(check0Id, 0x8, {}, true); } void EeIntC::int0Check() { - } } \ No newline at end of file diff --git a/app/src/main/cpp/cosmic/gs/gif_bridge.cpp b/app/src/main/cpp/cosmic/gs/gif_bridge.cpp index c1e5a7b..6a53020 100644 --- a/app/src/main/cpp/cosmic/gs/gif_bridge.cpp +++ b/app/src/main/cpp/cosmic/gs/gif_bridge.cpp @@ -59,8 +59,7 @@ namespace cosmic::gs { } } void GifBridge::update(u32 cycles) { - if (!maskedPath3() && - !queueGetSize()) { + if (!maskedPath3() && !queueGetSize()) { requestDmac(Gif); } while (isPathActivated(Gif) && !maskedPath3() && diff --git a/app/src/main/cpp/cosmic/gs/gs_engine.cpp b/app/src/main/cpp/cosmic/gs/gs_engine.cpp index 5bfb268..49dcc29 100644 --- a/app/src/main/cpp/cosmic/gs/gs_engine.cpp +++ b/app/src/main/cpp/cosmic/gs/gs_engine.cpp @@ -67,7 +67,7 @@ namespace cosmic::gs { break; default: // For some reason, the title Ridge Racer V uses the value 11 as a alias for the value 1 - ranges::for_each(gswAddrAlias, [&](auto& path) { + ranges::for_each(gswAddrAlias, [&](const auto& path) { if (path.gameCase == addr) { gsWrite(path.rCase, data); } diff --git a/app/src/main/cpp/cosmic/gs/gs_engine.h b/app/src/main/cpp/cosmic/gs/gs_engine.h index 8b7d5b0..0f0c504 100644 --- a/app/src/main/cpp/cosmic/gs/gs_engine.h +++ b/app/src/main/cpp/cosmic/gs/gs_engine.h @@ -9,9 +9,8 @@ namespace cosmic::gs { struct GsPayloadDataPacket { GsPayloadDataPacket() = default; - GsPayloadDataPacket(u64 bufferSize) - : downloadBuffer(bufferSize) - {} + GsPayloadDataPacket(u64 bufferSize) : + downloadBuffer(bufferSize) {} u32 qw128Count; os::MappedMemory downloadBuffer; u32 indexAddr; diff --git a/app/src/main/cpp/cosmic/iop/iop_cop.cpp b/app/src/main/cpp/cosmic/iop/iop_cop.cpp index f8d71aa..a757fc2 100644 --- a/app/src/main/cpp/cosmic/iop/iop_cop.cpp +++ b/app/src/main/cpp/cosmic/iop/iop_cop.cpp @@ -15,12 +15,12 @@ namespace cosmic::iop { switch (copId) { case 12: { std::bitset<8 * 4> bin{}; - bin[0x00] = status.iec; - bin[0x01] = status.kuc; - bin[0x02] = status.iep; - bin[0x04] = status.kup; - bin[0x03] = status.ieo; - bin[0x05] = status.kuo; + bin[0] = status.iec; + bin[1] = status.kuc; + bin[2] = status.iep; + bin[3] = status.kup; + bin[4] = status.ieo; + bin[5] = status.kuo; bin[0x10] = status.isC; bin[0x16] = status.bev; diff --git a/app/src/main/cpp/cosmic/iop/iop_core.cpp b/app/src/main/cpp/cosmic/iop/iop_core.cpp index d029145..65dc218 100644 --- a/app/src/main/cpp/cosmic/iop/iop_core.cpp +++ b/app/src/main/cpp/cosmic/iop/iop_core.cpp @@ -33,7 +33,7 @@ namespace cosmic::iop { void IoMipsCore::takeBranchIf(bool take, i32 pcAddr) { if (!take && !onBranch) return; - i64 calcPc{static_cast(ioPc) + pcAddr}; + auto calcPc{static_cast(ioPc) + pcAddr}; waitPc = static_cast(calcPc); if (waitPc & 0x3) { throw AppErr("Next IOP PC {:#x}: lowest 3 bits couldn't be set", waitPc); diff --git a/app/src/main/cpp/cosmic/iop/iop_dma.cpp b/app/src/main/cpp/cosmic/iop/iop_dma.cpp index 67489ef..8e28cd9 100644 --- a/app/src/main/cpp/cosmic/iop/iop_dma.cpp +++ b/app/src/main/cpp/cosmic/iop/iop_dma.cpp @@ -23,29 +23,29 @@ namespace cosmic::iop { void IopDma::pulseSpu2Chain() { // When true, it means that we will write into the SPU2 device bool write2Spu; - auto spu2ch{Wrapper(channels[IopSpu2])}; + auto& spu2ch{channels[IopSpu2]}; std::array packet{}; - write2Spu = spu2ch->status.isFrom2Device; + write2Spu = spu2ch.status.isFrom2Device; - if (spu2ch->cyclesDelay) { - spu2ch->cyclesDelay--; + if (spu2ch.cyclesDelay) { + spu2ch.cyclesDelay--; return; } - if (spu2ch->cyclesDelay <= 0) { + if (spu2ch.cyclesDelay <= 0) { if (write2Spu) { - packet[0] = ioDmaRead(spu2ch->addr); + packet[0] = ioDmaRead(spu2ch.addr); spu2->writeDmaData(packet[0]); } else { packet[1] = spu2->requestDmaData(); - ioDmaWrite(spu2ch->addr, packet[1]); + ioDmaWrite(spu2ch.addr, packet[1]); } - spu2ch->size--; - spu2ch->addr += sizeof(u32); - spu2ch->cyclesDelay = 3; + spu2ch.size--; + spu2ch.addr += sizeof(u32); + spu2ch.cyclesDelay = 3; } - if (!spu2ch->size) { - spu2ch->wordCount = 0; + if (!spu2ch.size) { + spu2ch.wordCount = 0; } } } diff --git a/app/src/main/cpp/cosmic/iop/iop_intc.cpp b/app/src/main/cpp/cosmic/iop/iop_intc.cpp index 57bf4a5..2d7315e 100644 --- a/app/src/main/cpp/cosmic/iop/iop_intc.cpp +++ b/app/src/main/cpp/cosmic/iop/iop_intc.cpp @@ -59,7 +59,7 @@ namespace cosmic::iop { } u32 IopIntC::readICtrl() { // Global interrupt disable - const u32 ic{ctrl}; + const auto ic{ctrl}; ctrl ^= ctrl; iopCheck(); return ic; diff --git a/app/src/main/cpp/cosmic/iop/iop_intc.h b/app/src/main/cpp/cosmic/iop/iop_intc.h index db1a036..8aa6e0f 100644 --- a/app/src/main/cpp/cosmic/iop/iop_intc.h +++ b/app/src/main/cpp/cosmic/iop/iop_intc.h @@ -8,8 +8,8 @@ namespace cosmic::iop { class IoMipsCore; class IopIntC { public: - IopIntC(std::shared_ptr& mips) - : iop(mips) {} + IopIntC(std::shared_ptr& mips) : + iop(mips) {} void iopCheck(); void resetInterrupt(); diff --git a/app/src/main/cpp/cosmic/mio/dma_ctrl.cpp b/app/src/main/cpp/cosmic/mio/dma_ctrl.cpp index 6969041..4c5598c 100644 --- a/app/src/main/cpp/cosmic/mio/dma_ctrl.cpp +++ b/app/src/main/cpp/cosmic/mio/dma_ctrl.cpp @@ -72,15 +72,15 @@ namespace cosmic::mio { u32 countOfQw{}; for (; hasOwner && highCycles > 0; ) { - auto owner{Wrapper(channels.at(hasOwner.getId()))}; + auto& owner{channels.at(hasOwner.getId())}; // "Owner" is the privileged channel that will use the available clock pulses at the moment - switch (owner->index) { + switch (owner.index) { case Vif0: - countOfQw = feedVif0Pipe(*owner).first; break; + countOfQw = feedVif0Pipe(owner).first; break; } highCycles -= std::max(countOfQw, static_cast(1)); - if (owner->isScratch) + if (owner.isScratch) highCycles -= 0xc; if (!hasOwner) @@ -99,14 +99,12 @@ namespace cosmic::mio { } if ((address >> 16 & 0x1000) != 0x1000) { throw MioErr("(DMA): Reading from an invalid address, unreachable address {}", address); - } - if (cid == invCid) { + } else if (cid == invCid) { throw MioErr("No channel selected, very serious error..."); } // For specific channels like: SifX, IpuX, SprX if ((address >> 4 & 0x400) == 0x400) cid++; - which = address & 0xff; if ((address >> 12 & 0xe000) != 0xe000) { if (which == 0x10) diff --git a/app/src/main/cpp/cosmic/mio/mem_pipe.cpp b/app/src/main/cpp/cosmic/mio/mem_pipe.cpp index bf04f30..0aab78f 100644 --- a/app/src/main/cpp/cosmic/mio/mem_pipe.cpp +++ b/app/src/main/cpp/cosmic/mio/mem_pipe.cpp @@ -9,7 +9,7 @@ namespace cosmic::mio { VirtualPointer virtAddress{}; if (address >= 0x1fc00000 && address < 0x20000000 && isMips) { - virtAddress = directPointer(address, dev); + virtAddress = directPointer(address, dev); } if (dev == IopDev) { if (address < 0x00200000) diff --git a/app/src/main/cpp/cosmic/os/system_state.h b/app/src/main/cpp/cosmic/os/system_state.h index bdd89c6..446a7b5 100644 --- a/app/src/main/cpp/cosmic/os/system_state.h +++ b/app/src/main/cpp/cosmic/os/system_state.h @@ -70,9 +70,7 @@ namespace cosmic::os { biosPath; OsVariable turboMode, dumpImage; - - OsVariable schedAffinity, - eeMode; + OsVariable schedAffinity, eeMode; private: [[maybe_unused]] JavaVM* androidRuntime{}; }; diff --git a/app/src/main/cpp/cosmic/vm/emu_vm.cpp b/app/src/main/cpp/cosmic/vm/emu_vm.cpp index d7d6756..afc3324 100644 --- a/app/src/main/cpp/cosmic/vm/emu_vm.cpp +++ b/app/src/main/cpp/cosmic/vm/emu_vm.cpp @@ -51,10 +51,6 @@ namespace cosmic::vm { mips->cop2 = std::make_unique(vus); mips->timer = std::make_unique(scheduler, intc); - states->dumpImage.addListener([&]{ - dumpMemoryAtClash = *states->dumpImage; - }); - user->success("VM loaded successfully"); } @@ -104,12 +100,16 @@ namespace cosmic::vm { vu01->vpu0Cop2.resetVu(); vu01->vpu1Dlo.resetVu(); + states->dumpImage.addListener([&]{ + dumpMemoryAtClash = *states->dumpImage; + }); + iop->resetIop(); ioDma->resetIoDma(); sound->resetSound(); #if !defined(NDEBUG) - // Memory is assumed to be random content by a early moment before tbe 1ft boot stage, + // Memory is assumed to be random content by an early moment before tbe 1ft boot stage, // but for debugging purposes, we will cleanup everything from now (at least the EE memory) iop->iopMem->controller->mapped->iopSoftClean(); iop->iopMem->controller->mapped->sndSoftClean();