Fix for initialization of scalos preferences library. Library is now loaded only...
[AROS-Contrib.git] / Games / Bomber / BomberKeyboard.c
blob298adc368106cf97de01a7904aa8135302b3549f
1 //Virtual keycodes
2 #define VK_A 0x20
3 #define VK_B 0x35
4 #define VK_C 0x33
5 #define VK_D 0x22
6 #define VK_E 0x12
7 #define VK_F 0x23
8 #define VK_G 0x24
9 #define VK_H 0x25
10 #define VK_I 0x17
11 #define VK_J 0x26
12 #define VK_K 0x27
13 #define VK_L 0x28
14 #define VK_M 0x37
15 #define VK_N 0x36
16 #define VK_O 0x18
17 #define VK_P 0x19
18 #define VK_Q 0x10
19 #define VK_R 0x13
20 #define VK_S 0x21
21 #define VK_T 0x14
22 #define VK_U 0x1a
23 #define VK_V 0x34
24 #define VK_W 0x11
25 #define VK_X 0x32
26 #define VK_Y 0x31
27 #define VK_Z 0x15
29 #define VK_UP 0x4c
30 #define VK_DOWN 0x4d
31 #define VK_LEFT 0x4f
32 #define VK_RIGHT 0x4e
33 #define VK_CONTROL 0x63
34 #define VK_TAB 0x42
35 #define VK_ESCAPE 0x45
37 //Keyboard variables for each player
38 int ChosenKeys [3 * 5];
39 int Up [5],
40 Down [5],
41 Left [5],
42 Right [5],
43 Fire [5];
44 //Various keys
45 int Esc;
47 //For joystick
48 unsigned int JoyUp, JoyLeft, JoyRight, JoyDown;
49 int JoyAvail;
51 //Initializes the standard keys
52 void InitKeyboard ()
54 ChosenKeys [ 0] = VK_UP;
55 ChosenKeys [ 1] = VK_DOWN;
56 ChosenKeys [ 2] = VK_LEFT;
57 ChosenKeys [ 3] = VK_RIGHT;
58 ChosenKeys [ 4] = VK_CONTROL;
59 ChosenKeys [ 5] = VK_W;
60 ChosenKeys [ 6] = VK_X;
61 ChosenKeys [ 7] = VK_A;
62 ChosenKeys [ 8] = VK_D;
63 ChosenKeys [ 9] = VK_TAB;
64 ChosenKeys [10] = VK_U;
65 ChosenKeys [11] = VK_N;
66 ChosenKeys [12] = VK_H;
67 ChosenKeys [13] = VK_K;
68 ChosenKeys [14] = VK_B;
70 #if !NO_JOY
72 //Get info about joystick axes
73 JoyAvail = (joyGetDevCaps (JOYSTICKID1, &JoyCaps, sizeof (JoyCaps)) == JOYERR_NOERROR);
74 if (JoyAvail) {
75 JoyUp = (JoyCaps.wYmax - JoyCaps.wYmin) * 1 / 6;
76 JoyDown = (JoyCaps.wYmax - JoyCaps.wYmin) * 5 / 6;
77 JoyLeft = (JoyCaps.wXmax - JoyCaps.wXmin) * 1 / 6;
78 JoyRight = (JoyCaps.wXmax - JoyCaps.wXmin) * 5 / 6;
80 #endif
84 //Stores keyboard definition in registry
85 void SaveKeys ()
87 #if 0
88 HKEY KeyHandle;
89 RegCreateKey (HKEY_LOCAL_MACHINE, "Software\\Bomberman", &KeyHandle);
90 RegSetValueEx (KeyHandle, "Keys", 0, REG_BINARY, (LPBYTE)ChosenKeys, 60);
91 RegCloseKey (KeyHandle);
92 #endif
95 //Checks for keyboard input
96 void CheckKeyboard ()
98 #if !NO_JOY
99 JOYINFO JoyInfo;
100 #endif
102 //Player 1
103 Up [0] = GetAsyncKeyState (ChosenKeys [ 0]);
104 Down [0] = GetAsyncKeyState (ChosenKeys [ 1]);
105 Left [0] = GetAsyncKeyState (ChosenKeys [ 2]);
106 Right [0] = GetAsyncKeyState (ChosenKeys [ 3]);
107 Fire [0] = GetAsyncKeyState (ChosenKeys [ 4]);
108 //Player 2
109 Up [1] = GetAsyncKeyState (ChosenKeys [ 5]);
110 Down [1] = GetAsyncKeyState (ChosenKeys [ 6]);
111 Left [1] = GetAsyncKeyState (ChosenKeys [ 7]);
112 Right [1] = GetAsyncKeyState (ChosenKeys [ 8]);
113 Fire [1] = GetAsyncKeyState (ChosenKeys [ 9]);
114 //Player 3
115 Up [2] = GetAsyncKeyState (ChosenKeys [10]);
116 Down [2] = GetAsyncKeyState (ChosenKeys [11]);
117 Left [2] = GetAsyncKeyState (ChosenKeys [12]);
118 Right [2] = GetAsyncKeyState (ChosenKeys [13]);
119 Fire [2] = GetAsyncKeyState (ChosenKeys [14]);
121 #if !NO_JOY
122 //Player 4 - joystick
123 if (JoyAvail) {
124 joyGetPos (JOYSTICKID1, &JoyInfo);
125 Up [3] = (JoyInfo.wYpos < JoyUp);
126 Down [3] = (JoyInfo.wYpos > JoyDown);
127 Left [3] = (JoyInfo.wXpos < JoyLeft);
128 Right [3] = (JoyInfo.wXpos > JoyRight);
129 Fire [3] = (JoyInfo.wButtons & JOY_BUTTON1);
131 #endif
133 Esc = GetAsyncKeyState (VK_ESCAPE);
136 //Flush the keyboard buffer
137 void FlushKeys ()
139 InPointer = OutPointer;
142 //Returns a character
143 char getch ()
145 int t;
147 if (InPointer == OutPointer)
148 return -1;
149 else {
150 t = OutPointer++;
151 OutPointer %= 50;
152 return InBuffer [t];