mirror of
https://github.com/holub/mame
synced 2025-04-22 16:31:49 +03:00
converted some global_alloc_array() usage to dynamic_array/dynamic_buffer (nw)
This commit is contained in:
parent
fc38a629a8
commit
089ba456f4
@ -462,12 +462,12 @@ static int genesis_is_SMD(unsigned char *buf, unsigned int len)
|
||||
|
||||
int base_md_cart_slot_device::load_nonlist()
|
||||
{
|
||||
unsigned char *ROM, *tmpROM;
|
||||
unsigned char *ROM;
|
||||
bool is_smd, is_md;
|
||||
UINT32 tmplen = length(), offset, len;
|
||||
|
||||
dynamic_buffer tmpROM(tmplen);
|
||||
|
||||
// STEP 1: store a (possibly headered) copy of the file and determine its type (SMD? MD? BIN?)
|
||||
tmpROM = global_alloc_array(unsigned char, tmplen);
|
||||
fread(tmpROM, tmplen);
|
||||
is_smd = genesis_is_SMD(&tmpROM[0x200], tmplen - 0x200);
|
||||
is_md = (tmpROM[0x80] == 'E') && (tmpROM[0x81] == 'A') && (tmpROM[0x82] == 'M' || tmpROM[0x82] == 'G');
|
||||
@ -516,8 +516,6 @@ int base_md_cart_slot_device::load_nonlist()
|
||||
fread(ROM, len);
|
||||
}
|
||||
|
||||
global_free_array(tmpROM);
|
||||
|
||||
// if we allocated a ROM larger that the file (e.g. due to uneven cart size), set remaining space to 0xff
|
||||
if (len > (tmplen - offset))
|
||||
memset(m_cart->get_rom_base() + (tmplen - offset)/2, 0xffff, (len - tmplen + offset)/2);
|
||||
|
@ -630,11 +630,10 @@ bool base_sns_cart_slot_device::call_load()
|
||||
if (software_entry() == NULL)
|
||||
{
|
||||
UINT32 tmplen = length();
|
||||
UINT8 *tmpROM = global_alloc_array(UINT8, tmplen);
|
||||
dynamic_buffer tmpROM(tmplen);
|
||||
fread(tmpROM, tmplen);
|
||||
offset = snes_skip_header(tmpROM, tmplen);
|
||||
fseek(offset, SEEK_SET);
|
||||
global_free_array(tmpROM);
|
||||
}
|
||||
|
||||
len = (software_entry() == NULL) ? (length() - offset) : get_software_region_length("rom");
|
||||
|
@ -425,12 +425,12 @@ void device_image_interface::run_hash(void (*partialhash)(hash_collection &, con
|
||||
hash_collection &hashes, const char *types)
|
||||
{
|
||||
UINT32 size;
|
||||
UINT8 *buf = NULL;
|
||||
dynamic_buffer buf;
|
||||
|
||||
hashes.reset();
|
||||
size = (UINT32) length();
|
||||
|
||||
buf = global_alloc_array(UINT8, size);
|
||||
buf.resize(size);
|
||||
memset(buf,0,size);
|
||||
|
||||
/* read the file */
|
||||
@ -443,7 +443,6 @@ void device_image_interface::run_hash(void (*partialhash)(hash_collection &, con
|
||||
hashes.compute(buf, size, types);
|
||||
|
||||
/* cleanup */
|
||||
global_free_array(buf);
|
||||
fseek(0, SEEK_SET);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ void dp8390_device::check_dma_complete() {
|
||||
}
|
||||
|
||||
void dp8390_device::do_tx() {
|
||||
UINT8 *buf;
|
||||
dynamic_buffer buf;
|
||||
int i;
|
||||
UINT32 high16 = (m_regs.dcr & 4)?m_regs.rsar<<16:0;
|
||||
if(m_reset) return;
|
||||
@ -82,7 +82,7 @@ void dp8390_device::do_tx() {
|
||||
return;
|
||||
}
|
||||
|
||||
buf = global_alloc_array(UINT8, m_regs.tbcr);
|
||||
buf.resize(m_regs.tbcr);
|
||||
for(i = 0; i < m_regs.tbcr; i++) buf[i] = mem_read(high16 + (m_regs.tpsr << 8) + i);
|
||||
|
||||
if(send(buf, m_regs.tbcr)) {
|
||||
@ -94,7 +94,6 @@ void dp8390_device::do_tx() {
|
||||
}
|
||||
m_regs.cr &= ~4;
|
||||
check_irq();
|
||||
global_free_array(buf);
|
||||
}
|
||||
|
||||
void dp8390_device::set_cr(UINT8 newcr) {
|
||||
|
@ -745,7 +745,7 @@ void smc92x4_device::data_transfer_read(chrn_id_hd id, int transfer_enable)
|
||||
mfm_harddisk_device *harddisk;
|
||||
|
||||
int sector_data_id;
|
||||
UINT8 *buf;
|
||||
dynamic_buffer buf;
|
||||
|
||||
sync_latches_out();
|
||||
sync_status_in();
|
||||
@ -776,7 +776,7 @@ void smc92x4_device::data_transfer_read(chrn_id_hd id, int transfer_enable)
|
||||
|
||||
sector_len = 1 << (id.N+7);
|
||||
sector_data_id = id.data_id;
|
||||
buf = global_alloc_array(UINT8, sector_len);
|
||||
buf.resize(sector_len);
|
||||
|
||||
if (m_selected_drive_type & TYPE_FLOPPY)
|
||||
{
|
||||
@ -802,7 +802,6 @@ void smc92x4_device::data_transfer_read(chrn_id_hd id, int transfer_enable)
|
||||
}
|
||||
m_out_dip(CLEAR_LINE);
|
||||
}
|
||||
global_free_array(buf);
|
||||
|
||||
/* Check CRC. We assume everything is OK, no retry required. */
|
||||
m_register_r[CHIP_STATUS] &= ~CS_RETREQ;
|
||||
@ -836,7 +835,7 @@ void smc92x4_device::data_transfer_read(chrn_id_hd id, int transfer_enable)
|
||||
void smc92x4_device::data_transfer_write(chrn_id_hd id, int deldata, int redcur, int precomp, bool write_long)
|
||||
{
|
||||
int retry, i, sector_len;
|
||||
UINT8 *buf;
|
||||
dynamic_buffer buf;
|
||||
int sector_data_id;
|
||||
mfm_harddisk_device *harddisk;
|
||||
sync_latches_out();
|
||||
@ -857,7 +856,7 @@ void smc92x4_device::data_transfer_write(chrn_id_hd id, int deldata, int redcur,
|
||||
sector_len = 1 << (id.N+7);
|
||||
sector_data_id = id.data_id;
|
||||
|
||||
buf = global_alloc_array(UINT8, sector_len);
|
||||
buf.resize(sector_len);
|
||||
|
||||
/* Copy via DMA from controller RAM. */
|
||||
set_dma_address(DMA23_16, DMA15_8, DMA7_0);
|
||||
@ -877,14 +876,13 @@ void smc92x4_device::data_transfer_write(chrn_id_hd id, int deldata, int redcur,
|
||||
if (m_selected_drive_type & TYPE_FLOPPY)
|
||||
{
|
||||
if (VERBOSE>4) LOG("smc92x4 info: write sector CHS=(%d,%d,%d)\n", id.C, id.H, id.R);
|
||||
floppy_drive_write_sector_data(m_drive, id.H, sector_data_id, (char *) buf, sector_len, false);
|
||||
floppy_drive_write_sector_data(m_drive, id.H, sector_data_id, buf, sector_len, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
harddisk = static_cast<mfm_harddisk_device *>(m_drive);
|
||||
harddisk->write_sector(id.C, id.H, id.R, buf);
|
||||
}
|
||||
global_free_array(buf);
|
||||
sync_status_in();
|
||||
|
||||
m_register_r[CHIP_STATUS] &= ~CS_RETREQ;
|
||||
@ -1339,7 +1337,7 @@ void smc92x4_device::format_floppy_track(int flags)
|
||||
|
||||
int normal_data_mark = flags & 0x10;
|
||||
|
||||
UINT8 *buffer;
|
||||
dynamic_buffer buffer;
|
||||
|
||||
/* Determine the track size. We cannot allow different sizes in this design. */
|
||||
int data_count = 0;
|
||||
@ -1360,7 +1358,7 @@ void smc92x4_device::format_floppy_track(int flags)
|
||||
}
|
||||
|
||||
/* Build buffer */
|
||||
buffer = global_alloc_array(UINT8, data_count);
|
||||
buffer.resize(data_count);
|
||||
|
||||
fm = in_single_density_mode();
|
||||
|
||||
@ -1488,8 +1486,7 @@ void smc92x4_device::format_floppy_track(int flags)
|
||||
memset(&buffer[index], gap_byte, gap4);
|
||||
index += gap4;
|
||||
|
||||
floppy_drive_write_track_data_info_buffer(m_drive, m_register_w[DESIRED_HEAD]&0x0f, (char *)buffer, &data_count);
|
||||
global_free_array(buffer);
|
||||
floppy_drive_write_track_data_info_buffer(m_drive, m_register_w[DESIRED_HEAD]&0x0f, buffer, &data_count);
|
||||
sync_status_in();
|
||||
}
|
||||
|
||||
@ -1511,7 +1508,7 @@ void smc92x4_device::format_harddisk_track(int flags)
|
||||
|
||||
mfm_harddisk_device *harddisk = static_cast<mfm_harddisk_device *>(m_drive);
|
||||
|
||||
UINT8 *buffer;
|
||||
dynamic_buffer buffer;
|
||||
|
||||
sync_status_in();
|
||||
|
||||
@ -1528,7 +1525,7 @@ void smc92x4_device::format_harddisk_track(int flags)
|
||||
|
||||
data_count = gap1 + count*(sync+12+gap2+sync+size*128+gap3)+gap4;
|
||||
|
||||
buffer = global_alloc_array(UINT8, data_count);
|
||||
buffer.resize(data_count);
|
||||
|
||||
index = 0;
|
||||
gap_byte = 0x4e;
|
||||
@ -1590,7 +1587,6 @@ void smc92x4_device::format_harddisk_track(int flags)
|
||||
// Now write the whole track
|
||||
harddisk->write_track(m_register_w[DESIRED_HEAD]&0x0f, buffer, data_count);
|
||||
|
||||
global_free_array(buffer);
|
||||
sync_status_in();
|
||||
}
|
||||
|
||||
|
@ -2137,10 +2137,9 @@ void saturn_state::make_dir_current(UINT32 fad)
|
||||
{
|
||||
int i;
|
||||
UINT32 nextent, numentries;
|
||||
UINT8 *sect;
|
||||
dynamic_buffer sect(MAX_DIR_SIZE);
|
||||
direntryT *curentry;
|
||||
|
||||
sect = global_alloc_array(UINT8, MAX_DIR_SIZE);
|
||||
memset(sect, 0, MAX_DIR_SIZE);
|
||||
if(sectlenin != 2048)
|
||||
popmessage("Sector Length %d, contact MAMEdev (1)",sectlenin);
|
||||
@ -2230,8 +2229,6 @@ void saturn_state::make_dir_current(UINT32 fad)
|
||||
i = numfiles;
|
||||
}
|
||||
}
|
||||
|
||||
global_free_array(sect);
|
||||
}
|
||||
|
||||
void saturn_state::stvcd_exit( void )
|
||||
|
@ -78,20 +78,6 @@ static void output_exit(running_machine &machine);
|
||||
INLINE FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
||||
#if 0
|
||||
/*-------------------------------------------------
|
||||
copy_string - make a copy of a string
|
||||
-------------------------------------------------*/
|
||||
|
||||
INLINE const char *copy_string(const char *string)
|
||||
{
|
||||
char *newstring = global_alloc_array(char, strlen(string) + 1);
|
||||
strcpy(newstring, string);
|
||||
return newstring;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
get_hash - return the hash of an output value
|
||||
-------------------------------------------------*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "corealloc.h"
|
||||
#include "coretmpl.h"
|
||||
#include "sound/wavwrite.h"
|
||||
|
||||
struct wav_file
|
||||
@ -122,13 +122,13 @@ void wav_add_data_16(wav_file *wav, INT16 *data, int samples)
|
||||
|
||||
void wav_add_data_32(wav_file *wav, INT32 *data, int samples, int shift)
|
||||
{
|
||||
INT16 *temp;
|
||||
dynamic_array<INT16> temp;
|
||||
int i;
|
||||
|
||||
if (!wav) return;
|
||||
|
||||
/* allocate temp memory */
|
||||
temp = (INT16 *)global_alloc_array(INT16, samples);
|
||||
/* resize dynamic array */
|
||||
temp.resize(samples);
|
||||
if (!temp)
|
||||
return;
|
||||
|
||||
@ -142,21 +142,18 @@ void wav_add_data_32(wav_file *wav, INT32 *data, int samples, int shift)
|
||||
/* write and flush */
|
||||
fwrite(temp, 2, samples, wav->file);
|
||||
fflush(wav->file);
|
||||
|
||||
/* free memory */
|
||||
global_free_array(temp);
|
||||
}
|
||||
|
||||
|
||||
void wav_add_data_16lr(wav_file *wav, INT16 *left, INT16 *right, int samples)
|
||||
{
|
||||
INT16 *temp;
|
||||
dynamic_array<INT16> temp;
|
||||
int i;
|
||||
|
||||
if (!wav) return;
|
||||
|
||||
/* allocate temp memory */
|
||||
temp = (INT16 *)global_alloc_array(INT16, samples * 2);
|
||||
/* resize dynamic array */
|
||||
temp.resize(samples * 2);
|
||||
if (!temp)
|
||||
return;
|
||||
|
||||
@ -167,21 +164,18 @@ void wav_add_data_16lr(wav_file *wav, INT16 *left, INT16 *right, int samples)
|
||||
/* write and flush */
|
||||
fwrite(temp, 4, samples, wav->file);
|
||||
fflush(wav->file);
|
||||
|
||||
/* free memory */
|
||||
global_free_array(temp);
|
||||
}
|
||||
|
||||
|
||||
void wav_add_data_32lr(wav_file *wav, INT32 *left, INT32 *right, int samples, int shift)
|
||||
{
|
||||
INT16 *temp;
|
||||
dynamic_array<INT16> temp;
|
||||
int i;
|
||||
|
||||
if (!wav) return;
|
||||
|
||||
/* allocate temp memory */
|
||||
temp = (INT16 *)global_alloc_array(INT16, samples);
|
||||
/* resize dynamic array */
|
||||
temp.resize(samples);
|
||||
if (!temp)
|
||||
return;
|
||||
|
||||
@ -196,7 +190,4 @@ void wav_add_data_32lr(wav_file *wav, INT32 *left, INT32 *right, int samples, in
|
||||
/* write and flush */
|
||||
fwrite(temp, 4, samples, wav->file);
|
||||
fflush(wav->file);
|
||||
|
||||
/* free memory */
|
||||
global_free_array(temp);
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ huffman_error huffman_context_base::import_tree_huffman(bitstream_in &bitbuf)
|
||||
huffman_error huffman_context_base::export_tree_huffman(bitstream_out &bitbuf)
|
||||
{
|
||||
// first RLE compress the lengths of all the nodes
|
||||
dynamic_array<UINT8> rle_data(m_numcodes);
|
||||
dynamic_buffer rle_data(m_numcodes);
|
||||
UINT8 *dest = rle_data;
|
||||
dynamic_array<UINT16> rle_lengths(m_numcodes/3);
|
||||
UINT16 *lengths = rle_lengths;
|
||||
|
Loading…
Reference in New Issue
Block a user