Commit Graph

58 Commits

Author SHA1 Message Date
Vas Crabb
4cf33cfe0a Various optimisations to code generaton.
util/bitmap.cpp, util/palette.cpp: Marked lots of things constexpr.
Bitmaps don't throw exceptions on allocation failure, they just become
invalid.  Almost nothing in MAME actually checks for this.

emu/profiler.cpp: Abort if the profile stack overflows rather than
throwing an exception.  This is a developer feature and if it overflows,
the code is broken.  Calling a noreturn noexcept function generates less
code than throwing an exception, which adds up.

util/strformat.cpp: Traded away some unnecessary flexibility for more
compact code.  The stream objects must derive from std::basic_ostream
now - they can't just be any old objects with the expected operators.
2023-03-26 01:32:50 +11:00
AJR
2db924e5ec fileio.cpp: Remove optional second argument of path_iterator::next 2022-02-17 17:28:31 -05:00
Vas Crabb
aeb9eae874
util: Further API cleanups: (#8661)
* Turned `core_file` into an implementation of `random_read_write`.
* Turned PNG errors into a standard error category.
* Added a helper for generating what look like derived classes on-the-fly.
2021-10-05 03:34:45 +11:00
Vas Crabb
e8bbea1fc6
formats, osd, util: Started refactoring file I/O stuff. (#8456)
Added more modern generic I/O interfaces with implementation backed by stdio, osd_file and core_file, replacing io_generic.  Also replaced core_file's build-in zlib compression with a filter.

unzip.cpp, un7z.cpp: Added option to supply abstract I/O interface rather than filename.

Converted osd_file, core_file, archive_file, chd_file and device_image_interface to use std::error_condition rather than their own error enums.

Allow mounting TI-99 RPK from inside archives.
2021-08-22 09:06:15 +10:00
AJR
f806cfd21c render/bgfx: Fix failure to load texture .png files when -artpath contains multiple directories 2021-02-03 17:45:37 -05:00
AJR
91921618c2 Much more core std::string_view modernization
- Remove corestr.h from emu.h; update a few source files to not use it at all
- Change strtrimspace, strtrimrightspace and core_filename_extract_* to be pure functions taking a std::string_view by value and returning the same type
- Change strmakeupper and strmakelower to be pure functions taking a std::string_view and constructing a std::string
- Remove the string-modifying version of zippath_parent
- Change tag-based lookup functions in device_t to take std::string_view instead of const std::string & or const char *
- Remove the subdevice tag cache from device_t (since device finders are now recommended) and replace it with a map covering directly owned subdevices only
- Move the working directory setup method out of device_image_interface (only the UI seems to actually use the full version of this)
- Change output_manager to use std::string_view for output name arguments
- Change core_options to accept std::string_view for most name and value arguments (return values are still C strings for now)
- Change miscellaneous other functions to accept std::string_view arguments
- Remove a few string accessor macros from romload.h
- Remove many unnecessary c_str() calls from logging/error messages
2021-01-20 18:06:15 -05:00
AJR
aa29519528 Further additions of std::string_view
- corefile.cpp, fileio.cpp: Change puts to take a std::string_view parameter
- rendlay.cpp: Use std::string_view instead of bare pointers in various functions
- vecstream.h: Add std::string_view conversion operator to obtain output buffer without needing to make it a C string with explicit null termination
- xmlfile.cpp: Add get_attribute_string_ptr method that distinguishes between empty strings and absent attributes without falling back to C strings
2021-01-01 12:22:17 -05:00
Vas Crabb
cf078d736a ROM loading cleanup:
* More flexible constructors for path_iterator and emu_file
* More straightforward system/device ROM loading and software loading when using ROM loader
* Proper parent walk when searching for identical CHDs with different names from software list
* Fixed hangs if software item parents form a loop
* Fixed layouts being loaded from bogus empty paths

Note that there are changes in behaviour:
* For software list ROMs/disks, MAME will now search the software path before searching the machine path
* The search path for the owner of the software list device is used, which may not be the driver itself
* MAME will no longer load loose CHDs from the media path - it's just too unwieldy with the number of supported systems
* MAME will no longer search archives above the top level of the media path
2020-04-15 02:20:23 +10:00
Vas Crabb
9c600695f0 (nw) Cleanup on the way:
* Add doxygen comments for bit manipulation functions
* Add an overload of BIT that works like the AArch64 UBFX instruction
* Kill off some of the silly concatenating overloads for emu_file::open
* Make searchpath acually useful for devices

This is a checkpoint - I'm planning to improve ROM loading behaviour at
least a little.
2020-03-10 18:21:10 +11:00
Vas Crabb
96c9112785 general cleanup:
* move rarely-used output and pty interfaces out of emu.h
* consolidate and de-duplicate forward declarations, also remove some obsolete ones
* clean up more #include guard macros
* scope down a few more things

(nw) Everyone, please keep forward declarations for src/emu in src/emu/emufwd.h -
this will make it far easier to keep them in sync with declarations than having
them scattered through all the other files.
2017-05-23 15:01:11 +10:00
Vas Crabb
8179a84458 Introduce u8/u16/u32/u64/s8/s16/s32/s64
* New abbreviated types are in osd and util namespaces, and also in global namespace for things that #include "emu.h"
* Get rid of import of cstdint types to global namespace (C99 does this anyway)
* Remove the cstdint types from everything in emu
* Get rid of U64/S64 macros
* Fix a bug in dps16 caused by incorrect use of macro
* Fix debugcon not checking for "do " prefix case-insensitively
* Fix a lot of messed up tabulation
* More constexpr
* Fix up many __names
2016-11-19 05:38:48 +11:00
Miodrag Milanovic
ddb290d5f6 NOTICE (TYPE NAME CONSOLIDATION)
Use standard uint64_t, uint32_t, uint16_t or uint8_t instead of UINT64, UINT32, UINT16 or UINT8
also use standard int64_t, int32_t, int16_t or int8_t instead of INT64, INT32, INT16 or INT8
2016-10-22 13:13:17 +02:00
Miodrag Milanovic
d2e8f61149 dynamic_buffer is just std::vector<UINT8> (nw) 2016-10-21 12:35:05 +02:00
Vas Crabb
563690f545 make path_iterator hold onto its search path 2016-08-19 15:23:31 +10:00
Nathan Woods
a7bfc73cfb Changed various string arguments for emu_file::open() from 'const char *' to std::string 2016-07-29 20:53:46 -04:00
Nathan Woods
4aa0ab1724 Moved src/emu/hash.[cpp|h] into src/lib/util, and namespaced that code (and hashing.[cpp|h]) into util:: 2016-07-23 12:49:33 -04:00
Vas Crabb
5cee9e9bc4 POSIX implementation for new directory read features, cleanup of Windows implementation, return directory handle as smart pointer, fix full build [Vas Crabb] 2016-06-25 03:35:23 +10:00
Nathan Woods
cd8b414e6b C++-ified osd_directory (now osd::directory), and added last_modified to osd::directory::entry 2016-06-24 07:13:18 -04:00
Miodrag Milanovic
89c5e1f681 Various cleanups suggested by static analyzer (nw) 2016-04-24 12:58:31 +02:00
Vas Crabb
54279dbf11 Make emu_file archive searh order CRC+path, CRC+partial path, CRC, path, partial path and fold some redundant code 2016-03-25 15:25:30 +11:00
Vas Crabb
142292ee00 Fold some redundant code 2016-03-18 20:37:44 +11:00
Vas Crabb
100fa28671 * Remove confusing method from vectorstreams that hide base_ios method (fixes disassembly view)
* Allow std::string to pass through core_file unmolested (reduces temporary allocations)
* Make zip/7z instances of same class with uniform interface
* zippath browsing is broken at the moment

This is another step towards transparent archive support.  It's now
possible to access zip and 7z archives with the same code.  Nothing is
taking advantage of it yet.  There's now some very similar code in
fileio.cpp and clifront.cpp that could be folded at some point.
2016-03-18 19:32:10 +11:00
Vas Crabb
42fbb9c396 Make osd_file a polymorphic class that's held with smart pointers
Make avi_file a class that's held with smart pointers, encapsulate various AVI I/O structures
Make zip_file and _7z_file classes rather than having free functions everywhere
Hide zip/7z class implementation behind an interface, no longer need to call close() to send back to the cache
Don't dump as much crap in global namespace
Add solaris PTY implementation
Improve variable expansion for SDL OSD - supports ~/$FOO/${BAR} syntax
Rearrange stuff so the same things are in file module for all OSDs
Move file stuff into its own module

7z/zip open and destruct are still not thread-safe due to lack of interlocks around cache access
Directory functions still need to be moved to file module
SDL OSD may not initialise WinSock on Windows
2016-03-14 18:55:00 +11:00
Vas Crabb
5aea0893a0 Use type-safe printf for core_file and emu_file, surprisingly few knock-on effects
Properly fix up a couple of places I64FMT was being used, still more to deal with
2016-03-09 23:04:12 +11:00
Vas Crabb
73b44c9429 Turn core_file into a proper class that gets cleaned up safely using unique_ptr
Subverted somewhat by chd_file class
2016-03-06 21:49:56 +11:00
Vas Crabb
ba960afb5f Add function for flushing file buffers 2016-03-01 07:38:14 +11:00
Miodrag Milanovic
91605d3f4d clang-modernize part 1 (nw) 2015-12-03 18:17:25 +01:00
Miodrag Milanovic
54f8b3ae5d moved all to std::string (nw) 2015-04-22 11:30:45 +02:00
Miodrag Milanovic
7faba31b1b There is no implicit conversion to char* in std::string (nw) 2015-04-12 08:05:43 +02:00
Miodrag Milanovic
6ae44e46f9 Cleanups and version bump 2015-02-25 08:09:13 +01:00
Miodrag Milanovic
be88bed238 Better performance for -verifyroms on samba share [qmc2] 2015-02-12 18:36:34 +01:00
Aaron Giles
4ea9df02a1 Moved core template container classes up from emutempl.h to coretmpl.h:
[Aaron Giles]
 * these classes now no longer take a resource_pool; everything is
    managed globally -- this means that objects added to lists must be
    allocated with global_alloc
 * added new auto_pointer<> template which wraps a pointer and auto-frees
    it upon destruction; it also defaults to NULL so it doesn't need to
    be explicitly initialized
 * moved tagged_list template to tagmap.h

Redo of the low-level memory tracking system: [Aaron Giles]
 * moved low-level tracking out of emu\emualloc into lib\util\corealloc
    so it can be shared among all components and used by core libraries
 * global_alloc and friends no longer use a resource pool to track
    allocations; turns out this was a wholly redundant system that wasted
    a lot of memory
 * removed global_resource_pool entirely
 * added global_free_array to delete arrays allocated with 
    global_alloc_array
 * added tracking of object versus array allocation; we will now error
    if you use global_free on an array, or global_free_array on an object

Added new utility helper const_string_pool which can be used to 
efficiently accumulate strings that are not intended to be modified.
Used by updated makelist and software list code. [Aaron Giles]

Updated png2bdc and makelist tools to not leak memory and use more modern
techniques (no more MAX_DRIVERS in makelist, for example). [Aaron Giles]

Deprecated auto_strdup and removed all uses by way of caller-managed 
astrings and the software list rewrite. [Aaron Giles]

Rewrote software list management: [Aaron Giles]
 * removed the notion of a software_list that is separate from a
    software_list_device; they are one and the same now
 * moved several functions into device_image_interface since they really
    didn't belong in the core software list class
 * lots of simplification as a result of the above changes

Additional notes (no whatsnew):

Moved definition of FPTR to osdcomm.h.

Some changes happened in the OSD code to fix issues, especially regarding
freeing arrays. SDL folks may need to fix up some of these.

The following devices still are using tokens and should be modernized
(I found them because they kept their token as void * and tried to
delete it, which you can't):

namco_52xx_device (mame/audio/namco52.c)
namco_54xx_device (mame/audio/namco54.c)
namco_06xx_device (mame/machine/namco06.c)
namco_50xx_device (mame/machine/namco50.c)
namco_51xx_device (mame/machine/namco51.c)
namco_53xx_device (mame/machine/namco53.c)
voodoo_device (emu/video/voodoo.c)
mos6581_device (emu/sound/mos6581.c)
aica_device (emu/sound/aica.c)
scsp_device (emu/sound/scsp.c)
dmadac_sound_device (emu/sound/dmadac.c)
s3c2440_device (emu/machine/s3c2440.c)
wd1770_device (emu/machine/wd17xx.c)
latch8_device (emu/machine/latch8.c)
duart68681_device (emu/machine/68681.c)
s3c2400_device (emu/machine/s3c2400.c)
s3c2410_device (emu/machine/s3c2410.c)
strataflash_device (mess/machine/strata.c)
hd63450_device (mess/machine/hd63450.c)
tap_990_device (mess/machine/ti99/990_tap.c)
omti8621_device (mess/machine/omti8621.c)
vdt911_device (mess/video/911_vdt.c)
apollo_graphics_15i (mess/video/apollo.c)
asr733_device (mess/video/733_asr.c)
2014-03-11 15:54:58 +00:00
Oliver Stöneberg
5278254236 rest of ATTR_PRINTF review (nw) 2014-02-25 12:25:33 +00:00
Aaron Giles
5d0ce54f9e Bulk convert files that already had standard BSD license in my name
to new license tagged form.
2013-10-16 08:14:49 +00:00
Oliver Stöneberg
03379e4ab6 (MESS) fixed clang 3.2 warnings about unused private fields (nw) 2013-03-20 00:31:11 +00:00
Miodrag Milanovic
0e19f641d3 Cleanups and version bump 2013-01-11 07:32:46 +00:00
Aaron Giles
ab97dc30ef First pass at modernizing struct definitions. 2012-09-15 21:47:30 +00:00
R. Belmont
d75dbab0de Add LZMA codec and .7z container support [David Haywood, R. Belmont] 2012-02-12 17:55:51 +00:00
R. Belmont
c27b8e0784 Fix for systems where getc() is a #define rather than a function [ElBarto] 2011-09-25 14:46:07 +00:00
Aaron Giles
a7eef6130f path_iterator::next() now takes an optional filename to append to
the path.
2011-03-14 16:10:04 +00:00
Aaron Giles
06ee6804dd Converted core_options to a class. Removed a bunch of marginal
functionality in favor of alternate mechanisms. Errors are
now reported via an astring rather than via callbacks. Every
option must now specify a type (command, integer, float, string,
boolean, etc). Command behavior has changed so that only one
command is permitted. [Aaron Giles]

Changed fileio system to accept just a raw searchpath instead of
an options/option name combination. [Aaron Giles]

Created emu_options class dervied from core_options which wraps
core emulator options. Added mechanisms to cleanly change the
system name and add/remove system-specific options, versus the
old way using callbacks. Also added read accessors for all the
options, to ensure consistency in how parameters are handled.
Changed most core systems to access emu_options instead of
core_options. Also changed machine->options() to return emu_options.
[Aaron Giles]
 
Created cli_options class derived from emu_options which adds the
command-line specific options. Updated clifront code to leverage
the new class and the new core behaviors. cli_execute() now accepts
a cli_options object when called. [Aaron Giles]

Updated both SDL and Windows to have their own options classes,
derived from cli_options, which add the OSD-specific options on
top of everything else. Added accessors for all the options so
that queries are strongly typed and simplified. [Aaron Giles]

Out of whatsnew: I've surely screwed up some stuff, though I have
smoke tested a bunch of things. Let me know if you hit anything odd.
Also I know this change will impact the WINUI stuff, please let me 
know if there are issues. All the functionality necessary should 
still be present. If it's not obvious, please talk to me before 
adding stuff to the core_options class.
2011-03-03 17:05:24 +00:00
Aaron Giles
9ef0bcf8f2 Cleanups and version bump. 2011-02-28 09:27:05 +00:00
Aaron Giles
5e4df8c772 Hash generation and general cleanup. New class hash_collection holds
and manages a collection of hashes, and can be built from an internal
format string which is stored with each ROM. All core instances are
cleaned up to use the new interfaces, but it's likely that hashfile
code in MESS will need an update.

Also compacted the form of the hash strings used for ROMs, and fixed
verification/hashing of non-ZIPped files.
2011-02-14 08:41:08 +00:00
Aaron Giles
1b54456be5 mame_file is now emu_file and is a class. It is required
to pass a core_options object to the constructor, along with
a search path. This required pushing either a running_machine
or a core_options through some code that wasn't previously
ready to handle it. emu_files can be reused over multiple 
open/close sessions, and a lot of core code cleaned up
nicely as things were converted to them.

Also created a file_enumerator class for iterating over files
in a searchpath. This replaces the old mame_openpath functions.

Changed machine->options() to return a reference.

Removed public nvram_open() and fixed jchan/kaneko16 to
stop directly saving NVRAM.

Removed most of the mame_options() calls; this will soon go 
away entirely, so don't add any more.

Added core_options to device_validity_check() so they can be
used to validate things.
2011-02-12 03:47:37 +00:00
Miodrag Milanovic
33b47edf95 - Fixed issue with image empty slot [Miodrag Milanovic]
- Default for writeconfig is now 0 for MESS since it is not needed anymore
- Fixed handling of mounted devices on hard reset
- Unified some emuopts code, and removed ifdefs
2010-11-26 13:50:56 +00:00
Aaron Giles
4498faacd9 First round of an attempted cleanup of header files in the system.
- Created new central header "emu.h"; this should be included
    by pretty much any driver or device as the first include. This
    file in turn includes pretty much everything a driver or device
    will need, minus any other devices it references. Note that
    emu.h should *never* be included by another header file.
 - Updated all files in the core (src/emu) to use emu.h.
 - Removed a ton of redundant and poorly-tracked header includes
    from within other header files.
 - Temporarily changed driver.h to map to emu.h until we update
    files outside of the core.

Added class wrapper around tagmap so it can be directly included
and accessed within objects that need it. Updated all users to
embed tagmap objects and changed them to call through the class.

Added nicer functions for finding devices, ports, and regions in
a machine:

   machine->device("tag") -- return the named device, or NULL
   machine->port("tag") -- return the named port, or NULL
   machine->region("tag"[, &length[, &flags]]) -- return the
      named region and optionally its length and flags
      
Made the device tag an astring. This required touching a lot of 
code that printed the device to explicitly fetch the C-string
from it. (Thank you gcc for flagging that issue!)
2010-01-10 00:29:26 +00:00
Aaron Giles
a92de5930c Extended the astring class wrapper into something useful, and
useable as a stack object. Also designed the interfaces to allow
for chaining operations. And added a casting operator to const
char * for seamless use in most functions that take plain old C
strings.

Changed all uses of astring to use the object directly on the
stack or embedded in objects instead of explicitly allocating 
and deallocating it. Removed a lot of annoying memory management
code as a result.

Changed interfaces that accepted/returned an astring * to
use an astring & instead.

Removed auto_alloc_astring(machine). Use 
auto_alloc(machine, astring) instead.
2010-01-08 17:18:54 +00:00
Aaron Giles
91a1b8d634 NOTE: This change requires two new osd functions: osd_malloc() and
osd_free(). They take the same parameters as malloc() and free().

Renamed mamecore.h -> emucore.h.

New C++-aware memory manager, implemented in emualloc.*. This is a
simple manager that allows you to add any type of object to a
resource pool. Most commonly, allocated objects are added, and so
a set of allocation macros is provided to allow you to manage
objects in a particular pool:

  pool_alloc(p, t) = allocate object of type 't' and add to pool 'p'
  pool_alloc_clear(p, t) = same as above, but clear the memory first
  pool_alloc_array(p, t, c) = allocate an array of 'c' objects of type
                              't' and add to pool 'p'
  pool_alloc_array_clear(p, t, c) = same, but with clearing
  pool_free(p, v) = free object 'v' and remove it from the pool

Note that pool_alloc[_clear] is roughly equivalent to "new t" and
pool_alloc_array[_clear] is roughly equivalent to "new t[c]". Also
note that pool_free works for single objects and arrays.

There is a single global_resource_pool defined which should be used
for any global allocations. It has equivalent macros to the pool_*
macros above that automatically target the global pool.

In addition, the memory module defines global new/delete overrides
that access file and line number parameters so that allocations can
be tracked. Currently this tracking is only done if MAME_DEBUG is
enabled. In debug builds, any unfreed memory will be printed at
the end of the session.

emualloc.h also has #defines to disable malloc/free/realloc/calloc.
Since emualloc.h is included by emucore.h, this means pretty much
all code within the emulator is forced to use the new allocators.
Although straight new/delete do work, their use is discouraged, as
any allocations made with them will not be tracked.

Changed the familar auto_alloc_* macros to map to the resource pool
model described above. The running_machine is now a class and contains
a resource pool which is automatically destructed upon deletion. If
you are a driver writer, all your allocations should be done with
auto_alloc_*.

Changed all drivers and files in the core using malloc/realloc or the 
old alloc_*_or_die macros to use (preferably) the auto_alloc_* macros 
instead, or the global_alloc_* macros if necessary.

Added simple C++ wrappers for astring and bitmap_t, as these need
proper constructors/destructors to be used for auto_alloc_astring and
auto_alloc_bitmap.

Removed references to the winalloc prefix file. Most of its 
functionality has moved into the core, save for the guard page 
allocations, which are now implemented in osd_alloc and osd_free.
2010-01-08 06:05:29 +00:00
Aaron Giles
a0dc0e0196 Added new function mame_fclose_and_open_next() which will close a file
and then keep searching the searchpath for the next valid file. Did some
internal rearranging in fileio.c to make this work.

Changed cheat search so that it loads *all* cheat files in all search
paths. Note that it is easy to end up with duplicate entries this way.
Some currently disabled code is present which filters out duplicates,
but the logic for doing this is quite unclear with the presence of
text-only cheats, which is why the code is disabled for now.
2009-09-03 15:54:07 +00:00
Fabio Priuli
1e5f2af24f Fixed remaining occurrences of crsshairpath 2009-07-14 07:06:24 +00:00