sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
libkbd.c
Go to the documentation of this file.
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
15
16
#include <
tamtypes.h
>
17
#include <fcntl.h>
18
#include <
unistd.h
>
19
#include <
ps2sdkapi.h
>
20
#include <
iopcontrol.h
>
21
#include "
libkbd.h
"
22
23
static
int
kbd_fd;
24
static
int
curr_blockmode;
25
static
int
curr_readmode;
26
27
int
PS2KbdInit
(
void
)
28
{
29
if
(HasIopRebootedSinceLastCall())
30
kbd_fd = -1;
31
32
if
(kbd_fd > 0)
/* Already initialised */
33
{
34
return
2;
35
}
36
37
kbd_fd = open(PS2KBD_DEVFILE, O_RDONLY);
38
if
(kbd_fd < 0)
39
{
40
return
0;
41
}
42
curr_blockmode = PS2KBD_NONBLOCKING;
43
curr_readmode = PS2KBD_READMODE_NORMAL;
44
45
return
1;
46
}
47
48
int
PS2KbdRead
(
char
*key)
49
{
50
if
((kbd_fd >= 0) && (curr_readmode == PS2KBD_READMODE_NORMAL))
51
{
52
return
read(kbd_fd, key, 1);
53
}
54
55
return
0;
56
}
57
58
int
PS2KbdReadRaw
(PS2KbdRawKey *key)
59
{
60
if
((kbd_fd >= 0) && (curr_readmode == PS2KBD_READMODE_RAW))
61
{
62
return
read(kbd_fd, key, 2) / 2;
63
}
64
65
return
0;
66
}
67
68
int
PS2KbdSetReadmode
(u32 readmode)
69
{
70
if
((kbd_fd >= 0) && ((u32)curr_readmode != readmode))
71
{
72
curr_readmode = readmode;
73
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_SETREADMODE
, &readmode);
74
}
75
return
0;
76
}
77
78
int
PS2KbdSetBlockingMode
(u32 blockmode)
79
{
80
if
((kbd_fd >= 0) && ((u32)curr_blockmode != blockmode))
81
{
82
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_SETBLOCKMODE
, &blockmode);
83
}
84
85
return
0;
86
}
87
88
int
PS2KbdSetRepeatRate
(u32 repeat)
89
{
90
if
(kbd_fd >= 0)
91
{
92
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_SETREPEATRATE
, &repeat);
93
}
94
return
0;
95
}
96
97
int
PS2KbdSetLeds
(u8 leds)
98
{
99
if
(kbd_fd >= 0)
100
{
101
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_SETLEDS
, &leds);
102
}
103
return
0;
104
}
105
106
int
PS2KbdSetKeymap
(PS2KbdKeyMap *keymaps)
107
{
108
if
(kbd_fd >= 0)
109
{
110
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_SETKEYMAP
, keymaps);
111
}
112
return
0;
113
}
114
115
int
PS2KbdSetCtrlmap
(u8 *ctrlmap)
116
{
117
if
(kbd_fd >= 0)
118
{
119
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_SETCTRLMAP
, ctrlmap);
120
}
121
return
0;
122
}
123
124
int
PS2KbdSetAltmap
(u8 *altmap)
125
{
126
if
(kbd_fd >= 0)
127
{
128
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_SETALTMAP
, altmap);
129
}
130
return
0;
131
}
132
133
int
PS2KbdSetSpecialmap
(u8 *special)
134
{
135
if
(kbd_fd >= 0)
136
{
137
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_SETSPECIALMAP
, special);
138
}
139
return
0;
140
}
141
142
int
PS2KbdFlushBuffer
(
void
)
143
{
144
int
dummy;
145
146
if
(kbd_fd >= 0)
147
{
148
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_FLUSHBUFFER
, &dummy);
149
}
150
return
0;
151
}
152
153
int
PS2KbdResetKeymap
(
void
)
154
{
155
int
dummy;
156
157
if
(kbd_fd >= 0)
158
{
159
return
_ps2sdk_ioctl(kbd_fd,
PS2KBD_IOCTL_RESETKEYMAP
, &dummy);
160
}
161
return
0;
162
}
163
164
int
PS2KbdClose
(
void
)
165
{
166
if
(kbd_fd >= 0)
167
{
168
close(kbd_fd);
169
kbd_fd = -1;
170
}
171
172
return
1;
173
}
PS2KBD_IOCTL_SETREPEATRATE
#define PS2KBD_IOCTL_SETREPEATRATE
Definition
ps2kbd.h:88
PS2KBD_IOCTL_SETALTMAP
#define PS2KBD_IOCTL_SETALTMAP
Definition
ps2kbd.h:94
PS2KBD_IOCTL_SETLEDS
#define PS2KBD_IOCTL_SETLEDS
Definition
ps2kbd.h:86
PS2KBD_IOCTL_SETKEYMAP
#define PS2KBD_IOCTL_SETKEYMAP
Definition
ps2kbd.h:90
PS2KBD_IOCTL_SETREADMODE
#define PS2KBD_IOCTL_SETREADMODE
Definition
ps2kbd.h:84
PS2KBD_IOCTL_SETSPECIALMAP
#define PS2KBD_IOCTL_SETSPECIALMAP
Definition
ps2kbd.h:96
PS2KBD_IOCTL_SETBLOCKMODE
#define PS2KBD_IOCTL_SETBLOCKMODE
Definition
ps2kbd.h:98
PS2KBD_IOCTL_SETCTRLMAP
#define PS2KBD_IOCTL_SETCTRLMAP
Definition
ps2kbd.h:92
PS2KBD_IOCTL_FLUSHBUFFER
#define PS2KBD_IOCTL_FLUSHBUFFER
Definition
ps2kbd.h:100
PS2KBD_IOCTL_RESETKEYMAP
#define PS2KBD_IOCTL_RESETKEYMAP
Definition
ps2kbd.h:102
iopcontrol.h
libkbd.h
PS2KbdInit
int PS2KbdInit(void)
Definition
libkbd.c:27
PS2KbdSetKeymap
int PS2KbdSetKeymap(PS2KbdKeyMap *keymaps)
Definition
libkbd.c:106
PS2KbdFlushBuffer
int PS2KbdFlushBuffer(void)
Definition
libkbd.c:142
PS2KbdSetSpecialmap
int PS2KbdSetSpecialmap(u8 *special)
Definition
libkbd.c:133
PS2KbdSetAltmap
int PS2KbdSetAltmap(u8 *altmap)
Definition
libkbd.c:124
PS2KbdReadRaw
int PS2KbdReadRaw(PS2KbdRawKey *key)
Definition
libkbd.c:58
PS2KbdSetRepeatRate
int PS2KbdSetRepeatRate(u32 repeat)
Definition
libkbd.c:88
PS2KbdSetCtrlmap
int PS2KbdSetCtrlmap(u8 *ctrlmap)
Definition
libkbd.c:115
PS2KbdSetLeds
int PS2KbdSetLeds(u8 leds)
Definition
libkbd.c:97
PS2KbdResetKeymap
int PS2KbdResetKeymap(void)
Definition
libkbd.c:153
PS2KbdRead
int PS2KbdRead(char *key)
Definition
libkbd.c:48
PS2KbdSetReadmode
int PS2KbdSetReadmode(u32 readMode)
Definition
libkbd.c:68
PS2KbdSetBlockingMode
int PS2KbdSetBlockingMode(u32 readMode)
Definition
libkbd.c:78
PS2KbdClose
int PS2KbdClose(void)
Definition
libkbd.c:164
ps2sdkapi.h
tamtypes.h
unistd.h
core
kbd
src
libkbd.c
Generated by
1.18.0