-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhiscores.c
141 lines (133 loc) · 4.4 KB
/
hiscores.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
This file is part of the zBoy project.
Copyright (C) Mateusz Viste 2010,2011,2012,2013,2014,2015
*/
uint8_t *GetHiScoresOffsets(unsigned int *offset1, unsigned int *offset2) {
switch (RomInfos.CrcSum) {
case 0x0509069C: /* Pac-Man */
case 0xB681E243: /* Pac-Man (another version) */
*offset1 = 0xFF8C;
*offset2 = 0xFF8E;
return(MemoryInternalHiRAM);
break;
case 0xB3A86164: /* Hyper Lode Runner */
*offset1 = 0xFFA7;
*offset2 = 0xFFA9;
return(MemoryInternalHiRAM);
break;
case 0x0E5BB1C4: /* Ms. Pac-Man */
*offset1 = 0xD8C7;
*offset2 = 0xD8C9;
return(MemoryInternalRAM);
break;
case 0xF59CEDEA: /* Pipe Dream */
*offset1 = 0xC212;
*offset2 = 0xC22C;
return(MemoryInternalRAM);
break;
case 0x90776841: /* Super Marioland v1.0 */
case 0x2C27EC70: /* Super Marioland v1.1 */
*offset1 = 0xC0C0;
*offset2 = 0xC0C3;
return(MemoryInternalRAM);
break;
case 0x63F9407D: /* Tetris v1.0 */
case 0x46DF91AD: /* Tetris v1.1 */
*offset1 = 0xD000;
*offset2 = 0xD761;
return(MemoryInternalRAM);
break;
case 0xC1F88833: /* Asteroids */
*offset1 = 0xDB00;
*offset2 = 0xDB53;
return(MemoryInternalRAM);
break;
case 0xA37A814A: /* BattleCity */
*offset1 = 0xCA02;
*offset2 = 0xCA06;
return(MemoryInternalRAM);
break;
case 0xB76C769B: /* Tetris Attack v1.0 */
*offset1 = 0xCF00;
*offset2 = 0xCF2C;
return(MemoryInternalRAM);
break;
case 0x6C742478: /* Dig Dug */
*offset1 = 0xDE08;
*offset2 = 0xDE17;
return(MemoryInternalRAM);
break;
case 0x6A6ECFEC: /* Galaga & Galaxian */
*offset1 = 0xD70D;
*offset2 = 0xD716;
return(MemoryInternalRAM);
break;
default: /* if not found, set offsets to 0 */
return(NULL);
break;
}
}
#define XorKey 1983
void SaveHiScoresMem(void) {
/*
unsigned int UintVar, offset1, offset2;
uint8_t *memarea;
uint32_t HiScoreCheckSum = 1985;
FILE *FileHandler;
char SaveDir[1024];
char SaveScoresFile[1024];
drv_getsavedir(SaveDir, 1024); /* provides the SaveDir variable * /
snprintf(SaveScoresFile, 1022, "%s%08X.hi", SaveDir, (unsigned int)RomInfos.CrcSum);
memarea = GetHiScoresOffsets(&offset1, &offset2);
if (memarea != NULL) {
FileHandler = fopen(SaveScoresFile, "wb");
for (UintVar = offset1; UintVar <= offset2; UintVar++) {
fputc(memarea[UintVar], FileHandler);
HiScoreCheckSum += memarea[UintVar];
}
/* Write the checksum value into the file * /
HiScoreCheckSum ^= XorKey;
fputc((HiScoreCheckSum >> 24) & 0xFF, FileHandler);
fputc((HiScoreCheckSum >> 16) & 0xFF, FileHandler);
fputc((HiScoreCheckSum >> 8) & 0xFF, FileHandler);
fputc(HiScoreCheckSum & 0xFF, FileHandler);
/* Close the file * /
fclose(FileHandler);
}
*/
}
void LoadHiScoresMem(void) {
/*
unsigned int UintVar, offset1, offset2;
unsigned int HiScoreCheckSum = 1985, SavedCheckSum;
char SaveDir[1024];
char SaveScoresFile[1024];
uint8_t *memarea;
FILE *FileHandler;
drv_getsavedir(SaveDir, 1024); /* provides the SaveDir variable * /
snprintf(SaveScoresFile, 1022, "%s%08X.hi", SaveDir, (unsigned int)RomInfos.CrcSum);
memarea = GetHiScoresOffsets(&offset1, &offset2);
if (memarea != NULL) {
FileHandler = fopen(SaveScoresFile, "rb");
if (FileHandler != NULL) {
for (UintVar = offset1; UintVar <= offset2; UintVar++) {
memarea[UintVar] = fgetc(FileHandler);
SaveScoresWriteProtection[UintVar - offset1] = UintVar;
HiScoreCheckSum += memarea[UintVar];
}
/* Check if hiscores haven't been modified by a cheater * /
SavedCheckSum = ((unsigned int) fgetc(FileHandler) << 24);
SavedCheckSum |= ((unsigned int) fgetc(FileHandler) << 16);
SavedCheckSum |= ((unsigned int) fgetc(FileHandler) << 8);
SavedCheckSum |= (unsigned int) fgetc(FileHandler);
SavedCheckSum ^= XorKey;
if (HiScoreCheckSum != SavedCheckSum) {
printf("Cksum mismatch on hiscores!\n");
for (UintVar = 0; UintVar < 2048; UintVar++) SaveScoresWriteProtection[UintVar] = 0;
}
/* Close the file * /
fclose(FileHandler);
}
}
*/
}