1 /*
2  * Copyright (c) 2003,2008 NONAKA Kimihiro
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "common.h"
27 #include "joystick.h"
28 #include "prop.h"
29 #include "keyboard.h"
30 #include "mfp.h"
31 #include "windraw.h"
32 
33 #include "libretro.h"
34 
35 BYTE	KeyBufWP;
36 BYTE	KeyBufRP;
37 BYTE	KeyBuf[KeyBufSize];
38 BYTE	KeyEnable = 1;
39 BYTE	KeyIntFlag = 0;
40 
41 struct keyboard_key kbd_key[] = {
42 #include "keytbl.inc"
43 };
44 
45 extern BYTE traceflag;
46 
47 void
Keyboard_Init(void)48 Keyboard_Init(void)
49 {
50 
51 	KeyBufWP = 0;
52 	KeyBufRP = 0;
53 	ZeroMemory(KeyBuf, KeyBufSize);
54 	KeyEnable = 1;
55 	KeyIntFlag = 0;
56 
57 }
58 
59 // ----------------------------------
60 //	�ơ��֤���
61 // ----------------------------------
62 
63 #define	NC	0
64 #define KEYTABLE_MAX 512
65 
66 
67 BYTE KeyTable[KEYTABLE_MAX] = {
68 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x00
69 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
70 	//	  BS, TAB,    ,    ,    , RET,    ,    		; 0x08
71 		0x0f,0x10,  NC,  NC,  NC,0x1d,  NC,  NC,
72 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x10
73 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
74 	//	    ,    ,    , ESC,    ,    ,    ,    		; 0x18
75 		  NC,  NC,  NC,0x01,  NC,  NC,  NC,  NC,
76 	//	 SPC,  ! ,  " ,  # ,  $ ,  % ,  & ,  '		; 0x20
77 		0x35,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
78 	//	  ( ,  ) ,  * ,  + ,  , ,  - ,  . ,  /		; 0x28
79 		0x09,0x0a,0x28,0x27,0x31,0x0c,0x32,0x33,
80 	//	  0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7		; 0x30
81 		0x0b,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
82 	//	  8 ,  9 ,  ; ,  : ,  < ,  = ,  > ,  ? 		; 0x38
83 		0x09,0x0a,0x28,0x27,0x31,0x0c,0x32,0x33,
84 	//	  @ ,  A ,  B ,  C ,  D ,  E ,  F ,  G		; 0x40
85 		0x1b,0x1e,0x2e,0x2c,0x20,0x13,0x21,0x22,
86 	//	  H ,  I ,  J ,  K ,  L ,  M ,  N ,  O		; 0x48
87 		0x23,0x18,0x24,0x25,0x26,0x30,0x2f,0x10,
88 	//	  P ,  Q ,  R ,  S ,  T ,  U ,  V ,  W		; 0x50
89 		0x1a,0x11,0x14,0x1f,0x15,0x17,0x2d,0x12,
90 	//	  X ,  Y ,  Z ,  [ ,  \ ,  ] ,  ^ ,  _		; 0x58
91 		0x2b,0x16,0x2a,0x1c,0x0e,0x29,0x0d,0x34,
92 	//	  ` ,  a ,  b ,  c ,  d ,  e ,  f ,  g		; 0x60
93 		0x1b,0x1e,0x2e,0x2c,0x20,0x13,0x21,0x22,
94 	//	  h ,  i ,  j ,  k ,  l ,  m ,  n ,  o		; 0x68
95 		0x23,0x18,0x24,0x25,0x26,0x30,0x2f,0x19,
96 	//	  p ,  q ,  r ,  s ,  t ,  u ,  v ,  w		; 0x70
97 		0x1a,0x11,0x14,0x1f,0x15,0x17,0x2d,0x12,
98 	//	  x ,  y ,  z ,  { ,  | ,  } ,  ~ ,   		; 0x78
99 		0x2b,0x16,0x2a,0x1c,0x0e,0x29,0x0d,  NC,
100 	//	    ,    ,    ,    ,    ,    ,    ,  		; 0x80
101 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
102 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0x88
103 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
104 	//	    ,    ,    ,    ,    ,    ,    ,  		; 0x90
105 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
106 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0x98
107 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
108 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xa0
109 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
110 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xa8
111 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
112 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xb0
113 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
114 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xb8
115 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
116 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xc0
117 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
118 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xc8
119 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
120 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xd0
121 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
122 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xd8
123 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
124 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xe0
125 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
126 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xe8
127 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
128 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xf0
129 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
130 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xf8
131 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
132 
133 	//							;0x100
134 
135 	//	    ,    ,    ,    ,    ,    ,    ,  		; 0x00
136 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
137 	//	  BS, TAB,  LF, CLR,    , RET,    ,   		; 0x08
138 		0x0f,0x10,0x1d,  NC,  NC,0x1d,  NC,  NC,
139 	//	    ,  ��,  ��,  ��,  ��,SYSQ,    ,  		; 0x10
140 		  NC,0x3c,0x3e,0x3d,0x3b,  NC,  NC,  NC,
141 	//	    ,    ,    , ESC,    ,    ,    ,   		; 0x18
142 		  NC,  NC,0x63,0x01,  NC,  NC,  NC,  NC,
143 	//	    ,KANJ,MUHE,HENM,HENK,RONM,HIRA,KATA		; 0x20
144 		  NC,  NC,0x56,  NC,  NC,  NC,  NC,  NC,
145 	//	HIKA,ZENK,HANK,ZNHN,    ,KANA,    ,   		; 0x28
146 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
147 	//	SFTL,    ,    ,    ,    ,    ,    ,    		; 0x30
148 		0x70,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
149 	//	    ,    ,    ,    ,    ,ZKOU,MKOU,   		; 0x38
150 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
151 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x40
152 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
153 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0x48
154 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
155 	//	HOME,  ��,  ��,  ��,  ��,RLDN,RLUP, END		; 0x50
156 		0x36,0x3b,0x3c,0x3d,0x3e,0x39,0x38,0x3a,
157 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0x58
158 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
159 	//	    ,PRNT, INS,    ,    ,    ,    ,    		; 0x60
160 		  NC,  NC,0x5e,  NC,  NC,  NC,  NC,  NC,
161 	//	    ,    ,    ,BREA,    ,    ,    ,   		; 0x68
162 		  NC,  NC,  NC,0x61,  NC,  NC,  NC,  NC,
163 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x70
164 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
165 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x78
166 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
167 	//	<SPC,    ,    ,    ,    ,    ,    ,    		; 0x80
168 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
169 	//	    ,<TAB,    ,    ,    ,<ENT,    ,  		; 0x88
170 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
171 	//	    ,    ,    ,    ,    ,<HOM,<��>,<��>		; 0x90
172 		  NC,  NC,  NC,  NC,  NC,0x36,0x3b,0x3c,
173 	//	<��>,<��>,<RDN,<RUP,<END,    ,<INS,<DEL		; 0x98
174 		0x3d,0x3e,0x39,0x38,0x3a,  NC,0x5e,0x37,
175 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xa0
176 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
177 	//	    ,    , <*>, <+>, <,>, <->, <.>, </>		; 0xa8
178 		  NC,  NC,0x41,0x46,  NC,0x42,0x51,0x40,
179 	//	 <0>, <1>, <2>, <3>, <4>, <5>, <6>, <7>		; 0xb0
180 		0x4f,0x4b,0x4c,0x4d,0x47,0x48,0x49,0x43,
181 	//	 <8>, <9>,    ,    ,    ,    , f.1, f.2		; 0xb8
182 		0x44,0x45,  NC,  NC,  NC,  NC,0x63,0x64,
183 	//	 f.3, f.4, f.5, f.6, f.7, f.8, f.9,f.10		; 0xc0
184 		0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,
185 	//	f.11,f.12,f.13,f.14,f.15,    ,    ,   		; 0xc8
186 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
187 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xd0
188 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
189 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xd8
190 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
191 	//	    ,SFTL,SFTR,CTLL,CTLR,CAPS,    ,METL		; 0xe0
192 		  NC,0x70,0x70,0x71,0x71,0x5d,  NC,0x55,
193 	//	METR,ALTL,ALTR,    ,    ,    ,    ,    		; 0xe8
194 		0x55,0x55,0x55,  NC,  NC,  NC,  NC,  NC,
195 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xf0
196 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
197 	//	    ,    ,    ,    ,    ,    ,    , DEL		; 0xf8
198 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,0x37
199 };
200 
201 BYTE KeyTableMaster[KEYTABLE_MAX] = {
202 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x00
203 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
204 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x08
205 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
206 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x10
207 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
208 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x18
209 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
210 	//	 SPC,  ! ,  " ,  # ,  $ ,  % ,  & ,  '		; 0x20
211 		0x35,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
212 	//	  ( ,  ) ,  * ,  + ,  , ,  - ,  . ,  /		; 0x28
213 		0x09,0x0a,0x28,0x27,0x31,0x0c,0x32,0x33,
214 	//	  0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7		; 0x30
215 		0x0b,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
216 	//	  8 ,  9 ,  ; ,  : ,  < ,  = ,  > ,  ? 		; 0x38
217 		0x09,0x0a,0x28,0x27,0x31,0x0c,0x32,0x33,
218 	//	  @ ,  A ,  B ,  C ,  D ,  E ,  F ,  G		; 0x40
219 		0x1b,0x1e,0x2e,0x2c,0x20,0x13,0x21,0x22,
220 	//	  H ,  I ,  J ,  K ,  L ,  M ,  N ,  O		; 0x48
221 		0x23,0x18,0x24,0x25,0x26,0x30,0x2f,0x10,
222 	//	  P ,  Q ,  R ,  S ,  T ,  U ,  V ,  W		; 0x50
223 		0x1a,0x11,0x14,0x1f,0x15,0x17,0x2d,0x12,
224 	//	  X ,  Y ,  Z ,  [ ,  \ ,  ] ,  ^ ,  _		; 0x58
225 		0x2b,0x16,0x2a,0x1c,0x0e,0x29,0x0d,0x34,
226 	//	  ` ,  a ,  b ,  c ,  d ,  e ,  f ,  g		; 0x60
227 		0x1b,0x1e,0x2e,0x2c,0x20,0x13,0x21,0x22,
228 	//	  h ,  i ,  j ,  k ,  l ,  m ,  n ,  o		; 0x68
229 		0x23,0x18,0x24,0x25,0x26,0x30,0x2f,0x19,
230 	//	  p ,  q ,  r ,  s ,  t ,  u ,  v ,  w		; 0x70
231 		0x1a,0x11,0x14,0x1f,0x15,0x17,0x2d,0x12,
232 	//	  x ,  y ,  z ,  { ,  | ,  } ,  ~ ,   		; 0x78
233 		0x2b,0x16,0x2a,0x1c,0x0e,0x29,0x0d,  NC,
234 	//	    ,    ,    ,    ,    ,    ,    ,  		; 0x80
235 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
236 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0x88
237 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
238 	//	    ,    ,    ,    ,    ,    ,    ,  		; 0x90
239 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
240 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0x98
241 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
242 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xa0
243 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
244 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xa8
245 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
246 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xb0
247 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
248 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xb8
249 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
250 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xc0
251 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
252 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xc8
253 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
254 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xd0
255 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
256 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xd8
257 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
258 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xe0
259 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
260 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xe8
261 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
262 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xf0
263 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
264 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xf8
265 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
266 
267 	//							;0x100
268 
269 	//	    ,    ,    ,    ,    ,    ,    ,  		; 0x00
270 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
271 	//	  BS, TAB,  LF, CLR,    , RET,    ,   		; 0x08
272 		0x0f,0x10,0x1d,  NC,  NC,0x1d,  NC,  NC,
273 	//	    ,    ,    ,PAUS,SCRL,SYSQ,    ,  		; 0x10
274 		  NC,  NC,  NC,0x61,  NC,  NC,  NC,  NC,
275 	//	    ,    ,    , ESC,    ,    ,    ,   		; 0x18
276 		  NC,  NC,0x63,0x01,  NC,  NC,  NC,  NC,
277 	//	    ,KANJ,MUHE,HENM,HENK,RONM,HIRA,KATA		; 0x20
278 		  NC,  NC,0x56,  NC,  NC,  NC,  NC,  NC,
279 	//	HIKA,ZENK,HANK,ZNHN,    ,KANA,    ,   		; 0x28
280 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
281 	//	ALNU,    ,    ,    ,    ,    ,    ,    		; 0x30
282 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
283 	//	    ,    ,    ,    ,    ,ZKOU,MKOU,   		; 0x38
284 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
285 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x40
286 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
287 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0x48
288 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
289 	//	HOME,  ��,  ��,  ��,  ��,RLDN,RLUP, END		; 0x50
290 		0x36,  NC,  NC,  NC,  NC,0x39,0x38,0x3a,
291 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0x58
292 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
293 	//	    ,PRNT, INS,    ,    ,    ,    ,    		; 0x60
294 		  NC,  NC,0x5e,  NC,  NC,  NC,  NC,  NC,
295 	//	    ,    ,    ,BREA,    ,    ,    ,   		; 0x68
296 		  NC,  NC,  NC,0x61,  NC,  NC,  NC,  NC,
297 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x70
298 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
299 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0x78
300 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
301 	//	<SPC,    ,    ,    ,    ,    ,    ,    		; 0x80
302 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
303 	//	    ,<TAB,    ,    ,    ,<ENT,    ,  		; 0x88
304 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
305 	//	    ,    ,    ,    ,    ,<HOM,<��>,<��>		; 0x90
306 		  NC,  NC,  NC,  NC,  NC,0x36,  NC,  NC,
307 	//	<��>,<��>,<RDN,<RUP,<END,    ,<INS,<DEL		; 0x98
308 		  NC,  NC,0x39,0x38,0x3a,  NC,0x5e,0x37,
309 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xa0
310 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
311 	//	    ,    , <*>, <+>, <,>, <->, <.>, </>		; 0xa8
312 		  NC,  NC,0x41,0x46,  NC,0x42,  NC,0x40,
313 	//	 <0>, <1>, <2>, <3>, <4>, <5>, <6>, <7>		; 0xb0
314 		0x4f,0x4b,0x4c,0x4d,0x47,0x48,0x49,0x43,
315 	//	 <8>, <9>,    ,    ,    ,    , f.1, f.2		; 0xb8
316 		0x44,0x45,  NC,  NC,  NC,  NC,0x63,0x64,
317 	//	 f.3, f.4, f.5, f.6, f.7, f.8, f.9,f.10		; 0xc0
318 		0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,
319 	//	f.11,f.12,f.13,f.14,f.15,    ,    ,   		; 0xc8
320 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
321 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xd0
322 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
323 	//	    ,    ,    ,    ,    ,    ,    ,   		; 0xd8
324 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
325 	//	    ,SFTL,SFTR,CTLL,CTLR,CAPS,    ,METL		; 0xe0
326 		  NC,0x70,0x70,0x71,0x71,0x5d,  NC,0x55,
327 	//	METR,ALTL,ALTR,    ,    ,    ,    ,    		; 0xe8
328 		0x55,0x55,0x55,  NC,  NC,  NC,  NC,  NC,
329 	//	    ,    ,    ,    ,    ,    ,    ,    		; 0xf0
330 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,  NC,
331 	//	    ,    ,    ,    ,    ,    ,    , DEL		; 0xf8
332 		  NC,  NC,  NC,  NC,  NC,  NC,  NC,0x37
333 };
334 
335 // P6K: PX68K_KEYBOARD
336 //      ~ ~   ~
337 #define P6K_UP 1
338 #define P6K_DOWN 2
339 
send_keycode(BYTE code,int flag)340 void send_keycode(BYTE code, int flag)
341 {
342 	BYTE newwp;
343 
344 	if (code != NC) {
345 		newwp = ((KeyBufWP + 1) & (KeyBufSize - 1));
346 		if (newwp != KeyBufRP) {
347 			KeyBuf[KeyBufWP] = code | ((flag == P6K_UP)? 0x80 : 0);
348 #ifdef DEBUG
349 			p6logd("KeyBuf: %x\n", KeyBuf[KeyBufWP]);
350 #endif
351 			KeyBufWP = newwp;
352 #ifdef DEBUG
353 			p6logd("KeyBufWP: %d\n", KeyBufWP);
354 #endif
355 		}
356 	}
357 }
358 
get_x68k_keycode(DWORD wp)359 static BYTE get_x68k_keycode(DWORD wp)
360 {
361 	if (wp < KEYTABLE_MAX/2) {
362 		return KeyTable[wp];
363 	}
364 
365 	switch (wp) {
366 	case RETROK_UP:
367 		return 0x3c;
368 	case RETROK_DOWN:
369 		return 0x3e;
370 	case RETROK_LEFT:
371 		return 0x3b;
372 	case RETROK_RIGHT:
373 		return 0x3d;
374 
375 #define RETROK_KP_0 RETROK_KP0
376 #define RETROK_KP_1 RETROK_KP1
377 #define RETROK_KP_2 RETROK_KP2
378 #define RETROK_KP_3 RETROK_KP3
379 #define RETROK_KP_4 RETROK_KP4
380 #define RETROK_KP_5 RETROK_KP5
381 #define RETROK_KP_6 RETROK_KP6
382 #define RETROK_KP_7 RETROK_KP7
383 #define RETROK_KP_8 RETROK_KP8
384 #define RETROK_KP_9 RETROK_KP9
385 #define RETROK_NUMLOCKCLEAR RETROK_NUMLOCK
386 
387 	case RETROK_KP_0:
388 		return 0x4f;
389 	case RETROK_KP_1:
390 		return 0x4b;
391 	case RETROK_KP_2:
392 		return 0x4c;
393 	case RETROK_KP_3:
394 		return 0x4d;
395 	case RETROK_KP_4:
396 		return 0x47;
397 	case RETROK_KP_5:
398 		return 0x48;
399 	case RETROK_KP_6:
400 		return 0x49;
401 	case RETROK_KP_7:
402 		return 0x43;
403 	case RETROK_KP_8:
404 		return 0x44;
405 	case RETROK_KP_9:
406 		return 0x45;
407 	case RETROK_NUMLOCKCLEAR:
408 		return 0x3f;
409 
410 	case RETROK_F1:
411 		return 0x63;
412 	case RETROK_F2:
413 		return 0x64;
414 	case RETROK_F3:
415 		return 0x65;
416 	case RETROK_F4:
417 		return 0x66;
418 	case RETROK_F5:
419 		return 0x67;
420 	case RETROK_F6:
421 		return 0x68;
422 	case RETROK_F7:
423 		return 0x69;
424 	case RETROK_F8:
425 		return 0x6a;
426 	case RETROK_F9:
427 		return 0x6b;
428 	case RETROK_F10:
429 		return 0x6c;
430 	case RETROK_LSHIFT:
431 	case RETROK_RSHIFT:
432 		return 0x70;
433 	case RETROK_LCTRL:
434 	case RETROK_RCTRL:
435 		return 0x71;
436 	case RETROK_KP_DIVIDE:
437 		return 0x40;
438 	case RETROK_KP_MULTIPLY:
439 		return 0x41;
440 	case RETROK_KP_MINUS:
441 		return 0x42;
442 	case RETROK_KP_PLUS:
443 		return 0x46;
444 	case RETROK_KP_ENTER:
445 		return 0x4e;
446 	case RETROK_INSERT:
447 		return 0x5e;
448 	case RETROK_HOME:
449 		return 0x36;
450 	case RETROK_END:
451 		return 0x3a;
452 	case RETROK_PAGEUP:
453 		return 0x38;
454 	case RETROK_PAGEDOWN:
455 		return 0x39;
456 	default:
457 		return -1;
458 	}
459 }
460 
461 // ----------------------------------
462 //	WM_KEYDOWN��
463 // ----------------------------------
464 void
Keyboard_KeyDown(DWORD wp)465 Keyboard_KeyDown(DWORD wp)
466 {
467 
468 	BYTE code;
469 	BYTE newwp;
470 #if 0
471 	if (wp & ~0xff) {
472 		if (wp == GDK_VoidSymbol)
473 			code = NC;
474 		else if ((wp & 0xff00) == 0xff00)
475 			code = KeyTable[(wp & 0xff) | 0x100];
476 		else
477 			code = NC;
478 	} else
479 		code = KeyTable[wp & 0xff];
480 #endif
481 	code = get_x68k_keycode(wp);
482 	if (code < 0) {
483 		return;
484 	}
485 
486 	p6logd("Keyboard_KeyDown: ");
487 	p6logd("wp=0x%x, code=0x%x\n", wp, code);
488 //	p6logd("RETROK_UP: 0x%x", RETROK_UP);
489 
490 #if 0
491 	if (code != NC) {
492 		newwp = ((KeyBufWP + 1) & (KeyBufSize - 1));
493 		if (newwp != KeyBufRP) {
494 			KeyBuf[KeyBufWP] = code;
495 			KeyBufWP = newwp;
496 			p6logd("KeyBufWP: %d\n", KeyBufWP);
497 		}
498 	}
499 #else
500 	send_keycode(code, P6K_DOWN);
501 #endif
502 //return;
503 	p6logd("JoyKeyState: 0x%x\n", JoyKeyState);
504 
505 	switch (wp) {
506 	case RETROK_UP:
507 		puts("key up");
508 		if (!(JoyKeyState&JOY_DOWN))
509 			JoyKeyState |= JOY_UP;
510 		break;
511 
512 	case RETROK_DOWN:
513 		if (!(JoyKeyState&JOY_UP))
514 			JoyKeyState |= JOY_DOWN;
515 		break;
516 
517 	case RETROK_LEFT:
518 		if (!(JoyKeyState&JOY_RIGHT))
519 			JoyKeyState |= JOY_LEFT;
520 		break;
521 
522 	case RETROK_RIGHT:
523 		if (!(JoyKeyState&JOY_LEFT))
524 			JoyKeyState |= JOY_RIGHT;
525 		break;
526 	case RETROK_a:
527 		JoyKeyState |= (JOY_LEFT | JOY_RIGHT);	// [RUN]
528 		break;
529 
530 	case RETROK_s:
531 		JoyKeyState |= (JOY_UP | JOY_DOWN);		// [SELECT]
532 		break;
533 
534 	case RETROK_z:
535 		puts("key z");
536 		if (Config.JoyKeyReverse)
537 			JoyKeyState |= JOY_TRG2;
538 		else
539 			JoyKeyState |= JOY_TRG1;
540 		break;
541 
542 	case RETROK_x:
543 		puts("key x");
544 		if (Config.JoyKeyReverse)
545 			JoyKeyState |= JOY_TRG1;
546 		else
547 			JoyKeyState |= JOY_TRG2;
548 		break;
549 	}
550 }
551 
552 // ----------------------------------
553 //	WM_KEYUP
554 // ----------------------------------
555 void
Keyboard_KeyUp(DWORD wp)556 Keyboard_KeyUp(DWORD wp)
557 {
558 	BYTE code;
559 	BYTE newwp;
560 #if 0
561 	if (wp & ~0xff) {
562 		if (wp == GDK_VoidSymbol)
563 			code = NC;
564 		else if ((wp & 0xff00) == 0xff00)
565 			code = KeyTable[(wp & 0xff) | 0x100];
566 		else
567 			code = NC;
568 	} else
569 		code = KeyTable[wp & 0xff];
570 #endif
571 	code = get_x68k_keycode(wp);
572 	if (code < 0) {
573 		return;
574 	}
575 #if 0
576 	if (code != NC) {
577 		newwp = ((KeyBufWP + 1) & (KeyBufSize - 1));
578 		if (newwp != KeyBufRP) {
579 			KeyBuf[KeyBufWP] = code | 0x80;
580 			KeyBufWP = newwp;
581 		}
582 	}
583 #else
584 	send_keycode(code, P6K_UP);
585 #endif
586 //return;
587 	p6logd("JoyKeyState: 0x%x\n", JoyKeyState);
588 
589 	switch(wp) {
590 	case RETROK_UP:
591 		JoyKeyState &= ~JOY_UP;
592 		break;
593 
594 	case RETROK_DOWN:
595 		JoyKeyState &= ~JOY_DOWN;
596 		break;
597 
598 	case RETROK_LEFT:
599 		JoyKeyState &= ~JOY_LEFT;
600 		break;
601 
602 	case RETROK_RIGHT:
603 		JoyKeyState &= ~JOY_RIGHT;
604 		break;
605 
606 	case RETROK_a:
607 		JoyKeyState &= ~(JOY_LEFT | JOY_RIGHT);	// [RUN]
608 		break;
609 
610 	case RETROK_s:
611 		JoyKeyState &= ~(JOY_UP | JOY_DOWN);	// [SELECT]
612 		break;
613 
614 	case RETROK_z:
615 		if (Config.JoyKeyReverse)
616 			JoyKeyState &= ~JOY_TRG2;
617 		else
618 			JoyKeyState &= ~JOY_TRG1;
619 		break;
620 
621 	case RETROK_x:
622 		if (Config.JoyKeyReverse)
623 			JoyKeyState &= ~JOY_TRG1;
624 		else
625 			JoyKeyState &= ~JOY_TRG2;
626 		break;
627 	}
628 
629 }
630 
631 // ----------------------------------
632 //	Key Check
633 //	1�ե졼�����4���2400bps/10bit/60fps�Ȥ���С������˸ƤФ�ơ�MFP�˥ǡ���������
634 // ----------------------------------
635 
636 void
Keyboard_Int(void)637 Keyboard_Int(void)
638 {
639 	if (KeyBufRP != KeyBufWP) {
640 #ifdef DEBUG
641 		p6logd("KeyBufRP:%d, KeyBufWP:%d\n", KeyBufRP, KeyBufWP);
642 #endif
643 		if (!KeyIntFlag) {
644 			LastKey = KeyBuf[KeyBufRP];
645 			KeyBufRP = ((KeyBufRP+1)&(KeyBufSize-1));
646 			KeyIntFlag = 1;
647 			MFP_Int(3);
648 		}
649 	} else if (!KeyIntFlag) {
650 		LastKey = 0;
651 	}
652 }
653 
654 /********** ���եȥ����������ܡ��� **********/
655 
656 
Keyboard_IsSwKeyboard(void)657 int Keyboard_IsSwKeyboard(void)
658 {
659 
660 	return FALSE;
661 
662 }
663