summaryrefslogtreecommitdiffstatshomepage
path: root/src/build/makelist.c
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2011-04-13 20:31:00 +0000
committer Aaron Giles <aaron@aarongiles.com>2011-04-13 20:31:00 +0000
commit00d745ca7752d2f96e842a7f23e157c0d2c40bdf (patch)
tree9b6a3dcda7d0ff05b098fe0823fe4d09f6d0e6b4 /src/build/makelist.c
parentf99e1a5da63f996cd07fae98d42c2e5ff389adef (diff)
(Big tangle of changes that all happened as I was looking into the ROM
loader rewrite, which is still in progress....) Replaced mamedriv.c with a new driver list mechanism that is generated by the build tools. The emulator core now expects the presence of a file called src/$(TARGET)/$(SUBTARGET).lst which is just a raw list of driver names, one per line. C and C++ comments are still permitted. This file is parsed by a new build tool makelist which extracts the driver names, sorts them, and generates a file called drivlist.c, which is consumed by the core. [Aaron Giles] Added new osdcore function osd_malloc_array() which is identical to osd_malloc() but obviously hints that the underlying allocation is for an array. Updated all callers to use the appropriate form. Modified the Windows allocator to only use guard pages for array-style allocations, allowing us to enable them once again in debug builds. [Aaron Giles] Created new static class driver_list to wrap accesses to the list of available drivers. Improved speed of driver lookups by relying on the presorting done by makelist. [Aaron Giles] Created helper class driver_enumerator as a helper for iterating through the list of drivers. This class supports basic filtering and iteration, and also serves as a temporary cache of machine_configs. [Aaron Giles] Created cli_frontend object to wrap all the CLI handling code in clifront.c. Updated/simplified all the code to take advantage of the driver_enumerator. [Aaron Giles] Created media_auditor object to wrap all the auditing functions in audit.c. Updated all users to the new interface. Note that the new auditing mechanism is slightly out of sync with the romload code in terms of finding ROMs owned by devices, so it may mis-report some issues until the new ROM loading code is in. [Aaron Giles] Added concept of a per-device searchpath. For most devices, their searchpath is just the short name of the device. For driver_devices, the searchpath is driver[;parent[;bios]]. This searchpath will eventually be used by the rom loader to find ROMs. For now it is used by the media auditor only. [Aaron Giles] Created info_xml_creator object to wrap all the info generation functions in info.c. Converted the file to C++ and cleaned up the input processing code. [Aaron Giles] (not for whatsnew ... Known issues: auditing of CHDs appears busted, and debug builds report unfreed memory if you use the built-in game picker)
Diffstat (limited to 'src/build/makelist.c')
-rw-r--r--src/build/makelist.c203
1 files changed, 203 insertions, 0 deletions
diff --git a/src/build/makelist.c b/src/build/makelist.c
new file mode 100644
index 00000000000..c28a14a61e8
--- /dev/null
+++ b/src/build/makelist.c
@@ -0,0 +1,203 @@
+/***************************************************************************
+
+ makelist.c
+
+ Create and sort the driver list.
+
+****************************************************************************
+
+ Copyright Aaron Giles
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name 'MAME' nor the names of its contributors may be
+ used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+***************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include "corefile.h"
+
+
+#define MAX_DRIVERS 65536
+
+static const char *drivlist[MAX_DRIVERS];
+
+
+//-------------------------------------------------
+// driver_sort_callback - compare two items in
+// a string array
+//-------------------------------------------------
+
+int sort_callback(const void *elem1, const void *elem2)
+{
+ const char **item1 = (const char **)elem1;
+ const char **item2 = (const char **)elem2;
+ return strcmp(*item1, *item2);
+}
+
+
+//-------------------------------------------------
+// main - primary entry point
+//-------------------------------------------------
+
+int main(int argc, char *argv[])
+{
+ // needs at least 1 argument
+ if (argc < 2)
+ {
+ fprintf(stderr,
+ "Usage:\n"
+ " makelist <source.lst>\n"
+ );
+ return 0;
+ }
+
+ // extract arguments
+ const char *srcfile = argv[1];
+
+ // read source file
+ void *buffer;
+ UINT32 length;
+ file_error filerr = core_fload(srcfile, &buffer, &length);
+ if (filerr != FILERR_NONE)
+ {
+ fprintf(stderr, "Unable to read source file '%s'\n", srcfile);
+ return 1;
+ }
+
+ // rip through it to find all drivers
+ int drivcount = 0;
+ char *srcptr = (char *)buffer;
+ char *endptr = srcptr + length;
+ int linenum = 1;
+ bool in_comment = false;
+ while (srcptr < endptr)
+ {
+ char c = *srcptr++;
+
+ // count newlines
+ if (c == 13 || c == 10)
+ {
+ if (c == 13 && *srcptr == 10)
+ srcptr++;
+ linenum++;
+ continue;
+ }
+
+ // skip any spaces
+ if (isspace(c))
+ continue;
+
+ // look for end of C comment
+ if (in_comment && c == '*' && *srcptr == '/')
+ {
+ srcptr++;
+ in_comment = false;
+ continue;
+ }
+
+ // skip anything else inside a C comment
+ if (in_comment)
+ continue;
+
+ // look for start of C comment
+ if (c == '/' && *srcptr == '*')
+ {
+ srcptr++;
+ in_comment = true;
+ continue;
+ }
+
+ // if we hit a C++ comment, scan to the end of line
+ if (c == '/' && *srcptr == '/')
+ {
+ while (srcptr < endptr && *srcptr != 13 && *srcptr != 10)
+ srcptr++;
+ continue;
+ }
+
+ // extract the driver name
+ char drivname[32];
+ drivname[0] = 0;
+ srcptr--;
+ for (int pos = 0; srcptr < endptr && pos < ARRAY_LENGTH(drivname) - 1 && !isspace(*srcptr); pos++)
+ {
+ drivname[pos] = *srcptr++;
+ drivname[pos+1] = 0;
+ }
+
+ // verify the name as valid
+ for (char *drivch = drivname; *drivch != 0; drivch++)
+ {
+ if ((*drivch >= 'a' && *drivch <= 'z') || (*drivch >= '0' && *drivch <= '9') || *drivch == '_')
+ continue;
+ fprintf(stderr, "%s:%d - Invalid character '%c' in driver \"%s\"\n", srcfile, linenum, *drivch, drivname);
+ return 1;
+ }
+
+ // add it to the list
+ char *name = (char *)malloc(strlen(drivname) + 1);
+ strcpy(name, drivname);
+ drivlist[drivcount++] = name;
+ }
+
+ // add a reference to the ___empty driver
+ drivlist[drivcount++] = "___empty";
+
+ // output a count
+ if (drivcount == 0)
+ {
+ fprintf(stderr, "No drivers found\n");
+ return 1;
+ }
+ fprintf(stderr, "%d drivers found\n", drivcount);
+
+ // sort the list
+ qsort(drivlist, drivcount, sizeof(*drivlist), sort_callback);
+
+ // start with a header
+ printf("#include \"emu.h\"\n\n");
+
+ // output the list of externs first
+ for (int index = 0; index < drivcount; index++)
+ printf("GAME_EXTERN(%s);\n", drivlist[index]);
+ printf("\n");
+
+ // then output the array
+ printf("const game_driver * const driver_list::s_drivers_sorted[%d] =\n", drivcount);
+ printf("{\n");
+ for (int index = 0; index < drivcount; index++)
+ printf("\t&GAME_NAME(%s)%s\n", drivlist[index], (index == drivcount - 1) ? "" : ",");
+ printf("};\n");
+ printf("\n");
+
+ // also output a global count
+ printf("int driver_list::s_driver_count = %d;\n", drivcount);
+
+ return 0;
+}