fix P2 DPAD; cosmetics
[d2d-psx.git] / src / keyb.c
blob7003c672fd6c254725b1d18b00007d2ab0c3bffc
1 /*
2 * Copyright (C) Prikol Software 1996-1997
3 * Copyright (C) Aleksey Volynskov 1996-1997
4 * Copyright (C) <ARembo@gmail.com> 2011
5 * Copyright (C) fgsfds 2019
7 * This file is part of the Doom2D PSX project.
9 * Doom2D PSX is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * Doom2D PSX is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/> or
20 * write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "keyb.h"
25 #include <stdlib.h>
27 #include <libetc.h>
28 #include <libpad.h>
30 unsigned int pad_btns = 0;
31 unsigned int pad_trig = 0;
33 static key_f * key_proc = NULL;
35 const char *K_name(int k) {
36 static const char *knames[16] = {
37 "L2",
38 "R2",
39 "L1",
40 "R1",
41 "TRIANGLE",
42 "CIRCLE",
43 "CROSS",
44 "SQUARE",
45 "SELECT",
46 "L3",
47 "R3",
48 "START",
49 "UP",
50 "RIGHT",
51 "DOWN",
52 "LEFT"
54 int i;
55 for (i = 0; i < 32; ++i)
56 if (k & (1 << i))
57 return knames[i & 0xF];
60 void K_init(void) {
61 PadInit(0);
64 void K_done(void) {
65 PadStop();
68 // установить функцию обработки клавиш
69 void K_setkeyproc(key_f * k) {
70 key_proc = k;
73 void K_update(void) {
74 unsigned int pad = PadRead(0);
75 pad_trig = pad & (pad ^ pad_btns);
77 // run keyproc
78 if (key_proc && pad_btns != pad) {
79 unsigned int i, n, new;
80 i = 1;
81 for (n = 0; n < 32; ++n, i <<= 1) {
82 new = pad & i;
83 if (new != (pad_btns & i))
84 key_proc(i, new);
88 pad_btns = pad;