-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdload.cpp
More file actions
73 lines (56 loc) · 1.46 KB
/
sdload.cpp
File metadata and controls
73 lines (56 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// sdload.cpp
//
// To do: more patches
// To do: saving patches
//
#include <circle/string.h>
#include <circle/util.h>
#include "sdload.h"
CSDLoad::CSDLoad(CInterruptSystem* pInterrupt, CTimer* pTimer)
: m_EMMC(pInterrupt, pTimer),
m_patchCount(0)
{
memset(m_patchBuffer, 0, sizeof(m_patchBuffer));
memset(m_patchBufferSize, 0, sizeof(m_patchBufferSize));
}
bool CSDLoad::Initialize()
{
if (!m_EMMC.Initialize())
return false;
return true;
}
bool CSDLoad::LoadPatches() // LOAD PATCHES
{
m_patchCount = 0;
// Fixed array of filenames
const char* patchFiles[MAX_PATCHES] =
{
"SD:/patches/patch0.txt",
"SD:/patches/patch1.txt",
"SD:/patches/patch2.txt",
"SD:/patches/patch3.txt",
"SD:/patches/patch4.txt",
"SD:/patches/patch5.txt",
"SD:/patches/patch6.txt",
"SD:/patches/patch7.txt"
};
if (f_mount(&m_FileSystem, DRIVE, 1) != FR_OK)
{ return false; }
for (unsigned i = 0; i < MAX_PATCHES; ++i)
{
FIL File;
if(f_open(&File, patchFiles[i], FA_READ | FA_OPEN_EXISTING) != FR_OK)
break; // stop if file not found
UINT bytesRead = 0;
if (f_read(&File, m_patchBuffer[i], sizeof(m_patchBuffer[i])-1, &bytesRead) != FR_OK)
return false;
if (!bytesRead)
return false;
f_close(&File);
m_patchBuffer[i][bytesRead] = '\0'; // Ensure null terminated
m_patchBufferSize[i] = bytesRead;
++m_patchCount;
}
return (m_patchCount > 0);
}