forked from M4Duke/cpcxfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpc.c
53 lines (42 loc) · 950 Bytes
/
cpc.c
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
/*
Duke 2016
Some CPC specific functions.
*/
// decrypt "protected" basic files, reversed from CPC
int decrypt_basp(unsigned char *data, int size)
{
int idx1, idx2, i, j;
unsigned char xorstream1[13] = { 0xE2, 0x9D, 0xDB, 0X1A, 0x42, 0x29, 0x39, 0xC6, 0xB3, 0xC6, 0x90, 0x45, 0x8A };
unsigned char xorstream2[11] = { 0x49, 0xB1, 0x36, 0xF0, 0x2E, 0x1E, 0x06, 0x2A, 0x28, 0x19, 0xEA };
idx1 = 0;
idx2 = 0;
i = 0;
j = 0;
while (j < size)
{
if ( i == 0x80)
{
idx1 = 0;
idx2 = 0;
i = 0;
}
data[j] ^= xorstream1[idx1++];
data[j] ^= xorstream2[idx2++];
if (idx1 == 13)
idx1 = 0;
if (idx2 == 11)
idx2 = 0;
i++;
j++;
}
return 0;
}
// simple checksum used by amsdos headers
unsigned short checksum16(unsigned char *data, int size)
{
int i;
unsigned short checksum = 0;
for (i=0; i<size; i++)
checksum+=data[i];
return checksum;
}