From ec999446e8bd4f4430e1be4609001a48911f4fdb Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 21 Oct 2017 21:00:40 -0400 Subject: [PATCH] Commutes `int` and `unsigned` casts to the functional style. --- Components/1770/1770.cpp | 32 +++++----- Components/8272/i8272.cpp | 52 ++++++++-------- Components/8272/i8272.hpp | 2 +- Components/AY38910/AY38910.cpp | 12 ++-- Machines/AmstradCPC/AmstradCPC.cpp | 2 +- Machines/Atari2600/TIA.cpp | 60 +++++++++---------- Machines/Commodore/SerialBus.cpp | 6 +- Machines/Electron/Electron.cpp | 14 ++--- Outputs/CRT/CRT.cpp | 14 ++--- Outputs/CRT/Internals/Flywheel.hpp | 2 +- StaticAnalyser/Commodore/Disk.cpp | 2 +- Storage/Disk/Controller/DiskController.cpp | 2 +- Storage/Disk/Controller/MFMDiskController.cpp | 6 +- Storage/Disk/DiskImage/Formats/G64.cpp | 4 +- Storage/Disk/Drive.cpp | 6 +- Storage/Disk/Parsers/CPM.cpp | 6 +- Storage/Disk/Track/TrackSerialiser.cpp | 2 +- Storage/Tape/Parsers/Acorn.cpp | 2 +- Storage/Tape/Parsers/Oric.cpp | 2 +- Storage/Tape/Parsers/ZX8081.cpp | 6 +- Storage/TimedEventLoop.cpp | 2 +- 21 files changed, 118 insertions(+), 118 deletions(-) diff --git a/Components/1770/1770.cpp b/Components/1770/1770.cpp index 9d4343949..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; @@ -118,21 +118,21 @@ void WD1770::run_for(const Cycles cycles) { 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/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 499795a07..85d8d5f21 100644 --- a/Components/AY38910/AY38910.cpp +++ b/Components/AY38910/AY38910.cpp @@ -67,7 +67,7 @@ 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, static_cast(v ^ 0xf))); + volumes_[v] = static_cast(max_volume / powf(root_two, static_cast(v ^ 0xf))); } volumes_[0] = 0; } @@ -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..5d5c44188 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -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/TIA.cpp b/Machines/Atari2600/TIA.cpp index 4c3f5ba4b..c9eb7404c 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); } } } @@ -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) { @@ -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]]; 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/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index cb39fc39f..9bec3bd22 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -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(); @@ -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/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 5474e378d..16705bb36 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -403,10 +403,10 @@ 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(static_cast(first_cycle_after_sync) < horizontal_retrace_period) first_cycle_after_sync = (int)horizontal_retrace_period; - if(static_cast(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 = static_cast((unsigned)first_cycle_after_sync - horizontal_retrace_period) / static_cast(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 @@ -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 = static_cast(((unsigned)first_line_after_sync * horizontal_period) - vertical_retrace_period) / static_cast(vertical_scan_period); - float height = static_cast((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/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/StaticAnalyser/Commodore/Disk.cpp b/StaticAnalyser/Commodore/Disk.cpp index cd384116b..5fda286b7 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) { diff --git a/Storage/Disk/Controller/DiskController.cpp b/Storage/Disk/Controller/DiskController.cpp index 3acb59ead..7601d537e 100644 --- a/Storage/Disk/Controller/DiskController.cpp +++ b/Storage/Disk/Controller/DiskController.cpp @@ -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/G64.cpp b/Storage/Disk/DiskImage/Formats/G64.cpp index 5eaf2848d..be0b921ff 100644 --- a/Storage/Disk/DiskImage/Formats/G64.cpp +++ b/Storage/Disk/DiskImage/Formats/G64.cpp @@ -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; @@ -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; diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index babbd362d..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)); @@ -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/Parsers/CPM.cpp b/Storage/Disk/Parsers/CPM.cpp index 2931bf3bc..0dded7a4e 100644 --- a/Storage/Disk/Parsers/CPM.cpp +++ b/Storage/Disk/Parsers/CPM.cpp @@ -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; + 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) * (size_t)parameters.block_size; - int sectors_per_block = parameters.block_size / (int)sector_size; - int records_per_sector = (int)sector_size / 128; + 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()) { 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/Tape/Parsers/Acorn.cpp b/Storage/Tape/Parsers/Acorn.cpp index fefef8601..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)(static_cast(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_) { 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 051386cbf..577192f38 100644 --- a/Storage/TimedEventLoop.cpp +++ b/Storage/TimedEventLoop.cpp @@ -80,7 +80,7 @@ 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 = static_cast(numerator % denominator); subcycles_until_event_.clock_rate = static_cast(denominator);