sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
misc.c
1
/*
2
# _____ ___ ____ ___ ____
3
# ____| | ____| | | |____|
4
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5
#-----------------------------------------------------------------------
6
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7
# Licenced under Academic Free License version 2.0
8
# Review ps2sdk README & LICENSE files for further details.
9
#
10
# Miscellaneous routines
11
*/
12
13
#include <errno.h>
14
#ifdef _IOP
15
#include <
intrman.h
>
16
#include <
cdvdman.h
>
17
#include <
sysclib.h
>
18
#include <
sysmem.h
>
19
#include <
thbase.h
>
20
#else
21
#include <
string.h
>
22
#include <
time.h
>
23
#include <
stdlib.h
>
24
#endif
25
#include <
iomanX.h
>
26
#include <
stdio.h
>
27
#include <
hdd-ioctl.h
>
28
29
#include "
libapa.h
"
30
31
void
*apaAllocMem(
int
size)
32
{
33
#ifdef _IOP
34
int
intrStat;
35
void
*
mem
;
36
37
CpuSuspendIntr
(&intrStat);
38
mem
= AllocSysMemory(ALLOC_FIRST, size, NULL);
39
if
(
mem
== NULL)
40
APA_PRINTF(APA_DRV_NAME
": error: out of memory\n"
);
41
CpuResumeIntr
(intrStat);
42
43
return
mem
;
44
#else
45
return
malloc(size);
46
#endif
47
}
48
49
void
apaFreeMem(
void
*ptr)
50
{
51
#ifdef _IOP
52
int
intrStat;
53
54
CpuSuspendIntr
(&intrStat);
55
FreeSysMemory(ptr);
56
CpuResumeIntr
(intrStat);
57
#else
58
free(ptr);
59
#endif
60
}
61
62
int
apaGetTime(
apa_ps2time_t
*tm)
63
{
64
#ifdef _IOP
65
int
i;
66
sceCdCLOCK
cdtime;
67
static
apa_ps2time_t
timeBuf={
68
0, 7, 6, 5, 4, 3, 2000
// used if can not get time...
69
};
70
71
for
(i = 0; i < 20; i++)
72
{
73
int
ret;
74
75
ret =
sceCdReadClock
(&cdtime);
76
77
if
(ret!=0 && cdtime.
stat
==0)
78
{
79
timeBuf.sec=btoi(cdtime.
second
);
80
timeBuf.min=btoi(cdtime.
minute
);
81
timeBuf.hour=btoi(cdtime.
hour
);
82
timeBuf.day=btoi(cdtime.
day
);
83
timeBuf.month=btoi(cdtime.
month
& 0x7F);
//The old CDVDMAN sceCdReadClock() function does not automatically file off the highest bit.
84
timeBuf.year=btoi(cdtime.
year
) + 2000;
85
break
;
86
}
else
{
87
if
(!(cdtime.
stat
& 0x80))
88
break
;
89
}
90
91
DelayThread(100000);
92
}
93
94
memcpy(tm, &timeBuf,
sizeof
(
apa_ps2time_t
));
95
#else
96
time_t rawtime;
97
struct
tm timeinfo;
98
time(&rawtime);
99
// Convert to JST
100
rawtime += (-9 * 60 * 60);
101
#ifdef _WIN32
102
gmtime_s(&timeinfo, &rawtime);
103
#else
104
gmtime_r(&rawtime, &timeinfo);
105
#endif
106
107
tm->sec = timeinfo.tm_sec;
108
tm->min = timeinfo.tm_min;
109
tm->hour = timeinfo.tm_hour;
110
tm->day = timeinfo.tm_mday;
111
tm->month = timeinfo.tm_mon + 1;
112
tm->year = timeinfo.tm_year + 1900;
113
#endif
114
115
return
0;
116
}
117
118
int
apaGetIlinkID(u8 *idbuf)
119
{
120
#ifdef _IOP
121
u32 stat;
122
int
i;
123
124
for
(i = 0; ; i++)
125
{
126
stat=0;
127
memset(idbuf, 0, 32);
128
if
((
sceCdRI
(idbuf, &stat) != 0) && (stat == 0))
129
{
130
return
0;
131
}
132
133
if
(i >= 20)
134
break
;
135
136
DelayThread(100000);
137
}
138
139
APA_PRINTF(APA_DRV_NAME
": Error: cannot get id\n"
);
140
return
-
EIO
;
141
#else
142
memset(idbuf, 0, 32);
143
return
0;
144
#endif
145
}
cdvdman.h
EIO
#define EIO
Definition
errno.h:38
hdd-ioctl.h
intrman.h
CpuResumeIntr
int CpuResumeIntr(int state)
Definition
intrman.c:217
CpuSuspendIntr
int CpuSuspendIntr(int *state)
Definition
intrman.c:195
iomanX.h
libapa.h
sceCdRI
int sceCdRI(unsigned char *buffer, u32 *result)
Definition
scmd.c:722
sceCdReadClock
int sceCdReadClock(sceCdCLOCK *clock)
Definition
scmd.c:116
stdio.h
stdlib.h
string.h
apa_ps2time_t
Definition
libapa.h:47
mem
Definition
mem.c:336
sceCdCLOCK
Definition
libcdvd-common.h:190
sceCdCLOCK::month
u8 month
Definition
libcdvd-common.h:204
sceCdCLOCK::minute
u8 minute
Definition
libcdvd-common.h:196
sceCdCLOCK::second
u8 second
Definition
libcdvd-common.h:194
sceCdCLOCK::year
u8 year
Definition
libcdvd-common.h:206
sceCdCLOCK::stat
u8 stat
Definition
libcdvd-common.h:192
sceCdCLOCK::hour
u8 hour
Definition
libcdvd-common.h:198
sceCdCLOCK::day
u8 day
Definition
libcdvd-common.h:202
sysclib.h
sysmem.h
thbase.h
time.h
core
apa
src
misc.c
Generated by
1.18.0