From bf11a28fb5fcecb101d202a4708f7a00101ddd72 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 1 Dec 2019 20:14:58 +0300 Subject: [PATCH] C-style cast cleanup IV --- Utilities/JIT.cpp | 65 ++++++++++++-------- rpcs3/Emu/Cell/Modules/cellAdec.cpp | 78 ++++++++++++------------ rpcs3/Emu/Cell/Modules/cellAudio.cpp | 8 +-- rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp | 4 +- rpcs3/Emu/Cell/Modules/cellBgdl.cpp | 4 +- rpcs3/Emu/Cell/Modules/cellDmux.cpp | 42 ++++++------- rpcs3/Emu/Cell/Modules/cellFont.cpp | 22 +++---- rpcs3/Emu/Cell/Modules/cellGame.cpp | 2 +- rpcs3/Emu/Cell/Modules/cellGifDec.cpp | 30 +++++---- rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp | 12 ++-- rpcs3/Emu/Cell/Modules/cellJpgDec.cpp | 28 ++++----- rpcs3/Emu/Cell/Modules/cellKb.cpp | 2 +- rpcs3/Emu/Cell/Modules/cellMouse.cpp | 4 +- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 24 ++++---- rpcs3/Emu/Cell/lv2/sys_usbd.cpp | 24 ++++---- rpcs3/Emu/Io/MouseHandler.h | 6 +- rpcs3/stb_image.cpp | 25 +++----- 17 files changed, 190 insertions(+), 190 deletions(-) diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index feadadfa8180..0a2dfaff8549 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -298,7 +298,7 @@ class LLVMSegmentAllocator { auto ptr = ::mmap(nullptr, max_size, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_32BIT, -1, 0); if (ptr != MAP_FAILED) - found_segs[num_segs++] = Segment(ptr, u32(max_size)); + found_segs[num_segs++] = Segment(ptr, static_cast(max_size)); else if (max_size > 0x1000000) max_size -= 0x1000000; else @@ -314,7 +314,7 @@ class LLVMSegmentAllocator { for (auto curr_size = max_size; (0x80000000u - curr_size) >= addr; curr_size += 0x1000000) { - if (auto ptr = utils::memory_reserve(curr_size, (void*)addr)) + if (auto ptr = utils::memory_reserve(curr_size, reinterpret_cast(addr))) { if (max_addr == 0 || max_size < curr_size) { @@ -331,8 +331,8 @@ class LLVMSegmentAllocator if (max_addr == 0) break; - if (auto ptr = utils::memory_reserve(max_size, (void*)max_addr)) - found_segs[num_segs++] = Segment(ptr, u32(max_size)); + if (auto ptr = utils::memory_reserve(max_size, reinterpret_cast(max_addr))) + found_segs[num_segs++] = Segment(ptr, static_cast(max_size)); start_addr = max_addr + max_size; } @@ -353,7 +353,7 @@ class LLVMSegmentAllocator if (auto ptr = utils::memory_reserve(DEFAULT_SEGMENT_SIZE)) { - m_curr.addr = (u8*)ptr; + m_curr.addr = static_cast(ptr); m_curr.size = DEFAULT_SEGMENT_SIZE; m_curr.used = 0; } @@ -378,7 +378,7 @@ class LLVMSegmentAllocator store_curr(); u32 best_idx = UINT_MAX; - for (u32 i = 0, segs_size = (u32)m_segs.size(); i < segs_size; i++) + for (u32 i = 0, segs_size = ::size32(m_segs); i < segs_size; i++) { const auto seg_remaining = m_segs[i].remaining(); if (seg_remaining < size) @@ -393,7 +393,7 @@ class LLVMSegmentAllocator const auto size_to_reserve = (size > DEFAULT_SEGMENT_SIZE) ? ::align(size+4096, 4096) : DEFAULT_SEGMENT_SIZE; if (auto ptr = utils::memory_reserve(size_to_reserve)) { - best_idx = (u32)m_segs.size(); + best_idx = ::size32(m_segs); m_segs.emplace_back(ptr, size_to_reserve); } else @@ -407,17 +407,22 @@ class LLVMSegmentAllocator return true; } - std::pair current_segment() const { return std::make_pair(u64(m_curr.addr), m_curr.size); } + std::pair current_segment() const + { + return std::make_pair(reinterpret_cast(m_curr.addr), m_curr.size); + } + std::pair find_segment(u64 addr) const { for (const auto& seg: m_segs) { - if (addr < (u64)seg.addr) + const u64 seg_addr = reinterpret_cast(seg.addr); + if (addr < seg_addr) continue; - const auto end_addr = u64(seg.addr) + seg.size; + const auto end_addr = seg_addr + seg.size; if (addr < end_addr) - return std::make_pair(u64(seg.addr), seg.size); + return std::make_pair(seg_addr, seg.size); } return std::make_pair(0, 0); @@ -438,7 +443,10 @@ class LLVMSegmentAllocator if (store_curr()) m_curr = Segment(); - auto allocated_it = std::remove_if(m_segs.begin(), m_segs.end(), [](const Segment& seg) { return u64(seg.addr + seg.size) > 0x80000000u; }); + auto allocated_it = std::remove_if(m_segs.begin(), m_segs.end(), [](const Segment& seg) + { + return reinterpret_cast(seg.addr + seg.size) > 0x80000000u; + }); if (allocated_it != m_segs.end()) { for (auto it = allocated_it; it != m_segs.end(); ++it) @@ -475,7 +483,10 @@ class LLVMSegmentAllocator struct Segment { Segment() {} - Segment(void* addr, u32 size) : addr((u8*)addr), size(size) {} + Segment(void* addr, u32 size) + : addr(static_cast(addr)) + , size(size) + {} u8* addr = nullptr; u32 size = 0; @@ -572,12 +583,12 @@ struct MemoryManager : llvm::RTDyldMemoryManager else { LOG_ERROR(GENERAL, "LLVM: Linkage failed: %s", name); - addr = (u64)null; + addr = reinterpret_cast(null); } } // Verify address for small code model - const u64 code_start = u64(m_code_addr); + const u64 code_start = reinterpret_cast(m_code_addr); const s64 addr_diff = addr - code_start; if (addr_diff < INT_MIN || addr_diff > INT_MAX) { @@ -587,7 +598,7 @@ struct MemoryManager : llvm::RTDyldMemoryManager // Allocate memory for trampolines if (m_tramps) { - const s64 tramps_diff = u64(m_tramps) - code_start; + const s64 tramps_diff = reinterpret_cast(m_tramps) - code_start; if (tramps_diff < INT_MIN || tramps_diff > INT_MAX) m_tramps = nullptr; //previously allocated trampoline section too far away now } @@ -609,10 +620,10 @@ struct MemoryManager : llvm::RTDyldMemoryManager data[0x6] = 0x48; // MOV rax, imm64 (not executed) data[0x7] = 0xb8; std::memcpy(data.data() + 8, &addr, 8); - addr = (u64)&data; + addr = reinterpret_cast(&data); // Reset pointer (memory page exhausted) - if (((u64)m_tramps % 4096) == 0) + if ((reinterpret_cast(m_tramps) % 4096) == 0) { m_tramps = nullptr; } @@ -624,9 +635,9 @@ struct MemoryManager : llvm::RTDyldMemoryManager bool needsToReserveAllocationSpace() override { return true; } void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign, uintptr_t RODataSize, uint32_t RODataAlign, uintptr_t RWDataSize, uint32_t RWDataAlign) override { - const u32 wanted_code_size = ::align(u32(CodeSize), std::min(4096u, CodeAlign)); - const u32 wanted_rodata_size = ::align(u32(RODataSize), std::min(4096u, RODataAlign)); - const u32 wanted_rwdata_size = ::align(u32(RWDataSize), std::min(4096u, RWDataAlign)); + const u32 wanted_code_size = ::align(static_cast(CodeSize), std::min(4096u, CodeAlign)); + const u32 wanted_rodata_size = ::align(static_cast(RODataSize), std::min(4096u, RODataAlign)); + const u32 wanted_rwdata_size = ::align(static_cast(RWDataSize), std::min(4096u, RWDataAlign)); // Lock memory manager std::lock_guard lock(s_mutex); @@ -638,7 +649,7 @@ struct MemoryManager : llvm::RTDyldMemoryManager u8* allocateCodeSection(std::uintptr_t size, uint align, uint sec_id, llvm::StringRef sec_name) override { void* ptr = nullptr; - const u32 wanted_size = ::align(u32(size), 4096); + const u32 wanted_size = ::align(static_cast(size), 4096); { // Lock memory manager std::lock_guard lock(s_mutex); @@ -653,16 +664,16 @@ struct MemoryManager : llvm::RTDyldMemoryManager return nullptr; } utils::memory_commit(ptr, size, utils::protection::wx); - m_code_addr = (u8*)ptr; + m_code_addr = static_cast(ptr); LOG_NOTICE(GENERAL, "LLVM: Code section %u '%s' allocated -> %p (size=0x%llx, aligned 0x%x)", sec_id, sec_name.data(), ptr, size, align); - return (u8*)ptr; + return static_cast(ptr); } u8* allocateDataSection(std::uintptr_t size, uint align, uint sec_id, llvm::StringRef sec_name, bool is_ro) override { void* ptr = nullptr; - const u32 wanted_size = ::align(u32(size), 4096); + const u32 wanted_size = ::align(static_cast(size), 4096); { // Lock memory manager std::lock_guard lock(s_mutex); @@ -684,7 +695,7 @@ struct MemoryManager : llvm::RTDyldMemoryManager utils::memory_commit(ptr, size); LOG_NOTICE(GENERAL, "LLVM: Data section %u '%s' allocated -> %p (size=0x%llx, aligned 0x%x, %s)", sec_id, sec_name.data(), ptr, size, align, is_ro ? "ro" : "rw"); - return (u8*)ptr; + return static_cast(ptr); } bool finalizeMemory(std::string* = nullptr) override @@ -868,7 +879,7 @@ struct EventListener : llvm::JITEventListener // Use current memory segment as a BASE, compute the difference const u64 segment_start = s_alloc.current_segment().first; - const u64 code_diff = u64(m_mem.m_code_addr) - segment_start; + const u64 code_diff = reinterpret_cast(m_mem.m_code_addr) - segment_start; // Fix RUNTIME_FUNCTION records (.pdata section) for (auto& rf : rfs) diff --git a/rpcs3/Emu/Cell/Modules/cellAdec.cpp b/rpcs3/Emu/Cell/Modules/cellAdec.cpp index b6fbfcbefe7e..da45db92fba3 100644 --- a/rpcs3/Emu/Cell/Modules/cellAdec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAdec.cpp @@ -351,7 +351,7 @@ class AudioDecoder : public ppu_thread { fmt::throw_exception("avformat_alloc_context() failed" HERE); } - io_buf = (u8*)av_malloc(4096); + io_buf = static_cast(av_malloc(4096)); fmt->pb = avio_alloc_context(io_buf, 256, 0, this, adecRead, NULL, NULL); if (!fmt->pb) { @@ -457,7 +457,7 @@ class AudioDecoder : public ppu_thread if (size) { - data = (u8*)av_calloc(1, size + AV_INPUT_BUFFER_PADDING_SIZE); + data = static_cast(av_calloc(1, size + AV_INPUT_BUFFER_PADDING_SIZE)); this->size = size + AV_INPUT_BUFFER_PADDING_SIZE; } else @@ -579,10 +579,10 @@ class AudioDecoder : public ppu_thread // frame.pts = ts/* - first_pts*/; // last_pts = frame.pts; //} - last_pts += ((u64)frame.data->nb_samples) * 90000 / frame.data->sample_rate; + last_pts += frame.data->nb_samples * 90000ull / frame.data->sample_rate; frame.pts = last_pts; - s32 nbps = av_get_bytes_per_sample((AVSampleFormat)frame.data->format); + s32 nbps = av_get_bytes_per_sample(static_cast(frame.data->format)); switch (frame.data->format) { case AV_SAMPLE_FMT_FLTP: break; @@ -621,7 +621,7 @@ class AudioDecoder : public ppu_thread default: { - fmt::throw_exception("Unknown task(%d)" HERE, (u32)task.type); + fmt::throw_exception("Unknown task(%d)" HERE, +task.type); } } } @@ -632,7 +632,7 @@ class AudioDecoder : public ppu_thread int adecRead(void* opaque, u8* buf, int buf_size) { - AudioDecoder& adec = *(AudioDecoder*)opaque; + AudioDecoder& adec = *static_cast(opaque); int res = 0; @@ -642,7 +642,7 @@ int adecRead(void* opaque, u8* buf, int buf_size) u8 code1 = vm::read8(adec.reader.addr + 2); u8 code2 = vm::read8(adec.reader.addr + 3); adec.ch_cfg = (code1 >> 2) & 0x7; - adec.frame_size = ((((u32)code1 & 0x3) << 8) | (u32)code2) * 8 + 8; + adec.frame_size = (((u32{code1} & 0x3) << 8) | code2) * 8 + 8; adec.sample_rate = at3freq[code1 >> 5]; adec.reader.size -= 8; @@ -668,7 +668,7 @@ int adecRead(void* opaque, u8* buf, int buf_size) adec.reader.init = true; } - if (adec.reader.size < (u32)buf_size /*&& !adec.just_started*/) + if (adec.reader.size < static_cast(buf_size) /*&& !adec.just_started*/) { AdecTask task; if (!adec.job.peek(task, 0, &adec.is_closed)) @@ -707,7 +707,7 @@ int adecRead(void* opaque, u8* buf, int buf_size) default: { - cellAdec.error("adecRawRead(): unknown task (%d)", (u32)task.type); + cellAdec.error("adecRawRead(): unknown task (%d)", +task.type); Emu.Pause(); return -1; } @@ -716,7 +716,7 @@ int adecRead(void* opaque, u8* buf, int buf_size) goto next; } // TODO:: Syphurith: I don't know whether we should keep this else-if now. Since the if condition is same with this one. - else if (adec.reader.size < (u32)buf_size) + else if (adec.reader.size < static_cast(buf_size)) { buf_size = adec.reader.size; } @@ -864,8 +864,10 @@ error_code cellAdecStartSeq(u32 handle, u32 param) task.at3p.output = atx->bw_pcm; task.at3p.downmix = atx->downmix_flag; task.at3p.ats_header = atx->au_includes_ats_hdr_flg; - cellAdec.todo("*** CellAdecParamAtracX: sr=%d, ch_cfg=%d(%d), frame_size=0x%x, extra=0x%x, output=%d, downmix=%d, ats_header=%d", - task.at3p.sample_rate, task.at3p.channel_config, task.at3p.channels, task.at3p.frame_size, (u32&)task.at3p.extra_config, task.at3p.output, task.at3p.downmix, task.at3p.ats_header); + cellAdec.todo("*** CellAdecParamAtracX: sr=%d, ch_cfg=%d(%d), frame_size=0x%x, extra=%u:%u:%u:%u, output=%d, downmix=%d, ats_header=%d", + task.at3p.sample_rate, task.at3p.channel_config, task.at3p.channels, task.at3p.frame_size, + task.at3p.extra_config[0], task.at3p.extra_config[1], task.at3p.extra_config[2], task.at3p.extra_config[3], + task.at3p.output, task.at3p.downmix, task.at3p.ats_header); break; } case CELL_ADEC_TYPE_MP3: @@ -917,7 +919,7 @@ error_code cellAdecDecodeAu(u32 handle, vm::ptr auInfo) task.au.auInfo_addr = auInfo.addr(); task.au.addr = auInfo->startAddr; task.au.size = auInfo->size; - task.au.pts = ((u64)auInfo->pts.upper << 32) | (u64)auInfo->pts.lower; + task.au.pts = (u64{auInfo->pts.upper} << 32) | u64{auInfo->pts.lower}; task.au.userdata = auInfo->userData; //cellAdec.notice("cellAdecDecodeAu(): addr=0x%x, size=0x%x, pts=0x%llx", task.au.addr, task.au.size, task.au.pts); @@ -954,7 +956,7 @@ error_code cellAdecGetPcm(u32 handle, vm::ptr outBuffer) // reverse byte order: if (frame->format == AV_SAMPLE_FMT_FLTP && frame->channels == 1) { - float* in_f = (float*)frame->extended_data[0]; + float* in_f = reinterpret_cast(frame->extended_data[0]); for (u32 i = 0; i < af.size / 4; i++) { outBuffer[i] = in_f[i]; @@ -963,8 +965,8 @@ error_code cellAdecGetPcm(u32 handle, vm::ptr outBuffer) else if (frame->format == AV_SAMPLE_FMT_FLTP && frame->channels == 2) { float* in_f[2]; - in_f[0] = (float*)frame->extended_data[0]; - in_f[1] = (float*)frame->extended_data[1]; + in_f[0] = reinterpret_cast(frame->extended_data[0]); + in_f[1] = reinterpret_cast(frame->extended_data[1]); for (u32 i = 0; i < af.size / 8; i++) { outBuffer[i * 2 + 0] = in_f[0][i]; @@ -974,12 +976,12 @@ error_code cellAdecGetPcm(u32 handle, vm::ptr outBuffer) else if (frame->format == AV_SAMPLE_FMT_FLTP && frame->channels == 6) { float* in_f[6]; - in_f[0] = (float*)frame->extended_data[0]; - in_f[1] = (float*)frame->extended_data[1]; - in_f[2] = (float*)frame->extended_data[2]; - in_f[3] = (float*)frame->extended_data[3]; - in_f[4] = (float*)frame->extended_data[4]; - in_f[5] = (float*)frame->extended_data[5]; + in_f[0] = reinterpret_cast(frame->extended_data[0]); + in_f[1] = reinterpret_cast(frame->extended_data[1]); + in_f[2] = reinterpret_cast(frame->extended_data[2]); + in_f[3] = reinterpret_cast(frame->extended_data[3]); + in_f[4] = reinterpret_cast(frame->extended_data[4]); + in_f[5] = reinterpret_cast(frame->extended_data[5]); for (u32 i = 0; i < af.size / 24; i++) { outBuffer[i * 6 + 0] = in_f[0][i]; @@ -993,14 +995,14 @@ error_code cellAdecGetPcm(u32 handle, vm::ptr outBuffer) else if (frame->format == AV_SAMPLE_FMT_FLTP && frame->channels == 8) { float* in_f[8]; - in_f[0] = (float*)frame->extended_data[0]; - in_f[1] = (float*)frame->extended_data[1]; - in_f[2] = (float*)frame->extended_data[2]; - in_f[3] = (float*)frame->extended_data[3]; - in_f[4] = (float*)frame->extended_data[4]; - in_f[5] = (float*)frame->extended_data[5]; - in_f[6] = (float*)frame->extended_data[6]; - in_f[7] = (float*)frame->extended_data[7]; + in_f[0] = reinterpret_cast(frame->extended_data[0]); + in_f[1] = reinterpret_cast(frame->extended_data[1]); + in_f[2] = reinterpret_cast(frame->extended_data[2]); + in_f[3] = reinterpret_cast(frame->extended_data[3]); + in_f[4] = reinterpret_cast(frame->extended_data[4]); + in_f[5] = reinterpret_cast(frame->extended_data[5]); + in_f[6] = reinterpret_cast(frame->extended_data[6]); + in_f[7] = reinterpret_cast(frame->extended_data[7]); for (u32 i = 0; i < af.size / 24; i++) { outBuffer[i * 8 + 0] = in_f[0][i]; @@ -1015,21 +1017,21 @@ error_code cellAdecGetPcm(u32 handle, vm::ptr outBuffer) } else if (frame->format == AV_SAMPLE_FMT_S16P && frame->channels == 1) { - s16* in_i = (s16*)frame->extended_data[0]; + s16* in_i = reinterpret_cast(frame->extended_data[0]); for (u32 i = 0; i < af.size / 2; i++) { - outBuffer[i] = (float)in_i[i] / 0x8000; + outBuffer[i] = in_i[i] / 32768.f; } } else if (frame->format == AV_SAMPLE_FMT_S16P && frame->channels == 2) { s16* in_i[2]; - in_i[0] = (s16*)frame->extended_data[0]; - in_i[1] = (s16*)frame->extended_data[1]; + in_i[0] = reinterpret_cast(frame->extended_data[0]); + in_i[1] = reinterpret_cast(frame->extended_data[1]); for (u32 i = 0; i < af.size / 4; i++) { - outBuffer[i * 2 + 0] = (float)in_i[0][i] / 0x8000; - outBuffer[i * 2 + 1] = (float)in_i[1][i] / 0x8000; + outBuffer[i * 2 + 0] = in_i[0][i] / 32768.f; + outBuffer[i * 2 + 1] = in_i[1][i] / 32768.f; } } else @@ -1074,8 +1076,8 @@ error_code cellAdecGetPcmItem(u32 handle, vm::pptr pcmItem) pcm->startAddr = 0x00000312; // invalid address (no output) pcm->size = af.size; pcm->status = CELL_OK; - pcm->auInfo.pts.lower = (u32)(af.pts); - pcm->auInfo.pts.upper = (u32)(af.pts >> 32); + pcm->auInfo.pts.lower = static_cast(af.pts); + pcm->auInfo.pts.upper = static_cast(af.pts >> 32); pcm->auInfo.size = af.auSize; pcm->auInfo.startAddr = af.auAddr; pcm->auInfo.userData = af.userdata; diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index 555585e43b1a..8d031040c451 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -1119,7 +1119,7 @@ error_code cellAudioGetPortConfig(u32 portNum, vm::ptr port case audio_port_state::closed: portConfig->status = CELL_AUDIO_STATUS_CLOSE; break; case audio_port_state::opened: portConfig->status = CELL_AUDIO_STATUS_READY; break; case audio_port_state::started: portConfig->status = CELL_AUDIO_STATUS_RUN; break; - default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, (u32)state); + default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, static_cast(state)); } portConfig->nChannel = port.num_channels; @@ -1152,7 +1152,7 @@ error_code cellAudioPortStart(u32 portNum) case audio_port_state::closed: return CELL_AUDIO_ERROR_PORT_NOT_OPEN; case audio_port_state::started: return CELL_AUDIO_ERROR_PORT_ALREADY_RUN; case audio_port_state::opened: return CELL_OK; - default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, (u32)state); + default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, static_cast(state)); } } @@ -1179,7 +1179,7 @@ error_code cellAudioPortClose(u32 portNum) case audio_port_state::closed: return CELL_AUDIO_ERROR_PORT_NOT_OPEN; case audio_port_state::started: return CELL_OK; case audio_port_state::opened: return CELL_OK; - default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, (u32)state); + default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, static_cast(state)); } } @@ -1206,7 +1206,7 @@ error_code cellAudioPortStop(u32 portNum) case audio_port_state::closed: return CELL_AUDIO_ERROR_PORT_NOT_RUN; case audio_port_state::started: return CELL_OK; case audio_port_state::opened: return CELL_AUDIO_ERROR_PORT_NOT_RUN; - default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, (u32)state); + default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, static_cast(state)); } } diff --git a/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp b/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp index 124a5db7ce0d..9ea98cdda6ba 100644 --- a/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp @@ -213,14 +213,14 @@ error_code cellAudioInGetAvailableDeviceInfo(u32 count, vm::ptrget(); - u32 num_devices_returned = std::min(count, (u32)av_manager->devices.size()); + u32 num_devices_returned = std::min(count, ::size32(av_manager->devices)); for (u32 index = 0; index < num_devices_returned; index++) { av_manager->copy_device_info(index, device_info + index); } - return not_an_error((s32)num_devices_returned); + return not_an_error(num_devices_returned); } error_code cellAudioOutGetAvailableDeviceInfo(u32 count, vm::ptr info) diff --git a/rpcs3/Emu/Cell/Modules/cellBgdl.cpp b/rpcs3/Emu/Cell/Modules/cellBgdl.cpp index 0dfcaeed8ef9..424a5acf5a05 100644 --- a/rpcs3/Emu/Cell/Modules/cellBgdl.cpp +++ b/rpcs3/Emu/Cell/Modules/cellBgdl.cpp @@ -4,8 +4,6 @@ #include "cellBgdl.h" - - LOG_CHANNEL(cellBGDL); error_code cellBGDLGetInfo(vm::cptr content_id, vm::ptr info, s32 num) @@ -22,7 +20,7 @@ error_code cellBGDLGetInfo2(vm::cptr service_id, vm::ptr inf error_code cellBGDLSetMode(CellBGDLMode mode) { - cellBGDL.todo("cellBGDLSetMode(mode=%d)", (s32) mode); + cellBGDL.todo("cellBGDLSetMode(mode=%d)", +mode); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellDmux.cpp b/rpcs3/Emu/Cell/Modules/cellDmux.cpp index 9aaa7cfd52de..42d2aaa6c97e 100644 --- a/rpcs3/Emu/Cell/Modules/cellDmux.cpp +++ b/rpcs3/Emu/Cell/Modules/cellDmux.cpp @@ -39,7 +39,7 @@ struct DemuxerStream { if (sizeof(T) > size) return false; - out = vm::_ref(addr); + std::memcpy(&out, vm::base(addr), sizeof(T)); addr += sizeof(T); size -= sizeof(T); @@ -51,7 +51,7 @@ struct DemuxerStream { if (sizeof(T) + shift > size) return false; - out = vm::_ref(addr + shift); + std::memcpy(&out, vm::base(addr + shift), sizeof(T)); return true; } @@ -68,12 +68,12 @@ struct DemuxerStream u64 get_ts(u8 c) { - u8 v[4]; get((u32&)v); + u8 v[4]; get(v); return - (((u64)c & 0x0e) << 29) | - (((u64)v[0]) << 21) | - (((u64)v[1] & 0x7e) << 15) | - (((u64)v[2]) << 7) | ((u64)v[3] >> 1); + ((u64{c} & 0x0e) << 29) | + ((u64{v[0]}) << 21) | + ((u64{v[1]} & 0x7e) << 15) | + ((u64{v[2]}) << 7) | (u64{v[3]} >> 1); } }; @@ -380,10 +380,10 @@ class Demuxer : public ppu_thread if (data[0] != 0x0f || data[1] != 0xd0) { - fmt::throw_exception("ATX: 0x0fd0 header not found (ats=0x%llx)" HERE, *(be_t*)data); + fmt::throw_exception("ATX: 0x0fd0 header not found (ats=0x%llx)" HERE, *reinterpret_cast*>(data)); } - u32 frame_size = ((((u32)data[2] & 0x3) << 8) | (u32)data[3]) * 8 + 8; + u32 frame_size = (((u32{data[2]} & 0x3) << 8) | u32{data[3]}) * 8 + 8; if (size < frame_size + 8) break; // skip non-complete AU @@ -445,7 +445,7 @@ class Demuxer : public ppu_thread { ElementaryStream& es = *esAVC[ch]; - const u32 old_size = (u32)es.raw_data.size(); + const u32 old_size = ::size32(es.raw_data); if (es.isfull(old_size)) { stream = backup; @@ -611,7 +611,7 @@ class Demuxer : public ppu_thread { ElementaryStream& es = *task.es.es_ptr; - const u32 old_size = (u32)es.raw_data.size(); + const u32 old_size = ::size32(es.raw_data); if (old_size && (es.fidMajor & -0x10) == 0xe0) { // TODO (it's only for AVC, some ATX data may be lost) @@ -634,7 +634,7 @@ class Demuxer : public ppu_thread if (es.raw_data.size()) { - cellDmux.error("dmuxFlushEs: 0x%x bytes lost (es_id=%d)", (u32)es.raw_data.size(), es.id); + cellDmux.error("dmuxFlushEs: 0x%x bytes lost (es_id=%d)", ::size32(es.raw_data), es.id); } // callback @@ -659,7 +659,7 @@ class Demuxer : public ppu_thread default: { - fmt::throw_exception("Demuxer thread error: unknown task (0x%x)" HERE, (u32)task.type); + fmt::throw_exception("Demuxer thread error: unknown task (0x%x)" HERE, +task.type); } } } @@ -816,10 +816,10 @@ void ElementaryStream::push_au(u32 size, u64 dts, u64 pts, u64 userdata, bool ra auto info = vm::ptr::make(put); info->auAddr = put + 128; info->auSize = size; - info->dts.lower = (u32)(dts); - info->dts.upper = (u32)(dts >> 32); - info->pts.lower = (u32)(pts); - info->pts.upper = (u32)(pts >> 32); + info->dts.lower = static_cast(dts); + info->dts.upper = static_cast(dts >> 32); + info->pts.lower = static_cast(pts); + info->pts.upper = static_cast(pts >> 32); info->isRap = rap; info->reserved = 0; info->userData = userdata; @@ -830,10 +830,10 @@ void ElementaryStream::push_au(u32 size, u64 dts, u64 pts, u64 userdata, bool ra auto inf = vm::ptr::make(put + 64); inf->auAddr = put + 128; inf->auSize = size; - inf->dtsLower = (u32)(dts); - inf->dtsUpper = (u32)(dts >> 32); - inf->ptsLower = (u32)(pts); - inf->ptsUpper = (u32)(pts >> 32); + inf->dtsLower = static_cast(dts); + inf->dtsUpper = static_cast(dts >> 32); + inf->ptsLower = static_cast(pts); + inf->ptsUpper = static_cast(pts >> 32); inf->auMaxSize = 0; // ????? inf->userData = userdata; diff --git a/rpcs3/Emu/Cell/Modules/cellFont.cpp b/rpcs3/Emu/Cell/Modules/cellFont.cpp index cdc416df6d2b..da4a4cf1b440 100644 --- a/rpcs3/Emu/Cell/Modules/cellFont.cpp +++ b/rpcs3/Emu/Cell/Modules/cellFont.cpp @@ -2,8 +2,6 @@ #include "Emu/System.h" #include "Emu/Cell/PPUModule.h" -// Defines STB_TRUETYPE_IMPLEMENTATION *once* before including stb_truetype.h (as noted in stb_truetype.h's comments) -#define STB_TRUETYPE_IMPLEMENTATION #include #include "cellFont.h" @@ -51,7 +49,7 @@ s32 cellFontOpenFontMemory(vm::ptr library, u32 fontAddr, u32 f { cellFont.warning("cellFontOpenFontMemory(library=*0x%x, fontAddr=0x%x, fontSize=%d, subNum=%d, uniqueId=%d, font=*0x%x)", library, fontAddr, fontSize, subNum, uniqueId, font); - font->stbfont = (stbtt_fontinfo*)((u8*)&(font->stbfont) + sizeof(void*)); // hack: use next bytes of the struct + font->stbfont = vm::_ptr(font.addr() + font.size()); // hack: use next bytes of the struct if (!stbtt_InitFont(font->stbfont, vm::_ptr(fontAddr), 0)) return CELL_FONT_ERROR_FONT_OPEN_FAILED; @@ -92,7 +90,7 @@ s32 cellFontOpenFontset(ppu_thread& ppu, vm::ptr library, vm::p } std::string file; - switch((u32)fontType->type) + switch (fontType->type) { case CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN: file = "/dev_flash/data/font/SCE-PS3-RD-R-LATIN.TTF"; break; case CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN: file = "/dev_flash/data/font/SCE-PS3-RD-L-LATIN.TTF"; break; @@ -321,22 +319,22 @@ s32 cellFontRenderCharGlyphImage(vm::ptr font, u32 code, vm::ptrstbfont, &ascent, &descent, &lineGap); - baseLineY = (int)((float)ascent * scale); // ??? + baseLineY = static_cast(ascent * scale); // ??? // Move the rendered character to the surface unsigned char* buffer = vm::_ptr(surface->buffer.addr()); - for (u32 ypos = 0; ypos < (u32)height; ypos++) + for (u32 ypos = 0; ypos < static_cast(height); ypos++) { - if ((u32)y + ypos + yoff + baseLineY >= (u32)surface->height) + if (static_cast(y) + ypos + yoff + baseLineY >= static_cast(surface->height)) break; - for (u32 xpos = 0; xpos < (u32)width; xpos++) + for (u32 xpos = 0; xpos < static_cast(width); xpos++) { - if ((u32)x + xpos >= (u32)surface->width) + if (static_cast(x) + xpos >= static_cast(surface->width)) break; // TODO: There are some oddities in the position of the character in the final buffer - buffer[((s32)y + ypos + yoff + baseLineY)*surface->width + (s32)x + xpos] = box[ypos * width + xpos]; + buffer[(static_cast(y) + ypos + yoff + baseLineY) * surface->width + static_cast(x) + xpos] = box[ypos * width + xpos]; } } stbtt_FreeBitmap(box, 0); @@ -407,9 +405,9 @@ s32 cellFontGetCharGlyphMetrics(vm::ptr font, u32 code, vm::ptrwidth = (x1-x0) * scale; metrics->height = (y1-y0) * scale; - metrics->h_bearingX = (float)leftSideBearing * scale; + metrics->h_bearingX = leftSideBearing * scale; metrics->h_bearingY = 0.f; - metrics->h_advance = (float)advanceWidth * scale; + metrics->h_advance = advanceWidth * scale; metrics->v_bearingX = 0.f; metrics->v_bearingY = 0.f; metrics->v_advance = 0.f; diff --git a/rpcs3/Emu/Cell/Modules/cellGame.cpp b/rpcs3/Emu/Cell/Modules/cellGame.cpp index 127da9c1768e..767fc33975cd 100644 --- a/rpcs3/Emu/Cell/Modules/cellGame.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGame.cpp @@ -572,7 +572,7 @@ error_code cellGameDataCheckCreate2(ppu_thread& ppu, u32 version, vm::cptr funcStat(ppu, cbResult, cbGet, cbSet); - switch ((s32)cbResult->result) + switch (cbResult->result) { case CELL_GAMEDATA_CBRESULT_OK_CANCEL: { diff --git a/rpcs3/Emu/Cell/Modules/cellGifDec.cpp b/rpcs3/Emu/Cell/Modules/cellGifDec.cpp index 010a64354803..1646b2a0312b 100644 --- a/rpcs3/Emu/Cell/Modules/cellGifDec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGifDec.cpp @@ -105,8 +105,8 @@ s32 cellGifDecReadHeader(PMainHandle mainHandle, PSubHandle subHandle, PInfo inf } } - if (*(be_t*)buffer != 0x47494638 || - (*(le_t*)(buffer + 4) != 0x6139 && *(le_t*)(buffer + 4) != 0x6137)) // Error: The first 6 bytes are not a valid GIF signature + if (*reinterpret_cast*>(buffer) != 0x47494638 || + (*reinterpret_cast*>(buffer + 4) != 0x6139 && *reinterpret_cast*>(buffer + 4) != 0x6137)) // Error: The first 6 bytes are not a valid GIF signature { return CELL_GIFDEC_ERROR_STREAM_FORMAT; // Surprisingly there is no error code related with headerss } @@ -143,7 +143,7 @@ s32 cellGifDecSetParameter(PMainHandle mainHandle, PSubHandle subHandle, PInPara current_outParam.outputWidth = current_info.SWidth; current_outParam.outputHeight = current_info.SHeight; current_outParam.outputColorSpace = inParam->colorSpace; - switch ((u32)current_outParam.outputColorSpace) + switch (current_outParam.outputColorSpace) { case CELL_GIFDEC_RGBA: case CELL_GIFDEC_ARGB: current_outParam.outputComponents = 4; break; @@ -169,8 +169,8 @@ s32 cellGifDecDecodeData(PMainHandle mainHandle, PSubHandle subHandle, vm::ptrstatus = CELL_GIFDEC_DEC_STATUS_STOP; - const u32& fd = subHandle->fd; - const u64& fileSize = subHandle->fileSize; + const u32 fd = subHandle->fd; + const u64 fileSize = subHandle->fileSize; const CellGifDecOutParam& current_outParam = subHandle->outParam; //Copy the GIF file to a buffer @@ -195,18 +195,18 @@ s32 cellGifDecDecodeData(PMainHandle mainHandle, PSubHandle subHandle, vm::ptr ( - stbi_load_from_memory(gif.get(), (s32)fileSize, &width, &height, &actual_components, 4), + stbi_load_from_memory(gif.get(), ::narrow(fileSize), &width, &height, &actual_components, 4), &::free ); if (!image) return CELL_GIFDEC_ERROR_STREAM_FORMAT; - const int bytesPerLine = (u32)dataCtrlParam->outputBytesPerLine; + const int bytesPerLine = static_cast(dataCtrlParam->outputBytesPerLine); const char nComponents = 4; uint image_size = width * height * nComponents; - switch((u32)current_outParam.outputColorSpace) + switch(current_outParam.outputColorSpace) { case CELL_GIFDEC_RGBA: { @@ -233,7 +233,7 @@ s32 cellGifDecDecodeData(PMainHandle mainHandle, PSubHandle subHandle, vm::ptr(linesize); for (int i = 0; i < height; i++) { const int dstOffset = i * bytesPerLine; @@ -245,15 +245,14 @@ s32 cellGifDecDecodeData(PMainHandle mainHandle, PSubHandle subHandle, vm::ptr(image_size); + uint* source_current = reinterpret_cast(image.get()); + uint* dest_current = img.get(); for (uint i = 0; i < image_size / nComponents; i++) { uint val = *source_current; @@ -261,8 +260,7 @@ s32 cellGifDecDecodeData(PMainHandle mainHandle, PSubHandle subHandle, vm::ptr uri, vm::cptr str, vm::ptrscheme.set(pool.addr() + schemeOffset); uri->hostname.set(pool.addr() + hostOffset); @@ -59,7 +59,7 @@ s32 cellHttpUtilParseUri(vm::ptr uri, vm::cptr str, vm::ptrport = (u32)80; + uri->port = 80; } return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellJpgDec.cpp b/rpcs3/Emu/Cell/Modules/cellJpgDec.cpp index 2f9f7e557f4c..e1d90b7ef9b2 100644 --- a/rpcs3/Emu/Cell/Modules/cellJpgDec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellJpgDec.cpp @@ -118,8 +118,8 @@ s32 cellJpgDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr } } - if ((le_t&)(buffer[0]) != 0xE0FFD8FF || // Error: Not a valid SOI header - (le_t&)(buffer[6]) != 0x4649464A) // Error: Not a valid JFIF string + if (*reinterpret_cast*>(buffer.get()) != 0xE0FFD8FF || // Error: Not a valid SOI header + *reinterpret_cast(buffer.get() + 6) != "JFIF"_u32) // Error: Not a valid JFIF string { return CELL_JPGDEC_ERROR_HEADER; } @@ -202,7 +202,7 @@ s32 cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::cp int width, height, actual_components; auto image = std::unique_ptr ( - stbi_load_from_memory(jpg.get(), (s32)fileSize, &width, &height, &actual_components, 4), + stbi_load_from_memory(jpg.get(), ::narrow(fileSize), &width, &height, &actual_components, 4), &::free ); @@ -210,10 +210,10 @@ s32 cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::cp return CELL_JPGDEC_ERROR_STREAM_FORMAT; const bool flip = current_outParam.outputMode == CELL_JPGDEC_BOTTOM_TO_TOP; - const int bytesPerLine = (u32)dataCtrlParam->outputBytesPerLine; + const int bytesPerLine = static_cast(dataCtrlParam->outputBytesPerLine); size_t image_size = width * height; - switch((u32)current_outParam.outputColorSpace) + switch(current_outParam.outputColorSpace) { case CELL_JPG_RGB: case CELL_JPG_RGBA: @@ -245,7 +245,7 @@ s32 cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::cp { //TODO: Find out if we can't do padding without an extra copy const int linesize = std::min(bytesPerLine, width * nComponents); - char *output = (char *) malloc(linesize); + const auto output = std::make_unique(linesize); for (int i = 0; i < height; i++) { const int dstOffset = i * bytesPerLine; @@ -257,15 +257,14 @@ s32 cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::cp output[j + 2] = image.get()[srcOffset + j + 1]; output[j + 3] = image.get()[srcOffset + j + 2]; } - memcpy(&data[dstOffset], output, linesize); + std::memcpy(&data[dstOffset], output.get(), linesize); } - free(output); } else { - uint* img = (uint*)new char[image_size]; - uint* source_current = (uint*)&(image.get()[0]); - uint* dest_current = img; + const auto img = std::make_unique(image_size); + uint* source_current = reinterpret_cast(image.get()); + uint* dest_current = img.get(); for (uint i = 0; i < image_size / nComponents; i++) { uint val = *source_current; @@ -273,8 +272,7 @@ s32 cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::cp source_current++; dest_current++; } - memcpy(data.get_ptr(), img, image_size); - delete[] img; + std::memcpy(data.get_ptr(), img.get(), image_size); } } break; @@ -294,7 +292,7 @@ s32 cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::cp dataOutInfo->status = CELL_JPGDEC_DEC_STATUS_FINISH; if(dataCtrlParam->outputBytesPerLine) - dataOutInfo->outputLines = (u32)(image_size / dataCtrlParam->outputBytesPerLine); + dataOutInfo->outputLines = static_cast(image_size / dataCtrlParam->outputBytesPerLine); return CELL_OK; } @@ -324,7 +322,7 @@ s32 cellJpgDecSetParameter(u32 mainHandle, u32 subHandle, vm::cptroutputColorSpace; - switch ((u32)current_outParam.outputColorSpace) + switch (current_outParam.outputColorSpace) { case CELL_JPG_GRAYSCALE: current_outParam.outputComponents = 1; break; diff --git a/rpcs3/Emu/Cell/Modules/cellKb.cpp b/rpcs3/Emu/Cell/Modules/cellKb.cpp index 9c82278a0bae..a86edb4eeff4 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.cpp +++ b/rpcs3/Emu/Cell/Modules/cellKb.cpp @@ -290,7 +290,7 @@ error_code cellKbRead(u32 port_no, vm::ptr data) KbData& current_data = handler->GetData(port_no); data->led = current_data.led; data->mkey = current_data.mkey; - data->len = std::min((s32)CELL_KB_MAX_KEYCODES, current_data.len); + data->len = std::min(CELL_KB_MAX_KEYCODES, current_data.len); for (s32 i = 0; i < current_data.len; i++) { diff --git a/rpcs3/Emu/Cell/Modules/cellMouse.cpp b/rpcs3/Emu/Cell/Modules/cellMouse.cpp index c67fc4179167..d64f01111740 100644 --- a/rpcs3/Emu/Cell/Modules/cellMouse.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMouse.cpp @@ -243,7 +243,7 @@ error_code cellMouseGetDataList(u32 port_no, vm::ptr data) // TODO: check if (current_info.mode[port_no] != CELL_MOUSE_INFO_TABLET_MOUSE_MODE) has any impact auto& list = handler->GetDataList(port_no); - data->list_num = std::min((u32)CELL_MOUSE_MAX_DATA_LIST_NUM, (u32)list.size()); + data->list_num = std::min(CELL_MOUSE_MAX_DATA_LIST_NUM, static_cast(list.size())); int i = 0; for (auto it = list.begin(); it != list.end() && i < CELL_MOUSE_MAX_DATA_LIST_NUM; ++it, ++i) @@ -324,7 +324,7 @@ error_code cellMouseGetTabletDataList(u32 port_no, vm::ptrGetTabletDataList(port_no); - data->list_num = std::min((u32)CELL_MOUSE_MAX_DATA_LIST_NUM, (u32)list.size()); + data->list_num = std::min(CELL_MOUSE_MAX_DATA_LIST_NUM, static_cast(list.size())); int i = 0; for (auto it = list.begin(); it != list.end() && i < CELL_MOUSE_MAX_DATA_LIST_NUM; ++it, ++i) diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index 02cea02d864a..188377e8b64e 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -89,14 +89,14 @@ void sys_spu_image::deploy(u32 loc, sys_spu_segment* segs, u32 nsegs) fmt::append(dump, "\n\t[%d] t=0x%x, ls=0x%x, size=0x%x, addr=0x%x", i, seg.type, seg.ls, seg.size, seg.addr); - sha1_update(&sha, (uchar*)&seg.type, sizeof(seg.type)); + sha1_update(&sha, reinterpret_cast(&seg.type), sizeof(seg.type)); // Hash big-endian values if (seg.type == SYS_SPU_SEGMENT_TYPE_COPY) { std::memcpy(vm::base(loc + seg.ls), vm::base(seg.addr), seg.size); - sha1_update(&sha, (uchar*)&seg.size, sizeof(seg.size)); - sha1_update(&sha, (uchar*)&seg.ls, sizeof(seg.ls)); + sha1_update(&sha, reinterpret_cast(&seg.size), sizeof(seg.size)); + sha1_update(&sha, reinterpret_cast(&seg.ls), sizeof(seg.ls)); sha1_update(&sha, vm::_ptr(seg.addr), seg.size); } else if (seg.type == SYS_SPU_SEGMENT_TYPE_FILL) @@ -107,14 +107,14 @@ void sys_spu_image::deploy(u32 loc, sys_spu_segment* segs, u32 nsegs) } std::fill_n(vm::_ptr(loc + seg.ls), seg.size / 4, seg.addr); - sha1_update(&sha, (uchar*)&seg.size, sizeof(seg.size)); - sha1_update(&sha, (uchar*)&seg.ls, sizeof(seg.ls)); - sha1_update(&sha, (uchar*)&seg.addr, sizeof(seg.addr)); + sha1_update(&sha, reinterpret_cast(&seg.size), sizeof(seg.size)); + sha1_update(&sha, reinterpret_cast(&seg.ls), sizeof(seg.ls)); + sha1_update(&sha, reinterpret_cast(&seg.addr), sizeof(seg.addr)); } else if (seg.type == SYS_SPU_SEGMENT_TYPE_INFO) { const be_t size = seg.size + 0x14; // Workaround - sha1_update(&sha, (uchar*)&size, sizeof(size)); + sha1_update(&sha, reinterpret_cast(&size), sizeof(size)); } } @@ -881,9 +881,9 @@ error_code sys_spu_thread_write_ls(ppu_thread& ppu, u32 id, u32 lsa, u64 value, switch (type) { - case 1: thread->_ref(lsa) = (u8)value; break; - case 2: thread->_ref(lsa) = (u16)value; break; - case 4: thread->_ref(lsa) = (u32)value; break; + case 1: thread->_ref(lsa) = static_cast(value); break; + case 2: thread->_ref(lsa) = static_cast(value); break; + case 4: thread->_ref(lsa) = static_cast(value); break; case 8: thread->_ref(lsa) = value; break; default: ASSUME(0); } @@ -1235,7 +1235,7 @@ error_code sys_spu_thread_bind_queue(ppu_thread& ppu, u32 id, u32 spuq, u32 spuq continue; } - if (v.first == spuq_num || + if (v.first == spuq_num || (!v.second.owner_before(queue) && !queue.owner_before(v.second))) { return CELL_EBUSY; @@ -1747,7 +1747,7 @@ error_code sys_raw_spu_get_spu_cfg(ppu_thread& ppu, u32 id, vm::ptr value) return CELL_ESRCH; } - *value = (u32)thread->snr_config; + *value = static_cast(thread->snr_config); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp index 6c5f758c5759..dd2f4f4a179d 100644 --- a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp @@ -32,7 +32,7 @@ void fmt_class_string::format(std::string& out, u64 arg) datrace += ' '; } - fmt::append(out, "TR[r:%d][sz:%d] => %s", (u8)transfer.status, transfer.actual_length, datrace); + fmt::append(out, "TR[r:%d][sz:%d] => %s", +transfer.status, transfer.actual_length, datrace); } struct UsbLdd @@ -46,7 +46,8 @@ struct UsbLdd struct UsbPipe { std::shared_ptr device = nullptr; - u8 endpoint = 0; + + u8 endpoint = 0; }; class usb_handler_thread @@ -274,11 +275,11 @@ void usb_handler_thread::send_message(u32 message, u32 tr_id) void usb_handler_thread::transfer_complete(struct libusb_transfer* transfer) { - UsbTransfer* usbd_transfer = (UsbTransfer*)transfer->user_data; + UsbTransfer* usbd_transfer = static_cast(transfer->user_data); if (transfer->status != 0) { - sys_usbd.error("Transfer Error: %d", (s32)transfer->status); + sys_usbd.error("Transfer Error: %d", +transfer->status); } switch (transfer->status) @@ -324,13 +325,13 @@ u32 usb_handler_thread::add_ldd(vm::ptr s_product, u16 slen_product, u16 i { UsbLdd new_ldd; new_ldd.name.resize(slen_product); - memcpy(new_ldd.name.data(), s_product.get_ptr(), (u32)slen_product); + memcpy(new_ldd.name.data(), s_product.get_ptr(), slen_product); new_ldd.id_vendor = id_vendor; new_ldd.id_product_min = id_product_min; new_ldd.id_product_max = id_product_max; ldds.push_back(new_ldd); - return (u32)ldds.size(); // TODO: to check + return ::size32(ldds); // TODO: to check } u32 usb_handler_thread::open_pipe(u32 device_handle, u8 endpoint) @@ -341,7 +342,7 @@ u32 usb_handler_thread::open_pipe(u32 device_handle, u8 endpoint) bool usb_handler_thread::close_pipe(u32 pipe_id) { - return (bool)open_pipes.erase(pipe_id); + return open_pipes.erase(pipe_id) != 0; } bool usb_handler_thread::is_pipe(u32 pipe_id) const @@ -482,7 +483,8 @@ s32 sys_usbd_get_device_list(u32 handle, vm::ptr device_list, if (!usbh->is_init) return CELL_EINVAL; - u32 i_tocopy = std::min((s32)max_devices, (s32)usbh->handled_devices.size()); + // TODO: was std::min + u32 i_tocopy = std::min(max_devices, ::size32(usbh->handled_devices)); for (u32 index = 0; index < i_tocopy; index++) { @@ -538,7 +540,7 @@ s32 sys_usbd_get_descriptor(u32 handle, u32 device_handle, vm::ptr descrip return CELL_EINVAL; } - u8* ptr = (u8*)descriptor.get_ptr(); + u8* ptr = static_cast(descriptor.get_ptr()); usbh->handled_devices[device_handle].second->device.write_data(ptr); return CELL_OK; @@ -572,7 +574,7 @@ s32 sys_usbd_open_pipe(u32 handle, u32 device_handle, u32 unk1, u64 unk2, u64 un return CELL_EINVAL; } - return usbh->open_pipe(device_handle, (u8)endpoint); + return usbh->open_pipe(device_handle, static_cast(endpoint)); } s32 sys_usbd_open_default_pipe(u32 handle, u32 device_handle) @@ -716,7 +718,7 @@ s32 sys_usbd_transfer_data(u32 handle, u32 id_pipe, vm::ptr buf, u32 buf_siz // Claiming interface if (request->bmRequestType == 0 && request->bRequest == 0x09) { - pipe.device->set_configuration((u8)request->wValue); + pipe.device->set_configuration(static_cast(+request->wValue)); pipe.device->set_interface(0); } diff --git a/rpcs3/Emu/Io/MouseHandler.h b/rpcs3/Emu/Io/MouseHandler.h index 38d5d69a7ff7..ecd18166e535 100644 --- a/rpcs3/Emu/Io/MouseHandler.h +++ b/rpcs3/Emu/Io/MouseHandler.h @@ -155,7 +155,7 @@ class MouseHandlerBase { std::lock_guard lock(mutex); - for (u32 p = 0; p < (u32)m_mice.size(); ++p) + for (u32 p = 0; p < m_mice.size(); ++p) { if (m_info.status[p] != CELL_MOUSE_STATUS_CONNECTED) { @@ -186,7 +186,7 @@ class MouseHandlerBase { std::lock_guard lock(mutex); - for (u32 p = 0; p < (u32)m_mice.size(); ++p) + for (u32 p = 0; p < m_mice.size(); ++p) { if (m_info.status[p] != CELL_MOUSE_STATUS_CONNECTED) { @@ -213,7 +213,7 @@ class MouseHandlerBase { std::lock_guard lock(mutex); - for (u32 p = 0; p < (u32)m_mice.size(); ++p) + for (u32 p = 0; p < m_mice.size(); ++p) { if (m_info.status[p] != CELL_MOUSE_STATUS_CONNECTED) { diff --git a/rpcs3/stb_image.cpp b/rpcs3/stb_image.cpp index 806b9f8f42f4..65f64baea24b 100644 --- a/rpcs3/stb_image.cpp +++ b/rpcs3/stb_image.cpp @@ -2,28 +2,21 @@ // Defines STB_IMAGE_IMPLEMENTATION *once* for stb_image.h includes (Should this be placed somewhere else?) #define STB_IMAGE_IMPLEMENTATION +// Sneak in truetype as well. +#define STB_TRUETYPE_IMPLEMENTATION + // This header generates lots of errors, so we ignore those (not rpcs3 code) -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Weverything" +#ifdef _MSC_VER +#pragma warning(push, 0) #include -#pragma clang diagnostic pop - -#elif defined(__GNUC__) || defined(__GNUG__) +#include +#pragma warning(pop) +#else #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wall" #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #include +#include #pragma GCC diagnostic pop - -#elif defined(_MSC_VER) -// TODO Turn off warnings for MSVC. Using the normal push warning levels simply -// creates a new warning about warnings being supressed (ie fuck msvc) -// #pragma warning( push, 4 ) -#include -// #pragma warning( pop ) - -#else -#include #endif