diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/CHANGES.md retroarch-1.7.8.4-r201909221517-5f87fa1/CHANGES.md --- retroarch-1.7.8.4-r201909211518-302e2fd/CHANGES.md 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/CHANGES.md 2019-09-22 15:17:52.000000000 +0000 @@ -1,9 +1,11 @@ # Future -- BUGFIX: Touch input - When using an overlay to toggle the quick menu on touchscreen devices, we no longer get 'phantom' menu input - i.e. the old bug of hitting the toggle and instantly resuming content (or performing a save state) is fixed. +- AI SERVICE: Image mode is now much faster, it now saves the image in-memory in PNG format then passes it along to the translation service +- BUGFIX: Touch input - When using an overlay to toggle the quick menu on touchscreen devices, we no longer get 'phantom' menu input - i.e. the old bug of hitting the toggle and instantly resuming content (or performing a save state) is fixed - BUGFIX: Networking - RetroArch crashed when pressing left while Relay Server Location entry was selected - BUGFIX: Networking - fix memory leak that could happen at exit after a network operation had run -- FPGA: Add initial FPGA port for Z-Turn boards - not really release-ready yet, will need community support to continue +- CHEEVOS: Improve handling of line endings when calculating CD hashes for retroachievements +- FPGA: Add initial FPGA port for Z-Turn boards - not really release-ready yet, will need community support to continue. Currently employs naive framebuffer approach, not fullspeed - GONG: Stability fixes - MENU/MATERIALUI: MaterialUI no longer 'forgets' its place when navigating backwards in menus, and navigation in general is 'cleaner'. - MENU/RGUI: Functional mouse/touchscreen support @@ -11,6 +13,8 @@ - MENU/MOUSE: Mouse wheel up/down is now a proper 'up/down', same as using cursor keys or a dpad - MENU/MOUSE: Mouse wheel tilt left/right has been wired up to normal 'left/right' commands. Also further improved mouse wheel tilt - MENU/OSX: Fixed mouse buttons - mouse down events were not hooked up +- OSD: Memory details should now be available on every platform (get_mem_total and get_mem_free need to be implemented in the frontend driver for it to work) +- OSD: Memory details can now be shown individually without FPS and frame count - WIN32: Log window now has title 'Logging Console' - WII: Add Wiimote lightgun support diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/cheevos-new/cheevos.c retroarch-1.7.8.4-r201909221517-5f87fa1/cheevos-new/cheevos.c --- retroarch-1.7.8.4-r201909211518-302e2fd/cheevos-new/cheevos.c 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/cheevos-new/cheevos.c 2019-09-22 15:17:52.000000000 +0000 @@ -1583,8 +1583,9 @@ char disc_path[PATH_MAX_LENGTH]; char* tmp; - intfstream_read(m3u_stream, buffer, sizeof(buffer)); + num_read = intfstream_read(m3u_stream, buffer, sizeof(buffer)); intfstream_close(m3u_stream); + buffer[num_read] = '\0'; tmp = buffer; while (*tmp && *tmp != '\n') @@ -1640,7 +1641,7 @@ if (exe_name) { scan = exe_name; - while (*scan != '\n' && *scan != ';' && *scan != ' ') + while (*scan != '\n' && *scan != '\r' && *scan != ';' && *scan != ' ') ++scan; *scan = '\0'; diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/debian/changelog retroarch-1.7.8.4-r201909221517-5f87fa1/debian/changelog --- retroarch-1.7.8.4-r201909211518-302e2fd/debian/changelog 2019-09-21 15:18:00.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/debian/changelog 2019-09-22 15:17:56.000000000 +0000 @@ -1,8 +1,8 @@ -retroarch (1.7.8.4-r201909211518-302e2fd-92~ubuntu19.10.1) eoan; urgency=low +retroarch (1.7.8.4-r201909221517-5f87fa1-92~ubuntu19.10.1) eoan; urgency=low * Auto build. - -- Launchpad Package Builder Sat, 21 Sep 2019 15:18:00 +0000 + -- Launchpad Package Builder Sun, 22 Sep 2019 15:17:56 +0000 retroarch (1.7.8.4-1) unstable; urgency=low diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/debian/git-build-recipe.manifest retroarch-1.7.8.4-r201909221517-5f87fa1/debian/git-build-recipe.manifest --- retroarch-1.7.8.4-r201909211518-302e2fd/debian/git-build-recipe.manifest 2019-09-21 15:18:00.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/debian/git-build-recipe.manifest 2019-09-22 15:17:56.000000000 +0000 @@ -1,3 +1,3 @@ -# git-build-recipe format 0.4 deb-version {debupstream}-r201909211518-302e2fd-92 -lp:~libretro/libretro/+git/RetroArch git-commit:302e2fdc531972a358fffdba0051ec6434622db0 +# git-build-recipe format 0.4 deb-version {debupstream}-r201909221517-5f87fa1-92 +lp:~libretro/libretro/+git/RetroArch git-commit:5f87fa1acada333556e4c0fca11b0478a4d9fc63 nest packaging lp:~libretro/libretro/+git/RetroArch-debian debian git-commit:12473ca96a271fcce0c4605ff4a693f3b24f2d9b diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/frontend/drivers/platform_ctr.c retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/drivers/platform_ctr.c --- retroarch-1.7.8.4-r201909211518-302e2fd/frontend/drivers/platform_ctr.c 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/drivers/platform_ctr.c 2019-09-22 15:17:52.000000000 +0000 @@ -504,9 +504,9 @@ return osGetMemRegionSize(MEMREGION_ALL); } -static uint64_t frontend_ctr_get_mem_used(void) +static uint64_t frontend_ctr_get_mem_free(void) { - return osGetMemRegionUsed(MEMREGION_ALL); + return osGetMemRegionFree(MEMREGION_ALL); } static enum frontend_powerstate frontend_ctr_get_powerstate( @@ -609,7 +609,7 @@ frontend_ctr_get_powerstate, frontend_ctr_parse_drive_list, frontend_ctr_get_mem_total, - frontend_ctr_get_mem_used, + frontend_ctr_get_mem_free, NULL, /* install_signal_handler */ NULL, /* get_signal_handler_state */ NULL, /* set_signal_handler_state */ diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/frontend/drivers/platform_gx.c retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/drivers/platform_gx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/frontend/drivers/platform_gx.c 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/drivers/platform_gx.c 2019-09-22 15:17:52.000000000 +0000 @@ -525,10 +525,11 @@ return total; } -static uint64_t frontend_gx_get_mem_used(void) +static uint64_t frontend_gx_get_mem_free(void) { uint64_t total = SYSMEM1_SIZE - SYS_GetArena1Size(); #if defined(HW_RVL) && !defined(IS_SALAMANDER) + /* TODO/FIXME - this needs to change */ total += gx_mem2_used(); #endif return total; @@ -555,7 +556,7 @@ NULL, /* get_powerstate */ frontend_gx_parse_drive_list, frontend_gx_get_mem_total, - frontend_gx_get_mem_used, + frontend_gx_get_mem_free, NULL, /* install_signal_handler */ NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/frontend/drivers/platform_switch.c retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/drivers/platform_switch.c --- retroarch-1.7.8.4-r201909211518-302e2fd/frontend/drivers/platform_switch.c 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/drivers/platform_switch.c 2019-09-22 15:17:52.000000000 +0000 @@ -820,13 +820,16 @@ { uint64_t memoryTotal = 0; svcGetInfo(&memoryTotal, 6, 0xffff8001, 0); - memoryTotal += frontend_switch_get_mem_used(); + /* TODO/FIXME - is now 'free memory', perhaps logic + * here needs to change */ + memoryTotal += frontend_switch_get_mem_free(); return memoryTotal; } -static uint64_t frontend_switch_get_mem_used(void) +static uint64_t frontend_switch_get_mem_free(void) { + /* TODO/FIXME - should become 'free memory' */ uint64_t memoryUsed = 0; svcGetInfo(&memoryUsed, 7, 0xffff8001, 0); diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/frontend/drivers/platform_unix.c retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/drivers/platform_unix.c --- retroarch-1.7.8.4-r201909211518-302e2fd/frontend/drivers/platform_unix.c 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/drivers/platform_unix.c 2019-09-22 15:17:52.000000000 +0000 @@ -2048,51 +2048,16 @@ static uint64_t frontend_unix_get_mem_total(void) { - char line[256]; - uint64_t total = 0; - FILE * data = fopen("/proc/meminfo", "r"); - if (!data) - return 0; - - while (fgets(line, sizeof(line), data)) - { - if (sscanf(line, "MemTotal: " STRING_REP_USIZE " kB", (size_t*)&total) == 1) - { - fclose(data); - total *= 1024; - return total; - } - } - - fclose(data); - return 0; + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + return pages * page_size; } -static uint64_t frontend_unix_get_mem_used(void) +static uint64_t frontend_unix_get_mem_free(void) { - char line[256]; - uint64_t total = 0; - uint64_t freemem = 0; - uint64_t buffers = 0; - uint64_t cached = 0; - FILE* data = fopen("/proc/meminfo", "r"); - if (!data) - return 0; - - while (fgets(line, sizeof(line), data)) - { - if (sscanf(line, "MemTotal: " STRING_REP_USIZE " kB", (size_t*)&total) == 1) - total *= 1024; - if (sscanf(line, "MemFree: " STRING_REP_USIZE " kB", (size_t*)&freemem) == 1) - freemem *= 1024; - if (sscanf(line, "Buffers: " STRING_REP_USIZE " kB", (size_t*)&buffers) == 1) - buffers *= 1024; - if (sscanf(line, "Cached: " STRING_REP_USIZE " kB", (size_t*)&cached) == 1) - cached *= 1024; - } - - fclose(data); - return total - freemem - buffers - cached; + unsigned long long ps = sysconf(_SC_PAGESIZE); + unsigned long long pn = sysconf(_SC_AVPHYS_PAGES); + return ps * pn; } /*#include */ @@ -2418,7 +2383,7 @@ frontend_unix_get_powerstate, frontend_unix_parse_drive_list, frontend_unix_get_mem_total, - frontend_unix_get_mem_used, + frontend_unix_get_mem_free, frontend_unix_install_signal_handlers, frontend_unix_get_signal_handler_state, frontend_unix_set_signal_handler_state, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/frontend/frontend_driver.c retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/frontend_driver.c --- retroarch-1.7.8.4-r201909211518-302e2fd/frontend/frontend_driver.c 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/frontend_driver.c 2019-09-22 15:17:52.000000000 +0000 @@ -370,12 +370,12 @@ return frontend->get_total_mem(); } -uint64_t frontend_driver_get_used_memory(void) +uint64_t frontend_driver_get_free_memory(void) { frontend_ctx_driver_t *frontend = frontend_get_ptr(); - if (!frontend || !frontend->get_used_mem) + if (!frontend || !frontend->get_free_mem) return 0; - return frontend->get_used_mem(); + return frontend->get_free_mem(); } void frontend_driver_install_signal_handler(void) diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/frontend/frontend_driver.h retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/frontend_driver.h --- retroarch-1.7.8.4-r201909211518-302e2fd/frontend/frontend_driver.h 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/frontend/frontend_driver.h 2019-09-22 15:17:52.000000000 +0000 @@ -95,7 +95,7 @@ enum frontend_powerstate (*get_powerstate)(int *seconds, int *percent); int (*parse_drive_list)(void*, bool); uint64_t (*get_total_mem)(void); - uint64_t (*get_used_mem)(void); + uint64_t (*get_free_mem)(void); void (*install_signal_handler)(void); int (*get_signal_handler_state)(void); void (*set_signal_handler_state)(int value); @@ -193,7 +193,7 @@ uint64_t frontend_driver_get_total_memory(void); -uint64_t frontend_driver_get_used_memory(void); +uint64_t frontend_driver_get_free_memory(void); void frontend_driver_install_signal_handler(void); diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/metal_common.h retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/metal_common.h --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/metal_common.h 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/metal_common.h 2019-09-22 15:17:52.000000000 +0000 @@ -1,9 +1,18 @@ -// -// metal_common.h -// RetroArch_Metal -// -// Created by Stuart Carnie on 5/14/18. -// +/* RetroArch - A frontend for libretro. + * Copyright (C) 2018-2019 - Stuart Carnie + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ #ifndef METAL_COMMON_H__ #define METAL_COMMON_H__ @@ -26,6 +35,38 @@ #pragma mark - Classes +#import + +@interface MetalView : MTKView +@end + +#ifdef HAVE_COCOA_METAL + +@protocol ApplePlatform + +/*! @brief renderView returns the current render view based on the viewType */ +@property (readonly) id renderView; + +/*! @brief isActive returns true if the application has focus */ +@property (readonly) bool hasFocus; + +@property (readwrite) apple_view_type_t viewType; + +/*! @brief setVideoMode adjusts the video display to the specified mode */ +- (void)setVideoMode:(gfx_ctx_mode_t)mode; + +/*! @brief setCursorVisible specifies whether the cursor is visible */ +- (void)setCursorVisible:(bool)v; + +/*! @brief controls whether the screen saver should be disabled and + * the displays should not sleep. + */ +- (bool)setDisableDisplaySleep:(bool)disable; +@end + +extern id apple_platform; +#endif + @interface FrameView : NSObject @property (nonatomic, readonly) RPixelFormat format; diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/metal_common.m retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/metal_common.m --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/metal_common.m 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/metal_common.m 2019-09-22 15:17:52.000000000 +0000 @@ -1,8 +1,17 @@ -/* - * metal_common.m - * RetroArch_Metal +/* RetroArch - A frontend for libretro. + * Copyright (C) 2018-2019 - Stuart Carnie + * Copyright (C) 2011-2017 - Daniel De Matteis * - * Created by Stuart Carnie on 5/14/18. + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . */ #import @@ -39,6 +48,24 @@ x = (__bridge __typeof__(x))(__bridge_retained void *)((NSObject *)__y); \ } +@implementation MetalView + +- (void)keyDown:(NSEvent*)theEvent +{ +} + +/* Stop the annoying sound when pressing a key. */ +- (BOOL)acceptsFirstResponder +{ + return YES; +} + +- (BOOL)isFlipped +{ + return YES; +} +@end + #pragma mark - private categories @interface FrameView() diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/sdl2_common.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/sdl2_common.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/sdl2_common.c 1970-01-01 00:00:00.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/sdl2_common.c 2019-09-22 15:17:52.000000000 +0000 @@ -0,0 +1,80 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2019 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + +#include + +#include "sdl2_common.h" +#include "../../retroarch.h" + +#ifdef HAVE_SDL2 +#include "SDL.h" +#include "SDL_syswm.h" + +void sdl2_set_handles(void *data, enum rarch_display_type display_type) +{ + /* SysWMinfo headers are broken on OSX. */ + SDL_SysWMinfo info; + SDL_Window *window = (SDL_Window*)data; + SDL_VERSION(&info.version); + + if (SDL_GetWindowWMInfo(window, &info) != 1) + return; + + video_driver_display_userdata_set((uintptr_t)window); + + switch (display_type) + { + case RARCH_DISPLAY_WIN32: +#if defined(_WIN32) + video_driver_display_type_set(RARCH_DISPLAY_WIN32); + video_driver_display_set(0); + video_driver_window_set((uintptr_t)info.info.win.window); +#endif + break; + case RARCH_DISPLAY_X11: +#if defined(HAVE_X11) + video_driver_display_type_set(RARCH_DISPLAY_X11); + video_driver_display_set((uintptr_t)info.info.x11.display); + video_driver_window_set((uintptr_t)info.info.x11.window); +#endif + break; + case RARCH_DISPLAY_OSX: +#ifdef HAVE_COCOA + video_driver_display_type_set(RARCH_DISPLAY_OSX); + video_driver_display_set(0); + video_driver_window_set((uintptr_t)info.info.cocoa.window); +#endif + break; + case RARCH_DISPLAY_WAYLAND: +#ifdef HAVE_WAYLAND + video_driver_display_type_set(RARCH_DISPLAY_WAYLAND); + video_driver_display_set((uintptr_t)info.info.wl.display); + video_driver_window_set((uintptr_t)info.info.wl.surface); +#endif + break; + default: + case RARCH_DISPLAY_NONE: + break; + } +} + +#endif diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/sdl2_common.h retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/sdl2_common.h --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/sdl2_common.h 1970-01-01 00:00:00.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/sdl2_common.h 2019-09-22 15:17:52.000000000 +0000 @@ -0,0 +1,27 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2019 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef SDL2_COMMON_H__ +#define SDL2_COMMON_H__ + +#include +#include + +#include "../video_defines.h" + +void sdl2_set_handles(void *data, enum rarch_display_type + display_type); + +#endif diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/win32_common.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/win32_common.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/win32_common.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/win32_common.c 2019-09-22 15:17:52.000000000 +0000 @@ -992,6 +992,7 @@ video_driver_display_type_set(RARCH_DISPLAY_WIN32); video_driver_display_set(0); + video_driver_display_userdata_set((uintptr_t)&main_window); video_driver_window_set((uintptr_t)main_window.hwnd); #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 /* 2K */ diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/x11_common.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/x11_common.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/common/x11_common.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/common/x11_common.c 2019-09-22 15:17:52.000000000 +0000 @@ -687,7 +687,9 @@ video_driver_get_window_title(title, sizeof(title)); if (title[0]) - XStoreName(g_x11_dpy, g_x11_win, title); + XChangeProperty(g_x11_dpy, g_x11_win, XA_WM_NAME, XA_STRING, + 8, PropModeReplace, (const unsigned char*)title, + strlen(title)); } bool x11_input_ctx_new(bool true_full) diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers/gl.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers/gl.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers/gl.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers/gl.c 2019-09-22 15:17:52.000000000 +0000 @@ -3064,8 +3064,9 @@ font_driver_render_msg(video_info, NULL, msg, NULL); } - video_info->cb_update_window_title( - video_info->context_data, video_info); + if (video_info->cb_update_window_title) + video_info->cb_update_window_title( + video_info->context_data, video_info); /* Reset state which could easily mess up libretro core. */ if (gl->hw_render_fbo_init) diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers/sdl2_gfx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers/sdl2_gfx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers/sdl2_gfx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers/sdl2_gfx.c 2019-09-22 15:17:52.000000000 +0000 @@ -36,6 +36,10 @@ #include "SDL.h" #include "SDL_syswm.h" +#ifdef HAVE_SDL2 +#include "../common/sdl2_common.h" +#endif + #include "../font_driver.h" #include "../../configuration.h" @@ -211,28 +215,6 @@ } } -static void sdl2_gfx_set_handles(sdl2_video_t *vid) -{ - /* SysWMinfo headers are broken on OSX. */ -#if defined(_WIN32) || defined(HAVE_X11) - SDL_SysWMinfo info; - SDL_VERSION(&info.version); - - if (SDL_GetWindowWMInfo(vid->window, &info) != 1) - return; - -#if defined(_WIN32) - video_driver_display_type_set(RARCH_DISPLAY_WIN32); - video_driver_display_set(0); - video_driver_window_set((uintptr_t)info.info.win.window); -#elif defined(HAVE_X11) - video_driver_display_type_set(RARCH_DISPLAY_X11); - video_driver_display_set((uintptr_t)info.info.x11.display); - video_driver_window_set((uintptr_t)info.info.x11.window); -#endif -#endif -} - static void sdl2_init_renderer(sdl2_video_t *vid) { unsigned flags = SDL_RENDERER_ACCELERATED; @@ -448,7 +430,13 @@ sdl2_init_renderer(vid); sdl2_init_font(vid, settings->paths.path_font, settings->floats.video_font_size); - sdl2_gfx_set_handles(vid); +#if defined(_WIN32) + sdl2_set_handles(vid->window, RARCH_DISPLAY_WIN32); +#elif defined(HAVE_X11) + sdl2_set_handles(vid->window, RARCH_DISPLAY_X11); +#elif defined(HAVE_COCOA) + sdl2_set_handles(vid->window, RARCH_DISPLAY_OSX); +#endif sdl_refresh_viewport(vid); @@ -522,7 +510,7 @@ video_driver_get_window_title(title, sizeof(title)); if (title[0]) - SDL_SetWindowTitle(vid->window, title); + SDL_SetWindowTitle((SDL_Window*)video_driver_display_userdata_get(), title); return true; } diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/android_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/android_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/android_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/android_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -615,10 +615,6 @@ (void)flags; } -static void android_gfx_update_window_title(void *data, void *data2) -{ -} - const gfx_ctx_driver_t gfx_ctx_android = { android_gfx_ctx_init, android_gfx_ctx_destroy, @@ -633,7 +629,7 @@ NULL, /* get_video_output_next */ android_gfx_ctx_get_metrics, NULL, - android_gfx_update_window_title, + NULL, /* update_title */ android_gfx_ctx_check_window, android_gfx_ctx_set_resize, android_gfx_ctx_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/cocoa_gl_ctx.m retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/cocoa_gl_ctx.m --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/cocoa_gl_ctx.m 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/cocoa_gl_ctx.m 2019-09-22 15:17:52.000000000 +0000 @@ -44,6 +44,9 @@ #ifdef HAVE_VULKAN #include "../common/vulkan_common.h" #endif +#ifdef HAVE_METAL +#include "../common/metal_common.h" +#endif typedef struct cocoa_ctx_data { @@ -90,8 +93,26 @@ @end #endif -/* forward declaration */ -void *nsview_get_ptr(void); +static CocoaView* g_instance; + +void *nsview_get_ptr(void) +{ +#if defined(HAVE_COCOA) + video_driver_display_type_set(RARCH_DISPLAY_OSX); + video_driver_display_set(0); + video_driver_display_userdata_set((uintptr_t)g_instance); +#elif defined(HAVE_COCOA_METAL) + video_driver_display_type_set(RARCH_DISPLAY_OSX); + video_driver_display_set(0); + video_driver_display_userdata_set((uintptr_t)g_instance); +#endif + return (BRIDGE void *)g_instance; +} + +void nsview_set_ptr(CocoaView *p) +{ + g_instance = p; +} #if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL) static NSOpenGLPixelFormat* g_format; @@ -228,7 +249,7 @@ #if defined(HAVE_COCOA_METAL) NSView *g_view = apple_platform.renderView; #elif defined(HAVE_COCOA) - CocoaView *g_view = (CocoaView*)nsview_get_ptr(); + CocoaView *g_view = g_instance; #endif backing_scale_def = (float)get_from_selector ([[g_view window] class], [g_view window], selector, &ret); @@ -348,15 +369,8 @@ #if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL) static void cocoagl_gfx_ctx_update_title(void *data, void *data2) { - ui_window_cocoa_t view; const ui_window_t *window = ui_companion_driver_get_window_ptr(); - -#if defined(HAVE_COCOA) - view.data = (CocoaView*)nsview_get_ptr(); -#elif defined(HAVE_COCOA_METAL) - view.data = (BRIDGE void *)apple_platform.renderView; -#endif - + if (window) { char title[128]; @@ -366,7 +380,7 @@ video_driver_get_window_title(title, sizeof(title)); if (title[0]) - window->set_title(&view, title); + window->set_title((void*)video_driver_display_userdata_get(), title); } } #endif @@ -471,7 +485,7 @@ #if defined(HAVE_COCOA_METAL) NSView *g_view = apple_platform.renderView; #elif defined(HAVE_COCOA) - CocoaView *g_view = (CocoaView*)nsview_get_ptr(); + CocoaView *g_view = g_instance; #endif CGRect cgrect = NSRectToCGRect([g_view frame]); #if MAC_OS_X_VERSION_10_7 diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/drm_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/drm_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/drm_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/drm_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -928,10 +928,6 @@ drm->core_hw_context_enable = true; } -void gfx_ctx_drm_update_window_title(void *data, void *data2) -{ -} - const gfx_ctx_driver_t gfx_ctx_drm = { gfx_ctx_drm_init, gfx_ctx_drm_destroy, @@ -946,7 +942,7 @@ NULL, /* get_video_output_next */ NULL, /* get_metrics */ NULL, - gfx_ctx_drm_update_window_title, + NULL, /* update_title */ gfx_ctx_drm_check_window, NULL, /* set_resize */ gfx_ctx_drm_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/fpga_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/fpga_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/fpga_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/fpga_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -50,7 +50,7 @@ return false; } -static void gfx_ctx_fpga_update_window_title(void *data, void *data2) +static void gfx_ctx_fpga_update_title(void *data, void *data2) { char title[128]; @@ -176,7 +176,7 @@ NULL, /* get_video_output_next */ gfx_ctx_fpga_get_metrics, NULL, - gfx_ctx_fpga_update_window_title, + gfx_ctx_fpga_update_title, gfx_ctx_fpga_check_window, gfx_ctx_fpga_set_resize, gfx_ctx_fpga_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/gdi_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/gdi_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/gdi_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/gdi_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -68,10 +68,10 @@ return false; } -static void gfx_ctx_gdi_update_window_title(void *data, void *data2) +static void gfx_ctx_gdi_update_title(void *data, void *data2) { video_frame_info_t* video_info = (video_frame_info_t*)data2; - const ui_window_t *window = ui_companion_driver_get_window_ptr(); + const ui_window_t *window = ui_companion_driver_get_window_ptr(); char title[128]; title[0] = '\0'; @@ -288,7 +288,7 @@ NULL, /* get_video_output_next */ win32_get_metrics, NULL, - gfx_ctx_gdi_update_window_title, + gfx_ctx_gdi_update_title, gfx_ctx_gdi_check_window, gfx_ctx_gdi_set_resize, gfx_ctx_gdi_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/khr_display_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/khr_display_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/khr_display_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/khr_display_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -276,10 +276,6 @@ return &khr->vk.context; } -static void gfx_ctx_khr_display_update_window_title(void *data, void *data2) -{ -} - const gfx_ctx_driver_t gfx_ctx_khr_display = { gfx_ctx_khr_display_init, gfx_ctx_khr_display_destroy, @@ -294,7 +290,7 @@ NULL, /* get_video_output_next */ NULL, /* get_metrics */ NULL, - gfx_ctx_khr_display_update_window_title, + NULL, /* update_title */ gfx_ctx_khr_display_check_window, gfx_ctx_khr_display_set_resize, gfx_ctx_khr_display_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/mali_fbdev_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/mali_fbdev_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/mali_fbdev_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/mali_fbdev_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -305,10 +305,6 @@ return mali->refresh_rate; } -static void gfx_ctx_mali_fbdev_update_window_title(void *data, void *data2) -{ -} - const gfx_ctx_driver_t gfx_ctx_mali_fbdev = { gfx_ctx_mali_fbdev_init, gfx_ctx_mali_fbdev_destroy, @@ -323,7 +319,7 @@ NULL, /* get_video_output_next */ NULL, /* get_metrics */ NULL, - gfx_ctx_mali_fbdev_update_window_title, + NULL, /* update_title */ gfx_ctx_mali_fbdev_check_window, NULL, /* set_resize */ gfx_ctx_mali_fbdev_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/orbis_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/orbis_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/orbis_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/orbis_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -287,10 +287,6 @@ return ctx_orbis->refresh_rate; } -static void orbis_ctx_update_window_title(void *data, void *data2) -{ -} - const gfx_ctx_driver_t orbis_ctx = { orbis_ctx_init, orbis_ctx_destroy, @@ -305,7 +301,7 @@ NULL, /* get_video_output_next */ NULL, /* get_metrics */ NULL, - orbis_ctx_update_window_title, + NULL, /* update_title */ orbis_ctx_check_window, NULL, /* set_resize */ orbis_ctx_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/ps3_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/ps3_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/ps3_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/ps3_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -409,10 +409,6 @@ (void)data; } -static void gfx_ctx_ps3_update_window_title(void *data, void *data2) -{ -} - const gfx_ctx_driver_t gfx_ctx_ps3 = { gfx_ctx_ps3_init, gfx_ctx_ps3_destroy, @@ -427,7 +423,7 @@ gfx_ctx_ps3_get_video_output_next, NULL, /* get_metrics */ NULL, - gfx_ctx_ps3_update_window_title, + NULL, /* update_title */ gfx_ctx_ps3_check_window, NULL, /* set_resize */ gfx_ctx_ps3_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/sdl_gl_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/sdl_gl_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/sdl_gl_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/sdl_gl_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -28,6 +28,10 @@ #include "SDL.h" +#ifdef HAVE_SDL2 +#include "../common/sdl2_common.h" +#endif + static enum gfx_ctx_api sdl_api = GFX_CTX_OPENGL_API; static unsigned g_major = 2; static unsigned g_minor = 1; @@ -214,6 +218,14 @@ goto error; #ifdef HAVE_SDL2 +#if defined(_WIN32) + sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_WIN32); +#elif defined(HAVE_X11) + sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_X11); +#elif defined(HAVE_COCOA) + sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_OSX); +#endif + if (sdl->g_ctx) video_driver_set_video_cache_context_ack(); else @@ -276,20 +288,18 @@ static void sdl_ctx_update_title(void *data, void *data2) { char title[128]; - title[0] = '\0'; video_driver_get_window_title(title, sizeof(title)); + if (title[0]) + { #ifdef HAVE_SDL2 - gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data; - - if (sdl && title[0]) - SDL_SetWindowTitle(sdl->g_win, title); + SDL_SetWindowTitle((SDL_Window*)video_driver_display_userdata_get(), title); #else - if (title[0]) SDL_WM_SetCaption(title, NULL); #endif + } } static void sdl_ctx_check_window(void *data, bool *quit, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/sixel_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/sixel_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/sixel_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/sixel_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -48,10 +48,6 @@ return false; } -static void gfx_ctx_sixel_update_window_title(void *data, void *data2) -{ -} - static void gfx_ctx_sixel_get_video_size(void *data, unsigned *width, unsigned *height) { @@ -170,7 +166,7 @@ NULL, /* get_video_output_next */ gfx_ctx_sixel_get_metrics, NULL, - gfx_ctx_sixel_update_window_title, + NULL, /* update_title */ gfx_ctx_sixel_check_window, gfx_ctx_sixel_set_resize, gfx_ctx_sixel_has_focus, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/wayland_ctx.c retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/wayland_ctx.c --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/drivers_context/wayland_ctx.c 2019-09-21 15:17:55.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/drivers_context/wayland_ctx.c 2019-09-22 15:17:52.000000000 +0000 @@ -1158,23 +1158,19 @@ if (wl && title[0]) { - if (wl->xdg_toplevel) + if (wl->xdg_toplevel || wl->zxdg_toplevel) { - if (wl->deco) + if (wl->deco) { - zxdg_toplevel_decoration_v1_set_mode(wl->deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); - } - xdg_toplevel_set_title(wl->xdg_toplevel, title); - } - else if (wl->zxdg_toplevel) - { - if (wl->deco) - { - zxdg_toplevel_decoration_v1_set_mode(wl->deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); - } - zxdg_toplevel_v6_set_title(wl->zxdg_toplevel, title); - } - } + zxdg_toplevel_decoration_v1_set_mode(wl->deco, + ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + } + } + if (wl->xdg_toplevel) + xdg_toplevel_set_title(wl->xdg_toplevel, title); + else if (wl->zxdg_toplevel) + zxdg_toplevel_v6_set_title(wl->zxdg_toplevel, title); + } } static bool gfx_ctx_wl_get_metrics(void *data, diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/gfx/video_defines.h retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/video_defines.h --- retroarch-1.7.8.4-r201909211518-302e2fd/gfx/video_defines.h 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/gfx/video_defines.h 2019-09-22 15:17:52.000000000 +0000 @@ -76,6 +76,7 @@ RARCH_DISPLAY_X11, /* video_display => N/A, video_window => HWND */ RARCH_DISPLAY_WIN32, + RARCH_DISPLAY_WAYLAND, RARCH_DISPLAY_OSX }; diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/griffin/griffin.c retroarch-1.7.8.4-r201909221517-5f87fa1/griffin/griffin.c --- retroarch-1.7.8.4-r201909211518-302e2fd/griffin/griffin.c 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/griffin/griffin.c 2019-09-22 15:17:52.000000000 +0000 @@ -406,6 +406,7 @@ #ifdef HAVE_SDL2 #include "../gfx/drivers/sdl2_gfx.c" +#include "../gfx/common/sdl2_common.c" #endif #ifdef HAVE_VG diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/input/drivers_joypad/gx_joypad.c retroarch-1.7.8.4-r201909221517-5f87fa1/input/drivers_joypad/gx_joypad.c --- retroarch-1.7.8.4-r201909211518-302e2fd/input/drivers_joypad/gx_joypad.c 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/input/drivers_joypad/gx_joypad.c 2019-09-22 15:17:52.000000000 +0000 @@ -44,8 +44,24 @@ #ifdef HW_RVL #define MAX_MOUSEBUTTONS 6 -static const uint32_t gx_mousemask[MAX_MOUSEBUTTONS] = {WPAD_BUTTON_B, WPAD_BUTTON_A, WPAD_BUTTON_1, WPAD_BUTTON_2, - WPAD_BUTTON_PLUS, WPAD_BUTTON_MINUS}; +static const uint32_t gx_mousemask[MAX_MOUSEBUTTONS] = +{ + WPAD_BUTTON_B, + WPAD_BUTTON_A, + WPAD_BUTTON_1, + WPAD_BUTTON_2, + WPAD_BUTTON_PLUS, + WPAD_BUTTON_MINUS +}; + +struct gx_mousedata +{ + int32_t x, y; + uint32_t mouse_button; + bool valid; +}; + +static struct gx_mousedata gx_mouse[2]; #endif enum @@ -109,15 +125,6 @@ static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; static bool g_menu = false; -struct gx_mousedata -{ - int32_t x, y; - uint32_t mouse_button; - bool valid; -}; - -static struct gx_mousedata gx_mouse[2]; - static bool gx_joypad_query_pad(unsigned pad); #ifdef HW_RVL @@ -135,7 +142,8 @@ } #ifdef HW_RVL -static inline void gx_mouse_info(uint32_t joybutton, unsigned port) { +static inline void gx_mouse_info(uint32_t joybutton, unsigned port) +{ uint8_t i; ir_t ir; @@ -151,12 +159,11 @@ { gx_mouse[port].valid = false; } - + /* reset button state */ gx_mouse[port].mouse_button = 0; - for (i = 0; i < MAX_MOUSEBUTTONS; i++) { + for (i = 0; i < MAX_MOUSEBUTTONS; i++) gx_mouse[port].mouse_button |= (joybutton & gx_mousemask[i]) ? (1 << i) : 0; - } /* Small adjustment to match the RA buttons */ gx_mouse[port].mouse_button = gx_mouse[port].mouse_button << 2; @@ -169,8 +176,8 @@ void gx_joypad_read_mouse(unsigned port, int *irx, int *iry, uint32_t *button) { - *irx = gx_mouse[port].x; - *iry = gx_mouse[port].y; + *irx = gx_mouse[port].x; + *iry = gx_mouse[port].y; *button = gx_mouse[port].mouse_button; } #endif @@ -470,10 +477,8 @@ /* Mouse & Lightgun: Retrieve IR data */ if (ptype == WPAD_EXP_NONE) - { if (port == WPAD_CHAN_0 || port == WPAD_CHAN_1) gx_mouse_info(wpaddata->btns_h, port); - } *state_cur |= (down & WPAD_BUTTON_A) ? (UINT64_C(1) << GX_WIIMOTE_A) : 0; *state_cur |= (down & WPAD_BUTTON_B) ? (UINT64_C(1) << GX_WIIMOTE_B) : 0; diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/formats/cdfs/cdfs.c retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/formats/cdfs/cdfs.c --- retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/formats/cdfs/cdfs.c 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/formats/cdfs/cdfs.c 2019-09-22 15:17:52.000000000 +0000 @@ -344,8 +344,6 @@ while (*cue && *cue != '\n') ++cue; - if (cue == line) - continue; if (*cue) *cue++ = '\0'; diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/formats/png/rpng_encode.c retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/formats/png/rpng_encode.c --- retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/formats/png/rpng_encode.c 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/formats/png/rpng_encode.c 2019-09-22 15:17:52.000000000 +0000 @@ -24,8 +24,9 @@ #include #include +#include #include -#include +#include #include #include "rpng_internal.h" @@ -37,6 +38,9 @@ goto end; \ } while(0) +double DEFLATE_PADDING = 1.1; +int PNG_ROUGH_HEADER = 100; + static void dword_write_be(uint8_t *buf, uint32_t val) { *buf++ = (uint8_t)(val >> 24); @@ -45,16 +49,16 @@ *buf++ = (uint8_t)(val >> 0); } -static bool png_write_crc(RFILE *file, const uint8_t *data, size_t size) +static bool png_write_crc_string(intfstream_t *intf_s, const uint8_t *data, size_t size) { uint8_t crc_raw[4] = {0}; uint32_t crc = encoding_crc32(0, data, size); dword_write_be(crc_raw, crc); - return filestream_write(file, crc_raw, sizeof(crc_raw)) == sizeof(crc_raw); + return intfstream_write(intf_s, crc_raw, sizeof(crc_raw)) == sizeof(crc_raw); } -static bool png_write_ihdr(RFILE *file, const struct png_ihdr *ihdr) +static bool png_write_ihdr_string(intfstream_t *intf_s, const struct png_ihdr *ihdr) { uint8_t ihdr_raw[21]; @@ -83,32 +87,32 @@ dword_write_be(ihdr_raw + 0, sizeof(ihdr_raw) - 8); dword_write_be(ihdr_raw + 8, ihdr->width); dword_write_be(ihdr_raw + 12, ihdr->height); - if (filestream_write(file, ihdr_raw, sizeof(ihdr_raw)) != sizeof(ihdr_raw)) + if (intfstream_write(intf_s, ihdr_raw, sizeof(ihdr_raw)) != sizeof(ihdr_raw)) return false; - return png_write_crc(file, ihdr_raw + sizeof(uint32_t), + return png_write_crc_string(intf_s, ihdr_raw + sizeof(uint32_t), sizeof(ihdr_raw) - sizeof(uint32_t)); } -static bool png_write_idat(RFILE *file, const uint8_t *data, size_t size) +static bool png_write_idat_string(intfstream_t* intf_s, const uint8_t *data, size_t size) { - if (filestream_write(file, data, size) != (ssize_t)size) + if (intfstream_write(intf_s, data, size) != (ssize_t)size) return false; - return png_write_crc(file, data + sizeof(uint32_t), size - sizeof(uint32_t)); + return png_write_crc_string(intf_s, data + sizeof(uint32_t), size - sizeof(uint32_t)); } -static bool png_write_iend(RFILE *file) +static bool png_write_iend_string(intfstream_t* intf_s) { const uint8_t data[] = { 0, 0, 0, 0, 'I', 'E', 'N', 'D', }; - if (filestream_write(file, data, sizeof(data)) != sizeof(data)) + if (intfstream_write(intf_s, data, sizeof(data)) != sizeof(data)) return false; - return png_write_crc(file, data + sizeof(uint32_t), + return png_write_crc_string(intf_s, data + sizeof(uint32_t), sizeof(data) - sizeof(uint32_t)); } @@ -199,14 +203,12 @@ return count_sad(target, width); } -static bool rpng_save_image(const char *path, - const uint8_t *data, - unsigned width, unsigned height, unsigned pitch, unsigned bpp) +bool rpng_save_image_stream(const uint8_t *data, intfstream_t* intf_s, + unsigned width, unsigned height, signed pitch, unsigned bpp) { unsigned h; - bool ret = true; struct png_ihdr ihdr = {0}; - + bool ret = true; const struct trans_stream_backend *stream_backend = NULL; size_t encode_buf_size = 0; uint8_t *encode_buf = NULL; @@ -221,26 +223,24 @@ void *stream = NULL; uint32_t total_in = 0; uint32_t total_out = 0; - RFILE *file = filestream_open(path, - RETRO_VFS_FILE_ACCESS_WRITE, - RETRO_VFS_FILE_ACCESS_HINT_NONE); - if (!file) + + if (!intf_s) GOTO_END_ERROR(); stream_backend = trans_stream_get_zlib_deflate_backend(); - if (filestream_write(file, png_magic, sizeof(png_magic)) != sizeof(png_magic)) + if (intfstream_write(intf_s, png_magic, sizeof(png_magic)) != sizeof(png_magic)) GOTO_END_ERROR(); ihdr.width = width; ihdr.height = height; ihdr.depth = 8; ihdr.color_type = bpp == sizeof(uint32_t) ? 6 : 2; /* RGBA or RGB */ - if (!png_write_ihdr(file, &ihdr)) + if (!png_write_ihdr_string(intf_s, &ihdr)) GOTO_END_ERROR(); encode_buf_size = (width * bpp + 1) * height; - encode_buf = (uint8_t*)malloc(encode_buf_size); + encode_buf = (uint8_t*)malloc(encode_buf_size); if (!encode_buf) GOTO_END_ERROR(); @@ -339,15 +339,12 @@ memcpy(deflate_buf + 4, "IDAT", 4); dword_write_be(deflate_buf + 0, ((uint32_t)total_out)); - if (!png_write_idat(file, deflate_buf, ((size_t)total_out + 8))) + if (!png_write_idat_string(intf_s, deflate_buf, ((size_t)total_out + 8))) GOTO_END_ERROR(); - if (!png_write_iend(file)) + if (!png_write_iend_string(intf_s)) GOTO_END_ERROR(); - end: - if (file) - filestream_close(file); free(encode_buf); free(deflate_buf); free(rgba_line); @@ -371,13 +368,78 @@ bool rpng_save_image_argb(const char *path, const uint32_t *data, unsigned width, unsigned height, unsigned pitch) { - return rpng_save_image(path, (const uint8_t*)data, - width, height, pitch, sizeof(uint32_t)); + bool ret = false; + intfstream_t* intf_s = NULL; + + intf_s = intfstream_open_file(path, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE); + + ret = rpng_save_image_stream((const uint8_t*) data, intf_s, + width, height, + (signed) pitch, sizeof(uint32_t)); + intfstream_close(intf_s); + free(intf_s); + return ret; } bool rpng_save_image_bgr24(const char *path, const uint8_t *data, unsigned width, unsigned height, unsigned pitch) { - return rpng_save_image(path, (const uint8_t*)data, - width, height, pitch, 3); + bool ret = false; + intfstream_t* intf_s = NULL; + + intf_s = intfstream_open_file(path, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE); + ret = rpng_save_image_stream(data, intf_s, width, height, + (signed) pitch, 3); + intfstream_close(intf_s); + free(intf_s); + return ret; } + + +uint8_t* rpng_save_image_bgr24_string(const uint8_t *data, + unsigned width, unsigned height, signed pitch, uint64_t* bytes) +{ + bool ret = false; + uint8_t* buf = NULL; + uint8_t* output = NULL; + int buf_length = 0; + intfstream_t* intf_s = NULL; + + buf_length = (int)(width*height*3*DEFLATE_PADDING)+PNG_ROUGH_HEADER; + buf = (uint8_t*)malloc(buf_length*sizeof(uint8_t)); + if (!buf) + GOTO_END_ERROR(); + + intf_s = intfstream_open_writable_memory(buf, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE, + buf_length); + + ret = rpng_save_image_stream((const uint8_t*)data, + intf_s, width, height, pitch, 3); + + *bytes = intfstream_get_ptr(intf_s); + intfstream_rewind(intf_s); + output = (uint8_t*)malloc((*bytes)*sizeof(uint8_t)); + if (!output) + GOTO_END_ERROR(); + intfstream_read(intf_s, output, *bytes); + +end: + if (buf) + free(buf); + if (intf_s) + free(intf_s); + if (ret == false) + { + if (output) + free(output); + return NULL; + } + return output; +} + diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/include/formats/rpng.h retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/include/formats/rpng.h --- retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/include/formats/rpng.h 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/include/formats/rpng.h 2019-09-22 15:17:52.000000000 +0000 @@ -56,6 +56,9 @@ bool rpng_save_image_bgr24(const char *path, const uint8_t *data, unsigned width, unsigned height, unsigned pitch); +uint8_t* rpng_save_image_bgr24_string(const uint8_t *data, + unsigned width, unsigned height, signed pitch, uint64_t *bytes); + RETRO_END_DECLS #endif diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/include/streams/interface_stream.h retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/include/streams/interface_stream.h --- retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/include/streams/interface_stream.h 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/include/streams/interface_stream.h 2019-09-22 15:17:52.000000000 +0000 @@ -74,6 +74,8 @@ int64_t intfstream_write(intfstream_internal_t *intf, const void *s, uint64_t len); +int64_t intfstream_get_ptr(intfstream_internal_t *intf); + char *intfstream_gets(intfstream_internal_t *intf, char *buffer, uint64_t len); @@ -100,6 +102,9 @@ intfstream_t *intfstream_open_memory(void *data, unsigned mode, unsigned hints, uint64_t size); +intfstream_t *intfstream_open_writable_memory(void *data, + unsigned mode, unsigned hints, uint64_t size); + intfstream_t *intfstream_open_chd_track(const char *path, unsigned mode, unsigned hints, int32_t track); diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/include/streams/memory_stream.h retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/include/streams/memory_stream.h --- retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/include/streams/memory_stream.h 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/include/streams/memory_stream.h 2019-09-22 15:17:52.000000000 +0000 @@ -56,6 +56,8 @@ uint64_t memstream_get_last_size(void); +uint64_t memstream_get_ptr(memstream_t *stream); + RETRO_END_DECLS #endif diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/streams/interface_stream.c retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/streams/interface_stream.c --- retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/streams/interface_stream.c 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/streams/interface_stream.c 2019-09-22 15:17:52.000000000 +0000 @@ -298,6 +298,24 @@ return 0; } +int64_t intfstream_get_ptr(intfstream_internal_t* intf) +{ + if (!intf) + return 0; + + switch (intf->type) + { + case INTFSTREAM_FILE: + return -1; + case INTFSTREAM_MEMORY: + return memstream_get_ptr(intf->memory.fp); + case INTFSTREAM_CHD: + return -1; + } + + return 0; +} + char *intfstream_gets(intfstream_internal_t *intf, char *buffer, uint64_t len) { @@ -441,7 +459,35 @@ info.memory.writable = false; fd = (intfstream_t*)intfstream_init(&info); + if (!fd) + return NULL; + + if (!intfstream_open(fd, NULL, mode, hints)) + goto error; + return fd; + +error: + if (fd) + { + intfstream_close(fd); + free(fd); + } + return NULL; +} + +intfstream_t *intfstream_open_writable_memory(void *data, + unsigned mode, unsigned hints, uint64_t size) +{ + intfstream_info_t info; + intfstream_t *fd = NULL; + + info.type = INTFSTREAM_MEMORY; + info.memory.buf.data = (uint8_t*)data; + info.memory.buf.size = size; + info.memory.writable = true; + + fd = (intfstream_t*)intfstream_init(&info); if (!fd) return NULL; @@ -459,6 +505,8 @@ return NULL; } + + intfstream_t *intfstream_open_chd_track(const char *path, unsigned mode, unsigned hints, int32_t track) { diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/streams/memory_stream.c retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/streams/memory_stream.c --- retroarch-1.7.8.4-r201909211518-302e2fd/libretro-common/streams/memory_stream.c 2019-09-21 15:17:56.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/libretro-common/streams/memory_stream.c 2019-09-22 15:17:52.000000000 +0000 @@ -71,7 +71,7 @@ memstream_t *memstream_open(unsigned writing) { - memstream_t *stream; + memstream_t *stream; if (!g_buffer || !g_size) return NULL; @@ -92,6 +92,11 @@ free(stream); } +uint64_t memstream_get_ptr(memstream_t *stream) +{ + return stream->ptr; +} + uint64_t memstream_read(memstream_t *stream, void *data, uint64_t bytes) { uint64_t avail = 0; diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/Makefile.common retroarch-1.7.8.4-r201909221517-5f87fa1/Makefile.common --- retroarch-1.7.8.4-r201909211518-302e2fd/Makefile.common 2019-09-21 15:17:54.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/Makefile.common 2019-09-22 15:17:52.000000000 +0000 @@ -1273,7 +1273,8 @@ ifeq ($(HAVE_SDL2), 1) HAVE_SDL_COMMON = 1 - OBJ += gfx/drivers/sdl2_gfx.o + OBJ += gfx/drivers/sdl2_gfx.o \ + gfx/common/sdl2_common.o DEF_FLAGS += $(SDL2_CFLAGS) LIBS += $(SDL2_LIBS) else ifeq ($(HAVE_SDL), 1) diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/menu/menu_displaylist.c retroarch-1.7.8.4-r201909221517-5f87fa1/menu/menu_displaylist.c --- retroarch-1.7.8.4-r201909211518-302e2fd/menu/menu_displaylist.c 2019-09-21 15:17:57.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/menu/menu_displaylist.c 2019-09-22 15:17:52.000000000 +0000 @@ -579,47 +579,25 @@ char tmp[PATH_MAX_LENGTH]; char tmp2[PATH_MAX_LENGTH]; char tmp3[PATH_MAX_LENGTH]; - uint64_t memory_used = frontend_driver_get_used_memory(); + uint64_t memory_free = frontend_driver_get_free_memory(); uint64_t memory_total = frontend_driver_get_total_memory(); tmp[0] = tmp2[0] = tmp3[0] = '\0'; - if (memory_used != 0 && memory_total != 0) + if (memory_free != 0 && memory_total != 0) { snprintf(tmp, sizeof(tmp), - "%s %s: %" PRIu64 "/%" PRIu64 " B", - msg_hash_to_str(MSG_MEMORY), - msg_hash_to_str(MSG_IN_BYTES), - memory_used, - memory_total - ); - snprintf(tmp2, sizeof(tmp2), "%s %s: %" PRIu64 "/%" PRIu64 " MB", msg_hash_to_str(MSG_MEMORY), msg_hash_to_str(MSG_IN_MEGABYTES), - BYTES_TO_MB(memory_used), + BYTES_TO_MB(memory_free), BYTES_TO_MB(memory_total) ); - snprintf(tmp3, sizeof(tmp3), - "%s %s: %" PRIu64 "/%" PRIu64 " GB", - msg_hash_to_str(MSG_MEMORY), - msg_hash_to_str(MSG_IN_GIGABYTES), - BYTES_TO_GB(memory_used), - BYTES_TO_GB(memory_total) - ); if (menu_entries_append_enum(info->list, tmp, "", MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, 0, 0)) count++; - if (menu_entries_append_enum(info->list, tmp2, "", - MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, - MENU_SETTINGS_CORE_INFO_NONE, 0, 0)) - count++; - if (menu_entries_append_enum(info->list, tmp3, "", - MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, - MENU_SETTINGS_CORE_INFO_NONE, 0, 0)) - count++; } } diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/menu/widgets/menu_widgets.c retroarch-1.7.8.4-r201909221517-5f87fa1/menu/widgets/menu_widgets.c --- retroarch-1.7.8.4-r201909211518-302e2fd/menu/widgets/menu_widgets.c 2019-09-21 15:17:57.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/menu/widgets/menu_widgets.c 2019-09-22 15:17:52.000000000 +0000 @@ -1620,7 +1620,10 @@ } /* FPS Counter */ - if (video_info->fps_show || video_info->framecount_show) + if ( video_info->fps_show + || video_info->framecount_show + || video_info->memory_show + ) { const char *text = *video_info->fps_text == '\0' ? "N/A" : video_info->fps_text; diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/retroarch.c retroarch-1.7.8.4-r201909221517-5f87fa1/retroarch.c --- retroarch-1.7.8.4-r201909211518-302e2fd/retroarch.c 2019-09-21 15:17:58.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/retroarch.c 2019-09-22 15:17:53.000000000 +0000 @@ -148,6 +148,7 @@ #ifdef HAVE_TRANSLATE #include #include +#include #include "translation_defines.h" #endif @@ -1318,22 +1319,20 @@ /* VIDEO GLOBAL VARIABLES */ +#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) static void retroarch_set_runtime_shader_preset(const char *arg) { -#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) if (!string_is_empty(arg)) strlcpy(runtime_shader_preset, arg, sizeof(runtime_shader_preset)); else runtime_shader_preset[0] = '\0'; -#endif } static void retroarch_unset_runtime_shader_preset(void) { -#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) runtime_shader_preset[0] = '\0'; -#endif } +#endif #define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024) @@ -1436,6 +1435,7 @@ * Used by e.g. input drivers which bind to a window. * Drivers are responsible for setting these if an input driver * could potentially make use of this. */ +static uintptr_t video_driver_display_userdata = 0; static uintptr_t video_driver_display = 0; static uintptr_t video_driver_window = 0; @@ -2706,7 +2706,7 @@ unsigned image_width, image_height; char* body_copy = NULL; uint8_t* raw_output_data = NULL; - char* raw_bmp_data = NULL; + char* raw_image_file_data = NULL; struct scaler_ctx* scaler = NULL; bool is_paused = runloop_paused; http_transfer_data_t *data = (http_transfer_data_t*)task_data; @@ -2714,8 +2714,10 @@ int new_image_size = 0; int new_sound_size = 0; const void* dummy_data = NULL; - void* raw_image_data = NULL; + void* raw_image_data = NULL; + void* raw_image_data_alpha = NULL; void* raw_sound_data = NULL; + int retval = 0; settings_t *settings = configuration_settings; int i = 0; @@ -2736,7 +2738,6 @@ data->data[data->len] = '\0'; /* Parse JSON body for the image and sound data */ - body_copy = strdup(data->data); while (true) @@ -2755,7 +2756,7 @@ *(found_string+i-start-1) = '\0'; if (curr_state == 1)/*image*/ { - raw_bmp_data = (char*)unbase64(found_string, + raw_image_file_data = (char*)unbase64(found_string, strlen(found_string), &new_image_size); curr_state = 0; @@ -2787,31 +2788,91 @@ if (found_string) free(found_string); - if (!raw_bmp_data && !raw_sound_data) + if (!raw_image_file_data && !raw_sound_data) { error = "Invalid JSON body."; goto finish; } - if (raw_bmp_data) + if (raw_image_file_data) { /* Get the video frame dimensions reference */ video_driver_cached_frame_get(&dummy_data, &width, &height, &pitch); - /* Get image data (24 bit), and convert to the emulated pixel format */ - image_width = - ((uint32_t) ((uint8_t)raw_bmp_data[21]) << 24) + - ((uint32_t) ((uint8_t)raw_bmp_data[20]) << 16) + - ((uint32_t) ((uint8_t)raw_bmp_data[19]) << 8) + - ((uint32_t) ((uint8_t)raw_bmp_data[18]) << 0); - - image_height = - ((uint32_t) ((uint8_t)raw_bmp_data[25]) << 24) + - ((uint32_t) ((uint8_t)raw_bmp_data[24]) << 16) + - ((uint32_t) ((uint8_t)raw_bmp_data[23]) << 8) + - ((uint32_t) ((uint8_t)raw_bmp_data[22]) << 0); - raw_image_data = raw_bmp_data + 54 * sizeof(uint8_t); + if (raw_image_file_data[0] == 'B' && raw_image_file_data[1] == 'M') + { + /* This is a BMP file coming back. */ + /* Get image data (24 bit), and convert to the emulated pixel format */ + image_width = + ((uint32_t) ((uint8_t)raw_image_file_data[21]) << 24) + + ((uint32_t) ((uint8_t)raw_image_file_data[20]) << 16) + + ((uint32_t) ((uint8_t)raw_image_file_data[19]) << 8) + + ((uint32_t) ((uint8_t)raw_image_file_data[18]) << 0); + + image_height = + ((uint32_t) ((uint8_t)raw_image_file_data[25]) << 24) + + ((uint32_t) ((uint8_t)raw_image_file_data[24]) << 16) + + ((uint32_t) ((uint8_t)raw_image_file_data[23]) << 8) + + ((uint32_t) ((uint8_t)raw_image_file_data[22]) << 0); + raw_image_data = raw_image_file_data + 54 * sizeof(uint8_t); + } + else if (raw_image_file_data[1] == 'P' && raw_image_file_data[2] == 'N' && + raw_image_file_data[3] == 'G') + { + /* PNG coming back from the url */ + image_width = + ((uint32_t) ((uint8_t)raw_image_file_data[16])<<24)+ + ((uint32_t) ((uint8_t)raw_image_file_data[17])<<16)+ + ((uint32_t) ((uint8_t)raw_image_file_data[18])<<8)+ + ((uint32_t) ((uint8_t)raw_image_file_data[19])<<0); + image_height = + ((uint32_t) ((uint8_t)raw_image_file_data[20])<<24)+ + ((uint32_t) ((uint8_t)raw_image_file_data[21])<<16)+ + ((uint32_t) ((uint8_t)raw_image_file_data[22])<<8)+ + ((uint32_t) ((uint8_t)raw_image_file_data[23])<<0); + + rpng_t *rpng = rpng_alloc(); + if (!rpng) + { + error = "Can't allocate memory."; + goto finish; + } + rpng_set_buf_ptr(rpng, raw_image_file_data, new_image_size); + rpng_start(rpng); + while (rpng_iterate_image(rpng)); + do + { + retval = rpng_process_image(rpng, &raw_image_data_alpha, new_image_size, &image_width, &image_height); + } + while(retval == IMAGE_PROCESS_NEXT); + + /* Returned output from the png processor is an upside down RGBA + * image, so we have to change that to RGB first. This should + * probably be replaced with a scaler call.*/ + { + int d,tw,th,tc; + d=0; + raw_image_data = malloc(image_width*image_height*3*sizeof(uint8_t)); + for (i=0;iuints.ai_service_mode == 1) - mode_chr = "sound"; + mode_chr = "sound,wav"; snprintf(temp_string, sizeof(temp_string), @@ -3283,8 +3361,6 @@ sizeof(new_ai_service_url)); } - - RARCH_LOG("Server URL: %s\n", new_ai_service_url); task_push_http_post_transfer(new_ai_service_url, json_buffer, true, NULL, handle_translation_cb, NULL); @@ -11285,12 +11361,17 @@ static void retroarch_overlay_init(void) { settings_t *settings = configuration_settings; + +#if 0 #if defined(GEKKO) + /* TODO/FIXME - Wiimpathy - behavior here has changed - can you + * rewrite this? */ /* Avoid a crash at startup or even when toggling overlay in rgui */ - uint64_t memory_used = frontend_driver_get_used_memory(); - if (memory_used > (72 * 1024 * 1024)) + uint64_t memory_free = frontend_driver_get_free_memory(); + if (memory_free > (72 * 1024 * 1024)) return; #endif +#endif retroarch_overlay_deinit(); @@ -18029,6 +18110,7 @@ video_driver_display_type_set(RARCH_DISPLAY_NONE); video_driver_display_set(0); + video_driver_display_userdata_set(0); video_driver_window_set(0); if (!video_driver_pixel_converter_init(RARCH_SCALE_BASE * scale)) @@ -19121,8 +19203,7 @@ /* Get the amount of frames per seconds. */ if (video_driver_frame_count) { - static char title[256]; - settings_t *settings = configuration_settings; + size_t buf_pos = 1; /* set this to 1 to avoid an offset issue */ unsigned write_index = video_driver_frame_time_count++ & (MEASURE_FRAME_TIME_SAMPLES_COUNT - 1); @@ -19130,38 +19211,49 @@ video_driver_frame_time_samples[write_index] = frame_time; fps_time = new_time; - strlcpy(title, video_driver_window_title, sizeof(title)); - if (video_info.fps_show) - { - size_t buf_pos = snprintf( + buf_pos = snprintf( video_info.fps_text, sizeof(video_info.fps_text), "FPS: %6.2f", last_fps); - if (video_info.framecount_show) - { - STRLCAT_CONST_INCR(video_info.fps_text, buf_pos, " || ", sizeof(video_info.fps_text)); - } - } if (video_info.framecount_show) { char frames_text[64]; + if (video_info.fps_text[buf_pos-1] != '\0') + { + STRLCAT_CONST_INCR(video_info.fps_text, buf_pos, " || ", sizeof(video_info.fps_text)); + } snprintf(frames_text, sizeof(frames_text), "%s: %" PRIu64, msg_hash_to_str(MSG_FRAMES), (uint64_t)video_driver_frame_count); - strlcat(video_info.fps_text, frames_text, sizeof(video_info.fps_text)); + buf_pos = strlcat(video_info.fps_text, frames_text, sizeof(video_info.fps_text)); } - if ((video_driver_frame_count % video_info.fps_update_interval) == 0) + if (video_info.memory_show) { - size_t buf_pos; + char mem[128]; + uint64_t mem_bytes_used = frontend_driver_get_free_memory(); + uint64_t mem_bytes_total = frontend_driver_get_total_memory(); + + mem[0] = '\0'; + snprintf( + mem, sizeof(mem), "MEM: %.2f/%.2fMB", mem_bytes_used / (1024.0f * 1024.0f), + mem_bytes_total / (1024.0f * 1024.0f)); + if (video_info.fps_text[buf_pos-1] != '\0') + { + STRLCAT_CONST_INCR(video_info.fps_text, buf_pos, " || ", sizeof(video_info.fps_text)); + } + strlcat(video_info.fps_text, mem, sizeof(video_info.fps_text)); + } + if ((video_driver_frame_count % video_info.fps_update_interval) == 0) + { last_fps = TIME_TO_FPS(curr_time, new_time, video_info.fps_update_interval); buf_pos = strlcpy(video_driver_window_title, - title, sizeof(video_driver_window_title)); + video_driver_title_buf, sizeof(video_driver_window_title)); if (!string_is_empty(video_info.fps_text)) { @@ -19174,19 +19266,6 @@ curr_time = new_time; video_driver_window_title_update = true; } - - if (settings->bools.video_memory_show) - { - char mem[128]; - uint64_t mem_bytes_used = frontend_driver_get_used_memory(); - uint64_t mem_bytes_total = frontend_driver_get_total_memory(); - - mem[0] = '\0'; - snprintf( - mem, sizeof(mem), " || MEM: %.2f/%.2fMB", mem_bytes_used / (1024.0f * 1024.0f), - mem_bytes_total / (1024.0f * 1024.0f)); - strlcat(video_info.fps_text, mem, sizeof(video_info.fps_text)); - } } else { @@ -19328,7 +19407,10 @@ video_driver_frame_count++; /* Display the FPS, with a higher priority. */ - if (video_info.fps_show || video_info.framecount_show) + if ( video_info.fps_show + || video_info.framecount_show + || video_info.memory_show + ) { #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) if (!menu_widgets_inited) @@ -19378,6 +19460,16 @@ return video_driver_display; } +uintptr_t video_driver_display_userdata_get(void) +{ + return video_driver_display_userdata; +} + +void video_driver_display_userdata_set(uintptr_t idx) +{ + video_driver_display_userdata = idx; +} + void video_driver_display_set(uintptr_t idx) { video_driver_display = idx; @@ -19459,6 +19551,7 @@ video_info->hard_sync = settings->bools.video_hard_sync; video_info->hard_sync_frames = settings->uints.video_hard_sync_frames; video_info->fps_show = settings->bools.video_fps_show; + video_info->memory_show = settings->bools.video_memory_show; video_info->fps_update_interval = settings->uints.fps_update_interval; video_info->statistics_show = settings->bools.video_statistics_show; video_info->framecount_show = settings->bools.video_framecount_show; @@ -25596,10 +25689,10 @@ filestream_printf(file, "CPU Cores: %u\n", cpu_features_get_core_amount()); { - uint64_t memory_used = frontend_driver_get_used_memory(); + uint64_t memory_free = frontend_driver_get_free_memory(); uint64_t memory_total = frontend_driver_get_total_memory(); - filestream_printf(file, "Memory: %" PRIu64 "/%" PRIu64 " MB\n", memory_used / 1024 / 1024, memory_total / 1024 / 1024); + filestream_printf(file, "Memory: %" PRIu64 "/%" PRIu64 " MB\n", memory_free / 1024 / 1024, memory_total / 1024 / 1024); } filestream_printf(file, "GPU Device: %s\n", !string_is_empty(video_driver_get_gpu_device_string()) ? @@ -26208,7 +26301,7 @@ fill_pathname_join(log_file_path, settings->paths.log_dir, log_to_file_timestamp ? timestamped_log_file_name - : ".log", + : "retroarch.log", sizeof(log_file_path)); } diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/retroarch.h retroarch-1.7.8.4-r201909221517-5f87fa1/retroarch.h --- retroarch-1.7.8.4-r201909211518-302e2fd/retroarch.h 2019-09-21 15:17:58.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/retroarch.h 2019-09-22 15:17:53.000000000 +0000 @@ -1154,6 +1154,7 @@ bool black_frame_insertion; bool hard_sync; bool fps_show; + bool memory_show; bool statistics_show; bool framecount_show; bool scale_integer; @@ -1785,6 +1786,8 @@ int16_t *res_x, int16_t *res_y, int16_t *res_screen_x, int16_t *res_screen_y); +uintptr_t video_driver_display_userdata_get(void); + uintptr_t video_driver_display_get(void); enum rarch_display_type video_driver_display_type_get(void); @@ -1795,8 +1798,12 @@ void video_driver_display_set(uintptr_t idx); +void video_driver_display_userdata_set(uintptr_t idx); + void video_driver_window_set(uintptr_t idx); +uintptr_t video_driver_window_get(void); + bool video_driver_texture_load(void *data, enum texture_filter_type filter_type, uintptr_t *id); diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/ui/drivers/cocoa/cocoa_common.h retroarch-1.7.8.4-r201909221517-5f87fa1/ui/drivers/cocoa/cocoa_common.h --- retroarch-1.7.8.4-r201909211518-302e2fd/ui/drivers/cocoa/cocoa_common.h 2019-09-21 15:17:58.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/ui/drivers/cocoa/cocoa_common.h 2019-09-22 15:17:53.000000000 +0000 @@ -50,40 +50,6 @@ APPLE_VIEW_TYPE_METAL, } apple_view_type_t; -#ifdef HAVE_METAL -#import - -@interface MetalView : MTKView -@end - -#ifdef HAVE_COCOA_METAL - -@protocol ApplePlatform - -/*! @brief renderView returns the current render view based on the viewType */ -@property (readonly) id renderView; - -/*! @brief isActive returns true if the application has focus */ -@property (readonly) bool hasFocus; - -@property (readwrite) apple_view_type_t viewType; - -/*! @brief setVideoMode adjusts the video display to the specified mode */ -- (void)setVideoMode:(gfx_ctx_mode_t)mode; - -/*! @brief setCursorVisible specifies whether the cursor is visible */ -- (void)setCursorVisible:(bool)v; - -/*! @brief controls whether the screen saver should be disabled and - * the displays should not sleep. - */ -- (bool)setDisableDisplaySleep:(bool)disable; -@end - -extern id apple_platform; -#endif -#endif - #if defined(HAVE_COCOATOUCH) #include @@ -178,4 +144,8 @@ void *get_chosen_screen(void); +void *nsview_get_ptr(void); + +void nsview_set_ptr(CocoaView *ptr); + #endif diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/ui/drivers/cocoa/cocoa_common.m retroarch-1.7.8.4-r201909221517-5f87fa1/ui/drivers/cocoa/cocoa_common.m --- retroarch-1.7.8.4-r201909211518-302e2fd/ui/drivers/cocoa/cocoa_common.m 2019-09-21 15:17:58.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/ui/drivers/cocoa/cocoa_common.m 2019-09-22 15:17:53.000000000 +0000 @@ -29,35 +29,9 @@ #ifdef HAVE_COCOATOUCH #import "GCDWebUploader.h" #import "WebServer.h" - -#endif - -#ifdef HAVE_METAL -@implementation MetalView - -- (void)keyDown:(NSEvent*)theEvent -{ -} - -/* Stop the annoying sound when pressing a key. */ -- (BOOL)acceptsFirstResponder -{ - return YES; -} - -- (BOOL)isFlipped -{ - return YES; -} -@end #endif -static CocoaView* g_instance; -void *nsview_get_ptr(void) -{ - return (BRIDGE void *)g_instance; -} /* forward declarations */ void cocoagl_gfx_ctx_update(void); @@ -87,10 +61,13 @@ + (CocoaView*)get { - if (!g_instance) - g_instance = [CocoaView new]; - - return g_instance; + CocoaView *view = (BRIDGE CocoaView*)nsview_get_ptr(); + if (!view) + { + view = [CocoaView new]; + nsview_set_ptr(view); + } + return view; } - (id)init @@ -117,6 +94,16 @@ [self.view addGestureRecognizer:swipe]; #endif #endif + +#if defined(HAVE_COCOA) + video_driver_display_type_set(RARCH_DISPLAY_OSX); + video_driver_display_set(0); + video_driver_display_userdata_set((uintptr_t)self); +#elif defined(HAVE_COCOA_METAL) + video_driver_display_type_set(RARCH_DISPLAY_OSX); + video_driver_display_set(0); + video_driver_display_userdata_set((uintptr_t)self); +#endif return self; } @@ -325,6 +312,6 @@ }]; #endif } -#endif // end HAVE_COCOATOUCH +#endif @end diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/ui/drivers/cocoa/ui_cocoa_window.m retroarch-1.7.8.4-r201909221517-5f87fa1/ui/drivers/cocoa/ui_cocoa_window.m --- retroarch-1.7.8.4-r201909211518-302e2fd/ui/drivers/cocoa/ui_cocoa_window.m 2019-09-21 15:17:58.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/ui/drivers/cocoa/ui_cocoa_window.m 2019-09-22 15:17:53.000000000 +0000 @@ -59,8 +59,7 @@ static void ui_window_cocoa_set_title(void *data, char *buf) { - ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data; - CocoaView *cocoa_view = (BRIDGE CocoaView*)cocoa->data; + CocoaView *cocoa_view = (BRIDGE CocoaView*)data; const char* const text = buf; /* < Can't access buffer directly in the block */ [[cocoa_view window] setTitle:[NSString stringWithCString:text encoding:NSUTF8StringEncoding]]; } diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/wiiu/main.c retroarch-1.7.8.4-r201909221517-5f87fa1/wiiu/main.c --- retroarch-1.7.8.4-r201909211518-302e2fd/wiiu/main.c 2019-09-21 15:17:59.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/wiiu/main.c 2019-09-22 15:17:53.000000000 +0000 @@ -84,12 +84,7 @@ fsdev_init(); main(argc, argv); fsdev_exit(); - - /* TODO: fix elf2rpl so it doesn't error with "Could not find matching symbol - for relocation" then uncomment this */ -#if 0 __fini(); -#endif memoryRelease(); SYSRelaunchTitle(0, 0); exit(0); diff -Nru retroarch-1.7.8.4-r201909211518-302e2fd/wiiu/wut/elf2rpl/main.cpp retroarch-1.7.8.4-r201909221517-5f87fa1/wiiu/wut/elf2rpl/main.cpp --- retroarch-1.7.8.4-r201909211518-302e2fd/wiiu/wut/elf2rpl/main.cpp 2019-09-21 15:17:59.000000000 +0000 +++ retroarch-1.7.8.4-r201909221517-5f87fa1/wiiu/wut/elf2rpl/main.cpp 2019-09-22 15:17:53.000000000 +0000 @@ -24,47 +24,56 @@ static const uint32_t DataAddress = 0x10000000u; static const uint32_t WiiuLoadAddress = 0xC0000000u; +int verbose = 0; +constexpr int verbose_loaded_sections = 1; +constexpr int verbose_loaded_symbols = 2; +constexpr int verbose_loaded_imports = 2; +constexpr int verbose_loaded_relocations = 3; +constexpr int verbose_pruned_symbols = 2; +constexpr int verbose_convert_relocations = 3; + struct ElfFile { struct Symbol { std::string name; - uint32_t address; - uint32_t size; - elf::SymbolType type; - elf::SymbolBinding binding; - uint32_t outNamePos; + uint32_t address = 0; + uint32_t size = 0; + elf::SymbolType type = elf::STT_NOTYPE; + elf::SymbolBinding binding = elf::STB_LOCAL; + uint32_t outNamePos = 0; + uint32_t refCount = 0; }; struct Relocation { - uint32_t target; - elf::RelocationType type; + uint32_t target = 0; + elf::RelocationType type = elf::R_PPC_NONE; - Symbol *symbol; - uint32_t addend; + Symbol *symbol = nullptr; + uint32_t addend = 0; }; struct DataSection { std::string name; - uint32_t address; - elf::SectionType type; - elf::SectionFlags flags; + uint32_t address = 0; + elf::SectionType type = elf::SHT_NULL; + elf::SectionFlags flags = elf::SectionFlags(0); /* Data used if type == SHT_PROGBITS */ std::vector data; /* Size used if type == SHT_NOBITS */ - uint32_t size; + uint32_t size = 0; }; struct RplImport { - Symbol *trampSymbol; - Symbol *stubSymbol; - uint32_t stubAddr; - uint32_t trampAddr; + Symbol *trampSymbol = nullptr; + Symbol *stubSymbol = nullptr; + uint32_t stubAddr = 0; + uint32_t trampAddr = 0; }; struct RplImportLibrary @@ -73,7 +82,7 @@ std::vector> imports; }; - uint32_t entryPoint; + uint32_t entryPoint = 0; std::vector> dataSections; std::vector> symbols; std::vector> relocations; @@ -268,7 +277,14 @@ data->name = shStrTab + section.header.name; data->address = section.header.addr; data->data = section.data; + data->size = section.header.size; file.dataSections.emplace_back(data); + if (verbose >= verbose_loaded_sections) + { + std::cout << "Data section " << data->name + << std::hex << ": 0x" << data->address + << " - 0x" << data->address + data->size << std::endl; + } } else if (section.header.type == elf::SHT_NOBITS) { auto bss = new ElfFile::DataSection(); bss->type = elf::SHT_NOBITS; @@ -277,6 +293,20 @@ bss->address = section.header.addr; bss->size = section.header.size; file.dataSections.emplace_back(bss); + if (verbose >= verbose_loaded_sections) + { + std::cout << "BSS section " << bss->name + << std::hex << ": 0x" << bss->address << " - 0x" + << bss->address + bss->size << std::endl; + } + } else { + if (verbose >= verbose_loaded_sections) + { + std::string name = shStrTab + section.header.name; + std::cout << "Section type 0x" << section.header.type << ' ' << name + << std::hex << ": 0x" << section.header.addr << " - 0x" + << section.header.addr + section.header.size << std::endl; + } } } @@ -358,6 +388,12 @@ symbol->type = type; symbol->binding = binding; file.symbols.emplace_back(symbol); + + if (verbose >= verbose_loaded_symbols) + { + std::cout << "Symbol " << symbol->name << " 0x" << std::hex << symbol->address + << " 0x" << symbol->size << '\n'; + } } } @@ -377,6 +413,11 @@ auto lib = new ElfFile::RplImportLibrary(); lib->name = getLoaderDataPtr(inSections, rpl.name); + if (verbose >= verbose_loaded_imports) + { + std::cout << "Import library " << lib->name << std::endl; + } + for (auto stubAddr = rpl.stubStart; stubAddr < rpl.stubEnd; stubAddr += 4) { auto import = new ElfFile::RplImport(); import->trampAddr = byte_swap(*getLoaderDataPtr(inSections, stubAddr)); @@ -384,6 +425,7 @@ /* Get the tramp symbol */ import->trampSymbol = findSymbol(file, import->trampAddr); + import->trampSymbol->refCount++; /* Create a new symbol to use for the import */ auto stubSymbol = new ElfFile::Symbol(); @@ -393,11 +435,17 @@ stubSymbol->size = 0; stubSymbol->binding = elf::STB_GLOBAL; stubSymbol->type = elf::STT_FUNC; + stubSymbol->refCount++; file.symbols.emplace_back(stubSymbol); /* Rename tramp symbol */ import->trampSymbol->name += "_tramp"; + if (verbose >= verbose_loaded_symbols) + { + std::cout << "Import trampoline " << import->trampSymbol->name << std::endl; + } + lib->imports.emplace_back(import); } @@ -440,19 +488,47 @@ auto addend = static_cast(rela.addend); + if (verbose >= verbose_loaded_relocations) + { + std::cout << "Relocation #" << std::dec << file.relocations.size() + << " offset 0x" << std::hex << rela.offset + << " addend 0x" << addend; + } + if (auto import = findImport(file, addend)) { relocation->symbol = import->stubSymbol; relocation->addend = 0; + if (verbose >= verbose_loaded_relocations) + { + std::cout << " -> import "; + } } else if (auto symbol = findSymbol(file, addend)) { relocation->symbol = symbol; relocation->addend = 0; + if (verbose >= verbose_loaded_relocations) + { + std::cout << " -> symbol "; + } } else if (addend >= DataAddress && addend < WiiuLoadAddress) { relocation->symbol = findSymbol(file, DataAddress); relocation->addend = addend - DataAddress; + if (verbose >= verbose_loaded_relocations) + { + std::cout << " -> data symbol "; + } } else if (addend >= CodeAddress && addend < DataAddress) { relocation->symbol = findSymbol(file, CodeAddress); relocation->addend = addend - CodeAddress; + if (verbose >= verbose_loaded_relocations) + { + std::cout << "-> code symbol "; + } } else { + if (verbose >= verbose_loaded_relocations) + { + std::cout << "-> not found" << std::endl; + } + /* If we can't find a proper symbol, write the addend in and hope for the best */ auto ptr = getLoaderDataPtr(inSections, rela.offset); *ptr = addend; @@ -461,6 +537,12 @@ continue; } + if (verbose >= verbose_loaded_relocations) + { + std::cout << relocation->symbol->name << std::endl; + } + + relocation->symbol->refCount++; relocation->target = rela.offset; relocation->type = static_cast(type); file.relocations.emplace_back(relocation); @@ -497,29 +579,72 @@ continue; } - if(index == 0) + if (verbose >= verbose_loaded_relocations) + { + std::cout << "Dyn relocation #" << std::dec << file.relocations.size() + << " offset 0x" << std::hex << rela.offset + << " addend 0x" << rela.addend + << " addr 0x" << addr; + } + + // Why index must be == 0? + if (index == 0) { auto addend = static_cast(rela.addend); if (auto import = findImport(file, addend)) { relocation->symbol = import->stubSymbol; relocation->addend = 0; + if (verbose >= verbose_loaded_relocations) + { + std::cout << "-> import "; + } } else if (auto symbol = findSymbol(file, addend)) { relocation->symbol = symbol; relocation->addend = 0; + if (verbose >= verbose_loaded_relocations) + { + std::cout << "-> symbol "; + } } else if (addr >= CodeAddress && addr < DataAddress) { index = 1; relocation->symbol = findSymbol(file, CodeAddress); relocation->addend = rela.addend - CodeAddress; + if (verbose >= verbose_loaded_relocations) + { + std::cout << "-> code symbol "; + } } else if (addr >= DataAddress && addr < WiiuLoadAddress) { index = 2; relocation->symbol = findSymbol(file, DataAddress); relocation->addend = rela.addend - DataAddress; + if (verbose >= verbose_loaded_relocations) + { + std::cout << "-> data symbol"; + } } else { - std::cout << "Unexpected symbol address in .rela.dyn section" << std::endl; + if (verbose >= verbose_loaded_relocations) + { + std::cout << " -> bad" << std::endl; + } + std::cout << "Unexpected relocation symbol address 0x" << std::hex << addr + << " in .rela.dyn section" << std::endl; return false; } } + else + { + // Again, I don't know why we fall here, but relocation is now uninitialized, + // so I can't continue and add it to list + if (verbose >= verbose_loaded_relocations) + { + std::cout << " -> index" << index << std::endl; + } + + std::cout << "Unexpected relocation symbol index " << std::dec << index + << " in .rela.dyn section" << std::endl; + return false; + } switch (type) { case elf::R_PPC_RELATIVE: @@ -535,7 +660,11 @@ /* Scrap any compiler/linker garbage */ if(relocation->target >= CodeAddress && relocation->target < WiiuLoadAddress) + { + relocation->symbol->refCount++; file.relocations.emplace_back(relocation); + } + } } @@ -740,11 +869,17 @@ sectionSymbolItr = addSection(file, outSections, sectionSymbolItr, out); } - /* Prune out unneeded symbols */ + /* Prune out unneeded symbols - but keep those used for relocations! */ for (unsigned i = 0u; i < file.symbols.size(); ++i) { - if (!file.symbols[i]->name.empty() && file.symbols[i]->type == elf::STT_NOTYPE && file.symbols[i]->size == 0) + if (!file.symbols[i]->name.empty() && file.symbols[i]->type == elf::STT_NOTYPE + && file.symbols[i]->size == 0 && file.symbols[i]->refCount == 0) { + if (verbose >= verbose_pruned_symbols) + { + std::cout << "Pruning symbol " << file.symbols[i]->name << std::endl; + } + file.symbols.erase(file.symbols.begin() + i); i--; } @@ -752,8 +887,10 @@ /* NOTICE: FROM NOW ON DO NOT MODIFY mSymbols */ + int number = -1; /* Convert relocations */ for (auto &relocation : file.relocations) { + ++number; OutputSection *targetSection = nullptr; for (auto §ion : outSections) { @@ -780,6 +917,17 @@ }); auto idx = itr - file.symbols.begin(); + bool symbol_found = (itr != file.symbols.end()); + + if ((verbose >= verbose_convert_relocations) || !symbol_found) + { + std::cout << "Converting relocation #" << std::dec << number + << std::hex << " @ 0x" << relocation->target; + } + if ((verbose >= verbose_convert_relocations) && symbol_found) + { + std::cout << "-> symbol index: " << idx << std::endl; + } /* If the symbol doesn't exist but it is within DATA or TEXT, use those symbols + an addend */ if (itr == file.symbols.end()) { @@ -787,11 +935,14 @@ idx = 1; relocation->addend = relocation->symbol->address - CodeAddress; relocation->symbol = findSymbol(file, CodeAddress); + std::cout << "-> no symbol, using TEXT" << std::endl; } else if (relocation->symbol->address >= DataAddress && relocation->symbol->address < WiiuLoadAddress) { idx = 2; relocation->addend = relocation->symbol->address - DataAddress; relocation->symbol = findSymbol(file, DataAddress); + std::cout << "-> no symbol, using DATA" << std::endl; } else { + std::cout << "-> invalid" << std::endl; std::cout << "Could not find matching symbol for relocation" << std::endl; return false; } @@ -1216,15 +1367,31 @@ int main(int argc, char **argv) { - if (argc < 3) + int arg_start = 1; + + while (argc >= arg_start + 1 && argv[arg_start][0] == '-') + { + if (argv[arg_start] == std::string("--")) + { + ++arg_start; + break; + } + else if (argv[arg_start] == std::string("-v")) + { + ++verbose; + ++arg_start; + } + } + + if (argc < arg_start + 1) { std::cout << "Usage: " << argv[0] << " " << std::endl; return -1; } ElfFile elf; - auto src = argv[1]; - auto dst = argv[2]; + auto src = argv[arg_start]; + auto dst = argv[arg_start + 1]; if (!read(elf, src)) return -1;