Subversion Repositories psp

[/] [branches/] [smsplus_adhoc/] [loadrom.c] - Blame information for rev 204

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jack
/*
2
    loadrom.c --
3
    File loading and management.
4
*/
5
 
6
#include "shared.h"
7
 
8
char game_name[PATH_MAX];
9
 
10
typedef struct {
11
    uint32 crc;
12
    int mapper;
13
    int display;
14
    int territory;
15
    char *name;
16
} rominfo_t;
17
 
18
rominfo_t game_list[] = {
19
    {0x29822980, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Cosmic Spacehead"},
20
    {0xB9664AE1, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Fantastic Dizzy"},
21
    {0xA577CE46, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Micro Machines"},
22
    {0x8813514B, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Excellent Dizzy (Proto)"},
23
    {0xAA140C9C, MAPPER_CODIES, DISPLAY_PAL, TERRITORY_EXPORT, "Excellent Dizzy (Proto - GG)"},
24
    {-1        , -1  , NULL},
25
};
26
 
27
int load_rom(char *filename)
28
{
29
    int i;
30
    int size;
31
 
32
    if(cart.rom)
33
    {
34
        free(cart.rom);
35
        cart.rom = NULL;
36
    }
37
 
38
    if(check_zip(filename))
39
    {
40
        char name[PATH_MAX];
41
        cart.rom = loadFromZipByName(filename, name, &size);
42
        if(!cart.rom) return 0;
43
        strcpy(game_name, name);
44
    }
45
    else
46 15 jack
    {
47
        strcpy(game_name, filename);
48
 
49 14 jack
        FILE *fd = NULL;
50
 
51
        fd = fopen(filename, "rb");
52
        if(!fd) return 0;
53
 
54
        /* Seek to end of file, and get size */
55
        fseek(fd, 0, SEEK_END);
56
        size = ftell(fd);
57
        fseek(fd, 0, SEEK_SET);
58
 
59
        cart.rom = malloc(size);
60
        if(!cart.rom) return 0;
61
        fread(cart.rom, size, 1, fd);
62
 
63
        fclose(fd);
64
    }
65
 
66
    /* Don't load games smaller than 16K */
67
    if(size < 0x4000) return 0;
68
 
69
    /* Take care of image header, if present */
70
    if((size / 512) & 1)
71
    {
72
        size -= 512;
73
        memmove(cart.rom, cart.rom + 512, size);
74
    }
75
 
76
    cart.pages = (size / 0x4000);
77
    cart.crc = crc32(0L, cart.rom, size);
78
 
79
    /* Assign default settings (US NTSC machine) */
80
    cart.mapper     = MAPPER_SEGA;
81
    sms.display     = DISPLAY_NTSC;
82
    sms.territory   = TERRITORY_EXPORT;
83
 
84
    /* Look up mapper in game list */
85
    for(i = 0; game_list[i].name != NULL; i++)
86
    {
87
        if(cart.crc == game_list[i].crc)
88
        {
89
            cart.mapper     = game_list[i].mapper;
90
            sms.display     = game_list[i].display;
91
            sms.territory   = game_list[i].territory;
92
        }
93
    }
94
 
95
    /* Figure out game image type */
96
    if(stricmp(strrchr(game_name, '.'), ".gg") == 0)
97
        sms.console = CONSOLE_GG;
98
    else
99
        sms.console = CONSOLE_SMS;
100
 
101
    system_assign_device(PORT_A, DEVICE_PAD2B);
102
    system_assign_device(PORT_B, DEVICE_PAD2B);
103
 
104
    return 1;
105
}
106