diff options
Diffstat (limited to 'src/emu')
114 files changed, 436 insertions, 552 deletions
diff --git a/src/emu/audit.c b/src/emu/audit.c index dc7b8343887..b7aa96e1c22 100644 --- a/src/emu/audit.c +++ b/src/emu/audit.c @@ -88,8 +88,7 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid if (records > 0) { /* allocate memory for the records */ - *audit = (audit_record *)malloc_or_die(sizeof(**audit) * records); - memset(*audit, 0, sizeof(**audit) * records); + *audit = alloc_array_clear_or_die(audit_record, records); record = *audit; /* iterate over ROM sources and regions */ @@ -174,8 +173,7 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor goto skip; /* allocate memory for the records */ - *audit = (audit_record *)malloc_or_die(sizeof(**audit) * records); - memset(*audit, 0, sizeof(**audit) * records); + *audit = alloc_array_clear_or_die(audit_record, records); record = *audit; /* now iterate over sample entries */ diff --git a/src/emu/cheat.c b/src/emu/cheat.c index c317afa79cb..57e1b23cdad 100644 --- a/src/emu/cheat.c +++ b/src/emu/cheat.c @@ -371,8 +371,7 @@ void cheat_init(running_machine *machine) add_exit_callback(machine, cheat_exit); /* allocate memory */ - cheatinfo = (cheat_private *)auto_malloc(sizeof(*cheatinfo)); - memset(cheatinfo, 0, sizeof(*cheatinfo)); + cheatinfo = auto_alloc_clear(machine, cheat_private); machine->cheat_data = cheatinfo; /* load the cheat file */ @@ -1061,8 +1060,7 @@ static cheat_entry *cheat_entry_load(running_machine *machine, const char *filen } /* allocate memory for the cheat */ - cheat = (cheat_entry *)malloc_or_die(sizeof(*cheat) + (tempcount - 1) * sizeof(cheat->tempvar)); - memset(cheat, 0, sizeof(*cheat) + (tempcount - 1) * sizeof(cheat->tempvar)); + cheat = (cheat_entry *)alloc_array_clear_or_die(UINT8, sizeof(*cheat) + (tempcount - 1) * sizeof(cheat->tempvar)); cheat->numtemp = tempcount; /* get the description */ @@ -1232,8 +1230,7 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node cheat_parameter *param; /* allocate memory for it */ - param = (cheat_parameter *)malloc_or_die(sizeof(*param)); - memset(param, 0, sizeof(*param)); + param = alloc_clear_or_die(cheat_parameter); /* read the core attributes */ param->minval = xml_get_attribute_int(paramnode, "min", 0); @@ -1250,8 +1247,7 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node parameter_item *curitem; /* allocate memory for it */ - curitem = (parameter_item *)malloc_or_die(sizeof(*curitem)); - memset(curitem, 0, sizeof(*curitem)); + curitem = alloc_clear_or_die(parameter_item); /* check for NULL text */ if (itemnode->value == NULL || itemnode->value[0] == 0) @@ -1361,8 +1357,7 @@ static cheat_script *cheat_script_load(running_machine *machine, const char *fil const char *state; /* allocate memory for it */ - script = (cheat_script *)malloc_or_die(sizeof(*script)); - memset(script, 0, sizeof(*script)); + script = alloc_clear_or_die(cheat_script); /* read the core attributes */ script->state = SCRIPT_STATE_RUN; @@ -1476,8 +1471,7 @@ static script_entry *script_entry_load(running_machine *machine, const char *fil EXPRERR experr; /* allocate memory for it */ - entry = (script_entry *)malloc_or_die(sizeof(*entry)); - memset(entry, 0, sizeof(*entry)); + entry = alloc_clear_or_die(script_entry); /* read the condition if present */ expression = xml_get_attribute_string(entrynode, "condition", NULL); @@ -1546,8 +1540,7 @@ static script_entry *script_entry_load(running_machine *machine, const char *fil output_argument *curarg; /* allocate memory for it */ - curarg = (output_argument *)malloc_or_die(sizeof(*curarg)); - memset(curarg, 0, sizeof(*curarg)); + curarg = alloc_clear_or_die(output_argument); /* first extract attributes */ curarg->count = xml_get_attribute_int(argnode, "count", 1); diff --git a/src/emu/clifront.c b/src/emu/clifront.c index 6ea65dca75d..02f6efcef29 100644 --- a/src/emu/clifront.c +++ b/src/emu/clifront.c @@ -440,7 +440,7 @@ int cli_info_listclones(core_options *options, const char *gamename) int cli_info_listbrothers(core_options *options, const char *gamename) { - UINT8 *didit = (UINT8 *)malloc_or_die(driver_list_get_count(drivers)); + UINT8 *didit = alloc_array_or_die(UINT8, driver_list_get_count(drivers)); astring *filename = astring_alloc(); int drvindex, count = 0; diff --git a/src/emu/config.c b/src/emu/config.c index 3d0edbf74f7..f7842cb6a59 100644 --- a/src/emu/config.c +++ b/src/emu/config.c @@ -92,7 +92,7 @@ void config_register(running_machine *machine, const char *nodename, config_call config_type **ptype; /* allocate a new type */ - newtype = (config_type *)auto_malloc(sizeof(*newtype)); + newtype = auto_alloc(machine, config_type); newtype->next = NULL; newtype->name = nodename; newtype->load = load; diff --git a/src/emu/cpu/asap/asap.c b/src/emu/cpu/asap/asap.c index ba373a15b73..c26f956a678 100644 --- a/src/emu/cpu/asap/asap.c +++ b/src/emu/cpu/asap/asap.c @@ -217,7 +217,9 @@ static void jsr_c(asap_state *); static void jsr_c0(asap_state *); static void trapf(asap_state *); -static void (*const opcodetable[32][4])(asap_state *) = +typedef void (*asap_ophandler)(asap_state *); + +static const asap_ophandler opcodetable[32][4] = { { trap0, trap0, trap0, trap0 }, { NULL, NULL, NULL, NULL }, @@ -407,11 +409,11 @@ static void set_irq_line(asap_state *asap, int irqline, int state) INITIALIZATION AND SHUTDOWN ***************************************************************************/ -static void init_tables(void) +static void init_tables(running_machine *machine) { /* allocate opcode table */ if (!opcode) - opcode = (void (**)(asap_state *))auto_malloc(32 * 32 * 2 * sizeof(void *)); + opcode = auto_alloc_array(machine, asap_ophandler, 32 * 32 * 2); /* fill opcode table */ if (opcode) @@ -439,7 +441,7 @@ static CPU_INIT( asap ) asap_state *asap = get_safe_token(device); int i; - init_tables(); + init_tables(device->machine); for (i = 0; i < REGBASE; i++) asap->src2val[i] = i; asap->irq_callback = irqcallback; diff --git a/src/emu/cpu/cubeqcpu/cubeqcpu.c b/src/emu/cpu/cubeqcpu/cubeqcpu.c index 543a407199c..56e18979b61 100644 --- a/src/emu/cpu/cubeqcpu/cubeqcpu.c +++ b/src/emu/cpu/cubeqcpu/cubeqcpu.c @@ -326,7 +326,7 @@ static CPU_INIT( cquestsnd ) cpustate->program = memory_find_address_space(device, ADDRESS_SPACE_PROGRAM); /* Allocate RAM shared with 68000 */ - cpustate->sram = (UINT16 *)auto_malloc(4096); + cpustate->sram = auto_alloc_array(device->machine, UINT16, 4096/2); cquestsnd_state_register(device); } @@ -392,8 +392,8 @@ static CPU_INIT( cquestrot ) memset(cpustate, 0, sizeof(*cpustate)); /* Allocate RAM */ - cpustate->dram = (UINT16 *)auto_malloc(16384 * sizeof(UINT16)); /* Shared with 68000 */ - cpustate->sram = (UINT16 *)auto_malloc(2048 * sizeof(UINT16)); /* Private */ + cpustate->dram = auto_alloc_array(device->machine, UINT16, 16384); /* Shared with 68000 */ + cpustate->sram = auto_alloc_array(device->machine, UINT16, 2048); /* Private */ cpustate->device = device; cpustate->lindevice = cputag_get_cpu(device->machine, rotconfig->lin_cpu_tag); @@ -475,10 +475,10 @@ static CPU_INIT( cquestlin ) memset(cpustate, 0, sizeof(*cpustate)); /* Allocate RAM */ - cpustate->sram = (UINT16 *)auto_malloc(4096 * sizeof(UINT16)); /* Shared with rotate CPU */ - cpustate->ptr_ram = (UINT8 *)auto_malloc(1024); /* Pointer RAM */ - cpustate->e_stack = (UINT32 *)auto_malloc(32768 * sizeof(UINT32)); /* Stack DRAM: 32kx20 */ - cpustate->o_stack = (UINT32 *)auto_malloc(32768 * sizeof(UINT32)); /* Stack DRAM: 32kx20 */ + cpustate->sram = auto_alloc_array(device->machine, UINT16, 4096); /* Shared with rotate CPU */ + cpustate->ptr_ram = auto_alloc_array(device->machine, UINT8, 1024); /* Pointer RAM */ + cpustate->e_stack = auto_alloc_array(device->machine, UINT32, 32768); /* Stack DRAM: 32kx20 */ + cpustate->o_stack = auto_alloc_array(device->machine, UINT32, 32768); /* Stack DRAM: 32kx20 */ cpustate->device = device; cpustate->rotdevice = cputag_get_cpu(device->machine, linconfig->rot_cpu_tag); diff --git a/src/emu/cpu/drcfe.c b/src/emu/cpu/drcfe.c index 7cb86b9fa58..695ae20d59a 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 = (opcode_desc *)malloc_or_die(sizeof(*desc)); + desc = alloc_or_die(opcode_desc); return desc; } @@ -128,12 +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 = (drcfe_state *)malloc_or_die(sizeof(*drcfe)); - memset(drcfe, 0, sizeof(*drcfe)); + drcfe = alloc_clear_or_die(drcfe_state); /* allocate the description array */ - drcfe->desc_array = (opcode_desc **)malloc_or_die((config->window_end + config->window_start + 2) * sizeof(*drcfe->desc_array)); - memset(drcfe->desc_array, 0, (config->window_end + config->window_start + 2) * sizeof(*drcfe->desc_array)); + drcfe->desc_array = alloc_array_clear_or_die(opcode_desc *, config->window_end + config->window_start + 2); /* copy in configuration information */ drcfe->window_start = config->window_start; diff --git a/src/emu/cpu/esrip/esrip.c b/src/emu/cpu/esrip/esrip.c index d25e4a40e56..c28286ed929 100644 --- a/src/emu/cpu/esrip/esrip.c +++ b/src/emu/cpu/esrip/esrip.c @@ -260,13 +260,13 @@ static CPU_INIT( esrip ) cpustate->draw = _config->draw; /* Allocate image pointer table RAM */ - cpustate->ipt_ram = (UINT16 *)auto_malloc(IPT_RAM_SIZE); + cpustate->ipt_ram = auto_alloc_array(device->machine, UINT16, IPT_RAM_SIZE/2); cpustate->device = device; cpustate->program = memory_find_address_space(device, ADDRESS_SPACE_PROGRAM); /* Create the instruction decode lookup table */ - cpustate->optable = (UINT8 *)auto_malloc(65536); + cpustate->optable = auto_alloc_array(device->machine, UINT8, 65536); make_ops(cpustate); /* Register stuff for state saving */ diff --git a/src/emu/cpu/i386/i386.c b/src/emu/cpu/i386/i386.c index 21a71773cd6..874fd94342d 100644 --- a/src/emu/cpu/i386/i386.c +++ b/src/emu/cpu/i386/i386.c @@ -391,13 +391,13 @@ INLINE void CYCLES_RM(i386_state *cpustate,int modrm, int r, int m) } } -static void build_cycle_table(void) +static void build_cycle_table(running_machine *machine) { int i, j; for (j=0; j < X86_NUM_CPUS; j++) { - cycle_table_rm[j] = (UINT8 *)auto_malloc(sizeof(UINT8) * CYCLES_NUM_OPCODES); - cycle_table_pm[j] = (UINT8 *)auto_malloc(sizeof(UINT8) * CYCLES_NUM_OPCODES); + cycle_table_rm[j] = auto_alloc_array(machine, UINT8, CYCLES_NUM_OPCODES); + cycle_table_pm[j] = auto_alloc_array(machine, UINT8, CYCLES_NUM_OPCODES); for (i=0; i < sizeof(x86_cycle_table)/sizeof(X86_CYCLE_TABLE); i++) { @@ -507,7 +507,7 @@ static CPU_INIT( i386 ) static const int regs32[8] = {EAX,ECX,EDX,EBX,ESP,EBP,ESI,EDI}; i386_state *cpustate = get_safe_token(device); - build_cycle_table(); + build_cycle_table(device->machine); for( i=0; i < 256; i++ ) { int c=0; diff --git a/src/emu/cpu/jaguar/jaguar.c b/src/emu/cpu/jaguar/jaguar.c index d597b3cbfb5..aea65b19f00 100644 --- a/src/emu/cpu/jaguar/jaguar.c +++ b/src/emu/cpu/jaguar/jaguar.c @@ -367,7 +367,7 @@ static void init_tables(void) } /* fill in the mirror table */ - mirror_table = (UINT16 *)malloc_or_die(65536 * sizeof(mirror_table[0])); + mirror_table = alloc_array_or_die(UINT16, 65536); for (i = 0; i < 65536; i++) mirror_table[i] = ((i >> 15) & 0x0001) | ((i >> 13) & 0x0002) | ((i >> 11) & 0x0004) | ((i >> 9) & 0x0008) | @@ -379,7 +379,7 @@ static void init_tables(void) ((i << 13) & 0x4000) | ((i << 15) & 0x8000); /* fill in the condition table */ - condition_table = (UINT8 *)malloc_or_die(32 * 8 * sizeof(condition_table[0])); + condition_table = alloc_array_or_die(UINT8, 32 * 8); for (i = 0; i < 8; i++) for (j = 0; j < 32; j++) { diff --git a/src/emu/cpu/mb86233/mb86233.c b/src/emu/cpu/mb86233/mb86233.c index 9c477fadb48..c03e7aa8344 100644 --- a/src/emu/cpu/mb86233/mb86233.c +++ b/src/emu/cpu/mb86233/mb86233.c @@ -118,7 +118,7 @@ static CPU_INIT( mb86233 ) cpustate->fifo_write_cb = _config->fifo_write_cb; } - cpustate->RAM = (UINT32 *)auto_malloc(2 * 0x200 * sizeof(UINT32)); /* 2x 2KB */ + cpustate->RAM = auto_alloc_array(device->machine, UINT32, 2 * 0x200); /* 2x 2KB */ memset( cpustate->RAM, 0, 2 * 0x200 * sizeof(UINT32) ); cpustate->ARAM = &cpustate->RAM[0]; cpustate->BRAM = &cpustate->RAM[0x200]; diff --git a/src/emu/cpu/mc68hc11/mc68hc11.c b/src/emu/cpu/mc68hc11/mc68hc11.c index 19c9953709c..c5ced5d9020 100644 --- a/src/emu/cpu/mc68hc11/mc68hc11.c +++ b/src/emu/cpu/mc68hc11/mc68hc11.c @@ -356,7 +356,7 @@ static CPU_INIT( hc11 ) } cpustate->internal_ram_size = 1280; /* FIXME: this is for MC68HC11M0 */ - cpustate->internal_ram = (UINT8 *)auto_malloc(cpustate->internal_ram_size); + cpustate->internal_ram = auto_alloc_array(device->machine, UINT8, cpustate->internal_ram_size); cpustate->reg_position = 0; cpustate->ram_position = 0x100; diff --git a/src/emu/cpu/mips/mips3.c b/src/emu/cpu/mips/mips3.c index 68599760a49..be58d00e8b7 100644 --- a/src/emu/cpu/mips/mips3.c +++ b/src/emu/cpu/mips/mips3.c @@ -2137,14 +2137,14 @@ static CPU_GET_INFO( mips3 ) static CPU_INIT( r4600be ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_R4600, TRUE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_R4600, TRUE, index, clock, irqcallback, memory); } static CPU_INIT( r4600le ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_R4600, FALSE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_R4600, FALSE, index, clock, irqcallback, memory); } @@ -2193,14 +2193,14 @@ CPU_GET_INFO( r4600le ) static CPU_INIT( r4650be ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_R4650, TRUE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_R4650, TRUE, index, clock, irqcallback, memory); } static CPU_INIT( r4650le ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_R4650, FALSE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_R4650, FALSE, index, clock, irqcallback, memory); } @@ -2249,14 +2249,14 @@ CPU_GET_INFO( r4650le ) static CPU_INIT( r4700be ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_R4700, TRUE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_R4700, TRUE, index, clock, irqcallback, memory); } static CPU_INIT( r4700le ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_R4700, FALSE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_R4700, FALSE, index, clock, irqcallback, memory); } @@ -2306,14 +2306,14 @@ CPU_GET_INFO( r4700le ) static CPU_INIT( r5000be ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_R5000, TRUE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_R5000, TRUE, index, clock, irqcallback, memory); } static CPU_INIT( r5000le ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_R5000, FALSE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_R5000, FALSE, index, clock, irqcallback, memory); } @@ -2362,14 +2362,14 @@ CPU_GET_INFO( r5000le ) static CPU_INIT( qed5271be ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_QED5271, TRUE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_QED5271, TRUE, index, clock, irqcallback, memory); } static CPU_INIT( qed5271le ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_QED5271, FALSE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_QED5271, FALSE, index, clock, irqcallback, memory); } @@ -2418,14 +2418,14 @@ CPU_GET_INFO( qed5271le ) static CPU_INIT( rm7000be ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_RM7000, TRUE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_RM7000, TRUE, index, clock, irqcallback, memory); } static CPU_INIT( rm7000le ) { size_t memsize = mips3com_init(&mips3.core, MIPS3_TYPE_RM7000, FALSE, device, index, clock, irqcallback, NULL); - void *memory = auto_malloc(memsize); + void *memory = auto_alloc_array(device->machine, UINT8, memsize); mips3com_init(&mips3.core, MIPS3_TYPE_RM7000, FALSE, index, clock, irqcallback, memory); } diff --git a/src/emu/cpu/mips/psx.c b/src/emu/cpu/mips/psx.c index 0f204a6f09f..a86bfbcf135 100644 --- a/src/emu/cpu/mips/psx.c +++ b/src/emu/cpu/mips/psx.c @@ -1316,7 +1316,7 @@ static void mips_update_scratchpad( const address_space *space ) } else { - memory_install_readwrite32_handler( space, 0x1f800000, 0x1f8003ff, 0, 0, (read32_space_func)SMH_BANK32, (write32_space_func)SMH_BANK32 ); + memory_install_readwrite32_handler( space, 0x1f800000, 0x1f8003ff, 0, 0, (read32_space_func)SMH_BANK(32), (write32_space_func)SMH_BANK(32) ); memory_set_bankptr(space->machine, 32, psxcpu->dcache ); } diff --git a/src/emu/cpu/mips/r3000.c b/src/emu/cpu/mips/r3000.c index d5120d66d70..9dd2d3722a9 100644 --- a/src/emu/cpu/mips/r3000.c +++ b/src/emu/cpu/mips/r3000.c @@ -301,8 +301,8 @@ static CPU_INIT( r3000 ) r3000_state *r3000 = get_safe_token(device); /* allocate memory */ - r3000->icache = (UINT32 *)auto_malloc(configdata->icache); - r3000->dcache = (UINT32 *)auto_malloc(configdata->dcache); + r3000->icache = auto_alloc_array(device->machine, UINT32, configdata->icache/4); + r3000->dcache = auto_alloc_array(device->machine, UINT32, configdata->dcache/4); r3000->icache_size = configdata->icache; r3000->dcache_size = configdata->dcache; diff --git a/src/emu/cpu/se3208/se3208.c b/src/emu/cpu/se3208/se3208.c index c908fa382f9..b5e31bace87 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=(_OP *)malloc_or_die(sizeof(_OP)*0x10000); + OpTable=alloc_array_or_die(_OP, 0x10000); for(i=0;i<0x10000;++i) OpTable[i]=DecodeOp(i); } diff --git a/src/emu/cpu/sh2/sh2.c b/src/emu/cpu/sh2/sh2.c index ae3736e4b9e..9f8d8aac311 100644 --- a/src/emu/cpu/sh2/sh2.c +++ b/src/emu/cpu/sh2/sh2.c @@ -2247,8 +2247,7 @@ static CPU_DISASSEMBLE( sh2 ) static CPU_INIT( sh2 ) { /* allocate the core memory */ - sh2 = auto_malloc(sizeof(SH2)); - memset(sh2, 0, sizeof(SH2)); + sh2 = auto_alloc_clear(device->machine, SH2); /* initialize the common core parts */ sh2_common_init(sh2, device, irqcallback); diff --git a/src/emu/cpu/sh2/sh2comn.c b/src/emu/cpu/sh2/sh2comn.c index a046cc7c7a6..691e62dbe4d 100644 --- a/src/emu/cpu/sh2/sh2comn.c +++ b/src/emu/cpu/sh2/sh2comn.c @@ -712,7 +712,7 @@ void sh2_common_init(SH2 *sh2, const device_config *device, cpu_irq_callback irq sh2->dma_timer[1] = timer_alloc(device->machine, sh2_dmac_callback, sh2); timer_adjust_oneshot(sh2->dma_timer[1], attotime_never, 0); - sh2->m = (UINT32 *)auto_malloc(0x200); + sh2->m = auto_alloc_array(device->machine, UINT32, 0x200/4); if(conf) { diff --git a/src/emu/cpu/sh4/sh4comn.c b/src/emu/cpu/sh4/sh4comn.c index 0f06c7fe8f0..0218bf5e121 100644 --- a/src/emu/cpu/sh4/sh4comn.c +++ b/src/emu/cpu/sh4/sh4comn.c @@ -1182,7 +1182,7 @@ void sh4_common_init(const device_config *device) sh4->rtc_timer = timer_alloc(device->machine, sh4_rtc_timer_callback, sh4); timer_adjust_oneshot(sh4->rtc_timer, attotime_never, 0); - sh4->m = (UINT32 *)auto_malloc(16384*4); + sh4->m = auto_alloc_array(device->machine, UINT32, 16384); } void sh4_dma_ddt(const device_config *device, struct sh4_ddt_dma *s) diff --git a/src/emu/cpu/sharc/sharc.c b/src/emu/cpu/sharc/sharc.c index c441c656b19..8ffbebd970a 100644 --- a/src/emu/cpu/sharc/sharc.c +++ b/src/emu/cpu/sharc/sharc.c @@ -445,7 +445,7 @@ static CPU_INIT( sharc ) build_opcode_table(); - cpustate->internal_ram = (UINT16 *)auto_malloc(2 * 0x10000 * sizeof(UINT16)); // 2x 128KB + cpustate->internal_ram = auto_alloc_array(device->machine, UINT16, 2 * 0x10000); // 2x 128KB cpustate->internal_ram_block0 = &cpustate->internal_ram[0]; cpustate->internal_ram_block1 = &cpustate->internal_ram[0x20000/2]; diff --git a/src/emu/cpu/tms32025/tms32025.c b/src/emu/cpu/tms32025/tms32025.c index e12e6722ef0..2660eff27c7 100644 --- a/src/emu/cpu/tms32025/tms32025.c +++ b/src/emu/cpu/tms32025/tms32025.c @@ -1719,7 +1719,7 @@ static CPU_INIT( tms32025 ) { tms32025_state *cpustate = get_safe_token(device); - cpustate->intRAM = (UINT16 *)auto_malloc(0x800*2); + cpustate->intRAM = auto_alloc_array(device->machine, UINT16, 0x800); cpustate->irq_callback = irqcallback; cpustate->device = device; cpustate->program = memory_find_address_space(device, ADDRESS_SPACE_PROGRAM); diff --git a/src/emu/cpu/tms34010/tms34010.c b/src/emu/cpu/tms34010/tms34010.c index 59b865436b1..4598a8874dc 100644 --- a/src/emu/cpu/tms34010/tms34010.c +++ b/src/emu/cpu/tms34010/tms34010.c @@ -704,7 +704,7 @@ static CPU_INIT( tms34010 ) timer_adjust_oneshot(tms->scantimer, attotime_zero, 0); /* allocate the shiftreg */ - tms->shiftreg = (UINT16 *)auto_malloc(SHIFTREG_SIZE); + tms->shiftreg = auto_alloc_array(device->machine, UINT16, SHIFTREG_SIZE/2); state_save_register_device_item(device, 0, tms->pc); state_save_register_device_item(device, 0, tms->st); diff --git a/src/emu/cpu/vtlb.c b/src/emu/cpu/vtlb.c index de4a755e17a..c921831e977 100644 --- a/src/emu/cpu/vtlb.c +++ b/src/emu/cpu/vtlb.c @@ -60,8 +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 = (vtlb_state *)malloc_or_die(sizeof(*vtlb)); - memset(vtlb, 0, sizeof(*vtlb)); + vtlb = alloc_clear_or_die(vtlb_state); /* fill in CPU information */ vtlb->device = cpu; @@ -78,20 +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 = (offs_t *)malloc_or_die(sizeof(vtlb->live[0]) * (fixed_entries + dynamic_entries)); - memset(vtlb->live, 0, sizeof(vtlb->live[0]) * (fixed_entries + dynamic_entries)); + vtlb->live = alloc_array_clear_or_die(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 = (vtlb_entry *)malloc_or_die(sizeof(vtlb->table[0]) << (vtlb->addrwidth - vtlb->pageshift)); - memset(vtlb->table, 0, sizeof(vtlb->table[0]) << (vtlb->addrwidth - vtlb->pageshift)); + vtlb->table = alloc_array_clear_or_die(vtlb_entry, 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 = (int *)malloc_or_die(sizeof(vtlb->fixedpages[0]) * fixed_entries); - memset(vtlb->fixedpages, 0, sizeof(vtlb->fixedpages[0]) * fixed_entries); + vtlb->fixedpages = alloc_array_clear_or_die(int, fixed_entries); state_save_register_device_item_pointer(cpu, space, vtlb->fixedpages, fixed_entries); } return vtlb; diff --git a/src/emu/cpu/x86log.c b/src/emu/cpu/x86log.c index 94f02970587..d961387a1ba 100644 --- a/src/emu/cpu/x86log.c +++ b/src/emu/cpu/x86log.c @@ -91,8 +91,7 @@ x86log_context *x86log_create_context(const char *filename) x86log_context *log; /* allocate the log */ - log = (x86log_context *)malloc_or_die(sizeof(*log)); - memset(log, 0, sizeof(*log)); + log = alloc_clear_or_die(x86log_context); /* allocate the filename */ log->filename = astring_dupc(filename); diff --git a/src/emu/cpu/z180/z180.c b/src/emu/cpu/z180/z180.c index 9d8d0b02bc2..5ddc56e1f04 100644 --- a/src/emu/cpu/z180/z180.c +++ b/src/emu/cpu/z180/z180.c @@ -2067,8 +2067,8 @@ static CPU_RESET( z180 ) int oldval, newval, val; UINT8 *padd, *padc, *psub, *psbc; /* allocate big flag arrays once */ - SZHVC_add = (UINT8 *)auto_malloc(2*256*256); - SZHVC_sub = (UINT8 *)auto_malloc(2*256*256); + SZHVC_add = auto_alloc_array(device->machine, UINT8, 2*256*256); + SZHVC_sub = auto_alloc_array(device->machine, UINT8, 2*256*256); padd = &SZHVC_add[ 0*256]; padc = &SZHVC_add[256*256]; psub = &SZHVC_sub[ 0*256]; diff --git a/src/emu/cpu/z80/z80daisy.c b/src/emu/cpu/z80/z80daisy.c index eb15e3c2621..bcfd2640d54 100644 --- a/src/emu/cpu/z80/z80daisy.c +++ b/src/emu/cpu/z80/z80daisy.c @@ -29,7 +29,7 @@ z80_daisy_state *z80daisy_init(const device_config *cpudevice, const z80_daisy_c /* create a linked list of devices */ for ( ; daisy->devname != NULL; daisy++) { - *tailptr = (z80_daisy_state *)auto_malloc(sizeof(**tailptr)); + *tailptr = auto_alloc(cpudevice->machine, z80_daisy_state); (*tailptr)->next = NULL; (*tailptr)->device = devtag_get_device(cpudevice->machine, device_inherit_tag(tempstring, cpudevice->tag, daisy->devname)); if ((*tailptr)->device == NULL) diff --git a/src/emu/cpuexec.c b/src/emu/cpuexec.c index 255cddab94a..721fe97d9ec 100644 --- a/src/emu/cpuexec.c +++ b/src/emu/cpuexec.c @@ -223,8 +223,7 @@ void cpuexec_init(running_machine *machine) attotime min_quantum; /* allocate global state */ - machine->cpuexec_data = (cpuexec_private *)auto_malloc(sizeof(*machine->cpuexec_data)); - memset(machine->cpuexec_data, 0, sizeof(*machine->cpuexec_data)); + machine->cpuexec_data = auto_alloc_clear(machine, cpuexec_private); /* set the core scheduling quantum */ min_quantum = machine->config->minimum_quantum; diff --git a/src/emu/debug/debugcmt.c b/src/emu/debug/debugcmt.c index 6200c76d2d3..4db231cce50 100644 --- a/src/emu/debug/debugcmt.c +++ b/src/emu/debug/debugcmt.c @@ -110,8 +110,7 @@ int debug_comment_init(running_machine *machine) if (numcpu > 0) { /* allocate enough comment groups for the total # of cpu's */ - debug_comments = (comment_group*) auto_malloc(numcpu * sizeof(comment_group)); - memset(debug_comments, 0, numcpu * sizeof(comment_group)); + debug_comments = auto_alloc_array_clear(machine, comment_group, numcpu); /* automatically load em up */ debug_comment_load(machine); @@ -137,7 +136,7 @@ int debug_comment_add(const device_config *device, offs_t addr, const char *comm int match = 0; /* Create a new item to insert into the list */ - debug_comment *insert_me = (debug_comment*) malloc_or_die(sizeof(debug_comment)); + debug_comment *insert_me = alloc_or_die(debug_comment); insert_me->color = color; insert_me->is_valid = 1; insert_me->address = addr; diff --git a/src/emu/debug/debugcon.c b/src/emu/debug/debugcon.c index cc2fd0b7117..c56efb8f5ef 100644 --- a/src/emu/debug/debugcon.c +++ b/src/emu/debug/debugcon.c @@ -404,8 +404,7 @@ void debug_console_register_command(running_machine *machine, const char *comman assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call debug_console_register_command() at init time!"); assert_always((machine->debug_flags & DEBUG_FLAG_ENABLED) != 0, "Cannot call debug_console_register_command() when debugger is not running"); - cmd = (debug_command *)auto_malloc(sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = auto_alloc_clear(machine, debug_command); /* fill in the command */ strcpy(cmd->command, command); diff --git a/src/emu/debug/debugcpu.c b/src/emu/debug/debugcpu.c index 0c7987df683..911b9bbe72b 100644 --- a/src/emu/debug/debugcpu.c +++ b/src/emu/debug/debugcpu.c @@ -158,8 +158,7 @@ void debug_cpu_init(running_machine *machine) int regnum; /* allocate and reset globals */ - machine->debugcpu_data = global = (debugcpu_private *)auto_malloc(sizeof(*global)); - memset(global, 0, sizeof(*global)); + machine->debugcpu_data = global = auto_alloc_clear(machine, debugcpu_private); global->execution_state = EXECUTION_STATE_STOPPED; global->bpindex = 1; global->wpindex = 1; @@ -190,8 +189,7 @@ void debug_cpu_init(running_machine *machine) cpu_debug_data *info; /* allocate some information */ - info = (cpu_debug_data *)auto_malloc(sizeof(*info)); - memset(info, 0, sizeof(*info)); + info = auto_alloc_clear(machine, cpu_debug_data); classheader->debug = info; /* reset the PC data */ @@ -983,7 +981,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 = (debug_cpu_breakpoint *)malloc_or_die(sizeof(*bp)); + bp = alloc_or_die(debug_cpu_breakpoint); bp->index = global->bpindex++; bp->enabled = TRUE; bp->address = address; @@ -991,7 +989,7 @@ int debug_cpu_breakpoint_set(const device_config *device, offs_t address, parsed bp->action = NULL; if (action != NULL) { - bp->action = (char *)malloc_or_die(strlen(action) + 1); + bp->action = alloc_array_or_die(char, strlen(action) + 1); strcpy(bp->action, action); } @@ -1087,7 +1085,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 = (debug_cpu_watchpoint *)malloc_or_die(sizeof(*wp)); + debug_cpu_watchpoint *wp = alloc_or_die(debug_cpu_watchpoint); /* fill in the structure */ wp->index = global->wpindex++; @@ -1099,7 +1097,7 @@ int debug_cpu_watchpoint_set(const address_space *space, int type, offs_t addres wp->action = NULL; if (action != NULL) { - wp->action = (char *)malloc_or_die(strlen(action) + 1); + wp->action = alloc_array_or_die(char, strlen(action) + 1); strcpy(wp->action, action); } @@ -1245,7 +1243,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 = (char *)malloc_or_die(strlen(action) + 1); + info->trace.action = alloc_array_or_die(char, strlen(action) + 1); strcpy(info->trace.action, action); } @@ -1313,7 +1311,7 @@ int debug_cpu_hotspot_track(const device_config *device, int numspots, int thres if (numspots > 0) { /* allocate memory for hotspots */ - info->hotspots = (debug_hotspot_entry *)malloc_or_die(sizeof(*info->hotspots) * numspots); + info->hotspots = alloc_array_or_die(debug_hotspot_entry, numspots); memset(info->hotspots, 0xff, sizeof(*info->hotspots) * numspots); /* fill in the info */ diff --git a/src/emu/debug/debugvw.c b/src/emu/debug/debugvw.c index 9ee2cd06faa..765990a985d 100644 --- a/src/emu/debug/debugvw.c +++ b/src/emu/debug/debugvw.c @@ -342,8 +342,7 @@ void debug_view_init(running_machine *machine) debugvw_private *global; /* allocate memory for our globals */ - global = machine->debugvw_data = (debugvw_private *)auto_malloc(sizeof(*machine->debugvw_data)); - memset(global, 0, sizeof(*global)); + global = machine->debugvw_data = auto_alloc_clear(machine, debugvw_private); /* register for some manual cleanup */ add_exit_callback(machine, debug_view_exit); @@ -1053,8 +1052,7 @@ static const registers_subview_item *registers_view_enumerate_subviews(running_m /* determine the string and allocate a subview large enough */ astring_printf(tempstring, "CPU '%s' (%s)", cpu->tag, cpu_get_name(cpu)); - subview = (registers_subview_item *)auto_malloc(sizeof(*subview) + astring_len(tempstring)); - memset(subview, 0, sizeof(*subview)); + subview = (registers_subview_item *)auto_alloc_array_clear(machine, UINT8, sizeof(*subview) + astring_len(tempstring)); /* populate the subview */ subview->next = NULL; @@ -1523,8 +1521,7 @@ static const disasm_subview_item *disasm_view_enumerate_subviews(running_machine /* determine the string and allocate a subview large enough */ astring_printf(tempstring, "CPU '%s' (%s)", cpu->tag, cpu_get_name(cpu)); - subview = (disasm_subview_item *)auto_malloc(sizeof(*subview) + astring_len(tempstring)); - memset(subview, 0, sizeof(*subview)); + subview = (disasm_subview_item *)auto_alloc_array_clear(machine, UINT8, sizeof(*subview) + astring_len(tempstring)); /* populate the subview */ subview->next = NULL; @@ -1881,12 +1878,12 @@ static int disasm_view_recompute(debug_view *view, offs_t pc, int startline, int /* allocate address array */ if (dasmdata->byteaddress != NULL) free(dasmdata->byteaddress); - dasmdata->byteaddress = (offs_t *)malloc_or_die(sizeof(dasmdata->byteaddress[0]) * dasmdata->allocated.y); + dasmdata->byteaddress = alloc_array_or_die(offs_t, dasmdata->allocated.y); /* allocate disassembly buffer */ if (dasmdata->dasm != NULL) free(dasmdata->dasm); - dasmdata->dasm = (char *)malloc_or_die(sizeof(dasmdata->dasm[0]) * dasmdata->allocated.x * dasmdata->allocated.y); + dasmdata->dasm = alloc_array_or_die(char, dasmdata->allocated.x * dasmdata->allocated.y); } /* iterate over lines */ @@ -2446,8 +2443,7 @@ static const memory_subview_item *memory_view_enumerate_subviews(running_machine /* determine the string and allocate a subview large enough */ astring_printf(tempstring, "CPU '%s' (%s) %s memory", cpu->tag, cpu_get_name(cpu), space->name); - subview = (memory_subview_item *)auto_malloc(sizeof(*subview) + astring_len(tempstring)); - memset(subview, 0, sizeof(*subview)); + subview = (memory_subview_item *)auto_alloc_array_clear(machine, UINT8, sizeof(*subview) + astring_len(tempstring)); /* populate the subview */ subview->next = NULL; @@ -2476,8 +2472,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 *)auto_malloc(sizeof(*subview) + astring_len(tempstring)); - memset(subview, 0, sizeof(*subview)); + subview = (memory_subview_item *)auto_alloc_array_clear(machine, UINT8, sizeof(*subview) + astring_len(tempstring)); /* populate the subview */ subview->next = NULL; @@ -2514,8 +2509,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 *)auto_malloc(sizeof(*subview) + astring_len(tempstring)); - memset(subview, 0, sizeof(*subview)); + subview = (memory_subview_item *)auto_alloc_array_clear(machine, UINT8, sizeof(*subview) + astring_len(tempstring)); /* populate the subview */ subview->next = NULL; diff --git a/src/emu/debugger.c b/src/emu/debugger.c index a6541e5237a..3e8625bd03e 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 = (machine_entry *)malloc_or_die(sizeof(*entry)); + entry = alloc_or_die(machine_entry); entry->next = machine_list; entry->machine = machine; machine_list = entry; diff --git a/src/emu/devintrf.c b/src/emu/devintrf.c index f9daef51023..e362660628f 100644 --- a/src/emu/devintrf.c +++ b/src/emu/devintrf.c @@ -111,7 +111,7 @@ device_config *device_list_add(device_config **listheadptr, const device_config configlen = (UINT32)devtype_get_info_int(type, DEVINFO_INT_INLINE_CONFIG_BYTES); /* allocate a new device */ - device = (device_config *)malloc_or_die(sizeof(*device) + strlen(tag) + configlen); + device = (device_config *)alloc_array_or_die(UINT8, sizeof(*device) + strlen(tag) + configlen); /* populate device relationships */ device->next = NULL; @@ -554,8 +554,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 = malloc_or_die(device->tokenbytes); - memset(device->token, 0, device->tokenbytes); + device->token = alloc_array_clear_or_die(UINT8, device->tokenbytes); /* fill in the remaining runtime fields */ device->execute = (device_execute_func)device_get_info_fct(device, DEVINFO_FCT_EXECUTE); diff --git a/src/emu/drawgfx.c b/src/emu/drawgfx.c index 732f5fa9523..70332549135 100644 --- a/src/emu/drawgfx.c +++ b/src/emu/drawgfx.c @@ -90,8 +90,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 = (gfx_element *)malloc_or_die(sizeof(*gfx)); - memset(gfx, 0, sizeof(*gfx)); + gfx = alloc_clear_or_die(gfx_element); /* fill in the data */ gfx->width = width; @@ -120,7 +119,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c } else { - UINT32 *buffer = (UINT32 *)malloc_or_die(sizeof(buffer[0]) * gfx->layout.width); + UINT32 *buffer = alloc_array_or_die(UINT32, gfx->layout.width); memcpy(buffer, gfx->layout.extxoffs, sizeof(gfx->layout.extxoffs[0]) * gfx->layout.width); gfx->layout.extxoffs = buffer; } @@ -135,7 +134,7 @@ gfx_element *gfx_element_alloc(running_machine *machine, const gfx_layout *gl, c } else { - UINT32 *buffer = (UINT32 *)malloc_or_die(sizeof(buffer[0]) * gfx->layout.height); + UINT32 *buffer = alloc_array_or_die(UINT32, gfx->layout.height); memcpy(buffer, gfx->layout.extyoffs, sizeof(gfx->layout.extyoffs[0]) * gfx->layout.height); gfx->layout.extyoffs = buffer; } @@ -143,10 +142,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 = (UINT32 *)malloc_or_die(gfx->total_elements * sizeof(*gfx->pen_usage)); + gfx->pen_usage = alloc_array_or_die(UINT32, gfx->total_elements); /* allocate a dirty array */ - gfx->dirty = (UINT8 *)malloc_or_die(gfx->total_elements * sizeof(*gfx->dirty)); + gfx->dirty = alloc_array_or_die(UINT8, gfx->total_elements); memset(gfx->dirty, 1, gfx->total_elements * sizeof(*gfx->dirty)); /* raw graphics case */ @@ -173,7 +172,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 = (UINT8 *)malloc_or_die(gfx->total_elements * gfx->char_modulo); + gfx->gfxdata = alloc_array_or_die(UINT8, gfx->total_elements * gfx->char_modulo); } return gfx; diff --git a/src/emu/driver.c b/src/emu/driver.c index d28094e66ee..bcd2e7610dd 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 = (const game_driver **)malloc_or_die(driver_list_get_count(driverlist) * sizeof(*templist)); + templist = alloc_array_or_die(const game_driver *, driver_list_get_count(driverlist)); /* build up a list of valid entries */ for (drvnum = driver_count = 0; driverlist[drvnum] != NULL; drvnum++) @@ -145,7 +145,7 @@ void driver_list_get_approx_matches(const game_driver * const driverlist[], cons } /* allocate some temp memory */ - penalty = (int *)malloc_or_die(matches * sizeof(*penalty)); + penalty = alloc_array_or_die(int, matches); /* initialize everyone's states */ for (matchnum = 0; matchnum < matches; matchnum++) diff --git a/src/emu/emupal.c b/src/emu/emupal.c index 02268a67738..5cb9f9762f7 100644 --- a/src/emu/emupal.c +++ b/src/emu/emupal.c @@ -95,7 +95,7 @@ static void configure_rgb_shadows(running_machine *machine, int mode, float fact void palette_init(running_machine *machine) { - palette_private *palette = (palette_private *)auto_malloc(sizeof(*palette)); + palette_private *palette = auto_alloc_clear(machine, palette_private); const device_config *device = video_screen_first(machine->config); bitmap_format format; @@ -113,7 +113,6 @@ void palette_init(running_machine *machine) add_exit_callback(machine, palette_exit); /* reset all our data */ - memset(palette, 0, sizeof(*palette)); palette->format = format; /* determine the color mode */ @@ -146,8 +145,8 @@ void palette_init(running_machine *machine) /* set up save/restore of the palette */ numcolors = palette_get_num_colors(machine->palette); - palette->save_pen = (pen_t *)auto_malloc(sizeof(*palette->save_pen) * numcolors); - palette->save_bright = (float *)auto_malloc(sizeof(*palette->save_bright) * numcolors); + palette->save_pen = auto_alloc_array(machine, pen_t, numcolors); + palette->save_bright = auto_alloc_array(machine, float, numcolors); state_save_register_global_pointer(machine, palette->save_pen, numcolors); state_save_register_global_pointer(machine, palette->save_bright, numcolors); state_save_register_presave(machine, palette_presave, palette); @@ -330,8 +329,7 @@ colortable_t *colortable_alloc(running_machine *machine, UINT32 palettesize) assert(palettesize > 0); /* allocate the colortable */ - ctable = (colortable_t *)auto_malloc(sizeof(*ctable)); - memset(ctable, 0, sizeof(*ctable)); + ctable = auto_alloc_clear(machine, colortable_t); /* fill in the basics */ ctable->machine = machine; @@ -339,13 +337,13 @@ colortable_t *colortable_alloc(running_machine *machine, UINT32 palettesize) ctable->palentries = palettesize; /* allocate the raw colortable */ - ctable->raw = (UINT16 *)auto_malloc(ctable->entries * sizeof(*ctable->raw)); + ctable->raw = auto_alloc_array(machine, UINT16, ctable->entries); for (index = 0; index < ctable->entries; index++) ctable->raw[index] = index % ctable->palentries; state_save_register_global_pointer(machine, ctable->raw, ctable->entries); /* allocate the palette */ - ctable->palette = (rgb_t *)auto_malloc(ctable->palentries * sizeof(*ctable->palette)); + ctable->palette = auto_alloc_array(machine, rgb_t, ctable->palentries); for (index = 0; index < ctable->palentries; index++) ctable->palette[index] = MAKE_ARGB(0x80,0xff,0xff,0xff); state_save_register_global_pointer(machine, ctable->palette, ctable->palentries); @@ -660,7 +658,7 @@ static void allocate_color_tables(running_machine *machine, palette_private *pal { case BITMAP_FORMAT_INDEXED16: /* create a dummy 1:1 mapping */ - machine->pens = pentable = (pen_t *)auto_malloc((total_colors + 2) * sizeof(machine->pens[0])); + machine->pens = pentable = auto_alloc_array(machine, pen_t, total_colors + 2); for (i = 0; i < total_colors + 2; i++) pentable[i] = i; break; @@ -690,7 +688,7 @@ static void allocate_shadow_tables(running_machine *machine, palette_private *pa /* if we have shadows, allocate shadow tables */ if (machine->config->video_attributes & VIDEO_HAS_SHADOWS) { - pen_t *table = (pen_t *)auto_malloc(65536 * sizeof(*table)); + pen_t *table = auto_alloc_array(machine, pen_t, 65536); int i; /* palettized mode gets a single 64k table in slots 0 and 2 */ @@ -713,7 +711,7 @@ static void allocate_shadow_tables(running_machine *machine, palette_private *pa /* if we have hilights, allocate shadow tables */ if (machine->config->video_attributes & VIDEO_HAS_HIGHLIGHTS) { - pen_t *table = (pen_t *)auto_malloc(65536 * sizeof(*table)); + pen_t *table = auto_alloc_array(machine, pen_t, 65536); int i; /* palettized mode gets a single 64k table in slots 1 and 3 */ diff --git a/src/emu/inptport.c b/src/emu/inptport.c index ec95895acc7..c3b05cf5a7f 100644 --- a/src/emu/inptport.c +++ b/src/emu/inptport.c @@ -630,8 +630,7 @@ time_t input_port_init(running_machine *machine, const input_port_token *tokens) time_t basetime; /* allocate memory for our data structure */ - machine->input_port_data = (input_port_private *)auto_malloc(sizeof(*machine->input_port_data)); - memset(machine->input_port_data, 0, sizeof(*machine->input_port_data)); + machine->input_port_data = auto_alloc_clear(machine, input_port_private); portdata = machine->input_port_data; /* add an exit callback and a frame callback */ @@ -1506,8 +1505,7 @@ static void init_port_types(running_machine *machine) for (typenum = 0; typenum < ARRAY_LENGTH(core_types); typenum++) { /* allocate memory for the state and link it to the end of the list */ - *stateptr = (input_type_state *)auto_malloc(sizeof(**stateptr)); - memset(*stateptr, 0, sizeof(**stateptr)); + *stateptr = auto_alloc_clear(machine, input_type_state); /* copy the type description and link the previous description to it */ (*stateptr)->typedesc = core_types[typenum]; @@ -1556,8 +1554,7 @@ static void init_port_state(running_machine *machine) input_port_state *portstate; /* allocate a new input_port_info structure */ - portstate = (input_port_state *)auto_malloc(sizeof(*portstate)); - memset(portstate, 0, sizeof(*portstate)); + portstate = auto_alloc_clear(machine, input_port_state); ((input_port_config *)port)->state = portstate; ((input_port_config *)port)->machine = machine; @@ -1573,8 +1570,7 @@ static void init_port_state(running_machine *machine) int seqtype; /* allocate a new input_field_info structure */ - fieldstate = (input_field_state *)auto_malloc(sizeof(*fieldstate)); - memset(fieldstate, 0, sizeof(*fieldstate)); + fieldstate = auto_alloc_clear(machine, input_field_state); ((input_field_config *)field)->state = fieldstate; /* fill in the basic values */ @@ -1619,7 +1615,7 @@ static void init_port_state(running_machine *machine) astring *name = mess_get_keyboard_key_name(field); if (name != NULL) { - field->state->name = auto_strdup(astring_c(name)); + field->state->name = auto_strdup(machine, astring_c(name)); astring_free(name); } } @@ -1720,8 +1716,7 @@ static callback_field_info *init_field_callback_info(const input_field_config *f input_port_value mask; /* allocate memory */ - info = (callback_field_info *)auto_malloc(sizeof(*info)); - memset(info, 0, sizeof(*info)); + info = auto_alloc_clear(field->port->machine, callback_field_info); /* fill in the data */ info->field = field; @@ -1743,8 +1738,7 @@ static analog_field_state *init_field_analog_state(const input_field_config *fie input_port_value mask; /* allocate memory */ - state = (analog_field_state *)auto_malloc(sizeof(*state)); - memset(state, 0, sizeof(*state)); + state = auto_alloc_clear(field->port->machine, analog_field_state); /* compute the shift amount and number of bits */ for (mask = field->mask; !(mask & 1); mask >>= 1) @@ -2958,8 +2952,7 @@ static input_port_config *port_config_alloc(const input_port_config **listhead) input_port_config *config; /* allocate memory */ - config = (input_port_config *)malloc_or_die(sizeof(*config)); - memset(config, 0, sizeof(*config)); + config = alloc_clear_or_die(input_port_config); /* add it to the tail */ for (tailptr = listhead; *tailptr != NULL; tailptr = &(*tailptr)->next) ; @@ -3020,8 +3013,7 @@ static input_field_config *field_config_alloc(input_port_config *port, int type, int seqtype; /* allocate memory */ - config = (input_field_config *)malloc_or_die(sizeof(*config)); - memset(config, 0, sizeof(*config)); + config = alloc_clear_or_die(input_field_config); /* fill in the basic field values */ config->port = port; @@ -3128,8 +3120,7 @@ static input_setting_config *setting_config_alloc(input_field_config *field, inp input_setting_config *config; /* allocate memory */ - config = (input_setting_config *)malloc_or_die(sizeof(*config)); - memset(config, 0, sizeof(*config)); + config = alloc_clear_or_die(input_setting_config); /* fill in the basic setting values */ config->field = field; @@ -3188,8 +3179,7 @@ static const input_field_diplocation *diplocation_list_alloc(const input_field_c const char *comma, *colon, *number; /* allocate a new entry */ - *tailptr = (input_field_diplocation *)malloc_or_die(sizeof(**tailptr)); - memset(*tailptr, 0, sizeof(**tailptr)); + *tailptr = alloc_clear_or_die(input_field_diplocation); entries++; /* find the end of this entry */ @@ -3208,7 +3198,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 = (char *)malloc_or_die(colon - tempbuf + 1); + (*tailptr)->swname = lastname = alloc_array_or_die(char, colon - tempbuf + 1); strncpy(lastname, tempbuf, colon - tempbuf); lastname[colon - tempbuf] = 0; number = colon + 1; @@ -3223,7 +3213,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 = (char *)malloc_or_die(strlen(lastname) + 1); + (*tailptr)->swname = namecopy = alloc_array_or_die(char, strlen(lastname) + 1); strcpy(namecopy, lastname); } @@ -3455,8 +3445,8 @@ static void load_remap_table(running_machine *machine, xml_data_node *parentnode int remapnum; /* allocate tables */ - oldtable = (input_code *)malloc_or_die(count * sizeof(*oldtable)); - newtable = (input_code *)malloc_or_die(count * sizeof(*newtable)); + oldtable = alloc_array_or_die(input_code, count); + newtable = alloc_array_or_die(input_code, count); /* build up the remap table */ count = 0; diff --git a/src/emu/input.c b/src/emu/input.c index b50e51d415f..536b0b2a063 100644 --- a/src/emu/input.c +++ b/src/emu/input.c @@ -731,13 +731,13 @@ 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 = (input_device *)auto_realloc(devlist->list, (devlist->count + 1) * sizeof(devlist->list[0])); + devlist->list = auto_extend_array(machine, devlist->list, input_device, devlist->count + 1); device = &devlist->list[devlist->count++]; memset(device, 0, sizeof(*device)); /* fill in the data */ device->machine = machine; - device->name = astring_cpyc(auto_astring_alloc(), name); + device->name = astring_cpyc(auto_astring_alloc(machine), name); device->devclass = devclass; device->devindex = devlist->count - 1; device->internal = internal; @@ -780,15 +780,14 @@ void input_device_item_add(input_device *device, const char *name, void *interna assert(device->item[itemid] == NULL); /* allocate a new item and copy data into it */ - item = (input_device_item *)auto_malloc(sizeof(*item)); - memset(item, 0, sizeof(*item)); + item = auto_alloc_clear(device->machine, input_device_item); device->item[itemid] = item; device->maxitem = MAX(device->maxitem, itemid); /* copy in the data passed in from the item list */ item->devclass = device->devclass; item->devindex = device->devindex; - item->name = astring_cpyc(auto_astring_alloc(), name); + item->name = astring_cpyc(auto_astring_alloc(device->machine), name); item->token = NULL; item->internal = internal; item->itemclass = input_item_standard_class(device->devclass, itemid_std); @@ -799,7 +798,7 @@ void input_device_item_add(input_device *device, const char *name, void *interna if (itemid > ITEM_ID_MAXIMUM) { /* copy the item name, removing spaces/underscores and making all caps */ - item->token = astring_toupper(astring_cpyc(auto_astring_alloc(), name)); + item->token = astring_toupper(astring_cpyc(auto_astring_alloc(device->machine), name)); astring_delchr(item->token, ' '); astring_delchr(item->token, '_'); } diff --git a/src/emu/inputseq.c b/src/emu/inputseq.c index b136ea4b8f8..e2f481bfaa2 100644 --- a/src/emu/inputseq.c +++ b/src/emu/inputseq.c @@ -511,7 +511,7 @@ astring *input_seq_to_tokens(astring *string, const input_seq *seq) int input_seq_from_tokens(const char *string, input_seq *seq) { - char *strcopy = (char *)malloc_or_die(strlen(string) + 1); + char *strcopy = alloc_array_or_die(char, strlen(string) + 1); char *str = strcopy; int result = FALSE; diff --git a/src/emu/machine/at28c16.c b/src/emu/machine/at28c16.c index 9c22e5a8f24..c2fa87dd5c6 100644 --- a/src/emu/machine/at28c16.c +++ b/src/emu/machine/at28c16.c @@ -137,8 +137,8 @@ static DEVICE_START(at28c16) assert(device->machine != NULL); assert(device->machine->config != NULL); - c->data = (UINT8 *)auto_malloc( SIZE_DATA ); - c->id = (UINT8 *)auto_malloc( SIZE_ID ); + c->data = auto_alloc_array( device->machine, UINT8, SIZE_DATA ); + c->id = auto_alloc_array( device->machine, UINT8, SIZE_ID ); c->a9_12v = 0; c->oe_12v = 0; c->last_write = -1; diff --git a/src/emu/machine/i2cmem.c b/src/emu/machine/i2cmem.c index 43cb3ca0ed1..8450ed311ca 100644 --- a/src/emu/machine/i2cmem.c +++ b/src/emu/machine/i2cmem.c @@ -53,9 +53,9 @@ struct i2cmem_chip int shift; int devsel; int byteaddr; - unsigned char *data; + UINT8 *data; int data_size; - unsigned char *page; + UINT8 *page; int page_offset; int page_size; }; @@ -71,10 +71,10 @@ struct i2cmem_chip static struct i2cmem_chip i2cmem[ I2CMEM_MAXCHIP ]; -void i2cmem_init( running_machine *machine, int chip, int slave_address, int page_size, int data_size, unsigned char *data ) +void i2cmem_init( running_machine *machine, int chip, int slave_address, int page_size, int data_size, UINT8 *data ) { struct i2cmem_chip *c; - unsigned char *page = NULL; + UINT8 *page = NULL; if( chip >= I2CMEM_MAXCHIP ) { @@ -86,12 +86,12 @@ void i2cmem_init( running_machine *machine, int chip, int slave_address, int pag if( data == NULL ) { - data = (unsigned char *)auto_malloc( data_size ); + data = auto_alloc_array( machine, UINT8, data_size ); } if( page_size > 0 ) { - page = (unsigned char *)auto_malloc( page_size ); + page = auto_alloc_array( machine, UINT8, page_size ); } c->slave_address = slave_address; diff --git a/src/emu/machine/i2cmemdev.c b/src/emu/machine/i2cmemdev.c index be0ae9bb6bb..9485b405956 100644 --- a/src/emu/machine/i2cmemdev.c +++ b/src/emu/machine/i2cmemdev.c @@ -393,12 +393,11 @@ static DEVICE_START( i2cmem ) if( config != NULL ) { - c->data = auto_malloc( config->data_size ); - if( config->data != NULL ) - memcpy(c->data, config->data, config->data_size); + c->data = auto_alloc_array( device->machine, UINT8, config->data_size ); + memcpy(c->data, config->data, config->data_size); if( config->page_size > 0 ) - page = auto_malloc( config->page_size ); + page = auto_alloc_array( device->machine, UINT8, config->page_size ); c->slave_address = config->slave_address; c->data_size = config->data_size; diff --git a/src/emu/machine/intelfsh.c b/src/emu/machine/intelfsh.c index 7014b011bb9..2f4bfba1a46 100644 --- a/src/emu/machine/intelfsh.c +++ b/src/emu/machine/intelfsh.c @@ -125,7 +125,7 @@ void intelflash_init(running_machine *machine, int chip, int type, void *data) } if( data == NULL ) { - data = auto_malloc( c->size ); + data = auto_alloc_array( machine, UINT8, c->size ); memset( data, 0xff, c->size ); } diff --git a/src/emu/machine/ldcore.c b/src/emu/machine/ldcore.c index 43540d24062..ded391e0642 100644 --- a/src/emu/machine/ldcore.c +++ b/src/emu/machine/ldcore.c @@ -1349,7 +1349,7 @@ static void init_disc(const device_config *device) ldcore->chdtracks = totalhunks / 2; /* allocate memory for the precomputed per-frame metadata */ - ldcore->vbidata = (UINT8 *)auto_malloc(totalhunks * VBI_PACKED_BYTES); + ldcore->vbidata = auto_alloc_array(device->machine, UINT8, totalhunks * VBI_PACKED_BYTES); err = chd_get_metadata(ldcore->disc, AV_LD_METADATA_TAG, 0, ldcore->vbidata, totalhunks * VBI_PACKED_BYTES, &vbilength, NULL, NULL); if (err != CHDERR_NONE || vbilength != totalhunks * VBI_PACKED_BYTES) fatalerror("Precomputed VBI metadata missing or incorrect size"); @@ -1378,11 +1378,11 @@ 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(ldcore->width, ldcore->height * 2, BITMAP_FORMAT_YUY16); + frame->bitmap = auto_bitmap_alloc(device->machine, 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 = (bitmap_t *)auto_malloc(sizeof(*frame->visbitmap)); + 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; @@ -1390,7 +1390,7 @@ static void init_video(const device_config *device) } /* allocate an empty frame of the same size */ - ldcore->emptyframe = auto_bitmap_alloc(ldcore->width, ldcore->height * 2, BITMAP_FORMAT_YUY16); + ldcore->emptyframe = auto_bitmap_alloc(device->machine, ldcore->width, ldcore->height * 2, BITMAP_FORMAT_YUY16); fillbitmap_yuy16(ldcore->emptyframe, 0, 128, 128); /* allocate texture for rendering */ @@ -1410,8 +1410,8 @@ static void init_video(const device_config *device) if (ldcore->config.overwidth > 0 && ldcore->config.overheight > 0 && ldcore->config.overupdate != NULL) { ldcore->overenable = TRUE; - ldcore->overbitmap[0] = auto_bitmap_alloc(ldcore->config.overwidth, ldcore->config.overheight, (bitmap_format)ldcore->config.overformat); - ldcore->overbitmap[1] = auto_bitmap_alloc(ldcore->config.overwidth, ldcore->config.overheight, (bitmap_format)ldcore->config.overformat); + ldcore->overbitmap[0] = auto_bitmap_alloc(device->machine, ldcore->config.overwidth, ldcore->config.overheight, (bitmap_format)ldcore->config.overformat); + ldcore->overbitmap[1] = auto_bitmap_alloc(device->machine, ldcore->config.overwidth, ldcore->config.overheight, (bitmap_format)ldcore->config.overformat); ldcore->overtex = render_texture_alloc(NULL, NULL); if (ldcore->overtex == NULL) fatalerror("Out of memory allocating overlay texture"); @@ -1435,8 +1435,8 @@ static void init_audio(const device_config *device) /* allocate audio buffers */ ldcore->audiomaxsamples = ((UINT64)ldcore->samplerate * 1000000 + ldcore->fps_times_1million - 1) / ldcore->fps_times_1million; ldcore->audiobufsize = ldcore->audiomaxsamples * 4; - ldcore->audiobuffer[0] = (INT16 *)auto_malloc(ldcore->audiobufsize * sizeof(ldcore->audiobuffer[0][0])); - ldcore->audiobuffer[1] = (INT16 *)auto_malloc(ldcore->audiobufsize * sizeof(ldcore->audiobuffer[1][0])); + ldcore->audiobuffer[0] = auto_alloc_array(device->machine, INT16, ldcore->audiobufsize); + ldcore->audiobuffer[1] = auto_alloc_array(device->machine, INT16, ldcore->audiobufsize); } @@ -1470,16 +1470,14 @@ static DEVICE_START( laserdisc ) ld->device = device; /* allocate memory for the core state */ - ld->core = (ldcore_data *)auto_malloc(sizeof(*ld->core)); - memset(ld->core, 0, sizeof(*ld->core)); + ld->core = auto_alloc_clear(device->machine, ldcore_data); ldcore = ld->core; /* determine the maximum player-specific state size and allocate it */ statesize = 0; for (index = 0; index < ARRAY_LENGTH(player_interfaces); index++) statesize = MAX(statesize, player_interfaces[index]->statesize); - ld->player = (ldplayer_data *)auto_malloc(statesize); - memset(ld->player, 0, statesize); + ld->player = (ldplayer_data *)auto_alloc_array_clear(device->machine, UINT8, statesize); /* copy config data to the live state */ ldcore->config = *config; diff --git a/src/emu/machine/mc146818.c b/src/emu/machine/mc146818.c index 8099f0ec3b6..938e60b9f16 100644 --- a/src/emu/machine/mc146818.c +++ b/src/emu/machine/mc146818.c @@ -199,8 +199,7 @@ static TIMER_CALLBACK( mc146818_timer ) void mc146818_init(running_machine *machine, MC146818_TYPE type) { - mc146818 = (struct mc146818_chip *)auto_malloc(sizeof(*mc146818)); - memset(mc146818, 0, sizeof(*mc146818)); + mc146818 = auto_alloc_clear(machine, struct mc146818_chip); mc146818->type = type; mc146818->last_refresh = timer_get_time(machine); timer_pulse(machine, ATTOTIME_IN_HZ(1), NULL, 0, mc146818_timer); diff --git a/src/emu/machine/scsi.c b/src/emu/machine/scsi.c index f2ce60f3b72..0c3a9b858de 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 *) malloc_or_die( SCSISizeof( scsiClass ) ); + SCSIInstance *scsiInstance = alloc_or_die(SCSIInstance); scsiInstance->scsiClass = scsiClass; scsiInstance->machine = machine; return scsiInstance; diff --git a/src/emu/machine/timekpr.c b/src/emu/machine/timekpr.c index f90b578fd74..2a7f8699ed6 100644 --- a/src/emu/machine/timekpr.c +++ b/src/emu/machine/timekpr.c @@ -308,7 +308,7 @@ static DEVICE_START(timekeeper) c->month = make_bcd( systime.local_time.month + 1 ); c->year = make_bcd( systime.local_time.year % 100 ); c->century = make_bcd( systime.local_time.year / 100 ); - c->data = (UINT8 *)auto_malloc( c->size ); + c->data = auto_alloc_array( device->machine, UINT8, c->size ); c->default_data = device->region; if (c->default_data != NULL) diff --git a/src/emu/machine/wd33c93.c b/src/emu/machine/wd33c93.c index df52db848e3..ef570b22ef6 100644 --- a/src/emu/machine/wd33c93.c +++ b/src/emu/machine/wd33c93.c @@ -798,7 +798,7 @@ void wd33c93_init( running_machine *machine, const struct WD33C93interface *inte /* allocate a timer for commands */ scsi_data.cmd_timer = timer_alloc(machine, wd33c93_complete_cb, NULL); - scsi_data.temp_input = (UINT8 *)auto_malloc( TEMP_INPUT_LEN ); + scsi_data.temp_input = auto_alloc_array( machine, UINT8, TEMP_INPUT_LEN ); // state_save_register_item_array(machine, "wd33c93", NULL, 0, scsi_data); } diff --git a/src/emu/machine/x2212.c b/src/emu/machine/x2212.c index 0a1526f07b7..50a1dffeb57 100644 --- a/src/emu/machine/x2212.c +++ b/src/emu/machine/x2212.c @@ -88,8 +88,8 @@ static DEVICE_START(x2212) assert(device->machine != NULL); assert(device->machine->config != NULL); - c->sram = (UINT8 *)auto_malloc( SIZE_DATA ); - c->e2prom = (UINT8 *)auto_malloc( SIZE_DATA ); + c->sram = auto_alloc_array( device->machine, UINT8, SIZE_DATA ); + c->e2prom = auto_alloc_array( device->machine, UINT8, SIZE_DATA ); c->store = 1; c->array_recall = 1; diff --git a/src/emu/machine/x76f041.c b/src/emu/machine/x76f041.c index a4aa5f1e840..fb26eaf74de 100644 --- a/src/emu/machine/x76f041.c +++ b/src/emu/machine/x76f041.c @@ -115,7 +115,7 @@ void x76f041_init( running_machine *machine, int chip, UINT8 *data ) if( data == NULL ) { - data = (UINT8 *)auto_malloc( + data = auto_alloc_array( machine, UINT8, SIZE_RESPONSE_TO_RESET + SIZE_READ_PASSWORD + SIZE_WRITE_PASSWORD + diff --git a/src/emu/machine/x76f100.c b/src/emu/machine/x76f100.c index 33d3089ce98..d355b7c6cac 100644 --- a/src/emu/machine/x76f100.c +++ b/src/emu/machine/x76f100.c @@ -84,7 +84,7 @@ void x76f100_init( running_machine *machine, int chip, UINT8 *data ) if( data == NULL ) { - data = (UINT8 *)auto_malloc( + data = auto_alloc_array( machine, UINT8, SIZE_RESPONSE_TO_RESET + SIZE_READ_PASSWORD + SIZE_WRITE_PASSWORD + diff --git a/src/emu/mame.c b/src/emu/mame.c index 3a7340e55d9..26952ea6a01 100644 --- a/src/emu/mame.c +++ b/src/emu/mame.c @@ -458,7 +458,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 = (callback_item *)malloc_or_die(sizeof(*cb)); + cb = alloc_or_die(callback_item); /* add us to the end of the list */ cb->func.frame = callback; @@ -481,7 +481,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 = (callback_item *)malloc_or_die(sizeof(*cb)); + cb = alloc_or_die(callback_item); /* add us to the end of the list */ cb->func.reset = callback; @@ -504,7 +504,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 = (callback_item *)malloc_or_die(sizeof(*cb)); + cb = alloc_or_die(callback_item); /* add us to the end of the list */ cb->func.pause = callback; @@ -527,7 +527,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 = (callback_item *)malloc_or_die(sizeof(*cb)); + cb = alloc_or_die(callback_item); /* add us to the head of the list */ cb->func.exit = callback; @@ -782,7 +782,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 *)malloc_or_die(sizeof(*info) + length); + info = (region_info *)alloc_array_or_die(UINT8, sizeof(*info) + length); info->next = NULL; info->name = astring_dupc(name); info->length = length; @@ -1247,7 +1247,7 @@ void add_logerror_callback(running_machine *machine, void (*callback)(running_ma assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_logerror_callback at init time!"); - cb = (callback_item *)auto_malloc(sizeof(*cb)); + cb = auto_alloc(machine, callback_item); cb->func.log = callback; cb->next = NULL; diff --git a/src/emu/mconfig.c b/src/emu/mconfig.c index 4859725550e..a4fe4e41031 100644 --- a/src/emu/mconfig.c +++ b/src/emu/mconfig.c @@ -69,8 +69,7 @@ machine_config *machine_config_alloc(const machine_config_token *tokens) machine_config *config; /* allocate a new configuration object */ - config = (machine_config *)malloc_or_die(sizeof(*config)); - memset(config, 0, sizeof(*config)); + config = alloc_clear_or_die(machine_config); /* parse tokens into the config */ machine_config_detokenize(config, tokens, NULL, 0); diff --git a/src/emu/memory.c b/src/emu/memory.c index d72cfdaecb7..0c8b7232000 100644 --- a/src/emu/memory.c +++ b/src/emu/memory.c @@ -441,7 +441,7 @@ INLINE void add_bank_reference(bank_info *bank, const address_space *space) return; /* allocate a new entry and fill it */ - (*refptr) = (bank_reference *)malloc_or_die(sizeof(**refptr)); + (*refptr) = alloc_or_die(bank_reference); (*refptr)->next = NULL; (*refptr)->space = space; } @@ -712,8 +712,7 @@ void memory_init(running_machine *machine) add_exit_callback(machine, memory_exit); /* allocate our private data */ - memdata = machine->memory_data = (memory_private *)auto_malloc(sizeof(*machine->memory_data)); - memset(memdata, 0, sizeof(*memdata)); + memdata = machine->memory_data = auto_alloc_clear(machine, memory_private); /* build up the cpudata array with info about all CPUs and address spaces */ memory_init_spaces(machine); @@ -769,8 +768,7 @@ address_map *address_map_alloc(const device_config *device, const game_driver *d const addrmap_token *internal_map; address_map *map; - map = (address_map *)malloc_or_die(sizeof(*map)); - memset(map, 0, sizeof(*map)); + map = alloc_clear_or_die(address_map); /* append the internal CPU map (first so it takes priority) */ internal_map = (const addrmap_token *)device_get_info_ptr(device, CPUINFO_PTR_INTERNAL_MEMORY_MAP + spacenum); @@ -1494,7 +1492,7 @@ static void memory_init_spaces(running_machine *machine) int spacenum; /* create a global watchpoint-filled table */ - memdata->wptable = (UINT8 *)auto_malloc(1 << LEVEL1_BITS); + memdata->wptable = auto_alloc_array(machine, UINT8, 1 << LEVEL1_BITS); memset(memdata->wptable, STATIC_WATCHPOINT, 1 << LEVEL1_BITS); /* loop over CPUs */ @@ -1502,7 +1500,7 @@ static void memory_init_spaces(running_machine *machine) for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++) if (cpu_get_addrbus_width(device, spacenum) > 0) { - address_space *space = (address_space *)malloc_or_die(sizeof(*space)); + address_space *space = alloc_clear_or_die(address_space); int logbits = cpu_get_logaddr_width(device, spacenum); int ashift = cpu_get_addrbus_shift(device, spacenum); int abits = cpu_get_addrbus_width(device, spacenum); @@ -1516,7 +1514,6 @@ static void memory_init_spaces(running_machine *machine) logbits = abits; /* determine the address and data bits */ - memset(space, 0, sizeof(*space)); space->machine = machine; space->cpu = device; space->name = address_space_names[spacenum]; @@ -1536,16 +1533,12 @@ static void memory_init_spaces(running_machine *machine) space->log_unmap = TRUE; /* allocate subtable information; we malloc this manually because it will be realloc'ed */ - space->read.subtable = (subtable_data *)auto_malloc(sizeof(*space->read.subtable) * SUBTABLE_COUNT); - memset(space->read.subtable, 0, sizeof(*space->read.subtable) * SUBTABLE_COUNT); - space->write.subtable = (subtable_data *)auto_malloc(sizeof(*space->write.subtable) * SUBTABLE_COUNT); - memset(space->write.subtable, 0, sizeof(*space->write.subtable) * SUBTABLE_COUNT); + space->read.subtable = auto_alloc_array_clear(machine, subtable_data, SUBTABLE_COUNT); + space->write.subtable = auto_alloc_array_clear(machine, subtable_data, SUBTABLE_COUNT); /* allocate the handler table */ - space->read.handlers[0] = (handler_data *)auto_malloc(sizeof(*space->read.handlers[0]) * ARRAY_LENGTH(space->read.handlers)); - memset(space->read.handlers[0], 0, sizeof(*space->read.handlers[0]) * ARRAY_LENGTH(space->read.handlers)); - space->write.handlers[0] = (handler_data *)auto_malloc(sizeof(*space->write.handlers[0]) * ARRAY_LENGTH(space->write.handlers)); - memset(space->write.handlers[0], 0, sizeof(*space->write.handlers[0]) * ARRAY_LENGTH(space->write.handlers)); + space->read.handlers[0] = auto_alloc_array_clear(machine, handler_data, ARRAY_LENGTH(space->read.handlers)); + space->write.handlers[0] = auto_alloc_array_clear(machine, handler_data, ARRAY_LENGTH(space->write.handlers)); for (entrynum = 1; entrynum < ARRAY_LENGTH(space->read.handlers); entrynum++) { space->read.handlers[entrynum] = space->read.handlers[0] + entrynum; @@ -1568,8 +1561,8 @@ static void memory_init_spaces(running_machine *machine) space->write.handlers[STATIC_WATCHPOINT]->bytemask = ~0; /* allocate memory; these aren't auto-malloc'ed as we need to expand them */ - space->read.table = (UINT8 *)malloc_or_die(1 << LEVEL1_BITS); - space->write.table = (UINT8 *)malloc_or_die(1 << LEVEL1_BITS); + space->read.table = alloc_array_or_die(UINT8, 1 << LEVEL1_BITS); + space->write.table = alloc_array_or_die(UINT8, 1 << LEVEL1_BITS); /* initialize everything to unmapped */ memset(space->read.table, STATIC_UNMAP, 1 << LEVEL1_BITS); @@ -2059,9 +2052,8 @@ static void map_detokenize(address_map *map, const game_driver *driver, const ch /* start a new range */ case ADDRMAP_TOKEN_RANGE: - entry = *entryptr = (address_map_entry *)malloc_or_die(sizeof(**entryptr)); + entry = *entryptr = alloc_clear_or_die(address_map_entry); entryptr = &entry->next; - memset(entry, 0, sizeof(*entry)); TOKEN_GET_UINT64_UNPACK2(tokens, entry->addrstart, 32, entry->addrend, 32); break; @@ -3030,7 +3022,7 @@ static direct_range *direct_range_find(address_space *space, offs_t byteaddress, if (range != NULL) space->direct.freerangelist = range->next; else - range = (direct_range *)malloc_or_die(sizeof(*range)); + range = alloc_or_die(direct_range); /* fill in the range */ table_derive_range(&space->read, byteaddress, &range->bytestart, &range->byteend); @@ -3102,8 +3094,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 *)malloc_or_die(bytestoalloc); - memset(block, 0, bytestoalloc); + block = (memory_block *)alloc_array_clear_or_die(UINT8, bytestoalloc); if (allocatemem) memory = block + 1; diff --git a/src/emu/memory.h b/src/emu/memory.h index 94e6e1a6a44..d2d1208b50c 100644 --- a/src/emu/memory.h +++ b/src/emu/memory.h @@ -443,38 +443,6 @@ union _addrmap64_token #define SMH_NOP ((void *)STATIC_NOP) #define SMH_UNMAP ((void *)STATIC_UNMAP) #define SMH_BANK(n) ((void *)(STATIC_BANK1 + (n) - 1)) -#define SMH_BANK1 SMH_BANK(1) -#define SMH_BANK2 SMH_BANK(2) -#define SMH_BANK3 SMH_BANK(3) -#define SMH_BANK4 SMH_BANK(4) -#define SMH_BANK5 SMH_BANK(5) -#define SMH_BANK6 SMH_BANK(6) -#define SMH_BANK7 SMH_BANK(7) -#define SMH_BANK8 SMH_BANK(8) -#define SMH_BANK9 SMH_BANK(9) -#define SMH_BANK10 SMH_BANK(10) -#define SMH_BANK11 SMH_BANK(11) -#define SMH_BANK12 SMH_BANK(12) -#define SMH_BANK13 SMH_BANK(13) -#define SMH_BANK14 SMH_BANK(14) -#define SMH_BANK15 SMH_BANK(15) -#define SMH_BANK16 SMH_BANK(16) -#define SMH_BANK17 SMH_BANK(17) -#define SMH_BANK18 SMH_BANK(18) -#define SMH_BANK19 SMH_BANK(19) -#define SMH_BANK20 SMH_BANK(20) -#define SMH_BANK21 SMH_BANK(21) -#define SMH_BANK22 SMH_BANK(22) -#define SMH_BANK23 SMH_BANK(23) -#define SMH_BANK24 SMH_BANK(24) -#define SMH_BANK25 SMH_BANK(25) -#define SMH_BANK26 SMH_BANK(26) -#define SMH_BANK27 SMH_BANK(27) -#define SMH_BANK28 SMH_BANK(28) -#define SMH_BANK29 SMH_BANK(29) -#define SMH_BANK30 SMH_BANK(30) -#define SMH_BANK31 SMH_BANK(31) -#define SMH_BANK32 SMH_BANK(32) /* helper macro for merging data with the memory mask */ diff --git a/src/emu/output.c b/src/emu/output.c index beb3dde3c7b..ae5ff296379 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 = (char *)malloc_or_die(strlen(string) + 1); + char *newstring = alloc_array_or_die(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 = (output_item *)malloc_or_die(sizeof(*item)); + output_item *item = alloc_or_die(output_item); UINT32 hash = get_hash(outname); /* fill in the data */ @@ -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 = (output_notify *)malloc_or_die(sizeof(**headptr)); + *headptr = alloc_or_die(output_notify); /* fill in the new record */ (*headptr)->next = NULL; diff --git a/src/emu/render.c b/src/emu/render.c index 984e8f5e522..a791a824575 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 = (container_item *)malloc_or_die(sizeof(*result)); + result = alloc_or_die(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 = (render_primitive *)malloc_or_die(sizeof(*result)); + result = alloc_or_die(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 = (render_ref *)malloc_or_die(sizeof(*ref)); + ref = alloc_or_die(render_ref); /* set the refptr and link us into the list */ ref->refptr = refptr; @@ -1073,8 +1073,7 @@ render_target *render_target_alloc(running_machine *machine, const char *layoutf int listnum; /* allocate memory for the target */ - target = (render_target *)malloc_or_die(sizeof(*target)); - memset(target, 0, sizeof(*target)); + target = alloc_clear_or_die(render_target); /* add it to the end of the list */ for (nextptr = &targetlist; *nextptr != NULL; nextptr = &(*nextptr)->next) ; @@ -2433,8 +2432,7 @@ render_texture *render_texture_alloc(texture_scaler_func scaler, void *param) int texnum; /* allocate a new group */ - texture = (render_texture *)malloc_or_die(sizeof(*texture) * TEXTURE_GROUP_SIZE); - memset(texture, 0, sizeof(*texture) * TEXTURE_GROUP_SIZE); + texture = alloc_array_clear_or_die(render_texture, TEXTURE_GROUP_SIZE); /* add them to the list */ for (texnum = 0; texnum < TEXTURE_GROUP_SIZE; texnum++) @@ -2770,8 +2768,7 @@ static render_container *render_container_alloc(running_machine *machine) int color; /* allocate and clear memory */ - container = (render_container *)malloc_or_die(sizeof(*container)); - memset(container, 0, sizeof(*container)); + container = alloc_clear_or_die(render_container); /* default values */ container->brightness = 1.0f; diff --git a/src/emu/rendfont.c b/src/emu/rendfont.c index eab3f5d572d..bceeadb170e 100644 --- a/src/emu/rendfont.c +++ b/src/emu/rendfont.c @@ -141,8 +141,7 @@ render_font *render_font_alloc(const char *filename) render_font *font; /* allocate and clear memory */ - font = (render_font *)malloc_or_die(sizeof(*font)); - memset(font, 0, sizeof(*font)); + font = alloc_clear_or_die(render_font); /* attempt to load the cached version of the font first */ if (filename != NULL && render_font_load_cached_bdf(font, filename) == 0) @@ -150,8 +149,7 @@ render_font *render_font_alloc(const char *filename) /* if we failed, clean up and realloc */ render_font_free(font); - font = (render_font *)malloc_or_die(sizeof(*font)); - memset(font, 0, sizeof(*font)); + font = alloc_clear_or_die(render_font); /* load the raw data instead */ filerr = mame_fopen_ram(font_uismall, sizeof(font_uismall), OPEN_FLAG_READ, &ramfile); @@ -434,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 = (char *)malloc_or_die(font->rawsize + 1); + data = alloc_array_clear_or_die(char, font->rawsize + 1); /* read and hash the first chunk */ bytes = mame_fread(file, data, MIN(CACHED_BDF_HASH_SIZE, font->rawsize)); @@ -583,10 +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] = (render_font_char *)malloc_or_die(256 * sizeof(font->chars[0][0])); - memset(font->chars[charnum / 256], 0, 256 * sizeof(font->chars[0][0])); - } + font->chars[charnum / 256] = alloc_array_clear_or_die(render_font_char, 256); /* fill in the entry */ ch = &font->chars[charnum / 256][charnum % 256]; @@ -642,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 = (UINT8 *)malloc_or_die(filesize - CACHED_HEADER_SIZE); + data = alloc_array_or_die(UINT8, filesize - CACHED_HEADER_SIZE); bytes_read = mame_fread(file, data, filesize - CACHED_HEADER_SIZE); if (bytes_read != filesize - CACHED_HEADER_SIZE) goto error; @@ -657,10 +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] = (render_font_char *)malloc_or_die(256 * sizeof(font->chars[0][0])); - memset(font->chars[chnum / 256], 0, 256 * sizeof(font->chars[0][0])); - } + font->chars[chnum / 256] = alloc_array_clear_or_die(render_font_char, 256); /* fill in the entry */ ch = &font->chars[chnum / 256][chnum % 256]; @@ -728,11 +720,10 @@ static int render_font_save_cached(render_font *font, const char *filename, UINT } /* allocate an array to hold the character data */ - chartable = (UINT8 *)malloc_or_die(numchars * CACHED_CHAR_SIZE); - memset(chartable, 0, numchars * CACHED_CHAR_SIZE); + chartable = alloc_array_clear_or_die(UINT8, numchars * CACHED_CHAR_SIZE); /* allocate a temp buffer to compress into */ - tempbuffer = (UINT8 *)malloc_or_die(65536); + tempbuffer = alloc_array_or_die(UINT8, 65536); /* write the header */ dest = tempbuffer; diff --git a/src/emu/rendlay.c b/src/emu/rendlay.c index f3b0d0cbf66..5fe1318d89b 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 = (char *)malloc_or_die(strlen(string) + 1); + char *newstring = alloc_array_or_die(char, strlen(string) + 1); strcpy(newstring, string); return newstring; } @@ -1509,8 +1509,7 @@ layout_file *layout_file_load(const machine_config *config, const char *dirname, return NULL; /* allocate the layout group object first */ - file = (layout_file *)malloc_or_die(sizeof(*file)); - memset(file, 0, sizeof(*file)); + file = alloc_clear_or_die(layout_file); /* find the layout node */ mamelayoutnode = xml_get_sibling(rootnode->child, "mamelayout"); @@ -1579,8 +1578,7 @@ static layout_element *load_layout_element(const machine_config *config, xml_dat int first; /* allocate a new element */ - element = (layout_element *)malloc_or_die(sizeof(*element)); - memset(element, 0, sizeof(*element)); + element = alloc_clear_or_die(layout_element); /* extract the name */ name = xml_get_attribute_string_with_subst(config, elemnode, "name", NULL); @@ -1642,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 = (element_texture *)malloc_or_die((element->maxstate + 1) * sizeof(element->elemtex[0])); + element->elemtex = alloc_array_or_die(element_texture, element->maxstate + 1); for (state = 0; state <= element->maxstate; state++) { element->elemtex[state].element = element; @@ -1668,8 +1666,7 @@ static element_component *load_element_component(const machine_config *config, x element_component *component; /* allocate memory for the component */ - component = (element_component *)malloc_or_die(sizeof(*component)); - memset(component, 0, sizeof(*component)); + component = alloc_clear_or_die(element_component); /* fetch common data */ component->state = xml_get_attribute_int_with_subst(config, compnode, "state", -1); @@ -1699,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 = (char *)malloc_or_die(strlen(text) + 1); + string = alloc_array_or_die(char, strlen(text) + 1); strcpy(string, text); component->string = string; } @@ -1756,8 +1753,7 @@ static layout_view *load_layout_view(const machine_config *config, xml_data_node int layer; /* first allocate memory */ - view = (layout_view *)malloc_or_die(sizeof(*view)); - memset(view, 0, sizeof(*view)); + view = alloc_clear_or_die(layout_view); /* allocate a copy of the name */ view->name = copy_string(xml_get_attribute_string_with_subst(config, viewnode, "name", "")); @@ -1810,8 +1806,7 @@ static view_item *load_view_item(const machine_config *config, xml_data_node *it const char *name; /* allocate a new item */ - item = (view_item *)malloc_or_die(sizeof(*item)); - memset(item, 0, sizeof(*item)); + item = alloc_clear_or_die(view_item); /* allocate a copy of the output name */ item->output_name = copy_string(xml_get_attribute_string_with_subst(config, itemnode, "name", "")); diff --git a/src/emu/restrack.c b/src/emu/restrack.c index 1f899cb5efb..72e3704497f 100644 --- a/src/emu/restrack.c +++ b/src/emu/restrack.c @@ -197,7 +197,7 @@ void *restrack_register_object(object_type type, void *ptr, size_t size, const c freeing memory -------------------------------------------------*/ -void *auto_malloc_file_line(size_t size, const char *file, int line) +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); #ifdef MAME_DEBUG @@ -212,7 +212,7 @@ void *auto_malloc_file_line(size_t size, const char *file, int line) freeing memory -------------------------------------------------*/ -void *auto_realloc_file_line(void *ptr, size_t size, const char *file, int line) +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) @@ -236,7 +236,7 @@ void *auto_realloc_file_line(void *ptr, size_t size, const char *file, int line) string -------------------------------------------------*/ -char *auto_strdup_file_line(const char *str, const char *file, int line) +char *auto_strdup_file_line(running_machine *machine, const char *str, const char *file, int line) { return pool_strdup_file_line(current_pool(), str, file, line); } @@ -247,9 +247,9 @@ char *auto_strdup_file_line(const char *str, const char *file, int line) auto-freeing string if str is null -------------------------------------------------*/ -char *auto_strdup_allow_null_file_line(const char *str, const char *file, int line) +char *auto_strdup_allow_null_file_line(running_machine *machine, const char *str, const char *file, int line) { - return (str != NULL) ? auto_strdup_file_line(str, file, line) : NULL; + return (str != NULL) ? auto_strdup_file_line(machine, str, file, line) : NULL; } @@ -258,7 +258,7 @@ char *auto_strdup_allow_null_file_line(const char *str, const char *file, int li auto-freeing astring -------------------------------------------------*/ -astring *auto_astring_alloc_file_line(const char *file, int line) +astring *auto_astring_alloc_file_line(running_machine *machine, const char *file, int line) { return (astring *)restrack_register_object(OBJTYPE_ASTRING, astring_alloc(), 0, file, line); } @@ -269,7 +269,7 @@ astring *auto_astring_alloc_file_line(const char *file, int line) auto-freeing bitmap -------------------------------------------------*/ -bitmap_t *auto_bitmap_alloc_file_line(int width, int height, bitmap_format format, const char *file, int line) +bitmap_t *auto_bitmap_alloc_file_line(running_machine *machine, int width, int height, bitmap_format format, const char *file, int line) { return (bitmap_t *)restrack_register_object(OBJTYPE_BITMAP, bitmap_alloc(width, height, format), width * height, file, line); } diff --git a/src/emu/restrack.h b/src/emu/restrack.h index 5caf0672644..d62cc0e7a21 100644 --- a/src/emu/restrack.h +++ b/src/emu/restrack.h @@ -59,32 +59,39 @@ INLINE int get_resource_tag(void) /* allocate memory and fatalerror if there's a problem */ -#define malloc_or_die(s) malloc_or_die_file_line(s, __FILE__, __LINE__) +#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_malloc(s) auto_malloc_file_line(s, __FILE__, __LINE__) -void *auto_malloc_file_line(size_t size, const char *file, int line) ATTR_MALLOC; +#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_realloc(p, s) auto_realloc_file_line(p, s, __FILE__, __LINE__) -void *auto_realloc_file_line(void *ptr, size_t size, const char *file, int line) ATTR_MALLOC; +#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(s) auto_strdup_file_line(s, __FILE__, __LINE__) -char *auto_strdup_file_line(const char *str, const char *file, int line) ATTR_MALLOC; +#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(s) auto_strdup_allow_null_file_line(s, __FILE__, __LINE__) -char *auto_strdup_allow_null_file_line(const char *str, const char *file, int line) ATTR_MALLOC; +#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() auto_astring_alloc_file_line(__FILE__, __LINE__) -astring *auto_astring_alloc_file_line(const char *file, int line); +#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(w,h,f) auto_bitmap_alloc_file_line(w, h, f, __FILE__, __LINE__) -bitmap_t *auto_bitmap_alloc_file_line(int width, int height, bitmap_format format, const char *file, int line); +#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 140190e4669..49d8330b40d 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -115,7 +115,7 @@ chd_file *get_disk_handle(const char *region) file associated with the given region -------------------------------------------------*/ -void set_disk_handle(const char *region, mame_file *file, chd_file *chdfile) +void set_disk_handle(running_machine *machine, const char *region, mame_file *file, chd_file *chdfile) { open_chd chd = { 0 }; @@ -125,7 +125,7 @@ void set_disk_handle(const char *region, mame_file *file, chd_file *chdfile) chd.origfile = file; /* we're okay, add to the list of disks */ - *chd_list_tailptr = (open_chd *)auto_malloc(sizeof(**chd_list_tailptr)); + *chd_list_tailptr = auto_alloc(machine, open_chd); **chd_list_tailptr = chd; chd_list_tailptr = &(*chd_list_tailptr)->next; } @@ -757,7 +757,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 = (UINT8 *)malloc_or_die(tempbufsize); + tempbuf = alloc_array_or_die(UINT8, tempbufsize); /* chunky reads for complex loads */ skip += groupsize; @@ -1225,7 +1225,7 @@ static void process_disk_entries(rom_load_data *romdata, const char *regiontag, /* we're okay, add to the list of disks */ LOG(("Assigning to handle %d\n", DISK_GETINDEX(romp))); - *chd_list_tailptr = (open_chd *)auto_malloc(sizeof(**chd_list_tailptr)); + *chd_list_tailptr = auto_alloc(romdata->machine, open_chd); **chd_list_tailptr = chd; chd_list_tailptr = &(*chd_list_tailptr)->next; } diff --git a/src/emu/romload.h b/src/emu/romload.h index 9a653ffd9ae..9150cf2faf3 100644 --- a/src/emu/romload.h +++ b/src/emu/romload.h @@ -328,7 +328,7 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game chd_file *get_disk_handle(const char *region); /* set a pointer to the CHD file associated with the given region */ -void set_disk_handle(const char *region, mame_file *file, chd_file *chd); +void set_disk_handle(running_machine *machine, const char *region, mame_file *file, chd_file *chd); #endif /* __ROMLOAD_H__ */ diff --git a/src/emu/sound.c b/src/emu/sound.c index 03ed3fc27f1..9f54ae418c4 100644 --- a/src/emu/sound.c +++ b/src/emu/sound.c @@ -202,9 +202,9 @@ void sound_init(running_machine *machine) VPRINTF(("total speakers = %d\n", speaker_output_count(machine->config))); /* allocate memory for mix buffers */ - leftmix = (INT32 *)auto_malloc(machine->sample_rate * sizeof(*leftmix)); - rightmix = (INT32 *)auto_malloc(machine->sample_rate * sizeof(*rightmix)); - finalmix = (INT16 *)auto_malloc(machine->sample_rate * sizeof(*finalmix)); + leftmix = auto_alloc_array(machine, INT32, machine->sample_rate); + rightmix = auto_alloc_array(machine, INT32, machine->sample_rate); + finalmix = auto_alloc_array(machine, INT16, machine->sample_rate); /* allocate a global timer for sound timing */ sound_update_timer = timer_alloc(machine, sound_update, NULL); @@ -341,7 +341,7 @@ static DEVICE_CUSTOM_CONFIG( sound ) /* allocate a new route */ for (routeptr = &config->routelist; *routeptr != NULL; routeptr = &(*routeptr)->next) ; - *routeptr = (sound_route *)malloc_or_die(sizeof(**routeptr)); + *routeptr = alloc_or_die(sound_route); (*routeptr)->next = NULL; (*routeptr)->output = output; (*routeptr)->input = input; @@ -451,7 +451,7 @@ static void route_sound(running_machine *machine) { info->mixer_stream = stream_create(curspeak, info->inputs, 1, machine->sample_rate, info, mixer_update); state_save_register_postload(machine, mixer_postload, info->mixer_stream); - info->input = (speaker_input *)auto_malloc(info->inputs * sizeof(*info->input)); + info->input = auto_alloc_array(machine, speaker_input, info->inputs); info->inputs = 0; } else @@ -490,7 +490,7 @@ static void route_sound(running_machine *machine) /* fill in the input data on this speaker */ speakerinfo->input[speakerinfo->inputs].gain = route->gain; speakerinfo->input[speakerinfo->inputs].default_gain = route->gain; - speakerinfo->input[speakerinfo->inputs].name = auto_strdup(astring_c(tempstring)); + speakerinfo->input[speakerinfo->inputs].name = auto_strdup(machine, astring_c(tempstring)); /* connect the output to the input */ if (stream_device_output_to_stream_output(sound, outputnum, &stream, &streamoutput)) diff --git a/src/emu/sound/aica.c b/src/emu/sound/aica.c index db4408125a8..0c34fe515e9 100644 --- a/src/emu/sound/aica.c +++ b/src/emu/sound/aica.c @@ -647,10 +647,8 @@ static void AICA_Init(const device_config *device, aica_state *AICA, const aica_ } AICALFO_Init(device->machine); - AICA->buffertmpl=(signed int*) auto_malloc(44100*sizeof(signed int)); - AICA->buffertmpr=(signed int*) auto_malloc(44100*sizeof(signed int)); - memset(AICA->buffertmpl,0,44100*sizeof(signed int)); - memset(AICA->buffertmpr,0,44100*sizeof(signed int)); + AICA->buffertmpl=auto_alloc_array_clear(device->machine, signed int, 44100); + AICA->buffertmpr=auto_alloc_array_clear(device->machine, signed int, 44100); // no "pend" AICA[0].udata.data[0xa0/2] = 0; diff --git a/src/emu/sound/ay8910.c b/src/emu/sound/ay8910.c index 9f1092a11b0..0da96f3ee4d 100644 --- a/src/emu/sound/ay8910.c +++ b/src/emu/sound/ay8910.c @@ -743,10 +743,8 @@ void *ay8910_start_ym(void *infoptr, sound_type chip_type, const device_config * ay8910_context *info = (ay8910_context *)infoptr; if (info == NULL) - { - info = (ay8910_context *)auto_malloc(sizeof(*info)); - memset(info, 0, sizeof(*info)); - } + info = auto_alloc_clear(device->machine, ay8910_context); + info->device = device; info->intf = intf; devcb_resolve_read8(&info->portAread, &intf->portAread, device); diff --git a/src/emu/sound/c140.c b/src/emu/sound/c140.c index 0d258903405..300840e7e04 100644 --- a/src/emu/sound/c140.c +++ b/src/emu/sound/c140.c @@ -496,7 +496,7 @@ static DEVICE_START( c140 ) } /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ - info->mixer_buffer_left = (INT16 *)auto_malloc(2 * sizeof(INT16)*info->sample_rate ); + info->mixer_buffer_left = auto_alloc_array(device->machine, INT16, 2 * info->sample_rate); info->mixer_buffer_right = info->mixer_buffer_left + info->sample_rate; } diff --git a/src/emu/sound/cdda.c b/src/emu/sound/cdda.c index 20ba3ec46a4..7c99a6aa766 100644 --- a/src/emu/sound/cdda.c +++ b/src/emu/sound/cdda.c @@ -59,7 +59,7 @@ static DEVICE_START( cdda ) cdda_info *info = get_safe_token(device); /* allocate an audio cache */ - info->audio_cache = (UINT8 *)auto_malloc( CD_MAX_SECTOR_DATA * MAX_SECTORS ); + info->audio_cache = auto_alloc_array( device->machine, UINT8, CD_MAX_SECTOR_DATA * MAX_SECTORS ); intf = (const struct CDDAinterface *)device->static_config; diff --git a/src/emu/sound/cem3394.c b/src/emu/sound/cem3394.c index e3ba18f8d09..f01a02230cf 100644 --- a/src/emu/sound/cem3394.c +++ b/src/emu/sound/cem3394.c @@ -344,8 +344,8 @@ static DEVICE_START( cem3394 ) chip->filter_zero_freq = intf->filter_zero_freq; /* allocate memory for a mixer buffer and external buffer (1 second should do it!) */ - chip->mixer_buffer = (INT16 *)auto_malloc(chip->sample_rate * sizeof(INT16)); - chip->external_buffer = (INT16 *)auto_malloc(chip->sample_rate * sizeof(INT16)); + chip->mixer_buffer = auto_alloc_array(device->machine, INT16, chip->sample_rate); + chip->external_buffer = auto_alloc_array(device->machine, INT16, chip->sample_rate); state_save_register_device_item_array(device, 0, chip->values); state_save_register_device_item(device, 0, chip->wave_select); diff --git a/src/emu/sound/discrete.c b/src/emu/sound/discrete.c index f71bb6b0ccd..b56c4b0523c 100644 --- a/src/emu/sound/discrete.c +++ b/src/emu/sound/discrete.c @@ -292,16 +292,13 @@ static DEVICE_START( discrete ) discrete_log("discrete_start() - Sanity check counted %d nodes", info->node_count); /* allocate memory for the array of actual nodes */ - info->node_list = (node_description *)auto_malloc(info->node_count * sizeof(info->node_list[0])); - memset(info->node_list, 0, info->node_count * sizeof(info->node_list[0])); + info->node_list = auto_alloc_array_clear(device->machine, node_description, info->node_count); /* allocate memory for the node execution order array */ - info->running_order = (node_description **)auto_malloc(info->node_count * sizeof(info->running_order[0])); - memset(info->running_order, 0, info->node_count * sizeof(info->running_order[0])); + info->running_order = auto_alloc_array_clear(device->machine, node_description *, info->node_count); /* allocate memory to hold pointers to nodes by index */ - info->indexed_node = (node_description **)auto_malloc(DISCRETE_MAX_NODES * sizeof(info->indexed_node[0])); - memset(info->indexed_node, 0, DISCRETE_MAX_NODES * sizeof(info->indexed_node[0])); + info->indexed_node = auto_alloc_array_clear(device->machine, node_description *, DISCRETE_MAX_NODES); /* initialize the node data */ init_nodes(info, intf, device); @@ -605,10 +602,7 @@ static void init_nodes(discrete_info *info, discrete_sound_block *block_list, co /* allocate memory if necessary */ if (node->module.contextsize) - { - node->context = auto_malloc(node->module.contextsize); - memset(node->context, 0, node->module.contextsize); - } + node->context = auto_alloc_array_clear(device->machine, UINT8, node->module.contextsize); /* if we are an stream input node, track that */ if (block->type == DSS_INPUT_STREAM) diff --git a/src/emu/sound/dmadac.c b/src/emu/sound/dmadac.c index 1e0e64b068e..9367be43f80 100644 --- a/src/emu/sound/dmadac.c +++ b/src/emu/sound/dmadac.c @@ -106,8 +106,7 @@ static DEVICE_START( dmadac ) dmadac_state *info = get_safe_token(device); /* allocate a clear a buffer */ - info->buffer = (INT16 *)auto_malloc(sizeof(info->buffer[0]) * BUFFER_SIZE); - memset(info->buffer, 0, sizeof(info->buffer[0]) * BUFFER_SIZE); + info->buffer = auto_alloc_array_clear(device->machine, INT16, BUFFER_SIZE); /* reset the state */ info->volume = 0x100; diff --git a/src/emu/sound/es5506.c b/src/emu/sound/es5506.c index a3948c479b3..3d650a68dfb 100644 --- a/src/emu/sound/es5506.c +++ b/src/emu/sound/es5506.c @@ -194,7 +194,7 @@ static void compute_tables(es5506_state *chip) int i; /* allocate ulaw lookup table */ - chip->ulaw_lookup = (INT16 *)auto_malloc(sizeof(chip->ulaw_lookup[0]) << ULAW_MAXBITS); + chip->ulaw_lookup = auto_alloc_array(chip->device->machine, INT16, 1 << ULAW_MAXBITS); /* generate ulaw lookup table */ for (i = 0; i < (1 << ULAW_MAXBITS); i++) @@ -213,7 +213,7 @@ static void compute_tables(es5506_state *chip) } /* allocate volume lookup table */ - chip->volume_lookup = (UINT16 *)auto_malloc(sizeof(chip->volume_lookup[0]) * 4096); + chip->volume_lookup = auto_alloc_array(chip->device->machine, UINT16, 4096); /* generate ulaw lookup table */ for (i = 0; i < 4096; i++) @@ -842,9 +842,6 @@ static void es5506_start_common(const device_config *device, const void *config, if (LOG_COMMANDS && !eslog) eslog = fopen("es.log", "w"); - /* compute the tables */ - compute_tables(chip); - /* create the stream */ chip->stream = stream_create(device, 0, 2, device->clock / (16*32), chip, es5506_update); @@ -860,6 +857,9 @@ static void es5506_start_common(const device_config *device, const void *config, chip->irq_callback = intf->irq_callback; chip->irqv = 0x80; + /* compute the tables */ + compute_tables(chip); + /* init the voices */ accum_mask = (sndtype == SOUND_ES5506) ? 0xffffffff : 0x7fffffff; for (j = 0; j < 32; j++) @@ -873,7 +873,7 @@ static void es5506_start_common(const device_config *device, const void *config, } /* allocate memory */ - chip->scratch = (INT32 *)auto_malloc(sizeof(chip->scratch[0]) * 2 * MAX_SAMPLE_CHUNK); + chip->scratch = auto_alloc_array(device->machine, INT32, 2 * MAX_SAMPLE_CHUNK); /* success */ } diff --git a/src/emu/sound/filter.c b/src/emu/sound/filter.c index f59a1e8082d..2996f8a28e4 100644 --- a/src/emu/sound/filter.c +++ b/src/emu/sound/filter.c @@ -2,7 +2,7 @@ #include "filter.h" static filter* filter_alloc(void) { - filter* f = (filter *)malloc_or_die(sizeof(filter)); + filter* f = alloc_or_die(filter); return f; } @@ -20,7 +20,7 @@ void filter_state_reset(filter* f, filter_state* s) { filter_state* filter_state_alloc(void) { int i; - filter_state* s = (filter_state *)malloc_or_die(sizeof(filter_state)); + filter_state* s = alloc_or_die(filter_state); s->prev_mac = 0; for(i=0;i<FILTER_ORDER_MAX;++i) s->xprev[i] = 0; diff --git a/src/emu/sound/ics2115.c b/src/emu/sound/ics2115.c index e3257411b4e..ea217f60eeb 100644 --- a/src/emu/sound/ics2115.c +++ b/src/emu/sound/ics2115.c @@ -459,7 +459,7 @@ static DEVICE_START( ics2115 ) chip->rom = device->region; chip->timer[0].timer = timer_alloc(device->machine, timer_cb_0, chip); chip->timer[1].timer = timer_alloc(device->machine, timer_cb_1, chip); - chip->ulaw = (INT16 *)auto_malloc(256*sizeof(INT16)); + chip->ulaw = auto_alloc_array(device->machine, INT16, 256); chip->stream = stream_create(device, 0, 2, 33075, chip, update); for(i=0; i<256; i++) { diff --git a/src/emu/sound/k005289.c b/src/emu/sound/k005289.c index 5266041ca75..cb5acc9098f 100644 --- a/src/emu/sound/k005289.c +++ b/src/emu/sound/k005289.c @@ -71,14 +71,14 @@ INLINE k005289_state *get_safe_token(const device_config *device) } /* build a table to divide by the number of voices */ -static void make_mixer_table(k005289_state *info, int voices) +static void make_mixer_table(running_machine *machine, k005289_state *info, int voices) { int count = voices * 128; int i; int gain = 16; /* allocate memory */ - info->mixer_table = (INT16 *)auto_malloc(256 * voices * sizeof(INT16)); + info->mixer_table = auto_alloc_array(machine, INT16, 256 * voices); /* find the middle of the table */ info->mixer_lookup = info->mixer_table + (128 * voices); @@ -171,10 +171,10 @@ static DEVICE_START( k005289 ) info->mclock = device->clock; /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ - info->mixer_buffer = (short *)auto_malloc(2 * sizeof(short) * info->rate); + info->mixer_buffer = auto_alloc_array(device->machine, short, 2 * info->rate); /* build the mixer table */ - make_mixer_table(info, 2); + make_mixer_table(device->machine, info, 2); info->sound_prom = device->region; diff --git a/src/emu/sound/k051649.c b/src/emu/sound/k051649.c index 7ac4b9b4896..1f8ace78b32 100644 --- a/src/emu/sound/k051649.c +++ b/src/emu/sound/k051649.c @@ -65,14 +65,14 @@ INLINE k051649_state *get_safe_token(const device_config *device) } /* build a table to divide by the number of voices */ -static void make_mixer_table(k051649_state *info, int voices) +static void make_mixer_table(running_machine *machine, k051649_state *info, int voices) { int count = voices * 256; int i; int gain = 8; /* allocate memory */ - info->mixer_table = (INT16 *)auto_malloc(512 * voices * sizeof(INT16)); + info->mixer_table = auto_alloc_array(machine, INT16, 512 * voices); /* find the middle of the table */ info->mixer_lookup = info->mixer_table + (256 * voices); @@ -145,10 +145,10 @@ static DEVICE_START( k051649 ) info->mclock = device->clock; /* allocate a buffer to mix into - 1 second's worth should be more than enough */ - info->mixer_buffer = (short *)auto_malloc(2 * sizeof(short) * info->rate); + info->mixer_buffer = auto_alloc_array(device->machine, short, 2 * info->rate); /* build the mixer table */ - make_mixer_table(info, 5); + make_mixer_table(device->machine, info, 5); } static DEVICE_RESET( k051649 ) diff --git a/src/emu/sound/k053260.c b/src/emu/sound/k053260.c index d03b673d86b..fe721516fb7 100644 --- a/src/emu/sound/k053260.c +++ b/src/emu/sound/k053260.c @@ -233,7 +233,7 @@ static DEVICE_START( k053260 ) for ( i = 0; i < 0x30; i++ ) ic->regs[i] = 0; - ic->delta_table = ( UINT32 * )auto_malloc( 0x1000 * sizeof( UINT32 ) ); + ic->delta_table = auto_alloc_array( device->machine, UINT32, 0x1000 ); ic->channel = stream_create( device, 0, 2, rate, ic, k053260_update ); diff --git a/src/emu/sound/k054539.c b/src/emu/sound/k054539.c index d6025c62fbd..6707bfcdfdc 100644 --- a/src/emu/sound/k054539.c +++ b/src/emu/sound/k054539.c @@ -455,7 +455,7 @@ static void k054539_init_chip(const device_config *device, k054539_state *info) info->k054539_flags |= K054539_UPDATE_AT_KEYON; //* make it default until proven otherwise // Real size of 0x4000, the addon is to simplify the reverb buffer computations - info->ram = (unsigned char *)auto_malloc(0x4000*2+device->clock/50*2); + info->ram = auto_alloc_array(device->machine, unsigned char, 0x4000*2+device->clock/50*2); info->reverb_pos = 0; info->cur_ptr = 0; memset(info->ram, 0, 0x4000*2+device->clock/50*2); diff --git a/src/emu/sound/namco.c b/src/emu/sound/namco.c index 471b7f9de6e..3070b670080 100644 --- a/src/emu/sound/namco.c +++ b/src/emu/sound/namco.c @@ -117,7 +117,7 @@ static void update_namco_waveform(namco_sound *chip, int offset, UINT8 data) /* build the decoded waveform table */ -static void build_decoded_waveform(namco_sound *chip, UINT8 *rgnbase) +static void build_decoded_waveform(running_machine *machine, namco_sound *chip, UINT8 *rgnbase) { INT16 *p; int size; @@ -139,7 +139,7 @@ static void build_decoded_waveform(namco_sound *chip, UINT8 *rgnbase) size = 32 * 8; /* 32 samples, 8 waveforms */ } - p = (INT16 *)auto_malloc(size * MAX_VOLUME * sizeof (INT16)); + p = auto_alloc_array(machine, INT16, size * MAX_VOLUME); for (v = 0; v < MAX_VOLUME; v++) { @@ -388,7 +388,7 @@ static DEVICE_START( namco ) logerror("Namco: freq fractional bits = %d: internal freq = %d, output freq = %d\n", chip->f_fracbits, chip->namco_clock, chip->sample_rate); /* build the waveform table */ - build_decoded_waveform(chip, device->region); + build_decoded_waveform(device->machine, chip, device->region); /* get stream channels */ if (intf->stereo) diff --git a/src/emu/sound/psx.c b/src/emu/sound/psx.c index bd7ecdd5071..5cc70a5c55e 100644 --- a/src/emu/sound/psx.c +++ b/src/emu/sound/psx.c @@ -329,7 +329,7 @@ static DEVICE_START( psxspu ) chip->m_p_n_effect[ n_effect ] = 0; } - chip->m_p_n_spuram = (UINT16 *)auto_malloc( SPU_RAM_SIZE ); + chip->m_p_n_spuram = auto_alloc_array( device->machine, UINT16, SPU_RAM_SIZE/2 ); state_save_register_device_item( device, 0, chip->m_n_mainvolumeleft ); state_save_register_device_item( device, 0, chip->m_n_mainvolumeright ); diff --git a/src/emu/sound/samples.c b/src/emu/sound/samples.c index 22174b7699a..56b2b86be17 100644 --- a/src/emu/sound/samples.c +++ b/src/emu/sound/samples.c @@ -25,7 +25,7 @@ struct _samples_info const device_config *device; int numchannels; /* how many channels */ sample_channel *channel;/* array of channels */ - struct loaded_samples *samples;/* array of samples */ + loaded_samples *samples;/* array of samples */ }; @@ -50,7 +50,7 @@ INLINE samples_info *get_safe_token(const device_config *device) read_wav_sample - read a WAV file as a sample -------------------------------------------------*/ -static int read_wav_sample(mame_file *f, struct loaded_sample *sample) +static int read_wav_sample(running_machine *machine, mame_file *f, loaded_sample *sample) { unsigned long offset = 0; UINT32 length, rate, filesize; @@ -153,7 +153,7 @@ static int read_wav_sample(mame_file *f, struct loaded_sample *sample) unsigned char *tempptr; int sindex; - sample->data = (INT16 *)auto_malloc(sizeof(*sample->data) * length); + sample->data = auto_alloc_array(machine, INT16, length); mame_fread(f, sample->data, length); /* convert 8-bit data to signed samples */ @@ -164,7 +164,7 @@ static int read_wav_sample(mame_file *f, struct loaded_sample *sample) else { /* 16-bit data is fine as-is */ - sample->data = (INT16 *)auto_malloc(sizeof(*sample->data) * (length/2)); + sample->data = auto_alloc_array(machine, INT16, length/2); mame_fread(f, sample->data, length); sample->length /= 2; if (ENDIANNESS_NATIVE != ENDIANNESS_LITTLE) @@ -179,9 +179,9 @@ static int read_wav_sample(mame_file *f, struct loaded_sample *sample) readsamples - load all samples -------------------------------------------------*/ -struct loaded_samples *readsamples(const char *const *samplenames, const char *basename) +loaded_samples *readsamples(running_machine *machine, const char *const *samplenames, const char *basename) { - struct loaded_samples *samples; + loaded_samples *samples; int skipfirst = 0; int i; @@ -201,8 +201,7 @@ struct loaded_samples *readsamples(const char *const *samplenames, const char *b return NULL; /* allocate the array */ - samples = (struct loaded_samples *)auto_malloc(sizeof(struct loaded_samples) + (i-1) * sizeof(struct loaded_sample)); - memset(samples, 0, sizeof(struct loaded_samples) + (i-1) * sizeof(struct loaded_sample)); + samples = (loaded_samples *)auto_alloc_array_clear(machine, UINT8, sizeof(loaded_samples) + (i-1) * sizeof(loaded_sample)); samples->total = i; /* load the samples */ @@ -223,7 +222,7 @@ struct loaded_samples *readsamples(const char *const *samplenames, const char *b } if (filerr == FILERR_NONE) { - read_wav_sample(f, &samples->sample[i]); + read_wav_sample(machine, f, &samples->sample[i]); mame_fclose(f); } @@ -243,7 +242,7 @@ void sample_start(const device_config *device,int channel,int samplenum,int loop { samples_info *info = get_safe_token(device); sample_channel *chan; - struct loaded_sample *sample; + loaded_sample *sample; /* if samples are disabled, just return quietly */ if (info->samples == NULL) @@ -450,7 +449,7 @@ static STATE_POSTLOAD( samples_postload ) /* attach any samples that were loaded and playing */ if (chan->source_num >= 0 && chan->source_num < info->samples->total) { - struct loaded_sample *sample = &info->samples->sample[chan->source_num]; + loaded_sample *sample = &info->samples->sample[chan->source_num]; chan->source = sample->data; chan->source_length = sample->length; if (!sample->data) @@ -482,12 +481,12 @@ static DEVICE_START( samples ) /* read audio samples */ if (intf->samplenames) - info->samples = readsamples(intf->samplenames,device->machine->gamedrv->name); + info->samples = readsamples(device->machine, intf->samplenames,device->machine->gamedrv->name); /* allocate channels */ info->numchannels = intf->channels; assert(info->numchannels < MAX_CHANNELS); - info->channel = (sample_channel *)auto_malloc(sizeof(*info->channel) * info->numchannels); + info->channel = auto_alloc_array(device->machine, sample_channel, info->numchannels); for (i = 0; i < info->numchannels; i++) { info->channel[i].stream = stream_create(device, 0, 1, device->machine->sample_rate, &info->channel[i], sample_update_sound); diff --git a/src/emu/sound/samples.h b/src/emu/sound/samples.h index ff8e3fa0911..27c52fe0832 100644 --- a/src/emu/sound/samples.h +++ b/src/emu/sound/samples.h @@ -3,17 +3,19 @@ #ifndef __SAMPLES_H__ #define __SAMPLES_H__ -struct loaded_sample +typedef struct _loaded_sample loaded_sample; +struct _loaded_sample { int length; /* length in samples */ int frequency; /* frequency of the sample */ INT16 * data; /* 16-bit signed data */ }; -struct loaded_samples +typedef struct _loaded_samples loaded_samples; +struct _loaded_samples { int total; /* number of samples */ - struct loaded_sample sample[1]; /* array of samples */ + loaded_sample sample[1]; /* array of samples */ }; typedef struct _samples_interface samples_interface; @@ -38,7 +40,7 @@ int sample_playing(const device_config *device,int channel); /* helper function that reads samples from disk - this can be used by other */ /* drivers as well (e.g. a sound chip emulator needing drum samples) */ -struct loaded_samples *readsamples(const char *const *samplenames, const char *name); +loaded_samples *readsamples(running_machine *machine, const char *const *samplenames, const char *name); DEVICE_GET_INFO( samples ); #define SOUND_SAMPLES DEVICE_GET_INFO_NAME( samples ) diff --git a/src/emu/sound/scsp.c b/src/emu/sound/scsp.c index 892bdd4e528..67c07770925 100644 --- a/src/emu/sound/scsp.c +++ b/src/emu/sound/scsp.c @@ -648,10 +648,8 @@ static void SCSP_Init(const device_config *device, struct _SCSP *SCSP, const scs } LFO_Init(device->machine); - SCSP->buffertmpl=(signed int*) auto_malloc(44100*sizeof(signed int)); - SCSP->buffertmpr=(signed int*) auto_malloc(44100*sizeof(signed int)); - memset(SCSP->buffertmpl,0,44100*sizeof(signed int)); - memset(SCSP->buffertmpr,0,44100*sizeof(signed int)); + SCSP->buffertmpl=auto_alloc_array_clear(device->machine, signed int, 44100); + SCSP->buffertmpr=auto_alloc_array_clear(device->machine, signed int, 44100); // no "pend" SCSP[0].udata.data[0x20/2] = 0; diff --git a/src/emu/sound/segapcm.c b/src/emu/sound/segapcm.c index 6413a5e6fde..2999e72c733 100644 --- a/src/emu/sound/segapcm.c +++ b/src/emu/sound/segapcm.c @@ -93,7 +93,7 @@ static DEVICE_START( segapcm ) segapcm_state *spcm = get_safe_token(device); spcm->rom = (const UINT8 *)device->region; - spcm->ram = (UINT8 *)auto_malloc(0x800); + spcm->ram = auto_alloc_array(device->machine, UINT8, 0x800); memset(spcm->ram, 0xff, 0x800); diff --git a/src/emu/sound/sid.c b/src/emu/sound/sid.c index 887f3f4f302..01221310efa 100644 --- a/src/emu/sound/sid.c +++ b/src/emu/sound/sid.c @@ -166,8 +166,8 @@ static void filterTableInit(running_machine *machine) float resDyMin; float resDy; - filterTable = auto_malloc(sizeof(*filterTable) * 0x800); - bandPassParam = auto_malloc(sizeof(*bandPassParam) * 0x800); + filterTable = auto_alloc_array(machine, float, 0x800); + bandPassParam = auto_alloc_array(machine, float, 0x800); uk = 0; for ( rk = 0; rk < 0x800; rk++ ) @@ -233,7 +233,7 @@ void sid6581_init (SID6581 *This) This->filter.Enabled = TRUE; - sidInitMixerEngine(); + sidInitMixerEngine(This->device->machine); filterTableInit(This->device->machine); sidInitWaveformTables(This->type); diff --git a/src/emu/sound/sidvoice.c b/src/emu/sound/sidvoice.c index 3ee758e84ab..64b2f8df0a2 100644 --- a/src/emu/sound/sidvoice.c +++ b/src/emu/sound/sidvoice.c @@ -26,7 +26,7 @@ static INT8* ampMod1x8; static const UINT32 noiseSeed = 0x7ffff8; -void sidInitMixerEngine(void) +void sidInitMixerEngine(running_machine *machine) { UINT16 uk; INT32 si, sj ; @@ -34,7 +34,7 @@ void sidInitMixerEngine(void) /* 8-bit volume modulation tables. */ float filterAmpl = 0.7f; - ampMod1x8=(INT8*) auto_malloc(256*256); + ampMod1x8=auto_alloc_array(machine, INT8, 256*256); uk = 0; for ( si = 0; si < 256; si++ ) diff --git a/src/emu/sound/sidvoice.h b/src/emu/sound/sidvoice.h index d3f788afe76..81241196275 100644 --- a/src/emu/sound/sidvoice.h +++ b/src/emu/sound/sidvoice.h @@ -107,7 +107,7 @@ void sidEmuSet2(sidOperator* pVoice); INT8 sidWaveCalcNormal(sidOperator* pVoice); void sidInitWaveformTables(SIDTYPE type); -void sidInitMixerEngine(void); +void sidInitMixerEngine(running_machine *machine); #if 0 extern ptr2sidVoidFunc sid6581ModeNormalTable[16]; diff --git a/src/emu/sound/sp0256.c b/src/emu/sound/sp0256.c index 11011cbe598..59137e34a27 100644 --- a/src/emu/sound/sp0256.c +++ b/src/emu/sound/sp0256.c @@ -1201,7 +1201,7 @@ static DEVICE_START( sp0256 ) /* -------------------------------------------------------------------- */ /* Allocate a scratch buffer for generating ~10kHz samples. */ /* -------------------------------------------------------------------- */ - sp->scratch = (INT16 *)malloc_or_die(SCBUF_SIZE * sizeof(INT16)); + sp->scratch = auto_alloc_array(device->machine, INT16, SCBUF_SIZE); sp->sc_head = sp->sc_tail = 0; /* -------------------------------------------------------------------- */ @@ -1220,12 +1220,6 @@ static DEVICE_START( sp0256 ) sp0256_bitrevbuff(sp->rom, 0, 0xffff); } -static DEVICE_STOP( sp0256 ) -{ - sp0256_state *sp = get_safe_token(device); - free( sp->scratch ); -} - static void sp0256_reset(sp0256_state *sp) { /* ---------------------------------------------------------------- */ @@ -1364,7 +1358,6 @@ DEVICE_GET_INFO( sp0256 ) /* --- the following bits of info are returned as pointers to data or functions --- */ case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( sp0256 ); break; - case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME( sp0256 ); break; case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( sp0256 ); break; /* --- the following bits of info are returned as NULL-terminated strings --- */ diff --git a/src/emu/sound/tms5110.c b/src/emu/sound/tms5110.c index 9adf77d6faa..bc30a852e02 100644 --- a/src/emu/sound/tms5110.c +++ b/src/emu/sound/tms5110.c @@ -181,8 +181,7 @@ void *tms5110_create(const device_config *device, int variant) { struct tms5110 *tms; - tms = (struct tms5110 *)malloc_or_die(sizeof(*tms)); - memset(tms, 0, sizeof(*tms)); + tms = alloc_clear_or_die(struct tms5110); tms->device = device; tms5110_set_variant(tms, variant); diff --git a/src/emu/sound/tms5220.c b/src/emu/sound/tms5220.c index d00d5f5bacd..e19333fa3b8 100644 --- a/src/emu/sound/tms5220.c +++ b/src/emu/sound/tms5220.c @@ -179,8 +179,7 @@ void *tms5220_create(const device_config *device) { struct tms5220 *tms; - tms = (struct tms5220 *)malloc_or_die(sizeof(*tms)); - memset(tms, 0, sizeof(*tms)); + tms = alloc_clear_or_die(struct tms5220); tms->device = device; state_save_register_device_item_array(device, 0, tms->fifo); diff --git a/src/emu/sound/votrax.c b/src/emu/sound/votrax.c index 299e1ee5fd9..a63cc45f92e 100644 --- a/src/emu/sound/votrax.c +++ b/src/emu/sound/votrax.c @@ -30,7 +30,7 @@ struct _votrax_state int volume; sound_stream * channel; - struct loaded_sample *sample; + loaded_sample *sample; UINT32 pos; UINT32 frac; UINT32 step; @@ -116,7 +116,7 @@ static DEVICE_START( votrax ) votrax_state *votrax = get_safe_token(device); votrax->device = device; - votrax->samples = readsamples(VotraxTable,"votrax"); + votrax->samples = readsamples(device->machine,VotraxTable,"votrax"); votrax->frequency = 8000; votrax->volume = 230; diff --git a/src/emu/sound/ymf271.c b/src/emu/sound/ymf271.c index bf7ec832c54..6372b032b4f 100644 --- a/src/emu/sound/ymf271.c +++ b/src/emu/sound/ymf271.c @@ -1568,13 +1568,13 @@ READ8_DEVICE_HANDLER( ymf271_r ) return 0; } -static void init_tables(void) +static void init_tables(running_machine *machine) { int i,j; for (i=0; i < ARRAY_LENGTH(wavetable); i++) { - wavetable[i] = (INT16 *)auto_malloc(SIN_LEN * sizeof(INT16)); + wavetable[i] = auto_alloc_array(machine, INT16, SIN_LEN); } for (i=0; i < SIN_LEN; i++) @@ -1652,7 +1652,7 @@ static void init_tables(void) alfo_table[3][i] = (i < (LFO_LENGTH/2)) ? ALFO_MAX-tri_wave : tri_wave; } - mix = (INT32 *)auto_malloc(48000*2*sizeof(*mix)); + mix = auto_alloc_array(machine, INT32, 48000*2); } static void init_state(YMF271Chip *chip, const device_config *device) @@ -1741,7 +1741,7 @@ static void ymf271_init(const device_config *device, YMF271Chip *chip, UINT8 *ro devcb_resolve_read8(&chip->ext_mem_read, ext_read, device); devcb_resolve_write8(&chip->ext_mem_write, ext_write, device); - init_tables(); + init_tables(device->machine); init_state(chip, device); } diff --git a/src/emu/sound/ymf278b.c b/src/emu/sound/ymf278b.c index 76dbac1820d..00939c8762b 100644 --- a/src/emu/sound/ymf278b.c +++ b/src/emu/sound/ymf278b.c @@ -676,7 +676,7 @@ static void ymf278b_init(const device_config *device, YMF278BChip *chip, void (* chip->irq_line = CLEAR_LINE; chip->clock = device->clock; - mix = (INT32 *)auto_malloc(44100*2*sizeof(*mix)); + mix = auto_alloc_array(device->machine, INT32, 44100*2); } static DEVICE_START( ymf278b ) diff --git a/src/emu/sound/ymz280b.c b/src/emu/sound/ymz280b.c index 40750d9be5a..360b3aac8de 100644 --- a/src/emu/sound/ymz280b.c +++ b/src/emu/sound/ymz280b.c @@ -659,7 +659,7 @@ static DEVICE_START( ymz280b ) chip->stream = stream_create(device, 0, 2, INTERNAL_SAMPLE_RATE, chip, ymz280b_update); /* allocate memory */ - chip->scratch = (INT16 *)auto_malloc(sizeof(chip->scratch[0]) * MAX_SAMPLE_CHUNK); + chip->scratch = auto_alloc_array(device->machine, INT16, MAX_SAMPLE_CHUNK); /* state save */ { diff --git a/src/emu/state.c b/src/emu/state.c index cf7a82f07ed..1c408a4e0b8 100644 --- a/src/emu/state.c +++ b/src/emu/state.c @@ -165,8 +165,7 @@ INLINE void flip_data(state_entry *entry) void state_init(running_machine *machine) { - machine->state_data = (state_private *)auto_malloc(sizeof(*machine->state_data)); - memset(machine->state_data, 0, sizeof(*machine->state_data)); + machine->state_data = auto_alloc_clear(machine, state_private); } @@ -264,8 +263,7 @@ void state_save_register_memory(running_machine *machine, const char *module, co /* didn't find one; allocate a new one */ next = *entryptr; - *entryptr = (state_entry *)malloc_or_die(sizeof(**entryptr)); - memset(*entryptr, 0, sizeof(**entryptr)); + *entryptr = alloc_clear_or_die(state_entry); /* fill in the rest */ (*entryptr)->next = next; @@ -314,7 +312,7 @@ void state_save_register_presave(running_machine *machine, state_presave_func fu fatalerror("Duplicate save state function (%p, %p)", param, func); /* allocate a new entry */ - *cbptr = (state_callback *)malloc_or_die(sizeof(state_callback)); + *cbptr = alloc_or_die(state_callback); /* fill it in */ (*cbptr)->next = NULL; @@ -345,7 +343,7 @@ void state_save_register_postload(running_machine *machine, state_postload_func fatalerror("Duplicate save state function (%p, %p)", param, func); /* allocate a new entry */ - *cbptr = (state_callback *)malloc_or_die(sizeof(state_callback)); + *cbptr = alloc_or_die(state_callback); /* fill it in */ (*cbptr)->next = NULL; diff --git a/src/emu/streams.c b/src/emu/streams.c index 829cbed2a51..66efcc49fa0 100644 --- a/src/emu/streams.c +++ b/src/emu/streams.c @@ -165,9 +165,9 @@ struct _streams_private ***************************************************************************/ static STATE_POSTLOAD( stream_postload ); -static void allocate_resample_buffers(streams_private *strdata, sound_stream *stream); -static void allocate_output_buffers(streams_private *strdata, sound_stream *stream); -static void recompute_sample_rate_data(streams_private *strdata, sound_stream *stream); +static void allocate_resample_buffers(running_machine *machine, sound_stream *stream); +static void allocate_output_buffers(running_machine *machine, sound_stream *stream); +static void recompute_sample_rate_data(running_machine *machine, sound_stream *stream); static void generate_samples(sound_stream *stream, int samples); static stream_sample_t *generate_resampled_data(stream_input *input, UINT32 numsamples); @@ -218,8 +218,7 @@ void streams_init(running_machine *machine) streams_private *strdata; /* allocate memory for our private data */ - strdata = (streams_private *)auto_malloc(sizeof(*strdata)); - memset(strdata, 0, sizeof(*strdata)); + strdata = auto_alloc_clear(machine, streams_private); /* reset globals */ strdata->stream_tailptr = &strdata->stream_head; @@ -311,7 +310,7 @@ void streams_update(running_machine *machine) stream->new_sample_rate = 0; /* recompute all the data */ - recompute_sample_rate_data(strdata, stream); + recompute_sample_rate_data(machine, stream); /* reset our sample indexes to the current time */ stream->output_sampindex = (INT64)stream->output_sampindex * (INT64)stream->sample_rate / old_rate; @@ -343,8 +342,7 @@ sound_stream *stream_create(const device_config *device, int inputs, int outputs char statetag[30]; /* allocate memory */ - stream = (sound_stream *)auto_malloc(sizeof(*stream)); - memset(stream, 0, sizeof(*stream)); + stream = auto_alloc_clear(device->machine, sound_stream); VPRINTF(("stream_create(%d, %d, %d) => %p\n", inputs, outputs, sample_rate, stream)); @@ -365,10 +363,8 @@ sound_stream *stream_create(const device_config *device, int inputs, int outputs /* allocate space for the inputs */ if (inputs > 0) { - stream->input = (stream_input *)auto_malloc(inputs * sizeof(*stream->input)); - memset(stream->input, 0, inputs * sizeof(*stream->input)); - stream->input_array = (stream_sample_t **)auto_malloc(inputs * sizeof(*stream->input_array)); - memset(stream->input_array, 0, inputs * sizeof(*stream->input_array)); + stream->input = auto_alloc_array_clear(device->machine, stream_input, inputs); + stream->input_array = auto_alloc_array_clear(device->machine, stream_sample_t *, inputs); } /* initialize the state of each input */ @@ -382,10 +378,8 @@ sound_stream *stream_create(const device_config *device, int inputs, int outputs /* allocate space for the outputs */ if (outputs > 0) { - stream->output = (stream_output *)auto_malloc(outputs * sizeof(*stream->output)); - memset(stream->output, 0, outputs * sizeof(*stream->output)); - stream->output_array = (stream_sample_t **)auto_malloc(outputs * sizeof(*stream->output_array)); - memset(stream->output_array, 0, outputs * sizeof(*stream->output_array)); + stream->output = auto_alloc_array_clear(device->machine, stream_output, outputs); + stream->output_array = auto_alloc_array_clear(device->machine, stream_sample_t *, outputs); } /* initialize the state of each output */ @@ -402,7 +396,7 @@ sound_stream *stream_create(const device_config *device, int inputs, int outputs /* force an update to the sample rates; this will cause everything to be recomputed and will generate the initial resample buffers for our inputs */ - recompute_sample_rate_data(strdata, stream); + recompute_sample_rate_data(device->machine, stream); /* set up the initial output buffer positions now that we have data */ stream->output_base_sampindex = -stream->max_samples_per_update; @@ -497,7 +491,7 @@ void stream_set_input(sound_stream *stream, int index, sound_stream *input_strea input->source->dependents++; /* update sample rates now that we know the input */ - recompute_sample_rate_data(stream->device->machine->streams_data, stream); + recompute_sample_rate_data(stream->device->machine, stream); } @@ -702,7 +696,7 @@ static STATE_POSTLOAD( stream_postload ) int outputnum; /* recompute the same rate information */ - recompute_sample_rate_data(strdata, stream); + recompute_sample_rate_data(machine, stream); /* make sure our output buffers are fully cleared */ for (outputnum = 0; outputnum < stream->outputs; outputnum++) @@ -720,7 +714,7 @@ static STATE_POSTLOAD( stream_postload ) resample buffer sizes and expand if necessary -------------------------------------------------*/ -static void allocate_resample_buffers(streams_private *strdata, sound_stream *stream) +static void allocate_resample_buffers(running_machine *machine, sound_stream *stream) { /* compute the target number of samples */ INT32 bufsize = 2 * stream->max_samples_per_update; @@ -737,7 +731,7 @@ static void allocate_resample_buffers(streams_private *strdata, sound_stream *st for (inputnum = 0; inputnum < stream->inputs; inputnum++) { stream_input *input = &stream->input[inputnum]; - input->resample = (stream_sample_t *)auto_realloc(input->resample, stream->resample_bufalloc * sizeof(input->resample[0])); + input->resample = auto_extend_array(machine, input->resample, stream_sample_t, stream->resample_bufalloc); } } } @@ -748,7 +742,7 @@ static void allocate_resample_buffers(streams_private *strdata, sound_stream *st output buffer sizes and expand if necessary -------------------------------------------------*/ -static void allocate_output_buffers(streams_private *strdata, sound_stream *stream) +static void allocate_output_buffers(running_machine *machine, sound_stream *stream) { /* compute the target number of samples */ INT32 bufsize = OUTPUT_BUFFER_UPDATES * stream->max_samples_per_update; @@ -767,7 +761,7 @@ static void allocate_output_buffers(streams_private *strdata, sound_stream *stre for (outputnum = 0; outputnum < stream->outputs; outputnum++) { stream_output *output = &stream->output[outputnum]; - output->buffer = (stream_sample_t *)auto_realloc(output->buffer, stream->output_bufalloc * sizeof(output->buffer[0])); + 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])); } } @@ -780,8 +774,9 @@ static void allocate_output_buffers(streams_private *strdata, sound_stream *stre by this stream -------------------------------------------------*/ -static void recompute_sample_rate_data(streams_private *strdata, sound_stream *stream) +static void recompute_sample_rate_data(running_machine *machine, sound_stream *stream) { + streams_private *strdata = machine->streams_data; int inputnum; /* recompute the timing parameters */ @@ -789,8 +784,8 @@ static void recompute_sample_rate_data(streams_private *strdata, sound_stream *s stream->max_samples_per_update = (strdata->update_attoseconds + stream->attoseconds_per_sample - 1) / stream->attoseconds_per_sample; /* update resample and output buffer sizes */ - allocate_resample_buffers(strdata, stream); - allocate_output_buffers(strdata, stream); + allocate_resample_buffers(machine, stream); + allocate_output_buffers(machine, stream); /* iterate over each input */ for (inputnum = 0; inputnum < stream->inputs; inputnum++) diff --git a/src/emu/tilemap.c b/src/emu/tilemap.c index f776e6b2501..71c9cb334bf 100644 --- a/src/emu/tilemap.c +++ b/src/emu/tilemap.c @@ -303,7 +303,7 @@ void tilemap_init(running_machine *machine) tilemap_tailptr = &tilemap_list; tilemap_instance = 0; - priority_bitmap = auto_bitmap_alloc(screen_width, screen_height, BITMAP_FORMAT_INDEXED8); + priority_bitmap = auto_bitmap_alloc(machine, screen_width, screen_height, BITMAP_FORMAT_INDEXED8); add_exit_callback(machine, tilemap_exit); } } @@ -324,8 +324,7 @@ tilemap *tilemap_create(running_machine *machine, tile_get_info_func tile_get_in int group; /* allocate the tilemap itself */ - tmap = (tilemap *)malloc_or_die(sizeof(*tmap)); - memset(tmap, 0, sizeof(*tmap)); + tmap = alloc_clear_or_die(tilemap); /* fill in the basic metrics */ tmap->machine = machine; @@ -354,19 +353,16 @@ tilemap *tilemap_create(running_machine *machine, tile_get_info_func tile_get_in /* initialize scroll information */ tmap->scrollrows = 1; tmap->scrollcols = 1; - tmap->rowscroll = (INT32 *)malloc_or_die(tmap->height * sizeof(*tmap->rowscroll)); - memset(tmap->rowscroll, 0, tmap->height * sizeof(*tmap->rowscroll)); - tmap->colscroll = (INT32 *)malloc_or_die(tmap->width * sizeof(*tmap->colscroll)); - memset(tmap->colscroll, 0, tmap->width * sizeof(*tmap->colscroll)); + tmap->rowscroll = alloc_array_clear_or_die(INT32, tmap->height); + tmap->colscroll = alloc_array_clear_or_die(INT32, tmap->width); /* allocate the pixel data cache */ tmap->pixmap = bitmap_alloc(tmap->width, tmap->height, BITMAP_FORMAT_INDEXED16); /* allocate transparency mapping data */ - tmap->tileflags = (UINT8 *)malloc_or_die(tmap->max_logical_index); + 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 = (UINT8 *)malloc_or_die(sizeof(tmap->pen_to_flags[0]) * MAX_PEN_TO_FLAGS * TILEMAP_NUM_GROUPS); - memset(tmap->pen_to_flags, 0, sizeof(tmap->pen_to_flags[0]) * MAX_PEN_TO_FLAGS * TILEMAP_NUM_GROUPS); + tmap->pen_to_flags = alloc_array_clear_or_die(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); @@ -1157,8 +1153,8 @@ static void mappings_create(tilemap *tmap) tmap->max_memory_index++; /* allocate the necessary mappings */ - tmap->memory_to_logical = (tilemap_logical_index *)malloc_or_die(tmap->max_memory_index * sizeof(*tmap->memory_to_logical)); - tmap->logical_to_memory = (tilemap_memory_index *)malloc_or_die(tmap->max_logical_index * sizeof(*tmap->logical_to_memory)); + 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); /* update the mappings */ mappings_update(tmap); diff --git a/src/emu/timer.c b/src/emu/timer.c index f2422276a3a..62080cacfe8 100644 --- a/src/emu/timer.c +++ b/src/emu/timer.c @@ -300,8 +300,7 @@ void timer_init(running_machine *machine) int i; /* allocate global data */ - global = machine->timer_data = (timer_private *)auto_malloc(sizeof(*global)); - memset(global, 0, sizeof(*global)); + global = machine->timer_data = auto_alloc_clear(machine, timer_private); /* we need to wait until the first call to timer_cyclestorun before using real CPU times */ global->exec.basetime = attotime_zero; diff --git a/src/emu/ui.c b/src/emu/ui.c index c6bad41f5f1..bafc859e1c8 100644 --- a/src/emu/ui.c +++ b/src/emu/ui.c @@ -97,7 +97,7 @@ static UINT32 handler_ingame(running_machine *machine, UINT32 state); static UINT32 handler_load_save(running_machine *machine, UINT32 state); /* slider controls */ -static slider_state *slider_alloc(const char *title, INT32 minval, INT32 defval, INT32 maxval, INT32 incval, slider_update update, void *arg); +static slider_state *slider_alloc(running_machine *machine, const char *title, INT32 minval, INT32 defval, INT32 maxval, INT32 incval, slider_update update, void *arg); static slider_state *slider_init(running_machine *machine); static INT32 slider_volume(running_machine *machine, void *arg, astring *string, INT32 newval); static INT32 slider_mixervol(running_machine *machine, void *arg, astring *string, INT32 newval); @@ -1390,11 +1390,10 @@ const slider_state *ui_get_slider_list(void) slider_alloc - allocate a new slider entry -------------------------------------------------*/ -static slider_state *slider_alloc(const char *title, INT32 minval, INT32 defval, INT32 maxval, INT32 incval, slider_update update, void *arg) +static slider_state *slider_alloc(running_machine *machine, const char *title, INT32 minval, INT32 defval, INT32 maxval, INT32 incval, slider_update update, void *arg) { int size = sizeof(slider_state) + strlen(title); - slider_state *state = (slider_state *)auto_malloc(size); - memset(state, 0, size); + slider_state *state = (slider_state *)auto_alloc_array_clear(machine, UINT8, size); state->minval = minval; state->defval = defval; @@ -1424,7 +1423,7 @@ static slider_state *slider_init(running_machine *machine) int numitems, item; /* add overall volume */ - *tailptr = slider_alloc("Master Volume", -32, 0, 0, 1, slider_volume, NULL); + *tailptr = slider_alloc(machine, "Master Volume", -32, 0, 0, 1, slider_volume, NULL); tailptr = &(*tailptr)->next; /* add per-channel volume */ @@ -1438,7 +1437,7 @@ static slider_state *slider_init(running_machine *machine) maxval = 2 * defval; astring_printf(string, "%s Volume", sound_get_user_gain_name(machine, item)); - *tailptr = slider_alloc(astring_c(string), 0, defval, maxval, 20, slider_mixervol, (void *)(FPTR)item); + *tailptr = slider_alloc(machine, astring_c(string), 0, defval, maxval, 20, slider_mixervol, (void *)(FPTR)item); tailptr = &(*tailptr)->next; } @@ -1448,7 +1447,7 @@ static slider_state *slider_init(running_machine *machine) if (field->type == IPT_ADJUSTER) { void *param = (void *)field; - *tailptr = slider_alloc(field->name, 0, field->defvalue, 100, 1, slider_adjuster, param); + *tailptr = slider_alloc(machine, field->name, 0, field->defvalue, 100, 1, slider_adjuster, param); tailptr = &(*tailptr)->next; } @@ -1459,7 +1458,7 @@ static slider_state *slider_init(running_machine *machine) if (machine->cpu[item] != NULL) { astring_printf(string, "Overclock CPU %s", machine->cpu[item]->tag); - *tailptr = slider_alloc(astring_c(string), 10, 1000, 2000, 1, slider_overclock, (void *)(FPTR)item); + *tailptr = slider_alloc(machine, astring_c(string), 10, 1000, 2000, 1, slider_overclock, (void *)(FPTR)item); tailptr = &(*tailptr)->next; } } @@ -1478,33 +1477,33 @@ static slider_state *slider_init(running_machine *machine) if (options_get_bool(mame_options(), OPTION_CHEAT)) { astring_printf(string, "%s Refresh Rate", slider_get_screen_desc(device)); - *tailptr = slider_alloc(astring_c(string), -10000, 0, 10000, 1000, slider_refresh, param); + *tailptr = slider_alloc(machine, astring_c(string), -10000, 0, 10000, 1000, slider_refresh, param); tailptr = &(*tailptr)->next; } /* add standard brightness/contrast/gamma controls per-screen */ astring_printf(string, "%s Brightness", slider_get_screen_desc(device)); - *tailptr = slider_alloc(astring_c(string), 100, 1000, 2000, 10, slider_brightness, param); + *tailptr = slider_alloc(machine, astring_c(string), 100, 1000, 2000, 10, slider_brightness, param); tailptr = &(*tailptr)->next; astring_printf(string, "%s Contrast", slider_get_screen_desc(device)); - *tailptr = slider_alloc(astring_c(string), 100, 1000, 2000, 50, slider_contrast, param); + *tailptr = slider_alloc(machine, astring_c(string), 100, 1000, 2000, 50, slider_contrast, param); tailptr = &(*tailptr)->next; astring_printf(string, "%s Gamma", slider_get_screen_desc(device)); - *tailptr = slider_alloc(astring_c(string), 100, 1000, 3000, 50, slider_gamma, param); + *tailptr = slider_alloc(machine, astring_c(string), 100, 1000, 3000, 50, slider_gamma, param); tailptr = &(*tailptr)->next; /* add scale and offset controls per-screen */ astring_printf(string, "%s Horiz Stretch", slider_get_screen_desc(device)); - *tailptr = slider_alloc(astring_c(string), 500, (defxscale == 0) ? 1000 : defxscale, 1500, 2, slider_xscale, param); + *tailptr = slider_alloc(machine, astring_c(string), 500, (defxscale == 0) ? 1000 : defxscale, 1500, 2, slider_xscale, param); tailptr = &(*tailptr)->next; astring_printf(string, "%s Horiz Position", slider_get_screen_desc(device)); - *tailptr = slider_alloc(astring_c(string), -500, defxoffset, 500, 2, slider_xoffset, param); + *tailptr = slider_alloc(machine, astring_c(string), -500, defxoffset, 500, 2, slider_xoffset, param); tailptr = &(*tailptr)->next; astring_printf(string, "%s Vert Stretch", slider_get_screen_desc(device)); - *tailptr = slider_alloc(astring_c(string), 500, (defyscale == 0) ? 1000 : defyscale, 1500, 2, slider_yscale, param); + *tailptr = slider_alloc(machine, astring_c(string), 500, (defyscale == 0) ? 1000 : defyscale, 1500, 2, slider_yscale, param); tailptr = &(*tailptr)->next; astring_printf(string, "%s Vert Position", slider_get_screen_desc(device)); - *tailptr = slider_alloc(astring_c(string), -500, defyoffset, 500, 2, slider_yoffset, param); + *tailptr = slider_alloc(machine, astring_c(string), -500, defyoffset, 500, 2, slider_yoffset, param); tailptr = &(*tailptr)->next; } @@ -1521,16 +1520,16 @@ static slider_state *slider_init(running_machine *machine) /* add scale and offset controls per-overlay */ astring_printf(string, "%s Horiz Stretch", slider_get_laserdisc_desc(device)); - *tailptr = slider_alloc(astring_c(string), 500, (defxscale == 0) ? 1000 : defxscale, 1500, 2, slider_overxscale, param); + *tailptr = slider_alloc(machine, astring_c(string), 500, (defxscale == 0) ? 1000 : defxscale, 1500, 2, slider_overxscale, param); tailptr = &(*tailptr)->next; astring_printf(string, "%s Horiz Position", slider_get_laserdisc_desc(device)); - *tailptr = slider_alloc(astring_c(string), -500, defxoffset, 500, 2, slider_overxoffset, param); + *tailptr = slider_alloc(machine, astring_c(string), -500, defxoffset, 500, 2, slider_overxoffset, param); tailptr = &(*tailptr)->next; astring_printf(string, "%s Vert Stretch", slider_get_laserdisc_desc(device)); - *tailptr = slider_alloc(astring_c(string), 500, (defyscale == 0) ? 1000 : defyscale, 1500, 2, slider_overyscale, param); + *tailptr = slider_alloc(machine, astring_c(string), 500, (defyscale == 0) ? 1000 : defyscale, 1500, 2, slider_overyscale, param); tailptr = &(*tailptr)->next; astring_printf(string, "%s Vert Position", slider_get_laserdisc_desc(device)); - *tailptr = slider_alloc(astring_c(string), -500, defyoffset, 500, 2, slider_overyoffset, param); + *tailptr = slider_alloc(machine, astring_c(string), -500, defyoffset, 500, 2, slider_overyoffset, param); tailptr = &(*tailptr)->next; } } @@ -1541,9 +1540,9 @@ static slider_state *slider_init(running_machine *machine) if (scrconfig->type == SCREEN_TYPE_VECTOR) { /* add flicker control */ - *tailptr = slider_alloc("Vector Flicker", 0, 0, 1000, 10, slider_flicker, NULL); + *tailptr = slider_alloc(machine, "Vector Flicker", 0, 0, 1000, 10, slider_flicker, NULL); tailptr = &(*tailptr)->next; - *tailptr = slider_alloc("Beam Width", 10, 100, 1000, 10, slider_beam, NULL); + *tailptr = slider_alloc(machine, "Beam Width", 10, 100, 1000, 10, slider_beam, NULL); tailptr = &(*tailptr)->next; break; } @@ -1557,10 +1556,10 @@ static slider_state *slider_init(running_machine *machine) { void *param = (void *)field; astring_printf(string, "Crosshair Scale %s", (field->crossaxis == CROSSHAIR_AXIS_X) ? "X" : "Y"); - *tailptr = slider_alloc(astring_c(string), -3000, 1000, 3000, 100, slider_crossscale, param); + *tailptr = slider_alloc(machine, astring_c(string), -3000, 1000, 3000, 100, slider_crossscale, param); tailptr = &(*tailptr)->next; astring_printf(string, "Crosshair Offset %s", (field->crossaxis == CROSSHAIR_AXIS_X) ? "X" : "Y"); - *tailptr = slider_alloc(astring_c(string), -3000, 0, 3000, 100, slider_crossoffset, param); + *tailptr = slider_alloc(machine, astring_c(string), -3000, 0, 3000, 100, slider_crossoffset, param); tailptr = &(*tailptr)->next; } #endif diff --git a/src/emu/uiinput.c b/src/emu/uiinput.c index bc6d42d2595..fc2190c2013 100644 --- a/src/emu/uiinput.c +++ b/src/emu/uiinput.c @@ -76,8 +76,7 @@ static void ui_input_frame_update(running_machine *machine); void ui_input_init(running_machine *machine) { /* create the private data */ - machine->ui_input_data = (ui_input_private *)auto_malloc(sizeof(*machine->ui_input_data)); - memset(machine->ui_input_data, 0, sizeof(*machine->ui_input_data)); + machine->ui_input_data = auto_alloc_clear(machine, ui_input_private); machine->ui_input_data->current_mouse_x = -1; machine->ui_input_data->current_mouse_y = -1; diff --git a/src/emu/uimenu.c b/src/emu/uimenu.c index 0457dec6bca..d36d10226dd 100644 --- a/src/emu/uimenu.c +++ b/src/emu/uimenu.c @@ -448,8 +448,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 = (ui_menu *)malloc_or_die(sizeof(*menu)); - memset(menu, 0, sizeof(*menu)); + menu = alloc_clear_or_die(ui_menu); /* initialize the state */ menu->machine = machine; @@ -652,9 +651,8 @@ void *ui_menu_alloc_state(ui_menu *menu, size_t size, ui_menu_destroy_state_func (*menu->destroy_state)(menu, menu->state); free(menu->state); } - menu->state = malloc_or_die(size); + menu->state = alloc_array_clear_or_die(UINT8, size); menu->destroy_state = destroy_state; - memset(menu->state, 0, size); return menu->state; } @@ -681,8 +679,7 @@ void *ui_menu_pool_alloc(ui_menu *menu, size_t size) } /* allocate a new pool */ - pool = (ui_menu_pool *)malloc_or_die(sizeof(*pool) + UI_MENU_POOL_SIZE); - memset(pool, 0, sizeof(*pool)); + pool = (ui_menu_pool *)alloc_array_clear_or_die(UINT8, sizeof(*pool) + UI_MENU_POOL_SIZE); /* wire it up */ pool->next = menu->pool; diff --git a/src/emu/validity.c b/src/emu/validity.c index 49f0f09052b..adfbb207a48 100644 --- a/src/emu/validity.c +++ b/src/emu/validity.c @@ -233,7 +233,7 @@ static quark_table *quark_table_alloc(UINT32 entries, UINT32 hashsize) /* determine how many total bytes we need */ total_bytes = sizeof(*table) + entries * sizeof(table->entry[0]) + hashsize * sizeof(table->hash[0]); - table = (quark_table *)auto_malloc(total_bytes); + table = (quark_table *)alloc_array_or_die(UINT8, total_bytes); /* fill in the details */ table->entries = entries; @@ -292,6 +292,34 @@ static void quark_tables_create(void) } +/*------------------------------------------------- + quark_tables_free - free allocated tables +-------------------------------------------------*/ + +static void quark_tables_free(void) +{ + if (source_table != NULL) + free(source_table); + source_table = NULL; + + if (name_table != NULL) + free(name_table); + name_table = NULL; + + if (description_table != NULL) + free(description_table); + description_table = NULL; + + if (roms_table != NULL) + free(roms_table); + roms_table = NULL; + + if (defstr_table != NULL) + free(defstr_table); + defstr_table = NULL; +} + + /*************************************************************************** VALIDATION FUNCTIONS @@ -1718,6 +1746,7 @@ int mame_validitychecks(const game_driver *curdriver) end_resource_tracking(); exit_resource_tracking(); + quark_tables_free(); return error; } diff --git a/src/emu/video.c b/src/emu/video.c index 9b890fe995e..aefd99440ef 100644 --- a/src/emu/video.c +++ b/src/emu/video.c @@ -434,7 +434,7 @@ static void init_buffered_spriteram(running_machine *machine) assert_always(spriteram_size != 0, "Video buffers spriteram but spriteram_size is 0"); /* allocate memory for the back buffer */ - buffered_spriteram = (UINT8 *)auto_malloc(spriteram_size); + buffered_spriteram = auto_alloc_array(machine, UINT8, spriteram_size); /* register for saving it */ state_save_register_global_pointer(machine, buffered_spriteram, spriteram_size); @@ -443,7 +443,7 @@ static void init_buffered_spriteram(running_machine *machine) if (spriteram_2_size) { /* allocate memory */ - buffered_spriteram_2 = (UINT8 *)auto_malloc(spriteram_2_size); + buffered_spriteram_2 = auto_alloc_array(machine, UINT8, spriteram_2_size); /* register for saving it */ state_save_register_global_pointer(machine, buffered_spriteram_2, spriteram_2_size); diff --git a/src/emu/video.h b/src/emu/video.h index f86269739ef..3579d07b4aa 100644 --- a/src/emu/video.h +++ b/src/emu/video.h @@ -52,7 +52,7 @@ enum #define video_screen_get_format(screen) (((screen_config *)(screen)->inline_config)->format) /* allocates a bitmap that has the same dimensions and format as the passed in screen */ -#define video_screen_auto_bitmap_alloc(screen) auto_bitmap_alloc(video_screen_get_width(screen), video_screen_get_height(screen), video_screen_get_format(screen)) +#define video_screen_auto_bitmap_alloc(screen) auto_bitmap_alloc(screen->machine, video_screen_get_width(screen), video_screen_get_height(screen), video_screen_get_format(screen)) diff --git a/src/emu/video/generic.c b/src/emu/video/generic.c index 4b41a7526b7..2b085fb3c2b 100644 --- a/src/emu/video/generic.c +++ b/src/emu/video/generic.c @@ -367,7 +367,7 @@ equal to the size of normal spriteram. Spriteram size _must_ be declared in the memory map: - { 0x120000, 0x1207ff, SMH_BANK2, &spriteram, &spriteram_size }, + { 0x120000, 0x1207ff, SMH_BANK(2), &spriteram, &spriteram_size }, Then the video driver must draw the sprites from the buffered_spriteram pointer. The function buffer_spriteram_w() is used to simulate hardware diff --git a/src/emu/video/poly.c b/src/emu/video/poly.c index d78279762cc..9e658218828 100644 --- a/src/emu/video/poly.c +++ b/src/emu/video/poly.c @@ -333,8 +333,7 @@ poly_manager *poly_alloc(running_machine *machine, int max_polys, size_t extra_d poly_manager *poly; /* allocate the manager itself */ - poly = (poly_manager *)malloc_or_die(sizeof(*poly)); - memset(poly, 0, sizeof(*poly)); + poly = alloc_clear_or_die(poly_manager); poly->flags = flags; /* allocate polygons */ @@ -1314,12 +1313,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 = (void **)malloc_or_die(sizeof(*ptrarray) * itemcount); - memset(ptrarray, 0, sizeof(*ptrarray) * itemcount); + ptrarray = alloc_array_clear_or_die(void *, itemcount); /* allocate the actual items */ - ptrarray[0] = malloc_or_die(*itemsize * itemcount); - memset(ptrarray[0], 0, *itemsize * itemcount); + ptrarray[0] = alloc_array_clear_or_die(UINT8, *itemsize * itemcount); /* initialize the pointer array */ for (itemnum = 1; itemnum < itemcount; itemnum++) diff --git a/src/emu/video/resnet.c b/src/emu/video/resnet.c index 2acba3d1d46..c17b2e67623 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 = (double *)malloc_or_die( sizeof(double) * (1<<MAX_RES_PER_NET) * MAX_NETS); - os = (double *)malloc_or_die( sizeof(double) * (1<<MAX_RES_PER_NET) * MAX_NETS); + 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); networks_no = 0; for (n = 0; n < MAX_NETS; n++) @@ -700,7 +700,7 @@ rgb_t *compute_res_net_all(const UINT8 *prom, const res_net_decode_info *rdi, co int i,j,k; rgb_t *rgb; - rgb = (rgb_t *)malloc_or_die((rdi->end - rdi->start + 1)*sizeof(rgb_t)); + rgb = alloc_array_or_die(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/s2636.c b/src/emu/video/s2636.c index f52f172f951..b539415f814 100644 --- a/src/emu/video/s2636.c +++ b/src/emu/video/s2636.c @@ -117,19 +117,19 @@ struct _s2636_t * *************************************/ -s2636_t *s2636_config(UINT8 *work_ram, int screen_height, int screen_width, int y_offset, int x_offset) +s2636_t *s2636_config(running_machine *machine, UINT8 *work_ram, int screen_height, int screen_width, int y_offset, int x_offset) { s2636_t *s2636; /* allocate the object that holds the state */ - s2636 = (s2636_t *)auto_malloc(sizeof(*s2636)); + s2636 = auto_alloc(machine, s2636_t); s2636->work_ram = work_ram; s2636->y_offset = y_offset; s2636->x_offset = x_offset; - s2636->bitmap = auto_bitmap_alloc(screen_width, screen_height, BITMAP_FORMAT_INDEXED16); - s2636->collision_bitmap = auto_bitmap_alloc(screen_width, screen_height, BITMAP_FORMAT_INDEXED16); + s2636->bitmap = auto_bitmap_alloc(machine, screen_width, screen_height, BITMAP_FORMAT_INDEXED16); + s2636->collision_bitmap = auto_bitmap_alloc(machine, screen_width, screen_height, BITMAP_FORMAT_INDEXED16); return s2636; } diff --git a/src/emu/video/s2636.h b/src/emu/video/s2636.h index 17dce840297..ad2034dea53 100644 --- a/src/emu/video/s2636.h +++ b/src/emu/video/s2636.h @@ -14,7 +14,7 @@ typedef struct _s2636_t s2636_t; #define S2636_IS_PIXEL_DRAWN(p) (((p) & 0x08) ? TRUE : FALSE) #define S2636_PIXEL_COLOR(p) ((p) & 0x07) -s2636_t *s2636_config(UINT8 *work_ram, int screen_height, int screen_width, int y_offset, int x_offset); +s2636_t *s2636_config(running_machine *machine, UINT8 *work_ram, int screen_height, int screen_width, int y_offset, int x_offset); /* returns a BITMAP_FORMAT_INDEXED16 bitmap the size of the screen D0-D2 of each pixel is the pixel color diff --git a/src/emu/video/tms34061.c b/src/emu/video/tms34061.c index f94edb7fec3..68d3291419d 100644 --- a/src/emu/video/tms34061.c +++ b/src/emu/video/tms34061.c @@ -84,14 +84,12 @@ void tms34061_start(running_machine *machine, const struct tms34061_interface *i tms34061.vrammask = tms34061.intf.vramsize - 1; /* allocate memory for VRAM */ - tms34061.vram = (UINT8 *)auto_malloc(tms34061.intf.vramsize + 256 * 2); - memset(tms34061.vram, 0, tms34061.intf.vramsize + 256 * 2); + tms34061.vram = auto_alloc_array_clear(machine, UINT8, tms34061.intf.vramsize + 256 * 2); /* not really a save state, just there for debugging purposes */ state_save_register_global_pointer(machine, tms34061.vram, tms34061.intf.vramsize); /* allocate memory for latch RAM */ - tms34061.latchram = (UINT8 *)auto_malloc(tms34061.intf.vramsize + 256 * 2); - memset(tms34061.latchram, 0, tms34061.intf.vramsize + 256 * 2); + tms34061.latchram = auto_alloc_array_clear(machine, UINT8, tms34061.intf.vramsize + 256 * 2); /* add some buffer space for VRAM and latch RAM */ tms34061.vram += 256; diff --git a/src/emu/video/tms9928a.c b/src/emu/video/tms9928a.c index 85367e1646b..615f2d982e3 100644 --- a/src/emu/video/tms9928a.c +++ b/src/emu/video/tms9928a.c @@ -200,14 +200,13 @@ static void TMS9928A_start (running_machine *machine, const TMS9928a_interface * /* Video RAM */ tms.vramsize = intf->vram; - tms.vMem = (UINT8*) auto_malloc (intf->vram); - memset (tms.vMem, 0, intf->vram); + tms.vMem = auto_alloc_array_clear(machine, UINT8, intf->vram); /* Sprite back buffer */ - tms.dBackMem = (UINT8*)auto_malloc (IMAGE_SIZE); + tms.dBackMem = auto_alloc_array(machine, UINT8, IMAGE_SIZE); /* back bitmap */ - tms.tmpbmp = auto_bitmap_alloc (256, 192, video_screen_get_format(machine->primary_screen)); + tms.tmpbmp = auto_bitmap_alloc (machine, 256, 192, video_screen_get_format(machine->primary_screen)); TMS9928A_reset (); tms.LimitSprites = 1; diff --git a/src/emu/video/v9938.c b/src/emu/video/v9938.c index 70072ae1eb5..512564b2331 100644 --- a/src/emu/video/v9938.c +++ b/src/emu/video/v9938.c @@ -164,7 +164,7 @@ PALETTE_INIT( v9958 ) PALETTE_INIT_CALL(v9938); /* set up YJK table */ - pal_indYJK = (UINT16 *)auto_malloc(0x20000 * sizeof(UINT16)); + pal_indYJK = auto_alloc_array(machine, UINT16, 0x20000); LOG(("Building YJK table for V9958 screens, may take a while ... \n")); i = 0; @@ -494,8 +494,7 @@ void v9938_init (running_machine *machine, int which, const device_config *scree vdp->size_old = -1; /* allocate VRAM */ - vdp->vram = (UINT8 *)auto_malloc (0x20000); - memset (vdp->vram, 0, 0x20000); + vdp->vram = auto_alloc_array_clear(machine, UINT8, 0x20000); if (vdp->vram_size < 0x20000) { /* set unavailable RAM to 0xff */ @@ -504,10 +503,7 @@ void v9938_init (running_machine *machine, int which, const device_config *scree /* do we have expanded memory? */ if (vdp->vram_size > 0x20000) - { - vdp->vram_exp = (UINT8 *)auto_malloc (0x10000); - memset (vdp->vram_exp, 0, 0x10000); - } + vdp->vram_exp = auto_alloc_array_clear(machine, UINT8, 0x10000); else vdp->vram_exp = NULL; diff --git a/src/emu/video/vector.c b/src/emu/video/vector.c index 3ab6f36a703..0c664e77178 100644 --- a/src/emu/video/vector.c +++ b/src/emu/video/vector.c @@ -184,7 +184,7 @@ VIDEO_START( vector ) vector_index = 0; /* allocate memory for tables */ - vector_list = (point *)auto_malloc (MAX_POINTS * sizeof (vector_list[0])); + vector_list = auto_alloc_array(machine, point, MAX_POINTS); } diff --git a/src/emu/video/voodoo.c b/src/emu/video/voodoo.c index 7644c5dc6fd..9b455699dcf 100644 --- a/src/emu/video/voodoo.c +++ b/src/emu/video/voodoo.c @@ -4471,7 +4471,7 @@ static DEVICE_START( voodoo ) /* create a multiprocessor work queue */ v->poly = poly_alloc(device->machine, 64, sizeof(poly_extra_data), 0); - v->thread_stats = (stats_block *)auto_malloc(sizeof(v->thread_stats[0]) * WORK_MAX_THREADS); + v->thread_stats = auto_alloc_array(device->machine, stats_block, WORK_MAX_THREADS); /* create a table of precomputed 1/n and log2(n) values */ /* n ranges from 1.0000 to 2.0000 */ @@ -4565,14 +4565,14 @@ static DEVICE_START( voodoo ) if (config->type <= VOODOO_2) { /* separate FB/TMU memory */ - fbmem = auto_malloc(config->fbmem << 20); - tmumem[0] = auto_malloc(config->tmumem0 << 20); - tmumem[1] = (config->tmumem1 != 0) ? auto_malloc(config->tmumem1 << 20) : NULL; + fbmem = auto_alloc_array(device->machine, UINT8, config->fbmem << 20); + tmumem[0] = auto_alloc_array(device->machine, UINT8, config->tmumem0 << 20); + tmumem[1] = (config->tmumem1 != 0) ? auto_alloc_array(device->machine, UINT8, config->tmumem1 << 20) : NULL; } else { /* shared memory */ - tmumem[0] = tmumem[1] = fbmem = auto_malloc(config->fbmem << 20); + tmumem[0] = tmumem[1] = fbmem = auto_alloc_array(device->machine, UINT8, config->fbmem << 20); tmumem0 = config->fbmem; } |