-
Notifications
You must be signed in to change notification settings - Fork 9
/
ps1.c
92 lines (73 loc) · 1.9 KB
/
ps1.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <kernel.h>
#include <sifcmd.h>
#include <libmc.h>
#include "main.h"
#include "ps1.h"
#include "OSDInit.h"
struct PS1DRV
{
char ver[32];
int major;
int minor;
int region;
};
static struct PS1DRV ps1drv = {"", 0, 0, 0};
static char ps1ver_uni[] = "rom0:PS1VER?";
int PS1DRVInit(void)
{
const char *pChar;
int fd, result;
ps1drv.ver[0] = '\0';
fd = _ps2sdk_open("rom0:PS1ID", O_RDONLY);
if (fd < 0)
return -1;
_ps2sdk_read(fd, ps1drv.ver, sizeof(ps1drv.ver));
_ps2sdk_close(fd);
pChar = ps1drv.ver;
ps1drv.major = atoi(pChar);
for (pChar = ps1drv.ver; *pChar >= '0' && *pChar <= '9'; pChar++)
{
};
if (*pChar == '.')
{
ps1drv.minor = atoi(pChar + 1);
for (; *pChar >= '0' && *pChar <= '9'; pChar++)
{
};
result = 0;
ps1drv.region = *pChar;
}
else
{ //Missing dot
ps1drv.region = 0;
ps1drv.major = 0;
ps1drv.minor = 0;
result = -1;
}
if (result == 0)
{
if (OSDGetPS1DRVRegion(&ps1ver_uni[11]) == 0 || (fd = _ps2sdk_open(ps1ver_uni, O_RDONLY)) < 0)
fd = _ps2sdk_open("rom0:PS1VER", O_RDONLY);
if (fd >= 0)
{
result = _ps2sdk_read(fd, ps1drv.ver, sizeof(ps1drv.ver) - 1);
_ps2sdk_close(fd);
//NULL-terminate, only if non-error
ps1drv.ver[result >= 0 ? result : 0] = '\0';
}
}
//The original always returned -1. But we'll return something more meaningful.
return result;
}
const char *PS1DRVGetVersion(void)
{
if (ps1drv.ver[0] == '\0')
{ //rom0:PS1VER is missing (not present in the earliest ROMs)
return (OSDGetConsoleRegion() == CONSOLE_REGION_JAPAN ? "1.01" : "1.10");
}
return ps1drv.ver;
}