summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--.gitattributes6
-rw-r--r--src/emu/attotime.c2
-rw-r--r--src/emu/attotime.h2
-rw-r--r--src/emu/audit.c6
-rw-r--r--src/emu/audit.h2
-rw-r--r--src/emu/cheat.c70
-rw-r--r--src/emu/cheat.h2
-rw-r--r--src/emu/clifront.c43
-rw-r--r--src/emu/cpu/adsp2100/adsp2100.c12
-rw-r--r--src/emu/cpu/drcfe.c13
-rw-r--r--src/emu/cpu/drcuml.c19
-rw-r--r--src/emu/cpu/jaguar/jaguar.c8
-rw-r--r--src/emu/cpu/se3208/se3208.c4
-rw-r--r--src/emu/cpu/v30mz/nechost.h2
-rw-r--r--src/emu/cpu/vtlb.c16
-rw-r--r--src/emu/cpu/x86log.c4
-rw-r--r--src/emu/cpu/z80/z80.c12
-rw-r--r--src/emu/cpu/z8000/z8000tbl.c10
-rw-r--r--src/emu/debug/debugcmd.c25
-rw-r--r--src/emu/debug/debugcmt.c34
-rw-r--r--src/emu/debug/debugcpu.c26
-rw-r--r--src/emu/debug/debugvw.c71
-rw-r--r--src/emu/debug/express.c4
-rw-r--r--src/emu/debug/express.h2
-rw-r--r--src/emu/debug/textbuf.c2
-rw-r--r--src/emu/debugger.c6
-rw-r--r--src/emu/deprecat.h2
-rw-r--r--src/emu/devintrf.c13
-rw-r--r--src/emu/devintrf.h2
-rw-r--r--src/emu/drawgfx.c29
-rw-r--r--src/emu/drawgfx.h4
-rw-r--r--src/emu/driver.c8
-rw-r--r--src/emu/driver.h2
-rw-r--r--src/emu/emu.mak4
-rw-r--r--src/emu/emucore.c (renamed from src/emu/mamecore.c)4
-rw-r--r--src/emu/emucore.h (renamed from src/emu/mamecore.h)25
-rw-r--r--src/emu/emuopts.c2
-rw-r--r--src/emu/emuopts.h2
-rw-r--r--src/emu/fileio.c27
-rw-r--r--src/emu/fileio.h2
-rw-r--r--src/emu/info.h2
-rw-r--r--src/emu/inptport.c30
-rw-r--r--src/emu/input.c6
-rw-r--r--src/emu/input.h2
-rw-r--r--src/emu/inputseq.c7
-rw-r--r--src/emu/machine/eeprom.c8
-rw-r--r--src/emu/machine/generic.h2
-rw-r--r--src/emu/machine/ldcore.c24
-rw-r--r--src/emu/machine/scsi.c2
-rw-r--r--src/emu/machine/scsidev.c2
-rw-r--r--src/emu/mame.c216
-rw-r--r--src/emu/mame.h32
-rw-r--r--src/emu/mconfig.c4
-rw-r--r--src/emu/mconfig.h2
-rw-r--r--src/emu/memory.c96
-rw-r--r--src/emu/memory.h3
-rw-r--r--src/emu/output.c14
-rw-r--r--src/emu/output.h2
-rw-r--r--src/emu/render.c41
-rw-r--r--src/emu/rendersw.c2
-rw-r--r--src/emu/rendfont.c40
-rw-r--r--src/emu/rendlay.c52
-rw-r--r--src/emu/restrack.c380
-rw-r--r--src/emu/restrack.h96
-rw-r--r--src/emu/romload.c6
-rw-r--r--src/emu/romload.h2
-rw-r--r--src/emu/sound.c4
-rw-r--r--src/emu/sound/ay8910.c4
-rw-r--r--src/emu/sound/filter.c8
-rw-r--r--src/emu/sound/fm.c27
-rw-r--r--src/emu/sound/fm2612.c9
-rw-r--r--src/emu/sound/fmopl.c12
-rw-r--r--src/emu/sound/tiasound.c7
-rw-r--r--src/emu/sound/wavwrite.c2
-rw-r--r--src/emu/sound/ym2151.c6
-rw-r--r--src/emu/sound/ym2413.c19
-rw-r--r--src/emu/sound/ymf262.c12
-rw-r--r--src/emu/state.h2
-rw-r--r--src/emu/streams.c13
-rw-r--r--src/emu/streams.h2
-rw-r--r--src/emu/tilemap.c36
-rw-r--r--src/emu/tilemap.h2
-rw-r--r--src/emu/timer.c2
-rw-r--r--src/emu/timer.h2
-rw-r--r--src/emu/ui.h2
-rw-r--r--src/emu/uigfx.h2
-rw-r--r--src/emu/uiinput.h2
-rw-r--r--src/emu/uimenu.c28
-rw-r--r--src/emu/uimenu.h2
-rw-r--r--src/emu/validity.c5
-rw-r--r--src/emu/validity.h2
-rw-r--r--src/emu/video.h2
-rw-r--r--src/emu/video/generic.h2
-rw-r--r--src/emu/video/poly.c40
-rw-r--r--src/emu/video/poly.h2
-rw-r--r--src/emu/video/resnet.c12
-rw-r--r--src/emu/video/resnet.h2
-rw-r--r--src/lib/util/astring.c67
-rw-r--r--src/lib/util/astring.h33
-rw-r--r--src/lib/util/bitmap.c205
-rw-r--r--src/lib/util/bitmap.h31
-rw-r--r--src/lib/util/pool.c8
-rw-r--r--src/mame/drivers/alg.c12
-rw-r--r--src/mame/drivers/ampoker2.c6
-rw-r--r--src/mame/drivers/arkanoid.c4
-rw-r--r--src/mame/drivers/backfire.c4
-rw-r--r--src/mame/drivers/balsente.c4
-rw-r--r--src/mame/drivers/bfcobra.c4
-rw-r--r--src/mame/drivers/bfm_sc1.c4
-rw-r--r--src/mame/drivers/bfm_sc2.c4
-rw-r--r--src/mame/drivers/cave.c12
-rw-r--r--src/mame/drivers/coinmstr.c16
-rw-r--r--src/mame/drivers/darkmist.c8
-rw-r--r--src/mame/drivers/dassault.c8
-rw-r--r--src/mame/drivers/ddayjlc.c4
-rw-r--r--src/mame/drivers/deco156.c4
-rw-r--r--src/mame/drivers/deco32.c8
-rw-r--r--src/mame/drivers/deco_mlc.c4
-rw-r--r--src/mame/drivers/dynax.c66
-rw-r--r--src/mame/drivers/exerion.c4
-rw-r--r--src/mame/drivers/fcombat.c4
-rw-r--r--src/mame/drivers/forte2.c4
-rw-r--r--src/mame/drivers/funworld.c12
-rw-r--r--src/mame/drivers/gaiden.c22
-rw-r--r--src/mame/drivers/galaxian.c8
-rw-r--r--src/mame/drivers/gauntlet.c16
-rw-r--r--src/mame/drivers/goldstar.c24
-rw-r--r--src/mame/drivers/hng64.c8
-rw-r--r--src/mame/drivers/igs011.c16
-rw-r--r--src/mame/drivers/igs017.c4
-rw-r--r--src/mame/drivers/igs_m027.c4
-rw-r--r--src/mame/drivers/igspoker.c4
-rw-r--r--src/mame/drivers/legionna.c8
-rw-r--r--src/mame/drivers/megasys1.c8
-rw-r--r--src/mame/drivers/mitchell.c4
-rw-r--r--src/mame/drivers/model3.c2
-rw-r--r--src/mame/drivers/ms32.c12
-rw-r--r--src/mame/drivers/mustache.c4
-rw-r--r--src/mame/drivers/namcos86.c8
-rw-r--r--src/mame/drivers/ninjakd2.c4
-rw-r--r--src/mame/drivers/nmk16.c16
-rw-r--r--src/mame/drivers/nova2001.c4
-rw-r--r--src/mame/drivers/panicr.c4
-rw-r--r--src/mame/drivers/pirates.c16
-rw-r--r--src/mame/drivers/popeye.c8
-rw-r--r--src/mame/drivers/segag80r.c4
-rw-r--r--src/mame/drivers/seta.c4
-rw-r--r--src/mame/drivers/silkroad.c4
-rw-r--r--src/mame/drivers/simpl156.c4
-rw-r--r--src/mame/drivers/snowbros.c12
-rw-r--r--src/mame/drivers/tcl.c4
-rw-r--r--src/mame/drivers/tmnt.c8
-rw-r--r--src/mame/drivers/toki.c60
-rw-r--r--src/mame/drivers/travrusa.c18
-rw-r--r--src/mame/drivers/tumbleb.c36
-rw-r--r--src/mame/drivers/twin16.c4
-rw-r--r--src/mame/drivers/wecleman.c30
-rw-r--r--src/mame/drivers/wink.c22
-rw-r--r--src/mame/includes/model3.h2
-rw-r--r--src/mame/machine/deco102.c60
-rw-r--r--src/mame/machine/deco156.c8
-rw-r--r--src/mame/machine/decocrpt.c56
-rw-r--r--src/mame/machine/kaneko16.c4
-rw-r--r--src/mame/machine/neoboot.c138
-rw-r--r--src/mame/machine/neocrypt.c142
-rw-r--r--src/mame/machine/scramble.c50
-rw-r--r--src/mame/machine/segas32.c4
-rw-r--r--src/mame/machine/stvcd.c28
-rw-r--r--src/mame/video/aeroboto.c4
-rw-r--r--src/mame/video/bfm_adr2.c4
-rw-r--r--src/mame/video/dkong.c8
-rw-r--r--src/mame/video/hng64.c4
-rw-r--r--src/mame/video/m62.c36
-rw-r--r--src/mame/video/mario.c8
-rw-r--r--src/mame/video/model3.c84
-rw-r--r--src/mame/video/namcos22.c9
-rw-r--r--src/mame/video/naughtyb.c4
-rw-r--r--src/mame/video/phoenix.c12
-rw-r--r--src/mame/video/popper.c4
-rw-r--r--src/mame/video/tceptor.c4
-rw-r--r--src/osd/osdcore.h33
-rw-r--r--src/osd/osdepend.h2
-rw-r--r--src/osd/osdmini/minimisc.c20
-rw-r--r--src/osd/windows/d3d8intf.c4
-rw-r--r--src/osd/windows/d3d9intf.c4
-rw-r--r--src/osd/windows/debugwin.c14
-rw-r--r--src/osd/windows/drawd3d.c14
-rw-r--r--src/osd/windows/drawdd.c10
-rw-r--r--src/osd/windows/drawgdi.c12
-rw-r--r--src/osd/windows/drawnone.c2
-rw-r--r--src/osd/windows/input.c72
-rw-r--r--src/osd/windows/main.c14
-rw-r--r--src/osd/windows/output.c10
-rw-r--r--src/osd/windows/strconv.c4
-rw-r--r--src/osd/windows/strconv.h2
-rw-r--r--src/osd/windows/video.c14
-rw-r--r--src/osd/windows/window.c4
-rw-r--r--src/osd/windows/windows.mak13
-rw-r--r--src/osd/windows/winmisc.c86
-rw-r--r--src/osd/windows/winprefix.h28
-rw-r--r--src/tools/chdman.c8
-rw-r--r--src/tools/ldverify.c2
-rw-r--r--src/tools/romcmp.c1
203 files changed, 1761 insertions, 2113 deletions
diff --git a/.gitattributes b/.gitattributes
index c4f1084425c..744207d045b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -564,6 +564,8 @@ src/emu/eigccppc.h svneol=native#text/plain
src/emu/eigccx86.h svneol=native#text/plain
src/emu/eminline.h 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.h 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/mame.c 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.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/rendutil.c 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.h svneol=native#text/plain
src/emu/sndintrf.h svneol=native#text/plain
diff --git a/src/emu/attotime.c b/src/emu/attotime.c
index 60460d9a50f..6febd5a0439 100644
--- a/src/emu/attotime.c
+++ b/src/emu/attotime.c
@@ -9,7 +9,7 @@
***************************************************************************/
-#include "mamecore.h"
+#include "emucore.h"
#include "attotime.h"
#include "eminline.h"
diff --git a/src/emu/attotime.h b/src/emu/attotime.h
index 693e4cd0f84..fab20277b04 100644
--- a/src/emu/attotime.h
+++ b/src/emu/attotime.h
@@ -36,7 +36,7 @@
#ifndef __ATTOTIME_H__
#define __ATTOTIME_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "eminline.h"
#include <math.h>
diff --git a/src/emu/audit.c b/src/emu/audit.c
index f7b70c0cc34..0a9aa420c64 100644
--- a/src/emu/audit.c
+++ b/src/emu/audit.c
@@ -88,7 +88,7 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid
if (records > 0)
{
/* allocate memory for the records */
- *audit = alloc_array_clear_or_die(audit_record, records);
+ *audit = global_alloc_array_clear(audit_record, records);
record = *audit;
/* 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 (!anyfound && anyrequired)
{
- free(*audit);
+ global_free(*audit);
*audit = NULL;
records = 0;
}
@@ -172,7 +172,7 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor
goto skip;
/* allocate memory for the records */
- *audit = alloc_array_clear_or_die(audit_record, records);
+ *audit = global_alloc_array_clear(audit_record, records);
record = *audit;
/* now iterate over sample entries */
diff --git a/src/emu/audit.h b/src/emu/audit.h
index ede7c30efe7..779faf5cacc 100644
--- a/src/emu/audit.h
+++ b/src/emu/audit.h
@@ -14,7 +14,7 @@
#ifndef __AUDIT_H__
#define __AUDIT_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "hash.h"
diff --git a/src/emu/cheat.c b/src/emu/cheat.c
index d3698a0e504..130f84738f8 100644
--- a/src/emu/cheat.c
+++ b/src/emu/cheat.c
@@ -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 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 void cheat_entry_save(mame_file *cheatfile, const cheat_entry *cheat);
-static void cheat_entry_free(cheat_entry *cheat);
-static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node *paramnode);
+static void cheat_entry_free(running_machine *machine, cheat_entry *cheat);
+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_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 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 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 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 */
if (cheatinfo->cheatlist != NULL)
- cheat_list_free(cheatinfo->cheatlist);
+ cheat_list_free(machine, cheatinfo->cheatlist);
/* free any text strings */
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;
error:
- cheat_list_free(cheatlist);
+ cheat_list_free(machine, cheatlist);
xml_file_free(rootnode);
if (cheatfile != NULL)
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
-------------------------------------------------*/
-static void cheat_list_free(cheat_entry *cheat)
+static void cheat_list_free(running_machine *machine, cheat_entry *cheat)
{
while (cheat != NULL)
{
cheat_entry *entry = cheat;
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 */
- 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;
/* get the description */
@@ -1236,7 +1236,7 @@ static cheat_entry *cheat_entry_load(running_machine *machine, const char *filen
if (paramnode != NULL)
{
/* load this parameter */
- cheat_parameter *curparam = cheat_parameter_load(filename, paramnode);
+ cheat_parameter *curparam = cheat_parameter_load(machine, filename, paramnode);
if (curparam == NULL)
goto error;
@@ -1272,7 +1272,7 @@ static cheat_entry *cheat_entry_load(running_machine *machine, const char *filen
return cheat;
error:
- cheat_entry_free(cheat);
+ cheat_entry_free(machine, cheat);
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
-------------------------------------------------*/
-static void cheat_entry_free(cheat_entry *cheat)
+static void cheat_entry_free(running_machine *machine, cheat_entry *cheat)
{
script_state state;
@@ -1337,16 +1337,16 @@ static void cheat_entry_free(cheat_entry *cheat)
astring_free(cheat->comment);
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++)
if (cheat->script[state] != NULL)
- cheat_script_free(cheat->script[state]);
+ cheat_script_free(machine, cheat->script[state]);
if (cheat->symbols != NULL)
symtable_free(cheat->symbols);
- free(cheat);
+ auto_free(machine, cheat);
}
@@ -1356,14 +1356,14 @@ static void cheat_entry_free(cheat_entry *cheat)
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;
xml_data_node *itemnode;
cheat_parameter *param;
/* allocate memory for it */
- param = alloc_clear_or_die(cheat_parameter);
+ param = auto_alloc_clear(machine, cheat_parameter);
/* read the core attributes */
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;
/* allocate memory for it */
- curitem = alloc_clear_or_die(parameter_item);
+ curitem = auto_alloc_clear(machine, parameter_item);
/* check for NULL text */
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;
error:
- cheat_parameter_free(param);
+ cheat_parameter_free(machine, param);
return NULL;
}
@@ -1460,7 +1460,7 @@ static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *pa
parameter
-------------------------------------------------*/
-static void cheat_parameter_free(cheat_parameter *param)
+static void cheat_parameter_free(running_machine *machine, cheat_parameter *param)
{
while (param->itemlist != NULL)
{
@@ -1469,10 +1469,10 @@ static void cheat_parameter_free(cheat_parameter *param)
if (item->text != NULL)
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;
/* allocate memory for it */
- script = alloc_clear_or_die(cheat_script);
+ script = auto_alloc_clear(machine, cheat_script);
/* read the core attributes */
script->state = SCRIPT_STATE_RUN;
@@ -1538,7 +1538,7 @@ static cheat_script *cheat_script_load(running_machine *machine, const char *fil
return script;
error:
- cheat_script_free(script);
+ cheat_script_free(machine, script);
return NULL;
}
@@ -1578,16 +1578,16 @@ static void cheat_script_save(mame_file *cheatfile, const cheat_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)
{
script_entry *entry = script->entrylist;
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;
/* allocate memory for it */
- entry = alloc_clear_or_die(script_entry);
+ entry = auto_alloc_clear(machine, script_entry);
/* read the condition if present */
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;
/* allocate memory for it */
- curarg = alloc_clear_or_die(output_argument);
+ curarg = auto_alloc_clear(machine, output_argument);
/* first extract attributes */
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;
error:
- script_entry_free(entry);
+ script_entry_free(machine, entry);
return NULL;
}
@@ -1784,7 +1784,7 @@ static void script_entry_save(mame_file *cheatfile, const script_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)
expression_free(entry->condition);
@@ -1800,10 +1800,10 @@ static void script_entry_free(script_entry *entry)
if (curarg->expression != NULL)
expression_free(curarg->expression);
- free(curarg);
+ auto_free(machine, curarg);
}
- free(entry);
+ auto_free(machine, entry);
}
diff --git a/src/emu/cheat.h b/src/emu/cheat.h
index 2fcfbb2d721..e7ff2fd9081 100644
--- a/src/emu/cheat.h
+++ b/src/emu/cheat.h
@@ -14,7 +14,7 @@
#ifndef __CHEAT_H__
#define __CHEAT_H__
-#include "mamecore.h"
+#include "emucore.h"
diff --git a/src/emu/clifront.c b/src/emu/clifront.c
index e0172ea52f6..91f05f3ecda 100644
--- a/src/emu/clifront.c
+++ b/src/emu/clifront.c
@@ -179,7 +179,7 @@ int cli_execute(int argc, char **argv, const options_entry *osd_options)
if (fatal.exitcode() != 0)
result = fatal.exitcode();
}
- catch (emu_exception &exception)
+ catch (emu_exception &)
{
fprintf(stderr, "Caught unhandled emulator exception\n");
}
@@ -198,6 +198,9 @@ error:
options_free(options);
astring_free(gamename);
astring_free(exename);
+
+ /* report any unfreed memory */
+ dump_unfreed_mem();
return result;
}
@@ -356,13 +359,7 @@ static void display_help(void)
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);
-
- /* clean up our tracked resources */
- exit_resource_tracking();
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)
{
- 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();
int drvindex, count = 0;
@@ -495,7 +492,7 @@ int cli_info_listbrothers(core_options *options, const char *gamename)
/* return an error if none found */
astring_free(filename);
- free(didit);
+ global_free(didit);
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 drvindex;
- /* since we expand the machine driver, we need to set things up */
- init_resource_tracking();
-
/* iterate over drivers */
for (drvindex = 0; drivers[drvindex] != NULL; drvindex++)
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);
}
- /* clean up our tracked resources */
- exit_resource_tracking();
-
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 drvindex;
- /* since we expand the machine driver, we need to set things up */
- init_resource_tracking();
-
/* iterate over drivers */
for (drvindex = 0; drivers[drvindex] != NULL; drvindex++)
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);
}
- /* clean up our tracked resources */
- exit_resource_tracking();
-
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);
res = audit_summary(drivers[drvindex], audit_records, audit, TRUE);
if (audit_records > 0)
- free(audit);
+ global_free(audit);
/* if not found, count that and leave it at that */
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);
res = audit_summary(drivers[drvindex], audit_records, audit, TRUE);
if (audit_records > 0)
- free(audit);
+ global_free(audit);
else
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))
if (entry->uncompressed_length != 0)
{
- UINT8 *data = (UINT8 *)malloc(entry->uncompressed_length);
+ UINT8 *data = global_alloc_array(UINT8, entry->uncompressed_length);
if (data != NULL)
{
/* decompress data into RAM and identify it */
ziperr = zip_file_decompress(zip, data, entry->uncompressed_length);
if (ziperr == ZIPERR_NONE)
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);
if (filerr == FILERR_NONE && length > 0 && (UINT32)length == length)
{
- UINT8 *data = (UINT8 *)malloc(length);
+ UINT8 *data = global_alloc_array(UINT8, length);
if (data != NULL)
{
UINT32 bytes;
@@ -1003,7 +988,7 @@ static void identify_file(const char *name, romident_status *status)
filerr = osd_read(file, data, 0, length, &bytes);
if (filerr == FILERR_NONE)
identify_data(name, data, bytes, status);
- free(data);
+ global_free(data);
}
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 */
length = jedbin_output(&jed, NULL, 0);
- tempjed = (UINT8 *)malloc(length);
+ tempjed = global_alloc_array(UINT8, length);
if (tempjed == NULL)
return;
@@ -1072,7 +1057,7 @@ static void identify_data(const char *name, const UINT8 *data, int length, romid
/* free any temporary JED data */
if (tempjed != NULL)
- free(tempjed);
+ global_free(tempjed);
}
diff --git a/src/emu/cpu/adsp2100/adsp2100.c b/src/emu/cpu/adsp2100/adsp2100.c
index 2fa1bee4ea7..aabb5349239 100644
--- a/src/emu/cpu/adsp2100/adsp2100.c
+++ b/src/emu/cpu/adsp2100/adsp2100.c
@@ -924,11 +924,11 @@ static int create_tables(void)
/* allocate the tables */
if (!reverse_table)
- reverse_table = (UINT16 *)malloc(0x4000 * sizeof(UINT16));
+ reverse_table = global_alloc_array(UINT16, 0x4000);
if (!mask_table)
- mask_table = (UINT16 *)malloc(0x4000 * sizeof(UINT16));
+ mask_table = global_alloc_array(UINT16, 0x4000);
if (!condition_table)
- condition_table = (UINT8 *)malloc(0x1000 * sizeof(UINT8));
+ condition_table = global_alloc_array(UINT8, 0x1000);
/* handle errors */
if (reverse_table == NULL || mask_table == NULL || condition_table == NULL)
@@ -1010,15 +1010,15 @@ static int create_tables(void)
static CPU_EXIT( adsp21xx )
{
if (reverse_table != NULL)
- free(reverse_table);
+ global_free(reverse_table);
reverse_table = NULL;
if (mask_table != NULL)
- free(mask_table);
+ global_free(mask_table);
mask_table = NULL;
if (condition_table != NULL)
- free(condition_table);
+ global_free(condition_table);
condition_table = NULL;
#if TRACK_HOTSPOTS
diff --git a/src/emu/cpu/drcfe.c b/src/emu/cpu/drcfe.c
index 0d7c124c063..0be7c4c65a9 100644
--- a/src/emu/cpu/drcfe.c
+++ b/src/emu/cpu/drcfe.c
@@ -97,7 +97,7 @@ INLINE opcode_desc *desc_alloc(drcfe_state *drcfe)
if (desc != NULL)
drcfe->desc_free_list = desc->next;
else
- desc = alloc_or_die(opcode_desc);
+ desc = auto_alloc(drcfe->device->machine, opcode_desc);
return desc;
}
@@ -128,10 +128,10 @@ drcfe_state *drcfe_init(const device_config *cpu, const drcfe_config *config, vo
drcfe_state *drcfe;
/* 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 */
- 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 */
drcfe->window_start = config->window_start;
@@ -164,15 +164,14 @@ void drcfe_exit(drcfe_state *drcfe)
{
opcode_desc *freeme = drcfe->desc_free_list;
drcfe->desc_free_list = drcfe->desc_free_list->next;
- free(freeme);
+ auto_free(drcfe->device->machine, freeme);
}
/* free the description array */
- if (drcfe->desc_array != NULL)
- free(drcfe->desc_array);
+ auto_free(drcfe->device->machine, drcfe->desc_array);
/* free the object itself */
- free(drcfe);
+ auto_free(drcfe->device->machine, drcfe);
}
diff --git a/src/emu/cpu/drcuml.c b/src/emu/cpu/drcuml.c
index cd42eae0510..d0ecfd2066c 100644
--- a/src/emu/cpu/drcuml.c
+++ b/src/emu/cpu/drcuml.c
@@ -646,8 +646,8 @@ void drcuml_free(drcuml_state *drcuml)
/* free memory */
if (block->inst != NULL)
- free(block->inst);
- free(block);
+ auto_free(drcuml->device->machine, block->inst);
+ auto_free(drcuml->device->machine, block);
}
/* free all the symbols */
@@ -655,7 +655,7 @@ void drcuml_free(drcuml_state *drcuml)
{
drcuml_symbol *sym = drcuml->symlist;
drcuml->symlist = sym->next;
- free(sym);
+ auto_free(drcuml->device->machine, sym);
}
/* close any files */
@@ -687,18 +687,13 @@ drcuml_block *drcuml_block_begin(drcuml_state *drcuml, UINT32 maxinst, jmp_buf *
if (bestblock == NULL)
{
/* allocate the block structure itself */
- bestblock = (drcuml_block *)malloc(sizeof(*bestblock));
- if (bestblock == NULL)
- fatalerror("Out of memory allocating block in drcuml_block_begin");
- memset(bestblock, 0, sizeof(*bestblock));
+ bestblock = auto_alloc_clear(drcuml->device->machine, drcuml_block);
/* fill in the structure */
bestblock->drcuml = drcuml;
bestblock->next = drcuml->blocklist;
bestblock->maxinst = maxinst * 3 / 2;
- bestblock->inst = (drcuml_instruction *)malloc(sizeof(drcuml_instruction) * bestblock->maxinst);
- if (bestblock->inst == NULL)
- fatalerror("Out of memory allocating instruction array in drcuml_block_begin");
+ bestblock->inst = auto_alloc_array(drcuml->device->machine, drcuml_instruction, bestblock->maxinst);
/* hook us into the list */
drcuml->blocklist = bestblock;
@@ -1037,9 +1032,7 @@ void drcuml_symbol_add(drcuml_state *drcuml, void *base, UINT32 length, const ch
drcuml_symbol *symbol;
/* allocate memory to hold the symbol */
- symbol = (drcuml_symbol *)malloc(sizeof(*symbol) + strlen(name));
- if (symbol == NULL)
- fatalerror("Out of memory allocating symbol in drcuml_symbol_add");
+ symbol = (drcuml_symbol *)auto_alloc_array(drcuml->device->machine, UINT8, sizeof(*symbol) + strlen(name));
/* fill in the structure */
symbol->next = NULL;
diff --git a/src/emu/cpu/jaguar/jaguar.c b/src/emu/cpu/jaguar/jaguar.c
index 121093a21af..f272a2a419e 100644
--- a/src/emu/cpu/jaguar/jaguar.c
+++ b/src/emu/cpu/jaguar/jaguar.c
@@ -370,7 +370,7 @@ static void init_tables(void)
}
/* 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++)
mirror_table[i] = ((i >> 15) & 0x0001) | ((i >> 13) & 0x0002) |
((i >> 11) & 0x0004) | ((i >> 9) & 0x0008) |
@@ -382,7 +382,7 @@ static void init_tables(void)
((i << 13) & 0x4000) | ((i << 15) & 0x8000);
/* 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 (j = 0; j < 32; j++)
{
@@ -461,11 +461,11 @@ static CPU_EXIT( jaguar )
return;
if (mirror_table != NULL)
- free(mirror_table);
+ global_free(mirror_table);
mirror_table = NULL;
if (condition_table != NULL)
- free(condition_table);
+ global_free(condition_table);
condition_table = NULL;
}
diff --git a/src/emu/cpu/se3208/se3208.c b/src/emu/cpu/se3208/se3208.c
index 5839b8d2573..cdd5ec25aa8 100644
--- a/src/emu/cpu/se3208/se3208.c
+++ b/src/emu/cpu/se3208/se3208.c
@@ -1705,7 +1705,7 @@ static void BuildTable(void)
{
int i;
if(!OpTable)
- OpTable=alloc_array_or_die(_OP, 0x10000);
+ OpTable=global_alloc_array(_OP, 0x10000);
for(i=0;i<0x10000;++i)
OpTable[i]=DecodeOp(i);
}
@@ -1797,7 +1797,7 @@ static CPU_INIT( se3208 )
static CPU_EXIT( se3208 )
{
if(OpTable)
- free(OpTable);
+ global_free(OpTable);
}
diff --git a/src/emu/cpu/v30mz/nechost.h b/src/emu/cpu/v30mz/nechost.h
index a2b5f44a03d..f0d275f1d0f 100644
--- a/src/emu/cpu/v30mz/nechost.h
+++ b/src/emu/cpu/v30mz/nechost.h
@@ -3,7 +3,7 @@
#define BIGCASE
-#include "mamecore.h"
+#include "emucore.h"
typedef char BOOLEAN;
diff --git a/src/emu/cpu/vtlb.c b/src/emu/cpu/vtlb.c
index c8c3bc49b27..656321c69db 100644
--- a/src/emu/cpu/vtlb.c
+++ b/src/emu/cpu/vtlb.c
@@ -60,7 +60,7 @@ vtlb_state *vtlb_alloc(const device_config *cpu, int space, int fixed_entries, i
vtlb_state *vtlb;
/* 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 */
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);
/* 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);
/* 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));
/* allocate the fixed page count array */
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);
}
return vtlb;
@@ -102,16 +102,16 @@ void vtlb_free(vtlb_state *vtlb)
{
/* free the fixed pages if allocated */
if (vtlb->fixedpages != NULL)
- free(vtlb->fixedpages);
+ auto_free(vtlb->device->machine, vtlb->fixedpages);
/* free the table and array if they exist */
if (vtlb->live != NULL)
- free(vtlb->live);
+ auto_free(vtlb->device->machine, vtlb->live);
if (vtlb->table != NULL)
- free(vtlb->table);
+ auto_free(vtlb->device->machine, vtlb->table);
/* and then the VTLB object itself */
- free(vtlb);
+ auto_free(vtlb->device->machine, vtlb);
}
diff --git a/src/emu/cpu/x86log.c b/src/emu/cpu/x86log.c
index bf61884ce58..5af2b8dad0e 100644
--- a/src/emu/cpu/x86log.c
+++ b/src/emu/cpu/x86log.c
@@ -91,7 +91,7 @@ x86log_context *x86log_create_context(const char *filename)
x86log_context *log;
/* allocate the log */
- log = alloc_clear_or_die(x86log_context);
+ log = global_alloc_clear(x86log_context);
/* allocate the filename */
log->filename = astring_dupc(filename);
@@ -114,7 +114,7 @@ void x86log_free_context(x86log_context *log)
/* free the structure */
astring_free(log->filename);
- free(log);
+ global_free(log);
}
diff --git a/src/emu/cpu/z80/z80.c b/src/emu/cpu/z80/z80.c
index f13b97b9928..61eeef4ed5e 100644
--- a/src/emu/cpu/z80/z80.c
+++ b/src/emu/cpu/z80/z80.c
@@ -3362,12 +3362,8 @@ static CPU_INIT( z80 )
int oldval, newval, val;
UINT8 *padd, *padc, *psub, *psbc;
/* allocate big flag arrays once */
- SZHVC_add = (UINT8 *)malloc(2*256*256);
- SZHVC_sub = (UINT8 *)malloc(2*256*256);
- if( !SZHVC_add || !SZHVC_sub )
- {
- fatalerror("Z80: failed to allocate 2 * 128K flags arrays!!!");
- }
+ SZHVC_add = global_alloc_array(UINT8, 2*256*256);
+ SZHVC_sub = global_alloc_array(UINT8, 2*256*256);
padd = &SZHVC_add[ 0*256];
padc = &SZHVC_add[256*256];
psub = &SZHVC_sub[ 0*256];
@@ -3514,9 +3510,9 @@ static CPU_RESET( z80 )
static CPU_EXIT( z80 )
{
- if (SZHVC_add) free(SZHVC_add);
+ global_free(SZHVC_add);
SZHVC_add = NULL;
- if (SZHVC_sub) free(SZHVC_sub);
+ global_free(SZHVC_sub);
SZHVC_sub = NULL;
}
diff --git a/src/emu/cpu/z8000/z8000tbl.c b/src/emu/cpu/z8000/z8000tbl.c
index 4ce36f55bac..e34ebd79888 100644
--- a/src/emu/cpu/z8000/z8000tbl.c
+++ b/src/emu/cpu/z8000/z8000tbl.c
@@ -545,11 +545,7 @@ void z8000_init_tables(void)
int i;
/* allocate the opcode execution and disassembler array */
- z8000_exec = (Z8000_exec *)malloc(0x10000 * sizeof(Z8000_exec));
- if( !z8000_exec )
- {
- fatalerror("cannot allocate Z8000 execution table\n");
- }
+ z8000_exec = global_alloc_array(Z8000_exec, 0x10000);
/* set up the zero, sign, parity lookup table */
for (i = 0; i < 256; i++)
@@ -586,9 +582,7 @@ void z8000_init_tables(void)
void z8000_deinit_tables(void)
{
- if( !z8000_exec )
- return;
- free( z8000_exec );
+ global_free( z8000_exec );
z8000_exec = 0;
}
diff --git a/src/emu/debug/debugcmd.c b/src/emu/debug/debugcmd.c
index bc661c1a10e..56dd599d1f0 100644
--- a/src/emu/debug/debugcmd.c
+++ b/src/emu/debug/debugcmd.c
@@ -396,7 +396,7 @@ static void debug_command_exit(running_machine *machine)
debug_cpu_trace(cpu, NULL, 0, NULL);
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 */
if (cheat.cheatmap != NULL)
- free(cheat.cheatmap);
- cheat.cheatmap = (cheat_map *)malloc(real_length * sizeof(cheat_map));
- if (cheat.cheatmap == NULL)
- {
- debug_console_printf(machine, "Unable of allocate the necessary memory\n");
- return;
- }
+ auto_free(machine, cheat.cheatmap);
+ cheat.cheatmap = auto_alloc_array(machine, cheat_map, real_length);
cheat.length = real_length;
cheat.undo = 0;
@@ -1846,8 +1841,6 @@ static void execute_cheatinit(running_machine *machine, int ref, int params, con
else
{
/* add range to cheat system */
- cheat_map * cheatmap_bak = cheat.cheatmap;
-
if (cheat.cpu == 0)
{
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))
return;
- cheat.cheatmap = (cheat_map *)realloc(cheat.cheatmap, (cheat.length + real_length) * sizeof(cheat_map));
- if (cheat.cheatmap == NULL)
- {
- cheat.cheatmap = cheatmap_bak;
- debug_console_printf(machine, "Unable of allocate the necessary memory\n");
- return;
- }
+ cheat_map *newmap = auto_alloc_array(machine, cheat_map, cheat.length + real_length);
+ for (int item = 0; item < cheat.length; item++)
+ newmap[item] = cheat.cheatmap[item];
+ auto_free(machine, cheat.cheatmap);
+ cheat.cheatmap = newmap;
active_cheat = cheat.length;
cheat.length += real_length;
diff --git a/src/emu/debug/debugcmt.c b/src/emu/debug/debugcmt.c
index ae5e3b5830e..7f24d481e5f 100644
--- a/src/emu/debug/debugcmt.c
+++ b/src/emu/debug/debugcmt.c
@@ -78,7 +78,6 @@ struct _debug_cpu_comment_group
static int debug_comment_load_xml(running_machine *machine, mame_file *file);
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;
/* 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->is_valid = 1;
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 */
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->change_count++;
@@ -198,7 +197,7 @@ int debug_comment_remove(const device_config *device, offs_t addr, UINT32 c_crc)
return 0;
/* 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++)
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"))
{
/* 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]->color = xml_get_attribute_int(datanode, "color", 0);
@@ -530,29 +529,4 @@ error:
static void debug_comment_exit(running_machine *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;
- }
- }
}
diff --git a/src/emu/debug/debugcpu.c b/src/emu/debug/debugcpu.c
index 3654248079c..4038edd8883 100644
--- a/src/emu/debug/debugcpu.c
+++ b/src/emu/debug/debugcpu.c
@@ -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!");
/* allocate breakpoint */
- bp = alloc_or_die(debug_cpu_breakpoint);
+ bp = auto_alloc(device->machine, debug_cpu_breakpoint);
bp->index = global->bpindex++;
bp->enabled = TRUE;
bp->address = address;
@@ -986,7 +986,7 @@ int debug_cpu_breakpoint_set(const device_config *device, offs_t address, parsed
bp->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);
}
@@ -1027,8 +1027,8 @@ int debug_cpu_breakpoint_clear(running_machine *machine, int bpnum)
if (bp->condition != NULL)
expression_free(bp->condition);
if (bp->action != NULL)
- free(bp->action);
- free(bp);
+ auto_free(machine, bp->action);
+ auto_free(machine, bp);
/* update the flags */
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;
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 */
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;
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);
}
@@ -1138,8 +1138,8 @@ int debug_cpu_watchpoint_clear(running_machine *machine, int wpnum)
if (wp->condition != NULL)
expression_free(wp->condition);
if (wp->action != NULL)
- free(wp->action);
- free(wp);
+ auto_free(machine, wp->action);
+ auto_free(machine, wp);
watchpoint_update_flags(cpu_get_address_space(cpu, spacenum));
return TRUE;
@@ -1231,7 +1231,7 @@ void debug_cpu_trace(const device_config *device, FILE *file, int trace_over, co
info->trace.file = NULL;
if (info->trace.action != NULL)
- free(info->trace.action);
+ auto_free(device->machine, info->trace.action);
info->trace.action = NULL;
/* 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;
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);
}
@@ -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 (info->hotspots)
- free(info->hotspots);
+ auto_free(device->machine, info->hotspots);
info->hotspots = NULL;
/* only start tracking if we have a non-zero count */
if (numspots > 0)
{
/* 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);
/* fill in the info */
@@ -1937,7 +1937,7 @@ static void debug_cpu_exit(running_machine *machine)
if (info->trace.file != NULL)
fclose(info->trace.file);
if (info->trace.action != NULL)
- free(info->trace.action);
+ auto_free(machine, info->trace.action);
/* free the symbol table */
if (info->symtable != NULL)
diff --git a/src/emu/debug/debugvw.c b/src/emu/debug/debugvw.c
index 8553d050ee4..7602df76e40 100644
--- a/src/emu/debug/debugvw.c
+++ b/src/emu/debug/debugvw.c
@@ -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));
/* allocate memory for the view */
- view = (debug_view *)malloc(sizeof(*view));
- if (view == NULL)
- return NULL;
- memset(view, 0, sizeof(*view));
+ view = auto_alloc_clear(machine, debug_view);
/* set the view type information */
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 */
view->viewdata_size = view->visible.y * view->visible.x;
- view->viewdata = (debug_view_char *)malloc(sizeof(view->viewdata[0]) * view->viewdata_size);
- if (view->viewdata == NULL)
- {
- free(view);
- return NULL;
- }
+ view->viewdata = auto_alloc_array(machine, debug_view_char, view->viewdata_size);
/* allocate extra memory */
if (view->cb.alloc != NULL && !(*view->cb.alloc)(view))
{
- free(view->viewdata);
- free(view);
+ auto_free(machine, view->viewdata);
+ auto_free(machine, view);
return NULL;
}
@@ -450,8 +442,8 @@ void debug_view_free(debug_view *view)
if (view->cb.free != NULL)
(*view->cb.free)(view);
if (view->viewdata != NULL)
- free(view->viewdata);
- free(view);
+ auto_free(view->machine, view->viewdata);
+ auto_free(view->machine, view);
break;
}
}
@@ -497,7 +489,8 @@ void debug_view_end_update(debug_view *view)
if (size > view->viewdata_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 */
@@ -906,10 +899,7 @@ static int textbuf_view_alloc(debug_view *view, text_buffer *textbuf)
debug_view_textbuf *textdata;
/* allocate memory */
- textdata = (debug_view_textbuf *)malloc(sizeof(*textdata));
- if (textdata == NULL)
- return FALSE;
- memset(textdata, 0, sizeof(*textdata));
+ textdata = auto_alloc_clear(view->machine, debug_view_textbuf);
/* by default we track live */
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;
/* free any memory we callocated */
- if (textdata != NULL)
- free(textdata);
+ auto_free(view->machine, textdata);
view->extra_data = NULL;
}
@@ -1084,10 +1073,7 @@ static int registers_view_alloc(debug_view *view)
return FALSE;
/* allocate memory */
- regdata = (debug_view_registers *)malloc(sizeof(*regdata));
- if (regdata == NULL)
- return FALSE;
- memset(regdata, 0, sizeof(*regdata));
+ regdata = auto_alloc_clear(view->machine, debug_view_registers);
/* default to the first subview */
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 */
if (regdata != NULL)
- free(regdata);
+ auto_free(view->machine, regdata);
view->extra_data = NULL;
}
@@ -1556,10 +1542,7 @@ static int disasm_view_alloc(debug_view *view)
return FALSE;
/* allocate disasm */
- dasmdata = (debug_view_disasm *)malloc(sizeof(*dasmdata));
- if (dasmdata == NULL)
- return FALSE;
- memset(dasmdata, 0, sizeof(*dasmdata));
+ dasmdata = auto_alloc_clear(view->machine, debug_view_disasm);
/* default to the first subview */
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);
if (dasmdata->byteaddress != NULL)
- free(dasmdata->byteaddress);
+ auto_free(view->machine, dasmdata->byteaddress);
if (dasmdata->dasm != NULL)
- free(dasmdata->dasm);
- free(dasmdata);
+ auto_free(view->machine, dasmdata->dasm);
+ auto_free(view->machine, dasmdata);
}
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;
/* allocate address array */
- if (dasmdata->byteaddress != NULL)
- free(dasmdata->byteaddress);
- dasmdata->byteaddress = alloc_array_or_die(offs_t, dasmdata->allocated.y);
+ auto_free(view->machine, dasmdata->byteaddress);
+ dasmdata->byteaddress = auto_alloc_array(view->machine, offs_t, dasmdata->allocated.y);
/* allocate disassembly buffer */
- if (dasmdata->dasm != NULL)
- free(dasmdata->dasm);
- dasmdata->dasm = alloc_array_or_die(char, dasmdata->allocated.x * dasmdata->allocated.y);
+ auto_free(view->machine, dasmdata->dasm);
+ dasmdata->dasm = auto_alloc_array(view->machine, char, dasmdata->allocated.x * dasmdata->allocated.y);
}
/* 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);
else
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 */
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 */
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 */
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 */
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 */
subview->next = NULL;
@@ -2516,7 +2497,7 @@ static int memory_view_alloc(debug_view *view)
return FALSE;
/* allocate memory */
- memdata = alloc_clear_or_die(debug_view_memory);
+ memdata = auto_alloc_clear(view->machine, debug_view_memory);
memdata->subviewlist = subviews;
/* 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;
memdata->subviewlist = item->next;
- free(item);
+ auto_free(view->machine, item);
}
debug_view_expression_free(&memdata->expression);
- free(memdata);
+ auto_free(view->machine, memdata);
}
view->extra_data = NULL;
}
diff --git a/src/emu/debug/express.c b/src/emu/debug/express.c
index 099c01506b9..434e2c83090 100644
--- a/src/emu/debug/express.c
+++ b/src/emu/debug/express.c
@@ -1978,7 +1978,7 @@ int symtable_add(symbol_table *table, const char *name, const symbol_entry *entr
int strindex;
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 */
all_digits = TRUE;
@@ -1990,7 +1990,7 @@ int symtable_add(symbol_table *table, const char *name, const symbol_entry *entr
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 */
oldentry = (symbol_entry *)symtable_find(table, name);
diff --git a/src/emu/debug/express.h b/src/emu/debug/express.h
index 3baf8f4a4cd..3cd9c1db930 100644
--- a/src/emu/debug/express.h
+++ b/src/emu/debug/express.h
@@ -10,7 +10,7 @@
#ifndef __EXPRESS_H__
#define __EXPRESS_H__
-#include "mamecore.h"
+#include "osdcore.h"
/***************************************************************************
CONSTANTS
diff --git a/src/emu/debug/textbuf.c b/src/emu/debug/textbuf.c
index 3ad15b1b159..0576ff4f642 100644
--- a/src/emu/debug/textbuf.c
+++ b/src/emu/debug/textbuf.c
@@ -9,7 +9,7 @@
***************************************************************************/
-#include "mamecore.h"
+#include "osdcore.h"
#include "textbuf.h"
diff --git a/src/emu/debugger.c b/src/emu/debugger.c
index 3e8625bd03e..d88d089331c 100644
--- a/src/emu/debugger.c
+++ b/src/emu/debugger.c
@@ -75,7 +75,7 @@ void debugger_init(running_machine *machine)
/* allocate a new entry for our global list */
add_exit_callback(machine, debugger_exit);
- entry = alloc_or_die(machine_entry);
+ entry = global_alloc(machine_entry);
entry->next = machine_list;
entry->machine = machine;
machine_list = entry;
@@ -117,7 +117,7 @@ static void debugger_exit(running_machine *machine)
{
machine_entry *deleteme = *entryptr;
*entryptr = deleteme->next;
- free(deleteme);
+ global_free(deleteme);
break;
}
}
@@ -137,6 +137,6 @@ void debugger_flush_all_traces_on_abnormal_exit(void)
machine_entry *deleteme = machine_list;
debug_cpu_flush_traces(deleteme->machine);
machine_list = deleteme->next;
- free(deleteme);
+ global_free(deleteme);
}
}
diff --git a/src/emu/deprecat.h b/src/emu/deprecat.h
index 68abaaeb34a..5c01d54df04 100644
--- a/src/emu/deprecat.h
+++ b/src/emu/deprecat.h
@@ -15,7 +15,7 @@
#ifndef __DEPRECAT_H__
#define __DEPRECAT_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "devintrf.h"
diff --git a/src/emu/devintrf.c b/src/emu/devintrf.c
index 0512f246afd..a8a6b95a3d9 100644
--- a/src/emu/devintrf.c
+++ b/src/emu/devintrf.c
@@ -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);
/* 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 */
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->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 */
device->machine = NULL;
@@ -260,8 +260,8 @@ void device_list_remove(device_list *devlist, const char *tag)
/* free the device object */
if (device->inline_config != NULL)
- free(device->inline_config);
- free(device);
+ global_free(device->inline_config);
+ 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));
/* 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 */
device->region = memory_region(machine, device->tag);
@@ -741,8 +741,7 @@ static void device_list_stop(running_machine *machine)
(*stop)(device);
/* free allocated memory for the token */
- if (device->token != NULL)
- free(device->token);
+ auto_free(machine, device->token);
/* reset all runtime fields */
device->token = NULL;
diff --git a/src/emu/devintrf.h b/src/emu/devintrf.h
index 5c066c79c51..d238dd90dca 100644
--- a/src/emu/devintrf.h
+++ b/src/emu/devintrf.h
@@ -14,7 +14,7 @@
#ifndef __DEVINTRF_H__
#define __DEVINTRF_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "romload.h"
#include "memory.h"
#include "tagmap.h"
diff --git a/src/emu/drawgfx.c b/src/emu/drawgfx.c
index 522305b2c41..e633d77ffd6 100644
--- a/src/emu/drawgfx.c
+++ b/src/emu/drawgfx.c
@@ -227,7 +227,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c
gfx_element *gfx;
/* 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 */
gfx->width = width;
@@ -256,7 +256,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c
}
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);
gfx->layout.extxoffs = buffer;
}
@@ -271,7 +271,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c
}
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);
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 */
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 */
- 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));
/* 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;
/* 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;
@@ -338,17 +338,12 @@ void gfx_element_free(gfx_element *gfx)
return;
/* free our data */
- if (gfx->layout.extyoffs != NULL)
- free((void *)gfx->layout.extyoffs);
- if (gfx->layout.extxoffs != NULL)
- free((void *)gfx->layout.extxoffs);
- if (gfx->pen_usage != NULL)
- free(gfx->pen_usage);
- if (gfx->dirty != NULL)
- free(gfx->dirty);
- if (!(gfx->flags & GFX_ELEMENT_DONT_FREE))
- free(gfx->gfxdata);
- free(gfx);
+ auto_free(gfx->machine, gfx->layout.extyoffs);
+ auto_free(gfx->machine, gfx->layout.extxoffs);
+ auto_free(gfx->machine, gfx->pen_usage);
+ auto_free(gfx->machine, gfx->dirty);
+ auto_free(gfx->machine, gfx->gfxdata);
+ auto_free(gfx->machine, gfx);
}
diff --git a/src/emu/drawgfx.h b/src/emu/drawgfx.h
index 0ef35862474..a588fbc61eb 100644
--- a/src/emu/drawgfx.h
+++ b/src/emu/drawgfx.h
@@ -14,7 +14,7 @@
#ifndef __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
{
UINT16 width; /* current pixel width of each element (changeble with source clipping) */
diff --git a/src/emu/driver.c b/src/emu/driver.c
index 522c270fef3..c22ca41b735 100644
--- a/src/emu/driver.c
+++ b/src/emu/driver.c
@@ -114,7 +114,7 @@ void driver_list_get_approx_matches(const game_driver * const driverlist[], cons
int shufnum;
/* 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 */
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++)
list[matchnum] = templist[matchnum % driver_count];
- free((void *)templist);
+ global_free(templist);
return;
}
/* allocate some temp memory */
- penalty = alloc_array_or_die(int, matches);
+ penalty = global_alloc_array(int, matches);
/* initialize everyone's states */
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(penalty);
+ global_free(penalty);
}
diff --git a/src/emu/driver.h b/src/emu/driver.h
index 88fa88fbb68..9f805d13a10 100644
--- a/src/emu/driver.h
+++ b/src/emu/driver.h
@@ -169,7 +169,7 @@ typedef UINT32 (*video_update_func)(const device_config *screen, bitmap_t *bitma
TYPE DEFINITIONS
***************************************************************************/
-/* In mamecore.h: typedef struct _game_driver game_driver; */
+/* In emucore.h: typedef struct _game_driver game_driver; */
struct _game_driver
{
const char * source_file; /* set this to __FILE__ */
diff --git a/src/emu/emu.mak b/src/emu/emu.mak
index d7fab1dc404..ef9097bd0fb 100644
--- a/src/emu/emu.mak
+++ b/src/emu/emu.mak
@@ -48,6 +48,8 @@ EMUOBJS = \
$(EMUOBJ)/devintrf.o \
$(EMUOBJ)/drawgfx.o \
$(EMUOBJ)/driver.o \
+ $(EMUOBJ)/emualloc.o \
+ $(EMUOBJ)/emucore.o \
$(EMUOBJ)/emuopts.o \
$(EMUOBJ)/emupal.o \
$(EMUOBJ)/fileio.o \
@@ -57,7 +59,6 @@ EMUOBJS = \
$(EMUOBJ)/inputseq.o \
$(EMUOBJ)/inptport.o \
$(EMUOBJ)/mame.o \
- $(EMUOBJ)/mamecore.o \
$(EMUOBJ)/mconfig.o \
$(EMUOBJ)/memory.o \
$(EMUOBJ)/output.o \
@@ -65,7 +66,6 @@ EMUOBJS = \
$(EMUOBJ)/rendfont.o \
$(EMUOBJ)/rendlay.o \
$(EMUOBJ)/rendutil.o \
- $(EMUOBJ)/restrack.o \
$(EMUOBJ)/romload.o \
$(EMUOBJ)/sound.o \
$(EMUOBJ)/state.o \
diff --git a/src/emu/mamecore.c b/src/emu/emucore.c
index 55b6b8a1edb..869e68949ba 100644
--- a/src/emu/mamecore.c
+++ b/src/emu/emucore.c
@@ -2,7 +2,7 @@
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.
Copyright Nicola Salmoria and the MAME Team.
@@ -10,7 +10,7 @@
****************************************************************************/
-#include "mamecore.h"
+#include "emucore.h"
#include <ctype.h>
/* a giant string buffer for temporary strings */
diff --git a/src/emu/mamecore.h b/src/emu/emucore.h
index 94dc687f648..8ac07b50814 100644
--- a/src/emu/mamecore.h
+++ b/src/emu/emucore.h
@@ -1,6 +1,6 @@
/***************************************************************************
- mamecore.h
+ emucore.h
General core utilities and macros used throughout MAME.
@@ -20,6 +20,7 @@
#include <stdarg.h>
#include <exception>
#include "osdcomm.h"
+#include "emualloc.h"
#include "bitmap.h"
#include "coreutil.h"
#include "corestr.h"
@@ -61,7 +62,7 @@ typedef UINT32 FPTR;
/* These are forward struct declarations that are used to break
circular dependencies in the code */
-typedef struct _running_machine running_machine;
+class running_machine;
typedef struct _game_driver game_driver;
typedef struct _machine_config machine_config;
typedef struct _gfx_element gfx_element;
@@ -176,6 +177,14 @@ enum
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 */
#ifdef __cplusplus
#define DECLARE_ENUM_OPERATORS(type) \
@@ -193,11 +202,11 @@ inline void operator--(type &value, int) { value = (type)((int)value - 1); }
#undef assert_always
#ifdef MAME_DEBUG
-#define assert(x) do { if (!(x)) 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(x) do { if (!(x)) throw emu_fatalerror("assert: %s:%d: %s", __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
-#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(x) do { } while (0)
+#define assert_always(x, msg) do { if (!(x)) throw emu_fatalerror("Fatal error: %s (%s:%d)", msg, __FILE__, __LINE__); } while (0)
#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
-class emu_exception : public std::exception
-{
-};
+class emu_exception : public std::exception { };
// emu_fatalerror is a generic fatal exception that provides an error string
diff --git a/src/emu/emuopts.c b/src/emu/emuopts.c
index 90179d8bc1f..e8c32bc40a5 100644
--- a/src/emu/emuopts.c
+++ b/src/emu/emuopts.c
@@ -9,7 +9,7 @@
***************************************************************************/
-#include "mamecore.h"
+#include "emucore.h"
#include "mame.h"
#include "fileio.h"
#include "emuopts.h"
diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h
index c7b6ac06510..1a55ecfb58b 100644
--- a/src/emu/emuopts.h
+++ b/src/emu/emuopts.h
@@ -14,7 +14,7 @@
#ifndef __EMUOPTS_H__
#define __EMUOPTS_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "options.h"
diff --git a/src/emu/fileio.c b/src/emu/fileio.c
index 73fedb4c384..7cf8cc19d1f 100644
--- a/src/emu/fileio.c
+++ b/src/emu/fileio.c
@@ -191,9 +191,7 @@ file_error mame_fopen_ram(const void *data, UINT32 length, UINT32 openflags, mam
file_error filerr;
/* allocate the file itself */
- *file = (mame_file *)malloc(sizeof(**file));
- if (*file == NULL)
- return FILERR_OUT_OF_MEMORY;
+ *file = global_alloc(mame_file);
/* reset the file handle */
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;
/* allocate the file itself */
- *file = (mame_file *)malloc(sizeof(**file));
- if (*file == NULL)
- return FILERR_OUT_OF_MEMORY;
+ *file = global_alloc(mame_file);
/* reset the file handle */
memset(*file, 0, sizeof(**file));
@@ -387,10 +383,10 @@ void mame_fclose(mame_file *file)
if (file->file != NULL)
core_fclose(file->file);
if (file->zipdata != NULL)
- free(file->zipdata);
+ global_free(file->zipdata);
if (file->filename != NULL)
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;
/* allocate a new mame_path */
- path = (mame_path *)malloc(sizeof(*path));
- if (path == NULL)
- return NULL;
- memset(path, 0, sizeof(*path));
+ path = global_alloc_clear(mame_path);
/* initialize the iterator */
path_iterator_init(&path->iterator, opts, searchpath);
@@ -734,7 +727,7 @@ void mame_closepath(mame_path *path)
/* free memory */
if (path->pathbuffer != NULL)
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);
/* allocate some memory */
- file->zipdata = (UINT8 *)malloc(file->ziplength);
- if (file->zipdata == NULL)
- return FILERR_OUT_OF_MEMORY;
+ file->zipdata = global_alloc_array(UINT8, file->ziplength);
/* read the data into our buffer and return */
ziperr = zip_file_decompress(file->zipfile, file->zipdata, file->ziplength);
if (ziperr != ZIPERR_NONE)
{
- free(file->zipdata);
+ global_free(file->zipdata);
file->zipdata = NULL;
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);
if (filerr != FILERR_NONE)
{
- free(file->zipdata);
+ global_free(file->zipdata);
file->zipdata = NULL;
return FILERR_FAILURE;
}
diff --git a/src/emu/fileio.h b/src/emu/fileio.h
index a4a7ced06ed..3e77fffe2d5 100644
--- a/src/emu/fileio.h
+++ b/src/emu/fileio.h
@@ -14,7 +14,7 @@
#ifndef __FILEIO_H__
#define __FILEIO_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "osdcore.h"
#include "corefile.h"
#include "mame.h"
diff --git a/src/emu/info.h b/src/emu/info.h
index b12259b80d4..09753b8ce5e 100644
--- a/src/emu/info.h
+++ b/src/emu/info.h
@@ -14,7 +14,7 @@
#ifndef __INFO_H__
#define __INFO_H__
-#include "mamecore.h"
+#include "emucore.h"
/***************************************************************************
diff --git a/src/emu/inptport.c b/src/emu/inptport.c
index 1cb9ca36005..b36ef2d8afa 100644
--- a/src/emu/inptport.c
+++ b/src/emu/inptport.c
@@ -3094,7 +3094,7 @@ static input_port_config *port_config_alloc(const input_port_config **listhead)
input_port_config *config;
/* allocate memory */
- config = alloc_clear_or_die(input_port_config);
+ config = global_alloc_clear(input_port_config);
/* add it to the tail */
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;
/* 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;
/* allocate memory */
- config = alloc_clear_or_die(input_field_config);
+ config = global_alloc_clear(input_field_config);
/* fill in the basic field values */
config->port = port;
@@ -3246,7 +3246,7 @@ static void field_config_free(input_field_config **fieldptr)
*fieldptr = (input_field_config *)field->next;
/* 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;
/* allocate memory */
- config = alloc_clear_or_die(input_setting_config);
+ config = global_alloc_clear(input_setting_config);
/* fill in the basic setting values */
config->field = field;
@@ -3290,7 +3290,7 @@ static void setting_config_free(input_setting_config **settingptr)
*settingptr = (input_setting_config *)setting->next;
/* 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;
/* allocate a new entry */
- *tailptr = alloc_clear_or_die(input_field_diplocation);
+ *tailptr = global_alloc_clear(input_field_diplocation);
entries++;
/* 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 */
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);
lastname[colon - tempbuf] = 0;
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);
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);
}
@@ -3400,13 +3400,13 @@ static void diplocation_free(input_field_diplocation **diplocptr)
/* free the name */
if (diploc->swname != NULL)
- free((void *)diploc->swname);
+ global_free(diploc->swname);
/* remove ourself from the list */
*diplocptr = (input_field_diplocation *)diploc->next;
/* 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;
/* allocate tables */
- oldtable = alloc_array_or_die(input_code, count);
- newtable = alloc_array_or_die(input_code, count);
+ oldtable = global_alloc_array(input_code, count);
+ newtable = global_alloc_array(input_code, count);
/* build up the remap table */
count = 0;
@@ -3625,8 +3625,8 @@ static void load_remap_table(running_machine *machine, xml_data_node *parentnode
}
/* release the tables */
- free(oldtable);
- free(newtable);
+ global_free(oldtable);
+ global_free(newtable);
}
}
diff --git a/src/emu/input.c b/src/emu/input.c
index 4d3690f34b5..89d19bff793 100644
--- a/src/emu/input.c
+++ b/src/emu/input.c
@@ -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);
/* 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++];
memset(device, 0, sizeof(*device));
diff --git a/src/emu/input.h b/src/emu/input.h
index 6d8dcfd062f..d1d5f55760c 100644
--- a/src/emu/input.h
+++ b/src/emu/input.h
@@ -14,7 +14,7 @@
#ifndef __INPUT_H__
#define __INPUT_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "astring.h"
diff --git a/src/emu/inputseq.c b/src/emu/inputseq.c
index 6f4afc2640a..81ec4104a40 100644
--- a/src/emu/inputseq.c
+++ b/src/emu/inputseq.c
@@ -9,8 +9,7 @@
***************************************************************************/
-#include "inputseq.h"
-#include "restrack.h"
+#include "mame.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)
{
- char *strcopy = alloc_array_or_die(char, strlen(string) + 1);
+ char *strcopy = auto_alloc_array(machine, char, strlen(string) + 1);
char *str = strcopy;
int result = FALSE;
@@ -565,7 +564,7 @@ int input_seq_from_tokens(running_machine *machine, const char *string, input_se
str = strtemp + 1;
}
- free(strcopy);
+ auto_free(machine, strcopy);
return result;
}
diff --git a/src/emu/machine/eeprom.c b/src/emu/machine/eeprom.c
index 997411a1567..b4b7d5408ea 100644
--- a/src/emu/machine/eeprom.c
+++ b/src/emu/machine/eeprom.c
@@ -323,19 +323,19 @@ static DEVICE_NVRAM( eeprom )
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++)
buffer[offs] = memory_read_byte(device->space[0], offs);
mame_fwrite(file, buffer, eeprom_bytes);
- free(buffer);
+ auto_free(device->machine, buffer);
}
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);
for (offs = 0; offs < eeprom_bytes; offs++)
memory_write_byte(device->space[0], offs, buffer[offs]);
- free(buffer);
+ auto_free(device->machine, buffer);
}
else
{
diff --git a/src/emu/machine/generic.h b/src/emu/machine/generic.h
index 5d80cd0edb7..477c6ca0a19 100644
--- a/src/emu/machine/generic.h
+++ b/src/emu/machine/generic.h
@@ -14,7 +14,7 @@
#ifndef __MACHINE_GENERIC_H__
#define __MACHINE_GENERIC_H__
-#include "mamecore.h"
+#include "emucore.h"
diff --git a/src/emu/machine/ldcore.c b/src/emu/machine/ldcore.c
index 9a1d42d2514..5336fad98e3 100644
--- a/src/emu/machine/ldcore.c
+++ b/src/emu/machine/ldcore.c
@@ -848,10 +848,15 @@ static void read_track_data(laserdisc_state *ld)
frame->lastfield = tracknum * 2 + fieldnum;
/* set the video target information */
- ldcore->videotarget = *frame->bitmap;
- ldcore->videotarget.base = BITMAP_ADDR16(&ldcore->videotarget, fieldnum, 0);
- ldcore->videotarget.height /= 2;
- ldcore->videotarget.rowpixels *= 2;
+ ldcore->videotarget.alloc = NULL;
+ ldcore->videotarget.base = BITMAP_ADDR16(frame->bitmap, fieldnum, 0);
+ ldcore->videotarget.rowpixels = frame->bitmap->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;
/* set the audio target information */
@@ -1397,15 +1402,14 @@ static void init_video(const device_config *device)
frame_data *frame = &ldcore->frame[index];
/* 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);
/* 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 = *frame->bitmap;
- frame->visbitmap->base = BITMAP_ADDR16(frame->visbitmap, 44, frame->bitmap->width * 8 / 720);
- frame->visbitmap->height -= 44;
- frame->visbitmap->width -= 2 * frame->bitmap->width * 8 / 720;
+ frame->visbitmap = auto_alloc(device->machine, bitmap_t(BITMAP_ADDR16(frame->visbitmap, 44, frame->bitmap->width * 8 / 720),
+ frame->bitmap->width - 2 * frame->bitmap->width * 8 / 720,
+ frame->bitmap->height - 44,
+ frame->bitmap->rowpixels, frame->bitmap->format));
}
/* allocate an empty frame of the same size */
diff --git a/src/emu/machine/scsi.c b/src/emu/machine/scsi.c
index 2922e1e5099..a60d2866eb8 100644
--- a/src/emu/machine/scsi.c
+++ b/src/emu/machine/scsi.c
@@ -105,7 +105,7 @@ int SCSIBase( const SCSIClass *scsiClass, int operation, void *file, INT64 intpa
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->machine = machine;
return scsiInstance;
diff --git a/src/emu/machine/scsidev.c b/src/emu/machine/scsidev.c
index 122650fdfee..9b410781f4d 100644
--- a/src/emu/machine/scsidev.c
+++ b/src/emu/machine/scsidev.c
@@ -145,7 +145,7 @@ static int scsidev_dispatch( int operation, void *file, INT64 intparm, void *ptr
return 0;
case SCSIOP_DELETE_INSTANCE:
- free( (SCSIInstance *)file );
+ auto_free( ((SCSIInstance *)file)->machine, file );
return 0;
}
return 0;
diff --git a/src/emu/mame.c b/src/emu/mame.c
index bc6d0de1134..fed4262b2c6 100644
--- a/src/emu/mame.c
+++ b/src/emu/mame.c
@@ -198,11 +198,8 @@ const char mame_disclaimer[] =
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 TIMER_CALLBACK( soft_reset );
-static void free_callback_list(callback_item **cb);
static void saveload_init(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);
/* create the machine structure and driver */
- machine = create_machine(driver);
+ machine = global_alloc(running_machine(driver));
mame = machine->mame_data;
/* start in the "pre-init phase" */
@@ -290,8 +287,6 @@ int mame_execute(core_options *options)
/* looooong term: remove this */
global_machine = machine;
- init_resource_tracking();
-
/* use try/catch for deep error recovery */
try
{
@@ -300,9 +295,6 @@ int mame_execute(core_options *options)
/* move to the init phase */
mame->current_phase = MAME_PHASE_INIT;
- /* start tracking resources for real */
- begin_resource_tracking();
-
/* if we have a logfile, set up the callback */
mame->logerror_callback_list = NULL;
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);
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 */
soft_reset(machine, NULL, 0);
@@ -356,9 +343,6 @@ int mame_execute(core_options *options)
/* and out via the exit phase */
mame->current_phase = MAME_PHASE_EXIT;
- /* stop tracking resources at this level */
- end_resource_tracking();
-
/* save the NVRAM and configuration */
sound_mute(machine, TRUE);
nvram_save(machine);
@@ -371,7 +355,7 @@ int mame_execute(core_options *options)
if (fatal.exitcode() != 0)
error = fatal.exitcode();
}
- catch (emu_exception &exception)
+ catch (emu_exception &)
{
mame_printf_error("Caught unhandled emulator exception\n");
error = MAMERR_FATALERROR;
@@ -386,19 +370,10 @@ int mame_execute(core_options *options)
for (cb = mame->exit_callback_list; cb; cb = cb->next)
(*cb->func.exit)(machine);
- /* close all inner resource tracking */
- exit_resource_tracking();
-
/* close the logfile */
if (mame->logfile != NULL)
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 */
if (mame->new_driver_pending != NULL)
{
@@ -408,7 +383,7 @@ int mame_execute(core_options *options)
exit_pending = mame->exit_pending;
/* destroy the machine */
- destroy_machine(machine);
+ global_free(machine);
/* reset the options */
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!");
/* allocate memory */
- cb = alloc_or_die(callback_item);
+ cb = auto_alloc(machine, callback_item);
/* add us to the end of the list */
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!");
/* allocate memory */
- cb = alloc_or_die(callback_item);
+ cb = auto_alloc(machine, callback_item);
/* add us to the end of the list */
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!");
/* allocate memory */
- cb = alloc_or_die(callback_item);
+ cb = auto_alloc(machine, callback_item);
/* add us to the end of the list */
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!");
/* allocate memory */
- cb = alloc_or_die(callback_item);
+ cb = auto_alloc(machine, callback_item);
/* add us to the head of the list */
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);
/* 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->name = astring_dupc(name);
info->length = length;
@@ -835,7 +810,7 @@ void memory_region_free(running_machine *machine, const char *name)
/* free the region */
astring_free(info->name);
- free(info);
+ auto_free(machine, info);
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
-------------------------------------------------*/
-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;
-
- /* 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)
+ try
{
- machine->driver_data = malloc(machine->config->driver_data_size);
- if (machine->driver_data == NULL)
- goto error;
- memset(machine->driver_data, 0, machine->config->driver_data_size);
- }
+ memset(&portlist, 0, sizeof(portlist));
+ memset(gfx, 0, sizeof(gfx));
+ memset(&generic, 0, sizeof(generic));
- /* find devices */
- machine->firstcpu = cpu_first(machine->config);
- machine->primary_screen = video_screen_first(machine->config);
+ /* allocate memory for the internal mame_data */
+ mame_data = auto_alloc_clear(this, mame_private);
- /* attach this machine to all the devices in the configuration */
- device_list_attach_machine(machine);
+ /* allocate memory for the memory region map */
+ mame_data->regionmap = tagmap_alloc();
+ if (mame_data->regionmap == NULL)
+ throw std::bad_alloc();
- /* 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;
+ /* initialize the driver-related variables in the machine */
+ basename = mame_strdup(driver->name);
+ config = machine_config_alloc(driver->machine_config);
- return machine;
+ /* allocate the driver data */
+ if (config->driver_data_size != 0)
+ driver_data = auto_alloc_array_clear(this, UINT8, config->driver_data_size);
-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;
+ /* 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);
+ }
}
/*-------------------------------------------------
- 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;
}
@@ -1555,11 +1547,6 @@ static TIMER_CALLBACK( soft_reset )
/* temporarily in the reset phase */
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 */
for (cb = machine->mame_data->reset_callback_list; cb; cb = cb->next)
(*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
diff --git a/src/emu/mame.h b/src/emu/mame.h
index 22537879529..65c38c295be 100644
--- a/src/emu/mame.h
+++ b/src/emu/mame.h
@@ -12,10 +12,9 @@
#ifndef __MAME_H__
#define __MAME_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "video.h"
#include "crsshair.h"
-#include "restrack.h"
#include "options.h"
#include "inptport.h"
#include "cpuintrf.h"
@@ -27,6 +26,7 @@
#endif /* MESS */
+
/***************************************************************************
CONSTANTS
***************************************************************************/
@@ -115,6 +115,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
***************************************************************************/
@@ -178,9 +195,16 @@ struct _generic_pointers
/* description of the currently-running machine */
-/* typedef struct _running_machine running_machine; -- in mamecore.h */
-struct _running_machine
+class 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 */
const machine_config * config; /* points to the constructed machine_config */
input_port_list portlist; /* points to a list of input port configurations */
diff --git a/src/emu/mconfig.c b/src/emu/mconfig.c
index cfa33dc6fb8..67f36990c7e 100644
--- a/src/emu/mconfig.c
+++ b/src/emu/mconfig.c
@@ -71,7 +71,7 @@ machine_config *machine_config_alloc(const machine_config_token *tokens)
machine_config *config;
/* allocate a new configuration object */
- config = alloc_clear_or_die(machine_config);
+ config = global_alloc_clear(machine_config);
/* initialize the device list */
device_list_init(&config->devicelist, TRUE);
@@ -96,7 +96,7 @@ void machine_config_free(machine_config *config)
device_list_deinit(&config->devicelist);
/* release the configuration itself */
- free(config);
+ global_free(config);
}
diff --git a/src/emu/mconfig.h b/src/emu/mconfig.h
index 7d9cb1faa1a..b7f5d2bc34f 100644
--- a/src/emu/mconfig.h
+++ b/src/emu/mconfig.h
@@ -113,7 +113,7 @@ enum
TYPE DEFINITIONS
***************************************************************************/
-/* In mamecore.h: typedef struct _machine_config machine_config; */
+/* In emucore.h: typedef struct _machine_config machine_config; */
struct _machine_config
{
UINT32 driver_data_size; /* amount of memory needed for driver_data */
diff --git a/src/emu/memory.c b/src/emu/memory.c
index 137e86209b1..7655df3ced4 100644
--- a/src/emu/memory.c
+++ b/src/emu/memory.c
@@ -528,7 +528,7 @@ INLINE void add_bank_reference(bank_info *bank, const address_space *space)
return;
/* allocate a new entry and fill it */
- (*refptr) = alloc_or_die(bank_reference);
+ (*refptr) = auto_alloc(space->machine, bank_reference);
(*refptr)->next = NULL;
(*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;
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) */
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);
if (entry->region_string != NULL)
astring_free(entry->region_string);
- free(entry);
+ global_free(entry);
}
/* 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);
if (base == NULL)
fatalerror("memory_set_bankptr called NULL base");
- if (ALLOW_ONLY_AUTO_MALLOC_BANKS)
- validate_auto_malloc_memory(base, bank->byteend - bank->bytestart + 1);
+// if (ALLOW_ONLY_AUTO_MALLOC_BANKS)
+// validate_auto_malloc_memory(base, bank->byteend - bank->bytestart + 1);
/* set the 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++)
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 ashift = device_get_addrbus_shift(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->write.handlers[STATIC_WATCHPOINT]->bytemask = ~0;
- /* allocate memory; these aren't auto-malloc'ed as we need to expand them */
- space->read.table = alloc_array_or_die(UINT8, 1 << LEVEL1_BITS);
- space->write.table = alloc_array_or_die(UINT8, 1 << LEVEL1_BITS);
+ /* allocate memory */
+ space->read.machine = machine;
+ 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 */
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)
{
memory_private *memdata = machine->memory_data;
- address_space *space, *nextspace;
-
- /* 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);
- }
+ address_space *space;
/* 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 */
if (space->map != NULL)
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 */
@@ -2356,7 +2306,7 @@ static void map_detokenize(memory_private *memdata, address_map *map, const game
/* start a new 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;
TOKEN_GET_UINT64_UNPACK2(tokens, entry->addrstart, 32, entry->addrend, 32);
break;
@@ -2705,7 +2655,7 @@ static genf *bank_find_or_allocate(const address_space *space, const char *tag,
sprintf(name, "Bank '%s'", tag);
/* 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 */
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 (subindex >= tabledata->subtable_alloc)
{
+ UINT32 oldsize = (1 << LEVEL1_BITS) + (tabledata->subtable_alloc << LEVEL2_BITS);
tabledata->subtable_alloc += SUBTABLE_ALLOC;
- tabledata->table = (UINT8 *)realloc(tabledata->table, (1 << LEVEL1_BITS) + (tabledata->subtable_alloc << LEVEL2_BITS));
- if (!tabledata->table)
- fatalerror("error: ran out of memory allocating memory subtable");
+ UINT32 newsize = (1 << LEVEL1_BITS) + (tabledata->subtable_alloc << LEVEL2_BITS);
+
+ 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 */
@@ -3352,7 +3306,7 @@ static direct_range *direct_range_find(address_space *space, offs_t byteaddress,
if (range != NULL)
space->direct.freerangelist = range->next;
else
- range = alloc_or_die(direct_range);
+ range = auto_alloc(space->machine, direct_range);
/* fill in the range */
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;
/* 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)
memory = block + 1;
diff --git a/src/emu/memory.h b/src/emu/memory.h
index c589df2be45..408d7e1d5f1 100644
--- a/src/emu/memory.h
+++ b/src/emu/memory.h
@@ -14,7 +14,7 @@
#ifndef __MEMORY_H__
#define __MEMORY_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "tokenize.h"
#include "astring.h"
@@ -270,6 +270,7 @@ struct _address_table
UINT8 subtable_alloc; /* number of subtables allocated */
subtable_data * subtable; /* info about each subtable */
handler_data * handlers[256]; /* array of user-installed handlers */
+ running_machine * machine; /* pointer back to the machine */
};
diff --git a/src/emu/output.c b/src/emu/output.c
index ae5ff296379..86bba23e363 100644
--- a/src/emu/output.c
+++ b/src/emu/output.c
@@ -78,7 +78,7 @@ static void output_exit(running_machine *machine);
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);
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)
{
- output_item *item = alloc_or_die(output_item);
+ output_item *item = global_alloc(output_item);
UINT32 hash = get_hash(outname);
/* fill in the data */
@@ -188,14 +188,14 @@ static void output_exit(running_machine *machine)
for (notify = item->notifylist; notify != NULL; )
{
output_notify *next = notify->next;
- free(notify);
+ global_free(notify);
notify = next;
}
/* free the name and the item */
if (item->name != NULL)
- free((void *)item->name);
- free(item);
+ global_free(item->name);
+ global_free(item);
item = next;
}
@@ -203,7 +203,7 @@ static void output_exit(running_machine *machine)
for (notify = global_notifylist; notify != NULL; )
{
output_notify *next = notify->next;
- free(notify);
+ global_free(notify);
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 */
while (*headptr != NULL)
headptr = &(*headptr)->next;
- *headptr = alloc_or_die(output_notify);
+ *headptr = global_alloc(output_notify);
/* fill in the new record */
(*headptr)->next = NULL;
diff --git a/src/emu/output.h b/src/emu/output.h
index cb71a4f53a6..d0dff350d8f 100644
--- a/src/emu/output.h
+++ b/src/emu/output.h
@@ -14,7 +14,7 @@
#ifndef __OUTPUT_H__
#define __OUTPUT_H__
-#include "mamecore.h"
+#include "emucore.h"
/***************************************************************************
diff --git a/src/emu/render.c b/src/emu/render.c
index 03866274206..4f3a21d894f 100644
--- a/src/emu/render.c
+++ b/src/emu/render.c
@@ -343,7 +343,7 @@ INLINE container_item *alloc_container_item(void)
if (result != NULL)
container_item_free_list = result->next;
else
- result = alloc_or_die(container_item);
+ result = global_alloc(container_item);
memset(result, 0, sizeof(*result));
return result;
@@ -375,7 +375,7 @@ INLINE render_primitive *alloc_render_primitive(int type)
if (result != NULL)
render_primitive_free_list = result->next;
else
- result = alloc_or_die(render_primitive);
+ result = global_alloc(render_primitive);
/* clear to 0 */
memset(result, 0, sizeof(*result));
@@ -426,7 +426,7 @@ INLINE void add_render_ref(render_ref **list, void *refptr)
if (ref != NULL)
render_ref_free_list = ref->next;
else
- ref = alloc_or_die(render_ref);
+ ref = global_alloc(render_ref);
/* set the refptr and link us into the list */
ref->refptr = refptr;
@@ -620,7 +620,7 @@ static void render_exit(running_machine *machine)
{
render_texture *temp = render_texture_free_list;
render_texture_free_list = temp->next;
- free(temp);
+ global_free(temp);
}
/* free the render primitives */
@@ -628,7 +628,7 @@ static void render_exit(running_machine *machine)
{
render_primitive *temp = render_primitive_free_list;
render_primitive_free_list = temp->next;
- free(temp);
+ global_free(temp);
}
/* free the render refs */
@@ -636,7 +636,7 @@ static void render_exit(running_machine *machine)
{
render_ref *temp = render_ref_free_list;
render_ref_free_list = temp->next;
- free(temp);
+ global_free(temp);
}
/* free the container items */
@@ -644,7 +644,7 @@ static void render_exit(running_machine *machine)
{
container_item *temp = container_item_free_list;
container_item_free_list = temp->next;
- free(temp);
+ global_free(temp);
}
/* free the targets */
@@ -1072,7 +1072,7 @@ render_target *render_target_alloc(running_machine *machine, const char *layoutf
int listnum;
/* 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 */
for (nextptr = &targetlist; *nextptr != NULL; nextptr = &(*nextptr)->next) ;
@@ -1168,7 +1168,7 @@ void render_target_free(render_target *target)
}
/* 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;
/* 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 */
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 */
if (texture->bcglookup != NULL)
- free(texture->bcglookup);
+ global_free(texture->bcglookup);
/* add ourself back to the free list */
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);
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;
}
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);
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;
}
@@ -2728,7 +2734,10 @@ static const rgb_t *texture_get_adjusted_palette(render_texture *texture, render
adjusted = palette_entry_list_adjusted(texture->palette);
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;
}
@@ -2767,7 +2776,7 @@ static render_container *render_container_alloc(running_machine *machine)
int color;
/* allocate and clear memory */
- container = alloc_clear_or_die(render_container);
+ container = global_alloc_clear(render_container);
/* default values */
container->brightness = 1.0f;
@@ -2810,7 +2819,7 @@ static void render_container_free(render_container *container)
palette_client_free(container->palclient);
/* free the container itself */
- free(container);
+ global_free(container);
}
diff --git a/src/emu/rendersw.c b/src/emu/rendersw.c
index e4cea22028c..0cc49c1f585 100644
--- a/src/emu/rendersw.c
+++ b/src/emu/rendersw.c
@@ -55,7 +55,7 @@
#ifndef FIRST_TIME
#define FIRST_TIME
-#include "mamecore.h"
+#include "emucore.h"
#include "eminline.h"
#include "video/rgbutil.h"
#include "render.h"
diff --git a/src/emu/rendfont.c b/src/emu/rendfont.c
index bceeadb170e..a14ce310085 100644
--- a/src/emu/rendfont.c
+++ b/src/emu/rendfont.c
@@ -141,7 +141,7 @@ render_font *render_font_alloc(const char *filename)
render_font *font;
/* 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 */
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 */
render_font_free(font);
- font = alloc_clear_or_die(render_font);
+ font = global_alloc_clear(render_font);
/* load the raw data instead */
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(font->chars[tablenum]);
+ global_free(font->chars[tablenum]);
}
/* free the raw data and the size itself */
if (font->rawdata != NULL)
- free((void *)font->rawdata);
- free(font);
+ global_free((void *)font->rawdata);
+ 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 */
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 */
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);
}
else
- free(data);
+ global_free(data);
/* close the file */
- free(cachedname);
+ global_free(cachedname);
mame_fclose(file);
return result;
error:
/* close the file */
if (cachedname != NULL)
- free(cachedname);
+ global_free(cachedname);
if (data != NULL)
- free(data);
+ global_free(data);
mame_fclose(file);
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 (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 */
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;
/* 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);
if (bytes_read != filesize - CACHED_HEADER_SIZE)
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 (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 */
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:
if (data != NULL)
- free(data);
+ global_free(data);
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 */
- 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 */
- tempbuffer = alloc_array_or_die(UINT8, 65536);
+ tempbuffer = global_alloc_array(UINT8, 65536);
/* write the header */
dest = tempbuffer;
@@ -831,14 +831,14 @@ static int render_font_save_cached(render_font *font, const char *filename, UINT
/* all done */
mame_fclose(file);
- free(tempbuffer);
- free(chartable);
+ global_free(tempbuffer);
+ global_free(chartable);
return 0;
error:
mame_fclose(file);
osd_rmfile(filename);
- free(tempbuffer);
- free(chartable);
+ global_free(tempbuffer);
+ global_free(chartable);
return 1;
}
diff --git a/src/emu/rendlay.c b/src/emu/rendlay.c
index 357c2aca8fb..548c74f4845 100644
--- a/src/emu/rendlay.c
+++ b/src/emu/rendlay.c
@@ -217,7 +217,7 @@ INLINE void reduce_fraction(int *num, int *den)
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);
return newstring;
}
@@ -1509,7 +1509,7 @@ layout_file *layout_file_load(const machine_config *config, const char *dirname,
return NULL;
/* allocate the layout group object first */
- file = alloc_clear_or_die(layout_file);
+ file = global_alloc_clear(layout_file);
/* find the layout node */
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;
/* allocate a new element */
- element = alloc_clear_or_die(layout_element);
+ element = global_alloc_clear(layout_element);
/* extract the name */
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 */
- 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++)
{
element->elemtex[state].element = element;
@@ -1666,7 +1666,7 @@ static element_component *load_element_component(const machine_config *config, x
element_component *component;
/* allocate memory for the component */
- component = alloc_clear_or_die(element_component);
+ component = global_alloc_clear(element_component);
/* fetch common data */
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 */
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);
component->string = string;
}
@@ -1736,7 +1736,7 @@ static element_component *load_element_component(const machine_config *config, x
return component;
error:
- free(component);
+ global_free(component);
return NULL;
}
@@ -1753,7 +1753,7 @@ static layout_view *load_layout_view(const machine_config *config, xml_data_node
int layer;
/* first allocate memory */
- view = alloc_clear_or_die(layout_view);
+ view = global_alloc_clear(layout_view);
/* allocate a copy of the 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;
/* allocate a new item */
- item = alloc_clear_or_die(view_item);
+ item = global_alloc_clear(view_item);
/* allocate a copy of the output 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:
if (item->output_name != NULL)
- free((void *)item->output_name);
+ global_free(item->output_name);
if (item->input_tag != NULL)
- free((void *)item->input_tag);
- free(item);
+ global_free(item->input_tag);
+ global_free(item);
return NULL;
}
@@ -2049,7 +2049,7 @@ void layout_file_free(layout_file *file)
}
/* 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->itemlist[layer] = temp->next;
if (temp->output_name != NULL)
- free((void *)temp->output_name);
+ global_free(temp->output_name);
if (temp->input_tag != NULL)
- free((void *)temp->input_tag);
- free(temp);
+ global_free(temp->input_tag);
+ global_free(temp);
}
/* free the view itself */
if (view->name != NULL)
- free((void *)view->name);
- free(view);
+ global_free((void *)view->name);
+ global_free(view);
}
@@ -2095,16 +2095,16 @@ static void layout_element_free(layout_element *element)
element_component *temp = element->complist;
element->complist = temp->next;
if (temp->string != NULL)
- free((void *)temp->string);
+ global_free(temp->string);
if (temp->dirname != NULL)
- free((void *)temp->dirname);
+ global_free(temp->dirname);
if (temp->imagefile != NULL)
- free((void *)temp->imagefile);
+ global_free(temp->imagefile);
if (temp->alphafile != NULL)
- free((void *)temp->alphafile);
+ global_free(temp->alphafile);
if (temp->bitmap != NULL)
bitmap_free(temp->bitmap);
- free(temp);
+ global_free(temp);
}
/* free all textures */
@@ -2117,11 +2117,11 @@ static void layout_element_free(layout_element *element)
if (element->elemtex[state].texture != NULL)
render_texture_free(element->elemtex[state].texture);
- free(element->elemtex);
+ global_free(element->elemtex);
}
/* free the element itself */
if (element->name != NULL)
- free((void *)element->name);
- free(element);
+ global_free(element->name);
+ global_free(element);
}
diff --git a/src/emu/restrack.c b/src/emu/restrack.c
deleted file mode 100644
index 843fb814eea..00000000000
--- a/src/emu/restrack.c
+++ /dev/null
@@ -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;
-}
diff --git a/src/emu/restrack.h b/src/emu/restrack.h
deleted file mode 100644
index 84fed6a37d8..00000000000
--- a/src/emu/restrack.h
+++ /dev/null
@@ -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__ */
diff --git a/src/emu/romload.c b/src/emu/romload.c
index a16453abe6a..d3d4e7a6a90 100644
--- a/src/emu/romload.c
+++ b/src/emu/romload.c
@@ -760,7 +760,7 @@ static int read_rom_data(rom_load_data *romdata, const rom_entry *romp)
/* use a temporary buffer for complex loads */
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 */
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));
if (rom_fread(romdata, bufptr, bytesleft) != bytesleft)
{
- free(tempbuf);
+ auto_free(romdata->machine, tempbuf);
return 0;
}
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"));
return ROM_GETLENGTH(romp);
diff --git a/src/emu/romload.h b/src/emu/romload.h
index c10c11023eb..a18cac123c0 100644
--- a/src/emu/romload.h
+++ b/src/emu/romload.h
@@ -14,7 +14,7 @@
#ifndef __ROMLOAD_H__
#define __ROMLOAD_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "chd.h"
#include "options.h"
diff --git a/src/emu/sound.c b/src/emu/sound.c
index 34f632d6993..13ce05c91e7 100644
--- a/src/emu/sound.c
+++ b/src/emu/sound.c
@@ -346,7 +346,7 @@ static DEVICE_CUSTOM_CONFIG( sound )
/* allocate a new route */
for (routeptr = &config->routelist; *routeptr != NULL; routeptr = &(*routeptr)->next) ;
- *routeptr = alloc_or_die(sound_route);
+ *routeptr = global_alloc(sound_route);
(*routeptr)->next = NULL;
(*routeptr)->output = output;
(*routeptr)->input = input;
@@ -361,7 +361,7 @@ static DEVICE_CUSTOM_CONFIG( sound )
{
sound_route *temp = config->routelist;
config->routelist = temp->next;
- free(temp);
+ global_free(temp);
}
break;
}
diff --git a/src/emu/sound/ay8910.c b/src/emu/sound/ay8910.c
index 27cacd35899..51db7748fe5 100644
--- a/src/emu/sound/ay8910.c
+++ b/src/emu/sound/ay8910.c
@@ -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 *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 (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]); */
- 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)
diff --git a/src/emu/sound/filter.c b/src/emu/sound/filter.c
index 2996f8a28e4..960dd4e3c00 100644
--- a/src/emu/sound/filter.c
+++ b/src/emu/sound/filter.c
@@ -2,12 +2,12 @@
#include "filter.h"
static filter* filter_alloc(void) {
- filter* f = alloc_or_die(filter);
+ filter* f = global_alloc(filter);
return f;
}
void filter_free(filter* f) {
- free(f);
+ global_free(f);
}
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) {
int i;
- filter_state* s = alloc_or_die(filter_state);
+ filter_state* s = global_alloc(filter_state);
s->prev_mac = 0;
for(i=0;i<FILTER_ORDER_MAX;++i)
s->xprev[i] = 0;
@@ -28,7 +28,7 @@ filter_state* filter_state_alloc(void) {
}
void filter_state_free(filter_state* s) {
- free(s);
+ global_free(s);
}
/****************************************************************************/
diff --git a/src/emu/sound/fm.c b/src/emu/sound/fm.c
index 5c5084024e3..2c36d3154e1 100644
--- a/src/emu/sound/fm.c
+++ b/src/emu/sound/fm.c
@@ -2264,14 +2264,11 @@ void * ym2203_init(void *param, const device_config *device, int clock, int rate
YM2203 *F2203;
/* allocate ym2203 state space */
- if( (F2203 = (YM2203 *)malloc(sizeof(YM2203)))==NULL)
- return NULL;
- /* clear */
- memset(F2203,0,sizeof(YM2203));
+ F2203 = auto_alloc_clear(device->machine, YM2203);
if( !init_tables() )
{
- free( F2203 );
+ auto_free( device->machine, F2203 );
return NULL;
}
@@ -2298,7 +2295,7 @@ void ym2203_shutdown(void *chip)
YM2203 *FM2203 = (YM2203 *)chip;
FMCloseTable();
- free(FM2203);
+ auto_free(FM2203->OPN.ST.device->machine, FM2203);
}
/* YM2203 I/O interface */
@@ -3487,14 +3484,11 @@ void * ym2608_init(void *param, const device_config *device, int clock, int rate
YM2608 *F2608;
/* allocate extend state space */
- if( (F2608 = (YM2608 *)malloc(sizeof(YM2608)))==NULL)
- return NULL;
- /* clear */
- memset(F2608,0,sizeof(YM2608));
+ F2608 = auto_alloc_clear(device->machine, YM2608);
/* allocate total level table (128kb space) */
if( !init_tables() )
{
- free( F2608 );
+ auto_free( device->machine, F2608 );
return NULL;
}
@@ -3542,7 +3536,7 @@ void ym2608_shutdown(void *chip)
YM2608 *F2608 = (YM2608 *)chip;
FMCloseTable();
- free(F2608);
+ auto_free(F2608->OPN.ST.device->machine, F2608);
}
/* reset one of chips */
@@ -4172,14 +4166,11 @@ void *ym2610_init(void *param, const device_config *device, int clock, int rate,
YM2610 *F2610;
/* allocate extend state space */
- if( (F2610 = (YM2610 *)malloc(sizeof(YM2610)))==NULL)
- return NULL;
- /* clear */
- memset(F2610,0,sizeof(YM2610));
+ F2610 = auto_alloc_clear(device->machine, YM2610);
/* allocate total level table (128kb space) */
if( !init_tables() )
{
- free( F2610 );
+ auto_free( device->machine, F2610 );
return NULL;
}
@@ -4219,7 +4210,7 @@ void ym2610_shutdown(void *chip)
YM2610 *F2610 = (YM2610 *)chip;
FMCloseTable();
- free(F2610);
+ auto_free(F2610->OPN.ST.device->machine, F2610);
}
/* reset one of chip */
diff --git a/src/emu/sound/fm2612.c b/src/emu/sound/fm2612.c
index ca1a2bced34..8860ea8dc90 100644
--- a/src/emu/sound/fm2612.c
+++ b/src/emu/sound/fm2612.c
@@ -2451,14 +2451,11 @@ void * ym2612_init(void *param, const device_config *device, int clock, int rate
YM2612 *F2612;
/* allocate extend state space */
- if( (F2612 = (YM2612 *)malloc(sizeof(YM2612)))==NULL)
- return NULL;
- /* clear */
- memset(F2612,0,sizeof(YM2612));
+ F2612 = auto_alloc_clear(device->machine, YM2612);
/* allocate total level table (128kb space) */
if( !init_tables() )
{
- free( F2612 );
+ auto_free( device->machine, F2612 );
return NULL;
}
@@ -2486,7 +2483,7 @@ void ym2612_shutdown(void *chip)
YM2612 *F2612 = (YM2612 *)chip;
FMCloseTable();
- free(F2612);
+ auto_free(F2612->OPN.ST.device->machine, F2612);
}
/* reset one of chip */
diff --git a/src/emu/sound/fmopl.c b/src/emu/sound/fmopl.c
index 90dc292ca9a..05812c5f7cd 100644
--- a/src/emu/sound/fmopl.c
+++ b/src/emu/sound/fmopl.c
@@ -313,6 +313,7 @@ typedef struct fm_opl_f {
UINT32 rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */
attotime TimerBase; /* Timer base time (==sampling time)*/
+ const device_config *device;
} FM_OPL;
@@ -1978,13 +1979,7 @@ static FM_OPL *OPLCreate(const device_config *device, UINT32 clock, UINT32 rate,
#endif
/* allocate memory block */
- ptr = (char *)malloc(state_size);
-
- if (ptr==NULL)
- return NULL;
-
- /* clear */
- memset(ptr,0,state_size);
+ ptr = (char *)auto_alloc_array_clear(device->machine, UINT8, state_size);
OPL = (FM_OPL *)ptr;
@@ -1998,6 +1993,7 @@ static FM_OPL *OPLCreate(const device_config *device, UINT32 clock, UINT32 rate,
ptr += sizeof(YM_DELTAT);
#endif
+ OPL->device = device;
OPL->type = type;
OPL->clock = clock;
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)
{
OPL_UnLockTable();
- free(OPL);
+ auto_free(OPL->device->machine, OPL);
}
/* Optional handlers */
diff --git a/src/emu/sound/tiasound.c b/src/emu/sound/tiasound.c
index c686010a2d3..7d75d42b05d 100644
--- a/src/emu/sound/tiasound.c
+++ b/src/emu/sound/tiasound.c
@@ -547,10 +547,7 @@ void *tia_sound_init(int clock, int sample_rate, int gain)
struct tia *chip;
int chan;
- chip = (struct tia *)malloc(sizeof(*chip));
- if (!chip)
- return NULL;
- memset(chip, 0, sizeof(*chip));
+ chip = global_alloc_clear(struct tia);
/* set the gain factor (normally use TIA_DEFAULT_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)
{
- free(chip);
+ global_free(chip);
}
diff --git a/src/emu/sound/wavwrite.c b/src/emu/sound/wavwrite.c
index 53005fabf2d..98a392145c1 100644
--- a/src/emu/sound/wavwrite.c
+++ b/src/emu/sound/wavwrite.c
@@ -1,4 +1,4 @@
-#include "mamecore.h"
+#include "osdcore.h"
#include "sound/wavwrite.h"
struct _wav_file
diff --git a/src/emu/sound/ym2151.c b/src/emu/sound/ym2151.c
index 1e918d66479..1ce0b07fa95 100644
--- a/src/emu/sound/ym2151.c
+++ b/src/emu/sound/ym2151.c
@@ -1506,9 +1506,7 @@ void * ym2151_init(const device_config *device, int clock, int rate)
{
YM2151 *PSG;
- PSG = (YM2151 *)malloc(sizeof(YM2151));
- if (PSG == NULL)
- return NULL;
+ PSG = auto_alloc(device->machine, YM2151);
memset(PSG, 0, sizeof(YM2151));
@@ -1559,7 +1557,7 @@ void ym2151_shutdown(void *_chip)
{
YM2151 *chip = (YM2151 *)_chip;
- free (chip);
+ auto_free (chip->device->machine, chip);
if (cymfile)
fclose (cymfile);
diff --git a/src/emu/sound/ym2413.c b/src/emu/sound/ym2413.c
index 4988348bfeb..cb21173c85a 100644
--- a/src/emu/sound/ym2413.c
+++ b/src/emu/sound/ym2413.c
@@ -263,6 +263,7 @@ typedef struct {
int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */
+ const device_config *device;
} YM2413;
/* key scale level */
@@ -2002,26 +2003,14 @@ static void OPLLResetChip(YM2413 *chip)
/* 'rate' is sampling rate */
static YM2413 *OPLLCreate(const device_config *device, int clock, int rate)
{
- char *ptr;
YM2413 *chip;
- int state_size;
if (OPLL_LockTable(device) == -1) return NULL;
- /* calculate chip state size */
- state_size = sizeof(YM2413);
-
/* allocate memory block */
- ptr = (char *)malloc(state_size);
-
- if (ptr==NULL)
- return NULL;
-
- /* clear */
- memset(ptr,0,state_size);
-
- chip = (YM2413 *)ptr;
+ chip = auto_alloc_clear(device->machine, YM2413);
+ chip->device = device;
chip->clock = clock;
chip->rate = rate;
@@ -2037,7 +2026,7 @@ static YM2413 *OPLLCreate(const device_config *device, int clock, int rate)
static void OPLLDestroy(YM2413 *chip)
{
OPLL_UnLockTable();
- free(chip);
+ auto_free(chip->device->machine, chip);
}
/* Option handlers */
diff --git a/src/emu/sound/ymf262.c b/src/emu/sound/ymf262.c
index ad0306e6437..7a9c39c0dbc 100644
--- a/src/emu/sound/ymf262.c
+++ b/src/emu/sound/ymf262.c
@@ -268,6 +268,7 @@ typedef struct {
int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */
attotime TimerBase; /* Timer base time (==sampling time)*/
+ const device_config *device;
} 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;
/* allocate memory block */
- chip = (OPL3 *)malloc(sizeof(OPL3));
-
- if (chip==NULL)
- return NULL;
-
- /* clear */
- memset(chip, 0, sizeof(OPL3));
+ chip = auto_alloc_clear(device->machine, OPL3);
+ chip->device = device;
chip->type = type;
chip->clock = clock;
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)
{
OPL3_UnLockTable();
- free(chip);
+ auto_free(chip->device->machine, chip);
}
diff --git a/src/emu/state.h b/src/emu/state.h
index 47be8c350b3..bb1c5a0ae29 100644
--- a/src/emu/state.h
+++ b/src/emu/state.h
@@ -14,7 +14,7 @@
#ifndef __STATE_H__
#define __STATE_H__
-#include "mamecore.h"
+#include "emucore.h"
diff --git a/src/emu/streams.c b/src/emu/streams.c
index 2628b40d5f6..24bedbf56a6 100644
--- a/src/emu/streams.c
+++ b/src/emu/streams.c
@@ -723,15 +723,20 @@ static void allocate_resample_buffers(running_machine *machine, sound_stream *st
if (stream->resample_bufalloc < bufsize)
{
int inputnum;
+ int oldsize;
/* this becomes the new allocation size */
+ oldsize = stream->resample_bufalloc;
stream->resample_bufalloc = bufsize;
/* iterate over outputs and realloc their buffers */
for (inputnum = 0; inputnum < stream->inputs; 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++)
{
stream_output *output = &stream->output[outputnum];
- output->buffer = auto_extend_array(machine, output->buffer, stream_sample_t, stream->output_bufalloc);
- memset(&output->buffer[oldsize], 0, (stream->output_bufalloc - oldsize) * sizeof(output->buffer[0]));
+ stream_sample_t *newbuffer = auto_alloc_array(machine, stream_sample_t, stream->output_bufalloc);
+ memcpy(newbuffer, output->buffer, oldsize * sizeof(stream_sample_t));
+ delete[] output->buffer;
+ output->buffer = newbuffer;
}
}
}
diff --git a/src/emu/streams.h b/src/emu/streams.h
index 06f78faec0d..772c01d834b 100644
--- a/src/emu/streams.h
+++ b/src/emu/streams.h
@@ -12,7 +12,7 @@
#ifndef STREAMS_H
#define STREAMS_H
-#include "mamecore.h"
+#include "emucore.h"
/***************************************************************************
diff --git a/src/emu/tilemap.c b/src/emu/tilemap.c
index a4dbf235751..0e895954255 100644
--- a/src/emu/tilemap.c
+++ b/src/emu/tilemap.c
@@ -349,7 +349,7 @@ static tilemap_t *tilemap_create_common(running_machine *machine, void *get_info
tilemap_instance = machine->tilemap_data->instance;
/* allocate the tilemap itself */
- tmap = alloc_clear_or_die(tilemap_t);
+ tmap = auto_alloc_clear(machine, tilemap_t);
/* fill in the basic metrics */
tmap->machine = machine;
@@ -379,16 +379,16 @@ static tilemap_t *tilemap_create_common(running_machine *machine, void *get_info
/* initialize scroll information */
tmap->scrollrows = 1;
tmap->scrollcols = 1;
- tmap->rowscroll = alloc_array_clear_or_die(INT32, tmap->height);
- tmap->colscroll = alloc_array_clear_or_die(INT32, tmap->width);
+ tmap->rowscroll = auto_alloc_array_clear(machine, INT32, tmap->height);
+ tmap->colscroll = auto_alloc_array_clear(machine, INT32, tmap->width);
/* 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 */
- tmap->tileflags = alloc_array_or_die(UINT8, tmap->max_logical_index);
- tmap->flagsmap = bitmap_alloc(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->tileflags = auto_alloc_array(machine, UINT8, tmap->max_logical_index);
+ tmap->flagsmap = auto_bitmap_alloc(machine, tmap->width, tmap->height, BITMAP_FORMAT_INDEXED8);
+ 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++)
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(tmap->pen_to_flags);
- free(tmap->tileflags);
- bitmap_free(tmap->flagsmap);
- bitmap_free(tmap->pixmap);
- free(tmap->colscroll);
- free(tmap->rowscroll);
- free(tmap->logical_to_memory);
- free(tmap->memory_to_logical);
- free(tmap);
+ auto_free(tmap->machine, tmap->pen_to_flags);
+ auto_free(tmap->machine, tmap->tileflags);
+ auto_free(tmap->machine, tmap->flagsmap);
+ auto_free(tmap->machine, tmap->pixmap);
+ auto_free(tmap->machine, tmap->colscroll);
+ auto_free(tmap->machine, tmap->rowscroll);
+ auto_free(tmap->machine, tmap->logical_to_memory);
+ auto_free(tmap->machine, tmap->memory_to_logical);
+ auto_free(tmap->machine, tmap);
}
@@ -1195,8 +1195,8 @@ static void mappings_create(tilemap_t *tmap)
tmap->max_memory_index++;
/* allocate the necessary mappings */
- tmap->memory_to_logical = alloc_array_or_die(tilemap_logical_index, tmap->max_memory_index);
- tmap->logical_to_memory = alloc_array_or_die(tilemap_memory_index, tmap->max_logical_index);
+ tmap->memory_to_logical = auto_alloc_array(tmap->machine, tilemap_logical_index, tmap->max_memory_index);
+ tmap->logical_to_memory = auto_alloc_array(tmap->machine, tilemap_memory_index, tmap->max_logical_index);
/* update the mappings */
mappings_update(tmap);
diff --git a/src/emu/tilemap.h b/src/emu/tilemap.h
index 1df7a88df13..cd325da30d3 100644
--- a/src/emu/tilemap.h
+++ b/src/emu/tilemap.h
@@ -297,7 +297,7 @@
#ifndef __TILEMAP_H__
#define __TILEMAP_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "drawgfx.h"
diff --git a/src/emu/timer.c b/src/emu/timer.c
index 4c2ff3d5ec9..a62f88b546f 100644
--- a/src/emu/timer.c
+++ b/src/emu/timer.c
@@ -12,7 +12,6 @@
#include "driver.h"
#include "profiler.h"
-#include "pool.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))
fatalerror("timer_alloc() called after save state registration closed! (file %s, line %d)\n", file, line);
timer_register_save(timer);
- restrack_register_object(OBJTYPE_TIMER, timer, 0, file, line);
}
/* return a handle */
diff --git a/src/emu/timer.h b/src/emu/timer.h
index ce62752e845..d49dbce15ad 100644
--- a/src/emu/timer.h
+++ b/src/emu/timer.h
@@ -15,7 +15,7 @@
#ifndef __TIMER_H__
#define __TIMER_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "devintrf.h"
#include "attotime.h"
diff --git a/src/emu/ui.h b/src/emu/ui.h
index 9accd38fd82..153ca711a4d 100644
--- a/src/emu/ui.h
+++ b/src/emu/ui.h
@@ -14,7 +14,7 @@
#ifndef __USRINTRF_H__
#define __USRINTRF_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "render.h"
#include "unicode.h"
diff --git a/src/emu/uigfx.h b/src/emu/uigfx.h
index 3fd2387b332..a19188d1007 100644
--- a/src/emu/uigfx.h
+++ b/src/emu/uigfx.h
@@ -14,7 +14,7 @@
#ifndef __UIGFX_H__
#define __UIGFX_H__
-#include "mamecore.h"
+#include "emucore.h"
/***************************************************************************
diff --git a/src/emu/uiinput.h b/src/emu/uiinput.h
index fad20937bb3..75907085fa2 100644
--- a/src/emu/uiinput.h
+++ b/src/emu/uiinput.h
@@ -14,7 +14,7 @@
#ifndef __UIINPUT_H__
#define __UIINPUT_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "render.h"
#include "unicode.h"
diff --git a/src/emu/uimenu.c b/src/emu/uimenu.c
index 3818aee4da5..d804f9b5850 100644
--- a/src/emu/uimenu.c
+++ b/src/emu/uimenu.c
@@ -385,7 +385,7 @@ void ui_menu_init(running_machine *machine)
ui_menu_stack_reset(machine);
/* 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++)
{
int alpha = 0xff;
@@ -416,7 +416,6 @@ static void ui_menu_exit(running_machine *machine)
/* free textures */
render_texture_free(hilight_texture);
- bitmap_free(hilight_bitmap);
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;
/* 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 */
menu->machine = machine;
@@ -459,23 +458,23 @@ void ui_menu_free(ui_menu *menu)
{
ui_menu_pool *pool = menu->pool;
menu->pool = pool->next;
- free(pool);
+ auto_free(menu->machine, pool);
}
/* free the item array */
if (menu->item != NULL)
- free(menu->item);
+ auto_free(menu->machine, menu->item);
/* free the state */
if (menu->state != NULL)
{
if (menu->destroy_state != NULL)
(*menu->destroy_state)(menu, menu->state);
- free(menu->state);
+ auto_free(menu->machine, menu->state);
}
/* 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 */
if (menu->numitems >= menu->allocitems)
{
+ int olditems = menu->allocitems;
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++;
@@ -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)
(*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;
return menu->state;
@@ -666,7 +670,7 @@ void *ui_menu_pool_alloc(ui_menu *menu, size_t size)
}
/* 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 */
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_result = audit_summary(driver, audit_records, audit, FALSE);
if (audit_records > 0)
- free(audit);
+ global_free(audit);
/* if everything looks good, schedule the new driver */
if (audit_result == CORRECT || audit_result == BEST_AVAILABLE)
diff --git a/src/emu/uimenu.h b/src/emu/uimenu.h
index 2017fc9ed5b..cbf7a0dbc2b 100644
--- a/src/emu/uimenu.h
+++ b/src/emu/uimenu.h
@@ -14,7 +14,7 @@
#ifndef __UIMENU_H__
#define __UIMENU_H__
-#include "mamecore.h"
+#include "emucore.h"
/***************************************************************************
diff --git a/src/emu/validity.c b/src/emu/validity.c
index 595c534c1b1..906b3cf95f0 100644
--- a/src/emu/validity.c
+++ b/src/emu/validity.c
@@ -1488,8 +1488,6 @@ int mame_validitychecks(const game_driver *curdriver)
/* validate inline function behavior */
error = validate_inlines() || error;
- init_resource_tracking();
- begin_resource_tracking();
get_profile_ticks();
/* pre-populate the defstr tagmap with all the default strings */
@@ -1590,9 +1588,6 @@ int mame_validitychecks(const game_driver *curdriver)
#endif
#endif
- end_resource_tracking();
- exit_resource_tracking();
-
tagmap_free(defstr);
tagmap_free(roms);
tagmap_free(descriptions);
diff --git a/src/emu/validity.h b/src/emu/validity.h
index 314869e2fd2..66b512b4249 100644
--- a/src/emu/validity.h
+++ b/src/emu/validity.h
@@ -11,7 +11,7 @@
#pragma once
-#include "mamecore.h"
+#include "emucore.h"
#ifndef __VALIDITY_H__
#define __VALIDITY_H__
diff --git a/src/emu/video.h b/src/emu/video.h
index 362d8f5f238..466e214b76e 100644
--- a/src/emu/video.h
+++ b/src/emu/video.h
@@ -14,7 +14,7 @@
#ifndef __VIDEO_H__
#define __VIDEO_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "devintrf.h"
#include "timer.h"
#include "render.h"
diff --git a/src/emu/video/generic.h b/src/emu/video/generic.h
index 75d5261295c..e6f50fff8c1 100644
--- a/src/emu/video/generic.h
+++ b/src/emu/video/generic.h
@@ -14,7 +14,7 @@
#ifndef __VIDEO_GENERIC_H__
#define __VIDEO_GENERIC_H__
-#include "mamecore.h"
+#include "emucore.h"
diff --git a/src/emu/video/poly.c b/src/emu/video/poly.c
index f94927e66e9..995d33aa070 100644
--- a/src/emu/video/poly.c
+++ b/src/emu/video/poly.c
@@ -203,8 +203,7 @@ struct _poly_manager
FUNCTION PROTOTYPES
***************************************************************************/
-static void **allocate_array(size_t *itemsize, UINT32 itemcount);
-static void free_array(void **array);
+static void **allocate_array(running_machine *machine, size_t *itemsize, UINT32 itemcount);
static void *poly_item_callback(void *param, int threadid);
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;
/* allocate the manager itself */
- poly = alloc_clear_or_die(poly_manager);
+ poly = auto_alloc_clear(machine, poly_manager);
poly->flags = flags;
/* allocate polygons */
poly->polygon_size = sizeof(polygon_info);
poly->polygon_count = MAX(max_polys, 1);
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 */
poly->extra_size = extra_data_size;
poly->extra_count = poly->polygon_count;
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 */
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_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 */
if (!(flags & POLYFLAG_NO_WORK_QUEUE))
@@ -394,14 +393,6 @@ void poly_free(poly_manager *poly)
/* free the work queue */
if (poly->queue != NULL)
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
-------------------------------------------------*/
-static void **allocate_array(size_t *itemsize, UINT32 itemcount)
+static void **allocate_array(running_machine *machine, size_t *itemsize, UINT32 itemcount)
{
void **ptrarray;
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;
/* allocate the array */
- ptrarray = alloc_array_clear_or_die(void *, itemcount);
+ ptrarray = auto_alloc_array_clear(machine, void *, itemcount);
/* 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 */
for (itemnum = 1; itemnum < itemcount; itemnum++)
@@ -1326,21 +1317,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
item
-------------------------------------------------*/
diff --git a/src/emu/video/poly.h b/src/emu/video/poly.h
index 866c686e5dc..eb2efd089b6 100644
--- a/src/emu/video/poly.h
+++ b/src/emu/video/poly.h
@@ -35,7 +35,7 @@
#ifndef __POLYNEW_H__
#define __POLYNEW_H__
-#include "mamecore.h"
+#include "emucore.h"
/***************************************************************************
diff --git a/src/emu/video/resnet.c b/src/emu/video/resnet.c
index c17b2e67623..02e1befc779 100644
--- a/src/emu/video/resnet.c
+++ b/src/emu/video/resnet.c
@@ -260,8 +260,8 @@ double compute_resistor_net_outputs(
/* parse input parameters */
- o = alloc_array_or_die(double, (1<<MAX_RES_PER_NET) * MAX_NETS);
- os = 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 = global_alloc_array(double, (1<<MAX_RES_PER_NET) * MAX_NETS);
networks_no = 0;
for (n = 0; n < MAX_NETS; n++)
@@ -423,8 +423,8 @@ if (VERBOSE)
}
/* debug end */
- free(o);
- free(os);
+ global_free(o);
+ global_free(os);
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);
}
-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;
int i,j,k;
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++)
{
UINT8 t[3] = {0,0,0};
diff --git a/src/emu/video/resnet.h b/src/emu/video/resnet.h
index c7f574fc855..a88a21ca8a3 100644
--- a/src/emu/video/resnet.h
+++ b/src/emu/video/resnet.h
@@ -159,7 +159,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di);
/* 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 */
diff --git a/src/lib/util/astring.c b/src/lib/util/astring.c
index 18f8968cf21..7ce911dfa30 100644
--- a/src/lib/util/astring.c
+++ b/src/lib/util/astring.c
@@ -48,24 +48,16 @@
/***************************************************************************
- TYPE DEFINITIONS
-***************************************************************************/
-
-struct _astring
-{
- char * text;
- int alloclen;
- char smallbuf[256 - sizeof(int) - sizeof(char *)];
-};
-
-
-
-/***************************************************************************
GLOBAL VARIABLES
***************************************************************************/
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 } };
+#endif
@@ -143,6 +135,53 @@ INLINE void normalize_substr(int *start, int *count, int length)
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
-------------------------------------------------*/
@@ -180,6 +219,8 @@ void astring_free(astring *str)
free(str);
}
+#endif
+
/***************************************************************************
diff --git a/src/lib/util/astring.h b/src/lib/util/astring.h
index 1ac8f449e0d..84cd030cf47 100644
--- a/src/lib/util/astring.h
+++ b/src/lib/util/astring.h
@@ -42,15 +42,44 @@
#ifndef __ASTRING_H__
#define __ASTRING_H__
-#include "pool.h"
#include <stdarg.h>
+#include "osdcomm.h"
/***************************************************************************
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
diff --git a/src/lib/util/bitmap.c b/src/lib/util/bitmap.c
index 8eb7cbd2bbd..3f40e9f3a20 100644
--- a/src/lib/util/bitmap.c
+++ b/src/lib/util/bitmap.c
@@ -39,12 +39,152 @@
#include "bitmap.h"
+#ifdef __cplusplus
+#include <new>
+#endif
/***************************************************************************
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 of the given format
@@ -146,6 +286,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
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
diff --git a/src/lib/util/bitmap.h b/src/lib/util/bitmap.h
index 06a515867a4..b95f176ebd0 100644
--- a/src/lib/util/bitmap.h
+++ b/src/lib/util/bitmap.h
@@ -79,8 +79,8 @@ struct _rectangle
/* bitmaps describe a rectangular array of pixels */
-typedef struct _bitmap_t bitmap_t;
-struct _bitmap_t
+typedef struct _bitmap_base bitmap_base;
+struct _bitmap_base
{
void * alloc; /* pointer to allocated pixel memory */
void * base; /* pointer to pixel (0,0) (adjusted for padding) */
@@ -94,6 +94,30 @@ struct _bitmap_t
};
+#ifdef __cplusplus
+
+/* class for C++ */
+class bitmap_t : public bitmap_base
+{
+private:
+ bitmap_t(const bitmap_t &);
+ bitmap_t &operator=(const bitmap_t &);
+
+public:
+ bitmap_t();
+ bitmap_t(int _width, int _height, bitmap_format _format, int _xslop = 0, int _yslop = 0);
+ bitmap_t(void *_base, int _width, int _height, int _rowpixels, bitmap_format _format);
+ ~bitmap_t();
+};
+
+#else
+
+/* direct map for C */
+typedef bitmap_base bitmap_t;
+
+#endif
+
+
/***************************************************************************
MACROS
@@ -132,6 +156,9 @@ void bitmap_set_palette(bitmap_t *bitmap, palette_t *palette);
/* free allocated data for a bitmap */
void bitmap_free(bitmap_t *bitmap);
+/* 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);
+
/* ----- bitmap drawing ----- */
diff --git a/src/lib/util/pool.c b/src/lib/util/pool.c
index 48b5791b304..b73d948dccf 100644
--- a/src/lib/util/pool.c
+++ b/src/lib/util/pool.c
@@ -497,11 +497,7 @@ void pool_iterate_end(object_pool_iterator *iter)
void *pool_malloc_file_line(object_pool *pool, size_t size, const char *file, int line)
{
-#ifdef MALLOC_DEBUG
- void *ptr = malloc_file_line(size, file, line);
-#else
void *ptr = malloc(size);
-#endif
return pool_object_add_file_line(pool, OBJTYPE_MEMORY, ptr, size, file, line);
}
@@ -515,11 +511,7 @@ void *pool_realloc_file_line(object_pool *pool, void *ptr, size_t size, const ch
{
if (ptr != NULL)
pool_object_remove(pool, ptr, FALSE);
-#ifdef MALLOC_DEBUG
- ptr = realloc_file_line(ptr, size, file, line);
-#else
ptr = realloc(ptr, size);
-#endif
if (size != 0)
pool_object_add_file_line(pool, OBJTYPE_MEMORY, ptr, size, file, line);
return ptr;
diff --git a/src/mame/drivers/alg.c b/src/mame/drivers/alg.c
index 7e090df4774..515ca0ce6de 100644
--- a/src/mame/drivers/alg.c
+++ b/src/mame/drivers/alg.c
@@ -685,7 +685,7 @@ static DRIVER_INIT( palr1 )
{
UINT32 length = memory_region_length(machine, "user2");
UINT8 *rom = memory_region(machine, "user2");
- UINT8 *original = alloc_array_or_die(UINT8, length);
+ UINT8 *original = auto_alloc_array(machine, UINT8, length);
UINT32 srcaddr;
memcpy(original, rom, length);
@@ -696,7 +696,7 @@ static DRIVER_INIT( palr1 )
if (srcaddr & 0x8000) dstaddr ^= 0x4000;
rom[dstaddr] = original[srcaddr];
}
- free(original);
+ auto_free(machine, original);
alg_init(machine);
}
@@ -705,7 +705,7 @@ static DRIVER_INIT( palr3 )
{
UINT32 length = memory_region_length(machine, "user2");
UINT8 *rom = memory_region(machine, "user2");
- UINT8 *original = alloc_array_or_die(UINT8, length);
+ UINT8 *original = auto_alloc_array(machine, UINT8, length);
UINT32 srcaddr;
memcpy(original, rom, length);
@@ -715,7 +715,7 @@ static DRIVER_INIT( palr3 )
if (srcaddr & 0x2000) dstaddr ^= 0x1000;
rom[dstaddr] = original[srcaddr];
}
- free(original);
+ auto_free(machine, original);
alg_init(machine);
}
@@ -724,7 +724,7 @@ static DRIVER_INIT( palr6 )
{
UINT32 length = memory_region_length(machine, "user2");
UINT8 *rom = memory_region(machine, "user2");
- UINT8 *original = alloc_array_or_die(UINT8, length);
+ UINT8 *original = auto_alloc_array(machine, UINT8, length);
UINT32 srcaddr;
memcpy(original, rom, length);
@@ -736,7 +736,7 @@ static DRIVER_INIT( palr6 )
dstaddr ^= 0x20000;
rom[dstaddr] = original[srcaddr];
}
- free(original);
+ auto_free(machine, original);
alg_init(machine);
}
diff --git a/src/mame/drivers/ampoker2.c b/src/mame/drivers/ampoker2.c
index c1c9e38a6f8..2ea2dafe03a 100644
--- a/src/mame/drivers/ampoker2.c
+++ b/src/mame/drivers/ampoker2.c
@@ -1274,7 +1274,6 @@ static DRIVER_INIT( rabbitpk )
{
UINT8 *rom = memory_region(machine, "maincpu");
- UINT8 *buffer;
int size = memory_region_length(machine, "maincpu");
int start = 0;
int i;
@@ -1291,11 +1290,6 @@ static DRIVER_INIT( rabbitpk )
{
rom[i] = BITSWAP8(rom[i], 1, 2, 5, 4, 3, 0, 7, 6) ^ dec_base[(i >> 2) & 0x1f];
}
-
- buffer = alloc_array_or_die(UINT8, size);
- memcpy(buffer, rom, size);
-
- free(buffer);
}
diff --git a/src/mame/drivers/arkanoid.c b/src/mame/drivers/arkanoid.c
index 1bf8e1c8dfe..8e281bc247c 100644
--- a/src/mame/drivers/arkanoid.c
+++ b/src/mame/drivers/arkanoid.c
@@ -1304,7 +1304,7 @@ static DRIVER_INIT( block2 )
// the graphics on this bootleg have the data scrambled
int tile;
UINT8* srcgfx = memory_region(machine,"gfx1");
- UINT8* buffer = alloc_array_or_die(UINT8, 0x18000);
+ UINT8* buffer = auto_alloc_array(machine, UINT8, 0x18000);
for (tile = 0; tile < 0x3000; tile++)
{
@@ -1328,7 +1328,7 @@ static DRIVER_INIT( block2 )
memcpy(srcgfx, buffer, 0x18000);
- free(buffer);
+ auto_free(machine, buffer);
state->bootleg_id = BLOCK2;
arkanoid_bootleg_init(machine);
diff --git a/src/mame/drivers/backfire.c b/src/mame/drivers/backfire.c
index 4aa201c2449..00466977ee5 100644
--- a/src/mame/drivers/backfire.c
+++ b/src/mame/drivers/backfire.c
@@ -628,7 +628,7 @@ static void descramble_sound( running_machine *machine )
{
UINT8 *rom = memory_region(machine, "ymz");
int length = 0x200000; // only the first rom is swapped on backfire!
- UINT8 *buf1 = alloc_array_or_die(UINT8, length);
+ UINT8 *buf1 = auto_alloc_array(machine, UINT8, length);
UINT32 x;
for (x=0;x<length;x++)
@@ -647,7 +647,7 @@ static void descramble_sound( running_machine *machine )
memcpy(rom,buf1,length);
- free (buf1);
+ auto_free (machine, buf1);
}
static READ32_HANDLER( backfire_speedup_r )
diff --git a/src/mame/drivers/balsente.c b/src/mame/drivers/balsente.c
index d8a7b16a520..9ec40049e67 100644
--- a/src/mame/drivers/balsente.c
+++ b/src/mame/drivers/balsente.c
@@ -1995,7 +1995,7 @@ static void expand_roms(running_machine *machine, UINT8 cd_rom_mask)
/* load EF from 0x2e000-0x30000 */
/* ROM region must be 0x40000 total */
- UINT8 *temp = alloc_array_or_die(UINT8, 0x20000);
+ UINT8 *temp = auto_alloc_array(machine, UINT8, 0x20000);
{
UINT8 *rom = memory_region(machine, "maincpu");
UINT32 len = memory_region_length(machine, "maincpu");
@@ -2050,7 +2050,7 @@ static void expand_roms(running_machine *machine, UINT8 cd_rom_mask)
memcpy(&rom[base + 0x00000], &ab_base[0x0000], 0x2000);
}
- free(temp);
+ auto_free(machine, temp);
}
}
diff --git a/src/mame/drivers/bfcobra.c b/src/mame/drivers/bfcobra.c
index c0666f5b84e..90bac11867c 100644
--- a/src/mame/drivers/bfcobra.c
+++ b/src/mame/drivers/bfcobra.c
@@ -1665,7 +1665,7 @@ static DRIVER_INIT( bfcobra )
UINT8 *rom;
UINT8 *tmp;
- tmp = alloc_array_or_die(UINT8, 0x8000);
+ tmp = auto_alloc_array(machine, UINT8, 0x8000);
rom = memory_region(machine, "audiocpu") + 0x8000;
memcpy(tmp, rom, 0x8000);
@@ -1685,7 +1685,7 @@ static DRIVER_INIT( bfcobra )
rom[addr] = data;
}
- free(tmp);
+ auto_free(machine, tmp);
init_ram(machine);
diff --git a/src/mame/drivers/bfm_sc1.c b/src/mame/drivers/bfm_sc1.c
index ef22983c04c..08b3c775dd0 100644
--- a/src/mame/drivers/bfm_sc1.c
+++ b/src/mame/drivers/bfm_sc1.c
@@ -662,7 +662,7 @@ static void decode_sc1(running_machine *machine,const char *rom_region)
rom = memory_region(machine,rom_region);
- tmp = alloc_array_or_die(UINT8, 0x10000);
+ tmp = auto_alloc_array(machine, UINT8, 0x10000);
{
int i;
@@ -704,7 +704,7 @@ static void decode_sc1(running_machine *machine,const char *rom_region)
rom[newaddress] = codec_data[ tmp[address] ];
}
- free( tmp );
+ auto_free( machine, tmp );
}
}
// machine start (called only once) /////////////////////////////////////////////////
diff --git a/src/mame/drivers/bfm_sc2.c b/src/mame/drivers/bfm_sc2.c
index 442b36c21e6..a3d905d6cac 100644
--- a/src/mame/drivers/bfm_sc2.c
+++ b/src/mame/drivers/bfm_sc2.c
@@ -1434,7 +1434,7 @@ static void decode_mainrom(running_machine *machine, const char *rom_region)
rom = memory_region(machine, rom_region);
- tmp = alloc_array_or_die(UINT8, 0x10000);
+ tmp = auto_alloc_array(machine, UINT8, 0x10000);
{
int i;
long address;
@@ -1475,7 +1475,7 @@ static void decode_mainrom(running_machine *machine, const char *rom_region)
rom[newaddress] = codec_data[ tmp[address] ];
}
- free(tmp);
+ auto_free(machine, tmp);
}
}
diff --git a/src/mame/drivers/cave.c b/src/mame/drivers/cave.c
index d0afca6aeb0..341f90bb028 100644
--- a/src/mame/drivers/cave.c
+++ b/src/mame/drivers/cave.c
@@ -4047,13 +4047,13 @@ static DRIVER_INIT( mazinger )
memory_configure_bank(machine, "bank2", 2, 6, &ROM[0x10000], 0x4000);
/* decrypt sprites */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0; i < len; i++)
buffer[i ^ 0xdf88] = src[BITSWAP24(i,23,22,21,20,19,9,7,3,15,4,17,14,18,2,16,5,11,8,6,13,1,10,12,0)];
memcpy(src, buffer, len);
- free(buffer);
+ auto_free(machine, buffer);
}
state->region_byte = 0x05;
@@ -4099,7 +4099,7 @@ static DRIVER_INIT( pwrins2j )
memory_configure_bank(machine, "bank1", 0, 3, &ROM[0x00000], 0x4000);
memory_configure_bank(machine, "bank1", 3, 5, &ROM[0x10000], 0x4000);
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
for(i = 0; i < len/2; i++)
{
@@ -4110,7 +4110,7 @@ static DRIVER_INIT( pwrins2j )
}
memcpy(src,buffer,len);
- free(buffer);
+ auto_free(machine, buffer);
}
unpack_sprites(machine);
@@ -4149,13 +4149,13 @@ static DRIVER_INIT( sailormn )
memory_configure_bank(machine, "bank1", 2, 0x1e, &ROM[0x10000], 0x4000);
/* decrypt sprites */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0; i < len; i++)
buffer[i ^ 0x950c4] = src[BITSWAP24(i,23,22,21,20,15,10,12,6,11,1,13,3,16,17,2,5,14,7,18,8,4,19,9,0)];
memcpy(src, buffer, len);
- free(buffer);
+ auto_free(machine, buffer);
}
sailormn_unpack_tiles( machine, "gfx4" );
diff --git a/src/mame/drivers/coinmstr.c b/src/mame/drivers/coinmstr.c
index 0bf7b319968..f6d1e6e8877 100644
--- a/src/mame/drivers/coinmstr.c
+++ b/src/mame/drivers/coinmstr.c
@@ -1196,18 +1196,18 @@ static DRIVER_INIT( coinmstr )
{
UINT8 *rom = memory_region(machine, "user1");
int length = memory_region_length(machine, "user1");
- UINT8 *buf = alloc_array_or_die(UINT8, length);
+ UINT8 *buf = auto_alloc_array(machine, UINT8, length);
int i;
- memcpy(buf,rom,length);
+ memcpy(buf,rom,length);
- for(i = 0; i < length; i++)
- {
- int adr = BITSWAP24(i, 23,22,21,20,19,18,17,16,15, 14,8,7,2,5,12,10,9,11,13,3,6,0,1,4);
- rom[i] = BITSWAP8(buf[adr],3,2,4,1,5,0,6,7);
- }
+ for(i = 0; i < length; i++)
+ {
+ int adr = BITSWAP24(i, 23,22,21,20,19,18,17,16,15, 14,8,7,2,5,12,10,9,11,13,3,6,0,1,4);
+ rom[i] = BITSWAP8(buf[adr],3,2,4,1,5,0,6,7);
+ }
- free(buf);
+ auto_free(machine, buf);
}
diff --git a/src/mame/drivers/darkmist.c b/src/mame/drivers/darkmist.c
index 46563ce087b..e77afec5acf 100644
--- a/src/mame/drivers/darkmist.c
+++ b/src/mame/drivers/darkmist.c
@@ -336,7 +336,7 @@ ROM_END
static void decrypt_gfx(running_machine *machine)
{
- UINT8 *buf = alloc_array_or_die(UINT8, 0x40000);
+ UINT8 *buf = auto_alloc_array(machine, UINT8, 0x40000);
UINT8 *rom;
int size;
int i;
@@ -409,7 +409,7 @@ static void decrypt_gfx(running_machine *machine)
rom[i] = buf[BITSWAP24(i, 23,22,21,20,19,18,17,16,15,14, 12,11,10,9,8, 5,4,3, 13, 7,6, 1,0, 2)];
}
- free(buf);
+ auto_free(machine, buf);
}
static void decrypt_snd(running_machine *machine)
@@ -426,7 +426,7 @@ static DRIVER_INIT(darkmist)
const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
int i, len;
UINT8 *ROM = memory_region(machine, "maincpu");
- UINT8 *buffer = alloc_array_or_die(UINT8, 0x10000);
+ UINT8 *buffer = auto_alloc_array(machine, UINT8, 0x10000);
UINT8 *decrypt = auto_alloc_array(machine, UINT8, 0x8000);
decrypt_gfx(machine);
@@ -494,7 +494,7 @@ static DRIVER_INIT(darkmist)
ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14 ,5,4,3,2,11,10,9,8,13,12,1,0,7,6)];
}
- free(buffer);
+ auto_free(machine, buffer);
}
GAME( 1986, darkmist, 0, darkmist, darkmist, darkmist, ROT270, "Taito", "The Lost Castle In Darkmist", GAME_IMPERFECT_GRAPHICS|GAME_NO_COCKTAIL )
diff --git a/src/mame/drivers/dassault.c b/src/mame/drivers/dassault.c
index 800bef2b5da..dcd07759aa0 100644
--- a/src/mame/drivers/dassault.c
+++ b/src/mame/drivers/dassault.c
@@ -808,7 +808,7 @@ static DRIVER_INIT( dassault )
{
const UINT8 *src = memory_region(machine, "gfx1");
UINT8 *dst = memory_region(machine, "gfx2");
- UINT8 *tmp = alloc_array_or_die(UINT8, 0x80000);
+ UINT8 *tmp = auto_alloc_array(machine, UINT8, 0x80000);
/* Playfield 4 also has access to the char graphics, make things easier
by just copying the chars to both banks (if I just used a different gfx
@@ -818,7 +818,7 @@ static DRIVER_INIT( dassault )
memcpy(dst+0x080000,src+0x00000,0x10000);
memcpy(dst+0x110000,src+0x10000,0x10000);
- free(tmp);
+ auto_free(machine, tmp);
/* Save time waiting on vblank bit */
memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x3f8000, 0x3f8001, 0, 0, dassault_main_skip);
@@ -828,7 +828,7 @@ static DRIVER_INIT( thndzone )
{
const UINT8 *src = memory_region(machine, "gfx1");
UINT8 *dst = memory_region(machine, "gfx2");
- UINT8 *tmp = alloc_array_or_die(UINT8, 0x80000);
+ UINT8 *tmp = auto_alloc_array(machine, UINT8, 0x80000);
/* Playfield 4 also has access to the char graphics, make things easier
by just copying the chars to both banks (if I just used a different gfx
@@ -838,7 +838,7 @@ static DRIVER_INIT( thndzone )
memcpy(dst+0x080000,src+0x00000,0x10000);
memcpy(dst+0x110000,src+0x10000,0x10000);
- free(tmp);
+ auto_free(machine, tmp);
/* Save time waiting on vblank bit */
memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x3f8000, 0x3f8001, 0, 0, thndzone_main_skip);
diff --git a/src/mame/drivers/ddayjlc.c b/src/mame/drivers/ddayjlc.c
index f52e644917e..1dd1acc3ca6 100644
--- a/src/mame/drivers/ddayjlc.c
+++ b/src/mame/drivers/ddayjlc.c
@@ -638,7 +638,7 @@ static DRIVER_INIT( ddayjlc )
{
UINT32 oldaddr, newadr, length,j;
UINT8 *src, *dst, *temp;
- temp = alloc_array_or_die(UINT8, 0x10000);
+ temp = auto_alloc_array(machine, UINT8, 0x10000);
src = temp;
dst = memory_region(machine, "gfx1");
length = memory_region_length(machine, "gfx1");
@@ -652,7 +652,7 @@ static DRIVER_INIT( ddayjlc )
newadr += 32;
oldaddr += 16;
}
- free(temp);
+ auto_free(machine, temp);
}
memory_configure_bank(machine, "bank1", 0, 3, memory_region(machine, "user1"), 0x4000);
diff --git a/src/mame/drivers/deco156.c b/src/mame/drivers/deco156.c
index f55bd7f7a04..85fdff988f4 100644
--- a/src/mame/drivers/deco156.c
+++ b/src/mame/drivers/deco156.c
@@ -636,7 +636,7 @@ static void descramble_sound( running_machine *machine, const char *tag )
{
UINT8 *rom = memory_region(machine, tag);
int length = memory_region_length(machine, tag);
- UINT8 *buf1 = alloc_array_or_die(UINT8, length);
+ UINT8 *buf1 = auto_alloc_array(machine, UINT8, length);
UINT32 x;
for (x=0;x<length;x++)
@@ -655,7 +655,7 @@ static void descramble_sound( running_machine *machine, const char *tag )
memcpy(rom,buf1,length);
- free (buf1);
+ auto_free (machine, buf1);
}
static DRIVER_INIT( hvysmsh )
diff --git a/src/mame/drivers/deco32.c b/src/mame/drivers/deco32.c
index 37e64ea6260..c945cfcbb82 100644
--- a/src/mame/drivers/deco32.c
+++ b/src/mame/drivers/deco32.c
@@ -3027,7 +3027,7 @@ static DRIVER_INIT( lockload )
static DRIVER_INIT( tattass )
{
UINT8 *RAM = memory_region(machine, "gfx1");
- UINT8 *tmp = alloc_array_or_die(UINT8, 0x80000);
+ UINT8 *tmp = auto_alloc_array(machine, UINT8, 0x80000);
/* Reorder bitplanes to make decoding easier */
memcpy(tmp,RAM+0x80000,0x80000);
@@ -3039,7 +3039,7 @@ static DRIVER_INIT( tattass )
memcpy(RAM+0x80000,RAM+0x100000,0x80000);
memcpy(RAM+0x100000,tmp,0x80000);
- free(tmp);
+ auto_free(machine, tmp);
deco56_decrypt_gfx(machine, "gfx1"); /* 141 */
deco56_decrypt_gfx(machine, "gfx2"); /* 141 */
@@ -3048,7 +3048,7 @@ static DRIVER_INIT( tattass )
static DRIVER_INIT( nslasher )
{
UINT8 *RAM = memory_region(machine, "gfx1");
- UINT8 *tmp = alloc_array_or_die(UINT8, 0x80000);
+ UINT8 *tmp = auto_alloc_array(machine, UINT8, 0x80000);
/* Reorder bitplanes to make decoding easier */
memcpy(tmp,RAM+0x80000,0x80000);
@@ -3060,7 +3060,7 @@ static DRIVER_INIT( nslasher )
memcpy(RAM+0x80000,RAM+0x100000,0x80000);
memcpy(RAM+0x100000,tmp,0x80000);
- free(tmp);
+ auto_free(machine, tmp);
deco56_decrypt_gfx(machine, "gfx1"); /* 141 */
deco74_decrypt_gfx(machine, "gfx2");
diff --git a/src/mame/drivers/deco_mlc.c b/src/mame/drivers/deco_mlc.c
index 2b8ac29783b..837db6e1d02 100644
--- a/src/mame/drivers/deco_mlc.c
+++ b/src/mame/drivers/deco_mlc.c
@@ -683,7 +683,7 @@ static void descramble_sound( running_machine *machine )
/* the same as simpl156 / heavy smash? */
UINT8 *rom = memory_region(machine, "ymz");
int length = memory_region_length(machine, "ymz");
- UINT8 *buf1 = alloc_array_or_die(UINT8, length);
+ UINT8 *buf1 = auto_alloc_array(machine, UINT8, length);
UINT32 x;
@@ -703,7 +703,7 @@ static void descramble_sound( running_machine *machine )
memcpy(rom,buf1,length);
- free (buf1);
+ auto_free (machine, buf1);
}
static READ32_HANDLER( avengrgs_speedup_r )
diff --git a/src/mame/drivers/dynax.c b/src/mame/drivers/dynax.c
index 3c5a1ea0c6c..6571a79c49c 100644
--- a/src/mame/drivers/dynax.c
+++ b/src/mame/drivers/dynax.c
@@ -5199,11 +5199,11 @@ static DRIVER_INIT( maya )
}
/* Address lines scrambling on the blitter data roms */
- rom = alloc_array_or_die(UINT8, 0xc0000);
+ rom = auto_alloc_array(machine, UINT8, 0xc0000);
memcpy(rom, gfx, 0xc0000);
for (i = 0; i < 0xc0000; i++)
gfx[i] = rom[BITSWAP24(i,23,22,21,20,19,18,14,15, 16,17,13,12,11,10,9,8, 7,6,5,4,3,2,1,0)];
- free(rom);
+ auto_free(machine, rom);
}
@@ -5906,12 +5906,12 @@ static DRIVER_INIT( mjelct3 )
int i;
UINT8 *rom = memory_region(machine, "maincpu");
size_t size = memory_region_length(machine, "maincpu");
- UINT8 *rom1 = alloc_array_or_die(UINT8, size);
+ UINT8 *rom1 = auto_alloc_array(machine, UINT8, size);
- memcpy(rom1,rom,size);
- for (i = 0; i < size; i++)
- rom[i] = BITSWAP8(rom1[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8, 1,6,5,4,3,2,7, 0)], 7,6, 1,4,3,2,5,0);
- free(rom1);
+ memcpy(rom1,rom,size);
+ for (i = 0; i < size; i++)
+ rom[i] = BITSWAP8(rom1[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8, 1,6,5,4,3,2,7, 0)], 7,6, 1,4,3,2,5,0);
+ auto_free(machine, rom1);
}
static DRIVER_INIT( mjelct3a )
@@ -5919,37 +5919,37 @@ static DRIVER_INIT( mjelct3a )
int i,j;
UINT8 *rom = memory_region(machine, "maincpu");
size_t size = memory_region_length(machine, "maincpu");
- UINT8 *rom1 = alloc_array_or_die(UINT8, size);
+ UINT8 *rom1 = auto_alloc_array(machine, UINT8, size);
- memcpy(rom1,rom,size);
- for (i = 0; i < size; i++)
+ memcpy(rom1,rom,size);
+ for (i = 0; i < size; i++)
+ {
+ j = i & ~0x7e00;
+ switch(i & 0x7000)
{
- j = i & ~0x7e00;
- switch(i & 0x7000)
- {
- case 0x0000: j |= 0x0400; break;
- case 0x1000: j |= 0x4400; break;
- case 0x2000: j |= 0x4200; break;
- case 0x3000: j |= 0x0200; break;
- case 0x4000: j |= 0x4600; break;
- case 0x5000: j |= 0x4000; break;
+ case 0x0000: j |= 0x0400; break;
+ case 0x1000: j |= 0x4400; break;
+ case 0x2000: j |= 0x4200; break;
+ case 0x3000: j |= 0x0200; break;
+ case 0x4000: j |= 0x4600; break;
+ case 0x5000: j |= 0x4000; break;
// case 0x6000: j |= 0x0000; break;
- case 0x7000: j |= 0x0600; break;
- }
- switch(i & 0x0e00)
- {
- case 0x0000: j |= 0x2000; break;
- case 0x0200: j |= 0x3800; break;
- case 0x0400: j |= 0x2800; break;
- case 0x0600: j |= 0x0800; break;
- case 0x0800: j |= 0x1800; break;
+ case 0x7000: j |= 0x0600; break;
+ }
+ switch(i & 0x0e00)
+ {
+ case 0x0000: j |= 0x2000; break;
+ case 0x0200: j |= 0x3800; break;
+ case 0x0400: j |= 0x2800; break;
+ case 0x0600: j |= 0x0800; break;
+ case 0x0800: j |= 0x1800; break;
// case 0x0a00: j |= 0x0000; break;
- case 0x0c00: j |= 0x1000; break;
- case 0x0e00: j |= 0x3000; break;
- }
- rom[j] = rom1[i];
+ case 0x0c00: j |= 0x1000; break;
+ case 0x0e00: j |= 0x3000; break;
}
- free(rom1);
+ rom[j] = rom1[i];
+ }
+ auto_free(machine, rom1);
DRIVER_INIT_CALL(mjelct3);
}
diff --git a/src/mame/drivers/exerion.c b/src/mame/drivers/exerion.c
index 7e50ff2f555..f5988e94606 100644
--- a/src/mame/drivers/exerion.c
+++ b/src/mame/drivers/exerion.c
@@ -454,7 +454,7 @@ static DRIVER_INIT( exerion )
UINT8 *src, *dst, *temp;
/* allocate some temporary space */
- temp = alloc_array_or_die(UINT8, 0x10000);
+ temp = auto_alloc_array(machine, UINT8, 0x10000);
/* make a temporary copy of the character data */
src = temp;
@@ -493,7 +493,7 @@ static DRIVER_INIT( exerion )
dst[newaddr] = src[oldaddr];
}
- free(temp);
+ auto_free(machine, temp);
}
diff --git a/src/mame/drivers/fcombat.c b/src/mame/drivers/fcombat.c
index 3b7f3e92214..435e3ca1fde 100644
--- a/src/mame/drivers/fcombat.c
+++ b/src/mame/drivers/fcombat.c
@@ -347,7 +347,7 @@ static DRIVER_INIT( fcombat )
UINT8 *src, *dst, *temp;
/* allocate some temporary space */
- temp = alloc_array_or_die(UINT8, 0x10000);
+ temp = auto_alloc_array(machine, UINT8, 0x10000);
/* make a temporary copy of the character data */
src = temp;
@@ -431,7 +431,7 @@ static DRIVER_INIT( fcombat )
memcpy(&dst[oldaddr * 32 * 8 * 2 + 32 * 8], &src[oldaddr * 32 * 8 + 0x2000], 32 * 8);
}
- free(temp);
+ auto_free(machine, temp);
}
ROM_START( fcombat )
diff --git a/src/mame/drivers/forte2.c b/src/mame/drivers/forte2.c
index 7e2989bfd1e..11b743dc760 100644
--- a/src/mame/drivers/forte2.c
+++ b/src/mame/drivers/forte2.c
@@ -156,13 +156,13 @@ static DRIVER_INIT(pesadelo)
}
// address line swap
- buf = alloc_array_or_die(UINT8, memsize);
+ buf = auto_alloc_array(machine, UINT8, memsize);
memcpy(buf, mem, memsize);
for ( i = 0; i < memsize; i++ )
{
mem[BITSWAP16(i,11,9,8,13,14,15,12,7,6,5,4,3,2,1,0,10)] = buf[i];
}
- free(buf);
+ auto_free(machine, buf);
}
diff --git a/src/mame/drivers/funworld.c b/src/mame/drivers/funworld.c
index fce1b63db93..d6ac330b4c3 100644
--- a/src/mame/drivers/funworld.c
+++ b/src/mame/drivers/funworld.c
@@ -3105,7 +3105,7 @@ static DRIVER_INIT( saloon )
rom[i] = BITSWAP8(rom[i], 7, 6, 5, 4, 3, 0, 1, 2);
}
- buffer = alloc_array_or_die(UINT8, size);
+ buffer = auto_alloc_array(machine, UINT8, size);
memcpy(buffer, rom, size);
@@ -3117,14 +3117,14 @@ static DRIVER_INIT( saloon )
rom[a] = buffer[i];
}
- free(buffer);
+ auto_free(machine, buffer);
/******************************
* Graphics ROM decryption *
******************************/
- buffer = alloc_array_or_die(UINT8, sizeg);
+ buffer = auto_alloc_array(machine, UINT8, sizeg);
memcpy(buffer, gfxrom, sizeg);
/* address lines swap: fedcba9876543210 -> fedcb67584a39012 */
@@ -3135,7 +3135,7 @@ static DRIVER_INIT( saloon )
gfxrom[a] = buffer[i];
}
- free(buffer);
+ auto_free(machine, buffer);
/****************************
@@ -3149,7 +3149,7 @@ static DRIVER_INIT( saloon )
prom[i] = BITSWAP8(prom[i], 2, 3, 5, 4, 6, 7, 1, 0);
}
- buffer = alloc_array_or_die(UINT8, sizep);
+ buffer = auto_alloc_array(machine, UINT8, sizep);
memcpy(buffer, prom, sizep);
@@ -3161,7 +3161,7 @@ static DRIVER_INIT( saloon )
prom[a] = buffer[i];
}
- free(buffer);
+ auto_free(machine, buffer);
}
diff --git a/src/mame/drivers/gaiden.c b/src/mame/drivers/gaiden.c
index 1b005563656..6a05021dd55 100644
--- a/src/mame/drivers/gaiden.c
+++ b/src/mame/drivers/gaiden.c
@@ -1597,7 +1597,7 @@ static void descramble_drgnbowl_gfx(running_machine *machine)
int i;
UINT8 *ROM = memory_region(machine, "maincpu");
size_t size = memory_region_length(machine, "maincpu");
- UINT8 *buffer = alloc_array_or_die(UINT8, size);
+ UINT8 *buffer = auto_alloc_array(machine, UINT8, size);
memcpy(buffer, ROM, size);
for( i = 0; i < size; i++ )
@@ -1610,11 +1610,11 @@ static void descramble_drgnbowl_gfx(running_machine *machine)
3, 2, 1, 0)];
}
- free(buffer);
+ auto_free(machine, buffer);
ROM = memory_region(machine, "gfx2");
size = memory_region_length(machine, "gfx2");
- buffer = alloc_array_or_die(UINT8, size);
+ buffer = auto_alloc_array(machine, UINT8, size);
memcpy(buffer,ROM,size);
for( i = 0; i < size; i++ )
@@ -1628,7 +1628,7 @@ static void descramble_drgnbowl_gfx(running_machine *machine)
5, 2, 1, 0)];
}
- free(buffer);
+ auto_free(machine, buffer);
}
static DRIVER_INIT( drgnbowl )
@@ -1639,13 +1639,13 @@ static DRIVER_INIT( drgnbowl )
descramble_drgnbowl_gfx(machine);
}
-static void descramble_mastninj_gfx(UINT8* src)
+static void descramble_mastninj_gfx(running_machine *machine, UINT8* src)
{
UINT8 *buffer;
int len = 0x80000;
/* rearrange gfx */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0;i < len; i++)
@@ -1659,10 +1659,10 @@ static void descramble_mastninj_gfx(UINT8* src)
3,2,1,0)];
}
memcpy(src, buffer, len);
- free(buffer);
+ auto_free(machine, buffer);
}
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0; i < len; i++)
@@ -1676,15 +1676,15 @@ static void descramble_mastninj_gfx(UINT8* src)
3,2,1,0)];
}
memcpy(src, buffer, len);
- free(buffer);
+ auto_free(machine, buffer);
}
}
static DRIVER_INIT(mastninj)
{
// rearrange the graphic roms into a format that MAME can decode
- descramble_mastninj_gfx(memory_region(machine,"gfx2"));
- descramble_mastninj_gfx(memory_region(machine,"gfx3"));
+ descramble_mastninj_gfx(machine, memory_region(machine,"gfx2"));
+ descramble_mastninj_gfx(machine, memory_region(machine,"gfx3"));
DRIVER_INIT_CALL(shadoww);
}
diff --git a/src/mame/drivers/galaxian.c b/src/mame/drivers/galaxian.c
index 0ba099ae625..8ec993487e3 100644
--- a/src/mame/drivers/galaxian.c
+++ b/src/mame/drivers/galaxian.c
@@ -2332,7 +2332,7 @@ static void decode_anteater_gfx(running_machine *machine)
{
UINT32 romlength = memory_region_length(machine, "gfx1");
UINT8 *rombase = memory_region(machine, "gfx1");
- UINT8 *scratch = alloc_array_or_die(UINT8, romlength);
+ UINT8 *scratch = auto_alloc_array(machine, UINT8, romlength);
UINT32 offs;
memcpy(scratch, rombase, romlength);
@@ -2344,7 +2344,7 @@ static void decode_anteater_gfx(running_machine *machine)
srcoffs |= (BIT(offs,0) ^ BIT(offs,6) ^ 1) << 10;
rombase[offs] = scratch[srcoffs];
}
- free(scratch);
+ auto_free(machine, scratch);
}
@@ -2352,7 +2352,7 @@ static void decode_losttomb_gfx(running_machine *machine)
{
UINT32 romlength = memory_region_length(machine, "gfx1");
UINT8 *rombase = memory_region(machine, "gfx1");
- UINT8 *scratch = alloc_array_or_die(UINT8, romlength);
+ UINT8 *scratch = auto_alloc_array(machine, UINT8, romlength);
UINT32 offs;
memcpy(scratch, rombase, romlength);
@@ -2364,7 +2364,7 @@ static void decode_losttomb_gfx(running_machine *machine)
srcoffs |= ((BIT(offs,1) & BIT(offs,7)) | ((1 ^ BIT(offs,1)) & (BIT(offs,8)))) << 10;
rombase[offs] = scratch[srcoffs];
}
- free(scratch);
+ auto_free(machine, scratch);
}
diff --git a/src/mame/drivers/gauntlet.c b/src/mame/drivers/gauntlet.c
index 0dd48fc5727..7bc64217152 100644
--- a/src/mame/drivers/gauntlet.c
+++ b/src/mame/drivers/gauntlet.c
@@ -1652,7 +1652,7 @@ static DRIVER_INIT( gauntlet2 )
static DRIVER_INIT( vindctr2 )
{
UINT8 *gfx2_base = memory_region(machine, "gfx2");
- UINT8 *data = alloc_array_or_die(UINT8, 0x8000);
+ UINT8 *data = auto_alloc_array(machine, UINT8, 0x8000);
int i;
gauntlet_common_init(machine, 118, 1);
@@ -1660,13 +1660,13 @@ static DRIVER_INIT( vindctr2 )
/* highly strange -- the address bits on the chip at 2J (and only that
chip) are scrambled -- this is verified on the schematics! */
- memcpy(data, &gfx2_base[0x88000], 0x8000);
- for (i = 0; i < 0x8000; i++)
- {
- int srcoffs = (i & 0x4000) | ((i << 11) & 0x3800) | ((i >> 3) & 0x07ff);
- gfx2_base[0x88000 + i] = data[srcoffs];
- }
- free(data);
+ memcpy(data, &gfx2_base[0x88000], 0x8000);
+ for (i = 0; i < 0x8000; i++)
+ {
+ int srcoffs = (i & 0x4000) | ((i << 11) & 0x3800) | ((i >> 3) & 0x07ff);
+ gfx2_base[0x88000 + i] = data[srcoffs];
+ }
+ auto_free(machine, data);
}
diff --git a/src/mame/drivers/goldstar.c b/src/mame/drivers/goldstar.c
index ad5a8d978c0..4c96c87660f 100644
--- a/src/mame/drivers/goldstar.c
+++ b/src/mame/drivers/goldstar.c
@@ -7990,7 +7990,7 @@ static DRIVER_INIT(goldstar)
// this block swapping is the same for chry10, chrygld and cb3
// the underlying bitswaps / xors are different however
-static void do_blockswaps(UINT8* ROM)
+static void do_blockswaps(running_machine *machine, UINT8* ROM)
{
int A;
UINT8 *buffer;
@@ -8009,7 +8009,7 @@ static void do_blockswaps(UINT8* ROM)
0xa000, 0xa800, 0xb000, 0xb800,
};
- buffer = alloc_array_or_die(UINT8, 0x10000);
+ buffer = auto_alloc_array(machine, UINT8, 0x10000);
memcpy(buffer,ROM,0x10000);
// swap some 0x800 blocks around..
@@ -8018,7 +8018,7 @@ static void do_blockswaps(UINT8* ROM)
memcpy(ROM+A*0x800,buffer+cherry_swaptables[A],0x800);
}
- free(buffer);
+ auto_free(machine, buffer);
}
static void dump_to_file(running_machine* machine, UINT8* ROM)
@@ -8066,7 +8066,6 @@ static DRIVER_INIT( chry10 )
int size = memory_region_length(machine, "maincpu");
int start = 0;
- UINT8 *buffer;
int i;
for (i = start; i < size; i++)
@@ -8074,12 +8073,7 @@ static DRIVER_INIT( chry10 )
ROM[i] = chry10_decrypt(ROM[i]);
}
- buffer = alloc_array_or_die(UINT8, size);
- memcpy(buffer, ROM, size);
-
- free(buffer);
-
- do_blockswaps(ROM);
+ do_blockswaps(machine, ROM);
/* The game has a PIC for protection.
If the code enter to this sub, just
@@ -8096,7 +8090,6 @@ static DRIVER_INIT( cb3 )
int size = memory_region_length(machine, "maincpu");
int start = 0;
- UINT8 *buffer;
int i;
for (i = start; i < size; i++)
@@ -8104,12 +8097,7 @@ static DRIVER_INIT( cb3 )
ROM[i] = decrypt(ROM[i], i);
}
- buffer = alloc_array_or_die(UINT8, size);
- memcpy(buffer, ROM, size);
-
- free(buffer);
-
- do_blockswaps(ROM);
+ do_blockswaps(machine, ROM);
dump_to_file(machine, ROM);
}
@@ -8118,7 +8106,7 @@ static DRIVER_INIT( chrygld )
{
int A;
UINT8 *ROM = memory_region(machine, "maincpu");
- do_blockswaps(ROM);
+ do_blockswaps(machine, ROM);
// a data bitswap
for (A = 0;A < 0x10000;A++)
diff --git a/src/mame/drivers/hng64.c b/src/mame/drivers/hng64.c
index fde46cc1bea..e1e5006a6f8 100644
--- a/src/mame/drivers/hng64.c
+++ b/src/mame/drivers/hng64.c
@@ -1667,7 +1667,7 @@ static GFXDECODE_START( hng64 )
GFXDECODE_ENTRY( "textures", 0, hng64_texlayout, 0x0, 0x10 ) /* textures */
GFXDECODE_END
-static void hng64_reorder(UINT8* gfxregion, size_t gfxregionsize)
+static void hng64_reorder(running_machine *machine, UINT8* gfxregion, size_t gfxregionsize)
{
// by default 2 4bpp tiles are stored in each 8bpp tile, this makes decoding in MAME harder than it needs to be
// reorder them
@@ -1675,7 +1675,7 @@ static void hng64_reorder(UINT8* gfxregion, size_t gfxregionsize)
int i;
UINT8 tilesize = 4*8; // 4 bytes per line, 8 lines
- buffer = alloc_array_or_die(UINT8, gfxregionsize);
+ buffer = auto_alloc_array(machine, UINT8, gfxregionsize);
for (i=0;i<gfxregionsize/2;i+=tilesize)
{
@@ -1685,14 +1685,14 @@ static void hng64_reorder(UINT8* gfxregion, size_t gfxregionsize)
memcpy(gfxregion, buffer, gfxregionsize);
- free (buffer);
+ auto_free (machine, buffer);
}
static DRIVER_INIT( hng64_reorder_gfx )
{
- hng64_reorder(memory_region(machine,"scrtile"), memory_region_length(machine, "scrtile"));
+ hng64_reorder(machine, memory_region(machine,"scrtile"), memory_region_length(machine, "scrtile"));
}
#define HACK_REGION
diff --git a/src/mame/drivers/igs011.c b/src/mame/drivers/igs011.c
index bb5df591885..19276a55f1d 100644
--- a/src/mame/drivers/igs011.c
+++ b/src/mame/drivers/igs011.c
@@ -547,7 +547,7 @@ static void lhb2_decrypt(running_machine *machine)
int i,j;
int rom_size = 0x80000;
UINT16 *src = (UINT16 *) (memory_region(machine, "maincpu"));
- UINT16 *result_data = alloc_array_or_die(UINT16, rom_size/2);
+ UINT16 *result_data = auto_alloc_array(machine, UINT16, rom_size/2);
for (i=0; i<rom_size/2; i++)
{
@@ -569,7 +569,7 @@ static void lhb2_decrypt(running_machine *machine)
memcpy(src,result_data,rom_size);
- free(result_data);
+ auto_free(machine, result_data);
}
@@ -588,7 +588,7 @@ static void nkishusp_decrypt(running_machine *machine)
int i,j;
int rom_size = 0x80000;
UINT16 *src = (UINT16 *) (memory_region(machine, "maincpu"));
- UINT16 *result_data = alloc_array_or_die(UINT16, rom_size/2);
+ UINT16 *result_data = auto_alloc_array(machine, UINT16, rom_size/2);
for (i=0; i<rom_size/2; i++)
{
@@ -610,7 +610,7 @@ static void nkishusp_decrypt(running_machine *machine)
memcpy(src,result_data,rom_size);
- free(result_data);
+ auto_free(machine, result_data);
}
@@ -734,14 +734,14 @@ static void lhb2_decrypt_gfx(running_machine *machine)
int i;
unsigned rom_size = 0x200000;
UINT8 *src = (UINT8 *) (memory_region(machine, "blitter"));
- UINT8 *result_data = alloc_array_or_die(UINT8, rom_size);
+ UINT8 *result_data = auto_alloc_array(machine, UINT8, rom_size);
for (i=0; i<rom_size; i++)
result_data[i] = src[BITSWAP24(i, 23,22,21,20, 19, 17,16,15, 13,12, 10,9,8,7,6,5,4, 2,1, 3, 11, 14, 18, 0)];
memcpy(src,result_data,rom_size);
- free(result_data);
+ auto_free(machine, result_data);
}
static void drgnwrld_gfx_decrypt(running_machine *machine)
@@ -749,14 +749,14 @@ static void drgnwrld_gfx_decrypt(running_machine *machine)
int i;
unsigned rom_size = 0x400000;
UINT8 *src = (UINT8 *) (memory_region(machine, "blitter"));
- UINT8 *result_data = alloc_array_or_die(UINT8, rom_size);
+ UINT8 *result_data = auto_alloc_array(machine, UINT8, rom_size);
for (i=0; i<rom_size; i++)
result_data[i] = src[BITSWAP24(i, 23,22,21,20,19,18,17,16,15, 12, 13, 14, 11,10,9,8,7,6,5,4,3,2,1,0)];
memcpy(src,result_data,rom_size);
- free(result_data);
+ auto_free(machine, result_data);
}
diff --git a/src/mame/drivers/igs017.c b/src/mame/drivers/igs017.c
index ad280cd1be2..d3ea7b06fa2 100644
--- a/src/mame/drivers/igs017.c
+++ b/src/mame/drivers/igs017.c
@@ -534,7 +534,7 @@ static void mgcs_decrypt_tiles(running_machine *machine)
{
int length = memory_region_length(machine, "tilemaps");
UINT8 *rom = memory_region(machine, "tilemaps");
- UINT8 *tmp = alloc_array_or_die(UINT8, length);
+ UINT8 *tmp = auto_alloc_array(machine, UINT8, length);
int i;
memcpy(tmp,rom,length);
@@ -544,7 +544,7 @@ static void mgcs_decrypt_tiles(running_machine *machine)
rom[i] = tmp[addr];
}
- free(tmp);
+ auto_free(machine, tmp);
}
static void mgcs_flip_sprites(running_machine *machine)
diff --git a/src/mame/drivers/igs_m027.c b/src/mame/drivers/igs_m027.c
index 69721e244cc..2ea3d2576cc 100644
--- a/src/mame/drivers/igs_m027.c
+++ b/src/mame/drivers/igs_m027.c
@@ -269,7 +269,7 @@ static void sdwx_gfx_decrypt(running_machine *machine)
int i;
unsigned rom_size = 0x80000;
UINT8 *src = (UINT8 *) (memory_region(machine, "gfx1"));
- UINT8 *result_data = alloc_array_or_die(UINT8, rom_size);
+ UINT8 *result_data = auto_alloc_array(machine, UINT8, rom_size);
for (i=0; i<rom_size; i++)
result_data[i] = src[BITSWAP24(i, 23,22,21,20,19,18,17,16,15,14,13,12,11,8,7,6,10,9,5,4,3,2,1,0)];
@@ -281,7 +281,7 @@ static void sdwx_gfx_decrypt(running_machine *machine)
memcpy(src+i+0x100,result_data+i+0x080,0x80);
memcpy(src+i+0x180,result_data+i+0x180,0x80);
}
- free(result_data);
+ auto_free(machine, result_data);
}
/***************************************************************************
diff --git a/src/mame/drivers/igspoker.c b/src/mame/drivers/igspoker.c
index b9c9202729a..bf0bdf028b8 100644
--- a/src/mame/drivers/igspoker.c
+++ b/src/mame/drivers/igspoker.c
@@ -2084,7 +2084,7 @@ static DRIVER_INIT( number10 )
/* Descramble graphic */
rom = memory_region(machine, "gfx1");
length = memory_region_length(machine, "gfx1");
- tmp = alloc_array_or_die(UINT8, length);
+ tmp = auto_alloc_array(machine, UINT8, length);
memcpy(tmp,rom,length);
for (A = 0;A < length;A++)
{
@@ -2092,7 +2092,7 @@ static DRIVER_INIT( number10 )
rom[A] = tmp[addr];
}
- free(tmp);
+ auto_free(machine, tmp);
}
diff --git a/src/mame/drivers/legionna.c b/src/mame/drivers/legionna.c
index 10314b18c17..77c6b9b2847 100644
--- a/src/mame/drivers/legionna.c
+++ b/src/mame/drivers/legionna.c
@@ -958,13 +958,13 @@ static const gfx_layout legionna_new_charlayout =
};
-static void descramble_legionnaire_gfx(UINT8* src)
+static void descramble_legionnaire_gfx(running_machine *machine, UINT8* src)
{
UINT8 *buffer;
int len = 0x10000;
/* rearrange gfx */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0;i < len; i++)
@@ -978,7 +978,7 @@ static void descramble_legionnaire_gfx(UINT8* src)
3,2,1,0)];
}
memcpy(src,buffer,len);
- free(buffer);
+ auto_free(machine, buffer);
}
}
@@ -2102,7 +2102,7 @@ static DRIVER_INIT( denjinmk )
static DRIVER_INIT( legiongfx )
{
- descramble_legionnaire_gfx( memory_region(machine, "gfx5") );
+ descramble_legionnaire_gfx( machine, memory_region(machine, "gfx5") );
}
diff --git a/src/mame/drivers/megasys1.c b/src/mame/drivers/megasys1.c
index b6730d3341d..cbed064de79 100644
--- a/src/mame/drivers/megasys1.c
+++ b/src/mame/drivers/megasys1.c
@@ -3613,7 +3613,7 @@ static void rodlandj_gfx_unmangle(running_machine *machine, const char *region)
| ((rom[i] & 0x48) << 1)
| ((rom[i] & 0x10) << 2);
- buffer = alloc_array_or_die(UINT8, size);
+ buffer = auto_alloc_array(machine, UINT8, size);
memcpy(buffer,rom,size);
@@ -3628,7 +3628,7 @@ static void rodlandj_gfx_unmangle(running_machine *machine, const char *region)
rom[i] = buffer[a];
}
- free(buffer);
+ auto_free(machine, buffer);
}
static void jitsupro_gfx_unmangle(running_machine *machine, const char *region)
@@ -3642,7 +3642,7 @@ static void jitsupro_gfx_unmangle(running_machine *machine, const char *region)
for (i = 0;i < size;i++)
rom[i] = BITSWAP8(rom[i],0x4,0x3,0x5,0x7,0x6,0x2,0x1,0x0);
- buffer = alloc_array_or_die(UINT8, size);
+ buffer = auto_alloc_array(machine, UINT8, size);
memcpy(buffer,rom,size);
@@ -3655,7 +3655,7 @@ static void jitsupro_gfx_unmangle(running_machine *machine, const char *region)
rom[i] = buffer[a];
}
- free(buffer);
+ auto_free(machine, buffer);
}
/*************************************
diff --git a/src/mame/drivers/mitchell.c b/src/mame/drivers/mitchell.c
index 13fe7cb3d59..b6a0b4bc5b0 100644
--- a/src/mame/drivers/mitchell.c
+++ b/src/mame/drivers/mitchell.c
@@ -2189,7 +2189,7 @@ static DRIVER_INIT( mstworld )
{
/* descramble the program rom .. */
int len = memory_region_length(machine, "maincpu");
- UINT8* source = alloc_array_or_die(UINT8, len);
+ UINT8* source = auto_alloc_array(machine, UINT8, len);
UINT8* dst = memory_region(machine, "maincpu") ;
int x;
@@ -2226,7 +2226,7 @@ static DRIVER_INIT( mstworld )
memcpy(&dst[((x / 2) * 0x4000) + 0x50000],&source[tablebank[x + 1] * 0x4000], 0x4000);
}
}
- free(source);
+ auto_free(machine, source);
bootleg_decode(machine);
configure_banks(machine);
diff --git a/src/mame/drivers/model3.c b/src/mame/drivers/model3.c
index 96fe4acdf8c..55c6e7e82cd 100644
--- a/src/mame/drivers/model3.c
+++ b/src/mame/drivers/model3.c
@@ -1123,7 +1123,7 @@ static void real3d_dma_callback(running_machine *machine, UINT32 src, UINT32 dst
switch(dst >> 24)
{
case 0x88: /* Display List End Trigger */
- real3d_display_list_end();
+ real3d_display_list_end(machine);
break;
case 0x8c: /* Display List RAM 2 */
real3d_display_list2_dma(space, src, dst, length, byteswap);
diff --git a/src/mame/drivers/ms32.c b/src/mame/drivers/ms32.c
index 8898c624a93..64b513e45f3 100644
--- a/src/mame/drivers/ms32.c
+++ b/src/mame/drivers/ms32.c
@@ -2147,7 +2147,7 @@ void ms32_rearrange_sprites(running_machine *machine, const char *region)
source_data = memory_region ( machine, region );
source_size = memory_region_length( machine, region );
- result_data = alloc_array_or_die(UINT8, source_size);
+ result_data = auto_alloc_array(machine, UINT8, source_size);
for(i=0; i<source_size; i++)
{
@@ -2157,7 +2157,7 @@ void ms32_rearrange_sprites(running_machine *machine, const char *region)
}
memcpy (source_data, result_data, source_size);
- free (result_data);
+ auto_free (machine, result_data);
}
@@ -2172,7 +2172,7 @@ void decrypt_ms32_tx(running_machine *machine, int addr_xor,int data_xor, const
source_data = memory_region ( machine, region );
source_size = memory_region_length( machine, region );
- result_data = alloc_array_or_die(UINT8, source_size);
+ result_data = auto_alloc_array(machine, UINT8, source_size);
addr_xor ^= 0x1005d;
@@ -2212,7 +2212,7 @@ void decrypt_ms32_tx(running_machine *machine, int addr_xor,int data_xor, const
}
memcpy (source_data, result_data, source_size);
- free (result_data);
+ auto_free (machine, result_data);
}
void decrypt_ms32_bg(running_machine *machine, int addr_xor,int data_xor, const char *region)
@@ -2226,7 +2226,7 @@ void decrypt_ms32_bg(running_machine *machine, int addr_xor,int data_xor, const
source_data = memory_region ( machine, region );
source_size = memory_region_length( machine, region );
- result_data = alloc_array_or_die(UINT8, source_size);
+ result_data = auto_alloc_array(machine, UINT8, source_size);
addr_xor ^= 0xc1c5b;
@@ -2267,7 +2267,7 @@ void decrypt_ms32_bg(running_machine *machine, int addr_xor,int data_xor, const
}
memcpy (source_data, result_data, source_size);
- free (result_data);
+ auto_free (machine, result_data);
}
diff --git a/src/mame/drivers/mustache.c b/src/mame/drivers/mustache.c
index bd092106204..c8a699a0744 100644
--- a/src/mame/drivers/mustache.c
+++ b/src/mame/drivers/mustache.c
@@ -265,7 +265,7 @@ static DRIVER_INIT( mustache )
int G2 = memory_region_length(machine, "gfx2")/2;
UINT8 *gfx1 = memory_region(machine, "gfx1");
UINT8 *gfx2 = memory_region(machine, "gfx2");
- UINT8 *buf=alloc_array_or_die(UINT8, G2*2);
+ UINT8 *buf=auto_alloc_array(machine, UINT8, G2*2);
/* BG data lines */
for (i=0;i<G1; i++)
@@ -301,7 +301,7 @@ static DRIVER_INIT( mustache )
for (i = 0; i < 2*G2; i++)
gfx2[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,12,11,10,9,8,7,6,5,4,13,14,3,2,1,0)];
- free(buf);
+ auto_free(machine, buf);
seibu_sound_decrypt(machine,"maincpu",0x8000);
}
diff --git a/src/mame/drivers/namcos86.c b/src/mame/drivers/namcos86.c
index 39273c47868..393c851fe2a 100644
--- a/src/mame/drivers/namcos86.c
+++ b/src/mame/drivers/namcos86.c
@@ -1505,7 +1505,7 @@ static DRIVER_INIT( namco86 )
/* shuffle tile ROMs so regular gfx unpack routines can be used */
gfx = memory_region(machine, "gfx1");
size = memory_region_length(machine, "gfx1") * 2 / 3;
- buffer = alloc_array_or_die(UINT8, size );
+ buffer = auto_alloc_array(machine, UINT8, size );
{
UINT8 *dest1 = gfx;
@@ -1525,12 +1525,12 @@ static DRIVER_INIT( namco86 )
*mono ^= 0xff; mono++;
}
- free( buffer );
+ auto_free( machine, buffer );
}
gfx = memory_region(machine, "gfx2");
size = memory_region_length(machine, "gfx2") * 2 / 3;
- buffer = alloc_array_or_die(UINT8, size );
+ buffer = auto_alloc_array(machine, UINT8, size );
{
UINT8 *dest1 = gfx;
@@ -1550,7 +1550,7 @@ static DRIVER_INIT( namco86 )
*mono ^= 0xff; mono++;
}
- free( buffer );
+ auto_free( machine, buffer );
}
}
diff --git a/src/mame/drivers/ninjakd2.c b/src/mame/drivers/ninjakd2.c
index 9ed6b0925e1..010557aa1f3 100644
--- a/src/mame/drivers/ninjakd2.c
+++ b/src/mame/drivers/ninjakd2.c
@@ -1404,7 +1404,7 @@ static void lineswap_gfx_roms(running_machine *machine, const char *region, cons
UINT8* const src = memory_region(machine, region);
- UINT8* const temp = alloc_array_or_die(UINT8, length);
+ UINT8* const temp = auto_alloc_array(machine, UINT8, length);
const int mask = (1 << (bit + 1)) - 1;
@@ -1419,7 +1419,7 @@ static void lineswap_gfx_roms(running_machine *machine, const char *region, cons
memcpy(src, temp, length);
- free(temp);
+ auto_free(machine, temp);
}
static void gfx_unscramble(running_machine *machine)
diff --git a/src/mame/drivers/nmk16.c b/src/mame/drivers/nmk16.c
index 2a1acb86ac7..69d029bf045 100644
--- a/src/mame/drivers/nmk16.c
+++ b/src/mame/drivers/nmk16.c
@@ -5022,15 +5022,15 @@ static void decryptcode( running_machine *machine, int a23, int a22, int a21, in
int i;
UINT8 *RAM = memory_region( machine, "maincpu" );
size_t size = memory_region_length( machine, "maincpu" );
- UINT8 *buffer = alloc_array_or_die(UINT8, size );
+ UINT8 *buffer = auto_alloc_array(machine, UINT8, size );
- memcpy( buffer, RAM, size );
- for( i = 0; i < size; i++ )
- {
- RAM[ i ] = buffer[ BITSWAP24( i, a23, a22, a21, a20, a19, a18, a17, a16, a15, a14, a13, a12,
- a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0 ) ];
- }
- free( buffer );
+ memcpy( buffer, RAM, size );
+ for( i = 0; i < size; i++ )
+ {
+ RAM[ i ] = buffer[ BITSWAP24( i, a23, a22, a21, a20, a19, a18, a17, a16, a15, a14, a13, a12,
+ a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0 ) ];
+ }
+ auto_free( machine, buffer );
}
diff --git a/src/mame/drivers/nova2001.c b/src/mame/drivers/nova2001.c
index 2b76156a073..c753b14aaa8 100644
--- a/src/mame/drivers/nova2001.c
+++ b/src/mame/drivers/nova2001.c
@@ -989,7 +989,7 @@ static void lineswap_gfx_roms(running_machine *machine, const char *region, cons
UINT8* const src = memory_region(machine, region);
- UINT8* const temp = alloc_array_or_die(UINT8, length);
+ UINT8* const temp = auto_alloc_array(machine, UINT8, length);
const int mask = (1 << (bit + 1)) - 1;
@@ -1004,7 +1004,7 @@ static void lineswap_gfx_roms(running_machine *machine, const char *region, cons
memcpy(src, temp, length);
- free(temp);
+ auto_free(machine, temp);
}
diff --git a/src/mame/drivers/panicr.c b/src/mame/drivers/panicr.c
index 6da7617c706..fa12d0c3ccb 100644
--- a/src/mame/drivers/panicr.c
+++ b/src/mame/drivers/panicr.c
@@ -439,7 +439,7 @@ ROM_END
static DRIVER_INIT( panicr )
{
- UINT8 *buf = alloc_array_or_die(UINT8, 0x80000);
+ UINT8 *buf = auto_alloc_array(machine, UINT8, 0x80000);
UINT8 *rom;
int size;
int i;
@@ -546,7 +546,7 @@ static DRIVER_INIT( panicr )
}
}
- free(buf);
+ auto_free(machine, buf);
}
diff --git a/src/mame/drivers/pirates.c b/src/mame/drivers/pirates.c
index 9769c4e5da3..4ef08bde203 100644
--- a/src/mame/drivers/pirates.c
+++ b/src/mame/drivers/pirates.c
@@ -355,7 +355,7 @@ static void pirates_decrypt_68k(running_machine *machine)
rom_size = memory_region_length(machine, "maincpu");
- buf = alloc_array_or_die(UINT16, rom_size/2);
+ buf = auto_alloc_array(machine, UINT16, rom_size/2);
rom = (UINT16 *)memory_region(machine, "maincpu");
memcpy (buf, rom, rom_size);
@@ -373,7 +373,7 @@ static void pirates_decrypt_68k(running_machine *machine)
rom[i] = (vr<<8) | vl;
}
- free (buf);
+ auto_free (machine, buf);
}
static void pirates_decrypt_p(running_machine *machine)
@@ -384,7 +384,7 @@ static void pirates_decrypt_p(running_machine *machine)
rom_size = memory_region_length(machine, "gfx1");
- buf = alloc_array_or_die(UINT8, rom_size);
+ buf = auto_alloc_array(machine, UINT8, rom_size);
rom = memory_region(machine, "gfx1");
memcpy (buf, rom, rom_size);
@@ -397,7 +397,7 @@ static void pirates_decrypt_p(running_machine *machine)
rom[adr+2*(rom_size/4)] = BITSWAP8(buf[i+2*(rom_size/4)], 1,4,7,0,3,5,6,2);
rom[adr+3*(rom_size/4)] = BITSWAP8(buf[i+3*(rom_size/4)], 2,3,4,0,7,5,1,6);
}
- free (buf);
+ auto_free (machine, buf);
}
static void pirates_decrypt_s(running_machine *machine)
@@ -408,7 +408,7 @@ static void pirates_decrypt_s(running_machine *machine)
rom_size = memory_region_length(machine, "gfx2");
- buf = alloc_array_or_die(UINT8, rom_size);
+ buf = auto_alloc_array(machine, UINT8, rom_size);
rom = memory_region(machine, "gfx2");
memcpy (buf, rom, rom_size);
@@ -421,7 +421,7 @@ static void pirates_decrypt_s(running_machine *machine)
rom[adr+2*(rom_size/4)] = BITSWAP8(buf[i+2*(rom_size/4)], 2,3,4,0,7,5,1,6);
rom[adr+3*(rom_size/4)] = BITSWAP8(buf[i+3*(rom_size/4)], 4,2,7,1,6,5,0,3);
}
- free (buf);
+ auto_free (machine, buf);
}
@@ -433,7 +433,7 @@ static void pirates_decrypt_oki(running_machine *machine)
rom_size = memory_region_length(machine, "oki");
- buf = alloc_array_or_die(UINT8, rom_size);
+ buf = auto_alloc_array(machine, UINT8, rom_size);
rom = memory_region(machine, "oki");
memcpy (buf, rom, rom_size);
@@ -443,7 +443,7 @@ static void pirates_decrypt_oki(running_machine *machine)
int adr = BITSWAP24(i,23,22,21,20,19,10,16,13,8,4,7,11,14,17,12,6,2,0,5,18,15,3,1,9);
rom[adr] = BITSWAP8(buf[i], 2,3,4,0,7,5,1,6);
}
- free (buf);
+ auto_free (machine, buf);
}
diff --git a/src/mame/drivers/popeye.c b/src/mame/drivers/popeye.c
index 95771c40548..9c3a8350468 100644
--- a/src/mame/drivers/popeye.c
+++ b/src/mame/drivers/popeye.c
@@ -644,13 +644,13 @@ static DRIVER_INIT( skyskipr )
int len = 0x10000;
/* decrypt the program ROMs */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0;i < len; i++)
buffer[i] = BITSWAP8(rom[BITSWAP16(i,15,14,13,12,11,10,8,7,0,1,2,4,5,9,3,6) ^ 0xfc],3,4,2,5,1,6,0,7);
memcpy(rom,buffer,len);
- free(buffer);
+ auto_free(machine, buffer);
}
state_save_register_global(machine, prot0);
@@ -665,13 +665,13 @@ static DRIVER_INIT( popeye )
int len = 0x10000;
/* decrypt the program ROMs */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0;i < len; i++)
buffer[i] = BITSWAP8(rom[BITSWAP16(i,15,14,13,12,11,10,8,7,6,3,9,5,4,2,1,0) ^ 0x3f],3,4,2,5,1,6,0,7);
memcpy(rom,buffer,len);
- free(buffer);
+ auto_free(machine, buffer);
}
state_save_register_global(machine, prot0);
diff --git a/src/mame/drivers/segag80r.c b/src/mame/drivers/segag80r.c
index 21457c7d12f..84e03479cee 100644
--- a/src/mame/drivers/segag80r.c
+++ b/src/mame/drivers/segag80r.c
@@ -1426,7 +1426,7 @@ static void monsterb_expand_gfx(running_machine *machine, const char *region)
/* expand the background ROMs; A11/A12 of each ROM is independently controlled via */
/* banking */
dest = memory_region(machine, region);
- temp = alloc_array_or_die(UINT8, 0x4000);
+ temp = auto_alloc_array(machine, UINT8, 0x4000);
memcpy(temp, dest, 0x4000);
/* 16 effective total banks */
@@ -1435,7 +1435,7 @@ static void monsterb_expand_gfx(running_machine *machine, const char *region)
memcpy(&dest[0x0000 + i * 0x800], &temp[0x0000 + (i & 3) * 0x800], 0x800);
memcpy(&dest[0x8000 + i * 0x800], &temp[0x2000 + (i >> 2) * 0x800], 0x800);
}
- free(temp);
+ auto_free(machine, temp);
}
diff --git a/src/mame/drivers/seta.c b/src/mame/drivers/seta.c
index 89435c0947e..3e6616c62e9 100644
--- a/src/mame/drivers/seta.c
+++ b/src/mame/drivers/seta.c
@@ -9891,7 +9891,7 @@ static DRIVER_INIT ( blandia )
int rpos;
rom_size = 0x80000;
- buf = alloc_array_or_die(UINT8, rom_size);
+ buf = auto_alloc_array(machine, UINT8, rom_size);
rom = memory_region(machine, "gfx2") + 0x40000;
@@ -9911,7 +9911,7 @@ static DRIVER_INIT ( blandia )
memcpy( rom, buf, rom_size );
- free(buf);
+ auto_free(machine, buf);
}
diff --git a/src/mame/drivers/silkroad.c b/src/mame/drivers/silkroad.c
index c377173662a..547bd977bc7 100644
--- a/src/mame/drivers/silkroad.c
+++ b/src/mame/drivers/silkroad.c
@@ -345,13 +345,13 @@ static DRIVER_INIT( silkroad )
src += tileoffset; len -=tileoffset;
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0;i < len; i++)
buffer[i] = src[i-1];
memcpy(src,buffer,len);
- free(buffer);
+ auto_free(machine, buffer);
}
}
diff --git a/src/mame/drivers/simpl156.c b/src/mame/drivers/simpl156.c
index 18a33afac2d..9dd2a506046 100644
--- a/src/mame/drivers/simpl156.c
+++ b/src/mame/drivers/simpl156.c
@@ -513,7 +513,7 @@ static DRIVER_INIT(simpl156)
{
UINT8 *rom = memory_region(machine, "okimusic");
int length = memory_region_length(machine, "okimusic");
- UINT8 *buf1 = alloc_array_or_die(UINT8, length);
+ UINT8 *buf1 = auto_alloc_array(machine, UINT8, length);
UINT32 x;
@@ -534,7 +534,7 @@ static DRIVER_INIT(simpl156)
memcpy(rom,buf1,length);
- free (buf1);
+ auto_free (machine, buf1);
deco56_decrypt_gfx(machine, "gfx1");
deco156_decrypt(machine);
diff --git a/src/mame/drivers/snowbros.c b/src/mame/drivers/snowbros.c
index 6c63ccfc1e9..00e76c85c50 100644
--- a/src/mame/drivers/snowbros.c
+++ b/src/mame/drivers/snowbros.c
@@ -2681,7 +2681,7 @@ static DRIVER_INIT(4in1boot)
int len = memory_region_length(machine, "maincpu");
/* strange order */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0;i < len; i++)
@@ -2689,20 +2689,20 @@ static DRIVER_INIT(4in1boot)
else buffer[i] = src[i];
memcpy(src,buffer,len);
- free(buffer);
+ auto_free(machine, buffer);
}
src = memory_region(machine, "soundcpu");
len = memory_region_length(machine, "soundcpu");
/* strange order */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0;i < len; i++)
buffer[i] = src[i^0x4000];
memcpy(src,buffer,len);
- free(buffer);
+ auto_free(machine, buffer);
}
memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x200000, 0x200001, 0, 0, _4in1_02_read );
}
@@ -2714,13 +2714,13 @@ static DRIVER_INIT(snowbro3)
int len = memory_region_length(machine, "maincpu");
/* strange order */
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
{
int i;
for (i = 0;i < len; i++)
buffer[i] = src[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,3,4,1,2,0)];
memcpy(src,buffer,len);
- free(buffer);
+ auto_free(machine, buffer);
}
}
diff --git a/src/mame/drivers/tcl.c b/src/mame/drivers/tcl.c
index 87fab6877ac..1013f962c9e 100644
--- a/src/mame/drivers/tcl.c
+++ b/src/mame/drivers/tcl.c
@@ -183,7 +183,7 @@ static DRIVER_INIT(tcl)
const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
UINT8 *dest = memory_region(machine, "maincpu");
int len = memory_region_length(machine, "maincpu");
- UINT8 *src = alloc_array_or_die(UINT8, len);
+ UINT8 *src = auto_alloc_array(machine, UINT8, len);
int i,idx=0;
memcpy(src, dest, len);
@@ -204,7 +204,7 @@ static DRIVER_INIT(tcl)
WRITEDEST((src[idx]^0x11)^0xf0); // abcdefgh -> ABCdefgH
}
}
- free(src);
+ auto_free(machine, src);
memory_set_decrypted_region(space, 0x0000, 0x7fff, dest+0x10000);
}
diff --git a/src/mame/drivers/tmnt.c b/src/mame/drivers/tmnt.c
index 3c3065ba441..b28de62bb39 100644
--- a/src/mame/drivers/tmnt.c
+++ b/src/mame/drivers/tmnt.c
@@ -4068,7 +4068,7 @@ static DRIVER_INIT( mia )
}
}
- temp = alloc_array_or_die(UINT8, len);
+ temp = auto_alloc_array(machine, UINT8, len);
memcpy(temp, gfxdata, len);
for (A = 0; A < len / 4; A++)
{
@@ -4106,7 +4106,7 @@ static DRIVER_INIT( mia )
gfxdata[4 * A + 2] = temp[4 * B + 2];
gfxdata[4 * A + 3] = temp[4 * B + 3];
}
- free(temp);
+ auto_free(machine, temp);
}
@@ -4161,7 +4161,7 @@ static DRIVER_INIT( tmnt )
}
}
- temp = alloc_array_or_die(UINT8, len);
+ temp = auto_alloc_array(machine, UINT8, len);
memcpy(temp, gfxdata, len);
code_conv_table = &memory_region(machine, "proms")[0x0000];
for (A = 0; A < len / 4; A++)
@@ -4213,7 +4213,7 @@ static DRIVER_INIT( tmnt )
gfxdata[4 * A + 2] = temp[4 * B + 2];
gfxdata[4 * A + 3] = temp[4 * B + 3];
}
- free(temp);
+ auto_free(machine, temp);
}
static DRIVER_INIT( cuebrick )
diff --git a/src/mame/drivers/toki.c b/src/mame/drivers/toki.c
index 3df5bfcf233..54b6c5fc291 100644
--- a/src/mame/drivers/toki.c
+++ b/src/mame/drivers/toki.c
@@ -726,7 +726,7 @@ ROM_END
static DRIVER_INIT( toki )
{
UINT8 *ROM = memory_region(machine, "oki");
- UINT8 *buffer = alloc_array_or_die(UINT8, 0x20000);
+ UINT8 *buffer = auto_alloc_array(machine, UINT8, 0x20000);
int i;
memcpy(buffer,ROM,0x20000);
@@ -735,7 +735,7 @@ static DRIVER_INIT( toki )
ROM[i] = buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,13,14,15,12,11,10,9,8,7,6,5,4,3,2,1,0)];
}
- free(buffer);
+ auto_free(machine, buffer);
seibu_sound_decrypt(machine,"audiocpu",0x2000);
}
@@ -743,7 +743,7 @@ static DRIVER_INIT( toki )
static DRIVER_INIT( tokib )
{
- UINT8 *temp = alloc_array_or_die(UINT8, 65536 * 2);
+ UINT8 *temp = auto_alloc_array(machine, UINT8, 65536 * 2);
int i, offs, len;
UINT8 *rom;
@@ -754,36 +754,36 @@ static DRIVER_INIT( tokib )
rom[i] ^= 0xff;
/* merge background tile graphics together */
- len = memory_region_length(machine, "gfx3");
- rom = memory_region(machine, "gfx3");
- for (offs = 0; offs < len; offs += 0x20000)
+ len = memory_region_length(machine, "gfx3");
+ rom = memory_region(machine, "gfx3");
+ for (offs = 0; offs < len; offs += 0x20000)
+ {
+ UINT8 *base = &rom[offs];
+ memcpy (temp, base, 65536 * 2);
+ for (i = 0; i < 16; i++)
{
- UINT8 *base = &rom[offs];
- memcpy (temp, base, 65536 * 2);
- for (i = 0; i < 16; i++)
- {
- memcpy (&base[0x00000 + i * 0x800], &temp[0x0000 + i * 0x2000], 0x800);
- memcpy (&base[0x10000 + i * 0x800], &temp[0x0800 + i * 0x2000], 0x800);
- memcpy (&base[0x08000 + i * 0x800], &temp[0x1000 + i * 0x2000], 0x800);
- memcpy (&base[0x18000 + i * 0x800], &temp[0x1800 + i * 0x2000], 0x800);
- }
+ memcpy (&base[0x00000 + i * 0x800], &temp[0x0000 + i * 0x2000], 0x800);
+ memcpy (&base[0x10000 + i * 0x800], &temp[0x0800 + i * 0x2000], 0x800);
+ memcpy (&base[0x08000 + i * 0x800], &temp[0x1000 + i * 0x2000], 0x800);
+ memcpy (&base[0x18000 + i * 0x800], &temp[0x1800 + i * 0x2000], 0x800);
}
- len = memory_region_length(machine, "gfx4");
- rom = memory_region(machine, "gfx4");
- for (offs = 0; offs < len; offs += 0x20000)
+ }
+ len = memory_region_length(machine, "gfx4");
+ rom = memory_region(machine, "gfx4");
+ for (offs = 0; offs < len; offs += 0x20000)
+ {
+ UINT8 *base = &rom[offs];
+ memcpy (temp, base, 65536 * 2);
+ for (i = 0; i < 16; i++)
{
- UINT8 *base = &rom[offs];
- memcpy (temp, base, 65536 * 2);
- for (i = 0; i < 16; i++)
- {
- memcpy (&base[0x00000 + i * 0x800], &temp[0x0000 + i * 0x2000], 0x800);
- memcpy (&base[0x10000 + i * 0x800], &temp[0x0800 + i * 0x2000], 0x800);
- memcpy (&base[0x08000 + i * 0x800], &temp[0x1000 + i * 0x2000], 0x800);
- memcpy (&base[0x18000 + i * 0x800], &temp[0x1800 + i * 0x2000], 0x800);
- }
+ memcpy (&base[0x00000 + i * 0x800], &temp[0x0000 + i * 0x2000], 0x800);
+ memcpy (&base[0x10000 + i * 0x800], &temp[0x0800 + i * 0x2000], 0x800);
+ memcpy (&base[0x08000 + i * 0x800], &temp[0x1000 + i * 0x2000], 0x800);
+ memcpy (&base[0x18000 + i * 0x800], &temp[0x1800 + i * 0x2000], 0x800);
}
+ }
- free (temp);
+ auto_free (machine, temp);
}
static DRIVER_INIT(jujub)
@@ -822,7 +822,7 @@ static DRIVER_INIT(jujub)
{
UINT8 *ROM = memory_region(machine, "oki");
- UINT8 *buffer = alloc_array_or_die(UINT8, 0x20000);
+ UINT8 *buffer = auto_alloc_array(machine, UINT8, 0x20000);
int i;
memcpy(buffer,ROM,0x20000);
@@ -831,7 +831,7 @@ static DRIVER_INIT(jujub)
ROM[i] = buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,13,14,15,12,11,10,9,8,7,6,5,4,3,2,1,0)];
}
- free(buffer);
+ auto_free(machine, buffer);
}
}
diff --git a/src/mame/drivers/travrusa.c b/src/mame/drivers/travrusa.c
index 41120483e39..79db698cc3c 100644
--- a/src/mame/drivers/travrusa.c
+++ b/src/mame/drivers/travrusa.c
@@ -459,18 +459,18 @@ static DRIVER_INIT( motorace )
{
int A, j;
UINT8 *rom = memory_region(machine, "maincpu");
- UINT8 *buffer = alloc_array_or_die(UINT8, 0x2000);
+ UINT8 *buffer = auto_alloc_array(machine, UINT8, 0x2000);
- memcpy(buffer, rom, 0x2000);
+ memcpy(buffer, rom, 0x2000);
- /* The first CPU ROM has the address and data lines scrambled */
- for (A = 0; A < 0x2000; A++)
- {
- j = BITSWAP16(A,15,14,13,9,7,5,3,1,12,10,8,6,4,2,0,11);
- rom[j] = BITSWAP8(buffer[A],2,7,4,1,6,3,0,5);
- }
+ /* The first CPU ROM has the address and data lines scrambled */
+ for (A = 0; A < 0x2000; A++)
+ {
+ j = BITSWAP16(A,15,14,13,9,7,5,3,1,12,10,8,6,4,2,0,11);
+ rom[j] = BITSWAP8(buffer[A],2,7,4,1,6,3,0,5);
+ }
- free(buffer);
+ auto_free(machine, buffer);
}
static DRIVER_INIT( shtridra )
diff --git a/src/mame/drivers/tumbleb.c b/src/mame/drivers/tumbleb.c
index edab73eb9aa..a791cd6b53d 100644
--- a/src/mame/drivers/tumbleb.c
+++ b/src/mame/drivers/tumbleb.c
@@ -3591,38 +3591,36 @@ static DRIVER_INIT( htchctch )
static void suprtrio_decrypt_code(running_machine *machine)
{
UINT16 *rom = (UINT16 *)memory_region(machine, "maincpu");
- UINT16 *buf = alloc_array_or_die(UINT16, 0x80000/2);
+ UINT16 *buf = auto_alloc_array(machine, UINT16, 0x80000/2);
int i;
/* decrypt main ROMs */
+ memcpy(buf,rom,0x80000);
+ for (i = 0;i < 0x40000;i++)
{
- memcpy(buf,rom,0x80000);
- for (i = 0;i < 0x40000;i++)
- {
- int j = i ^ 0x06;
- if ((i & 1) == 0) j ^= 0x02;
- if ((i & 3) == 0) j ^= 0x08;
- rom[i] = buf[j];
- }
- free(buf);
+ int j = i ^ 0x06;
+ if ((i & 1) == 0) j ^= 0x02;
+ if ((i & 3) == 0) j ^= 0x08;
+ rom[i] = buf[j];
}
+ auto_free(machine, buf);
}
static void suprtrio_decrypt_gfx(running_machine *machine)
{
UINT16 *rom = (UINT16 *)memory_region(machine, "gfx1");
- UINT16 *buf = alloc_array_or_die(UINT16, 0x100000/2);
+ UINT16 *buf = auto_alloc_array(machine, UINT16, 0x100000/2);
int i;
/* decrypt tiles */
- memcpy(buf,rom,0x100000);
- for (i = 0;i < 0x80000;i++)
- {
- int j = i ^ 0x02;
- if (i & 1) j ^= 0x04;
- rom[i] = buf[j];
- }
- free(buf);
+ memcpy(buf,rom,0x100000);
+ for (i = 0;i < 0x80000;i++)
+ {
+ int j = i ^ 0x02;
+ if (i & 1) j ^= 0x04;
+ rom[i] = buf[j];
+ }
+ auto_free(machine, buf);
}
static DRIVER_INIT( suprtrio )
diff --git a/src/mame/drivers/twin16.c b/src/mame/drivers/twin16.c
index 07b65438398..9c42e3a5961 100644
--- a/src/mame/drivers/twin16.c
+++ b/src/mame/drivers/twin16.c
@@ -1303,7 +1303,7 @@ static void gfx_untangle( running_machine *machine )
{
// sprite, tile data
int i;
- UINT16 *temp = alloc_array_or_die(UINT16, 0x200000/2);
+ UINT16 *temp = auto_alloc_array(machine, UINT16, 0x200000/2);
twin16_gfx_rom = (UINT16 *)memory_region(machine, "gfx2");
memcpy( temp, twin16_gfx_rom, 0x200000 );
@@ -1313,7 +1313,7 @@ static void gfx_untangle( running_machine *machine )
twin16_gfx_rom[i*2+0] = temp[i+0x080000];
twin16_gfx_rom[i*2+1] = temp[i];
}
- free( temp );
+ auto_free( machine, temp );
}
static DRIVER_INIT( twin16 )
diff --git a/src/mame/drivers/wecleman.c b/src/mame/drivers/wecleman.c
index 6eadd87bd13..0ee54a4239b 100644
--- a/src/mame/drivers/wecleman.c
+++ b/src/mame/drivers/wecleman.c
@@ -1247,20 +1247,18 @@ static void wecleman_unpack_sprites(running_machine *machine)
}
}
-static void bitswap(UINT8 *src,size_t len,int _14,int _13,int _12,int _11,int _10,int _f,int _e,int _d,int _c,int _b,int _a,int _9,int _8,int _7,int _6,int _5,int _4,int _3,int _2,int _1,int _0)
+static void bitswap(running_machine *machine,UINT8 *src,size_t len,int _14,int _13,int _12,int _11,int _10,int _f,int _e,int _d,int _c,int _b,int _a,int _9,int _8,int _7,int _6,int _5,int _4,int _3,int _2,int _1,int _0)
{
- UINT8 *buffer = alloc_array_or_die(UINT8, len);
- {
- int i;
+ UINT8 *buffer = auto_alloc_array(machine, UINT8, len);
+ int i;
- memcpy(buffer,src,len);
- for (i = 0;i < len;i++)
- {
- src[i] =
- buffer[BITSWAP24(i,23,22,21,_14,_13,_12,_11,_10,_f,_e,_d,_c,_b,_a,_9,_8,_7,_6,_5,_4,_3,_2,_1,_0)];
- }
- free(buffer);
+ memcpy(buffer,src,len);
+ for (i = 0;i < len;i++)
+ {
+ src[i] =
+ buffer[BITSWAP24(i,23,22,21,_14,_13,_12,_11,_10,_f,_e,_d,_c,_b,_a,_9,_8,_7,_6,_5,_4,_3,_2,_1,_0)];
}
+ auto_free(machine, buffer);
}
/* Unpack sprites data and do some patching */
@@ -1288,18 +1286,18 @@ static DRIVER_INIT( wecleman )
RAM[i] = BITSWAP8(RAM[i],7,0,1,2,3,4,5,6);
}
- bitswap(memory_region(machine, "gfx1"), memory_region_length(machine, "gfx1"),
+ bitswap(machine, memory_region(machine, "gfx1"), memory_region_length(machine, "gfx1"),
0,1,20,19,18,17,14,9,16,6,4,7,8,15,10,11,13,5,12,3,2);
/* Now we can unpack each nibble of the sprites into a pixel (one byte) */
wecleman_unpack_sprites(machine);
/* Bg & Fg & Txt */
- bitswap(memory_region(machine, "gfx2"), memory_region_length(machine, "gfx2"),
+ bitswap(machine, memory_region(machine, "gfx2"), memory_region_length(machine, "gfx2"),
20,19,18,17,16,15,12,7,14,4,2,5,6,13,8,9,11,3,10,1,0);
/* Road */
- bitswap(memory_region(machine, "gfx3"), memory_region_length(machine, "gfx3"),
+ bitswap(machine, memory_region(machine, "gfx3"), memory_region_length(machine, "gfx3"),
20,19,18,17,16,15,14,7,12,4,2,5,6,13,8,9,11,3,10,1,0);
spr_color_offs = 0x40;
@@ -1365,7 +1363,7 @@ static void hotchase_sprite_decode( running_machine *machine, int num16_banks, i
int i;
base = memory_region(machine, "gfx1"); // sprites
- temp = alloc_array_or_die(UINT8, bank_size );
+ temp = auto_alloc_array(machine, UINT8, bank_size );
for( i = num16_banks; i >0; i-- ){
UINT8 *finish = base + 2*bank_size*i;
@@ -1403,7 +1401,7 @@ static void hotchase_sprite_decode( running_machine *machine, int num16_banks, i
*dest++ = data & 0xF;
} while( dest<finish );
}
- free( temp );
+ auto_free( machine, temp );
}
/* Unpack sprites data and do some patching */
diff --git a/src/mame/drivers/wink.c b/src/mame/drivers/wink.c
index 2d353739c51..78ec5b9cc97 100644
--- a/src/mame/drivers/wink.c
+++ b/src/mame/drivers/wink.c
@@ -385,25 +385,25 @@ static DRIVER_INIT( wink )
{
UINT32 i;
UINT8 *ROM = memory_region(machine, "maincpu");
- UINT8 *buffer = alloc_array_or_die(UINT8, 0x8000);
+ UINT8 *buffer = auto_alloc_array(machine, UINT8, 0x8000);
// protection module reverse engineered by HIGHWAYMAN
- memcpy(buffer,ROM,0x8000);
+ memcpy(buffer,ROM,0x8000);
- for (i = 0x0000; i <= 0x1fff; i++)
- ROM[i] = buffer[BITSWAP16(i,15,14,13, 11,12, 7, 9, 8,10, 6, 4, 5, 1, 2, 3, 0)];
+ for (i = 0x0000; i <= 0x1fff; i++)
+ ROM[i] = buffer[BITSWAP16(i,15,14,13, 11,12, 7, 9, 8,10, 6, 4, 5, 1, 2, 3, 0)];
- for (i = 0x2000; i <= 0x3fff; i++)
- ROM[i] = buffer[BITSWAP16(i,15,14,13, 10, 7,12, 9, 8,11, 6, 3, 1, 5, 2, 4, 0)];
+ for (i = 0x2000; i <= 0x3fff; i++)
+ ROM[i] = buffer[BITSWAP16(i,15,14,13, 10, 7,12, 9, 8,11, 6, 3, 1, 5, 2, 4, 0)];
- for (i = 0x4000; i <= 0x5fff; i++)
- ROM[i] = buffer[BITSWAP16(i,15,14,13, 7,10,11, 9, 8,12, 6, 1, 3, 4, 2, 5, 0)];
+ for (i = 0x4000; i <= 0x5fff; i++)
+ ROM[i] = buffer[BITSWAP16(i,15,14,13, 7,10,11, 9, 8,12, 6, 1, 3, 4, 2, 5, 0)];
- for (i = 0x6000; i <= 0x7fff; i++)
- ROM[i] = buffer[BITSWAP16(i,15,14,13, 11,12, 7, 9, 8,10, 6, 4, 5, 1, 2, 3, 0)];
+ for (i = 0x6000; i <= 0x7fff; i++)
+ ROM[i] = buffer[BITSWAP16(i,15,14,13, 11,12, 7, 9, 8,10, 6, 4, 5, 1, 2, 3, 0)];
- free(buffer);
+ auto_free(machine, buffer);
for (i = 0; i < 0x8000; i++)
ROM[i] += BITSWAP8(i & 0xff, 7,5,3,1,6,4,2,0);
diff --git a/src/mame/includes/model3.h b/src/mame/includes/model3.h
index 3b7f15f66ba..d6a5200922a 100644
--- a/src/mame/includes/model3.h
+++ b/src/mame/includes/model3.h
@@ -35,7 +35,7 @@ VIDEO_UPDATE(model3);
WRITE64_HANDLER(real3d_cmd_w);
WRITE64_HANDLER(real3d_display_list_w);
WRITE64_HANDLER(real3d_polygon_ram_w);
-void real3d_display_list_end(void);
+void real3d_display_list_end(running_machine *machine);
void real3d_display_list1_dma(const address_space *space, UINT32 src, UINT32 dst, int length, int byteswap);
void real3d_display_list2_dma(const address_space *space, UINT32 src, UINT32 dst, int length, int byteswap);
void real3d_vrom_texture_dma(const address_space *space, UINT32 src, UINT32 dst, int length, int byteswap);
diff --git a/src/mame/machine/deco102.c b/src/mame/machine/deco102.c
index 846d374f4a7..bc747b7e706 100644
--- a/src/mame/machine/deco102.c
+++ b/src/mame/machine/deco102.c
@@ -54,40 +54,40 @@ void deco102_decrypt_cpu(running_machine *machine, const char *cputag, int addre
UINT16 *rom = (UINT16 *)memory_region(machine, cputag);
int size = memory_region_length(machine, cputag);
UINT16 *opcodes = auto_alloc_array(machine, UINT16, size / 2);
- UINT16 *buf = alloc_array_or_die(UINT16, size / 2);
+ UINT16 *buf = auto_alloc_array(machine, UINT16, size / 2);
- memcpy(buf, rom, size);
+ memcpy(buf, rom, size);
- memory_set_decrypted_region(space, 0, size - 1, opcodes);
- m68k_set_encrypted_opcode_range(devtag_get_device(machine, cputag), 0, size);
+ memory_set_decrypted_region(space, 0, size - 1, opcodes);
+ m68k_set_encrypted_opcode_range(devtag_get_device(machine, cputag), 0, size);
- for (i = 0; i < size / 2; i++)
- {
- int src;
+ for (i = 0; i < size / 2; i++)
+ {
+ int src;
- // calculate address of encrypted word in ROM
- src = i & 0xf0000;
- if (i & 0x0001) src ^= 0xbe0b;
- if (i & 0x0002) src ^= 0x5699;
- if (i & 0x0004) src ^= 0x1322;
- if (i & 0x0008) src ^= 0x0004;
- if (i & 0x0010) src ^= 0x08a0;
- if (i & 0x0020) src ^= 0x0089;
- if (i & 0x0040) src ^= 0x0408;
- if (i & 0x0080) src ^= 0x1212;
- if (i & 0x0100) src ^= 0x08e0;
- if (i & 0x0200) src ^= 0x5499;
- if (i & 0x0400) src ^= 0x9a8b;
- if (i & 0x0800) src ^= 0x1222;
- if (i & 0x1000) src ^= 0x1200;
- if (i & 0x2000) src ^= 0x0008;
- if (i & 0x4000) src ^= 0x1210;
- if (i & 0x8000) src ^= 0x00e0;
- src ^= address_xor;
+ // calculate address of encrypted word in ROM
+ src = i & 0xf0000;
+ if (i & 0x0001) src ^= 0xbe0b;
+ if (i & 0x0002) src ^= 0x5699;
+ if (i & 0x0004) src ^= 0x1322;
+ if (i & 0x0008) src ^= 0x0004;
+ if (i & 0x0010) src ^= 0x08a0;
+ if (i & 0x0020) src ^= 0x0089;
+ if (i & 0x0040) src ^= 0x0408;
+ if (i & 0x0080) src ^= 0x1212;
+ if (i & 0x0100) src ^= 0x08e0;
+ if (i & 0x0200) src ^= 0x5499;
+ if (i & 0x0400) src ^= 0x9a8b;
+ if (i & 0x0800) src ^= 0x1222;
+ if (i & 0x1000) src ^= 0x1200;
+ if (i & 0x2000) src ^= 0x0008;
+ if (i & 0x4000) src ^= 0x1210;
+ if (i & 0x8000) src ^= 0x00e0;
+ src ^= address_xor;
- rom[i] = decrypt(buf[src], i, data_select_xor);
- opcodes[i] = decrypt(buf[src], i, opcode_select_xor);
- }
+ rom[i] = decrypt(buf[src], i, data_select_xor);
+ opcodes[i] = decrypt(buf[src], i, opcode_select_xor);
+ }
- free(buf);
+ auto_free(machine, buf);
}
diff --git a/src/mame/machine/deco156.c b/src/mame/machine/deco156.c
index 9de91a949c8..3c47b2629ec 100644
--- a/src/mame/machine/deco156.c
+++ b/src/mame/machine/deco156.c
@@ -126,9 +126,9 @@ void deco156_decrypt(running_machine *machine)
{
UINT32 *rom = (UINT32 *)memory_region(machine, "maincpu");
int length = memory_region_length(machine, "maincpu");
- UINT32 *buf = alloc_array_or_die(UINT32, length/4);
+ UINT32 *buf = auto_alloc_array(machine, UINT32, length/4);
- memcpy(buf, rom, length);
- decrypt(buf, rom, length);
- free(buf);
+ memcpy(buf, rom, length);
+ decrypt(buf, rom, length);
+ auto_free(machine, buf);
}
diff --git a/src/mame/machine/decocrpt.c b/src/mame/machine/decocrpt.c
index 7305c07e724..b551f12a4fd 100644
--- a/src/mame/machine/decocrpt.c
+++ b/src/mame/machine/decocrpt.c
@@ -602,7 +602,7 @@ static void deco_decrypt(running_machine *machine,const char *rgntag,const UINT8
{
UINT16 *rom = (UINT16 *)memory_region(machine, rgntag);
int len = memory_region_length(machine, rgntag)/2;
- UINT16 *buffer = alloc_array_or_die(UINT16, len);
+ UINT16 *buffer = auto_alloc_array(machine, UINT16, len);
int i;
/* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */
@@ -610,36 +610,36 @@ static void deco_decrypt(running_machine *machine,const char *rgntag,const UINT8
for (i = 0;i < len;i++)
rom[i] = BIG_ENDIANIZE_INT16(rom[i]);
- memcpy(buffer,rom,len*2);
+ memcpy(buffer,rom,len*2);
- for (i = 0;i < len;i++)
- {
- int addr = (i & ~0x7ff) | address_table[i & 0x7ff];
- int pat = swap_table[i & 0x7ff];
+ for (i = 0;i < len;i++)
+ {
+ int addr = (i & ~0x7ff) | address_table[i & 0x7ff];
+ int pat = swap_table[i & 0x7ff];
- if (remap_only)
- rom[i] = buffer[addr];
- else
- rom[i] = BITSWAP16(buffer[addr] ^ xor_masks[xor_table[addr & 0x7ff]],
- swap_patterns[pat][0],
- swap_patterns[pat][1],
- swap_patterns[pat][2],
- swap_patterns[pat][3],
- swap_patterns[pat][4],
- swap_patterns[pat][5],
- swap_patterns[pat][6],
- swap_patterns[pat][7],
- swap_patterns[pat][8],
- swap_patterns[pat][9],
- swap_patterns[pat][10],
- swap_patterns[pat][11],
- swap_patterns[pat][12],
- swap_patterns[pat][13],
- swap_patterns[pat][14],
- swap_patterns[pat][15]);
- }
+ if (remap_only)
+ rom[i] = buffer[addr];
+ else
+ rom[i] = BITSWAP16(buffer[addr] ^ xor_masks[xor_table[addr & 0x7ff]],
+ swap_patterns[pat][0],
+ swap_patterns[pat][1],
+ swap_patterns[pat][2],
+ swap_patterns[pat][3],
+ swap_patterns[pat][4],
+ swap_patterns[pat][5],
+ swap_patterns[pat][6],
+ swap_patterns[pat][7],
+ swap_patterns[pat][8],
+ swap_patterns[pat][9],
+ swap_patterns[pat][10],
+ swap_patterns[pat][11],
+ swap_patterns[pat][12],
+ swap_patterns[pat][13],
+ swap_patterns[pat][14],
+ swap_patterns[pat][15]);
+ }
- free(buffer);
+ auto_free(machine, buffer);
/* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */
if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE)
diff --git a/src/mame/machine/kaneko16.c b/src/mame/machine/kaneko16.c
index a110f090b67..e649dd45d33 100644
--- a/src/mame/machine/kaneko16.c
+++ b/src/mame/machine/kaneko16.c
@@ -2039,7 +2039,7 @@ DRIVER_INIT(calc3_scantables)
for (x=0;x<numregions;x++)
{
- UINT8* tmpdstram = (UINT8*)malloc(0x2000);
+ UINT8* tmpdstram = auto_alloc_array(machine, UINT8, 0x2000);
int length;
memset(tmpdstram, 0x00,0x2000);
length = calc3_decompress_table(machine, x, tmpdstram, 0);
@@ -2072,7 +2072,7 @@ DRIVER_INIT(calc3_scantables)
}
}
#endif
- free(tmpdstram);
+ auto_free(machine, tmpdstram);
}
// there is also a 0x1000 block of data at the end.. same on both games, maybe it's related to the decryption tables??
diff --git a/src/mame/machine/neoboot.c b/src/mame/machine/neoboot.c
index 6ccad38c388..0ae38e83983 100644
--- a/src/mame/machine/neoboot.c
+++ b/src/mame/machine/neoboot.c
@@ -24,7 +24,7 @@ void neogeo_bootleg_cx_decrypt( running_machine *machine )
int i;
int cx_size = memory_region_length( machine, "sprites" );
UINT8 *rom = memory_region( machine, "sprites" );
- UINT8 *buf = alloc_array_or_die(UINT8, cx_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, cx_size );
memcpy( buf, rom, cx_size );
@@ -32,7 +32,7 @@ void neogeo_bootleg_cx_decrypt( running_machine *machine )
memcpy( &rom[ i * 0x40 ], &buf[ (i ^ 1) * 0x40 ], 0x40 );
}
- free( buf );
+ auto_free( machine, buf );
}
@@ -44,7 +44,7 @@ void neogeo_bootleg_sx_decrypt( running_machine *machine, int value )
if (value == 1)
{
- UINT8 *buf = alloc_array_or_die(UINT8, sx_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, sx_size );
memcpy( buf, rom, sx_size );
for( i = 0; i < sx_size; i += 0x10 )
@@ -52,7 +52,7 @@ void neogeo_bootleg_sx_decrypt( running_machine *machine, int value )
memcpy( &rom[ i ], &buf[ i + 8 ], 8 );
memcpy( &rom[ i + 8 ], &buf[ i ], 8 );
}
- free( buf );
+ auto_free( machine, buf );
}
else if (value == 2)
{
@@ -72,7 +72,7 @@ void kog_px_decrypt( running_machine *machine )
{
/* the protection chip does some *very* strange things to the rom */
UINT8 *src = memory_region(machine, "maincpu");
- UINT8 *dst = alloc_array_or_die(UINT8, 0x600000 );
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x600000 );
UINT16 *rom = (UINT16 *)memory_region(machine, "maincpu");
int i;
static const int sec[] = { 0x3, 0x8, 0x7, 0xC, 0x1, 0xA, 0x6, 0xD };
@@ -87,7 +87,7 @@ void kog_px_decrypt( running_machine *machine )
memcpy (dst + 0x090000, src + 0x040000, 0x004000);
memcpy (dst + 0x100000, src + 0x200000, 0x400000);
memcpy (src, dst, 0x600000);
- free (dst);
+ auto_free (machine, dst);
for (i = 0x90000/2; i < 0x94000/2; i++){
if (((rom[i]&0xFFBF) == 0x4EB9 || rom[i] == 0x43F9) && !rom[i + 1])
@@ -186,18 +186,18 @@ void install_kof10th_protection ( running_machine *machine )
void decrypt_kof10th(running_machine *machine)
{
int i, j;
- UINT8 *dst = alloc_array_or_die(UINT8, 0x900000);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x900000);
UINT8 *src = memory_region( machine, "maincpu" );
- memcpy(dst + 0x000000, src + 0x700000, 0x100000); // Correct (Verified in Uni-bios)
- memcpy(dst + 0x100000, src + 0x000000, 0x800000);
+ memcpy(dst + 0x000000, src + 0x700000, 0x100000); // Correct (Verified in Uni-bios)
+ memcpy(dst + 0x100000, src + 0x000000, 0x800000);
- for (i = 0; i < 0x900000; i++) {
- j = BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12,11,2,9,8,7,1,5,4,3,10,6,0);
- src[j] = dst[i];
- }
+ for (i = 0; i < 0x900000; i++) {
+ j = BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12,11,2,9,8,7,1,5,4,3,10,6,0);
+ src[j] = dst[i];
+ }
- free(dst);
+ auto_free(machine, dst);
// Altera protection chip patches these over P ROM
((UINT16*)src)[0x0124/2] = 0x000d; // Enables XOR for RAM moves, forces SoftDIPs, and USA region
@@ -219,9 +219,9 @@ void decrypt_kf10thep(running_machine *machine)
UINT8 *src = memory_region(machine, "maincpu");
UINT16 *buf = (UINT16*)memory_region(machine, "audiocrypt");
UINT8 *srom = (UINT8*)memory_region(machine, "fixed");
- UINT8 *sbuf = alloc_array_or_die(UINT8, 0x20000);
+ UINT8 *sbuf = auto_alloc_array(machine, UINT8, 0x20000);
- UINT8 *dst = alloc_array_or_die(UINT8, 0x200000);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x200000);
memcpy(dst,buf,0x200000);
memcpy(src+0x000000,dst+0x060000,0x20000);
@@ -240,13 +240,13 @@ void decrypt_kf10thep(running_machine *machine)
if (rom[i+0] == 0x4ef9 && rom[i+1] == 0x0000) rom[i+1] = 0x000F; // correct JMP in moved code
}
rom[0x00342/2] = 0x000f;
- free(dst);
+ auto_free(machine, dst);
for (i=0;i<0x20000;i++)
sbuf[i]=srom[i^0x8];
memcpy(srom,sbuf,0x20000);
- free(sbuf);
+ auto_free(machine, sbuf);
}
@@ -257,7 +257,7 @@ static void kf2k5uni_px_decrypt( running_machine *machine )
{
int i, j, ofst;
UINT8 *src = memory_region( machine, "maincpu" );
- UINT8 *dst = alloc_array_or_die(UINT8, 0x80);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x80);
for (i = 0; i < 0x800000; i+=0x80)
{
@@ -268,7 +268,7 @@ static void kf2k5uni_px_decrypt( running_machine *machine )
}
memcpy(src + i, dst, 0x80);
}
- free(dst);
+ auto_free(machine, dst);
memcpy(src, src + 0x600000, 0x100000); // Seems to be the same as kof10th
}
@@ -318,7 +318,7 @@ void kof2002b_gfx_decrypt(running_machine *machine, UINT8 *src, int size)
{ 8, 0, 7, 3, 4, 5, 6, 2, 1 },
};
- UINT8 *dst = alloc_array_or_die(UINT8, 0x10000 );
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x10000 );
for ( i = 0; i < size; i+=0x10000 )
{
@@ -332,7 +332,7 @@ void kof2002b_gfx_decrypt(running_machine *machine, UINT8 *src, int size)
memcpy( src+i+ofst*128, dst+j*128, 128 );
}
}
- free( dst );
+ auto_free( machine, dst );
}
@@ -344,20 +344,20 @@ void kf2k2mp_decrypt( running_machine *machine )
int i,j;
UINT8 *src = memory_region(machine, "maincpu");
- UINT8 *dst = alloc_array_or_die(UINT8, 0x80);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x80);
memmove(src, src + 0x300000, 0x500000);
- for (i = 0; i < 0x800000; i+=0x80)
+ for (i = 0; i < 0x800000; i+=0x80)
+ {
+ for (j = 0; j < 0x80 / 2; j++)
{
- for (j = 0; j < 0x80 / 2; j++)
- {
- int ofst = BITSWAP8( j, 6, 7, 2, 3, 4, 5, 0, 1 );
- memcpy(dst + j * 2, src + i + ofst * 2, 2);
- }
- memcpy(src + i, dst, 0x80);
+ int ofst = BITSWAP8( j, 6, 7, 2, 3, 4, 5, 0, 1 );
+ memcpy(dst + j * 2, src + i + ofst * 2, 2);
}
- free(dst);
+ memcpy(src + i, dst, 0x80);
+ }
+ auto_free(machine, dst);
}
@@ -367,14 +367,14 @@ void kf2k2mp_decrypt( running_machine *machine )
void kf2k2mp2_px_decrypt( running_machine *machine )
{
UINT8 *src = memory_region(machine, "maincpu");
- UINT8 *dst = alloc_array_or_die(UINT8, 0x600000);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x600000);
memcpy (dst + 0x000000, src + 0x1C0000, 0x040000);
memcpy (dst + 0x040000, src + 0x140000, 0x080000);
memcpy (dst + 0x0C0000, src + 0x100000, 0x040000);
memcpy (dst + 0x100000, src + 0x200000, 0x400000);
memcpy (src + 0x000000, dst + 0x000000, 0x600000);
- free (dst);
+ auto_free (machine, dst);
}
@@ -387,7 +387,7 @@ static void cthd2003_neogeo_gfx_address_fix_do(running_machine *machine, int sta
int i,j;
int tilesize=128;
- UINT8* rom = alloc_array_or_die(UINT8, 16*tilesize); // 16 tiles buffer
+ UINT8* rom = auto_alloc_array(machine, UINT8, 16*tilesize); // 16 tiles buffer
UINT8* realrom = memory_region(machine, "sprites") + start*tilesize;
for (i = 0; i < (end-start)/16; i++) {
@@ -402,7 +402,7 @@ static void cthd2003_neogeo_gfx_address_fix_do(running_machine *machine, int sta
memcpy(realrom,rom,tilesize*16);
realrom+=16*tilesize;
}
- free(rom);
+ auto_free(machine, rom);
}
static void cthd2003_neogeo_gfx_address_fix(running_machine *machine, int start, int end)
@@ -442,7 +442,7 @@ static void cthd2003_c(running_machine *machine, int pow)
void decrypt_cthd2003( running_machine *machine )
{
UINT8 *romdata = memory_region(machine, "fixed");
- UINT8 *tmp = alloc_array_or_die(UINT8, 8*128*128);
+ UINT8 *tmp = auto_alloc_array(machine, UINT8, 8*128*128);
memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128);
memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128);
@@ -457,7 +457,7 @@ void decrypt_cthd2003( running_machine *machine )
memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128);
memcpy(romdata, tmp, 8*128*128);
- free(tmp);
+ auto_free(machine, tmp);
memcpy(romdata-0x10000,romdata,0x10000);
@@ -527,7 +527,7 @@ static void ct2k3sp_sx_decrypt( running_machine *machine )
{
int rom_size = memory_region_length( machine, "fixed" );
UINT8 *rom = memory_region( machine, "fixed" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
int i;
int ofst;
@@ -550,20 +550,20 @@ static void ct2k3sp_sx_decrypt( running_machine *machine )
memcpy( &rom[ 0x28000 ], &buf[ 0x30000 ], 0x8000 );
memcpy( &rom[ 0x30000 ], &buf[ 0x28000 ], 0x8000 );
- free( buf );
+ auto_free( machine, buf );
}
void decrypt_ct2k3sp( running_machine *machine )
{
UINT8 *romdata = memory_region(machine, "audiocpu")+0x10000;
- UINT8*tmp = alloc_array_or_die(UINT8, 8*128*128);
+ UINT8*tmp = auto_alloc_array(machine, UINT8, 8*128*128);
memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128);
memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128);
memcpy(tmp+8*64*128, romdata+8*32*128, 8*32*128);
memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128);
memcpy(romdata, tmp, 8*128*128);
- free(tmp);
+ auto_free(machine, tmp);
memcpy(romdata-0x10000,romdata,0x10000);
ct2k3sp_sx_decrypt(machine);
cthd2003_c(machine, 0);
@@ -576,14 +576,14 @@ void decrypt_ct2k3sp( running_machine *machine )
void decrypt_ct2k3sa( running_machine *machine )
{
UINT8 *romdata = memory_region(machine, "audiocpu")+0x10000;
- UINT8*tmp = alloc_array_or_die(UINT8, 8*128*128);
+ UINT8*tmp = auto_alloc_array(machine, UINT8, 8*128*128);
memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128);
memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128);
memcpy(tmp+8*64*128, romdata+8*32*128, 8*32*128);
memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128);
memcpy(romdata, tmp, 8*128*128);
- free(tmp);
+ auto_free(machine, tmp);
memcpy(romdata-0x10000,romdata,0x10000);
cthd2003_c(machine, 0);
}
@@ -634,16 +634,16 @@ void patch_ct2k3sa( running_machine *machine )
void decrypt_kof2k4se_68k( running_machine *machine )
{
UINT8 *src = memory_region(machine, "maincpu")+0x100000;
- UINT8 *dst = alloc_array_or_die(UINT8, 0x400000);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x400000);
int i;
static const int sec[] = {0x300000,0x200000,0x100000,0x000000};
- memcpy(dst,src,0x400000);
+ memcpy(dst,src,0x400000);
- for(i = 0; i < 4; ++i)
- {
+ for(i = 0; i < 4; ++i)
+ {
memcpy(src+i*0x100000,dst+sec[i],0x100000);
- }
- free(dst);
+ }
+ auto_free(machine, dst);
}
@@ -664,7 +664,7 @@ void lans2004_decrypt_68k( running_machine *machine )
int i;
UINT8 *src = memory_region( machine, "maincpu" );
UINT16 *rom = (UINT16*)memory_region( machine, "maincpu" );
- UINT8 *dst = alloc_array_or_die(UINT8, 0x600000);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x600000);
{
static const int sec[] = { 0x3, 0x8, 0x7, 0xC, 0x1, 0xA, 0x6, 0xD };
@@ -676,7 +676,7 @@ void lans2004_decrypt_68k( running_machine *machine )
memcpy (dst + 0x02FFF0, src + 0x1A92BE, 0x000010);
memcpy (dst + 0x100000, src + 0x200000, 0x400000);
memcpy (src, dst, 0x600000);
- free (dst);
+ auto_free (machine, dst);
}
for (i = 0xBBB00/2; i < 0xBE000/2; i++) {
@@ -744,7 +744,7 @@ void svcboot_px_decrypt( running_machine *machine )
int i;
int size = memory_region_length( machine, "maincpu" );
UINT8 *src = memory_region( machine, "maincpu" );
- UINT8 *dst = alloc_array_or_die(UINT8, size );
+ UINT8 *dst = auto_alloc_array(machine, UINT8, size );
int ofst;
for( i = 0; i < size / 0x100000; i++ ){
memcpy( &dst[ i * 0x100000 ], &src[ sec[ i ] * 0x100000 ], 0x100000 );
@@ -754,7 +754,7 @@ void svcboot_px_decrypt( running_machine *machine )
ofst += (i & 0xffff00);
memcpy( &src[ i * 2 ], &dst[ ofst * 2 ], 0x02 );
}
- free( dst );
+ auto_free( machine, dst );
}
void svcboot_cx_decrypt( running_machine *machine )
@@ -773,7 +773,7 @@ void svcboot_cx_decrypt( running_machine *machine )
int i;
int size = memory_region_length( machine, "sprites" );
UINT8 *src = memory_region( machine, "sprites" );
- UINT8 *dst = alloc_array_or_die(UINT8, size );
+ UINT8 *dst = auto_alloc_array(machine, UINT8, size );
int ofst;
memcpy( dst, src, size );
for( i = 0; i < size / 0x80; i++ ){
@@ -786,7 +786,7 @@ void svcboot_cx_decrypt( running_machine *machine )
ofst += (i & 0xfffff00);
memcpy( &src[ i * 0x80 ], &dst[ ofst * 0x80 ], 0x80 );
}
- free( dst );
+ auto_free( machine, dst );
}
@@ -800,7 +800,7 @@ void svcplus_px_decrypt( running_machine *machine )
};
int size = memory_region_length( machine, "maincpu" );
UINT8 *src = memory_region( machine, "maincpu" );
- UINT8 *dst = alloc_array_or_die(UINT8, size );
+ UINT8 *dst = auto_alloc_array(machine, UINT8, size );
int i;
int ofst;
memcpy( dst, src, size );
@@ -816,7 +816,7 @@ void svcplus_px_decrypt( running_machine *machine )
for( i = 0; i < 6; i++ ){
memcpy( &src[ i * 0x100000 ], &dst[ sec[ i ] * 0x100000 ], 0x100000 );
}
- free( dst );
+ auto_free( machine, dst );
}
void svcplus_px_hack( running_machine *machine )
@@ -845,12 +845,12 @@ void svcplusa_px_decrypt( running_machine *machine )
};
int size = memory_region_length( machine, "maincpu" );
UINT8 *src = memory_region( machine, "maincpu" );
- UINT8 *dst = alloc_array_or_die(UINT8, size );
+ UINT8 *dst = auto_alloc_array(machine, UINT8, size );
memcpy( dst, src, size );
for( i = 0; i < 6; i++ ){
memcpy( &src[ i * 0x100000 ], &dst[ sec[ i ] * 0x100000 ], 0x100000 );
}
- free( dst );
+ auto_free( machine, dst );
}
@@ -864,7 +864,7 @@ void svcsplus_px_decrypt( running_machine *machine )
};
int size = memory_region_length( machine, "maincpu" );
UINT8 *src = memory_region( machine, "maincpu" );
- UINT8 *dst = alloc_array_or_die(UINT8, size );
+ UINT8 *dst = auto_alloc_array(machine, UINT8, size );
int i;
int ofst;
memcpy( dst, src, size );
@@ -876,7 +876,7 @@ void svcsplus_px_decrypt( running_machine *machine )
ofst += sec[ (i & 0xf80000) >> 19 ] << 19;
memcpy( &src[ i * 2 ], &dst[ ofst * 2 ], 0x02 );
}
- free( dst );
+ auto_free( machine, dst );
}
void svcsplus_px_hack( running_machine *machine )
@@ -961,13 +961,13 @@ void kf2k3bl_px_decrypt( running_machine *machine )
int rom_size = 0x800000;
UINT8 *rom = memory_region( machine, "maincpu" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
memcpy( buf, rom, rom_size );
for( i = 0; i < rom_size / 0x100000; i++ ){
memcpy( &rom[ i * 0x100000 ], &buf[ sec[ i ] * 0x100000 ], 0x100000 );
}
- free( buf );
+ auto_free( machine, buf );
}
void kf2k3bl_install_protection(running_machine *machine)
@@ -981,7 +981,7 @@ void kf2k3bl_install_protection(running_machine *machine)
void kf2k3pl_px_decrypt( running_machine *machine )
{
- UINT16*tmp = alloc_array_or_die(UINT16, 0x100000/2);
+ UINT16*tmp = auto_alloc_array(machine, UINT16, 0x100000/2);
UINT16*rom = (UINT16*)memory_region( machine, "maincpu" );
int j;
int i;
@@ -992,7 +992,7 @@ void kf2k3pl_px_decrypt( running_machine *machine )
for (j = 0;j < 0x100000/2;j++)
rom[i+j] = tmp[BITSWAP24(j,23,22,21,20,19,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)];
}
- free(tmp);
+ auto_free(machine, tmp);
/* patched by Altera protection chip on PCB */
rom[0xf38ac/2] = 0x4e75;
@@ -1042,7 +1042,7 @@ void samsho5b_px_decrypt( running_machine *machine )
{
int px_size = memory_region_length( machine, "maincpu" );
UINT8 *rom = memory_region( machine, "maincpu" );
- UINT8 *buf = alloc_array_or_die(UINT8, px_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, px_size );
int ofst;
int i;
@@ -1061,7 +1061,7 @@ void samsho5b_px_decrypt( running_machine *machine )
memcpy( &rom[ 0x000000 ], &buf[ 0x700000 ], 0x100000 );
memcpy( &rom[ 0x100000 ], &buf[ 0x000000 ], 0x700000 );
- free( buf );
+ auto_free( machine, buf );
}
@@ -1085,7 +1085,7 @@ void matrimbl_decrypt( running_machine *machine )
{
/* decrypt Z80 */
UINT8 *rom = memory_region( machine, "audiocpu" )+0x10000;
- UINT8 *buf = alloc_array_or_die(UINT8, 0x20000 );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, 0x20000 );
int i, j=0;
memcpy( buf, rom, 0x20000 );
for( i=0x00000; i<0x20000; i++ )
@@ -1116,7 +1116,7 @@ void matrimbl_decrypt( running_machine *machine )
}
rom[ j ]=buf[ i ];
}
- free( buf );
+ auto_free( machine, buf );
memcpy( rom-0x10000, rom, 0x10000 );
/* decrypt gfx */
diff --git a/src/mame/machine/neocrypt.c b/src/mame/machine/neocrypt.c
index c7365cb6064..f435557a9a4 100644
--- a/src/mame/machine/neocrypt.c
+++ b/src/mame/machine/neocrypt.c
@@ -537,7 +537,7 @@ static void neogeo_gfx_decrypt(running_machine *machine, int extra_xor)
rom_size = memory_region_length(machine, "sprites");
- buf = alloc_array_or_die(UINT8, rom_size);
+ buf = auto_alloc_array(machine, UINT8, rom_size);
rom = memory_region(machine, "sprites");
@@ -587,7 +587,7 @@ static void neogeo_gfx_decrypt(running_machine *machine, int extra_xor)
rom[4*rpos+3] = buf[4*baser+3];
}
- free(buf);
+ auto_free(machine, buf);
}
@@ -679,7 +679,7 @@ void svcpcb_gfx_decrypt(running_machine *machine)
int ofst;
int rom_size = memory_region_length( machine, "sprites" );
UINT8 *rom = memory_region( machine, "sprites" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
for( i = 0; i < rom_size; i++ )
{
@@ -702,7 +702,7 @@ void svcpcb_gfx_decrypt(running_machine *machine)
ofst += (i & 0xffe00000);
memcpy( &rom[ i * 4 ], &buf[ ofst * 4 ], 0x04 );
}
- free( buf );
+ auto_free( machine, buf );
}
@@ -729,7 +729,7 @@ void kf2k3pcb_gfx_decrypt(running_machine *machine)
int ofst;
int rom_size = memory_region_length( machine, "sprites" );
UINT8 *rom = memory_region( machine, "sprites" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
for ( i = 0; i < rom_size; i++ )
{
@@ -748,7 +748,7 @@ void kf2k3pcb_gfx_decrypt(running_machine *machine)
ofst += (i & 0xff800000);
memcpy( &rom[ ofst ], &buf[ i ], 0x04 );
}
- free( buf );
+ auto_free( machine, buf );
}
@@ -891,7 +891,7 @@ void neogeo_cmc50_m1_decrypt(running_machine *machine)
size_t rom_size = 0x80000;
UINT8* rom2 = memory_region(machine, "audiocpu");
- UINT8* buffer = alloc_array_or_die(UINT8, rom_size);
+ UINT8* buffer = auto_alloc_array(machine, UINT8, rom_size);
UINT32 i;
@@ -942,7 +942,7 @@ void neogeo_cmc50_m1_decrypt(running_machine *machine)
}
#endif
- free( buffer );
+ auto_free( machine, buffer );
}
@@ -957,7 +957,7 @@ NeoGeo 'P' ROM encryption
void kof98_decrypt_68k(running_machine *machine)
{
UINT8 *src = memory_region(machine, "maincpu");
- UINT8 *dst = alloc_array_or_die(UINT8, 0x200000);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x200000);
int i, j, k;
static const UINT32 sec[]={0x000000,0x100000,0x000004,0x100004,0x10000a,0x00000a,0x10000e,0x00000e};
static const UINT32 pos[]={0x000,0x004,0x00a,0x00e};
@@ -996,7 +996,7 @@ void kof98_decrypt_68k(running_machine *machine)
}
memcpy( &src[0x100000], &src[0x200000], 0x400000 );
- free(dst);
+ auto_free(machine, dst);
}
@@ -1174,13 +1174,13 @@ void kof2002_decrypt_68k(running_machine *machine)
int i;
static const int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000};
UINT8 *src = memory_region(machine, "maincpu")+0x100000;
- UINT8 *dst = alloc_array_or_die(UINT8, 0x400000);
- memcpy( dst, src, 0x400000 );
- for( i=0; i<8; ++i )
- {
- memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
- }
- free(dst);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x400000);
+ memcpy( dst, src, 0x400000 );
+ for( i=0; i<8; ++i )
+ {
+ memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
+ }
+ auto_free(machine, dst);
}
@@ -1189,13 +1189,13 @@ void matrim_decrypt_68k(running_machine *machine)
int i;
static const int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000};
UINT8 *src = memory_region(machine, "maincpu")+0x100000;
- UINT8 *dst = alloc_array_or_die(UINT8, 0x400000);
- memcpy( dst, src, 0x400000);
- for( i=0; i<8; ++i )
- {
- memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
- }
- free(dst);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x400000);
+ memcpy( dst, src, 0x400000);
+ for( i=0; i<8; ++i )
+ {
+ memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
+ }
+ auto_free(machine, dst);
}
@@ -1204,14 +1204,14 @@ void samsho5_decrypt_68k(running_machine *machine)
int i;
static const int sec[]={0x000000,0x080000,0x700000,0x680000,0x500000,0x180000,0x200000,0x480000,0x300000,0x780000,0x600000,0x280000,0x100000,0x580000,0x400000,0x380000};
UINT8 *src = memory_region(machine, "maincpu");
- UINT8 *dst = alloc_array_or_die(UINT8, 0x800000);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x800000);
- memcpy( dst, src, 0x800000 );
- for( i=0; i<16; ++i )
- {
- memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
- }
- free(dst);
+ memcpy( dst, src, 0x800000 );
+ for( i=0; i<16; ++i )
+ {
+ memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
+ }
+ auto_free(machine, dst);
}
@@ -1220,14 +1220,14 @@ void samsh5sp_decrypt_68k(running_machine *machine)
int i;
static const int sec[]={0x000000,0x080000,0x500000,0x480000,0x600000,0x580000,0x700000,0x280000,0x100000,0x680000,0x400000,0x780000,0x200000,0x380000,0x300000,0x180000};
UINT8 *src = memory_region(machine, "maincpu");
- UINT8 *dst = alloc_array_or_die(UINT8, 0x800000);
+ UINT8 *dst = auto_alloc_array(machine, UINT8, 0x800000);
- memcpy( dst, src, 0x800000 );
- for( i=0; i<16; ++i )
- {
- memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
- }
- free(dst);
+ memcpy( dst, src, 0x800000 );
+ for( i=0; i<16; ++i )
+ {
+ memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
+ }
+ auto_free(machine, dst);
}
@@ -1240,7 +1240,7 @@ void mslug5_decrypt_68k(running_machine *machine)
int ofst;
int rom_size = 0x800000;
UINT8 *rom = memory_region( machine, "maincpu" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
for( i = 0; i < 0x100000; i++ )
{
@@ -1273,7 +1273,7 @@ void mslug5_decrypt_68k(running_machine *machine)
memcpy( buf, rom, rom_size );
memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 );
memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 );
- free( buf );
+ auto_free( machine, buf );
}
@@ -1285,7 +1285,7 @@ void svc_px_decrypt(running_machine *machine)
int ofst;
int rom_size = 0x800000;
UINT8 *rom = memory_region( machine, "maincpu" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
for( i = 0; i < 0x100000; i++ )
{
@@ -1318,7 +1318,7 @@ void svc_px_decrypt(running_machine *machine)
memcpy( buf, rom, rom_size );
memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 );
memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 );
- free( buf );
+ auto_free( machine, buf );
}
@@ -1329,7 +1329,7 @@ void kf2k3pcb_decrypt_68k(running_machine *machine)
int ofst;
int rom_size = 0x900000;
UINT8 *rom = memory_region( machine, "maincpu" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
for (i = 0; i < 0x100000; i++)
{
@@ -1360,7 +1360,7 @@ void kf2k3pcb_decrypt_68k(running_machine *machine)
memcpy (&rom[0x000000], &buf[0x000000], 0x100000);
memcpy (&rom[0x100000], &buf[0x800000], 0x100000);
memcpy (&rom[0x200000], &buf[0x100000], 0x700000);
- free( buf );
+ auto_free( machine, buf );
}
@@ -1372,7 +1372,7 @@ void kof2003_decrypt_68k(running_machine *machine)
int ofst;
int rom_size = 0x900000;
UINT8 *rom = memory_region( machine, "maincpu" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
for (i = 0; i < 0x100000; i++)
{
@@ -1407,7 +1407,7 @@ void kof2003_decrypt_68k(running_machine *machine)
memcpy (&rom[0x000000], &buf[0x000000], 0x100000);
memcpy (&rom[0x100000], &buf[0x800000], 0x100000);
memcpy (&rom[0x200000], &buf[0x100000], 0x700000);
- free( buf );
+ auto_free( machine, buf );
}
@@ -1420,7 +1420,7 @@ void kof2003h_decrypt_68k(running_machine *machine)
int ofst;
int rom_size = 0x900000;
UINT8 *rom = memory_region( machine, "maincpu" );
- UINT8 *buf = alloc_array_or_die(UINT8, rom_size );
+ UINT8 *buf = auto_alloc_array(machine, UINT8, rom_size );
for (i = 0; i < 0x100000; i++)
{
@@ -1455,7 +1455,7 @@ void kof2003h_decrypt_68k(running_machine *machine)
memcpy (&rom[0x000000], &buf[0x000000], 0x100000);
memcpy (&rom[0x100000], &buf[0x800000], 0x100000);
memcpy (&rom[0x200000], &buf[0x100000], 0x700000);
- free( buf );
+ auto_free( machine, buf );
}
@@ -1475,7 +1475,7 @@ void neo_pcm2_snk_1999(running_machine *machine, int value)
if( rom != NULL )
{ /* swap address lines on the whole ROMs */
- UINT16 *buffer = alloc_array_or_die(UINT16, value / 2);
+ UINT16 *buffer = auto_alloc_array(machine, UINT16, value / 2);
for( i = 0; i < size / 2; i += ( value / 2 ) )
{
@@ -1485,7 +1485,7 @@ void neo_pcm2_snk_1999(running_machine *machine, int value)
rom[ i + j ] = buffer[ j ^ (value/4) ];
}
}
- free(buffer);
+ auto_free(machine, buffer);
}
}
@@ -1510,7 +1510,7 @@ void neo_pcm2_swap(running_machine *machine, int value)
{0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62},
{0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62}};
UINT8 *src = memory_region(machine, "ymsnd");
- UINT8 *buf = alloc_array_or_die(UINT8, 0x1000000);
+ UINT8 *buf = auto_alloc_array(machine, UINT8, 0x1000000);
int i, j, d;
memcpy(buf,src,0x1000000);
@@ -1521,7 +1521,7 @@ void neo_pcm2_swap(running_machine *machine, int value)
d=((i+addrs[value][0])&0xffffff);
src[j]=buf[d]^xordata[value][j&0x7];
}
- free(buf);
+ auto_free(machine, buf);
}
@@ -1554,27 +1554,27 @@ void kof2003biosdecode(running_machine *machine)
0xd3,0xd2,0x5c,0x5d,0x57,0x56,0xd8,0xd9,
};
UINT16*src= (UINT16*)memory_region( machine, "mainbios" );
- UINT16*buf= alloc_array_or_die(UINT16, 0x80000/2);
+ UINT16*buf= auto_alloc_array(machine, UINT16, 0x80000/2);
int a,addr;
- for (a=0;a<0x80000/2;a++)
- {
- if (src[a] & (0x0004 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0001 << (8*BYTE_XOR_LE(0));
- if (src[a] & (0x0010 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0002 << (8*BYTE_XOR_LE(0));
- if (src[a] & (0x0020 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0008 << (8*BYTE_XOR_LE(0));
- //address xor
- addr = a & ~0xff;
- addr |= address[BYTE_XOR_LE(a & 0x7f)];
- if ( a & 0x00008) addr ^= 0x0008;
- if ( a & 0x00080) addr ^= 0x0080;
- if ( a & 0x00200) addr ^= 0x0100;
- if (~a & 0x02000) addr ^= 0x0400;
- if (~a & 0x10000) addr ^= 0x1000;
- if ( a & 0x02000) addr ^= 0x8000;
- buf[addr]=src[a];
- }
- memcpy(src,buf,0x80000);
- free(buf);
+ for (a=0;a<0x80000/2;a++)
+ {
+ if (src[a] & (0x0004 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0001 << (8*BYTE_XOR_LE(0));
+ if (src[a] & (0x0010 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0002 << (8*BYTE_XOR_LE(0));
+ if (src[a] & (0x0020 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0008 << (8*BYTE_XOR_LE(0));
+ //address xor
+ addr = a & ~0xff;
+ addr |= address[BYTE_XOR_LE(a & 0x7f)];
+ if ( a & 0x00008) addr ^= 0x0008;
+ if ( a & 0x00080) addr ^= 0x0080;
+ if ( a & 0x00200) addr ^= 0x0100;
+ if (~a & 0x02000) addr ^= 0x0400;
+ if (~a & 0x10000) addr ^= 0x1000;
+ if ( a & 0x02000) addr ^= 0x8000;
+ buf[addr]=src[a];
+ }
+ memcpy(src,buf,0x80000);
+ auto_free(machine, buf);
}
diff --git a/src/mame/machine/scramble.c b/src/mame/machine/scramble.c
index 533c0e0fa63..a57e63b16e3 100644
--- a/src/mame/machine/scramble.c
+++ b/src/mame/machine/scramble.c
@@ -457,24 +457,24 @@ DRIVER_INIT( rescue )
RAM = memory_region(machine, "gfx1");
len = memory_region_length(machine, "gfx1");
- scratch = alloc_array_or_die(UINT8, len);
+ scratch = auto_alloc_array(machine, UINT8, len);
- memcpy(scratch, RAM, len);
+ memcpy(scratch, RAM, len);
- for (i = 0; i < len; i++)
- {
- int j;
+ for (i = 0; i < len; i++)
+ {
+ int j;
- j = i & 0xa7f;
- j |= ( bit(i,3) ^ bit(i,10) ) << 7;
- j |= ( bit(i,1) ^ bit(i,7) ) << 8;
- j |= ( bit(i,0) ^ bit(i,8) ) << 10;
+ j = i & 0xa7f;
+ j |= ( bit(i,3) ^ bit(i,10) ) << 7;
+ j |= ( bit(i,1) ^ bit(i,7) ) << 8;
+ j |= ( bit(i,0) ^ bit(i,8) ) << 10;
- RAM[i] = scratch[j];
- }
+ RAM[i] = scratch[j];
+ }
- free(scratch);
+ auto_free(machine, scratch);
}
DRIVER_INIT( minefld )
@@ -493,25 +493,25 @@ DRIVER_INIT( minefld )
RAM = memory_region(machine, "gfx1");
len = memory_region_length(machine, "gfx1");
- scratch = alloc_array_or_die(UINT8, len);
+ scratch = auto_alloc_array(machine, UINT8, len);
- memcpy(scratch, RAM, len);
+ memcpy(scratch, RAM, len);
- for (i = 0; i < len; i++)
- {
- int j;
+ for (i = 0; i < len; i++)
+ {
+ int j;
- j = i & 0xd5f;
- j |= ( bit(i,3) ^ bit(i,7) ) << 5;
- j |= ( bit(i,2) ^ bit(i,9) ^ ( bit(i,0) & bit(i,5) ) ^
- ( bit(i,3) & bit(i,7) & ( bit(i,0) ^ bit(i,5) ))) << 7;
- j |= ( bit(i,0) ^ bit(i,5) ^ ( bit(i,3) & bit(i,7) ) ) << 9;
+ j = i & 0xd5f;
+ j |= ( bit(i,3) ^ bit(i,7) ) << 5;
+ j |= ( bit(i,2) ^ bit(i,9) ^ ( bit(i,0) & bit(i,5) ) ^
+ ( bit(i,3) & bit(i,7) & ( bit(i,0) ^ bit(i,5) ))) << 7;
+ j |= ( bit(i,0) ^ bit(i,5) ^ ( bit(i,3) & bit(i,7) ) ) << 9;
- RAM[i] = scratch[j];
- }
+ RAM[i] = scratch[j];
+ }
- free(scratch);
+ auto_free(machine, scratch);
}
#ifdef UNUSED_FUNCTION
diff --git a/src/mame/machine/segas32.c b/src/mame/machine/segas32.c
index 64a6d9c04b9..03f24e9e42d 100644
--- a/src/mame/machine/segas32.c
+++ b/src/mame/machine/segas32.c
@@ -39,7 +39,7 @@ static void nec_v25_cpu_decrypt(running_machine *machine)
const address_space *space = cputag_get_address_space(machine, "mcu", ADDRESS_SPACE_PROGRAM);
UINT8 *rom = memory_region(machine, "mcu");
UINT8* decrypted = auto_alloc_array(machine, UINT8, 0x100000);
- UINT8* temp = alloc_array_or_die(UINT8, 0x100000);
+ UINT8* temp = auto_alloc_array(machine, UINT8, 0x100000);
// set CPU3 opcode base
memory_set_decrypted_region(space, 0x00000, 0xfffff, decrypted);
@@ -61,7 +61,7 @@ static void nec_v25_cpu_decrypt(running_machine *machine)
memcpy(rom+0xf0000, rom, 0x10000);
memcpy(decrypted+0xf0000, decrypted, 0x10000);
- free(temp);
+ auto_free(machine, temp);
}
void decrypt_ga2_protrom(running_machine *machine)
diff --git a/src/mame/machine/stvcd.c b/src/mame/machine/stvcd.c
index bce2a270a24..d7d7cc3026b 100644
--- a/src/mame/machine/stvcd.c
+++ b/src/mame/machine/stvcd.c
@@ -140,8 +140,8 @@ static UINT32 fadstoplay = 0;
static int buffull, sectorstore, freeblocks;
// iso9660 utilities
-static void read_new_dir(UINT32 fileno);
-static void make_dir_current(UINT32 fad);
+static void read_new_dir(running_machine *machine, UINT32 fileno);
+static void make_dir_current(running_machine *machine, UINT32 fad);
static direntryT curroot; // root entry of current filesystem
static direntryT *curdir; // current directory
@@ -216,7 +216,7 @@ void stvcd_reset(running_machine *machine)
cd_stat = CD_STAT_PAUSE;
if (curdir != (direntryT *)NULL)
- free((void *)curdir);
+ auto_free(machine, curdir);
curdir = (direntryT *)NULL; // no directory yet
xfertype = XFERTYPE_INVALID;
@@ -267,7 +267,7 @@ void stvcd_reset(running_machine *machine)
if (cdrom)
{
CDROM_LOG(("Opened CD-ROM successfully, reading root directory\n"))
- read_new_dir(0xffffff); // read root directory
+ read_new_dir(machine, 0xffffff); // read root directory
}
else
{
@@ -525,7 +525,7 @@ static UINT32 cd_readLong(UINT32 addr)
}
}
-static void cd_writeWord(UINT32 addr, UINT16 data)
+static void cd_writeWord(running_machine *machine, UINT32 addr, UINT16 data)
{
UINT32 temp;
@@ -1171,7 +1171,7 @@ static void cd_writeWord(UINT32 addr, UINT16 data)
temp = (cr3&0xff)<<16;
temp |= cr4;
- read_new_dir(temp);
+ read_new_dir(machine, temp);
break;
case 0x7100: // Read directory entry
@@ -1386,7 +1386,7 @@ WRITE32_HANDLER( stvcd_w )
case 0x90022:
case 0x90024:
case 0x90026:
- cd_writeWord(offset, data>>16);
+ cd_writeWord(space->machine, offset, data>>16);
break;
default:
@@ -1396,7 +1396,7 @@ WRITE32_HANDLER( stvcd_w )
}
// iso9660 parsing
-static void read_new_dir(UINT32 fileno)
+static void read_new_dir(running_machine *machine, UINT32 fileno)
{
int foundpd, i;
UINT32 cfad, dirfad;
@@ -1460,7 +1460,7 @@ static void read_new_dir(UINT32 fileno)
}
// done with all that, read the root directory now
- make_dir_current(curroot.firstfad);
+ make_dir_current(machine, curroot.firstfad);
}
}
else
@@ -1469,12 +1469,12 @@ static void read_new_dir(UINT32 fileno)
{
mame_printf_error("ERROR: new directory too big (%d)!\n", curdir[fileno].length);
}
- make_dir_current(curdir[fileno].firstfad);
+ make_dir_current(machine, curdir[fileno].firstfad);
}
}
// makes the directory pointed to by FAD current
-static void make_dir_current(UINT32 fad)
+static void make_dir_current(running_machine *machine, UINT32 fad)
{
int i;
UINT32 nextent, numentries;
@@ -1504,10 +1504,10 @@ static void make_dir_current(UINT32 fad)
if (curdir != (direntryT *)NULL)
{
- free((void *)curdir);
+ auto_free(machine, curdir);
}
- curdir = alloc_array_or_die(direntryT, numentries);
+ curdir = auto_alloc_array(machine, direntryT, numentries);
curentry = curdir;
numfiles = numentries;
@@ -1543,7 +1543,7 @@ void stvcd_exit(running_machine* machine)
{
if (curdir != (direntryT *)NULL)
{
- free((void *)curdir);
+ auto_free(machine, curdir);
curdir = (direntryT *)NULL;
}
diff --git a/src/mame/video/aeroboto.c b/src/mame/video/aeroboto.c
index 27694460f0b..06a832e5929 100644
--- a/src/mame/video/aeroboto.c
+++ b/src/mame/video/aeroboto.c
@@ -60,13 +60,13 @@ VIDEO_START( aeroboto )
UINT8 *temp;
int i;
- temp = alloc_array_or_die(UINT8, state->stars_length);
+ temp = auto_alloc_array(machine, UINT8, state->stars_length);
memcpy(temp, state->stars_rom, state->stars_length);
for (i = 0; i < state->stars_length; i++)
state->stars_rom[(i & ~0xff) + (i << 5 & 0xe0) + (i >> 3 & 0x1f)] = temp[i];
- free(temp);
+ auto_free(machine, temp);
}
#endif
}
diff --git a/src/mame/video/bfm_adr2.c b/src/mame/video/bfm_adr2.c
index 355b28cb4e5..6e35918b7a1 100644
--- a/src/mame/video/bfm_adr2.c
+++ b/src/mame/video/bfm_adr2.c
@@ -432,7 +432,7 @@ void adder2_decode_char_roms(running_machine *machine)
{
UINT8 *s;
- s = alloc_array_or_die(UINT8, 0x40000 );
+ s = auto_alloc_array(machine, UINT8, 0x40000 );
{
int x, y;
@@ -459,7 +459,7 @@ void adder2_decode_char_roms(running_machine *machine)
}
y++;
}
- free(s);
+ auto_free(machine, s);
}
}
}
diff --git a/src/mame/video/dkong.c b/src/mame/video/dkong.c
index ac78bd4905c..baee631f912 100644
--- a/src/mame/video/dkong.c
+++ b/src/mame/video/dkong.c
@@ -205,7 +205,7 @@ PALETTE_INIT( dkong2b)
rgb_t *rgb;
int i;
- rgb = compute_res_net_all(color_prom, &dkong_decode_info, &dkong_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &dkong_decode_info, &dkong_net_info);
palette_set_colors(machine, 0, rgb, 256);
/* Now treat tri-state black background generation */
@@ -225,7 +225,7 @@ PALETTE_INIT( dkong2b)
color_prom += 512;
/* color_prom now points to the beginning of the character color codes */
state->color_codes = color_prom; /* we'll need it later */
- free(rgb);
+ auto_free(machine, rgb);
}
#ifdef UNUSED_FUNCTION
@@ -437,10 +437,10 @@ PALETTE_INIT( dkong3 )
dkong_state *state = (dkong_state *)machine->driver_data;
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &dkong3_decode_info, &dkong3_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &dkong3_decode_info, &dkong3_net_info);
palette_set_colors(machine, 0, rgb, 256);
palette_normalize_range(machine->palette, 0, 255, 0, 255);
- free(rgb);
+ auto_free(machine, rgb);
color_prom += 1024;
/* color_prom now points to the beginning of the character color codes */
diff --git a/src/mame/video/hng64.c b/src/mame/video/hng64.c
index 9c44af85e73..2f779b13d99 100644
--- a/src/mame/video/hng64.c
+++ b/src/mame/video/hng64.c
@@ -2378,7 +2378,7 @@ void hng64_command3d(running_machine* machine, const UINT16* packet)
/* A temporary place to put some polygons. This will optimize away if the compiler's any good. */
int numPolys = 0;
- struct polygon* polys = (struct polygon*)malloc(sizeof(struct polygon) * (1024*5));
+ struct polygon* polys = auto_alloc_array(machine, struct polygon, 1024*5);
//printf("packet type : %04x\n", packet[0]);
switch (packet[0])
@@ -2436,7 +2436,7 @@ void hng64_command3d(running_machine* machine, const UINT16* packet)
break;
}
- free(polys);
+ auto_free(machine, polys);
}
static void clear3d(running_machine *machine)
diff --git a/src/mame/video/m62.c b/src/mame/video/m62.c
index 92d9a17e8bb..db8cb560046 100644
--- a/src/mame/video/m62.c
+++ b/src/mame/video/m62.c
@@ -185,13 +185,13 @@ PALETTE_INIT( m62 )
irem_z80_state *state = (irem_z80_state *)machine->driver_data;
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &m62_tile_decode_info, &m62_tile_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &m62_tile_decode_info, &m62_tile_net_info);
palette_set_colors(machine, 0x000, rgb, 0x100);
- free(rgb);
+ auto_free(machine, rgb);
- rgb = compute_res_net_all(color_prom, &m62_sprite_decode_info, &m62_sprite_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &m62_sprite_decode_info, &m62_sprite_net_info);
palette_set_colors(machine, 0x100, rgb, 0x100);
- free(rgb);
+ auto_free(machine, rgb);
palette_normalize_range(machine->palette, 0x000, 0x1ff, 0x00, 0xff);
@@ -205,13 +205,13 @@ PALETTE_INIT( lotlot )
irem_z80_state *state = (irem_z80_state *)machine->driver_data;
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &lotlot_tile_decode_info, &m62_tile_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &lotlot_tile_decode_info, &m62_tile_net_info);
palette_set_colors(machine, 0x000, rgb, 0x180);
- free(rgb);
+ auto_free(machine, rgb);
- rgb = compute_res_net_all(color_prom, &lotlot_sprite_decode_info, &m62_sprite_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &lotlot_sprite_decode_info, &m62_sprite_net_info);
palette_set_colors(machine, 0x180, rgb, 0x180);
- free(rgb);
+ auto_free(machine, rgb);
palette_normalize_range(machine->palette, 0x000, 0x2ff, 0x00, 0xff);
@@ -225,17 +225,17 @@ PALETTE_INIT( battroad )
irem_z80_state *state = (irem_z80_state *)machine->driver_data;
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &m62_tile_decode_info, &m62_tile_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &m62_tile_decode_info, &m62_tile_net_info);
palette_set_colors(machine, 0x000, rgb, 0x100);
- free(rgb);
+ auto_free(machine, rgb);
- rgb = compute_res_net_all(color_prom, &m62_sprite_decode_info, &m62_sprite_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &m62_sprite_decode_info, &m62_sprite_net_info);
palette_set_colors(machine, 0x100, rgb, 0x100);
- free(rgb);
+ auto_free(machine, rgb);
- rgb = compute_res_net_all(color_prom, &battroad_char_decode_info, &m62_tile_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &battroad_char_decode_info, &m62_tile_net_info);
palette_set_colors(machine, 0x200, rgb, 0x020);
- free(rgb);
+ auto_free(machine, rgb);
palette_normalize_range(machine->palette, 0x000, 0x21f, 0x00, 0xff);
@@ -248,13 +248,13 @@ PALETTE_INIT( spelunk2 )
irem_z80_state *state = (irem_z80_state *)machine->driver_data;
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &spelunk2_tile_decode_info, &m62_tile_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &spelunk2_tile_decode_info, &m62_tile_net_info);
palette_set_colors(machine, 0x000, rgb, 0x200);
- free(rgb);
+ auto_free(machine, rgb);
- rgb = compute_res_net_all(color_prom, &spelunk2_sprite_decode_info, &m62_sprite_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &spelunk2_sprite_decode_info, &m62_sprite_net_info);
palette_set_colors(machine, 0x200, rgb, 0x100);
- free(rgb);
+ auto_free(machine, rgb);
palette_normalize_range(machine->palette, 0x000, 0x2ff, 0x00, 0xff);
diff --git a/src/mame/video/mario.c b/src/mame/video/mario.c
index e709843b089..04f06abc8a4 100644
--- a/src/mame/video/mario.c
+++ b/src/mame/video/mario.c
@@ -66,12 +66,12 @@ PALETTE_INIT( mario )
{
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &mario_decode_info, &mario_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &mario_decode_info, &mario_net_info);
palette_set_colors(machine, 0, rgb, 256);
- free(rgb);
- rgb = compute_res_net_all(color_prom+256, &mario_decode_info, &mario_net_info_std);
+ auto_free(machine, rgb);
+ rgb = compute_res_net_all(machine, color_prom+256, &mario_decode_info, &mario_net_info_std);
palette_set_colors(machine, 256, rgb, 256);
- free(rgb);
+ auto_free(machine, rgb);
palette_normalize_range(machine->palette, 0, 255, 0, 255);
palette_normalize_range(machine->palette, 256, 511, 0, 255);
diff --git a/src/mame/video/model3.c b/src/mame/video/model3.c
index 3731e90c955..0fa8fae5b82 100644
--- a/src/mame/video/model3.c
+++ b/src/mame/video/model3.c
@@ -62,18 +62,18 @@ struct _poly_extra_data
/* forward declarations */
-static void real3d_traverse_display_list(void);
-static void draw_model(UINT32 addr);
+static void real3d_traverse_display_list(running_machine *machine);
+static void draw_model(running_machine *machine, UINT32 addr);
static void init_matrix_stack(void);
static void get_top_matrix(MATRIX *out);
static void push_matrix_stack(void);
static void pop_matrix_stack(void);
static void multiply_matrix_stack(MATRIX matrix);
static void translate_matrix_stack(float x, float y, float z);
-static void traverse_list(UINT32 address);
-static void draw_block(UINT32 address);
-static void draw_viewport(int pri, UINT32 address);
-static void invalidate_texture(int page, int texx, int texy, int texwidth, int texheight);
+static void traverse_list(running_machine *machine, UINT32 address);
+static void draw_block(running_machine *machine, UINT32 address);
+static void draw_viewport(running_machine *machine, int pri, UINT32 address);
+static void invalidate_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight);
/*****************************************************************************/
@@ -157,8 +157,8 @@ static UINT32 matrix_base_address;
static void model3_exit(running_machine *machine)
{
- invalidate_texture(0, 0, 0, 6, 5);
- invalidate_texture(1, 0, 0, 6, 5);
+ invalidate_texture(machine, 0, 0, 0, 6, 5);
+ invalidate_texture(machine, 1, 0, 0, 6, 5);
poly_free(poly);
}
@@ -435,7 +435,7 @@ VIDEO_UPDATE( model3 )
// if(real3d_display_list) {
// bitmap_fill(zbuffer, cliprect, 0);
// bitmap_fill(bitmap3d, cliprect, 0x8000);
-// real3d_traverse_display_list();
+// real3d_traverse_display_list(screen->machine);
// }
copybitmap_trans(bitmap, bitmap3d, 0, 0, 0, 0, cliprect, 0x8000);
}
@@ -544,7 +544,7 @@ READ64_HANDLER( model3_palette_r )
1024 pixels / 32 pixel resolution vertically
2048 pixels / 32 pixel resolution horizontally
*/
-static void invalidate_texture(int page, int texx, int texy, int texwidth, int texheight)
+static void invalidate_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight)
{
int wtiles = 1 << texwidth;
int htiles = 1 << texheight;
@@ -556,11 +556,11 @@ static void invalidate_texture(int page, int texx, int texy, int texwidth, int t
{
cached_texture *freeme = texcache[page][texy + y][texx + x];
texcache[page][texy + y][texx + x] = freeme->next;
- free(freeme);
+ auto_free(machine, freeme);
}
}
-static cached_texture *get_texture(int page, int texx, int texy, int texwidth, int texheight, int format)
+static cached_texture *get_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight, int format)
{
cached_texture *tex = texcache[page][texy][texx];
int pixheight = 32 << texheight;
@@ -574,7 +574,7 @@ static cached_texture *get_texture(int page, int texx, int texy, int texwidth, i
return tex;
/* create a new texture */
- tex = (cached_texture *)alloc_array_or_die(UINT8, sizeof(cached_texture) + (2 * pixwidth * 2 * pixheight) * sizeof(rgb_t));
+ tex = (cached_texture *)auto_alloc_array(machine, UINT8, sizeof(cached_texture) + (2 * pixwidth * 2 * pixheight) * sizeof(rgb_t));
tex->width = texwidth;
tex->height = texheight;
tex->format = format;
@@ -755,7 +755,7 @@ INLINE void write_texture8(int xpos, int ypos, int width, int height, int page,
}
#endif
-static void real3d_upload_texture(UINT32 header, UINT32 *data)
+static void real3d_upload_texture(running_machine *machine, UINT32 header, UINT32 *data)
{
int width = 32 << ((header >> 14) & 0x7);
int height = 32 << ((header >> 17) & 0x7);
@@ -769,7 +769,7 @@ static void real3d_upload_texture(UINT32 header, UINT32 *data)
case 0x00: /* Texture with mipmaps */
// if(bitdepth) {
write_texture16(xpos, ypos, width, height, page, (UINT16*)data);
- invalidate_texture(page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
+ invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
// } else {
/* TODO: 8-bit textures are weird. need to figure out some additional bits */
//logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header);
@@ -779,7 +779,7 @@ static void real3d_upload_texture(UINT32 header, UINT32 *data)
case 0x01: /* Texture without mipmaps */
// if(bitdepth) {
write_texture16(xpos, ypos, width, height, page, (UINT16*)data);
- invalidate_texture(page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
+ invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
// } else {
/* TODO: 8-bit textures are weird. need to figure out some additional bits */
//logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header);
@@ -796,7 +796,7 @@ static void real3d_upload_texture(UINT32 header, UINT32 *data)
}
}
-void real3d_display_list_end(void)
+void real3d_display_list_end(running_machine *machine)
{
/* upload textures if there are any in the FIFO */
if (texture_fifo_pos > 0)
@@ -806,14 +806,14 @@ void real3d_display_list_end(void)
{
int length = (texture_fifo[i] / 2) + 2;
UINT32 header = texture_fifo[i+1];
- real3d_upload_texture(header, &texture_fifo[i+2]);
+ real3d_upload_texture(machine, header, &texture_fifo[i+2]);
i += length;
};
}
texture_fifo_pos = 0;
bitmap_fill(zbuffer, NULL, 0);
bitmap_fill(bitmap3d, NULL, 0x8000);
- real3d_traverse_display_list();
+ real3d_traverse_display_list(machine);
// real3d_display_list = 1;
}
@@ -862,7 +862,7 @@ void real3d_vrom_texture_dma(const address_space *space, UINT32 src, UINT32 dst,
address = memory_read_dword(space, (src+0));
header = memory_read_dword(space, (src+4));
}
- real3d_upload_texture(header, (UINT32*)&model3_vrom[address]);
+ real3d_upload_texture(space->machine, header, (UINT32*)&model3_vrom[address]);
}
}
@@ -900,7 +900,7 @@ void real3d_polygon_ram_dma(const address_space *space, UINT32 src, UINT32 dst,
WRITE64_HANDLER( real3d_cmd_w )
{
- real3d_display_list_end();
+ real3d_display_list_end(space->machine);
}
@@ -1078,7 +1078,7 @@ static int clip_polygon(const poly_vertex *v, int num_vertices, PLANE cp, poly_v
return clip_verts;
}
-static void render_one(TRIANGLE *tri)
+static void render_one(running_machine *machine, TRIANGLE *tri)
{
poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
poly_draw_scanline_func callback = NULL;
@@ -1096,7 +1096,7 @@ static void render_one(TRIANGLE *tri)
tri->v[2].pu = tri->v[2].pu * tri->v[2].pz * 256.0f;
tri->v[2].pv = tri->v[2].pv * tri->v[2].pz * 256.0f;
- extra->texture = get_texture((tri->param & TRI_PARAM_TEXTURE_PAGE) ? 1 : 0, tri->texture_x, tri->texture_y, tri->texture_width, tri->texture_height, tri->texture_format);
+ extra->texture = get_texture(machine, (tri->param & TRI_PARAM_TEXTURE_PAGE) ? 1 : 0, tri->texture_x, tri->texture_y, tri->texture_width, tri->texture_height, tri->texture_format);
extra->texture_param = tri->param;
extra->polygon_transparency = tri->transparency;
extra->polygon_intensity = tri->intensity;
@@ -1119,7 +1119,7 @@ static void render_one(TRIANGLE *tri)
}
}
-static void draw_model(UINT32 addr)
+static void draw_model(running_machine *machine, UINT32 addr)
{
UINT32 *model = (addr >= 0x100000) ? &model3_vrom[addr] : &polygon_ram[addr];
UINT32 header[7];
@@ -1306,7 +1306,7 @@ static void draw_model(UINT32 addr)
tri.param |= (header[2] & 0x1) ? TRI_PARAM_TEXTURE_MIRROR_V : 0;
tri.param |= (header[6] & 0x80000000) ? TRI_PARAM_ALPHA_TEST : 0;
- render_one(&tri);
+ render_one(machine, &tri);
}
}
@@ -1346,16 +1346,16 @@ static void load_matrix(int matrix_num, MATRIX *out)
(*out)[3][0] = matrix[0]; (*out)[3][1] = matrix[1]; (*out)[3][2] = matrix[2]; (*out)[3][3] = 1.0f;
}
-static void traverse_list4(int lod_num, UINT32 address)
+static void traverse_list4(running_machine *machine, int lod_num, UINT32 address)
{
/* does something with the LOD selection */
UINT32 *list = get_memory_pointer(address);
UINT32 link = list[0];
- draw_model(link & 0xffffff);
+ draw_model(machine, link & 0xffffff);
}
-static void traverse_list(UINT32 address)
+static void traverse_list(running_machine *machine, UINT32 address)
{
UINT32 *list = get_memory_pointer(address);
int list_ptr = 0;
@@ -1384,29 +1384,29 @@ static void traverse_list(UINT32 address)
address = list[--list_ptr] & 0xffffff;
if (address != 0 && address != 0x800800)
// if (address != 0)
- draw_block(address);
+ draw_block(machine, address);
}
list_depth--;
}
-INLINE void process_link(UINT32 address, UINT32 link)
+INLINE void process_link(running_machine *machine, UINT32 address, UINT32 link)
{
if (link != 0 && link != 0x0fffffff && link != 0x00800800 && link != 0x01000000)
{
switch (link >> 24)
{
case 0x00: /* link to another node */
- draw_block(link & 0xffffff);
+ draw_block(machine, link & 0xffffff);
break;
case 0x01:
case 0x03: /* both of these link to models, is there any difference ? */
- draw_model(link & 0xffffff);
+ draw_model(machine, link & 0xffffff);
break;
case 0x04: /* list of links */
- traverse_list(link & 0xffffff);
+ traverse_list(machine, link & 0xffffff);
break;
default:
@@ -1416,7 +1416,7 @@ INLINE void process_link(UINT32 address, UINT32 link)
}
}
-static void draw_block(UINT32 address)
+static void draw_block(running_machine *machine, UINT32 address)
{
const UINT32 *node = get_memory_pointer(address);
UINT32 link;
@@ -1446,18 +1446,18 @@ static void draw_block(UINT32 address)
/* bit 0x08 of word 0 indicates a pointer list */
if (node[0] & 0x08)
- traverse_list4((node[3 - offset] >> 12) & 0x7f, link & 0xffffff);
+ traverse_list4(machine, (node[3 - offset] >> 12) & 0x7f, link & 0xffffff);
else
- process_link(address, link);
+ process_link(machine, address, link);
pop_matrix_stack();
/* handle the second link */
link = node[8 - offset];
- process_link(address, link);
+ process_link(machine, address, link);
}
-static void draw_viewport(int pri, UINT32 address)
+static void draw_viewport(running_machine *machine, int pri, UINT32 address)
{
const UINT32 *node = get_memory_pointer(address);
UINT32 link_address;
@@ -1471,7 +1471,7 @@ static void draw_viewport(int pri, UINT32 address)
/* traverse to the link node before drawing this viewport */
/* check this is correct as this affects the rendering order */
if (link_address != 0x01000000)
- draw_viewport(pri, link_address);
+ draw_viewport(machine, pri, link_address);
/* skip if this isn't the right priority */
if (pri != ((node[0] >> 3) & 3))
@@ -1515,18 +1515,18 @@ static void draw_viewport(int pri, UINT32 address)
load_matrix(0, &coordinate_system);
/* process a link */
- process_link(link_address, node[2]);
+ process_link(machine, link_address, node[2]);
}
-static void real3d_traverse_display_list(void)
+static void real3d_traverse_display_list(running_machine *machine)
{
int pri;
init_matrix_stack();
for (pri = 0; pri < 4; pri++)
- draw_viewport(pri, 0x800000);
+ draw_viewport(machine, pri, 0x800000);
poly_wait(poly, "real3d_traverse_display_list");
}
diff --git a/src/mame/video/namcos22.c b/src/mame/video/namcos22.c
index bf7de0ee420..34f6d971657 100644
--- a/src/mame/video/namcos22.c
+++ b/src/mame/video/namcos22.c
@@ -837,7 +837,7 @@ MallocSceneNode( running_machine *machine )
}
else
{
- node = alloc_or_die(struct SceneNode);
+ node = auto_alloc(machine, struct SceneNode);
}
memset( node, 0, sizeof(*node) );
return node;
@@ -2199,13 +2199,6 @@ static void namcos22_reset(running_machine *machine)
static void namcos22_exit(running_machine *machine)
{
- while (mpFreeSceneNode != NULL)
- {
- struct SceneNode *node = mpFreeSceneNode;
- mpFreeSceneNode = node->nextInBucket;
- free(node);
- }
-
poly_free(poly);
}
diff --git a/src/mame/video/naughtyb.c b/src/mame/video/naughtyb.c
index b366b21c9d5..68fb3871d95 100644
--- a/src/mame/video/naughtyb.c
+++ b/src/mame/video/naughtyb.c
@@ -91,10 +91,10 @@ PALETTE_INIT( naughtyb )
rgb_t *rgb;
int i;
- rgb = compute_res_net_all(color_prom, &naughtyb_decode_info, &naughtyb_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &naughtyb_decode_info, &naughtyb_net_info);
for (i = 0; i < 0x100; i++)
palette_set_color(machine, BITSWAP8(i,5,7,6,2,1,0,4,3), rgb[i]);
- free(rgb);
+ auto_free(machine, rgb);
palette_normalize_range(machine->palette, 0, 255, 0, 255);
}
diff --git a/src/mame/video/phoenix.c b/src/mame/video/phoenix.c
index ed24ae3e613..81e3cc22e9c 100644
--- a/src/mame/video/phoenix.c
+++ b/src/mame/video/phoenix.c
@@ -90,7 +90,7 @@ PALETTE_INIT( phoenix )
int i;
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &phoenix_decode_info, &phoenix_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &phoenix_decode_info, &phoenix_net_info);
/* native order */
for (i=0;i<256;i++)
{
@@ -99,7 +99,7 @@ PALETTE_INIT( phoenix )
palette_set_color(machine,i,rgb[col]);
}
palette_normalize_range(machine->palette, 0, 255, 0, 255);
- free(rgb);
+ auto_free(machine, rgb);
}
PALETTE_INIT( survival )
@@ -107,7 +107,7 @@ PALETTE_INIT( survival )
int i;
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &phoenix_decode_info, &survival_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &phoenix_decode_info, &survival_net_info);
/* native order */
for (i=0;i<256;i++)
{
@@ -116,7 +116,7 @@ PALETTE_INIT( survival )
palette_set_color(machine,i,rgb[col]);
}
palette_normalize_range(machine->palette, 0, 255, 0, 255);
- free(rgb);
+ auto_free(machine, rgb);
}
PALETTE_INIT( pleiads )
@@ -124,7 +124,7 @@ PALETTE_INIT( pleiads )
int i;
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &phoenix_decode_info, &pleiades_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &phoenix_decode_info, &pleiades_net_info);
/* native order */
for (i=0;i<256;i++)
{
@@ -133,7 +133,7 @@ PALETTE_INIT( pleiads )
palette_set_color(machine,i,rgb[col]);
}
palette_normalize_range(machine->palette, 0, 255, 0, 255);
- free(rgb);
+ auto_free(machine, rgb);
}
/***************************************************************************
diff --git a/src/mame/video/popper.c b/src/mame/video/popper.c
index 2d4869184cc..d95740aa597 100644
--- a/src/mame/video/popper.c
+++ b/src/mame/video/popper.c
@@ -48,10 +48,10 @@ PALETTE_INIT( popper )
{
rgb_t *rgb;
- rgb = compute_res_net_all(color_prom, &popper_decode_info, &popper_net_info);
+ rgb = compute_res_net_all(machine, color_prom, &popper_decode_info, &popper_net_info);
palette_set_colors(machine, 0, rgb, 64);
palette_normalize_range(machine->palette, 0, 63, 0, 255);
- free(rgb);
+ auto_free(machine, rgb);
}
WRITE8_HANDLER( popper_ol_videoram_w )
diff --git a/src/mame/video/tceptor.c b/src/mame/video/tceptor.c
index f4e9078e1e2..c036a5015eb 100644
--- a/src/mame/video/tceptor.c
+++ b/src/mame/video/tceptor.c
@@ -263,7 +263,7 @@ static void decode_bg(running_machine *machine, const char * region)
int len = 0x8000;
int i;
- buffer = alloc_array_or_die(UINT8, len);
+ buffer = auto_alloc_array(machine, UINT8, len);
/* expand rom tc2-19.10d */
for (i = 0; i < len / 2; i++)
@@ -273,7 +273,7 @@ static void decode_bg(running_machine *machine, const char * region)
}
memcpy(src, buffer, len);
- free(buffer);
+ auto_free(machine, buffer);
/* decode the graphics */
machine->gfx[gfx_index] = gfx_element_alloc(machine, &bg_layout, memory_region(machine, region), 64, 2048);
diff --git a/src/osd/osdcore.h b/src/osd/osdcore.h
index 91811eea9fc..67bfda407e2 100644
--- a/src/osd/osdcore.h
+++ b/src/osd/osdcore.h
@@ -721,6 +721,39 @@ void osd_work_item_release(osd_work_item *item);
***************************************************************************/
/*-----------------------------------------------------------------------------
+ osd_malloc: allocate memory that
+
+ Parameters:
+
+ size - the number of bytes to allocate
+
+ Return value:
+
+ a pointer to the allocated memory
+
+ Notes:
+
+ This is just a hook to do OS-specific allocation trickery.
+ It can be safely written as a wrapper to malloc().
+-----------------------------------------------------------------------------*/
+void *osd_malloc(size_t size);
+
+
+/*-----------------------------------------------------------------------------
+ osd_free: free memory allocated by osd_malloc
+
+ Parameters:
+
+ ptr - the pointer returned from osd_mallo
+
+ Return value:
+
+ None
+-----------------------------------------------------------------------------*/
+void osd_free(void *ptr);
+
+
+/*-----------------------------------------------------------------------------
osd_alloc_executable: allocate memory that can contain executable code
Parameters:
diff --git a/src/osd/osdepend.h b/src/osd/osdepend.h
index 9f187ca472b..b2d1484085e 100644
--- a/src/osd/osdepend.h
+++ b/src/osd/osdepend.h
@@ -66,7 +66,7 @@
#ifndef __OSDEPEND_H__
#define __OSDEPEND_H__
-#include "mamecore.h"
+#include "emucore.h"
#include "osdcore.h"
#include "inptport.h"
#include "timer.h"
diff --git a/src/osd/osdmini/minimisc.c b/src/osd/osdmini/minimisc.c
index 7fba006366d..8faae218544 100644
--- a/src/osd/osdmini/minimisc.c
+++ b/src/osd/osdmini/minimisc.c
@@ -43,6 +43,26 @@
//============================================================
+// osd_alloc
+//============================================================
+
+void *osd_alloc(size_t size)
+{
+ return malloc(size);
+}
+
+
+//============================================================
+// osd_free
+//============================================================
+
+void osd_free(void *ptr)
+{
+ free(ptr);
+}
+
+
+//============================================================
// osd_alloc_executable
//============================================================
diff --git a/src/osd/windows/d3d8intf.c b/src/osd/windows/d3d8intf.c
index 5a5df622e9a..1d8c02c8da3 100644
--- a/src/osd/windows/d3d8intf.c
+++ b/src/osd/windows/d3d8intf.c
@@ -136,7 +136,7 @@ d3d *drawd3d8_init(void)
}
// allocate an object to hold our data
- d3dptr = alloc_or_die(d3d);
+ d3dptr = global_alloc(d3d);
d3dptr->version = 8;
d3dptr->d3dobj = d3d8;
d3dptr->dllhandle = dllhandle;
@@ -258,7 +258,7 @@ static ULONG d3d_release(d3d *d3dptr)
IDirect3D8 *d3d8 = (IDirect3D8 *)d3dptr->d3dobj;
ULONG result = IDirect3D8_Release(d3d8);
FreeLibrary(d3dptr->dllhandle);
- free(d3dptr);
+ global_free(d3dptr);
return result;
}
diff --git a/src/osd/windows/d3d9intf.c b/src/osd/windows/d3d9intf.c
index 04880352b84..805ba7f8c28 100644
--- a/src/osd/windows/d3d9intf.c
+++ b/src/osd/windows/d3d9intf.c
@@ -134,7 +134,7 @@ d3d *drawd3d9_init(void)
}
// allocate an object to hold our data
- d3dptr = alloc_or_die(d3d);
+ d3dptr = global_alloc(d3d);
d3dptr->version = 9;
d3dptr->d3dobj = d3d9;
d3dptr->dllhandle = dllhandle;
@@ -256,7 +256,7 @@ static ULONG d3d_release(d3d *d3dptr)
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
ULONG result = IDirect3D9_Release(d3d9);
FreeLibrary(d3dptr->dllhandle);
- free(d3dptr);
+ global_free(d3dptr);
return result;
}
diff --git a/src/osd/windows/debugwin.c b/src/osd/windows/debugwin.c
index 28abcb151db..ccc183b190f 100644
--- a/src/osd/windows/debugwin.c
+++ b/src/osd/windows/debugwin.c
@@ -430,7 +430,7 @@ void debugwin_init_windows(void)
t_face = tstring_from_utf8(options_get_string(mame_options(), WINOPTION_DEBUGGER_FONT));
debug_font = CreateFont(-MulDiv(size, GetDeviceCaps(temp_dc, LOGPIXELSY), 72), 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, t_face);
- free(t_face);
+ global_free(t_face);
// fall back to Lucida Console 8
if (debug_font == NULL)
@@ -535,7 +535,7 @@ static debugwin_info *debugwin_window_create(running_machine *machine, LPCSTR ti
RECT work_bounds;
// allocate memory
- info = alloc_clear_or_die(debugwin_info);
+ info = global_alloc_clear(debugwin_info);
// create the window
info->handler = handler;
@@ -567,7 +567,7 @@ static debugwin_info *debugwin_window_create(running_machine *machine, LPCSTR ti
cleanup:
if (info->wnd != NULL)
DestroyWindow(info->wnd);
- free(info);
+ global_free(info);
return NULL;
}
@@ -599,7 +599,7 @@ static void debugwin_window_free(debugwin_info *info)
}
// free our memory
- free(info);
+ global_free(info);
}
@@ -1574,7 +1574,7 @@ static LRESULT CALLBACK debugwin_edit_proc(HWND wnd, UINT message, WPARAM wparam
if (utf8_buffer != NULL)
{
(*info->process_string)(info, utf8_buffer);
- free(utf8_buffer);
+ global_free(utf8_buffer);
}
}
break;
@@ -1777,7 +1777,7 @@ static void memory_create_window(running_machine *machine)
{
TCHAR *t_name = tstring_from_utf8(subview->name);
int item = SendMessage(info->otherwnd[0], CB_ADDSTRING, 0, (LPARAM)t_name);
- free(t_name);
+ global_free(t_name);
if (cursel == -1 && subview->space != NULL && subview->space->cpu == curcpu)
cursel = item;
}
@@ -2086,7 +2086,7 @@ static void disasm_create_window(running_machine *machine)
{
TCHAR *t_name = tstring_from_utf8(subview->name);
int item = SendMessage(info->otherwnd[0], CB_ADDSTRING, 0, (LPARAM)t_name);
- free(t_name);
+ global_free(t_name);
if (cursel == 0 && subview->space->cpu == curcpu)
cursel = item;
}
diff --git a/src/osd/windows/drawd3d.c b/src/osd/windows/drawd3d.c
index 4a061224157..7d2267f9da4 100644
--- a/src/osd/windows/drawd3d.c
+++ b/src/osd/windows/drawd3d.c
@@ -532,7 +532,7 @@ static int drawd3d_window_init(win_window_info *window)
d3d_info *d3d;
// allocate memory for our structures
- d3d = alloc_clear_or_die(d3d_info);
+ d3d = global_alloc_clear(d3d_info);
window->drawdata = d3d;
// experimental: load a PNG to use for vector rendering; it is treated
@@ -582,7 +582,7 @@ static void drawd3d_window_destroy(win_window_info *window)
bitmap_free(d3d->vector_bitmap);
// free the memory in the window
- free(d3d);
+ global_free(d3d);
window->drawdata = NULL;
}
@@ -943,7 +943,7 @@ static void device_delete_resources(d3d_info *d3d)
(*d3dintf->texture.release)(tex->d3dtex);
if (tex->d3dsurface != NULL)
(*d3dintf->surface.release)(tex->d3dsurface);
- free(tex);
+ global_free(tex);
}
// free the vertex buffer
@@ -1201,7 +1201,7 @@ static int config_adapter_mode(win_window_info *window)
if (utf8_device != NULL)
{
mame_printf_error("Device %s currently in an unsupported mode\n", utf8_device);
- free(utf8_device);
+ global_free(utf8_device);
}
return 1;
}
@@ -1229,7 +1229,7 @@ static int config_adapter_mode(win_window_info *window)
if (utf8_device != NULL)
{
mame_printf_error("Proposed video mode not supported on device %s\n", utf8_device);
- free(utf8_device);
+ global_free(utf8_device);
}
return 1;
}
@@ -1689,7 +1689,7 @@ static texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsour
HRESULT result;
// allocate a new texture
- texture = alloc_clear_or_die(texture_info);
+ texture = global_alloc_clear(texture_info);
// fill in the core data
texture->hash = texture_compute_hash(texsource, flags);
@@ -1813,7 +1813,7 @@ error:
(*d3dintf->surface.release)(texture->d3dsurface);
if (texture->d3dtex != NULL)
(*d3dintf->texture.release)(texture->d3dtex);
- free(texture);
+ global_free(texture);
return NULL;
}
diff --git a/src/osd/windows/drawdd.c b/src/osd/windows/drawdd.c
index f8e2884a02d..66773379d45 100644
--- a/src/osd/windows/drawdd.c
+++ b/src/osd/windows/drawdd.c
@@ -281,7 +281,7 @@ static int drawdd_window_init(win_window_info *window)
dd_info *dd;
// allocate memory for our structures
- dd = alloc_clear_or_die(dd_info);
+ dd = global_alloc_clear(dd_info);
window->drawdata = dd;
// configure the adapter for the mode we want
@@ -318,7 +318,7 @@ static void drawdd_window_destroy(win_window_info *window)
ddraw_delete(window);
// free the memory in the window
- free(dd);
+ global_free(dd);
window->drawdata = NULL;
}
@@ -600,7 +600,8 @@ static int ddraw_create_surfaces(win_window_info *window)
if (dd->membuffersize < dd->blitwidth * dd->blitheight * 4)
{
dd->membuffersize = dd->blitwidth * dd->blitheight * 4;
- dd->membuffer = realloc(dd->membuffer, dd->membuffersize);
+ global_free(dd->membuffer);
+ dd->membuffer = global_alloc_array(UINT8, dd->membuffersize);
}
if (dd->membuffer == NULL)
goto error;
@@ -707,8 +708,7 @@ static void ddraw_delete_surfaces(win_window_info *window)
dd->clipper = NULL;
// free the memory buffer
- if (dd->membuffer != NULL)
- free(dd->membuffer);
+ global_free(dd->membuffer);
dd->membuffer = NULL;
dd->membuffersize = 0;
diff --git a/src/osd/windows/drawgdi.c b/src/osd/windows/drawgdi.c
index b31ee1ff95f..0f9f7425bcb 100644
--- a/src/osd/windows/drawgdi.c
+++ b/src/osd/windows/drawgdi.c
@@ -44,8 +44,7 @@
#include <windows.h>
// MAME headers
-#include "mamecore.h"
-#include "restrack.h"
+#include "emucore.h"
// MAMEOS headers
#include "window.h"
@@ -121,7 +120,7 @@ static int drawgdi_window_init(win_window_info *window)
int i;
// allocate memory for our structures
- gdi = alloc_clear_or_die(gdi_info);
+ gdi = global_alloc_clear(gdi_info);
window->drawdata = gdi;
// fill in the bitmap info header
@@ -162,8 +161,8 @@ static void drawgdi_window_destroy(win_window_info *window)
// free the bitmap memory
if (gdi->bmdata != NULL)
- free(gdi->bmdata);
- free(gdi);
+ global_free(gdi->bmdata);
+ global_free(gdi);
window->drawdata = NULL;
}
@@ -209,7 +208,8 @@ static int drawgdi_window_draw(win_window_info *window, HDC dc, int update)
if (pitch * height * 4 > gdi->bmsize)
{
gdi->bmsize = pitch * height * 4 * 2;
- gdi->bmdata = (UINT8 *)realloc(gdi->bmdata, gdi->bmsize);
+ global_free(gdi->bmdata);
+ gdi->bmdata = global_alloc_array(UINT8, gdi->bmsize);
}
// draw the primitives to the bitmap
diff --git a/src/osd/windows/drawnone.c b/src/osd/windows/drawnone.c
index d61e54adb36..07cb67f345f 100644
--- a/src/osd/windows/drawnone.c
+++ b/src/osd/windows/drawnone.c
@@ -44,7 +44,7 @@
#include <windows.h>
// MAME headers
-#include "mamecore.h"
+#include "emucore.h"
// MAMEOS headers
#include "window.h"
diff --git a/src/osd/windows/input.c b/src/osd/windows/input.c
index 47f7a96f800..09750a094ac 100644
--- a/src/osd/windows/input.c
+++ b/src/osd/windows/input.c
@@ -688,7 +688,7 @@ BOOL wininput_handle_raw(HANDLE device)
// if necessary, allocate a temporary buffer and fetch the data
if (size > sizeof(small_buffer))
{
- data = (LPBYTE)malloc(size);
+ data = global_alloc_array(BYTE, size);
if (data == NULL)
return result;
}
@@ -720,7 +720,7 @@ BOOL wininput_handle_raw(HANDLE device)
// free the temporary buffer and return the result
if (data != small_buffer)
- free(data);
+ global_free(data);
return result;
}
@@ -826,7 +826,7 @@ static device_info *generic_device_alloc(running_machine *machine, device_info *
device_info *devinfo;
// allocate memory for the device object
- devinfo = alloc_clear_or_die(device_info);
+ devinfo = global_alloc_clear(device_info);
devinfo->head = devlist_head_ptr;
devinfo->machine = machine;
@@ -842,7 +842,7 @@ static device_info *generic_device_alloc(running_machine *machine, device_info *
return devinfo;
error:
- free(devinfo);
+ global_free(devinfo);
return NULL;
}
@@ -862,11 +862,11 @@ static void generic_device_free(device_info *devinfo)
// free the copy of the name if present
if (devinfo->name != NULL)
- free((void *)devinfo->name);
+ global_free((void *)devinfo->name);
devinfo->name = NULL;
// and now free the info
- free(devinfo);
+ global_free(devinfo);
}
@@ -979,7 +979,7 @@ static void win32_init(running_machine *machine)
{
const char *name = utf8_from_tstring(default_axis_name[axisnum]);
input_device_item_add(devinfo->device, name, &devinfo->mouse.state.lX + axisnum, (input_item_id)(ITEM_ID_XAXIS + axisnum), generic_axis_get_state);
- free((void *)name);
+ global_free(name);
}
// populate the buttons
@@ -987,7 +987,7 @@ static void win32_init(running_machine *machine)
{
const char *name = utf8_from_tstring(default_button_name(butnum));
input_device_item_add(devinfo->device, name, &devinfo->mouse.state.rgbButtons[butnum], (input_item_id)(ITEM_ID_BUTTON1 + butnum), generic_button_get_state);
- free((void *)name);
+ global_free(name);
}
}
}
@@ -1298,14 +1298,14 @@ static const char *dinput_device_item_name(device_info *devinfo, int offset, con
return utf8_from_tstring(namestring);
// otherwise, allocate space to add the suffix
- combined = alloc_array_or_die(TCHAR, _tcslen(namestring) + 1 + _tcslen(suffix) + 1);
+ combined = global_alloc_array(TCHAR, _tcslen(namestring) + 1 + _tcslen(suffix) + 1);
_tcscpy(combined, namestring);
_tcscat(combined, TEXT(" "));
_tcscat(combined, suffix);
// convert to UTF8, free the temporary string, and return
utf8 = utf8_from_tstring(combined);
- free(combined);
+ global_free(combined);
return utf8;
}
@@ -1367,7 +1367,7 @@ static BOOL CALLBACK dinput_keyboard_enum(LPCDIDEVICEINSTANCE instance, LPVOID r
// add the item to the device
input_device_item_add(devinfo->device, name, &devinfo->keyboard.state[keynum], itemid, generic_button_get_state);
- free((void *)name);
+ global_free(name);
}
exit:
@@ -1446,7 +1446,7 @@ static BOOL CALLBACK dinput_mouse_enum(LPCDIDEVICEINSTANCE instance, LPVOID ref)
if (guninfo != NULL && axisnum < 2)
input_device_item_add(guninfo->device, name, &guninfo->mouse.state.lX + axisnum, (input_item_id)(ITEM_ID_XAXIS + axisnum), generic_axis_get_state);
- free((void *)name);
+ global_free(name);
}
// populate the buttons
@@ -1461,7 +1461,7 @@ static BOOL CALLBACK dinput_mouse_enum(LPCDIDEVICEINSTANCE instance, LPVOID ref)
if (guninfo != NULL)
input_device_item_add(guninfo->device, name, &devinfo->mouse.state.rgbButtons[butnum], (input_item_id)(ITEM_ID_BUTTON1 + butnum), generic_button_get_state);
- free((void *)name);
+ global_free(name);
}
exit:
@@ -1553,7 +1553,7 @@ static BOOL CALLBACK dinput_joystick_enum(LPCDIDEVICEINSTANCE instance, LPVOID r
// populate the item description as well
name = dinput_device_item_name(devinfo, offsetof(DIJOYSTATE2, lX) + axisnum * sizeof(LONG), default_axis_name[axisnum], NULL);
input_device_item_add(devinfo->device, name, &devinfo->joystick.state.lX + axisnum, (input_item_id)(ITEM_ID_XAXIS + axisnum), generic_axis_get_state);
- free((void *)name);
+ global_free(name);
axiscount++;
}
@@ -1566,22 +1566,22 @@ static BOOL CALLBACK dinput_joystick_enum(LPCDIDEVICEINSTANCE instance, LPVOID r
// left
name = dinput_device_item_name(devinfo, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum), TEXT("L"));
input_device_item_add(devinfo->device, name, (void *)(FPTR)(povnum * 4 + POVDIR_LEFT), ITEM_ID_OTHER_SWITCH, dinput_joystick_pov_get_state);
- free((void *)name);
+ global_free(name);
// right
name = dinput_device_item_name(devinfo, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum), TEXT("R"));
input_device_item_add(devinfo->device, name, (void *)(FPTR)(povnum * 4 + POVDIR_RIGHT), ITEM_ID_OTHER_SWITCH, dinput_joystick_pov_get_state);
- free((void *)name);
+ global_free(name);
// up
name = dinput_device_item_name(devinfo, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum), TEXT("U"));
input_device_item_add(devinfo->device, name, (void *)(FPTR)(povnum * 4 + POVDIR_UP), ITEM_ID_OTHER_SWITCH, dinput_joystick_pov_get_state);
- free((void *)name);
+ global_free(name);
// down
name = dinput_device_item_name(devinfo, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum), TEXT("D"));
input_device_item_add(devinfo->device, name, (void *)(FPTR)(povnum * 4 + POVDIR_DOWN), ITEM_ID_OTHER_SWITCH, dinput_joystick_pov_get_state);
- free((void *)name);
+ global_free(name);
}
// populate the buttons
@@ -1590,7 +1590,7 @@ static BOOL CALLBACK dinput_joystick_enum(LPCDIDEVICEINSTANCE instance, LPVOID r
FPTR offset = (FPTR)(&((DIJOYSTATE2 *)NULL)->rgbButtons[butnum]);
const char *name = dinput_device_item_name(devinfo, offset, default_button_name(butnum), NULL);
input_device_item_add(devinfo->device, name, &devinfo->joystick.state.rgbButtons[butnum], (butnum < 16) ? (input_item_id)(ITEM_ID_BUTTON1 + butnum) : ITEM_ID_OTHER_SWITCH, generic_button_get_state);
- free((void *)name);
+ global_free(name);
}
exit:
@@ -1683,7 +1683,7 @@ static void rawinput_init(running_machine *machine)
goto error;
if (device_count == 0)
goto error;
- devlist = alloc_array_or_die(RAWINPUTDEVICELIST, device_count);
+ devlist = global_alloc_array(RAWINPUTDEVICELIST, device_count);
if ((*get_rawinput_device_list)(devlist, &device_count, sizeof(*devlist)) == -1)
goto error;
@@ -1725,12 +1725,12 @@ static void rawinput_init(running_machine *machine)
if (!(*register_rawinput_devices)(reglist, regcount, sizeof(reglist[0])))
goto error;
- free(devlist);
+ global_free(devlist);
return;
error:
if (devlist != NULL)
- free(devlist);
+ global_free(devlist);
}
@@ -1763,7 +1763,7 @@ static device_info *rawinput_device_create(running_machine *machine, device_info
// determine the length of the device name, allocate it, and fetch it
if ((*get_rawinput_device_info)(device->hDevice, RIDI_DEVICENAME, NULL, &name_length) != 0)
goto error;
- tname = alloc_array_or_die(TCHAR, name_length);
+ tname = global_alloc_array(TCHAR, name_length);
if ((*get_rawinput_device_info)(device->hDevice, RIDI_DEVICENAME, tname, &name_length) == -1)
goto error;
@@ -1774,7 +1774,7 @@ static device_info *rawinput_device_create(running_machine *machine, device_info
// improve the name and then allocate a device
tname = rawinput_device_improve_name(tname);
devinfo = generic_device_alloc(machine, devlist_head_ptr, tname);
- free(tname);
+ global_free(tname);
// copy the handle
devinfo->rawinput.device = device->hDevice;
@@ -1782,7 +1782,7 @@ static device_info *rawinput_device_create(running_machine *machine, device_info
error:
if (tname != NULL)
- free(tname);
+ global_free(tname);
if (devinfo != NULL)
rawinput_device_release(devinfo);
return NULL;
@@ -1827,7 +1827,7 @@ static TCHAR *rawinput_device_improve_name(TCHAR *name)
return name;
// allocate a temporary string and concatenate the base path plus the name
- regpath = alloc_array_or_die(TCHAR, _tcslen(basepath) + 1 + _tcslen(name));
+ regpath = global_alloc_array(TCHAR, _tcslen(basepath) + 1 + _tcslen(name));
_tcscpy(regpath, basepath);
chdst = regpath + _tcslen(regpath);
@@ -1915,7 +1915,7 @@ static TCHAR *rawinput_device_improve_name(TCHAR *name)
// free memory and close the key
if (endparentid != NULL)
- free(endparentid);
+ global_free(endparentid);
RegCloseKey(endkey);
}
}
@@ -1931,7 +1931,7 @@ static TCHAR *rawinput_device_improve_name(TCHAR *name)
convert:
// replace the name with the nicer one
- free(name);
+ global_free(name);
// remove anything prior to the final semicolon
chsrc = _tcsrchr(regstring, ';');
@@ -1939,14 +1939,14 @@ convert:
chsrc++;
else
chsrc = regstring;
- name = alloc_array_or_die(TCHAR, _tcslen(chsrc) + 1);
+ name = global_alloc_array(TCHAR, _tcslen(chsrc) + 1);
_tcscpy(name, chsrc);
exit:
if (regstring != NULL)
- free(regstring);
+ global_free(regstring);
if (regpath != NULL)
- free(regpath);
+ global_free(regpath);
if (regkey != NULL)
RegCloseKey(regkey);
@@ -1985,7 +1985,7 @@ static void rawinput_keyboard_enum(running_machine *machine, PRAWINPUTDEVICELIST
// add the item to the device
input_device_item_add(devinfo->device, name, &devinfo->keyboard.state[keynum], itemid, generic_button_get_state);
- free((void *)name);
+ global_free(name);
}
}
@@ -2059,7 +2059,7 @@ static void rawinput_mouse_enum(running_machine *machine, PRAWINPUTDEVICELIST de
if (guninfo != NULL && axisnum < 2)
input_device_item_add(guninfo->device, name, &guninfo->mouse.state.lX + axisnum, (input_item_id)(ITEM_ID_XAXIS + axisnum), generic_axis_get_state);
- free((void *)name);
+ global_free(name);
}
// populate the buttons
@@ -2072,7 +2072,7 @@ static void rawinput_mouse_enum(running_machine *machine, PRAWINPUTDEVICELIST de
if (guninfo != NULL)
input_device_item_add(guninfo->device, name, &guninfo->mouse.state.rgbButtons[butnum], (input_item_id)(ITEM_ID_BUTTON1 + butnum), generic_button_get_state);
- free((void *)name);
+ global_free(name);
}
}
@@ -2160,7 +2160,7 @@ static TCHAR *reg_query_string(HKEY key, const TCHAR *path)
return NULL;
// allocate a buffer
- buffer = alloc_array_or_die(TCHAR, datalen + sizeof(*buffer));
+ buffer = global_alloc_array(TCHAR, datalen + sizeof(*buffer));
buffer[datalen / sizeof(*buffer)] = 0;
// now get the actual data
@@ -2169,7 +2169,7 @@ static TCHAR *reg_query_string(HKEY key, const TCHAR *path)
return buffer;
// otherwise return a NULL buffer
- free(buffer);
+ global_free(buffer);
return NULL;
}
diff --git a/src/osd/windows/main.c b/src/osd/windows/main.c
index 52c2f5ab96e..0d028ebb692 100644
--- a/src/osd/windows/main.c
+++ b/src/osd/windows/main.c
@@ -61,20 +61,11 @@ extern int utf8_main(int argc, char *argv[]);
#undef wmain
#endif
-#ifdef MALLOC_DEBUG
-extern void check_unfreed_mem(void);
-extern int winalloc_in_main_code;
-#endif
-
extern "C" int _tmain(int argc, TCHAR **argv)
{
int i, rc;
char **utf8_argv;
-#ifdef MALLOC_DEBUG
- winalloc_in_main_code = TRUE;
-#endif
-
/* convert arguments to UTF-8 */
utf8_argv = (char **) malloc(argc * sizeof(*argv));
if (utf8_argv == NULL)
@@ -94,10 +85,5 @@ extern "C" int _tmain(int argc, TCHAR **argv)
free(utf8_argv[i]);
free(utf8_argv);
-#ifdef MALLOC_DEBUG
- check_unfreed_mem();
- winalloc_in_main_code = FALSE;
-#endif
-
return rc;
}
diff --git a/src/osd/windows/output.c b/src/osd/windows/output.c
index 4629dcd886c..252a6ea43da 100644
--- a/src/osd/windows/output.c
+++ b/src/osd/windows/output.c
@@ -179,7 +179,7 @@ static void winoutput_exit(running_machine *machine)
{
registered_client *temp = clientlist;
clientlist = temp->next;
- free(temp);
+ global_free(temp);
}
// broadcast a shutdown message
@@ -260,7 +260,7 @@ static LRESULT register_client(HWND hwnd, LPARAM id)
}
// add us to the end
- *client = alloc_or_die(registered_client);
+ *client = global_alloc(registered_client);
(*client)->next = NULL;
(*client)->id = id;
(*client)->hwnd = hwnd;
@@ -286,7 +286,7 @@ static LRESULT unregister_client(HWND hwnd, LPARAM id)
{
registered_client *temp = *client;
*client = (*client)->next;
- free(temp);
+ global_free(temp);
found = TRUE;
break;
}
@@ -319,7 +319,7 @@ static LRESULT send_id_string(running_machine *machine, HWND hwnd, LPARAM id)
// allocate memory for the message
datalen = sizeof(*temp) + strlen(name);
- temp = (copydata_id_string *)alloc_array_or_die(UINT8, datalen);
+ temp = (copydata_id_string *)global_alloc_array(UINT8, datalen);
temp->id = id;
strcpy(temp->string, name);
@@ -330,7 +330,7 @@ static LRESULT send_id_string(running_machine *machine, HWND hwnd, LPARAM id)
SendMessage(hwnd, WM_COPYDATA, (WPARAM)output_hwnd, (LPARAM)&copydata);
// free the data
- free(temp);
+ global_free(temp);
return 0;
}
diff --git a/src/osd/windows/strconv.c b/src/osd/windows/strconv.c
index e70bd4aaf45..e7f8c011a4d 100644
--- a/src/osd/windows/strconv.c
+++ b/src/osd/windows/strconv.c
@@ -43,10 +43,6 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-// MAME headers
-#include "restrack.h"
-#include "mame.h"
-
// MAMEOS headers
#include "strconv.h"
#include "unicode.h"
diff --git a/src/osd/windows/strconv.h b/src/osd/windows/strconv.h
index c398be30be3..33f093112a9 100644
--- a/src/osd/windows/strconv.h
+++ b/src/osd/windows/strconv.h
@@ -42,7 +42,7 @@
#ifndef __WIN_STRCONV__
#define __WIN_STRCONV__
-#include "mamecore.h"
+#include "osdcore.h"
diff --git a/src/osd/windows/video.c b/src/osd/windows/video.c
index 7850ac96b9f..d3d119cede7 100644
--- a/src/osd/windows/video.c
+++ b/src/osd/windows/video.c
@@ -160,7 +160,7 @@ static void winvideo_exit(running_machine *machine)
{
win_monitor_info *temp = win_monitor_list;
win_monitor_list = temp->next;
- free(temp);
+ global_free(temp);
}
}
@@ -265,7 +265,7 @@ static void init_monitors(void)
if (utf8_device != NULL)
{
mame_printf_verbose("Video: Monitor %p = \"%s\" %s\n", monitor->handle, utf8_device, (monitor == primary_monitor) ? "(primary)" : "");
- free(utf8_device);
+ global_free(utf8_device);
}
}
}
@@ -290,7 +290,7 @@ static BOOL CALLBACK monitor_enum_callback(HMONITOR handle, HDC dc, LPRECT rect,
assert(result);
// allocate a new monitor info
- monitor = alloc_clear_or_die(win_monitor_info);
+ monitor = global_alloc_clear(win_monitor_info);
// copy in the data
monitor->handle = handle;
@@ -351,7 +351,7 @@ static win_monitor_info *pick_monitor(int index)
if (utf8_device != NULL)
{
rc = strcmp(scrname, utf8_device);
- free(utf8_device);
+ global_free(utf8_device);
}
if (rc == 0)
goto finishit;
@@ -473,7 +473,7 @@ static void extract_video_config(running_machine *machine)
static void load_effect_overlay(running_machine *machine, const char *filename)
{
const device_config *screen;
- char *tempstr = alloc_array_or_die(char, strlen(filename) + 5);
+ char *tempstr = global_alloc_array(char, strlen(filename) + 5);
char *dest;
// append a .PNG extension
@@ -488,7 +488,7 @@ static void load_effect_overlay(running_machine *machine, const char *filename)
if (effect_bitmap == NULL)
{
mame_printf_error("Unable to load PNG file '%s'\n", tempstr);
- free(tempstr);
+ global_free(tempstr);
return;
}
@@ -496,7 +496,7 @@ static void load_effect_overlay(running_machine *machine, const char *filename)
for (screen = video_screen_first(machine->config); screen != NULL; screen = video_screen_next(screen))
render_container_set_overlay(render_container_get_screen(screen), effect_bitmap);
- free(tempstr);
+ global_free(tempstr);
}
diff --git a/src/osd/windows/window.c b/src/osd/windows/window.c
index 64a1cb20f64..330b9c2bd02 100644
--- a/src/osd/windows/window.c
+++ b/src/osd/windows/window.c
@@ -614,7 +614,7 @@ void winwindow_video_window_create(running_machine *machine, int index, win_moni
assert(GetCurrentThreadId() == main_threadid);
// allocate a new window object
- window = alloc_clear_or_die(win_window_info);
+ window = global_alloc_clear(win_window_info);
window->maxwidth = config->width;
window->maxheight = config->height;
window->refresh = config->refresh;
@@ -709,7 +709,7 @@ static void winwindow_video_window_destroy(win_window_info *window)
osd_lock_free(window->render_lock);
// free the window itself
- free(window);
+ global_free(window);
}
diff --git a/src/osd/windows/windows.mak b/src/osd/windows/windows.mak
index aab0830bc09..21d6efeb9a3 100644
--- a/src/osd/windows/windows.mak
+++ b/src/osd/windows/windows.mak
@@ -147,6 +147,9 @@ CPPONLYFLAGS += /EHsc
# disable function pointer warnings in C++ which are evil to work around
CPPONLYFLAGS += /wd4191 /wd4060 /wd4065 /wd4640
+# disable warning about exception specifications
+CPPONLYFLAGS += /wd4290
+
# explicitly set the entry point for UNICODE builds
LDFLAGS += /ENTRY:wmainCRTStartup
@@ -206,7 +209,6 @@ DEFS += -Dmain=utf8_main
# debug build: enable guard pages on all memory allocations
ifdef DEBUG
DEFS += -DMALLOC_DEBUG
-LDFLAGS += -Wl,--allow-multiple-definition
endif
@@ -253,13 +255,7 @@ OSDCOREOBJS = \
$(WINOBJ)/wintime.o \
$(WINOBJ)/winutf8.o \
$(WINOBJ)/winutil.o \
- $(WINOBJ)/winwork.o \
-
-# if malloc debugging is enabled, include the necessary code
-ifneq ($(findstring MALLOC_DEBUG,$(DEFS)),)
-OSDCOREOBJS += \
- $(WINOBJ)/winalloc.o
-endif
+ $(WINOBJ)/winwork.o
@@ -344,4 +340,3 @@ $(RESFILE): $(WINSRC)/mame.rc $(WINOBJ)/mamevers.rc
$(WINOBJ)/mamevers.rc: $(BUILDOUT)/verinfo$(BUILD_EXE) $(SRC)/version.c
@echo Emitting $@...
@"$(BUILDOUT)/verinfo$(BUILD_EXE)" -b windows $(SRC)/version.c > $@
-
diff --git a/src/osd/windows/winmisc.c b/src/osd/windows/winmisc.c
index f1aa4d0668e..90c8dad9e9e 100644
--- a/src/osd/windows/winmisc.c
+++ b/src/osd/windows/winmisc.c
@@ -45,7 +45,7 @@
#include <tchar.h>
// MAME headers
-#include "osdcore.h"
+#include "emucore.h"
// MAMEOS headers
#include "winutf8.h"
@@ -53,6 +53,90 @@
//============================================================
+// MACROS
+//============================================================
+
+// presumed size of a page of memory
+#define PAGE_SIZE 4096
+
+// allocations this size and larger get guard pages
+#define GUARD_PAGE_THRESH 32
+
+// align allocations to start or end of the page?
+#define GUARD_ALIGN_START 0
+
+
+
+//============================================================
+// osd_malloc
+//============================================================
+
+void *osd_malloc(size_t size)
+{
+#ifndef MALLOC_DEBUG
+ return HeapAlloc(GetProcessHeap(), 0, size);
+#else
+ // add in space for the base pointer
+ size += sizeof(size_t);
+
+ // small items just come from the heap
+ void *result;
+ if (size < GUARD_PAGE_THRESH)
+ result = HeapAlloc(GetProcessHeap(), 0, size);
+
+ // large items get guard pages
+ else
+ {
+ // round the size up to a page boundary
+ size_t rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
+
+ // reserve that much memory, plus two guard pages
+ void *page_base = VirtualAlloc(NULL, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);
+ if (page_base == NULL)
+ return NULL;
+
+ // now allow access to everything but the first and last pages
+ page_base = VirtualAlloc(reinterpret_cast<UINT8 *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE);
+ if (page_base == NULL)
+ return NULL;
+
+ // work backwards from the page base to get to the block base
+ result = GUARD_ALIGN_START ? page_base : (reinterpret_cast<UINT8 *>(page_base) + rounded_size - size);
+ }
+
+ // store the page_base at the start
+ *reinterpret_cast<size_t *>(result) = size;
+ return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
+#endif
+}
+
+
+//============================================================
+// osd_free
+//============================================================
+
+void osd_free(void *ptr)
+{
+#ifndef MALLOC_DEBUG
+ HeapFree(GetProcessHeap(), 0, ptr);
+#else
+ size_t size = reinterpret_cast<size_t *>(ptr)[-1];
+
+ // small items just get freed
+ if (size < GUARD_PAGE_THRESH)
+ HeapFree(GetProcessHeap(), 0, ptr);
+
+ // large items need more care
+ else
+ {
+ FPTR page_base = (reinterpret_cast<FPTR>(ptr) - sizeof(size_t)) & ~(PAGE_SIZE - 1);
+ VirtualFree(reinterpret_cast<void *>(page_base - PAGE_SIZE), 0, MEM_RELEASE);
+ }
+#endif
+}
+
+
+//============================================================
// osd_alloc_executable
//============================================================
diff --git a/src/osd/windows/winprefix.h b/src/osd/windows/winprefix.h
index 7756adaab9a..5d8275d5653 100644
--- a/src/osd/windows/winprefix.h
+++ b/src/osd/windows/winprefix.h
@@ -41,34 +41,6 @@
#define _WIN32_WINNT 0x0501
-#ifdef MALLOC_DEBUG
-#include <stdlib.h>
-#include <malloc.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// override malloc/calloc/realloc/free to track file/line
-void *malloc_file_line(size_t size, const char *file, int line);
-void *calloc_file_line(size_t size, size_t count, const char *FILE, int line);
-void *realloc_file_line(void *memory, size_t size, const char *file, int line);
-void free_file_line(void *memory, const char *file, int line);
-
-#ifdef __cplusplus
-};
-#endif
-
-#undef malloc
-#define malloc(x) malloc_file_line(x, __FILE__, __LINE__)
-#undef calloc
-#define calloc(x,y) calloc_file_line(x, y, __FILE__, __LINE__)
-#undef realloc
-#define realloc(x,y) realloc_file_line(x, y, __FILE__, __LINE__)
-#undef free
-#define free(x) free_file_line(x, __FILE__, __LINE__)
-#endif
-
#ifdef _MSC_VER
#define alloca _alloca
#define round(x) floor((x) + 0.5)
diff --git a/src/tools/chdman.c b/src/tools/chdman.c
index ac056554a59..f3432560d16 100644
--- a/src/tools/chdman.c
+++ b/src/tools/chdman.c
@@ -874,7 +874,7 @@ static avi_error read_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sam
}
/* build the fake bitmap */
- *avconfig->video = *fullbitmap;
+ bitmap_clone_existing(avconfig->video, fullbitmap);
if (interlaced)
{
avconfig->video->base = BITMAP_ADDR16(avconfig->video, framenum % interlace_factor, 0);
@@ -944,7 +944,7 @@ static avi_error fake_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sam
}
/* build the fake bitmap */
- *avconfig->video = *fullbitmap;
+ bitmap_clone_existing(avconfig->video, fullbitmap);
if (interlaced)
{
avconfig->video->base = BITMAP_ADDR16(avconfig->video, framenum % interlace_factor, 0);
@@ -1827,7 +1827,7 @@ static int do_extractav(int argc, char *argv[], int param)
progress(framenum == 0, "Extracting hunk %d/%d... \r", framenum, numframes);
/* set up the fake bitmap for this frame */
- *avconfig.video = *fullbitmap;
+ bitmap_clone_existing(avconfig.video, fullbitmap);
if (interlaced)
{
avconfig.video->base = BITMAP_ADDR16(avconfig.video, framenum % 2, 0);
@@ -2158,7 +2158,7 @@ static int do_fixavdata(int argc, char *argv[], int param)
progress(framenum == 0, "Processing hunk %d/%d... \r", framenum, header.totalhunks);
/* set up the fake bitmap for this frame */
- *avconfig.video = *fullbitmap;
+ bitmap_clone_existing(avconfig.video, fullbitmap);
/* configure the decompressor for this frame */
chd_codec_config(chd, AV_CODEC_DECOMPRESS_CONFIG, &avconfig);
diff --git a/src/tools/ldverify.c b/src/tools/ldverify.c
index 0e250698fdc..acad492da0b 100644
--- a/src/tools/ldverify.c
+++ b/src/tools/ldverify.c
@@ -270,7 +270,7 @@ static int read_chd(void *file, int frame, bitmap_t *bitmap, INT16 *lsound, INT1
for (fieldnum = 0; fieldnum < interlace_factor; fieldnum++)
{
/* make a fake bitmap for this field */
- fakebitmap = *bitmap;
+ bitmap_clone_existing(&fakebitmap, bitmap);
fakebitmap.base = BITMAP_ADDR16(&fakebitmap, fieldnum, 0);
fakebitmap.rowpixels *= interlace_factor;
fakebitmap.height /= interlace_factor;
diff --git a/src/tools/romcmp.c b/src/tools/romcmp.c
index ebf6f5abfa9..265fd427caa 100644
--- a/src/tools/romcmp.c
+++ b/src/tools/romcmp.c
@@ -10,7 +10,6 @@
***************************************************************************/
#include "unzip.h"
-#include "osdepend.h" /* for CLIB_DECL */
#include "osdcore.h"
#include <stdarg.h>