├── .github ├── ISSUE_TEMPLATE │ ├── bugs.yml │ ├── config.yml │ └── feature-request.yml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── build.yaml ├── .gitignore ├── LICENSE.txt ├── Makefile ├── README.md ├── Zelda3.sln ├── assets ├── .gitignore ├── compile_music.py ├── compile_resources.py ├── decode_music.py ├── extract_music.py ├── extract_resources.py ├── palette_usage.bin ├── restool.py ├── sprite_sheet_info.py ├── sprite_sheets.py ├── sprites │ └── .gitignore ├── tables.py ├── text_compression.py └── util.py ├── extract_assets.bat ├── other ├── 3x5_font.png ├── extract_snapshot_log.py ├── glitches_faq.txt ├── make_text_dict.py ├── msu │ └── encode_opus.py ├── name_remap.txt ├── names.txt └── replace_in_files.py ├── packages.config ├── platform └── vita │ ├── Makefile │ ├── bg.png │ ├── icon0.png │ ├── pic0.png │ ├── startup.png │ ├── template.xml │ └── zelda3.ini ├── requirements.txt ├── run_with_tcc.bat ├── saves └── ref │ ├── Chapter 1 - Zelda's Rescue.sav │ ├── Chapter 10 - After Ice Palace.sav │ ├── Chapter 11 - After Misery Mire.sav │ ├── Chapter 12 - After Turtle Rock.sav │ ├── Chapter 13 - After Ganon's Tower.sav │ ├── Chapter 2 - After Eastern Palace.sav │ ├── Chapter 3 - After Desert Palace.sav │ ├── Chapter 4 - After Tower of Hera.sav │ ├── Chapter 5 - After Hyrule Castle Tower.sav │ ├── Chapter 6 - After Dark Palace.sav │ ├── Chapter 7 - After Swamp Palace.sav │ ├── Chapter 8 - After Skull Woods.sav │ └── Chapter 9 - After Gargoyle's Domain.sav ├── snes ├── apu.c ├── apu.h ├── cart.c ├── cart.h ├── cpu.c ├── cpu.h ├── dma.c ├── dma.h ├── dsp.c ├── dsp.h ├── dsp_regs.h ├── input.c ├── input.h ├── ppu.c ├── ppu.h ├── saveload.h ├── snes.c ├── snes.h ├── snes_other.c ├── snes_regs.h ├── spc.c ├── spc.h ├── tracing.c └── tracing.h ├── src ├── ancilla.c ├── ancilla.h ├── assets.h ├── attract.c ├── attract.h ├── audio.c ├── audio.h ├── config.c ├── config.h ├── dungeon.c ├── dungeon.h ├── ending.c ├── ending.h ├── features.h ├── glsl_shader.c ├── glsl_shader.h ├── hud.c ├── hud.h ├── load_gfx.c ├── load_gfx.h ├── main.c ├── messaging.c ├── messaging.h ├── misc.c ├── misc.h ├── nmi.c ├── nmi.h ├── opengl.c ├── overlord.c ├── overlord.h ├── overworld.c ├── overworld.h ├── platform │ ├── switch │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── icon.jpg │ │ └── zelda3.ini │ └── win32 │ │ ├── resource.h │ │ ├── triforce.ico │ │ ├── volume_control.c │ │ ├── volume_control.h │ │ └── zelda3.rc ├── player.c ├── player.h ├── player_oam.c ├── player_oam.h ├── poly.c ├── poly.h ├── select_file.c ├── select_file.h ├── spc_player.c ├── spc_player.h ├── sprite.c ├── sprite.h ├── sprite_main.c ├── sprite_main.h ├── tagalong.c ├── tagalong.h ├── tile_detect.c ├── tile_detect.h ├── types.h ├── util.c ├── util.h ├── variables.h ├── zelda_cpu_infra.c ├── zelda_cpu_infra.h ├── zelda_rtl.c └── zelda_rtl.h ├── third_party ├── .gitignore ├── gl_core │ ├── gl_core_3_1.c │ └── gl_core_3_1.h ├── opus-1.3.1-stripped │ ├── .gitignore │ ├── AUTHORS │ ├── COPYING │ ├── README │ ├── _kiss_fft_guts.h │ ├── arch.h │ ├── arm │ │ ├── arm2gnu.pl │ │ ├── arm_celt_map.c │ │ ├── armcpu.c │ │ ├── armcpu.h │ │ ├── armopts.s.in │ │ ├── celt_fft_ne10.c │ │ ├── celt_mdct_ne10.c │ │ ├── celt_neon_intr.c │ │ ├── celt_pitch_xcorr_arm-gnu.S │ │ ├── celt_pitch_xcorr_arm.s │ │ ├── fft_arm.h │ │ ├── fixed_arm64.h │ │ ├── fixed_armv4.h │ │ ├── fixed_armv5e.h │ │ ├── kiss_fft_armv4.h │ │ ├── kiss_fft_armv5e.h │ │ ├── mdct_arm.h │ │ ├── pitch_arm.h │ │ └── pitch_neon_intr.c │ ├── bands.c │ ├── bands.h │ ├── celt.c │ ├── celt.h │ ├── celt_decoder.c │ ├── config.h │ ├── cpu_support.h │ ├── cwrs.c │ ├── cwrs.h │ ├── ecintrin.h │ ├── entcode.c │ ├── entcode.h │ ├── entdec.c │ ├── entdec.h │ ├── float_cast.h │ ├── kiss_fft.c │ ├── kiss_fft.h │ ├── laplace.c │ ├── laplace.h │ ├── mathops.c │ ├── mathops.h │ ├── mdct.c │ ├── mdct.h │ ├── mfrngcod.h │ ├── mips │ │ ├── celt_mipsr1.h │ │ ├── fixed_generic_mipsr1.h │ │ ├── kiss_fft_mipsr1.h │ │ ├── mdct_mipsr1.h │ │ ├── pitch_mipsr1.h │ │ └── vq_mipsr1.h │ ├── modes.c │ ├── modes.h │ ├── opus.c │ ├── opus.h │ ├── opus_custom.h │ ├── opus_decoder.c │ ├── opus_decoder_amalgam.c │ ├── opus_defines.h │ ├── opus_private.h │ ├── opus_types.h │ ├── os_support.h │ ├── pitch.h │ ├── quant_bands.c │ ├── quant_bands.h │ ├── rate.c │ ├── rate.h │ ├── stack_alloc.h │ ├── static_modes_float.h │ ├── static_modes_float_arm_ne10.h │ ├── vq.c │ ├── vq.h │ └── x86 │ │ ├── pitch_sse.c │ │ ├── pitch_sse.h │ │ ├── pitch_sse2.c │ │ ├── vq_sse.h │ │ ├── x86cpu.c │ │ └── x86cpu.h └── stb │ └── stb_image.h ├── zelda3.ini ├── zelda3.vcxproj └── zelda3.vcxproj.filters /.github/ISSUE_TEMPLATE/bugs.yml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: Report bugs here. 3 | labels: [bug] 4 | body: 5 | - type: textarea 6 | id: description 7 | attributes: 8 | label: "Describe your bug here. And how to reproduce it." 9 | validations: 10 | required: true 11 | 12 | 13 | - type: dropdown 14 | id: btarget 15 | attributes: 16 | label: "What is your build target?" 17 | options: 18 | - "Windows" 19 | - "Linux" 20 | - "Mac" 21 | - "Nintendo Switch" 22 | validations: 23 | required: true 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: [] -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Ask for a feature or just give ideas! 3 | labels: [enhancement] 4 | body: 5 | - type: textarea 6 | attributes: 7 | label: What feature do you want to get added? And how it will work? 8 | validations: 9 | required: true 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | 4 | ### Will this Pull Request break anything? 5 | 6 | 7 | ### Suggested Testing Steps 8 | 9 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | workflow_dispatch: 9 | 10 | jobs: 11 | build-unix: 12 | name: on ${{ matrix.name }} 13 | runs-on: ${{ matrix.os }} 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | include: 18 | - name: Linux 19 | os: ubuntu-latest 20 | - name: Mac 21 | os: macos-latest 22 | steps: 23 | - uses: actions/checkout@v3 24 | - uses: actions/setup-python@v4 25 | with: 26 | python-version: '3.10' 27 | - name: Install dependencies for Linux 28 | if: ${{ matrix.name == 'Linux' }} 29 | run: | 30 | sudo apt update 31 | sudo apt install -y libsdl2-dev 32 | - name: Install dependencies for Mac 33 | if: ${{ matrix.name == 'Mac' }} 34 | run: | 35 | brew install sdl2 coreutils 36 | - name: Build 37 | run: make -j$(nproc) zelda3 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.vs/ 2 | /packages/ 3 | /.vscode/ 4 | .DS_Store 5 | *.dSYM 6 | /*.vcxproj.user 7 | *.aps 8 | /obj/ 9 | /bin/ 10 | /assets/overworld/*.yaml 11 | /assets/dungeon/*.yaml 12 | /assets/img/ 13 | /assets/old/ 14 | /zelda3.sfc 15 | /zelda3.smc 16 | /saves/*.sav 17 | /saves/sram.dat 18 | /saves/sram.bak 19 | /zelda3 20 | __pycache__ 21 | /src/*.o 22 | /*.exe 23 | /*.out 24 | /snes/*.o 25 | /msu/ 26 | /tmp/ 27 | /zelda3_assets.dat 28 | /SDL2.dll 29 | /zelda3.*.ini 30 | /zelda3.wiki 31 | /sprites-gfx 32 | /glsl-shaders 33 | /token.txt 34 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 snesrev 4 | Copyright (c) 2021 elzo_d 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | 25 | This is the license for Opus: 26 | 27 | /* Copyright (c) 2007-2008 CSIRO 28 | Copyright (c) 2007-2009 Xiph.Org Foundation 29 | Copyright (c) 2008-2009 Gregory Maxwell 30 | Written by Jean-Marc Valin and Gregory Maxwell */ 31 | /* 32 | Redistribution and use in source and binary forms, with or without 33 | modification, are permitted provided that the following conditions 34 | are met: 35 | 36 | - Redistributions of source code must retain the above copyright 37 | notice, this list of conditions and the following disclaimer. 38 | 39 | - Redistributions in binary form must reproduce the above copyright 40 | notice, this list of conditions and the following disclaimer in the 41 | documentation and/or other materials provided with the distribution. 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 46 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 47 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 48 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 49 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 50 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 51 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 52 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 53 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 | */ 55 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TARGET_EXEC:=zelda3 2 | ROM:=tables/zelda3.sfc 3 | SRCS:=$(wildcard src/*.c snes/*.c) third_party/gl_core/gl_core_3_1.c third_party/opus-1.3.1-stripped/opus_decoder_amalgam.c 4 | OBJS:=$(SRCS:%.c=%.o) 5 | PYTHON:=/usr/bin/env python3 6 | CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-O2 -Werror) -I . 7 | CFLAGS:=${CFLAGS} $(shell sdl2-config --cflags) -DSYSTEM_VOLUME_MIXER_AVAILABLE=0 8 | 9 | ifeq (${OS},Windows_NT) 10 | WINDRES:=windres 11 | RES:=zelda3.res 12 | SDLFLAGS:=-Wl,-Bstatic $(shell sdl2-config --static-libs) 13 | else 14 | SDLFLAGS:=$(shell sdl2-config --libs) -lm 15 | endif 16 | 17 | .PHONY: all clean clean_obj clean_gen 18 | 19 | all: $(TARGET_EXEC) zelda3_assets.dat 20 | $(TARGET_EXEC): $(OBJS) $(RES) 21 | $(CC) $^ -o $@ $(LDFLAGS) $(SDLFLAGS) 22 | %.o : %.c 23 | $(CC) -c $(CFLAGS) $< -o $@ 24 | 25 | $(RES): src/platform/win32/zelda3.rc 26 | @echo "Generating Windows resources" 27 | @$(WINDRES) $< -O coff -o $@ 28 | 29 | zelda3_assets.dat: 30 | @echo "Extracting game resources" 31 | $(PYTHON) assets/restool.py --extract-from-rom 32 | 33 | clean: clean_obj clean_gen 34 | clean_obj: 35 | @$(RM) $(OBJS) $(TARGET_EXEC) 36 | clean_gen: 37 | @$(RM) $(RES) zelda3_assets.dat tables/zelda3_assets.dat tables/*.txt tables/*.png tables/sprites/*.png tables/*.yaml 38 | @rm -rf tables/__pycache__ tables/dungeon tables/img tables/overworld tables/sound 39 | -------------------------------------------------------------------------------- /Zelda3.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30717.126 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zelda3", "zelda3.vcxproj", "{CB07E01D-A194-481A-BEA1-DC13756AD150}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F140B55D-AB87-442A-BA26-8CBB59C574BE}" 9 | ProjectSection(SolutionItems) = preProject 10 | .gitignore = .gitignore 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|x64 = Debug|x64 16 | Debug|x86 = Debug|x86 17 | Release|x64 = Release|x64 18 | Release|x86 = Release|x86 19 | ReleaseDeploy|x64 = ReleaseDeploy|x64 20 | ReleaseDeploy|x86 = ReleaseDeploy|x86 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.Debug|x64.ActiveCfg = Debug|x64 24 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.Debug|x64.Build.0 = Debug|x64 25 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.Debug|x86.ActiveCfg = Debug|Win32 26 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.Debug|x86.Build.0 = Debug|Win32 27 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.Release|x64.ActiveCfg = Release|x64 28 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.Release|x64.Build.0 = Release|x64 29 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.Release|x86.ActiveCfg = Release|Win32 30 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.Release|x86.Build.0 = Release|Win32 31 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.ReleaseDeploy|x64.ActiveCfg = ReleaseDeploy|x64 32 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.ReleaseDeploy|x64.Build.0 = ReleaseDeploy|x64 33 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.ReleaseDeploy|x86.ActiveCfg = ReleaseDeploy|Win32 34 | {CB07E01D-A194-481A-BEA1-DC13756AD150}.ReleaseDeploy|x86.Build.0 = ReleaseDeploy|Win32 35 | EndGlobalSection 36 | GlobalSection(SolutionProperties) = preSolution 37 | HideSolutionNode = FALSE 38 | EndGlobalSection 39 | GlobalSection(NestedProjects) = preSolution 40 | {EEFFA9B7-67F6-49EF-9FFE-88B0AC6983C3} = {F140B55D-AB87-442A-BA26-8CBB59C574BE} 41 | {DB1FCD75-2215-46F9-8F60-B200B2747834} = {EEFFA9B7-67F6-49EF-9FFE-88B0AC6983C3} 42 | EndGlobalSection 43 | GlobalSection(ExtensibilityGlobals) = postSolution 44 | SolutionGuid = {E47623E3-1B23-4ED7-8FC1-3E1F0AD82DD0} 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /assets/.gitignore: -------------------------------------------------------------------------------- 1 | zelda3.sfc 2 | dialogue*.txt 3 | generated_*.h 4 | linksprite.png 5 | map32_to_map16.txt 6 | music_info.yaml 7 | sfx.txt 8 | /sound 9 | sound_ending.txt 10 | sound_indoor.txt 11 | sound_intro.txt 12 | /hud_icons.png 13 | /font*.png 14 | 15 | -------------------------------------------------------------------------------- /assets/palette_usage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/assets/palette_usage.bin -------------------------------------------------------------------------------- /assets/restool.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import util 3 | import sys 4 | import os 5 | 6 | os.chdir(os.path.dirname(__file__)) 7 | 8 | 9 | parser = argparse.ArgumentParser(description='Resource tool used to build zelda3_assets.dat', allow_abbrev=False) 10 | parser.add_argument('-r', '--rom', nargs='?', metavar='ROM') 11 | parser.add_argument('--extract-from-rom', '-e', action='store_true', help='Extract/overwrite things from the ROM') 12 | 13 | optional = parser.add_argument_group('Language settings') 14 | optional.add_argument('--extract-dialogue', action='store_true', help = 'Extract dialogue from a translated ROM') 15 | optional.add_argument('--languages', action='store', metavar='L1,L2', help = 'Comma separated list of additional languages to build (de,fr,fr-c,en,es,pl,pt,redux,nl,sv).') 16 | 17 | optional = parser.add_argument_group('Debug things') 18 | optional.add_argument('--no-build', action='store_true', help="Don't actually build zelda3_assets.dat") 19 | optional.add_argument('--print-strings', action='store_true', help="Print all dialogue strings") 20 | optional.add_argument('--print-assets-header', action='store_true') 21 | 22 | optional = parser.add_argument_group('Image handling') 23 | optional.add_argument('--sprites-from-png', action='store_true', help="When compiling, load sprites from png instead of from ROM") 24 | 25 | args = parser.parse_args() 26 | 27 | if args.extract_dialogue: 28 | ROM = util.load_rom(args.rom, True) 29 | import extract_resources, sprite_sheets 30 | sprite_sheets.decode_font() 31 | extract_resources.print_dialogue() 32 | sys.exit(0) 33 | 34 | ROM = util.load_rom(args.rom) 35 | 36 | want_compile = True 37 | 38 | if args.extract_from_rom: 39 | import extract_resources 40 | extract_resources.main() 41 | 42 | if args.print_strings: 43 | import text_compression 44 | text_compression.print_strings(ROM) 45 | want_compile = False 46 | 47 | if want_compile and not args.no_build: 48 | import compile_resources 49 | compile_resources.main(args) 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /assets/sprites/.gitignore: -------------------------------------------------------------------------------- 1 | /*.png 2 | -------------------------------------------------------------------------------- /extract_assets.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | 2>nul (del zelda3_assets.dat) 4 | python assets/restool.py --extract-from-rom 5 | IF NOT ERRORLEVEL 0 goto ERROR 6 | 7 | IF NOT EXIST "zelda3_assets.dat" ( 8 | ECHO ERROR: The python program didn't generate zelda3_assets.dat successfully. 9 | goto ERROR 10 | ) ELSE ( 11 | REM 12 | ) 13 | 14 | goto DONE 15 | 16 | 17 | :ERROR 18 | ECHO: 19 | ECHO ERROR: Asset extraction failed! 20 | pause 21 | EXIT /B 1 22 | 23 | :DONE 24 | echo Complete! 25 | pause -------------------------------------------------------------------------------- /other/3x5_font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/other/3x5_font.png -------------------------------------------------------------------------------- /other/extract_snapshot_log.py: -------------------------------------------------------------------------------- 1 | import struct 2 | import sys 3 | 4 | data = open(sys.argv[1], 'rb').read() 5 | 6 | ver, total_frames, log_size, last_inputs = struct.unpack_from('IIII', data) 7 | 8 | log = data[32:32+log_size] 9 | 10 | KEYS = "AXsSUDLRBY" 11 | 12 | keys_memo = {} 13 | def get_keys(i): 14 | if i not in keys_memo: 15 | keys_memo[i] = "".join(k for j, k in enumerate(KEYS) if i & (1 << j)) 16 | return keys_memo[i] 17 | 18 | frame_ctr = 0 19 | bb = iter(log) 20 | 21 | try: 22 | while True: 23 | cmd = bb.__next__() 24 | mask = 0xf if cmd < 0xc0 else 1 25 | frames = cmd & mask 26 | if frames == mask: 27 | while True: 28 | t = bb.__next__() 29 | frames += t 30 | if t != 255: 31 | break 32 | frame_ctr += frames 33 | if cmd < 0xc0: 34 | last_inputs ^= 1 << (cmd >> 4) 35 | print('%d: %s' % (frame_ctr, get_keys(last_inputs))) 36 | elif cmd < 0xd0: 37 | nb = 1 + ((cmd >> 2) & 3) 38 | addr = ((cmd >> 1) & 1) << 16 39 | addr |= bb.__next__() << 8 40 | addr |= bb.__next__() 41 | for i in range(nb): 42 | bb.__next__() 43 | print('%d: patchbytes(0x%x)' % (frame_ctr, addr)) 44 | else: 45 | assert 0 46 | except StopIteration: 47 | pass 48 | -------------------------------------------------------------------------------- /other/make_text_dict.py: -------------------------------------------------------------------------------- 1 | import array 2 | 3 | memos = {} 4 | memoslist = [] 5 | def memo(s): 6 | m = memos.get(s) 7 | if m == None: 8 | m = len(memoslist) 9 | memos[s] = m 10 | memoslist.append(s) 11 | return m 12 | 13 | def tos(s): return "".join(memoslist[c] for c in s) 14 | 15 | lines = [] 16 | for line in open('dialogue.txt', 'r').read().splitlines(): 17 | line = line.split(': ')[1] 18 | 19 | r = array.array('H') 20 | 21 | i = 0 22 | while i < len(line): 23 | if line[i] == '[': 24 | j = line.index(']', i + 1) 25 | r.append(memo(line[i:j+1])) 26 | i = j + 1 27 | else: 28 | r.append(memo(line[i])) 29 | i += 1 30 | 31 | #print(repr(line)) 32 | #print(r) 33 | lines.append(list(r)) 34 | import collections 35 | 36 | 37 | def find_all_ngrams(lines, N, cost): 38 | ctr = collections.Counter() 39 | for line in lines: 40 | for i in range(len(line) - N + 1): 41 | if line[i] != line[i+1]: 42 | ctr[tuple(line[i:i+N])] += 1 43 | r = list((b, a) for a, b in ctr.items() if b >= 2) 44 | if len(r) == 0: 45 | return None, 0 46 | b, a = max(r) 47 | return a, (N - cost) * b - N - 2 # 2 is the overhead of the dict 48 | 49 | def find_best_ngram(cost): 50 | best_score=0 51 | 52 | for i in range(2, 32): 53 | text, score = find_all_ngrams(lines, i, cost) 54 | if score > best_score: 55 | best_score = score 56 | best_text = text 57 | return best_score, best_text 58 | 59 | def update_ngrams(lines, replace_from, replace_to): 60 | for line in lines: 61 | for i in range(len(line) - len(replace_from) + 1): 62 | if tuple(line[i:i+len(replace_from)]) == replace_from: 63 | line[i:i+len(replace_from)] = replace_to 64 | 65 | total_gain = 0 66 | 67 | original_tokens = sum(len(line) for line in lines) 68 | 69 | 70 | kTextDictionary_US = [ 71 | ' ', ' ', ' ', "'s ", 'and ', 72 | 'are ', 'all ', 'ain', 'and', 'at ', 73 | 'ast', 'an', 'at', 'ble', 'ba', 74 | 'be', 'bo', 'can ', 'che', 'com', 75 | 'ck', 'des', 'di', 'do', 'en ', 76 | 'er ', 'ear', 'ent', 'ed ', 'en', 77 | 'er', 'ev', 'for', 'fro', 'give ', 78 | 'get', 'go', 'have', 'has', 'her', 79 | 'hi', 'ha', 'ight ', 'ing ', 'in', 80 | 'is', 'it', 'just', 'know', 'ly ', 81 | 'la', 'lo', 'man', 'ma', 'me', 82 | 'mu', "n't ", 'non', 'not', 'open', 83 | 'ound', 'out ', 'of', 'on', 'or', 84 | 'per', 'ple', 'pow', 'pro', 're ', 85 | 're', 'some', 'se', 'sh', 'so', 86 | 'st', 'ter ', 'thin', 'ter', 'tha', 87 | 'the', 'thi', 'to', 'tr', 'up', 88 | 'ver', 'with', 'wa', 'we', 'wh', 89 | 'wi', 'you', 'Her', 'Tha', 'The', 90 | 'Thi', 'You', 91 | ] 92 | 93 | 94 | dictionary = [] 95 | 96 | for i in range(111+256): 97 | best_score, best_text = find_best_ngram(1 if i < 111 else 2) 98 | if best_score == 0: 99 | break 100 | 101 | total_gain += best_score 102 | 103 | print(f'Removed best bigram "{tos(best_text)}" with gain {best_score}, total gain {total_gain} / {original_tokens}') 104 | 105 | dictionary.append(best_text) 106 | 107 | update_ngrams(lines, best_text, [memo('{%s}' % tos(best_text))]) 108 | 109 | #print('kTextDictionary_NEW = [') 110 | #for i, d in enumerate(dictionary): 111 | # repl = tos(d).replace('{', '').replace('}', '') 112 | # print(f'{repr(repl)},') 113 | #print(']') 114 | 115 | 116 | for i, a in enumerate(lines): 117 | print(i, tos(a)) 118 | -------------------------------------------------------------------------------- /other/msu/encode_opus.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import concurrent.futures 3 | import opuslib 4 | import struct 5 | import samplerate # pip install samplerate 6 | import numpy as np 7 | 8 | # File format 9 | # 4 byte: OPUZ 10 | # 4 byte: VERSION = 0 11 | # Foreach Repeat Entry { 12 | # 4 byte: seek to file offset 13 | # 4 byte: num pcm samples to play from here 14 | # 2 byte: # samples to skip + flags 15 | # } 16 | 17 | def encode_to_msu_opus(msu_infile, bitrate = 128000): 18 | raw_msu1 = bytearray(open(msu_infile, 'rb').read()) 19 | 20 | if raw_msu1[:4] != b'MSU1': 21 | raise Exception('Expecting MSU1 file') 22 | msu_repeat_pos, = struct.unpack_from('= 48 or kMsuTracksWithRepeat[i]) 122 | 123 | with concurrent.futures.ThreadPoolExecutor() as executor: 124 | results = [executor.submit(task, i) for i in range(1, 115)] 125 | 126 | for future in concurrent.futures.as_completed(results): 127 | result = future.result() 128 | 129 | -------------------------------------------------------------------------------- /other/replace_in_files.py: -------------------------------------------------------------------------------- 1 | import os, re, sys, glob 2 | 3 | repl = open(sys.argv[1],'r').read().splitlines() 4 | repl = [a.split(' ') for a in repl] 5 | repl_dict = dict(repl) 6 | 7 | c = re.compile('\\b(' + "|".join(a[0] for a in repl) + ')\\b') 8 | 9 | def replacer(m): 10 | return repl_dict[m.group(0)] 11 | 12 | def replace_in_file(fname): 13 | s = open(fname, 'r').read() 14 | s_org = s 15 | 16 | s, num = c.subn(replacer, s) 17 | print(num) 18 | if num: 19 | assert s != s_org 20 | open(fname, 'w').write(s) 21 | 22 | 23 | 24 | for filename in glob.glob('*.c') + glob.glob('*.h'): 25 | replace_in_file(filename) 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /platform/vita/Makefile: -------------------------------------------------------------------------------- 1 | TARGET := zelda3 2 | TITLE := ZELDASNES 3 | SOURCES := ../.. ../../src ../../snes 4 | 5 | LIBS = -lSDL2_mixer -lSDL2_image -lSDL2 -lpng -lwebp -ljpeg -lmikmod -lz -lm -lvita2d \ 6 | -lstdc++ -lsndfile -lvorbis -lvorbisenc -lvorbisfile -logg -lcurl -lssl -lSceIme_stub \ 7 | -lcrypto -lFLAC -lopenal -limgui -lvitaGL -lvitashark -lSceShaccCgExt -lmathneon -lopus \ 8 | -lmpg123 -ltaihen_stub -lkubridge_stub -lSceAppMgr_stub -lSceAppUtil_stub -lSceAudio_stub \ 9 | -lSceAudioIn_stub -lSceCtrl_stub -lSceCommonDialog_stub -lSceDisplay_stub -lSceFios2_stub \ 10 | -lSceGxm_stub -lSceLibcBridge_stub -lSceShaccCg_stub -lSceSysmodule_stub -lScePower_stub \ 11 | -lSceTouch_stub -lSceMotion_stub -lSceHid_stub -lSceVshBridge_stub -lSceKernelDmacmgr_stub 12 | 13 | CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) 14 | CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) 15 | BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin)) 16 | OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 17 | 18 | PREFIX = arm-vita-eabi 19 | CC = $(PREFIX)-gcc 20 | CXX = $(PREFIX)-g++ 21 | CFLAGS = -g -Wl,-q,--wrap,fopen,--wrap,mkdir -O3 -ffast-math -DSTBI_NO_THREAD_LOCALS \ 22 | -I$(VITASDK)/$(PREFIX)/include/SDL2 -fno-tree-vectorize -DNDEBUG -I../.. 23 | CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive 24 | ASFLAGS = $(CFLAGS) 25 | 26 | all: $(TARGET).vpk 27 | 28 | $(TARGET).vpk: $(TARGET).velf 29 | vita-make-fself -c -s $< eboot.bin 30 | vita-mksfoex -s TITLE_ID=$(TITLE) "Zelda: A Link to the Past" param.sfo 31 | vita-pack-vpk -s param.sfo -b eboot.bin \ 32 | --add icon0.png=sce_sys/icon0.png \ 33 | --add bg.png=sce_sys/livearea/contents/bg.png \ 34 | --add pic0.png=sce_sys/pic0.png \ 35 | --add startup.png=sce_sys/livearea/contents/startup.png \ 36 | --add template.xml=sce_sys/livearea/contents/template.xml \ 37 | $(TARGET).vpk 38 | 39 | %.velf: %.elf 40 | cp $< $<.unstripped.elf 41 | $(PREFIX)-strip -g $< 42 | vita-elf-create $< $@ 43 | 44 | $(TARGET).elf: $(OBJS) 45 | $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ 46 | 47 | clean: 48 | @rm -rf $(TARGET).velf $(TARGET).elf $(TARGET).sysvelf $(OBJS) 49 | -------------------------------------------------------------------------------- /platform/vita/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/platform/vita/bg.png -------------------------------------------------------------------------------- /platform/vita/icon0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/platform/vita/icon0.png -------------------------------------------------------------------------------- /platform/vita/pic0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/platform/vita/pic0.png -------------------------------------------------------------------------------- /platform/vita/startup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/platform/vita/startup.png -------------------------------------------------------------------------------- /platform/vita/template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bg.png 6 | 7 | 8 | 9 | startup.png 10 | 11 | 12 | -------------------------------------------------------------------------------- /platform/vita/zelda3.ini: -------------------------------------------------------------------------------- 1 | [General] 2 | # Automatically save state on quit and reload on start 3 | Autosave = 0 4 | DisplayPerfInTitle = 0 5 | 6 | # Extended aspect ratio, either 16:9, 16:10, or 18:9. 4:3 means normal aspect ratio. 7 | # Add ", unchanged_sprites" to avoid changing sprite spawn/die behavior. Without this 8 | # replays will be incompatible. 9 | # Add ", no_visual_fixes" to avoid fixing some graphics glitches (for example with Cape). 10 | # It won't affect replays/game behavior but the memory compare will not work. 11 | # Add "extend_y, " right before the aspect radio specifier to display 240 lines instead of 224. 12 | ExtendedAspectRatio = 16:9 13 | 14 | 15 | [Graphics] 16 | # Window size ( Auto or WidthxHeight ) 17 | WindowSize = 960x544 18 | # Fullscreen mode (0=windowed, 1=desktop fullscreen, 2=fullscreen w/mode change) 19 | Fullscreen = 0 20 | # Window scale (1=100%, 2=200%, 3=300%, etc.) 21 | WindowScale = 1 22 | NewRenderer = 1 23 | EnhancedMode7 = 0 24 | IgnoreAspectRatio = 0 25 | BilinearFiltering = 0 26 | 27 | # Enable this option to remove the sprite limits per scan line 28 | NoSpriteLimits = 1 29 | 30 | # Change the appearance of Link by loading a ZSPR file 31 | # See all sprites here: https://snesrev.github.io/sprites-gfx/snes/zelda3/link/ 32 | # Download the files with "git clone https://github.com/snesrev/sprites-gfx.git" 33 | # LinkGraphics = sprites-gfx/snes/zelda3/link/sheets/megaman-x.2.zspr 34 | 35 | 36 | [Sound] 37 | EnableAudio = 1 38 | 39 | # DSP frequency in samples per second (e.g. 48000, 44100, 32000, 22050, 11025) 40 | AudioFreq = 44100 41 | # number of separate sound channels (1=mono, 2=stereo) 42 | AudioChannels = 2 43 | # Audio buffer size in samples (power of 2; e.g., 4096, 2048, 1024) [try 1024 if sound is crackly]. The higher the more lag before you hear sounds. 44 | AudioSamples = 1024 45 | 46 | # Enable MSU support for audio. Files need to be in a subfolder, msu/alttp_msu-*.pcm 47 | # Only works with 44100 hz and 2 channels 48 | EnableMSU = 0 49 | 50 | 51 | [Features] 52 | # Item switch on L/R. Also allows reordering of items in inventory by pressing Y+direction 53 | # Hold X inside of the item selection screen to reassign the X key into a separate item slot. 54 | # When X is assigned to an item, the Select key is used to enter the map. Press Select inside 55 | # of the Start menu to see the old select options. 56 | ItemSwitchLR = 0 57 | 58 | # Allow turning while dashing 59 | TurnWhileDashing = 0 60 | 61 | # Allow mirror to be used to warp to the Dark World 62 | MirrorToDarkworld = 0 63 | 64 | # Collect items (like hearts) with sword instead of having to touch them 65 | CollectItemsWithSword = 0 66 | 67 | # Level 2-4 sword can be used to break pots 68 | BreakPotsWithSword = 0 69 | 70 | # Disable the low health beep 71 | DisableLowHealthBeep = 0 72 | 73 | # Avoid waiting too much at the start 74 | SkipIntroOnKeypress = 0 75 | 76 | # Display max rupees/bombs/arrows with orange/yellow color 77 | ShowMaxItemsInYellow = 0 78 | 79 | # Allows up to four bombs active at a time instead of two. 80 | MoreActiveBombs = 0 81 | 82 | # Can carry 9999 rupees instead of 999 83 | CarryMoreRupees = 0 84 | 85 | # Enable various zelda bug fixes 86 | MiscBugFixes = 0 87 | 88 | # Enable some more advanced zelda bugfixes that change game behavior 89 | GameChangingBugFixes = 0 90 | 91 | # Allow bird travel to be cancelled by hitting the X key 92 | CancelBirdTravel = 0 93 | 94 | 95 | [KeyMap] 96 | # Change what keyboard keys map to the joypad 97 | # Order: Up, Down, Left, Right, Select, Start, A, B, X, Y, L, R 98 | 99 | # This default is suitable for QWERTY keyboards. 100 | Controls = Up, Down, Left, Right, Right Shift, Return, x, z, s, a, c, v 101 | 102 | # This default is suitable for QWERTZ keyboards. 103 | #Controls = Up, Down, Left, Right, Right Shift, Return, x, y, s, a, c, v 104 | 105 | # This one is suitable for AZERTY keyboards. 106 | #Controls = Up, Down, Left, Right, Right Shift, Return, x, w, s, q, c, v 107 | 108 | CheatLife = w 109 | CheatKeys = o 110 | CheatWalkThroughWalls = Ctrl+e 111 | ClearKeyLog = k 112 | StopReplay = l 113 | Fullscreen = Alt+Return 114 | Reset = Ctrl+r 115 | Pause = Shift+p 116 | PauseDimmed = p 117 | Turbo = Tab 118 | ReplayTurbo = t 119 | WindowBigger = Ctrl+Up 120 | WindowSmaller = Ctrl+Down 121 | 122 | Load = F1, F2, F3, F4, F5, F6, F7, F8, F9, F10 123 | Save = Shift+F1,Shift+F2,Shift+F3,Shift+F4,Shift+F5,Shift+F6,Shift+F7,Shift+F8,Shift+F9,Shift+F10 124 | Replay= Ctrl+F1,Ctrl+F2,Ctrl+F3,Ctrl+F4,Ctrl+F5,Ctrl+F6,Ctrl+F7,Ctrl+F8,Ctrl+F9,Ctrl+F10 125 | 126 | LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace 127 | ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace 128 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Pillow 2 | PyYAML 3 | -------------------------------------------------------------------------------- /run_with_tcc.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set SDL2=third_party\SDL2-2.26.3 4 | 5 | IF NOT EXIST "third_party\tcc\tcc.exe" ( 6 | ECHO: 7 | ECHO ERROR: third_party\tcc\tcc.exe doesn't exist. Please verify that you have put it in the right location. 8 | ECHO Download it from https://github.com/FitzRoyX/tinycc/releases/download/tcc_20221020/tcc_20221020.zip 9 | ECHO It needs to be the 64-bit version. 10 | ECHO: 11 | PAUSE 12 | EXIT /B 1 13 | ) ELSE ( 14 | REM 15 | ) 16 | 17 | IF NOT EXIST "%SDL2%\lib\x64\SDL2.dll" ( 18 | ECHO: 19 | ECHO ERROR: SDL is not unzipped properly into %SDL2% 20 | ECHO Download it from https://github.com/libsdl-org/SDL/releases/download/release-2.26.3/SDL2-devel-2.26.3-VC.zip 21 | ECHO: 22 | PAUSE 23 | EXIT /B 1 24 | ) ELSE ( 25 | REM 26 | ) 27 | 28 | IF NOT EXIST "zelda3_assets.dat" ( 29 | ECHO: 30 | ECHO ERROR: zelda3_assets.dat was not found. 31 | ECHO You need to extract assets from the ROM first, or get this file from a friend. Please see README.md 32 | ECHO: 33 | PAUSE 34 | EXIT /B 1 35 | ) ELSE ( 36 | REM 37 | ) 38 | 39 | 40 | echo Building with TCC... 41 | third_party\tcc\tcc.exe -ozelda3.exe -DCOMPILER_TCC=1 -DSTBI_NO_SIMD=1 -DHAVE_STDINT_H=1 -D_HAVE_STDINT_H=1 -DSYSTEM_VOLUME_MIXER_AVAILABLE=0 -I%SDL2%/include -L%SDL2%/lib/x64 -lSDL2 -I. src/*.c snes/*.c third_party/gl_core/gl_core_3_1.c third_party/opus-1.3.1-stripped/opus_decoder_amalgam.c 42 | IF ERRORLEVEL 1 goto GETOUT 43 | 44 | copy %SDL2%\lib\x64\SDL2.dll . 45 | 46 | echo Running... 47 | zelda3.exe 48 | 49 | 50 | :GETOUT 51 | pause 52 | -------------------------------------------------------------------------------- /saves/ref/Chapter 1 - Zelda's Rescue.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 1 - Zelda's Rescue.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 10 - After Ice Palace.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 10 - After Ice Palace.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 11 - After Misery Mire.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 11 - After Misery Mire.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 12 - After Turtle Rock.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 12 - After Turtle Rock.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 13 - After Ganon's Tower.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 13 - After Ganon's Tower.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 2 - After Eastern Palace.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 2 - After Eastern Palace.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 3 - After Desert Palace.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 3 - After Desert Palace.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 4 - After Tower of Hera.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 4 - After Tower of Hera.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 5 - After Hyrule Castle Tower.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 5 - After Hyrule Castle Tower.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 6 - After Dark Palace.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 6 - After Dark Palace.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 7 - After Swamp Palace.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 7 - After Swamp Palace.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 8 - After Skull Woods.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 8 - After Skull Woods.sav -------------------------------------------------------------------------------- /saves/ref/Chapter 9 - After Gargoyle's Domain.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/saves/ref/Chapter 9 - After Gargoyle's Domain.sav -------------------------------------------------------------------------------- /snes/apu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef APU_H 3 | #define APU_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct Apu Apu; 12 | 13 | #include "spc.h" 14 | #include "dsp.h" 15 | 16 | typedef struct Timer { 17 | uint8_t cycles; 18 | uint8_t divider; 19 | uint8_t target; 20 | uint8_t counter; 21 | bool enabled; 22 | } Timer; 23 | 24 | 25 | struct Apu { 26 | Spc* spc; 27 | Dsp* dsp; 28 | uint8_t ram[0x10000]; 29 | bool romReadable; 30 | uint8_t dspAdr; 31 | uint32_t cycles; 32 | uint8_t inPorts[6]; // includes 2 bytes of ram 33 | uint8_t outPorts[4]; 34 | Timer timer[3]; 35 | uint8_t cpuCyclesLeft; 36 | union { 37 | DspRegWriteHistory hist; 38 | void *padpad; 39 | }; 40 | }; 41 | 42 | typedef struct Apu2 { 43 | // Snes* snes; 44 | Spc* spc; 45 | Dsp* dsp; 46 | uint8_t ram[0x10000]; 47 | bool romReadable; 48 | uint8_t dspAdr; 49 | uint32_t cycles; 50 | uint8_t inPorts[6]; // includes 2 bytes of ram 51 | uint8_t outPorts[4]; 52 | Timer timer[3]; 53 | uint8_t cpuCyclesLeft; 54 | } Apu2; 55 | 56 | Apu* apu_init(); 57 | void apu_free(Apu* apu); 58 | void apu_reset(Apu* apu); 59 | void apu_cycle(Apu* apu); 60 | uint8_t apu_cpuRead(Apu* apu, uint16_t adr); 61 | void apu_cpuWrite(Apu* apu, uint16_t adr, uint8_t val); 62 | void apu_saveload(Apu *apu, SaveLoadFunc *func, void *ctx); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /snes/cart.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "cart.h" 9 | #include "snes.h" 10 | 11 | static uint8_t cart_readLorom(Cart* cart, uint8_t bank, uint16_t adr); 12 | static void cart_writeLorom(Cart* cart, uint8_t bank, uint16_t adr, uint8_t val); 13 | static uint8_t cart_readHirom(Cart* cart, uint8_t bank, uint16_t adr); 14 | static void cart_writeHirom(Cart* cart, uint8_t bank, uint16_t adr, uint8_t val); 15 | 16 | Cart* cart_init(Snes* snes) { 17 | Cart* cart = (Cart *)malloc(sizeof(Cart)); 18 | cart->snes = snes; 19 | cart->type = 0; 20 | cart->rom = NULL; 21 | cart->romSize = 0; 22 | cart->ramSize = 0x2000; 23 | cart->ram = (uint8_t *)malloc(cart->ramSize); 24 | return cart; 25 | } 26 | 27 | void cart_free(Cart* cart) { 28 | free(cart); 29 | } 30 | 31 | void cart_reset(Cart* cart) { 32 | if(cart->ramSize > 0 && cart->ram != NULL) memset(cart->ram, 0, cart->ramSize); // for now 33 | } 34 | 35 | void cart_saveload(Cart *cart, SaveLoadFunc *func, void *ctx) { 36 | func(ctx, cart->ram, cart->ramSize); 37 | } 38 | 39 | void cart_load(Cart* cart, int type, uint8_t* rom, int romSize, int ramSize) { 40 | cart->type = type; 41 | if(cart->rom != NULL) free(cart->rom); 42 | cart->rom = (uint8_t*)malloc(romSize); 43 | cart->romSize = romSize; 44 | assert(ramSize == cart->ramSize); 45 | memset(cart->ram, 0, ramSize); 46 | cart->ramSize = ramSize; 47 | memcpy(cart->rom, rom, romSize); 48 | } 49 | 50 | uint8_t cart_read(Cart* cart, uint8_t bank, uint16_t adr) { 51 | if (cart->type == 1) 52 | return cart_readLorom(cart, bank, adr); 53 | 54 | switch(cart->type) { 55 | case 0: return cart->snes->openBus; 56 | case 1: 57 | case 2: return cart_readHirom(cart, bank, adr); 58 | } 59 | return cart->snes->openBus; 60 | } 61 | 62 | void cart_write(Cart* cart, uint8_t bank, uint16_t adr, uint8_t val) { 63 | switch(cart->type) { 64 | case 0: break; 65 | case 1: cart_writeLorom(cart, bank, adr, val); break; 66 | case 2: cart_writeHirom(cart, bank, adr, val); break; 67 | } 68 | } 69 | 70 | static uint8_t cart_readLorom(Cart* cart, uint8_t bank, uint16_t adr) { 71 | if(adr >= 0x8000) { 72 | // adr 8000-ffff in all banks or all addresses in banks 40-7f and c0-ff 73 | return cart->rom[((bank << 15) | (adr & 0x7fff)) & (cart->romSize - 1)]; 74 | } 75 | if(((bank >= 0x70 && bank < 0x7e) || bank >= 0xf0) && adr < 0x8000 && cart->ramSize > 0) { 76 | // banks 70-7e and f0-ff, adr 0000-7fff 77 | return cart->ram[(((bank & 0xf) << 15) | adr) & (cart->ramSize - 1)]; 78 | } 79 | if(bank & 0x40) { 80 | // adr 8000-ffff in all banks or all addresses in banks 40-7f and c0-ff 81 | return cart->rom[((bank << 15) | (adr & 0x7fff)) & (cart->romSize - 1)]; 82 | } 83 | return cart->snes->openBus; 84 | } 85 | 86 | static void cart_writeLorom(Cart* cart, uint8_t bank, uint16_t adr, uint8_t val) { 87 | if(((bank >= 0x70 && bank < 0x7e) || bank > 0xf0) && adr < 0x8000 && cart->ramSize > 0) { 88 | // banks 70-7e and f0-ff, adr 0000-7fff 89 | cart->ram[(((bank & 0xf) << 15) | adr) & (cart->ramSize - 1)] = val; 90 | } 91 | } 92 | 93 | static uint8_t cart_readHirom(Cart* cart, uint8_t bank, uint16_t adr) { 94 | bank &= 0x7f; 95 | if(bank < 0x40 && adr >= 0x6000 && adr < 0x8000 && cart->ramSize > 0) { 96 | // banks 00-3f and 80-bf, adr 6000-7fff 97 | return cart->ram[(((bank & 0x3f) << 13) | (adr & 0x1fff)) & (cart->ramSize - 1)]; 98 | } 99 | if(adr >= 0x8000 || bank >= 0x40) { 100 | // adr 8000-ffff in all banks or all addresses in banks 40-7f and c0-ff 101 | return cart->rom[(((bank & 0x3f) << 16) | adr) & (cart->romSize - 1)]; 102 | } 103 | return cart->snes->openBus; 104 | } 105 | 106 | static void cart_writeHirom(Cart* cart, uint8_t bank, uint16_t adr, uint8_t val) { 107 | bank &= 0x7f; 108 | if(bank < 0x40 && adr >= 0x6000 && adr < 0x8000 && cart->ramSize > 0) { 109 | // banks 00-3f and 80-bf, adr 6000-7fff 110 | cart->ram[(((bank & 0x3f) << 13) | (adr & 0x1fff)) & (cart->ramSize - 1)] = val; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /snes/cart.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CART_H 3 | #define CART_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct Cart Cart; 12 | 13 | #include "snes.h" 14 | 15 | struct Cart { 16 | Snes* snes; 17 | uint8_t type; 18 | 19 | uint8_t* rom; 20 | uint32_t romSize; 21 | uint8_t* ram; 22 | uint32_t ramSize; 23 | }; 24 | 25 | // TODO: how to handle reset & load? (especially where to init ram) 26 | 27 | Cart* cart_init(Snes* snes); 28 | void cart_free(Cart* cart); 29 | void cart_reset(Cart* cart); // will reset special chips etc, general reading is set up in load 30 | void cart_load(Cart* cart, int type, uint8_t* rom, int romSize, int ramSize); // TODO: figure out how to handle (battery, cart-chips etc) 31 | uint8_t cart_read(Cart* cart, uint8_t bank, uint16_t adr); 32 | void cart_write(Cart* cart, uint8_t bank, uint16_t adr, uint8_t val); 33 | void cart_saveload(Cart *cart, SaveLoadFunc *func, void *ctx); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /snes/cpu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CPU_H 3 | #define CPU_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "saveload.h" 12 | 13 | typedef struct Cpu Cpu; 14 | 15 | struct Cpu { 16 | // reference to memory handler, for reading//writing 17 | void* mem; 18 | uint8_t memType; // used to define which type mem is 19 | // registers 20 | uint16_t a; 21 | uint16_t x; 22 | uint16_t y; 23 | uint16_t sp; 24 | uint16_t pc; 25 | uint16_t dp; // direct page (D) 26 | uint8_t k; // program bank (PB) 27 | uint8_t db; // data bank (B) 28 | // flags 29 | bool c; 30 | bool z; 31 | bool v; 32 | bool n; 33 | bool i; 34 | bool d; 35 | bool xf; 36 | bool mf; 37 | bool e; 38 | // interrupts 39 | bool irqWanted; 40 | bool nmiWanted; 41 | // power state (WAI/STP) 42 | bool waiting; 43 | bool stopped; 44 | // internal use 45 | uint8_t cyclesUsed; // indicates how many cycles an opcode used 46 | uint16_t spBreakpoint; 47 | bool in_emu; 48 | }; 49 | 50 | Cpu* cpu_init(void* mem, int memType); 51 | void cpu_free(Cpu* cpu); 52 | void cpu_reset(Cpu* cpu); 53 | int cpu_runOpcode(Cpu* cpu); 54 | void cpu_saveload(Cpu *cpu, SaveLoadFunc *func, void *ctx); 55 | uint8_t cpu_getFlags(Cpu *cpu); 56 | void cpu_setFlags(Cpu *cpu, uint8_t val); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /snes/dma.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef DMA_H 3 | #define DMA_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct Dma Dma; 12 | 13 | #include "snes.h" 14 | 15 | typedef struct DmaChannel { 16 | uint8_t bAdr; 17 | uint8_t aBank; 18 | uint8_t indBank; // hdma 19 | uint8_t repCount; // hdma 20 | uint16_t aAdr; 21 | uint16_t size; // also indirect hdma adr 22 | uint16_t tableAdr; // hdma 23 | uint8_t unusedByte; 24 | bool dmaActive; 25 | bool hdmaActive; 26 | uint8_t mode; 27 | bool fixed; 28 | bool decrement; 29 | bool indirect; // hdma 30 | bool fromB; 31 | bool unusedBit; 32 | bool doTransfer; // hdma 33 | bool terminated; // hdma 34 | uint8_t offIndex; 35 | } DmaChannel; 36 | 37 | struct Dma { 38 | Snes* snes; 39 | DmaChannel channel[8]; 40 | uint16_t hdmaTimer; 41 | uint32_t dmaTimer; 42 | bool dmaBusy; 43 | }; 44 | 45 | Dma* dma_init(Snes* snes); 46 | void dma_free(Dma* dma); 47 | void dma_reset(Dma* dma); 48 | uint8_t dma_read(Dma* dma, uint16_t adr); // 43x0-43xf 49 | void dma_write(Dma* dma, uint16_t adr, uint8_t val); // 43x0-43xf 50 | void dma_doDma(Dma* dma); 51 | void dma_initHdma(Dma* dma); 52 | void dma_doHdma(Dma* dma); 53 | bool dma_cycle(Dma* dma); 54 | void dma_startDma(Dma* dma, uint8_t val, bool hdma); 55 | void dma_saveload(Dma *dma, SaveLoadFunc *func, void *ctx); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /snes/dsp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef DSP_H 3 | #define DSP_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "dsp_regs.h" 12 | typedef struct Dsp Dsp; 13 | 14 | #include "saveload.h" 15 | 16 | typedef struct DspChannel { 17 | // pitch 18 | uint16_t pitch; 19 | uint16_t pitchCounter; 20 | bool pitchModulation; 21 | // brr decoding 22 | int16_t decodeBuffer[19]; // 16 samples per brr-block, +3 for interpolation 23 | uint8_t srcn; 24 | uint16_t decodeOffset; 25 | uint8_t previousFlags; // from last sample 26 | int16_t old; 27 | int16_t older; 28 | bool useNoise; 29 | // adsr, envelope, gain 30 | uint16_t adsrRates[4]; // attack, decay, sustain, gain 31 | uint16_t rateCounter; 32 | uint8_t adsrState; // 0: attack, 1: decay, 2: sustain, 3: gain, 4: release 33 | uint16_t sustainLevel; 34 | bool useGain; 35 | uint8_t gainMode; 36 | bool directGain; 37 | uint16_t gainValue; // for direct gain 38 | uint16_t gain; 39 | // keyon/off 40 | bool keyOn; 41 | bool keyOff; 42 | // output 43 | int16_t sampleOut; // final sample, to be multiplied by channel volume 44 | int8_t volumeL; 45 | int8_t volumeR; 46 | bool echoEnable; 47 | } DspChannel; 48 | 49 | struct Dsp { 50 | uint8_t *apu_ram; 51 | // mirror ram 52 | uint8_t ram[0x80]; 53 | // 8 channels 54 | DspChannel channel[8]; 55 | // overarching 56 | uint16_t dirPage; 57 | bool evenCycle; 58 | bool mute; 59 | bool reset; 60 | int8_t masterVolumeL; 61 | int8_t masterVolumeR; 62 | // noise 63 | int16_t noiseSample; 64 | uint16_t noiseRate; 65 | uint16_t noiseCounter; 66 | // echo 67 | bool echoWrites; 68 | int8_t echoVolumeL; 69 | int8_t echoVolumeR; 70 | int8_t feedbackVolume; 71 | uint16_t echoBufferAdr; 72 | uint16_t echoDelay; 73 | uint16_t echoRemain; 74 | uint16_t echoBufferIndex; 75 | uint8_t firBufferIndex; 76 | int8_t firValues[8]; 77 | int16_t firBufferL[8]; 78 | int16_t firBufferR[8]; 79 | // sample buffer (1 frame at 32040 Hz: 534 samples, *2 for stereo) 80 | int16_t sampleBuffer[534 * 2]; 81 | uint16_t sampleOffset; // current offset in samplebuffer 82 | }; 83 | 84 | 85 | typedef struct DspRegWriteHistory { 86 | uint32_t count; 87 | uint8_t addr[256]; 88 | uint8_t val[256]; 89 | } DspRegWriteHistory; 90 | 91 | Dsp* dsp_init(uint8_t *apu_ram); 92 | void dsp_free(Dsp* dsp); 93 | void dsp_reset(Dsp* dsp); 94 | void dsp_cycle(Dsp* dsp); 95 | uint8_t dsp_read(Dsp* dsp, uint8_t adr); 96 | void dsp_write(Dsp* dsp, uint8_t adr, uint8_t val); 97 | void dsp_getSamples(Dsp* dsp, int16_t* sampleData, int samplesPerFrame, int numChannels); 98 | void dsp_saveload(Dsp *dsp, SaveLoadFunc *func, void *ctx); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /snes/dsp_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef DSP_REGS_H 2 | #define DSP_REGS_H 3 | 4 | enum DspReg { 5 | V0VOLL = 0x00, 6 | V0VOLR = 0x01, 7 | V0PITCHL = 0x02, 8 | V0PITCHH = 0x03, 9 | V0SRCN = 0x04, 10 | V0ADSR1 = 0x05, 11 | V0ADSR2 = 0x06, 12 | V0GAIN = 0x07, 13 | V0ENVX = 0x08, 14 | V0OUTX = 0x09, 15 | MVOLL = 0x0C, 16 | EFB = 0x0D, 17 | FIR0 = 0x0F, 18 | V1VOLL = 0x10, 19 | V1VOLR = 0x11, 20 | V1PL = 0x12, 21 | V1PH = 0x13, 22 | V1SRCN = 0x14, 23 | V1ADSR1 = 0x15, 24 | V1ADSR2 = 0x16, 25 | V1GAIN = 0x17, 26 | V1ENVX = 0x18, 27 | V1OUTX = 0x19, 28 | MVOLR = 0x1C, 29 | FIR1 = 0x1F, 30 | V2VOLL = 0x20, 31 | V2VOLR = 0x21, 32 | V2PL = 0x22, 33 | V2PH = 0x23, 34 | V2SRCN = 0x24, 35 | V2ADSR1 = 0x25, 36 | V2ADSR2 = 0x26, 37 | V2GAIN = 0x27, 38 | V2ENVX = 0x28, 39 | V2OUTX = 0x29, 40 | EVOLL = 0x2C, 41 | PMON = 0x2D, 42 | FIR2 = 0x2F, 43 | V3VOLL = 0x30, 44 | V3VOLR = 0x31, 45 | V3PL = 0x32, 46 | V3PH = 0x33, 47 | V3SRCN = 0x34, 48 | V3ADSR1 = 0x35, 49 | V3ADSR2 = 0x36, 50 | V3GAIN = 0x37, 51 | V3ENVX = 0x38, 52 | V3OUTX = 0x39, 53 | EVOLR = 0x3C, 54 | NON = 0x3D, 55 | FIR3 = 0x3F, 56 | V4VOLL = 0x40, 57 | V4VOLR = 0x41, 58 | V4PL = 0x42, 59 | V4PH = 0x43, 60 | V4SRCN = 0x44, 61 | V4ADSR1 = 0x45, 62 | V4ADSR2 = 0x46, 63 | V4GAIN = 0x47, 64 | V4ENVX = 0x48, 65 | V4OUTX = 0x49, 66 | KON = 0x4C, 67 | EON = 0x4D, 68 | FIR4 = 0x4F, 69 | V5VOLL = 0x50, 70 | V5VOLR = 0x51, 71 | V5PL = 0x52, 72 | V5PH = 0x53, 73 | V5SRCN = 0x54, 74 | V5ADSR1 = 0x55, 75 | V5ADSR2 = 0x56, 76 | V5GAIN = 0x57, 77 | V5ENVX = 0x58, 78 | V5OUTX = 0x59, 79 | KOF = 0x5C, 80 | DIR = 0x5D, 81 | FIR5 = 0x5F, 82 | V6VOLL = 0x60, 83 | V6VOLR = 0x61, 84 | V6PL = 0x62, 85 | V6PH = 0x63, 86 | V6SRCN = 0x64, 87 | V6ADSR1 = 0x65, 88 | V6ADSR2 = 0x66, 89 | V6GAIN = 0x67, 90 | V6ENVX = 0x68, 91 | V6OUTX = 0x69, 92 | FLG = 0x6C, 93 | ESA = 0x6D, 94 | FIR6 = 0x6F, 95 | V7VOLL = 0x70, 96 | V7VOLR = 0x71, 97 | V7PL = 0x72, 98 | V7PH = 0x73, 99 | V7SRCN = 0x74, 100 | V7ADSR1 = 0x75, 101 | V7ADSR2 = 0x76, 102 | V7GAIN = 0x77, 103 | V7ENVX = 0x78, 104 | V7OUTX = 0x79, 105 | ENDX = 0x7C, 106 | EDL = 0x7D, 107 | FIR7 = 0x7F, 108 | }; 109 | #endif // DSP_REGS_H -------------------------------------------------------------------------------- /snes/input.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "input.h" 9 | #include "snes.h" 10 | 11 | Input* input_init(Snes* snes) { 12 | Input* input = (Input * )malloc(sizeof(Input)); 13 | input->snes = snes; 14 | // TODO: handle (where?) 15 | input->type = 1; 16 | input->currentState = 0; 17 | return input; 18 | } 19 | 20 | void input_free(Input* input) { 21 | free(input); 22 | } 23 | 24 | void input_reset(Input* input) { 25 | input->latchLine = false; 26 | input->latchedState = 0; 27 | } 28 | 29 | void input_cycle(Input* input) { 30 | if(input->latchLine) { 31 | input->latchedState = input->currentState; 32 | } 33 | } 34 | 35 | uint8_t input_read(Input* input) { 36 | uint8_t ret = input->latchedState & 1; 37 | input->latchedState >>= 1; 38 | input->latchedState |= 0x8000; 39 | return ret; 40 | } 41 | -------------------------------------------------------------------------------- /snes/input.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef INPUT_H 3 | #define INPUT_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct Input Input; 12 | 13 | #include "snes.h" 14 | 15 | struct Input { 16 | Snes* snes; 17 | uint8_t type; 18 | // latchline 19 | bool latchLine; 20 | // for controller 21 | uint16_t currentState; // actual state 22 | uint16_t latchedState; 23 | }; 24 | 25 | Input* input_init(Snes* snes); 26 | void input_free(Input* input); 27 | void input_reset(Input* input); 28 | void input_cycle(Input* input); 29 | uint8_t input_read(Input* input); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /snes/ppu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ZELDA3_SNES_PPU_H_ 3 | #define ZELDA3_SNES_PPU_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "snes/saveload.h" 11 | typedef struct Ppu Ppu; 12 | 13 | #include "src/types.h" 14 | 15 | typedef struct BgLayer { 16 | uint16_t hScroll; 17 | uint16_t vScroll; 18 | // -- snapshot starts here 19 | bool tilemapWider; 20 | bool tilemapHigher; 21 | uint16_t tilemapAdr; 22 | // -- snapshot ends here 23 | uint16_t tileAdr; 24 | } BgLayer; 25 | 26 | enum { 27 | kPpuXPixels = 256 + kPpuExtraLeftRight * 2, 28 | }; 29 | 30 | typedef uint16_t PpuZbufType; 31 | 32 | typedef struct PpuPixelPrioBufs { 33 | // This holds the prio in the upper 8 bits and the color in the lower 8 bits. 34 | PpuZbufType data[kPpuXPixels]; 35 | } PpuPixelPrioBufs; 36 | 37 | enum { 38 | kPpuRenderFlags_NewRenderer = 1, 39 | // Render mode7 upsampled by 4x4 40 | kPpuRenderFlags_4x4Mode7 = 2, 41 | // Use 240 height instead of 224 42 | kPpuRenderFlags_Height240 = 4, 43 | // Disable sprite render limits 44 | kPpuRenderFlags_NoSpriteLimits = 8, 45 | }; 46 | 47 | 48 | struct Ppu { 49 | bool lineHasSprites; 50 | uint8_t lastBrightnessMult; 51 | uint8_t lastMosaicModulo; 52 | uint8_t renderFlags; 53 | uint32_t renderPitch; 54 | uint8_t *renderBuffer; 55 | uint8_t extraLeftCur, extraRightCur, extraLeftRight, extraBottomCur; 56 | float mode7PerspectiveLow, mode7PerspectiveHigh; 57 | 58 | // TMW / TSW etc 59 | uint8 screenEnabled[2]; 60 | uint8 screenWindowed[2]; 61 | uint8 mosaicEnabled; 62 | uint8 mosaicSize; 63 | // object/sprites 64 | uint16_t objTileAdr1; 65 | uint16_t objTileAdr2; 66 | uint8_t objSize; 67 | // Window 68 | uint8_t window1left; 69 | uint8_t window1right; 70 | uint8_t window2left; 71 | uint8_t window2right; 72 | uint32_t windowsel; 73 | 74 | // color math 75 | uint8_t clipMode; 76 | uint8_t preventMathMode; 77 | bool addSubscreen; 78 | bool subtractColor; 79 | bool halfColor; 80 | uint8 mathEnabled; 81 | uint8_t fixedColorR, fixedColorG, fixedColorB; 82 | // settings 83 | bool forcedBlank; 84 | uint8_t brightness; 85 | uint8_t mode; 86 | 87 | // vram access 88 | uint16_t vramPointer; 89 | uint16_t vramIncrement; 90 | bool vramIncrementOnHigh; 91 | // cgram access 92 | uint8_t cgramPointer; 93 | bool cgramSecondWrite; 94 | uint8_t cgramBuffer; 95 | // oam access 96 | uint16_t oamAdr; 97 | bool oamSecondWrite; 98 | uint8_t oamBuffer; 99 | 100 | // background layers 101 | BgLayer bgLayer[4]; 102 | uint8_t scrollPrev; 103 | uint8_t scrollPrev2; 104 | 105 | // mode 7 106 | int16_t m7matrix[8]; // a, b, c, d, x, y, h, v 107 | uint8_t m7prev; 108 | bool m7largeField; 109 | bool m7charFill; 110 | bool m7xFlip; 111 | bool m7yFlip; 112 | bool m7extBg_always_zero; 113 | // mode 7 internal 114 | int32_t m7startX; 115 | int32_t m7startY; 116 | 117 | uint16_t oam[0x110]; 118 | 119 | // store 31 extra entries to remove the need for clamp 120 | uint8_t brightnessMult[32 + 31]; 121 | uint8_t brightnessMultHalf[32 * 2]; 122 | uint16_t cgram[0x100]; 123 | uint8_t mosaicModulo[kPpuXPixels]; 124 | uint32_t colorMapRgb[256]; 125 | PpuPixelPrioBufs bgBuffers[2]; 126 | PpuPixelPrioBufs objBuffer; 127 | uint16_t vram[0x8000]; 128 | }; 129 | 130 | Ppu* ppu_init(); 131 | void ppu_free(Ppu* ppu); 132 | void ppu_reset(Ppu* ppu); 133 | void ppu_handleVblank(Ppu* ppu); 134 | void ppu_runLine(Ppu* ppu, int line); 135 | uint8_t ppu_read(Ppu* ppu, uint8_t adr); 136 | void ppu_write(Ppu* ppu, uint8_t adr, uint8_t val); 137 | void ppu_saveload(Ppu *ppu, SaveLoadFunc *func, void *ctx); 138 | void PpuBeginDrawing(Ppu *ppu, uint8_t *buffer, size_t pitch, uint32_t render_flags); 139 | 140 | // Returns the current render scale, 1x = 256px, 2x=512px, 4x=1024px 141 | int PpuGetCurrentRenderScale(Ppu *ppu, uint32_t render_flags); 142 | 143 | void PpuSetMode7PerspectiveCorrection(Ppu *ppu, int low, int high); 144 | void PpuSetExtraSideSpace(Ppu *ppu, int left, int right, int bottom); 145 | 146 | #endif // ZELDA3_SNES_PPU_H_ 147 | -------------------------------------------------------------------------------- /snes/saveload.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef void SaveLoadFunc(void *ctx, void *data, size_t data_size); 4 | 5 | #define SL(x) func(ctx, &x, sizeof(x)) -------------------------------------------------------------------------------- /snes/snes.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SNES_H 3 | #define SNES_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct Snes Snes; 12 | 13 | #include "cpu.h" 14 | #include "apu.h" 15 | #include "dma.h" 16 | #include "ppu.h" 17 | #include "cart.h" 18 | #include "input.h" 19 | 20 | struct Snes { 21 | Cpu* cpu; 22 | Apu* apu; 23 | Ppu* ppu; 24 | Dma* dma; 25 | Cart* cart; 26 | // input 27 | bool debug_cycles; 28 | bool disableHpos; 29 | Input* input1; 30 | Input* input2; 31 | 32 | 33 | // frame timing 34 | 35 | 36 | uint16_t hPos; 37 | uint16_t vPos; 38 | uint32_t frames; 39 | // cpu handling 40 | uint8_t cpuCyclesLeft; 41 | uint8_t cpuMemOps; 42 | double apuCatchupCycles; 43 | // nmi / irq 44 | bool hIrqEnabled; 45 | bool vIrqEnabled; 46 | bool nmiEnabled; 47 | uint16_t hTimer; 48 | uint16_t vTimer; 49 | bool inNmi; 50 | bool inIrq; 51 | bool inVblank; 52 | // joypad handling 53 | uint16_t portAutoRead[4]; // as read by auto-joypad read 54 | bool autoJoyRead; 55 | uint16_t autoJoyTimer; // times how long until reading is done 56 | bool ppuLatch; 57 | // multiplication/division 58 | uint8_t multiplyA; 59 | uint16_t multiplyResult; 60 | uint16_t divideA; 61 | uint16_t divideResult; 62 | // misc 63 | bool fastMem; 64 | uint8_t openBus; 65 | // ram 66 | uint8_t *ram; 67 | uint32_t ramAdr; 68 | }; 69 | 70 | Snes* snes_init(uint8_t *ram); 71 | void snes_free(Snes* snes); 72 | void snes_reset(Snes* snes, bool hard); 73 | // used by dma, cpu 74 | uint8_t snes_readBBus(Snes* snes, uint8_t adr); 75 | void snes_writeBBus(Snes* snes, uint8_t adr, uint8_t val); 76 | uint8_t snes_read(Snes* snes, uint32_t adr); 77 | void snes_write(Snes* snes, uint32_t adr, uint8_t val); 78 | uint8_t snes_cpuRead(Snes* snes, uint32_t adr); 79 | void snes_cpuWrite(Snes* snes, uint32_t adr, uint8_t val); 80 | // debugging 81 | void snes_printCpuLine(Snes *snes); 82 | void snes_doAutoJoypad(Snes *snes); 83 | // snes_other.c functions: 84 | 85 | bool snes_loadRom(Snes* snes, uint8_t* data, int length); 86 | void snes_saveload(Snes *snes, SaveLoadFunc *func, void *ctx); 87 | 88 | 89 | #endif 90 | 91 | -------------------------------------------------------------------------------- /snes/spc.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SPC_H 3 | #define SPC_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct Spc Spc; 12 | 13 | #include "apu.h" 14 | #include "saveload.h" 15 | 16 | struct Spc { 17 | Apu* apu; 18 | // registers 19 | uint8_t a; 20 | uint8_t x; 21 | uint8_t y; 22 | uint8_t sp; 23 | uint16_t pc; 24 | // flags 25 | bool c; 26 | bool z; 27 | bool v; 28 | bool n; 29 | bool i; 30 | bool h; 31 | bool p; 32 | bool b; 33 | // stopping 34 | bool stopped; 35 | // internal use 36 | uint8_t cyclesUsed; // indicates how many cycles an opcode used 37 | }; 38 | 39 | Spc* spc_init(Apu* apu); 40 | void spc_free(Spc* spc); 41 | void spc_reset(Spc* spc); 42 | int spc_runOpcode(Spc* spc); 43 | void spc_saveload(Spc *spc, SaveLoadFunc *func, void *ctx); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /snes/tracing.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TRACING_H 3 | #define TRACING_H 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "snes.h" 13 | 14 | void getProcessorStateCpu(Snes* snes, char* line); 15 | void getProcessorStateSpc(Apu* apu, char* line); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/attract.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | typedef struct AttractOamInfo { 3 | int8 x, y; 4 | uint8 c, f, e; 5 | } AttractOamInfo; 6 | 7 | 8 | extern const uint16 kMapMode_Zooms1[240]; 9 | extern const uint16 kMapMode_Zooms2[240]; 10 | void Attract_DrawSpriteSet2(const AttractOamInfo *p, int n); 11 | void Attract_ZeldaPrison_Case0(); 12 | void Attract_ZeldaPrison_Case1(); 13 | void Attract_ZeldaPrison_DrawA(); 14 | void Attract_MaidenWarp_Case0(); 15 | void Attract_MaidenWarp_Case1(); 16 | void Attract_MaidenWarp_Case2(); 17 | void Attract_MaidenWarp_Case3(); 18 | void Attract_MaidenWarp_Case4(); 19 | void Dungeon_LoadAndDrawEntranceRoom(uint8 a); 20 | void Dungeon_SaveAndLoadLoadAllPalettes(uint8 a, uint8 k); 21 | void Module14_Attract(); 22 | void Attract_Fade(); 23 | void Attract_InitGraphics(); 24 | void Attract_FadeInStep(); 25 | void Attract_FadeInSequence(); 26 | void Attract_FadeOutSequence(); 27 | void Attract_LoadNewScene(); 28 | void AttractScene_PolkaDots(); 29 | void AttractScene_WorldMap(); 30 | void AttractScene_ThroneRoom(); 31 | void Attract_PrepFinish(); 32 | void Attract_PrepZeldaPrison(); 33 | void Attract_PrepMaidenWarp(); 34 | void AttractScene_EndOfStory(); 35 | void Death_Func31(); 36 | void Attract_EnactStory(); 37 | void AttractDramatize_PolkaDots(); 38 | void AttractDramatize_WorldMap(); 39 | void Attract_ThroneRoom(); 40 | void AttractDramatize_Prison(); 41 | void AttractDramatize_AgahnimAltar(); 42 | void Attract_SkipToFileSelect(); 43 | void Attract_BuildNextImageTileMap(); 44 | void Attract_ShowTimedTextMessage(); 45 | void Attract_ControlMapZoom(); 46 | void Attract_BuildBackgrounds(); 47 | void Attract_TriggerBGDMA(uint16 dstv); 48 | void Attract_DrawPreloadedSprite(const uint8 *xp, const uint8 *yp, const uint8 *cp, const uint8 *fp, const uint8 *ep, int n); 49 | void Attract_DrawZelda(); 50 | void Sprite_SimulateSoldier(int k, uint16 x, uint16 y, uint8 dir, uint8 flags, uint8 gfx); 51 | -------------------------------------------------------------------------------- /src/audio.h: -------------------------------------------------------------------------------- 1 | #ifndef ZELDA3_AUDIO_H_ 2 | #define ZELDA3_AUDIO_H_ 3 | 4 | #include "types.h" 5 | 6 | // Things for msu 7 | bool ZeldaIsPlayingMusicTrack(uint8 track); 8 | bool ZeldaIsPlayingMusicTrackWithBug(uint8 track); 9 | void ZeldaPlayMsuAudioTrack(uint8 track); 10 | bool ZeldaIsMusicPlaying(); 11 | 12 | void ZeldaEnableMsu(uint8 enable); 13 | 14 | void ZeldaRenderAudio(int16 *audio_buffer, int samples, int channels); 15 | void ZeldaDiscardUnusedAudioFrames(); 16 | void ZeldaRestoreMusicAfterLoad_Locked(bool is_reset); 17 | void ZeldaSaveMusicStateToRam_Locked(); 18 | void ZeldaPushApuState(); 19 | 20 | #endif // ZELDA3_AUDIO_H_ 21 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | #include 4 | 5 | enum { 6 | kKeys_Null, 7 | kKeys_Controls, 8 | kKeys_Controls_Last = kKeys_Controls + 11, 9 | kKeys_Load, 10 | kKeys_Load_Last = kKeys_Load + 19, 11 | kKeys_Save, 12 | kKeys_Save_Last = kKeys_Save + 19, 13 | kKeys_Replay, 14 | kKeys_Replay_Last = kKeys_Replay + 19, 15 | kKeys_LoadRef, 16 | kKeys_LoadRef_Last = kKeys_LoadRef + 19, 17 | kKeys_ReplayRef, 18 | kKeys_ReplayRef_Last = kKeys_ReplayRef + 19, 19 | kKeys_CheatLife, 20 | kKeys_CheatKeys, 21 | kKeys_CheatEquipment, 22 | kKeys_CheatWalkThroughWalls, 23 | kKeys_ClearKeyLog, 24 | kKeys_StopReplay, 25 | kKeys_Fullscreen, 26 | kKeys_Reset, 27 | kKeys_Pause, 28 | kKeys_PauseDimmed, 29 | kKeys_Turbo, 30 | kKeys_ReplayTurbo, 31 | kKeys_WindowBigger, 32 | kKeys_WindowSmaller, 33 | kKeys_DisplayPerf, 34 | kKeys_ToggleRenderer, 35 | kKeys_VolumeUp, 36 | kKeys_VolumeDown, 37 | kKeys_Total, 38 | }; 39 | 40 | enum { 41 | kOutputMethod_SDL, 42 | kOutputMethod_SDLSoftware, 43 | kOutputMethod_OpenGL, 44 | kOutputMethod_OpenGL_ES, 45 | }; 46 | 47 | typedef struct Config { 48 | int window_width; 49 | int window_height; 50 | bool enhanced_mode7; 51 | bool new_renderer; 52 | bool ignore_aspect_ratio; 53 | uint8 fullscreen; 54 | uint8 window_scale; 55 | bool enable_audio; 56 | bool linear_filtering; 57 | uint8 output_method; 58 | uint16 audio_freq; 59 | uint8 audio_channels; 60 | uint16 audio_samples; 61 | bool autosave; 62 | uint8 extended_aspect_ratio; 63 | bool extend_y; 64 | bool no_sprite_limits; 65 | bool display_perf_title; 66 | uint8 enable_msu; 67 | bool resume_msu; 68 | bool disable_frame_delay; 69 | bool bilinear_filtering; 70 | uint8 msuvolume; 71 | uint32 features0; 72 | 73 | const char *link_graphics; 74 | char *memory_buffer; 75 | const char *shader; 76 | const char *msu_path; 77 | const char *language; 78 | } Config; 79 | 80 | enum { 81 | kMsuEnabled_Msu = 1, 82 | kMsuEnabled_MsuDeluxe = 2, 83 | kMsuEnabled_Opuz = 4, 84 | }; 85 | enum { 86 | kGamepadBtn_Invalid = -1, 87 | kGamepadBtn_A, 88 | kGamepadBtn_B, 89 | kGamepadBtn_X, 90 | kGamepadBtn_Y, 91 | kGamepadBtn_Back, 92 | kGamepadBtn_Guide, 93 | kGamepadBtn_Start, 94 | kGamepadBtn_L3, 95 | kGamepadBtn_R3, 96 | kGamepadBtn_L1, 97 | kGamepadBtn_R1, 98 | kGamepadBtn_DpadUp, 99 | kGamepadBtn_DpadDown, 100 | kGamepadBtn_DpadLeft, 101 | kGamepadBtn_DpadRight, 102 | kGamepadBtn_L2, 103 | kGamepadBtn_R2, 104 | kGamepadBtn_Count, 105 | }; 106 | 107 | extern Config g_config; 108 | 109 | void ParseConfigFile(const char *filename); 110 | int FindCmdForSdlKey(SDL_Keycode code, SDL_Keymod mod); 111 | int FindCmdForGamepadButton(int button, uint32 modifiers); 112 | -------------------------------------------------------------------------------- /src/ending.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct IntroSpriteEnt { 4 | int8 x, y; 5 | uint8 charnum, flags; 6 | uint8 ext; 7 | } IntroSpriteEnt; 8 | 9 | void Intro_SetupScreen(); 10 | void Intro_LoadTextPointersAndPalettes(); 11 | void Credits_LoadScene_Overworld_PrepGFX(); 12 | void Credits_LoadScene_Overworld_Overlay(); 13 | void Credits_LoadScene_Overworld_LoadMap(); 14 | void Credits_OperateScrollingAndTileMap(); 15 | void Credits_LoadCoolBackground(); 16 | void Credits_LoadScene_Dungeon(); 17 | void Module18_GanonEmerges(); 18 | void Module19_TriforceRoom(); 19 | void Intro_InitializeBackgroundSettings(); 20 | void Polyhedral_InitializeThread(); 21 | void Module00_Intro(); 22 | void Intro_Init(); 23 | void Intro_Init_Continue(); 24 | void Intro_Clear1kbBlocksOfWRAM(); 25 | void Intro_InitializeMemory_darken(); 26 | void IntroZeldaFadein(); 27 | void Intro_FadeInBg(); 28 | void Intro_SwordComingDown(); 29 | void Intro_WaitPlayer(); 30 | void FadeMusicAndResetSRAMMirror(); 31 | void Intro_InitializeTriforcePolyThread(); 32 | void Intro_InitGfx_Helper(); 33 | void LoadTriforceSpritePalette(); 34 | void Intro_HandleAllTriforceAnimations(); 35 | void Scene_AnimateEverySprite(); 36 | void Intro_AnimateTriforce(); 37 | void Intro_RunStep(); 38 | void Intro_AnimOneObj(int k); 39 | void Intro_SpriteType_A_0(int k); 40 | void Intro_SpriteType_B_0(int k); 41 | void AnimateSceneSprite_DrawTriangle(int k); 42 | void Intro_CopySpriteType4ToOam(int k); 43 | void EXIT_0CCA90(int k); 44 | void InitializeSceneSprite_Copyright(int k); 45 | void AnimateSceneSprite_Copyright(int k); 46 | void InitializeSceneSprite_Sparkle(int k); 47 | void AnimateSceneSprite_Sparkle(int k); 48 | void AnimateSceneSprite_AddObjectsToOamBuffer(int k, const IntroSpriteEnt *src, int num); 49 | void AnimateSceneSprite_MoveTriangle(int k); 50 | void TriforceRoom_PrepGFXSlotForPoly(); 51 | void Credits_InitializePolyhedral(); 52 | void AdvancePolyhedral(); 53 | void TriforceRoom_HandlePoly(); 54 | void Credits_AnimateTheTriangles(); 55 | void InitializeSceneSprite_TriforceRoomTriangle(int k); 56 | void Intro_SpriteType_B_456(int k); 57 | void AnimateTriforceRoomTriangle_HandleContracting(int k); 58 | void InitializeSceneSprite_CreditsTriangle(int k); 59 | void AnimateSceneSprite_CreditsTriangle(int k); 60 | void Intro_DisplayLogo(); 61 | void Intro_SetupSwordAndIntroFlash(); 62 | void Intro_PeriodicSwordAndIntroFlash(); 63 | void Module1A_Credits(); 64 | void Credits_LoadNextScene_Overworld(); 65 | void Credits_LoadNextScene_Dungeon(); 66 | void Credits_PrepAndLoadSprites(); 67 | void Credits_ScrollScene_Overworld(); 68 | void Credits_ScrollScene_Dungeon(); 69 | void Credits_HandleSceneFade(); 70 | void Credits_SpriteDraw_DrawShadow(int k); 71 | void EndSequence_DrawShadow2(int k); 72 | void Ending_Func2(int k, uint8 ain); 73 | void Credits_SpriteDraw_ActivateAndRunSprite(int k, uint8 a); 74 | void Credits_SpriteDraw_PreexistingSpriteDraw(int k, uint8 a); 75 | void Credits_SpriteDraw_Single(int k, uint8 a, uint8 j); 76 | void Credits_SpriteDraw_SetShadowProp(int k, uint8 a); 77 | void Credits_SpriteDraw_AddSparkle(int j_count, uint8 xb, uint8 yb); 78 | void Credits_SpriteDraw_WalkLinkAwayFromPedestal(int k); 79 | void Credits_SpriteDraw_MoveSquirrel(int k); 80 | void Credits_SpriteDraw_CirclingBirds(int k); 81 | void Credits_HandleCameraScrollControl(); 82 | void EndSequence_32(); 83 | void Credits_FadeOutFixedCol(); 84 | void Credits_FadeColorAndBeginAnimating(); 85 | void Credits_AddNextAttribution(); 86 | void Credits_AddEndingSequenceText(); 87 | void Credits_BrightenTriangles(); 88 | void Credits_StopCreditsScroll(); 89 | void Credits_FadeAndDisperseTriangles(); 90 | void Credits_FadeInTheEnd(); 91 | void Credits_HangForever(); 92 | void CrystalCutscene_InitializePolyhedral(); 93 | -------------------------------------------------------------------------------- /src/features.h: -------------------------------------------------------------------------------- 1 | // This file declares extensions to the base game 2 | #ifndef ZELDA3_FEATURES_H_ 3 | #define ZELDA3_FEATURES_H_ 4 | 5 | #include "types.h" 6 | 7 | // Special RAM locations that are unused but I use for compat things. 8 | enum { 9 | kRam_APUI00 = 0x648, 10 | kRam_CrystalRotateCounter = 0x649, 11 | kRam_BugsFixed = 0x64a, 12 | kRam_Features0 = 0x64c, 13 | }; 14 | 15 | enum { 16 | // Poly rendered uses correct speed 17 | kBugFix_PolyRenderer = 1, 18 | kBugFix_AncillaOverwrites = 1, 19 | kBugFix_Latest = 1, 20 | }; 21 | 22 | // Enum values for kRam_Features0 23 | enum { 24 | kFeatures0_ExtendScreen64 = 1, 25 | kFeatures0_SwitchLR = 2, 26 | kFeatures0_TurnWhileDashing = 4, 27 | kFeatures0_MirrorToDarkworld = 8, 28 | kFeatures0_CollectItemsWithSword = 16, 29 | kFeatures0_BreakPotsWithSword = 32, 30 | kFeatures0_DisableLowHealthBeep = 64, 31 | kFeatures0_SkipIntroOnKeypress = 128, 32 | kFeatures0_ShowMaxItemsInYellow = 256, 33 | kFeatures0_MoreActiveBombs = 512, 34 | 35 | // This is set for visual fixes that don't affect game behavior but will affect ram compare. 36 | kFeatures0_WidescreenVisualFixes = 1024, 37 | 38 | kFeatures0_CarryMoreRupees = 2048, 39 | 40 | kFeatures0_MiscBugFixes = 4096, 41 | 42 | kFeatures0_CancelBirdTravel = 8192, 43 | 44 | kFeatures0_GameChangingBugFixes = 16384, 45 | 46 | kFeatures0_SwitchLRLimit = 32768, 47 | 48 | kFeatures0_DimFlashes = 65536, 49 | }; 50 | 51 | #define enhanced_features0 (*(uint32*)(g_ram+0x64c)) 52 | #define msu_curr_sample (*(uint32*)(g_ram+0x650)) 53 | #define msu_volume (*(uint8*)(g_ram+0x654)) 54 | #define msu_track (*(uint8*)(g_ram+0x655)) 55 | #define hud_inventory_order ((uint8*)(g_ram + 0x225)) // 4x6 bytes 56 | #define hud_cur_item_x (*(uint8*)(g_ram+0x656)) 57 | #define hud_cur_item_l (*(uint8*)(g_ram+0x657)) 58 | #define hud_cur_item_r (*(uint8*)(g_ram+0x658)) 59 | 60 | 61 | 62 | extern uint32 g_wanted_zelda_features; 63 | 64 | 65 | #endif // ZELDA3_FEATURES_H_ 66 | -------------------------------------------------------------------------------- /src/glsl_shader.h: -------------------------------------------------------------------------------- 1 | #ifndef ZELDA3_GLSL_SHADER_H_ 2 | #define ZELDA3_GLSL_SHADER_H_ 3 | 4 | #include "types.h" 5 | 6 | enum { 7 | kGlslMaxPasses = 20, 8 | kGlslMaxTextures = 10, 9 | }; 10 | 11 | enum GLSLScaleType { 12 | GLSL_NONE, 13 | GLSL_SOURCE, 14 | GLSL_VIEWPORT, 15 | GLSL_ABSOLUTE 16 | }; 17 | 18 | typedef struct GlslTextureUniform { 19 | int Texture; 20 | int InputSize; 21 | int TextureSize; 22 | int TexCoord; 23 | } GlslTextureUniform; 24 | 25 | typedef struct GlslUniforms { 26 | GlslTextureUniform Top; 27 | int OutputSize; 28 | int FrameCount, FrameDirection; 29 | int LUTTexCoord; 30 | int VertexCoord; 31 | GlslTextureUniform Orig; 32 | GlslTextureUniform Prev[7]; 33 | GlslTextureUniform Pass[kGlslMaxPasses]; 34 | GlslTextureUniform PassPrev[kGlslMaxPasses]; 35 | int Texture[kGlslMaxTextures]; 36 | } GlslUniforms; 37 | 38 | typedef struct GlslPass { 39 | char *filename; 40 | uint8 scale_type_x, scale_type_y; 41 | bool float_framebuffer; 42 | bool srgb_framebuffer; 43 | bool mipmap_input; 44 | float scale_x, scale_y; 45 | uint wrap_mode; 46 | uint frame_count_mod; 47 | uint frame_count; 48 | uint gl_program, gl_fbo; 49 | uint filter; 50 | uint gl_texture; 51 | uint16 width, height; 52 | GlslUniforms unif; 53 | } GlslPass; 54 | 55 | typedef struct GlTextureWithSize { 56 | uint gl_texture; 57 | uint16 width, height; 58 | } GlTextureWithSize; 59 | 60 | typedef struct GlslTexture { 61 | struct GlslTexture *next; 62 | char *id; 63 | char *filename; 64 | uint filter; 65 | uint gl_texture; 66 | uint wrap_mode; 67 | bool mipmap; 68 | int width; 69 | int height; 70 | } GlslTexture; 71 | 72 | typedef struct GlslParam { 73 | struct GlslParam *next; 74 | char *id; 75 | bool has_value; 76 | float value; 77 | float min; 78 | float max; 79 | uint uniform[kGlslMaxPasses]; 80 | } GlslParam; 81 | 82 | typedef struct GlslShader { 83 | int n_pass; 84 | GlslPass *pass; 85 | GlslParam *first_param; 86 | GlslTexture *first_texture; 87 | uint *gl_vao; 88 | uint gl_vbo; 89 | uint frame_count; 90 | int max_prev_frame; 91 | GlTextureWithSize prev_frame[8]; 92 | } GlslShader; 93 | 94 | GlslShader *GlslShader_CreateFromFile(const char *filename, bool opengl_es); 95 | void GlslShader_Destroy(GlslShader *gs); 96 | void GlslShader_Render(GlslShader *gs, GlTextureWithSize *tex, int viewport_x, int viewport_y, int viewport_width, int viewport_height); 97 | 98 | 99 | #endif // ZELDA3_GLSL_SHADER_H_ 100 | -------------------------------------------------------------------------------- /src/hud.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | enum kHudItems { 5 | 6 | kHudItem_Bombs = 4, 7 | kHudItem_Mushroom = 5, 8 | kHudItem_Hammer = 12, 9 | kHudItem_Flute = 13, 10 | kHudItem_BookMudora = 15, 11 | kHudItem_BottleOld = 16, 12 | 13 | kHudItem_Shovel = 16, 14 | kHudItem_Bottle1 = 21, 15 | kHudItem_Bottle2 = 22, 16 | kHudItem_Bottle3 = 23, 17 | kHudItem_Bottle4 = 24, 18 | }; 19 | 20 | void Hud_RefreshIcon(); 21 | uint8 CheckPalaceItemPosession(); 22 | void Hud_FloorIndicator(); 23 | void Hud_RemoveSuperBombIndicator(); 24 | void Hud_SuperBombIndicator(); 25 | void Hud_RefillLogic(); 26 | void Hud_Module_Run(); 27 | void Hud_ClearTileMap(); 28 | void Hud_Init(); 29 | void Hud_BringMenuDown(); 30 | void Hud_ChooseNextMode(); 31 | void Hud_NormalMenu(); 32 | void Hud_UpdateHud(); 33 | uint8 Hud_LookupInventoryItem(uint8 item); 34 | void Hud_UpdateEquippedItem(); 35 | void Hud_CloseMenu(); 36 | void Hud_GotoBottleMenu(); 37 | void Hud_InitBottleMenu(); 38 | void Hud_ExpandBottleMenu(); 39 | void Hud_BottleMenu(); 40 | void Hud_DrawBottleMenu_Update(); 41 | void Hud_EraseBottleMenu(); 42 | void Hud_RestoreNormalMenu(); 43 | void Hud_SearchForEquippedItem(); 44 | void Hud_DrawYButtonItems(); 45 | void Hud_DrawAbilityBox(); 46 | void Hud_DrawProgressIcons(); 47 | void Hud_DrawProgressIcons_Pendants(); 48 | void Hud_DrawProgressIcons_Crystals(); 49 | void Hud_DrawSelectedYButtonItem(); 50 | void Hud_DrawEquipmentBox(); 51 | void Hud_DrawBottleMenu(); 52 | bool Hud_RefillHealth(); 53 | void Hud_AnimateHeartRefill(); 54 | bool Hud_RefillMagicPower(); 55 | void Hud_RestoreTorchBackground(); 56 | void Hud_RebuildIndoor(); 57 | void Hud_Rebuild(); 58 | const uint16 *Hud_GetItemBoxPtr(int item); 59 | int GetCurrentItemButtonIndex(); 60 | uint8 *GetCurrentItemButtonPtr(int i); 61 | 62 | void Hud_HandleItemSwitchInputs(); 63 | -------------------------------------------------------------------------------- /src/messaging.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | const uint8 *GetDungmapFloorLayout(); 5 | uint8 GetOtherDungmapInfo(int count); 6 | void DungMap_4(); 7 | void Module_Messaging_6(); 8 | void OverworldMap_SetupHdma(); 9 | const uint8 *GetLightOverworldTilemap(); 10 | void SaveGameFile(); 11 | void TransferMode7Characters(); 12 | void Module0E_Interface(); 13 | void Module_Messaging_0(); 14 | void Module0E_05_DesertPrayer(); 15 | void Module0E_04_RedPotion(); 16 | void Module0E_08_GreenPotion(); 17 | void Module0E_09_BluePotion(); 18 | void Module0E_0B_SaveMenu(); 19 | void Module1B_SpawnSelect(); 20 | void CleanUpAndPrepDesertPrayerHDMA(); 21 | void DesertPrayer_InitializeIrisHDMA(); 22 | void DesertPrayer_BuildIrisHDMATable(); 23 | Pair16U DesertHDMA_CalculateIrisShapeLine(); 24 | void Animate_GAMEOVER_Letters(); 25 | void GameOverText_SweepLeft(); 26 | void GameOverText_UnfurlRight(); 27 | void Module12_GameOver(); 28 | void GameOver_AdvanceImmediately(); 29 | void Death_Func1(); 30 | void GameOver_DelayBeforeIris(); 31 | void GameOver_IrisWipe(); 32 | void GameOver_SplatAndFade(); 33 | void Death_Func6(); 34 | void Death_Func4(); 35 | void Animate_GAMEOVER_Letters_bounce(); 36 | void GameOver_Finalize_GAMEOVR(); 37 | void GameOver_SaveAndOrContinue(); 38 | void Death_Func15(bool count_as_death); 39 | void GameOver_AnimateChoiceFairy(); 40 | void GameOver_InitializeRevivalFairy(); 41 | void RevivalFairy_Main_bounce(); 42 | void GameOver_RiseALittle(); 43 | void GameOver_Restore0D(); 44 | void GameOver_Restore0E(); 45 | void GameOver_ResituateLink(); 46 | void Module0E_0A_FluteMenu(); 47 | void FluteMenu_HandleSelection(); 48 | void FluteMenu_LoadSelectedScreen(); 49 | void Overworld_LoadOverlayAndMap(); 50 | void FluteMenu_FadeInAndQuack(); 51 | void BirdTravel_Finish_Doit(); 52 | void Messaging_OverworldMap(); 53 | void WorldMap_FadeOut(); 54 | void WorldMap_LoadLightWorldMap(); 55 | void WorldMap_LoadDarkWorldMap(); 56 | void WorldMap_LoadSpriteGFX(); 57 | void WorldMap_Brighten(); 58 | void WorldMap_PlayerControl(); 59 | void WorldMap_RestoreGraphics(); 60 | void Attract_SetUpConclusionHDMA(); 61 | void WorldMap_ExitMap(); 62 | void WorldMap_SetUpHDMA(); 63 | void WorldMap_FillTilemapWithEF(); 64 | void WorldMap_HandleSprites(); 65 | bool OverworldMap_CheckForPendant(int k); 66 | bool OverworldMap_CheckForCrystal(int k); 67 | void Module0E_03_DungeonMap(); 68 | void Module0E_03_01_DrawMap(); 69 | void Module0E_03_01_00_PrepMapGraphics(); 70 | void Module0E_03_01_01_DrawLEVEL(); 71 | void Module0E_03_01_02_DrawFloorsBackdrop(); 72 | void DungeonMap_BuildFloorListBoxes(uint8 t5, uint16 r14); 73 | void Module0E_03_01_03_DrawRooms(); 74 | void DungeonMap_DrawBorderForRooms(uint16 pd, uint16 mask); 75 | void DungeonMap_DrawFloorNumbersByRoom(uint16 pd, uint16 r8); 76 | void DungeonMap_DrawDungeonLayout(int pd); 77 | void DungeonMap_DrawSingleRowOfRooms(int i, int arg_x); 78 | void DungeonMap_DrawRoomMarkers(); 79 | void DungeonMap_HandleInputAndSprites(); 80 | void DungeonMap_HandleInput(); 81 | void DungeonMap_HandleMovementInput(); 82 | void DungeonMap_HandleFloorSelect(); 83 | void DungeonMap_ScrollFloors(); 84 | void DungeonMap_DrawSprites(); 85 | void DungeonMap_DrawLinkPointing(int spr_pos, uint8 r2, uint8 r3); 86 | int DungeonMap_DrawBlinkingIndicator(int spr_pos); 87 | int DungeonMap_DrawLocationMarker(int spr_pos, uint16 r14); 88 | int DungeonMap_DrawFloorNumberObjects(int spr_pos); 89 | void DungeonMap_DrawFloorBlinker(); 90 | int DungeonMap_DrawBossIcon(int spr_pos); 91 | int DungeonMap_DrawBossIconByFloor(int spr_pos); 92 | void DungeonMap_RecoverGFX(); 93 | void ToggleStarTilesAndAdvance(); 94 | void Death_InitializeGameOverLetters(); 95 | void CopySaveToWRAM(); 96 | void RenderText(); 97 | void RenderText_PostDeathSaveOptions(); 98 | void Text_Initialize(); 99 | void Text_Initialize_initModuleStateLoop(); 100 | void Text_InitVwfState(); 101 | void Text_LoadCharacterBuffer(); 102 | uint8 *Text_WritePlayerName(uint8 *p); 103 | uint8 Text_FilterPlayerNameCharacters(uint8 a); 104 | void Text_Render(); 105 | void RenderText_Draw_Border(); 106 | void RenderText_Draw_BorderIncremental(); 107 | void RenderText_Draw_CharacterTilemap(); 108 | void RenderText_Draw_MessageCharacters(); 109 | void RenderText_Draw_Finish(); 110 | void VWF_RenderSingle(); 111 | void RenderText_Draw_Choose2LowOr3(); 112 | void RenderText_Draw_ChooseItem(); 113 | void RenderText_FindYItem_Previous(); 114 | void RenderText_FindYItem_Next(); 115 | void RenderText_DrawSelectedYItem(); 116 | void RenderText_Draw_Choose2HiOr3(); 117 | void RenderText_Draw_Choose3(); 118 | void RenderText_Draw_Choose1Or2(); 119 | bool RenderText_Draw_Scroll(); 120 | void RenderText_SetDefaultWindowPosition(); 121 | void RenderText_DrawBorderInitialize(); 122 | uint16 *RenderText_DrawBorderRow(uint16 *d, int y); 123 | void Text_BuildCharacterTilemap(); 124 | void RenderText_Refresh(); 125 | void Text_GenerateMessagePointers(); 126 | void DungMap_LightenUpMap(); 127 | void DungMap_Backup(); 128 | void DungMap_FadeMapToBlack(); 129 | void DungMap_RestoreOld(); 130 | void Death_PlayerSwoon(); 131 | void Death_PrepFaint(); 132 | void DisplaySelectMenu(); 133 | bool DidPressButtonForMap(); 134 | -------------------------------------------------------------------------------- /src/misc.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "variables.h" 3 | #include "zelda_rtl.h" 4 | 5 | #pragma once 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | static inline OamEnt *GetOamCurPtr() { 16 | return (OamEnt *)&g_ram[oam_cur_ptr]; 17 | } 18 | 19 | static inline int FindInByteArray(const uint8 *data, uint8 lookfor, size_t size) { 20 | for (size_t i = size; i--;) 21 | if (data[i] == lookfor) 22 | return (int)i; 23 | return -1; 24 | } 25 | 26 | static inline int FindInWordArray(const uint16 *data, uint16 lookfor, size_t size) { 27 | for (size_t i = size; i--;) 28 | if (data[i] == lookfor) 29 | return (int)i; 30 | return -1; 31 | } 32 | 33 | 34 | extern const uint16 kMemoryLocationToGiveItemTo[76]; 35 | 36 | const uint16 *SrcPtr(uint16 src); 37 | uint8 Ancilla_Sfx2_Near(uint8 a); 38 | void Ancilla_Sfx3_Near(uint8 a); 39 | void LoadDungeonRoomRebuildHUD(); 40 | void Module_Unknown0(); 41 | void Module_Unknown1(); 42 | void Module_MainRouting(); 43 | void NMI_PrepareSprites(); 44 | void Sound_LoadIntroSongBank(); 45 | void LoadOverworldSongs(); 46 | void LoadDungeonSongs(); 47 | void LoadCreditsSongs(); 48 | void Dungeon_LightTorch(); 49 | void RoomDraw_AdjustTorchLightingChange(uint16 x, uint16 y, uint16 r8); 50 | int Dungeon_PrepOverlayDma_nextPrep(int dst, uint16 r8); 51 | int Dungeon_PrepOverlayDma_watergate(int dst, uint16 r8, uint16 r6, int loops); 52 | void Module05_LoadFile(); 53 | void Module13_BossVictory_Pendant(); 54 | void BossVictory_Heal(); 55 | void Dungeon_StartVictorySpin(); 56 | void Dungeon_RunVictorySpin(); 57 | void Dungeon_CloseVictorySpin(); 58 | void Module15_MirrorWarpFromAga(); 59 | void Module16_BossVictory_Crystal(); 60 | void Module16_04_FadeAndEnd(); 61 | void TriforceRoom_LinkApproachTriforce(); 62 | void AncillaAdd_ItemReceipt(uint8 ain, uint8 yin, int chest_pos); 63 | void ItemReceipt_GiveBottledItem(uint8 item); 64 | void Module17_SaveAndQuit(); 65 | void WallMaster_SendPlayerToLastEntrance(); 66 | uint8 GetRandomNumber(); 67 | uint8 Link_CalculateSfxPan(); 68 | void SpriteSfx_QueueSfx1WithPan(int k, uint8 a); 69 | void SpriteSfx_QueueSfx2WithPan(int k, uint8 a); 70 | void SpriteSfx_QueueSfx3WithPan(int k, uint8 a); 71 | uint8 Sprite_CalculateSfxPan(int k); 72 | uint8 CalculateSfxPan(uint16 x); 73 | uint8 CalculateSfxPan_Arbitrary(uint8 a); 74 | void Init_LoadDefaultTileAttr(); 75 | void Main_ShowTextMessage(); 76 | uint8 HandleItemTileAction_Overworld(uint16 x, uint16 y); 77 | -------------------------------------------------------------------------------- /src/nmi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | void NMI_UploadSubscreenOverlayFormer(); 5 | void NMI_UploadSubscreenOverlayLatter(); 6 | void Interrupt_NMI(uint16 joypad_input); 7 | void NMI_ReadJoypads(uint16 joypad_input); 8 | void NMI_DoUpdates(); 9 | void NMI_UploadTilemap(); 10 | void NMI_UploadTilemap_doNothing(); 11 | void NMI_UploadBG3Text(); 12 | void NMI_UpdateOWScroll(); 13 | void NMI_UpdateSubscreenOverlay(); 14 | void NMI_HandleArbitraryTileMap(const uint8 *src, int i, int i_end); 15 | void NMI_UpdateBG1Wall(); 16 | void NMI_TileMapNothing(); 17 | void NMI_UpdateLoadLightWorldMap(); 18 | void NMI_UpdateBG2Left(); 19 | void NMI_UpdateBGChar3and4(); 20 | void NMI_UpdateBGChar5and6(); 21 | void NMI_UpdateBGCharHalf(); 22 | void NMI_UpdateBGChar0(); 23 | void NMI_UpdateBGChar1(); 24 | void NMI_UpdateBGChar2(); 25 | void NMI_UpdateBGChar3(); 26 | void NMI_UpdateObjChar0(); 27 | void NMI_UpdateObjChar2(); 28 | void NMI_UpdateObjChar3(); 29 | void NMI_RunTileMapUpdateDMA(int dst); 30 | void NMI_UploadDarkWorldMap(); 31 | void NMI_UploadGameOverText(); 32 | void NMI_UpdatePegTiles(); 33 | void NMI_UpdateStarTiles(); 34 | void HandleStripes14(const uint8 *p); 35 | void NMI_UpdateIRQGFX(); 36 | -------------------------------------------------------------------------------- /src/overlord.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | void Overlord_StalfosFactory(int k); 5 | void Overlord_SetX(int k, uint16 v); 6 | void Overlord_SetY(int k, uint16 v); 7 | void Overlord_SpawnBoulder(); 8 | void Overlord_Main(); 9 | void Overlord_ExecuteAll(); 10 | void Overlord_ExecuteSingle(int k); 11 | void Overlord19_ArmosCoordinator_bounce(int k); 12 | void Overlord18_InvisibleStalfos(int k); 13 | void Overlord17_PotTrap(int k); 14 | void Overlord16_ZoroSpawner(int k); 15 | void Overlord15_WizzrobeSpawner(int k); 16 | void Overlord14_TileRoom(int k); 17 | int TileRoom_SpawnTile(int k); 18 | void Overlord10_PirogusuSpawner_left(int k); 19 | void Overlord0A_FallingSquare(int k); 20 | void SpawnFallingTile(int k); 21 | void Overlord09_WallmasterSpawner(int k); 22 | void Overlord08_BlobSpawner(int k); 23 | void Overlord07_MovingFloor(int k); 24 | void Sprite_Overlord_PlayFallingSfx(int k); 25 | void Overlord05_FallingStalfos(int k); 26 | void Overlord06_BadSwitchSnake(int k); 27 | void Overlord02_FullRoomCannons(int k); 28 | void Overlord03_VerticalCannon(int k); 29 | void Overlord_SpawnCannonBall(int k, int xd); 30 | void Overlord01_PositionTarget(int k); 31 | void Overlord_CheckIfActive(int k); 32 | void ArmosCoordinator_RotateKnights(int k); 33 | void ArmosCoordinator_Rotate(int k); 34 | bool ArmosCoordinator_CheckKnights(); 35 | void ArmosCoordinator_DisableCoercion(int k); 36 | -------------------------------------------------------------------------------- /src/platform/switch/.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /*.nacp 3 | /*.nro 4 | /*.elf -------------------------------------------------------------------------------- /src/platform/switch/icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/src/platform/switch/icon.jpg -------------------------------------------------------------------------------- /src/platform/switch/zelda3.ini: -------------------------------------------------------------------------------- 1 | [General] 2 | # Automatically save state on quit and reload on start 3 | Autosave = 0 4 | DisplayPerfInTitle = 0 5 | 6 | # Extended aspect ratio, either 16:9, 16:10, or 18:9. 4:3 means normal aspect ratio. 7 | # Add ", unchanged_sprites" to avoid changing sprite spawn/die behavior. Without this 8 | # replays will be incompatible. 9 | # Add ", no_visual_fixes" to avoid fixing some graphics glitches (for example with Cape). 10 | # It won't affect replays/game behavior but the memory compare will not work. 11 | # Add "extend_y, " right before the aspect radio specifier to display 240 lines instead of 224. 12 | ExtendedAspectRatio = 16:9 13 | 14 | 15 | [Graphics] 16 | # Window size ( Auto or WidthxHeight ) 17 | WindowSize = 1280x720 18 | # Fullscreen mode (0=windowed, 1=desktop fullscreen, 2=fullscreen w/mode change) 19 | Fullscreen = 0 20 | # Window scale (1=100%, 2=200%, 3=300%, etc.) 21 | WindowScale = 1 22 | NewRenderer = 1 23 | EnhancedMode7 = 1 24 | IgnoreAspectRatio = 0 25 | 26 | # Enable this option to remove the sprite limits per scan line 27 | NoSpriteLimits = 1 28 | 29 | # Change the appearance of Link by loading a ZSPR file 30 | # See all sprites here: https://snesrev.github.io/sprites-gfx/snes/zelda3/link/ 31 | # Download the files with "git clone https://github.com/snesrev/sprites-gfx.git" 32 | # LinkGraphics = sprites-gfx/snes/zelda3/link/sheets/megaman-x.2.zspr 33 | 34 | 35 | [Sound] 36 | EnableAudio = 1 37 | 38 | # DSP frequency in samples per second (e.g. 48000, 44100, 32000, 22050, 11025) 39 | AudioFreq = 44100 40 | # number of separate sound channels (1=mono, 2=stereo) 41 | AudioChannels = 2 42 | # Audio buffer size in samples (power of 2; e.g., 4096, 2048, 1024) [try 1024 if sound is crackly]. The higher the more lag before you hear sounds. 43 | AudioSamples = 1024 44 | 45 | # Enable MSU support for audio. Files need to be in a subfolder, msu/alttp_msu-*.pcm 46 | # Only works with 44100 hz and 2 channels 47 | EnableMSU = 0 48 | 49 | 50 | [Features] 51 | # Item switch on L/R. Also allows reordering of items in inventory by pressing Y+direction 52 | # Hold X inside of the item selection screen to reassign the X key into a separate item slot. 53 | # When X is assigned to an item, the Select key is used to enter the map. Press Select inside 54 | # of the Start menu to see the old select options. 55 | ItemSwitchLR = 0 56 | 57 | # Allow turning while dashing 58 | TurnWhileDashing = 0 59 | 60 | # Allow mirror to be used to warp to the Dark World 61 | MirrorToDarkworld = 0 62 | 63 | # Collect items (like hearts) with sword instead of having to touch them 64 | CollectItemsWithSword = 0 65 | 66 | # Level 2-4 sword can be used to break pots 67 | BreakPotsWithSword = 0 68 | 69 | # Disable the low health beep 70 | DisableLowHealthBeep = 0 71 | 72 | # Avoid waiting too much at the start 73 | SkipIntroOnKeypress = 0 74 | 75 | # Display max rupees/bombs/arrows with orange/yellow color 76 | ShowMaxItemsInYellow = 0 77 | 78 | # Allows up to four bombs active at a time instead of two. 79 | MoreActiveBombs = 0 80 | 81 | # Can carry 9999 rupees instead of 999 82 | CarryMoreRupees = 0 83 | 84 | # Enable various zelda bug fixes 85 | MiscBugFixes = 0 86 | 87 | # Enable some more advanced zelda bugfixes that change game behavior 88 | GameChangingBugFixes = 0 89 | 90 | # Allow bird travel to be cancelled by hitting the X key 91 | CancelBirdTravel = 0 92 | 93 | 94 | [KeyMap] 95 | # Change what keyboard keys map to the joypad 96 | # Order: Up, Down, Left, Right, Select, Start, A, B, X, Y, L, R 97 | 98 | # This default is suitable for QWERTY keyboards. 99 | Controls = Up, Down, Left, Right, Right Shift, Return, x, z, s, a, c, v 100 | 101 | # This default is suitable for QWERTZ keyboards. 102 | #Controls = Up, Down, Left, Right, Right Shift, Return, x, y, s, a, c, v 103 | 104 | # This one is suitable for AZERTY keyboards. 105 | #Controls = Up, Down, Left, Right, Right Shift, Return, x, w, s, q, c, v 106 | 107 | CheatLife = w 108 | CheatKeys = o 109 | CheatWalkThroughWalls = Ctrl+e 110 | ClearKeyLog = k 111 | StopReplay = l 112 | Fullscreen = Alt+Return 113 | Reset = Ctrl+r 114 | Pause = Shift+p 115 | PauseDimmed = p 116 | Turbo = Tab 117 | ReplayTurbo = t 118 | WindowBigger = Ctrl+Up 119 | WindowSmaller = Ctrl+Down 120 | 121 | Load = F1, F2, F3, F4, F5, F6, F7, F8, F9, F10 122 | Save = Shift+F1,Shift+F2,Shift+F3,Shift+F4,Shift+F5,Shift+F6,Shift+F7,Shift+F8,Shift+F9,Shift+F10 123 | Replay= Ctrl+F1,Ctrl+F2,Ctrl+F3,Ctrl+F4,Ctrl+F5,Ctrl+F6,Ctrl+F7,Ctrl+F8,Ctrl+F9,Ctrl+F10 124 | 125 | LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace 126 | ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace 127 | -------------------------------------------------------------------------------- /src/platform/win32/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by zelda3.rc 4 | // 5 | #define IDI_ICON1 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /src/platform/win32/triforce.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rinnegatamante/zelda3/6c5e8d50e40ccbca8b6553457a6308dbd3eee35b/src/platform/win32/triforce.ico -------------------------------------------------------------------------------- /src/platform/win32/volume_control.c: -------------------------------------------------------------------------------- 1 | #include "volume_control.h" 2 | 3 | #define COBJMACROS 4 | #define CINTERFACE 5 | 6 | #define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | static ISimpleAudioVolume *GetSimpleAudioVolume(); 14 | 15 | DEFINE_GUID(IID_IMMDeviceEnumerator, 0XA95664D2, 0X9614, 0X4F35, 0XA7, 0X46, 0XDE, 0X8D, 0XB6, 0X36, 0X17, 0XE6); 16 | DEFINE_GUID(CLSID_MMDeviceEnumerator, 0XBCDE0395, 0XE52F, 0X467C, 0X8E, 0X3D, 0XC4, 0X57, 0X92, 0X91, 0X69, 0X2E); 17 | DEFINE_GUID(IID_IAudioSessionManager, 0X77AA99A0, 0X1BD6, 0X484F, 0X8B, 0XC7, 0X2C, 0X65, 0X4C, 0X9A, 0X9B, 0X6F); 18 | 19 | static void InitializeCom() { 20 | static bool com_initialized; 21 | if (!com_initialized) 22 | com_initialized = SUCCEEDED(CoInitialize(NULL)); 23 | } 24 | 25 | int GetApplicationVolume() { 26 | ISimpleAudioVolume *simple_audio_volume = GetSimpleAudioVolume(); 27 | if (!simple_audio_volume) 28 | return false; 29 | float volume_level = -1; 30 | HRESULT result = ISimpleAudioVolume_GetMasterVolume(simple_audio_volume, &volume_level); 31 | ISimpleAudioVolume_Release(simple_audio_volume); 32 | return (int)(volume_level * 100); 33 | } 34 | 35 | bool SetApplicationVolume(int volume_level) { 36 | ISimpleAudioVolume *simple_audio_volume = GetSimpleAudioVolume(); 37 | if (!simple_audio_volume) 38 | return false; 39 | HRESULT result = ISimpleAudioVolume_SetMasterVolume(simple_audio_volume, (float)(volume_level / 100.0), NULL); 40 | ISimpleAudioVolume_Release(simple_audio_volume); 41 | return SUCCEEDED(result); 42 | } 43 | 44 | bool SetApplicationMuted(bool muted) { 45 | ISimpleAudioVolume *simple_audio_volume = GetSimpleAudioVolume(); 46 | if (!simple_audio_volume) 47 | return false; 48 | HRESULT result = ISimpleAudioVolume_SetMute(simple_audio_volume, muted, NULL); 49 | ISimpleAudioVolume_Release(simple_audio_volume); 50 | return SUCCEEDED(result); 51 | } 52 | 53 | static ISimpleAudioVolume *GetSimpleAudioVolume() { 54 | HRESULT result; 55 | IMMDeviceEnumerator *device_enumerator = NULL; 56 | IMMDevice *device = NULL; 57 | IAudioSessionManager *audio_session_manager = NULL; 58 | ISimpleAudioVolume *simple_audio_volume = NULL; 59 | 60 | InitializeCom(); 61 | 62 | result = CoCreateInstance(&CLSID_MMDeviceEnumerator, 63 | NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &device_enumerator); 64 | if (FAILED(result) || device_enumerator == NULL) 65 | goto done; 66 | 67 | result = IMMDeviceEnumerator_GetDefaultAudioEndpoint(device_enumerator, eRender, eConsole, &device); 68 | if (FAILED(result) || device == NULL) 69 | goto done; 70 | 71 | result = IMMDevice_Activate(device, &IID_IAudioSessionManager, CLSCTX_INPROC_SERVER, NULL, &audio_session_manager); 72 | if (FAILED(result) || audio_session_manager == NULL) 73 | goto done; 74 | result = IAudioSessionManager_GetSimpleAudioVolume(audio_session_manager, &GUID_NULL, 0, &simple_audio_volume); 75 | 76 | done: 77 | if (device_enumerator) IMMDeviceEnumerator_Release(device_enumerator); 78 | if (device) IMMDevice_Release(device); 79 | if (audio_session_manager) IAudioSessionManager_Release(audio_session_manager); 80 | 81 | return simple_audio_volume; 82 | } 83 | -------------------------------------------------------------------------------- /src/platform/win32/volume_control.h: -------------------------------------------------------------------------------- 1 | #ifndef ZELDA3_PLATFORM_WIN32_VOLUME_CONTROL_H_ 2 | #define ZELDA3_PLATFORM_WIN32_VOLUME_CONTROL_H_ 3 | 4 | #include 5 | 6 | #ifndef SYSTEM_VOLUME_MIXER_AVAILABLE 7 | #define SYSTEM_VOLUME_MIXER_AVAILABLE 1 8 | #endif // SYSTEM_VOLUME_MIXER_AVAILABLE 9 | 10 | int GetApplicationVolume(); 11 | bool SetApplicationVolume(int volume_level); 12 | bool SetApplicationMuted(bool muted); 13 | 14 | #endif // ZELDA3_PLATFORM_WIN32_VOLUME_CONTROL_H_ 15 | -------------------------------------------------------------------------------- /src/platform/win32/zelda3.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "src\\platform\\win32\\resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_ICON1 ICON "src\\platform\\win32\\triforce.ico" 56 | 57 | #endif // English (United States) resources 58 | ///////////////////////////////////////////////////////////////////////////// 59 | 60 | 61 | 62 | #ifndef APSTUDIO_INVOKED 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // Generated from the TEXTINCLUDE 3 resource. 66 | // 67 | 68 | 69 | ///////////////////////////////////////////////////////////////////////////// 70 | #endif // not APSTUDIO_INVOKED 71 | 72 | -------------------------------------------------------------------------------- /src/player_oam.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | typedef struct SwordResult { 5 | uint8 r6; 6 | uint8 r12; 7 | } SwordResult; 8 | 9 | bool PlayerOam_WantInvokeSword(); 10 | void CalculateSwordHitBox(); 11 | void LinkOam_Main(); 12 | uint8 FindMostSignificantBit(uint8 v); 13 | bool LinkOam_SetWeaponVRAMOffsets(int r2, SwordResult *sr); 14 | bool LinkOam_SetEquipmentVRAMOffsets(int r2, SwordResult *sr); 15 | int LinkOam_CalculateSwordSparklePosition(int oam_pos, uint8 oam_x, uint8 oam_y); 16 | void LinkOam_UnusedWeaponSettings(int r4loc, uint8 oam_x, uint8 oam_y); 17 | void LinkOam_DrawDungeonFallShadow(int r4loc, uint8 xcoord); 18 | void LinkOam_DrawFootObject(int r4loc, uint8 oam_x, uint8 oam_y); 19 | void LinkOam_CalculateXOffsetRelativeLink(uint8 x); 20 | -------------------------------------------------------------------------------- /src/poly.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | uint16 Poly_Divide(uint16 a, uint16 b); 5 | void Poly_RunFrame(); 6 | void Polyhedral_SetShapePointer(); 7 | void Polyhedral_SetRotationMatrix(); 8 | void Polyhedral_OperateRotation(); 9 | void Polyhedral_RotatePoint(); 10 | void Polyhedral_ProjectPoint(); 11 | void Polyhedral_DrawPolyhedron(); 12 | void Polyhedral_SetForegroundColor(); 13 | int16 Polyhedral_CalculateCrossProduct(); 14 | void Polyhedral_SetColorMask(int c); 15 | void Polyhedral_EmptyBitMapBuffer(); 16 | void Polyhedral_DrawFace(); 17 | void Polyhedral_FillLine(); 18 | bool Polyhedral_SetLeft(); 19 | bool Polyhedral_SetRight(); 20 | -------------------------------------------------------------------------------- /src/select_file.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | bool Intro_CheckCksum(const uint8 *s); 5 | uint16 *SelectFile_Func1(); 6 | void SelectFile_Func5_DrawOams(int k); 7 | void SelectFile_Func6_DrawOams2(int k); 8 | void SelectFile_Func17(int k); 9 | void SelectFile_Func16(); 10 | void Module_NamePlayer_1(); 11 | void Module_NamePlayer_2(); 12 | void Intro_FixCksum(uint8 *s); 13 | void LoadFileSelectGraphics(); 14 | void Intro_ValidateSram(); 15 | void Module01_FileSelect(); 16 | void Module_SelectFile_0(); 17 | void FileSelect_ReInitSaveFlagsAndEraseTriforce(); 18 | void FileSelect_EraseTriforce(); 19 | void Module_EraseFile_1(); 20 | void FileSelect_TriggerStripesAndAdvance(); 21 | void FileSelect_TriggerNameStripesAndAdvance(); 22 | void FileSelect_Main(); 23 | void Module02_CopyFile(); 24 | void Module_CopyFile_2(); 25 | void CopyFile_ChooseSelection(); 26 | void CopyFile_ChooseTarget(); 27 | void CopyFile_ConfirmSelection(); 28 | void FilePicker_DeleteHeaderStripe(); 29 | void CopyFile_SelectionAndBlinker(); 30 | void ReturnToFileSelect(); 31 | void CopyFile_TargetSelectionAndBlink(); 32 | void CopyFile_HandleConfirmation(); 33 | void Module03_KILLFile(); 34 | void KILLFile_SetUp(); 35 | void KILLFile_HandleSelection(); 36 | void KILLFile_HandleConfirmation(); 37 | void KILLFile_ChooseTarget(); 38 | void FileSelect_DrawFairy(uint8 x, uint8 y); 39 | void Module04_NameFile(); 40 | void NameFile_EraseSave(); 41 | void NameFile_DoTheNaming(); 42 | void NameFile_CheckForScrollInputX(); 43 | void NameFile_CheckForScrollInputY(); 44 | void NameFile_DrawSelectedCharacter(int k, uint16 chr); 45 | -------------------------------------------------------------------------------- /src/spc_player.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "snes/dsp.h" 3 | 4 | typedef struct Channel { 5 | uint16 pattern_order_ptr_for_chan; 6 | uint8 note_ticks_left; 7 | uint8 note_keyoff_ticks_left; 8 | uint8 subroutine_num_loops; 9 | uint8 volume_fade_ticks; 10 | uint8 pan_num_ticks; 11 | uint8 pitch_slide_length; 12 | uint8 pitch_slide_delay_left; 13 | uint8 vibrato_hold_count; 14 | uint8 vib_depth; 15 | uint8 tremolo_hold_count; 16 | uint8 tremolo_depth; 17 | uint8 vibrato_change_count; 18 | uint8 note_length; 19 | uint8 note_gate_off_fixedpt; 20 | uint8 channel_volume_master; 21 | uint8 instrument_id; 22 | uint16 instrument_pitch_base; 23 | uint16 saved_pattern_ptr; 24 | uint16 pattern_start_ptr; 25 | uint8 pitch_envelope_num_ticks; 26 | uint8 pitch_envelope_delay; 27 | uint8 pitch_envelope_direction; 28 | uint8 pitch_envelope_slide_value; 29 | uint8 vibrato_count; 30 | uint8 vibrato_rate; 31 | uint8 vibrato_delay_ticks; 32 | uint8 vibrato_fade_num_ticks; 33 | uint8 vibrato_fade_add_per_tick; 34 | uint8 vibrato_depth_target; 35 | uint8 tremolo_count; 36 | uint8 tremolo_rate; 37 | uint8 tremolo_delay_ticks; 38 | uint8 channel_transposition; 39 | uint16 channel_volume; 40 | uint16 volume_fade_addpertick; 41 | uint8 volume_fade_target; 42 | uint8 final_volume; 43 | uint16 pan_value; 44 | uint16 pan_add_per_tick; 45 | uint8 pan_target_value; 46 | uint8 pan_flag_with_phase_invert; 47 | uint16 pitch; 48 | uint16 pitch_add_per_tick; 49 | uint8 pitch_target; 50 | uint8 fine_tune; 51 | uint16 sfx_sound_ptr; 52 | uint8 sfx_which_sound; 53 | uint8 sfx_arr_countdown; 54 | uint8 sfx_note_length_left; 55 | uint8 sfx_note_length; 56 | uint8 sfx_pan; 57 | uint8 index; 58 | } Channel; 59 | 60 | typedef struct SpcPlayer { 61 | DspRegWriteHistory *reg_write_history; 62 | uint8 timer_cycles; 63 | Dsp *dsp; 64 | uint8 new_value_from_snes[4]; 65 | uint8 port_to_snes[4]; 66 | uint8 last_value_from_snes[4]; 67 | uint8 counter_sf0c; 68 | uint16 _always_zero; 69 | uint16 temp_accum; 70 | uint8 ttt; 71 | uint8 did_affect_volumepitch_flag; 72 | uint16 addr0; 73 | uint16 addr1; 74 | uint16 lfsr_value; 75 | uint8 is_chan_on; 76 | uint8 fast_forward; 77 | uint8 sfx_start_arg_pan; 78 | uint16 sfx_sound_ptr_cur; 79 | uint16 music_ptr_toplevel; 80 | uint8 block_count; 81 | uint8 sfx_timer_accum; 82 | uint8 chn; 83 | uint8 key_ON; 84 | uint8 key_OFF; 85 | uint8 cur_chan_bit; 86 | uint8 reg_FLG; 87 | uint8 reg_NON; 88 | uint8 reg_EON; 89 | uint8 reg_PMON; 90 | uint8 echo_stored_time; 91 | uint8 echo_parameter_EDL; 92 | uint8 reg_EFB; 93 | uint8 global_transposition; 94 | uint8 main_tempo_accum; 95 | uint16 tempo; 96 | uint8 tempo_fade_num_ticks; 97 | uint8 tempo_fade_final; 98 | uint16 tempo_fade_add; 99 | uint16 master_volume; 100 | uint8 master_volume_fade_ticks; 101 | uint8 master_volume_fade_target; 102 | uint16 master_volume_fade_add_per_tick; 103 | uint8 vol_dirty; 104 | uint8 percussion_base_id; 105 | uint16 echo_volume_left; 106 | uint16 echo_volume_right; 107 | uint16 echo_volume_fade_add_left; 108 | uint16 echo_volume_fade_add_right; 109 | uint8 echo_volume_fade_ticks; 110 | uint8 echo_volume_fade_target_left; 111 | uint8 echo_volume_fade_target_right; 112 | uint8 sfx_channel_index; 113 | uint8 current_bit; 114 | uint8 dsp_register_index; 115 | uint8 echo_channels; 116 | uint8 byte_3C4; 117 | uint8 byte_3C5; 118 | uint8 echo_fract_incr; 119 | uint8 sfx_channel_index2; 120 | uint8 sfx_channel_bit; 121 | uint8 pause_music_ctr; 122 | uint8 port2_active; 123 | uint8 port2_current_bit; 124 | uint8 port3_active; 125 | uint8 port3_current_bit; 126 | uint8 port1_active; 127 | uint8 port1_current_bit; 128 | uint8 byte_3E1; 129 | uint8 sfx_play_echo_flag; 130 | uint8 sfx_channels_echo_mask2; 131 | uint8 port1_counter; 132 | uint8 channel_67_volume; 133 | uint8 cutk_always_zero; 134 | uint8 last_written_edl; 135 | uint8 input_ports[4]; 136 | Channel channel[8]; 137 | uint8 ram[65536]; // rest of ram 138 | } SpcPlayer; 139 | 140 | SpcPlayer *SpcPlayer_Create(); 141 | void SpcPlayer_GenerateSamples(SpcPlayer *p); 142 | void SpcPlayer_Initialize(SpcPlayer *p); 143 | void SpcPlayer_Upload(SpcPlayer *p, const uint8_t *data); 144 | void SpcPlayer_CopyVariablesFromRam(SpcPlayer *p); 145 | void SpcPlayer_CopyVariablesToRam(SpcPlayer *p); 146 | -------------------------------------------------------------------------------- /src/tagalong.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | typedef struct TagalongMessageInfo { 5 | uint16 y, x, bit, msg, tagalong; 6 | } TagalongMessageInfo; 7 | 8 | bool Tagalong_IsFollowing(); 9 | bool Follower_ValidateMessageFreedom(); 10 | void Follower_MoveTowardsLink(); 11 | bool Follower_CheckBlindTrigger(); 12 | void Follower_Initialize(); 13 | void Sprite_BecomeFollower(int k); 14 | void Follower_Main(); 15 | void Follower_NoTimedMessage(); 16 | void Follower_CheckGameMode(); 17 | void Follower_BasicMover(); 18 | void Follower_NotFollowing(); 19 | void Follower_OldMan(); 20 | void Follower_OldManUnused(); 21 | void Follower_DoLayers(); 22 | bool Follower_CheckProximityToLink(); 23 | void Follower_HandleTrigger(); 24 | void Tagalong_Draw(); 25 | void Follower_AnimateMovement_preserved(uint8 ain, uint16 xin, uint16 yin); 26 | bool Follower_CheckForTrigger(const TagalongMessageInfo *info); 27 | void Follower_Disable(); 28 | void Blind_SpawnFromMaiden(uint16 x, uint16 y); 29 | void Kiki_RevertToSprite(int k); 30 | int Kiki_SpawnHandlerMonke(int k); 31 | void Kiki_SpawnHandler_A(int k); 32 | void Kiki_SpawnHandler_B(int k); 33 | -------------------------------------------------------------------------------- /src/tile_detect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | 5 | uint8 Overworld_GetTileAttributeAtLocation(uint16 x, uint16 y); 6 | void TileDetect_Movement_Y(uint16 direction); 7 | void TileDetect_Movement_X(uint16 direction); 8 | void TileDetect_Movement_VerticalSlopes(uint16_t direction); 9 | void TileDetect_Movement_HorizontalSlopes(uint16_t direction); 10 | void Player_TileDetectNearby(); 11 | void Hookshot_CheckTileCollision(int k); 12 | void Hookshot_CheckSingleLayerTileCollision(uint16 x, uint16 y, int dir); 13 | void HandleNudgingInADoor(int8 speed); 14 | void TileCheckForMirrorBonk(); 15 | void TileDetect_SwordSwingDeepInDoor(uint8 dw); 16 | void TileDetect_ResetState(); 17 | void TileDetection_Execute(uint16 x, uint16 y, uint16 bits); 18 | void TileDetect_ExecuteInner(uint8 tile, uint16 offs, uint16 bits, bool is_indoors); 19 | -------------------------------------------------------------------------------- /src/types.h: -------------------------------------------------------------------------------- 1 | #ifndef ZELDA3_TYPES_H_ 2 | #define ZELDA3_TYPES_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | // Build time config options 9 | enum { 10 | kEnableLargeScreen = 1, 11 | // How much extra spacing to add on the sides 12 | kPpuExtraLeftRight = kEnableLargeScreen ? 96 : 0, 13 | }; 14 | 15 | typedef uint8_t uint8; 16 | typedef int8_t int8; 17 | typedef uint16_t uint16; 18 | typedef int16_t int16; 19 | typedef uint32_t uint32; 20 | typedef int32_t int32; 21 | typedef uint64_t uint64; 22 | typedef int64_t int64; 23 | typedef unsigned int uint; 24 | 25 | #define arraysize(x) sizeof(x)/sizeof(x[0]) 26 | #define sign8(x) ((x) & 0x80) 27 | #define sign16(x) ((x) & 0x8000) 28 | #define load24(x) ((*(uint32*)&(x))&0xffffff) 29 | 30 | #ifdef _MSC_VER 31 | #define countof _countof 32 | #define NORETURN __declspec(noreturn) 33 | #define FORCEINLINE __forceinline 34 | #define NOINLINE __declspec(noinline) 35 | #else 36 | #define countof(a) (sizeof(a)/sizeof(*(a))) 37 | #define NORETURN 38 | #define FORCEINLINE inline 39 | #define NOINLINE 40 | #endif 41 | 42 | #ifdef _DEBUG 43 | #define kDebugFlag 1 44 | #else 45 | #define kDebugFlag 0 46 | #endif 47 | 48 | static FORCEINLINE uint16 abs16(uint16 t) { return sign16(t) ? -t : t; } 49 | static FORCEINLINE uint8 abs8(uint8 t) { return sign8(t) ? -t : t; } 50 | static FORCEINLINE int IntMin(int a, int b) { return a < b ? a : b; } 51 | static FORCEINLINE int IntMax(int a, int b) { return a > b ? a : b; } 52 | static FORCEINLINE uint UintMin(uint a, uint b) { return a < b ? a : b; } 53 | static FORCEINLINE uint UintMax(uint a, uint b) { return a > b ? a : b; } 54 | 55 | // windows.h defines this too 56 | #ifdef HIBYTE 57 | #undef HIBYTE 58 | #endif 59 | 60 | #define BYTE(x) (*(uint8*)&(x)) 61 | #define HIBYTE(x) (((uint8*)&(x))[1]) 62 | #define WORD(x) (*(uint16*)&(x)) 63 | #define DWORD(x) (*(uint32*)&(x)) 64 | #define XY(x, y) ((y)*64+(x)) 65 | 66 | #ifndef swap16 67 | static inline uint16 swap16(uint16 v) { return (v << 8) | (v >> 8); } 68 | #endif 69 | 70 | typedef struct Point16U { 71 | uint16 x, y; 72 | } Point16U; 73 | 74 | typedef struct PointU8 { 75 | uint8 x, y; 76 | } PointU8; 77 | 78 | typedef struct Pair16U { 79 | uint16 a, b; 80 | } Pair16U; 81 | 82 | typedef struct PairU8 { 83 | uint8 a, b; 84 | } PairU8; 85 | 86 | typedef struct ProjectSpeedRet { 87 | uint8 x, y; 88 | uint8 xdiff, ydiff; 89 | } ProjectSpeedRet; 90 | 91 | typedef struct OamEnt { 92 | uint8 x, y, charnum, flags; 93 | } OamEnt; 94 | 95 | typedef struct MemBlk { 96 | const uint8 *ptr; 97 | size_t size; 98 | } MemBlk; 99 | MemBlk FindIndexInMemblk(MemBlk data, size_t i); 100 | 101 | void NORETURN Die(const char *error); 102 | 103 | #endif // ZELDA3_TYPES_H_ 104 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | #ifndef ZELDA3_UTIL_H_ 2 | #define ZELDA3_UTIL_H_ 3 | 4 | #include "types.h" 5 | 6 | typedef struct SDL_Window SDL_Window; 7 | 8 | struct RendererFuncs { 9 | bool (*Initialize)(SDL_Window *window); 10 | void (*Destroy)(); 11 | void (*BeginDraw)(int width, int height, uint8 **pixels, int *pitch); 12 | void (*EndDraw)(); 13 | }; 14 | 15 | 16 | typedef struct ByteArray { 17 | uint8 *data; 18 | size_t size, capacity; 19 | } ByteArray; 20 | 21 | void ByteArray_Resize(ByteArray *arr, size_t new_size); 22 | void ByteArray_Destroy(ByteArray *arr); 23 | void ByteArray_AppendData(ByteArray *arr, const uint8 *data, size_t data_size); 24 | void ByteArray_AppendByte(ByteArray *arr, uint8 v); 25 | 26 | uint8 *ReadWholeFile(const char *name, size_t *length); 27 | char *NextDelim(char **s, int sep); 28 | char *NextLineStripComments(char **s); 29 | char *NextPossiblyQuotedString(char **s); 30 | char *SplitKeyValue(char *p); 31 | bool StringEqualsNoCase(const char *a, const char *b); 32 | const char *StringStartsWithNoCase(const char *a, const char *b); 33 | bool ParseBool(const char *value, bool *result); 34 | const char *SkipPrefix(const char *big, const char *little); 35 | void StrSet(char **rv, const char *s); 36 | char *StrFmt(const char *fmt, ...); 37 | char *ReplaceFilenameWithNewPath(const char *old_path, const char *new_path); 38 | uint8 *ApplyBps(const uint8 *src, size_t src_size_in, 39 | const uint8 *bps, size_t bps_size, size_t *length_out); 40 | 41 | #endif // ZELDA3_UTIL_H_ -------------------------------------------------------------------------------- /src/zelda_cpu_infra.h: -------------------------------------------------------------------------------- 1 | #ifndef ZELDA3_ZELDA_CPU_INFRA_H_ 2 | #define ZELDA3_ZELDA_CPU_INFRA_H_ 3 | #include "types.h" 4 | 5 | extern uint8 g_emulated_ram[0x20000]; 6 | 7 | uint8 *GetPtr(uint32 addr); 8 | 9 | void RunEmulatedFuncSilent(uint32 pc, uint16 a, uint16 x, uint16 y, bool mf, bool xf, int b, int whatflags); 10 | void RunEmulatedFunc(uint32 pc, uint16 a, uint16 x, uint16 y, bool mf, bool xf, int b, int whatflags); 11 | 12 | bool EmuInitialize(uint8 *data, size_t size); 13 | 14 | #endif // ZELDA3_ZELDA_CPU_INFRA_H_ 15 | -------------------------------------------------------------------------------- /src/zelda_rtl.h: -------------------------------------------------------------------------------- 1 | // This file defines various things related to the runtime environment 2 | // of the code 3 | #ifndef ZELDA3_ZELDA_RTL_H_ 4 | #define ZELDA3_ZELDA_RTL_H_ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "types.h" 12 | #include "features.h" 13 | 14 | struct Snes; 15 | struct Dsp; 16 | 17 | typedef struct ZeldaEnv { 18 | uint8 *ram; 19 | uint8 *sram; 20 | uint16 *vram; 21 | struct Ppu *ppu; 22 | struct SpcPlayer *player; 23 | struct Dma *dma; 24 | 25 | MemBlk dialogue_blk; 26 | MemBlk dialogue_font_blk; 27 | uint8 dialogue_flags; 28 | } ZeldaEnv; 29 | extern ZeldaEnv g_zenv; 30 | extern int frame_ctr_dbg; 31 | 32 | typedef void PlayerHandlerFunc(); 33 | typedef void HandlerFuncK(int k); 34 | 35 | static inline void zelda_snes_dummy_write(uint32 adr, uint8 val) {} 36 | 37 | void zelda_apu_write(uint32_t adr, uint8_t val); 38 | uint8_t zelda_read_apui00(); 39 | uint8_t zelda_apu_read(uint32_t adr); 40 | void zelda_ppu_write(uint32_t adr, uint8_t val); 41 | void zelda_ppu_write_word(uint32_t adr, uint16_t val); 42 | 43 | 44 | // 512x480 32-bit pixels. Returns true if we instead draw 1024x960 45 | void HdmaSetup(uint32 addr6, uint32 addr7, uint8 transfer_unit, uint8 reg6, uint8 reg7, uint8 indirect_bank); 46 | 47 | void ZeldaInitialize(); 48 | void ZeldaReset(bool preserve_sram); 49 | void ZeldaDrawPpuFrame(uint8 *pixel_buffer, size_t pitch, uint32 render_flags); 50 | void ZeldaRunFrameInternal(uint16 input, int run_what); 51 | bool ZeldaRunFrame(int input_state); 52 | void LoadSongBank(const uint8 *p); 53 | void ZeldaApuLock(); 54 | void ZeldaApuUnlock(); 55 | bool ZeldaIsPlayingMusicTrack(uint8 track); 56 | uint8 ZeldaGetEntranceMusicTrack(int track); 57 | void ZeldaSetLanguage(const char *language); 58 | void PatchCommand(char cmd); 59 | 60 | // Things for state management 61 | 62 | enum { 63 | kSaveLoad_Save = 0, 64 | kSaveLoad_Load = 1, 65 | kSaveLoad_Replay = 2, 66 | }; 67 | 68 | void SaveLoadSlot(int cmd, int which); 69 | void ZeldaWriteSram(); 70 | void ZeldaReadSram(); 71 | 72 | typedef void ZeldaRunFrameFunc(uint16 input, int run_what); 73 | typedef void ZeldaSyncAllFunc(); 74 | 75 | void ZeldaSetupEmuCallbacks(uint8 *emu_ram, ZeldaRunFrameFunc *func, ZeldaSyncAllFunc *sync_all); 76 | 77 | // Button definitions, zelda splits them in separate 8-bit high/low 78 | enum { 79 | kJoypadL_A = 0x80, 80 | kJoypadL_X = 0x40, 81 | kJoypadL_L = 0x20, 82 | kJoypadL_R = 0x10, 83 | 84 | kJoypadH_B = 0x80, 85 | kJoypadH_Y = 0x40, 86 | kJoypadH_Select = 0x20, 87 | kJoypadH_Start = 0x10, 88 | 89 | kJoypadH_Up = 0x8, 90 | kJoypadH_Down = 0x4, 91 | kJoypadH_Left = 0x2, 92 | kJoypadH_Right = 0x1, 93 | 94 | kJoypadH_AnyDir = 0xf, 95 | }; 96 | 97 | #endif // ZELDA3_ZELDA_RTL_H_ 98 | -------------------------------------------------------------------------------- /third_party/.gitignore: -------------------------------------------------------------------------------- 1 | /tcc/ 2 | /SDL2-2.*/ 3 | /gl_core/*.o -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/.gitignore: -------------------------------------------------------------------------------- 1 | /opus_decoder_amalgam.o 2 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/AUTHORS: -------------------------------------------------------------------------------- 1 | Jean-Marc Valin (jmvalin@jmvalin.ca) 2 | Koen Vos (koenvos74@gmail.com) 3 | Timothy Terriberry (tterribe@xiph.org) 4 | Karsten Vandborg Sorensen (karsten.vandborg.sorensen@skype.net) 5 | Soren Skak Jensen (ssjensen@gn.com) 6 | Gregory Maxwell (greg@xiph.org) 7 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic, 2 | Jean-Marc Valin, Timothy B. Terriberry, 3 | CSIRO, Gregory Maxwell, Mark Borgerding, 4 | Erik de Castro Lopo 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | - Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | - Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 18 | names of specific contributors, may be used to endorse or promote 19 | products derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 26 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | Opus is subject to the royalty-free patent licenses which are 35 | specified at: 36 | 37 | Xiph.Org Foundation: 38 | https://datatracker.ietf.org/ipr/1524/ 39 | 40 | Microsoft Corporation: 41 | https://datatracker.ietf.org/ipr/1914/ 42 | 43 | Broadcom Corporation: 44 | https://datatracker.ietf.org/ipr/1526/ 45 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/armcpu.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 Xiph.Org Foundation 2 | * Copyright (c) 2013 Parrot */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if !defined(ARMCPU_H) 29 | # define ARMCPU_H 30 | 31 | # if defined(OPUS_ARM_MAY_HAVE_EDSP) 32 | # define MAY_HAVE_EDSP(name) name ## _edsp 33 | # else 34 | # define MAY_HAVE_EDSP(name) name ## _c 35 | # endif 36 | 37 | # if defined(OPUS_ARM_MAY_HAVE_MEDIA) 38 | # define MAY_HAVE_MEDIA(name) name ## _media 39 | # else 40 | # define MAY_HAVE_MEDIA(name) MAY_HAVE_EDSP(name) 41 | # endif 42 | 43 | # if defined(OPUS_ARM_MAY_HAVE_NEON) 44 | # define MAY_HAVE_NEON(name) name ## _neon 45 | # else 46 | # define MAY_HAVE_NEON(name) MAY_HAVE_MEDIA(name) 47 | # endif 48 | 49 | # if defined(OPUS_ARM_PRESUME_EDSP) 50 | # define PRESUME_EDSP(name) name ## _edsp 51 | # else 52 | # define PRESUME_EDSP(name) name ## _c 53 | # endif 54 | 55 | # if defined(OPUS_ARM_PRESUME_MEDIA) 56 | # define PRESUME_MEDIA(name) name ## _media 57 | # else 58 | # define PRESUME_MEDIA(name) PRESUME_EDSP(name) 59 | # endif 60 | 61 | # if defined(OPUS_ARM_PRESUME_NEON) 62 | # define PRESUME_NEON(name) name ## _neon 63 | # else 64 | # define PRESUME_NEON(name) PRESUME_MEDIA(name) 65 | # endif 66 | 67 | # if defined(OPUS_HAVE_RTCD) 68 | int opus_select_arch(void); 69 | 70 | #define OPUS_ARCH_ARM_V4 (0) 71 | #define OPUS_ARCH_ARM_EDSP (1) 72 | #define OPUS_ARCH_ARM_MEDIA (2) 73 | #define OPUS_ARCH_ARM_NEON (3) 74 | 75 | # endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/armopts.s.in: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Mozilla Corporation */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | ; Set the following to 1 if we have EDSP instructions 28 | ; (LDRD/STRD, etc., ARMv5E and later). 29 | OPUS_ARM_MAY_HAVE_EDSP * @OPUS_ARM_MAY_HAVE_EDSP@ 30 | 31 | ; Set the following to 1 if we have ARMv6 media instructions. 32 | OPUS_ARM_MAY_HAVE_MEDIA * @OPUS_ARM_MAY_HAVE_MEDIA@ 33 | 34 | ; Set the following to 1 if we have NEON (some ARMv7) 35 | OPUS_ARM_MAY_HAVE_NEON * @OPUS_ARM_MAY_HAVE_NEON@ 36 | 37 | END 38 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/fft_arm.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015 Xiph.Org Foundation 2 | Written by Viswanath Puttagunta */ 3 | /** 4 | @file fft_arm.h 5 | @brief ARM Neon Intrinsic optimizations for fft using NE10 library 6 | */ 7 | 8 | /* 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | - Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | - Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | 34 | #if !defined(FFT_ARM_H) 35 | #define FFT_ARM_H 36 | 37 | #include "kiss_fft.h" 38 | 39 | #if defined(HAVE_ARM_NE10) 40 | 41 | int opus_fft_alloc_arm_neon(kiss_fft_state *st); 42 | void opus_fft_free_arm_neon(kiss_fft_state *st); 43 | 44 | void opus_fft_neon(const kiss_fft_state *st, 45 | const kiss_fft_cpx *fin, 46 | kiss_fft_cpx *fout); 47 | 48 | void opus_ifft_neon(const kiss_fft_state *st, 49 | const kiss_fft_cpx *fin, 50 | kiss_fft_cpx *fout); 51 | 52 | #if !defined(OPUS_HAVE_RTCD) 53 | #define OVERRIDE_OPUS_FFT (1) 54 | 55 | #define opus_fft_alloc_arch(_st, arch) \ 56 | ((void)(arch), opus_fft_alloc_arm_neon(_st)) 57 | 58 | #define opus_fft_free_arch(_st, arch) \ 59 | ((void)(arch), opus_fft_free_arm_neon(_st)) 60 | 61 | #define opus_fft(_st, _fin, _fout, arch) \ 62 | ((void)(arch), opus_fft_neon(_st, _fin, _fout)) 63 | 64 | #define opus_ifft(_st, _fin, _fout, arch) \ 65 | ((void)(arch), opus_ifft_neon(_st, _fin, _fout)) 66 | 67 | #endif /* OPUS_HAVE_RTCD */ 68 | 69 | #endif /* HAVE_ARM_NE10 */ 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/fixed_arm64.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Vidyo */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef FIXED_ARM64_H 28 | #define FIXED_ARM64_H 29 | 30 | #include 31 | 32 | #undef SIG2WORD16 33 | #define SIG2WORD16(x) (vqmovns_s32(PSHR32((x), SIG_SHIFT))) 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/fixed_armv4.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Xiph.Org Foundation and contributors */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef FIXED_ARMv4_H 28 | #define FIXED_ARMv4_H 29 | 30 | /** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */ 31 | #undef MULT16_32_Q16 32 | static OPUS_INLINE opus_val32 MULT16_32_Q16_armv4(opus_val16 a, opus_val32 b) 33 | { 34 | unsigned rd_lo; 35 | int rd_hi; 36 | __asm__( 37 | "#MULT16_32_Q16\n\t" 38 | "smull %0, %1, %2, %3\n\t" 39 | : "=&r"(rd_lo), "=&r"(rd_hi) 40 | : "%r"(b),"r"(SHL32(a,16)) 41 | ); 42 | return rd_hi; 43 | } 44 | #define MULT16_32_Q16(a, b) (MULT16_32_Q16_armv4(a, b)) 45 | 46 | 47 | /** 16x32 multiplication, followed by a 15-bit shift right. Results fits in 32 bits */ 48 | #undef MULT16_32_Q15 49 | static OPUS_INLINE opus_val32 MULT16_32_Q15_armv4(opus_val16 a, opus_val32 b) 50 | { 51 | unsigned rd_lo; 52 | int rd_hi; 53 | __asm__( 54 | "#MULT16_32_Q15\n\t" 55 | "smull %0, %1, %2, %3\n\t" 56 | : "=&r"(rd_lo), "=&r"(rd_hi) 57 | : "%r"(b), "r"(SHL32(a,16)) 58 | ); 59 | /*We intentionally don't OR in the high bit of rd_lo for speed.*/ 60 | return SHL32(rd_hi,1); 61 | } 62 | #define MULT16_32_Q15(a, b) (MULT16_32_Q15_armv4(a, b)) 63 | 64 | 65 | /** 16x32 multiply, followed by a 15-bit shift right and 32-bit add. 66 | b must fit in 31 bits. 67 | Result fits in 32 bits. */ 68 | #undef MAC16_32_Q15 69 | #define MAC16_32_Q15(c, a, b) ADD32(c, MULT16_32_Q15(a, b)) 70 | 71 | /** 16x32 multiply, followed by a 16-bit shift right and 32-bit add. 72 | Result fits in 32 bits. */ 73 | #undef MAC16_32_Q16 74 | #define MAC16_32_Q16(c, a, b) ADD32(c, MULT16_32_Q16(a, b)) 75 | 76 | /** 32x32 multiplication, followed by a 31-bit shift right. Results fits in 32 bits */ 77 | #undef MULT32_32_Q31 78 | #define MULT32_32_Q31(a,b) (opus_val32)((((opus_int64)(a)) * ((opus_int64)(b)))>>31) 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/fixed_armv5e.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007-2009 Xiph.Org Foundation 2 | Copyright (C) 2003-2008 Jean-Marc Valin 3 | Copyright (C) 2007-2008 CSIRO 4 | Copyright (C) 2013 Parrot */ 5 | /* 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | - Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | - Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 21 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef FIXED_ARMv5E_H 31 | #define FIXED_ARMv5E_H 32 | 33 | #include "fixed_armv4.h" 34 | 35 | /** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */ 36 | #undef MULT16_32_Q16 37 | static OPUS_INLINE opus_val32 MULT16_32_Q16_armv5e(opus_val16 a, opus_val32 b) 38 | { 39 | int res; 40 | __asm__( 41 | "#MULT16_32_Q16\n\t" 42 | "smulwb %0, %1, %2\n\t" 43 | : "=r"(res) 44 | : "r"(b),"r"(a) 45 | ); 46 | return res; 47 | } 48 | #define MULT16_32_Q16(a, b) (MULT16_32_Q16_armv5e(a, b)) 49 | 50 | 51 | /** 16x32 multiplication, followed by a 15-bit shift right. Results fits in 32 bits */ 52 | #undef MULT16_32_Q15 53 | static OPUS_INLINE opus_val32 MULT16_32_Q15_armv5e(opus_val16 a, opus_val32 b) 54 | { 55 | int res; 56 | __asm__( 57 | "#MULT16_32_Q15\n\t" 58 | "smulwb %0, %1, %2\n\t" 59 | : "=r"(res) 60 | : "r"(b), "r"(a) 61 | ); 62 | return SHL32(res,1); 63 | } 64 | #define MULT16_32_Q15(a, b) (MULT16_32_Q15_armv5e(a, b)) 65 | 66 | 67 | /** 16x32 multiply, followed by a 15-bit shift right and 32-bit add. 68 | b must fit in 31 bits. 69 | Result fits in 32 bits. */ 70 | #undef MAC16_32_Q15 71 | static OPUS_INLINE opus_val32 MAC16_32_Q15_armv5e(opus_val32 c, opus_val16 a, 72 | opus_val32 b) 73 | { 74 | int res; 75 | __asm__( 76 | "#MAC16_32_Q15\n\t" 77 | "smlawb %0, %1, %2, %3;\n" 78 | : "=r"(res) 79 | : "r"(SHL32(b,1)), "r"(a), "r"(c) 80 | ); 81 | return res; 82 | } 83 | #define MAC16_32_Q15(c, a, b) (MAC16_32_Q15_armv5e(c, a, b)) 84 | 85 | /** 16x32 multiply, followed by a 16-bit shift right and 32-bit add. 86 | Result fits in 32 bits. */ 87 | #undef MAC16_32_Q16 88 | static OPUS_INLINE opus_val32 MAC16_32_Q16_armv5e(opus_val32 c, opus_val16 a, 89 | opus_val32 b) 90 | { 91 | int res; 92 | __asm__( 93 | "#MAC16_32_Q16\n\t" 94 | "smlawb %0, %1, %2, %3;\n" 95 | : "=r"(res) 96 | : "r"(b), "r"(a), "r"(c) 97 | ); 98 | return res; 99 | } 100 | #define MAC16_32_Q16(c, a, b) (MAC16_32_Q16_armv5e(c, a, b)) 101 | 102 | /** 16x16 multiply-add where the result fits in 32 bits */ 103 | #undef MAC16_16 104 | static OPUS_INLINE opus_val32 MAC16_16_armv5e(opus_val32 c, opus_val16 a, 105 | opus_val16 b) 106 | { 107 | int res; 108 | __asm__( 109 | "#MAC16_16\n\t" 110 | "smlabb %0, %1, %2, %3;\n" 111 | : "=r"(res) 112 | : "r"(a), "r"(b), "r"(c) 113 | ); 114 | return res; 115 | } 116 | #define MAC16_16(c, a, b) (MAC16_16_armv5e(c, a, b)) 117 | 118 | /** 16x16 multiplication where the result fits in 32 bits */ 119 | #undef MULT16_16 120 | static OPUS_INLINE opus_val32 MULT16_16_armv5e(opus_val16 a, opus_val16 b) 121 | { 122 | int res; 123 | __asm__( 124 | "#MULT16_16\n\t" 125 | "smulbb %0, %1, %2;\n" 126 | : "=r"(res) 127 | : "r"(a), "r"(b) 128 | ); 129 | return res; 130 | } 131 | #define MULT16_16(a, b) (MULT16_16_armv5e(a, b)) 132 | 133 | #ifdef OPUS_ARM_INLINE_MEDIA 134 | 135 | #undef SIG2WORD16 136 | static OPUS_INLINE opus_val16 SIG2WORD16_armv6(opus_val32 x) 137 | { 138 | celt_sig res; 139 | __asm__( 140 | "#SIG2WORD16\n\t" 141 | "ssat %0, #16, %1, ASR #12\n\t" 142 | : "=r"(res) 143 | : "r"(x+2048) 144 | ); 145 | return EXTRACT16(res); 146 | } 147 | #define SIG2WORD16(x) (SIG2WORD16_armv6(x)) 148 | 149 | #endif /* OPUS_ARM_INLINE_MEDIA */ 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/kiss_fft_armv4.h: -------------------------------------------------------------------------------- 1 | /*Copyright (c) 2013, Xiph.Org Foundation and contributors. 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE.*/ 25 | 26 | #ifndef KISS_FFT_ARMv4_H 27 | #define KISS_FFT_ARMv4_H 28 | 29 | #if !defined(KISS_FFT_GUTS_H) 30 | #error "This file should only be included from _kiss_fft_guts.h" 31 | #endif 32 | 33 | #ifdef FIXED_POINT 34 | 35 | #undef C_MUL 36 | #define C_MUL(m,a,b) \ 37 | do{ \ 38 | int br__; \ 39 | int bi__; \ 40 | int tt__; \ 41 | __asm__ __volatile__( \ 42 | "#C_MUL\n\t" \ 43 | "ldrsh %[br], [%[bp], #0]\n\t" \ 44 | "ldm %[ap], {r0,r1}\n\t" \ 45 | "ldrsh %[bi], [%[bp], #2]\n\t" \ 46 | "smull %[tt], %[mi], r1, %[br]\n\t" \ 47 | "smlal %[tt], %[mi], r0, %[bi]\n\t" \ 48 | "rsb %[bi], %[bi], #0\n\t" \ 49 | "smull %[br], %[mr], r0, %[br]\n\t" \ 50 | "mov %[tt], %[tt], lsr #15\n\t" \ 51 | "smlal %[br], %[mr], r1, %[bi]\n\t" \ 52 | "orr %[mi], %[tt], %[mi], lsl #17\n\t" \ 53 | "mov %[br], %[br], lsr #15\n\t" \ 54 | "orr %[mr], %[br], %[mr], lsl #17\n\t" \ 55 | : [mr]"=r"((m).r), [mi]"=r"((m).i), \ 56 | [br]"=&r"(br__), [bi]"=r"(bi__), [tt]"=r"(tt__) \ 57 | : [ap]"r"(&(a)), [bp]"r"(&(b)) \ 58 | : "r0", "r1" \ 59 | ); \ 60 | } \ 61 | while(0) 62 | 63 | #undef C_MUL4 64 | #define C_MUL4(m,a,b) \ 65 | do{ \ 66 | int br__; \ 67 | int bi__; \ 68 | int tt__; \ 69 | __asm__ __volatile__( \ 70 | "#C_MUL4\n\t" \ 71 | "ldrsh %[br], [%[bp], #0]\n\t" \ 72 | "ldm %[ap], {r0,r1}\n\t" \ 73 | "ldrsh %[bi], [%[bp], #2]\n\t" \ 74 | "smull %[tt], %[mi], r1, %[br]\n\t" \ 75 | "smlal %[tt], %[mi], r0, %[bi]\n\t" \ 76 | "rsb %[bi], %[bi], #0\n\t" \ 77 | "smull %[br], %[mr], r0, %[br]\n\t" \ 78 | "mov %[tt], %[tt], lsr #17\n\t" \ 79 | "smlal %[br], %[mr], r1, %[bi]\n\t" \ 80 | "orr %[mi], %[tt], %[mi], lsl #15\n\t" \ 81 | "mov %[br], %[br], lsr #17\n\t" \ 82 | "orr %[mr], %[br], %[mr], lsl #15\n\t" \ 83 | : [mr]"=r"((m).r), [mi]"=r"((m).i), \ 84 | [br]"=&r"(br__), [bi]"=r"(bi__), [tt]"=r"(tt__) \ 85 | : [ap]"r"(&(a)), [bp]"r"(&(b)) \ 86 | : "r0", "r1" \ 87 | ); \ 88 | } \ 89 | while(0) 90 | 91 | #undef C_MULC 92 | #define C_MULC(m,a,b) \ 93 | do{ \ 94 | int br__; \ 95 | int bi__; \ 96 | int tt__; \ 97 | __asm__ __volatile__( \ 98 | "#C_MULC\n\t" \ 99 | "ldrsh %[br], [%[bp], #0]\n\t" \ 100 | "ldm %[ap], {r0,r1}\n\t" \ 101 | "ldrsh %[bi], [%[bp], #2]\n\t" \ 102 | "smull %[tt], %[mr], r0, %[br]\n\t" \ 103 | "smlal %[tt], %[mr], r1, %[bi]\n\t" \ 104 | "rsb %[bi], %[bi], #0\n\t" \ 105 | "smull %[br], %[mi], r1, %[br]\n\t" \ 106 | "mov %[tt], %[tt], lsr #15\n\t" \ 107 | "smlal %[br], %[mi], r0, %[bi]\n\t" \ 108 | "orr %[mr], %[tt], %[mr], lsl #17\n\t" \ 109 | "mov %[br], %[br], lsr #15\n\t" \ 110 | "orr %[mi], %[br], %[mi], lsl #17\n\t" \ 111 | : [mr]"=r"((m).r), [mi]"=r"((m).i), \ 112 | [br]"=&r"(br__), [bi]"=r"(bi__), [tt]"=r"(tt__) \ 113 | : [ap]"r"(&(a)), [bp]"r"(&(b)) \ 114 | : "r0", "r1" \ 115 | ); \ 116 | } \ 117 | while(0) 118 | 119 | #endif /* FIXED_POINT */ 120 | 121 | #endif /* KISS_FFT_ARMv4_H */ 122 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/kiss_fft_armv5e.h: -------------------------------------------------------------------------------- 1 | /*Copyright (c) 2013, Xiph.Org Foundation and contributors. 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE.*/ 25 | 26 | #ifndef KISS_FFT_ARMv5E_H 27 | #define KISS_FFT_ARMv5E_H 28 | 29 | #if !defined(KISS_FFT_GUTS_H) 30 | #error "This file should only be included from _kiss_fft_guts.h" 31 | #endif 32 | 33 | #ifdef FIXED_POINT 34 | 35 | #if defined(__thumb__)||defined(__thumb2__) 36 | #define LDRD_CONS "Q" 37 | #else 38 | #define LDRD_CONS "Uq" 39 | #endif 40 | 41 | #undef C_MUL 42 | #define C_MUL(m,a,b) \ 43 | do{ \ 44 | int mr1__; \ 45 | int mr2__; \ 46 | int mi__; \ 47 | long long aval__; \ 48 | int bval__; \ 49 | __asm__( \ 50 | "#C_MUL\n\t" \ 51 | "ldrd %[aval], %H[aval], %[ap]\n\t" \ 52 | "ldr %[bval], %[bp]\n\t" \ 53 | "smulwb %[mi], %H[aval], %[bval]\n\t" \ 54 | "smulwb %[mr1], %[aval], %[bval]\n\t" \ 55 | "smulwt %[mr2], %H[aval], %[bval]\n\t" \ 56 | "smlawt %[mi], %[aval], %[bval], %[mi]\n\t" \ 57 | : [mr1]"=r"(mr1__), [mr2]"=r"(mr2__), [mi]"=r"(mi__), \ 58 | [aval]"=&r"(aval__), [bval]"=r"(bval__) \ 59 | : [ap]LDRD_CONS(a), [bp]"m"(b) \ 60 | ); \ 61 | (m).r = SHL32(SUB32(mr1__, mr2__), 1); \ 62 | (m).i = SHL32(mi__, 1); \ 63 | } \ 64 | while(0) 65 | 66 | #undef C_MUL4 67 | #define C_MUL4(m,a,b) \ 68 | do{ \ 69 | int mr1__; \ 70 | int mr2__; \ 71 | int mi__; \ 72 | long long aval__; \ 73 | int bval__; \ 74 | __asm__( \ 75 | "#C_MUL4\n\t" \ 76 | "ldrd %[aval], %H[aval], %[ap]\n\t" \ 77 | "ldr %[bval], %[bp]\n\t" \ 78 | "smulwb %[mi], %H[aval], %[bval]\n\t" \ 79 | "smulwb %[mr1], %[aval], %[bval]\n\t" \ 80 | "smulwt %[mr2], %H[aval], %[bval]\n\t" \ 81 | "smlawt %[mi], %[aval], %[bval], %[mi]\n\t" \ 82 | : [mr1]"=r"(mr1__), [mr2]"=r"(mr2__), [mi]"=r"(mi__), \ 83 | [aval]"=&r"(aval__), [bval]"=r"(bval__) \ 84 | : [ap]LDRD_CONS(a), [bp]"m"(b) \ 85 | ); \ 86 | (m).r = SHR32(SUB32(mr1__, mr2__), 1); \ 87 | (m).i = SHR32(mi__, 1); \ 88 | } \ 89 | while(0) 90 | 91 | #undef C_MULC 92 | #define C_MULC(m,a,b) \ 93 | do{ \ 94 | int mr__; \ 95 | int mi1__; \ 96 | int mi2__; \ 97 | long long aval__; \ 98 | int bval__; \ 99 | __asm__( \ 100 | "#C_MULC\n\t" \ 101 | "ldrd %[aval], %H[aval], %[ap]\n\t" \ 102 | "ldr %[bval], %[bp]\n\t" \ 103 | "smulwb %[mr], %[aval], %[bval]\n\t" \ 104 | "smulwb %[mi1], %H[aval], %[bval]\n\t" \ 105 | "smulwt %[mi2], %[aval], %[bval]\n\t" \ 106 | "smlawt %[mr], %H[aval], %[bval], %[mr]\n\t" \ 107 | : [mr]"=r"(mr__), [mi1]"=r"(mi1__), [mi2]"=r"(mi2__), \ 108 | [aval]"=&r"(aval__), [bval]"=r"(bval__) \ 109 | : [ap]LDRD_CONS(a), [bp]"m"(b) \ 110 | ); \ 111 | (m).r = SHL32(mr__, 1); \ 112 | (m).i = SHL32(SUB32(mi1__, mi2__), 1); \ 113 | } \ 114 | while(0) 115 | 116 | #endif /* FIXED_POINT */ 117 | 118 | #endif /* KISS_FFT_GUTS_H */ 119 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/arm/mdct_arm.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015 Xiph.Org Foundation 2 | Written by Viswanath Puttagunta */ 3 | /** 4 | @file arm_mdct.h 5 | @brief ARM Neon Intrinsic optimizations for mdct using NE10 library 6 | */ 7 | 8 | /* 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | - Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | - Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #if !defined(MDCT_ARM_H) 34 | #define MDCT_ARM_H 35 | 36 | #include "mdct.h" 37 | 38 | #if defined(HAVE_ARM_NE10) 39 | /** Compute a forward MDCT and scale by 4/N, trashes the input array */ 40 | void clt_mdct_forward_neon(const mdct_lookup *l, kiss_fft_scalar *in, 41 | kiss_fft_scalar * OPUS_RESTRICT out, 42 | const opus_val16 *window, int overlap, 43 | int shift, int stride, int arch); 44 | 45 | void clt_mdct_backward_neon(const mdct_lookup *l, kiss_fft_scalar *in, 46 | kiss_fft_scalar * OPUS_RESTRICT out, 47 | const opus_val16 *window, int overlap, 48 | int shift, int stride, int arch); 49 | 50 | #if !defined(OPUS_HAVE_RTCD) 51 | #define OVERRIDE_OPUS_MDCT (1) 52 | #define clt_mdct_forward(_l, _in, _out, _window, _int, _shift, _stride, _arch) \ 53 | clt_mdct_forward_neon(_l, _in, _out, _window, _int, _shift, _stride, _arch) 54 | #define clt_mdct_backward(_l, _in, _out, _window, _int, _shift, _stride, _arch) \ 55 | clt_mdct_backward_neon(_l, _in, _out, _window, _int, _shift, _stride, _arch) 56 | #endif /* OPUS_HAVE_RTCD */ 57 | #endif /* HAVE_ARM_NE10 */ 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/config.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef CONFIG_H 29 | #define CONFIG_H 30 | 31 | #include 32 | 33 | #define USE_ALLOCA 1 34 | 35 | /* Comment out the next line for floating-point code */ 36 | /*#define FIXED_POINT 1 */ 37 | 38 | #define OPUS_BUILD 1 39 | 40 | #if (defined(_M_IX86) || defined(_M_X64)) && !COMPILER_TCC 41 | 42 | /* Can always compile SSE intrinsics (no special compiler flags necessary) */ 43 | /* (at least on windows)... */ 44 | #if defined(_MSC_VER) 45 | #define OPUS_X86_MAY_HAVE_SSE 46 | #define OPUS_X86_MAY_HAVE_SSE2 47 | #define OPUS_X86_MAY_HAVE_SSE4_1 48 | #endif 49 | 50 | /* Presume SSE functions, if compiled to use SSE/SSE2/AVX (note that AMD64 implies SSE2, and AVX 51 | implies SSE4.1) */ 52 | #if defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP >= 1)) || defined(__AVX__) 53 | #define OPUS_X86_PRESUME_SSE 1 54 | #endif 55 | #if defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || defined(__AVX__) 56 | #define OPUS_X86_PRESUME_SSE2 1 57 | #endif 58 | #if defined(__AVX__) 59 | #define OPUS_X86_PRESUME_SSE4_1 1 60 | #endif 61 | 62 | #if !defined(OPUS_X86_PRESUME_SSE4_1) || !defined(OPUS_X86_PRESUME_SSE2) || !defined(OPUS_X86_PRESUME_SSE) 63 | #define OPUS_HAVE_RTCD 1 64 | #endif 65 | 66 | #endif 67 | 68 | //#include "version.h" 69 | 70 | #endif /* CONFIG_H */ 71 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/cpu_support.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 Xiph.Org Foundation 2 | * Copyright (c) 2013 Parrot */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef CPU_SUPPORT_H 29 | #define CPU_SUPPORT_H 30 | 31 | #include "opus_types.h" 32 | #include "opus_defines.h" 33 | 34 | #if defined(OPUS_HAVE_RTCD) && \ 35 | (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) 36 | #include "arm/armcpu.h" 37 | 38 | /* We currently support 4 ARM variants: 39 | * arch[0] -> ARMv4 40 | * arch[1] -> ARMv5E 41 | * arch[2] -> ARMv6 42 | * arch[3] -> NEON 43 | */ 44 | #define OPUS_ARCHMASK 3 45 | 46 | #elif (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(OPUS_X86_PRESUME_SSE)) || \ 47 | (defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(OPUS_X86_PRESUME_SSE2)) || \ 48 | (defined(OPUS_X86_MAY_HAVE_SSE4_1) && !defined(OPUS_X86_PRESUME_SSE4_1)) || \ 49 | (defined(OPUS_X86_MAY_HAVE_AVX) && !defined(OPUS_X86_PRESUME_AVX)) 50 | 51 | #include "x86/x86cpu.h" 52 | /* We currently support 5 x86 variants: 53 | * arch[0] -> non-sse 54 | * arch[1] -> sse 55 | * arch[2] -> sse2 56 | * arch[3] -> sse4.1 57 | * arch[4] -> avx 58 | */ 59 | #define OPUS_ARCHMASK 7 60 | int opus_select_arch(void); 61 | 62 | #else 63 | #define OPUS_ARCHMASK 0 64 | 65 | static OPUS_INLINE int opus_select_arch(void) 66 | { 67 | return 0; 68 | } 69 | #endif 70 | #endif 71 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/cwrs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Copyright (c) 2007-2009 Timothy B. Terriberry 4 | Written by Timothy B. Terriberry and Jean-Marc Valin */ 5 | /* 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | - Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | - Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 21 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef CWRS_H 31 | #define CWRS_H 32 | 33 | #include "arch.h" 34 | #include "stack_alloc.h" 35 | //#include "entenc.h" 36 | #include "entdec.h" 37 | 38 | #ifdef CUSTOM_MODES 39 | int log2_frac(opus_uint32 val, int frac); 40 | #endif 41 | 42 | void get_required_bits(opus_int16 *bits, int N, int K, int frac); 43 | 44 | void encode_pulses(const int *_y, int N, int K, ec_enc *enc); 45 | 46 | opus_val32 decode_pulses(int *_y, int N, int K, ec_dec *dec); 47 | 48 | #endif /* CWRS_H */ 49 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/ecintrin.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003-2008 Timothy B. Terriberry 2 | Copyright (c) 2008 Xiph.Org Foundation */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /*Some common macros for potential platform-specific optimization.*/ 29 | #include "opus_types.h" 30 | #include 31 | #include 32 | #include "arch.h" 33 | #if !defined(_ecintrin_H) 34 | # define _ecintrin_H (1) 35 | 36 | /*Some specific platforms may have optimized intrinsic or OPUS_INLINE assembly 37 | versions of these functions which can substantially improve performance. 38 | We define macros for them to allow easy incorporation of these non-ANSI 39 | features.*/ 40 | 41 | /*Modern gcc (4.x) can compile the naive versions of min and max with cmov if 42 | given an appropriate architecture, but the branchless bit-twiddling versions 43 | are just as fast, and do not require any special target architecture. 44 | Earlier gcc versions (3.x) compiled both code to the same assembly 45 | instructions, because of the way they represented ((_b)>(_a)) internally.*/ 46 | # define EC_MINI(_a,_b) ((_a)+(((_b)-(_a))&-((_b)<(_a)))) 47 | 48 | /*Count leading zeros. 49 | This macro should only be used for implementing ec_ilog(), if it is defined. 50 | All other code should use EC_ILOG() instead.*/ 51 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) 52 | # include 53 | /*In _DEBUG mode this is not an intrinsic by default.*/ 54 | # pragma intrinsic(_BitScanReverse) 55 | 56 | static __inline int ec_bsr(unsigned long _x){ 57 | unsigned long ret; 58 | _BitScanReverse(&ret,_x); 59 | return (int)ret; 60 | } 61 | # define EC_CLZ0 (1) 62 | # define EC_CLZ(_x) (-ec_bsr(_x)) 63 | #elif defined(ENABLE_TI_DSPLIB) 64 | # include "dsplib.h" 65 | # define EC_CLZ0 (31) 66 | # define EC_CLZ(_x) (_lnorm(_x)) 67 | #elif __GNUC_PREREQ(3,4) 68 | # if INT_MAX>=2147483647 69 | # define EC_CLZ0 ((int)sizeof(unsigned)*CHAR_BIT) 70 | # define EC_CLZ(_x) (__builtin_clz(_x)) 71 | # elif LONG_MAX>=2147483647L 72 | # define EC_CLZ0 ((int)sizeof(unsigned long)*CHAR_BIT) 73 | # define EC_CLZ(_x) (__builtin_clzl(_x)) 74 | # endif 75 | #endif 76 | 77 | #if defined(EC_CLZ) 78 | /*Note that __builtin_clz is not defined when _x==0, according to the gcc 79 | documentation (and that of the BSR instruction that implements it on x86). 80 | The majority of the time we can never pass it zero. 81 | When we need to, it can be special cased.*/ 82 | # define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x)) 83 | #else 84 | int ec_ilog(opus_uint32 _v); 85 | # define EC_ILOG(_x) (ec_ilog(_x)) 86 | #endif 87 | #endif 88 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/entdec.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2001-2011 Timothy B. Terriberry 2 | Copyright (c) 2008-2009 Xiph.Org Foundation */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if !defined(_entdec_H) 29 | # define _entdec_H (1) 30 | # include 31 | # include "entcode.h" 32 | 33 | /*Initializes the decoder. 34 | _buf: The input buffer to use. 35 | Return: 0 on success, or a negative value on error.*/ 36 | void ec_dec_init(ec_dec *_this,unsigned char *_buf,opus_uint32 _storage); 37 | 38 | /*Calculates the cumulative frequency for the next symbol. 39 | This can then be fed into the probability model to determine what that 40 | symbol is, and the additional frequency information required to advance to 41 | the next symbol. 42 | This function cannot be called more than once without a corresponding call to 43 | ec_dec_update(), or decoding will not proceed correctly. 44 | _ft: The total frequency of the symbols in the alphabet the next symbol was 45 | encoded with. 46 | Return: A cumulative frequency representing the encoded symbol. 47 | If the cumulative frequency of all the symbols before the one that 48 | was encoded was fl, and the cumulative frequency of all the symbols 49 | up to and including the one encoded is fh, then the returned value 50 | will fall in the range [fl,fh).*/ 51 | unsigned ec_decode(ec_dec *_this,unsigned _ft); 52 | 53 | /*Equivalent to ec_decode() with _ft==1<<_bits.*/ 54 | unsigned ec_decode_bin(ec_dec *_this,unsigned _bits); 55 | 56 | /*Advance the decoder past the next symbol using the frequency information the 57 | symbol was encoded with. 58 | Exactly one call to ec_decode() must have been made so that all necessary 59 | intermediate calculations are performed. 60 | _fl: The cumulative frequency of all symbols that come before the symbol 61 | decoded. 62 | _fh: The cumulative frequency of all symbols up to and including the symbol 63 | decoded. 64 | Together with _fl, this defines the range [_fl,_fh) in which the value 65 | returned above must fall. 66 | _ft: The total frequency of the symbols in the alphabet the symbol decoded 67 | was encoded in. 68 | This must be the same as passed to the preceding call to ec_decode().*/ 69 | void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft); 70 | 71 | /* Decode a bit that has a 1/(1<<_logp) probability of being a one */ 72 | int ec_dec_bit_logp(ec_dec *_this,unsigned _logp); 73 | 74 | /*Decodes a symbol given an "inverse" CDF table. 75 | No call to ec_dec_update() is necessary after this call. 76 | _icdf: The "inverse" CDF, such that symbol s falls in the range 77 | [s>0?ft-_icdf[s-1]:0,ft-_icdf[s]), where ft=1<<_ftb. 78 | The values must be monotonically non-increasing, and the last value 79 | must be 0. 80 | _ftb: The number of bits of precision in the cumulative distribution. 81 | Return: The decoded symbol s.*/ 82 | int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb); 83 | 84 | /*Extracts a raw unsigned integer with a non-power-of-2 range from the stream. 85 | The bits must have been encoded with ec_enc_uint(). 86 | No call to ec_dec_update() is necessary after this call. 87 | _ft: The number of integers that can be decoded (one more than the max). 88 | This must be at least 2, and no more than 2**32-1. 89 | Return: The decoded bits.*/ 90 | opus_uint32 ec_dec_uint(ec_dec *_this,opus_uint32 _ft); 91 | 92 | /*Extracts a sequence of raw bits from the stream. 93 | The bits must have been encoded with ec_enc_bits(). 94 | No call to ec_dec_update() is necessary after this call. 95 | _ftb: The number of bits to extract. 96 | This must be between 0 and 25, inclusive. 97 | Return: The decoded bits.*/ 98 | opus_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/laplace.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Written by Jean-Marc Valin */ 4 | /* 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifdef HAVE_CONFIG_H 30 | #include "config.h" 31 | #endif 32 | 33 | #include "laplace.h" 34 | #include "mathops.h" 35 | 36 | /* The minimum probability of an energy delta (out of 32768). */ 37 | #define LAPLACE_LOG_MINP (0) 38 | #define LAPLACE_MINP (1<>15; 49 | } 50 | 51 | #if ENABLE_ENCODER 52 | void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay) 53 | { 54 | unsigned fl; 55 | int val = *value; 56 | fl = 0; 57 | if (val) 58 | { 59 | int s; 60 | int i; 61 | s = -(val<0); 62 | val = (val+s)^s; 63 | fl = fs; 64 | fs = ec_laplace_get_freq1(fs, decay); 65 | /* Search the decaying part of the PDF.*/ 66 | for (i=1; fs > 0 && i < val; i++) 67 | { 68 | fs *= 2; 69 | fl += fs+2*LAPLACE_MINP; 70 | fs = (fs*(opus_int32)decay)>>15; 71 | } 72 | /* Everything beyond that has probability LAPLACE_MINP. */ 73 | if (!fs) 74 | { 75 | int di; 76 | int ndi_max; 77 | ndi_max = (32768-fl+LAPLACE_MINP-1)>>LAPLACE_LOG_MINP; 78 | ndi_max = (ndi_max-s)>>1; 79 | di = IMIN(val - i, ndi_max - 1); 80 | fl += (2*di+1+s)*LAPLACE_MINP; 81 | fs = IMIN(LAPLACE_MINP, 32768-fl); 82 | *value = (i+di+s)^s; 83 | } 84 | else 85 | { 86 | fs += LAPLACE_MINP; 87 | fl += fs&~s; 88 | } 89 | celt_assert(fl+fs<=32768); 90 | celt_assert(fs>0); 91 | } 92 | ec_encode_bin(enc, fl, fl+fs, 15); 93 | } 94 | #endif // #if ENABLE_ENCODER 95 | 96 | int ec_laplace_decode(ec_dec *dec, unsigned fs, int decay) 97 | { 98 | int val=0; 99 | unsigned fl; 100 | unsigned fm; 101 | fm = ec_decode_bin(dec, 15); 102 | fl = 0; 103 | if (fm >= fs) 104 | { 105 | val++; 106 | fl = fs; 107 | fs = ec_laplace_get_freq1(fs, decay)+LAPLACE_MINP; 108 | /* Search the decaying part of the PDF.*/ 109 | while(fs > LAPLACE_MINP && fm >= fl+2*fs) 110 | { 111 | fs *= 2; 112 | fl += fs; 113 | fs = ((fs-2*LAPLACE_MINP)*(opus_int32)decay)>>15; 114 | fs += LAPLACE_MINP; 115 | val++; 116 | } 117 | /* Everything beyond that has probability LAPLACE_MINP. */ 118 | if (fs <= LAPLACE_MINP) 119 | { 120 | int di; 121 | di = (fm-fl)>>(LAPLACE_LOG_MINP+1); 122 | val += di; 123 | fl += 2*di*LAPLACE_MINP; 124 | } 125 | if (fm < fl+fs) 126 | val = -val; 127 | else 128 | fl += fs; 129 | } 130 | celt_assert(fl<32768); 131 | celt_assert(fs>0); 132 | celt_assert(fl<=fm); 133 | celt_assert(fm>EC_SYM_BITS) 46 | /*The number of bits available for the last, partial symbol in the code field.*/ 47 | # define EC_CODE_EXTRA ((EC_CODE_BITS-2)%EC_SYM_BITS+1) 48 | #endif 49 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/mips/fixed_generic_mipsr1.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007-2009 Xiph.Org Foundation 2 | Copyright (C) 2003-2008 Jean-Marc Valin 3 | Copyright (C) 2007-2008 CSIRO */ 4 | /** 5 | @file fixed_generic.h 6 | @brief Generic fixed-point operations 7 | */ 8 | /* 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | - Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | - Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef CELT_FIXED_GENERIC_MIPSR1_H 34 | #define CELT_FIXED_GENERIC_MIPSR1_H 35 | 36 | #undef MULT16_32_Q15_ADD 37 | static inline int MULT16_32_Q15_ADD(int a, int b, int c, int d) { 38 | int m; 39 | asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b)); 40 | asm volatile("madd $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d)); 41 | asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15)); 42 | return m; 43 | } 44 | 45 | #undef MULT16_32_Q15_SUB 46 | static inline int MULT16_32_Q15_SUB(int a, int b, int c, int d) { 47 | int m; 48 | asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b)); 49 | asm volatile("msub $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d)); 50 | asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15)); 51 | return m; 52 | } 53 | 54 | #undef MULT16_16_Q15_ADD 55 | static inline int MULT16_16_Q15_ADD(int a, int b, int c, int d) { 56 | int m; 57 | asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b)); 58 | asm volatile("madd $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d)); 59 | asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15)); 60 | return m; 61 | } 62 | 63 | #undef MULT16_16_Q15_SUB 64 | static inline int MULT16_16_Q15_SUB(int a, int b, int c, int d) { 65 | int m; 66 | asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b)); 67 | asm volatile("msub $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d)); 68 | asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15)); 69 | return m; 70 | } 71 | 72 | 73 | #undef MULT16_32_Q16 74 | static inline int MULT16_32_Q16(int a, int b) 75 | { 76 | int c; 77 | asm volatile("MULT $ac1,%0, %1" : : "r" (a), "r" (b)); 78 | asm volatile("EXTR.W %0,$ac1, %1" : "=r" (c): "i" (16)); 79 | return c; 80 | } 81 | 82 | #undef MULT16_32_P16 83 | static inline int MULT16_32_P16(int a, int b) 84 | { 85 | int c; 86 | asm volatile("MULT $ac1, %0, %1" : : "r" (a), "r" (b)); 87 | asm volatile("EXTR_R.W %0,$ac1, %1" : "=r" (c): "i" (16)); 88 | return c; 89 | } 90 | 91 | #undef MULT16_32_Q15 92 | static inline int MULT16_32_Q15(int a, int b) 93 | { 94 | int c; 95 | asm volatile("MULT $ac1, %0, %1" : : "r" (a), "r" (b)); 96 | asm volatile("EXTR.W %0,$ac1, %1" : "=r" (c): "i" (15)); 97 | return c; 98 | } 99 | 100 | #undef MULT32_32_Q31 101 | static inline int MULT32_32_Q31(int a, int b) 102 | { 103 | int r; 104 | asm volatile("MULT $ac1, %0, %1" : : "r" (a), "r" (b)); 105 | asm volatile("EXTR.W %0,$ac1, %1" : "=r" (r): "i" (31)); 106 | return r; 107 | } 108 | 109 | #undef PSHR32 110 | static inline int PSHR32(int a, int shift) 111 | { 112 | int r; 113 | asm volatile ("SHRAV_R.W %0, %1, %2" :"=r" (r): "r" (a), "r" (shift)); 114 | return r; 115 | } 116 | 117 | #undef MULT16_16_P15 118 | static inline int MULT16_16_P15(int a, int b) 119 | { 120 | int r; 121 | asm volatile ("mul %0, %1, %2" :"=r" (r): "r" (a), "r" (b)); 122 | asm volatile ("SHRA_R.W %0, %1, %2" : "+r" (r): "0" (r), "i"(15)); 123 | return r; 124 | } 125 | 126 | #endif /* CELT_FIXED_GENERIC_MIPSR1_H */ 127 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/mips/vq_mipsr1.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Written by Jean-Marc Valin */ 4 | /* 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef __VQ_MIPSR1_H__ 30 | #define __VQ_MIPSR1_H__ 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include "config.h" 34 | #endif 35 | 36 | #include "mathops.h" 37 | #include "arch.h" 38 | 39 | #define OVERRIDE_vq_exp_rotation1 40 | static void exp_rotation1(celt_norm *X, int len, int stride, opus_val16 c, opus_val16 s) 41 | { 42 | int i; 43 | opus_val16 ms; 44 | celt_norm *Xptr; 45 | Xptr = X; 46 | ms = NEG16(s); 47 | for (i=0;i=0;i--) 57 | { 58 | celt_norm x1, x2; 59 | x1 = Xptr[0]; 60 | x2 = Xptr[stride]; 61 | Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15)); 62 | *Xptr-- = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15)); 63 | } 64 | } 65 | 66 | #define OVERRIDE_renormalise_vector 67 | void renormalise_vector(celt_norm *X, int N, opus_val16 gain, int arch) 68 | { 69 | int i; 70 | #ifdef FIXED_POINT 71 | int k; 72 | #endif 73 | opus_val32 E = EPSILON; 74 | opus_val16 g; 75 | opus_val32 t; 76 | celt_norm *xptr = X; 77 | int X0, X1; 78 | 79 | (void)arch; 80 | 81 | asm volatile("mult $ac1, $0, $0"); 82 | asm volatile("MTLO %0, $ac1" : :"r" (E)); 83 | /*if(N %4) 84 | printf("error");*/ 85 | for (i=0;i>1; 103 | #endif 104 | t = VSHR32(E, 2*(k-7)); 105 | g = MULT16_16_P15(celt_rsqrt_norm(t),gain); 106 | 107 | xptr = X; 108 | for (i=0;i 42 | #include 43 | #include 44 | 45 | /** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */ 46 | #ifndef OVERRIDE_OPUS_ALLOC 47 | static OPUS_INLINE void *opus_alloc (size_t size) 48 | { 49 | return malloc(size); 50 | } 51 | #endif 52 | 53 | /** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */ 54 | #ifndef OVERRIDE_OPUS_ALLOC_SCRATCH 55 | static OPUS_INLINE void *opus_alloc_scratch (size_t size) 56 | { 57 | /* Scratch space doesn't need to be cleared */ 58 | return opus_alloc(size); 59 | } 60 | #endif 61 | 62 | /** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */ 63 | #ifndef OVERRIDE_OPUS_FREE 64 | static OPUS_INLINE void opus_free (void *ptr) 65 | { 66 | free(ptr); 67 | } 68 | #endif 69 | 70 | /** Copy n elements from src to dst. The 0* term provides compile-time type checking */ 71 | #ifndef OVERRIDE_OPUS_COPY 72 | #define OPUS_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) 73 | #endif 74 | 75 | /** Copy n elements from src to dst, allowing overlapping regions. The 0* term 76 | provides compile-time type checking */ 77 | #ifndef OVERRIDE_OPUS_MOVE 78 | #define OPUS_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) 79 | #endif 80 | 81 | /** Set n elements of dst to zero */ 82 | #ifndef OVERRIDE_OPUS_CLEAR 83 | #define OPUS_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst)))) 84 | #endif 85 | 86 | /*#ifdef __GNUC__ 87 | #pragma GCC poison printf sprintf 88 | #pragma GCC poison malloc free realloc calloc 89 | #endif*/ 90 | 91 | #endif /* OS_SUPPORT_H */ 92 | 93 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/quant_bands.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Written by Jean-Marc Valin */ 4 | /* 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef QUANT_BANDS 30 | #define QUANT_BANDS 31 | 32 | #include "arch.h" 33 | #include "modes.h" 34 | //#include "entenc.h" 35 | #include "entdec.h" 36 | #include "mathops.h" 37 | 38 | #ifdef FIXED_POINT 39 | extern const signed char eMeans[25]; 40 | #else 41 | extern const opus_val16 eMeans[25]; 42 | #endif 43 | 44 | void amp2Log2(const CELTMode *m, int effEnd, int end, 45 | celt_ener *bandE, opus_val16 *bandLogE, int C); 46 | 47 | void log2Amp(const CELTMode *m, int start, int end, 48 | celt_ener *eBands, const opus_val16 *oldEBands, int C); 49 | 50 | void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, 51 | const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget, 52 | opus_val16 *error, ec_enc *enc, int C, int LM, 53 | int nbAvailableBytes, int force_intra, opus_val32 *delayedIntra, 54 | int two_pass, int loss_rate, int lfe); 55 | 56 | void quant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, ec_enc *enc, int C); 57 | 58 | void quant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc, int C); 59 | 60 | void unquant_coarse_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int intra, ec_dec *dec, int C, int LM); 61 | 62 | void unquant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, ec_dec *dec, int C); 63 | 64 | void unquant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, int *fine_priority, int bits_left, ec_dec *dec, int C); 65 | 66 | #endif /* QUANT_BANDS */ 67 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/rate.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Written by Jean-Marc Valin */ 4 | /* 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef RATE_H 30 | #define RATE_H 31 | 32 | #define MAX_PSEUDO 40 33 | #define LOG_MAX_PSEUDO 6 34 | 35 | #define CELT_MAX_PULSES 128 36 | 37 | #define MAX_FINE_BITS 8 38 | 39 | #define FINE_OFFSET 21 40 | #define QTHETA_OFFSET 4 41 | #define QTHETA_OFFSET_TWOPHASE 16 42 | 43 | #include "cwrs.h" 44 | #include "modes.h" 45 | 46 | void compute_pulse_cache(CELTMode *m, int LM); 47 | 48 | static OPUS_INLINE int get_pulses(int i) 49 | { 50 | return i<8 ? i : (8 + (i&7)) << ((i>>3)-1); 51 | } 52 | 53 | static OPUS_INLINE int bits2pulses(const CELTMode *m, int band, int LM, int bits) 54 | { 55 | int i; 56 | int lo, hi; 57 | const unsigned char *cache; 58 | 59 | LM++; 60 | cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; 61 | 62 | lo = 0; 63 | hi = cache[0]; 64 | bits--; 65 | for (i=0;i>1; 68 | /* OPT: Make sure this is implemented with a conditional move */ 69 | if ((int)cache[mid] >= bits) 70 | hi = mid; 71 | else 72 | lo = mid; 73 | } 74 | if (bits- (lo == 0 ? -1 : (int)cache[lo]) <= (int)cache[hi]-bits) 75 | return lo; 76 | else 77 | return hi; 78 | } 79 | 80 | static OPUS_INLINE int pulses2bits(const CELTMode *m, int band, int LM, int pulses) 81 | { 82 | const unsigned char *cache; 83 | 84 | LM++; 85 | cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; 86 | return pulses == 0 ? 0 : cache[pulses]+1; 87 | } 88 | 89 | /** Compute the pulse allocation, i.e. how many pulses will go in each 90 | * band. 91 | @param m mode 92 | @param offsets Requested increase or decrease in the number of bits for 93 | each band 94 | @param total Number of bands 95 | @param pulses Number of pulses per band (returned) 96 | @return Total number of bits allocated 97 | */ 98 | int clt_compute_allocation(const CELTMode *m, int start, int end, const int *offsets, const int *cap, int alloc_trim, int *intensity, int *dual_stereo, 99 | opus_int32 total, opus_int32 *balance, int *pulses, int *ebits, int *fine_priority, int C, int LM, ec_ctx *ec, int encode, int prev, int signalBandwidth); 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/vq.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Written by Jean-Marc Valin */ 4 | /** 5 | @file vq.h 6 | @brief Vector quantisation of the residual 7 | */ 8 | /* 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | - Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | - Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef VQ_H 34 | #define VQ_H 35 | 36 | //#include "entenc.h" 37 | #include "entdec.h" 38 | #include "modes.h" 39 | 40 | #if (defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(FIXED_POINT)) 41 | #include "x86/vq_sse.h" 42 | #endif 43 | 44 | void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread); 45 | 46 | opus_val16 op_pvq_search_c(celt_norm *X, int *iy, int K, int N, int arch); 47 | 48 | #if !defined(OVERRIDE_OP_PVQ_SEARCH) 49 | #define op_pvq_search(x, iy, K, N, arch) \ 50 | (op_pvq_search_c(x, iy, K, N, arch)) 51 | #endif 52 | 53 | /** Algebraic pulse-vector quantiser. The signal x is replaced by the sum of 54 | * the pitch and a combination of pulses such that its norm is still equal 55 | * to 1. This is the function that will typically require the most CPU. 56 | * @param X Residual signal to quantise/encode (returns quantised version) 57 | * @param N Number of samples to encode 58 | * @param K Number of pulses to use 59 | * @param enc Entropy encoder state 60 | * @ret A mask indicating which blocks in the band received pulses 61 | */ 62 | unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc, 63 | opus_val16 gain, int resynth, int arch); 64 | 65 | /** Algebraic pulse decoder 66 | * @param X Decoded normalised spectrum (returned) 67 | * @param N Number of samples to decode 68 | * @param K Number of pulses to use 69 | * @param dec Entropy decoder state 70 | * @ret A mask indicating which blocks in the band received pulses 71 | */ 72 | unsigned alg_unquant(celt_norm *X, int N, int K, int spread, int B, 73 | ec_dec *dec, opus_val16 gain); 74 | 75 | void renormalise_vector(celt_norm *X, int N, opus_val16 gain, int arch); 76 | 77 | int stereo_itheta(const celt_norm *X, const celt_norm *Y, int stereo, int N, int arch); 78 | 79 | #endif /* VQ_H */ 80 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/x86/pitch_sse2.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Cisco Systems, INC 2 | Written by XiangMingZhu WeiZhou MinPeng YanWang 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "../config.h" 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | //#include "macros.h" 36 | #include "celt_lpc.h" 37 | #include "stack_alloc.h" 38 | #include "mathops.h" 39 | #include "pitch.h" 40 | 41 | #if defined(OPUS_X86_MAY_HAVE_SSE2) && defined(FIXED_POINT) 42 | opus_val32 celt_inner_prod_sse2(const opus_val16 *x, const opus_val16 *y, 43 | int N) 44 | { 45 | opus_int i, dataSize16; 46 | opus_int32 sum; 47 | 48 | __m128i inVec1_76543210, inVec1_FEDCBA98, acc1; 49 | __m128i inVec2_76543210, inVec2_FEDCBA98, acc2; 50 | 51 | sum = 0; 52 | dataSize16 = N & ~15; 53 | 54 | acc1 = _mm_setzero_si128(); 55 | acc2 = _mm_setzero_si128(); 56 | 57 | for (i=0;i= 8) 75 | { 76 | inVec1_76543210 = _mm_loadu_si128((__m128i *)(&x[i + 0])); 77 | inVec2_76543210 = _mm_loadu_si128((__m128i *)(&y[i + 0])); 78 | 79 | inVec1_76543210 = _mm_madd_epi16(inVec1_76543210, inVec2_76543210); 80 | 81 | acc1 = _mm_add_epi32(acc1, inVec1_76543210); 82 | i += 8; 83 | } 84 | 85 | acc1 = _mm_add_epi32(acc1, _mm_unpackhi_epi64( acc1, acc1)); 86 | acc1 = _mm_add_epi32(acc1, _mm_shufflelo_epi16( acc1, 0x0E)); 87 | sum += _mm_cvtsi128_si32(acc1); 88 | 89 | for (;i 47 | static _inline void cpuid(unsigned int CPUInfo[4], unsigned int InfoType) 48 | { 49 | __cpuid((int*)CPUInfo, InfoType); 50 | } 51 | 52 | #else 53 | 54 | #if defined(CPU_INFO_BY_C) 55 | #include 56 | #endif 57 | 58 | static void cpuid(unsigned int CPUInfo[4], unsigned int InfoType) 59 | { 60 | #if defined(CPU_INFO_BY_ASM) 61 | #if defined(__i386__) && defined(__PIC__) 62 | /* %ebx is PIC register in 32-bit, so mustn't clobber it. */ 63 | __asm__ __volatile__ ( 64 | "xchg %%ebx, %1\n" 65 | "cpuid\n" 66 | "xchg %%ebx, %1\n": 67 | "=a" (CPUInfo[0]), 68 | "=r" (CPUInfo[1]), 69 | "=c" (CPUInfo[2]), 70 | "=d" (CPUInfo[3]) : 71 | "0" (InfoType) 72 | ); 73 | #else 74 | __asm__ __volatile__ ( 75 | "cpuid": 76 | "=a" (CPUInfo[0]), 77 | "=b" (CPUInfo[1]), 78 | "=c" (CPUInfo[2]), 79 | "=d" (CPUInfo[3]) : 80 | "0" (InfoType) 81 | ); 82 | #endif 83 | #elif defined(CPU_INFO_BY_C) 84 | __get_cpuid(InfoType, &(CPUInfo[0]), &(CPUInfo[1]), &(CPUInfo[2]), &(CPUInfo[3])); 85 | #endif 86 | } 87 | 88 | #endif 89 | 90 | typedef struct CPU_Feature{ 91 | /* SIMD: 128-bit */ 92 | int HW_SSE; 93 | int HW_SSE2; 94 | int HW_SSE41; 95 | /* SIMD: 256-bit */ 96 | int HW_AVX; 97 | } CPU_Feature; 98 | 99 | static void opus_cpu_feature_check(CPU_Feature *cpu_feature) 100 | { 101 | unsigned int info[4] = {0}; 102 | unsigned int nIds = 0; 103 | 104 | cpuid(info, 0); 105 | nIds = info[0]; 106 | 107 | if (nIds >= 1){ 108 | cpuid(info, 1); 109 | cpu_feature->HW_SSE = (info[3] & (1 << 25)) != 0; 110 | cpu_feature->HW_SSE2 = (info[3] & (1 << 26)) != 0; 111 | cpu_feature->HW_SSE41 = (info[2] & (1 << 19)) != 0; 112 | cpu_feature->HW_AVX = (info[2] & (1 << 28)) != 0; 113 | } 114 | else { 115 | cpu_feature->HW_SSE = 0; 116 | cpu_feature->HW_SSE2 = 0; 117 | cpu_feature->HW_SSE41 = 0; 118 | cpu_feature->HW_AVX = 0; 119 | } 120 | } 121 | 122 | int opus_select_arch(void) 123 | { 124 | CPU_Feature cpu_feature; 125 | int arch; 126 | 127 | opus_cpu_feature_check(&cpu_feature); 128 | 129 | arch = 0; 130 | if (!cpu_feature.HW_SSE) 131 | { 132 | return arch; 133 | } 134 | arch++; 135 | 136 | if (!cpu_feature.HW_SSE2) 137 | { 138 | return arch; 139 | } 140 | arch++; 141 | 142 | if (!cpu_feature.HW_SSE41) 143 | { 144 | return arch; 145 | } 146 | arch++; 147 | 148 | if (!cpu_feature.HW_AVX) 149 | { 150 | return arch; 151 | } 152 | arch++; 153 | 154 | return arch; 155 | } 156 | 157 | #endif 158 | -------------------------------------------------------------------------------- /third_party/opus-1.3.1-stripped/x86/x86cpu.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Cisco Systems, INC 2 | Written by XiangMingZhu WeiZhou MinPeng YanWang 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if !defined(X86CPU_H) 29 | # define X86CPU_H 30 | 31 | # if defined(OPUS_X86_MAY_HAVE_SSE) 32 | # define MAY_HAVE_SSE(name) name ## _sse 33 | # else 34 | # define MAY_HAVE_SSE(name) name ## _c 35 | # endif 36 | 37 | # if defined(OPUS_X86_MAY_HAVE_SSE2) 38 | # define MAY_HAVE_SSE2(name) name ## _sse2 39 | # else 40 | # define MAY_HAVE_SSE2(name) name ## _c 41 | # endif 42 | 43 | # if defined(OPUS_X86_MAY_HAVE_SSE4_1) 44 | # define MAY_HAVE_SSE4_1(name) name ## _sse4_1 45 | # else 46 | # define MAY_HAVE_SSE4_1(name) name ## _c 47 | # endif 48 | 49 | # if defined(OPUS_X86_MAY_HAVE_AVX) 50 | # define MAY_HAVE_AVX(name) name ## _avx 51 | # else 52 | # define MAY_HAVE_AVX(name) name ## _c 53 | # endif 54 | 55 | # if defined(OPUS_HAVE_RTCD) 56 | int opus_select_arch(void); 57 | # endif 58 | 59 | /*gcc appears to emit MOVDQA's to load the argument of an _mm_cvtepi8_epi32() 60 | or _mm_cvtepi16_epi32() when optimizations are disabled, even though the 61 | actual PMOVSXWD instruction takes an m32 or m64. Unlike a normal memory 62 | reference, these require 16-byte alignment and load a full 16 bytes (instead 63 | of 4 or 8), possibly reading out of bounds. 64 | 65 | We can insert an explicit MOVD or MOVQ using _mm_cvtsi32_si128() or 66 | _mm_loadl_epi64(), which should have the same semantics as an m32 or m64 67 | reference in the PMOVSXWD instruction itself, but gcc is not smart enough to 68 | optimize this out when optimizations ARE enabled. 69 | 70 | Clang, in contrast, requires us to do this always for _mm_cvtepi8_epi32 71 | (which is fair, since technically the compiler is always allowed to do the 72 | dereference before invoking the function implementing the intrinsic). 73 | However, it is smart enough to eliminate the extra MOVD instruction. 74 | For _mm_cvtepi16_epi32, it does the right thing, though does *not* optimize out 75 | the extra MOVQ if it's specified explicitly */ 76 | 77 | # if defined(__clang__) || !defined(__OPTIMIZE__) 78 | # define OP_CVTEPI8_EPI32_M32(x) \ 79 | (_mm_cvtepi8_epi32(_mm_cvtsi32_si128(*(int *)(x)))) 80 | # else 81 | # define OP_CVTEPI8_EPI32_M32(x) \ 82 | (_mm_cvtepi8_epi32(*(__m128i *)(x))) 83 | #endif 84 | 85 | /* similar reasoning about the instruction sequence as in the 32-bit macro above, 86 | */ 87 | # if defined(__clang__) || !defined(__OPTIMIZE__) 88 | # define OP_CVTEPI16_EPI32_M64(x) \ 89 | (_mm_cvtepi16_epi32(_mm_loadl_epi64((__m128i *)(x)))) 90 | # else 91 | # define OP_CVTEPI16_EPI32_M64(x) \ 92 | (_mm_cvtepi16_epi32(*(__m128i *)(x))) 93 | # endif 94 | 95 | #endif 96 | --------------------------------------------------------------------------------