mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-19 19:16:34 +00:00
Reduce usages of reinterpret_cast.
(And do some drive-by `const`ing)
This commit is contained in:
@@ -169,9 +169,11 @@ public:
|
||||
}
|
||||
|
||||
for(int c = 0; c < 16; c++) {
|
||||
uint8_t *colour = reinterpret_cast<uint8_t *>(&colours_[c]);
|
||||
colour[0] = luminances[c];
|
||||
colour[1] = chrominances[c];
|
||||
const uint8_t colour[2] = {
|
||||
luminances[c],
|
||||
chrominances[c]
|
||||
};
|
||||
colours_[c] = std::bit_cast<uint16_t>(colour);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -563,8 +563,8 @@ void TIA::draw_playfield(int start, int end) {
|
||||
// proceed along four-pixel boundaries, plotting four pixels at a time
|
||||
int aligned_position = (start + 3)&~3;
|
||||
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;
|
||||
const int offset = (aligned_position - first_pixel_cycle) >> 2;
|
||||
const uint32_t value = ((background_[(offset/20)&background_half_mask_] >> (offset%20))&1) * 0x01010101;
|
||||
*reinterpret_cast<uint32_t *>(&collision_buffer_[aligned_position - first_pixel_cycle]) |= value;
|
||||
aligned_position += 4;
|
||||
}
|
||||
|
||||
@@ -510,9 +510,11 @@ void Video::write(int address, uint16_t value) {
|
||||
if(address == 0x20) video_stream_.will_change_border_colour();
|
||||
|
||||
raw_palette_[address - 0x20] = value;
|
||||
uint8_t *const entry = reinterpret_cast<uint8_t *>(&palette_[address - 0x20]);
|
||||
entry[0] = uint8_t((value & 0x700) >> 7);
|
||||
entry[1] = uint8_t((value & 0x77) << 1);
|
||||
const uint8_t entry[] = {
|
||||
uint8_t((value & 0x700) >> 7),
|
||||
uint8_t((value & 0x77) << 1),
|
||||
};
|
||||
palette_[address - 0x20] = std::bit_cast<uint16_t>(entry);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ uint16_t mapped_colour(const uint8_t source) {
|
||||
(green << 4) + blue
|
||||
)
|
||||
};
|
||||
return *reinterpret_cast<const uint16_t *>(parts);
|
||||
return std::bit_cast<uint16_t>(parts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
void Memory::Fuzz(uint8_t *buffer, std::size_t size) {
|
||||
void Memory::Fuzz(uint8_t *const buffer, const std::size_t size) {
|
||||
const unsigned int divider = (unsigned(RAND_MAX) + 1) / 256;
|
||||
unsigned int shift = 1, value = 1;
|
||||
while(value < divider) {
|
||||
@@ -23,6 +23,6 @@ void Memory::Fuzz(uint8_t *buffer, std::size_t size) {
|
||||
}
|
||||
}
|
||||
|
||||
void Memory::Fuzz(uint16_t *buffer, std::size_t size) {
|
||||
void Memory::Fuzz(uint16_t *const buffer, const std::size_t size) {
|
||||
Fuzz(reinterpret_cast<uint8_t *>(buffer), size * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
void Memory::PackBigEndian16(const std::vector<uint8_t> &source, uint16_t *target) {
|
||||
void Memory::PackBigEndian16(const std::vector<uint8_t> &source, uint16_t *const target) {
|
||||
for(size_t c = 0; c < source.size(); c += 2) {
|
||||
target[c >> 1] = uint16_t(source[c] << 8) | uint16_t(source[c+1]);
|
||||
}
|
||||
}
|
||||
|
||||
void Memory::PackBigEndian16(const std::vector<uint8_t> &source, uint8_t *target) {
|
||||
void Memory::PackBigEndian16(const std::vector<uint8_t> &source, uint8_t *const target) {
|
||||
PackBigEndian16(source, reinterpret_cast<uint16_t *>(target));
|
||||
}
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
}
|
||||
|
||||
- (Uniforms *)uniforms {
|
||||
return reinterpret_cast<Uniforms *>(_uniformsBuffer.contents);
|
||||
return static_cast<Uniforms *>(_uniformsBuffer.contents);
|
||||
}
|
||||
|
||||
- (void)setIsFrameSynced:(BOOL)isFrameSynced {
|
||||
@@ -313,13 +313,13 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
options:SharedResourceOptionsTexture];
|
||||
|
||||
// Install all that storage in the buffering scan target.
|
||||
_scanTarget.set_write_area(reinterpret_cast<uint8_t *>(_writeAreaBuffer.contents));
|
||||
_scanTarget.set_write_area(static_cast<uint8_t *>(_writeAreaBuffer.contents));
|
||||
_scanTarget.set_line_buffer(
|
||||
reinterpret_cast<BufferingScanTarget::Line *>(_linesBuffer.contents),
|
||||
static_cast<BufferingScanTarget::Line *>(_linesBuffer.contents),
|
||||
NumBufferedLines
|
||||
);
|
||||
_scanTarget.set_scan_buffer(
|
||||
reinterpret_cast<BufferingScanTarget::Scan *>(_scansBuffer.contents),
|
||||
static_cast<BufferingScanTarget::Scan *>(_scansBuffer.contents),
|
||||
NumBufferedScans
|
||||
);
|
||||
|
||||
@@ -887,7 +887,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
- (id<MTLBuffer>)bufferForOffset:(size_t)offset {
|
||||
// Store and apply the offset.
|
||||
const auto buffer = _lineOffsetBuffers[_lineOffsetBuffer];
|
||||
*(reinterpret_cast<int *>(_lineOffsetBuffers[_lineOffsetBuffer].contents)) = int(offset);
|
||||
*(static_cast<int *>(_lineOffsetBuffers[_lineOffsetBuffer].contents)) = int(offset);
|
||||
++_lineOffsetBuffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ using namespace InstructionSet::M68k;
|
||||
NSBundle *const bundle = [NSBundle bundleForClass:[self class]];
|
||||
NSURL *const testURL = [bundle URLForResource:@"bcd-table" withExtension:@"bin" subdirectory:@"flamewing 68000 BCD tests"];
|
||||
NSData *const testData = [NSData dataWithContentsOfURL:testURL];
|
||||
const uint8_t *bytes = reinterpret_cast<const uint8_t *>(testData.bytes);
|
||||
const uint8_t *bytes = static_cast<const uint8_t *>(testData.bytes);
|
||||
|
||||
NullFlowController flow_controller;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ struct MachineRunner {
|
||||
|
||||
void start() {
|
||||
last_time_ = Time::nanos_now();
|
||||
timer_ = SDL_AddTimer(timer_period, &sdl_callback, reinterpret_cast<void *>(this));
|
||||
timer_ = SDL_AddTimer(timer_period, &sdl_callback, static_cast<void *>(this));
|
||||
}
|
||||
|
||||
void stop() {
|
||||
@@ -120,7 +120,7 @@ private:
|
||||
|
||||
static constexpr Uint32 timer_period = 4;
|
||||
static Uint32 sdl_callback(Uint32, void *param) {
|
||||
reinterpret_cast<MachineRunner *>(param)->update();
|
||||
static_cast<MachineRunner *>(param)->update();
|
||||
return timer_period;
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ struct SpeakerDelegate: public Outputs::Speaker::Speaker::Delegate {
|
||||
}
|
||||
|
||||
static void SDL_audio_callback(void *const userdata, Uint8 *const stream, const int len) {
|
||||
reinterpret_cast<SpeakerDelegate *>(userdata)->audio_callback(stream, len);
|
||||
static_cast<SpeakerDelegate *>(userdata)->audio_callback(stream, len);
|
||||
}
|
||||
|
||||
SDL_AudioDeviceID audio_device;
|
||||
|
||||
@@ -317,7 +317,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
void set_output_volume(float volume) final {
|
||||
void set_output_volume(const float volume) final {
|
||||
scale_.store(int(std::clamp(volume * 65536.0f, 0.0f, 65536.0f)));
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
it is safe to read from @c buffer, and in stereo it will be half the number — it is a count
|
||||
of the number of time points at which audio was sampled.
|
||||
*/
|
||||
void push(const int16_t *buffer, size_t length) {
|
||||
void push(const int16_t *const buffer, const size_t length) {
|
||||
buffer_ = buffer;
|
||||
#ifndef NDEBUG
|
||||
const bool did_process =
|
||||
@@ -396,7 +396,7 @@ private:
|
||||
|
||||
SampleSource &sample_source_;
|
||||
|
||||
void skip_samples(size_t count) {
|
||||
void skip_samples(const size_t count) {
|
||||
sample_source_.template apply_samples<Action::Ignore>(count, nullptr);
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ private:
|
||||
return int(65536.0 / sample_source_.average_output_peak());
|
||||
}
|
||||
|
||||
void get_samples(size_t length, int16_t *target) {
|
||||
void get_samples(const size_t length, int16_t *const target) {
|
||||
if constexpr (SampleSource::is_stereo) {
|
||||
StereoSample *const stereo_target = reinterpret_cast<StereoSample *>(target);
|
||||
sample_source_.template apply_samples<Action::Store>(length, stereo_target);
|
||||
|
||||
@@ -398,7 +398,7 @@ struct ProcessorStorage {
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t *byte(int pointer) {
|
||||
uint8_t *byte(const int pointer) {
|
||||
assert(pointer >= 0 && pointer < 4);
|
||||
#if TARGET_RT_BIG_ENDIAN
|
||||
return reinterpret_cast<uint8_t *>(&value) + (3 ^ pointer);
|
||||
|
||||
@@ -347,7 +347,10 @@ struct Microcycle: public MicrocycleOperationStorage<op> {
|
||||
* if this is a word read, reads a word (in the host platform's endianness) from @c target; and
|
||||
* if this is a write, does the converse of a read.
|
||||
*/
|
||||
forceinline void apply(uint8_t *target, OperationT read_write_mask = Operation::PermitRead | Operation::PermitWrite) const {
|
||||
forceinline void apply(
|
||||
uint8_t *const target,
|
||||
const OperationT read_write_mask = Operation::PermitRead | Operation::PermitWrite
|
||||
) const {
|
||||
assert( (this->operation & (Operation::SelectWord | Operation::SelectByte)) != (Operation::SelectWord | Operation::SelectByte));
|
||||
|
||||
switch(
|
||||
|
||||
@@ -277,8 +277,8 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::uni
|
||||
|
||||
// Rewrite the entire disk image, in extended form.
|
||||
Storage::FileHolder output(file_name_, Storage::FileMode::Rewrite);
|
||||
output.write(reinterpret_cast<const uint8_t *>("EXTENDED CPC DSK File\r\nDisk-Info\r\n"), 34);
|
||||
output.write(reinterpret_cast<const uint8_t *>("Clock Signal "), 14);
|
||||
output.write("EXTENDED CPC DSK File\r\nDisk-Info\r\n", 34);
|
||||
output.write("Clock Signal ", 14);
|
||||
output.put(uint8_t(head_position_count_));
|
||||
output.put(uint8_t(head_count_));
|
||||
output.putn(2, 0);
|
||||
@@ -318,7 +318,7 @@ void CPCDSK::set_tracks(const std::map<::Storage::Disk::Track::Address, std::uni
|
||||
if(!track) continue;
|
||||
|
||||
// Output track header.
|
||||
output.write(reinterpret_cast<const uint8_t *>("Track-Info\r\n"), 13);
|
||||
output.write("Track-Info\r\n", 13);
|
||||
output.putn(3, 0);
|
||||
output.put(track->track);
|
||||
output.put(track->side);
|
||||
|
||||
@@ -73,7 +73,7 @@ std::size_t FileHolder::write(const std::vector<uint8_t> &buffer) {
|
||||
return std::fwrite(buffer.data(), 1, buffer.size(), file_);
|
||||
}
|
||||
|
||||
std::size_t FileHolder::write(const uint8_t *buffer, const std::size_t size) {
|
||||
std::size_t FileHolder::write(const void *buffer, const std::size_t size) {
|
||||
return std::fwrite(buffer, 1, size, file_);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
std::size_t write(const std::vector<uint8_t> &);
|
||||
|
||||
/*! Writes @c buffer one byte at a time in order, writing @c size bytes in total. */
|
||||
std::size_t write(const uint8_t *, std::size_t);
|
||||
std::size_t write(const void *, std::size_t);
|
||||
|
||||
/*! Moves @c bytes from the anchor indicated by @c whence: SEEK_SET, SEEK_CUR or SEEK_END. */
|
||||
bool seek(long offset, Whence);
|
||||
|
||||
Reference in New Issue
Block a user