/* ** core.cpp ** ** This file is part of mkxp. ** ** Copyright (C) 2013 - 2021 Amaryllis Kulla ** ** mkxp 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 Foundation, either version 2 of the License, or ** (at your option) any later version. ** ** mkxp 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 mkxp. If not, see . */ #include #include #include #include #include #ifdef MKXPZ_HAVE_ALIGNED_MALLOC # include #endif #include #include #include #include #include #include "git-hash.h" #include "sandbox.h" #include "binding-sandbox.h" #include "core.h" #include "filesystem.h" #include "gl-fun.h" #include "glstate.h" using namespace mkxp_retro; using namespace mkxp_sandbox; namespace mkxp_retro { retro_log_printf_t log_printf = NULL; retro_video_refresh_t video_refresh; retro_audio_sample_batch_t audio_sample_batch; retro_environment_t environment; retro_input_poll_t input_poll; retro_input_state_t input_state; struct retro_perf_callback perf; retro_hw_render_callback hw_render; } static inline void *malloc_align(size_t alignment, size_t size) { #if defined(MKXPZ_HAVE_POSIX_MEMALIGN) || defined(MKXPZ_BUILD_XCODE) void *mem; return posix_memalign(&mem, alignment, size) ? NULL : mem; #elif defined(MKXPZ_HAVE_ALIGNED_MALLOC) return _aligned_malloc(size, alignment); #elif defined(MKXPZ_HAVE_ALIGNED_ALLOC) return aligned_alloc(alignment, size); #else return std::malloc(size); #endif } static inline void free_align(void *ptr) { #if defined(MKXPZ_HAVE_ALIGNED_MALLOC) _aligned_free(ptr); #else std::free(ptr); #endif } extern const uint8_t mkxp_gmgsx_sf2[]; extern const size_t mkxp_gmgsx_sf2_len; static ALCdevice *al_device = NULL; static ALCcontext *al_context = NULL; static LPALCRENDERSAMPLESSOFT alcRenderSamplesSOFT = NULL; static LPALCLOOPBACKOPENDEVICESOFT alcLoopbackOpenDeviceSOFT = NULL; static int16_t *sound_buf; static bool retro_framebuffer_supported; static bool shared_state_initialized; static void fallback_log(enum retro_log_level level, const char *fmt, ...) { std::va_list va; va_start(va, fmt); std::vfprintf(stderr, fmt, va); va_end(va); } static void fluid_log(int level, char *message, void *data) { switch (level) { case FLUID_PANIC: log_printf(RETRO_LOG_ERROR, "fluidsynth: panic: %s\n", message); break; case FLUID_ERR: log_printf(RETRO_LOG_ERROR, "fluidsynth: error: %s\n", message); break; case FLUID_WARN: log_printf(RETRO_LOG_WARN, "fluidsynth: warning: %s\n", message); break; case FLUID_INFO: log_printf(RETRO_LOG_INFO, "fluidsynth: %s\n", message); break; case FLUID_DBG: log_printf(RETRO_LOG_DEBUG, "fluidsynth: debug: %s\n", message); break; } } static uint32_t *frame_buf; boost::optional mkxp_retro::sandbox; boost::optional