diff --git a/Machines/Commodore/1540/C1540.cpp b/Machines/Commodore/1540/C1540.cpp index 5efcd6c24..ca92c51c2 100644 --- a/Machines/Commodore/1540/C1540.cpp +++ b/Machines/Commodore/1540/C1540.cpp @@ -69,8 +69,8 @@ unsigned int Machine::perform_bus_operation(CPU::MOS6502::BusOperation operation return 1; } -void Machine::set_rom(const uint8_t *rom) { - memcpy(rom_, rom, sizeof(rom_)); +void Machine::set_rom(const std::vector &rom) { + memcpy(rom_, rom.data(), std::min(sizeof(rom_), rom.size())); } void Machine::set_disk(std::shared_ptr disk) { diff --git a/Machines/Commodore/1540/C1540.hpp b/Machines/Commodore/1540/C1540.hpp index 8fdfdc69c..5fdcf4294 100644 --- a/Machines/Commodore/1540/C1540.hpp +++ b/Machines/Commodore/1540/C1540.hpp @@ -131,7 +131,7 @@ class Machine: /*! Sets the ROM image to use for this drive; it is assumed that the buffer provided will be at least 16 kb in size. */ - void set_rom(const uint8_t *rom); + void set_rom(const std::vector &rom); /*! Sets the serial bus to which this drive should attach itself. diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 871610a42..67513e38a 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -246,8 +246,8 @@ void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data) { case Characters: target = character_rom_; max_length = 0x1000; break; case BASIC: target = basic_rom_; break; case Drive: - drive_rom_.reset(new uint8_t[length]); - memcpy(drive_rom_.get(), data, length); + drive_rom_.resize(length); + memcpy(drive_rom_.data(), data, length); install_disk_rom(); return; } @@ -313,10 +313,10 @@ void Machine::tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape) { #pragma mark - Disc void Machine::install_disk_rom() { - if(drive_rom_ && c1540_) { - c1540_->set_rom(drive_rom_.get()); + if(!drive_rom_.empty() && c1540_) { + c1540_->set_rom(drive_rom_); c1540_->run_for_cycles(2000000); - drive_rom_.reset(); + drive_rom_.clear(); } } diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index 4b3f7cf19..86b4c88ca 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -199,7 +199,7 @@ class Machine: uint8_t user_basic_memory_[0x0400]; uint8_t screen_memory_[0x1000]; uint8_t colour_memory_[0x0400]; - std::unique_ptr drive_rom_; + std::vector drive_rom_; uint8_t *processor_read_memory_map_[64]; uint8_t *processor_write_memory_map_[64]; diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index e7350da6e..29434ba0f 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -15,6 +15,7 @@ #include #include +#include #include "../SignalProcessing/Stepper.hpp" #include "../SignalProcessing/FIRFilter.hpp" @@ -54,7 +55,7 @@ class Speaker { void set_output_rate(float cycles_per_second, int buffer_size) { output_cycles_per_second_ = cycles_per_second; if(buffer_size_ != buffer_size) { - buffer_in_progress_.reset(new int16_t[buffer_size]); + buffer_in_progress_.resize((size_t)buffer_size); buffer_size_ = buffer_size; } set_needs_updated_filter_coefficients(); @@ -104,7 +105,7 @@ class Speaker { } std::shared_ptr>> queued_functions_; - std::unique_ptr buffer_in_progress_; + std::vector buffer_in_progress_; float high_frequency_cut_off_; int buffer_size_; int buffer_in_progress_pointer_; @@ -154,14 +155,14 @@ template class Filter: public Speaker { unsigned int cycles_to_read = (unsigned int)(buffer_size_ - buffer_in_progress_pointer_); if(cycles_to_read > cycles_remaining) cycles_to_read = cycles_remaining; - static_cast(this)->get_samples(cycles_to_read, &buffer_in_progress_.get()[buffer_in_progress_pointer_]); + static_cast(this)->get_samples(cycles_to_read, &buffer_in_progress_[(size_t)buffer_in_progress_pointer_]); buffer_in_progress_pointer_ += cycles_to_read; // announce to delegate if full if(buffer_in_progress_pointer_ == buffer_size_) { buffer_in_progress_pointer_ = 0; if(delegate_) { - delegate_->speaker_did_complete_samples(this, buffer_in_progress_.get(), buffer_size_); + delegate_->speaker_did_complete_samples(this, buffer_in_progress_.data(), buffer_size_); } } @@ -175,19 +176,19 @@ template class Filter: public Speaker { if(input_cycles_per_second_ > output_cycles_per_second_ || (input_cycles_per_second_ == output_cycles_per_second_ && high_frequency_cut_off_ >= 0.0)) { while(cycles_remaining) { unsigned int cycles_to_read = (unsigned int)std::min((int)cycles_remaining, number_of_taps_ - input_buffer_depth_); - static_cast(this)->get_samples(cycles_to_read, &input_buffer_.get()[input_buffer_depth_]); + static_cast(this)->get_samples(cycles_to_read, &input_buffer_[(size_t)input_buffer_depth_]); cycles_remaining -= cycles_to_read; input_buffer_depth_ += cycles_to_read; if(input_buffer_depth_ == number_of_taps_) { - buffer_in_progress_.get()[buffer_in_progress_pointer_] = filter_->apply(input_buffer_.get()); + buffer_in_progress_[(size_t)buffer_in_progress_pointer_] = filter_->apply(input_buffer_.data()); buffer_in_progress_pointer_++; // announce to delegate if full if(buffer_in_progress_pointer_ == buffer_size_) { buffer_in_progress_pointer_ = 0; if(delegate_) { - delegate_->speaker_did_complete_samples(this, buffer_in_progress_.get(), buffer_size_); + delegate_->speaker_did_complete_samples(this, buffer_in_progress_.data(), buffer_size_); } } @@ -196,7 +197,7 @@ template class Filter: public Speaker { // anything. Otherwise skip as required to get to the next sample batch and don't expect to reuse. uint64_t steps = stepper_->step(); if(steps < number_of_taps_) { - int16_t *input_buffer = input_buffer_.get(); + int16_t *input_buffer = input_buffer_.data(); memmove(input_buffer, &input_buffer[steps], sizeof(int16_t) * ((size_t)number_of_taps_ - (size_t)steps)); input_buffer_depth_ -= steps; } else { @@ -218,7 +219,7 @@ template class Filter: public Speaker { std::unique_ptr stepper_; std::unique_ptr filter_; - std::unique_ptr input_buffer_; + std::vector input_buffer_; int input_buffer_depth_; void update_filter_coefficients() { @@ -244,7 +245,7 @@ template class Filter: public Speaker { } filter_.reset(new SignalProcessing::FIRFilter((unsigned int)number_of_taps_, (float)input_cycles_per_second_, 0.0, high_pass_frequency, SignalProcessing::FIRFilter::DefaultAttenuation)); - input_buffer_.reset(new int16_t[number_of_taps_]); + input_buffer_.resize((size_t)number_of_taps_); input_buffer_depth_ = 0; } };