diff --git a/src/devices/bus/c64/exp.cpp b/src/devices/bus/c64/exp.cpp index ca0ed342343..8915d3301b7 100644 --- a/src/devices/bus/c64/exp.cpp +++ b/src/devices/bus/c64/exp.cpp @@ -123,7 +123,7 @@ bool c64_expansion_slot_device::call_load() { size = length(); - if (!core_stricmp(filetype(), "80")) + if (filetype() == "80") { fread(m_card->m_roml, size); m_card->m_exrom = (0); @@ -133,20 +133,20 @@ bool c64_expansion_slot_device::call_load() m_card->m_game = 0; } } - else if (!core_stricmp(filetype(), "a0")) + else if (filetype() == "a0") { fread(m_card->m_romh, 0x2000); m_card->m_exrom = 0; m_card->m_game = 0; } - else if (!core_stricmp(filetype(), "e0")) + else if (filetype() == "e0") { fread(m_card->m_romh, 0x2000); m_card->m_game = 0; } - else if (!core_stricmp(filetype(), "crt")) + else if (filetype() == "crt") { size_t roml_size = 0; size_t romh_size = 0; @@ -209,7 +209,7 @@ std::string c64_expansion_slot_device::get_default_card_software() { if (open_image_file(mconfig().options())) { - if (!core_stricmp(filetype(), "crt")) + if (filetype() == "crt") return cbm_crt_get_card(*m_file); clear(); diff --git a/src/devices/bus/cbm2/exp.cpp b/src/devices/bus/cbm2/exp.cpp index dfba98a37db..08cdb2e84c7 100644 --- a/src/devices/bus/cbm2/exp.cpp +++ b/src/devices/bus/cbm2/exp.cpp @@ -111,17 +111,17 @@ bool cbm2_expansion_slot_device::call_load() { size = length(); - if (!core_stricmp(filetype(), "20")) + if (filetype() == "20") { m_card->m_bank1.allocate(size); fread(m_card->m_bank1, size); } - else if (!core_stricmp(filetype(), "40")) + else if (filetype() == "40") { m_card->m_bank2.allocate(size); fread(m_card->m_bank2, size); } - else if (!core_stricmp(filetype(), "60")) + else if (filetype() == "60") { m_card->m_bank3.allocate(size); fread(m_card->m_bank3, size); diff --git a/src/devices/bus/intv/slot.cpp b/src/devices/bus/intv/slot.cpp index 8344f60c0b7..30e6d07aa23 100644 --- a/src/devices/bus/intv/slot.cpp +++ b/src/devices/bus/intv/slot.cpp @@ -247,10 +247,9 @@ int intv_cart_slot_device::load_fullpath() UINT8 low_byte; UINT8 *ROM; - const char *file_type = filetype(); /* if it is in .rom format, we enter here */ - if (!core_stricmp (file_type, "rom")) + if (filetype() == "rom") { // header fread(&temp, 1); diff --git a/src/devices/bus/vic10/exp.cpp b/src/devices/bus/vic10/exp.cpp index d157c547c63..27a2e8a07df 100644 --- a/src/devices/bus/vic10/exp.cpp +++ b/src/devices/bus/vic10/exp.cpp @@ -119,7 +119,7 @@ bool vic10_expansion_slot_device::call_load() { size = length(); - if (!core_stricmp(filetype(), "80")) + if (filetype() == "80") { fread(m_card->m_lorom, 0x2000); @@ -128,11 +128,11 @@ bool vic10_expansion_slot_device::call_load() fread(m_card->m_uprom, 0x2000); } } - else if (!core_stricmp(filetype(), "e0")) + else if (filetype() == "e0") { fread(m_card->m_uprom, size); } - else if (!core_stricmp(filetype(), "crt")) + else if (filetype() == "crt") { size_t roml_size = 0; size_t romh_size = 0; @@ -174,7 +174,7 @@ std::string vic10_expansion_slot_device::get_default_card_software() { if (open_image_file(mconfig().options())) { - if (!core_stricmp(filetype(), "crt")) + if (filetype() == "crt") return cbm_crt_get_card(*m_file); clear(); diff --git a/src/devices/bus/vic20/exp.cpp b/src/devices/bus/vic20/exp.cpp index f96cff982aa..3cca5366f04 100644 --- a/src/devices/bus/vic20/exp.cpp +++ b/src/devices/bus/vic20/exp.cpp @@ -113,13 +113,13 @@ bool vic20_expansion_slot_device::call_load() { if (software_entry() == nullptr) { - if (!core_stricmp(filetype(), "20")) fread(m_card->m_blk1, 0x2000); - else if (!core_stricmp(filetype(), "40")) fread(m_card->m_blk2, 0x2000); - else if (!core_stricmp(filetype(), "60")) fread(m_card->m_blk3, 0x2000); - else if (!core_stricmp(filetype(), "70")) fread(m_card->m_blk3, 0x2000, 0x1000); - else if (!core_stricmp(filetype(), "a0")) fread(m_card->m_blk5, 0x2000); - else if (!core_stricmp(filetype(), "b0")) fread(m_card->m_blk5, 0x2000, 0x1000); - else if (!core_stricmp(filetype(), "crt")) + if (filetype() == "20") fread(m_card->m_blk1, 0x2000); + else if (filetype() == "40") fread(m_card->m_blk2, 0x2000); + else if (filetype() == "60") fread(m_card->m_blk3, 0x2000); + else if (filetype() == "70") fread(m_card->m_blk3, 0x2000, 0x1000); + else if (filetype() == "a0") fread(m_card->m_blk5, 0x2000); + else if (filetype() == "b0") fread(m_card->m_blk5, 0x2000, 0x1000); + else if (filetype() == "crt") { // read the header UINT8 header[2]; diff --git a/src/devices/imagedev/cassette.cpp b/src/devices/imagedev/cassette.cpp index 57c4f52d15a..753dc195387 100644 --- a/src/devices/imagedev/cassette.cpp +++ b/src/devices/imagedev/cassette.cpp @@ -2,7 +2,7 @@ // copyright-holders:Nathan Woods, Miodrag Milanovic /********************************************************************* - cassette.c + cassette.cpp Interface to the cassette image abstraction code @@ -264,7 +264,6 @@ bool cassette_image_device::internal_load(bool is_create) { casserr_t err; int cassette_flags; - const char *extension; int is_writable; device_image_interface *image = nullptr; interface(image); @@ -284,18 +283,7 @@ bool cassette_image_device::internal_load(bool is_create) is_writable = !is_readonly(); cassette_flags = is_writable ? (CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT) : CASSETTE_FLAG_READONLY; std::string fname; - if (software_entry()==nullptr) { - extension = filetype(); - } else { - fname = m_mame_file->filename(); - int loc = fname.find_last_of('.'); - if (loc!=-1) { - extension = fname.substr(loc + 1,fname.length()-loc).c_str(); - } else { - extension = ""; - } - } - err = cassette_open_choices((void *)image, &image_ioprocs, extension, m_formats, cassette_flags, &m_cassette); + err = cassette_open_choices((void *)image, &image_ioprocs, filetype().c_str(), m_formats, cassette_flags, &m_cassette); /* this is kind of a hack */ if (err && is_writable) diff --git a/src/devices/imagedev/chd_cd.cpp b/src/devices/imagedev/chd_cd.cpp index cac16961a31..c2f643ebf80 100644 --- a/src/devices/imagedev/chd_cd.cpp +++ b/src/devices/imagedev/chd_cd.cpp @@ -108,7 +108,7 @@ bool cdrom_image_device::call_load() if (software_entry() == nullptr) { - if (strstr(m_image_name.c_str(), ".chd") && is_loaded()) { + if ((filetype() == ".chd") && is_loaded()) { err = m_self_chd.open( image_core_file() ); /* CDs are never writeable */ if ( err ) goto error; diff --git a/src/devices/imagedev/flopdrv.cpp b/src/devices/imagedev/flopdrv.cpp index 290d6671cd3..ab844a1f255 100644 --- a/src/devices/imagedev/flopdrv.cpp +++ b/src/devices/imagedev/flopdrv.cpp @@ -422,7 +422,6 @@ int legacy_floppy_image_device::internal_floppy_device_load(bool is_create, int floperr_t err; const struct FloppyFormat *floppy_options; int floppy_flags, i; - const char *extension; device_image_interface *image = nullptr; interface(image); /* figure out the floppy options */ @@ -440,8 +439,7 @@ int legacy_floppy_image_device::internal_floppy_device_load(bool is_create, int { /* opening an image */ floppy_flags = !is_readonly() ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY; - extension = filetype(); - err = floppy_open_choices((void *) image, &image_ioprocs, extension, floppy_options, floppy_flags, &m_floppy); + err = floppy_open_choices((void *) image, &image_ioprocs, filetype().c_str(), floppy_options, floppy_flags, &m_floppy); if (err) goto error; } diff --git a/src/devices/imagedev/snapquik.cpp b/src/devices/imagedev/snapquik.cpp index a3c55ff4064..1c815aa351e 100644 --- a/src/devices/imagedev/snapquik.cpp +++ b/src/devices/imagedev/snapquik.cpp @@ -2,7 +2,7 @@ // copyright-holders:Nathan Woods, Miodrag Milanovic /********************************************************************* - snapquik.h + snapquik.cpp Snapshots and quickloads @@ -66,7 +66,7 @@ void snapshot_image_device::device_config_complete() TIMER_CALLBACK_MEMBER(snapshot_image_device::process_snapshot_or_quickload) { /* invoke the load */ - m_load(*this, filetype(), length()); + m_load(*this, filetype().c_str(), length()); } //------------------------------------------------- diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp index cb2a7f6a02d..dec39310bc1 100644 --- a/src/emu/diimage.cpp +++ b/src/emu/diimage.cpp @@ -209,15 +209,14 @@ void device_image_interface::set_image_filename(const std::string &filename) m_basename.assign(iter.base(), m_image_name.end()); } m_basename_noext = m_basename; - m_filetype = ""; auto loc = m_basename_noext.find_last_of('.'); if (loc != std::string::npos) - { m_basename_noext = m_basename_noext.substr(0, loc); - m_filetype = m_basename.substr(loc + 1); - } + + m_filetype = core_filename_extract_extension(m_basename, true, true); } + /**************************************************************************** CREATION FORMATS ****************************************************************************/ @@ -1002,6 +1001,12 @@ bool device_image_interface::load_internal(const std::string &path, bool is_crea m_manufacturer = m_software_info_ptr->publisher(); m_year = m_software_info_ptr->year(); //m_playable = m_software_info_ptr->supported(); + + // set file type + std::string filename = (m_mame_file != nullptr) && (m_mame_file->filename() != nullptr) + ? m_mame_file->filename() + : ""; + m_filetype = core_filename_extract_extension(filename, true, true); } // did we fail to find the file? diff --git a/src/emu/diimage.h b/src/emu/diimage.h index 7854f9022c1..9d31b295f3c 100644 --- a/src/emu/diimage.h +++ b/src/emu/diimage.h @@ -177,7 +177,7 @@ public: const char *filename() const { if (m_image_name.empty()) return nullptr; else return m_image_name.c_str(); } const char *basename() const { if (m_basename.empty()) return nullptr; else return m_basename.c_str(); } const char *basename_noext() const { if (m_basename_noext.empty()) return nullptr; else return m_basename_noext.c_str(); } - const char *filetype() const { if (m_filetype.empty()) return nullptr; else return m_filetype.c_str(); } + const std::string &filetype() const { return m_filetype; } bool is_open() const { return bool(m_file); } util::core_file &image_core_file() const { return *m_file; } UINT64 length() { check_for_file(); return m_file->size(); } diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index 5fcd9e00239..22b67046150 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -1266,11 +1266,11 @@ core_file::core_file() FILENAME UTILITIES ***************************************************************************/ -/*------------------------------------------------- - core_filename_extract_base - extract the base - name from a filename; note that this makes - assumptions about path separators --------------------------------------------------*/ +// ------------------------------------------------- +// core_filename_extract_base - extract the base +// name from a filename; note that this makes +// assumptions about path separators +// ------------------------------------------------- std::string core_filename_extract_base(const std::string &name, bool strip_extension) { @@ -1290,10 +1290,26 @@ std::string core_filename_extract_base(const std::string &name, bool strip_exten } -/*------------------------------------------------- - core_filename_ends_with - does the given - filename end with the specified extension? --------------------------------------------------*/ +// ------------------------------------------------- +// core_filename_extract_extension +// ------------------------------------------------- + +std::string core_filename_extract_extension(const std::string &filename, bool strip_period, bool normalize_to_lowercase) +{ + auto loc = filename.find_last_of('.'); + std::string result = loc != std::string::npos + ? filename.substr(loc + (strip_period ? 1 : 0)) + : ""; + if (normalize_to_lowercase) + std::transform(result.begin(), result.end(), result.begin(), ::tolower); + return result; +} + + +// ------------------------------------------------- +// core_filename_ends_with - does the given +// filename end with the specified extension? +// ------------------------------------------------- bool core_filename_ends_with(const std::string &filename, const std::string &extension) { diff --git a/src/lib/util/corefile.h b/src/lib/util/corefile.h index 5fa6d5af9a7..fff2240c0cc 100644 --- a/src/lib/util/corefile.h +++ b/src/lib/util/corefile.h @@ -139,10 +139,13 @@ protected: /* ----- filename utilities ----- */ -/* extract the base part of a filename (remove extensions and paths) */ +// extract the base part of a filename (remove extensions and paths) std::string core_filename_extract_base(const std::string &name, bool strip_extension = false); -/* true if the given filename ends with a particular extension */ +// extracts the file extension from a filename +std::string core_filename_extract_extension(const std::string &filename, bool strip_period = false, bool normalize_to_lowercase = false); + +// true if the given filename ends with a particular extension bool core_filename_ends_with(const std::string &filename, const std::string &extension); diff --git a/src/mame/drivers/d6800.cpp b/src/mame/drivers/d6800.cpp index e0ca57edcd8..9b1b7cd620c 100644 --- a/src/mame/drivers/d6800.cpp +++ b/src/mame/drivers/d6800.cpp @@ -366,7 +366,7 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 ) image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length,quick_addr,quick_addr+quick_length,exec_addr); // Start the quickload - if (strcmp(image.filetype(), "bin") == 0) + if (image.filetype() == "bin") m_maincpu->set_pc(quick_addr); else m_maincpu->set_pc(exec_addr); diff --git a/src/mame/drivers/eti660.cpp b/src/mame/drivers/eti660.cpp index 72ab5cb146d..7f420f16178 100644 --- a/src/mame/drivers/eti660.cpp +++ b/src/mame/drivers/eti660.cpp @@ -286,7 +286,7 @@ QUICKLOAD_LOAD_MEMBER( eti660_state, eti660 ) space.write_byte(i + quick_addr, quick_data[i]); /* display a message about the loaded quickload */ - if (strcmp(image.filetype(), "bin") == 0) + if (image.filetype() == "bin") image.message(" Quickload: size=%04X : start=%04X : end=%04X : Press 6 to start",quick_length,quick_addr,quick_addr+quick_length); else image.message(" Quickload: size=%04X : start=%04X : end=%04X : Press 8 to start",quick_length,quick_addr,quick_addr+quick_length); diff --git a/src/mame/drivers/jaguar.cpp b/src/mame/drivers/jaguar.cpp index d19bba4b9ea..ff4d8129b76 100644 --- a/src/mame/drivers/jaguar.cpp +++ b/src/mame/drivers/jaguar.cpp @@ -2018,11 +2018,11 @@ int jaguar_state::quickload(device_image_interface &image, const char *file_type skip = 96; else /* ABS binary */ - if (!core_stricmp(image.filetype(), "abs")) + if (image.filetype() == "abs") start = 0xc000; else /* JAG binary */ - if (!core_stricmp(image.filetype(), "jag")) + if (image.filetype() == "jag") start = 0x5000; @@ -2063,7 +2063,7 @@ DEVICE_IMAGE_LOAD_MEMBER( jaguar_state, jaguar_cart ) size = image.length(); /* .rom files load & run at 802000 */ - if (!core_stricmp(image.filetype(), "rom")) + if (image.filetype() == "rom") { load_offset = 0x2000; // fix load address m_cart_base[0x101] = 0x802000; // fix exec address diff --git a/src/mame/drivers/ssem.cpp b/src/mame/drivers/ssem.cpp index dac314aa9eb..010183798ae 100644 --- a/src/mame/drivers/ssem.cpp +++ b/src/mame/drivers/ssem.cpp @@ -549,7 +549,7 @@ QUICKLOAD_LOAD_MEMBER(ssem_state, ssem_store) token_buf[4] = '\0'; sscanf(token_buf, "%04u", &line); - if (!core_stricmp(image.filetype(), "snp")) + if (image.filetype() == "snp") { UINT32 word = 0; @@ -565,7 +565,7 @@ QUICKLOAD_LOAD_MEMBER(ssem_state, ssem_store) space.write_byte((line << 2) + 2, (word >> 8) & 0x000000ff); space.write_byte((line << 2) + 3, (word >> 0) & 0x000000ff); } - else if (!core_stricmp(image.filetype(), "asm")) + else if (image.filetype() == "asm") { char op_buf[4] = { 0 }; INT32 value = 0; diff --git a/src/mame/drivers/studio2.cpp b/src/mame/drivers/studio2.cpp index 1f620756308..d03f2dde54b 100644 --- a/src/mame/drivers/studio2.cpp +++ b/src/mame/drivers/studio2.cpp @@ -535,7 +535,7 @@ DEVICE_IMAGE_LOAD_MEMBER( studio2_state, studio2_cart_load ) if (image.software_entry() == nullptr) { - if (!strcmp(image.filetype(), "st2")) + if (image.filetype() == "st2") { UINT8 header[0x100]; UINT8 catalogue[10], title[32], pages[64]; diff --git a/src/mame/drivers/vc4000.cpp b/src/mame/drivers/vc4000.cpp index 0d99a69747d..ab0a3b3b216 100644 --- a/src/mame/drivers/vc4000.cpp +++ b/src/mame/drivers/vc4000.cpp @@ -414,7 +414,7 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000) } else { - if (core_stricmp(image.filetype(), "tvc")==0) + if (image.filetype() == "tvc") { if (quick_data[0] != 2) { @@ -455,7 +455,7 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000) } } else - if (core_stricmp(image.filetype(), "pgm")==0) + if (image.filetype() == "pgm") { if (quick_data[0] != 0) { diff --git a/src/mame/drivers/vip.cpp b/src/mame/drivers/vip.cpp index 9c8c88c4156..537fb4b2342 100644 --- a/src/mame/drivers/vip.cpp +++ b/src/mame/drivers/vip.cpp @@ -667,13 +667,13 @@ QUICKLOAD_LOAD_MEMBER( vip_state, vip ) int chip8_size = 0; int size = image.length(); - if (strcmp(image.filetype(), "c8") == 0) + if (image.filetype() == "c8") { /* CHIP-8 program */ chip8_ptr = m_chip8->base(); chip8_size = m_chip8->bytes(); } - else if (strcmp(image.filename(), "c8x") == 0) + else if (image.filetype() == "c8x") { /* CHIP-8X program */ chip8_ptr = m_chip8x->base(); diff --git a/src/mame/machine/atarifdc.cpp b/src/mame/machine/atarifdc.cpp index 6c390d9839e..cab09ef2b93 100644 --- a/src/mame/machine/atarifdc.cpp +++ b/src/mame/machine/atarifdc.cpp @@ -112,7 +112,6 @@ void atari_fdc_device::atari_load_proc(device_image_interface &image, bool is_cr { int id = floppy_get_drive(image); int size, i; - const char *ext; m_drv[id].image = std::make_unique(MAXSIZE); if (!m_drv[id].image) @@ -144,34 +143,29 @@ void atari_fdc_device::atari_load_proc(device_image_interface &image, bool is_cr /* re allocate the buffer; we don't want to be too lazy ;) */ //m_drv[id].image = (UINT8*)image.image_realloc(m_drv[id].image, size); - ext = image.filetype(); - - // hack alert, this means we can only load ATR via the softlist at the moment, image.filetype reutrns nullptr :/ - if (image.software_entry() != nullptr) ext="ATR"; - /* no extension: assume XFD format (no header) */ - if (!ext) + if (image.filetype() == "") { m_drv[id].type = FORMAT_XFD; m_drv[id].header_skip = 0; } else /* XFD extension */ - if( toupper(ext[0])=='X' && toupper(ext[1])=='F' && toupper(ext[2])=='D' ) + if( image.filetype() == "xfd" ) { m_drv[id].type = FORMAT_XFD; m_drv[id].header_skip = 0; } else /* ATR extension */ - if( toupper(ext[0])=='A' && toupper(ext[1])=='T' && toupper(ext[2])=='R' ) + if( image.filetype() == "atr" ) { m_drv[id].type = FORMAT_ATR; m_drv[id].header_skip = 16; } else /* DSK extension */ - if( toupper(ext[0])=='D' && toupper(ext[1])=='S' && toupper(ext[2])=='K' ) + if( image.filetype() == "dsk" ) { m_drv[id].type = FORMAT_DSK; m_drv[id].header_skip = sizeof(atari_dsk_format); diff --git a/src/mame/machine/lynx.cpp b/src/mame/machine/lynx.cpp index 179ac99a40f..562c0e89407 100644 --- a/src/mame/machine/lynx.cpp +++ b/src/mame/machine/lynx.cpp @@ -2069,8 +2069,7 @@ DEVICE_IMAGE_LOAD_MEMBER( lynx_state, lynx_cart ) if (image.software_entry() == nullptr) { // check for lnx header - const char *filetype = image.filetype(); - if (!core_stricmp(filetype, "lnx")) + if (image.filetype() == "lnx") { // 64 byte header // LYNX @@ -2101,10 +2100,9 @@ DEVICE_IMAGE_LOAD_MEMBER( lynx_state, lynx_cart ) // set-up granularity if (image.software_entry() == nullptr) { - const char *filetype = image.filetype(); - if (!core_stricmp(filetype, "lnx")) // from header + if (image.filetype() == "lnx") // from header m_granularity = gran; - else if (!core_stricmp(filetype, "lyx")) + else if (image.filetype() == "lyx") { /* 2008-10 FP: FIXME: .lyx file don't have an header, hence they miss "lynx_granularity" (see above). What if bank 0 has to be loaded elsewhere? And what about bank 1? diff --git a/src/mame/machine/mbee.cpp b/src/mame/machine/mbee.cpp index 1ee06970321..034d498759f 100644 --- a/src/mame/machine/mbee.cpp +++ b/src/mame/machine/mbee.cpp @@ -2,7 +2,7 @@ // copyright-holders:Robbbert /*************************************************************************** - microbee.c + microbee.cpp machine driver Originally written by Juergen Buchmueller, Jan 2000 @@ -627,7 +627,7 @@ QUICKLOAD_LOAD_MEMBER( mbee_state, mbee ) UINT16 i, j; UINT8 data, sw = m_io_config->read() & 1; /* reading the config switch: 1 = autorun */ - if (!core_stricmp(image.filetype(), "mwb")) + if (image.filetype() == "mwb") { /* mwb files - standard basic files */ for (i = 0; i < quickload_size; i++) @@ -657,7 +657,7 @@ QUICKLOAD_LOAD_MEMBER( mbee_state, mbee ) else space.write_word(0xa2,0x8517); } - else if (!core_stricmp(image.filetype(), "com")) + else if (image.filetype() == "com") { /* com files - most com files are just machine-language games with a wrapper and don't need cp/m to be present */ for (i = 0; i < quickload_size; i++) @@ -681,7 +681,7 @@ QUICKLOAD_LOAD_MEMBER( mbee_state, mbee ) if (sw) m_maincpu->set_pc(0x100); } - else if (!core_stricmp(image.filetype(), "bee")) + else if (image.filetype() == "bee") { /* bee files - machine-language games that start at 0900 */ for (i = 0; i < quickload_size; i++)