Updated validity.c to current core style.

This commit is contained in:
Aaron Giles 2008-02-19 18:02:59 +00:00
parent 949599e0ff
commit 671afc2661

View File

@ -19,31 +19,25 @@
#include <zlib.h>
/*************************************
*
* Debugging
*
*************************************/
/***************************************************************************
DEBUGGING
***************************************************************************/
#define REPORT_TIMES (0)
/*************************************
*
* Constants
*
*************************************/
/***************************************************************************
CONSTANTS
***************************************************************************/
#define QUARK_HASH_SIZE 389
/*************************************
*
* Type definitions
*
*************************************/
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef struct _quark_entry quark_entry;
struct _quark_entry
@ -64,11 +58,9 @@ struct _quark_table
/*************************************
*
* Local variables
*
*************************************/
/***************************************************************************
GLOBAL VARIABLES
***************************************************************************/
static quark_table *source_table;
static quark_table *name_table;
@ -79,6 +71,15 @@ static quark_table *defstr_table;
/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/
/*-------------------------------------------------
input_port_string_from_index - return an
indexed string from the input port system
-------------------------------------------------*/
INLINE const char *input_port_string_from_index(UINT32 index)
{
input_port_token token;
@ -87,15 +88,53 @@ INLINE const char *input_port_string_from_index(UINT32 index)
}
/*-------------------------------------------------
quark_string_crc - compute the CRC of a string
-------------------------------------------------*/
/*************************************
*
* Allocate an array of quark
* entries and a hash table
*
*************************************/
INLINE UINT32 quark_string_crc(const char *string)
{
return crc32(0, (UINT8 *)string, (UINT32)strlen(string));
}
static quark_table *allocate_quark_table(UINT32 entries, UINT32 hashsize)
/*-------------------------------------------------
quark_add - add a quark to the table and
connect it to the hash tables
-------------------------------------------------*/
INLINE void quark_add(quark_table *table, int index, UINT32 crc)
{
quark_entry *entry = &table->entry[index];
int hash = crc % table->hashsize;
entry->crc = crc;
entry->next = table->hash[hash];
table->hash[hash] = entry;
}
/*-------------------------------------------------
quark_table_get_first - return a pointer to the
first hash entry connected to a CRC
-------------------------------------------------*/
INLINE quark_entry *quark_table_get_first(quark_table *table, UINT32 crc)
{
return table->hash[crc % table->hashsize];
}
/***************************************************************************
QUARK TABLES
***************************************************************************/
/*-------------------------------------------------
quark_table_alloc - allocate an array of
quark entries and a hash table
-------------------------------------------------*/
static quark_table *quark_table_alloc(UINT32 entries, UINT32 hashsize)
{
quark_table *table;
UINT32 total_bytes;
@ -118,73 +157,21 @@ static quark_table *allocate_quark_table(UINT32 entries, UINT32 hashsize)
}
/*-------------------------------------------------
quark_tables_create - build "quarks" for fast
string operations
-------------------------------------------------*/
/*************************************
*
* Compute the CRC of a string
*
*************************************/
INLINE UINT32 quark_string_crc(const char *string)
static void quark_tables_create(void)
{
return crc32(0, (UINT8 *)string, (UINT32)strlen(string));
}
/*************************************
*
* Add a quark to the table and
* connect it to the hash tables
*
*************************************/
INLINE void add_quark(quark_table *table, int index, UINT32 crc)
{
quark_entry *entry = &table->entry[index];
int hash = crc % table->hashsize;
entry->crc = crc;
entry->next = table->hash[hash];
table->hash[hash] = entry;
}
/*************************************
*
* Return a pointer to the first
* hash entry connected to a CRC
*
*************************************/
INLINE quark_entry *first_hash_entry(quark_table *table, UINT32 crc)
{
return table->hash[crc % table->hashsize];
}
/*************************************
*
* Build "quarks" for fast string
* operations
*
*************************************/
static void build_quarks(void)
{
int drivnum, strnum;
/* first count drivers */
for (drivnum = 0; drivers[drivnum]; drivnum++)
;
int drivnum = driver_list_get_count(drivers), strnum;
/* allocate memory for the quark tables */
source_table = allocate_quark_table(drivnum, QUARK_HASH_SIZE);
name_table = allocate_quark_table(drivnum, QUARK_HASH_SIZE);
description_table = allocate_quark_table(drivnum, QUARK_HASH_SIZE);
roms_table = allocate_quark_table(drivnum, QUARK_HASH_SIZE);
inputs_table = allocate_quark_table(drivnum, QUARK_HASH_SIZE);
source_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
name_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
description_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
roms_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
inputs_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
/* build the quarks and the hash tables */
for (drivnum = 0; drivers[drivnum]; drivnum++)
@ -192,34 +179,37 @@ static void build_quarks(void)
const game_driver *driver = drivers[drivnum];
/* fill in the quark with hashes of the strings */
add_quark(source_table, drivnum, quark_string_crc(driver->source_file));
add_quark(name_table, drivnum, quark_string_crc(driver->name));
add_quark(description_table, drivnum, quark_string_crc(driver->description));
quark_add(source_table, drivnum, quark_string_crc(driver->source_file));
quark_add(name_table, drivnum, quark_string_crc(driver->name));
quark_add(description_table, drivnum, quark_string_crc(driver->description));
/* only track actual driver ROM entries */
if (driver->rom && (driver->flags & GAME_NO_STANDALONE) == 0)
add_quark(roms_table, drivnum, (FPTR)driver->rom);
quark_add(roms_table, drivnum, (FPTR)driver->rom);
}
/* allocate memory for a quark table of strings */
defstr_table = allocate_quark_table(INPUT_STRING_COUNT, 97);
defstr_table = quark_table_alloc(INPUT_STRING_COUNT, 97);
/* add all the default strings */
for (strnum = 1; strnum < INPUT_STRING_COUNT; strnum++)
{
const char *string = input_port_string_from_index(strnum);
if (string != NULL)
add_quark(defstr_table, strnum, quark_string_crc(string));
quark_add(defstr_table, strnum, quark_string_crc(string));
}
}
/*************************************
*
* Validate inline functions
*
*************************************/
/***************************************************************************
VALIDATION FUNCTIONS
***************************************************************************/
/*-------------------------------------------------
validate_inlines - validate inline function
behaviors
-------------------------------------------------*/
static int validate_inlines(void)
{
@ -369,12 +359,10 @@ static int validate_inlines(void)
}
/*************************************
*
* Validate basic driver info
*
*************************************/
/*-------------------------------------------------
validate_driver - validate basic driver
information
-------------------------------------------------*/
static int validate_driver(int drivnum, const machine_config *drv)
{
@ -437,7 +425,7 @@ static int validate_driver(int drivnum, const machine_config *drv)
/* find duplicate driver names */
crc = quark_string_crc(driver->name);
for (entry = first_hash_entry(name_table, crc); entry; entry = entry->next)
for (entry = quark_table_get_first(name_table, crc); entry; entry = entry->next)
if (entry->crc == crc && entry != &name_table->entry[drivnum])
{
const game_driver *match = drivers[entry - name_table->entry];
@ -450,7 +438,7 @@ static int validate_driver(int drivnum, const machine_config *drv)
/* find duplicate descriptions */
crc = quark_string_crc(driver->description);
for (entry = first_hash_entry(description_table, crc); entry; entry = entry->next)
for (entry = quark_table_get_first(description_table, crc); entry; entry = entry->next)
if (entry->crc == crc && entry != &description_table->entry[drivnum])
{
const game_driver *match = drivers[entry - description_table->entry];
@ -466,7 +454,7 @@ static int validate_driver(int drivnum, const machine_config *drv)
if (driver->rom && (driver->flags & GAME_IS_BIOS_ROOT) == 0)
{
crc = (FPTR)driver->rom;
for (entry = first_hash_entry(roms_table, crc); entry; entry = entry->next)
for (entry = quark_table_get_first(roms_table, crc); entry; entry = entry->next)
if (entry->crc == crc && entry != &roms_table->entry[drivnum])
{
const game_driver *match = drivers[entry - roms_table->entry];
@ -483,12 +471,9 @@ static int validate_driver(int drivnum, const machine_config *drv)
}
/*************************************
*
* Validate ROM definitions
*
*************************************/
/*-------------------------------------------------
validate_roms - validate ROM definitions
-------------------------------------------------*/
static int validate_roms(int drivnum, const machine_config *drv, UINT32 *region_length)
{
@ -614,12 +599,9 @@ static int validate_roms(int drivnum, const machine_config *drv, UINT32 *region_
}
/*************************************
*
* Validate CPUs and memory maps
*
*************************************/
/*-------------------------------------------------
validate_cpu - validate CPUs and memory maps
-------------------------------------------------*/
static int validate_cpu(int drivnum, const machine_config *drv, const UINT32 *region_length)
{
@ -784,12 +766,10 @@ static int validate_cpu(int drivnum, const machine_config *drv, const UINT32 *re
}
/*************************************
*
* Validate display
*
*************************************/
/*-------------------------------------------------
validate_display - validate display
configurations
-------------------------------------------------*/
static int validate_display(int drivnum, const machine_config *drv)
{
@ -852,12 +832,10 @@ static int validate_display(int drivnum, const machine_config *drv)
}
/*************************************
*
* Validate graphics
*
*************************************/
/*-------------------------------------------------
validate_gfx - validate graphics decoding
configuration
-------------------------------------------------*/
static int validate_gfx(int drivnum, const machine_config *drv, const UINT32 *region_length)
{
@ -944,11 +922,10 @@ static int validate_gfx(int drivnum, const machine_config *drv, const UINT32 *re
}
/*************************************
*
* Display valid coin order
*
*************************************/
/*-------------------------------------------------
display_valid_coin_order - display the
correct coin order
-------------------------------------------------*/
static void display_valid_coin_order(int drivnum, const input_port_entry *memory)
{
@ -969,7 +946,7 @@ static void display_valid_coin_order(int drivnum, const input_port_entry *memory
/* hash the string and look it up in the string table */
crc = quark_string_crc(inp->name);
for (entry = first_hash_entry(defstr_table, crc); entry; entry = entry->next)
for (entry = quark_table_get_first(defstr_table, crc); entry; entry = entry->next)
if (entry->crc == crc && !strcmp(inp->name, input_port_string_from_index(entry - defstr_table->entry)))
{
strindex = entry - defstr_table->entry;
@ -1005,11 +982,9 @@ static void display_valid_coin_order(int drivnum, const input_port_entry *memory
}
/*************************************
*
* Validate input ports
*
*************************************/
/*-------------------------------------------------
validate_inputs - validate input configuration
-------------------------------------------------*/
static int validate_inputs(int drivnum, const machine_config *drv, input_port_entry **memory)
{
@ -1030,12 +1005,12 @@ static int validate_inputs(int drivnum, const machine_config *drv, input_port_en
/* skip if we already validated these ports */
crc = (FPTR)driver->ipt;
for (entry = first_hash_entry(inputs_table, crc); entry; entry = entry->next)
for (entry = quark_table_get_first(inputs_table, crc); entry; entry = entry->next)
if (entry->crc == crc && driver->ipt == drivers[entry - inputs_table->entry]->ipt)
return FALSE;
/* otherwise, add ourself to the list */
add_quark(inputs_table, drivnum, crc);
quark_add(inputs_table, drivnum, crc);
/* allocate the input ports */
*memory = input_port_allocate(driver->ipt, *memory);
@ -1196,7 +1171,7 @@ static int validate_inputs(int drivnum, const machine_config *drv, input_port_en
/* hash the string and look it up in the string table */
crc = quark_string_crc(inp->name);
for (entry = first_hash_entry(defstr_table, crc); entry; entry = entry->next)
for (entry = quark_table_get_first(defstr_table, crc); entry; entry = entry->next)
if (entry->crc == crc && !strcmp(inp->name, input_port_string_from_index(entry - defstr_table->entry)))
{
strindex = entry - defstr_table->entry;
@ -1285,12 +1260,10 @@ static int validate_inputs(int drivnum, const machine_config *drv, input_port_en
}
/*************************************
*
* Validate sound and speakers
*
*************************************/
/*-------------------------------------------------
validate_sound - validate sound and
speaker configuration
-------------------------------------------------*/
static int validate_sound(int drivnum, const machine_config *drv)
{
@ -1356,12 +1329,9 @@ static int validate_sound(int drivnum, const machine_config *drv)
}
/*************************************
*
* Master validity checker
*
*************************************/
/*-------------------------------------------------
mame_validitychecks - master validity checker
-------------------------------------------------*/
int mame_validitychecks(const game_driver *curdriver)
{
@ -1423,7 +1393,7 @@ int mame_validitychecks(const game_driver *curdriver)
/* prepare by pre-scanning all the drivers and adding their info to hash tables */
prep -= osd_profiling_ticks();
build_quarks();
quark_tables_create();
prep += osd_profiling_ticks();
/* iterate over all drivers */