-
Notifications
You must be signed in to change notification settings - Fork 0
/
memcard.js
34 lines (28 loc) · 849 Bytes
/
memcard.js
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
function is_memcard(byte_array)
{
return byte_array[0] == 0x4D && byte_array[1] == 0x43;
}
function browse_toc(byte_array)
{
let addresses = [];
let current_address = 0x00;
while (current_address <= 0x780)
{
current_address += 0x80;
if (byte_array[current_address] != 0xA0 && check_toc_entry(byte_array, current_address))
addresses.push(0x2000 * (current_address / 0x80));
}
return addresses;
}
function check_toc_entry(byte_array, current_address)
{
const code_US = "SLUS-01324BOF4";
const code_EU = "SLES-03552BOF4";
for (let i = 0; i < 0x0E; i++)
{
if (byte_array[current_address + 0x0C + i] != code_US[i].charCodeAt()
&& byte_array[current_address + 0x0C + i] != code_EU[i].charCodeAt())
return false;
}
return true;
}