diff --git a/include/memory.hpp b/include/memory.hpp index 0e75f36c..33b18ca5 100644 --- a/include/memory.hpp +++ b/include/memory.hpp @@ -95,6 +95,7 @@ namespace KernelMemoryTypes { class Memory { u8* fcram; u8* dspRam; + u8* vram; // Provided to the memory class by the GPU class u64& cpuTicks; // Reference to the CPU tick counter using SharedMemoryBlock = KernelMemoryTypes::SharedMemoryBlock; @@ -237,6 +238,7 @@ public: u8* getDSPMem() { return dspRam; } u8* getDSPDataMem() { return &dspRam[DSP_DATA_MEMORY_OFFSET]; } u8* getDSPCodeMem() { return &dspRam[DSP_CODE_MEMORY_OFFSET]; } - u32 getUsedUserMem() { return usedUserMemory; } + + void setVRAM(u8* pointer) { vram = pointer; } }; \ No newline at end of file diff --git a/src/core/PICA/gpu.cpp b/src/core/PICA/gpu.cpp index a9f2ad4d..4cd3554c 100644 --- a/src/core/PICA/gpu.cpp +++ b/src/core/PICA/gpu.cpp @@ -7,6 +7,7 @@ using namespace Floats; GPU::GPU(Memory& mem) : mem(mem), renderer(*this, regs) { vram = new u8[vramSize]; + mem.setVRAM(vram); // Give the bus a pointer to our VRAM } void GPU::reset() { @@ -275,7 +276,6 @@ void GPU::fireDMA(u32 dest, u32 source, u32 size) { std::memcpy(&vram[dest - vramStart], &fcram[source - fcramStart], size); } else { printf("Non-trivially optimizable GPU DMA. Falling back to byte-by-byte transfer"); - std::memcpy(&vram[dest - vramStart], mem.getReadPointer(source), size); for (u32 i = 0; i < size; i++) { mem.write8(dest + i, mem.read8(source + i)); diff --git a/src/core/fs/archive_save_data.cpp b/src/core/fs/archive_save_data.cpp index 758c1312..572d22e0 100644 --- a/src/core/fs/archive_save_data.cpp +++ b/src/core/fs/archive_save_data.cpp @@ -5,7 +5,32 @@ namespace fs = std::filesystem; FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) { - Helpers::panic("[SaveData] CreateFile not yet supported"); + if (path.type == PathType::UTF16) { + if (!isPathSafe(path)) + Helpers::panic("Unsafe path in SaveData::CreateFile"); + + fs::path p = IOFile::getAppData() / "SaveData"; + p += fs::path(path.utf16_string).make_preferred(); + + if (fs::exists(p)) + return FSResult::AlreadyExists; + + IOFile file(p.string().c_str(), "wb"); + + // If the size is 0, leave the file empty and return success + if (size == 0) { + return FSResult::Success; + } + + // If it is not empty, seek to size - 1 and write a 0 to create a file of size "size" + else if (file.seek(size - 1, SEEK_SET) && file.writeBytes("", 1).second == 1) { + return FSResult::Success; + } + + return FSResult::FileTooLarge; + } + + Helpers::panic("SaveDataArchive::OpenFile: Failed"); return FSResult::Success; } @@ -170,4 +195,4 @@ Rust::Result SaveDataArchive::openArchive(const FSPath& std::optional SaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) { Helpers::panic("Unimplemented SaveData::ReadFile"); return 0; -} \ No newline at end of file +} diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 6d64f3f8..37c13c7d 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -143,7 +143,15 @@ void Memory::write8(u32 vaddr, u8 value) { *(u8*)(pointer + offset) = value; } else { - Helpers::panic("Unimplemented 8-bit write, addr: %08X, val: %02X", vaddr, value); + // VRAM write + if (vaddr >= VirtualAddrs::VramStart && vaddr < VirtualAddrs::VramStart + VirtualAddrs::VramSize) { + // TODO: Invalidate renderer caches here + vram[vaddr - VirtualAddrs::VramStart] = value; + } + + else { + Helpers::panic("Unimplemented 8-bit write, addr: %08X, val: %02X", vaddr, value); + } } }