From 5456a4a39dc51f912889b62a48a842e509644821 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Dec 2019 13:42:24 -0500 Subject: [PATCH] Eliminates `static` where `constexpr`a aren't class members; adds some `if constexpr`s for clarity. --- Machines/AmstradCPC/AmstradCPC.cpp | 54 +++++++++++-------- Machines/Apple/Macintosh/Keyboard.hpp | 2 +- Machines/Apple/Macintosh/Macintosh.cpp | 6 +-- Machines/Apple/Macintosh/Video.hpp | 10 ++-- Machines/Electron/Video.cpp | 30 +++++------ Machines/Oric/Oric.cpp | 4 +- Machines/ZX8081/ZX8081.cpp | 10 ++-- .../xcschemes/Clock Signal.xcscheme | 2 +- Storage/MassStorage/SCSI/SCSI.hpp | 2 +- 9 files changed, 65 insertions(+), 55 deletions(-) diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index 870efb114..6b4192205 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -877,8 +877,10 @@ template class ConcreteMachine: // Pump the AY ay_.run_for(cycle.length); - // Clock the FDC, if connected, using a lazy scale by two - time_since_fdc_update_ += cycle.length; + if constexpr (has_fdc) { + // Clock the FDC, if connected, using a lazy scale by two + time_since_fdc_update_ += cycle.length; + } // Update typing activity if(typer_) typer_->run_for(cycle.length); @@ -904,9 +906,11 @@ template class ConcreteMachine: } // Check for an upper ROM selection - if(has_fdc && !(address&0x2000)) { - upper_rom_ = (*cycle.value == 7) ? ROMType::AMSDOS : ROMType::BASIC; - if(upper_rom_is_paged_) read_pointers_[3] = roms_[upper_rom_].data(); + if constexpr (has_fdc) { + if(!(address&0x2000)) { + upper_rom_ = (*cycle.value == 7) ? ROMType::AMSDOS : ROMType::BASIC; + if(upper_rom_is_paged_) read_pointers_[3] = roms_[upper_rom_].data(); + } } // Check for a CRTC access @@ -923,16 +927,18 @@ template class ConcreteMachine: i8255_.set_register((address >> 8) & 3, *cycle.value); } - // Check for an FDC access - if(has_fdc && (address & 0x580) == 0x100) { - flush_fdc(); - fdc_.set_register(address & 1, *cycle.value); - } + if constexpr (has_fdc) { + // Check for an FDC access + if((address & 0x580) == 0x100) { + flush_fdc(); + fdc_.set_register(address & 1, *cycle.value); + } - // Check for a disk motor access - if(has_fdc && !(address & 0x580)) { - flush_fdc(); - fdc_.set_motor_on(!!(*cycle.value)); + // Check for a disk motor access + if(!(address & 0x580)) { + flush_fdc(); + fdc_.set_motor_on(!!(*cycle.value)); + } } break; case CPU::Z80::PartialMachineCycle::Input: @@ -945,9 +951,11 @@ template class ConcreteMachine: } // Check for an FDC access - if(has_fdc && (address & 0x580) == 0x100) { - flush_fdc(); - *cycle.value &= fdc_.get_register(address & 1); + if constexpr (has_fdc) { + if((address & 0x580) == 0x100) { + flush_fdc(); + *cycle.value &= fdc_.get_register(address & 1); + } } // Check for a CRTC access; the below is not a typo, the CRTC can be selected @@ -1065,7 +1073,7 @@ template class ConcreteMachine: // MARK: - Activity Source void set_activity_observer(Activity::Observer *observer) override { - if(has_fdc) fdc_.set_activity_observer(observer); + if constexpr (has_fdc) fdc_.set_activity_observer(observer); } // MARK: - Configuration options. @@ -1155,11 +1163,13 @@ template class ConcreteMachine: FDC fdc_; HalfCycles time_since_fdc_update_; void flush_fdc() { - // Clock the FDC, if connected, using a lazy scale by two - if(has_fdc && !fdc_is_sleeping_) { - fdc_.run_for(Cycles(time_since_fdc_update_.as_integral())); + if constexpr (has_fdc) { + // Clock the FDC, if connected, using a lazy scale by two + if(!fdc_is_sleeping_) { + fdc_.run_for(Cycles(time_since_fdc_update_.as_integral())); + } + time_since_fdc_update_ = HalfCycles(0); } - time_since_fdc_update_ = HalfCycles(0); } InterruptTimer interrupt_timer_; diff --git a/Machines/Apple/Macintosh/Keyboard.hpp b/Machines/Apple/Macintosh/Keyboard.hpp index 2caf4bbd0..ae5bfdf7e 100644 --- a/Machines/Apple/Macintosh/Keyboard.hpp +++ b/Machines/Apple/Macintosh/Keyboard.hpp @@ -18,7 +18,7 @@ namespace Apple { namespace Macintosh { -static constexpr uint16_t KeypadMask = 0x100; +constexpr uint16_t KeypadMask = 0x100; /*! Defines the keycodes that could be passed directly to a Macintosh via set_key_pressed. diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index 0f71be531..b1a3cd122 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -152,7 +152,7 @@ template class ConcreteMachin scc_.set_delegate(this); // Also watch for changes in clocking requirement from the SCSI chip. - if(model == Analyser::Static::Macintosh::Target::Model::MacPlus) { + if constexpr (model == Analyser::Static::Macintosh::Target::Model::MacPlus) { scsi_bus_.set_clocking_hint_observer(this); } @@ -514,7 +514,7 @@ template class ConcreteMachin void set_activity_observer(Activity::Observer *observer) override { iwm_->set_activity_observer(observer); - if(model == Analyser::Static::Macintosh::Target::Model::MacPlus) { + if constexpr (model == Analyser::Static::Macintosh::Target::Model::MacPlus) { scsi_bus_.set_activity_observer(observer); } } @@ -642,7 +642,7 @@ template class ConcreteMachin } // Update the SCSI if currently active. - if(model == Analyser::Static::Macintosh::Target::Model::MacPlus) { + if constexpr (model == Analyser::Static::Macintosh::Target::Model::MacPlus) { if(scsi_bus_is_clocked_) scsi_bus_.run_for(duration); } } diff --git a/Machines/Apple/Macintosh/Video.hpp b/Machines/Apple/Macintosh/Video.hpp index 3c52289ed..e63f9c817 100644 --- a/Machines/Apple/Macintosh/Video.hpp +++ b/Machines/Apple/Macintosh/Video.hpp @@ -17,11 +17,11 @@ namespace Apple { namespace Macintosh { -static constexpr HalfCycles line_length(704); -static constexpr int number_of_lines = 370; -static constexpr HalfCycles frame_length(line_length * HalfCycles(number_of_lines)); -static constexpr int sync_start = 36; -static constexpr int sync_end = 38; +constexpr HalfCycles line_length(704); +constexpr int number_of_lines = 370; +constexpr HalfCycles frame_length(line_length * HalfCycles(number_of_lines)); +constexpr int sync_start = 36; +constexpr int sync_end = 38; /*! Models the 68000-era Macintosh video hardware, producing a 512x348 pixel image, diff --git a/Machines/Electron/Video.cpp b/Machines/Electron/Video.cpp index 97aeb31ec..33fa92057 100644 --- a/Machines/Electron/Video.cpp +++ b/Machines/Electron/Video.cpp @@ -16,24 +16,24 @@ using namespace Electron; #define graphics_column(v) ((((v) & 127) - first_graphics_cycle + 128) & 127) namespace { - static constexpr int cycles_per_line = 128; - static constexpr int lines_per_frame = 625; - static constexpr int cycles_per_frame = lines_per_frame * cycles_per_line; - static constexpr int crt_cycles_multiplier = 8; - static constexpr int crt_cycles_per_line = crt_cycles_multiplier * cycles_per_line; + constexpr int cycles_per_line = 128; + constexpr int lines_per_frame = 625; + constexpr int cycles_per_frame = lines_per_frame * cycles_per_line; + constexpr int crt_cycles_multiplier = 8; + constexpr int crt_cycles_per_line = crt_cycles_multiplier * cycles_per_line; - static constexpr int field_divider_line = 312; // i.e. the line, simultaneous with which, the first field's sync ends. So if - // the first line with pixels in field 1 is the 20th in the frame, the first line - // with pixels in field 2 will be 20+field_divider_line - static constexpr int first_graphics_line = 31; - static constexpr int first_graphics_cycle = 33; + constexpr int field_divider_line = 312; // i.e. the line, simultaneous with which, the first field's sync ends. So if + // the first line with pixels in field 1 is the 20th in the frame, the first line + // with pixels in field 2 will be 20+field_divider_line + constexpr int first_graphics_line = 31; + constexpr int first_graphics_cycle = 33; - static constexpr int display_end_interrupt_line = 256; + constexpr int display_end_interrupt_line = 256; - static constexpr int real_time_clock_interrupt_1 = 16704; - static constexpr int real_time_clock_interrupt_2 = 56704; - static constexpr int display_end_interrupt_1 = (first_graphics_line + display_end_interrupt_line)*cycles_per_line; - static constexpr int display_end_interrupt_2 = (first_graphics_line + field_divider_line + display_end_interrupt_line)*cycles_per_line; + constexpr int real_time_clock_interrupt_1 = 16704; + constexpr int real_time_clock_interrupt_2 = 56704; + constexpr int display_end_interrupt_1 = (first_graphics_line + display_end_interrupt_line)*cycles_per_line; + constexpr int display_end_interrupt_2 = (first_graphics_line + field_divider_line + display_end_interrupt_line)*cycles_per_line; } // MARK: - Lifecycle diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index 3b7aca12e..4214574e6 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -224,7 +224,7 @@ template class Co tape_player_.set_delegate(this); Memory::Fuzz(ram_, sizeof(ram_)); - if(disk_interface == Analyser::Static::Oric::Target::DiskInterface::Pravetz) { + if constexpr (disk_interface == Analyser::Static::Oric::Target::DiskInterface::Pravetz) { diskii_.set_clocking_hint_observer(this); } @@ -630,7 +630,7 @@ template class Co // Helper to discern current IRQ state inline void set_interrupt_line() { bool irq_line = via_.get_interrupt_line(); - if(disk_interface == Analyser::Static::Oric::Target::DiskInterface::Microdisc) + if constexpr (disk_interface == Analyser::Static::Oric::Target::DiskInterface::Microdisc) irq_line |= microdisc_.get_interrupt_request_line(); m6502_.set_irq_line(irq_line); } diff --git a/Machines/ZX8081/ZX8081.cpp b/Machines/ZX8081/ZX8081.cpp index f0de30e17..569be4e46 100644 --- a/Machines/ZX8081/ZX8081.cpp +++ b/Machines/ZX8081/ZX8081.cpp @@ -86,7 +86,7 @@ template class ConcreteMachine: rom_ = std::move(*roms[0]); rom_.resize(use_zx81_rom ? 8192 : 4096); - if(is_zx81) { + if constexpr (is_zx81) { tape_trap_address_ = 0x37c; tape_return_address_ = 0x380; vsync_start_ = HalfCycles(32); @@ -158,7 +158,7 @@ template class ConcreteMachine: video_.run_for(cycle.length); } - if(is_zx81) horizontal_counter_ %= HalfCycles(Cycles(207)); + if constexpr (is_zx81) horizontal_counter_ %= HalfCycles(Cycles(207)); if(!tape_advance_delay_) { tape_player_.run_for(cycle.length); } else { @@ -185,7 +185,7 @@ template class ConcreteMachine: if(!(address & 1)) nmi_is_enabled_ = is_zx81; // The below emulates the ZonX AY expansion device. - if(is_zx81) { + if constexpr (is_zx81) { if((address&0xef) == 0xcf) { ay_set_register(*cycle.value); } else if((address&0xef) == 0x0f) { @@ -209,7 +209,7 @@ template class ConcreteMachine: } // The below emulates the ZonX AY expansion device. - if(is_zx81) { + if constexpr (is_zx81) { if((address&0xef) == 0xcf) { value &= ay_read_data(); } @@ -308,7 +308,7 @@ template class ConcreteMachine: forceinline void flush() { video_.flush(); - if(is_zx81) { + if constexpr (is_zx81) { update_audio(); audio_queue_.perform(); } 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 175c1d515..7b1a6914b 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme @@ -67,7 +67,7 @@