1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #include "engines/icb/p4_generic.h"
29 #include "engines/icb/debug.h"
30 #include "engines/icb/p4.h"
31 #include "engines/icb/player.h"
32 #include "engines/icb/direct_input.h"
33 #include "engines/icb/cluster_manager_pc.h"
34 
35 #include "common/textconsole.h"
36 #include "common/events.h"
37 #include "common/keyboard.h"
38 
39 namespace ICB {
40 
41 bool8 keyboard_buf_scancodes[Common::KEYCODE_LAST];
42 bool8 repeats_scancodes[Common::KEYCODE_LAST];
43 
Init_direct_input()44 void Init_direct_input() {
45 	SetDefaultKeys();
46 }
47 
setKeyState(Common::KeyCode key,bool pressed)48 void setKeyState(Common::KeyCode key, bool pressed) {
49 	if (key >= Common::KEYCODE_LAST)
50 		return;
51 
52 	keyboard_buf_scancodes[key] = pressed;
53 }
54 
Get_DI_key_press()55 uint32 Get_DI_key_press() {
56 	for (uint32 i = 0; i < Common::KEYCODE_LAST; i++) {
57 		if (Read_DI_once_keys(i)) {
58 			return i;
59 		}
60 	}
61 
62 	return 0;
63 }
64 
Clear_DI_key_buffer()65 void Clear_DI_key_buffer() {
66 	for (uint32 i = 0; i < Common::KEYCODE_LAST; i++) {
67 		repeats_scancodes[i] = FALSE8;
68 		keyboard_buf_scancodes[i] = FALSE8;
69 	}
70 }
71 
Read_DI_once_keys(uint32 key)72 bool8 Read_DI_once_keys(uint32 key) {
73 	// in
74 	//      key = keycode
75 
76 	// out
77 	//      0 not pressed down currently
78 	//      1 pressed down
79 
80 	if (key >= Common::KEYCODE_LAST)
81 		return FALSE8;
82 
83 	// set repeat
84 	if (keyboard_buf_scancodes[key] && (repeats_scancodes[key]))
85 		return (0); // key is still pressed so return 0
86 
87 	repeats_scancodes[key] = keyboard_buf_scancodes[key];
88 
89 	return (repeats_scancodes[key]);
90 }
91 
Read_DI_keys(uint32 key)92 bool8 Read_DI_keys(uint32 key) {
93 	// in
94 	//      key = keycode
95 
96 	// out
97 	//      0 not pressed down currently
98 	//      1 pressed down
99 
100 	if (key >= Common::KEYCODE_LAST)
101 		return FALSE8;
102 
103 	// set repeat
104 	repeats_scancodes[key] = keyboard_buf_scancodes[key];
105 
106 	return (repeats_scancodes[key]);
107 }
108 
DI_key_waiting()109 bool8 DI_key_waiting() {
110 	for (uint32 i = 0; i < Common::KEYCODE_LAST; i++) {
111 		if (keyboard_buf_scancodes[i])
112 			return TRUE8;
113 	}
114 
115 	return FALSE8;
116 }
117 
SetDefaultKeys()118 void SetDefaultKeys() {
119 	fire_key = Common::KEYCODE_SPACE;
120 	interact_key = Common::KEYCODE_LCTRL;
121 	inventory_key = Common::KEYCODE_RETURN;
122 	arm_key = Common::KEYCODE_LALT;
123 	remora_key = Common::KEYCODE_r;
124 	crouch_key = Common::KEYCODE_x;
125 	sidestep_key = Common::KEYCODE_LSHIFT;
126 	run_key = Common::KEYCODE_z;
127 	up_key = Common::KEYCODE_UP;
128 	down_key = Common::KEYCODE_DOWN;
129 	left_key = Common::KEYCODE_LEFT;
130 	right_key = Common::KEYCODE_RIGHT;
131 	pause_key = Common::KEYCODE_ESCAPE;
132 }
133 
134 } // End of namespace ICB
135