src/emu/inptport.c
| r7350 | r7351 | |
| 269 | 269 | UINT32 playback_accumulated_frames;/* accumulated frames during playback */ |
| 270 | 270 | }; |
| 271 | 271 | |
| 272 | | typedef const input_port_config *input_port_config_c; |
| 273 | | typedef const input_field_config *input_field_config_c; |
| 274 | 272 | |
| 275 | | |
| 276 | 273 | typedef struct _inputx_code inputx_code; |
| 277 | 274 | struct _inputx_code |
| 278 | 275 | { |
| 279 | 276 | unicode_char ch; |
| 280 | | input_field_config_c field[NUM_SIMUL_KEYS]; |
| 277 | const input_field_config * field[NUM_SIMUL_KEYS]; |
| 281 | 278 | }; |
| 282 | 279 | |
| 283 | 280 | typedef struct _key_buffer key_buffer; |
| r7350 | r7351 | |
| 1913 | 1910 | return ch; |
| 1914 | 1911 | } |
| 1915 | 1912 | |
| 1913 | /*************************************************************************** |
| 1914 | MISCELLANEOUS |
| 1915 | ***************************************************************************/ |
| 1916 | |
| 1916 | 1917 | /*------------------------------------------------- |
| 1918 | find_charinfo - looks up information about a |
| 1919 | particular character |
| 1920 | -------------------------------------------------*/ |
| 1921 | |
| 1922 | static const char_info *find_charinfo(unicode_char target_char) |
| 1923 | { |
| 1924 | int low = 0; |
| 1925 | int high = ARRAY_LENGTH(charinfo); |
| 1926 | int i; |
| 1927 | unicode_char ch; |
| 1928 | |
| 1929 | /* perform a simple binary search to find the proper alternate */ |
| 1930 | while(high > low) |
| 1931 | { |
| 1932 | i = (high + low) / 2; |
| 1933 | ch = charinfo[i].ch; |
| 1934 | if (ch < target_char) |
| 1935 | low = i + 1; |
| 1936 | else if (ch > target_char) |
| 1937 | high = i; |
| 1938 | else |
| 1939 | return &charinfo[i]; |
| 1940 | } |
| 1941 | return NULL; |
| 1942 | } |
| 1943 | |
| 1944 | /*------------------------------------------------- |
| 1945 | inputx_key_name - returns the name of a |
| 1946 | specific key |
| 1947 | -------------------------------------------------*/ |
| 1948 | |
| 1949 | static const char *inputx_key_name(unicode_char ch) |
| 1950 | { |
| 1951 | static char buf[UTF8_CHAR_MAX + 1]; |
| 1952 | const char_info *ci; |
| 1953 | const char *result; |
| 1954 | int pos; |
| 1955 | |
| 1956 | ci = find_charinfo(ch); |
| 1957 | result = ci ? ci->name : NULL; |
| 1958 | |
| 1959 | if (ci && ci->name) |
| 1960 | { |
| 1961 | result = ci->name; |
| 1962 | } |
| 1963 | else |
| 1964 | { |
| 1965 | if ((ch > 0x7F) || isprint(ch)) |
| 1966 | { |
| 1967 | pos = utf8_from_uchar(buf, ARRAY_LENGTH(buf), ch); |
| 1968 | buf[pos] = '\0'; |
| 1969 | result = buf; |
| 1970 | } |
| 1971 | else |
| 1972 | result = "???"; |
| 1973 | } |
| 1974 | return result; |
| 1975 | } |
| 1976 | |
| 1977 | /*------------------------------------------------- |
| 1917 | 1978 | get_keyboard_key_name - builds the name of |
| 1918 | 1979 | a key based on natural keyboard characters |
| 1919 | 1980 | -------------------------------------------------*/ |
| r7350 | r7351 | |
| 4641 | 4702 | } |
| 4642 | 4703 | } |
| 4643 | 4704 | |
| 4644 | | int input_machine_have_keyboard(running_machine *machine) |
| 4705 | int input_machine_has_keyboard(running_machine *machine) |
| 4645 | 4706 | { |
| 4646 | 4707 | const input_field_config *field; |
| 4647 | 4708 | const input_port_config *port; |
| r7350 | r7351 | |
| 4659 | 4720 | } |
| 4660 | 4721 | |
| 4661 | 4722 | /*************************************************************************** |
| 4662 | | MISCELLANEOUS |
| 4663 | | ***************************************************************************/ |
| 4664 | | |
| 4665 | | /*------------------------------------------------- |
| 4666 | | find_charinfo - looks up information about a |
| 4667 | | particular character |
| 4668 | | -------------------------------------------------*/ |
| 4669 | | |
| 4670 | | static const char_info *find_charinfo(unicode_char target_char) |
| 4671 | | { |
| 4672 | | int low = 0; |
| 4673 | | int high = ARRAY_LENGTH(charinfo); |
| 4674 | | int i; |
| 4675 | | unicode_char ch; |
| 4676 | | |
| 4677 | | /* perform a simple binary search to find the proper alternate */ |
| 4678 | | while(high > low) |
| 4679 | | { |
| 4680 | | i = (high + low) / 2; |
| 4681 | | ch = charinfo[i].ch; |
| 4682 | | if (ch < target_char) |
| 4683 | | low = i + 1; |
| 4684 | | else if (ch > target_char) |
| 4685 | | high = i; |
| 4686 | | else |
| 4687 | | return &charinfo[i]; |
| 4688 | | } |
| 4689 | | return NULL; |
| 4690 | | } |
| 4691 | | |
| 4692 | | |
| 4693 | | |
| 4694 | | /*************************************************************************** |
| 4695 | 4723 | CODE ASSEMBLING |
| 4696 | 4724 | ***************************************************************************/ |
| 4697 | 4725 | |
| r7350 | r7351 | |
| 4747 | 4775 | sets up natural keyboard input mapping |
| 4748 | 4776 | -------------------------------------------------*/ |
| 4749 | 4777 | |
| 4750 | | static int scan_keys(running_machine *machine, const input_port_config *portconfig, inputx_code *codes, input_port_config_c *ports, input_field_config_c *shift_ports, int keys, int shift) |
| 4778 | static int scan_keys(running_machine *machine, const input_port_config *portconfig, inputx_code *codes, const input_port_config * *ports, const input_field_config * *shift_ports, int keys, int shift) |
| 4751 | 4779 | { |
| 4752 | 4780 | int code_count = 0; |
| 4753 | 4781 | const input_port_config *port; |
| r7350 | r7351 | |
| 4911 | 4939 | } |
| 4912 | 4940 | |
| 4913 | 4941 | /* posting keys directly only makes sense for a computer */ |
| 4914 | | if (input_machine_have_keyboard(machine)) |
| 4942 | if (input_machine_has_keyboard(machine)) |
| 4915 | 4943 | { |
| 4916 | 4944 | codes = build_codes(machine, machine->portlist.first()); |
| 4917 | 4945 | setup_keybuffer(machine); |
| r7350 | r7351 | |
| 4980 | 5008 | return 1; |
| 4981 | 5009 | } |
| 4982 | 5010 | |
| 4983 | | |
| 4984 | | |
| 4985 | | int inputx_can_post_key(running_machine *machine, unicode_char ch) |
| 4986 | | { |
| 4987 | | return inputx_can_post(machine) && (can_post_key_directly(ch) || can_post_key_alternate(ch)); |
| 4988 | | } |
| 4989 | | |
| 4990 | | |
| 4991 | | |
| 4992 | 5011 | static attotime choose_delay(unicode_char ch) |
| 4993 | 5012 | { |
| 4994 | 5013 | attoseconds_t delay = 0; |
| r7350 | r7351 | |
| 5046 | 5065 | |
| 5047 | 5066 | |
| 5048 | 5067 | |
| 5049 | | void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate) |
| 5068 | static void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate) |
| 5050 | 5069 | { |
| 5051 | 5070 | int last_cr = 0; |
| 5052 | 5071 | unicode_char ch; |
| r7350 | r7351 | |
| 5147 | 5166 | } |
| 5148 | 5167 | } |
| 5149 | 5168 | |
| 5150 | | /*------------------------------------------------- |
| 5151 | | inputx_key_name - returns the name of a |
| 5152 | | specific key |
| 5153 | | -------------------------------------------------*/ |
| 5154 | | |
| 5155 | | const char *inputx_key_name(unicode_char ch) |
| 5156 | | { |
| 5157 | | static char buf[UTF8_CHAR_MAX + 1]; |
| 5158 | | const char_info *ci; |
| 5159 | | const char *result; |
| 5160 | | int pos; |
| 5161 | | |
| 5162 | | ci = find_charinfo(ch); |
| 5163 | | result = ci ? ci->name : NULL; |
| 5164 | | |
| 5165 | | if (ci && ci->name) |
| 5166 | | { |
| 5167 | | result = ci->name; |
| 5168 | | } |
| 5169 | | else |
| 5170 | | { |
| 5171 | | if ((ch > 0x7F) || isprint(ch)) |
| 5172 | | { |
| 5173 | | pos = utf8_from_uchar(buf, ARRAY_LENGTH(buf), ch); |
| 5174 | | buf[pos] = '\0'; |
| 5175 | | result = buf; |
| 5176 | | } |
| 5177 | | else |
| 5178 | | result = "???"; |
| 5179 | | } |
| 5180 | | return result; |
| 5181 | | } |
| 5182 | | |
| 5183 | | |
| 5184 | | |
| 5185 | | /* --------------------------------------------------------------------- */ |
| 5186 | | |
| 5187 | 5169 | int inputx_is_posting(running_machine *machine) |
| 5188 | 5170 | { |
| 5189 | 5171 | const key_buffer *keybuf; |
| r7350 | r7351 | |
| 5191 | 5173 | return (keybuf->begin_pos != keybuf->end_pos) || (charqueue_empty && !charqueue_empty()); |
| 5192 | 5174 | } |
| 5193 | 5175 | |
| 5194 | | |
| 5195 | | |
| 5196 | 5176 | /*************************************************************************** |
| 5197 | 5177 | |
| 5198 | 5178 | Coded input |
| 5199 | 5179 | |
| 5200 | 5180 | ***************************************************************************/ |
| 5181 | static void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate); |
| 5201 | 5182 | |
| 5202 | | void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate) |
| 5183 | static void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate) |
| 5203 | 5184 | { |
| 5204 | 5185 | size_t i, j, key_len, increment; |
| 5205 | 5186 | unicode_char ch; |
| r7350 | r7351 | |
| 5276 | 5257 | |
| 5277 | 5258 | ***************************************************************************/ |
| 5278 | 5259 | |
| 5279 | | void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len) |
| 5260 | static void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate) |
| 5280 | 5261 | { |
| 5281 | | inputx_postn_rate(machine, text, text_len, attotime_make(0, 0)); |
| 5282 | | } |
| 5283 | | |
| 5284 | | |
| 5285 | | |
| 5286 | | void inputx_post_rate(running_machine *machine, const unicode_char *text, attotime rate) |
| 5287 | | { |
| 5288 | | size_t len = 0; |
| 5289 | | while(text[len]) |
| 5290 | | len++; |
| 5291 | | inputx_postn_rate(machine, text, len, rate); |
| 5292 | | } |
| 5293 | | |
| 5294 | | |
| 5295 | | |
| 5296 | | void inputx_post(running_machine *machine, const unicode_char *text) |
| 5297 | | { |
| 5298 | | inputx_post_rate(machine, text, attotime_make(0, 0)); |
| 5299 | | } |
| 5300 | | |
| 5301 | | |
| 5302 | | |
| 5303 | | void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate) |
| 5304 | | { |
| 5305 | 5262 | inputx_postn_rate(machine, &ch, 1, rate); |
| 5306 | 5263 | } |
| 5307 | 5264 | |
| 5308 | | |
| 5309 | | |
| 5310 | 5265 | void inputx_postc(running_machine *machine, unicode_char ch) |
| 5311 | 5266 | { |
| 5312 | 5267 | inputx_postc_rate(machine, ch, attotime_make(0, 0)); |
| 5313 | 5268 | } |
| 5314 | 5269 | |
| 5315 | | |
| 5316 | | |
| 5317 | | void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate) |
| 5270 | static void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate) |
| 5318 | 5271 | { |
| 5319 | 5272 | size_t len = 0; |
| 5320 | | unicode_char c; |
| 5321 | | utf16_char w1, w2; |
| 5322 | 5273 | unicode_char buf[256]; |
| 5323 | | |
| 5324 | | while(text_len > 0) |
| 5325 | | { |
| 5326 | | if (len == ARRAY_LENGTH(buf)) |
| 5327 | | { |
| 5328 | | inputx_postn(machine, buf, len); |
| 5329 | | len = 0; |
| 5330 | | } |
| 5331 | | |
| 5332 | | w1 = *(text++); |
| 5333 | | text_len--; |
| 5334 | | |
| 5335 | | if ((w1 >= 0xd800) && (w1 <= 0xdfff)) |
| 5336 | | { |
| 5337 | | if (w1 <= 0xDBFF) |
| 5338 | | { |
| 5339 | | w2 = 0; |
| 5340 | | if (text_len > 0) |
| 5341 | | { |
| 5342 | | w2 = *(text++); |
| 5343 | | text_len--; |
| 5344 | | } |
| 5345 | | if ((w2 >= 0xdc00) && (w2 <= 0xdfff)) |
| 5346 | | { |
| 5347 | | c = w1 & 0x03ff; |
| 5348 | | c <<= 10; |
| 5349 | | c |= w2 & 0x03ff; |
| 5350 | | } |
| 5351 | | else |
| 5352 | | { |
| 5353 | | c = INVALID_CHAR; |
| 5354 | | } |
| 5355 | | } |
| 5356 | | else |
| 5357 | | { |
| 5358 | | c = INVALID_CHAR; |
| 5359 | | } |
| 5360 | | } |
| 5361 | | else |
| 5362 | | { |
| 5363 | | c = w1; |
| 5364 | | } |
| 5365 | | buf[len++] = c; |
| 5366 | | } |
| 5367 | | inputx_postn_rate(machine, buf, len, rate); |
| 5368 | | } |
| 5369 | | |
| 5370 | | |
| 5371 | | |
| 5372 | | void inputx_postn_utf16(running_machine *machine, const utf16_char *text, size_t text_len) |
| 5373 | | { |
| 5374 | | inputx_postn_utf16_rate(machine, text, text_len, attotime_make(0, 0)); |
| 5375 | | } |
| 5376 | | |
| 5377 | | |
| 5378 | | |
| 5379 | | void inputx_post_utf16_rate(running_machine *machine, const utf16_char *text, attotime rate) |
| 5380 | | { |
| 5381 | | size_t len = 0; |
| 5382 | | while(text[len]) |
| 5383 | | len++; |
| 5384 | | inputx_postn_utf16_rate(machine, text, len, rate); |
| 5385 | | } |
| 5386 | | |
| 5387 | | |
| 5388 | | |
| 5389 | | void inputx_post_utf16(running_machine *machine, const utf16_char *text) |
| 5390 | | { |
| 5391 | | inputx_post_utf16_rate(machine, text, attotime_make(0, 0)); |
| 5392 | | } |
| 5393 | | |
| 5394 | | |
| 5395 | | |
| 5396 | | void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate) |
| 5397 | | { |
| 5398 | | size_t len = 0; |
| 5399 | | unicode_char buf[256]; |
| 5400 | 5274 | unicode_char c; |
| 5401 | 5275 | int rc; |
| 5402 | 5276 | |
| r7350 | r7351 | |
| 5404 | 5278 | { |
| 5405 | 5279 | if (len == ARRAY_LENGTH(buf)) |
| 5406 | 5280 | { |
| 5407 | | inputx_postn(machine, buf, len); |
| 5281 | inputx_postn_rate(machine, buf, len, attotime_make(0, 0)); |
| 5408 | 5282 | len = 0; |
| 5409 | 5283 | } |
| 5410 | 5284 | |
| r7350 | r7351 | |
| 5421 | 5295 | inputx_postn_rate(machine, buf, len, rate); |
| 5422 | 5296 | } |
| 5423 | 5297 | |
| 5424 | | |
| 5425 | | |
| 5426 | | void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len) |
| 5298 | void inputx_post_utf8(running_machine *machine, const char *text) |
| 5427 | 5299 | { |
| 5428 | | inputx_postn_utf8_rate(machine, text, text_len, attotime_make(0, 0)); |
| 5300 | inputx_postn_utf8_rate(machine, text, strlen(text), attotime_make(0, 0)); |
| 5429 | 5301 | } |
| 5430 | 5302 | |
| 5431 | | |
| 5432 | | |
| 5433 | 5303 | void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate) |
| 5434 | 5304 | { |
| 5435 | 5305 | inputx_postn_utf8_rate(machine, text, strlen(text), rate); |
| 5436 | | } |
| 5306 | } |
| 5437 | 5307 | |
| 5438 | | |
| 5439 | | |
| 5440 | | void inputx_post_utf8(running_machine *machine, const char *text) |
| 5441 | | { |
| 5442 | | inputx_post_utf8_rate(machine, text, attotime_make(0, 0)); |
| 5443 | | } |
| 5444 | | |
| 5445 | | |
| 5446 | | |
| 5447 | | void inputx_post_coded(running_machine *machine, const char *text) |
| 5448 | | { |
| 5449 | | inputx_postn_coded(machine, text, strlen(text)); |
| 5450 | | } |
| 5451 | | |
| 5452 | | |
| 5453 | | |
| 5454 | | void inputx_post_coded_rate(running_machine *machine, const char *text, attotime rate) |
| 5455 | | { |
| 5456 | | inputx_postn_coded_rate(machine, text, strlen(text), rate); |
| 5457 | | } |
| 5458 | | |
| 5459 | | |
| 5460 | | |
| 5461 | | void inputx_postn_coded(running_machine *machine, const char *text, size_t text_len) |
| 5462 | | { |
| 5463 | | inputx_postn_coded_rate(machine, text, text_len, attotime_make(0, 0)); |
| 5464 | | } |
| 5465 | | |
| 5466 | | |
| 5467 | | |
| 5468 | 5308 | /*************************************************************************** |
| 5469 | 5309 | |
| 5470 | 5310 | Other stuff |
| r7350 | r7351 | |
| 5653 | 5493 | |
| 5654 | 5494 | static void execute_input(running_machine *machine, int ref, int params, const char *param[]) |
| 5655 | 5495 | { |
| 5656 | | inputx_post_coded(machine, param[0]); |
| 5496 | inputx_postn_coded_rate(machine, param[0], strlen(param[0]), attotime_make(0, 0)); |
| 5657 | 5497 | } |
| 5658 | 5498 | |
| 5659 | 5499 | |
src/emu/inptport.h
| r7350 | r7351 | |
| 1156 | 1156 | const char *input_port_string_from_token(const input_port_token token); |
| 1157 | 1157 | |
| 1158 | 1158 | /* return TRUE if machine use full keyboard emulation */ |
| 1159 | | int input_machine_have_keyboard(running_machine *machine); |
| 1159 | int input_machine_has_keyboard(running_machine *machine); |
| 1160 | 1160 | |
| 1161 | 1161 | /* these are called by the core; they should not be called from FEs */ |
| 1162 | 1162 | void inputx_init(running_machine *machine); |
| r7350 | r7351 | |
| 1172 | 1172 | |
| 1173 | 1173 | /* these can be called from FEs */ |
| 1174 | 1174 | int inputx_can_post(running_machine *machine); |
| 1175 | | int inputx_can_post_key(running_machine *machine, unicode_char ch); |
| 1176 | | int inputx_is_posting(running_machine *machine); |
| 1177 | | const char *inputx_key_name(unicode_char ch); |
| 1178 | 1175 | |
| 1179 | 1176 | /* various posting functions; can be called from FEs */ |
| 1180 | | void inputx_post(running_machine *machine, const unicode_char *text); |
| 1181 | | void inputx_post_rate(running_machine *machine, const unicode_char *text, attotime rate); |
| 1182 | 1177 | void inputx_postc(running_machine *machine, unicode_char ch); |
| 1183 | | void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate); |
| 1184 | | void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len); |
| 1185 | | void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate); |
| 1186 | | void inputx_post_utf16(running_machine *machine, const utf16_char *text); |
| 1187 | | void inputx_post_utf16_rate(running_machine *machine, const utf16_char *text, attotime rate); |
| 1188 | | void inputx_postn_utf16(running_machine *machine, const utf16_char *text, size_t text_len); |
| 1189 | | void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate); |
| 1190 | 1178 | void inputx_post_utf8(running_machine *machine, const char *text); |
| 1191 | 1179 | void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate); |
| 1192 | | void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len); |
| 1193 | | void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate); |
| 1194 | | void inputx_post_coded(running_machine *machine, const char *text); |
| 1195 | | void inputx_post_coded_rate(running_machine *machine, const char *text, attotime rate); |
| 1196 | | void inputx_postn_coded(running_machine *machine, const char *text, size_t text_len); |
| 1197 | | void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate); |
| 1180 | int inputx_is_posting(running_machine *machine); |
| 1198 | 1181 | |
| 1199 | 1182 | /* miscellaneous functions */ |
| 1200 | 1183 | int input_classify_port(const input_field_config *field); |