├── .github └── workflows │ ├── crowdin_prep.yml │ └── crowdin_translate.yml ├── .gitignore ├── .gitlab-ci.yml ├── .travis.yml ├── COPYING ├── Makefile ├── Makefile.common ├── Makefile.libretro ├── README.md ├── appveyor.yml ├── changelog ├── common ├── gambatte-array.h └── uncopyable.h ├── crowdin.yml ├── intl ├── .gitignore ├── core_option_regex.py ├── core_option_translation.py ├── crowdin.yaml ├── crowdin_prep.py ├── crowdin_source_upload.py ├── crowdin_translate.py ├── crowdin_translation_download.py ├── download_workflow.py ├── initial_sync.py ├── remove_initial_cycle.py └── upload_workflow.py └── libgambatte ├── include ├── gambatte.h ├── gbint.h └── inputgetter.h ├── libretro-common ├── compat │ ├── compat_posix_string.c │ ├── compat_snprintf.c │ ├── compat_strcasestr.c │ ├── compat_strl.c │ └── fopen_utf8.c ├── encodings │ └── encoding_utf.c ├── file │ ├── file_path.c │ └── file_path_io.c ├── include │ ├── array │ │ └── rhmap.h │ ├── boolean.h │ ├── compat │ │ ├── fopen_utf8.h │ │ ├── msvc.h │ │ ├── msvc │ │ │ └── stdint.h │ │ ├── posix_string.h │ │ ├── strcasestr.h │ │ └── strl.h │ ├── encodings │ │ └── utf.h │ ├── file │ │ └── file_path.h │ ├── libretro.h │ ├── retro_assert.h │ ├── retro_common_api.h │ ├── retro_environment.h │ ├── retro_inline.h │ ├── retro_miscellaneous.h │ ├── streams │ │ ├── file_stream.h │ │ └── file_stream_transforms.h │ ├── string │ │ └── stdstring.h │ ├── time │ │ └── rtime.h │ └── vfs │ │ ├── vfs.h │ │ └── vfs_implementation.h ├── streams │ ├── file_stream.c │ └── file_stream_transforms.c ├── string │ └── stdstring.c ├── time │ └── rtime.c └── vfs │ └── vfs_implementation.c ├── libretro ├── blipper.c ├── blipper.h ├── cc_resampler.h ├── control ├── gambatte_log.c ├── gambatte_log.h ├── gbcpalettes.h ├── jni │ ├── Android.mk │ └── Application.mk ├── libretro.cpp ├── libretro_core_options.h ├── libretro_core_options_intl.h ├── link.T ├── net_serial.cpp └── net_serial.h └── src ├── bootloader.cpp ├── bootloader.h ├── counterdef.h ├── cpu.cpp ├── cpu.h ├── gambatte-memory.cpp ├── gambatte-memory.h ├── gambatte.cpp ├── initstate.cpp ├── initstate.h ├── insertion_sort.h ├── interrupter.cpp ├── interrupter.h ├── interruptrequester.cpp ├── interruptrequester.h ├── mem ├── cartridge.cpp ├── cartridge.h ├── cartridge_libretro.cpp ├── huc3.cpp ├── huc3.h ├── memptrs.cpp ├── memptrs.h ├── rtc.cpp └── rtc.h ├── minkeeper.h ├── savestate.h ├── serial_io.h ├── sound.cpp ├── sound.h ├── sound ├── channel1.cpp ├── channel1.h ├── channel2.cpp ├── channel2.h ├── channel3.cpp ├── channel3.h ├── channel4.cpp ├── channel4.h ├── duty_unit.cpp ├── duty_unit.h ├── envelope_unit.cpp ├── envelope_unit.h ├── length_counter.cpp ├── length_counter.h ├── master_disabler.h ├── sound_unit.h └── static_output_tester.h ├── statesaver.cpp ├── statesaver.h ├── tima.cpp ├── tima.h ├── video.cpp ├── video.h ├── video ├── lcddef.h ├── ly_counter.cpp ├── ly_counter.h ├── lyc_irq.cpp ├── lyc_irq.h ├── m0_irq.h ├── next_m0_time.cpp ├── next_m0_time.h ├── ppu.cpp ├── ppu.h ├── sprite_mapper.cpp └── sprite_mapper.h └── video_libretro.cpp /.github/workflows/crowdin_prep.yml: -------------------------------------------------------------------------------- 1 | # Prepare source texts & upload them to Crowdin 2 | 3 | name: Crowdin Source Texts Upload 4 | 5 | # on change to the English texts 6 | on: 7 | push: 8 | branches: 9 | - master 10 | paths: 11 | - "libgambatte/libretro/libretro_core_options.h" 12 | 13 | jobs: 14 | upload_source_file: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Setup Java JDK 18 | uses: actions/setup-java@v3 19 | with: 20 | java-version: 18 21 | distribution: zulu 22 | 23 | - name: Setup Python 24 | uses: actions/setup-python@v4 25 | with: 26 | python-version: '3.10' 27 | 28 | - name: Checkout 29 | uses: actions/checkout@v3 30 | 31 | - name: Upload Source 32 | shell: bash 33 | env: 34 | CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }} 35 | run: | 36 | python3 intl/upload_workflow.py $CROWDIN_API_KEY "gambatte-libretro" "libgambatte/libretro" 37 | -------------------------------------------------------------------------------- /.github/workflows/crowdin_translate.yml: -------------------------------------------------------------------------------- 1 | # Download translations form Crowdin & Recreate libretro_core_options_intl.h 2 | 3 | name: Crowdin Translation Integration 4 | 5 | on: 6 | schedule: 7 | - cron: '50 10 * * 5' # Friday at 10:50 AM, UTC 8 | 9 | jobs: 10 | create_intl_file: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Setup Java JDK 14 | uses: actions/setup-java@v3 15 | with: 16 | java-version: 18 17 | distribution: zulu 18 | 19 | - name: Setup Python 20 | uses: actions/setup-python@v4 21 | with: 22 | python-version: '3.10' 23 | 24 | - name: Checkout 25 | uses: actions/checkout@v3 26 | with: 27 | persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. 28 | fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. 29 | 30 | - name: Create intl file 31 | shell: bash 32 | env: 33 | CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }} 34 | run: | 35 | python3 intl/download_workflow.py $CROWDIN_API_KEY "gambatte-libretro" "libgambatte/libretro" 36 | 37 | - name: Commit files 38 | run: | 39 | git config --local user.email "github-actions@github.com" 40 | git config --local user.name "github-actions[bot]" 41 | git add intl/download_workflow.py "libgambatte/libretro/libretro_core_options_intl.h" 42 | git commit -m "Fetch translations & Recreate libretro_core_options_intl.h" 43 | 44 | - name: GitHub Push 45 | uses: ad-m/github-push-action@v0.6.0 46 | with: 47 | github_token: ${{ secrets.GITHUB_TOKEN }} 48 | branch: ${{ github.ref }} 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.dll 4 | *.dylib 5 | *.a 6 | *.js 7 | *.bc 8 | .npmignore 9 | package.json 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: generic 2 | os: linux 3 | dist: trusty 4 | sudo: required 5 | addons: 6 | apt: 7 | packages: 8 | - g++-7 9 | sources: 10 | - ubuntu-toolchain-r-test 11 | env: 12 | global: 13 | - CORE=gambatte 14 | - COMPILER_NAME=gcc CXX=g++-7 CC=gcc-7 15 | matrix: 16 | - PLATFORM=3ds 17 | - PLATFORM=linux_x64 18 | - PLATFORM=ngc 19 | - PLATFORM=wii 20 | - PLATFORM=wiiu 21 | before_script: 22 | - pwd 23 | - mkdir -p ~/bin 24 | - ln -s /usr/bin/gcc-7 ~/bin/gcc 25 | - ln -s /usr/bin/g++-7 ~/bin/g++ 26 | - ln -s /usr/bin/cpp-7 ~/bin/cpp 27 | - export PATH=~/bin:$PATH 28 | - ls -l ~/bin 29 | - echo $PATH 30 | - g++-7 --version 31 | - g++ --version 32 | script: 33 | - cd ~/ 34 | - git clone --depth=50 https://github.com/libretro/libretro-super 35 | - cd libretro-super/travis 36 | - ./build.sh 37 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.libretro 2 | -------------------------------------------------------------------------------- /Makefile.common: -------------------------------------------------------------------------------- 1 | LIBRETRO_COMM_DIR := $(CORE_DIR)/../libretro-common 2 | INCFLAGS := \ 3 | -I$(CORE_DIR) \ 4 | -I$(CORE_DIR)/../include \ 5 | -I$(CORE_DIR)/../../common \ 6 | -I$(CORE_DIR)/../../common/resample \ 7 | -I$(CORE_DIR)/../libretro \ 8 | -I$(LIBRETRO_COMM_DIR)/include 9 | 10 | ifneq (,$(findstring msvc2003,$(platform))) 11 | INCFLAGS += -I$(LIBRETRO_COMM_DIR)/include/compat/msvc 12 | endif 13 | 14 | SOURCES_C := \ 15 | $(CORE_DIR)/../libretro/gambatte_log.c \ 16 | $(CORE_DIR)/../libretro/blipper.c 17 | 18 | SOURCES_CXX := \ 19 | $(CORE_DIR)/bootloader.cpp \ 20 | $(CORE_DIR)/cpu.cpp \ 21 | $(CORE_DIR)/gambatte.cpp \ 22 | $(CORE_DIR)/initstate.cpp \ 23 | $(CORE_DIR)/interrupter.cpp \ 24 | $(CORE_DIR)/interruptrequester.cpp \ 25 | $(CORE_DIR)/gambatte-memory.cpp \ 26 | $(CORE_DIR)/sound.cpp \ 27 | $(CORE_DIR)/statesaver.cpp \ 28 | $(CORE_DIR)/tima.cpp \ 29 | $(CORE_DIR)/video.cpp \ 30 | $(CORE_DIR)/video_libretro.cpp \ 31 | $(CORE_DIR)/mem/cartridge.cpp \ 32 | $(CORE_DIR)/mem/cartridge_libretro.cpp \ 33 | $(CORE_DIR)/mem/huc3.cpp \ 34 | $(CORE_DIR)/mem/memptrs.cpp \ 35 | $(CORE_DIR)/mem/rtc.cpp \ 36 | $(CORE_DIR)/sound/channel1.cpp \ 37 | $(CORE_DIR)/sound/channel2.cpp \ 38 | $(CORE_DIR)/sound/channel3.cpp \ 39 | $(CORE_DIR)/sound/channel4.cpp \ 40 | $(CORE_DIR)/sound/duty_unit.cpp \ 41 | $(CORE_DIR)/sound/envelope_unit.cpp \ 42 | $(CORE_DIR)/sound/length_counter.cpp \ 43 | $(CORE_DIR)/video/ly_counter.cpp \ 44 | $(CORE_DIR)/video/lyc_irq.cpp \ 45 | $(CORE_DIR)/video/next_m0_time.cpp \ 46 | $(CORE_DIR)/video/ppu.cpp \ 47 | $(CORE_DIR)/video/sprite_mapper.cpp \ 48 | $(CORE_DIR)/../libretro/libretro.cpp 49 | 50 | ifeq ($(HAVE_NETWORK),1) 51 | SOURCES_CXX += \ 52 | $(CORE_DIR)/../libretro/net_serial.cpp 53 | endif 54 | 55 | ifneq ($(STATIC_LINKING), 1) 56 | SOURCES_C += \ 57 | $(LIBRETRO_COMM_DIR)/compat/compat_posix_string.c \ 58 | $(LIBRETRO_COMM_DIR)/compat/compat_snprintf.c \ 59 | $(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.c \ 60 | $(LIBRETRO_COMM_DIR)/compat/compat_strl.c \ 61 | $(LIBRETRO_COMM_DIR)/compat/fopen_utf8.c \ 62 | $(LIBRETRO_COMM_DIR)/encodings/encoding_utf.c \ 63 | $(LIBRETRO_COMM_DIR)/file/file_path.c \ 64 | $(LIBRETRO_COMM_DIR)/file/file_path_io.c \ 65 | $(LIBRETRO_COMM_DIR)/streams/file_stream.c \ 66 | $(LIBRETRO_COMM_DIR)/streams/file_stream_transforms.c \ 67 | $(LIBRETRO_COMM_DIR)/string/stdstring.c \ 68 | $(LIBRETRO_COMM_DIR)/time/rtime.c \ 69 | $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.c 70 | endif 71 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 0.1.{build} 2 | 3 | shallow_clone: true 4 | 5 | image: Visual Studio 2017 6 | 7 | environment: 8 | makefile_location: "." 9 | makefile_name: Makefile.libretro 10 | target_name: gambatte 11 | 12 | configuration: 13 | - release 14 | 15 | platform: 16 | - windows_msvc2017_uwp_x64 17 | - windows_msvc2017_uwp_x86 18 | - windows_msvc2017_uwp_arm 19 | - windows_msvc2017_desktop_x64 20 | - windows_msvc2017_desktop_x86 21 | 22 | init: 23 | - set Path=C:\msys64\usr\bin;%Path% 24 | 25 | build_script: 26 | - cd %makefile_location% 27 | - make -f %makefile_name% platform=%platform% 28 | 29 | artifacts: 30 | - path: '**\%target_name%*.dll' 31 | - path: '**\%target_name%*.lib' 32 | - path: '**\%target_name%*.pdb' 33 | - path: '**\libretro.h' -------------------------------------------------------------------------------- /common/gambatte-array.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2008 by Sindre Aamås * 3 | * aamas@stud.ntnu.no * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License version 2 as * 7 | * published by the Free Software Foundation. * 8 | * * 9 | * This program is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU General Public License version 2 for more details. * 13 | * * 14 | * You should have received a copy of the GNU General Public License * 15 | * version 2 along with this program; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ***************************************************************************/ 19 | #ifndef ARRAY_H 20 | #define ARRAY_H 21 | 22 | #include 23 | #include "uncopyable.h" 24 | 25 | template 26 | class Array : Uncopyable { 27 | T *a; 28 | std::size_t sz; 29 | 30 | public: 31 | explicit Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {} 32 | ~Array() { delete []a; } 33 | void reset(const std::size_t size = 0) { delete []a; a = size ? new T[size] : 0; sz = size; } 34 | std::size_t size() const { return sz; } 35 | T * get() const { return a; } 36 | operator T*() const { return a; } 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /common/uncopyable.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2009 by Sindre Aamås * 3 | * aamas@stud.ntnu.no * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License version 2 as * 7 | * published by the Free Software Foundation. * 8 | * * 9 | * This program is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU General Public License version 2 for more details. * 13 | * * 14 | * You should have received a copy of the GNU General Public License * 15 | * version 2 along with this program; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ***************************************************************************/ 19 | #ifndef UNCOPYABLE_H 20 | #define UNCOPYABLE_H 21 | 22 | class Uncopyable { 23 | Uncopyable(const Uncopyable&); 24 | Uncopyable& operator=(const Uncopyable&); 25 | public: 26 | Uncopyable() {} 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /crowdin.yml: -------------------------------------------------------------------------------- 1 | files: 2 | - source: /intl/_us/*.json 3 | translation: /intl/_%two_letters_code%/%original_file_name% 4 | -------------------------------------------------------------------------------- /intl/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | crowdin-cli.jar 3 | *.h 4 | *.json 5 | -------------------------------------------------------------------------------- /intl/crowdin.yaml: -------------------------------------------------------------------------------- 1 | "project_id": "380544" 2 | "api_token": "_secret_" 3 | "base_url": "https://api.crowdin.com" 4 | "preserve_hierarchy": true 5 | 6 | "files": 7 | [ 8 | { 9 | "source": "/_core_name_/_us.json", 10 | "dest": "/_core_name_/_core_name_.json", 11 | "translation": "/_core_name_/_%two_letters_code%.json", 12 | }, 13 | ] 14 | -------------------------------------------------------------------------------- /intl/crowdin_prep.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import core_option_translation as t 4 | 5 | if __name__ == '__main__': 6 | try: 7 | if t.os.path.isfile(t.sys.argv[1]) or t.sys.argv[1].endswith('.h'): 8 | _temp = t.os.path.dirname(t.sys.argv[1]) 9 | else: 10 | _temp = t.sys.argv[1] 11 | while _temp.endswith('/') or _temp.endswith('\\'): 12 | _temp = _temp[:-1] 13 | TARGET_DIR_PATH = _temp 14 | except IndexError: 15 | TARGET_DIR_PATH = t.os.path.dirname(t.os.path.dirname(t.os.path.realpath(__file__))) 16 | print("No path provided, assuming parent directory:\n" + TARGET_DIR_PATH) 17 | 18 | CORE_NAME = t.clean_file_name(t.sys.argv[2]) 19 | DIR_PATH = t.os.path.dirname(t.os.path.realpath(__file__)) 20 | H_FILE_PATH = t.os.path.join(TARGET_DIR_PATH, 'libretro_core_options.h') 21 | 22 | print('Getting texts from libretro_core_options.h') 23 | with open(H_FILE_PATH, 'r+', encoding='utf-8') as _h_file: 24 | _main_text = _h_file.read() 25 | _hash_n_str = t.get_texts(_main_text) 26 | _files = t.create_msg_hash(DIR_PATH, CORE_NAME, _hash_n_str) 27 | 28 | _source_jsons = t.h2json(_files) 29 | 30 | print('\nAll done!') 31 | -------------------------------------------------------------------------------- /intl/crowdin_source_upload.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | import os 5 | import shutil 6 | import subprocess 7 | import sys 8 | import urllib.request 9 | import zipfile 10 | import core_option_translation as t 11 | 12 | # -------------------- MAIN -------------------- # 13 | 14 | if __name__ == '__main__': 15 | # Check Crowdin API Token and core name 16 | try: 17 | API_KEY = sys.argv[1] 18 | CORE_NAME = t.clean_file_name(sys.argv[2]) 19 | except IndexError as e: 20 | print('Please provide Crowdin API Token and core name!') 21 | raise e 22 | 23 | DIR_PATH = t.os.path.dirname(t.os.path.realpath(__file__)) 24 | YAML_PATH = t.os.path.join(DIR_PATH, 'crowdin.yaml') 25 | 26 | # Apply Crowdin API Key 27 | with open(YAML_PATH, 'r') as crowdin_config_file: 28 | crowdin_config = crowdin_config_file.read() 29 | crowdin_config = re.sub(r'"api_token": "_secret_"', 30 | f'"api_token": "{API_KEY}"', 31 | crowdin_config, 1) 32 | crowdin_config = re.sub(r'/_core_name_', 33 | f'/{CORE_NAME}' 34 | , crowdin_config) 35 | with open(YAML_PATH, 'w') as crowdin_config_file: 36 | crowdin_config_file.write(crowdin_config) 37 | 38 | try: 39 | # Download Crowdin CLI 40 | jar_name = 'crowdin-cli.jar' 41 | jar_path = t.os.path.join(DIR_PATH, jar_name) 42 | crowdin_cli_file = 'crowdin-cli.zip' 43 | crowdin_cli_url = 'https://downloads.crowdin.com/cli/v3/' + crowdin_cli_file 44 | crowdin_cli_path = t.os.path.join(DIR_PATH, crowdin_cli_file) 45 | 46 | if not os.path.isfile(t.os.path.join(DIR_PATH, jar_name)): 47 | print('download crowdin-cli.jar') 48 | urllib.request.urlretrieve(crowdin_cli_url, crowdin_cli_path) 49 | with zipfile.ZipFile(crowdin_cli_path, 'r') as zip_ref: 50 | jar_dir = t.os.path.join(DIR_PATH, zip_ref.namelist()[0]) 51 | for file in zip_ref.namelist(): 52 | if file.endswith(jar_name): 53 | jar_file = file 54 | break 55 | zip_ref.extract(jar_file, path=DIR_PATH) 56 | os.rename(t.os.path.join(DIR_PATH, jar_file), jar_path) 57 | os.remove(crowdin_cli_path) 58 | shutil.rmtree(jar_dir) 59 | 60 | print('upload source *.json') 61 | subprocess.run(['java', '-jar', jar_path, 'upload', 'sources', '--config', YAML_PATH]) 62 | 63 | # Reset Crowdin API Key 64 | with open(YAML_PATH, 'r') as crowdin_config_file: 65 | crowdin_config = crowdin_config_file.read() 66 | crowdin_config = re.sub(r'"api_token": ".*?"', 67 | '"api_token": "_secret_"', 68 | crowdin_config, 1) 69 | 70 | # TODO this is NOT safe! 71 | crowdin_config = re.sub(re.escape(f'/{CORE_NAME}'), 72 | '/_core_name_', 73 | crowdin_config) 74 | 75 | with open(YAML_PATH, 'w') as crowdin_config_file: 76 | crowdin_config_file.write(crowdin_config) 77 | 78 | except Exception as e: 79 | # Try really hard to reset Crowdin API Key 80 | with open(YAML_PATH, 'r') as crowdin_config_file: 81 | crowdin_config = crowdin_config_file.read() 82 | crowdin_config = re.sub(r'"api_token": ".*?"', 83 | '"api_token": "_secret_"', 84 | crowdin_config, 1) 85 | 86 | # TODO this is NOT safe! 87 | crowdin_config = re.sub(re.escape(f'/{CORE_NAME}'), 88 | '/_core_name_', 89 | crowdin_config) 90 | 91 | with open(YAML_PATH, 'w') as crowdin_config_file: 92 | crowdin_config_file.write(crowdin_config) 93 | raise e 94 | -------------------------------------------------------------------------------- /intl/crowdin_translate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import core_option_translation as t 4 | 5 | if __name__ == '__main__': 6 | try: 7 | if t.os.path.isfile(t.sys.argv[1]) or t.sys.argv[1].endswith('.h'): 8 | _temp = t.os.path.dirname(t.sys.argv[1]) 9 | else: 10 | _temp = t.sys.argv[1] 11 | while _temp.endswith('/') or _temp.endswith('\\'): 12 | _temp = _temp[:-1] 13 | TARGET_DIR_PATH = _temp 14 | except IndexError: 15 | TARGET_DIR_PATH = t.os.path.dirname(t.os.path.dirname(t.os.path.realpath(__file__))) 16 | print("No path provided, assuming parent directory:\n" + TARGET_DIR_PATH) 17 | 18 | CORE_NAME = t.clean_file_name(t.sys.argv[2]) 19 | DIR_PATH = t.os.path.dirname(t.os.path.realpath(__file__)) 20 | LOCALISATIONS_PATH = t.os.path.join(DIR_PATH, CORE_NAME) 21 | US_FILE_PATH = t.os.path.join(LOCALISATIONS_PATH, '_us.h') 22 | H_FILE_PATH = t.os.path.join(TARGET_DIR_PATH, 'libretro_core_options.h') 23 | INTL_FILE_PATH = t.os.path.join(TARGET_DIR_PATH, 'libretro_core_options_intl.h') 24 | 25 | print('Getting texts from libretro_core_options.h') 26 | with open(H_FILE_PATH, 'r+', encoding='utf-8') as _h_file: 27 | _main_text = _h_file.read() 28 | _hash_n_str = t.get_texts(_main_text) 29 | _files = t.create_msg_hash(DIR_PATH, CORE_NAME, _hash_n_str) 30 | _source_jsons = t.h2json(_files) 31 | 32 | print('Converting translations *.json to *.h:') 33 | localisation_files = t.os.scandir(LOCALISATIONS_PATH) 34 | t.json2h(LOCALISATIONS_PATH, localisation_files) 35 | 36 | print('Constructing libretro_core_options_intl.h') 37 | t.create_intl_file(INTL_FILE_PATH, LOCALISATIONS_PATH, _main_text, _files["_us"]) 38 | 39 | print('\nAll done!') 40 | -------------------------------------------------------------------------------- /intl/crowdin_translation_download.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | import os 5 | import shutil 6 | import subprocess 7 | import sys 8 | import urllib.request 9 | import zipfile 10 | import core_option_translation as t 11 | 12 | # -------------------- MAIN -------------------- # 13 | 14 | if __name__ == '__main__': 15 | # Check Crowdin API Token and core name 16 | try: 17 | API_KEY = sys.argv[1] 18 | CORE_NAME = t.clean_file_name(sys.argv[2]) 19 | except IndexError as e: 20 | print('Please provide Crowdin API Token and core name!') 21 | raise e 22 | 23 | DIR_PATH = t.os.path.dirname(t.os.path.realpath(__file__)) 24 | YAML_PATH = t.os.path.join(DIR_PATH, 'crowdin.yaml') 25 | 26 | # Apply Crowdin API Key 27 | with open(YAML_PATH, 'r') as crowdin_config_file: 28 | crowdin_config = crowdin_config_file.read() 29 | crowdin_config = re.sub(r'"api_token": "_secret_"', 30 | f'"api_token": "{API_KEY}"', 31 | crowdin_config, 1) 32 | crowdin_config = re.sub(r'/_core_name_', 33 | f'/{CORE_NAME}' 34 | , crowdin_config) 35 | with open(YAML_PATH, 'w') as crowdin_config_file: 36 | crowdin_config_file.write(crowdin_config) 37 | 38 | try: 39 | # Download Crowdin CLI 40 | jar_name = 'crowdin-cli.jar' 41 | jar_path = t.os.path.join(DIR_PATH, jar_name) 42 | crowdin_cli_file = 'crowdin-cli.zip' 43 | crowdin_cli_url = 'https://downloads.crowdin.com/cli/v3/' + crowdin_cli_file 44 | crowdin_cli_path = t.os.path.join(DIR_PATH, crowdin_cli_file) 45 | 46 | if not os.path.isfile(t.os.path.join(DIR_PATH, jar_name)): 47 | print('download crowdin-cli.jar') 48 | urllib.request.urlretrieve(crowdin_cli_url, crowdin_cli_path) 49 | with zipfile.ZipFile(crowdin_cli_path, 'r') as zip_ref: 50 | jar_dir = t.os.path.join(DIR_PATH, zip_ref.namelist()[0]) 51 | for file in zip_ref.namelist(): 52 | if file.endswith(jar_name): 53 | jar_file = file 54 | break 55 | zip_ref.extract(jar_file, path=DIR_PATH) 56 | os.rename(t.os.path.join(DIR_PATH, jar_file), jar_path) 57 | os.remove(crowdin_cli_path) 58 | shutil.rmtree(jar_dir) 59 | 60 | print('download translation *.json') 61 | subprocess.run(['java', '-jar', jar_path, 'download', '--config', YAML_PATH]) 62 | 63 | # Reset Crowdin API Key 64 | with open(YAML_PATH, 'r') as crowdin_config_file: 65 | crowdin_config = crowdin_config_file.read() 66 | crowdin_config = re.sub(r'"api_token": ".*?"', 67 | '"api_token": "_secret_"', 68 | crowdin_config, 1) 69 | 70 | # TODO this is NOT safe! 71 | crowdin_config = re.sub(re.escape(f'/{CORE_NAME}'), 72 | '/_core_name_', 73 | crowdin_config) 74 | 75 | with open(YAML_PATH, 'w') as crowdin_config_file: 76 | crowdin_config_file.write(crowdin_config) 77 | 78 | except Exception as e: 79 | # Try really hard to reset Crowdin API Key 80 | with open(YAML_PATH, 'r') as crowdin_config_file: 81 | crowdin_config = crowdin_config_file.read() 82 | crowdin_config = re.sub(r'"api_token": ".*?"', 83 | '"api_token": "_secret_"', 84 | crowdin_config, 1) 85 | 86 | # TODO this is NOT safe! 87 | crowdin_config = re.sub(re.escape(f'/{CORE_NAME}'), 88 | '/_core_name_', 89 | crowdin_config) 90 | 91 | with open(YAML_PATH, 'w') as crowdin_config_file: 92 | crowdin_config_file.write(crowdin_config) 93 | raise e 94 | -------------------------------------------------------------------------------- /intl/download_workflow.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import subprocess 5 | 6 | try: 7 | api_key = sys.argv[1] 8 | core_name = sys.argv[2] 9 | dir_path = sys.argv[3] 10 | except IndexError as e: 11 | print('Please provide path to libretro_core_options.h, Crowdin API Token and core name!') 12 | raise e 13 | 14 | subprocess.run(['python3', 'intl/crowdin_prep.py', dir_path, core_name]) 15 | subprocess.run(['python3', 'intl/crowdin_translation_download.py', api_key, core_name]) 16 | subprocess.run(['python3', 'intl/crowdin_translate.py', dir_path, core_name]) 17 | -------------------------------------------------------------------------------- /intl/initial_sync.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | import os 5 | import shutil 6 | import subprocess 7 | import sys 8 | import time 9 | import urllib.request 10 | import zipfile 11 | import core_option_translation as t 12 | 13 | # -------------------- MAIN -------------------- # 14 | 15 | if __name__ == '__main__': 16 | # Check Crowdin API Token and core name 17 | try: 18 | API_KEY = sys.argv[1] 19 | CORE_NAME = t.clean_file_name(sys.argv[2]) 20 | except IndexError as e: 21 | print('Please provide Crowdin API Token and core name!') 22 | raise e 23 | 24 | DIR_PATH = os.path.dirname(os.path.realpath(__file__)) 25 | YAML_PATH = os.path.join(DIR_PATH, 'crowdin.yaml') 26 | 27 | # Apply Crowdin API Key 28 | with open(YAML_PATH, 'r') as crowdin_config_file: 29 | crowdin_config = crowdin_config_file.read() 30 | crowdin_config = re.sub(r'"api_token": "_secret_"', 31 | f'"api_token": "{API_KEY}"', 32 | crowdin_config, 1) 33 | crowdin_config = re.sub(r'/_core_name_', 34 | f'/{CORE_NAME}' 35 | , crowdin_config) 36 | with open(YAML_PATH, 'w') as crowdin_config_file: 37 | crowdin_config_file.write(crowdin_config) 38 | 39 | try: 40 | # Download Crowdin CLI 41 | jar_name = 'crowdin-cli.jar' 42 | jar_path = os.path.join(DIR_PATH, jar_name) 43 | crowdin_cli_file = 'crowdin-cli.zip' 44 | crowdin_cli_url = 'https://downloads.crowdin.com/cli/v3/' + crowdin_cli_file 45 | crowdin_cli_path = os.path.join(DIR_PATH, crowdin_cli_file) 46 | 47 | if not os.path.isfile(os.path.join(DIR_PATH, jar_name)): 48 | print('download crowdin-cli.jar') 49 | urllib.request.urlretrieve(crowdin_cli_url, crowdin_cli_path) 50 | with zipfile.ZipFile(crowdin_cli_path, 'r') as zip_ref: 51 | jar_dir = os.path.join(DIR_PATH, zip_ref.namelist()[0]) 52 | for file in zip_ref.namelist(): 53 | if file.endswith(jar_name): 54 | jar_file = file 55 | break 56 | zip_ref.extract(jar_file, path=DIR_PATH) 57 | os.rename(os.path.join(DIR_PATH, jar_file), jar_path) 58 | os.remove(crowdin_cli_path) 59 | shutil.rmtree(jar_dir) 60 | 61 | print('upload source & translations *.json') 62 | subprocess.run(['java', '-jar', jar_path, 'upload', 'sources', '--config', YAML_PATH]) 63 | subprocess.run(['java', '-jar', jar_path, 'upload', 'translations', '--config', YAML_PATH]) 64 | 65 | print('wait for crowdin server to process data') 66 | time.sleep(10) 67 | 68 | print('download translation *.json') 69 | subprocess.run(['java', '-jar', jar_path, 'download', '--config', YAML_PATH]) 70 | 71 | # Reset Crowdin API Key 72 | with open(YAML_PATH, 'r') as crowdin_config_file: 73 | crowdin_config = crowdin_config_file.read() 74 | crowdin_config = re.sub(r'"api_token": ".*?"', '"api_token": "_secret_"', crowdin_config, 1) 75 | 76 | # TODO this is NOT safe! 77 | crowdin_config = re.sub(re.escape(f'/{CORE_NAME}'), 78 | '/_core_name_', 79 | crowdin_config) 80 | 81 | with open(YAML_PATH, 'w') as crowdin_config_file: 82 | crowdin_config_file.write(crowdin_config) 83 | 84 | with open('intl/upload_workflow.py', 'r') as workflow: 85 | workflow_config = workflow.read() 86 | workflow_config = workflow_config.replace( 87 | "subprocess.run(['python3', 'intl/core_option_translation.py', dir_path, core_name])", 88 | "subprocess.run(['python3', 'intl/crowdin_prep.py', dir_path, core_name])" 89 | ) 90 | workflow_config = workflow_config.replace( 91 | "subprocess.run(['python3', 'intl/initial_sync.py', api_key, core_name])", 92 | "subprocess.run(['python3', 'intl/crowdin_source_upload.py', api_key, core_name])" 93 | ) 94 | with open('intl/upload_workflow.py', 'w') as workflow: 95 | workflow.write(workflow_config) 96 | 97 | with open('intl/download_workflow.py', 'r') as workflow: 98 | workflow_config = workflow.read() 99 | workflow_config = workflow_config.replace( 100 | "subprocess.run(['python3', 'intl/core_option_translation.py', dir_path, core_name])", 101 | "subprocess.run(['python3', 'intl/crowdin_prep.py', dir_path, core_name])" 102 | ) 103 | workflow_config = workflow_config.replace( 104 | "subprocess.run(['python3', 'intl/initial_sync.py', api_key, core_name])", 105 | "subprocess.run(['python3', 'intl/crowdin_translation_download.py', api_key, core_name])" 106 | ) 107 | with open('intl/download_workflow.py', 'w') as workflow: 108 | workflow.write(workflow_config) 109 | 110 | except Exception as e: 111 | # Try really hard to reset Crowdin API Key 112 | with open(YAML_PATH, 'r') as crowdin_config_file: 113 | crowdin_config = crowdin_config_file.read() 114 | crowdin_config = re.sub(r'"api_token": ".*?"', 115 | '"api_token": "_secret_"', 116 | crowdin_config, 1) 117 | 118 | # TODO this is NOT safe! 119 | crowdin_config = re.sub(re.escape(f'/{CORE_NAME}'), 120 | '/_core_name_', 121 | crowdin_config) 122 | 123 | with open(YAML_PATH, 'w') as crowdin_config_file: 124 | crowdin_config_file.write(crowdin_config) 125 | raise e 126 | -------------------------------------------------------------------------------- /intl/remove_initial_cycle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | with open('intl/upload_workflow.py', 'r') as workflow: 4 | workflow_config = workflow.read() 5 | 6 | workflow_config = workflow_config.replace( 7 | "subprocess.run(['python3', 'intl/core_option_translation.py', dir_path, core_name])", 8 | "subprocess.run(['python3', 'intl/crowdin_prep.py', dir_path, core_name])" 9 | ) 10 | workflow_config = workflow_config.replace( 11 | "subprocess.run(['python3', 'intl/initial_sync.py', api_key, core_name])", 12 | "subprocess.run(['python3', 'intl/crowdin_source_upload.py', api_key, core_name])" 13 | ) 14 | with open('intl/upload_workflow.py', 'w') as workflow: 15 | workflow.write(workflow_config) 16 | 17 | 18 | with open('intl/download_workflow.py', 'r') as workflow: 19 | workflow_config = workflow.read() 20 | 21 | workflow_config = workflow_config.replace( 22 | "subprocess.run(['python3', 'intl/core_option_translation.py', dir_path, core_name])", 23 | "subprocess.run(['python3', 'intl/crowdin_prep.py', dir_path, core_name])" 24 | ) 25 | workflow_config = workflow_config.replace( 26 | "subprocess.run(['python3', 'intl/initial_sync.py', api_key, core_name])", 27 | "subprocess.run(['python3', 'intl/crowdin_translation_download.py', api_key, core_name])" 28 | ) 29 | with open('intl/download_workflow.py', 'w') as workflow: 30 | workflow.write(workflow_config) 31 | -------------------------------------------------------------------------------- /intl/upload_workflow.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import subprocess 5 | 6 | try: 7 | api_key = sys.argv[1] 8 | core_name = sys.argv[2] 9 | dir_path = sys.argv[3] 10 | except IndexError as e: 11 | print('Please provide path to libretro_core_options.h, Crowdin API Token and core name!') 12 | raise e 13 | 14 | subprocess.run(['python3', 'intl/crowdin_prep.py', dir_path, core_name]) 15 | subprocess.run(['python3', 'intl/crowdin_source_upload.py', api_key, core_name]) 16 | -------------------------------------------------------------------------------- /libgambatte/include/gbint.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2007 by Sindre Aamås * 3 | * aamas@stud.ntnu.no * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License version 2 as * 7 | * published by the Free Software Foundation. * 8 | * * 9 | * This program is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU General Public License version 2 for more details. * 13 | * * 14 | * You should have received a copy of the GNU General Public License * 15 | * version 2 along with this program; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ***************************************************************************/ 19 | #ifndef GAMBATTE_INT_H 20 | #define GAMBATTE_INT_H 21 | 22 | #ifdef HAVE_CSTDINT 23 | 24 | #include 25 | 26 | namespace gambatte { 27 | using std::uint_least32_t; 28 | using std::uint_least16_t; 29 | } 30 | 31 | #elif defined(HAVE_STDINT_H) 32 | 33 | #include 34 | 35 | namespace gambatte { 36 | using ::uint_least32_t; 37 | using ::uint_least16_t; 38 | } 39 | 40 | #else 41 | 42 | namespace gambatte { 43 | #ifdef CHAR_LEAST_32 44 | typedef unsigned char uint_least32_t; 45 | #elif defined(SHORT_LEAST_32) 46 | typedef unsigned short uint_least32_t; 47 | #elif defined(INT_LEAST_32) 48 | typedef unsigned uint_least32_t; 49 | #else 50 | typedef unsigned long uint_least32_t; 51 | #endif 52 | 53 | #ifdef CHAR_LEAST_16 54 | typedef unsigned char uint_least16_t; 55 | #else 56 | typedef unsigned short uint_least16_t; 57 | #endif 58 | } 59 | 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /libgambatte/include/inputgetter.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2007 by Sindre Aamås * 3 | * aamas@stud.ntnu.no * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License version 2 as * 7 | * published by the Free Software Foundation. * 8 | * * 9 | * This program is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU General Public License version 2 for more details. * 13 | * * 14 | * You should have received a copy of the GNU General Public License * 15 | * version 2 along with this program; if not, write to the * 16 | * Free Software Foundation, Inc., * 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 | ***************************************************************************/ 19 | #ifndef GAMBATTE_INPUTGETTER_H 20 | #define GAMBATTE_INPUTGETTER_H 21 | 22 | namespace gambatte { 23 | class InputGetter { 24 | public: 25 | enum { A = 0x01, B = 0x02, SELECT = 0x04, START = 0x08, RIGHT = 0x10, LEFT = 0x20, UP = 0x40, DOWN = 0x80 }; 26 | virtual ~InputGetter() {}; 27 | 28 | /** @return A|B|SELECT|START|RIGHT|LEFT|UP|DOWN if those buttons are pressed. */ 29 | virtual unsigned operator()() = 0; 30 | }; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/compat/compat_posix_string.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (compat_posix_string.c). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | #ifdef _WIN32 28 | 29 | #undef strcasecmp 30 | #undef strdup 31 | #undef isblank 32 | #undef strtok_r 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | int retro_strcasecmp__(const char *a, const char *b) 41 | { 42 | while (*a && *b) 43 | { 44 | int a_ = tolower(*a); 45 | int b_ = tolower(*b); 46 | 47 | if (a_ != b_) 48 | return a_ - b_; 49 | 50 | a++; 51 | b++; 52 | } 53 | 54 | return tolower(*a) - tolower(*b); 55 | } 56 | 57 | char *retro_strdup__(const char *orig) 58 | { 59 | size_t len = strlen(orig) + 1; 60 | char *ret = (char*)malloc(len); 61 | if (!ret) 62 | return NULL; 63 | 64 | strlcpy(ret, orig, len); 65 | return ret; 66 | } 67 | 68 | int retro_isblank__(int c) 69 | { 70 | return (c == ' ') || (c == '\t'); 71 | } 72 | 73 | char *retro_strtok_r__(char *str, const char *delim, char **saveptr) 74 | { 75 | char *first = NULL; 76 | if (!saveptr || !delim) 77 | return NULL; 78 | 79 | if (str) 80 | *saveptr = str; 81 | 82 | do 83 | { 84 | char *ptr = NULL; 85 | first = *saveptr; 86 | while (*first && strchr(delim, *first)) 87 | *first++ = '\0'; 88 | 89 | if (*first == '\0') 90 | return NULL; 91 | 92 | ptr = first + 1; 93 | 94 | while (*ptr && !strchr(delim, *ptr)) 95 | ptr++; 96 | 97 | *saveptr = ptr + (*ptr ? 1 : 0); 98 | *ptr = '\0'; 99 | } while (strlen(first) == 0); 100 | 101 | return first; 102 | } 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/compat/compat_snprintf.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (compat_snprintf.c). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | /* THIS FILE HAS NOT BEEN VALIDATED ON PLATFORMS BESIDES MSVC */ 24 | #ifdef _MSC_VER 25 | 26 | #include 27 | #include 28 | 29 | #if _MSC_VER < 1800 30 | #define va_copy(dst, src) ((dst) = (src)) 31 | #endif 32 | 33 | #if _MSC_VER < 1300 34 | #define _vscprintf c89_vscprintf_retro__ 35 | 36 | static int c89_vscprintf_retro__(const char *fmt, va_list pargs) 37 | { 38 | int retval; 39 | va_list argcopy; 40 | va_copy(argcopy, pargs); 41 | retval = vsnprintf(NULL, 0, fmt, argcopy); 42 | va_end(argcopy); 43 | return retval; 44 | } 45 | #endif 46 | 47 | /* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 */ 48 | 49 | int c99_vsnprintf_retro__(char *s, size_t len, const char *fmt, va_list ap) 50 | { 51 | int count = -1; 52 | 53 | if (len != 0) 54 | { 55 | #if (_MSC_VER <= 1310) 56 | count = _vsnprintf(s, len - 1, fmt, ap); 57 | #else 58 | count = _vsnprintf_s(s, len, len - 1, fmt, ap); 59 | #endif 60 | } 61 | 62 | if (count == -1) 63 | count = _vscprintf(fmt, ap); 64 | 65 | /* there was no room for a NULL, so truncate the last character */ 66 | if (count == len && len) 67 | s[len - 1] = '\0'; 68 | 69 | return count; 70 | } 71 | 72 | int c99_snprintf_retro__(char *s, size_t len, const char *fmt, ...) 73 | { 74 | int count; 75 | va_list ap; 76 | 77 | va_start(ap, fmt); 78 | count = c99_vsnprintf_retro__(s, len, fmt, ap); 79 | va_end(ap); 80 | 81 | return count; 82 | } 83 | #endif 84 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/compat/compat_strcasestr.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (compat_strcasestr.c). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | /* Pretty much strncasecmp. */ 28 | static int casencmp(const char *a, const char *b, size_t n) 29 | { 30 | size_t i; 31 | 32 | for (i = 0; i < n; i++) 33 | { 34 | int a_lower = tolower(a[i]); 35 | int b_lower = tolower(b[i]); 36 | if (a_lower != b_lower) 37 | return a_lower - b_lower; 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | char *strcasestr_retro__(const char *haystack, const char *needle) 44 | { 45 | size_t i, search_off; 46 | size_t hay_len = strlen(haystack); 47 | size_t needle_len = strlen(needle); 48 | 49 | if (needle_len > hay_len) 50 | return NULL; 51 | 52 | search_off = hay_len - needle_len; 53 | for (i = 0; i <= search_off; i++) 54 | if (!casencmp(haystack + i, needle, needle_len)) 55 | return (char*)haystack + i; 56 | 57 | return NULL; 58 | } 59 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/compat/compat_strl.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (compat_strl.c). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | /* Implementation of strlcpy()/strlcat() based on OpenBSD. */ 29 | 30 | #ifndef __MACH__ 31 | 32 | size_t strlcpy(char *dest, const char *source, size_t size) 33 | { 34 | size_t src_size = 0; 35 | size_t n = size; 36 | 37 | if (n) 38 | while (--n && (*dest++ = *source++)) src_size++; 39 | 40 | if (!n) 41 | { 42 | if (size) *dest = '\0'; 43 | while (*source++) src_size++; 44 | } 45 | 46 | return src_size; 47 | } 48 | 49 | size_t strlcat(char *dest, const char *source, size_t size) 50 | { 51 | size_t len = strlen(dest); 52 | 53 | dest += len; 54 | 55 | if (len > size) 56 | size = 0; 57 | else 58 | size -= len; 59 | 60 | return len + strlcpy(dest, source, size); 61 | } 62 | #endif 63 | 64 | char *strldup(const char *s, size_t n) 65 | { 66 | char *dst = (char*)malloc(sizeof(char) * (n + 1)); 67 | strlcpy(dst, s, n); 68 | return dst; 69 | } 70 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/compat/fopen_utf8.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (fopen_utf8.c). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX) 29 | #ifndef LEGACY_WIN32 30 | #define LEGACY_WIN32 31 | #endif 32 | #endif 33 | 34 | #ifdef _WIN32 35 | #undef fopen 36 | 37 | void *fopen_utf8(const char * filename, const char * mode) 38 | { 39 | #if defined(LEGACY_WIN32) 40 | FILE *ret = NULL; 41 | char * filename_local = utf8_to_local_string_alloc(filename); 42 | 43 | if (!filename_local) 44 | return NULL; 45 | ret = fopen(filename_local, mode); 46 | if (filename_local) 47 | free(filename_local); 48 | return ret; 49 | #else 50 | wchar_t * filename_w = utf8_to_utf16_string_alloc(filename); 51 | wchar_t * mode_w = utf8_to_utf16_string_alloc(mode); 52 | FILE* ret = NULL; 53 | 54 | if (filename_w && mode_w) 55 | ret = _wfopen(filename_w, mode_w); 56 | if (filename_w) 57 | free(filename_w); 58 | if (mode_w) 59 | free(mode_w); 60 | return ret; 61 | #endif 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/file/file_path_io.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (file_path_io.c). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #define VFS_FRONTEND 39 | #include 40 | 41 | #ifdef _WIN32 42 | #include 43 | #else 44 | #include /* stat() is defined here */ 45 | #endif 46 | 47 | /* TODO/FIXME - globals */ 48 | static retro_vfs_stat_t path_stat_cb = retro_vfs_stat_impl; 49 | static retro_vfs_mkdir_t path_mkdir_cb = retro_vfs_mkdir_impl; 50 | 51 | void path_vfs_init(const struct retro_vfs_interface_info* vfs_info) 52 | { 53 | const struct retro_vfs_interface* 54 | vfs_iface = vfs_info->iface; 55 | 56 | path_stat_cb = retro_vfs_stat_impl; 57 | path_mkdir_cb = retro_vfs_mkdir_impl; 58 | 59 | if (vfs_info->required_interface_version < PATH_REQUIRED_VFS_VERSION || !vfs_iface) 60 | return; 61 | 62 | path_stat_cb = vfs_iface->stat; 63 | path_mkdir_cb = vfs_iface->mkdir; 64 | } 65 | 66 | int path_stat(const char *path) 67 | { 68 | return path_stat_cb(path, NULL); 69 | } 70 | 71 | /** 72 | * path_is_directory: 73 | * @path : path 74 | * 75 | * Checks if path is a directory. 76 | * 77 | * Returns: true (1) if path is a directory, otherwise false (0). 78 | */ 79 | bool path_is_directory(const char *path) 80 | { 81 | return (path_stat_cb(path, NULL) & RETRO_VFS_STAT_IS_DIRECTORY) != 0; 82 | } 83 | 84 | bool path_is_character_special(const char *path) 85 | { 86 | return (path_stat_cb(path, NULL) & RETRO_VFS_STAT_IS_CHARACTER_SPECIAL) != 0; 87 | } 88 | 89 | bool path_is_valid(const char *path) 90 | { 91 | return (path_stat_cb(path, NULL) & RETRO_VFS_STAT_IS_VALID) != 0; 92 | } 93 | 94 | int32_t path_get_size(const char *path) 95 | { 96 | int32_t filesize = 0; 97 | if (path_stat_cb(path, &filesize) != 0) 98 | return filesize; 99 | 100 | return -1; 101 | } 102 | 103 | /** 104 | * path_mkdir: 105 | * @dir : directory 106 | * 107 | * Create directory on filesystem. 108 | * 109 | * Returns: true (1) if directory could be created, otherwise false (0). 110 | **/ 111 | bool path_mkdir(const char *dir) 112 | { 113 | bool norecurse = false; 114 | char *basedir = NULL; 115 | 116 | if (!(dir && *dir)) 117 | return false; 118 | 119 | /* Use heap. Real chance of stack 120 | * overflow if we recurse too hard. */ 121 | basedir = strdup(dir); 122 | 123 | if (!basedir) 124 | return false; 125 | 126 | path_parent_dir(basedir); 127 | 128 | if (!*basedir || !strcmp(basedir, dir)) 129 | { 130 | free(basedir); 131 | return false; 132 | } 133 | 134 | if ( path_is_directory(basedir) 135 | || path_mkdir(basedir)) 136 | norecurse = true; 137 | 138 | free(basedir); 139 | 140 | if (norecurse) 141 | { 142 | int ret = path_mkdir_cb(dir); 143 | 144 | /* Don't treat this as an error. */ 145 | if (ret == -2 && path_is_directory(dir)) 146 | return true; 147 | else if (ret == 0) 148 | return true; 149 | } 150 | return false; 151 | } 152 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/boolean.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (boolean.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_BOOLEAN_H 24 | #define __LIBRETRO_SDK_BOOLEAN_H 25 | 26 | #ifndef __cplusplus 27 | 28 | #if defined(_MSC_VER) && _MSC_VER < 1800 && !defined(SN_TARGET_PS3) 29 | /* Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. */ 30 | #define bool unsigned char 31 | #define true 1 32 | #define false 0 33 | #else 34 | #include 35 | #endif 36 | 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/compat/fopen_utf8.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (fopen_utf8.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_COMPAT_FOPEN_UTF8_H 24 | #define __LIBRETRO_SDK_COMPAT_FOPEN_UTF8_H 25 | 26 | #ifdef _WIN32 27 | /* Defined to error rather than fopen_utf8, to make it clear to everyone reading the code that not worrying about utf16 is fine */ 28 | /* TODO: enable */ 29 | /* #define fopen (use fopen_utf8 instead) */ 30 | void *fopen_utf8(const char * filename, const char * mode); 31 | #else 32 | #define fopen_utf8 fopen 33 | #endif 34 | #endif 35 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/compat/msvc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (msvc.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_COMPAT_MSVC_H 24 | #define __LIBRETRO_SDK_COMPAT_MSVC_H 25 | 26 | #ifdef _MSC_VER 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /* Pre-MSVC 2015 compilers don't implement snprintf, vsnprintf in a cross-platform manner. */ 33 | #if _MSC_VER < 1900 34 | #include 35 | #include 36 | #include 37 | 38 | #ifndef snprintf 39 | #define snprintf c99_snprintf_retro__ 40 | #endif 41 | int c99_snprintf_retro__(char *outBuf, size_t size, const char *format, ...); 42 | 43 | #ifndef vsnprintf 44 | #define vsnprintf c99_vsnprintf_retro__ 45 | #endif 46 | int c99_vsnprintf_retro__(char *outBuf, size_t size, const char *format, va_list ap); 47 | #endif 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #undef UNICODE /* Do not bother with UNICODE at this time. */ 54 | #include 55 | #include 56 | 57 | #define _USE_MATH_DEFINES 58 | #include 59 | 60 | /* Python headers defines ssize_t and sets HAVE_SSIZE_T. 61 | * Cannot duplicate these efforts. 62 | */ 63 | #ifndef HAVE_SSIZE_T 64 | #if defined(_WIN64) 65 | typedef __int64 ssize_t; 66 | #elif defined(_WIN32) 67 | typedef int ssize_t; 68 | #endif 69 | #endif 70 | 71 | #define mkdir(dirname, unused) _mkdir(dirname) 72 | #define strtoull _strtoui64 73 | #undef strcasecmp 74 | #define strcasecmp _stricmp 75 | #undef strncasecmp 76 | #define strncasecmp _strnicmp 77 | 78 | /* Disable some of the annoying warnings. */ 79 | #pragma warning(disable : 4800) 80 | #pragma warning(disable : 4805) 81 | #pragma warning(disable : 4244) 82 | #pragma warning(disable : 4305) 83 | #pragma warning(disable : 4146) 84 | #pragma warning(disable : 4267) 85 | #pragma warning(disable : 4723) 86 | #pragma warning(disable : 4996) 87 | 88 | /* roundf and va_copy is available since MSVC 2013 */ 89 | #if _MSC_VER < 1800 90 | #define roundf(in) (in >= 0.0f ? floorf(in + 0.5f) : ceilf(in - 0.5f)) 91 | #define va_copy(x, y) ((x) = (y)) 92 | #endif 93 | 94 | #if _MSC_VER <= 1310 95 | #ifndef __cplusplus 96 | /* VC6 math.h doesn't define some functions when in C mode. 97 | * Trying to define a prototype gives "undefined reference". 98 | * But providing an implementation then gives "function already has body". 99 | * So the equivalent of the implementations from math.h are used as 100 | * defines here instead, and it seems to work. 101 | */ 102 | #define cosf(x) ((float)cos((double)x)) 103 | #define powf(x, y) ((float)pow((double)x, (double)y)) 104 | #define sinf(x) ((float)sin((double)x)) 105 | #define ceilf(x) ((float)ceil((double)x)) 106 | #define floorf(x) ((float)floor((double)x)) 107 | #define sqrtf(x) ((float)sqrt((double)x)) 108 | #define fabsf(x) ((float)fabs((double)(x))) 109 | #endif 110 | 111 | #ifndef _strtoui64 112 | #define _strtoui64(x, y, z) (_atoi64(x)) 113 | #endif 114 | 115 | #endif 116 | 117 | #ifndef PATH_MAX 118 | #define PATH_MAX _MAX_PATH 119 | #endif 120 | 121 | #ifndef SIZE_MAX 122 | #define SIZE_MAX _UI32_MAX 123 | #endif 124 | 125 | #endif 126 | #endif 127 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/compat/posix_string.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (posix_string.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_COMPAT_POSIX_STRING_H 24 | #define __LIBRETRO_SDK_COMPAT_POSIX_STRING_H 25 | 26 | #include 27 | 28 | #ifdef _MSC_VER 29 | #include 30 | #endif 31 | 32 | RETRO_BEGIN_DECLS 33 | 34 | #ifdef _WIN32 35 | #undef strtok_r 36 | #define strtok_r(str, delim, saveptr) retro_strtok_r__(str, delim, saveptr) 37 | 38 | char *strtok_r(char *str, const char *delim, char **saveptr); 39 | #endif 40 | 41 | #ifdef _MSC_VER 42 | #undef strcasecmp 43 | #undef strdup 44 | #define strcasecmp(a, b) retro_strcasecmp__(a, b) 45 | #define strdup(orig) retro_strdup__(orig) 46 | int strcasecmp(const char *a, const char *b); 47 | char *strdup(const char *orig); 48 | 49 | /* isblank is available since MSVC 2013 */ 50 | #if _MSC_VER < 1800 51 | #undef isblank 52 | #define isblank(c) retro_isblank__(c) 53 | int isblank(int c); 54 | #endif 55 | 56 | #endif 57 | 58 | RETRO_END_DECLS 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/compat/strcasestr.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (strcasestr.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_COMPAT_STRCASESTR_H 24 | #define __LIBRETRO_SDK_COMPAT_STRCASESTR_H 25 | 26 | #include 27 | 28 | #if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H) 29 | #include "../../../config.h" 30 | #endif 31 | 32 | #ifndef HAVE_STRCASESTR 33 | 34 | #include 35 | 36 | RETRO_BEGIN_DECLS 37 | 38 | /* Avoid possible naming collisions during link 39 | * since we prefer to use the actual name. */ 40 | #define strcasestr(haystack, needle) strcasestr_retro__(haystack, needle) 41 | 42 | char *strcasestr(const char *haystack, const char *needle); 43 | 44 | RETRO_END_DECLS 45 | 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/compat/strl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (strl.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_COMPAT_STRL_H 24 | #define __LIBRETRO_SDK_COMPAT_STRL_H 25 | 26 | #include 27 | #include 28 | 29 | #if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H) 30 | #include "../../../config.h" 31 | #endif 32 | 33 | #include 34 | 35 | RETRO_BEGIN_DECLS 36 | 37 | #ifdef __MACH__ 38 | #ifndef HAVE_STRL 39 | #define HAVE_STRL 40 | #endif 41 | #endif 42 | 43 | #ifndef HAVE_STRL 44 | /* Avoid possible naming collisions during link since 45 | * we prefer to use the actual name. */ 46 | #define strlcpy(dst, src, size) strlcpy_retro__(dst, src, size) 47 | 48 | #define strlcat(dst, src, size) strlcat_retro__(dst, src, size) 49 | 50 | size_t strlcpy(char *dest, const char *source, size_t size); 51 | size_t strlcat(char *dest, const char *source, size_t size); 52 | 53 | #endif 54 | 55 | char *strldup(const char *s, size_t n); 56 | 57 | RETRO_END_DECLS 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/encodings/utf.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (utf.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef _LIBRETRO_ENCODINGS_UTF_H 24 | #define _LIBRETRO_ENCODINGS_UTF_H 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | 33 | RETRO_BEGIN_DECLS 34 | 35 | enum CodePage 36 | { 37 | CODEPAGE_LOCAL = 0, /* CP_ACP */ 38 | CODEPAGE_UTF8 = 65001 /* CP_UTF8 */ 39 | }; 40 | 41 | size_t utf8_conv_utf32(uint32_t *out, size_t out_chars, 42 | const char *in, size_t in_size); 43 | 44 | bool utf16_conv_utf8(uint8_t *out, size_t *out_chars, 45 | const uint16_t *in, size_t in_size); 46 | 47 | size_t utf8len(const char *string); 48 | 49 | size_t utf8cpy(char *d, size_t d_len, const char *s, size_t chars); 50 | 51 | const char *utf8skip(const char *str, size_t chars); 52 | 53 | uint32_t utf8_walk(const char **string); 54 | 55 | bool utf16_to_char_string(const uint16_t *in, char *s, size_t len); 56 | 57 | char* utf8_to_local_string_alloc(const char *str); 58 | 59 | char* local_to_utf8_string_alloc(const char *str); 60 | 61 | wchar_t* utf8_to_utf16_string_alloc(const char *str); 62 | 63 | char* utf16_to_utf8_string_alloc(const wchar_t *str); 64 | 65 | RETRO_END_DECLS 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/retro_assert.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (retro_assert.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __RETRO_ASSERT_H 24 | #define __RETRO_ASSERT_H 25 | 26 | #include 27 | 28 | #ifdef RARCH_INTERNAL 29 | #include 30 | #define retro_assert(cond) ((void)( (cond) || (printf("Assertion failed at %s:%d.\n", __FILE__, __LINE__), abort(), 0) )) 31 | #else 32 | #define retro_assert(cond) assert(cond) 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/retro_common_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (retro_common_api.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef _LIBRETRO_COMMON_RETRO_COMMON_API_H 24 | #define _LIBRETRO_COMMON_RETRO_COMMON_API_H 25 | 26 | /* 27 | This file is designed to normalize the libretro-common compiling environment 28 | for public API headers. This should be leaner than a normal compiling environment, 29 | since it gets #included into other project's sources. 30 | */ 31 | 32 | /* ------------------------------------ */ 33 | 34 | /* 35 | Ordinarily we want to put #ifdef __cplusplus extern "C" in C library 36 | headers to enable them to get used by c++ sources. 37 | However, we want to support building this library as C++ as well, so a 38 | special technique is called for. 39 | */ 40 | 41 | #define RETRO_BEGIN_DECLS 42 | #define RETRO_END_DECLS 43 | 44 | #ifdef __cplusplus 45 | 46 | #ifdef CXX_BUILD 47 | /* build wants everything to be built as c++, so no extern "C" */ 48 | #else 49 | #undef RETRO_BEGIN_DECLS 50 | #undef RETRO_END_DECLS 51 | #define RETRO_BEGIN_DECLS extern "C" { 52 | #define RETRO_END_DECLS } 53 | #endif 54 | 55 | #else 56 | 57 | /* header is included by a C source file, so no extern "C" */ 58 | 59 | #endif 60 | 61 | /* 62 | IMO, this non-standard ssize_t should not be used. 63 | However, it's a good example of how to handle something like this. 64 | */ 65 | #ifdef _MSC_VER 66 | #ifndef HAVE_SSIZE_T 67 | #define HAVE_SSIZE_T 68 | #if defined(_WIN64) 69 | typedef __int64 ssize_t; 70 | #elif defined(_WIN32) 71 | typedef int ssize_t; 72 | #endif 73 | #endif 74 | #elif defined(__MACH__) 75 | #include 76 | #endif 77 | 78 | #ifdef _MSC_VER 79 | #if _MSC_VER >= 1800 80 | #include 81 | #else 82 | #ifndef PRId64 83 | #define PRId64 "I64d" 84 | #define PRIu64 "I64u" 85 | #define PRIuPTR "Iu" 86 | #endif 87 | #endif 88 | #else 89 | /* C++11 says this one isn't needed, but apparently (some versions of) mingw require it anyways */ 90 | /* https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format */ 91 | /* https://github.com/libretro/RetroArch/issues/6009 */ 92 | #ifndef __STDC_FORMAT_MACROS 93 | #define __STDC_FORMAT_MACROS 1 94 | #endif 95 | #include 96 | #endif 97 | #ifndef PRId64 98 | #error "inttypes.h is being screwy" 99 | #endif 100 | #define STRING_REP_INT64 "%" PRId64 101 | #define STRING_REP_UINT64 "%" PRIu64 102 | #define STRING_REP_USIZE "%" PRIuPTR 103 | 104 | /* 105 | I would like to see retro_inline.h moved in here; possibly boolean too. 106 | 107 | rationale: these are used in public APIs, and it is easier to find problems 108 | and write code that works the first time portably when theyre included uniformly 109 | than to do the analysis from scratch each time you think you need it, for each feature. 110 | 111 | Moreover it helps force you to make hard decisions: if you EVER bring in boolean.h, 112 | then you should pay the price everywhere, so you can see how much grief it will cause. 113 | 114 | Of course, another school of thought is that you should do as little damage as possible 115 | in as few places as possible... 116 | */ 117 | 118 | /* _LIBRETRO_COMMON_RETRO_COMMON_API_H */ 119 | #endif 120 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/retro_environment.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (retro_environment.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_ENVIRONMENT_H 24 | #define __LIBRETRO_SDK_ENVIRONMENT_H 25 | 26 | /* 27 | This file is designed to create a normalized environment for compiling 28 | libretro-common's private implementations, or any other sources which might 29 | enjoy use of it's environment (RetroArch for instance). 30 | This should be an elaborately crafted environment so that sources don't 31 | need to be full of platform-specific workarounds. 32 | */ 33 | 34 | #if defined (__cplusplus) 35 | #if 0 36 | printf("This is C++, version %d.\n", __cplusplus); 37 | #endif 38 | /* The expected values would be 39 | * 199711L, for ISO/IEC 14882:1998 or 14882:2003 40 | */ 41 | 42 | #elif defined(__STDC__) 43 | /* This is standard C. */ 44 | 45 | #if (__STDC__ == 1) 46 | /* The implementation is ISO-conforming. */ 47 | #define __STDC_ISO__ 48 | #else 49 | /* The implementation is not ISO-conforming. */ 50 | #endif 51 | 52 | #if defined(__STDC_VERSION__) 53 | #if (__STDC_VERSION__ >= 201112L) 54 | /* This is C11. */ 55 | #define __STDC_C11__ 56 | #elif (__STDC_VERSION__ >= 199901L) 57 | /* This is C99. */ 58 | #define __STDC_C99__ 59 | #elif (__STDC_VERSION__ >= 199409L) 60 | /* This is C89 with amendment 1. */ 61 | #define __STDC_C89__ 62 | #define __STDC_C89_AMENDMENT_1__ 63 | #else 64 | /* This is C89 without amendment 1. */ 65 | #define __STDC_C89__ 66 | #endif 67 | #else /* !defined(__STDC_VERSION__) */ 68 | /* This is C89. __STDC_VERSION__ is not defined. */ 69 | #define __STDC_C89__ 70 | #endif 71 | 72 | #else /* !defined(__STDC__) */ 73 | /* This is not standard C. __STDC__ is not defined. */ 74 | #endif 75 | 76 | #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) 77 | /* Try to find out if we're compiling for WinRT or non-WinRT */ 78 | #if defined(_MSC_VER) && defined(__has_include) 79 | #if __has_include() 80 | #define HAVE_WINAPIFAMILY_H 1 81 | #else 82 | #define HAVE_WINAPIFAMILY_H 0 83 | #endif 84 | 85 | /* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */ 86 | #elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */ 87 | #define HAVE_WINAPIFAMILY_H 1 88 | #else 89 | #define HAVE_WINAPIFAMILY_H 0 90 | #endif 91 | 92 | #if HAVE_WINAPIFAMILY_H 93 | #include 94 | #define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)) 95 | #else 96 | #define WINAPI_FAMILY_WINRT 0 97 | #endif /* HAVE_WINAPIFAMILY_H */ 98 | 99 | #if WINAPI_FAMILY_WINRT 100 | #undef __WINRT__ 101 | #define __WINRT__ 1 102 | #endif 103 | 104 | /* MSVC obviously has to have some non-standard constants... */ 105 | #if _M_IX86_FP == 1 106 | #define __SSE__ 1 107 | #elif _M_IX86_FP == 2 || (defined(_M_AMD64) || defined(_M_X64)) 108 | #define __SSE__ 1 109 | #define __SSE2__ 1 110 | #endif 111 | 112 | #endif 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/retro_inline.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (retro_inline.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_INLINE_H 24 | #define __LIBRETRO_SDK_INLINE_H 25 | 26 | #ifndef INLINE 27 | 28 | #if defined(_WIN32) || defined(__INTEL_COMPILER) 29 | #define INLINE __inline 30 | #elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L 31 | #define INLINE inline 32 | #elif defined(__GNUC__) 33 | #define INLINE __inline__ 34 | #else 35 | #define INLINE 36 | #endif 37 | 38 | #endif 39 | #endif 40 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/streams/file_stream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (file_stream.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_FILE_STREAM_H 24 | #define __LIBRETRO_SDK_FILE_STREAM_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | #define FILESTREAM_REQUIRED_VFS_VERSION 2 42 | 43 | RETRO_BEGIN_DECLS 44 | 45 | typedef struct RFILE RFILE; 46 | 47 | #define FILESTREAM_REQUIRED_VFS_VERSION 2 48 | 49 | void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info); 50 | 51 | int64_t filestream_get_size(RFILE *stream); 52 | 53 | int64_t filestream_truncate(RFILE *stream, int64_t length); 54 | 55 | /** 56 | * filestream_open: 57 | * @path : path to file 58 | * @mode : file mode to use when opening (read/write) 59 | * @bufsize : optional buffer size (-1 or 0 to use default) 60 | * 61 | * Opens a file for reading or writing, depending on the requested mode. 62 | * Returns a pointer to an RFILE if opened successfully, otherwise NULL. 63 | **/ 64 | RFILE* filestream_open(const char *path, unsigned mode, unsigned hints); 65 | 66 | int64_t filestream_seek(RFILE *stream, int64_t offset, int seek_position); 67 | 68 | int64_t filestream_read(RFILE *stream, void *data, int64_t len); 69 | 70 | int64_t filestream_write(RFILE *stream, const void *data, int64_t len); 71 | 72 | int64_t filestream_tell(RFILE *stream); 73 | 74 | void filestream_rewind(RFILE *stream); 75 | 76 | int filestream_close(RFILE *stream); 77 | 78 | int64_t filestream_read_file(const char *path, void **buf, int64_t *len); 79 | 80 | char* filestream_gets(RFILE *stream, char *s, size_t len); 81 | 82 | int filestream_getc(RFILE *stream); 83 | 84 | int filestream_vscanf(RFILE *stream, const char* format, va_list *args); 85 | 86 | int filestream_scanf(RFILE *stream, const char* format, ...); 87 | 88 | int filestream_eof(RFILE *stream); 89 | 90 | bool filestream_write_file(const char *path, const void *data, int64_t size); 91 | 92 | int filestream_putc(RFILE *stream, int c); 93 | 94 | int filestream_vprintf(RFILE *stream, const char* format, va_list args); 95 | 96 | int filestream_printf(RFILE *stream, const char* format, ...); 97 | 98 | int filestream_error(RFILE *stream); 99 | 100 | int filestream_flush(RFILE *stream); 101 | 102 | int filestream_delete(const char *path); 103 | 104 | int filestream_rename(const char *old_path, const char *new_path); 105 | 106 | const char* filestream_get_path(RFILE *stream); 107 | 108 | bool filestream_exists(const char *path); 109 | 110 | /* Returned pointer must be freed by the caller. */ 111 | char* filestream_getline(RFILE *stream); 112 | 113 | libretro_vfs_implementation_file* filestream_get_vfs_handle(RFILE *stream); 114 | 115 | RETRO_END_DECLS 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/streams/file_stream_transforms.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (file_stream_transforms.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_FILE_STREAM_TRANSFORMS_H 24 | #define __LIBRETRO_SDK_FILE_STREAM_TRANSFORMS_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | RETRO_BEGIN_DECLS 32 | 33 | #ifndef SKIP_STDIO_REDEFINES 34 | 35 | #define FILE RFILE 36 | 37 | #undef fopen 38 | #undef fclose 39 | #undef ftell 40 | #undef fseek 41 | #undef fread 42 | #undef fgets 43 | #undef fgetc 44 | #undef fwrite 45 | #undef fputc 46 | #undef fflush 47 | #undef fprintf 48 | #undef ferror 49 | #undef feof 50 | #undef fscanf 51 | 52 | #define fopen rfopen 53 | #define fclose rfclose 54 | #define ftell rftell 55 | #define fseek rfseek 56 | #define fread rfread 57 | #define fgets rfgets 58 | #define fgetc rfgetc 59 | #define fwrite rfwrite 60 | #define fputc rfputc 61 | #define fflush rfflush 62 | #define fprintf rfprintf 63 | #define ferror rferror 64 | #define feof rfeof 65 | #define fscanf rfscanf 66 | 67 | #endif 68 | 69 | RFILE* rfopen(const char *path, const char *mode); 70 | 71 | int rfclose(RFILE* stream); 72 | 73 | int64_t rftell(RFILE* stream); 74 | 75 | int64_t rfseek(RFILE* stream, int64_t offset, int origin); 76 | 77 | int64_t rfread(void* buffer, 78 | size_t elem_size, size_t elem_count, RFILE* stream); 79 | 80 | char *rfgets(char *buffer, int maxCount, RFILE* stream); 81 | 82 | int rfgetc(RFILE* stream); 83 | 84 | int64_t rfwrite(void const* buffer, 85 | size_t elem_size, size_t elem_count, RFILE* stream); 86 | 87 | int rfputc(int character, RFILE * stream); 88 | 89 | int64_t rfflush(RFILE * stream); 90 | 91 | int rfprintf(RFILE * stream, const char * format, ...); 92 | 93 | int rferror(RFILE* stream); 94 | 95 | int rfeof(RFILE* stream); 96 | 97 | int rfscanf(RFILE * stream, const char * format, ...); 98 | 99 | RETRO_END_DECLS 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/time/rtime.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (rtime.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_RTIME_H__ 24 | #define __LIBRETRO_SDK_RTIME_H__ 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | RETRO_BEGIN_DECLS 33 | 34 | /* TODO/FIXME: Move all generic time handling functions 35 | * to this file */ 36 | 37 | /* Must be called before using rtime_localtime() */ 38 | void rtime_init(void); 39 | 40 | /* Must be called upon program termination */ 41 | void rtime_deinit(void); 42 | 43 | /* Thread-safe wrapper for localtime() */ 44 | struct tm *rtime_localtime(const time_t *timep, struct tm *result); 45 | 46 | RETRO_END_DECLS 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/vfs/vfs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (vfs_implementation.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_VFS_H 24 | #define __LIBRETRO_SDK_VFS_H 25 | 26 | #include 27 | #include 28 | 29 | #ifdef RARCH_INTERNAL 30 | #ifndef VFS_FRONTEND 31 | #define VFS_FRONTEND 32 | #endif 33 | #endif 34 | 35 | RETRO_BEGIN_DECLS 36 | 37 | #ifdef _WIN32 38 | typedef void* HANDLE; 39 | #endif 40 | 41 | #ifdef HAVE_CDROM 42 | typedef struct 43 | { 44 | int64_t byte_pos; 45 | char *cue_buf; 46 | size_t cue_len; 47 | unsigned cur_lba; 48 | unsigned last_frame_lba; 49 | unsigned char cur_min; 50 | unsigned char cur_sec; 51 | unsigned char cur_frame; 52 | unsigned char cur_track; 53 | unsigned char last_frame[2352]; 54 | char drive; 55 | bool last_frame_valid; 56 | } vfs_cdrom_t; 57 | #endif 58 | 59 | enum vfs_scheme 60 | { 61 | VFS_SCHEME_NONE = 0, 62 | VFS_SCHEME_CDROM 63 | }; 64 | 65 | #if !(defined(__WINRT__) && defined(__cplusplus_winrt)) 66 | #ifdef VFS_FRONTEND 67 | struct retro_vfs_file_handle 68 | #else 69 | struct libretro_vfs_implementation_file 70 | #endif 71 | { 72 | #ifdef HAVE_CDROM 73 | vfs_cdrom_t cdrom; /* int64_t alignment */ 74 | #endif 75 | int64_t size; 76 | uint64_t mappos; 77 | uint64_t mapsize; 78 | FILE *fp; 79 | #ifdef _WIN32 80 | HANDLE fh; 81 | #endif 82 | char *buf; 83 | char* orig_path; 84 | uint8_t *mapped; 85 | int fd; 86 | unsigned hints; 87 | enum vfs_scheme scheme; 88 | }; 89 | #endif 90 | 91 | /* Replace the following symbol with something appropriate 92 | * to signify the file is being compiled for a front end instead of a core. 93 | * This allows the same code to act as reference implementation 94 | * for VFS and as fallbacks for when the front end does not provide VFS functionality. 95 | */ 96 | 97 | #ifdef VFS_FRONTEND 98 | typedef struct retro_vfs_file_handle libretro_vfs_implementation_file; 99 | #else 100 | typedef struct libretro_vfs_implementation_file libretro_vfs_implementation_file; 101 | #endif 102 | 103 | #ifdef VFS_FRONTEND 104 | typedef struct retro_vfs_dir_handle libretro_vfs_implementation_dir; 105 | #else 106 | typedef struct libretro_vfs_implementation_dir libretro_vfs_implementation_dir; 107 | #endif 108 | 109 | RETRO_END_DECLS 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/include/vfs/vfs_implementation.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (vfs_implementation.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_VFS_IMPLEMENTATION_H 24 | #define __LIBRETRO_SDK_VFS_IMPLEMENTATION_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | RETRO_BEGIN_DECLS 33 | 34 | libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints); 35 | 36 | int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream); 37 | 38 | int retro_vfs_file_error_impl(libretro_vfs_implementation_file *stream); 39 | 40 | int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream); 41 | 42 | int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, int64_t length); 43 | 44 | int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream); 45 | 46 | int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream, int64_t offset, int seek_position); 47 | 48 | int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void *s, uint64_t len); 49 | 50 | int64_t retro_vfs_file_write_impl(libretro_vfs_implementation_file *stream, const void *s, uint64_t len); 51 | 52 | int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream); 53 | 54 | int retro_vfs_file_remove_impl(const char *path); 55 | 56 | int retro_vfs_file_rename_impl(const char *old_path, const char *new_path); 57 | 58 | const char *retro_vfs_file_get_path_impl(libretro_vfs_implementation_file *stream); 59 | 60 | int retro_vfs_stat_impl(const char *path, int32_t *size); 61 | 62 | int retro_vfs_mkdir_impl(const char *dir); 63 | 64 | libretro_vfs_implementation_dir *retro_vfs_opendir_impl(const char *dir, bool include_hidden); 65 | 66 | bool retro_vfs_readdir_impl(libretro_vfs_implementation_dir *dirstream); 67 | 68 | const char *retro_vfs_dirent_get_name_impl(libretro_vfs_implementation_dir *dirstream); 69 | 70 | bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *dirstream); 71 | 72 | int retro_vfs_closedir_impl(libretro_vfs_implementation_dir *dirstream); 73 | 74 | RETRO_END_DECLS 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/streams/file_stream_transforms.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (file_stream_transforms.c). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | RFILE* rfopen(const char *path, const char *mode) 30 | { 31 | RFILE *output = NULL; 32 | unsigned int retro_mode = RETRO_VFS_FILE_ACCESS_READ; 33 | bool position_to_end = false; 34 | 35 | if (strstr(mode, "r")) 36 | { 37 | retro_mode = RETRO_VFS_FILE_ACCESS_READ; 38 | if (strstr(mode, "+")) 39 | { 40 | retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE | 41 | RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING; 42 | } 43 | } 44 | else if (strstr(mode, "w")) 45 | { 46 | retro_mode = RETRO_VFS_FILE_ACCESS_WRITE; 47 | if (strstr(mode, "+")) 48 | retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE; 49 | } 50 | else if (strstr(mode, "a")) 51 | { 52 | retro_mode = RETRO_VFS_FILE_ACCESS_WRITE | 53 | RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING; 54 | position_to_end = true; 55 | if (strstr(mode, "+")) 56 | { 57 | retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE | 58 | RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING; 59 | } 60 | } 61 | 62 | output = filestream_open(path, retro_mode, 63 | RETRO_VFS_FILE_ACCESS_HINT_NONE); 64 | if (output && position_to_end) 65 | filestream_seek(output, 0, RETRO_VFS_SEEK_POSITION_END); 66 | 67 | return output; 68 | } 69 | 70 | int rfclose(RFILE* stream) 71 | { 72 | return filestream_close(stream); 73 | } 74 | 75 | int64_t rftell(RFILE* stream) 76 | { 77 | return filestream_tell(stream); 78 | } 79 | 80 | int64_t rfseek(RFILE* stream, int64_t offset, int origin) 81 | { 82 | int seek_position = -1; 83 | switch (origin) 84 | { 85 | case SEEK_SET: 86 | seek_position = RETRO_VFS_SEEK_POSITION_START; 87 | break; 88 | case SEEK_CUR: 89 | seek_position = RETRO_VFS_SEEK_POSITION_CURRENT; 90 | break; 91 | case SEEK_END: 92 | seek_position = RETRO_VFS_SEEK_POSITION_END; 93 | break; 94 | } 95 | 96 | return filestream_seek(stream, offset, seek_position); 97 | } 98 | 99 | int64_t rfread(void* buffer, 100 | size_t elem_size, size_t elem_count, RFILE* stream) 101 | { 102 | return (filestream_read(stream, buffer, elem_size * elem_count) / elem_size); 103 | } 104 | 105 | char *rfgets(char *buffer, int maxCount, RFILE* stream) 106 | { 107 | return filestream_gets(stream, buffer, maxCount); 108 | } 109 | 110 | int rfgetc(RFILE* stream) 111 | { 112 | return filestream_getc(stream); 113 | } 114 | 115 | int64_t rfwrite(void const* buffer, 116 | size_t elem_size, size_t elem_count, RFILE* stream) 117 | { 118 | return filestream_write(stream, buffer, elem_size * elem_count); 119 | } 120 | 121 | int rfputc(int character, RFILE * stream) 122 | { 123 | return filestream_putc(stream, character); 124 | } 125 | 126 | int64_t rfflush(RFILE * stream) 127 | { 128 | return filestream_flush(stream); 129 | } 130 | 131 | int rfprintf(RFILE * stream, const char * format, ...) 132 | { 133 | int result; 134 | va_list vl; 135 | va_start(vl, format); 136 | result = filestream_vprintf(stream, format, vl); 137 | va_end(vl); 138 | return result; 139 | } 140 | 141 | int rferror(RFILE* stream) 142 | { 143 | return filestream_error(stream); 144 | } 145 | 146 | int rfeof(RFILE* stream) 147 | { 148 | return filestream_eof(stream); 149 | } 150 | 151 | int rfscanf(RFILE * stream, const char * format, ...) 152 | { 153 | int result; 154 | va_list vl; 155 | va_start(vl, format); 156 | result = filestream_vscanf(stream, format, &vl); 157 | va_end(vl); 158 | return result; 159 | } 160 | -------------------------------------------------------------------------------- /libgambatte/libretro-common/time/rtime.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2020 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (rtime.c). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifdef HAVE_THREADS 24 | #include 25 | #include 26 | #include 27 | #endif 28 | 29 | #include 30 | #include