From e983854e7161dd53853319a224e4c0e30c3e587a Mon Sep 17 00:00:00 2001
From: Thomas Harte <thomas.harte@gmail.com>
Date: Sat, 21 Oct 2017 21:50:53 -0400
Subject: [PATCH] Converts all `uint8_t` and `uint16_t` casts to the functional
 style.

---
 Machines/Atari2600/Cartridges/Pitfall2.hpp    |   2 +-
 .../Commodore/1540/Implementation/C1540.cpp   |   2 +-
 Machines/Commodore/Vic-20/Vic20.cpp           |  14 +--
 Machines/Electron/Electron.cpp                |   2 +-
 Machines/Electron/Speaker.cpp                 |   2 +-
 Machines/Electron/Tape.cpp                    |   8 +-
 Machines/Electron/Video.cpp                   |   6 +-
 Machines/Oric/Oric.cpp                        |   2 +-
 Machines/Oric/Video.cpp                       |   8 +-
 Machines/ZX8081/ZX8081.cpp                    |   8 +-
 NumberTheory/CRC.hpp                          |   8 +-
 .../xcschemes/Clock Signal.xcscheme           |   2 +
 Outputs/CRT/CRT.cpp                           |  16 +--
 Outputs/CRT/Internals/CRTOpenGL.hpp           |   2 +-
 Outputs/CRT/Internals/TextureBuilder.cpp      |   7 +-
 Processors/6502/Implementation/6502Base.cpp   |  14 +--
 .../Implementation/6502Implementation.hpp     |  44 +++----
 Processors/Z80/Implementation/Z80Base.cpp     |  78 ++++++------
 .../Z80/Implementation/Z80Implementation.hpp  | 114 +++++++++---------
 StaticAnalyser/Acorn/Disk.cpp                 |   4 +-
 StaticAnalyser/Acorn/Tape.cpp                 |  16 +--
 StaticAnalyser/Atari/StaticAnalyser.cpp       |   8 +-
 StaticAnalyser/Commodore/Disk.cpp             |  18 +--
 StaticAnalyser/Commodore/File.cpp             |   2 +-
 .../Disassembler/Disassembler6502.cpp         |   4 +-
 StaticAnalyser/Oric/Tape.cpp                  |  10 +-
 Storage/Data/ZX8081.cpp                       |   2 +-
 Storage/Disk/DiskImage/Formats/CPCDSK.cpp     |  16 +--
 Storage/Disk/DiskImage/Formats/D64.cpp        |  10 +-
 Storage/Disk/DiskImage/Formats/HFE.cpp        |   4 +-
 Storage/Disk/Encodings/MFM/Encoder.cpp        |   6 +-
 Storage/FileHolder.cpp                        |   8 +-
 Storage/FileHolder.hpp                        |   4 +-
 Storage/Tape/Formats/CSW.cpp                  |   2 +-
 Storage/Tape/Formats/OricTAP.cpp              |   6 +-
 Storage/Tape/Formats/TapePRG.cpp              |   2 +-
 Storage/Tape/Formats/TapeUEF.cpp              |   2 +-
 Storage/Tape/Parsers/Commodore.cpp            |   4 +-
 38 files changed, 235 insertions(+), 232 deletions(-)

diff --git a/Machines/Atari2600/Cartridges/Pitfall2.hpp b/Machines/Atari2600/Cartridges/Pitfall2.hpp
index b35cfd127..36cd1ff59 100644
--- a/Machines/Atari2600/Cartridges/Pitfall2.hpp
+++ b/Machines/Atari2600/Cartridges/Pitfall2.hpp
@@ -73,7 +73,7 @@ class Pitfall2: public BusExtender {
 					mask_[address & 7] = 0x00;
 				break;
 				case 0x1058: case 0x1059: case 0x105a: case 0x105b: case 0x105c: case 0x105d: case 0x105e: case 0x105f:
-					featcher_address_[address & 7] = (featcher_address_[address & 7] & 0x00ff) | (uint16_t)(*value << 8);
+					featcher_address_[address & 7] = (featcher_address_[address & 7] & 0x00ff) | static_cast<uint16_t>(*value << 8);
 				break;
 				case 0x1070: case 0x1071: case 0x1072: case 0x1073: case 0x1074: case 0x1075: case 0x1076: case 0x1077:
 					random_number_generator_ = 0;
diff --git a/Machines/Commodore/1540/Implementation/C1540.cpp b/Machines/Commodore/1540/Implementation/C1540.cpp
index 3ece4ed3f..ac2a98e76 100644
--- a/Machines/Commodore/1540/Implementation/C1540.cpp
+++ b/Machines/Commodore/1540/Implementation/C1540.cpp
@@ -117,7 +117,7 @@ void MachineBase::process_input_bit(int value) {
 	}
 	bit_window_offset_++;
 	if(bit_window_offset_ == 8) {
-		drive_VIA_port_handler_.set_data_input((uint8_t)shift_register_);
+		drive_VIA_port_handler_.set_data_input(static_cast<uint8_t>(shift_register_));
 		bit_window_offset_ = 0;
 		if(drive_VIA_port_handler_.get_should_set_overflow()) {
 			m6502_.set_overflow_line(true);
diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp
index 8298f7e9e..7b10b4eb1 100644
--- a/Machines/Commodore/Vic-20/Vic20.cpp
+++ b/Machines/Commodore/Vic-20/Vic20.cpp
@@ -357,7 +357,7 @@ class ConcreteMachine:
 			if(!media.cartridges.empty()) {
 				rom_address_ = 0xa000;
 				std::vector<uint8_t> rom_image = media.cartridges.front()->get_segments().front().data;
-				rom_length_ = (uint16_t)(rom_image.size());
+				rom_length_ = static_cast<uint16_t>(rom_image.size());
 
 				rom_ = new uint8_t[0x2000];
 				memcpy(rom_, rom_image.data(), rom_image.size());
@@ -467,7 +467,7 @@ class ConcreteMachine:
 						std::unique_ptr<Storage::Tape::Commodore::Header> header = parser.get_next_header(tape_->get_tape());
 
 						// serialise to wherever b2:b3 points
-						uint16_t tape_buffer_pointer = (uint16_t)user_basic_memory_[0xb2] | (uint16_t)(user_basic_memory_[0xb3] << 8);
+						uint16_t tape_buffer_pointer = static_cast<uint16_t>(user_basic_memory_[0xb2]) | static_cast<uint16_t>(user_basic_memory_[0xb3] << 8);
 						if(header) {
 							header->serialise(&user_basic_memory_[tape_buffer_pointer], 0x8000 - tape_buffer_pointer);
 						} else {
@@ -481,13 +481,13 @@ class ConcreteMachine:
 
 						*value = 0x0c;	// i.e. NOP abs
 					} else if(address == 0xf90b) {
-						uint8_t x = (uint8_t)m6502_.get_value_of_register(CPU::MOS6502::Register::X);
+						uint8_t x = static_cast<uint8_t>(m6502_.get_value_of_register(CPU::MOS6502::Register::X));
 						if(x == 0xe) {
 							Storage::Tape::Commodore::Parser parser;
 							std::unique_ptr<Storage::Tape::Commodore::Data> data = parser.get_next_data(tape_->get_tape());
 							uint16_t start_address, end_address;
-							start_address = (uint16_t)(user_basic_memory_[0xc1] | (user_basic_memory_[0xc2] << 8));
-							end_address = (uint16_t)(user_basic_memory_[0xae] | (user_basic_memory_[0xaf] << 8));
+							start_address = static_cast<uint16_t>(user_basic_memory_[0xc1] | (user_basic_memory_[0xc2] << 8));
+							end_address = static_cast<uint16_t>(user_basic_memory_[0xae] | (user_basic_memory_[0xaf] << 8));
 
 							// perform a via-processor_write_memory_map_ memcpy
 							uint8_t *data_ptr = data->data.data();
@@ -502,8 +502,8 @@ class ConcreteMachine:
 
 							// set tape status, carry and flag
 							user_basic_memory_[0x90] |= 0x40;
-							uint8_t	flags = (uint8_t)m6502_.get_value_of_register(CPU::MOS6502::Register::Flags);
-							flags &= ~(uint8_t)(CPU::MOS6502::Flag::Carry | CPU::MOS6502::Flag::Interrupt);
+							uint8_t	flags = static_cast<uint8_t>(m6502_.get_value_of_register(CPU::MOS6502::Register::Flags));
+							flags &= ~static_cast<uint8_t>((CPU::MOS6502::Flag::Carry | CPU::MOS6502::Flag::Interrupt));
 							m6502_.set_value_of_register(CPU::MOS6502::Register::Flags, flags);
 
 							// to ensure that execution proceeds to 0xfccf, pretend a NOP was here and
diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp
index 9bec3bd22..3248b1045 100644
--- a/Machines/Electron/Electron.cpp
+++ b/Machines/Electron/Electron.cpp
@@ -257,7 +257,7 @@ class ConcreteMachine:
 																						// allow the PC read to return an RTS.
 									)
 								) {
-									uint8_t service_call = (uint8_t)m6502_.get_value_of_register(CPU::MOS6502::Register::X);
+									uint8_t service_call = static_cast<uint8_t>(m6502_.get_value_of_register(CPU::MOS6502::Register::X));
 									if(address == 0xf0a8) {
 										if(!ram_[0x247] && service_call == 14) {
 											tape_.set_delegate(nullptr);
diff --git a/Machines/Electron/Speaker.cpp b/Machines/Electron/Speaker.cpp
index 1e4b20abd..01162ee79 100644
--- a/Machines/Electron/Speaker.cpp
+++ b/Machines/Electron/Speaker.cpp
@@ -13,7 +13,7 @@ using namespace Electron;
 void Speaker::get_samples(unsigned int number_of_samples, int16_t *target) {
 	if(is_enabled_) {
 		while(number_of_samples--) {
-			*target = (int16_t)((counter_ / (divider_+1)) * 8192);
+			*target = static_cast<int16_t>((counter_ / (divider_+1)) * 8192);
 			target++;
 			counter_ = (counter_ + 1) % ((divider_+1) * 2);
 		}
diff --git a/Machines/Electron/Tape.cpp b/Machines/Electron/Tape.cpp
index ebb7edec2..118cb1eaf 100644
--- a/Machines/Electron/Tape.cpp
+++ b/Machines/Electron/Tape.cpp
@@ -15,7 +15,7 @@ Tape::Tape() : TapePlayer(2000000) {
 }
 
 void Tape::push_tape_bit(uint16_t bit) {
-	data_register_ = (uint16_t)((data_register_ >> 1) | (bit << 10));
+	data_register_ = static_cast<uint16_t>((data_register_ >> 1) | (bit << 10));
 
 	if(input_.minimum_bits_until_full) input_.minimum_bits_until_full--;
 	if(input_.minimum_bits_until_full == 8) interrupt_status_ &= ~Interrupt::ReceiveDataFull;
@@ -57,12 +57,12 @@ void Tape::set_counter(uint8_t value) {
 }
 
 void Tape::set_data_register(uint8_t value) {
-	data_register_ = (uint16_t)((value << 2) | 1);
+	data_register_ = static_cast<uint16_t>((value << 2) | 1);
 	output_.bits_remaining_until_empty = 9;
 }
 
 uint8_t Tape::get_data_register() {
-	return (uint8_t)(data_register_ >> 2);
+	return static_cast<uint8_t>(data_register_ >> 2);
 }
 
 void Tape::process_input_pulse(const Storage::Tape::Tape::Pulse &pulse) {
@@ -70,7 +70,7 @@ void Tape::process_input_pulse(const Storage::Tape::Tape::Pulse &pulse) {
 }
 
 void Tape::acorn_shifter_output_bit(int value) {
-	push_tape_bit((uint16_t)value);
+	push_tape_bit(static_cast<uint16_t>(value));
 }
 
 void Tape::run_for(const Cycles cycles) {
diff --git a/Machines/Electron/Video.cpp b/Machines/Electron/Video.cpp
index 30994efb6..48c94b3a8 100644
--- a/Machines/Electron/Video.cpp
+++ b/Machines/Electron/Video.cpp
@@ -246,11 +246,11 @@ void VideoOutput::run_for(const Cycles cycles) {
 void VideoOutput::set_register(int address, uint8_t value) {
 	switch(address & 0xf) {
 		case 0x02:
-			start_screen_address_ = (start_screen_address_ & 0xfe00) | (uint16_t)((value & 0xe0) << 1);
+			start_screen_address_ = (start_screen_address_ & 0xfe00) | static_cast<uint16_t>((value & 0xe0) << 1);
 			if(!start_screen_address_) start_screen_address_ |= 0x8000;
 		break;
 		case 0x03:
-			start_screen_address_ = (start_screen_address_ & 0x01ff) | (uint16_t)((value & 0x3f) << 9);
+			start_screen_address_ = (start_screen_address_ & 0x01ff) | static_cast<uint16_t>((value & 0x3f) << 9);
 			if(!start_screen_address_) start_screen_address_ |= 0x8000;
 		break;
 		case 0x07: {
@@ -292,7 +292,7 @@ void VideoOutput::set_register(int address, uint8_t value) {
 			}
 
 			// regenerate all palette tables for now
-#define pack(a, b) (uint8_t)((a << 4) | (b))
+#define pack(a, b) static_cast<uint8_t>((a << 4) | (b))
 			for(int byte = 0; byte < 256; byte++) {
 				uint8_t *target = (uint8_t *)&palette_tables_.forty1bpp[byte];
 				target[0] = pack(palette_[(byte&0x80) >> 4], palette_[(byte&0x40) >> 3]);
diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp
index b59b37a0d..0e1ad22c7 100644
--- a/Machines/Oric/Oric.cpp
+++ b/Machines/Oric/Oric.cpp
@@ -87,7 +87,7 @@ class TapePlayer: public Storage::Tape::BinaryTapePlayer {
 			@returns The next byte from the tape.
 		*/
 		uint8_t get_next_byte(bool use_fast_encoding) {
-			return (uint8_t)parser_.get_next_byte(get_tape(), use_fast_encoding);
+			return static_cast<uint8_t>(parser_.get_next_byte(get_tape(), use_fast_encoding));
 		}
 
 	private:
diff --git a/Machines/Oric/Video.cpp b/Machines/Oric/Video.cpp
index 6ecf19daa..a2921d338 100644
--- a/Machines/Oric/Video.cpp
+++ b/Machines/Oric/Video.cpp
@@ -56,7 +56,7 @@ void VideoOutput::set_output_device(Outputs::CRT::OutputDevice output_device) {
 void VideoOutput::set_colour_rom(const std::vector<uint8_t> &rom) {
 	for(size_t c = 0; c < 8; c++) {
 		size_t index = (c << 2);
-		uint16_t rom_value = (uint16_t)(((uint16_t)rom[index] << 8) | (uint16_t)rom[index+1]);
+		uint16_t rom_value = static_cast<uint16_t>((static_cast<uint16_t>(rom[index]) << 8) | static_cast<uint16_t>(rom[index+1]));
 		rom_value = (rom_value & 0xff00) | ((rom_value >> 4)&0x000f) | ((rom_value << 4)&0x00f0);
 		colour_forms_[c] = rom_value;
 	}
@@ -65,7 +65,7 @@ void VideoOutput::set_colour_rom(const std::vector<uint8_t> &rom) {
 	uint16_t test_value = 0x0001;
 	if(*(uint8_t *)&test_value != 0x01) {
 		for(size_t c = 0; c < 8; c++) {
-			colour_forms_[c] = (uint16_t)((colour_forms_[c] >> 8) | (colour_forms_[c] << 8));
+			colour_forms_[c] = static_cast<uint16_t>((colour_forms_[c] >> 8) | (colour_forms_[c] << 8));
 		}
 	}
 }
@@ -133,8 +133,8 @@ void VideoOutput::run_for(const Cycles cycles) {
 					if(pixel_target_) {
 						uint16_t colours[2];
 						if(output_device_ == Outputs::CRT::Monitor) {
-							colours[0] = (uint8_t)(paper_ ^ inverse_mask);
-							colours[1] = (uint8_t)(ink_ ^ inverse_mask);
+							colours[0] = static_cast<uint8_t>(paper_ ^ inverse_mask);
+							colours[1] = static_cast<uint8_t>(ink_ ^ inverse_mask);
 						} else {
 							colours[0] = colour_forms_[paper_ ^ inverse_mask];
 							colours[1] = colour_forms_[ink_ ^ inverse_mask];
diff --git a/Machines/ZX8081/ZX8081.cpp b/Machines/ZX8081/ZX8081.cpp
index 4679db934..089adb1ea 100644
--- a/Machines/ZX8081/ZX8081.cpp
+++ b/Machines/ZX8081/ZX8081.cpp
@@ -155,7 +155,7 @@ template<bool is_zx81> class ConcreteMachine:
 						int next_byte = parser_.get_next_byte(tape_player_.get_tape());
 						if(next_byte != -1) {
 							uint16_t hl = z80_.get_value_of_register(CPU::Z80::Register::HL);
-							ram_[hl & ram_mask_] = (uint8_t)next_byte;
+							ram_[hl & ram_mask_] = static_cast<uint8_t>(next_byte);
 							*cycle.value = 0x00;
 							z80_.set_value_of_register(CPU::Z80::Register::ProgramCounter, tape_return_address_ - 1);
 
@@ -249,7 +249,7 @@ template<bool is_zx81> class ConcreteMachine:
 				automatic_tape_motor_start_address_ = 0x0206;
 				automatic_tape_motor_end_address_ = 0x024d;
 			}
-			rom_mask_ = (uint16_t)(rom_.size() - 1);
+			rom_mask_ = static_cast<uint16_t>(rom_.size() - 1);
 
 			switch(target.zx8081.memory_model) {
 				case StaticAnalyser::ZX8081MemoryModel::Unexpanded:
@@ -301,9 +301,9 @@ template<bool is_zx81> class ConcreteMachine:
 
 		void set_key_state(uint16_t key, bool isPressed) override final {
 			if(isPressed)
-				key_states_[key >> 8] &= (uint8_t)(~key);
+				key_states_[key >> 8] &= static_cast<uint8_t>(~key);
 			else
-				key_states_[key >> 8] |= (uint8_t)key;
+				key_states_[key >> 8] |= static_cast<uint8_t>(key);
 		}
 
 		void clear_all_keys() override final {
diff --git a/NumberTheory/CRC.hpp b/NumberTheory/CRC.hpp
index 801495b81..5f6e29bdd 100644
--- a/NumberTheory/CRC.hpp
+++ b/NumberTheory/CRC.hpp
@@ -23,12 +23,12 @@ class CRC16 {
 		CRC16(uint16_t polynomial, uint16_t reset_value) :
 				reset_value_(reset_value), value_(reset_value) {
 			for(int c = 0; c < 256; c++) {
-				uint16_t shift_value = (uint16_t)(c << 8);
+				uint16_t shift_value = static_cast<uint16_t>(c << 8);
 				for(int b = 0; b < 8; b++) {
 					uint16_t exclusive_or = (shift_value&0x8000) ? polynomial : 0x0000;
-					shift_value = (uint16_t)(shift_value << 1) ^ exclusive_or;
+					shift_value = static_cast<uint16_t>(shift_value << 1) ^ exclusive_or;
 				}
-				xor_table[c] = (uint16_t)shift_value;
+				xor_table[c] = static_cast<uint16_t>(shift_value);
 			}
 		}
 
@@ -37,7 +37,7 @@ class CRC16 {
 
 		/// Updates the CRC to include @c byte.
 		inline void add(uint8_t byte) {
-			value_ = (uint16_t)((value_ << 8) ^ xor_table[(value_ >> 8) ^ byte]);
+			value_ = static_cast<uint16_t>((value_ << 8) ^ xor_table[(value_ >> 8) ^ byte]);
 		}
 
 		/// @returns The current value of the CRC.
diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme
index 8aeaaf6bc..952d0cbdc 100644
--- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme	
+++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme	
@@ -72,11 +72,13 @@
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      enableUBSanitizer = "YES"
       language = ""
       launchStyle = "0"
       useCustomWorkingDirectory = "NO"
       ignoresPersistentStateOnLaunch = "NO"
       debugDocumentVersioning = "YES"
+      stopOnEveryUBSanitizerIssue = "YES"
       debugServiceExtension = "internal"
       allowLocationSimulation = "NO">
       <BuildableProductRunnable
diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp
index 16705bb36..e4af0b992 100644
--- a/Outputs/CRT/CRT.cpp
+++ b/Outputs/CRT/CRT.cpp
@@ -47,7 +47,7 @@ void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_di
 
 	// figure out the divisor necessary to get the horizontal flywheel into a 16-bit range
 	unsigned int real_clock_scan_period = (multiplied_cycles_per_line * height_of_display) / (time_multiplier_ * common_output_divisor_);
-	vertical_flywheel_output_divider_ = (uint16_t)(ceilf(real_clock_scan_period / 65536.0f) * (time_multiplier_ * common_output_divisor_));
+	vertical_flywheel_output_divider_ = static_cast<uint16_t>(ceilf(real_clock_scan_period / 65536.0f) * (time_multiplier_ * common_output_divisor_));
 
 	openGL_output_builder_.set_timing(cycles_per_line, multiplied_cycles_per_line, height_of_display, horizontal_flywheel_->get_scan_period(), vertical_flywheel_->get_scan_period(), vertical_flywheel_output_divider_);
 }
@@ -68,7 +68,7 @@ void CRT::set_new_display_type(unsigned int cycles_per_line, DisplayType display
 
 void CRT::set_composite_function_type(CompositeSourceType type, float offset_of_first_sample) {
 	if(type == DiscreteFourSamplesPerCycle) {
-		colour_burst_phase_adjustment_ = (uint8_t)(offset_of_first_sample * 256.0f) & 63;
+		colour_burst_phase_adjustment_ = static_cast<uint8_t>(offset_of_first_sample * 256.0f) & 63;
 	} else {
 		colour_burst_phase_adjustment_ = 0xff;
 	}
@@ -170,7 +170,7 @@ void CRT::advance_cycles(unsigned int number_of_cycles, bool hsync_requested, bo
 		if(next_run) {
 			// output_y and texture locations will be written later; we won't necessarily know what they are
 			// outside of the locked region
-			source_output_position_x1() = (uint16_t)horizontal_flywheel_->get_current_output_position();
+			source_output_position_x1() = static_cast<uint16_t>(horizontal_flywheel_->get_current_output_position());
 			source_phase() = colour_burst_phase_;
 			source_amplitude() = colour_burst_amplitude_;
 		}
@@ -184,7 +184,7 @@ void CRT::advance_cycles(unsigned int number_of_cycles, bool hsync_requested, bo
 		vertical_flywheel_->apply_event(next_run_length, (next_run_length == time_until_vertical_sync_event) ? next_vertical_sync_event : Flywheel::SyncEvent::None);
 
 		if(next_run) {
-			source_output_position_x2() = (uint16_t)horizontal_flywheel_->get_current_output_position();
+			source_output_position_x2() = static_cast<uint16_t>(horizontal_flywheel_->get_current_output_position());
 		}
 
 		// if this is horizontal retrace then advance the output line counter and bookend an output run
@@ -203,8 +203,8 @@ void CRT::advance_cycles(unsigned int number_of_cycles, bool hsync_requested, bo
 				!openGL_output_builder_.composite_output_buffer_is_full()) {
 
 				if(!is_writing_composite_run_) {
-					output_run_.x1 = (uint16_t)horizontal_flywheel_->get_current_output_position();
-					output_run_.y = (uint16_t)(vertical_flywheel_->get_current_output_position() / vertical_flywheel_output_divider_);
+					output_run_.x1 = static_cast<uint16_t>(horizontal_flywheel_->get_current_output_position());
+					output_run_.y = static_cast<uint16_t>(vertical_flywheel_->get_current_output_position() / vertical_flywheel_output_divider_);
 				} else {
 					// Get and write all those previously unwritten output ys
 					const uint16_t output_y = openGL_output_builder_.get_composite_output_y();
@@ -215,7 +215,7 @@ void CRT::advance_cycles(unsigned int number_of_cycles, bool hsync_requested, bo
 						output_x1() = output_run_.x1;
 						output_position_y() = output_run_.y;
 						output_tex_y() = output_y;
-						output_x2() = (uint16_t)horizontal_flywheel_->get_current_output_position();
+						output_x2() = static_cast<uint16_t>(horizontal_flywheel_->get_current_output_position());
 					}
 					openGL_output_builder_.array_builder.flush(
 						[=] (uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size) {
@@ -378,7 +378,7 @@ void CRT::output_colour_burst(unsigned int number_of_cycles, uint8_t phase, uint
 }
 
 void CRT::output_default_colour_burst(unsigned int number_of_cycles) {
-	output_colour_burst(number_of_cycles, (uint8_t)((phase_numerator_ * 256) / phase_denominator_ + (is_alernate_line_ ? 128 : 0)));
+	output_colour_burst(number_of_cycles, static_cast<uint8_t>((phase_numerator_ * 256) / phase_denominator_ + (is_alernate_line_ ? 128 : 0)));
 }
 
 void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider) {
diff --git a/Outputs/CRT/Internals/CRTOpenGL.hpp b/Outputs/CRT/Internals/CRTOpenGL.hpp
index 164e65395..4dbacf0c5 100644
--- a/Outputs/CRT/Internals/CRTOpenGL.hpp
+++ b/Outputs/CRT/Internals/CRTOpenGL.hpp
@@ -134,7 +134,7 @@ class OpenGLOutputBuilder {
 		}
 
 		inline uint16_t get_composite_output_y() {
-			return (uint16_t)composite_src_output_y_;
+			return static_cast<uint16_t>(composite_src_output_y_);
 		}
 
 		inline bool composite_output_buffer_is_full() {
diff --git a/Outputs/CRT/Internals/TextureBuilder.cpp b/Outputs/CRT/Internals/TextureBuilder.cpp
index 101c81a33..21a4d624c 100644
--- a/Outputs/CRT/Internals/TextureBuilder.cpp
+++ b/Outputs/CRT/Internals/TextureBuilder.cpp
@@ -82,9 +82,10 @@ uint8_t *TextureBuilder::allocate_write_area(size_t required_length, size_t requ
 	}
 
 	// Queue up the latest write area.
-	write_area_.x = write_areas_start_x_ + 1 + static_cast<uint16_t>(alignment_offset);
+	write_areas_start_x_ += static_cast<uint16_t>(alignment_offset);
+	write_area_.x = write_areas_start_x_ + 1;
 	write_area_.y = write_areas_start_y_;
-	write_area_.length = (uint16_t)required_length;
+	write_area_.length = static_cast<uint16_t>(required_length);
 
 	// Return a video pointer.
 	return pointer_to_location(write_area_.x, write_area_.y);
@@ -95,7 +96,7 @@ void TextureBuilder::reduce_previous_allocation_to(size_t actual_length) {
 	if(was_full_) return;
 
 	// Update the length of the current write area.
-	write_area_.length = (uint16_t)actual_length;
+	write_area_.length = static_cast<uint16_t>(actual_length);
 
 	// Bookend the allocation with duplicates of the first and last pixel, to protect
 	// against rounding errors when this run is drawn.
diff --git a/Processors/6502/Implementation/6502Base.cpp b/Processors/6502/Implementation/6502Base.cpp
index c30de1344..148715819 100644
--- a/Processors/6502/Implementation/6502Base.cpp
+++ b/Processors/6502/Implementation/6502Base.cpp
@@ -28,13 +28,13 @@ uint16_t ProcessorBase::get_value_of_register(Register r) {
 
 void ProcessorBase::set_value_of_register(Register r, uint16_t value) {
 	switch (r) {
-		case Register::ProgramCounter:	pc_.full = value;			break;
-		case Register::StackPointer:	s_ = (uint8_t)value;		break;
-		case Register::Flags:			set_flags((uint8_t)value);	break;
-		case Register::A:				a_ = (uint8_t)value;		break;
-		case Register::X:				x_ = (uint8_t)value;		break;
-		case Register::Y:				y_ = (uint8_t)value;		break;
-		case Register::S:				s_ = (uint8_t)value;		break;
+		case Register::ProgramCounter:	pc_.full = value;						break;
+		case Register::StackPointer:	s_ = static_cast<uint8_t>(value);		break;
+		case Register::Flags:			set_flags(static_cast<uint8_t>(value));	break;
+		case Register::A:				a_ = static_cast<uint8_t>(value);		break;
+		case Register::X:				x_ = static_cast<uint8_t>(value);		break;
+		case Register::Y:				y_ = static_cast<uint8_t>(value);		break;
+		case Register::S:				s_ = static_cast<uint8_t>(value);		break;
 		default: break;
 	}
 }
diff --git a/Processors/6502/Implementation/6502Implementation.hpp b/Processors/6502/Implementation/6502Implementation.hpp
index b17c5a517..8888a3071 100644
--- a/Processors/6502/Implementation/6502Implementation.hpp
+++ b/Processors/6502/Implementation/6502Implementation.hpp
@@ -194,17 +194,17 @@ if(number_of_cycles <= Cycles(0)) break;
 
 					case OperationCMP: {
 						const uint16_t temp16 = a_ - operand_;
-						negative_result_ = zero_result_ = (uint8_t)temp16;
+						negative_result_ = zero_result_ = static_cast<uint8_t>(temp16);
 						carry_flag_ = ((~temp16) >> 8)&1;
 					} continue;
 					case OperationCPX: {
 						const uint16_t temp16 = x_ - operand_;
-						negative_result_ = zero_result_ = (uint8_t)temp16;
+						negative_result_ = zero_result_ = static_cast<uint8_t>(temp16);
 						carry_flag_ = ((~temp16) >> 8)&1;
 					} continue;
 					case OperationCPY: {
 						const uint16_t temp16 = y_ - operand_;
-						negative_result_ = zero_result_ = (uint8_t)temp16;
+						negative_result_ = zero_result_ = static_cast<uint8_t>(temp16);
 						carry_flag_ = ((~temp16) >> 8)&1;
 					} continue;
 
@@ -223,7 +223,7 @@ if(number_of_cycles <= Cycles(0)) break;
 					case OperationSBC:
 						if(decimal_flag_) {
 							const uint16_t notCarry = carry_flag_ ^ 0x1;
-							const uint16_t decimalResult = (uint16_t)a_ - (uint16_t)operand_ - notCarry;
+							const uint16_t decimalResult = static_cast<uint16_t>(a_) - static_cast<uint16_t>(operand_) - notCarry;
 							uint16_t temp16;
 
 							temp16 = (a_&0xf) - (operand_&0xf) - notCarry;
@@ -232,13 +232,13 @@ if(number_of_cycles <= Cycles(0)) break;
 							temp16 += (a_&0xf0) - (operand_&0xf0);
 
 							overflow_flag_ = ( ( (decimalResult^a_)&(~decimalResult^operand_) )&0x80) >> 1;
-							negative_result_ = (uint8_t)temp16;
-							zero_result_ = (uint8_t)decimalResult;
+							negative_result_ = static_cast<uint8_t>(temp16);
+							zero_result_ = static_cast<uint8_t>(decimalResult);
 
 							if(temp16 > 0xff) temp16 -= 0x60;
 
 							carry_flag_ = (temp16 > 0xff) ? 0 : Flag::Carry;
-							a_ = (uint8_t)temp16;
+							a_ = static_cast<uint8_t>(temp16);
 							continue;
 						} else {
 							operand_ = ~operand_;
@@ -247,22 +247,22 @@ if(number_of_cycles <= Cycles(0)) break;
 					// deliberate fallthrough
 					case OperationADC:
 						if(decimal_flag_) {
-							const uint16_t decimalResult = (uint16_t)a_ + (uint16_t)operand_ + (uint16_t)carry_flag_;
+							const uint16_t decimalResult = static_cast<uint16_t>(a_) + static_cast<uint16_t>(operand_) + static_cast<uint16_t>(carry_flag_);
 
 							uint8_t low_nibble = (a_ & 0xf) + (operand_ & 0xf) + carry_flag_;
 							if(low_nibble >= 0xa) low_nibble = ((low_nibble + 0x6) & 0xf) + 0x10;
-							uint16_t result = (uint16_t)(a_ & 0xf0) + (uint16_t)(operand_ & 0xf0) + (uint16_t)low_nibble;
-							negative_result_ = (uint8_t)result;
+							uint16_t result = static_cast<uint16_t>(a_ & 0xf0) + static_cast<uint16_t>(operand_ & 0xf0) + static_cast<uint16_t>(low_nibble);
+							negative_result_ = static_cast<uint8_t>(result);
 							overflow_flag_ = (( (result^a_)&(result^operand_) )&0x80) >> 1;
 							if(result >= 0xa0) result += 0x60;
 
 							carry_flag_ = (result >> 8) ? 1 : 0;
-							a_ = (uint8_t)result;
-							zero_result_ = (uint8_t)decimalResult;
+							a_ = static_cast<uint8_t>(result);
+							zero_result_ = static_cast<uint8_t>(decimalResult);
 						} else {
-							const uint16_t result = (uint16_t)a_ + (uint16_t)operand_ + (uint16_t)carry_flag_;
+							const uint16_t result = static_cast<uint16_t>(a_) + static_cast<uint16_t>(operand_) + static_cast<uint16_t>(carry_flag_);
 							overflow_flag_ = (( (result^a_)&(result^operand_) )&0x80) >> 1;
-							negative_result_ = zero_result_ = a_ = (uint8_t)result;
+							negative_result_ = zero_result_ = a_ = static_cast<uint8_t>(result);
 							carry_flag_ = (result >> 8)&1;
 						}
 
@@ -286,13 +286,13 @@ if(number_of_cycles <= Cycles(0)) break;
 					continue;
 
 					case OperationROL: {
-						const uint8_t temp8 = (uint8_t)((operand_ << 1) | carry_flag_);
+						const uint8_t temp8 = static_cast<uint8_t>((operand_ << 1) | carry_flag_);
 						carry_flag_ = operand_ >> 7;
 						operand_ = negative_result_ = zero_result_ = temp8;
 					} continue;
 
 					case OperationRLA: {
-						const uint8_t temp8 = (uint8_t)((operand_ << 1) | carry_flag_);
+						const uint8_t temp8 = static_cast<uint8_t>((operand_ << 1) | carry_flag_);
 						carry_flag_ = operand_ >> 7;
 						operand_ = temp8;
 						a_ &= operand_;
@@ -320,13 +320,13 @@ if(number_of_cycles <= Cycles(0)) break;
 					continue;
 
 					case OperationROR: {
-						const uint8_t temp8 = (uint8_t)((operand_ >> 1) | (carry_flag_ << 7));
+						const uint8_t temp8 = static_cast<uint8_t>((operand_ >> 1) | (carry_flag_ << 7));
 						carry_flag_ = operand_ & 1;
 						operand_ = negative_result_ = zero_result_ = temp8;
 					} continue;
 
 					case OperationRRA: {
-						const uint8_t temp8 = (uint8_t)((operand_ >> 1) | (carry_flag_ << 7));
+						const uint8_t temp8 = static_cast<uint8_t>((operand_ >> 1) | (carry_flag_ << 7));
 						carry_flag_ = operand_ & 1;
 						operand_ = temp8;
 					} continue;
@@ -466,7 +466,7 @@ if(number_of_cycles <= Cycles(0)) break;
 					case OperationBEQ: BRA(!zero_result_);							continue;
 
 					case CycleAddSignedOperandToPC:
-						nextAddress.full = (uint16_t)(pc_.full + (int8_t)operand_);
+						nextAddress.full = static_cast<uint16_t>(pc_.full + (int8_t)operand_);
 						pc_.bytes.low = nextAddress.bytes.low;
 						if(nextAddress.bytes.high != pc_.bytes.high) {
 							uint16_t halfUpdatedPc = pc_.full;
@@ -491,7 +491,7 @@ if(number_of_cycles <= Cycles(0)) break;
 						if(decimal_flag_) {
 							a_ &= operand_;
 							uint8_t unshiftedA = a_;
-							a_ = (uint8_t)((a_ >> 1) | (carry_flag_ << 7));
+							a_ = static_cast<uint8_t>((a_ >> 1) | (carry_flag_ << 7));
 							zero_result_ = negative_result_ = a_;
 							overflow_flag_ = (a_^(a_ << 1))&Flag::Overflow;
 
@@ -501,7 +501,7 @@ if(number_of_cycles <= Cycles(0)) break;
 							if(carry_flag_) a_ += 0x60;
 						} else {
 							a_ &= operand_;
-							a_ = (uint8_t)((a_ >> 1) | (carry_flag_ << 7));
+							a_ = static_cast<uint8_t>((a_ >> 1) | (carry_flag_ << 7));
 							negative_result_ = zero_result_ = a_;
 							carry_flag_ = (a_ >> 6)&1;
 							overflow_flag_ = (a_^(a_ << 1))&Flag::Overflow;
@@ -511,7 +511,7 @@ if(number_of_cycles <= Cycles(0)) break;
 					case OperationSBX:
 						x_ &= a_;
 						uint16_t difference = x_ - operand_;
-						x_ = (uint8_t)difference;
+						x_ = static_cast<uint8_t>(difference);
 						negative_result_ = zero_result_ = x_;
 						carry_flag_ = ((difference >> 8)&1)^1;
 					continue;
diff --git a/Processors/Z80/Implementation/Z80Base.cpp b/Processors/Z80/Implementation/Z80Base.cpp
index 617053c5a..182498c75 100644
--- a/Processors/Z80/Implementation/Z80Base.cpp
+++ b/Processors/Z80/Implementation/Z80Base.cpp
@@ -22,7 +22,7 @@ uint16_t ProcessorBase::get_value_of_register(Register r) {
 
 		case Register::A:						return a_;
 		case Register::Flags:					return get_flags();
-		case Register::AF:						return (uint16_t)((a_ << 8) | get_flags());
+		case Register::AF:						return static_cast<uint16_t>((a_ << 8) | get_flags());
 		case Register::B:						return bc_.bytes.high;
 		case Register::C:						return bc_.bytes.low;
 		case Register::BC:						return bc_.full;
@@ -59,7 +59,7 @@ uint16_t ProcessorBase::get_value_of_register(Register r) {
 
 		case Register::IFF1:					return iff1_ ? 1 : 0;
 		case Register::IFF2:					return iff2_ ? 1 : 0;
-		case Register::IM:						return (uint16_t)interrupt_mode_;
+		case Register::IM:						return static_cast<uint16_t>(interrupt_mode_);
 
 		case Register::MemPtr:					return memptr_.full;
 
@@ -72,49 +72,49 @@ void ProcessorBase::set_value_of_register(Register r, uint16_t value) {
 		case Register::ProgramCounter:	pc_.full = value;				break;
 		case Register::StackPointer:	sp_.full = value;				break;
 
-		case Register::A:				a_ = (uint8_t)value;			break;
-		case Register::AF:				a_ = (uint8_t)(value >> 8);		// deliberate fallthrough...
-		case Register::Flags:			set_flags((uint8_t)value);		break;
+		case Register::A:				a_ = static_cast<uint8_t>(value);			break;
+		case Register::AF:				a_ = static_cast<uint8_t>(value >> 8);		// deliberate fallthrough...
+		case Register::Flags:			set_flags(static_cast<uint8_t>(value));		break;
 
-		case Register::B:				bc_.bytes.high = (uint8_t)value;		break;
-		case Register::C:				bc_.bytes.low = (uint8_t)value;			break;
-		case Register::BC:				bc_.full = value;						break;
-		case Register::D:				de_.bytes.high = (uint8_t)value;		break;
-		case Register::E:				de_.bytes.low = (uint8_t)value;			break;
-		case Register::DE:				de_.full = value;						break;
-		case Register::H:				hl_.bytes.high = (uint8_t)value;		break;
-		case Register::L:				hl_.bytes.low = (uint8_t)value;			break;
-		case Register::HL:				hl_.full = value;						break;
+		case Register::B:				bc_.bytes.high = static_cast<uint8_t>(value);	break;
+		case Register::C:				bc_.bytes.low = static_cast<uint8_t>(value);	break;
+		case Register::BC:				bc_.full = value;								break;
+		case Register::D:				de_.bytes.high = static_cast<uint8_t>(value);	break;
+		case Register::E:				de_.bytes.low = static_cast<uint8_t>(value);	break;
+		case Register::DE:				de_.full = value;								break;
+		case Register::H:				hl_.bytes.high = static_cast<uint8_t>(value);	break;
+		case Register::L:				hl_.bytes.low = static_cast<uint8_t>(value);	break;
+		case Register::HL:				hl_.full = value;								break;
 
-		case Register::ADash:			afDash_.bytes.high = (uint8_t)value;	break;
-		case Register::FlagsDash:		afDash_.bytes.low = (uint8_t)value;		break;
-		case Register::AFDash:			afDash_.full = value;					break;
-		case Register::BDash:			bcDash_.bytes.high = (uint8_t)value;	break;
-		case Register::CDash:			bcDash_.bytes.low = (uint8_t)value;		break;
-		case Register::BCDash:			bcDash_.full = value;					break;
-		case Register::DDash:			deDash_.bytes.high = (uint8_t)value;	break;
-		case Register::EDash:			deDash_.bytes.low = (uint8_t)value;		break;
-		case Register::DEDash:			deDash_.full = value;					break;
-		case Register::HDash:			hlDash_.bytes.high = (uint8_t)value;	break;
-		case Register::LDash:			hlDash_.bytes.low = (uint8_t)value;		break;
-		case Register::HLDash:			hlDash_.full = value;					break;
+		case Register::ADash:			afDash_.bytes.high = static_cast<uint8_t>(value);	break;
+		case Register::FlagsDash:		afDash_.bytes.low = static_cast<uint8_t>(value);	break;
+		case Register::AFDash:			afDash_.full = value;								break;
+		case Register::BDash:			bcDash_.bytes.high = static_cast<uint8_t>(value);	break;
+		case Register::CDash:			bcDash_.bytes.low = static_cast<uint8_t>(value);	break;
+		case Register::BCDash:			bcDash_.full = value;								break;
+		case Register::DDash:			deDash_.bytes.high = static_cast<uint8_t>(value);	break;
+		case Register::EDash:			deDash_.bytes.low = static_cast<uint8_t>(value);	break;
+		case Register::DEDash:			deDash_.full = value;								break;
+		case Register::HDash:			hlDash_.bytes.high = static_cast<uint8_t>(value);	break;
+		case Register::LDash:			hlDash_.bytes.low = static_cast<uint8_t>(value);	break;
+		case Register::HLDash:			hlDash_.full = value;								break;
 
-		case Register::IXh:				ix_.bytes.high = (uint8_t)value;		break;
-		case Register::IXl:				ix_.bytes.low = (uint8_t)value;			break;
-		case Register::IX:				ix_.full = value;						break;
-		case Register::IYh:				iy_.bytes.high = (uint8_t)value;		break;
-		case Register::IYl:				iy_.bytes.low = (uint8_t)value;			break;
-		case Register::IY:				iy_.full = value;						break;
+		case Register::IXh:				ix_.bytes.high = static_cast<uint8_t>(value);		break;
+		case Register::IXl:				ix_.bytes.low = static_cast<uint8_t>(value);		break;
+		case Register::IX:				ix_.full = value;									break;
+		case Register::IYh:				iy_.bytes.high = static_cast<uint8_t>(value);		break;
+		case Register::IYl:				iy_.bytes.low = static_cast<uint8_t>(value);		break;
+		case Register::IY:				iy_.full = value;									break;
 
-		case Register::R:				ir_.bytes.low = (uint8_t)value;			break;
-		case Register::I:				ir_.bytes.high = (uint8_t)value;		break;
-		case Register::Refresh:			ir_.full = (uint16_t)value;				break;
+		case Register::R:				ir_.bytes.low = static_cast<uint8_t>(value);		break;
+		case Register::I:				ir_.bytes.high = static_cast<uint8_t>(value);		break;
+		case Register::Refresh:			ir_.full = value;									break;
 
-		case Register::IFF1:			iff1_ = !!value;						break;
-		case Register::IFF2:			iff2_ = !!value;						break;
-		case Register::IM:				interrupt_mode_ = value % 3;			break;
+		case Register::IFF1:			iff1_ = !!value;				break;
+		case Register::IFF2:			iff2_ = !!value;				break;
+		case Register::IM:				interrupt_mode_ = value % 3;	break;
 
-		case Register::MemPtr:			memptr_.full = value;					break;
+		case Register::MemPtr:			memptr_.full = value;			break;
 
 		default: break;
 	}
diff --git a/Processors/Z80/Implementation/Z80Implementation.hpp b/Processors/Z80/Implementation/Z80Implementation.hpp
index a5de59af3..595027775 100644
--- a/Processors/Z80/Implementation/Z80Implementation.hpp
+++ b/Processors/Z80/Implementation/Z80Implementation.hpp
@@ -58,7 +58,7 @@ template <	class T,
 			scheduled_program_counter_++;
 
 #define set_parity(v)	\
-	parity_overflow_result_ = (uint8_t)(v^1);\
+	parity_overflow_result_ = static_cast<uint8_t>(v^1);\
 	parity_overflow_result_ ^= parity_overflow_result_ >> 4;\
 	parity_overflow_result_ ^= parity_overflow_result_ << 2;\
 	parity_overflow_result_ ^= parity_overflow_result_ >> 1;
@@ -88,12 +88,12 @@ template <	class T,
 				case MicroOp::DecodeOperation:
 					refresh_addr_ = ir_;
 					ir_.bytes.low = (ir_.bytes.low & 0x80) | ((ir_.bytes.low + current_instruction_page_->r_step) & 0x7f);
-					pc_.full += pc_increment_ & (uint16_t)halt_mask_;
+					pc_.full += pc_increment_ & static_cast<uint16_t>(halt_mask_);
 					scheduled_program_counter_ = current_instruction_page_->instructions[operation_ & halt_mask_];
 				break;
 				case MicroOp::DecodeOperationNoRChange:
 					refresh_addr_ = ir_;
-					pc_.full += pc_increment_ & (uint16_t)halt_mask_;
+					pc_.full += pc_increment_ & static_cast<uint16_t>(halt_mask_);
 					scheduled_program_counter_ = current_instruction_page_->instructions[operation_ & halt_mask_];
 				break;
 
@@ -146,7 +146,7 @@ template <	class T,
 				break;
 
 				case MicroOp::CCF:
-					half_carry_result_ = (uint8_t)(carry_result_ << 4);
+					half_carry_result_ = static_cast<uint8_t>(carry_result_ << 4);
 					carry_result_ ^= Flag::Carry;
 					subtract_flag_ = 0;
 					bit53_result_ = a_;
@@ -175,12 +175,12 @@ template <	class T,
 #pragma mark - 8-bit arithmetic
 
 #define set_arithmetic_flags(sub, b53)	\
-	sign_result_ = zero_result_ = (uint8_t)result;	\
-	carry_result_ = (uint8_t)(result >> 8);	\
-	half_carry_result_ = (uint8_t)half_result;	\
-	parity_overflow_result_ = (uint8_t)(overflow >> 5);	\
+	sign_result_ = zero_result_ = static_cast<uint8_t>(result);	\
+	carry_result_ = static_cast<uint8_t>(result >> 8);	\
+	half_carry_result_ = static_cast<uint8_t>(half_result);	\
+	parity_overflow_result_ = static_cast<uint8_t>(overflow >> 5);	\
 	subtract_flag_ = sub;	\
-	bit53_result_ = (uint8_t)b53;
+	bit53_result_ = static_cast<uint8_t>(b53);
 
 				case MicroOp::CP8: {
 					uint8_t value = *(uint8_t *)operation->source;
@@ -204,7 +204,7 @@ template <	class T,
 					// different and the result is different again
 					int overflow = (value^a_) & (result^a_);
 
-					a_ = (uint8_t)result;
+					a_ = static_cast<uint8_t>(result);
 					set_arithmetic_flags(Flag::Subtract, result);
 				} break;
 
@@ -217,7 +217,7 @@ template <	class T,
 					// different and the result is different again
 					int overflow = (value^a_) & (result^a_);
 
-					a_ = (uint8_t)result;
+					a_ = static_cast<uint8_t>(result);
 					set_arithmetic_flags(Flag::Subtract, result);
 				} break;
 
@@ -230,7 +230,7 @@ template <	class T,
 					// the same and the result is different
 					int overflow = ~(value^a_) & (result^a_);
 
-					a_ = (uint8_t)result;
+					a_ = static_cast<uint8_t>(result);
 					set_arithmetic_flags(0, result);
 				} break;
 
@@ -243,7 +243,7 @@ template <	class T,
 					// the same and the result is different
 					int overflow = ~(value^a_) & (result^a_);
 
-					a_ = (uint8_t)result;
+					a_ = static_cast<uint8_t>(result);
 					set_arithmetic_flags(0, result);
 				} break;
 
@@ -254,12 +254,12 @@ template <	class T,
 					int result = -a_;
 					int halfResult = -(a_&0xf);
 
-					a_ = (uint8_t)result;
+					a_ = static_cast<uint8_t>(result);
 					bit53_result_ = sign_result_ = zero_result_ = a_;
 					parity_overflow_result_ = overflow ? Flag::Overflow : 0;
 					subtract_flag_ = Flag::Subtract;
-					carry_result_ = (uint8_t)(result >> 8);
-					half_carry_result_ = (uint8_t)halfResult;
+					carry_result_ = static_cast<uint8_t>(result >> 8);
+					half_carry_result_ = static_cast<uint8_t>(halfResult);
 				} break;
 
 				case MicroOp::Increment8: {
@@ -271,12 +271,12 @@ template <	class T,
 					int overflow = (value ^ result) & ~value;
 					int half_result = (value&0xf) + 1;
 
-					*(uint8_t *)operation->source = (uint8_t)result;
+					*(uint8_t *)operation->source = static_cast<uint8_t>(result);
 
 					// sign, zero and 5 & 3 are set directly from the result
-					bit53_result_ = sign_result_ = zero_result_ = (uint8_t)result;
-					half_carry_result_ = (uint8_t)half_result;
-					parity_overflow_result_ = (uint8_t)(overflow >> 5);
+					bit53_result_ = sign_result_ = zero_result_ = static_cast<uint8_t>(result);
+					half_carry_result_ = static_cast<uint8_t>(half_result);
+					parity_overflow_result_ = static_cast<uint8_t>(overflow >> 5);
 					subtract_flag_ = 0;
 				} break;
 
@@ -289,12 +289,12 @@ template <	class T,
 					int overflow = (value ^ result) & value;
 					int half_result = (value&0xf) - 1;
 
-					*(uint8_t *)operation->source = (uint8_t)result;
+					*(uint8_t *)operation->source = static_cast<uint8_t>(result);
 
 					// sign, zero and 5 & 3 are set directly from the result
-					bit53_result_ = sign_result_ = zero_result_ = (uint8_t)result;
-					half_carry_result_ = (uint8_t)half_result;
-					parity_overflow_result_ = (uint8_t)(overflow >> 5);
+					bit53_result_ = sign_result_ = zero_result_ = static_cast<uint8_t>(result);
+					half_carry_result_ = static_cast<uint8_t>(half_result);
+					parity_overflow_result_ = static_cast<uint8_t>(overflow >> 5);
 					subtract_flag_ = Flag::Subtract;
 				} break;
 
@@ -362,12 +362,12 @@ template <	class T,
 					int result = sourceValue + destinationValue;
 					int halfResult = (sourceValue&0xfff) + (destinationValue&0xfff);
 
-					bit53_result_ = (uint8_t)(result >> 8);
-					carry_result_ = (uint8_t)(result >> 16);
-					half_carry_result_ = (uint8_t)(halfResult >> 8);
+					bit53_result_ = static_cast<uint8_t>(result >> 8);
+					carry_result_ = static_cast<uint8_t>(result >> 16);
+					half_carry_result_ = static_cast<uint8_t>(halfResult >> 8);
 					subtract_flag_ = 0;
 
-					*(uint16_t *)operation->destination = (uint16_t)result;
+					*(uint16_t *)operation->destination = static_cast<uint16_t>(result);
 					memptr_.full++;
 				} break;
 
@@ -381,14 +381,14 @@ template <	class T,
 					int overflow = (result ^ destinationValue) & ~(destinationValue ^ sourceValue);
 
 					bit53_result_	=
-					sign_result_	= (uint8_t)(result >> 8);
-					zero_result_	= (uint8_t)(result | sign_result_);
+					sign_result_	= static_cast<uint8_t>(result >> 8);
+					zero_result_	= static_cast<uint8_t>(result | sign_result_);
 					subtract_flag_	= 0;
-					carry_result_	= (uint8_t)(result >> 16);
-					half_carry_result_ = (uint8_t)(halfResult >> 8);
-					parity_overflow_result_ = (uint8_t)(overflow >> 13);
+					carry_result_	= static_cast<uint8_t>(result >> 16);
+					half_carry_result_ = static_cast<uint8_t>(halfResult >> 8);
+					parity_overflow_result_ = static_cast<uint8_t>(overflow >> 13);
 
-					*(uint16_t *)operation->destination = (uint16_t)result;
+					*(uint16_t *)operation->destination = static_cast<uint16_t>(result);
 					memptr_.full++;
 				} break;
 
@@ -405,14 +405,14 @@ template <	class T,
 					int overflow = (result ^ destinationValue) & (sourceValue ^ destinationValue);
 
 					bit53_result_	=
-					sign_result_	= (uint8_t)(result >> 8);
-					zero_result_	= (uint8_t)(result | sign_result_);
+					sign_result_	= static_cast<uint8_t>(result >> 8);
+					zero_result_	= static_cast<uint8_t>(result | sign_result_);
 					subtract_flag_	= Flag::Subtract;
-					carry_result_	= (uint8_t)(result >> 16);
-					half_carry_result_ = (uint8_t)(halfResult >> 8);
-					parity_overflow_result_ = (uint8_t)(overflow >> 13);
+					carry_result_	= static_cast<uint8_t>(result >> 16);
+					half_carry_result_ = static_cast<uint8_t>(halfResult >> 8);
+					parity_overflow_result_ = static_cast<uint8_t>(overflow >> 13);
 
-					*(uint16_t *)operation->destination = (uint16_t)result;
+					*(uint16_t *)operation->destination = static_cast<uint16_t>(result);
 					memptr_.full++;
 				} break;
 
@@ -477,7 +477,7 @@ template <	class T,
 	de_.full += dir;	\
 	hl_.full += dir;	\
 	uint8_t sum = a_ + temp8_;	\
-	bit53_result_ = (uint8_t)((sum&0x8) | ((sum & 0x02) << 4));	\
+	bit53_result_ = static_cast<uint8_t>((sum&0x8) | ((sum & 0x02) << 4));	\
 	subtract_flag_ = 0;	\
 	half_carry_result_ = 0;	\
 	parity_overflow_result_ = bc_.full ? Flag::Parity : 0;
@@ -515,7 +515,7 @@ template <	class T,
 	sign_result_ = zero_result_ = result;	\
 	\
 	result -= (halfResult >> 4)&1;	\
-	bit53_result_ = (uint8_t)((result&0x8) | ((result&0x2) << 4));	\
+	bit53_result_ = static_cast<uint8_t>((result&0x8) | ((result&0x2) << 4));	\
 
 				case MicroOp::CPDR: {
 					CPxR_STEP(-1);
@@ -650,25 +650,25 @@ template <	class T,
 
 				case MicroOp::RLA: {
 					uint8_t new_carry = a_ >> 7;
-					a_ = (uint8_t)((a_ << 1) | (carry_result_ & Flag::Carry));
+					a_ = static_cast<uint8_t>((a_ << 1) | (carry_result_ & Flag::Carry));
 					set_rotate_flags();
 				} break;
 
 				case MicroOp::RRA: {
 					uint8_t new_carry = a_ & 1;
-					a_ = (uint8_t)((a_ >> 1) | (carry_result_ << 7));
+					a_ = static_cast<uint8_t>((a_ >> 1) | (carry_result_ << 7));
 					set_rotate_flags();
 				} break;
 
 				case MicroOp::RLCA: {
 					uint8_t new_carry = a_ >> 7;
-					a_ = (uint8_t)((a_ << 1) | new_carry);
+					a_ = static_cast<uint8_t>((a_ << 1) | new_carry);
 					set_rotate_flags();
 				} break;
 
 				case MicroOp::RRCA: {
 					uint8_t new_carry = a_ & 1;
-					a_ = (uint8_t)((a_ >> 1) | (new_carry << 7));
+					a_ = static_cast<uint8_t>((a_ >> 1) | (new_carry << 7));
 					set_rotate_flags();
 				} break;
 
@@ -682,51 +682,51 @@ template <	class T,
 
 				case MicroOp::RLC:
 					carry_result_ = *(uint8_t *)operation->source >> 7;
-					*(uint8_t *)operation->source = (uint8_t)((*(uint8_t *)operation->source << 1) | carry_result_);
+					*(uint8_t *)operation->source = static_cast<uint8_t>((*(uint8_t *)operation->source << 1) | carry_result_);
 					set_shift_flags();
 				break;
 
 				case MicroOp::RRC:
 					carry_result_ = *(uint8_t *)operation->source;
-					*(uint8_t *)operation->source = (uint8_t)((*(uint8_t *)operation->source >> 1) | (carry_result_ << 7));
+					*(uint8_t *)operation->source = static_cast<uint8_t>((*(uint8_t *)operation->source >> 1) | (carry_result_ << 7));
 					set_shift_flags();
 				break;
 
 				case MicroOp::RL: {
 					uint8_t next_carry = *(uint8_t *)operation->source >> 7;
-					*(uint8_t *)operation->source = (uint8_t)((*(uint8_t *)operation->source << 1) | (carry_result_ & Flag::Carry));
+					*(uint8_t *)operation->source = static_cast<uint8_t>((*(uint8_t *)operation->source << 1) | (carry_result_ & Flag::Carry));
 					carry_result_ = next_carry;
 					set_shift_flags();
 				} break;
 
 				case MicroOp::RR: {
 					uint8_t next_carry = *(uint8_t *)operation->source;
-					*(uint8_t *)operation->source = (uint8_t)((*(uint8_t *)operation->source >> 1) | (carry_result_ << 7));
+					*(uint8_t *)operation->source = static_cast<uint8_t>((*(uint8_t *)operation->source >> 1) | (carry_result_ << 7));
 					carry_result_ = next_carry;
 					set_shift_flags();
 				} break;
 
 				case MicroOp::SLA:
 					carry_result_ = *(uint8_t *)operation->source >> 7;
-					*(uint8_t *)operation->source = (uint8_t)(*(uint8_t *)operation->source << 1);
+					*(uint8_t *)operation->source = static_cast<uint8_t>(*(uint8_t *)operation->source << 1);
 					set_shift_flags();
 				break;
 
 				case MicroOp::SRA:
 					carry_result_ = *(uint8_t *)operation->source;
-					*(uint8_t *)operation->source = (uint8_t)((*(uint8_t *)operation->source >> 1) | (*(uint8_t *)operation->source & 0x80));
+					*(uint8_t *)operation->source = static_cast<uint8_t>((*(uint8_t *)operation->source >> 1) | (*(uint8_t *)operation->source & 0x80));
 					set_shift_flags();
 				break;
 
 				case MicroOp::SLL:
 					carry_result_ = *(uint8_t *)operation->source >> 7;
-					*(uint8_t *)operation->source = (uint8_t)(*(uint8_t *)operation->source << 1) | 1;
+					*(uint8_t *)operation->source = static_cast<uint8_t>(*(uint8_t *)operation->source << 1) | 1;
 					set_shift_flags();
 				break;
 
 				case MicroOp::SRL:
 					carry_result_ = *(uint8_t *)operation->source;
-					*(uint8_t *)operation->source = (uint8_t)((*(uint8_t *)operation->source >> 1));
+					*(uint8_t *)operation->source = static_cast<uint8_t>((*(uint8_t *)operation->source >> 1));
 					set_shift_flags();
 				break;
 
@@ -742,7 +742,7 @@ template <	class T,
 					memptr_.full = hl_.full + 1;
 					uint8_t low_nibble = a_ & 0xf;
 					a_ = (a_ & 0xf0) | (temp8_ & 0xf);
-					temp8_ = (uint8_t)((temp8_ >> 4) | (low_nibble << 4));
+					temp8_ = static_cast<uint8_t>((temp8_ >> 4) | (low_nibble << 4));
 					set_decimal_rotate_flags();
 				} break;
 
@@ -750,7 +750,7 @@ template <	class T,
 					memptr_.full = hl_.full + 1;
 					uint8_t low_nibble = a_ & 0xf;
 					a_ = (a_ & 0xf0) | (temp8_ >> 4);
-					temp8_ = (uint8_t)((temp8_ << 4) | low_nibble);
+					temp8_ = static_cast<uint8_t>((temp8_ << 4) | low_nibble);
 					set_decimal_rotate_flags();
 				} break;
 
@@ -845,7 +845,7 @@ template <	class T,
 				break;
 
 				case MicroOp::CalculateIndexAddress:
-					memptr_.full = (uint16_t)(*(uint16_t *)operation->source + (int8_t)temp8_);
+					memptr_.full = static_cast<uint16_t>(*(uint16_t *)operation->source + (int8_t)temp8_);
 				break;
 
 				case MicroOp::IndexedPlaceHolder:
diff --git a/StaticAnalyser/Acorn/Disk.cpp b/StaticAnalyser/Acorn/Disk.cpp
index 7e5c6f663..9052c90f0 100644
--- a/StaticAnalyser/Acorn/Disk.cpp
+++ b/StaticAnalyser/Acorn/Disk.cpp
@@ -57,8 +57,8 @@ std::unique_ptr<Catalogue> StaticAnalyser::Acorn::GetDFSCatalogue(const std::sha
 
 		if(start_sector < 2) continue;
 		while(data_length > 0) {
-			uint8_t sector = (uint8_t)(start_sector % 10);
-			uint8_t track = (uint8_t)(start_sector / 10);
+			uint8_t sector = static_cast<uint8_t>(start_sector % 10);
+			uint8_t track = static_cast<uint8_t>(start_sector / 10);
 			start_sector++;
 
 			Storage::Encodings::MFM::Sector *next_sector = parser.get_sector(0, track, sector);
diff --git a/StaticAnalyser/Acorn/Tape.cpp b/StaticAnalyser/Acorn/Tape.cpp
index 68d67f737..0c77a0936 100644
--- a/StaticAnalyser/Acorn/Tape.cpp
+++ b/StaticAnalyser/Acorn/Tape.cpp
@@ -50,14 +50,14 @@ static std::unique_ptr<File::Chunk> GetNextChunk(const std::shared_ptr<Storage::
 	// addresses
 	new_chunk->load_address = (uint32_t)parser.get_next_word(tape);
 	new_chunk->execution_address = (uint32_t)parser.get_next_word(tape);
-	new_chunk->block_number = (uint16_t)parser.get_next_short(tape);
-	new_chunk->block_length = (uint16_t)parser.get_next_short(tape);
-	new_chunk->block_flag = (uint8_t)parser.get_next_byte(tape);
+	new_chunk->block_number = static_cast<uint16_t>(parser.get_next_short(tape));
+	new_chunk->block_length = static_cast<uint16_t>(parser.get_next_short(tape));
+	new_chunk->block_flag = static_cast<uint8_t>(parser.get_next_byte(tape));
 	new_chunk->next_address = (uint32_t)parser.get_next_word(tape);
 
 	uint16_t calculated_header_crc = parser.get_crc();
-	uint16_t stored_header_crc = (uint16_t)parser.get_next_short(tape);
-	stored_header_crc = (uint16_t)((stored_header_crc >> 8) | (stored_header_crc << 8));
+	uint16_t stored_header_crc = static_cast<uint16_t>(parser.get_next_short(tape));
+	stored_header_crc = static_cast<uint16_t>((stored_header_crc >> 8) | (stored_header_crc << 8));
 	new_chunk->header_crc_matched = stored_header_crc == calculated_header_crc;
 
 	if(!new_chunk->header_crc_matched) return nullptr;
@@ -65,13 +65,13 @@ static std::unique_ptr<File::Chunk> GetNextChunk(const std::shared_ptr<Storage::
 	parser.reset_crc();
 	new_chunk->data.reserve(new_chunk->block_length);
 	for(int c = 0; c < new_chunk->block_length; c++) {
-		new_chunk->data.push_back((uint8_t)parser.get_next_byte(tape));
+		new_chunk->data.push_back(static_cast<uint8_t>(parser.get_next_byte(tape)));
 	}
 
 	if(new_chunk->block_length && !(new_chunk->block_flag&0x40)) {
 		uint16_t calculated_data_crc = parser.get_crc();
-		uint16_t stored_data_crc = (uint16_t)parser.get_next_short(tape);
-		stored_data_crc = (uint16_t)((stored_data_crc >> 8) | (stored_data_crc << 8));
+		uint16_t stored_data_crc = static_cast<uint16_t>(parser.get_next_short(tape));
+		stored_data_crc = static_cast<uint16_t>((stored_data_crc >> 8) | (stored_data_crc << 8));
 		new_chunk->data_crc_matched = stored_data_crc == calculated_data_crc;
 	} else {
 		new_chunk->data_crc_matched = true;
diff --git a/StaticAnalyser/Atari/StaticAnalyser.cpp b/StaticAnalyser/Atari/StaticAnalyser.cpp
index 927629495..cd1d0a907 100644
--- a/StaticAnalyser/Atari/StaticAnalyser.cpp
+++ b/StaticAnalyser/Atari/StaticAnalyser.cpp
@@ -16,8 +16,8 @@ static void DeterminePagingFor2kCartridge(StaticAnalyser::Target &target, const
 	// if this is a 2kb cartridge then it's definitely either unpaged or a CommaVid
 	uint16_t entry_address, break_address;
 
-	entry_address = ((uint16_t)(segment.data[0x7fc] | (segment.data[0x7fd] << 8))) & 0x1fff;
-	break_address = ((uint16_t)(segment.data[0x7fe] | (segment.data[0x7ff] << 8))) & 0x1fff;
+	entry_address = (static_cast<uint16_t>(segment.data[0x7fc] | (segment.data[0x7fd] << 8))) & 0x1fff;
+	break_address = (static_cast<uint16_t>(segment.data[0x7fe] | (segment.data[0x7ff] << 8))) & 0x1fff;
 
 	// a CommaVid start address needs to be outside of its RAM
 	if(entry_address < 0x1800 || break_address < 0x1800) return;
@@ -122,8 +122,8 @@ static void DeterminePagingForCartridge(StaticAnalyser::Target &target, const St
 
 	uint16_t entry_address, break_address;
 
-	entry_address = (uint16_t)(segment.data[segment.data.size() - 4] | (segment.data[segment.data.size() - 3] << 8));
-	break_address = (uint16_t)(segment.data[segment.data.size() - 2] | (segment.data[segment.data.size() - 1] << 8));
+	entry_address = static_cast<uint16_t>(segment.data[segment.data.size() - 4] | (segment.data[segment.data.size() - 3] << 8));
+	break_address = static_cast<uint16_t>(segment.data[segment.data.size() - 2] | (segment.data[segment.data.size() - 1] << 8));
 
 	std::function<size_t(uint16_t address)> address_mapper = [](uint16_t address) {
 		if(!(address & 0x1000)) return (size_t)-1;
diff --git a/StaticAnalyser/Commodore/Disk.cpp b/StaticAnalyser/Commodore/Disk.cpp
index 5fda286b7..3cc3adeda 100644
--- a/StaticAnalyser/Commodore/Disk.cpp
+++ b/StaticAnalyser/Commodore/Disk.cpp
@@ -108,7 +108,7 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
 		}
 
 		std::shared_ptr<Sector> get_sector(uint8_t sector) {
-			uint16_t sector_address = (uint16_t)((track_ << 8) | sector);
+			uint16_t sector_address = static_cast<uint16_t>((track_ << 8) | sector);
 			if(sector_cache_[sector_address]) return sector_cache_[sector_address];
 
 			std::shared_ptr<Sector> first_sector = get_next_sector();
@@ -134,12 +134,12 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
 				}
 
 				// get sector details, skip if this looks malformed
-				uint8_t checksum = (uint8_t)get_next_byte();
-				sector->sector = (uint8_t)get_next_byte();
-				sector->track = (uint8_t)get_next_byte();
+				uint8_t checksum = static_cast<uint8_t>(get_next_byte());
+				sector->sector = static_cast<uint8_t>(get_next_byte());
+				sector->track = static_cast<uint8_t>(get_next_byte());
 				uint8_t disk_id[2];
-				disk_id[0] = (uint8_t)get_next_byte();
-				disk_id[1] = (uint8_t)get_next_byte();
+				disk_id[0] = static_cast<uint8_t>(get_next_byte());
+				disk_id[1] = static_cast<uint8_t>(get_next_byte());
 				if(checksum != (sector->sector ^ sector->track ^ disk_id[0] ^ disk_id[1])) continue;
 
 				// look for the following data
@@ -150,12 +150,12 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
 
 				checksum = 0;
 				for(size_t c = 0; c < 256; c++) {
-					sector->data[c] = (uint8_t)get_next_byte();
+					sector->data[c] = static_cast<uint8_t>(get_next_byte());
 					checksum ^= sector->data[c];
 				}
 
 				if(checksum == get_next_byte()) {
-					uint16_t sector_address = (uint16_t)((sector->track << 8) | sector->sector);
+					uint16_t sector_address = static_cast<uint16_t>((sector->track << 8) | sector->sector);
 					sector_cache_[sector_address] = sector;
 					return sector;
 				}
@@ -223,7 +223,7 @@ std::list<File> StaticAnalyser::Commodore::GetFiles(const std::shared_ptr<Storag
 			next_track = sector->data[0];
 			next_sector = sector->data[1];
 
-			if(is_first_sector) new_file.starting_address = (uint16_t)sector->data[2] | (uint16_t)(sector->data[3] << 8);
+			if(is_first_sector) new_file.starting_address = static_cast<uint16_t>(sector->data[2]) | static_cast<uint16_t>(sector->data[3] << 8);
 			if(next_track)
 				new_file.data.insert(new_file.data.end(), sector->data.begin() + (is_first_sector ? 4 : 2), sector->data.end());
 			else
diff --git a/StaticAnalyser/Commodore/File.cpp b/StaticAnalyser/Commodore/File.cpp
index 363d7501c..066685154 100644
--- a/StaticAnalyser/Commodore/File.cpp
+++ b/StaticAnalyser/Commodore/File.cpp
@@ -39,7 +39,7 @@ bool StaticAnalyser::Commodore::File::is_basic() {
 
 		if(next_line_number <= line_number) break;
 
-		line_number = (uint16_t)next_line_number;
+		line_number = static_cast<uint16_t>(next_line_number);
 		line_address = next_line_address;
 	}
 
diff --git a/StaticAnalyser/Disassembler/Disassembler6502.cpp b/StaticAnalyser/Disassembler/Disassembler6502.cpp
index fb54a95bb..e5cfe2bdd 100644
--- a/StaticAnalyser/Disassembler/Disassembler6502.cpp
+++ b/StaticAnalyser/Disassembler/Disassembler6502.cpp
@@ -249,7 +249,7 @@ static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<
 				if(low_operand_address >= memory.size() || high_operand_address >= memory.size()) return;
 				address += 2;
 
-				instruction.operand = memory[low_operand_address] | (uint16_t)(memory[high_operand_address] << 8);
+				instruction.operand = memory[low_operand_address] | static_cast<uint16_t>(memory[high_operand_address] << 8);
 			}
 			break;
 		}
@@ -301,7 +301,7 @@ static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<
 			return;
 		}
 		if(instruction.addressing_mode == Instruction::Relative) {
-			uint16_t destination = (uint16_t)(address + (int8_t)instruction.operand);
+			uint16_t destination = static_cast<uint16_t>(address + (int8_t)instruction.operand);
 			disassembly.remaining_entry_points.push_back(destination);
 		}
 	}
diff --git a/StaticAnalyser/Oric/Tape.cpp b/StaticAnalyser/Oric/Tape.cpp
index 8ba4e772c..02c2c8514 100644
--- a/StaticAnalyser/Oric/Tape.cpp
+++ b/StaticAnalyser/Oric/Tape.cpp
@@ -49,10 +49,10 @@ std::list<File> StaticAnalyser::Oric::GetFiles(const std::shared_ptr<Storage::Ta
 		}
 
 		// read end and start addresses
-		new_file.ending_address = (uint16_t)(parser.get_next_byte(tape, is_fast) << 8);
-		new_file.ending_address |= (uint16_t)parser.get_next_byte(tape, is_fast);
-		new_file.starting_address = (uint16_t)(parser.get_next_byte(tape, is_fast) << 8);
-		new_file.starting_address |= (uint16_t)parser.get_next_byte(tape, is_fast);
+		new_file.ending_address = static_cast<uint16_t>(parser.get_next_byte(tape, is_fast) << 8);
+		new_file.ending_address |= static_cast<uint16_t>(parser.get_next_byte(tape, is_fast));
+		new_file.starting_address = static_cast<uint16_t>(parser.get_next_byte(tape, is_fast) << 8);
+		new_file.starting_address |= static_cast<uint16_t>(parser.get_next_byte(tape, is_fast));
 
 		// skip an empty byte
 		parser.get_next_byte(tape, is_fast);
@@ -72,7 +72,7 @@ std::list<File> StaticAnalyser::Oric::GetFiles(const std::shared_ptr<Storage::Ta
 		size_t body_length = new_file.ending_address - new_file.starting_address + 1;
 		new_file.data.reserve(body_length);
 		for(size_t c = 0; c < body_length; c++) {
-			new_file.data.push_back((uint8_t)parser.get_next_byte(tape, is_fast));
+			new_file.data.push_back(static_cast<uint8_t>(parser.get_next_byte(tape, is_fast)));
 		}
 
 		// only one validation check: was there enough tape?
diff --git a/Storage/Data/ZX8081.cpp b/Storage/Data/ZX8081.cpp
index ada6f2e6d..ca8c02c3d 100644
--- a/Storage/Data/ZX8081.cpp
+++ b/Storage/Data/ZX8081.cpp
@@ -11,7 +11,7 @@
 using namespace Storage::Data::ZX8081;
 
 static uint16_t short_at(size_t address, const std::vector<uint8_t> &data) {
-	return (uint16_t)(data[address] | (data[address + 1] << 8));
+	return static_cast<uint16_t>(data[address] | (data[address + 1] << 8));
 }
 
 static std::shared_ptr<File> ZX80FileFromData(const std::vector<uint8_t> &data) {
diff --git a/Storage/Disk/DiskImage/Formats/CPCDSK.cpp b/Storage/Disk/DiskImage/Formats/CPCDSK.cpp
index f5fdf76c9..8d194268b 100644
--- a/Storage/Disk/DiskImage/Formats/CPCDSK.cpp
+++ b/Storage/Disk/DiskImage/Formats/CPCDSK.cpp
@@ -76,8 +76,8 @@ std::shared_ptr<Track> CPCDSK::get_track_at_position(Track::Address address) {
 	// Grab the track information.
 	fseek(file_, 5, SEEK_CUR);	// skip track number, side number, sector size — each is given per sector
 	int number_of_sectors = fgetc(file_);
-	uint8_t gap3_length = (uint8_t)fgetc(file_);
-	uint8_t filler_byte = (uint8_t)fgetc(file_);
+	uint8_t gap3_length = static_cast<uint8_t>(fgetc(file_));
+	uint8_t filler_byte = static_cast<uint8_t>(fgetc(file_));
 
 	// Grab the sector information
 	struct SectorInfo {
@@ -93,12 +93,12 @@ std::shared_ptr<Track> CPCDSK::get_track_at_position(Track::Address address) {
 	while(number_of_sectors--) {
 		SectorInfo sector_info;
 
-		sector_info.track = (uint8_t)fgetc(file_);
-		sector_info.side = (uint8_t)fgetc(file_);
-		sector_info.sector = (uint8_t)fgetc(file_);
-		sector_info.length = (uint8_t)fgetc(file_);
-		sector_info.status1 = (uint8_t)fgetc(file_);
-		sector_info.status2 = (uint8_t)fgetc(file_);
+		sector_info.track = static_cast<uint8_t>(fgetc(file_));
+		sector_info.side = static_cast<uint8_t>(fgetc(file_));
+		sector_info.sector = static_cast<uint8_t>(fgetc(file_));
+		sector_info.length = static_cast<uint8_t>(fgetc(file_));
+		sector_info.status1 = static_cast<uint8_t>(fgetc(file_));
+		sector_info.status2 = static_cast<uint8_t>(fgetc(file_));
 		sector_info.actual_length = fgetc16le();
 
 		sector_infos.push_back(sector_info);
diff --git a/Storage/Disk/DiskImage/Formats/D64.cpp b/Storage/Disk/DiskImage/Formats/D64.cpp
index dd434718f..b6010a6c5 100644
--- a/Storage/Disk/DiskImage/Formats/D64.cpp
+++ b/Storage/Disk/DiskImage/Formats/D64.cpp
@@ -30,7 +30,7 @@ D64::D64(const char *file_name) :
 	disk_id_ = 0;
 	while(*file_name) {
 		disk_id_ ^= file_name[0];
-		disk_id_ = (uint16_t)((disk_id_ << 2) ^ (disk_id_ >> 13));
+		disk_id_ = static_cast<uint16_t>((disk_id_ << 2) ^ (disk_id_ >> 13));
 		file_name++;
 	}
 }
@@ -95,16 +95,16 @@ std::shared_ptr<Track> D64::get_track_at_position(Track::Address address) {
 		uint8_t *sector_data = &data[sector * 349];
 		sector_data[0] = sector_data[1] = sector_data[2] = 0xff;
 
-		uint8_t sector_number = (uint8_t)(sector);				// sectors count from 0
-		uint8_t track_number = (uint8_t)((address.position >> 1) + 1);	// tracks count from 1
-		uint8_t checksum = (uint8_t)(sector_number ^ track_number ^ disk_id_ ^ (disk_id_ >> 8));
+		uint8_t sector_number = static_cast<uint8_t>(sector);						// sectors count from 0
+		uint8_t track_number = static_cast<uint8_t>((address.position >> 1) + 1);	// tracks count from 1
+		uint8_t checksum = static_cast<uint8_t>(sector_number ^ track_number ^ disk_id_ ^ (disk_id_ >> 8));
 		uint8_t header_start[4] = {
 			0x08, checksum, sector_number, track_number
 		};
 		Encodings::CommodoreGCR::encode_block(&sector_data[3], header_start);
 
 		uint8_t header_end[4] = {
-			(uint8_t)(disk_id_ & 0xff), (uint8_t)(disk_id_ >> 8), 0, 0
+			static_cast<uint8_t>(disk_id_ & 0xff), static_cast<uint8_t>(disk_id_ >> 8), 0, 0
 		};
 		Encodings::CommodoreGCR::encode_block(&sector_data[8], header_end);
 
diff --git a/Storage/Disk/DiskImage/Formats/HFE.cpp b/Storage/Disk/DiskImage/Formats/HFE.cpp
index a0068b38a..748895d90 100644
--- a/Storage/Disk/DiskImage/Formats/HFE.cpp
+++ b/Storage/Disk/DiskImage/Formats/HFE.cpp
@@ -69,7 +69,7 @@ std::shared_ptr<Track> HFE::get_track_at_position(Track::Address address) {
 
 		uint16_t c = 0;
 		while(c < track_length) {
-			uint16_t length = (uint16_t)std::min(256, track_length - c);
+			uint16_t length = static_cast<uint16_t>(std::min(256, track_length - c));
 			fread(&segment.data[c], 1, length, file_);
 			c += length;
 			fseek(file_, 256, SEEK_CUR);
@@ -99,7 +99,7 @@ void HFE::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tra
 
 		uint16_t c = 0;
 		while(c < data_length) {
-			uint16_t length = (uint16_t)std::min(256, data_length - c);
+			uint16_t length = static_cast<uint16_t>(std::min(256, data_length - c));
 			fwrite(&segment.data[c], 1, length, file_);
 			c += length;
 			fseek(file_, 256, SEEK_CUR);
diff --git a/Storage/Disk/Encodings/MFM/Encoder.cpp b/Storage/Disk/Encodings/MFM/Encoder.cpp
index d517635c6..4fe111f62 100644
--- a/Storage/Disk/Encodings/MFM/Encoder.cpp
+++ b/Storage/Disk/Encodings/MFM/Encoder.cpp
@@ -23,7 +23,7 @@ class MFMEncoder: public Encoder {
 		void add_byte(uint8_t input) {
 			crc_generator_.add(input);
 			uint16_t spread_value =
-				(uint16_t)(
+				static_cast<uint16_t>(
 					((input & 0x01) << 0) |
 					((input & 0x02) << 1) |
 					((input & 0x04) << 2) |
@@ -33,7 +33,7 @@ class MFMEncoder: public Encoder {
 					((input & 0x40) << 6) |
 					((input & 0x80) << 7)
 				);
-			uint16_t or_bits = (uint16_t)((spread_value << 1) | (spread_value >> 1) | (last_output_ << 15));
+			uint16_t or_bits = static_cast<uint16_t>((spread_value << 1) | (spread_value >> 1) | (last_output_ << 15));
 			uint16_t output = spread_value | ((~or_bits) & 0xaaaa);
 			output_short(output);
 		}
@@ -79,7 +79,7 @@ class FMEncoder: public Encoder {
 		void add_byte(uint8_t input) {
 			crc_generator_.add(input);
 			output_short(
-				(uint16_t)(
+				static_cast<uint16_t>(
 					((input & 0x01) << 0) |
 					((input & 0x02) << 1) |
 					((input & 0x04) << 2) |
diff --git a/Storage/FileHolder.cpp b/Storage/FileHolder.cpp
index c369dc1fd..566e4f497 100644
--- a/Storage/FileHolder.cpp
+++ b/Storage/FileHolder.cpp
@@ -55,8 +55,8 @@ uint32_t FileHolder::fgetc24le() {
 }
 
 uint16_t FileHolder::fgetc16le() {
-	uint16_t result = (uint16_t)fgetc(file_);
-	result |= (uint16_t)(fgetc(file_) << 8);
+	uint16_t result = static_cast<uint16_t>(fgetc(file_));
+	result |= static_cast<uint16_t>(fgetc(file_) << 8);
 
 	return result;
 }
@@ -71,8 +71,8 @@ uint32_t FileHolder::fgetc32be() {
 }
 
 uint16_t FileHolder::fgetc16be() {
-	uint16_t result = (uint16_t)(fgetc(file_) << 8);
-	result |= (uint16_t)fgetc(file_);
+	uint16_t result = static_cast<uint16_t>(fgetc(file_) << 8);
+	result |= static_cast<uint16_t>(fgetc(file_));
 
 	return result;
 }
diff --git a/Storage/FileHolder.hpp b/Storage/FileHolder.hpp
index 47544f6bc..a553cf926 100644
--- a/Storage/FileHolder.hpp
+++ b/Storage/FileHolder.hpp
@@ -95,7 +95,7 @@ class FileHolder {
 				uint8_t get_bits(int q) {
 					uint8_t result = 0;
 					while(q--) {
-						result = (uint8_t)((result << 1) | get_bit());
+						result = static_cast<uint8_t>((result << 1) | get_bit());
 					}
 					return result;
 				}
@@ -109,7 +109,7 @@ class FileHolder {
 				uint8_t get_bit() {
 					if(!bits_remaining_) {
 						bits_remaining_ = 8;
-						next_value_ = (uint8_t)fgetc(file_);
+						next_value_ = static_cast<uint8_t>(fgetc(file_));
 					}
 
 					uint8_t bit;
diff --git a/Storage/Tape/Formats/CSW.cpp b/Storage/Tape/Formats/CSW.cpp
index 89c399b49..5e0dd7067 100644
--- a/Storage/Tape/Formats/CSW.cpp
+++ b/Storage/Tape/Formats/CSW.cpp
@@ -72,7 +72,7 @@ CSW::CSW(const char *file_name) :
 		// uncompress will tell how many compressed bytes there actually were, so use its
 		// modification of output_length to throw away all the memory that isn't actually
 		// needed.
-		uLongf output_length = (uLongf)(number_of_waves * 5);
+		uLongf output_length = static_cast<uLongf>(number_of_waves * 5);
 		uncompress(source_data_.data(), &output_length, file_data.data(), file_data.size());
 		source_data_.resize((size_t)output_length);
 	} else {
diff --git a/Storage/Tape/Formats/OricTAP.cpp b/Storage/Tape/Formats/OricTAP.cpp
index eace8799d..30c431899 100644
--- a/Storage/Tape/Formats/OricTAP.cpp
+++ b/Storage/Tape/Formats/OricTAP.cpp
@@ -71,9 +71,9 @@ Tape::Pulse OricTAP::virtual_get_next_pulse()
 				// [9...]:		filename, up to NULL byte
 				next_byte = static_cast<uint8_t>(fgetc(file_));
 
-				if(phase_counter_ == 4)	data_end_address_ = (uint16_t)(next_byte << 8);
+				if(phase_counter_ == 4)	data_end_address_ = static_cast<uint16_t>(next_byte << 8);
 				if(phase_counter_ == 5)	data_end_address_ |= next_byte;
-				if(phase_counter_ == 6)	data_start_address_ = (uint16_t)(next_byte << 8);
+				if(phase_counter_ == 6)	data_start_address_ = static_cast<uint16_t>(next_byte << 8);
 				if(phase_counter_ == 7)	data_start_address_ |= next_byte;
 
 				if(phase_counter_ >= 9 && !next_byte)	// advance after the filename-ending NULL byte
@@ -119,7 +119,7 @@ Tape::Pulse OricTAP::virtual_get_next_pulse()
 		parity ^= (parity >> 4);
 		parity ^= (parity >> 2);
 		parity ^= (parity >> 1);
-		current_value_ = (uint16_t)(((uint16_t)next_byte << 1) | ((parity&1) << 9) | (7 << 10));
+		current_value_ = static_cast<uint16_t>((static_cast<uint16_t>(next_byte) << 1) | ((parity&1) << 9) | (7 << 10));
 	}
 
 	// In slow mode, a 0 is 4 periods of 1200 Hz, a 1 is 8 periods at 2400 Hz.
diff --git a/Storage/Tape/Formats/TapePRG.cpp b/Storage/Tape/Formats/TapePRG.cpp
index 3e4077482..27be6d234 100644
--- a/Storage/Tape/Formats/TapePRG.cpp
+++ b/Storage/Tape/Formats/TapePRG.cpp
@@ -61,7 +61,7 @@ PRG::PRG(const char *file_name) :
 		throw ErrorBadFormat;
 
 	load_address_ = fgetc16le();
-	length_ = (uint16_t)(file_stats_.st_size - 2);
+	length_ = static_cast<uint16_t>(file_stats_.st_size - 2);
 
 	if (load_address_ + length_ >= 65536)
 		throw ErrorBadFormat;
diff --git a/Storage/Tape/Formats/TapeUEF.cpp b/Storage/Tape/Formats/TapeUEF.cpp
index 742cfdaf6..761ad5c1d 100644
--- a/Storage/Tape/Formats/TapeUEF.cpp
+++ b/Storage/Tape/Formats/TapeUEF.cpp
@@ -105,7 +105,7 @@ void UEF::virtual_reset() {
 #pragma mark - Chunk navigator
 
 bool UEF::get_next_chunk(UEF::Chunk &result) {
-	uint16_t chunk_id = (uint16_t)gzget16(file_);
+	uint16_t chunk_id = static_cast<uint16_t>(gzget16(file_));
 	uint32_t chunk_length = (uint32_t)gzget32(file_);
 	z_off_t start_of_next_chunk = gztell(file_) + chunk_length;
 
diff --git a/Storage/Tape/Parsers/Commodore.cpp b/Storage/Tape/Parsers/Commodore.cpp
index f6551fe70..20afa879a 100644
--- a/Storage/Tape/Parsers/Commodore.cpp
+++ b/Storage/Tape/Parsers/Commodore.cpp
@@ -105,8 +105,8 @@ std::unique_ptr<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
 	// parse if this is not pure data
 	if(header->type != Header::DataBlock)
 	{
-		header->starting_address	= (uint16_t)(header->data[0] | (header->data[1] << 8));
-		header->ending_address		= (uint16_t)(header->data[2] | (header->data[3] << 8));
+		header->starting_address	= static_cast<uint16_t>(header->data[0] | (header->data[1] << 8));
+		header->ending_address		= static_cast<uint16_t>(header->data[2] | (header->data[3] << 8));
 
 		for(size_t c = 0; c < 16; c++)
 		{