src/mess/filemngr.c
| r2888 | r2889 | |
| 28 | 28 | CONSTANTS |
| 29 | 29 | ***************************************************************************/ |
| 30 | 30 | |
| 31 | #define ENABLE_CREATE 0 |
| 32 | |
| 31 | 33 | #define SLOT_EMPTY "[empty slot]" |
| 32 | 34 | #define SLOT_CREATE "[create]" |
| 33 | 35 | |
| r2888 | r2889 | |
| 37 | 39 | TYPE DEFINITIONS |
| 38 | 40 | ***************************************************************************/ |
| 39 | 41 | |
| 42 | /* state of the file creator menu */ |
| 43 | typedef union _filecreator_state filecreator_state; |
| 44 | union _filecreator_state |
| 45 | { |
| 46 | UINT32 i; |
| 47 | struct |
| 48 | { |
| 49 | int selected : 16; |
| 50 | unsigned int is_built : 1; |
| 51 | } s; |
| 52 | }; |
| 53 | |
| 54 | |
| 55 | |
| 56 | /* state of the file selector menu */ |
| 40 | 57 | typedef union _fileselector_state fileselector_state; |
| 41 | 58 | union _fileselector_state |
| 42 | 59 | { |
| r2888 | r2889 | |
| 54 | 71 | LOCAL VARIABLES |
| 55 | 72 | ***************************************************************************/ |
| 56 | 73 | |
| 74 | |
| 75 | |
| 57 | 76 | static const device_config *selected_device; |
| 58 | 77 | static astring *current_directory; |
| 59 | 78 | static astring *current_file; |
| r2888 | r2889 | |
| 65 | 84 | ***************************************************************************/ |
| 66 | 85 | |
| 67 | 86 | /*------------------------------------------------- |
| 87 | code_to_ascii - converts an input_code to its |
| 88 | ASCII equivalent |
| 89 | -------------------------------------------------*/ |
| 90 | |
| 91 | static char code_to_ascii(input_code code) |
| 92 | { |
| 93 | /* code, lower case (w/o shift), upper case (with shift), control */ |
| 94 | static const struct |
| 95 | { |
| 96 | input_code code; |
| 97 | char ch; |
| 98 | char shift_ch; |
| 99 | char ctrl_ch; |
| 100 | } code_to_char_table[] = |
| 101 | { |
| 102 | { KEYCODE_0, '0', ')', 0}, |
| 103 | { KEYCODE_1, '1', '!', 0}, |
| 104 | { KEYCODE_2, '2', '"', 0}, |
| 105 | { KEYCODE_3, '3', '#', 0}, |
| 106 | { KEYCODE_4, '4', '$', 0}, |
| 107 | { KEYCODE_5, '5', '%', 0}, |
| 108 | { KEYCODE_6, '6', '^', 0}, |
| 109 | { KEYCODE_7, '7', '&', 0}, |
| 110 | { KEYCODE_8, '8', '*', 0}, |
| 111 | { KEYCODE_9, '9', '(', 0}, |
| 112 | { KEYCODE_A, 'a', 'A', 1}, |
| 113 | { KEYCODE_B, 'b', 'B', 2}, |
| 114 | { KEYCODE_C, 'c', 'C', 3}, |
| 115 | { KEYCODE_D, 'd', 'D', 4}, |
| 116 | { KEYCODE_E, 'e', 'E', 5}, |
| 117 | { KEYCODE_F, 'f', 'F', 6}, |
| 118 | { KEYCODE_G, 'g', 'G', 7}, |
| 119 | { KEYCODE_H, 'h', 'H', 8}, |
| 120 | { KEYCODE_I, 'i', 'I', 9}, |
| 121 | { KEYCODE_J, 'j', 'J', 10}, |
| 122 | { KEYCODE_K, 'k', 'K', 11}, |
| 123 | { KEYCODE_L, 'l', 'L', 12}, |
| 124 | { KEYCODE_M, 'm', 'M', 13}, |
| 125 | { KEYCODE_N, 'n', 'N', 14}, |
| 126 | { KEYCODE_O, 'o', 'O', 15}, |
| 127 | { KEYCODE_P, 'p', 'P', 16}, |
| 128 | { KEYCODE_Q, 'q', 'Q', 17}, |
| 129 | { KEYCODE_R, 'r', 'R', 18}, |
| 130 | { KEYCODE_S, 's', 'S', 19}, |
| 131 | { KEYCODE_T, 't', 'T', 20}, |
| 132 | { KEYCODE_U, 'u', 'U', 21}, |
| 133 | { KEYCODE_V, 'v', 'V', 22}, |
| 134 | { KEYCODE_W, 'w', 'W', 23}, |
| 135 | { KEYCODE_X, 'x', 'X', 24}, |
| 136 | { KEYCODE_Y, 'y', 'Y', 25}, |
| 137 | { KEYCODE_Z, 'z', 'Z', 26}, |
| 138 | { KEYCODE_OPENBRACE, '[', '{', 27}, |
| 139 | { KEYCODE_BACKSLASH, '\\', '|', 28}, |
| 140 | { KEYCODE_CLOSEBRACE, ']', '}', 29}, |
| 141 | { KEYCODE_TILDE, '^', '~', 30}, |
| 142 | { KEYCODE_BACKSPACE, 127, 127, 31}, |
| 143 | { KEYCODE_COLON, ':', ';', 0}, |
| 144 | { KEYCODE_EQUALS, '=', '+', 0}, |
| 145 | { KEYCODE_MINUS, '-', '_', 0}, |
| 146 | { KEYCODE_STOP, '.', '<', 0}, |
| 147 | { KEYCODE_COMMA, ',', '>', 0}, |
| 148 | { KEYCODE_SLASH, '/', '?', 0}, |
| 149 | { KEYCODE_ENTER, 13, 13, 13}, |
| 150 | { KEYCODE_ESC, 27, 27, 27 } |
| 151 | }; |
| 152 | |
| 153 | int i; |
| 154 | char result = 0; |
| 155 | |
| 156 | for (i = 0; i < ARRAY_LENGTH(code_to_char_table); i++) |
| 157 | { |
| 158 | if (code_to_char_table[i].code == code) |
| 159 | { |
| 160 | if (input_code_pressed(KEYCODE_LCONTROL) || input_code_pressed(KEYCODE_RCONTROL)) |
| 161 | result = code_to_char_table[i].ctrl_ch; |
| 162 | else if (input_code_pressed(KEYCODE_LSHIFT) || input_code_pressed(KEYCODE_RSHIFT)) |
| 163 | result = code_to_char_table[i].shift_ch; |
| 164 | else |
| 165 | result = code_to_char_table[i].ch; |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | return result; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | |
| 174 | /*------------------------------------------------- |
| 175 | poll_keyboard - polls the keyboard and appends |
| 176 | the result to the specified buffer |
| 177 | -------------------------------------------------*/ |
| 178 | |
| 179 | static void poll_keyboard(char *buffer, size_t buffer_length, int (*filter)(unicode_char)) |
| 180 | { |
| 181 | input_code code; |
| 182 | char ascii_char; |
| 183 | int length; |
| 184 | |
| 185 | /* poll keyboard */ |
| 186 | code = input_code_poll_switches(FALSE); |
| 187 | if (code != INPUT_CODE_INVALID) |
| 188 | { |
| 189 | ascii_char = code_to_ascii(code); |
| 190 | |
| 191 | switch (ascii_char) |
| 192 | { |
| 193 | case 0: /* NUL */ |
| 194 | case 13: /* return */ |
| 195 | case 27: /* escape */ |
| 196 | break; |
| 197 | |
| 198 | case 25: /* Ctrl-Y (clear line) */ |
| 199 | buffer[0] = '\0'; |
| 200 | break; |
| 201 | |
| 202 | case 127: /* delete */ |
| 203 | length = strlen(buffer); |
| 204 | if (length > 0) |
| 205 | buffer[length - 1] = '\0'; |
| 206 | break; |
| 207 | |
| 208 | default: |
| 209 | if ((filter == NULL) || (*filter)(ascii_char)) |
| 210 | { |
| 211 | /* got a char - add to string */ |
| 212 | snprintf(buffer + strlen(buffer), buffer_length - strlen(buffer), "%c", ascii_char); |
| 213 | } |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | |
| 220 | |
| 221 | /*------------------------------------------------- |
| 68 | 222 | extra_text_draw_box - generically adds header |
| 69 | 223 | or footer text |
| 70 | 224 | -------------------------------------------------*/ |
| r2888 | r2889 | |
| 133 | 287 | ***************************************************************************/ |
| 134 | 288 | |
| 135 | 289 | /*------------------------------------------------- |
| 290 | is_valid_filename_char - tests to see if a |
| 291 | character is valid in a filename |
| 292 | -------------------------------------------------*/ |
| 293 | |
| 294 | static int is_valid_filename_char(unicode_char ch) |
| 295 | { |
| 296 | /* this should really be in the OSD layer */ |
| 297 | static const char valid_filename_char[] = |
| 298 | { |
| 299 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00-0f */ |
| 300 | 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10-1f */ |
| 301 | 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* !"#$%&'()*+,-./ */ |
| 302 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */ |
| 303 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* @ABCDEFGHIJKLMNO */ |
| 304 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, /* PQRSTUVWXYZ[\]^_ */ |
| 305 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* `abcdefghijklmno */ |
| 306 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, /* pqrstuvwxyz{|}~ */ |
| 307 | }; |
| 308 | return (ch < ARRAY_LENGTH(valid_filename_char)) && valid_filename_char[ch]; |
| 309 | } |
| 310 | |
| 311 | |
| 312 | |
| 313 | /*------------------------------------------------- |
| 314 | file_creator_render_extra - perform our |
| 315 | special rendering |
| 316 | -------------------------------------------------*/ |
| 317 | |
| 318 | static void file_creator_render_extra(const menu_extra *extra, float origx1, float origy1, float origx2, float origy2) |
| 319 | { |
| 320 | extra_text_render(extra, origx1, origy1, origx2, origy2, astring_c(current_directory), NULL); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | |
| 325 | /*------------------------------------------------- |
| 136 | 326 | menu_file_create - file creator menu |
| 137 | 327 | -------------------------------------------------*/ |
| 138 | 328 | |
| 139 | 329 | static UINT32 menu_file_create(running_machine *machine, UINT32 state) |
| 140 | 330 | { |
| 141 | | fatalerror("NYI"); |
| 142 | | return 0; |
| 331 | static char filename_buffer[1024]; |
| 332 | |
| 333 | ui_menu_item item_list[200]; |
| 334 | int menu_items = 0; |
| 335 | filecreator_state fc_state; |
| 336 | UINT32 selected; |
| 337 | int visible_items; |
| 338 | int underscore_pos; |
| 339 | menu_extra extra; |
| 340 | |
| 341 | /* disassemble state */ |
| 342 | fc_state.i = state; |
| 343 | selected = fc_state.s.selected; |
| 344 | |
| 345 | /* is this the first time that we've been called? */ |
| 346 | if (!fc_state.s.is_built) |
| 347 | { |
| 348 | filename_buffer[0] = '\0'; |
| 349 | fc_state.s.is_built = TRUE; |
| 350 | } |
| 351 | |
| 352 | /* add the "[empty slot]" entry */ |
| 353 | memset(&item_list[menu_items], 0, sizeof(item_list[menu_items])); |
| 354 | item_list[menu_items].text = "New Image Name:"; |
| 355 | item_list[menu_items].subtext = filename_buffer; |
| 356 | menu_items++; |
| 357 | |
| 358 | /* add an item for the return */ |
| 359 | memset(&item_list[menu_items], 0, sizeof(item_list[menu_items])); |
| 360 | item_list[menu_items].text = "Return to Prior Menu"; |
| 361 | menu_items++; |
| 362 | |
| 363 | /* compute extras */ |
| 364 | memset(&extra, 0, sizeof(extra)); |
| 365 | extra.top = ui_get_line_height() + 3.0f * UI_BOX_TB_BORDER; |
| 366 | extra.render = file_creator_render_extra; |
| 367 | |
| 368 | /* if we're selecting the file name, poll the keyboard */ |
| 369 | if (selected == 0) |
| 370 | poll_keyboard(filename_buffer, ARRAY_LENGTH(filename_buffer), is_valid_filename_char); |
| 371 | |
| 372 | /* put the underscore in the menu */ |
| 373 | underscore_pos = strlen(filename_buffer); |
| 374 | snprintf(filename_buffer + underscore_pos, ARRAY_LENGTH(filename_buffer) - underscore_pos, "_"); |
| 375 | |
| 376 | /* draw the menu */ |
| 377 | visible_items = ui_menu_draw(item_list, menu_items, selected, &extra); |
| 378 | |
| 379 | /* remove the underscore */ |
| 380 | filename_buffer[underscore_pos] = '\0'; |
| 381 | |
| 382 | /* handle the keys */ |
| 383 | if (ui_menu_generic_keys(machine, &selected, menu_items, visible_items)) |
| 384 | goto done; |
| 385 | |
| 386 | if (input_ui_pressed(machine, IPT_UI_SELECT)) |
| 387 | fatalerror("NYI"); |
| 388 | |
| 389 | done: |
| 390 | fc_state.s.selected = selected; |
| 391 | return fc_state.i; |
| 143 | 392 | } |
| 144 | 393 | |
| 145 | 394 | |
| r2888 | r2889 | |
| 234 | 483 | (*menu_items)++; |
| 235 | 484 | |
| 236 | 485 | info = image_device_getinfo(device->machine->config, device); |
| 237 | | if (0 && info.creatable && !zippath_is_zip(directory)) /* NYI */ |
| 486 | if (ENABLE_CREATE && info.creatable && !zippath_is_zip(directory)) |
| 238 | 487 | { |
| 239 | 488 | /* add the "[create]" entry */ |
| 240 | 489 | memset(&item_list[*menu_items], 0, sizeof(item_list[*menu_items])); |