From 0035a4ef3d0141b4b1b970efb33029ec41d1d07c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 12 Jan 2017 19:44:36 -0500 Subject: [PATCH] GCMemcard: Const-correctness changes A few function reference and pointer parameters are only read from. --- Source/Core/Core/HW/GCMemcard.cpp | 14 +++++++------- Source/Core/Core/HW/GCMemcard.h | 10 +++++----- Source/Core/Core/HW/GCMemcardDirectory.cpp | 4 ++-- Source/Core/Core/HW/GCMemcardDirectory.h | 4 ++-- Source/Core/Core/HW/GCMemcardRaw.cpp | 2 +- Source/Core/Core/HW/GCMemcardRaw.h | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/Core/Core/HW/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard.cpp index c08b798458..85a26e4ac8 100644 --- a/Source/Core/Core/HW/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard.cpp @@ -250,7 +250,7 @@ bool GCMemcard::Save() return mcdFile.Close(); } -void calc_checksumsBE(u16* buf, u32 length, u16* csum, u16* inv_csum) +void calc_checksumsBE(const u16* buf, u32 length, u16* csum, u16* inv_csum) { *csum = *inv_csum = 0; @@ -639,7 +639,7 @@ u32 GCMemcard::GetSaveData(u8 index, std::vector& Blocks) const } // End DEntry functions -u32 GCMemcard::ImportFile(DEntry& direntry, std::vector& saveBlocks) +u32 GCMemcard::ImportFile(const DEntry& direntry, std::vector& saveBlocks) { if (!m_valid) return NOMEMCARD; @@ -1271,7 +1271,7 @@ bool GCMemcard::Format(bool shift_jis, u16 SizeMb) /* Returns: Error code */ /*************************************************************/ -s32 GCMemcard::FZEROGX_MakeSaveGameValid(Header& cardheader, DEntry& direntry, +s32 GCMemcard::FZEROGX_MakeSaveGameValid(const Header& cardheader, const DEntry& direntry, std::vector& FileBuffer) { u32 i, j; @@ -1280,7 +1280,7 @@ s32 GCMemcard::FZEROGX_MakeSaveGameValid(Header& cardheader, DEntry& direntry, int block = 0; // check for F-Zero GX system file - if (strcmp((char*)direntry.Filename, "f_zero.dat") != 0) + if (strcmp(reinterpret_cast(direntry.Filename), "f_zero.dat") != 0) return 0; // get encrypted destination memory card serial numbers @@ -1324,7 +1324,7 @@ s32 GCMemcard::FZEROGX_MakeSaveGameValid(Header& cardheader, DEntry& direntry, /* Returns: Error code */ /***********************************************************/ -s32 GCMemcard::PSO_MakeSaveGameValid(Header& cardheader, DEntry& direntry, +s32 GCMemcard::PSO_MakeSaveGameValid(const Header& cardheader, const DEntry& direntry, std::vector& FileBuffer) { u32 i, j; @@ -1334,10 +1334,10 @@ s32 GCMemcard::PSO_MakeSaveGameValid(Header& cardheader, DEntry& direntry, u32 pso3offset = 0x00; // check for PSO1&2 system file - if (strcmp((char*)direntry.Filename, "PSO_SYSTEM") != 0) + if (strcmp(reinterpret_cast(direntry.Filename), "PSO_SYSTEM") != 0) { // check for PSO3 system file - if (strcmp((char*)direntry.Filename, "PSO3_SYSTEM") == 0) + if (strcmp(reinterpret_cast(direntry.Filename), "PSO3_SYSTEM") == 0) { // PSO3 data block size adjustment pso3offset = 0x10; diff --git a/Source/Core/Core/HW/GCMemcard.h b/Source/Core/Core/HW/GCMemcard.h index c609cc5dd7..b6be07df33 100644 --- a/Source/Core/Core/HW/GCMemcard.h +++ b/Source/Core/Core/HW/GCMemcard.h @@ -76,7 +76,7 @@ public: } virtual ~MemoryCardBase() {} virtual s32 Read(u32 address, s32 length, u8* destaddress) = 0; - virtual s32 Write(u32 destaddress, s32 length, u8* srcaddress) = 0; + virtual s32 Write(u32 destaddress, s32 length, const u8* srcaddress) = 0; virtual void ClearBlock(u32 address) = 0; virtual void ClearAll() = 0; virtual void DoState(PointerWrap& p) = 0; @@ -95,7 +95,7 @@ struct GCMBlock u8 block[BLOCK_SIZE]; }; -void calc_checksumsBE(u16* buf, u32 length, u16* csum, u16* inv_csum); +void calc_checksumsBE(const u16* buf, u32 length, u16* csum, u16* inv_csum); #pragma pack(push, 1) struct Header // Offset Size Description @@ -321,9 +321,9 @@ public: bool Save(); bool Format(bool shift_jis = false, u16 SizeMb = MemCard2043Mb); static bool Format(u8* card_data, bool shift_jis = false, u16 SizeMb = MemCard2043Mb); - static s32 FZEROGX_MakeSaveGameValid(Header& cardheader, DEntry& direntry, + static s32 FZEROGX_MakeSaveGameValid(const Header& cardheader, const DEntry& direntry, std::vector& FileBuffer); - static s32 PSO_MakeSaveGameValid(Header& cardheader, DEntry& direntry, + static s32 PSO_MakeSaveGameValid(const Header& cardheader, const DEntry& direntry, std::vector& FileBuffer); u32 TestChecksums() const; @@ -364,7 +364,7 @@ public: u32 GetSaveData(u8 index, std::vector& saveBlocks) const; // adds the file to the directory and copies its contents - u32 ImportFile(DEntry& direntry, std::vector& saveBlocks); + u32 ImportFile(const DEntry& direntry, std::vector& saveBlocks); // delete a file from the directory u32 RemoveFile(u8 index); diff --git a/Source/Core/Core/HW/GCMemcardDirectory.cpp b/Source/Core/Core/HW/GCMemcardDirectory.cpp index 69d177f052..489b5a4dce 100644 --- a/Source/Core/Core/HW/GCMemcardDirectory.cpp +++ b/Source/Core/Core/HW/GCMemcardDirectory.cpp @@ -270,7 +270,7 @@ s32 GCMemcardDirectory::Read(u32 address, s32 length, u8* destaddress) return length + extra; } -s32 GCMemcardDirectory::Write(u32 destaddress, s32 length, u8* srcaddress) +s32 GCMemcardDirectory::Write(u32 destaddress, s32 length, const u8* srcaddress) { std::unique_lock l(m_write_mutex); if (length != 0x80) @@ -475,7 +475,7 @@ inline s32 GCMemcardDirectory::SaveAreaRW(u32 block, bool writing) return -1; } -s32 GCMemcardDirectory::DirectoryWrite(u32 destaddress, u32 length, u8* srcaddress) +s32 GCMemcardDirectory::DirectoryWrite(u32 destaddress, u32 length, const u8* srcaddress) { u32 block = destaddress / BLOCK_SIZE; u32 offset = destaddress % BLOCK_SIZE; diff --git a/Source/Core/Core/HW/GCMemcardDirectory.h b/Source/Core/Core/HW/GCMemcardDirectory.h index 711dfda026..8a1dcba1c5 100644 --- a/Source/Core/Core/HW/GCMemcardDirectory.h +++ b/Source/Core/Core/HW/GCMemcardDirectory.h @@ -28,7 +28,7 @@ public: void FlushToFile(); void FlushThread(); s32 Read(u32 address, s32 length, u8* destaddress) override; - s32 Write(u32 destaddress, s32 length, u8* srcaddress) override; + s32 Write(u32 destaddress, s32 length, const u8* srcaddress) override; void ClearBlock(u32 address) override; void ClearAll() override {} void DoState(PointerWrap& p) override; @@ -37,7 +37,7 @@ private: int LoadGCI(const std::string& fileName, DiscIO::Region card_region, bool currentGameOnly); inline s32 SaveAreaRW(u32 block, bool writing = false); // s32 DirectoryRead(u32 offset, u32 length, u8* destaddress); - s32 DirectoryWrite(u32 destaddress, u32 length, u8* srcaddress); + s32 DirectoryWrite(u32 destaddress, u32 length, const u8* srcaddress); inline void SyncSaves(); bool SetUsedBlocks(int saveIndex); diff --git a/Source/Core/Core/HW/GCMemcardRaw.cpp b/Source/Core/Core/HW/GCMemcardRaw.cpp index 24c72b7f6f..ccb1566ee1 100644 --- a/Source/Core/Core/HW/GCMemcardRaw.cpp +++ b/Source/Core/Core/HW/GCMemcardRaw.cpp @@ -157,7 +157,7 @@ s32 MemoryCard::Read(u32 srcaddress, s32 length, u8* destaddress) return length; } -s32 MemoryCard::Write(u32 destaddress, s32 length, u8* srcaddress) +s32 MemoryCard::Write(u32 destaddress, s32 length, const u8* srcaddress) { if (!IsAddressInBounds(destaddress)) { diff --git a/Source/Core/Core/HW/GCMemcardRaw.h b/Source/Core/Core/HW/GCMemcardRaw.h index 0b0e5cf637..fdd582658d 100644 --- a/Source/Core/Core/HW/GCMemcardRaw.h +++ b/Source/Core/Core/HW/GCMemcardRaw.h @@ -23,7 +23,7 @@ public: void MakeDirty(); s32 Read(u32 address, s32 length, u8* destaddress) override; - s32 Write(u32 destaddress, s32 length, u8* srcaddress) override; + s32 Write(u32 destaddress, s32 length, const u8* srcaddress) override; void ClearBlock(u32 address) override; void ClearAll() override; void DoState(PointerWrap& p) override;