Skip to content

Commit

Permalink
Merge pull request #375 from TomHarte/UndefinedBehaviour
Browse files Browse the repository at this point in the history
Resolves various pieces of undefined behaviour.
  • Loading branch information
TomHarte committed Mar 23, 2018
2 parents 2a320fd + 3bb496f commit 76661c0
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Analyser/Static/Acorn/Target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace Static {
namespace Acorn {

struct Target: public ::Analyser::Static::Target {
bool has_adfs;
bool has_dfs;
bool should_shift_restart;
bool has_adfs = false;
bool has_dfs = false;
bool should_shift_restart = false;
};

}
Expand Down
2 changes: 1 addition & 1 deletion Analyser/Static/AmstradCPC/Target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Target: public ::Analyser::Static::Target {
CPC6128
};

Model model;
Model model = Model::CPC464;
};

}
Expand Down
4 changes: 2 additions & 2 deletions Analyser/Static/Atari/Target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ struct Target: public ::Analyser::Static::Target {
};

// TODO: shouldn't these be properties of the cartridge?
PagingModel paging_model;
bool uses_superchip;
PagingModel paging_model = PagingModel::None;
bool uses_superchip = false;
};

}
Expand Down
4 changes: 2 additions & 2 deletions Analyser/Static/Commodore/Target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct Target: public ::Analyser::Static::Target {
ThirtyTwoKB
};

MemoryModel memory_model;
bool has_c1540;
MemoryModel memory_model = MemoryModel::Unexpanded;
bool has_c1540 = false;
};

}
Expand Down
4 changes: 2 additions & 2 deletions Analyser/Static/Oric/Target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Static {
namespace Oric {

struct Target: public ::Analyser::Static::Target {
bool use_atmos_rom;
bool has_microdisc;
bool use_atmos_rom = false;
bool has_microdisc = false;
};

}
Expand Down
4 changes: 2 additions & 2 deletions Analyser/Static/ZX8081/Target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct Target: public ::Analyser::Static::Target {
SixtyFourKB
};

MemoryModel memory_model;
bool isZX81;
MemoryModel memory_model = MemoryModel::Unexpanded;
bool isZX81 = false;
};

}
Expand Down
4 changes: 4 additions & 0 deletions Components/6560/6560.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ template <class T> class MOS6560 {
set_output_mode(OutputMode::NTSC);
}

~MOS6560() {
audio_queue_.flush();
}

void set_clock_rate(double clock_rate) {
speaker_.set_input_rate(static_cast<float>(clock_rate / 4.0));
}
Expand Down
2 changes: 2 additions & 0 deletions Concurrency/AsyncTaskQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ AsyncTaskQueue::AsyncTaskQueue()

AsyncTaskQueue::~AsyncTaskQueue() {
#ifdef __APPLE__
flush();
dispatch_release(serial_dispatch_queue_);
serial_dispatch_queue_ = nullptr;
#else
Expand Down Expand Up @@ -82,6 +83,7 @@ void AsyncTaskQueue::flush() {

DeferringAsyncTaskQueue::~DeferringAsyncTaskQueue() {
perform();
flush();
}

void DeferringAsyncTaskQueue::defer(std::function<void(void)> function) {
Expand Down
4 changes: 4 additions & 0 deletions Machines/AmstradCPC/AmstradCPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class AYDeferrer {
speaker_.set_input_rate(1000000);
}

~AYDeferrer() {
audio_queue_.flush();
}

/// Adds @c half_cycles half cycles to the amount of time that has passed.
inline void run_for(HalfCycles half_cycles) {
cycles_since_update_ += half_cycles;
Expand Down
4 changes: 4 additions & 0 deletions Machines/Atari2600/Bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class Bus {
tia_sound_(audio_queue_),
speaker_(tia_sound_) {}

virtual ~Bus() {
audio_queue_.flush();
}

virtual void run_for(const Cycles cycles) = 0;
virtual void apply_confidence(Analyser::Dynamic::ConfidenceCounter &confidence_counter) = 0;
virtual void set_reset_line(bool state) = 0;
Expand Down
4 changes: 4 additions & 0 deletions Machines/ColecoVision/ColecoVision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class ConcreteMachine:
joysticks_.emplace_back(new Joystick);
}

~ConcreteMachine() {
audio_queue_.flush();
}

std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() override {
return joysticks_;
}
Expand Down
4 changes: 4 additions & 0 deletions Machines/Electron/Electron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class ConcreteMachine:
speaker_.set_input_rate(2000000 / SoundGenerator::clock_rate_divider);
}

~ConcreteMachine() {
audio_queue_.flush();
}

void set_rom(ROMSlot slot, const std::vector<uint8_t> &data, bool is_writeable) override final {
uint8_t *target = nullptr;
switch(slot) {
Expand Down
4 changes: 4 additions & 0 deletions Machines/MSX/MSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class ConcreteMachine:
tape_player_.set_sleep_observer(this);
}

~ConcreteMachine() {
audio_queue_.flush();
}

void setup_output(float aspect_ratio) override {
vdp_.reset(new TI::TMS9918(TI::TMS9918::TMS9918A));
}
Expand Down
4 changes: 4 additions & 0 deletions Machines/Oric/Oric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ class ConcreteMachine:
Memory::Fuzz(ram_, sizeof(ram_));
}

~ConcreteMachine() {
audio_queue_.flush();
}

// Obtains the system ROMs.
bool set_rom_fetcher(const std::function<std::vector<std::unique_ptr<std::vector<uint8_t>>>(const std::string &machine, const std::vector<std::string> &names)> &roms_with_names) override {
auto roms = roms_with_names(
Expand Down
4 changes: 4 additions & 0 deletions Machines/ZX8081/ZX8081.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ template<bool is_zx81> class ConcreteMachine:
clear_all_keys();
}

~ConcreteMachine() {
audio_queue_.flush();
}

forceinline HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) {
const HalfCycles previous_counter = horizontal_counter_;
horizontal_counter_ += cycle.length;
Expand Down
6 changes: 3 additions & 3 deletions Processors/Z80/Implementation/Z80Storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class ProcessorStorage {
uint8_t carry_result_; // the carry flag is set if bit 0 of carry_result_ is set
uint8_t halt_mask_ = 0xff;

int flag_adjustment_history_ = 0; // a shifting record of whether each opcode set any flags; it turns out
// that knowledge of what the last opcode did is necessary to get bits 5 & 3
// correct for SCF and CCF.
unsigned int flag_adjustment_history_ = 0; // a shifting record of whether each opcode set any flags; it turns out
// that knowledge of what the last opcode did is necessary to get bits 5 & 3
// correct for SCF and CCF.

HalfCycles number_of_cycles_;

Expand Down
2 changes: 1 addition & 1 deletion Storage/Disk/Encodings/MFM/SegmentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::map<std::size_t, Storage::Encodings::MFM::Sector> Storage::Encodings::MFM::
case 2: new_sector->address.sector = shifter.get_byte(); ++position; break;
case 3:
new_sector->size = shifter.get_byte();
size = static_cast<std::size_t>(128 << new_sector->size);
size = static_cast<std::size_t>(128 << (new_sector->size&7));
++position;
is_reading = false;
shifter.set_should_obey_syncs(true);
Expand Down

0 comments on commit 76661c0

Please sign in to comment.