mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-25 18:30:21 +00:00
Switched to use of std::vector
in those few remaining places where I was still using a unique_ptr
to a native type and new
ing for myself. So, some of my earliest bits of code.
This commit is contained in:
parent
ab51bc443b
commit
f931cd582d
@ -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<uint8_t> &rom) {
|
||||
memcpy(rom_, rom.data(), std::min(sizeof(rom_), rom.size()));
|
||||
}
|
||||
|
||||
void Machine::set_disk(std::shared_ptr<Storage::Disk::Disk> disk) {
|
||||
|
@ -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<uint8_t> &rom);
|
||||
|
||||
/*!
|
||||
Sets the serial bus to which this drive should attach itself.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<uint8_t> drive_rom_;
|
||||
std::vector<uint8_t> drive_rom_;
|
||||
|
||||
uint8_t *processor_read_memory_map_[64];
|
||||
uint8_t *processor_write_memory_map_[64];
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#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<std::list<std::function<void(void)>>> queued_functions_;
|
||||
|
||||
std::unique_ptr<int16_t> buffer_in_progress_;
|
||||
std::vector<int16_t> buffer_in_progress_;
|
||||
float high_frequency_cut_off_;
|
||||
int buffer_size_;
|
||||
int buffer_in_progress_pointer_;
|
||||
@ -154,14 +155,14 @@ template <class T> 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<T *>(this)->get_samples(cycles_to_read, &buffer_in_progress_.get()[buffer_in_progress_pointer_]);
|
||||
static_cast<T *>(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 T> 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<T *>(this)->get_samples(cycles_to_read, &input_buffer_.get()[input_buffer_depth_]);
|
||||
static_cast<T *>(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 T> 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 T> class Filter: public Speaker {
|
||||
std::unique_ptr<SignalProcessing::Stepper> stepper_;
|
||||
std::unique_ptr<SignalProcessing::FIRFilter> filter_;
|
||||
|
||||
std::unique_ptr<int16_t> input_buffer_;
|
||||
std::vector<int16_t> input_buffer_;
|
||||
int input_buffer_depth_;
|
||||
|
||||
void update_filter_coefficients() {
|
||||
@ -244,7 +245,7 @@ template <class T> 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;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user