From 2795a81120a2f7685054b6635d9f6357c69f97a9 Mon Sep 17 00:00:00 2001 From: Gabriel Correia Date: Sat, 22 Jun 2024 21:28:45 -0300 Subject: [PATCH] `Core`: Renamed the class that stores object references --- app/src/main/cpp/cosmic/common/types.h | 6 +++--- app/src/main/cpp/cosmic/console/backdoor.cpp | 10 +++++----- app/src/main/cpp/cosmic/console/backdoor.h | 6 +++--- app/src/main/cpp/cosmic/console/bios_loader.cpp | 2 +- app/src/main/cpp/cosmic/console/bios_loader.h | 2 +- app/src/main/cpp/cosmic/console/virt_devices.cpp | 4 ++-- .../main/cpp/cosmic/creeper/cached_blocks.cpp | 16 ++++++++-------- app/src/main/cpp/cosmic/creeper/cached_blocks.h | 10 +++++----- .../cpp/cosmic/creeper/dispatch_functions.cpp | 8 ++++---- app/src/main/cpp/cosmic/creeper/mips_cop.cpp | 2 +- .../main/cpp/cosmic/creeper/psx_interpreter.cpp | 4 ++-- .../main/cpp/cosmic/creeper/psx_interpreter.h | 4 ++-- app/src/main/cpp/cosmic/creeper/vector_codes.cpp | 2 +- app/src/main/cpp/cosmic/creeper/vector_codes.h | 4 ++-- app/src/main/cpp/cosmic/ee/cop_cache.cpp | 14 +++++++------- app/src/main/cpp/cosmic/ee/ee_core.cpp | 8 ++++---- app/src/main/cpp/cosmic/ee/ee_info.h | 4 ++-- .../main/cpp/cosmic/fishron/jitter_arm64_ee.h | 2 +- .../cpp/cosmic/gpu/vulcano/vram_allocator.cpp | 2 +- .../main/cpp/cosmic/gpu/vulcano/vram_allocator.h | 4 ++-- app/src/main/cpp/cosmic/hle/syscall_gate.h | 2 +- app/src/main/cpp/cosmic/iop/iop_core.cpp | 2 +- app/src/main/cpp/cosmic/iop/iop_dma.cpp | 2 +- app/src/main/cpp/cosmic/iop/iop_info.h | 4 ++-- app/src/main/cpp/cosmic/mio/dma_ctrl.cpp | 8 ++++---- app/src/main/cpp/cosmic/mio/dma_ctrl.h | 4 ++-- app/src/main/cpp/cosmic/vm/emu_thread.h | 12 ++++++------ app/src/main/cpp/cosmic/vm/emu_vm.cpp | 2 +- app/src/main/cpp/cosmic/vm/step_frameloop.cpp | 8 ++++---- app/src/main/cpp/cosmic/vu/v01_cop2vu.cpp | 2 +- app/src/main/cpp/cosmic/vu/v01_cop2vu.h | 6 +++--- app/src/main/cpp/cosmic/vu/vecu.cpp | 6 +++--- app/src/main/cpp/cosmic/vu/vecu.h | 10 +++++----- app/src/main/cpp/cosmic/vu/vif10_upload.cpp | 2 +- app/src/main/cpp/cosmic/vu/vif10_upload.h | 4 ++-- app/src/main/cpp/cosmic/vu/vu_info.h | 4 ++-- 36 files changed, 96 insertions(+), 96 deletions(-) diff --git a/app/src/main/cpp/cosmic/common/types.h b/app/src/main/cpp/cosmic/common/types.h index 057d895..aa5bcc7 100644 --- a/app/src/main/cpp/cosmic/common/types.h +++ b/app/src/main/cpp/cosmic/common/types.h @@ -10,10 +10,10 @@ #include namespace cosmic { template - class Optional : public std::optional> { + class Wrapper : public std::optional> { public: - Optional() = default; - Optional(T& reference) : std::optional>(reference) { + Wrapper() = default; + Wrapper(T& reference) : std::optional>(reference) { } auto take() const { return this->value().get(); diff --git a/app/src/main/cpp/cosmic/console/backdoor.cpp b/app/src/main/cpp/cosmic/console/backdoor.cpp index a05adfd..c0439a3 100644 --- a/app/src/main/cpp/cosmic/console/backdoor.cpp +++ b/app/src/main/cpp/cosmic/console/backdoor.cpp @@ -5,11 +5,11 @@ namespace cosmic { } namespace cosmic::console { BackDoor::BackDoor(vm::EmuVm& aliveVm) { - vm = Optional(aliveVm); + vm = Wrapper(aliveVm); echo.lock(); vmRefs = 1; } - Optional BackDoor::openVm() { + Wrapper BackDoor::openVm() { std::thread::id nub{}; if (owner == nub && owner != std::this_thread::get_id()) { while (echo.try_lock()) { @@ -22,14 +22,14 @@ namespace cosmic::console { } if (owner != std::this_thread::get_id()) throw AppErr("This resource should have the lock held until the object is released"); - Optional vmRef{}; + Wrapper vmRef{}; if (vmRefs) { vmRef = vm; vmRefs++; } return vmRef; } - void BackDoor::leaveVm(Optional& lvm) { + void BackDoor::leaveVm(Wrapper& lvm) { if (echo.try_lock()) { if (owner != std::this_thread::get_id()) throw AppErr("The program flow is broken, review the usage of BackDoor in the code"); @@ -37,7 +37,7 @@ namespace cosmic::console { vmRefs--; if (!vm || vmRefs <= 0) { vm.reset(); - vm = Optional(lvm); + vm = Wrapper(lvm); vmRefs = 1; } owner = {}; diff --git a/app/src/main/cpp/cosmic/console/backdoor.h b/app/src/main/cpp/cosmic/console/backdoor.h index dd2c450..03322aa 100644 --- a/app/src/main/cpp/cosmic/console/backdoor.h +++ b/app/src/main/cpp/cosmic/console/backdoor.h @@ -10,12 +10,12 @@ namespace cosmic::console { class BackDoor { public: BackDoor(vm::EmuVm& aliveVm); - Optional openVm(); - void leaveVm(Optional& lvm); + Wrapper openVm(); + void leaveVm(Wrapper& lvm); private: std::thread::id owner; std::mutex echo; - Optional vm; + Wrapper vm; i32 vmRefs; }; } diff --git a/app/src/main/cpp/cosmic/console/bios_loader.cpp b/app/src/main/cpp/cosmic/console/bios_loader.cpp index 9a8932e..ab256f4 100644 --- a/app/src/main/cpp/cosmic/console/bios_loader.cpp +++ b/app/src/main/cpp/cosmic/console/bios_loader.cpp @@ -46,7 +46,7 @@ namespace cosmic::console { biosf.readFrom(here, 0); romHeader.release(); } - Optional BiosLoader::getModule(const std::string model) { + Wrapper BiosLoader::getModule(const std::string model) { std::span modelBin{BitCast(model.c_str()), model.size()}; std::span hdrBin{romHeader->operator*(), hdrSize}; auto indexInt{ranges::search(hdrBin, modelBin)}; diff --git a/app/src/main/cpp/cosmic/console/bios_loader.h b/app/src/main/cpp/cosmic/console/bios_loader.h index 5496e10..95ca055 100644 --- a/app/src/main/cpp/cosmic/console/bios_loader.h +++ b/app/src/main/cpp/cosmic/console/bios_loader.h @@ -26,7 +26,7 @@ namespace cosmic::console { private: bool isABios(); - Optional getModule(const std::string model); + Wrapper getModule(const std::string model); bool loadVersionInfo(std::span info); void fillVersion(hle::BiosInfo& bios, std::span info); diff --git a/app/src/main/cpp/cosmic/console/virt_devices.cpp b/app/src/main/cpp/cosmic/console/virt_devices.cpp index 2dc25e4..4b1b580 100644 --- a/app/src/main/cpp/cosmic/console/virt_devices.cpp +++ b/app/src/main/cpp/cosmic/console/virt_devices.cpp @@ -30,8 +30,8 @@ namespace cosmic::console { gif = std::make_shared(gs); mio::HardWithDmaCap caps{}; - caps.vif0 = Optional(VUs->vifs[0]); - caps.vif1 = Optional(VUs->vifs[1]); + caps.vif0 = Wrapper(VUs->vifs[0]); + caps.vif1 = Wrapper(VUs->vifs[1]); caps.ee = eeR5900; pipe->controller->connectDevices(caps); diff --git a/app/src/main/cpp/cosmic/creeper/cached_blocks.cpp b/app/src/main/cpp/cosmic/creeper/cached_blocks.cpp index 4e4f495..3231f5f 100644 --- a/app/src/main/cpp/cosmic/creeper/cached_blocks.cpp +++ b/app/src/main/cpp/cosmic/creeper/cached_blocks.cpp @@ -32,7 +32,7 @@ namespace cosmic::creeper { auto endIterator{std::end(run)}; for (; opIterator != run.end(); executedInst++) { - Optional opcInside{*opIterator}; + Wrapper opcInside{*opIterator}; bool isLastABr{false}; // Todo: May not work as expected if (opIterator != run.begin()) { @@ -57,7 +57,7 @@ namespace cosmic::creeper { if ((opIterator + 1) != endIterator) { // Simulating the pipeline execution with the aim of resolving one or more instructions // within the same cycle - Optional opcSuper{*(opIterator + 1)}; + Wrapper opcSuper{*(opIterator + 1)}; // Execute only two instructions if the operations use different pipelines if (((opcInside->infoCallable.pipe ^ opcSuper->infoCallable.pipe) != invPipe) && opcSuper->infoCallable.pipe != dangerousPipe) { @@ -102,7 +102,7 @@ namespace cosmic::creeper { block = localPc32; } } - MipsIvInterpreter::MipsIvInterpreter(Optional mips) : + MipsIvInterpreter::MipsIvInterpreter(Wrapper mips) : ee::EeExecutor(mips) { lastCleaned = actualPc = 0; memset(metrics.data(), 0, sizeof(metrics)); @@ -115,8 +115,8 @@ namespace cosmic::creeper { auto vmRef{outside->openVm()}; vm = vmRef; - fpu = Optional(cpu->cop1); - c0 = Optional(cpu->cop0); + fpu = Wrapper(cpu->cop1); + c0 = Wrapper(cpu->cop0); outside->leaveVm(vmRef); } @@ -127,16 +127,16 @@ namespace cosmic::creeper { PCs[0] = cpu->eePc; actualPc = PCs[0]; PCs[1] = PCs[0] & cleanPcBlock; - Optional chosen{}; + Wrapper chosen{}; ranges::for_each(metrics, [&](auto& met){ if (met.blockPc == PCs[1]) - chosen = Optional(met); + chosen = Wrapper(met); }); bool isCached{true}; if (!chosen) { // Choosing the metric with the lowest frequency number std::sort(metrics.begin(), metrics.end()); - chosen = Optional(metrics[0]); + chosen = Wrapper(metrics[0]); isCached = false; } [[unlikely]] if (!isCached) { diff --git a/app/src/main/cpp/cosmic/creeper/cached_blocks.h b/app/src/main/cpp/cosmic/creeper/cached_blocks.h index df312c6..2c303c7 100644 --- a/app/src/main/cpp/cosmic/creeper/cached_blocks.h +++ b/app/src/main/cpp/cosmic/creeper/cached_blocks.h @@ -78,7 +78,7 @@ namespace cosmic::creeper { class MipsIvInterpreter : public ee::EeExecutor { public: - MipsIvInterpreter(Optional mips); + MipsIvInterpreter(Wrapper mips); u32 executeCode() override; void performInvalidation(u32 address) override; @@ -184,10 +184,10 @@ namespace cosmic::creeper { u32 lastCleaned; u32 actualPc; - static Optional cpu; - static Optional vm; - static Optional fpu; - static Optional c0; + static Wrapper cpu; + static Wrapper vm; + static Wrapper fpu; + static Wrapper c0; static EeMapSpecial ivSpecial; static EeRegImm ivRegImm; diff --git a/app/src/main/cpp/cosmic/creeper/dispatch_functions.cpp b/app/src/main/cpp/cosmic/creeper/dispatch_functions.cpp index 37a011b..a016a6c 100644 --- a/app/src/main/cpp/cosmic/creeper/dispatch_functions.cpp +++ b/app/src/main/cpp/cosmic/creeper/dispatch_functions.cpp @@ -208,10 +208,10 @@ namespace cosmic::creeper { const u32 opcode{cpu->fetchByAddress(pc)}; return opcode; } - Optional MipsIvInterpreter::cpu; - Optional MipsIvInterpreter::vm; - Optional MipsIvInterpreter::fpu; - Optional MipsIvInterpreter::c0; + Wrapper MipsIvInterpreter::cpu; + Wrapper MipsIvInterpreter::vm; + Wrapper MipsIvInterpreter::fpu; + Wrapper MipsIvInterpreter::c0; u32& MipsIvInterpreter::doReg(const Reg regId) { return cpu->GPRs[regId].words[0]; diff --git a/app/src/main/cpp/cosmic/creeper/mips_cop.cpp b/app/src/main/cpp/cosmic/creeper/mips_cop.cpp index 9f821e3..7987f31 100644 --- a/app/src/main/cpp/cosmic/creeper/mips_cop.cpp +++ b/app/src/main/cpp/cosmic/creeper/mips_cop.cpp @@ -7,7 +7,7 @@ namespace cosmic::creeper { void MipsIvInterpreter::tlbr(Operands ops) { - auto entry{cpu->fetchTlbFromCop(c0->GPRs.data())}; + auto& entry{cpu->fetchTlbFromCop(c0->GPRs.data())}; c0->loadFromGprToTlb(entry); } void MipsIvInterpreter::c0mfc(Operands ops) { diff --git a/app/src/main/cpp/cosmic/creeper/psx_interpreter.cpp b/app/src/main/cpp/cosmic/creeper/psx_interpreter.cpp index 3e63de5..6cbfaad 100644 --- a/app/src/main/cpp/cosmic/creeper/psx_interpreter.cpp +++ b/app/src/main/cpp/cosmic/creeper/psx_interpreter.cpp @@ -219,9 +219,9 @@ namespace cosmic::creeper { } } IopInterpreter::IopInterpreter( - Optional core) : + Wrapper core) : IopExecVe(core) { - Optional vmInter{outside->openVm()}; + Wrapper vmInter{outside->openVm()}; vm = vmInter; outside->leaveVm(vm); diff --git a/app/src/main/cpp/cosmic/creeper/psx_interpreter.h b/app/src/main/cpp/cosmic/creeper/psx_interpreter.h index 49af579..7610562 100644 --- a/app/src/main/cpp/cosmic/creeper/psx_interpreter.h +++ b/app/src/main/cpp/cosmic/creeper/psx_interpreter.h @@ -9,7 +9,7 @@ namespace cosmic::vm { namespace cosmic::creeper { class IopInterpreter : public iop::IopExecVe { public: - IopInterpreter(Optional core); + IopInterpreter(Wrapper core); u32 executeCode() override; u32 execPsx(u32 opcode, std::array opeRegs); u32 execCop(u32 opcode, std::array opeRegs); @@ -19,7 +19,7 @@ namespace cosmic::creeper { CachedFastPc fastPc; u32 fetchPcInst() override; - Optional vm; + Wrapper vm; void issueInterruptSignal(); void sltiu(Operands ops); diff --git a/app/src/main/cpp/cosmic/creeper/vector_codes.cpp b/app/src/main/cpp/cosmic/creeper/vector_codes.cpp index 8becace..56bf8a2 100644 --- a/app/src/main/cpp/cosmic/creeper/vector_codes.cpp +++ b/app/src/main/cpp/cosmic/creeper/vector_codes.cpp @@ -1,7 +1,7 @@ #include #include namespace cosmic::creeper { - Optional VuMicroInterpreter::vu; + Wrapper VuMicroInterpreter::vu; u32 VuMicroInterpreter::executeCode() { VuMicroOperands ops[2]; diff --git a/app/src/main/cpp/cosmic/creeper/vector_codes.h b/app/src/main/cpp/cosmic/creeper/vector_codes.h index 7e1df67..f7d35f2 100644 --- a/app/src/main/cpp/cosmic/creeper/vector_codes.h +++ b/app/src/main/cpp/cosmic/creeper/vector_codes.h @@ -26,7 +26,7 @@ namespace cosmic::creeper { class VuMicroInterpreter : public vu::VuMicroExecutor { public: - VuMicroInterpreter(Optional vuCake) : + VuMicroInterpreter(Wrapper vuCake) : vu::VuMicroExecutor(vuCake) { vu = vuMicro; } @@ -57,6 +57,6 @@ namespace cosmic::creeper { private: VuMicroOrder ordered; - static Optional vu; + static Wrapper vu; }; } diff --git a/app/src/main/cpp/cosmic/ee/cop_cache.cpp b/app/src/main/cpp/cosmic/ee/cop_cache.cpp index 991f150..5e85f3a 100644 --- a/app/src/main/cpp/cosmic/ee/cop_cache.cpp +++ b/app/src/main/cpp/cosmic/ee/cop_cache.cpp @@ -6,7 +6,7 @@ namespace cosmic::ee { // We don't check for a cache miss here const os::vec& CtrlCop::readCache(u32 address, CacheMode mode) { auto tagAddr{getCachePfn(address, mode)}; - auto cachedData{getCache(address, false, mode)}; + auto& cachedData{getCache(address, false, mode)}; u8 lineLayer{}; tagAddr |= dirtyBit; if (cachedData.tags[0] == tagAddr) @@ -21,7 +21,7 @@ namespace cosmic::ee { return cont.vec[(address >> 4) & 3]; } void CtrlCop::invIndexed(u32 address) { - auto invWaysAt{getCache(address, true)}; + auto& invWaysAt{getCache(address, true)}; invWaysAt.tags[0] &= ~dirtyBit; invWaysAt.tags[1] &= ~dirtyBit; invWaysAt.lrf[0] = invWaysAt.lrf[1] = { @@ -32,7 +32,7 @@ namespace cosmic::ee { bool CtrlCop::isCacheHit(u32 address, u8 lane, CacheMode mode) { // Each cache line is indexed by virtual address auto addrTag{getCachePfn(address, mode)}; - auto mirror{getCache(address, false, mode)}; + auto& mirror{getCache(address, false, mode)}; addrTag |= dirtyBit; switch (lane) { @@ -136,13 +136,13 @@ namespace cosmic::ee { cacheIndex = (mem >> 6) & 0x3f; cacheBank = dataCache; } - Optional roCache{cacheBank[cacheIndex]}; + Wrapper roCache{cacheBank[cacheIndex]}; const auto firstWayLayer{roCache->tags[0]}; const auto secondWayLayer{roCache->tags[1]}; - std::array, 2> maps{ - Optional(virtMap[firstWayLayer >> 12]), - Optional(virtMap[secondWayLayer >> 12]) + std::array, 2> maps{ + Wrapper(virtMap[firstWayLayer >> 12]), + Wrapper(virtMap[secondWayLayer >> 12]) }; const auto firstLrf{roCache->lrf[0]}; const auto secondLrf{roCache->lrf[1]}; diff --git a/app/src/main/cpp/cosmic/ee/ee_core.cpp b/app/src/main/cpp/cosmic/ee/ee_core.cpp index 2f0bedb..e05dcea 100644 --- a/app/src/main/cpp/cosmic/ee/ee_core.cpp +++ b/app/src/main/cpp/cosmic/ee/ee_core.cpp @@ -72,7 +72,7 @@ namespace cosmic::ee { !cop0.isCacheHit(eePc, 1)) { cop0.loadCacheLine(eePc, *this); } - auto pcCached{cop0.readCache(eePc)}; + auto& pcCached{cop0.readCache(eePc)}; const u32 part{(incPc() & 0xf) / 4}; return pcCached.to32(part); } @@ -105,7 +105,7 @@ namespace cosmic::ee { cached.isValid = false; if (!cached.isValid) { - const auto fasterInstructions{cop0.readCache(address)}; + const auto& fasterInstructions{cop0.readCache(address)}; cached[0] = fasterInstructions.to32(0); cached[4] = fasterInstructions.to32(1); cached[8] = fasterInstructions.to32(2); @@ -127,9 +127,9 @@ namespace cosmic::ee { if (executor) executor.reset(); if (cpuMode == CachedInterpreter) { - executor = std::make_unique(Optional(*this)); + executor = std::make_unique(Wrapper(*this)); } else if (cpuMode == JitRe) { - executor = std::make_unique(Optional(*this)); + executor = std::make_unique(Wrapper(*this)); } }); } diff --git a/app/src/main/cpp/cosmic/ee/ee_info.h b/app/src/main/cpp/cosmic/ee/ee_info.h index 820fcfc..8699fbd 100644 --- a/app/src/main/cpp/cosmic/ee/ee_info.h +++ b/app/src/main/cpp/cosmic/ee/ee_info.h @@ -5,14 +5,14 @@ namespace cosmic::ee { class EeMipsCore; class EeExecutor { public: - EeExecutor(Optional& mips) : + EeExecutor(Wrapper& mips) : eeCpu(mips) {} virtual u32 executeCode() = 0; virtual u32 fetchPcInst(u32 pc) = 0; virtual void performInvalidation(u32 address) = 0; virtual ~EeExecutor() = default; protected: - Optional eeCpu; + Wrapper eeCpu; }; enum MipsRegsHw : u8 { diff --git a/app/src/main/cpp/cosmic/fishron/jitter_arm64_ee.h b/app/src/main/cpp/cosmic/fishron/jitter_arm64_ee.h index e13d160..f82f0bf 100644 --- a/app/src/main/cpp/cosmic/fishron/jitter_arm64_ee.h +++ b/app/src/main/cpp/cosmic/fishron/jitter_arm64_ee.h @@ -5,7 +5,7 @@ namespace cosmic::fishron { class EeArm64Jitter : public ee::EeExecutor { public: - EeArm64Jitter(Optional intCpu) : + EeArm64Jitter(Wrapper intCpu) : EeExecutor(intCpu) {} u32 executeCode() override; u32 fetchPcInst(u32 address) override; diff --git a/app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.cpp b/app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.cpp index 55990b8..5df5eb4 100644 --- a/app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.cpp +++ b/app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.cpp @@ -1,7 +1,7 @@ #include namespace cosmic::gpu::vulcano { - VramManager::VramManager(Optional& gpu) : graphics(gpu) { + VramManager::VramManager(Wrapper& gpu) : graphics(gpu) { VmaAllocatorCreateInfo allocatorInfo{}; vmaCreateAllocator(&allocatorInfo, &vma); } diff --git a/app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.h b/app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.h index 0119647..7504094 100644 --- a/app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.h +++ b/app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.h @@ -6,10 +6,10 @@ namespace cosmic::gpu::vulcano { class GraphicsLayer; class VramManager { public: - VramManager(Optional& gpu); + VramManager(Wrapper& gpu); ~VramManager(); private: VmaAllocator vma{VK_NULL_HANDLE}; - Optional graphics; + Wrapper graphics; }; } diff --git a/app/src/main/cpp/cosmic/hle/syscall_gate.h b/app/src/main/cpp/cosmic/hle/syscall_gate.h index 47003bf..7bf7dd6 100644 --- a/app/src/main/cpp/cosmic/hle/syscall_gate.h +++ b/app/src/main/cpp/cosmic/hle/syscall_gate.h @@ -24,6 +24,6 @@ namespace cosmic::hle { void doSyscall(SyscallOrigin origin, i16 sys); private: void resetEe(); - Optional vm; + Wrapper vm; }; } diff --git a/app/src/main/cpp/cosmic/iop/iop_core.cpp b/app/src/main/cpp/cosmic/iop/iop_core.cpp index cc1f71b..adf8d2b 100644 --- a/app/src/main/cpp/cosmic/iop/iop_core.cpp +++ b/app/src/main/cpp/cosmic/iop/iop_core.cpp @@ -15,7 +15,7 @@ namespace cosmic::iop { IoMipsCore::IoMipsCore(std::shared_ptr& pipe) : iopMem(pipe) { - interpreter = std::make_unique(Optional(*this)); + interpreter = std::make_unique(Wrapper(*this)); for (auto& cache : instCache) { cache.data = {}; cache.tag = {}; diff --git a/app/src/main/cpp/cosmic/iop/iop_dma.cpp b/app/src/main/cpp/cosmic/iop/iop_dma.cpp index 6a9e998..67489ef 100644 --- a/app/src/main/cpp/cosmic/iop/iop_dma.cpp +++ b/app/src/main/cpp/cosmic/iop/iop_dma.cpp @@ -23,7 +23,7 @@ namespace cosmic::iop { void IopDma::pulseSpu2Chain() { // When true, it means that we will write into the SPU2 device bool write2Spu; - auto spu2ch{Optional(channels[IopSpu2])}; + auto spu2ch{Wrapper(channels[IopSpu2])}; std::array packet{}; write2Spu = spu2ch->status.isFrom2Device; diff --git a/app/src/main/cpp/cosmic/iop/iop_info.h b/app/src/main/cpp/cosmic/iop/iop_info.h index a0a073e..e4ad015 100644 --- a/app/src/main/cpp/cosmic/iop/iop_info.h +++ b/app/src/main/cpp/cosmic/iop/iop_info.h @@ -5,14 +5,14 @@ namespace cosmic::iop { class IopExecVe { public: - IopExecVe(Optional& mips) : + IopExecVe(Wrapper& mips) : cpu(mips) {} virtual u32 executeCode() = 0; virtual u32 fetchPcInst() = 0; virtual ~IopExecVe() = default; protected: - Optional cpu; + Wrapper cpu; }; enum IopSpecial { diff --git a/app/src/main/cpp/cosmic/mio/dma_ctrl.cpp b/app/src/main/cpp/cosmic/mio/dma_ctrl.cpp index 3a3ae05..6969041 100644 --- a/app/src/main/cpp/cosmic/mio/dma_ctrl.cpp +++ b/app/src/main/cpp/cosmic/mio/dma_ctrl.cpp @@ -72,7 +72,7 @@ namespace cosmic::mio { u32 countOfQw{}; for (; hasOwner && highCycles > 0; ) { - auto owner{Optional(channels.at(hasOwner.getId()))}; + auto owner{Wrapper(channels.at(hasOwner.getId()))}; // "Owner" is the privileged channel that will use the available clock pulses at the moment switch (owner->index) { @@ -229,13 +229,13 @@ namespace cosmic::mio { } else if (!isVu) { return *PipeCraftPtr(pipe, address & 0x01fffff0); } - Optional vu01Mem{}; + Wrapper vu01Mem{}; u32 mask; if (address < 0x11008000) { - vu01Mem = Optional(hw.vif0->vifVu->vecRegion); + vu01Mem = Wrapper(hw.vif0->vifVu->vecRegion); mask = hw.vif0->vifVu->getMemMask(); } else { - vu01Mem = Optional(hw.vif1->vifVu->vecRegion); + vu01Mem = Wrapper(hw.vif1->vifVu->vecRegion); mask = hw.vif1->vifVu->getMemMask(); } bool is0Inst{address < 0x11004000}; diff --git a/app/src/main/cpp/cosmic/mio/dma_ctrl.h b/app/src/main/cpp/cosmic/mio/dma_ctrl.h index 32a7704..cd92ff5 100644 --- a/app/src/main/cpp/cosmic/mio/dma_ctrl.h +++ b/app/src/main/cpp/cosmic/mio/dma_ctrl.h @@ -20,7 +20,7 @@ namespace cosmic::mio { struct HardWithDmaCap { public: HardWithDmaCap() {} - Optional + Wrapper vif0, vif1; std::shared_ptr ee; @@ -194,7 +194,7 @@ namespace cosmic::mio { std::shared_ptr pipe; struct { - Optional vif1, vif0; + Wrapper vif1, vif0; std::shared_ptr core; } hw; }; diff --git a/app/src/main/cpp/cosmic/vm/emu_thread.h b/app/src/main/cpp/cosmic/vm/emu_thread.h index 25e79ec..f389b1e 100644 --- a/app/src/main/cpp/cosmic/vm/emu_thread.h +++ b/app/src/main/cpp/cosmic/vm/emu_thread.h @@ -12,7 +12,7 @@ namespace cosmic::vm { }; struct SharedVm { SharedVm(EmuVm& svm) { - vm = Optional(svm); + vm = Wrapper(svm); running.store(false); monitor.store(SvrNone); } @@ -32,7 +32,7 @@ namespace cosmic::vm { auto isRunning() const { return running.load(); } - Optional vm; + Wrapper vm; std::atomic running; std::atomic monitor; @@ -47,10 +47,10 @@ namespace cosmic::vm { void updateValues(std::shared_ptr& svm, bool running, u8 isSuper); static void vmMain(std::shared_ptr& svm); static void vmSupervisor(std::shared_ptr svm); - static void runFrameLoop(Optional& vm); - static void stepMips(Optional& vm, u32 mips, u32 iop, u32 bus); - static void stepVus(Optional& vm, u32 mips, u32 bus); - static void stepGs(Optional& vm, u32 bus); + static void runFrameLoop(Wrapper& vm); + static void stepMips(Wrapper& vm, u32 mips, u32 iop, u32 bus); + static void stepVus(Wrapper& vm, u32 mips, u32 bus); + static void stepGs(Wrapper& vm, u32 bus); std::thread vmThread; std::shared_ptr vmSharedPtr; diff --git a/app/src/main/cpp/cosmic/vm/emu_vm.cpp b/app/src/main/cpp/cosmic/vm/emu_vm.cpp index 453a602..280ecf1 100644 --- a/app/src/main/cpp/cosmic/vm/emu_vm.cpp +++ b/app/src/main/cpp/cosmic/vm/emu_vm.cpp @@ -40,7 +40,7 @@ namespace cosmic::vm { status.setDesiredFrames(30); - Optional vus[]{ + Wrapper vus[]{ vu01->vpu0Cop2, vu01->vpu1Dlo }; diff --git a/app/src/main/cpp/cosmic/vm/step_frameloop.cpp b/app/src/main/cpp/cosmic/vm/step_frameloop.cpp index 14da4db..06ed7e7 100644 --- a/app/src/main/cpp/cosmic/vm/step_frameloop.cpp +++ b/app/src/main/cpp/cosmic/vm/step_frameloop.cpp @@ -2,25 +2,25 @@ #include namespace cosmic::vm { - void EmuThread::stepMips(Optional& vm, u32 mips, u32 iop, u32 bus) { + void EmuThread::stepMips(Wrapper& vm, u32 mips, u32 iop, u32 bus) { vm->mips->pulse(mips); vm->iop->pulse(iop); // DMAC runs in parallel, which could be optimized (and will be early next year) vm->sharedPipe->controller->pulse(bus); vm->mpegDecoder->update(); } - void EmuThread::stepVus(Optional& vm, u32 mips, u32 bus) { + void EmuThread::stepVus(Wrapper& vm, u32 mips, u32 bus) { // VUs can run in parallel with EE... for (u8 runVifs{}; runVifs < 2; runVifs++) vm->vu01->vifs[runVifs].update(bus); vm->vu01->vpu0Cop2.pulse(mips); vm->vu01->vpu1Dlo.pulse(mips); } - void EmuThread::stepGs(Optional& vm, u32 bus) { + void EmuThread::stepGs(Wrapper& vm, u32 bus) { vm->gsGif->update(bus); } - void EmuThread::runFrameLoop(Optional& vm) { + void EmuThread::runFrameLoop(Wrapper& vm) { auto sched{vm->scheduler}; while (!vm->status.get(HasFrame)) { u32 mipsCycles{sched->getNextCycles(Scheduler::Mips)}; diff --git a/app/src/main/cpp/cosmic/vu/v01_cop2vu.cpp b/app/src/main/cpp/cosmic/vu/v01_cop2vu.cpp index bc1ac5f..e975e48 100644 --- a/app/src/main/cpp/cosmic/vu/v01_cop2vu.cpp +++ b/app/src/main/cpp/cosmic/vu/v01_cop2vu.cpp @@ -1,7 +1,7 @@ #include namespace cosmic::vu { - MacroModeCop2::MacroModeCop2(Optional vus[2]) + MacroModeCop2::MacroModeCop2(Wrapper vus[2]) : v0(vus[0]), v1(vus[1]) { cop2il = false; diff --git a/app/src/main/cpp/cosmic/vu/v01_cop2vu.h b/app/src/main/cpp/cosmic/vu/v01_cop2vu.h index ae6d90b..74d09d4 100644 --- a/app/src/main/cpp/cosmic/vu/v01_cop2vu.h +++ b/app/src/main/cpp/cosmic/vu/v01_cop2vu.h @@ -6,7 +6,7 @@ namespace cosmic::vu { // Just a communication interface between these two VUs class MacroModeCop2 { public: - MacroModeCop2(Optional vus[2]); + MacroModeCop2(Wrapper vus[2]); void clearInterlock(); bool checkInterlock(); bool interlockCheck(bool isCop2); @@ -14,8 +14,8 @@ namespace cosmic::vu { u32 cfc2(u32 special); void ctc2(u32 special, u32 value); - Optional v0; - Optional v1; + Wrapper v0; + Wrapper v1; bool cop2il, vuIl; }; diff --git a/app/src/main/cpp/cosmic/vu/vecu.cpp b/app/src/main/cpp/cosmic/vu/vecu.cpp index 33413b9..2f3937e 100644 --- a/app/src/main/cpp/cosmic/vu/vecu.cpp +++ b/app/src/main/cpp/cosmic/vu/vecu.cpp @@ -28,7 +28,7 @@ namespace cosmic::vu { } } - VectorUnit::VectorUnit(Optional vu2, VuWorkMemory vuWm) : + VectorUnit::VectorUnit(Wrapper vu2, VuWorkMemory vuWm) : paraVu(vu2), vecRegion(vuWm) { @@ -198,9 +198,9 @@ namespace cosmic::vu { } return {}; } - void VectorUnit::establishVif(u16 conTops[2], Optional gif) { + void VectorUnit::establishVif(u16 conTops[2], Wrapper gif) { for (u8 top{}; top < 2; top++) - vifTops[top] = Optional(conTops[top]); + vifTops[top] = Wrapper(conTops[top]); if (gif) vu1Gif = gif; diff --git a/app/src/main/cpp/cosmic/vu/vecu.h b/app/src/main/cpp/cosmic/vu/vecu.h index 0ebd28c..1bb8604 100644 --- a/app/src/main/cpp/cosmic/vu/vecu.h +++ b/app/src/main/cpp/cosmic/vu/vecu.h @@ -81,7 +81,7 @@ namespace cosmic::vu { class VectorUnit { public: VectorUnit() = delete; - VectorUnit(Optional vu2, VuWorkMemory vuWm); + VectorUnit(Wrapper vu2, VuWorkMemory vuWm); void resetVu(); void softwareReset(); @@ -103,7 +103,7 @@ namespace cosmic::vu { VuReg acc; alignas(32) std::array intsRegs; - void establishVif(u16 conTops[2], Optional gif); + void establishVif(u16 conTops[2], Wrapper gif); // P register: Used by EFU to store the result - waitp could be used to stall the execution // while EFU doesn't finish the previous calculation u32 vuPc{}; @@ -113,7 +113,7 @@ namespace cosmic::vu { VuStatus status; VuIntPipeline intPipeline; - Optional paraVu; + Wrapper paraVu; void pushIntPipe(u8 ir, u8 fir); void finishStallPipeTask(bool isDiv); @@ -199,7 +199,7 @@ namespace cosmic::vu { i64 trigger; bool isDirty; } clock; - Optional vifTops[2]; - Optional vu1Gif; + Wrapper vifTops[2]; + Wrapper vu1Gif; }; } diff --git a/app/src/main/cpp/cosmic/vu/vif10_upload.cpp b/app/src/main/cpp/cosmic/vu/vif10_upload.cpp index d3f48b2..5f057c9 100644 --- a/app/src/main/cpp/cosmic/vu/vif10_upload.cpp +++ b/app/src/main/cpp/cosmic/vu/vif10_upload.cpp @@ -2,7 +2,7 @@ #include namespace cosmic::vu { - VifMalice::VifMalice(Optional vector, VifGifInterconnector card) : + VifMalice::VifMalice(Wrapper vector, VifGifInterconnector card) : vif2gif(card), vifVu(vector) { tops[0] = {}; diff --git a/app/src/main/cpp/cosmic/vu/vif10_upload.h b/app/src/main/cpp/cosmic/vu/vif10_upload.h index 4cd7cdc..3293fd1 100644 --- a/app/src/main/cpp/cosmic/vu/vif10_upload.h +++ b/app/src/main/cpp/cosmic/vu/vif10_upload.h @@ -57,7 +57,7 @@ namespace cosmic::vu { public: VifMalice() = default; VifMalice(VifMalice&) = delete; - VifMalice(Optional vector, VifGifInterconnector card); + VifMalice(Wrapper vector, VifGifInterconnector card); void update(u32 cycles); void resetVif(); @@ -74,7 +74,7 @@ namespace cosmic::vu { std::shared_ptr interrupts; std::shared_ptr dmac; - Optional vifVu; + Wrapper vifVu; mio::DirectChannels vifId; private: u16 memMask{}; diff --git a/app/src/main/cpp/cosmic/vu/vu_info.h b/app/src/main/cpp/cosmic/vu/vu_info.h index 383b829..e16da26 100644 --- a/app/src/main/cpp/cosmic/vu/vu_info.h +++ b/app/src/main/cpp/cosmic/vu/vu_info.h @@ -5,7 +5,7 @@ namespace cosmic::vu { class VectorUnit; class VuMicroExecutor { public: - VuMicroExecutor(Optional& vu) : vuMicro(vu) { + VuMicroExecutor(Wrapper& vu) : vuMicro(vu) { } virtual u32 executeCode() = 0; @@ -14,6 +14,6 @@ namespace cosmic::vu { virtual std::pair fetchPcInst() = 0; virtual ~VuMicroExecutor() = default; protected: - Optional vuMicro; + Wrapper vuMicro; }; }