diff --git a/Components/1770/1770.cpp b/Components/1770/1770.cpp index c30ba1ae9..f71756601 100644 --- a/Components/1770/1770.cpp +++ b/Components/1770/1770.cpp @@ -26,7 +26,7 @@ WD1770::Status::Status() : WD1770::WD1770(Personality p) : Storage::Disk::MFMController(8000000), - interesting_event_mask_((int)Event1770::Command), + interesting_event_mask_(static_cast(Event1770::Command)), resume_point_(0), delay_time_(0), index_hole_count_target_(-1), @@ -34,7 +34,7 @@ WD1770::WD1770(Personality p) : personality_(p), head_is_loaded_(false) { set_is_double_density(false); - posit_event((int)Event1770::Command); + posit_event(static_cast(Event1770::Command)); } void WD1770::set_register(int address, uint8_t value) { @@ -47,7 +47,7 @@ void WD1770::set_register(int address, uint8_t value) { }); } else { command_ = value; - posit_event((int)Event1770::Command); + posit_event(static_cast(Event1770::Command)); } } break; @@ -115,24 +115,24 @@ void WD1770::run_for(const Cycles cycles) { Storage::Disk::Controller::run_for(cycles); if(delay_time_) { - unsigned int number_of_cycles = (unsigned int)cycles.as_int(); + unsigned int number_of_cycles = static_cast(cycles.as_int()); if(delay_time_ <= number_of_cycles) { delay_time_ = 0; - posit_event((int)Event1770::Timer); + posit_event(static_cast(Event1770::Timer)); } else { delay_time_ -= number_of_cycles; } } } -#define WAIT_FOR_EVENT(mask) resume_point_ = __LINE__; interesting_event_mask_ = (int)mask; return; case __LINE__: +#define WAIT_FOR_EVENT(mask) resume_point_ = __LINE__; interesting_event_mask_ = static_cast(mask); return; case __LINE__: #define WAIT_FOR_TIME(ms) resume_point_ = __LINE__; delay_time_ = ms * 8000; WAIT_FOR_EVENT(Event1770::Timer); -#define WAIT_FOR_BYTES(count) resume_point_ = __LINE__; distance_into_section_ = 0; WAIT_FOR_EVENT(Event::Token); if(get_latest_token().type == Token::Byte) distance_into_section_++; if(distance_into_section_ < count) { interesting_event_mask_ = (int)Event::Token; return; } +#define WAIT_FOR_BYTES(count) resume_point_ = __LINE__; distance_into_section_ = 0; WAIT_FOR_EVENT(Event::Token); if(get_latest_token().type == Token::Byte) distance_into_section_++; if(distance_into_section_ < count) { interesting_event_mask_ = static_cast(Event::Token); return; } #define BEGIN_SECTION() switch(resume_point_) { default: #define END_SECTION() 0; } #define READ_ID() \ - if(new_event_type == (int)Event::Token) { \ + if(new_event_type == static_cast(Event::Token)) { \ if(!distance_into_section_ && get_latest_token().type == Token::ID) {set_data_mode(DataMode::Reading); distance_into_section_++; } \ else if(distance_into_section_ && distance_into_section_ < 7 && get_latest_token().type == Token::Byte) { \ header_[distance_into_section_ - 1] = get_latest_token().byte_value; \ @@ -169,10 +169,10 @@ void WD1770::run_for(const Cycles cycles) { // +--------+----------+-------------------------+ void WD1770::posit_event(int new_event_type) { - if(new_event_type == (int)Event::IndexHole) { + if(new_event_type == static_cast(Event::IndexHole)) { index_hole_count_++; if(index_hole_count_target_ == index_hole_count_) { - posit_event((int)Event1770::IndexHoleTarget); + posit_event(static_cast(Event1770::IndexHoleTarget)); index_hole_count_target_ = -1; } @@ -187,7 +187,7 @@ void WD1770::posit_event(int new_event_type) { } } - if(!(interesting_event_mask_ & (int)new_event_type)) return; + if(!(interesting_event_mask_ & static_cast(new_event_type))) return; interesting_event_mask_ &= ~new_event_type; Status new_status; @@ -310,7 +310,7 @@ void WD1770::posit_event(int new_event_type) { distance_into_section_ = 0; verify_read_data: - WAIT_FOR_EVENT((int)Event::IndexHole | (int)Event::Token); + WAIT_FOR_EVENT(static_cast(Event::IndexHole) | static_cast(Event::Token)); READ_ID(); if(index_hole_count_ == 6) { @@ -394,7 +394,7 @@ void WD1770::posit_event(int new_event_type) { } type2_get_header: - WAIT_FOR_EVENT((int)Event::IndexHole | (int)Event::Token); + WAIT_FOR_EVENT(static_cast(Event::IndexHole) | static_cast(Event::Token)); READ_ID(); if(index_hole_count_ == 5) { @@ -611,8 +611,8 @@ void WD1770::posit_event(int new_event_type) { distance_into_section_ = 0; read_address_get_header: - WAIT_FOR_EVENT((int)Event::IndexHole | (int)Event::Token); - if(new_event_type == (int)Event::Token) { + WAIT_FOR_EVENT(static_cast(Event::IndexHole) | static_cast(Event::Token)); + if(new_event_type == static_cast(Event::Token)) { if(!distance_into_section_ && get_latest_token().type == Token::ID) {set_data_mode(DataMode::Reading); distance_into_section_++; } else if(distance_into_section_ && distance_into_section_ < 7 && get_latest_token().type == Token::Byte) { if(status_.data_request) { @@ -652,7 +652,7 @@ void WD1770::posit_event(int new_event_type) { index_hole_count_ = 0; read_track_read_byte: - WAIT_FOR_EVENT((int)Event::Token | (int)Event::IndexHole); + WAIT_FOR_EVENT(static_cast(Event::Token) | static_cast(Event::IndexHole)); if(index_hole_count_) { goto wait_for_command; } @@ -785,5 +785,5 @@ void WD1770::set_motor_on(bool motor_on) {} void WD1770::set_head_loaded(bool head_loaded) { head_is_loaded_ = head_loaded; - if(head_loaded) posit_event((int)Event1770::HeadLoad); + if(head_loaded) posit_event(static_cast(Event1770::HeadLoad)); } diff --git a/Components/6532/6532.hpp b/Components/6532/6532.hpp index 4b2cfdfb8..a2477c321 100644 --- a/Components/6532/6532.hpp +++ b/Components/6532/6532.hpp @@ -51,7 +51,7 @@ template class MOS6532 { case 0x04: case 0x05: case 0x06: case 0x07: if(address & 0x10) { timer_.writtenShift = timer_.activeShift = (decodedAddress - 0x04) * 3 + (decodedAddress / 0x07); // i.e. 0, 3, 6, 10 - timer_.value = ((unsigned int)value << timer_.activeShift) ; + timer_.value = (static_cast(value) << timer_.activeShift) ; timer_.interrupt_enabled = !!(address&0x08); interrupt_status_ &= ~InterruptFlag::Timer; evaluate_interrupts(); @@ -107,7 +107,7 @@ template class MOS6532 { } inline void run_for(const Cycles cycles) { - unsigned int number_of_cycles = (unsigned int)cycles.as_int(); + unsigned int number_of_cycles = static_cast(cycles.as_int()); // permit counting _to_ zero; counting _through_ zero initiates the other behaviour if(timer_.value >= number_of_cycles) { @@ -126,7 +126,7 @@ template class MOS6532 { port_{{.output_mask = 0, .output = 0}, {.output_mask = 0, .output = 0}}, a7_interrupt_({.last_port_value = 0, .enabled = false}), interrupt_line_(false), - timer_{.value = (unsigned int)((rand() & 0xff) << 10), .activeShift = 10, .writtenShift = 10, .interrupt_enabled = false} {} + timer_{.value = static_cast((rand() & 0xff) << 10), .activeShift = 10, .writtenShift = 10, .interrupt_enabled = false} {} inline void set_port_did_change(int port) { if(!port) { diff --git a/Components/6560/6560.cpp b/Components/6560/6560.cpp index 37f15eded..39907e705 100644 --- a/Components/6560/6560.cpp +++ b/Components/6560/6560.cpp @@ -98,7 +98,7 @@ static uint8_t noise_pattern[] = { #define shift(r) shift_registers_[r] = (shift_registers_[r] << 1) | (((shift_registers_[r]^0x80)&control_registers_[r]) >> 7) #define increment(r) shift_registers_[r] = (shift_registers_[r]+1)%8191 -#define update(r, m, up) counters_[r]++; if((counters_[r] >> m) == 0x80) { up(r); counters_[r] = (unsigned int)(control_registers_[r]&0x7f) << m; } +#define update(r, m, up) counters_[r]++; if((counters_[r] >> m) == 0x80) { up(r); counters_[r] = static_cast(control_registers_[r]&0x7f) << m; } // Note on slightly askew test: as far as I can make out, if the value in the register is 0x7f then what's supposed to happen // is that the 0x7f is loaded, on the next clocked cycle the Vic spots a 0x7f, pumps the output, reloads, etc. No increment // ever occurs. It's conditional. I don't really want two conditionals if I can avoid it so I'm incrementing regardless and diff --git a/Components/6560/6560.hpp b/Components/6560/6560.hpp index 8f9bbf618..2c3717910 100644 --- a/Components/6560/6560.hpp +++ b/Components/6560/6560.hpp @@ -66,7 +66,7 @@ template class MOS6560 { } void set_clock_rate(double clock_rate) { - speaker_->set_input_rate((float)(clock_rate / 4.0)); + speaker_->set_input_rate(static_cast(clock_rate / 4.0)); } std::shared_ptr get_crt() { return crt_; } @@ -128,7 +128,7 @@ template class MOS6560 { break; } - crt_->set_new_display_type((unsigned int)(timing_.cycles_per_line*4), display_type); + crt_->set_new_display_type(static_cast(timing_.cycles_per_line*4), display_type); crt_->set_visible_area(Outputs::CRT::Rect(0.05f, 0.05f, 0.9f, 0.9f)); // switch(output_mode) { @@ -141,7 +141,7 @@ template class MOS6560 { // } for(int c = 0; c < 16; c++) { - uint8_t *colour = (uint8_t *)&colours_[c]; + uint8_t *colour = reinterpret_cast(&colours_[c]); colour[0] = luminances[c]; colour[1] = chrominances[c]; } @@ -270,7 +270,7 @@ template class MOS6560 { pixel_pointer = nullptr; if(output_state_ == State::Pixels) { - pixel_pointer = (uint16_t *)crt_->allocate_write_area(260); + pixel_pointer = reinterpret_cast(crt_->allocate_write_area(260)); } } cycles_in_state_++; @@ -454,7 +454,7 @@ template class MOS6560 { uint16_t *pixel_pointer; void output_border(unsigned int number_of_cycles) { - uint16_t *colour_pointer = (uint16_t *)crt_->allocate_write_area(1); + uint16_t *colour_pointer = reinterpret_cast(crt_->allocate_write_area(1)); if(colour_pointer) *colour_pointer = registers_.borderColour; crt_->output_level(number_of_cycles); } diff --git a/Components/8272/i8272.cpp b/Components/8272/i8272.cpp index c1aa2a5d2..c6bff6ea8 100644 --- a/Components/8272/i8272.cpp +++ b/Components/8272/i8272.cpp @@ -80,7 +80,7 @@ namespace { i8272::i8272(BusHandler &bus_handler, Cycles clock_rate) : Storage::Disk::MFMController(clock_rate), bus_handler_(bus_handler) { - posit_event((int)Event8272::CommandByte); + posit_event(static_cast(Event8272::CommandByte)); } bool i8272::is_sleeping() { @@ -96,7 +96,7 @@ void i8272::run_for(Cycles cycles) { if(delay_time_ > 0) { if(cycles.as_int() >= delay_time_) { delay_time_ = 0; - posit_event((int)Event8272::Timer); + posit_event(static_cast(Event8272::Timer)); } else { delay_time_ -= cycles.as_int(); } @@ -155,7 +155,7 @@ void i8272::run_for(Cycles cycles) { // check for busy plus ready disabled if(is_executing_ && !get_drive().get_is_ready()) { - posit_event((int)Event8272::NoLongerReady); + posit_event(static_cast(Event8272::NoLongerReady)); } is_sleeping_ = !delay_time_ && !drives_seeking_ && !head_timers_running_; @@ -176,7 +176,7 @@ void i8272::set_register(int address, uint8_t value) { } else { // accumulate latest byte in the command byte sequence command_.push_back(value); - posit_event((int)Event8272::CommandByte); + posit_event(static_cast(Event8272::CommandByte)); } } @@ -185,7 +185,7 @@ uint8_t i8272::get_register(int address) { if(result_stack_.empty()) return 0xff; uint8_t result = result_stack_.back(); result_stack_.pop_back(); - if(result_stack_.empty()) posit_event((int)Event8272::ResultEmpty); + if(result_stack_.empty()) posit_event(static_cast(Event8272::ResultEmpty)); return result; } else { @@ -197,16 +197,16 @@ uint8_t i8272::get_register(int address) { #define END_SECTION() } #define MS_TO_CYCLES(x) x * 8000 -#define WAIT_FOR_EVENT(mask) resume_point_ = __LINE__; interesting_event_mask_ = (int)mask; return; case __LINE__: -#define WAIT_FOR_TIME(ms) resume_point_ = __LINE__; interesting_event_mask_ = (int)Event8272::Timer; delay_time_ = MS_TO_CYCLES(ms); is_sleeping_ = false; update_sleep_observer(); case __LINE__: if(delay_time_) return; +#define WAIT_FOR_EVENT(mask) resume_point_ = __LINE__; interesting_event_mask_ = static_cast(mask); return; case __LINE__: +#define WAIT_FOR_TIME(ms) resume_point_ = __LINE__; interesting_event_mask_ = static_cast(Event8272::Timer); delay_time_ = MS_TO_CYCLES(ms); is_sleeping_ = false; update_sleep_observer(); case __LINE__: if(delay_time_) return; #define PASTE(x, y) x##y #define CONCAT(x, y) PASTE(x, y) #define FIND_HEADER() \ set_data_mode(DataMode::Scanning); \ - CONCAT(find_header, __LINE__): WAIT_FOR_EVENT((int)Event::Token | (int)Event::IndexHole); \ - if(event_type == (int)Event::IndexHole) { index_hole_limit_--; } \ + CONCAT(find_header, __LINE__): WAIT_FOR_EVENT(static_cast(Event::Token) | static_cast(Event::IndexHole)); \ + if(event_type == static_cast(Event::IndexHole)) { index_hole_limit_--; } \ else if(get_latest_token().type == Token::ID) goto CONCAT(header_found, __LINE__); \ \ if(index_hole_limit_) goto CONCAT(find_header, __LINE__); \ @@ -214,8 +214,8 @@ uint8_t i8272::get_register(int address) { #define FIND_DATA() \ set_data_mode(DataMode::Scanning); \ - CONCAT(find_data, __LINE__): WAIT_FOR_EVENT((int)Event::Token | (int)Event::IndexHole); \ - if(event_type == (int)Event::Token) { \ + CONCAT(find_data, __LINE__): WAIT_FOR_EVENT(static_cast(Event::Token) | static_cast(Event::IndexHole)); \ + if(event_type == static_cast(Event::Token)) { \ if(get_latest_token().type == Token::Byte || get_latest_token().type == Token::Sync) goto CONCAT(find_data, __LINE__); \ } @@ -263,8 +263,8 @@ uint8_t i8272::get_register(int address) { } void i8272::posit_event(int event_type) { - if(event_type == (int)Event::IndexHole) index_hole_count_++; - if(event_type == (int)Event8272::NoLongerReady) { + if(event_type == static_cast(Event::IndexHole)) index_hole_count_++; + if(event_type == static_cast(Event8272::NoLongerReady)) { SetNotReady(); goto abort; } @@ -432,7 +432,7 @@ void i8272::posit_event(int event_type) { read_data_found_header: FIND_DATA(); ClearControlMark(); - if(event_type == (int)Event::Token) { + if(event_type == static_cast(Event::Token)) { if(get_latest_token().type != Token::Data && get_latest_token().type != Token::DeletedData) { // Something other than a data mark came next — impliedly an ID or index mark. SetMissingAddressMark(); @@ -463,24 +463,24 @@ void i8272::posit_event(int event_type) { // // TODO: consider DTL. read_data_get_byte: - WAIT_FOR_EVENT((int)Event::Token | (int)Event::IndexHole); - if(event_type == (int)Event::Token) { + WAIT_FOR_EVENT(static_cast(Event::Token) | static_cast(Event::IndexHole)); + if(event_type == static_cast(Event::Token)) { result_stack_.push_back(get_latest_token().byte_value); distance_into_section_++; SetDataRequest(); SetDataDirectionToProcessor(); - WAIT_FOR_EVENT((int)Event8272::ResultEmpty | (int)Event::Token | (int)Event::IndexHole); + WAIT_FOR_EVENT(static_cast(Event8272::ResultEmpty) | static_cast(Event::Token) | static_cast(Event::IndexHole)); } switch(event_type) { - case (int)Event8272::ResultEmpty: // The caller read the byte in time; proceed as normal. + case static_cast(Event8272::ResultEmpty): // The caller read the byte in time; proceed as normal. ResetDataRequest(); if(distance_into_section_ < (128 << size_)) goto read_data_get_byte; break; - case (int)Event::Token: // The caller hasn't read the old byte yet and a new one has arrived + case static_cast(Event::Token): // The caller hasn't read the old byte yet and a new one has arrived SetOverrun(); goto abort; break; - case (int)Event::IndexHole: + case static_cast(Event::IndexHole): SetEndOfCylinder(); goto abort; break; @@ -611,7 +611,7 @@ void i8272::posit_event(int event_type) { distance_into_section_++; SetDataRequest(); // TODO: other possible exit conditions; find a way to merge with the read_data version of this. - WAIT_FOR_EVENT((int)Event8272::ResultEmpty); + WAIT_FOR_EVENT(static_cast(Event8272::ResultEmpty)); ResetDataRequest(); if(distance_into_section_ < (128 << header_[2])) goto read_track_get_byte; @@ -648,13 +648,13 @@ void i8272::posit_event(int event_type) { expects_input_ = true; distance_into_section_ = 0; format_track_write_header: - WAIT_FOR_EVENT((int)Event::DataWritten | (int)Event::IndexHole); + WAIT_FOR_EVENT(static_cast(Event::DataWritten) | static_cast(Event::IndexHole)); switch(event_type) { - case (int)Event::IndexHole: + case static_cast(Event::IndexHole): SetOverrun(); goto abort; break; - case (int)Event::DataWritten: + case static_cast(Event::DataWritten): header_[distance_into_section_] = input_; write_byte(input_); has_input_ = false; @@ -685,8 +685,8 @@ void i8272::posit_event(int event_type) { // Otherwise, pad out to the index hole. format_track_pad: write_byte(get_is_double_density() ? 0x4e : 0xff); - WAIT_FOR_EVENT((int)Event::DataWritten | (int)Event::IndexHole); - if(event_type != (int)Event::IndexHole) goto format_track_pad; + WAIT_FOR_EVENT(static_cast(Event::DataWritten) | static_cast(Event::IndexHole)); + if(event_type != static_cast(Event::IndexHole)) goto format_track_pad; end_writing(); diff --git a/Components/8272/i8272.hpp b/Components/8272/i8272.hpp index a11f81c00..ba6cbc442 100644 --- a/Components/8272/i8272.hpp +++ b/Components/8272/i8272.hpp @@ -68,7 +68,7 @@ class i8272: public Storage::Disk::MFMController { NoLongerReady = (1 << 6) }; void posit_event(int type); - int interesting_event_mask_ = (int)Event8272::CommandByte; + int interesting_event_mask_ = static_cast(Event8272::CommandByte); int resume_point_ = 0; bool is_access_command_ = false; diff --git a/Components/AY38910/AY38910.cpp b/Components/AY38910/AY38910.cpp index 3dcde8f47..85d8d5f21 100644 --- a/Components/AY38910/AY38910.cpp +++ b/Components/AY38910/AY38910.cpp @@ -67,13 +67,13 @@ AY38910::AY38910() : float max_volume = 8192; float root_two = sqrtf(2.0f); for(int v = 0; v < 16; v++) { - volumes_[v] = (int)(max_volume / powf(root_two, (float)(v ^ 0xf))); + volumes_[v] = static_cast(max_volume / powf(root_two, static_cast(v ^ 0xf))); } volumes_[0] = 0; } void AY38910::set_clock_rate(double clock_rate) { - set_input_rate((float)clock_rate); + set_input_rate(static_cast(clock_rate)); } void AY38910::get_samples(unsigned int number_of_samples, int16_t *target) { @@ -201,7 +201,7 @@ void AY38910::set_register_value(uint8_t value) { break; case 12: - envelope_period_ = (envelope_period_ & 0xff) | (int)(value << 8); + envelope_period_ = (envelope_period_ & 0xff) | static_cast(value << 8); break; case 13: @@ -262,15 +262,15 @@ uint8_t AY38910::get_data_output() { } void AY38910::set_control_lines(ControlLines control_lines) { - switch((int)control_lines) { + switch(static_cast(control_lines)) { default: control_state_ = Inactive; break; - case (int)(BDIR | BC2 | BC1): + case static_cast(BDIR | BC2 | BC1): case BDIR: case BC1: control_state_ = LatchAddress; break; - case (int)(BC2 | BC1): control_state_ = Read; break; - case (int)(BDIR | BC2): control_state_ = Write; break; + case static_cast(BC2 | BC1): control_state_ = Read; break; + case static_cast(BDIR | BC2): control_state_ = Write; break; } update_bus(); diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index 7f2ebd9ea..01cc1c2d3 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -221,26 +221,26 @@ class CRTCBusHandler { // fetch two bytes and translate into pixels switch(mode_) { case 0: - ((uint16_t *)pixel_pointer_)[0] = mode0_output_[ram_[address]]; - ((uint16_t *)pixel_pointer_)[1] = mode0_output_[ram_[address+1]]; + reinterpret_cast(pixel_pointer_)[0] = mode0_output_[ram_[address]]; + reinterpret_cast(pixel_pointer_)[1] = mode0_output_[ram_[address+1]]; pixel_pointer_ += 4; break; case 1: - ((uint32_t *)pixel_pointer_)[0] = mode1_output_[ram_[address]]; - ((uint32_t *)pixel_pointer_)[1] = mode1_output_[ram_[address+1]]; + reinterpret_cast(pixel_pointer_)[0] = mode1_output_[ram_[address]]; + reinterpret_cast(pixel_pointer_)[1] = mode1_output_[ram_[address+1]]; pixel_pointer_ += 8; break; case 2: - ((uint64_t *)pixel_pointer_)[0] = mode2_output_[ram_[address]]; - ((uint64_t *)pixel_pointer_)[1] = mode2_output_[ram_[address+1]]; + reinterpret_cast(pixel_pointer_)[0] = mode2_output_[ram_[address]]; + reinterpret_cast(pixel_pointer_)[1] = mode2_output_[ram_[address+1]]; pixel_pointer_ += 16; break; case 3: - ((uint16_t *)pixel_pointer_)[0] = mode3_output_[ram_[address]]; - ((uint16_t *)pixel_pointer_)[1] = mode3_output_[ram_[address+1]]; + reinterpret_cast(pixel_pointer_)[0] = mode3_output_[ram_[address]]; + reinterpret_cast(pixel_pointer_)[1] = mode3_output_[ram_[address+1]]; pixel_pointer_ += 4; break; @@ -344,7 +344,7 @@ class CRTCBusHandler { private: void output_border(unsigned int length) { - uint8_t *colour_pointer = (uint8_t *)crt_->allocate_write_area(1); + uint8_t *colour_pointer = static_cast(crt_->allocate_write_area(1)); if(colour_pointer) *colour_pointer = border_; crt_->output_level(length * 16); } @@ -381,7 +381,7 @@ class CRTCBusHandler { // Mode 0: abcdefgh -> [gcea] [hdfb] for(int c = 0; c < 256; c++) { // prepare mode 0 - uint8_t *mode0_pixels = (uint8_t *)&mode0_output_[c]; + uint8_t *mode0_pixels = reinterpret_cast(&mode0_output_[c]); mode0_pixels[0] = palette_[Mode0Colour0(c)]; mode0_pixels[1] = palette_[Mode0Colour1(c)]; } @@ -390,7 +390,7 @@ class CRTCBusHandler { case 1: for(int c = 0; c < 256; c++) { // prepare mode 1 - uint8_t *mode1_pixels = (uint8_t *)&mode1_output_[c]; + uint8_t *mode1_pixels = reinterpret_cast(&mode1_output_[c]); mode1_pixels[0] = palette_[Mode1Colour0(c)]; mode1_pixels[1] = palette_[Mode1Colour1(c)]; mode1_pixels[2] = palette_[Mode1Colour2(c)]; @@ -401,7 +401,7 @@ class CRTCBusHandler { case 2: for(int c = 0; c < 256; c++) { // prepare mode 2 - uint8_t *mode2_pixels = (uint8_t *)&mode2_output_[c]; + uint8_t *mode2_pixels = reinterpret_cast(&mode2_output_[c]); mode2_pixels[0] = palette_[((c & 0x80) >> 7)]; mode2_pixels[1] = palette_[((c & 0x40) >> 6)]; mode2_pixels[2] = palette_[((c & 0x20) >> 5)]; @@ -416,7 +416,7 @@ class CRTCBusHandler { case 3: for(int c = 0; c < 256; c++) { // prepare mode 3 - uint8_t *mode3_pixels = (uint8_t *)&mode3_output_[c]; + uint8_t *mode3_pixels = reinterpret_cast(&mode3_output_[c]); mode3_pixels[0] = palette_[Mode3Colour0(c)]; mode3_pixels[1] = palette_[Mode3Colour1(c)]; } @@ -428,7 +428,7 @@ class CRTCBusHandler { switch(mode_) { case 0: { for(uint8_t c : mode0_palette_hits_[pen]) { - uint8_t *mode0_pixels = (uint8_t *)&mode0_output_[c]; + uint8_t *mode0_pixels = reinterpret_cast(&mode0_output_[c]); mode0_pixels[0] = palette_[Mode0Colour0(c)]; mode0_pixels[1] = palette_[Mode0Colour1(c)]; } @@ -436,7 +436,7 @@ class CRTCBusHandler { case 1: if(pen > 3) return; for(uint8_t c : mode1_palette_hits_[pen]) { - uint8_t *mode1_pixels = (uint8_t *)&mode1_output_[c]; + uint8_t *mode1_pixels = reinterpret_cast(&mode1_output_[c]); mode1_pixels[0] = palette_[Mode1Colour0(c)]; mode1_pixels[1] = palette_[Mode1Colour1(c)]; mode1_pixels[2] = palette_[Mode1Colour2(c)]; @@ -453,7 +453,7 @@ class CRTCBusHandler { if(pen > 3) return; // Same argument applies here as to case 1, as the unused bits aren't masked out. for(uint8_t c : mode3_palette_hits_[pen]) { - uint8_t *mode3_pixels = (uint8_t *)&mode3_output_[c]; + uint8_t *mode3_pixels = reinterpret_cast(&mode3_output_[c]); mode3_pixels[0] = palette_[Mode3Colour0(c)]; mode3_pixels[1] = palette_[Mode3Colour1(c)]; } @@ -920,7 +920,7 @@ class ConcreteMachine: // See header; provides the system ROMs. void set_rom(ROMType type, std::vector data) override final { - roms_[(int)type] = data; + roms_[static_cast(type)] = data; } void set_component_is_sleeping(void *component, bool is_sleeping) override final { diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index 92bc5c9e1..34e67e806 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -137,7 +137,7 @@ class ConcreteMachine: void setup_output(float aspect_ratio) override { bus_->tia_.reset(new TIA); bus_->speaker_.reset(new Speaker); - bus_->speaker_->set_input_rate((float)(get_clock_rate() / (double)CPUTicksPerAudioTick)); + bus_->speaker_->set_input_rate(static_cast(get_clock_rate() / static_cast(CPUTicksPerAudioTick))); bus_->tia_->get_crt()->set_delegate(this); } @@ -188,8 +188,8 @@ class ConcreteMachine: bus_->tia_->set_output_mode(TIA::OutputMode::PAL); } - bus_->speaker_->set_input_rate((float)(clock_rate / (double)CPUTicksPerAudioTick)); - bus_->speaker_->set_high_frequency_cut_off((float)(clock_rate / ((double)CPUTicksPerAudioTick * 2.0))); + bus_->speaker_->set_input_rate(static_cast(clock_rate / static_cast(CPUTicksPerAudioTick))); + bus_->speaker_->set_high_frequency_cut_off(static_cast(clock_rate / (static_cast(CPUTicksPerAudioTick) * 2.0))); set_clock_rate(clock_rate); } } 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(*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/Atari2600/TIA.cpp b/Machines/Atari2600/TIA.cpp index 385aec79a..885ab69bf 100644 --- a/Machines/Atari2600/TIA.cpp +++ b/Machines/Atari2600/TIA.cpp @@ -44,12 +44,12 @@ TIA::TIA(bool create_crt) : } for(int c = 0; c < 64; c++) { - bool has_playfield = c & (int)(CollisionType::Playfield); - bool has_ball = c & (int)(CollisionType::Ball); - bool has_player0 = c & (int)(CollisionType::Player0); - bool has_player1 = c & (int)(CollisionType::Player1); - bool has_missile0 = c & (int)(CollisionType::Missile0); - bool has_missile1 = c & (int)(CollisionType::Missile1); + bool has_playfield = c & static_cast(CollisionType::Playfield); + bool has_ball = c & static_cast(CollisionType::Ball); + bool has_player0 = c & static_cast(CollisionType::Player0); + bool has_player1 = c & static_cast(CollisionType::Player1); + bool has_missile0 = c & static_cast(CollisionType::Missile0); + bool has_missile1 = c & static_cast(CollisionType::Missile1); uint8_t collision_registers[8]; collision_registers[0] = ((has_missile0 && has_player1) ? 0x80 : 0x00) | ((has_missile0 && has_player0) ? 0x40 : 0x00); @@ -71,51 +71,51 @@ TIA::TIA(bool create_crt) : (collision_registers[7] << 8); // all priority modes show the background if nothing else is present - colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::OnTop][c] = static_cast(ColourIndex::Background); + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::Standard)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreLeft)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreRight)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::OnTop)][c] = static_cast(ColourIndex::Background); // test 1 for standard priority: if there is a playfield or ball pixel, plot that colour if(has_playfield || has_ball) { - colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] = static_cast(ColourIndex::PlayfieldBall); + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::Standard)][c] = static_cast(ColourIndex::PlayfieldBall); } // test 1 for score mode: if there is a ball pixel, plot that colour if(has_ball) { - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = static_cast(ColourIndex::PlayfieldBall); + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreLeft)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreRight)][c] = static_cast(ColourIndex::PlayfieldBall); } // test 1 for on-top mode, test 2 for everbody else: if there is a player 1 or missile 1 pixel, plot that colour if(has_player1 || has_missile1) { - colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::OnTop][c] = static_cast(ColourIndex::PlayerMissile1); + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::Standard)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreLeft)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreRight)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::OnTop)][c] = static_cast(ColourIndex::PlayerMissile1); } // in the right-hand side of score mode, the playfield has the same priority as player 1 if(has_playfield) { - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = static_cast(ColourIndex::PlayerMissile1); + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreRight)][c] = static_cast(ColourIndex::PlayerMissile1); } // next test for everybody: if there is a player 0 or missile 0 pixel, plot that colour instead if(has_player0 || has_missile0) { - colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = - colour_mask_by_mode_collision_flags_[(int)ColourMode::OnTop][c] = static_cast(ColourIndex::PlayerMissile0); + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::Standard)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreLeft)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreRight)][c] = + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::OnTop)][c] = static_cast(ColourIndex::PlayerMissile0); } // if this is the left-hand side of score mode, the playfield has the same priority as player 0 if(has_playfield) { - colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = static_cast(ColourIndex::PlayerMissile0); + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreLeft)][c] = static_cast(ColourIndex::PlayerMissile0); } // a final test for 'on top' priority mode: if the playfield or ball are visible, prefer that colour to all others if(has_playfield || has_ball) { - colour_mask_by_mode_collision_flags_[(int)ColourMode::OnTop][c] = static_cast(ColourIndex::PlayfieldBall); + colour_mask_by_mode_collision_flags_[static_cast(ColourMode::OnTop)][c] = static_cast(ColourIndex::PlayfieldBall); } } } @@ -162,7 +162,7 @@ void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode) { // cycles_per_line * 2 cycles of information from one sync edge to the next crt_->set_new_display_type(cycles_per_line * 2 - 1, display_type); -/* speaker_->set_input_rate((float)(get_clock_rate() / 38.0));*/ +/* speaker_->set_input_rate(static_cast(get_clock_rate() / 38.0));*/ } void TIA::run_for(const Cycles cycles) { @@ -203,7 +203,7 @@ int TIA::get_cycles_until_horizontal_blank(const Cycles from_offset) { } void TIA::set_background_colour(uint8_t colour) { - colour_palette_[(int)ColourIndex::Background] = colour; + colour_palette_[static_cast(ColourIndex::Background)] = colour; } void TIA::set_playfield(uint16_t offset, uint8_t value) { @@ -243,7 +243,7 @@ void TIA::set_playfield_control_and_ball_size(uint8_t value) { } void TIA::set_playfield_ball_colour(uint8_t colour) { - colour_palette_[(int)ColourIndex::PlayfieldBall] = colour; + colour_palette_[static_cast(ColourIndex::PlayfieldBall)] = colour; } void TIA::set_player_number_and_size(int player, uint8_t value) { @@ -305,7 +305,7 @@ void TIA::set_player_motion(int player, uint8_t motion) { void TIA::set_player_missile_colour(int player, uint8_t colour) { assert(player >= 0 && player < 2); - colour_palette_[(int)ColourIndex::PlayerMissile0 + player] = colour; + colour_palette_[static_cast(ColourIndex::PlayerMissile0) + player] = colour; } void TIA::set_missile_enable(int missile, bool enabled) { @@ -412,11 +412,11 @@ void TIA::output_for_cycles(int number_of_cycles) { #define Period(function, target) \ if(output_cursor < target) { \ if(horizontal_counter_ <= target) { \ - if(crt_) crt_->function((unsigned int)((horizontal_counter_ - output_cursor) * 2)); \ + if(crt_) crt_->function(static_cast((horizontal_counter_ - output_cursor) * 2)); \ horizontal_counter_ %= cycles_per_line; \ return; \ } else { \ - if(crt_) crt_->function((unsigned int)((target - output_cursor) * 2)); \ + if(crt_) crt_->function(static_cast((target - output_cursor) * 2)); \ output_cursor = target; \ } \ } @@ -442,12 +442,12 @@ void TIA::output_for_cycles(int number_of_cycles) { if(output_mode_ & blank_flag) { if(pixel_target_) { output_pixels(pixels_start_location_, output_cursor); - if(crt_) crt_->output_data((unsigned int)(output_cursor - pixels_start_location_) * 2, 2); + if(crt_) crt_->output_data(static_cast(output_cursor - pixels_start_location_) * 2, 2); pixel_target_ = nullptr; pixels_start_location_ = 0; } int duration = std::min(228, horizontal_counter_) - output_cursor; - if(crt_) crt_->output_blank((unsigned int)(duration * 2)); + if(crt_) crt_->output_blank(static_cast(duration * 2)); } else { if(!pixels_start_location_ && crt_) { pixels_start_location_ = output_cursor; @@ -464,7 +464,7 @@ void TIA::output_for_cycles(int number_of_cycles) { } if(horizontal_counter_ == cycles_per_line && crt_) { - crt_->output_data((unsigned int)(output_cursor - pixels_start_location_) * 2, 2); + crt_->output_data(static_cast(output_cursor - pixels_start_location_) * 2, 2); pixel_target_ = nullptr; pixels_start_location_ = 0; } @@ -490,18 +490,18 @@ void TIA::output_pixels(int start, int end) { if(playfield_priority_ == PlayfieldPriority::Score) { while(start < end && start < first_pixel_cycle + 80) { uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle]; - pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][buffer_value]]; + pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreLeft)][buffer_value]]; start++; target_position++; } while(start < end) { uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle]; - pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][buffer_value]]; + pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[static_cast(ColourMode::ScoreRight)][buffer_value]]; start++; target_position++; } } else { - int table_index = (int)((playfield_priority_ == PlayfieldPriority::Standard) ? ColourMode::Standard : ColourMode::OnTop); + int table_index = static_cast((playfield_priority_ == PlayfieldPriority::Standard) ? ColourMode::Standard : ColourMode::OnTop); while(start < end) { uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle]; pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[table_index][buffer_value]]; @@ -553,7 +553,7 @@ void TIA::draw_playfield(int start, int end) { while(aligned_position < end) { int offset = (aligned_position - first_pixel_cycle) >> 2; uint32_t value = ((background_[(offset/20)&background_half_mask_] >> (offset%20))&1) * 0x01010101; - *(uint32_t *)&collision_buffer_[aligned_position - first_pixel_cycle] |= value; + *reinterpret_cast(&collision_buffer_[aligned_position - first_pixel_cycle]) |= value; aligned_position += 4; } } diff --git a/Machines/Commodore/1540/Implementation/C1540.cpp b/Machines/Commodore/1540/Implementation/C1540.cpp index 08379641e..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(shift_register_)); bit_window_offset_ = 0; if(drive_VIA_port_handler_.get_should_set_overflow()) { m6502_.set_overflow_line(true); @@ -136,7 +136,7 @@ void MachineBase::drive_via_did_step_head(void *driveVIA, int direction) { } void MachineBase::drive_via_did_set_data_density(void *driveVIA, int density) { - set_expected_bit_length(Storage::Encodings::CommodoreGCR::length_of_a_bit_in_time_zone((unsigned int)density)); + set_expected_bit_length(Storage::Encodings::CommodoreGCR::length_of_a_bit_in_time_zone(static_cast(density))); } #pragma mark - SerialPortVIA diff --git a/Machines/Commodore/SerialBus.cpp b/Machines/Commodore/SerialBus.cpp index 8ac9e3614..6ef4bef84 100644 --- a/Machines/Commodore/SerialBus.cpp +++ b/Machines/Commodore/SerialBus.cpp @@ -27,12 +27,12 @@ void ::Commodore::Serial::AttachPortAndBus(std::shared_ptr port, std::shar void Bus::add_port(std::shared_ptr port) { ports_.push_back(port); - for(int line = (int)ServiceRequest; line <= (int)Reset; line++) { + for(int line = static_cast(ServiceRequest); line <= static_cast(Reset); line++) { // the addition of a new device may change the line output... - set_line_output_did_change((Line)line); + set_line_output_did_change(static_cast(line)); // ... but the new device will need to be told the current state regardless - port->set_input((Line)line, line_levels_[line]); + port->set_input(static_cast(line), line_levels_[line]); } } 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 rom_image = media.cartridges.front()->get_segments().front().data; - rom_length_ = (uint16_t)(rom_image.size()); + rom_length_ = static_cast(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 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(user_basic_memory_[0xb2]) | static_cast(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(m6502_.get_value_of_register(CPU::MOS6502::Register::X)); if(x == 0xe) { Storage::Tape::Commodore::Parser parser; std::unique_ptr 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(user_basic_memory_[0xc1] | (user_basic_memory_[0xc2] << 8)); + end_address = static_cast(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(m6502_.get_value_of_register(CPU::MOS6502::Register::Flags)); + flags &= ~static_cast((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 cb39fc39f..edde9f14e 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -52,7 +52,7 @@ class ConcreteMachine: break; } - memcpy(target, &data[0], std::min((size_t)16384, data.size())); + memcpy(target, &data[0], std::min(static_cast(16384), data.size())); } void set_key_state(uint16_t key, bool isPressed) override final { @@ -111,7 +111,7 @@ class ConcreteMachine: ROMSlot slot = ROMSlot12; for(std::shared_ptr cartridge : media.cartridges) { set_rom(slot, cartridge->get_segments().front().data, false); - slot = (ROMSlot)(((int)slot + 1)&15); + slot = static_cast((static_cast(slot) + 1)&15); } return !media.tapes.empty() || !media.disks.empty() || !media.cartridges.empty(); @@ -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(m6502_.get_value_of_register(CPU::MOS6502::Register::X)); if(address == 0xf0a8) { if(!ram_[0x247] && service_call == 14) { tape_.set_delegate(nullptr); @@ -310,10 +310,10 @@ class ConcreteMachine: } } - cycles_since_display_update_ += Cycles((int)cycles); - cycles_since_audio_update_ += Cycles((int)cycles); + cycles_since_display_update_ += Cycles(static_cast(cycles)); + cycles_since_audio_update_ += Cycles(static_cast(cycles)); if(cycles_since_audio_update_ > Cycles(16384)) update_audio(); - tape_.run_for(Cycles((int)cycles)); + tape_.run_for(Cycles(static_cast(cycles))); cycles_until_display_interrupt_ -= cycles; if(cycles_until_display_interrupt_ < 0) { @@ -322,8 +322,8 @@ class ConcreteMachine: queue_next_display_interrupt(); } - if(typer_) typer_->run_for(Cycles((int)cycles)); - if(plus3_) plus3_->run_for(Cycles(4*(int)cycles)); + if(typer_) typer_->run_for(Cycles(static_cast(cycles))); + if(plus3_) plus3_->run_for(Cycles(4*static_cast(cycles))); if(shift_restart_counter_) { shift_restart_counter_ -= cycles; if(shift_restart_counter_ <= 0) { @@ -334,7 +334,7 @@ class ConcreteMachine: } } - return Cycles((int)cycles); + return Cycles(static_cast(cycles)); } forceinline void flush() { 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((counter_ / (divider_+1)) * 8192); target++; counter_ = (counter_ + 1) % ((divider_+1) * 2); } diff --git a/Machines/Electron/Tape.cpp b/Machines/Electron/Tape.cpp index 15d15be41..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((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((value << 2) | 1); output_.bits_remaining_until_empty = 9; } uint8_t Tape::get_data_register() { - return (uint8_t)(data_register_ >> 2); + return static_cast(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(value)); } void Tape::run_for(const Cycles cycles) { @@ -80,7 +80,7 @@ void Tape::run_for(const Cycles cycles) { TapePlayer::run_for(cycles); } } else { - output_.cycles_into_pulse += (unsigned int)cycles.as_int(); + output_.cycles_into_pulse += static_cast(cycles.as_int()); while(output_.cycles_into_pulse > 1664) { // 1664 = the closest you can get to 1200 baud if you're looking for something output_.cycles_into_pulse -= 1664; // that divides the 125,000Hz clock that the sound divider runs off. push_tape_bit(1); diff --git a/Machines/Electron/Video.cpp b/Machines/Electron/Video.cpp index faa1d410e..d5f01194e 100644 --- a/Machines/Electron/Video.cpp +++ b/Machines/Electron/Video.cpp @@ -86,7 +86,7 @@ void VideoOutput::start_pixel_line() { } void VideoOutput::end_pixel_line() { - if(current_output_target_) crt_->output_data((unsigned int)((current_output_target_ - initial_output_target_) * current_output_divider_), current_output_divider_); + if(current_output_target_) crt_->output_data(static_cast((current_output_target_ - initial_output_target_) * current_output_divider_), current_output_divider_); current_character_row_++; } @@ -104,7 +104,7 @@ void VideoOutput::output_pixels(unsigned int number_of_cycles) { } if(!initial_output_target_ || divider != current_output_divider_) { - if(current_output_target_) crt_->output_data((unsigned int)((current_output_target_ - initial_output_target_) * current_output_divider_), current_output_divider_); + if(current_output_target_) crt_->output_data(static_cast((current_output_target_ - initial_output_target_) * current_output_divider_), current_output_divider_); current_output_divider_ = divider; initial_output_target_ = current_output_target_ = crt_->allocate_write_area(640 / current_output_divider_, 4); } @@ -121,7 +121,7 @@ void VideoOutput::output_pixels(unsigned int number_of_cycles) { if(initial_output_target_) { while(number_of_cycles--) { get_pixel(); - *(uint32_t *)current_output_target_ = palette_tables_.eighty1bpp[last_pixel_byte_]; + *reinterpret_cast(current_output_target_) = palette_tables_.eighty1bpp[last_pixel_byte_]; current_output_target_ += 4; current_pixel_column_++; } @@ -132,7 +132,7 @@ void VideoOutput::output_pixels(unsigned int number_of_cycles) { if(initial_output_target_) { while(number_of_cycles--) { get_pixel(); - *(uint16_t *)current_output_target_ = palette_tables_.eighty2bpp[last_pixel_byte_]; + *reinterpret_cast(current_output_target_) = palette_tables_.eighty2bpp[last_pixel_byte_]; current_output_target_ += 2; current_pixel_column_++; } @@ -154,7 +154,7 @@ void VideoOutput::output_pixels(unsigned int number_of_cycles) { if(initial_output_target_) { if(current_pixel_column_&1) { last_pixel_byte_ <<= 4; - *(uint16_t *)current_output_target_ = palette_tables_.forty1bpp[last_pixel_byte_]; + *reinterpret_cast(current_output_target_) = palette_tables_.forty1bpp[last_pixel_byte_]; current_output_target_ += 2; number_of_cycles--; @@ -162,11 +162,11 @@ void VideoOutput::output_pixels(unsigned int number_of_cycles) { } while(number_of_cycles > 1) { get_pixel(); - *(uint16_t *)current_output_target_ = palette_tables_.forty1bpp[last_pixel_byte_]; + *reinterpret_cast(current_output_target_) = palette_tables_.forty1bpp[last_pixel_byte_]; current_output_target_ += 2; last_pixel_byte_ <<= 4; - *(uint16_t *)current_output_target_ = palette_tables_.forty1bpp[last_pixel_byte_]; + *reinterpret_cast(current_output_target_) = palette_tables_.forty1bpp[last_pixel_byte_]; current_output_target_ += 2; number_of_cycles -= 2; @@ -174,7 +174,7 @@ void VideoOutput::output_pixels(unsigned int number_of_cycles) { } if(number_of_cycles) { get_pixel(); - *(uint16_t *)current_output_target_ = palette_tables_.forty1bpp[last_pixel_byte_]; + *reinterpret_cast(current_output_target_) = palette_tables_.forty1bpp[last_pixel_byte_]; current_output_target_ += 2; current_pixel_column_++; } @@ -223,16 +223,16 @@ void VideoOutput::run_for(const Cycles cycles) { while(number_of_cycles) { int draw_action_length = screen_map_[screen_map_pointer_].length; int time_left_in_action = std::min(number_of_cycles, draw_action_length - cycles_into_draw_action_); - if(screen_map_[screen_map_pointer_].type == DrawAction::Pixels) output_pixels((unsigned int)time_left_in_action); + if(screen_map_[screen_map_pointer_].type == DrawAction::Pixels) output_pixels(static_cast(time_left_in_action)); number_of_cycles -= time_left_in_action; cycles_into_draw_action_ += time_left_in_action; if(cycles_into_draw_action_ == draw_action_length) { switch(screen_map_[screen_map_pointer_].type) { - case DrawAction::Sync: crt_->output_sync((unsigned int)(draw_action_length * crt_cycles_multiplier)); break; - case DrawAction::ColourBurst: crt_->output_default_colour_burst((unsigned int)(draw_action_length * crt_cycles_multiplier)); break; - case DrawAction::Blank: crt_->output_blank((unsigned int)(draw_action_length * crt_cycles_multiplier)); break; - case DrawAction::Pixels: end_pixel_line(); break; + case DrawAction::Sync: crt_->output_sync(static_cast(draw_action_length * crt_cycles_multiplier)); break; + case DrawAction::ColourBurst: crt_->output_default_colour_burst(static_cast(draw_action_length * crt_cycles_multiplier)); break; + case DrawAction::Blank: crt_->output_blank(static_cast(draw_action_length * crt_cycles_multiplier)); break; + case DrawAction::Pixels: end_pixel_line(); break; } screen_map_pointer_ = (screen_map_pointer_ + 1) % screen_map_.size(); cycles_into_draw_action_ = 0; @@ -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((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((value & 0x3f) << 9); if(!start_screen_address_) start_screen_address_ |= 0x8000; break; case 0x07: { @@ -292,17 +292,17 @@ 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((a << 4) | (b)) for(int byte = 0; byte < 256; byte++) { - uint8_t *target = (uint8_t *)&palette_tables_.forty1bpp[byte]; + uint8_t *target = reinterpret_cast(&palette_tables_.forty1bpp[byte]); target[0] = pack(palette_[(byte&0x80) >> 4], palette_[(byte&0x40) >> 3]); target[1] = pack(palette_[(byte&0x20) >> 2], palette_[(byte&0x10) >> 1]); - target = (uint8_t *)&palette_tables_.eighty2bpp[byte]; + target = reinterpret_cast(&palette_tables_.eighty2bpp[byte]); target[0] = pack(palette_[((byte&0x80) >> 4) | ((byte&0x08) >> 2)], palette_[((byte&0x40) >> 3) | ((byte&0x04) >> 1)]); target[1] = pack(palette_[((byte&0x20) >> 2) | ((byte&0x02) >> 0)], palette_[((byte&0x10) >> 1) | ((byte&0x01) << 1)]); - target = (uint8_t *)&palette_tables_.eighty1bpp[byte]; + target = reinterpret_cast(&palette_tables_.eighty1bpp[byte]); target[0] = pack(palette_[(byte&0x80) >> 4], palette_[(byte&0x40) >> 3]); target[1] = pack(palette_[(byte&0x20) >> 2], palette_[(byte&0x10) >> 1]); target[2] = pack(palette_[(byte&0x08) >> 0], palette_[(byte&0x04) << 1]); @@ -376,9 +376,9 @@ unsigned int VideoOutput::get_cycles_until_next_ram_availability(int from_time) int output_position_line = graphics_line(output_position_); int implied_row = current_character_row_ + (current_line - output_position_line) % 10; if(implied_row < 8) - result += (unsigned int)(80 - current_column); + result += static_cast(80 - current_column); } - else result += (unsigned int)(80 - current_column); + else result += static_cast(80 - current_column); } } return result; 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(parser_.get_next_byte(get_tape(), use_fast_encoding)); } private: diff --git a/Machines/Oric/Video.cpp b/Machines/Oric/Video.cpp index e29012803..f5f5d41f1 100644 --- a/Machines/Oric/Video.cpp +++ b/Machines/Oric/Video.cpp @@ -56,16 +56,16 @@ void VideoOutput::set_output_device(Outputs::CRT::OutputDevice output_device) { void VideoOutput::set_colour_rom(const std::vector &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((static_cast(rom[index]) << 8) | static_cast(rom[index+1])); rom_value = (rom_value & 0xff00) | ((rom_value >> 4)&0x000f) | ((rom_value << 4)&0x00f0); colour_forms_[c] = rom_value; } // check for big endianness and byte swap if required uint16_t test_value = 0x0001; - if(*(uint8_t *)&test_value != 0x01) { + if(*reinterpret_cast(&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((colour_forms_[c] >> 8) | (colour_forms_[c] << 8)); } } } @@ -89,7 +89,7 @@ void VideoOutput::run_for(const Cycles cycles) { if(counter_ >= v_sync_start_position_ && counter_ < v_sync_end_position_) { // this is a sync line cycles_run_for = v_sync_end_position_ - counter_; - clamp(crt_->output_sync((unsigned int)(v_sync_end_position_ - v_sync_start_position_) * 6)); + clamp(crt_->output_sync(static_cast(v_sync_end_position_ - v_sync_start_position_) * 6)); } else if(counter_ < 224*64 && h_counter < 40) { // this is a pixel line if(!h_counter) { @@ -97,7 +97,7 @@ void VideoOutput::run_for(const Cycles cycles) { paper_ = 0x0; use_alternative_character_set_ = use_double_height_characters_ = blink_text_ = false; set_character_set_base_address(); - pixel_target_ = (uint16_t *)crt_->allocate_write_area(240); + pixel_target_ = reinterpret_cast(crt_->allocate_write_area(240)); if(!counter_) { frame_counter_++; @@ -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(paper_ ^ inverse_mask); + colours[1] = static_cast(ink_ ^ inverse_mask); } else { colours[0] = colour_forms_[paper_ ^ inverse_mask]; colours[1] = colour_forms_[ink_ ^ inverse_mask]; @@ -202,7 +202,7 @@ void VideoOutput::run_for(const Cycles cycles) { cycles_run_for = 48 - h_counter; clamp( int period = (counter_ < 224*64) ? 8 : 48; - crt_->output_blank((unsigned int)period * 6); + crt_->output_blank(static_cast(period) * 6); ); } else if(h_counter < 54) { cycles_run_for = 54 - h_counter; diff --git a/Machines/Utility/MemoryFuzzer.cpp b/Machines/Utility/MemoryFuzzer.cpp index 35ddf5e6a..c83d4783c 100644 --- a/Machines/Utility/MemoryFuzzer.cpp +++ b/Machines/Utility/MemoryFuzzer.cpp @@ -11,7 +11,7 @@ #include void Memory::Fuzz(uint8_t *buffer, size_t size) { - unsigned int divider = ((unsigned int)RAND_MAX + 1) / 256; + unsigned int divider = (static_cast(RAND_MAX) + 1) / 256; unsigned int shift = 1, value = 1; while(value < divider) { value <<= 1; diff --git a/Machines/ZX8081/Video.cpp b/Machines/ZX8081/Video.cpp index c15d5d0c2..89c73fc9e 100644 --- a/Machines/ZX8081/Video.cpp +++ b/Machines/ZX8081/Video.cpp @@ -31,7 +31,7 @@ Video::Video() : void Video::run_for(const HalfCycles half_cycles) { // Just keep a running total of the amount of time that remains owed to the CRT. - cycles_since_update_ += (unsigned int)half_cycles.as_int(); + cycles_since_update_ += static_cast(half_cycles.as_int()); } void Video::flush() { @@ -48,7 +48,7 @@ void Video::flush(bool next_sync) { if(line_data_) { // If there is output data queued, output it either if it's being interrupted by // sync, or if we're past its end anyway. Otherwise let it be. - unsigned int data_length = (unsigned int)(line_data_pointer_ - line_data_); + unsigned int data_length = static_cast(line_data_pointer_ - line_data_); if(data_length < cycles_since_update_ || next_sync) { unsigned int output_length = std::min(data_length, cycles_since_update_); crt_->output_data(output_length, 1); @@ -58,7 +58,7 @@ void Video::flush(bool next_sync) { } // Any pending pixels being dealt with, pad with the white level. - uint8_t *colour_pointer = (uint8_t *)crt_->allocate_write_area(1); + uint8_t *colour_pointer = static_cast(crt_->allocate_write_area(1)); if(colour_pointer) *colour_pointer = 0xff; crt_->output_level(cycles_since_update_); } diff --git a/Machines/ZX8081/ZX8081.cpp b/Machines/ZX8081/ZX8081.cpp index 4679db934..dcedbdeeb 100644 --- a/Machines/ZX8081/ZX8081.cpp +++ b/Machines/ZX8081/ZX8081.cpp @@ -135,7 +135,7 @@ template class ConcreteMachine: z80_.set_interrupt_line(false); } if(has_latched_video_byte_) { - size_t char_address = (size_t)((address & 0xfe00) | ((latched_video_byte_ & 0x3f) << 3) | line_counter_); + size_t char_address = static_cast((address & 0xfe00) | ((latched_video_byte_ & 0x3f) << 3) | line_counter_); uint8_t mask = (latched_video_byte_ & 0x80) ? 0x00 : 0xff; if(char_address < ram_base_) { latched_video_byte_ = rom_[char_address & rom_mask_] ^ mask; @@ -155,7 +155,7 @@ template 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(next_byte); *cycle.value = 0x00; z80_.set_value_of_register(CPU::Z80::Register::ProgramCounter, tape_return_address_ - 1); @@ -249,7 +249,7 @@ template 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(rom_.size() - 1); switch(target.zx8081.memory_model) { case StaticAnalyser::ZX8081MemoryModel::Unexpanded: @@ -301,9 +301,9 @@ template 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(~key); else - key_states_[key >> 8] |= (uint8_t)key; + key_states_[key >> 8] |= static_cast(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(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(shift_value << 1) ^ exclusive_or; } - xor_table[c] = (uint16_t)shift_value; + xor_table[c] = static_cast(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((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"> (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(offset_of_first_sample * 256.0f) & 63; } else { colour_burst_phase_adjustment_ = 0xff; } @@ -120,17 +120,17 @@ Flywheel::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested, return horizontal_flywheel_->get_next_event_in_period(hsync_is_requested, cycles_to_run_for, cycles_advanced); } -#define output_x1() (*(uint16_t *)&next_output_run[OutputVertexOffsetOfHorizontal + 0]) -#define output_x2() (*(uint16_t *)&next_output_run[OutputVertexOffsetOfHorizontal + 2]) -#define output_position_y() (*(uint16_t *)&next_output_run[OutputVertexOffsetOfVertical + 0]) -#define output_tex_y() (*(uint16_t *)&next_output_run[OutputVertexOffsetOfVertical + 2]) +#define output_x1() (*reinterpret_cast(&next_output_run[OutputVertexOffsetOfHorizontal + 0])) +#define output_x2() (*reinterpret_cast(&next_output_run[OutputVertexOffsetOfHorizontal + 2])) +#define output_position_y() (*reinterpret_cast(&next_output_run[OutputVertexOffsetOfVertical + 0])) +#define output_tex_y() (*reinterpret_cast(&next_output_run[OutputVertexOffsetOfVertical + 2])) -#define source_input_position_x1() (*(uint16_t *)&next_run[SourceVertexOffsetOfInputStart + 0]) -#define source_input_position_y() (*(uint16_t *)&next_run[SourceVertexOffsetOfInputStart + 2]) -#define source_input_position_x2() (*(uint16_t *)&next_run[SourceVertexOffsetOfEnds + 0]) -#define source_output_position_x1() (*(uint16_t *)&next_run[SourceVertexOffsetOfOutputStart + 0]) -#define source_output_position_y() (*(uint16_t *)&next_run[SourceVertexOffsetOfOutputStart + 2]) -#define source_output_position_x2() (*(uint16_t *)&next_run[SourceVertexOffsetOfEnds + 2]) +#define source_input_position_x1() (*reinterpret_cast(&next_run[SourceVertexOffsetOfInputStart + 0])) +#define source_input_position_y() (*reinterpret_cast(&next_run[SourceVertexOffsetOfInputStart + 2])) +#define source_input_position_x2() (*reinterpret_cast(&next_run[SourceVertexOffsetOfEnds + 0])) +#define source_output_position_x1() (*reinterpret_cast(&next_run[SourceVertexOffsetOfOutputStart + 0])) +#define source_output_position_y() (*reinterpret_cast(&next_run[SourceVertexOffsetOfOutputStart + 2])) +#define source_output_position_x2() (*reinterpret_cast(&next_run[SourceVertexOffsetOfEnds + 2])) #define source_phase() next_run[SourceVertexOffsetOfPhaseTimeAndAmplitude + 0] #define source_amplitude() next_run[SourceVertexOffsetOfPhaseTimeAndAmplitude + 1] @@ -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(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(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(horizontal_flywheel_->get_current_output_position()); + output_run_.y = static_cast(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(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) { @@ -223,13 +223,13 @@ void CRT::advance_cycles(unsigned int number_of_cycles, bool hsync_requested, bo [=] (const std::vector &write_areas, size_t number_of_write_areas) { assert(number_of_write_areas * SourceVertexSize == input_size); for(size_t run = 0; run < number_of_write_areas; run++) { - *(uint16_t *)&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfInputStart + 0] = write_areas[run].x; - *(uint16_t *)&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfInputStart + 2] = write_areas[run].y; - *(uint16_t *)&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfEnds + 0] = write_areas[run].x + write_areas[run].length; + *reinterpret_cast(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfInputStart + 0]) = write_areas[run].x; + *reinterpret_cast(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfInputStart + 2]) = write_areas[run].y; + *reinterpret_cast(&input_buffer[run * SourceVertexSize + SourceVertexOffsetOfEnds + 0]) = write_areas[run].x + write_areas[run].length; } }); for(size_t position = 0; position < input_size; position += SourceVertexSize) { - (*(uint16_t *)&input_buffer[position + SourceVertexOffsetOfOutputStart + 2]) = output_y; + (*reinterpret_cast(&input_buffer[position + SourceVertexOffsetOfOutputStart + 2])) = output_y; } }); colour_burst_amplitude_ = 0; @@ -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((phase_numerator_ * 256) / phase_denominator_ + (is_alernate_line_ ? 128 : 0))); } void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider) { @@ -403,11 +403,11 @@ Outputs::CRT::Rect CRT::get_rect_for_area(int first_line_after_sync, int number_ unsigned int horizontal_retrace_period = horizontal_period - horizontal_scan_period; // make sure that the requested range is visible - if((unsigned int)first_cycle_after_sync < horizontal_retrace_period) first_cycle_after_sync = (int)horizontal_retrace_period; - if((unsigned int)(first_cycle_after_sync + number_of_cycles) > horizontal_scan_period) number_of_cycles = (int)(horizontal_scan_period - (unsigned)first_cycle_after_sync); + if(static_cast(first_cycle_after_sync) < horizontal_retrace_period) first_cycle_after_sync = static_cast(horizontal_retrace_period); + if(static_cast(first_cycle_after_sync + number_of_cycles) > horizontal_scan_period) number_of_cycles = static_cast(horizontal_scan_period - static_cast(first_cycle_after_sync)); - float start_x = (float)((unsigned)first_cycle_after_sync - horizontal_retrace_period) / (float)horizontal_scan_period; - float width = (float)number_of_cycles / (float)horizontal_scan_period; + float start_x = static_cast(static_cast(first_cycle_after_sync) - horizontal_retrace_period) / static_cast(horizontal_scan_period); + float width = static_cast(number_of_cycles) / static_cast(horizontal_scan_period); // determine prima facie y extent unsigned int vertical_period = vertical_flywheel_->get_standard_period(); @@ -415,13 +415,13 @@ Outputs::CRT::Rect CRT::get_rect_for_area(int first_line_after_sync, int number_ unsigned int vertical_retrace_period = vertical_period - vertical_scan_period; // make sure that the requested range is visible -// if((unsigned)first_line_after_sync * horizontal_period < vertical_retrace_period) +// if(static_cast(first_line_after_sync) * horizontal_period < vertical_retrace_period) // first_line_after_sync = (vertical_retrace_period + horizontal_period - 1) / horizontal_period; // if((first_line_after_sync + number_of_lines) * horizontal_period > vertical_scan_period) -// number_of_lines = (int)(horizontal_scan_period - (unsigned)first_cycle_after_sync); +// number_of_lines = static_cast(horizontal_scan_period - static_cast(first_cycle_after_sync)); - float start_y = (float)(((unsigned)first_line_after_sync * horizontal_period) - vertical_retrace_period) / (float)vertical_scan_period; - float height = (float)((unsigned)number_of_lines * horizontal_period) / vertical_scan_period; + float start_y = static_cast((static_cast(first_line_after_sync) * horizontal_period) - vertical_retrace_period) / static_cast(vertical_scan_period); + float height = static_cast(static_cast(number_of_lines) * horizontal_period) / vertical_scan_period; // adjust to ensure aspect ratio is correct float adjusted_aspect_ratio = (3.0f*aspect_ratio / 4.0f); diff --git a/Outputs/CRT/Internals/ArrayBuilder.cpp b/Outputs/CRT/Internals/ArrayBuilder.cpp index 1f09602f5..30c4cf6aa 100644 --- a/Outputs/CRT/Internals/ArrayBuilder.cpp +++ b/Outputs/CRT/Internals/ArrayBuilder.cpp @@ -122,7 +122,7 @@ size_t ArrayBuilder::Buffer::submit(bool is_input) { submission_function_(is_input, data.data(), length); } else { glBindBuffer(GL_ARRAY_BUFFER, buffer); - uint8_t *destination = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); + uint8_t *destination = static_cast(glMapBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT)); memcpy(destination, data.data(), length); glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length); glUnmapBuffer(GL_ARRAY_BUFFER); diff --git a/Outputs/CRT/Internals/CRTOpenGL.cpp b/Outputs/CRT/Internals/CRTOpenGL.cpp index af9d18bb0..bfccfdc52 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.cpp +++ b/Outputs/CRT/Internals/CRTOpenGL.cpp @@ -103,7 +103,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out } // make sure there's a target to draw to - if(!framebuffer_ || (unsigned int)framebuffer_->get_height() != output_height || (unsigned int)framebuffer_->get_width() != output_width) { + if(!framebuffer_ || static_cast(framebuffer_->get_height()) != output_height || static_cast(framebuffer_->get_width()) != output_width) { std::unique_ptr new_framebuffer(new OpenGL::TextureTarget((GLsizei)output_width, (GLsizei)output_height, pixel_accumulation_texture_unit, GL_LINEAR)); if(framebuffer_) { new_framebuffer->bind_framebuffer(); @@ -111,7 +111,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out glActiveTexture(pixel_accumulation_texture_unit); framebuffer_->bind_texture(); - framebuffer_->draw((float)output_width / (float)output_height); + framebuffer_->draw(static_cast(output_width) / static_cast(output_height)); new_framebuffer->bind_texture(); } @@ -223,7 +223,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out glActiveTexture(pixel_accumulation_texture_unit); framebuffer_->bind_texture(); - framebuffer_->draw((float)output_width / (float)output_height); + framebuffer_->draw(static_cast(output_width) / static_cast(output_height)); fence_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); draw_mutex_.unlock(); @@ -381,7 +381,7 @@ void OpenGLOutputBuilder::set_gamma() { } float OpenGLOutputBuilder::get_composite_output_width() const { - return ((float)colour_cycle_numerator_ * 4.0f) / (float)(colour_cycle_denominator_ * IntermediateBufferWidth); + return (static_cast(colour_cycle_numerator_) * 4.0f) / static_cast(colour_cycle_denominator_ * IntermediateBufferWidth); } void OpenGLOutputBuilder::set_output_shader_width() { @@ -392,7 +392,7 @@ void OpenGLOutputBuilder::set_output_shader_width() { } void OpenGLOutputBuilder::set_timing_uniforms() { - const float colour_subcarrier_frequency = (float)colour_cycle_numerator_ / (float)colour_cycle_denominator_; + const float colour_subcarrier_frequency = static_cast(colour_cycle_numerator_) / static_cast(colour_cycle_denominator_); const float output_width = get_composite_output_width(); const float sample_cycles_per_line = cycles_per_line_ / output_width; @@ -407,7 +407,7 @@ void OpenGLOutputBuilder::set_timing_uniforms() { } if(rgb_filter_shader_program_) { rgb_filter_shader_program_->set_width_scalers(1.0f, 1.0f); - rgb_filter_shader_program_->set_filter_coefficients(sample_cycles_per_line, (float)input_frequency_ * 0.5f); + rgb_filter_shader_program_->set_filter_coefficients(sample_cycles_per_line, static_cast(input_frequency_) * 0.5f); } if(output_shader_program_) { set_output_shader_width(); 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(composite_src_output_y_); } inline bool composite_output_buffer_is_full() { diff --git a/Outputs/CRT/Internals/Flywheel.hpp b/Outputs/CRT/Internals/Flywheel.hpp index 13746d0d4..92a0d75a6 100644 --- a/Outputs/CRT/Internals/Flywheel.hpp +++ b/Outputs/CRT/Internals/Flywheel.hpp @@ -174,7 +174,7 @@ struct Flywheel { @returns `true` if a sync is expected soon or the time at which it was expected was recent. */ inline bool is_near_expected_sync() { - return abs((int)counter_ - (int)expected_next_sync_) < (int)standard_period_ / 50; + return abs(static_cast(counter_) - static_cast(expected_next_sync_)) < static_cast(standard_period_) / 50; } private: diff --git a/Outputs/CRT/Internals/Shaders/IntermediateShader.cpp b/Outputs/CRT/Internals/Shaders/IntermediateShader.cpp index 894e4f293..5bfad3f8a 100644 --- a/Outputs/CRT/Internals/Shaders/IntermediateShader.cpp +++ b/Outputs/CRT/Internals/Shaders/IntermediateShader.cpp @@ -350,7 +350,7 @@ void IntermediateShader::set_filter_coefficients(float sampling_rate, float cuto // int halfSize = (taps >> 1); // while(c < halfSize && sample < 5) { -// offsets[sample] = (float)(halfSize - c); +// offsets[sample] = static_cast(halfSize - c); // if((coefficients[c] < 0.0f) == (coefficients[c+1] < 0.0f) && c+1 < (taps >> 1)) { // weights[sample] = coefficients[c] + coefficients[c+1]; // offsets[sample] -= (coefficients[c+1] / weights[sample]); diff --git a/Outputs/CRT/Internals/Shaders/OutputShader.cpp b/Outputs/CRT/Internals/Shaders/OutputShader.cpp index 1c773828a..4453311c3 100644 --- a/Outputs/CRT/Internals/Shaders/OutputShader.cpp +++ b/Outputs/CRT/Internals/Shaders/OutputShader.cpp @@ -92,7 +92,7 @@ std::unique_ptr OutputShader::make_shader(const char *fragment_met } void OutputShader::set_output_size(unsigned int output_width, unsigned int output_height, Outputs::CRT::Rect visible_area) { - GLfloat outputAspectRatioMultiplier = ((float)output_width / (float)output_height) / (4.0f / 3.0f); + GLfloat outputAspectRatioMultiplier = (static_cast(output_width) / static_cast(output_height)) / (4.0f / 3.0f); GLfloat bonusWidth = (outputAspectRatioMultiplier - 1.0f) * visible_area.size.width; visible_area.origin.x -= bonusWidth * 0.5f * visible_area.size.width; @@ -107,9 +107,9 @@ void OutputShader::set_source_texture_unit(GLenum unit) { } void OutputShader::set_timing(unsigned int height_of_display, unsigned int cycles_per_line, unsigned int horizontal_scan_period, unsigned int vertical_scan_period, unsigned int vertical_period_divider) { - GLfloat scan_angle = atan2f(1.0f / (float)height_of_display, 1.0f); + GLfloat scan_angle = atan2f(1.0f / static_cast(height_of_display), 1.0f); GLfloat scan_normal[] = { -sinf(scan_angle), cosf(scan_angle)}; - GLfloat multiplier = (float)cycles_per_line / ((float)height_of_display * (float)horizontal_scan_period); + GLfloat multiplier = static_cast(cycles_per_line) / (static_cast(height_of_display) * static_cast(horizontal_scan_period)); scan_normal[0] *= multiplier; scan_normal[1] *= multiplier; diff --git a/Outputs/CRT/Internals/Shaders/Shader.cpp b/Outputs/CRT/Internals/Shaders/Shader.cpp index 413932dc3..5010dab0e 100644 --- a/Outputs/CRT/Internals/Shaders/Shader.cpp +++ b/Outputs/CRT/Internals/Shaders/Shader.cpp @@ -29,7 +29,7 @@ GLuint Shader::compile_shader(const std::string &source, GLenum type) { GLint logLength; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); if(logLength > 0) { - GLchar *log = new GLchar[(size_t)logLength]; + GLchar *log = new GLchar[static_cast(logLength)]; glGetShaderInfoLog(shader, logLength, &logLength, log); printf("Compile log:\n%s\n", log); delete[] log; @@ -66,7 +66,7 @@ Shader::Shader(const std::string &vertex_shader, const std::string &fragment_sha GLint logLength; glGetProgramiv(shader_program_, GL_INFO_LOG_LENGTH, &logLength); if(logLength > 0) { - GLchar *log = new GLchar[(size_t)logLength]; + GLchar *log = new GLchar[static_cast(logLength)]; glGetProgramInfoLog(shader_program_, logLength, &logLength, log); printf("Link log:\n%s\n", log); delete[] log; @@ -186,9 +186,9 @@ void Shader::set_uniform(const std::string &name, GLuint value1, GLuint value2, } void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLint *values) { - size_t number_of_values = (size_t)count * (size_t)size; + size_t number_of_values = static_cast(count) * static_cast(size); GLint *values_copy = new GLint[number_of_values]; - memcpy(values_copy, values, sizeof(*values) * (size_t)number_of_values); + memcpy(values_copy, values, sizeof(*values) * static_cast(number_of_values)); enqueue_function([name, size, count, values_copy, this] { switch(size) { @@ -202,9 +202,9 @@ void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, con } void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLfloat *values) { - size_t number_of_values = (size_t)count * (size_t)size; + size_t number_of_values = static_cast(count) * static_cast(size); GLfloat *values_copy = new GLfloat[number_of_values]; - memcpy(values_copy, values, sizeof(*values) * (size_t)number_of_values); + memcpy(values_copy, values, sizeof(*values) * static_cast(number_of_values)); enqueue_function([name, size, count, values_copy, this] { switch(size) { @@ -218,9 +218,9 @@ void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, con } void Shader::set_uniform(const std::string &name, GLint size, GLsizei count, const GLuint *values) { - size_t number_of_values = (size_t)count * (size_t)size; + size_t number_of_values = static_cast(count) * static_cast(size); GLuint *values_copy = new GLuint[number_of_values]; - memcpy(values_copy, values, sizeof(*values) * (size_t)number_of_values); + memcpy(values_copy, values, sizeof(*values) * static_cast(number_of_values)); enqueue_function([name, size, count, values_copy, this] { switch(size) { @@ -238,7 +238,7 @@ void Shader::set_uniform_matrix(const std::string &name, GLint size, bool transp } void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei count, bool transpose, const GLfloat *values) { - size_t number_of_values = (size_t)count * (size_t)size * (size_t)size; + size_t number_of_values = static_cast(count) * static_cast(size) * static_cast(size); GLfloat *values_copy = new GLfloat[number_of_values]; memcpy(values_copy, values, sizeof(*values) * number_of_values); 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(alignment_offset); + write_areas_start_x_ += static_cast(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(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(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/Outputs/CRT/Internals/TextureTarget.cpp b/Outputs/CRT/Internals/TextureTarget.cpp index 963908cc1..b7778fe77 100644 --- a/Outputs/CRT/Internals/TextureTarget.cpp +++ b/Outputs/CRT/Internals/TextureTarget.cpp @@ -29,7 +29,7 @@ TextureTarget::TextureTarget(GLsizei width, GLsizei height, GLenum texture_unit, glGenTextures(1, &_texture); glActiveTexture(texture_unit); glBindTexture(GL_TEXTURE_2D, _texture); - uint8_t *blank_buffer = (uint8_t *)calloc((size_t)(_expanded_width * _expanded_height), 4); + uint8_t *blank_buffer = static_cast(calloc(static_cast(_expanded_width * _expanded_height), 4)); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)_expanded_width, (GLsizei)_expanded_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, blank_buffer); free(blank_buffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter); @@ -114,14 +114,14 @@ void TextureTarget::draw(float aspect_ratio) { buffer[2] = 0.0f; buffer[3] = 0.0f; buffer[6] = 0.0f; - buffer[7] = (float)_height / (float)_expanded_height; - buffer[10] = (float)_width / (float)_expanded_width; + buffer[7] = static_cast(_height) / static_cast(_expanded_height); + buffer[10] = static_cast(_width) / static_cast(_expanded_width); buffer[11] = 0; buffer[14] = buffer[10]; buffer[15] = buffer[7]; // determine positions; rule is to keep the same height and centre - float internal_aspect_ratio = (float)_width / (float)_height; + float internal_aspect_ratio = static_cast(_width) / static_cast(_height); float aspect_ratio_ratio = internal_aspect_ratio / aspect_ratio; buffer[0] = -aspect_ratio_ratio; buffer[1] = -1.0f; diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index 85f7ecb8b..9eb18ce86 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -55,12 +55,12 @@ class Speaker { void set_output_rate(float cycles_per_second, int buffer_size) { output_cycles_per_second_ = cycles_per_second; - buffer_in_progress_.resize((size_t)buffer_size); + buffer_in_progress_.resize(static_cast(buffer_size)); set_needs_updated_filter_coefficients(); } void set_output_quality(int number_of_taps) { - requested_number_of_taps_ = (size_t)number_of_taps; + requested_number_of_taps_ = static_cast(number_of_taps); set_needs_updated_filter_coefficients(); } @@ -144,16 +144,16 @@ template class Filter: public Speaker { void run_for(const Cycles cycles) { enqueue([=]() { - unsigned int cycles_remaining = (unsigned int)cycles.as_int(); + unsigned int cycles_remaining = static_cast(cycles.as_int()); if(coefficients_are_dirty_) update_filter_coefficients(); // if input and output rates exactly match, just accumulate results and pass on if(input_cycles_per_second_ == output_cycles_per_second_ && high_frequency_cut_off_ < 0.0) { while(cycles_remaining) { - unsigned int cycles_to_read = (unsigned int)(buffer_in_progress_.size() - (size_t)buffer_in_progress_pointer_); + unsigned int cycles_to_read = static_cast(buffer_in_progress_.size() - static_cast(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_[(size_t)buffer_in_progress_pointer_]); + static_cast(this)->get_samples(cycles_to_read, &buffer_in_progress_[static_cast(buffer_in_progress_pointer_)]); buffer_in_progress_pointer_ += cycles_to_read; // announce to delegate if full @@ -173,13 +173,13 @@ template class Filter: public Speaker { // if the output rate is less than the input rate, use the filter 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((size_t)cycles_remaining, number_of_taps_ - input_buffer_depth_); - static_cast(this)->get_samples(cycles_to_read, &input_buffer_[(size_t)input_buffer_depth_]); + unsigned int cycles_to_read = static_cast(std::min(static_cast(cycles_remaining), number_of_taps_ - input_buffer_depth_)); + static_cast(this)->get_samples(cycles_to_read, &input_buffer_[static_cast(input_buffer_depth_)]); cycles_remaining -= cycles_to_read; input_buffer_depth_ += cycles_to_read; if(input_buffer_depth_ == number_of_taps_) { - buffer_in_progress_[(size_t)buffer_in_progress_pointer_] = filter_->apply(input_buffer_.data()); + buffer_in_progress_[static_cast(buffer_in_progress_pointer_)] = filter_->apply(input_buffer_.data()); buffer_in_progress_pointer_++; // announce to delegate if full @@ -196,11 +196,11 @@ template class Filter: public Speaker { uint64_t steps = stepper_->step(); if(steps < number_of_taps_) { int16_t *input_buffer = input_buffer_.data(); - memmove(input_buffer, &input_buffer[steps], sizeof(int16_t) * ((size_t)number_of_taps_ - (size_t)steps)); + memmove(input_buffer, &input_buffer[steps], sizeof(int16_t) * (static_cast(number_of_taps_) - static_cast(steps))); input_buffer_depth_ -= steps; } else { if(steps > number_of_taps_) - static_cast(this)->skip_samples((unsigned int)steps - (unsigned int)number_of_taps_); + static_cast(this)->skip_samples(static_cast(steps) - static_cast(number_of_taps_)); input_buffer_depth_ = 0; } } @@ -225,7 +225,7 @@ template class Filter: public Speaker { if(requested_number_of_taps_) { number_of_taps_ = requested_number_of_taps_; } else { - number_of_taps_ = (size_t)ceilf((input_cycles_per_second_ + output_cycles_per_second_) / output_cycles_per_second_); + number_of_taps_ = static_cast(ceilf((input_cycles_per_second_ + output_cycles_per_second_) / output_cycles_per_second_)); number_of_taps_ *= 2; number_of_taps_ |= 1; } @@ -241,9 +241,9 @@ template class Filter: public Speaker { } else { high_pass_frequency = output_cycles_per_second_ / 2.0f; } - filter_.reset(new SignalProcessing::FIRFilter((unsigned int)number_of_taps_, (float)input_cycles_per_second_, 0.0, high_pass_frequency, SignalProcessing::FIRFilter::DefaultAttenuation)); + filter_.reset(new SignalProcessing::FIRFilter(static_cast(number_of_taps_), static_cast(input_cycles_per_second_), 0.0, high_pass_frequency, SignalProcessing::FIRFilter::DefaultAttenuation)); - input_buffer_.resize((size_t)number_of_taps_); + input_buffer_.resize(static_cast(number_of_taps_)); input_buffer_depth_ = 0; } }; 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(value); break; + case Register::Flags: set_flags(static_cast(value)); break; + case Register::A: a_ = static_cast(value); break; + case Register::X: x_ = static_cast(value); break; + case Register::Y: y_ = static_cast(value); break; + case Register::S: s_ = static_cast(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(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(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(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(a_) - static_cast(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(temp16); + zero_result_ = static_cast(decimalResult); if(temp16 > 0xff) temp16 -= 0x60; carry_flag_ = (temp16 > 0xff) ? 0 : Flag::Carry; - a_ = (uint8_t)temp16; + a_ = static_cast(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(a_) + static_cast(operand_) + static_cast(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(a_ & 0xf0) + static_cast(operand_ & 0xf0) + static_cast(low_nibble); + negative_result_ = static_cast(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(result); + zero_result_ = static_cast(decimalResult); } else { - const uint16_t result = (uint16_t)a_ + (uint16_t)operand_ + (uint16_t)carry_flag_; + const uint16_t result = static_cast(a_) + static_cast(operand_) + static_cast(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(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((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((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((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((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(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((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((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(difference); negative_result_ = zero_result_ = x_; carry_flag_ = ((difference >> 8)&1)^1; continue; diff --git a/Processors/AllRAMProcessor.cpp b/Processors/AllRAMProcessor.cpp index c4d4c7c79..86fa758bf 100644 --- a/Processors/AllRAMProcessor.cpp +++ b/Processors/AllRAMProcessor.cpp @@ -16,12 +16,12 @@ AllRAMProcessor::AllRAMProcessor(size_t memory_size) : timestamp_(0) {} void AllRAMProcessor::set_data_at_address(uint16_t startAddress, size_t length, const uint8_t *data) { - size_t endAddress = std::min(startAddress + length, (size_t)65536); + size_t endAddress = std::min(startAddress + length, static_cast(65536)); memcpy(&memory_[startAddress], data, endAddress - startAddress); } void AllRAMProcessor::get_data_at_address(uint16_t startAddress, size_t length, uint8_t *data) { - size_t endAddress = std::min(startAddress + length, (size_t)65536); + size_t endAddress = std::min(startAddress + length, static_cast(65536)); memcpy(data, &memory_[startAddress], endAddress - startAddress); } 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((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(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(value); break; + case Register::AF: a_ = static_cast(value >> 8); // deliberate fallthrough... + case Register::Flags: set_flags(static_cast(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(value); break; + case Register::C: bc_.bytes.low = static_cast(value); break; + case Register::BC: bc_.full = value; break; + case Register::D: de_.bytes.high = static_cast(value); break; + case Register::E: de_.bytes.low = static_cast(value); break; + case Register::DE: de_.full = value; break; + case Register::H: hl_.bytes.high = static_cast(value); break; + case Register::L: hl_.bytes.low = static_cast(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(value); break; + case Register::FlagsDash: afDash_.bytes.low = static_cast(value); break; + case Register::AFDash: afDash_.full = value; break; + case Register::BDash: bcDash_.bytes.high = static_cast(value); break; + case Register::CDash: bcDash_.bytes.low = static_cast(value); break; + case Register::BCDash: bcDash_.full = value; break; + case Register::DDash: deDash_.bytes.high = static_cast(value); break; + case Register::EDash: deDash_.bytes.low = static_cast(value); break; + case Register::DEDash: deDash_.full = value; break; + case Register::HDash: hlDash_.bytes.high = static_cast(value); break; + case Register::LDash: hlDash_.bytes.low = static_cast(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(value); break; + case Register::IXl: ix_.bytes.low = static_cast(value); break; + case Register::IX: ix_.full = value; break; + case Register::IYh: iy_.bytes.high = static_cast(value); break; + case Register::IYl: iy_.bytes.low = static_cast(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(value); break; + case Register::I: ir_.bytes.high = static_cast(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..8ee0d01cc 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(v^1);\ parity_overflow_result_ ^= parity_overflow_result_ >> 4;\ parity_overflow_result_ ^= parity_overflow_result_ << 2;\ parity_overflow_result_ ^= parity_overflow_result_ >> 1; @@ -88,20 +88,20 @@ 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(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(halt_mask_); scheduled_program_counter_ = current_instruction_page_->instructions[operation_ & halt_mask_]; break; - case MicroOp::Increment16: (*(uint16_t *)operation->source)++; break; - case MicroOp::IncrementPC: pc_.full += pc_increment_; break; - case MicroOp::Decrement16: (*(uint16_t *)operation->source)--; break; - case MicroOp::Move8: *(uint8_t *)operation->destination = *(uint8_t *)operation->source; break; - case MicroOp::Move16: *(uint16_t *)operation->destination = *(uint16_t *)operation->source; break; + case MicroOp::Increment16: (*static_cast(operation->source))++; break; + case MicroOp::IncrementPC: pc_.full += pc_increment_; break; + case MicroOp::Decrement16: (*static_cast(operation->source))--; break; + case MicroOp::Move8: *static_cast(operation->destination) = *static_cast(operation->source); break; + case MicroOp::Move16: *static_cast(operation->destination) = *static_cast(operation->source); break; case MicroOp::AssembleAF: temp16_.bytes.high = a_; @@ -122,17 +122,17 @@ template < class T, carry_result_ = 0; case MicroOp::And: - a_ &= *(uint8_t *)operation->source; + a_ &= *static_cast(operation->source); set_logical_flags(Flag::HalfCarry); break; case MicroOp::Or: - a_ |= *(uint8_t *)operation->source; + a_ |= *static_cast(operation->source); set_logical_flags(0); break; case MicroOp::Xor: - a_ ^= *(uint8_t *)operation->source; + a_ ^= *static_cast(operation->source); set_logical_flags(0); 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(carry_result_ << 4); carry_result_ ^= Flag::Carry; subtract_flag_ = 0; bit53_result_ = a_; @@ -175,15 +175,15 @@ 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(result); \ + carry_result_ = static_cast(result >> 8); \ + half_carry_result_ = static_cast(half_result); \ + parity_overflow_result_ = static_cast(overflow >> 5); \ subtract_flag_ = sub; \ - bit53_result_ = (uint8_t)b53; + bit53_result_ = static_cast(b53); case MicroOp::CP8: { - uint8_t value = *(uint8_t *)operation->source; + uint8_t value = *static_cast(operation->source); int result = a_ - value; int half_result = (a_&0xf) - (value&0xf); @@ -196,7 +196,7 @@ template < class T, } break; case MicroOp::SUB8: { - uint8_t value = *(uint8_t *)operation->source; + uint8_t value = *static_cast(operation->source); int result = a_ - value; int half_result = (a_&0xf) - (value&0xf); @@ -204,12 +204,12 @@ template < class T, // different and the result is different again int overflow = (value^a_) & (result^a_); - a_ = (uint8_t)result; + a_ = static_cast(result); set_arithmetic_flags(Flag::Subtract, result); } break; case MicroOp::SBC8: { - uint8_t value = *(uint8_t *)operation->source; + uint8_t value = *static_cast(operation->source); int result = a_ - value - (carry_result_ & Flag::Carry); int half_result = (a_&0xf) - (value&0xf) - (carry_result_ & Flag::Carry); @@ -217,12 +217,12 @@ template < class T, // different and the result is different again int overflow = (value^a_) & (result^a_); - a_ = (uint8_t)result; + a_ = static_cast(result); set_arithmetic_flags(Flag::Subtract, result); } break; case MicroOp::ADD8: { - uint8_t value = *(uint8_t *)operation->source; + uint8_t value = *static_cast(operation->source); int result = a_ + value; int half_result = (a_&0xf) + (value&0xf); @@ -230,12 +230,12 @@ template < class T, // the same and the result is different int overflow = ~(value^a_) & (result^a_); - a_ = (uint8_t)result; + a_ = static_cast(result); set_arithmetic_flags(0, result); } break; case MicroOp::ADC8: { - uint8_t value = *(uint8_t *)operation->source; + uint8_t value = *static_cast(operation->source); int result = a_ + value + (carry_result_ & Flag::Carry); int half_result = (a_&0xf) + (value&0xf) + (carry_result_ & Flag::Carry); @@ -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(result); set_arithmetic_flags(0, result); } break; @@ -254,16 +254,16 @@ template < class T, int result = -a_; int halfResult = -(a_&0xf); - a_ = (uint8_t)result; + a_ = static_cast(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(result >> 8); + half_carry_result_ = static_cast(halfResult); } break; case MicroOp::Increment8: { - uint8_t value = *(uint8_t *)operation->source; + uint8_t value = *static_cast(operation->source); int result = value + 1; // with an increment, overflow occurs if the sign changes from @@ -271,17 +271,17 @@ template < class T, int overflow = (value ^ result) & ~value; int half_result = (value&0xf) + 1; - *(uint8_t *)operation->source = (uint8_t)result; + *static_cast(operation->source) = static_cast(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(result); + half_carry_result_ = static_cast(half_result); + parity_overflow_result_ = static_cast(overflow >> 5); subtract_flag_ = 0; } break; case MicroOp::Decrement8: { - uint8_t value = *(uint8_t *)operation->source; + uint8_t value = *static_cast(operation->source); int result = value - 1; // with a decrement, overflow occurs if the sign changes from @@ -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; + *static_cast(operation->source) = static_cast(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(result); + half_carry_result_ = static_cast(half_result); + parity_overflow_result_ = static_cast(overflow >> 5); subtract_flag_ = Flag::Subtract; } break; @@ -356,24 +356,24 @@ template < class T, #pragma mark - 16-bit arithmetic case MicroOp::ADD16: { - memptr_.full = *(uint16_t *)operation->destination; - uint16_t sourceValue = *(uint16_t *)operation->source; + memptr_.full = *static_cast(operation->destination); + uint16_t sourceValue = *static_cast(operation->source); uint16_t destinationValue = memptr_.full; 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(result >> 8); + carry_result_ = static_cast(result >> 16); + half_carry_result_ = static_cast(halfResult >> 8); subtract_flag_ = 0; - *(uint16_t *)operation->destination = (uint16_t)result; + *static_cast(operation->destination) = static_cast(result); memptr_.full++; } break; case MicroOp::ADC16: { - memptr_.full = *(uint16_t *)operation->destination; - uint16_t sourceValue = *(uint16_t *)operation->source; + memptr_.full = *static_cast(operation->destination); + uint16_t sourceValue = *static_cast(operation->source); uint16_t destinationValue = memptr_.full; int result = sourceValue + destinationValue + (carry_result_ & Flag::Carry); int halfResult = (sourceValue&0xfff) + (destinationValue&0xfff) + (carry_result_ & Flag::Carry); @@ -381,20 +381,20 @@ 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(result >> 8); + zero_result_ = static_cast(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(result >> 16); + half_carry_result_ = static_cast(halfResult >> 8); + parity_overflow_result_ = static_cast(overflow >> 13); - *(uint16_t *)operation->destination = (uint16_t)result; + *static_cast(operation->destination) = static_cast(result); memptr_.full++; } break; case MicroOp::SBC16: { - memptr_.full = *(uint16_t *)operation->destination; - uint16_t sourceValue = *(uint16_t *)operation->source; + memptr_.full = *static_cast(operation->destination); + uint16_t sourceValue = *static_cast(operation->source); uint16_t destinationValue = memptr_.full; int result = destinationValue - sourceValue - (carry_result_ & Flag::Carry); int halfResult = (destinationValue&0xfff) - (sourceValue&0xfff) - (carry_result_ & Flag::Carry); @@ -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(result >> 8); + zero_result_ = static_cast(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(result >> 16); + half_carry_result_ = static_cast(halfResult >> 8); + parity_overflow_result_ = static_cast(overflow >> 13); - *(uint16_t *)operation->destination = (uint16_t)result; + *static_cast(operation->destination) = static_cast(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((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((result&0x8) | ((result&0x2) << 4)); \ case MicroOp::CPDR: { CPxR_STEP(-1); @@ -619,12 +619,12 @@ template < class T, #pragma mark - Bit Manipulation case MicroOp::BIT: { - uint8_t result = *(uint8_t *)operation->source & (1 << ((operation_ >> 3)&7)); + uint8_t result = *static_cast(operation->source) & (1 << ((operation_ >> 3)&7)); if(current_instruction_page_->is_indexed || ((operation_&0x08) == 7)) { bit53_result_ = memptr_.bytes.high; } else { - bit53_result_ = *(uint8_t *)operation->source; + bit53_result_ = *static_cast(operation->source); } sign_result_ = zero_result_ = result; @@ -634,11 +634,11 @@ template < class T, } break; case MicroOp::RES: - *(uint8_t *)operation->source &= ~(1 << ((operation_ >> 3)&7)); + *static_cast(operation->source) &= ~(1 << ((operation_ >> 3)&7)); break; case MicroOp::SET: - *(uint8_t *)operation->source |= (1 << ((operation_ >> 3)&7)); + *static_cast(operation->source) |= (1 << ((operation_ >> 3)&7)); break; #pragma mark - Rotation and shifting @@ -650,83 +650,83 @@ template < class T, case MicroOp::RLA: { uint8_t new_carry = a_ >> 7; - a_ = (uint8_t)((a_ << 1) | (carry_result_ & Flag::Carry)); + a_ = static_cast((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((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((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((a_ >> 1) | (new_carry << 7)); set_rotate_flags(); } break; #undef set_rotate_flags #define set_shift_flags() \ - sign_result_ = zero_result_ = bit53_result_ = *(uint8_t *)operation->source; \ + sign_result_ = zero_result_ = bit53_result_ = *static_cast(operation->source); \ set_parity(sign_result_); \ half_carry_result_ = 0; \ subtract_flag_ = 0; case MicroOp::RLC: - carry_result_ = *(uint8_t *)operation->source >> 7; - *(uint8_t *)operation->source = (uint8_t)((*(uint8_t *)operation->source << 1) | carry_result_); + carry_result_ = *static_cast(operation->source) >> 7; + *static_cast(operation->source) = static_cast((*static_cast(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)); + carry_result_ = *static_cast(operation->source); + *static_cast(operation->source) = static_cast((*static_cast(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 next_carry = *static_cast(operation->source) >> 7; + *static_cast(operation->source) = static_cast((*static_cast(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 next_carry = *static_cast(operation->source); + *static_cast(operation->source) = static_cast((*static_cast(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); + carry_result_ = *static_cast(operation->source) >> 7; + *static_cast(operation->source) = static_cast(*static_cast(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)); + carry_result_ = *static_cast(operation->source); + *static_cast(operation->source) = static_cast((*static_cast(operation->source) >> 1) | (*static_cast(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; + carry_result_ = *static_cast(operation->source) >> 7; + *static_cast(operation->source) = static_cast(*static_cast(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)); + carry_result_ = *static_cast(operation->source); + *static_cast(operation->source) = static_cast((*static_cast(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((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((temp8_ << 4) | low_nibble); set_decimal_rotate_flags(); } break; @@ -782,7 +782,7 @@ template < class T, case MicroOp::SetInFlags: subtract_flag_ = half_carry_result_ = 0; - sign_result_ = zero_result_ = bit53_result_ = *(uint8_t *)operation->source; + sign_result_ = zero_result_ = bit53_result_ = *static_cast(operation->source); set_parity(sign_result_); 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(*static_cast(operation->source) + (int8_t)temp8_); break; case MicroOp::IndexedPlaceHolder: diff --git a/SignalProcessing/FIRFilter.cpp b/SignalProcessing/FIRFilter.cpp index 5109da8a3..c4b2951c1 100644 --- a/SignalProcessing/FIRFilter.cpp +++ b/SignalProcessing/FIRFilter.cpp @@ -69,11 +69,11 @@ void FIRFilter::coefficients_for_idealised_filter_response(short *filterCoeffici /* work out the right hand side of the filter coefficients */ unsigned int Np = (numberOfTaps - 1) / 2; float I0 = ino(a); - float NpSquared = (float)(Np * Np); + float NpSquared = static_cast(Np * Np); for(unsigned int i = 0; i <= Np; i++) { filterCoefficientsFloat[Np + i] = A[i] * - ino(a * sqrtf(1.0f - ((float)(i * i) / NpSquared) )) / + ino(a * sqrtf(1.0f - (static_cast(i * i) / NpSquared) )) / I0; } @@ -99,7 +99,7 @@ void FIRFilter::coefficients_for_idealised_filter_response(short *filterCoeffici void FIRFilter::get_coefficients(float *coefficients) { for(unsigned int i = 0; i < number_of_taps_; i++) { - coefficients[i] = (float)filter_coefficients_[i] / kCSKaiserBesselFilterFixedMultiplier; + coefficients[i] = static_cast(filter_coefficients_[i]) / kCSKaiserBesselFilterFixedMultiplier; } } @@ -123,7 +123,7 @@ FIRFilter::FIRFilter(unsigned int number_of_taps, float input_sample_rate, float float *A = new float[Np+1]; A[0] = 2.0f * (high_frequency - low_frequency) / input_sample_rate; for(unsigned int i = 1; i <= Np; i++) { - float iPi = (float)i * (float)M_PI; + float iPi = static_cast(i) * static_cast(M_PI); A[i] = ( sinf(twoOverSampleRate * iPi * high_frequency) - diff --git a/StaticAnalyser/Acorn/Disk.cpp b/StaticAnalyser/Acorn/Disk.cpp index 7e5c6f663..6ab4ab585 100644 --- a/StaticAnalyser/Acorn/Disk.cpp +++ b/StaticAnalyser/Acorn/Disk.cpp @@ -51,14 +51,14 @@ std::unique_ptr StaticAnalyser::Acorn::GetDFSCatalogue(const std::sha new_file.execution_address = (uint32_t)(details->data[file_offset+2] | (details->data[file_offset+3] << 8) | ((details->data[file_offset+6]&0xc0) << 10)); new_file.is_protected = !!(names->data[file_offset + 7] & 0x80); - long data_length = (long)(details->data[file_offset+4] | (details->data[file_offset+5] << 8) | ((details->data[file_offset+6]&0x30) << 12)); + long data_length = static_cast(details->data[file_offset+4] | (details->data[file_offset+5] << 8) | ((details->data[file_offset+6]&0x30) << 12)); int start_sector = details->data[file_offset+7] | ((details->data[file_offset+6]&0x03) << 8); - new_file.data.reserve((size_t)data_length); + new_file.data.reserve(static_cast(data_length)); 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(start_sector % 10); + uint8_t track = static_cast(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 GetNextChunk(const std::shared_ptrload_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(parser.get_next_short(tape)); + new_chunk->block_length = static_cast(parser.get_next_short(tape)); + new_chunk->block_flag = static_cast(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(parser.get_next_short(tape)); + stored_header_crc = static_cast((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 GetNextChunk(const std::shared_ptrdata.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(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(parser.get_next_short(tape)); + stored_data_crc = static_cast((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..e5844260a 100644 --- a/StaticAnalyser/Atari/StaticAnalyser.cpp +++ b/StaticAnalyser/Atari/StaticAnalyser.cpp @@ -16,15 +16,15 @@ 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(segment.data[0x7fc] | (segment.data[0x7fd] << 8))) & 0x1fff; + break_address = (static_cast(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; std::function high_location_mapper = [](uint16_t address) { address &= 0x1fff; - return (size_t)(address - 0x1800); + return static_cast(address - 0x1800); }; StaticAnalyser::MOS6502::Disassembly high_location_disassembly = StaticAnalyser::MOS6502::Disassemble(segment.data, high_location_mapper, {entry_address, break_address}); @@ -122,12 +122,12 @@ 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(segment.data[segment.data.size() - 4] | (segment.data[segment.data.size() - 3] << 8)); + break_address = static_cast(segment.data[segment.data.size() - 2] | (segment.data[segment.data.size() - 1] << 8)); std::function address_mapper = [](uint16_t address) { - if(!(address & 0x1000)) return (size_t)-1; - return (size_t)(address & 0xfff); + if(!(address & 0x1000)) return static_cast(-1); + return static_cast(address & 0xfff); }; std::vector final_4k(segment.data.end() - 4096, segment.data.end()); diff --git a/StaticAnalyser/Commodore/Disk.cpp b/StaticAnalyser/Commodore/Disk.cpp index cbba94f8c..e09ccee75 100644 --- a/StaticAnalyser/Commodore/Disk.cpp +++ b/StaticAnalyser/Commodore/Disk.cpp @@ -40,7 +40,7 @@ class CommodoreGCRParser: public Storage::Disk::Controller { @returns a sector if one was found; @c nullptr otherwise. */ std::shared_ptr get_sector(uint8_t track, uint8_t sector) { - int difference = (int)track - (int)track_; + int difference = static_cast(track) - static_cast(track_); track_ = track; if(difference) { @@ -67,7 +67,7 @@ class CommodoreGCRParser: public Storage::Disk::Controller { std::shared_ptr sector_cache_[65536]; void process_input_bit(int value) { - shift_register_ = ((shift_register_ << 1) | (unsigned int)value) & 0x3ff; + shift_register_ = ((shift_register_ << 1) | static_cast(value)) & 0x3ff; bit_count_++; } @@ -108,7 +108,7 @@ class CommodoreGCRParser: public Storage::Disk::Controller { } std::shared_ptr get_sector(uint8_t sector) { - uint16_t sector_address = (uint16_t)((track_ << 8) | sector); + uint16_t sector_address = static_cast((track_ << 8) | sector); if(sector_cache_[sector_address]) return sector_cache_[sector_address]; std::shared_ptr 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(get_next_byte()); + sector->sector = static_cast(get_next_byte()); + sector->track = static_cast(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(get_next_byte()); + disk_id[1] = static_cast(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(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((sector->track << 8) | sector->sector); sector_cache_[sector_address] = sector; return sector; } @@ -188,7 +188,7 @@ std::list StaticAnalyser::Commodore::GetFiles(const std::shared_ptr(-32); while(header_pointer+32+31 < directory.size()) { header_pointer += 32; @@ -212,7 +212,7 @@ std::list StaticAnalyser::Commodore::GetFiles(const std::shared_ptr(directory[header_pointer + 0x1e]) + (static_cast(directory[header_pointer + 0x1f]) << 8); new_file.data.reserve((number_of_sectors - 1) * 254 + 252); bool is_first_sector = true; @@ -223,7 +223,7 @@ std::list StaticAnalyser::Commodore::GetFiles(const std::shared_ptrdata[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(sector->data[2]) | static_cast(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(next_line_number); line_address = next_line_address; } diff --git a/StaticAnalyser/Disassembler/Disassembler6502.cpp b/StaticAnalyser/Disassembler/Disassembler6502.cpp index fb54a95bb..df047e5b2 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(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(address + (int8_t)instruction.operand); disassembly.remaining_entry_points.push_back(destination); } } @@ -332,6 +332,6 @@ Disassembly StaticAnalyser::MOS6502::Disassemble(const std::vector &mem std::function StaticAnalyser::MOS6502::OffsetMapper(uint16_t start_address) { return [start_address](uint16_t argument) { - return (size_t)(argument - start_address); + return static_cast(argument - start_address); }; } 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 StaticAnalyser::Oric::GetFiles(const std::shared_ptr(parser.get_next_byte(tape, is_fast) << 8); + new_file.ending_address |= static_cast(parser.get_next_byte(tape, is_fast)); + new_file.starting_address = static_cast(parser.get_next_byte(tape, is_fast) << 8); + new_file.starting_address |= static_cast(parser.get_next_byte(tape, is_fast)); // skip an empty byte parser.get_next_byte(tape, is_fast); @@ -72,7 +72,7 @@ std::list StaticAnalyser::Oric::GetFiles(const std::shared_ptr(parser.get_next_byte(tape, is_fast))); } // only one validation check: was there enough tape? diff --git a/Storage/Cartridge/Formats/BinaryDump.cpp b/Storage/Cartridge/Formats/BinaryDump.cpp index 3c6d5b74f..018f020b6 100644 --- a/Storage/Cartridge/Formats/BinaryDump.cpp +++ b/Storage/Cartridge/Formats/BinaryDump.cpp @@ -21,9 +21,9 @@ BinaryDump::BinaryDump(const char *file_name) { // grab contents FILE *file = fopen(file_name, "rb"); if(!file) throw ErrorNotAccessible; - size_t data_length = (size_t)file_stats.st_size; + size_t data_length = static_cast(file_stats.st_size); std::vector contents(data_length); - fread(&contents[0], 1, (size_t)(data_length), file); + fread(&contents[0], 1, static_cast(data_length), file); fclose(file); // enshrine diff --git a/Storage/Cartridge/Formats/PRG.cpp b/Storage/Cartridge/Formats/PRG.cpp index 923ed7ac4..1ea6b406d 100644 --- a/Storage/Cartridge/Formats/PRG.cpp +++ b/Storage/Cartridge/Formats/PRG.cpp @@ -28,11 +28,11 @@ PRG::PRG(const char *file_name) { int loading_address = fgetc(file); loading_address |= fgetc(file) << 8; - size_t data_length = (size_t)file_stats.st_size - 2; + size_t data_length = static_cast(file_stats.st_size) - 2; size_t padded_data_length = 1; while(padded_data_length < data_length) padded_data_length <<= 1; std::vector contents(padded_data_length); - fread(&contents[0], 1, (size_t)(data_length), file); + fread(&contents[0], 1, static_cast(data_length), file); fclose(file); // accept only files intended to load at 0xa000 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 &data) { - return (uint16_t)(data[address] | (data[address + 1] << 8)); + return static_cast(data[address] | (data[address + 1] << 8)); } static std::shared_ptr ZX80FileFromData(const std::vector &data) { diff --git a/Storage/Disk/Controller/DiskController.cpp b/Storage/Disk/Controller/DiskController.cpp index 4f6daf7c8..7601d537e 100644 --- a/Storage/Disk/Controller/DiskController.cpp +++ b/Storage/Disk/Controller/DiskController.cpp @@ -15,7 +15,7 @@ using namespace Storage::Disk; Controller::Controller(Cycles clock_rate) : clock_rate_multiplier_(128000000 / clock_rate.as_int()), clock_rate_(clock_rate.as_int() * clock_rate_multiplier_), - empty_drive_(new Drive((unsigned int)clock_rate.as_int(), 1, 1)) { + empty_drive_(new Drive(static_cast(clock_rate.as_int()), 1, 1)) { // seed this class with a PLL, any PLL, so that it's safe to assume non-nullptr later Time one(1); set_expected_bit_length(one); @@ -66,7 +66,7 @@ void Controller::set_expected_bit_length(Time bit_length) { // this conversion doesn't need to be exact because there's a lot of variation to be taken // account of in rotation speed, air turbulence, etc, so a direct conversion will do - int clocks_per_bit = (int)cycles_per_bit.get_unsigned_int(); + int clocks_per_bit = static_cast(cycles_per_bit.get_unsigned_int()); pll_.reset(new DigitalPhaseLockedLoop(clocks_per_bit, 3)); pll_->set_delegate(this); } diff --git a/Storage/Disk/Controller/MFMDiskController.cpp b/Storage/Disk/Controller/MFMDiskController.cpp index 2587559ac..55e57c4b7 100644 --- a/Storage/Disk/Controller/MFMDiskController.cpp +++ b/Storage/Disk/Controller/MFMDiskController.cpp @@ -20,11 +20,11 @@ MFMController::MFMController(Cycles clock_rate) : } void MFMController::process_index_hole() { - posit_event((int)Event::IndexHole); + posit_event(static_cast(Event::IndexHole)); } void MFMController::process_write_completed() { - posit_event((int)Event::DataWritten); + posit_event(static_cast(Event::DataWritten)); } void MFMController::set_is_double_density(bool is_double_density) { @@ -82,7 +82,7 @@ void MFMController::process_input_bit(int value) { break; } latest_token_.byte_value = shifter_.get_byte(); - posit_event((int)Event::Token); + posit_event(static_cast(Event::Token)); } void MFMController::write_bit(int bit) { diff --git a/Storage/Disk/DiskImage/Formats/AcornADF.cpp b/Storage/Disk/DiskImage/Formats/AcornADF.cpp index 07a083675..8e063224f 100644 --- a/Storage/Disk/DiskImage/Formats/AcornADF.cpp +++ b/Storage/Disk/DiskImage/Formats/AcornADF.cpp @@ -20,8 +20,8 @@ using namespace Storage::Disk; AcornADF::AcornADF(const char *file_name) : MFMSectorDump(file_name) { // very loose validation: the file needs to be a multiple of 256 bytes // and not ungainly large - if(file_stats_.st_size % (off_t)(128 << sector_size)) throw ErrorNotAcornADF; - if(file_stats_.st_size < 7 * (off_t)(128 << sector_size)) throw ErrorNotAcornADF; + if(file_stats_.st_size % static_cast(128 << sector_size)) throw ErrorNotAcornADF; + if(file_stats_.st_size < 7 * static_cast(128 << sector_size)) throw ErrorNotAcornADF; // check that the initial directory's 'Hugo's are present fseek(file_, 513, SEEK_SET); diff --git a/Storage/Disk/DiskImage/Formats/CPCDSK.cpp b/Storage/Disk/DiskImage/Formats/CPCDSK.cpp index f5fdf76c9..ed8e273b8 100644 --- a/Storage/Disk/DiskImage/Formats/CPCDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/CPCDSK.cpp @@ -30,7 +30,7 @@ CPCDSK::CPCDSK(const char *file_name) : // Skip two unused bytes and grab the track size table. fseek(file_, 2, SEEK_CUR); for(int c = 0; c < head_position_count_ * head_count_; c++) { - track_sizes_.push_back((size_t)(fgetc(file_) << 8)); + track_sizes_.push_back(static_cast(fgetc(file_) << 8)); } } else { size_of_a_track_ = fgetc16le(); @@ -76,8 +76,8 @@ std::shared_ptr 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(fgetc(file_)); + uint8_t filler_byte = static_cast(fgetc(file_)); // Grab the sector information struct SectorInfo { @@ -93,12 +93,12 @@ std::shared_ptr 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(fgetc(file_)); + sector_info.side = static_cast(fgetc(file_)); + sector_info.sector = static_cast(fgetc(file_)); + sector_info.length = static_cast(fgetc(file_)); + sector_info.status1 = static_cast(fgetc(file_)); + sector_info.status2 = static_cast(fgetc(file_)); sector_info.actual_length = fgetc16le(); sector_infos.push_back(sector_info); @@ -118,7 +118,7 @@ std::shared_ptr CPCDSK::get_track_at_position(Track::Address address) { if(is_extended_) { data_size = sector_info.actual_length; } else { - data_size = (size_t)(128 << sector_info.length); + data_size = static_cast(128 << sector_info.length); if(data_size == 0x2000) data_size = 0x1800; } new_sector.data.resize(data_size); diff --git a/Storage/Disk/DiskImage/Formats/D64.cpp b/Storage/Disk/DiskImage/Formats/D64.cpp index 619ff2197..ce7433341 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((disk_id_ << 2) ^ (disk_id_ >> 13)); file_name++; } } @@ -84,8 +84,8 @@ std::shared_ptr D64::get_track_at_position(Track::Address address) { // = 349 GCR bytes per sector PCMSegment track; - size_t track_bytes = 349 * (size_t)sectors_by_zone[zone]; - track.number_of_bits = (unsigned int)track_bytes * 8; + size_t track_bytes = 349 * static_cast(sectors_by_zone[zone]); + track.number_of_bits = static_cast(track_bytes) * 8; track.data.resize(track_bytes); uint8_t *data = &track.data[0]; @@ -95,16 +95,16 @@ std::shared_ptr 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(sector); // sectors count from 0 + uint8_t track_number = static_cast((address.position >> 1) + 1); // tracks count from 1 + uint8_t checksum = static_cast(sector_number ^ track_number ^ disk_id_ ^ (disk_id_ >> 8)); uint8_t header_start[4] = { 0x08, checksum, sector_number, track_number }; Encodings::CommodoreGCR::encode_block(§or_data[3], header_start); uint8_t header_end[4] = { - (uint8_t)(disk_id_ & 0xff), (uint8_t)(disk_id_ >> 8), 0, 0 + static_cast(disk_id_ & 0xff), static_cast(disk_id_ >> 8), 0, 0 }; Encodings::CommodoreGCR::encode_block(§or_data[8], header_end); diff --git a/Storage/Disk/DiskImage/Formats/G64.cpp b/Storage/Disk/DiskImage/Formats/G64.cpp index b2bac6d1d..80b368661 100644 --- a/Storage/Disk/DiskImage/Formats/G64.cpp +++ b/Storage/Disk/DiskImage/Formats/G64.cpp @@ -43,7 +43,7 @@ std::shared_ptr G64::get_track_at_position(Track::Address address) { if(address.head >= 1) return resulting_track; // seek to this track's entry in the track table - fseek(file_, (long)((address.position * 4) + 0xc), SEEK_SET); + fseek(file_, static_cast((address.position * 4) + 0xc), SEEK_SET); // read the track offset uint32_t track_offset; @@ -53,7 +53,7 @@ std::shared_ptr G64::get_track_at_position(Track::Address address) { if(!track_offset) return resulting_track; // seek to the track start - fseek(file_, (int)track_offset, SEEK_SET); + fseek(file_, static_cast(track_offset), SEEK_SET); // get the real track length uint16_t track_length; @@ -64,7 +64,7 @@ std::shared_ptr G64::get_track_at_position(Track::Address address) { fread(&track_contents[0], 1, track_length, file_); // seek to this track's entry in the speed zone table - fseek(file_, (long)((address.position * 4) + 0x15c), SEEK_SET); + fseek(file_, static_cast((address.position * 4) + 0x15c), SEEK_SET); // read the speed zone offsrt uint32_t speed_zone_offset; @@ -73,7 +73,7 @@ std::shared_ptr G64::get_track_at_position(Track::Address address) { // if the speed zone is not constant, create a track based on the whole table; otherwise create one that's constant if(speed_zone_offset > 3) { // seek to start of speed zone - fseek(file_, (int)speed_zone_offset, SEEK_SET); + fseek(file_, static_cast(speed_zone_offset), SEEK_SET); uint16_t speed_zone_length = (track_length + 3) >> 2; @@ -106,7 +106,7 @@ std::shared_ptr G64::get_track_at_position(Track::Address address) { } else { PCMSegment segment; segment.number_of_bits = track_length * 8; - segment.length_of_a_bit = Encodings::CommodoreGCR::length_of_a_bit_in_time_zone((unsigned int)speed_zone_offset); + segment.length_of_a_bit = Encodings::CommodoreGCR::length_of_a_bit_in_time_zone(static_cast(speed_zone_offset)); segment.data = std::move(track_contents); resulting_track.reset(new PCMTrack(std::move(segment))); diff --git a/Storage/Disk/DiskImage/Formats/HFE.cpp b/Storage/Disk/DiskImage/Formats/HFE.cpp index a0068b38a..c067399e1 100644 --- a/Storage/Disk/DiskImage/Formats/HFE.cpp +++ b/Storage/Disk/DiskImage/Formats/HFE.cpp @@ -23,7 +23,7 @@ HFE::HFE(const char *file_name) : head_count_ = fgetc(file_); fseek(file_, 7, SEEK_CUR); - track_list_offset_ = (long)fgetc16le() << 9; + track_list_offset_ = static_cast(fgetc16le() << 9); } HFE::~HFE() { @@ -49,7 +49,7 @@ uint16_t HFE::seek_track(Track::Address address) { // based on an assumption of two heads. fseek(file_, track_list_offset_ + address.position * 4, SEEK_SET); - long track_offset = (long)fgetc16le() << 9; + long track_offset = static_cast(fgetc16le() << 9); uint16_t track_length = fgetc16le(); fseek(file_, track_offset, SEEK_SET); @@ -69,7 +69,7 @@ std::shared_ptr 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(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> &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(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/DiskImage/Formats/OricMFMDSK.cpp b/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp index 5a5c7b94e..e9ec533bf 100644 --- a/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp @@ -108,7 +108,7 @@ std::shared_ptr OricMFMDSK::get_track_at_position(Track::Address address) } } - segment.number_of_bits = (unsigned int)(segment.data.size() * 8); + segment.number_of_bits = static_cast(segment.data.size() * 8); std::shared_ptr track(new PCMTrack(segment)); return track; @@ -158,7 +158,7 @@ void OricMFMDSK::set_tracks(const std::map lock_guard(file_access_mutex_); fseek(file_, file_offset, SEEK_SET); - size_t track_size = std::min((size_t)6400, parsed_track.size()); + size_t track_size = std::min(static_cast(6400), parsed_track.size()); fwrite(parsed_track.data(), 1, track_size, file_); } } diff --git a/Storage/Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp b/Storage/Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp index a151029af..21ab01df6 100644 --- a/Storage/Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp +++ b/Storage/Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp @@ -19,7 +19,7 @@ using namespace Storage::Disk; std::shared_ptr Storage::Disk::track_for_sectors(uint8_t *const source, uint8_t track, uint8_t side, uint8_t first_sector, uint8_t size, bool is_double_density) { std::vector sectors; - off_t byte_size = (off_t)(128 << size); + off_t byte_size = static_cast(128 << size); off_t source_pointer = 0; for(int sector = 0; sector < 10; sector++) { sectors.emplace_back(); @@ -48,7 +48,7 @@ void Storage::Disk::decode_sectors(Track &track, uint8_t *const destination, uin Storage::Disk::track_serialisation(track, is_double_density ? Storage::Encodings::MFM::MFMBitLength : Storage::Encodings::MFM::FMBitLength), is_double_density); - size_t byte_size = (size_t)(128 << sector_size); + size_t byte_size = static_cast(128 << sector_size); for(auto &pair : sectors) { if(pair.second.address.sector > last_sector) continue; if(pair.second.address.sector < first_sector) continue; diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index e94df592a..3e809e3d6 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -67,7 +67,7 @@ void Drive::set_head(int head) { Storage::Time Drive::get_time_into_track() { // `result` will initially be amount of time since the index hole was seen as a // proportion of a second; convert it into proportion of a rotation, simplify and return. - Time result(cycles_since_index_hole_, (int)get_input_clock_rate()); + Time result(cycles_since_index_hole_, static_cast(get_input_clock_rate())); result /= rotational_multiplier_; result.simplify(); assert(result <= Time(1)); @@ -102,7 +102,7 @@ void Drive::set_event_delegate(Storage::Disk::Drive::EventDelegate *delegate) { } void Drive::advance(const Cycles cycles) { - cycles_since_index_hole_ += (unsigned int)cycles.as_int(); + cycles_since_index_hole_ += static_cast(cycles.as_int()); if(event_delegate_) event_delegate_->advance(cycles); } @@ -112,10 +112,10 @@ void Drive::run_for(const Cycles cycles) { int number_of_cycles = cycles.as_int(); while(number_of_cycles) { - int cycles_until_next_event = (int)get_cycles_until_next_event(); + int cycles_until_next_event = static_cast(get_cycles_until_next_event()); int cycles_to_run_for = std::min(cycles_until_next_event, number_of_cycles); if(!is_reading_ && cycles_until_bits_written_ > zero) { - int write_cycles_target = (int)cycles_until_bits_written_.get_unsigned_int(); + int write_cycles_target = static_cast(cycles_until_bits_written_.get_unsigned_int()); if(cycles_until_bits_written_.length % cycles_until_bits_written_.clock_rate) write_cycles_target++; cycles_to_run_for = std::min(cycles_to_run_for, write_cycles_target); } diff --git a/Storage/Disk/Encodings/MFM/Encoder.cpp b/Storage/Disk/Encodings/MFM/Encoder.cpp index e4dc91bf3..d01da9420 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( ((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((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( ((input & 0x01) << 0) | ((input & 0x02) << 1) | ((input & 0x04) << 2) | @@ -161,7 +161,7 @@ template std::shared_ptr shifter.add_data_address_mark(); size_t c = 0; - size_t declared_length = (size_t)(128 << sector.size); + size_t declared_length = static_cast(128 << sector.size); for(c = 0; c < sector.data.size() && c < declared_length; c++) { shifter.add_byte(sector.data[c]); } @@ -181,7 +181,7 @@ template std::shared_ptr size_t max_size = expected_track_bytes + (expected_track_bytes / 10); if(segment.data.size() > max_size) segment.data.resize(max_size); - segment.number_of_bits = (unsigned int)(segment.data.size() * 8); + segment.number_of_bits = static_cast(segment.data.size() * 8); return std::shared_ptr(new Storage::Disk::PCMTrack(std::move(segment))); } @@ -200,7 +200,7 @@ void Encoder::add_crc(bool incorrectly) { add_byte((crc_value & 0xff) ^ (incorrectly ? 1 : 0)); } -const size_t Storage::Encodings::MFM::DefaultSectorGapLength = (size_t)~0; +const size_t Storage::Encodings::MFM::DefaultSectorGapLength = std::numeric_limits::max(); std::shared_ptr Storage::Encodings::MFM::GetFMTrackWithSectors(const std::vector §ors, size_t sector_gap_length, uint8_t sector_gap_filler_byte) { return GetTrackWithSectors( diff --git a/Storage/Disk/Encodings/MFM/SegmentParser.cpp b/Storage/Disk/Encodings/MFM/SegmentParser.cpp index dcec44d05..25fed0618 100644 --- a/Storage/Disk/Encodings/MFM/SegmentParser.cpp +++ b/Storage/Disk/Encodings/MFM/SegmentParser.cpp @@ -56,7 +56,7 @@ std::map Storage::Encodings::MFM::secto case 2: new_sector->address.sector = shifter.get_byte(); ++position; break; case 3: new_sector->size = shifter.get_byte(); - size = (size_t)(128 << new_sector->size); + size = static_cast(128 << new_sector->size); ++position; is_reading = false; shifter.set_should_obey_syncs(true); diff --git a/Storage/Disk/Parsers/CPM.cpp b/Storage/Disk/Parsers/CPM.cpp index 2931bf3bc..0a4889664 100644 --- a/Storage/Disk/Parsers/CPM.cpp +++ b/Storage/Disk/Parsers/CPM.cpp @@ -40,7 +40,7 @@ std::unique_ptr Storage::Disk::CPM::GetCatalogue( sector = 0; track++; } - } while(size_read < (size_t)parameters.block_size); + } while(size_read < static_cast(parameters.block_size)); } catalogue_allocation_bitmap <<= 1; @@ -77,7 +77,7 @@ std::unique_ptr Storage::Disk::CPM::GetCatalogue( for(size_t s = 0; s < 3; s++) entry.type.push_back((char)catalogue[c + s + 9] & 0x7f); entry.read_only = catalogue[c + 9] & 0x80; entry.system = catalogue[c + 10] & 0x80; - entry.extent = (size_t)(catalogue[c + 12] + (catalogue[c + 14] << 5)); + entry.extent = static_cast(catalogue[c + 12] + (catalogue[c + 14] << 5)); entry.number_of_records = catalogue[c + 15]; entry.catalogue_index = c; } @@ -87,10 +87,10 @@ std::unique_ptr Storage::Disk::CPM::GetCatalogue( std::unique_ptr result(new Catalogue); - bool has_long_allocation_units = (parameters.tracks * parameters.sectors_per_track * (int)sector_size / parameters.block_size) >= 256; - size_t bytes_per_catalogue_entry = (has_long_allocation_units ? 8 : 16) * (size_t)parameters.block_size; - int sectors_per_block = parameters.block_size / (int)sector_size; - int records_per_sector = (int)sector_size / 128; + bool has_long_allocation_units = (parameters.tracks * parameters.sectors_per_track * static_cast(sector_size) / parameters.block_size) >= 256; + size_t bytes_per_catalogue_entry = (has_long_allocation_units ? 8 : 16) * static_cast(parameters.block_size); + int sectors_per_block = parameters.block_size / static_cast(sector_size); + int records_per_sector = static_cast(sector_size) / 128; auto entry = catalogue_entries.begin(); while(entry != catalogue_entries.end()) { @@ -111,7 +111,7 @@ std::unique_ptr Storage::Disk::CPM::GetCatalogue( new_file.system = entry->system; // Create storage for data. - size_t required_size = final_entry->extent * bytes_per_catalogue_entry + (size_t)final_entry->number_of_records * 128; + size_t required_size = final_entry->extent * bytes_per_catalogue_entry + static_cast(final_entry->number_of_records) * 128; new_file.data.resize(required_size); // Accumulate all data. @@ -144,7 +144,7 @@ std::unique_ptr Storage::Disk::CPM::GetCatalogue( } int records_to_copy = std::min(entry->number_of_records - record, records_per_sector); - memcpy(&new_file.data[entry->extent * bytes_per_catalogue_entry + (size_t)record * 128], sector_contents->data.data(), (size_t)records_to_copy * 128); + memcpy(&new_file.data[entry->extent * bytes_per_catalogue_entry + static_cast(record) * 128], sector_contents->data.data(), static_cast(records_to_copy) * 128); record += records_to_copy; } } diff --git a/Storage/Disk/Track/PCMSegment.cpp b/Storage/Disk/Track/PCMSegment.cpp index ea73bf2a9..acac4b0cc 100644 --- a/Storage/Disk/Track/PCMSegment.cpp +++ b/Storage/Disk/Track/PCMSegment.cpp @@ -109,5 +109,5 @@ Storage::Time PCMSegmentEventSource::seek_to(const Time &time_from_start) { bit_pointer_ = 1 + (relative_time / segment_->length_of_a_bit).get_unsigned_int(); // map up to the correct amount of time - return half_bit_length + segment_->length_of_a_bit * (unsigned int)(bit_pointer_ - 1); + return half_bit_length + segment_->length_of_a_bit * static_cast(bit_pointer_ - 1); } diff --git a/Storage/Disk/Track/TrackSerialiser.cpp b/Storage/Disk/Track/TrackSerialiser.cpp index 09310a927..af7b0a387 100644 --- a/Storage/Disk/Track/TrackSerialiser.cpp +++ b/Storage/Disk/Track/TrackSerialiser.cpp @@ -40,7 +40,7 @@ Storage::Disk::PCMSegment Storage::Disk::track_serialisation(Track &track, Time Time extended_length = next_event.length * length_multiplier + time_error; time_error.clock_rate = extended_length.clock_rate; time_error.length = extended_length.length % extended_length.clock_rate; - pll.run_for(Cycles((int)extended_length.get_unsigned_int())); + pll.run_for(Cycles(static_cast(extended_length.get_unsigned_int()))); pll.add_pulse(); // If the PLL is now sufficiently primed, restart, and start recording bits this time. diff --git a/Storage/FileHolder.cpp b/Storage/FileHolder.cpp index c369dc1fd..f8c357d69 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(fgetc(file_)); + result |= static_cast(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(fgetc(file_) << 8); + result |= static_cast(fgetc(file_)); return result; } @@ -85,9 +85,9 @@ void FileHolder::ensure_file_is_at_least_length(long length) { fseek(file_, 0, SEEK_END); long bytes_to_write = length - ftell(file_); if(bytes_to_write > 0) { - uint8_t *empty = new uint8_t[(size_t)bytes_to_write]; - memset(empty, 0, (size_t)bytes_to_write); - fwrite(empty, sizeof(uint8_t), (size_t)bytes_to_write, file_); + uint8_t *empty = new uint8_t[static_cast(bytes_to_write)]; + memset(empty, 0, static_cast(bytes_to_write)); + fwrite(empty, sizeof(uint8_t), static_cast(bytes_to_write), file_); delete[] empty; } } 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((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(fgetc(file_)); } uint8_t bit; diff --git a/Storage/Storage.hpp b/Storage/Storage.hpp index bb6ccd3aa..c55364356 100644 --- a/Storage/Storage.hpp +++ b/Storage/Storage.hpp @@ -24,9 +24,9 @@ struct Time { unsigned int length, clock_rate; Time() : length(0), clock_rate(1) {} Time(unsigned int unsigned_int_value) : length(unsigned_int_value), clock_rate(1) {} - Time(int int_value) : Time((unsigned int)int_value) {} + Time(int int_value) : Time(static_cast(int_value)) {} Time(unsigned int length, unsigned int clock_rate) : length(length), clock_rate(clock_rate) {} - Time(int length, int clock_rate) : Time((unsigned int)length, (unsigned int)clock_rate) {} + Time(int length, int clock_rate) : Time(static_cast(length), static_cast(clock_rate)) {} Time(uint64_t length, uint64_t clock_rate) { install_result(length, clock_rate); } @@ -48,7 +48,7 @@ struct Time { @returns the floating point conversion of this @c Time. This will often be less precise. */ inline float get_float() const { - return (float)length / (float)clock_rate; + return static_cast(length) / static_cast(clock_rate); } inline unsigned int get_unsigned_int() const { @@ -210,8 +210,8 @@ struct Time { private: inline void install_result(uint64_t long_length, uint64_t long_clock_rate) { if(long_length <= std::numeric_limits::max() && long_clock_rate <= std::numeric_limits::max()) { - length = (unsigned int)long_length; - clock_rate = (unsigned int)long_clock_rate; + length = static_cast(long_length); + clock_rate = static_cast(long_clock_rate); return; } @@ -247,8 +247,8 @@ struct Time { } if(long_length <= std::numeric_limits::max() && long_clock_rate <= std::numeric_limits::max()) { - length = (unsigned int)long_length; - clock_rate = (unsigned int)long_clock_rate; + length = static_cast(long_length); + clock_rate = static_cast(long_clock_rate); } else { length = std::numeric_limits::max(); clock_rate = 1u; diff --git a/Storage/Tape/Formats/CSW.cpp b/Storage/Tape/Formats/CSW.cpp index 89c399b49..102c15dea 100644 --- a/Storage/Tape/Formats/CSW.cpp +++ b/Storage/Tape/Formats/CSW.cpp @@ -62,19 +62,19 @@ CSW::CSW(const char *file_name) : // The only clue given by CSW as to the output size in bytes is that there will be // number_of_waves waves. Waves are usually one byte, but may be five. So this code // is pessimistic. - source_data_.resize((size_t)number_of_waves * 5); + source_data_.resize(static_cast(number_of_waves) * 5); std::vector file_data; - size_t remaining_data = (size_t)file_stats_.st_size - (size_t)ftell(file_); + size_t remaining_data = static_cast(file_stats_.st_size) - static_cast(ftell(file_)); file_data.resize(remaining_data); fread(file_data.data(), sizeof(uint8_t), remaining_data, file_); // 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(number_of_waves * 5); uncompress(source_data_.data(), &output_length, file_data.data(), file_data.size()); - source_data_.resize((size_t)output_length); + source_data_.resize(static_cast(output_length)); } else { rle_start_ = ftell(file_); } 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(fgetc(file_)); - if(phase_counter_ == 4) data_end_address_ = (uint16_t)(next_byte << 8); + if(phase_counter_ == 4) data_end_address_ = static_cast(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(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((static_cast(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/TZX.cpp b/Storage/Tape/Formats/TZX.cpp index ee0028464..0cd130ccb 100644 --- a/Storage/Tape/Formats/TZX.cpp +++ b/Storage/Tape/Formats/TZX.cpp @@ -91,7 +91,7 @@ void TZX::get_next_pulses() { void TZX::get_generalised_data_block() { uint32_t block_length = fgetc32le(); - long endpoint = ftell(file_) + (long)block_length; + long endpoint = ftell(file_) + static_cast(block_length); uint16_t pause_after_block = fgetc16le(); uint32_t total_pilot_symbols = fgetc32le(); @@ -200,7 +200,7 @@ void TZX::get_turbo_speed_data_block() { data_block.data.number_of_bits_in_final_byte = static_cast(fgetc(file_)); data_block.data.pause_after_block = fgetc16le(); data_block.data.data_length = fgetc16le(); - data_block.data.data_length |= (long)(fgetc(file_) << 16); + data_block.data.data_length |= static_cast(fgetc(file_) << 16); get_data_block(data_block); } @@ -251,7 +251,7 @@ void TZX::get_pure_data_block() { data.number_of_bits_in_final_byte = static_cast(fgetc(file_)); data.pause_after_block = fgetc16le(); data.data_length = fgetc16le(); - data.data_length |= (long)(fgetc(file_) << 16); + data.data_length |= static_cast(fgetc(file_) << 16); get_data(data); } 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(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 b99140a87..cb59703fc 100644 --- a/Storage/Tape/Formats/TapeUEF.cpp +++ b/Storage/Tape/Formats/TapeUEF.cpp @@ -25,14 +25,14 @@ static float gzgetfloat(gzFile file) { int mantissa; mantissa = bytes[0] | (bytes[1] << 8) | ((bytes[2]&0x7f)|0x80) << 16; - float result = (float)mantissa; - result = (float)ldexp(result, -23); + float result = static_cast(mantissa); + result = static_cast(ldexp(result, -23)); /* decode exponent */ int exponent; exponent = ((bytes[2]&0x80) >> 7) | (bytes[3]&0x7f) << 1; exponent -= 127; - result = (float)ldexp(result, exponent); + result = static_cast(ldexp(result, exponent)); /* flip sign if necessary */ if(bytes[3]&0x80) @@ -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(gzget16(file_)); uint32_t chunk_length = (uint32_t)gzget32(file_); z_off_t start_of_next_chunk = gztell(file_) + chunk_length; @@ -145,7 +145,7 @@ void UEF::get_next_pulses() { case 0x0113: { // TODO: something smarter than just converting this to an int float new_time_base = gzgetfloat(file_); - time_base_ = (unsigned int)roundf(new_time_base); + time_base_ = static_cast(roundf(new_time_base)); } break; @@ -173,7 +173,7 @@ void UEF::queue_implicit_bit_pattern(uint32_t length) { } void UEF::queue_explicit_bit_pattern(uint32_t length) { - size_t length_in_bits = (length << 3) - (size_t)gzget8(file_); + size_t length_in_bits = (length << 3) - static_cast(gzget8(file_)); uint8_t current_byte = 0; for(size_t bit = 0; bit < length_in_bits; bit++) { if(!(bit&7)) current_byte = gzget8(file_); @@ -184,7 +184,7 @@ void UEF::queue_explicit_bit_pattern(uint32_t length) { void UEF::queue_integer_gap() { Time duration; - duration.length = (unsigned int)gzget16(file_); + duration.length = static_cast(gzget16(file_)); duration.clock_rate = time_base_; emplace_back(Pulse::Zero, duration); } @@ -192,19 +192,19 @@ void UEF::queue_integer_gap() { void UEF::queue_floating_point_gap() { float length = gzgetfloat(file_); Time duration; - duration.length = (unsigned int)(length * 4000000); + duration.length = static_cast(length * 4000000); duration.clock_rate = 4000000; emplace_back(Pulse::Zero, duration); } void UEF::queue_carrier_tone() { - unsigned int number_of_cycles = (unsigned int)gzget16(file_); + unsigned int number_of_cycles = static_cast(gzget16(file_)); while(number_of_cycles--) queue_bit(1); } void UEF::queue_carrier_tone_with_dummy() { - unsigned int pre_cycles = (unsigned int)gzget16(file_); - unsigned int post_cycles = (unsigned int)gzget16(file_); + unsigned int pre_cycles = static_cast(gzget16(file_)); + unsigned int post_cycles = static_cast(gzget16(file_)); while(pre_cycles--) queue_bit(1); queue_implicit_byte(0xaa); while(post_cycles--) queue_bit(1); diff --git a/Storage/Tape/Formats/ZX80O81P.cpp b/Storage/Tape/Formats/ZX80O81P.cpp index 82b33bcc1..a446e1be3 100644 --- a/Storage/Tape/Formats/ZX80O81P.cpp +++ b/Storage/Tape/Formats/ZX80O81P.cpp @@ -15,8 +15,8 @@ ZX80O81P::ZX80O81P(const char *file_name) : Storage::FileHolder(file_name) { // Grab the actual file contents - data_.resize((size_t)file_stats_.st_size); - fread(data_.data(), 1, (size_t)file_stats_.st_size, file_); + data_.resize(static_cast(file_stats_.st_size)); + fread(data_.data(), 1, static_cast(file_stats_.st_size), file_); // If it's a ZX81 file, prepend a file name. std::string type = extension(); diff --git a/Storage/Tape/Parsers/Acorn.cpp b/Storage/Tape/Parsers/Acorn.cpp index 3bcb2f496..627f02eac 100644 --- a/Storage/Tape/Parsers/Acorn.cpp +++ b/Storage/Tape/Parsers/Acorn.cpp @@ -75,7 +75,7 @@ Shifter::Shifter() : } void Shifter::process_pulse(const Storage::Tape::Tape::Pulse &pulse) { - pll_.run_for(Cycles((int)((float)PLLClockRate * pulse.length.get_float()))); + pll_.run_for(Cycles(static_cast(static_cast(PLLClockRate) * pulse.length.get_float()))); bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High; if(is_high != was_high_) { @@ -85,10 +85,10 @@ void Shifter::process_pulse(const Storage::Tape::Tape::Pulse &pulse) { } void Shifter::digital_phase_locked_loop_output_bit(int value) { - input_pattern_ = ((input_pattern_ << 1) | (unsigned int)value) & 0xf; + input_pattern_ = ((input_pattern_ << 1) | static_cast(value)) & 0xf; switch(input_pattern_) { case 0x5: delegate_->acorn_shifter_output_bit(0); input_pattern_ = 0; break; case 0xf: delegate_->acorn_shifter_output_bit(1); input_pattern_ = 0; break; - default: break;; + default: break; } } 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
Parser::get_next_header_body(const std::shared_ptrtype != 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(header->data[0] | (header->data[1] << 8)); + header->ending_address = static_cast(header->data[2] | (header->data[3] << 8)); for(size_t c = 0; c < 16; c++) { diff --git a/Storage/Tape/Parsers/Oric.cpp b/Storage/Tape/Parsers/Oric.cpp index 1c64dc687..ec448c624 100644 --- a/Storage/Tape/Parsers/Oric.cpp +++ b/Storage/Tape/Parsers/Oric.cpp @@ -159,7 +159,7 @@ void Parser::inspect_waves(const std::vector &waves) } if(slow_sync_matching_depth < waves.size() && fast_sync_matching_depth < waves.size()) { - int least_depth = (int)std::min(slow_sync_matching_depth, fast_sync_matching_depth); + int least_depth = static_cast(std::min(slow_sync_matching_depth, fast_sync_matching_depth)); remove_waves(least_depth ? least_depth : 1); } diff --git a/Storage/Tape/Parsers/ZX8081.cpp b/Storage/Tape/Parsers/ZX8081.cpp index dcd0a0134..34e489552 100644 --- a/Storage/Tape/Parsers/ZX8081.cpp +++ b/Storage/Tape/Parsers/ZX8081.cpp @@ -81,9 +81,9 @@ void Parser::inspect_waves(const std::vector &waves) { // check are 8 and 3. size_t gaps_to_swallow = wave_offset + ((waves[number_of_pulses + wave_offset] == WaveType::Gap) ? 1 : 0); switch(number_of_pulses) { - case 8: push_symbol(SymbolType::One, (int)(number_of_pulses + gaps_to_swallow)); break; - case 3: push_symbol(SymbolType::Zero, (int)(number_of_pulses + gaps_to_swallow)); break; - default: push_symbol(SymbolType::Unrecognised, 1); break; + case 8: push_symbol(SymbolType::One, static_cast(number_of_pulses + gaps_to_swallow)); break; + case 3: push_symbol(SymbolType::Zero, static_cast(number_of_pulses + gaps_to_swallow)); break; + default: push_symbol(SymbolType::Unrecognised, 1); break; } } } diff --git a/Storage/TimedEventLoop.cpp b/Storage/TimedEventLoop.cpp index 43d1aee86..577192f38 100644 --- a/Storage/TimedEventLoop.cpp +++ b/Storage/TimedEventLoop.cpp @@ -46,7 +46,7 @@ void TimedEventLoop::run_for(const Cycles cycles) { } unsigned int TimedEventLoop::get_cycles_until_next_event() { - return (unsigned int)std::max(cycles_until_event_, 0); + return static_cast(std::max(cycles_until_event_, 0)); } unsigned int TimedEventLoop::get_input_clock_rate() { @@ -80,10 +80,10 @@ void TimedEventLoop::set_next_event_time_interval(Time interval) { // So this event will fire in the integral number of cycles from now, putting us at the remainder // number of subcycles assert(cycles_until_event_ == 0); - cycles_until_event_ += (int)(numerator / denominator); + cycles_until_event_ += static_cast(numerator / denominator); assert(cycles_until_event_ >= 0); - subcycles_until_event_.length = (unsigned int)(numerator % denominator); - subcycles_until_event_.clock_rate = (unsigned int)denominator; + subcycles_until_event_.length = static_cast(numerator % denominator); + subcycles_until_event_.clock_rate = static_cast(denominator); subcycles_until_event_.simplify(); }