diff --git a/.gitattributes b/.gitattributes index 9d1ee588127..709e349256e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3615,6 +3615,8 @@ src/lib/util/chdcd.c svneol=native#text/plain src/lib/util/chdcd.h svneol=native#text/plain src/lib/util/chdcodec.c svneol=native#text/plain src/lib/util/chdcodec.h svneol=native#text/plain +src/lib/util/corealloc.c svneol=native#text/plain +src/lib/util/corealloc.h svneol=native#text/plain src/lib/util/corefile.c svneol=native#text/plain src/lib/util/corefile.h svneol=native#text/plain src/lib/util/corestr.c svneol=native#text/plain @@ -3622,6 +3624,8 @@ src/lib/util/corestr.h svneol=native#text/plain src/lib/util/coretmpl.h svneol=native#text/plain src/lib/util/coreutil.c svneol=native#text/plain src/lib/util/coreutil.h svneol=native#text/plain +src/lib/util/cstrpool.c svneol=native#text/plain +src/lib/util/cstrpool.h svneol=native#text/plain src/lib/util/flac.c svneol=native#text/plain src/lib/util/flac.h svneol=native#text/plain src/lib/util/harddisk.c svneol=native#text/plain diff --git a/src/build/makelist.c b/src/build/makelist.c index df2afef66dc..04327e78fe0 100644 --- a/src/build/makelist.c +++ b/src/build/makelist.c @@ -12,15 +12,12 @@ #include #include #include "corefile.h" +#include "cstrpool.h" -#define MAX_DRIVERS 65536 -#define MAX_IGNORE 512 - -static const char *drivlist[MAX_DRIVERS]; -static int drivcount; -static const char *ignorelst[MAX_IGNORE]; -static int ignorecount; +static dynamic_array drivlist; +static dynamic_array ignorelst; +static const_string_pool string_pool; //------------------------------------------------- @@ -42,11 +39,9 @@ int sort_callback(const void *elem1, const void *elem2) bool isignored(const char *drivname) { - if (ignorecount>0) { - for(int i=0;ichars[chnum].width > 0) - numchars++; - - /* allocate an array to hold the character data */ - chartable = (UINT8 *)malloc(numchars * CACHED_CHAR_SIZE); - - /* allocate a temp buffer to compress into */ - tempbuffer = (UINT8 *)malloc(65536); - if (chartable == NULL || tempbuffer == NULL) - goto error; - - memset(chartable, 0, numchars * CACHED_CHAR_SIZE); - - /* write the header */ - dest = tempbuffer; - *dest++ = 'f'; - *dest++ = 'o'; - *dest++ = 'n'; - *dest++ = 't'; - *dest++ = hash >> 24; - *dest++ = hash >> 16; - *dest++ = hash >> 8; - *dest++ = hash & 0xff; - *dest++ = font->height >> 8; - *dest++ = font->height & 0xff; - *dest++ = font->yoffs >> 8; - *dest++ = font->yoffs & 0xff; - *dest++ = numchars >> 24; - *dest++ = numchars >> 16; - *dest++ = numchars >> 8; - *dest++ = numchars & 0xff; - bytes_written = core_fwrite(file, tempbuffer, dest - tempbuffer); - if (bytes_written != dest - tempbuffer) - goto error; - - /* write the empty table to the beginning of the file */ - bytes_written = core_fwrite(file, chartable, numchars * CACHED_CHAR_SIZE); - if (bytes_written != numchars * CACHED_CHAR_SIZE) - goto error; - - /* loop over all characters */ - tableindex = 0; - for (chnum = 0; chnum < 65536; chnum++) + UINT32 bytes_written = core_fwrite(&file, base, end - base); + if (bytes_written != end - base) { - ch = &font->chars[chnum]; - if (ch->width > 0) - { - UINT8 accum, accbit; - int x, y; - - /* write out a bit-compressed bitmap if we have one */ - if (ch->bitmap != NULL) - { - /* write the data to the tempbuffer */ - dest = tempbuffer; - accum = 0; - accbit = 7; - - /* bit-encode the character data */ - for (y = 0; y < ch->bmheight; y++) - { - int desty = y + font->height + font->yoffs - ch->yoffs - ch->bmheight; - const UINT32 *src = (desty >= 0 && desty < font->height) ? &ch->bitmap->pix32(desty) : NULL; - for (x = 0; x < ch->bmwidth; x++) - { - if (src != NULL && src[x] != 0) - accum |= 1 << accbit; - if (accbit-- == 0) - { - *dest++ = accum; - accum = 0; - accbit = 7; - } - } - } - - /* flush any extra */ - if (accbit != 7) - *dest++ = accum; - - /* write the data */ - bytes_written = core_fwrite(file, tempbuffer, dest - tempbuffer); - if (bytes_written != dest - tempbuffer) - goto error; - - /* free the bitmap and texture */ - delete ch->bitmap; - ch->bitmap = NULL; - } - - /* compute the table entry */ - dest = &chartable[tableindex++ * CACHED_CHAR_SIZE]; - *dest++ = chnum >> 8; - *dest++ = chnum & 0xff; - *dest++ = ch->width >> 8; - *dest++ = ch->width & 0xff; - *dest++ = ch->xoffs >> 8; - *dest++ = ch->xoffs & 0xff; - *dest++ = ch->yoffs >> 8; - *dest++ = ch->yoffs & 0xff; - *dest++ = ch->bmwidth >> 8; - *dest++ = ch->bmwidth & 0xff; - *dest++ = ch->bmheight >> 8; - *dest++ = ch->bmheight & 0xff; - } + fprintf(stderr, "Error writing to destination file\n"); + throw; } - - /* seek back to the beginning and rewrite the table */ - core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET); - bytes_written = core_fwrite(file, chartable, numchars * CACHED_CHAR_SIZE); - if (bytes_written != numchars * CACHED_CHAR_SIZE) - goto error; - - /* all done */ - core_fclose(file); - free(tempbuffer); - free(chartable); - return 0; - -error: - core_fclose(file); - osd_rmfile(filename); - free(tempbuffer); - free(chartable); - return 1; } -/*------------------------------------------------- - bitmap_to_chars - convert a bitmap to - characters in the given font --------------------------------------------------*/ +//------------------------------------------------- +// render_font_save_cached - write the cached +// data out to the file +//------------------------------------------------- -static int bitmap_to_chars(bitmap_argb32 &bitmap, render_font *font) +static bool render_font_save_cached(render_font &font, const char *filename, UINT32 hash) { - int rowstart = 0; - int x, y; + // attempt to open the file + core_file *file; + file_error filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file); + if (filerr != FILERR_NONE) + return true; - /* loop over rows */ + try + { + // determine the number of characters + int numchars = 0; + for (int chnum = 0; chnum < 65536; chnum++) + if (font.chars[chnum].width > 0) + numchars++; + + // write the header + dynamic_buffer tempbuffer(65536); + UINT8 *dest = &tempbuffer[0]; + *dest++ = 'f'; + *dest++ = 'o'; + *dest++ = 'n'; + *dest++ = 't'; + *dest++ = hash >> 24; + *dest++ = hash >> 16; + *dest++ = hash >> 8; + *dest++ = hash & 0xff; + *dest++ = font.height >> 8; + *dest++ = font.height & 0xff; + *dest++ = font.yoffs >> 8; + *dest++ = font.yoffs & 0xff; + *dest++ = numchars >> 24; + *dest++ = numchars >> 16; + *dest++ = numchars >> 8; + *dest++ = numchars & 0xff; + write_data(*file, tempbuffer, dest); + + // write the empty table to the beginning of the file + dynamic_buffer chartable(numchars * CACHED_CHAR_SIZE + 1, 0); + write_data(*file, &chartable[0], &chartable[numchars * CACHED_CHAR_SIZE]); + + // loop over all characters + int tableindex = 0; + for (int chnum = 0; chnum < 65536; chnum++) + { + render_font_char &ch = font.chars[chnum]; + if (ch.width > 0) + { + // write out a bit-compressed bitmap if we have one + if (ch.bitmap != NULL) + { + // write the data to the tempbuffer + dest = tempbuffer; + UINT8 accum = 0; + UINT8 accbit = 7; + + // bit-encode the character data + for (int y = 0; y < ch.bmheight; y++) + { + int desty = y + font.height + font.yoffs - ch.yoffs - ch.bmheight; + const UINT32 *src = (desty >= 0 && desty < font.height) ? &ch.bitmap->pix32(desty) : NULL; + for (int x = 0; x < ch.bmwidth; x++) + { + if (src != NULL && src[x] != 0) + accum |= 1 << accbit; + if (accbit-- == 0) + { + *dest++ = accum; + accum = 0; + accbit = 7; + } + } + } + + // flush any extra + if (accbit != 7) + *dest++ = accum; + + // write the data + write_data(*file, tempbuffer, dest); + + // free the bitmap and texture + global_free(ch.bitmap); + ch.bitmap = NULL; + } + + // compute the table entry + dest = &chartable[tableindex++ * CACHED_CHAR_SIZE]; + *dest++ = chnum >> 8; + *dest++ = chnum & 0xff; + *dest++ = ch.width >> 8; + *dest++ = ch.width & 0xff; + *dest++ = ch.xoffs >> 8; + *dest++ = ch.xoffs & 0xff; + *dest++ = ch.yoffs >> 8; + *dest++ = ch.yoffs & 0xff; + *dest++ = ch.bmwidth >> 8; + *dest++ = ch.bmwidth & 0xff; + *dest++ = ch.bmheight >> 8; + *dest++ = ch.bmheight & 0xff; + } + } + + // seek back to the beginning and rewrite the table + core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET); + write_data(*file, &chartable[0], &chartable[numchars * CACHED_CHAR_SIZE]); + + // all done + core_fclose(file); + return false; + } + catch (...) + { + core_fclose(file); + osd_rmfile(filename); + return true; + } +} + + +//------------------------------------------------- +// bitmap_to_chars - convert a bitmap to +// characters in the given font +//------------------------------------------------- + +static bool bitmap_to_chars(bitmap_argb32 &bitmap, render_font &font) +{ + // loop over rows + int rowstart = 0; while (rowstart < bitmap.height()) { - int rowend, baseline, colstart; - int chstart; - - /* find the top of the row */ + // find the top of the row for ( ; rowstart < bitmap.height(); rowstart++) if (pixel_is_set(bitmap, rowstart, 0)) break; if (rowstart >= bitmap.height()) break; - /* find the bottom of the row */ + // find the bottom of the row + int rowend; for (rowend = rowstart + 1; rowend < bitmap.height(); rowend++) if (!pixel_is_set(bitmap, rowend, 0)) { @@ -282,7 +273,8 @@ static int bitmap_to_chars(bitmap_argb32 &bitmap, render_font *font) break; } - /* find the baseline */ + // find the baseline + int baseline; for (baseline = rowstart; baseline <= rowend; baseline++) if (pixel_is_set(bitmap, baseline, 1)) break; @@ -292,50 +284,50 @@ static int bitmap_to_chars(bitmap_argb32 &bitmap, render_font *font) break; } - /* set or confirm the height */ - if (font->height == 0) + // set or confirm the height + if (font.height == 0) { - font->height = rowend - rowstart + 1; - font->yoffs = baseline - rowend; + font.height = rowend - rowstart + 1; + font.yoffs = baseline - rowend; } else { - if (font->height != rowend - rowstart + 1) + if (font.height != rowend - rowstart + 1) { fprintf(stderr, "Inconsistent font height at rows %d-%d\n", rowstart, rowend); break; } - if (font->yoffs != baseline - rowend) + if (font.yoffs != baseline - rowend) { fprintf(stderr, "Inconsistent baseline at rows %d-%d\n", rowstart, rowend); break; } } - /* decode the starting character */ - chstart = 0; - for (x = 0; x < 4; x++) - for (y = 0; y < 4; y++) + // decode the starting character + int chstart = 0; + for (int x = 0; x < 4; x++) + for (int y = 0; y < 4; y++) chstart = (chstart << 1) | pixel_is_set(bitmap, rowstart + y, 2 + x); - /* print info */ + // print info // printf("Row %d-%d, baseline %d, character start %X\n", rowstart, rowend, baseline, chstart); - /* scan the column to find characters */ - colstart = 0; + // scan the column to find characters + int colstart = 0; while (colstart < bitmap.width()) { - render_font_char *ch = &font->chars[chstart]; - int colend; + render_font_char &ch = font.chars[chstart]; - /* find the start of the character */ + // find the start of the character for ( ; colstart < bitmap.width(); colstart++) if (pixel_is_set(bitmap, rowend + 2, colstart)) break; if (colstart >= bitmap.width()) break; - /* find the end of the character */ + // find the end of the character + int colend; for (colend = colstart + 1; colend < bitmap.width(); colend++) if (!pixel_is_set(bitmap, rowend + 2, colend)) { @@ -344,82 +336,68 @@ static int bitmap_to_chars(bitmap_argb32 &bitmap, render_font *font) } // skip char which code is already registered - if (ch->width <= 0) + if (ch.width <= 0) { - /* print info */ + // print info // printf(" Character %X - width = %d\n", chstart, colend - colstart + 1); - /* allocate a bitmap */ - ch->bitmap = new(std::nothrow) bitmap_argb32(colend - colstart + 1, font->height); - if (ch->bitmap == NULL) - { - fprintf(stderr, "Error allocating character bitmap (%dx%d)\n", colend - colstart + 1, font->height); - continue; - } + // allocate a bitmap + ch.bitmap = global_alloc(bitmap_argb32(colend - colstart + 1, font.height)); - /* plot the character */ - for (y = rowstart; y <= rowend; y++) - for (x = colstart; x <= colend; x++) - ch->bitmap->pix32(y - rowstart, x - colstart) = pixel_is_set(bitmap, y, x) ? 0xffffffff : 0x00000000; + // plot the character + for (int y = rowstart; y <= rowend; y++) + for (int x = colstart; x <= colend; x++) + ch.bitmap->pix32(y - rowstart, x - colstart) = pixel_is_set(bitmap, y, x) ? 0xffffffff : 0x00000000; - /* set the character parameters */ - ch->width = colend - colstart + 1; - ch->xoffs = 0; - ch->yoffs = font->yoffs; - ch->bmwidth = ch->bitmap->width(); - ch->bmheight = ch->bitmap->height(); + // set the character parameters + ch.width = colend - colstart + 1; + ch.xoffs = 0; + ch.yoffs = font.yoffs; + ch.bmwidth = ch.bitmap->width(); + ch.bmheight = ch.bitmap->height(); } - /* next character */ + // next character chstart++; colstart = colend + 1; } - /* next row */ + // next row rowstart = rowend + 1; } - /* return non-zero (TRUE) if we errored */ + // return non-zero (TRUE) if we errored return (rowstart < bitmap.height()); } -/*------------------------------------------------- - main - main entry point --------------------------------------------------*/ +//------------------------------------------------- +// main - main entry point +//------------------------------------------------- int main(int argc, char *argv[]) { - const char *bdcname; - render_font *font; - int error = FALSE; - int curarg; - - /* validate arguments */ + // validate arguments if (argc < 3) { fprintf(stderr, "Usage:\n%s [ [...]] \n", argv[0]); return 1; } - bdcname = argv[argc - 1]; + const char *bdcname = argv[argc - 1]; - /* allocate a font */ - font = (render_font *)malloc(sizeof(*font)); - if (font == NULL) - return 1; - memset(font, 0, sizeof(*font)); - - /* iterate over input files */ - for (curarg = 1; curarg < argc - 1; curarg++) + // iterate over input files + static render_font font; + bool error = false; + for (int curarg = 1; curarg < argc - 1; curarg++) { - /* load the png file */ + // load the png file const char *pngname = argv[curarg]; core_file *file; file_error filerr = core_fopen(pngname, OPEN_FLAG_READ, &file); if (filerr != FILERR_NONE) { fprintf(stderr, "Error %d attempting to open PNG file\n", filerr); - error = TRUE; + error = true; break; } @@ -429,21 +407,20 @@ int main(int argc, char *argv[]) if (pngerr != PNGERR_NONE) { fprintf(stderr, "Error %d reading PNG file\n", pngerr); - error = TRUE; + error = true; break; } - /* parse the PNG into characters */ + // parse the PNG into characters error = bitmap_to_chars(bitmap, font); if (error) break; } - /* write out the resulting font */ + // write out the resulting font if (!error) - render_font_save_cached(font, bdcname, 0); + error = render_font_save_cached(font, bdcname, 0); - /* cleanup after ourselves */ - free(font); - return error; + // cleanup after ourselves + return error ? 1 : 0; } diff --git a/src/emu/audit.c b/src/emu/audit.c index 51a92abbf8d..c8ca031243b 100644 --- a/src/emu/audit.c +++ b/src/emu/audit.c @@ -188,12 +188,12 @@ media_auditor::summary media_auditor::audit_software(const char *list_name, soft // store validation for later m_validation = validation; - astring combinedpath(swinfo->shortname, ";", list_name, PATH_SEPARATOR, swinfo->shortname); - astring locationtag(list_name, "%", swinfo->shortname, "%"); - if ( swinfo->parentname ) + astring combinedpath(swinfo->shortname(), ";", list_name, PATH_SEPARATOR, swinfo->shortname()); + astring locationtag(list_name, "%", swinfo->shortname(), "%"); + if (swinfo->parentname() != NULL) { - locationtag.cat(swinfo->parentname); - combinedpath.cat(";").cat(swinfo->parentname).cat(";").cat(list_name).cat(PATH_SEPARATOR).cat(swinfo->parentname); + locationtag.cat(swinfo->parentname()); + combinedpath.cat(";").cat(swinfo->parentname()).cat(";").cat(list_name).cat(PATH_SEPARATOR).cat(swinfo->parentname()); } m_searchpath = combinedpath; @@ -201,10 +201,10 @@ media_auditor::summary media_auditor::audit_software(const char *list_name, soft int required = 0; // now iterate over software parts - for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) ) + for ( software_part *part = swinfo->first_part(); part != NULL; part = part->next() ) { // now iterate over regions - for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) ) + for ( const rom_entry *region = part->romdata(); region; region = rom_next_region( region ) ) { // now iterate over rom definitions for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) diff --git a/src/emu/bus/adam/exp.c b/src/emu/bus/adam/exp.c index 38a4f183f20..8965e7ebacd 100644 --- a/src/emu/bus/adam/exp.c +++ b/src/emu/bus/adam/exp.c @@ -197,9 +197,9 @@ bool adam_expansion_slot_device::call_load() // call_softlist_load - //------------------------------------------------- -bool adam_expansion_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool adam_expansion_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry); + load_software_part_region(*this, swlist, swname, start_entry); return true; } @@ -209,9 +209,9 @@ bool adam_expansion_slot_device::call_softlist_load(char *swlist, char *swname, // get_default_card_software - //------------------------------------------------- -const char * adam_expansion_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void adam_expansion_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "standard"); + software_get_default_slot(result, "standard"); } diff --git a/src/emu/bus/adam/exp.h b/src/emu/bus/adam/exp.h index c2614a41856..0afcaee60b1 100644 --- a/src/emu/bus/adam/exp.h +++ b/src/emu/bus/adam/exp.h @@ -84,7 +84,7 @@ protected: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } @@ -98,7 +98,7 @@ protected: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); devcb_resolved_write_line m_out_int_func; diff --git a/src/emu/bus/adamnet/adamnet.c b/src/emu/bus/adamnet/adamnet.c index f522930bdbf..132feaa2822 100644 --- a/src/emu/bus/adamnet/adamnet.c +++ b/src/emu/bus/adamnet/adamnet.c @@ -114,7 +114,7 @@ void adamnet_device::device_stop() void adamnet_device::add_device(device_t *target) { - daisy_entry *entry = auto_alloc(machine(), daisy_entry(target)); + daisy_entry *entry = global_alloc(daisy_entry(target)); entry->m_interface->m_bus = this; diff --git a/src/emu/bus/c64/exp.c b/src/emu/bus/c64/exp.c index ecafa19c361..1739a672a71 100644 --- a/src/emu/bus/c64/exp.c +++ b/src/emu/bus/c64/exp.c @@ -208,9 +208,9 @@ bool c64_expansion_slot_device::call_load() // call_softlist_load - //------------------------------------------------- -bool c64_expansion_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool c64_expansion_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry); + load_software_part_region(*this, swlist, swname, start_entry); return true; } @@ -220,19 +220,20 @@ bool c64_expansion_slot_device::call_softlist_load(char *swlist, char *swname, r // get_default_card_software - //------------------------------------------------- -const char * c64_expansion_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void c64_expansion_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { if (!mame_stricmp(filetype(), "crt")) { - return cbm_crt_get_card(m_file); + cbm_crt_get_card(result, m_file); + return; } clear(); } - return software_get_default_slot(config, options, this, "standard"); + software_get_default_slot(result, "standard"); } diff --git a/src/emu/bus/c64/exp.h b/src/emu/bus/c64/exp.h index 6f2c199c3be..678441c6260 100644 --- a/src/emu/bus/c64/exp.h +++ b/src/emu/bus/c64/exp.h @@ -127,7 +127,7 @@ protected: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } @@ -141,7 +141,7 @@ protected: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); devcb2_read8 m_read_dma_cd; devcb2_write8 m_write_dma_cd; diff --git a/src/emu/bus/cbm2/exp.c b/src/emu/bus/cbm2/exp.c index f19566ab203..93ef2d648e8 100644 --- a/src/emu/bus/cbm2/exp.c +++ b/src/emu/bus/cbm2/exp.c @@ -146,9 +146,9 @@ bool cbm2_expansion_slot_device::call_load() // call_softlist_load - //------------------------------------------------- -bool cbm2_expansion_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool cbm2_expansion_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry); + load_software_part_region(*this, swlist, swname, start_entry); return true; } @@ -158,9 +158,9 @@ bool cbm2_expansion_slot_device::call_softlist_load(char *swlist, char *swname, // get_default_card_software - //------------------------------------------------- -const char * cbm2_expansion_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void cbm2_expansion_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "standard"); + software_get_default_slot(result, "standard"); } diff --git a/src/emu/bus/cbm2/exp.h b/src/emu/bus/cbm2/exp.h index 6b20d47baf1..726f00a5bb3 100644 --- a/src/emu/bus/cbm2/exp.h +++ b/src/emu/bus/cbm2/exp.h @@ -85,7 +85,7 @@ protected: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } @@ -99,7 +99,7 @@ protected: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); device_cbm2_expansion_card_interface *m_card; }; diff --git a/src/emu/bus/cbmiec/cbmiec.c b/src/emu/bus/cbmiec/cbmiec.c index f466c0ef147..b79556e21fa 100644 --- a/src/emu/bus/cbmiec/cbmiec.c +++ b/src/emu/bus/cbmiec/cbmiec.c @@ -342,7 +342,7 @@ void cbm_iec_device::device_stop() void cbm_iec_device::add_device(cbm_iec_slot_device *slot, device_t *target) { - daisy_entry *entry = auto_alloc(machine(), daisy_entry(target)); + daisy_entry *entry = global_alloc(daisy_entry(target)); entry->m_interface->m_slot = slot; entry->m_interface->m_bus = this; diff --git a/src/emu/bus/econet/econet.c b/src/emu/bus/econet/econet.c index 46701892f30..cdf784e11aa 100644 --- a/src/emu/bus/econet/econet.c +++ b/src/emu/bus/econet/econet.c @@ -270,7 +270,7 @@ void econet_device::device_stop() void econet_device::add_device(device_t *target, int address) { - daisy_entry *entry = auto_alloc(machine(), daisy_entry(target)); + daisy_entry *entry = global_alloc(daisy_entry(target)); entry->m_interface->m_econet = this; entry->m_interface->m_address = address; diff --git a/src/emu/bus/gameboy/gb_slot.c b/src/emu/bus/gameboy/gb_slot.c index 8646440a0f3..ae01c9525ea 100644 --- a/src/emu/bus/gameboy/gb_slot.c +++ b/src/emu/bus/gameboy/gb_slot.c @@ -451,9 +451,9 @@ void base_gb_cart_slot_device::setup_ram(UINT8 banks) call softlist load -------------------------------------------------*/ -bool base_gb_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool base_gb_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -574,43 +574,46 @@ int base_gb_cart_slot_device::get_cart_type(UINT8 *ROM, UINT32 len) get default card software -------------------------------------------------*/ -const char * base_gb_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void base_gb_cart_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { const char *slot_string = "rom"; UINT32 len = core_fsize(m_file), offset = 0; - UINT8 *ROM = global_alloc_array(UINT8, len); + dynamic_buffer rom(len); int type; - core_fread(m_file, ROM, len); + core_fread(m_file, rom, len); if ((len % 0x4000) == 512) offset = 512; - if (get_mmm01_candidate(ROM + offset, len - offset)) + if (get_mmm01_candidate(rom + offset, len - offset)) offset += (len - 0x8000); - type = get_cart_type(ROM + offset, len - offset); + type = get_cart_type(rom + offset, len - offset); slot_string = gb_get_slot(type); //printf("type: %s\n", slot_string); - global_free(ROM); clear(); - return slot_string; + result.cpy(slot_string); + return; } - return software_get_default_slot(config, options, this, "rom"); + software_get_default_slot(result, "rom"); } -const char * megaduck_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void megaduck_cart_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) - return "rom"; + if (open_image_file(mconfig().options())) + { + result.cpy("rom"); + return; + } - return software_get_default_slot(config, options, this, "rom"); + software_get_default_slot(result, "rom"); } diff --git a/src/emu/bus/gameboy/gb_slot.h b/src/emu/bus/gameboy/gb_slot.h index 8c9049f68d5..7a1d651a5f7 100644 --- a/src/emu/bus/gameboy/gb_slot.h +++ b/src/emu/bus/gameboy/gb_slot.h @@ -117,7 +117,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); int get_type() { return m_type; } int get_cart_type(UINT8 *ROM, UINT32 len); @@ -139,7 +139,7 @@ public: virtual const char *file_extensions() const { return "bin,gb,gbc"; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing virtual DECLARE_READ8_MEMBER(read_rom); @@ -180,7 +180,7 @@ public: virtual const char *file_extensions() const { return "bin"; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); }; diff --git a/src/emu/bus/gba/gba_slot.c b/src/emu/bus/gba/gba_slot.c index 05c64325686..4ac3f7b8022 100644 --- a/src/emu/bus/gba/gba_slot.c +++ b/src/emu/bus/gba/gba_slot.c @@ -240,9 +240,9 @@ void gba_cart_slot_device::call_unload() call softlist load -------------------------------------------------*/ -bool gba_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool gba_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -396,28 +396,28 @@ int gba_cart_slot_device::get_cart_type(UINT8 *ROM, UINT32 len) get default card software -------------------------------------------------*/ -const char * gba_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void gba_cart_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { const char *slot_string = "gba_rom"; UINT32 len = core_fsize(m_file); - UINT8 *ROM = global_alloc_array(UINT8, len); + dynamic_buffer rom(len); int type; - core_fread(m_file, ROM, len); + core_fread(m_file, rom, len); - type = get_cart_type(ROM, len); + type = get_cart_type(rom, len); slot_string = gba_get_slot(type); //printf("type: %s\n", slot_string); - global_free(ROM); clear(); - return slot_string; + result.cpy(slot_string); + return; } - return software_get_default_slot(config, options, this, "gba_rom"); + software_get_default_slot(result, "gba_rom"); } /*------------------------------------------------- diff --git a/src/emu/bus/gba/gba_slot.h b/src/emu/bus/gba/gba_slot.h index efb3c9077a5..216c2ed0006 100644 --- a/src/emu/bus/gba/gba_slot.h +++ b/src/emu/bus/gba/gba_slot.h @@ -67,7 +67,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); void install_rom(); @@ -88,7 +88,7 @@ public: virtual const char *file_extensions() const { return "gba,bin"; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing virtual DECLARE_READ32_MEMBER(read_rom); diff --git a/src/emu/bus/ieee488/ieee488.c b/src/emu/bus/ieee488/ieee488.c index deacdaa58c2..d2ebcee6a1a 100644 --- a/src/emu/bus/ieee488/ieee488.c +++ b/src/emu/bus/ieee488/ieee488.c @@ -156,7 +156,7 @@ void ieee488_device::device_stop() void ieee488_device::add_device(ieee488_slot_device *slot, device_t *target) { - daisy_entry *entry = auto_alloc(machine(), daisy_entry(target)); + daisy_entry *entry = global_alloc(daisy_entry(target)); entry->m_interface->m_bus = this; entry->m_interface->m_slot = slot; diff --git a/src/emu/bus/iq151/iq151.c b/src/emu/bus/iq151/iq151.c index ff334a8ea80..39d13ae4aed 100644 --- a/src/emu/bus/iq151/iq151.c +++ b/src/emu/bus/iq151/iq151.c @@ -206,9 +206,9 @@ bool iq151cart_slot_device::call_load() call softlist load -------------------------------------------------*/ -bool iq151cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool iq151cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -216,7 +216,7 @@ bool iq151cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_e get default card software -------------------------------------------------*/ -const char * iq151cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void iq151cart_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, NULL); + software_get_default_slot(result, NULL); } diff --git a/src/emu/bus/iq151/iq151.h b/src/emu/bus/iq151/iq151.h index 95eff69fe58..27e511168a0 100644 --- a/src/emu/bus/iq151/iq151.h +++ b/src/emu/bus/iq151/iq151.h @@ -100,7 +100,7 @@ public: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } @@ -113,7 +113,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing virtual void read(offs_t offset, UINT8 &data); diff --git a/src/emu/bus/iq151/video32.c b/src/emu/bus/iq151/video32.c index bcc0e84251d..ba37286246f 100644 --- a/src/emu/bus/iq151/video32.c +++ b/src/emu/bus/iq151/video32.c @@ -75,7 +75,7 @@ void iq151_video32_device::device_start() m_videoram = (UINT8*)memregion("videoram")->base(); m_chargen = (UINT8*)memregion("chargen")->base(); - m_gfxdecode->set_gfx(0, auto_alloc(machine(), gfx_element(m_palette, iq151_video32_charlayout, m_chargen, 1, 0))); + m_gfxdecode->set_gfx(0, global_alloc(gfx_element(m_palette, iq151_video32_charlayout, m_chargen, 1, 0))); } //------------------------------------------------- diff --git a/src/emu/bus/iq151/video64.c b/src/emu/bus/iq151/video64.c index 6b67da2bacf..93720651c8f 100644 --- a/src/emu/bus/iq151/video64.c +++ b/src/emu/bus/iq151/video64.c @@ -74,7 +74,7 @@ void iq151_video64_device::device_start() m_videoram = (UINT8*)memregion("videoram")->base(); m_chargen = (UINT8*)memregion("chargen")->base(); - m_gfxdecode->set_gfx(0,auto_alloc(machine(), gfx_element(m_palette, iq151_video64_charlayout, m_chargen, 1, 0))); + m_gfxdecode->set_gfx(0,global_alloc(gfx_element(m_palette, iq151_video64_charlayout, m_chargen, 1, 0))); } //------------------------------------------------- diff --git a/src/emu/bus/kc/kc.c b/src/emu/bus/kc/kc.c index 952152ca8d8..287e1e28825 100644 --- a/src/emu/bus/kc/kc.c +++ b/src/emu/bus/kc/kc.c @@ -380,9 +380,9 @@ bool kccart_slot_device::call_load() call softlist load -------------------------------------------------*/ -bool kccart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool kccart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -390,7 +390,7 @@ bool kccart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entr get default card software -------------------------------------------------*/ -const char * kccart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void kccart_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "standard"); + software_get_default_slot(result, "standard"); } diff --git a/src/emu/bus/kc/kc.h b/src/emu/bus/kc/kc.h index 1ec28892cd6..05ab3db5dbd 100644 --- a/src/emu/bus/kc/kc.h +++ b/src/emu/bus/kc/kc.h @@ -99,7 +99,7 @@ public: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } @@ -112,7 +112,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); }; // device type definition diff --git a/src/emu/bus/megadrive/md_slot.c b/src/emu/bus/megadrive/md_slot.c index 3dfb90a2aac..25336f1352b 100644 --- a/src/emu/bus/megadrive/md_slot.c +++ b/src/emu/bus/megadrive/md_slot.c @@ -682,9 +682,9 @@ void base_md_cart_slot_device::setup_nvram() call softlist load -------------------------------------------------*/ -bool base_md_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool base_md_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -907,30 +907,29 @@ int base_md_cart_slot_device::get_cart_type(UINT8 *ROM, UINT32 len) get default card software -------------------------------------------------*/ -const char * base_md_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void base_md_cart_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { const char *slot_string = "rom"; UINT32 len = core_fsize(m_file), offset = 0; - UINT8 *ROM = global_alloc_array(UINT8, len); + dynamic_buffer rom(len); int type; - core_fread(m_file, ROM, len); + core_fread(m_file, rom, len); - if (genesis_is_SMD(&ROM[0x200], len - 0x200)) + if (genesis_is_SMD(&rom[0x200], len - 0x200)) offset = 0x200; - type = get_cart_type(ROM + offset, len - offset); + type = get_cart_type(rom + offset, len - offset); slot_string = md_get_slot(type); - global_free(ROM); clear(); - return slot_string; + result.cpy(slot_string); } else - return software_get_default_slot(config, options, this, "rom"); + software_get_default_slot(result, "rom"); } diff --git a/src/emu/bus/megadrive/md_slot.h b/src/emu/bus/megadrive/md_slot.h index 879b7dd862e..e4e2ab3dac6 100644 --- a/src/emu/bus/megadrive/md_slot.h +++ b/src/emu/bus/megadrive/md_slot.h @@ -155,7 +155,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } @@ -166,7 +166,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); int get_type() { return m_type; } diff --git a/src/emu/bus/nes/aladdin.c b/src/emu/bus/nes/aladdin.c index 0ddceeb347d..9a09aba7818 100644 --- a/src/emu/bus/nes/aladdin.c +++ b/src/emu/bus/nes/aladdin.c @@ -135,38 +135,37 @@ bool nes_aladdin_slot_device::call_load() } -bool nes_aladdin_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool nes_aladdin_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } -const char * nes_aladdin_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void nes_aladdin_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { const char *slot_string = "algn"; UINT32 len = core_fsize(m_file); - UINT8 *ROM = global_alloc_array(UINT8, len); + dynamic_buffer rom(len); UINT8 mapper; - core_fread(m_file, ROM, len); + core_fread(m_file, rom, len); - mapper = (ROM[6] & 0xf0) >> 4; - mapper |= ROM[7] & 0xf0; + mapper = (rom[6] & 0xf0) >> 4; + mapper |= rom[7] & 0xf0; // if (mapper == 71) // slot_string = "algn"; if (mapper == 232) slot_string = "algq"; - global_free(ROM); clear(); - return slot_string; + result.cpy(slot_string); } else - return software_get_default_slot(config, options, this, "algn"); + software_get_default_slot(result, "algn"); } diff --git a/src/emu/bus/nes/aladdin.h b/src/emu/bus/nes/aladdin.h index f944c1127b5..922e9778a82 100644 --- a/src/emu/bus/nes/aladdin.h +++ b/src/emu/bus/nes/aladdin.h @@ -50,7 +50,7 @@ public: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } @@ -63,7 +63,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); virtual DECLARE_READ8_MEMBER(read); void write_prg(UINT32 offset, UINT8 data) { if (m_cart) m_cart->write_prg(offset, data); } diff --git a/src/emu/bus/nes/datach.c b/src/emu/bus/nes/datach.c index babd3f94454..b16efe9ffdf 100644 --- a/src/emu/bus/nes/datach.c +++ b/src/emu/bus/nes/datach.c @@ -138,16 +138,16 @@ bool nes_datach_slot_device::call_load() } -bool nes_datach_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool nes_datach_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } -const char * nes_datach_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void nes_datach_slot_device::get_default_card_software(astring &result) { // any way to detect the game with X24C01? - return software_get_default_slot(config, options, this, "datach_rom"); + software_get_default_slot(result, "datach_rom"); } diff --git a/src/emu/bus/nes/datach.h b/src/emu/bus/nes/datach.h index a65fd683231..6fc8cd5e0b4 100644 --- a/src/emu/bus/nes/datach.h +++ b/src/emu/bus/nes/datach.h @@ -52,7 +52,7 @@ public: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } @@ -65,7 +65,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); virtual DECLARE_READ8_MEMBER(read); void write_prg_bank(UINT8 bank) { if (m_cart) m_cart->write_prg_bank(bank); } diff --git a/src/emu/bus/nes/karastudio.c b/src/emu/bus/nes/karastudio.c index a62dc44ec1b..d331cbdeb4d 100644 --- a/src/emu/bus/nes/karastudio.c +++ b/src/emu/bus/nes/karastudio.c @@ -127,15 +127,15 @@ bool nes_kstudio_slot_device::call_load() } -bool nes_kstudio_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool nes_kstudio_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } -const char * nes_kstudio_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void nes_kstudio_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "ks_exp"); + software_get_default_slot(result, "ks_exp"); } diff --git a/src/emu/bus/nes/karastudio.h b/src/emu/bus/nes/karastudio.h index 1acd4fcbe6a..d3c8f2a6568 100644 --- a/src/emu/bus/nes/karastudio.h +++ b/src/emu/bus/nes/karastudio.h @@ -49,7 +49,7 @@ public: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } @@ -62,7 +62,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); virtual DECLARE_READ8_MEMBER(read); void write_prg_bank(UINT8 bank) { if (m_cart) m_cart->write_prg_bank(bank); } diff --git a/src/emu/bus/nes/nes_ines.inc b/src/emu/bus/nes/nes_ines.inc index c564697f982..77c1aca7d4a 100644 --- a/src/emu/bus/nes/nes_ines.inc +++ b/src/emu/bus/nes/nes_ines.inc @@ -342,14 +342,11 @@ void nes_cart_slot_device::call_load_ines() UINT8 header[0x10]; UINT8 mapper, submapper = 0, local_options; bool ines20 = FALSE, prg16k; - const char *mapinfo = NULL; + astring mapinfo; int pcb_id = 0, mapint1 = 0, mapint2 = 0, mapint3 = 0, mapint4 = 0; int crc_hack = 0; bool bus_conflict = FALSE; - // check if the image is recognized by nes.hsi - mapinfo = hashfile_extrainfo(*this); - // read out the header fseek(0, SEEK_SET); fread(&header, 0x10); @@ -380,7 +377,7 @@ void nes_cart_slot_device::call_load_ines() } // use info from nes.hsi if available! - if (mapinfo) + if (hashfile_extrainfo(*this, mapinfo)) { if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4)) { @@ -395,7 +392,7 @@ void nes_cart_slot_device::call_load_ines() } else { - logerror("NES: [%s], Invalid mapinfo found\n", mapinfo); + logerror("NES: [%s], Invalid mapinfo found\n", mapinfo.cstr()); } } else @@ -818,13 +815,10 @@ const char * nes_cart_slot_device::get_default_card_ines(UINT8 *ROM, UINT32 len) { UINT8 mapper, submapper = 0; bool ines20 = FALSE; - const char *mapinfo = NULL; + astring mapinfo; int pcb_id = 0, mapint1 = 0, mapint2 = 0, mapint3 = 0, mapint4 = 0; int crc_hack = 0; - // check if the image is recognized by nes.hsi -// mapinfo = hashfile_extrainfo(*this); - mapper = (ROM[6] & 0xf0) >> 4; switch (ROM[7] & 0xc) @@ -843,7 +837,8 @@ const char * nes_cart_slot_device::get_default_card_ines(UINT8 *ROM, UINT32 len) } // use info from nes.hsi if available! - if (mapinfo) +// if (hashfile_extrainfo(*this, mapinfo)) + if (0) { if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4)) { diff --git a/src/emu/bus/nes/nes_slot.c b/src/emu/bus/nes/nes_slot.c index 52a80b1618d..a206b4c69a6 100644 --- a/src/emu/bus/nes/nes_slot.c +++ b/src/emu/bus/nes/nes_slot.c @@ -957,9 +957,9 @@ void nes_cart_slot_device::call_unload() call softlist load -------------------------------------------------*/ -bool nes_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool nes_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -967,29 +967,28 @@ bool nes_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_en get default card software -------------------------------------------------*/ -const char * nes_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void nes_cart_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { const char *slot_string = "nrom"; UINT32 len = core_fsize(m_file); - UINT8 *ROM = global_alloc_array(UINT8, len); + dynamic_buffer rom(len); - core_fread(m_file, ROM, len); + core_fread(m_file, rom, len); - if ((ROM[0] == 'N') && (ROM[1] == 'E') && (ROM[2] == 'S')) - slot_string = get_default_card_ines(ROM, len); + if ((rom[0] == 'N') && (rom[1] == 'E') && (rom[2] == 'S')) + slot_string = get_default_card_ines(rom, len); - if ((ROM[0] == 'U') && (ROM[1] == 'N') && (ROM[2] == 'I') && (ROM[3] == 'F')) - slot_string = get_default_card_unif(ROM, len); + if ((rom[0] == 'U') && (rom[1] == 'N') && (rom[2] == 'I') && (rom[3] == 'F')) + slot_string = get_default_card_unif(rom, len); - global_free(ROM); clear(); - return slot_string; + result.cpy(slot_string); } else - return software_get_default_slot(config, options, this, "nrom"); + software_get_default_slot(result, "nrom"); } diff --git a/src/emu/bus/nes/nes_slot.h b/src/emu/bus/nes/nes_slot.h index a264caa64f5..b7a7c633603 100644 --- a/src/emu/bus/nes/nes_slot.h +++ b/src/emu/bus/nes/nes_slot.h @@ -346,7 +346,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); void call_load_ines(); void call_load_unif(); @@ -364,7 +364,7 @@ public: virtual device_image_partialhash_func get_partial_hash() const { return &nes_partialhash; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); const char * get_default_card_ines(UINT8 *ROM, UINT32 len); const char * get_default_card_unif(UINT8 *ROM, UINT32 len); const char * nes_get_slot(int pcb_id); diff --git a/src/emu/bus/nes/sunsoft_dcs.c b/src/emu/bus/nes/sunsoft_dcs.c index 015f45ed055..8150cc255bc 100644 --- a/src/emu/bus/nes/sunsoft_dcs.c +++ b/src/emu/bus/nes/sunsoft_dcs.c @@ -106,15 +106,15 @@ bool nes_ntb_slot_device::call_load() } -bool nes_ntb_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool nes_ntb_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } -const char * nes_ntb_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void nes_ntb_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "ntbrom"); + software_get_default_slot(result, "ntbrom"); } //----------------------------------------------- diff --git a/src/emu/bus/nes/sunsoft_dcs.h b/src/emu/bus/nes/sunsoft_dcs.h index 342af98a1fc..c11794fd640 100644 --- a/src/emu/bus/nes/sunsoft_dcs.h +++ b/src/emu/bus/nes/sunsoft_dcs.h @@ -46,7 +46,7 @@ public: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } @@ -59,7 +59,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); virtual DECLARE_READ8_MEMBER(read); diff --git a/src/emu/bus/plus4/exp.c b/src/emu/bus/plus4/exp.c index 6ee8212c236..d49bb98b970 100644 --- a/src/emu/bus/plus4/exp.c +++ b/src/emu/bus/plus4/exp.c @@ -148,9 +148,9 @@ bool plus4_expansion_slot_device::call_load() // call_softlist_load - //------------------------------------------------- -bool plus4_expansion_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool plus4_expansion_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry); + load_software_part_region(*this, swlist, swname, start_entry); return true; } @@ -160,9 +160,9 @@ bool plus4_expansion_slot_device::call_softlist_load(char *swlist, char *swname, // get_default_card_software - //------------------------------------------------- -const char * plus4_expansion_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void plus4_expansion_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "standard"); + software_get_default_slot(result, "standard"); } diff --git a/src/emu/bus/plus4/exp.h b/src/emu/bus/plus4/exp.h index 16bcb8096bf..dcdffcecdfc 100644 --- a/src/emu/bus/plus4/exp.h +++ b/src/emu/bus/plus4/exp.h @@ -116,7 +116,7 @@ protected: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } @@ -130,7 +130,7 @@ protected: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); devcb2_write_line m_write_irq; devcb2_read8 m_read_dma_cd; diff --git a/src/emu/bus/saturn/sat_slot.c b/src/emu/bus/saturn/sat_slot.c index cc6d66786e0..8db3368ed4a 100644 --- a/src/emu/bus/saturn/sat_slot.c +++ b/src/emu/bus/saturn/sat_slot.c @@ -173,9 +173,9 @@ void sat_cart_slot_device::call_unload() call softlist load -------------------------------------------------*/ -bool sat_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool sat_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -184,9 +184,9 @@ bool sat_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_en get default card software -------------------------------------------------*/ -const char * sat_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void sat_cart_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "rom"); + software_get_default_slot(result, "rom"); } diff --git a/src/emu/bus/saturn/sat_slot.h b/src/emu/bus/saturn/sat_slot.h index d610494e65c..9dc0070cd07 100644 --- a/src/emu/bus/saturn/sat_slot.h +++ b/src/emu/bus/saturn/sat_slot.h @@ -72,7 +72,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); int get_cart_type(); @@ -87,7 +87,7 @@ public: virtual const char *file_extensions() const { return "bin"; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing virtual DECLARE_READ32_MEMBER(read_rom); diff --git a/src/emu/bus/sega8/sega8_slot.c b/src/emu/bus/sega8/sega8_slot.c index c8ebf5297cb..e30306f3257 100644 --- a/src/emu/bus/sega8/sega8_slot.c +++ b/src/emu/bus/sega8/sega8_slot.c @@ -429,9 +429,9 @@ void sega8_cart_slot_device::call_unload() call softlist load -------------------------------------------------*/ -bool sega8_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool sega8_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry); + load_software_part_region(*this, swlist, swname, start_entry); return TRUE; } @@ -610,31 +610,31 @@ int sega8_cart_slot_device::get_cart_type(UINT8 *ROM, UINT32 len) get default card software -------------------------------------------------*/ -const char * sega8_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void sega8_cart_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { const char *slot_string = "rom"; UINT32 len = core_fsize(m_file), offset = 0; - UINT8 *ROM = global_alloc_array(UINT8, len); + dynamic_buffer rom(len); int type; - core_fread(m_file, ROM, len); + core_fread(m_file, rom, len); if ((len % 0x4000) == 512) offset = 512; - type = get_cart_type(ROM + offset, len - offset); + type = get_cart_type(rom + offset, len - offset); slot_string = sega8_get_slot(type); //printf("type: %s\n", slot_string); - global_free(ROM); clear(); - return slot_string; + result.cpy(slot_string); + return; } - return software_get_default_slot(config, options, this, "rom"); + software_get_default_slot(result, "rom"); } diff --git a/src/emu/bus/sega8/sega8_slot.h b/src/emu/bus/sega8/sega8_slot.h index 5f11457cc5a..c7d32c2e440 100644 --- a/src/emu/bus/sega8/sega8_slot.h +++ b/src/emu/bus/sega8/sega8_slot.h @@ -110,7 +110,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); int get_type() { return m_type; } int get_cart_type(UINT8 *ROM, UINT32 len); @@ -135,7 +135,7 @@ public: virtual const char *file_extensions() const { return m_extensions; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing virtual DECLARE_READ8_MEMBER(read_cart); diff --git a/src/emu/bus/snes/snes_slot.c b/src/emu/bus/snes/snes_slot.c index 6765685841f..735bfe856a0 100644 --- a/src/emu/bus/snes/snes_slot.c +++ b/src/emu/bus/snes/snes_slot.c @@ -909,9 +909,9 @@ void base_sns_cart_slot_device::setup_nvram() call softlist load -------------------------------------------------*/ -bool base_sns_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool base_sns_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -1024,23 +1024,23 @@ void base_sns_cart_slot_device::get_cart_type_addon(UINT8 *ROM, UINT32 len, int get default card software -------------------------------------------------*/ -const char * base_sns_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void base_sns_cart_slot_device::get_default_card_software(astring &result) { - bool fullpath = open_image_file(options); + bool fullpath = open_image_file(mconfig().options()); if (fullpath) { const char *slot_string = "lorom"; UINT32 offset = 0; UINT32 len = core_fsize(m_file); - UINT8 *ROM = global_alloc_array(UINT8, len); + dynamic_buffer rom(len); int type = 0, addon = 0; - core_fread(m_file, ROM, len); + core_fread(m_file, rom, len); - offset = snes_skip_header(ROM, len); + offset = snes_skip_header(rom, len); - get_cart_type_addon(ROM + offset, len - offset, type, addon); + get_cart_type_addon(rom + offset, len - offset, type, addon); // here we're from fullpath, so check if it's a DSP game which needs legacy device (i.e. it has no appended DSP dump) switch (addon) { @@ -1081,13 +1081,13 @@ const char * base_sns_cart_slot_device::get_default_card_software(const machine_ slot_string = sns_get_slot(type); - global_free(ROM); clear(); - return slot_string; + result.cpy(slot_string); + return; } - return software_get_default_slot(config, options, this, "lorom"); + software_get_default_slot(result, "lorom"); } diff --git a/src/emu/bus/snes/snes_slot.h b/src/emu/bus/snes/snes_slot.h index a5710cda74b..8951fb27a0c 100644 --- a/src/emu/bus/snes/snes_slot.h +++ b/src/emu/bus/snes/snes_slot.h @@ -166,7 +166,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); void get_cart_type_addon(UINT8 *ROM, UINT32 len, int &type, int &addon); UINT32 snes_skip_header(UINT8 *ROM, UINT32 snes_rom_size); @@ -184,7 +184,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing virtual DECLARE_READ8_MEMBER(read_l); diff --git a/src/emu/bus/vic10/exp.c b/src/emu/bus/vic10/exp.c index 4b698463325..0757af5edf9 100644 --- a/src/emu/bus/vic10/exp.c +++ b/src/emu/bus/vic10/exp.c @@ -173,9 +173,9 @@ bool vic10_expansion_slot_device::call_load() // call_softlist_load - //------------------------------------------------- -bool vic10_expansion_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool vic10_expansion_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry); + load_software_part_region(*this, swlist, swname, start_entry); return true; } @@ -185,19 +185,20 @@ bool vic10_expansion_slot_device::call_softlist_load(char *swlist, char *swname, // get_default_card_software - //------------------------------------------------- -const char * vic10_expansion_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void vic10_expansion_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { if (!mame_stricmp(filetype(), "crt")) { - return cbm_crt_get_card(m_file); + cbm_crt_get_card(result, m_file); + return; } clear(); } - return software_get_default_slot(config, options, this, "standard"); + software_get_default_slot(result, "standard"); } diff --git a/src/emu/bus/vic10/exp.h b/src/emu/bus/vic10/exp.h index 36d92009625..a190fbafd6c 100644 --- a/src/emu/bus/vic10/exp.h +++ b/src/emu/bus/vic10/exp.h @@ -115,7 +115,7 @@ protected: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } @@ -129,7 +129,7 @@ protected: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); devcb2_write_line m_write_irq; devcb2_write_line m_write_res; diff --git a/src/emu/bus/vic20/exp.c b/src/emu/bus/vic20/exp.c index 4ce4403e4bf..7f6cf3db6eb 100644 --- a/src/emu/bus/vic20/exp.c +++ b/src/emu/bus/vic20/exp.c @@ -158,9 +158,9 @@ bool vic20_expansion_slot_device::call_load() // call_softlist_load - //------------------------------------------------- -bool vic20_expansion_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool vic20_expansion_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry); + load_software_part_region(*this, swlist, swname, start_entry); return true; } @@ -170,9 +170,9 @@ bool vic20_expansion_slot_device::call_softlist_load(char *swlist, char *swname, // get_default_card_software - //------------------------------------------------- -const char * vic20_expansion_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void vic20_expansion_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "standard"); + software_get_default_slot(result, "standard"); } diff --git a/src/emu/bus/vic20/exp.h b/src/emu/bus/vic20/exp.h index aa9db53acfe..94e0c8fd145 100644 --- a/src/emu/bus/vic20/exp.h +++ b/src/emu/bus/vic20/exp.h @@ -108,7 +108,7 @@ protected: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } @@ -122,7 +122,7 @@ protected: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); devcb2_write_line m_write_irq; devcb2_write_line m_write_nmi; diff --git a/src/emu/bus/vidbrain/exp.c b/src/emu/bus/vidbrain/exp.c index 0645280cfc1..f2efbe9d2bd 100644 --- a/src/emu/bus/vidbrain/exp.c +++ b/src/emu/bus/vidbrain/exp.c @@ -188,9 +188,9 @@ bool videobrain_expansion_slot_device::call_load() // call_softlist_load - //------------------------------------------------- -bool videobrain_expansion_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool videobrain_expansion_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry); + load_software_part_region(*this, swlist, swname, start_entry); return true; } @@ -200,9 +200,9 @@ bool videobrain_expansion_slot_device::call_softlist_load(char *swlist, char *sw // get_default_card_software - //------------------------------------------------- -const char * videobrain_expansion_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void videobrain_expansion_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "standard"); + software_get_default_slot(result, "standard"); } diff --git a/src/emu/bus/vidbrain/exp.h b/src/emu/bus/vidbrain/exp.h index 018038350ec..dc07320b0f6 100644 --- a/src/emu/bus/vidbrain/exp.h +++ b/src/emu/bus/vidbrain/exp.h @@ -116,7 +116,7 @@ protected: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } @@ -130,7 +130,7 @@ protected: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); devcb_resolved_write_line m_out_extres_func; diff --git a/src/emu/bus/z88/z88.c b/src/emu/bus/z88/z88.c index c3b409c3eb0..1e3645114bb 100644 --- a/src/emu/bus/z88/z88.c +++ b/src/emu/bus/z88/z88.c @@ -184,9 +184,9 @@ void z88cart_slot_device::call_unload() call softlist load -------------------------------------------------*/ -bool z88cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool z88cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -194,9 +194,9 @@ bool z88cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_ent get default card software -------------------------------------------------*/ -const char * z88cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void z88cart_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(config, options, this, "128krom"); + software_get_default_slot(result, "128krom"); } diff --git a/src/emu/bus/z88/z88.h b/src/emu/bus/z88/z88.h index f853ac25d56..754aa0a824f 100644 --- a/src/emu/bus/z88/z88.h +++ b/src/emu/bus/z88/z88.h @@ -103,7 +103,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } @@ -116,7 +116,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing virtual DECLARE_READ8_MEMBER(read); diff --git a/src/emu/cheat.c b/src/emu/cheat.c index 4d591967d92..bd4e10ca58d 100644 --- a/src/emu/cheat.c +++ b/src/emu/cheat.c @@ -136,8 +136,7 @@ inline const char *number_and_format::format(astring &string) const //------------------------------------------------- cheat_parameter::cheat_parameter(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node ¶mnode) - : m_value(0), - m_itemlist(manager.machine().respool()) + : m_value(0) { // read the core attributes m_minval = number_and_format(xml_get_attribute_int(¶mnode, "min", 0), xml_get_attribute_int_format(¶mnode, "min")); @@ -160,7 +159,7 @@ cheat_parameter::cheat_parameter(cheat_manager &manager, symbol_table &symbols, int format = xml_get_attribute_int_format(itemnode, "value"); // allocate and append a new item - item &curitem = m_itemlist.append(*auto_alloc(manager.machine(), item(itemnode->value, value, format))); + item &curitem = m_itemlist.append(*global_alloc(item(itemnode->value, value, format))); // ensure the maximum expands to suit m_maxval = MAX(m_maxval, curitem.value()); @@ -317,8 +316,7 @@ bool cheat_parameter::set_next_state() //------------------------------------------------- cheat_script::cheat_script(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node &scriptnode) - : m_entrylist(manager.machine().respool()), - m_state(SCRIPT_STATE_RUN) + : m_state(SCRIPT_STATE_RUN) { // read the core attributes const char *state = xml_get_attribute_string(&scriptnode, "state", "run"); @@ -336,11 +334,11 @@ cheat_script::cheat_script(cheat_manager &manager, symbol_table &symbols, const { // handle action nodes if (strcmp(entrynode->name, "action") == 0) - m_entrylist.append(*auto_alloc(manager.machine(), script_entry(manager, symbols, filename, *entrynode, true))); + m_entrylist.append(*global_alloc(script_entry(manager, symbols, filename, *entrynode, true))); // handle output nodes else if (strcmp(entrynode->name, "output") == 0) - m_entrylist.append(*auto_alloc(manager.machine(), script_entry(manager, symbols, filename, *entrynode, false))); + m_entrylist.append(*global_alloc(script_entry(manager, symbols, filename, *entrynode, false))); // anything else is ignored else @@ -402,8 +400,7 @@ void cheat_script::save(emu_file &cheatfile) const cheat_script::script_entry::script_entry(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node &entrynode, bool isaction) : m_next(NULL), m_condition(&symbols), - m_expression(&symbols), - m_arglist(manager.machine().respool()) + m_expression(&symbols) { const char *expression = NULL; try @@ -446,7 +443,7 @@ cheat_script::script_entry::script_entry(cheat_manager &manager, symbol_table &s int totalargs = 0; for (xml_data_node *argnode = xml_get_sibling(entrynode.child, "argument"); argnode != NULL; argnode = xml_get_sibling(argnode->next, "argument")) { - output_argument &curarg = m_arglist.append(*auto_alloc(manager.machine(), output_argument(manager, symbols, filename, *argnode))); + output_argument &curarg = m_arglist.append(*global_alloc(output_argument(manager, symbols, filename, *argnode))); // verify we didn't overrun the argument count totalargs += curarg.count(); @@ -684,7 +681,6 @@ void cheat_script::script_entry::output_argument::save(emu_file &cheatfile) cons cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, const char *filename, xml_data_node &cheatnode) : m_manager(manager), m_next(NULL), - m_parameter(NULL), m_on_script(NULL), m_off_script(NULL), m_change_script(NULL), @@ -736,7 +732,7 @@ cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, cons if (paramnode != NULL) { // load this parameter - m_parameter = auto_alloc(manager.machine(), cheat_parameter(manager, m_symbols, filename, *paramnode)); + m_parameter.reset(global_alloc(cheat_parameter(manager, m_symbols, filename, *paramnode))); // only one parameter allowed paramnode = xml_get_sibling(paramnode->next, "parameter"); @@ -748,14 +744,14 @@ cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, cons for (xml_data_node *scriptnode = xml_get_sibling(cheatnode.child, "script"); scriptnode != NULL; scriptnode = xml_get_sibling(scriptnode->next, "script")) { // load this entry - cheat_script *curscript = auto_alloc(manager.machine(), cheat_script(manager, m_symbols, filename, *scriptnode)); + cheat_script *curscript = global_alloc(cheat_script(manager, m_symbols, filename, *scriptnode)); // if we have a script already for this slot, it is an error - cheat_script *&slot = script_for_state(curscript->state()); + auto_pointer &slot = script_for_state(curscript->state()); if (slot != NULL) mame_printf_warning("%s.xml(%d): only one on script allowed; ignoring additional scripts\n", filename, scriptnode->line); else - slot = curscript; + slot.reset(curscript); } } catch (emu_fatalerror &) @@ -773,11 +769,6 @@ cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, cons cheat_entry::~cheat_entry() { - auto_free(m_manager.machine(), m_on_script); - auto_free(m_manager.machine(), m_off_script); - auto_free(m_manager.machine(), m_change_script); - auto_free(m_manager.machine(), m_run_script); - auto_free(m_manager.machine(), m_parameter); } @@ -1034,7 +1025,7 @@ bool cheat_entry::set_state(script_state newstate) // given script pointer //------------------------------------------------- -cheat_script *&cheat_entry::script_for_state(script_state state) +auto_pointer &cheat_entry::script_for_state(script_state state) { switch (state) { @@ -1058,7 +1049,6 @@ cheat_script *&cheat_entry::script_for_state(script_state state) cheat_manager::cheat_manager(running_machine &machine) : m_machine(machine), - m_cheatlist(machine.respool()), m_disabled(true), m_symtable(&machine) { @@ -1411,7 +1401,7 @@ void cheat_manager::load_cheats(const char *filename) for (xml_data_node *cheatnode = xml_get_sibling(mamecheatnode->child, "cheat"); cheatnode != NULL; cheatnode = xml_get_sibling(cheatnode->next, "cheat")) { // load this entry - cheat_entry *curcheat = auto_alloc(machine(), cheat_entry(*this, m_symtable, filename, *cheatnode)); + cheat_entry *curcheat = global_alloc(cheat_entry(*this, m_symtable, filename, *cheatnode)); // make sure we're not a duplicate cheat_entry *scannode = NULL; @@ -1427,7 +1417,7 @@ void cheat_manager::load_cheats(const char *filename) if (scannode == NULL) m_cheatlist.append(*curcheat); else - auto_free(machine(), curcheat); + global_free(curcheat); } // free the file and loop for the next one diff --git a/src/emu/cheat.h b/src/emu/cheat.h index 81bfc999496..601687c7882 100644 --- a/src/emu/cheat.h +++ b/src/emu/cheat.h @@ -260,18 +260,18 @@ public: private: // internal helpers bool set_state(script_state newstate); - cheat_script *&script_for_state(script_state state); + auto_pointer &script_for_state(script_state state); // internal state cheat_manager & m_manager; // reference to our manager cheat_entry * m_next; // next cheat entry astring m_description; // string description/menu title astring m_comment; // comment data - cheat_parameter * m_parameter; // parameter - cheat_script * m_on_script; // script to run when turning on - cheat_script * m_off_script; // script to run when turning off - cheat_script * m_change_script; // script to run when value changes - cheat_script * m_run_script; // script to run each frame when on + auto_pointer m_parameter; // parameter + auto_pointer m_on_script; // script to run when turning on + auto_pointer m_off_script; // script to run when turning off + auto_pointer m_change_script; // script to run when value changes + auto_pointer m_run_script; // script to run each frame when on symbol_table m_symbols; // symbol table for this cheat script_state m_state; // current cheat state UINT32 m_numtemp; // number of temporary variables diff --git a/src/emu/clifront.c b/src/emu/clifront.c index 6e9846aa0bc..2167d47784d 100644 --- a/src/emu/clifront.c +++ b/src/emu/clifront.c @@ -94,7 +94,8 @@ cli_options::cli_options() cli_frontend::cli_frontend(cli_options &options, osd_interface &osd) : m_options(options), m_osd(osd), - m_result(MAMERR_NONE) + m_result(MAMERR_NONE), + m_start_memory(next_memory_id()) { // begin tracking memory track_memory(true); @@ -107,10 +108,13 @@ cli_frontend::cli_frontend(cli_options &options, osd_interface &osd) cli_frontend::~cli_frontend() { + // nuke any device options since they will leak memory + m_options.remove_device_options(); + // report any unfreed memory on clean exits track_memory(false); if (m_result == MAMERR_NONE) - dump_unfreed_mem(); + dump_unfreed_mem(m_start_memory); } @@ -128,6 +132,7 @@ int cli_frontend::execute(int argc, char **argv) // first parse options to be able to get software from it astring option_errors; m_options.parse_command_line(argc, argv, option_errors); + // We need to preprocess the config files once to determine the web server's configuration // and file locations if (m_options.read_config()) @@ -146,58 +151,56 @@ int cli_frontend::execute(int argc, char **argv) if (iter.first() == NULL) throw emu_fatalerror(MAMERR_FATALERROR, "Error: unknown option: %s\n", m_options.software_name()); - bool found = FALSE; - for (software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) + bool found = false; + for (software_list_device *swlistdev = iter.first(); swlistdev != NULL; swlistdev = iter.next()) { - software_list *list = software_list_open(m_options, swlist->list_name(), FALSE, NULL); - if (list) + software_info *swinfo = swlistdev->find(m_options.software_name()); + if (swinfo != NULL) { - software_info *swinfo = software_list_find(list, m_options.software_name(), NULL); - if (swinfo != NULL) + // loop through all parts + for (software_part *swpart = swinfo->first_part(); swpart != NULL; swpart = swpart->next()) { - // loop through all parts - for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) + const char *mount = swpart->feature("automount"); + if (swpart->is_compatible(*swlistdev)) { - const char *mount = software_part_get_feature(swpart, "automount"); - if (is_software_compatible(swpart, swlist)) + if (mount == NULL || strcmp(mount,"no") != 0) { - if (mount == NULL || strcmp(mount,"no") != 0) + // search for an image device with the right interface + image_interface_iterator imgiter(config.root_device()); + for (device_image_interface *image = imgiter.first(); image != NULL; image = imgiter.next()) { - // search for an image device with the right interface - image_interface_iterator imgiter(config.root_device()); - for (device_image_interface *image = imgiter.first(); image != NULL; image = imgiter.next()) + const char *interface = image->image_interface(); + if (interface != NULL) { - const char *interface = image->image_interface(); - if (interface != NULL) + if (swpart->matches_interface(interface)) { - if (softlist_contain_interface(interface, swpart->interface_)) + const char *option = m_options.value(image->brief_instance_name()); + + // mount only if not already mounted + if (*option == 0) { - const char *option = m_options.value(image->brief_instance_name()); - // mount only if not already mounted - if (*option == 0) - { - astring val; - val.printf("%s:%s:%s",swlist->list_name(),m_options.software_name(),swpart->name); - // call this in order to set slot devices according to mounting - m_options.parse_slot_devices(argc, argv, option_errors, image->instance_name(), val.cstr()); - break; - } + astring val; + val.printf("%s:%s:%s", swlistdev->list_name(), m_options.software_name(), swpart->name()); + + // call this in order to set slot devices according to mounting + m_options.parse_slot_devices(argc, argv, option_errors, image->instance_name(), val.cstr()); + break; } } } } - found = TRUE; } + found = true; } } - software_list_close(list); } - if (found) break; + if (found) + break; } if (!found) { - software_display_matches(config,m_options, NULL,m_options.software_name()); + software_list_device::display_matches(config, NULL, m_options.software_name()); throw emu_fatalerror(MAMERR_FATALERROR, NULL); } } @@ -229,6 +232,7 @@ int cli_frontend::execute(int argc, char **argv) const game_driver *system = m_options.system(); if (system == NULL && *(m_options.system_name()) != 0) throw emu_fatalerror(MAMERR_NO_SUCH_GAME, "Unknown system '%s'", m_options.system_name()); + // otherwise just run the game m_result = mame_execute(m_options, m_osd); } @@ -963,7 +967,6 @@ void cli_frontend::verifyroms(const char *gamename) } const_cast(config).device_remove(&config.root_device(), temptag.cstr()); - global_free(dev); } } } @@ -1143,54 +1146,41 @@ void cli_frontend::verifysamples(const char *gamename) "]>\n\n" \ "\n" -void cli_frontend::output_single_softlist(FILE *out,software_list *list, const char *listname) +void cli_frontend::output_single_softlist(FILE *out, software_list_device &swlistdev) { astring tempstr; - software_list_parse( list, NULL, NULL ); - fprintf(out, "\t\n", listname, xml_normalize_string(software_list_get_description(list)) ); - - for ( software_info *swinfo = software_list_find( list, "*", NULL ); swinfo != NULL; swinfo = software_list_find( list, "*", swinfo ) ) + fprintf(out, "\t\n", swlistdev.list_name(), xml_normalize_string(swlistdev.description())); + for (software_info *swinfo = swlistdev.first_software_info(); swinfo != NULL; swinfo = swinfo->next()) { - fprintf( out, "\t\tshortname ); - if ( swinfo->parentname != NULL ) - fprintf( out, " cloneof=\"%s\"", swinfo->parentname ); - if ( swinfo->supported == SOFTWARE_SUPPORTED_PARTIAL ) + fprintf( out, "\t\tshortname() ); + if ( swinfo->parentname() != NULL ) + fprintf( out, " cloneof=\"%s\"", swinfo->parentname() ); + if ( swinfo->supported() == SOFTWARE_SUPPORTED_PARTIAL ) fprintf( out, " supported=\"partial\"" ); - if ( swinfo->supported == SOFTWARE_SUPPORTED_NO ) + if ( swinfo->supported() == SOFTWARE_SUPPORTED_NO ) fprintf( out, " supported=\"no\"" ); fprintf( out, ">\n" ); - fprintf( out, "\t\t\t%s\n", xml_normalize_string(swinfo->longname) ); - fprintf( out, "\t\t\t%s\n", xml_normalize_string( swinfo->year ) ); - fprintf( out, "\t\t\t%s\n", xml_normalize_string( swinfo->publisher ) ); + fprintf( out, "\t\t\t%s\n", xml_normalize_string(swinfo->longname()) ); + fprintf( out, "\t\t\t%s\n", xml_normalize_string( swinfo->year() ) ); + fprintf( out, "\t\t\t%s\n", xml_normalize_string( swinfo->publisher() ) ); - feature_list *flist = swinfo->other_info; - while ( flist ) { - fprintf( out, "\t\t\t\n", flist->name, xml_normalize_string( flist->value ) ); - flist = flist->next; - } + for (feature_list_item *flist = swinfo->other_info(); flist != NULL; flist = flist->next()) + fprintf( out, "\t\t\t\n", flist->name(), xml_normalize_string( flist->value() ) ); - for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) ) + for ( software_part *part = swinfo->first_part(); part != NULL; part = part->next() ) { - fprintf( out, "\t\t\tname ); - if ( part->interface_ ) - fprintf( out, " interface=\"%s\"", part->interface_ ); + fprintf( out, "\t\t\tname() ); + if ( part->interface() != NULL ) + fprintf( out, " interface=\"%s\"", part->interface() ); fprintf( out, ">\n"); - if ( part->featurelist ) - { - feature_list *flist = part->featurelist; - - while( flist ) - { - fprintf( out, "\t\t\t\t\n", flist->name, xml_normalize_string(flist->value) ); - flist = flist->next; - } - } + for (feature_list_item *flist = part->featurelist(); flist != NULL; flist = flist->next()) + fprintf( out, "\t\t\t\t\n", flist->name(), xml_normalize_string(flist->value()) ); /* TODO: display rom region information */ - for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) ) + for ( const rom_entry *region = part->romdata(); region; region = rom_next_region( region ) ) { int is_disk = ROMREGION_ISDISKDATA(region); @@ -1286,7 +1276,7 @@ void cli_frontend::listsoftware(const char *gamename) { FILE *out = stdout; int_map list_map; - bool isfirst = TRUE; + bool isfirst = true; // determine which drivers to output; return an error if none found driver_enumerator drivlist(m_options, gamename); @@ -1296,25 +1286,14 @@ void cli_frontend::listsoftware(const char *gamename) while (drivlist.next()) { software_list_device_iterator iter(drivlist.config().root_device()); - for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) - { - if (swlist->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) - { - software_list *list = software_list_open(m_options, swlist->list_name(), FALSE, NULL); - - if ( list ) - { - /* Verify if we have encountered this list before */ - if (list_map.add(swlist->list_name(), 0, false) != TMERR_DUPLICATE) + for (software_list_device *swlistdev = iter.first(); swlistdev != NULL; swlistdev = iter.next()) + if (swlistdev->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) + if (list_map.add(swlistdev->list_name(), 0, false) != TMERR_DUPLICATE) + if (swlistdev->first_software_info() != NULL) { - if (isfirst) { fprintf( out, SOFTLIST_XML_BEGIN); isfirst = FALSE; } - output_single_softlist(out, list, swlist->list_name()); + if (isfirst) { fprintf(out, SOFTLIST_XML_BEGIN); isfirst = false; } + output_single_softlist(out, *swlistdev); } - - software_list_close( list ); - } - } - } } if (!isfirst) @@ -1351,25 +1330,15 @@ void cli_frontend::verifysoftware(const char *gamename) matched++; software_list_device_iterator iter(drivlist.config().root_device()); - for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) - { - if (swlist->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) - { - software_list *list = software_list_open(m_options, swlist->list_name(), FALSE, NULL); - - if ( list ) - { - /* Verify if we have encountered this list before */ - if (list_map.add(swlist->list_name(), 0, false) != TMERR_DUPLICATE) + for (software_list_device *swlistdev = iter.first(); swlistdev != NULL; swlistdev = iter.next()) + if (swlistdev->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) + if (list_map.add(swlistdev->list_name(), 0, false) != TMERR_DUPLICATE) + if (swlistdev->first_software_info() != NULL) { nrlists++; - - // Get the actual software list contents - software_list_parse( list, NULL, NULL ); - - for ( software_info *swinfo = software_list_find( list, "*", NULL ); swinfo != NULL; swinfo = software_list_find( list, "*", swinfo ) ) + for (software_info *swinfo = swlistdev->first_software_info(); swinfo != NULL; swinfo = swinfo->next()) { - media_auditor::summary summary = auditor.audit_software(swlist->list_name(), swinfo, AUDIT_VALIDATE_FAST); + media_auditor::summary summary = auditor.audit_software(swlistdev->list_name(), swinfo, AUDIT_VALIDATE_FAST); // if not found, count that and leave it at that if (summary == media_auditor::NOTFOUND) @@ -1381,11 +1350,11 @@ void cli_frontend::verifysoftware(const char *gamename) { // output the summary of the audit astring summary_string; - auditor.summarize(swinfo->shortname,&summary_string); + auditor.summarize(swinfo->shortname(), &summary_string); mame_printf_info("%s", summary_string.cstr()); // display information about what we discovered - mame_printf_info("romset %s:%s ", swlist->list_name(), swinfo->shortname); + mame_printf_info("romset %s:%s ", swlistdev->list_name(), swinfo->shortname()); // switch off of the result switch (summary) @@ -1411,11 +1380,6 @@ void cli_frontend::verifysoftware(const char *gamename) } } } - - software_list_close( list ); - } - } - } } // clear out any cached files @@ -1454,19 +1418,13 @@ void cli_frontend::getsoftlist(const char *gamename) while (drivlist.next()) { software_list_device_iterator iter(drivlist.config().root_device()); - for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) - { - software_list *list = software_list_open(m_options, swlist->list_name(), FALSE, NULL); - if ( list ) - { - if ((mame_strwildcmp(swlist->list_name(),gamename)==0) && list_map.add(swlist->list_name(), 0, false) != TMERR_DUPLICATE) + for (software_list_device *swlistdev = iter.first(); swlistdev != NULL; swlistdev = iter.next()) + if (mame_strwildcmp(swlistdev->list_name(), gamename) == 0 && list_map.add(swlistdev->list_name(), 0, false) != TMERR_DUPLICATE) + if (swlistdev->first_software_info() != NULL) { if (isfirst) { fprintf( out, SOFTLIST_XML_BEGIN); isfirst = FALSE; } - output_single_softlist(out, list, swlist->list_name()); + output_single_softlist(out, *swlistdev); } - software_list_close( list ); - } - } } if (!isfirst) @@ -1493,21 +1451,16 @@ void cli_frontend::verifysoftlist(const char *gamename) while (drivlist.next()) { software_list_device_iterator iter(drivlist.config().root_device()); - for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) - { - software_list *list = software_list_open(m_options, swlist->list_name(), FALSE, NULL); - if ( list ) - { - if ((mame_strwildcmp(swlist->list_name(),gamename)==0) && list_map.add(swlist->list_name(), 0, false) != TMERR_DUPLICATE) + for (software_list_device *swlistdev = iter.first(); swlistdev != NULL; swlistdev = iter.next()) + if (mame_strwildcmp(swlistdev->list_name(), gamename) == 0 && list_map.add(swlistdev->list_name(), 0, false) != TMERR_DUPLICATE) + if (swlistdev->first_software_info() != NULL) { matched++; // Get the actual software list contents - software_list_parse( list, NULL, NULL ); - - for ( software_info *swinfo = software_list_find( list, "*", NULL ); swinfo != NULL; swinfo = software_list_find( list, "*", swinfo ) ) + for (software_info *swinfo = swlistdev->first_software_info(); swinfo != NULL; swinfo = swinfo->next()) { - media_auditor::summary summary = auditor.audit_software(swlist->list_name(), swinfo, AUDIT_VALIDATE_FAST); + media_auditor::summary summary = auditor.audit_software(swlistdev->list_name(), swinfo, AUDIT_VALIDATE_FAST); // if not found, count that and leave it at that if (summary == media_auditor::NOTFOUND) @@ -1515,15 +1468,15 @@ void cli_frontend::verifysoftlist(const char *gamename) notfound++; } // else display information about what we discovered - else if(summary != media_auditor::NONE_NEEDED) + else if (summary != media_auditor::NONE_NEEDED) { // output the summary of the audit astring summary_string; - auditor.summarize(swinfo->shortname,&summary_string); + auditor.summarize(swinfo->shortname(), &summary_string); mame_printf_info("%s", summary_string.cstr()); // display information about what we discovered - mame_printf_info("romset %s:%s ", swlist->list_name(), swinfo->shortname); + mame_printf_info("romset %s:%s ", swlistdev->list_name(), swinfo->shortname()); // switch off of the result switch (summary) @@ -1549,9 +1502,6 @@ void cli_frontend::verifysoftlist(const char *gamename) } } } - software_list_close( list ); - } - } } // clear out any cached files @@ -1787,8 +1737,8 @@ void media_identifier::identify(const char *filename) const CSzFileItem *f = _7z->db.db.Files + i; _7z->curr_file_idx = i; int namelen = SzArEx_GetFileNameUtf16(&_7z->db, i, NULL); - UINT16* temp = (UINT16 *)malloc(namelen * sizeof(UINT16)); - void* temp2 = malloc((namelen+1) * sizeof(UINT8)); + dynamic_array temp(namelen); + dynamic_buffer temp2(namelen+1); UINT8* temp3 = (UINT8*)temp2; memset(temp3, 0x00, namelen); SzArEx_GetFileNameUtf16(&_7z->db, i, temp); @@ -1800,19 +1750,12 @@ void media_identifier::identify(const char *filename) if (!(f->IsDir) && (f->Size != 0)) { - UINT8 *data = global_alloc_array(UINT8, f->Size); - if (data != NULL) - { - // decompress data into RAM and identify it - _7zerr = _7z_file_decompress(_7z, data, f->Size); - if (_7zerr == _7ZERR_NONE) - identify_data((const char*)temp2, data, f->Size); - global_free(data); - } + // decompress data into RAM and identify it + dynamic_buffer data(f->Size); + _7zerr = _7z_file_decompress(_7z, data, f->Size); + if (_7zerr == _7ZERR_NONE) + identify_data((const char*)&temp2[0], data, f->Size); } - - free(temp); - free(temp2); } // close up @@ -1833,15 +1776,11 @@ void media_identifier::identify(const char *filename) for (const zip_file_header *entry = zip_file_first_file(zip); entry != NULL; entry = zip_file_next_file(zip)) if (entry->uncompressed_length != 0) { - UINT8 *data = global_alloc_array(UINT8, entry->uncompressed_length); - if (data != NULL) - { - // decompress data into RAM and identify it - ziperr = zip_file_decompress(zip, data, entry->uncompressed_length); - if (ziperr == ZIPERR_NONE) - identify_data(entry->filename, data, entry->uncompressed_length); - global_free(data); - } + // decompress data into RAM and identify it + dynamic_buffer data(entry->uncompressed_length); + ziperr = zip_file_decompress(zip, data, entry->uncompressed_length); + if (ziperr == ZIPERR_NONE) + identify_data(entry->filename, data, entry->uncompressed_length); } // close up @@ -1927,13 +1866,13 @@ void media_identifier::identify_file(const char *name) void media_identifier::identify_data(const char *name, const UINT8 *data, int length) { // if this is a '.jed' file, process it into raw bits first - UINT8 *tempjed = NULL; + dynamic_buffer tempjed; jed_data jed; if (core_filename_ends_with(name, ".jed") && jed_parse(data, length, &jed) == JEDERR_NONE) { // now determine the new data length and allocate temporary memory for it length = jedbin_output(&jed, NULL, 0); - tempjed = global_alloc_array(UINT8, length); + tempjed.resize(length); jedbin_output(&jed, tempjed, length); data = tempjed; } @@ -1968,9 +1907,6 @@ void media_identifier::identify_data(const char *name, const UINT8 *data, int le // if we did find it, count it as a match else m_matches++; - - // free any temporary JED data - global_free(tempjed); } @@ -2008,13 +1944,11 @@ int media_identifier::find_by_hash(const hash_collection &hashes, int length) // next iterate over softlists software_list_device_iterator iter(m_drivlist.config().root_device()); - for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) + for (software_list_device *swlistdev = iter.first(); swlistdev != NULL; swlistdev = iter.next()) { - software_list *list = software_list_open(m_drivlist.options(), swlist->list_name(), FALSE, NULL); - - for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) - for (software_part *part = software_find_part(swinfo, NULL, NULL); part != NULL; part = software_part_next(part)) - for (const rom_entry *region = part->romdata; region != NULL; region = rom_next_region(region)) + for (software_info *swinfo = swlistdev->first_software_info(); swinfo != NULL; swinfo = swinfo->next()) + for (software_part *part = swinfo->first_part(); part != NULL; part = part->next()) + for (const rom_entry *region = part->romdata(); region != NULL; region = rom_next_region(region)) for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) { hash_collection romhashes(ROM_GETHASHDATA(rom)); @@ -2025,11 +1959,10 @@ int media_identifier::find_by_hash(const hash_collection &hashes, int length) // output information about the match if (found) mame_printf_info(" "); - mame_printf_info("= %s%-20s %s:%s %s\n", baddump ? "(BAD) " : "", ROM_GETNAME(rom), swlist->list_name(), swinfo->shortname, swinfo->longname); + mame_printf_info("= %s%-20s %s:%s %s\n", baddump ? "(BAD) " : "", ROM_GETNAME(rom), swlistdev->list_name(), swinfo->shortname(), swinfo->longname()); found++; } } - software_list_close(list); } } diff --git a/src/emu/clifront.h b/src/emu/clifront.h index 9d5381e5b01..dfa2bc721d9 100644 --- a/src/emu/clifront.h +++ b/src/emu/clifront.h @@ -72,6 +72,7 @@ private: class cli_frontend { typedef tagmap_t int_map; + public: // construction/destruction cli_frontend(cli_options &options, osd_interface &osd); @@ -107,12 +108,13 @@ private: void execute_commands(const char *exename); void display_help(); void display_suggestions(const char *gamename); - void output_single_softlist(FILE *out,software_list *list, const char *listname); + void output_single_softlist(FILE *out, software_list_device &swlist); // internal state cli_options & m_options; osd_interface & m_osd; int m_result; + UINT64 m_start_memory; }; diff --git a/src/emu/cpu/drcfe.c b/src/emu/cpu/drcfe.c index b1f0957005d..d4bae00ad81 100644 --- a/src/emu/cpu/drcfe.c +++ b/src/emu/cpu/drcfe.c @@ -55,8 +55,6 @@ drc_frontend::drc_frontend(device_t &cpu, UINT32 window_start, UINT32 window_end m_cpudevice(downcast(cpu)), m_program(m_cpudevice.space(AS_PROGRAM)), m_pageshift(m_cpudevice.space_config(AS_PROGRAM)->m_page_shift), - m_desc_live_list(cpu.machine().respool()), - m_desc_allocator(cpu.machine().respool()), m_desc_array(window_end + window_start + 2, 0) { } diff --git a/src/emu/cpu/drcuml.c b/src/emu/cpu/drcuml.c index 42519ccd368..9096f0b8d8c 100644 --- a/src/emu/cpu/drcuml.c +++ b/src/emu/cpu/drcuml.c @@ -124,9 +124,7 @@ drcuml_state::drcuml_state(device_t &device, drc_cache &cache, UINT32 flags, int m_beintf((device.machine().options().drc_use_c()) ? *static_cast(auto_alloc(device.machine(), drcbe_c(*this, device, cache, flags, modes, addrbits, ignorebits))) : *static_cast(auto_alloc(device.machine(), drcbe_native(*this, device, cache, flags, modes, addrbits, ignorebits)))), - m_umllog(NULL), - m_blocklist(device.machine().respool()), - m_symlist(device.machine().respool()) + m_umllog(NULL) { // if we're to log, create the logfile if (flags & DRCUML_OPTION_LOG_UML) @@ -201,7 +199,7 @@ drcuml_block *drcuml_state::begin_block(UINT32 maxinst) // if we failed to find one, allocate a new one if (bestblock == NULL) - bestblock = &m_blocklist.append(*auto_alloc(m_device.machine(), drcuml_block(*this, maxinst * 3/2))); + bestblock = &m_blocklist.append(*global_alloc(drcuml_block(*this, maxinst * 3/2))); // start the block bestblock->begin(); @@ -216,7 +214,7 @@ drcuml_block *drcuml_state::begin_block(UINT32 maxinst) code_handle *drcuml_state::handle_alloc(const char *name) { // allocate the handle, add it to our list, and return it - return &m_handlelist.append(*auto_alloc(m_device.machine(), code_handle(*this, name))); + return &m_handlelist.append(*global_alloc(code_handle(*this, name))); } @@ -227,7 +225,7 @@ code_handle *drcuml_state::handle_alloc(const char *name) void drcuml_state::symbol_add(void *base, UINT32 length, const char *name) { - m_symlist.append(*auto_alloc(m_device.machine(), symbol(base, length, name))); + m_symlist.append(*global_alloc(symbol(base, length, name))); } diff --git a/src/emu/cpu/dsp56k/inst.c b/src/emu/cpu/dsp56k/inst.c index 58c3bf67aed..1c69cfd21dc 100644 --- a/src/emu/cpu/dsp56k/inst.c +++ b/src/emu/cpu/dsp56k/inst.c @@ -26,28 +26,26 @@ Instruction* Instruction::decodeInstruction(const Opcode* opc, // Avoid "05-- 05--" recursion if (shifted) return NULL; - Instruction* op = decodeInstruction(opc, w0, w1, true); + auto_pointer op(decodeInstruction(opc, w0, w1, true)); if (op) { // This parallel move only works for certain trailing instructions. - if (dynamic_cast(op) || - dynamic_cast(op) || - dynamic_cast(op) || - dynamic_cast(op) || - dynamic_cast(op) || - dynamic_cast(op) || - dynamic_cast(op) || - dynamic_cast(op) || - dynamic_cast(op) || - dynamic_cast(op) + if (dynamic_cast(op.get()) || + dynamic_cast(op.get()) || + dynamic_cast(op.get()) || + dynamic_cast(op.get()) || + dynamic_cast(op.get()) || + dynamic_cast(op.get()) || + dynamic_cast(op.get()) || + dynamic_cast(op.get()) || + dynamic_cast(op.get()) || + dynamic_cast(op.get()) /* TODO: More? */) { op->m_sizeIncrement = 1; return op; } } - - global_free(op); } diff --git a/src/emu/cpu/dsp56k/opcode.c b/src/emu/cpu/dsp56k/opcode.c index d695ec0a501..58ade2b7b30 100644 --- a/src/emu/cpu/dsp56k/opcode.c +++ b/src/emu/cpu/dsp56k/opcode.c @@ -6,15 +6,13 @@ namespace DSP56K { Opcode::Opcode(UINT16 w0, UINT16 w1) : m_word0(w0)/*, m_word1(w1)*/ { - m_instruction = Instruction::decodeInstruction(this, w0, w1); - m_parallelMove = ParallelMove::decodeParallelMove(this, w0, w1); + m_instruction.reset(Instruction::decodeInstruction(this, w0, w1)); + m_parallelMove.reset(ParallelMove::decodeParallelMove(this, w0, w1)); } Opcode::~Opcode() { - global_free(m_instruction); - global_free(m_parallelMove); } diff --git a/src/emu/cpu/dsp56k/opcode.h b/src/emu/cpu/dsp56k/opcode.h index 75e93885f84..da6a8a87d1b 100644 --- a/src/emu/cpu/dsp56k/opcode.h +++ b/src/emu/cpu/dsp56k/opcode.h @@ -32,8 +32,8 @@ public: const size_t instAccumulatorBitsModified() const; private: - Instruction* m_instruction; - ParallelMove* m_parallelMove; + auto_pointer m_instruction; + auto_pointer m_parallelMove; UINT16 m_word0; //UINT16 m_word1; diff --git a/src/emu/cpu/jaguar/jaguar.c b/src/emu/cpu/jaguar/jaguar.c index e9a3f3d8dc9..a35492ace44 100644 --- a/src/emu/cpu/jaguar/jaguar.c +++ b/src/emu/cpu/jaguar/jaguar.c @@ -441,11 +441,11 @@ jaguar_cpu_device::~jaguar_cpu_device() return; if (mirror_table != NULL) - global_free(mirror_table); + global_free_array(mirror_table); mirror_table = NULL; if (condition_table != NULL) - global_free(condition_table); + global_free_array(condition_table); condition_table = NULL; } diff --git a/src/emu/crsshair.c b/src/emu/crsshair.c index 70e9f05ac93..b99a1f5d679 100644 --- a/src/emu/crsshair.c +++ b/src/emu/crsshair.c @@ -38,7 +38,7 @@ struct crosshair_global UINT8 visible[MAX_PLAYERS]; /* visibility per player */ bitmap_argb32 * bitmap[MAX_PLAYERS]; /* bitmap per player */ render_texture * texture[MAX_PLAYERS]; /* texture per player */ - device_t *screen[MAX_PLAYERS]; /* the screen on which this player's crosshair is drawn */ + screen_device * screen[MAX_PLAYERS]; /* the screen on which this player's crosshair is drawn */ float x[MAX_PLAYERS]; /* current X position */ float y[MAX_PLAYERS]; /* current Y position */ float last_x[MAX_PLAYERS]; /* last X position */ @@ -405,7 +405,7 @@ void crosshair_render(screen_device &screen) given player's crosshair -------------------------------------------------*/ -void crosshair_set_screen(running_machine &machine, int player, device_t *screen) +void crosshair_set_screen(running_machine &machine, int player, screen_device *screen) { global.screen[player] = screen; } diff --git a/src/emu/crsshair.h b/src/emu/crsshair.h index af316f55c5d..e572e2f35ee 100644 --- a/src/emu/crsshair.h +++ b/src/emu/crsshair.h @@ -19,8 +19,8 @@ CONSTANTS ***************************************************************************/ -#define CROSSHAIR_SCREEN_NONE ((device_t *) 0) -#define CROSSHAIR_SCREEN_ALL ((device_t *) ~0) +#define CROSSHAIR_SCREEN_NONE ((screen_device *) 0) +#define CROSSHAIR_SCREEN_ALL ((screen_device *) ~0) /* user settings for visibility mode */ #define CROSSHAIR_VISIBILITY_OFF 0 @@ -64,7 +64,7 @@ void crosshair_init(running_machine &machine); void crosshair_render(screen_device &screen); /* sets the screen(s) for a given player's crosshair */ -void crosshair_set_screen(running_machine &machine, int player, device_t *screen); +void crosshair_set_screen(running_machine &machine, int player, screen_device *screen); /* return TRUE if any crosshairs are used */ int crosshair_get_usage(running_machine &machine); diff --git a/src/emu/debug/debugvw.c b/src/emu/debug/debugvw.c index 6d4ff66056c..d00240cc923 100644 --- a/src/emu/debug/debugvw.c +++ b/src/emu/debug/debugvw.c @@ -59,115 +59,6 @@ debug_view_source::~debug_view_source() // DEBUG VIEW SOURCE LIST //************************************************************************** -//------------------------------------------------- -// debug_view_source_list - constructor -//------------------------------------------------- - -debug_view_source_list::debug_view_source_list(running_machine &machine) - : m_machine(machine), - m_head(NULL), - m_tail(NULL), - m_count(0) -{ -} - - -//------------------------------------------------- -// ~debug_view_source_list - destructor -//------------------------------------------------- - -debug_view_source_list::~debug_view_source_list() -{ - reset(); -} - - -//------------------------------------------------- -// index - return the index of a source -//------------------------------------------------- - -int debug_view_source_list::index(const debug_view_source &source) const -{ - int result = 0; - for (debug_view_source *cursource = m_head; cursource != NULL; cursource = cursource->m_next) - { - if (cursource == &source) - break; - result++; - } - return result; -} - - -//------------------------------------------------- -// by_index - return a source given an index -//------------------------------------------------- - -const debug_view_source *debug_view_source_list::by_index(int index) const -{ - if (m_head == NULL) - return NULL; - const debug_view_source *result; - for (result = m_head; index > 0 && result->m_next != NULL; result = result->m_next) - index--; - return result; -} - - -//------------------------------------------------- -// reset - free all the view_sources -//------------------------------------------------- - -void debug_view_source_list::reset() -{ - // free from the head - while (m_head != NULL) - { - debug_view_source *source = m_head; - m_head = source->m_next; - auto_free(machine(), source); - } - - // reset the tail pointer and index - m_tail = NULL; - m_count = 0; -} - - -//------------------------------------------------- -// append - add a view_source to the end of the -// list -//------------------------------------------------- - -void debug_view_source_list::append(debug_view_source &source) -{ - // set the next and index values - source.m_next = NULL; - - // append to the end - if (m_tail == NULL) - m_head = m_tail = &source; - else - m_tail->m_next = &source; - m_tail = &source; - m_count++; -} - - -//------------------------------------------------- -// match_device - find the first view that -// matches the given device -//------------------------------------------------- - -const debug_view_source *debug_view_source_list::match_device(device_t *device) const -{ - for (debug_view_source *source = m_head; source != NULL; source = source->m_next) - if (device == source->m_device) - return source; - return m_head; -} - - //************************************************************************** // DEBUG VIEW @@ -181,7 +72,6 @@ debug_view::debug_view(running_machine &machine, debug_view_type type, debug_vie : m_next(NULL), m_type(type), m_source(NULL), - m_source_list(machine), m_osdupdate(osdupdate), m_osdprivate(osdprivate), m_visible(10,10), @@ -341,6 +231,20 @@ void debug_view::set_source(const debug_view_source &source) } +//------------------------------------------------- +// source_for_device - find the first source that +// matches the given device +//------------------------------------------------- + +const debug_view_source *debug_view::source_for_device(device_t *device) const +{ + for (debug_view_source *source = m_source_list.first(); source != NULL; source = source->next()) + if (device == source->device()) + return source; + return m_source_list.first(); +} + + //------------------------------------------------- // adjust_visible_x_for_cursor - adjust a view's // visible X position to ensure the cursor is diff --git a/src/emu/debug/debugvw.h b/src/emu/debug/debugvw.h index 50f84dd6b57..70db5910448 100644 --- a/src/emu/debug/debugvw.h +++ b/src/emu/debug/debugvw.h @@ -113,7 +113,7 @@ class debug_view_source { DISABLE_COPYING(debug_view_source); - friend class debug_view_source_list; + friend class simple_list; public: // construction/destruction @@ -135,38 +135,6 @@ private: }; -// a debug_view_source_list contains a list of debug_view_sources -class debug_view_source_list -{ - DISABLE_COPYING(debug_view_source_list); - -public: - // construction/destruction - debug_view_source_list(running_machine &machine); - ~debug_view_source_list(); - - // getters - running_machine &machine() const { return m_machine; } - const debug_view_source *head() const { return m_head; } - int count() const { return m_count; } - int index(const debug_view_source &source) const; - const debug_view_source *by_index(int index) const; - - // operations - void reset(); - void append(debug_view_source &view_source); - const debug_view_source *match_device(device_t *device) const; - int match_device_index(device_t *device) const { return index(*match_device(device)); } - -private: - // internal state - running_machine & m_machine; // reference to our machine - debug_view_source * m_head; // head of the list - debug_view_source * m_tail; // end of the tail - UINT32 m_count; // number of items in the list -}; - - // debug_view describes a single text-based view class debug_view { @@ -190,7 +158,8 @@ public: bool cursor_supported() { flush_updates(); return m_supports_cursor; } bool cursor_visible() { flush_updates(); return m_cursor_visible; } const debug_view_source *source() const { return m_source; } - const debug_view_source_list &source_list() const { return m_source_list; } + const debug_view_source *first_source() { return m_source_list.first(); } + const simple_list &source_list() const { return m_source_list; } // setters void set_size(int width, int height); @@ -199,8 +168,11 @@ public: void set_cursor_position(debug_view_xy pos); void set_cursor_visible(bool visible = true); void set_source(const debug_view_source &source); + + // helpers void process_char(int character) { view_char(character); } void process_click(int button, debug_view_xy pos) { view_click(button, pos); } + const debug_view_source *source_for_device(device_t *device) const; protected: // internal updating helpers @@ -225,7 +197,7 @@ protected: debug_view * m_next; // link to the next view debug_view_type m_type; // type of view const debug_view_source *m_source; // currently selected data source - debug_view_source_list m_source_list; // list of available data sources + simple_list m_source_list; // list of available data sources // OSD data debug_view_osd_update_func m_osdupdate; // callback for the update diff --git a/src/emu/debug/dvbpoints.c b/src/emu/debug/dvbpoints.c index 904e5df0386..9b48bc96787 100644 --- a/src/emu/debug/dvbpoints.c +++ b/src/emu/debug/dvbpoints.c @@ -64,11 +64,11 @@ void debug_view_breakpoints::enumerate_sources() { astring name; name.printf("%s '%s'", dasm->device().name(), dasm->device().tag()); - m_source_list.append(*auto_alloc(machine(), debug_view_source(name.cstr(), &dasm->device()))); + m_source_list.append(*global_alloc(debug_view_source(name.cstr(), &dasm->device()))); } // reset the source to a known good entry - set_source(*m_source_list.head()); + set_source(*m_source_list.first()); } @@ -262,7 +262,7 @@ int debug_view_breakpoints::breakpoints(SortMode sort, device_debug::breakpoint* // Alloc int numBPs = 0; bpList = NULL; - for (const debug_view_source *source = m_source_list.head(); source != NULL; source = source->next()) + for (const debug_view_source *source = m_source_list.first(); source != NULL; source = source->next()) { const device_debug& debugInterface = *source->device()->debug(); for (device_debug::breakpoint *bp = debugInterface.breakpoint_first(); bp != NULL; bp = bp->next()) @@ -271,7 +271,7 @@ int debug_view_breakpoints::breakpoints(SortMode sort, device_debug::breakpoint* bpList = new device_debug::breakpoint*[numBPs]; int bpAddIndex = 0; - for (const debug_view_source *source = m_source_list.head(); source != NULL; source = source->next()) + for (const debug_view_source *source = m_source_list.first(); source != NULL; source = source->next()) { // Collect device_debug& debugInterface = *source->device()->debug(); diff --git a/src/emu/debug/dvdisasm.c b/src/emu/debug/dvdisasm.c index ef65d329c71..cba167a2160 100644 --- a/src/emu/debug/dvdisasm.c +++ b/src/emu/debug/dvdisasm.c @@ -62,7 +62,7 @@ debug_view_disasm::debug_view_disasm(running_machine &machine, debug_view_osd_up // count the number of comments int total_comments = 0; - for (const debug_view_source *source = m_source_list.head(); source != NULL; source = source->next()) + for (const debug_view_source *source = m_source_list.first(); source != NULL; source = source->next()) { const debug_view_disasm_source &dasmsource = downcast(*source); total_comments += dasmsource.m_device.debug()->comment_count(); @@ -99,11 +99,11 @@ void debug_view_disasm::enumerate_sources() for (device_disasm_interface *dasm = iter.first(); dasm != NULL; dasm = iter.next()) { name.printf("%s '%s'", dasm->device().name(), dasm->device().tag()); - m_source_list.append(*auto_alloc(machine(), debug_view_disasm_source(name, dasm->device()))); + m_source_list.append(*global_alloc(debug_view_disasm_source(name, dasm->device()))); } // reset the source to a known good entry - set_source(*m_source_list.head()); + set_source(*m_source_list.first()); } diff --git a/src/emu/debug/dvmemory.c b/src/emu/debug/dvmemory.c index 7f303c84a29..ff38b03717d 100644 --- a/src/emu/debug/dvmemory.c +++ b/src/emu/debug/dvmemory.c @@ -131,14 +131,14 @@ void debug_view_memory::enumerate_sources() { address_space &space = memintf->space(spacenum); name.printf("%s '%s' %s space memory", memintf->device().name(), memintf->device().tag(), space.name()); - m_source_list.append(*auto_alloc(machine(), debug_view_memory_source(name, space))); + m_source_list.append(*global_alloc(debug_view_memory_source(name, space))); } // then add all the memory regions for (memory_region *region = machine().memory().first_region(); region != NULL; region = region->next()) { name.printf("Region '%s'", region->name()); - m_source_list.append(*auto_alloc(machine(), debug_view_memory_source(name, *region))); + m_source_list.append(*global_alloc(debug_view_memory_source(name, *region))); } // finally add all global array symbols @@ -156,12 +156,12 @@ void debug_view_memory::enumerate_sources() if (strncmp(itemname, "timer/", 6)) { name.cpy(itemname); - m_source_list.append(*auto_alloc(machine(), debug_view_memory_source(name, base, valsize, valcount))); + m_source_list.append(*global_alloc(debug_view_memory_source(name, base, valsize, valcount))); } } // reset the source to a known good entry - set_source(*m_source_list.head()); + set_source(*m_source_list.first()); } diff --git a/src/emu/debug/dvstate.c b/src/emu/debug/dvstate.c index 452f7ef5619..a2f6c24dacc 100644 --- a/src/emu/debug/dvstate.c +++ b/src/emu/debug/dvstate.c @@ -79,11 +79,11 @@ void debug_view_state::enumerate_sources() for (device_state_interface *state = iter.first(); state != NULL; state = iter.next()) { name.printf("%s '%s'", state->device().name(), state->device().tag()); - m_source_list.append(*auto_alloc(machine(), debug_view_state_source(name, state->device()))); + m_source_list.append(*global_alloc(debug_view_state_source(name, state->device()))); } // reset the source to a known good entry - set_source(*m_source_list.head()); + set_source(*m_source_list.first()); } diff --git a/src/emu/debug/dvwpoints.c b/src/emu/debug/dvwpoints.c index 234080bfe14..e9ff9a8754d 100644 --- a/src/emu/debug/dvwpoints.c +++ b/src/emu/debug/dvwpoints.c @@ -63,11 +63,11 @@ void debug_view_watchpoints::enumerate_sources() { astring name; name.printf("%s '%s'", dasm->device().name(), dasm->device().tag()); - m_source_list.append(*auto_alloc(machine(), debug_view_source(name.cstr(), &dasm->device()))); + m_source_list.append(*global_alloc(debug_view_source(name.cstr(), &dasm->device()))); } // reset the source to a known good entry - set_source(*m_source_list.head()); + set_source(*m_source_list.first()); } @@ -299,7 +299,7 @@ int debug_view_watchpoints::watchpoints(SortMode sort, device_debug::watchpoint* // Alloc int numWPs = 0; wpList = NULL; - for (const debug_view_source *source = m_source_list.head(); source != NULL; source = source->next()) + for (const debug_view_source *source = m_source_list.first(); source != NULL; source = source->next()) { for (address_spacenum spacenum = AS_0; spacenum < ADDRESS_SPACES; spacenum++) { @@ -312,7 +312,7 @@ int debug_view_watchpoints::watchpoints(SortMode sort, device_debug::watchpoint* wpList = new device_debug::watchpoint*[numWPs]; int wpAddIndex = 0; - for (const debug_view_source *source = m_source_list.head(); source != NULL; source = source->next()) + for (const debug_view_source *source = m_source_list.first(); source != NULL; source = source->next()) { // Collect for (address_spacenum spacenum = AS_0; spacenum < ADDRESS_SPACES; spacenum++) diff --git a/src/emu/debugger.c b/src/emu/debugger.c index a89d0328120..4810fcba23b 100644 --- a/src/emu/debugger.c +++ b/src/emu/debugger.c @@ -67,7 +67,7 @@ void debugger_init(running_machine &machine) machine_entry *entry; /* initialize the submodules */ - machine.m_debug_view = auto_alloc(machine, debug_view_manager(machine)); + machine.m_debug_view.reset(global_alloc(debug_view_manager(machine))); debug_cpu_init(machine); debug_command_init(machine); debug_console_init(machine); diff --git a/src/emu/debugint/debugint.c b/src/emu/debugint/debugint.c index 0d6df253b5c..42c000e3e6a 100644 --- a/src/emu/debugint/debugint.c +++ b/src/emu/debugint/debugint.c @@ -956,9 +956,7 @@ static void on_disasm_cpu_activate(DView *dv, const ui_menu_event *event) { current = current->next(); if (current == NULL) - { - current = dv->view->source_list().head(); - } + current = dv->view->first_source(); dv->view->set_source(*current); dview_set_state(dv, VIEW_STATE_NEEDS_UPDATE, TRUE); dview_set_title(dv, current->name()); @@ -1360,7 +1358,7 @@ static void followers_set_cpu(device_t *device) { if (dview_is_state(dv, VIEW_STATE_FOLLOW_CPU)) { - const debug_view_source *source = dv->view->source_list().match_device(device); + const debug_view_source *source = dv->view->source_for_device(device); switch (dv->type) { case DVT_DISASSEMBLY: diff --git a/src/emu/devcpu.c b/src/emu/devcpu.c index 802faf1d7a7..5fedea366a7 100644 --- a/src/emu/devcpu.c +++ b/src/emu/devcpu.c @@ -103,7 +103,7 @@ legacy_cpu_device::legacy_cpu_device(const machine_config &mconfig, device_type legacy_cpu_device::~legacy_cpu_device() { - global_free(m_token); + global_free_array((UINT8 *)m_token); } diff --git a/src/emu/devfind.h b/src/emu/devfind.h index 8afaed9f75a..9f75cde7cb4 100644 --- a/src/emu/devfind.h +++ b/src/emu/devfind.h @@ -251,11 +251,8 @@ public: shared_ptr_finder(device_t &base, const char *tag, UINT8 width = sizeof(_PointerType) * 8) : object_finder_base<_PointerType>(base, tag), m_bytes(0), - m_allocated(false), m_width(width) { } - virtual ~shared_ptr_finder() { if (m_allocated) global_free(this->m_target); } - // operators to make use transparent _PointerType operator[](int index) const { return this->m_target[index]; } _PointerType &operator[](int index) { return this->m_target[index]; } @@ -270,11 +267,11 @@ public: // dynamic allocation of a shared pointer void allocate(UINT32 entries) { - assert(!m_allocated); - m_allocated = true; - this->m_target = global_alloc_array_clear(_PointerType, entries); + assert(m_allocated.count() == 0); + m_allocated.resize(entries); + this->m_target = m_allocated; m_bytes = entries * sizeof(_PointerType); - this->m_base.save_pointer(this->m_target, this->m_tag, entries); + this->m_base.save_item(this->m_allocated, this->m_tag); } // finder @@ -288,8 +285,8 @@ public: protected: // internal state size_t m_bytes; - bool m_allocated; UINT8 m_width; + dynamic_array<_PointerType> m_allocated; }; // optional shared pointer finder @@ -322,13 +319,7 @@ public: shared_ptr_array_finder(device_t &base, const char *basetag, UINT8 width = sizeof(_PointerType) * 8) { for (int index = 0; index < _Count; index++) - m_array[index] = global_alloc(shared_ptr_type(base, m_tag[index].format("%s.%d", basetag, index), width)); - } - - virtual ~shared_ptr_array_finder() - { - for (int index = 0; index < _Count; index++) - global_free(m_array[index]); + m_array[index].reset(global_alloc(shared_ptr_type(base, m_tag[index].format("%s.%d", basetag, index), width))); } // array accessors @@ -337,7 +328,7 @@ public: protected: // internal state - shared_ptr_type *m_array[_Count+1]; + auto_pointer m_array[_Count+1]; astring m_tag[_Count+1]; }; diff --git a/src/emu/device.c b/src/emu/device.c index 89d9f029466..b4cf54a9e10 100644 --- a/src/emu/device.c +++ b/src/emu/device.c @@ -87,7 +87,6 @@ device_t::device_t(const machine_config &mconfig, device_type type, const char * m_clock_scale(1.0), m_attoseconds_per_clock((clock == 0) ? 0 : HZ_TO_ATTOSECONDS(clock)), - m_debug(NULL), m_region(NULL), m_machine_config(mconfig), m_static_config(NULL), @@ -413,7 +412,7 @@ void device_t::start() // if we're debugging, create a device_debug object if ((machine().debug_flags & DEBUG_FLAG_ENABLED) != 0) { - m_debug = auto_alloc(machine(), device_debug(*this)); + m_debug.reset(global_alloc(device_debug(*this))); debug_setup(); } @@ -445,7 +444,7 @@ void device_t::stop() intf->interface_post_stop(); // free any debugging info - auto_free(machine(), m_debug); + m_debug.reset(); // we're now officially stopped, and the machine is off-limits m_started = false; diff --git a/src/emu/device.h b/src/emu/device.h index f6928674c4f..604ec1550cf 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -116,9 +116,9 @@ class device_t : public delegate_late_bind protected: // construction/destruction device_t(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); +public: virtual ~device_t(); -public: // getters running_machine &machine() const { assert(m_machine != NULL); return *m_machine; } const char *tag() const { return m_tag; } @@ -270,7 +270,7 @@ protected: double m_clock_scale; // clock scale factor attoseconds_t m_attoseconds_per_clock;// period in attoseconds - device_debug * m_debug; + auto_pointer m_debug; memory_region * m_region; // our device-local region const machine_config & m_machine_config; // reference to the machine's configuration const void * m_static_config; // static device configuration diff --git a/src/emu/diimage.c b/src/emu/diimage.c index 4b372a185ca..36693a9ad13 100644 --- a/src/emu/diimage.c +++ b/src/emu/diimage.c @@ -55,13 +55,10 @@ device_image_interface::device_image_interface(const machine_config &mconfig, de : device_interface(device), m_file(NULL), m_mame_file(NULL), - m_full_software_name(NULL), m_software_info_ptr(NULL), m_software_part_ptr(NULL), - m_software_list_name(NULL), m_readonly(false), m_created(false), - m_formatlist(NULL), m_is_loading(FALSE) { } @@ -73,15 +70,6 @@ device_image_interface::device_image_interface(const machine_config &mconfig, de device_image_interface::~device_image_interface() { - image_device_format **formatptr = &m_formatlist; - - /* free all entries */ - while (*formatptr != NULL) - { - image_device_format *entry = *formatptr; - *formatptr = entry->m_next; - global_free(entry); - } } //------------------------------------------------- @@ -195,22 +183,6 @@ image_error_t device_image_interface::set_image_filename(const char *filename) CREATION FORMATS ****************************************************************************/ -/*------------------------------------------------- - device_get_indexed_creatable_format - - accesses a specific image format available for - image creation by index --------------------------------------------------*/ - -const image_device_format *device_image_interface::device_get_indexed_creatable_format(int index) -{ - const image_device_format *format = device_get_creatable_formats(); - while(index-- && (format != NULL)) - format = format->m_next; - return format; -} - - - /*------------------------------------------------- device_get_named_creatable_format - accesses a specific image format available for @@ -219,10 +191,10 @@ const image_device_format *device_image_interface::device_get_indexed_creatable_ const image_device_format *device_image_interface::device_get_named_creatable_format(const char *format_name) { - const image_device_format *format = device_get_creatable_formats(); - while((format != NULL) && strcmp(format->m_name, format_name)) - format = format->m_next; - return format; + for (const image_device_format *format = m_formatlist.first(); format != NULL; format = format->next()) + if (strcmp(format->name(), format_name) == 0) + return format; + return NULL; } /**************************************************************************** @@ -420,18 +392,7 @@ UINT32 device_image_interface::get_software_region_length(const char *tag) const char *device_image_interface::get_feature(const char *feature_name) { - feature_list *feature; - - if ( ! m_software_part_ptr || ! m_software_part_ptr->featurelist ) - return NULL; - - for ( feature = m_software_part_ptr->featurelist; feature; feature = feature->next ) - { - if ( ! strcmp( feature->name, feature_name ) ) - return feature->value; - } - - return NULL; + return (m_software_part_ptr == NULL) ? NULL : m_software_part_ptr->feature(feature_name); } @@ -786,7 +747,8 @@ static int verify_length_and_hash(emu_file *file, const char *name, UINT32 exple /*------------------------------------------------- load_software - software image loading -------------------------------------------------*/ -bool device_image_interface::load_software(char *swlist, char *swname, rom_entry *start) + +bool device_image_interface::load_software(software_list_device &swlist, const char *swname, const rom_entry *start) { astring locationtag, breakstr("%"); const rom_entry *region; @@ -807,38 +769,29 @@ bool device_image_interface::load_software(char *swlist, char *swname, rom_entry UINT32 crc = 0; bool has_crc = hash_collection(ROM_GETHASHDATA(romp)).crc(crc); + software_info *swinfo = swlist.find(swname); + if (swinfo == NULL) + return false; + + UINT32 supported = swinfo->supported(); + if (supported == SOFTWARE_SUPPORTED_PARTIAL) + mame_printf_error("WARNING: support for software %s (in list %s) is only partial\n", swname, swlist.list_name()); + if (supported == SOFTWARE_SUPPORTED_NO) + mame_printf_error("WARNING: support for software %s (in list %s) is only preliminary\n", swname, swlist.list_name()); + // attempt reading up the chain through the parents and create a locationtag astring in the format // " swlist % clonename % parentname " // below, we have the code to split the elements and to create paths to load from - software_list *software_list_ptr = software_list_open(device().machine().options(), swlist, FALSE, NULL); - if (software_list_ptr) + while (swinfo != NULL) { - for (software_info *swinfo = software_list_find(software_list_ptr, swname, NULL); swinfo != NULL; ) - { - { - astring tmp(swinfo->shortname); - locationtag.cat(tmp); - locationtag.cat(breakstr); - //printf("%s\n", locationtag.cstr()); - } - - const char *parentname = software_get_clone(device().machine().options(), swlist, swinfo->shortname); - if (parentname != NULL) - swinfo = software_list_find(software_list_ptr, parentname, NULL); - else - swinfo = NULL; - } - // strip the final '%' - locationtag.del(locationtag.len() - 1, 1); - software_list_close(software_list_ptr); + locationtag.cat(swinfo->shortname()).cat(breakstr); + const char *parentname = swinfo->parentname(); + swinfo = (parentname != NULL) ? swlist.find(parentname) : NULL; } + // strip the final '%' + locationtag.del(locationtag.len() - 1, 1); - if (software_get_support(device().machine().options(), swlist, swname) == SOFTWARE_SUPPORTED_PARTIAL) - mame_printf_error("WARNING: support for software %s (in list %s) is only partial\n", swname, swlist); - - if (software_get_support(device().machine().options(), swlist, swname) == SOFTWARE_SUPPORTED_NO) - mame_printf_error("WARNING: support for software %s (in list %s) is only preliminary\n", swname, swlist); // check if locationtag actually contains two locations separated by '%' // (i.e. check if we are dealing with a clone in softwarelist) @@ -852,10 +805,10 @@ bool device_image_interface::load_software(char *swlist, char *swname, rom_entry } // prepare locations where we have to load from: list/parentname & list/clonename - astring tag1(swlist); + astring tag1(swlist.list_name()); tag1.cat(PATH_SEPARATOR); tag2.cpy(tag1.cat(tag4)); - tag1.cpy(swlist); + tag1.cpy(swlist.list_name()); tag1.cat(PATH_SEPARATOR); tag3.cpy(tag1.cat(tag5)); @@ -933,19 +886,26 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int /* Check if there's a software list defined for this device and use that if we're not creating an image */ if (!filename_has_period && !just_load) { - softload = load_software_part( device().machine().options(), this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name, &m_software_list_name ); - // if we had launched from softlist with a specified part, e.g. "shortname:part" - // we would have recorded the wrong name, so record it again based on software_info - if (m_software_info_ptr && m_full_software_name) - m_err = set_image_filename(m_full_software_name); + softload = load_software_part(path, m_software_part_ptr); + if (softload) + { + m_software_info_ptr = &m_software_part_ptr->info(); + m_software_list_name.cpy(m_software_info_ptr->list().list_name()); + m_full_software_name.cpy(m_software_part_ptr->name()); + + // if we had launched from softlist with a specified part, e.g. "shortname:part" + // we would have recorded the wrong name, so record it again based on software_info + if (m_software_info_ptr && m_full_software_name) + m_err = set_image_filename(m_full_software_name); - // check if image should be read-only - const char *read_only = get_feature("read_only"); - if (read_only && !strcmp(read_only, "true")) { - make_readonly(); + // check if image should be read-only + const char *read_only = get_feature("read_only"); + if (read_only && !strcmp(read_only, "true")) { + make_readonly(); + } + + m_from_swlist = TRUE; } - - m_from_swlist = TRUE; } if (is_create || filename_has_period) @@ -967,14 +927,14 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int if ( m_software_info_ptr ) { // sanitize - if (!m_software_info_ptr->longname || !m_software_info_ptr->publisher || !m_software_info_ptr->year) + if (m_software_info_ptr->longname() == NULL || m_software_info_ptr->publisher() == NULL || m_software_info_ptr->year() == NULL) fatalerror("Each entry in an XML list must have all of the following fields: description, publisher, year!\n"); // store - m_longname = m_software_info_ptr->longname; - m_manufacturer = m_software_info_ptr->publisher; - m_year = m_software_info_ptr->year; - //m_playable = m_software_info_ptr->supported; + m_longname = m_software_info_ptr->longname(); + m_manufacturer = m_software_info_ptr->publisher(); + m_year = m_software_info_ptr->year(); + //m_playable = m_software_info_ptr->supported(); } /* did we fail to find the file? */ @@ -1107,7 +1067,7 @@ bool device_image_interface::finish_load() bool device_image_interface::create(const char *path, const image_device_format *create_format, option_resolution *create_args) { - int format_index = (create_format != NULL) ? create_format->m_index : 0; + int format_index = (create_format != NULL) ? m_formatlist.indexof(*create_format) : 0; return load_internal(path, TRUE, format_index, create_args, FALSE); } @@ -1143,10 +1103,10 @@ void device_image_interface::clear() m_basename_noext.reset(); m_filetype.reset(); - m_full_software_name = NULL; + m_full_software_name.reset(); m_software_info_ptr = NULL; m_software_part_ptr = NULL; - m_software_list_name = NULL; + m_software_list_name.reset(); } /*------------------------------------------------- @@ -1193,6 +1153,173 @@ void device_image_interface::update_names(const device_type device_type, const c } } +//------------------------------------------------- +// software_name_split - helper that splits a +// software_list:software:part string into +// separate software_list, software, and part +// strings. +// +// str1:str2:str3 => swlist_name - str1, swname - str2, swpart - str3 +// str1:str2 => swlist_name - NULL, swname - str1, swpart - str2 +// str1 => swlist_name - NULL, swname - str1, swpart - NULL +//------------------------------------------------- + +void device_image_interface::software_name_split(const char *swlist_swname, astring &swlist_name, astring &swname, astring &swpart) +{ + // reset all output parameters + swlist_name.reset(); + swname.reset(); + swpart.reset(); + + // if no colon, this is the swname by itself + const char *split1 = strchr(swlist_swname, ':'); + if (split1 == NULL) + { + swname.cpy(swlist_swname); + return; + } + + // if one colon, it is the swname and swpart alone + const char *split2 = strchr(split1 + 1, ':'); + if (split2 == NULL) + { + swname.cpy(swlist_swname, split1 - swlist_swname); + swpart.cpy(split1 + 1); + return; + } + + // if two colons present, split into 3 parts + swlist_name.cpy(swlist_swname, split1 - swlist_swname); + swname.cpy(split1 + 1, split2 - (split1 + 1)); + swpart.cpy(split2 + 1); +} + + +software_part *device_image_interface::find_software_item(const char *path, bool restrict_to_interface) +{ + // + // Note: old code would explicitly load swlist_name if it was specified, rather than + // searching the devices. + // + // Also if not found, old code would attempt to open .xml and even + // .xml. Hopefully removing this won't break anything. + // + + // split full software name into software list name and short software name + astring swlist_name, swinfo_name, swpart_name; + software_name_split(path, swlist_name, swinfo_name, swpart_name); + bool explicit_name = (swlist_name.len() > 0); + + // determine interface + const char *interface = NULL; + if (restrict_to_interface) + interface = image_interface(); + + // find the software list if explicitly specified + software_list_device_iterator deviter(device().mconfig().root_device()); + for (software_list_device *swlistdev = deviter.first(); swlistdev != NULL; swlistdev = deviter.next()) + if (!explicit_name || swlist_name == swlistdev->list_name()) + { + software_info *info = swlistdev->find(swinfo_name); + if (info != NULL) + { + software_part *part = info->find_part(swpart_name, interface); + if (part != NULL) + return part; + } + } + + // if explicitly specified and not found, just error here + return NULL; +} + + +//------------------------------------------------- +// load_software_part +// +// Load a software part for a device. The part to +// load is determined by the "path", software lists +// configured for a driver, and the interface +// supported by the device. +// +// returns true if the software could be loaded, +// false otherwise. If the software could be loaded +// sw_info and sw_part are also set. +//------------------------------------------------- + +bool device_image_interface::load_software_part(const char *path, software_part *&swpart) +{ + // if no match has been found, we suggest similar shortnames + swpart = find_software_item(path, true); + if (swpart == NULL) + { + software_list_device::display_matches(device().machine().config(), image_interface(), path); + return false; + } + + // Load the software part + bool result = call_softlist_load(swpart->info().list(), swpart->info().shortname(), swpart->romdata()); + + // Tell the world which part we actually loaded + astring full_sw_name; + full_sw_name.printf("%s:%s:%s", swpart->info().list().list_name(), swpart->info().shortname(), swpart->name()); + + // check compatibility + if (!swpart->is_compatible(swpart->info().list())) + mame_printf_warning("WARNING! the set %s might not work on this system due to missing filter(s) '%s'\n", swpart->info().shortname(), swpart->info().list().filter()); + + // check requirements and load those images + const char *requirement = swpart->feature("requirement"); + if (requirement != NULL) + { + software_part *req_swpart = find_software_item(requirement, false); + if (req_swpart != NULL) + { + image_interface_iterator imgiter(device().machine().root_device()); + for (device_image_interface *req_image = imgiter.first(); req_image != NULL; req_image = imgiter.next()) + { + const char *interface = req_image->image_interface(); + if (interface != NULL) + { + if (req_swpart->matches_interface(interface)) + { + const char *option = device().mconfig().options().value(req_image->brief_instance_name()); + // mount only if not already mounted + if (strlen(option) == 0 && !req_image->filename()) + { + req_image->set_init_phase(); + req_image->load(requirement); + } + break; + } + } + } + } + } + return result; +} + +//------------------------------------------------- +// software_get_default_slot +//------------------------------------------------- + +void device_image_interface::software_get_default_slot(astring &result, const char *default_card_slot) +{ + const char *path = device().mconfig().options().value(instance_name()); + result.reset(); + if (strlen(path) > 0) + { + result.cpy(default_card_slot); + software_part *swpart = find_software_item(path, true); + if (swpart != NULL) + { + const char *slot = swpart->feature("slot"); + if (slot != NULL) + result.cpy(slot); + } + } +} + /*------------------------------------------------- get_selection_menu - create the menu stack for ui-level image selection @@ -1200,7 +1327,7 @@ void device_image_interface::update_names(const device_type device_type, const c ui_menu *device_image_interface::get_selection_menu(running_machine &machine, render_container *container) { - return auto_alloc_clear(machine, ui_menu_control_device_image(machine, container, this)); + return global_alloc_clear(ui_menu_control_device_image(machine, container, this)); } ui_menu_control_device_image::ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu(machine, container) @@ -1210,7 +1337,7 @@ ui_menu_control_device_image::ui_menu_control_device_image(running_machine &mach sld = 0; if (image->software_list_name()) { software_list_device_iterator iter(machine.config().root_device()); - for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) + for (software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) { if (strcmp(swlist->list_name(),image->software_list_name())==0) sld = swlist; } @@ -1296,11 +1423,7 @@ void ui_menu_control_device_image::test_create(bool &can_create, bool &need_conf void ui_menu_control_device_image::load_software_part() { - astring temp_name(sld->list_name()); - temp_name.cat(":"); - temp_name.cat(swi->shortname); - temp_name.cat(":"); - temp_name.cat(swp->name); + astring temp_name(sld->list_name(), ":", swi->shortname(), ":", swp->name()); hook_load(temp_name, true); } @@ -1327,20 +1450,20 @@ void ui_menu_control_device_image::handle() zippath_closedir(directory); } submenu_result = -1; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_selector(machine(), container, image, current_directory, current_file, true, image->image_interface()!=NULL, can_create, &submenu_result))); + ui_menu::stack_push(global_alloc_clear(ui_menu_file_selector(machine(), container, image, current_directory, current_file, true, image->image_interface()!=NULL, can_create, &submenu_result))); state = SELECT_FILE; break; } case START_SOFTLIST: sld = 0; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software(machine(), container, image->image_interface(), &sld))); + ui_menu::stack_push(global_alloc_clear(ui_menu_software(machine(), container, image->image_interface(), &sld))); state = SELECT_SOFTLIST; break; case START_OTHER_PART: { submenu_result = -1; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, swi, swp->interface_, &swp, true, &submenu_result))); + ui_menu::stack_push(global_alloc_clear(ui_menu_software_parts(machine(), container, swi, swp->interface(), &swp, true, &submenu_result))); state = SELECT_OTHER_PART; break; } @@ -1351,22 +1474,20 @@ void ui_menu_control_device_image::handle() break; } software_info_name = ""; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_list(machine(), container, sld, image->image_interface(), software_info_name))); + ui_menu::stack_push(global_alloc_clear(ui_menu_software_list(machine(), container, sld, image->image_interface(), software_info_name))); state = SELECT_PARTLIST; break; case SELECT_PARTLIST: - swl = software_list_open(machine().options(), sld->list_name(), false, NULL); - swi = software_list_find(swl, software_info_name, NULL); - if(swinfo_has_multiple_parts(swi, image->image_interface())) { + swi = sld->find(software_info_name); + if(swi->has_multiple_parts(image->image_interface())) { submenu_result = -1; swp = 0; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, swi, image->image_interface(), &swp, false, &submenu_result))); + ui_menu::stack_push(global_alloc_clear(ui_menu_software_parts(machine(), container, swi, image->image_interface(), &swp, false, &submenu_result))); state = SELECT_ONE_PART; } else { - swp = software_find_part(swi, NULL, NULL); + swp = swi->first_part(); load_software_part(); - software_list_close(swl); ui_menu::stack_pop(machine()); } break; @@ -1375,13 +1496,11 @@ void ui_menu_control_device_image::handle() switch(submenu_result) { case ui_menu_software_parts::T_ENTRY: { load_software_part(); - software_list_close(swl); ui_menu::stack_pop(machine()); break; } case -1: // return to list - software_list_close(swl); state = SELECT_SOFTLIST; break; @@ -1419,7 +1538,7 @@ void ui_menu_control_device_image::handle() break; case ui_menu_file_selector::R_CREATE: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, image, current_directory, current_file))); + ui_menu::stack_push(global_alloc_clear(ui_menu_file_create(machine(), container, image, current_directory, current_file))); state = CREATE_FILE; break; @@ -1439,7 +1558,7 @@ void ui_menu_control_device_image::handle() test_create(can_create, need_confirm); if(can_create) { if(need_confirm) { - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, &create_confirmed))); + ui_menu::stack_push(global_alloc_clear(ui_menu_confirm_save_as(machine(), container, &create_confirmed))); state = CREATE_CONFIRM; } else { state = DO_CREATE; diff --git a/src/emu/diimage.h b/src/emu/diimage.h index aa62485b4d1..fe2ca71461f 100644 --- a/src/emu/diimage.h +++ b/src/emu/diimage.h @@ -21,6 +21,8 @@ // TYPE DEFINITIONS //************************************************************************** +class software_list; + enum iodevice_t { /* List of all supported devices. Refer to the device by these names only */ @@ -65,10 +67,26 @@ struct image_device_type_info const char *m_shortname; }; -struct image_device_format +class image_device_format { + friend class simple_list; + +public: + image_device_format(const char *name, const char *description, const char *extensions, const char *optspec) + : m_next(NULL), + m_name(name), + m_description(description), + m_extensions(extensions), + m_optspec(optspec) { } + + image_device_format *next() const { return m_next; } + const char *name() const { return m_name; } + const char *description() const { return m_description; } + const char *extensions() const { return m_extensions; } + const char *optspec() const { return m_optspec; } + +private: image_device_format *m_next; - int m_index; astring m_name; astring m_description; astring m_extensions; @@ -137,7 +155,7 @@ public: virtual void device_compute_hash(hash_collection &hashes, const void *data, size_t length, const char *types) const; virtual bool call_load() { return FALSE; } - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return FALSE; } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { return FALSE; } virtual bool call_create(int format_type, option_resolution *format_options) { return FALSE; } virtual void call_unload() { } virtual void call_display() { } @@ -156,10 +174,9 @@ public: virtual ui_menu *get_selection_menu(running_machine &machine, class render_container *container); - const image_device_format *device_get_indexed_creatable_format(int index); + const image_device_format *device_get_indexed_creatable_format(int index) { return m_formatlist.find(index); } const image_device_format *device_get_named_creatable_format(const char *format_name); const option_guide *device_get_creation_option_guide() { return create_option_guide(); } - const image_device_format *device_get_creatable_formats() { return formatlist(); } const char *error(); void seterror(image_error_t err, const char *message); @@ -218,16 +235,18 @@ public: const char *instance_name() const { return m_instance_name; } const char *brief_instance_name() const { return m_brief_instance_name; } bool uses_file_extension(const char *file_extension) const; - image_device_format *formatlist() const { return m_formatlist; } + image_device_format *formatlist() const { return m_formatlist.first(); } bool load(const char *path); bool open_image_file(emu_options &options); bool finish_load(); void unload(); bool create(const char *path, const image_device_format *create_format, option_resolution *create_args); - bool load_software(char *swlist, char *swname, rom_entry *entry); + bool load_software(software_list_device &swlist, const char *swname, const rom_entry *entry); int reopen_for_write(const char *path); + static void software_name_split(const char *swlist_swname, astring &swlist_name, astring &swname, astring &swpart); + protected: bool load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args, bool just_load); void determine_open_plan(int is_create, UINT32 *open_plan); @@ -248,6 +267,11 @@ protected: void run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *), hash_collection &hashes, const char *types); void image_checkhash(); void update_names(const device_type device_type = NULL, const char *inst = NULL, const char *brief = NULL); + + software_part *find_software_item(const char *path, bool restrict_to_interface); + bool load_software_part(const char *path, software_part *&swpart); + void software_get_default_slot(astring &result, const char *default_card_slot); + // derived class overrides // configuration @@ -270,10 +294,10 @@ protected: astring m_working_directory; /* Software information */ - char *m_full_software_name; + astring m_full_software_name; software_info *m_software_info_ptr; software_part *m_software_part_ptr; - char *m_software_list_name; + astring m_software_list_name; /* info read from the hash file/software list */ astring m_longname; @@ -297,7 +321,7 @@ protected: astring m_instance_name; /* creation info */ - image_device_format *m_formatlist; + simple_list m_formatlist; bool m_is_loading; }; @@ -325,10 +349,9 @@ protected: int submenu_result; bool create_confirmed; bool softlist_done; - const struct software_list *swl; const software_info *swi; const software_part *swp; - const class software_list_device *sld; + class software_list_device *sld; astring software_info_name; void test_create(bool &can_create, bool &need_confirm); diff --git a/src/emu/dinetwork.c b/src/emu/dinetwork.c index 2702a84bf8f..32c0db9fe26 100644 --- a/src/emu/dinetwork.c +++ b/src/emu/dinetwork.c @@ -5,7 +5,6 @@ device_network_interface::device_network_interface(const machine_config &mconfig : device_interface(device) { m_promisc = false; - m_dev = NULL; m_bandwidth = bandwidth; set_mac("\0\0\0\0\0\0"); m_intf = 0; @@ -13,7 +12,6 @@ device_network_interface::device_network_interface(const machine_config &mconfig device_network_interface::~device_network_interface() { - if(m_dev) global_free(m_dev); } int device_network_interface::send(UINT8 *buf, int len) @@ -40,7 +38,7 @@ void device_network_interface::set_mac(const char *mac) void device_network_interface::set_interface(int id) { - m_dev = open_netdev(id, this, (int)(m_bandwidth*1000000/8.0/1500)); + m_dev.reset(open_netdev(id, this, (int)(m_bandwidth*1000000/8.0/1500))); if(!m_dev) { logerror("Network interface %d not found\n", id); id = -1; diff --git a/src/emu/dinetwork.h b/src/emu/dinetwork.h index b239fe2ceb0..99232a63405 100644 --- a/src/emu/dinetwork.h +++ b/src/emu/dinetwork.h @@ -24,7 +24,7 @@ protected: bool m_promisc; char m_mac[6]; float m_bandwidth; - class netdev *m_dev; + auto_pointer m_dev; int m_intf; }; diff --git a/src/emu/dislot.c b/src/emu/dislot.c index f2d6f851322..11f179d0a1e 100644 --- a/src/emu/dislot.c +++ b/src/emu/dislot.c @@ -46,8 +46,7 @@ void device_slot_interface::static_option_add(device_t &device, const char *name if (option != NULL) throw emu_fatalerror("slot '%s' duplicate option '%s\n", device.tag(), name); - option = pool_alloc(intf.m_options.pool(), device_slot_option(name, devtype)); - intf.m_options.append(name, *option); + intf.m_options.append(name, *global_alloc(device_slot_option(name, devtype))); } device_slot_option *device_slot_interface::static_option(device_t &device, const char *name) diff --git a/src/emu/dislot.h b/src/emu/dislot.h index 7eb05b90fcb..d7df2c451d5 100644 --- a/src/emu/dislot.h +++ b/src/emu/dislot.h @@ -116,7 +116,7 @@ public: const char *default_option() const { return m_default_option; } device_slot_option *first_option() const { return m_options.first(); } device_slot_option *option(const char *name) const { if (name) return m_options.find(name); return NULL; } - virtual const char *get_default_card_software(const machine_config &config, emu_options &options) { return NULL; } + virtual void get_default_card_software(astring &result) { result.reset(); } device_t *get_card_device(); private: diff --git a/src/emu/drawgfx.c b/src/emu/drawgfx.c index 7ed78b9906f..0349ef62b0e 100644 --- a/src/emu/drawgfx.c +++ b/src/emu/drawgfx.c @@ -76,7 +76,6 @@ gfxdecode_device::gfxdecode_device(const machine_config &mconfig, const char *ta m_palette(NULL), m_gfxdecodeinfo(NULL) { - memset(m_gfx, 0, sizeof(m_gfx)); } //************************************************************************** @@ -94,8 +93,6 @@ void gfxdecode_device::static_set_gfxdecodeinfo(device_t &device, const gfx_deco void gfxdecode_device::device_stop() { - for (int i = 0; i < MAX_GFX_ELEMENTS; i++) - auto_free(machine(), m_gfx[i]); } //------------------------------------------------- @@ -244,7 +241,7 @@ void gfxdecode_device::device_start() glcopy.total = total; // allocate the graphics - m_gfx[curgfx] = auto_alloc(machine(), gfx_element(m_palette, glcopy, (region_base != NULL) ? region_base + gfxdecode->start : NULL, gfxdecode->total_color_codes, gfxdecode->color_codes_start)); + m_gfx[curgfx].reset(global_alloc(gfx_element(m_palette, glcopy, (region_base != NULL) ? region_base + gfxdecode->start : NULL, gfxdecode->total_color_codes, gfxdecode->color_codes_start))); } } diff --git a/src/emu/drawgfx.h b/src/emu/drawgfx.h index 5e82783f7d4..ae594cb665b 100644 --- a/src/emu/drawgfx.h +++ b/src/emu/drawgfx.h @@ -452,9 +452,8 @@ public: static void static_set_palette(device_t &device, const char *tag); gfx_element * gfx(int index) { assert(index < MAX_GFX_ELEMENTS); return m_gfx[index]; } - gfx_element ** gfx() { return m_gfx; } - void set_gfx(int index, gfx_element * val) { assert(index < MAX_GFX_ELEMENTS); m_gfx[index] = val; } + void set_gfx(int index, gfx_element * val) { assert(index < MAX_GFX_ELEMENTS); m_gfx[index].reset(val); } protected: // device-level overrides virtual void device_validity_check(validity_checker &valid) const; @@ -465,7 +464,7 @@ private: // configuration state palette_device * m_palette; const gfx_decode_entry *m_gfxdecodeinfo; // pointer to array of graphics decoding information - gfx_element * m_gfx[MAX_GFX_ELEMENTS]; // array of pointers to graphic sets (chars, sprites) + auto_pointer m_gfx[MAX_GFX_ELEMENTS]; // array of pointers to graphic sets (chars, sprites) }; // device type iterator diff --git a/src/emu/drivenum.c b/src/emu/drivenum.c index 453f6e6f123..c5d5c6907db 100644 --- a/src/emu/drivenum.c +++ b/src/emu/drivenum.c @@ -131,8 +131,8 @@ driver_enumerator::driver_enumerator(emu_options &options) : m_current(-1), m_filtered_count(0), m_options(options), - m_included(global_alloc_array(UINT8, s_driver_count)), - m_config(global_alloc_array_clear(machine_config *, s_driver_count)) + m_included(s_driver_count, 0), + m_config(s_driver_count, 0) { include_all(); } @@ -142,8 +142,8 @@ driver_enumerator::driver_enumerator(emu_options &options, const char *string) : m_current(-1), m_filtered_count(0), m_options(options), - m_included(global_alloc_array(UINT8, s_driver_count)), - m_config(global_alloc_array_clear(machine_config *, s_driver_count)) + m_included(s_driver_count, 0), + m_config(s_driver_count, 0) { filter(string); } @@ -153,8 +153,8 @@ driver_enumerator::driver_enumerator(emu_options &options, const game_driver &dr : m_current(-1), m_filtered_count(0), m_options(options), - m_included(global_alloc_array(UINT8, s_driver_count)), - m_config(global_alloc_array_clear(machine_config *, s_driver_count)) + m_included(s_driver_count, 0), + m_config(s_driver_count, 0) { filter(driver); } @@ -166,13 +166,7 @@ driver_enumerator::driver_enumerator(emu_options &options, const game_driver &dr driver_enumerator::~driver_enumerator() { - // free any configs - for (int index = 0; index < s_driver_count; index++) - global_free(m_config[index]); - - // free the arrays - global_free(m_included); - global_free(m_config); + // configs are freed by the cache } @@ -248,7 +242,10 @@ int driver_enumerator::filter(const game_driver &driver) void driver_enumerator::include_all() { - memset(m_included, 1, sizeof(m_included[0]) * s_driver_count); m_filtered_count = s_driver_count; + memset(m_included, 1, sizeof(m_included[0]) * s_driver_count); + m_filtered_count = s_driver_count; + + // always exclude the empty driver int empty = find("___empty"); assert(empty != -1); m_included[empty] = 0; @@ -263,6 +260,7 @@ void driver_enumerator::include_all() bool driver_enumerator::next() { // always advance one + release_current(); m_current++; // if we have a filter, scan forward to the next match @@ -286,6 +284,7 @@ bool driver_enumerator::next() bool driver_enumerator::next_excluded() { // always advance one + release_current(); m_current++; // if we have a filter, scan forward to the next match @@ -317,7 +316,7 @@ void driver_enumerator::find_approximate_matches(const char *string, int count, srand(osd_ticks()); // allocate a temporary list - int *templist = global_alloc_array(int, m_filtered_count); + dynamic_array templist(m_filtered_count); int arrayindex = 0; for (int index = 0; index < s_driver_count; index++) if (m_included[index]) @@ -337,13 +336,11 @@ void driver_enumerator::find_approximate_matches(const char *string, int count, // copy out the first few entries for (int matchnum = 0; matchnum < count; matchnum++) results[matchnum] = templist[matchnum % m_filtered_count]; - - global_free(templist); return; } // allocate memory to track the penalty value - int *penalty = global_alloc_array(int, count); + dynamic_array penalty(count); // initialize everyone's states for (int matchnum = 0; matchnum < count; matchnum++) @@ -382,21 +379,27 @@ void driver_enumerator::find_approximate_matches(const char *string, int count, penalty[matchnum] = curpenalty; } } - - // free our temp memory - global_free(penalty); } -driver_enumerator::config_entry::config_entry(machine_config &config, int index) - : m_next(NULL), - m_config(&config), - m_index(index) +//------------------------------------------------- +// release_current - release bulky memory +// structures from the current entry because +// we're done with it +//------------------------------------------------- + +void driver_enumerator::release_current() { -} + // skip if no current entry + if (m_current < 0 || m_current >= s_driver_count) + return; + + // skip if we haven't cached a config + if (m_config[m_current] == NULL) + return; - -driver_enumerator::config_entry::~config_entry() -{ - global_free(m_config); + // iterate over software lists in this entry and reset + software_list_device_iterator deviter(m_config[m_current]->root_device()); + for (software_list_device *swlistdev = deviter.first(); swlistdev != NULL; swlistdev = deviter.next()) + swlistdev->release(); } diff --git a/src/emu/drivenum.h b/src/emu/drivenum.h index c7d58dc3f97..cb23b96b34b 100644 --- a/src/emu/drivenum.h +++ b/src/emu/drivenum.h @@ -50,11 +50,11 @@ public: // static helpers static bool matches(const char *wildstring, const char *string); + static int penalty_compare(const char *source, const char *target); protected: // internal helpers static int driver_sort_callback(const void *elem1, const void *elem2); - static int penalty_compare(const char *source, const char *target); // internal state static int s_driver_count; @@ -116,6 +116,9 @@ public: void find_approximate_matches(const char *string, int count, int *results); private: + // internal helpers + void release_current(); + // entry in the config cache struct config_entry { @@ -123,8 +126,7 @@ private: public: // construction/destruction - config_entry(machine_config &config, int index); - ~config_entry(); + config_entry(machine_config &config, int index) : m_next(NULL), m_config(&config), m_index(index) { } // getters config_entry *next() const { return m_next; } @@ -134,7 +136,7 @@ private: private: // internal state config_entry * m_next; - machine_config * m_config; + auto_pointer m_config; int m_index; }; @@ -144,8 +146,8 @@ private: int m_current; int m_filtered_count; emu_options & m_options; - UINT8 * m_included; - machine_config ** m_config; + dynamic_array m_included; + mutable dynamic_array m_config; mutable simple_list m_config_cache; }; diff --git a/src/emu/emualloc.c b/src/emu/emualloc.c index 22c0e044fed..adf6cd21419 100644 --- a/src/emu/emualloc.c +++ b/src/emu/emualloc.c @@ -20,196 +20,11 @@ -//************************************************************************** -// CONSTANTS -//************************************************************************** - -// align all allocated memory to this size -//const int memory_align = 16; - -// number of memory_entries to allocate in a block -const int memory_block_alloc_chunk = 256; - - - -//************************************************************************** -// MACROS -//************************************************************************** - -// enable deletion -#undef delete - - - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// this struct is allocated in pools to track memory allocations -// it must be a POD type!! -class memory_entry -{ -public: - memory_entry * m_next; // link to the next entry - memory_entry * m_prev; // link to the previous entry - size_t m_size; // size of the allocation (not including this header) - void * m_base; // base of the allocation - const char * m_file; // file the allocation was made from - int m_line; // line number within that file - UINT64 m_id; // unique id - - static const int k_hash_prime = 6151; - - static UINT64 s_curid; // current ID - static osd_lock * s_lock; // lock for managing the list - static bool s_lock_alloc; // set to true temporarily during lock allocation - static bool s_tracking; // set to true when tracking is live - static memory_entry *s_hash[k_hash_prime];// hash table based on pointer - static memory_entry *s_freehead; // pointer to the head of the free list - - static memory_entry *allocate(size_t size, void *base, const char *file, int line); - static memory_entry *find(void *ptr); - static void release(memory_entry *entry); - static void report_unfreed(); - -private: - static void acquire_lock(); - static void release_lock(); -}; - - - //************************************************************************** // GLOBALS //************************************************************************** -// dummy zeromem object -const zeromem_t zeromem = { }; - -// globals for memory_entry -UINT64 memory_entry::s_curid = 1; -osd_lock *memory_entry::s_lock = NULL; -bool memory_entry::s_lock_alloc = false; -bool memory_entry::s_tracking = false; -memory_entry *memory_entry::s_hash[memory_entry::k_hash_prime] = { NULL }; -memory_entry *memory_entry::s_freehead = NULL; - -// wrapper for the global resource pool to help ensure construction order -resource_pool &global_resource_pool() -{ - static resource_pool s_pool(6151); - return s_pool; -}; - - -//************************************************************************** -// GLOBAL HELPERS -//************************************************************************** - -//------------------------------------------------- -// malloc_file_line - allocate memory with file -// and line number information -//------------------------------------------------- - -void *malloc_file_line(size_t size, const char *file, int line) -{ - // allocate the memory and fail if we can't - void *result = osd_malloc(size); - if (result == NULL) - return NULL; - - // add a new entry - memory_entry::allocate(size, result, file, line); - -#if !__has_feature(memory_sanitizer) && defined(MAME_DEBUG) - memset(result, 0xdd, size); -#endif - - return result; -} - - -//------------------------------------------------- -// malloc_array_file_line - allocate memory with -// file and line number information, and a hint -// that this object is an array -//------------------------------------------------- - -void *malloc_array_file_line(size_t size, const char *file, int line) -{ - // allocate the memory and fail if we can't - void *result = osd_malloc_array(size); - if (result == NULL) - return NULL; - - // add a new entry - memory_entry::allocate(size, result, file, line); - -#if !__has_feature(memory_sanitizer) && defined(MAME_DEBUG) - memset(result, 0xdd, size); -#endif - - return result; -} - - -//------------------------------------------------- -// free_file_line - free memory with file -// and line number information -//------------------------------------------------- - -void free_file_line(void *memory, const char *file, int line) -{ - // ignore NULL frees/deletes - if (memory == NULL) - return; - - // find the memory entry - memory_entry *entry = memory_entry::find(memory); - - // warn about untracked frees - if (entry == NULL) - { - fprintf(stderr, "Error: attempt to free untracked memory in %s(%d)!\n", file, line); - osd_break_into_debugger("Error: attempt to free untracked memory"); - return; - } - -#ifdef MAME_DEBUG - // clear memory to a bogus value - memset(memory, 0xfc, entry->m_size); -#endif - - // free the entry and the memory - memory_entry::release(entry); - osd_free(memory); -} - - -//------------------------------------------------- -// dump_unfreed_mem - called from the exit path -// of any code that wants to check for unfreed -// memory -//------------------------------------------------- - -void track_memory(bool track) -{ - memory_entry::s_tracking = track; -} - - -//------------------------------------------------- -// dump_unfreed_mem - called from the exit path -// of any code that wants to check for unfreed -// memory -//------------------------------------------------- - -void dump_unfreed_mem() -{ -#ifdef MAME_DEBUG - memory_entry::report_unfreed(); -#endif -} +UINT64 resource_pool::s_id = 0; @@ -225,11 +40,10 @@ void dump_unfreed_mem() resource_pool::resource_pool(int hash_size) : m_hash_size(hash_size), m_listlock(osd_lock_alloc()), - m_hash(new resource_pool_item *[hash_size]), + m_hash(hash_size, 0), m_ordered_head(NULL), m_ordered_tail(NULL) { - memset(m_hash, 0, hash_size * sizeof(m_hash[0])); } @@ -244,7 +58,6 @@ resource_pool::~resource_pool() clear(); if (m_listlock != NULL) osd_lock_free(m_listlock); - delete[] m_hash; } @@ -252,7 +65,7 @@ resource_pool::~resource_pool() // add - add a new item to the resource pool //------------------------------------------------- -void resource_pool::add(resource_pool_item &item) +void resource_pool::add(resource_pool_item &item, size_t size, const char *type) { osd_lock_acquire(m_listlock); @@ -263,13 +76,9 @@ void resource_pool::add(resource_pool_item &item) // fetch the ID of this item's pointer; some implementations put hidden data // before, so if we don't find it, check 4 bytes ahead - memory_entry *entry = memory_entry::find(item.m_ptr); - if (entry == NULL) - entry = memory_entry::find(reinterpret_cast(item.m_ptr) - sizeof(size_t)); - assert(entry != NULL); - item.m_id = entry->m_id; + item.m_id = ++s_id; if (LOG_ALLOCS) - fprintf(stderr, "#%06d, add %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), entry->m_file, (int)entry->m_line); + fprintf(stderr, "#%06d, add %s, %d bytes\n", (UINT32)item.m_id, type, size); // find the entry to insert after resource_pool_item *insert_after; @@ -340,7 +149,7 @@ void resource_pool::remove(void *ptr) // delete the object and break if (LOG_ALLOCS) fprintf(stderr, "#%06d, delete %d bytes\n", (UINT32)deleteme->m_id, static_cast(deleteme->m_size)); - delete deleteme; + global_free(deleteme); break; } @@ -414,170 +223,3 @@ void resource_pool::clear() osd_lock_release(m_listlock); } - - - -//************************************************************************** -// MEMORY ENTRY -//************************************************************************** - -//------------------------------------------------- -// acquire_lock - acquire the memory entry lock, -// creating a new one if needed -//------------------------------------------------- - -void memory_entry::acquire_lock() -{ - // allocate a lock on first usage - // note that osd_lock_alloc() may re-enter this path, so protect against recursion! - if (s_lock == NULL) - { - if (s_lock_alloc) - return; - s_lock_alloc = true; - s_lock = osd_lock_alloc(); - s_lock_alloc = false; - } - osd_lock_acquire(s_lock); -} - - -//------------------------------------------------- -// release_lock - release the memory entry lock -//------------------------------------------------- - -void memory_entry::release_lock() -{ - osd_lock_release(s_lock); -} - - -//------------------------------------------------- -// allocate - allocate a new memory entry -//------------------------------------------------- - -memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, int line) -{ - acquire_lock(); - - // if we're out of free entries, allocate a new chunk - if (s_freehead == NULL) - { - // create a new chunk, and fail if we can't - memory_entry *entry = reinterpret_cast(osd_malloc_array(memory_block_alloc_chunk * sizeof(memory_entry))); - if (entry == NULL) - { - release_lock(); - return NULL; - } - - // add all the entries to the list - for (int entrynum = 0; entrynum < memory_block_alloc_chunk; entrynum++) - { - entry->m_next = s_freehead; - s_freehead = entry++; - } - } - - // grab a free entry - memory_entry *entry = s_freehead; - s_freehead = entry->m_next; - - // populate it - entry->m_size = size; - entry->m_base = base; - entry->m_file = s_tracking ? file : NULL; - entry->m_line = s_tracking ? line : 0; - entry->m_id = s_curid++; - if (LOG_ALLOCS) - fprintf(stderr, "#%06d, alloc %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), entry->m_file, (int)entry->m_line); - - // add it to the alloc list - int hashval = reinterpret_cast(base) % k_hash_prime; - entry->m_next = s_hash[hashval]; - if (entry->m_next != NULL) - entry->m_next->m_prev = entry; - entry->m_prev = NULL; - s_hash[hashval] = entry; - - release_lock(); - return entry; -} - - -//------------------------------------------------- -// find - find a memory entry -//------------------------------------------------- - -memory_entry *memory_entry::find(void *ptr) -{ - // NULL maps to nothing - if (ptr == NULL) - return NULL; - - // scan the list under the lock - acquire_lock(); - - int hashval = reinterpret_cast(ptr) % k_hash_prime; - memory_entry *entry; - for (entry = s_hash[hashval]; entry != NULL; entry = entry->m_next) - if (entry->m_base == ptr) - break; - - release_lock(); - return entry; -} - - -//------------------------------------------------- -// release - release a memory entry -//------------------------------------------------- - -void memory_entry::release(memory_entry *entry) -{ - acquire_lock(); - - // remove ourselves from the alloc list - int hashval = reinterpret_cast(entry->m_base) % k_hash_prime; - if (entry->m_prev != NULL) - entry->m_prev->m_next = entry->m_next; - else - s_hash[hashval] = entry->m_next; - if (entry->m_next != NULL) - entry->m_next->m_prev = entry->m_prev; - - // add ourself to the free list - entry->m_next = s_freehead; - s_freehead = entry; - - release_lock(); -} - - -//------------------------------------------------- -// report_unfreed - print a list of unfreed -// memory to the target file -//------------------------------------------------- - -void memory_entry::report_unfreed() -{ - acquire_lock(); - - // check for leaked memory - UINT32 total = 0; - - for (int hashnum = 0; hashnum < k_hash_prime; hashnum++) - for (memory_entry *entry = s_hash[hashnum]; entry != NULL; entry = entry->m_next) - if (entry->m_file != NULL) - { - if (total == 0) - fprintf(stderr, "--- memory leak warning ---\n"); - total += entry->m_size; - fprintf(stderr, "#%06d, nofree %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), entry->m_file, (int)entry->m_line); - } - - release_lock(); - - if (total > 0) - fprintf(stderr, "a total of %u bytes were not freed\n", total); -} diff --git a/src/emu/emualloc.h b/src/emu/emualloc.h index 39a02db248f..b39b1c10c64 100644 --- a/src/emu/emualloc.h +++ b/src/emu/emualloc.h @@ -15,6 +15,7 @@ #include #include "osdcore.h" +#include "coretmpl.h" //************************************************************************** @@ -44,133 +45,6 @@ #define pool_alloc_array_clear(_pool, _type, _num) (_pool).add_array(new(__FILE__, __LINE__, zeromem) _type[_num], (_num)) #define pool_free(_pool, v) (_pool).remove(v) -// global allocation helpers -#define global_alloc(_type) pool_alloc(global_resource_pool(), _type) -#define global_alloc_clear(_type) pool_alloc_clear(global_resource_pool(), _type) -#define global_alloc_array(_type, _num) pool_alloc_array(global_resource_pool(), _type, _num) -#define global_alloc_array_clear(_type, _num) pool_alloc_array_clear(global_resource_pool(), _type, _num) -#define global_free(v) pool_free(global_resource_pool(), v) - - - -//************************************************************************** -// FUNCTION PROTOTYPES -//************************************************************************** - -// allocate memory with file and line number information -void *malloc_file_line(size_t size, const char *file, int line); -void *malloc_array_file_line(size_t size, const char *file, int line); - -// free memory with file and line number information -void free_file_line(void *memory, const char *file, int line); - -// called from the exit path of any code that wants to check for unfreed memory -void track_memory(bool track); -void dump_unfreed_mem(); - - - -//************************************************************************** -// INLINE FUNCTIONS -//************************************************************************** - -// zeromem_t is a dummy class used to tell new to zero memory after allocation -class zeromem_t { }; - -#ifndef NO_MEM_TRACKING - -// standard new/delete operators (try to avoid using) -ATTR_FORCE_INLINE inline void *operator new(std::size_t size) throw (std::bad_alloc) -{ - void *result = malloc_file_line(size, NULL, 0); - if (result == NULL) - throw std::bad_alloc(); - return result; -} - -ATTR_FORCE_INLINE inline void *operator new[](std::size_t size) throw (std::bad_alloc) -{ - void *result = malloc_array_file_line(size, NULL, 0); - if (result == NULL) - throw std::bad_alloc(); - return result; -} - -ATTR_FORCE_INLINE inline void operator delete(void *ptr) throw() -{ - if (ptr != NULL) - free_file_line(ptr, NULL, 0); -} - -ATTR_FORCE_INLINE inline void operator delete[](void *ptr) throw() -{ - if (ptr != NULL) - free_file_line(ptr, NULL, 0); -} - -#endif - -// file/line new/delete operators -ATTR_FORCE_INLINE inline void *operator new(std::size_t size, const char *file, int line) throw (std::bad_alloc) -{ - void *result = malloc_file_line(size, file, line); - if (result == NULL) - throw std::bad_alloc(); - return result; -} - -ATTR_FORCE_INLINE inline void *operator new[](std::size_t size, const char *file, int line) throw (std::bad_alloc) -{ - void *result = malloc_array_file_line(size, file, line); - if (result == NULL) - throw std::bad_alloc(); - return result; -} - -ATTR_FORCE_INLINE inline void operator delete(void *ptr, const char *file, int line) -{ - if (ptr != NULL) - free_file_line(ptr, file, line); -} - -ATTR_FORCE_INLINE inline void operator delete[](void *ptr, const char *file, int line) -{ - if (ptr != NULL) - free_file_line(ptr, file, line); -} - - -// file/line new/delete operators with zeroing -ATTR_FORCE_INLINE inline void *operator new(std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc) -{ - void *result = malloc_file_line(size, file, line); - if (result == NULL) - throw std::bad_alloc(); - memset(result, 0, size); - return result; -} - -ATTR_FORCE_INLINE inline void *operator new[](std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc) -{ - void *result = malloc_array_file_line(size, file, line); - if (result == NULL) - throw std::bad_alloc(); - memset(result, 0, size); - return result; -} - -ATTR_FORCE_INLINE inline void operator delete(void *ptr, const char *file, int line, const zeromem_t &) -{ - if (ptr != NULL) - free_file_line(ptr, file, line); -} - -ATTR_FORCE_INLINE inline void operator delete[](void *ptr, const char *file, int line, const zeromem_t &) -{ - if (ptr != NULL) - free_file_line(ptr, file, line); -} - //************************************************************************** @@ -254,7 +128,7 @@ public: resource_pool(int hash_size = 193); virtual ~resource_pool(); - void add(resource_pool_item &item); + void add(resource_pool_item &item, size_t size, const char *type); void remove(resource_pool_item &item) { remove(item.m_ptr); } void remove(void *ptr); void remove(const void *ptr) { remove(const_cast(ptr)); } @@ -262,46 +136,17 @@ public: bool contains(void *ptrstart, void *ptrend); void clear(); - template _ObjectClass *add_object(_ObjectClass* object) { add(*EMUALLOC_SELF_NEW resource_pool_object<_ObjectClass>(object)); return object; } - template _ObjectClass *add_array(_ObjectClass* array, int count) { add(*EMUALLOC_SELF_NEW resource_pool_array<_ObjectClass>(array, count)); return array; } + template _ObjectClass *add_object(_ObjectClass* object) { add(*EMUALLOC_SELF_NEW resource_pool_object<_ObjectClass>(object), sizeof(_ObjectClass), typeid(_ObjectClass).name()); return object; } + template _ObjectClass *add_array(_ObjectClass* array, int count) { add(*EMUALLOC_SELF_NEW resource_pool_array<_ObjectClass>(array, count), sizeof(_ObjectClass), typeid(_ObjectClass).name()); return array; } private: int m_hash_size; osd_lock * m_listlock; - resource_pool_item ** m_hash; + dynamic_array m_hash; resource_pool_item * m_ordered_head; resource_pool_item * m_ordered_tail; + static UINT64 s_id; }; - -//************************************************************************** -// GLOBAL VARIABLES -//************************************************************************** - -// dummy objects to pass to the specialized new variants -extern const zeromem_t zeromem; - - -resource_pool &global_resource_pool(); - - - -//************************************************************************** -// ADDDITIONAL MACROS -//************************************************************************** - -#ifndef NO_MEM_TRACKING -// re-route classic malloc-style allocations -#undef malloc -#undef calloc -#undef realloc -#undef free - -#define malloc(x) malloc_array_file_line(x, __FILE__, __LINE__) -#define calloc(x,y) __error_use_auto_alloc_clear_or_global_alloc_clear_instead__ -#define realloc(x,y) __error_realloc_is_dangerous__ -#define free(x) free_file_line(x, __FILE__, __LINE__) -#endif - #endif /* __EMUALLOC_H__ */ diff --git a/src/emu/emucore.h b/src/emu/emucore.h index 4b3330c9e9f..5a1b797a141 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -60,13 +60,6 @@ // genf is a generic function pointer; cast function pointers to this instead of void * typedef void genf(void); -// FPTR is used to cast a pointer to a scalar -#ifdef PTR64 -typedef UINT64 FPTR; -#else -typedef UINT32 FPTR; -#endif - // pen_t is used to represent pixel values in bitmaps typedef UINT32 pen_t; diff --git a/src/emu/emuopts.c b/src/emu/emuopts.c index 8495b4e457f..5834a61a0fa 100644 --- a/src/emu/emuopts.c +++ b/src/emu/emuopts.c @@ -105,8 +105,6 @@ const options_entry emu_options::s_option_entries[] = { OPTION_GAMMA "(0.1-3.0)", "1.0", OPTION_FLOAT, "default game screen gamma correction" }, { OPTION_PAUSE_BRIGHTNESS "(0.0-1.0)", "0.65", OPTION_FLOAT, "amount to scale the screen brightness when paused" }, { OPTION_EFFECT, "none", OPTION_STRING, "name of a PNG file to use for visual effects, or 'none'" }, - { OPTION_MINIMUM_WIDTH, "0", OPTION_INTEGER, "minimum screen width" }, - { OPTION_MINIMUM_HEIGHT, "0", OPTION_INTEGER, "minimum screen height" }, // vector options { NULL, NULL, OPTION_HEADER, "CORE VECTOR OPTIONS" }, @@ -201,57 +199,51 @@ emu_options::emu_options() // options for the configured system //------------------------------------------------- -bool emu_options::add_slot_options(bool isfirst) +bool emu_options::add_slot_options(bool isfirstpass) { // look up the system configured by name; if no match, do nothing const game_driver *cursystem = system(); if (cursystem == NULL) return false; + machine_config config(*cursystem, *this); // iterate through all slot devices - options_entry entry[2] = { { 0 }, { 0 } }; bool first = true; + // create the configuration - machine_config config(*cursystem, *this); - bool added = false; + int starting_count = options_count(); slot_interface_iterator iter(config.root_device()); for (const device_slot_interface *slot = iter.first(); slot != NULL; slot = iter.next()) { - if (slot->fixed()) continue; + // skip fixed slots + if (slot->fixed()) + continue; + // first device? add the header as to be pretty - if (first && isfirst) - { - entry[0].name = NULL; - entry[0].description = "SLOT DEVICES"; - entry[0].flags = OPTION_HEADER | OPTION_FLAG_DEVICE; - entry[0].defvalue = NULL; - add_entries(entry); - } + if (isfirstpass && first) + add_entry(NULL, "SLOT DEVICES", OPTION_HEADER | OPTION_FLAG_DEVICE); first = false; // retrieve info about the device instance - if (!exists(slot->device().tag() + 1)) { + const char *name = slot->device().tag() + 1; + if (!exists(name)) + { // add the option - entry[0].name = slot->device().tag() + 1; - entry[0].description = NULL; - entry[0].flags = OPTION_STRING | OPTION_FLAG_DEVICE; - entry[0].defvalue = slot->default_option(); - if ( entry[0].defvalue ) + UINT32 flags = OPTION_STRING | OPTION_FLAG_DEVICE; + const char *defvalue = slot->default_option(); + if (defvalue != NULL) { - const device_slot_option *option = slot->option(entry[0].defvalue); - if (option && !option->selectable()) - { - entry[0].flags |= OPTION_FLAG_INTERNAL; - } + const device_slot_option *option = slot->option(defvalue); + if (option != NULL && !option->selectable()) + flags |= OPTION_FLAG_INTERNAL; } - add_entries(entry, true); - - added = true; + add_entry(name, NULL, flags, defvalue, true); } } - return added; + return (options_count() != starting_count); } + //------------------------------------------------- // update_slot_options - update slot values // depending of image mounted @@ -263,72 +255,61 @@ void emu_options::update_slot_options() const game_driver *cursystem = system(); if (cursystem == NULL) return; + machine_config config(*cursystem, *this); // iterate through all slot devices - // create the configuration - machine_config config(*cursystem, *this); slot_interface_iterator iter(config.root_device()); for (device_slot_interface *slot = iter.first(); slot != NULL; slot = iter.next()) { // retrieve info about the device instance - if (exists(slot->device().tag()+1)) { - if (slot->first_option() != NULL) { - const char *def = slot->get_default_card_software(config,*this); - if (def) - { - set_default_value(slot->device().tag()+1,def); - const device_slot_option *option = slot->option( def ); - set_flag(slot->device().tag()+1, ~OPTION_FLAG_INTERNAL, option && !option->selectable() ? OPTION_FLAG_INTERNAL : 0 ); - } + const char *name = slot->device().tag() + 1; + if (exists(name) && slot->first_option() != NULL) + { + astring defvalue; + slot->get_default_card_software(defvalue); + if (defvalue.len() > 0) + { + set_default_value(name, defvalue); + const device_slot_option *option = slot->option(defvalue); + set_flag(name, ~OPTION_FLAG_INTERNAL, (option != NULL && !option->selectable()) ? OPTION_FLAG_INTERNAL : 0); } } } } + + //------------------------------------------------- // add_device_options - add all of the device // options for the configured system //------------------------------------------------- -void emu_options::add_device_options(bool isfirst) +void emu_options::add_device_options(bool isfirstpass) { // look up the system configured by name; if no match, do nothing const game_driver *cursystem = system(); if (cursystem == NULL) return; - - // iterate through all slot devices - options_entry entry[2] = { { 0 }, { 0 } }; - bool first = true; - // iterate through all image devices machine_config config(*cursystem, *this); + + // iterate through all image devices + bool first = true; image_interface_iterator iter(config.root_device()); for (const device_image_interface *image = iter.first(); image != NULL; image = iter.next()) { // first device? add the header as to be pretty - if (first && isfirst) - { - entry[0].name = NULL; - entry[0].description = "IMAGE DEVICES"; - entry[0].flags = OPTION_HEADER | OPTION_FLAG_DEVICE; - entry[0].defvalue = NULL; - add_entries(entry); - } + if (first && isfirstpass) + add_entry(NULL, "IMAGE DEVICES", OPTION_HEADER | OPTION_FLAG_DEVICE); first = false; // retrieve info about the device instance astring option_name; option_name.printf("%s;%s", image->instance_name(), image->brief_instance_name()); - if (strcmp(image->device_typename(image->image_type()),image->instance_name())==0){ - option_name.printf("%s;%s;%s1;%s1", image->instance_name(), image->brief_instance_name(), image->instance_name(), image->brief_instance_name()); - } + if (strcmp(image->device_typename(image->image_type()), image->instance_name()) == 0) + option_name.catprintf(";%s1;%s1", image->instance_name(), image->brief_instance_name()); + // add the option - if (!exists(image->instance_name())) { - entry[0].name = option_name; - entry[0].description = NULL; - entry[0].flags = OPTION_STRING | OPTION_FLAG_DEVICE; - entry[0].defvalue = NULL; - add_entries(entry, true); - } + if (!exists(image->instance_name())) + add_entry(option_name, NULL, OPTION_STRING | OPTION_FLAG_DEVICE, NULL, true); } } @@ -360,16 +341,21 @@ void emu_options::remove_device_options() bool emu_options::parse_slot_devices(int argc, char *argv[], astring &error_string, const char *name, const char *value) { - bool isfirst = true; + // an initial parse to capture the initial set of values bool result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); - while (add_slot_options(isfirst)) { + + // keep adding slot options until we stop seeing new stuff + bool isfirstpass = true; + while (add_slot_options(isfirstpass)) + { result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); - isfirst = false; + isfirstpass = false; } + + // add device options and reparse add_device_options(true); - if (name && exists(name)) { + if (name != NULL && exists(name)) set_value(name, value, OPTION_PRIORITY_CMDLINE, error_string); - } result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); int num = 0; @@ -379,11 +365,12 @@ bool emu_options::parse_slot_devices(int argc, char *argv[], astring &error_stri while (add_slot_options(false)); add_device_options(false); result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); - } while(num != options_count()); + } while (num != options_count()); return result; } + //------------------------------------------------- // parse_command_line - parse the command line // and update the devices @@ -504,13 +491,12 @@ void emu_options::set_system_name(const char *name) astring error; set_value(OPTION_SYSTEMNAME, name, OPTION_PRIORITY_CMDLINE, error); assert(!error); - // remove any existing device options + + // remove any existing device options and then add them afresh remove_device_options(); + if (add_slot_options(true)) + while (add_slot_options(false)) { } - bool isfirst = true; - while (add_slot_options(isfirst)) { - isfirst = false; - } // then add the options add_device_options(true); int num = 0; @@ -567,26 +553,25 @@ bool emu_options::parse_one_ini(const char *basename, int priority, astring *err const char *emu_options::main_value(astring &buffer, const char *name) const { buffer = value(name); - int pos = buffer.chr(0,','); - if (pos!=-1) { - buffer = buffer.substr(0,pos); - } + int pos = buffer.chr(0, ','); + if (pos != -1) + buffer = buffer.substr(0, pos); return buffer.cstr(); } const char *emu_options::sub_value(astring &buffer, const char *name, const char *subname) const { - astring tmp = ","; - tmp.cat(subname); - tmp.cat("="); + astring tmp(",", subname, "="); buffer = value(name); - int pos = buffer.find(0,tmp); - if (pos!=-1) { - int endpos = buffer.chr(pos+1,','); - if(endpos==-1) endpos = buffer.len(); - buffer = buffer.substr(pos+tmp.len(),endpos-pos-tmp.len()); - } else { - buffer =""; + int pos = buffer.find(0, tmp); + if (pos != -1) + { + int endpos = buffer.chr(pos + 1, ','); + if (endpos == -1) + endpos = buffer.len(); + buffer = buffer.substr(pos + tmp.len(), endpos - pos - tmp.len()); } + else + buffer.reset(); return buffer.cstr(); } diff --git a/src/emu/emutempl.h b/src/emu/emutempl.h index c0a581f91aa..a56a12de788 100644 --- a/src/emu/emutempl.h +++ b/src/emu/emutempl.h @@ -18,387 +18,5 @@ // TYPE DEFINITIONS //************************************************************************** -// ======================> simple_list - -// a simple_list is a singly-linked list whose 'next' pointer is owned -// by the object -template -class simple_list -{ - // we don't support deep copying - DISABLE_COPYING(simple_list); - -public: - // construction/destruction - simple_list(resource_pool &pool = global_resource_pool()) - : m_head(NULL), - m_tail(NULL), - m_pool(pool), - m_count(0) { } - - virtual ~simple_list() { reset(); } - - // simple getters - resource_pool &pool() const { return m_pool; } - _ElementType *first() const { return m_head; } - _ElementType *last() const { return m_tail; } - int count() const { return m_count; } - - // remove (free) all objects in the list, leaving an empty list - void reset() - { - while (m_head != NULL) - remove(*m_head); - } - - // add the given object to the head of the list - _ElementType &prepend(_ElementType &object) - { - object.m_next = m_head; - m_head = &object; - if (m_tail == NULL) - m_tail = m_head; - m_count++; - return object; - } - - // add the given list to the head of the list - void prepend_list(simple_list<_ElementType> &list) - { - int count = list.count(); - if (count == 0) - return; - _ElementType *tail = list.last(); - _ElementType *head = list.detach_all(); - tail->m_next = m_head; - m_head = head; - if (m_tail == NULL) - m_tail = tail; - m_count += count; - } - - // add the given object to the tail of the list - _ElementType &append(_ElementType &object) - { - object.m_next = NULL; - if (m_tail != NULL) - m_tail = m_tail->m_next = &object; - else - m_tail = m_head = &object; - m_count++; - return object; - } - - // add the given list to the tail of the list - void append_list(simple_list<_ElementType> &list) - { - int count = list.count(); - if (count == 0) - return; - _ElementType *tail = list.last(); - _ElementType *head = list.detach_all(); - if (m_tail != NULL) - m_tail->m_next = head; - else - m_head = head; - m_tail = tail; - m_count += count; - } - - // insert the given object after a particular object (NULL means prepend) - _ElementType &insert_after(_ElementType &object, _ElementType *insert_after) - { - if (insert_after == NULL) - return prepend(object); - object.m_next = insert_after->m_next; - insert_after->m_next = &object; - if (m_tail == insert_after) - m_tail = &object; - m_count++; - return object; - } - - // insert the given object before a particular object (NULL means append) - _ElementType &insert_before(_ElementType &object, _ElementType *insert_before) - { - if (insert_before == NULL) - return append(object); - for (_ElementType **curptr = &m_head; *curptr != NULL; curptr = &(*curptr)->m_next) - if (*curptr == insert_before) - { - object.m_next = insert_before; - *curptr = &object; - if (m_head == insert_before) - m_head = &object; - m_count++; - return object; - } - return object; - } - - // replace an item in the list at the same location, and remove it - _ElementType &replace_and_remove(_ElementType &object, _ElementType &toreplace) - { - _ElementType *prev = NULL; - for (_ElementType *cur = m_head; cur != NULL; prev = cur, cur = cur->m_next) - if (cur == &toreplace) - { - if (prev != NULL) - prev->m_next = &object; - else - m_head = &object; - if (m_tail == &toreplace) - m_tail = &object; - object.m_next = toreplace.m_next; - pool_free(m_pool, &toreplace); - return object; - } - return append(object); - } - - // detach the head item from the list, but don't free its memory - _ElementType *detach_head() - { - _ElementType *result = m_head; - if (result != NULL) - { - m_head = result->m_next; - m_count--; - if (m_head == NULL) - m_tail = NULL; - } - return result; - } - - // detach the given item from the list, but don't free its memory - _ElementType &detach(_ElementType &object) - { - _ElementType *prev = NULL; - for (_ElementType *cur = m_head; cur != NULL; prev = cur, cur = cur->m_next) - if (cur == &object) - { - if (prev != NULL) - prev->m_next = object.m_next; - else - m_head = object.m_next; - if (m_tail == &object) - m_tail = prev; - m_count--; - return object; - } - return object; - } - - // deatch the entire list, returning the head, but don't free memory - _ElementType *detach_all() - { - _ElementType *result = m_head; - m_head = m_tail = NULL; - m_count = 0; - return result; - } - - // remove the given object and free its memory - void remove(_ElementType &object) - { - detach(object); - pool_free(m_pool, &object); - } - - // find an object by index in the list - _ElementType *find(int index) const - { - for (_ElementType *cur = m_head; cur != NULL; cur = cur->m_next) - if (index-- == 0) - return cur; - return NULL; - } - - // return the index of the given object in the list - int indexof(const _ElementType &object) const - { - int index = 0; - for (_ElementType *cur = m_head; cur != NULL; cur = cur->m_next) - { - if (cur == &object) - return index; - index++; - } - return -1; - } - -private: - // internal state - _ElementType * m_head; // head of the singly-linked list - _ElementType * m_tail; // tail of the singly-linked list - resource_pool & m_pool; // resource pool where objects are freed - int m_count; // number of objects in the list -}; - - -// ======================> simple_list_wrapper - -// a simple_list_wrapper wraps an existing object with a next pointer so it -// can live in a simple_list without requiring the object to have a next -// pointer -template -class simple_list_wrapper -{ -public: - template friend class simple_list; - - // construction/destruction - simple_list_wrapper(_ObjectType *object) - : m_next(NULL), - m_object(object) { } - - // operators - operator _ObjectType *() { return m_object; } - operator _ObjectType *() const { return m_object; } - _ObjectType *operator *() { return m_object; } - _ObjectType *operator *() const { return m_object; } - - // getters - simple_list_wrapper *next() const { return m_next; } - _ObjectType *object() const { return m_object; } - -private: - // internal state - simple_list_wrapper * m_next; - _ObjectType * m_object; -}; - - -// ======================> fixed_allocator - -// a fixed_allocator is a simple class that maintains a free pool of objects -template -class fixed_allocator -{ - // we don't support deep copying - DISABLE_COPYING(fixed_allocator); - -public: - // construction/destruction - fixed_allocator(resource_pool &pool = global_resource_pool()) - : m_freelist(pool) { } - - // allocate a new item, either by recycling an old one, or by allocating a new one - _ItemType *alloc() - { - _ItemType *result = m_freelist.detach_head(); - if (result == NULL) - result = m_freelist.pool().add_object(new _ItemType); - return result; - } - - // reclaim an item by adding it to the free list - void reclaim(_ItemType *item) { if (item != NULL) m_freelist.append(*item); } - void reclaim(_ItemType &item) { m_freelist.append(item); } - - // reclaim all items from a list - void reclaim_all(simple_list<_ItemType> &list) { m_freelist.append_list(list); } - -private: - // internal state - simple_list<_ItemType> m_freelist; // list of free objects -}; - - -// ======================> tagged_list - -// a tagged_list is a class that maintains a list of objects that can be quickly looked up by tag -template -class tagged_list -{ - // we don't support deep copying - DISABLE_COPYING(tagged_list); - -public: - // construction/destruction - tagged_list(resource_pool &pool = global_resource_pool()) - : m_list(pool) { } - - // simple getters - resource_pool &pool() const { return m_list.pool(); } - _ElementType *first() const { return m_list.first(); } - _ElementType *last() const { return m_list.last(); } - int count() const { return m_list.count(); } - - // remove (free) all objects in the list, leaving an empty list - void reset() { m_list.reset(); m_map.reset(); } - - // add the given object to the head of the list - _ElementType &prepend(const char *tag, _ElementType &object) - { - if (m_map.add_unique_hash(tag, &object, false) != TMERR_NONE) - throw emu_fatalerror("Error adding object named '%s'", tag); - return m_list.prepend(object); - } - - // add the given object to the tail of the list - _ElementType &append(const char *tag, _ElementType &object) - { - if (m_map.add_unique_hash(tag, &object, false) != TMERR_NONE) - throw emu_fatalerror("Error adding object named '%s'", tag); - return m_list.append(object); - } - - // insert the given object after a particular object (NULL means prepend) - _ElementType &insert_after(const char *tag, _ElementType &object, _ElementType *insert_after) - { - if (m_map.add_unique_hash(tag, &object, false) != TMERR_NONE) - throw emu_fatalerror("Error adding object named '%s'", tag); - return m_list.insert_after(object, insert_after); - } - - // replace an item in the list at the same location, and remove it - _ElementType &replace_and_remove(const char *tag, _ElementType &object, _ElementType &toreplace) - { - m_map.remove(&toreplace); - m_list.replace_and_remove(object, toreplace); - if (m_map.add_unique_hash(tag, &object, false) != TMERR_NONE) - throw emu_fatalerror("Error replacing object named '%s'", tag); - return object; - } - - // detach the given item from the list, but don't free its memory - _ElementType &detach(_ElementType &object) - { - m_map.remove(&object); - return m_list.detach(object); - } - - // remove the given object and free its memory - void remove(_ElementType &object) - { - m_map.remove(&object); - return m_list.remove(object); - } - - // find an object by index in the list - _ElementType *find(int index) const - { - return m_list.find(index); - } - - // return the index of the given object in the list - int indexof(const _ElementType &object) const - { - return m_list.indexof(object); - } - - // operations by tag - _ElementType &replace_and_remove(const char *tag, _ElementType &object) { _ElementType *existing = find(tag); return (existing == NULL) ? append(tag, object) : replace_and_remove(tag, object, *existing); } - void remove(const char *tag) { _ElementType *object = find(tag); if (object != NULL) remove(*object); } - _ElementType *find(const char *tag) const { return m_map.find_hash_only(tag); } - int indexof(const char *tag) const { _ElementType *object = find(tag); return (object != NULL) ? m_list.indexof(*object) : NULL; } - -private: - // internal state - simple_list<_ElementType> m_list; - tagmap_t<_ElementType *> m_map; -}; - #endif /* __EMUTEMPL_H__ */ diff --git a/src/emu/fileio.c b/src/emu/fileio.c index 8ac8d96598f..4883c199d4a 100644 --- a/src/emu/fileio.c +++ b/src/emu/fileio.c @@ -144,10 +144,8 @@ emu_file::emu_file(UINT32 openflags) m_crc(0), m_openflags(openflags), m_zipfile(NULL), - m_zipdata(NULL), m_ziplength(0), m__7zfile(NULL), - m__7zdata(NULL), m__7zlength(0), m_remove_on_close(false) { @@ -162,10 +160,8 @@ emu_file::emu_file(const char *searchpath, UINT32 openflags) m_crc(0), m_openflags(openflags), m_zipfile(NULL), - m_zipdata(NULL), m_ziplength(0), m__7zfile(NULL), - m__7zdata(NULL), m__7zlength(0), m_remove_on_close(false) { @@ -239,15 +235,15 @@ hash_collection &emu_file::hashes(const char *types) return m_hashes; // if we have ZIP data, just hash that directly - if (m__7zdata != NULL) + if (m__7zdata.count() != 0) { - m_hashes.compute(m__7zdata, m__7zlength, needed); + m_hashes.compute(m__7zdata, m__7zdata.count(), needed); return m_hashes; } - if (m_zipdata != NULL) + if (m_zipdata.count() != 0) { - m_hashes.compute(m_zipdata, m_ziplength, needed); + m_hashes.compute(m_zipdata, m_zipdata.count(), needed); return m_hashes; } @@ -411,13 +407,8 @@ void emu_file::close() core_fclose(m_file); m_file = NULL; - if (m__7zdata != NULL) - global_free(m__7zdata); - m__7zdata = NULL; - - if (m_zipdata != NULL) - global_free(m_zipdata); - m_zipdata = NULL; + m__7zdata.reset(); + m_zipdata.reset(); if (m_remove_on_close) osd_rmfile(m_fullpath); @@ -739,27 +730,25 @@ file_error emu_file::attempt_zipped() file_error emu_file::load_zipped_file() { assert(m_file == NULL); - assert(m_zipdata == NULL); + assert(m_zipdata.count() == 0); assert(m_zipfile != NULL); // allocate some memory - m_zipdata = global_alloc_array(UINT8, m_ziplength); + m_zipdata.resize(m_ziplength); // read the data into our buffer and return - zip_error ziperr = zip_file_decompress(m_zipfile, m_zipdata, m_ziplength); + zip_error ziperr = zip_file_decompress(m_zipfile, m_zipdata, m_zipdata.count()); if (ziperr != ZIPERR_NONE) { - global_free(m_zipdata); - m_zipdata = NULL; + m_zipdata.reset(); return FILERR_FAILURE; } // convert to RAM file - file_error filerr = core_fopen_ram(m_zipdata, m_ziplength, m_openflags, &m_file); + file_error filerr = core_fopen_ram(m_zipdata, m_zipdata.count(), m_openflags, &m_file); if (filerr != FILERR_NONE) { - global_free(m_zipdata); - m_zipdata = NULL; + m_zipdata.reset(); return FILERR_FAILURE; } @@ -866,27 +855,25 @@ file_error emu_file::attempt__7zped() file_error emu_file::load__7zped_file() { assert(m_file == NULL); - assert(m__7zdata == NULL); + assert(m__7zdata.count() == 0); assert(m__7zfile != NULL); // allocate some memory - m__7zdata = global_alloc_array(UINT8, m__7zlength); + m__7zdata.resize(m__7zlength); // read the data into our buffer and return - _7z_error _7zerr = _7z_file_decompress(m__7zfile, m__7zdata, m__7zlength); + _7z_error _7zerr = _7z_file_decompress(m__7zfile, m__7zdata, m__7zdata.count()); if (_7zerr != _7ZERR_NONE) { - global_free(m__7zdata); - m__7zdata = NULL; + m__7zdata.reset(); return FILERR_FAILURE; } // convert to RAM file - file_error filerr = core_fopen_ram(m__7zdata, m__7zlength, m_openflags, &m_file); + file_error filerr = core_fopen_ram(m__7zdata, m__7zdata.count(), m_openflags, &m_file); if (filerr != FILERR_NONE) { - global_free(m__7zdata); - m__7zdata = NULL; + m__7zdata.reset(); return FILERR_FAILURE; } diff --git a/src/emu/fileio.h b/src/emu/fileio.h index 680748d0101..b5781a5d1c3 100644 --- a/src/emu/fileio.h +++ b/src/emu/fileio.h @@ -156,11 +156,11 @@ private: hash_collection m_hashes; // collection of hashes zip_file * m_zipfile; // ZIP file pointer - UINT8 * m_zipdata; // ZIP file data + dynamic_buffer m_zipdata; // ZIP file data UINT64 m_ziplength; // ZIP file length _7z_file * m__7zfile; // 7Z file pointer - UINT8 * m__7zdata; // 7Z file data + dynamic_buffer m__7zdata; // 7Z file data UINT64 m__7zlength; // 7Z file length bool m_remove_on_close; // flag: remove the file when closing diff --git a/src/emu/hashfile.c b/src/emu/hashfile.c index fb9a4d07a2c..f56504ca783 100644 --- a/src/emu/hashfile.c +++ b/src/emu/hashfile.c @@ -537,7 +537,7 @@ const hash_info *hashfile_lookup(hash_file *hashfile, const hash_collection *has const char *extra_info = NULL; -const char *read_hash_config(device_image_interface &image, const char *sysname) +bool read_hash_config(device_image_interface &image, const char *sysname, astring &result) { hash_file *hashfile = NULL; const hash_info *info = NULL; @@ -545,7 +545,7 @@ const char *read_hash_config(device_image_interface &image, const char *sysname) /* open the hash file */ hashfile = hashfile_open(image.device().machine().options(), sysname, FALSE, NULL); if (!hashfile) - return NULL; + return false; /* look up this entry in the hash file */ info = hashfile_lookup(hashfile, &image.hash()); @@ -553,34 +553,27 @@ const char *read_hash_config(device_image_interface &image, const char *sysname) if (!info || !info->extrainfo) { hashfile_close(hashfile); - return NULL; + return false; } - extra_info = auto_strdup(image.device().machine(), info->extrainfo); - if (!extra_info) - { - hashfile_close(hashfile); - return NULL; - } + result.cpy(info->extrainfo); /* copy the relevant entries */ hashfile_close(hashfile); - - return extra_info; + return true; } -const char *hashfile_extrainfo(device_image_interface &image) +bool hashfile_extrainfo(device_image_interface &image, astring &result) { - const char *rc; - /* now read the hash file */ image.crc(); extra_info = NULL; int drv = driver_list::find(image.device().machine().system()); int compat, open = drv; + bool hashfound; do { - rc = read_hash_config(image, driver_list::driver(open).name); + hashfound = read_hash_config(image, driver_list::driver(open).name, result); // first check if there are compatible systems compat = driver_list::compatible_with(open); // if so, try to open its hashfile @@ -594,8 +587,8 @@ const char *hashfile_extrainfo(device_image_interface &image) } } // if no extrainfo has been found but we can try a compatible or a parent set, go back - while (rc == NULL && open != -1); - return rc; + while (!hashfound && open != -1); + return hashfound; } /*************************************************************************** @@ -616,11 +609,11 @@ static void *expat_malloc(size_t size) static void *expat_realloc(void *ptr, size_t size) { - if (ptr) global_free(ptr); + if (ptr) global_free_array((UINT8 *)ptr); return global_alloc_array_clear(UINT8,size); } static void expat_free(void *ptr) { - global_free(ptr); + global_free_array((UINT8 *)ptr); } diff --git a/src/emu/hashfile.h b/src/emu/hashfile.h index c59421487f2..c462b5c74d3 100644 --- a/src/emu/hashfile.h +++ b/src/emu/hashfile.h @@ -12,6 +12,6 @@ #include "emu.h" -const char *hashfile_extrainfo(device_image_interface &image); +bool hashfile_extrainfo(device_image_interface &image, astring &result); #endif /* __HASHFILE_H__ */ diff --git a/src/emu/imagedev/cartslot.h b/src/emu/imagedev/cartslot.h index fee89b2cb70..9b524dbda9f 100644 --- a/src/emu/imagedev/cartslot.h +++ b/src/emu/imagedev/cartslot.h @@ -39,7 +39,7 @@ public: virtual bool call_load(); virtual void call_unload(); virtual void call_display_info() { if (!m_device_image_displayinfo.isnull()) m_device_image_displayinfo(*this); } - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { load_software_part_region( this, swlist, swname, start_entry ); return TRUE; } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { load_software_part_region( *this, swlist, swname, start_entry ); return TRUE; } virtual device_image_partialhash_func get_partial_hash() const { return m_device_image_partialhash; } virtual iodevice_t image_type() const { return IO_CARTSLOT; } diff --git a/src/emu/imagedev/cassette.h b/src/emu/imagedev/cassette.h index 7dcbc77a2bd..7fd6c2ea4fb 100644 --- a/src/emu/imagedev/cassette.h +++ b/src/emu/imagedev/cassette.h @@ -65,7 +65,7 @@ public: virtual void call_unload(); virtual void call_display(); virtual void call_display_info() { if (m_device_displayinfo) m_device_displayinfo(*this); } - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } virtual iodevice_t image_type() const { return IO_CASSETTE; } diff --git a/src/emu/imagedev/chd_cd.c b/src/emu/imagedev/chd_cd.c index 31b29aa1865..153e9dd3365 100644 --- a/src/emu/imagedev/chd_cd.c +++ b/src/emu/imagedev/chd_cd.c @@ -65,15 +65,7 @@ void cdrom_image_device::device_config_complete() m_extension_list = "chd,cue,toc,nrg,gdi,iso,cdr"; - image_device_format *format = global_alloc_clear(image_device_format);; - format->m_index = 0; - format->m_name = "chdcd"; - format->m_description = "CD-ROM drive"; - format->m_extensions = m_extension_list; - format->m_optspec = cd_option_spec; - format->m_next = NULL; - - m_formatlist = format; + m_formatlist.append(*global_alloc(image_device_format("chdcd", "CD-ROM drive", m_extension_list, cd_option_spec))); // set brief and instance name update_names(); diff --git a/src/emu/imagedev/chd_cd.h b/src/emu/imagedev/chd_cd.h index d5f8bdb30b1..1504a28f13f 100644 --- a/src/emu/imagedev/chd_cd.h +++ b/src/emu/imagedev/chd_cd.h @@ -38,7 +38,7 @@ public: virtual bool call_load(); virtual void call_unload(); virtual void call_display_info() { if (m_device_displayinfo) m_device_displayinfo(*this); } - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { load_software_part_region(this, swlist, swname, start_entry ); return TRUE; } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } virtual iodevice_t image_type() const { return IO_CDROM; } @@ -61,7 +61,6 @@ protected: chd_file m_self_chd; cdrom_file *m_cdrom_handle; - image_device_format m_format; const char *m_extension_list; }; diff --git a/src/emu/imagedev/flopdrv.c b/src/emu/imagedev/flopdrv.c index c9c97cf5ddc..69b883f585a 100644 --- a/src/emu/imagedev/flopdrv.c +++ b/src/emu/imagedev/flopdrv.c @@ -918,31 +918,14 @@ void legacy_floppy_image_device::device_start() void legacy_floppy_image_device::device_config_complete() { - image_device_format **formatptr; - image_device_format *format; - formatptr = &m_formatlist; - int cnt = 0; - m_extension_list[0] = '\0'; const struct FloppyFormat *floppy_options = ((floppy_interface*)static_config())->formats; for (int i = 0; floppy_options[i].construct; i++) { // only add if creatable if (floppy_options[i].param_guidelines) { - // allocate a new format - format = global_alloc_clear(image_device_format); - - // populate it - format->m_index = cnt; - format->m_name = floppy_options[i].name; - format->m_description = floppy_options[i].description; - format->m_extensions = floppy_options[i].extensions; - format->m_optspec = floppy_options[i].param_guidelines; - - // and append it to the list - *formatptr = format; - formatptr = &format->m_next; - cnt++; + // allocate a new format and append it to the list + m_formatlist.append(*global_alloc(image_device_format(floppy_options[i].name, floppy_options[i].description, floppy_options[i].extensions, floppy_options[i].param_guidelines))); } image_specify_extension( m_extension_list, 256, floppy_options[i].extensions ); } diff --git a/src/emu/imagedev/flopdrv.h b/src/emu/imagedev/flopdrv.h index c59e4d282a2..a5146168d3c 100644 --- a/src/emu/imagedev/flopdrv.h +++ b/src/emu/imagedev/flopdrv.h @@ -187,7 +187,7 @@ public: ~legacy_floppy_image_device(); virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } virtual bool call_create(int format_type, option_resolution *format_options); virtual void call_unload(); virtual void call_display_info(); @@ -204,13 +204,13 @@ public: virtual const option_guide *create_option_guide() const { return floppy_option_guide; } // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct floppy_drive *token() const { assert(m_token != NULL); return m_token; } protected: // device overrides virtual void device_config_complete(); virtual void device_start(); - void *m_token; + struct floppy_drive *m_token; char m_extension_list[256]; }; diff --git a/src/emu/imagedev/floppy.c b/src/emu/imagedev/floppy.c index 911b3271dca..bd32e44a9fc 100644 --- a/src/emu/imagedev/floppy.c +++ b/src/emu/imagedev/floppy.c @@ -187,9 +187,6 @@ void floppy_image_device::setup_wpt_cb(wpt_cb cb) void floppy_image_device::set_formats(const floppy_format_type *formats) { - image_device_format **formatptr; - image_device_format *format; - formatptr = &m_formatlist; extension_list[0] = '\0'; fif_list = 0; for(int cnt=0; formats[cnt]; cnt++) @@ -201,17 +198,9 @@ void floppy_image_device::set_formats(const floppy_format_type *formats) else fif_list->append(fif); - format = global_alloc_clear(image_device_format); - format->m_index = cnt; - format->m_name = fif->name(); - format->m_description = fif->description(); - format->m_extensions = fif->extensions(); - format->m_optspec = ""; + m_formatlist.append(*global_alloc(image_device_format(fif->name(), fif->description(), fif->extensions(), ""))); image_specify_extension( extension_list, 256, fif->extensions() ); - // and append it to the list - *formatptr = format; - formatptr = &format->m_next; } // set brief and instance name @@ -615,7 +604,7 @@ void floppy_image_device::write_flux(attotime start, attotime end, int transitio int start_pos = find_position(base, start); int end_pos = find_position(base, end); - int *trans_pos = transition_count ? global_alloc_array(int, transition_count) : 0; + dynamic_array trans_pos(transition_count); for(int i=0; i != transition_count; i++) trans_pos[i] = find_position(base, transitions[i]); @@ -663,9 +652,6 @@ void floppy_image_device::write_flux(attotime start, attotime end, int transitio } image->set_track_size(cyl, ss, cells); - - if(trans_pos) - global_free(trans_pos); } void floppy_image_device::write_zone(UINT32 *buf, int &cells, int &index, UINT32 spos, UINT32 epos, UINT32 mg) @@ -839,32 +825,29 @@ astring ui_menu_control_floppy_image::try_file(astring location, astring name, b void ui_menu_control_floppy_image::hook_load(astring filename, bool softlist) { input_filename = filename; - if(softlist) { - char *swlist_name, *swname, *swpart; - software_name_split(filename.cstr(), &swlist_name, &swname, &swpart); - software_list *sw_list = software_list_open(machine().options(), swlist_name, FALSE, NULL); - software_info *sw_info = software_list_find(sw_list, swname, NULL); - software_part *sw_part = software_find_part(sw_info, swpart, NULL); - const char *parentname = software_get_clone(machine().options(), swlist_name, sw_info->shortname); - for(const rom_entry *region = sw_part->romdata; region; region = rom_next_region(region)) { + if (softlist) + { + astring swlist_name, swinfo_name, swpart_name; + device_image_interface::software_name_split(filename.cstr(), swlist_name, swinfo_name, swpart_name); + software_list_device *swlistdev = software_list_device::find_by_name(machine().config(), swlist_name); + software_info *swinfo = swlistdev->find(swinfo_name); + software_part *swpart = swinfo->find_part(swpart_name); + const char *parentname = swinfo->parentname(); + for(const rom_entry *region = swpart->romdata(); region; region = rom_next_region(region)) { const rom_entry *romp = region + 1; UINT32 crc = 0; bool has_crc = hash_collection(ROM_GETHASHDATA(romp)).crc(crc); - filename = try_file(astring(swlist_name) + PATH_SEPARATOR + astring(swname), ROM_GETNAME(romp), has_crc, crc); + filename = try_file(astring(swlistdev->list_name()) + PATH_SEPARATOR + astring(swinfo_name), ROM_GETNAME(romp), has_crc, crc); if(filename == "") filename = try_file(astring(swlist_name) + PATH_SEPARATOR + astring(parentname), ROM_GETNAME(romp), has_crc, crc); if(filename == "") - filename = try_file(swname, ROM_GETNAME(romp), has_crc, crc); + filename = try_file(swinfo_name, ROM_GETNAME(romp), has_crc, crc); if(filename == "") filename = try_file(parentname, ROM_GETNAME(romp), has_crc, crc); if(filename != "") - goto found; + break; } - - found: - software_list_close(sw_list); - global_free(swlist_name); } input_format = static_cast(image)->identify(filename); diff --git a/src/emu/imagedev/floppy.h b/src/emu/imagedev/floppy.h index 9646ecde7bb..a7b06749cc7 100644 --- a/src/emu/imagedev/floppy.h +++ b/src/emu/imagedev/floppy.h @@ -70,7 +70,7 @@ public: virtual void call_unload(); virtual bool call_create(int format_type, option_resolution *format_options); virtual void call_display_info() {} - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } virtual const char *image_interface() const = 0; virtual iodevice_t image_type() const { return IO_FLOPPY; } @@ -131,7 +131,6 @@ protected: virtual void setup_characteristics() = 0; - image_device_format format; floppy_image_format_t *input_format; floppy_image_format_t *output_format; floppy_image *image; diff --git a/src/emu/imagedev/harddriv.c b/src/emu/imagedev/harddriv.c index f65be26142c..089d80518a1 100644 --- a/src/emu/imagedev/harddriv.c +++ b/src/emu/imagedev/harddriv.c @@ -74,15 +74,7 @@ void harddisk_image_device::device_config_complete() memset(&m_device_displayinfo, 0, sizeof(m_device_displayinfo)); } - image_device_format *format = global_alloc_clear(image_device_format);; - format->m_index = 0; - format->m_name = "chd"; - format->m_description = "CHD Hard drive"; - format->m_extensions = "chd,hd"; - format->m_optspec = hd_option_spec; - format->m_next = NULL; - - m_formatlist = format; + m_formatlist.append(*global_alloc(image_device_format("chd", "CHD Hard drive", "chd,hd", hd_option_spec))); // set brief and instance name update_names(); diff --git a/src/emu/imagedev/harddriv.h b/src/emu/imagedev/harddriv.h index 05e65236365..c44e47bb802 100644 --- a/src/emu/imagedev/harddriv.h +++ b/src/emu/imagedev/harddriv.h @@ -41,7 +41,7 @@ public: virtual bool call_create(int create_format, option_resolution *create_args); virtual void call_unload(); virtual void call_display_info() { if (m_device_displayinfo) m_device_displayinfo(*this); } - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { load_software_part_region(this, swlist, swname, start_entry ); return TRUE; } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } virtual iodevice_t image_type() const { return IO_HARDDISK; } @@ -70,8 +70,6 @@ protected: chd_file m_origchd; /* handle to the original CHD */ chd_file m_diffchd; /* handle to the diff CHD */ hard_disk_file *m_hard_disk_handle; - - image_device_format m_format; }; // device type definition diff --git a/src/emu/imagedev/snapquik.h b/src/emu/imagedev/snapquik.h index adde197320b..909b8c2081c 100644 --- a/src/emu/imagedev/snapquik.h +++ b/src/emu/imagedev/snapquik.h @@ -23,7 +23,7 @@ public: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } virtual iodevice_t image_type() const { return IO_SNAPSHOT; } virtual bool is_readable() const { return 1; } diff --git a/src/emu/info.c b/src/emu/info.c index a54f73d4cfa..67ece74f50a 100644 --- a/src/emu/info.c +++ b/src/emu/info.c @@ -401,7 +401,7 @@ void info_xml_creator::output_devices() { astring temptag("_"); temptag.cat(option->name()); - device_t *dev = const_cast(m_drivlist.config()).device_add(&m_drivlist.config().root_device(), temptag.cstr(), option->devtype(), 0); + auto_pointer dev(const_cast(m_drivlist.config()).device_add(&m_drivlist.config().root_device(), temptag.cstr(), option->devtype(), 0)); // notify this device and all its subdevices that they are now configured device_iterator subiter(*dev); @@ -413,7 +413,6 @@ void info_xml_creator::output_devices() output_one_device(*dev, temptag.cstr()); const_cast(m_drivlist.config()).device_remove(&m_drivlist.config().root_device(), temptag.cstr()); - global_free(dev); } } } diff --git a/src/emu/input.c b/src/emu/input.c index f7f7aa93b94..0ebd5d7df3d 100644 --- a/src/emu/input.c +++ b/src/emu/input.c @@ -44,54 +44,6 @@ const input_seq input_seq::empty_seq; // TYPE DEFINITIONS //************************************************************************** -// ======================> input_device_item - -// a single item on an input device -class input_device_item -{ -protected: - // construction/destruction - input_device_item(input_device &device, const char *name, void *internal, input_item_id itemid, item_get_state_func getstate, input_item_class itemclass); - virtual ~input_device_item() { } - -public: - // getters - input_device &device() const { return m_device; } - input_manager &manager() const { return m_device.manager(); } - running_machine &machine() const { return m_device.machine(); } - const char *name() const { return m_name; } - void *internal() const { return m_internal; } - input_item_id itemid() const { return m_itemid; } - input_item_class itemclass() const { return m_itemclass; } - const char *token() const { return m_token; } - INT32 current() const { return m_current; } - INT32 memory() const { return m_memory; } - - // helpers - INT32 update_value() { return m_current = (*m_getstate)(m_device.internal(), m_internal); } - void set_memory(INT32 value) { m_memory = value; } - - // readers - virtual INT32 read_as_switch(input_item_modifier modifier) = 0; - virtual INT32 read_as_relative(input_item_modifier modifier) = 0; - virtual INT32 read_as_absolute(input_item_modifier modifier) = 0; - -protected: - // internal state - input_device & m_device; // reference to our owning device - astring m_name; // string name of item - void * m_internal; // internal callback pointer - input_item_id m_itemid; // originally specified item id - input_item_class m_itemclass; // class of the item - item_get_state_func m_getstate; // get state callback - astring m_token; // tokenized name for non-standard items - - // live state - INT32 m_current; // current raw value - INT32 m_memory; // "memory" value, to remember where we started during polling -}; - - // ======================> input_device_switch_item // derived input item representing a switch input @@ -848,9 +800,6 @@ input_device::input_device(input_class &_class, int devindex, const char *name, m_steadykey_enabled(_class.manager().machine().options().steadykey()), m_lightgun_reload_button(_class.manager().machine().options().offscreen_reload()) { - // reset the items - memset(m_item, 0, sizeof(m_item)); - // additional work for joysticks if (devclass() == DEVICE_CLASS_JOYSTICK) { @@ -899,15 +848,15 @@ input_item_id input_device::add_item(const char *name, input_item_id itemid, ite switch (m_class.standard_item_class(originalid)) { case ITEM_CLASS_SWITCH: - item = auto_alloc(machine(), input_device_switch_item(*this, name, internal, itemid, getstate)); + item = global_alloc(input_device_switch_item(*this, name, internal, itemid, getstate)); break; case ITEM_CLASS_RELATIVE: - item = auto_alloc(machine(), input_device_relative_item(*this, name, internal, itemid, getstate)); + item = global_alloc(input_device_relative_item(*this, name, internal, itemid, getstate)); break; case ITEM_CLASS_ABSOLUTE: - item = auto_alloc(machine(), input_device_absolute_item(*this, name, internal, itemid, getstate)); + item = global_alloc(input_device_absolute_item(*this, name, internal, itemid, getstate)); break; default: @@ -915,7 +864,7 @@ input_item_id input_device::add_item(const char *name, input_item_id itemid, ite } // assign the new slot and update the maximum - m_item[itemid] = item; + m_item[itemid].reset(item); m_maxitem = MAX(m_maxitem, itemid); return itemid; } @@ -1006,8 +955,6 @@ input_class::input_class(input_manager &manager, input_device_class devclass, bo m_enabled(enabled), m_multi(multi) { - memset(m_device, 0, sizeof(m_device)); - // request a per-frame callback for the keyboard class if (devclass == DEVICE_CLASS_KEYBOARD) machine().add_notifier(MACHINE_NOTIFY_FRAME, machine_notify_delegate(FUNC(input_class::frame_callback), this)); @@ -1038,13 +985,13 @@ input_device *input_class::add_device(int devindex, const char *name, void *inte assert(m_device[devindex] == NULL); // allocate a new device - input_device *device = m_device[devindex] = auto_alloc(machine(), input_device(*this, devindex, name, internal)); + m_device[devindex].reset(global_alloc(input_device(*this, devindex, name, internal))); // update the maximum index found m_maxindex = MAX(m_maxindex, devindex); mame_printf_verbose("Input: Adding %s #%d: %s\n", (*devclass_string_table)[m_devclass], devindex, name); - return device; + return m_device[devindex]; } diff --git a/src/emu/input.h b/src/emu/input.h index 15615a55ace..e35838520ee 100644 --- a/src/emu/input.h +++ b/src/emu/input.h @@ -484,6 +484,55 @@ private: }; +// ======================> input_device_item + +// a single item on an input device +class input_device_item +{ +protected: + // construction/destruction + input_device_item(input_device &device, const char *name, void *internal, input_item_id itemid, item_get_state_func getstate, input_item_class itemclass); + +public: + virtual ~input_device_item() { } + + // getters + input_device &device() const { return m_device; } + input_manager &manager() const; + running_machine &machine() const; + const char *name() const { return m_name; } + void *internal() const { return m_internal; } + input_item_id itemid() const { return m_itemid; } + input_item_class itemclass() const { return m_itemclass; } + const char *token() const { return m_token; } + INT32 current() const { return m_current; } + INT32 memory() const { return m_memory; } + + // helpers + INT32 update_value(); + void set_memory(INT32 value) { m_memory = value; } + + // readers + virtual INT32 read_as_switch(input_item_modifier modifier) = 0; + virtual INT32 read_as_relative(input_item_modifier modifier) = 0; + virtual INT32 read_as_absolute(input_item_modifier modifier) = 0; + +protected: + // internal state + input_device & m_device; // reference to our owning device + astring m_name; // string name of item + void * m_internal; // internal callback pointer + input_item_id m_itemid; // originally specified item id + input_item_class m_itemclass; // class of the item + item_get_state_func m_getstate; // get state callback + astring m_token; // tokenized name for non-standard items + + // live state + INT32 m_current; // current raw value + INT32 m_memory; // "memory" value, to remember where we started during polling +}; + + // ======================> input_device // a logical device of a given class that can provide input @@ -522,7 +571,7 @@ private: input_class & m_class; // reference to our class astring m_name; // string name of device int m_devindex; // device index of this device - input_device_item * m_item[ITEM_ID_ABSOLUTE_MAXIMUM+1]; // array of pointers to items + auto_pointer m_item[ITEM_ID_ABSOLUTE_MAXIMUM+1]; // array of pointers to items input_item_id m_maxitem; // maximum item index void * m_internal; // internal callback pointer @@ -547,7 +596,7 @@ public: // getters input_manager &manager() const { return m_manager; } running_machine &machine() const; - input_device *device(int index) const { return (index <= m_maxindex) ? m_device[index] : NULL; } + input_device *device(int index) const { return (index <= m_maxindex) ? m_device[index].get() : NULL; } input_device_class devclass() const { return m_devclass; } int maxindex() const { return m_maxindex; } bool enabled() const { return m_enabled; } @@ -570,7 +619,7 @@ private: // internal state input_manager & m_manager; // reference to our manager - input_device * m_device[DEVICE_INDEX_MAXIMUM]; // array of devices in this class + auto_pointer m_device[DEVICE_INDEX_MAXIMUM]; // array of devices in this class input_device_class m_devclass; // our device class int m_maxindex; // maximum populated index bool m_enabled; // is this class enabled? @@ -1094,6 +1143,11 @@ extern const char joystick_map_4way_diagonal[]; // INLINE FUNCTIONS //************************************************************************** +// input_device_item helpers +inline input_manager &input_device_item::manager() const { return m_device.manager(); } +inline running_machine &input_device_item::machine() const { return m_device.machine(); } +inline INT32 input_device_item::update_value() { return m_current = (*m_getstate)(m_device.internal(), m_internal); } + // input_device helpers inline input_manager &input_device::manager() const { return m_class.manager(); } inline running_machine &input_device::machine() const { return m_class.machine(); } @@ -1103,4 +1157,5 @@ inline input_device_class input_device::devclass() const { return m_class.devcla inline running_machine &input_class::machine() const { return m_manager.machine(); } + #endif // __INPUT_H__ diff --git a/src/emu/ioport.c b/src/emu/ioport.c index eb4e201886d..7d7c5978f39 100644 --- a/src/emu/ioport.c +++ b/src/emu/ioport.c @@ -1587,7 +1587,6 @@ ioport_diplocation::ioport_diplocation(const char *name, UINT8 swnum, bool inver ioport_field::ioport_field(ioport_port &port, ioport_type type, ioport_value defvalue, ioport_value maskbits, const char *name) : m_next(NULL), m_port(port), - m_live(NULL), m_modcount(port.modcount()), m_mask(maskbits), m_defvalue(defvalue & maskbits), @@ -1638,7 +1637,6 @@ ioport_field::ioport_field(ioport_port &port, ioport_type type, ioport_value def ioport_field::~ioport_field() { - global_free(m_live); } @@ -2263,7 +2261,7 @@ void ioport_field::init_live_state(analog_field *analog) m_crosshair_mapper.bind_relative_to(device()); // allocate live state - m_live = global_alloc(ioport_field_live(*this, analog)); + m_live.reset(global_alloc(ioport_field_live(*this, analog))); m_condition.initialize(device()); @@ -2338,8 +2336,7 @@ ioport_port::ioport_port(device_t &owner, const char *tag) m_device(owner), m_tag(tag), m_modcount(0), - m_active(0), - m_live(NULL) + m_active(0) { } @@ -2350,7 +2347,6 @@ ioport_port::ioport_port(device_t &owner, const char *tag) ioport_port::~ioport_port() { - global_free(m_live); } @@ -2530,7 +2526,7 @@ void ioport_port::insert_field(ioport_field &newfield, ioport_value &disallowedb void ioport_port::init_live_state() { - m_live = global_alloc(ioport_port_live(*this)); + m_live.reset(global_alloc(ioport_port_live(*this))); } diff --git a/src/emu/ioport.h b/src/emu/ioport.h index 1792094264a..602cfebcdd2 100644 --- a/src/emu/ioport.h +++ b/src/emu/ioport.h @@ -1090,7 +1090,7 @@ private: // internal state ioport_field * m_next; // pointer to next field in sequence ioport_port & m_port; // reference to the port that owns us - ioport_field_live * m_live; // live state of field (NULL if not live) + auto_pointer m_live; // live state of field (NULL if not live) int m_modcount; // modification count simple_list m_settinglist; // list of input_setting_configs simple_list m_diploclist; // list of locations for various bits @@ -1138,9 +1138,7 @@ class ioport_list : public tagged_list DISABLE_COPYING(ioport_list); public: - // construction/destruction - ioport_list(resource_pool &pool = global_resource_pool()) - : tagged_list(pool) { } + ioport_list() { } using tagged_list::append; void append(device_t &device, astring &errorbuf); @@ -1195,7 +1193,7 @@ private: astring m_tag; // copy of this port's tag int m_modcount; // modification count ioport_value m_active; // mask of active bits in the port - ioport_port_live * m_live; // live state of port (NULL if not live) + auto_pointer m_live; // live state of port (NULL if not live) }; diff --git a/src/emu/machine.c b/src/emu/machine.c index a87433f3e56..2789183b5a6 100644 --- a/src/emu/machine.c +++ b/src/emu/machine.c @@ -81,6 +81,7 @@ #include "validity.h" #include "unzip.h" #include "debug/debugcon.h" +#include "debug/debugvw.h" #include @@ -120,14 +121,6 @@ running_machine::running_machine(const machine_config &_config, osd_interface &o m_config(_config), m_system(_config.gamedrv()), m_osd(osd), - m_cheat(NULL), - m_render(NULL), - m_input(NULL), - m_sound(NULL), - m_video(NULL), - m_ui(NULL), - m_tilemap(NULL), - m_debug_view(NULL), m_current_phase(MACHINE_PHASE_PREINIT), m_paused(false), m_hard_reset_pending(false), @@ -139,11 +132,9 @@ running_machine::running_machine(const machine_config &_config, osd_interface &o m_ui_active(_config.options().ui_active()), m_basename(_config.gamedrv().name), m_sample_rate(_config.options().sample_rate()), - m_logfile(NULL), m_saveload_schedule(SLS_NONE), m_saveload_schedule_time(attotime::zero), m_saveload_searchpath(NULL), - m_logerror_list(m_respool), m_save(*this), m_memory(*this), @@ -225,9 +216,9 @@ void running_machine::start() { // initialize basic can't-fail systems here config_init(*this); - m_input = auto_alloc(*this, input_manager(*this)); + m_input.reset(global_alloc(input_manager(*this))); output_init(*this); - m_render = auto_alloc(*this, render_manager(*this)); + m_render.reset(global_alloc(render_manager(*this))); generic_machine_init(*this); // allocate a soft_reset timer @@ -237,8 +228,8 @@ void running_machine::start() m_osd.init(*this); // create the video manager - m_video = auto_alloc(*this, video_manager(*this)); - m_ui = auto_alloc(*this, ui_manager(*this)); + m_video.reset(global_alloc(video_manager(*this))); + m_ui.reset(global_alloc(ui_manager(*this))); // initialize the base time (needed for doing record/playback) ::time(&m_base_time); @@ -254,7 +245,7 @@ void running_machine::start() ui_input_init(*this); // initialize the streams engine before the sound devices start - m_sound = auto_alloc(*this, sound_manager(*this)); + m_sound.reset(global_alloc(sound_manager(*this))); // first load ROMs, then populate memory, and finally initialize CPUs // these operations must proceed in this order @@ -270,7 +261,7 @@ void running_machine::start() // initialize image devices image_init(*this); - m_tilemap = auto_alloc(*this, tilemap_manager(*this)); + m_tilemap.reset(global_alloc(tilemap_manager(*this))); crosshair_init(*this); network_init(*this); @@ -300,7 +291,7 @@ void running_machine::start() schedule_load("auto"); // set up the cheat engine - m_cheat = auto_alloc(*this, cheat_manager(*this)); + m_cheat.reset(global_alloc(cheat_manager(*this))); // allocate autoboot timer m_autoboot_timer = scheduler().timer_alloc(timer_expired_delegate(FUNC(running_machine::autoboot_callback), this)); @@ -348,7 +339,7 @@ int running_machine::run(bool firstrun) // if we have a logfile, set up the callback if (options().log()) { - m_logfile = auto_alloc(*this, emu_file(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)); + m_logfile.reset(global_alloc(emu_file(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS))); file_error filerr = m_logfile->open("error.log"); assert_always(filerr == FILERR_NONE, "unable to open log file"); add_logerror_callback(logfile_callback); @@ -442,7 +433,7 @@ int running_machine::run(bool firstrun) zip_file_cache_clear(); // close the logfile - auto_free(*this, m_logfile); + m_logfile.reset(); return error; } @@ -784,7 +775,7 @@ void running_machine::add_notifier(machine_notification event, machine_notify_de void running_machine::add_logerror_callback(logerror_callback callback) { assert_always(m_current_phase == MACHINE_PHASE_INIT, "Can only call add_logerror_callback at init time!"); - m_logerror_list.append(*auto_alloc(*this, logerror_callback_item(callback))); + m_logerror_list.append(*global_alloc(logerror_callback_item(callback))); } @@ -1149,9 +1140,6 @@ void running_machine::stop_all_devices() device_iterator iter(root_device()); for (device_t *device = iter.first(); device != NULL; device = iter.next()) device->stop(); - - // then nuke the device tree -// global_free(m_root_device); } diff --git a/src/emu/machine.h b/src/emu/machine.h index 62b64295d4b..81657587965 100644 --- a/src/emu/machine.h +++ b/src/emu/machine.h @@ -104,7 +104,6 @@ const int DEBUG_FLAG_OSD_ENABLED = 0x00001000; // The OSD debugger is e #define auto_bitmap_ind16_alloc(m, w, h) auto_alloc(m, bitmap_ind16(w, h)) #define auto_bitmap_ind32_alloc(m, w, h) auto_alloc(m, bitmap_ind32(w, h)) #define auto_bitmap_rgb32_alloc(m, w, h) auto_alloc(m, bitmap_rgb32(w, h)) -#define auto_strdup(m, s) strcpy(auto_alloc_array(m, char, strlen(s) + 1), s) @@ -311,14 +310,14 @@ private: osd_interface & m_osd; // reference to OSD system // managers - cheat_manager * m_cheat; // internal data from cheat.c - render_manager * m_render; // internal data from render.c - input_manager * m_input; // internal data from input.c - sound_manager * m_sound; // internal data from sound.c - video_manager * m_video; // internal data from video.c - ui_manager * m_ui; // internal data from ui.c - tilemap_manager * m_tilemap; // internal data from tilemap.c - debug_view_manager * m_debug_view; // internal data from debugvw.c + auto_pointer m_cheat; // internal data from cheat.c + auto_pointer m_render; // internal data from render.c + auto_pointer m_input; // internal data from input.c + auto_pointer m_sound; // internal data from sound.c + auto_pointer m_video; // internal data from video.c + auto_pointer m_ui; // internal data from ui.c + auto_pointer m_tilemap; // internal data from tilemap.c + auto_pointer m_debug_view; // internal data from debugvw.c // system state machine_phase m_current_phase; // current execution phase @@ -341,7 +340,7 @@ private: astring m_basename; // basename used for game-related paths astring m_context; // context string buffer int m_sample_rate; // the digital audio sample rate - emu_file * m_logfile; // pointer to the active log file + auto_pointer m_logfile; // pointer to the active log file // load/save management enum saveload_schedule diff --git a/src/emu/machine/68681.c b/src/emu/machine/68681.c index 3e489728c87..78d9b4e5d10 100644 --- a/src/emu/machine/68681.c +++ b/src/emu/machine/68681.c @@ -912,6 +912,11 @@ duart68681_device::duart68681_device(const machine_config &mconfig, const char * m_token = global_alloc_clear(duart68681_state); } +duart68681_device::~duart68681_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/emu/machine/68681.h b/src/emu/machine/68681.h index 4e4eb208586..5327e82986d 100644 --- a/src/emu/machine/68681.h +++ b/src/emu/machine/68681.h @@ -16,10 +16,10 @@ class duart68681_device : public device_t { public: duart68681_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~duart68681_device() { global_free(m_token); } + ~duart68681_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct duart68681_state *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -27,7 +27,7 @@ protected: virtual void device_reset(); private: // internal state - void *m_token; + struct duart68681_state *m_token; }; extern ATTR_DEPRECATED const device_type DUART68681; diff --git a/src/emu/machine/intelfsh.c b/src/emu/machine/intelfsh.c index b77f38ea9f8..33f3a146a0a 100644 --- a/src/emu/machine/intelfsh.c +++ b/src/emu/machine/intelfsh.c @@ -496,11 +496,10 @@ void intelfsh_device::nvram_default() void intelfsh_device::nvram_read(emu_file &file) { - UINT8 *buffer = global_alloc_array(UINT8, m_size); + dynamic_buffer buffer(m_size); file.read(buffer, m_size); for (int byte = 0; byte < m_size; byte++) m_addrspace[0]->write_byte(byte, buffer[byte]); - global_free(buffer); } @@ -511,11 +510,10 @@ void intelfsh_device::nvram_read(emu_file &file) void intelfsh_device::nvram_write(emu_file &file) { - UINT8 *buffer = global_alloc_array(UINT8, m_size); + dynamic_buffer buffer(m_size); for (int byte = 0; byte < m_size; byte++) buffer[byte] = m_addrspace[0]->read_byte(byte); file.write(buffer, m_size); - global_free(buffer); } diff --git a/src/emu/machine/latch8.c b/src/emu/machine/latch8.c index c4a977828e6..fcd7b2e32b2 100644 --- a/src/emu/machine/latch8.c +++ b/src/emu/machine/latch8.c @@ -241,6 +241,11 @@ latch8_device::latch8_device(const machine_config &mconfig, const char *tag, dev memset((void*)&m_inline_config,0,sizeof(m_inline_config)); } +latch8_device::~latch8_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/emu/machine/latch8.h b/src/emu/machine/latch8.h index c35c90d0453..3ee52e5ac8d 100644 --- a/src/emu/machine/latch8.h +++ b/src/emu/machine/latch8.h @@ -44,10 +44,10 @@ class latch8_device : public device_t { public: latch8_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~latch8_device() { global_free(m_token); } + ~latch8_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct latch8_t *token() const { assert(m_token != NULL); return m_token; } latch8_config m_inline_config; void set_maskout(UINT32 maskout) { m_inline_config.maskout = maskout; } @@ -73,7 +73,7 @@ protected: virtual void device_reset(); private: // internal state - void *m_token; + struct latch8_t *m_token; }; extern const device_type LATCH8; diff --git a/src/emu/machine/nscsi_s1410.c b/src/emu/machine/nscsi_s1410.c index d3f3defd95e..ce9db745f45 100644 --- a/src/emu/machine/nscsi_s1410.c +++ b/src/emu/machine/nscsi_s1410.c @@ -58,7 +58,7 @@ void nscsi_s1410_device::scsi_command() blocks = (bytes_per_sector == 256) ? 32 : 17; int track_length = blocks*bytes_per_sector; - UINT8 *data = global_alloc_array(UINT8,track_length); + dynamic_buffer data(track_length); memset(data, 0xc6, track_length); if(!hard_disk_write(harddisk, lba, data)) { @@ -67,7 +67,6 @@ void nscsi_s1410_device::scsi_command() } else { scsi_status_complete(SS_GOOD); } - global_free(data); } break; diff --git a/src/emu/machine/s3c2400.c b/src/emu/machine/s3c2400.c index 3256be60d1a..1e0ee2a69ec 100644 --- a/src/emu/machine/s3c2400.c +++ b/src/emu/machine/s3c2400.c @@ -76,6 +76,11 @@ s3c2400_device::s3c2400_device(const machine_config &mconfig, const char *tag, d m_token = global_alloc_clear(s3c24xx_t); } +s3c2400_device::~s3c2400_device() +{ + global_free(m_token); +} + //------------------------------------------------- // static_set_palette_tag: Set the tag of the // palette device diff --git a/src/emu/machine/s3c2400.h b/src/emu/machine/s3c2400.h index ec27282b86d..cf33e3d2d52 100644 --- a/src/emu/machine/s3c2400.h +++ b/src/emu/machine/s3c2400.h @@ -37,13 +37,13 @@ class s3c2400_device : public device_t { public: s3c2400_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~s3c2400_device() { global_free(m_token); } + ~s3c2400_device(); // static configuration static void static_set_palette_tag(device_t &device, const char *tag); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct s3c24xx_t *token() const { assert(m_token != NULL); return m_token; } // device-level overrides virtual void device_config_complete(); @@ -51,7 +51,7 @@ public: virtual void device_reset(); private: // internal state - void *m_token; + struct s3c24xx_t *m_token; required_device m_palette; public: UINT32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); diff --git a/src/emu/machine/s3c2410.c b/src/emu/machine/s3c2410.c index 774077f8bcf..fee3f06b845 100644 --- a/src/emu/machine/s3c2410.c +++ b/src/emu/machine/s3c2410.c @@ -79,6 +79,11 @@ s3c2410_device::s3c2410_device(const machine_config &mconfig, const char *tag, d m_token = global_alloc_clear(s3c24xx_t); } +s3c2410_device::~s3c2410_device() +{ + global_free(m_token); +} + //------------------------------------------------- // static_set_palette_tag: Set the tag of the // palette device diff --git a/src/emu/machine/s3c2410.h b/src/emu/machine/s3c2410.h index 139dad06cc1..f418c388971 100644 --- a/src/emu/machine/s3c2410.h +++ b/src/emu/machine/s3c2410.h @@ -45,20 +45,20 @@ class s3c2410_device : public device_t { public: s3c2410_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~s3c2410_device() { global_free(m_token); } + ~s3c2410_device(); // static configuration static void static_set_palette_tag(device_t &device, const char *tag); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct s3c24xx_t *token() const { assert(m_token != NULL); return m_token; } // device-level overrides virtual void device_config_complete(); virtual void device_start(); virtual void device_reset(); private: // internal state - void *m_token; + struct s3c24xx_t *m_token; required_device m_palette; public: UINT32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); diff --git a/src/emu/machine/s3c2440.c b/src/emu/machine/s3c2440.c index 7019ce89bf8..e0425c9f3fc 100644 --- a/src/emu/machine/s3c2440.c +++ b/src/emu/machine/s3c2440.c @@ -81,6 +81,11 @@ s3c2440_device::s3c2440_device(const machine_config &mconfig, const char *tag, d m_token = global_alloc_clear(s3c24xx_t); } +s3c2440_device::~s3c2440_device() +{ + global_free(m_token); +} + //------------------------------------------------- // static_set_palette_tag: Set the tag of the // palette device diff --git a/src/emu/machine/s3c2440.h b/src/emu/machine/s3c2440.h index ebb8f087e6d..901ddd790f1 100644 --- a/src/emu/machine/s3c2440.h +++ b/src/emu/machine/s3c2440.h @@ -45,13 +45,13 @@ class s3c2440_device : public device_t { public: s3c2440_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~s3c2440_device() { global_free(m_token); } + ~s3c2440_device(); // static configuration static void static_set_palette_tag(device_t &device, const char *tag); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct s3c24xx_t *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -59,7 +59,7 @@ protected: virtual void device_reset(); private: // internal state - void *m_token; + struct s3c24xx_t *m_token; required_device m_palette; public: UINT32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); diff --git a/src/emu/machine/tc009xlvc.c b/src/emu/machine/tc009xlvc.c index 5d14d701b8b..e1ef19afab9 100644 --- a/src/emu/machine/tc009xlvc.c +++ b/src/emu/machine/tc009xlvc.c @@ -294,7 +294,7 @@ void tc0091lvc_device::device_start() //printf("m_gfx_index %d\n", m_gfx_index); - m_gfxdecode->set_gfx(m_gfx_index, auto_alloc(machine(), gfx_element(m_palette, char_layout, (UINT8 *)m_pcg_ram, m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index, global_alloc(gfx_element(m_palette, char_layout, (UINT8 *)m_pcg_ram, m_palette->entries() / 16, 0))); } void tc0091lvc_device::device_reset() diff --git a/src/emu/machine/wd17xx.c b/src/emu/machine/wd17xx.c index a52af7f5e26..f639803deb6 100644 --- a/src/emu/machine/wd17xx.c +++ b/src/emu/machine/wd17xx.c @@ -2254,6 +2254,11 @@ wd1770_device::wd1770_device(const machine_config &mconfig, device_type type, co m_token = global_alloc_clear(wd1770_state); } +wd1770_device::~wd1770_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/emu/machine/wd17xx.h b/src/emu/machine/wd17xx.h index f25bde784a9..8b41f4c5fbb 100644 --- a/src/emu/machine/wd17xx.h +++ b/src/emu/machine/wd17xx.h @@ -20,10 +20,10 @@ class wd1770_device : public device_t public: wd1770_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); wd1770_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); - ~wd1770_device() { global_free(m_token); } + virtual ~wd1770_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct wd1770_state *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -31,7 +31,7 @@ protected: virtual void device_reset(); private: // internal state - void *m_token; + struct wd1770_state *m_token; }; extern const device_type WD1770; diff --git a/src/emu/mame.c b/src/emu/mame.c index 2e00575159d..ab55609f2e2 100644 --- a/src/emu/mame.c +++ b/src/emu/mame.c @@ -170,6 +170,7 @@ int mame_execute(emu_options &options, osd_interface &osd) astring errors; options.parse_standard_inis(errors); } + // otherwise, perform validity checks before anything else if (system != NULL) { @@ -188,6 +189,7 @@ int mame_execute(emu_options &options, osd_interface &osd) web.set_machine(machine); web.push_message("update_machine"); + // run the machine error = machine.run(firstrun); firstrun = false; diff --git a/src/emu/mconfig.c b/src/emu/mconfig.c index 1ea7808ce7b..2dab4ad964d 100644 --- a/src/emu/mconfig.c +++ b/src/emu/mconfig.c @@ -29,8 +29,7 @@ machine_config::machine_config(const game_driver &gamedrv, emu_options &options) m_memcard_handler(NULL), m_default_layout(NULL), m_gamedrv(gamedrv), - m_options(options), - m_root_device(NULL) + m_options(options) { // construct the config (*gamedrv.machine_config)(*this, NULL, NULL); @@ -89,7 +88,6 @@ machine_config::machine_config(const game_driver &gamedrv, emu_options &options) machine_config::~machine_config() { - global_free(m_root_device); } @@ -145,7 +143,7 @@ device_t *machine_config::device_add(device_t *owner, const char *tag, device_ty // otherwise, allocate the device directly assert(m_root_device == NULL); - m_root_device = (*type)(*this, tag, owner, clock); + m_root_device.reset((*type)(*this, tag, owner, clock)); // apply any machine configuration owned by the device now machine_config_constructor additions = m_root_device->machine_config_additions(); diff --git a/src/emu/mconfig.h b/src/emu/mconfig.h index e82d9a1dcad..e37466e737d 100644 --- a/src/emu/mconfig.h +++ b/src/emu/mconfig.h @@ -103,7 +103,7 @@ private: // internal state const game_driver & m_gamedrv; emu_options & m_options; - device_t * m_root_device; + auto_pointer m_root_device; }; diff --git a/src/emu/memory.c b/src/emu/memory.c index 0b19dc94120..ac5a29068d9 100644 --- a/src/emu/memory.c +++ b/src/emu/memory.c @@ -772,7 +772,7 @@ private: } // internal state - handler_entry_read * m_handlers[TOTAL_MEMORY_BANKS]; // array of user-installed handlers + auto_pointer m_handlers[TOTAL_MEMORY_BANKS]; // array of user-installed handlers }; @@ -838,7 +838,7 @@ private: } // internal state - handler_entry_write * m_handlers[TOTAL_MEMORY_BANKS]; // array of user-installed handlers + auto_pointer m_handlers[TOTAL_MEMORY_BANKS]; // array of user-installed handlers }; // ======================> address_table_setoffset @@ -852,9 +852,7 @@ public: { // allocate handlers for each entry, prepopulating the bankptrs for banks for (int entrynum = 0; entrynum < ARRAY_LENGTH(m_handlers); entrynum++) - { - m_handlers[entrynum] = auto_alloc(space.machine(), handler_entry_setoffset()); - } + m_handlers[entrynum].reset(global_alloc(handler_entry_setoffset())); // Watchpoints and unmap states do not make sense for setoffset m_handlers[STATIC_NOP]->set_delegate(setoffset_delegate(FUNC(address_table_setoffset::nop_so), this)); @@ -863,8 +861,6 @@ public: ~address_table_setoffset() { - for (int handnum = 0; handnum < ARRAY_LENGTH(m_handlers); handnum++) - auto_free(m_space.machine(), m_handlers[handnum]); } handler_entry &handler(UINT32 index) const { assert(index < ARRAY_LENGTH(m_handlers)); return *m_handlers[index]; } @@ -892,7 +888,7 @@ private: } // internal state - handler_entry_setoffset *m_handlers[TOTAL_MEMORY_BANKS]; // array of user-installed handlers + auto_pointer m_handlers[TOTAL_MEMORY_BANKS]; // array of user-installed handlers }; @@ -1723,7 +1719,6 @@ address_space::address_space(memory_manager &manager, device_memory_interface &m : m_next(NULL), m_config(*memory.space_config(spacenum)), m_device(memory.device()), - m_map(NULL), m_addrmask(0xffffffffUL >> (32 - m_config.m_addrbus_width)), m_bytemask(address_to_byte_end(m_addrmask)), m_logaddrmask(0xffffffffUL >> (32 - m_config.m_logaddr_width)), @@ -1732,7 +1727,7 @@ address_space::address_space(memory_manager &manager, device_memory_interface &m m_spacenum(spacenum), m_debugger_access(false), m_log_unmap(true), - m_direct(*auto_alloc(memory.device().machine(), direct_read_data(*this))), + m_direct(global_alloc(direct_read_data(*this))), m_name(memory.space_config(spacenum)->name()), m_addrchars((m_config.m_addrbus_width + 3) / 4), m_logaddrchars((m_config.m_logaddr_width + 3) / 4), @@ -1750,8 +1745,6 @@ address_space::address_space(memory_manager &manager, device_memory_interface &m address_space::~address_space() { - auto_free(m_manager.machine(), &m_direct); - global_free(m_map); } @@ -1869,7 +1862,7 @@ void address_space::prepare_map() UINT32 devregionsize = (devregion != NULL) ? devregion->bytes() : 0; // allocate the address map - m_map = global_alloc(address_map(m_device, m_spacenum)); + m_map.reset(global_alloc(address_map(m_device, m_spacenum))); // merge in the submaps m_map->uplift_submaps(machine(), m_device, *m_device.owner(), endianness()); @@ -1900,7 +1893,7 @@ void address_space::prepare_map() if (manager().m_sharelist.find(device().siblingtag(fulltag, entry->m_share).cstr()) == NULL) { VPRINTF(("Creating share '%s' of length 0x%X\n", fulltag.cstr(), entry->m_byteend + 1 - entry->m_bytestart)); - memory_share *share = auto_alloc(machine(), memory_share(m_map->m_databits, entry->m_byteend + 1 - entry->m_bytestart, endianness())); + memory_share *share = global_alloc(memory_share(m_map->m_databits, entry->m_byteend + 1 - entry->m_bytestart, endianness())); manager().m_sharelist.append(fulltag, *share); } } @@ -2963,7 +2956,7 @@ void address_table::map_range(offs_t addrstart, offs_t addrend, offs_t addrmask, populate_range_mirrored(bytestart, byteend, bytemirror, entry); // recompute any direct access on this space if it is a read modification - m_space.m_direct.force_update(entry); + m_space.m_direct->force_update(entry); // verify_reference_counts(); } @@ -3089,7 +3082,7 @@ void address_table::setup_range_masked(offs_t addrstart, offs_t addrend, offs_t entries.push_back(entry); // recompute any direct access on this space if it is a read modification - m_space.m_direct.force_update(entry); + m_space.m_direct->force_update(entry); } // Ranges in range_partial must duplicated then partially changed @@ -3132,7 +3125,7 @@ void address_table::setup_range_masked(offs_t addrstart, offs_t addrend, offs_t entries.push_back(entry); // recompute any direct access on this space if it is a read modification - m_space.m_direct.force_update(entry); + m_space.m_direct->force_update(entry); } } @@ -3310,7 +3303,7 @@ void address_table::populate_range_mirrored(offs_t bytestart, offs_t byteend, of for (int bit = 0; bit < lmirrorbits; bit++) if (lmirrorcount & (1 << bit)) lmirrorbase |= lmirrorbit[bit]; - m_space.m_direct.remove_intersecting_ranges(bytestart + lmirrorbase, byteend + lmirrorbase); + m_space.m_direct->remove_intersecting_ranges(bytestart + lmirrorbase, byteend + lmirrorbase); } // if this is not our first time through, and the level 2 entry matches the previous @@ -3752,7 +3745,7 @@ address_table_read::address_table_read(address_space &space, bool large) for (int entrynum = 0; entrynum < ARRAY_LENGTH(m_handlers); entrynum++) { UINT8 **bankptr = (entrynum >= STATIC_BANK1 && entrynum <= STATIC_BANKMAX) ? space.manager().bank_pointer_addr(entrynum) : NULL; - m_handlers[entrynum] = auto_alloc(space.machine(), handler_entry_read(space.data_width(), space.endianness(), bankptr)); + m_handlers[entrynum].reset(global_alloc(handler_entry_read(space.data_width(), space.endianness(), bankptr))); } // we have to allocate different object types based on the data bus width @@ -3800,8 +3793,6 @@ address_table_read::address_table_read(address_space &space, bool large) address_table_read::~address_table_read() { - for (int handnum = 0; handnum < ARRAY_LENGTH(m_handlers); handnum++) - auto_free(m_space.machine(), m_handlers[handnum]); } @@ -3828,7 +3819,7 @@ address_table_write::address_table_write(address_space &space, bool large) for (int entrynum = 0; entrynum < ARRAY_LENGTH(m_handlers); entrynum++) { UINT8 **bankptr = (entrynum >= STATIC_BANK1 && entrynum <= STATIC_BANKMAX) ? space.manager().bank_pointer_addr(entrynum) : NULL; - m_handlers[entrynum] = auto_alloc(space.machine(), handler_entry_write(space.data_width(), space.endianness(), bankptr)); + m_handlers[entrynum].reset(global_alloc(handler_entry_write(space.data_width(), space.endianness(), bankptr))); } // we have to allocate different object types based on the data bus width @@ -3876,8 +3867,6 @@ address_table_write::address_table_write(address_space &space, bool large) address_table_write::~address_table_write() { - for (int handnum = 0; handnum < ARRAY_LENGTH(m_handlers); handnum++) - auto_free(m_space.machine(), m_handlers[handnum]); } @@ -3993,7 +3982,7 @@ direct_read_data::direct_range *direct_read_data::find_range(offs_t byteaddress, if (range != NULL) m_freerangelist.detach(*range); else - range = auto_alloc(m_space.machine(), direct_range); + range = global_alloc(direct_range); // fill in the range m_space.read().derive_range(byteaddress, range->m_bytestart, range->m_byteend); @@ -4168,7 +4157,6 @@ memory_bank::memory_bank(address_space &space, int index, offs_t bytestart, offs memory_bank::~memory_bank() { - auto_free(machine(), m_entry); } diff --git a/src/emu/memory.h b/src/emu/memory.h index da956d4975f..5f72db81e9a 100644 --- a/src/emu/memory.h +++ b/src/emu/memory.h @@ -303,7 +303,7 @@ public: address_spacenum spacenum() const { return m_spacenum; } address_map *map() const { return m_map; } - direct_read_data &direct() const { return m_direct; } + direct_read_data &direct() const { return *m_direct; } int data_width() const { return m_config.data_width(); } int addr_width() const { return m_config.addr_width(); } @@ -377,7 +377,7 @@ public: void set_decrypted_region(offs_t addrstart, offs_t addrend, void *base); // direct access - direct_update_delegate set_direct_update_handler(direct_update_delegate function) { return m_direct.set_direct_update(function); } + direct_update_delegate set_direct_update_handler(direct_update_delegate function) { return m_direct->set_direct_update(function); } bool set_direct_region(offs_t &byteaddress); // umap ranges (short form) @@ -543,7 +543,7 @@ protected: address_space * m_next; // next address space in the global list const address_space_config &m_config; // configuration of this space device_t & m_device; // reference to the owning device - address_map * m_map; // original memory map + auto_pointer m_map; // original memory map offs_t m_addrmask; // physical address mask offs_t m_bytemask; // byte-converted physical address mask offs_t m_logaddrmask; // logical address mask @@ -552,7 +552,7 @@ protected: address_spacenum m_spacenum; // address space index bool m_debugger_access; // treat accesses as coming from the debugger bool m_log_unmap; // log unmapped accesses in this space? - direct_read_data & m_direct; // fast direct-access read info + auto_pointer m_direct; // fast direct-access read info const char * m_name; // friendly name of the address space UINT8 m_addrchars; // number of characters to use for physical addresses UINT8 m_logaddrchars; // number of characters to use for logical addresses diff --git a/src/emu/output.c b/src/emu/output.c index 363cd1180d1..05fb234b150 100644 --- a/src/emu/output.c +++ b/src/emu/output.c @@ -26,22 +26,30 @@ TYPE DEFINITIONS ***************************************************************************/ -struct output_notify +class output_notify { - output_notify * next; /* link to next item */ - output_notifier_func notifier; /* callback to call */ - void * param; /* parameter to pass the callback */ +public: + output_notify(output_notifier_func callback, void *param) + : m_next(NULL), + m_notifier(callback), + m_param(param) { } + + output_notify *next() const { return m_next; } + + output_notify * m_next; /* link to next item */ + output_notifier_func m_notifier; /* callback to call */ + void * m_param; /* parameter to pass the callback */ }; struct output_item { output_item * next; /* next item in list */ - const char * name; /* string name of the item */ + astring name; /* string name of the item */ UINT32 hash; /* hash for this item name */ UINT32 id; /* unique ID for this item */ INT32 value; /* current value */ - output_notify * notifylist; /* list of notifier callbacks */ + simple_list notifylist; /* list of notifier callbacks */ }; @@ -51,7 +59,7 @@ struct output_item ***************************************************************************/ static output_item *itemtable[HASH_SIZE]; -static output_notify *global_notifylist; +static simple_list global_notifylist; static UINT32 uniqueid = 12345; @@ -121,11 +129,10 @@ INLINE output_item *create_new_item(const char *outname, INT32 value) /* fill in the data */ item->next = itemtable[hash % HASH_SIZE]; - item->name = copy_string(outname); + item->name.cpy(outname); item->hash = hash; item->id = uniqueid++; item->value = value; - item->notifylist = NULL; /* add us to the hash table */ itemtable[hash % HASH_SIZE] = item; @@ -153,7 +160,7 @@ void output_init(running_machine &machine) /* reset the lists */ memset(itemtable, 0, sizeof(itemtable)); - global_notifylist = NULL; + global_notifylist.reset(); } @@ -178,7 +185,6 @@ static void output_resume(running_machine &machine) static void output_exit(running_machine &machine) { - output_notify *notify; output_item *item; int hash; @@ -188,28 +194,13 @@ static void output_exit(running_machine &machine) { output_item *next = item->next; - /* remove all notifiers */ - for (notify = item->notifylist; notify != NULL; ) - { - output_notify *next_notify = notify->next; - global_free(notify); - notify = next_notify; - } - /* free the name and the item */ - if (item->name != NULL) - global_free(item->name); global_free(item); item = next; } /* remove all global notifiers */ - for (notify = global_notifylist; notify != NULL; ) - { - output_notify *next = notify->next; - global_free(notify); - notify = next; - } + global_notifylist.reset(); } @@ -220,7 +211,6 @@ static void output_exit(running_machine &machine) void output_set_value(const char *outname, INT32 value) { output_item *item = find_item(outname); - output_notify *notify; INT32 oldval; /* if no item of that name, create a new one and send the item's state */ @@ -241,12 +231,12 @@ void output_set_value(const char *outname, INT32 value) if (oldval != value) { /* call the local notifiers first */ - for (notify = item->notifylist; notify != NULL; notify = notify->next) - (*notify->notifier)(outname, value, notify->param); + for (output_notify *notify = item->notifylist.first(); notify != NULL; notify = notify->next()) + (*notify->m_notifier)(outname, value, notify->m_param); /* call the global notifiers next */ - for (notify = global_notifylist; notify != NULL; notify = notify->next) - (*notify->notifier)(outname, value, notify->param); + for (output_notify *notify = global_notifylist.first(); notify != NULL; notify = notify->next()) + (*notify->m_notifier)(outname, value, notify->m_param); } } @@ -327,8 +317,6 @@ INT32 output_get_indexed_value(const char *basename, int index) void output_set_notifier(const char *outname, output_notifier_func callback, void *param) { - output_notify **headptr; - /* if an item is specified, find it */ if (outname != NULL) { @@ -337,22 +325,10 @@ void output_set_notifier(const char *outname, output_notifier_func callback, voi /* if no item of that name, create a new one */ if (item == NULL) item = create_new_item(outname, 0); - headptr = &item->notifylist; + item->notifylist.append(*global_alloc(output_notify(callback, param))); } - - /* if no item is specified, we add to the global list */ else - headptr = &global_notifylist; - - /* find the end of the list and add to it */ - while (*headptr != NULL) - headptr = &(*headptr)->next; - *headptr = global_alloc(output_notify); - - /* fill in the new record */ - (*headptr)->next = NULL; - (*headptr)->notifier = callback; - (*headptr)->param = param; + global_notifylist.append(*global_alloc(output_notify(callback, param))); } diff --git a/src/emu/render.c b/src/emu/render.c index 97bff87b72f..9bdda5219c7 100644 --- a/src/emu/render.c +++ b/src/emu/render.c @@ -381,7 +381,7 @@ void render_texture::release() for (int scalenum = 0; scalenum < ARRAY_LENGTH(m_scaled); scalenum++) { m_manager->invalidate_all(m_scaled[scalenum].bitmap); - auto_free(m_manager->machine(), m_scaled[scalenum].bitmap); + global_free(m_scaled[scalenum].bitmap); m_scaled[scalenum].bitmap = NULL; m_scaled[scalenum].seqid = 0; } @@ -422,7 +422,7 @@ void render_texture::set_bitmap(bitmap_t &bitmap, const rectangle &sbounds, text if (m_scaled[scalenum].bitmap != NULL) { m_manager->invalidate_all(m_scaled[scalenum].bitmap); - auto_free(m_manager->machine(), m_scaled[scalenum].bitmap); + global_free(m_scaled[scalenum].bitmap); } m_scaled[scalenum].bitmap = NULL; m_scaled[scalenum].seqid = 0; @@ -506,11 +506,11 @@ bool render_texture::get_scaled(UINT32 dwidth, UINT32 dheight, render_texinfo &t if (scaled->bitmap != NULL) { m_manager->invalidate_all(scaled->bitmap); - auto_free(m_manager->machine(), scaled->bitmap); + global_free(scaled->bitmap); } // allocate a new bitmap - scaled->bitmap = auto_alloc(m_manager->machine(), bitmap_argb32(dwidth, dheight)); + scaled->bitmap = global_alloc(bitmap_argb32(dwidth, dheight)); scaled->seqid = ++m_curseq; // let the scaler do the work @@ -597,12 +597,9 @@ const rgb_t *render_texture::get_adjusted_palette(render_container &container) render_container::render_container(render_manager &manager, screen_device *screen) : m_next(NULL), m_manager(manager), - m_itemlist(manager.machine().respool()), - m_item_allocator(manager.machine().respool()), m_screen(screen), m_overlaybitmap(NULL), - m_overlaytexture(NULL), - m_palclient(NULL) + m_overlaytexture(NULL) { // all palette entries are opaque by default for (int color = 0; color < ARRAY_LENGTH(m_bcglookup); color++) @@ -621,7 +618,7 @@ render_container::render_container(render_manager &manager, screen_device *scree m_user.m_gamma = manager.machine().options().gamma(); // allocate a client to the main palette if (m_screen->palette() != NULL) - m_palclient = global_alloc(palette_client(*m_screen->palette()->palette())); + m_palclient.reset(global_alloc(palette_client(*m_screen->palette()->palette()))); } recompute_lookups(); @@ -639,9 +636,6 @@ render_container::~render_container() // free the overlay texture m_manager.texture_free(m_overlaytexture); - - // release our palette client - global_free(m_palclient); } @@ -932,7 +926,6 @@ render_target::render_target(render_manager &manager, const char *layoutfile, UI : m_next(NULL), m_manager(manager), m_curview(NULL), - m_filelist(*auto_alloc(manager.machine(), simple_list(manager.machine().respool()))), m_flags(flags), m_listindex(0), m_width(640), @@ -943,8 +936,7 @@ render_target::render_target(render_manager &manager, const char *layoutfile, UI m_base_view(NULL), m_base_orientation(ROT0), m_maxtexwidth(65536), - m_maxtexheight(65536), - m_debug_containers(manager.machine().respool()) + m_maxtexheight(65536) { // determine the base layer configuration based on options m_base_layerconfig.set_backdrops_enabled(manager.machine().options().use_backdrops()); @@ -993,7 +985,6 @@ render_target::render_target(render_manager &manager, const char *layoutfile, UI render_target::~render_target() { - auto_free(m_manager.machine(), &m_filelist); } @@ -1632,7 +1623,7 @@ bool render_target::load_layout_file(const char *dirname, const char *filename) bool result = true; try { - m_filelist.append(*auto_alloc(m_manager.machine(), layout_file(m_manager.machine(), *rootnode, dirname))); + m_filelist.append(*global_alloc(layout_file(m_manager.machine(), *rootnode, dirname))); } catch (emu_fatalerror &err) { @@ -2409,12 +2400,9 @@ done: render_manager::render_manager(running_machine &machine) : m_machine(machine), - m_targetlist(machine.respool()), m_ui_target(NULL), m_live_textures(0), - m_texture_allocator(machine.respool()), - m_ui_container(auto_alloc(machine, render_container(*this))), - m_screen_container_list(machine.respool()) + m_ui_container(global_alloc(render_container(*this))) { // register callbacks config_register(machine, "video", config_saveload_delegate(FUNC(render_manager::config_load), this), config_saveload_delegate(FUNC(render_manager::config_save), this)); @@ -2483,7 +2471,7 @@ float render_manager::max_update_rate() const render_target *render_manager::target_alloc(const char *layoutfile, UINT32 flags) { - return &m_targetlist.append(*auto_alloc(machine(), render_target(*this, layoutfile, flags))); + return &m_targetlist.append(*global_alloc(render_target(*this, layoutfile, flags))); } @@ -2577,7 +2565,7 @@ void render_manager::texture_free(render_texture *texture) render_font *render_manager::font_alloc(const char *filename) { - return auto_alloc(machine(), render_font(*this, filename)); + return global_alloc(render_font(*this, filename)); } @@ -2587,7 +2575,7 @@ render_font *render_manager::font_alloc(const char *filename) void render_manager::font_free(render_font *font) { - auto_free(machine(), font); + global_free(font); } @@ -2614,7 +2602,7 @@ void render_manager::invalidate_all(void *refptr) render_container *render_manager::container_alloc(screen_device *screen) { - render_container *container = auto_alloc(machine(), render_container(*this, screen)); + render_container *container = global_alloc(render_container(*this, screen)); if (screen != NULL) m_screen_container_list.append(*container); return container; @@ -2627,8 +2615,7 @@ render_container *render_manager::container_alloc(screen_device *screen) void render_manager::container_free(render_container *container) { - m_screen_container_list.detach(*container); - auto_free(machine(), container); + m_screen_container_list.remove(*container); } diff --git a/src/emu/render.h b/src/emu/render.h index 75bea195e95..a0c24ba1868 100644 --- a/src/emu/render.h +++ b/src/emu/render.h @@ -246,15 +246,11 @@ class render_screen_list }; public: - // construction/destruction - render_screen_list(resource_pool &pool = global_resource_pool()) - : m_list(pool) { } - // getters int count() const { return m_list.count(); } // operations - void add(screen_device &screen) { m_list.append(*pool_alloc(m_list.pool(), item(screen))); } + void add(screen_device &screen) { m_list.append(*global_alloc(item(screen))); } void reset() { m_list.reset(); } // query @@ -424,6 +420,7 @@ class render_texture public: // getters int format() const { return m_format; } + render_manager *manager() const { return m_manager; } // configure the texture bitmap void set_bitmap(bitmap_t &bitmap, const rectangle &sbounds, texture_format format); @@ -578,7 +575,7 @@ private: user_settings m_user; // user settings bitmap_argb32 * m_overlaybitmap; // overlay bitmap render_texture * m_overlaytexture; // overlay texture - palette_client * m_palclient; // client to the system palette + auto_pointer m_palclient; // client to the system palette rgb_t m_bcglookup256[0x400]; // lookup table for brightness/contrast/gamma rgb_t m_bcglookup[0x10000]; // full palette lookup with bcg adjustements }; @@ -694,7 +691,7 @@ private: render_target * m_next; // link to next target render_manager & m_manager; // reference to our owning manager layout_view * m_curview; // current view - simple_list &m_filelist; // list of layout files + simple_list m_filelist; // list of layout files UINT32 m_flags; // creation flags render_primitive_list m_primlist[NUM_PRIMLISTS]; // list of primitives int m_listindex; // index of next primlist to use diff --git a/src/emu/rendfont.c b/src/emu/rendfont.c index 217cff6276e..f6de9822243 100644 --- a/src/emu/rendfont.c +++ b/src/emu/rendfont.c @@ -53,9 +53,7 @@ inline render_font::glyph &render_font::get_char(unicode_char chnum) // grab the table; if none, return the dummy character if (m_glyphs[chnum / 256].count() == 0 && m_format == FF_OSD) - { m_glyphs[chnum / 256].resize(256); - } if (m_glyphs[chnum / 256].count() == 0) return dummy_glyph; @@ -123,19 +121,12 @@ render_font::~render_font() { // free all the subtables for (int tablenum = 0; tablenum < 256; tablenum++) - if (m_glyphs[tablenum] != NULL) + for (int charnum = 0; charnum < m_glyphs[tablenum].count(); charnum++) { - // loop over characters - for (int charnum = 0; charnum < 256; charnum++) - { - glyph &gl = m_glyphs[tablenum][charnum]; - m_manager.texture_free(gl.texture); - } + glyph &gl = m_glyphs[tablenum][charnum]; + m_manager.texture_free(gl.texture); } - // free the raw data and the size itself - auto_free(m_manager.machine(), m_rawdata); - // release the OSD font if (m_osdfont != NULL) m_manager.machine().osd().font_close(m_osdfont); @@ -534,7 +525,7 @@ bool render_font::load_bdf() } // make sure all the numbers are the same width - if (m_glyphs[0] != NULL) + if (m_glyphs[0].count() > '9') { int maxwidth = 0; for (int ch = '0'; ch <= '9'; ch++) diff --git a/src/emu/rendlay.c b/src/emu/rendlay.c index 9ea4446c8d1..d28322479d2 100644 --- a/src/emu/rendlay.c +++ b/src/emu/rendlay.c @@ -402,7 +402,6 @@ static void parse_orientation(running_machine &machine, xml_data_node *orientnod layout_element::layout_element(running_machine &machine, xml_data_node &elemnode, const char *dirname) : m_next(NULL), m_machine(machine), - m_complist(machine.respool()), m_defstate(0), m_maxstate(0) { @@ -421,7 +420,7 @@ layout_element::layout_element(running_machine &machine, xml_data_node &elemnode for (xml_data_node *compnode = elemnode.child; compnode != NULL; compnode = compnode->next) { // allocate a new component - component &newcomp = m_complist.append(*auto_alloc(machine, component(machine, *compnode, dirname))); + component &newcomp = m_complist.append(*global_alloc(component(machine, *compnode, dirname))); // accumulate bounds if (first) @@ -571,10 +570,7 @@ layout_element::component::component(running_machine &machine, xml_data_node &co m_state(0) { for (int i=0;i &elemlist) : m_next(NULL), m_aspect(1.0f), - m_scraspect(1.0f), - m_screens(machine.respool()), - m_backdrop_list(machine.respool()), - m_screen_list(machine.respool()), - m_overlay_list(machine.respool()), - m_bezel_list(machine.respool()), - m_cpanel_list(machine.respool()), - m_marquee_list(machine.respool()) + m_scraspect(1.0f) { // allocate a copy of the name m_name = xml_get_attribute_string_with_subst(machine, viewnode, "name", ""); @@ -1934,27 +1918,27 @@ layout_view::layout_view(running_machine &machine, xml_data_node &viewnode, simp // load backdrop items for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "backdrop"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "backdrop")) - m_backdrop_list.append(*auto_alloc(machine, item(machine, *itemnode, elemlist))); + m_backdrop_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load screen items for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "screen"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "screen")) - m_screen_list.append(*auto_alloc(machine, item(machine, *itemnode, elemlist))); + m_screen_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load overlay items for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "overlay"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "overlay")) - m_overlay_list.append(*auto_alloc(machine, item(machine, *itemnode, elemlist))); + m_overlay_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load bezel items for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "bezel"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "bezel")) - m_bezel_list.append(*auto_alloc(machine, item(machine, *itemnode, elemlist))); + m_bezel_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load cpanel items for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "cpanel"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "cpanel")) - m_cpanel_list.append(*auto_alloc(machine, item(machine, *itemnode, elemlist))); + m_cpanel_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load marquee items for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "marquee"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "marquee")) - m_marquee_list.append(*auto_alloc(machine, item(machine, *itemnode, elemlist))); + m_marquee_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // recompute the data for the view based on a default layer config recompute(render_layer_config()); @@ -2201,9 +2185,7 @@ int layout_view::item::state() const //------------------------------------------------- layout_file::layout_file(running_machine &machine, xml_data_node &rootnode, const char *dirname) - : m_next(NULL), - m_elemlist(machine.respool()), - m_viewlist(machine.respool()) + : m_next(NULL) { // find the layout node xml_data_node *mamelayoutnode = xml_get_sibling(rootnode.child, "mamelayout"); @@ -2217,11 +2199,11 @@ layout_file::layout_file(running_machine &machine, xml_data_node &rootnode, cons // parse all the elements for (xml_data_node *elemnode = xml_get_sibling(mamelayoutnode->child, "element"); elemnode != NULL; elemnode = xml_get_sibling(elemnode->next, "element")) - m_elemlist.append(*auto_alloc(machine, layout_element(machine, *elemnode, dirname))); + m_elemlist.append(*global_alloc(layout_element(machine, *elemnode, dirname))); // parse all the views for (xml_data_node *viewnode = xml_get_sibling(mamelayoutnode->child, "view"); viewnode != NULL; viewnode = xml_get_sibling(viewnode->next, "view")) - m_viewlist.append(*auto_alloc(machine, layout_view(machine, *viewnode, m_elemlist))); + m_viewlist.append(*global_alloc(layout_view(machine, *viewnode, m_elemlist))); } diff --git a/src/emu/rendlay.h b/src/emu/rendlay.h index dc46a171542..1de79ef17b9 100644 --- a/src/emu/rendlay.h +++ b/src/emu/rendlay.h @@ -136,7 +136,7 @@ private: int m_textalign; // text alignment to box bitmap_argb32 m_bitmap[MAX_BITMAPS]; // source bitmap for images astring m_dirname; // directory name of image file (for lazy loading) - emu_file * m_file[MAX_BITMAPS]; // file object for reading image/alpha files + auto_pointer m_file[MAX_BITMAPS]; // file object for reading image/alpha files astring m_imagefile[MAX_BITMAPS]; // name of the image file (for lazy loading) astring m_alphafile[MAX_BITMAPS]; // name of the alpha file (for lazy loading) bool m_hasalpha[MAX_BITMAPS]; // is there any alpha component present? diff --git a/src/emu/romload.c b/src/emu/romload.c index 38485b74b03..e8272d9963c 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -750,10 +750,7 @@ static int read_rom_data(romload_private *romdata, const rom_entry *parent_regio /* read as much as we can */ LOG((" Reading %X bytes into buffer\n", bytesleft)); if (rom_fread(romdata, bufptr, bytesleft, parent_region) != bytesleft) - { - auto_free(romdata->machine(), tempbuf); return 0; - } numbytes -= bytesleft; LOG((" Copying to %p\n", base)); @@ -1281,44 +1278,13 @@ static void normalize_flags_for_device(running_machine &machine, const char *rgn more general process_region_list. -------------------------------------------------*/ -void load_software_part_region(device_t *device, char *swlist, char *swname, rom_entry *start_region) +void load_software_part_region(device_t &device, software_list_device &swlist, const char *swname, const rom_entry *start_region) { - astring locationtag(swlist), breakstr("%"); - romload_private *romdata = device->machine().romload_data; + astring locationtag(swlist.list_name()), breakstr("%"); + romload_private *romdata = device.machine().romload_data; const rom_entry *region; astring regiontag; - // attempt reading up the chain through the parents and create a locationtag astring in the format - // " swlist % clonename % parentname " - // open_rom_file contains the code to split the elements and to create paths to load from - - software_list *software_list_ptr = software_list_open(device->machine().options(), swlist, FALSE, NULL); - if (software_list_ptr) - { - locationtag.cat(breakstr); - - for (software_info *swinfo = software_list_find(software_list_ptr, swname, NULL); swinfo != NULL; ) - { - { - astring tmp(swinfo->shortname); - locationtag.cat(tmp); - locationtag.cat(breakstr); - // printf("%s\n", locationtag.cstr()); - } - const char *parentname = software_get_clone(device->machine().options(), swlist, swinfo->shortname); - if (parentname != NULL) - swinfo = software_list_find(software_list_ptr, parentname, NULL); - else - swinfo = NULL; - } - // strip the final '%' - locationtag.del(locationtag.len() - 1, 1); - software_list_close(software_list_ptr); - } - - /* Make sure we are passed a device */ - assert(device != NULL); - romdata->errorstring.reset(); romdata->softwarningstring.reset(); @@ -1326,23 +1292,44 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom romdata->romstotalsize = 0; romdata->romsloadedsize = 0; - if (software_get_support(device->machine().options(), swlist, swname) == SOFTWARE_SUPPORTED_PARTIAL) + software_info *swinfo = swlist.find(swname); + if (swinfo != NULL) { - romdata->errorstring.catprintf("WARNING: support for software %s (in list %s) is only partial\n", swname, swlist); - romdata->softwarningstring.catprintf("Support for software %s (in list %s) is only partial\n", swname, swlist); - } - if (software_get_support(device->machine().options(), swlist, swname) == SOFTWARE_SUPPORTED_NO) - { - romdata->errorstring.catprintf("WARNING: support for software %s (in list %s) is only preliminary\n", swname, swlist); - romdata->softwarningstring.catprintf("Support for software %s (in list %s) is only preliminary\n", swname, swlist); + UINT32 supported = swinfo->supported(); + if (supported == SOFTWARE_SUPPORTED_PARTIAL) + { + romdata->errorstring.catprintf("WARNING: support for software %s (in list %s) is only partial\n", swname, swlist.list_name()); + romdata->softwarningstring.catprintf("Support for software %s (in list %s) is only partial\n", swname, swlist.list_name()); + } + if (supported == SOFTWARE_SUPPORTED_NO) + { + romdata->errorstring.catprintf("WARNING: support for software %s (in list %s) is only preliminary\n", swname, swlist.list_name()); + romdata->softwarningstring.catprintf("Support for software %s (in list %s) is only preliminary\n", swname, swlist.list_name()); + } + + // attempt reading up the chain through the parents and create a locationtag astring in the format + // " swlist % clonename % parentname " + // open_rom_file contains the code to split the elements and to create paths to load from + + locationtag.cat(breakstr); + + while (swinfo != NULL) + { + locationtag.cat(swinfo->shortname()).cat(breakstr); + const char *parentname = swinfo->parentname(); + swinfo = (parentname != NULL) ? swlist.find(parentname) : NULL; + } + // strip the final '%' + locationtag.del(locationtag.len() - 1, 1); } + /* loop until we hit the end */ for (region = start_region; region != NULL; region = rom_next_region(region)) { UINT32 regionlength = ROMREGION_GETLENGTH(region); - device->subtag(regiontag, ROMREGION_GETTAG(region)); + device.subtag(regiontag, ROMREGION_GETTAG(region)); LOG(("Processing region \"%s\" (length=%X)\n", regiontag.cstr(), regionlength)); /* the first entry must be a region */ @@ -1388,7 +1375,7 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom /* now process the entries in the region */ if (ROMREGION_ISROMDATA(region)) - process_rom_entries(romdata, locationtag, region, region + 1, device, TRUE); + process_rom_entries(romdata, locationtag, region, region + 1, &device, TRUE); else if (ROMREGION_ISDISKDATA(region)) process_disk_entries(romdata, core_strdup(regiontag.cstr()), region, region + 1, locationtag); } @@ -1396,7 +1383,7 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom /* now go back and post-process all the regions */ for (region = start_region; region != NULL; region = rom_next_region(region)) { - device->subtag(regiontag, ROMREGION_GETTAG(region)); + device.subtag(regiontag, ROMREGION_GETTAG(region)); region_post_process(romdata, regiontag.cstr(), ROMREGION_ISINVERTED(region)); } diff --git a/src/emu/romload.h b/src/emu/romload.h index 19734ea3e28..dbf8f1bce32 100644 --- a/src/emu/romload.h +++ b/src/emu/romload.h @@ -122,7 +122,7 @@ enum class machine_config; class emu_options; class chd_file; - +class software_list_device; struct rom_entry { @@ -307,6 +307,6 @@ chd_file *get_disk_handle(running_machine &machine, const char *region); /* set a pointer to the CHD file associated with the given region */ int set_disk_handle(running_machine &machine, const char *region, const char *fullpath); -void load_software_part_region(device_t *device, char *swlist, char *swname, rom_entry *start_region); +void load_software_part_region(device_t &device, software_list_device &swlist, const char *swname, const rom_entry *start_region); #endif /* __ROMLOAD_H__ */ diff --git a/src/emu/save.c b/src/emu/save.c index b087607d603..d7d8ba57ab5 100644 --- a/src/emu/save.c +++ b/src/emu/save.c @@ -62,10 +62,7 @@ enum save_manager::save_manager(running_machine &machine) : m_machine(machine), m_reg_allowed(true), - m_illegal_regs(0), - m_entry_list(machine.respool()), - m_presave_list(machine.respool()), - m_postload_list(machine.respool()) + m_illegal_regs(0) { } @@ -120,7 +117,7 @@ void save_manager::register_presave(save_prepost_delegate func) fatalerror("Duplicate save state function (%s/%s)\n", cb->m_func.name(), func.name()); // allocate a new entry - m_presave_list.append(*auto_alloc(machine(), state_callback(func))); + m_presave_list.append(*global_alloc(state_callback(func))); } @@ -141,7 +138,7 @@ void save_manager::register_postload(save_prepost_delegate func) fatalerror("Duplicate save state function (%s/%s)\n", cb->m_func.name(), func.name()); // allocate a new entry - m_postload_list.append(*auto_alloc(machine(), state_callback(func))); + m_postload_list.append(*global_alloc(state_callback(func))); } @@ -186,7 +183,7 @@ void save_manager::save_memory(const char *module, const char *tag, UINT32 index } // insert us into the list - m_entry_list.insert_after(*auto_alloc(machine(), state_entry(val, totalname, valsize, valcount)), insert_after); + m_entry_list.insert_after(*global_alloc(state_entry(val, totalname, valsize, valcount)), insert_after); } diff --git a/src/emu/schedule.c b/src/emu/schedule.c index 7e4a817b686..f135821d201 100644 --- a/src/emu/schedule.c +++ b/src/emu/schedule.c @@ -315,13 +315,10 @@ device_scheduler::device_scheduler(running_machine &machine) : m_execute_list(NULL), m_basetime(attotime::zero), m_timer_list(NULL), - m_timer_allocator(machine.respool()), m_callback_timer(NULL), m_callback_timer_modified(false), m_callback_timer_expire_time(attotime::zero), m_suspend_changes_pending(true), - m_quantum_list(machine.respool()), - m_quantum_allocator(machine.respool()), m_quantum_minimum(ATTOSECONDS_IN_NSEC(1) / 1000) { // append a single never-expiring timer so there is always one in the list diff --git a/src/emu/softlist.c b/src/emu/softlist.c index 1deb49e85b2..d997dd2c600 100644 --- a/src/emu/softlist.c +++ b/src/emu/softlist.c @@ -4,7 +4,6 @@ Software list construction helpers. - ***************************************************************************/ #include "emu.h" @@ -12,30 +11,356 @@ #include "emuopts.h" #include "softlist.h" #include "clifront.h" +#include "validity.h" #include + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + typedef tagmap_t softlist_map; -//************************************************************************** -// LIVE DEVICE -//************************************************************************** +// ======================> softlist_parser -tagmap_t software_list_device::s_checked_lists; +class softlist_parser +{ +public: + // construction (== execution) + softlist_parser(software_list_device &list, astring &errors); + +private: + enum parse_position + { + POS_ROOT, + POS_MAIN, + POS_SOFT, + POS_PART, + POS_DATA + }; + + // internal parsing helpers + const char *filename() const { return m_list.filename(); } + const char *infoname() const { return (m_current_info != NULL) ? m_current_info->shortname() : "???"; } + int line() const { return XML_GetCurrentLineNumber(m_parser); } + int column() const { return XML_GetCurrentColumnNumber(m_parser); } + const char *parser_error() const { return XML_ErrorString(XML_GetErrorCode(m_parser)); } + + // internal error helpers + void ATTR_PRINTF(2,3) parse_error(const char *fmt, ...); + void unknown_tag(const char *tagname) { parse_error("Unknown tag: %s", tagname); } + void unknown_attribute(const char *attrname) { parse_error("Unknown attribute: %s", attrname); } + + // internal helpers + void parse_attributes(const char **attributes, int numattrs, const char *attrlist[], const char *outlist[]); + void add_rom_entry(const char *name, const char *hashdata, UINT32 offset, UINT32 length, UINT32 flags); + + // expat callbacks + static void *expat_malloc(size_t size); + static void *expat_realloc(void *ptr, size_t size); + static void expat_free(void *ptr); + static void start_handler(void *data, const char *tagname, const char **attributes); + static void data_handler(void *data, const XML_Char *s, int len); + static void end_handler(void *data, const char *name); + + // internal parsing + void parse_root_start(const char *tagname, const char **attributes); + void parse_main_start(const char *tagname, const char **attributes); + void parse_soft_start(const char *tagname, const char **attributes); + void parse_part_start(const char *tagname, const char **attributes); + void parse_data_start(const char *tagname, const char **attributes); + void parse_soft_end(const char *name); + + // internal parsing state + software_list_device & m_list; + astring & m_errors; + XML_Parser m_parser; + bool m_done; + bool m_data_accum_expected; + astring m_data_accum; + software_info * m_current_info; + software_part * m_current_part; + parse_position m_pos; +}; + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** // device type definition const device_type SOFTWARE_LIST = &device_creator; + + +//************************************************************************** +// SOFTWARE PART +//************************************************************************** + +//------------------------------------------------- +// software_part - constructor +//------------------------------------------------- + +software_part::software_part(software_info &info, const char *name, const char *interface) + : m_next(NULL), + m_info(info), + m_name(name), + m_interface(interface) +{ + // ensure strings we are passed are in the string pool + assert(info.list().string_pool_contains(name)); + assert(info.list().string_pool_contains(interface)); +} + + +//------------------------------------------------- +// feature - return the value of the given +// feature, if specified +//------------------------------------------------- + +const char *software_part::feature(const char *feature_name) const +{ + assert(feature_name != NULL); + + // scan the feature list for an entry matching feature_name and return the value + for (const feature_list_item *feature = m_featurelist.first(); feature != NULL; feature = feature->next()) + if (strcmp(feature->name(), feature_name) == 0) + return feature->value(); + return NULL; + +} + + +//------------------------------------------------- +// is_compatible - determine if we are compatible +// with the given software_list_device +//------------------------------------------------- + +bool software_part::is_compatible(const software_list_device &swlistdev) const +{ + // get the compatibility feature and the softlist filter; if either is NULL, assume compatible + const char *compatibility = feature("compatibility"); + const char *filter = swlistdev.filter(); + if (compatibility == NULL || filter == NULL) + return true; + + // copy the comma-delimited strings and ensure they end with a final comma + astring comp(compatibility, ","); + astring filt(filter, ","); + + // iterate over filter items and see if they exist in the compatibility list; if so, return true + for (int start = 0, end = filt.chr(start, ','); end != -1; start = end + 1, end = filt.chr(start, ',')) + { + astring token(filt, start, end - start + 1); + if (comp.find(0, token) != -1) + return true; + } + return false; +} + + +//------------------------------------------------- +// matches_interface - determine if we match +// an interface in the provided list +//------------------------------------------------- + +bool software_part::matches_interface(const char *interface_list) const +{ + // if we have no interface, then we match by default + if (m_interface == NULL) + return true; + + // copy the comma-delimited interface list and ensure it ends with a final comma + astring interfaces(interface_list, ","); + + // then add a comma to the end of our interface and return true if we find it in the list string + astring our_interface(m_interface, ","); + return (interfaces.find(0, our_interface) != -1); +} + + + +//************************************************************************** +// SOFTWARE INFO +//************************************************************************** + +//------------------------------------------------- +// software_info - constructor +//------------------------------------------------- + +software_info::software_info(software_list_device &list, const char *name, const char *parent, const char *supported) + : m_next(NULL), + m_list(list), + m_supported(SOFTWARE_SUPPORTED_YES), + m_shortname(name), + m_parentname(parent) +{ + // ensure strings we are passed are in the string pool + assert(list.string_pool_contains(name)); + assert(list.string_pool_contains(parent)); + + // handle the supported flag if provided + if (supported != NULL) + { + if (strcmp(supported, "partial") == 0) + m_supported = SOFTWARE_SUPPORTED_PARTIAL; + else if (strcmp(supported, "no") == 0) + m_supported = SOFTWARE_SUPPORTED_NO; + } +} + + +//------------------------------------------------- +// find_part - find a part by name with an +// optional interface match +//------------------------------------------------- + +software_part *software_info::find_part(const char *partname, const char *interface) +{ + // if neither partname nor interface supplied, then we just return the first entry + if (partname == NULL && interface == NULL) + return m_partdata.first(); + + // look for the part by name and match against the interface if provided + for (software_part *part = m_partdata.first(); part != NULL; part = part->next()) + if (partname != NULL && strcmp(partname, part->name()) == 0) + if (interface == NULL || part->matches_interface(interface)) + return part; + + return NULL; +} + + +//------------------------------------------------- +// has_multiple_parts - return true if we have +// more than one part matching the given +// interface +//------------------------------------------------- + +bool software_info::has_multiple_parts(const char *interface) const +{ + int count = 0; + + // increment the count for each match and stop if we hit more than 1 + for (software_part *part = first_part(); part != NULL; part = part->next()) + if (part->matches_interface(interface)) + if (++count > 1) + return true; + + return false; +} + + + +//************************************************************************** +// CONST STRING POOL +//************************************************************************** + +//------------------------------------------------- +// const_string_pool - constructor +//------------------------------------------------- + +const_string_pool::const_string_pool() +{ +} + + +//------------------------------------------------- +// add - add a string to the string pool +//------------------------------------------------- + +const char *const_string_pool::add(const char *string) +{ + // if NULL or a small number (for some hash strings), just return as-is + if (FPTR(string) < 0x100) + return string; + + // scan to find space + for (pool_chunk *chunk = m_chunklist.first(); chunk != NULL; chunk = chunk->next()) + { + const char *result = chunk->add(string); + if (result != NULL) + return result; + } + + // no space anywhere, create a new pool and prepend it (so it gets used first) + const char *result = m_chunklist.prepend(*global_alloc(pool_chunk)).add(string); + assert(result != NULL); + return result; +} + + +//------------------------------------------------- +// contains - determine if the given string +// pointer lives in the pool +//------------------------------------------------- + +bool const_string_pool::contains(const char *string) +{ + // if NULL or a small number (for some hash strings), then yes, effectively + if (FPTR(string) < 0x100) + return true; + + // scan to find it + for (pool_chunk *chunk = m_chunklist.first(); chunk != NULL; chunk = chunk->next()) + if (chunk->contains(string)) + return true; + + return false; +} + + +//------------------------------------------------- +// pool_chunk - constructor +//------------------------------------------------- + +const_string_pool::pool_chunk::pool_chunk() + : m_next(NULL), + m_used(0) +{ +} + + +//------------------------------------------------- +// add - add a string to this pool +//------------------------------------------------- + +const char *const_string_pool::pool_chunk::add(const char *string) +{ + // get the length of the string (no string can be longer than a full pool) + int bytes = strlen(string) + 1; + assert(bytes < POOL_SIZE); + + // if too big, return NULL + if (m_used + bytes > POOL_SIZE) + return NULL; + + // allocate, copy, and return the memory + char *dest = &m_buffer[m_used]; + m_used += bytes; + memcpy(dest, string, bytes); + return dest; +} + + + +//************************************************************************** +// SOFTWARE LIST DEVICE +//************************************************************************** + //------------------------------------------------- // software_list_device - constructor //------------------------------------------------- software_list_device::software_list_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, SOFTWARE_LIST, "Software list", tag, owner, clock, "software_list", __FILE__), - m_list_name(NULL), m_list_type(SOFTWARE_LIST_ORIGINAL_SYSTEM), - m_filter(NULL) + m_filter(NULL), + m_parsed(false), + m_file(mconfig.options().hash_path(), OPEN_FLAG_READ) { } @@ -47,9 +372,9 @@ software_list_device::software_list_device(const machine_config &mconfig, const void software_list_device::static_set_config(device_t &device, const char *list, softlist_type list_type) { - software_list_device &softlist = downcast(device); - softlist.m_list_name = list; - softlist.m_list_type = list_type; + software_list_device &swlistdev = downcast(device); + swlistdev.m_list_name.cpy(list); + swlistdev.m_list_type = list_type; } @@ -73,2093 +398,910 @@ void software_list_device::device_start() } +//------------------------------------------------- +// find_approx_matches - search ourselves for +// a list of possible matches of the given name +// and optional interface +//------------------------------------------------- -/*************************************************************************** - EXPAT INTERFACES -***************************************************************************/ - -/*------------------------------------------------- - expat_malloc/expat_realloc/expat_free - - wrappers for memory allocation functions so - that they pass through out memory tracking - systems --------------------------------------------------*/ - -static void *expat_malloc(size_t size) +void software_list_device::find_approx_matches(const char *name, int matches, software_info **list, const char *interface) { - return global_alloc_array_clear(UINT8,size); -} - -static void *expat_realloc(void *ptr, size_t size) -{ - if (ptr) global_free(ptr); - return global_alloc_array_clear(UINT8,size); -} - -static void expat_free(void *ptr) -{ - global_free(ptr); -} - - -/*------------------------------------------------- - parse_error --------------------------------------------------*/ - -INLINE void ATTR_PRINTF(2,3) parse_error(parse_state *state, const char *fmt, ...) -{ - char buf[256]; - va_list va; - - if (state->error_proc) - { - va_start(va, fmt); - vsnprintf(buf, ARRAY_LENGTH(buf), fmt, va); - va_end(va); - (*state->error_proc)(buf); - } -} - - -/*------------------------------------------------- - unknown_tag --------------------------------------------------*/ - -INLINE void unknown_tag(software_list *swlist, const char *tagname) -{ - parse_error(&swlist->state, "%s: Unknown tag: %s (line %lu column %lu)\n", - swlist->file->filename(), - tagname, - XML_GetCurrentLineNumber(swlist->state.parser), - XML_GetCurrentColumnNumber(swlist->state.parser)); -} - - - -/*------------------------------------------------- - unknown_attribute --------------------------------------------------*/ - -INLINE void unknown_attribute(software_list *swlist, const char *attrname) -{ - parse_error(&swlist->state, "%s: Unknown attribute: %s (line %lu column %lu)\n", - swlist->file->filename(), - attrname, - XML_GetCurrentLineNumber(swlist->state.parser), - XML_GetCurrentColumnNumber(swlist->state.parser)); -} - - - -#if 0 -/*------------------------------------------------- - unknown_attribute_value --------------------------------------------------*/ - -INLINE void unknown_attribute_value(software_list *swlist, - const char *attrname, const char *attrvalue) -{ - parse_error(&swlist->state, "%s: Unknown attribute value: %s (line %lu column %lu)\n", - swlist->file->filename(), - attrvalue, - XML_GetCurrentLineNumber(swlist->state.parser), - XML_GetCurrentColumnNumber(swlist->state.parser)); -} -#endif - - -/*------------------------------------------------- - software_name_split - helper; splits a software_list:software:part - string into separate software_list, software, - and part strings. - - str1:str2:str3 => swlist_name - str1, swname - str2, swpart - str3 - str1:str2 => swlist_name - NULL, swname - str1, swpart - str2 - str1 => swlist_name - NULL, swname - str1, swpart - NULL - - swlist_namem, swnane and swpart will be global_alloc'ed - from the global pool. So they should be global_free'ed - when they are not used anymore. --------------------------------------------------*/ - -#define global_strdup(s) strcpy(global_alloc_array(char, strlen(s) + 1), s) - -void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart ) -{ - const char *split_1st_loc = strchr( swlist_swname, ':' ); - const char *split_2nd_loc = ( split_1st_loc ) ? strchr( split_1st_loc + 1, ':' ) : NULL; - - *swlist_name = NULL; - *swname = NULL; - *swpart = NULL; - - if ( split_1st_loc ) - { - if ( split_2nd_loc ) - { - int size = split_1st_loc - swlist_swname; - *swlist_name = global_alloc_array_clear(char,size+1); - memcpy( *swlist_name, swlist_swname, size ); - - size = split_2nd_loc - ( split_1st_loc + 1 ); - *swname = global_alloc_array_clear(char,size+1); - memcpy( *swname, split_1st_loc + 1, size ); - - size = strlen( swlist_swname ) - ( split_2nd_loc + 1 - swlist_swname ); - *swpart = global_alloc_array_clear(char,size+1); - memcpy( *swpart, split_2nd_loc + 1, size ); - } - else - { - int size = split_1st_loc - swlist_swname; - *swname = global_alloc_array_clear(char,size+1); - memcpy( *swname, swlist_swname, size ); - - size = strlen( swlist_swname ) - ( split_1st_loc + 1 - swlist_swname ); - *swpart = global_alloc_array_clear(char,size+1); - memcpy( *swpart, split_1st_loc + 1, size ); - } - } - else - { - *swname = global_strdup(swlist_swname); - } -} - - -/*------------------------------------------------- - add_rom_entry --------------------------------------------------*/ - -static void add_rom_entry(software_list *swlist, const char *name, const char *hashdata, UINT32 offset, UINT32 length, UINT32 flags) -{ - software_part *part = &swlist->softinfo->partdata[swlist->softinfo->current_part_entry-1]; - if ((flags & ROMENTRY_TYPEMASK) == ROMENTRYTYPE_REGION && name!=NULL && part!=NULL) { - if (swlist->current_rom_entry>0) { - for (int i=0;icurrent_rom_entry;i++) { - if ((part->romdata[i]._name != NULL) && (strcmp(part->romdata[i]._name,name)==0)) { - parse_error(&swlist->state, "%s: Duplicated dataarea %s in %s\n",swlist->file->filename(),name,swlist->current_software_info->shortname); - } - } - } - } - - if ( part->romdata == NULL ) - { - /* Allocate initial space to hold the rom information */ - swlist->rom_entries = 3; - part->romdata = (struct rom_entry *)pool_malloc_lib(swlist->pool, swlist->rom_entries * sizeof(struct rom_entry)); - if ( part->romdata == NULL ) - { - fatalerror("Unable to claim memory for storing a rom entry\n"); - } - } - - struct rom_entry *entry = &part->romdata[swlist->current_rom_entry]; - - entry->_name = name; - entry->_hashdata = hashdata; - entry->_offset = offset; - entry->_length = length; - entry->_flags = flags; - - swlist->current_rom_entry += 1; - - if ( swlist->current_rom_entry >= swlist->rom_entries ) - { - struct rom_entry *new_entries; - - swlist->rom_entries += 10; - new_entries = (struct rom_entry *)pool_realloc_lib(swlist->pool, part->romdata, swlist->rom_entries * sizeof(struct rom_entry) ); - - if ( new_entries ) - { - part->romdata = new_entries; - } - else - { - /* Allocation error */ - swlist->current_rom_entry -= 1; - } - } -} - -/*------------------------------------------------- - add_feature --------------------------------------------------*/ - -static void add_feature(software_list *swlist, char *feature_name, char *feature_value) -{ - software_part *part = &swlist->softinfo->partdata[swlist->softinfo->current_part_entry-1]; - feature_list *new_entry; - - /* First allocate the new entry */ - new_entry = (feature_list *)pool_malloc_lib(swlist->pool, sizeof(feature_list) ); - - if ( new_entry ) - { - new_entry->next = NULL; - new_entry->name = feature_name; - new_entry->value = feature_value ? feature_value : feature_name; - - /* Add new feature to end of feature list */ - if ( part->featurelist ) - { - feature_list *list = part->featurelist; - while ( list->next != NULL ) - { - list = list->next; - } - list->next = new_entry; - } - else - { - part->featurelist = new_entry; - } - } - else - { - /* Unable to allocate memory */ - } -} - -/*------------------------------------------------- - add_info (same as add_feature, but its target - is softinfo->shared_info) - -------------------------------------------------*/ - -static void add_info(software_list *swlist, char *feature_name, char *feature_value) -{ - software_info *info = swlist->softinfo; - feature_list *new_entry; - - /* First allocate the new entry */ - new_entry = (feature_list *)pool_malloc_lib(swlist->pool, sizeof(feature_list) ); - - if ( new_entry ) - { - new_entry->next = NULL; - new_entry->name = feature_name; - new_entry->value = feature_value ? feature_value : feature_name; - - /* Add new feature to end of feature list */ - if ( info->shared_info ) - { - feature_list *list = info->shared_info; - while ( list->next != NULL ) - { - list = list->next; - } - list->next = new_entry; - } - else - { - info->shared_info = new_entry; - } - } - else - { - /* Unable to allocate memory */ - } -} - -/*------------------------------------------------- - add_other_info (same as add_info, but its target - is softinfo->other_info) - -------------------------------------------------*/ - -static void add_other_info(software_list *swlist, char *info_name, char *info_value) -{ - software_info *info = swlist->softinfo; - feature_list *new_entry; - - /* First allocate the new entry */ - new_entry = (feature_list *)pool_malloc_lib(swlist->pool, sizeof(feature_list) ); - - if ( new_entry ) - { - new_entry->next = NULL; - new_entry->name = info_name; - new_entry->value = info_value ? info_value : info_name; - - /* Add new feature to end of feature list */ - if ( info->other_info ) - { - feature_list *list = info->other_info; - while ( list->next != NULL ) - { - list = list->next; - } - list->next = new_entry; - } - else - { - info->other_info = new_entry; - } - } - else - { - /* Unable to allocate memory */ - } -} - -/*------------------------------------------------- - add_software_part --------------------------------------------------*/ - -static void add_software_part(software_list *swlist, const char *name, const char *interface) -{ - software_part *part = &swlist->softinfo->partdata[swlist->softinfo->current_part_entry]; - - part->name = name; - part->interface_ = interface; - part->featurelist = NULL; - part->romdata = NULL; - - swlist->softinfo->current_part_entry += 1; - - if ( swlist->softinfo->current_part_entry >= swlist->softinfo->part_entries ) - { - software_part *new_parts; - - swlist->softinfo->part_entries += 2; - new_parts = (software_part *)pool_realloc_lib(swlist->pool, swlist->softinfo->partdata, swlist->softinfo->part_entries * sizeof(software_part) ); - - if ( new_parts ) - { - swlist->softinfo->partdata = new_parts; - } - else - { - /* Allocation error */ - swlist->softinfo->current_part_entry -= 1; - } - } -} - - -/*------------------------------------------------- - start_handler --------------------------------------------------*/ - -static void start_handler(void *data, const char *tagname, const char **attributes) -{ - software_list *swlist = (software_list *) data; - char **text_dest; - - switch(swlist->state.pos) - { - case POS_ROOT: - if (!strcmp(tagname, "softwarelist")) - { - for( ; attributes[0]; attributes += 2 ) - { - if ( ! strcmp(attributes[0], "name" ) ) - { - } - else if ( ! strcmp(attributes[0], "description" ) ) - { - swlist->description = (const char *)pool_malloc_lib(swlist->pool, (strlen(attributes[1]) + 1) * sizeof(char)); - if (!swlist->description) - return; - - strcpy((char *)swlist->description, attributes[1]); - } else - unknown_attribute(swlist, attributes[0]); - } - } - else - { - unknown_tag(swlist, tagname); - } - break; - - case POS_MAIN: - if ( !strcmp( tagname, "software" ) ) - { - const char *name = NULL; - const char *parent = NULL; - const char *supported = NULL; - - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - { - name = attributes[1]; - } - else if ( !strcmp( attributes[0], "cloneof" ) ) - { - parent = attributes[1]; - } - else if ( !strcmp( attributes[0], "supported" ) ) - { - supported = attributes[1]; - } - else - unknown_attribute(swlist, attributes[0]); - } - - if ( name ) - { - struct software_info *elem = (struct software_info *)pool_malloc_lib(swlist->pool,sizeof(struct software_info)); - - if ( !elem ) - return; - - /* Clear element and add element to list */ - memset(elem,0,sizeof(struct software_info)); - - /* Allocate space to hold the shortname and copy the short name */ - elem->shortname = (const char*)pool_malloc_lib(swlist->pool, ( strlen( name ) + 1 ) * sizeof(char) ); - - if ( ! elem->shortname ) - return; - - strcpy( (char *)elem->shortname, name ); - - /* Allocate space to hold the parentname and copy the parent name */ - if (parent) - { - elem->parentname = (const char*)pool_malloc_lib(swlist->pool, ( strlen(parent) + 1 ) * sizeof(char) ); - strcpy((char *)elem->parentname, parent); - } - - /* Allocate initial space to hold part information */ - elem->part_entries = 2; - elem->current_part_entry = 0; - elem->partdata = (software_part *)pool_malloc_lib(swlist->pool, elem->part_entries * sizeof(software_part) ); - if ( !elem->partdata ) - return; - elem->shared_info = (feature_list *)pool_malloc_lib(swlist->pool, sizeof(feature_list) ); - if ( !elem->shared_info ) - return; - else - { - elem->shared_info->next = (feature_list *)pool_malloc_lib(swlist->pool, sizeof(feature_list) ); - elem->shared_info->next = NULL; - elem->shared_info->name = NULL; - elem->shared_info->value = NULL; - } - - /* Handle the supported flag */ - elem->supported = SOFTWARE_SUPPORTED_YES; - if ( supported && ! strcmp( supported, "partial" ) ) - elem->supported = SOFTWARE_SUPPORTED_PARTIAL; - if ( supported && ! strcmp( supported, "no" ) ) - elem->supported = SOFTWARE_SUPPORTED_NO; - - /* Add the entry to the end of the list */ - if ( swlist->software_info_list == NULL ) - { - swlist->software_info_list = elem; - swlist->current_software_info = elem; - } - else - { - swlist->current_software_info->next = elem; - swlist->current_software_info = elem; - } - - /* Quick lookup for setting software information */ - swlist->softinfo = swlist->current_software_info; - } - else - { - parse_error(&swlist->state, "%s: No name defined for item (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - - swlist->softinfo = NULL; - } - } - else - { - unknown_tag(swlist, tagname); - } - break; - - case POS_SOFT: - text_dest = NULL; - - if (!strcmp(tagname, "description")) - text_dest = (char **) &swlist->softinfo->longname; - else if (!strcmp(tagname, "year")) - text_dest = (char **) &swlist->softinfo->year; - else if (!strcmp(tagname, "publisher")) - text_dest = (char **) &swlist->softinfo->publisher; - else if (!strcmp(tagname, "info")) - { - const char *str_info_name = NULL; - const char *str_info_value = NULL; - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - str_info_name = attributes[1]; - else if ( !strcmp( attributes[0], "value" ) ) - str_info_value = attributes[1]; - else - unknown_attribute(swlist, attributes[0]); - } - - if ( str_info_name && swlist->softinfo ) - { - char *name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_info_name ) + 1 ) * sizeof(char) ); - char *value = NULL; - - if ( !name ) - return; - - strcpy( name, str_info_name ); - - if ( str_info_value ) - { - value = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_info_value ) + 1 ) * sizeof(char) ); - - if ( !value ) - return; - - strcpy( value, str_info_value ); - - add_other_info( swlist, name, value ); - } - } else { - parse_error(&swlist->state, "%s: Incomplete other_info definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - else if (!strcmp(tagname, "sharedfeat")) - { - const char *str_feature_name = NULL; - const char *str_feature_value = NULL; - - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - str_feature_name = attributes[1]; - - else if ( !strcmp( attributes[0], "value" ) ) - str_feature_value = attributes[1]; - - else - unknown_attribute(swlist, attributes[0]); - } - - /* Prepare for adding feature to feature list */ - if ( str_feature_name && swlist->softinfo ) - { - char *name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_feature_name ) + 1 ) * sizeof(char) ); - char *value = NULL; - - if ( !name ) - return; - - strcpy( name, str_feature_name ); - - if ( str_feature_value ) - { - value = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_feature_value ) + 1 ) * sizeof(char) ); - - if ( !value ) - return; - - strcpy( value, str_feature_value ); - } - - add_info( swlist, name, value ); - } else { - parse_error(&swlist->state, "%s: Incomplete sharedfeat definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - else if ( !strcmp(tagname, "part" ) ) - { - const char *str_name = NULL; - const char *str_interface = NULL; - - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - str_name = attributes[1]; - - else if ( !strcmp( attributes[0], "interface" ) ) - str_interface = attributes[1]; - - else - unknown_attribute(swlist, attributes[0]); - } - - if ( str_name && str_interface && strcmp(str_name, "") && strcmp(str_interface, "") ) - { - if ( swlist->softinfo ) - { - char *name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) ); - char *interface = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_interface ) + 1 ) * sizeof(char) ); - - if ( !name || !interface ) - return; - - strcpy( name, str_name ); - strcpy( interface, str_interface ); - - add_software_part( swlist, name, interface ); - - /* Set up rom/dataarea information */ - swlist->rom_entries = 0; - swlist->current_rom_entry = 0; - swlist->softinfo->partdata[swlist->softinfo->current_part_entry-1].romdata = NULL; - } - } - else - { - /* Incomplete/incorrect part definition ("" names are invalid too) */ - parse_error(&swlist->state, "%s: Incomplete part definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - else - unknown_tag(swlist, tagname); - - if (text_dest && swlist->softinfo) - swlist->state.text_dest = text_dest; - break; - - case POS_PART: - if (!strcmp(tagname, "dataarea")) - { - const char *str_name = NULL; - const char *str_size = NULL; - - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - str_name = attributes[1]; - - else if ( !strcmp( attributes[0], "size") ) - str_size = attributes[1]; - - else - unknown_attribute(swlist, attributes[0]); - } - if ( str_name && str_size && strcmp(str_name, "") && strcmp(str_size, "") ) - { - if ( swlist->softinfo ) - { - UINT32 length = strtol( str_size, NULL, 0 ); - char *s = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) ); - - if ( !s ) - return; - - strcpy( s, str_name ); - - /* ROM_REGION( length, "name", flags ) */ - add_rom_entry( swlist, s, NULL, 0, length, ROMENTRYTYPE_REGION ); - } - } - else - { - /* Missing dataarea name or size ("" are invalid too) */ - parse_error(&swlist->state, "%s: Incomplete dataarea definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - else if (!strcmp(tagname, "diskarea")) - { - const char *str_name = NULL; - - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - str_name = attributes[1]; - else - unknown_attribute(swlist, attributes[0]); - } - if ( str_name ) - { - if ( swlist->softinfo ) - { - char *s = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) ); - - if ( !s ) - return; - - strcpy( s, str_name ); - - /* ROM_REGION( length, "name", flags ) */ - add_rom_entry( swlist, s, NULL, 0, 1, ROMENTRYTYPE_REGION | ROMREGION_DATATYPEDISK); - } - } - else - { - /* Missing dataarea name or size */ - parse_error(&swlist->state, "%s: Incomplete diskarea definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - else if ( !strcmp(tagname, "feature") ) - { - const char *str_feature_name = NULL; - const char *str_feature_value = NULL; - - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - str_feature_name = attributes[1]; - - else if ( !strcmp( attributes[0], "value" ) ) - str_feature_value = attributes[1]; - - else - unknown_attribute(swlist, attributes[0]); - } - - /* Prepare for adding feature to feature list */ - if ( str_feature_name && swlist->softinfo ) - { - char *name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_feature_name ) + 1 ) * sizeof(char) ); - char *value = NULL; - - if ( !name ) - return; - - strcpy( name, str_feature_name ); - - if ( str_feature_value ) - { - value = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_feature_value ) + 1 ) * sizeof(char) ); - - if ( !value ) - return; - - strcpy( value, str_feature_value ); - } - - add_feature( swlist, name, value ); - } else { - parse_error(&swlist->state, "%s: Incomplete feature definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - else if (!strcmp(tagname, "dipswitch")) - { - } - else - unknown_tag(swlist, tagname ); - break; - - case POS_DATA: - if (!strcmp(tagname, "rom")) - { - const char *str_name = NULL; - const char *str_size = NULL; - const char *str_crc = NULL; - const char *str_sha1 = NULL; - const char *str_offset = NULL; - const char *str_value = NULL; - const char *str_status = NULL; - const char *str_loadflag = NULL; - - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - str_name = attributes[1]; - else if ( !strcmp( attributes[0], "size" ) ) - str_size = attributes[1]; - else if ( !strcmp( attributes[0], "crc" ) ) - str_crc = attributes[1]; - else if ( !strcmp( attributes[0], "sha1" ) ) - str_sha1 = attributes[1]; - else if ( !strcmp( attributes[0], "offset" ) ) - str_offset = attributes[1]; - else if ( !strcmp( attributes[0], "value" ) ) - str_value = attributes[1]; - else if ( !strcmp( attributes[0], "status" ) ) - str_status = attributes[1]; - else if ( !strcmp( attributes[0], "loadflag" ) ) - str_loadflag = attributes[1]; - else - unknown_attribute(swlist, attributes[0]); - } - if ( swlist->softinfo ) - { - if ( str_size && str_offset ) - { - UINT32 length = strtol( str_size, NULL, 0 ); - UINT32 offset = strtol( str_offset, NULL, 0 ); - - if ( str_loadflag && !strcmp(str_loadflag, "reload") ) - { - /* Handle 'reload' loadflag */ - add_rom_entry( swlist, NULL, NULL, offset, length, ROMENTRYTYPE_RELOAD | ROM_INHERITFLAGS ); - } - else if ( str_loadflag && !strcmp(str_loadflag, "reload_plain") ) - { - /* Handle 'reload_plain' loadflag */ - add_rom_entry( swlist, NULL, NULL, offset, length, ROMENTRYTYPE_RELOAD); - } - else if ( str_loadflag && !strcmp(str_loadflag, "continue") ) - { - /* Handle 'continue' loadflag */ - add_rom_entry( swlist, NULL, NULL, offset, length, ROMENTRYTYPE_CONTINUE | ROM_INHERITFLAGS ); - } - else if ( str_loadflag && !strcmp(str_loadflag, "fill") ) - { - /* Handle 'fill' loadflag */ - add_rom_entry( swlist, NULL, (const char*)(FPTR)(strtol( str_value, NULL, 0 ) & 0xff), offset, length, ROMENTRYTYPE_FILL ); - } - else - { - if ( str_name) - { - char *s_name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) ); - int hashsize = 7 + 4; - if (str_crc) hashsize+= strlen(str_crc); - if (str_sha1) hashsize+= strlen(str_sha1); - char *hashdata = (char *)pool_malloc_lib( swlist->pool, sizeof(char) * (hashsize) ); - int baddump = ( str_status && !strcmp(str_status, "baddump") ) ? 1 : 0; - int nodump = ( str_status && !strcmp(str_status, "nodump" ) ) ? 1 : 0; - int romflags = 0; - - if ( !s_name || !hashdata ) - return; - - strcpy( s_name, str_name ); - if (nodump) { - sprintf( hashdata, "%s", NO_DUMP); - if (str_crc && str_sha1) { - parse_error(&swlist->state, "%s: No need for hash definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } else { - if (str_crc && str_sha1) { - sprintf( hashdata, "%c%s%c%s%s", hash_collection::HASH_CRC, str_crc, hash_collection::HASH_SHA1, str_sha1, (baddump ? BAD_DUMP : "")); - } else { - parse_error(&swlist->state, "%s: Incomplete rom hash definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - - /* Handle loadflag attribute */ - if ( str_loadflag && !strcmp(str_loadflag, "load16_word_swap") ) - romflags = ROM_GROUPWORD | ROM_REVERSE; - else if ( str_loadflag && !strcmp(str_loadflag, "load16_byte") ) - romflags = ROM_SKIP(1); - else if ( str_loadflag && !strcmp(str_loadflag, "load32_word_swap") ) - romflags = ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2); - else if ( str_loadflag && !strcmp(str_loadflag, "load32_word") ) - romflags = ROM_GROUPWORD | ROM_SKIP(2); - else if ( str_loadflag && !strcmp(str_loadflag, "load32_byte") ) - romflags = ROM_SKIP(3); - - /* ROM_LOAD( name, offset, length, hash ) */ - add_rom_entry( swlist, s_name, hashdata, offset, length, ROMENTRYTYPE_ROM | romflags ); - } else { - parse_error(&swlist->state, "%s: Rom name missing (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - } - else - { - /* Missing name, size, crc, sha1, or offset */ - parse_error(&swlist->state, "%s: Incomplete rom definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - } - else - if (!strcmp(tagname, "disk")) - { - const char *str_name = NULL; - const char *str_sha1 = NULL; - const char *str_status = NULL; - const char *str_writeable = NULL; - - for ( ; attributes[0]; attributes += 2 ) - { - if ( !strcmp( attributes[0], "name" ) ) - str_name = attributes[1]; - else if ( !strcmp( attributes[0], "sha1" ) ) - str_sha1 = attributes[1]; - else if ( !strcmp( attributes[0], "status" ) ) - str_status = attributes[1]; - else if ( !strcmp( attributes[0], "writeable" ) ) - str_writeable = attributes[1]; - else - unknown_attribute(swlist, attributes[0]); - } - if ( swlist->softinfo ) - { - if ( str_name && str_sha1 ) - { - char *s_name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) ); - char *hashdata = (char *)pool_malloc_lib( swlist->pool, sizeof(char) * ( strlen(str_sha1) + 7 + 4 ) ); - int baddump = ( str_status && !strcmp(str_status, "baddump") ) ? 1 : 0; - int nodump = ( str_status && !strcmp(str_status, "nodump" ) ) ? 1 : 0; - int writeable = ( str_writeable && !strcmp(str_writeable, "yes" ) ) ? 1 : 0; - - if ( !s_name || !hashdata ) - return; - - strcpy( s_name, str_name ); - sprintf( hashdata, "%c%s%s", hash_collection::HASH_SHA1, str_sha1, ( nodump ? NO_DUMP : ( baddump ? BAD_DUMP : "" ) ) ); - - add_rom_entry( swlist, s_name, hashdata, 0, 0, ROMENTRYTYPE_ROM | (writeable ? DISK_READWRITE : DISK_READONLY ) ); - } - else - { - if (!str_status || strcmp(str_status, "nodump")) // a no_dump chd is not an incomplete entry - { - parse_error(&swlist->state, "%s: Incomplete disk definition (line %lu)\n", - swlist->file->filename(),XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - } - } - else if (!strcmp(tagname, "dipvalue")) - { - } - else - unknown_tag(swlist, tagname); - break; - } - swlist->state.pos = (softlist_parse_position) (swlist->state.pos + 1); -} - -/*------------------------------------------------- - end_handler --------------------------------------------------*/ - -static void end_handler(void *data, const char *name) -{ - software_list *swlist = (software_list *) data; - swlist->state.text_dest = NULL; - - swlist->state.pos = (softlist_parse_position) (swlist->state.pos - 1); - switch(swlist->state.pos) - { - case POS_ROOT: - break; - - case POS_MAIN: - if ( swlist->softinfo ) - { - add_software_part( swlist, NULL, NULL ); - } - break; - - case POS_SOFT: - if ( ! strcmp( name, "part" ) && swlist->softinfo ) - { - /* Was any dataarea/rom information encountered? */ - if ( swlist->softinfo->partdata[swlist->softinfo->current_part_entry-1].romdata != NULL ) - { - /* If so, force a ROM_END */ - add_rom_entry( swlist, NULL, NULL, 0, 0, ROMENTRYTYPE_END ); - } - /* Add shared_info inherited from the software_info level, if any */ - if ( swlist->softinfo && swlist->softinfo->shared_info ) - { - feature_list *list = swlist->softinfo->shared_info; - - while( list->next ) - { - add_feature( swlist, list->next->name, list->next->value ); - list = list->next; - } - } - } - break; - - case POS_PART: - break; - case POS_DATA: - break; - } -} - - -/*------------------------------------------------- - data_handler --------------------------------------------------*/ - -static void data_handler(void *data, const XML_Char *s, int len) -{ - software_list *swlist = (software_list *) data; - int text_len; - char *text; - - if (swlist->state.text_dest) - { - text = *swlist->state.text_dest; - - text_len = text ? strlen(text) : 0; - text = (char*)pool_realloc_lib(swlist->pool, text, text_len + len + 1); - if (!text) - return; - - memcpy(&text[text_len], s, len); - text[text_len + len] = '\0'; - *swlist->state.text_dest = text; - } else { - if (swlist->state.error_proc) - { - int errcnt = 0; - for (int i=0;i0) { - parse_error(&swlist->state, "%s: Unknown content (line %lu)\n", - swlist->file->filename(), - XML_GetCurrentLineNumber(swlist->state.parser)); - } - } - } -} - - -/*------------------------------------------------- - software_list_get_count - -------------------------------------------------*/ - -static int software_list_get_count(const software_list *swlist) -{ - int count = 0; - - for (const software_info *swinfo = software_list_find(swlist, "*", NULL); swinfo != NULL; swinfo = software_list_find(swlist, "*", swinfo)) - count++; - - return count; -} - - -/*------------------------------------------------- - software_get_clone - retrive name string of the - parent software, if any - -------------------------------------------------*/ - -const char *software_get_clone(emu_options &options, char *swlist, const char *swname) -{ - const software_list *software_list_ptr = software_list_open(options, swlist, FALSE, NULL); - const char *retval = NULL; - if (software_list_ptr) - { - const software_info *tmp = software_list_find(software_list_ptr, swname, NULL); - retval = core_strdup(tmp->parentname); - software_list_close(software_list_ptr); - } - - return retval; -} - - -/*------------------------------------------------- - software_get_support - retrive support state of - the software - -------------------------------------------------*/ - -UINT32 software_get_support(emu_options &options, char *swlist, const char *swname) -{ - const software_list *software_list_ptr = software_list_open(options, swlist, FALSE, NULL); - UINT32 retval = 0; - - if (software_list_ptr) - { - const software_info *tmp = software_list_find(software_list_ptr, swname, NULL); - retval = tmp->supported; - software_list_close(software_list_ptr); - } - - return retval; -} - - -/*------------------------------------------------- - software_list_parse --------------------------------------------------*/ - -void software_list_parse(software_list *swlist, - void (*error_proc)(const char *message), - void *param) -{ - char buf[1024]; - UINT32 len; - XML_Memory_Handling_Suite memcallbacks; - - swlist->file->seek(0, SEEK_SET); - - memset(&swlist->state, 0, sizeof(swlist->state)); - swlist->state.error_proc = error_proc; - swlist->state.param = param; - - /* create the XML parser */ - memcallbacks.malloc_fcn = expat_malloc; - memcallbacks.realloc_fcn = expat_realloc; - memcallbacks.free_fcn = expat_free; - swlist->state.parser = XML_ParserCreate_MM(NULL, &memcallbacks, NULL); - if (!swlist->state.parser) - goto done; - - XML_SetUserData(swlist->state.parser, swlist); - XML_SetElementHandler(swlist->state.parser, start_handler, end_handler); - XML_SetCharacterDataHandler(swlist->state.parser, data_handler); - - while(!swlist->state.done) - { - len = swlist->file->read(buf, sizeof(buf)); - swlist->state.done = swlist->file->eof(); - if (XML_Parse(swlist->state.parser, buf, len, swlist->state.done) == XML_STATUS_ERROR) - { - parse_error(&swlist->state, "%s: %s (line %lu column %lu)\n", - swlist->file->filename(), - XML_ErrorString(XML_GetErrorCode(swlist->state.parser)), - XML_GetCurrentLineNumber(swlist->state.parser), - XML_GetCurrentColumnNumber(swlist->state.parser)); - goto done; - } - } - -done: - if (swlist->state.parser) - XML_ParserFree(swlist->state.parser); - swlist->state.parser = NULL; - swlist->current_software_info = swlist->software_info_list; - swlist->list_entries = software_list_get_count(swlist); -} - - -/*------------------------------------------------- - software_list_open --------------------------------------------------*/ - -software_list *software_list_open(emu_options &options, const char *listname, int is_preload, - void (*error_proc)(const char *message)) -{ - software_list *swlist = NULL; - object_pool *pool = NULL; - file_error filerr; - - /* create a pool for this software list file */ - pool = pool_alloc_lib(error_proc); - if (!pool) - goto error; - - /* allocate space for this software list file */ - swlist = (software_list *) pool_malloc_lib(pool, sizeof(*swlist)); - if (!swlist) - goto error; - - /* set up the software_list structure */ - memset(swlist, 0, sizeof(*swlist)); - swlist->pool = pool; - swlist->error_proc = error_proc; - - /* open a file */ - swlist->file = global_alloc(emu_file(options.hash_path(), OPEN_FLAG_READ)); - filerr = swlist->file->open(listname, ".xml"); - if (filerr != FILERR_NONE) - goto error; - - if (is_preload) - { - software_list_parse(swlist, swlist->error_proc, NULL); - swlist->current_software_info = NULL; - } - - return swlist; - -error: - if (swlist != NULL) - software_list_close(swlist); - return NULL; -} - - -/*------------------------------------------------- - software_list_close --------------------------------------------------*/ - -void software_list_close(const software_list *swlist) -{ - if (swlist == NULL) - return; - - if (swlist->file != NULL) - global_free(swlist->file); - pool_free_lib(swlist->pool); -} - - -/*------------------------------------------------- - software_list_get_description - -------------------------------------------------*/ - -const char *software_list_get_description(const software_list *swlist) -{ - return swlist->description; -} - - -#if 0 -/*------------------------------------------------- - software_list_find_by_number - -------------------------------------------------*/ - -INLINE software_info *software_list_find_by_number(software_list *swlist, int number) -{ - int length = swlist->list_entries; - if (number > length) - return NULL; - - software_info *cur_info = software_list_find(swlist, "*", NULL); - - for (int count = 0; count < number; count++) - cur_info = software_list_find(swlist, "*", cur_info); - - return cur_info; -} -#endif - - -/*------------------------------------------------- - softlist_penalty_compare (borrowed from driver.c) - -------------------------------------------------*/ - -static int softlist_penalty_compare(const char *source, const char *target) -{ - int gaps = 1; - int last = TRUE; - - /* scan the strings */ - for ( ; *source && *target; target++) - { - /* do a case insensitive match */ - int match = (tolower((UINT8)*source) == tolower((UINT8)*target)); - - /* if we matched, advance the source */ - if (match) - source++; - - /* if the match state changed, count gaps */ - if (match != last) - { - last = match; - if (!match) - gaps++; - } - } - - /* penalty if short string does not completely fit in */ - for ( ; *source; source++) - gaps++; - - /* if we matched perfectly, gaps == 0 */ - if (gaps == 1 && *source == 0 && *target == 0) - gaps = 0; - - return gaps; -} - - -/*------------------------------------------------- - software_list_find_approx_matches - -------------------------------------------------*/ - -void software_list_find_approx_matches(software_list_device *swlistdev, software_list *swlist, const char *name, int matches, software_info **list, const char* interface) -{ -#undef rand - - int matchnum; - int *penalty; - - /* if no name, return */ + // if no name, return if (name == NULL || name[0] == 0) return; - /* allocate some temp memory */ - penalty = global_alloc_array(int, matches); - - /* initialize everyone's states */ - for (matchnum = 0; matchnum < matches; matchnum++) + // initialize everyone's states + dynamic_array penalty(matches); + for (int matchnum = 0; matchnum < matches; matchnum++) { penalty[matchnum] = 9999; list[matchnum] = NULL; } - for (software_info *swinfo = software_list_find(swlist, "*", NULL); swinfo != NULL; swinfo = software_list_find(swlist, "*", swinfo)) + // iterate over our info (will cause a parse if needed) + for (software_info *swinfo = first_software_info(); swinfo != NULL; swinfo = swinfo->next()) { - int curpenalty, tmp; - software_info *candidate = swinfo; - - software_part *part = software_find_part(swinfo, NULL, NULL); - if ((interface==NULL || softlist_contain_interface(interface, part->interface_)) && (is_software_compatible(part, swlistdev))) + software_part *part = swinfo->first_part(); + if ((interface == NULL || part->matches_interface(interface)) && part->is_compatible(*this)) { - /* pick the best match between driver name and description */ - curpenalty = softlist_penalty_compare(name, candidate->longname); - tmp = softlist_penalty_compare(name, candidate->shortname); - curpenalty = MIN(curpenalty, tmp); + // pick the best match between driver name and description + int longpenalty = driver_list::penalty_compare(name, swinfo->longname()); + int shortpenalty = driver_list::penalty_compare(name, swinfo->shortname()); + int curpenalty = MIN(longpenalty, shortpenalty); - /* insert into the sorted table of matches */ - for (matchnum = matches - 1; matchnum >= 0; matchnum--) + // insert into the sorted table of matches + for (int matchnum = matches - 1; matchnum >= 0; matchnum--) { - /* stop if we're worse than the current entry */ + // stop if we're worse than the current entry if (curpenalty >= penalty[matchnum]) break; - /* as long as this isn't the last entry, bump this one down */ + // as long as this isn't the last entry, bump this one down if (matchnum < matches - 1) { penalty[matchnum + 1] = penalty[matchnum]; list[matchnum + 1] = list[matchnum]; } - list[matchnum] = candidate; + list[matchnum] = swinfo; penalty[matchnum] = curpenalty; } } } - - /* free our temp memory */ - global_free(penalty); } -/*------------------------------------------------- - software_list_find --------------------------------------------------*/ +//------------------------------------------------- +// release - reset to a pre-parsed state +//------------------------------------------------- -const software_info *software_list_find(const software_list *swlist, const char *look_for, const software_info *prev) +void software_list_device::release() { - if (swlist == NULL) - return NULL; +fprintf(stderr, "Resetting %s\n", m_file.filename()); + m_parsed = false; + m_description = NULL; + m_errors.reset(); + m_infolist.reset(); + m_stringpool.reset(); +} + +//------------------------------------------------- +// find_by_name - find a software list by name +// across all software list devices +//------------------------------------------------- + +software_list_device *software_list_device::find_by_name(const machine_config &config, const char *name) +{ + // iterate over each device in the system and find a match + software_list_device_iterator deviter(config.root_device()); + for (software_list_device *swlistdev = deviter.first(); swlistdev != NULL; swlistdev = deviter.next()) + if (strcmp(swlistdev->list_name(), name) == 0) + return swlistdev; + return NULL; +} + + +//------------------------------------------------- +// software_display_matches - display a list of +// possible matches in the system to the given +// name, across all software list devices +//------------------------------------------------- + +void software_list_device::display_matches(const machine_config &config, const char *interface, const char *name) +{ + // check if there is at least one software list + software_list_device_iterator deviter(config.root_device()); + if (deviter.first()) + mame_printf_error("\n\"%s\" approximately matches the following\n" + "supported software items (best match first):\n\n", name); + + // iterate through lists + for (software_list_device *swlistdev = deviter.first(); swlistdev != NULL; swlistdev = deviter.next()) + { + // get the top 16 approximate matches for the selected device interface (i.e. only carts for cartslot, etc.) + software_info *matches[16] = { 0 }; + swlistdev->find_approx_matches(name, ARRAY_LENGTH(matches), matches, interface); + + // if we found some, print them + if (matches[0] != 0) + { + // different output depending on original system or compatible + if (swlistdev->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) + mame_printf_error("* Software list \"%s\" (%s) matches: \n", swlistdev->list_name(), swlistdev->description()); + else + mame_printf_error("* Compatible software list \"%s\" (%s) matches: \n", swlistdev->list_name(), swlistdev->description()); + + // print them out + for (int softnum = 0; softnum < ARRAY_LENGTH(matches); softnum++) + if (matches[softnum] != NULL) + mame_printf_error("%-18s%s\n", matches[softnum]->shortname(), matches[softnum]->longname()); + + mame_printf_error("\n"); + } + } +} + + +//------------------------------------------------- +// find - find an item by name in the software +// list, using wildcards and optionally starting +// from an intermediate point +//------------------------------------------------- + +software_info *software_list_device::find(const char *look_for, software_info *prev) +{ + // NULL search returns nothing if (look_for == NULL) return NULL; - /* If we haven't read in the xml file yet, then do it now */ - /* Just-in-time parsing, hence the const-cast */ - if ( ! swlist->software_info_list ) - software_list_parse( const_cast(swlist), swlist->error_proc, NULL ); - - for ( prev = prev ? prev->next : swlist->software_info_list; prev; prev = prev->next ) - { - if ( !mame_strwildcmp( look_for, prev->shortname ) ) + // find a match (will cause a parse if needed when calling first_software_info) + for (prev = (prev != NULL) ? prev->next() : first_software_info(); prev != NULL; prev = prev->next()) + if (mame_strwildcmp(look_for, prev->shortname()) == 0) break; - } return prev; } -software_info *software_list_find(software_list *swlist, const char *look_for, software_info *prev) + +//------------------------------------------------- +// parse - parse our softlist file +//------------------------------------------------- + +void software_list_device::parse() { - return const_cast(software_list_find(const_cast(swlist), - look_for, - const_cast(prev))); -} + // skip if done + if (m_parsed) + return; -/*------------------------------------------------- - software_find_romdata (for validation purposes) - -------------------------------------------------*/ + // reset the errors + m_errors.reset(); -static struct rom_entry *software_find_romdata(software_part *swpart, const char *dataname) -{ - struct rom_entry *data = swpart ? swpart->romdata : NULL; - - /* If no dataname supplied, then we just return the first entry */ - if (data) + // attempt to open the file + file_error filerr = m_file.open(m_list_name, ".xml"); + if (filerr == FILERR_NONE) { - while(data && data->_name) - { - if (dataname) - { - if (!strcmp(dataname, data->_name)) - { - break; - } - } - /* No specific dataname supplied, return the first rom_entry */ - else - break; - - data++; - } - - if (data && !data->_name) - data = NULL; - } - - return data; -} - - -/*------------------------------------------------- - software_romdata_next (for validation purposes) - -------------------------------------------------*/ - -static struct rom_entry *software_romdata_next(struct rom_entry *romdata) -{ - if (romdata && romdata->_name) - { - romdata++; + // parse if no error + softlist_parser parser(*this, m_errors); + m_file.close(); } else - romdata = NULL; - - return romdata; + m_errors.printf("Error opening file: %s\n", filename()); + + // indicate that we've been parsed + m_parsed = true; } -/*------------------------------------------------- - software_find_part --------------------------------------------------*/ - -const software_part *software_find_part(const software_info *sw, const char *partname, const char *interface) -{ - const software_part *part = sw ? sw->partdata : NULL; - - /* If neither partname nor interface supplied, then we just return the first entry */ - if ( partname || interface ) - { - while( part && part->name ) - { - if ( partname ) - { - if ( !strcmp(partname, part->name ) ) - { - if ( interface ) - { - if ( softlist_contain_interface(interface, part->interface_) ) - { - break; - } - } - else - { - break; - } - } - } - else - { - /* No specific partname supplied, find the first match based on interface */ - if ( interface ) - { - if ( softlist_contain_interface(interface, part->interface_) ) - { - break; - } - } - } - part++; - } - } - - if ( part && ! part->name ) - part = NULL; - - return part; -} - -software_part *software_find_part(software_info *sw, const char *partname, const char *interface) -{ - return const_cast(software_find_part(const_cast(sw), partname, interface)); -} - -/*------------------------------------------------- - software_part_next --------------------------------------------------*/ - -const software_part *software_part_next(const software_part *part) -{ - if ( part && part->name ) - { - part++; - } - - if ( ! part->name ) - part = NULL; - - return part; -} - -software_part *software_part_next(software_part *part) -{ - return const_cast(software_part_next(const_cast(part))); -} - -/*------------------------------------------------- - software_display_matches --------------------------------------------------*/ - -void software_display_matches(const machine_config &config,emu_options &options, const char *interface ,const char *name) -{ - // check if there is at least a software list - software_list_device_iterator deviter(config.root_device()); - if (deviter.first()) - { - mame_printf_error("\n\"%s\" approximately matches the following\n" - "supported software items (best match first):\n\n", name); - } - - for (software_list_device *swlist = deviter.first(); swlist != NULL; swlist = deviter.next()) - { - software_list *list = software_list_open(options, swlist->list_name(), FALSE, NULL); - - if (list) - { - software_info *matches[16] = { 0 }; - int softnum; - - software_list_parse(list, list->error_proc, NULL); - // get the top 16 approximate matches for the selected device interface (i.e. only carts for cartslot, etc.) - software_list_find_approx_matches(swlist, list, name, ARRAY_LENGTH(matches), matches, interface); - - if (matches[0] != 0) - { - if (swlist->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) - mame_printf_error("* Software list \"%s\" (%s) matches: \n", swlist->list_name(), software_list_get_description(list)); - else - mame_printf_error("* Compatible software list \"%s\" (%s) matches: \n", swlist->list_name(), software_list_get_description(list)); - - // print them out - for (softnum = 0; softnum < ARRAY_LENGTH(matches); softnum++) - if (matches[softnum] != NULL) - mame_printf_error("%-18s%s\n", matches[softnum]->shortname, matches[softnum]->longname); - - mame_printf_error("\n"); - } - software_list_close(list); - } - } -} - -static void find_software_item(const machine_config &config, emu_options &options, const device_image_interface *image, const char *path, software_list **software_list_ptr, software_info **software_info_ptr,software_part **software_part_ptr, const char **sw_list_name) -{ - char *swlist_name, *swname, *swpart; //, *swname_bckp; - *software_list_ptr = NULL; - *software_info_ptr = NULL; - *software_part_ptr = NULL; - - /* Split full software name into software list name and short software name */ - software_name_split(path, &swlist_name, &swname, &swpart ); -// swname_bckp = swname; - - const char *interface = NULL; - if (image) interface = image->image_interface(); - - if ( swlist_name ) - { - /* Try to open the software list xml file explicitly named by the user */ - *software_list_ptr = software_list_open( options, swlist_name, FALSE, NULL ); - - if ( *software_list_ptr ) - { - *software_info_ptr = software_list_find( *software_list_ptr, swname, NULL ); - - if ( *software_info_ptr ) - { - *software_part_ptr = software_find_part( *software_info_ptr, swpart, interface ); - } - } - } - else - { - /* Loop through all the software lists named in the driver */ - software_list_device_iterator deviter(config.root_device()); - for (software_list_device *swlist = deviter.first(); swlist != NULL; swlist = deviter.next()) - { - swlist_name = (char *)swlist->list_name(); - - if (swlist->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) - { - if ( *software_list_ptr ) - { - software_list_close( *software_list_ptr ); - } - - *software_list_ptr = software_list_open( options, swlist_name, FALSE, NULL ); - - if ( software_list_ptr ) - { - *software_info_ptr = software_list_find( *software_list_ptr, swname, NULL ); - - if ( *software_info_ptr ) - { - *software_part_ptr = software_find_part( *software_info_ptr, swpart, interface ); - if (*software_part_ptr) break; - } - } - } - } - - /* If not found try to load the software list using the driver name */ - if ( ! *software_part_ptr ) - { - swlist_name = (char *)options.system()->name; - - if ( *software_list_ptr ) - { - software_list_close( *software_list_ptr ); - } - - *software_list_ptr = software_list_open( options, swlist_name, FALSE, NULL ); - - if ( *software_list_ptr ) - { - *software_info_ptr = software_list_find( *software_list_ptr, swname, NULL ); - - if ( *software_info_ptr ) - { - *software_part_ptr = software_find_part( *software_info_ptr, swpart, interface ); - } - } - } - - /* If not found try to load the software list using the software name as software */ - /* list name and software part name as software name. */ - if ( ! *software_part_ptr ) - { - swlist_name = swname; - swname = swpart; - swpart = NULL; - - if ( *software_list_ptr ) - { - software_list_close( *software_list_ptr ); - } - - *software_list_ptr = software_list_open( options, swlist_name, FALSE, NULL ); - - if ( software_list_ptr ) - { - *software_info_ptr = software_list_find( *software_list_ptr, swname, NULL ); - - if ( *software_info_ptr ) - { - *software_part_ptr = software_find_part( *software_info_ptr, swpart, interface ); - } - - if ( ! *software_part_ptr ) - { - software_list_close( *software_list_ptr ); - *software_list_ptr = NULL; - } - } - } - } - *sw_list_name = global_strdup(swlist_name); - - global_free( swlist_name ); - global_free( swname ); - global_free( swpart ); -} - -/*------------------------------------------------- - load_software_part - - Load a software part for a device. The part to - load is determined by the "path", software lists - configured for a driver, and the interface - supported by the device. - - returns true if the software could be loaded, - false otherwise. If the software could be loaded - sw_info and sw_part are also set. --------------------------------------------------*/ - -bool load_software_part(emu_options &options, device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name, char**list_name) -{ - software_list *software_list_ptr = NULL; - software_info *software_info_ptr = NULL; - software_part *software_part_ptr = NULL; - const char *swlist_name = NULL; - - bool result = false; - *sw_info = NULL; - *sw_part = NULL; - *list_name = NULL; - - find_software_item(image->device().machine().config(), options, image, path, &software_list_ptr, &software_info_ptr, &software_part_ptr, &swlist_name); - - // if no match has been found, we suggest similar shortnames - if (software_info_ptr == NULL) - { - software_display_matches(image->device().machine().config(),image->device().machine().options(), image->image_interface(), path); - } - - if ( software_part_ptr ) - { - /* Load the software part */ - try { - result = image->call_softlist_load((char *)swlist_name, (char *)software_info_ptr->shortname, software_part_ptr->romdata ); - } - catch (emu_fatalerror &fatal) - { - software_list_close( software_list_ptr ); - global_free(swlist_name); - throw fatal; - } - - /* Sanity checks */ - if (software_info_ptr->shortname == NULL) - throw emu_fatalerror("Software entry is missing the name attribute!\n"); - if (software_info_ptr->longname == NULL) - throw emu_fatalerror("Software entry '%s' is missing the description element!\n", software_info_ptr->shortname); - - /* Create a copy of the software and part information */ - *sw_info = auto_alloc_clear( image->device().machine(), software_info ); - (*sw_info)->shortname = auto_strdup( image->device().machine(), software_info_ptr->shortname ); - (*sw_info)->longname = auto_strdup( image->device().machine(), software_info_ptr->longname ); - if ( software_info_ptr->year ) - (*sw_info)->year = auto_strdup( image->device().machine(), software_info_ptr->year ); - if ( software_info_ptr->publisher ) - (*sw_info)->publisher = auto_strdup( image->device().machine(), software_info_ptr->publisher ); - - (*sw_info)->partdata = (software_part *)auto_alloc_array_clear(image->device().machine(), UINT8, software_info_ptr->part_entries * sizeof(software_part) ); - software_part *new_part = (*sw_info)->partdata; - for (software_part *swp = software_find_part(software_info_ptr, NULL, NULL); swp != NULL; swp = software_part_next(swp)) - { - if (strcmp(software_part_ptr->name,swp->name)==0) *sw_part = new_part; - - new_part->name = auto_strdup( image->device().machine(), swp->name ); - if ( swp->interface_ ) - new_part->interface_ = auto_strdup( image->device().machine(), swp->interface_ ); - - if ( swp->featurelist ) - { - feature_list *list = swp->featurelist; - feature_list *new_list = auto_alloc_clear( image->device().machine(), feature_list ); - - new_part->featurelist = new_list; - - new_list->name = auto_strdup( image->device().machine(), list->name ); - new_list->value = auto_strdup( image->device().machine(), list->value ); - - list = list->next; - - while( list ) - { - new_list->next = auto_alloc_clear( image->device().machine(), feature_list ); - new_list = new_list->next; - new_list->name = auto_strdup( image->device().machine(), list->name ); - new_list->value = auto_strdup( image->device().machine(), list->value ); - - list = list->next; - } - new_list->next = NULL; - } - new_part++; - } - *list_name = auto_strdup( image->device().machine(), swlist_name ); - - /* Tell the world which part we actually loaded */ - *full_sw_name = auto_alloc_array( image->device().machine(), char, strlen(swlist_name) + strlen(software_info_ptr->shortname) + strlen(software_part_ptr->name) + 3 ); - sprintf( *full_sw_name, "%s:%s:%s", swlist_name, software_info_ptr->shortname, software_part_ptr->name ); - - software_list_device_iterator iter(image->device().machine().root_device()); - for (software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) - { - if (strcmp(swlist->list_name(),swlist_name)==0) { - if (!is_software_compatible(software_part_ptr, swlist)) { - mame_printf_warning("WARNING! the set %s might not work on this system due to missing filter(s) '%s'\n",software_info_ptr->shortname,swlist->filter()); - } - break; - } - } - - { - const char *requirement = software_part_get_feature(software_part_ptr, "requirement"); - if (requirement!=NULL) { - software_list *req_software_list_ptr = NULL; - software_info *req_software_info_ptr = NULL; - software_part *req_software_part_ptr = NULL; - const char *req_swlist_name = NULL; - - find_software_item(image->device().machine().config(), options, NULL, requirement, &req_software_list_ptr, &req_software_info_ptr, &req_software_part_ptr, &req_swlist_name); - - if ( req_software_list_ptr ) - { - image_interface_iterator imgiter(image->device().machine().root_device()); - for (device_image_interface *req_image = imgiter.first(); req_image != NULL; req_image = imgiter.next()) - { - const char *interface = req_image->image_interface(); - if (interface != NULL) - { - if (softlist_contain_interface(interface, req_software_part_ptr->interface_)) - { - const char *option = options.value(req_image->brief_instance_name()); - // mount only if not already mounted - if (strlen(option)==0 && !req_image->filename()) { - req_image->set_init_phase(); - req_image->load(requirement); - } - break; - } - } - } - software_list_close( req_software_list_ptr ); - req_software_info_ptr = NULL; - req_software_list_ptr = NULL; - global_free(req_swlist_name); - } - } - } - } - - /* Close the software list if it's still open */ - if ( software_list_ptr ) - { - software_list_close( software_list_ptr ); - software_info_ptr = NULL; - software_list_ptr = NULL; - } - global_free(swlist_name); - return result; -} - - -/*------------------------------------------------- - software_part_get_feature - -------------------------------------------------*/ - -const char *software_part_get_feature(const software_part *part, const char *feature_name) -{ - const feature_list *feature; - - if (part == NULL) - return NULL; - - for (feature = part->featurelist; feature; feature = feature->next) - { - if (!strcmp(feature->name, feature_name)) - return feature->value; - } - - return NULL; - -} - -/*------------------------------------------------- - software_get_default_slot - -------------------------------------------------*/ - - const char *software_get_default_slot(const machine_config &config, emu_options &options, const device_image_interface *image, const char* default_card_slot) -{ - const char* retVal = NULL; - const char* path = options.value(image->instance_name()); - software_list *software_list_ptr = NULL; - software_info *software_info_ptr = NULL; - software_part *software_part_ptr = NULL; - const char *swlist_name = NULL; - - if (strlen(path)>0) { - retVal = default_card_slot; - find_software_item(config, options, image, path, &software_list_ptr, &software_info_ptr, &software_part_ptr, &swlist_name); - if (software_part_ptr!=NULL) { - const char *slot = software_part_get_feature(software_part_ptr, "slot"); - if (slot!=NULL) { - retVal = core_strdup(slot); - } - } - software_list_close(software_list_ptr); - global_free(swlist_name); - } - return retVal; -} - -/*------------------------------------------------- - is_software_compatible - -------------------------------------------------*/ - -bool is_software_compatible(const software_part *swpart, const software_list_device *swlist) -{ - const char *compatibility = software_part_get_feature(swpart, "compatibility"); - const char *filter = swlist->filter(); - if ((compatibility==NULL) || (filter==NULL)) return TRUE; - astring comp = astring(compatibility,","); - char *filt = core_strdup(filter); - char *token = strtok(filt,","); - while (token!= NULL) - { - if (comp.find(0,astring(token,","))!=-1) return TRUE; - token = strtok (NULL, ","); - } - return FALSE; -} - -/*------------------------------------------------- - swinfo_has_multiple_parts - -------------------------------------------------*/ - -bool swinfo_has_multiple_parts(const software_info *swinfo, const char *interface) -{ - int count = 0; - - for (const software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) - { - if (softlist_contain_interface(interface, swpart->interface_)) - count++; - } - return (count > 1) ? true : false; -} - -/*************************************************************************** - DEVICE INTERFACE -***************************************************************************/ - - -void validate_error_proc(const char *message) -{ - mame_printf_error("%s", message); -} +//------------------------------------------------- +// device_validity_check - validate the device +// configuration +//------------------------------------------------- void software_list_device::device_validity_check(validity_checker &valid) const { // add to the global map whenever we check a list so we don't re-check // it in the future - if (s_checked_lists.add(m_list_name, 1, false) == TMERR_DUPLICATE) + if (valid.already_checked(astring("softlist/", m_list_name.cstr()))) return; // do device validation only in case of validate command - if (strcmp(mconfig().options().command(), CLICOMMAND_VALIDATE) != 0) return; + if (strcmp(mconfig().options().command(), CLICOMMAND_VALIDATE) != 0) + return; + + // actually do the validate + const_cast(this)->internal_validity_check(valid); +} + + +//------------------------------------------------- +// internal_validity_check - internal helper to +// check the list +//------------------------------------------------- + +void software_list_device::internal_validity_check(validity_checker &valid) +{ + enum { NAME_LEN_PARENT = 8, NAME_LEN_CLONE = 16 }; + + // first parse and output core errors if any + if (m_errors.len() > 0) + { + mame_printf_error("%s: Errors parsing software list:\n%s", filename(), errors_string()); + release(); + return; + } softlist_map names; softlist_map descriptions; - - enum { NAME_LEN_PARENT = 8, NAME_LEN_CLONE = 16 }; - - software_list *list = software_list_open(mconfig().options(), m_list_name, FALSE, NULL); - if ( list ) + for (software_info *swinfo = first_software_info(); swinfo != NULL; swinfo = swinfo->next()) { - software_list_parse( list, &validate_error_proc, NULL ); + // First, check if the xml got corrupted: - for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) + // Did we lost any description? + if (swinfo->longname() == NULL) { - const char *s; - int is_clone = 0; - - /* First, check if the xml got corrupted: */ - - /* Did we lost any description? */ - if (swinfo->longname == NULL) - { - mame_printf_error("%s: %s has no description\n", list->file->filename(), swinfo->shortname); - break; - } - - /* Did we lost any year? */ - if (swinfo->year == NULL) - { - mame_printf_error("%s: %s has no year\n", list->file->filename(), swinfo->shortname); - break; - } - - /* Did we lost any publisher? */ - if (swinfo->publisher == NULL) - { - mame_printf_error("%s: %s has no publisher\n", list->file->filename(), swinfo->shortname); - break; - } - - /* Second, since the xml is fine, run additional checks: */ - - /* check for duplicate names */ - if (names.add(swinfo->shortname, swinfo, FALSE) == TMERR_DUPLICATE) - { - software_info *match = names.find(swinfo->shortname); - mame_printf_error("%s: %s is a duplicate name (%s)\n", list->file->filename(), swinfo->shortname, match->shortname); - } - - /* check for duplicate descriptions */ - if (descriptions.add(astring(swinfo->longname).makelower().cstr(), swinfo, FALSE) == TMERR_DUPLICATE) - mame_printf_error("%s: %s is a duplicate description (%s)\n", list->file->filename(), swinfo->longname, swinfo->shortname); - - if (swinfo->parentname != NULL) - { - is_clone = 1; - - if (strcmp(swinfo->parentname, swinfo->shortname) == 0) - { - mame_printf_error("%s: %s is set as a clone of itself\n", list->file->filename(), swinfo->shortname); - break; - } - - /* make sure the parent exists */ - software_info *swinfo2 = software_list_find(list, swinfo->parentname, NULL ); - - if (!swinfo2) - mame_printf_error("%s: parent '%s' software for '%s' not found\n", list->file->filename(), swinfo->parentname, swinfo->shortname); - else if (swinfo2->parentname != NULL) - mame_printf_error("%s: %s is a clone of a clone\n", list->file->filename(), swinfo->shortname); - } - - /* make sure the driver name is 8 chars or less */ - if ((is_clone && strlen(swinfo->shortname) > NAME_LEN_CLONE) || ((!is_clone) && strlen(swinfo->shortname) > NAME_LEN_PARENT)) - mame_printf_error("%s: %s %s driver name must be %d characters or less\n", list->file->filename(), swinfo->shortname, - is_clone ? "clone" : "parent", is_clone ? NAME_LEN_CLONE : NAME_LEN_PARENT); - - /* make sure the year is only digits, '?' or '+' */ - for (s = swinfo->year; *s; s++) - if (!isdigit((UINT8)*s) && *s != '?' && *s != '+') - { - mame_printf_error("%s: %s has an invalid year '%s'\n", list->file->filename(), swinfo->shortname, swinfo->year); - break; - } - - softlist_map part_names; - - for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) - { - if (swpart->interface_ == NULL) - mame_printf_error("%s: %s has a part (%s) without interface\n", list->file->filename(), swinfo->shortname, swpart->name); - - if (software_find_romdata(swpart, NULL) == NULL) - mame_printf_error("%s: %s has a part (%s) with no data\n", list->file->filename(), swinfo->shortname, swpart->name); - - if (part_names.add(swpart->name, swinfo, FALSE) == TMERR_DUPLICATE) - mame_printf_error("%s: %s has a part (%s) whose name is duplicate\n", list->file->filename(), swinfo->shortname, swpart->name); - - for (struct rom_entry *swdata = software_find_romdata(swpart, NULL); swdata != NULL; swdata = software_romdata_next(swdata)) - { - struct rom_entry *data = swdata; - - if (data->_name && data->_hashdata) - { - const char *str; - - /* make sure it's all lowercase */ - for (str = data->_name; *str; str++) - if (tolower((UINT8)*str) != *str) - { - mame_printf_error("%s: %s has upper case ROM name %s\n", list->file->filename(), swinfo->shortname, data->_name); - break; - } - - /* make sure the hash is valid */ - hash_collection hashes; - if (!hashes.from_internal_string(data->_hashdata)) - mame_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", list->file->filename(), swinfo->shortname, data->_name, data->_hashdata); - } - } - } - } - software_list_close(list); - } -} - -bool softlist_contain_interface(const char *interface, const char *part_interface) -{ - bool result = FALSE; - - astring interfaces(interface); - char *intf = strtok((char*)interfaces.cstr(),","); - while (intf != NULL) - { - if (!strcmp(intf, part_interface)) - { - result = TRUE; + mame_printf_error("%s: %s has no description\n", filename(), swinfo->shortname()); break; } - intf = strtok (NULL, ","); + + // Did we lost any year? + if (swinfo->year() == NULL) + { + mame_printf_error("%s: %s has no year\n", filename(), swinfo->shortname()); + break; + } + + // Did we lost any publisher? + if (swinfo->publisher() == NULL) + { + mame_printf_error("%s: %s has no publisher\n", filename(), swinfo->shortname()); + break; + } + + // Second, since the xml is fine, run additional checks: + + // check for duplicate names + if (names.add(swinfo->shortname(), swinfo, false) == TMERR_DUPLICATE) + { + software_info *match = names.find(swinfo->shortname()); + mame_printf_error("%s: %s is a duplicate name (%s)\n", filename(), swinfo->shortname(), match->shortname()); + } + + // check for duplicate descriptions + if (descriptions.add(astring(swinfo->longname()).makelower().cstr(), swinfo, false) == TMERR_DUPLICATE) + mame_printf_error("%s: %s is a duplicate description (%s)\n", filename(), swinfo->longname(), swinfo->shortname()); + + bool is_clone = false; + if (swinfo->parentname() != NULL) + { + is_clone = true; + if (strcmp(swinfo->parentname(), swinfo->shortname()) == 0) + { + mame_printf_error("%s: %s is set as a clone of itself\n", filename(), swinfo->shortname()); + break; + } + + // make sure the parent exists + software_info *swinfo2 = find(swinfo->parentname()); + + if (swinfo2 == NULL) + mame_printf_error("%s: parent '%s' software for '%s' not found\n", filename(), swinfo->parentname(), swinfo->shortname()); + else if (swinfo2->parentname() != NULL) + mame_printf_error("%s: %s is a clone of a clone\n", filename(), swinfo->shortname()); + } + + // make sure the driver name is 8 chars or less + if ((is_clone && strlen(swinfo->shortname()) > NAME_LEN_CLONE) || (!is_clone && strlen(swinfo->shortname()) > NAME_LEN_PARENT)) + mame_printf_error("%s: %s %s driver name must be %d characters or less\n", filename(), swinfo->shortname(), + is_clone ? "clone" : "parent", is_clone ? NAME_LEN_CLONE : NAME_LEN_PARENT); + + // make sure the year is only digits, '?' or '+' + for (const char *s = swinfo->year(); *s != 0; s++) + if (!isdigit((UINT8)*s) && *s != '?' && *s != '+') + { + mame_printf_error("%s: %s has an invalid year '%s'\n", filename(), swinfo->shortname(), swinfo->year()); + break; + } + + softlist_map part_names; + for (software_part *part = swinfo->first_part(); part != NULL; part = part->next()) + { + if (part->interface() == NULL) + mame_printf_error("%s: %s has a part (%s) without interface\n", filename(), swinfo->shortname(), part->name()); + + if (part->romdata() == NULL) + mame_printf_error("%s: %s has a part (%s) with no data\n", filename(), swinfo->shortname(), part->name()); + + if (part_names.add(part->name(), swinfo, false) == TMERR_DUPLICATE) + mame_printf_error("%s: %s has a part (%s) whose name is duplicate\n", filename(), swinfo->shortname(), part->name()); + + for (const rom_entry *data = part->romdata(); data->_name != NULL; data++) + if (data->_hashdata != NULL) + { + // make sure it's all lowercase + for (const char *str = data->_name; *str; str++) + if (tolower((UINT8)*str) != *str) + { + mame_printf_error("%s: %s has upper case ROM name %s\n", filename(), swinfo->shortname(), data->_name); + break; + } + + // make sure the hash is valid + hash_collection hashes; + if (!hashes.from_internal_string(data->_hashdata)) + mame_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", filename(), swinfo->shortname(), data->_name, data->_hashdata); + } + } + } + + // release all the memory + release(); +} + + + +//************************************************************************** +// SOFTWARE LIST PARSER +//************************************************************************** + +//------------------------------------------------- +// softlist_parser - constructor +//------------------------------------------------- + +softlist_parser::softlist_parser(software_list_device &list, astring &errors) + : m_list(list), + m_errors(errors), + m_done(false), + m_data_accum_expected(false), + m_current_info(NULL), + m_current_part(NULL), + m_pos(POS_ROOT) +{ +fprintf(stderr, "Parsing %s\n", m_list.m_file.filename()); + // set up memory callbacks + XML_Memory_Handling_Suite memcallbacks; + memcallbacks.malloc_fcn = expat_malloc; + memcallbacks.realloc_fcn = expat_realloc; + memcallbacks.free_fcn = expat_free; + + // create the parser + m_parser = XML_ParserCreate_MM(NULL, &memcallbacks, NULL); + if (m_parser == NULL) + throw std::bad_alloc(); + + // set the handlers + XML_SetUserData(m_parser, this); + XML_SetElementHandler(m_parser, &softlist_parser::start_handler, &softlist_parser::end_handler); + XML_SetCharacterDataHandler(m_parser, &softlist_parser::data_handler); + + // parse the file contents + m_list.m_file.seek(0, SEEK_SET); + char buffer[1024]; + while (!m_done) + { + UINT32 length = m_list.m_file.read(buffer, sizeof(buffer)); + m_done = m_list.m_file.eof(); + if (XML_Parse(m_parser, buffer, length, m_done) == XML_STATUS_ERROR) + { + parse_error("%s", parser_error()); + break; + } + } + + // free the parser + XML_ParserFree(m_parser); +fprintf(stderr, "Parsing complete\n"); +} + + +//------------------------------------------------- +// expat_malloc/expat_realloc/expat_free - +// wrappers for memory allocation functions so +// that they pass through out memory tracking +// systems +//------------------------------------------------- + +void *softlist_parser::expat_malloc(size_t size) +{ + return global_alloc_array_clear(UINT8, size); +} + +void *softlist_parser::expat_realloc(void *ptr, size_t size) +{ + if (ptr != NULL) global_free_array((UINT8 *)ptr); + return global_alloc_array_clear(UINT8, size); +} + +void softlist_parser::expat_free(void *ptr) +{ + global_free_array((UINT8 *)ptr); +} + + +//------------------------------------------------- +// parse_error - append a parsing error with +// filename, line and column information +//------------------------------------------------- + +void ATTR_PRINTF(2,3) softlist_parser::parse_error(const char *fmt, ...) +{ + // always start with filename(line.column): + m_errors.catprintf("%s(%d.%d): ", filename(), line(), column()); + + // append the remainder of the string + va_list va; + va_start(va, fmt); + m_errors.catvprintf(fmt, va); + va_end(va); + + // append a newline at the end + m_errors.cat("\n"); +} + + +//------------------------------------------------- +// parse_attributes - helper to parse a set of +// attributes into a list of strings +//------------------------------------------------- + +void softlist_parser::parse_attributes(const char **attributes, int numattrs, const char *attrlist[], const char *outlist[]) +{ + // iterate over attribute/value pairs + for( ; attributes[0]; attributes += 2) + { + int index; + + // look for a match among the attributes provided + for (index = 0; index < numattrs; index++) + if (strcmp(attributes[0], attrlist[index]) == 0) + { + // if found, set the corresponding output entry to the value + outlist[index] = attributes[1]; + break; + } + + // if not found, report an unknown attribute + if (index == numattrs) + unknown_attribute(attributes[0]); + } +} + + +//------------------------------------------------- +// add_rom_entry - append a new ROM entry to the +// current part's list +//------------------------------------------------- + +void softlist_parser::add_rom_entry(const char *name, const char *hashdata, UINT32 offset, UINT32 length, UINT32 flags) +{ + // get the current part + if (m_current_part == NULL) + { + parse_error("ROM entry added in invalid context"); + return; + } + + // make sure we don't add duplicate regions + if (name != NULL && (flags & ROMENTRY_TYPEMASK) == ROMENTRYTYPE_REGION) + for (int romentry = 0; romentry < m_current_part->m_romdata.count(); romentry++) + if (m_current_part->m_romdata[romentry]._name != NULL && strcmp(m_current_part->m_romdata[romentry]._name, name) == 0) + parse_error("Duplicated dataarea %s in software %s", name, infoname()); + + // create the new entry and append it + rom_entry &entry = m_current_part->m_romdata.append(); + entry._name = m_list.add_string(name); + entry._hashdata = m_list.add_string(hashdata); + entry._offset = offset; + entry._length = length; + entry._flags = flags; +} + + +//------------------------------------------------- +// start_handler - expat handler for tag start +//------------------------------------------------- + +void softlist_parser::start_handler(void *data, const char *tagname, const char **attributes) +{ + // switch off the current state + softlist_parser *state = reinterpret_cast(data); + switch (state->m_pos) + { + case POS_ROOT: + state->parse_root_start(tagname, attributes); + break; + + case POS_MAIN: + state->parse_main_start(tagname, attributes); + break; + + case POS_SOFT: + state->parse_soft_start(tagname, attributes); + break; + + case POS_PART: + state->parse_part_start(tagname, attributes); + break; + + case POS_DATA: + state->parse_data_start(tagname, attributes); + break; + } + + // increment the state since this is a tag start + state->m_pos = parse_position(state->m_pos + 1); +} + + +//------------------------------------------------- +// end_handler - handle end-of-tag post-processing +//------------------------------------------------- + +void softlist_parser::end_handler(void *data, const char *name) +{ + // reset the text destination and bump the position down + softlist_parser *state = reinterpret_cast(data); + state->m_pos = parse_position(state->m_pos - 1); + + // switch off of the new position + switch (state->m_pos) + { + case POS_ROOT: + break; + + case POS_MAIN: + state->m_current_info = NULL; + break; + + case POS_SOFT: + state->parse_soft_end(name); + state->m_current_part = NULL; + break; + + case POS_PART: + break; + + case POS_DATA: + break; + } + + // stop accumulating + state->m_data_accum_expected = false; + state->m_data_accum.reset(); +} + + +//------------------------------------------------- +// data_handler - expat data handler +//------------------------------------------------- + +void softlist_parser::data_handler(void *data, const XML_Char *s, int len) +{ + softlist_parser *state = reinterpret_cast(data); + + // if we have an astring to accumulate data in, do it + if (state->m_data_accum_expected) + state->m_data_accum.cat(s, len); + + // otherwise, report an error if the data is non-blank + else + for (int i = 0; i < len; i++) + if (!isspace(s[i])) + { + state->parse_error("Unexpected content"); + break; + } +} + + +//------------------------------------------------- +// parse_root_start - handle tag start at the root +//------------------------------------------------- + +void softlist_parser::parse_root_start(const char *tagname, const char **attributes) +{ + // + if (strcmp(tagname, "softwarelist") == 0) + { + static const char *attrnames[] = { "name", "description" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + if (attrvalues[1] != NULL) + m_list.m_description = m_list.add_string(attrvalues[1]); + } + else + unknown_tag(tagname); +} + + +//------------------------------------------------- +// parse_main_start - handle tag start within +// a softwarelist tag +//------------------------------------------------- + +void softlist_parser::parse_main_start(const char *tagname, const char **attributes) +{ + // + if (strcmp(tagname, "software") == 0) + { + static const char *attrnames[] = { "name", "cloneof", "supported" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + if (attrvalues[0] != NULL) + m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1]), attrvalues[2]))); + else + parse_error("No name defined for item"); + } + else + unknown_tag(tagname); +} + + +//------------------------------------------------- +// parse_main_start - handle tag start within +// a software tag +//------------------------------------------------- + +void softlist_parser::parse_soft_start(const char *tagname, const char **attributes) +{ + // get the current info; error if none + if (m_current_info == NULL) + { + parse_error("Tag %s found outside of software context", tagname); + return; + } + + // + if (strcmp(tagname, "description") == 0) + m_data_accum_expected = true; + + // + else if (strcmp(tagname, "year") == 0) + m_data_accum_expected = true; + + // + else if (strcmp(tagname, "publisher") == 0) + m_data_accum_expected = true; + + // + else if (strcmp(tagname, "info") == 0) + { + static const char *attrnames[] = { "name", "value" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + if (attrvalues[0] != NULL && attrvalues[1] != NULL) + m_current_info->m_other_info.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1])))); + else + parse_error("Incomplete other_info definition"); + } + + // + else if (strcmp(tagname, "sharedfeat") == 0) + { + static const char *attrnames[] = { "name", "value" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + if (attrvalues[0] != NULL && attrvalues[1] != NULL) + m_current_info->m_shared_info.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1])))); + else + parse_error("Incomplete sharedfeat definition"); + } + + // + else if (strcmp(tagname, "part" ) == 0) + { + static const char *attrnames[] = { "name", "interface" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + if (attrvalues[0] != NULL && attrvalues[1] != NULL && strcmp(attrvalues[0], "") != 0 && strcmp(attrvalues[1], "") != 0) + m_current_part = &m_current_info->m_partdata.append(*global_alloc(software_part(*m_current_info, m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1])))); + else + parse_error("Incomplete part definition"); + } + else + unknown_tag(tagname); +} + + +//------------------------------------------------- +// parse_part_start - handle tag start within +// a part tag +//------------------------------------------------- + +void softlist_parser::parse_part_start(const char *tagname, const char **attributes) +{ + // get the current part; error if none + if (m_current_part == NULL) + { + parse_error("Tag %s found outside of part context", tagname); + return; + } + + // + if (strcmp(tagname, "dataarea") == 0) + { + static const char *attrnames[] = { "name", "size" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + if (attrvalues[0] != NULL && attrvalues[1] != NULL && strcmp(attrvalues[0], "") != 0 && strcmp(attrvalues[1], "") != 0) + add_rom_entry(attrvalues[0], NULL, 0, strtol(attrvalues[1], NULL, 0), ROMENTRYTYPE_REGION); + else + parse_error("Incomplete dataarea definition"); + } + + // + else if (strcmp(tagname, "diskarea") == 0) + { + static const char *attrnames[] = { "name" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + if (attrvalues[0] != NULL) + add_rom_entry(attrvalues[0], NULL, 0, 1, ROMENTRYTYPE_REGION | ROMREGION_DATATYPEDISK); + else + parse_error("Incomplete diskarea definition"); + } + + // + else if (strcmp(tagname, "feature") == 0) + { + static const char *attrnames[] = { "name", "value" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + if (attrvalues[0] != NULL) + m_current_part->m_featurelist.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1])))); + else + parse_error("Incomplete feature definition"); + } + + // + else if (strcmp(tagname, "dipswitch") == 0) + ; + else + unknown_tag(tagname); +} + + +//------------------------------------------------- +// parse_data_start - handle tag start within a +// dataarea or diskarea tag +//------------------------------------------------- + +void softlist_parser::parse_data_start(const char *tagname, const char **attributes) +{ + // get the current part; error if none + if (m_current_part == NULL) + { + parse_error("Tag %s found outside of part context", tagname); + return; + } + + // + if (strcmp(tagname, "rom") == 0) + { + static const char *attrnames[] = { "name", "size", "crc", "sha1", "offset", "value", "status", "loadflag" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + const char *name = attrvalues[0]; + const char *sizestr = attrvalues[1]; + const char *crc = attrvalues[2]; + const char *sha1 = attrvalues[3]; + const char *offsetstr = attrvalues[4]; + const char *value = attrvalues[5]; + const char *status = attrvalues[6]; + const char *loadflag = attrvalues[7]; + if (sizestr != NULL && offsetstr != NULL) + { + UINT32 length = strtol(sizestr, NULL, 0); + UINT32 offset = strtol(offsetstr, NULL, 0); + + if (loadflag != NULL && strcmp(loadflag, "reload") == 0) + add_rom_entry(NULL, NULL, offset, length, ROMENTRYTYPE_RELOAD | ROM_INHERITFLAGS); + else if (loadflag != NULL && strcmp(loadflag, "reload_plain") == 0) + add_rom_entry(NULL, NULL, offset, length, ROMENTRYTYPE_RELOAD); + else if (loadflag != NULL && strcmp(loadflag, "continue") == 0) + add_rom_entry(NULL, NULL, offset, length, ROMENTRYTYPE_CONTINUE | ROM_INHERITFLAGS); + else if (loadflag != NULL && strcmp(loadflag, "fill") == 0) + add_rom_entry(NULL, (const char *)(FPTR)(strtol(value, NULL, 0) & 0xff), offset, length, ROMENTRYTYPE_FILL); + else if (name != NULL) + { + bool baddump = (status != NULL && strcmp(status, "baddump") == 0); + bool nodump = (status != NULL && strcmp(status, "nodump") == 0); + + astring hashdata; + if (nodump) + { + hashdata.printf("%s", NO_DUMP); + if (crc != NULL && sha1 != NULL) + parse_error("No need for hash definition"); + } + else + { + if (crc != NULL && sha1 != NULL) + hashdata.printf("%c%s%c%s%s", hash_collection::HASH_CRC, crc, hash_collection::HASH_SHA1, sha1, (baddump ? BAD_DUMP : "")); + else + parse_error("Incomplete rom hash definition"); + } + + // Handle loadflag attribute + int romflags = 0; + if (loadflag != NULL && strcmp(loadflag, "load16_word_swap") == 0) + romflags = ROM_GROUPWORD | ROM_REVERSE; + else if (loadflag != NULL && strcmp(loadflag, "load16_byte") == 0) + romflags = ROM_SKIP(1); + else if (loadflag != NULL && strcmp(loadflag, "load32_word_swap") == 0) + romflags = ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2); + else if (loadflag != NULL && strcmp(loadflag, "load32_word") == 0) + romflags = ROM_GROUPWORD | ROM_SKIP(2); + else if (loadflag != NULL && strcmp(loadflag, "load32_byte") == 0) + romflags = ROM_SKIP(3); + + add_rom_entry(name, hashdata, offset, length, ROMENTRYTYPE_ROM | romflags); + } + else + parse_error("Rom name missing"); + } + else + parse_error("Incomplete rom definition"); + } + + // + else if (strcmp(tagname, "disk") == 0) + { + static const char *attrnames[] = { "name", "sha1", "status", "writeable" }; + const char *attrvalues[ARRAY_LENGTH(attrnames)] = { 0 }; + parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + + const char *name = attrvalues[0]; + const char *sha1 = attrvalues[1]; + const char *status = attrvalues[2]; + const char *writeablestr = attrvalues[3]; + if (name != NULL && sha1 != NULL) + { + bool baddump = (status != NULL && strcmp(status, "baddump") == 0); + bool nodump = (status != NULL && strcmp(status, "nodump" ) == 0); + bool writeable = (writeablestr != NULL && strcmp(writeablestr, "yes") == 0); + astring hashdata; + hashdata.printf( "%c%s%s", hash_collection::HASH_SHA1, sha1, (nodump ? NO_DUMP : (baddump ? BAD_DUMP : ""))); + + add_rom_entry(name, hashdata, 0, 0, ROMENTRYTYPE_ROM | (writeable ? DISK_READWRITE : DISK_READONLY)); + } + else if (status == NULL || strcmp(status, "nodump") != NULL) // a no_dump chd is not an incomplete entry + parse_error("Incomplete disk definition"); + } + + // + else if (strcmp(tagname, "dipvalue") == 0) + ; + else + unknown_tag(tagname); +} + + +//------------------------------------------------- +// parse_soft_end - handle end-of-tag post- +// processing within the tag +//------------------------------------------------- + +void softlist_parser::parse_soft_end(const char *tagname) +{ + assert(m_current_info != NULL); + + // + if (strcmp(tagname, "description") == 0) + m_current_info->m_longname = m_list.add_string(m_data_accum); + + // + else if (strcmp(tagname, "year") == 0) + m_current_info->m_year = m_list.add_string(m_data_accum); + + // + else if (strcmp(tagname, "publisher") == 0) + m_current_info->m_publisher = m_list.add_string(m_data_accum); + + // + else if (strcmp(tagname, "part") == 0) + { + // get the last part + assert(m_current_part != NULL); + if (m_current_part == NULL) + return; + + // was any dataarea/rom information encountered? if so, add a terminator + if (m_current_part->romdata() != NULL) + add_rom_entry(NULL, NULL, 0, 0, ROMENTRYTYPE_END); + + // get the info; if present, copy shared data (we assume name/value strings live + // in the string pool and don't need to be reallocated) + if (m_current_info != NULL) + for (feature_list_item *item = m_current_info->shared_info(); item != NULL; item = item->next()) + m_current_part->m_featurelist.append(*global_alloc(feature_list_item(item->name(), item->value()))); } - return result; } diff --git a/src/emu/softlist.h b/src/emu/softlist.h index c0d48b6ac88..5a32e67c1c8 100644 --- a/src/emu/softlist.h +++ b/src/emu/softlist.h @@ -11,10 +11,14 @@ #include "ui/menu.h" #include "expat.h" -#include "pool.h" +#include "cstrpool.h" +//************************************************************************** +// CONSTANTS +//************************************************************************** + #define SOFTWARE_SUPPORTED_YES 0 #define SOFTWARE_SUPPORTED_PARTIAL 1 #define SOFTWARE_SUPPORTED_NO 2 @@ -25,6 +29,12 @@ enum softlist_type SOFTWARE_LIST_COMPATIBLE_SYSTEM }; + + +//************************************************************************** +// MACROS +//************************************************************************** + #define MCFG_SOFTWARE_LIST_CONFIG(_list,_list_type) \ software_list_device::static_set_config(*device, _list, _list_type); @@ -52,10 +62,129 @@ enum softlist_type MCFG_DEVICE_REMOVE( _tag ) + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> feature_list_item + +// an item in a list of name/value pairs +class feature_list_item +{ + friend class simple_list; + +public: + // construction/destruction + feature_list_item(const char *name = NULL, const char *value = NULL) + : m_next(NULL), + m_name(name), + m_value(value) { } + + // getters + feature_list_item *next() const { return m_next; } + const char *name() const { return m_name; } + const char *value() const { return m_value; } + +private: + // internal state + feature_list_item * m_next; + const char * m_name; + const char * m_value; +}; + + +// ======================> software_part + +// a single part of a software item +class software_part +{ + friend class softlist_parser; + friend class simple_list; + +public: + // construction/destruction + software_part(software_info &info, const char *name = NULL, const char *interface = NULL); + + // getters + software_part *next() const { return m_next; } + software_info &info() const { return m_info; } + const char *name() const { return m_name; } + const char *interface() const { return m_interface; } + feature_list_item *featurelist() const { return m_featurelist.first(); } + rom_entry *romdata(int index = 0) { return (index < m_romdata.count()) ? &m_romdata[index] : NULL; } + + // helpers + bool is_compatible(const software_list_device &swlist) const; + bool matches_interface(const char *interface) const; + const char *feature(const char *feature_name) const; + +private: + // internal state + software_part * m_next; + software_info & m_info; + const char * m_name; + const char * m_interface; + simple_list m_featurelist; + dynamic_array m_romdata; +}; + + +// ======================> software_info + +// a single software item +class software_info +{ + friend class softlist_parser; + friend class simple_list; + +public: + // construction/destruction + software_info(software_list_device &list, const char *name, const char *parent, const char *supported); + + // getters + software_info *next() const { return m_next; } + software_list_device &list() const { return m_list; } + const char *shortname() const { return m_shortname; } + const char *longname() const { return m_longname; } + const char *parentname() const { return m_parentname; } + const char *year() const { return m_year; } + const char *publisher() const { return m_publisher; } + feature_list_item *other_info() const { return m_other_info.first(); } + feature_list_item *shared_info() const { return m_shared_info.first(); } + UINT32 supported() const { return m_supported; } + int num_parts() const { return m_partdata.count(); } + software_part *first_part() const { return m_partdata.first(); } + software_part *last_part() const { return m_partdata.last(); } + + // additional operations + software_part *find_part(const char *partname, const char *interface = NULL); + bool has_multiple_parts(const char *interface) const; + +private: + // internal state + software_info * m_next; + software_list_device & m_list; + UINT32 m_supported; + const char * m_shortname; + const char * m_longname; + const char * m_parentname; + const char * m_year; // Copyright year on title screen, actual release dates can be tracked in external resources + const char * m_publisher; + simple_list m_other_info; // Here we store info like developer, serial #, etc. which belong to the software entry as a whole + simple_list m_shared_info; // Here we store info like TV standard compatibility, or add-on requirements, etc. which get inherited + // by each part of this software entry (after loading these are stored in partdata->featurelist) + simple_list m_partdata; +}; + + // ======================> software_list_device +// device representing a software list class software_list_device : public device_t { + friend class softlist_parser; + public: // construction/destruction software_list_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); @@ -68,22 +197,48 @@ public: const char *list_name() const { return m_list_name; } softlist_type list_type() const { return m_list_type; } const char *filter() const { return m_filter; } + const char *filename() { return m_file.filename(); } - // validation helpers - static void reset_checked_lists() { s_checked_lists.reset(); } + // getters that may trigger a parse + const char *description() { if (!m_parsed) parse(); return m_description; } + bool valid() { if (!m_parsed) parse(); return m_infolist.count() > 0; } + const char *errors_string() { if (!m_parsed) parse(); return m_errors; } + + // operations + software_info *find(const char *look_for, software_info *prev = NULL); + software_info *first_software_info() { if (!m_parsed) parse(); return m_infolist.first(); } + void find_approx_matches(const char *name, int matches, software_info **list, const char *interface); + void release(); + + // string pool helpers + const char *add_string(const char *string) { return m_stringpool.add(string); } + bool string_pool_contains(const char *string) { return m_stringpool.contains(string); } + + // static helpers + static software_list_device *find_by_name(const machine_config &mconfig, const char *name); + static void display_matches(const machine_config &config, const char *interface, const char *name); protected: + // internal helpers + void parse(); + void internal_validity_check(validity_checker &valid) ATTR_COLD; + // device-level overrides virtual void device_start(); virtual void device_validity_check(validity_checker &valid) const ATTR_COLD; // configuration state - const char * m_list_name; + astring m_list_name; softlist_type m_list_type; const char * m_filter; - // static state - static tagmap_t s_checked_lists; + // internal state + bool m_parsed; + emu_file m_file; + const char * m_description; + astring m_errors; + simple_list m_infolist; + const_string_pool m_stringpool; }; @@ -94,116 +249,4 @@ extern const device_type SOFTWARE_LIST; typedef device_type_iterator<&device_creator, software_list_device> software_list_device_iterator; - -/********************************************************************* - - Internal structures and XML file handling - -*********************************************************************/ - -/* Replace this with list? */ -struct feature_list -{ - feature_list *next; - char *name; - char *value; -}; - -struct software_part -{ - const char *name; - const char *interface_; - feature_list *featurelist; - struct rom_entry *romdata; -}; - - -/* The software info struct holds basic software information. */ -struct software_info -{ - const char *shortname; - const char *longname; - const char *parentname; - const char *year; // Copyright year on title screen, actual release dates can be tracked in external resources - const char *publisher; - feature_list *other_info; // Here we store info like developer, serial #, etc. which belong to the software entry as a whole - feature_list *shared_info; // Here we store info like TV standard compatibility, or add-on requirements, etc. which get inherited - // by each part of this software entry (after loading these are stored in partdata->featurelist) - UINT32 supported; - int part_entries; - int current_part_entry; - software_part *partdata; - struct software_info *next; // Used internally -}; - - -enum softlist_parse_position -{ - POS_ROOT, - POS_MAIN, - POS_SOFT, - POS_PART, - POS_DATA -}; - - -struct parse_state -{ - XML_Parser parser; - int done; - - void (*error_proc)(const char *message); - void *param; - - enum softlist_parse_position pos; - char **text_dest; -}; - - -struct software_list -{ - emu_file *file; - object_pool *pool; - parse_state state; - const char *description; - struct software_info *software_info_list; - struct software_info *current_software_info; - software_info *softinfo; - const char *look_for; - int rom_entries; - int current_rom_entry; - void (*error_proc)(const char *message); - int list_entries; -}; - -/* Handling a software list */ -software_list *software_list_open(emu_options &options, const char *listname, int is_preload, void (*error_proc)(const char *message)); -void software_list_close(const software_list *swlist); -software_info *software_list_find(software_list *swlist, const char *look_for, software_info *prev); -const char *software_list_get_description(const software_list *swlist); -void software_list_parse(software_list *swlist, void (*error_proc)(const char *message), void *param); - -software_part *software_find_part(software_info *sw, const char *partname, const char *interface_); -software_part *software_part_next(software_part *part); - -const software_info *software_list_find(const software_list *swlist, const char *look_for, const software_info *prev); -const software_part *software_find_part(const software_info *sw, const char *partname, const char *interface_); -const software_part *software_part_next(const software_part *part); - -/* helpers */ -const char *software_get_clone(emu_options &options, char *swlist, const char *swname); -UINT32 software_get_support(emu_options &options, char *swlist, const char *swname); -const char *software_part_get_feature(const software_part *part, const char *feature_name); -void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart); - -bool load_software_part(emu_options &options, device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name, char**list_name); - -void software_display_matches(const machine_config &config, emu_options &options,const char *interface,const char *swname_bckp); - -const char *software_get_default_slot(const machine_config &config, emu_options &options, const device_image_interface *image, const char* default_card_slot); - -bool is_software_compatible(const software_part *swpart, const software_list_device *swlist); -bool swinfo_has_multiple_parts(const software_info *swinfo, const char *interface); - -bool softlist_contain_interface(const char *interface, const char *part_interface); #endif diff --git a/src/emu/sound/aica.c b/src/emu/sound/aica.c index 8a08654cdce..b3d31568c49 100644 --- a/src/emu/sound/aica.c +++ b/src/emu/sound/aica.c @@ -1600,6 +1600,11 @@ aica_device::aica_device(const machine_config &mconfig, const char *tag, device_ m_token = global_alloc_clear(aica_state); } +aica_device::~aica_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/emu/sound/aica.h b/src/emu/sound/aica.h index f47827169fe..3f5b2e029de 100644 --- a/src/emu/sound/aica.h +++ b/src/emu/sound/aica.h @@ -30,10 +30,10 @@ class aica_device : public device_t, { public: aica_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~aica_device() { global_free(m_token); } + ~aica_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct aica_state *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -44,7 +44,7 @@ protected: virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); private: // internal state - void *m_token; + struct aica_state *m_token; }; extern const device_type AICA; diff --git a/src/emu/sound/ay8910.c b/src/emu/sound/ay8910.c index 3245e9e4b04..e42d04af8b8 100644 --- a/src/emu/sound/ay8910.c +++ b/src/emu/sound/ay8910.c @@ -333,9 +333,8 @@ INLINE void build_3D_table(double rl, const ay_ym_param *par, const ay_ym_param int j, j1, j2, j3, e, indx; double rt, rw, n; double min = 10.0, max = 0.0; - double *temp; - temp = global_alloc_array(double, 8*32*32*32); + dynamic_array temp(8*32*32*32); for (e=0; e < 8; e++) for (j1=0; j1 < 32; j1++) @@ -381,8 +380,6 @@ INLINE void build_3D_table(double rl, const ay_ym_param *par, const ay_ym_param } /* for (e=0;e<16;e++) printf("%d %d\n",e<<10, tab[e<<10]); */ - - global_free(temp); } INLINE void build_single_table(double rl, const ay_ym_param *par, int normalize, INT32 *tab, int zero_is_off) diff --git a/src/emu/sound/discrete.h b/src/emu/sound/discrete.h index 775511cbf01..9efba1e95eb 100644 --- a/src/emu/sound/discrete.h +++ b/src/emu/sound/discrete.h @@ -3765,7 +3765,7 @@ public: m_arr = global_alloc_array_clear(_ElementType, m_allocated); } ~dynamic_array_t() { - global_free(m_arr); + global_free_array(m_arr); } _ElementType& operator [] (unsigned int index) const // get array item { diff --git a/src/emu/sound/dmadac.c b/src/emu/sound/dmadac.c index 9e9b7e8ab74..94c33ebb1c9 100644 --- a/src/emu/sound/dmadac.c +++ b/src/emu/sound/dmadac.c @@ -245,6 +245,11 @@ dmadac_sound_device::dmadac_sound_device(const machine_config &mconfig, const ch m_token = global_alloc_clear(dmadac_state); } +dmadac_sound_device::~dmadac_sound_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/emu/sound/dmadac.h b/src/emu/sound/dmadac.h index d7657504022..2c580d1487b 100644 --- a/src/emu/sound/dmadac.h +++ b/src/emu/sound/dmadac.h @@ -18,10 +18,10 @@ class dmadac_sound_device : public device_t, { public: dmadac_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~dmadac_sound_device() { global_free(m_token); } + ~dmadac_sound_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct dmadac_state *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -31,7 +31,7 @@ protected: virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); private: // internal state - void *m_token; + struct dmadac_state *m_token; }; extern const device_type DMADAC; diff --git a/src/emu/sound/mos6581.c b/src/emu/sound/mos6581.c index 8f71603d20a..62ac428a7c1 100644 --- a/src/emu/sound/mos6581.c +++ b/src/emu/sound/mos6581.c @@ -60,6 +60,10 @@ mos6581_device::mos6581_device(const machine_config &mconfig, const char *tag, d m_token = global_alloc_clear(SID6581_t); } +mos6581_device::~mos6581_device() +{ + global_free(m_token); +} //------------------------------------------------- // mos8580_device - constructor diff --git a/src/emu/sound/mos6581.h b/src/emu/sound/mos6581.h index a45a79d5a16..5cc70dfd1d9 100644 --- a/src/emu/sound/mos6581.h +++ b/src/emu/sound/mos6581.h @@ -56,7 +56,7 @@ class mos6581_device : public device_t, public: mos6581_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, UINT32 variant, const char *shortname, const char *source); mos6581_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~mos6581_device() { global_free(m_token); } + ~mos6581_device(); template void set_callbacks(_potx potx, _poty poty) { m_read_potx.set_callback(potx); diff --git a/src/emu/sound/scsp.c b/src/emu/sound/scsp.c index e8ffe42dbda..dc73795629a 100644 --- a/src/emu/sound/scsp.c +++ b/src/emu/sound/scsp.c @@ -1519,6 +1519,11 @@ scsp_device::scsp_device(const machine_config &mconfig, const char *tag, device_ m_token = global_alloc_clear(scsp_state); } +scsp_device::~scsp_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/emu/sound/scsp.h b/src/emu/sound/scsp.h index 9c493854833..dbac1bdd200 100644 --- a/src/emu/sound/scsp.h +++ b/src/emu/sound/scsp.h @@ -32,10 +32,10 @@ class scsp_device : public device_t, { public: scsp_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~scsp_device() { global_free(m_token); } + ~scsp_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct scsp_state *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -45,7 +45,7 @@ protected: virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); private: // internal state - void *m_token; + struct scsp_state *m_token; }; extern const device_type SCSP; diff --git a/src/emu/sound/spu.c b/src/emu/sound/spu.c index dd4e86358e6..e1a313fd327 100644 --- a/src/emu/sound/spu.c +++ b/src/emu/sound/spu.c @@ -473,7 +473,7 @@ public: *prev; }; - unsigned char *buffer; + dynamic_buffer buffer; unsigned int head, tail, in, @@ -494,14 +494,12 @@ public: marker_tail(NULL) { buffer_size=sector_size*num_sectors; - buffer=new unsigned char [buffer_size]; - memset(buffer,0,buffer_size); + buffer.resize_and_clear(buffer_size); } ~stream_buffer() { flush_all(); - global_free(buffer); } unsigned char *add_sector(const unsigned int sector) @@ -594,10 +592,10 @@ public: unsigned int get_bytes_in() const { return in; } unsigned int get_bytes_free() const { return buffer_size-in; } - unsigned char *get_tail_ptr() const { return buffer+tail; } - unsigned char *get_tail_ptr(const unsigned int offset) const + unsigned char *get_tail_ptr() { return &buffer[tail]; } + unsigned char *get_tail_ptr(const unsigned int offset) { - return buffer+((tail+offset)%buffer_size); + return &buffer[((tail+offset)%buffer_size)]; } unsigned int get_tail_offset() const { return tail; } void increment_tail(const unsigned int offset) @@ -1003,7 +1001,7 @@ void spu_device::device_start() save_item(NAME(xa_buffer->sector_size)); save_item(NAME(xa_buffer->num_sectors)); save_item(NAME(xa_buffer->buffer_size)); - save_pointer(NAME(xa_buffer->buffer), xa_sector_size*xa_buffer_sectors); + save_item(NAME(xa_buffer->buffer)); save_item(NAME(cdda_buffer->head)); save_item(NAME(cdda_buffer->tail)); @@ -1011,7 +1009,7 @@ void spu_device::device_start() save_item(NAME(cdda_buffer->sector_size)); save_item(NAME(cdda_buffer->num_sectors)); save_item(NAME(cdda_buffer->buffer_size)); - save_pointer(NAME(cdda_buffer->buffer), cdda_sector_size*cdda_buffer_sectors); + save_item(NAME(cdda_buffer->buffer)); } void spu_device::device_reset() @@ -1082,16 +1080,16 @@ void spu_device::device_post_load() void spu_device::device_stop() { for (unsigned int i=0; i<4; i++) - global_free(output_buf[i]); + global_free_array(output_buf[i]); kill_stream(); - global_free(spu_ram); + global_free_array(spu_ram); invalidate_cache(0,spu_ram_size); - global_free(cache); + global_free_array(cache); global_free(xa_buffer); global_free(cdda_buffer); - global_free(voice); + global_free_array(voice); } // // diff --git a/src/emu/sound/spureverb.c b/src/emu/sound/spureverb.c index ce24d40b550..c9a8407f12f 100644 --- a/src/emu/sound/spureverb.c +++ b/src/emu/sound/spureverb.c @@ -57,10 +57,10 @@ reverb::~reverb() for (int c=0; c<2; c++) { for (int f=0; f<4; f++) - global_free(y[c][f]); - global_free(x[c]); - global_free(ax[c]); - global_free(ay[c]); + global_free_array(y[c][f]); + global_free_array(x[c]); + global_free_array(ax[c]); + global_free_array(ay[c]); } } diff --git a/src/emu/sound/tiasound.c b/src/emu/sound/tiasound.c index 5e01a371a2b..5c4296371af 100644 --- a/src/emu/sound/tiasound.c +++ b/src/emu/sound/tiasound.c @@ -588,5 +588,5 @@ void *tia_sound_init(int clock, int sample_rate, int gain) void tia_sound_free(void *chip) { - global_free(chip); + global_free((struct tia *)chip); } diff --git a/src/emu/tilemap.c b/src/emu/tilemap.c index b4cfc80b958..4d65fd16c32 100644 --- a/src/emu/tilemap.c +++ b/src/emu/tilemap.c @@ -361,10 +361,6 @@ tilemap_t &tilemap_t::init(tilemap_manager &manager, gfxdecode_device &decoder, // populate logical <-> memory mappings m_mapper = mapper; - m_memory_to_logical = NULL; - m_max_logical_index = 0; - m_logical_to_memory = NULL; - m_max_memory_index = 0; // initialize tile information geters m_tile_get_info = tile_get_info; @@ -381,10 +377,8 @@ tilemap_t &tilemap_t::init(tilemap_manager &manager, gfxdecode_device &decoder, // reset scroll information m_scrollrows = 1; m_scrollcols = 1; - m_rowscroll.resize(m_height); - memset(&m_rowscroll[0], 0, m_height * sizeof(m_rowscroll[0])); - m_colscroll.resize(m_width); - memset(&m_colscroll[0], 0, m_width * sizeof(m_rowscroll[0])); + m_rowscroll.resize_and_clear(m_height); + m_colscroll.resize_and_clear(m_width); m_dx = 0; m_dx_flipped = 0; m_dy = 0; @@ -395,7 +389,6 @@ tilemap_t &tilemap_t::init(tilemap_manager &manager, gfxdecode_device &decoder, // allocate transparency mapping m_flagsmap.allocate(m_width, m_height); - m_tileflags = NULL; memset(m_pen_to_flags, 0, sizeof(m_pen_to_flags)); // create the initial mappings @@ -408,7 +401,6 @@ tilemap_t &tilemap_t::init(tilemap_manager &manager, gfxdecode_device &decoder, m_tileinfo.gfxnum = 0xff; // allocate transparency mapping data - m_tileflags = auto_alloc_array(machine(), UINT8, m_max_logical_index); for (int group = 0; group < TILEMAP_NUM_GROUPS; group++) map_pens_to_layer(group, 0, 0, TILEMAP_PIXEL_LAYER0); @@ -449,7 +441,7 @@ tilemap_t::~tilemap_t() void tilemap_t::mark_tile_dirty(tilemap_memory_index memindex) { // only mark if within range - if (memindex < m_max_memory_index) + if (memindex < m_memory_to_logical.count()) { // there may be no logical index for a given memory index logical_index logindex = m_memory_to_logical[memindex]; @@ -619,21 +611,22 @@ void tilemap_t::postload() void tilemap_t::mappings_create() { // compute the maximum logical index - m_max_logical_index = m_rows * m_cols; + int max_logical_index = m_rows * m_cols; // compute the maximum memory index - m_max_memory_index = 0; + int max_memory_index = 0; for (UINT32 row = 0; row < m_rows; row++) for (UINT32 col = 0; col < m_cols; col++) { tilemap_memory_index memindex = memory_index(col, row); - m_max_memory_index = MAX(m_max_memory_index, memindex); + max_memory_index = MAX(max_memory_index, memindex); } - m_max_memory_index++; + max_memory_index++; // allocate the necessary mappings - m_memory_to_logical = auto_alloc_array(machine(), logical_index, m_max_memory_index); - m_logical_to_memory = auto_alloc_array(machine(), tilemap_memory_index, m_max_logical_index); + m_memory_to_logical.resize(max_memory_index); + m_logical_to_memory.resize(max_logical_index); + m_tileflags.resize(max_logical_index); // update the mappings mappings_update(); @@ -648,10 +641,10 @@ void tilemap_t::mappings_create() void tilemap_t::mappings_update() { // initialize all the mappings to invalid values - memset(m_memory_to_logical, 0xff, m_max_memory_index * sizeof(m_memory_to_logical[0])); + memset(&m_memory_to_logical[0], 0xff, m_memory_to_logical.count() * sizeof(m_memory_to_logical[0])); // now iterate over all logical indexes and populate the memory index - for (logical_index logindex = 0; logindex < m_max_logical_index; logindex++) + for (logical_index logindex = 0; logindex < m_logical_to_memory.count(); logindex++) { UINT32 logical_col = logindex % m_cols; UINT32 logical_row = logindex / m_cols; @@ -685,7 +678,7 @@ inline void tilemap_t::realize_all_dirty_tiles() // flush the dirty status to all tiles if (m_all_tiles_dirty || gfx_elements_changed()) { - memset(m_tileflags, TILE_FLAG_DIRTY, m_max_logical_index); + memset(&m_tileflags[0], TILE_FLAG_DIRTY, m_tileflags.count()); m_all_tiles_dirty = false; m_gfx_used = 0; } @@ -1477,6 +1470,29 @@ tilemap_manager::tilemap_manager(running_machine &machine) } +//------------------------------------------------- +// ~tilemap_manager - destructor +//------------------------------------------------- + +tilemap_manager::~tilemap_manager() +{ + // detach all device tilemaps since they will be destroyed + // as subdevices elsewhere + bool found = true; + while (found) + { + found = false; + for (tilemap_t *tmap = m_tilemap_list.first(); tmap != NULL; tmap = tmap->next()) + if (tmap->device() != NULL) + { + found = true; + m_tilemap_list.detach(*tmap); + break; + } + } +} + + //------------------------------------------------- // set_flip_all - set a global flip for all the // tilemaps @@ -1501,14 +1517,14 @@ static const struct tilemap_t &tilemap_manager::create(gfxdecode_device &decoder, tilemap_get_info_delegate tile_get_info, tilemap_mapper_delegate mapper, int tilewidth, int tileheight, int cols, int rows, tilemap_t *allocated) { if (allocated == NULL) - allocated = auto_alloc(machine(), tilemap_t); + allocated = global_alloc(tilemap_t); return m_tilemap_list.append(allocated->init(*this, decoder, tile_get_info, mapper, tilewidth, tileheight, cols, rows)); } tilemap_t &tilemap_manager::create(gfxdecode_device &decoder, tilemap_get_info_delegate tile_get_info, tilemap_standard_mapper mapper, int tilewidth, int tileheight, int cols, int rows, tilemap_t *allocated) { if (allocated == NULL) - allocated = auto_alloc(machine(), tilemap_t); + allocated = global_alloc(tilemap_t); return m_tilemap_list.append(allocated->init(*this, decoder, tile_get_info, tilemap_mapper_delegate(s_standard_mappers[mapper].func, s_standard_mappers[mapper].name, machine().driver_data()), tilewidth, tileheight, cols, rows)); } diff --git a/src/emu/tilemap.h b/src/emu/tilemap.h index 3e6fbf9026b..9a28c2f3cab 100644 --- a/src/emu/tilemap.h +++ b/src/emu/tilemap.h @@ -629,10 +629,8 @@ private: // logical <-> memory mappings tilemap_mapper_delegate m_mapper; // callback to map a row/column to a memory index - logical_index * m_memory_to_logical; // map from memory index to logical index - logical_index m_max_logical_index; // maximum valid logical index - tilemap_memory_index * m_logical_to_memory; // map from logical index to memory index - tilemap_memory_index m_max_memory_index; // maximum valid memory index + dynamic_array m_memory_to_logical; // map from memory index to logical index + dynamic_array m_logical_to_memory; // map from logical index to memory index // callback to interpret video RAM for the tilemap tilemap_get_info_delegate m_tile_get_info; // callback to get information about a tile @@ -662,7 +660,7 @@ private: // transparency mapping bitmap_ind8 m_flagsmap; // per-pixel flags - UINT8 * m_tileflags; // per-tile flags + dynamic_array m_tileflags; // per-tile flags UINT8 m_pen_to_flags[MAX_PEN_TO_FLAGS * TILEMAP_NUM_GROUPS]; // mapping of pens to flags }; @@ -677,6 +675,7 @@ class tilemap_manager public: // construction/destuction tilemap_manager(running_machine &machine); + ~tilemap_manager(); // getters running_machine &machine() const { return m_machine; } diff --git a/src/emu/ui/filemngr.c b/src/emu/ui/filemngr.c index 2241e0ab37a..1650145277d 100644 --- a/src/emu/ui/filemngr.c +++ b/src/emu/ui/filemngr.c @@ -86,10 +86,10 @@ void ui_menu_file_manager::populate() if (image->part_entry() != NULL) { const software_part *tmp = image->part_entry(); - if (tmp->name != NULL) + if (tmp->name() != NULL) { tmp_name.cat(" ("); - tmp_name.cat(tmp->name); + tmp_name.cat(tmp->name()); // also check if this part has a specific part_id (e.g. "Map Disc", "Bonus Disc", etc.), and in case display it if (image->get_feature("part_id") != NULL) { diff --git a/src/emu/ui/filesel.c b/src/emu/ui/filesel.c index 6d20c9dfed4..975f66f339d 100644 --- a/src/emu/ui/filesel.c +++ b/src/emu/ui/filesel.c @@ -273,10 +273,10 @@ void ui_menu_file_create::populate() item_append("New Image Name:", new_image_name, 0, ITEMREF_NEW_IMAGE_NAME); // do we support multiple formats? - format = m_image->device_get_creatable_formats(); + format = m_image->formatlist(); if (ENABLE_FORMATS && (format != NULL)) { - item_append("Image Format:", m_current_format->m_description, 0, ITEMREF_FORMAT); + item_append("Image Format:", m_current_format->description(), 0, ITEMREF_FORMAT); m_current_format = format; } diff --git a/src/emu/ui/selgame.c b/src/emu/ui/selgame.c index c86620aa377..87deeaabf0e 100644 --- a/src/emu/ui/selgame.c +++ b/src/emu/ui/selgame.c @@ -27,9 +27,8 @@ // ctor //------------------------------------------------- -ui_menu_select_game::ui_menu_select_game(running_machine &machine, render_container *container, const char *gamename) : ui_menu(machine, container) +ui_menu_select_game::ui_menu_select_game(running_machine &machine, render_container *container, const char *gamename) : ui_menu(machine, container), m_driverlist(driver_list::total() + 1) { - m_driverlist = global_alloc_array(const game_driver *, driver_list::total()+1); build_driver_list(); if(gamename) strcpy(m_search, gamename); @@ -43,8 +42,6 @@ ui_menu_select_game::ui_menu_select_game(running_machine &machine, render_contai ui_menu_select_game::~ui_menu_select_game() { - global_free(m_drivlist); - global_free(m_driverlist); } @@ -57,7 +54,7 @@ ui_menu_select_game::~ui_menu_select_game() void ui_menu_select_game::build_driver_list() { // start with an empty list - m_drivlist = global_alloc(driver_enumerator(machine().options())); + m_drivlist.reset(global_alloc(driver_enumerator(machine().options()))); m_drivlist->exclude_all(); // open a path to the ROMs and find them in the array diff --git a/src/emu/ui/selgame.h b/src/emu/ui/selgame.h index b1d9b2111dc..94e6f37d43b 100644 --- a/src/emu/ui/selgame.h +++ b/src/emu/ui/selgame.h @@ -35,8 +35,8 @@ private: UINT8 m_rerandomize; char m_search[40]; int m_matchlist[VISIBLE_GAMES_IN_LIST]; - const game_driver ** m_driverlist; - driver_enumerator * m_drivlist; + dynamic_array m_driverlist; + auto_pointer m_drivlist; // internal methods void build_driver_list(); diff --git a/src/emu/ui/swlist.c b/src/emu/ui/swlist.c index 454ebb06a97..3eaf3908830 100644 --- a/src/emu/ui/swlist.c +++ b/src/emu/ui/swlist.c @@ -56,23 +56,19 @@ ui_menu_software_parts::~ui_menu_software_parts() void ui_menu_software_parts::populate() { - for (const software_part *swpart = software_find_part(m_info, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) + for (const software_part *swpart = m_info->first_part(); swpart != NULL; swpart = swpart->next()) { - if (softlist_contain_interface(m_interface, swpart->interface_)) + if (swpart->matches_interface(m_interface)) { software_part_menu_entry *entry = (software_part_menu_entry *) m_pool_alloc(sizeof(*entry)); // check if the available parts have specific part_id to be displayed (e.g. "Map Disc", "Bonus Disc", etc.) // if not, we simply display "part_name"; if yes we display "part_name (part_id)" - astring menu_part_name(swpart->name); - if (software_part_get_feature(swpart, "part_id") != NULL) - { - menu_part_name.cat(" ("); - menu_part_name.cat(software_part_get_feature(swpart, "part_id")); - menu_part_name.cat(")"); - } + astring menu_part_name(swpart->name()); + if (swpart->feature("part_id") != NULL) + menu_part_name.cat(" (").cat(swpart->feature("part_id")).cat(")"); entry->type = T_ENTRY; entry->part = swpart; - item_append(m_info->shortname, menu_part_name.cstr(), 0, entry); + item_append(m_info->shortname(), menu_part_name.cstr(), 0, entry); } } @@ -113,7 +109,7 @@ void ui_menu_software_parts::handle() // ctor //------------------------------------------------- -ui_menu_software_list::ui_menu_software_list(running_machine &machine, render_container *container, const software_list_device *swlist, const char *interface, astring &result) +ui_menu_software_list::ui_menu_software_list(running_machine &machine, render_container *container, software_list_device *swlist, const char *interface, astring &result) : ui_menu(machine, container), m_result(result) { m_swlist = swlist; @@ -181,17 +177,17 @@ ui_menu_software_list::entry_info *ui_menu_software_list::append_software_entry( bool entry_updated = FALSE; // check if at least one of the parts has the correct interface and add a menu entry only in this case - for (const software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) + for (const software_part *swpart = swinfo->first_part(); swpart != NULL; swpart = swpart->next()) { - if ((softlist_contain_interface(m_interface, swpart->interface_)) && is_software_compatible(swpart, m_swlist)) + if (swpart->matches_interface(m_interface) && swpart->is_compatible(*m_swlist)) { entry_updated = TRUE; // allocate a new entry entry = (entry_info *) m_pool_alloc(sizeof(*entry)); memset(entry, 0, sizeof(*entry)); - entry->short_name = pool_strdup(swinfo->shortname); - entry->long_name = pool_strdup(swinfo->longname); + entry->short_name = pool_strdup(swinfo->shortname()); + entry->long_name = pool_strdup(swinfo->longname()); break; } } @@ -219,16 +215,9 @@ ui_menu_software_list::entry_info *ui_menu_software_list::append_software_entry( void ui_menu_software_list::populate() { - const software_list *list = software_list_open(machine().options(), m_swlist->list_name(), false, NULL); - // build up the list of entries for the menu - if (list) - { - for (const software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) - append_software_entry(swinfo); - - software_list_close(list); - } + for (const software_info *swinfo = m_swlist->first_software_info(); swinfo != NULL; swinfo = swinfo->next()) + append_software_entry(swinfo); // add an entry to change ordering item_append("Switch Item Ordering", NULL, 0, (void *)1); @@ -378,7 +367,7 @@ void ui_menu_software_list::handle() // ctor //------------------------------------------------- -ui_menu_software::ui_menu_software(running_machine &machine, render_container *container, const char *interface, const software_list_device **result) +ui_menu_software::ui_menu_software(running_machine &machine, render_container *container, const char *interface, software_list_device **result) : ui_menu(machine, container) { m_interface = interface; @@ -401,68 +390,39 @@ ui_menu_software::~ui_menu_software() void ui_menu_software::populate() { - bool haveCompatible = false; + bool have_compatible = false; // Add original software lists for this system software_list_device_iterator iter(machine().config().root_device()); - for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) - { - if (swlist->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) - { - const software_list *list = software_list_open(machine().options(), swlist->list_name(), false, NULL); - - if (list && m_interface) + for (software_list_device *swlistdev = iter.first(); swlistdev != NULL; swlistdev = iter.next()) + if (swlistdev->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) + if (swlistdev->first_software_info() != NULL && m_interface != NULL) { bool found = false; - for (const software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) - { - const software_part *part = software_find_part(swinfo, NULL, NULL); - if (softlist_contain_interface(m_interface, part->interface_)) + for (const software_info *swinfo = swlistdev->first_software_info(); swinfo != NULL; swinfo = swinfo->next()) + if (swinfo->first_part()->matches_interface(m_interface)) found = true; - } if (found) - { - item_append(list->description, NULL, 0, (void *)swlist); - } - - software_list_close(list); + item_append(swlistdev->description(), NULL, 0, (void *)swlistdev); } - } - } // add compatible software lists for this system - for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) - { - if (swlist->list_type() == SOFTWARE_LIST_COMPATIBLE_SYSTEM) - { - const software_list *list = software_list_open(machine().options(), swlist->list_name(), false, NULL); - - if (list && m_interface) + for (software_list_device *swlistdev = iter.first(); swlistdev != NULL; swlistdev = iter.next()) + if (swlistdev->list_type() == SOFTWARE_LIST_COMPATIBLE_SYSTEM) + if (swlistdev->first_software_info() != NULL && m_interface != NULL) { bool found = false; - for (const software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) - { - const software_part *part = software_find_part(swinfo, NULL, NULL); - if (softlist_contain_interface(m_interface, part->interface_)) - { + for (const software_info *swinfo = swlistdev->first_software_info(); swinfo != NULL; swinfo = swinfo->next()) + if (swinfo->first_part()->matches_interface(m_interface)) found = true; - } - } - if (found) { - if (!haveCompatible) + if (!have_compatible) item_append("[compatible lists]", NULL, MENU_FLAG_DISABLE, NULL); - - item_append(list->description, NULL, 0, (void *)swlist); + item_append(swlistdev->description(), NULL, 0, (void *)swlistdev); } - - haveCompatible = true; - software_list_close(list); + have_compatible = true; } - } - } - } diff --git a/src/emu/ui/swlist.h b/src/emu/ui/swlist.h index e5caaade381..98c5de0d860 100644 --- a/src/emu/ui/swlist.h +++ b/src/emu/ui/swlist.h @@ -41,7 +41,7 @@ private: class ui_menu_software_list : public ui_menu { public: - ui_menu_software_list(running_machine &machine, render_container *container, const software_list_device *swlist, const char *interface, astring &result); + ui_menu_software_list(running_machine &machine, render_container *container, software_list_device *swlist, const char *interface, astring &result); virtual ~ui_menu_software_list(); virtual void populate(); virtual void handle(); @@ -55,7 +55,7 @@ private: }; // variables - const software_list_device * m_swlist; // currently selected list + software_list_device * m_swlist; // currently selected list const char * m_interface; astring & m_result; entry_info * m_entrylist; @@ -72,14 +72,14 @@ private: class ui_menu_software : public ui_menu { public: - ui_menu_software(running_machine &machine, render_container *container, const char *interface, const software_list_device **result); + ui_menu_software(running_machine &machine, render_container *container, const char *interface, software_list_device **result); virtual ~ui_menu_software(); virtual void populate(); virtual void handle(); private: const char * m_interface; - const software_list_device ** m_result; + software_list_device ** m_result; }; #endif /* __UI_SWLIST_H__ */ diff --git a/src/emu/validity.c b/src/emu/validity.c index d1c2f20b387..66650201e99 100644 --- a/src/emu/validity.c +++ b/src/emu/validity.c @@ -237,9 +237,7 @@ void validity_checker::validate_begin() // reset internal state m_errors = 0; m_warnings = 0; - - // reset some special case state - software_list_device::reset_checked_lists(); + m_already_checked.reset(); } @@ -1047,7 +1045,6 @@ void validity_checker::validate_devices() } const_cast(*m_current_config).device_remove(&m_current_config->root_device(), temptag.cstr()); - global_free(dev); } } diff --git a/src/emu/validity.h b/src/emu/validity.h index f1d98cde34e..d59c0003625 100644 --- a/src/emu/validity.h +++ b/src/emu/validity.h @@ -48,6 +48,9 @@ public: void validate_tag(const char *tag); int region_length(const char *tag) { return m_region_map.find(tag); } + // generic registry of already-checked stuff + bool already_checked(const char *string) { return (m_already_checked.add(string, 1, false) == TMERR_DUPLICATE); } + private: // internal helpers const char *ioport_string_from_index(UINT32 index); @@ -97,6 +100,7 @@ private: const device_t * m_current_device; const char * m_current_ioport; int_map m_region_map; + tagmap_t m_already_checked; // callbacks output_delegate m_saved_error_output; diff --git a/src/emu/video.c b/src/emu/video.c index 49a7c02ea22..576495e0ded 100644 --- a/src/emu/video.c +++ b/src/emu/video.c @@ -101,7 +101,6 @@ video_manager::video_manager(running_machine &machine) m_snap_native(true), m_snap_width(0), m_snap_height(0), - m_mngfile(NULL), m_avifile(NULL), m_movie_frame_period(attotime::zero), m_movie_next_frame_time(attotime::zero), @@ -422,7 +421,7 @@ void video_manager::begin_recording(const char *name, movie_format format) else if (format == MF_MNG) { // create a new movie file and start recording - m_mngfile = auto_alloc(machine(), emu_file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)); + m_mngfile.reset(global_alloc(emu_file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS))); file_error filerr; if (name != NULL) filerr = m_mngfile->open(name); @@ -443,8 +442,7 @@ void video_manager::begin_recording(const char *name, movie_format format) else { mame_printf_error("Error creating MNG\n"); - global_free(m_mngfile); - m_mngfile = NULL; + m_mngfile.reset(); } } } @@ -467,8 +465,7 @@ void video_manager::end_recording() if (m_mngfile != NULL) { mng_capture_stop(*m_mngfile); - auto_free(machine(), m_mngfile); - m_mngfile = NULL; + m_mngfile.reset(); } // reset the state diff --git a/src/emu/video.h b/src/emu/video.h index bfb73b2b46c..c525f066b61 100644 --- a/src/emu/video.h +++ b/src/emu/video.h @@ -166,7 +166,7 @@ private: INT32 m_snap_height; // height of snapshots (0 == auto) // movie recording - emu_file * m_mngfile; // handle to the open movie file + auto_pointer m_mngfile; // handle to the open movie file avi_file * m_avifile; // handle to the open movie file attotime m_movie_frame_period; // period of a single movie frame attotime m_movie_next_frame_time; // time of next frame diff --git a/src/emu/video/resnet.c b/src/emu/video/resnet.c index 863541f00ba..5a00e07f01d 100644 --- a/src/emu/video/resnet.c +++ b/src/emu/video/resnet.c @@ -242,8 +242,6 @@ double compute_resistor_net_outputs( int rescount[MAX_NETS]; /* number of resistors in each of the nets */ double r[MAX_NETS][MAX_RES_PER_NET]; /* resistances */ - double *o; /* calulated outputs */ - double *os; /* calulated, scaled outputss */ int r_pd[MAX_NETS]; /* pulldown resistances */ int r_pu[MAX_NETS]; /* pullup resistances */ @@ -258,8 +256,8 @@ double compute_resistor_net_outputs( /* parse input parameters */ - o = global_alloc_array(double, (1< o((1< os((1<rgb[channel].vBias; - double vOH = di->vOH; - double vOL = di->vOL; - double minout = di->rgb[channel].minout; - double cut = di->rgb[channel].cut; - double vcc = di->vcc; + double vBias = di.rgb[channel].vBias; + double vOH = di.vOH; + double vOL = di.vOL; + double minout = di.rgb[channel].minout; + double cut = di.rgb[channel].cut; + double vcc = di.vcc; double ttlHRes = 0; - double rGnd = di->rgb[channel].rGnd; - UINT8 OpenCol = di->OpenCol; + double rGnd = di.rgb[channel].rGnd; + UINT8 OpenCol = di.OpenCol; /* Global options */ - switch (di->options & RES_NET_AMP_MASK) + switch (di.options & RES_NET_AMP_MASK) { case RES_NET_AMP_USE_GLOBAL: /* just ignore */ @@ -492,7 +488,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) fatalerror("compute_res_net: Unknown amplifier type\n"); } - switch (di->options & RES_NET_VCC_MASK) + switch (di.options & RES_NET_VCC_MASK) { case RES_NET_VCC_5V: vcc = 5.0; @@ -504,7 +500,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) fatalerror("compute_res_net: Unknown vcc type\n"); } - switch (di->options & RES_NET_VBIAS_MASK) + switch (di.options & RES_NET_VBIAS_MASK) { case RES_NET_VBIAS_USE_GLOBAL: /* just ignore */ @@ -522,7 +518,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) fatalerror("compute_res_net: Unknown vcc type\n"); } - switch (di->options & RES_NET_VIN_MASK) + switch (di.options & RES_NET_VIN_MASK) { case RES_NET_VIN_OPEN_COL: OpenCol = 1; @@ -551,7 +547,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) /* Per channel options */ - switch (di->rgb[channel].options & RES_NET_AMP_MASK) + switch (di.rgb[channel].options & RES_NET_AMP_MASK) { case RES_NET_AMP_USE_GLOBAL: /* use global defaults */ @@ -575,7 +571,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) fatalerror("compute_res_net: Unknown amplifier type\n"); } - switch (di->rgb[channel].options & RES_NET_VBIAS_MASK) + switch (di.rgb[channel].options & RES_NET_VBIAS_MASK) { case RES_NET_VBIAS_USE_GLOBAL: /* use global defaults */ @@ -595,7 +591,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) /* Input impedances */ - switch (di->options & RES_NET_MONITOR_MASK) + switch (di.options & RES_NET_MONITOR_MASK) { case RES_NET_MONITOR_INVERT: case RES_NET_MONITOR_SANYO_EZV20: @@ -611,29 +607,29 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) /* compute here - pass a / low inputs */ - for (i=0; irgb[channel].num; i++) + for (i=0; i> i) & 1); - if (di->rgb[channel].R[i] != 0.0 && !level) + if (di.rgb[channel].R[i] != 0.0 && !level) { if (OpenCol) { - rTotal += 1.0 / di->rgb[channel].R[i]; - v += vOL / di->rgb[channel].R[i]; + rTotal += 1.0 / di.rgb[channel].R[i]; + v += vOL / di.rgb[channel].R[i]; } else { - rTotal += 1.0 / di->rgb[channel].R[i]; - v += vOL / di->rgb[channel].R[i]; + rTotal += 1.0 / di.rgb[channel].R[i]; + v += vOL / di.rgb[channel].R[i]; } } } /* Mix in rbias and rgnd */ - if ( di->rgb[channel].rBias != 0.0 ) + if ( di.rgb[channel].rBias != 0.0 ) { - rTotal += 1.0 / di->rgb[channel].rBias; - v += vBias / di->rgb[channel].rBias; + rTotal += 1.0 / di.rgb[channel].rBias; + v += vBias / di.rgb[channel].rBias; } if (rGnd != 0.0) rTotal += 1.0 / rGnd; @@ -643,7 +639,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) * There will be now current into/from the TTL gate */ - if ( (di->options & RES_NET_VIN_MASK)==RES_NET_VIN_TTL_OUT) + if ( (di.options & RES_NET_VIN_MASK)==RES_NET_VIN_TTL_OUT) { if (v / rTotal > vOH) OpenCol = 1; @@ -651,10 +647,10 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) /* Second pass - high inputs */ - for (i=0; irgb[channel].num; i++) + for (i=0; i> i) & 1); - if (di->rgb[channel].R[i] != 0.0 && level) + if (di.rgb[channel].R[i] != 0.0 && level) { if (OpenCol) { @@ -663,8 +659,8 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) } else { - rTotal += 1.0 / (di->rgb[channel].R[i] + ttlHRes); - v += vOH / (di->rgb[channel].R[i] + ttlHRes); + rTotal += 1.0 / (di.rgb[channel].R[i] + ttlHRes); + v += vOH / (di.rgb[channel].R[i] + ttlHRes); } } } @@ -673,7 +669,7 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) v *= rTotal; v = MAX(minout, v - cut); - switch (di->options & RES_NET_MONITOR_MASK) + switch (di.options & RES_NET_MONITOR_MASK) { case RES_NET_MONITOR_INVERT: v = vcc - v; @@ -693,30 +689,28 @@ int compute_res_net(int inputs, int channel, const res_net_info *di) return (int) (v * 255 / vcc + 0.4); } -rgb_t *compute_res_net_all(running_machine &machine, const UINT8 *prom, const res_net_decode_info *rdi, const res_net_info *di) +void compute_res_net_all(dynamic_array &rgb, const UINT8 *prom, const res_net_decode_info &rdi, const res_net_info &di) { UINT8 r,g,b; int i,j,k; - rgb_t *rgb; - rgb = auto_alloc_array(machine, rgb_t, rdi->end - rdi->start + 1); - for (i=rdi->start; i<=rdi->end; i++) + rgb.resize(rdi.end - rdi.start + 1); + for (i=rdi.start; i<=rdi.end; i++) { UINT8 t[3] = {0,0,0}; int s; - for (j=0;jnumcomp;j++) + for (j=0;jshift[3*j+k]; + s = rdi.shift[3*j+k]; if (s>0) - t[k] = t[k] | ( (prom[i+rdi->offset[3*j+k]]>>s) & rdi->mask[3*j+k]); + t[k] = t[k] | ( (prom[i+rdi.offset[3*j+k]]>>s) & rdi.mask[3*j+k]); else - t[k] = t[k] | ( (prom[i+rdi->offset[3*j+k]]<<(0-s)) & rdi->mask[3*j+k]); + t[k] = t[k] | ( (prom[i+rdi.offset[3*j+k]]<<(0-s)) & rdi.mask[3*j+k]); } r = compute_res_net(t[0], RES_NET_CHAN_RED, di); g = compute_res_net(t[1], RES_NET_CHAN_GREEN, di); b = compute_res_net(t[2], RES_NET_CHAN_BLUE, di); - rgb[i-rdi->start] = rgb_t(r,g,b); + rgb[i-rdi.start] = rgb_t(r,g,b); } - return rgb; } diff --git a/src/emu/video/resnet.h b/src/emu/video/resnet.h index 9c76d609a9d..3dae2bbb11f 100644 --- a/src/emu/video/resnet.h +++ b/src/emu/video/resnet.h @@ -153,11 +153,11 @@ struct res_net_decode_info { /* return a single value for one channel */ -int compute_res_net(int inputs, int channel, const res_net_info *di); +int compute_res_net(int inputs, int channel, const res_net_info &di); /* compute all values */ -rgb_t *compute_res_net_all(running_machine &machine, const UINT8 *prom, const res_net_decode_info *rdi, const res_net_info *di); +void compute_res_net_all(dynamic_array &rgb, const UINT8 *prom, const res_net_decode_info &rdi, const res_net_info &di); /* legacy interface */ diff --git a/src/emu/video/voodoo.c b/src/emu/video/voodoo.c index 7187ae621d1..55c321fade4 100644 --- a/src/emu/video/voodoo.c +++ b/src/emu/video/voodoo.c @@ -5709,6 +5709,11 @@ voodoo_device::voodoo_device(const machine_config &mconfig, device_type type, co m_token = global_alloc_clear(voodoo_state); } +voodoo_device::~voodoo_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/emu/video/voodoo.h b/src/emu/video/voodoo.h index 5e0b13bf886..e7a2e6d9f2f 100644 --- a/src/emu/video/voodoo.h +++ b/src/emu/video/voodoo.h @@ -97,10 +97,10 @@ class voodoo_device : public device_t { public: voodoo_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); - ~voodoo_device() { global_free(m_token); } + ~voodoo_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct voodoo_state *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -108,7 +108,7 @@ protected: virtual void device_reset(); private: // internal state - void *m_token; + struct voodoo_state *m_token; }; class voodoo_1_device : public voodoo_device diff --git a/src/lib/formats/cassimg.c b/src/lib/formats/cassimg.c index 1594cf6121c..0b428272ed5 100644 --- a/src/lib/formats/cassimg.c +++ b/src/lib/formats/cassimg.c @@ -10,7 +10,6 @@ #include #include "imageutl.h" -#include "pool.h" #include "cassimg.h" @@ -84,16 +83,11 @@ static cassette_image *cassette_init(const struct CassetteFormat *format, void * { cassette_image *cassette; - cassette = (cassette_image *)malloc(sizeof(cassette_image)); - if (!cassette) - return NULL; - - memset(cassette, 0, sizeof(*cassette)); + cassette = global_alloc_clear(cassette_image); cassette->format = format; cassette->io.file = file; cassette->io.procs = procs; cassette->flags = flags; - cassette->pool = pool_alloc_lib(NULL); return cassette; } @@ -282,8 +276,9 @@ void cassette_close(cassette_image *cassette) { if ((cassette->flags & CASSETTE_FLAG_DIRTY) && (cassette->flags & CASSETTE_FLAG_SAVEONEXIT)) cassette_save(cassette); - pool_free_lib(cassette->pool); - free(cassette); + for (int i = 0; i < cassette->blocks.count(); i++) + global_free(cassette->blocks[i]); + global_free(cassette); } } @@ -375,59 +370,26 @@ static casserr_t compute_manipulation_ranges(cassette_image *cassette, int chann -static casserr_t lookup_sample(cassette_image *cassette, int channel, size_t sample, int allocate, INT32 **ptr) +static casserr_t lookup_sample(cassette_image *cassette, int channel, size_t sample, INT32 **ptr) { - size_t sample_block; - size_t sample_index; - size_t sample_size; - size_t new_block_count; - size_t new_block_sample_count; - INT32 *new_block; - struct sample_block *new_blocks; - struct sample_block *block; - *ptr = NULL; - sample_block = (sample / SAMPLES_PER_BLOCK) * cassette->channels + channel; - sample_index = sample % SAMPLES_PER_BLOCK; - sample_size = sizeof(block->block[0]); + size_t sample_blocknum = (sample / SAMPLES_PER_BLOCK) * cassette->channels + channel; + size_t sample_index = sample % SAMPLES_PER_BLOCK; /* is this block beyond the edge of our waveform? */ - if (sample_block >= cassette->block_count) - { - if (!allocate) - return CASSETTE_ERROR_SUCCESS; + if (sample_blocknum >= cassette->blocks.count()) + cassette->blocks.resize_keep_and_clear_new(sample_blocknum + 1); + + if (cassette->blocks[sample_blocknum] == NULL) + cassette->blocks[sample_blocknum] = global_alloc(sample_block); - /* allocate new blocks */ - new_block_count = sample_block + 1; - new_blocks = (struct sample_block *)pool_realloc_lib(cassette->pool, cassette->blocks, new_block_count * sizeof(cassette->blocks[0])); - if (!new_blocks) - return CASSETTE_ERROR_OUTOFMEMORY; - - cassette->blocks = new_blocks; - memset(&cassette->blocks[cassette->block_count], 0, (new_block_count - cassette->block_count) * sizeof(cassette->blocks[0])); - cassette->block_count = new_block_count; - } - - block = &cassette->blocks[sample_block]; + sample_block &block = *cassette->blocks[sample_blocknum]; /* is this sample access off the current block? */ - if (sample_index >= block->sample_count) - { - if (!allocate) - return CASSETTE_ERROR_SUCCESS; + if (sample_index >= block.count()) + block.resize_keep_and_clear_new(SAMPLES_PER_BLOCK); - new_block_sample_count = SAMPLES_PER_BLOCK; - - new_block = (INT32*)pool_realloc_lib(cassette->pool, block->block, new_block_sample_count * sample_size); - if (!new_block) - return CASSETTE_ERROR_OUTOFMEMORY; - - block->block = new_block; - memset(&block->block[block->sample_count], 0, (new_block_sample_count - block->sample_count) * sample_size); - block->sample_count = new_block_sample_count; - } - - *ptr = &block->block[sample_index]; + *ptr = &block[sample_index]; return CASSETTE_ERROR_SUCCESS; } @@ -467,7 +429,7 @@ casserr_t cassette_get_samples(cassette_image *cassette, int channel, /* find the sample that we are putting */ d = map_double(ranges.sample_last + 1 - ranges.sample_first, 0, sample_count, sample_index) + ranges.sample_first; cassette_sample_index = (size_t) d; - err = lookup_sample(cassette, channel, cassette_sample_index, TRUE, (INT32 **) &source_ptr); + err = lookup_sample(cassette, channel, cassette_sample_index, (INT32 **) &source_ptr); if (err) return err; @@ -573,7 +535,7 @@ casserr_t cassette_put_samples(cassette_image *cassette, int channel, for (channel = ranges.channel_first; channel <= ranges.channel_last; channel++) { /* find the sample that we are putting */ - err = lookup_sample(cassette, channel, sample_index, TRUE, &dest_ptr); + err = lookup_sample(cassette, channel, sample_index, &dest_ptr); if (err) return err; *dest_ptr = dest_value; diff --git a/src/lib/formats/cassimg.h b/src/lib/formats/cassimg.h index 93e55a5d601..bd7fc68db93 100644 --- a/src/lib/formats/cassimg.h +++ b/src/lib/formats/cassimg.h @@ -10,7 +10,7 @@ #define CASSIMG_H #include "osdcore.h" -#include "pool.h" +#include "coretmpl.h" #include "ioprocs.h" #ifndef LOG_FORMATS @@ -69,11 +69,7 @@ typedef enum } casserr_t; -struct sample_block -{ - INT32 *block; - size_t sample_count; -}; +typedef dynamic_array sample_block; struct CassetteOptions { @@ -94,14 +90,12 @@ struct cassette_image { const struct CassetteFormat *format; struct io_generic io; - object_pool *pool; int channels; int flags; UINT32 sample_frequency; - struct sample_block *blocks; - size_t block_count; + dynamic_array blocks; size_t sample_count; }; diff --git a/src/lib/formats/cbm_crt.c b/src/lib/formats/cbm_crt.c index 54b127c5af5..fd44e061376 100644 --- a/src/lib/formats/cbm_crt.c +++ b/src/lib/formats/cbm_crt.c @@ -90,7 +90,7 @@ static const char * CRT_C64_SLOT_NAMES[_CRT_C64_COUNT] = // cbm_crt_get_card - get slot interface card //------------------------------------------------- -const char * cbm_crt_get_card(core_file *file) +void cbm_crt_get_card(astring &result, core_file *file) { // read the header cbm_crt_header header; @@ -100,10 +100,11 @@ const char * cbm_crt_get_card(core_file *file) { UINT16 hardware = pick_integer_be(header.hardware, 0, 2); - return CRT_C64_SLOT_NAMES[hardware]; + result.cpy(CRT_C64_SLOT_NAMES[hardware]); + return; } - return NULL; + result.reset(); } diff --git a/src/lib/formats/cbm_crt.h b/src/lib/formats/cbm_crt.h index f099daaf818..bfb8732442c 100644 --- a/src/lib/formats/cbm_crt.h +++ b/src/lib/formats/cbm_crt.h @@ -136,7 +136,7 @@ struct cbm_crt_chip // FUNCTION PROTOTYPES //************************************************************************** -const char * cbm_crt_get_card(core_file *file); +void cbm_crt_get_card(astring &result, core_file *file); bool cbm_crt_read_header(core_file* file, size_t *roml_size, size_t *romh_size, int *exrom, int *game); bool cbm_crt_read_data(core_file* file, UINT8 *roml, UINT8 *romh); diff --git a/src/lib/formats/ccvf_dsk.c b/src/lib/formats/ccvf_dsk.c index 0895e1ee4d6..7c9c0cd274f 100644 --- a/src/lib/formats/ccvf_dsk.c +++ b/src/lib/formats/ccvf_dsk.c @@ -90,11 +90,11 @@ bool ccvf_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) const format &f = formats[0]; UINT64 size = io_generic_size(io); - UINT8 *img = global_alloc_array(UINT8, size); + dynamic_buffer img(size); io_generic_read(io, img, 0, size); - astring ccvf = astring((const char *)img, size); - UINT8 *bytes = global_alloc_array(UINT8, 78720); + astring ccvf = astring((const char *)&img[0], size); + dynamic_buffer bytes(78720); int start = 0, end = 0; astring line; @@ -119,7 +119,7 @@ bool ccvf_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) int total_size = 200000000/f.cell_size; for(int track=0; track < f.track_count; track++) { - UINT32 *buffer = global_alloc_array_clear(UINT32, total_size); + dynamic_array buffer(total_size); int offset = 0; for (int i=0; i<1920 && posset_variant(f.variant); - global_free(bytes); - global_free(img); - return true; } diff --git a/src/lib/formats/d64_dsk.c b/src/lib/formats/d64_dsk.c index c0ef28283cf..0d6295e2c38 100644 --- a/src/lib/formats/d64_dsk.c +++ b/src/lib/formats/d64_dsk.c @@ -189,14 +189,13 @@ bool d64_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) const format &f = formats[type]; UINT64 size = io_generic_size(io); - UINT8 *img; + dynamic_buffer img; if(size == (UINT32)f.sector_count*f.sector_base_size) { - img = global_alloc_array(UINT8, size + f.sector_count); - memset(&img[size], ERROR_00, f.sector_count); + img.resize_and_clear(size + f.sector_count, ERROR_00); } else { - img = global_alloc_array(UINT8, size); + img.resize(size); } io_generic_read(io, img, 0, size); @@ -235,8 +234,6 @@ bool d64_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) } } - global_free(img); - image->set_variant(f.variant); return true; diff --git a/src/lib/formats/dfi_dsk.c b/src/lib/formats/dfi_dsk.c index 36e26359cdf..28a774c906e 100644 --- a/src/lib/formats/dfi_dsk.c +++ b/src/lib/formats/dfi_dsk.c @@ -68,8 +68,7 @@ bool dfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) { UINT64 size = io_generic_size(io); UINT64 pos = 4; - UINT8 *data = 0; - int data_size = 0; // size of currently allocated array for a track + dynamic_buffer data; int onerev_time = 0; // time for one revolution, used to guess clock and rpm for DFE2 files unsigned long clock_rate = 100000000; // sample clock rate in megahertz int rpm=360; // drive rpm @@ -84,18 +83,11 @@ bool dfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) // if the position-so-far-in-file plus 10 (for the header) plus track size // is larger than the size of the file, free buffers and bail out if(pos+tsize+10 > size) { - if(data) - global_free(data); return false; } // reallocate the data array if it gets too small - if(tsize > data_size) { - if(data) - global_free(data); - data_size = tsize; - data = global_alloc_array(UINT8, data_size); - } + data.resize(tsize); pos += 10; // skip the header, we already read it io_generic_read(io, data, pos, tsize); @@ -229,9 +221,6 @@ bool dfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) image->set_track_size(track, head, tpos); } - if(data) - global_free(data); - return true; } diff --git a/src/lib/formats/flopimg.c b/src/lib/formats/flopimg.c index 04b88d3b337..ca9af339518 100644 --- a/src/lib/formats/flopimg.c +++ b/src/lib/formats/flopimg.c @@ -430,7 +430,7 @@ static floperr_t floppy_readwrite_sector(floppy_image_legacy *floppy, int head, floperr_t err; const struct FloppyCallbacks *fmt; size_t this_buffer_len; - UINT8 *alloc_buf = NULL; + dynamic_buffer alloc_buf; UINT32 sector_length; UINT8 *buffer_ptr = (UINT8 *)buffer; floperr_t (*read_sector)(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen); @@ -486,13 +486,7 @@ static floperr_t floppy_readwrite_sector(floppy_image_legacy *floppy, int head, { /* we will be doing an partial read/write; in other words we * will not be reading/writing a full sector */ - if (alloc_buf) free(alloc_buf); - alloc_buf = (UINT8*)malloc(sector_length); - if (!alloc_buf) - { - err = FLOPPY_ERROR_OUTOFMEMORY; - goto done; - } + alloc_buf.resize(sector_length); /* read the sector (we need to do this even when writing */ err = read_sector(floppy, head, track, sector, alloc_buf, sector_length); @@ -543,8 +537,6 @@ static floperr_t floppy_readwrite_sector(floppy_image_legacy *floppy, int head, err = FLOPPY_ERROR_SUCCESS; done: - if (alloc_buf) - free(alloc_buf); return err; } @@ -965,7 +957,7 @@ floppy_image::~floppy_image() { for (int i=0;i buffer(track_size); gen_crc_info crcs[MAX_CRC_COUNT]; collect_crcs(desc, crcs); @@ -1638,7 +1630,6 @@ void floppy_image_format_t::generate_track(const desc_e *desc, int track, int he fixup_crcs(buffer, crcs); generate_track_from_levels(track, head, buffer, track_size, 0, image); - global_free(buffer); } void floppy_image_format_t::normalize_times(UINT32 *buffer, int bitlen) @@ -2606,7 +2597,7 @@ void floppy_image_format_t::build_wd_track_mfm(int track, int head, floppy_image void floppy_image_format_t::build_pc_track_fm(int track, int head, floppy_image *image, int cell_count, int sector_count, const desc_pc_sector *sects, int gap_3, int gap_4a, int gap_1, int gap_2) { - UINT32 *track_data = global_alloc_array(UINT32, cell_count+10000); + dynamic_array track_data(cell_count+10000); int tpos = 0; // gap 4a , IAM and gap 1 @@ -2670,12 +2661,11 @@ void floppy_image_format_t::build_pc_track_fm(int track, int head, floppy_image raw_w(track_data, tpos, cell_count-tpos, 0xffff >> (16+tpos-cell_count)); generate_track_from_levels(track, head, track_data, cell_count, 0, image); - global_free(track_data); } void floppy_image_format_t::build_pc_track_mfm(int track, int head, floppy_image *image, int cell_count, int sector_count, const desc_pc_sector *sects, int gap_3, int gap_4a, int gap_1, int gap_2) { - UINT32 *track_data = global_alloc_array(UINT32, cell_count+10000); + dynamic_array track_data(cell_count+10000); int tpos = 0; // gap 4a , IAM and gap 1 @@ -2742,5 +2732,4 @@ void floppy_image_format_t::build_pc_track_mfm(int track, int head, floppy_image raw_w(track_data, tpos, cell_count-tpos, 0x9254 >> (16+tpos-cell_count)); generate_track_from_levels(track, head, track_data, cell_count, 0, image); - global_free(track_data); } diff --git a/src/lib/formats/g64_dsk.c b/src/lib/formats/g64_dsk.c index 5cf2d3d856e..c1c55acc4e8 100644 --- a/src/lib/formats/g64_dsk.c +++ b/src/lib/formats/g64_dsk.c @@ -41,7 +41,7 @@ int g64_format::identify(io_generic *io, UINT32 form_factor) bool g64_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) { UINT64 size = io_generic_size(io); - UINT8 *img = global_alloc_array(UINT8, size); + dynamic_buffer img(size); io_generic_read(io, img, 0, size); if (img[VERSION]) { @@ -74,8 +74,6 @@ bool g64_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) generate_track_from_bitstream(track, head, &img[track_offset+2], track_size, image); } - global_free(img); - image->set_variant(floppy_image::SSSD); return true; @@ -102,6 +100,7 @@ bool g64_format::save(io_generic *io, floppy_image *image) int head = 0; int tracks_written = 0; + dynamic_buffer trackbuf(TRACK_LENGTH-2); for (int track = 0; track < 84; track++) { offs_t tpos = TRACK_OFFSET + track * 4; offs_t spos = SPEED_ZONE + track * 4; @@ -113,7 +112,6 @@ bool g64_format::save(io_generic *io, floppy_image *image) if (image->get_track_size(track, head) <= 1) continue; - UINT8 *trackbuf = global_alloc_array(UINT8, TRACK_LENGTH-2); int track_size; int speed_zone; @@ -141,8 +139,6 @@ bool g64_format::save(io_generic *io, floppy_image *image) io_generic_write(io, trackbuf, dpos + 2, track_size); tracks_written++; - - global_free(trackbuf); } return true; diff --git a/src/lib/formats/hxcmfm_dsk.c b/src/lib/formats/hxcmfm_dsk.c index a49dfd5c3e5..967f05539a3 100644 --- a/src/lib/formats/hxcmfm_dsk.c +++ b/src/lib/formats/hxcmfm_dsk.c @@ -71,23 +71,17 @@ bool mfm_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) { MFMIMG header; MFMTRACKIMG trackdesc; - UINT8 *trackbuf = 0; - int trackbuf_size = 0; // read header io_generic_read(io, &header, 0, sizeof(header)); int counter = 0; + dynamic_buffer trackbuf; for(int track=0; track < header.number_of_track; track++) { for(int side=0; side < header.number_of_side; side++) { // read location of io_generic_read(io, &trackdesc,(header.mfmtracklistoffset)+( counter *sizeof(trackdesc)),sizeof(trackdesc)); - if(trackdesc.mfmtracksize > trackbuf_size) { - if(trackbuf) - global_free(trackbuf); - trackbuf_size = trackdesc.mfmtracksize; - trackbuf = global_alloc_array(UINT8, trackbuf_size); - } + trackbuf.resize(trackdesc.mfmtracksize); // actual data read io_generic_read(io, trackbuf, trackdesc.mfmtrackoffset, trackdesc.mfmtracksize); @@ -97,8 +91,6 @@ bool mfm_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) counter++; } } - if(trackbuf) - global_free(trackbuf); image->set_variant(floppy_image::DSDD); return true; diff --git a/src/lib/formats/imd_dsk.c b/src/lib/formats/imd_dsk.c index f3da7d8d113..2f0ee10635d 100644 --- a/src/lib/formats/imd_dsk.c +++ b/src/lib/formats/imd_dsk.c @@ -334,7 +334,7 @@ int imd_format::identify(io_generic *io, UINT32 form_factor) bool imd_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) { UINT64 size = io_generic_size(io); - UINT8 *img = global_alloc_array(UINT8, size); + dynamic_buffer img(size); io_generic_read(io, img, 0, size); UINT64 pos; @@ -413,7 +413,6 @@ bool imd_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) global_free(sects[i].data); } - global_free(img); return true; } diff --git a/src/lib/formats/ipf_dsk.c b/src/lib/formats/ipf_dsk.c index 88af68e4713..f8e7423157b 100644 --- a/src/lib/formats/ipf_dsk.c +++ b/src/lib/formats/ipf_dsk.c @@ -42,10 +42,9 @@ int ipf_format::identify(io_generic *io, UINT32 form_factor) bool ipf_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) { UINT64 size = io_generic_size(io); - UINT8 *data = global_alloc_array(UINT8, size); + dynamic_buffer data(size); io_generic_read(io, data, 0, size); bool res = parse(data, size, image); - global_free(data); return res; } @@ -387,27 +386,19 @@ bool ipf_format::generate_track(track_info *t, floppy_image *image) if(t->index_cells >= t->size_cells) return false; - UINT32 *track = global_alloc_array(UINT32, t->size_cells); - UINT32 *data_pos = global_alloc_array(UINT32, t->block_count+1); - UINT32 *gap_pos = global_alloc_array(UINT32, t->block_count); - UINT32 *splice_pos = global_alloc_array(UINT32, t->block_count); + dynamic_array track(t->size_cells); + dynamic_array data_pos(t->block_count+1); + dynamic_array gap_pos(t->block_count); + dynamic_array splice_pos(t->block_count); bool context = false; UINT32 pos = 0; for(UINT32 i = 0; i != t->block_count; i++) { if(!generate_block(t, i, i == t->block_count-1 ? t->size_cells - t->index_cells : 0xffffffff, track, pos, data_pos[i], gap_pos[i], splice_pos[i], context)) { - global_free(track); - global_free(data_pos); - global_free(gap_pos); - global_free(splice_pos); return false; } } if(pos != t->size_cells) { - global_free(track); - global_free(data_pos); - global_free(gap_pos); - global_free(splice_pos); return false; } @@ -416,10 +407,6 @@ bool ipf_format::generate_track(track_info *t, floppy_image *image) mark_track_splice(track, splice_pos[t->block_count-1], t->size_cells); if(!generate_timings(t, track, data_pos, gap_pos)) { - global_free(track); - global_free(data_pos); - global_free(gap_pos); - global_free(splice_pos); return false; } @@ -428,11 +415,6 @@ bool ipf_format::generate_track(track_info *t, floppy_image *image) generate_track_from_levels(t->cylinder, t->head, track, t->size_cells, splice_pos[t->block_count-1] + t->index_cells, image); - global_free(track); - global_free(data_pos); - global_free(gap_pos); - global_free(splice_pos); - return true; } diff --git a/src/lib/formats/mfi_dsk.c b/src/lib/formats/mfi_dsk.c index 12666d53017..eca7a00d705 100644 --- a/src/lib/formats/mfi_dsk.c +++ b/src/lib/formats/mfi_dsk.c @@ -113,8 +113,7 @@ bool mfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) image->set_variant(h.variant); - UINT8 *compressed = 0; - int compressed_size = 0; + dynamic_buffer compressed; entry *ent = entries; for(unsigned int cyl=0; cyl != h.cyl_count; cyl++) @@ -126,12 +125,7 @@ bool mfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) continue; } - if(ent->compressed_size > compressed_size) { - if(compressed) - global_free(compressed); - compressed_size = ent->compressed_size; - compressed = global_alloc_array(UINT8, compressed_size); - } + compressed.resize(ent->compressed_size); io_generic_read(io, compressed, ent->offset, ent->compressed_size); @@ -155,9 +149,6 @@ bool mfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) ent++; } - if(compressed) - global_free(compressed); - return true; } diff --git a/src/lib/formats/pasti_dsk.c b/src/lib/formats/pasti_dsk.c index 96f64d887c5..c1c3e164ab7 100644 --- a/src/lib/formats/pasti_dsk.c +++ b/src/lib/formats/pasti_dsk.c @@ -62,8 +62,7 @@ bool pasti_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) UINT8 fh[16]; io_generic_read(io, fh, 0, 16); - UINT8 *raw_track = 0; - int raw_track_size = 0; + dynamic_buffer raw_track; int tracks = fh[10]; int heads = 1+(tracks >= 160); @@ -85,12 +84,7 @@ bool pasti_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) int track_num = th[14]; int flags2 = th[15]; - if(entry_len-16 > raw_track_size) { - if(raw_track) - global_free(raw_track); - raw_track_size = entry_len-16; - raw_track = global_alloc_array(UINT8, entry_len-16); - } + raw_track.resize(entry_len-16); io_generic_read(io, raw_track, pos+16, entry_len-16); @@ -275,7 +269,7 @@ void pasti_format::wd_generate_track_from_sectors_and_track(int track, int head, { if(0) printf("Track %d head %d sectors %d\n", track, head, obs.sector_count); - UINT32 *trackbuf = global_alloc_array(UINT32, 200000); + dynamic_array trackbuf(200000); int pos = 0; wd_sect_info sect_infos[256]; @@ -347,8 +341,6 @@ void pasti_format::wd_generate_track_from_sectors_and_track(int track, int head, wd_generate_gap(trackbuf, pos, obs, 0, obs.track_size, false, 1000, 1000); generate_track_from_levels(track, head, trackbuf, pos, 0, image); - - global_free(trackbuf); } void pasti_format::wd_generate_track_from_sectors_only(int track, int head, floppy_image *image, wd_obs &obs) diff --git a/src/lib/formats/td0_dsk.c b/src/lib/formats/td0_dsk.c index d69504f4965..d72cef70996 100644 --- a/src/lib/formats/td0_dsk.c +++ b/src/lib/formats/td0_dsk.c @@ -820,7 +820,7 @@ bool td0_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) int track_spt; int offset = 0; const int max_size = 4*1024*1024; // 4MB ought to be large enough for any floppy - UINT8 *imagebuf = global_alloc_array(UINT8, max_size); + dynamic_buffer imagebuf(max_size); UINT8 header[12]; try @@ -1005,7 +1005,6 @@ bool td0_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) } catch(bool ret) { - global_free(imagebuf); return ret; } return false; diff --git a/src/lib/formats/upd765_dsk.c b/src/lib/formats/upd765_dsk.c index cec4dd4373e..5966e1de1a3 100644 --- a/src/lib/formats/upd765_dsk.c +++ b/src/lib/formats/upd765_dsk.c @@ -236,7 +236,7 @@ bool upd765_format::save(io_generic *io, floppy_image *image) // Allocate the storage for the list of testable formats for a // given cell size - int *candidates = global_alloc_array(int, formats_count); + dynamic_array candidates(formats_count); // Format we're finally choosing int chosen_candidate = -1; @@ -341,8 +341,6 @@ bool upd765_format::save(io_generic *io, floppy_image *image) io_generic_write(io, sectdata, (track*f.head_count + head)*track_size, track_size); } - global_free(candidates); - return true; } diff --git a/src/lib/formats/wd177x_dsk.c b/src/lib/formats/wd177x_dsk.c index d4619acae97..57223fecc2f 100644 --- a/src/lib/formats/wd177x_dsk.c +++ b/src/lib/formats/wd177x_dsk.c @@ -226,7 +226,7 @@ bool wd177x_format::save(io_generic *io, floppy_image *image) // Allocate the storage for the list of testable formats for a // given cell size - int *candidates = global_alloc_array(int, formats_count); + dynamic_array candidates(formats_count); // Format we're finally choosing int chosen_candidate = -1; @@ -331,7 +331,6 @@ bool wd177x_format::save(io_generic *io, floppy_image *image) io_generic_write(io, sectdata, get_image_offset(f, head, track), track_size); } - global_free(candidates); return true; } diff --git a/src/lib/lib.mak b/src/lib/lib.mak index 84897a8d74e..13a0fa9283c 100644 --- a/src/lib/lib.mak +++ b/src/lib/lib.mak @@ -41,9 +41,11 @@ UTILOBJS = \ $(LIBOBJ)/util/chd.o \ $(LIBOBJ)/util/chdcd.o \ $(LIBOBJ)/util/chdcodec.o \ + $(LIBOBJ)/util/corealloc.o \ $(LIBOBJ)/util/corefile.o \ $(LIBOBJ)/util/corestr.o \ $(LIBOBJ)/util/coreutil.o \ + $(LIBOBJ)/util/cstrpool.o \ $(LIBOBJ)/util/flac.o \ $(LIBOBJ)/util/harddisk.o \ $(LIBOBJ)/util/hashing.o \ diff --git a/src/lib/util/aviio.c b/src/lib/util/aviio.c index 3e6b11ed881..7dd2e3bb9c1 100644 --- a/src/lib/util/aviio.c +++ b/src/lib/util/aviio.c @@ -370,9 +370,15 @@ INLINE avi_error set_stream_chunk_info(avi_stream *stream, UINT32 index, UINT64 if (index >= stream->chunksalloc) { UINT32 newcount = MAX(index, stream->chunksalloc + 1000); - stream->chunk = (avi_chunk_list *)realloc(stream->chunk, newcount * sizeof(stream->chunk[0])); - if (stream->chunk == NULL) + avi_chunk_list *newchunks = (avi_chunk_list *)malloc(newcount * sizeof(stream->chunk[0])); + if (newchunks == NULL) return AVIERR_NO_MEMORY; + if (stream->chunk != NULL) + { + memcpy(newchunks, stream->chunk, stream->chunksalloc * sizeof(stream->chunk[0])); + free(stream->chunk); + } + stream->chunk = newchunks; stream->chunksalloc = newcount; } @@ -446,9 +452,12 @@ INLINE avi_error expand_tempbuffer(avi_file *file, UINT32 length) if (length > file->tempbuffersize) { file->tempbuffersize = 2 * length; - file->tempbuffer = (UINT8 *)realloc(file->tempbuffer, file->tempbuffersize); - if (file->tempbuffer == NULL) + UINT8 *newbuffer = (UINT8 *)malloc(file->tempbuffersize); + if (newbuffer == NULL) return AVIERR_NO_MEMORY; + if (file->tempbuffer != NULL) + free(file->tempbuffer); + file->tempbuffer = newbuffer; } return AVIERR_NONE; } diff --git a/src/lib/util/corealloc.c b/src/lib/util/corealloc.c new file mode 100644 index 00000000000..089770b20ed --- /dev/null +++ b/src/lib/util/corealloc.c @@ -0,0 +1,375 @@ +// license:BSD-3-Clause +// copyright-holders:Aaron Giles +/*************************************************************************** + + corealloc.c + + Memory allocation helpers for the helper library. + +***************************************************************************/ + +#include "corealloc.h" +#include "osdcore.h" + + +//************************************************************************** +// DEBUGGING +//************************************************************************** + +#define LOG_ALLOCS (0) + + + +//************************************************************************** +// CONSTANTS +//************************************************************************** + +// number of memory_entries to allocate in a block +const int memory_block_alloc_chunk = 256; + + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// this struct is allocated in pools to track memory allocations +// it must be a POD type!! +class memory_entry +{ +public: + // internal state + memory_entry * m_next; // link to the next entry + memory_entry * m_prev; // link to the previous entry + size_t m_size; // size of the allocation (not including this header) + void * m_base; // base of the allocation + const char * m_file; // file the allocation was made from + int m_line; // line number within that file + UINT64 m_id; // unique id + bool m_array; // array? + + // hashing prime number + static const int k_hash_prime = 6151; + + // global state + static UINT64 s_curid; // current ID + static osd_lock * s_lock; // lock for managing the list + static bool s_lock_alloc; // set to true temporarily during lock allocation + static bool s_tracking; // set to true when tracking is live + static memory_entry *s_hash[k_hash_prime];// hash table based on pointer + static memory_entry *s_freehead; // pointer to the head of the free list + + // static helpers + static memory_entry *allocate(size_t size, void *base, const char *file, int line, bool array); + static memory_entry *find(void *ptr); + static void release(memory_entry *entry, const char *file, int line); + static void report_unfreed(UINT64 start); + +private: + static void acquire_lock(); + static void release_lock(); +}; + + + +//************************************************************************** +// GLOBALS +//************************************************************************** + +// dummy zeromem object +const zeromem_t zeromem = { }; + +// globals for memory_entry +UINT64 memory_entry::s_curid = 1; +osd_lock *memory_entry::s_lock = NULL; +bool memory_entry::s_lock_alloc = false; +bool memory_entry::s_tracking = false; +memory_entry *memory_entry::s_hash[memory_entry::k_hash_prime] = { NULL }; +memory_entry *memory_entry::s_freehead = NULL; + + + +//************************************************************************** +// GLOBAL HELPERS +//************************************************************************** + +//------------------------------------------------- +// malloc_file_line - allocate memory with file +// and line number information +//------------------------------------------------- + +void *malloc_file_line(size_t size, const char *file, int line, bool array, bool throw_on_fail, bool clear) +{ + // allocate the memory and fail if we can't + void *result = array ? osd_malloc_array(size) : osd_malloc(size); + if (result == NULL) + { + fprintf(stderr, "Failed to allocate %d bytes (%s:%d)\n", size, file, line); + osd_break_into_debugger("Failed to allocate RAM"); + if (throw_on_fail) + throw std::bad_alloc(); + return NULL; + } + + // zap the memory if requested + if (clear) + memset(result, 0, size); + else + { +#if !__has_feature(memory_sanitizer) && defined(INITIALIZE_ALLOCATED_MEMORY) + memset(result, 0xdd, size); +#endif + } + + // add a new entry + memory_entry::allocate(size, result, file, line, array); + + return result; +} + + +//------------------------------------------------- +// free_file_line - free memory with file +// and line number information +//------------------------------------------------- + +void free_file_line(void *memory, const char *file, int line, bool array) +{ + // find the memory entry + memory_entry *entry = memory_entry::find(memory); + + // warn about untracked frees + if (entry == NULL) + { + fprintf(stderr, "Error: attempt to free untracked memory %p in %s(%d)!\n", memory, file, line); + osd_break_into_debugger("Error: attempt to free untracked memory"); + return; + } + + // warn about mismatched arrays + if (!array && entry->m_array) + { + fprintf(stderr, "Error: attempt to free array %p with global_free in %s(%d)!\n", memory, file, line); + osd_break_into_debugger("Error: attempt to free array with global_free"); + } + if (array && !entry->m_array) + { + fprintf(stderr, "Error: attempt to free single object %p with global_free_array in %s(%d)!\n", memory, file, line); + osd_break_into_debugger("Error: attempt to free single object with global_free_array"); + } + +#ifdef OVERWRITE_FREED_MEMORY + // clear memory to a bogus value + memset(memory, 0xfc, entry->m_size); +#endif + + // free the entry and the memory + memory_entry::release(entry, file, line); + osd_free(memory); +} + + +//------------------------------------------------- +// dump_unfreed_mem - called from the exit path +// of any code that wants to check for unfreed +// memory +//------------------------------------------------- + +void track_memory(bool track) +{ + memory_entry::s_tracking = track; +} + + +//------------------------------------------------- +// next_memory_id - return the ID of the next +// allocated block +//------------------------------------------------- + +UINT64 next_memory_id() +{ + return memory_entry::s_curid; +} + + +//------------------------------------------------- +// dump_unfreed_mem - called from the exit path +// of any code that wants to check for unfreed +// memory +//------------------------------------------------- + +void dump_unfreed_mem(UINT64 start) +{ + memory_entry::report_unfreed(start); +} + + + +//************************************************************************** +// MEMORY ENTRY +//************************************************************************** + +//------------------------------------------------- +// acquire_lock - acquire the memory entry lock, +// creating a new one if needed +//------------------------------------------------- + +void memory_entry::acquire_lock() +{ + // allocate a lock on first usage + // note that osd_lock_alloc() may re-enter this path, so protect against recursion! + if (s_lock == NULL) + { + if (s_lock_alloc) + return; + s_lock_alloc = true; + s_lock = osd_lock_alloc(); + s_lock_alloc = false; + } + osd_lock_acquire(s_lock); +} + + +//------------------------------------------------- +// release_lock - release the memory entry lock +//------------------------------------------------- + +void memory_entry::release_lock() +{ + osd_lock_release(s_lock); +} + + +//------------------------------------------------- +// allocate - allocate a new memory entry +//------------------------------------------------- + +memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, int line, bool array) +{ + acquire_lock(); + + // if we're out of free entries, allocate a new chunk + if (s_freehead == NULL) + { + // create a new chunk, and fail if we can't + memory_entry *entry = reinterpret_cast(osd_malloc_array(memory_block_alloc_chunk * sizeof(memory_entry))); + if (entry == NULL) + { + release_lock(); + return NULL; + } + + // add all the entries to the list + for (int entrynum = 0; entrynum < memory_block_alloc_chunk; entrynum++) + { + entry->m_next = s_freehead; + s_freehead = entry++; + } + } + + // grab a free entry + memory_entry *entry = s_freehead; + s_freehead = entry->m_next; + + // populate it + entry->m_size = size; + entry->m_base = base; + entry->m_file = s_tracking ? file : NULL; + entry->m_line = s_tracking ? line : 0; + entry->m_id = s_curid++; + entry->m_array = array; + if (LOG_ALLOCS) + fprintf(stderr, "#%06d, alloc %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), entry->m_file, (int)entry->m_line); + + // add it to the alloc list + int hashval = reinterpret_cast(base) % k_hash_prime; + entry->m_next = s_hash[hashval]; + if (entry->m_next != NULL) + entry->m_next->m_prev = entry; + entry->m_prev = NULL; + s_hash[hashval] = entry; + + release_lock(); + return entry; +} + + +//------------------------------------------------- +// find - find a memory entry +//------------------------------------------------- + +memory_entry *memory_entry::find(void *ptr) +{ + // NULL maps to nothing + if (ptr == NULL) + return NULL; + + // scan the list under the lock + acquire_lock(); + + int hashval = reinterpret_cast(ptr) % k_hash_prime; + memory_entry *entry; + for (entry = s_hash[hashval]; entry != NULL; entry = entry->m_next) + if (entry->m_base == ptr) + break; + + release_lock(); + return entry; +} + + +//------------------------------------------------- +// release - release a memory entry +//------------------------------------------------- + +void memory_entry::release(memory_entry *entry, const char *file, int line) +{ + acquire_lock(); + + if (LOG_ALLOCS) + fprintf(stderr, "#%06d, release %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), file, line); + + // remove ourselves from the alloc list + int hashval = reinterpret_cast(entry->m_base) % k_hash_prime; + if (entry->m_prev != NULL) + entry->m_prev->m_next = entry->m_next; + else + s_hash[hashval] = entry->m_next; + if (entry->m_next != NULL) + entry->m_next->m_prev = entry->m_prev; + + // add ourself to the free list + entry->m_next = s_freehead; + s_freehead = entry; + + release_lock(); +} + + +//------------------------------------------------- +// report_unfreed - print a list of unfreed +// memory to the target file +//------------------------------------------------- + +void memory_entry::report_unfreed(UINT64 start) +{ + acquire_lock(); + + // check for leaked memory + UINT32 total = 0; + + for (int hashnum = 0; hashnum < k_hash_prime; hashnum++) + for (memory_entry *entry = s_hash[hashnum]; entry != NULL; entry = entry->m_next) + if (entry->m_file != NULL && entry->m_id >= start) + { + if (total == 0) + fprintf(stderr, "--- memory leak warning ---\n"); + total += entry->m_size; + fprintf(stderr, "#%06d, nofree %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), entry->m_file, (int)entry->m_line); + } + + release_lock(); + + if (total > 0) + fprintf(stderr, "a total of %u bytes were not freed\n", total); +} diff --git a/src/lib/util/corealloc.h b/src/lib/util/corealloc.h new file mode 100644 index 00000000000..0d2c2003057 --- /dev/null +++ b/src/lib/util/corealloc.h @@ -0,0 +1,121 @@ +// license:BSD-3-Clause +// copyright-holders:Aaron Giles +/*************************************************************************** + + corealloc.h + + Memory allocation helpers for the helper library. + +***************************************************************************/ + +#pragma once + +#ifndef __COREALLOC_H__ +#define __COREALLOC_H__ + +#include +#include "osdcore.h" + + +//************************************************************************** +// DEBUGGING +//************************************************************************** + +// define this to initialize allocated memory to a fixed non-0 value +//#define INITIALIZE_ALLOCATED_MEMORY + +// define this to zap memory to a fixed non-0 value before freeing +//#define OVERWRITE_FREED_MEMORY + + + +//************************************************************************** +// MACROS +//************************************************************************** + +// global allocation helpers -- use these instead of new and delete +#define global_alloc(_type) new(__FILE__, __LINE__) _type +#define global_alloc_clear(_type) new(__FILE__, __LINE__, zeromem) _type +#define global_alloc_array(_type, _num) new(__FILE__, __LINE__) _type[_num] +#define global_alloc_array_clear(_type, _num) new(__FILE__, __LINE__, zeromem) _type[_num] +#define global_free(_ptr) do { delete _ptr; } while (0) +#define global_free_array(_ptr) do { delete[] _ptr; } while (0) + + + +//************************************************************************** +// FUNCTION PROTOTYPES +//************************************************************************** + +// allocate memory with file and line number information +void *malloc_file_line(size_t size, const char *file, int line, bool array, bool throw_on_fail, bool clear); + +// free memory with file and line number information +void free_file_line(void *memory, const char *file, int line, bool array); +inline void free_file_line(const void *memory, const char *file, int line, bool array) { free_file_line(const_cast(memory), file, line, array); } + +// called from the exit path of any code that wants to check for unfreed memory +void track_memory(bool track); +UINT64 next_memory_id(); +void dump_unfreed_mem(UINT64 start = 0); + + + +//************************************************************************** +// INLINE FUNCTIONS +//************************************************************************** + +// zeromem_t is a dummy class used to tell new to zero memory after allocation +class zeromem_t { }; + +#ifndef NO_MEM_TRACKING + +// standard new/delete operators (try to avoid using) +ATTR_FORCE_INLINE inline void *operator new(std::size_t size) throw (std::bad_alloc) { return malloc_file_line(size, NULL, 0, false, true, false); } +ATTR_FORCE_INLINE inline void *operator new[](std::size_t size) throw (std::bad_alloc) { return malloc_file_line(size, NULL, 0, true, true, false); } +ATTR_FORCE_INLINE inline void operator delete(void *ptr) throw() { if (ptr != NULL) free_file_line(ptr, NULL, 0, false); } +ATTR_FORCE_INLINE inline void operator delete[](void *ptr) throw() { if (ptr != NULL) free_file_line(ptr, NULL, 0, true); } + +#endif + +// file/line new/delete operators +ATTR_FORCE_INLINE inline void *operator new(std::size_t size, const char *file, int line) throw (std::bad_alloc) { return malloc_file_line(size, file, line, false, true, false); } +ATTR_FORCE_INLINE inline void *operator new[](std::size_t size, const char *file, int line) throw (std::bad_alloc) { return malloc_file_line(size, file, line, true, true, false); } +ATTR_FORCE_INLINE inline void operator delete(void *ptr, const char *file, int line) { if (ptr != NULL) free_file_line(ptr, file, line, false); } +ATTR_FORCE_INLINE inline void operator delete[](void *ptr, const char *file, int line) { if (ptr != NULL) free_file_line(ptr, file, line, true); } + +// file/line new/delete operators with zeroing +ATTR_FORCE_INLINE inline void *operator new(std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc) { return malloc_file_line(size, file, line, false, true, true); } +ATTR_FORCE_INLINE inline void *operator new[](std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc) { return malloc_file_line(size, file, line, true, true, true); } +ATTR_FORCE_INLINE inline void operator delete(void *ptr, const char *file, int line, const zeromem_t &) { if (ptr != NULL) free_file_line(ptr, file, line, false); } +ATTR_FORCE_INLINE inline void operator delete[](void *ptr, const char *file, int line, const zeromem_t &) { if (ptr != NULL) free_file_line(ptr, file, line, true); } + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +// dummy objects to pass to the specialized new variants +extern const zeromem_t zeromem; + + + +//************************************************************************** +// ADDDITIONAL MACROS +//************************************************************************** + +#ifndef NO_MEM_TRACKING +// re-route classic malloc-style allocations +#undef malloc +#undef calloc +#undef realloc +#undef free + +#define malloc(x) malloc_file_line(x, __FILE__, __LINE__, true, false, false) +#define calloc(x,y) __error_use_auto_alloc_clear_or_global_alloc_clear_instead__ +#define realloc(x,y) __error_realloc_is_dangerous__ +#define free(x) free_file_line(x, __FILE__, __LINE__, true) +#endif + +#endif /* __COREALLOC_H__ */ diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index 2c52c81dc5e..1115ae0e62e 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -15,13 +15,49 @@ #include #include "osdcore.h" +#include "corealloc.h" // TEMPORARY helper to catch is_pod assertions in the debugger #if 0 #undef assert -#define assert(x) do { if (!(x)) { printf("Assert: %s\n", #x); asm("int $3"); } } while (0) +#define assert(x) do { if (!(x)) { fprintf(stderr, "Assert: %s\n", #x); osd_break_into_debugger("Assertion failed"); } } while (0) #endif + +// ======================> auto_pointer + +// an object that transparently wraps a pointer and auto-frees it upon destruction +template +class auto_pointer +{ +private: + // we don't support deep copying + auto_pointer(const auto_pointer &); + auto_pointer &operator=(const auto_pointer &); + +public: + // construction/destruction + auto_pointer(_ElementType *value = NULL) + : m_ptr(value) { } + virtual ~auto_pointer() { reset(); } + + // operators + operator _ElementType *() const { return m_ptr; } + _ElementType &operator*() const { assert(m_ptr != NULL); return *m_ptr; } + _ElementType *operator->() const { return m_ptr; } + + // simple getters + _ElementType *get() const { return m_ptr; } + + // core operations + void reset(_ElementType *ptr = NULL) { if (m_ptr != ptr) { global_free(m_ptr); m_ptr = ptr; } } + +private: + // internal state + _ElementType * m_ptr; // pointer we are tracking +}; + + // ======================> dynamic_array // an array that is dynamically sized and can optionally auto-expand @@ -51,8 +87,9 @@ public: int count() const { return m_count; } // core operations - const _ElementType &append(const _ElementType &element) { if (m_count == m_allocated) expand_and_keep_internal((m_allocated == 0) ? 16 : (m_allocated << 1)); m_array[m_count++] = element; return element; } - void reset() { delete[] m_array; m_array = NULL; m_count = m_allocated = 0; } + _ElementType &append() { if (m_count == m_allocated) expand_and_keep_internal((m_allocated == 0) ? 16 : (m_allocated << 1)); return m_array[m_count++]; } + const _ElementType &append(const _ElementType &element) { return (append() = element); } + void reset() { global_free_array(m_array); m_array = NULL; m_count = m_allocated = 0; } void resize(int count) { if (count > m_allocated) expand_internal(count); m_count = count; } void resize_keep(int count) { if (count > m_allocated) expand_and_keep_internal(count); m_count = count; } void clear(UINT8 data = 0) { clear_internal(0, m_count, data); } @@ -65,8 +102,8 @@ private: // internal helpers void expand_internal(int count) { - delete[] m_array; - m_array = new _ElementType[count]; + global_free_array(m_array); + m_array = global_alloc_array(_ElementType, count); m_allocated = count; } @@ -74,11 +111,11 @@ private: { _ElementType *oldarray = m_array; int oldcount = m_count; - m_array = new _ElementType[count]; + m_array = global_alloc_array(_ElementType, count); m_allocated = count; for (int index = 0; index < oldcount; index++) m_array[index] = oldarray[index]; - delete[] oldarray; + global_free_array(oldarray); } #ifdef __GNUC__ @@ -93,11 +130,291 @@ private: int m_allocated; // amount of space allocated for the array }; - -// ======================> dynamic_buffer - typedef dynamic_array dynamic_buffer; +// ======================> simple_list + +// a simple_list is a singly-linked list whose 'next' pointer is owned +// by the object +template +class simple_list +{ + // we don't support deep copying + simple_list(const simple_list &); + simple_list &operator=(const simple_list &); + +public: + // construction/destruction + simple_list() + : m_head(NULL), + m_tail(NULL), + m_count(0) { } + + virtual ~simple_list() { reset(); } + + // simple getters + _ElementType *first() const { return m_head; } + _ElementType *last() const { return m_tail; } + int count() const { return m_count; } + + // remove (free) all objects in the list, leaving an empty list + void reset() + { + while (m_head != NULL) + remove(*m_head); + } + + // add the given object to the head of the list + _ElementType &prepend(_ElementType &object) + { + object.m_next = m_head; + m_head = &object; + if (m_tail == NULL) + m_tail = m_head; + m_count++; + return object; + } + + // add the given list to the head of the list + void prepend_list(simple_list<_ElementType> &list) + { + int count = list.count(); + if (count == 0) + return; + _ElementType *tail = list.last(); + _ElementType *head = list.detach_all(); + tail->m_next = m_head; + m_head = head; + if (m_tail == NULL) + m_tail = tail; + m_count += count; + } + + // add the given object to the tail of the list + _ElementType &append(_ElementType &object) + { + object.m_next = NULL; + if (m_tail != NULL) + m_tail = m_tail->m_next = &object; + else + m_tail = m_head = &object; + m_count++; + return object; + } + + // add the given list to the tail of the list + void append_list(simple_list<_ElementType> &list) + { + int count = list.count(); + if (count == 0) + return; + _ElementType *tail = list.last(); + _ElementType *head = list.detach_all(); + if (m_tail != NULL) + m_tail->m_next = head; + else + m_head = head; + m_tail = tail; + m_count += count; + } + + // insert the given object after a particular object (NULL means prepend) + _ElementType &insert_after(_ElementType &object, _ElementType *insert_after) + { + if (insert_after == NULL) + return prepend(object); + object.m_next = insert_after->m_next; + insert_after->m_next = &object; + if (m_tail == insert_after) + m_tail = &object; + m_count++; + return object; + } + + // insert the given object before a particular object (NULL means append) + _ElementType &insert_before(_ElementType &object, _ElementType *insert_before) + { + if (insert_before == NULL) + return append(object); + for (_ElementType **curptr = &m_head; *curptr != NULL; curptr = &(*curptr)->m_next) + if (*curptr == insert_before) + { + object.m_next = insert_before; + *curptr = &object; + if (m_head == insert_before) + m_head = &object; + m_count++; + return object; + } + return object; + } + + // replace an item in the list at the same location, and remove it + _ElementType &replace_and_remove(_ElementType &object, _ElementType &toreplace) + { + _ElementType *prev = NULL; + for (_ElementType *cur = m_head; cur != NULL; prev = cur, cur = cur->m_next) + if (cur == &toreplace) + { + if (prev != NULL) + prev->m_next = &object; + else + m_head = &object; + if (m_tail == &toreplace) + m_tail = &object; + object.m_next = toreplace.m_next; + global_free(&toreplace); + return object; + } + return append(object); + } + + // detach the head item from the list, but don't free its memory + _ElementType *detach_head() + { + _ElementType *result = m_head; + if (result != NULL) + { + m_head = result->m_next; + m_count--; + if (m_head == NULL) + m_tail = NULL; + } + return result; + } + + // detach the given item from the list, but don't free its memory + _ElementType &detach(_ElementType &object) + { + _ElementType *prev = NULL; + for (_ElementType *cur = m_head; cur != NULL; prev = cur, cur = cur->m_next) + if (cur == &object) + { + if (prev != NULL) + prev->m_next = object.m_next; + else + m_head = object.m_next; + if (m_tail == &object) + m_tail = prev; + m_count--; + return object; + } + return object; + } + + // deatch the entire list, returning the head, but don't free memory + _ElementType *detach_all() + { + _ElementType *result = m_head; + m_head = m_tail = NULL; + m_count = 0; + return result; + } + + // remove the given object and free its memory + void remove(_ElementType &object) + { + global_free(&detach(object)); + } + + // find an object by index in the list + _ElementType *find(int index) const + { + for (_ElementType *cur = m_head; cur != NULL; cur = cur->m_next) + if (index-- == 0) + return cur; + return NULL; + } + + // return the index of the given object in the list + int indexof(const _ElementType &object) const + { + int index = 0; + for (_ElementType *cur = m_head; cur != NULL; cur = cur->m_next) + { + if (cur == &object) + return index; + index++; + } + return -1; + } + +private: + // internal state + _ElementType * m_head; // head of the singly-linked list + _ElementType * m_tail; // tail of the singly-linked list + int m_count; // number of objects in the list +}; + + +// ======================> simple_list_wrapper + +// a simple_list_wrapper wraps an existing object with a next pointer so it +// can live in a simple_list without requiring the object to have a next +// pointer +template +class simple_list_wrapper +{ +public: + template friend class simple_list; + + // construction/destruction + simple_list_wrapper(_ObjectType *object) + : m_next(NULL), + m_object(object) { } + + // operators + operator _ObjectType *() { return m_object; } + operator _ObjectType *() const { return m_object; } + _ObjectType *operator *() { return m_object; } + _ObjectType *operator *() const { return m_object; } + + // getters + simple_list_wrapper *next() const { return m_next; } + _ObjectType *object() const { return m_object; } + +private: + // internal state + simple_list_wrapper * m_next; + _ObjectType * m_object; +}; + + +// ======================> fixed_allocator + +// a fixed_allocator is a simple class that maintains a free pool of objects +template +class fixed_allocator +{ + // we don't support deep copying + fixed_allocator(const fixed_allocator &); + fixed_allocator &operator=(const fixed_allocator &); + +public: + // construction/destruction + fixed_allocator() { } + + // allocate a new item, either by recycling an old one, or by allocating a new one + _ItemType *alloc() + { + _ItemType *result = m_freelist.detach_head(); + if (result == NULL) + result = global_alloc(_ItemType); + return result; + } + + // reclaim an item by adding it to the free list + void reclaim(_ItemType *item) { if (item != NULL) m_freelist.append(*item); } + void reclaim(_ItemType &item) { m_freelist.append(item); } + + // reclaim all items from a list + void reclaim_all(simple_list<_ItemType> &list) { m_freelist.append_list(list); } + +private: + // internal state + simple_list<_ItemType> m_freelist; // list of free objects +}; + #endif diff --git a/src/lib/util/cstrpool.c b/src/lib/util/cstrpool.c new file mode 100644 index 00000000000..17b43b325a6 --- /dev/null +++ b/src/lib/util/cstrpool.c @@ -0,0 +1,100 @@ +/*************************************************************************** + + cstrpool.c + + Constant string pool helper class. + +***************************************************************************/ + +#include "cstrpool.h" + + +//************************************************************************** +// CONST STRING POOL +//************************************************************************** + +//------------------------------------------------- +// const_string_pool - constructor +//------------------------------------------------- + +const_string_pool::const_string_pool() +{ +} + + +//------------------------------------------------- +// add - add a string to the string pool +//------------------------------------------------- + +const char *const_string_pool::add(const char *string) +{ + // if NULL or a small number (for some hash strings), just return as-is + if (FPTR(string) < 0x100) + return string; + + // scan to find space + for (pool_chunk *chunk = m_chunklist.first(); chunk != NULL; chunk = chunk->next()) + { + const char *result = chunk->add(string); + if (result != NULL) + return result; + } + + // no space anywhere, create a new pool and prepend it (so it gets used first) + const char *result = m_chunklist.prepend(*global_alloc(pool_chunk)).add(string); + assert(result != NULL); + return result; +} + + +//------------------------------------------------- +// contains - determine if the given string +// pointer lives in the pool +//------------------------------------------------- + +bool const_string_pool::contains(const char *string) +{ + // if NULL or a small number (for some hash strings), then yes, effectively + if (FPTR(string) < 0x100) + return true; + + // scan to find it + for (pool_chunk *chunk = m_chunklist.first(); chunk != NULL; chunk = chunk->next()) + if (chunk->contains(string)) + return true; + + return false; +} + + +//------------------------------------------------- +// pool_chunk - constructor +//------------------------------------------------- + +const_string_pool::pool_chunk::pool_chunk() + : m_next(NULL), + m_used(0) +{ +} + + +//------------------------------------------------- +// add - add a string to this pool +//------------------------------------------------- + +const char *const_string_pool::pool_chunk::add(const char *string) +{ + // get the length of the string (no string can be longer than a full pool) + int bytes = strlen(string) + 1; + assert(bytes < POOL_SIZE); + + // if too big, return NULL + if (m_used + bytes > POOL_SIZE) + return NULL; + + // allocate, copy, and return the memory + char *dest = &m_buffer[m_used]; + m_used += bytes; + memcpy(dest, string, bytes); + return dest; +} diff --git a/src/lib/util/cstrpool.h b/src/lib/util/cstrpool.h new file mode 100644 index 00000000000..c4b4805362d --- /dev/null +++ b/src/lib/util/cstrpool.h @@ -0,0 +1,63 @@ +/********************************************************************* + + cstrpool.h + + Constant string pool helper class. + +*********************************************************************/ + +#pragma once + +#ifndef __CSTRPOOL_H_ +#define __CSTRPOOL_H_ + +#include "coretmpl.h" + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> const_string_pool + +// a pool to hold constant strings efficiently +class const_string_pool +{ +public: + // construction + const_string_pool(); + + // operations + void reset() { m_chunklist.reset(); } + const char *add(const char *string); + bool contains(const char *string); + +private: + // shared string pool + class pool_chunk + { + static const int POOL_SIZE = 4096; + friend class simple_list; + + public: + // construction + pool_chunk(); + + // getters + pool_chunk *next() const { return m_next; } + + // operations + const char *add(const char *string); + bool contains(const char *string) const { return (string >= m_buffer && string < &m_buffer[POOL_SIZE]); } + + private: + // internal state + pool_chunk * m_next; + UINT32 m_used; + char m_buffer[POOL_SIZE]; + }; + simple_list m_chunklist; +}; + + +#endif diff --git a/src/lib/util/options.c b/src/lib/util/options.c index c0cd1f9d3d8..7aa08ad0500 100644 --- a/src/lib/util/options.c +++ b/src/lib/util/options.c @@ -50,19 +50,19 @@ const char *const core_options::s_option_unadorned[MAX_UNADORNED_OPTIONS] = // entry - constructor //------------------------------------------------- -core_options::entry::entry(const options_entry &entrylist) +core_options::entry::entry(const char *name, const char *description, UINT32 flags, const char *defvalue) : m_next(NULL), - m_flags(entrylist.flags), + m_flags(flags), m_seqid(0), m_error_reported(false), m_priority(OPTION_PRIORITY_DEFAULT), - m_description(entrylist.description) + m_description(description) { // copy in the name(s) as appropriate - if (entrylist.name != NULL) + if (name != NULL) { // first extract any range - astring namestr(entrylist.name); + astring namestr(name); int lparen = namestr.chr(0, '('); int dash = namestr.chr(lparen + 1, '-'); int rparen = namestr.chr(dash + 1, ')'); @@ -88,8 +88,8 @@ core_options::entry::entry(const options_entry &entrylist) } // set the default value - if (entrylist.defvalue != NULL) - m_defdata = entrylist.defvalue; + if (defvalue != NULL) + m_defdata = defvalue; m_data = m_defdata; } @@ -156,29 +156,21 @@ void core_options::entry::revert(int priority) //------------------------------------------------- core_options::core_options() - : m_entrylist(NULL), - m_entrylist_tailptr(&m_entrylist) { } core_options::core_options(const options_entry *entrylist) - : m_entrylist(NULL), - m_entrylist_tailptr(&m_entrylist) { add_entries(entrylist); } core_options::core_options(const options_entry *entrylist1, const options_entry *entrylist2) - : m_entrylist(NULL), - m_entrylist_tailptr(&m_entrylist) { add_entries(entrylist1); add_entries(entrylist2); } core_options::core_options(const options_entry *entrylist1, const options_entry *entrylist2, const options_entry *entrylist3) - : m_entrylist(NULL), - m_entrylist_tailptr(&m_entrylist) { add_entries(entrylist1); add_entries(entrylist2); @@ -186,8 +178,6 @@ core_options::core_options(const options_entry *entrylist1, const options_entry } core_options::core_options(const core_options &src) - : m_entrylist(NULL), - m_entrylist_tailptr(&m_entrylist) { copyfrom(src); } @@ -199,13 +189,6 @@ core_options::core_options(const core_options &src) core_options::~core_options() { - // delete all entries from the list - while (m_entrylist != NULL) - { - core_options::entry *e = m_entrylist; - remove_entry(*m_entrylist); - delete e; - } } @@ -229,11 +212,11 @@ core_options &core_options::operator=(const core_options &rhs) bool core_options::operator==(const core_options &rhs) { // iterate over options in the first list - for (entry *curentry = m_entrylist; curentry != NULL; curentry = curentry->next()) + for (entry *curentry = m_entrylist.first(); curentry != NULL; curentry = curentry->next()) if (!curentry->is_header()) { // if the values differ, return false - if (strcmp(curentry->m_data, rhs.value(curentry->name())) != 0) + if (strcmp(curentry->value(), rhs.value(curentry->name())) != 0) return false; } @@ -251,6 +234,40 @@ bool core_options::operator!=(const core_options &rhs) } +//------------------------------------------------- +// add_entry - add an entry to the current +// options set +//------------------------------------------------- + +void core_options::add_entry(const char *name, const char *description, UINT32 flags, const char *defvalue, bool override_existing) +{ + // allocate a new entry + entry *newentry = global_alloc(entry(name, description, flags, defvalue)); + if (newentry->name() != NULL) + { + // see if we match an existing entry + entry *existing = m_entrymap.find(newentry->name()); + if (existing != NULL) + { + // if we're overriding existing entries, then remove the old one + if (override_existing) + m_entrylist.remove(*existing); + + // otherwise, just override the default and current values and throw out the new entry + else + { + existing->set_default_value(newentry->value()); + global_free(newentry); + return; + } + } + } + + // add us to the list and maps + append_entry(*newentry); +} + + //------------------------------------------------- // add_entries - add entries to the current // options sets @@ -260,36 +277,7 @@ void core_options::add_entries(const options_entry *entrylist, bool override_exi { // loop over entries until we hit a NULL name for ( ; entrylist->name != NULL || (entrylist->flags & OPTION_HEADER) != 0; entrylist++) - { - // allocate a new entry - entry *newentry = new entry(*entrylist); - if (newentry->name() != NULL) - { - // see if we match an existing entry - entry *existing = m_entrymap.find(newentry->name()); - if (existing != NULL) - { - // if we're overriding existing entries, then remove the old one - if (override_existing) - { - core_options::entry *e = m_entrylist; - remove_entry(*existing); - delete e; - } - - // otherwise, just override the default and current values and throw out the new entry - else - { - existing->set_default_value(newentry->value()); - delete newentry; - continue; - } - } - } - - // add us to the list and maps - append_entry(*newentry); - } + add_entry(*entrylist, override_existing); } @@ -323,7 +311,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, astri // iterate through arguments int unadorned_index = 0; - bool retVal = true; + bool retval = true; for (int arg = 1; arg < argc; arg++) { // determine the entry name to search for @@ -336,7 +324,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, astri if (curentry == NULL) { error_string.catprintf("Error: unknown option: %s\n", curarg); - retVal = false; + retval = false; if (!is_unadorned) arg++; continue; } @@ -371,7 +359,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, astri // set the new data validate_and_set_data(*curentry, newdata, priority, error_string); } - return retVal; + return retval; } @@ -448,7 +436,7 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p void core_options::revert(int priority) { // iterate over options and revert to defaults if below the given priority - for (entry *curentry = m_entrylist; curentry != NULL; curentry = curentry->next()) + for (entry *curentry = m_entrylist.first(); curentry != NULL; curentry = curentry->next()) curentry->revert(priority); } @@ -469,7 +457,7 @@ const char *core_options::output_ini(astring &buffer, const core_options *diff) const char *last_header = NULL; // loop over all items - for (entry *curentry = m_entrylist; curentry != NULL; curentry = curentry->next()) + for (entry *curentry = m_entrylist.first(); curentry != NULL; curentry = curentry->next()) { const char *name = curentry->name(); const char *value = curentry->value(); @@ -529,7 +517,7 @@ const char *core_options::output_help(astring &buffer) buffer.reset(); // loop over all items - for (entry *curentry = m_entrylist; curentry != NULL; curentry = curentry->next()) + for (entry *curentry = m_entrylist.first(); curentry != NULL; curentry = curentry->next()) { // header: just print if (curentry->is_header()) @@ -629,6 +617,7 @@ void core_options::set_flag(const char *name, UINT32 mask, UINT32 flag) curentry->set_flag(mask, flag); } + //------------------------------------------------- // reset - reset the options state, removing // everything @@ -636,15 +625,7 @@ void core_options::set_flag(const char *name, UINT32 mask, UINT32 flag) void core_options::reset() { - // remove all entries from the list - while (m_entrylist != NULL) - { - core_options::entry *e = m_entrylist; - remove_entry(*m_entrylist); - delete e; - } - - // reset the map + m_entrylist.reset(); m_entrymap.reset(); } @@ -656,20 +637,17 @@ void core_options::reset() void core_options::append_entry(core_options::entry &newentry) { - // append to the list - *m_entrylist_tailptr = &newentry; - m_entrylist_tailptr = &newentry.m_next; + m_entrylist.append(newentry); // if we have names, add them to the map - astring tempstr; for (int name = 0; name < ARRAY_LENGTH(newentry.m_name); name++) - if (newentry.m_name[name]) + if (newentry.name(name) != NULL) { - m_entrymap.add(newentry.m_name[name], &newentry); + m_entrymap.add(newentry.name(name), &newentry); // for boolean options add a "no" variant as well if (newentry.type() == OPTION_BOOLEAN) - m_entrymap.add(tempstr.cpy("no").cat(newentry.m_name[name]), &newentry); + m_entrymap.add(astring("no", newentry.name(name)), &newentry); } } @@ -681,32 +659,13 @@ void core_options::append_entry(core_options::entry &newentry) void core_options::remove_entry(core_options::entry &delentry) { - // remove us from the list - entry *preventry = NULL; - for (entry *curentry = m_entrylist; curentry != NULL; curentry = curentry->next()) - if (curentry == &delentry) - { - // update link from previous to us - if (preventry != NULL) - preventry->m_next = delentry.m_next; - else - m_entrylist = delentry.m_next; + // remove all names from the map + for (int name = 0; name < ARRAY_LENGTH(delentry.m_name); name++) + if (delentry.m_name[name]) + m_entrymap.remove(delentry.m_name[name]); - // if we're the last item, update the next pointer - if (delentry.m_next == NULL) - { - if (preventry != NULL) - m_entrylist_tailptr = &preventry->m_next; - else - m_entrylist_tailptr = &m_entrylist; - } - - // remove all entries from the map - for (int name = 0; name < ARRAY_LENGTH(delentry.m_name); name++) - if (delentry.m_name[name]) - m_entrymap.remove(delentry.m_name[name]); - break; - } + // remove the entry from the list + m_entrylist.remove(delentry); } @@ -720,8 +679,8 @@ void core_options::copyfrom(const core_options &src) reset(); // iterate through the src options and make our own - for (entry *curentry = src.m_entrylist; curentry != NULL; curentry = curentry->next()) - append_entry(*new entry(*curentry)); + for (entry *curentry = src.m_entrylist.first(); curentry != NULL; curentry = curentry->next()) + append_entry(*global_alloc(entry(curentry->name(), curentry->description(), curentry->flags(), curentry->default_value()))); } @@ -802,15 +761,3 @@ bool core_options::validate_and_set_data(core_options::entry &curentry, const ch curentry.set_value(data, priority); return true; } - -//------------------------------------------------- -// options_count - take number of existing -// number of options in structure -//------------------------------------------------- - -int core_options::options_count() -{ - int number = 0; - for (entry *curentry = m_entrylist; curentry != NULL; curentry = curentry->next()) number++; - return number; -} diff --git a/src/lib/util/options.h b/src/lib/util/options.h index 75191bf1d5b..f90e56a0a23 100644 --- a/src/lib/util/options.h +++ b/src/lib/util/options.h @@ -68,14 +68,15 @@ public: class entry { friend class core_options; + friend class simple_list; // construction/destruction - entry(const options_entry &entry); + entry(const char *name, const char *description, UINT32 flags = 0, const char *defvalue = NULL); public: // getters entry *next() const { return m_next; } - const char *name() const { return m_name[0] ? m_name[0].cstr() : NULL; } + const char *name(int index = 0) const { return (index < ARRAY_LENGTH(m_name) && m_name[index]) ? m_name[index].cstr() : NULL; } const char *description() const { return m_description; } const char *value() const { return m_data; } const char *default_value() const { return m_defdata; } @@ -125,10 +126,12 @@ public: bool operator!=(const core_options &rhs); // getters - entry *first() const { return m_entrylist; } + entry *first() const { return m_entrylist.first(); } const char *command() const { return m_command; } // configuration + void add_entry(const char *name, const char *description, UINT32 flags = 0, const char *defvalue = NULL, bool override_existing = false); + void add_entry(const options_entry &data, bool override_existing = false) { add_entry(data.name, data.description, data.flags, data.defvalue, override_existing); } void add_entries(const options_entry *entrylist, bool override_existing = false); void set_default_value(const char *name, const char *defvalue); void remove_entry(entry &delentry); @@ -162,7 +165,8 @@ public: // misc static const char *unadorned(int x = 0) { return s_option_unadorned[MIN(x, MAX_UNADORNED_OPTIONS)]; } - int options_count(); + int options_count() const { return m_entrylist.count(); } + private: // internal helpers void reset(); @@ -171,8 +175,7 @@ private: bool validate_and_set_data(entry &curentry, const char *newdata, int priority, astring &error_string); // internal state - entry * m_entrylist; // head of list of entries - entry ** m_entrylist_tailptr; // pointer to tail of entry list + simple_list m_entrylist; // head of list of entries tagmap_t m_entrymap; // map for fast lookup astring m_command; // command found static const char *const s_option_unadorned[]; // array of unadorned option "names" diff --git a/src/lib/util/simple_set.h b/src/lib/util/simple_set.h index b0e2793cd76..9f9f127f6ec 100644 --- a/src/lib/util/simple_set.h +++ b/src/lib/util/simple_set.h @@ -40,9 +40,8 @@ class simple_set public: // Construction - simple_set(resource_pool &pool = global_resource_pool()) - : m_root(NULL), - m_pool(pool) + simple_set() + : m_root(NULL) { } simple_set(const simple_set& rhs) @@ -57,10 +56,6 @@ public: } - // A reference to the resource pool - resource_pool &pool() const { return m_pool; } - - // Returns number of elements in the tree -- O(n) int size() const { @@ -116,7 +111,7 @@ public: // If it's a leaf node, simply remove it removeNode(currNode); - pool_free(m_pool, currNode); + global_free(currNode); } else { @@ -145,7 +140,7 @@ public: tree_node* right = currNode->right; // We no longer need this node - pool_free(m_pool, currNode); + global_free(currNode); // Check to see if we removed the root node if (!parentNode) @@ -216,7 +211,7 @@ public: } else { - pool_free(m_pool, c); + global_free(c); } return retVal; @@ -258,10 +253,6 @@ private: // The AVL tree's root tree_node* m_root; - // Resource pool where objects are freed - resource_pool& m_pool; - - // Find a node in the tree tree_node* findNode(const T& x) const { @@ -282,7 +273,7 @@ private: { if (t == NULL) { - t = pool_alloc(m_pool, tree_node(x, NULL, NULL, NULL)); + t = global_alloc(tree_node(x, NULL, NULL, NULL)); // An empty sub-tree here, insertion successful return true; @@ -353,7 +344,7 @@ private: clearRecurse(t->left); clearRecurse(t->right); - pool_free(m_pool, t); + global_free(t); } t = NULL; } @@ -485,7 +476,7 @@ private: else { // Create a node with the left and right nodes and a parent set to NULL - tree_node* retVal = pool_alloc(m_pool, tree_node(t->element, NULL, clone(t->left), clone(t->right))); + tree_node* retVal = global_alloc(tree_node(t->element, NULL, clone(t->left), clone(t->right))); // Now set our children's parent node reference if (retVal->left) { retVal->left->setParent(retVal); } diff --git a/src/lib/util/tagmap.h b/src/lib/util/tagmap.h index 07acdaa26da..d35922a49b0 100644 --- a/src/lib/util/tagmap.h +++ b/src/lib/util/tagmap.h @@ -14,6 +14,7 @@ #define __TAGMAP_H__ #include "osdcore.h" +#include "coretmpl.h" #include "astring.h" #ifdef MAME_DEBUG #include "eminline.h" @@ -183,7 +184,7 @@ private: { entry_t *entry = *entryptr; *entryptr = entry->next(); - delete entry; + global_free(entry); } // internal state @@ -191,6 +192,110 @@ private: }; +// ======================> tagged_list + +// a tagged_list is a class that maintains a list of objects that can be quickly looked up by tag +template +class tagged_list +{ + // we don't support deep copying + tagged_list(const tagged_list &); + tagged_list &operator=(const tagged_list &); + +public: + class add_exception + { + public: + add_exception(const char *tag) : m_tag(tag) { } + const char *tag() const { return m_tag; } + private: + const char *m_tag; + }; + + // construction + tagged_list() { } + + // simple getters + _ElementType *first() const { return m_list.first(); } + _ElementType *last() const { return m_list.last(); } + int count() const { return m_list.count(); } + + // remove (free) all objects in the list, leaving an empty list + void reset() { m_list.reset(); m_map.reset(); } + + // add the given object to the head of the list + _ElementType &prepend(const char *tag, _ElementType &object) + { + if (m_map.add_unique_hash(tag, &object, false) != TMERR_NONE) + throw add_exception(tag); + return m_list.prepend(object); + } + + // add the given object to the tail of the list + _ElementType &append(const char *tag, _ElementType &object) + { + if (m_map.add_unique_hash(tag, &object, false) != TMERR_NONE) + throw add_exception(tag); + return m_list.append(object); + } + + // insert the given object after a particular object (NULL means prepend) + _ElementType &insert_after(const char *tag, _ElementType &object, _ElementType *insert_after) + { + if (m_map.add_unique_hash(tag, &object, false) != TMERR_NONE) + throw add_exception(tag); + return m_list.insert_after(object, insert_after); + } + + // replace an item in the list at the same location, and remove it + _ElementType &replace_and_remove(const char *tag, _ElementType &object, _ElementType &toreplace) + { + m_map.remove(&toreplace); + m_list.replace_and_remove(object, toreplace); + if (m_map.add_unique_hash(tag, &object, false) != TMERR_NONE) + throw add_exception(tag); + return object; + } + + // detach the given item from the list, but don't free its memory + _ElementType &detach(_ElementType &object) + { + m_map.remove(&object); + return m_list.detach(object); + } + + // remove the given object and free its memory + void remove(_ElementType &object) + { + m_map.remove(&object); + return m_list.remove(object); + } + + // find an object by index in the list + _ElementType *find(int index) const + { + return m_list.find(index); + } + + // return the index of the given object in the list + int indexof(const _ElementType &object) const + { + return m_list.indexof(object); + } + + // operations by tag + _ElementType &replace_and_remove(const char *tag, _ElementType &object) { _ElementType *existing = find(tag); return (existing == NULL) ? append(tag, object) : replace_and_remove(tag, object, *existing); } + void remove(const char *tag) { _ElementType *object = find(tag); if (object != NULL) remove(*object); } + _ElementType *find(const char *tag) const { return m_map.find_hash_only(tag); } + int indexof(const char *tag) const { _ElementType *object = find(tag); return (object != NULL) ? m_list.indexof(*object) : NULL; } + +private: + // internal state + simple_list<_ElementType> m_list; + tagmap_t<_ElementType *> m_map; +}; + + //************************************************************************** // IMPLEMENTATION @@ -218,7 +323,7 @@ tagmap_error tagmap_t<_ElementType, _HashSize>::add_common(const char *tag, _Ele } // now allocate a new entry and add to the head of the list - entry_t *entry = new entry_t(tag, fullhash, object); + entry_t *entry = global_alloc(entry_t(tag, fullhash, object)); entry->m_next = m_table[hashindex]; m_table[hashindex] = entry; return TMERR_NONE; diff --git a/src/lib/util/xmlfile.c b/src/lib/util/xmlfile.c index 568d0737144..2c8d78cdcdb 100644 --- a/src/lib/util/xmlfile.c +++ b/src/lib/util/xmlfile.c @@ -564,17 +564,29 @@ const char *xml_normalize_string(const char *string) static void *expat_malloc(size_t size) { - return malloc(size); -} - -static void *expat_realloc(void *ptr, size_t size) -{ - return realloc(ptr, size); + UINT32 *result = (UINT32 *)malloc(size + 4 * sizeof(UINT32)); + *result = size; + return &result[4]; } static void expat_free(void *ptr) { - free(ptr); + if (ptr != NULL) + free(&((UINT32 *)ptr)[-4]); +} + +static void *expat_realloc(void *ptr, size_t size) +{ + void *newptr = expat_malloc(size); + if (newptr == NULL) + return NULL; + if (ptr != NULL) + { + UINT32 oldsize = ((UINT32 *)ptr)[-4]; + memcpy(newptr, ptr, oldsize); + expat_free(ptr); + } + return newptr; } @@ -658,7 +670,7 @@ static void expat_element_start(void *data, const XML_Char *name, const XML_Char /*------------------------------------------------- - expat_data - expat callback for a additional + expat_data - expat callback for an additional element data -------------------------------------------------*/ @@ -678,9 +690,15 @@ static void expat_data(void *data, const XML_Char *s, int len) oldlen = (int)strlen((*curnode)->value); /* realloc */ - newdata = (char *)realloc((void *)(*curnode)->value, oldlen + len + 1); + newdata = (char *)malloc(oldlen + len + 1); if (newdata == NULL) return; + if ((*curnode)->value != NULL) + { + memcpy(newdata, (*curnode)->value, oldlen); + free((*curnode)->value); + } + (*curnode)->value = newdata; /* copy in the new data a NULL-terminate */ memcpy(&newdata[oldlen], s, len); diff --git a/src/mame/audio/namco52.c b/src/mame/audio/namco52.c index 7e9c1805f7f..bcd3a127eee 100644 --- a/src/mame/audio/namco52.c +++ b/src/mame/audio/namco52.c @@ -234,6 +234,11 @@ namco_52xx_device::namco_52xx_device(const machine_config &mconfig, const char * m_token = global_alloc_clear(namco_52xx_state); } +namco_52xx_device::~namco_52xx_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- diff --git a/src/mame/audio/namco52.h b/src/mame/audio/namco52.h index b5dfb233e38..48c00b8262d 100644 --- a/src/mame/audio/namco52.h +++ b/src/mame/audio/namco52.h @@ -28,10 +28,10 @@ class namco_52xx_device : public device_t { public: namco_52xx_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~namco_52xx_device() { global_free(m_token); } + ~namco_52xx_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct namco_52xx_state *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_start(); @@ -39,7 +39,7 @@ protected: virtual machine_config_constructor device_mconfig_additions() const; private: // internal state - void *m_token; + struct namco_52xx_state *m_token; }; extern const device_type NAMCO_52XX; diff --git a/src/mame/audio/namco54.c b/src/mame/audio/namco54.c index 434de1ffc0c..e14d9b3cb6e 100644 --- a/src/mame/audio/namco54.c +++ b/src/mame/audio/namco54.c @@ -190,6 +190,11 @@ namco_54xx_device::namco_54xx_device(const machine_config &mconfig, const char * m_token = global_alloc_clear(namco_54xx_state); } +namco_54xx_device::~namco_54xx_device() +{ + global_free(m_token); +} + //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- diff --git a/src/mame/audio/namco54.h b/src/mame/audio/namco54.h index 57e5e88f847..3dd9c61d58c 100644 --- a/src/mame/audio/namco54.h +++ b/src/mame/audio/namco54.h @@ -25,10 +25,10 @@ class namco_54xx_device : public device_t { public: namco_54xx_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~namco_54xx_device() { global_free(m_token); } + ~namco_54xx_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct namco_54xx_state *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_start(); @@ -36,7 +36,7 @@ protected: virtual machine_config_constructor device_mconfig_additions() const; private: // internal state - void *m_token; + struct namco_54xx_state *m_token; }; extern const device_type NAMCO_54XX; diff --git a/src/mame/drivers/8080bw.c b/src/mame/drivers/8080bw.c index 08e1feed3b2..cd5836031d1 100644 --- a/src/mame/drivers/8080bw.c +++ b/src/mame/drivers/8080bw.c @@ -2658,7 +2658,7 @@ DRIVER_INIT_MEMBER(_8080bw_state,vortex) { UINT8 *rom = memregion("maincpu")->base(); int length = memregion("maincpu")->bytes(); - UINT8 *buf1 = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer buf1(length); UINT32 x; for (x = 0; x < length; x++) { @@ -2699,8 +2699,6 @@ DRIVER_INIT_MEMBER(_8080bw_state,vortex) } memcpy(rom, buf1, length); - - auto_free(machine(), buf1); } @@ -3074,14 +3072,13 @@ DRIVER_INIT_MEMBER(_8080bw_state,attackfc) { UINT8 *rom = memregion("maincpu")->base(); UINT32 len = memregion("maincpu")->bytes(); - UINT8 *buffer = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer buffer(len); // swap a8/a9 for (int i = 0; i < len; i++) buffer[BITSWAP16(i, 15,14,13,12,11,10,8,9, 7,6,5,4,3,2,1,0)] = rom[i]; memcpy(rom, buffer, len); - auto_free(machine(), buffer); } diff --git a/src/mame/drivers/alg.c b/src/mame/drivers/alg.c index e35127324d7..eec129f9aae 100644 --- a/src/mame/drivers/alg.c +++ b/src/mame/drivers/alg.c @@ -724,7 +724,7 @@ DRIVER_INIT_MEMBER(alg_state,palr1) { UINT32 length = memregion("user2")->bytes(); UINT8 *rom = memregion("user2")->base(); - UINT8 *original = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer original(length); UINT32 srcaddr; memcpy(original, rom, length); @@ -735,7 +735,6 @@ DRIVER_INIT_MEMBER(alg_state,palr1) if (srcaddr & 0x8000) dstaddr ^= 0x4000; rom[dstaddr] = original[srcaddr]; } - auto_free(machine(), original); alg_init(); } @@ -744,7 +743,7 @@ DRIVER_INIT_MEMBER(alg_state,palr3) { UINT32 length = memregion("user2")->bytes(); UINT8 *rom = memregion("user2")->base(); - UINT8 *original = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer original(length); UINT32 srcaddr; memcpy(original, rom, length); @@ -754,7 +753,6 @@ DRIVER_INIT_MEMBER(alg_state,palr3) if (srcaddr & 0x2000) dstaddr ^= 0x1000; rom[dstaddr] = original[srcaddr]; } - auto_free(machine(), original); alg_init(); } @@ -763,7 +761,7 @@ DRIVER_INIT_MEMBER(alg_state,palr6) { UINT32 length = memregion("user2")->bytes(); UINT8 *rom = memregion("user2")->base(); - UINT8 *original = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer original(length); UINT32 srcaddr; memcpy(original, rom, length); @@ -775,7 +773,6 @@ DRIVER_INIT_MEMBER(alg_state,palr6) dstaddr ^= 0x20000; rom[dstaddr] = original[srcaddr]; } - auto_free(machine(), original); alg_init(); } diff --git a/src/mame/drivers/arkanoid.c b/src/mame/drivers/arkanoid.c index 2ac4cb26e10..539724677e6 100644 --- a/src/mame/drivers/arkanoid.c +++ b/src/mame/drivers/arkanoid.c @@ -1800,7 +1800,7 @@ DRIVER_INIT_MEMBER(arkanoid_state,block2) // the graphics on this bootleg have the data scrambled int tile; UINT8* srcgfx = memregion("gfx1")->base(); - UINT8* buffer = auto_alloc_array(machine(), UINT8, 0x18000); + dynamic_buffer buffer(0x18000); for (tile = 0; tile < 0x3000; tile++) { @@ -1824,8 +1824,6 @@ DRIVER_INIT_MEMBER(arkanoid_state,block2) memcpy(srcgfx, buffer, 0x18000); - auto_free(machine(), buffer); - m_bootleg_id = BLOCK2; arkanoid_bootleg_init(); } diff --git a/src/mame/drivers/backfire.c b/src/mame/drivers/backfire.c index 7c02ba493ef..094148e8bf4 100644 --- a/src/mame/drivers/backfire.c +++ b/src/mame/drivers/backfire.c @@ -684,7 +684,7 @@ void backfire_state::descramble_sound() { UINT8 *rom = memregion("ymz")->base(); int length = 0x200000; // only the first rom is swapped on backfire! - UINT8 *buf1 = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer buf1(length); UINT32 x; for (x = 0; x < length; x++) @@ -702,8 +702,6 @@ void backfire_state::descramble_sound() } memcpy(rom, buf1, length); - - auto_free(machine(), buf1); } READ32_MEMBER(backfire_state::backfire_speedup_r) diff --git a/src/mame/drivers/balsente.c b/src/mame/drivers/balsente.c index d4fd59d3748..b6cace1d9c7 100644 --- a/src/mame/drivers/balsente.c +++ b/src/mame/drivers/balsente.c @@ -2075,7 +2075,7 @@ void balsente_state::expand_roms(UINT8 cd_rom_mask) /* load EF from 0x2e000-0x30000 */ /* ROM region must be 0x40000 total */ - UINT8 *temp = auto_alloc_array(machine(), UINT8, 0x20000); + dynamic_buffer temp(0x20000); { UINT8 *rom = memregion("maincpu")->base(); UINT32 len = memregion("maincpu")->bytes(); @@ -2129,8 +2129,6 @@ void balsente_state::expand_roms(UINT8 cd_rom_mask) memcpy(&rom[base + 0x02000], (cd_rom_mask & 0x01) ? &cd_base[0x0000] : cd_common, 0x2000); memcpy(&rom[base + 0x00000], &ab_base[0x0000], 0x2000); } - - auto_free(machine(), temp); } } diff --git a/src/mame/drivers/bfcobra.c b/src/mame/drivers/bfcobra.c index ffcc01f012d..50a13ae7554 100644 --- a/src/mame/drivers/bfcobra.c +++ b/src/mame/drivers/bfcobra.c @@ -1662,9 +1662,8 @@ DRIVER_INIT_MEMBER(bfcobra_state,bfcobra) UINT32 i; UINT8 *rom; - UINT8 *tmp; - tmp = auto_alloc_array(machine(), UINT8, 0x8000); + dynamic_buffer tmp(0x8000); rom = memregion("audiocpu")->base() + 0x8000; memcpy(tmp, rom, 0x8000); @@ -1684,8 +1683,6 @@ DRIVER_INIT_MEMBER(bfcobra_state,bfcobra) rom[addr] = data; } - auto_free(machine(), tmp); - init_ram(); m_bank_data[0] = 1; diff --git a/src/mame/drivers/cave.c b/src/mame/drivers/cave.c index ea6c4e729a5..eead7eb132d 100644 --- a/src/mame/drivers/cave.c +++ b/src/mame/drivers/cave.c @@ -4820,7 +4820,6 @@ DRIVER_INIT_MEMBER(cave_state,hotdogst) DRIVER_INIT_MEMBER(cave_state,mazinger) { UINT8 *ROM = memregion("audiocpu")->base(); - UINT8 *buffer; UINT8 *src = memregion("sprites0")->base(); int len = memregion("sprites0")->bytes(); @@ -4833,13 +4832,12 @@ DRIVER_INIT_MEMBER(cave_state,mazinger) membank("okibank2")->configure_entries(0, 4, &ROM[0x00000], 0x20000); /* decrypt sprites */ - buffer = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer buffer(len); { int i; for (i = 0; i < len; i++) buffer[i ^ 0xdf88] = src[BITSWAP24(i,23,22,21,20,19,9,7,3,15,4,17,14,18,2,16,5,11,8,6,13,1,10,12,0)]; memcpy(src, buffer, len); - auto_free(machine(), buffer); } unpack_sprites("sprites0"); @@ -4888,7 +4886,6 @@ DRIVER_INIT_MEMBER(cave_state,ppsatan) DRIVER_INIT_MEMBER(cave_state,pwrinst2j) { UINT8 *ROM = memregion("audiocpu")->base(); - UINT8 *buffer; UINT8 *src = memregion("sprites0")->base(); int len = memregion("sprites0")->bytes(); int i, j; @@ -4897,7 +4894,7 @@ DRIVER_INIT_MEMBER(cave_state,pwrinst2j) membank("z80bank")->configure_entries(0, 8, &ROM[0x00000], 0x4000); - buffer = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer buffer(len); { for(i = 0; i < len/2; i++) { @@ -4908,7 +4905,6 @@ DRIVER_INIT_MEMBER(cave_state,pwrinst2j) } memcpy(src,buffer,len); - auto_free(machine(), buffer); } unpack_sprites("sprites0"); @@ -4935,7 +4931,6 @@ DRIVER_INIT_MEMBER(cave_state,pwrinst2) DRIVER_INIT_MEMBER(cave_state,sailormn) { UINT8 *ROM = memregion("audiocpu")->base(); - UINT8 *buffer; UINT8 *src = memregion("sprites0")->base(); int len = memregion("sprites0")->bytes(); @@ -4952,13 +4947,12 @@ DRIVER_INIT_MEMBER(cave_state,sailormn) membank("oki2bank2")->configure_entries(0, 0x10, &ROM[0x00000], 0x20000); /* decrypt sprites */ - buffer = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer buffer(len); { int i; for (i = 0; i < len; i++) buffer[i ^ 0x950c4] = src[BITSWAP24(i,23,22,21,20,15,10,12,6,11,1,13,3,16,17,2,5,14,7,18,8,4,19,9,0)]; memcpy(src, buffer, len); - auto_free(machine(), buffer); } sailormn_unpack_tiles( machine(), "layer2" ); diff --git a/src/mame/drivers/coinmstr.c b/src/mame/drivers/coinmstr.c index 618653d9499..96f5a65f72b 100644 --- a/src/mame/drivers/coinmstr.c +++ b/src/mame/drivers/coinmstr.c @@ -1389,7 +1389,7 @@ DRIVER_INIT_MEMBER(coinmstr_state,coinmstr) { UINT8 *rom = memregion("user1")->base(); int length = memregion("user1")->bytes(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer buf(length); int i; memcpy(buf,rom,length); @@ -1399,8 +1399,6 @@ DRIVER_INIT_MEMBER(coinmstr_state,coinmstr) int adr = BITSWAP24(i, 23,22,21,20,19,18,17,16,15, 14,8,7,2,5,12,10,9,11,13,3,6,0,1,4); rom[i] = BITSWAP8(buf[adr],3,2,4,1,5,0,6,7); } - - auto_free(machine(), buf); } diff --git a/src/mame/drivers/coolridr.c b/src/mame/drivers/coolridr.c index f0fce39ea6d..ccddd292b52 100644 --- a/src/mame/drivers/coolridr.c +++ b/src/mame/drivers/coolridr.c @@ -565,7 +565,7 @@ void coolridr_state::video_start() m_screen->register_screen_bitmap(m_screen1_bitmap); m_screen->register_screen_bitmap(m_screen2_bitmap); - m_gfxdecode->set_gfx(m_gfx_index, auto_alloc(machine(), gfx_element(m_palette, h1_tile_layout, m_h1_pcg, 8, 0))); + m_gfxdecode->set_gfx(m_gfx_index, global_alloc(gfx_element(m_palette, h1_tile_layout, m_h1_pcg, 8, 0))); } /* diff --git a/src/mame/drivers/cps2.c b/src/mame/drivers/cps2.c index 48f4356b003..6caf02448c2 100644 --- a/src/mame/drivers/cps2.c +++ b/src/mame/drivers/cps2.c @@ -8496,15 +8496,13 @@ void cps_state::gigaman2_gfx_reorder() int i; int length = memregion( "gfx" )->bytes(); UINT16 *rom = (UINT16 *)memregion("gfx")->base(); - UINT16 *buf = auto_alloc_array(machine(), UINT16, length ); + dynamic_array buf( length ); memcpy (buf, rom, length); for (i = 0; i < length/2; i++) { rom[i] = buf[((i & ~7) >> 2) | ((i & 4) << 18) | ((i & 2) >> 1) | ((i & 1) << 21)]; } - - auto_free( machine(), buf ); } DRIVER_INIT_MEMBER(cps_state,gigaman2) diff --git a/src/mame/drivers/cps3.c b/src/mame/drivers/cps3.c index eda556159c4..9a96eaf5b41 100644 --- a/src/mame/drivers/cps3.c +++ b/src/mame/drivers/cps3.c @@ -904,12 +904,12 @@ void cps3_state::video_start() save_pointer(NAME(m_char_ram), 0x800000 /4); /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(0, auto_alloc(machine(), gfx_element(m_palette, cps3_tiles8x8_layout, (UINT8 *)m_ss_ram, m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(0, global_alloc(gfx_element(m_palette, cps3_tiles8x8_layout, (UINT8 *)m_ss_ram, m_palette->entries() / 16, 0))); //decode_ssram(); /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(1, auto_alloc(machine(), gfx_element(m_palette, cps3_tiles16x16_layout, (UINT8 *)m_char_ram, m_palette->entries() / 64, 0))); + m_gfxdecode->set_gfx(1, global_alloc(gfx_element(m_palette, cps3_tiles16x16_layout, (UINT8 *)m_char_ram, m_palette->entries() / 64, 0))); m_gfxdecode->gfx(1)->set_granularity(64); //decode_charram(); diff --git a/src/mame/drivers/darkmist.c b/src/mame/drivers/darkmist.c index 94dfc494c1f..5ce73313a21 100644 --- a/src/mame/drivers/darkmist.c +++ b/src/mame/drivers/darkmist.c @@ -313,7 +313,7 @@ ROM_END void darkmist_state::decrypt_gfx() { - UINT8 *buf = auto_alloc_array(machine(), UINT8, 0x40000); + dynamic_buffer buf(0x40000); UINT8 *rom; int size; int i; @@ -385,8 +385,6 @@ void darkmist_state::decrypt_gfx() { rom[i] = buf[BITSWAP24(i, 23,22,21,20,19,18,17,16,15,14, 12,11,10,9,8, 5,4,3, 13, 7,6, 1,0, 2)]; } - - auto_free(machine(), buf); } void darkmist_state::decrypt_snd() @@ -403,7 +401,7 @@ DRIVER_INIT_MEMBER(darkmist_state,darkmist) address_space &space = m_maincpu->space(AS_PROGRAM); int i, len; UINT8 *ROM = memregion("maincpu")->base(); - UINT8 *buffer = auto_alloc_array(machine(), UINT8, 0x10000); + dynamic_buffer buffer(0x10000); UINT8 *decrypt = auto_alloc_array(machine(), UINT8, 0x8000); decrypt_gfx(); @@ -470,8 +468,6 @@ DRIVER_INIT_MEMBER(darkmist_state,darkmist) { ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14 ,5,4,3,2,11,10,9,8,13,12,1,0,7,6)]; } - - auto_free(machine(), buffer); } GAME( 1986, darkmist, 0, darkmist, darkmist, darkmist_state, darkmist, ROT270, "Taito Corporation", "The Lost Castle In Darkmist", GAME_IMPERFECT_GRAPHICS|GAME_NO_COCKTAIL ) diff --git a/src/mame/drivers/dassault.c b/src/mame/drivers/dassault.c index a630a89b50f..1ad6887cbca 100644 --- a/src/mame/drivers/dassault.c +++ b/src/mame/drivers/dassault.c @@ -971,7 +971,7 @@ DRIVER_INIT_MEMBER(dassault_state,dassault) { const UINT8 *src = memregion("gfx1")->base(); UINT8 *dst = memregion("gfx2")->base(); - UINT8 *tmp = auto_alloc_array(machine(), UINT8, 0x80000); + dynamic_buffer tmp(0x80000); /* Playfield 4 also has access to the char graphics, make things easier by just copying the chars to both banks (if I just used a different gfx @@ -980,15 +980,13 @@ DRIVER_INIT_MEMBER(dassault_state,dassault) memcpy(dst + 0x090000, tmp + 0x00000, 0x80000); memcpy(dst + 0x080000, src + 0x00000, 0x10000); memcpy(dst + 0x110000, src + 0x10000, 0x10000); - - auto_free(machine(), tmp); } DRIVER_INIT_MEMBER(dassault_state,thndzone) { const UINT8 *src = memregion("gfx1")->base(); UINT8 *dst = memregion("gfx2")->base(); - UINT8 *tmp = auto_alloc_array(machine(), UINT8, 0x80000); + dynamic_buffer tmp(0x80000); /* Playfield 4 also has access to the char graphics, make things easier by just copying the chars to both banks (if I just used a different gfx @@ -997,8 +995,6 @@ DRIVER_INIT_MEMBER(dassault_state,thndzone) memcpy(dst + 0x090000, tmp + 0x00000, 0x80000); memcpy(dst + 0x080000, src + 0x00000, 0x10000); memcpy(dst + 0x110000, src + 0x10000, 0x10000); - - auto_free(machine(), tmp); } /**********************************************************************************/ diff --git a/src/mame/drivers/ddayjlc.c b/src/mame/drivers/ddayjlc.c index 79c943eedfb..c7e2787ad00 100644 --- a/src/mame/drivers/ddayjlc.c +++ b/src/mame/drivers/ddayjlc.c @@ -669,8 +669,8 @@ DRIVER_INIT_MEMBER(ddayjlc_state,ddayjlc) { UINT32 oldaddr, newadr, length,j; - UINT8 *src, *dst, *temp; - temp = auto_alloc_array(machine(), UINT8, 0x10000); + UINT8 *src, *dst; + dynamic_buffer temp(0x10000); src = temp; dst = memregion("gfx1")->base(); length = memregion("gfx1")->bytes(); @@ -684,7 +684,6 @@ DRIVER_INIT_MEMBER(ddayjlc_state,ddayjlc) newadr += 32; oldaddr += 16; } - auto_free(machine(), temp); } membank("bank1")->configure_entries(0, 3, memregion("user1")->base(), 0x4000); diff --git a/src/mame/drivers/deco156.c b/src/mame/drivers/deco156.c index bdf93f7f29c..468726d8abd 100644 --- a/src/mame/drivers/deco156.c +++ b/src/mame/drivers/deco156.c @@ -629,7 +629,7 @@ void deco156_state::descramble_sound( const char *tag ) { UINT8 *rom = memregion(tag)->base(); int length = memregion(tag)->bytes(); - UINT8 *buf1 = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer buf1(length); UINT32 x; for (x = 0; x < length; x++) @@ -647,8 +647,6 @@ void deco156_state::descramble_sound( const char *tag ) } memcpy(rom,buf1,length); - - auto_free(machine(), buf1); } DRIVER_INIT_MEMBER(deco156_state,hvysmsh) diff --git a/src/mame/drivers/deco32.c b/src/mame/drivers/deco32.c index 9c52c4c3af1..6a286ad35b6 100644 --- a/src/mame/drivers/deco32.c +++ b/src/mame/drivers/deco32.c @@ -3641,7 +3641,7 @@ DRIVER_INIT_MEMBER(dragngun_state,lockload) DRIVER_INIT_MEMBER(deco32_state,tattass) { UINT8 *RAM = memregion("gfx1")->base(); - UINT8 *tmp = auto_alloc_array(machine(), UINT8, 0x80000); + dynamic_buffer tmp(0x80000); /* Reorder bitplanes to make decoding easier */ memcpy(tmp,RAM+0x80000,0x80000); @@ -3653,8 +3653,6 @@ DRIVER_INIT_MEMBER(deco32_state,tattass) memcpy(RAM+0x80000,RAM+0x100000,0x80000); memcpy(RAM+0x100000,tmp,0x80000); - auto_free(machine(), tmp); - deco56_decrypt_gfx(machine(), "gfx1"); /* 141 */ deco56_decrypt_gfx(machine(), "gfx2"); /* 141 */ } @@ -3662,7 +3660,7 @@ DRIVER_INIT_MEMBER(deco32_state,tattass) DRIVER_INIT_MEMBER(deco32_state,nslasher) { UINT8 *RAM = memregion("gfx1")->base(); - UINT8 *tmp = auto_alloc_array(machine(), UINT8, 0x80000); + dynamic_buffer tmp(0x80000); /* Reorder bitplanes to make decoding easier */ memcpy(tmp,RAM+0x80000,0x80000); @@ -3674,8 +3672,6 @@ DRIVER_INIT_MEMBER(deco32_state,nslasher) memcpy(RAM+0x80000,RAM+0x100000,0x80000); memcpy(RAM+0x100000,tmp,0x80000); - auto_free(machine(), tmp); - deco56_decrypt_gfx(machine(), "gfx1"); /* 141 */ deco74_decrypt_gfx(machine(), "gfx2"); diff --git a/src/mame/drivers/deco_mlc.c b/src/mame/drivers/deco_mlc.c index 2e57b32a1d3..570697591e7 100644 --- a/src/mame/drivers/deco_mlc.c +++ b/src/mame/drivers/deco_mlc.c @@ -801,7 +801,7 @@ void deco_mlc_state::descramble_sound( ) /* the same as simpl156 / heavy smash? */ UINT8 *rom = memregion("ymz")->base(); int length = memregion("ymz")->bytes(); - UINT8 *buf1 = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer buf1(length); UINT32 x; @@ -820,8 +820,6 @@ void deco_mlc_state::descramble_sound( ) } memcpy(rom,buf1,length); - - auto_free(machine(), buf1); } READ32_MEMBER(deco_mlc_state::avengrgs_speedup_r) diff --git a/src/mame/drivers/dynax.c b/src/mame/drivers/dynax.c index 7ec6a0d3e43..363a84c2e57 100644 --- a/src/mame/drivers/dynax.c +++ b/src/mame/drivers/dynax.c @@ -5121,11 +5121,12 @@ DRIVER_INIT_MEMBER(dynax_state,maya) } /* Address lines scrambling on the blitter data roms */ - rom = auto_alloc_array(machine(), UINT8, 0xc0000); - memcpy(rom, gfx, 0xc0000); - for (i = 0; i < 0xc0000; i++) - gfx[i] = rom[BITSWAP24(i,23,22,21,20,19,18,14,15, 16,17,13,12,11,10,9,8, 7,6,5,4,3,2,1,0)]; - auto_free(machine(), rom); + { + dynamic_buffer rom(0xc0000); + memcpy(rom, gfx, 0xc0000); + for (i = 0; i < 0xc0000; i++) + gfx[i] = rom[BITSWAP24(i,23,22,21,20,19,18,14,15, 16,17,13,12,11,10,9,8, 7,6,5,4,3,2,1,0)]; + } } @@ -5921,12 +5922,11 @@ DRIVER_INIT_MEMBER(dynax_state,mjelct3) int i; UINT8 *rom = memregion("maincpu")->base(); size_t size = memregion("maincpu")->bytes(); - UINT8 *rom1 = auto_alloc_array(machine(), UINT8, size); + dynamic_buffer rom1(size); memcpy(rom1, rom, size); for (i = 0; i < size; i++) rom[i] = BITSWAP8(rom1[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8, 1,6,5,4,3,2,7, 0)], 7,6, 1,4,3,2,5,0); - auto_free(machine(), rom1); } DRIVER_INIT_MEMBER(dynax_state,mjelct3a) @@ -5934,7 +5934,7 @@ DRIVER_INIT_MEMBER(dynax_state,mjelct3a) int i, j; UINT8 *rom = memregion("maincpu")->base(); size_t size = memregion("maincpu")->bytes(); - UINT8 *rom1 = auto_alloc_array(machine(), UINT8, size); + dynamic_buffer rom1(size); memcpy(rom1, rom, size); for (i = 0; i < size; i++) @@ -5964,7 +5964,6 @@ DRIVER_INIT_MEMBER(dynax_state,mjelct3a) } rom[j] = rom1[i]; } - auto_free(machine(), rom1); DRIVER_INIT_CALL(mjelct3); } diff --git a/src/mame/drivers/exerion.c b/src/mame/drivers/exerion.c index eb27093adba..11ab5ec66f0 100644 --- a/src/mame/drivers/exerion.c +++ b/src/mame/drivers/exerion.c @@ -524,10 +524,10 @@ ROM_END DRIVER_INIT_MEMBER(exerion_state,exerion) { UINT32 oldaddr, newaddr, length; - UINT8 *src, *dst, *temp; + UINT8 *src, *dst; /* allocate some temporary space */ - temp = auto_alloc_array(machine(), UINT8, 0x10000); + dynamic_buffer temp(0x10000); /* make a temporary copy of the character data */ src = temp; @@ -565,8 +565,6 @@ DRIVER_INIT_MEMBER(exerion_state,exerion) ((oldaddr ) & 0xc003); /* keep n9-n8 h3-h2 */ dst[newaddr] = src[oldaddr]; } - - auto_free(machine(), temp); } diff --git a/src/mame/drivers/fcombat.c b/src/mame/drivers/fcombat.c index 4f31051a8f2..32c197fb557 100644 --- a/src/mame/drivers/fcombat.c +++ b/src/mame/drivers/fcombat.c @@ -321,10 +321,10 @@ MACHINE_CONFIG_END DRIVER_INIT_MEMBER(fcombat_state,fcombat) { UINT32 oldaddr, newaddr, length; - UINT8 *src, *dst, *temp; + UINT8 *src, *dst; /* allocate some temporary space */ - temp = auto_alloc_array(machine(), UINT8, 0x10000); + dynamic_buffer temp(0x10000); /* make a temporary copy of the character data */ src = temp; @@ -407,8 +407,6 @@ DRIVER_INIT_MEMBER(fcombat_state,fcombat) memcpy(&dst[oldaddr * 32 * 8 * 2], &src[oldaddr * 32 * 8], 32 * 8); memcpy(&dst[oldaddr * 32 * 8 * 2 + 32 * 8], &src[oldaddr * 32 * 8 + 0x2000], 32 * 8); } - - auto_free(machine(), temp); } ROM_START( fcombat ) diff --git a/src/mame/drivers/forte2.c b/src/mame/drivers/forte2.c index 7183a3060bc..429b6c8d1f4 100644 --- a/src/mame/drivers/forte2.c +++ b/src/mame/drivers/forte2.c @@ -145,7 +145,6 @@ DRIVER_INIT_MEMBER(forte2_state,pesadelo) int i; UINT8 *mem = memregion("maincpu")->base(); int memsize = memregion("maincpu")->bytes(); - UINT8 *buf; // data swap for ( i = 0; i < memsize; i++ ) @@ -154,13 +153,12 @@ DRIVER_INIT_MEMBER(forte2_state,pesadelo) } // address line swap - buf = auto_alloc_array(machine(), UINT8, memsize); + dynamic_buffer buf(memsize); memcpy(buf, mem, memsize); for ( i = 0; i < memsize; i++ ) { mem[BITSWAP16(i,11,9,8,13,14,15,12,7,6,5,4,3,2,1,0,10)] = buf[i]; } - auto_free(machine(), buf); } diff --git a/src/mame/drivers/funworld.c b/src/mame/drivers/funworld.c index 1c7abeeb945..9635ccfd4c8 100644 --- a/src/mame/drivers/funworld.c +++ b/src/mame/drivers/funworld.c @@ -5840,7 +5840,6 @@ DRIVER_INIT_MEMBER(funworld_state, saloon) int sizep = memregion("proms")->bytes(); int startp = 0; - UINT8 *buffer; int i, a; /***************************** @@ -5854,37 +5853,37 @@ DRIVER_INIT_MEMBER(funworld_state, saloon) rom[i] = BITSWAP8(rom[i], 7, 6, 5, 4, 3, 0, 1, 2); } - buffer = auto_alloc_array(machine(), UINT8, size); - memcpy(buffer, rom, size); - - - /* address lines swap: fedcba9876543210 -> fedcba9820134567 */ - - for (i = start; i < size; i++) { - a = ((i & 0xff00) | BITSWAP8(i & 0xff, 2, 0, 1, 3, 4, 5, 6, 7)); - rom[a] = buffer[i]; - } + dynamic_buffer buffer(size); + memcpy(buffer, rom, size); - auto_free(machine(), buffer); + + /* address lines swap: fedcba9876543210 -> fedcba9820134567 */ + + for (i = start; i < size; i++) + { + a = ((i & 0xff00) | BITSWAP8(i & 0xff, 2, 0, 1, 3, 4, 5, 6, 7)); + rom[a] = buffer[i]; + } + } /****************************** * Graphics ROM decryption * ******************************/ - buffer = auto_alloc_array(machine(), UINT8, sizeg); - memcpy(buffer, gfxrom, sizeg); - - /* address lines swap: fedcba9876543210 -> fedcb67584a39012 */ - - for (i = startg; i < sizeg; i++) { - a = BITSWAP16(i, 15, 14, 13, 12, 11, 6, 7, 5, 8, 4, 10, 3, 9, 0, 1, 2); - gfxrom[a] = buffer[i]; - } + dynamic_buffer buffer(sizeg); + memcpy(buffer, gfxrom, sizeg); - auto_free(machine(), buffer); + /* address lines swap: fedcba9876543210 -> fedcb67584a39012 */ + + for (i = startg; i < sizeg; i++) + { + a = BITSWAP16(i, 15, 14, 13, 12, 11, 6, 7, 5, 8, 4, 10, 3, 9, 0, 1, 2); + gfxrom[a] = buffer[i]; + } + } /**************************** @@ -5898,19 +5897,19 @@ DRIVER_INIT_MEMBER(funworld_state, saloon) prom[i] = BITSWAP8(prom[i], 2, 3, 5, 4, 6, 7, 1, 0); } - buffer = auto_alloc_array(machine(), UINT8, sizep); - memcpy(buffer, prom, sizep); - - - /* address lines swap: fedcba9876543210 -> fedcba9487652013 */ - - for (i = startp; i < sizep; i++) { - a = BITSWAP16(i, 15, 14, 13, 12, 11, 10, 9, 4, 8, 7, 6, 5, 2, 0, 1, 3); - prom[a] = buffer[i]; - } + dynamic_buffer buffer(sizep); + memcpy(buffer, prom, sizep); - auto_free(machine(), buffer); + + /* address lines swap: fedcba9876543210 -> fedcba9487652013 */ + + for (i = startp; i < sizep; i++) + { + a = BITSWAP16(i, 15, 14, 13, 12, 11, 10, 9, 4, 8, 7, 6, 5, 2, 0, 1, 3); + prom[a] = buffer[i]; + } + } m_palette->update(); } @@ -6026,7 +6025,6 @@ DRIVER_INIT_MEMBER(funworld_state, dino4) int sizeg = memregion("gfx1")->bytes(); int startg = 0; - UINT8 *buffer; int i, a; /***************************** @@ -6040,37 +6038,37 @@ DRIVER_INIT_MEMBER(funworld_state, dino4) rom[i] = BITSWAP8(rom[i], 7, 6, 5, 4, 3, 1, 2, 0); } - buffer = auto_alloc_array(machine(), UINT8, size); - memcpy(buffer, rom, size); - - - /* address lines swap: fedcba9876543210 -> fedcba9867543210 */ - - for (i = start; i < size; i++) { - a = BITSWAP16(i, 15, 13, 14, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); - rom[a] = buffer[i]; - } + dynamic_buffer buffer(size); + memcpy(buffer, rom, size); - auto_free(machine(), buffer); + + /* address lines swap: fedcba9876543210 -> fedcba9867543210 */ + + for (i = start; i < size; i++) + { + a = BITSWAP16(i, 15, 13, 14, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); + rom[a] = buffer[i]; + } + } /****************************** * Graphics ROM decryption * ******************************/ - buffer = auto_alloc_array(machine(), UINT8, sizeg); - memcpy(buffer, gfxrom, sizeg); - - /* address lines swap: fedcba9876543210 -> fedcb67584a39012 */ - - for (i = startg; i < sizeg; i++) { - a = BITSWAP16(i, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1, 0); - gfxrom[a] = buffer[i]; - } + dynamic_buffer buffer(sizeg); + memcpy(buffer, gfxrom, sizeg); - auto_free(machine(), buffer); + /* address lines swap: fedcba9876543210 -> fedcb67584a39012 */ + + for (i = startg; i < sizeg; i++) + { + a = BITSWAP16(i, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1, 0); + gfxrom[a] = buffer[i]; + } + } } @@ -6145,7 +6143,6 @@ DRIVER_INIT_MEMBER(funworld_state, rcdino4) int sizeg = memregion("gfx1")->bytes(); int startg = 0; - UINT8 *buffer; int i, a; /***************************** @@ -6159,37 +6156,37 @@ DRIVER_INIT_MEMBER(funworld_state, rcdino4) rom[i] = BITSWAP8(rom[i], 7, 6, 5, 4, 3, 1, 2, 0); } - buffer = auto_alloc_array(machine(), UINT8, size); - memcpy(buffer, rom, size); - - - /* address lines swap: fedcba9876543210 -> fedcba9867543210 */ - - for (i = start; i < size; i++) { - a = BITSWAP16(i, 15, 13, 14, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); - rom[a] = buffer[i]; - } + dynamic_buffer buffer(size); + memcpy(buffer, rom, size); - auto_free(machine(), buffer); + + /* address lines swap: fedcba9876543210 -> fedcba9867543210 */ + + for (i = start; i < size; i++) + { + a = BITSWAP16(i, 15, 13, 14, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); + rom[a] = buffer[i]; + } + } /****************************** * Graphics ROM decryption * ******************************/ - buffer = auto_alloc_array(machine(), UINT8, sizeg); - memcpy(buffer, gfxrom, sizeg); - - /* address lines swap: fedcba9876543210 -> fedcb67584a39012 */ - - for (i = startg; i < sizeg; i++) { - a = BITSWAP16(i, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1, 0); - gfxrom[a] = buffer[i]; - } + dynamic_buffer buffer(sizeg); + memcpy(buffer, gfxrom, sizeg); - auto_free(machine(), buffer); + /* address lines swap: fedcba9876543210 -> fedcb67584a39012 */ + + for (i = startg; i < sizeg; i++) + { + a = BITSWAP16(i, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1, 0); + gfxrom[a] = buffer[i]; + } + } /* d4-d5 data lines swap, plus a XOR with 0x81, implemented in two steps for an easy view */ diff --git a/src/mame/drivers/gaiden.c b/src/mame/drivers/gaiden.c index 415bd47e7e6..e11806ec9cf 100644 --- a/src/mame/drivers/gaiden.c +++ b/src/mame/drivers/gaiden.c @@ -1510,37 +1510,38 @@ void gaiden_state::descramble_drgnbowl_gfx() int i; UINT8 *ROM = memregion("maincpu")->base(); size_t size = memregion("maincpu")->bytes(); - UINT8 *buffer = auto_alloc_array(machine(), UINT8, size); - - memcpy(buffer, ROM, size); - for( i = 0; i < size; i++ ) + { - ROM[i] = buffer[BITSWAP24(i,23,22,21,20, - 19,18,17,15, - 16,14,13,12, - 11,10, 9, 8, - 7, 6, 5, 4, - 3, 2, 1, 0)]; - } + dynamic_buffer buffer(size); - auto_free(machine(), buffer); + memcpy(buffer, ROM, size); + for( i = 0; i < size; i++ ) + { + ROM[i] = buffer[BITSWAP24(i,23,22,21,20, + 19,18,17,15, + 16,14,13,12, + 11,10, 9, 8, + 7, 6, 5, 4, + 3, 2, 1, 0)]; + } + } ROM = memregion("gfx2")->base(); size = memregion("gfx2")->bytes(); - buffer = auto_alloc_array(machine(), UINT8, size); - - memcpy(buffer,ROM,size); - for( i = 0; i < size; i++ ) { - ROM[i] = buffer[BITSWAP24(i,23,22,21,20, - 19,18,16,17, - 15,14,13, 4, - 3,12,11,10, - 9, 8, 7, 6, - 5, 2, 1, 0)]; - } + dynamic_buffer buffer(size); - auto_free(machine(), buffer); + memcpy(buffer,ROM,size); + for( i = 0; i < size; i++ ) + { + ROM[i] = buffer[BITSWAP24(i,23,22,21,20, + 19,18,16,17, + 15,14,13, 4, + 3,12,11,10, + 9, 8, 7, 6, + 5, 2, 1, 0)]; + } + } } DRIVER_INIT_MEMBER(gaiden_state,drgnbowl) @@ -1552,12 +1553,11 @@ DRIVER_INIT_MEMBER(gaiden_state,drgnbowl) void gaiden_state::descramble_mastninj_gfx(UINT8* src) { - UINT8 *buffer; int len = 0x80000; /* rearrange gfx */ - buffer = auto_alloc_array(machine(), UINT8, len); { + dynamic_buffer buffer(len); int i; for (i = 0;i < len; i++) { @@ -1570,11 +1570,10 @@ void gaiden_state::descramble_mastninj_gfx(UINT8* src) 3,2,1,0)]; } memcpy(src, buffer, len); - auto_free(machine(), buffer); } - buffer = auto_alloc_array(machine(), UINT8, len); { + dynamic_buffer buffer(len); int i; for (i = 0; i < len; i++) { @@ -1587,7 +1586,6 @@ void gaiden_state::descramble_mastninj_gfx(UINT8* src) 3,2,1,0)]; } memcpy(src, buffer, len); - auto_free(machine(), buffer); } } diff --git a/src/mame/drivers/galaxian.c b/src/mame/drivers/galaxian.c index 43e9f7b75d3..7648d5287f1 100644 --- a/src/mame/drivers/galaxian.c +++ b/src/mame/drivers/galaxian.c @@ -5758,7 +5758,7 @@ void galaxian_state::decode_anteater_gfx() { UINT32 romlength = memregion("gfx1")->bytes(); UINT8 *rombase = memregion("gfx1")->base(); - UINT8 *scratch = auto_alloc_array(machine(), UINT8, romlength); + dynamic_buffer scratch(romlength); UINT32 offs; memcpy(scratch, rombase, romlength); @@ -5770,7 +5770,6 @@ void galaxian_state::decode_anteater_gfx() srcoffs |= (BIT(offs,0) ^ BIT(offs,6) ^ 1) << 10; rombase[offs] = scratch[srcoffs]; } - auto_free(machine(), scratch); } @@ -5778,7 +5777,7 @@ void galaxian_state::decode_losttomb_gfx() { UINT32 romlength = memregion("gfx1")->bytes(); UINT8 *rombase = memregion("gfx1")->base(); - UINT8 *scratch = auto_alloc_array(machine(), UINT8, romlength); + dynamic_buffer scratch(romlength); UINT32 offs; memcpy(scratch, rombase, romlength); @@ -5790,7 +5789,6 @@ void galaxian_state::decode_losttomb_gfx() srcoffs |= ((BIT(offs,1) & BIT(offs,7)) | ((1 ^ BIT(offs,1)) & (BIT(offs,8)))) << 10; rombase[offs] = scratch[srcoffs]; } - auto_free(machine(), scratch); } diff --git a/src/mame/drivers/galaxold.c b/src/mame/drivers/galaxold.c index 0c8280ae0b0..fede945e0b0 100644 --- a/src/mame/drivers/galaxold.c +++ b/src/mame/drivers/galaxold.c @@ -2847,7 +2847,7 @@ DRIVER_INIT_MEMBER(galaxold_state,ckonggx) }; UINT8 *rom = memregion("maincpu")->base(); - UINT8 *buffer = auto_alloc_array(machine(), UINT8, 0x5800); + dynamic_buffer buffer(0x5800); for (int i=0;i<88;i++) { @@ -2856,7 +2856,6 @@ DRIVER_INIT_MEMBER(galaxold_state,ckonggx) } memcpy(rom, buffer, 0x5800); - auto_free(machine(), buffer); } diff --git a/src/mame/drivers/gauntlet.c b/src/mame/drivers/gauntlet.c index a0827a8f360..1aaeeade467 100644 --- a/src/mame/drivers/gauntlet.c +++ b/src/mame/drivers/gauntlet.c @@ -1662,7 +1662,7 @@ DRIVER_INIT_MEMBER(gauntlet_state,gauntlet2) DRIVER_INIT_MEMBER(gauntlet_state,vindctr2) { UINT8 *gfx2_base = memregion("gfx2")->base(); - UINT8 *data = auto_alloc_array(machine(), UINT8, 0x8000); + dynamic_buffer data(0x8000); int i; common_init(118, 1); @@ -1676,7 +1676,6 @@ DRIVER_INIT_MEMBER(gauntlet_state,vindctr2) int srcoffs = (i & 0x4000) | ((i << 11) & 0x3800) | ((i >> 3) & 0x07ff); gfx2_base[0x88000 + i] = data[srcoffs]; } - auto_free(machine(), data); } diff --git a/src/mame/drivers/goldstar.c b/src/mame/drivers/goldstar.c index 883b0a4e18d..88177687110 100644 --- a/src/mame/drivers/goldstar.c +++ b/src/mame/drivers/goldstar.c @@ -11561,7 +11561,6 @@ DRIVER_INIT_MEMBER(goldstar_state,goldstar) void goldstar_state::do_blockswaps(UINT8* ROM) { int A; - UINT8 *buffer; static const UINT16 cherry_swaptables[32] = { /* to align with goldstar */ @@ -11577,7 +11576,7 @@ void goldstar_state::do_blockswaps(UINT8* ROM) 0xa000, 0xa800, 0xb000, 0xb800, }; - buffer = auto_alloc_array(machine(), UINT8, 0x10000); + dynamic_buffer buffer(0x10000); memcpy(buffer,ROM,0x10000); // swap some 0x800 blocks around.. @@ -11585,8 +11584,6 @@ void goldstar_state::do_blockswaps(UINT8* ROM) { memcpy(ROM+A*0x800,buffer+cherry_swaptables[A],0x800); } - - auto_free(machine(), buffer); } void goldstar_state::dump_to_file( UINT8* ROM) diff --git a/src/mame/drivers/hng64.c b/src/mame/drivers/hng64.c index 0f039cb5d7f..8ff7cc66111 100644 --- a/src/mame/drivers/hng64.c +++ b/src/mame/drivers/hng64.c @@ -1736,11 +1736,10 @@ static void hng64_reorder(running_machine &machine, UINT8* gfxregion, size_t gfx { // by default 2 4bpp tiles are stored in each 8bpp tile, this makes decoding in MAME harder than it needs to be // reorder them - UINT8* buffer; int i; UINT8 tilesize = 4*8; // 4 bytes per line, 8 lines - buffer = auto_alloc_array(machine, UINT8, gfxregionsize); + dynamic_buffer buffer(gfxregionsize); for (i=0;ibase()); - UINT16 *result_data = auto_alloc_array(machine(), UINT16, rom_size/2); + dynamic_array result_data(rom_size/2); for (i=0; ibase()); - UINT16 *result_data = auto_alloc_array(machine(), UINT16, rom_size/2); + dynamic_array result_data(rom_size/2); for (i=0; ibase()); - UINT8 *result_data = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer result_data(rom_size); for (i=0; ibase()); - UINT8 *result_data = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer result_data(rom_size); for (i=0; ibytes(); UINT8 *rom = memregion("tilemaps")->base(); - UINT8 *tmp = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer tmp(length); int i; memcpy(tmp,rom,length); @@ -679,8 +679,6 @@ void igs017_state::mgcs_decrypt_tiles() int addr = (i & ~0xffff) | BITSWAP16(i,15,14,13,12,11,10,6,7,8,9,5,4,3,2,1,0); rom[i] = tmp[addr]; } - - auto_free(machine(), tmp); } void igs017_state::mgcs_flip_sprites() @@ -966,7 +964,7 @@ void igs017_state::lhzb2_decrypt_tiles() { int length = memregion("tilemaps")->bytes(); UINT8 *rom = memregion("tilemaps")->base(); - UINT8 *tmp = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer tmp(length); int i; int addr; @@ -976,8 +974,6 @@ void igs017_state::lhzb2_decrypt_tiles() addr = (i & ~0xffffff) | BITSWAP24(i,23,22,21,20,19,18,17,1,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,0); rom[i] = tmp[addr]; } - - auto_free(machine(), tmp); } void igs017_state::lhzb2_decrypt_sprites() @@ -1193,7 +1189,7 @@ void igs017_state::slqz2_decrypt_tiles() { int length = memregion("tilemaps")->bytes(); UINT8 *rom = memregion("tilemaps")->base(); - UINT8 *tmp = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer tmp(length); int i; memcpy(tmp,rom,length); @@ -1202,8 +1198,6 @@ void igs017_state::slqz2_decrypt_tiles() int addr = (i & ~0xff) | BITSWAP8(i,7,4,5,6,3,2,1,0); rom[i] = tmp[addr]; } - - auto_free(machine(), tmp); } DRIVER_INIT_MEMBER(igs017_state,slqz2) diff --git a/src/mame/drivers/igs_m027.c b/src/mame/drivers/igs_m027.c index 237410fb335..8b97e16a791 100644 --- a/src/mame/drivers/igs_m027.c +++ b/src/mame/drivers/igs_m027.c @@ -292,7 +292,7 @@ void igs_m027_state::sdwx_gfx_decrypt() int i; unsigned rom_size = 0x80000; UINT8 *src = (UINT8 *) (memregion("gfx1")->base()); - UINT8 *result_data = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer result_data(rom_size); for (i=0; ibase(); @@ -2327,15 +2326,13 @@ DRIVER_INIT_MEMBER(igspoker_state,number10) /* Descramble graphic */ rom = memregion("gfx1")->base(); length = memregion("gfx1")->bytes(); - tmp = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer tmp(length); memcpy(tmp,rom,length); for (A = 0;A < length;A++) { int addr = (A & ~0xffff) | BITSWAP16(A,15,14,13,12,11,10,9,8,7,6,5,4,3,0,1,2); rom[A] = tmp[addr]; } - - auto_free(machine(), tmp); } diff --git a/src/mame/drivers/jclub2.c b/src/mame/drivers/jclub2.c index c3717d81193..53aa7906cbe 100644 --- a/src/mame/drivers/jclub2.c +++ b/src/mame/drivers/jclub2.c @@ -1019,13 +1019,12 @@ DRIVER_INIT_MEMBER(darkhors_state,darkhors) if (eeprom != NULL) { size_t len = memregion("eeprom")->bytes(); - UINT8* temp = (UINT8*)auto_alloc_array(machine(), UINT8, len); + dynamic_buffer temp(len); int i; for (i = 0; i < len; i++) temp[i] = eeprom[BITSWAP8(i,7,5,4,3,2,1,0,6)]; memcpy(eeprom, temp, len); - auto_free(machine(), temp); } } diff --git a/src/mame/drivers/kas89.c b/src/mame/drivers/kas89.c index c8e988f020c..88cc456b237 100644 --- a/src/mame/drivers/kas89.c +++ b/src/mame/drivers/kas89.c @@ -861,7 +861,6 @@ DRIVER_INIT_MEMBER(kas89_state,kas89) int i; UINT8 *mem = memregion("maincpu")->base(); int memsize = memregion("maincpu")->bytes(); - UINT8 *buf; /* Unscrambling data lines */ for ( i = 0; i < memsize; i++ ) @@ -870,14 +869,12 @@ DRIVER_INIT_MEMBER(kas89_state,kas89) } /* Unscrambling address lines */ - buf = auto_alloc_array(machine(), UINT8, memsize); + dynamic_buffer buf(memsize); memcpy(buf, mem, memsize); for ( i = 0; i < memsize; i++ ) { mem[BITSWAP16(i,15,14,5,6,3,0,12,1,9,13,4,7,10,8,2,11)] = buf[i]; } - - auto_free(machine(), buf); } diff --git a/src/mame/drivers/legionna.c b/src/mame/drivers/legionna.c index 01862053e8c..f3bf710c39d 100644 --- a/src/mame/drivers/legionna.c +++ b/src/mame/drivers/legionna.c @@ -910,11 +910,10 @@ static const gfx_layout legionna_new_charlayout = void legionna_state::descramble_legionnaire_gfx(UINT8* src) { - UINT8 *buffer; int len = 0x10000; /* rearrange gfx */ - buffer = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer buffer(len); { int i; for (i = 0;i < len; i++) @@ -928,7 +927,6 @@ void legionna_state::descramble_legionnaire_gfx(UINT8* src) 3,2,1,0)]; } memcpy(src,buffer,len); - auto_free(machine(), buffer); } } diff --git a/src/mame/drivers/megasys1.c b/src/mame/drivers/megasys1.c index 171b07d9fb3..e420a224de9 100644 --- a/src/mame/drivers/megasys1.c +++ b/src/mame/drivers/megasys1.c @@ -3661,7 +3661,6 @@ void megasys1_state::rodlandj_gfx_unmangle(const char *region) { UINT8 *rom = memregion(region)->base(); int size = memregion(region)->bytes(); - UINT8 *buffer; int i; /* data lines swap: 76543210 -> 64537210 */ @@ -3671,7 +3670,7 @@ void megasys1_state::rodlandj_gfx_unmangle(const char *region) | ((rom[i] & 0x48) << 1) | ((rom[i] & 0x10) << 2); - buffer = auto_alloc_array(machine(), UINT8, size); + dynamic_buffer buffer(size); memcpy(buffer,rom,size); @@ -3685,22 +3684,19 @@ void megasys1_state::rodlandj_gfx_unmangle(const char *region) | ((i & 0x0008) << 5); rom[i] = buffer[a]; } - - auto_free(machine(), buffer); } void megasys1_state::jitsupro_gfx_unmangle(const char *region) { UINT8 *rom = memregion(region)->base(); int size = memregion(region)->bytes(); - UINT8 *buffer; int i; /* data lines swap: 76543210 -> 43576210 */ for (i = 0;i < size;i++) rom[i] = BITSWAP8(rom[i],0x4,0x3,0x5,0x7,0x6,0x2,0x1,0x0); - buffer = auto_alloc_array(machine(), UINT8, size); + dynamic_buffer buffer(size); memcpy(buffer,rom,size); @@ -3712,22 +3708,19 @@ void megasys1_state::jitsupro_gfx_unmangle(const char *region) rom[i] = buffer[a]; } - - auto_free(machine(), buffer); } void megasys1_state::stdragona_gfx_unmangle(const char *region) { UINT8 *rom = memregion(region)->base(); int size = memregion(region)->bytes(); - UINT8 *buffer; int i; /* data lines swap: 76543210 -> 37564210 */ for (i = 0;i < size;i++) rom[i] = BITSWAP8(rom[i],3,7,5,6,4,2,1,0); - buffer = auto_alloc_array(machine(), UINT8, size); + dynamic_buffer buffer(size); memcpy(buffer,rom,size); @@ -3739,8 +3732,6 @@ void megasys1_state::stdragona_gfx_unmangle(const char *region) rom[i] = buffer[a]; } - - auto_free(machine(), buffer); } /************************************* diff --git a/src/mame/drivers/meyc8088.c b/src/mame/drivers/meyc8088.c index 3cb85102e99..591b71324c5 100644 --- a/src/mame/drivers/meyc8088.c +++ b/src/mame/drivers/meyc8088.c @@ -122,11 +122,10 @@ static const res_net_info meyc8088_net_info = PALETTE_INIT_MEMBER(meyc8088_state, meyc8088) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &meyc8088_decode_info, &meyc8088_net_info); + compute_res_net_all(rgb, color_prom, meyc8088_decode_info, meyc8088_net_info); palette.set_pen_colors(0, rgb, 32); - auto_free(machine(), rgb); } UINT32 meyc8088_state::screen_update_meyc8088(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) diff --git a/src/mame/drivers/mitchell.c b/src/mame/drivers/mitchell.c index b4cbc5cc3ba..c8a25ad5526 100644 --- a/src/mame/drivers/mitchell.c +++ b/src/mame/drivers/mitchell.c @@ -2234,7 +2234,7 @@ DRIVER_INIT_MEMBER(mitchell_state,mstworld) { /* descramble the program rom .. */ int len = memregion("maincpu")->bytes(); - UINT8* source = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer source(len); UINT8* dst = memregion("maincpu")->base() ; int x; @@ -2271,7 +2271,6 @@ DRIVER_INIT_MEMBER(mitchell_state,mstworld) memcpy(&dst[((x / 2) * 0x4000) + 0x50000],&source[tablebank[x + 1] * 0x4000], 0x4000); } } - auto_free(machine(), source); bootleg_decode(); configure_banks(); diff --git a/src/mame/drivers/mpu4vid.c b/src/mame/drivers/mpu4vid.c index e01cd4694a8..e7e7059b017 100644 --- a/src/mame/drivers/mpu4vid.c +++ b/src/mame/drivers/mpu4vid.c @@ -482,10 +482,10 @@ VIDEO_START_MEMBER(mpu4vid_state,mpu4_vid) assert(m_gfx_index != MAX_GFX_ELEMENTS); /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(m_gfx_index+0, auto_alloc(machine(), gfx_element(m_palette, mpu4_vid_char_8x8_layout, reinterpret_cast(m_vid_vidram.target()), m_palette->entries() / 16, 0))); - m_gfxdecode->set_gfx(m_gfx_index+1, auto_alloc(machine(), gfx_element(m_palette, mpu4_vid_char_8x16_layout, reinterpret_cast(m_vid_vidram.target()), m_palette->entries() / 16, 0))); - m_gfxdecode->set_gfx(m_gfx_index+2, auto_alloc(machine(), gfx_element(m_palette, mpu4_vid_char_16x8_layout, reinterpret_cast(m_vid_vidram.target()), m_palette->entries() / 16, 0))); - m_gfxdecode->set_gfx(m_gfx_index+3, auto_alloc(machine(), gfx_element(m_palette, mpu4_vid_char_16x16_layout, reinterpret_cast(m_vid_vidram.target()), m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index+0, global_alloc(gfx_element(m_palette, mpu4_vid_char_8x8_layout, reinterpret_cast(m_vid_vidram.target()), m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index+1, global_alloc(gfx_element(m_palette, mpu4_vid_char_8x16_layout, reinterpret_cast(m_vid_vidram.target()), m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index+2, global_alloc(gfx_element(m_palette, mpu4_vid_char_16x8_layout, reinterpret_cast(m_vid_vidram.target()), m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index+3, global_alloc(gfx_element(m_palette, mpu4_vid_char_16x16_layout, reinterpret_cast(m_vid_vidram.target()), m_palette->entries() / 16, 0))); m_scn2674->init_stuff(); diff --git a/src/mame/drivers/multfish.c b/src/mame/drivers/multfish.c index f6fc9f04a64..f6e22dc552b 100644 --- a/src/mame/drivers/multfish.c +++ b/src/mame/drivers/multfish.c @@ -433,7 +433,7 @@ A12 <-> A13 UINT32 i,j,jscr,romoffset; UINT8 *igrosoft_gamble_gfx = memregion("gfx")->base(); - UINT8 *temprom = auto_alloc_array(machine(), UINT8, igrosoft_gamble_ROM_SIZE); + dynamic_buffer temprom(igrosoft_gamble_ROM_SIZE); /* ROM 1 decode */ @@ -476,7 +476,6 @@ A12 <-> A13 } memcpy(&igrosoft_gamble_gfx[romoffset],temprom,igrosoft_gamble_ROM_SIZE); } - auto_free(machine(), temprom); } INLINE void rom_decodel(UINT8 *romptr, UINT8 *tmprom, UINT8 xor_data, UINT32 xor_add) @@ -505,7 +504,7 @@ INLINE void rom_decodeh(UINT8 *romptr, UINT8 *tmprom, UINT8 xor_data, UINT32 xor static void lottery_decode(running_machine &machine, UINT8 xor12, UINT8 xor34, UINT8 xor56, UINT8 xor78, UINT32 xor_addr) { UINT8 *igrosoft_gamble_gfx = machine.root_device().memregion("gfx")->base(); - UINT8 *temprom = auto_alloc_array(machine, UINT8, igrosoft_gamble_ROM_SIZE); + dynamic_buffer temprom(igrosoft_gamble_ROM_SIZE); /* ROMs decode */ rom_decodel(&igrosoft_gamble_gfx[0x000000], temprom, xor12, xor_addr); @@ -516,8 +515,6 @@ static void lottery_decode(running_machine &machine, UINT8 xor12, UINT8 xor34, U rom_decodeh(&igrosoft_gamble_gfx[0x180000], temprom, xor56, xor_addr); rom_decodeh(&igrosoft_gamble_gfx[0x280000], temprom, xor78, xor_addr); rom_decodeh(&igrosoft_gamble_gfx[0x380000], temprom, xor78, xor_addr); - - auto_free(machine, temprom); } INLINE void roment_decodel(UINT8 *romptr, UINT8 *tmprom, UINT8 xor_data, UINT32 xor_add) @@ -546,7 +543,7 @@ INLINE void roment_decodeh(UINT8 *romptr, UINT8 *tmprom, UINT8 xor_data, UINT32 static void ent_decode(running_machine &machine, UINT8 xor12, UINT8 xor34, UINT8 xor56, UINT8 xor78, UINT32 xor_addr) { UINT8 *igrosoft_gamble_gfx = machine.root_device().memregion("gfx")->base(); - UINT8 *temprom = auto_alloc_array(machine, UINT8, igrosoft_gamble_ROM_SIZE); + dynamic_buffer temprom(igrosoft_gamble_ROM_SIZE); /* ROMs decode */ roment_decodel(&igrosoft_gamble_gfx[0x000000], temprom, xor12, xor_addr); @@ -557,8 +554,6 @@ static void ent_decode(running_machine &machine, UINT8 xor12, UINT8 xor34, UINT8 roment_decodeh(&igrosoft_gamble_gfx[0x180000], temprom, xor56, xor_addr); roment_decodeh(&igrosoft_gamble_gfx[0x280000], temprom, xor78, xor_addr); roment_decodeh(&igrosoft_gamble_gfx[0x380000], temprom, xor78, xor_addr); - - auto_free(machine, temprom); } DRIVER_INIT_MEMBER(igrosoft_gamble_state,island2l) diff --git a/src/mame/drivers/multigam.c b/src/mame/drivers/multigam.c index 0e6e124d663..02ae1351afe 100644 --- a/src/mame/drivers/multigam.c +++ b/src/mame/drivers/multigam.c @@ -1460,7 +1460,7 @@ DRIVER_INIT_MEMBER(multigam_state,multigmt) { address_space &space = m_maincpu->space(AS_PROGRAM); - UINT8* buf = auto_alloc_array(machine(), UINT8, 0x80000); + dynamic_buffer buf(0x80000); UINT8 *rom; int size; int i; @@ -1492,7 +1492,6 @@ DRIVER_INIT_MEMBER(multigam_state,multigmt) rom[i] = BITSWAP8(buf[addr], 4, 7, 3, 2, 5, 1, 6, 0); } - auto_free(machine(), buf); multigam_switch_prg_rom(space, 0x0, 0x01); }; diff --git a/src/mame/drivers/mustache.c b/src/mame/drivers/mustache.c index 919b728e70a..42a12293616 100644 --- a/src/mame/drivers/mustache.c +++ b/src/mame/drivers/mustache.c @@ -237,7 +237,7 @@ DRIVER_INIT_MEMBER(mustache_state,mustache) int G2 = memregion("gfx2")->bytes()/2; UINT8 *gfx1 = memregion("gfx1")->base(); UINT8 *gfx2 = memregion("gfx2")->base(); - UINT8 *buf=auto_alloc_array(machine(), UINT8, G2*2); + dynamic_buffer buf(G2*2); /* BG data lines */ for (i=0;idecrypt("maincpu",0x8000); } diff --git a/src/mame/drivers/namcoic.c b/src/mame/drivers/namcoic.c index 38629fc7d4f..a7a404879b9 100644 --- a/src/mame/drivers/namcoic.c +++ b/src/mame/drivers/namcoic.c @@ -1443,7 +1443,7 @@ void namco_c45_road_device::draw(bitmap_ind16 &bitmap, const rectangle &cliprect void namco_c45_road_device::device_start() { // create a gfx_element describing the road graphics - m_gfxdecode->set_gfx(0, auto_alloc(machine(), gfx_element(m_palette, s_tile_layout, 0x10000 + (UINT8 *)&m_ram[0], 0x3f, 0xf00))); + m_gfxdecode->set_gfx(0, global_alloc(gfx_element(m_palette, s_tile_layout, 0x10000 + (UINT8 *)&m_ram[0], 0x3f, 0xf00))); // create a tilemap for the road m_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(namco_c45_road_device::get_road_info), this), diff --git a/src/mame/drivers/namcos86.c b/src/mame/drivers/namcos86.c index 70a00f4adc6..91bd65c91ae 100644 --- a/src/mame/drivers/namcos86.c +++ b/src/mame/drivers/namcos86.c @@ -1512,14 +1512,13 @@ DRIVER_INIT_MEMBER(namcos86_state,namco86) { int size; UINT8 *gfx; - UINT8 *buffer; /* shuffle tile ROMs so regular gfx unpack routines can be used */ gfx = memregion("gfx1")->base(); size = memregion("gfx1")->bytes() * 2 / 3; - buffer = auto_alloc_array(machine(), UINT8, size ); { + dynamic_buffer buffer( size ); UINT8 *dest1 = gfx; UINT8 *dest2 = gfx + ( size / 2 ); UINT8 *mono = gfx + size; @@ -1536,15 +1535,13 @@ DRIVER_INIT_MEMBER(namcos86_state,namco86) *mono ^= 0xff; mono++; } - - auto_free( machine(), buffer ); } gfx = memregion("gfx2")->base(); size = memregion("gfx2")->bytes() * 2 / 3; - buffer = auto_alloc_array(machine(), UINT8, size ); { + dynamic_buffer buffer( size ); UINT8 *dest1 = gfx; UINT8 *dest2 = gfx + ( size / 2 ); UINT8 *mono = gfx + size; @@ -1561,8 +1558,6 @@ DRIVER_INIT_MEMBER(namcos86_state,namco86) *mono ^= 0xff; mono++; } - - auto_free( machine(), buffer ); } } diff --git a/src/mame/drivers/ninjakd2.c b/src/mame/drivers/ninjakd2.c index e9be91398ef..67e79aa93ca 100644 --- a/src/mame/drivers/ninjakd2.c +++ b/src/mame/drivers/ninjakd2.c @@ -1423,7 +1423,7 @@ void ninjakd2_state::lineswap_gfx_roms(const char *region, const int bit) { const int length = memregion(region)->bytes(); UINT8* const src = memregion(region)->base(); - UINT8* const temp = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer temp(length); const int mask = (1 << (bit + 1)) - 1; for (int sa = 0; sa < length; sa++) @@ -1433,7 +1433,6 @@ void ninjakd2_state::lineswap_gfx_roms(const char *region, const int bit) } memcpy(src, temp, length); - auto_free(machine(), temp); } void ninjakd2_state::gfx_unscramble() diff --git a/src/mame/drivers/nmk16.c b/src/mame/drivers/nmk16.c index ae9ae793095..d3f4c094a0c 100644 --- a/src/mame/drivers/nmk16.c +++ b/src/mame/drivers/nmk16.c @@ -5088,7 +5088,7 @@ static void decryptcode( running_machine &machine, int a23, int a22, int a21, in int i; UINT8 *RAM = machine.root_device().memregion( "maincpu" )->base(); size_t size = machine.root_device().memregion( "maincpu" )->bytes(); - UINT8 *buffer = auto_alloc_array(machine, UINT8, size ); + dynamic_buffer buffer( size ); memcpy( buffer, RAM, size ); for( i = 0; i < size; i++ ) @@ -5096,7 +5096,6 @@ static void decryptcode( running_machine &machine, int a23, int a22, int a21, in RAM[ i ] = buffer[ BITSWAP24( i, a23, a22, a21, a20, a19, a18, a17, a16, a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0 ) ]; } - auto_free( machine, buffer ); } diff --git a/src/mame/drivers/nova2001.c b/src/mame/drivers/nova2001.c index f1d02bcd903..c50934d0ca4 100644 --- a/src/mame/drivers/nova2001.c +++ b/src/mame/drivers/nova2001.c @@ -987,7 +987,7 @@ void nova2001_state::lineswap_gfx_roms(const char *region, const int bit) UINT8* const src = memregion(region)->base(); - UINT8* const temp = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer temp(length); const int mask = (1 << (bit + 1)) - 1; @@ -1001,8 +1001,6 @@ void nova2001_state::lineswap_gfx_roms(const char *region, const int bit) } memcpy(src, temp, length); - - auto_free(machine(), temp); } diff --git a/src/mame/drivers/panicr.c b/src/mame/drivers/panicr.c index fc3da104f74..3a57129b9c5 100644 --- a/src/mame/drivers/panicr.c +++ b/src/mame/drivers/panicr.c @@ -719,7 +719,7 @@ ROM_END DRIVER_INIT_MEMBER(panicr_state,panicr) { - UINT8 *buf = auto_alloc_array(machine(), UINT8, 0x80000); + dynamic_buffer buf(0x80000); UINT8 *rom; int size; int i,j; @@ -823,8 +823,6 @@ DRIVER_INIT_MEMBER(panicr_state,panicr) } } - auto_free(machine(), buf); - m_tempbitmap_1 = auto_bitmap_ind16_alloc(machine(),256,256); m_temprender = auto_bitmap_ind16_alloc(machine(),256,256); m_tempbitmap_clip.set(0, 256-1, 0, 256-1); diff --git a/src/mame/drivers/pengadvb.c b/src/mame/drivers/pengadvb.c index 752215e1d87..20f11e11e22 100644 --- a/src/mame/drivers/pengadvb.c +++ b/src/mame/drivers/pengadvb.c @@ -293,7 +293,6 @@ void pengadvb_state::pengadvb_decrypt(const char* region) { UINT8 *mem = memregion(region)->base(); int memsize = memregion(region)->bytes(); - UINT8 *buf; int i; // data lines swap @@ -303,13 +302,12 @@ void pengadvb_state::pengadvb_decrypt(const char* region) } // address line swap - buf = auto_alloc_array(machine(), UINT8, memsize); + dynamic_buffer buf(memsize); memcpy(buf, mem, memsize); for ( i = 0; i < memsize; i++ ) { mem[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,5,11,10,9,8,7,6,12,4,3,2,1,0)]; } - auto_free(machine(), buf); } DRIVER_INIT_MEMBER(pengadvb_state,pengadvb) diff --git a/src/mame/drivers/pgm.c b/src/mame/drivers/pgm.c index 584d615b8f6..aa940c9064b 100644 --- a/src/mame/drivers/pgm.c +++ b/src/mame/drivers/pgm.c @@ -4025,7 +4025,7 @@ void pgm_state::expand_32x32x5bpp() glcopy.total = (gfx2_size_needed / glcopy.charincrement)*8; - m_gfxdecode->set_gfx(1, auto_alloc(machine(), gfx_element(m_palette, glcopy, (UINT8 *)dst, 32, 0x400))); + m_gfxdecode->set_gfx(1, global_alloc(gfx_element(m_palette, glcopy, (UINT8 *)dst, 32, 0x400))); } diff --git a/src/mame/drivers/pirates.c b/src/mame/drivers/pirates.c index 0c597b7c527..80672917e48 100644 --- a/src/mame/drivers/pirates.c +++ b/src/mame/drivers/pirates.c @@ -325,12 +325,12 @@ ROM_END void pirates_state::pirates_decrypt_68k() { int rom_size; - UINT16 *buf, *rom; + UINT16 *rom; int i; rom_size = memregion("maincpu")->bytes(); - buf = auto_alloc_array(machine(), UINT16, rom_size/2); + dynamic_buffer buf(rom_size/2); rom = (UINT16 *)memregion("maincpu")->base(); memcpy (buf, rom, rom_size); @@ -348,18 +348,17 @@ void pirates_state::pirates_decrypt_68k() rom[i] = (vr<<8) | vl; } - auto_free (machine(), buf); } void pirates_state::pirates_decrypt_p() { int rom_size; - UINT8 *buf, *rom; + UINT8 *rom; int i; rom_size = memregion("gfx1")->bytes(); - buf = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer buf(rom_size); rom = memregion("gfx1")->base(); memcpy (buf, rom, rom_size); @@ -372,18 +371,17 @@ void pirates_state::pirates_decrypt_p() rom[adr+2*(rom_size/4)] = BITSWAP8(buf[i+2*(rom_size/4)], 1,4,7,0,3,5,6,2); rom[adr+3*(rom_size/4)] = BITSWAP8(buf[i+3*(rom_size/4)], 2,3,4,0,7,5,1,6); } - auto_free (machine(), buf); } void pirates_state::pirates_decrypt_s() { int rom_size; - UINT8 *buf, *rom; + UINT8 *rom; int i; rom_size = memregion("gfx2")->bytes(); - buf = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer buf(rom_size); rom = memregion("gfx2")->base(); memcpy (buf, rom, rom_size); @@ -396,19 +394,18 @@ void pirates_state::pirates_decrypt_s() rom[adr+2*(rom_size/4)] = BITSWAP8(buf[i+2*(rom_size/4)], 2,3,4,0,7,5,1,6); rom[adr+3*(rom_size/4)] = BITSWAP8(buf[i+3*(rom_size/4)], 4,2,7,1,6,5,0,3); } - auto_free (machine(), buf); } void pirates_state::pirates_decrypt_oki() { int rom_size; - UINT8 *buf, *rom; + UINT8 *rom; int i; rom_size = memregion("oki")->bytes(); - buf = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer buf(rom_size); rom = memregion("oki")->base(); memcpy (buf, rom, rom_size); @@ -418,7 +415,6 @@ void pirates_state::pirates_decrypt_oki() int adr = BITSWAP24(i,23,22,21,20,19,10,16,13,8,4,7,11,14,17,12,6,2,0,5,18,15,3,1,9); rom[adr] = BITSWAP8(buf[i], 2,3,4,0,7,5,1,6); } - auto_free (machine(), buf); } diff --git a/src/mame/drivers/popeye.c b/src/mame/drivers/popeye.c index 1b72d9c92b0..d33c1b2b67e 100644 --- a/src/mame/drivers/popeye.c +++ b/src/mame/drivers/popeye.c @@ -678,18 +678,16 @@ ROM_END DRIVER_INIT_MEMBER(popeye_state,skyskipr) { - UINT8 *buffer; UINT8 *rom = memregion("maincpu")->base(); int len = memregion("maincpu")->bytes(); /* decrypt the program ROMs */ - buffer = auto_alloc_array(machine(), UINT8, len); { + dynamic_buffer buffer(len); int i; for (i = 0;i < len; i++) buffer[i] = BITSWAP8(rom[BITSWAP16(i,15,14,13,12,11,10,8,7,0,1,2,4,5,9,3,6) ^ 0xfc],3,4,2,5,1,6,0,7); memcpy(rom,buffer,len); - auto_free(machine(), buffer); } save_item(NAME(m_prot0)); @@ -699,18 +697,16 @@ DRIVER_INIT_MEMBER(popeye_state,skyskipr) DRIVER_INIT_MEMBER(popeye_state,popeye) { - UINT8 *buffer; UINT8 *rom = memregion("maincpu")->base(); int len = memregion("maincpu")->bytes(); /* decrypt the program ROMs */ - buffer = auto_alloc_array(machine(), UINT8, len); { + dynamic_buffer buffer(len); int i; for (i = 0;i < len; i++) buffer[i] = BITSWAP8(rom[BITSWAP16(i,15,14,13,12,11,10,8,7,6,3,9,5,4,2,1,0) ^ 0x3f],3,4,2,5,1,6,0,7); memcpy(rom,buffer,len); - auto_free(machine(), buffer); } save_item(NAME(m_prot0)); diff --git a/src/mame/drivers/popobear.c b/src/mame/drivers/popobear.c index 0ab4c9457bf..93547595211 100644 --- a/src/mame/drivers/popobear.c +++ b/src/mame/drivers/popobear.c @@ -224,7 +224,7 @@ void popobear_state::video_start() /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(m_gfx_index, auto_alloc(machine(), gfx_element(m_palette, popobear_char_layout, (UINT8 *)m_vram_rearranged, m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index, global_alloc(gfx_element(m_palette, popobear_char_layout, (UINT8 *)m_vram_rearranged, m_palette->entries() / 16, 0))); m_bg_tilemap[0] = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(popobear_state::get_popobear_bg0_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64); m_bg_tilemap[1] = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(popobear_state::get_popobear_bg1_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64); diff --git a/src/mame/drivers/segag80r.c b/src/mame/drivers/segag80r.c index fe60acdc10e..aca94860df8 100644 --- a/src/mame/drivers/segag80r.c +++ b/src/mame/drivers/segag80r.c @@ -1400,13 +1400,13 @@ ROM_END void segag80r_state::monsterb_expand_gfx(const char *region) { - UINT8 *temp, *dest; + UINT8 *dest; int i; /* expand the background ROMs; A11/A12 of each ROM is independently controlled via */ /* banking */ dest = memregion(region)->base(); - temp = auto_alloc_array(machine(), UINT8, 0x4000); + dynamic_buffer temp(0x4000); memcpy(temp, dest, 0x4000); /* 16 effective total banks */ @@ -1415,7 +1415,6 @@ void segag80r_state::monsterb_expand_gfx(const char *region) memcpy(&dest[0x0000 + i * 0x800], &temp[0x0000 + (i & 3) * 0x800], 0x800); memcpy(&dest[0x8000 + i * 0x800], &temp[0x2000 + (i >> 2) * 0x800], 0x800); } - auto_free(machine(), temp); } diff --git a/src/mame/drivers/seta.c b/src/mame/drivers/seta.c index 08a423d548c..b2fce0c1df2 100644 --- a/src/mame/drivers/seta.c +++ b/src/mame/drivers/seta.c @@ -11020,12 +11020,11 @@ DRIVER_INIT_MEMBER(seta_state,blandia) /* rearrange the gfx data so it can be decoded in the same way as the other set */ int rom_size; - UINT8 *buf; UINT8 *rom; int rpos; rom_size = 0x80000; - buf = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer buf(rom_size); rom = memregion("gfx2")->base() + 0x40000; @@ -11044,8 +11043,6 @@ DRIVER_INIT_MEMBER(seta_state,blandia) } memcpy( rom, buf, rom_size ); - - auto_free(machine(), buf); } diff --git a/src/mame/drivers/simpl156.c b/src/mame/drivers/simpl156.c index 54fa02f0f3d..8b9f0a4850b 100644 --- a/src/mame/drivers/simpl156.c +++ b/src/mame/drivers/simpl156.c @@ -1025,7 +1025,7 @@ DRIVER_INIT_MEMBER(simpl156_state,simpl156) { UINT8 *rom = memregion("okimusic")->base(); int length = memregion("okimusic")->bytes(); - UINT8 *buf1 = auto_alloc_array(machine(), UINT8, length); + dynamic_buffer buf1(length); UINT32 x; @@ -1046,8 +1046,6 @@ DRIVER_INIT_MEMBER(simpl156_state,simpl156) memcpy(rom, buf1, length); - auto_free(machine(), buf1); - deco56_decrypt_gfx(machine(), "gfx1"); deco156_decrypt(machine()); } diff --git a/src/mame/drivers/snowbros.c b/src/mame/drivers/snowbros.c index a467b30f634..d050bf0ab2d 100644 --- a/src/mame/drivers/snowbros.c +++ b/src/mame/drivers/snowbros.c @@ -2722,51 +2722,46 @@ READ16_MEMBER(snowbros_state::_4in1_02_read) DRIVER_INIT_MEMBER(snowbros_state,4in1boot) { - UINT8 *buffer; UINT8 *src = memregion("maincpu")->base(); int len = memregion("maincpu")->bytes(); /* strange order */ - buffer = auto_alloc_array(machine(), UINT8, len); { + dynamic_buffer buffer(len); int i; for (i = 0;i < len; i++) if (i&1) buffer[i] = BITSWAP8(src[i],6,7,5,4,3,2,1,0); else buffer[i] = src[i]; memcpy(src,buffer,len); - auto_free(machine(), buffer); } src = memregion("soundcpu")->base(); len = memregion("soundcpu")->bytes(); /* strange order */ - buffer = auto_alloc_array(machine(), UINT8, len); { + dynamic_buffer buffer(len); int i; for (i = 0;i < len; i++) buffer[i] = src[i^0x4000]; memcpy(src,buffer,len); - auto_free(machine(), buffer); } m_maincpu->space(AS_PROGRAM).install_read_handler(0x200000, 0x200001, read16_delegate(FUNC(snowbros_state::_4in1_02_read),this)); } DRIVER_INIT_MEMBER(snowbros_state,snowbro3) { - UINT8 *buffer; UINT8 *src = memregion("maincpu")->base(); int len = memregion("maincpu")->bytes(); /* strange order */ - buffer = auto_alloc_array(machine(), UINT8, len); { + dynamic_buffer buffer(len); int i; for (i = 0;i < len; i++) buffer[i] = src[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,3,4,1,2,0)]; memcpy(src,buffer,len); - auto_free(machine(), buffer); } } diff --git a/src/mame/drivers/speedbal.c b/src/mame/drivers/speedbal.c index 6668efe8933..4891612ce89 100644 --- a/src/mame/drivers/speedbal.c +++ b/src/mame/drivers/speedbal.c @@ -272,7 +272,7 @@ DRIVER_INIT_MEMBER(speedbal_state,speedbal) { // sprite tiles are in an odd order, rearrange to simplify video drawing function UINT8* rom = memregion("sprites")->base(); - UINT8* temp = auto_alloc_array(machine(), UINT8, 0x200*128); + dynamic_buffer temp(0x200*128); for (int i=0;i<0x200;i++) { @@ -281,7 +281,6 @@ DRIVER_INIT_MEMBER(speedbal_state,speedbal) } memcpy(rom,temp,0x200*128); - auto_free(machine(), temp); } diff --git a/src/mame/drivers/srmp6.c b/src/mame/drivers/srmp6.c index 4b7d7ca02c1..8a4fac6ba9f 100644 --- a/src/mame/drivers/srmp6.c +++ b/src/mame/drivers/srmp6.c @@ -169,7 +169,7 @@ void srmp6_state::video_start() m_sprram_old = auto_alloc_array_clear(machine(), UINT16, 0x80000/2); /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(0, auto_alloc(machine(), gfx_element(m_palette, tiles8x8_layout, (UINT8*)m_tileram, m_palette->entries() / 256, 0))); + m_gfxdecode->set_gfx(0, global_alloc(gfx_element(m_palette, tiles8x8_layout, (UINT8*)m_tileram, m_palette->entries() / 256, 0))); m_gfxdecode->gfx(0)->set_granularity(256); m_brightness = 0x60; diff --git a/src/mame/drivers/tcl.c b/src/mame/drivers/tcl.c index 7289cbb65ba..790b3f373d9 100644 --- a/src/mame/drivers/tcl.c +++ b/src/mame/drivers/tcl.c @@ -195,7 +195,7 @@ DRIVER_INIT_MEMBER(tcl_state,tcl) address_space &space = m_maincpu->space(AS_PROGRAM); UINT8 *dest = memregion("maincpu")->base(); int len = memregion("maincpu")->bytes(); - UINT8 *src = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer src(len); int i,idx=0; memcpy(src, dest, len); @@ -216,7 +216,6 @@ DRIVER_INIT_MEMBER(tcl_state,tcl) WRITEDEST((src[idx]^0x11)^0xf0); // abcdefgh -> ABCdefgH } } - auto_free(machine(), src); space.set_decrypted_region(0x0000, 0x7fff, dest+0x10000); } diff --git a/src/mame/drivers/tmnt.c b/src/mame/drivers/tmnt.c index 9068f58572d..6f965a8dc9c 100644 --- a/src/mame/drivers/tmnt.c +++ b/src/mame/drivers/tmnt.c @@ -4068,7 +4068,6 @@ DRIVER_INIT_MEMBER(tmnt_state,mia) int len; int i, j, k, A, B; int bits[32]; - UINT8 *temp; /* along with the normal byte reordering, TMNT also needs the bits to @@ -4112,7 +4111,7 @@ DRIVER_INIT_MEMBER(tmnt_state,mia) } } - temp = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer temp(len); memcpy(temp, gfxdata, len); for (A = 0; A < len / 4; A++) { @@ -4150,7 +4149,6 @@ DRIVER_INIT_MEMBER(tmnt_state,mia) gfxdata[4 * A + 2] = temp[4 * B + 2]; gfxdata[4 * A + 3] = temp[4 * B + 3]; } - auto_free(machine(), temp); } @@ -4161,7 +4159,6 @@ DRIVER_INIT_MEMBER(tmnt_state,tmnt) int len; int i, j, k, A, B, entry; int bits[32]; - UINT8 *temp; /* along with the normal byte reordering, TMNT also needs the bits to @@ -4205,7 +4202,7 @@ DRIVER_INIT_MEMBER(tmnt_state,tmnt) } } - temp = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer temp(len); memcpy(temp, gfxdata, len); code_conv_table = &memregion("proms")->base()[0x0000]; for (A = 0; A < len / 4; A++) @@ -4257,7 +4254,6 @@ DRIVER_INIT_MEMBER(tmnt_state,tmnt) gfxdata[4 * A + 2] = temp[4 * B + 2]; gfxdata[4 * A + 3] = temp[4 * B + 3]; } - auto_free(machine(), temp); } DRIVER_INIT_MEMBER(tmnt_state,cuebrick) diff --git a/src/mame/drivers/toki.c b/src/mame/drivers/toki.c index 7ec94349bdc..174e43a05df 100644 --- a/src/mame/drivers/toki.c +++ b/src/mame/drivers/toki.c @@ -782,7 +782,7 @@ ROM_END DRIVER_INIT_MEMBER(toki_state,toki) { UINT8 *ROM = memregion("oki")->base(); - UINT8 *buffer = auto_alloc_array(machine(), UINT8, 0x20000); + dynamic_buffer buffer(0x20000); int i; memcpy(buffer,ROM,0x20000); @@ -791,15 +791,13 @@ DRIVER_INIT_MEMBER(toki_state,toki) ROM[i] = buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,13,14,15,12,11,10,9,8,7,6,5,4,3,2,1,0)]; } - auto_free(machine(), buffer); - m_seibu_sound->decrypt("audiocpu",0x2000); } DRIVER_INIT_MEMBER(toki_state,tokib) { - UINT8 *temp = auto_alloc_array(machine(), UINT8, 65536 * 2); + dynamic_buffer temp(65536 * 2); int i, offs, len; UINT8 *rom; @@ -832,8 +830,6 @@ DRIVER_INIT_MEMBER(toki_state,tokib) memcpy (&base[0x18000 + i * 0x800], &temp[0x1800 + i * 0x2000], 0x800); } } - - auto_free (machine(), temp); } DRIVER_INIT_MEMBER(toki_state,jujuba) @@ -872,7 +868,7 @@ DRIVER_INIT_MEMBER(toki_state,jujuba) { UINT8 *ROM = memregion("oki")->base(); - UINT8 *buffer = auto_alloc_array(machine(), UINT8, 0x20000); + dynamic_buffer buffer(0x20000); int i; memcpy(buffer,ROM,0x20000); @@ -880,8 +876,6 @@ DRIVER_INIT_MEMBER(toki_state,jujuba) { ROM[i] = buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,13,14,15,12,11,10,9,8,7,6,5,4,3,2,1,0)]; } - - auto_free(machine(), buffer); } } diff --git a/src/mame/drivers/travrusa.c b/src/mame/drivers/travrusa.c index 6288801ddc6..2c2d46e0b85 100644 --- a/src/mame/drivers/travrusa.c +++ b/src/mame/drivers/travrusa.c @@ -542,7 +542,7 @@ DRIVER_INIT_MEMBER(travrusa_state,motorace) { int A, j; UINT8 *rom = memregion("maincpu")->base(); - UINT8 *buffer = auto_alloc_array(machine(), UINT8, 0x2000); + dynamic_buffer buffer(0x2000); memcpy(buffer, rom, 0x2000); @@ -552,8 +552,6 @@ DRIVER_INIT_MEMBER(travrusa_state,motorace) j = BITSWAP16(A,15,14,13,9,7,5,3,1,12,10,8,6,4,2,0,11); rom[j] = BITSWAP8(buffer[A],2,7,4,1,6,3,0,5); } - - auto_free(machine(), buffer); } DRIVER_INIT_MEMBER(travrusa_state,shtridra) diff --git a/src/mame/drivers/tumbleb.c b/src/mame/drivers/tumbleb.c index 5187bd2de2a..91099ea56a7 100644 --- a/src/mame/drivers/tumbleb.c +++ b/src/mame/drivers/tumbleb.c @@ -3529,7 +3529,7 @@ DRIVER_INIT_MEMBER(tumbleb_state,htchctch) void tumbleb_state::suprtrio_decrypt_code() { UINT16 *rom = (UINT16 *)memregion("maincpu")->base(); - UINT16 *buf = auto_alloc_array(machine(), UINT16, 0x80000/2); + dynamic_array buf(0x80000/2); int i; /* decrypt main ROMs */ @@ -3541,13 +3541,12 @@ void tumbleb_state::suprtrio_decrypt_code() if ((i & 3) == 0) j ^= 0x08; rom[i] = buf[j]; } - auto_free(machine(), buf); } void tumbleb_state::suprtrio_decrypt_gfx() { UINT16 *rom = (UINT16 *)memregion("tilegfx")->base(); - UINT16 *buf = auto_alloc_array(machine(), UINT16, 0x100000/2); + dynamic_array buf(0x100000/2); int i; /* decrypt tiles */ @@ -3558,7 +3557,6 @@ void tumbleb_state::suprtrio_decrypt_gfx() if (i & 1) j ^= 0x04; rom[i] = buf[j]; } - auto_free(machine(), buf); } DRIVER_INIT_MEMBER(tumbleb_state,suprtrio) diff --git a/src/mame/drivers/wecleman.c b/src/mame/drivers/wecleman.c index bd094b02c76..af851d5d2e4 100644 --- a/src/mame/drivers/wecleman.c +++ b/src/mame/drivers/wecleman.c @@ -1300,7 +1300,7 @@ void wecleman_state::wecleman_unpack_sprites() void wecleman_state::bitswap(UINT8 *src,size_t len,int _14,int _13,int _12,int _11,int _10,int _f,int _e,int _d,int _c,int _b,int _a,int _9,int _8,int _7,int _6,int _5,int _4,int _3,int _2,int _1,int _0) { - UINT8 *buffer = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer buffer(len); int i; memcpy(buffer,src,len); @@ -1309,7 +1309,6 @@ void wecleman_state::bitswap(UINT8 *src,size_t len,int _14,int _13,int _12,int _ src[i] = buffer[BITSWAP24(i,23,22,21,_14,_13,_12,_11,_10,_f,_e,_d,_c,_b,_a,_9,_8,_7,_6,_5,_4,_3,_2,_1,_0)]; } - auto_free(machine(), buffer); } /* Unpack sprites data and do some patching */ @@ -1410,11 +1409,11 @@ ROM_END void wecleman_state::hotchase_sprite_decode( int num16_banks, int bank_size ) { - UINT8 *base, *temp; + UINT8 *base; int i; base = memregion("gfx1")->base(); // sprites - temp = auto_alloc_array(machine(), UINT8, bank_size ); + dynamic_buffer temp( bank_size ); for( i = num16_banks; i >0; i-- ){ UINT8 *finish = base + 2*bank_size*i; @@ -1452,7 +1451,6 @@ void wecleman_state::hotchase_sprite_decode( int num16_banks, int bank_size ) *dest++ = data & 0xF; } while( destbase(); - UINT8 *buffer = auto_alloc_array(machine(), UINT8, 0x8000); + dynamic_buffer buffer(0x8000); // protection module reverse engineered by HIGHWAYMAN @@ -436,8 +436,6 @@ DRIVER_INIT_MEMBER(wink_state,wink) for (i = 0x6000; i <= 0x7fff; i++) ROM[i] = buffer[BITSWAP16(i,15,14,13, 11,12, 7, 9, 8,10, 6, 4, 5, 1, 2, 3, 0)]; - auto_free(machine(), buffer); - for (i = 0; i < 0x8000; i++) ROM[i] += BITSWAP8(i & 0xff, 7,5,3,1,6,4,2,0); } diff --git a/src/mame/includes/firetrk.h b/src/mame/includes/firetrk.h index 44947435b84..3104a57ce47 100644 --- a/src/mame/includes/firetrk.h +++ b/src/mame/includes/firetrk.h @@ -127,11 +127,12 @@ public: DECLARE_WRITE8_MEMBER(superbug_motor_snd_w); DECLARE_WRITE8_MEMBER(firetrk_xtndply_w); void prom_to_palette(int number, UINT8 val); - void firetrk_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx, int which, int flash); - void superbug_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx, int flash); - void montecar_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx, int which, int is_collision_detection); + void firetrk_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, int which, int flash); + void superbug_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, int flash); + void montecar_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, int which, int is_collision_detection); void check_collision(firetrk_state *state, int which); void set_service_mode(int enable); + void draw_text(palette_device &palette, bitmap_ind16 &bitmap, const rectangle &cliprect, UINT8 *alpha_ram, int x, int count, int height); }; diff --git a/src/mame/includes/gyruss.h b/src/mame/includes/gyruss.h index 7f3db0080c9..98540fb3ef9 100644 --- a/src/mame/includes/gyruss.h +++ b/src/mame/includes/gyruss.h @@ -62,5 +62,5 @@ public: UINT32 screen_update_gyruss(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); INTERRUPT_GEN_MEMBER(master_vblank_irq); INTERRUPT_GEN_MEMBER(slave_vblank_irq); - void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx ); + void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect ); }; diff --git a/src/mame/machine/atarigen.c b/src/mame/machine/atarigen.c index 6db4bdbc0a5..7123f30869c 100644 --- a/src/mame/machine/atarigen.c +++ b/src/mame/machine/atarigen.c @@ -1524,7 +1524,6 @@ void atarigen_state::blend_gfx(int gfx0, int gfx1, int mask0, int mask1) // free the second graphics element m_gfxdecode->set_gfx(gfx1, NULL); - auto_free(machine(), gx1); } diff --git a/src/mame/machine/bfm_comn.c b/src/mame/machine/bfm_comn.c index 9bc6cc6b7e7..070d7411725 100644 --- a/src/mame/machine/bfm_comn.c +++ b/src/mame/machine/bfm_comn.c @@ -19,12 +19,12 @@ static const UINT8 DataDecode[]= /////////////////////////////////////////////////////////////////////////// void bfm_decode_mainrom(running_machine &machine, const char *rom_region, UINT8* codec_data) { - UINT8 *tmp, *rom; + UINT8 *rom; rom = machine.root_device().memregion(rom_region)->base(); - tmp = auto_alloc_array(machine, UINT8, 0x10000); { + dynamic_buffer tmp(0x10000); int i; long address; @@ -64,6 +64,5 @@ void bfm_decode_mainrom(running_machine &machine, const char *rom_region, UINT8* rom[newaddress] = codec_data[ tmp[address] ]; } - auto_free(machine, tmp); } } diff --git a/src/mame/machine/deco102.c b/src/mame/machine/deco102.c index 5f4c16e8c08..932a7d1bf73 100644 --- a/src/mame/machine/deco102.c +++ b/src/mame/machine/deco102.c @@ -54,7 +54,7 @@ void deco102_decrypt_cpu(running_machine &machine, const char *cputag, int addre UINT16 *rom = (UINT16 *)machine.root_device().memregion(cputag)->base(); int size = machine.root_device().memregion(cputag)->bytes(); UINT16 *opcodes = auto_alloc_array(machine, UINT16, size / 2); - UINT16 *buf = auto_alloc_array(machine, UINT16, size / 2); + dynamic_array buf(size / 2); memcpy(buf, rom, size); @@ -88,6 +88,4 @@ void deco102_decrypt_cpu(running_machine &machine, const char *cputag, int addre rom[i] = decrypt(buf[src], i, data_select_xor); opcodes[i] = decrypt(buf[src], i, opcode_select_xor); } - - auto_free(machine, buf); } diff --git a/src/mame/machine/deco156.c b/src/mame/machine/deco156.c index b2a4f61011a..110d7ad8a83 100644 --- a/src/mame/machine/deco156.c +++ b/src/mame/machine/deco156.c @@ -126,9 +126,8 @@ void deco156_decrypt(running_machine &machine) { UINT32 *rom = (UINT32 *)machine.root_device().memregion("maincpu")->base(); int length = machine.root_device().memregion("maincpu")->bytes(); - UINT32 *buf = auto_alloc_array(machine, UINT32, length/4); + dynamic_array buf(length/4); memcpy(buf, rom, length); decrypt(buf, rom, length); - auto_free(machine, buf); } diff --git a/src/mame/machine/decocrpt.c b/src/mame/machine/decocrpt.c index 8365384db14..5580c444f0d 100644 --- a/src/mame/machine/decocrpt.c +++ b/src/mame/machine/decocrpt.c @@ -602,7 +602,7 @@ static void deco_decrypt(running_machine &machine,const char *rgntag,const UINT8 { UINT16 *rom = (UINT16 *)machine.root_device().memregion(rgntag)->base(); int len = machine.root_device().memregion(rgntag)->bytes()/2; - UINT16 *buffer = auto_alloc_array(machine, UINT16, len); + dynamic_array buffer(len); int i; /* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */ @@ -639,8 +639,6 @@ static void deco_decrypt(running_machine &machine,const char *rgntag,const UINT8 swap_patterns[pat][15]); } - auto_free(machine, buffer); - /* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */ if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) for (i = 0;i < len;i++) diff --git a/src/mame/machine/jalcrpt.c b/src/mame/machine/jalcrpt.c index db381bc77ee..3b91f78f239 100644 --- a/src/mame/machine/jalcrpt.c +++ b/src/mame/machine/jalcrpt.c @@ -123,12 +123,10 @@ void ms32_rearrange_sprites(running_machine &machine, const char *region) UINT8 *source_data; int source_size; - UINT8 *result_data; - source_data = machine.root_device().memregion ( region )->base(); source_size = machine.root_device().memregion( region )->bytes(); - result_data = auto_alloc_array(machine, UINT8, source_size); + dynamic_buffer result_data(source_size); for(i=0; ibase(); source_size = machine.root_device().memregion( region )->bytes(); - result_data = auto_alloc_array(machine, UINT8, source_size); + dynamic_buffer result_data(source_size); addr_xor ^= 0x1005d; @@ -193,7 +188,6 @@ void decrypt_ms32_tx(running_machine &machine, int addr_xor,int data_xor, const } memcpy (source_data, result_data, source_size); - auto_free (machine, result_data); } void decrypt_ms32_bg(running_machine &machine, int addr_xor,int data_xor, const char *region) @@ -202,12 +196,10 @@ void decrypt_ms32_bg(running_machine &machine, int addr_xor,int data_xor, const UINT8 *source_data; int source_size; - UINT8 *result_data; - source_data = machine.root_device().memregion ( region )->base(); source_size = machine.root_device().memregion( region )->bytes(); - result_data = auto_alloc_array(machine, UINT8, source_size); + dynamic_buffer result_data(source_size); addr_xor ^= 0xc1c5b; @@ -248,5 +240,4 @@ void decrypt_ms32_bg(running_machine &machine, int addr_xor,int data_xor, const } memcpy (source_data, result_data, source_size); - auto_free (machine, result_data); } diff --git a/src/mame/machine/kaneko_calc3.c b/src/mame/machine/kaneko_calc3.c index 1ab7c38bd53..42ecc162791 100644 --- a/src/mame/machine/kaneko_calc3.c +++ b/src/mame/machine/kaneko_calc3.c @@ -1549,7 +1549,7 @@ void kaneko_calc3_device::initial_scan_tables(running_machine& machine) for (x=0;xbytes(); UINT8 *rom = memregion( "sprites" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, cx_size ); + dynamic_buffer buf( cx_size ); memcpy( buf, rom, cx_size ); for( i = 0; i < cx_size / 0x40; i++ ){ memcpy( &rom[ i * 0x40 ], &buf[ (i ^ 1) * 0x40 ], 0x40 ); } - - auto_free( machine(), buf ); } @@ -44,7 +42,7 @@ void neogeo_state::neogeo_bootleg_sx_decrypt(int value ) if (value == 1) { - UINT8 *buf = auto_alloc_array(machine(), UINT8, sx_size ); + dynamic_buffer buf( sx_size ); memcpy( buf, rom, sx_size ); for( i = 0; i < sx_size; i += 0x10 ) @@ -52,7 +50,6 @@ void neogeo_state::neogeo_bootleg_sx_decrypt(int value ) memcpy( &rom[ i ], &buf[ i + 8 ], 8 ); memcpy( &rom[ i + 8 ], &buf[ i ], 8 ); } - auto_free( machine(), buf ); } else if (value == 2) { @@ -72,7 +69,7 @@ void neogeo_state::kog_px_decrypt() { /* the protection chip does some *very* strange things to the rom */ UINT8 *src = memregion("maincpu")->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x600000 ); + dynamic_buffer dst( 0x600000 ); UINT16 *rom = (UINT16 *)memregion("maincpu")->base(); int i; static const int sec[] = { 0x3, 0x8, 0x7, 0xC, 0x1, 0xA, 0x6, 0xD }; @@ -87,7 +84,6 @@ void neogeo_state::kog_px_decrypt() memcpy (dst + 0x090000, src + 0x040000, 0x004000); memcpy (dst + 0x100000, src + 0x200000, 0x400000); memcpy (src, dst, 0x600000); - auto_free (machine(), dst); for (i = 0x90000/2; i < 0x94000/2; i++){ if (((rom[i]&0xFFBF) == 0x4EB9 || rom[i] == 0x43F9) && !rom[i + 1]) @@ -135,7 +131,7 @@ void neogeo_state::kog_px_decrypt() void neogeo_state::kof97oro_px_decode() { int i; - UINT16 *tmp = auto_alloc_array(machine(), UINT16, 0x500000 ); + dynamic_array tmp( 0x500000 ); UINT16 *src = (UINT16*)memregion("maincpu")->base(); for (i = 0; i < 0x500000/2; i++) { @@ -143,8 +139,6 @@ void neogeo_state::kof97oro_px_decode() } memcpy (src, tmp, 0x500000); - - auto_free (machine(), tmp); } @@ -204,7 +198,7 @@ void neogeo_state::install_kof10th_protection () void neogeo_state::decrypt_kof10th() { int i, j; - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x900000); + dynamic_buffer dst(0x900000); UINT8 *src = memregion( "maincpu" )->base(); memcpy(dst + 0x000000, src + 0x700000, 0x100000); // Correct (Verified in Uni-bios) @@ -215,8 +209,6 @@ void neogeo_state::decrypt_kof10th() src[j] = dst[i]; } - auto_free(machine(), dst); - // Altera protection chip patches these over P ROM ((UINT16*)src)[0x0124/2] = 0x000d; // Enables XOR for RAM moves, forces SoftDIPs, and USA region ((UINT16*)src)[0x0126/2] = 0xf7a8; @@ -233,7 +225,7 @@ void neogeo_state::decrypt_kof10th() void neogeo_state::kf10thep_px_decrypt() { UINT16 *rom = (UINT16*)memregion("maincpu")->base(); - UINT16 *buf = auto_alloc_array(machine(), UINT16, 0x100000/2); + dynamic_array buf(0x100000/2); memcpy(&buf[0x000000/2], &rom[0x060000/2], 0x20000); memcpy(&buf[0x020000/2], &rom[0x100000/2], 0x20000); @@ -246,7 +238,6 @@ void neogeo_state::kf10thep_px_decrypt() memcpy(&buf[0x0002e0/2], &rom[0x0402e0/2], 0x6a); // copy banked code to a new memory region memcpy(&buf[0x0f92bc/2], &rom[0x0492bc/2], 0xb9e); // copy banked code to a new memory region memcpy(rom, buf, 0x100000); - auto_free(machine(), buf); for (int i = 0xf92bc/2; i < 0xf9e58/2; i++) { @@ -266,7 +257,7 @@ void neogeo_state::kf2k5uni_px_decrypt() { int i, j, ofst; UINT8 *src = memregion( "maincpu" )->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x80); + UINT8 dst[0x80]; for (i = 0; i < 0x800000; i+=0x80) { @@ -277,7 +268,6 @@ void neogeo_state::kf2k5uni_px_decrypt() } memcpy(src + i, dst, 0x80); } - auto_free(machine(), dst); memcpy(src, src + 0x600000, 0x100000); // Seems to be the same as kof10th } @@ -326,7 +316,7 @@ void neogeo_state::kof2002b_gfx_decrypt(UINT8 *src, int size) { 8, 0, 7, 6, 2, 1 }, }; - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x10000 ); + dynamic_buffer dst( 0x10000 ); for ( i = 0; i < size; i+=0x10000 ) { @@ -339,7 +329,6 @@ void neogeo_state::kof2002b_gfx_decrypt(UINT8 *src, int size) memcpy( src+i+ofst*128, dst+j*128, 128 ); } } - auto_free( machine(), dst ); } @@ -351,7 +340,7 @@ void neogeo_state::kf2k2mp_decrypt() int i,j; UINT8 *src = memregion("maincpu")->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x80); + UINT8 dst[0x80]; memmove(src, src + 0x300000, 0x500000); @@ -364,7 +353,6 @@ void neogeo_state::kf2k2mp_decrypt() } memcpy(src + i, dst, 0x80); } - auto_free(machine(), dst); } @@ -374,14 +362,13 @@ void neogeo_state::kf2k2mp_decrypt() void neogeo_state::kf2k2mp2_px_decrypt() { UINT8 *src = memregion("maincpu")->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x600000); + dynamic_buffer dst(0x600000); memcpy (dst + 0x000000, src + 0x1C0000, 0x040000); memcpy (dst + 0x040000, src + 0x140000, 0x080000); memcpy (dst + 0x0C0000, src + 0x100000, 0x040000); memcpy (dst + 0x100000, src + 0x200000, 0x400000); memcpy (src + 0x000000, dst + 0x000000, 0x600000); - auto_free (machine(), dst); } @@ -394,7 +381,7 @@ void neogeo_state::cthd2003_neogeo_gfx_address_fix_do(int start, int end, int bi int i,j; int tilesize=128; - UINT8* rom = auto_alloc_array(machine(), UINT8, 16*tilesize); // 16 tiles buffer + dynamic_buffer rom(16*tilesize); // 16 tiles buffer UINT8* realrom = memregion("sprites")->base() + start*tilesize; for (i = 0; i < (end-start)/16; i++) { @@ -409,7 +396,6 @@ void neogeo_state::cthd2003_neogeo_gfx_address_fix_do(int start, int end, int bi memcpy(realrom,rom,tilesize*16); realrom+=16*tilesize; } - auto_free(machine(), rom); } void neogeo_state::cthd2003_neogeo_gfx_address_fix(int start, int end) @@ -449,7 +435,7 @@ void neogeo_state::cthd2003_c(int pow) void neogeo_state::decrypt_cthd2003() { UINT8 *romdata = memregion("fixed")->base(); - UINT8 *tmp = auto_alloc_array(machine(), UINT8, 8*128*128); + dynamic_buffer tmp(8*128*128); memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128); memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128); @@ -464,8 +450,6 @@ void neogeo_state::decrypt_cthd2003() memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128); memcpy(romdata, tmp, 8*128*128); - auto_free(machine(), tmp); - memcpy(romdata-0x10000,romdata,0x10000); cthd2003_c(0); @@ -534,7 +518,7 @@ void neogeo_state::ct2k3sp_sx_decrypt() { int rom_size = memregion( "fixed" )->bytes(); UINT8 *rom = memregion( "fixed" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); int i; int ofst; @@ -556,21 +540,18 @@ void neogeo_state::ct2k3sp_sx_decrypt() memcpy( &rom[ 0x10000 ], &buf[ 0x08000 ], 0x8000 ); memcpy( &rom[ 0x28000 ], &buf[ 0x30000 ], 0x8000 ); memcpy( &rom[ 0x30000 ], &buf[ 0x28000 ], 0x8000 ); - - auto_free( machine(), buf ); } void neogeo_state::decrypt_ct2k3sp() { UINT8 *romdata = memregion("audiocpu")->base()+0x10000; - UINT8*tmp = auto_alloc_array(machine(), UINT8, 8*128*128); + dynamic_buffer tmp(8*128*128); memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128); memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128); memcpy(tmp+8*64*128, romdata+8*32*128, 8*32*128); memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128); memcpy(romdata, tmp, 8*128*128); - auto_free(machine(), tmp); memcpy(romdata-0x10000,romdata,0x10000); ct2k3sp_sx_decrypt(); cthd2003_c(0); @@ -583,14 +564,13 @@ void neogeo_state::decrypt_ct2k3sp() void neogeo_state::decrypt_ct2k3sa() { UINT8 *romdata = memregion("audiocpu")->base()+0x10000; - UINT8*tmp = auto_alloc_array(machine(), UINT8, 8*128*128); + dynamic_buffer tmp(8*128*128); memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128); memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128); memcpy(tmp+8*64*128, romdata+8*32*128, 8*32*128); memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128); memcpy(romdata, tmp, 8*128*128); - auto_free(machine(), tmp); memcpy(romdata-0x10000,romdata,0x10000); cthd2003_c(0); } @@ -641,7 +621,7 @@ void neogeo_state::patch_ct2k3sa() void neogeo_state::decrypt_kof2k4se_68k() { UINT8 *src = memregion("maincpu")->base()+0x100000; - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x400000); + dynamic_buffer dst(0x400000); int i; static const int sec[] = {0x300000,0x200000,0x100000,0x000000}; memcpy(dst,src,0x400000); @@ -650,7 +630,6 @@ void neogeo_state::decrypt_kof2k4se_68k() { memcpy(src+i*0x100000,dst+sec[i],0x100000); } - auto_free(machine(), dst); } @@ -671,10 +650,10 @@ void neogeo_state::lans2004_decrypt_68k() int i; UINT8 *src = memregion( "maincpu" )->base(); UINT16 *rom = (UINT16*)memregion( "maincpu" )->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x600000); { static const int sec[] = { 0x3, 0x8, 0x7, 0xC, 0x1, 0xA, 0x6, 0xD }; + dynamic_buffer dst(0x600000); for (i = 0; i < 8; i++) memcpy (dst + i * 0x20000, src + sec[i] * 0x20000, 0x20000); @@ -683,7 +662,6 @@ void neogeo_state::lans2004_decrypt_68k() memcpy (dst + 0x02FFF0, src + 0x1A92BE, 0x000010); memcpy (dst + 0x100000, src + 0x200000, 0x400000); memcpy (src, dst, 0x600000); - auto_free (machine(), dst); } for (i = 0xBBB00/2; i < 0xBE000/2; i++) { @@ -751,7 +729,7 @@ void neogeo_state::svcboot_px_decrypt() int i; int size = memregion( "maincpu" )->bytes(); UINT8 *src = memregion( "maincpu" )->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, size ); + dynamic_buffer dst( size ); int ofst; for( i = 0; i < size / 0x100000; i++ ){ memcpy( &dst[ i * 0x100000 ], &src[ sec[ i ] * 0x100000 ], 0x100000 ); @@ -761,7 +739,6 @@ void neogeo_state::svcboot_px_decrypt() ofst += (i & 0xffff00); memcpy( &src[ i * 2 ], &dst[ ofst * 2 ], 0x02 ); } - auto_free( machine(), dst ); } void neogeo_state::svcboot_cx_decrypt() @@ -780,7 +757,7 @@ void neogeo_state::svcboot_cx_decrypt() int i; int size = memregion( "sprites" )->bytes(); UINT8 *src = memregion( "sprites" )->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, size ); + dynamic_buffer dst( size ); int ofst; memcpy( dst, src, size ); for( i = 0; i < size / 0x80; i++ ){ @@ -793,7 +770,6 @@ void neogeo_state::svcboot_cx_decrypt() ofst += (i & 0xfffff00); memcpy( &src[ i * 0x80 ], &dst[ ofst * 0x80 ], 0x80 ); } - auto_free( machine(), dst ); } @@ -807,7 +783,7 @@ void neogeo_state::svcplus_px_decrypt() }; int size = memregion( "maincpu" )->bytes(); UINT8 *src = memregion( "maincpu" )->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, size ); + dynamic_buffer dst( size ); int i; int ofst; memcpy( dst, src, size ); @@ -823,7 +799,6 @@ void neogeo_state::svcplus_px_decrypt() for( i = 0; i < 6; i++ ){ memcpy( &src[ i * 0x100000 ], &dst[ sec[ i ] * 0x100000 ], 0x100000 ); } - auto_free( machine(), dst ); } void neogeo_state::svcplus_px_hack() @@ -845,12 +820,11 @@ void neogeo_state::svcplusa_px_decrypt() }; int size = memregion( "maincpu" )->bytes(); UINT8 *src = memregion( "maincpu" )->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, size ); + dynamic_buffer dst( size ); memcpy( dst, src, size ); for( i = 0; i < 6; i++ ){ memcpy( &src[ i * 0x100000 ], &dst[ sec[ i ] * 0x100000 ], 0x100000 ); } - auto_free( machine(), dst ); } @@ -864,7 +838,7 @@ void neogeo_state::svcsplus_px_decrypt() }; int size = memregion( "maincpu" )->bytes(); UINT8 *src = memregion( "maincpu" )->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, size ); + dynamic_buffer dst( size ); int i; int ofst; memcpy( dst, src, size ); @@ -876,7 +850,6 @@ void neogeo_state::svcsplus_px_decrypt() ofst += sec[ (i & 0xf80000) >> 19 ] << 19; memcpy( &src[ i * 2 ], &dst[ ofst * 2 ], 0x02 ); } - auto_free( machine(), dst ); } void neogeo_state::svcsplus_px_hack() @@ -959,13 +932,12 @@ void neogeo_state::kf2k3bl_px_decrypt() int rom_size = 0x800000; UINT8 *rom = memregion( "maincpu" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); memcpy( buf, rom, rom_size ); for( i = 0; i < rom_size / 0x100000; i++ ){ memcpy( &rom[ i * 0x100000 ], &buf[ sec[ i ] * 0x100000 ], 0x100000 ); } - auto_free( machine(), buf ); } void neogeo_state::kf2k3bl_install_protection() @@ -981,7 +953,7 @@ void neogeo_state::kf2k3bl_install_protection() void neogeo_state::kf2k3pl_px_decrypt() { - UINT16*tmp = auto_alloc_array(machine(), UINT16, 0x100000/2); + dynamic_array tmp(0x100000/2); UINT16*rom = (UINT16*)memregion( "maincpu" )->base(); int j; int i; @@ -992,7 +964,6 @@ void neogeo_state::kf2k3pl_px_decrypt() for (j = 0;j < 0x100000/2;j++) rom[i+j] = tmp[BITSWAP24(j,23,22,21,20,19,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)]; } - auto_free(machine(), tmp); /* patched by Altera protection chip on PCB */ rom[0xf38ac/2] = 0x4e75; @@ -1038,7 +1009,7 @@ void neogeo_state::samsho5b_px_decrypt() { int px_size = memregion( "maincpu" )->bytes(); UINT8 *rom = memregion( "maincpu" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, px_size ); + dynamic_buffer buf( px_size ); int ofst; int i; @@ -1056,8 +1027,6 @@ void neogeo_state::samsho5b_px_decrypt() memcpy( &rom[ 0x000000 ], &buf[ 0x700000 ], 0x100000 ); memcpy( &rom[ 0x100000 ], &buf[ 0x000000 ], 0x700000 ); - - auto_free( machine(), buf ); } @@ -1081,7 +1050,7 @@ void neogeo_state::matrimbl_decrypt() { /* decrypt Z80 */ UINT8 *rom = memregion( "audiocpu" )->base()+0x10000; - UINT8 *buf = auto_alloc_array(machine(), UINT8, 0x20000 ); + dynamic_buffer buf( 0x20000 ); int i, j=0; memcpy( buf, rom, 0x20000 ); for( i=0x00000; i<0x20000; i++ ) @@ -1112,7 +1081,6 @@ void neogeo_state::matrimbl_decrypt() } rom[ j ]=buf[ i ]; } - auto_free( machine(), buf ); memcpy( rom-0x10000, rom, 0x10000 ); /* decrypt gfx */ diff --git a/src/mame/machine/neocrypt.c b/src/mame/machine/neocrypt.c index 6ab24123c6b..eb881ec7dff 100644 --- a/src/mame/machine/neocrypt.c +++ b/src/mame/machine/neocrypt.c @@ -512,13 +512,12 @@ void neogeo_state::decrypt(UINT8 *r0, UINT8 *r1, void neogeo_state::neogeo_gfx_decrypt(int extra_xor) { int rom_size; - UINT8 *buf; UINT8 *rom; int rpos; rom_size = memregion("sprites")->bytes(); - buf = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer buf(rom_size); rom = memregion("sprites")->base(); @@ -567,8 +566,6 @@ void neogeo_state::neogeo_gfx_decrypt(int extra_xor) rom[4*rpos+2] = buf[4*baser+2]; rom[4*rpos+3] = buf[4*baser+3]; } - - auto_free(machine(), buf); } @@ -660,7 +657,7 @@ void neogeo_state::svcpcb_gfx_decrypt() int ofst; int rom_size = memregion( "sprites" )->bytes(); UINT8 *rom = memregion( "sprites" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); for( i = 0; i < rom_size; i++ ) { @@ -682,7 +679,6 @@ void neogeo_state::svcpcb_gfx_decrypt() ofst += (i & 0xffe00000); memcpy( &rom[ i * 4 ], &buf[ ofst * 4 ], 0x04 ); } - auto_free( machine(), buf ); } @@ -709,7 +705,7 @@ void neogeo_state::kf2k3pcb_gfx_decrypt() int ofst; int rom_size = memregion( "sprites" )->bytes(); UINT8 *rom = memregion( "sprites" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); for ( i = 0; i < rom_size; i++ ) { @@ -731,7 +727,6 @@ void neogeo_state::kf2k3pcb_gfx_decrypt() ofst += (i & 0xff800000); memcpy( &rom[ ofst ], &buf[ i ], 0x04 ); } - auto_free( machine(), buf ); } @@ -874,7 +869,7 @@ void neogeo_state::neogeo_cmc50_m1_decrypt() size_t rom_size = 0x80000; UINT8* rom2 = memregion("audiocpu")->base(); - UINT8* buffer = auto_alloc_array(machine(), UINT8, rom_size); + dynamic_buffer buffer(rom_size); UINT32 i; @@ -924,8 +919,6 @@ void neogeo_state::neogeo_cmc50_m1_decrypt() } } #endif - - auto_free( machine(), buffer ); } @@ -940,7 +933,7 @@ NeoGeo 'P' ROM encryption void neogeo_state::kof98_decrypt_68k() { UINT8 *src = memregion("maincpu")->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x200000); + dynamic_buffer dst(0x200000); int i, j, k; static const UINT32 sec[]={0x000000,0x100000,0x000004,0x100004,0x10000a,0x00000a,0x10000e,0x00000e}; static const UINT32 pos[]={0x000,0x004,0x00a,0x00e}; @@ -978,8 +971,6 @@ void neogeo_state::kof98_decrypt_68k() memcpy( &src[i+0x000102], &dst[i+0x100100], 2 ); } memmove( &src[0x100000], &src[0x200000], 0x400000 ); - - auto_free(machine(), dst); } @@ -1157,13 +1148,12 @@ void neogeo_state::kof2002_decrypt_68k() int i; static const int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000}; UINT8 *src = memregion("maincpu")->base()+0x100000; - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x400000); + dynamic_buffer dst(0x400000); memcpy( dst, src, 0x400000 ); for( i=0; i<8; ++i ) { memcpy( src+i*0x80000, dst+sec[i], 0x80000 ); } - auto_free(machine(), dst); } @@ -1172,13 +1162,12 @@ void neogeo_state::matrim_decrypt_68k() int i; static const int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000}; UINT8 *src = memregion("maincpu")->base()+0x100000; - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x400000); + dynamic_buffer dst(0x400000); memcpy( dst, src, 0x400000); for( i=0; i<8; ++i ) { memcpy( src+i*0x80000, dst+sec[i], 0x80000 ); } - auto_free(machine(), dst); } @@ -1187,14 +1176,13 @@ void neogeo_state::samsho5_decrypt_68k() int i; static const int sec[]={0x000000,0x080000,0x700000,0x680000,0x500000,0x180000,0x200000,0x480000,0x300000,0x780000,0x600000,0x280000,0x100000,0x580000,0x400000,0x380000}; UINT8 *src = memregion("maincpu")->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x800000); + dynamic_buffer dst(0x800000); memcpy( dst, src, 0x800000 ); for( i=0; i<16; ++i ) { memcpy( src+i*0x80000, dst+sec[i], 0x80000 ); } - auto_free(machine(), dst); } @@ -1203,14 +1191,13 @@ void neogeo_state::samsh5sp_decrypt_68k() int i; static const int sec[]={0x000000,0x080000,0x500000,0x480000,0x600000,0x580000,0x700000,0x280000,0x100000,0x680000,0x400000,0x780000,0x200000,0x380000,0x300000,0x180000}; UINT8 *src = memregion("maincpu")->base(); - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x800000); + dynamic_buffer dst(0x800000); memcpy( dst, src, 0x800000 ); for( i=0; i<16; ++i ) { memcpy( src+i*0x80000, dst+sec[i], 0x80000 ); } - auto_free(machine(), dst); } @@ -1223,7 +1210,7 @@ void neogeo_state::mslug5_decrypt_68k() int ofst; int rom_size = 0x800000; UINT8 *rom = memregion( "maincpu" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); for( i = 0; i < 0x100000; i++ ) { @@ -1256,7 +1243,6 @@ void neogeo_state::mslug5_decrypt_68k() memcpy( buf, rom, rom_size ); memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 ); memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 ); - auto_free( machine(), buf ); } @@ -1268,7 +1254,7 @@ void neogeo_state::svc_px_decrypt() int ofst; int rom_size = 0x800000; UINT8 *rom = memregion( "maincpu" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); for( i = 0; i < 0x100000; i++ ) { @@ -1301,7 +1287,6 @@ void neogeo_state::svc_px_decrypt() memcpy( buf, rom, rom_size ); memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 ); memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 ); - auto_free( machine(), buf ); } @@ -1312,7 +1297,7 @@ void neogeo_state::kf2k3pcb_decrypt_68k() int ofst; int rom_size = 0x900000; UINT8 *rom = memregion( "maincpu" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); for (i = 0; i < 0x100000; i++) { @@ -1343,7 +1328,6 @@ void neogeo_state::kf2k3pcb_decrypt_68k() memcpy (&rom[0x000000], &buf[0x000000], 0x100000); memcpy (&rom[0x100000], &buf[0x800000], 0x100000); memcpy (&rom[0x200000], &buf[0x100000], 0x700000); - auto_free( machine(), buf ); } @@ -1355,7 +1339,7 @@ void neogeo_state::kof2003_decrypt_68k() int ofst; int rom_size = 0x900000; UINT8 *rom = memregion( "maincpu" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); for (i = 0; i < 0x100000; i++) { @@ -1390,7 +1374,6 @@ void neogeo_state::kof2003_decrypt_68k() memcpy (&rom[0x000000], &buf[0x000000], 0x100000); memcpy (&rom[0x100000], &buf[0x800000], 0x100000); memcpy (&rom[0x200000], &buf[0x100000], 0x700000); - auto_free( machine(), buf ); } @@ -1402,7 +1385,7 @@ void neogeo_state::kof2003h_decrypt_68k() int ofst; int rom_size = 0x900000; UINT8 *rom = memregion( "maincpu" )->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, rom_size ); + dynamic_buffer buf( rom_size ); for (i = 0; i < 0x100000; i++) { @@ -1437,7 +1420,6 @@ void neogeo_state::kof2003h_decrypt_68k() memcpy (&rom[0x000000], &buf[0x000000], 0x100000); memcpy (&rom[0x100000], &buf[0x800000], 0x100000); memcpy (&rom[0x200000], &buf[0x100000], 0x700000); - auto_free( machine(), buf ); } @@ -1457,7 +1439,7 @@ void neogeo_state::neo_pcm2_snk_1999(int value) if( rom != NULL ) { /* swap address lines on the whole ROMs */ - UINT16 *buffer = auto_alloc_array(machine(), UINT16, value / 2); + dynamic_array buffer(value / 2); for( i = 0; i < size / 2; i += ( value / 2 ) ) { @@ -1467,7 +1449,6 @@ void neogeo_state::neo_pcm2_snk_1999(int value) rom[ i + j ] = buffer[ j ^ (value/4) ]; } } - auto_free(machine(), buffer); } } @@ -1492,7 +1473,7 @@ void neogeo_state::neo_pcm2_swap(int value) {0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62}, {0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62}}; UINT8 *src = memregion("ymsnd")->base(); - UINT8 *buf = auto_alloc_array(machine(), UINT8, 0x1000000); + dynamic_buffer buf(0x1000000); int i, j, d; memcpy(buf,src,0x1000000); @@ -1503,7 +1484,6 @@ void neogeo_state::neo_pcm2_swap(int value) d=((i+addrs[value][0])&0xffffff); src[j]=buf[d]^xordata[value][j&0x7]; } - auto_free(machine(), buf); } @@ -1529,7 +1509,7 @@ void neogeo_state::kf2k3pcb_sp1_decrypt() }; UINT16 *rom = (UINT16 *)memregion("mainbios")->base(); - UINT16 *buf = auto_alloc_array(machine(), UINT16, 0x80000/2); + dynamic_array buf(0x80000/2); int i, addr; for (i = 0; i < 0x80000/2; i++) @@ -1553,5 +1533,4 @@ void neogeo_state::kf2k3pcb_sp1_decrypt() } memcpy(rom, buf, 0x80000); - auto_free(machine(), buf); } diff --git a/src/mame/machine/pgmprot_igs027a_type1.c b/src/mame/machine/pgmprot_igs027a_type1.c index f3faba9cc63..7f28919045e 100644 --- a/src/mame/machine/pgmprot_igs027a_type1.c +++ b/src/mame/machine/pgmprot_igs027a_type1.c @@ -366,7 +366,7 @@ void pgm_arm_type1_state::pgm_decode_kovlsqh2_tiles() { int i, j; UINT16 *src = (UINT16 *)(memregion("tiles")->base() + 0x180000); - UINT16 *dst = auto_alloc_array(machine(), UINT16, 0x800000); + dynamic_array dst(0x800000); for (i = 0; i < 0x800000 / 2; i++) { @@ -376,14 +376,12 @@ void pgm_arm_type1_state::pgm_decode_kovlsqh2_tiles() } memcpy( src, dst, 0x800000 ); - - auto_free( machine(), dst ); } void pgm_arm_type1_state::pgm_decode_kovlsqh2_sprites( UINT8 *src ) { int i, j; - UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x800000); + dynamic_buffer dst(0x800000); for (i = 0; i < 0x800000; i++) { @@ -393,8 +391,6 @@ void pgm_arm_type1_state::pgm_decode_kovlsqh2_sprites( UINT8 *src ) } memcpy( src, dst, 0x800000 ); - - auto_free( machine(), dst ); } void pgm_arm_type1_state::pgm_decode_kovlsqh2_samples() @@ -413,7 +409,7 @@ void pgm_arm_type1_state::pgm_decode_kovqhsgs_program() { int i; UINT16 *src = (UINT16 *)(memregion("maincpu")->base() + 0x100000); - UINT16 *dst = auto_alloc_array(machine(), UINT16, 0x400000); + dynamic_array dst(0x400000); for (i = 0; i < 0x400000 / 2; i++) { @@ -423,15 +419,13 @@ void pgm_arm_type1_state::pgm_decode_kovqhsgs_program() } memcpy( src, dst, 0x400000 ); - - auto_free( machine(), dst ); } void pgm_arm_type1_state::pgm_decode_kovqhsgs2_program() { int i; UINT16 *src = (UINT16 *)(memregion("maincpu")->base() + 0x100000); - UINT16 *dst = auto_alloc_array(machine(), UINT16, 0x400000); + dynamic_array dst(0x400000); for (i = 0; i < 0x400000 / 2; i++) { @@ -441,8 +435,6 @@ void pgm_arm_type1_state::pgm_decode_kovqhsgs2_program() } memcpy( src, dst, 0x400000 ); - - auto_free( machine(), dst ); } diff --git a/src/mame/machine/pgmprot_igs027a_type3.c b/src/mame/machine/pgmprot_igs027a_type3.c index 89e21ca9a2d..a8150fd15ab 100644 --- a/src/mame/machine/pgmprot_igs027a_type3.c +++ b/src/mame/machine/pgmprot_igs027a_type3.c @@ -714,7 +714,7 @@ DRIVER_INIT_MEMBER(pgm_arm_type3_state,dmnfrnt) // todo, collapse these to an address swap void pgm_arm_type3_state::pgm_descramble_happy6(UINT8* src) { - UINT8* buffer = auto_alloc_array(machine(), UINT8, 0x800000); + dynamic_buffer buffer(0x800000); int writeaddress = 0; for (int j = 0; j < 0x800; j += 0x200) @@ -726,14 +726,13 @@ void pgm_arm_type3_state::pgm_descramble_happy6(UINT8* src) } } memcpy(src, buffer, 0x800000); - auto_free(machine(), buffer); } void pgm_arm_type3_state::pgm_descramble_happy6_2(UINT8* src) { - UINT8* buffer = auto_alloc_array(machine(), UINT8, 0x800000); + dynamic_buffer buffer(0x800000); int writeaddress = 0; for (int k = 0; k < 0x800000; k += 0x100000) { @@ -747,7 +746,6 @@ void pgm_arm_type3_state::pgm_descramble_happy6_2(UINT8* src) } } memcpy(src, buffer, 0x800000); - auto_free(machine(), buffer); } INPUT_PORTS_START( happy6 ) diff --git a/src/mame/machine/scramble.c b/src/mame/machine/scramble.c index d9cf23c953e..1588999a577 100644 --- a/src/mame/machine/scramble.c +++ b/src/mame/machine/scramble.c @@ -387,7 +387,6 @@ DRIVER_INIT_MEMBER(scramble_state,rescue) { offs_t i, len; UINT8 *RAM; - UINT8 *scratch; DRIVER_INIT_CALL(scobra); @@ -400,7 +399,7 @@ DRIVER_INIT_MEMBER(scramble_state,rescue) RAM = memregion("gfx1")->base(); len = memregion("gfx1")->bytes(); - scratch = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer scratch(len); memcpy(scratch, RAM, len); @@ -416,15 +415,12 @@ DRIVER_INIT_MEMBER(scramble_state,rescue) RAM[i] = scratch[j]; } - - auto_free(machine(), scratch); } DRIVER_INIT_MEMBER(scramble_state,minefld) { offs_t i, len; UINT8 *RAM; - UINT8 *scratch; DRIVER_INIT_CALL(scobra); @@ -436,7 +432,7 @@ DRIVER_INIT_MEMBER(scramble_state,minefld) RAM = memregion("gfx1")->base(); len = memregion("gfx1")->bytes(); - scratch = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer scratch(len); memcpy(scratch, RAM, len); @@ -453,8 +449,6 @@ DRIVER_INIT_MEMBER(scramble_state,minefld) RAM[i] = scratch[j]; } - - auto_free(machine(), scratch); } #ifdef UNUSED_FUNCTION diff --git a/src/mame/machine/segaic16.c b/src/mame/machine/segaic16.c index 9c0c7e84d4f..2fdea7422e5 100644 --- a/src/mame/machine/segaic16.c +++ b/src/mame/machine/segaic16.c @@ -601,8 +601,7 @@ sega_315_5195_mapper_device::decrypt_bank::decrypt_bank() m_end(0), m_rgnoffs(~0), m_srcptr(NULL), - m_fd1089(NULL), - m_fd1094_cache(NULL) + m_fd1089(NULL) { // invalidate all states reset(); @@ -615,8 +614,6 @@ sega_315_5195_mapper_device::decrypt_bank::decrypt_bank() sega_315_5195_mapper_device::decrypt_bank::~decrypt_bank() { - // delete any allocated cache - global_free(m_fd1094_cache); } @@ -631,14 +628,13 @@ void sega_315_5195_mapper_device::decrypt_bank::set_decrypt(fd1089_base_device * m_fd1089 = fd1089; // clear out all fd1094 stuff - delete m_fd1094_cache; - m_fd1094_cache = NULL; + m_fd1094_cache.reset(); } void sega_315_5195_mapper_device::decrypt_bank::set_decrypt(fd1094_device *fd1094) { // set the fd1094 pointer and allocate a decryption cache - m_fd1094_cache = global_alloc(fd1094_decryption_cache(*fd1094)); + m_fd1094_cache.reset(global_alloc(fd1094_decryption_cache(*fd1094))); // clear out all fd1089 stuff m_fd1089 = NULL; diff --git a/src/mame/machine/segaic16.h b/src/mame/machine/segaic16.h index 2b5acf37e73..6aabe5e562d 100644 --- a/src/mame/machine/segaic16.h +++ b/src/mame/machine/segaic16.h @@ -151,7 +151,7 @@ private: UINT8 * m_srcptr; fd1089_base_device * m_fd1089; dynamic_array m_fd1089_decrypted; - fd1094_decryption_cache *m_fd1094_cache; + auto_pointer m_fd1094_cache; }; // internal helpers diff --git a/src/mame/machine/segas32.c b/src/mame/machine/segas32.c index 2dc8e4399cc..3f0fb296ab5 100644 --- a/src/mame/machine/segas32.c +++ b/src/mame/machine/segas32.c @@ -37,7 +37,7 @@ void segas32_state::decrypt_ga2_protrom() { int i; UINT8 *rom = memregion("mcu")->base(); - UINT8* temp = auto_alloc_array(machine(), UINT8, 0x100000); + dynamic_buffer temp(0x100000); // make copy of ROM so original can be overwritten memcpy(temp, rom, 0x10000); @@ -45,8 +45,6 @@ void segas32_state::decrypt_ga2_protrom() // unscramble the address lines for(i = 0; i < 0x10000; i++) rom[i] = temp[BITSWAP16(i, 14, 11, 15, 12, 13, 4, 3, 7, 5, 10, 2, 8, 9, 6, 1, 0)]; - - auto_free(machine(), temp); } WRITE16_MEMBER(segas32_state::ga2_dpram_w) diff --git a/src/mame/video/aeroboto.c b/src/mame/video/aeroboto.c index cb60ded650b..4ab506e55f4 100644 --- a/src/mame/video/aeroboto.c +++ b/src/mame/video/aeroboto.c @@ -53,16 +53,13 @@ void aeroboto_state::video_start() #if STARS_LAYOUT { - UINT8 *temp; int i; - temp = auto_alloc_array(machine(), UINT8, m_stars_length); + dynamic_buffer temp(m_stars_length); memcpy(temp, m_stars_rom, m_stars_length); for (i = 0; i < m_stars_length; i++) m_stars_rom[(i & ~0xff) + (i << 5 & 0xe0) + (i >> 3 & 0x1f)] = temp[i]; - - auto_free(machine(), temp); } #endif } diff --git a/src/mame/video/atarisy1.c b/src/mame/video/atarisy1.c index bced2a446b7..dd272404e1d 100644 --- a/src/mame/video/atarisy1.c +++ b/src/mame/video/atarisy1.c @@ -617,15 +617,15 @@ int atarisy1_state::get_bank(UINT8 prom1, UINT8 prom2, int bpp) switch (bpp) { case 4: - m_gfxdecode->set_gfx(gfx_index,auto_alloc(machine(), gfx_element(m_palette, objlayout_4bpp, srcdata, 0x40, 256))); + m_gfxdecode->set_gfx(gfx_index,global_alloc(gfx_element(m_palette, objlayout_4bpp, srcdata, 0x40, 256))); break; case 5: - m_gfxdecode->set_gfx(gfx_index,auto_alloc(machine(), gfx_element(m_palette, objlayout_5bpp, srcdata, 0x40, 256))); + m_gfxdecode->set_gfx(gfx_index,global_alloc(gfx_element(m_palette, objlayout_5bpp, srcdata, 0x40, 256))); break; case 6: - m_gfxdecode->set_gfx(gfx_index,auto_alloc(machine(), gfx_element(m_palette, objlayout_6bpp, srcdata, 0x40, 256))); + m_gfxdecode->set_gfx(gfx_index,global_alloc(gfx_element(m_palette, objlayout_6bpp, srcdata, 0x40, 256))); break; default: diff --git a/src/mame/video/bfm_adr2.c b/src/mame/video/bfm_adr2.c index b18a7ced7b5..61ec2644908 100644 --- a/src/mame/video/bfm_adr2.c +++ b/src/mame/video/bfm_adr2.c @@ -458,9 +458,7 @@ void bfm_adder2_device::adder2_decode_char_roms() if ( p ) { - UINT8 *s; - - s = auto_alloc_array(machine(), UINT8, 0x40000 ); + dynamic_buffer s( 0x40000 ); { int x, y; @@ -487,7 +485,6 @@ void bfm_adder2_device::adder2_decode_char_roms() } y++; } - auto_free(machine(), s); } } } diff --git a/src/mame/video/carjmbre.c b/src/mame/video/carjmbre.c index 8c729a9a586..41cf4c2b6ff 100644 --- a/src/mame/video/carjmbre.c +++ b/src/mame/video/carjmbre.c @@ -33,12 +33,11 @@ static const res_net_info carjmbre_net_info = PALETTE_INIT_MEMBER(carjmbre_state, carjmbre) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &carjmbre_decode_info, &carjmbre_net_info); + compute_res_net_all(rgb, color_prom, carjmbre_decode_info, carjmbre_net_info); palette.set_pen_colors(0, rgb, 64); palette.palette()->normalize_range(0, 63); - auto_free(machine(), rgb); } diff --git a/src/mame/video/dkong.c b/src/mame/video/dkong.c index 3b31c4abaaa..bf6fd3445c7 100644 --- a/src/mame/video/dkong.c +++ b/src/mame/video/dkong.c @@ -200,10 +200,10 @@ static const res_net_info radarscp_grid_net_info = PALETTE_INIT_MEMBER(dkong_state,dkong2b) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; int i; - rgb = compute_res_net_all(machine(), color_prom, &dkong_decode_info, &dkong_net_info); + compute_res_net_all(rgb, color_prom, dkong_decode_info, dkong_net_info); palette.set_pen_colors(0, rgb, 256); /* Now treat tri-state black background generation */ @@ -212,9 +212,9 @@ PALETTE_INIT_MEMBER(dkong_state,dkong2b) if ( (i & 0x03) == 0x00 ) /* NOR => CS=1 => Tristate => real black */ { int r,g,b; - r = compute_res_net( 1, 0, &dkong_net_bck_info ); - g = compute_res_net( 1, 1, &dkong_net_bck_info ); - b = compute_res_net( 1, 2, &dkong_net_bck_info ); + r = compute_res_net( 1, 0, dkong_net_bck_info ); + g = compute_res_net( 1, 1, dkong_net_bck_info ); + b = compute_res_net( 1, 2, dkong_net_bck_info ); palette.set_pen_color(i,r,g,b); } @@ -223,7 +223,6 @@ PALETTE_INIT_MEMBER(dkong_state,dkong2b) color_prom += 512; /* color_prom now points to the beginning of the character color codes */ m_color_codes = color_prom; /* we'll need it later */ - auto_free(machine(), rgb); } #ifdef UNUSED_FUNCTION @@ -236,11 +235,11 @@ PALETTE_INIT_MEMBER(dkong_state,dkong4b) for (i = 0;i < 256;i++) { /* red component */ - r = compute_res_net( (color_prom[256]>>1) & 0x07, 0, &radarscp_net_info ); + r = compute_res_net( (color_prom[256]>>1) & 0x07, 0, radarscp_net_info ); /* green component */ - g = compute_res_net( ((color_prom[256]<<2) & 0x04) | ((color_prom[0]>>2) & 0x03), 1, &radarscp_net_info ); + g = compute_res_net( ((color_prom[256]<<2) & 0x04) | ((color_prom[0]>>2) & 0x03), 1, radarscp_net_info ); /* blue component */ - b = compute_res_net( (color_prom[0]>>0) & 0x03, 2, &radarscp_net_info ); + b = compute_res_net( (color_prom[0]>>0) & 0x03, 2, radarscp_net_info ); palette.set_pen_color(i,r,g,b); color_prom++; @@ -251,9 +250,9 @@ PALETTE_INIT_MEMBER(dkong_state,dkong4b) for (i=0;i<256;i++) if ( (i & 0x03) == 0x00 ) /* NOR => CS=1 => Tristate => real black */ { - r = compute_res_net( 1, 0, &radarscp_net_bck_info ); - g = compute_res_net( 1, 1, &radarscp_net_bck_info ); - b = compute_res_net( 1, 2, &radarscp_net_bck_info ); + r = compute_res_net( 1, 0, radarscp_net_bck_info ); + g = compute_res_net( 1, 1, radarscp_net_bck_info ); + b = compute_res_net( 1, 2, radarscp_net_bck_info ); palette.set_pen_color(i,r,g,b); } @@ -274,11 +273,11 @@ PALETTE_INIT_MEMBER(dkong_state,radarscp) for (i = 0;i < 256;i++) { /* red component */ - r = compute_res_net( (color_prom[256]>>1) & 0x07, 0, &radarscp_net_info ); + r = compute_res_net( (color_prom[256]>>1) & 0x07, 0, radarscp_net_info ); /* green component */ - g = compute_res_net( ((color_prom[256]<<2) & 0x04) | ((color_prom[0]>>2) & 0x03), 1, &radarscp_net_info ); + g = compute_res_net( ((color_prom[256]<<2) & 0x04) | ((color_prom[0]>>2) & 0x03), 1, radarscp_net_info ); /* blue component */ - b = compute_res_net( (color_prom[0]>>0) & 0x03, 2, &radarscp_net_info ); + b = compute_res_net( (color_prom[0]>>0) & 0x03, 2, radarscp_net_info ); palette.set_pen_color(i,r,g,b); color_prom++; @@ -289,24 +288,24 @@ PALETTE_INIT_MEMBER(dkong_state,radarscp) for (i=0;i<256;i++) if ( (m_vidhw != DKONG_RADARSCP_CONVERSION) && ( (i & 0x03) == 0x00 )) /* NOR => CS=1 => Tristate => real black */ { - r = compute_res_net( 1, 0, &radarscp_net_bck_info ); - g = compute_res_net( 1, 1, &radarscp_net_bck_info ); - b = compute_res_net( 1, 2, &radarscp_net_bck_info ); + r = compute_res_net( 1, 0, radarscp_net_bck_info ); + g = compute_res_net( 1, 1, radarscp_net_bck_info ); + b = compute_res_net( 1, 2, radarscp_net_bck_info ); palette.set_pen_color(i,r,g,b); } /* Star color */ - r = compute_res_net( 1, 0, &radarscp_stars_net_info ); - g = compute_res_net( 0, 1, &radarscp_stars_net_info ); - b = compute_res_net( 0, 2, &radarscp_stars_net_info ); + r = compute_res_net( 1, 0, radarscp_stars_net_info ); + g = compute_res_net( 0, 1, radarscp_stars_net_info ); + b = compute_res_net( 0, 2, radarscp_stars_net_info ); palette.set_pen_color(RADARSCP_STAR_COL,r,g,b); /* Oscillating background */ for (i = 0;i < 256;i++) { - r = compute_res_net( 0, 0, &radarscp_blue_net_info ); - g = compute_res_net( 0, 1, &radarscp_blue_net_info ); - b = compute_res_net( i, 2, &radarscp_blue_net_info ); + r = compute_res_net( 0, 0, radarscp_blue_net_info ); + g = compute_res_net( 0, 1, radarscp_blue_net_info ); + b = compute_res_net( i, 2, radarscp_blue_net_info ); palette.set_pen_color(RADARSCP_BCK_COL_OFFSET + i,r,g,b); } @@ -314,9 +313,9 @@ PALETTE_INIT_MEMBER(dkong_state,radarscp) /* Grid */ for (i = 0;i < 8;i++) { - r = compute_res_net( i & 1, 0, &radarscp_grid_net_info ); - g = compute_res_net( (i>>1) & 1, 1, &radarscp_grid_net_info ); - b = compute_res_net( (i>>2) & 1, 2, &radarscp_grid_net_info ); + r = compute_res_net( i & 1, 0, radarscp_grid_net_info ); + g = compute_res_net( (i>>1) & 1, 1, radarscp_grid_net_info ); + b = compute_res_net( (i>>2) & 1, 2, radarscp_grid_net_info ); palette.set_pen_color(RADARSCP_GRID_COL_OFFSET + i,r,g,b); } @@ -337,11 +336,11 @@ PALETTE_INIT_MEMBER(dkong_state,radarscp1) for (i = 0;i < 256;i++) { /* red component */ - r = compute_res_net( color_prom[512], 0, &radarscp1_net_info ); + r = compute_res_net( color_prom[512], 0, radarscp1_net_info ); /* green component */ - g = compute_res_net( color_prom[256], 1, &radarscp1_net_info ); + g = compute_res_net( color_prom[256], 1, radarscp1_net_info ); /* blue component */ - b = compute_res_net( color_prom[0], 2, &radarscp1_net_info ); + b = compute_res_net( color_prom[0], 2, radarscp1_net_info ); palette.set_pen_color(i,r,g,b); color_prom++; @@ -352,24 +351,24 @@ PALETTE_INIT_MEMBER(dkong_state,radarscp1) for (i=0;i<256;i++) if ( (i & 0x03) == 0x00 ) /* NOR => CS=1 => Tristate => real black */ { - r = compute_res_net( 0, 0, &radarscp1_net_info ); - g = compute_res_net( 0, 1, &radarscp1_net_info ); - b = compute_res_net( 0, 2, &radarscp1_net_info ); + r = compute_res_net( 0, 0, radarscp1_net_info ); + g = compute_res_net( 0, 1, radarscp1_net_info ); + b = compute_res_net( 0, 2, radarscp1_net_info ); palette.set_pen_color(i,r,g,b); } /* Star color */ - r = compute_res_net( 1, 0, &radarscp_stars_net_info ); - g = compute_res_net( 0, 1, &radarscp_stars_net_info ); - b = compute_res_net( 0, 2, &radarscp_stars_net_info ); + r = compute_res_net( 1, 0, radarscp_stars_net_info ); + g = compute_res_net( 0, 1, radarscp_stars_net_info ); + b = compute_res_net( 0, 2, radarscp_stars_net_info ); palette.set_pen_color(RADARSCP_STAR_COL,r,g,b); /* Oscillating background */ for (i = 0;i < 256;i++) { - r = compute_res_net( 0, 0, &radarscp_blue_net_info ); - g = compute_res_net( 0, 1, &radarscp_blue_net_info ); - b = compute_res_net( i, 2, &radarscp_blue_net_info ); + r = compute_res_net( 0, 0, radarscp_blue_net_info ); + g = compute_res_net( 0, 1, radarscp_blue_net_info ); + b = compute_res_net( i, 2, radarscp_blue_net_info ); palette.set_pen_color(RADARSCP_BCK_COL_OFFSET + i,r,g,b); } @@ -377,9 +376,9 @@ PALETTE_INIT_MEMBER(dkong_state,radarscp1) /* Grid */ for (i = 0;i < 8;i++) { - r = compute_res_net( i & 1, 0, &radarscp_grid_net_info ); - g = compute_res_net( (i>>1) & 1, 1, &radarscp_grid_net_info ); - b = compute_res_net( (i>>2) & 1, 2, &radarscp_grid_net_info ); + r = compute_res_net( i & 1, 0, radarscp_grid_net_info ); + g = compute_res_net( (i>>1) & 1, 1, radarscp_grid_net_info ); + b = compute_res_net( (i>>2) & 1, 2, radarscp_grid_net_info ); palette.set_pen_color(RADARSCP_GRID_COL_OFFSET + i,r,g,b); } @@ -430,12 +429,11 @@ PALETTE_INIT_MEMBER(dkong_state,radarscp1) PALETTE_INIT_MEMBER(dkong_state,dkong3) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &dkong3_decode_info, &dkong3_net_info); + compute_res_net_all(rgb, color_prom, dkong3_decode_info, dkong3_net_info); palette.set_pen_colors(0, rgb, 256); palette.palette()->normalize_range(0, 255); - auto_free(machine(), rgb); color_prom += 1024; /* color_prom now points to the beginning of the character color codes */ diff --git a/src/mame/video/firetrk.c b/src/mame/video/firetrk.c index bb4d00b9004..9d44beb4ca7 100644 --- a/src/mame/video/firetrk.c +++ b/src/mame/video/firetrk.c @@ -237,7 +237,7 @@ VIDEO_START_MEMBER(firetrk_state,montecar) } -void firetrk_state::firetrk_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx, int which, int flash) +void firetrk_state::firetrk_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, int which, int flash) { int gfx_bank, code, color, flip_x, flip_y, x, y; @@ -262,11 +262,11 @@ void firetrk_state::firetrk_draw_car(bitmap_ind16 &bitmap, const rectangle &clip y = 104; } - gfx[gfx_bank]->transpen(m_palette,bitmap,cliprect, code, color, flip_x, flip_y, x, y, 0); + m_gfxdecode->gfx(gfx_bank)->transpen(m_palette,bitmap,cliprect, code, color, flip_x, flip_y, x, y, 0); } -void firetrk_state::superbug_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx, int flash) +void firetrk_state::superbug_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, int flash) { int gfx_bank = (*m_car_rot & 0x10) ? 4 : 3; int code = ~*m_car_rot & 0x03; @@ -274,11 +274,11 @@ void firetrk_state::superbug_draw_car(bitmap_ind16 &bitmap, const rectangle &cli int flip_x = *m_car_rot & 0x04; int flip_y = *m_car_rot & 0x08; - gfx[gfx_bank]->transpen(m_palette,bitmap,cliprect, code, color, flip_x, flip_y, 144, 104, 0); + m_gfxdecode->gfx(gfx_bank)->transpen(m_palette,bitmap,cliprect, code, color, flip_x, flip_y, 144, 104, 0); } -void firetrk_state::montecar_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx, int which, int is_collision_detection) +void firetrk_state::montecar_draw_car(bitmap_ind16 &bitmap, const rectangle &cliprect, int which, int is_collision_detection) { int gfx_bank, code, color, flip_x, flip_y, x, y; @@ -303,17 +303,17 @@ void firetrk_state::montecar_draw_car(bitmap_ind16 &bitmap, const rectangle &cli y = 104; } - gfx[gfx_bank]->transpen(m_palette,bitmap,cliprect, code, color, flip_x, flip_y, x, y, 0); + m_gfxdecode->gfx(gfx_bank)->transpen(m_palette,bitmap,cliprect, code, color, flip_x, flip_y, x, y, 0); } -static void draw_text(palette_device &palette, bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx, UINT8 *alpha_ram, +void firetrk_state::draw_text(palette_device &palette, bitmap_ind16 &bitmap, const rectangle &cliprect, UINT8 *alpha_ram, int x, int count, int height) { int i; for (i = 0; i < count; i++) - gfx[0]->opaque(palette,bitmap,cliprect, alpha_ram[i], 0, 0, 0, x, i * height); + m_gfxdecode->gfx(0)->opaque(palette,bitmap,cliprect, alpha_ram[i], 0, 0, 0, x, i * height); } @@ -346,21 +346,21 @@ UINT32 firetrk_state::screen_update_firetrk(screen_device &screen, bitmap_ind16 bitmap.fill(0, cliprect); m_tilemap1->draw(screen, bitmap, playfield_window, 0, 0); - firetrk_draw_car(bitmap, playfield_window, m_gfxdecode->gfx(), 0, m_flash); - firetrk_draw_car(bitmap, playfield_window, m_gfxdecode->gfx(), 1, m_flash); - draw_text(m_palette, bitmap, cliprect, m_gfxdecode->gfx(), m_alpha_num_ram + 0x00, 296, 0x10, 0x10); - draw_text(m_palette, bitmap, cliprect, m_gfxdecode->gfx(), m_alpha_num_ram + 0x10, 8, 0x10, 0x10); + firetrk_draw_car(bitmap, playfield_window, 0, m_flash); + firetrk_draw_car(bitmap, playfield_window, 1, m_flash); + draw_text(m_palette, bitmap, cliprect, m_alpha_num_ram + 0x00, 296, 0x10, 0x10); + draw_text(m_palette, bitmap, cliprect, m_alpha_num_ram + 0x10, 8, 0x10, 0x10); if (cliprect.max_y == screen.visible_area().max_y) { m_tilemap2->draw(screen, m_helper1, playfield_window, 0, 0); m_helper2.fill(0xff, playfield_window); - firetrk_draw_car(m_helper2, playfield_window, m_gfxdecode->gfx(), 0, FALSE); + firetrk_draw_car(m_helper2, playfield_window, 0, FALSE); check_collision(this, 0); m_helper2.fill(0xff, playfield_window); - firetrk_draw_car(m_helper2, playfield_window, m_gfxdecode->gfx(), 1, FALSE); + firetrk_draw_car(m_helper2, playfield_window, 1, FALSE); check_collision(this, 1); *m_blink = FALSE; @@ -380,16 +380,16 @@ UINT32 firetrk_state::screen_update_superbug(screen_device &screen, bitmap_ind16 bitmap.fill(0, cliprect); m_tilemap1->draw(screen, bitmap, playfield_window, 0, 0); - superbug_draw_car(bitmap, playfield_window, m_gfxdecode->gfx(), m_flash); - draw_text(m_palette, bitmap, cliprect, m_gfxdecode->gfx(), m_alpha_num_ram + 0x00, 296, 0x10, 0x10); - draw_text(m_palette, bitmap, cliprect, m_gfxdecode->gfx(), m_alpha_num_ram + 0x10, 8, 0x10, 0x10); + superbug_draw_car(bitmap, playfield_window, m_flash); + draw_text(m_palette, bitmap, cliprect, m_alpha_num_ram + 0x00, 296, 0x10, 0x10); + draw_text(m_palette, bitmap, cliprect, m_alpha_num_ram + 0x10, 8, 0x10, 0x10); if (cliprect.max_y == screen.visible_area().max_y) { m_tilemap2->draw(screen, m_helper1, playfield_window, 0, 0); m_helper2.fill(0xff, playfield_window); - superbug_draw_car(m_helper2, playfield_window, m_gfxdecode->gfx(), FALSE); + superbug_draw_car(m_helper2, playfield_window, FALSE); check_collision(this, 0); *m_blink = FALSE; @@ -409,21 +409,21 @@ UINT32 firetrk_state::screen_update_montecar(screen_device &screen, bitmap_ind16 bitmap.fill(0x2c, cliprect); m_tilemap1->draw(screen, bitmap, playfield_window, 0, 0); - montecar_draw_car(bitmap, playfield_window, m_gfxdecode->gfx(), 0, FALSE); - montecar_draw_car(bitmap, playfield_window, m_gfxdecode->gfx(), 1, FALSE); - draw_text(m_palette, bitmap, cliprect, m_gfxdecode->gfx(), m_alpha_num_ram + 0x00, 24, 0x20, 0x08); - draw_text(m_palette, bitmap, cliprect, m_gfxdecode->gfx(), m_alpha_num_ram + 0x20, 16, 0x20, 0x08); + montecar_draw_car(bitmap, playfield_window, 0, FALSE); + montecar_draw_car(bitmap, playfield_window, 1, FALSE); + draw_text(m_palette, bitmap, cliprect, m_alpha_num_ram + 0x00, 24, 0x20, 0x08); + draw_text(m_palette, bitmap, cliprect, m_alpha_num_ram + 0x20, 16, 0x20, 0x08); if (cliprect.max_y == screen.visible_area().max_y) { m_tilemap2->draw(screen, m_helper1, playfield_window, 0, 0); m_helper2.fill(0xff, playfield_window); - montecar_draw_car(m_helper2, playfield_window, m_gfxdecode->gfx(), 0, TRUE); + montecar_draw_car(m_helper2, playfield_window, 0, TRUE); check_collision(this, 0); m_helper2.fill(0xff, playfield_window); - montecar_draw_car(m_helper2, playfield_window, m_gfxdecode->gfx(), 1, TRUE); + montecar_draw_car(m_helper2, playfield_window, 1, TRUE); check_collision(this, 1); } diff --git a/src/mame/video/gyruss.c b/src/mame/video/gyruss.c index 9b5c913cdfe..a6d27895e06 100644 --- a/src/mame/video/gyruss.c +++ b/src/mame/video/gyruss.c @@ -124,7 +124,7 @@ READ8_MEMBER(gyruss_state::gyruss_scanline_r) } -void gyruss_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element **gfx ) +void gyruss_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect ) { int offs; @@ -139,7 +139,7 @@ void gyruss_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect int flip_x = ~m_spriteram[offs + 2] & 0x40; int flip_y = m_spriteram[offs + 2] & 0x80; - gfx[gfx_bank]->transpen(m_palette,bitmap,cliprect, code, color, flip_x, flip_y, x, y, 0); + m_gfxdecode->gfx(gfx_bank)->transpen(m_palette,bitmap,cliprect, code, color, flip_x, flip_y, x, y, 0); } } @@ -153,7 +153,7 @@ UINT32 gyruss_state::screen_update_gyruss(screen_device &screen, bitmap_ind16 &b } m_tilemap->draw(screen, bitmap, cliprect, TILEMAP_DRAW_OPAQUE, 0); - draw_sprites(bitmap, cliprect, m_gfxdecode->gfx()); + draw_sprites(bitmap, cliprect); m_tilemap->draw(screen, bitmap, cliprect, 0, 0); return 0; diff --git a/src/mame/video/hng64.c b/src/mame/video/hng64.c index 34d89fce09b..ca085b8ae09 100644 --- a/src/mame/video/hng64.c +++ b/src/mame/video/hng64.c @@ -2416,7 +2416,7 @@ void hng64_command3d(running_machine& machine, const UINT16* packet) /* A temporary place to put some polygons. This will optimize away if the compiler's any good. */ int numPolys = 0; - struct polygon* polys = auto_alloc_array(machine, struct polygon, 1024*5); + dynamic_array polys(1024*5); //printf("packet type : %04x %04x|%04x %04x|%04x %04x|%04x %04x\n", packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]); switch (packet[0]) @@ -2501,8 +2501,6 @@ void hng64_command3d(running_machine& machine, const UINT16* packet) drawShaded(machine, &polys[i]); } } - - auto_free(machine, polys); } void hng64_state::clear3d() diff --git a/src/mame/video/k001604.c b/src/mame/video/k001604.c index 3c70bc74947..c6304da534b 100644 --- a/src/mame/video/k001604.c +++ b/src/mame/video/k001604.c @@ -120,8 +120,8 @@ void k001604_device::device_start() m_layer_8x8[0]->set_transparent_pen(0); m_layer_8x8[1]->set_transparent_pen(0); - m_gfxdecode->set_gfx(m_gfx_index[0], auto_alloc_clear(machine(), gfx_element(m_palette, k001604_char_layout_layer_8x8, (UINT8*)&m_char_ram[0], m_palette->entries() / 16, 0))); - m_gfxdecode->set_gfx(m_gfx_index[1], auto_alloc_clear(machine(), gfx_element(m_palette, k001604_char_layout_layer_16x16, (UINT8*)&m_char_ram[0], m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index[0], global_alloc(gfx_element(m_palette, k001604_char_layout_layer_8x8, (UINT8*)&m_char_ram[0], m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index[1], global_alloc(gfx_element(m_palette, k001604_char_layout_layer_16x16, (UINT8*)&m_char_ram[0], m_palette->entries() / 16, 0))); save_pointer(NAME(m_reg), 0x400 / 4); save_pointer(NAME(m_char_ram), 0x200000 / 4); diff --git a/src/mame/video/k037122.c b/src/mame/video/k037122.c index 398adcf1ef5..c428c89320e 100644 --- a/src/mame/video/k037122.c +++ b/src/mame/video/k037122.c @@ -72,7 +72,7 @@ void k037122_device::device_start() m_layer[0]->set_transparent_pen(0); m_layer[1]->set_transparent_pen(0); - m_gfxdecode->set_gfx(m_gfx_index,auto_alloc_clear(machine(), gfx_element(m_palette, k037122_char_layout, (UINT8*)m_char_ram, m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index,global_alloc(gfx_element(m_palette, k037122_char_layout, (UINT8*)m_char_ram, m_palette->entries() / 16, 0))); save_pointer(NAME(m_reg), 0x400 / 4); save_pointer(NAME(m_char_ram), 0x200000 / 4); diff --git a/src/mame/video/konami_helper.c b/src/mame/video/konami_helper.c index 9556d28732d..7fae31cde46 100644 --- a/src/mame/video/konami_helper.c +++ b/src/mame/video/konami_helper.c @@ -82,7 +82,7 @@ void konami_decode_gfx(running_machine &machine, gfxdecode_device * gfxdecode, p memcpy(&gl, layout, sizeof(gl)); gl.total = total; - gfxdecode->set_gfx(gfx_index, auto_alloc(machine, gfx_element(&palette, gl, data, palette.entries() >> bpp, 0))); + gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(&palette, gl, data, palette.entries() >> bpp, 0))); } diff --git a/src/mame/video/lockon.c b/src/mame/video/lockon.c index b006856c22c..4feb180527c 100644 --- a/src/mame/video/lockon.c +++ b/src/mame/video/lockon.c @@ -109,15 +109,15 @@ PALETTE_INIT_MEMBER(lockon_state, lockon) if (p2 & 0x80) { - r = compute_res_net((p2 >> 2) & 0x1f, 0, &lockon_net_info); - g = compute_res_net(((p1 >> 5) & 0x7) | (p2 & 3) << 3, 1, &lockon_net_info); - b = compute_res_net((p1 & 0x1f), 2, &lockon_net_info); + r = compute_res_net((p2 >> 2) & 0x1f, 0, lockon_net_info); + g = compute_res_net(((p1 >> 5) & 0x7) | (p2 & 3) << 3, 1, lockon_net_info); + b = compute_res_net((p1 & 0x1f), 2, lockon_net_info); } else { - r = compute_res_net((p2 >> 2) & 0x1f, 0, &lockon_pd_net_info); - g = compute_res_net(((p1 >> 5) & 0x7) | (p2 & 3) << 3, 1, &lockon_pd_net_info); - b = compute_res_net((p1 & 0x1f), 2, &lockon_pd_net_info); + r = compute_res_net((p2 >> 2) & 0x1f, 0, lockon_pd_net_info); + g = compute_res_net(((p1 >> 5) & 0x7) | (p2 & 3) << 3, 1, lockon_pd_net_info); + b = compute_res_net((p1 & 0x1f), 2, lockon_pd_net_info); } palette.set_pen_color(i, rgb_t(r, g, b)); diff --git a/src/mame/video/m10.c b/src/mame/video/m10.c index 691921c72cb..4273fd0e787 100644 --- a/src/mame/video/m10.c +++ b/src/mame/video/m10.c @@ -98,7 +98,7 @@ VIDEO_START_MEMBER(m10_state,m10) m_tx_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(m10_state::get_tile_info),this), tilemap_mapper_delegate(FUNC(m10_state::tilemap_scan),this), 8, 8, 32, 32); m_tx_tilemap->set_transparent_pen(0); - m_back_gfx = auto_alloc(machine(), gfx_element(m_palette, backlayout, m_chargen, 8, 0)); + m_back_gfx = global_alloc(gfx_element(m_palette, backlayout, m_chargen, 8, 0)); m_gfxdecode->set_gfx(1, m_back_gfx); return ; @@ -106,7 +106,7 @@ VIDEO_START_MEMBER(m10_state,m10) VIDEO_START_MEMBER(m10_state,m15) { - m_gfxdecode->set_gfx(0,auto_alloc(machine(), gfx_element(m_palette, charlayout, m_chargen, 8, 0))); + m_gfxdecode->set_gfx(0,global_alloc(gfx_element(m_palette, charlayout, m_chargen, 8, 0))); m_tx_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(m10_state::get_tile_info),this),tilemap_mapper_delegate(FUNC(m10_state::tilemap_scan),this), 8, 8, 32, 32); diff --git a/src/mame/video/m62.c b/src/mame/video/m62.c index 31a98788e16..7af34d0b78c 100644 --- a/src/mame/video/m62.c +++ b/src/mame/video/m62.c @@ -200,15 +200,13 @@ void m62_state::m62_amplify_contrast(palette_t *palette, UINT32 numcolors) PALETTE_INIT_MEMBER(m62_state, m62) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &m62_tile_decode_info, &m62_tile_net_info); + compute_res_net_all(rgb, color_prom, m62_tile_decode_info, m62_tile_net_info); palette.set_pen_colors(0x000, rgb, 0x100); - auto_free(machine(), rgb); - rgb = compute_res_net_all(machine(), color_prom, &m62_sprite_decode_info, &m62_sprite_net_info); + compute_res_net_all(rgb, color_prom, m62_sprite_decode_info, m62_sprite_net_info); palette.set_pen_colors(0x100, rgb, 0x100); - auto_free(machine(), rgb); m62_amplify_contrast(palette.palette(),0); @@ -220,15 +218,13 @@ PALETTE_INIT_MEMBER(m62_state, m62) PALETTE_INIT_MEMBER(m62_state,lotlot) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &lotlot_tile_decode_info, &m62_tile_net_info); + compute_res_net_all(rgb, color_prom, lotlot_tile_decode_info, m62_tile_net_info); palette.set_pen_colors(0x000, rgb, 0x180); - auto_free(machine(), rgb); - rgb = compute_res_net_all(machine(), color_prom, &lotlot_sprite_decode_info, &m62_sprite_net_info); + compute_res_net_all(rgb, color_prom, lotlot_sprite_decode_info, m62_sprite_net_info); palette.set_pen_colors(0x180, rgb, 0x180); - auto_free(machine(), rgb); m62_amplify_contrast(palette.palette(),0); @@ -240,23 +236,20 @@ PALETTE_INIT_MEMBER(m62_state,lotlot) PALETTE_INIT_MEMBER(m62_state,battroad) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; // m62 palette - rgb = compute_res_net_all(machine(), color_prom, &m62_tile_decode_info, &m62_tile_net_info); + compute_res_net_all(rgb, color_prom, m62_tile_decode_info, m62_tile_net_info); palette.set_pen_colors(0x000, rgb, 0x100); - auto_free(machine(), rgb); - rgb = compute_res_net_all(machine(), color_prom, &m62_sprite_decode_info, &m62_sprite_net_info); + compute_res_net_all(rgb, color_prom, m62_sprite_decode_info, m62_sprite_net_info); palette.set_pen_colors(0x100, rgb, 0x100); - auto_free(machine(), rgb); m62_amplify_contrast(palette.palette(),0x200); // custom palette for foreground - rgb = compute_res_net_all(machine(), color_prom, &battroad_char_decode_info, &battroad_char_net_info); + compute_res_net_all(rgb, color_prom, battroad_char_decode_info, battroad_char_net_info); palette.set_pen_colors(0x200, rgb, 0x020); - auto_free(machine(), rgb); /* we'll need this at run time */ m_sprite_height_prom = color_prom + 0x620; @@ -266,15 +259,13 @@ PALETTE_INIT_MEMBER(m62_state,battroad) PALETTE_INIT_MEMBER(m62_state,spelunk2) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &spelunk2_tile_decode_info, &m62_tile_net_info); + compute_res_net_all(rgb, color_prom, spelunk2_tile_decode_info, m62_tile_net_info); palette.set_pen_colors(0x000, rgb, 0x200); - auto_free(machine(), rgb); - rgb = compute_res_net_all(machine(), color_prom, &spelunk2_sprite_decode_info, &m62_sprite_net_info); + compute_res_net_all(rgb, color_prom, spelunk2_sprite_decode_info, m62_sprite_net_info); palette.set_pen_colors(0x200, rgb, 0x100); - auto_free(machine(), rgb); m62_amplify_contrast(palette.palette(),0); diff --git a/src/mame/video/mario.c b/src/mame/video/mario.c index 98ac4f073e2..9789d36928b 100644 --- a/src/mame/video/mario.c +++ b/src/mame/video/mario.c @@ -65,14 +65,12 @@ static const res_net_info mario_net_info_std = PALETTE_INIT_MEMBER(mario_state, mario) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &mario_decode_info, &mario_net_info); + compute_res_net_all(rgb, color_prom, mario_decode_info, mario_net_info); palette.set_pen_colors(0, rgb, 256); - auto_free(machine(), rgb); - rgb = compute_res_net_all(machine(), color_prom+256, &mario_decode_info, &mario_net_info_std); + compute_res_net_all(rgb, color_prom+256, mario_decode_info, mario_net_info_std); palette.set_pen_colors(256, rgb, 256); - auto_free(machine(), rgb); palette.palette()->normalize_range(0, 255); palette.palette()->normalize_range(256, 511); diff --git a/src/mame/video/namcona1.c b/src/mame/video/namcona1.c index a7f1f1a8199..53c80a89e46 100644 --- a/src/mame/video/namcona1.c +++ b/src/mame/video/namcona1.c @@ -289,9 +289,9 @@ void namcona1_state::video_start() m_shaperam = auto_alloc_array_clear(machine(), UINT16, 0x2000*4/2 ); m_cgram = auto_alloc_array_clear(machine(), UINT16, 0x1000*0x40/2 ); - m_gfxdecode->set_gfx(0, auto_alloc( machine(), gfx_element(m_palette, cg_layout_8bpp, (UINT8 *)m_cgram, m_palette->entries()/256, 0 ))); - m_gfxdecode->set_gfx(1, auto_alloc( machine(), gfx_element(m_palette, cg_layout_4bpp, (UINT8 *)m_cgram, m_palette->entries()/16, 0 ))); - m_gfxdecode->set_gfx(2, auto_alloc( machine(), gfx_element(m_palette, shape_layout, (UINT8 *)m_shaperam, m_palette->entries()/2, 0 ))); + m_gfxdecode->set_gfx(0, global_alloc( gfx_element(m_palette, cg_layout_8bpp, (UINT8 *)m_cgram, m_palette->entries()/256, 0 ))); + m_gfxdecode->set_gfx(1, global_alloc( gfx_element(m_palette, cg_layout_4bpp, (UINT8 *)m_cgram, m_palette->entries()/16, 0 ))); + m_gfxdecode->set_gfx(2, global_alloc( gfx_element(m_palette, shape_layout, (UINT8 *)m_shaperam, m_palette->entries()/2, 0 ))); } /* namcona1_vh_start */ diff --git a/src/mame/video/phoenix.c b/src/mame/video/phoenix.c index d92f094d655..31470787f65 100644 --- a/src/mame/video/phoenix.c +++ b/src/mame/video/phoenix.c @@ -79,9 +79,9 @@ PALETTE_INIT_MEMBER(phoenix_state,phoenix) { const UINT8 *color_prom = memregion("proms")->base(); int i; - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &phoenix_decode_info, &phoenix_net_info); + compute_res_net_all(rgb, color_prom, phoenix_decode_info, phoenix_net_info); /* native order */ for (i=0;i<256;i++) { @@ -90,16 +90,15 @@ PALETTE_INIT_MEMBER(phoenix_state,phoenix) palette.set_pen_color(i,rgb[col]); } palette.palette()->normalize_range(0, 255); - auto_free(machine(), rgb); } PALETTE_INIT_MEMBER(phoenix_state,survival) { const UINT8 *color_prom = memregion("proms")->base(); int i; - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &phoenix_decode_info, &survival_net_info); + compute_res_net_all(rgb, color_prom, phoenix_decode_info, survival_net_info); /* native order */ for (i=0;i<256;i++) { @@ -108,16 +107,15 @@ PALETTE_INIT_MEMBER(phoenix_state,survival) palette.set_pen_color(i,rgb[col]); } palette.palette()->normalize_range(0, 255); - auto_free(machine(), rgb); } PALETTE_INIT_MEMBER(phoenix_state,pleiads) { const UINT8 *color_prom = memregion("proms")->base(); int i; - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &phoenix_decode_info, &pleiades_net_info); + compute_res_net_all(rgb, color_prom, phoenix_decode_info, pleiades_net_info); /* native order */ for (i=0;i<256;i++) { @@ -126,7 +124,6 @@ PALETTE_INIT_MEMBER(phoenix_state,pleiads) palette.set_pen_color(i,rgb[col]); } palette.palette()->normalize_range(0, 255); - auto_free(machine(), rgb); } /*************************************************************************** diff --git a/src/mame/video/plygonet.c b/src/mame/video/plygonet.c index 8f649332004..d63de0f9b74 100644 --- a/src/mame/video/plygonet.c +++ b/src/mame/video/plygonet.c @@ -99,7 +99,7 @@ void polygonet_state::video_start() assert(m_ttl_gfx_index != MAX_GFX_ELEMENTS); /* decode the ttl layer's gfx */ - m_gfxdecode->set_gfx(m_ttl_gfx_index, auto_alloc(machine(), gfx_element(m_palette, charlayout, memregion("gfx1")->base(), m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_ttl_gfx_index, global_alloc(gfx_element(m_palette, charlayout, memregion("gfx1")->base(), m_palette->entries() / 16, 0))); /* create the tilemap */ m_ttl_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(polygonet_state::ttl_get_tile_info),this), tilemap_mapper_delegate(FUNC(polygonet_state::plygonet_scan),this), 8, 8, 64, 32); diff --git a/src/mame/video/popeye.c b/src/mame/video/popeye.c index 3da7e8f7c67..5591f672acd 100644 --- a/src/mame/video/popeye.c +++ b/src/mame/video/popeye.c @@ -124,9 +124,9 @@ void popeye_state::convert_color_prom(const UINT8 *color_prom) { int prom_offs = i | ((i & 8) << 1); /* address bits 3 and 4 are tied together */ int r, g, b; - r = compute_res_net(((color_prom[prom_offs] ^ m_invertmask) >> 0) & 0x07, 0, &popeye_7051_txt_net_info); - g = compute_res_net(((color_prom[prom_offs] ^ m_invertmask) >> 3) & 0x07, 1, &popeye_7051_txt_net_info); - b = compute_res_net(((color_prom[prom_offs] ^ m_invertmask) >> 6) & 0x03, 2, &popeye_7051_txt_net_info); + r = compute_res_net(((color_prom[prom_offs] ^ m_invertmask) >> 0) & 0x07, 0, popeye_7051_txt_net_info); + g = compute_res_net(((color_prom[prom_offs] ^ m_invertmask) >> 3) & 0x07, 1, popeye_7051_txt_net_info); + b = compute_res_net(((color_prom[prom_offs] ^ m_invertmask) >> 6) & 0x03, 2, popeye_7051_txt_net_info); m_palette->set_pen_color(16 + (2 * i) + 0,rgb_t(0,0,0)); m_palette->set_pen_color(16 + (2 * i) + 1,rgb_t(r,g,b)); } @@ -160,15 +160,14 @@ void popeye_state::convert_color_prom(const UINT8 *color_prom) #if USE_NEW_COLOR /* sprites */ - rgb_t *rgb; + dynamic_array rgb; UINT8 cpi[512]; for (i=0; i<512; i++) cpi[i] = color_prom[i] ^ m_invertmask; - rgb = compute_res_net_all(machine(), &cpi[0], &popeye_7052_decode_info, &popeye_7052_obj_net_info); + compute_res_net_all(rgb, &cpi[0], popeye_7052_decode_info, popeye_7052_obj_net_info); m_palette->set_pen_colors(48, rgb, 256); - auto_free(machine(), rgb); #else for (i = 0;i < 256;i++) { @@ -221,13 +220,12 @@ void popeye_state::set_background_palette(int bank) #if USE_NEW_COLOR UINT8 cpi[16]; - rgb_t *rgb; + dynamic_array rgb; for (i=0; i<16; i++) cpi[i] = color_prom[i] ^ m_invertmask; - rgb = compute_res_net_all(machine(), cpi, &popeye_7051_decode_info, &popeye_7051_bck_net_info); + compute_res_net_all(rgb, cpi, popeye_7051_decode_info, popeye_7051_bck_net_info); m_palette->set_pen_colors(0, rgb, 16); - auto_free(machine(), rgb); #else for (i = 0;i < 16;i++) diff --git a/src/mame/video/popper.c b/src/mame/video/popper.c index 26c8d4114ba..38e32c86154 100644 --- a/src/mame/video/popper.c +++ b/src/mame/video/popper.c @@ -41,12 +41,11 @@ static const res_net_info popper_net_info = PALETTE_INIT_MEMBER(popper_state, popper) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &popper_decode_info, &popper_net_info); + compute_res_net_all(rgb, color_prom, popper_decode_info, popper_net_info); palette.set_pen_colors(0, rgb, 64); palette.palette()->normalize_range(0, 63); - auto_free(machine(), rgb); } WRITE8_MEMBER(popper_state::popper_ol_videoram_w) diff --git a/src/mame/video/rungun.c b/src/mame/video/rungun.c index 384cdd42b98..a174be4146f 100644 --- a/src/mame/video/rungun.c +++ b/src/mame/video/rungun.c @@ -86,7 +86,7 @@ void rungun_state::video_start() assert(gfx_index != MAX_GFX_ELEMENTS); // decode the ttl layer's gfx - m_gfxdecode->set_gfx(gfx_index, auto_alloc(machine(), gfx_element(m_palette, charlayout, memregion("gfx3")->base(), m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(m_palette, charlayout, memregion("gfx3")->base(), m_palette->entries() / 16, 0))); m_ttl_gfx_index = gfx_index; // create the tilemap diff --git a/src/mame/video/segaic24.c b/src/mame/video/segaic24.c index aaeec7698d1..8fb90ac8dcd 100644 --- a/src/mame/video/segaic24.c +++ b/src/mame/video/segaic24.c @@ -117,7 +117,7 @@ void segas24_tile::device_start() memset(char_ram, 0, 0x80000); memset(tile_ram, 0, 0x10000); - m_gfxdecode->set_gfx(char_gfx_index, auto_alloc(machine(), gfx_element(m_palette, char_layout, (UINT8 *)char_ram, m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(char_gfx_index, global_alloc(gfx_element(m_palette, char_layout, (UINT8 *)char_ram, m_palette->entries() / 16, 0))); save_pointer(NAME(tile_ram), 0x10000/2); save_pointer(NAME(char_ram), 0x80000/2); diff --git a/src/mame/video/st0016.c b/src/mame/video/st0016.c index bd13dfadccc..18dcd5957a7 100644 --- a/src/mame/video/st0016.c +++ b/src/mame/video/st0016.c @@ -449,7 +449,7 @@ VIDEO_START_MEMBER(st0016_state,st0016) assert(gfx_index != MAX_GFX_ELEMENTS); /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(gfx_index, auto_alloc(machine(), gfx_element(m_palette, charlayout, (UINT8 *) st0016_charram, 0x40, 0))); + m_gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(m_palette, charlayout, (UINT8 *) st0016_charram, 0x40, 0))); st0016_ramgfx = gfx_index; spr_dx=0; diff --git a/src/mame/video/st0020.c b/src/mame/video/st0020.c index 0db93635c87..5918490de0b 100644 --- a/src/mame/video/st0020.c +++ b/src/mame/video/st0020.c @@ -78,7 +78,7 @@ void st0020_device::device_start() if (m_gfxdecode->gfx(m_gfx_index) == 0) break; - m_gfxdecode->set_gfx(m_gfx_index, auto_alloc(machine(), gfx_element(m_palette, layout_16x8x8_2, (UINT8 *)m_st0020_gfxram, m_palette->entries() / 64, 0))); + m_gfxdecode->set_gfx(m_gfx_index, global_alloc(gfx_element(m_palette, layout_16x8x8_2, (UINT8 *)m_st0020_gfxram, m_palette->entries() / 64, 0))); m_gfxdecode->gfx(m_gfx_index)->set_granularity(64); /* 256 colour sprites with palette selectable on 64 colour boundaries */ diff --git a/src/mame/video/tagteam.c b/src/mame/video/tagteam.c index 01b3bd4727a..8a87d690ee3 100644 --- a/src/mame/video/tagteam.c +++ b/src/mame/video/tagteam.c @@ -35,11 +35,10 @@ static const res_net_decode_info tagteam_decode_info = PALETTE_INIT_MEMBER(tagteam_state, tagteam) { const UINT8 *color_prom = memregion("proms")->base(); - rgb_t *rgb; + dynamic_array rgb; - rgb = compute_res_net_all(machine(), color_prom, &tagteam_decode_info, &tagteam_net_info); + compute_res_net_all(rgb, color_prom, tagteam_decode_info, tagteam_net_info); palette.set_pen_colors(0x00, rgb, 0x20); - auto_free(machine(), rgb); } diff --git a/src/mame/video/taitojc.c b/src/mame/video/taitojc.c index bdf2c1b309c..499b38d295e 100644 --- a/src/mame/video/taitojc.c +++ b/src/mame/video/taitojc.c @@ -315,7 +315,7 @@ void taitojc_state::video_start() m_tile_ram = auto_alloc_array_clear(machine(), UINT32, 0x4000/4); /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(m_gfx_index, auto_alloc(machine(), gfx_element(m_palette, taitojc_char_layout, (UINT8 *)m_char_ram, m_palette->entries() / 16, 0))); + m_gfxdecode->set_gfx(m_gfx_index, global_alloc(gfx_element(m_palette, taitojc_char_layout, (UINT8 *)m_char_ram, m_palette->entries() / 16, 0))); m_texture = auto_alloc_array(machine(), UINT8, 0x400000); diff --git a/src/mame/video/tc0080vco.c b/src/mame/video/tc0080vco.c index 27626993216..dc1701a0c01 100644 --- a/src/mame/video/tc0080vco.c +++ b/src/mame/video/tc0080vco.c @@ -201,7 +201,7 @@ void tc0080vco_device::device_start() m_scroll_ram = m_ram + 0x20800 / 2; /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(m_txnum, auto_alloc_clear(machine(), gfx_element(m_palette, charlayout, (UINT8 *)m_char_ram, 64, 0))); + m_gfxdecode->set_gfx(m_txnum, global_alloc(gfx_element(m_palette, charlayout, (UINT8 *)m_char_ram, 64, 0))); save_pointer(NAME(m_ram), TC0080VCO_RAM_SIZE / 2); machine().save().register_postload(save_prepost_delegate(FUNC(tc0080vco_device::postload), this)); diff --git a/src/mame/video/tc0100scn.c b/src/mame/video/tc0100scn.c index 4231a33968b..47e215dfd8c 100644 --- a/src/mame/video/tc0100scn.c +++ b/src/mame/video/tc0100scn.c @@ -283,7 +283,7 @@ void tc0100scn_device::device_start() /* we call this here, so that they can be modified at video_start*/ /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(m_txnum, auto_alloc_clear(machine(), gfx_element(m_palette, tc0100scn_charlayout, (UINT8 *)m_char_ram, 64, 0))); + m_gfxdecode->set_gfx(m_txnum, global_alloc(gfx_element(m_palette, tc0100scn_charlayout, (UINT8 *)m_char_ram, 64, 0))); save_pointer(NAME(m_ram), TC0100SCN_RAM_SIZE / 2); save_item(NAME(m_ctrl)); diff --git a/src/mame/video/tc0480scp.c b/src/mame/video/tc0480scp.c index 1aabd0aaa2b..a83d8199afc 100644 --- a/src/mame/video/tc0480scp.c +++ b/src/mame/video/tc0480scp.c @@ -292,7 +292,7 @@ void tc0480scp_device::device_start() set_layer_ptrs(); /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(m_txnum, auto_alloc_clear(machine(), gfx_element(m_palette, tc0480scp_charlayout, (UINT8 *)m_char_ram, 64, 0))); + m_gfxdecode->set_gfx(m_txnum, global_alloc(gfx_element(m_palette, tc0480scp_charlayout, (UINT8 *)m_char_ram, 64, 0))); save_pointer(NAME(m_ram), TC0480SCP_RAM_SIZE / 2); save_item(NAME(m_ctrl)); diff --git a/src/mame/video/tceptor.c b/src/mame/video/tceptor.c index eadc92a29a9..bd5e66f1de5 100644 --- a/src/mame/video/tceptor.c +++ b/src/mame/video/tceptor.c @@ -236,11 +236,10 @@ void tceptor_state::decode_bg(const char * region) int gfx_index = m_bg; UINT8 *src = memregion(region)->base() + 0x8000; - UINT8 *buffer; int len = 0x8000; int i; - buffer = auto_alloc_array(machine(), UINT8, len); + dynamic_buffer buffer(len); /* expand rom tc2-19.10d */ for (i = 0; i < len / 2; i++) @@ -250,16 +249,15 @@ void tceptor_state::decode_bg(const char * region) } memcpy(src, buffer, len); - auto_free(machine(), buffer); /* decode the graphics */ - m_gfxdecode->set_gfx(gfx_index, auto_alloc(machine(), gfx_element(m_palette, bg_layout, memregion(region)->base(), 64, 0x0a00))); + m_gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(m_palette, bg_layout, memregion(region)->base(), 64, 0x0a00))); } void tceptor_state::decode_sprite(int gfx_index, const gfx_layout *layout, const void *data) { /* decode the graphics */ - m_gfxdecode->set_gfx(gfx_index, auto_alloc(machine(), gfx_element(m_palette, *layout, (const UINT8 *)data, 64, 1024))); + m_gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(m_palette, *layout, (const UINT8 *)data, 64, 1024))); } // fix sprite order diff --git a/src/mame/video/tx1.c b/src/mame/video/tx1.c index 9ee16fb6ff6..c5966f05bf5 100644 --- a/src/mame/video/tx1.c +++ b/src/mame/video/tx1.c @@ -130,9 +130,9 @@ PALETTE_INIT_MEMBER(tx1_state,tx1) { int r, g, b; - r = compute_res_net(color_prom[i + 0x300] & 0xf, 0, &tx1_net_info); - g = compute_res_net(color_prom[i + 0x400] & 0xf, 1, &tx1_net_info); - b = compute_res_net(color_prom[i + 0x500] & 0xf, 2, &tx1_net_info); + r = compute_res_net(color_prom[i + 0x300] & 0xf, 0, tx1_net_info); + g = compute_res_net(color_prom[i + 0x400] & 0xf, 1, tx1_net_info); + b = compute_res_net(color_prom[i + 0x500] & 0xf, 2, tx1_net_info); palette.set_pen_color(i, rgb_t(r, g, b)); } diff --git a/src/mame/video/ygv608.c b/src/mame/video/ygv608.c index 8f4e680acbd..6295e1a59fc 100644 --- a/src/mame/video/ygv608.c +++ b/src/mame/video/ygv608.c @@ -534,8 +534,6 @@ void ygv608_device::device_start() memset(&m_base_addr, 0, sizeof(m_base_addr)); m_base_y_shift = 0; - m_work_bitmap = NULL; - // flag rebuild of the tilemaps m_screen_resize = 1; m_tilemap_resize = 1; @@ -783,8 +781,7 @@ UINT32 ygv608_device::update_screen(screen_device &screen, bitmap_ind16 &bitmap, 0, ((int)(m_regs.s.vdw)<<3)-1 ); #endif - auto_free( machine(), m_work_bitmap ); - m_work_bitmap = auto_bitmap_ind16_alloc(machine(), screen.width(), screen.height()); + m_work_bitmap.resize(screen.width(), screen.height()); // reset resize flag m_screen_resize = 0; @@ -822,7 +819,7 @@ UINT32 ygv608_device::update_screen(screen_device &screen, bitmap_ind16 &bitmap, m_tilemap_B->set_scroll_cols(m_page_x ); // now clear the screen in case we change to 1-plane mode - m_work_bitmap->fill(0, finalclip ); + m_work_bitmap.fill(0, finalclip ); // reset resize flag m_tilemap_resize = 0; @@ -875,12 +872,12 @@ UINT32 ygv608_device::update_screen(screen_device &screen, bitmap_ind16 &bitmap, if ((m_regs.s.r7 & r7_md) & MD_1PLANE) { // If the background tilemap is disabled, we need to clear the bitmap to black - m_work_bitmap->fill(0, finalclip); -// m_work_bitmap->fill(1, *visarea); + m_work_bitmap.fill(0, finalclip); +// m_work_bitmap.fill(1, *visarea); } else #endif - m_tilemap_B->draw(screen, *m_work_bitmap, finalclip, 0, 0 ); + m_tilemap_B->draw(screen, m_work_bitmap, finalclip, 0, 0 ); #ifdef _ENABLE_ROTATE_ZOOM @@ -896,7 +893,7 @@ UINT32 ygv608_device::update_screen(screen_device &screen, bitmap_ind16 &bitmap, cos_theta = (double)m_dx / (double)0x10000; if( m_regs.s.zron ) - copyrozbitmap( bitmap, finalclip, m_work_bitmap, + copyrozbitmap( bitmap, finalclip, &m_work_bitmap, ( visarea.min_x << 16 ) + m_ax + 0x10000 * r * ( -sin( alpha ) * cos_theta + cos( alpha ) * sin_theta ), @@ -906,29 +903,29 @@ UINT32 ygv608_device::update_screen(screen_device &screen, bitmap_ind16 &bitmap, m_dx, m_dxy, m_dyx, m_dy, 0); else #endif - copybitmap( bitmap, *m_work_bitmap, 0, 0, 0, 0, finalclip); + copybitmap( bitmap, m_work_bitmap, 0, 0, 0, 0, finalclip); // for some reason we can't use an opaque m_tilemap_A // so use a transparent but clear the work bitmap first // - look at why this is the case?!? - m_work_bitmap->fill(0, visarea ); + m_work_bitmap.fill(0, visarea ); if ((m_regs.s.r11 & r11_prm) == PRM_ASBDEX || (m_regs.s.r11 & r11_prm) == PRM_ASEBDX ) draw_sprites(bitmap, finalclip); - m_tilemap_A->draw(screen, *m_work_bitmap, finalclip, 0, 0 ); + m_tilemap_A->draw(screen, m_work_bitmap, finalclip, 0, 0 ); #ifdef _ENABLE_ROTATE_ZOOM if( m_regs.s.zron ) - copyrozbitmap_trans( bitmap, finalclip, m_work_bitmap, + copyrozbitmap_trans( bitmap, finalclip, &m_work_bitmap, m_ax, // + ( visarea.min_x << 16 ), m_ay, // + ( visarea.min_y << 16 ), m_dx, m_dxy, m_dyx, m_dy, 0, 0 ); else #endif - copybitmap_trans( bitmap, *m_work_bitmap, 0, 0, 0, 0, finalclip, 0 ); + copybitmap_trans( bitmap, m_work_bitmap, 0, 0, 0, 0, finalclip, 0 ); if ((m_regs.s.r11 & r11_prm) == PRM_SABDEX || (m_regs.s.r11 & r11_prm) == PRM_SEABDX) diff --git a/src/mame/video/ygv608.h b/src/mame/video/ygv608.h index aee4c5793b9..3dbd6b0e7f0 100644 --- a/src/mame/video/ygv608.h +++ b/src/mame/video/ygv608.h @@ -323,7 +323,7 @@ private: tilemap_t *m_tilemap_B_cache_16[3]; tilemap_t *m_tilemap_A; tilemap_t *m_tilemap_B; - bitmap_ind16 *m_work_bitmap; + bitmap_ind16 m_work_bitmap; void HandleYGV608Reset(); void HandleRomTransfers(); diff --git a/src/mess/drivers/aim65.c b/src/mess/drivers/aim65.c index 518563672d4..cd6876a8a24 100644 --- a/src/mess/drivers/aim65.c +++ b/src/mess/drivers/aim65.c @@ -221,7 +221,6 @@ static const struct aim_cart_range aim_cart_table[] = DEVICE_IMAGE_LOAD_MEMBER( aim65_state, aim65_cart ) { UINT32 size; - UINT8 *temp_copy; const struct aim_cart_range *aim_cart = &aim_cart_table[0], *this_cart; /* First, determine where this cart has to be loaded */ @@ -243,22 +242,21 @@ DEVICE_IMAGE_LOAD_MEMBER( aim65_state, aim65_cart ) return IMAGE_INIT_FAIL; } + dynamic_buffer temp_copy; if (image.software_entry() == NULL) { size = image.length(); - temp_copy = auto_alloc_array(machine(), UINT8, size); if (size > 0x1000) { image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } + temp_copy.resize(size); if (image.fread(temp_copy, size) != size) { image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } } @@ -274,14 +272,12 @@ DEVICE_IMAGE_LOAD_MEMBER( aim65_state, aim65_cart ) } size = image.get_software_region_length(this_cart->tag + 1); - temp_copy = auto_alloc_array(machine(), UINT8, size); + temp_copy.resize(size); memcpy(temp_copy, image.get_software_region(this_cart->tag + 1), size); } memcpy(memregion("maincpu")->base() + this_cart->offset, temp_copy, size); - auto_free(machine(), temp_copy); - return IMAGE_INIT_PASS; } diff --git a/src/mess/drivers/atari400.c b/src/mess/drivers/atari400.c index 1e483cb2dfa..74fabf6492b 100644 --- a/src/mess/drivers/atari400.c +++ b/src/mess/drivers/atari400.c @@ -2270,8 +2270,8 @@ DEVICE_IMAGE_LOAD_MEMBER( a400_state, a5200_cart ) { /* load an optional (dual) cartidge */ size = image.fread(&mem[0x4000], 0x8000); - const char *info = hashfile_extrainfo(image); - if (info && !strcmp(info, "A13MIRRORING")) + astring info; + if (hashfile_extrainfo(image, info) && info == "A13MIRRORING") A13_mirr = TRUE; } else diff --git a/src/mess/drivers/atom.c b/src/mess/drivers/atom.c index 47dac0336a4..2cd0afb4e59 100644 --- a/src/mess/drivers/atom.c +++ b/src/mess/drivers/atom.c @@ -740,7 +740,6 @@ static const struct atom_cart_range atom_cart_table[] = DEVICE_IMAGE_LOAD_MEMBER( atom_state, atom_cart ) { UINT32 size; - UINT8 *temp_copy; int mirror, i; const struct atom_cart_range *atom_cart = &atom_cart_table[0], *this_cart; @@ -763,29 +762,28 @@ DEVICE_IMAGE_LOAD_MEMBER( atom_state, atom_cart ) return IMAGE_INIT_FAIL; } + dynamic_buffer temp_copy; if (image.software_entry() == NULL) { size = image.length(); - temp_copy = auto_alloc_array(machine(), UINT8, size); if (size > 0x1000) { image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } + temp_copy.resize(size); if (image.fread(temp_copy, size) != size) { image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } } else { size = image.get_software_region_length( "rom"); - temp_copy = auto_alloc_array(machine(), UINT8, size); + temp_copy.resize(size); memcpy(temp_copy, image.get_software_region("rom"), size); } @@ -795,8 +793,6 @@ DEVICE_IMAGE_LOAD_MEMBER( atom_state, atom_cart ) for (i = 0; i < mirror; i++) memcpy(memregion(this_cart->region)->base() + this_cart->offset + i * size, temp_copy, size); - auto_free(machine(), temp_copy); - return IMAGE_INIT_PASS; } diff --git a/src/mess/drivers/bcs3.c b/src/mess/drivers/bcs3.c index d449598a5bc..38d3d45c769 100644 --- a/src/mess/drivers/bcs3.c +++ b/src/mess/drivers/bcs3.c @@ -29,7 +29,7 @@ public: required_device m_maincpu; const UINT8 *m_p_chargen; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; DECLARE_READ8_MEMBER(bcs3_keyboard_r); virtual void machine_reset(); virtual void video_start(); diff --git a/src/mess/drivers/beehive.c b/src/mess/drivers/beehive.c index 14dbc4b90b6..284dc692d69 100644 --- a/src/mess/drivers/beehive.c +++ b/src/mess/drivers/beehive.c @@ -36,7 +36,7 @@ public: DECLARE_READ8_MEMBER(beehive_60_r); DECLARE_WRITE8_MEMBER(beehive_62_w); const UINT8 *m_p_chargen; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; UINT8 m_keyline; virtual void machine_reset(); virtual void video_start(); diff --git a/src/mess/drivers/binbug.c b/src/mess/drivers/binbug.c index 5b08d098690..5a6ace253ad 100644 --- a/src/mess/drivers/binbug.c +++ b/src/mess/drivers/binbug.c @@ -80,8 +80,8 @@ public: UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); optional_device m_keyboard; required_device m_cass; - required_shared_ptr m_p_videoram; - required_shared_ptr m_p_attribram; + required_shared_ptr m_p_videoram; + required_shared_ptr m_p_attribram; required_device m_maincpu; DECLARE_QUICKLOAD_LOAD_MEMBER( binbug ); }; diff --git a/src/mess/drivers/c10.c b/src/mess/drivers/c10.c index 21266f6cb50..1db7924cfdc 100644 --- a/src/mess/drivers/c10.c +++ b/src/mess/drivers/c10.c @@ -29,7 +29,7 @@ public: required_device m_maincpu; const UINT8 *m_p_chargen; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; virtual void machine_reset(); virtual void video_start(); UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); diff --git a/src/mess/drivers/casloopy.c b/src/mess/drivers/casloopy.c index 426a8493892..3b5ae2191af 100644 --- a/src/mess/drivers/casloopy.c +++ b/src/mess/drivers/casloopy.c @@ -228,8 +228,8 @@ void casloopy_state::video_start() for(int i=0;i<0x10000;i++) m_vram[i] = i & 0xff; - m_gfxdecode->set_gfx(m_gfx_index, auto_alloc(machine(), gfx_element(m_palette, casloopy_4bpp_layout, m_vram, 0x10, 0))); - m_gfxdecode->set_gfx(m_gfx_index+1, auto_alloc(machine(), gfx_element(m_palette, casloopy_8bpp_layout, m_vram, 1, 0))); + m_gfxdecode->set_gfx(m_gfx_index, global_alloc(gfx_element(m_palette, casloopy_4bpp_layout, m_vram, 0x10, 0))); + m_gfxdecode->set_gfx(m_gfx_index+1, global_alloc(gfx_element(m_palette, casloopy_8bpp_layout, m_vram, 1, 0))); } UINT32 casloopy_state::screen_update_casloopy(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) diff --git a/src/mess/drivers/cdc721.c b/src/mess/drivers/cdc721.c index 128833b80af..783b789c67e 100644 --- a/src/mess/drivers/cdc721.c +++ b/src/mess/drivers/cdc721.c @@ -25,7 +25,7 @@ public: DECLARE_PALETTE_INIT(cdc721); const UINT8 *m_p_chargen; UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; private: required_device m_maincpu; diff --git a/src/mess/drivers/crvision.c b/src/mess/drivers/crvision.c index 3816ad73ea2..e6d2ca385ff 100644 --- a/src/mess/drivers/crvision.c +++ b/src/mess/drivers/crvision.c @@ -762,20 +762,20 @@ void laser2001_state::machine_start() DEVICE_IMAGE_LOAD_MEMBER( crvision_state, crvision_cart ) { UINT32 size; - UINT8 *temp_copy; + dynamic_buffer temp_copy; UINT8 *mem = memregion(M6502_TAG)->base(); address_space &program = m_maincpu->space(AS_PROGRAM); if (image.software_entry() == NULL) { size = image.length(); - temp_copy = auto_alloc_array(machine(), UINT8, size); + temp_copy.resize(size); image.fread( temp_copy, size); } else { size= image.get_software_region_length("rom"); - temp_copy = auto_alloc_array(machine(), UINT8, size); + temp_copy.resize(size); memcpy(temp_copy, image.get_software_region("rom"), size); } @@ -862,8 +862,6 @@ DEVICE_IMAGE_LOAD_MEMBER( crvision_state, crvision_cart ) membank(BANK_ROM2)->configure_entry(0, mem + 0x4000); membank(BANK_ROM2)->set_entry(0); - auto_free(machine(), temp_copy); - return IMAGE_INIT_PASS; } diff --git a/src/mess/drivers/grfd2301.c b/src/mess/drivers/grfd2301.c index 517b03e8227..a8aff5d9524 100644 --- a/src/mess/drivers/grfd2301.c +++ b/src/mess/drivers/grfd2301.c @@ -47,7 +47,7 @@ public: virtual void machine_reset(); const UINT8 *m_p_chargen; UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; private: required_device m_maincpu; diff --git a/src/mess/drivers/irisha.c b/src/mess/drivers/irisha.c index 469be379702..481c82e2360 100644 --- a/src/mess/drivers/irisha.c +++ b/src/mess/drivers/irisha.c @@ -46,7 +46,7 @@ public: TIMER_CALLBACK_MEMBER(irisha_key); DECLARE_WRITE_LINE_MEMBER(irisha_pic_set_int_line); UINT32 screen_update_irisha(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; private: bool m_sg1_line; diff --git a/src/mess/drivers/jonos.c b/src/mess/drivers/jonos.c index 1721d470f45..0bc8a8a9422 100644 --- a/src/mess/drivers/jonos.c +++ b/src/mess/drivers/jonos.c @@ -27,7 +27,7 @@ public: DECLARE_DRIVER_INIT(jonos); UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; private: const UINT8 *m_p_chargen; virtual void machine_reset(); diff --git a/src/mess/drivers/megadriv.c b/src/mess/drivers/megadriv.c index 946cd186608..31c2cbd5071 100644 --- a/src/mess/drivers/megadriv.c +++ b/src/mess/drivers/megadriv.c @@ -394,7 +394,7 @@ DRIVER_INIT_MEMBER(md_cons_state,md_jpn) DEVICE_IMAGE_LOAD_MEMBER( md_base_state, _32x_cart ) { UINT32 length; - UINT8 *temp_copy; + dynamic_buffer temp_copy; UINT16 *ROM16; UINT32 *ROM32; int i; @@ -402,13 +402,13 @@ DEVICE_IMAGE_LOAD_MEMBER( md_base_state, _32x_cart ) if (image.software_entry() == NULL) { length = image.length(); - temp_copy = auto_alloc_array(machine(), UINT8, length); + temp_copy.resize(length); image.fread(temp_copy, length); } else { length = image.get_software_region_length("rom"); - temp_copy = auto_alloc_array(machine(), UINT8, length); + temp_copy.resize(length); memcpy(temp_copy, image.get_software_region("rom"), length); } @@ -426,8 +426,6 @@ DEVICE_IMAGE_LOAD_MEMBER( md_base_state, _32x_cart ) for (i = 0x00; i < length; i += 2) ROM16[i / 2] = pick_integer_be(temp_copy, i, 2); - auto_free(machine(), temp_copy); - return IMAGE_INIT_PASS; } diff --git a/src/mess/drivers/mes.c b/src/mess/drivers/mes.c index 5a9586eea84..e15a1c9cefc 100644 --- a/src/mess/drivers/mes.c +++ b/src/mess/drivers/mes.c @@ -22,7 +22,7 @@ public: required_device m_maincpu; const UINT8 *m_p_chargen; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; virtual void machine_reset(); virtual void video_start(); UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); diff --git a/src/mess/drivers/mz2500.c b/src/mess/drivers/mz2500.c index b27d96a6b30..2aa2048fe35 100644 --- a/src/mess/drivers/mz2500.c +++ b/src/mess/drivers/mz2500.c @@ -1782,8 +1782,8 @@ void mz2500_state::machine_start() save_pointer(NAME(m_emm_ram), 0x100000); /* TODO: gfx[4] crashes as per now */ - m_gfxdecode->set_gfx(3, auto_alloc(machine(), gfx_element(m_palette, mz2500_pcg_layout_1bpp, (UINT8 *)m_pcg_ram, 0x10, 0))); - m_gfxdecode->set_gfx(4, auto_alloc(machine(), gfx_element(m_palette, mz2500_pcg_layout_3bpp, (UINT8 *)m_pcg_ram, 4, 0))); + m_gfxdecode->set_gfx(3, global_alloc(gfx_element(m_palette, mz2500_pcg_layout_1bpp, (UINT8 *)m_pcg_ram, 0x10, 0))); + m_gfxdecode->set_gfx(4, global_alloc(gfx_element(m_palette, mz2500_pcg_layout_3bpp, (UINT8 *)m_pcg_ram, 4, 0))); } void mz2500_state::machine_reset() diff --git a/src/mess/drivers/pegasus.c b/src/mess/drivers/pegasus.c index 3357c25e8d1..e33f5a13739 100644 --- a/src/mess/drivers/pegasus.c +++ b/src/mess/drivers/pegasus.c @@ -75,7 +75,7 @@ public: UINT8 m_kbd_row; bool m_kbd_irq; UINT8 *m_p_pcgram; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; const UINT8 *m_p_chargen; UINT8 m_control_bits; virtual void machine_reset(); diff --git a/src/mess/drivers/ptcsol.c b/src/mess/drivers/ptcsol.c index 921ff7b6ee2..9206bddfdd7 100644 --- a/src/mess/drivers/ptcsol.c +++ b/src/mess/drivers/ptcsol.c @@ -187,7 +187,7 @@ private: required_device m_cass2; required_device m_uart; required_device m_uart_s; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; required_ioport m_iop_arrows; required_ioport m_iop_config; required_ioport m_iop_s1; diff --git a/src/mess/drivers/rex6000.c b/src/mess/drivers/rex6000.c index 40156b2c283..c348e19feae 100644 --- a/src/mess/drivers/rex6000.c +++ b/src/mess/drivers/rex6000.c @@ -569,22 +569,19 @@ QUICKLOAD_LOAD_MEMBER( rex6000_state,rex6000) static const char magic[] = "ApplicationName:Addin"; address_space& flash = machine().device("flash0b")->memory().space(0); UINT32 img_start = 0; - UINT8 *data; - data = (UINT8*)auto_alloc_array(machine(), UINT8, image.length()); + dynamic_buffer data(image.length()); image.fread(data, image.length()); - if(strncmp((const char*)data, magic, 21)) + if(strncmp((const char*)&data[0], magic, 21)) return IMAGE_INIT_FAIL; - img_start = strlen((const char*)data) + 5; + img_start = strlen((const char*)&data[0]) + 5; img_start += 0xa0; //skip the icon (40x32 pixel) for (UINT32 i=0; i m_p_videoram; + required_shared_ptr m_p_videoram; DECLARE_DRIVER_INIT(sbrain); DECLARE_MACHINE_RESET(sbrain); DECLARE_READ8_MEMBER(ppi_pa_r); diff --git a/src/mess/drivers/smc777.c b/src/mess/drivers/smc777.c index 085139e4c6b..626c4cb18d4 100644 --- a/src/mess/drivers/smc777.c +++ b/src/mess/drivers/smc777.c @@ -988,7 +988,7 @@ void smc777_state::machine_start() save_pointer(NAME(m_gvram), 0x8000); save_pointer(NAME(m_pcg), 0x800); - m_gfxdecode->set_gfx(0, auto_alloc(machine(), gfx_element(m_palette, smc777_charlayout, (UINT8 *)m_pcg, 8, 0))); + m_gfxdecode->set_gfx(0, global_alloc(gfx_element(m_palette, smc777_charlayout, (UINT8 *)m_pcg, 8, 0))); } void smc777_state::machine_reset() diff --git a/src/mess/drivers/spc1000.c b/src/mess/drivers/spc1000.c index f12dbba4317..1075957d15f 100644 --- a/src/mess/drivers/spc1000.c +++ b/src/mess/drivers/spc1000.c @@ -51,7 +51,7 @@ public: return state->m_p_videoram[0x1000+(ch&0x7F)*16+line]; } - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; private: UINT8 m_IPLK; UINT8 m_GMODE; diff --git a/src/mess/drivers/sv8000.c b/src/mess/drivers/sv8000.c index 384d6353994..8e13c6d8cd7 100644 --- a/src/mess/drivers/sv8000.c +++ b/src/mess/drivers/sv8000.c @@ -69,7 +69,7 @@ private: required_device m_maincpu; required_device m_s68047p; - required_shared_ptr m_videoram; + required_shared_ptr m_videoram; required_ioport m_io_row0; required_ioport m_io_row1; required_ioport m_io_row2; diff --git a/src/mess/drivers/svision.c b/src/mess/drivers/svision.c index f07abb71d1a..4eb17678a74 100644 --- a/src/mess/drivers/svision.c +++ b/src/mess/drivers/svision.c @@ -474,32 +474,30 @@ DRIVER_INIT_MEMBER(svision_state,svisions) DEVICE_IMAGE_LOAD_MEMBER( svision_state, svision_cart ) { UINT32 size; - UINT8 *temp_copy; + dynamic_buffer temp_copy; int mirror, i; if (image.software_entry() == NULL) { size = image.length(); - temp_copy = auto_alloc_array(machine(), UINT8, size); if (size > memregion("user1")->bytes()) { image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } + temp_copy.resize(size); if (image.fread( temp_copy, size) != size) { image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } } else { size = image.get_software_region_length("rom"); - temp_copy = auto_alloc_array(machine(), UINT8, size); + temp_copy.resize(size); memcpy(temp_copy, image.get_software_region("rom"), size); } @@ -511,8 +509,6 @@ DEVICE_IMAGE_LOAD_MEMBER( svision_state, svision_cart ) memcpy(memregion("user1")->base() + i * size, temp_copy, size); } - auto_free(machine(), temp_copy); - return IMAGE_INIT_PASS; } diff --git a/src/mess/drivers/uzebox.c b/src/mess/drivers/uzebox.c index 81c98912926..697fc00127c 100644 --- a/src/mess/drivers/uzebox.c +++ b/src/mess/drivers/uzebox.c @@ -274,16 +274,14 @@ DEVICE_IMAGE_LOAD_MEMBER(uzebox_state,uzebox_cart) if (image.software_entry() == NULL) { UINT32 size = image.length(); - UINT8* data = (UINT8*)auto_alloc_array(machine(), UINT8, size); + dynamic_buffer data(size); image.fread(data, size); - if (!strncmp((const char*)data, "UZEBOX", 6)) + if (!strncmp((const char*)&data[0], "UZEBOX", 6)) memcpy(rom, data + 0x200, size - 0x200); else memcpy(rom, data, size); - - auto_free(machine(), data); } else { diff --git a/src/mess/drivers/x1.c b/src/mess/drivers/x1.c index f02def5cedd..4af21662d7c 100644 --- a/src/mess/drivers/x1.c +++ b/src/mess/drivers/x1.c @@ -2526,7 +2526,7 @@ MACHINE_START_MEMBER(x1_state,x1) save_pointer(NAME(m_emm_ram), 0x1000000); save_pointer(NAME(m_pcg_ram), 0x1800); - m_gfxdecode->set_gfx(3, auto_alloc(machine(), gfx_element(m_palette, x1_pcg_8x8, (UINT8 *)m_pcg_ram, 1, 0))); + m_gfxdecode->set_gfx(3, global_alloc(gfx_element(m_palette, x1_pcg_8x8, (UINT8 *)m_pcg_ram, 1, 0))); } PALETTE_INIT_MEMBER(x1_state,x1) diff --git a/src/mess/drivers/z9001.c b/src/mess/drivers/z9001.c index a7987691668..5cf49ff70b8 100644 --- a/src/mess/drivers/z9001.c +++ b/src/mess/drivers/z9001.c @@ -59,8 +59,8 @@ public: UINT8 m_framecnt; required_device m_beeper; required_device m_cass; - required_shared_ptr m_p_colorram; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_colorram; + required_shared_ptr m_p_videoram; DECLARE_WRITE8_MEMBER(kbd_put); DECLARE_WRITE8_MEMBER(port88_w); DECLARE_WRITE_LINE_MEMBER(cass_w); diff --git a/src/mess/drivers/zorba.c b/src/mess/drivers/zorba.c index 702f348c5ed..2342fdef044 100644 --- a/src/mess/drivers/zorba.c +++ b/src/mess/drivers/zorba.c @@ -65,7 +65,7 @@ public: const UINT8 *m_p_chargen; UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); DECLARE_PALETTE_INIT(zorba); - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; DECLARE_DRIVER_INIT(zorba); DECLARE_MACHINE_RESET(zorba); DECLARE_READ8_MEMBER(ram_r); diff --git a/src/mess/drivers/zrt80.c b/src/mess/drivers/zrt80.c index 18337b17417..410d132a222 100644 --- a/src/mess/drivers/zrt80.c +++ b/src/mess/drivers/zrt80.c @@ -48,7 +48,7 @@ public: DECLARE_WRITE8_MEMBER(zrt80_38_w); DECLARE_WRITE8_MEMBER(kbd_put); const UINT8 *m_p_chargen; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); private: diff --git a/src/mess/includes/apollo.h b/src/mess/includes/apollo.h index 471364f8c86..810026bb65b 100644 --- a/src/mess/includes/apollo.h +++ b/src/mess/includes/apollo.h @@ -299,10 +299,10 @@ class apollo_graphics_15i : public device_t public: apollo_graphics_15i(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); apollo_graphics_15i(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock, device_type type, const char *name, const char *shortname, const char *source); - ~apollo_graphics_15i() { global_free(m_token); } + ~apollo_graphics_15i(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + class apollo_graphics *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -310,7 +310,7 @@ protected: virtual void device_reset(); private: // internal state - void *m_token; + class apollo_graphics *m_token; }; extern const device_type APOLLO_GRAPHICS; diff --git a/src/mess/includes/mz80.h b/src/mess/includes/mz80.h index 2a80c29955c..ae91c8af3b4 100644 --- a/src/mess/includes/mz80.h +++ b/src/mess/includes/mz80.h @@ -47,9 +47,9 @@ public: bool m_prev_state; UINT8 m_mz80k_cursor_cnt; UINT8 m_mz80k_keyboard_line; - required_shared_ptr m_p_ram; + required_shared_ptr m_p_ram; const UINT8 *m_p_chargen; - required_shared_ptr m_p_videoram; + required_shared_ptr m_p_videoram; DECLARE_DRIVER_INIT(mz80k); virtual void machine_reset(); virtual void video_start(); diff --git a/src/mess/machine/amstrad.c b/src/mess/machine/amstrad.c index bddc8c74af6..709e1ad9352 100644 --- a/src/mess/machine/amstrad.c +++ b/src/mess/machine/amstrad.c @@ -3197,7 +3197,7 @@ DEVICE_IMAGE_LOAD_MEMBER(amstrad_state, amstrad_plus_cartridge) // ... and so on. UINT32 size, offset = 0; - UINT8 *temp_copy; + dynamic_buffer temp_copy; unsigned char header[12]; // RIFF chunk char chunkid[4]; // chunk ID (4 character code - cb00, cb01, cb02... upto cb31 (max 512kB), other chunks are ignored) char chunklen[4]; // chunk length (always little-endian) @@ -3209,18 +3209,17 @@ DEVICE_IMAGE_LOAD_MEMBER(amstrad_state, amstrad_plus_cartridge) if (image.software_entry() == NULL) { size = image.length(); - temp_copy = auto_alloc_array(machine(), UINT8, size); + temp_copy.resize(size); if (image.fread(temp_copy, size) != size) { logerror("IMG: failed to read from cart image\n"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } } else { size= image.get_software_region_length("rom"); - temp_copy = auto_alloc_array(machine(), UINT8, size); + temp_copy.resize(size); memcpy(temp_copy, image.get_software_region("rom"), size); } @@ -3242,7 +3241,6 @@ DEVICE_IMAGE_LOAD_MEMBER(amstrad_state, amstrad_plus_cartridge) if ((size - offset) < 0x4000) { logerror("BIN: block %i loaded is smaller than 16kB in size\n", offset / 0x4000); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } offset += 0x4000; @@ -3254,7 +3252,6 @@ DEVICE_IMAGE_LOAD_MEMBER(amstrad_state, amstrad_plus_cartridge) if (strncmp((char*)(header + 8), "AMS!", 4) != 0) { logerror("CPR: not an Amstrad CPC cartridge image\n"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } @@ -3312,10 +3309,8 @@ DEVICE_IMAGE_LOAD_MEMBER(amstrad_state, amstrad_plus_cartridge) else // CPR carts in our softlist { logerror("Gamelist cart in RIFF format\n"); - auto_free(machine(), temp_copy); return IMAGE_INIT_FAIL; } - auto_free(machine(), temp_copy); return IMAGE_INIT_PASS; } diff --git a/src/mess/machine/cococart.c b/src/mess/machine/cococart.c index 98689ce8d59..85c8844e0e0 100644 --- a/src/mess/machine/cococart.c +++ b/src/mess/machine/cococart.c @@ -360,9 +360,9 @@ bool cococart_slot_device::call_load() // call_softlist_load //------------------------------------------------- -bool cococart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool cococart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -372,9 +372,9 @@ bool cococart_slot_device::call_softlist_load(char *swlist, char *swname, rom_en // get_default_card_software //------------------------------------------------- -const char * cococart_slot_device::get_default_card_software(const machine_config &devlist, emu_options &options) +void cococart_slot_device::get_default_card_software(astring &result) { - return software_get_default_slot(devlist, options, this, "pak"); + software_get_default_slot(result, "pak"); } diff --git a/src/mess/machine/cococart.h b/src/mess/machine/cococart.h index 6aceea37931..e207ae26068 100644 --- a/src/mess/machine/cococart.h +++ b/src/mess/machine/cococart.h @@ -83,7 +83,7 @@ public: // image-level overrides virtual bool call_load(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); virtual iodevice_t image_type() const { return IO_CARTSLOT; } @@ -97,7 +97,7 @@ public: virtual const option_guide *create_option_guide() const { return NULL; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing to $FF40-$FF7F DECLARE_READ8_MEMBER(read); diff --git a/src/mess/machine/cybiko.c b/src/mess/machine/cybiko.c index faed6a32554..a18c93f8dd4 100644 --- a/src/mess/machine/cybiko.c +++ b/src/mess/machine/cybiko.c @@ -46,11 +46,10 @@ QUICKLOAD_LOAD_MEMBER( cybiko_state, cybikoxt ) address_space &dest = m_maincpu->space(AS_PROGRAM); UINT32 size = MIN(image.length(), RAMDISK_SIZE); - UINT8 *buffer = global_alloc_array(UINT8, size); + dynamic_buffer buffer(size); image.fread(buffer, size); for (int byte = 0; byte < size; byte++) dest.write_byte(0x400000 + byte, buffer[byte]); - global_free(buffer); return IMAGE_INIT_PASS; } @@ -62,7 +61,7 @@ QUICKLOAD_LOAD_MEMBER( cybiko_state, cybikoxt ) NVRAM_HANDLER( cybikoxt ) { address_space &space = machine.driver_data()->m_maincpu->space(AS_PROGRAM); - UINT8 *buffer = global_alloc_array(UINT8, RAMDISK_SIZE); + dynamic_buffer buffer(RAMDISK_SIZE); if (read_or_write) { @@ -81,8 +80,6 @@ NVRAM_HANDLER( cybikoxt ) for (offs_t offs = 0; offs < RAMDISK_SIZE; offs++) space.write_byte(0x400000 + offs, buffer[offs]); } - - global_free(buffer); } void cybiko_state::machine_start() diff --git a/src/mess/machine/hd63450.c b/src/mess/machine/hd63450.c index 6d689dced4f..c39a39d2919 100644 --- a/src/mess/machine/hd63450.c +++ b/src/mess/machine/hd63450.c @@ -473,6 +473,8 @@ hd63450_device::hd63450_device(const machine_config &mconfig, const char *tag, d m_token = global_alloc_clear(hd63450_t); } +hd63450_device::~hd63450_device() { global_free(m_token); } + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/mess/machine/hd63450.h b/src/mess/machine/hd63450.h index 98aeea113e1..e732608ec9e 100644 --- a/src/mess/machine/hd63450.h +++ b/src/mess/machine/hd63450.h @@ -27,17 +27,17 @@ class hd63450_device : public device_t { public: hd63450_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~hd63450_device() { global_free(m_token); } + ~hd63450_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct hd63450_t *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); virtual void device_start(); private: // internal state - void *m_token; + struct hd63450_t *m_token; }; extern const device_type HD63450; diff --git a/src/mess/machine/intv.c b/src/mess/machine/intv.c index f4d31afc38d..97e7427980a 100644 --- a/src/mess/machine/intv.c +++ b/src/mess/machine/intv.c @@ -470,8 +470,8 @@ int intv_state::intv_load_rom_file(device_image_interface &image) // 7. extra = 1 ECS, 2 Intellivoice int start, size; int mapper, rom[5], ram, extra; - const char *extrainfo = hashfile_extrainfo(image); - if (!extrainfo) + astring extrainfo; + if (!hashfile_extrainfo(image, extrainfo)) { /* If no extrainfo, we assume a single 0x2000 chunk at 0x5000 */ for (i = 0; i < 0x2000; i++ ) @@ -484,7 +484,7 @@ int intv_state::intv_load_rom_file(device_image_interface &image) } else { - sscanf(extrainfo,"%d %d %d %d %d %d %d", &mapper, &rom[0], &rom[1], &rom[2], + sscanf(extrainfo.cstr() ,"%d %d %d %d %d %d %d", &mapper, &rom[0], &rom[1], &rom[2], &rom[3], &ram, &extra); // logerror("extrainfo: %d %d %d %d %d %d %d \n", mapper, rom[0], rom[1], rom[2], diff --git a/src/mess/machine/kc.c b/src/mess/machine/kc.c index 5632ca27f49..6c6815e792c 100644 --- a/src/mess/machine/kc.c +++ b/src/mess/machine/kc.c @@ -28,7 +28,6 @@ struct kcc_header /* load snapshot */ QUICKLOAD_LOAD_MEMBER( kc_state,kc) { - UINT8 *data; struct kcc_header *header; UINT16 addr; UINT16 datasize; @@ -38,20 +37,13 @@ QUICKLOAD_LOAD_MEMBER( kc_state,kc) /* get file size */ UINT64 size = image.length(); - if (size != 0) - { - /* malloc memory for this data */ - data = (UINT8 *)auto_alloc_array(machine(), UINT8, size); - - if (data != NULL) - image.fread( data, size); - } - else - { + if (size == 0) return IMAGE_INIT_FAIL; - } - header = (struct kcc_header *) data; + dynamic_buffer data(size); + image.fread( data, size); + + header = (struct kcc_header *) &data[0]; addr = (header->load_address_l & 0x0ff) | ((header->load_address_h & 0x0ff)<<8); datasize = ((header->end_address_l & 0x0ff) | ((header->end_address_h & 0x0ff)<<8)) - addr; execution_address = (header->execution_address_l & 0x0ff) | ((header->execution_address_h & 0x0ff)<<8); @@ -73,8 +65,6 @@ QUICKLOAD_LOAD_MEMBER( kc_state,kc) m_maincpu->set_pc(execution_address); } - auto_free(machine(), data); - logerror("Snapshot loaded at: 0x%04x-0x%04x, execution address: 0x%04x\n", addr, addr + datasize - 1, execution_address); return IMAGE_INIT_PASS; diff --git a/src/mess/machine/microdrv.h b/src/mess/machine/microdrv.h index 65cd535f458..561e847445a 100644 --- a/src/mess/machine/microdrv.h +++ b/src/mess/machine/microdrv.h @@ -38,7 +38,7 @@ public: virtual bool call_load(); virtual void call_unload(); virtual void call_display_info() { if (m_device_displayinfo) m_device_displayinfo(*this); } - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } virtual iodevice_t image_type() const { return IO_CASSETTE; } diff --git a/src/mess/machine/msx.c b/src/mess/machine/msx.c index 43fdce1b9ca..08183994c4b 100644 --- a/src/mess/machine/msx.c +++ b/src/mess/machine/msx.c @@ -72,7 +72,7 @@ DEVICE_IMAGE_LOAD_MEMBER(msx_state,msx_cart) int size_aligned; UINT8 *mem; int type = -1; - const char *extra = NULL; + astring extra; char *sramfile; slot_state *st; int id = -1; @@ -179,21 +179,19 @@ DEVICE_IMAGE_LOAD_MEMBER(msx_state,msx_cart) } /* see if msx.crc will tell us more */ - extra = hashfile_extrainfo(image); - - if (!extra) + if (!hashfile_extrainfo(image, extra)) { logerror("cart #%d: warning: no information in crc file\n", id); type = -1; } else - if ((1 != sscanf(extra, "%d", &type) ) || type < 0 || type > SLOT_LAST_CARTRIDGE_TYPE) + if ((1 != sscanf(extra.cstr(), "%d", &type) ) || type < 0 || type > SLOT_LAST_CARTRIDGE_TYPE) { logerror("cart #%d: warning: information in crc file not valid\n", id); type = -1; } else - logerror ("cart #%d: info: cart extra info: '%s' = %s\n", id, extra, msx_slot_list[type].name); + logerror ("cart #%d: info: cart extra info: '%s' = %s\n", id, extra.cstr(), msx_slot_list[type].name); /* if not, attempt autodetection */ if (type < 0) diff --git a/src/mess/machine/pce_slot.c b/src/mess/machine/pce_slot.c index b500982ae88..642545cf346 100644 --- a/src/mess/machine/pce_slot.c +++ b/src/mess/machine/pce_slot.c @@ -287,9 +287,9 @@ void pce_cart_slot_device::call_unload() call softlist load -------------------------------------------------*/ -bool pce_cart_slot_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool pce_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - load_software_part_region(this, swlist, swname, start_entry ); + load_software_part_region(*this, swlist, swname, start_entry ); return TRUE; } @@ -328,28 +328,28 @@ int pce_cart_slot_device::get_cart_type(UINT8 *ROM, UINT32 len) get default card software -------------------------------------------------*/ -const char * pce_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options) +void pce_cart_slot_device::get_default_card_software(astring &result) { - if (open_image_file(options)) + if (open_image_file(mconfig().options())) { const char *slot_string = "rom"; UINT32 len = core_fsize(m_file); - UINT8 *ROM = global_alloc_array(UINT8, len); + dynamic_buffer rom(len); int type; - core_fread(m_file, ROM, len); + core_fread(m_file, rom, len); - type = get_cart_type(ROM, len); + type = get_cart_type(rom, len); slot_string = pce_get_slot(type); //printf("type: %s\n", slot_string); - global_free(ROM); clear(); - return slot_string; + result.cpy(slot_string); + return; } - return software_get_default_slot(config, options, this, "rom"); + software_get_default_slot(result, "rom"); } /*------------------------------------------------- diff --git a/src/mess/machine/pce_slot.h b/src/mess/machine/pce_slot.h index 5622024ebd8..655fffa57da 100644 --- a/src/mess/machine/pce_slot.h +++ b/src/mess/machine/pce_slot.h @@ -67,7 +67,7 @@ public: // image-level overrides virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); int get_type() { return m_type; } int get_cart_type(UINT8 *ROM, UINT32 len); @@ -88,7 +88,7 @@ public: virtual const char *file_extensions() const { return "pce,bin"; } // slot interface overrides - virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + virtual void get_default_card_software(astring &result); // reading and writing virtual DECLARE_READ8_MEMBER(read_cart); diff --git a/src/mess/machine/psion_pack.c b/src/mess/machine/psion_pack.c index ea62850f561..98f26eb5673 100644 --- a/src/mess/machine/psion_pack.c +++ b/src/mess/machine/psion_pack.c @@ -94,16 +94,7 @@ void datapack_device::device_start() void datapack_device::device_config_complete() { - image_device_format *format = global_alloc_clear(image_device_format); - - format->m_index = 0; - format->m_name = "opk"; - format->m_description = "Psion Datapack image"; - format->m_extensions = "opk"; - format->m_optspec = datapack_option_spec; - format->m_next = NULL; - - m_formatlist = format; + m_formatlist.append(*global_alloc(image_device_format("opk", "Psion Datapack image", "opk", datapack_option_spec))); // set brief and instance name update_names(); diff --git a/src/mess/machine/psion_pack.h b/src/mess/machine/psion_pack.h index 74169703a2d..47ff33d8383 100644 --- a/src/mess/machine/psion_pack.h +++ b/src/mess/machine/psion_pack.h @@ -28,7 +28,7 @@ public: virtual bool call_load(); virtual void call_unload(); virtual bool call_create(int format_type, option_resolution *create_args); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } virtual iodevice_t image_type() const { return IO_CARTSLOT; } virtual bool is_readable() const { return 1; } diff --git a/src/mess/machine/psxcd.c b/src/mess/machine/psxcd.c index 02be32111ce..25ab627cc37 100644 --- a/src/mess/machine/psxcd.c +++ b/src/mess/machine/psxcd.c @@ -151,7 +151,7 @@ void psxcd_device::device_stop() for (int i = 0; i < MAX_PSXCD_TIMERS; i++) { if(m_timerinuse[i] && m_timers[i]->ptr()) - global_free(m_timers[i]->ptr()); + global_free((command_result *)m_timers[i]->ptr()); } while(res_queue) { @@ -169,7 +169,7 @@ void psxcd_device::device_reset() for (int i = 0; i < MAX_PSXCD_TIMERS; i++) { if(m_timerinuse[i] && m_timers[i]->ptr()) - global_free(m_timers[i]->ptr()); + global_free((command_result *)m_timers[i]->ptr()); m_timers[i]->adjust(attotime::never, 0, attotime::never); m_timerinuse[i] = false; } @@ -1220,7 +1220,7 @@ void psxcd_device::device_timer(emu_timer &timer, device_timer_id tid, int param } } -int psxcd_device::add_system_event(int type, UINT64 t, void *ptr) +int psxcd_device::add_system_event(int type, UINT64 t, command_result *ptr) { // t is in maincpu clock cycles UINT32 hz = m_sysclock / t; diff --git a/src/mess/machine/psxcd.h b/src/mess/machine/psxcd.h index 45f6f7ce453..6d2f8a5f81a 100644 --- a/src/mess/machine/psxcd.h +++ b/src/mess/machine/psxcd.h @@ -96,7 +96,7 @@ private: void read_sector(); void play_sector(); UINT32 sub_loc(CDPOS src1, CDPOS src2); - int add_system_event(int type, UINT64 t, void *ptr); + int add_system_event(int type, UINT64 t, command_result *ptr); UINT8 bcd_to_decimal(const UINT8 bcd) { return ((bcd>>4)*10)+(bcd&0xf); } UINT8 decimal_to_bcd(const UINT8 dec) { return ((dec/10)<<4)|(dec%10); } diff --git a/src/mess/machine/s1410.c b/src/mess/machine/s1410.c index b79d963ded6..195be0c04f5 100644 --- a/src/mess/machine/s1410.c +++ b/src/mess/machine/s1410.c @@ -260,7 +260,7 @@ void s1410_device::ExecCommand() if ((m_disk) && (m_blocks)) { - UINT8 *data = global_alloc_array(UINT8, m_sector_bytes); + dynamic_buffer data(m_sector_bytes); memset(data, 0xc6, m_sector_bytes); while (m_blocks > 0) @@ -272,8 +272,6 @@ void s1410_device::ExecCommand() m_lba++; m_blocks--; } - - global_free(data); } m_phase = SCSI_PHASE_STATUS; diff --git a/src/mess/machine/smartmed.h b/src/mess/machine/smartmed.h index 17c0e72614c..6e8337b82b9 100644 --- a/src/mess/machine/smartmed.h +++ b/src/mess/machine/smartmed.h @@ -161,7 +161,7 @@ public: virtual bool call_load(); virtual void call_unload(); - virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } + virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } void set_image_interface(const char *image_interface) { m_image_interface = image_interface; } protected: diff --git a/src/mess/machine/strata.c b/src/mess/machine/strata.c index 81632a6eec2..8fbe3e4659a 100644 --- a/src/mess/machine/strata.c +++ b/src/mess/machine/strata.c @@ -108,6 +108,8 @@ strataflash_device::strataflash_device(const machine_config &mconfig, const char m_token = global_alloc_clear(strata_t); } +strataflash_device::~strataflash_device() { global_free(m_token); } + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/mess/machine/strata.h b/src/mess/machine/strata.h index f5a2534f369..6b954f832c5 100644 --- a/src/mess/machine/strata.h +++ b/src/mess/machine/strata.h @@ -6,17 +6,17 @@ class strataflash_device : public device_t { public: strataflash_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~strataflash_device() { global_free(m_token); } + ~strataflash_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct strata_t *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); virtual void device_start(); private: // internal state - void *m_token; + struct strata_t *m_token; }; extern const device_type STRATAFLASH; diff --git a/src/mess/machine/ti99/990_tap.c b/src/mess/machine/ti99/990_tap.c index b83120cb2b9..57deb20d918 100644 --- a/src/mess/machine/ti99/990_tap.c +++ b/src/mess/machine/ti99/990_tap.c @@ -1073,6 +1073,8 @@ tap_990_device::tap_990_device(const machine_config &mconfig, const char *tag, d m_token = global_alloc_clear(tap_990_t); } +tap_990_device::~tap_990_device() { global_free(m_token); } + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/mess/machine/ti99/990_tap.h b/src/mess/machine/ti99/990_tap.h index 280a70f6676..33b23a27183 100644 --- a/src/mess/machine/ti99/990_tap.h +++ b/src/mess/machine/ti99/990_tap.h @@ -20,10 +20,10 @@ class tap_990_device : public device_t { public: tap_990_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~tap_990_device() { global_free(m_token); } + ~tap_990_device(); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct tap_990_t *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); @@ -31,7 +31,7 @@ protected: virtual machine_config_constructor device_mconfig_additions() const; private: // internal state - void *m_token; + struct tap_990_t *m_token; }; extern const device_type TI990_TAPE_CTRL; diff --git a/src/mess/machine/ti99/gromport.c b/src/mess/machine/ti99/gromport.c index fa54d3e5976..15f6e16720e 100644 --- a/src/mess/machine/ti99/gromport.c +++ b/src/mess/machine/ti99/gromport.c @@ -1325,10 +1325,10 @@ void ti99_cartridge_device::set_slot(int i) m_slot = i; } -bool ti99_cartridge_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +bool ti99_cartridge_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) { - if (VERBOSE>8) LOG("ti99_cartridge_device: swlist = %s, swname = %s\n", swlist, swname); - load_software_part_region(this, swlist, swname, start_entry); + if (VERBOSE>8) LOG("ti99_cartridge_device: swlist = %s, swname = %s\n", swlist.list_name(), swname); + load_software_part_region(*this, swlist, swname, start_entry); m_softlist = true; m_rpk = NULL; return true; diff --git a/src/mess/machine/ti99/gromport.h b/src/mess/machine/ti99/gromport.h index 8b7e1b07cba..65c5aa549eb 100644 --- a/src/mess/machine/ti99/gromport.h +++ b/src/mess/machine/ti99/gromport.h @@ -96,7 +96,7 @@ protected: // Image handling: implementation of methods which are abstract in the parent bool call_load(); void call_unload(); - bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); + bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry); void prepare_cartridge(); diff --git a/src/mess/video/733_asr.c b/src/mess/video/733_asr.c index 329334dce0a..39b844df0b7 100644 --- a/src/mess/video/733_asr.c +++ b/src/mess/video/733_asr.c @@ -229,6 +229,8 @@ asr733_device::asr733_device(const machine_config &mconfig, const char *tag, dev m_token = global_alloc_clear(asr_t); } +asr733_device::~asr733_device() { global_free(m_token); } + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/mess/video/733_asr.h b/src/mess/video/733_asr.h index c105c49bd35..27e24917c7f 100644 --- a/src/mess/video/733_asr.h +++ b/src/mess/video/733_asr.h @@ -19,12 +19,12 @@ class asr733_device : public device_t { public: asr733_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~asr733_device() { global_free(m_token); } + ~asr733_device(); DECLARE_PALETTE_INIT(asr733); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct asr_t *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides @@ -36,7 +36,7 @@ public: required_device m_palette; private: // internal state - void *m_token; + struct asr_t *m_token; required_device m_gfxdecode; }; diff --git a/src/mess/video/911_vdt.c b/src/mess/video/911_vdt.c index ae905341e0f..3b337e32608 100644 --- a/src/mess/video/911_vdt.c +++ b/src/mess/video/911_vdt.c @@ -279,6 +279,8 @@ vdt911_device::vdt911_device(const machine_config &mconfig, const char *tag, dev m_token = global_alloc_clear(vdt_t); } +vdt911_device::~vdt911_device() { global_free(m_token); } + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/mess/video/911_vdt.h b/src/mess/video/911_vdt.h index 7c450202aa6..2bdcb3f1d2c 100644 --- a/src/mess/video/911_vdt.h +++ b/src/mess/video/911_vdt.h @@ -43,12 +43,12 @@ class vdt911_device : public device_t { public: vdt911_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~vdt911_device() { global_free(m_token); } + ~vdt911_device(); DECLARE_PALETTE_INIT(vdt911); // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } + struct vdt_t *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides @@ -57,7 +57,7 @@ protected: virtual machine_config_constructor device_mconfig_additions() const; private: // internal state - void *m_token; + struct vdt_t *m_token; required_device m_gfxdecode; required_device m_palette; }; diff --git a/src/mess/video/apollo.c b/src/mess/video/apollo.c index 15c4013b208..81e9dbda373 100644 --- a/src/mess/video/apollo.c +++ b/src/mess/video/apollo.c @@ -2139,6 +2139,11 @@ apollo_graphics_15i::apollo_graphics_15i(const machine_config &mconfig, m_token = new apollo_graphics; } +apollo_graphics_15i::~apollo_graphics_15i() +{ + global_free(m_token); +} + //------------------------------------------------- // device_config_complete - perform any // operations now that the configuration is diff --git a/src/mess/video/x68k.c b/src/mess/video/x68k.c index d7850fe262b..2ccd1243f84 100644 --- a/src/mess/video/x68k.c +++ b/src/mess/video/x68k.c @@ -1094,11 +1094,11 @@ VIDEO_START_MEMBER(x68k_state,x68000) break; /* create the char set (gfx will then be updated dynamically from RAM) */ - m_gfxdecode->set_gfx(gfx_index, auto_alloc(machine(), gfx_element(m_palette, x68k_pcg_8, memregion("user1")->base(), 32, 0))); + m_gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(m_palette, x68k_pcg_8, memregion("user1")->base(), 32, 0))); gfx_index++; - m_gfxdecode->set_gfx(gfx_index, auto_alloc(machine(), gfx_element(m_palette, x68k_pcg_16, memregion("user1")->base(), 32, 0))); + m_gfxdecode->set_gfx(gfx_index, global_alloc(gfx_element(m_palette, x68k_pcg_16, memregion("user1")->base(), 32, 0))); m_gfxdecode->gfx(gfx_index)->set_colors(32); /* Tilemaps */ diff --git a/src/osd/osdcomm.h b/src/osd/osdcomm.h index a23dc4658af..f87c863b16b 100644 --- a/src/osd/osdcomm.h +++ b/src/osd/osdcomm.h @@ -111,6 +111,13 @@ __extension__ typedef signed long long INT64; #endif +/* pointer-sized values */ +#ifdef PTR64 +typedef UINT64 FPTR; +#else +typedef UINT32 FPTR; +#endif + /*************************************************************************** diff --git a/src/osd/sdl/debugqtdasmwindow.c b/src/osd/sdl/debugqtdasmwindow.c index 4fe46291f20..ca9a5045d69 100644 --- a/src/osd/sdl/debugqtdasmwindow.c +++ b/src/osd/sdl/debugqtdasmwindow.c @@ -46,8 +46,8 @@ DasmWindow::DasmWindow(running_machine* machine, QWidget* parent) : // Populate the combo box & set the proper cpu populateComboBox(); - //const debug_view_source *source = mem->views[0]->view->source_list().match_device(curcpu); - //gtk_combo_box_set_active(zone_w, mem->views[0]->view->source_list().index(*source)); + //const debug_view_source *source = mem->views[0]->view->source_for_device(curcpu); + //gtk_combo_box_set_active(zone_w, mem->views[0]->view->source_list().indexof(*source)); //mem->views[0]->view->set_source(*source); @@ -111,7 +111,7 @@ DasmWindow::~DasmWindow() void DasmWindow::cpuChanged(int index) { - m_dasmView->view()->set_source(*m_dasmView->view()->source_list().by_index(index)); + m_dasmView->view()->set_source(*m_dasmView->view()->source_list().find(index)); m_dasmView->viewport()->update(); } @@ -204,7 +204,7 @@ void DasmWindow::populateComboBox() return; m_cpuComboBox->clear(); - for (const debug_view_source* source = m_dasmView->view()->source_list().head(); + for (const debug_view_source* source = m_dasmView->view()->first_source(); source != NULL; source = source->next()) { diff --git a/src/osd/sdl/debugqtmainwindow.c b/src/osd/sdl/debugqtmainwindow.c index 62999d8f74f..e64a6f318a0 100644 --- a/src/osd/sdl/debugqtmainwindow.c +++ b/src/osd/sdl/debugqtmainwindow.c @@ -123,8 +123,8 @@ MainWindow::~MainWindow() void MainWindow::setProcessor(device_t* processor) { // Cpu swap - m_procFrame->view()->view()->set_source(*m_procFrame->view()->view()->source_list().match_device(processor)); - m_dasmFrame->view()->view()->set_source(*m_dasmFrame->view()->view()->source_list().match_device(processor)); + m_procFrame->view()->view()->set_source(*m_procFrame->view()->view()->source_for_device(processor)); + m_dasmFrame->view()->view()->set_source(*m_dasmFrame->view()->view()->source_for_device(processor)); // Scrollbar refresh - seems I should be able to do in the DebuggerView m_dasmFrame->view()->verticalScrollBar()->setValue(m_dasmFrame->view()->view()->visible_position().y); diff --git a/src/osd/sdl/debugqtmemorywindow.c b/src/osd/sdl/debugqtmemorywindow.c index 5612bb55328..979f324801d 100644 --- a/src/osd/sdl/debugqtmemorywindow.c +++ b/src/osd/sdl/debugqtmemorywindow.c @@ -136,7 +136,7 @@ MemoryWindow::~MemoryWindow() void MemoryWindow::memoryRegionChanged(int index) { - m_memTable->view()->set_source(*m_memTable->view()->source_list().by_index(index)); + m_memTable->view()->set_source(*m_memTable->view()->source_list().find(index)); m_memTable->viewport()->update(); // Update the chunk size radio buttons to the memory region's default @@ -233,7 +233,7 @@ void MemoryWindow::populateComboBox() return; m_memoryComboBox->clear(); - for (const debug_view_source* source = m_memTable->view()->source_list().head(); + for (const debug_view_source* source = m_memTable->view()->first_source(); source != NULL; source = source->next()) { @@ -245,8 +245,8 @@ void MemoryWindow::populateComboBox() void MemoryWindow::setToCurrentCpu() { device_t* curCpu = debug_cpu_get_visible_cpu(*m_machine); - const debug_view_source *source = m_memTable->view()->source_list().match_device(curCpu); - const int listIndex = m_memTable->view()->source_list().index(*source); + const debug_view_source *source = m_memTable->view()->source_for_device(curCpu); + const int listIndex = m_memTable->view()->source_list().indexof(*source); m_memoryComboBox->setCurrentIndex(listIndex); } diff --git a/src/osd/sdl/input.c b/src/osd/sdl/input.c index 2f1bed309c0..b93cceb3cfd 100644 --- a/src/osd/sdl/input.c +++ b/src/osd/sdl/input.c @@ -138,7 +138,7 @@ struct device_info // device information device_info ** head; device_info * next; - char * name; + astring name; // MAME information input_device * device; @@ -759,7 +759,7 @@ static void sdlinput_register_joysticks(running_machine &machine) devinfo->joystick.device = joy; - mame_printf_verbose("Joystick: %s\n", devinfo->name); + mame_printf_verbose("Joystick: %s\n", devinfo->name.cstr()); mame_printf_verbose("Joystick: ... %d axes, %d buttons %d hats %d balls\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy), SDL_JoystickNumBalls(joy)); mame_printf_verbose("Joystick: ... Physical id %d mapped to logical id %d\n", physical_stick, stick); @@ -775,7 +775,7 @@ static void sdlinput_register_joysticks(running_machine &machine) else itemid = ITEM_ID_OTHER_AXIS_ABSOLUTE; - sprintf(tempname, "A%d %s", axis, devinfo->name); + sprintf(tempname, "A%d %s", axis, devinfo->name.cstr()); devinfo->device->add_item(tempname, itemid, generic_axis_get_state, &devinfo->joystick.axes[axis]); } @@ -826,9 +826,9 @@ static void sdlinput_register_joysticks(running_machine &machine) else itemid = ITEM_ID_OTHER_AXIS_RELATIVE; - sprintf(tempname, "R%d %s", ball * 2, devinfo->name); + sprintf(tempname, "R%d %s", ball * 2, devinfo->name.cstr()); devinfo->device->add_item(tempname, (input_item_id) itemid, generic_axis_get_state, &devinfo->joystick.balls[ball * 2]); - sprintf(tempname, "R%d %s", ball * 2 + 1, devinfo->name); + sprintf(tempname, "R%d %s", ball * 2 + 1, devinfo->name.cstr()); devinfo->device->add_item(tempname, (input_item_id) (itemid + 1), generic_axis_get_state, &devinfo->joystick.balls[ball * 2 + 1]); } } @@ -886,9 +886,9 @@ static void sdlinput_register_mice(running_machine &machine) continue; // add the axes - sprintf(defname, "X %s", devinfo->name); + sprintf(defname, "X %s", devinfo->name.cstr()); devinfo->device->add_item(defname, ITEM_ID_XAXIS, generic_axis_get_state, &devinfo->mouse.lX); - sprintf(defname, "Y %s", devinfo->name); + sprintf(defname, "Y %s", devinfo->name.cstr()); devinfo->device->add_item(defname, ITEM_ID_YAXIS, generic_axis_get_state, &devinfo->mouse.lY); for (button = 0; button < 4; button++) @@ -903,7 +903,7 @@ static void sdlinput_register_mice(running_machine &machine) if (0 && mouse_enabled) SDL_SetRelativeMouseMode(index, SDL_TRUE); - mame_printf_verbose("Mouse: Registered %s\n", devinfo->name); + mame_printf_verbose("Mouse: Registered %s\n", devinfo->name.cstr()); } mame_printf_verbose("Mouse: End initialization\n"); } @@ -920,7 +920,7 @@ static void sdlinput_register_mice(running_machine &machine) // SDL 1.2 has only 1 mouse - 1.3+ will also change that, so revisit this then devinfo = generic_device_alloc(&mouse_list, "System mouse"); - devinfo->device = machine.input().device_class(DEVICE_CLASS_MOUSE).add_device(devinfo->name, devinfo); + devinfo->device = machine.input().device_class(DEVICE_CLASS_MOUSE).add_device(devinfo->name.cstr(), devinfo); mouse_enabled = machine.options().mouse(); @@ -936,7 +936,7 @@ static void sdlinput_register_mice(running_machine &machine) devinfo->device->add_item(defname, itemid, generic_button_get_state, &devinfo->mouse.buttons[button]); } - mame_printf_verbose("Mouse: Registered %s\n", devinfo->name); + mame_printf_verbose("Mouse: Registered %s\n", devinfo->name.cstr()); mame_printf_verbose("Mouse: End initialization\n"); } #endif @@ -1143,9 +1143,9 @@ static void sdlinput_register_lightguns(running_machine &machine) } - sprintf(defname, "X %s", devinfo->name); + sprintf(defname, "X %s", devinfo->name.cstr()); devinfo->device->add_item(defname, ITEM_ID_XAXIS, generic_axis_get_state, &devinfo->lightgun.lX); - sprintf(defname, "Y %s", devinfo->name); + sprintf(defname, "Y %s", devinfo->name.cstr()); devinfo->device->add_item(defname, ITEM_ID_YAXIS, generic_axis_get_state, &devinfo->lightgun.lY); @@ -1342,7 +1342,7 @@ static void sdlinput_register_keyboards(running_machine &machine) devinfo->device->add_item(defname, itemid, generic_button_get_state, &devinfo->keyboard.state[OSD_SDL_INDEX(key_trans_table[keynum].sdl_key)]); } - mame_printf_verbose("Keyboard: Registered %s\n", devinfo->name); + mame_printf_verbose("Keyboard: Registered %s\n", devinfo->name.cstr()); } mame_printf_verbose("Keyboard: End initialization\n"); } @@ -1363,7 +1363,7 @@ static void sdlinput_register_keyboards(running_machine &machine) // SDL 1.2 only has 1 keyboard (1.3+ will have multiple, this must be revisited then) // add it now devinfo = generic_device_alloc(&keyboard_list, "System keyboard"); - devinfo->device = machine.input().device_class(DEVICE_CLASS_KEYBOARD).add_device(devinfo->name, devinfo); + devinfo->device = machine.input().device_class(DEVICE_CLASS_KEYBOARD).add_device(devinfo->name.cstr(), devinfo); // populate it for (keynum = 0; sdl_key_trans_table[keynum].mame_key != ITEM_ID_INVALID; keynum++) @@ -1380,7 +1380,7 @@ static void sdlinput_register_keyboards(running_machine &machine) devinfo->device->add_item(defname, itemid, generic_button_get_state, &devinfo->keyboard.state[OSD_SDL_INDEX(key_trans_table[keynum].sdl_key)]); } - mame_printf_verbose("Keyboard: Registered %s\n", devinfo->name); + mame_printf_verbose("Keyboard: Registered %s\n", devinfo->name.cstr()); mame_printf_verbose("Keyboard: End initialization\n"); } #endif @@ -1761,7 +1761,7 @@ void sdlinput_poll(running_machine &machine) case SDL_KEYDOWN: #ifdef SDL2_MULTIAPI devinfo = generic_device_find_index( keyboard_list, keyboard_map.logical[event.key.which]); - //printf("Key down %d %d %s => %d %s (scrlock keycode is %d)\n", event.key.which, event.key.keysym.scancode, devinfo->name, OSD_SDL_INDEX_KEYSYM(&event.key.keysym), sdl_key_trans_table[event.key.keysym.scancode].mame_key_name, KEYCODE_SCRLOCK); + //printf("Key down %d %d %s => %d %s (scrlock keycode is %d)\n", event.key.which, event.key.keysym.scancode, devinfo->name.cstr(), OSD_SDL_INDEX_KEYSYM(&event.key.keysym), sdl_key_trans_table[event.key.keysym.scancode].mame_key_name, KEYCODE_SCRLOCK); #else devinfo = generic_device_find_index( keyboard_list, keyboard_map.logical[0]); #endif @@ -1857,7 +1857,7 @@ void sdlinput_poll(running_machine &machine) devinfo = generic_device_find_index(mouse_list, mouse_map.logical[0]); #endif devinfo->mouse.buttons[event.button.button-1] = 0x80; - //printf("But down %d %d %d %d %s\n", event.button.which, event.button.button, event.button.x, event.button.y, devinfo->name); + //printf("But down %d %d %d %d %s\n", event.button.which, event.button.button, event.button.x, event.button.y, devinfo->name.cstr()); if (event.button.button == 1) { // FIXME Move static declaration @@ -1915,7 +1915,7 @@ void sdlinput_poll(running_machine &machine) #endif #if (SDLMAME_SDL2) // FIXME: may apply to 1.2 as well ... - //printf("Motion %d %d %d %s\n", event.motion.which, event.motion.x, event.motion.y, devinfo->name); + //printf("Motion %d %d %d %s\n", event.motion.which, event.motion.x, event.motion.y, devinfo->name.cstr()); devinfo->mouse.lX += event.motion.xrel * INPUT_RELATIVE_PER_PIXEL; devinfo->mouse.lY += event.motion.yrel * INPUT_RELATIVE_PER_PIXEL; #else @@ -2238,20 +2238,13 @@ static device_info *generic_device_alloc(device_info **devlist_head_ptr, const c devinfo->head = devlist_head_ptr; // allocate a UTF8 copy of the name - devinfo->name = (char *) global_alloc_array(char, strlen(name)+1); - if (devinfo->name == NULL) - goto error; - strcpy(devinfo->name, (char *)name); + devinfo->name.cpy(name); // append us to the list for (curdev_ptr = devinfo->head; *curdev_ptr != NULL; curdev_ptr = &(*curdev_ptr)->next) ; *curdev_ptr = devinfo; return devinfo; - -error: - global_free(devinfo); - return NULL; } @@ -2268,13 +2261,6 @@ static void generic_device_free(device_info *devinfo) if (*curdev_ptr == devinfo) *curdev_ptr = devinfo->next; - // free the copy of the name if present - if (devinfo->name != NULL) - { - global_free((void *)devinfo->name); - } - devinfo->name = NULL; - // and now free the info global_free(devinfo); } diff --git a/src/osd/windows/debugwin.c b/src/osd/windows/debugwin.c index 4c47b15fe01..91158575199 100644 --- a/src/osd/windows/debugwin.c +++ b/src/osd/windows/debugwin.c @@ -1755,7 +1755,7 @@ static void memory_create_window(running_machine &machine) // populate the combobox int maxlength = 0; - for (const debug_view_source *source = info->view[0].view->source_list().head(); source != NULL; source = source->next()) + for (const debug_view_source *source = info->view[0].view->first_source(); source != NULL; source = source->next()) { int length = strlen(source->name()); if (length > maxlength) @@ -1764,8 +1764,8 @@ static void memory_create_window(running_machine &machine) SendMessage(info->otherwnd[0], CB_ADDSTRING, 0, (LPARAM)t_name); osd_free(t_name); } - const debug_view_source *source = info->view[0].view->source_list().match_device(curcpu); - SendMessage(info->otherwnd[0], CB_SETCURSEL, info->view[0].view->source_list().index(*source), 0); + const debug_view_source *source = info->view[0].view->source_for_device(curcpu); + SendMessage(info->otherwnd[0], CB_SETCURSEL, info->view[0].view->source_list().indexof(*source), 0); SendMessage(info->otherwnd[0], CB_SETDROPPEDWIDTH, (maxlength + 2) * debug_font_width + vscroll_width, 0); info->view[0].view->set_source(*source); @@ -1889,7 +1889,7 @@ static int memory_handle_command(debugwin_info *info, WPARAM wparam, LPARAM lpar int sel = SendMessage((HWND)lparam, CB_GETCURSEL, 0, 0); if (sel != CB_ERR) { - memview->set_source(*memview->source_list().by_index(sel)); + memview->set_source(*memview->source_list().find(sel)); memory_update_caption(info->machine(), info->wnd); // reset the focus @@ -2066,7 +2066,7 @@ static void disasm_create_window(running_machine &machine) // populate the combobox int maxlength = 0; - for (const debug_view_source *source = info->view[0].view->source_list().head(); source != NULL; source = source->next()) + for (const debug_view_source *source = info->view[0].view->first_source(); source != NULL; source = source->next()) { int length = strlen(source->name()); if (length > maxlength) @@ -2075,8 +2075,8 @@ static void disasm_create_window(running_machine &machine) SendMessage(info->otherwnd[0], CB_ADDSTRING, 0, (LPARAM)t_name); osd_free(t_name); } - const debug_view_source *source = info->view[0].view->source_list().match_device(curcpu); - SendMessage(info->otherwnd[0], CB_SETCURSEL, info->view[0].view->source_list().index(*source), 0); + const debug_view_source *source = info->view[0].view->source_for_device(curcpu); + SendMessage(info->otherwnd[0], CB_SETCURSEL, info->view[0].view->source_list().indexof(*source), 0); SendMessage(info->otherwnd[0], CB_SETDROPPEDWIDTH, (maxlength + 2) * debug_font_width + vscroll_width, 0); info->view[0].view->set_source(*source); @@ -2198,7 +2198,7 @@ static int disasm_handle_command(debugwin_info *info, WPARAM wparam, LPARAM lpar int sel = SendMessage((HWND)lparam, CB_GETCURSEL, 0, 0); if (sel != CB_ERR) { - dasmview->set_source(*dasmview->source_list().by_index(sel)); + dasmview->set_source(*dasmview->source_list().find(sel)); disasm_update_caption(info->machine(), info->wnd); // reset the focus @@ -2468,7 +2468,7 @@ void console_create_window(running_machine &machine) // loop over all register views and get the maximum size main_console_regwidth = 0; - for (const debug_view_source *source = info->view[1].view->source_list().head(); source != NULL; source = source->next()) + for (const debug_view_source *source = info->view[1].view->first_source(); source != NULL; source = source->next()) { UINT32 regchars; @@ -2486,7 +2486,7 @@ void console_create_window(running_machine &machine) // loop over all CPUs and compute the width range based on dasm width info->minwidth = 0; info->maxwidth = 0; - for (const debug_view_source *source = info->view[0].view->source_list().head(); source != NULL; source = source->next()) + for (const debug_view_source *source = info->view[0].view->first_source(); source != NULL; source = source->next()) { UINT32 minwidth, maxwidth, dischars; @@ -2623,8 +2623,8 @@ static void console_process_string(debugwin_info *info, const char *string) static void console_set_cpu(device_t *device) { // first set all the views to the new cpu number - main_console->view[0].view->set_source(*main_console->view[0].view->source_list().match_device(device)); - main_console->view[1].view->set_source(*main_console->view[1].view->source_list().match_device(device)); + main_console->view[0].view->set_source(*main_console->view[0].view->source_for_device(device)); + main_console->view[1].view->set_source(*main_console->view[1].view->source_for_device(device)); // then update the caption char curtitle[256]; diff --git a/src/osd/windows/drawdd.c b/src/osd/windows/drawdd.c index 991d7d45806..06fdd314b9a 100644 --- a/src/osd/windows/drawdd.c +++ b/src/osd/windows/drawdd.c @@ -61,7 +61,7 @@ struct dd_info DDCAPS ddcaps; // capabilities of the device DDCAPS helcaps; // capabilities of the hardware - void * membuffer; // memory buffer for complex rendering + UINT8 * membuffer; // memory buffer for complex rendering UINT32 membuffersize; // current size of the memory buffer }; @@ -537,7 +537,7 @@ static int ddraw_create_surfaces(win_window_info *window) if (dd->membuffersize < dd->blitwidth * dd->blitheight * 4) { dd->membuffersize = dd->blitwidth * dd->blitheight * 4; - global_free(dd->membuffer); + global_free_array(dd->membuffer); dd->membuffer = global_alloc_array(UINT8, dd->membuffersize); } if (dd->membuffer == NULL) @@ -640,7 +640,7 @@ static void ddraw_delete_surfaces(win_window_info *window) dd->clipper = NULL; // free the memory buffer - global_free(dd->membuffer); + global_free_array(dd->membuffer); dd->membuffer = NULL; dd->membuffersize = 0; diff --git a/src/osd/windows/input.c b/src/osd/windows/input.c index 6e68cc60a66..9d79ef20429 100644 --- a/src/osd/windows/input.c +++ b/src/osd/windows/input.c @@ -693,7 +693,7 @@ BOOL wininput_handle_raw(HANDLE device) // free the temporary buffer and return the result if (data != small_buffer) - global_free(data); + global_free_array(data); return result; } @@ -1295,7 +1295,7 @@ static char *dinput_device_item_name(device_info *devinfo, int offset, const TCH // convert to UTF8, free the temporary string, and return utf8 = utf8_from_tstring(combined); - global_free(combined); + global_free_array(combined); return utf8; } @@ -1728,12 +1728,12 @@ static void rawinput_init(running_machine &machine) if (!(*register_rawinput_devices)(reglist, regcount, sizeof(reglist[0]))) goto error; - global_free(devlist); + global_free_array(devlist); return; error: if (devlist != NULL) - global_free(devlist); + global_free_array(devlist); } @@ -1777,7 +1777,7 @@ static device_info *rawinput_device_create(running_machine &machine, device_info // improve the name and then allocate a device tname = rawinput_device_improve_name(tname); devinfo = generic_device_alloc(machine, devlist_head_ptr, tname); - global_free(tname); + global_free_array(tname); // copy the handle devinfo->rawinput.device = device->hDevice; @@ -1785,7 +1785,7 @@ static device_info *rawinput_device_create(running_machine &machine, device_info error: if (tname != NULL) - global_free(tname); + global_free_array(tname); if (devinfo != NULL) rawinput_device_release(devinfo); return NULL; @@ -1918,7 +1918,7 @@ static TCHAR *rawinput_device_improve_name(TCHAR *name) // free memory and close the key if (endparentid != NULL) - global_free(endparentid); + global_free_array(endparentid); RegCloseKey(endkey); } } @@ -1934,7 +1934,7 @@ static TCHAR *rawinput_device_improve_name(TCHAR *name) convert: // replace the name with the nicer one - global_free(name); + global_free_array(name); // remove anything prior to the final semicolon chsrc = _tcsrchr(regstring, ';'); @@ -1947,9 +1947,9 @@ convert: exit: if (regstring != NULL) - global_free(regstring); + global_free_array(regstring); if (regpath != NULL) - global_free(regpath); + global_free_array(regpath); if (regkey != NULL) RegCloseKey(regkey); @@ -2172,7 +2172,7 @@ static TCHAR *reg_query_string(HKEY key, const TCHAR *path) return buffer; // otherwise return a NULL buffer - global_free(buffer); + global_free_array(buffer); return NULL; } diff --git a/src/osd/windows/output.c b/src/osd/windows/output.c index b930fa6ce1d..689c02cc6e4 100644 --- a/src/osd/windows/output.c +++ b/src/osd/windows/output.c @@ -269,7 +269,6 @@ static LRESULT unregister_client(HWND hwnd, LPARAM id) static LRESULT send_id_string(running_machine &machine, HWND hwnd, LPARAM id) { - copydata_id_string *temp; COPYDATASTRUCT copydata; const char *name; int datalen; @@ -285,8 +284,9 @@ static LRESULT send_id_string(running_machine &machine, HWND hwnd, LPARAM id) name = ""; // allocate memory for the message - datalen = sizeof(*temp) + strlen(name); - temp = (copydata_id_string *)global_alloc_array(UINT8, datalen); + datalen = sizeof(copydata_id_string) + strlen(name) + 1; + dynamic_buffer buffer(datalen); + copydata_id_string *temp = (copydata_id_string *)&buffer[0]; temp->id = id; strcpy(temp->string, name); @@ -296,8 +296,6 @@ static LRESULT send_id_string(running_machine &machine, HWND hwnd, LPARAM id) copydata.lpData = temp; SendMessage(hwnd, WM_COPYDATA, (WPARAM)output_hwnd, (LPARAM)©data); - // free the data - global_free(temp); return 0; } diff --git a/src/osd/windows/winmain.c b/src/osd/windows/winmain.c index c40d9d3672c..3f3a7256101 100644 --- a/src/osd/windows/winmain.c +++ b/src/osd/windows/winmain.c @@ -198,7 +198,7 @@ private: UINT8 m_stack_depth; UINT8 m_entry_stride; UINT32 m_max_seconds; - FPTR * m_buffer; + dynamic_array m_buffer; FPTR * m_buffer_ptr; FPTR * m_buffer_end; }; @@ -1648,7 +1648,7 @@ sampling_profiler::sampling_profiler(UINT32 max_seconds, UINT8 stack_depth = 0) m_stack_depth(stack_depth), m_entry_stride(stack_depth + 2), m_max_seconds(max_seconds), - m_buffer(global_alloc(FPTR[max_seconds * 1000 * m_entry_stride])), + m_buffer(max_seconds * 1000 * m_entry_stride), m_buffer_ptr(m_buffer), m_buffer_end(m_buffer + max_seconds * 1000 * m_entry_stride) { @@ -1661,7 +1661,6 @@ sampling_profiler::sampling_profiler(UINT32 max_seconds, UINT8 stack_depth = 0) sampling_profiler::~sampling_profiler() { - global_free(m_buffer); } diff --git a/src/tools/regrep.c b/src/tools/regrep.c index 9f7c6156d60..114d5fa467b 100644 --- a/src/tools/regrep.c +++ b/src/tools/regrep.c @@ -62,9 +62,7 @@ struct summary_file char source[100]; UINT8 status[MAX_COMPARES]; UINT8 matchbitmap[MAX_COMPARES]; - char * text[MAX_COMPARES]; - UINT32 textsize[MAX_COMPARES]; - UINT32 textalloc[MAX_COMPARES]; + astring text[MAX_COMPARES]; }; @@ -403,21 +401,8 @@ static int read_summary_log(const char *filename, int index) if (!foundchars) continue; - /* see if we have enough room */ - if (curfile->textsize[index] + (curptr - linestart) + 1 >= curfile->textalloc[index]) - { - curfile->textalloc[index] = curfile->textsize[index] + (curptr - linestart) + 256; - curfile->text[index] = (char *)realloc(curfile->text[index], curfile->textalloc[index]); - if (curfile->text[index] == NULL) - { - fprintf(stderr, "Unable to allocate memory for text\n"); - goto error; - } - } - /* append our text */ - strcpy(curfile->text[index] + curfile->textsize[index], linestart); - curfile->textsize[index] += curptr - linestart; + curfile->text[index].cat(linestart); } } @@ -474,11 +459,7 @@ static summary_file *parse_driver_tag(char *linestart, int index) /* clear out any old status for this file */ curfile->status[index] = STATUS_NOT_PRESENT; - if (curfile->text[index] != NULL) - free(curfile->text[index]); - curfile->text[index] = NULL; - curfile->textsize[index] = 0; - curfile->textalloc[index] = 0; + curfile->text[index].reset(); /* strip leading/trailing spaces from the status */ colon = trim_string(colon + 1); @@ -1016,11 +997,11 @@ static void create_linked_file(astring &dirname, const summary_file *curfile, co if (imageindex != -1) core_fprintf(linkfile, " [%d]", imageindex); core_fprintf(linkfile, "\t

\n"); - if (curfile->text[listnum] != NULL) + if (curfile->text[listnum].len() != 0) { core_fprintf(linkfile, "\t

\n"); core_fprintf(linkfile, "\tErrors:\n"); - core_fprintf(linkfile, "\t

%s
\n", curfile->text[listnum]); + core_fprintf(linkfile, "\t
%s
\n", curfile->text[listnum].cstr()); core_fprintf(linkfile, "\t

\n"); } }