1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-26 19:17:52 +00:00

Be more rigorous about static constexpr.

This commit is contained in:
Thomas Harte
2025-08-26 22:54:39 -04:00
parent 1ca279d99d
commit 5018d7d577
59 changed files with 204 additions and 186 deletions
@@ -125,11 +125,11 @@ private:
uint32_t alarm_ = 0xff'ffff;
public:
template <int byte> void write(uint8_t v) {
template <int byte> void write(const uint8_t v) {
if constexpr (byte == 3) {
return;
}
constexpr int shift = byte << 3;
static constexpr int shift = byte << 3;
// Write to either the alarm or the current value as directed;
// writing to any part of the current value other than the LSB
@@ -147,7 +147,7 @@ public:
if constexpr (byte == 3) {
return 0xff; // Assumed. Just a guess.
}
constexpr int shift = byte << 3;
static constexpr int shift = byte << 3;
if constexpr (byte == 2) {
latch_ = value_ | 0xff00'0000;
@@ -163,7 +163,7 @@ public:
return result;
}
bool advance(int count) {
bool advance(const int count) {
// The 8250 uses a simple binary counter to replace the
// 6526's time-of-day clock. So this is easy.
const uint32_t distance_to_alarm = (alarm_ - value_) & 0xff'ffff;
+1 -1
View File
@@ -114,7 +114,7 @@ void MFP68901::write(int address, const uint8_t value) {
return;
}
constexpr int timer_prescales[] = {
static constexpr int timer_prescales[] = {
1, 4, 10, 16, 50, 64, 100, 200
};
+2 -2
View File
@@ -226,7 +226,7 @@ void TMS9918<personality>::run_for(const HalfCycles cycles) {
// TODO: where did this magic constant come from? https://www.smspower.org/forums/17970-RoadRashHow#111000 mentioned in passing
// that "the vertical scroll register is latched at the start of the active display" and this is two clocks before that, so it's
// not uncompelling. I can just no longer find my source.
constexpr auto latch_time = LineLayout<personality>::EndOfLeftBorder - 2;
static constexpr auto latch_time = LineLayout<personality>::EndOfLeftBorder - 2;
static_assert(latch_time > 0);
if(this->fetch_pointer_.column < latch_time && end_column >= latch_time) {
if(!this->fetch_pointer_.row) {
@@ -1211,7 +1211,7 @@ uint8_t TMS9918<personality>::read(const int address) {
template <Personality personality>
int Base<personality>::fetch_line() const {
// This is the proper Master System value; TODO: what's correct for Yamaha, etc?
constexpr int row_change_position = 31;
static constexpr int row_change_position = 31;
return
(this->fetch_pointer_.column < row_change_position)
+4 -4
View File
@@ -87,8 +87,8 @@ template <Personality personality> struct Base: public Storage<personality> {
/// applicable @c memory_mask.
template <int shift, int length = 8> void install_field(AddressT &target, const uint8_t source) {
static_assert(length > 0 && length <= 8);
constexpr auto source_mask = (1 << length) - 1;
constexpr auto mask = AddressT(~(source_mask << shift));
static constexpr auto source_mask = (1 << length) - 1;
static constexpr auto mask = AddressT(~(source_mask << shift));
target = (
(target & mask) |
AddressT((source & source_mask) << shift)
@@ -545,8 +545,8 @@ template <Personality personality> struct Base: public Storage<personality> {
if(Storage<personality>::cram_is_selected_) {
// Adjust the palette. In a Master System blue has a slightly different
// scale; cf. https://www.retrorgb.com/sega-master-system-non-linear-blue-channel-findings.html
constexpr uint8_t rg_scale[] = {0, 85, 170, 255};
constexpr uint8_t b_scale[] = {0, 104, 170, 255};
static constexpr uint8_t rg_scale[] = {0, 85, 170, 255};
static constexpr uint8_t b_scale[] = {0, 104, 170, 255};
Storage<personality>::colour_ram_[address & 0x1f] = palette_pack(
rg_scale[(read_ahead_buffer_ >> 0) & 3],
rg_scale[(read_ahead_buffer_ >> 2) & 3],
+2 -2
View File
@@ -93,8 +93,8 @@ void Base<personality>::draw_sprites(
assert(!buffer.is_filling);
}
constexpr uint32_t sprite_colour_selection_masks[2] = {0x00000000, 0xffffffff};
constexpr int colour_masks[16] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
static constexpr uint32_t sprite_colour_selection_masks[2] = {0x00000000, 0xffffffff};
static constexpr int colour_masks[16] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
const int sprite_width = sprites_16x16_ ? 16 : 8;
const int shifter_target = sprite_width << 1;
const int pixel_width = sprites_magnified_ ? sprite_width << 1 : sprite_width;
+10 -10
View File
@@ -407,8 +407,8 @@ struct TextSequencer {
return;
} else {
// For the 120 slots in between follow a three-step pattern of:
constexpr int offset = cycle - 30;
constexpr auto column = AddressT(offset / 3);
static constexpr int offset = cycle - 30;
static constexpr auto column = AddressT(offset / 3);
switch(offset % 3) {
case 0: // (1) fetch tile name.
fetcher.fetch_name(column);
@@ -457,16 +457,16 @@ struct CharacterSequencer {
// Body of line: tiles themselves, plus some additional potential sprites.
if(cycle >= 27 && cycle < 155) {
constexpr int offset = cycle - 27;
constexpr int block = offset >> 2;
constexpr int sub_block = offset & 3;
static constexpr int offset = cycle - 27;
static constexpr int block = offset >> 2;
static constexpr int sub_block = offset & 3;
switch(sub_block) {
case 0: character_fetcher.fetch_name(block); break;
case 1:
if(!(block & 3)) {
character_fetcher.base->do_external_slot(to_internal<personality, Clock::TMSMemoryWindow, Clock::FromStartOfSync>(cycle));
} else {
constexpr int sprite = 8 + ((block >> 2) * 3) + ((block & 3) - 1);
static constexpr int sprite = 8 + ((block >> 2) * 3) + ((block & 3) - 1);
sprite_fetcher.fetch_y(sprite);
}
break;
@@ -549,9 +549,9 @@ struct SMSSequencer {
}
if(cycle >= 25 && cycle < 153) {
constexpr int offset = cycle - 25;
constexpr int block = offset >> 2;
constexpr int sub_block = offset & 3;
static constexpr int offset = cycle - 25;
static constexpr int block = offset >> 2;
static constexpr int sub_block = offset & 3;
switch(sub_block) {
default: break;
@@ -561,7 +561,7 @@ struct SMSSequencer {
if(!(block & 3)) {
fetcher.base->do_external_slot(to_internal<personality, Clock::TMSMemoryWindow, Clock::FromStartOfSync>(cycle));
} else {
constexpr int sprite = (8 + ((block >> 2) * 3) + ((block & 3) - 1)) << 1;
static constexpr int sprite = (8 + ((block >> 2) * 3) + ((block & 3) - 1)) << 1;
fetcher.posit_sprite(sprite);
fetcher.posit_sprite(sprite+1);
}
+26 -26
View File
@@ -29,49 +29,49 @@ template <Personality personality, typename Enable = void> struct LineLayout;
// * text mode on all VDPs adjusts border width.
template <Personality personality> struct LineLayout<personality, std::enable_if_t<is_classic_vdp(personality)>> {
constexpr static int StartOfSync = 0;
constexpr static int EndOfSync = 26;
constexpr static int StartOfColourBurst = 29;
constexpr static int EndOfColourBurst = 43;
constexpr static int EndOfLeftErase = 50;
constexpr static int EndOfLeftBorder = 63;
constexpr static int EndOfPixels = 319;
constexpr static int EndOfRightBorder = 334;
static constexpr int StartOfSync = 0;
static constexpr int EndOfSync = 26;
static constexpr int StartOfColourBurst = 29;
static constexpr int EndOfColourBurst = 43;
static constexpr int EndOfLeftErase = 50;
static constexpr int EndOfLeftBorder = 63;
static constexpr int EndOfPixels = 319;
static constexpr int EndOfRightBorder = 334;
constexpr static int CyclesPerLine = 342;
static constexpr int CyclesPerLine = 342;
constexpr static int TextModeEndOfLeftBorder = 69;
constexpr static int TextModeEndOfPixels = 309;
static constexpr int TextModeEndOfLeftBorder = 69;
static constexpr int TextModeEndOfPixels = 309;
constexpr static int ModeLatchCycle = 36; // Just a guess; correlates with the known 144 for the Yamaha VDPs,
static constexpr int ModeLatchCycle = 36; // Just a guess; correlates with the known 144 for the Yamaha VDPs,
// and falls into the collection gap between the final sprite
// graphics and the initial tiles or pixels.
/// The number of internal cycles that must elapse between a request to read or write and
/// it becoming a candidate for action.
constexpr static int VRAMAccessDelay = 6;
static constexpr int VRAMAccessDelay = 6;
};
template <Personality personality> struct LineLayout<personality, std::enable_if_t<is_yamaha_vdp(personality)>> {
constexpr static int StartOfSync = 0;
constexpr static int EndOfSync = 100;
constexpr static int StartOfColourBurst = 113;
constexpr static int EndOfColourBurst = 167;
constexpr static int EndOfLeftErase = 202;
constexpr static int EndOfLeftBorder = 258;
constexpr static int EndOfPixels = 1282;
constexpr static int EndOfRightBorder = 1341;
static constexpr int StartOfSync = 0;
static constexpr int EndOfSync = 100;
static constexpr int StartOfColourBurst = 113;
static constexpr int EndOfColourBurst = 167;
static constexpr int EndOfLeftErase = 202;
static constexpr int EndOfLeftBorder = 258;
static constexpr int EndOfPixels = 1282;
static constexpr int EndOfRightBorder = 1341;
constexpr static int CyclesPerLine = 1368;
static constexpr int CyclesPerLine = 1368;
constexpr static int TextModeEndOfLeftBorder = 294;
constexpr static int TextModeEndOfPixels = 1254;
static constexpr int TextModeEndOfLeftBorder = 294;
static constexpr int TextModeEndOfPixels = 1254;
constexpr static int ModeLatchCycle = 144;
static constexpr int ModeLatchCycle = 144;
/// The number of internal cycles that must elapse between a request to read or write and
/// it becoming a candidate for action.
constexpr static int VRAMAccessDelay = 16;
static constexpr int VRAMAccessDelay = 16;
};
}
@@ -19,7 +19,7 @@ struct Vector {
template <int offset, bool high> void set(const uint8_t value) {
constexpr uint8_t mask = high ? (offset ? 0x3 : 0x1) : 0xff;
constexpr int shift = high ? 8 : 0;
static constexpr int shift = high ? 8 : 0;
v[offset] = (v[offset] & ~(mask << shift)) | ((value & mask) << shift);
}
@@ -18,8 +18,8 @@ public:
this is used to select a key scaling rate if key-rate scaling is enabled.
*/
void set_period(const int period, const int octave) {
constexpr int key_level_scales[16] = {0, 48, 64, 74, 80, 86, 90, 94, 96, 100, 102, 104, 106, 108, 110, 112};
constexpr int masks[2] = {~0, 0};
static constexpr int key_level_scales[16] = {0, 48, 64, 74, 80, 86, 90, 94, 96, 100, 102, 104, 106, 108, 110, 112};
static constexpr int masks[2] = {~0, 0};
// A two's complement assumption is embedded below; the use of masks relies
// on the sign bit to clamp to zero.
@@ -22,7 +22,7 @@ public:
/*!
@returns The output of waveform @c form at [integral] phase @c phase.
*/
static constexpr LogSign wave(Waveform form, int phase) {
static constexpr LogSign wave(const Waveform form, const int phase) {
constexpr int waveforms[4][4] = {
{1023, 1023, 1023, 1023}, // Sine: don't mask in any quadrant.
{511, 511, 0, 0}, // Half sine: keep the first half intact, lock to 0 in the second half.
+1 -1
View File
@@ -47,7 +47,7 @@ void RP5C01::run_for(const HalfCycles cycles) {
// Update time within day.
seconds_ += elapsed_seconds;
constexpr int day_length = 60 * 60 * 24;
static constexpr int day_length = 60 * 60 * 24;
if(seconds_ < day_length) {
return;
}