| 1013 | } |
| 1014 | |
| 1015 | s32 FolderMemoryCard::Save(const u8* src, u32 adr, int size) |
| 1016 | { |
| 1017 | //const u32 block = adr / BlockSizeRaw; |
| 1018 | //const u32 cluster = adr / ClusterSizeRaw; |
| 1019 | const u32 page = adr / PageSizeRaw; |
| 1020 | const u32 offset = adr % PageSizeRaw; |
| 1021 | const u32 end = offset + size; |
| 1022 | |
| 1023 | if (end > PageSizeRaw) |
| 1024 | { |
| 1025 | // is trying to store more than one page at a time |
| 1026 | // do this recursively so that each function call only has to care about one page |
| 1027 | const u32 toNextPage = PageSizeRaw - offset; |
| 1028 | Save(src + toNextPage, adr + toNextPage, size - toNextPage); |
| 1029 | size = toNextPage; |
| 1030 | } |
| 1031 | |
| 1032 | if (offset < PageSize) |
| 1033 | { |
| 1034 | // is trying to store (part of) an actual data block |
| 1035 | const u32 dataLength = std::min((u32)size, PageSize - offset); |
| 1036 | |
| 1037 | // if cache page has not yet been touched, fill it with the data from our memory card |
| 1038 | auto it = m_cache.find(page); |
| 1039 | MemoryCardPage* cachePage; |
| 1040 | if (it == m_cache.end()) |
| 1041 | { |
| 1042 | cachePage = &m_cache[page]; |
| 1043 | const u32 adrLoad = page * PageSizeRaw; |
| 1044 | ReadDataWithoutCache(&cachePage->raw[0], adrLoad, PageSize); |
| 1045 | memcpy(&m_oldDataCache[page].raw[0], &cachePage->raw[0], PageSize); |
| 1046 | } |
| 1047 | else |
| 1048 | { |
| 1049 | cachePage = &it->second; |
| 1050 | } |
| 1051 | |
| 1052 | // then just write to the cache |
| 1053 | memcpy(&cachePage->raw[offset], src, dataLength); |
| 1054 | |
| 1055 | SetTimeLastWrittenToNow(); |
| 1056 | } |
| 1057 | |
| 1058 | return 1; |
| 1059 | } |
| 1060 | |
| 1061 | void FolderMemoryCard::NextFrame() |
| 1062 | { |