-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadrom.c
104 lines (84 loc) · 2.55 KB
/
loadrom.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
/*
loadrom.c --
File loading and management.
*/
#include "shared.h"
char game_name[PATH_MAX];
typedef struct {
uint32 crc;
int mapper;
int display;
int territory;
char *name;
} rominfo_t;
rominfo_t game_list[] = {
{0x29822980, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Cosmic Spacehead"},
{0xB9664AE1, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Fantastic Dizzy"},
{0xA577CE46, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Micro Machines"},
{0x8813514B, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Excellent Dizzy (Proto)"},
{0xAA140C9C, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Excellent Dizzy (Proto - GG)"},
{-1 , -1 , -1, -1, NULL},
};
int load_rom(char *filename)
{
int i;
int size;
if(cart.rom)
{
free(cart.rom);
cart.rom = NULL;
}
if(check_zip(filename))
{
char name[PATH_MAX];
cart.rom = loadFromZipByName(filename, name, &size);
if(!cart.rom) return 0;
strcpy(game_name, name);
}
else
{
FILE *fd = NULL;
fd = fopen(filename, "rb");
if(!fd) return 0;
/* Seek to end of file, and get size */
fseek(fd, 0, SEEK_END);
size = ftell(fd);
fseek(fd, 0, SEEK_SET);
cart.rom = malloc(size);
if(!cart.rom) return 0;
fread(cart.rom, size, 1, fd);
fclose(fd);
}
/* Don't load games smaller than 16K */
if(size < 0x4000) return 0;
/* Take care of image header, if present */
if((size / 512) & 1)
{
size -= 512;
memmove(cart.rom, cart.rom + 512, size);
}
cart.pages = (size / 0x4000);
cart.crc = crc32(0L, cart.rom, size);
/* Assign default settings (US NTSC machine) */
cart.mapper = MAPPER_SEGA;
sms.display = DISPLAY_NTSC;
sms.territory = TERRITORY_EXPORT;
/* Look up mapper in game list */
for(i = 0; game_list[i].name != NULL; i++)
{
if(cart.crc == game_list[i].crc)
{
cart.mapper = game_list[i].mapper;
sms.display = game_list[i].display;
sms.territory = game_list[i].territory;
}
}
/* Figure out game image type */
if(stricmp(strrchr(game_name, '.'), ".gg") == 0)
sms.console = CONSOLE_GG;
else
sms.console = CONSOLE_SMS;
system_assign_device(PORT_A, DEVICE_PAD2B);
system_assign_device(PORT_B, DEVICE_PAD2B);
return 1;
}