From ad9df4bb90b7b41d251abe9ed25e8b95a32196ed Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 21 Oct 2017 22:30:15 -0400 Subject: [PATCH] Commutes `uint8_t *`, `uint16_t *`, `uint32_t *`, `size_t`, `off_t` and `long` to functional-style casts. --- Components/6560/6560.hpp | 6 +- Machines/AmstradCPC/AmstradCPC.cpp | 32 +++--- Machines/Atari2600/TIA.cpp | 2 +- Machines/Electron/Electron.cpp | 2 +- Machines/Electron/Video.cpp | 18 ++-- Machines/Oric/Video.cpp | 4 +- Machines/ZX8081/Video.cpp | 2 +- Machines/ZX8081/ZX8081.cpp | 2 +- Outputs/CRT/CRT.cpp | 28 +++--- Outputs/CRT/Internals/ArrayBuilder.cpp | 2 +- Outputs/CRT/Internals/Shaders/Shader.cpp | 18 ++-- Outputs/CRT/Internals/TextureTarget.cpp | 2 +- Outputs/Speaker.hpp | 20 ++-- Processors/AllRAMProcessor.cpp | 4 +- .../Z80/Implementation/Z80Implementation.hpp | 98 +++++++++---------- StaticAnalyser/Acorn/Disk.cpp | 4 +- StaticAnalyser/Atari/StaticAnalyser.cpp | 6 +- StaticAnalyser/Commodore/Disk.cpp | 4 +- .../Disassembler/Disassembler6502.cpp | 2 +- Storage/Cartridge/Formats/BinaryDump.cpp | 4 +- Storage/Cartridge/Formats/PRG.cpp | 4 +- Storage/Disk/DiskImage/Formats/AcornADF.cpp | 4 +- Storage/Disk/DiskImage/Formats/CPCDSK.cpp | 4 +- Storage/Disk/DiskImage/Formats/D64.cpp | 2 +- Storage/Disk/DiskImage/Formats/G64.cpp | 4 +- Storage/Disk/DiskImage/Formats/HFE.cpp | 4 +- Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp | 2 +- .../Formats/Utility/ImplicitSectors.cpp | 4 +- Storage/Disk/Encodings/MFM/Encoder.cpp | 4 +- Storage/Disk/Encodings/MFM/SegmentParser.cpp | 2 +- Storage/Disk/Parsers/CPM.cpp | 10 +- Storage/FileHolder.cpp | 6 +- Storage/Tape/Formats/CSW.cpp | 6 +- Storage/Tape/Formats/TZX.cpp | 6 +- Storage/Tape/Formats/TapeUEF.cpp | 2 +- Storage/Tape/Formats/ZX80O81P.cpp | 4 +- 36 files changed, 164 insertions(+), 164 deletions(-) diff --git a/Components/6560/6560.hpp b/Components/6560/6560.hpp index a40313381..2c3717910 100644 --- a/Components/6560/6560.hpp +++ b/Components/6560/6560.hpp @@ -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/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index 5d5c44188..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)]; } diff --git a/Machines/Atari2600/TIA.cpp b/Machines/Atari2600/TIA.cpp index c9eb7404c..885ab69bf 100644 --- a/Machines/Atari2600/TIA.cpp +++ b/Machines/Atari2600/TIA.cpp @@ -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/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 3248b1045..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 { diff --git a/Machines/Electron/Video.cpp b/Machines/Electron/Video.cpp index 48c94b3a8..d5f01194e 100644 --- a/Machines/Electron/Video.cpp +++ b/Machines/Electron/Video.cpp @@ -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_++; } @@ -294,15 +294,15 @@ void VideoOutput::set_register(int address, uint8_t value) { // regenerate all palette tables for now #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]); diff --git a/Machines/Oric/Video.cpp b/Machines/Oric/Video.cpp index a2921d338..d97c13916 100644 --- a/Machines/Oric/Video.cpp +++ b/Machines/Oric/Video.cpp @@ -63,7 +63,7 @@ void VideoOutput::set_colour_rom(const std::vector &rom) { // 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] = static_cast((colour_forms_[c] >> 8) | (colour_forms_[c] << 8)); } @@ -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, 2)); if(!counter_) { frame_counter_++; diff --git a/Machines/ZX8081/Video.cpp b/Machines/ZX8081/Video.cpp index 5beebb8b6..89c73fc9e 100644 --- a/Machines/ZX8081/Video.cpp +++ b/Machines/ZX8081/Video.cpp @@ -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 089adb1ea..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; diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index e4af0b992..14487acda 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -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] @@ -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; 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/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/TextureTarget.cpp b/Outputs/CRT/Internals/TextureTarget.cpp index 27db1b4c9..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); diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index d035434cd..6bba2b5f4 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(); } @@ -150,10 +150,10 @@ template class Filter: public Speaker { // 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 = static_cast(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 = static_cast(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,7 +196,7 @@ 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_) @@ -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; } @@ -243,7 +243,7 @@ template class Filter: public Speaker { } 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/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/Z80Implementation.hpp b/Processors/Z80/Implementation/Z80Implementation.hpp index 595027775..8ee0d01cc 100644 --- a/Processors/Z80/Implementation/Z80Implementation.hpp +++ b/Processors/Z80/Implementation/Z80Implementation.hpp @@ -97,11 +97,11 @@ template < class T, 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; @@ -183,7 +183,7 @@ template < class T, 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); @@ -209,7 +209,7 @@ template < class T, } 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); @@ -222,7 +222,7 @@ template < class T, } 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); @@ -235,7 +235,7 @@ template < class T, } 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); @@ -263,7 +263,7 @@ template < class T, } 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,7 +271,7 @@ template < class T, int overflow = (value ^ result) & ~value; int half_result = (value&0xf) + 1; - *(uint8_t *)operation->source = static_cast(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_ = static_cast(result); @@ -281,7 +281,7 @@ template < class T, } 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,7 +289,7 @@ template < class T, int overflow = (value ^ result) & value; int half_result = (value&0xf) - 1; - *(uint8_t *)operation->source = static_cast(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_ = static_cast(result); @@ -356,8 +356,8 @@ 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); @@ -367,13 +367,13 @@ template < class T, half_carry_result_ = static_cast(halfResult >> 8); subtract_flag_ = 0; - *(uint16_t *)operation->destination = static_cast(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); @@ -388,13 +388,13 @@ template < class T, half_carry_result_ = static_cast(halfResult >> 8); parity_overflow_result_ = static_cast(overflow >> 13); - *(uint16_t *)operation->destination = static_cast(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); @@ -412,7 +412,7 @@ template < class T, half_carry_result_ = static_cast(halfResult >> 8); parity_overflow_result_ = static_cast(overflow >> 13); - *(uint16_t *)operation->destination = static_cast(result); + *static_cast(operation->destination) = static_cast(result); memptr_.full++; } break; @@ -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 @@ -675,58 +675,58 @@ template < class T, #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 = static_cast((*(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 = static_cast((*(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 = static_cast((*(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 = static_cast((*(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 = static_cast(*(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 = static_cast((*(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 = static_cast(*(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 = static_cast((*(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; @@ -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 = static_cast(*(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/StaticAnalyser/Acorn/Disk.cpp b/StaticAnalyser/Acorn/Disk.cpp index 9052c90f0..6ab4ab585 100644 --- a/StaticAnalyser/Acorn/Disk.cpp +++ b/StaticAnalyser/Acorn/Disk.cpp @@ -51,9 +51,9 @@ 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) { diff --git a/StaticAnalyser/Atari/StaticAnalyser.cpp b/StaticAnalyser/Atari/StaticAnalyser.cpp index cd1d0a907..e5844260a 100644 --- a/StaticAnalyser/Atari/StaticAnalyser.cpp +++ b/StaticAnalyser/Atari/StaticAnalyser.cpp @@ -24,7 +24,7 @@ static void DeterminePagingFor2kCartridge(StaticAnalyser::Target &target, const 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}); @@ -126,8 +126,8 @@ static void DeterminePagingForCartridge(StaticAnalyser::Target &target, const St 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 3cc3adeda..e09ccee75 100644 --- a/StaticAnalyser/Commodore/Disk.cpp +++ b/StaticAnalyser/Commodore/Disk.cpp @@ -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; diff --git a/StaticAnalyser/Disassembler/Disassembler6502.cpp b/StaticAnalyser/Disassembler/Disassembler6502.cpp index e5cfe2bdd..df047e5b2 100644 --- a/StaticAnalyser/Disassembler/Disassembler6502.cpp +++ b/StaticAnalyser/Disassembler/Disassembler6502.cpp @@ -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/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/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 8d194268b..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(); @@ -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 b6010a6c5..ce7433341 100644 --- a/Storage/Disk/DiskImage/Formats/D64.cpp +++ b/Storage/Disk/DiskImage/Formats/D64.cpp @@ -84,7 +84,7 @@ 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]; + 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]; diff --git a/Storage/Disk/DiskImage/Formats/G64.cpp b/Storage/Disk/DiskImage/Formats/G64.cpp index be0b921ff..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; @@ -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; diff --git a/Storage/Disk/DiskImage/Formats/HFE.cpp b/Storage/Disk/DiskImage/Formats/HFE.cpp index 748895d90..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); diff --git a/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp b/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp index 7190c509f..e9ec533bf 100644 --- a/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp @@ -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/Encodings/MFM/Encoder.cpp b/Storage/Disk/Encodings/MFM/Encoder.cpp index 4fe111f62..d01da9420 100644 --- a/Storage/Disk/Encodings/MFM/Encoder.cpp +++ b/Storage/Disk/Encodings/MFM/Encoder.cpp @@ -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]); } @@ -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 0dded7a4e..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; } @@ -88,7 +88,7 @@ std::unique_ptr Storage::Disk::CPM::GetCatalogue( std::unique_ptr result(new Catalogue); 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; + 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; @@ -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/FileHolder.cpp b/Storage/FileHolder.cpp index 566e4f497..f8c357d69 100644 --- a/Storage/FileHolder.cpp +++ b/Storage/FileHolder.cpp @@ -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/Tape/Formats/CSW.cpp b/Storage/Tape/Formats/CSW.cpp index 5e0dd7067..102c15dea 100644 --- a/Storage/Tape/Formats/CSW.cpp +++ b/Storage/Tape/Formats/CSW.cpp @@ -62,10 +62,10 @@ 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_); @@ -74,7 +74,7 @@ CSW::CSW(const char *file_name) : // needed. 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/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/TapeUEF.cpp b/Storage/Tape/Formats/TapeUEF.cpp index 761ad5c1d..cb59703fc 100644 --- a/Storage/Tape/Formats/TapeUEF.cpp +++ b/Storage/Tape/Formats/TapeUEF.cpp @@ -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_); 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();