Previous 15994 Revisions Next

r8128 Friday 21st May, 2010 at 14:19:44 UTC by Dirk Best
Added very basic software list support to the internal ui
[src/emu]romload.c
[src/mess]softlist.c softlist.h uimess.c

src/emu/romload.c
r8127r8128
12991299      if (devtag_get_device(romdata->machine, astring_c(regiontag)) != NULL)
13001300         regionflags = normalize_flags_for_device(romdata->machine, regionflags, astring_c(regiontag));
13011301
1302      /* clear old region (todo: should be moved to an image unload function) */
1303      if (memory_region(romdata->machine, astring_c(regiontag)) != NULL)
1304         memory_region_free(romdata->machine, astring_c(regiontag));
1305
13021306      /* remember the base and length */
13031307      romdata->region = memory_region_alloc(romdata->machine, astring_c(regiontag), regionlength, regionflags);
13041308      LOG(("Allocated %X bytes @ %p\n", romdata->region->length, romdata->region->base.v));
src/mess/uimess.c
r8127r8128
1111#include "uimess.h"
1212#include "uiinput.h"
1313#include "input.h"
14#include "softlist.h"
1415#include "devices/cassette.h"
1516
1617
r8127r8128
149150   /* add image info menu */
150151   ui_menu_item_append(menu, "Image Information", NULL, 0, (void*)ui_mess_menu_image_info);
151152
152   /* add image info menu */
153   /* add file manager menu */
153154   ui_menu_item_append(menu, "File Manager", NULL, 0, (void*)ui_mess_menu_file_manager);
154155
156   /* add software menu */
157   ui_menu_item_append(menu, "Software", NULL, 0, (void*)ui_mess_menu_software);
158
155159   /* add tape control menu */
156160   if (machine->devicelist.first(CASSETTE))
157161      ui_menu_item_append(menu, "Tape Control", NULL, 0, (void*)ui_mess_menu_tape_control);
src/mess/softlist.c
r8127r8128
5050   mame_file   *file;
5151   object_pool   *pool;
5252   parse_state   state;
53   const char *description;
5354   struct software_info_list   *software_info_list;
5455   struct software_info_list   *current_software_info;
5556   software_info   *softinfo;
r8127r8128
305306               }
306307               if ( ! strcmp(attributes[0], "description" ) )
307308               {
309                  swlist->description =  (const char *)pool_malloc_lib(swlist->pool, (strlen(attributes[1])  + 1) * sizeof(char));
310                  if (!swlist->description)
311                     return;
312
313                  strcpy((char *)swlist->description, attributes[1]);
308314               }
309315            }
310316         }
r8127r8128
12141220   }
12151221}
12161222
1223
1224/***************************************************************************
1225    MENU SUPPORT
1226***************************************************************************/
1227
1228/* state of the software menu */
1229typedef struct _software_menu_state software_menu_state;
1230struct _software_menu_state
1231{
1232   char *list_name;   /* currently selected list */
1233};
1234
1235/* state of a software entry */
1236typedef struct _software_entry_state software_entry_state;
1237struct _software_entry_state
1238{
1239   const char *short_name;
1240   const char *interface;
1241};
1242
1243
1244/* populate a specific list */
1245static void ui_mess_menu_populate_software_entries(running_machine *machine, ui_menu *menu, char *list_name)
1246{
1247   software_list *list = software_list_open(mame_options(), list_name, FALSE, NULL);
1248
1249   if (list)
1250   {
1251      for (software_info *swinfo = software_list_first(list); swinfo != NULL; swinfo = software_list_next(list))
1252      {
1253         software_entry_state *entry = (software_entry_state *) ui_menu_pool_alloc(menu, sizeof(*entry));
1254         entry->short_name = ui_menu_pool_strdup(menu, swinfo->shortname);
1255
1256         software_part *part = software_find_part(swinfo, NULL, NULL);
1257         entry->interface = ui_menu_pool_strdup(menu, part->interface_);
1258
1259         ui_menu_item_append(menu, swinfo->shortname, swinfo->longname, 0, entry);
1260      }
1261
1262      software_list_close(list);
1263   }
1264}
1265
1266void ui_mess_menu_software_list(running_machine *machine, ui_menu *menu, void *parameter, void *state)
1267{
1268   const ui_menu_event *event;
1269   software_menu_state *sw_state = (software_menu_state *)state;
1270
1271   if (!ui_menu_populated(menu))
1272      ui_mess_menu_populate_software_entries(machine, menu, sw_state->list_name);
1273
1274   /* process the menu */
1275   event = ui_menu_process(machine, menu, 0);
1276
1277   if (event != NULL && event->iptkey == IPT_UI_SELECT && event->itemref != NULL)
1278   {
1279      running_device *image = NULL;
1280      software_entry_state *entry = (software_entry_state *) event->itemref;
1281
1282      /* search for a device with the right interface */
1283      for (running_device *dev = machine->devicelist.first(); dev != NULL; dev = dev->next)
1284      {
1285         const char *interface = dev->get_config_string(DEVINFO_STR_INTERFACE);
1286
1287         if (interface != NULL)
1288         {
1289            if (!strcmp(interface, entry->interface))
1290            {
1291               image = dev;
1292               break;
1293            }
1294         }
1295      }
1296
1297      if (image != NULL)
1298         image_load(image, entry->short_name);
1299      else
1300         popmessage("No matching device found for interface '%s'!", entry->interface);
1301   }
1302}
1303
1304/* list of available software lists - i.e. cartridges, floppies */
1305static void ui_mess_menu_populate_software_list(running_machine *machine, ui_menu *menu)
1306{
1307   for (const device_config *dev = machine->config->devicelist.first(); dev != NULL; dev = dev->next)
1308   {
1309      if (!strcmp(dev->tag(), __SOFTWARE_LIST_TAG))
1310      {
1311         software_list_config *swlist = (software_list_config *)dev->inline_config;
1312
1313         for (int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++)
1314         {
1315            if (swlist->list_name[i])
1316            {
1317               software_list *list = software_list_open(mame_options(), swlist->list_name[i], FALSE, NULL);
1318
1319               if (list)
1320               {
1321                  /* todo: fix this */
1322                  for (software_info *swinfo = software_list_first(list); swinfo != NULL; swinfo = software_list_next(list))
1323                  {
1324                  }
1325
1326                  ui_menu_item_append(menu, list->description, NULL, 0, swlist->list_name[i]);
1327
1328                  software_list_close(list);
1329               }
1330            }
1331         }
1332      }
1333   }
1334}
1335
1336void ui_mess_menu_software(running_machine *machine, ui_menu *menu, void *parameter, void *state)
1337{
1338   const ui_menu_event *event;
1339
1340   if (!ui_menu_populated(menu))
1341      ui_mess_menu_populate_software_list(machine, menu);
1342
1343   /* process the menu */
1344   event = ui_menu_process(machine, menu, 0);
1345
1346   if (event != NULL && event->iptkey == IPT_UI_SELECT)
1347   {
1348      ui_menu *child_menu = ui_menu_alloc(machine, render_container_get_ui(), ui_mess_menu_software_list, NULL);
1349      software_menu_state *child_menustate = (software_menu_state *)ui_menu_alloc_state(child_menu, sizeof(*child_menustate), NULL);
1350      child_menustate->list_name = (char *)event->itemref;
1351      ui_menu_stack_push(child_menu);
1352   }
1353}
src/mess/softlist.h
r8127r8128
99#ifndef __SOFTLIST_H_
1010#define __SOFTLIST_H_
1111
12#include "uimenu.h"
13
14
1215/*********************************************************************
1316
1417    Internal structures and XML file handling
r8127r8128
5760
5861bool load_software_part(running_device *device, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name);
5962
63void ui_mess_menu_software(running_machine *machine, ui_menu *menu, void *parameter, void *state);
6064
65
6166/*********************************************************************
6267
6368    Driver software list configuration

Previous 15994 Revisions Next


© 1998-2018 The MESS Team