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.
This commit is contained in:
Aaron Giles 2010-01-08 06:05:29 +00:00
parent 26ef635515
commit 91a1b8d634
203 changed files with 1766 additions and 2118 deletions

6
.gitattributes vendored
View File

@ -564,6 +564,8 @@ src/emu/eigccppc.h svneol=native#text/plain
src/emu/eigccx86.h svneol=native#text/plain src/emu/eigccx86.h svneol=native#text/plain
src/emu/eminline.h svneol=native#text/plain src/emu/eminline.h svneol=native#text/plain
src/emu/emu.mak svneol=native#text/plain src/emu/emu.mak svneol=native#text/plain
src/emu/emucore.c svneol=native#text/plain
src/emu/emucore.h svneol=native#text/plain
src/emu/emuopts.c svneol=native#text/plain src/emu/emuopts.c svneol=native#text/plain
src/emu/emuopts.h svneol=native#text/plain src/emu/emuopts.h svneol=native#text/plain
src/emu/emupal.c svneol=native#text/plain src/emu/emupal.c svneol=native#text/plain
@ -745,8 +747,6 @@ src/emu/machine/z80sio.c svneol=native#text/plain
src/emu/machine/z80sio.h svneol=native#text/plain src/emu/machine/z80sio.h svneol=native#text/plain
src/emu/mame.c svneol=native#text/plain src/emu/mame.c svneol=native#text/plain
src/emu/mame.h svneol=native#text/plain src/emu/mame.h svneol=native#text/plain
src/emu/mamecore.c svneol=native#text/plain
src/emu/mamecore.h svneol=native#text/plain
src/emu/mconfig.c svneol=native#text/plain src/emu/mconfig.c svneol=native#text/plain
src/emu/mconfig.h svneol=native#text/plain src/emu/mconfig.h svneol=native#text/plain
src/emu/memconv.h svneol=native#text/plain src/emu/memconv.h svneol=native#text/plain
@ -765,8 +765,6 @@ src/emu/rendlay.c svneol=native#text/plain
src/emu/rendlay.h svneol=native#text/plain src/emu/rendlay.h svneol=native#text/plain
src/emu/rendutil.c svneol=native#text/plain src/emu/rendutil.c svneol=native#text/plain
src/emu/rendutil.h svneol=native#text/plain src/emu/rendutil.h svneol=native#text/plain
src/emu/restrack.c svneol=native#text/plain
src/emu/restrack.h svneol=native#text/plain
src/emu/romload.c svneol=native#text/plain src/emu/romload.c svneol=native#text/plain
src/emu/romload.h svneol=native#text/plain src/emu/romload.h svneol=native#text/plain
src/emu/sndintrf.h svneol=native#text/plain src/emu/sndintrf.h svneol=native#text/plain

View File

@ -9,7 +9,7 @@
***************************************************************************/ ***************************************************************************/
#include "mamecore.h" #include "emucore.h"
#include "attotime.h" #include "attotime.h"
#include "eminline.h" #include "eminline.h"

View File

@ -36,7 +36,7 @@
#ifndef __ATTOTIME_H__ #ifndef __ATTOTIME_H__
#define __ATTOTIME_H__ #define __ATTOTIME_H__
#include "mamecore.h" #include "emucore.h"
#include "eminline.h" #include "eminline.h"
#include <math.h> #include <math.h>

View File

@ -88,7 +88,7 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid
if (records > 0) if (records > 0)
{ {
/* allocate memory for the records */ /* allocate memory for the records */
*audit = alloc_array_clear_or_die(audit_record, records); *audit = global_alloc_array_clear(audit_record, records);
record = *audit; record = *audit;
/* iterate over ROM sources and regions */ /* iterate over ROM sources and regions */
@ -129,7 +129,7 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid
/* if we found nothing, we don't have the set at all */ /* if we found nothing, we don't have the set at all */
if (!anyfound && anyrequired) if (!anyfound && anyrequired)
{ {
free(*audit); global_free(*audit);
*audit = NULL; *audit = NULL;
records = 0; records = 0;
} }
@ -172,7 +172,7 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor
goto skip; goto skip;
/* allocate memory for the records */ /* allocate memory for the records */
*audit = alloc_array_clear_or_die(audit_record, records); *audit = global_alloc_array_clear(audit_record, records);
record = *audit; record = *audit;
/* now iterate over sample entries */ /* now iterate over sample entries */

View File

@ -14,7 +14,7 @@
#ifndef __AUDIT_H__ #ifndef __AUDIT_H__
#define __AUDIT_H__ #define __AUDIT_H__
#include "mamecore.h" #include "emucore.h"
#include "hash.h" #include "hash.h"

View File

@ -220,19 +220,19 @@ static void cheat_execute_script(cheat_private *cheatinfo, cheat_entry *cheat, s
static cheat_entry *cheat_list_load(running_machine *machine, const char *filename); static cheat_entry *cheat_list_load(running_machine *machine, const char *filename);
static int cheat_list_save(const char *filename, const cheat_entry *cheatlist); static int cheat_list_save(const char *filename, const cheat_entry *cheatlist);
static void cheat_list_free(cheat_entry *cheat); static void cheat_list_free(running_machine *machine, cheat_entry *cheat);
static cheat_entry *cheat_entry_load(running_machine *machine, const char *filename, xml_data_node *cheatnode); static cheat_entry *cheat_entry_load(running_machine *machine, const char *filename, xml_data_node *cheatnode);
static void cheat_entry_save(mame_file *cheatfile, const cheat_entry *cheat); static void cheat_entry_save(mame_file *cheatfile, const cheat_entry *cheat);
static void cheat_entry_free(cheat_entry *cheat); static void cheat_entry_free(running_machine *machine, cheat_entry *cheat);
static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node *paramnode); static cheat_parameter *cheat_parameter_load(running_machine *machine, const char *filename, xml_data_node *paramnode);
static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *param); static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *param);
static void cheat_parameter_free(cheat_parameter *param); static void cheat_parameter_free(running_machine *machine, cheat_parameter *param);
static cheat_script *cheat_script_load(running_machine *machine, const char *filename, xml_data_node *scriptnode, cheat_entry *cheat); static cheat_script *cheat_script_load(running_machine *machine, const char *filename, xml_data_node *scriptnode, cheat_entry *cheat);
static void cheat_script_save(mame_file *cheatfile, const cheat_script *script); static void cheat_script_save(mame_file *cheatfile, const cheat_script *script);
static void cheat_script_free(cheat_script *script); static void cheat_script_free(running_machine *machine, cheat_script *script);
static script_entry *script_entry_load(running_machine *machine, const char *filename, xml_data_node *entrynode, cheat_entry *cheat, int isaction); static script_entry *script_entry_load(running_machine *machine, const char *filename, xml_data_node *entrynode, cheat_entry *cheat, int isaction);
static void script_entry_save(mame_file *cheatfile, const script_entry *entry); static void script_entry_save(mame_file *cheatfile, const script_entry *entry);
static void script_entry_free(script_entry *entry); static void script_entry_free(running_machine *machine, script_entry *entry);
static astring *quote_astring_expression(astring *string, int isattribute); static astring *quote_astring_expression(astring *string, int isattribute);
static int validate_format(const char *filename, int line, const script_entry *entry); static int validate_format(const char *filename, int line, const script_entry *entry);
@ -438,7 +438,7 @@ static void cheat_exit(running_machine *machine)
/* free the list of cheats */ /* free the list of cheats */
if (cheatinfo->cheatlist != NULL) if (cheatinfo->cheatlist != NULL)
cheat_list_free(cheatinfo->cheatlist); cheat_list_free(machine, cheatinfo->cheatlist);
/* free any text strings */ /* free any text strings */
for (linenum = 0; linenum < ARRAY_LENGTH(cheatinfo->output); linenum++) for (linenum = 0; linenum < ARRAY_LENGTH(cheatinfo->output); linenum++)
@ -1110,7 +1110,7 @@ static cheat_entry *cheat_list_load(running_machine *machine, const char *filena
return cheatlist; return cheatlist;
error: error:
cheat_list_free(cheatlist); cheat_list_free(machine, cheatlist);
xml_file_free(rootnode); xml_file_free(rootnode);
if (cheatfile != NULL) if (cheatfile != NULL)
mame_fclose(cheatfile); mame_fclose(cheatfile);
@ -1159,13 +1159,13 @@ static int cheat_list_save(const char *filename, const cheat_entry *cheatlist)
cheat_list_free - free a list of cheats cheat_list_free - free a list of cheats
-------------------------------------------------*/ -------------------------------------------------*/
static void cheat_list_free(cheat_entry *cheat) static void cheat_list_free(running_machine *machine, cheat_entry *cheat)
{ {
while (cheat != NULL) while (cheat != NULL)
{ {
cheat_entry *entry = cheat; cheat_entry *entry = cheat;
cheat = entry->next; cheat = entry->next;
cheat_entry_free(entry); cheat_entry_free(machine, entry);
} }
} }
@ -1193,7 +1193,7 @@ static cheat_entry *cheat_entry_load(running_machine *machine, const char *filen
} }
/* allocate memory for the cheat */ /* allocate memory for the cheat */
cheat = (cheat_entry *)alloc_array_clear_or_die(UINT8, sizeof(*cheat) + (tempcount - 1) * sizeof(cheat->tempvar)); cheat = (cheat_entry *)auto_alloc_array_clear(machine, UINT8, sizeof(*cheat) + (tempcount - 1) * sizeof(cheat->tempvar));
cheat->numtemp = tempcount; cheat->numtemp = tempcount;
/* get the description */ /* get the description */
@ -1236,7 +1236,7 @@ static cheat_entry *cheat_entry_load(running_machine *machine, const char *filen
if (paramnode != NULL) if (paramnode != NULL)
{ {
/* load this parameter */ /* load this parameter */
cheat_parameter *curparam = cheat_parameter_load(filename, paramnode); cheat_parameter *curparam = cheat_parameter_load(machine, filename, paramnode);
if (curparam == NULL) if (curparam == NULL)
goto error; goto error;
@ -1272,7 +1272,7 @@ static cheat_entry *cheat_entry_load(running_machine *machine, const char *filen
return cheat; return cheat;
error: error:
cheat_entry_free(cheat); cheat_entry_free(machine, cheat);
return NULL; return NULL;
} }
@ -1326,7 +1326,7 @@ static void cheat_entry_save(mame_file *cheatfile, const cheat_entry *cheat)
cheat_entry_free - free a single cheat entry cheat_entry_free - free a single cheat entry
-------------------------------------------------*/ -------------------------------------------------*/
static void cheat_entry_free(cheat_entry *cheat) static void cheat_entry_free(running_machine *machine, cheat_entry *cheat)
{ {
script_state state; script_state state;
@ -1337,16 +1337,16 @@ static void cheat_entry_free(cheat_entry *cheat)
astring_free(cheat->comment); astring_free(cheat->comment);
if (cheat->parameter != NULL) if (cheat->parameter != NULL)
cheat_parameter_free(cheat->parameter); cheat_parameter_free(machine, cheat->parameter);
for (state = SCRIPT_STATE_OFF; state < SCRIPT_STATE_COUNT; state++) for (state = SCRIPT_STATE_OFF; state < SCRIPT_STATE_COUNT; state++)
if (cheat->script[state] != NULL) if (cheat->script[state] != NULL)
cheat_script_free(cheat->script[state]); cheat_script_free(machine, cheat->script[state]);
if (cheat->symbols != NULL) if (cheat->symbols != NULL)
symtable_free(cheat->symbols); symtable_free(cheat->symbols);
free(cheat); auto_free(machine, cheat);
} }
@ -1356,14 +1356,14 @@ static void cheat_entry_free(cheat_entry *cheat)
structures structures
-------------------------------------------------*/ -------------------------------------------------*/
static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node *paramnode) static cheat_parameter *cheat_parameter_load(running_machine *machine, const char *filename, xml_data_node *paramnode)
{ {
parameter_item **itemtailptr; parameter_item **itemtailptr;
xml_data_node *itemnode; xml_data_node *itemnode;
cheat_parameter *param; cheat_parameter *param;
/* allocate memory for it */ /* allocate memory for it */
param = alloc_clear_or_die(cheat_parameter); param = auto_alloc_clear(machine, cheat_parameter);
/* read the core attributes */ /* read the core attributes */
param->minval = xml_get_attribute_int(paramnode, "min", 0); param->minval = xml_get_attribute_int(paramnode, "min", 0);
@ -1380,7 +1380,7 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node
parameter_item *curitem; parameter_item *curitem;
/* allocate memory for it */ /* allocate memory for it */
curitem = alloc_clear_or_die(parameter_item); curitem = auto_alloc_clear(machine, parameter_item);
/* check for NULL text */ /* check for NULL text */
if (itemnode->value == NULL || itemnode->value[0] == 0) if (itemnode->value == NULL || itemnode->value[0] == 0)
@ -1413,7 +1413,7 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node
return param; return param;
error: error:
cheat_parameter_free(param); cheat_parameter_free(machine, param);
return NULL; return NULL;
} }
@ -1460,7 +1460,7 @@ static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *pa
parameter parameter
-------------------------------------------------*/ -------------------------------------------------*/
static void cheat_parameter_free(cheat_parameter *param) static void cheat_parameter_free(running_machine *machine, cheat_parameter *param)
{ {
while (param->itemlist != NULL) while (param->itemlist != NULL)
{ {
@ -1469,10 +1469,10 @@ static void cheat_parameter_free(cheat_parameter *param)
if (item->text != NULL) if (item->text != NULL)
astring_free(item->text); astring_free(item->text);
free(item); auto_free(machine, item);
} }
free(param); auto_free(machine, param);
} }
@ -1490,7 +1490,7 @@ static cheat_script *cheat_script_load(running_machine *machine, const char *fil
const char *state; const char *state;
/* allocate memory for it */ /* allocate memory for it */
script = alloc_clear_or_die(cheat_script); script = auto_alloc_clear(machine, cheat_script);
/* read the core attributes */ /* read the core attributes */
script->state = SCRIPT_STATE_RUN; script->state = SCRIPT_STATE_RUN;
@ -1538,7 +1538,7 @@ static cheat_script *cheat_script_load(running_machine *machine, const char *fil
return script; return script;
error: error:
cheat_script_free(script); cheat_script_free(machine, script);
return NULL; return NULL;
} }
@ -1578,16 +1578,16 @@ static void cheat_script_save(mame_file *cheatfile, const cheat_script *script)
script script
-------------------------------------------------*/ -------------------------------------------------*/
static void cheat_script_free(cheat_script *script) static void cheat_script_free(running_machine *machine, cheat_script *script)
{ {
while (script->entrylist != NULL) while (script->entrylist != NULL)
{ {
script_entry *entry = script->entrylist; script_entry *entry = script->entrylist;
script->entrylist = entry->next; script->entrylist = entry->next;
script_entry_free(entry); script_entry_free(machine, entry);
} }
free(script); auto_free(machine, script);
} }
@ -1604,7 +1604,7 @@ static script_entry *script_entry_load(running_machine *machine, const char *fil
EXPRERR experr; EXPRERR experr;
/* allocate memory for it */ /* allocate memory for it */
entry = alloc_clear_or_die(script_entry); entry = auto_alloc_clear(machine, script_entry);
/* read the condition if present */ /* read the condition if present */
expression = xml_get_attribute_string(entrynode, "condition", NULL); expression = xml_get_attribute_string(entrynode, "condition", NULL);
@ -1673,7 +1673,7 @@ static script_entry *script_entry_load(running_machine *machine, const char *fil
output_argument *curarg; output_argument *curarg;
/* allocate memory for it */ /* allocate memory for it */
curarg = alloc_clear_or_die(output_argument); curarg = auto_alloc_clear(machine, output_argument);
/* first extract attributes */ /* first extract attributes */
curarg->count = xml_get_attribute_int(argnode, "count", 1); curarg->count = xml_get_attribute_int(argnode, "count", 1);
@ -1712,7 +1712,7 @@ static script_entry *script_entry_load(running_machine *machine, const char *fil
return entry; return entry;
error: error:
script_entry_free(entry); script_entry_free(machine, entry);
return NULL; return NULL;
} }
@ -1784,7 +1784,7 @@ static void script_entry_save(mame_file *cheatfile, const script_entry *entry)
entry entry
-------------------------------------------------*/ -------------------------------------------------*/
static void script_entry_free(script_entry *entry) static void script_entry_free(running_machine *machine, script_entry *entry)
{ {
if (entry->condition != NULL) if (entry->condition != NULL)
expression_free(entry->condition); expression_free(entry->condition);
@ -1800,10 +1800,10 @@ static void script_entry_free(script_entry *entry)
if (curarg->expression != NULL) if (curarg->expression != NULL)
expression_free(curarg->expression); expression_free(curarg->expression);
free(curarg); auto_free(machine, curarg);
} }
free(entry); auto_free(machine, entry);
} }

View File

@ -14,7 +14,7 @@
#ifndef __CHEAT_H__ #ifndef __CHEAT_H__
#define __CHEAT_H__ #define __CHEAT_H__
#include "mamecore.h" #include "emucore.h"

View File

@ -179,7 +179,7 @@ int cli_execute(int argc, char **argv, const options_entry *osd_options)
if (fatal.exitcode() != 0) if (fatal.exitcode() != 0)
result = fatal.exitcode(); result = fatal.exitcode();
} }
catch (emu_exception &exception) catch (emu_exception &)
{ {
fprintf(stderr, "Caught unhandled emulator exception\n"); fprintf(stderr, "Caught unhandled emulator exception\n");
} }
@ -198,6 +198,9 @@ error:
options_free(options); options_free(options);
astring_free(gamename); astring_free(gamename);
astring_free(exename); astring_free(exename);
/* report any unfreed memory */
dump_unfreed_mem();
return result; return result;
} }
@ -356,13 +359,7 @@ static void display_help(void)
int cli_info_listxml(core_options *options, const char *gamename) int cli_info_listxml(core_options *options, const char *gamename)
{ {
/* since print_mame_xml expands the machine driver, we need to set things up */
init_resource_tracking();
print_mame_xml(stdout, drivers, gamename); print_mame_xml(stdout, drivers, gamename);
/* clean up our tracked resources */
exit_resource_tracking();
return MAMERR_NONE; return MAMERR_NONE;
} }
@ -459,7 +456,7 @@ int cli_info_listclones(core_options *options, const char *gamename)
int cli_info_listbrothers(core_options *options, const char *gamename) int cli_info_listbrothers(core_options *options, const char *gamename)
{ {
UINT8 *didit = alloc_array_or_die(UINT8, driver_list_get_count(drivers)); UINT8 *didit = global_alloc_array(UINT8, driver_list_get_count(drivers));
astring *filename = astring_alloc(); astring *filename = astring_alloc();
int drvindex, count = 0; int drvindex, count = 0;
@ -495,7 +492,7 @@ int cli_info_listbrothers(core_options *options, const char *gamename)
/* return an error if none found */ /* return an error if none found */
astring_free(filename); astring_free(filename);
free(didit); global_free(didit);
return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME; return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME;
} }
@ -618,9 +615,6 @@ int cli_info_listsamples(core_options *options, const char *gamename)
int count = 0; int count = 0;
int drvindex; int drvindex;
/* since we expand the machine driver, we need to set things up */
init_resource_tracking();
/* iterate over drivers */ /* iterate over drivers */
for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) for (drvindex = 0; drivers[drvindex] != NULL; drvindex++)
if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0)
@ -645,9 +639,6 @@ int cli_info_listsamples(core_options *options, const char *gamename)
machine_config_free(config); machine_config_free(config);
} }
/* clean up our tracked resources */
exit_resource_tracking();
return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME; return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME;
} }
@ -663,9 +654,6 @@ int cli_info_listdevices(core_options *options, const char *gamename)
int count = 0; int count = 0;
int drvindex; int drvindex;
/* since we expand the machine driver, we need to set things up */
init_resource_tracking();
/* iterate over drivers */ /* iterate over drivers */
for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) for (drvindex = 0; drivers[drvindex] != NULL; drvindex++)
if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0)
@ -706,9 +694,6 @@ int cli_info_listdevices(core_options *options, const char *gamename)
machine_config_free(config); machine_config_free(config);
} }
/* clean up our tracked resources */
exit_resource_tracking();
return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME; return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME;
} }
@ -737,7 +722,7 @@ static int info_verifyroms(core_options *options, const char *gamename)
audit_records = audit_images(options, drivers[drvindex], AUDIT_VALIDATE_FAST, &audit); audit_records = audit_images(options, drivers[drvindex], AUDIT_VALIDATE_FAST, &audit);
res = audit_summary(drivers[drvindex], audit_records, audit, TRUE); res = audit_summary(drivers[drvindex], audit_records, audit, TRUE);
if (audit_records > 0) if (audit_records > 0)
free(audit); global_free(audit);
/* if not found, count that and leave it at that */ /* if not found, count that and leave it at that */
if (res == NOTFOUND) if (res == NOTFOUND)
@ -821,7 +806,7 @@ static int info_verifysamples(core_options *options, const char *gamename)
audit_records = audit_samples(options, drivers[drvindex], &audit); audit_records = audit_samples(options, drivers[drvindex], &audit);
res = audit_summary(drivers[drvindex], audit_records, audit, TRUE); res = audit_summary(drivers[drvindex], audit_records, audit, TRUE);
if (audit_records > 0) if (audit_records > 0)
free(audit); global_free(audit);
else else
continue; continue;
@ -956,14 +941,14 @@ static void romident(const char *filename, romident_status *status)
for (entry = zip_file_first_file(zip); entry; entry = zip_file_next_file(zip)) for (entry = zip_file_first_file(zip); entry; entry = zip_file_next_file(zip))
if (entry->uncompressed_length != 0) if (entry->uncompressed_length != 0)
{ {
UINT8 *data = (UINT8 *)malloc(entry->uncompressed_length); UINT8 *data = global_alloc_array(UINT8, entry->uncompressed_length);
if (data != NULL) if (data != NULL)
{ {
/* decompress data into RAM and identify it */ /* decompress data into RAM and identify it */
ziperr = zip_file_decompress(zip, data, entry->uncompressed_length); ziperr = zip_file_decompress(zip, data, entry->uncompressed_length);
if (ziperr == ZIPERR_NONE) if (ziperr == ZIPERR_NONE)
identify_data(entry->filename, data, entry->uncompressed_length, status); identify_data(entry->filename, data, entry->uncompressed_length, status);
free(data); global_free(data);
} }
} }
@ -994,7 +979,7 @@ static void identify_file(const char *name, romident_status *status)
filerr = osd_open(name, OPEN_FLAG_READ, &file, &length); filerr = osd_open(name, OPEN_FLAG_READ, &file, &length);
if (filerr == FILERR_NONE && length > 0 && (UINT32)length == length) if (filerr == FILERR_NONE && length > 0 && (UINT32)length == length)
{ {
UINT8 *data = (UINT8 *)malloc(length); UINT8 *data = global_alloc_array(UINT8, length);
if (data != NULL) if (data != NULL)
{ {
UINT32 bytes; UINT32 bytes;
@ -1003,7 +988,7 @@ static void identify_file(const char *name, romident_status *status)
filerr = osd_read(file, data, 0, length, &bytes); filerr = osd_read(file, data, 0, length, &bytes);
if (filerr == FILERR_NONE) if (filerr == FILERR_NONE)
identify_data(name, data, bytes, status); identify_data(name, data, bytes, status);
free(data); global_free(data);
} }
osd_close(file); osd_close(file);
} }
@ -1029,7 +1014,7 @@ static void identify_data(const char *name, const UINT8 *data, int length, romid
{ {
/* now determine the new data length and allocate temporary memory for it */ /* now determine the new data length and allocate temporary memory for it */
length = jedbin_output(&jed, NULL, 0); length = jedbin_output(&jed, NULL, 0);
tempjed = (UINT8 *)malloc(length); tempjed = global_alloc_array(UINT8, length);
if (tempjed == NULL) if (tempjed == NULL)
return; return;
@ -1072,7 +1057,7 @@ static void identify_data(const char *name, const UINT8 *data, int length, romid
/* free any temporary JED data */ /* free any temporary JED data */
if (tempjed != NULL) if (tempjed != NULL)
free(tempjed); global_free(tempjed);
} }

View File

@ -924,11 +924,11 @@ static int create_tables(void)
/* allocate the tables */ /* allocate the tables */
if (!reverse_table) if (!reverse_table)
reverse_table = (UINT16 *)malloc(0x4000 * sizeof(UINT16)); reverse_table = global_alloc_array(UINT16, 0x4000);
if (!mask_table) if (!mask_table)
mask_table = (UINT16 *)malloc(0x4000 * sizeof(UINT16)); mask_table = global_alloc_array(UINT16, 0x4000);
if (!condition_table) if (!condition_table)
condition_table = (UINT8 *)malloc(0x1000 * sizeof(UINT8)); condition_table = global_alloc_array(UINT8, 0x1000);
/* handle errors */ /* handle errors */
if (reverse_table == NULL || mask_table == NULL || condition_table == NULL) if (reverse_table == NULL || mask_table == NULL || condition_table == NULL)
@ -1010,15 +1010,15 @@ static int create_tables(void)
static CPU_EXIT( adsp21xx ) static CPU_EXIT( adsp21xx )
{ {
if (reverse_table != NULL) if (reverse_table != NULL)
free(reverse_table); global_free(reverse_table);
reverse_table = NULL; reverse_table = NULL;
if (mask_table != NULL) if (mask_table != NULL)
free(mask_table); global_free(mask_table);
mask_table = NULL; mask_table = NULL;
if (condition_table != NULL) if (condition_table != NULL)
free(condition_table); global_free(condition_table);
condition_table = NULL; condition_table = NULL;
#if TRACK_HOTSPOTS #if TRACK_HOTSPOTS

View File

@ -97,7 +97,7 @@ INLINE opcode_desc *desc_alloc(drcfe_state *drcfe)
if (desc != NULL) if (desc != NULL)
drcfe->desc_free_list = desc->next; drcfe->desc_free_list = desc->next;
else else
desc = alloc_or_die(opcode_desc); desc = auto_alloc(drcfe->device->machine, opcode_desc);
return desc; return desc;
} }
@ -128,10 +128,10 @@ drcfe_state *drcfe_init(const device_config *cpu, const drcfe_config *config, vo
drcfe_state *drcfe; drcfe_state *drcfe;
/* allocate some memory to hold the state */ /* allocate some memory to hold the state */
drcfe = alloc_clear_or_die(drcfe_state); drcfe = auto_alloc_clear(cpu->machine, drcfe_state);
/* allocate the description array */ /* allocate the description array */
drcfe->desc_array = alloc_array_clear_or_die(opcode_desc *, config->window_end + config->window_start + 2); drcfe->desc_array = auto_alloc_array_clear(cpu->machine, opcode_desc *, config->window_end + config->window_start + 2);
/* copy in configuration information */ /* copy in configuration information */
drcfe->window_start = config->window_start; drcfe->window_start = config->window_start;
@ -164,15 +164,14 @@ void drcfe_exit(drcfe_state *drcfe)
{ {
opcode_desc *freeme = drcfe->desc_free_list; opcode_desc *freeme = drcfe->desc_free_list;
drcfe->desc_free_list = drcfe->desc_free_list->next; drcfe->desc_free_list = drcfe->desc_free_list->next;
free(freeme); auto_free(drcfe->device->machine, freeme);
} }
/* free the description array */ /* free the description array */
if (drcfe->desc_array != NULL) auto_free(drcfe->device->machine, drcfe->desc_array);
free(drcfe->desc_array);
/* free the object itself */ /* free the object itself */
free(drcfe); auto_free(drcfe->device->machine, drcfe);
} }

View File

@ -646,8 +646,8 @@ void drcuml_free(drcuml_state *drcuml)
/* free memory */ /* free memory */
if (block->inst != NULL) if (block->inst != NULL)
free(block->inst); auto_free(drcuml->device->machine, block->inst);
free(block); auto_free(drcuml->device->machine, block);
} }
/* free all the symbols */ /* free all the symbols */
@ -655,7 +655,7 @@ void drcuml_free(drcuml_state *drcuml)
{ {
drcuml_symbol *sym = drcuml->symlist; drcuml_symbol *sym = drcuml->symlist;
drcuml->symlist = sym->next; drcuml->symlist = sym->next;
free(sym); auto_free(drcuml->device->machine, sym);
} }
/* close any files */ /* close any files */
@ -687,18 +687,13 @@ drcuml_block *drcuml_block_begin(drcuml_state *drcuml, UINT32 maxinst, jmp_buf *
if (bestblock == NULL) if (bestblock == NULL)
{ {
/* allocate the block structure itself */ /* allocate the block structure itself */
bestblock = (drcuml_block *)malloc(sizeof(*bestblock)); bestblock = auto_alloc_clear(drcuml->device->machine, drcuml_block);
if (bestblock == NULL)
fatalerror("Out of memory allocating block in drcuml_block_begin");
memset(bestblock, 0, sizeof(*bestblock));
/* fill in the structure */ /* fill in the structure */
bestblock->drcuml = drcuml; bestblock->drcuml = drcuml;
bestblock->next = drcuml->blocklist; bestblock->next = drcuml->blocklist;
bestblock->maxinst = maxinst * 3 / 2; bestblock->maxinst = maxinst * 3 / 2;
bestblock->inst = (drcuml_instruction *)malloc(sizeof(drcuml_instruction) * bestblock->maxinst); bestblock->inst = auto_alloc_array(drcuml->device->machine, drcuml_instruction, bestblock->maxinst);
if (bestblock->inst == NULL)
fatalerror("Out of memory allocating instruction array in drcuml_block_begin");
/* hook us into the list */ /* hook us into the list */
drcuml->blocklist = bestblock; drcuml->blocklist = bestblock;
@ -1037,9 +1032,7 @@ void drcuml_symbol_add(drcuml_state *drcuml, void *base, UINT32 length, const ch
drcuml_symbol *symbol; drcuml_symbol *symbol;
/* allocate memory to hold the symbol */ /* allocate memory to hold the symbol */
symbol = (drcuml_symbol *)malloc(sizeof(*symbol) + strlen(name)); symbol = (drcuml_symbol *)auto_alloc_array(drcuml->device->machine, UINT8, sizeof(*symbol) + strlen(name));
if (symbol == NULL)
fatalerror("Out of memory allocating symbol in drcuml_symbol_add");
/* fill in the structure */ /* fill in the structure */
symbol->next = NULL; symbol->next = NULL;

View File

@ -370,7 +370,7 @@ static void init_tables(void)
} }
/* fill in the mirror table */ /* fill in the mirror table */
mirror_table = alloc_array_or_die(UINT16, 65536); mirror_table = global_alloc_array(UINT16, 65536);
for (i = 0; i < 65536; i++) for (i = 0; i < 65536; i++)
mirror_table[i] = ((i >> 15) & 0x0001) | ((i >> 13) & 0x0002) | mirror_table[i] = ((i >> 15) & 0x0001) | ((i >> 13) & 0x0002) |
((i >> 11) & 0x0004) | ((i >> 9) & 0x0008) | ((i >> 11) & 0x0004) | ((i >> 9) & 0x0008) |
@ -382,7 +382,7 @@ static void init_tables(void)
((i << 13) & 0x4000) | ((i << 15) & 0x8000); ((i << 13) & 0x4000) | ((i << 15) & 0x8000);
/* fill in the condition table */ /* fill in the condition table */
condition_table = alloc_array_or_die(UINT8, 32 * 8); condition_table = global_alloc_array(UINT8, 32 * 8);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
for (j = 0; j < 32; j++) for (j = 0; j < 32; j++)
{ {
@ -461,11 +461,11 @@ static CPU_EXIT( jaguar )
return; return;
if (mirror_table != NULL) if (mirror_table != NULL)
free(mirror_table); global_free(mirror_table);
mirror_table = NULL; mirror_table = NULL;
if (condition_table != NULL) if (condition_table != NULL)
free(condition_table); global_free(condition_table);
condition_table = NULL; condition_table = NULL;
} }

View File

@ -1705,7 +1705,7 @@ static void BuildTable(void)
{ {
int i; int i;
if(!OpTable) if(!OpTable)
OpTable=alloc_array_or_die(_OP, 0x10000); OpTable=global_alloc_array(_OP, 0x10000);
for(i=0;i<0x10000;++i) for(i=0;i<0x10000;++i)
OpTable[i]=DecodeOp(i); OpTable[i]=DecodeOp(i);
} }
@ -1797,7 +1797,7 @@ static CPU_INIT( se3208 )
static CPU_EXIT( se3208 ) static CPU_EXIT( se3208 )
{ {
if(OpTable) if(OpTable)
free(OpTable); global_free(OpTable);
} }

View File

@ -3,7 +3,7 @@
#define BIGCASE #define BIGCASE
#include "mamecore.h" #include "emucore.h"
typedef char BOOLEAN; typedef char BOOLEAN;

View File

@ -60,7 +60,7 @@ vtlb_state *vtlb_alloc(const device_config *cpu, int space, int fixed_entries, i
vtlb_state *vtlb; vtlb_state *vtlb;
/* allocate memory for the core structure */ /* allocate memory for the core structure */
vtlb = alloc_clear_or_die(vtlb_state); vtlb = auto_alloc_clear(cpu->machine, vtlb_state);
/* fill in CPU information */ /* fill in CPU information */
vtlb->device = cpu; vtlb->device = cpu;
@ -77,17 +77,17 @@ vtlb_state *vtlb_alloc(const device_config *cpu, int space, int fixed_entries, i
assert(vtlb->addrwidth > vtlb->pageshift); assert(vtlb->addrwidth > vtlb->pageshift);
/* allocate the entry array */ /* allocate the entry array */
vtlb->live = alloc_array_clear_or_die(offs_t, fixed_entries + dynamic_entries); vtlb->live = auto_alloc_array_clear(cpu->machine, offs_t, fixed_entries + dynamic_entries);
state_save_register_device_item_pointer(cpu, space, vtlb->live, fixed_entries + dynamic_entries); state_save_register_device_item_pointer(cpu, space, vtlb->live, fixed_entries + dynamic_entries);
/* allocate the lookup table */ /* allocate the lookup table */
vtlb->table = alloc_array_clear_or_die(vtlb_entry, (size_t) 1 << (vtlb->addrwidth - vtlb->pageshift)); vtlb->table = auto_alloc_array_clear(cpu->machine, vtlb_entry, (size_t) 1 << (vtlb->addrwidth - vtlb->pageshift));
state_save_register_device_item_pointer(cpu, space, vtlb->table, 1 << (vtlb->addrwidth - vtlb->pageshift)); state_save_register_device_item_pointer(cpu, space, vtlb->table, 1 << (vtlb->addrwidth - vtlb->pageshift));
/* allocate the fixed page count array */ /* allocate the fixed page count array */
if (fixed_entries > 0) if (fixed_entries > 0)
{ {
vtlb->fixedpages = alloc_array_clear_or_die(int, fixed_entries); vtlb->fixedpages = auto_alloc_array_clear(cpu->machine, int, fixed_entries);
state_save_register_device_item_pointer(cpu, space, vtlb->fixedpages, fixed_entries); state_save_register_device_item_pointer(cpu, space, vtlb->fixedpages, fixed_entries);
} }
return vtlb; return vtlb;
@ -102,16 +102,16 @@ void vtlb_free(vtlb_state *vtlb)
{ {
/* free the fixed pages if allocated */ /* free the fixed pages if allocated */
if (vtlb->fixedpages != NULL) if (vtlb->fixedpages != NULL)
free(vtlb->fixedpages); auto_free(vtlb->device->machine, vtlb->fixedpages);
/* free the table and array if they exist */ /* free the table and array if they exist */
if (vtlb->live != NULL) if (vtlb->live != NULL)
free(vtlb->live); auto_free(vtlb->device->machine, vtlb->live);
if (vtlb->table != NULL) if (vtlb->table != NULL)
free(vtlb->table); auto_free(vtlb->device->machine, vtlb->table);
/* and then the VTLB object itself */ /* and then the VTLB object itself */
free(vtlb); auto_free(vtlb->device->machine, vtlb);
} }

View File

@ -91,7 +91,7 @@ x86log_context *x86log_create_context(const char *filename)
x86log_context *log; x86log_context *log;
/* allocate the log */ /* allocate the log */
log = alloc_clear_or_die(x86log_context); log = global_alloc_clear(x86log_context);
/* allocate the filename */ /* allocate the filename */
log->filename = astring_dupc(filename); log->filename = astring_dupc(filename);
@ -114,7 +114,7 @@ void x86log_free_context(x86log_context *log)
/* free the structure */ /* free the structure */
astring_free(log->filename); astring_free(log->filename);
free(log); global_free(log);
} }

View File

@ -3362,12 +3362,8 @@ static CPU_INIT( z80 )
int oldval, newval, val; int oldval, newval, val;
UINT8 *padd, *padc, *psub, *psbc; UINT8 *padd, *padc, *psub, *psbc;
/* allocate big flag arrays once */ /* allocate big flag arrays once */
SZHVC_add = (UINT8 *)malloc(2*256*256); SZHVC_add = global_alloc_array(UINT8, 2*256*256);
SZHVC_sub = (UINT8 *)malloc(2*256*256); SZHVC_sub = global_alloc_array(UINT8, 2*256*256);
if( !SZHVC_add || !SZHVC_sub )
{
fatalerror("Z80: failed to allocate 2 * 128K flags arrays!!!");
}
padd = &SZHVC_add[ 0*256]; padd = &SZHVC_add[ 0*256];
padc = &SZHVC_add[256*256]; padc = &SZHVC_add[256*256];
psub = &SZHVC_sub[ 0*256]; psub = &SZHVC_sub[ 0*256];
@ -3514,9 +3510,9 @@ static CPU_RESET( z80 )
static CPU_EXIT( z80 ) static CPU_EXIT( z80 )
{ {
if (SZHVC_add) free(SZHVC_add); global_free(SZHVC_add);
SZHVC_add = NULL; SZHVC_add = NULL;
if (SZHVC_sub) free(SZHVC_sub); global_free(SZHVC_sub);
SZHVC_sub = NULL; SZHVC_sub = NULL;
} }

View File

@ -545,11 +545,7 @@ void z8000_init_tables(void)
int i; int i;
/* allocate the opcode execution and disassembler array */ /* allocate the opcode execution and disassembler array */
z8000_exec = (Z8000_exec *)malloc(0x10000 * sizeof(Z8000_exec)); z8000_exec = global_alloc_array(Z8000_exec, 0x10000);
if( !z8000_exec )
{
fatalerror("cannot allocate Z8000 execution table\n");
}
/* set up the zero, sign, parity lookup table */ /* set up the zero, sign, parity lookup table */
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
@ -586,9 +582,7 @@ void z8000_init_tables(void)
void z8000_deinit_tables(void) void z8000_deinit_tables(void)
{ {
if( !z8000_exec ) global_free( z8000_exec );
return;
free( z8000_exec );
z8000_exec = 0; z8000_exec = 0;
} }

View File

@ -396,7 +396,7 @@ static void debug_command_exit(running_machine *machine)
debug_cpu_trace(cpu, NULL, 0, NULL); debug_cpu_trace(cpu, NULL, 0, NULL);
if (cheat.length) if (cheat.length)
free(cheat.cheatmap); auto_free(machine, cheat.cheatmap);
} }
@ -1831,13 +1831,8 @@ static void execute_cheatinit(running_machine *machine, int ref, int params, con
{ {
/* initialize new cheat system */ /* initialize new cheat system */
if (cheat.cheatmap != NULL) if (cheat.cheatmap != NULL)
free(cheat.cheatmap); auto_free(machine, cheat.cheatmap);
cheat.cheatmap = (cheat_map *)malloc(real_length * sizeof(cheat_map)); cheat.cheatmap = auto_alloc_array(machine, cheat_map, real_length);
if (cheat.cheatmap == NULL)
{
debug_console_printf(machine, "Unable of allocate the necessary memory\n");
return;
}
cheat.length = real_length; cheat.length = real_length;
cheat.undo = 0; cheat.undo = 0;
@ -1846,8 +1841,6 @@ static void execute_cheatinit(running_machine *machine, int ref, int params, con
else else
{ {
/* add range to cheat system */ /* add range to cheat system */
cheat_map * cheatmap_bak = cheat.cheatmap;
if (cheat.cpu == 0) if (cheat.cpu == 0)
{ {
debug_console_printf(machine, "Use cheatinit before cheatrange\n"); debug_console_printf(machine, "Use cheatinit before cheatrange\n");
@ -1857,13 +1850,11 @@ static void execute_cheatinit(running_machine *machine, int ref, int params, con
if (!debug_command_parameter_cpu_space(machine, &cheat.cpu, ADDRESS_SPACE_PROGRAM, &space)) if (!debug_command_parameter_cpu_space(machine, &cheat.cpu, ADDRESS_SPACE_PROGRAM, &space))
return; return;
cheat.cheatmap = (cheat_map *)realloc(cheat.cheatmap, (cheat.length + real_length) * sizeof(cheat_map)); cheat_map *newmap = auto_alloc_array(machine, cheat_map, cheat.length + real_length);
if (cheat.cheatmap == NULL) for (int item = 0; item < cheat.length; item++)
{ newmap[item] = cheat.cheatmap[item];
cheat.cheatmap = cheatmap_bak; auto_free(machine, cheat.cheatmap);
debug_console_printf(machine, "Unable of allocate the necessary memory\n"); cheat.cheatmap = newmap;
return;
}
active_cheat = cheat.length; active_cheat = cheat.length;
cheat.length += real_length; cheat.length += real_length;

View File

@ -78,7 +78,6 @@ struct _debug_cpu_comment_group
static int debug_comment_load_xml(running_machine *machine, mame_file *file); static int debug_comment_load_xml(running_machine *machine, mame_file *file);
static void debug_comment_exit(running_machine *machine); static void debug_comment_exit(running_machine *machine);
static void debug_comment_free(running_machine *machine);
@ -123,7 +122,7 @@ int debug_comment_add(const device_config *device, offs_t addr, const char *comm
int i = 0; int i = 0;
/* Create a new item to insert into the list */ /* Create a new item to insert into the list */
debug_comment *insert_me = alloc_or_die(debug_comment); debug_comment *insert_me = auto_alloc(device->machine, debug_comment);
insert_me->color = color; insert_me->color = color;
insert_me->is_valid = 1; insert_me->is_valid = 1;
insert_me->address = addr; insert_me->address = addr;
@ -150,7 +149,7 @@ int debug_comment_add(const device_config *device, offs_t addr, const char *comm
/* Got an exact match? Just replace */ /* Got an exact match? Just replace */
if (match == 1) if (match == 1)
{ {
free(comments->comment_info[insert_point]); auto_free(device->machine, comments->comment_info[insert_point]);
comments->comment_info[insert_point] = insert_me; comments->comment_info[insert_point] = insert_me;
comments->change_count++; comments->change_count++;
@ -198,7 +197,7 @@ int debug_comment_remove(const device_config *device, offs_t addr, UINT32 c_crc)
return 0; return 0;
/* Okay, it's there, now remove it */ /* Okay, it's there, now remove it */
free(comments->comment_info[remove_index]); auto_free(device->machine, comments->comment_info[remove_index]);
for (i = remove_index; i < comments->comment_count-1; i++) for (i = remove_index; i < comments->comment_count-1; i++)
comments->comment_info[i] = comments->comment_info[i+1]; comments->comment_info[i] = comments->comment_info[i+1];
@ -496,7 +495,7 @@ static int debug_comment_load_xml(running_machine *machine, mame_file *fp)
for (datanode = xml_get_sibling(cpunode->child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment")) for (datanode = xml_get_sibling(cpunode->child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment"))
{ {
/* Malloc the comment */ /* Malloc the comment */
comments->comment_info[j] = (debug_comment*) malloc(sizeof(debug_comment)); comments->comment_info[j] = auto_alloc(machine, debug_comment);
comments->comment_info[j]->address = xml_get_attribute_int(datanode, "address", 0); comments->comment_info[j]->address = xml_get_attribute_int(datanode, "address", 0);
comments->comment_info[j]->color = xml_get_attribute_int(datanode, "color", 0); comments->comment_info[j]->color = xml_get_attribute_int(datanode, "color", 0);
@ -530,29 +529,4 @@ error:
static void debug_comment_exit(running_machine *machine) static void debug_comment_exit(running_machine *machine)
{ {
debug_comment_save(machine); debug_comment_save(machine);
debug_comment_free(machine);
}
/*-------------------------------------------------------------------------
debug_comment_free - cleans up memory
-------------------------------------------------------------------------*/
static void debug_comment_free(running_machine *machine)
{
const device_config *cpu;
for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu))
{
debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
if (comments != NULL)
{
int j;
for (j = 0; j < comments->comment_count; j++)
free(comments->comment_info[j]);
comments->comment_count = 0;
}
}
} }

View File

@ -978,7 +978,7 @@ int debug_cpu_breakpoint_set(const device_config *device, offs_t address, parsed
assert_always(device != NULL, "debug_cpu_breakpoint_set() called with invalid cpu!"); assert_always(device != NULL, "debug_cpu_breakpoint_set() called with invalid cpu!");
/* allocate breakpoint */ /* allocate breakpoint */
bp = alloc_or_die(debug_cpu_breakpoint); bp = auto_alloc(device->machine, debug_cpu_breakpoint);
bp->index = global->bpindex++; bp->index = global->bpindex++;
bp->enabled = TRUE; bp->enabled = TRUE;
bp->address = address; bp->address = address;
@ -986,7 +986,7 @@ int debug_cpu_breakpoint_set(const device_config *device, offs_t address, parsed
bp->action = NULL; bp->action = NULL;
if (action != NULL) if (action != NULL)
{ {
bp->action = alloc_array_or_die(char, strlen(action) + 1); bp->action = auto_alloc_array(device->machine, char, strlen(action) + 1);
strcpy(bp->action, action); strcpy(bp->action, action);
} }
@ -1027,8 +1027,8 @@ int debug_cpu_breakpoint_clear(running_machine *machine, int bpnum)
if (bp->condition != NULL) if (bp->condition != NULL)
expression_free(bp->condition); expression_free(bp->condition);
if (bp->action != NULL) if (bp->action != NULL)
free(bp->action); auto_free(machine, bp->action);
free(bp); auto_free(machine, bp);
/* update the flags */ /* update the flags */
breakpoint_update_flags(info); breakpoint_update_flags(info);
@ -1082,7 +1082,7 @@ int debug_cpu_watchpoint_set(const address_space *space, int type, offs_t addres
{ {
debugcpu_private *global = space->machine->debugcpu_data; debugcpu_private *global = space->machine->debugcpu_data;
cpu_debug_data *info = cpu_get_debug_data(space->cpu); cpu_debug_data *info = cpu_get_debug_data(space->cpu);
debug_cpu_watchpoint *wp = alloc_or_die(debug_cpu_watchpoint); debug_cpu_watchpoint *wp = auto_alloc(space->machine, debug_cpu_watchpoint);
/* fill in the structure */ /* fill in the structure */
wp->index = global->wpindex++; wp->index = global->wpindex++;
@ -1094,7 +1094,7 @@ int debug_cpu_watchpoint_set(const address_space *space, int type, offs_t addres
wp->action = NULL; wp->action = NULL;
if (action != NULL) if (action != NULL)
{ {
wp->action = alloc_array_or_die(char, strlen(action) + 1); wp->action = auto_alloc_array(space->machine, char, strlen(action) + 1);
strcpy(wp->action, action); strcpy(wp->action, action);
} }
@ -1138,8 +1138,8 @@ int debug_cpu_watchpoint_clear(running_machine *machine, int wpnum)
if (wp->condition != NULL) if (wp->condition != NULL)
expression_free(wp->condition); expression_free(wp->condition);
if (wp->action != NULL) if (wp->action != NULL)
free(wp->action); auto_free(machine, wp->action);
free(wp); auto_free(machine, wp);
watchpoint_update_flags(cpu_get_address_space(cpu, spacenum)); watchpoint_update_flags(cpu_get_address_space(cpu, spacenum));
return TRUE; return TRUE;
@ -1231,7 +1231,7 @@ void debug_cpu_trace(const device_config *device, FILE *file, int trace_over, co
info->trace.file = NULL; info->trace.file = NULL;
if (info->trace.action != NULL) if (info->trace.action != NULL)
free(info->trace.action); auto_free(device->machine, info->trace.action);
info->trace.action = NULL; info->trace.action = NULL;
/* open any new files */ /* open any new files */
@ -1240,7 +1240,7 @@ void debug_cpu_trace(const device_config *device, FILE *file, int trace_over, co
info->trace.trace_over_target = ~0; info->trace.trace_over_target = ~0;
if (action != NULL) if (action != NULL)
{ {
info->trace.action = alloc_array_or_die(char, strlen(action) + 1); info->trace.action = auto_alloc_array(device->machine, char, strlen(action) + 1);
strcpy(info->trace.action, action); strcpy(info->trace.action, action);
} }
@ -1301,14 +1301,14 @@ int debug_cpu_hotspot_track(const device_config *device, int numspots, int thres
/* if we already have tracking info, kill it */ /* if we already have tracking info, kill it */
if (info->hotspots) if (info->hotspots)
free(info->hotspots); auto_free(device->machine, info->hotspots);
info->hotspots = NULL; info->hotspots = NULL;
/* only start tracking if we have a non-zero count */ /* only start tracking if we have a non-zero count */
if (numspots > 0) if (numspots > 0)
{ {
/* allocate memory for hotspots */ /* allocate memory for hotspots */
info->hotspots = alloc_array_or_die(debug_hotspot_entry, numspots); info->hotspots = auto_alloc_array(device->machine, debug_hotspot_entry, numspots);
memset(info->hotspots, 0xff, sizeof(*info->hotspots) * numspots); memset(info->hotspots, 0xff, sizeof(*info->hotspots) * numspots);
/* fill in the info */ /* fill in the info */
@ -1937,7 +1937,7 @@ static void debug_cpu_exit(running_machine *machine)
if (info->trace.file != NULL) if (info->trace.file != NULL)
fclose(info->trace.file); fclose(info->trace.file);
if (info->trace.action != NULL) if (info->trace.action != NULL)
free(info->trace.action); auto_free(machine, info->trace.action);
/* free the symbol table */ /* free the symbol table */
if (info->symtable != NULL) if (info->symtable != NULL)

View File

@ -385,10 +385,7 @@ debug_view *debug_view_alloc(running_machine *machine, int type, debug_view_osd_
assert(type >= 0 && type < ARRAY_LENGTH(callback_table)); assert(type >= 0 && type < ARRAY_LENGTH(callback_table));
/* allocate memory for the view */ /* allocate memory for the view */
view = (debug_view *)malloc(sizeof(*view)); view = auto_alloc_clear(machine, debug_view);
if (view == NULL)
return NULL;
memset(view, 0, sizeof(*view));
/* set the view type information */ /* set the view type information */
view->machine = machine; view->machine = machine;
@ -403,18 +400,13 @@ debug_view *debug_view_alloc(running_machine *machine, int type, debug_view_osd_
/* allocate memory for the buffer */ /* allocate memory for the buffer */
view->viewdata_size = view->visible.y * view->visible.x; view->viewdata_size = view->visible.y * view->visible.x;
view->viewdata = (debug_view_char *)malloc(sizeof(view->viewdata[0]) * view->viewdata_size); view->viewdata = auto_alloc_array(machine, debug_view_char, view->viewdata_size);
if (view->viewdata == NULL)
{
free(view);
return NULL;
}
/* allocate extra memory */ /* allocate extra memory */
if (view->cb.alloc != NULL && !(*view->cb.alloc)(view)) if (view->cb.alloc != NULL && !(*view->cb.alloc)(view))
{ {
free(view->viewdata); auto_free(machine, view->viewdata);
free(view); auto_free(machine, view);
return NULL; return NULL;
} }
@ -450,8 +442,8 @@ void debug_view_free(debug_view *view)
if (view->cb.free != NULL) if (view->cb.free != NULL)
(*view->cb.free)(view); (*view->cb.free)(view);
if (view->viewdata != NULL) if (view->viewdata != NULL)
free(view->viewdata); auto_free(view->machine, view->viewdata);
free(view); auto_free(view->machine, view);
break; break;
} }
} }
@ -497,7 +489,8 @@ void debug_view_end_update(debug_view *view)
if (size > view->viewdata_size) if (size > view->viewdata_size)
{ {
view->viewdata_size = size; view->viewdata_size = size;
view->viewdata = (debug_view_char *)realloc(view->viewdata, sizeof(view->viewdata[0]) * view->viewdata_size); global_free(view->viewdata);
view->viewdata = auto_alloc_array(view->machine, debug_view_char, view->viewdata_size);
} }
/* update the view */ /* update the view */
@ -906,10 +899,7 @@ static int textbuf_view_alloc(debug_view *view, text_buffer *textbuf)
debug_view_textbuf *textdata; debug_view_textbuf *textdata;
/* allocate memory */ /* allocate memory */
textdata = (debug_view_textbuf *)malloc(sizeof(*textdata)); textdata = auto_alloc_clear(view->machine, debug_view_textbuf);
if (textdata == NULL)
return FALSE;
memset(textdata, 0, sizeof(*textdata));
/* by default we track live */ /* by default we track live */
textdata->textbuf = textbuf; textdata->textbuf = textbuf;
@ -931,8 +921,7 @@ static void textbuf_view_free(debug_view *view)
debug_view_textbuf *textdata = (debug_view_textbuf *)view->extra_data; debug_view_textbuf *textdata = (debug_view_textbuf *)view->extra_data;
/* free any memory we callocated */ /* free any memory we callocated */
if (textdata != NULL) auto_free(view->machine, textdata);
free(textdata);
view->extra_data = NULL; view->extra_data = NULL;
} }
@ -1084,10 +1073,7 @@ static int registers_view_alloc(debug_view *view)
return FALSE; return FALSE;
/* allocate memory */ /* allocate memory */
regdata = (debug_view_registers *)malloc(sizeof(*regdata)); regdata = auto_alloc_clear(view->machine, debug_view_registers);
if (regdata == NULL)
return FALSE;
memset(regdata, 0, sizeof(*regdata));
/* default to the first subview */ /* default to the first subview */
regdata->device = view->machine->debugvw_data->registers_subviews->device; regdata->device = view->machine->debugvw_data->registers_subviews->device;
@ -1109,7 +1095,7 @@ static void registers_view_free(debug_view *view)
/* free any memory we callocated */ /* free any memory we callocated */
if (regdata != NULL) if (regdata != NULL)
free(regdata); auto_free(view->machine, regdata);
view->extra_data = NULL; view->extra_data = NULL;
} }
@ -1556,10 +1542,7 @@ static int disasm_view_alloc(debug_view *view)
return FALSE; return FALSE;
/* allocate disasm */ /* allocate disasm */
dasmdata = (debug_view_disasm *)malloc(sizeof(*dasmdata)); dasmdata = auto_alloc_clear(view->machine, debug_view_disasm);
if (dasmdata == NULL)
return FALSE;
memset(dasmdata, 0, sizeof(*dasmdata));
/* default to the first subview */ /* default to the first subview */
dasmdata->space = view->machine->debugvw_data->disasm_subviews->space; dasmdata->space = view->machine->debugvw_data->disasm_subviews->space;
@ -1600,10 +1583,10 @@ static void disasm_view_free(debug_view *view)
{ {
debug_view_expression_free(&dasmdata->expression); debug_view_expression_free(&dasmdata->expression);
if (dasmdata->byteaddress != NULL) if (dasmdata->byteaddress != NULL)
free(dasmdata->byteaddress); auto_free(view->machine, dasmdata->byteaddress);
if (dasmdata->dasm != NULL) if (dasmdata->dasm != NULL)
free(dasmdata->dasm); auto_free(view->machine, dasmdata->dasm);
free(dasmdata); auto_free(view->machine, dasmdata);
} }
view->extra_data = NULL; view->extra_data = NULL;
} }
@ -1841,14 +1824,12 @@ static int disasm_view_recompute(debug_view *view, offs_t pc, int startline, int
dasmdata->allocated.y = view->total.y; dasmdata->allocated.y = view->total.y;
/* allocate address array */ /* allocate address array */
if (dasmdata->byteaddress != NULL) auto_free(view->machine, dasmdata->byteaddress);
free(dasmdata->byteaddress); dasmdata->byteaddress = auto_alloc_array(view->machine, offs_t, dasmdata->allocated.y);
dasmdata->byteaddress = alloc_array_or_die(offs_t, dasmdata->allocated.y);
/* allocate disassembly buffer */ /* allocate disassembly buffer */
if (dasmdata->dasm != NULL) auto_free(view->machine, dasmdata->dasm);
free(dasmdata->dasm); dasmdata->dasm = auto_alloc_array(view->machine, char, dasmdata->allocated.x * dasmdata->allocated.y);
dasmdata->dasm = alloc_array_or_die(char, dasmdata->allocated.x * dasmdata->allocated.y);
} }
/* iterate over lines */ /* iterate over lines */
@ -2411,7 +2392,7 @@ static const memory_subview_item *memory_view_enumerate_subviews(running_machine
astring_printf(tempstring, "CPU '%s' (%s) %s memory", device->tag, device_get_name(device), space->name); astring_printf(tempstring, "CPU '%s' (%s) %s memory", device->tag, device_get_name(device), space->name);
else else
astring_printf(tempstring, "%s '%s' space #%d memory", device_get_name(device), device->tag, spacenum); astring_printf(tempstring, "%s '%s' space #%d memory", device_get_name(device), device->tag, spacenum);
subview = (memory_subview_item *)alloc_array_clear_or_die(UINT8, sizeof(*subview) + astring_len(tempstring)); subview = (memory_subview_item *)auto_alloc_array_clear(machine, UINT8, sizeof(*subview) + astring_len(tempstring));
/* populate the subview */ /* populate the subview */
subview->next = NULL; subview->next = NULL;
@ -2440,7 +2421,7 @@ static const memory_subview_item *memory_view_enumerate_subviews(running_machine
/* determine the string and allocate a subview large enough */ /* determine the string and allocate a subview large enough */
astring_printf(tempstring, "Region '%s'", rgntag); astring_printf(tempstring, "Region '%s'", rgntag);
subview = (memory_subview_item *)alloc_array_clear_or_die(UINT8, sizeof(*subview) + astring_len(tempstring)); subview = (memory_subview_item *)auto_alloc_array_clear(machine, UINT8, sizeof(*subview) + astring_len(tempstring));
/* populate the subview */ /* populate the subview */
subview->next = NULL; subview->next = NULL;
@ -2477,7 +2458,7 @@ static const memory_subview_item *memory_view_enumerate_subviews(running_machine
/* determine the string and allocate a subview large enough */ /* determine the string and allocate a subview large enough */
astring_printf(tempstring, "%s", strrchr(name, '/') + 1); astring_printf(tempstring, "%s", strrchr(name, '/') + 1);
subview = (memory_subview_item *)alloc_array_clear_or_die(UINT8, sizeof(*subview) + astring_len(tempstring)); subview = (memory_subview_item *)auto_alloc_array_clear(machine, UINT8, sizeof(*subview) + astring_len(tempstring));
/* populate the subview */ /* populate the subview */
subview->next = NULL; subview->next = NULL;
@ -2516,7 +2497,7 @@ static int memory_view_alloc(debug_view *view)
return FALSE; return FALSE;
/* allocate memory */ /* allocate memory */
memdata = alloc_clear_or_die(debug_view_memory); memdata = auto_alloc_clear(view->machine, debug_view_memory);
memdata->subviewlist = subviews; memdata->subviewlist = subviews;
/* allocate the expression data */ /* allocate the expression data */
@ -2557,10 +2538,10 @@ static void memory_view_free(debug_view *view)
{ {
memory_subview_item *item = (memory_subview_item *)memdata->subviewlist; memory_subview_item *item = (memory_subview_item *)memdata->subviewlist;
memdata->subviewlist = item->next; memdata->subviewlist = item->next;
free(item); auto_free(view->machine, item);
} }
debug_view_expression_free(&memdata->expression); debug_view_expression_free(&memdata->expression);
free(memdata); auto_free(view->machine, memdata);
} }
view->extra_data = NULL; view->extra_data = NULL;
} }

View File

@ -1978,7 +1978,7 @@ int symtable_add(symbol_table *table, const char *name, const symbol_entry *entr
int strindex; int strindex;
int all_digits, i; int all_digits, i;
assert_always(entry->table == table, "Mismatched symbol tables"); // assert_always(entry->table == table, "Mismatched symbol tables");
/* we cannot add numeric symbols */ /* we cannot add numeric symbols */
all_digits = TRUE; all_digits = TRUE;
@ -1990,7 +1990,7 @@ int symtable_add(symbol_table *table, const char *name, const symbol_entry *entr
break; break;
} }
} }
assert_always(!all_digits, "All-digit symbols are not allowed"); // assert_always(!all_digits, "All-digit symbols are not allowed");
/* see if we already have an entry and just overwrite it if we do */ /* see if we already have an entry and just overwrite it if we do */
oldentry = (symbol_entry *)symtable_find(table, name); oldentry = (symbol_entry *)symtable_find(table, name);

View File

@ -10,7 +10,7 @@
#ifndef __EXPRESS_H__ #ifndef __EXPRESS_H__
#define __EXPRESS_H__ #define __EXPRESS_H__
#include "mamecore.h" #include "osdcore.h"
/*************************************************************************** /***************************************************************************
CONSTANTS CONSTANTS

View File

@ -9,7 +9,7 @@
***************************************************************************/ ***************************************************************************/
#include "mamecore.h" #include "osdcore.h"
#include "textbuf.h" #include "textbuf.h"

View File

@ -75,7 +75,7 @@ void debugger_init(running_machine *machine)
/* allocate a new entry for our global list */ /* allocate a new entry for our global list */
add_exit_callback(machine, debugger_exit); add_exit_callback(machine, debugger_exit);
entry = alloc_or_die(machine_entry); entry = global_alloc(machine_entry);
entry->next = machine_list; entry->next = machine_list;
entry->machine = machine; entry->machine = machine;
machine_list = entry; machine_list = entry;
@ -117,7 +117,7 @@ static void debugger_exit(running_machine *machine)
{ {
machine_entry *deleteme = *entryptr; machine_entry *deleteme = *entryptr;
*entryptr = deleteme->next; *entryptr = deleteme->next;
free(deleteme); global_free(deleteme);
break; break;
} }
} }
@ -137,6 +137,6 @@ void debugger_flush_all_traces_on_abnormal_exit(void)
machine_entry *deleteme = machine_list; machine_entry *deleteme = machine_list;
debug_cpu_flush_traces(deleteme->machine); debug_cpu_flush_traces(deleteme->machine);
machine_list = deleteme->next; machine_list = deleteme->next;
free(deleteme); global_free(deleteme);
} }
} }

View File

@ -15,7 +15,7 @@
#ifndef __DEPRECAT_H__ #ifndef __DEPRECAT_H__
#define __DEPRECAT_H__ #define __DEPRECAT_H__
#include "mamecore.h" #include "emucore.h"
#include "devintrf.h" #include "devintrf.h"

View File

@ -148,7 +148,7 @@ device_config *device_list_add(device_list *devlist, const device_config *owner,
configlen = (UINT32)devtype_get_info_int(type, DEVINFO_INT_INLINE_CONFIG_BYTES); configlen = (UINT32)devtype_get_info_int(type, DEVINFO_INT_INLINE_CONFIG_BYTES);
/* allocate a new device */ /* allocate a new device */
device = (device_config *)alloc_array_or_die(UINT8, sizeof(*device) + strlen(tag)); device = (device_config *)global_alloc_array(UINT8, sizeof(*device) + strlen(tag));
/* add to the map */ /* add to the map */
tmerr = tagmap_add_unique_hash(devlist->map, tag, device, FALSE); tmerr = tagmap_add_unique_hash(devlist->map, tag, device, FALSE);
@ -181,7 +181,7 @@ device_config *device_list_add(device_list *devlist, const device_config *owner,
device->clock = device->owner->clock * ((device->clock >> 12) & 0xfff) / ((device->clock >> 0) & 0xfff); device->clock = device->owner->clock * ((device->clock >> 12) & 0xfff) / ((device->clock >> 0) & 0xfff);
} }
device->static_config = NULL; device->static_config = NULL;
device->inline_config = (configlen == 0) ? NULL : alloc_array_or_die(UINT8, configlen); device->inline_config = (configlen == 0) ? NULL : global_alloc_array(UINT8, configlen);
/* ensure live fields are all cleared */ /* ensure live fields are all cleared */
device->machine = NULL; device->machine = NULL;
@ -260,8 +260,8 @@ void device_list_remove(device_list *devlist, const char *tag)
/* free the device object */ /* free the device object */
if (device->inline_config != NULL) if (device->inline_config != NULL)
free(device->inline_config); global_free(device->inline_config);
free(device); global_free(device);
} }
@ -660,7 +660,7 @@ void device_list_start(running_machine *machine)
fatalerror("Device %s specifies a 0 token length!\n", device_get_name(device)); fatalerror("Device %s specifies a 0 token length!\n", device_get_name(device));
/* allocate memory for the token */ /* allocate memory for the token */
device->token = alloc_array_clear_or_die(UINT8, device->tokenbytes); device->token = auto_alloc_array_clear(machine, UINT8, device->tokenbytes);
/* fill in the remaining runtime fields */ /* fill in the remaining runtime fields */
device->region = memory_region(machine, device->tag); device->region = memory_region(machine, device->tag);
@ -741,8 +741,7 @@ static void device_list_stop(running_machine *machine)
(*stop)(device); (*stop)(device);
/* free allocated memory for the token */ /* free allocated memory for the token */
if (device->token != NULL) auto_free(machine, device->token);
free(device->token);
/* reset all runtime fields */ /* reset all runtime fields */
device->token = NULL; device->token = NULL;

View File

@ -14,7 +14,7 @@
#ifndef __DEVINTRF_H__ #ifndef __DEVINTRF_H__
#define __DEVINTRF_H__ #define __DEVINTRF_H__
#include "mamecore.h" #include "emucore.h"
#include "romload.h" #include "romload.h"
#include "memory.h" #include "memory.h"
#include "tagmap.h" #include "tagmap.h"

View File

@ -227,7 +227,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c
gfx_element *gfx; gfx_element *gfx;
/* allocate memory for the gfx_element structure */ /* allocate memory for the gfx_element structure */
gfx = alloc_clear_or_die(gfx_element); gfx = auto_alloc_clear(machine, gfx_element);
/* fill in the data */ /* fill in the data */
gfx->width = width; gfx->width = width;
@ -256,7 +256,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c
} }
else else
{ {
UINT32 *buffer = alloc_array_or_die(UINT32, gfx->layout.width); UINT32 *buffer = auto_alloc_array(machine, UINT32, gfx->layout.width);
memcpy(buffer, gfx->layout.extxoffs, sizeof(gfx->layout.extxoffs[0]) * gfx->layout.width); memcpy(buffer, gfx->layout.extxoffs, sizeof(gfx->layout.extxoffs[0]) * gfx->layout.width);
gfx->layout.extxoffs = buffer; gfx->layout.extxoffs = buffer;
} }
@ -271,7 +271,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c
} }
else else
{ {
UINT32 *buffer = alloc_array_or_die(UINT32, gfx->layout.height); UINT32 *buffer = auto_alloc_array(machine, UINT32, gfx->layout.height);
memcpy(buffer, gfx->layout.extyoffs, sizeof(gfx->layout.extyoffs[0]) * gfx->layout.height); memcpy(buffer, gfx->layout.extyoffs, sizeof(gfx->layout.extyoffs[0]) * gfx->layout.height);
gfx->layout.extyoffs = buffer; gfx->layout.extyoffs = buffer;
} }
@ -279,10 +279,10 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c
/* allocate a pen usage array for entries with 32 pens or less */ /* allocate a pen usage array for entries with 32 pens or less */
if (gfx->color_depth <= 32) if (gfx->color_depth <= 32)
gfx->pen_usage = alloc_array_or_die(UINT32, gfx->total_elements); gfx->pen_usage = auto_alloc_array(machine, UINT32, gfx->total_elements);
/* allocate a dirty array */ /* allocate a dirty array */
gfx->dirty = alloc_array_or_die(UINT8, gfx->total_elements); gfx->dirty = auto_alloc_array(machine, UINT8, gfx->total_elements);
memset(gfx->dirty, 1, gfx->total_elements * sizeof(*gfx->dirty)); memset(gfx->dirty, 1, gfx->total_elements * sizeof(*gfx->dirty));
/* raw graphics case */ /* raw graphics case */
@ -309,7 +309,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c
gfx->char_modulo = gfx->line_modulo * gfx->origheight; gfx->char_modulo = gfx->line_modulo * gfx->origheight;
/* allocate memory for the data */ /* allocate memory for the data */
gfx->gfxdata = alloc_array_or_die(UINT8, gfx->total_elements * gfx->char_modulo); gfx->gfxdata = auto_alloc_array(machine, UINT8, gfx->total_elements * gfx->char_modulo);
} }
return gfx; return gfx;
@ -338,17 +338,12 @@ void gfx_element_free(gfx_element *gfx)
return; return;
/* free our data */ /* free our data */
if (gfx->layout.extyoffs != NULL) auto_free(gfx->machine, gfx->layout.extyoffs);
free((void *)gfx->layout.extyoffs); auto_free(gfx->machine, gfx->layout.extxoffs);
if (gfx->layout.extxoffs != NULL) auto_free(gfx->machine, gfx->pen_usage);
free((void *)gfx->layout.extxoffs); auto_free(gfx->machine, gfx->dirty);
if (gfx->pen_usage != NULL) auto_free(gfx->machine, gfx->gfxdata);
free(gfx->pen_usage); auto_free(gfx->machine, gfx);
if (gfx->dirty != NULL)
free(gfx->dirty);
if (!(gfx->flags & GFX_ELEMENT_DONT_FREE))
free(gfx->gfxdata);
free(gfx);
} }

View File

@ -14,7 +14,7 @@
#ifndef __DRAWGFX_H__ #ifndef __DRAWGFX_H__
#define __DRAWGFX_H__ #define __DRAWGFX_H__
#include "mamecore.h" #include "emucore.h"
@ -115,7 +115,7 @@ struct _gfx_layout
}; };
/* In mamecore.h: typedef struct _gfx_element gfx_element; */ /* In emucore.h: typedef struct _gfx_element gfx_element; */
struct _gfx_element struct _gfx_element
{ {
UINT16 width; /* current pixel width of each element (changeble with source clipping) */ UINT16 width; /* current pixel width of each element (changeble with source clipping) */

View File

@ -114,7 +114,7 @@ void driver_list_get_approx_matches(const game_driver * const driverlist[], cons
int shufnum; int shufnum;
/* allocate a temporary list */ /* allocate a temporary list */
templist = alloc_array_or_die(const game_driver *, driver_list_get_count(driverlist)); templist = global_alloc_array(const game_driver *, driver_list_get_count(driverlist));
/* build up a list of valid entries */ /* build up a list of valid entries */
for (drvnum = driver_count = 0; driverlist[drvnum] != NULL; drvnum++) for (drvnum = driver_count = 0; driverlist[drvnum] != NULL; drvnum++)
@ -140,12 +140,12 @@ void driver_list_get_approx_matches(const game_driver * const driverlist[], cons
for (matchnum = 0; matchnum < matches; matchnum++) for (matchnum = 0; matchnum < matches; matchnum++)
list[matchnum] = templist[matchnum % driver_count]; list[matchnum] = templist[matchnum % driver_count];
free((void *)templist); global_free(templist);
return; return;
} }
/* allocate some temp memory */ /* allocate some temp memory */
penalty = alloc_array_or_die(int, matches); penalty = global_alloc_array(int, matches);
/* initialize everyone's states */ /* initialize everyone's states */
for (matchnum = 0; matchnum < matches; matchnum++) for (matchnum = 0; matchnum < matches; matchnum++)
@ -187,7 +187,7 @@ void driver_list_get_approx_matches(const game_driver * const driverlist[], cons
} }
/* free our temp memory */ /* free our temp memory */
free(penalty); global_free(penalty);
} }

View File

@ -169,7 +169,7 @@ typedef UINT32 (*video_update_func)(const device_config *screen, bitmap_t *bitma
TYPE DEFINITIONS TYPE DEFINITIONS
***************************************************************************/ ***************************************************************************/
/* In mamecore.h: typedef struct _game_driver game_driver; */ /* In emucore.h: typedef struct _game_driver game_driver; */
struct _game_driver struct _game_driver
{ {
const char * source_file; /* set this to __FILE__ */ const char * source_file; /* set this to __FILE__ */

View File

@ -48,6 +48,8 @@ EMUOBJS = \
$(EMUOBJ)/devintrf.o \ $(EMUOBJ)/devintrf.o \
$(EMUOBJ)/drawgfx.o \ $(EMUOBJ)/drawgfx.o \
$(EMUOBJ)/driver.o \ $(EMUOBJ)/driver.o \
$(EMUOBJ)/emualloc.o \
$(EMUOBJ)/emucore.o \
$(EMUOBJ)/emuopts.o \ $(EMUOBJ)/emuopts.o \
$(EMUOBJ)/emupal.o \ $(EMUOBJ)/emupal.o \
$(EMUOBJ)/fileio.o \ $(EMUOBJ)/fileio.o \
@ -57,7 +59,6 @@ EMUOBJS = \
$(EMUOBJ)/inputseq.o \ $(EMUOBJ)/inputseq.o \
$(EMUOBJ)/inptport.o \ $(EMUOBJ)/inptport.o \
$(EMUOBJ)/mame.o \ $(EMUOBJ)/mame.o \
$(EMUOBJ)/mamecore.o \
$(EMUOBJ)/mconfig.o \ $(EMUOBJ)/mconfig.o \
$(EMUOBJ)/memory.o \ $(EMUOBJ)/memory.o \
$(EMUOBJ)/output.o \ $(EMUOBJ)/output.o \
@ -65,7 +66,6 @@ EMUOBJS = \
$(EMUOBJ)/rendfont.o \ $(EMUOBJ)/rendfont.o \
$(EMUOBJ)/rendlay.o \ $(EMUOBJ)/rendlay.o \
$(EMUOBJ)/rendutil.o \ $(EMUOBJ)/rendutil.o \
$(EMUOBJ)/restrack.o \
$(EMUOBJ)/romload.o \ $(EMUOBJ)/romload.o \
$(EMUOBJ)/sound.o \ $(EMUOBJ)/sound.o \
$(EMUOBJ)/state.o \ $(EMUOBJ)/state.o \

View File

@ -2,7 +2,7 @@
mamecore.c mamecore.c
Simple core functions that are defined in mamecore.h and which may Simple core functions that are defined in emucore.h and which may
need to be accessed by other MAME-related tools. need to be accessed by other MAME-related tools.
Copyright Nicola Salmoria and the MAME Team. Copyright Nicola Salmoria and the MAME Team.
@ -10,7 +10,7 @@
****************************************************************************/ ****************************************************************************/
#include "mamecore.h" #include "emucore.h"
#include <ctype.h> #include <ctype.h>
/* a giant string buffer for temporary strings */ /* a giant string buffer for temporary strings */

View File

@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
mamecore.h emucore.h
General core utilities and macros used throughout MAME. General core utilities and macros used throughout MAME.
@ -20,6 +20,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <exception> #include <exception>
#include "osdcomm.h" #include "osdcomm.h"
#include "emualloc.h"
#include "bitmap.h" #include "bitmap.h"
#include "coreutil.h" #include "coreutil.h"
#include "corestr.h" #include "corestr.h"
@ -61,7 +62,7 @@ typedef UINT32 FPTR;
/* These are forward struct declarations that are used to break /* These are forward struct declarations that are used to break
circular dependencies in the code */ circular dependencies in the code */
typedef struct _running_machine running_machine; class running_machine;
typedef struct _game_driver game_driver; typedef struct _game_driver game_driver;
typedef struct _machine_config machine_config; typedef struct _machine_config machine_config;
typedef struct _gfx_element gfx_element; typedef struct _gfx_element gfx_element;
@ -176,6 +177,14 @@ enum
COMMON MACROS COMMON MACROS
***************************************************************************/ ***************************************************************************/
// Macro for defining a copy constructor and assignment operator to
// prevent copying
#define DISABLE_COPYING(_Type) \
private: \
_Type(const _Type &); \
_Type &operator=(const _Type &) \
/* Macro for declaring enumerator operators for easier porting */ /* Macro for declaring enumerator operators for easier porting */
#ifdef __cplusplus #ifdef __cplusplus
#define DECLARE_ENUM_OPERATORS(type) \ #define DECLARE_ENUM_OPERATORS(type) \
@ -193,11 +202,11 @@ inline void operator--(type &value, int) { value = (type)((int)value - 1); }
#undef assert_always #undef assert_always
#ifdef MAME_DEBUG #ifdef MAME_DEBUG
#define assert(x) do { if (!(x)) fatalerror("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0) #define assert(x) do { if (!(x)) throw emu_fatalerror("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0)
#define assert_always(x, msg) do { if (!(x)) fatalerror("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0) #define assert_always(x, msg) do { if (!(x)) throw emu_fatalerror("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0)
#else #else
#define assert(x) do { } while (0) #define assert(x) do { } while (0)
#define assert_always(x, msg) do { if (!(x)) fatalerror("Fatal error: %s (%s:%d)", msg, __FILE__, __LINE__); } while (0) #define assert_always(x, msg) do { if (!(x)) throw emu_fatalerror("Fatal error: %s (%s:%d)", msg, __FILE__, __LINE__); } while (0)
#endif #endif
@ -325,9 +334,7 @@ inline void operator--(type &value, int) { value = (type)((int)value - 1); }
***************************************************************************/ ***************************************************************************/
// emu_exception is the base class for all emu-related exceptions // emu_exception is the base class for all emu-related exceptions
class emu_exception : public std::exception class emu_exception : public std::exception { };
{
};
// emu_fatalerror is a generic fatal exception that provides an error string // emu_fatalerror is a generic fatal exception that provides an error string

View File

@ -9,7 +9,7 @@
***************************************************************************/ ***************************************************************************/
#include "mamecore.h" #include "emucore.h"
#include "mame.h" #include "mame.h"
#include "fileio.h" #include "fileio.h"
#include "emuopts.h" #include "emuopts.h"

View File

@ -14,7 +14,7 @@
#ifndef __EMUOPTS_H__ #ifndef __EMUOPTS_H__
#define __EMUOPTS_H__ #define __EMUOPTS_H__
#include "mamecore.h" #include "emucore.h"
#include "options.h" #include "options.h"

View File

@ -191,9 +191,7 @@ file_error mame_fopen_ram(const void *data, UINT32 length, UINT32 openflags, mam
file_error filerr; file_error filerr;
/* allocate the file itself */ /* allocate the file itself */
*file = (mame_file *)malloc(sizeof(**file)); *file = global_alloc(mame_file);
if (*file == NULL)
return FILERR_OUT_OF_MEMORY;
/* reset the file handle */ /* reset the file handle */
memset(*file, 0, sizeof(**file)); memset(*file, 0, sizeof(**file));
@ -231,9 +229,7 @@ static file_error fopen_internal(core_options *opts, path_iterator *iterator, co
return FILERR_INVALID_ACCESS; return FILERR_INVALID_ACCESS;
/* allocate the file itself */ /* allocate the file itself */
*file = (mame_file *)malloc(sizeof(**file)); *file = global_alloc(mame_file);
if (*file == NULL)
return FILERR_OUT_OF_MEMORY;
/* reset the file handle */ /* reset the file handle */
memset(*file, 0, sizeof(**file)); memset(*file, 0, sizeof(**file));
@ -387,10 +383,10 @@ void mame_fclose(mame_file *file)
if (file->file != NULL) if (file->file != NULL)
core_fclose(file->file); core_fclose(file->file);
if (file->zipdata != NULL) if (file->zipdata != NULL)
free(file->zipdata); global_free(file->zipdata);
if (file->filename != NULL) if (file->filename != NULL)
astring_free(file->filename); astring_free(file->filename);
free(file); global_free(file);
} }
@ -672,10 +668,7 @@ mame_path *mame_openpath(core_options *opts, const char *searchpath)
mame_path *path; mame_path *path;
/* allocate a new mame_path */ /* allocate a new mame_path */
path = (mame_path *)malloc(sizeof(*path)); path = global_alloc_clear(mame_path);
if (path == NULL)
return NULL;
memset(path, 0, sizeof(*path));
/* initialize the iterator */ /* initialize the iterator */
path_iterator_init(&path->iterator, opts, searchpath); path_iterator_init(&path->iterator, opts, searchpath);
@ -734,7 +727,7 @@ void mame_closepath(mame_path *path)
/* free memory */ /* free memory */
if (path->pathbuffer != NULL) if (path->pathbuffer != NULL)
astring_free(path->pathbuffer); astring_free(path->pathbuffer);
free(path); global_free(path);
} }
@ -874,15 +867,13 @@ static file_error load_zipped_file(mame_file *file)
assert(file->zipfile != NULL); assert(file->zipfile != NULL);
/* allocate some memory */ /* allocate some memory */
file->zipdata = (UINT8 *)malloc(file->ziplength); file->zipdata = global_alloc_array(UINT8, file->ziplength);
if (file->zipdata == NULL)
return FILERR_OUT_OF_MEMORY;
/* read the data into our buffer and return */ /* read the data into our buffer and return */
ziperr = zip_file_decompress(file->zipfile, file->zipdata, file->ziplength); ziperr = zip_file_decompress(file->zipfile, file->zipdata, file->ziplength);
if (ziperr != ZIPERR_NONE) if (ziperr != ZIPERR_NONE)
{ {
free(file->zipdata); global_free(file->zipdata);
file->zipdata = NULL; file->zipdata = NULL;
return FILERR_FAILURE; return FILERR_FAILURE;
} }
@ -891,7 +882,7 @@ static file_error load_zipped_file(mame_file *file)
filerr = core_fopen_ram(file->zipdata, file->ziplength, file->openflags, &file->file); filerr = core_fopen_ram(file->zipdata, file->ziplength, file->openflags, &file->file);
if (filerr != FILERR_NONE) if (filerr != FILERR_NONE)
{ {
free(file->zipdata); global_free(file->zipdata);
file->zipdata = NULL; file->zipdata = NULL;
return FILERR_FAILURE; return FILERR_FAILURE;
} }

View File

@ -14,7 +14,7 @@
#ifndef __FILEIO_H__ #ifndef __FILEIO_H__
#define __FILEIO_H__ #define __FILEIO_H__
#include "mamecore.h" #include "emucore.h"
#include "osdcore.h" #include "osdcore.h"
#include "corefile.h" #include "corefile.h"
#include "mame.h" #include "mame.h"

View File

@ -14,7 +14,7 @@
#ifndef __INFO_H__ #ifndef __INFO_H__
#define __INFO_H__ #define __INFO_H__
#include "mamecore.h" #include "emucore.h"
/*************************************************************************** /***************************************************************************

View File

@ -3094,7 +3094,7 @@ static input_port_config *port_config_alloc(const input_port_config **listhead)
input_port_config *config; input_port_config *config;
/* allocate memory */ /* allocate memory */
config = alloc_clear_or_die(input_port_config); config = global_alloc_clear(input_port_config);
/* add it to the tail */ /* add it to the tail */
for (tailptr = listhead; *tailptr != NULL; tailptr = &(*tailptr)->next) ; for (tailptr = listhead; *tailptr != NULL; tailptr = &(*tailptr)->next) ;
@ -3121,7 +3121,7 @@ static void port_config_free(const input_port_config **portptr)
*portptr = port->next; *portptr = port->next;
/* free ourself */ /* free ourself */
free(port); global_free(port);
} }
@ -3155,7 +3155,7 @@ static input_field_config *field_config_alloc(input_port_config *port, int type,
int seqtype; int seqtype;
/* allocate memory */ /* allocate memory */
config = alloc_clear_or_die(input_field_config); config = global_alloc_clear(input_field_config);
/* fill in the basic field values */ /* fill in the basic field values */
config->port = port; config->port = port;
@ -3246,7 +3246,7 @@ static void field_config_free(input_field_config **fieldptr)
*fieldptr = (input_field_config *)field->next; *fieldptr = (input_field_config *)field->next;
/* free ourself */ /* free ourself */
free(field); global_free(field);
} }
@ -3262,7 +3262,7 @@ static input_setting_config *setting_config_alloc(input_field_config *field, inp
input_setting_config *config; input_setting_config *config;
/* allocate memory */ /* allocate memory */
config = alloc_clear_or_die(input_setting_config); config = global_alloc_clear(input_setting_config);
/* fill in the basic setting values */ /* fill in the basic setting values */
config->field = field; config->field = field;
@ -3290,7 +3290,7 @@ static void setting_config_free(input_setting_config **settingptr)
*settingptr = (input_setting_config *)setting->next; *settingptr = (input_setting_config *)setting->next;
/* free ourself */ /* free ourself */
free(setting); global_free(setting);
} }
@ -3321,7 +3321,7 @@ static const input_field_diplocation *diplocation_list_alloc(const input_field_c
const char *comma, *colon, *number; const char *comma, *colon, *number;
/* allocate a new entry */ /* allocate a new entry */
*tailptr = alloc_clear_or_die(input_field_diplocation); *tailptr = global_alloc_clear(input_field_diplocation);
entries++; entries++;
/* find the end of this entry */ /* find the end of this entry */
@ -3340,7 +3340,7 @@ static const input_field_diplocation *diplocation_list_alloc(const input_field_c
/* allocate and copy the name if it is present */ /* allocate and copy the name if it is present */
if (colon != NULL) if (colon != NULL)
{ {
(*tailptr)->swname = lastname = alloc_array_or_die(char, colon - tempbuf + 1); (*tailptr)->swname = lastname = global_alloc_array(char, colon - tempbuf + 1);
strncpy(lastname, tempbuf, colon - tempbuf); strncpy(lastname, tempbuf, colon - tempbuf);
lastname[colon - tempbuf] = 0; lastname[colon - tempbuf] = 0;
number = colon + 1; number = colon + 1;
@ -3355,7 +3355,7 @@ static const input_field_diplocation *diplocation_list_alloc(const input_field_c
error_buf_append(errorbuf, errorbuflen, "Switch location '%s' missing switch name!\n", location); error_buf_append(errorbuf, errorbuflen, "Switch location '%s' missing switch name!\n", location);
lastname = (char *)"UNK"; lastname = (char *)"UNK";
} }
(*tailptr)->swname = namecopy = alloc_array_or_die(char, strlen(lastname) + 1); (*tailptr)->swname = namecopy = global_alloc_array(char, strlen(lastname) + 1);
strcpy(namecopy, lastname); strcpy(namecopy, lastname);
} }
@ -3400,13 +3400,13 @@ static void diplocation_free(input_field_diplocation **diplocptr)
/* free the name */ /* free the name */
if (diploc->swname != NULL) if (diploc->swname != NULL)
free((void *)diploc->swname); global_free(diploc->swname);
/* remove ourself from the list */ /* remove ourself from the list */
*diplocptr = (input_field_diplocation *)diploc->next; *diplocptr = (input_field_diplocation *)diploc->next;
/* free ourself */ /* free ourself */
free(diploc); global_free(diploc);
} }
@ -3587,8 +3587,8 @@ static void load_remap_table(running_machine *machine, xml_data_node *parentnode
int remapnum; int remapnum;
/* allocate tables */ /* allocate tables */
oldtable = alloc_array_or_die(input_code, count); oldtable = global_alloc_array(input_code, count);
newtable = alloc_array_or_die(input_code, count); newtable = global_alloc_array(input_code, count);
/* build up the remap table */ /* build up the remap table */
count = 0; count = 0;
@ -3625,8 +3625,8 @@ static void load_remap_table(running_machine *machine, xml_data_node *parentnode
} }
/* release the tables */ /* release the tables */
free(oldtable); global_free(oldtable);
free(newtable); global_free(newtable);
} }
} }

View File

@ -759,7 +759,11 @@ input_device *input_device_add(running_machine *machine, input_device_class devc
assert(devclass != DEVICE_CLASS_INVALID && devclass < DEVICE_CLASS_MAXIMUM); assert(devclass != DEVICE_CLASS_INVALID && devclass < DEVICE_CLASS_MAXIMUM);
/* allocate a new device */ /* allocate a new device */
devlist->list = auto_extend_array(machine, devlist->list, input_device, devlist->count + 1); input_device *newlist = auto_alloc_array(machine, input_device, devlist->count + 1);
for (int devnum = 0; devnum < devlist->count; devnum++)
newlist[devnum] = devlist->list[devnum];
auto_free(machine, devlist->list);
devlist->list = newlist;
device = &devlist->list[devlist->count++]; device = &devlist->list[devlist->count++];
memset(device, 0, sizeof(*device)); memset(device, 0, sizeof(*device));

View File

@ -14,7 +14,7 @@
#ifndef __INPUT_H__ #ifndef __INPUT_H__
#define __INPUT_H__ #define __INPUT_H__
#include "mamecore.h" #include "emucore.h"
#include "astring.h" #include "astring.h"

View File

@ -9,8 +9,7 @@
***************************************************************************/ ***************************************************************************/
#include "inputseq.h" #include "mame.h"
#include "restrack.h"
#include <ctype.h> #include <ctype.h>
@ -511,7 +510,7 @@ astring *input_seq_to_tokens(running_machine *machine, astring *string, const in
int input_seq_from_tokens(running_machine *machine, const char *string, input_seq *seq) int input_seq_from_tokens(running_machine *machine, const char *string, input_seq *seq)
{ {
char *strcopy = alloc_array_or_die(char, strlen(string) + 1); char *strcopy = auto_alloc_array(machine, char, strlen(string) + 1);
char *str = strcopy; char *str = strcopy;
int result = FALSE; int result = FALSE;
@ -565,7 +564,7 @@ int input_seq_from_tokens(running_machine *machine, const char *string, input_se
str = strtemp + 1; str = strtemp + 1;
} }
free(strcopy); auto_free(machine, strcopy);
return result; return result;
} }

View File

@ -323,19 +323,19 @@ static DEVICE_NVRAM( eeprom )
if (read_or_write) if (read_or_write)
{ {
UINT8 *buffer = alloc_array_or_die(UINT8, eeprom_bytes); UINT8 *buffer = auto_alloc_array(device->machine, UINT8, eeprom_bytes);
for (offs = 0; offs < eeprom_bytes; offs++) for (offs = 0; offs < eeprom_bytes; offs++)
buffer[offs] = memory_read_byte(device->space[0], offs); buffer[offs] = memory_read_byte(device->space[0], offs);
mame_fwrite(file, buffer, eeprom_bytes); mame_fwrite(file, buffer, eeprom_bytes);
free(buffer); auto_free(device->machine, buffer);
} }
else if (file != NULL) else if (file != NULL)
{ {
UINT8 *buffer = alloc_array_or_die(UINT8, eeprom_bytes); UINT8 *buffer = auto_alloc_array(device->machine, UINT8, eeprom_bytes);
mame_fread(file, buffer, eeprom_bytes); mame_fread(file, buffer, eeprom_bytes);
for (offs = 0; offs < eeprom_bytes; offs++) for (offs = 0; offs < eeprom_bytes; offs++)
memory_write_byte(device->space[0], offs, buffer[offs]); memory_write_byte(device->space[0], offs, buffer[offs]);
free(buffer); auto_free(device->machine, buffer);
} }
else else
{ {

View File

@ -14,7 +14,7 @@
#ifndef __MACHINE_GENERIC_H__ #ifndef __MACHINE_GENERIC_H__
#define __MACHINE_GENERIC_H__ #define __MACHINE_GENERIC_H__
#include "mamecore.h" #include "emucore.h"

View File

@ -848,10 +848,15 @@ static void read_track_data(laserdisc_state *ld)
frame->lastfield = tracknum * 2 + fieldnum; frame->lastfield = tracknum * 2 + fieldnum;
/* set the video target information */ /* set the video target information */
ldcore->videotarget = *frame->bitmap; ldcore->videotarget.alloc = NULL;
ldcore->videotarget.base = BITMAP_ADDR16(&ldcore->videotarget, fieldnum, 0); ldcore->videotarget.base = BITMAP_ADDR16(frame->bitmap, fieldnum, 0);
ldcore->videotarget.height /= 2; ldcore->videotarget.rowpixels = frame->bitmap->rowpixels * 2;
ldcore->videotarget.rowpixels *= 2; ldcore->videotarget.width = frame->bitmap->width;
ldcore->videotarget.height = frame->bitmap->height / 2;
ldcore->videotarget.format = frame->bitmap->format;
ldcore->videotarget.bpp = frame->bitmap->bpp;
ldcore->videotarget.palette = frame->bitmap->palette;
ldcore->videotarget.cliprect = frame->bitmap->cliprect;
ldcore->avconfig.video = &ldcore->videotarget; ldcore->avconfig.video = &ldcore->videotarget;
/* set the audio target information */ /* set the audio target information */
@ -1397,15 +1402,14 @@ static void init_video(const device_config *device)
frame_data *frame = &ldcore->frame[index]; frame_data *frame = &ldcore->frame[index];
/* first allocate a YUY16 bitmap at 2x the height */ /* first allocate a YUY16 bitmap at 2x the height */
frame->bitmap = auto_bitmap_alloc(device->machine, ldcore->width, ldcore->height * 2, BITMAP_FORMAT_YUY16); frame->bitmap = auto_alloc(device->machine, bitmap_t(ldcore->width, ldcore->height * 2, BITMAP_FORMAT_YUY16));
fillbitmap_yuy16(frame->bitmap, 40, 109, 240); fillbitmap_yuy16(frame->bitmap, 40, 109, 240);
/* make a copy of the bitmap that clips out the VBI and horizontal blanking areas */ /* make a copy of the bitmap that clips out the VBI and horizontal blanking areas */
frame->visbitmap = auto_alloc(device->machine, bitmap_t); frame->visbitmap = auto_alloc(device->machine, bitmap_t(BITMAP_ADDR16(frame->visbitmap, 44, frame->bitmap->width * 8 / 720),
*frame->visbitmap = *frame->bitmap; frame->bitmap->width - 2 * frame->bitmap->width * 8 / 720,
frame->visbitmap->base = BITMAP_ADDR16(frame->visbitmap, 44, frame->bitmap->width * 8 / 720); frame->bitmap->height - 44,
frame->visbitmap->height -= 44; frame->bitmap->rowpixels, frame->bitmap->format));
frame->visbitmap->width -= 2 * frame->bitmap->width * 8 / 720;
} }
/* allocate an empty frame of the same size */ /* allocate an empty frame of the same size */

View File

@ -105,7 +105,7 @@ int SCSIBase( const SCSIClass *scsiClass, int operation, void *file, INT64 intpa
SCSIInstance *SCSIMalloc( running_machine *machine, const SCSIClass *scsiClass ) SCSIInstance *SCSIMalloc( running_machine *machine, const SCSIClass *scsiClass )
{ {
SCSIInstance *scsiInstance = (SCSIInstance *)alloc_array_or_die(UINT8, SCSISizeof( scsiClass )); SCSIInstance *scsiInstance = (SCSIInstance *)auto_alloc_array(machine, UINT8, SCSISizeof( scsiClass ));
scsiInstance->scsiClass = scsiClass; scsiInstance->scsiClass = scsiClass;
scsiInstance->machine = machine; scsiInstance->machine = machine;
return scsiInstance; return scsiInstance;

View File

@ -145,7 +145,7 @@ static int scsidev_dispatch( int operation, void *file, INT64 intparm, void *ptr
return 0; return 0;
case SCSIOP_DELETE_INSTANCE: case SCSIOP_DELETE_INSTANCE:
free( (SCSIInstance *)file ); auto_free( ((SCSIInstance *)file)->machine, file );
return 0; return 0;
} }
return 0; return 0;

View File

@ -198,11 +198,8 @@ const char mame_disclaimer[] =
static int parse_ini_file(core_options *options, const char *name, int priority); static int parse_ini_file(core_options *options, const char *name, int priority);
static running_machine *create_machine(const game_driver *driver);
static void destroy_machine(running_machine *machine);
static void init_machine(running_machine *machine); static void init_machine(running_machine *machine);
static TIMER_CALLBACK( soft_reset ); static TIMER_CALLBACK( soft_reset );
static void free_callback_list(callback_item **cb);
static void saveload_init(running_machine *machine); static void saveload_init(running_machine *machine);
static void handle_save(running_machine *machine); static void handle_save(running_machine *machine);
@ -281,7 +278,7 @@ int mame_execute(core_options *options)
mame_parse_ini_files(mame_options(), driver); mame_parse_ini_files(mame_options(), driver);
/* create the machine structure and driver */ /* create the machine structure and driver */
machine = create_machine(driver); machine = global_alloc(running_machine(driver));
mame = machine->mame_data; mame = machine->mame_data;
/* start in the "pre-init phase" */ /* start in the "pre-init phase" */
@ -290,8 +287,6 @@ int mame_execute(core_options *options)
/* looooong term: remove this */ /* looooong term: remove this */
global_machine = machine; global_machine = machine;
init_resource_tracking();
/* use try/catch for deep error recovery */ /* use try/catch for deep error recovery */
try try
{ {
@ -300,9 +295,6 @@ int mame_execute(core_options *options)
/* move to the init phase */ /* move to the init phase */
mame->current_phase = MAME_PHASE_INIT; mame->current_phase = MAME_PHASE_INIT;
/* start tracking resources for real */
begin_resource_tracking();
/* if we have a logfile, set up the callback */ /* if we have a logfile, set up the callback */
mame->logerror_callback_list = NULL; mame->logerror_callback_list = NULL;
if (options_get_bool(mame_options(), OPTION_LOG)) if (options_get_bool(mame_options(), OPTION_LOG))
@ -324,11 +316,6 @@ int mame_execute(core_options *options)
ui_display_startup_screens(machine, firstrun, !settingsloaded); ui_display_startup_screens(machine, firstrun, !settingsloaded);
firstrun = FALSE; firstrun = FALSE;
/* start resource tracking; note that soft_reset assumes it can */
/* call end_resource_tracking followed by begin_resource_tracking */
/* to clear out resources allocated between resets */
begin_resource_tracking();
/* perform a soft reset -- this takes us to the running phase */ /* perform a soft reset -- this takes us to the running phase */
soft_reset(machine, NULL, 0); soft_reset(machine, NULL, 0);
@ -356,9 +343,6 @@ int mame_execute(core_options *options)
/* and out via the exit phase */ /* and out via the exit phase */
mame->current_phase = MAME_PHASE_EXIT; mame->current_phase = MAME_PHASE_EXIT;
/* stop tracking resources at this level */
end_resource_tracking();
/* save the NVRAM and configuration */ /* save the NVRAM and configuration */
sound_mute(machine, TRUE); sound_mute(machine, TRUE);
nvram_save(machine); nvram_save(machine);
@ -371,7 +355,7 @@ int mame_execute(core_options *options)
if (fatal.exitcode() != 0) if (fatal.exitcode() != 0)
error = fatal.exitcode(); error = fatal.exitcode();
} }
catch (emu_exception &exception) catch (emu_exception &)
{ {
mame_printf_error("Caught unhandled emulator exception\n"); mame_printf_error("Caught unhandled emulator exception\n");
error = MAMERR_FATALERROR; error = MAMERR_FATALERROR;
@ -386,19 +370,10 @@ int mame_execute(core_options *options)
for (cb = mame->exit_callback_list; cb; cb = cb->next) for (cb = mame->exit_callback_list; cb; cb = cb->next)
(*cb->func.exit)(machine); (*cb->func.exit)(machine);
/* close all inner resource tracking */
exit_resource_tracking();
/* close the logfile */ /* close the logfile */
if (mame->logfile != NULL) if (mame->logfile != NULL)
mame_fclose(mame->logfile); mame_fclose(mame->logfile);
/* free our callback lists */
free_callback_list(&mame->exit_callback_list);
free_callback_list(&mame->pause_callback_list);
free_callback_list(&mame->reset_callback_list);
free_callback_list(&mame->frame_callback_list);
/* grab data from the MAME structure before it goes away */ /* grab data from the MAME structure before it goes away */
if (mame->new_driver_pending != NULL) if (mame->new_driver_pending != NULL)
{ {
@ -408,7 +383,7 @@ int mame_execute(core_options *options)
exit_pending = mame->exit_pending; exit_pending = mame->exit_pending;
/* destroy the machine */ /* destroy the machine */
destroy_machine(machine); global_free(machine);
/* reset the options */ /* reset the options */
mame_opts = NULL; mame_opts = NULL;
@ -457,7 +432,7 @@ void add_frame_callback(running_machine *machine, void (*callback)(running_machi
assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_frame_callback at init time!"); assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_frame_callback at init time!");
/* allocate memory */ /* allocate memory */
cb = alloc_or_die(callback_item); cb = auto_alloc(machine, callback_item);
/* add us to the end of the list */ /* add us to the end of the list */
cb->func.frame = callback; cb->func.frame = callback;
@ -480,7 +455,7 @@ void add_reset_callback(running_machine *machine, void (*callback)(running_machi
assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_reset_callback at init time!"); assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_reset_callback at init time!");
/* allocate memory */ /* allocate memory */
cb = alloc_or_die(callback_item); cb = auto_alloc(machine, callback_item);
/* add us to the end of the list */ /* add us to the end of the list */
cb->func.reset = callback; cb->func.reset = callback;
@ -503,7 +478,7 @@ void add_pause_callback(running_machine *machine, void (*callback)(running_machi
assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_pause_callback at init time!"); assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_pause_callback at init time!");
/* allocate memory */ /* allocate memory */
cb = alloc_or_die(callback_item); cb = auto_alloc(machine, callback_item);
/* add us to the end of the list */ /* add us to the end of the list */
cb->func.pause = callback; cb->func.pause = callback;
@ -526,7 +501,7 @@ void add_exit_callback(running_machine *machine, void (*callback)(running_machin
assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_exit_callback at init time!"); assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_exit_callback at init time!");
/* allocate memory */ /* allocate memory */
cb = alloc_or_die(callback_item); cb = auto_alloc(machine, callback_item);
/* add us to the head of the list */ /* add us to the head of the list */
cb->func.exit = callback; cb->func.exit = callback;
@ -793,7 +768,7 @@ UINT8 *memory_region_alloc(running_machine *machine, const char *name, UINT32 le
fatalerror("memory_region_alloc called with duplicate region name \"%s\"\n", name); fatalerror("memory_region_alloc called with duplicate region name \"%s\"\n", name);
/* allocate the region */ /* allocate the region */
info = (region_info *)alloc_array_or_die(UINT8, sizeof(*info) + length); info = (region_info *)auto_alloc_array(machine, UINT8, sizeof(*info) + length);
info->next = NULL; info->next = NULL;
info->name = astring_dupc(name); info->name = astring_dupc(name);
info->length = length; info->length = length;
@ -835,7 +810,7 @@ void memory_region_free(running_machine *machine, const char *name)
/* free the region */ /* free the region */
astring_free(info->name); astring_free(info->name);
free(info); auto_free(machine, info);
break; break;
} }
} }
@ -1340,92 +1315,109 @@ static int parse_ini_file(core_options *options, const char *name, int priority)
/*------------------------------------------------- /*-------------------------------------------------
create_machine - create the running machine running_machine - create the running machine
object and initialize it based on options object and initialize it based on options
-------------------------------------------------*/ -------------------------------------------------*/
static running_machine *create_machine(const game_driver *driver) running_machine::running_machine(const game_driver *driver)
: config(NULL),
firstcpu(NULL),
gamedrv(driver),
basename(NULL),
primary_screen(NULL),
palette(NULL),
pens(NULL),
colortable(NULL),
shadow_table(NULL),
priority_bitmap(NULL),
sample_rate(0),
debug_flags(0),
mame_data(NULL),
cpuexec_data(NULL),
timer_data(NULL),
state_data(NULL),
memory_data(NULL),
palette_data(NULL),
tilemap_data(NULL),
streams_data(NULL),
devices_data(NULL),
romload_data(NULL),
sound_data(NULL),
input_data(NULL),
input_port_data(NULL),
ui_input_data(NULL),
cheat_data(NULL),
debugcpu_data(NULL),
debugvw_data(NULL),
generic_machine_data(NULL),
generic_video_data(NULL),
generic_audio_data(NULL),
#ifdef MESS
images_data(NULL),
ui_mess_data(NULL),
#endif /* MESS */
driver_data(NULL)
{ {
running_machine *machine; try
/* allocate memory for the machine */
machine = (running_machine *)malloc(sizeof(*machine));
if (machine == NULL)
goto error;
memset(machine, 0, sizeof(*machine));
/* allocate memory for the internal mame_data */
machine->mame_data = (mame_private *)malloc(sizeof(*machine->mame_data));
if (machine->mame_data == NULL)
goto error;
memset(machine->mame_data, 0, sizeof(*machine->mame_data));
/* allocate memory for the memory region map */
machine->mame_data->regionmap = tagmap_alloc();
if (machine->mame_data->regionmap == NULL)
goto error;
/* initialize the driver-related variables in the machine */
machine->gamedrv = driver;
machine->basename = mame_strdup(driver->name);
machine->config = machine_config_alloc(driver->machine_config);
/* allocate the driver data */
if (machine->config->driver_data_size != 0)
{ {
machine->driver_data = malloc(machine->config->driver_data_size); memset(&portlist, 0, sizeof(portlist));
if (machine->driver_data == NULL) memset(gfx, 0, sizeof(gfx));
goto error; memset(&generic, 0, sizeof(generic));
memset(machine->driver_data, 0, machine->config->driver_data_size);
/* allocate memory for the internal mame_data */
mame_data = auto_alloc_clear(this, mame_private);
/* allocate memory for the memory region map */
mame_data->regionmap = tagmap_alloc();
if (mame_data->regionmap == NULL)
throw std::bad_alloc();
/* initialize the driver-related variables in the machine */
basename = mame_strdup(driver->name);
config = machine_config_alloc(driver->machine_config);
/* allocate the driver data */
if (config->driver_data_size != 0)
driver_data = auto_alloc_array_clear(this, UINT8, config->driver_data_size);
/* find devices */
firstcpu = cpu_first(config);
primary_screen = video_screen_first(config);
/* attach this machine to all the devices in the configuration */
device_list_attach_machine(this);
/* fetch core options */
sample_rate = options_get_int(mame_options(), OPTION_SAMPLERATE);
debug_flags = options_get_bool(mame_options(), OPTION_DEBUG) ? (DEBUG_FLAG_ENABLED | DEBUG_FLAG_CALL_HOOK) : 0;
}
catch (std::bad_alloc &)
{
if (driver_data != NULL)
auto_free(this, driver_data);
if (config != NULL)
machine_config_free((machine_config *)config);
if (mame_data != NULL)
auto_free(this, mame_data);
} }
/* find devices */
machine->firstcpu = cpu_first(machine->config);
machine->primary_screen = video_screen_first(machine->config);
/* attach this machine to all the devices in the configuration */
device_list_attach_machine(machine);
/* fetch core options */
machine->sample_rate = options_get_int(mame_options(), OPTION_SAMPLERATE);
machine->debug_flags = options_get_bool(mame_options(), OPTION_DEBUG) ? (DEBUG_FLAG_ENABLED | DEBUG_FLAG_CALL_HOOK) : 0;
return machine;
error:
if (machine->driver_data != NULL)
free(machine->driver_data);
if (machine->config != NULL)
machine_config_free((machine_config *)machine->config);
if (machine->mame_data != NULL)
free(machine->mame_data);
if (machine != NULL)
free(machine);
return NULL;
} }
/*------------------------------------------------- /*-------------------------------------------------
destroy_machine - free the machine data ~running_machine - free the machine data
-------------------------------------------------*/ -------------------------------------------------*/
static void destroy_machine(running_machine *machine) running_machine::~running_machine()
{ {
assert(machine == global_machine); assert(this == global_machine);
if (config != NULL)
machine_config_free((machine_config *)config);
if (mame_data != NULL && mame_data->regionmap != NULL)
tagmap_free(mame_data->regionmap);
if (basename != NULL)
auto_free(this, basename);
if (machine->driver_data != NULL)
free(machine->driver_data);
if (machine->config != NULL)
machine_config_free((machine_config *)machine->config);
if (machine->mame_data != NULL)
{
if (machine->mame_data->regionmap != NULL)
tagmap_free(machine->mame_data->regionmap);
free(machine->mame_data);
}
if (machine->basename != NULL)
free((void *)machine->basename);
free(machine);
global_machine = NULL; global_machine = NULL;
} }
@ -1555,11 +1547,6 @@ static TIMER_CALLBACK( soft_reset )
/* temporarily in the reset phase */ /* temporarily in the reset phase */
mame->current_phase = MAME_PHASE_RESET; mame->current_phase = MAME_PHASE_RESET;
/* a bit gross -- back off of the resource tracking, and put it back at the end */
assert(get_resource_tag() == 2);
end_resource_tracking();
begin_resource_tracking();
/* call all registered reset callbacks */ /* call all registered reset callbacks */
for (cb = machine->mame_data->reset_callback_list; cb; cb = cb->next) for (cb = machine->mame_data->reset_callback_list; cb; cb = cb->next)
(*cb->func.reset)(machine); (*cb->func.reset)(machine);
@ -1580,21 +1567,6 @@ static TIMER_CALLBACK( soft_reset )
} }
/*-------------------------------------------------
free_callback_list - free a list of callbacks
-------------------------------------------------*/
static void free_callback_list(callback_item **cb)
{
while (*cb)
{
callback_item *temp = *cb;
*cb = (*cb)->next;
free(temp);
}
}
/*************************************************************************** /***************************************************************************
SAVE/RESTORE SAVE/RESTORE

View File

@ -12,10 +12,9 @@
#ifndef __MAME_H__ #ifndef __MAME_H__
#define __MAME_H__ #define __MAME_H__
#include "mamecore.h" #include "emucore.h"
#include "video.h" #include "video.h"
#include "crsshair.h" #include "crsshair.h"
#include "restrack.h"
#include "options.h" #include "options.h"
#include "inptport.h" #include "inptport.h"
#include "cpuintrf.h" #include "cpuintrf.h"
@ -27,6 +26,7 @@
#endif /* MESS */ #endif /* MESS */
/*************************************************************************** /***************************************************************************
CONSTANTS CONSTANTS
***************************************************************************/ ***************************************************************************/
@ -114,6 +114,23 @@ typedef enum _output_channel output_channel;
/***************************************************************************
MACROS
***************************************************************************/
// global allocation helpers
#define auto_alloc(m, t) pool_alloc(static_cast<running_machine *>(m)->respool, t)
#define auto_alloc_clear(m, t) pool_alloc_clear(static_cast<running_machine *>(m)->respool, t)
#define auto_alloc_array(m, t, c) pool_alloc_array(static_cast<running_machine *>(m)->respool, t, c)
#define auto_alloc_array_clear(m, t, c) pool_alloc_array_clear(static_cast<running_machine *>(m)->respool, t, c)
#define auto_free(m, v) pool_free(static_cast<running_machine *>(m)->respool, v)
#define auto_astring_alloc(m) auto_alloc(m, astring)
#define auto_bitmap_alloc(m, w, h, f) auto_alloc(m, bitmap_t(w, h, f))
#define auto_strdup(m, s) strcpy(auto_alloc_array(m, char, strlen(s) + 1), s)
/*************************************************************************** /***************************************************************************
TYPE DEFINITIONS TYPE DEFINITIONS
***************************************************************************/ ***************************************************************************/
@ -178,9 +195,16 @@ struct _generic_pointers
/* description of the currently-running machine */ /* description of the currently-running machine */
/* typedef struct _running_machine running_machine; -- in mamecore.h */ class running_machine
struct _running_machine
{ {
DISABLE_COPYING(running_machine);
public:
running_machine(const game_driver *driver);
~running_machine();
resource_pool respool; /* pool of resources for this machine */
/* configuration data */ /* configuration data */
const machine_config * config; /* points to the constructed machine_config */ const machine_config * config; /* points to the constructed machine_config */
input_port_list portlist; /* points to a list of input port configurations */ input_port_list portlist; /* points to a list of input port configurations */

View File

@ -71,7 +71,7 @@ machine_config *machine_config_alloc(const machine_config_token *tokens)
machine_config *config; machine_config *config;
/* allocate a new configuration object */ /* allocate a new configuration object */
config = alloc_clear_or_die(machine_config); config = global_alloc_clear(machine_config);
/* initialize the device list */ /* initialize the device list */
device_list_init(&config->devicelist, TRUE); device_list_init(&config->devicelist, TRUE);
@ -96,7 +96,7 @@ void machine_config_free(machine_config *config)
device_list_deinit(&config->devicelist); device_list_deinit(&config->devicelist);
/* release the configuration itself */ /* release the configuration itself */
free(config); global_free(config);
} }

View File

@ -113,7 +113,7 @@ enum
TYPE DEFINITIONS TYPE DEFINITIONS
***************************************************************************/ ***************************************************************************/
/* In mamecore.h: typedef struct _machine_config machine_config; */ /* In emucore.h: typedef struct _machine_config machine_config; */
struct _machine_config struct _machine_config
{ {
UINT32 driver_data_size; /* amount of memory needed for driver_data */ UINT32 driver_data_size; /* amount of memory needed for driver_data */

View File

@ -528,7 +528,7 @@ INLINE void add_bank_reference(bank_info *bank, const address_space *space)
return; return;
/* allocate a new entry and fill it */ /* allocate a new entry and fill it */
(*refptr) = alloc_or_die(bank_reference); (*refptr) = auto_alloc(space->machine, bank_reference);
(*refptr)->next = NULL; (*refptr)->next = NULL;
(*refptr)->space = space; (*refptr)->space = space;
} }
@ -862,7 +862,7 @@ address_map *address_map_alloc(const device_config *device, const game_driver *d
const addrmap_token *default_map; const addrmap_token *default_map;
address_map *map; address_map *map;
map = alloc_clear_or_die(address_map); map = global_alloc_clear(address_map);
/* append the internal device map (first so it takes priority) */ /* append the internal device map (first so it takes priority) */
internal_map = (const addrmap_token *)device_get_info_ptr(device, DEVINFO_PTR_INTERNAL_MEMORY_MAP + spacenum); internal_map = (const addrmap_token *)device_get_info_ptr(device, DEVINFO_PTR_INTERNAL_MEMORY_MAP + spacenum);
@ -900,11 +900,11 @@ void address_map_free(address_map *map)
astring_free(entry->write.derived_tag); astring_free(entry->write.derived_tag);
if (entry->region_string != NULL) if (entry->region_string != NULL)
astring_free(entry->region_string); astring_free(entry->region_string);
free(entry); global_free(entry);
} }
/* free the map */ /* free the map */
free(map); global_free(map);
} }
@ -1215,8 +1215,8 @@ void memory_set_bankptr(running_machine *machine, const char *tag, void *base)
fatalerror("memory_set_bankptr called for unknown bank '%s'", tag); fatalerror("memory_set_bankptr called for unknown bank '%s'", tag);
if (base == NULL) if (base == NULL)
fatalerror("memory_set_bankptr called NULL base"); fatalerror("memory_set_bankptr called NULL base");
if (ALLOW_ONLY_AUTO_MALLOC_BANKS) // if (ALLOW_ONLY_AUTO_MALLOC_BANKS)
validate_auto_malloc_memory(base, bank->byteend - bank->bytestart + 1); // validate_auto_malloc_memory(base, bank->byteend - bank->bytestart + 1);
/* set the base */ /* set the base */
memdata->bank_ptr[bank->index] = (UINT8 *)base; memdata->bank_ptr[bank->index] = (UINT8 *)base;
@ -1726,7 +1726,7 @@ static void memory_init_spaces(running_machine *machine)
for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++) for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
if (device_get_addrbus_width(device, spacenum) > 0) if (device_get_addrbus_width(device, spacenum) > 0)
{ {
address_space *space = alloc_clear_or_die(address_space); address_space *space = auto_alloc_clear(machine, address_space);
int logbits = cpu_get_logaddr_width(device, spacenum); int logbits = cpu_get_logaddr_width(device, spacenum);
int ashift = device_get_addrbus_shift(device, spacenum); int ashift = device_get_addrbus_shift(device, spacenum);
int abits = device_get_addrbus_width(device, spacenum); int abits = device_get_addrbus_width(device, spacenum);
@ -1785,9 +1785,11 @@ static void memory_init_spaces(running_machine *machine)
space->read.handlers[STATIC_WATCHPOINT]->bytemask = ~0; space->read.handlers[STATIC_WATCHPOINT]->bytemask = ~0;
space->write.handlers[STATIC_WATCHPOINT]->bytemask = ~0; space->write.handlers[STATIC_WATCHPOINT]->bytemask = ~0;
/* allocate memory; these aren't auto-malloc'ed as we need to expand them */ /* allocate memory */
space->read.table = alloc_array_or_die(UINT8, 1 << LEVEL1_BITS); space->read.machine = machine;
space->write.table = alloc_array_or_die(UINT8, 1 << LEVEL1_BITS); space->read.table = auto_alloc_array(machine, UINT8, 1 << LEVEL1_BITS);
space->write.machine = machine;
space->write.table = auto_alloc_array(machine, UINT8, 1 << LEVEL1_BITS);
/* initialize everything to unmapped */ /* initialize everything to unmapped */
memset(space->read.table, STATIC_UNMAP, 1 << LEVEL1_BITS); memset(space->read.table, STATIC_UNMAP, 1 << LEVEL1_BITS);
@ -2197,66 +2199,14 @@ static void memory_init_locate(running_machine *machine)
static void memory_exit(running_machine *machine) static void memory_exit(running_machine *machine)
{ {
memory_private *memdata = machine->memory_data; memory_private *memdata = machine->memory_data;
address_space *space, *nextspace; address_space *space;
/* free the memory blocks */
while (memdata->memory_block_list != NULL)
{
memory_block *block = memdata->memory_block_list;
memdata->memory_block_list = block->next;
free(block);
}
/* free banks */
while (memdata->banklist != NULL)
{
bank_info *bank = memdata->banklist;
/* free references within each bank */
while (bank->reflist != NULL)
{
bank_reference *ref = bank->reflist;
bank->reflist = ref->next;
free(ref);
}
memdata->banklist = bank->next;
free(bank);
}
/* free all the address spaces and tables */ /* free all the address spaces and tables */
for (space = (address_space *)memdata->spacelist; space != NULL; space = nextspace) for (space = (address_space *)memdata->spacelist; space != NULL; space = space->next)
{ {
int entry;
nextspace = (address_space *)space->next;
/* free all direct ranges */
for (entry = 0; entry < ARRAY_LENGTH(space->direct.rangelist); entry++)
while (space->direct.rangelist[entry] != NULL)
{
direct_range *range = space->direct.rangelist[entry];
space->direct.rangelist[entry] = range->next;
free(range);
}
/* free the free list of direct ranges */
while (space->direct.freerangelist != NULL)
{
direct_range *range = space->direct.freerangelist;
space->direct.freerangelist = range->next;
free(range);
}
/* free the address map and tables */ /* free the address map and tables */
if (space->map != NULL) if (space->map != NULL)
address_map_free(space->map); address_map_free(space->map);
if (space->read.table != NULL)
free(space->read.table);
if (space->write.table != NULL)
free(space->write.table);
free(space);
} }
/* free the maps */ /* free the maps */
@ -2356,7 +2306,7 @@ static void map_detokenize(memory_private *memdata, address_map *map, const game
/* start a new range */ /* start a new range */
case ADDRMAP_TOKEN_RANGE: case ADDRMAP_TOKEN_RANGE:
entry = *entryptr = alloc_clear_or_die(address_map_entry); entry = *entryptr = global_alloc_clear(address_map_entry);
entryptr = &entry->next; entryptr = &entry->next;
TOKEN_GET_UINT64_UNPACK2(tokens, entry->addrstart, 32, entry->addrend, 32); TOKEN_GET_UINT64_UNPACK2(tokens, entry->addrstart, 32, entry->addrend, 32);
break; break;
@ -2705,7 +2655,7 @@ static genf *bank_find_or_allocate(const address_space *space, const char *tag,
sprintf(name, "Bank '%s'", tag); sprintf(name, "Bank '%s'", tag);
/* allocate the bank */ /* allocate the bank */
bank = (bank_info *)alloc_array_clear_or_die(UINT8, sizeof(bank_info) + strlen(tag) + 1 + strlen(name)); bank = (bank_info *)auto_alloc_array_clear(space->machine, UINT8, sizeof(bank_info) + strlen(tag) + 1 + strlen(name));
/* populate it */ /* populate it */
bank->index = banknum; bank->index = banknum;
@ -3138,10 +3088,14 @@ static UINT8 subtable_alloc(address_table *tabledata)
/* if this is past our allocation budget, allocate some more */ /* if this is past our allocation budget, allocate some more */
if (subindex >= tabledata->subtable_alloc) if (subindex >= tabledata->subtable_alloc)
{ {
UINT32 oldsize = (1 << LEVEL1_BITS) + (tabledata->subtable_alloc << LEVEL2_BITS);
tabledata->subtable_alloc += SUBTABLE_ALLOC; tabledata->subtable_alloc += SUBTABLE_ALLOC;
tabledata->table = (UINT8 *)realloc(tabledata->table, (1 << LEVEL1_BITS) + (tabledata->subtable_alloc << LEVEL2_BITS)); UINT32 newsize = (1 << LEVEL1_BITS) + (tabledata->subtable_alloc << LEVEL2_BITS);
if (!tabledata->table)
fatalerror("error: ran out of memory allocating memory subtable"); UINT8 *newtable = auto_alloc_array(tabledata->machine, UINT8, newsize);
memcpy(newtable, tabledata->table, oldsize);
auto_free(tabledata->machine, tabledata->table);
tabledata->table = newtable;
} }
/* bump the usecount and return */ /* bump the usecount and return */
@ -3352,7 +3306,7 @@ static direct_range *direct_range_find(address_space *space, offs_t byteaddress,
if (range != NULL) if (range != NULL)
space->direct.freerangelist = range->next; space->direct.freerangelist = range->next;
else else
range = alloc_or_die(direct_range); range = auto_alloc(space->machine, direct_range);
/* fill in the range */ /* fill in the range */
table_derive_range(&space->read, byteaddress, &range->bytestart, &range->byteend); table_derive_range(&space->read, byteaddress, &range->bytestart, &range->byteend);
@ -3424,7 +3378,7 @@ static void *block_allocate(const address_space *space, offs_t bytestart, offs_t
bytestoalloc += byteend - bytestart + 1; bytestoalloc += byteend - bytestart + 1;
/* allocate and clear the memory */ /* allocate and clear the memory */
block = (memory_block *)alloc_array_clear_or_die(UINT8, bytestoalloc); block = (memory_block *)auto_alloc_array_clear(space->machine, UINT8, bytestoalloc);
if (allocatemem) if (allocatemem)
memory = block + 1; memory = block + 1;

View File

@ -14,7 +14,7 @@
#ifndef __MEMORY_H__ #ifndef __MEMORY_H__
#define __MEMORY_H__ #define __MEMORY_H__
#include "mamecore.h" #include "emucore.h"
#include "tokenize.h" #include "tokenize.h"
#include "astring.h" #include "astring.h"
@ -270,6 +270,7 @@ struct _address_table
UINT8 subtable_alloc; /* number of subtables allocated */ UINT8 subtable_alloc; /* number of subtables allocated */
subtable_data * subtable; /* info about each subtable */ subtable_data * subtable; /* info about each subtable */
handler_data * handlers[256]; /* array of user-installed handlers */ handler_data * handlers[256]; /* array of user-installed handlers */
running_machine * machine; /* pointer back to the machine */
}; };

View File

@ -78,7 +78,7 @@ static void output_exit(running_machine *machine);
INLINE const char *copy_string(const char *string) INLINE const char *copy_string(const char *string)
{ {
char *newstring = alloc_array_or_die(char, strlen(string) + 1); char *newstring = global_alloc_array(char, strlen(string) + 1);
strcpy(newstring, string); strcpy(newstring, string);
return newstring; return newstring;
} }
@ -118,7 +118,7 @@ INLINE output_item *find_item(const char *string)
INLINE output_item *create_new_item(const char *outname, INT32 value) INLINE output_item *create_new_item(const char *outname, INT32 value)
{ {
output_item *item = alloc_or_die(output_item); output_item *item = global_alloc(output_item);
UINT32 hash = get_hash(outname); UINT32 hash = get_hash(outname);
/* fill in the data */ /* fill in the data */
@ -188,14 +188,14 @@ static void output_exit(running_machine *machine)
for (notify = item->notifylist; notify != NULL; ) for (notify = item->notifylist; notify != NULL; )
{ {
output_notify *next = notify->next; output_notify *next = notify->next;
free(notify); global_free(notify);
notify = next; notify = next;
} }
/* free the name and the item */ /* free the name and the item */
if (item->name != NULL) if (item->name != NULL)
free((void *)item->name); global_free(item->name);
free(item); global_free(item);
item = next; item = next;
} }
@ -203,7 +203,7 @@ static void output_exit(running_machine *machine)
for (notify = global_notifylist; notify != NULL; ) for (notify = global_notifylist; notify != NULL; )
{ {
output_notify *next = notify->next; output_notify *next = notify->next;
free(notify); global_free(notify);
notify = next; notify = next;
} }
} }
@ -343,7 +343,7 @@ void output_set_notifier(const char *outname, output_notifier_func callback, voi
/* find the end of the list and add to it */ /* find the end of the list and add to it */
while (*headptr != NULL) while (*headptr != NULL)
headptr = &(*headptr)->next; headptr = &(*headptr)->next;
*headptr = alloc_or_die(output_notify); *headptr = global_alloc(output_notify);
/* fill in the new record */ /* fill in the new record */
(*headptr)->next = NULL; (*headptr)->next = NULL;

View File

@ -14,7 +14,7 @@
#ifndef __OUTPUT_H__ #ifndef __OUTPUT_H__
#define __OUTPUT_H__ #define __OUTPUT_H__
#include "mamecore.h" #include "emucore.h"
/*************************************************************************** /***************************************************************************

View File

@ -343,7 +343,7 @@ INLINE container_item *alloc_container_item(void)
if (result != NULL) if (result != NULL)
container_item_free_list = result->next; container_item_free_list = result->next;
else else
result = alloc_or_die(container_item); result = global_alloc(container_item);
memset(result, 0, sizeof(*result)); memset(result, 0, sizeof(*result));
return result; return result;
@ -375,7 +375,7 @@ INLINE render_primitive *alloc_render_primitive(int type)
if (result != NULL) if (result != NULL)
render_primitive_free_list = result->next; render_primitive_free_list = result->next;
else else
result = alloc_or_die(render_primitive); result = global_alloc(render_primitive);
/* clear to 0 */ /* clear to 0 */
memset(result, 0, sizeof(*result)); memset(result, 0, sizeof(*result));
@ -426,7 +426,7 @@ INLINE void add_render_ref(render_ref **list, void *refptr)
if (ref != NULL) if (ref != NULL)
render_ref_free_list = ref->next; render_ref_free_list = ref->next;
else else
ref = alloc_or_die(render_ref); ref = global_alloc(render_ref);
/* set the refptr and link us into the list */ /* set the refptr and link us into the list */
ref->refptr = refptr; ref->refptr = refptr;
@ -620,7 +620,7 @@ static void render_exit(running_machine *machine)
{ {
render_texture *temp = render_texture_free_list; render_texture *temp = render_texture_free_list;
render_texture_free_list = temp->next; render_texture_free_list = temp->next;
free(temp); global_free(temp);
} }
/* free the render primitives */ /* free the render primitives */
@ -628,7 +628,7 @@ static void render_exit(running_machine *machine)
{ {
render_primitive *temp = render_primitive_free_list; render_primitive *temp = render_primitive_free_list;
render_primitive_free_list = temp->next; render_primitive_free_list = temp->next;
free(temp); global_free(temp);
} }
/* free the render refs */ /* free the render refs */
@ -636,7 +636,7 @@ static void render_exit(running_machine *machine)
{ {
render_ref *temp = render_ref_free_list; render_ref *temp = render_ref_free_list;
render_ref_free_list = temp->next; render_ref_free_list = temp->next;
free(temp); global_free(temp);
} }
/* free the container items */ /* free the container items */
@ -644,7 +644,7 @@ static void render_exit(running_machine *machine)
{ {
container_item *temp = container_item_free_list; container_item *temp = container_item_free_list;
container_item_free_list = temp->next; container_item_free_list = temp->next;
free(temp); global_free(temp);
} }
/* free the targets */ /* free the targets */
@ -1072,7 +1072,7 @@ render_target *render_target_alloc(running_machine *machine, const char *layoutf
int listnum; int listnum;
/* allocate memory for the target */ /* allocate memory for the target */
target = alloc_clear_or_die(render_target); target = global_alloc_clear(render_target);
/* add it to the end of the list */ /* add it to the end of the list */
for (nextptr = &targetlist; *nextptr != NULL; nextptr = &(*nextptr)->next) ; for (nextptr = &targetlist; *nextptr != NULL; nextptr = &(*nextptr)->next) ;
@ -1168,7 +1168,7 @@ void render_target_free(render_target *target)
} }
/* free the target itself */ /* free the target itself */
free(target); global_free(target);
} }
@ -2431,7 +2431,7 @@ render_texture *render_texture_alloc(texture_scaler_func scaler, void *param)
int texnum; int texnum;
/* allocate a new group */ /* allocate a new group */
texture = alloc_array_clear_or_die(render_texture, TEXTURE_GROUP_SIZE); texture = global_alloc_array_clear(render_texture, TEXTURE_GROUP_SIZE);
/* add them to the list */ /* add them to the list */
for (texnum = 0; texnum < TEXTURE_GROUP_SIZE; texnum++) for (texnum = 0; texnum < TEXTURE_GROUP_SIZE; texnum++)
@ -2482,7 +2482,7 @@ void render_texture_free(render_texture *texture)
/* free any B/C/G lookup tables */ /* free any B/C/G lookup tables */
if (texture->bcglookup != NULL) if (texture->bcglookup != NULL)
free(texture->bcglookup); global_free(texture->bcglookup);
/* add ourself back to the free list */ /* add ourself back to the free list */
base_save = texture->base; base_save = texture->base;
@ -2669,7 +2669,10 @@ static const rgb_t *texture_get_adjusted_palette(render_texture *texture, render
numentries = palette_get_num_colors(texture->palette) * palette_get_num_groups(texture->palette); numentries = palette_get_num_colors(texture->palette) * palette_get_num_groups(texture->palette);
if (texture->bcglookup == NULL || texture->bcglookup_entries < numentries) if (texture->bcglookup == NULL || texture->bcglookup_entries < numentries)
{ {
texture->bcglookup = (rgb_t *)realloc(texture->bcglookup, numentries * sizeof(*texture->bcglookup)); rgb_t *newlookup = global_alloc_array(rgb_t, numentries);
memcpy(newlookup, texture->bcglookup, texture->bcglookup_entries * sizeof(rgb_t));
delete[] texture->bcglookup;
texture->bcglookup = newlookup;
texture->bcglookup_entries = numentries; texture->bcglookup_entries = numentries;
} }
for (index = 0; index < numentries; index++) for (index = 0; index < numentries; index++)
@ -2696,7 +2699,10 @@ static const rgb_t *texture_get_adjusted_palette(render_texture *texture, render
adjusted = palette_entry_list_adjusted(texture->palette); adjusted = palette_entry_list_adjusted(texture->palette);
if (texture->bcglookup == NULL || texture->bcglookup_entries < 4 * 32) if (texture->bcglookup == NULL || texture->bcglookup_entries < 4 * 32)
{ {
texture->bcglookup = (rgb_t *)realloc(texture->bcglookup, 4 * 32 * sizeof(*texture->bcglookup)); rgb_t *newlookup = global_alloc_array(rgb_t, 4 * 32);
memcpy(newlookup, texture->bcglookup, texture->bcglookup_entries * sizeof(rgb_t));
delete[] texture->bcglookup;
texture->bcglookup = newlookup;
texture->bcglookup_entries = 4 * 32; texture->bcglookup_entries = 4 * 32;
} }
@ -2728,7 +2734,10 @@ static const rgb_t *texture_get_adjusted_palette(render_texture *texture, render
adjusted = palette_entry_list_adjusted(texture->palette); adjusted = palette_entry_list_adjusted(texture->palette);
if (texture->bcglookup == NULL || texture->bcglookup_entries < 4 * 256) if (texture->bcglookup == NULL || texture->bcglookup_entries < 4 * 256)
{ {
texture->bcglookup = (rgb_t *)realloc(texture->bcglookup, 4 * 256 * sizeof(*texture->bcglookup)); rgb_t *newlookup = global_alloc_array(rgb_t, 4 * 256);
memcpy(newlookup, texture->bcglookup, texture->bcglookup_entries * sizeof(rgb_t));
delete[] texture->bcglookup;
texture->bcglookup = newlookup;
texture->bcglookup_entries = 4 * 256; texture->bcglookup_entries = 4 * 256;
} }
@ -2767,7 +2776,7 @@ static render_container *render_container_alloc(running_machine *machine)
int color; int color;
/* allocate and clear memory */ /* allocate and clear memory */
container = alloc_clear_or_die(render_container); container = global_alloc_clear(render_container);
/* default values */ /* default values */
container->brightness = 1.0f; container->brightness = 1.0f;
@ -2810,7 +2819,7 @@ static void render_container_free(render_container *container)
palette_client_free(container->palclient); palette_client_free(container->palclient);
/* free the container itself */ /* free the container itself */
free(container); global_free(container);
} }

View File

@ -55,7 +55,7 @@
#ifndef FIRST_TIME #ifndef FIRST_TIME
#define FIRST_TIME #define FIRST_TIME
#include "mamecore.h" #include "emucore.h"
#include "eminline.h" #include "eminline.h"
#include "video/rgbutil.h" #include "video/rgbutil.h"
#include "render.h" #include "render.h"

View File

@ -141,7 +141,7 @@ render_font *render_font_alloc(const char *filename)
render_font *font; render_font *font;
/* allocate and clear memory */ /* allocate and clear memory */
font = alloc_clear_or_die(render_font); font = global_alloc_clear(render_font);
/* attempt to load the cached version of the font first */ /* attempt to load the cached version of the font first */
if (filename != NULL && render_font_load_cached_bdf(font, filename) == 0) if (filename != NULL && render_font_load_cached_bdf(font, filename) == 0)
@ -149,7 +149,7 @@ render_font *render_font_alloc(const char *filename)
/* if we failed, clean up and realloc */ /* if we failed, clean up and realloc */
render_font_free(font); render_font_free(font);
font = alloc_clear_or_die(render_font); font = global_alloc_clear(render_font);
/* load the raw data instead */ /* load the raw data instead */
filerr = mame_fopen_ram(font_uismall, sizeof(font_uismall), OPEN_FLAG_READ, &ramfile); filerr = mame_fopen_ram(font_uismall, sizeof(font_uismall), OPEN_FLAG_READ, &ramfile);
@ -188,13 +188,13 @@ void render_font_free(render_font *font)
} }
/* free the subtable itself */ /* free the subtable itself */
free(font->chars[tablenum]); global_free(font->chars[tablenum]);
} }
/* free the raw data and the size itself */ /* free the raw data and the size itself */
if (font->rawdata != NULL) if (font->rawdata != NULL)
free((void *)font->rawdata); global_free((void *)font->rawdata);
free(font); global_free(font);
} }
@ -432,7 +432,7 @@ static int render_font_load_cached_bdf(render_font *font, const char *filename)
/* determine the file size and allocate memory */ /* determine the file size and allocate memory */
font->rawsize = mame_fsize(file); font->rawsize = mame_fsize(file);
data = alloc_array_clear_or_die(char, font->rawsize + 1); data = global_alloc_array_clear(char, font->rawsize + 1);
/* read and hash the first chunk */ /* read and hash the first chunk */
bytes = mame_fread(file, data, MIN(CACHED_BDF_HASH_SIZE, font->rawsize)); bytes = mame_fread(file, data, MIN(CACHED_BDF_HASH_SIZE, font->rawsize));
@ -477,19 +477,19 @@ static int render_font_load_cached_bdf(render_font *font, const char *filename)
render_font_save_cached(font, cachedname, hash); render_font_save_cached(font, cachedname, hash);
} }
else else
free(data); global_free(data);
/* close the file */ /* close the file */
free(cachedname); global_free(cachedname);
mame_fclose(file); mame_fclose(file);
return result; return result;
error: error:
/* close the file */ /* close the file */
if (cachedname != NULL) if (cachedname != NULL)
free(cachedname); global_free(cachedname);
if (data != NULL) if (data != NULL)
free(data); global_free(data);
mame_fclose(file); mame_fclose(file);
return 1; return 1;
} }
@ -581,7 +581,7 @@ static int render_font_load_bdf(render_font *font)
/* if we don't have a subtable yet, make one */ /* if we don't have a subtable yet, make one */
if (font->chars[charnum / 256] == NULL) if (font->chars[charnum / 256] == NULL)
font->chars[charnum / 256] = alloc_array_clear_or_die(render_font_char, 256); font->chars[charnum / 256] = global_alloc_array_clear(render_font_char, 256);
/* fill in the entry */ /* fill in the entry */
ch = &font->chars[charnum / 256][charnum % 256]; ch = &font->chars[charnum / 256][charnum % 256];
@ -637,7 +637,7 @@ static int render_font_load_cached(render_font *font, mame_file *file, UINT32 ha
goto error; goto error;
/* now read the rest of the data */ /* now read the rest of the data */
data = alloc_array_or_die(UINT8, filesize - CACHED_HEADER_SIZE); data = global_alloc_array(UINT8, filesize - CACHED_HEADER_SIZE);
bytes_read = mame_fread(file, data, filesize - CACHED_HEADER_SIZE); bytes_read = mame_fread(file, data, filesize - CACHED_HEADER_SIZE);
if (bytes_read != filesize - CACHED_HEADER_SIZE) if (bytes_read != filesize - CACHED_HEADER_SIZE)
goto error; goto error;
@ -652,7 +652,7 @@ static int render_font_load_cached(render_font *font, mame_file *file, UINT32 ha
/* if we don't have a subtable yet, make one */ /* if we don't have a subtable yet, make one */
if (font->chars[chnum / 256] == NULL) if (font->chars[chnum / 256] == NULL)
font->chars[chnum / 256] = alloc_array_clear_or_die(render_font_char, 256); font->chars[chnum / 256] = global_alloc_array_clear(render_font_char, 256);
/* fill in the entry */ /* fill in the entry */
ch = &font->chars[chnum / 256][chnum % 256]; ch = &font->chars[chnum / 256][chnum % 256];
@ -676,7 +676,7 @@ static int render_font_load_cached(render_font *font, mame_file *file, UINT32 ha
error: error:
if (data != NULL) if (data != NULL)
free(data); global_free(data);
return 1; return 1;
} }
@ -720,10 +720,10 @@ static int render_font_save_cached(render_font *font, const char *filename, UINT
} }
/* allocate an array to hold the character data */ /* allocate an array to hold the character data */
chartable = alloc_array_clear_or_die(UINT8, numchars * CACHED_CHAR_SIZE); chartable = global_alloc_array_clear(UINT8, numchars * CACHED_CHAR_SIZE);
/* allocate a temp buffer to compress into */ /* allocate a temp buffer to compress into */
tempbuffer = alloc_array_or_die(UINT8, 65536); tempbuffer = global_alloc_array(UINT8, 65536);
/* write the header */ /* write the header */
dest = tempbuffer; dest = tempbuffer;
@ -831,14 +831,14 @@ static int render_font_save_cached(render_font *font, const char *filename, UINT
/* all done */ /* all done */
mame_fclose(file); mame_fclose(file);
free(tempbuffer); global_free(tempbuffer);
free(chartable); global_free(chartable);
return 0; return 0;
error: error:
mame_fclose(file); mame_fclose(file);
osd_rmfile(filename); osd_rmfile(filename);
free(tempbuffer); global_free(tempbuffer);
free(chartable); global_free(chartable);
return 1; return 1;
} }

View File

@ -217,7 +217,7 @@ INLINE void reduce_fraction(int *num, int *den)
INLINE const char *copy_string(const char *string) INLINE const char *copy_string(const char *string)
{ {
char *newstring = alloc_array_or_die(char, strlen(string) + 1); char *newstring = global_alloc_array(char, strlen(string) + 1);
strcpy(newstring, string); strcpy(newstring, string);
return newstring; return newstring;
} }
@ -1509,7 +1509,7 @@ layout_file *layout_file_load(const machine_config *config, const char *dirname,
return NULL; return NULL;
/* allocate the layout group object first */ /* allocate the layout group object first */
file = alloc_clear_or_die(layout_file); file = global_alloc_clear(layout_file);
/* find the layout node */ /* find the layout node */
mamelayoutnode = xml_get_sibling(rootnode->child, "mamelayout"); mamelayoutnode = xml_get_sibling(rootnode->child, "mamelayout");
@ -1578,7 +1578,7 @@ static layout_element *load_layout_element(const machine_config *config, xml_dat
int first; int first;
/* allocate a new element */ /* allocate a new element */
element = alloc_clear_or_die(layout_element); element = global_alloc_clear(layout_element);
/* extract the name */ /* extract the name */
name = xml_get_attribute_string_with_subst(config, elemnode, "name", NULL); name = xml_get_attribute_string_with_subst(config, elemnode, "name", NULL);
@ -1640,7 +1640,7 @@ static layout_element *load_layout_element(const machine_config *config, xml_dat
} }
/* allocate an array of element textures for the states */ /* allocate an array of element textures for the states */
element->elemtex = alloc_array_or_die(element_texture, element->maxstate + 1); element->elemtex = global_alloc_array(element_texture, element->maxstate + 1);
for (state = 0; state <= element->maxstate; state++) for (state = 0; state <= element->maxstate; state++)
{ {
element->elemtex[state].element = element; element->elemtex[state].element = element;
@ -1666,7 +1666,7 @@ static element_component *load_element_component(const machine_config *config, x
element_component *component; element_component *component;
/* allocate memory for the component */ /* allocate memory for the component */
component = alloc_clear_or_die(element_component); component = global_alloc_clear(element_component);
/* fetch common data */ /* fetch common data */
component->state = xml_get_attribute_int_with_subst(config, compnode, "state", -1); component->state = xml_get_attribute_int_with_subst(config, compnode, "state", -1);
@ -1696,7 +1696,7 @@ static element_component *load_element_component(const machine_config *config, x
/* allocate a copy of the string */ /* allocate a copy of the string */
component->type = COMPONENT_TYPE_TEXT; component->type = COMPONENT_TYPE_TEXT;
string = alloc_array_or_die(char, strlen(text) + 1); string = global_alloc_array(char, strlen(text) + 1);
strcpy(string, text); strcpy(string, text);
component->string = string; component->string = string;
} }
@ -1736,7 +1736,7 @@ static element_component *load_element_component(const machine_config *config, x
return component; return component;
error: error:
free(component); global_free(component);
return NULL; return NULL;
} }
@ -1753,7 +1753,7 @@ static layout_view *load_layout_view(const machine_config *config, xml_data_node
int layer; int layer;
/* first allocate memory */ /* first allocate memory */
view = alloc_clear_or_die(layout_view); view = global_alloc_clear(layout_view);
/* allocate a copy of the name */ /* allocate a copy of the name */
view->name = copy_string(xml_get_attribute_string_with_subst(config, viewnode, "name", "")); view->name = copy_string(xml_get_attribute_string_with_subst(config, viewnode, "name", ""));
@ -1806,7 +1806,7 @@ static view_item *load_view_item(const machine_config *config, xml_data_node *it
const char *name; const char *name;
/* allocate a new item */ /* allocate a new item */
item = alloc_clear_or_die(view_item); item = global_alloc_clear(view_item);
/* allocate a copy of the output name */ /* allocate a copy of the output name */
item->output_name = copy_string(xml_get_attribute_string_with_subst(config, itemnode, "name", "")); item->output_name = copy_string(xml_get_attribute_string_with_subst(config, itemnode, "name", ""));
@ -1859,10 +1859,10 @@ static view_item *load_view_item(const machine_config *config, xml_data_node *it
error: error:
if (item->output_name != NULL) if (item->output_name != NULL)
free((void *)item->output_name); global_free(item->output_name);
if (item->input_tag != NULL) if (item->input_tag != NULL)
free((void *)item->input_tag); global_free(item->input_tag);
free(item); global_free(item);
return NULL; return NULL;
} }
@ -2049,7 +2049,7 @@ void layout_file_free(layout_file *file)
} }
/* free the file itself */ /* free the file itself */
free(file); global_free(file);
} }
@ -2069,16 +2069,16 @@ static void layout_view_free(layout_view *view)
view_item *temp = view->itemlist[layer]; view_item *temp = view->itemlist[layer];
view->itemlist[layer] = temp->next; view->itemlist[layer] = temp->next;
if (temp->output_name != NULL) if (temp->output_name != NULL)
free((void *)temp->output_name); global_free(temp->output_name);
if (temp->input_tag != NULL) if (temp->input_tag != NULL)
free((void *)temp->input_tag); global_free(temp->input_tag);
free(temp); global_free(temp);
} }
/* free the view itself */ /* free the view itself */
if (view->name != NULL) if (view->name != NULL)
free((void *)view->name); global_free((void *)view->name);
free(view); global_free(view);
} }
@ -2095,16 +2095,16 @@ static void layout_element_free(layout_element *element)
element_component *temp = element->complist; element_component *temp = element->complist;
element->complist = temp->next; element->complist = temp->next;
if (temp->string != NULL) if (temp->string != NULL)
free((void *)temp->string); global_free(temp->string);
if (temp->dirname != NULL) if (temp->dirname != NULL)
free((void *)temp->dirname); global_free(temp->dirname);
if (temp->imagefile != NULL) if (temp->imagefile != NULL)
free((void *)temp->imagefile); global_free(temp->imagefile);
if (temp->alphafile != NULL) if (temp->alphafile != NULL)
free((void *)temp->alphafile); global_free(temp->alphafile);
if (temp->bitmap != NULL) if (temp->bitmap != NULL)
bitmap_free(temp->bitmap); bitmap_free(temp->bitmap);
free(temp); global_free(temp);
} }
/* free all textures */ /* free all textures */
@ -2117,11 +2117,11 @@ static void layout_element_free(layout_element *element)
if (element->elemtex[state].texture != NULL) if (element->elemtex[state].texture != NULL)
render_texture_free(element->elemtex[state].texture); render_texture_free(element->elemtex[state].texture);
free(element->elemtex); global_free(element->elemtex);
} }
/* free the element itself */ /* free the element itself */
if (element->name != NULL) if (element->name != NULL)
free((void *)element->name); global_free(element->name);
free(element); global_free(element);
} }

View File

@ -1,380 +0,0 @@
/***************************************************************************
restrack.c
Core MAME resource tracking.
Copyright Nicola Salmoria and the MAME Team.
Visit http://mamedev.org for licensing and usage restrictions.
***************************************************************************/
#include "restrack.h"
#include "pool.h"
#include "timer.h"
#include "state.h"
#include "mame.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
enum _memory_block_overlap
{
OVERLAP_NONE,
OVERLAP_PARTIAL,
OVERLAP_FULL
};
typedef enum _memory_block_overlap memory_block_overlap;
/***************************************************************************
GLOBAL VARIABLES
***************************************************************************/
/* pool list */
static object_pool *pools[64];
/* resource tracking */
int resource_tracking_tag = 0;
/***************************************************************************
PROTOTYPES
***************************************************************************/
static void astring_destructor(void *object, size_t size);
static void bitmap_destructor(void *object, size_t size);
static memory_block_overlap pool_contains_block(object_pool *pool, void *ptr, size_t size, void **found_block, size_t *found_block_size);
/***************************************************************************
CORE IMPLEMENTATION
***************************************************************************/
/*-------------------------------------------------
malloc_or_die_file_line - allocate memory or die
trying
-------------------------------------------------*/
void *malloc_or_die_file_line(size_t size, const char *file, int line)
{
void *result;
/* fail on attempted allocations of 0 */
if (size == 0)
fatalerror("Attempted to malloc zero bytes (%s:%d)", file, line);
/* allocate and return if we succeeded */
#ifdef MALLOC_DEBUG
result = malloc_file_line(size, file, line);
#else
result = malloc(size);
#endif
if (result != NULL)
{
#ifdef MAME_DEBUG
rand_memory(result, size);
#endif
return result;
}
/* otherwise, die horribly */
fatalerror("Failed to allocate %d bytes (%s:%d)", (int)size, file, line);
}
/*-------------------------------------------------
init_resource_tracking - initialize the
resource tracking system
-------------------------------------------------*/
void init_resource_tracking(void)
{
resource_tracking_tag = 0;
}
/*-------------------------------------------------
exit_resource_tracking - tear down the
resource tracking system
-------------------------------------------------*/
void exit_resource_tracking(void)
{
while (resource_tracking_tag != 0)
end_resource_tracking();
}
/*-------------------------------------------------
memory_error - report a memory error
-------------------------------------------------*/
static void memory_error(const char *message)
{
fatalerror("%s", message);
}
/*-------------------------------------------------
begin_resource_tracking - start tracking
resources
-------------------------------------------------*/
void begin_resource_tracking(void)
{
object_pool *new_pool;
/* sanity check */
assert_always(resource_tracking_tag < ARRAY_LENGTH(pools), "Too many memory pools");
/* create a new pool */
new_pool = pool_alloc(memory_error);
if (!new_pool)
fatalerror("Failed to allocate new memory pool");
pools[resource_tracking_tag] = new_pool;
/* add resource types */
pool_type_register(new_pool, OBJTYPE_ASTRING, "String", astring_destructor);
pool_type_register(new_pool, OBJTYPE_BITMAP, "Bitmap", bitmap_destructor);
pool_type_register(new_pool, OBJTYPE_TIMER, "Timer", timer_destructor);
/* increment the tag counter */
resource_tracking_tag++;
}
/*-------------------------------------------------
end_resource_tracking - stop tracking
resources
-------------------------------------------------*/
void end_resource_tracking(void)
{
/* decrement the tag counter */
resource_tracking_tag--;
/* free the memory pool */
pool_free(pools[resource_tracking_tag]);
pools[resource_tracking_tag] = NULL;
}
/*-------------------------------------------------
current_pool - identifies the current memory
pool
-------------------------------------------------*/
static object_pool *current_pool(void)
{
object_pool *pool;
assert_always((resource_tracking_tag > 0) && (resource_tracking_tag <= ARRAY_LENGTH(pools)), "Invalid resource_tracking_tag");
pool = pools[resource_tracking_tag - 1];
assert_always(pool != NULL, "current_pool() is NULL");
return pool;
}
/*-------------------------------------------------
restrack_register_object - registers an
object with the current pool
-------------------------------------------------*/
void *restrack_register_object(object_type type, void *ptr, size_t size, const char *file, int line)
{
if (resource_tracking_tag == 2) mame_printf_warning("restrack_register_object(%p,%ld) called within reset scope by %s, line %d\n", ptr, (long) size, file, line);
return pool_object_add_file_line(current_pool(), type, ptr, size, file, line);
}
/*-------------------------------------------------
auto_malloc_file_line - allocate auto-
freeing memory
-------------------------------------------------*/
void *auto_malloc_file_line(running_machine *machine, size_t size, const char *file, int line)
{
void *result = pool_malloc_file_line(current_pool(), size, file, line);
if (resource_tracking_tag == 2) mame_printf_warning("auto_malloc(%ld) called within reset scope by %s, line %d\n", (long) size, file, line);
#ifdef MAME_DEBUG
rand_memory(result, size);
#endif
return result;
}
/*-------------------------------------------------
auto_realloc_file_line - reallocate auto-
freeing memory
-------------------------------------------------*/
void *auto_realloc_file_line(running_machine *machine, void *ptr, size_t size, const char *file, int line)
{
object_pool *pool = current_pool();
if (ptr != NULL)
{
int tag = resource_tracking_tag;
for (; tag > 0; tag--)
{
pool = pools[tag - 1];
if (pool_object_exists(pool, OBJTYPE_MEMORY, ptr))
break;
}
assert_always(tag > 0, "Failed to find alloc in pool");
}
else if (resource_tracking_tag == 2) mame_printf_warning("auto_realloc(%p, %ld) called within reset scope by %s, line %d\n", ptr, (long) size, file, line);
return pool_realloc_file_line(pool, ptr, size, file, line);
}
/*-------------------------------------------------
auto_strdup_file_line - allocate auto-freeing
string
-------------------------------------------------*/
char *auto_strdup_file_line(running_machine *machine, const char *str, const char *file, int line)
{
if (resource_tracking_tag == 2) mame_printf_warning("auto_strdup() called within reset scope by %s, line %d\n", file, line);
return pool_strdup_file_line(current_pool(), str, file, line);
}
/*-------------------------------------------------
auto_strdup_allow_null_file_line - allocate
auto-freeing string if str is null
-------------------------------------------------*/
char *auto_strdup_allow_null_file_line(running_machine *machine, const char *str, const char *file, int line)
{
if (resource_tracking_tag == 2) mame_printf_warning("auto_strdup_allow_null() called within reset scope by %s, line %d\n", file, line);
return (str != NULL) ? auto_strdup_file_line(machine, str, file, line) : NULL;
}
/*-------------------------------------------------
auto_astring_alloc_file_line - allocate
auto-freeing astring
-------------------------------------------------*/
astring *auto_astring_alloc_file_line(running_machine *machine, const char *file, int line)
{
if (resource_tracking_tag == 2) mame_printf_warning("auto_astring_alloc() called within reset scope by %s, line %d\n", file, line);
return (astring *)restrack_register_object(OBJTYPE_ASTRING, astring_alloc(), 0, file, line);
}
/*-------------------------------------------------
auto_bitmap_alloc_file_line - allocate
auto-freeing bitmap
-------------------------------------------------*/
bitmap_t *auto_bitmap_alloc_file_line(running_machine *machine, int width, int height, bitmap_format format, const char *file, int line)
{
if (resource_tracking_tag == 2) mame_printf_warning("auto_bitmap_alloc(%d,%d) called within reset scope by %s, line %d\n", width, height, file, line);
return (bitmap_t *)restrack_register_object(OBJTYPE_BITMAP, bitmap_alloc(width, height, format), width * height, file, line);
}
/*-------------------------------------------------
validate_auto_malloc_memory - validate that a
block of memory has been allocated by
auto_malloc()
-------------------------------------------------*/
void validate_auto_malloc_memory(void *memory, size_t memory_size)
{
memory_block_overlap overlap = OVERLAP_NONE;
void *block_base = NULL;
size_t block_size = 0;
int i;
/* scan all pools for an overlapping block */
for (i = 0; overlap == OVERLAP_NONE && i < resource_tracking_tag; i++)
overlap = pool_contains_block(pools[i], memory, memory_size, &block_base, &block_size);
/* fatal error if not a full overlap */
switch (overlap)
{
case OVERLAP_NONE:
fatalerror("Memory block [0x%p-0x%p] not found", memory, (UINT8 *)memory + memory_size - 1);
break;
case OVERLAP_PARTIAL:
fatalerror("Memory block [0x%p-0x%p] partially overlaps with allocated block [0x%p-0x%p]", memory, (UINT8 *)memory + memory_size - 1, block_base, (UINT8 *)block_base + block_size - 1);
break;
case OVERLAP_FULL:
/* expected outcome */
break;
}
}
/*-------------------------------------------------
astring_destructor - destructor for astring
objects
-------------------------------------------------*/
static void astring_destructor(void *object, size_t size)
{
astring_free((astring *)object);
}
/*-------------------------------------------------
bitmap_destructor - destructor for bitmap
objects
-------------------------------------------------*/
static void bitmap_destructor(void *object, size_t size)
{
bitmap_free((bitmap_t *)object);
}
/*-------------------------------------------------
pool_contains_block - determines if a pool
contains a memory block
-------------------------------------------------*/
static memory_block_overlap pool_contains_block(object_pool *pool, void *ptr, size_t size, void **found_block, size_t *found_block_size)
{
memory_block_overlap overlap = OVERLAP_NONE;
object_pool_iterator *iter;
UINT8 *ptrstart = (UINT8 *)ptr;
UINT8 *ptrend = ptrstart + size - 1;
void *blockptr = NULL;
size_t blocksize = 0;
/* iterate over memory objects in the pool */
for (iter = pool_iterate_begin(pool, OBJTYPE_MEMORY); iter != NULL && pool_iterate_next(iter, &blockptr, &blocksize, NULL); )
{
int startwithin = (ptrstart >= (UINT8 *)blockptr && ptrstart < (UINT8 *)blockptr + blocksize);
int endwithin = (ptrend >= (UINT8 *)blockptr && ptrend < (UINT8 *)blockptr + blocksize);
/* if the start of the incoming pointer lies within the block... */
if (startwithin || endwithin)
{
overlap = (startwithin && endwithin) ? OVERLAP_FULL : OVERLAP_PARTIAL;
break;
}
}
pool_iterate_end(iter);
/* store the results */
if (overlap != OVERLAP_NONE)
{
if (found_block != NULL)
*found_block = blockptr;
if (found_block_size != NULL)
*found_block_size = blocksize;
}
return overlap;
}

View File

@ -1,96 +0,0 @@
/***************************************************************************
restrack.h
Core MAME resource tracking.
Copyright Nicola Salmoria and the MAME Team.
Visit http://mamedev.org for licensing and usage restrictions.
***************************************************************************/
#ifndef __RESTRACK_H__
#define __RESTRACK_H__
#include "mamecore.h"
#include "pool.h"
#include "astring.h"
/***************************************************************************
MACROS
***************************************************************************/
#define OBJTYPE_ASTRING OBJECT_TYPE('a','s','t','r')
#define OBJTYPE_BITMAP OBJECT_TYPE('b','i','t','m')
#define OBJTYPE_TIMER OBJECT_TYPE('t','i','m','r')
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
/* initialize the resource tracking system */
void init_resource_tracking(void);
/* tear down the resource tracking system */
void exit_resource_tracking(void);
/* begin tracking resources */
void begin_resource_tracking(void);
/* stop tracking resources and free everything since the last begin */
void end_resource_tracking(void);
/* register an object with the current pool */
void *restrack_register_object(object_type type, void *ptr, size_t size, const char *file, int line);
/* validate that a block of memory has been allocated by auto_malloc() */
void validate_auto_malloc_memory(void *memory, size_t memory_size);
/* return the current resource tag */
INLINE int get_resource_tag(void)
{
extern int resource_tracking_tag;
return resource_tracking_tag;
}
/* allocate memory and fatalerror if there's a problem */
#define alloc_or_die(t) ((t *)malloc_or_die_file_line(sizeof(t), __FILE__, __LINE__))
#define alloc_clear_or_die(t) ((t *)memset(malloc_or_die_file_line(sizeof(t), __FILE__, __LINE__), 0, sizeof(t)))
#define alloc_array_or_die(t, c) ((t *)malloc_or_die_file_line((c) * sizeof(t), __FILE__, __LINE__))
#define alloc_array_clear_or_die(t, c) ((t *)memset(malloc_or_die_file_line((c) * sizeof(t), __FILE__, __LINE__), 0, (c) * sizeof(t)))
void *malloc_or_die_file_line(size_t size, const char *file, int line) ATTR_MALLOC;
/* allocate memory that will be freed at the next end_resource_tracking */
#define auto_alloc(m, t) ((t *)auto_malloc_file_line(m, sizeof(t), __FILE__, __LINE__))
#define auto_alloc_clear(m, t) ((t *)memset(auto_malloc_file_line(m, sizeof(t), __FILE__, __LINE__), 0, sizeof(t)))
#define auto_alloc_array(m, t, c) ((t *)auto_malloc_file_line(m, (c) * sizeof(t), __FILE__, __LINE__))
#define auto_alloc_array_clear(m, t, c) ((t *)memset(auto_malloc_file_line(m, (c) * sizeof(t), __FILE__, __LINE__), 0, (c) * sizeof(t)))
void *auto_malloc_file_line(running_machine *machine, size_t size, const char *file, int line) ATTR_MALLOC;
/* allocate memory that will be freed at the next end_resource_tracking */
#define auto_extend_array(m, p, t, c) ((t *)auto_realloc_file_line(m, p, (c) * sizeof(t), __FILE__, __LINE__))
void *auto_realloc_file_line(running_machine *machine, void *ptr, size_t size, const char *file, int line) ATTR_MALLOC;
/* allocate memory and duplicate a string that will be freed at the next end_resource_tracking */
#define auto_strdup(m, s) auto_strdup_file_line(m, s, __FILE__, __LINE__)
char *auto_strdup_file_line(running_machine *machine, const char *str, const char *file, int line) ATTR_MALLOC;
/* auto_strdup() variant that tolerates NULL */
#define auto_strdup_allow_null(m, s) auto_strdup_allow_null_file_line(m, s, __FILE__, __LINE__)
char *auto_strdup_allow_null_file_line(running_machine *machine, const char *str, const char *file, int line) ATTR_MALLOC;
/* allocate a bitmap that will be freed at the next end_resource_tracking */
#define auto_astring_alloc(m) auto_astring_alloc_file_line(m, __FILE__, __LINE__)
astring *auto_astring_alloc_file_line(running_machine *machine, const char *file, int line);
/* allocate a bitmap that will be freed at the next end_resource_tracking */
#define auto_bitmap_alloc(m, w, h, f) auto_bitmap_alloc_file_line(m, w, h, f, __FILE__, __LINE__)
bitmap_t *auto_bitmap_alloc_file_line(running_machine *machine, int width, int height, bitmap_format format, const char *file, int line);
#endif /* __RESTRACK_H__ */

View File

@ -760,7 +760,7 @@ static int read_rom_data(rom_load_data *romdata, const rom_entry *romp)
/* use a temporary buffer for complex loads */ /* use a temporary buffer for complex loads */
tempbufsize = MIN(TEMPBUFFER_MAX_SIZE, numbytes); tempbufsize = MIN(TEMPBUFFER_MAX_SIZE, numbytes);
tempbuf = alloc_array_or_die(UINT8, tempbufsize); tempbuf = auto_alloc_array(romdata->machine, UINT8, tempbufsize);
/* chunky reads for complex loads */ /* chunky reads for complex loads */
skip += groupsize; skip += groupsize;
@ -774,7 +774,7 @@ static int read_rom_data(rom_load_data *romdata, const rom_entry *romp)
LOG((" Reading %X bytes into buffer\n", bytesleft)); LOG((" Reading %X bytes into buffer\n", bytesleft));
if (rom_fread(romdata, bufptr, bytesleft) != bytesleft) if (rom_fread(romdata, bufptr, bytesleft) != bytesleft)
{ {
free(tempbuf); auto_free(romdata->machine, tempbuf);
return 0; return 0;
} }
numbytes -= bytesleft; numbytes -= bytesleft;
@ -835,7 +835,7 @@ static int read_rom_data(rom_load_data *romdata, const rom_entry *romp)
} }
} }
} }
free(tempbuf); auto_free(romdata->machine, tempbuf);
LOG((" All done\n")); LOG((" All done\n"));
return ROM_GETLENGTH(romp); return ROM_GETLENGTH(romp);

View File

@ -14,7 +14,7 @@
#ifndef __ROMLOAD_H__ #ifndef __ROMLOAD_H__
#define __ROMLOAD_H__ #define __ROMLOAD_H__
#include "mamecore.h" #include "emucore.h"
#include "chd.h" #include "chd.h"
#include "options.h" #include "options.h"

View File

@ -346,7 +346,7 @@ static DEVICE_CUSTOM_CONFIG( sound )
/* allocate a new route */ /* allocate a new route */
for (routeptr = &config->routelist; *routeptr != NULL; routeptr = &(*routeptr)->next) ; for (routeptr = &config->routelist; *routeptr != NULL; routeptr = &(*routeptr)->next) ;
*routeptr = alloc_or_die(sound_route); *routeptr = global_alloc(sound_route);
(*routeptr)->next = NULL; (*routeptr)->next = NULL;
(*routeptr)->output = output; (*routeptr)->output = output;
(*routeptr)->input = input; (*routeptr)->input = input;
@ -361,7 +361,7 @@ static DEVICE_CUSTOM_CONFIG( sound )
{ {
sound_route *temp = config->routelist; sound_route *temp = config->routelist;
config->routelist = temp->next; config->routelist = temp->next;
free(temp); global_free(temp);
} }
break; break;
} }

View File

@ -348,7 +348,7 @@ INLINE void build_3D_table(double rl, const ay_ym_param *par, const ay_ym_param
double min = 10.0, max = 0.0; double min = 10.0, max = 0.0;
double *temp; double *temp;
temp = (double *)malloc(8*32*32*32*sizeof(*temp)); temp = global_alloc_array(double, 8*32*32*32);
for (e=0; e < 8; e++) for (e=0; e < 8; e++)
for (j1=0; j1 < 32; j1++) for (j1=0; j1 < 32; j1++)
@ -395,7 +395,7 @@ INLINE void build_3D_table(double rl, const ay_ym_param *par, const ay_ym_param
/* for (e=0;e<16;e++) printf("%d %d\n",e<<10, tab[e<<10]); */ /* for (e=0;e<16;e++) printf("%d %d\n",e<<10, tab[e<<10]); */
free(temp); global_free(temp);
} }
INLINE void build_single_table(double rl, const ay_ym_param *par, int normalize, INT32 *tab, int zero_is_off) INLINE void build_single_table(double rl, const ay_ym_param *par, int normalize, INT32 *tab, int zero_is_off)

View File

@ -2,12 +2,12 @@
#include "filter.h" #include "filter.h"
static filter* filter_alloc(void) { static filter* filter_alloc(void) {
filter* f = alloc_or_die(filter); filter* f = global_alloc(filter);
return f; return f;
} }
void filter_free(filter* f) { void filter_free(filter* f) {
free(f); global_free(f);
} }
void filter_state_reset(filter* f, filter_state* s) { void filter_state_reset(filter* f, filter_state* s) {
@ -20,7 +20,7 @@ void filter_state_reset(filter* f, filter_state* s) {
filter_state* filter_state_alloc(void) { filter_state* filter_state_alloc(void) {
int i; int i;
filter_state* s = alloc_or_die(filter_state); filter_state* s = global_alloc(filter_state);
s->prev_mac = 0; s->prev_mac = 0;
for(i=0;i<FILTER_ORDER_MAX;++i) for(i=0;i<FILTER_ORDER_MAX;++i)
s->xprev[i] = 0; s->xprev[i] = 0;
@ -28,7 +28,7 @@ filter_state* filter_state_alloc(void) {
} }
void filter_state_free(filter_state* s) { void filter_state_free(filter_state* s) {
free(s); global_free(s);
} }
/****************************************************************************/ /****************************************************************************/

View File

@ -2264,14 +2264,11 @@ void * ym2203_init(void *param, const device_config *device, int clock, int rate
YM2203 *F2203; YM2203 *F2203;
/* allocate ym2203 state space */ /* allocate ym2203 state space */
if( (F2203 = (YM2203 *)malloc(sizeof(YM2203)))==NULL) F2203 = auto_alloc_clear(device->machine, YM2203);
return NULL;
/* clear */
memset(F2203,0,sizeof(YM2203));
if( !init_tables() ) if( !init_tables() )
{ {
free( F2203 ); auto_free( device->machine, F2203 );
return NULL; return NULL;
} }
@ -2298,7 +2295,7 @@ void ym2203_shutdown(void *chip)
YM2203 *FM2203 = (YM2203 *)chip; YM2203 *FM2203 = (YM2203 *)chip;
FMCloseTable(); FMCloseTable();
free(FM2203); auto_free(FM2203->OPN.ST.device->machine, FM2203);
} }
/* YM2203 I/O interface */ /* YM2203 I/O interface */
@ -3487,14 +3484,11 @@ void * ym2608_init(void *param, const device_config *device, int clock, int rate
YM2608 *F2608; YM2608 *F2608;
/* allocate extend state space */ /* allocate extend state space */
if( (F2608 = (YM2608 *)malloc(sizeof(YM2608)))==NULL) F2608 = auto_alloc_clear(device->machine, YM2608);
return NULL;
/* clear */
memset(F2608,0,sizeof(YM2608));
/* allocate total level table (128kb space) */ /* allocate total level table (128kb space) */
if( !init_tables() ) if( !init_tables() )
{ {
free( F2608 ); auto_free( device->machine, F2608 );
return NULL; return NULL;
} }
@ -3542,7 +3536,7 @@ void ym2608_shutdown(void *chip)
YM2608 *F2608 = (YM2608 *)chip; YM2608 *F2608 = (YM2608 *)chip;
FMCloseTable(); FMCloseTable();
free(F2608); auto_free(F2608->OPN.ST.device->machine, F2608);
} }
/* reset one of chips */ /* reset one of chips */
@ -4172,14 +4166,11 @@ void *ym2610_init(void *param, const device_config *device, int clock, int rate,
YM2610 *F2610; YM2610 *F2610;
/* allocate extend state space */ /* allocate extend state space */
if( (F2610 = (YM2610 *)malloc(sizeof(YM2610)))==NULL) F2610 = auto_alloc_clear(device->machine, YM2610);
return NULL;
/* clear */
memset(F2610,0,sizeof(YM2610));
/* allocate total level table (128kb space) */ /* allocate total level table (128kb space) */
if( !init_tables() ) if( !init_tables() )
{ {
free( F2610 ); auto_free( device->machine, F2610 );
return NULL; return NULL;
} }
@ -4219,7 +4210,7 @@ void ym2610_shutdown(void *chip)
YM2610 *F2610 = (YM2610 *)chip; YM2610 *F2610 = (YM2610 *)chip;
FMCloseTable(); FMCloseTable();
free(F2610); auto_free(F2610->OPN.ST.device->machine, F2610);
} }
/* reset one of chip */ /* reset one of chip */

View File

@ -2451,14 +2451,11 @@ void * ym2612_init(void *param, const device_config *device, int clock, int rate
YM2612 *F2612; YM2612 *F2612;
/* allocate extend state space */ /* allocate extend state space */
if( (F2612 = (YM2612 *)malloc(sizeof(YM2612)))==NULL) F2612 = auto_alloc_clear(device->machine, YM2612);
return NULL;
/* clear */
memset(F2612,0,sizeof(YM2612));
/* allocate total level table (128kb space) */ /* allocate total level table (128kb space) */
if( !init_tables() ) if( !init_tables() )
{ {
free( F2612 ); auto_free( device->machine, F2612 );
return NULL; return NULL;
} }
@ -2486,7 +2483,7 @@ void ym2612_shutdown(void *chip)
YM2612 *F2612 = (YM2612 *)chip; YM2612 *F2612 = (YM2612 *)chip;
FMCloseTable(); FMCloseTable();
free(F2612); auto_free(F2612->OPN.ST.device->machine, F2612);
} }
/* reset one of chip */ /* reset one of chip */

View File

@ -313,6 +313,7 @@ typedef struct fm_opl_f {
UINT32 rate; /* sampling rate (Hz) */ UINT32 rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */ double freqbase; /* frequency base */
attotime TimerBase; /* Timer base time (==sampling time)*/ attotime TimerBase; /* Timer base time (==sampling time)*/
const device_config *device;
} FM_OPL; } FM_OPL;
@ -1978,13 +1979,7 @@ static FM_OPL *OPLCreate(const device_config *device, UINT32 clock, UINT32 rate,
#endif #endif
/* allocate memory block */ /* allocate memory block */
ptr = (char *)malloc(state_size); ptr = (char *)auto_alloc_array_clear(device->machine, UINT8, state_size);
if (ptr==NULL)
return NULL;
/* clear */
memset(ptr,0,state_size);
OPL = (FM_OPL *)ptr; OPL = (FM_OPL *)ptr;
@ -1998,6 +1993,7 @@ static FM_OPL *OPLCreate(const device_config *device, UINT32 clock, UINT32 rate,
ptr += sizeof(YM_DELTAT); ptr += sizeof(YM_DELTAT);
#endif #endif
OPL->device = device;
OPL->type = type; OPL->type = type;
OPL->clock = clock; OPL->clock = clock;
OPL->rate = rate; OPL->rate = rate;
@ -2012,7 +2008,7 @@ static FM_OPL *OPLCreate(const device_config *device, UINT32 clock, UINT32 rate,
static void OPLDestroy(FM_OPL *OPL) static void OPLDestroy(FM_OPL *OPL)
{ {
OPL_UnLockTable(); OPL_UnLockTable();
free(OPL); auto_free(OPL->device->machine, OPL);
} }
/* Optional handlers */ /* Optional handlers */

View File

@ -547,10 +547,7 @@ void *tia_sound_init(int clock, int sample_rate, int gain)
struct tia *chip; struct tia *chip;
int chan; int chan;
chip = (struct tia *)malloc(sizeof(*chip)); chip = global_alloc_clear(struct tia);
if (!chip)
return NULL;
memset(chip, 0, sizeof(*chip));
/* set the gain factor (normally use TIA_DEFAULT_GAIN) */ /* set the gain factor (normally use TIA_DEFAULT_GAIN) */
chip->tia_gain = gain; chip->tia_gain = gain;
@ -592,5 +589,5 @@ void *tia_sound_init(int clock, int sample_rate, int gain)
void tia_sound_free(void *chip) void tia_sound_free(void *chip)
{ {
free(chip); global_free(chip);
} }

View File

@ -1,4 +1,4 @@
#include "mamecore.h" #include "osdcore.h"
#include "sound/wavwrite.h" #include "sound/wavwrite.h"
struct _wav_file struct _wav_file

View File

@ -1506,9 +1506,7 @@ void * ym2151_init(const device_config *device, int clock, int rate)
{ {
YM2151 *PSG; YM2151 *PSG;
PSG = (YM2151 *)malloc(sizeof(YM2151)); PSG = auto_alloc(device->machine, YM2151);
if (PSG == NULL)
return NULL;
memset(PSG, 0, sizeof(YM2151)); memset(PSG, 0, sizeof(YM2151));
@ -1559,7 +1557,7 @@ void ym2151_shutdown(void *_chip)
{ {
YM2151 *chip = (YM2151 *)_chip; YM2151 *chip = (YM2151 *)_chip;
free (chip); auto_free (chip->device->machine, chip);
if (cymfile) if (cymfile)
fclose (cymfile); fclose (cymfile);

View File

@ -263,6 +263,7 @@ typedef struct {
int clock; /* master clock (Hz) */ int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */ int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */ double freqbase; /* frequency base */
const device_config *device;
} YM2413; } YM2413;
/* key scale level */ /* key scale level */
@ -2002,26 +2003,14 @@ static void OPLLResetChip(YM2413 *chip)
/* 'rate' is sampling rate */ /* 'rate' is sampling rate */
static YM2413 *OPLLCreate(const device_config *device, int clock, int rate) static YM2413 *OPLLCreate(const device_config *device, int clock, int rate)
{ {
char *ptr;
YM2413 *chip; YM2413 *chip;
int state_size;
if (OPLL_LockTable(device) == -1) return NULL; if (OPLL_LockTable(device) == -1) return NULL;
/* calculate chip state size */
state_size = sizeof(YM2413);
/* allocate memory block */ /* allocate memory block */
ptr = (char *)malloc(state_size); chip = auto_alloc_clear(device->machine, YM2413);
if (ptr==NULL)
return NULL;
/* clear */
memset(ptr,0,state_size);
chip = (YM2413 *)ptr;
chip->device = device;
chip->clock = clock; chip->clock = clock;
chip->rate = rate; chip->rate = rate;
@ -2037,7 +2026,7 @@ static YM2413 *OPLLCreate(const device_config *device, int clock, int rate)
static void OPLLDestroy(YM2413 *chip) static void OPLLDestroy(YM2413 *chip)
{ {
OPLL_UnLockTable(); OPLL_UnLockTable();
free(chip); auto_free(chip->device->machine, chip);
} }
/* Option handlers */ /* Option handlers */

View File

@ -268,6 +268,7 @@ typedef struct {
int rate; /* sampling rate (Hz) */ int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */ double freqbase; /* frequency base */
attotime TimerBase; /* Timer base time (==sampling time)*/ attotime TimerBase; /* Timer base time (==sampling time)*/
const device_config *device;
} OPL3; } OPL3;
@ -2337,14 +2338,9 @@ static OPL3 *OPL3Create(const device_config *device, int clock, int rate, int ty
if (OPL3_LockTable(device) == -1) return NULL; if (OPL3_LockTable(device) == -1) return NULL;
/* allocate memory block */ /* allocate memory block */
chip = (OPL3 *)malloc(sizeof(OPL3)); chip = auto_alloc_clear(device->machine, OPL3);
if (chip==NULL)
return NULL;
/* clear */
memset(chip, 0, sizeof(OPL3));
chip->device = device;
chip->type = type; chip->type = type;
chip->clock = clock; chip->clock = clock;
chip->rate = rate; chip->rate = rate;
@ -2361,7 +2357,7 @@ static OPL3 *OPL3Create(const device_config *device, int clock, int rate, int ty
static void OPL3Destroy(OPL3 *chip) static void OPL3Destroy(OPL3 *chip)
{ {
OPL3_UnLockTable(); OPL3_UnLockTable();
free(chip); auto_free(chip->device->machine, chip);
} }

View File

@ -14,7 +14,7 @@
#ifndef __STATE_H__ #ifndef __STATE_H__
#define __STATE_H__ #define __STATE_H__
#include "mamecore.h" #include "emucore.h"

View File

@ -723,15 +723,20 @@ static void allocate_resample_buffers(running_machine *machine, sound_stream *st
if (stream->resample_bufalloc < bufsize) if (stream->resample_bufalloc < bufsize)
{ {
int inputnum; int inputnum;
int oldsize;
/* this becomes the new allocation size */ /* this becomes the new allocation size */
oldsize = stream->resample_bufalloc;
stream->resample_bufalloc = bufsize; stream->resample_bufalloc = bufsize;
/* iterate over outputs and realloc their buffers */ /* iterate over outputs and realloc their buffers */
for (inputnum = 0; inputnum < stream->inputs; inputnum++) for (inputnum = 0; inputnum < stream->inputs; inputnum++)
{ {
stream_input *input = &stream->input[inputnum]; stream_input *input = &stream->input[inputnum];
input->resample = auto_extend_array(machine, input->resample, stream_sample_t, stream->resample_bufalloc); stream_sample_t *newbuffer = auto_alloc_array(machine, stream_sample_t, stream->resample_bufalloc);
memcpy(newbuffer, input->resample, oldsize * sizeof(stream_sample_t));
delete[] input->resample;
input->resample = newbuffer;
} }
} }
} }
@ -761,8 +766,10 @@ static void allocate_output_buffers(running_machine *machine, sound_stream *stre
for (outputnum = 0; outputnum < stream->outputs; outputnum++) for (outputnum = 0; outputnum < stream->outputs; outputnum++)
{ {
stream_output *output = &stream->output[outputnum]; stream_output *output = &stream->output[outputnum];
output->buffer = auto_extend_array(machine, output->buffer, stream_sample_t, stream->output_bufalloc); stream_sample_t *newbuffer = auto_alloc_array(machine, stream_sample_t, stream->output_bufalloc);
memset(&output->buffer[oldsize], 0, (stream->output_bufalloc - oldsize) * sizeof(output->buffer[0])); memcpy(newbuffer, output->buffer, oldsize * sizeof(stream_sample_t));
delete[] output->buffer;
output->buffer = newbuffer;
} }
} }
} }

View File

@ -12,7 +12,7 @@
#ifndef STREAMS_H #ifndef STREAMS_H
#define STREAMS_H #define STREAMS_H
#include "mamecore.h" #include "emucore.h"
/*************************************************************************** /***************************************************************************

View File

@ -349,7 +349,7 @@ static tilemap_t *tilemap_create_common(running_machine *machine, void *get_info
tilemap_instance = machine->tilemap_data->instance; tilemap_instance = machine->tilemap_data->instance;
/* allocate the tilemap itself */ /* allocate the tilemap itself */
tmap = alloc_clear_or_die(tilemap_t); tmap = auto_alloc_clear(machine, tilemap_t);
/* fill in the basic metrics */ /* fill in the basic metrics */
tmap->machine = machine; tmap->machine = machine;
@ -379,16 +379,16 @@ static tilemap_t *tilemap_create_common(running_machine *machine, void *get_info
/* initialize scroll information */ /* initialize scroll information */
tmap->scrollrows = 1; tmap->scrollrows = 1;
tmap->scrollcols = 1; tmap->scrollcols = 1;
tmap->rowscroll = alloc_array_clear_or_die(INT32, tmap->height); tmap->rowscroll = auto_alloc_array_clear(machine, INT32, tmap->height);
tmap->colscroll = alloc_array_clear_or_die(INT32, tmap->width); tmap->colscroll = auto_alloc_array_clear(machine, INT32, tmap->width);
/* allocate the pixel data cache */ /* allocate the pixel data cache */
tmap->pixmap = bitmap_alloc(tmap->width, tmap->height, BITMAP_FORMAT_INDEXED16); tmap->pixmap = auto_bitmap_alloc(machine, tmap->width, tmap->height, BITMAP_FORMAT_INDEXED16);
/* allocate transparency mapping data */ /* allocate transparency mapping data */
tmap->tileflags = alloc_array_or_die(UINT8, tmap->max_logical_index); tmap->tileflags = auto_alloc_array(machine, UINT8, tmap->max_logical_index);
tmap->flagsmap = bitmap_alloc(tmap->width, tmap->height, BITMAP_FORMAT_INDEXED8); tmap->flagsmap = auto_bitmap_alloc(machine, tmap->width, tmap->height, BITMAP_FORMAT_INDEXED8);
tmap->pen_to_flags = alloc_array_clear_or_die(UINT8, MAX_PEN_TO_FLAGS * TILEMAP_NUM_GROUPS); tmap->pen_to_flags = auto_alloc_array_clear(machine, UINT8, MAX_PEN_TO_FLAGS * TILEMAP_NUM_GROUPS);
for (group = 0; group < TILEMAP_NUM_GROUPS; group++) for (group = 0; group < TILEMAP_NUM_GROUPS; group++)
tilemap_map_pens_to_layer(tmap, group, 0, 0, TILEMAP_PIXEL_LAYER0); tilemap_map_pens_to_layer(tmap, group, 0, 0, TILEMAP_PIXEL_LAYER0);
@ -1155,15 +1155,15 @@ static void tilemap_dispose(tilemap_t *tmap)
} }
/* free allocated memory */ /* free allocated memory */
free(tmap->pen_to_flags); auto_free(tmap->machine, tmap->pen_to_flags);
free(tmap->tileflags); auto_free(tmap->machine, tmap->tileflags);
bitmap_free(tmap->flagsmap); auto_free(tmap->machine, tmap->flagsmap);
bitmap_free(tmap->pixmap); auto_free(tmap->machine, tmap->pixmap);
free(tmap->colscroll); auto_free(tmap->machine, tmap->colscroll);
free(tmap->rowscroll); auto_free(tmap->machine, tmap->rowscroll);
free(tmap->logical_to_memory); auto_free(tmap->machine, tmap->logical_to_memory);
free(tmap->memory_to_logical); auto_free(tmap->machine, tmap->memory_to_logical);
free(tmap); auto_free(tmap->machine, tmap);
} }
@ -1195,8 +1195,8 @@ static void mappings_create(tilemap_t *tmap)
tmap->max_memory_index++; tmap->max_memory_index++;
/* allocate the necessary mappings */ /* allocate the necessary mappings */
tmap->memory_to_logical = alloc_array_or_die(tilemap_logical_index, tmap->max_memory_index); tmap->memory_to_logical = auto_alloc_array(tmap->machine, tilemap_logical_index, tmap->max_memory_index);
tmap->logical_to_memory = alloc_array_or_die(tilemap_memory_index, tmap->max_logical_index); tmap->logical_to_memory = auto_alloc_array(tmap->machine, tilemap_memory_index, tmap->max_logical_index);
/* update the mappings */ /* update the mappings */
mappings_update(tmap); mappings_update(tmap);

View File

@ -297,7 +297,7 @@
#ifndef __TILEMAP_H__ #ifndef __TILEMAP_H__
#define __TILEMAP_H__ #define __TILEMAP_H__
#include "mamecore.h" #include "emucore.h"
#include "drawgfx.h" #include "drawgfx.h"

View File

@ -12,7 +12,6 @@
#include "driver.h" #include "driver.h"
#include "profiler.h" #include "profiler.h"
#include "pool.h"
#include "timer.h" #include "timer.h"
@ -648,7 +647,6 @@ INLINE emu_timer *_timer_alloc_common(running_machine *machine, timer_fired_func
if (!state_save_registration_allowed(machine)) if (!state_save_registration_allowed(machine))
fatalerror("timer_alloc() called after save state registration closed! (file %s, line %d)\n", file, line); fatalerror("timer_alloc() called after save state registration closed! (file %s, line %d)\n", file, line);
timer_register_save(timer); timer_register_save(timer);
restrack_register_object(OBJTYPE_TIMER, timer, 0, file, line);
} }
/* return a handle */ /* return a handle */

View File

@ -15,7 +15,7 @@
#ifndef __TIMER_H__ #ifndef __TIMER_H__
#define __TIMER_H__ #define __TIMER_H__
#include "mamecore.h" #include "emucore.h"
#include "devintrf.h" #include "devintrf.h"
#include "attotime.h" #include "attotime.h"

View File

@ -14,7 +14,7 @@
#ifndef __USRINTRF_H__ #ifndef __USRINTRF_H__
#define __USRINTRF_H__ #define __USRINTRF_H__
#include "mamecore.h" #include "emucore.h"
#include "render.h" #include "render.h"
#include "unicode.h" #include "unicode.h"

View File

@ -14,7 +14,7 @@
#ifndef __UIGFX_H__ #ifndef __UIGFX_H__
#define __UIGFX_H__ #define __UIGFX_H__
#include "mamecore.h" #include "emucore.h"
/*************************************************************************** /***************************************************************************

View File

@ -14,7 +14,7 @@
#ifndef __UIINPUT_H__ #ifndef __UIINPUT_H__
#define __UIINPUT_H__ #define __UIINPUT_H__
#include "mamecore.h" #include "emucore.h"
#include "render.h" #include "render.h"
#include "unicode.h" #include "unicode.h"

View File

@ -385,7 +385,7 @@ void ui_menu_init(running_machine *machine)
ui_menu_stack_reset(machine); ui_menu_stack_reset(machine);
/* create a texture for hilighting items */ /* create a texture for hilighting items */
hilight_bitmap = bitmap_alloc(256, 1, BITMAP_FORMAT_ARGB32); hilight_bitmap = auto_bitmap_alloc(machine, 256, 1, BITMAP_FORMAT_ARGB32);
for (x = 0; x < 256; x++) for (x = 0; x < 256; x++)
{ {
int alpha = 0xff; int alpha = 0xff;
@ -416,7 +416,6 @@ static void ui_menu_exit(running_machine *machine)
/* free textures */ /* free textures */
render_texture_free(hilight_texture); render_texture_free(hilight_texture);
bitmap_free(hilight_bitmap);
render_texture_free(arrow_texture); render_texture_free(arrow_texture);
} }
@ -435,7 +434,7 @@ ui_menu *ui_menu_alloc(running_machine *machine, ui_menu_handler_func handler, v
ui_menu *menu; ui_menu *menu;
/* allocate and clear memory for the menu and the state */ /* allocate and clear memory for the menu and the state */
menu = alloc_clear_or_die(ui_menu); menu = auto_alloc_clear(machine, ui_menu);
/* initialize the state */ /* initialize the state */
menu->machine = machine; menu->machine = machine;
@ -459,23 +458,23 @@ void ui_menu_free(ui_menu *menu)
{ {
ui_menu_pool *pool = menu->pool; ui_menu_pool *pool = menu->pool;
menu->pool = pool->next; menu->pool = pool->next;
free(pool); auto_free(menu->machine, pool);
} }
/* free the item array */ /* free the item array */
if (menu->item != NULL) if (menu->item != NULL)
free(menu->item); auto_free(menu->machine, menu->item);
/* free the state */ /* free the state */
if (menu->state != NULL) if (menu->state != NULL)
{ {
if (menu->destroy_state != NULL) if (menu->destroy_state != NULL)
(*menu->destroy_state)(menu, menu->state); (*menu->destroy_state)(menu, menu->state);
free(menu->state); auto_free(menu->machine, menu->state);
} }
/* free the menu */ /* free the menu */
free(menu); auto_free(menu->machine, menu);
} }
@ -545,8 +544,13 @@ void ui_menu_item_append(ui_menu *menu, const char *text, const char *subtext, U
/* realloc the item array if necessary */ /* realloc the item array if necessary */
if (menu->numitems >= menu->allocitems) if (menu->numitems >= menu->allocitems)
{ {
int olditems = menu->allocitems;
menu->allocitems += UI_MENU_ALLOC_ITEMS; menu->allocitems += UI_MENU_ALLOC_ITEMS;
menu->item = (ui_menu_item *)realloc(menu->item, menu->allocitems * sizeof(*item)); ui_menu_item *newitems = auto_alloc_array(menu->machine, ui_menu_item, menu->allocitems);
for (int itemnum = 0; itemnum < olditems; itemnum++)
newitems[itemnum] = menu->item[itemnum];
delete[] menu->item;
menu->item = newitems;
} }
index = menu->numitems++; index = menu->numitems++;
@ -636,9 +640,9 @@ void *ui_menu_alloc_state(ui_menu *menu, size_t size, ui_menu_destroy_state_func
{ {
if (menu->destroy_state != NULL) if (menu->destroy_state != NULL)
(*menu->destroy_state)(menu, menu->state); (*menu->destroy_state)(menu, menu->state);
free(menu->state); auto_free(menu->machine, menu->state);
} }
menu->state = alloc_array_clear_or_die(UINT8, size); menu->state = auto_alloc_array_clear(menu->machine, UINT8, size);
menu->destroy_state = destroy_state; menu->destroy_state = destroy_state;
return menu->state; return menu->state;
@ -666,7 +670,7 @@ void *ui_menu_pool_alloc(ui_menu *menu, size_t size)
} }
/* allocate a new pool */ /* allocate a new pool */
pool = (ui_menu_pool *)alloc_array_clear_or_die(UINT8, sizeof(*pool) + UI_MENU_POOL_SIZE); pool = (ui_menu_pool *)auto_alloc_array_clear(menu->machine, UINT8, sizeof(*pool) + UI_MENU_POOL_SIZE);
/* wire it up */ /* wire it up */
pool->next = menu->pool; pool->next = menu->pool;
@ -3417,7 +3421,7 @@ static void menu_select_game(running_machine *machine, ui_menu *menu, void *para
audit_records = audit_images(mame_options(), driver, AUDIT_VALIDATE_FAST, &audit); audit_records = audit_images(mame_options(), driver, AUDIT_VALIDATE_FAST, &audit);
audit_result = audit_summary(driver, audit_records, audit, FALSE); audit_result = audit_summary(driver, audit_records, audit, FALSE);
if (audit_records > 0) if (audit_records > 0)
free(audit); global_free(audit);
/* if everything looks good, schedule the new driver */ /* if everything looks good, schedule the new driver */
if (audit_result == CORRECT || audit_result == BEST_AVAILABLE) if (audit_result == CORRECT || audit_result == BEST_AVAILABLE)

View File

@ -14,7 +14,7 @@
#ifndef __UIMENU_H__ #ifndef __UIMENU_H__
#define __UIMENU_H__ #define __UIMENU_H__
#include "mamecore.h" #include "emucore.h"
/*************************************************************************** /***************************************************************************

View File

@ -1488,8 +1488,6 @@ int mame_validitychecks(const game_driver *curdriver)
/* validate inline function behavior */ /* validate inline function behavior */
error = validate_inlines() || error; error = validate_inlines() || error;
init_resource_tracking();
begin_resource_tracking();
get_profile_ticks(); get_profile_ticks();
/* pre-populate the defstr tagmap with all the default strings */ /* pre-populate the defstr tagmap with all the default strings */
@ -1590,9 +1588,6 @@ int mame_validitychecks(const game_driver *curdriver)
#endif #endif
#endif #endif
end_resource_tracking();
exit_resource_tracking();
tagmap_free(defstr); tagmap_free(defstr);
tagmap_free(roms); tagmap_free(roms);
tagmap_free(descriptions); tagmap_free(descriptions);

View File

@ -11,7 +11,7 @@
#pragma once #pragma once
#include "mamecore.h" #include "emucore.h"
#ifndef __VALIDITY_H__ #ifndef __VALIDITY_H__
#define __VALIDITY_H__ #define __VALIDITY_H__

View File

@ -14,7 +14,7 @@
#ifndef __VIDEO_H__ #ifndef __VIDEO_H__
#define __VIDEO_H__ #define __VIDEO_H__
#include "mamecore.h" #include "emucore.h"
#include "devintrf.h" #include "devintrf.h"
#include "timer.h" #include "timer.h"
#include "render.h" #include "render.h"

View File

@ -14,7 +14,7 @@
#ifndef __VIDEO_GENERIC_H__ #ifndef __VIDEO_GENERIC_H__
#define __VIDEO_GENERIC_H__ #define __VIDEO_GENERIC_H__
#include "mamecore.h" #include "emucore.h"

View File

@ -203,8 +203,7 @@ struct _poly_manager
FUNCTION PROTOTYPES FUNCTION PROTOTYPES
***************************************************************************/ ***************************************************************************/
static void **allocate_array(size_t *itemsize, UINT32 itemcount); static void **allocate_array(running_machine *machine, size_t *itemsize, UINT32 itemcount);
static void free_array(void **array);
static void *poly_item_callback(void *param, int threadid); static void *poly_item_callback(void *param, int threadid);
static STATE_PRESAVE( poly_state_presave ); static STATE_PRESAVE( poly_state_presave );
@ -333,26 +332,26 @@ poly_manager *poly_alloc(running_machine *machine, int max_polys, size_t extra_d
poly_manager *poly; poly_manager *poly;
/* allocate the manager itself */ /* allocate the manager itself */
poly = alloc_clear_or_die(poly_manager); poly = auto_alloc_clear(machine, poly_manager);
poly->flags = flags; poly->flags = flags;
/* allocate polygons */ /* allocate polygons */
poly->polygon_size = sizeof(polygon_info); poly->polygon_size = sizeof(polygon_info);
poly->polygon_count = MAX(max_polys, 1); poly->polygon_count = MAX(max_polys, 1);
poly->polygon_next = 0; poly->polygon_next = 0;
poly->polygon = (polygon_info **)allocate_array(&poly->polygon_size, poly->polygon_count); poly->polygon = (polygon_info **)allocate_array(machine, &poly->polygon_size, poly->polygon_count);
/* allocate extra data */ /* allocate extra data */
poly->extra_size = extra_data_size; poly->extra_size = extra_data_size;
poly->extra_count = poly->polygon_count; poly->extra_count = poly->polygon_count;
poly->extra_next = 1; poly->extra_next = 1;
poly->extra = allocate_array(&poly->extra_size, poly->extra_count); poly->extra = allocate_array(machine, &poly->extra_size, poly->extra_count);
/* allocate triangle work units */ /* allocate triangle work units */
poly->unit_size = (flags & POLYFLAG_ALLOW_QUADS) ? sizeof(quad_work_unit) : sizeof(tri_work_unit); poly->unit_size = (flags & POLYFLAG_ALLOW_QUADS) ? sizeof(quad_work_unit) : sizeof(tri_work_unit);
poly->unit_count = MIN(poly->polygon_count * UNITS_PER_POLY, 65535); poly->unit_count = MIN(poly->polygon_count * UNITS_PER_POLY, 65535);
poly->unit_next = 0; poly->unit_next = 0;
poly->unit = (work_unit **)allocate_array(&poly->unit_size, poly->unit_count); poly->unit = (work_unit **)allocate_array(machine, &poly->unit_size, poly->unit_count);
/* create the work queue */ /* create the work queue */
if (!(flags & POLYFLAG_NO_WORK_QUEUE)) if (!(flags & POLYFLAG_NO_WORK_QUEUE))
@ -394,14 +393,6 @@ void poly_free(poly_manager *poly)
/* free the work queue */ /* free the work queue */
if (poly->queue != NULL) if (poly->queue != NULL)
osd_work_queue_free(poly->queue); osd_work_queue_free(poly->queue);
/* free the arrays */
free_array(poly->extra);
free_array((void **)poly->polygon);
free_array((void **)poly->unit);
/* free the manager itself */
free(poly);
} }
@ -1300,7 +1291,7 @@ int poly_zclip_if_less(int numverts, const poly_vertex *v, poly_vertex *outv, in
allocate_array - allocate an array of pointers allocate_array - allocate an array of pointers
-------------------------------------------------*/ -------------------------------------------------*/
static void **allocate_array(size_t *itemsize, UINT32 itemcount) static void **allocate_array(running_machine *machine, size_t *itemsize, UINT32 itemcount)
{ {
void **ptrarray; void **ptrarray;
int itemnum; int itemnum;
@ -1313,10 +1304,10 @@ static void **allocate_array(size_t *itemsize, UINT32 itemcount)
*itemsize = ((*itemsize + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE) * CACHE_LINE_SIZE; *itemsize = ((*itemsize + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE) * CACHE_LINE_SIZE;
/* allocate the array */ /* allocate the array */
ptrarray = alloc_array_clear_or_die(void *, itemcount); ptrarray = auto_alloc_array_clear(machine, void *, itemcount);
/* allocate the actual items */ /* allocate the actual items */
ptrarray[0] = alloc_array_clear_or_die(UINT8, *itemsize * itemcount); ptrarray[0] = auto_alloc_array_clear(machine, UINT8, *itemsize * itemcount);
/* initialize the pointer array */ /* initialize the pointer array */
for (itemnum = 1; itemnum < itemcount; itemnum++) for (itemnum = 1; itemnum < itemcount; itemnum++)
@ -1325,21 +1316,6 @@ static void **allocate_array(size_t *itemsize, UINT32 itemcount)
} }
/*-------------------------------------------------
free_array - release an array of pointers
-------------------------------------------------*/
static void free_array(void **array)
{
if (array != NULL)
{
if (array[0] != NULL)
free(array[0]);
free(array);
}
}
/*------------------------------------------------- /*-------------------------------------------------
poly_item_callback - callback for each poly poly_item_callback - callback for each poly
item item

View File

@ -35,7 +35,7 @@
#ifndef __POLYNEW_H__ #ifndef __POLYNEW_H__
#define __POLYNEW_H__ #define __POLYNEW_H__
#include "mamecore.h" #include "emucore.h"
/*************************************************************************** /***************************************************************************

View File

@ -260,8 +260,8 @@ double compute_resistor_net_outputs(
/* parse input parameters */ /* parse input parameters */
o = alloc_array_or_die(double, (1<<MAX_RES_PER_NET) * MAX_NETS); o = global_alloc_array(double, (1<<MAX_RES_PER_NET) * MAX_NETS);
os = alloc_array_or_die(double, (1<<MAX_RES_PER_NET) * MAX_NETS); os = global_alloc_array(double, (1<<MAX_RES_PER_NET) * MAX_NETS);
networks_no = 0; networks_no = 0;
for (n = 0; n < MAX_NETS; n++) for (n = 0; n < MAX_NETS; n++)
@ -423,8 +423,8 @@ if (VERBOSE)
} }
/* debug end */ /* debug end */
free(o); global_free(o);
free(os); global_free(os);
return (scale); return (scale);
} }
@ -694,13 +694,13 @@ int compute_res_net(int inputs, int channel, const res_net_info *di)
return (int) (v *255 / vcc + 0.4); return (int) (v *255 / vcc + 0.4);
} }
rgb_t *compute_res_net_all(const UINT8 *prom, const res_net_decode_info *rdi, const res_net_info *di) rgb_t *compute_res_net_all(running_machine *machine, const UINT8 *prom, const res_net_decode_info *rdi, const res_net_info *di)
{ {
UINT8 r,g,b; UINT8 r,g,b;
int i,j,k; int i,j,k;
rgb_t *rgb; rgb_t *rgb;
rgb = alloc_array_or_die(rgb_t, rdi->end - rdi->start + 1); rgb = auto_alloc_array(machine, rgb_t, rdi->end - rdi->start + 1);
for (i=rdi->start; i<=rdi->end; i++) for (i=rdi->start; i<=rdi->end; i++)
{ {
UINT8 t[3] = {0,0,0}; UINT8 t[3] = {0,0,0};

View File

@ -159,7 +159,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di);
/* compute all values */ /* compute all values */
rgb_t *compute_res_net_all(const UINT8 *prom, const res_net_decode_info *rdi, const res_net_info *di); rgb_t *compute_res_net_all(running_machine *machine, const UINT8 *prom, const res_net_decode_info *rdi, const res_net_info *di);
/* legacy interface */ /* legacy interface */

View File

@ -47,25 +47,17 @@
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
struct _astring
{
char * text;
int alloclen;
char smallbuf[256 - sizeof(int) - sizeof(char *)];
};
/*************************************************************************** /***************************************************************************
GLOBAL VARIABLES GLOBAL VARIABLES
***************************************************************************/ ***************************************************************************/
static const char dummy_text[2] = { 0 }; static const char dummy_text[2] = { 0 };
#ifdef __cplusplus
static const astring dummy_astring;
#else
static const astring dummy_astring = { (char *)dummy_text, 1, { 0 } }; static const astring dummy_astring = { (char *)dummy_text, 1, { 0 } };
#endif
@ -143,6 +135,53 @@ INLINE void normalize_substr(int *start, int *count, int length)
ASTRING ALLOCATION ASTRING ALLOCATION
***************************************************************************/ ***************************************************************************/
#ifdef __cplusplus
/*-------------------------------------------------
astring - basic constructor
-------------------------------------------------*/
astring::astring()
{
/* initialize base fields by hand */
text = smallbuf;
alloclen = ARRAY_LENGTH(smallbuf);
smallbuf[0] = 0;
}
/*-------------------------------------------------
~astring - basic destructor
-------------------------------------------------*/
astring::~astring()
{
if (text != smallbuf)
free(text);
}
/*-------------------------------------------------
astring_alloc - allocate a new astring
-------------------------------------------------*/
astring *astring_alloc(void)
{
return new astring;
}
/*-------------------------------------------------
astring_free - free an astring
-------------------------------------------------*/
void astring_free(astring *str)
{
delete str;
}
#else
/*------------------------------------------------- /*-------------------------------------------------
astring_alloc - allocate a new astring astring_alloc - allocate a new astring
-------------------------------------------------*/ -------------------------------------------------*/
@ -180,6 +219,8 @@ void astring_free(astring *str)
free(str); free(str);
} }
#endif
/*************************************************************************** /***************************************************************************

View File

@ -42,15 +42,44 @@
#ifndef __ASTRING_H__ #ifndef __ASTRING_H__
#define __ASTRING_H__ #define __ASTRING_H__
#include "pool.h"
#include <stdarg.h> #include <stdarg.h>
#include "osdcomm.h"
/*************************************************************************** /***************************************************************************
TYPE DEFINITIONS TYPE DEFINITIONS
***************************************************************************/ ***************************************************************************/
typedef struct _astring astring; /* base astring structure */
typedef struct _astring_base astring_base;
struct _astring_base
{
char * text;
int alloclen;
char smallbuf[64 - sizeof(int) - sizeof(char *)];
};
#ifdef __cplusplus
/* class for C++ */
class astring : public astring_base
{
private:
astring(const astring &);
astring &operator=(const astring &);
public:
astring();
~astring();
};
#else
/* direct map for C */
typedef astring_base astring;
#endif

View File

@ -39,12 +39,152 @@
#include "bitmap.h" #include "bitmap.h"
#ifdef __cplusplus
#include <new>
#endif
/*************************************************************************** /***************************************************************************
BITMAP ALLOCATION/CONFIGURATION BITMAP ALLOCATION/CONFIGURATION
***************************************************************************/ ***************************************************************************/
#ifdef __cplusplus
/*-------------------------------------------------
bitmap_t - basic constructor
-------------------------------------------------*/
bitmap_t::bitmap_t()
{
/* initialize base fields by hand */
alloc = NULL;
base = NULL;
rowpixels = 0;
width = 0;
height = 0;
format = BITMAP_FORMAT_INVALID;
bpp = 0;
palette = NULL;
cliprect.min_x = cliprect.min_y = 0;
cliprect.max_x = cliprect.max_y = 0;
}
bitmap_t::bitmap_t(int _width, int _height, bitmap_format _format, int _xslop, int _yslop)
{
/* initialize base fields by hand */
alloc = NULL;
base = NULL;
rowpixels = (_width + 2 * _xslop + 7) & ~7;
width = _width;
height = _height;
format = _format;
bpp = bitmap_format_to_bpp(_format);
palette = NULL;
cliprect.min_x = cliprect.min_y = 0;
cliprect.max_x = width - 1;
cliprect.max_y = height - 1;
/* fail if invalid format */
if (bpp == 0)
throw std::bad_alloc();
/* allocate memory for the bitmap itself */
size_t allocbytes = rowpixels * (height + 2 * _yslop) * bpp / 8;
alloc = malloc(allocbytes);
if (alloc == NULL)
throw std::bad_alloc();
/* clear to 0 by default */
memset(alloc, 0, allocbytes);
/* compute the base */
base = (UINT8 *)alloc + (rowpixels * _yslop + _xslop) * (bpp / 8);
}
bitmap_t::bitmap_t(void *_base, int _width, int _height, int _rowpixels, bitmap_format _format)
{
/* initialize base fields by hand */
alloc = NULL;
base = _base;
rowpixels = _rowpixels;
width = _width;
height = _height;
format = _format;
bpp = bitmap_format_to_bpp(_format);
palette = NULL;
cliprect.min_x = cliprect.min_y = 0;
cliprect.max_x = width - 1;
cliprect.max_y = height - 1;
/* fail if invalid format */
if (bpp == 0)
throw std::bad_alloc();
}
/*-------------------------------------------------
~bitmap_t - basic destructor
-------------------------------------------------*/
bitmap_t::~bitmap_t()
{
/* dereference the palette */
if (palette != NULL)
palette_deref(palette);
/* free any allocated memory */
if (alloc != NULL)
free(alloc);
}
/*-------------------------------------------------
bitmap_alloc -- allocate memory for a new
bitmap of the given format
-------------------------------------------------*/
bitmap_t *bitmap_alloc(int width, int height, bitmap_format format)
{
return new bitmap_t(width, height, format);
}
/*-------------------------------------------------
bitmap_alloc_slop -- allocate a new bitmap with
additional slop on the borders
-------------------------------------------------*/
bitmap_t *bitmap_alloc_slop(int width, int height, int xslop, int yslop, bitmap_format format)
{
return new bitmap_t(width, height, format, xslop, yslop);
}
/*-------------------------------------------------
bitmap_wrap -- wrap an existing memory buffer
as a bitmap
-------------------------------------------------*/
bitmap_t *bitmap_wrap(void *base, int width, int height, int rowpixels, bitmap_format format)
{
return new bitmap_t(base, width, height, rowpixels, format);
}
/*-------------------------------------------------
bitmap_free -- release memory allocated for
a bitmap
-------------------------------------------------*/
void bitmap_free(bitmap_t *bitmap)
{
delete bitmap;
}
#else
/*------------------------------------------------- /*-------------------------------------------------
bitmap_alloc -- allocate memory for a new bitmap_alloc -- allocate memory for a new
bitmap of the given format bitmap of the given format
@ -145,6 +285,51 @@ bitmap_t *bitmap_wrap(void *base, int width, int height, int rowpixels, bitmap_f
} }
/*-------------------------------------------------
bitmap_free -- release memory allocated for
a bitmap
-------------------------------------------------*/
void bitmap_free(bitmap_t *bitmap)
{
/* dereference the palette */
if (bitmap->palette != NULL)
palette_deref(bitmap->palette);
/* free any allocated memory */
if (bitmap->alloc != NULL)
free(bitmap->alloc);
/* free the bitmap */
free(bitmap);
}
#endif
/*-------------------------------------------------
bitmap_clone_existing -- clone an existing
bitmap by copying its fields; the target
bitmap does not own the memory
-------------------------------------------------*/
void bitmap_clone_existing(bitmap_t *bitmap, const bitmap_t *srcbitmap)
{
if (bitmap->alloc != NULL)
free(bitmap->alloc);
bitmap->alloc = NULL;
bitmap->base = srcbitmap->base;
bitmap->rowpixels = srcbitmap->rowpixels;
bitmap->width = srcbitmap->width;
bitmap->height = srcbitmap->height;
bitmap->format = srcbitmap->format;
bitmap->bpp = srcbitmap->bpp;
bitmap->palette = srcbitmap->palette;
bitmap->cliprect = srcbitmap->cliprect;
}
/*------------------------------------------------- /*-------------------------------------------------
bitmap_set_palette -- associate a palette with bitmap_set_palette -- associate a palette with
a bitmap a bitmap
@ -168,26 +353,6 @@ void bitmap_set_palette(bitmap_t *bitmap, palette_t *palette)
} }
/*-------------------------------------------------
bitmap_free -- release memory allocated for
a bitmap
-------------------------------------------------*/
void bitmap_free(bitmap_t *bitmap)
{
/* dereference the palette */
if (bitmap->palette != NULL)
palette_deref(bitmap->palette);
/* free any allocated memory */
if (bitmap->alloc != NULL)
free(bitmap->alloc);
/* free the bitmap */
free(bitmap);
}
/*************************************************************************** /***************************************************************************
BITMAP DRAWING BITMAP DRAWING

Some files were not shown because too many files have changed in this diff Show More