src/emu/diimage.c
| r13911 | r13912 | |
| 40 | 40 | #include "emu.h" |
| 41 | 41 | #include "ui.h" |
| 42 | 42 | #include "zippath.h" |
| 43 | #include "uimenu.h" |
| 44 | #include "uiimage.h" |
| 45 | #include "uiswlist.h" |
| 43 | 46 | |
| 44 | | |
| 45 | 47 | //************************************************************************** |
| 46 | 48 | // DEVICE CONFIG IMAGE INTERFACE |
| 47 | 49 | //************************************************************************** |
| r13911 | r13912 | |
| 107 | 109 | |
| 108 | 110 | //------------------------------------------------- |
| 109 | 111 | // find_device_type - search trough list of |
| 110 | | // device types to extact data |
| 112 | // device types to extract data |
| 111 | 113 | //------------------------------------------------- |
| 112 | 114 | |
| 113 | 115 | const image_device_type_info *device_image_interface::find_device_type(iodevice_t type) |
| r13911 | r13912 | |
| 1032 | 1034 | m_brief_instance_name = device_brieftypename(image_type()); |
| 1033 | 1035 | } |
| 1034 | 1036 | } |
| 1037 | |
| 1038 | /*------------------------------------------------- |
| 1039 | get_selection_menu - create the menu stack |
| 1040 | for ui-level image selection |
| 1041 | -------------------------------------------------*/ |
| 1042 | |
| 1043 | class ui_menu_control_device_image : public ui_menu { |
| 1044 | public: |
| 1045 | ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *image); |
| 1046 | virtual ~ui_menu_control_device_image(); |
| 1047 | virtual void populate(); |
| 1048 | virtual void handle(); |
| 1049 | |
| 1050 | private: |
| 1051 | enum { |
| 1052 | START_FILE, START_OTHER_PART, START_SOFTLIST, SELECT_PARTLIST, SELECT_ONE_PART, SELECT_OTHER_PART, SELECT_FILE, CREATE_FILE, CREATE_CONFIRM, DO_CREATE, SELECT_SOFTLIST |
| 1053 | }; |
| 1054 | int state; |
| 1055 | |
| 1056 | device_image_interface *image; |
| 1057 | astring current_directory; |
| 1058 | astring current_file; |
| 1059 | int submenu_result; |
| 1060 | bool create_confirmed; |
| 1061 | bool softlist_done; |
| 1062 | const software_list *swl; |
| 1063 | const software_info *swi; |
| 1064 | const software_part *swp; |
| 1065 | const software_list_config *slc; |
| 1066 | astring software_info_name; |
| 1067 | |
| 1068 | void test_create(bool &can_create, bool &need_confirm); |
| 1069 | void load_software_part(); |
| 1070 | }; |
| 1071 | |
| 1072 | ui_menu *device_image_interface::get_selection_menu(running_machine &machine, render_container *container) |
| 1073 | { |
| 1074 | return auto_alloc_clear(machine, ui_menu_control_device_image(machine, container, this)); |
| 1075 | } |
| 1076 | |
| 1077 | ui_menu_control_device_image::ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu(machine, container) |
| 1078 | { |
| 1079 | image = _image; |
| 1080 | |
| 1081 | slc = 0; |
| 1082 | swi = image->software_entry(); |
| 1083 | swp = image->part_entry(); |
| 1084 | |
| 1085 | if(swi) |
| 1086 | { |
| 1087 | state = START_OTHER_PART; |
| 1088 | current_directory.cpy(image->working_directory()); |
| 1089 | } |
| 1090 | else |
| 1091 | { |
| 1092 | state = START_FILE; |
| 1093 | |
| 1094 | /* if the image exists, set the working directory to the parent directory */ |
| 1095 | if (image->exists()) |
| 1096 | { |
| 1097 | current_file.cpy(image->filename()); |
| 1098 | zippath_parent(current_directory, current_file); |
| 1099 | } else |
| 1100 | current_directory.cpy(image->working_directory()); |
| 1101 | |
| 1102 | /* check to see if the path exists; if not clear it */ |
| 1103 | if (zippath_opendir(current_directory, NULL) != FILERR_NONE) |
| 1104 | current_directory.reset(); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | ui_menu_control_device_image::~ui_menu_control_device_image() |
| 1109 | { |
| 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | |
| 1115 | /*------------------------------------------------- |
| 1116 | create_new_image - creates a new disk image |
| 1117 | -------------------------------------------------*/ |
| 1118 | |
| 1119 | void ui_menu_control_device_image::test_create(bool &can_create, bool &need_confirm) |
| 1120 | { |
| 1121 | astring path; |
| 1122 | osd_directory_entry *entry; |
| 1123 | osd_dir_entry_type file_type; |
| 1124 | |
| 1125 | /* assemble the full path */ |
| 1126 | zippath_combine(path, current_directory, current_file); |
| 1127 | |
| 1128 | /* does a file or a directory exist at the path */ |
| 1129 | entry = osd_stat(path); |
| 1130 | file_type = (entry != NULL) ? entry->type : ENTTYPE_NONE; |
| 1131 | if (entry != NULL) |
| 1132 | free(entry); |
| 1133 | |
| 1134 | switch(file_type) |
| 1135 | { |
| 1136 | case ENTTYPE_NONE: |
| 1137 | /* no file/dir here - always create */ |
| 1138 | can_create = true; |
| 1139 | need_confirm = false; |
| 1140 | break; |
| 1141 | |
| 1142 | case ENTTYPE_FILE: |
| 1143 | /* a file exists here - ask for permission from the user */ |
| 1144 | can_create = true; |
| 1145 | need_confirm = true; |
| 1146 | break; |
| 1147 | |
| 1148 | case ENTTYPE_DIR: |
| 1149 | /* a directory exists here - we can't save over it */ |
| 1150 | ui_popup_time(5, "Cannot save over directory"); |
| 1151 | can_create = false; |
| 1152 | need_confirm = false; |
| 1153 | break; |
| 1154 | |
| 1155 | default: |
| 1156 | fatalerror("Unexpected"); |
| 1157 | can_create = false; |
| 1158 | need_confirm = false; |
| 1159 | break; |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | void ui_menu_control_device_image::load_software_part() |
| 1164 | { |
| 1165 | astring temp_name(swi->shortname); |
| 1166 | temp_name.cat(":"); |
| 1167 | temp_name.cat(swp->name); |
| 1168 | image->load(temp_name.cstr()); |
| 1169 | } |
| 1170 | |
| 1171 | void ui_menu_control_device_image::populate() |
| 1172 | { |
| 1173 | } |
| 1174 | |
| 1175 | void ui_menu_control_device_image::handle() |
| 1176 | { |
| 1177 | switch(state) { |
| 1178 | case START_FILE: { |
| 1179 | bool can_create = false; |
| 1180 | if(image->is_creatable()) { |
| 1181 | zippath_directory *directory = NULL; |
| 1182 | file_error err = zippath_opendir(current_directory, &directory); |
| 1183 | can_create = err == FILERR_NONE && !zippath_is_zip(directory); |
| 1184 | if(directory) |
| 1185 | zippath_closedir(directory); |
| 1186 | } |
| 1187 | submenu_result = -1; |
| 1188 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_selector(machine(), container, image, current_directory, current_file, true, true, can_create, &submenu_result))); |
| 1189 | state = SELECT_FILE; |
| 1190 | break; |
| 1191 | } |
| 1192 | |
| 1193 | case START_SOFTLIST: |
| 1194 | slc = 0; |
| 1195 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software(machine(), container, image->image_interface(), &slc))); |
| 1196 | state = SELECT_SOFTLIST; |
| 1197 | break; |
| 1198 | |
| 1199 | case START_OTHER_PART: { |
| 1200 | submenu_result = -1; |
| 1201 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, swi, swp->interface_, &swp, true, &submenu_result))); |
| 1202 | state = SELECT_OTHER_PART; |
| 1203 | break; |
| 1204 | } |
| 1205 | |
| 1206 | case SELECT_SOFTLIST: |
| 1207 | if(!slc) { |
| 1208 | ui_menu::stack_pop(machine()); |
| 1209 | break; |
| 1210 | } |
| 1211 | software_info_name = ""; |
| 1212 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_list(machine(), container, slc, image->image_interface(), software_info_name))); |
| 1213 | state = SELECT_PARTLIST; |
| 1214 | break; |
| 1215 | |
| 1216 | case SELECT_PARTLIST: |
| 1217 | swl = software_list_open(machine().options(), slc->list_name, false, NULL); |
| 1218 | swi = software_list_find(swl, software_info_name, NULL); |
| 1219 | if(swinfo_has_multiple_parts(swi, image->image_interface())) { |
| 1220 | submenu_result = -1; |
| 1221 | swp = 0; |
| 1222 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, swi, image->image_interface(), &swp, false, &submenu_result))); |
| 1223 | state = SELECT_ONE_PART; |
| 1224 | } else { |
| 1225 | image->load(software_info_name); |
| 1226 | software_list_close(swl); |
| 1227 | ui_menu::stack_pop(machine()); |
| 1228 | } |
| 1229 | break; |
| 1230 | |
| 1231 | case SELECT_ONE_PART: |
| 1232 | switch(submenu_result) { |
| 1233 | case ui_menu_software_parts::T_ENTRY: { |
| 1234 | load_software_part(); |
| 1235 | software_list_close(swl); |
| 1236 | ui_menu::stack_pop(machine()); |
| 1237 | break; |
| 1238 | } |
| 1239 | |
| 1240 | case -1: // return to list |
| 1241 | software_list_close(swl); |
| 1242 | state = SELECT_SOFTLIST; |
| 1243 | break; |
| 1244 | |
| 1245 | } |
| 1246 | break; |
| 1247 | |
| 1248 | case SELECT_OTHER_PART: |
| 1249 | switch(submenu_result) { |
| 1250 | case ui_menu_software_parts::T_ENTRY: { |
| 1251 | load_software_part(); |
| 1252 | ui_menu::stack_pop(machine()); |
| 1253 | break; |
| 1254 | } |
| 1255 | |
| 1256 | case ui_menu_software_parts::T_FMGR: |
| 1257 | state = START_FILE; |
| 1258 | handle(); |
| 1259 | break; |
| 1260 | |
| 1261 | case -1: // return to system |
| 1262 | ui_menu::stack_pop(machine()); |
| 1263 | break; |
| 1264 | |
| 1265 | } |
| 1266 | break; |
| 1267 | |
| 1268 | case SELECT_FILE: |
| 1269 | switch(submenu_result) { |
| 1270 | case ui_menu_file_selector::R_EMPTY: |
| 1271 | image->unload(); |
| 1272 | ui_menu::stack_pop(machine()); |
| 1273 | break; |
| 1274 | |
| 1275 | case ui_menu_file_selector::R_FILE: |
| 1276 | image->load(current_file); |
| 1277 | ui_menu::stack_pop(machine()); |
| 1278 | break; |
| 1279 | |
| 1280 | case ui_menu_file_selector::R_CREATE: |
| 1281 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, image, current_directory, current_file))); |
| 1282 | state = CREATE_FILE; |
| 1283 | break; |
| 1284 | |
| 1285 | case ui_menu_file_selector::R_SOFTLIST: |
| 1286 | state = START_SOFTLIST; |
| 1287 | handle(); |
| 1288 | break; |
| 1289 | |
| 1290 | case -1: // return to system |
| 1291 | ui_menu::stack_pop(machine()); |
| 1292 | break; |
| 1293 | } |
| 1294 | break; |
| 1295 | |
| 1296 | case CREATE_FILE: { |
| 1297 | bool can_create, need_confirm; |
| 1298 | test_create(can_create, need_confirm); |
| 1299 | if(can_create) { |
| 1300 | if(need_confirm) { |
| 1301 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, &create_confirmed))); |
| 1302 | state = CREATE_CONFIRM; |
| 1303 | } else { |
| 1304 | astring path; |
| 1305 | zippath_combine(path, current_directory, current_file); |
| 1306 | int err = image->create(path, 0, NULL); |
| 1307 | if (err != 0) |
| 1308 | popmessage("Error: %s", image->error()); |
| 1309 | ui_menu::stack_pop(machine()); |
| 1310 | } |
| 1311 | } else { |
| 1312 | state = START_FILE; |
| 1313 | handle(); |
| 1314 | } |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | case CREATE_CONFIRM: { |
| 1319 | state = create_confirmed ? DO_CREATE : START_FILE; |
| 1320 | handle(); |
| 1321 | break; |
| 1322 | } |
| 1323 | |
| 1324 | case DO_CREATE: { |
| 1325 | astring path; |
| 1326 | zippath_combine(path, current_directory, current_file); |
| 1327 | int err = image->create(path, 0, NULL); |
| 1328 | if (err != 0) |
| 1329 | popmessage("Error: %s", image->error()); |
| 1330 | ui_menu::stack_pop(machine()); |
| 1331 | break; |
| 1332 | } |
| 1333 | } |
| 1334 | } |
src/emu/uiimage.c
| r13911 | r13912 | |
| 149 | 149 | confirm save as menu |
| 150 | 150 | -------------------------------------------------*/ |
| 151 | 151 | |
| 152 | | ui_menu_confirm_save_as::ui_menu_confirm_save_as(running_machine &machine, render_container *container, int *_yes) : ui_menu(machine, container) |
| 152 | ui_menu_confirm_save_as::ui_menu_confirm_save_as(running_machine &machine, render_container *container, bool *_yes) : ui_menu(machine, container) |
| 153 | 153 | { |
| 154 | 154 | yes = _yes; |
| 155 | *yes = false; |
| 155 | 156 | } |
| 156 | 157 | |
| 157 | 158 | ui_menu_confirm_save_as::~ui_menu_confirm_save_as() |
| r13911 | r13912 | |
| 160 | 161 | |
| 161 | 162 | void ui_menu_confirm_save_as::populate() |
| 162 | 163 | { |
| 163 | | item_append("File Already Exists - Overide?", NULL, MENU_FLAG_DISABLE, NULL); |
| 164 | item_append("File Already Exists - Override?", NULL, MENU_FLAG_DISABLE, NULL); |
| 164 | 165 | item_append(MENU_SEPARATOR_ITEM, NULL, MENU_FLAG_DISABLE, NULL); |
| 165 | 166 | item_append("No", NULL, 0, ITEMREF_NO); |
| 166 | 167 | item_append("Yes", NULL, 0, ITEMREF_YES); |
| r13911 | r13912 | |
| 179 | 180 | if ((event != NULL) && (event->iptkey == IPT_UI_SELECT)) |
| 180 | 181 | { |
| 181 | 182 | if (event->itemref == ITEMREF_YES) |
| 182 | | *yes = TRUE; |
| 183 | *yes = true; |
| 183 | 184 | |
| 184 | 185 | /* no matter what, pop out */ |
| 185 | 186 | ui_menu::stack_pop(machine()); |
| r13911 | r13912 | |
| 224 | 225 | void ui_menu_file_create::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) |
| 225 | 226 | { |
| 226 | 227 | extra_text_render(container, top, bottom, origx1, origy1, origx2, origy2, |
| 227 | | manager->current_directory, |
| 228 | current_directory, |
| 228 | 229 | NULL); |
| 229 | 230 | } |
| 230 | 231 | |
| r13911 | r13912 | |
| 235 | 236 | creator menu |
| 236 | 237 | -------------------------------------------------*/ |
| 237 | 238 | |
| 238 | | ui_menu_file_create::ui_menu_file_create(running_machine &machine, render_container *container, ui_menu_file_manager *parent) : ui_menu(machine, container) |
| 239 | ui_menu_file_create::ui_menu_file_create(running_machine &machine, render_container *container, device_image_interface *_image, astring &_current_directory, astring &_current_file) : ui_menu(machine, container), current_directory(_current_directory), current_file(_current_file) |
| 239 | 240 | { |
| 240 | | manager = parent; |
| 241 | image = _image; |
| 241 | 242 | } |
| 242 | 243 | |
| 243 | 244 | ui_menu_file_create::~ui_menu_file_create() |
| r13911 | r13912 | |
| 247 | 248 | void ui_menu_file_create::populate() |
| 248 | 249 | { |
| 249 | 250 | astring buffer; |
| 250 | | device_image_interface *device = manager->selected_device; |
| 251 | 251 | const image_device_format *format; |
| 252 | 252 | const char *new_image_name; |
| 253 | 253 | |
| r13911 | r13912 | |
| 264 | 264 | item_append("New Image Name:", new_image_name, 0, ITEMREF_NEW_IMAGE_NAME); |
| 265 | 265 | |
| 266 | 266 | /* do we support multiple formats? */ |
| 267 | | format = device->device_get_creatable_formats(); |
| 267 | format = image->device_get_creatable_formats(); |
| 268 | 268 | if (ENABLE_FORMATS && (format != NULL)) |
| 269 | 269 | { |
| 270 | 270 | item_append("Image Format:", current_format->m_description, 0, ITEMREF_FORMAT); |
| r13911 | r13912 | |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
| 282 | | |
| 283 | 282 | /*------------------------------------------------- |
| 284 | | create_new_image - creates a new disk image |
| 285 | | -------------------------------------------------*/ |
| 286 | | |
| 287 | | int ui_menu_file_create::create_new_image(device_image_interface *image, const char *directory, const char *filename, int *yes) |
| 288 | | { |
| 289 | | astring path; |
| 290 | | osd_directory_entry *entry; |
| 291 | | osd_dir_entry_type file_type; |
| 292 | | int do_create, err; |
| 293 | | int result = FALSE; |
| 294 | | |
| 295 | | /* assemble the full path */ |
| 296 | | zippath_combine(path, directory, filename); |
| 297 | | |
| 298 | | /* does a file or a directory exist at the path */ |
| 299 | | entry = osd_stat(path); |
| 300 | | file_type = (entry != NULL) ? entry->type : ENTTYPE_NONE; |
| 301 | | if (entry != NULL) |
| 302 | | free(entry); |
| 303 | | |
| 304 | | /* special case */ |
| 305 | | if ((file_type == ENTTYPE_FILE) && *yes) |
| 306 | | file_type = ENTTYPE_NONE; |
| 307 | | |
| 308 | | switch(file_type) |
| 309 | | { |
| 310 | | case ENTTYPE_NONE: |
| 311 | | /* no file/dir here - always create */ |
| 312 | | do_create = TRUE; |
| 313 | | break; |
| 314 | | |
| 315 | | case ENTTYPE_FILE: |
| 316 | | /* a file exists here - ask for permission from the user */ |
| 317 | | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, yes))); |
| 318 | | do_create = FALSE; |
| 319 | | break; |
| 320 | | |
| 321 | | case ENTTYPE_DIR: |
| 322 | | /* a directory exists here - we can't save over it */ |
| 323 | | ui_popup_time(ERROR_MESSAGE_TIME, "Cannot save over directory"); |
| 324 | | do_create = FALSE; |
| 325 | | break; |
| 326 | | |
| 327 | | default: |
| 328 | | fatalerror("Unexpected"); |
| 329 | | do_create = FALSE; |
| 330 | | break; |
| 331 | | } |
| 332 | | |
| 333 | | /* create the image, if appropriate */ |
| 334 | | if (do_create) |
| 335 | | { |
| 336 | | err = image->create(path, 0, NULL); |
| 337 | | if (err != 0) |
| 338 | | popmessage("Error: %s", image->error()); |
| 339 | | else |
| 340 | | result = TRUE; |
| 341 | | } |
| 342 | | |
| 343 | | return result; |
| 344 | | } |
| 345 | | |
| 346 | | |
| 347 | | |
| 348 | | /*------------------------------------------------- |
| 349 | 283 | menu_file_create - file creator menu |
| 350 | 284 | -------------------------------------------------*/ |
| 351 | 285 | |
| 352 | 286 | void ui_menu_file_create::handle() |
| 353 | 287 | { |
| 354 | | const ui_menu_event *event; |
| 355 | | ui_menu_event fake_event; |
| 288 | /* process the menu */ |
| 289 | const ui_menu_event *event = process(0); |
| 356 | 290 | |
| 357 | | if (confirm_save_as_yes) |
| 358 | | { |
| 359 | | /* we just returned from a "confirm save as" dialog and the user said "yes" - fake an event */ |
| 360 | | memset(&fake_event, 0, sizeof(fake_event)); |
| 361 | | fake_event.iptkey = IPT_UI_SELECT; |
| 362 | | fake_event.itemref = ITEMREF_CREATE; |
| 363 | | event = &fake_event; |
| 364 | | } |
| 365 | | else |
| 366 | | { |
| 367 | | /* process the menu */ |
| 368 | | event = process(0); |
| 369 | | } |
| 370 | | |
| 371 | 291 | /* process the event */ |
| 372 | 292 | if (event != NULL) |
| 373 | 293 | { |
| r13911 | r13912 | |
| 377 | 297 | case IPT_UI_SELECT: |
| 378 | 298 | if ((event->itemref == ITEMREF_CREATE) || (event->itemref == ITEMREF_NEW_IMAGE_NAME)) |
| 379 | 299 | { |
| 380 | | if (create_new_image( |
| 381 | | manager->selected_device, |
| 382 | | manager->current_directory, |
| 383 | | filename_buffer, |
| 384 | | &confirm_save_as_yes)) |
| 385 | | { |
| 386 | | /* success - pop out twice to device view */ |
| 387 | | ui_menu::stack_pop(machine()); |
| 388 | | ui_menu::stack_pop(machine()); |
| 389 | | } |
| 300 | current_file.cpy(filename_buffer); |
| 301 | ui_menu::stack_pop(machine()); |
| 390 | 302 | } |
| 391 | 303 | break; |
| 392 | 304 | |
| r13911 | r13912 | |
| 398 | 310 | ARRAY_LENGTH(filename_buffer), |
| 399 | 311 | event->unichar, |
| 400 | 312 | is_valid_filename_char); |
| 313 | reset(UI_MENU_RESET_REMEMBER_POSITION); |
| 401 | 314 | } |
| 402 | 315 | break; |
| 403 | 316 | } |
| r13911 | r13912 | |
| 419 | 332 | { |
| 420 | 333 | extra_text_render(container, top, bottom, |
| 421 | 334 | origx1, origy1, origx2, origy2, |
| 422 | | manager->current_directory, |
| 335 | current_directory, |
| 423 | 336 | NULL); |
| 424 | 337 | } |
| 425 | 338 | |
| r13911 | r13912 | |
| 523 | 436 | } |
| 524 | 437 | |
| 525 | 438 | /* determine the full path */ |
| 526 | | zippath_combine( |
| 527 | | buffer, |
| 528 | | manager->current_directory, |
| 529 | | dirent->name); |
| 439 | zippath_combine(buffer, current_directory, dirent->name); |
| 530 | 440 | |
| 531 | 441 | /* create the file selector entry */ |
| 532 | 442 | entry = append_entry( |
| r13911 | r13912 | |
| 587 | 497 | allocates all menu items for a directory |
| 588 | 498 | -------------------------------------------------*/ |
| 589 | 499 | |
| 590 | | ui_menu_file_selector::ui_menu_file_selector(running_machine &machine, render_container *container, ui_menu_file_manager *parent) : ui_menu(machine, container) |
| 500 | ui_menu_file_selector::ui_menu_file_selector(running_machine &machine, render_container *container, device_image_interface *_image, astring &_current_directory, astring &_current_file, bool _has_empty, bool _has_softlist, bool _has_create, int *_result) : ui_menu(machine, container), current_directory(_current_directory), current_file(_current_file) |
| 591 | 501 | { |
| 592 | | manager = parent; |
| 502 | image = _image; |
| 503 | has_empty = _has_empty; |
| 504 | has_softlist = _has_softlist; |
| 505 | has_create = _has_create; |
| 506 | result = _result; |
| 593 | 507 | } |
| 594 | 508 | |
| 595 | 509 | ui_menu_file_selector::~ui_menu_file_selector() |
| r13911 | r13912 | |
| 605 | 519 | const file_selector_entry *selected_entry = NULL; |
| 606 | 520 | int i; |
| 607 | 521 | const char *volume_name; |
| 608 | | device_image_interface *device = manager->selected_device; |
| 609 | | const char *path = manager->current_directory; |
| 522 | const char *path = current_directory; |
| 610 | 523 | |
| 524 | if(path[0]) |
| 525 | fprintf(stderr, "curdir=%s\n", path); |
| 526 | |
| 611 | 527 | /* open the directory */ |
| 612 | 528 | err = zippath_opendir(path, &directory); |
| 613 | 529 | if (err != FILERR_NONE) |
| r13911 | r13912 | |
| 616 | 532 | /* clear out the menu entries */ |
| 617 | 533 | entrylist = NULL; |
| 618 | 534 | |
| 619 | | /* add the "[empty slot]" entry */ |
| 620 | | append_entry(SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL); |
| 535 | if (has_empty) |
| 536 | { |
| 537 | /* add the "[empty slot]" entry */ |
| 538 | append_entry(SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL); |
| 539 | } |
| 621 | 540 | |
| 622 | | if (device->is_creatable() && !zippath_is_zip(directory)) |
| 541 | if (has_create) |
| 623 | 542 | { |
| 624 | 543 | /* add the "[create]" entry */ |
| 625 | 544 | append_entry(SELECTOR_ENTRY_TYPE_CREATE, NULL, NULL); |
| 626 | 545 | } |
| 627 | 546 | |
| 628 | | /* add the "[software list]" entry */ |
| 629 | | append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL); |
| 547 | if (has_softlist) |
| 548 | /* add the "[software list]" entry */ |
| 549 | append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL); |
| 630 | 550 | |
| 631 | 551 | /* add the drives */ |
| 632 | 552 | i = 0; |
| r13911 | r13912 | |
| 650 | 570 | selected_entry = entry; |
| 651 | 571 | |
| 652 | 572 | /* do we have to select this file? */ |
| 653 | | if (!mame_stricmp(manager->current_file, dirent->name)) |
| 573 | if (!mame_stricmp(current_file, dirent->name)) |
| 654 | 574 | selected_entry = entry; |
| 655 | 575 | } |
| 656 | 576 | } |
| r13911 | r13912 | |
| 671 | 591 | zippath_closedir(directory); |
| 672 | 592 | } |
| 673 | 593 | |
| 674 | | /*------------------------------------------------- |
| 675 | | check_path - performs a quick check to see if |
| 676 | | a path exists |
| 677 | | -------------------------------------------------*/ |
| 678 | 594 | |
| 679 | | static file_error check_path(const char *path) |
| 680 | | { |
| 681 | | return zippath_opendir(path, NULL); |
| 682 | | } |
| 683 | | |
| 684 | | |
| 685 | | |
| 686 | 595 | /*------------------------------------------------- |
| 687 | 596 | menu_file_selector - file selector menu |
| 688 | 597 | -------------------------------------------------*/ |
| r13911 | r13912 | |
| 706 | 615 | { |
| 707 | 616 | case SELECTOR_ENTRY_TYPE_EMPTY: |
| 708 | 617 | /* empty slot - unload */ |
| 709 | | manager->selected_device->unload(); |
| 618 | *result = R_EMPTY; |
| 710 | 619 | ui_menu::stack_pop(machine()); |
| 711 | 620 | break; |
| 712 | 621 | |
| 713 | 622 | case SELECTOR_ENTRY_TYPE_CREATE: |
| 714 | 623 | /* create */ |
| 715 | | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, manager))); |
| 624 | *result = R_CREATE; |
| 625 | ui_menu::stack_pop(machine()); |
| 716 | 626 | break; |
| 717 | 627 | case SELECTOR_ENTRY_TYPE_SOFTWARE_LIST: |
| 718 | | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software(machine(), container, manager->selected_device))); |
| 628 | *result = R_SOFTLIST; |
| 629 | ui_menu::stack_pop(machine()); |
| 719 | 630 | break; |
| 720 | 631 | case SELECTOR_ENTRY_TYPE_DRIVE: |
| 721 | 632 | case SELECTOR_ENTRY_TYPE_DIRECTORY: |
| 722 | 633 | /* drive/directory - first check the path */ |
| 723 | | err = check_path(entry->fullpath); |
| 634 | err = zippath_opendir(entry->fullpath, NULL); |
| 724 | 635 | if (err != FILERR_NONE) |
| 725 | 636 | { |
| 726 | 637 | /* this path is problematic; present the user with an error and bail */ |
| 727 | 638 | ui_popup_time(1, "Error accessing %s", entry->fullpath); |
| 728 | 639 | break; |
| 729 | 640 | } |
| 730 | | manager->current_directory.cpy(entry->fullpath); |
| 641 | current_directory.cpy(entry->fullpath); |
| 731 | 642 | reset((ui_menu_reset_options)0); |
| 732 | 643 | break; |
| 733 | 644 | |
| 734 | 645 | case SELECTOR_ENTRY_TYPE_FILE: |
| 735 | 646 | /* file */ |
| 736 | | manager->selected_device->load(entry->fullpath); |
| 647 | current_file.cpy(entry->fullpath); |
| 648 | *result = R_FILE; |
| 737 | 649 | ui_menu::stack_pop(machine()); |
| 738 | 650 | break; |
| 739 | 651 | } |
| r13911 | r13912 | |
| 830 | 742 | FILE MANAGER |
| 831 | 743 | ***************************************************************************/ |
| 832 | 744 | |
| 833 | | /*------------------------------------------------- |
| 834 | | fix_working_directory - checks the working |
| 835 | | directory for this device to ensure that it |
| 836 | | "makes sense" |
| 837 | | -------------------------------------------------*/ |
| 838 | 745 | |
| 839 | | void ui_menu_file_manager::fix_working_directory(device_image_interface *image) |
| 840 | | { |
| 841 | | /* if the image exists, set the working directory to the parent directory */ |
| 842 | | if (image->exists()) |
| 843 | | { |
| 844 | | astring astr; |
| 845 | | zippath_parent(astr, image->filename()); |
| 846 | | image->set_working_directory(astr); |
| 847 | | } |
| 848 | | |
| 849 | | /* check to see if the path exists; if not clear it */ |
| 850 | | if (check_path(image->working_directory()) != FILERR_NONE) |
| 851 | | image->set_working_directory(""); |
| 852 | | } |
| 853 | | |
| 854 | | |
| 855 | | |
| 856 | 746 | /*------------------------------------------------- |
| 857 | 747 | file_manager_render_extra - perform our |
| 858 | 748 | special rendering |
| r13911 | r13912 | |
| 954 | 844 | selected_device = (device_image_interface *) event->itemref; |
| 955 | 845 | if (selected_device != NULL) |
| 956 | 846 | { |
| 957 | | /* ensure that the working directory for this device exists */ |
| 958 | | fix_working_directory(selected_device); |
| 847 | ui_menu::stack_push(selected_device->get_selection_menu(machine(), container)); |
| 959 | 848 | |
| 960 | | /* set up current_directory and current_file - depends on whether we have an image */ |
| 961 | | current_directory.cpy(selected_device->working_directory()); |
| 962 | | current_file.cpy(selected_device->exists() ? selected_device->basename() : ""); |
| 963 | | |
| 964 | 849 | /* reset the existing menu */ |
| 965 | 850 | reset(UI_MENU_RESET_REMEMBER_POSITION); |
| 966 | | |
| 967 | | /* push the menu */ |
| 968 | | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_selector(machine(), container, this))); |
| 969 | 851 | } |
| 970 | 852 | } |
| 971 | 853 | } |
src/emu/uiswlist.c
| r13911 | r13912 | |
| 28 | 28 | TYPE DEFINITIONS |
| 29 | 29 | ***************************************************************************/ |
| 30 | 30 | |
| 31 | | ui_menu_software_parts::ui_menu_software_parts(running_machine &machine, render_container *container, ui_menu_software_entry_info *_entry) : ui_menu(machine, container) |
| 31 | ui_menu_software_parts::ui_menu_software_parts(running_machine &machine, render_container *container, const software_info *_info, const char *_interface, const software_part **part, bool _opt_fmgr, int *_result) : ui_menu(machine, container) |
| 32 | 32 | { |
| 33 | | entry = _entry; |
| 33 | info = _info; |
| 34 | interface = _interface; |
| 35 | selected_part = part; |
| 36 | opt_fmgr = _opt_fmgr; |
| 37 | result = _result; |
| 34 | 38 | } |
| 35 | 39 | |
| 36 | 40 | void ui_menu_software_parts::populate() |
| 37 | 41 | { |
| 38 | | if(entry->list_name) { |
| 39 | | software_list *list = software_list_open(machine().options(), entry->list_name, false, NULL); |
| 40 | | |
| 41 | | if (list) |
| 42 | for (const software_part *swpart = software_find_part(info, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 43 | { |
| 44 | if (strcmp(interface, swpart->interface_) == 0) |
| 42 | 45 | { |
| 43 | | software_info *info = software_list_find(list, entry->short_name, NULL); |
| 44 | | |
| 45 | | if (info) |
| 46 | software_part_menu_entry *entry = (software_part_menu_entry *) m_pool_alloc(sizeof(*entry)); |
| 47 | // check if the available parts have specific part_id to be displayed (e.g. "Map Disc", "Bonus Disc", etc.) |
| 48 | // if not, we simply display "part_name"; if yes we display "part_name (part_id)" |
| 49 | astring menu_part_name(swpart->name); |
| 50 | if (software_part_get_feature(swpart, "part_id") != NULL) |
| 46 | 51 | { |
| 47 | | for (software_part *swpart = software_find_part(info, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 48 | | { |
| 49 | | if (strcmp(entry->interface, swpart->interface_) == 0) |
| 50 | | { |
| 51 | | software_part_info *entry = (software_part_info *) m_pool_alloc(sizeof(*entry)); |
| 52 | | // check if the available parts have specific part_id to be displayed (e.g. "Map Disc", "Bonus Disc", etc.) |
| 53 | | // if not, we simply display "part_name"; if yes we display "part_name (part_id)" |
| 54 | | astring menu_part_name(swpart->name); |
| 55 | | if (software_part_get_feature(swpart, "part_id") != NULL) |
| 56 | | { |
| 57 | | menu_part_name.cat(" ("); |
| 58 | | menu_part_name.cat(software_part_get_feature(swpart, "part_id")); |
| 59 | | menu_part_name.cat(")"); |
| 60 | | } |
| 61 | | entry->part_name = pool_strdup(swpart->name); // part_name is later used to build up the filename to load, so we use swpart->name! |
| 62 | | entry->interface = pool_strdup(swpart->interface_); |
| 63 | | item_append(info->shortname, menu_part_name.cstr(), 0, entry); |
| 64 | | } |
| 65 | | } |
| 52 | menu_part_name.cat(" ("); |
| 53 | menu_part_name.cat(software_part_get_feature(swpart, "part_id")); |
| 54 | menu_part_name.cat(")"); |
| 66 | 55 | } |
| 67 | | |
| 68 | | software_list_close(list); |
| 56 | entry->type = T_ENTRY; |
| 57 | entry->part = swpart; |
| 58 | item_append(info->shortname, menu_part_name.cstr(), 0, entry); |
| 69 | 59 | } |
| 70 | 60 | } |
| 61 | if(opt_fmgr) { |
| 62 | software_part_menu_entry *entry = (software_part_menu_entry *) m_pool_alloc(sizeof(*entry)); |
| 63 | entry->type = T_FMGR; |
| 64 | entry->part = 0; |
| 65 | item_append("[file manager]", 0, 0, entry); |
| 66 | } |
| 71 | 67 | } |
| 72 | 68 | |
| 73 | 69 | ui_menu_software_parts::~ui_menu_software_parts() |
| r13911 | r13912 | |
| 81 | 77 | |
| 82 | 78 | if (event != NULL && event->iptkey == IPT_UI_SELECT && event->itemref != NULL) |
| 83 | 79 | { |
| 84 | | software_part_info *pentry = (software_part_info *) event->itemref; |
| 85 | | |
| 86 | | // build the name for the part to be loaded |
| 87 | | astring temp_name(entry->short_name); |
| 88 | | temp_name.cat(":"); |
| 89 | | temp_name.cat(pentry->part_name); |
| 90 | | //printf("%s\n", temp_name.cstr()); |
| 91 | | |
| 92 | | entry->image->load(temp_name.cstr()); |
| 80 | software_part_menu_entry *entry = (software_part_menu_entry *) event->itemref; |
| 81 | *result = entry->type; |
| 82 | *selected_part = entry->part; |
| 83 | ui_menu::stack_pop(machine()); |
| 93 | 84 | } |
| 94 | 85 | } |
| 95 | 86 | |
| 96 | | int ui_menu_software_list::compare_entries(const ui_menu_software_entry_info *e1, const ui_menu_software_entry_info *e2, bool shortname) |
| 87 | int ui_menu_software_list::compare_entries(const entry_info *e1, const entry_info *e2, bool shortname) |
| 97 | 88 | { |
| 98 | 89 | int result; |
| 99 | 90 | const char *e1_basename; |
| r13911 | r13912 | |
| 128 | 119 | |
| 129 | 120 | /* populate a specific list */ |
| 130 | 121 | |
| 131 | | ui_menu_software_entry_info *ui_menu_software_list::append_software_entry(software_info *swinfo, device_image_interface* image) |
| 122 | ui_menu_software_list::entry_info *ui_menu_software_list::append_software_entry(const software_info *swinfo) |
| 132 | 123 | { |
| 133 | | ui_menu_software_entry_info *entry = NULL; |
| 134 | | ui_menu_software_entry_info **entryptr; |
| 135 | | const char *interface = image->image_interface(); |
| 124 | entry_info *entry = NULL; |
| 125 | entry_info **entryptr; |
| 136 | 126 | bool entry_updated = FALSE; |
| 137 | 127 | |
| 138 | 128 | // check if at least one of the parts has the correct interface and add a menu entry only in this case |
| 139 | | for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 129 | for (const software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 140 | 130 | { |
| 141 | 131 | if ((strcmp(interface, swpart->interface_) == 0) && is_software_compatible(swpart, swlist)) |
| 142 | 132 | { |
| 143 | 133 | entry_updated = TRUE; |
| 144 | 134 | // allocate a new entry |
| 145 | | entry = (ui_menu_software_entry_info *) m_pool_alloc(sizeof(*entry)); |
| 135 | entry = (entry_info *) m_pool_alloc(sizeof(*entry)); |
| 146 | 136 | memset(entry, 0, sizeof(*entry)); |
| 147 | 137 | |
| 148 | 138 | entry->short_name = pool_strdup(swinfo->shortname); |
| 149 | 139 | entry->long_name = pool_strdup(swinfo->longname); |
| 150 | | entry->list_name = swlist->list_name; |
| 151 | | entry->image = image; |
| 152 | | entry->interface = pool_strdup(swpart->interface_); |
| 153 | 140 | break; |
| 154 | 141 | } |
| 155 | 142 | } |
| r13911 | r13912 | |
| 170 | 157 | return entry; |
| 171 | 158 | } |
| 172 | 159 | |
| 173 | | ui_menu_software_list::ui_menu_software_list(running_machine &machine, render_container *container, software_list_config *_swlist, device_image_interface *_image) : ui_menu(machine, container) |
| 160 | ui_menu_software_list::ui_menu_software_list(running_machine &machine, render_container *container, const software_list_config *_swlist, const char *_interface, astring &_result) : ui_menu(machine, container), result(_result) |
| 174 | 161 | { |
| 175 | 162 | swlist = _swlist; |
| 176 | | image = _image; |
| 163 | interface = _interface; |
| 177 | 164 | entrylist = NULL; |
| 178 | 165 | ordered_by_shortname = true; |
| 179 | 166 | } |
| r13911 | r13912 | |
| 184 | 171 | |
| 185 | 172 | void ui_menu_software_list::populate() |
| 186 | 173 | { |
| 187 | | software_list *list = software_list_open(machine().options(), swlist->list_name, false, NULL); |
| 174 | const software_list *list = software_list_open(machine().options(), swlist->list_name, false, NULL); |
| 188 | 175 | |
| 189 | 176 | // build up the list of entries for the menu |
| 190 | 177 | if (list) |
| 191 | 178 | { |
| 192 | | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 193 | | append_software_entry(swinfo, image); |
| 179 | for (const software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 180 | append_software_entry(swinfo); |
| 194 | 181 | |
| 195 | 182 | software_list_close(list); |
| 196 | 183 | } |
| r13911 | r13912 | |
| 199 | 186 | item_append("Switch Item Ordering", NULL, 0, (void *)1); |
| 200 | 187 | |
| 201 | 188 | // append all of the menu entries |
| 202 | | for (ui_menu_software_entry_info *entry = entrylist; entry != NULL; entry = entry->next) |
| 189 | for (entry_info *entry = entrylist; entry != NULL; entry = entry->next) |
| 203 | 190 | item_append(entry->short_name, entry->long_name, 0, entry); |
| 204 | 191 | } |
| 205 | 192 | |
| 206 | | bool ui_menu_software_list::swinfo_has_multiple_parts(software_info *swinfo, const char *interface) |
| 207 | | { |
| 208 | | int count = 0; |
| 209 | | |
| 210 | | for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 211 | | { |
| 212 | | if (strcmp(interface, swpart->interface_) == 0) |
| 213 | | count++; |
| 214 | | } |
| 215 | | return (count > 1) ? true : false; |
| 216 | | } |
| 217 | | |
| 218 | 193 | void ui_menu_software_list::handle() |
| 219 | 194 | { |
| 220 | | const ui_menu_software_entry_info *entry; |
| 221 | | const ui_menu_software_entry_info *selected_entry = NULL; |
| 195 | const entry_info *entry; |
| 196 | const entry_info *selected_entry = NULL; |
| 222 | 197 | int bestmatch = 0; |
| 223 | 198 | |
| 224 | 199 | /* process the menu */ |
| r13911 | r13912 | |
| 240 | 215 | /* handle selections */ |
| 241 | 216 | else if (event->iptkey == IPT_UI_SELECT) |
| 242 | 217 | { |
| 243 | | ui_menu_software_entry_info *entry = (ui_menu_software_entry_info *) event->itemref; |
| 244 | | software_list *tmp_list = software_list_open(machine().options(), swlist->list_name, false, NULL); |
| 245 | | software_info *tmp_info = software_list_find(tmp_list, entry->short_name, NULL); |
| 246 | | |
| 247 | | // if the selected software has multiple parts that can be loaded, open the submenu |
| 248 | | if (swinfo_has_multiple_parts(tmp_info, image->image_interface())) |
| 249 | | { |
| 250 | | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, entry))); |
| 251 | | } |
| 252 | | else |
| 253 | | { |
| 254 | | // otherwise, load the file |
| 255 | | image->load(entry->short_name); |
| 256 | | } |
| 257 | | software_list_close(tmp_list); |
| 258 | | |
| 259 | | // reset the char buffer when pressing IPT_UI_SELECT |
| 260 | | if (filename_buffer[0] != '\0') |
| 261 | | memset(filename_buffer, '\0', ARRAY_LENGTH(filename_buffer)); |
| 218 | entry_info *entry = (entry_info *) event->itemref; |
| 219 | result = entry->short_name; |
| 220 | ui_menu::stack_pop(machine()); |
| 262 | 221 | } |
| 263 | 222 | else if (event->iptkey == IPT_SPECIAL) |
| 264 | 223 | { |
| r13911 | r13912 | |
| 287 | 246 | |
| 288 | 247 | if (update_selected) |
| 289 | 248 | { |
| 290 | | const ui_menu_software_entry_info *cur_selected; |
| 249 | const entry_info *cur_selected; |
| 291 | 250 | |
| 292 | 251 | // if the current selection is a software entry, start search from here |
| 293 | 252 | if ((FPTR)event->itemref != 1) |
| 294 | | cur_selected= (const ui_menu_software_entry_info *)get_selection(); |
| 253 | cur_selected= (const entry_info *)get_selection(); |
| 295 | 254 | // else (if we are on the 'Switch Order' entry) start from the beginning |
| 296 | 255 | else |
| 297 | 256 | cur_selected= entrylist; |
| r13911 | r13912 | |
| 354 | 313 | } |
| 355 | 314 | |
| 356 | 315 | /* list of available software lists - i.e. cartridges, floppies */ |
| 357 | | ui_menu_software::ui_menu_software(running_machine &machine, render_container *container, device_image_interface* _image) : ui_menu(machine, container) |
| 316 | ui_menu_software::ui_menu_software(running_machine &machine, render_container *container, const char *_interface, const software_list_config **_result) : ui_menu(machine, container) |
| 358 | 317 | { |
| 359 | | image = _image; |
| 318 | interface = _interface; |
| 319 | result = _result; |
| 360 | 320 | } |
| 361 | 321 | |
| 362 | 322 | void ui_menu_software::populate() |
| 363 | 323 | { |
| 364 | 324 | bool haveCompatible = false; |
| 365 | | const char *interface = image->image_interface(); |
| 366 | 325 | |
| 367 | 326 | // Add original software lists for this system |
| 368 | 327 | for (const device_t *dev = machine().config().devicelist().first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) |
| 369 | 328 | { |
| 370 | | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(dev)->inline_config(); |
| 329 | const software_list_config *swlist = (const software_list_config *)downcast<const legacy_device_base *>(dev)->inline_config(); |
| 371 | 330 | |
| 372 | 331 | if (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM) |
| 373 | 332 | { |
| 374 | | software_list *list = software_list_open(machine().options(), swlist->list_name, false, NULL); |
| 333 | const software_list *list = software_list_open(machine().options(), swlist->list_name, false, NULL); |
| 375 | 334 | |
| 376 | 335 | if (list) |
| 377 | 336 | { |
| 378 | 337 | bool found = false; |
| 379 | | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 338 | for (const software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 380 | 339 | { |
| 381 | | software_part *part = software_find_part(swinfo, NULL, NULL); |
| 340 | const software_part *part = software_find_part(swinfo, NULL, NULL); |
| 382 | 341 | if (strcmp(interface,part->interface_)==0) { |
| 383 | 342 | found = true; |
| 384 | 343 | } |
| 385 | 344 | } |
| 386 | 345 | if (found) { |
| 387 | | item_append(list->description, NULL, 0, swlist); |
| 346 | item_append(list->description, NULL, 0, (void *)swlist); |
| 388 | 347 | } |
| 389 | 348 | |
| 390 | 349 | software_list_close(list); |
| r13911 | r13912 | |
| 395 | 354 | // Add compatible software lists for this system |
| 396 | 355 | for (const device_t *dev = machine().config().devicelist().first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) |
| 397 | 356 | { |
| 398 | | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(dev)->inline_config(); |
| 357 | const software_list_config *swlist = (const software_list_config *)downcast<const legacy_device_base *>(dev)->inline_config(); |
| 399 | 358 | |
| 400 | 359 | if (swlist->list_type == SOFTWARE_LIST_COMPATIBLE_SYSTEM) |
| 401 | 360 | { |
| 402 | | software_list *list = software_list_open(machine().options(), swlist->list_name, false, NULL); |
| 361 | const software_list *list = software_list_open(machine().options(), swlist->list_name, false, NULL); |
| 403 | 362 | |
| 404 | 363 | if (list) |
| 405 | 364 | { |
| 406 | 365 | bool found = false; |
| 407 | | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 366 | for (const software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 408 | 367 | { |
| 409 | | software_part *part = software_find_part(swinfo, NULL, NULL); |
| 368 | const software_part *part = software_find_part(swinfo, NULL, NULL); |
| 410 | 369 | if (strcmp(interface,part->interface_)==0) { |
| 411 | 370 | found = true; |
| 412 | 371 | } |
| r13911 | r13912 | |
| 415 | 374 | if (!haveCompatible) { |
| 416 | 375 | item_append("[compatible lists]", NULL, MENU_FLAG_DISABLE, NULL); |
| 417 | 376 | } |
| 418 | | item_append(list->description, NULL, 0, swlist); |
| 377 | item_append(list->description, NULL, 0, (void *)swlist); |
| 419 | 378 | } |
| 420 | 379 | |
| 421 | 380 | haveCompatible = true; |
| r13911 | r13912 | |
| 435 | 394 | /* process the menu */ |
| 436 | 395 | const ui_menu_event *event = process(0); |
| 437 | 396 | |
| 438 | | if (event != NULL && event->iptkey == IPT_UI_SELECT) |
| 439 | | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_list(machine(), container, (software_list_config *)event->itemref, image))); |
| 397 | if (event != NULL && event->iptkey == IPT_UI_SELECT) { |
| 398 | // ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_list(machine(), container, (software_list_config *)event->itemref, image))); |
| 399 | *result = (software_list_config *)event->itemref; |
| 400 | ui_menu::stack_pop(machine()); |
| 401 | } |
| 440 | 402 | } |
src/emu/uiswlist.h
| r13911 | r13912 | |
| 12 | 12 | #ifndef __UISWLIST_H__ |
| 13 | 13 | #define __UISWLIST_H__ |
| 14 | 14 | |
| 15 | | struct ui_menu_software_entry_info { |
| 16 | | ui_menu_software_entry_info *next; |
| 17 | | |
| 18 | | const char *short_name; |
| 19 | | const char *long_name; |
| 20 | | const char *interface; |
| 21 | | char *list_name; |
| 22 | | device_image_interface* image; |
| 23 | | }; |
| 24 | | |
| 25 | 15 | class ui_menu_software_parts : public ui_menu { |
| 26 | 16 | public: |
| 27 | | ui_menu_software_parts(running_machine &machine, render_container *container, ui_menu_software_entry_info *entry); |
| 17 | enum { T_ENTRY, T_FMGR }; |
| 18 | ui_menu_software_parts(running_machine &machine, render_container *container, const software_info *info, const char *interface, const software_part **part, bool opt_fmgr, int *result); |
| 28 | 19 | virtual ~ui_menu_software_parts(); |
| 29 | 20 | virtual void populate(); |
| 30 | 21 | virtual void handle(); |
| 31 | 22 | |
| 32 | 23 | private: |
| 33 | | struct software_part_info { |
| 34 | | const char *part_name; |
| 35 | | const char *interface; |
| 24 | struct software_part_menu_entry { |
| 25 | int type; |
| 26 | const software_part *part; |
| 36 | 27 | }; |
| 37 | 28 | |
| 38 | | ui_menu_software_entry_info *entry; |
| 29 | const software_info *info; |
| 30 | const char *interface; |
| 31 | const software_part **selected_part; |
| 32 | bool opt_fmgr; |
| 33 | int *result; |
| 39 | 34 | }; |
| 40 | 35 | |
| 41 | 36 | class ui_menu_software_list : public ui_menu { |
| 42 | 37 | public: |
| 43 | | ui_menu_software_list(running_machine &machine, render_container *container, software_list_config *swlist, device_image_interface *image); |
| 38 | ui_menu_software_list(running_machine &machine, render_container *container, const software_list_config *swlist, const char *interface, astring &result); |
| 44 | 39 | virtual ~ui_menu_software_list(); |
| 45 | 40 | virtual void populate(); |
| 46 | 41 | virtual void handle(); |
| 47 | 42 | |
| 48 | 43 | private: |
| 49 | | software_list_config *swlist; /* currently selected list */ |
| 50 | | device_image_interface *image; |
| 51 | | ui_menu_software_entry_info *entrylist; |
| 44 | struct entry_info { |
| 45 | entry_info *next; |
| 46 | |
| 47 | const char *short_name; |
| 48 | const char *long_name; |
| 49 | }; |
| 50 | |
| 51 | const software_list_config *swlist; /* currently selected list */ |
| 52 | const char *interface; |
| 53 | astring &result; |
| 54 | entry_info *entrylist; |
| 52 | 55 | char filename_buffer[1024]; |
| 53 | 56 | bool ordered_by_shortname; |
| 54 | 57 | |
| 55 | | int compare_entries(const ui_menu_software_entry_info *e1, const ui_menu_software_entry_info *e2, bool shortname); |
| 56 | | ui_menu_software_entry_info *append_software_entry(software_info *swinfo, device_image_interface* image); |
| 57 | | bool swinfo_has_multiple_parts(software_info *swinfo, const char *interface); |
| 58 | int compare_entries(const entry_info *e1, const entry_info *e2, bool shortname); |
| 59 | entry_info *append_software_entry(const software_info *swinfo); |
| 58 | 60 | }; |
| 59 | 61 | |
| 60 | 62 | class ui_menu_software : public ui_menu { |
| 61 | 63 | public: |
| 62 | | ui_menu_software(running_machine &machine, render_container *container, device_image_interface *device); |
| 64 | ui_menu_software(running_machine &machine, render_container *container, const char *interface, const software_list_config **result); |
| 63 | 65 | virtual ~ui_menu_software(); |
| 64 | 66 | virtual void populate(); |
| 65 | 67 | virtual void handle(); |
| 66 | 68 | |
| 67 | 69 | private: |
| 68 | | device_image_interface *image; |
| 70 | const char *interface; |
| 71 | const software_list_config **result; |
| 69 | 72 | }; |
| 70 | 73 | |
| 71 | 74 | #endif /* __UISWLIST_H__ */ |
src/emu/softlist.c
| r13911 | r13912 | |
| 975 | 975 | software_list_get_count |
| 976 | 976 | -------------------------------------------------*/ |
| 977 | 977 | |
| 978 | | static int software_list_get_count(software_list *swlist) |
| 978 | static int software_list_get_count(const software_list *swlist) |
| 979 | 979 | { |
| 980 | 980 | int count = 0; |
| 981 | 981 | |
| 982 | | for (software_info *swinfo = software_list_find(swlist, "*", NULL); swinfo != NULL; swinfo = software_list_find(swlist, "*", swinfo)) |
| 982 | for (const software_info *swinfo = software_list_find(swlist, "*", NULL); swinfo != NULL; swinfo = software_list_find(swlist, "*", swinfo)) |
| 983 | 983 | count++; |
| 984 | 984 | |
| 985 | 985 | return count; |
| r13911 | r13912 | |
| 993 | 993 | |
| 994 | 994 | const char *software_get_clone(emu_options &options, char *swlist, const char *swname) |
| 995 | 995 | { |
| 996 | | software_list *software_list_ptr = software_list_open(options, swlist, FALSE, NULL); |
| 996 | const software_list *software_list_ptr = software_list_open(options, swlist, FALSE, NULL); |
| 997 | 997 | const char *retval = NULL; |
| 998 | 998 | if (software_list_ptr) |
| 999 | 999 | { |
| 1000 | | software_info *tmp = software_list_find(software_list_ptr, swname, NULL); |
| 1000 | const software_info *tmp = software_list_find(software_list_ptr, swname, NULL); |
| 1001 | 1001 | retval = core_strdup(tmp->parentname); |
| 1002 | 1002 | software_list_close(software_list_ptr); |
| 1003 | 1003 | } |
| r13911 | r13912 | |
| 1013 | 1013 | |
| 1014 | 1014 | UINT32 software_get_support(emu_options &options, char *swlist, const char *swname) |
| 1015 | 1015 | { |
| 1016 | | software_list *software_list_ptr = software_list_open(options, swlist, FALSE, NULL); |
| 1016 | const software_list *software_list_ptr = software_list_open(options, swlist, FALSE, NULL); |
| 1017 | 1017 | UINT32 retval = 0; |
| 1018 | 1018 | |
| 1019 | 1019 | if (software_list_ptr) |
| 1020 | 1020 | { |
| 1021 | | software_info *tmp = software_list_find(software_list_ptr, swname, NULL); |
| 1021 | const software_info *tmp = software_list_find(software_list_ptr, swname, NULL); |
| 1022 | 1022 | retval = tmp->supported; |
| 1023 | 1023 | software_list_close(software_list_ptr); |
| 1024 | 1024 | } |
| r13911 | r13912 | |
| 1132 | 1132 | software_list_close |
| 1133 | 1133 | -------------------------------------------------*/ |
| 1134 | 1134 | |
| 1135 | | void software_list_close(software_list *swlist) |
| 1135 | void software_list_close(const software_list *swlist) |
| 1136 | 1136 | { |
| 1137 | 1137 | if (swlist == NULL) |
| 1138 | 1138 | return; |
| r13911 | r13912 | |
| 1147 | 1147 | software_list_get_description |
| 1148 | 1148 | -------------------------------------------------*/ |
| 1149 | 1149 | |
| 1150 | | const char *software_list_get_description(software_list *swlist) |
| 1150 | const char *software_list_get_description(const software_list *swlist) |
| 1151 | 1151 | { |
| 1152 | 1152 | return swlist->description; |
| 1153 | 1153 | } |
| r13911 | r13912 | |
| 1279 | 1279 | software_list_find |
| 1280 | 1280 | -------------------------------------------------*/ |
| 1281 | 1281 | |
| 1282 | | software_info *software_list_find(software_list *swlist, const char *look_for, software_info *prev) |
| 1282 | const software_info *software_list_find(const software_list *swlist, const char *look_for, const software_info *prev) |
| 1283 | 1283 | { |
| 1284 | 1284 | if (swlist == NULL) |
| 1285 | 1285 | return NULL; |
| r13911 | r13912 | |
| 1288 | 1288 | return NULL; |
| 1289 | 1289 | |
| 1290 | 1290 | /* If we haven't read in the xml file yet, then do it now */ |
| 1291 | /* Just-in-time parsing, hence the const-cast */ |
| 1291 | 1292 | if ( ! swlist->software_info_list ) |
| 1292 | | software_list_parse( swlist, swlist->error_proc, NULL ); |
| 1293 | software_list_parse( const_cast<software_list *>(swlist), swlist->error_proc, NULL ); |
| 1293 | 1294 | |
| 1294 | 1295 | for ( prev = prev ? prev->next : swlist->software_info_list; prev; prev = prev->next ) |
| 1295 | 1296 | { |
| r13911 | r13912 | |
| 1300 | 1301 | return prev; |
| 1301 | 1302 | } |
| 1302 | 1303 | |
| 1304 | software_info *software_list_find(software_list *swlist, const char *look_for, software_info *prev) |
| 1305 | { |
| 1306 | return const_cast<software_info *>(software_list_find(const_cast<const software_list *>(swlist), |
| 1307 | look_for, |
| 1308 | const_cast<const software_info *>(prev))); |
| 1309 | } |
| 1303 | 1310 | |
| 1304 | 1311 | /*------------------------------------------------- |
| 1305 | 1312 | software_find_romdata (for validation purposes) |
| r13911 | r13912 | |
| 1357 | 1364 | software_find_part |
| 1358 | 1365 | -------------------------------------------------*/ |
| 1359 | 1366 | |
| 1360 | | software_part *software_find_part(software_info *sw, const char *partname, const char *interface) |
| 1367 | const software_part *software_find_part(const software_info *sw, const char *partname, const char *interface) |
| 1361 | 1368 | { |
| 1362 | | software_part *part = sw ? sw->partdata : NULL; |
| 1369 | const software_part *part = sw ? sw->partdata : NULL; |
| 1363 | 1370 | |
| 1364 | 1371 | /* If neither partname nor interface supplied, then we just return the first entry */ |
| 1365 | 1372 | if ( partname || interface ) |
| r13911 | r13912 | |
| 1404 | 1411 | return part; |
| 1405 | 1412 | } |
| 1406 | 1413 | |
| 1414 | software_part *software_find_part(software_info *sw, const char *partname, const char *interface) |
| 1415 | { |
| 1416 | return const_cast<software_part *>(software_find_part(const_cast<const software_info *>(sw), partname, interface)); |
| 1417 | } |
| 1407 | 1418 | |
| 1408 | 1419 | /*------------------------------------------------- |
| 1409 | 1420 | software_part_next |
| 1410 | 1421 | -------------------------------------------------*/ |
| 1411 | 1422 | |
| 1412 | | software_part *software_part_next(software_part *part) |
| 1423 | const software_part *software_part_next(const software_part *part) |
| 1413 | 1424 | { |
| 1414 | 1425 | if ( part && part->name ) |
| 1415 | 1426 | { |
| r13911 | r13912 | |
| 1422 | 1433 | return part; |
| 1423 | 1434 | } |
| 1424 | 1435 | |
| 1436 | software_part *software_part_next(software_part *part) |
| 1437 | { |
| 1438 | return const_cast<software_part *>(software_part_next(const_cast<const software_part *>(part))); |
| 1439 | } |
| 1440 | |
| 1425 | 1441 | /*------------------------------------------------- |
| 1426 | 1442 | software_display_matches |
| 1427 | 1443 | -------------------------------------------------*/ |
| r13911 | r13912 | |
| 1754 | 1770 | software_part_get_feature |
| 1755 | 1771 | -------------------------------------------------*/ |
| 1756 | 1772 | |
| 1757 | | const char *software_part_get_feature(software_part *part, const char *feature_name) |
| 1773 | const char *software_part_get_feature(const software_part *part, const char *feature_name) |
| 1758 | 1774 | { |
| 1759 | | feature_list *feature; |
| 1775 | const feature_list *feature; |
| 1760 | 1776 | |
| 1761 | 1777 | if (part == NULL) |
| 1762 | 1778 | return NULL; |
| r13911 | r13912 | |
| 1803 | 1819 | is_software_compatible |
| 1804 | 1820 | -------------------------------------------------*/ |
| 1805 | 1821 | |
| 1806 | | bool is_software_compatible(software_part *swpart, software_list_config *swlist) |
| 1822 | bool is_software_compatible(const software_part *swpart, const software_list_config *swlist) |
| 1807 | 1823 | { |
| 1808 | 1824 | const char *compatibility = software_part_get_feature(swpart, "compatibility"); |
| 1809 | 1825 | const char *filter = swlist->filter; |
| r13911 | r13912 | |
| 1819 | 1835 | return FALSE; |
| 1820 | 1836 | } |
| 1821 | 1837 | |
| 1838 | /*------------------------------------------------- |
| 1839 | swinfo_has_multiple_parts |
| 1840 | -------------------------------------------------*/ |
| 1841 | |
| 1842 | bool swinfo_has_multiple_parts(const software_info *swinfo, const char *interface) |
| 1843 | { |
| 1844 | int count = 0; |
| 1845 | |
| 1846 | for (const software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 1847 | { |
| 1848 | if (strcmp(interface, swpart->interface_) == 0) |
| 1849 | count++; |
| 1850 | } |
| 1851 | return (count > 1) ? true : false; |
| 1852 | } |
| 1853 | |
| 1822 | 1854 | /*************************************************************************** |
| 1823 | 1855 | DEVICE INTERFACE |
| 1824 | 1856 | ***************************************************************************/ |