src/mess/inputx.c
| r2536 | r2537 | |
| 14 | 14 | #include "mame.h" |
| 15 | 15 | |
| 16 | 16 | #ifdef ENABLE_DEBUGGER |
| 17 | #include "deprecat.h" |
| 17 | 18 | #include "debug/debugcon.h" |
| 18 | 19 | #endif /* ENABLE_DEBUGGER */ |
| 19 | 20 | |
| r2536 | r2537 | |
| 685 | 686 | charqueue_empty = charqueue_empty_; |
| 686 | 687 | } |
| 687 | 688 | |
| 688 | | int inputx_can_post(void) |
| 689 | int inputx_can_post(running_machine *machine) |
| 689 | 690 | { |
| 690 | 691 | return queue_chars || codes; |
| 691 | 692 | } |
| 692 | 693 | |
| 693 | | static key_buffer *get_buffer(void) |
| 694 | static key_buffer *get_buffer(running_machine *machine) |
| 694 | 695 | { |
| 695 | | assert(inputx_can_post()); |
| 696 | assert(inputx_can_post(machine)); |
| 696 | 697 | return (key_buffer *) keybuffer; |
| 697 | 698 | } |
| 698 | 699 | |
| r2536 | r2537 | |
| 759 | 760 | |
| 760 | 761 | |
| 761 | 762 | |
| 762 | | int inputx_can_post_key(unicode_char ch) |
| 763 | int inputx_can_post_key(running_machine *machine, unicode_char ch) |
| 763 | 764 | { |
| 764 | | return inputx_can_post() && (can_post_key_directly(ch) || can_post_key_alternate(ch)); |
| 765 | return inputx_can_post(machine) && (can_post_key_directly(ch) || can_post_key_alternate(ch)); |
| 765 | 766 | } |
| 766 | 767 | |
| 767 | 768 | |
| r2536 | r2537 | |
| 795 | 796 | |
| 796 | 797 | |
| 797 | 798 | |
| 798 | | static void internal_post_key(unicode_char ch) |
| 799 | static void internal_post_key(running_machine *machine, unicode_char ch) |
| 799 | 800 | { |
| 800 | 801 | key_buffer *keybuf; |
| 801 | 802 | |
| 802 | | keybuf = get_buffer(); |
| 803 | keybuf = get_buffer(machine); |
| 803 | 804 | |
| 804 | 805 | /* need to start up the timer? */ |
| 805 | 806 | if (keybuf->begin_pos == keybuf->end_pos) |
| r2536 | r2537 | |
| 814 | 815 | |
| 815 | 816 | |
| 816 | 817 | |
| 817 | | static int buffer_full(void) |
| 818 | static int buffer_full(running_machine *machine) |
| 818 | 819 | { |
| 819 | 820 | key_buffer *keybuf; |
| 820 | | keybuf = get_buffer(); |
| 821 | keybuf = get_buffer(machine); |
| 821 | 822 | return ((keybuf->end_pos + 1) % (sizeof(keybuf->buffer) / sizeof(keybuf->buffer[0]))) == keybuf->begin_pos; |
| 822 | 823 | } |
| 823 | 824 | |
| 824 | 825 | |
| 825 | 826 | |
| 826 | | void inputx_postn_rate(const unicode_char *text, size_t text_len, attotime rate) |
| 827 | void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate) |
| 827 | 828 | { |
| 828 | 829 | int last_cr = 0; |
| 829 | 830 | unicode_char ch; |
| r2536 | r2537 | |
| 833 | 834 | |
| 834 | 835 | current_rate = rate; |
| 835 | 836 | |
| 836 | | if (inputx_can_post()) |
| 837 | if (inputx_can_post(machine)) |
| 837 | 838 | { |
| 838 | | while((text_len > 0) && !buffer_full()) |
| 839 | while((text_len > 0) && !buffer_full(machine)) |
| 839 | 840 | { |
| 840 | 841 | ch = *(text++); |
| 841 | 842 | text_len--; |
| r2536 | r2537 | |
| 857 | 858 | if (can_post_key_directly(ch)) |
| 858 | 859 | { |
| 859 | 860 | /* we can post this key in the queue directly */ |
| 860 | | internal_post_key(ch); |
| 861 | internal_post_key(machine, ch); |
| 861 | 862 | } |
| 862 | 863 | else if (can_post_key_alternate(ch)) |
| 863 | 864 | { |
| r2536 | r2537 | |
| 868 | 869 | while(*s) |
| 869 | 870 | { |
| 870 | 871 | s += uchar_from_utf8(&ch, s, strlen(s)); |
| 871 | | internal_post_key(ch); |
| 872 | internal_post_key(machine, ch); |
| 872 | 873 | } |
| 873 | 874 | } |
| 874 | 875 | } |
| r2536 | r2537 | |
| 887 | 888 | key_buffer *keybuf; |
| 888 | 889 | attotime delay; |
| 889 | 890 | |
| 890 | | keybuf = get_buffer(); |
| 891 | keybuf = get_buffer(machine); |
| 891 | 892 | |
| 892 | 893 | if (queue_chars) |
| 893 | 894 | { |
| r2536 | r2537 | |
| 931 | 932 | called from core to allow for natural keyboard |
| 932 | 933 | -------------------------------------------------*/ |
| 933 | 934 | |
| 934 | | void mess_input_port_update_hook(int portnum, UINT32 *digital) |
| 935 | void mess_input_port_update_hook(running_machine *machine, int portnum, UINT32 *digital) |
| 935 | 936 | { |
| 936 | 937 | const key_buffer *keybuf; |
| 937 | 938 | const mess_input_code *code; |
| r2536 | r2537 | |
| 939 | 940 | int i; |
| 940 | 941 | UINT32 value; |
| 941 | 942 | |
| 942 | | if (inputx_can_post()) |
| 943 | if (inputx_can_post(machine)) |
| 943 | 944 | { |
| 944 | | keybuf = get_buffer(); |
| 945 | keybuf = get_buffer(machine); |
| 945 | 946 | |
| 946 | 947 | /* is the key down right now? */ |
| 947 | 948 | if (keybuf->status_keydown && (keybuf->begin_pos != keybuf->end_pos)) |
| r2536 | r2537 | |
| 1035 | 1036 | |
| 1036 | 1037 | /* --------------------------------------------------------------------- */ |
| 1037 | 1038 | |
| 1038 | | int inputx_is_posting(void) |
| 1039 | int inputx_is_posting(running_machine *machine) |
| 1039 | 1040 | { |
| 1040 | 1041 | const key_buffer *keybuf; |
| 1041 | | keybuf = get_buffer(); |
| 1042 | keybuf = get_buffer(machine); |
| 1042 | 1043 | return (keybuf->begin_pos != keybuf->end_pos) || (charqueue_empty && !charqueue_empty()); |
| 1043 | 1044 | } |
| 1044 | 1045 | |
| r2536 | r2537 | |
| 1050 | 1051 | |
| 1051 | 1052 | ***************************************************************************/ |
| 1052 | 1053 | |
| 1053 | | void inputx_postn_coded_rate(const char *text, size_t text_len, attotime rate) |
| 1054 | void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate) |
| 1054 | 1055 | { |
| 1055 | 1056 | size_t i, j, key_len, increment; |
| 1056 | 1057 | unicode_char ch; |
| r2536 | r2537 | |
| 1114 | 1115 | } |
| 1115 | 1116 | |
| 1116 | 1117 | if (ch) |
| 1117 | | inputx_postc_rate(ch, rate); |
| 1118 | inputx_postc_rate(machine, ch, rate); |
| 1118 | 1119 | i += increment; |
| 1119 | 1120 | } |
| 1120 | 1121 | } |
| r2536 | r2537 | |
| 1127 | 1128 | |
| 1128 | 1129 | ***************************************************************************/ |
| 1129 | 1130 | |
| 1130 | | void inputx_postn(const unicode_char *text, size_t text_len) |
| 1131 | void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len) |
| 1131 | 1132 | { |
| 1132 | | inputx_postn_rate(text, text_len, attotime_make(0, 0)); |
| 1133 | inputx_postn_rate(machine, text, text_len, attotime_make(0, 0)); |
| 1133 | 1134 | } |
| 1134 | 1135 | |
| 1135 | 1136 | |
| 1136 | 1137 | |
| 1137 | | void inputx_post_rate(const unicode_char *text, attotime rate) |
| 1138 | void inputx_post_rate(running_machine *machine, const unicode_char *text, attotime rate) |
| 1138 | 1139 | { |
| 1139 | 1140 | size_t len = 0; |
| 1140 | 1141 | while(text[len]) |
| 1141 | 1142 | len++; |
| 1142 | | inputx_postn_rate(text, len, rate); |
| 1143 | inputx_postn_rate(machine, text, len, rate); |
| 1143 | 1144 | } |
| 1144 | 1145 | |
| 1145 | 1146 | |
| 1146 | 1147 | |
| 1147 | | void inputx_post(const unicode_char *text) |
| 1148 | void inputx_post(running_machine *machine, const unicode_char *text) |
| 1148 | 1149 | { |
| 1149 | | inputx_post_rate(text, attotime_make(0, 0)); |
| 1150 | inputx_post_rate(machine, text, attotime_make(0, 0)); |
| 1150 | 1151 | } |
| 1151 | 1152 | |
| 1152 | 1153 | |
| 1153 | 1154 | |
| 1154 | | void inputx_postc_rate(unicode_char ch, attotime rate) |
| 1155 | void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate) |
| 1155 | 1156 | { |
| 1156 | | inputx_postn_rate(&ch, 1, rate); |
| 1157 | inputx_postn_rate(machine, &ch, 1, rate); |
| 1157 | 1158 | } |
| 1158 | 1159 | |
| 1159 | 1160 | |
| 1160 | 1161 | |
| 1161 | | void inputx_postc(unicode_char ch) |
| 1162 | void inputx_postc(running_machine *machine, unicode_char ch) |
| 1162 | 1163 | { |
| 1163 | | inputx_postc_rate(ch, attotime_make(0, 0)); |
| 1164 | inputx_postc_rate(machine, ch, attotime_make(0, 0)); |
| 1164 | 1165 | } |
| 1165 | 1166 | |
| 1166 | 1167 | |
| 1167 | 1168 | |
| 1168 | | void inputx_postn_utf16_rate(const utf16_char *text, size_t text_len, attotime rate) |
| 1169 | void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate) |
| 1169 | 1170 | { |
| 1170 | 1171 | size_t len = 0; |
| 1171 | 1172 | unicode_char c; |
| r2536 | r2537 | |
| 1176 | 1177 | { |
| 1177 | 1178 | if (len == (sizeof(buf) / sizeof(buf[0]))) |
| 1178 | 1179 | { |
| 1179 | | inputx_postn(buf, len); |
| 1180 | inputx_postn(machine, buf, len); |
| 1180 | 1181 | len = 0; |
| 1181 | 1182 | } |
| 1182 | 1183 | |
| r2536 | r2537 | |
| 1215 | 1216 | } |
| 1216 | 1217 | buf[len++] = c; |
| 1217 | 1218 | } |
| 1218 | | inputx_postn_rate(buf, len, rate); |
| 1219 | inputx_postn_rate(machine, buf, len, rate); |
| 1219 | 1220 | } |
| 1220 | 1221 | |
| 1221 | 1222 | |
| 1222 | 1223 | |
| 1223 | | void inputx_postn_utf16(const utf16_char *text, size_t text_len) |
| 1224 | void inputx_postn_utf16(running_machine *machine, const utf16_char *text, size_t text_len) |
| 1224 | 1225 | { |
| 1225 | | inputx_postn_utf16_rate(text, text_len, attotime_make(0, 0)); |
| 1226 | inputx_postn_utf16_rate(machine, text, text_len, attotime_make(0, 0)); |
| 1226 | 1227 | } |
| 1227 | 1228 | |
| 1228 | 1229 | |
| 1229 | 1230 | |
| 1230 | | void inputx_post_utf16_rate(const utf16_char *text, attotime rate) |
| 1231 | void inputx_post_utf16_rate(running_machine *machine, const utf16_char *text, attotime rate) |
| 1231 | 1232 | { |
| 1232 | 1233 | size_t len = 0; |
| 1233 | 1234 | while(text[len]) |
| 1234 | 1235 | len++; |
| 1235 | | inputx_postn_utf16_rate(text, len, rate); |
| 1236 | inputx_postn_utf16_rate(machine, text, len, rate); |
| 1236 | 1237 | } |
| 1237 | 1238 | |
| 1238 | 1239 | |
| 1239 | 1240 | |
| 1240 | | void inputx_post_utf16(const utf16_char *text) |
| 1241 | void inputx_post_utf16(running_machine *machine, const utf16_char *text) |
| 1241 | 1242 | { |
| 1242 | | inputx_post_utf16_rate(text, attotime_make(0, 0)); |
| 1243 | inputx_post_utf16_rate(machine, text, attotime_make(0, 0)); |
| 1243 | 1244 | } |
| 1244 | 1245 | |
| 1245 | 1246 | |
| 1246 | 1247 | |
| 1247 | | void inputx_postn_utf8_rate(const char *text, size_t text_len, attotime rate) |
| 1248 | void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate) |
| 1248 | 1249 | { |
| 1249 | 1250 | size_t len = 0; |
| 1250 | 1251 | unicode_char buf[256]; |
| r2536 | r2537 | |
| 1255 | 1256 | { |
| 1256 | 1257 | if (len == (sizeof(buf) / sizeof(buf[0]))) |
| 1257 | 1258 | { |
| 1258 | | inputx_postn(buf, len); |
| 1259 | inputx_postn(machine, buf, len); |
| 1259 | 1260 | len = 0; |
| 1260 | 1261 | } |
| 1261 | 1262 | |
| r2536 | r2537 | |
| 1269 | 1270 | text_len -= rc; |
| 1270 | 1271 | buf[len++] = c; |
| 1271 | 1272 | } |
| 1272 | | inputx_postn_rate(buf, len, rate); |
| 1273 | inputx_postn_rate(machine, buf, len, rate); |
| 1273 | 1274 | } |
| 1274 | 1275 | |
| 1275 | 1276 | |
| 1276 | 1277 | |
| 1277 | | void inputx_postn_utf8(const char *text, size_t text_len) |
| 1278 | void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len) |
| 1278 | 1279 | { |
| 1279 | | inputx_postn_utf8_rate(text, text_len, attotime_make(0, 0)); |
| 1280 | inputx_postn_utf8_rate(machine, text, text_len, attotime_make(0, 0)); |
| 1280 | 1281 | } |
| 1281 | 1282 | |
| 1282 | 1283 | |
| 1283 | 1284 | |
| 1284 | | void inputx_post_utf8_rate(const char *text, attotime rate) |
| 1285 | void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate) |
| 1285 | 1286 | { |
| 1286 | | inputx_postn_utf8_rate(text, strlen(text), rate); |
| 1287 | inputx_postn_utf8_rate(machine, text, strlen(text), rate); |
| 1287 | 1288 | } |
| 1288 | 1289 | |
| 1289 | 1290 | |
| 1290 | 1291 | |
| 1291 | | void inputx_post_utf8(const char *text) |
| 1292 | void inputx_post_utf8(running_machine *machine, const char *text) |
| 1292 | 1293 | { |
| 1293 | | inputx_post_utf8_rate(text, attotime_make(0, 0)); |
| 1294 | inputx_post_utf8_rate(machine, text, attotime_make(0, 0)); |
| 1294 | 1295 | } |
| 1295 | 1296 | |
| 1296 | 1297 | |
| 1297 | 1298 | |
| 1298 | | void inputx_post_coded(const char *text) |
| 1299 | void inputx_post_coded(running_machine *machine, const char *text) |
| 1299 | 1300 | { |
| 1300 | | inputx_postn_coded(text, strlen(text)); |
| 1301 | inputx_postn_coded(machine, text, strlen(text)); |
| 1301 | 1302 | } |
| 1302 | 1303 | |
| 1303 | 1304 | |
| 1304 | 1305 | |
| 1305 | | void inputx_post_coded_rate(const char *text, attotime rate) |
| 1306 | void inputx_post_coded_rate(running_machine *machine, const char *text, attotime rate) |
| 1306 | 1307 | { |
| 1307 | | inputx_postn_coded_rate(text, strlen(text), rate); |
| 1308 | inputx_postn_coded_rate(machine, text, strlen(text), rate); |
| 1308 | 1309 | } |
| 1309 | 1310 | |
| 1310 | 1311 | |
| 1311 | 1312 | |
| 1312 | | void inputx_postn_coded(const char *text, size_t text_len) |
| 1313 | void inputx_postn_coded(running_machine *machine, const char *text, size_t text_len) |
| 1313 | 1314 | { |
| 1314 | | inputx_postn_coded_rate(text, text_len, attotime_make(0, 0)); |
| 1315 | inputx_postn_coded_rate(machine, text, text_len, attotime_make(0, 0)); |
| 1315 | 1316 | } |
| 1316 | 1317 | |
| 1317 | 1318 | |
| r2536 | r2537 | |
| 1473 | 1474 | #ifdef ENABLE_DEBUGGER |
| 1474 | 1475 | static void execute_input(int ref, int params, const char *param[]) |
| 1475 | 1476 | { |
| 1476 | | inputx_post_coded(param[0]); |
| 1477 | inputx_post_coded(Machine, param[0]); |
| 1477 | 1478 | } |
| 1478 | 1479 | #endif /* ENABLE_DEBUGGER */ |
| 1479 | 1480 | |
src/mess/inputx.h
| r2536 | r2537 | |
| 51 | 51 | |
| 52 | 52 | /* these are called by the core; they should not be called from FEs */ |
| 53 | 53 | void inputx_init(running_machine *machine); |
| 54 | | void mess_input_port_update_hook(int portnum, UINT32 *digital); |
| 54 | void mess_input_port_update_hook(running_machine *machine, int portnum, UINT32 *digital); |
| 55 | 55 | void inputx_handle_mess_extensions(input_port_entry *ipt); |
| 56 | 56 | |
| 57 | 57 | /* called by drivers to setup natural keyboard support */ |
| r2536 | r2537 | |
| 64 | 64 | int inputx_validitycheck(const game_driver *gamedrv, input_port_entry **memory); |
| 65 | 65 | |
| 66 | 66 | /* these can be called from FEs */ |
| 67 | | int inputx_can_post(void); |
| 68 | | int inputx_can_post_key(unicode_char ch); |
| 69 | | int inputx_is_posting(void); |
| 67 | int inputx_can_post(running_machine *machine); |
| 68 | int inputx_can_post_key(running_machine *machine, unicode_char ch); |
| 69 | int inputx_is_posting(running_machine *machine); |
| 70 | 70 | const char *inputx_key_name(unicode_char ch); |
| 71 | 71 | |
| 72 | 72 | /* various posting functions; can be called from FEs */ |
| 73 | | void inputx_post(const unicode_char *text); |
| 74 | | void inputx_post_rate(const unicode_char *text, attotime rate); |
| 75 | | void inputx_postc(unicode_char ch); |
| 76 | | void inputx_postc_rate(unicode_char ch, attotime rate); |
| 77 | | void inputx_postn(const unicode_char *text, size_t text_len); |
| 78 | | void inputx_postn_rate(const unicode_char *text, size_t text_len, attotime rate); |
| 79 | | void inputx_post_utf16(const utf16_char *text); |
| 80 | | void inputx_post_utf16_rate(const utf16_char *text, attotime rate); |
| 81 | | void inputx_postn_utf16(const utf16_char *text, size_t text_len); |
| 82 | | void inputx_postn_utf16_rate(const utf16_char *text, size_t text_len, attotime rate); |
| 83 | | void inputx_post_utf8(const char *text); |
| 84 | | void inputx_post_utf8_rate(const char *text, attotime rate); |
| 85 | | void inputx_postn_utf8(const char *text, size_t text_len); |
| 86 | | void inputx_postn_utf8_rate(const char *text, size_t text_len, attotime rate); |
| 87 | | void inputx_post_coded(const char *text); |
| 88 | | void inputx_post_coded_rate(const char *text, attotime rate); |
| 89 | | void inputx_postn_coded(const char *text, size_t text_len); |
| 90 | | void inputx_postn_coded_rate(const char *text, size_t text_len, attotime rate); |
| 73 | void inputx_post(running_machine *machine, const unicode_char *text); |
| 74 | void inputx_post_rate(running_machine *machine, const unicode_char *text, attotime rate); |
| 75 | void inputx_postc(running_machine *machine, unicode_char ch); |
| 76 | void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate); |
| 77 | void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len); |
| 78 | void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate); |
| 79 | void inputx_post_utf16(running_machine *machine, const utf16_char *text); |
| 80 | void inputx_post_utf16_rate(running_machine *machine, const utf16_char *text, attotime rate); |
| 81 | void inputx_postn_utf16(running_machine *machine, const utf16_char *text, size_t text_len); |
| 82 | void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate); |
| 83 | void inputx_post_utf8(running_machine *machine, const char *text); |
| 84 | void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate); |
| 85 | void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len); |
| 86 | void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate); |
| 87 | void inputx_post_coded(running_machine *machine, const char *text); |
| 88 | void inputx_post_coded_rate(running_machine *machine, const char *text, attotime rate); |
| 89 | void inputx_postn_coded(running_machine *machine, const char *text, size_t text_len); |
| 90 | void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate); |
| 91 | 91 | |
| 92 | 92 | /* miscellaneous functions */ |
| 93 | 93 | int input_classify_port(const input_port_entry *in); |