From 497c20443163d4aca9378ff846b17c6cfd5eb563 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 19 Dec 2015 18:47:54 +0100 Subject: [PATCH] global_alloc_array to std::make_unique where applicable (nw) --- src/devices/bus/cpc/cpc_rom.cpp | 7 +++---- src/devices/bus/cpc/cpc_rom.h | 4 ++-- src/devices/bus/ti99_peb/evpc.cpp | 10 +++++----- src/devices/bus/ti99_peb/evpc.h | 2 +- src/devices/bus/ti99_peb/hsgpl.cpp | 8 ++++---- src/devices/bus/ti99_peb/hsgpl.h | 4 ++-- src/devices/bus/ti99_peb/ti_rs232.cpp | 10 +++++----- src/devices/bus/ti99_peb/ti_rs232.h | 2 +- src/devices/bus/ti99x/datamux.cpp | 4 ++-- src/devices/bus/ti99x/datamux.h | 2 +- src/devices/cpu/jaguar/jaguar.cpp | 14 +++----------- src/devices/cpu/jaguar/jaguar.h | 4 ++++ src/devices/machine/at29x.cpp | 20 ++++++++++---------- src/devices/machine/at29x.h | 4 ++-- src/mame/includes/hp48.h | 2 +- src/mame/machine/hp48.cpp | 17 ++++++++--------- 16 files changed, 54 insertions(+), 60 deletions(-) diff --git a/src/devices/bus/cpc/cpc_rom.cpp b/src/devices/bus/cpc/cpc_rom.cpp index a60b8e35c0b..d0d59ea4452 100644 --- a/src/devices/bus/cpc/cpc_rom.cpp +++ b/src/devices/bus/cpc/cpc_rom.cpp @@ -110,15 +110,15 @@ bool rom_image_device::call_load() device_image_interface* image = this; UINT64 size = image->length(); - m_base = global_alloc_array(UINT8, 16384); + m_base = std::make_unique(16384); if(size <= 16384) { - image->fread(m_base,size); + image->fread(m_base.get(),size); } else { image->fseek(size-16384,SEEK_SET); - image->fread(m_base,16384); + image->fread(m_base.get(),16384); } return IMAGE_INIT_PASS; @@ -130,6 +130,5 @@ bool rom_image_device::call_load() -------------------------------------------------*/ void rom_image_device::call_unload() { - global_free_array(m_base); m_base = nullptr; } diff --git a/src/devices/bus/cpc/cpc_rom.h b/src/devices/bus/cpc/cpc_rom.h index b53a94d49d3..ee758aba761 100644 --- a/src/devices/bus/cpc/cpc_rom.h +++ b/src/devices/bus/cpc/cpc_rom.h @@ -39,7 +39,7 @@ public: virtual const char *file_extensions() const override { return "rom,bin"; } virtual const option_guide *create_option_guide() const override { return nullptr; } - UINT8* base() { return m_base; } + UINT8* base() { return m_base.get(); } protected: // device-level overrides @@ -47,7 +47,7 @@ protected: virtual void device_start() override; private: - UINT8* m_base; + std::unique_ptr m_base; }; diff --git a/src/devices/bus/ti99_peb/evpc.cpp b/src/devices/bus/ti99_peb/evpc.cpp index ee7b4cd77a2..6945df0dcc6 100644 --- a/src/devices/bus/ti99_peb/evpc.cpp +++ b/src/devices/bus/ti99_peb/evpc.cpp @@ -41,7 +41,7 @@ snug_enhanced_video_device::snug_enhanced_video_device(const machine_config &mco void snug_enhanced_video_device::nvram_default() { - memset(m_novram, 0, NOVRAM_SIZE); + memset(m_novram.get(), 0, NOVRAM_SIZE); } //------------------------------------------------- @@ -51,7 +51,7 @@ void snug_enhanced_video_device::nvram_default() void snug_enhanced_video_device::nvram_read(emu_file &file) { - file.read(m_novram, NOVRAM_SIZE); + file.read(m_novram.get(), NOVRAM_SIZE); } //------------------------------------------------- @@ -61,7 +61,7 @@ void snug_enhanced_video_device::nvram_read(emu_file &file) void snug_enhanced_video_device::nvram_write(emu_file &file) { - file.write(m_novram, NOVRAM_SIZE); + file.write(m_novram.get(), NOVRAM_SIZE); } @@ -312,7 +312,7 @@ WRITE8_MEMBER(snug_enhanced_video_device::cruwrite) void snug_enhanced_video_device::device_start() { m_dsrrom = memregion(DSRROM)->base(); - m_novram = global_alloc_array(UINT8, NOVRAM_SIZE); + m_novram = std::make_unique(NOVRAM_SIZE); } void snug_enhanced_video_device::device_reset() @@ -327,7 +327,7 @@ void snug_enhanced_video_device::device_reset() void snug_enhanced_video_device::device_stop() { - global_free_array(m_novram); + m_novram = nullptr; } ROM_START( ti99_evpc ) diff --git a/src/devices/bus/ti99_peb/evpc.h b/src/devices/bus/ti99_peb/evpc.h index 5fbc9a73e38..2b67fd272fc 100644 --- a/src/devices/bus/ti99_peb/evpc.h +++ b/src/devices/bus/ti99_peb/evpc.h @@ -55,7 +55,7 @@ private: UINT8* m_dsrrom; bool m_RAMEN; int m_dsr_page; - UINT8* m_novram; /* NOVRAM area */ + std::unique_ptr m_novram; /* NOVRAM area */ evpc_palette m_palette; }; diff --git a/src/devices/bus/ti99_peb/hsgpl.cpp b/src/devices/bus/ti99_peb/hsgpl.cpp index 7f75f23ca25..42ec9360ad3 100644 --- a/src/devices/bus/ti99_peb/hsgpl.cpp +++ b/src/devices/bus/ti99_peb/hsgpl.cpp @@ -613,8 +613,8 @@ void snug_high_speed_gpl_device::grom_write(address_space& space, offs_t offset, void snug_high_speed_gpl_device::device_start() { - m_ram6_memory = global_alloc_array(UINT8, RAMSIZE); - m_gram_memory = global_alloc_array(UINT8, GRAMSIZE); + m_ram6_memory = std::make_unique(RAMSIZE); + m_gram_memory = std::make_unique(GRAMSIZE); } void snug_high_speed_gpl_device::device_reset() @@ -651,8 +651,8 @@ void snug_high_speed_gpl_device::device_config_complete(void) void snug_high_speed_gpl_device::device_stop() { - global_free_array(m_ram6_memory); - global_free_array(m_gram_memory); + m_ram6_memory = nullptr; + m_gram_memory = nullptr; } // Flash setting is used to flash an empty HSGPL DSR ROM diff --git a/src/devices/bus/ti99_peb/hsgpl.h b/src/devices/bus/ti99_peb/hsgpl.h index 9cebf4bdb13..dfb755c67b4 100644 --- a/src/devices/bus/ti99_peb/hsgpl.h +++ b/src/devices/bus/ti99_peb/hsgpl.h @@ -47,8 +47,8 @@ private: at29c040a_device* m_grom_a_eeprom; at29c040a_device* m_grom_b_eeprom; - UINT8* m_ram6_memory; - UINT8* m_gram_memory; + std::unique_ptr m_ram6_memory; + std::unique_ptr m_gram_memory; void dsrspace_readz(address_space& space, offs_t offset, UINT8* value, UINT8 mem_mask); void cartspace_readz(address_space& space, offs_t offset, UINT8* value, UINT8 mem_mask); diff --git a/src/devices/bus/ti99_peb/ti_rs232.cpp b/src/devices/bus/ti99_peb/ti_rs232.cpp index af23d59a445..14565537ea8 100644 --- a/src/devices/bus/ti99_peb/ti_rs232.cpp +++ b/src/devices/bus/ti99_peb/ti_rs232.cpp @@ -705,7 +705,7 @@ void ti_rs232_pio_device::receive_data_or_line_state(int uartind) if (m_bufpos[uartind] == m_buflen[uartind]) { // Get all out of sdlsocket - m_buflen[uartind] = serial->fread(m_recvbuf[uartind], 512); + m_buflen[uartind] = serial->fread(m_recvbuf[uartind].get(), 512); m_bufpos[uartind] = 0; if (m_buflen[uartind]==0) return; } @@ -1023,8 +1023,8 @@ void ti_rs232_pio_device::device_start() m_serdev[1] = subdevice("serdev1"); m_piodev = subdevice("piodev"); // Prepare the receive buffers - m_recvbuf[0] = global_alloc_array(UINT8, 512); - m_recvbuf[1] = global_alloc_array(UINT8, 512); + m_recvbuf[0] = std::make_unique(512); + m_recvbuf[1] = std::make_unique(512); m_pio_write = true; // required for call_load of pio_attached_device m_pio_writable = false; m_pio_handshakein = false; @@ -1032,8 +1032,8 @@ void ti_rs232_pio_device::device_start() void ti_rs232_pio_device::device_stop() { - if (m_recvbuf[0] != nullptr) global_free_array(m_recvbuf[0]); - if (m_recvbuf[1] != nullptr) global_free_array(m_recvbuf[1]); + m_recvbuf[0] = nullptr; + m_recvbuf[1] = nullptr; } void ti_rs232_pio_device::device_reset() diff --git a/src/devices/bus/ti99_peb/ti_rs232.h b/src/devices/bus/ti99_peb/ti_rs232.h index df1a7bb3a69..18db7d3533e 100644 --- a/src/devices/bus/ti99_peb/ti_rs232.h +++ b/src/devices/bus/ti99_peb/ti_rs232.h @@ -80,7 +80,7 @@ private: // Input buffer for each UART. We have to copy the contents of sdlsocket here // because the buffer in corefile will be lost on the next write operation - UINT8* m_recvbuf[2]; + std::unique_ptr m_recvbuf[2]; int m_bufpos[2], m_buflen[2]; // Latches the state of the output lines for UART0/UART1 diff --git a/src/devices/bus/ti99x/datamux.cpp b/src/devices/bus/ti99x/datamux.cpp index a9b60f30c47..a17ebf95d77 100644 --- a/src/devices/bus/ti99x/datamux.cpp +++ b/src/devices/bus/ti99x/datamux.cpp @@ -393,7 +393,7 @@ void ti99_datamux_device::device_start(void) void ti99_datamux_device::device_stop(void) { - if (m_ram16b) global_free_array(m_ram16b); + m_ram16b = nullptr; } void ti99_datamux_device::device_reset(void) @@ -411,7 +411,7 @@ void ti99_datamux_device::device_reset(void) // better use a region? if (m_ram16b==nullptr) { - m_ram16b = global_alloc_array_clear(UINT16, 32768/2); + m_ram16b = make_unique_clear(32768/2); } // Now building the list of active devices at this databus multiplex. diff --git a/src/devices/bus/ti99x/datamux.h b/src/devices/bus/ti99x/datamux.h index a93fd6b4740..604dfb2e62f 100644 --- a/src/devices/bus/ti99x/datamux.h +++ b/src/devices/bus/ti99x/datamux.h @@ -134,7 +134,7 @@ private: int m_waitcount; /* Memory expansion (internal, 16 bit). */ - UINT16 *m_ram16b; + std::unique_ptr m_ram16b; /* Use the memory expansion? */ bool m_use32k; diff --git a/src/devices/cpu/jaguar/jaguar.cpp b/src/devices/cpu/jaguar/jaguar.cpp index 0a3d1e92741..81fcba812bf 100644 --- a/src/devices/cpu/jaguar/jaguar.cpp +++ b/src/devices/cpu/jaguar/jaguar.cpp @@ -78,10 +78,6 @@ PRIVATE GLOBAL VARIABLES ***************************************************************************/ -static UINT32 table_refcount = 0; -static UINT16 * mirror_table; -static UINT8 * condition_table; - const UINT32 jaguar_cpu_device::convert_zero[32] = { 32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; @@ -150,6 +146,7 @@ jaguar_cpu_device::jaguar_cpu_device(const machine_config &mconfig, device_type , m_isdsp(isdsp) , m_cpu_interrupt(*this) , m_tables_referenced(false) + , table_refcount(0) , m_table(isdsp ? dsp_op_table : gpu_op_table) { if (isdsp) @@ -291,7 +288,7 @@ void jaguar_cpu_device::init_tables() } /* fill in the mirror table */ - mirror_table = global_alloc_array(UINT16, 65536); + mirror_table = std::make_unique(65536); for (i = 0; i < 65536; i++) mirror_table[i] = ((i >> 15) & 0x0001) | ((i >> 13) & 0x0002) | ((i >> 11) & 0x0004) | ((i >> 9) & 0x0008) | @@ -303,7 +300,7 @@ void jaguar_cpu_device::init_tables() ((i << 13) & 0x4000) | ((i << 15) & 0x8000); /* fill in the condition table */ - condition_table = global_alloc_array(UINT8, 32 * 8); + condition_table = std::make_unique(32 * 8); for (i = 0; i < 8; i++) for (j = 0; j < 32; j++) { @@ -440,12 +437,7 @@ jaguar_cpu_device::~jaguar_cpu_device() if (--table_refcount != 0) return; - if (mirror_table != nullptr) - global_free_array(mirror_table); mirror_table = nullptr; - - if (condition_table != nullptr) - global_free_array(condition_table); condition_table = nullptr; } diff --git a/src/devices/cpu/jaguar/jaguar.h b/src/devices/cpu/jaguar/jaguar.h index 49f6e48d5c7..d2ab5f235e6 100644 --- a/src/devices/cpu/jaguar/jaguar.h +++ b/src/devices/cpu/jaguar/jaguar.h @@ -164,6 +164,10 @@ protected: static const UINT32 convert_zero[32]; bool m_tables_referenced; + UINT32 table_refcount; + std::unique_ptr mirror_table; + std::unique_ptr condition_table; + const op_func *m_table; void abs_rn(UINT16 op); diff --git a/src/devices/machine/at29x.cpp b/src/devices/machine/at29x.cpp index 440645b4c00..bb2bdd8b8b9 100644 --- a/src/devices/machine/at29x.cpp +++ b/src/devices/machine/at29x.cpp @@ -108,7 +108,7 @@ at29c040a_device::at29c040a_device(const machine_config &mconfig, const char *ta void at29x_device::nvram_default() { - memset(m_eememory, 0, m_memory_size+2); + memset(m_eememory.get(), 0, m_memory_size+2); } //------------------------------------------------- @@ -118,7 +118,7 @@ void at29x_device::nvram_default() void at29x_device::nvram_read(emu_file &file) { - file.read(m_eememory, m_memory_size+2); + file.read(m_eememory.get(), m_memory_size+2); } //------------------------------------------------- @@ -131,7 +131,7 @@ void at29x_device::nvram_write(emu_file &file) // If we don't write (because there were no changes), the file will be wiped if (TRACE_PRG) logerror("%s: Write to NVRAM file\n", tag()); m_eememory[0] = m_version; - file.write(m_eememory, m_memory_size+2); + file.write(m_eememory.get(), m_memory_size+2); } /* @@ -157,7 +157,7 @@ void at29x_device::device_timer(emu_timer &timer, device_timer_id id, int param, case PGM_3: // Programming cycle end; now burn the buffer into the flash EEPROM - memcpy(m_eememory + 2 + get_sector_number(m_programming_last_offset) * m_sector_size, m_programming_buffer, m_sector_size); + memcpy(m_eememory.get() + 2 + get_sector_number(m_programming_last_offset) * m_sector_size, m_programming_buffer.get(), m_sector_size); if (TRACE_PRG) logerror("%s: Sector write completed at location %04x\n", tag(), m_programming_last_offset); @@ -366,7 +366,7 @@ WRITE8_MEMBER( at29x_device::write ) else { if (TRACE_STATE) logerror("%s: Erase chip\n", tag()); - memset(m_eememory+2, 0xff, m_memory_size); + memset(m_eememory.get()+2, 0xff, m_memory_size); } } break; @@ -460,7 +460,7 @@ WRITE8_MEMBER( at29x_device::write ) { // enter programming mode if (TRACE_STATE) logerror("%s: Enter programming mode (m_pgm=%d, m_sdp=%d)\n", tag(), m_pgm, m_sdp); // Clear the programming buffer - memset(m_programming_buffer, 0xff, m_sector_size); + memset(m_programming_buffer.get(), 0xff, m_sector_size); m_pgm = PGM_2; } } @@ -479,8 +479,8 @@ WRITE8_MEMBER( at29x_device::write ) void at29x_device::device_start(void) { - m_programming_buffer = global_alloc_array(UINT8, m_sector_size); - m_eememory = global_alloc_array(UINT8, m_memory_size+2); + m_programming_buffer = std::make_unique(m_sector_size); + m_eememory = std::make_unique(m_memory_size+2); m_programming_timer = timer_alloc(PRGTIMER); // TODO: Complete 16-bit handling @@ -490,8 +490,8 @@ void at29x_device::device_start(void) void at29x_device::device_stop(void) { - global_free_array(m_programming_buffer); - global_free_array(m_eememory); + m_programming_buffer = nullptr; + m_eememory = nullptr; } void at29x_device::device_reset(void) diff --git a/src/devices/machine/at29x.h b/src/devices/machine/at29x.h index 6c8eb6531eb..924a17e0f70 100644 --- a/src/devices/machine/at29x.h +++ b/src/devices/machine/at29x.h @@ -63,7 +63,7 @@ protected: private: void sync_flags(void); - UINT8* m_eememory; + std::unique_ptr m_eememory; bool m_lower_bbl; // set when lower boot block lockout is enabled bool m_higher_bbl; // set when upper boot block lockout is enabled @@ -78,7 +78,7 @@ private: bool m_disabling_sdb; // set when a sdp disable command is in progress bool m_toggle_bit; // indicates flashing in progress (toggles for each query) - UINT8* m_programming_buffer; + std::unique_ptr m_programming_buffer; int m_programming_last_offset; emu_timer* m_programming_timer; }; diff --git a/src/mame/includes/hp48.h b/src/mame/includes/hp48.h index 15e029632a2..f4320c3d0d3 100644 --- a/src/mame/includes/hp48.h +++ b/src/mame/includes/hp48.h @@ -69,7 +69,7 @@ public: */ UINT32 m_port_size[2]; UINT8 m_port_write[2]; - UINT8* m_port_data[2]; + std::unique_ptr m_port_data[2]; UINT32 m_bank_switch; UINT32 m_io_addr; diff --git a/src/mame/machine/hp48.cpp b/src/mame/machine/hp48.cpp index e9769f159c1..6b1ece830ba 100644 --- a/src/mame/machine/hp48.cpp +++ b/src/mame/machine/hp48.cpp @@ -666,7 +666,7 @@ void hp48_state::hp48_apply_modules() { int off = (m_bank_switch << 16) % m_port_size[1]; LOG(( "hp48_apply_modules: port 2 offset is %i\n", off )); - m_modules[HP48_NCE3].data = m_port_data[1] + off; + m_modules[HP48_NCE3].data = m_port_data[1].get() + off; } /* ROM A19 (hi 256 KB) / NCE3 (port 2) control switch */ @@ -922,13 +922,12 @@ void hp48_port_image_device::hp48_fill_port() hp48_state *state = machine().driver_data(); int size = state->m_port_size[m_port]; LOG(( "hp48_fill_port: %s module=%i size=%i rw=%i\n", tag(), m_module, size, state->m_port_write[m_port] )); - state->m_port_data[m_port] = global_alloc_array(UINT8, 2 * size); - memset( state->m_port_data[m_port], 0, 2 * size ); + state->m_port_data[m_port] = make_unique_clear(2 * size); state->m_modules[m_module].off_mask = 2 * (( size > 128 * 1024 ) ? 128 * 1024 : size) - 1; state->m_modules[m_module].read = read8_delegate(); state->m_modules[m_module].write = write8_delegate(); state->m_modules[m_module].isnop = state->m_port_write[m_port] ? 0 : 1; - state->m_modules[m_module].data = state->m_port_data[m_port]; + state->m_modules[m_module].data = (void*)state->m_port_data[m_port].get(); state->hp48_apply_modules(); } @@ -963,8 +962,8 @@ bool hp48_port_image_device::call_load() state->m_port_size[m_port] = size; state->m_port_write[m_port] = !is_readonly(); hp48_fill_port( ); - fread(state->m_port_data[m_port], state->m_port_size[m_port] ); - state->hp48_decode_nibble( state->m_port_data[m_port], state->m_port_data[m_port], state->m_port_size[m_port] ); + fread(state->m_port_data[m_port].get(), state->m_port_size[m_port] ); + state->hp48_decode_nibble( state->m_port_data[m_port].get(), state->m_port_data[m_port].get(), state->m_port_size[m_port] ); return IMAGE_INIT_PASS; } @@ -996,11 +995,11 @@ void hp48_port_image_device::call_unload() tag(), state->m_port_size[m_port], state->m_port_write[m_port] )); if ( state->m_port_write[m_port] ) { - state->hp48_encode_nibble( state->m_port_data[m_port], state->m_port_data[m_port], state->m_port_size[m_port] ); + state->hp48_encode_nibble( state->m_port_data[m_port].get(), state->m_port_data[m_port].get(), state->m_port_size[m_port] ); fseek( 0, SEEK_SET ); - fwrite( state->m_port_data[m_port], state->m_port_size[m_port] ); + fwrite( state->m_port_data[m_port].get(), state->m_port_size[m_port] ); } - global_free_array( state->m_port_data[m_port] ); + state->m_port_data[m_port] = nullptr; hp48_unfill_port(); state->hp48_apply_modules(); }