diff options
| author | 2014-03-29 12:36:11 +0000 | |
|---|---|---|
| committer | 2014-03-29 12:36:11 +0000 | |
| commit | 06ab983049ea4f2bfd3192a3223199b7d7f8e550 (patch) | |
| tree | 83efb0f77494d3579c0275716be7f2e886f2f50b /src | |
| parent | d6a32473f465f9f009e0bd7b7f76ce885787c3f8 (diff) | |
converted some more global_alloc_array() usage to dynamic_array/dynamic_buffer (nw)
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/formats/apridisk.c | 8 | ||||
| -rw-r--r-- | src/lib/formats/ipf_dsk.c | 1 | ||||
| -rw-r--r-- | src/mame/drivers/astrafr.c | 3 | ||||
| -rw-r--r-- | src/mess/drivers/binbug.c | 56 | ||||
| -rw-r--r-- | src/mess/drivers/cd2650.c | 68 | ||||
| -rw-r--r-- | src/mess/drivers/d6800.c | 44 | ||||
| -rw-r--r-- | src/mess/drivers/homelab.c | 17 | ||||
| -rw-r--r-- | src/mess/drivers/instruct.c | 104 | ||||
| -rw-r--r-- | src/mess/drivers/lynx.c | 7 | ||||
| -rw-r--r-- | src/mess/drivers/phunsy.c | 40 | ||||
| -rw-r--r-- | src/mess/drivers/pipbug.c | 62 | ||||
| -rw-r--r-- | src/mess/drivers/ravens.c | 62 | ||||
| -rw-r--r-- | src/mess/drivers/timex.c | 13 | ||||
| -rw-r--r-- | src/mess/drivers/vc4000.c | 183 | ||||
| -rw-r--r-- | src/mess/machine/amstrad.c | 8 | ||||
| -rw-r--r-- | src/mess/machine/cbm_snqk.c | 9 | ||||
| -rw-r--r-- | src/mess/machine/lviv.c | 12 | ||||
| -rw-r--r-- | src/mess/machine/spec_snqk.c | 20 | ||||
| -rw-r--r-- | src/mess/machine/ti85.c | 6 | ||||
| -rw-r--r-- | src/mess/machine/x68k_hdc.c | 5 |
20 files changed, 292 insertions, 436 deletions
diff --git a/src/lib/formats/apridisk.c b/src/lib/formats/apridisk.c index 985177cc916..12f3d366011 100644 --- a/src/lib/formats/apridisk.c +++ b/src/lib/formats/apridisk.c @@ -6,7 +6,7 @@ #include "apridisk.h" #include "imageutl.h" -#include "corealloc.h" +#include "coretmpl.h" /*************************************************************************** CONSTANTS @@ -177,7 +177,7 @@ FLOPPY_CONSTRUCT( apridisk_construct ) } else if (compression == APR_COMPRESSED) { - UINT8 *buffer = (UINT8 *)global_alloc_array(UINT8, data_size); + dynamic_buffer buffer(data_size); UINT16 length; UINT8 value; @@ -186,12 +186,10 @@ FLOPPY_CONSTRUCT( apridisk_construct ) length = pick_integer_le(buffer, 0, 2); value = pick_integer_le(buffer, 2, 1); - global_free_array(buffer); - /* not sure if this is possible */ if (length != 512) { printf("Compression unsupported"); - exit(-1); + exit(-1); // TODO: NO! } memset(&tag->sectors[cur_sector].data, value, length); diff --git a/src/lib/formats/ipf_dsk.c b/src/lib/formats/ipf_dsk.c index 52e196911bd..e98c8e046c1 100644 --- a/src/lib/formats/ipf_dsk.c +++ b/src/lib/formats/ipf_dsk.c @@ -86,6 +86,7 @@ bool ipf_format::parse(UINT8 *data, UINT32 size, floppy_image *image) if(res) res = generate_tracks(image); global_free_array(tinfos); + tinfos = NULL; return res; } diff --git a/src/mame/drivers/astrafr.c b/src/mame/drivers/astrafr.c index f735cf17998..b6d6f532a76 100644 --- a/src/mame/drivers/astrafr.c +++ b/src/mame/drivers/astrafr.c @@ -2090,7 +2090,7 @@ ROM_END void astra_addresslines( UINT16* src, size_t srcsize, int small ) { - UINT16 *dst = global_alloc_array(UINT16, srcsize/2); + dynamic_array<UINT16> dst(srcsize/2); int blocksize; @@ -2107,7 +2107,6 @@ void astra_addresslines( UINT16* src, size_t srcsize, int small ) } memcpy(src,dst, srcsize); - global_free_array(dst); } diff --git a/src/mess/drivers/binbug.c b/src/mess/drivers/binbug.c index 00878720841..bf76fa8ecec 100644 --- a/src/mess/drivers/binbug.c +++ b/src/mess/drivers/binbug.c @@ -229,7 +229,7 @@ QUICKLOAD_LOAD_MEMBER( binbug_state, binbug ) int quick_addr = 0x440; int exec_addr; int quick_length; - UINT8 *quick_data; + dynamic_buffer quick_data; int read_; int result = IMAGE_INIT_FAIL; @@ -246,51 +246,41 @@ QUICKLOAD_LOAD_MEMBER( binbug_state, binbug ) } else { - quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) + quick_data.resize(quick_length); + read_ = image.fread( quick_data, quick_length); + if (read_ != quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); + image.message(" Cannot read the file"); + } + else if (quick_data[0] != 0xc4) + { + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); + image.message(" Invalid header"); } else { - read_ = image.fread( quick_data, quick_length); - if (read_ != quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); - image.message(" Cannot read the file"); - } - else if (quick_data[0] != 0xc4) + exec_addr = quick_data[1] * 256 + quick_data[2]; + + if (exec_addr >= quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); - image.message(" Invalid header"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); + image.message(" Exec address beyond end of file"); } else { - exec_addr = quick_data[1] * 256 + quick_data[2]; - - if (exec_addr >= quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); - image.message(" Exec address beyond end of file"); - } - else - { - for (i = quick_addr; i < read_; i++) - space.write_byte(i, quick_data[i]); + for (i = quick_addr; i < read_; i++) + space.write_byte(i, quick_data[i]); - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); - // Start the quickload - m_maincpu->set_state_int(S2650_PC, exec_addr); + // Start the quickload + m_maincpu->set_state_int(S2650_PC, exec_addr); - result = IMAGE_INIT_PASS; - } + result = IMAGE_INIT_PASS; } } - - global_free_array(quick_data); } return result; diff --git a/src/mess/drivers/cd2650.c b/src/mess/drivers/cd2650.c index a55e301528a..67cee1fb584 100644 --- a/src/mess/drivers/cd2650.c +++ b/src/mess/drivers/cd2650.c @@ -217,61 +217,51 @@ QUICKLOAD_LOAD_MEMBER( cd2650_state, cd2650 ) } else { - UINT8 *quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) + dynamic_buffer quick_data(quick_length); + int read_ = image.fread( quick_data, quick_length); + if (read_ != quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); + image.message(" Cannot read the file"); } else + if (quick_data[0] != 0x40) { - int read_ = image.fread( quick_data, quick_length); - if (read_ != quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); - image.message(" Cannot read the file"); - } - else - if (quick_data[0] != 0x40) + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); + image.message(" Invalid header"); + } + else + { + int exec_addr = quick_data[1] * 256 + quick_data[2]; + + if (exec_addr >= quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); - image.message(" Invalid header"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); + image.message(" Exec address beyond end of file"); } else { - int exec_addr = quick_data[1] * 256 + quick_data[2]; + // do not overwite system area (17E0-17FF) otherwise chess3 has problems + read_ = 0x17e0; + if (quick_length < 0x17e0) + read_ = quick_length; - if (exec_addr >= quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); - image.message(" Exec address beyond end of file"); - } - else - { - // do not overwite system area (17E0-17FF) otherwise chess3 has problems - read_ = 0x17e0; - if (quick_length < 0x17e0) - read_ = quick_length; + for (i = 0x1500; i < read_; i++) + m_p_videoram[i-0x1000] = quick_data[i]; - for (i = 0x1500; i < read_; i++) + if (quick_length > 0x17ff) + for (i = 0x1800; i < quick_length; i++) m_p_videoram[i-0x1000] = quick_data[i]; - if (quick_length > 0x17ff) - for (i = 0x1800; i < quick_length; i++) - m_p_videoram[i-0x1000] = quick_data[i]; + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); + // Start the quickload + m_maincpu->set_state_int(S2650_PC, exec_addr); - // Start the quickload - m_maincpu->set_state_int(S2650_PC, exec_addr); - - result = IMAGE_INIT_PASS; - } + result = IMAGE_INIT_PASS; } } - - global_free_array(quick_data); } return result; diff --git a/src/mess/drivers/d6800.c b/src/mess/drivers/d6800.c index f9da7fa98ec..aeebe49e7ad 100644 --- a/src/mess/drivers/d6800.c +++ b/src/mess/drivers/d6800.c @@ -346,44 +346,34 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 ) int quick_addr = 0x200; int exec_addr = 0xc000; int quick_length; - UINT8 *quick_data; + dynamic_buffer quick_data; int read_; int result = IMAGE_INIT_FAIL; quick_length = image.length(); - quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) + quick_data.resize(quick_length); + read_ = image.fread( quick_data, quick_length); + if (read_ != quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); + image.message(" Cannot read the file"); } else { - read_ = image.fread( quick_data, quick_length); - if (read_ != quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); - image.message(" Cannot read the file"); - } - else - { - for (i = 0; i < quick_length; i++) - if ((quick_addr + i) < 0x1000) - space.write_byte(i + quick_addr, quick_data[i]); + for (i = 0; i < quick_length; i++) + if ((quick_addr + i) < 0x1000) + space.write_byte(i + quick_addr, quick_data[i]); - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length,quick_addr,quick_addr+quick_length,exec_addr); + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length,quick_addr,quick_addr+quick_length,exec_addr); - // Start the quickload - if (strcmp(image.filetype(), "bin") == 0) - m_maincpu->set_pc(quick_addr); - else - m_maincpu->set_pc(exec_addr); - - result = IMAGE_INIT_PASS; - } + // Start the quickload + if (strcmp(image.filetype(), "bin") == 0) + m_maincpu->set_pc(quick_addr); + else + m_maincpu->set_pc(exec_addr); - global_free_array(quick_data); + result = IMAGE_INIT_PASS; } return result; diff --git a/src/mess/drivers/homelab.c b/src/mess/drivers/homelab.c index 7eaa8add922..49224d12c0a 100644 --- a/src/mess/drivers/homelab.c +++ b/src/mess/drivers/homelab.c @@ -651,26 +651,19 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab) UINT16 quick_addr; UINT16 quick_length; UINT16 quick_end; - UINT8 *quick_data; + dynamic_buffer quick_data; char pgmname[256]; UINT16 args[2]; int read_; quick_length = image.length(); - quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); - return IMAGE_INIT_FAIL; - } + quick_data.resize(quick_length); read_ = image.fread( quick_data, quick_length); if (read_ != quick_length) { image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); image.message(" Cannot read the file"); - global_free_array(quick_data); return IMAGE_INIT_FAIL; } @@ -680,7 +673,6 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab) { image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); image.message(" Invalid header"); - global_free_array(quick_data); return IMAGE_INIT_FAIL; } @@ -690,7 +682,6 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab) { image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File name too long"); image.message(" File name too long"); - global_free_array(quick_data); return IMAGE_INIT_FAIL; } @@ -704,7 +695,6 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab) { image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Unexpected EOF while getting file size"); image.message(" Unexpected EOF while getting file size"); - global_free_array(quick_data); return IMAGE_INIT_FAIL; } @@ -716,7 +706,6 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab) { image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too large"); image.message(" File too large"); - global_free_array(quick_data); return IMAGE_INIT_FAIL; } @@ -732,13 +721,11 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab) snprintf(message, ARRAY_LENGTH(message), "%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j); image.seterror(IMAGE_ERROR_INVALIDIMAGE, message); image.message("%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j); - global_free_array(quick_data); return IMAGE_INIT_FAIL; } space.write_byte(j, ch); } - global_free_array(quick_data); return IMAGE_INIT_PASS; } diff --git a/src/mess/drivers/instruct.c b/src/mess/drivers/instruct.c index c4102308d99..20ec1feae02 100644 --- a/src/mess/drivers/instruct.c +++ b/src/mess/drivers/instruct.c @@ -339,73 +339,63 @@ QUICKLOAD_LOAD_MEMBER( instruct_state, instruct ) } else { - UINT8* quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) + dynamic_buffer quick_data(quick_length); + read_ = image.fread( quick_data, quick_length); + if (read_ != quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); + image.message(" Cannot read the file"); + } + else if (quick_data[0] != 0xc5) + { + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); + image.message(" Invalid header"); } else { - read_ = image.fread( quick_data, quick_length); - if (read_ != quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); - image.message(" Cannot read the file"); - } - else if (quick_data[0] != 0xc5) + exec_addr = quick_data[1] * 256 + quick_data[2]; + + if (exec_addr >= quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); - image.message(" Invalid header"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); + image.message(" Exec address beyond end of file"); } else { - exec_addr = quick_data[1] * 256 + quick_data[2]; - - if (exec_addr >= quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); - image.message(" Exec address beyond end of file"); - } - else - { - // load to 0000-0FFE (standard ram + extra) - read_ = 0xfff; - if (quick_length < 0xfff) - read_ = quick_length; - m_p_ram[0] = 0x1f; // add jump for RST key - for (i = 1; i < read_; i++) - m_p_ram[i] = quick_data[i]; - - // load to 1780-17BF (spare ram inside 2656) - read_ = 0x17c0; - if (quick_length < 0x17c0) - read_ = quick_length; - if (quick_length > 0x1780) - for (i = 0x1780; i < read_; i++) - m_p_smiram[i-0x1780] = quick_data[i]; - - // put start address into PC so it can be debugged - m_p_smiram[0x68] = m_p_ram[1]; - m_p_smiram[0x69] = m_p_ram[2]; - - // load to 2000-7FFF (optional extra ram) - if (quick_length > 0x2000) - for (i = 0x2000; i < quick_length; i++) - m_p_extram[i-0x2000] = quick_data[i]; - - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); - - // Start the quickload - JP exec_addr - m_maincpu->set_state_int(S2650_PC, 0); - - result = IMAGE_INIT_PASS; - } + // load to 0000-0FFE (standard ram + extra) + read_ = 0xfff; + if (quick_length < 0xfff) + read_ = quick_length; + m_p_ram[0] = 0x1f; // add jump for RST key + for (i = 1; i < read_; i++) + m_p_ram[i] = quick_data[i]; + + // load to 1780-17BF (spare ram inside 2656) + read_ = 0x17c0; + if (quick_length < 0x17c0) + read_ = quick_length; + if (quick_length > 0x1780) + for (i = 0x1780; i < read_; i++) + m_p_smiram[i-0x1780] = quick_data[i]; + + // put start address into PC so it can be debugged + m_p_smiram[0x68] = m_p_ram[1]; + m_p_smiram[0x69] = m_p_ram[2]; + + // load to 2000-7FFF (optional extra ram) + if (quick_length > 0x2000) + for (i = 0x2000; i < quick_length; i++) + m_p_extram[i-0x2000] = quick_data[i]; + + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); + + // Start the quickload - JP exec_addr + m_maincpu->set_state_int(S2650_PC, 0); + + result = IMAGE_INIT_PASS; } } - - global_free_array(quick_data); } return result; diff --git a/src/mess/drivers/lynx.c b/src/mess/drivers/lynx.c index 458cc646bb4..7b13b06215b 100644 --- a/src/mess/drivers/lynx.c +++ b/src/mess/drivers/lynx.c @@ -150,7 +150,7 @@ ROM_END QUICKLOAD_LOAD_MEMBER( lynx_state, lynx ) { address_space &space = m_maincpu->space(AS_PROGRAM); - UINT8 *data = NULL; + dynamic_buffer data; UINT8 *rom = memregion("maincpu")->base(); UINT8 header[10]; // 80 08 dw Start dw Len B S 9 3 UINT16 start, length; @@ -167,19 +167,16 @@ QUICKLOAD_LOAD_MEMBER( lynx_state, lynx ) length = header[5] | (header[4]<<8); length -= 10; - data = global_alloc_array(UINT8, length); + data.resize(length); if (image.fread( data, length) != length) { - global_free_array(data); return IMAGE_INIT_FAIL; } for (i = 0; i < length; i++) space.write_byte(start + i, data[i]); - global_free_array(data); - rom[0x1fc] = start & 0xff; rom[0x1fd] = start >> 8; space.write_byte(0x1fc, start & 0xff); diff --git a/src/mess/drivers/phunsy.c b/src/mess/drivers/phunsy.c index 07fc51b4606..adc44076f69 100644 --- a/src/mess/drivers/phunsy.c +++ b/src/mess/drivers/phunsy.c @@ -286,7 +286,7 @@ QUICKLOAD_LOAD_MEMBER( phunsy_state, phunsy ) address_space &space = m_maincpu->space(AS_PROGRAM); UINT16 i; UINT16 quick_addr = 0x1800; - UINT8 *quick_data; + dynamic_buffer quick_data; int result = IMAGE_INIT_FAIL; int quick_length = image.length(); if (quick_length > 0x4000) @@ -296,35 +296,25 @@ QUICKLOAD_LOAD_MEMBER( phunsy_state, phunsy ) } else { - quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); - } - else - { - membank("bankru")->set_entry(0); // point at ram + quick_data.resize(quick_length); + membank("bankru")->set_entry(0); // point at ram - UINT16 exec_addr = quick_addr + 2; + UINT16 exec_addr = quick_addr + 2; - for (i = 0; i < quick_length; i++) - space.write_byte(i+quick_addr, quick_data[i]); + for (i = 0; i < quick_length; i++) + space.write_byte(i+quick_addr, quick_data[i]); - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); - // Start the quickload - m_maincpu->set_state_int(S2650_R0, exec_addr>>8); - m_maincpu->set_state_int(S2650_R1, 0x08); - m_maincpu->set_state_int(S2650_R2, 0xe0); - m_maincpu->set_state_int(S2650_R3, 0x83); - m_maincpu->set_state_int(S2650_PC, exec_addr); - - result = IMAGE_INIT_PASS; - } + // Start the quickload + m_maincpu->set_state_int(S2650_R0, exec_addr>>8); + m_maincpu->set_state_int(S2650_R1, 0x08); + m_maincpu->set_state_int(S2650_R2, 0xe0); + m_maincpu->set_state_int(S2650_R3, 0x83); + m_maincpu->set_state_int(S2650_PC, exec_addr); - global_free_array(quick_data); + result = IMAGE_INIT_PASS; } return result; diff --git a/src/mess/drivers/pipbug.c b/src/mess/drivers/pipbug.c index 3d745808f89..1810c93f3cc 100644 --- a/src/mess/drivers/pipbug.c +++ b/src/mess/drivers/pipbug.c @@ -96,7 +96,7 @@ QUICKLOAD_LOAD_MEMBER( pipbug_state, pipbug ) int quick_addr = 0x440; int exec_addr; int quick_length; - UINT8 *quick_data; + dynamic_buffer quick_data; int read_; int result = IMAGE_INIT_FAIL; @@ -113,51 +113,41 @@ QUICKLOAD_LOAD_MEMBER( pipbug_state, pipbug ) } else { - quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) + quick_data.resize(quick_length); + read_ = image.fread( quick_data, quick_length); + if (read_ != quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); + image.message(" Cannot read the file"); + } + else if (quick_data[0] != 0xc4) + { + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); + image.message(" Invalid header"); } else { - read_ = image.fread( quick_data, quick_length); - if (read_ != quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); - image.message(" Cannot read the file"); - } - else if (quick_data[0] != 0xc4) + exec_addr = quick_data[1] * 256 + quick_data[2]; + + if (exec_addr >= quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); - image.message(" Invalid header"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); + image.message(" Exec address beyond end of file"); } else { - exec_addr = quick_data[1] * 256 + quick_data[2]; - - if (exec_addr >= quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); - image.message(" Exec address beyond end of file"); - } - else - { - for (i = quick_addr; i < read_; i++) - space.write_byte(i, quick_data[i]); - - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); - - // Start the quickload - m_maincpu->set_state_int(S2650_PC, exec_addr); - - result = IMAGE_INIT_PASS; - } + for (i = quick_addr; i < read_; i++) + space.write_byte(i, quick_data[i]); + + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); + + // Start the quickload + m_maincpu->set_state_int(S2650_PC, exec_addr); + + result = IMAGE_INIT_PASS; } } - - global_free_array(quick_data); } return result; diff --git a/src/mess/drivers/ravens.c b/src/mess/drivers/ravens.c index 29ca1369d26..f7079dc789a 100644 --- a/src/mess/drivers/ravens.c +++ b/src/mess/drivers/ravens.c @@ -272,7 +272,7 @@ QUICKLOAD_LOAD_MEMBER( ravens_state, ravens ) int quick_addr = 0x900; int exec_addr; int quick_length; - UINT8 *quick_data; + dynamic_buffer quick_data; int read_; int result = IMAGE_INIT_FAIL; @@ -289,51 +289,41 @@ QUICKLOAD_LOAD_MEMBER( ravens_state, ravens ) } else { - quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) + quick_data.resize(quick_length); + read_ = image.fread( quick_data, quick_length); + if (read_ != quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); + image.message(" Cannot read the file"); + } + else if (quick_data[0] != 0xc6) + { + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); + image.message(" Invalid header"); } else { - read_ = image.fread( quick_data, quick_length); - if (read_ != quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); - image.message(" Cannot read the file"); - } - else if (quick_data[0] != 0xc6) + exec_addr = quick_data[2] * 256 + quick_data[3]; + + if (exec_addr >= quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); - image.message(" Invalid header"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); + image.message(" Exec address beyond end of file"); } else { - exec_addr = quick_data[2] * 256 + quick_data[3]; - - if (exec_addr >= quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); - image.message(" Exec address beyond end of file"); - } - else - { - for (i = quick_addr; i < read_; i++) - space.write_byte(i, quick_data[i]); - - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); - - // Start the quickload - m_maincpu->set_state_int(S2650_PC, exec_addr); - - result = IMAGE_INIT_PASS; - } + for (i = quick_addr; i < read_; i++) + space.write_byte(i, quick_data[i]); + + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); + + // Start the quickload + m_maincpu->set_state_int(S2650_PC, exec_addr); + + result = IMAGE_INIT_PASS; } } - - global_free_array(quick_data); } return result; diff --git a/src/mess/drivers/timex.c b/src/mess/drivers/timex.c index 5dc8c4d2005..85fd38d606b 100644 --- a/src/mess/drivers/timex.c +++ b/src/mess/drivers/timex.c @@ -621,7 +621,7 @@ MACHINE_RESET_MEMBER(spectrum_state,tc2048) DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart ) { int file_size; - UINT8 * file_data; + dynamic_buffer file_data; int chunks_in_file = 0; @@ -637,12 +637,7 @@ DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart ) return IMAGE_INIT_FAIL; } - file_data = global_alloc_array(UINT8, file_size); - if (file_data == NULL) - { - logerror ("Memory allocating error\n"); - return IMAGE_INIT_FAIL; - } + file_data.resize(file_size); image.fread(file_data, file_size); @@ -651,7 +646,6 @@ DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart ) if (chunks_in_file*0x2000+0x09 != file_size) { - global_free_array(file_data); logerror ("File corrupted\n"); return IMAGE_INIT_FAIL; } @@ -663,7 +657,6 @@ DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart ) timex_cart.data = global_alloc_array(UINT8, 0x10000); if (!timex_cart.data) { - global_free_array(file_data); logerror ("Memory allocate error\n"); return IMAGE_INIT_FAIL; } @@ -684,11 +677,9 @@ DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart ) memset (timex_cart.data+i*0x2000, 0xff, 0x2000); } } - global_free_array(file_data); break; default: logerror ("Cart type not supported\n"); - global_free_array(file_data); timex_cart.type = TIMEX_CART_NONE; return IMAGE_INIT_FAIL; } diff --git a/src/mess/drivers/vc4000.c b/src/mess/drivers/vc4000.c index 51b82085ef2..00e6a6527b5 100644 --- a/src/mess/drivers/vc4000.c +++ b/src/mess/drivers/vc4000.c @@ -558,127 +558,118 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000) int i; int exec_addr; int quick_length; - UINT8 *quick_data; + dynamic_buffer quick_data; int read_; int result = IMAGE_INIT_FAIL; quick_length = image.length(); - quick_data = global_alloc_array(UINT8, quick_length); - if (!quick_data) + quick_data.resize(quick_length); + read_ = image.fread( quick_data, quick_length); + if (read_ != quick_length) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); - image.message(" Cannot open file"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); + image.message(" Cannot read the file"); } else { - read_ = image.fread( quick_data, quick_length); - if (read_ != quick_length) + if (core_stricmp(image.filetype(), "tvc")==0) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); - image.message(" Cannot read the file"); - } - else - { - if (core_stricmp(image.filetype(), "tvc")==0) + if (quick_data[0] != 2) { - if (quick_data[0] != 2) + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); + image.message(" Invalid header"); + } + else + { + int quick_addr = quick_data[1] * 256 + quick_data[2]; + exec_addr = quick_data[3] * 256 + quick_data[4]; + + if (quick_length < 0x5) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); - image.message(" Invalid header"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short"); + image.message(" File too short"); } else + if ((quick_length + quick_addr - 5) > 0x1600) { - int quick_addr = quick_data[1] * 256 + quick_data[2]; - exec_addr = quick_data[3] * 256 + quick_data[4]; - - if (quick_length < 0x5) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short"); - image.message(" File too short"); - } - else - if ((quick_length + quick_addr - 5) > 0x1600) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long"); - image.message(" File too long"); - } - else - { - space.write_byte(0x08be, quick_data[3]); - space.write_byte(0x08bf, quick_data[4]); - - for (i = 5; i < quick_length; i++) - space.write_byte(i - 5 + quick_addr, quick_data[i]); - - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length-5,quick_addr,quick_addr+quick_length-5,exec_addr); - - // Start the quickload - m_maincpu->set_state_int(S2650_PC, exec_addr); - result = IMAGE_INIT_PASS; - } + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long"); + image.message(" File too long"); + } + else + { + space.write_byte(0x08be, quick_data[3]); + space.write_byte(0x08bf, quick_data[4]); + + for (i = 5; i < quick_length; i++) + space.write_byte(i - 5 + quick_addr, quick_data[i]); + + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length-5,quick_addr,quick_addr+quick_length-5,exec_addr); + + // Start the quickload + m_maincpu->set_state_int(S2650_PC, exec_addr); + result = IMAGE_INIT_PASS; } } + } + else + if (core_stricmp(image.filetype(), "pgm")==0) + { + if (quick_data[0] != 0) + { + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); + image.message(" Invalid header"); + } else - if (core_stricmp(image.filetype(), "pgm")==0) { - if (quick_data[0] != 0) + exec_addr = quick_data[1] * 256 + quick_data[2]; + + if (exec_addr >= quick_length) + { + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); + image.message(" Exec address beyond end of file"); + } + else + if (quick_length < 0x904) + { + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short"); + image.message(" File too short"); + } + else + if (quick_length > 0x2000) { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); - image.message(" Invalid header"); + image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long"); + image.message(" File too long"); } else { - exec_addr = quick_data[1] * 256 + quick_data[2]; - - if (exec_addr >= quick_length) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); - image.message(" Exec address beyond end of file"); - } - else - if (quick_length < 0x904) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short"); - image.message(" File too short"); - } - else - if (quick_length > 0x2000) - { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long"); - image.message(" File too long"); - } - else - { - space.write_byte(0x08be, quick_data[1]); - space.write_byte(0x08bf, quick_data[2]); - - // load to 08C0-15FF (standard ram + extra) - int read_ = 0x1600; - if (quick_length < 0x1600) - read_ = quick_length; - for (i = 0x8c0; i < read_; i++) - space.write_byte(i, quick_data[i]); - - // load to 1F50-1FAF (PVI regs) - read_ = 0x1FB0; - if (quick_length < 0x1FB0) - read_ = quick_length; - if (quick_length > 0x1FC0) - for (i = 0x1F50; i < read_; i++) - vc4000_video_w(space, i-0x1f00, quick_data[i]); - - /* display a message about the loaded quickload */ - image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); - - // Start the quickload - m_maincpu->set_state_int(S2650_PC, exec_addr); - result = IMAGE_INIT_PASS; - } + space.write_byte(0x08be, quick_data[1]); + space.write_byte(0x08bf, quick_data[2]); + + // load to 08C0-15FF (standard ram + extra) + int read_ = 0x1600; + if (quick_length < 0x1600) + read_ = quick_length; + for (i = 0x8c0; i < read_; i++) + space.write_byte(i, quick_data[i]); + + // load to 1F50-1FAF (PVI regs) + read_ = 0x1FB0; + if (quick_length < 0x1FB0) + read_ = quick_length; + if (quick_length > 0x1FC0) + for (i = 0x1F50; i < read_; i++) + vc4000_video_w(space, i-0x1f00, quick_data[i]); + + /* display a message about the loaded quickload */ + image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); + + // Start the quickload + m_maincpu->set_state_int(S2650_PC, exec_addr); + result = IMAGE_INIT_PASS; } } } - global_free_array(quick_data); } return result; } diff --git a/src/mess/machine/amstrad.c b/src/mess/machine/amstrad.c index 030866d689e..c9e19eed4a5 100644 --- a/src/mess/machine/amstrad.c +++ b/src/mess/machine/amstrad.c @@ -3149,27 +3149,23 @@ MACHINE_RESET_MEMBER(amstrad_state,aleste) /* load snapshot */ SNAPSHOT_LOAD_MEMBER( amstrad_state,amstrad) { - UINT8 *snapshot; + dynamic_buffer snapshot; /* get file size */ if (snapshot_size < 8) return IMAGE_INIT_FAIL; - snapshot = global_alloc_array(UINT8, snapshot_size); - if (!snapshot) - return IMAGE_INIT_FAIL; + snapshot.resize(snapshot_size); /* read whole file */ image.fread(snapshot, snapshot_size); if (memcmp(snapshot, "MV - SNA", 8)) { - global_free_array(snapshot); return IMAGE_INIT_FAIL; } amstrad_handle_snapshot(snapshot); - global_free_array(snapshot); return IMAGE_INIT_PASS; } diff --git a/src/mess/machine/cbm_snqk.c b/src/mess/machine/cbm_snqk.c index 816911110cd..ab93c625ca1 100644 --- a/src/mess/machine/cbm_snqk.c +++ b/src/mess/machine/cbm_snqk.c @@ -26,7 +26,7 @@ int general_cbm_loadsnap( device_image_interface &image, const char *file_type, address_space &space, offs_t offset, void (*cbm_sethiaddress)(address_space &space, UINT16 hiaddress) ) { char buffer[7]; - UINT8 *data = NULL; + dynamic_buffer data; UINT32 bytesread; UINT16 address = 0; int i; @@ -69,9 +69,7 @@ int general_cbm_loadsnap( device_image_interface &image, const char *file_type, address = 2049; snapshot_size -= 2; - data = global_alloc_array(UINT8, snapshot_size); - if (!data) - goto error; + data.resize(snapshot_size); bytesread = image.fread( data, snapshot_size); if (bytesread != snapshot_size) @@ -81,12 +79,9 @@ int general_cbm_loadsnap( device_image_interface &image, const char *file_type, space.write_byte(address + i + offset, data[i]); cbm_sethiaddress(space, address + snapshot_size); - global_free_array(data); return IMAGE_INIT_PASS; error: - if (data) - global_free_array(data); return IMAGE_INIT_FAIL; } diff --git a/src/mess/machine/lviv.c b/src/mess/machine/lviv.c index 2088f3f02cd..d62046ff422 100644 --- a/src/mess/machine/lviv.c +++ b/src/mess/machine/lviv.c @@ -321,20 +321,12 @@ int lviv_state::lviv_verify_snapshot (UINT8 * data, UINT32 size) SNAPSHOT_LOAD_MEMBER( lviv_state, lviv ) { - UINT8 *lviv_snapshot_data; - - lviv_snapshot_data = global_alloc_array(UINT8, LVIV_SNAPSHOT_SIZE); - if (!lviv_snapshot_data) - { - logerror ("Unable to load snapshot file\n"); - return IMAGE_INIT_FAIL; - } + dynamic_buffer lviv_snapshot_data(LVIV_SNAPSHOT_SIZE); image.fread( lviv_snapshot_data, LVIV_SNAPSHOT_SIZE); if(lviv_verify_snapshot(lviv_snapshot_data, snapshot_size) == IMAGE_VERIFY_FAIL) { - global_free_array(lviv_snapshot_data); return IMAGE_INIT_FAIL; } @@ -342,8 +334,6 @@ SNAPSHOT_LOAD_MEMBER( lviv_state, lviv ) dump_registers(); - global_free_array(lviv_snapshot_data); - logerror("Snapshot file loaded\n"); return IMAGE_INIT_PASS; } diff --git a/src/mess/machine/spec_snqk.c b/src/mess/machine/spec_snqk.c index c076197e0d2..d9e103a835d 100644 --- a/src/mess/machine/spec_snqk.c +++ b/src/mess/machine/spec_snqk.c @@ -112,11 +112,7 @@ static void spectrum_page_basicrom(running_machine &machine) SNAPSHOT_LOAD_MEMBER( spectrum_state,spectrum) { - UINT8 *snapshot_data = NULL; - - snapshot_data = global_alloc_array(UINT8, snapshot_size); - if (!snapshot_data) - goto error; + dynamic_buffer snapshot_data(snapshot_size); image.fread(snapshot_data, snapshot_size); @@ -233,13 +229,9 @@ SNAPSHOT_LOAD_MEMBER( spectrum_state,spectrum) spectrum_setup_z80(machine(), snapshot_data, snapshot_size); } - global_free_array(snapshot_data); - return IMAGE_INIT_PASS; error: - if (snapshot_data) - global_free_array(snapshot_data); return IMAGE_INIT_FAIL; } @@ -2453,11 +2445,7 @@ void spectrum_setup_z80(running_machine &machine, UINT8 *snapdata, UINT32 snapsi QUICKLOAD_LOAD_MEMBER( spectrum_state,spectrum) { - UINT8 *quickload_data = NULL; - - quickload_data = global_alloc_array(UINT8, quickload_size); - if (!quickload_data) - goto error; + dynamic_buffer quickload_data(quickload_size); image.fread(quickload_data, quickload_size); @@ -2480,13 +2468,9 @@ QUICKLOAD_LOAD_MEMBER( spectrum_state,spectrum) spectrum_setup_raw(machine(), quickload_data, quickload_size); } - global_free_array(quickload_data); - return IMAGE_INIT_PASS; error: - if (quickload_data) - global_free_array(quickload_data); return IMAGE_INIT_FAIL; } diff --git a/src/mess/machine/ti85.c b/src/mess/machine/ti85.c index e384863169c..45f11cc7ea1 100644 --- a/src/mess/machine/ti85.c +++ b/src/mess/machine/ti85.c @@ -679,7 +679,7 @@ void ti85_state::ti86_setup_snapshot (UINT8 * data) SNAPSHOT_LOAD_MEMBER( ti85_state, ti8x ) { int expected_snapshot_size = 0; - UINT8 *ti8x_snapshot_data; + dynamic_buffer ti8x_snapshot_data; if (!strncmp(machine().system().name, "ti85", 4)) expected_snapshot_size = TI85_SNAPSHOT_SIZE; @@ -694,8 +694,7 @@ SNAPSHOT_LOAD_MEMBER( ti85_state, ti8x ) return IMAGE_INIT_FAIL; } - if (!(ti8x_snapshot_data = global_alloc_array(UINT8, snapshot_size))) - return IMAGE_INIT_FAIL; + ti8x_snapshot_data.resize(snapshot_size); image.fread( ti8x_snapshot_data, snapshot_size); @@ -704,6 +703,5 @@ SNAPSHOT_LOAD_MEMBER( ti85_state, ti8x ) else if (!strncmp(machine().system().name, "ti86", 4)) ti86_setup_snapshot(ti8x_snapshot_data); - global_free_array(ti8x_snapshot_data); return IMAGE_INIT_PASS; } diff --git a/src/mess/machine/x68k_hdc.c b/src/mess/machine/x68k_hdc.c index 467ad1045cd..1a587492e56 100644 --- a/src/mess/machine/x68k_hdc.c +++ b/src/mess/machine/x68k_hdc.c @@ -66,7 +66,7 @@ bool x68k_hdc_image_device::call_create(int format_type, option_resolution *form WRITE16_MEMBER( x68k_hdc_image_device::hdc_w ) { unsigned int lba = 0; - char* blk; + dynamic_array<char> blk; switch(offset) { case 0x00: // data I/O @@ -265,11 +265,10 @@ WRITE16_MEMBER( x68k_hdc_image_device::hdc_w ) lba |= m_command[2] << 8; lba |= (m_command[1] & 0x1f) << 16; fseek(lba * 256,SEEK_SET); - blk = global_alloc_array(char, 256*33); + blk.resize(256*33); memset(blk,0,256*33); // formats 33 256-byte blocks fwrite(blk,256*33); - global_free_array(blk); logerror("SASI: FORMAT UNIT (LBA 0x%06x)\n",lba); break; default: |
