2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 22:43:11 -04:00
|
|
|
// Refer to the license.txt file included.
|
2010-12-19 16:03:39 +00:00
|
|
|
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "Core/HW/Sram.h"
|
2017-03-03 14:43:52 -05:00
|
|
|
|
2016-01-12 22:34:13 -05:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-01-15 21:46:32 +01:00
|
|
|
#include "Common/File.h"
|
2016-10-07 22:55:13 +02:00
|
|
|
#include "Common/Logging/Log.h"
|
2017-03-03 14:43:52 -05:00
|
|
|
#include "Common/Swap.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
|
2018-09-30 20:34:22 -07:00
|
|
|
// English
|
|
|
|
// This is just a template. Most/all fields are updated with sane(r) values at runtime.
|
2019-01-25 17:33:17 +01:00
|
|
|
// clang-format off
|
2018-09-30 20:34:22 -07:00
|
|
|
const Sram sram_dump = {Common::BigEndianValue<u32>{0},
|
|
|
|
{Common::BigEndianValue<u16>{0x2c}, Common::BigEndianValue<u16>{0xffd0}, 0,
|
2019-01-25 17:33:17 +01:00
|
|
|
0, 0, 0, 0, 0, {0x20 | SramFlags::kOobeDone | SramFlags::kStereo}},
|
2018-09-30 20:34:22 -07:00
|
|
|
{{
|
|
|
|
{'D', 'O', 'L', 'P', 'H', 'I', 'N', 'S', 'L', 'O', 'T', 'A'},
|
|
|
|
{'D', 'O', 'L', 'P', 'H', 'I', 'N', 'S', 'L', 'O', 'T', 'B'},
|
|
|
|
},
|
|
|
|
0,
|
|
|
|
{},
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{0x6E, 0x6D},
|
|
|
|
0,
|
|
|
|
{}}};
|
2019-01-25 17:33:17 +01:00
|
|
|
// clang-format on
|
2010-12-19 16:03:39 +00:00
|
|
|
|
2011-02-02 18:21:20 +00:00
|
|
|
#if 0
|
2010-12-19 16:03:39 +00:00
|
|
|
// german
|
2017-01-30 17:43:31 -05:00
|
|
|
const SRAM sram_dump_german = {{
|
2010-12-19 16:03:39 +00:00
|
|
|
0x1F, 0x66,
|
|
|
|
0xE0, 0x96,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x04, 0xEA, 0x19, 0x40,
|
|
|
|
0x00,
|
|
|
|
0x00,
|
|
|
|
0x01,
|
|
|
|
0x3C,
|
2014-02-16 23:51:41 -05:00
|
|
|
0x12, 0xD5, 0xEA, 0xD3, 0x00, 0xFA, 0x2D, 0x33, 0x13, 0x41, 0x26, 0x03,
|
2010-12-19 16:03:39 +00:00
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00,
|
|
|
|
0x00, 0x00,
|
|
|
|
0x00, 0x00,
|
|
|
|
0x00, 0x00,
|
|
|
|
0x00,
|
|
|
|
0x00,
|
|
|
|
0x84, 0xFF,
|
|
|
|
0x00, 0x00,
|
|
|
|
0x00, 0x00
|
|
|
|
}};
|
2011-02-02 18:21:20 +00:00
|
|
|
#endif
|
2010-12-19 16:03:39 +00:00
|
|
|
|
2014-07-15 19:29:42 -04:00
|
|
|
void InitSRAM()
|
2010-12-19 16:03:39 +00:00
|
|
|
{
|
2015-06-12 13:56:53 +02:00
|
|
|
File::IOFile file(SConfig::GetInstance().m_strSRAM, "rb");
|
2011-03-11 10:21:46 +00:00
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
if (!file.ReadArray(&g_SRAM, 1))
|
|
|
|
{
|
2020-11-19 21:45:54 -05:00
|
|
|
ERROR_LOG_FMT(EXPANSIONINTERFACE, "EXI IPL-DEV: Could not read all of SRAM");
|
2011-03-11 10:21:46 +00:00
|
|
|
g_SRAM = sram_dump;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_SRAM = sram_dump;
|
2010-12-19 16:03:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-18 02:15:07 -04:00
|
|
|
void SetCardFlashID(const u8* buffer, u8 card_index)
|
2010-12-19 16:03:39 +00:00
|
|
|
{
|
2016-07-18 02:15:07 -04:00
|
|
|
u64 rand = Common::swap64(&buffer[12]);
|
2010-12-19 16:03:39 +00:00
|
|
|
u8 csum = 0;
|
2014-03-11 00:30:55 +13:00
|
|
|
for (int i = 0; i < 12; i++)
|
2010-12-19 16:03:39 +00:00
|
|
|
{
|
|
|
|
rand = (((rand * (u64)0x0000000041c64e6dULL) + (u64)0x0000000000003039ULL) >> 16);
|
2017-09-04 03:35:21 -07:00
|
|
|
csum += g_SRAM.settings_ex.flash_id[card_index][i] = buffer[i] - ((u8)rand & 0xff);
|
2013-10-29 01:23:17 -04:00
|
|
|
rand = (((rand * (u64)0x0000000041c64e6dULL) + (u64)0x0000000000003039ULL) >> 16);
|
2010-12-19 16:03:39 +00:00
|
|
|
rand &= (u64)0x0000000000007fffULL;
|
|
|
|
}
|
2017-09-04 03:35:21 -07:00
|
|
|
g_SRAM.settings_ex.flash_id_checksum[card_index] = csum ^ 0xFF;
|
2010-12-19 16:03:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-08 01:08:29 +02:00
|
|
|
void FixSRAMChecksums()
|
|
|
|
{
|
2018-09-30 17:58:37 -07:00
|
|
|
// 16bit big-endian additive checksum
|
2015-06-08 01:08:29 +02:00
|
|
|
u16 checksum = 0;
|
|
|
|
u16 checksum_inv = 0;
|
2017-09-04 03:35:21 -07:00
|
|
|
for (auto p = reinterpret_cast<u16*>(&g_SRAM.settings.rtc_bias);
|
|
|
|
p != reinterpret_cast<u16*>(&g_SRAM.settings_ex); p++)
|
2015-06-08 01:08:29 +02:00
|
|
|
{
|
2018-09-30 17:58:37 -07:00
|
|
|
u16 value = Common::FromBigEndian(*p);
|
|
|
|
checksum += value;
|
|
|
|
checksum_inv += ~value;
|
2015-06-08 01:08:29 +02:00
|
|
|
}
|
2018-09-30 17:58:37 -07:00
|
|
|
g_SRAM.settings.checksum = checksum;
|
|
|
|
g_SRAM.settings.checksum_inv = checksum_inv;
|
2015-06-08 01:08:29 +02:00
|
|
|
}
|