From 246cceeb2742666b7ef3db5ff4d595eee73f5db1 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Wed, 14 Jun 2023 19:51:31 +0200 Subject: [PATCH] Silence more signedness warnings --- audio/common/wasapi.c | 6 +- audio/drivers/sdl_audio.c | 2 +- audio/drivers_microphone/sdl_microphone.c | 97 +- audio/drivers_microphone/wasapi.c | 87 +- cheevos/cheevos_client.c | 7 +- frontend/drivers/platform_win32.c | 8 +- gfx/common/dxgi_common.c | 14 +- gfx/common/win32_common.c | 2 +- gfx/display_servers/dispserv_win32.c | 26 +- gfx/drivers/d3d10.c | 4 +- gfx/drivers/gl1.c | 2 +- gfx/drivers/gl2.c | 2 +- gfx/drivers/gl3.c | 2 +- gfx/drivers/vulkan.c | 2 +- gfx/drivers_context/wgl_ctx.c | 8 +- gfx/drivers_font_renderer/coretext.c | 5 +- gfx/drivers_font_renderer/freetype.c | 6 +- input/drivers_joypad/xinput_hybrid_joypad.c | 2 +- input/input_driver.c | 1105 +++++++++---------- input/input_driver.h | 3 - libretro-common/cdrom/cdrom.c | 73 +- libretro-common/vfs/vfs_implementation.c | 4 +- menu/drivers/ozone.c | 22 +- menu/drivers/rgui.c | 40 +- menu/menu_explore.c | 2 +- ui/drivers/ui_qt.cpp | 12 +- 26 files changed, 756 insertions(+), 787 deletions(-) diff --git a/audio/common/wasapi.c b/audio/common/wasapi.c index 5d2b8cbe7e..b35a2ebe7d 100644 --- a/audio/common/wasapi.c +++ b/audio/common/wasapi.c @@ -238,7 +238,7 @@ static bool wasapi_select_device_format(WAVEFORMATEXTENSIBLE *format, IAudioClie * and Windows was unable to suggest another. * Usually happens with exclusive mode. * RetroArch will try selecting a format. */ - int i, j; + size_t i, j; WAVEFORMATEXTENSIBLE possible_format; HRESULT format_check_hr; RARCH_WARN("[WASAPI]: Requested format not supported, and Windows could not suggest one. RetroArch will do so.\n"); @@ -591,7 +591,7 @@ IMMDevice *wasapi_init_device(const char *id, EDataFlow data_flow) goto error; } - if (i == idx_found) + if (i == (UINT32)idx_found) break; IFACE_RELEASE(device); @@ -743,4 +743,4 @@ IAudioClient *wasapi_init_client(IMMDevice *device, bool *exclusive, device_period * (*rate) / 10000000, (double)device_period / 10000.0); return client; -} \ No newline at end of file +} diff --git a/audio/drivers/sdl_audio.c b/audio/drivers/sdl_audio.c index 241e410a5d..012da59338 100644 --- a/audio/drivers/sdl_audio.c +++ b/audio/drivers/sdl_audio.c @@ -82,7 +82,7 @@ static void sdl_audio_playback_cb(void *data, Uint8 *stream, int len) { sdl_audio_t *sdl = (sdl_audio_t*)data; size_t avail = FIFO_READ_AVAIL(sdl->speaker_buffer); - size_t write_size = len > (int)avail ? avail : len; + size_t write_size = (len > (int)avail) ? avail : (size_t)len; fifo_read(sdl->speaker_buffer, stream, write_size); #ifdef HAVE_THREADS diff --git a/audio/drivers_microphone/sdl_microphone.c b/audio/drivers_microphone/sdl_microphone.c index df163664ff..0875a60960 100644 --- a/audio/drivers_microphone/sdl_microphone.c +++ b/audio/drivers_microphone/sdl_microphone.c @@ -68,27 +68,41 @@ static void *sdl_microphone_init(void) return NULL; } - sdl = (sdl_microphone_t*)calloc(1, sizeof(*sdl)); - if (!sdl) + if (!(sdl = (sdl_microphone_t*)calloc(1, sizeof(*sdl)))) return NULL; return sdl; - -error: - free(sdl); - return NULL; } -static void sdl_microphone_close_mic(void *driver_context, void *microphone_context); +static void sdl_microphone_close_mic(void *driver_context, void *microphone_context) +{ + sdl_microphone_handle_t *microphone = (sdl_microphone_handle_t *)microphone_context; + + if (microphone) + { + /* If the microphone was originally initialized successfully... */ + if (microphone->device_id > 0) + SDL_CloseAudioDevice(microphone->device_id); + + fifo_free(microphone->sample_buffer); + +#ifdef HAVE_THREADS + slock_free(microphone->lock); + scond_free(microphone->cond); +#endif + + RARCH_LOG("[SDL audio]: Freed microphone with former device ID %u\n", microphone->device_id); + free(microphone); + } +} + static void sdl_microphone_free(void *data) { sdl_microphone_t *sdl = (sdl_microphone_t*)data; if (sdl) - { SDL_QuitSubSystem(SDL_INIT_AUDIO); - } free(sdl); /* NOTE: The microphone frontend should've closed the mics by now */ } @@ -107,10 +121,10 @@ static void sdl_audio_record_cb(void *data, Uint8 *stream, int len) } static void *sdl_microphone_open_mic(void *driver_context, - const char *device, - unsigned rate, - unsigned latency, - unsigned *new_rate) + const char *device, + unsigned rate, + unsigned latency, + unsigned *new_rate) { int frames; size_t bufsize; @@ -118,33 +132,32 @@ static void *sdl_microphone_open_mic(void *driver_context, SDL_AudioSpec desired_spec = {0}; void *tmp = NULL; - (void)driver_context; - + /* If the audio driver wasn't initialized yet... */ if (!SDL_WasInit(SDL_INIT_AUDIO)) - { /* If the audio driver wasn't initialized yet... */ + { RARCH_ERR("[SDL mic]: Attempted to initialize input device before initializing the audio subsystem\n"); return NULL; } - microphone = (sdl_microphone_handle_t *)calloc(1, sizeof(sdl_microphone_handle_t)); - if (!microphone) + if (!(microphone = (sdl_microphone_handle_t *) + calloc(1, sizeof(sdl_microphone_handle_t)))) return NULL; + /* Only print SDL audio devices if verbose logging is enabled */ if (verbosity_is_enabled()) - { /* Only print SDL audio devices if verbose logging is enabled */ + { int i; int num_available_microphones = SDL_GetNumAudioDevices(true); RARCH_DBG("[SDL mic]: %d audio capture devices found:\n", num_available_microphones); - for (i = 0; i < num_available_microphones; ++i) { + for (i = 0; i < num_available_microphones; ++i) RARCH_DBG("[SDL mic]: - %s\n", SDL_GetAudioDeviceName(i, true)); - } } /* We have to buffer up some data ourselves, so we let SDL * carry approximately half of the latency. * * SDL double buffers audio and we do as well. */ - frames = find_num_frames(rate, latency / 4); + frames = find_num_frames(rate, latency / 4); desired_spec.freq = rate; desired_spec.format = AUDIO_F32SYS; @@ -218,46 +231,18 @@ error: return NULL; } -static void sdl_microphone_close_mic(void *driver_context, void *microphone_context) -{ - sdl_microphone_handle_t *microphone = (sdl_microphone_handle_t *)microphone_context; - (void)driver_context; - - if (microphone) - { - if (microphone->device_id > 0) - { /* If the microphone was originally initialized successfully... */ - SDL_CloseAudioDevice(microphone->device_id); - } - - fifo_free(microphone->sample_buffer); - -#ifdef HAVE_THREADS - slock_free(microphone->lock); - scond_free(microphone->cond); -#endif - - RARCH_LOG("[SDL audio]: Freed microphone with former device ID %u\n", microphone->device_id); - free(microphone); - } -} - static bool sdl_microphone_mic_alive(const void *data, const void *microphone_context) { const sdl_microphone_handle_t *microphone = (const sdl_microphone_handle_t*)microphone_context; - (void)data; - if (!microphone) return false; /* Both params must be non-null */ - return SDL_GetAudioDeviceStatus(microphone->device_id) == SDL_AUDIO_PLAYING; } static bool sdl_microphone_start_mic(void *driver_context, void *microphone_context) { sdl_microphone_handle_t *microphone = (sdl_microphone_handle_t*)microphone_context; - (void)driver_context; if (!microphone) return false; @@ -286,18 +271,20 @@ static bool sdl_microphone_stop_mic(void *driver_context, void *microphone_conte switch (SDL_GetAudioDeviceStatus(microphone->device_id)) { - case SDL_AUDIO_PAUSED: - return true; case SDL_AUDIO_PLAYING: RARCH_ERR("[SDL mic]: Microphone %u failed to pause\n", microphone->device_id); return false; case SDL_AUDIO_STOPPED: RARCH_WARN("[SDL mic]: Microphone %u is in state STOPPED; it may not start again\n", microphone->device_id); - return true; + /* fall-through */ + case SDL_AUDIO_PAUSED: + break; default: RARCH_ERR("[SDL mic]: Microphone %u is in unknown state\n", microphone->device_id); return false; } + + return true; } static void sdl_microphone_set_nonblock_state(void *driver_context, bool state) @@ -378,8 +365,6 @@ static int sdl_microphone_read(void *driver_context, void *microphone_context, v static bool sdl_microphone_mic_use_float(const void *driver_context, const void *microphone_context) { sdl_microphone_handle_t *microphone = (sdl_microphone_handle_t*)microphone_context; - (void)driver_context; - return SDL_AUDIO_ISFLOAT(microphone->device_spec.format); } @@ -397,4 +382,4 @@ microphone_driver_t microphone_sdl = { sdl_microphone_start_mic, sdl_microphone_stop_mic, sdl_microphone_mic_use_float, -}; \ No newline at end of file +}; diff --git a/audio/drivers_microphone/wasapi.c b/audio/drivers_microphone/wasapi.c index 6ab9847b8f..a460244ad3 100644 --- a/audio/drivers_microphone/wasapi.c +++ b/audio/drivers_microphone/wasapi.c @@ -102,13 +102,12 @@ static int wasapi_microphone_fetch_fifo(wasapi_microphone_handle_t *microphone) do { - BYTE *mic_input = NULL; - UINT32 frames_read = 0; - UINT32 bytes_read = 0; + BYTE *mic_input = NULL; + UINT32 frames_read = 0; + UINT32 bytes_read = 0; DWORD buffer_status_flags = 0; - HRESULT hr; - - hr = _IAudioCaptureClient_GetBuffer(microphone->capture, &mic_input, &frames_read, &buffer_status_flags, NULL, NULL); + HRESULT hr = _IAudioCaptureClient_GetBuffer(microphone->capture, + &mic_input, &frames_read, &buffer_status_flags, NULL, NULL); if (FAILED(hr)) { RARCH_ERR("[WASAPI]: Failed to get capture device \"%s\"'s buffer: %s\n", @@ -118,15 +117,14 @@ static int wasapi_microphone_fetch_fifo(wasapi_microphone_handle_t *microphone) } bytes_read = frames_read * microphone->frame_size; + /* If the queue has room for the packets we just got... */ if (FIFO_WRITE_AVAIL(microphone->buffer) >= bytes_read && bytes_read > 0) - { /* If the queue has room for the packets we just got... */ + { fifo_write(microphone->buffer, mic_input, bytes_read); /* ...then enqueue the bytes directly from the mic's buffer */ } - else - { /* Not enough space for new frames, so we can't consume this packet right now */ + else /* Not enough space for new frames, so we can't consume this packet right now */ frames_read = 0; - } /* If there's insufficient room in the queue, then we can't read the packet. * In that case, we leave the packet for next time. */ @@ -140,20 +138,21 @@ static int wasapi_microphone_fetch_fifo(wasapi_microphone_handle_t *microphone) return -1; } + /* If this is a shared-mode stream and we didn't run out of room in the sample queue... */ if (!microphone->exclusive && frames_read > 0) - { /* If this is a shared-mode stream and we didn't run out of room in the sample queue... */ + { hr = _IAudioCaptureClient_GetNextPacketSize(microphone->capture, &next_packet_size); + /* Get the number of frames that the mic has for us. */ if (FAILED(hr)) - { /* Get the number of frames that the mic has for us. */ + { RARCH_ERR("[WASAPI]: Failed to get capture device \"%s\"'s next packet size: %s\n", microphone->device_name, hresult_name(hr)); return -1; } } + /* Exclusive-mode streams only deliver one packet at a time, though it's bigger. */ else - { /* Exclusive-mode streams only deliver one packet at a time, though it's bigger. */ next_packet_size = 0; - } } while (next_packet_size != 0); @@ -170,19 +169,21 @@ static int wasapi_microphone_fetch_fifo(wasapi_microphone_handle_t *microphone) */ static bool wasapi_microphone_wait_for_capture_event(wasapi_microphone_handle_t *microphone, DWORD timeout) { + /*...then let's wait for the mic to tell us that samples are ready. */ switch (WaitForSingleObject(microphone->read_event, timeout)) - { /*...then let's wait for the mic to tell us that samples are ready. */ + { case WAIT_OBJECT_0: /* Okay, there's data available. */ return true; case WAIT_TIMEOUT: /* Time out; there's nothing here for us. */ RARCH_ERR("[WASAPI]: Failed to wait for capture device \"%s\" event: Timeout after %ums\n", microphone->device_name, timeout); - return false; + break; default: RARCH_ERR("[WASAPI]: Failed to wait for capture device \"%s\" event: %s\n", microphone->device_name, wasapi_error(GetLastError())); - return false; + break; } + return false; } /** @@ -209,18 +210,17 @@ static int wasapi_microphone_read_buffered( int bytes_read = 0; /* Number of bytes sent to the core */ int bytes_available = FIFO_READ_AVAIL(microphone->buffer); + /* If we don't have any queued samples to give to the core... */ if (!bytes_available) - { /* If we don't have any queued samples to give to the core... */ + { + /* If we couldn't wait for the microphone to signal a capture event... */ if (!wasapi_microphone_wait_for_capture_event(microphone, timeout)) - { /* If we couldn't wait for the microphone to signal a capture event... */ return -1; - } bytes_available = wasapi_microphone_fetch_fifo(microphone); + /* If we couldn't fetch samples from the microphone... */ if (bytes_available < 0) - { /* If we couldn't fetch samples from the microphone... */ return -1; - } } /* Now that we have samples available, let's give them to the core */ @@ -241,18 +241,19 @@ static int wasapi_microphone_read(void *driver_context, void *mic_context, void if (!wasapi || !microphone || !buffer) return -1; + /* If microphones shouldn't block... */ if (wasapi->nonblock) - { /* If microphones shouldn't block... */ return wasapi_microphone_read_buffered(microphone, buffer, buffer_size, 0); - } if (microphone->exclusive) { int read; - for (read = -1; bytes_read < buffer_size; bytes_read += read) + for (read = -1; (size_t)bytes_read < buffer_size; bytes_read += read) { - read = wasapi_microphone_read_buffered(microphone, (char *) buffer + bytes_read, buffer_size - bytes_read, - INFINITE); + read = wasapi_microphone_read_buffered(microphone, + (char *)buffer + bytes_read, + buffer_size - bytes_read, + INFINITE); if (read == -1) return -1; } @@ -260,11 +261,12 @@ static int wasapi_microphone_read(void *driver_context, void *mic_context, void else { int read; - - for (read = -1; bytes_read < buffer_size; bytes_read += read) + for (read = -1; (size_t)bytes_read < buffer_size; bytes_read += read) { - read = wasapi_microphone_read_buffered(microphone, (char *) buffer + bytes_read, buffer_size - bytes_read, - INFINITE); + read = wasapi_microphone_read_buffered(microphone, + (char *)buffer + bytes_read, + buffer_size - bytes_read, + INFINITE); if (read == -1) return -1; } @@ -283,10 +285,10 @@ static void wasapi_microphone_set_nonblock_state(void *driver_context, bool nonb } static void *wasapi_microphone_open_mic(void *driver_context, const char *device, unsigned rate, - unsigned latency, unsigned *new_rate) + unsigned latency, unsigned *new_rate) { - settings_t *settings = config_get_ptr(); HRESULT hr; + settings_t *settings = config_get_ptr(); DWORD flags = 0; UINT32 frame_count = 0; REFERENCE_TIME dev_period = 0; @@ -295,15 +297,16 @@ static void *wasapi_microphone_open_mic(void *driver_context, const char *device bool exclusive_mode = settings->bools.microphone_wasapi_exclusive_mode; unsigned sh_buffer_length = settings->uints.microphone_wasapi_sh_buffer_length; wasapi_microphone_handle_t *microphone = calloc(1, sizeof(wasapi_microphone_handle_t)); - (void)driver_context; if (!microphone) return NULL; - microphone->exclusive = exclusive_mode; - microphone->device = wasapi_init_device(device, eCapture); + microphone->exclusive = exclusive_mode; + microphone->device = wasapi_init_device(device, eCapture); + + /* If we requested a particular capture device, but couldn't open it... */ if (device && !microphone->device) - { /* If we requested a particular capture device, but couldn't open it... */ + { RARCH_WARN("[WASAPI]: Failed to open requested capture device \"%s\", attempting to open default device\n", device); microphone->device = wasapi_init_device(NULL, eCapture); } @@ -340,8 +343,9 @@ static void *wasapi_microphone_open_mic(void *driver_context, const char *device microphone->frame_size = float_format ? sizeof(float) : sizeof(int16_t); microphone->engine_buffer_size = frame_count * microphone->frame_size; + /* If this mic should be used *exclusively* by RetroArch... */ if (microphone->exclusive) - { /* If this mic should be used *exclusively* by RetroArch... */ + { microphone->buffer = fifo_new(microphone->engine_buffer_size); if (!microphone->buffer) { @@ -354,8 +358,9 @@ static void *wasapi_microphone_open_mic(void *driver_context, const char *device } else { + /* If the user selected the "default" shared buffer length... */ if (sh_buffer_length <= 0) - { /* If the user selected the "default" shared buffer length... */ + { hr = _IAudioClient_GetDevicePeriod(microphone->client, &dev_period, NULL); if (FAILED(hr)) goto error; @@ -388,7 +393,7 @@ static void *wasapi_microphone_open_mic(void *driver_context, const char *device } hr = _IAudioClient_GetService(microphone->client, - IID_IAudioCaptureClient, (void**)µphone->capture); + IID_IAudioCaptureClient, (void**)µphone->capture); if (FAILED(hr)) { RARCH_ERR("[WASAPI]: Failed to get capture device's IAudioCaptureClient service: %s\n", hresult_name(hr)); @@ -562,4 +567,4 @@ microphone_driver_t microphone_wasapi = { wasapi_microphone_start_mic, wasapi_microphone_stop_mic, wasapi_microphone_use_float -}; \ No newline at end of file +}; diff --git a/cheevos/cheevos_client.c b/cheevos/cheevos_client.c index 30c802753b..24844b97bf 100644 --- a/cheevos/cheevos_client.c +++ b/cheevos/cheevos_client.c @@ -856,15 +856,16 @@ static void rcheevos_client_copy_achievements( * we don't need to keep the definition around * as it won't be reactivated. Otherwise, * we do have to keep a copy of it. */ - if ((achievement->active & (RCHEEVOS_ACTIVE_HARDCORE + if ((achievement->active & ( + RCHEEVOS_ACTIVE_HARDCORE | RCHEEVOS_ACTIVE_SOFTCORE)) != 0) achievement->memaddr = strdup(definition->definition); ++achievement; } - rcheevos_locals->game.achievement_count = achievement - - rcheevos_locals->game.achievements; + rcheevos_locals->game.achievement_count = (unsigned)(achievement + - rcheevos_locals->game.achievements); } static void rcheevos_client_copy_leaderboards( diff --git a/frontend/drivers/platform_win32.c b/frontend/drivers/platform_win32.c index 187bd7bc82..f9ee1d062a 100644 --- a/frontend/drivers/platform_win32.c +++ b/frontend/drivers/platform_win32.c @@ -141,9 +141,9 @@ const struct win32_lang_pair win32_lang_pairs[] = unsigned short win32_get_langid_from_retro_lang(enum retro_language lang) { - int i; + size_t i; - for (i = 0; i < sizeof(win32_lang_pairs) / sizeof(win32_lang_pairs[0]); i++) + for (i = 0; i < ARRAY_SIZE(win32_lang_pairs); i++) { if (win32_lang_pairs[i].lang == lang) return win32_lang_pairs[i].lang_ident; @@ -154,9 +154,9 @@ unsigned short win32_get_langid_from_retro_lang(enum retro_language lang) enum retro_language win32_get_retro_lang_from_langid(unsigned short langid) { - int i; + size_t i; - for (i = 0; i < sizeof(win32_lang_pairs) / sizeof(win32_lang_pairs[0]); i++) + for (i = 0; i < ARRAY_SIZE(win32_lang_pairs); i++) { if (win32_lang_pairs[i].lang_ident > 0x3ff) { diff --git a/gfx/common/dxgi_common.c b/gfx/common/dxgi_common.c index 3cc77394dd..82434851d0 100644 --- a/gfx/common/dxgi_common.c +++ b/gfx/common/dxgi_common.c @@ -161,19 +161,19 @@ DXGI_FORMAT* dxgi_get_format_fallback_list(DXGI_FORMAT format) dst_gb, dst_bb, dst_ab, dst_rs, dst_gs, dst_bs, dst_as) \ do \ { \ - if ((sizeof(src_type) == sizeof(dst_type)) && \ - ((src_rs == dst_rs && src_rb == dst_rb) || !dst_rb) && \ - ((src_gs == dst_gs && src_gb == dst_gb) || !dst_gb) && \ - ((src_bs == dst_bs && src_bb == dst_bb) || !dst_bb) && \ - ((src_as == dst_as && src_ab == dst_ab) || !dst_ab)) \ + if ( (sizeof(src_type) == sizeof(dst_type)) \ + && ((src_rs == dst_rs && src_rb == dst_rb) || !dst_rb) \ + && ((src_gs == dst_gs && src_gb == dst_gb) || !dst_gb) \ + && ((src_bs == dst_bs && src_bb == dst_bb) || !dst_bb) \ + && ((src_as == dst_as && src_ab == dst_ab) || !dst_ab)) \ { \ const UINT8* in = (const UINT8*)src_data; \ UINT8* out = (UINT8*)dst_data; \ for (i = 0; i < height; i++) \ { \ memcpy(out, in, width * sizeof(src_type)); \ - in += src_pitch ? src_pitch : width * sizeof(src_type); \ - out += dst_pitch ? dst_pitch : width * sizeof(dst_type); \ + in += src_pitch ? (int)src_pitch : (int)(width * sizeof(src_type)); \ + out += dst_pitch ? (int)dst_pitch : (int)(width * sizeof(dst_type)); \ } \ } \ else \ diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index c4bbfc14a8..b7fe88bdcf 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -2010,7 +2010,7 @@ static const char *meta_key_to_name(unsigned int meta_key) const struct input_key_map* entry = &input_config_key_map[i]; if (!entry->str) break; - if (entry->key == key_code) + if (entry->key == (enum retro_key)key_code) return entry->str; i++; } diff --git a/gfx/display_servers/dispserv_win32.c b/gfx/display_servers/dispserv_win32.c index 16aead87e2..83e4855e5f 100644 --- a/gfx/display_servers/dispserv_win32.c +++ b/gfx/display_servers/dispserv_win32.c @@ -273,7 +273,7 @@ static bool win32_display_server_set_resolution(void *data, continue; if (dm.dmBitsPerPel != curr_bpp) continue; - if (dm.dmDisplayFrequency != int_hz) + if (dm.dmDisplayFrequency != (DWORD)int_hz) continue; #if _WIN32_WINNT >= 0x0500 if (dm.dmDisplayOrientation != curr_orientation) @@ -459,10 +459,10 @@ void win32_display_server_set_screen_orientation(void *data, if (( dm.dmDisplayOrientation == DMDO_90 || dm.dmDisplayOrientation == DMDO_270) - && width != dm.dmPelsHeight) + && (width != (int)dm.dmPelsHeight)) { - /* device is changing orientations, swap the aspect */ - dm.dmPelsWidth = dm.dmPelsHeight; + /* Device is changing orientations, swap the aspect */ + dm.dmPelsWidth = dm.dmPelsHeight; dm.dmPelsHeight = width; } @@ -475,10 +475,10 @@ void win32_display_server_set_screen_orientation(void *data, if (( dm.dmDisplayOrientation == DMDO_DEFAULT || dm.dmDisplayOrientation == DMDO_180) - && width != dm.dmPelsHeight) + && (width != (int)dm.dmPelsHeight)) { - /* device is changing orientations, swap the aspect */ - dm.dmPelsWidth = dm.dmPelsHeight; + /* Device is changing orientations, swap the aspect */ + dm.dmPelsWidth = dm.dmPelsHeight; dm.dmPelsHeight = width; } @@ -491,10 +491,10 @@ void win32_display_server_set_screen_orientation(void *data, if (( dm.dmDisplayOrientation == DMDO_90 || dm.dmDisplayOrientation == DMDO_270) - && width != dm.dmPelsHeight) + && (width != (int)dm.dmPelsHeight)) { - /* device is changing orientations, swap the aspect */ - dm.dmPelsWidth = dm.dmPelsHeight; + /* Device is changing orientations, swap the aspect */ + dm.dmPelsWidth = dm.dmPelsHeight; dm.dmPelsHeight = width; } @@ -507,10 +507,10 @@ void win32_display_server_set_screen_orientation(void *data, if (( dm.dmDisplayOrientation == DMDO_DEFAULT || dm.dmDisplayOrientation == DMDO_180) - && width != dm.dmPelsHeight) + && (width != (int)dm.dmPelsHeight)) { - /* device is changing orientations, swap the aspect */ - dm.dmPelsWidth = dm.dmPelsHeight; + /* Device is changing orientations, swap the aspect */ + dm.dmPelsWidth = dm.dmPelsHeight; dm.dmPelsHeight = width; } diff --git a/gfx/drivers/d3d10.c b/gfx/drivers/d3d10.c index 9710210039..a85afee684 100644 --- a/gfx/drivers/d3d10.c +++ b/gfx/drivers/d3d10.c @@ -644,7 +644,7 @@ static void d3d10_font_free(void* data, bool is_threaded) static int d3d10_font_get_message_width(void* data, const char* msg, size_t msg_len, float scale) { - int i; + size_t i; int delta_x = 0; const struct font_glyph* glyph_q = NULL; d3d10_font_t* font = (d3d10_font_t*)data; @@ -806,7 +806,7 @@ static void d3d10_font_render_message( for (;;) { const char* delim = strchr(msg, '\n'); - size_t msg_len = delim ? (delim - msg) : strlen(msg); + size_t msg_len = delim ? (size_t)((delim - msg)) : strlen(msg); /* Draw the line */ if (msg_len <= (unsigned)d3d10->sprites.capacity) diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index 3c977066ac..a55617420e 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -630,7 +630,7 @@ static void gl1_raster_font_render_message(gl1_t *gl, for (;;) { const char *delim = strchr(msg, '\n'); - size_t msg_len = delim ? (delim - msg) : strlen(msg); + size_t msg_len = delim ? (size_t)(delim - msg) : strlen(msg); /* Draw the line */ gl1_raster_font_render_line(gl, font, glyph_q, diff --git a/gfx/drivers/gl2.c b/gfx/drivers/gl2.c index f4cfa280b6..09fe824457 100644 --- a/gfx/drivers/gl2.c +++ b/gfx/drivers/gl2.c @@ -930,7 +930,7 @@ static void gl2_raster_font_render_message(gl2_t *gl, for (;;) { const char *delim = strchr(msg, '\n'); - size_t msg_len = delim ? (delim - msg) : strlen(msg); + size_t msg_len = delim ? (size_t)(delim - msg) : strlen(msg); /* Draw the line */ gl2_raster_font_render_line(gl, font, diff --git a/gfx/drivers/gl3.c b/gfx/drivers/gl3.c index 006d86b890..bf2b6ca748 100644 --- a/gfx/drivers/gl3.c +++ b/gfx/drivers/gl3.c @@ -673,7 +673,7 @@ static void gl3_raster_font_render_message( for (;;) { const char *delim = strchr(msg, '\n'); - size_t msg_len = delim ? (delim - msg) : strlen(msg); + size_t msg_len = delim ? (size_t)(delim - msg) : strlen(msg); /* Draw the line */ gl3_raster_font_render_line(gl, font, diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index a3dd566393..e4fda61ed8 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -1509,7 +1509,7 @@ static void vulkan_font_render_message(vk_t *vk, for (;;) { const char *delim = strchr(msg, '\n'); - size_t msg_len = delim ? (delim - msg) : strlen(msg); + size_t msg_len = delim ? (size_t)(delim - msg) : strlen(msg); /* Draw the line */ vulkan_font_render_line(vk, font, glyph_q, msg, msg_len, diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index 4332821904..aa7ca4cbf4 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -18,9 +18,9 @@ /* Win32/WGL context. */ -/* necessary for mingw32 multimon defines: */ +/* Necessary for mingw32 multimon defines: */ #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0500 //_WIN32_WINNT_WIN2K +#define _WIN32_WINNT 0x0500 /* _WIN32_WINNT_WIN2K */ #endif #include @@ -323,8 +323,8 @@ void create_gl_context(HWND hwnd, bool *quit) break; } else if ( - versions[i][0] == win32_major && - versions[i][1] == win32_minor) + (versions[i][0] == (int)win32_major) + && (versions[i][1] == (int)win32_minor)) { /* The requested version was tried and * is not supported, go ahead and fail diff --git a/gfx/drivers_font_renderer/coretext.c b/gfx/drivers_font_renderer/coretext.c index 95c98693b3..813771f0e4 100644 --- a/gfx/drivers_font_renderer/coretext.c +++ b/gfx/drivers_font_renderer/coretext.c @@ -353,14 +353,11 @@ static const char *font_renderer_ct_get_default_font(void) return default_font; } -static bool font_renderer_ct_get_line_metrics( +static void font_renderer_ct_get_line_metrics( void* data, struct font_line_metrics **metrics) { ct_font_renderer_t *handle = (ct_font_renderer_t*)data; - if (!handle) - return false; *metrics = &handle->line_metrics; - return true; } font_renderer_driver_t coretext_font_renderer = { diff --git a/gfx/drivers_font_renderer/freetype.c b/gfx/drivers_font_renderer/freetype.c index fa545c876c..23019862d4 100644 --- a/gfx/drivers_font_renderer/freetype.c +++ b/gfx/drivers_font_renderer/freetype.c @@ -438,15 +438,11 @@ static const char *font_renderer_ft_get_default_font(void) #endif } -static bool font_renderer_ft_get_line_metrics( +static void font_renderer_ft_get_line_metrics( void* data, struct font_line_metrics **metrics) { ft_font_renderer_t *handle = (ft_font_renderer_t*)data; - if (!handle) - return false; - *metrics = &handle->line_metrics; - return true; } font_renderer_driver_t freetype_font_renderer = { diff --git a/input/drivers_joypad/xinput_hybrid_joypad.c b/input/drivers_joypad/xinput_hybrid_joypad.c index eb558b8aa3..cb57417f6a 100644 --- a/input/drivers_joypad/xinput_hybrid_joypad.c +++ b/input/drivers_joypad/xinput_hybrid_joypad.c @@ -217,7 +217,7 @@ static bool dinput_joypad_get_vidpid_from_xinput_index( int32_t index, int32_t *vid, int32_t *pid, int32_t *dinput_index) { - int i; + size_t i; for (i = 0; i < ARRAY_SIZE(g_xinput_pad_indexes); i++) { diff --git a/input/input_driver.c b/input/input_driver.c index 5706cc9784..8a5a3d798a 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -1186,6 +1186,550 @@ input_remote_t *input_driver_init_remote( } #endif +static int16_t input_state_device( + input_driver_state_t *input_st, + settings_t *settings, + input_mapper_t *handle, + unsigned input_analog_dpad_mode, + int16_t ret, + unsigned port, unsigned device, + unsigned idx, unsigned id, + bool button_mask) +{ + int16_t res = 0; + + switch (device) + { + case RETRO_DEVICE_JOYPAD: + + if (id < RARCH_FIRST_META_KEY) + { +#ifdef HAVE_NETWORKGAMEPAD + /* Don't process binds if input is coming from Remote RetroPad */ + if ( input_st->remote + && INPUT_REMOTE_KEY_PRESSED(input_st, id, port)) + res |= 1; + else +#endif + { + bool bind_valid = input_st->libretro_input_binds[port] + && (*input_st->libretro_input_binds[port])[id].valid; + unsigned remap_button = settings->uints.input_remap_ids[port][id]; + + /* TODO/FIXME: What on earth is this code doing...? */ + if (!(bind_valid && (id != remap_button))) + { + if (button_mask) + { + if (ret & (1 << id)) + res |= (1 << id); + } + else + res = ret; + } + + if (BIT256_GET(handle->buttons[port], id)) + res = 1; + +#ifdef HAVE_OVERLAY + /* Check if overlay is active and button + * corresponding to 'id' has been pressed */ + if ( (port == 0) + && input_st->overlay_ptr + && (input_st->overlay_ptr->flags & INPUT_OVERLAY_ALIVE) + && BIT256_GET(input_st->overlay_ptr->overlay_state.buttons, id)) + { +#ifdef HAVE_MENU + bool menu_driver_alive = menu_state_get_ptr()->flags & + MENU_ST_FLAG_ALIVE; +#else + bool menu_driver_alive = false; +#endif + bool input_remap_binds_enable = settings->bools.input_remap_binds_enable; + + /* This button has already been processed + * inside input_driver_poll() if all the + * following are true: + * > Menu driver is not running + * > Input remaps are enabled + * > 'id' is not equal to remapped button index + * If these conditions are met, input here + * is ignored */ + if ((menu_driver_alive || !input_remap_binds_enable) || + (id == remap_button)) + res |= 1; + } +#endif + } + + /* Don't allow turbo for D-pad. */ + if ( (id < RETRO_DEVICE_ID_JOYPAD_UP) || + ( (id > RETRO_DEVICE_ID_JOYPAD_RIGHT) && + (id <= RETRO_DEVICE_ID_JOYPAD_R3))) + { + /* + * Apply turbo button if activated. + */ + unsigned turbo_mode = settings->uints.input_turbo_mode; + + if (turbo_mode > INPUT_TURBO_MODE_CLASSIC) + { + /* Pressing turbo button toggles turbo mode on or off. + * Holding the button will + * pass through, else the pressed state will be modulated by a + * periodic pulse defined by the configured duty cycle. + */ + + /* Avoid detecting the turbo button being held as multiple toggles */ + if (!input_st->turbo_btns.frame_enable[port]) + input_st->turbo_btns.turbo_pressed[port] &= ~(1 << 31); + else if (input_st->turbo_btns.turbo_pressed[port] >= 0) + { + input_st->turbo_btns.turbo_pressed[port] |= (1 << 31); + /* Toggle turbo for selected buttons. */ + if (input_st->turbo_btns.enable[port] + != (1 << settings->uints.input_turbo_default_button)) + { + static const int button_map[]={ + RETRO_DEVICE_ID_JOYPAD_B, + RETRO_DEVICE_ID_JOYPAD_Y, + RETRO_DEVICE_ID_JOYPAD_A, + RETRO_DEVICE_ID_JOYPAD_X, + RETRO_DEVICE_ID_JOYPAD_L, + RETRO_DEVICE_ID_JOYPAD_R, + RETRO_DEVICE_ID_JOYPAD_L2, + RETRO_DEVICE_ID_JOYPAD_R2, + RETRO_DEVICE_ID_JOYPAD_L3, + RETRO_DEVICE_ID_JOYPAD_R3}; + input_st->turbo_btns.enable[port] = 1 << button_map[ + MIN( + ARRAY_SIZE(button_map) - 1, + settings->uints.input_turbo_default_button)]; + } + input_st->turbo_btns.mode1_enable[port] ^= 1; + } + + if (input_st->turbo_btns.turbo_pressed[port] & (1 << 31)) + { + /* Avoid detecting buttons being held as multiple toggles */ + if (!res) + input_st->turbo_btns.turbo_pressed[port] &= ~(1 << id); + else if (!(input_st->turbo_btns.turbo_pressed[port] & (1 << id)) && + turbo_mode == INPUT_TURBO_MODE_SINGLEBUTTON) + { + uint16_t enable_new; + input_st->turbo_btns.turbo_pressed[port] |= 1 << id; + /* Toggle turbo for pressed button but make + * sure at least one button has turbo */ + enable_new = input_st->turbo_btns.enable[port] ^ (1 << id); + if (enable_new) + input_st->turbo_btns.enable[port] = enable_new; + } + } + /* Hold mode stops turbo on release */ + else if ( + turbo_mode == INPUT_TURBO_MODE_SINGLEBUTTON_HOLD + && input_st->turbo_btns.enable[port] + && input_st->turbo_btns.mode1_enable[port]) + input_st->turbo_btns.mode1_enable[port] = 0; + + if (!res && input_st->turbo_btns.mode1_enable[port] && + input_st->turbo_btns.enable[port] & (1 << id)) + { + /* If turbo button is enabled for this key ID */ + res = (( input_st->turbo_btns.count + % settings->uints.input_turbo_period) + < settings->uints.input_turbo_duty_cycle); + } + } + else + { + /* If turbo button is held, all buttons pressed except + * for D-pad will go into a turbo mode. Until the button is + * released again, the input state will be modulated by a + * periodic pulse defined by the configured duty cycle. + */ + if (res) + { + if (input_st->turbo_btns.frame_enable[port]) + input_st->turbo_btns.enable[port] |= (1 << id); + + if (input_st->turbo_btns.enable[port] & (1 << id)) + /* if turbo button is enabled for this key ID */ + res = ((input_st->turbo_btns.count + % settings->uints.input_turbo_period) + < settings->uints.input_turbo_duty_cycle); + } + else + input_st->turbo_btns.enable[port] &= ~(1 << id); + } + } + } + + break; + + + case RETRO_DEVICE_KEYBOARD: + + res = ret; + + if (id < RETROK_LAST) + { +#ifdef HAVE_OVERLAY + if (port == 0) + { + if (input_st->overlay_ptr + && (input_st->overlay_ptr->flags & INPUT_OVERLAY_ALIVE)) + { + input_overlay_state_t + *ol_state = &input_st->overlay_ptr->overlay_state; + + if (OVERLAY_GET_KEY(ol_state, id)) + res |= 1; + } + } +#endif + if (MAPPER_GET_KEY(handle, id)) + res |= 1; + } + + break; + + + case RETRO_DEVICE_ANALOG: + { +#if defined(HAVE_NETWORKGAMEPAD) || defined(HAVE_OVERLAY) +#ifdef HAVE_NETWORKGAMEPAD + input_remote_state_t + *input_state = &input_st->remote_st_ptr; + +#endif + unsigned base = (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT) + ? 2 : 0; + if (id == RETRO_DEVICE_ID_ANALOG_Y) + base += 1; +#ifdef HAVE_NETWORKGAMEPAD + if ( input_st->remote + && input_state && input_state->analog[base][port]) + res = input_state->analog[base][port]; + else +#endif +#endif + { + if (id < RARCH_FIRST_META_KEY) + { + bool bind_valid = input_st->libretro_input_binds[port] + && (*input_st->libretro_input_binds[port])[id].valid; + + if (bind_valid) + { + /* reset_state - used to reset input state of a button + * when the gamepad mapper is in action for that button*/ + bool reset_state = false; + if (idx < 2 && id < 2) + { + unsigned offset = RARCH_FIRST_CUSTOM_BIND + + (idx * 4) + (id * 2); + + if (settings->uints.input_remap_ids[port][offset] != offset) + reset_state = true; + else if (settings->uints.input_remap_ids[port][offset+1] != (offset+1)) + reset_state = true; + } + + if (reset_state) + res = 0; + else + { + res = ret; + +#ifdef HAVE_OVERLAY + if (input_st->overlay_ptr && + (input_st->overlay_ptr->flags & INPUT_OVERLAY_ALIVE) && + (port == 0) && + (idx != RETRO_DEVICE_INDEX_ANALOG_BUTTON) && + !(((input_analog_dpad_mode == ANALOG_DPAD_LSTICK) && + (idx == RETRO_DEVICE_INDEX_ANALOG_LEFT)) || + ((input_analog_dpad_mode == ANALOG_DPAD_RSTICK) && + (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)))) + { + input_overlay_state_t *ol_state = + &input_st->overlay_ptr->overlay_state; + int16_t ol_analog = + ol_state->analog[base]; + + /* Analog values are an integer corresponding + * to the extent of the analog motion; these + * cannot be OR'd together, we must instead + * keep the value with the largest magnitude */ + if (ol_analog) + { + if (res == 0) + res = ol_analog; + else + { + int16_t ol_analog_abs = (ol_analog >= 0) ? + ol_analog : -ol_analog; + int16_t res_abs = (res >= 0) ? + res : -res; + + res = (ol_analog_abs > res_abs) ? + ol_analog : res; + } + } + } +#endif + } + } + } + } + + if (idx < 2 && id < 2) + { + unsigned offset = 0 + (idx * 4) + (id * 2); + int val1 = handle->analog_value[port][offset]; + int val2 = handle->analog_value[port][offset+1]; + + /* OR'ing these analog values is 100% incorrect, + * but I have no idea what this code is supposed + * to be doing (val1 and val2 always seem to be + * zero), so I will leave it alone... */ + if (val1) + res |= val1; + else if (val2) + res |= val2; + } + } + break; + + case RETRO_DEVICE_MOUSE: + case RETRO_DEVICE_LIGHTGUN: + case RETRO_DEVICE_POINTER: + + if (input_st->flags & INP_FLAG_BLOCK_POINTER_INPUT) + break; + + if (id < RARCH_FIRST_META_KEY) + { + bool bind_valid = input_st->libretro_input_binds[port] + && (*input_st->libretro_input_binds[port])[id].valid; + + if (bind_valid) + { + if (button_mask) + { + if (ret & (1 << id)) + res |= (1 << id); + } + else + res = ret; + } + } + + break; + } + + return res; +} + + +static int16_t input_state_internal(unsigned port, unsigned device, + unsigned idx, unsigned id) +{ + rarch_joypad_info_t joypad_info; + unsigned mapped_port; + input_driver_state_t *input_st = &input_driver_st; + settings_t *settings = config_get_ptr(); + float input_analog_deadzone = settings->floats.input_analog_deadzone; + float input_analog_sensitivity = settings->floats.input_analog_sensitivity; + unsigned *input_remap_port_map = settings->uints.input_remap_port_map[port]; + bool input_driver_analog_requested = input_st->analog_requested[port]; + const input_device_driver_t *joypad = input_st->primary_joypad; +#ifdef HAVE_MFI + const input_device_driver_t *sec_joypad = input_st->secondary_joypad; +#else + const input_device_driver_t *sec_joypad = NULL; +#endif +#ifdef HAVE_MENU + struct menu_state *menu_st = menu_state_get_ptr(); + bool input_blocked = (menu_st->input_driver_flushing_input > 0) || + (input_st->flags & INP_FLAG_BLOCK_LIBRETRO_INPUT); +#else + bool input_blocked = (input_st->flags & INP_FLAG_BLOCK_LIBRETRO_INPUT); +#endif + bool bitmask_enabled = false; + unsigned max_users = settings->uints.input_max_users; + int16_t result = 0; + + device &= RETRO_DEVICE_MASK; + bitmask_enabled = (device == RETRO_DEVICE_JOYPAD) && + (id == RETRO_DEVICE_ID_JOYPAD_MASK); + joypad_info.axis_threshold = settings->floats.input_axis_threshold; + + /* Loop over all 'physical' ports mapped to specified + * 'virtual' port index */ + while ((mapped_port = *(input_remap_port_map++)) < MAX_USERS) + { + int16_t ret = 0; + int16_t port_result = 0; + unsigned input_analog_dpad_mode = settings->uints.input_analog_dpad_mode[mapped_port]; + + joypad_info.joy_idx = settings->uints.input_joypad_index[mapped_port]; + joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx]; + + /* Skip disabled input devices */ + if (mapped_port >= max_users) + continue; + + /* If core has requested analog input, disable + * analog to dpad mapping (unless forced) */ + switch (input_analog_dpad_mode) + { + case ANALOG_DPAD_LSTICK: + case ANALOG_DPAD_RSTICK: + if (input_driver_analog_requested) + input_analog_dpad_mode = ANALOG_DPAD_NONE; + break; + case ANALOG_DPAD_LSTICK_FORCED: + input_analog_dpad_mode = ANALOG_DPAD_LSTICK; + break; + case ANALOG_DPAD_RSTICK_FORCED: + input_analog_dpad_mode = ANALOG_DPAD_RSTICK; + break; + default: + break; + } + + /* TODO/FIXME: This code is gibberish - a mess of nested + * refactors that make no sense whatsoever. The entire + * thing needs to be rewritten from scratch... */ + + ret = input_state_wrap( + input_st->current_driver, + input_st->current_data, + joypad, + sec_joypad, + &joypad_info, + (*input_st->libretro_input_binds), + input_st->flags & INP_FLAG_KB_MAPPING_BLOCKED, + mapped_port, device, idx, id); + + if ((device == RETRO_DEVICE_ANALOG) && + (ret == 0)) + { + if (input_st->libretro_input_binds[mapped_port]) + { + if (idx == RETRO_DEVICE_INDEX_ANALOG_BUTTON) + { + if (id < RARCH_FIRST_CUSTOM_BIND) + { + /* TODO/FIXME: Analog buttons can only be read as analog + * when the default mapping is applied. If the user + * remaps any analog buttons, they will become 'digital' + * due to the way that mapping is handled elsewhere. We + * cannot fix this without rewriting the entire mess that + * is the input remapping system... */ + bool valid_bind = (*input_st->libretro_input_binds[mapped_port])[id].valid && + (id == settings->uints.input_remap_ids[mapped_port][id]); + + if (valid_bind) + { + if (sec_joypad) + ret = input_joypad_analog_button( + input_analog_deadzone, + input_analog_sensitivity, + sec_joypad, &joypad_info, + id, + &(*input_st->libretro_input_binds[mapped_port])[id]); + + if (joypad && (ret == 0)) + ret = input_joypad_analog_button( + input_analog_deadzone, + input_analog_sensitivity, + joypad, &joypad_info, + id, + &(*input_st->libretro_input_binds[mapped_port])[id]); + } + } + } + else + { + if (sec_joypad) + ret = input_joypad_analog_axis( + input_analog_dpad_mode, + input_analog_deadzone, + input_analog_sensitivity, + sec_joypad, + &joypad_info, + idx, + id, + (*input_st->libretro_input_binds[mapped_port])); + + if (joypad && (ret == 0)) + ret = input_joypad_analog_axis( + input_analog_dpad_mode, + input_analog_deadzone, + input_analog_sensitivity, + joypad, + &joypad_info, + idx, + id, + (*input_st->libretro_input_binds[mapped_port])); + } + } + } + + if (!input_blocked) + { + input_mapper_t *handle = &input_st->mapper; + + if (bitmask_enabled) + { + unsigned i; + for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) + if (input_state_device(input_st, + settings, handle, + input_analog_dpad_mode, ret, mapped_port, + device, idx, i, true)) + port_result |= (1 << i); + } + else + port_result = input_state_device(input_st, + settings, handle, + input_analog_dpad_mode, ret, mapped_port, + device, idx, id, false); + } + + /* Digital values are represented by a bitmap; + * we can just perform the logical OR of + * successive samples. + * Analog values are an integer corresponding + * to the extent of the analog motion; these + * cannot be OR'd together, we must instead + * keep the value with the largest magnitude */ + if (device == RETRO_DEVICE_ANALOG) + { + if (result == 0) + result = port_result; + else + { + int16_t port_result_abs = (port_result >= 0) ? + port_result : -port_result; + int16_t result_abs = (result >= 0) ? + result : -result; + + if (port_result_abs > result_abs) + result = port_result; + } + } + else + result |= port_result; + } + + return result; +} + + #ifdef HAVE_OVERLAY /** * input_overlay_add_inputs: @@ -1280,9 +1824,9 @@ static bool input_overlay_add_inputs_inner(overlay_desc_t *desc, return (desc->updated != 0); case OVERLAY_TYPE_KEYBOARD: - if (ol_state ? - OVERLAY_GET_KEY(ol_state, desc->retro_key_idx) : - input_state_internal(port, RETRO_DEVICE_KEYBOARD, 0, desc->retro_key_idx)) + if ( ol_state + ? OVERLAY_GET_KEY(ol_state, desc->retro_key_idx) + : input_state_internal(port, RETRO_DEVICE_KEYBOARD, 0, desc->retro_key_idx)) { desc->updated = 1; return true; @@ -1297,14 +1841,11 @@ static bool input_overlay_add_inputs_inner(overlay_desc_t *desc, } static bool input_overlay_add_inputs(input_overlay_t *ol, + input_overlay_state_t *ol_state, bool show_touched, unsigned port) { size_t i; - bool button_pressed = false; - input_overlay_state_t *ol_state = &ol->overlay_state; - - if (!ol_state) - return false; + bool button_pressed = false; for (i = 0; i < ol->active->size; i++) { @@ -1327,9 +1868,9 @@ static void input_overlay_get_eightway_slope_limits( / (100.0f + diagonal_sensitivity); float high_angle /* 67.5 deg max */ - = (f * (0.375*M_PI) + (1.0f - f) * (0.25*M_PI)); + = (f * (0.375 * M_PI) + (1.0f - f) * (0.25 * M_PI)); float low_angle /* 22.5 deg min */ - = (f * (0.125*M_PI) + (1.0f - f) * (0.25*M_PI)); + = (f * (0.125 * M_PI) + (1.0f - f) * (0.25 * M_PI)); *high_slope = tan(high_angle); *low_slope = tan(low_angle); @@ -2303,7 +2844,7 @@ static void input_poll_overlay( break; } - button_pressed = input_overlay_add_inputs(ol, + button_pressed = input_overlay_add_inputs(ol, ol_state, (input_overlay_show_inputs == OVERLAY_SHOW_INPUT_TOUCHED), input_overlay_show_inputs_port); @@ -4366,352 +4907,6 @@ static void input_keys_pressed( } } -static int16_t input_state_device( - input_driver_state_t *input_st, - settings_t *settings, - input_mapper_t *handle, - unsigned input_analog_dpad_mode, - int16_t ret, - unsigned port, unsigned device, - unsigned idx, unsigned id, - bool button_mask) -{ - int16_t res = 0; - - switch (device) - { - case RETRO_DEVICE_JOYPAD: - - if (id < RARCH_FIRST_META_KEY) - { -#ifdef HAVE_NETWORKGAMEPAD - /* Don't process binds if input is coming from Remote RetroPad */ - if ( input_st->remote - && INPUT_REMOTE_KEY_PRESSED(input_st, id, port)) - res |= 1; - else -#endif - { - bool bind_valid = input_st->libretro_input_binds[port] - && (*input_st->libretro_input_binds[port])[id].valid; - unsigned remap_button = settings->uints.input_remap_ids[port][id]; - - /* TODO/FIXME: What on earth is this code doing...? */ - if (!(bind_valid && (id != remap_button))) - { - if (button_mask) - { - if (ret & (1 << id)) - res |= (1 << id); - } - else - res = ret; - } - - if (BIT256_GET(handle->buttons[port], id)) - res = 1; - -#ifdef HAVE_OVERLAY - /* Check if overlay is active and button - * corresponding to 'id' has been pressed */ - if ( (port == 0) - && input_st->overlay_ptr - && (input_st->overlay_ptr->flags & INPUT_OVERLAY_ALIVE) - && BIT256_GET(input_st->overlay_ptr->overlay_state.buttons, id)) - { -#ifdef HAVE_MENU - bool menu_driver_alive = menu_state_get_ptr()->flags & - MENU_ST_FLAG_ALIVE; -#else - bool menu_driver_alive = false; -#endif - bool input_remap_binds_enable = settings->bools.input_remap_binds_enable; - - /* This button has already been processed - * inside input_driver_poll() if all the - * following are true: - * > Menu driver is not running - * > Input remaps are enabled - * > 'id' is not equal to remapped button index - * If these conditions are met, input here - * is ignored */ - if ((menu_driver_alive || !input_remap_binds_enable) || - (id == remap_button)) - res |= 1; - } -#endif - } - - /* Don't allow turbo for D-pad. */ - if ( (id < RETRO_DEVICE_ID_JOYPAD_UP) || - ( (id > RETRO_DEVICE_ID_JOYPAD_RIGHT) && - (id <= RETRO_DEVICE_ID_JOYPAD_R3))) - { - /* - * Apply turbo button if activated. - */ - unsigned turbo_mode = settings->uints.input_turbo_mode; - - if (turbo_mode > INPUT_TURBO_MODE_CLASSIC) - { - /* Pressing turbo button toggles turbo mode on or off. - * Holding the button will - * pass through, else the pressed state will be modulated by a - * periodic pulse defined by the configured duty cycle. - */ - - /* Avoid detecting the turbo button being held as multiple toggles */ - if (!input_st->turbo_btns.frame_enable[port]) - input_st->turbo_btns.turbo_pressed[port] &= ~(1 << 31); - else if (input_st->turbo_btns.turbo_pressed[port] >= 0) - { - input_st->turbo_btns.turbo_pressed[port] |= (1 << 31); - /* Toggle turbo for selected buttons. */ - if (input_st->turbo_btns.enable[port] - != (1 << settings->uints.input_turbo_default_button)) - { - static const int button_map[]={ - RETRO_DEVICE_ID_JOYPAD_B, - RETRO_DEVICE_ID_JOYPAD_Y, - RETRO_DEVICE_ID_JOYPAD_A, - RETRO_DEVICE_ID_JOYPAD_X, - RETRO_DEVICE_ID_JOYPAD_L, - RETRO_DEVICE_ID_JOYPAD_R, - RETRO_DEVICE_ID_JOYPAD_L2, - RETRO_DEVICE_ID_JOYPAD_R2, - RETRO_DEVICE_ID_JOYPAD_L3, - RETRO_DEVICE_ID_JOYPAD_R3}; - input_st->turbo_btns.enable[port] = 1 << button_map[ - MIN( - ARRAY_SIZE(button_map) - 1, - settings->uints.input_turbo_default_button)]; - } - input_st->turbo_btns.mode1_enable[port] ^= 1; - } - - if (input_st->turbo_btns.turbo_pressed[port] & (1 << 31)) - { - /* Avoid detecting buttons being held as multiple toggles */ - if (!res) - input_st->turbo_btns.turbo_pressed[port] &= ~(1 << id); - else if (!(input_st->turbo_btns.turbo_pressed[port] & (1 << id)) && - turbo_mode == INPUT_TURBO_MODE_SINGLEBUTTON) - { - uint16_t enable_new; - input_st->turbo_btns.turbo_pressed[port] |= 1 << id; - /* Toggle turbo for pressed button but make - * sure at least one button has turbo */ - enable_new = input_st->turbo_btns.enable[port] ^ (1 << id); - if (enable_new) - input_st->turbo_btns.enable[port] = enable_new; - } - } - /* Hold mode stops turbo on release */ - else if ( - turbo_mode == INPUT_TURBO_MODE_SINGLEBUTTON_HOLD - && input_st->turbo_btns.enable[port] - && input_st->turbo_btns.mode1_enable[port]) - input_st->turbo_btns.mode1_enable[port] = 0; - - if (!res && input_st->turbo_btns.mode1_enable[port] && - input_st->turbo_btns.enable[port] & (1 << id)) - { - /* If turbo button is enabled for this key ID */ - res = (( input_st->turbo_btns.count - % settings->uints.input_turbo_period) - < settings->uints.input_turbo_duty_cycle); - } - } - else - { - /* If turbo button is held, all buttons pressed except - * for D-pad will go into a turbo mode. Until the button is - * released again, the input state will be modulated by a - * periodic pulse defined by the configured duty cycle. - */ - if (res) - { - if (input_st->turbo_btns.frame_enable[port]) - input_st->turbo_btns.enable[port] |= (1 << id); - - if (input_st->turbo_btns.enable[port] & (1 << id)) - /* if turbo button is enabled for this key ID */ - res = ((input_st->turbo_btns.count - % settings->uints.input_turbo_period) - < settings->uints.input_turbo_duty_cycle); - } - else - input_st->turbo_btns.enable[port] &= ~(1 << id); - } - } - } - - break; - - - case RETRO_DEVICE_KEYBOARD: - - res = ret; - - if (id < RETROK_LAST) - { -#ifdef HAVE_OVERLAY - if (port == 0) - { - if (input_st->overlay_ptr - && (input_st->overlay_ptr->flags & INPUT_OVERLAY_ALIVE)) - { - input_overlay_state_t - *ol_state = &input_st->overlay_ptr->overlay_state; - - if (OVERLAY_GET_KEY(ol_state, id)) - res |= 1; - } - } -#endif - if (MAPPER_GET_KEY(handle, id)) - res |= 1; - } - - break; - - - case RETRO_DEVICE_ANALOG: - { -#if defined(HAVE_NETWORKGAMEPAD) || defined(HAVE_OVERLAY) -#ifdef HAVE_NETWORKGAMEPAD - input_remote_state_t - *input_state = &input_st->remote_st_ptr; - -#endif - unsigned base = (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT) - ? 2 : 0; - if (id == RETRO_DEVICE_ID_ANALOG_Y) - base += 1; -#ifdef HAVE_NETWORKGAMEPAD - if ( input_st->remote - && input_state && input_state->analog[base][port]) - res = input_state->analog[base][port]; - else -#endif -#endif - { - if (id < RARCH_FIRST_META_KEY) - { - bool bind_valid = input_st->libretro_input_binds[port] - && (*input_st->libretro_input_binds[port])[id].valid; - - if (bind_valid) - { - /* reset_state - used to reset input state of a button - * when the gamepad mapper is in action for that button*/ - bool reset_state = false; - if (idx < 2 && id < 2) - { - unsigned offset = RARCH_FIRST_CUSTOM_BIND + - (idx * 4) + (id * 2); - - if (settings->uints.input_remap_ids[port][offset] != offset) - reset_state = true; - else if (settings->uints.input_remap_ids[port][offset+1] != (offset+1)) - reset_state = true; - } - - if (reset_state) - res = 0; - else - { - res = ret; - -#ifdef HAVE_OVERLAY - if (input_st->overlay_ptr && - (input_st->overlay_ptr->flags & INPUT_OVERLAY_ALIVE) && - (port == 0) && - (idx != RETRO_DEVICE_INDEX_ANALOG_BUTTON) && - !(((input_analog_dpad_mode == ANALOG_DPAD_LSTICK) && - (idx == RETRO_DEVICE_INDEX_ANALOG_LEFT)) || - ((input_analog_dpad_mode == ANALOG_DPAD_RSTICK) && - (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)))) - { - input_overlay_state_t *ol_state = - &input_st->overlay_ptr->overlay_state; - int16_t ol_analog = - ol_state->analog[base]; - - /* Analog values are an integer corresponding - * to the extent of the analog motion; these - * cannot be OR'd together, we must instead - * keep the value with the largest magnitude */ - if (ol_analog) - { - if (res == 0) - res = ol_analog; - else - { - int16_t ol_analog_abs = (ol_analog >= 0) ? - ol_analog : -ol_analog; - int16_t res_abs = (res >= 0) ? - res : -res; - - res = (ol_analog_abs > res_abs) ? - ol_analog : res; - } - } - } -#endif - } - } - } - } - - if (idx < 2 && id < 2) - { - unsigned offset = 0 + (idx * 4) + (id * 2); - int val1 = handle->analog_value[port][offset]; - int val2 = handle->analog_value[port][offset+1]; - - /* OR'ing these analog values is 100% incorrect, - * but I have no idea what this code is supposed - * to be doing (val1 and val2 always seem to be - * zero), so I will leave it alone... */ - if (val1) - res |= val1; - else if (val2) - res |= val2; - } - } - break; - - case RETRO_DEVICE_MOUSE: - case RETRO_DEVICE_LIGHTGUN: - case RETRO_DEVICE_POINTER: - - if (input_st->flags & INP_FLAG_BLOCK_POINTER_INPUT) - break; - - if (id < RARCH_FIRST_META_KEY) - { - bool bind_valid = input_st->libretro_input_binds[port] - && (*input_st->libretro_input_binds[port])[id].valid; - - if (bind_valid) - { - if (button_mask) - { - if (ret & (1 << id)) - res |= (1 << id); - } - else - res = ret; - } - } - - break; - } - - return res; -} - #ifdef HAVE_BSV_MOVIE /* Forward declaration */ void bsv_movie_free(bsv_movie_t*); @@ -5542,202 +5737,6 @@ void input_driver_poll(void) #endif } -int16_t input_state_internal(unsigned port, unsigned device, - unsigned idx, unsigned id) -{ - rarch_joypad_info_t joypad_info; - unsigned mapped_port; - input_driver_state_t *input_st = &input_driver_st; - settings_t *settings = config_get_ptr(); - float input_analog_deadzone = settings->floats.input_analog_deadzone; - float input_analog_sensitivity = settings->floats.input_analog_sensitivity; - unsigned *input_remap_port_map = settings->uints.input_remap_port_map[port]; - bool input_driver_analog_requested = input_st->analog_requested[port]; - const input_device_driver_t *joypad = input_st->primary_joypad; -#ifdef HAVE_MFI - const input_device_driver_t *sec_joypad = input_st->secondary_joypad; -#else - const input_device_driver_t *sec_joypad = NULL; -#endif -#ifdef HAVE_MENU - struct menu_state *menu_st = menu_state_get_ptr(); - bool input_blocked = (menu_st->input_driver_flushing_input > 0) || - (input_st->flags & INP_FLAG_BLOCK_LIBRETRO_INPUT); -#else - bool input_blocked = (input_st->flags & INP_FLAG_BLOCK_LIBRETRO_INPUT); -#endif - bool bitmask_enabled = false; - unsigned max_users = settings->uints.input_max_users; - int16_t result = 0; - - device &= RETRO_DEVICE_MASK; - bitmask_enabled = (device == RETRO_DEVICE_JOYPAD) && - (id == RETRO_DEVICE_ID_JOYPAD_MASK); - joypad_info.axis_threshold = settings->floats.input_axis_threshold; - - /* Loop over all 'physical' ports mapped to specified - * 'virtual' port index */ - while ((mapped_port = *(input_remap_port_map++)) < MAX_USERS) - { - int16_t ret = 0; - int16_t port_result = 0; - unsigned input_analog_dpad_mode = settings->uints.input_analog_dpad_mode[mapped_port]; - - joypad_info.joy_idx = settings->uints.input_joypad_index[mapped_port]; - joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx]; - - /* Skip disabled input devices */ - if (mapped_port >= max_users) - continue; - - /* If core has requested analog input, disable - * analog to dpad mapping (unless forced) */ - switch (input_analog_dpad_mode) - { - case ANALOG_DPAD_LSTICK: - case ANALOG_DPAD_RSTICK: - if (input_driver_analog_requested) - input_analog_dpad_mode = ANALOG_DPAD_NONE; - break; - case ANALOG_DPAD_LSTICK_FORCED: - input_analog_dpad_mode = ANALOG_DPAD_LSTICK; - break; - case ANALOG_DPAD_RSTICK_FORCED: - input_analog_dpad_mode = ANALOG_DPAD_RSTICK; - break; - default: - break; - } - - /* TODO/FIXME: This code is gibberish - a mess of nested - * refactors that make no sense whatsoever. The entire - * thing needs to be rewritten from scratch... */ - - ret = input_state_wrap( - input_st->current_driver, - input_st->current_data, - joypad, - sec_joypad, - &joypad_info, - (*input_st->libretro_input_binds), - input_st->flags & INP_FLAG_KB_MAPPING_BLOCKED, - mapped_port, device, idx, id); - - if ((device == RETRO_DEVICE_ANALOG) && - (ret == 0)) - { - if (input_st->libretro_input_binds[mapped_port]) - { - if (idx == RETRO_DEVICE_INDEX_ANALOG_BUTTON) - { - if (id < RARCH_FIRST_CUSTOM_BIND) - { - /* TODO/FIXME: Analog buttons can only be read as analog - * when the default mapping is applied. If the user - * remaps any analog buttons, they will become 'digital' - * due to the way that mapping is handled elsewhere. We - * cannot fix this without rewriting the entire mess that - * is the input remapping system... */ - bool valid_bind = (*input_st->libretro_input_binds[mapped_port])[id].valid && - (id == settings->uints.input_remap_ids[mapped_port][id]); - - if (valid_bind) - { - if (sec_joypad) - ret = input_joypad_analog_button( - input_analog_deadzone, - input_analog_sensitivity, - sec_joypad, &joypad_info, - id, - &(*input_st->libretro_input_binds[mapped_port])[id]); - - if (joypad && (ret == 0)) - ret = input_joypad_analog_button( - input_analog_deadzone, - input_analog_sensitivity, - joypad, &joypad_info, - id, - &(*input_st->libretro_input_binds[mapped_port])[id]); - } - } - } - else - { - if (sec_joypad) - ret = input_joypad_analog_axis( - input_analog_dpad_mode, - input_analog_deadzone, - input_analog_sensitivity, - sec_joypad, - &joypad_info, - idx, - id, - (*input_st->libretro_input_binds[mapped_port])); - - if (joypad && (ret == 0)) - ret = input_joypad_analog_axis( - input_analog_dpad_mode, - input_analog_deadzone, - input_analog_sensitivity, - joypad, - &joypad_info, - idx, - id, - (*input_st->libretro_input_binds[mapped_port])); - } - } - } - - if (!input_blocked) - { - input_mapper_t *handle = &input_st->mapper; - - if (bitmask_enabled) - { - unsigned i; - for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) - if (input_state_device(input_st, - settings, handle, - input_analog_dpad_mode, ret, mapped_port, - device, idx, i, true)) - port_result |= (1 << i); - } - else - port_result = input_state_device(input_st, - settings, handle, - input_analog_dpad_mode, ret, mapped_port, - device, idx, id, false); - } - - /* Digital values are represented by a bitmap; - * we can just perform the logical OR of - * successive samples. - * Analog values are an integer corresponding - * to the extent of the analog motion; these - * cannot be OR'd together, we must instead - * keep the value with the largest magnitude */ - if (device == RETRO_DEVICE_ANALOG) - { - if (result == 0) - result = port_result; - else - { - int16_t port_result_abs = (port_result >= 0) ? - port_result : -port_result; - int16_t result_abs = (result >= 0) ? - result : -result; - - if (port_result_abs > result_abs) - result = port_result; - } - } - else - result |= port_result; - } - - return result; -} - int16_t input_driver_state_wrapper(unsigned port, unsigned device, unsigned idx, unsigned id) { diff --git a/input/input_driver.h b/input/input_driver.h index fdcaf6ec79..9067111b43 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -963,9 +963,6 @@ void input_config_get_bind_string_joykey( char *buf, const char *prefix, const struct retro_keybind *bind, size_t size); -int16_t input_state_internal(unsigned port, unsigned device, - unsigned idx, unsigned id); - bool input_key_pressed(int key, bool keyboard_pressed); bool input_set_rumble_state(unsigned port, diff --git a/libretro-common/cdrom/cdrom.c b/libretro-common/cdrom/cdrom.c index 2873cbb140..56c8f2a110 100644 --- a/libretro-common/cdrom/cdrom.c +++ b/libretro-common/cdrom/cdrom.c @@ -1446,13 +1446,13 @@ struct string_list* cdrom_get_available_drives(void) DWORD drive_mask = GetLogicalDrives(); int i; - for (i = 0; i < sizeof(DWORD) * 8; i++) + for (i = 0; i < (int)(sizeof(DWORD) * 8); i++) { - char path[] = {"a:\\"}; + char path[] = {"a:\\"}; char cdrom_path[] = {"cdrom://a:/drive-track01.bin"}; - path[0] += i; - cdrom_path[8] += i; + path[0] += i; + cdrom_path[8] += i; /* this drive letter doesn't exist */ if (!(drive_mask & (1 << i))) @@ -1460,15 +1460,14 @@ struct string_list* cdrom_get_available_drives(void) if (GetDriveType(path) != DRIVE_CDROM) continue; - else + { - char drive_model[32] = {0}; - char drive_string[33] = {0}; + libretro_vfs_implementation_file *stream; + bool is_cdrom = false; + char drive_model[32] = {0}; + char drive_string[33] = {0}; union string_list_elem_attr attr = {0}; RFILE *file = filestream_open(cdrom_path, RETRO_VFS_FILE_ACCESS_READ, 0); - libretro_vfs_implementation_file *stream; - bool is_cdrom = false; - if (!file) continue; @@ -1524,9 +1523,7 @@ bool cdrom_drive_has_media(const char drive) if (file) { libretro_vfs_implementation_file *stream = filestream_get_vfs_handle(file); - bool has_media = false; - - has_media = cdrom_is_media_inserted(stream); + bool has_media = cdrom_is_media_inserted(stream); filestream_close(file); @@ -1538,14 +1535,14 @@ bool cdrom_drive_has_media(const char drive) bool cdrom_set_read_cache(libretro_vfs_implementation_file *stream, bool enabled) { + int i; /* MMC Command: MODE SENSE (10) and MODE SELECT (10) */ unsigned char cdb_sense_changeable[] = {0x5A, 0, 0x48, 0, 0, 0, 0, 0, 0x14, 0}; - unsigned char cdb_sense[] = {0x5A, 0, 0x8, 0, 0, 0, 0, 0, 0x14, 0}; - unsigned char cdb_select[] = {0x55, 0x10, 0, 0, 0, 0, 0, 0, 0x14, 0}; - unsigned char buf[20] = {0}; - int rv, i; - - rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb_sense_changeable, sizeof(cdb_sense_changeable), 0); + unsigned char cdb_sense[] = {0x5A, 0, 0x8, 0, 0, 0, 0, 0, 0x14, 0}; + unsigned char cdb_select[] = {0x55, 0x10, 0, 0, 0, 0, 0, 0, 0x14, 0}; + unsigned char buf[20] = {0}; + int rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), + cdb_sense_changeable, sizeof(cdb_sense_changeable), 0); #ifdef CDROM_DEBUG printf("[CDROM] mode sense changeable status code %d\n", rv); @@ -1581,9 +1578,7 @@ bool cdrom_set_read_cache(libretro_vfs_implementation_file *stream, bool enabled printf("Mode sense data for caching mode page: "); for (i = 0; i < (int)sizeof(buf); i++) - { printf("%02X ", buf[i]); - } printf("\n"); fflush(stdout); @@ -1596,7 +1591,7 @@ bool cdrom_set_read_cache(libretro_vfs_implementation_file *stream, bool enabled if (enabled) buf[10] &= ~1; else - buf[10] |= 1; + buf[10] |= 1; rv = cdrom_send_command(stream, DIRECTION_OUT, buf, sizeof(buf), cdb_select, sizeof(cdb_select), 0); @@ -1645,9 +1640,7 @@ bool cdrom_get_timeouts(libretro_vfs_implementation_file *stream, cdrom_group_ti printf("Mode sense data for timeout groups: "); for (i = 0; i < (int)sizeof(buf); i++) - { printf("%02X ", buf[i]); - } printf("\n"); @@ -1669,8 +1662,8 @@ bool cdrom_get_timeouts(libretro_vfs_implementation_file *stream, cdrom_group_ti bool cdrom_has_atip(libretro_vfs_implementation_file *stream) { /* MMC Command: READ TOC/PMA/ATIP */ - unsigned char cdb[] = {0x43, 0x2, 0x4, 0, 0, 0, 0, 0x9, 0x30, 0}; - unsigned char buf[32] = {0}; + unsigned char cdb[] = {0x43, 0x2, 0x4, 0, 0, 0, 0, 0x9, 0x30, 0}; + unsigned char buf[32] = {0}; unsigned short atip_len = 0; int rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb, sizeof(cdb), 0); @@ -1680,7 +1673,10 @@ bool cdrom_has_atip(libretro_vfs_implementation_file *stream) atip_len = buf[0] << 8 | buf[1]; #ifdef CDROM_DEBUG - printf("ATIP Length %d, Disc Type %d, Disc Sub-Type %d\n", atip_len, (buf[6] >> 6) & 0x1, ((buf[6] >> 5) & 0x1) << 2 | ((buf[6] >> 4) & 0x1) << 1 | ((buf[6] >> 3) & 0x1) << 0); + printf("ATIP Length %d, Disc Type %d, Disc Sub-Type %d\n", + atip_len, + (buf[6] >> 6) & 0x1, + ((buf[6] >> 5) & 0x1) << 2 | ((buf[6] >> 4) & 0x1) << 1 | ((buf[6] >> 3) & 0x1) << 0); #endif if (atip_len < 5) @@ -1691,30 +1687,23 @@ bool cdrom_has_atip(libretro_vfs_implementation_file *stream) void cdrom_device_fillpath(char *path, size_t len, char drive, unsigned char track, bool is_cue) { - size_t pos = 0; - if (!path || len == 0) return; - if (is_cue) { #ifdef _WIN32 - pos = strlcpy(path, "cdrom://", len); - + size_t pos = strlcpy(path, "cdrom://", len); if (len > pos) path[pos++] = drive; - pos = strlcat(path, ":/drive.cue", len); #else #ifdef __linux__ - pos = strlcpy(path, "cdrom://drive", len); - + size_t pos = strlcpy(path, "cdrom://drive", len); if (len > pos + 1) { path[pos++] = drive; - path[pos] = '\0'; + path[pos] = '\0'; } - pos = strlcat(path, ".cue", len); #endif #endif @@ -1722,22 +1711,18 @@ void cdrom_device_fillpath(char *path, size_t len, char drive, unsigned char tra else { #ifdef _WIN32 - pos = strlcpy(path, "cdrom://", len); - + size_t pos = strlcpy(path, "cdrom://", len); if (len > pos + 1) { path[pos++] = drive; - path[pos] = '\0'; + path[pos] = '\0'; } - pos += snprintf(path + pos, len - pos, ":/drive-track%02d.bin", track); #else #ifdef __linux__ - pos = strlcpy(path, "cdrom://drive", len); - + size_t pos = strlcpy(path, "cdrom://drive", len); if (len > pos) path[pos++] = drive; - pos += snprintf(path + pos, len - pos, "-track%02d.bin", track); #endif #endif diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index a84569acd2..b74716edb2 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -699,8 +699,8 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, int64_t retro_vfs_file_write_impl(libretro_vfs_implementation_file *stream, const void *s, uint64_t len) { - int64_t pos = 0; - size_t result = -1; + int64_t pos = 0; + ssize_t result = -1; if (!stream) return -1; diff --git a/menu/drivers/ozone.c b/menu/drivers/ozone.c index 1e25017ff6..ec64f15273 100644 --- a/menu/drivers/ozone.c +++ b/menu/drivers/ozone.c @@ -8025,7 +8025,7 @@ static enum menu_action ozone_parse_menu_entry_action( ? ozone_get_onscreen_category_selection(ozone) : ozone->categories_selection_ptr; - if (tab_selection < ozone->system_tab_end + 1) + if (tab_selection < (size_t)(ozone->system_tab_end + 1)) break; new_selection = tab_selection - ozone->system_tab_end - 1; @@ -8126,7 +8126,7 @@ static enum menu_action ozone_parse_menu_entry_action( new_selection = (int)(selection + 1); if (new_selection >= (int)(ozone->system_tab_end + horizontal_list_size + 1)) - new_selection = 0; + new_selection = 0; ozone_sidebar_goto(ozone, new_selection); new_action = MENU_ACTION_ACCESSIBILITY_SPEAK_TITLE; @@ -8368,7 +8368,7 @@ static enum menu_action ozone_parse_menu_entry_action( ? ozone_get_onscreen_category_selection(ozone) : ozone->categories_selection_ptr; - new_selection = tab_selection; + new_selection = (int)tab_selection; if (menu_st->scroll.mode == MENU_SCROLL_PAGE) new_selection = (int)(tab_selection - 10); @@ -8385,7 +8385,7 @@ static enum menu_action ozone_parse_menu_entry_action( new_selection = ozone->sidebar_index_list[l - 1]; } - if (tab_selection < ozone->system_tab_end + 1) + if (tab_selection < (size_t)(ozone->system_tab_end + 1)) new_selection = 0; else if ((int)tab_selection > (int)ozone->system_tab_end - new_selection || new_selection < 0) @@ -8429,7 +8429,7 @@ static enum menu_action ozone_parse_menu_entry_action( ? ozone_get_onscreen_category_selection(ozone) : ozone->categories_selection_ptr; - new_selection = tab_selection; + new_selection = (int)tab_selection; if (menu_st->scroll.mode == MENU_SCROLL_PAGE) new_selection = (int)(tab_selection + 10); @@ -8438,16 +8438,16 @@ static enum menu_action ozone_parse_menu_entry_action( /* Alphabetical scroll */ size_t l = 0; - while (l < ozone->sidebar_index_size - 1 - && ozone->sidebar_index_list[l + 1] <= tab_selection) + while ( (l < (size_t)(ozone->sidebar_index_size - 1)) + && (ozone->sidebar_index_list[l + 1] <= tab_selection)) l++; - if (l < ozone->sidebar_index_size - 1) + if (l < (size_t)(ozone->sidebar_index_size - 1)) new_selection = ozone->sidebar_index_list[l + 1]; - else if (l == ozone->sidebar_index_size - 1) + else if (l == (size_t)(ozone->sidebar_index_size - 1)) new_selection = ozone->system_tab_end + horizontal_list_size; - if (tab_selection < ozone->system_tab_end + 1) + if (tab_selection < (size_t)(ozone->system_tab_end + 1)) new_selection = ozone->system_tab_end + 1; } @@ -12493,7 +12493,7 @@ static int ozone_pointer_up(void *userdata, case MENU_INPUT_GESTURE_LONG_PRESS: /* 'Reset to default' action */ if ( ((int)y > ozone->dimensions.header_height) - && ((int)y < height - ozone->dimensions.footer_height) + && ((int)y < (int)(height - ozone->dimensions.footer_height)) && (ptr < entries_end) && (ptr == selection) && ((int)x > ozone->dimensions_sidebar_width + ozone->sidebar_offset) diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index ad8e7923fd..e15275d3ba 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -1853,12 +1853,12 @@ static bool INLINE rgui_draw_particle( /* This great convoluted mess just saves us * having to perform comparisons on every * iteration of the for loops... */ - int x_start_i = (x > 0) ? x : 0; - int y_start_i = (y > 0) ? y : 0; - int x_end = x + width; - int y_end = y + height; - int x_start = (x_start_i <= (int)fb_width) ? x_start_i : fb_width; - int y_start = (y_start_i <= (int)fb_height) ? y_start_i : fb_height; + unsigned x_start_i = (x > 0) ? x : 0; + unsigned y_start_i = (y > 0) ? y : 0; + int x_end = x + width; + int y_end = y + height; + int x_start = (x_start_i <= fb_width) ? x_start_i : fb_width; + int y_start = (y_start_i <= fb_height) ? y_start_i : fb_height; if (x_end <= 0) x_end = 0; @@ -5246,7 +5246,9 @@ static void rgui_render( title_width = (unsigned)(utf8len(thumbnail_title_buf) * rgui->font_width_stride); } - title_x = rgui->term_layout.start_x + ((rgui->term_layout.width * rgui->font_width_stride) - title_width) / 2; + title_x = (unsigned)(rgui->term_layout.start_x + + ((rgui->term_layout.width * rgui->font_width_stride) + - title_width) / 2); /* Draw thumbnail title background */ rgui_fill_rect(rgui->frame_buf.data, fb_width, fb_height, @@ -5387,7 +5389,7 @@ static void rgui_render( if (use_smooth_ticker) { ticker_smooth.selected = true; - ticker_smooth.field_width = title_max_len * rgui->font_width_stride; + ticker_smooth.field_width = (unsigned)(title_max_len * rgui->font_width_stride); ticker_smooth.src_str = rgui->menu_title; ticker_smooth.dst_str = title_buf; ticker_smooth.dst_str_len = sizeof(title_buf); @@ -5395,9 +5397,9 @@ static void rgui_render( /* If title is scrolling, then title_len == title_max_len */ if (gfx_animation_ticker_smooth(&ticker_smooth)) - title_len = title_max_len; + title_len = title_max_len; else - title_len = utf8len(title_buf); + title_len = utf8len(title_buf); } else { @@ -5413,8 +5415,10 @@ static void rgui_render( string_to_upper(title_buf); - title_x = ticker_x_offset + rgui->term_layout.start_x + - (rgui->term_layout.width - title_len) * rgui->font_width_stride / 2; + title_x = (unsigned)(ticker_x_offset + + rgui->term_layout.start_x + + (rgui->term_layout.width - title_len) + * rgui->font_width_stride / 2); /* Title is always centred, unless it is long enough * to infringe upon the battery indicator, in which case @@ -5470,7 +5474,7 @@ static void rgui_render( { unsigned term_offset = rgui_swap_thumbnails ? (unsigned)(rgui->term_layout.height - (i - new_start) - 1) - : (i - new_start); + : (unsigned)(i - new_start); unsigned thumbnail_width = 0; /* Note: @@ -5551,7 +5555,7 @@ static void rgui_render( if (use_smooth_ticker) { ticker_smooth.selected = entry_selected; - ticker_smooth.field_width = entry_title_max_len * rgui->font_width_stride; + ticker_smooth.field_width = (unsigned)(entry_title_max_len * rgui->font_width_stride); if (!string_is_empty(entry.rich_label)) ticker_smooth.src_str = entry.rich_label; else @@ -7861,11 +7865,11 @@ static void rgui_thumbnail_cycle_dupe(rgui_t *rgui) if (settings->uints.gfx_thumbnails == settings->uints.menu_left_thumbnails) { + unsigned tmp = (rgui->gfx_thumbnails_prev > 0) + ? (unsigned)rgui->gfx_thumbnails_prev + : settings->uints.gfx_thumbnails + 1; configuration_set_uint(settings, - settings->uints.gfx_thumbnails, - (rgui->gfx_thumbnails_prev > 0) - ? rgui->gfx_thumbnails_prev - : settings->uints.gfx_thumbnails + 1); + settings->uints.gfx_thumbnails, tmp); if (settings->uints.gfx_thumbnails > 3) configuration_set_uint(settings, diff --git a/menu/menu_explore.c b/menu/menu_explore.c index 14333b0f87..455f0020ee 100644 --- a/menu/menu_explore.c +++ b/menu/menu_explore.c @@ -595,7 +595,7 @@ explore_state_t *menu_explore_build_list(const char *directory_playlist, RHMAP_SET(rdb_indices, rdb_hash, rdb_num); } - if (rdb_num == (uintptr_t)-1) + if ((uintptr_t)rdb_num == (uintptr_t)-1) continue; rdb = &rdbs[rdb_num - 1]; diff --git a/ui/drivers/ui_qt.cpp b/ui/drivers/ui_qt.cpp index e87aa1db90..f1cfccb183 100644 --- a/ui/drivers/ui_qt.cpp +++ b/ui/drivers/ui_qt.cpp @@ -1646,7 +1646,7 @@ void MainWindow::onFileBrowserTableDirLoaded(const QString &path) QVector > MainWindow::getPlaylists() { - int i; + size_t i; QVector > playlists; size_t size = m_listWidget->count(); @@ -2243,7 +2243,7 @@ void MainWindow::onThumbnailDropped(const QImage &image, QVector > MainWindow::getCoreInfo() { - int i; + size_t i; QVector > infoList; runloop_state_t *runloop_st = runloop_state_get_ptr(); QHash currentCore = getSelectedCore(); @@ -2753,7 +2753,7 @@ void MainWindow::loadContent(const QHash &contentHash) { if (list->size > 0) { - int i; + size_t i; for (i = 0; i < list->size; i++) { const char *filePath = list->elems[i].data; @@ -3724,10 +3724,10 @@ void MainWindow::initContentTableWidget() if (path == ALL_PLAYLISTS_TOKEN) { - int i; + size_t i; + QStringList playlists; settings_t *settings = config_get_ptr(); QDir playlistDir(settings->paths.directory_playlist); - QStringList playlists; size_t list_size = (size_t)m_playlistFiles.count(); for (i = 0; i < list_size; i++) @@ -3910,7 +3910,7 @@ void MainWindow::onShowInfoMessage(QString msg) int MainWindow::onExtractArchive(QString path, QString extractionDir, QString tempExtension, retro_task_callback_t cb) { - int i; + size_t i; file_archive_transfer_t state; struct archive_extract_userdata userdata; QByteArray pathArray = path.toUtf8();