src/mess/compcfg.c
| r6091 | r6092 | |
| 1 | | #include <stdio.h> |
| 2 | | #include <ctype.h> |
| 3 | | #include <assert.h> |
| 4 | | |
| 5 | | #include "mame.h" |
| 6 | | #include "driver.h" |
| 7 | | #include "compcfg.h" |
| 8 | | |
| 9 | | #define MAX_RAM_OPTIONS 16 |
| 10 | | |
| 11 | | static int get_ram_options(const game_driver *gamedrv, UINT32 *ram_options, int max_options, int *default_option) |
| 12 | | { |
| 13 | | struct SystemConfigurationParamBlock params; |
| 14 | | |
| 15 | | memset(¶ms, 0, sizeof(params)); |
| 16 | | params.max_ram_options = max_options; |
| 17 | | params.ram_options = ram_options; |
| 18 | | |
| 19 | | if (gamedrv->sysconfig_ctor) |
| 20 | | gamedrv->sysconfig_ctor(¶ms); |
| 21 | | |
| 22 | | if (default_option) |
| 23 | | *default_option = params.default_ram_option; |
| 24 | | return params.actual_ram_options; |
| 25 | | } |
| 26 | | |
| 27 | | |
| 28 | | |
| 29 | | UINT32 ram_option(const game_driver *gamedrv, unsigned int i) |
| 30 | | { |
| 31 | | UINT32 ram_options[MAX_RAM_OPTIONS]; |
| 32 | | int ram_optcount; |
| 33 | | |
| 34 | | ram_optcount = get_ram_options(gamedrv, ram_options, sizeof(ram_options) / sizeof(ram_options[0]), NULL); |
| 35 | | return i >= ram_optcount ? 0 : ram_options[i]; |
| 36 | | } |
| 37 | | |
| 38 | | |
| 39 | | |
| 40 | | UINT32 ram_default(const game_driver *gamedrv) |
| 41 | | { |
| 42 | | UINT32 ram_options[MAX_RAM_OPTIONS]; |
| 43 | | int ram_optcount; |
| 44 | | int default_ram_option; |
| 45 | | |
| 46 | | ram_optcount = get_ram_options(gamedrv, ram_options, sizeof(ram_options) / sizeof(ram_options[0]), &default_ram_option); |
| 47 | | return default_ram_option >= ram_optcount ? 0 : ram_options[default_ram_option]; |
| 48 | | } |
| 49 | | |
| 50 | | |
| 51 | | |
| 52 | | int ram_option_count(const game_driver *gamedrv) |
| 53 | | { |
| 54 | | UINT32 ram_options[MAX_RAM_OPTIONS]; |
| 55 | | return get_ram_options(gamedrv, ram_options, sizeof(ram_options) / sizeof(ram_options[0]), NULL); |
| 56 | | } |
| 57 | | |
| 58 | | |
| 59 | | |
| 60 | | int ram_is_valid_option(const game_driver *gamedrv, UINT32 ram) |
| 61 | | { |
| 62 | | UINT32 ram_options[MAX_RAM_OPTIONS]; |
| 63 | | int ram_optcount; |
| 64 | | int i; |
| 65 | | |
| 66 | | ram_optcount = get_ram_options(gamedrv, ram_options, sizeof(ram_options) / sizeof(ram_options[0]), NULL); |
| 67 | | |
| 68 | | for(i = 0; i < ram_optcount; i++) |
| 69 | | if (ram_options[i] == ram) |
| 70 | | return 1; |
| 71 | | return 0; |
| 72 | | } |
| 73 | | |
| 74 | | |
| 75 | | |
| 76 | | UINT32 ram_parse_string(const char *s) |
| 77 | | { |
| 78 | | UINT32 ram; |
| 79 | | char suffix = '\0'; |
| 80 | | |
| 81 | | s += sscanf(s, "%u%c", &ram, &suffix); |
| 82 | | switch(tolower(suffix)) { |
| 83 | | case 'k': |
| 84 | | /* kilobytes */ |
| 85 | | ram *= 1024; |
| 86 | | break; |
| 87 | | |
| 88 | | case 'm': |
| 89 | | /* megabytes */ |
| 90 | | ram *= 1024*1024; |
| 91 | | break; |
| 92 | | |
| 93 | | case '\0': |
| 94 | | /* no suffix */ |
| 95 | | break; |
| 96 | | |
| 97 | | default: |
| 98 | | /* parse failure */ |
| 99 | | ram = 0; |
| 100 | | break; |
| 101 | | } |
| 102 | | return ram; |
| 103 | | } |
| 104 | | |
| 105 | | |
| 106 | | |
| 107 | | const char *ram_string(char *buffer, UINT32 ram) |
| 108 | | { |
| 109 | | const char *suffix; |
| 110 | | |
| 111 | | if ((ram % (1024*1024)) == 0) |
| 112 | | { |
| 113 | | ram /= 1024*1024; |
| 114 | | suffix = "m"; |
| 115 | | } |
| 116 | | else if ((ram % 1024) == 0) |
| 117 | | { |
| 118 | | ram /= 1024; |
| 119 | | suffix = "k"; |
| 120 | | } |
| 121 | | else |
| 122 | | { |
| 123 | | suffix = ""; |
| 124 | | } |
| 125 | | sprintf(buffer, "%u%s", ram, suffix); |
| 126 | | return buffer; |
| 127 | | } |
| 128 | | |
| 129 | | |
| 130 | | |
| 131 | | /* ----------------------------------------------------------------------- */ |
| 132 | | |
| 133 | | #if 0 |
| 134 | | /* NPW 25-Nov-2008 - Disabled in 0.128u4 */ |
| 135 | | UINT8 *memory_install_ram8_handler(running_machine *machine, int cpunum, int spacenum, offs_t start, offs_t end, offs_t ram_offset, int bank) |
| 136 | | { |
| 137 | | read8_space_func read_bank = (read8_space_func) (FPTR)(STATIC_BANK1 + bank - 1); |
| 138 | | write8_space_func write_bank = (write8_space_func) (FPTR)(STATIC_BANK1 + bank - 1); |
| 139 | | offs_t bank_size = end - start + 1; |
| 140 | | |
| 141 | | memory_set_bankptr(machine, bank, mess_ram + ram_offset); |
| 142 | | |
| 143 | | memory_install_read8_handler(machine, cpunum, spacenum, start, |
| 144 | | MIN(end, start - ram_offset + mess_ram_size - 1), 0, 0, read_bank); |
| 145 | | memory_install_write8_handler(machine, cpunum, spacenum, start, |
| 146 | | MIN(end, start - ram_offset + mess_ram_size - 1), 0, 0, write_bank); |
| 147 | | |
| 148 | | if (bank_size > (mess_ram_size - ram_offset)) |
| 149 | | { |
| 150 | | memory_install_read8_handler(machine, cpunum, spacenum, start - ram_offset + mess_ram_size, end, 0, 0, SMH_ROM); |
| 151 | | memory_install_write8_handler(machine, cpunum, spacenum, start - ram_offset + mess_ram_size, end, 0, 0, SMH_ROM); |
| 152 | | } |
| 153 | | return mess_ram + ram_offset; |
| 154 | | } |
| 155 | | #endif |
| 156 | | |
src/mess/devices/messram.c
| r6091 | r6092 | |
| 56 | 56 | integer value |
| 57 | 57 | -------------------------------------------------*/ |
| 58 | 58 | |
| 59 | | static UINT32 parse_string(const char *s) |
| 59 | UINT32 ram_parse_string(const char *s) |
| 60 | 60 | { |
| 61 | 61 | UINT32 ram; |
| 62 | 62 | char suffix = '\0'; |
| r6091 | r6092 | |
| 88 | 88 | return ram; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | const char *ram_string(char *buffer, UINT32 ram) |
| 92 | { |
| 93 | const char *suffix; |
| 91 | 94 | |
| 95 | if ((ram % (1024*1024)) == 0) |
| 96 | { |
| 97 | ram /= 1024*1024; |
| 98 | suffix = "m"; |
| 99 | } |
| 100 | else if ((ram % 1024) == 0) |
| 101 | { |
| 102 | ram /= 1024; |
| 103 | suffix = "k"; |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | suffix = ""; |
| 108 | } |
| 109 | sprintf(buffer, "%u%s", ram, suffix); |
| 110 | return buffer; |
| 111 | } |
| 112 | |
| 113 | |
| 92 | 114 | /***************************************************************************** |
| 93 | 115 | DEVICE INTERFACE |
| 94 | 116 | *****************************************************************************/ |
| r6091 | r6092 | |
| 104 | 126 | const char *ramsize_string = options_get_string(mame_options(), OPTION_RAMSIZE); |
| 105 | 127 | |
| 106 | 128 | if ((ramsize_string != NULL) && (ramsize_string[0] != '\0')) |
| 107 | | messram->size = parse_string(ramsize_string); |
| 129 | messram->size = ram_parse_string(ramsize_string); |
| 108 | 130 | } |
| 109 | 131 | |
| 110 | 132 | /* if we didn't get a size yet, use the default */ |
| 111 | 133 | if (messram->size == 0) |
| 112 | | messram->size = parse_string(config->default_size); |
| 134 | messram->size = ram_parse_string(config->default_size); |
| 113 | 135 | |
| 114 | 136 | /* allocate space for the ram */ |
| 115 | 137 | messram->ram = auto_alloc_array(device->machine, UINT8, messram->size); |
| r6091 | r6092 | |
| 139 | 161 | int error = FALSE; |
| 140 | 162 | |
| 141 | 163 | /* verify default ram value */ |
| 142 | | if (parse_string(config->default_size) == 0) |
| 164 | if (ram_parse_string(config->default_size) == 0) |
| 143 | 165 | { |
| 144 | 166 | mame_printf_error("%s: '%s' has an invalid default RAM option: %s\n", driver->source_file, driver->name, config->default_size); |
| 145 | 167 | error = TRUE; |
| r6091 | r6092 | |
| 168 | 190 | } |
| 169 | 191 | |
| 170 | 192 | /* compare command line option to default value */ |
| 171 | | if (parse_string(config->default_size) == specified_ram) |
| 193 | if (ram_parse_string(config->default_size) == specified_ram) |
| 172 | 194 | is_valid = TRUE; |
| 173 | 195 | } |
| 174 | 196 | else |
| r6091 | r6092 | |
| 188 | 210 | /* try to parse each option */ |
| 189 | 211 | while(*s != '\0') |
| 190 | 212 | { |
| 191 | | UINT32 option_ram_size = parse_string(s); |
| 213 | UINT32 option_ram_size = ram_parse_string(s); |
| 192 | 214 | |
| 193 | 215 | if (option_ram_size == 0) |
| 194 | 216 | { |
src/mess/infomess.c
| r6091 | r6092 | |
| 14 | 14 | #include "hash.h" |
| 15 | 15 | #include "xmlfile.h" |
| 16 | 16 | #include "infomess.h" |
| 17 | #include "devices/messram.h" |
| 17 | 18 | |
| 18 | 19 | /************************************* |
| 19 | 20 | * |
| r6091 | r6092 | |
| 107 | 108 | } |
| 108 | 109 | } |
| 109 | 110 | |
| 111 | /* device iteration helpers */ |
| 112 | #define ram_first(config) device_list_first((config)->devicelist, MESSRAM) |
| 113 | #define ram_next(previous) ((previous)->typenext) |
| 110 | 114 | |
| 111 | | |
| 112 | 115 | /*------------------------------------------------- |
| 113 | 116 | print_game_ramoptions - prints out all RAM |
| 114 | 117 | options for this system |
| 115 | 118 | -------------------------------------------------*/ |
| 116 | | |
| 117 | 119 | void print_game_ramoptions(FILE *out, const game_driver *game, const machine_config *config) |
| 118 | 120 | { |
| 119 | | int i, count; |
| 120 | | UINT32 ram; |
| 121 | | UINT32 default_ram; |
| 121 | const device_config *device; |
| 122 | |
| 123 | for (device = ram_first(config); device != NULL; device = ram_next(device)) |
| 124 | { |
| 125 | ram_config *config = device->inline_config; |
| 126 | fprintf(out, "\t\t<ramoption default=\"1\">%u</ramoption>\n", ram_parse_string(config->default_size)); |
| 127 | if (config->extra_options != NULL) |
| 128 | { |
| 129 | const char *s; |
| 122 | 130 | |
| 123 | | count = ram_option_count(game); |
| 124 | | default_ram = ram_default(game); |
| 131 | astring *buffer = astring_alloc(); |
| 132 | astring_cpyc(buffer, config->extra_options); |
| 133 | astring_replacechr(buffer, ',', 0); |
| 125 | 134 | |
| 126 | | for (i = 0; i < count; i++) |
| 127 | | { |
| 128 | | ram = ram_option(game, i); |
| 129 | | if (ram == default_ram) |
| 130 | | fprintf(out, "\t\t<ramoption default=\"1\">%u</ramoption>\n", ram); |
| 131 | | else |
| 132 | | fprintf(out, "\t\t<ramoption>%u</ramoption>\n", ram); |
| 135 | s = astring_c(buffer); |
| 136 | |
| 137 | /* try to parse each option */ |
| 138 | while(*s != '\0') |
| 139 | { |
| 140 | fprintf(out, "\t\t<ramoption>%u</ramoption>\n", ram_parse_string(s)); |
| 141 | s += strlen(s) + 1; |
| 142 | } |
| 143 | astring_free(buffer); |
| 144 | } |
| 133 | 145 | } |
| 134 | 146 | } |
src/mess/osd/winui/propertiesms.c
| r6091 | r6092 | |
| 32 | 32 | #include "messopts.h" |
| 33 | 33 | #include "strconv.h" |
| 34 | 34 | #include "winutf8.h" |
| 35 | #include "devices\messram.h" |
| 35 | 36 | |
| 36 | 37 | static BOOL SoftwareDirectories_OnInsertBrowse(HWND hDlg, BOOL bBrowse, LPCTSTR lpItem); |
| 37 | 38 | static BOOL SoftwareDirectories_OnDelete(HWND hDlg); |
| r6091 | r6092 | |
| 208 | 209 | |
| 209 | 210 | BOOL PropSheetFilter_Config(const machine_config *drv, const game_driver *gamedrv) |
| 210 | 211 | { |
| 211 | | return (ram_option_count(gamedrv) > 0) || DriverHasDevice(gamedrv, IO_PRINTER); |
| 212 | return (device_list_first(drv->devicelist, MESSRAM)!=NULL) || DriverHasDevice(gamedrv, IO_PRINTER); |
| 212 | 213 | } |
| 213 | 214 | |
| 214 | 215 | |
| r6091 | r6092 | |
| 382 | 383 | |
| 383 | 384 | static BOOL RamPopulateControl(datamap *map, HWND dialog, HWND control, core_options *opts, const char *option_name) |
| 384 | 385 | { |
| 385 | | int count, i, current_index, driver_index; |
| 386 | int i, current_index, driver_index; |
| 386 | 387 | const game_driver *gamedrv; |
| 387 | | UINT32 ram, current_ram; |
| 388 | | char buffer[64]; |
| 388 | UINT32 ram, current_ram; |
| 389 | 389 | const char *this_ram_string; |
| 390 | 390 | TCHAR* t_ramstring; |
| 391 | machine_config *cfg; |
| 392 | const device_config *device; |
| 391 | 393 | |
| 392 | 394 | // identify the driver |
| 393 | 395 | driver_index = PropertiesCurrentGame(dialog); |
| r6091 | r6092 | |
| 396 | 398 | // clear out the combo box |
| 397 | 399 | (void)ComboBox_ResetContent(control); |
| 398 | 400 | |
| 401 | // allocate the machine config |
| 402 | cfg = machine_config_alloc_with_mess_devices(gamedrv); |
| 403 | |
| 399 | 404 | // identify how many options that we have |
| 400 | | count = ram_option_count(gamedrv); |
| 401 | | EnableWindow(control, count > 0); |
| 402 | | |
| 405 | device = device_list_first(cfg->devicelist, MESSRAM); |
| 406 | |
| 407 | EnableWindow(control, (device != NULL)); |
| 408 | i = 0; |
| 403 | 409 | // we can only do something meaningful if there is more than one option |
| 404 | | if (count > 0) |
| 410 | if (device != NULL) |
| 405 | 411 | { |
| 412 | ram_config *config = device->inline_config; |
| 413 | |
| 406 | 414 | // identify the current amount of RAM |
| 407 | 415 | this_ram_string = options_get_string(opts, OPTION_RAMSIZE); |
| 408 | 416 | current_ram = (this_ram_string != NULL) ? ram_parse_string(this_ram_string) : 0; |
| 409 | 417 | if (current_ram == 0) |
| 410 | | current_ram = ram_default(gamedrv); |
| 418 | current_ram = ram_parse_string(config->default_size); |
| 411 | 419 | |
| 412 | 420 | // by default, assume index 0 |
| 413 | 421 | current_index = 0; |
| 414 | 422 | |
| 415 | | // loop through all options |
| 416 | | for (i = 0; i < count; i++) |
| 417 | 423 | { |
| 418 | | // identify this option |
| 419 | | ram = ram_option(gamedrv, i); |
| 420 | | this_ram_string = ram_string(buffer, ram); |
| 421 | | |
| 422 | | t_ramstring = tstring_from_utf8(this_ram_string); |
| 424 | t_ramstring = tstring_from_utf8(config->default_size); |
| 423 | 425 | if( !t_ramstring ) |
| 424 | 426 | return FALSE; |
| 425 | 427 | |
| 426 | | // add this option to the combo box |
| 427 | 428 | (void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring)); |
| 428 | | (void)ComboBox_SetItemData(control, i, ram); |
| 429 | (void)ComboBox_SetItemData(control, i, ram); |
| 430 | } |
| 431 | if (config->extra_options != NULL) |
| 432 | { |
| 433 | const char *s; |
| 429 | 434 | |
| 430 | | free(t_ramstring); |
| 435 | astring *buffer = astring_alloc(); |
| 436 | astring_cpyc(buffer, config->extra_options); |
| 437 | astring_replacechr(buffer, ',', 0); |
| 431 | 438 | |
| 432 | | // is this the current option? record the index if so |
| 433 | | if (ram == current_ram) |
| 434 | | current_index = i; |
| 435 | | } |
| 439 | s = astring_c(buffer); |
| 436 | 440 | |
| 441 | /* try to parse each option */ |
| 442 | while(*s != '\0') |
| 443 | { |
| 444 | i++; |
| 445 | // identify this option |
| 446 | ram = ram_parse_string(s); |
| 447 | this_ram_string = s; |
| 448 | |
| 449 | t_ramstring = tstring_from_utf8(this_ram_string); |
| 450 | if( !t_ramstring ) |
| 451 | return FALSE; |
| 452 | |
| 453 | // add this option to the combo box |
| 454 | (void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring)); |
| 455 | (void)ComboBox_SetItemData(control, i, ram); |
| 456 | |
| 457 | free(t_ramstring); |
| 458 | |
| 459 | // is this the current option? record the index if so |
| 460 | if (ram == current_ram) |
| 461 | current_index = i; |
| 462 | |
| 463 | s += strlen(s) + 1; |
| 464 | } |
| 465 | astring_free(buffer); |
| 466 | } |
| 467 | |
| 437 | 468 | // set the combo box |
| 438 | 469 | (void)ComboBox_SetCurSel(control, current_index); |
| 439 | 470 | } |