From fbb446e8adfef79f5ca47b9b1f64bf72266c1e57 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Fri, 31 Jan 2025 03:29:36 +1100 Subject: [PATCH] Fix up some stuff: * formats/cassimg.cpp: Put allocation outside loop again, check more allocations for failure. * pc8801_flop.xml: Actually mark clones as clones, transliterate title for S.F.3.D. * apple/macadb.cpp: Tidy a little. --- hash/pc8801_flop.xml | 6 +++--- src/lib/formats/cassimg.cpp | 39 ++++++++++++++++++++++++++---------- src/mame/alesis/midiverb.cpp | 5 ++--- src/mame/apple/macadb.cpp | 32 +++++++++-------------------- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/hash/pc8801_flop.xml b/hash/pc8801_flop.xml index 5e680d13eb4..52d06cc6aec 100644 --- a/hash/pc8801_flop.xml +++ b/hash/pc8801_flop.xml @@ -29122,7 +29122,7 @@ Start and Program Disks OK, the remaining part is damaged (missing d88 headers?) - S.F.3.D - Original Operation Thanksgiving + Point X Senryō Sakusen S.F.3.D - Original Operation Thanksgiving 1986 クロスメディアソフト (Cross Media Soft) @@ -29135,8 +29135,8 @@ Start and Program Disks OK, the remaining part is damaged (missing d88 headers?) - - S.F.3.D - Original Operation Thanksgiving (alt) + + Point X Senryō Sakusen S.F.3.D - Original Operation Thanksgiving (alt) 1986 クロスメディアソフト (Cross Media Soft) diff --git a/src/lib/formats/cassimg.cpp b/src/lib/formats/cassimg.cpp index 599b2698a81..fc953c2bdf2 100644 --- a/src/lib/formats/cassimg.cpp +++ b/src/lib/formats/cassimg.cpp @@ -791,7 +791,8 @@ cassette_image::error cassette_image::legacy_construct(const LegacyWaveFiller *l error err; int length; int sample_count; - std::vector samples; + std::unique_ptr samples; + std::unique_ptr chunk; int pos = 0; uint64_t offset = 0; @@ -814,15 +815,21 @@ cassette_image::error cassette_image::legacy_construct(const LegacyWaveFiller *l /* determine number of samples */ if (args.chunk_sample_calc != nullptr) { - if (size > 0x7FFFFFFF) + if (size > 0x7fffffff) { err = error::OUT_OF_MEMORY; goto done; } - std::vector bytes(size); - image_read(&bytes[0], 0, size); - sample_count = args.chunk_sample_calc(&bytes[0], (int)size); + std::unique_ptr bytes(new (std::nothrow) uint8_t [size]); + if (!bytes) + { + err = error::OUT_OF_MEMORY; + goto done; + } + + image_read(bytes.get(), 0, size); + sample_count = args.chunk_sample_calc(bytes.get(), (int)size); // chunk_sample_calc functions report errors by returning negative numbers if (sample_count < 0) @@ -842,7 +849,12 @@ cassette_image::error cassette_image::legacy_construct(const LegacyWaveFiller *l sample_count += args.header_samples + args.trailer_samples; /* allocate a buffer for the completed samples */ - samples.resize(sample_count); + samples.reset(new (std::nothrow) int16_t [sample_count]); + if (!samples) + { + err = error::OUT_OF_MEMORY; + goto done; + } /* if there has to be a header */ if (args.header_samples > 0) @@ -857,11 +869,15 @@ cassette_image::error cassette_image::legacy_construct(const LegacyWaveFiller *l } /* convert the file data to samples */ + chunk.reset(new (std::nothrow) uint8_t [args.chunk_size]); + if (!chunk) + { + err = error::OUT_OF_MEMORY; + goto done; + } while ((pos < sample_count) && (offset < size)) { - /* allocate a buffer for the binary data */ - std::vector chunk(args.chunk_size); - image_read(&chunk[0], offset, args.chunk_size); + image_read(chunk.get(), offset, args.chunk_size); offset += args.chunk_size; /* @@ -871,10 +887,10 @@ cassette_image::error cassette_image::legacy_construct(const LegacyWaveFiller *l without knowing how much data available in the image. Having wrong header with size bigger than image couses illegal access beyond image data. Desired state is: - length = args.fill_wave(&samples[pos], args.chunk_size, &chunk[0]); + length = args.fill_wave(&samples[pos], args.chunk_size, chunk.get()); aslo the fix for tap is commented out in 'tap_cas_fill_wave' */ - length = args.fill_wave(&samples[pos], sample_count - pos, &chunk[0]); + length = args.fill_wave(&samples[pos], sample_count - pos, chunk.get()); if (length < 0) { err = error::INVALID_IMAGE; @@ -884,6 +900,7 @@ cassette_image::error cassette_image::legacy_construct(const LegacyWaveFiller *l if (length == 0) break; } + chunk.reset(); /* if there has to be a trailer */ if (args.trailer_samples > 0) diff --git a/src/mame/alesis/midiverb.cpp b/src/mame/alesis/midiverb.cpp index 9d10a5fd78e..0004e1d14b6 100644 --- a/src/mame/alesis/midiverb.cpp +++ b/src/mame/alesis/midiverb.cpp @@ -2,7 +2,7 @@ // copyright-holders:m1macrophage /* -The Midiverb is a digital delay & reverb unit. +The MIDIverb is a digital delay & reverb unit. The computer portion of the device is very simple. The firmware runs on a 80C31 microcontroller. It reads the 4 buttons, drives the two 7-segment @@ -17,7 +17,7 @@ silence program is also enabled temporarily when switching between effects. Finally, there is a wet/dry control knob. For more information on the audio hardware, see midiverb_state::configure_audio(). -An interesting aspect of the Midiverb is its DSP, which is built out of discrete +An interesting aspect of the MIDIverb is its DSP, which is built out of discrete logic components and runs custom microcode. Each microcode instruction consists of a 2-bit opcode and 14-bit RAM delta offset. The effects program makes up the top 6 bits of the microcode ROM address, and the DSP just loops over the 128 @@ -653,4 +653,3 @@ ROM_END } // anonymous namespace SYST(1986, midiverb, 0, 0, midiverb, midiverb, midiverb_state, empty_init, "Alesis", "MIDIverb", MACHINE_SUPPORTS_SAVE) - diff --git a/src/mame/apple/macadb.cpp b/src/mame/apple/macadb.cpp index c2c0b926712..ef2d2d212f5 100644 --- a/src/mame/apple/macadb.cpp +++ b/src/mame/apple/macadb.cpp @@ -476,27 +476,19 @@ void macadb_device::portable_update_keyboard() bool macadb_device::adb_pollmouse() { - s32 NewX, NewY, NewButton; + s32 const NewButton = m_mouse0->read() & 0x03; + s32 const NewX = m_mouse1->read(); + s32 const NewY = m_mouse2->read(); - NewButton = m_mouse0->read() & 0x03; - NewX = m_mouse1->read(); - NewY = m_mouse2->read(); - - if ((NewX != m_lastmousex) || (NewY != m_lastmousey) || (NewButton != m_lastbutton)) - { - return true; - } - - return false; + return (NewX != m_lastmousex) || (NewY != m_lastmousey) || (NewButton != m_lastbutton); } void macadb_device::adb_accummouse(u8 *MouseX, u8 *MouseY ) { int MouseCountX = 0, MouseCountY = 0; - int NewX, NewY; - NewX = m_mouse1->read(); - NewY = m_mouse2->read(); + int const NewX = m_mouse1->read(); + int const NewY = m_mouse2->read(); // printf("pollmouse: X %d Y %d\n", NewX, NewY); @@ -538,10 +530,8 @@ void macadb_device::adb_accummouse(u8 *MouseX, u8 *MouseY ) void macadb_device::adb_talk() { - int addr, reg; - - addr = (m_command>>4); - reg = (m_command & 3); + int const addr = m_command >> 4; + int const reg = m_command & 3; // printf("Mac sent %x (cmd %d addr %d reg %d mr %d kr %d)\n", m_command, (m_command>>2)&3, addr, reg, m_mouseaddr, m_keybaddr); @@ -612,10 +602,8 @@ void macadb_device::adb_talk() this->adb_accummouse(&mouseX, &mouseY); } //printf("X %x Y %x\n", mouseX, mouseY); - m_buffer[0] = (m_lastbutton & 0x01) ? 0x00 : 0x80; - m_buffer[0] |= mouseY & 0x7f; - m_buffer[1] = (m_lastbutton & 0x02) ? 0x00 : 0x80; - m_buffer[1] |= mouseX & 0x7f; + m_buffer[0] = (BIT(~m_lastbutton, 0) << 7) | (mouseY & 0x7f); + m_buffer[1] = (BIT(~m_lastbutton, 1) << 7) | (mouseX & 0x7f); if ((m_buffer[0] != m_last_mouse[0]) || (m_buffer[1] != m_last_mouse[1])) {