libgambatte/libretro/msvc/msvc-2003-xbox1/msvc-2003-xbox1.vcproj000664 001750 001750 00000101713 12720365247 025171 0ustar00sergiosergio000000 000000 libgambatte/libretro/jni/Android.mk000664 001750 001750 00000001221 12720365247 020474 0ustar00sergiosergio000000 000000 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libretro ifeq ($(TARGET_ARCH),arm) LOCAL_CXXFLAGS += -DANDROID_ARM LOCAL_ARM_MODE := arm endif ifeq ($(TARGET_ARCH),x86) LOCAL_CXXFLAGS += -DANDROID_X86 endif ifeq ($(TARGET_ARCH),mips) LOCAL_CXXFLAGS += -DANDROID_MIPS endif CORE_DIR := ../../src include ../../Makefile.common LOCAL_SRC_FILES := $(SOURCES_CXX) $(SOURCES_C) LOCAL_CXXFLAGS += -DINLINE=inline -DHAVE_STDINT_H -DHAVE_INTTYPES_H -D__LIBRETRO__ LOCAL_C_INCLUDES = $(CORE_DIR) $(CORE_DIR)/../include $(CORE_DIR)/../../common $(CORE_DIR)/../../common/resample $(CORE_DIR)/../libretro include $(BUILD_SHARED_LIBRARY) libgambatte/libretro/blipper.h000664 001750 001750 00000013265 12720365247 017624 0ustar00sergiosergio000000 000000 /* * Copyright (C) 2013 - Hans-Kristian Arntzen * * Permission is hereby granted, free of charge, * to any person obtaining a copy of this software and * associated documentation files (the "Software"), * to deal in the Software without restriction, * including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #ifndef BLIPPER_H__ #define BLIPPER_H__ /* Compile time configurables. */ #ifndef BLIPPER_LOG_PERFORMANCE #define BLIPPER_LOG_PERFORMANCE 0 #endif #ifndef BLIPPER_FIXED_POINT #define BLIPPER_FIXED_POINT 1 #endif /* Set to float or double. * long double is unlikely to provide any improved precision. */ #ifndef BLIPPER_REAL_T #define BLIPPER_REAL_T float #endif /* Allows including several implementations in one lib. */ #if BLIPPER_FIXED_POINT #define BLIPPER_MANGLE(x) x##_fixed #else #define BLIPPER_MANGLE(x) x##_##BLIPPER_REAL_T #endif #ifdef __cplusplus extern "C" { #endif #include typedef struct blipper blipper_t; typedef BLIPPER_REAL_T blipper_real_t; #if BLIPPER_FIXED_POINT #ifdef HAVE_STDINT_H #include typedef int16_t blipper_sample_t; typedef int32_t blipper_long_sample_t; #else #if SHRT_MAX == 0x7fff typedef short blipper_sample_t; #elif INT_MAX == 0x7fff typedef int blipper_sample_t; #else #error "Cannot find suitable type for blipper_sampler_t." #endif #if INT_MAX == 0x7fffffffl typedef int blipper_long_sample_t; #elif LONG_MAX == 0x7fffffffl typedef long blipper_long_sample_t; #else #error "Cannot find suitable type for blipper_long_sample_t." #endif #endif #else typedef BLIPPER_REAL_T blipper_sample_t; typedef BLIPPER_REAL_T blipper_long_sample_t; /* Meaningless for float version. */ #endif /* Create a new blipper. * taps: Number of filter taps per impulse. * * cutoff: Cutoff frequency in the passband. Has a range of [0, 1]. * * beta: Beta used for Kaiser window. * * decimation: Sets decimation rate. Must be power-of-two (2^n). * The input sampling rate is then output_rate * 2^decimation. * buffer_samples: The maximum number of processed output samples that can be * buffered up by blipper. * * filter_bank: An optional filter which has already been created by * blipper_create_filter_bank(). blipper_new() does not take ownership * of the buffer and must be freed by caller. * If non-NULL, cutoff and beta will be ignored. * * Some sane values: * taps = 64, cutoff = 0.85, beta = 8.0 */ #define blipper_new BLIPPER_MANGLE(blipper_new) blipper_t *blipper_new(unsigned taps, double cutoff, double beta, unsigned decimation, unsigned buffer_samples, const blipper_sample_t *filter_bank); /* Reset the blipper to its initiate state. */ #define blipper_reset BLIPPER_MANGLE(blipper_reset) void blipper_reset(blipper_t *blip); /* Create a filter which can be passed to blipper_new() in filter_bank. * Arguments to decimation and taps must match. */ #define blipper_create_filter_bank BLIPPER_MANGLE(blipper_create_filter_bank) blipper_sample_t *blipper_create_filter_bank(unsigned decimation, unsigned taps, double cutoff, double beta); /* Frees the blipper. blip can be NULL (no-op). */ #define blipper_free BLIPPER_MANGLE(blipper_free) void blipper_free(blipper_t *blip); /* Data pushing interfaces. One of these should be used exclusively. */ /* Push a single delta, which occurs clock_step input samples after the * last time a delta was pushed. The delta value is the difference signal * between the new sample and the previous. * It is unnecessary to pass a delta of 0. * If the deltas are known beforehand (e.g. when synthesizing a waveform), * this is a more efficient interface than blipper_push_samples(). * * The caller must ensure not to push deltas in a way that can destabilize * the final integration. */ #define blipper_push_delta BLIPPER_MANGLE(blipper_push_delta) void blipper_push_delta(blipper_t *blip, blipper_long_sample_t delta, unsigned clocks_step); /* Push raw samples. blipper will find the deltas themself and push them. * stride is the number of samples between each sample to be used. * This can be used to push interleaved stereo data to two independent * blippers. */ #define blipper_push_samples BLIPPER_MANGLE(blipper_push_samples) void blipper_push_samples(blipper_t *blip, const blipper_sample_t *delta, unsigned samples, unsigned stride); /* Returns the number of samples available for reading using * blipper_read(). */ #define blipper_read_avail BLIPPER_MANGLE(blipper_read_avail) unsigned blipper_read_avail(blipper_t *blip); /* Reads processed samples. The caller must ensure to not read * more than what is returned from blipper_read_avail(). * As in blipper_push_samples(), stride is the number of samples * between each output sample in output. * Can be used to write to an interleaved stereo buffer. */ #define blipper_read BLIPPER_MANGLE(blipper_read) void blipper_read(blipper_t *blip, blipper_sample_t *output, unsigned samples, unsigned stride); #ifdef __cplusplus } #endif #endif libgambatte/libretro/link.T000664 001750 001750 00000000047 12720365247 017072 0ustar00sergiosergio000000 000000 { global: retro_*; local: *; }; libgambatte/libretro/msvc/msvc-2003-xbox1/stdint.h000664 001750 001750 00000017100 12720365247 023025 0ustar00sergiosergio000000 000000 // ISO C9x compliant stdint.h for Microsoft Visual Studio // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 // // Copyright (c) 2006-2008 Alexander Chemeris // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // 3. The name of the author may be used to endorse or promote products // derived from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////////// #ifndef __RARCH_STDINT_H #define __RARCH_STDINT_H #if _MSC_VER && (_MSC_VER < 1600) //pre-MSVC 2010 needs an implementation of stdint.h #if _MSC_VER > 1000 #pragma once #endif #include // For Visual Studio 6 in C++ mode and for many Visual Studio versions when // compiling for ARM we should wrap include with 'extern "C++" {}' // or compiler give many errors like this: // error C2733: second C linkage of overloaded function 'wmemchr' not allowed #ifdef __cplusplus extern "C" { #endif # include #ifdef __cplusplus } #endif // Define _W64 macros to mark types changing their size, like intptr_t. #ifndef _W64 # if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 # define _W64 __w64 # else # define _W64 # endif #endif // 7.18.1 Integer types // 7.18.1.1 Exact-width integer types // Visual Studio 6 and Embedded Visual C++ 4 doesn't // realize that, e.g. char has the same size as __int8 // so we give up on __intX for them. #if (_MSC_VER < 1300) typedef signed char int8_t; typedef signed short int16_t; typedef signed int int32_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; #else typedef signed __int8 int8_t; typedef signed __int16 int16_t; typedef signed __int32 int32_t; typedef unsigned __int8 uint8_t; typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; #endif typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; // 7.18.1.2 Minimum-width integer types typedef int8_t int_least8_t; typedef int16_t int_least16_t; typedef int32_t int_least32_t; typedef int64_t int_least64_t; typedef uint8_t uint_least8_t; typedef uint16_t uint_least16_t; typedef uint32_t uint_least32_t; typedef uint64_t uint_least64_t; // 7.18.1.3 Fastest minimum-width integer types typedef int8_t int_fast8_t; typedef int16_t int_fast16_t; typedef int32_t int_fast32_t; typedef int64_t int_fast64_t; typedef uint8_t uint_fast8_t; typedef uint16_t uint_fast16_t; typedef uint32_t uint_fast32_t; typedef uint64_t uint_fast64_t; // 7.18.1.4 Integer types capable of holding object pointers #ifdef _WIN64 // [ typedef signed __int64 intptr_t; typedef unsigned __int64 uintptr_t; #else // _WIN64 ][ typedef _W64 signed int intptr_t; typedef _W64 unsigned int uintptr_t; #endif // _WIN64 ] // 7.18.1.5 Greatest-width integer types typedef int64_t intmax_t; typedef uint64_t uintmax_t; // 7.18.2 Limits of specified-width integer types #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 // 7.18.2.1 Limits of exact-width integer types #define INT8_MIN ((int8_t)_I8_MIN) #define INT8_MAX _I8_MAX #define INT16_MIN ((int16_t)_I16_MIN) #define INT16_MAX _I16_MAX #define INT32_MIN ((int32_t)_I32_MIN) #define INT32_MAX _I32_MAX #define INT64_MIN ((int64_t)_I64_MIN) #define INT64_MAX _I64_MAX #define UINT8_MAX _UI8_MAX #define UINT16_MAX _UI16_MAX #define UINT32_MAX _UI32_MAX #define UINT64_MAX _UI64_MAX // 7.18.2.2 Limits of minimum-width integer types #define INT_LEAST8_MIN INT8_MIN #define INT_LEAST8_MAX INT8_MAX #define INT_LEAST16_MIN INT16_MIN #define INT_LEAST16_MAX INT16_MAX #define INT_LEAST32_MIN INT32_MIN #define INT_LEAST32_MAX INT32_MAX #define INT_LEAST64_MIN INT64_MIN #define INT_LEAST64_MAX INT64_MAX #define UINT_LEAST8_MAX UINT8_MAX #define UINT_LEAST16_MAX UINT16_MAX #define UINT_LEAST32_MAX UINT32_MAX #define UINT_LEAST64_MAX UINT64_MAX // 7.18.2.3 Limits of fastest minimum-width integer types #define INT_FAST8_MIN INT8_MIN #define INT_FAST8_MAX INT8_MAX #define INT_FAST16_MIN INT16_MIN #define INT_FAST16_MAX INT16_MAX #define INT_FAST32_MIN INT32_MIN #define INT_FAST32_MAX INT32_MAX #define INT_FAST64_MIN INT64_MIN #define INT_FAST64_MAX INT64_MAX #define UINT_FAST8_MAX UINT8_MAX #define UINT_FAST16_MAX UINT16_MAX #define UINT_FAST32_MAX UINT32_MAX #define UINT_FAST64_MAX UINT64_MAX // 7.18.2.4 Limits of integer types capable of holding object pointers #ifdef _WIN64 // [ # define INTPTR_MIN INT64_MIN # define INTPTR_MAX INT64_MAX # define UINTPTR_MAX UINT64_MAX #else // _WIN64 ][ # define INTPTR_MIN INT32_MIN # define INTPTR_MAX INT32_MAX # define UINTPTR_MAX UINT32_MAX #endif // _WIN64 ] // 7.18.2.5 Limits of greatest-width integer types #define INTMAX_MIN INT64_MIN #define INTMAX_MAX INT64_MAX #define UINTMAX_MAX UINT64_MAX // 7.18.3 Limits of other integer types #ifdef _WIN64 // [ # define PTRDIFF_MIN _I64_MIN # define PTRDIFF_MAX _I64_MAX #else // _WIN64 ][ # define PTRDIFF_MIN _I32_MIN # define PTRDIFF_MAX _I32_MAX #endif // _WIN64 ] #define SIG_ATOMIC_MIN INT_MIN #define SIG_ATOMIC_MAX INT_MAX #ifndef SIZE_MAX // [ # ifdef _WIN64 // [ # define SIZE_MAX _UI64_MAX # else // _WIN64 ][ # define SIZE_MAX _UI32_MAX # endif // _WIN64 ] #endif // SIZE_MAX ] // WCHAR_MIN and WCHAR_MAX are also defined in #ifndef WCHAR_MIN // [ # define WCHAR_MIN 0 #endif // WCHAR_MIN ] #ifndef WCHAR_MAX // [ # define WCHAR_MAX _UI16_MAX #endif // WCHAR_MAX ] #define WINT_MIN 0 #define WINT_MAX _UI16_MAX #endif // __STDC_LIMIT_MACROS ] // 7.18.4 Limits of other integer types #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 // 7.18.4.1 Macros for minimum-width integer constants #define INT8_C(val) val##i8 #define INT16_C(val) val##i16 #define INT32_C(val) val##i32 #define INT64_C(val) val##i64 #define UINT8_C(val) val##ui8 #define UINT16_C(val) val##ui16 #define UINT32_C(val) val##ui32 #define UINT64_C(val) val##ui64 // 7.18.4.2 Macros for greatest-width integer constants #define INTMAX_C INT64_C #define UINTMAX_C UINT64_C #endif // __STDC_CONSTANT_MACROS ] #else //sanity for everything else #include #endif #endif libgambatte/libretro/msvc/msvc-2003-xbox1.bat000664 001750 001750 00000003042 12720365247 022037 0ustar00sergiosergio000000 000000 @SET VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE @SET VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio .NET 2003 @SET FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework @SET FrameworkVersion=v1.1.4322 @SET FrameworkSDKDir=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1 @rem Root of Visual Studio common files. @if "%VSINSTALLDIR%"=="" goto Usage @if "%VCINSTALLDIR%"=="" set VCINSTALLDIR=%VSINSTALLDIR% @rem @rem Root of Visual Studio ide installed files. @rem @set DevEnvDir=%VSINSTALLDIR% @rem @rem Root of Visual C++ installed files. @rem @set MSVCDir=%VCINSTALLDIR%\VC7 @rem @echo Setting environment for using Microsoft Visual Studio .NET 2003 tools. @echo (If you have another version of Visual Studio or Visual C++ installed and wish @echo to use its tools from the command line, run vcvars32.bat for that version.) @rem @REM %VCINSTALLDIR%\Common7\Tools dir is added only for real setup. @set PATH=%DevEnvDir%;%MSVCDir%\BIN;%VCINSTALLDIR%\Common7\Tools;%VCINSTALLDIR%\Common7\Tools\bin\prerelease;%VCINSTALLDIR%\Common7\Tools\bin;%FrameworkSDKDir%\bin;%FrameworkDir%\%FrameworkVersion%;%PATH%; @set INCLUDE=%MSVCDir%\ATLMFC\INCLUDE;%MSVCDir%\INCLUDE;%FrameworkSDKDir%\include;%INCLUDE%;%XDK%\xbox\include @set LIB=%MSVCDir%\ATLMFC\LIB;%MSVCDir%\LIB;%MSVCDir%\PlatformSDK\lib;%XDK%\lib;%XDK%\xbox\lib;%LIB% @goto end :Usage @echo. VSINSTALLDIR variable is not set. @echo. @echo SYNTAX: %0 @goto end :end devenv /clean Release_LTCG msvc-2003-xbox1.sln devenv /build Release_LTCG msvc-2003-xbox1.sln exit libgambatte/libretro/msvc/msvc-2010.sln000664 001750 001750 00000001552 12720365247 021030 0ustar00sergiosergio000000 000000  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msvc-2010", "msvc-2010/msvc-2010.vcxproj", "{A79F81F6-3FEE-48AA-9157-24EB772B624E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Debug|Win32.ActiveCfg = Debug|Win32 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Debug|Win32.Build.0 = Debug|Win32 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Release|Win32.ActiveCfg = Release|Win32 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal libgambatte/libretro/blipper.c000664 001750 001750 00000030432 12720365247 017612 0ustar00sergiosergio000000 000000 /* * Copyright (C) 2013 - Hans-Kristian Arntzen * * Permission is hereby granted, free of charge, * to any person obtaining a copy of this software and * associated documentation files (the "Software"), * to deal in the Software without restriction, * including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #include "blipper.h" #include #include #include #include #if BLIPPER_LOG_PERFORMANCE #include static double get_time(void) { struct timespec tv; clock_gettime(CLOCK_MONOTONIC, &tv); return tv.tv_sec + tv.tv_nsec / 1000000000.0; } #endif struct blipper { blipper_long_sample_t *output_buffer; unsigned output_avail; unsigned output_buffer_samples; blipper_sample_t *filter_bank; unsigned phase; unsigned phases; unsigned phases_log2; unsigned taps; blipper_long_sample_t integrator; blipper_sample_t last_sample; #if BLIPPER_LOG_PERFORMANCE double total_time; double integrator_time; unsigned long total_samples; #endif int owns_filter; }; void blipper_free(blipper_t *blip) { if (blip) { #if BLIPPER_LOG_PERFORMANCE fprintf(stderr, "[blipper]: Processed %lu samples, using %.6f seconds blipping and %.6f seconds integrating.\n", blip->total_samples, blip->total_time, blip->integrator_time); #endif if (blip->owns_filter) free(blip->filter_bank); free(blip->output_buffer); free(blip); } } static double besseli0(double x) { unsigned i; double sum = 0.0; double factorial = 1.0; double factorial_mult = 0.0; double x_pow = 1.0; double two_div_pow = 1.0; double x_sqr = x * x; /* Approximate. This is an infinite sum. * Luckily, it converges rather fast. */ for (i = 0; i < 18; i++) { sum += x_pow * two_div_pow / (factorial * factorial); factorial_mult += 1.0; x_pow *= x_sqr; two_div_pow *= 0.25; factorial *= factorial_mult; } return sum; } static double sinc(double v) { if (fabs(v) < 0.00001) return 1.0; else return sin(v) / v; } /* index range = [-1, 1) */ static double kaiser_window(double index, double beta) { return besseli0(beta * sqrt(1.0 - index * index)); } #ifndef M_PI #define M_PI 3.14159265358979323846 #endif static blipper_real_t *blipper_create_sinc(unsigned phases, unsigned taps, double cutoff, double beta) { unsigned i, filter_len; double sidelobes, window_mod; blipper_real_t *filter; filter = (blipper_real_t*)malloc(phases * taps * sizeof(*filter)); if (!filter) return NULL; sidelobes = taps / 2.0; window_mod = 1.0 / kaiser_window(0.0, beta); filter_len = phases * taps; for (i = 0; i < filter_len; i++) { double sinc_phase; double window_phase = (double)i / filter_len; /* [0, 1) */ window_phase = 2.0 * window_phase - 1.0; /* [-1, 1) */ sinc_phase = window_phase * sidelobes; /* [-taps / 2, taps / 2) */ filter[i] = cutoff * sinc(M_PI * sinc_phase * cutoff) * kaiser_window(window_phase, beta) * window_mod; } return filter; } /* We differentiate and integrate at different sample rates. * Differentiation is D(z) = 1 - z^-1 and happens when delta impulses * are convolved. Integration step after decimation by D is 1 / (1 - z^-D). * * If our sinc filter is S(z) we'd have a response of * S(z) * (1 - z^-1) / (1 - z^-D) after blipping. * * Compensate by prefiltering S(z) with the inverse (1 - z^-D) / (1 - z^-1). * This filtering creates a finite length filter, albeit slightly longer. * * phases is the same as decimation rate. */ static blipper_real_t *blipper_prefilter_sinc(blipper_real_t *filter, unsigned phases, unsigned taps) { unsigned i; float filter_amp = 0.75f / phases; blipper_real_t *tmp_filter; blipper_real_t *new_filter = (blipper_real_t*)malloc((phases * taps + phases) * sizeof(*filter)); if (!new_filter) goto error; tmp_filter = (blipper_real_t*)realloc(filter, (phases * taps + phases) * sizeof(*filter)); if (!tmp_filter) goto error; filter = tmp_filter; /* Integrate. */ new_filter[0] = filter[0]; for (i = 1; i < phases * taps; i++) new_filter[i] = new_filter[i - 1] + filter[i]; for (i = phases * taps; i < phases * taps + phases; i++) new_filter[i] = new_filter[phases * taps - 1]; taps++; /* Differentiate with offset of D. */ memcpy(filter, new_filter, phases * sizeof(*filter)); for (i = phases; i < phases * taps; i++) filter[i] = new_filter[i] - new_filter[i - phases]; /* blipper_prefilter_sinc() boosts the gain of the sinc. * Have to compensate for this. Attenuate a bit more to ensure * we don't clip, especially in fixed point. */ for (i = 0; i < phases * taps; i++) filter[i] *= filter_amp; free(new_filter); return filter; error: free(new_filter); free(filter); return NULL; } /* Creates a polyphase filter bank. * Interleaves the filter for cache coherency and possibilities * for SIMD processing. */ static blipper_real_t *blipper_interleave_sinc(blipper_real_t *filter, unsigned phases, unsigned taps) { unsigned t, p; blipper_real_t *new_filter = (blipper_real_t*)malloc(phases * taps * sizeof(*filter)); if (!new_filter) goto error; for (t = 0; t < taps; t++) for (p = 0; p < phases; p++) new_filter[p * taps + t] = filter[t * phases + p]; free(filter); return new_filter; error: free(new_filter); free(filter); return NULL; } #if BLIPPER_FIXED_POINT static blipper_sample_t *blipper_quantize_sinc(blipper_real_t *filter, unsigned taps) { unsigned t; blipper_sample_t *filt = (blipper_sample_t*)malloc(taps * sizeof(*filt)); if (!filt) goto error; for (t = 0; t < taps; t++) filt[t] = (blipper_sample_t)floor(filter[t] * 0x7fff + 0.5); free(filter); return filt; error: free(filter); free(filt); return NULL; } #endif blipper_sample_t *blipper_create_filter_bank(unsigned phases, unsigned taps, double cutoff, double beta) { blipper_real_t *sinc_filter; /* blipper_prefilter_sinc() will add one tap. * To keep number of taps as expected, compensate for it here * to keep the interface more obvious. */ if (taps <= 1) return 0; taps--; sinc_filter = blipper_create_sinc(phases, taps, cutoff, beta); if (!sinc_filter) return 0; sinc_filter = blipper_prefilter_sinc(sinc_filter, phases, taps); if (!sinc_filter) return 0; taps++; sinc_filter = blipper_interleave_sinc(sinc_filter, phases, taps); if (!sinc_filter) return 0; #if BLIPPER_FIXED_POINT return blipper_quantize_sinc(sinc_filter, phases * taps); #else return sinc_filter; #endif } static unsigned log2_int(unsigned v) { unsigned ret; v >>= 1; for (ret = 0; v; v >>= 1, ret++); return ret; } void blipper_reset(blipper_t *blip) { blip->phase = 0; memset(blip->output_buffer, 0, (blip->output_avail + blip->taps) * sizeof(*blip->output_buffer)); blip->output_avail = 0; blip->last_sample = 0; blip->integrator = 0; } blipper_t *blipper_new(unsigned taps, double cutoff, double beta, unsigned decimation, unsigned buffer_samples, const blipper_sample_t *filter_bank) { blipper_t *blip = NULL; /* Sanity check. Not strictly required to be supported in C. */ if ((-3 >> 2) != -1) { fprintf(stderr, "Integer right shift not supported.\n"); return NULL; } if ((decimation & (decimation - 1)) != 0) { fprintf(stderr, "[blipper]: Decimation factor must be POT.\n"); return NULL; } blip = (blipper_t*)calloc(1, sizeof(*blip)); if (!blip) return NULL; blip->phases = decimation; blip->phases_log2 = log2_int(decimation); blip->taps = taps; if (!filter_bank) { blip->filter_bank = blipper_create_filter_bank(blip->phases, taps, cutoff, beta); if (!blip->filter_bank) goto error; blip->owns_filter = 1; } else blip->filter_bank = (blipper_sample_t*)filter_bank; blip->output_buffer = (blipper_long_sample_t*)calloc(buffer_samples + blip->taps, sizeof(*blip->output_buffer)); if (!blip->output_buffer) goto error; blip->output_buffer_samples = buffer_samples + blip->taps; return blip; error: blipper_free(blip); return NULL; } void blipper_push_delta(blipper_t *blip, blipper_long_sample_t delta, unsigned clocks_step) { unsigned target_output, filter_phase, taps, i; const blipper_sample_t *response; blipper_long_sample_t *target; blip->phase += clocks_step; target_output = (blip->phase + blip->phases - 1) >> blip->phases_log2; filter_phase = (target_output << blip->phases_log2) - blip->phase; response = blip->filter_bank + blip->taps * filter_phase; target = blip->output_buffer + target_output; taps = blip->taps; for (i = 0; i < taps; i++) target[i] += delta * response[i]; blip->output_avail = target_output; } void blipper_push_samples(blipper_t *blip, const blipper_sample_t *data, unsigned samples, unsigned stride) { unsigned s; unsigned clocks_skip = 0; blipper_sample_t last = blip->last_sample; #if BLIPPER_LOG_PERFORMANCE double t0 = get_time(); #endif for (s = 0; s < samples; s++, data += stride) { blipper_sample_t val = *data; if (val != last) { blipper_push_delta(blip, (blipper_long_sample_t)val - (blipper_long_sample_t)last, clocks_skip + 1); clocks_skip = 0; last = val; } else clocks_skip++; } blip->phase += clocks_skip; blip->output_avail = (blip->phase + blip->phases - 1) >> blip->phases_log2; blip->last_sample = last; #if BLIPPER_LOG_PERFORMANCE blip->total_time += get_time() - t0; blip->total_samples += samples; #endif } unsigned blipper_read_avail(blipper_t *blip) { return blip->output_avail; } void blipper_read(blipper_t *blip, blipper_sample_t *output, unsigned samples, unsigned stride) { unsigned s; blipper_long_sample_t sum = blip->integrator; const blipper_long_sample_t *out = blip->output_buffer; #if BLIPPER_LOG_PERFORMANCE double t0 = get_time(); #endif #if BLIPPER_FIXED_POINT for (s = 0; s < samples; s++, output += stride) { blipper_long_sample_t quant; /* Cannot overflow. Also add a leaky integrator. Mitigates DC shift numerical instability which is inherent for integrators. */ sum += (out[s] >> 1) - (sum >> 9); /* Rounded. With leaky integrator, this cannot overflow. */ quant = (sum + 0x4000) >> 15; /* Clamp. quant can potentially have range [-0x10000, 0xffff] here. * In both cases, top 16-bits will have a uniform bit pattern which can be exploited. */ if ((blipper_sample_t)quant != quant) { quant = (quant >> 16) ^ 0x7fff; sum = quant << 15; } *output = quant; } #else for (s = 0; s < samples; s++, output += stride) { /* Leaky integrator, same as fixed point (1.0f / 512.0f) */ sum += out[s] - sum * 0.00195f; *output = sum; } #endif /* Don't bother with ring buffering. * The entire buffer should be read out ideally anyways. */ memmove(blip->output_buffer, blip->output_buffer + samples, (blip->output_avail + blip->taps - samples) * sizeof(*out)); memset(blip->output_buffer + blip->taps, 0, samples * sizeof(*out)); blip->output_avail -= samples; blip->phase -= samples << blip->phases_log2; blip->integrator = sum; #if BLIPPER_LOG_PERFORMANCE blip->integrator_time += get_time() - t0; #endif } libgambatte/libretro/msvc/msvc-2010-360.bat000664 001750 001750 00000007767 12720365247 021326 0ustar00sergiosergio000000 000000 @echo off @echo Setting environment for using Microsoft Visual Studio 2010 x86 tools. @call :GetVSCommonToolsDir @if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR @call "%VS100COMNTOOLS%VCVarsQueryRegistry.bat" 32bit No64bit @if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR @if "%FrameworkDir32%"=="" goto error_no_FrameworkDIR32 @if "%FrameworkVersion32%"=="" goto error_no_FrameworkVer32 @if "%Framework35Version%"=="" goto error_no_Framework35Version @set FrameworkDir=%FrameworkDir32% @set FrameworkVersion=%FrameworkVersion32% @if not "%WindowsSdkDir%" == "" ( @set "PATH=%WindowsSdkDir%bin\NETFX 4.0 Tools;%WindowsSdkDir%bin;%PATH%" @set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%" @set "LIB=%WindowsSdkDir%lib;%LIB%" ) @rem @rem Root of Visual Studio IDE installed files. @rem @set DevEnvDir=%VSINSTALLDIR%Common7\IDE\ @rem PATH @rem ---- @if exist "%VSINSTALLDIR%Team Tools\Performance Tools" ( @set "PATH=%VSINSTALLDIR%Team Tools\Performance Tools;%PATH%" ) @if exist "%ProgramFiles%\HTML Help Workshop" set PATH=%ProgramFiles%\HTML Help Workshop;%PATH% @if exist "%ProgramFiles(x86)%\HTML Help Workshop" set PATH=%ProgramFiles(x86)%\HTML Help Workshop;%PATH% @if exist "%VCINSTALLDIR%VCPackages" set PATH=%VCINSTALLDIR%VCPackages;%PATH% @set PATH=%FrameworkDir%%Framework35Version%;%PATH% @set PATH=%FrameworkDir%%FrameworkVersion%;%PATH% @set PATH=%VSINSTALLDIR%Common7\Tools;%PATH% @if exist "%VCINSTALLDIR%BIN" set PATH=%VCINSTALLDIR%BIN;%PATH% @set PATH=%DevEnvDir%;%PATH% @if exist "%VSINSTALLDIR%VSTSDB\Deploy" ( @set "PATH=%VSINSTALLDIR%VSTSDB\Deploy;%PATH%" ) @if not "%FSHARPINSTALLDIR%" == "" ( @set "PATH=%FSHARPINSTALLDIR%;%PATH%" ) @rem INCLUDE @rem ------- @if exist "%VCINSTALLDIR%ATLMFC\INCLUDE" set INCLUDE=%VCINSTALLDIR%ATLMFC\INCLUDE;%INCLUDE% @if exist "%VCINSTALLDIR%INCLUDE" set INCLUDE=%VCINSTALLDIR%INCLUDE;%INCLUDE% @rem LIB @rem --- @if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIB=%VCINSTALLDIR%ATLMFC\LIB;%LIB% @if exist "%VCINSTALLDIR%LIB" set LIB=%VCINSTALLDIR%LIB;%LIB% @rem LIBPATH @rem ------- @if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIBPATH=%VCINSTALLDIR%ATLMFC\LIB;%LIBPATH% @if exist "%VCINSTALLDIR%LIB" set LIBPATH=%VCINSTALLDIR%LIB;%LIBPATH% @set LIBPATH=%FrameworkDir%%Framework35Version%;%LIBPATH% @set LIBPATH=%FrameworkDir%%FrameworkVersion%;%LIBPATH% @goto end @REM ----------------------------------------------------------------------- :GetVSCommonToolsDir @set VS100COMNTOOLS= @call :GetVSCommonToolsDirHelper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper64 HKCU > nul 2>&1 @exit /B 0 :GetVSCommonToolsDirHelper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "VS100COMNTOOLS=%%k" ) ) @if "%VS100COMNTOOLS%"=="" exit /B 1 @SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\" @exit /B 0 :GetVSCommonToolsDirHelper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "VS100COMNTOOLS=%%k" ) ) @if "%VS100COMNTOOLS%"=="" exit /B 1 @SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\" @exit /B 0 @REM ----------------------------------------------------------------------- :error_no_VS100COMNTOOLSDIR @echo ERROR: Cannot determine the location of the VS Common Tools folder. @goto end :error_no_VSINSTALLDIR @echo ERROR: Cannot determine the location of the VS installation. @goto end :error_no_FrameworkDIR32 @echo ERROR: Cannot determine the location of the .NET Framework 32bit installation. @goto end :error_no_FrameworkVer32 @echo ERROR: Cannot determine the version of the .NET Framework 32bit installation. @goto end :error_no_Framework35Version @echo ERROR: Cannot determine the .NET Framework 3.5 version. @goto end :end msbuild msvc-2010-360.sln /p:Configuration=Release_LTCG /target:clean msbuild msvc-2010-360.sln /p:Configuration=Release_LTCG exit libgambatte/src/sound/length_counter.cpp000664 001750 001750 00000004451 12720365247 021634 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "length_counter.h" #include "master_disabler.h" #include namespace gambatte { LengthCounter::LengthCounter(MasterDisabler &disabler, unsigned const mask) : disableMaster_(disabler) , lengthCounter_(0) , lengthMask_(mask) { nr1Change(0, 0, 0); } void LengthCounter::event() { counter_ = counter_disabled; lengthCounter_ = 0; disableMaster_(); } void LengthCounter::nr1Change(unsigned const newNr1, unsigned const nr4, unsigned long const cc) { lengthCounter_ = (~newNr1 & lengthMask_) + 1; counter_ = (nr4 & 0x40) ? ((cc >> 13) + lengthCounter_) << 13 : static_cast(counter_disabled); } void LengthCounter::nr4Change(unsigned const oldNr4, unsigned const newNr4, unsigned long const cc) { if (counter_ != counter_disabled) lengthCounter_ = (counter_ >> 13) - (cc >> 13); { unsigned dec = 0; if (newNr4 & 0x40) { dec = ~cc >> 12 & 1; if (!(oldNr4 & 0x40) && lengthCounter_) { if (!(lengthCounter_ -= dec)) disableMaster_(); } } if ((newNr4 & 0x80) && !lengthCounter_) lengthCounter_ = lengthMask_ + 1 - dec; } if ((newNr4 & 0x40) && lengthCounter_) counter_ = ((cc >> 13) + lengthCounter_) << 13; else counter_ = counter_disabled; } void LengthCounter::saveState(SaveState::SPU::LCounter &lstate) const { lstate.counter = counter_; lstate.lengthCounter = lengthCounter_; } void LengthCounter::loadState(SaveState::SPU::LCounter const &lstate, unsigned long const cc) { counter_ = std::max(lstate.counter, cc); lengthCounter_ = lstate.lengthCounter; } } libgambatte/src/mem/memptrs.h000664 001750 001750 00000011314 12720365247 017372 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007-2010 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef MEMPTRS_H #define MEMPTRS_H namespace gambatte { enum OamDmaSrc { oam_dma_src_rom, oam_dma_src_sram, oam_dma_src_vram, oam_dma_src_wram, oam_dma_src_invalid, oam_dma_src_off, }; class MemPtrs { public: enum RamFlag { READ_EN = 1, WRITE_EN = 2, RTC_EN = 4 }; MemPtrs(); ~MemPtrs(); void reset(unsigned rombanks, unsigned rambanks, unsigned wrambanks); const unsigned char * rmem(unsigned area) const { return rmem_[area]; } unsigned char * wmem(unsigned area) const { return wmem_[area]; } unsigned char * vramdata() const { return rambankdata_ - 0x4000; } unsigned char * vramdataend() const { return rambankdata_; } unsigned char * romdata() const { return memchunk_ + 0x4000; } unsigned char * romdata(unsigned area) const { return romdata_[area]; } unsigned char * romdataend() const { return rambankdata_ - 0x4000; } unsigned char * wramdata(unsigned area) const { return wramdata_[area]; } unsigned char * wramdataend() const { return wramdataend_; } unsigned char * rambankdata() const { return rambankdata_; } unsigned char * rambankdataend() const { return wramdata_[0]; } const unsigned char * rdisabledRam() const { return rdisabledRamw(); } const unsigned char * rsrambankptr() const { return rsrambankptr_; } unsigned char * wsrambankptr() const { return wsrambankptr_; } unsigned char * vrambankptr() const { return vrambankptr_; } OamDmaSrc oamDmaSrc() const { return oamDmaSrc_; } void setRombank0(unsigned bank); void setRombank(unsigned bank); void setRambank(unsigned ramFlags, unsigned rambank); void setVrambank(unsigned bank) { vrambankptr_ = vramdata() + bank * 0x2000ul - 0x8000; } void setWrambank(unsigned bank); void setOamDmaSrc(OamDmaSrc oamDmaSrc); private: unsigned char *romdata_[2]; unsigned char *wramdata_[2]; const unsigned char *rmem_[0x10]; unsigned char *wmem_[0x10]; unsigned char *vrambankptr_; unsigned char *rsrambankptr_; unsigned char *wsrambankptr_; unsigned char *memchunk_; unsigned char *rambankdata_; unsigned char *wramdataend_; OamDmaSrc oamDmaSrc_; MemPtrs(const MemPtrs &); MemPtrs & operator=(const MemPtrs &); void disconnectOamDmaAreas(); unsigned char * rdisabledRamw() const { return wramdataend_ ; } unsigned char * wdisabledRam() const { return wramdataend_ + 0x2000; } }; inline bool isCgb(const MemPtrs &memptrs) { return memptrs.wramdataend() - memptrs.wramdata(0) == 0x8000; } } #endif libgambatte/src/sound/channel2.h000664 001750 001750 00000003434 12720365247 017753 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef SOUND_CHANNEL2_H #define SOUND_CHANNEL2_H #include "duty_unit.h" #include "envelope_unit.h" #include "gbint.h" #include "length_counter.h" #include "static_output_tester.h" namespace gambatte { struct SaveState; class Channel2 { public: Channel2(); void setNr1(unsigned data); void setNr2(unsigned data); void setNr3(unsigned data); void setNr4(unsigned data); void setSo(unsigned long soMask); bool isActive() const { return master_; } void update(uint_least32_t *buf, unsigned long soBaseVol, unsigned long cycles); void reset(); void saveState(SaveState &state); void loadState(SaveState const &state); private: friend class StaticOutputTester; StaticOutputTester staticOutputTest_; DutyMasterDisabler disableMaster_; LengthCounter lengthCounter_; DutyUnit dutyUnit_; EnvelopeUnit envelopeUnit_; SoundUnit *nextEventUnit; unsigned long cycleCounter_; unsigned long soMask_; unsigned long prevOut_; unsigned char nr4_; bool master_; void setEvent(); }; } #endif libgambatte/src/mem/rtc.h000664 001750 001750 00000006122 12720365247 016474 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef RTC_H #define RTC_H #include #include namespace gambatte { struct SaveState; class Rtc { public: Rtc(); const unsigned char* getActive() const { return activeData_; } uint64_t& getBaseTime() { return baseTime_; } void setBaseTime(const uint64_t baseTime) { baseTime_ = baseTime; } void latch(const unsigned data) { if (!lastLatchData_ && data == 1) doLatch(); lastLatchData_ = data; } void saveState(SaveState &state) const; void loadState(const SaveState &state); void set(const bool enabled, unsigned bank) { bank &= 0xF; bank -= 8; this->enabled_ = enabled; this->index_ = bank; doSwapActive(); } void write(const unsigned data) { (this->*activeSet_)(data); *activeData_ = data; } private: unsigned char *activeData_; void (Rtc::*activeSet_)(unsigned); uint64_t baseTime_; uint64_t haltTime_; unsigned char index_; unsigned char dataDh_; unsigned char dataDl_; unsigned char dataH_; unsigned char dataM_; unsigned char dataS_; bool enabled_; bool lastLatchData_; void doLatch(); void doSwapActive(); void setDh(unsigned new_dh); void setDl(unsigned new_lowdays); void setH(unsigned new_hours); void setM(unsigned new_minutes); void setS(unsigned new_seconds); }; } #endif libgambatte/src/sound/master_disabler.h000664 001750 001750 00000002043 12720365247 021414 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef MASTER_DISABLER_H #define MASTER_DISABLER_H namespace gambatte { class MasterDisabler { public: explicit MasterDisabler(bool &master) : master_(master) {} virtual ~MasterDisabler() {} virtual void operator()() { master_ = false; } private: bool &master_; }; } #endif libgambatte/src/interrupter.cpp000664 001750 001750 00000004241 12720365247 020044 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "interrupter.h" #include "gambatte-memory.h" namespace gambatte { Interrupter::Interrupter(unsigned short &sp, unsigned short &pc) : sp_(sp) , pc_(pc) { } unsigned long Interrupter::interrupt(unsigned const address, unsigned long cc, Memory &memory) { cc += 8; sp_ = (sp_ - 1) & 0xFFFF; memory.write(sp_, pc_ >> 8, cc); cc += 4; sp_ = (sp_ - 1) & 0xFFFF; memory.write(sp_, pc_ & 0xFF, cc); pc_ = address; cc += 8; if (address == 0x40 && !gsCodes_.empty()) applyVblankCheats(cc, memory); return cc; } static int asHex(char c) { return c >= 'A' ? c - 'A' + 0xA : c - '0'; } void Interrupter::setGameShark(std::string const &codes) { std::string code; gsCodes_.clear(); for (std::size_t pos = 0; pos < codes.length(); pos += code.length() + 1) { code = codes.substr(pos, codes.find(';', pos) - pos); if (code.length() >= 8) { GsCode gs; gs.type = asHex(code[0]) << 4 | asHex(code[1]); gs.value = (asHex(code[2]) << 4 | asHex(code[3])) & 0xFF; gs.address = ( asHex(code[4]) << 4 | asHex(code[5]) | asHex(code[6]) << 12 | asHex(code[7]) << 8) & 0xFFFF; gsCodes_.push_back(gs); } } } void Interrupter::applyVblankCheats(unsigned long const cc, Memory &memory) { for (std::size_t i = 0, size = gsCodes_.size(); i < size; ++i) { if (gsCodes_[i].type == 0x01) memory.write(gsCodes_[i].address, gsCodes_[i].value, cc); } } } libgambatte/libretro/000700 001750 001750 00000000000 12720366157 015774 5ustar00sergiosergio000000 000000 libgambatte/src/video/lyc_irq.h000664 001750 001750 00000003451 12720365247 017700 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef VIDEO_LYC_IRQ_H #define VIDEO_LYC_IRQ_H namespace gambatte { struct SaveState; class LyCounter; class LycIrq { public: LycIrq(); void doEvent(unsigned char *ifreg, LyCounter const &lyCounter); unsigned lycReg() const { return lycRegSrc_; } void loadState(SaveState const &state); void saveState(SaveState &state) const; unsigned long time() const { return time_; } void setCgb(bool cgb) { cgb_ = cgb; } void lcdReset(); void reschedule(LyCounter const &lyCounter, unsigned long cc); void statRegChange(unsigned statReg, LyCounter const &lyCounter, unsigned long cc) { regChange(statReg, lycRegSrc_, lyCounter, cc); } void lycRegChange(unsigned lycReg, LyCounter const &lyCounter, unsigned long cc) { regChange(statRegSrc_, lycReg, lyCounter, cc); } private: unsigned long time_; unsigned char lycRegSrc_; unsigned char statRegSrc_; unsigned char lycReg_; unsigned char statReg_; bool cgb_; void regChange(unsigned statReg, unsigned lycReg, LyCounter const &lyCounter, unsigned long cc); }; } #endif libgambatte/src/sound.h000664 001750 001750 00000005652 12720365247 016265 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef SOUND_H #define SOUND_H #include #include #include "sound/channel1.h" #include "sound/channel2.h" #include "sound/channel3.h" #include "sound/channel4.h" namespace gambatte { class PSG { public: PSG(); void init(bool cgb); void reset(); void setStatePtrs(SaveState &state); void saveState(SaveState &state); void loadState(SaveState const &state); void generateSamples(unsigned long cycleCounter, bool doubleSpeed); void resetCounter(unsigned long newCc, unsigned long oldCc, bool doubleSpeed); std::size_t fillBuffer(); void setBuffer(uint_least32_t *buf) { buffer_ = buf; bufferPos_ = 0; } bool isEnabled() const { return enabled_; } void setEnabled(bool value) { enabled_ = value; } void setNr10(unsigned data) { ch1_.setNr0(data); } void setNr11(unsigned data) { ch1_.setNr1(data); } void setNr12(unsigned data) { ch1_.setNr2(data); } void setNr13(unsigned data) { ch1_.setNr3(data); } void setNr14(unsigned data) { ch1_.setNr4(data); } void setNr21(unsigned data) { ch2_.setNr1(data); } void setNr22(unsigned data) { ch2_.setNr2(data); } void setNr23(unsigned data) { ch2_.setNr3(data); } void setNr24(unsigned data) { ch2_.setNr4(data); } void setNr30(unsigned data) { ch3_.setNr0(data); } void setNr31(unsigned data) { ch3_.setNr1(data); } void setNr32(unsigned data) { ch3_.setNr2(data); } void setNr33(unsigned data) { ch3_.setNr3(data); } void setNr34(unsigned data) { ch3_.setNr4(data); } unsigned waveRamRead(unsigned index) const { return ch3_.waveRamRead(index); } void waveRamWrite(unsigned index, unsigned data) { ch3_.waveRamWrite(index, data); } void setNr41(unsigned data) { ch4_.setNr1(data); } void setNr42(unsigned data) { ch4_.setNr2(data); } void setNr43(unsigned data) { ch4_.setNr3(data); } void setNr44(unsigned data) { ch4_.setNr4(data); } void setSoVolume(unsigned nr50); void mapSo(unsigned nr51); unsigned getStatus() const; private: Channel1 ch1_; Channel2 ch2_; Channel3 ch3_; Channel4 ch4_; uint_least32_t *buffer_; std::size_t bufferPos_; unsigned long lastUpdate_; unsigned long soVol_; uint_least32_t rsum_; bool enabled_; void accumulateChannels(unsigned long cycles); }; } #endif libgambatte/src/mem/memptrs.cpp000664 001750 001750 00000013450 12720365247 017730 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007-2010 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "memptrs.h" #include #include namespace gambatte { MemPtrs::MemPtrs() : rmem_() , wmem_() , romdata_() , wramdata_() , vrambankptr_(0) , rsrambankptr_(0) , wsrambankptr_(0) ,memchunk_(0) , rambankdata_(0) , wramdataend_(0) , oamDmaSrc_(oam_dma_src_off) { } MemPtrs::~MemPtrs() { delete []memchunk_; } void MemPtrs::reset(const unsigned rombanks, const unsigned rambanks, const unsigned wrambanks) { delete []memchunk_; memchunk_ = new unsigned char[ 0x4000 + rombanks * 0x4000ul + 0x4000 + rambanks * 0x2000ul + wrambanks * 0x1000ul + 0x4000]; romdata_[0] = romdata(); rambankdata_ = romdata_[0] + rombanks * 0x4000ul + 0x4000; wramdata_[0] = rambankdata_ + rambanks * 0x2000ul; wramdataend_ = wramdata_[0] + wrambanks * 0x1000ul; std::memset(rdisabledRamw(), 0xFF, 0x2000); oamDmaSrc_ = oam_dma_src_off; rmem_[0x3] = rmem_[0x2] = rmem_[0x1] = rmem_[0x0] = romdata_[0]; rmem_[0xC] = wmem_[0xC] = wramdata_[0] - 0xC000; rmem_[0xE] = wmem_[0xE] = wramdata_[0] - 0xE000; setRombank(1); setRambank(0, 0); setVrambank(0); setWrambank(1); } void MemPtrs::setRombank0(const unsigned bank) { romdata_[0] = romdata() + bank * 0x4000ul; rmem_[0x3] = rmem_[0x2] = rmem_[0x1] = rmem_[0x0] = romdata_[0]; disconnectOamDmaAreas(); } void MemPtrs::setRombank(const unsigned bank) { romdata_[1] = romdata() + bank * 0x4000ul - 0x4000; rmem_[0x7] = rmem_[0x6] = rmem_[0x5] = rmem_[0x4] = romdata_[1]; disconnectOamDmaAreas(); } void MemPtrs::setRambank(const unsigned flags, const unsigned rambank) { unsigned char *const srambankptr = (flags & RTC_EN) ? 0 : (rambankdata() != rambankdataend() ? rambankdata_ + rambank * 0x2000ul - 0xA000 : wdisabledRam() - 0xA000); rsrambankptr_ = (flags & READ_EN) && srambankptr != wdisabledRam() - 0xA000 ? srambankptr : rdisabledRamw() - 0xA000; wsrambankptr_ = (flags & WRITE_EN) ? srambankptr : wdisabledRam() - 0xA000; rmem_[0xB] = rmem_[0xA] = rsrambankptr_; wmem_[0xB] = wmem_[0xA] = wsrambankptr_; disconnectOamDmaAreas(); } void MemPtrs::setWrambank(const unsigned bank) { wramdata_[1] = wramdata_[0] + ((bank & 0x07) ? (bank & 0x07) : 1) * 0x1000; rmem_[0xD] = wmem_[0xD] = wramdata_[1] - 0xD000; disconnectOamDmaAreas(); } void MemPtrs::setOamDmaSrc(const OamDmaSrc oamDmaSrc) { rmem_[0x3] = rmem_[0x2] = rmem_[0x1] = rmem_[0x0] = romdata_[0]; rmem_[0x7] = rmem_[0x6] = rmem_[0x5] = rmem_[0x4] = romdata_[1]; rmem_[0xB] = rmem_[0xA] = rsrambankptr_; wmem_[0xB] = wmem_[0xA] = wsrambankptr_; rmem_[0xC] = wmem_[0xC] = wramdata_[0] - 0xC000; rmem_[0xD] = wmem_[0xD] = wramdata_[1] - 0xD000; rmem_[0xE] = wmem_[0xE] = wramdata_[0] - 0xE000; oamDmaSrc_ = oamDmaSrc; disconnectOamDmaAreas(); } void MemPtrs::disconnectOamDmaAreas() { if (isCgb(*this)) { switch (oamDmaSrc_) { case oam_dma_src_rom: // fall through case oam_dma_src_sram: case oam_dma_src_invalid: std::fill(rmem_, rmem_ + 8, static_cast(0)); rmem_[0xB] = rmem_[0xA] = 0; wmem_[0xB] = wmem_[0xA] = 0; break; case oam_dma_src_vram: break; case oam_dma_src_wram: rmem_[0xE] = rmem_[0xD] = rmem_[0xC] = 0; wmem_[0xE] = wmem_[0xD] = wmem_[0xC] = 0; break; case oam_dma_src_off: break; } } else { switch (oamDmaSrc_) { case oam_dma_src_rom: // fall through case oam_dma_src_sram: case oam_dma_src_wram: case oam_dma_src_invalid: std::fill(rmem_, rmem_ + 8, static_cast(0)); rmem_[0xB] = rmem_[0xA] = 0; wmem_[0xB] = wmem_[0xA] = 0; rmem_[0xE] = rmem_[0xD] = rmem_[0xC] = 0; wmem_[0xE] = wmem_[0xD] = wmem_[0xC] = 0; break; case oam_dma_src_vram: break; case oam_dma_src_off: break; } } } } libgambatte/src/sound/envelope_unit.cpp000664 001750 001750 00000004364 12720365247 021473 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "envelope_unit.h" #include namespace gambatte { EnvelopeUnit::VolOnOffEvent EnvelopeUnit::nullEvent_; EnvelopeUnit::EnvelopeUnit(VolOnOffEvent &volOnOffEvent) : volOnOffEvent_(volOnOffEvent) , nr2_(0) , volume_(0) { } void EnvelopeUnit::reset() { counter_ = counter_disabled; } void EnvelopeUnit::saveState(SaveState::SPU::Env &estate) const { estate.counter = counter_; estate.volume = volume_; } void EnvelopeUnit::loadState(SaveState::SPU::Env const &estate, unsigned nr2, unsigned long cc) { counter_ = std::max(estate.counter, cc); volume_ = estate.volume; nr2_ = nr2; } void EnvelopeUnit::event() { unsigned long const period = nr2_ & 7; if (period) { unsigned newVol = volume_; if (nr2_ & 8) ++newVol; else --newVol; if (newVol < 0x10U) { volume_ = newVol; if (volume_ < 2) volOnOffEvent_(counter_); counter_ += period << 15; } else counter_ = counter_disabled; } else counter_ += 8ul << 15; } bool EnvelopeUnit::nr2Change(unsigned const newNr2) { if (!(nr2_ & 7) && counter_ != counter_disabled) ++volume_; else if (!(nr2_ & 8)) volume_ += 2; if ((nr2_ ^ newNr2) & 8) volume_ = 0x10 - volume_; volume_ &= 0xF; nr2_ = newNr2; return !(newNr2 & 0xF8); } bool EnvelopeUnit::nr4Init(unsigned long const cc) { unsigned long period = (nr2_ & 7) ? nr2_ & 7 : 8; if (((cc + 2) & 0x7000) == 0x0000) ++period; counter_ = cc - ((cc - 0x1000) & 0x7FFF) + period * 0x8000; volume_ = nr2_ >> 4; return !(nr2_ & 0xF8); } } libgambatte/src/counterdef.h000664 001750 001750 00000000163 12720365247 017263 0ustar00sergiosergio000000 000000 #ifndef COUNTERDEF_H #define COUNTERDEF_H namespace gambatte { enum { disabled_time = 0xfffffffful }; } #endif libgambatte/libretro/jni/Application.mk000664 001750 001750 00000000051 12720365247 021357 0ustar00sergiosergio000000 000000 APP_STL := gnustl_static APP_ABI := all libgambatte/src/gambatte.cpp000664 001750 001750 00000011006 12720365247 017242 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "gambatte.h" #include "cpu.h" #include "savestate.h" #include "statesaver.h" #include "initstate.h" #include namespace gambatte { struct GB::Priv { CPU cpu; int stateNo; bool gbaCgbMode; Priv() : stateNo(1), gbaCgbMode(false) {} void on_load_succeeded(unsigned flags); }; GB::GB() : p_(new Priv) {} GB::~GB() { delete p_; } long GB::runFor(gambatte::video_pixel_t *const videoBuf, const int pitch, gambatte::uint_least32_t *const soundBuf, unsigned &samples) { p_->cpu.setVideoBuffer(videoBuf, pitch); p_->cpu.setSoundBuffer(soundBuf); const long cyclesSinceBlit = p_->cpu.runFor(samples * 2); samples = p_->cpu.fillSoundBuffer(); return cyclesSinceBlit < 0 ? cyclesSinceBlit : static_cast(samples) - (cyclesSinceBlit >> 1); } void GB::reset() { SaveState state; p_->cpu.setStatePtrs(state); setInitState(state, p_->cpu.isCgb(), p_->gbaCgbMode); p_->cpu.loadState(state); } void GB::setInputGetter(InputGetter *getInput) { p_->cpu.setInputGetter(getInput); } void GB::Priv::on_load_succeeded(unsigned flags) { SaveState state; cpu.setStatePtrs(state); setInitState(state, cpu.isCgb(), gbaCgbMode = flags & GBA_CGB); cpu.loadState(state); stateNo = 1; } void *GB::savedata_ptr() { return p_->cpu.savedata_ptr(); } unsigned GB::savedata_size() { return p_->cpu.savedata_size(); } void *GB::rtcdata_ptr() { return p_->cpu.rtcdata_ptr(); } unsigned GB::rtcdata_size() { return p_->cpu.rtcdata_size(); } int GB::load(const void *romdata, unsigned romsize, const unsigned flags) { const int failed = p_->cpu.load(romdata, romsize, flags & FORCE_DMG, flags & MULTICART_COMPAT); if (!failed) p_->on_load_succeeded(flags); return failed; } bool GB::isCgb() const { return p_->cpu.isCgb(); } bool GB::isLoaded() const { return true; } void GB::setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32) { p_->cpu.setDmgPaletteColor(palNum, colorNum, rgb32); } void GB::loadState(const void *data) { SaveState state; p_->cpu.setStatePtrs(state); if (StateSaver::loadState(state, data)) { p_->cpu.loadState(state); } } void GB::saveState(void *data) { SaveState state; p_->cpu.setStatePtrs(state); p_->cpu.saveState(state); StateSaver::saveState(state, data); } size_t GB::stateSize() const { SaveState state; p_->cpu.setStatePtrs(state); p_->cpu.saveState(state); return StateSaver::stateSize(state); } void GB::setColorCorrection(bool enable) { p_->cpu.mem_.display_setColorCorrection(enable); } video_pixel_t GB::gbcToRgb32(const unsigned bgr15) { return p_->cpu.mem_.display_gbcToRgb32(bgr15); } void GB::setGameGenie(const std::string &codes) { p_->cpu.setGameGenie(codes); } void GB::setGameShark(const std::string &codes) { p_->cpu.setGameShark(codes); } void GB::clearCheats() { p_->cpu.clearCheats(); } #ifdef __LIBRETRO__ void *GB::vram_ptr() const { return p_->cpu.vram_ptr(); } void *GB::rambank0_ptr() const { return p_->cpu.rambank0_ptr(); } void *GB::rambank1_ptr() const { return p_->cpu.rambank1_ptr(); } void *GB::rombank0_ptr() const { return p_->cpu.rombank0_ptr(); } void *GB::rombank1_ptr() const { return p_->cpu.rombank1_ptr(); } #endif } libgambatte/src/video/sprite_mapper.h000664 001750 001750 00000010303 12720365247 021102 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef SPRITE_MAPPER_H #define SPRITE_MAPPER_H #include "ly_counter.h" #include "../savestate.h" namespace gambatte { class NextM0Time; class SpriteMapper { public: SpriteMapper(NextM0Time &nextM0Time, LyCounter const &lyCounter, unsigned char const *oamram); void reset(unsigned char const *oamram, bool cgb); unsigned long doEvent(unsigned long time); bool largeSprites(unsigned spNo) const { return oamReader_.largeSprites(spNo); } unsigned numSprites(unsigned ly) const { return num_[ly] & ~need_sorting_mask; } void oamChange(unsigned long cc) { oamReader_.change(cc); } void oamChange(unsigned char const *oamram, unsigned long cc) { oamReader_.change(oamram, cc); } unsigned char const * oamram() const { return oamReader_.oam(); } unsigned char const * posbuf() const { return oamReader_.spritePosBuf(); } void preSpeedChange(unsigned long cc) { oamReader_.update(cc); } void postSpeedChange(unsigned long cc) { oamReader_.change(cc); } void resetCycleCounter(unsigned long oldCc, unsigned long newCc) { oamReader_.update(oldCc); oamReader_.resetCycleCounter(oldCc, newCc); } void setLargeSpritesSource(bool src) { oamReader_.setLargeSpritesSrc(src); } unsigned char const * sprites(unsigned ly) const { if (num_[ly] & need_sorting_mask) sortLine(ly); return spritemap_ + ly * 10; } void setStatePtrs(SaveState &state) { oamReader_.setStatePtrs(state); } void enableDisplay(unsigned long cc) { oamReader_.enableDisplay(cc); } void saveState(SaveState &state) const { oamReader_.saveState(state); } void loadState(SaveState const &state, unsigned char const *oamram) { oamReader_.loadState(state, oamram); mapSprites(); } bool inactivePeriodAfterDisplayEnable(unsigned long cc) const { return oamReader_.inactivePeriodAfterDisplayEnable(cc); } static unsigned long schedule(LyCounter const &lyCounter, unsigned long cc) { return lyCounter.nextLineCycle(80, cc); } private: class OamReader { public: OamReader(LyCounter const &lyCounter, unsigned char const *oamram); void reset(unsigned char const *oamram, bool cgb); void change(unsigned long cc); void change(unsigned char const *oamram, unsigned long cc) { change(cc); oamram_ = oamram; } bool changed() const { return lastChange_ != 0xFF; } bool largeSprites(unsigned spNo) const { return szbuf_[spNo]; } unsigned char const * oam() const { return oamram_; } void resetCycleCounter(unsigned long oldCc, unsigned long newCc) { lu_ -= oldCc - newCc; } void setLargeSpritesSrc(bool src) { largeSpritesSrc_ = src; } void update(unsigned long cc); unsigned char const * spritePosBuf() const { return buf_; } void setStatePtrs(SaveState &state); void enableDisplay(unsigned long cc); void saveState(SaveState &state) const { state.ppu.enableDisplayM0Time = lu_; } void loadState(SaveState const &ss, unsigned char const *oamram); bool inactivePeriodAfterDisplayEnable(unsigned long cc) const { return cc < lu_; } unsigned lineTime() const { return lyCounter_.lineTime(); } private: unsigned char buf_[80]; bool szbuf_[40]; LyCounter const &lyCounter_; unsigned char const *oamram_; unsigned long lu_; unsigned char lastChange_; bool largeSpritesSrc_; bool cgb_; }; enum { need_sorting_mask = 0x80 }; mutable unsigned char spritemap_[144 * 10]; mutable unsigned char num_[144]; NextM0Time &nextM0Time_; OamReader oamReader_; void clearMap(); void mapSprites(); void sortLine(unsigned ly) const; }; } #endif libgambatte/libretro/msvc/msvc-2010-360/msvc-2010-360.vcxproj000664 001750 001750 00000037241 12720365247 024077 0ustar00sergiosergio000000 000000  CodeAnalysis Xbox 360 Debug Xbox 360 Profile Xbox 360 Profile_FastCap Xbox 360 Release Xbox 360 Release_LTCG Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E} Xbox360Proj gambatte-360 StaticLibrary MultiByte StaticLibrary MultiByte StaticLibrary MultiByte StaticLibrary MultiByte StaticLibrary MultiByte true StaticLibrary true MultiByte $(OutDir)msvc-2010-360$(TargetExt) $(OutDir)msvc-2010-360$(TargetExt) $(OutDir)msvc-2010-360$(TargetExt) $(OutDir)msvc-2010-360$(TargetExt) $(OutDir)msvc-2010-360$(TargetExt) $(OutDir)msvc-2010-360$(TargetExt) NotUsing Level3 ProgramDatabase Disabled false true false $(OutDir)$(ProjectName).pch MultiThreadedDebug _DEBUG;_XBOX;_XBOX360;_LIB;%(PreprocessorDefinitions);HAVE_STDINT_H Callcap ..\..\..\include;..\..\..\src\;..\..\..\src\video;..\..\..\src\file;..\..\..\src\sound;..\..\..\src\mem;..\..\..\..\common;..\libsnes;..\..\..\..\common\resample true NotUsing Level4 ProgramDatabase Disabled false true AnalyzeOnly false $(OutDir)$(ProjectName).pch MultiThreadedDebug _DEBUG;_XBOX;_XBOX360;_LIB;%(PreprocessorDefinitions);HAVE_STDINT_H Callcap ..\..\..\include;..\..\..\src\;..\..\..\src\video;..\..\..\src\file;..\..\..\src\sound;..\..\..\src\mem;..\..\..\..\common;..\libsnes;..\..\..\..\common\resample true Level3 NotUsing Full true false true ProgramDatabase Size false $(OutDir)$(ProjectName).pch MultiThreaded NDEBUG;_XBOX;_XBOX360;PROFILE;_LIB;%(PreprocessorDefinitions);HAVE_STDINT_H Callcap ..\..\..\include;..\..\..\src\;..\..\..\src\video;..\..\..\src\file;..\..\..\src\sound;..\..\..\src\mem;..\..\..\..\common;..\libsnes;..\..\..\..\common\resample true false xapilib.lib;%(IgnoreSpecificDefaultLibraries) true Level3 NotUsing Full true false true ProgramDatabase Fastcap Size false $(OutDir)$(ProjectName).pch MultiThreaded NDEBUG;_XBOX;_XBOX360;PROFILE;FASTCAP;_LIB;%(PreprocessorDefinitions);HAVE_STDINT_H ..\..\..\include;..\..\..\src\;..\..\..\src\video;..\..\..\src\file;..\..\..\src\sound;..\..\..\src\mem;..\..\..\..\common;..\libsnes;..\..\..\..\common\resample true false true Level3 NotUsing Full true true ProgramDatabase Size false false $(OutDir)$(ProjectName).pch MultiThreaded NDEBUG;_XBOX;_XBOX360;_LIB;%(PreprocessorDefinitions);HAVE_STDINT_H ..\..\..\include;..\..\..\src\;..\..\..\src\video;..\..\..\src\file;..\..\..\src\sound;..\..\..\src\mem;..\..\..\..\common;..\libsnes;..\..\..\..\common\resample true true true Level3 NotUsing Full true true ProgramDatabase Size false false $(OutDir)$(ProjectName).pch MultiThreaded NDEBUG;_XBOX;_XBOX360;LTCG;_LIB;%(PreprocessorDefinitions);HAVE_STDINT_H ..\..\..\include;..\..\..\src\;..\..\..\src\video;..\..\..\src\file;..\..\..\src\sound;..\..\..\src\mem;..\..\..\..\common;..\libsnes;..\..\..\..\common\resample true true true libgambatte/src/sound/000700 001750 001750 00000000000 12720366137 016067 5ustar00sergiosergio000000 000000 COPYING000664 001750 001750 00000043103 12720365247 012746 0ustar00sergiosergio000000 000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. libgambatte/src/video/000700 001750 001750 00000000000 12720366137 016045 5ustar00sergiosergio000000 000000 libgambatte/src/video/next_m0_time.cpp000664 001750 001750 00000000245 12720365247 021157 0ustar00sergiosergio000000 000000 #include "next_m0_time.h" #include "ppu.h" void gambatte::NextM0Time::predictNextM0Time(PPU const &ppu) { predictedNextM0Time_ = ppu.predictedNextXposTime(167); } libgambatte/src/video/lyc_irq.cpp000664 001750 001750 00000006225 12720365247 020235 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "lyc_irq.h" #include "counterdef.h" #include "lcddef.h" #include "ly_counter.h" #include "savestate.h" #include namespace gambatte { LycIrq::LycIrq() : time_(disabled_time) , lycRegSrc_(0) , statRegSrc_(0) , lycReg_(0) , statReg_(0) , cgb_(false) { } static unsigned long schedule(unsigned statReg, unsigned lycReg, LyCounter const &lyCounter, unsigned long cc) { return (statReg & lcdstat_lycirqen) && lycReg < 154 ? lyCounter.nextFrameCycle(lycReg ? lycReg * 456 : 153 * 456 + 8, cc) : static_cast(disabled_time); } void LycIrq::regChange(unsigned const statReg, unsigned const lycReg, LyCounter const &lyCounter, unsigned long const cc) { unsigned long const timeSrc = schedule(statReg, lycReg, lyCounter, cc); statRegSrc_ = statReg; lycRegSrc_ = lycReg; time_ = std::min(time_, timeSrc); if (cgb_) { if (time_ - cc > 8 || (timeSrc != time_ && time_ - cc > 4U - lyCounter.isDoubleSpeed() * 4U)) lycReg_ = lycReg; if (time_ - cc > 4U - lyCounter.isDoubleSpeed() * 4U) statReg_ = statReg; } else { if (time_ - cc > 4 || timeSrc != time_) lycReg_ = lycReg; if (time_ - cc > 4 || lycReg_ != 0) statReg_ = statReg; statReg_ = (statReg_ & lcdstat_lycirqen) | (statReg & ~lcdstat_lycirqen); } } static bool lycIrqBlockedByM2OrM1StatIrq(unsigned ly, unsigned statreg) { return ly - 1u < 144u - 1u ? statreg & lcdstat_m2irqen : statreg & lcdstat_m1irqen; } void LycIrq::doEvent(unsigned char *const ifreg, LyCounter const &lyCounter) { if ((statReg_ | statRegSrc_) & lcdstat_lycirqen) { unsigned cmpLy = lyCounter.time() - time_ < lyCounter.lineTime() ? 0 : lyCounter.ly(); if (lycReg_ == cmpLy && !lycIrqBlockedByM2OrM1StatIrq(lycReg_, statReg_)) *ifreg |= 2; } lycReg_ = lycRegSrc_; statReg_ = statRegSrc_; time_ = schedule(statReg_, lycReg_, lyCounter, time_); } void LycIrq::loadState(SaveState const &state) { lycRegSrc_ = state.mem.ioamhram.get()[0x145]; statRegSrc_ = state.mem.ioamhram.get()[0x141]; lycReg_ = state.ppu.lyc; statReg_ = statRegSrc_; } void LycIrq::saveState(SaveState &state) const { state.ppu.lyc = lycReg_; } void LycIrq::reschedule(LyCounter const &lyCounter, unsigned long cc) { time_ = std::min(schedule(statReg_ , lycReg_ , lyCounter, cc), schedule(statRegSrc_, lycRegSrc_, lyCounter, cc)); } void LycIrq::lcdReset() { statReg_ = statRegSrc_; lycReg_ = lycRegSrc_; } } libgambatte/src/tima.cpp000664 001750 001750 00000010207 12720365247 016412 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "tima.h" #include "savestate.h" static unsigned char const timaClock[4] = { 10, 4, 6, 8 }; namespace gambatte { Tima::Tima() : lastUpdate_(0) , tmatime_(disabled_time) , tima_(0) , tma_(0) , tac_(0) { } void Tima::saveState(SaveState &state) const { state.mem.timaLastUpdate = lastUpdate_; state.mem.tmatime = tmatime_; } void Tima::loadState(SaveState const &state, TimaInterruptRequester timaIrq) { lastUpdate_ = state.mem.timaLastUpdate; tmatime_ = state.mem.tmatime; tima_ = state.mem.ioamhram.get()[0x105]; tma_ = state.mem.ioamhram.get()[0x106]; tac_ = state.mem.ioamhram.get()[0x107]; unsigned long nextIrqEventTime = disabled_time; if (tac_ & 4) { nextIrqEventTime = tmatime_ != disabled_time && tmatime_ > state.cpu.cycleCounter ? tmatime_ : lastUpdate_ + ((256u - tima_) << timaClock[tac_ & 3]) + 3; } timaIrq.setNextIrqEventTime(nextIrqEventTime); } void Tima::resetCc(unsigned long const oldCc, unsigned long const newCc, TimaInterruptRequester timaIrq) { if (tac_ & 0x04) { updateIrq(oldCc, timaIrq); updateTima(oldCc); unsigned long const dec = oldCc - newCc; lastUpdate_ -= dec; timaIrq.setNextIrqEventTime(timaIrq.nextIrqEventTime() - dec); if (tmatime_ != disabled_time) tmatime_ -= dec; } } void Tima::updateTima(unsigned long const cc) { unsigned long const ticks = (cc - lastUpdate_) >> timaClock[tac_ & 3]; lastUpdate_ += ticks << timaClock[tac_ & 3]; if (cc >= tmatime_) { if (cc >= tmatime_ + 4) tmatime_ = disabled_time; tima_ = tma_; } unsigned long tmp = tima_ + ticks; while (tmp > 0x100) tmp -= 0x100 - tma_; if (tmp == 0x100) { tmp = 0; tmatime_ = lastUpdate_ + 3; if (cc >= tmatime_) { if (cc >= tmatime_ + 4) tmatime_ = disabled_time; tmp = tma_; } } tima_ = tmp; } void Tima::setTima(unsigned const data, unsigned long const cc, TimaInterruptRequester timaIrq) { if (tac_ & 0x04) { updateIrq(cc, timaIrq); updateTima(cc); if (tmatime_ - cc < 4) tmatime_ = disabled_time; timaIrq.setNextIrqEventTime(lastUpdate_ + ((256u - data) << timaClock[tac_ & 3]) + 3); } tima_ = data; } void Tima::setTma(unsigned const data, unsigned long const cc, TimaInterruptRequester timaIrq) { if (tac_ & 0x04) { updateIrq(cc, timaIrq); updateTima(cc); } tma_ = data; } void Tima::setTac(unsigned const data, unsigned long const cc, TimaInterruptRequester timaIrq) { if (tac_ ^ data) { unsigned long nextIrqEventTime = timaIrq.nextIrqEventTime(); if (tac_ & 0x04) { updateIrq(cc, timaIrq); updateTima(cc); lastUpdate_ -= (1u << (timaClock[tac_ & 3] - 1)) + 3; tmatime_ -= (1u << (timaClock[tac_ & 3] - 1)) + 3; nextIrqEventTime -= (1u << (timaClock[tac_ & 3] - 1)) + 3; if (cc >= nextIrqEventTime) timaIrq.flagIrq(); updateTima(cc); tmatime_ = disabled_time; nextIrqEventTime = disabled_time; } if (data & 4) { lastUpdate_ = (cc >> timaClock[data & 3]) << timaClock[data & 3]; nextIrqEventTime = lastUpdate_ + ((256u - tima_) << timaClock[data & 3]) + 3; } timaIrq.setNextIrqEventTime(nextIrqEventTime); } tac_ = data; } unsigned Tima::tima(unsigned long cc) { if (tac_ & 0x04) updateTima(cc); return tima_; } void Tima::doIrqEvent(TimaInterruptRequester timaIrq) { timaIrq.flagIrq(); timaIrq.setNextIrqEventTime(timaIrq.nextIrqEventTime() + ((256u - tma_) << timaClock[tac_ & 3])); } } libgambatte/src/video/m0_irq.h000664 001750 001750 00000002334 12720365247 017424 0ustar00sergiosergio000000 000000 #ifndef M0_IRQ_H #define M0_IRQ_H #include "lcddef.h" #include "../savestate.h" namespace gambatte { class M0Irq { public: M0Irq() : statReg_(0) , lycReg_(0) { } void lcdReset(unsigned statReg, unsigned lycReg) { statReg_ = statReg; lycReg_ = lycReg; } void statRegChange(unsigned statReg, unsigned long nextM0IrqTime, unsigned long cc, bool cgb) { if (nextM0IrqTime - cc > cgb * 2U) statReg_ = statReg; } void lycRegChange(unsigned lycReg, unsigned long nextM0IrqTime, unsigned long cc, bool ds, bool cgb) { if (nextM0IrqTime - cc > cgb * 5 + 1U - ds) lycReg_ = lycReg; } void doEvent(unsigned char *ifreg, unsigned ly, unsigned statReg, unsigned lycReg) { if (((statReg_ | statReg) & lcdstat_m0irqen) && (!(statReg_ & lcdstat_lycirqen) || ly != lycReg_)) { *ifreg |= 2; } statReg_ = statReg; lycReg_ = lycReg; } void saveState(SaveState &state) const { state.ppu.m0lyc = lycReg_; } void loadState(SaveState const &state) { lycReg_ = state.ppu.m0lyc; statReg_ = state.mem.ioamhram.get()[0x141]; } unsigned statReg() const { return statReg_; } private: unsigned char statReg_; unsigned char lycReg_; }; } #endif libgambatte/src/cpu.cpp000664 001750 001750 00000127562 12720365247 016264 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "cpu.h" #include "gambatte-memory.h" #include "savestate.h" namespace gambatte { CPU::CPU() : mem_(Interrupter(sp, pc_)) , cycleCounter_(0) , pc_(0x100) , sp(0xFFFE) , hf1(0xF) , hf2(0xF) , zf(0) , cf(0x100) , a_(0x01) , b(0x00) , c(0x13) , d(0x00) , e(0xD8) , h(0x01) , l(0x4D) , skip_(false) { } long CPU::runFor(unsigned long const cycles) { process(cycles); long const csb = mem_.cyclesSinceBlit(cycleCounter_); if (cycleCounter_ & 0x80000000) cycleCounter_ = mem_.resetCounters(cycleCounter_); return csb; } enum { hf2_hcf = 0x200, hf2_subf = 0x400, hf2_incf = 0x800 }; static unsigned updateHf2FromHf1(unsigned const hf1, unsigned hf2) { unsigned lhs = hf1 & 0xF; unsigned rhs = (hf2 & 0xF) + (hf2 >> 8 & 1); if (hf2 & hf2_incf) { lhs = rhs; rhs = 1; } unsigned res = (hf2 & hf2_subf) ? lhs - rhs : (lhs + rhs) << 5; hf2 |= res & hf2_hcf; return hf2; } static inline unsigned toF(unsigned hf2, unsigned cf, unsigned zf) { return ((hf2 & (hf2_subf | hf2_hcf)) | (cf & 0x100)) >> 4 | ((zf & 0xFF) ? 0 : 0x80); } static inline unsigned zfFromF(unsigned f) { return ~f & 0x80; } static inline unsigned hf2FromF(unsigned f) { return f << 4 & (hf2_subf | hf2_hcf); } static inline unsigned cfFromF(unsigned f) { return f << 4 & 0x100; } void CPU::setStatePtrs(SaveState &state) { mem_.setStatePtrs(state); } void CPU::saveState(SaveState &state) { cycleCounter_ = mem_.saveState(state, cycleCounter_); hf2 = updateHf2FromHf1(hf1, hf2); state.cpu.cycleCounter = cycleCounter_; state.cpu.pc = pc_; state.cpu.sp = sp; state.cpu.a = a_; state.cpu.b = b; state.cpu.c = c; state.cpu.d = d; state.cpu.e = e; state.cpu.f = toF(hf2, cf, zf); state.cpu.h = h; state.cpu.l = l; state.cpu.skip = skip_; } void CPU::loadState(SaveState const &state) { mem_.loadState(state); cycleCounter_ = state.cpu.cycleCounter; pc_ = state.cpu.pc & 0xFFFF; sp = state.cpu.sp & 0xFFFF; a_ = state.cpu.a & 0xFF; b = state.cpu.b & 0xFF; c = state.cpu.c & 0xFF; d = state.cpu.d & 0xFF; e = state.cpu.e & 0xFF; zf = zfFromF(state.cpu.f); hf2 = hf2FromF(state.cpu.f); cf = cfFromF(state.cpu.f); h = state.cpu.h & 0xFF; l = state.cpu.l & 0xFF; skip_ = state.cpu.skip; } // The main reasons for the use of macros is to more conveniently be able to tweak // which variables are local and which are not, combined with the fact that at the // time they were written GCC had a tendency to not be able to keep hot variables // in regs if you took an address/reference in an inline function. #define bc() ( b << 8 | c ) #define de() ( d << 8 | e ) #define hl() ( h << 8 | l ) #define READ(dest, addr) do { (dest) = mem_.read(addr, cycleCounter); cycleCounter += 4; } while (0) #define PC_READ(dest) do { (dest) = mem_.read(pc, cycleCounter); pc = (pc + 1) & 0xFFFF; cycleCounter += 4; } while (0) #define FF_READ(dest, addr) do { (dest) = mem_.ff_read(addr, cycleCounter); cycleCounter += 4; } while (0) #define WRITE(addr, data) do { mem_.write(addr, data, cycleCounter); cycleCounter += 4; } while (0) #define FF_WRITE(addr, data) do { mem_.ff_write(addr, data, cycleCounter); cycleCounter += 4; } while (0) #define PC_MOD(data) do { pc = data; cycleCounter += 4; } while (0) #define PUSH(r1, r2) do { \ sp = (sp - 1) & 0xFFFF; \ WRITE(sp, (r1)); \ sp = (sp - 1) & 0xFFFF; \ WRITE(sp, (r2)); \ } while (0) // CB OPCODES (Shifts, rotates and bits): // swap r (8 cycles): // Swap upper and lower nibbles of 8-bit register, reset flags, check zero flag: #define swap_r(r) do { \ cf = hf2 = 0; \ zf = (r); \ (r) = (zf << 4 | zf >> 4) & 0xFF; \ } while (0) // rlc r (8 cycles): // Rotate 8-bit register left, store old bit7 in CF. Reset SF and HCF, Check ZF: #define rlc_r(r) do { \ cf = (r) << 1; \ zf = cf | cf >> 8; \ (r) = zf & 0xFF; \ hf2 = 0; \ } while (0) // rl r (8 cycles): // Rotate 8-bit register left through CF, store old bit7 in CF, old CF value becomes bit0. Reset SF and HCF, Check ZF: #define rl_r(r) do { \ unsigned const oldcf = cf >> 8 & 1; \ cf = (r) << 1; \ zf = cf | oldcf; \ (r) = zf & 0xFF; \ hf2 = 0; \ } while (0) // rrc r (8 cycles): // Rotate 8-bit register right, store old bit0 in CF. Reset SF and HCF, Check ZF: #define rrc_r(r) do { \ zf = (r); \ cf = zf << 8; \ (r) = (zf | cf) >> 1 & 0xFF; \ hf2 = 0; \ } while (0) // rr r (8 cycles): // Rotate 8-bit register right through CF, store old bit0 in CF, old CF value becomes bit7. Reset SF and HCF, Check ZF: #define rr_r(r) do { \ unsigned const oldcf = cf & 0x100; \ cf = (r) << 8; \ (r) = zf = ((r) | oldcf) >> 1; \ hf2 = 0; \ } while (0) // sla r (8 cycles): // Shift 8-bit register left, store old bit7 in CF. Reset SF and HCF, Check ZF: #define sla_r(r) do { \ zf = cf = (r) << 1; \ (r) = zf & 0xFF; \ hf2 = 0; \ } while (0) // sra r (8 cycles): // Shift 8-bit register right, store old bit0 in CF. bit7=old bit7. Reset SF and HCF, Check ZF: #define sra_r(r) do { \ cf = (r) << 8; \ zf = (r) >> 1; \ (r) = zf | ((r) & 0x80); \ hf2 = 0; \ } while (0) // srl r (8 cycles): // Shift 8-bit register right, store old bit0 in CF. Reset SF and HCF, Check ZF: #define srl_r(r) do { \ zf = (r); \ cf = (r) << 8; \ zf >>= 1; \ (r) = zf; \ hf2 = 0; \ } while (0) // bit n,r (8 cycles): // bit n,(hl) (12 cycles): // Test bitn in 8-bit value, check ZF, unset SF, set HCF: #define bitn_u8(bitmask, u8) do { \ zf = (u8) & (bitmask); \ hf2 = hf2_hcf; \ } while (0) #define bit0_u8(u8) bitn_u8(0x01, (u8)) #define bit1_u8(u8) bitn_u8(0x02, (u8)) #define bit2_u8(u8) bitn_u8(0x04, (u8)) #define bit3_u8(u8) bitn_u8(0x08, (u8)) #define bit4_u8(u8) bitn_u8(0x10, (u8)) #define bit5_u8(u8) bitn_u8(0x20, (u8)) #define bit6_u8(u8) bitn_u8(0x40, (u8)) #define bit7_u8(u8) bitn_u8(0x80, (u8)) // set n,r (8 cycles): // Set bitn of 8-bit register: #define set0_r(r) ( (r) |= 0x01 ) #define set1_r(r) ( (r) |= 0x02 ) #define set2_r(r) ( (r) |= 0x04 ) #define set3_r(r) ( (r) |= 0x08 ) #define set4_r(r) ( (r) |= 0x10 ) #define set5_r(r) ( (r) |= 0x20 ) #define set6_r(r) ( (r) |= 0x40 ) #define set7_r(r) ( (r) |= 0x80 ) // set n,(hl) (16 cycles): // Set bitn of value at address stored in HL: #define setn_mem_hl(n) do { \ unsigned const hl = hl(); \ unsigned val; \ READ(val, hl); \ val |= 1 << (n); \ WRITE(hl, val); \ } while (0) // res n,r (8 cycles): // Unset bitn of 8-bit register: #define res0_r(r) ( (r) &= 0xFE ) #define res1_r(r) ( (r) &= 0xFD ) #define res2_r(r) ( (r) &= 0xFB ) #define res3_r(r) ( (r) &= 0xF7 ) #define res4_r(r) ( (r) &= 0xEF ) #define res5_r(r) ( (r) &= 0xDF ) #define res6_r(r) ( (r) &= 0xBF ) #define res7_r(r) ( (r) &= 0x7F ) // res n,(hl) (16 cycles): // Unset bitn of value at address stored in HL: #define resn_mem_hl(n) do { \ unsigned const hl = hl(); \ unsigned val; \ READ(val, hl); \ val &= ~(1 << (n)); \ WRITE(hl, val); \ } while (0) // 16-BIT LOADS: // ld rr,nn (12 cycles) // set rr to 16-bit value of next 2 bytes in memory #define ld_rr_nn(r1, r2) do { \ PC_READ(r2); \ PC_READ(r1); \ } while (0) // push rr (16 cycles): // Push value of register pair onto stack: #define push_rr(r1, r2) do { \ PUSH(r1, r2); \ cycleCounter += 4; \ } while (0) // pop rr (12 cycles): // Pop two bytes off stack into register pair: #define pop_rr(r1, r2) do { \ READ(r2, sp); \ sp = (sp + 1) & 0xFFFF; \ READ(r1, sp); \ sp = (sp + 1) & 0xFFFF; \ } while (0) // 8-BIT ALU: // add a,r (4 cycles): // add a,(addr) (8 cycles): // Add 8-bit value to A, check flags: #define add_a_u8(u8) do { \ hf1 = a; \ hf2 = u8; \ zf = cf = a + hf2; \ a = zf & 0xFF; \ } while (0) // adc a,r (4 cycles): // adc a,(addr) (8 cycles): // Add 8-bit value+CF to A, check flags: #define adc_a_u8(u8) do { \ hf1 = a; \ hf2 = (cf & 0x100) | (u8); \ zf = cf = (cf >> 8 & 1) + (u8) + a; \ a = zf & 0xFF; \ } while (0) // sub a,r (4 cycles): // sub a,(addr) (8 cycles): // Subtract 8-bit value from A, check flags: #define sub_a_u8(u8) do { \ hf1 = a; \ hf2 = u8; \ zf = cf = a - hf2; \ a = zf & 0xFF; \ hf2 |= hf2_subf; \ } while (0) // sbc a,r (4 cycles): // sbc a,(addr) (8 cycles): // Subtract CF and 8-bit value from A, check flags: #define sbc_a_u8(u8) do { \ hf1 = a; \ hf2 = hf2_subf | (cf & 0x100) | (u8); \ zf = cf = a - ((cf >> 8) & 1) - (u8); \ a = zf & 0xFF; \ } while (0) // and a,r (4 cycles): // and a,(addr) (8 cycles): // bitwise and 8-bit value into A, check flags: #define and_a_u8(u8) do { \ hf2 = hf2_hcf; \ cf = 0; \ a &= (u8); \ zf = a; \ } while (0) // or a,r (4 cycles): // or a,(hl) (8 cycles): // bitwise or 8-bit value into A, check flags: #define or_a_u8(u8) do { \ cf = hf2 = 0; \ a |= (u8); \ zf = a; \ } while (0) // xor a,r (4 cycles): // xor a,(hl) (8 cycles): // bitwise xor 8-bit value into A, check flags: #define xor_a_u8(u8) do { \ cf = hf2 = 0; \ a ^= (u8); \ zf = a; \ } while (0) // cp a,r (4 cycles): // cp a,(addr) (8 cycles): // Compare (subtract without storing result) 8-bit value to A, check flags: #define cp_a_u8(u8) do { \ hf1 = a; \ hf2 = u8; \ zf = cf = a - hf2; \ hf2 |= hf2_subf; \ } while (0) // inc r (4 cycles): // Increment value of 8-bit register, check flags except CF: #define inc_r(r) do { \ hf2 = (r) | hf2_incf; \ zf = (r) + 1; \ (r) = zf & 0xFF; \ } while (0) // dec r (4 cycles): // Decrement value of 8-bit register, check flags except CF: #define dec_r(r) do { \ hf2 = (r) | hf2_incf | hf2_subf; \ zf = (r) - 1; \ (r) = zf & 0xFF; \ } while (0) // 16-BIT ARITHMETIC // add hl,rr (8 cycles): // add 16-bit register to HL, check flags except ZF: #define add_hl_rr(rh, rl) do { \ cf = l + (rl); \ l = cf & 0xFF; \ hf1 = h; \ hf2 = (cf & 0x100) | (rh); \ cf = h + (cf >> 8) + (rh); \ h = cf & 0xFF; \ cycleCounter += 4; \ } while (0) // inc rr (8 cycles): // Increment 16-bit register: #define inc_rr(rh, rl) do { \ unsigned const lowinc = (rl) + 1; \ (rl) = lowinc & 0xFF; \ (rh) = ((rh) + (lowinc >> 8)) & 0xFF; \ cycleCounter += 4; \ } while (0) // dec rr (8 cycles): // Decrement 16-bit register: #define dec_rr(rh, rl) do { \ unsigned const lowdec = (rl) - 1; \ (rl) = lowdec & 0xFF; \ (rh) = ((rh) - (lowdec >> 8 & 1)) & 0xFF; \ cycleCounter += 4; \ } while (0) #define sp_plus_n(sumout) do { \ unsigned disp; \ PC_READ(disp); \ disp = (disp ^ 0x80) - 0x80; \ \ unsigned const res = sp + disp; \ cf = sp ^ disp ^ res; \ hf2 = cf << 5 & hf2_hcf; \ zf = 1; \ cycleCounter += 4; \ (sumout) = res & 0xFFFF; \ } while (0) // JUMPS: // jp nn (16 cycles): // Jump to address stored in the next two bytes in memory: #define jp_nn() do { \ unsigned imm0, imm1; \ PC_READ(imm0); \ PC_READ(imm1); \ PC_MOD(imm1 << 8 | imm0); \ } while (0) // jr disp (12 cycles): // Jump to value of next (signed) byte in memory+current address: #define jr_disp() do { \ unsigned disp; \ PC_READ(disp); \ disp = (disp ^ 0x80) - 0x80; \ PC_MOD((pc + disp) & 0xFFFF); \ } while (0) // CALLS, RESTARTS AND RETURNS: // call nn (24 cycles): // Jump to 16-bit immediate operand and push return address onto stack: #define call_nn() do { \ unsigned const npc = (pc + 2) & 0xFFFF; \ jp_nn(); \ PUSH(npc >> 8, npc & 0xFF); \ } while (0) // rst n (16 Cycles): // Push present address onto stack, jump to address n (one of 00h,08h,10h,18h,20h,28h,30h,38h): #define rst_n(n) do { \ PUSH(pc >> 8, pc & 0xFF); \ PC_MOD(n); \ } while (0) // ret (16 cycles): // Pop two bytes from the stack and jump to that address: #define ret() do { \ unsigned low, high; \ pop_rr(high, low); \ PC_MOD(high << 8 | low); \ } while (0) void CPU::process(unsigned long const cycles) { mem_.setEndtime(cycleCounter_, cycles); mem_.updateInput(); unsigned char a = a_; unsigned long cycleCounter = cycleCounter_; while (mem_.isActive()) { unsigned short pc = pc_; if (mem_.halted()) { if (cycleCounter < mem_.nextEventTime()) { unsigned long cycles = mem_.nextEventTime() - cycleCounter; cycleCounter += cycles + (-cycles & 3); } } else while (cycleCounter < mem_.nextEventTime()) { unsigned char opcode; PC_READ(opcode); if (skip_) { pc = (pc - 1) & 0xFFFF; skip_ = false; } switch (opcode) { case 0x00: break; case 0x01: ld_rr_nn(b, c); break; case 0x02: WRITE(bc(), a); break; case 0x03: inc_rr(b, c); break; case 0x04: inc_r(b); break; case 0x05: dec_r(b); break; case 0x06: PC_READ(b); break; // rlca (4 cycles): // Rotate 8-bit register A left, store old bit7 in CF. Reset SF, HCF, ZF: case 0x07: cf = a << 1; a = (cf | cf >> 8) & 0xFF; hf2 = 0; zf = 1; break; // ld (nn),SP (20 cycles): // Put value of SP into address given by next 2 bytes in memory: case 0x08: { unsigned imml, immh; PC_READ(imml); PC_READ(immh); unsigned const addr = immh << 8 | imml; WRITE(addr, sp & 0xFF); WRITE((addr + 1) & 0xFFFF, sp >> 8); } break; case 0x09: add_hl_rr(b, c); break; case 0x0A: READ(a, bc()); break; case 0x0B: dec_rr(b, c); break; case 0x0C: inc_r(c); break; case 0x0D: dec_r(c); break; case 0x0E: PC_READ(c); break; // rrca (4 cycles): // Rotate 8-bit register A right, store old bit0 in CF. Reset SF, HCF, ZF: case 0x0F: cf = a << 8 | a; a = cf >> 1 & 0xFF; hf2 = 0; zf = 1; break; // stop (4 cycles): // Halt CPU and LCD display until button pressed: case 0x10: pc = (pc + 1) & 0xFFFF; cycleCounter = mem_.stop(cycleCounter); if (cycleCounter < mem_.nextEventTime()) { unsigned long cycles = mem_.nextEventTime() - cycleCounter; cycleCounter += cycles + (-cycles & 3); } break; case 0x11: ld_rr_nn(d, e); break; case 0x12: WRITE(de(), a); break; case 0x13: inc_rr(d, e); break; case 0x14: inc_r(d); break; case 0x15: dec_r(d); break; case 0x16: PC_READ(d); break; // rla (4 cycles): // Rotate 8-bit register A left through CF, store old bit7 in CF, // old CF value becomes bit0. Reset SF, HCF, ZF: case 0x17: { unsigned oldcf = cf >> 8 & 1; cf = a << 1; a = (cf | oldcf) & 0xFF; } hf2 = 0; zf = 1; break; case 0x18: jr_disp(); break; case 0x19: add_hl_rr(d, e); break; case 0x1A: READ(a, de()); break; case 0x1B: dec_rr(d, e); break; case 0x1C: inc_r(e); break; case 0x1D: dec_r(e); break; case 0x1E: PC_READ(e); break; // rra (4 cycles): // Rotate 8-bit register A right through CF, store old bit0 in CF, // old CF value becomes bit7. Reset SF, HCF, ZF: case 0x1F: { unsigned oldcf = cf & 0x100; cf = a << 8; a = (a | oldcf) >> 1; } hf2 = 0; zf = 1; break; // jr nz,disp (12;8 cycles): // Jump to value of next (signed) byte in memory+current address if ZF is unset: case 0x20: if (zf & 0xFF) { jr_disp(); } else { PC_MOD((pc + 1) & 0xFFFF); } break; case 0x21: ld_rr_nn(h, l); break; // ldi (hl),a (8 cycles): // Put A into memory address in hl. Increment HL: case 0x22: { unsigned addr = hl(); WRITE(addr, a); addr = (addr + 1) & 0xFFFF; l = addr; h = addr >> 8; } break; case 0x23: inc_rr(h, l); break; case 0x24: inc_r(h); break; case 0x25: dec_r(h); break; case 0x26: PC_READ(h); break; // daa (4 cycles): // Adjust register A to correctly represent a BCD. Check ZF, HF and CF: case 0x27: hf2 = updateHf2FromHf1(hf1, hf2); { unsigned correction = (cf & 0x100) ? 0x60 : 0x00; if (hf2 & hf2_hcf) correction |= 0x06; if (!(hf2 &= hf2_subf)) { if ((a & 0x0F) > 0x09) correction |= 0x06; if (a > 0x99) correction |= 0x60; a += correction; } else a -= correction; cf = correction << 2 & 0x100; zf = a; a &= 0xFF; } break; // jr z,disp (12;8 cycles): // Jump to value of next (signed) byte in memory+current address if ZF is set: case 0x28: if (zf & 0xFF) { PC_MOD((pc + 1) & 0xFFFF); } else { jr_disp(); } break; case 0x29: add_hl_rr(h, l); break; // ldi a,(hl) (8 cycles): // Put value at address in hl into A. Increment HL: case 0x2A: { unsigned addr = hl(); READ(a, addr); addr = (addr + 1) & 0xFFFF; l = addr; h = addr >> 8; } break; case 0x2B: dec_rr(h, l); break; case 0x2C: inc_r(l); break; case 0x2D: dec_r(l); break; case 0x2E: PC_READ(l); break; // cpl (4 cycles): // Complement register A. (Flip all bits), set SF and HCF: case 0x2F: hf2 = hf2_subf | hf2_hcf; a ^= 0xFF; break; // jr nc,disp (12;8 cycles): // Jump to value of next (signed) byte in memory+current address if CF is unset: case 0x30: if (cf & 0x100) { PC_MOD((pc + 1) & 0xFFFF); } else { jr_disp(); } break; // ld sp,nn (12 cycles) // set sp to 16-bit value of next 2 bytes in memory case 0x31: { unsigned imml, immh; PC_READ(imml); PC_READ(immh); sp = immh << 8 | imml; } break; // ldd (hl),a (8 cycles): // Put A into memory address in hl. Decrement HL: case 0x32: { unsigned addr = hl(); WRITE(addr, a); addr = (addr - 1) & 0xFFFF; l = addr; h = addr >> 8; } break; case 0x33: sp = (sp + 1) & 0xFFFF; cycleCounter += 4; break; // inc (hl) (12 cycles): // Increment value at address in hl, check flags except CF: case 0x34: { unsigned const addr = hl(); READ(hf2, addr); zf = hf2 + 1; WRITE(addr, zf & 0xFF); hf2 |= hf2_incf; } break; // dec (hl) (12 cycles): // Decrement value at address in hl, check flags except CF: case 0x35: { unsigned const addr = hl(); READ(hf2, addr); zf = hf2 - 1; WRITE(addr, zf & 0xFF); hf2 |= hf2_incf | hf2_subf; } break; // ld (hl),n (12 cycles): // set memory at address in hl to value of next byte in memory: case 0x36: { unsigned imm; PC_READ(imm); WRITE(hl(), imm); } break; // scf (4 cycles): // Set CF. Unset SF and HCF: case 0x37: cf = 0x100; hf2 = 0; break; // jr c,disp (12;8 cycles): // Jump to value of next (signed) byte in memory+current address if CF is set: case 0x38: if (cf & 0x100) { jr_disp(); } else { PC_MOD((pc + 1) & 0xFFFF); } break; // add hl,sp (8 cycles): // add SP to HL, check flags except ZF: case 0x39: cf = l + sp; l = cf & 0xFF; hf1 = h; hf2 = ((cf ^ sp) & 0x100) | sp >> 8; cf >>= 8; cf += h; h = cf & 0xFF; cycleCounter += 4; break; // ldd a,(hl) (8 cycles): // Put value at address in hl into A. Decrement HL: case 0x3A: { unsigned addr = hl(); a = mem_.read(addr, cycleCounter); cycleCounter += 4; addr = (addr - 1) & 0xFFFF; l = addr; h = addr >> 8; } break; case 0x3B: sp = (sp - 1) & 0xFFFF; cycleCounter += 4; break; case 0x3C: inc_r(a); break; case 0x3D: dec_r(a); break; case 0x3E: PC_READ(a); break; // ccf (4 cycles): // Complement CF (unset if set vv.) Unset SF and HCF. case 0x3F: cf ^= 0x100; hf2 = 0; break; case 0x40: /*b = b;*/ break; case 0x41: b = c; break; case 0x42: b = d; break; case 0x43: b = e; break; case 0x44: b = h; break; case 0x45: b = l; break; case 0x46: READ(b, hl()); break; case 0x47: b = a; break; case 0x48: c = b; break; case 0x49: /*c = c;*/ break; case 0x4A: c = d; break; case 0x4B: c = e; break; case 0x4C: c = h; break; case 0x4D: c = l; break; case 0x4E: READ(c, hl()); break; case 0x4F: c = a; break; case 0x50: d = b; break; case 0x51: d = c; break; case 0x52: /*d = d;*/ break; case 0x53: d = e; break; case 0x54: d = h; break; case 0x55: d = l; break; case 0x56: READ(d, hl()); break; case 0x57: d = a; break; case 0x58: e = b; break; case 0x59: e = c; break; case 0x5A: e = d; break; case 0x5B: /*e = e;*/ break; case 0x5C: e = h; break; case 0x5D: e = l; break; case 0x5E: READ(e, hl()); break; case 0x5F: e = a; break; case 0x60: h = b; break; case 0x61: h = c; break; case 0x62: h = d; break; case 0x63: h = e; break; case 0x64: /*h = h;*/ break; case 0x65: h = l; break; case 0x66: READ(h, hl()); break; case 0x67: h = a; break; case 0x68: l = b; break; case 0x69: l = c; break; case 0x6A: l = d; break; case 0x6B: l = e; break; case 0x6C: l = h; break; case 0x6D: /*l = l;*/ break; case 0x6E: READ(l, hl()); break; case 0x6F: l = a; break; case 0x70: WRITE(hl(), b); break; case 0x71: WRITE(hl(), c); break; case 0x72: WRITE(hl(), d); break; case 0x73: WRITE(hl(), e); break; case 0x74: WRITE(hl(), h); break; case 0x75: WRITE(hl(), l); break; // halt (4 cycles): case 0x76: if (!mem_.ime() && ( mem_.ff_read(0x0F, cycleCounter) & mem_.ff_read(0xFF, cycleCounter) & 0x1F)) { if (mem_.isCgb()) cycleCounter += 4; else skip_ = true; } else { mem_.halt(); if (cycleCounter < mem_.nextEventTime()) { unsigned long cycles = mem_.nextEventTime() - cycleCounter; cycleCounter += cycles + (-cycles & 3); } } break; case 0x77: WRITE(hl(), a); break; case 0x78: a = b; break; case 0x79: a = c; break; case 0x7A: a = d; break; case 0x7B: a = e; break; case 0x7C: a = h; break; case 0x7D: a = l; break; case 0x7E: READ(a, hl()); break; case 0x7F: /*a = a;*/ break; case 0x80: add_a_u8(b); break; case 0x81: add_a_u8(c); break; case 0x82: add_a_u8(d); break; case 0x83: add_a_u8(e); break; case 0x84: add_a_u8(h); break; case 0x85: add_a_u8(l); break; case 0x86: { unsigned data; READ(data, hl()); add_a_u8(data); } break; case 0x87: add_a_u8(a); break; case 0x88: adc_a_u8(b); break; case 0x89: adc_a_u8(c); break; case 0x8A: adc_a_u8(d); break; case 0x8B: adc_a_u8(e); break; case 0x8C: adc_a_u8(h); break; case 0x8D: adc_a_u8(l); break; case 0x8E: { unsigned data; READ(data, hl()); adc_a_u8(data); } break; case 0x8F: adc_a_u8(a); break; case 0x90: sub_a_u8(b); break; case 0x91: sub_a_u8(c); break; case 0x92: sub_a_u8(d); break; case 0x93: sub_a_u8(e); break; case 0x94: sub_a_u8(h); break; case 0x95: sub_a_u8(l); break; case 0x96: { unsigned data; READ(data, hl()); sub_a_u8(data); } break; // A-A is always 0: case 0x97: hf2 = hf2_subf; cf = zf = a = 0; break; case 0x98: sbc_a_u8(b); break; case 0x99: sbc_a_u8(c); break; case 0x9A: sbc_a_u8(d); break; case 0x9B: sbc_a_u8(e); break; case 0x9C: sbc_a_u8(h); break; case 0x9D: sbc_a_u8(l); break; case 0x9E: { unsigned data; READ(data, hl()); sbc_a_u8(data); } break; case 0x9F: sbc_a_u8(a); break; case 0xA0: and_a_u8(b); break; case 0xA1: and_a_u8(c); break; case 0xA2: and_a_u8(d); break; case 0xA3: and_a_u8(e); break; case 0xA4: and_a_u8(h); break; case 0xA5: and_a_u8(l); break; case 0xA6: { unsigned data; READ(data, hl()); and_a_u8(data); } break; // A&A will always be A: case 0xA7: zf = a; cf = 0; hf2 = hf2_hcf; break; case 0xA8: xor_a_u8(b); break; case 0xA9: xor_a_u8(c); break; case 0xAA: xor_a_u8(d); break; case 0xAB: xor_a_u8(e); break; case 0xAC: xor_a_u8(h); break; case 0xAD: xor_a_u8(l); break; case 0xAE: { unsigned data; READ(data, hl()); xor_a_u8(data); } break; // A^A will always be 0: case 0xAF: cf = hf2 = zf = a = 0; break; case 0xB0: or_a_u8(b); break; case 0xB1: or_a_u8(c); break; case 0xB2: or_a_u8(d); break; case 0xB3: or_a_u8(e); break; case 0xB4: or_a_u8(h); break; case 0xB5: or_a_u8(l); break; case 0xB6: { unsigned data; READ(data, hl()); or_a_u8(data); } break; // A|A will always be A: case 0xB7: zf = a; hf2 = cf = 0; break; case 0xB8: cp_a_u8(b); break; case 0xB9: cp_a_u8(c); break; case 0xBA: cp_a_u8(d); break; case 0xBB: cp_a_u8(e); break; case 0xBC: cp_a_u8(h); break; case 0xBD: cp_a_u8(l); break; case 0xBE: { unsigned data; READ(data, hl()); cp_a_u8(data); } break; // A always equals A: case 0xBF: cf = zf = 0; hf2 = hf2_subf; break; // ret nz (20;8 cycles): // Pop two bytes from the stack and jump to that address, if ZF is unset: case 0xC0: cycleCounter += 4; if (zf & 0xFF) ret(); break; case 0xC1: pop_rr(b, c); break; // jp nz,nn (16;12 cycles): // Jump to address stored in next two bytes in memory if ZF is unset: case 0xC2: if (zf & 0xFF) { jp_nn(); } else { PC_MOD((pc + 2) & 0xFFFF); cycleCounter += 4; } break; case 0xC3: jp_nn(); break; // call nz,nn (24;12 cycles): // Push address of next instruction onto stack and then jump to // address stored in next two bytes in memory, if ZF is unset: case 0xC4: if (zf & 0xFF) { call_nn(); } else { PC_MOD((pc + 2) & 0xFFFF); cycleCounter += 4; } break; case 0xC5: push_rr(b, c); break; case 0xC6: { unsigned data; PC_READ(data); add_a_u8(data); } break; case 0xC7: rst_n(0x00); break; // ret z (20;8 cycles): // Pop two bytes from the stack and jump to that address, if ZF is set: case 0xC8: cycleCounter += 4; if (!(zf & 0xFF)) ret(); break; // ret (16 cycles): // Pop two bytes from the stack and jump to that address: case 0xC9: ret(); break; // jp z,nn (16;12 cycles): // Jump to address stored in next two bytes in memory if ZF is set: case 0xCA: if (zf & 0xFF) { PC_MOD((pc + 2) & 0xFFFF); cycleCounter += 4; } else { jp_nn(); } break; // CB OPCODES (Shifts, rotates and bits): case 0xCB: PC_READ(opcode); switch (opcode) { case 0x00: rlc_r(b); break; case 0x01: rlc_r(c); break; case 0x02: rlc_r(d); break; case 0x03: rlc_r(e); break; case 0x04: rlc_r(h); break; case 0x05: rlc_r(l); break; // rlc (hl) (16 cycles): // Rotate 8-bit value stored at address in HL left, store old bit7 in CF. // Reset SF and HCF. Check ZF: case 0x06: { unsigned const addr = hl(); READ(cf, addr); cf <<= 1; zf = cf | (cf >> 8); WRITE(addr, zf & 0xFF); hf2 = 0; } break; case 0x07: rlc_r(a); break; case 0x08: rrc_r(b); break; case 0x09: rrc_r(c); break; case 0x0A: rrc_r(d); break; case 0x0B: rrc_r(e); break; case 0x0C: rrc_r(h); break; case 0x0D: rrc_r(l); break; // rrc (hl) (16 cycles): // Rotate 8-bit value stored at address in HL right, store old bit0 in CF. // Reset SF and HCF. Check ZF: case 0x0E: { unsigned const addr = hl(); READ(zf, addr); cf = zf << 8; WRITE(addr, (zf | cf) >> 1 & 0xFF); hf2 = 0; } break; case 0x0F: rrc_r(a); break; case 0x10: rl_r(b); break; case 0x11: rl_r(c); break; case 0x12: rl_r(d); break; case 0x13: rl_r(e); break; case 0x14: rl_r(h); break; case 0x15: rl_r(l); break; // rl (hl) (16 cycles): // Rotate 8-bit value stored at address in HL left thorugh CF, // store old bit7 in CF, old CF value becoms bit0. Reset SF and HCF. Check ZF: case 0x16: { unsigned const addr = hl(); unsigned const oldcf = cf >> 8 & 1; READ(cf, addr); cf <<= 1; zf = cf | oldcf; WRITE(addr, zf & 0xFF); hf2 = 0; } break; case 0x17: rl_r(a); break; case 0x18: rr_r(b); break; case 0x19: rr_r(c); break; case 0x1A: rr_r(d); break; case 0x1B: rr_r(e); break; case 0x1C: rr_r(h); break; case 0x1D: rr_r(l); break; // rr (hl) (16 cycles): // Rotate 8-bit value stored at address in HL right thorugh CF, // store old bit0 in CF, old CF value becoms bit7. Reset SF and HCF. Check ZF: case 0x1E: { unsigned const addr = hl(); READ(zf, addr); unsigned const oldcf = cf & 0x100; cf = zf << 8; zf = (zf | oldcf) >> 1; WRITE(addr, zf); hf2 = 0; } break; case 0x1F: rr_r(a); break; case 0x20: sla_r(b); break; case 0x21: sla_r(c); break; case 0x22: sla_r(d); break; case 0x23: sla_r(e); break; case 0x24: sla_r(h); break; case 0x25: sla_r(l); break; // sla (hl) (16 cycles): // Shift 8-bit value stored at address in HL left, store old bit7 in CF. // Reset SF and HCF. Check ZF: case 0x26: { unsigned const addr = hl(); READ(cf, addr); cf <<= 1; zf = cf; WRITE(addr, zf & 0xFF); hf2 = 0; } break; case 0x27: sla_r(a); break; case 0x28: sra_r(b); break; case 0x29: sra_r(c); break; case 0x2A: sra_r(d); break; case 0x2B: sra_r(e); break; case 0x2C: sra_r(h); break; case 0x2D: sra_r(l); break; // sra (hl) (16 cycles): // Shift 8-bit value stored at address in HL right, store old bit0 in CF, // bit7=old bit7. Reset SF and HCF. Check ZF: case 0x2E: { unsigned const addr = hl(); READ(cf, addr); zf = cf >> 1; WRITE(addr, zf | (cf & 0x80)); cf <<= 8; hf2 = 0; } break; case 0x2F: sra_r(a); break; case 0x30: swap_r(b); break; case 0x31: swap_r(c); break; case 0x32: swap_r(d); break; case 0x33: swap_r(e); break; case 0x34: swap_r(h); break; case 0x35: swap_r(l); break; // swap (hl) (16 cycles): // Swap upper and lower nibbles of 8-bit value stored at address in HL, // reset flags, check zero flag: case 0x36: { unsigned const addr = hl(); READ(zf, addr); WRITE(addr, (zf << 4 | zf >> 4) & 0xFF); cf = hf2 = 0; } break; case 0x37: swap_r(a); break; case 0x38: srl_r(b); break; case 0x39: srl_r(c); break; case 0x3A: srl_r(d); break; case 0x3B: srl_r(e); break; case 0x3C: srl_r(h); break; case 0x3D: srl_r(l); break; // srl (hl) (16 cycles): // Shift 8-bit value stored at address in HL right, // store old bit0 in CF. Reset SF and HCF. Check ZF: case 0x3E: { unsigned const addr = hl(); READ(cf, addr); zf = cf >> 1; WRITE(addr, zf); cf <<= 8; hf2 = 0; } break; case 0x3F: srl_r(a); break; case 0x40: bit0_u8(b); break; case 0x41: bit0_u8(c); break; case 0x42: bit0_u8(d); break; case 0x43: bit0_u8(e); break; case 0x44: bit0_u8(h); break; case 0x45: bit0_u8(l); break; case 0x46: { unsigned data; READ(data, hl()); bit0_u8(data); } break; case 0x47: bit0_u8(a); break; case 0x48: bit1_u8(b); break; case 0x49: bit1_u8(c); break; case 0x4A: bit1_u8(d); break; case 0x4B: bit1_u8(e); break; case 0x4C: bit1_u8(h); break; case 0x4D: bit1_u8(l); break; case 0x4E: { unsigned data; READ(data, hl()); bit1_u8(data); } break; case 0x4F: bit1_u8(a); break; case 0x50: bit2_u8(b); break; case 0x51: bit2_u8(c); break; case 0x52: bit2_u8(d); break; case 0x53: bit2_u8(e); break; case 0x54: bit2_u8(h); break; case 0x55: bit2_u8(l); break; case 0x56: { unsigned data; READ(data, hl()); bit2_u8(data); } break; case 0x57: bit2_u8(a); break; case 0x58: bit3_u8(b); break; case 0x59: bit3_u8(c); break; case 0x5A: bit3_u8(d); break; case 0x5B: bit3_u8(e); break; case 0x5C: bit3_u8(h); break; case 0x5D: bit3_u8(l); break; case 0x5E: { unsigned data; READ(data, hl()); bit3_u8(data); } break; case 0x5F: bit3_u8(a); break; case 0x60: bit4_u8(b); break; case 0x61: bit4_u8(c); break; case 0x62: bit4_u8(d); break; case 0x63: bit4_u8(e); break; case 0x64: bit4_u8(h); break; case 0x65: bit4_u8(l); break; case 0x66: { unsigned data; READ(data, hl()); bit4_u8(data); } break; case 0x67: bit4_u8(a); break; case 0x68: bit5_u8(b); break; case 0x69: bit5_u8(c); break; case 0x6A: bit5_u8(d); break; case 0x6B: bit5_u8(e); break; case 0x6C: bit5_u8(h); break; case 0x6D: bit5_u8(l); break; case 0x6E: { unsigned data; READ(data, hl()); bit5_u8(data); } break; case 0x6F: bit5_u8(a); break; case 0x70: bit6_u8(b); break; case 0x71: bit6_u8(c); break; case 0x72: bit6_u8(d); break; case 0x73: bit6_u8(e); break; case 0x74: bit6_u8(h); break; case 0x75: bit6_u8(l); break; case 0x76: { unsigned data; READ(data, hl()); bit6_u8(data); } break; case 0x77: bit6_u8(a); break; case 0x78: bit7_u8(b); break; case 0x79: bit7_u8(c); break; case 0x7A: bit7_u8(d); break; case 0x7B: bit7_u8(e); break; case 0x7C: bit7_u8(h); break; case 0x7D: bit7_u8(l); break; case 0x7E: { unsigned data; READ(data, hl()); bit7_u8(data); } break; case 0x7F: bit7_u8(a); break; case 0x80: res0_r(b); break; case 0x81: res0_r(c); break; case 0x82: res0_r(d); break; case 0x83: res0_r(e); break; case 0x84: res0_r(h); break; case 0x85: res0_r(l); break; case 0x86: resn_mem_hl(0); break; case 0x87: res0_r(a); break; case 0x88: res1_r(b); break; case 0x89: res1_r(c); break; case 0x8A: res1_r(d); break; case 0x8B: res1_r(e); break; case 0x8C: res1_r(h); break; case 0x8D: res1_r(l); break; case 0x8E: resn_mem_hl(1); break; case 0x8F: res1_r(a); break; case 0x90: res2_r(b); break; case 0x91: res2_r(c); break; case 0x92: res2_r(d); break; case 0x93: res2_r(e); break; case 0x94: res2_r(h); break; case 0x95: res2_r(l); break; case 0x96: resn_mem_hl(2); break; case 0x97: res2_r(a); break; case 0x98: res3_r(b); break; case 0x99: res3_r(c); break; case 0x9A: res3_r(d); break; case 0x9B: res3_r(e); break; case 0x9C: res3_r(h); break; case 0x9D: res3_r(l); break; case 0x9E: resn_mem_hl(3); break; case 0x9F: res3_r(a); break; case 0xA0: res4_r(b); break; case 0xA1: res4_r(c); break; case 0xA2: res4_r(d); break; case 0xA3: res4_r(e); break; case 0xA4: res4_r(h); break; case 0xA5: res4_r(l); break; case 0xA6: resn_mem_hl(4); break; case 0xA7: res4_r(a); break; case 0xA8: res5_r(b); break; case 0xA9: res5_r(c); break; case 0xAA: res5_r(d); break; case 0xAB: res5_r(e); break; case 0xAC: res5_r(h); break; case 0xAD: res5_r(l); break; case 0xAE: resn_mem_hl(5); break; case 0xAF: res5_r(a); break; case 0xB0: res6_r(b); break; case 0xB1: res6_r(c); break; case 0xB2: res6_r(d); break; case 0xB3: res6_r(e); break; case 0xB4: res6_r(h); break; case 0xB5: res6_r(l); break; case 0xB6: resn_mem_hl(6); break; case 0xB7: res6_r(a); break; case 0xB8: res7_r(b); break; case 0xB9: res7_r(c); break; case 0xBA: res7_r(d); break; case 0xBB: res7_r(e); break; case 0xBC: res7_r(h); break; case 0xBD: res7_r(l); break; case 0xBE: resn_mem_hl(7); break; case 0xBF: res7_r(a); break; case 0xC0: set0_r(b); break; case 0xC1: set0_r(c); break; case 0xC2: set0_r(d); break; case 0xC3: set0_r(e); break; case 0xC4: set0_r(h); break; case 0xC5: set0_r(l); break; case 0xC6: setn_mem_hl(0); break; case 0xC7: set0_r(a); break; case 0xC8: set1_r(b); break; case 0xC9: set1_r(c); break; case 0xCA: set1_r(d); break; case 0xCB: set1_r(e); break; case 0xCC: set1_r(h); break; case 0xCD: set1_r(l); break; case 0xCE: setn_mem_hl(1); break; case 0xCF: set1_r(a); break; case 0xD0: set2_r(b); break; case 0xD1: set2_r(c); break; case 0xD2: set2_r(d); break; case 0xD3: set2_r(e); break; case 0xD4: set2_r(h); break; case 0xD5: set2_r(l); break; case 0xD6: setn_mem_hl(2); break; case 0xD7: set2_r(a); break; case 0xD8: set3_r(b); break; case 0xD9: set3_r(c); break; case 0xDA: set3_r(d); break; case 0xDB: set3_r(e); break; case 0xDC: set3_r(h); break; case 0xDD: set3_r(l); break; case 0xDE: setn_mem_hl(3); break; case 0xDF: set3_r(a); break; case 0xE0: set4_r(b); break; case 0xE1: set4_r(c); break; case 0xE2: set4_r(d); break; case 0xE3: set4_r(e); break; case 0xE4: set4_r(h); break; case 0xE5: set4_r(l); break; case 0xE6: setn_mem_hl(4); break; case 0xE7: set4_r(a); break; case 0xE8: set5_r(b); break; case 0xE9: set5_r(c); break; case 0xEA: set5_r(d); break; case 0xEB: set5_r(e); break; case 0xEC: set5_r(h); break; case 0xED: set5_r(l); break; case 0xEE: setn_mem_hl(5); break; case 0xEF: set5_r(a); break; case 0xF0: set6_r(b); break; case 0xF1: set6_r(c); break; case 0xF2: set6_r(d); break; case 0xF3: set6_r(e); break; case 0xF4: set6_r(h); break; case 0xF5: set6_r(l); break; case 0xF6: setn_mem_hl(6); break; case 0xF7: set6_r(a); break; case 0xF8: set7_r(b); break; case 0xF9: set7_r(c); break; case 0xFA: set7_r(d); break; case 0xFB: set7_r(e); break; case 0xFC: set7_r(h); break; case 0xFD: set7_r(l); break; case 0xFE: setn_mem_hl(7); break; case 0xFF: set7_r(a); break; } break; // call z,nn (24;12 cycles): // Push address of next instruction onto stack and then jump to // address stored in next two bytes in memory, if ZF is set: case 0xCC: if (zf & 0xFF) { PC_MOD((pc + 2) & 0xFFFF); cycleCounter += 4; } else { call_nn(); } break; case 0xCD: call_nn(); break; case 0xCE: { unsigned data; PC_READ(data); adc_a_u8(data); } break; case 0xCF: rst_n(0x08); break; // ret nc (20;8 cycles): // Pop two bytes from the stack and jump to that address, if CF is unset: case 0xD0: cycleCounter += 4; if (!(cf & 0x100)) ret(); break; case 0xD1: pop_rr(d, e); break; // jp nc,nn (16;12 cycles): // Jump to address stored in next two bytes in memory if CF is unset: case 0xD2: if (cf & 0x100) { PC_MOD((pc + 2) & 0xFFFF); cycleCounter += 4; } else { jp_nn(); } break; case 0xD3: // not specified. should freeze. break; // call nc,nn (24;12 cycles): // Push address of next instruction onto stack and then jump to // address stored in next two bytes in memory, if CF is unset: case 0xD4: if (cf & 0x100) { PC_MOD((pc + 2) & 0xFFFF); cycleCounter += 4; } else { call_nn(); } break; case 0xD5: push_rr(d, e); break; case 0xD6: { unsigned data; PC_READ(data); sub_a_u8(data); } break; case 0xD7: rst_n(0x10); break; // ret c (20;8 cycles): // Pop two bytes from the stack and jump to that address, if CF is set: case 0xD8: cycleCounter += 4; if (cf & 0x100) ret(); break; // reti (16 cycles): // Pop two bytes from the stack and jump to that address, then enable interrupts: case 0xD9: { unsigned sl, sh; pop_rr(sh, sl); mem_.ei(cycleCounter); PC_MOD(sh << 8 | sl); } break; // jp c,nn (16;12 cycles): // Jump to address stored in next two bytes in memory if CF is set: case 0xDA: if (cf & 0x100) { jp_nn(); } else { PC_MOD((pc + 2) & 0xFFFF); cycleCounter += 4; } break; case 0xDB: // not specified. should freeze. break; // call z,nn (24;12 cycles): // Push address of next instruction onto stack and then jump to // address stored in next two bytes in memory, if CF is set: case 0xDC: if (cf & 0x100) { call_nn(); } else { PC_MOD((pc + 2) & 0xFFFF); cycleCounter += 4; } break; case 0xDE: { unsigned data; PC_READ(data); sbc_a_u8(data); } break; case 0xDF: rst_n(0x18); break; // ld ($FF00+n),a (12 cycles): // Put value in A into address (0xFF00 + next byte in memory): case 0xE0: { unsigned imm; PC_READ(imm); FF_WRITE(imm, a); } break; case 0xE1: pop_rr(h, l); break; // ld ($FF00+C),a (8 ycles): // Put A into address (0xFF00 + register C): case 0xE2: FF_WRITE(c, a); break; case 0xE3: // not specified. should freeze. break; case 0xE4: // not specified. should freeze. break; case 0xE5: push_rr(h, l); break; case 0xE6: { unsigned data; PC_READ(data); and_a_u8(data); } break; case 0xE7: rst_n(0x20); break; // add sp,n (16 cycles): // Add next (signed) byte in memory to SP, reset ZF and SF, check HCF and CF: case 0xE8: sp_plus_n(sp); cycleCounter += 4; break; // jp hl (4 cycles): // Jump to address in hl: case 0xE9: pc = hl(); break; // ld (nn),a (16 cycles): // set memory at address given by the next 2 bytes to value in A: // Incrementing PC before call, because of possible interrupt. case 0xEA: { unsigned imml, immh; PC_READ(imml); PC_READ(immh); WRITE(immh << 8 | imml, a); } break; case 0xEB: // not specified. should freeze. break; case 0xEC: // not specified. should freeze. break; case 0xED: // not specified. should freeze. break; case 0xEE: { unsigned data; PC_READ(data); xor_a_u8(data); } break; case 0xEF: rst_n(0x28); break; // ld a,($FF00+n) (12 cycles): // Put value at address (0xFF00 + next byte in memory) into A: case 0xF0: { unsigned imm; PC_READ(imm); FF_READ(a, imm); } break; case 0xF1: { unsigned F; pop_rr(a, F); zf = zfFromF(F); hf2 = hf2FromF(F); cf = cfFromF(F); } break; // ld a,($FF00+C) (8 cycles): // Put value at address (0xFF00 + register C) into A: case 0xF2: FF_READ(a, c); break; // di (4 cycles): case 0xF3: mem_.di(); break; case 0xF4: // not specified. should freeze. break; case 0xF5: hf2 = updateHf2FromHf1(hf1, hf2); { unsigned F = toF(hf2, cf, zf); push_rr(a, F); } break; case 0xF6: { unsigned data; PC_READ(data); or_a_u8(data); } break; case 0xF7: rst_n(0x30); break; // ldhl sp,n (12 cycles): // Put (sp+next (signed) byte in memory) into hl (unsets ZF and SF, may enable HF and CF): case 0xF8: { unsigned sum; sp_plus_n(sum); l = sum & 0xFF; h = sum >> 8; } break; // ld sp,hl (8 cycles): // Put value in HL into SP case 0xF9: sp = hl(); cycleCounter += 4; break; // ld a,(nn) (16 cycles): // set A to value in memory at address given by the 2 next bytes. case 0xFA: { unsigned imml, immh; PC_READ(imml); PC_READ(immh); READ(a, immh << 8 | imml); } break; // ei (4 cycles): // Enable Interrupts after next instruction: case 0xFB: mem_.ei(cycleCounter); break; case 0xFC: // not specified. should freeze. break; case 0xFD: // not specified. should freeze break; case 0xFE: { unsigned data; PC_READ(data); cp_a_u8(data); } break; case 0xFF: rst_n(0x38); break; } } pc_ = pc; cycleCounter = mem_.event(cycleCounter); } a_ = a; cycleCounter_ = cycleCounter; } } libgambatte/libretro/control000664 001750 001750 00000000330 12720365247 017406 0ustar00sergiosergio000000 000000 Package: com.libretro.gambatte Name: gambatte Depends: Version: 0.0.1 Architecture: iphoneos-arm Description: Libretro iOS core of Gambatte Maintainer: libretro Author: libretro Section: System Tag: role::developer libgambatte/src/cpu.h000664 001750 001750 00000005776 12720365247 015733 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef CPU_H #define CPU_H #include "gambatte.h" #include "gambatte-memory.h" #include "savestate.h" namespace gambatte { class CPU { public: CPU(); long runFor(unsigned long cycles); void setStatePtrs(SaveState &state); void saveState(SaveState &state); void loadState(SaveState const &state); #if 0 void loadSavedata() { mem_.loadSavedata(); } void saveSavedata() { mem_.saveSavedata(); } #endif #ifdef __LIBRETRO__ void *savedata_ptr() { return mem_.savedata_ptr(); } unsigned savedata_size() { return mem_.savedata_size(); } void *rtcdata_ptr() { return mem_.rtcdata_ptr(); } unsigned rtcdata_size() { return mem_.rtcdata_size(); } void clearCheats() { mem_.clearCheats(); } void *vram_ptr() const { return mem_.vram_ptr(); } void *rambank0_ptr() const { return mem_.rambank0_ptr(); } void *rambank1_ptr() const { return mem_.rambank1_ptr(); } void *rombank0_ptr() const { return mem_.rombank0_ptr(); } void *rombank1_ptr() const { return mem_.rombank1_ptr(); } #endif void setVideoBuffer(video_pixel_t *videoBuf, std::ptrdiff_t pitch) { mem_.setVideoBuffer(videoBuf, pitch); } void setInputGetter(InputGetter *getInput) { mem_.setInputGetter(getInput); } void setSaveDir(std::string const &sdir) { mem_.setSaveDir(sdir); } std::string const saveBasePath() const { return mem_.saveBasePath(); } int load(const void *romdata, unsigned int romsize, bool forceDmg, bool multicartCompat) { return mem_.loadROM(romdata, romsize, forceDmg, multicartCompat); } #if 0 bool loaded() const { return mem_.loaded(); } #endif void setSoundBuffer(uint_least32_t *buf) { mem_.setSoundBuffer(buf); } std::size_t fillSoundBuffer() { return mem_.fillSoundBuffer(cycleCounter_); } bool isCgb() const { return mem_.isCgb(); } void setDmgPaletteColor(int palNum, int colorNum, unsigned long rgb32) { mem_.setDmgPaletteColor(palNum, colorNum, rgb32); } void setGameGenie(std::string const &codes) { mem_.setGameGenie(codes); } void setGameShark(std::string const &codes) { mem_.setGameShark(codes); } Memory mem_; private: unsigned long cycleCounter_; unsigned short pc_; unsigned short sp; unsigned hf1, hf2, zf, cf; unsigned char a_, b, c, d, e, /*f,*/ h, l; bool skip_; void process(unsigned long cycles); }; } #endif libgambatte/libretro/msvc/msvc-2010/libretro.def000664 001750 001750 00000001011 12720365247 022602 0ustar00sergiosergio000000 000000 LIBRARY "msvc-2010" EXPORTS retro_set_environment retro_set_video_refresh retro_set_audio_sample retro_set_audio_sample_batch retro_set_input_poll retro_set_input_state retro_init retro_deinit retro_api_version retro_get_system_info retro_get_system_av_info retro_set_controller_port_device retro_reset retro_run retro_serialize_size retro_serialize retro_unserialize retro_cheat_reset retro_cheat_set retro_load_game retro_load_game_special retro_unload_game retro_get_region retro_get_memory_data retro_get_memory_size libgambatte/libretro/msvc/msvc-2010-360/000700 001750 001750 00000000000 12720366137 020600 5ustar00sergiosergio000000 000000 libgambatte/src/gambatte-memory.cpp000664 001750 001750 00000061756 12720365247 020571 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "gambatte-memory.h" #include "inputgetter.h" #include "savestate.h" #include "sound.h" #include "video.h" #include namespace gambatte { Memory::Memory(Interrupter const &interrupter) : getInput_(0) , divLastUpdate_(0) , lastOamDmaUpdate_(disabled_time) , lcd_(ioamhram_, 0, VideoInterruptRequester(intreq_)) , interrupter_(interrupter) , dmaSource_(0) , dmaDestination_(0) , oamDmaPos_(0xFE) , serialCnt_(0) , blanklcd_(false) { intreq_.setEventTime(144 * 456ul); intreq_.setEventTime(0); } void Memory::setStatePtrs(SaveState &state) { state.mem.ioamhram.set(ioamhram_, sizeof ioamhram_); cart_.setStatePtrs(state); lcd_.setStatePtrs(state); psg_.setStatePtrs(state); } unsigned long Memory::saveState(SaveState &state, unsigned long cc) { cc = resetCounters(cc); nontrivial_ff_read(0x05, cc); nontrivial_ff_read(0x0F, cc); nontrivial_ff_read(0x26, cc); state.mem.divLastUpdate = divLastUpdate_; state.mem.nextSerialtime = intreq_.eventTime(intevent_serial); state.mem.unhaltTime = intreq_.eventTime(intevent_unhalt); state.mem.lastOamDmaUpdate = lastOamDmaUpdate_; state.mem.dmaSource = dmaSource_; state.mem.dmaDestination = dmaDestination_; state.mem.oamDmaPos = oamDmaPos_; intreq_.saveState(state); cart_.saveState(state); tima_.saveState(state); lcd_.saveState(state); psg_.saveState(state); return cc; } static int serialCntFrom(unsigned long cyclesUntilDone, bool cgbFast) { return cgbFast ? (cyclesUntilDone + 0xF) >> 4 : (cyclesUntilDone + 0x1FF) >> 9; } void Memory::loadState(SaveState const &state) { psg_.loadState(state); lcd_.loadState(state, state.mem.oamDmaPos < 0xA0 ? cart_.rdisabledRam() : ioamhram_); tima_.loadState(state, TimaInterruptRequester(intreq_)); cart_.loadState(state); intreq_.loadState(state); divLastUpdate_ = state.mem.divLastUpdate; intreq_.setEventTime(state.mem.nextSerialtime > state.cpu.cycleCounter ? state.mem.nextSerialtime : state.cpu.cycleCounter); intreq_.setEventTime(state.mem.unhaltTime); lastOamDmaUpdate_ = state.mem.lastOamDmaUpdate; dmaSource_ = state.mem.dmaSource; dmaDestination_ = state.mem.dmaDestination; oamDmaPos_ = state.mem.oamDmaPos; serialCnt_ = intreq_.eventTime(intevent_serial) != disabled_time ? serialCntFrom(intreq_.eventTime(intevent_serial) - state.cpu.cycleCounter, ioamhram_[0x102] & isCgb() * 2) : 8; cart_.setVrambank(ioamhram_[0x14F] & isCgb()); cart_.setOamDmaSrc(oam_dma_src_off); cart_.setWrambank(isCgb() && (ioamhram_[0x170] & 0x07) ? ioamhram_[0x170] & 0x07 : 1); if (lastOamDmaUpdate_ != disabled_time) { oamDmaInitSetup(); unsigned oamEventPos = oamDmaPos_ < 0xA0 ? 0xA0 : 0x100; intreq_.setEventTime( lastOamDmaUpdate_ + (oamEventPos - oamDmaPos_) * 4); } intreq_.setEventTime((ioamhram_[0x140] & lcdc_en) ? lcd_.nextMode1IrqTime() : state.cpu.cycleCounter); blanklcd_ = false; if (!isCgb()) std::memset(cart_.vramdata() + 0x2000, 0, 0x2000); } void Memory::setEndtime(unsigned long cc, unsigned long inc) { if (intreq_.eventTime(intevent_blit) <= cc) { intreq_.setEventTime(intreq_.eventTime(intevent_blit) + (70224 << isDoubleSpeed())); } intreq_.setEventTime(cc + (inc << isDoubleSpeed())); } void Memory::updateSerial(unsigned long const cc) { if (intreq_.eventTime(intevent_serial) != disabled_time) { if (intreq_.eventTime(intevent_serial) <= cc) { ioamhram_[0x101] = (((ioamhram_[0x101] + 1) << serialCnt_) - 1) & 0xFF; ioamhram_[0x102] &= 0x7F; intreq_.setEventTime(disabled_time); intreq_.flagIrq(8); } else { int const targetCnt = serialCntFrom(intreq_.eventTime(intevent_serial) - cc, ioamhram_[0x102] & isCgb() * 2); ioamhram_[0x101] = (((ioamhram_[0x101] + 1) << (serialCnt_ - targetCnt)) - 1) & 0xFF; serialCnt_ = targetCnt; } } } void Memory::updateTimaIrq(unsigned long cc) { while (intreq_.eventTime(intevent_tima) <= cc) tima_.doIrqEvent(TimaInterruptRequester(intreq_)); } void Memory::updateIrqs(unsigned long cc) { updateSerial(cc); updateTimaIrq(cc); lcd_.update(cc); } unsigned long Memory::event(unsigned long cc) { if (lastOamDmaUpdate_ != disabled_time) updateOamDma(cc); switch (intreq_.minEventId()) { case intevent_unhalt: intreq_.unhalt(); intreq_.setEventTime(disabled_time); break; case intevent_end: intreq_.setEventTime(disabled_time - 1); while (cc >= intreq_.minEventTime() && intreq_.eventTime(intevent_end) != disabled_time) { cc = event(cc); } intreq_.setEventTime(disabled_time); break; case intevent_blit: { bool const lcden = ioamhram_[0x140] & lcdc_en; unsigned long blitTime = intreq_.eventTime(intevent_blit); if (lcden | blanklcd_) { lcd_.updateScreen(blanklcd_, cc); intreq_.setEventTime(disabled_time); intreq_.setEventTime(disabled_time); while (cc >= intreq_.minEventTime()) cc = event(cc); } else blitTime += 70224 << isDoubleSpeed(); blanklcd_ = lcden ^ 1; intreq_.setEventTime(blitTime); } break; case intevent_serial: updateSerial(cc); break; case intevent_oam: intreq_.setEventTime(lastOamDmaUpdate_ == disabled_time ? static_cast(disabled_time) : intreq_.eventTime(intevent_oam) + 0xA0 * 4); break; case intevent_dma: { bool const doubleSpeed = isDoubleSpeed(); unsigned dmaSrc = dmaSource_; unsigned dmaDest = dmaDestination_; unsigned dmaLength = ((ioamhram_[0x155] & 0x7F) + 0x1) * 0x10; unsigned length = hdmaReqFlagged(intreq_) ? 0x10 : dmaLength; ackDmaReq(intreq_); if ((static_cast(dmaDest) + length) & 0x10000) { length = 0x10000 - dmaDest; ioamhram_[0x155] |= 0x80; } dmaLength -= length; if (!(ioamhram_[0x140] & lcdc_en)) dmaLength = 0; { unsigned long lOamDmaUpdate = lastOamDmaUpdate_; lastOamDmaUpdate_ = disabled_time; while (length--) { unsigned const src = dmaSrc++ & 0xFFFF; unsigned const data = (src & 0xE000) == 0x8000 || src > 0xFDFF ? 0xFF : read(src, cc); cc += 2 << doubleSpeed; if (cc - 3 > lOamDmaUpdate) { oamDmaPos_ = (oamDmaPos_ + 1) & 0xFF; lOamDmaUpdate += 4; if (oamDmaPos_ < 0xA0) { if (oamDmaPos_ == 0) startOamDma(lOamDmaUpdate - 1); ioamhram_[src & 0xFF] = data; } else if (oamDmaPos_ == 0xA0) { endOamDma(lOamDmaUpdate - 1); lOamDmaUpdate = disabled_time; } } nontrivial_write(0x8000 | (dmaDest++ & 0x1FFF), data, cc); } lastOamDmaUpdate_ = lOamDmaUpdate; } cc += 4; dmaSource_ = dmaSrc; dmaDestination_ = dmaDest; ioamhram_[0x155] = ((dmaLength / 0x10 - 0x1) & 0xFF) | (ioamhram_[0x155] & 0x80); if ((ioamhram_[0x155] & 0x80) && lcd_.hdmaIsEnabled()) { if (lastOamDmaUpdate_ != disabled_time) updateOamDma(cc); lcd_.disableHdma(cc); } } break; case intevent_tima: tima_.doIrqEvent(TimaInterruptRequester(intreq_)); break; case intevent_video: lcd_.update(cc); break; case intevent_interrupts: if (halted()) { if (isCgb()) cc += 4; intreq_.unhalt(); intreq_.setEventTime(disabled_time); } if (ime()) { unsigned const pendingIrqs = intreq_.pendingIrqs(); unsigned const n = pendingIrqs & -pendingIrqs; unsigned address; if (n <= 4) { static unsigned char const lut[] = { 0x40, 0x48, 0x48, 0x50 }; address = lut[n-1]; } else address = 0x50 + n; intreq_.ackIrq(n); cc = interrupter_.interrupt(address, cc, *this); } break; } return cc; } unsigned long Memory::stop(unsigned long cc) { cc += 4 + 4 * isDoubleSpeed(); if (ioamhram_[0x14D] & isCgb()) { psg_.generateSamples(cc, isDoubleSpeed()); lcd_.speedChange(cc); ioamhram_[0x14D] ^= 0x81; intreq_.setEventTime((ioamhram_[0x140] & lcdc_en) ? lcd_.nextMode1IrqTime() : cc + (70224 << isDoubleSpeed())); if (intreq_.eventTime(intevent_end) > cc) { intreq_.setEventTime(cc + ( isDoubleSpeed() ? (intreq_.eventTime(intevent_end) - cc) << 1 : (intreq_.eventTime(intevent_end) - cc) >> 1)); } } intreq_.halt(); intreq_.setEventTime(cc + 0x20000 + isDoubleSpeed() * 8); return cc; } static void decCycles(unsigned long &counter, unsigned long dec) { if (counter != disabled_time) counter -= dec; } void Memory::decEventCycles(IntEventId eventId, unsigned long dec) { if (intreq_.eventTime(eventId) != disabled_time) intreq_.setEventTime(eventId, intreq_.eventTime(eventId) - dec); } unsigned long Memory::resetCounters(unsigned long cc) { if (lastOamDmaUpdate_ != disabled_time) updateOamDma(cc); updateIrqs(cc); { unsigned long divinc = (cc - divLastUpdate_) >> 8; ioamhram_[0x104] = (ioamhram_[0x104] + divinc) & 0xFF; divLastUpdate_ += divinc << 8; } unsigned long const dec = cc < 0x10000 ? 0 : (cc & ~0x7FFFul) - 0x8000; decCycles(divLastUpdate_, dec); decCycles(lastOamDmaUpdate_, dec); decEventCycles(intevent_serial, dec); decEventCycles(intevent_oam, dec); decEventCycles(intevent_blit, dec); decEventCycles(intevent_end, dec); decEventCycles(intevent_unhalt, dec); unsigned long const oldCC = cc; cc -= dec; intreq_.resetCc(oldCC, cc); tima_.resetCc(oldCC, cc, TimaInterruptRequester(intreq_)); lcd_.resetCc(oldCC, cc); psg_.resetCounter(cc, oldCC, isDoubleSpeed()); return cc; } void Memory::updateInput() { unsigned state = 0xF; if ((ioamhram_[0x100] & 0x30) != 0x30 && getInput_) { unsigned input = (*getInput_)(); unsigned dpad_state = ~input >> 4; unsigned button_state = ~input; if (!(ioamhram_[0x100] & 0x10)) state &= dpad_state; if (!(ioamhram_[0x100] & 0x20)) state &= button_state; } if (state != 0xF && (ioamhram_[0x100] & 0xF) == 0xF) intreq_.flagIrq(0x10); ioamhram_[0x100] = (ioamhram_[0x100] & -0x10u) | state; } void Memory::updateOamDma(unsigned long const cc) { unsigned char const *const oamDmaSrc = oamDmaSrcPtr(); unsigned cycles = (cc - lastOamDmaUpdate_) >> 2; while (cycles--) { oamDmaPos_ = (oamDmaPos_ + 1) & 0xFF; lastOamDmaUpdate_ += 4; if (oamDmaPos_ < 0xA0) { if (oamDmaPos_ == 0) startOamDma(lastOamDmaUpdate_ - 1); ioamhram_[oamDmaPos_] = oamDmaSrc ? oamDmaSrc[oamDmaPos_] : cart_.rtcRead(); } else if (oamDmaPos_ == 0xA0) { endOamDma(lastOamDmaUpdate_ - 1); lastOamDmaUpdate_ = disabled_time; break; } } } void Memory::oamDmaInitSetup() { if (ioamhram_[0x146] < 0xA0) { cart_.setOamDmaSrc(ioamhram_[0x146] < 0x80 ? oam_dma_src_rom : oam_dma_src_vram); } else if (ioamhram_[0x146] < 0xFE - isCgb() * 0x1E) { cart_.setOamDmaSrc(ioamhram_[0x146] < 0xC0 ? oam_dma_src_sram : oam_dma_src_wram); } else cart_.setOamDmaSrc(oam_dma_src_invalid); } static unsigned char const * oamDmaSrcZero() { static unsigned char zeroMem[0xA0]; return zeroMem; } unsigned char const * Memory::oamDmaSrcPtr() const { switch (cart_.oamDmaSrc()) { case oam_dma_src_rom: return cart_.romdata(ioamhram_[0x146] >> 6) + (ioamhram_[0x146] << 8); case oam_dma_src_sram: return cart_.rsrambankptr() ? cart_.rsrambankptr() + (ioamhram_[0x146] << 8) : 0; case oam_dma_src_vram: return cart_.vrambankptr() + (ioamhram_[0x146] << 8); case oam_dma_src_wram: return cart_.wramdata(ioamhram_[0x146] >> 4 & 1) + (ioamhram_[0x146] << 8 & 0xFFF); case oam_dma_src_invalid: case oam_dma_src_off: break; } return ioamhram_[0x146] == 0xFF && !isCgb() ? oamDmaSrcZero() : cart_.rdisabledRam(); } void Memory::startOamDma(unsigned long cc) { lcd_.oamChange(cart_.rdisabledRam(), cc); } void Memory::endOamDma(unsigned long cc) { oamDmaPos_ = 0xFE; cart_.setOamDmaSrc(oam_dma_src_off); lcd_.oamChange(ioamhram_, cc); } unsigned Memory::nontrivial_ff_read(unsigned const p, unsigned long const cc) { if (lastOamDmaUpdate_ != disabled_time) updateOamDma(cc); switch (p) { case 0x00: updateInput(); break; case 0x01: case 0x02: updateSerial(cc); break; case 0x04: { unsigned long divcycles = (cc - divLastUpdate_) >> 8; ioamhram_[0x104] = (ioamhram_[0x104] + divcycles) & 0xFF; divLastUpdate_ += divcycles << 8; } break; case 0x05: ioamhram_[0x105] = tima_.tima(cc); break; case 0x0F: updateIrqs(cc); ioamhram_[0x10F] = intreq_.ifreg(); break; case 0x26: if (ioamhram_[0x126] & 0x80) { psg_.generateSamples(cc, isDoubleSpeed()); ioamhram_[0x126] = 0xF0 | psg_.getStatus(); } else ioamhram_[0x126] = 0x70; break; case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3E: case 0x3F: psg_.generateSamples(cc, isDoubleSpeed()); return psg_.waveRamRead(p & 0xF); case 0x41: return ioamhram_[0x141] | lcd_.getStat(ioamhram_[0x145], cc); case 0x44: return lcd_.getLyReg(cc); case 0x69: return lcd_.cgbBgColorRead(ioamhram_[0x168] & 0x3F, cc); case 0x6B: return lcd_.cgbSpColorRead(ioamhram_[0x16A] & 0x3F, cc); default: break; } return ioamhram_[p + 0x100]; } static bool isInOamDmaConflictArea(OamDmaSrc const oamDmaSrc, unsigned const p, bool const cgb) { struct Area { unsigned short areaUpper, exceptAreaLower, exceptAreaWidth, pad; }; static Area const cgbAreas[] = { { 0xC000, 0x8000, 0x2000, 0 }, { 0xC000, 0x8000, 0x2000, 0 }, { 0xA000, 0x0000, 0x8000, 0 }, { 0xFE00, 0x0000, 0xC000, 0 }, { 0xC000, 0x8000, 0x2000, 0 }, { 0x0000, 0x0000, 0x0000, 0 } }; static Area const dmgAreas[] = { { 0xFE00, 0x8000, 0x2000, 0 }, { 0xFE00, 0x8000, 0x2000, 0 }, { 0xA000, 0x0000, 0x8000, 0 }, { 0xFE00, 0x8000, 0x2000, 0 }, { 0xFE00, 0x8000, 0x2000, 0 }, { 0x0000, 0x0000, 0x0000, 0 } }; Area const *a = cgb ? cgbAreas : dmgAreas; return p < a[oamDmaSrc].areaUpper && p - a[oamDmaSrc].exceptAreaLower >= a[oamDmaSrc].exceptAreaWidth; } unsigned Memory::nontrivial_read(unsigned const p, unsigned long const cc) { if (p < 0xFF80) { if (lastOamDmaUpdate_ != disabled_time) { updateOamDma(cc); if (isInOamDmaConflictArea(cart_.oamDmaSrc(), p, isCgb()) && oamDmaPos_ < 0xA0) return ioamhram_[oamDmaPos_]; } if (p < 0xC000) { if (p < 0x8000) return cart_.romdata(p >> 14)[p]; if (p < 0xA000) { if (!lcd_.vramAccessible(cc)) return 0xFF; return cart_.vrambankptr()[p]; } if (cart_.rsrambankptr()) return cart_.rsrambankptr()[p]; return cart_.rtcRead(); } if (p < 0xFE00) return cart_.wramdata(p >> 12 & 1)[p & 0xFFF]; long const ffp = long(p) - 0xFF00; if (ffp >= 0) return nontrivial_ff_read(ffp, cc); if (!lcd_.oamReadable(cc) || oamDmaPos_ < 0xA0) return 0xFF; } return ioamhram_[p - 0xFE00]; } void Memory::nontrivial_ff_write(unsigned const p, unsigned data, unsigned long const cc) { if (lastOamDmaUpdate_ != disabled_time) updateOamDma(cc); switch (p & 0xFF) { case 0x00: if ((data ^ ioamhram_[0x100]) & 0x30) { ioamhram_[0x100] = (ioamhram_[0x100] & ~0x30u) | (data & 0x30); updateInput(); } return; case 0x01: updateSerial(cc); break; case 0x02: updateSerial(cc); serialCnt_ = 8; if ((data & 0x81) == 0x81) { intreq_.setEventTime((data & isCgb() * 2) ? (cc & ~0x07ul) + 0x010 * 8 : (cc & ~0xFFul) + 0x200 * 8); } else intreq_.setEventTime(disabled_time); data |= 0x7E - isCgb() * 2; break; case 0x04: ioamhram_[0x104] = 0; divLastUpdate_ = cc; return; case 0x05: tima_.setTima(data, cc, TimaInterruptRequester(intreq_)); break; case 0x06: tima_.setTma(data, cc, TimaInterruptRequester(intreq_)); break; case 0x07: data |= 0xF8; tima_.setTac(data, cc, TimaInterruptRequester(intreq_)); break; case 0x0F: updateIrqs(cc); intreq_.setIfreg(0xE0 | data); return; case 0x10: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr10(data); data |= 0x80; break; case 0x11: if (!psg_.isEnabled()) { if (isCgb()) return; data &= 0x3F; } psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr11(data); data |= 0x3F; break; case 0x12: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr12(data); break; case 0x13: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr13(data); return; case 0x14: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr14(data); data |= 0xBF; break; case 0x16: if (!psg_.isEnabled()) { if (isCgb()) return; data &= 0x3F; } psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr21(data); data |= 0x3F; break; case 0x17: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr22(data); break; case 0x18: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr23(data); return; case 0x19: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr24(data); data |= 0xBF; break; case 0x1A: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr30(data); data |= 0x7F; break; case 0x1B: if (!psg_.isEnabled() && isCgb()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr31(data); return; case 0x1C: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr32(data); data |= 0x9F; break; case 0x1D: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr33(data); return; case 0x1E: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr34(data); data |= 0xBF; break; case 0x20: if (!psg_.isEnabled() && isCgb()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr41(data); return; case 0x21: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr42(data); break; case 0x22: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr43(data); break; case 0x23: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setNr44(data); data |= 0xBF; break; case 0x24: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.setSoVolume(data); break; case 0x25: if (!psg_.isEnabled()) return; psg_.generateSamples(cc, isDoubleSpeed()); psg_.mapSo(data); break; case 0x26: if ((ioamhram_[0x126] ^ data) & 0x80) { psg_.generateSamples(cc, isDoubleSpeed()); if (!(data & 0x80)) { for (unsigned i = 0x10; i < 0x26; ++i) ff_write(i, 0, cc); psg_.setEnabled(false); } else { psg_.reset(); psg_.setEnabled(true); } } data = (data & 0x80) | (ioamhram_[0x126] & 0x7F); break; case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3E: case 0x3F: psg_.generateSamples(cc, isDoubleSpeed()); psg_.waveRamWrite(p & 0xF, data); break; case 0x40: if (ioamhram_[0x140] != data) { if ((ioamhram_[0x140] ^ data) & lcdc_en) { unsigned const lyc = lcd_.getStat(ioamhram_[0x145], cc) & lcdstat_lycflag; bool const hdmaEnabled = lcd_.hdmaIsEnabled(); lcd_.lcdcChange(data, cc); ioamhram_[0x144] = 0; ioamhram_[0x141] &= 0xF8; if (data & lcdc_en) { intreq_.setEventTime(blanklcd_ ? lcd_.nextMode1IrqTime() : lcd_.nextMode1IrqTime() + (70224 << isDoubleSpeed())); } else { ioamhram_[0x141] |= lyc; intreq_.setEventTime( cc + (456 * 4 << isDoubleSpeed())); if (hdmaEnabled) flagHdmaReq(intreq_); } } else lcd_.lcdcChange(data, cc); ioamhram_[0x140] = data; } return; case 0x41: lcd_.lcdstatChange(data, cc); data = (ioamhram_[0x141] & 0x87) | (data & 0x78); break; case 0x42: lcd_.scyChange(data, cc); break; case 0x43: lcd_.scxChange(data, cc); break; case 0x45: lcd_.lycRegChange(data, cc); break; case 0x46: if (lastOamDmaUpdate_ != disabled_time) endOamDma(cc); lastOamDmaUpdate_ = cc; intreq_.setEventTime(cc + 8); ioamhram_[0x146] = data; oamDmaInitSetup(); return; case 0x47: if (!isCgb()) lcd_.dmgBgPaletteChange(data, cc); break; case 0x48: if (!isCgb()) lcd_.dmgSpPalette1Change(data, cc); break; case 0x49: if (!isCgb()) lcd_.dmgSpPalette2Change(data, cc); break; case 0x4A: lcd_.wyChange(data, cc); break; case 0x4B: lcd_.wxChange(data, cc); break; case 0x4D: if (isCgb()) ioamhram_[0x14D] = (ioamhram_[0x14D] & ~1u) | (data & 1); return; case 0x4F: if (isCgb()) { cart_.setVrambank(data & 1); ioamhram_[0x14F] = 0xFE | data; } return; case 0x51: dmaSource_ = data << 8 | (dmaSource_ & 0xFF); return; case 0x52: dmaSource_ = (dmaSource_ & 0xFF00) | (data & 0xF0); return; case 0x53: dmaDestination_ = data << 8 | (dmaDestination_ & 0xFF); return; case 0x54: dmaDestination_ = (dmaDestination_ & 0xFF00) | (data & 0xF0); return; case 0x55: if (isCgb()) { ioamhram_[0x155] = data & 0x7F; if (lcd_.hdmaIsEnabled()) { if (!(data & 0x80)) { ioamhram_[0x155] |= 0x80; lcd_.disableHdma(cc); } } else { if (data & 0x80) { if (ioamhram_[0x140] & lcdc_en) { lcd_.enableHdma(cc); } else flagHdmaReq(intreq_); } else flagGdmaReq(intreq_); } } return; case 0x56: if (isCgb()) ioamhram_[0x156] = data | 0x3E; return; case 0x68: if (isCgb()) ioamhram_[0x168] = data | 0x40; return; case 0x69: if (isCgb()) { unsigned index = ioamhram_[0x168] & 0x3F; lcd_.cgbBgColorChange(index, data, cc); ioamhram_[0x168] = (ioamhram_[0x168] & ~0x3F) | ((index + (ioamhram_[0x168] >> 7)) & 0x3F); } return; case 0x6A: if (isCgb()) ioamhram_[0x16A] = data | 0x40; return; case 0x6B: if (isCgb()) { unsigned index = ioamhram_[0x16A] & 0x3F; lcd_.cgbSpColorChange(index, data, cc); ioamhram_[0x16A] = (ioamhram_[0x16A] & ~0x3F) | ((index + (ioamhram_[0x16A] >> 7)) & 0x3F); } return; case 0x6C: if (isCgb()) ioamhram_[0x16C] = data | 0xFE; return; case 0x70: if (isCgb()) { cart_.setWrambank((data & 0x07) ? data & 0x07 : 1); ioamhram_[0x170] = data | 0xF8; } return; case 0x72: case 0x73: case 0x74: if (isCgb()) break; return; case 0x75: if (isCgb()) ioamhram_[0x175] = data | 0x8F; return; case 0xFF: intreq_.setIereg(data); break; default: return; } ioamhram_[p + 0x100] = data; } void Memory::nontrivial_write(unsigned const p, unsigned const data, unsigned long const cc) { if (lastOamDmaUpdate_ != disabled_time) { updateOamDma(cc); if (isInOamDmaConflictArea(cart_.oamDmaSrc(), p, isCgb()) && oamDmaPos_ < 0xA0) { ioamhram_[oamDmaPos_] = data; return; } } if (p < 0xFE00) { if (p < 0xA000) { if (p < 0x8000) { cart_.mbcWrite(p, data); } else if (lcd_.vramAccessible(cc)) { lcd_.vramChange(cc); cart_.vrambankptr()[p] = data; } } else if (p < 0xC000) { if (cart_.wsrambankptr()) cart_.wsrambankptr()[p] = data; else cart_.rtcWrite(data); } else cart_.wramdata(p >> 12 & 1)[p & 0xFFF] = data; } else if (p - 0xFF80u >= 0x7Fu) { long const ffp = long(p) - 0xFF00; if (ffp < 0) { if (lcd_.oamWritable(cc) && oamDmaPos_ >= 0xA0 && (p < 0xFEA0 || isCgb())) { lcd_.oamChange(cc); ioamhram_[p - 0xFE00] = data; } } else nontrivial_ff_write(ffp, data, cc); } else ioamhram_[p - 0xFE00] = data; } std::size_t Memory::fillSoundBuffer(unsigned long cc) { psg_.generateSamples(cc, isDoubleSpeed()); return psg_.fillBuffer(); } int Memory::loadROM(const void *romdata, unsigned romsize, const bool forceDmg, const bool multicartCompat) { if (const int fail = cart_.loadROM(romdata, romsize, forceDmg, multicartCompat)) return fail; psg_.init(cart_.isCgb()); lcd_.reset(ioamhram_, cart_.vramdata(), cart_.isCgb()); interrupter_.setGameShark(std::string()); return 0; } } libgambatte/Makefile.libretro000664 001750 001750 00000020245 12720365247 017451 0ustar00sergiosergio000000 000000 DEBUG = 0 ifeq ($(platform),) platform = unix ifeq ($(shell uname -a),) platform = win else ifneq ($(findstring MINGW,$(shell uname -a)),) platform = win else ifneq ($(findstring Darwin,$(shell uname -a)),) platform = osx else ifneq ($(findstring win,$(shell uname -a)),) platform = win endif endif # system platform system_platform = unix ifeq ($(shell uname -a),) EXE_EXT = .exe system_platform = win else ifneq ($(findstring Darwin,$(shell uname -a)),) system_platform = osx else ifneq ($(findstring MINGW,$(shell uname -a)),) system_platform = win endif TARGET_NAME := gambatte ifeq ($(ARCHFLAGS),) ifeq ($(archs),ppc) ARCHFLAGS = -arch ppc -arch ppc64 else ARCHFLAGS = -arch i386 -arch x86_64 endif endif # Unix ifeq ($(platform), unix) TARGET := $(TARGET_NAME)_libretro.so fpic := -fPIC SHARED := -shared -Wl,-version-script=libretro/link.T # OS X else ifeq ($(platform), osx) TARGET := $(TARGET_NAME)_libretro.dylib fpic := -fPIC SHARED := -dynamiclib OSXVER = `sw_vers -productVersion | cut -d. -f 2` OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"` #fpic += -mmacosx-version-min=10.1 ifndef ($(NOUNIVERSAL)) CFLAGS += $(ARCHFLAGS) CXXFLAGS += $(ARCHFLAGS) LDFLAGS += $(ARCHFLAGS) endif # iOS else ifneq (,$(findstring ios,$(platform))) TARGET := $(TARGET_NAME)_libretro_ios.dylib fpic := -fPIC SHARED := -dynamiclib ifeq ($(IOSSDK),) IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path) endif CC = cc -arch armv7 -isysroot $(IOSSDK) CXX = c++ -arch armv7 -isysroot $(IOSSDK) ifeq ($(platform),ios9) CC += -miphoneos-version-min=8.0 CXX += -miphoneos-version-min=8.0 PLATFORM_DEFINES := -miphoneos-version-min=8.0 else CC += -miphoneos-version-min=5.0 CXX += -miphoneos-version-min=5.0 PLATFORM_DEFINES := -miphoneos-version-min=5.0 endif # Theos else ifeq ($(platform), theos_ios) DEPLOYMENT_IOSVERSION = 5.0 TARGET = iphone:latest:$(DEPLOYMENT_IOSVERSION) ARCHS = armv7 armv7s TARGET_IPHONEOS_DEPLOYMENT_VERSION=$(DEPLOYMENT_IOSVERSION) THEOS_BUILD_DIR := objs include $(THEOS)/makefiles/common.mk LIBRARY_NAME = $(TARGET_NAME)_libretro_ios # QNX else ifeq ($(platform), qnx) TARGET := $(TARGET_NAME)_libretro_qnx.so fpic := -fPIC SHARED := -lcpp -lm -shared -Wl,-version-script=libretro/link.T CC = qcc -Vgcc_ntoarmv7le CXX = QCC -Vgcc_ntoarmv7le_cpp AR = QCC -Vgcc_ntoarmv7le PLATFORM_DEFINES := -D__BLACKBERRY_QNX__ -fexceptions -marm -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp # PS3 else ifeq ($(platform), ps3) TARGET := $(TARGET_NAME)_libretro_ps3.a CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe CXX = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-g++.exe AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe PLATFORM_DEFINES := -D__CELLOS_LV2__ STATIC_LINKING = 1 # sncps3 else ifeq ($(platform), sncps3) TARGET := $(TARGET_NAME)_libretro_ps3.a CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe CXX = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe PLATFORM_DEFINES := -D__CELLOS_LV2__ STATIC_LINKING = 1 # Lightweight PS3 Homebrew SDK else ifeq ($(platform), psl1ght) TARGET := $(TARGET_NAME)_libretro_psl1ght.a CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT) CXX = $(PS3DEV)/ppu/bin/ppu-g++$(EXE_EXT) AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT) PLATFORM_DEFINES := -D__CELLOS_LV2__ STATIC_LINKING = 1 # PSP else ifeq ($(platform), psp1) TARGET := $(TARGET_NAME)_libretro_psp1.a CC = psp-gcc$(EXE_EXT) CXX = psp-g++$(EXE_EXT) AR = psp-ar$(EXE_EXT) PLATFORM_DEFINES := -DPSP -DCC_RESAMPLER CFLAGS += -G0 CXXFLAGS += -G0 STATIC_LINKING = 1 # Vita else ifeq ($(platform), vita) TARGET := $(TARGET_NAME)_libretro_vita.a CC = arm-vita-eabi-gcc$(EXE_EXT) CXX = arm-vita-eabi-g++$(EXE_EXT) AR = arm-vita-eabi-ar$(EXE_EXT) PLATFORM_DEFINES := -DCC_RESAMPLER CFLAGS += -DVITA CXXFLAGS += -DVITA STATIC_LINKING = 1 # CTR(3DS) else ifeq ($(platform), ctr) TARGET := $(TARGET_NAME)_libretro_ctr.a CC = $(DEVKITARM)/bin/arm-none-eabi-gcc$(EXE_EXT) CXX = $(DEVKITARM)/bin/arm-none-eabi-g++$(EXE_EXT) AR = $(DEVKITARM)/bin/arm-none-eabi-ar$(EXE_EXT) PLATFORM_DEFINES := -DARM11 -D_3DS -DCC_RESAMPLER CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard CFLAGS += -Wall -mword-relocations CFLAGS += -fomit-frame-pointer -ffast-math CXXFLAGS += $(CFLAGS) STATIC_LINKING = 1 # Raspberry Pi 2 else ifeq ($(platform), rpi2) TARGET := $(TARGET_NAME)_libretro.so fpic := -fPIC SHARED := -shared -Wl,-version-script=libretro/link.T PLATFORM_DEFINES := -DARM CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -funsafe-math-optimizations CFLAGS += -fomit-frame-pointer -ffast-math CXXFLAGS += $(CFLAGS) # Xbox 360 else ifeq ($(platform), xenon) TARGET := $(TARGET_NAME)_libretro_xenon360.a CC = xenon-gcc$(EXE_EXT) CXX = xenon-g++$(EXE_EXT) AR = xenon-ar$(EXE_EXT) PLATFORM_DEFINES := -D__LIBXENON__ STATIC_LINKING = 1 # Nintendo Game Cube else ifeq ($(platform), ngc) TARGET := $(TARGET_NAME)_libretro_ngc.a CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT) CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT) AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT) PLATFORM_DEFINES += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float STATIC_LINKING = 1 # Nintendo Wii else ifeq ($(platform), wii) TARGET := $(TARGET_NAME)_libretro_wii.a CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT) CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT) AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT) PLATFORM_DEFINES += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float STATIC_LINKING = 1 # ARM else ifneq (,$(findstring armv,$(platform))) TARGET := $(TARGET_NAME)_libretro.so fpic := -fPIC SHARED := -shared -Wl,-version-script=libretro/link.T ifneq (,$(findstring cortexa5,$(platform))) PLATFORM_DEFINES += -marm -mcpu=cortex-a5 else ifneq (,$(findstring cortexa8,$(platform))) PLATFORM_DEFINES += -marm -mcpu=cortex-a8 else ifneq (,$(findstring cortexa9,$(platform))) PLATFORM_DEFINES += -marm -mcpu=cortex-a9 else ifneq (,$(findstring cortexa15a7,$(platform))) PLATFORM_DEFINES += -marm -mcpu=cortex-a15.cortex-a7 else PLATFORM_DEFINES += -marm endif ifneq (,$(findstring softfloat,$(platform))) PLATFORM_DEFINES += -mfloat-abi=softfp else ifneq (,$(findstring hardfloat,$(platform))) PLATFORM_DEFINES += -mfloat-abi=hard endif PLATFORM_DEFINES += -DARM # emscripten else ifeq ($(platform), emscripten) TARGET := $(TARGET_NAME)_libretro_emscripten.bc # GCW0 else ifeq ($(platform), gcw0) TARGET := $(TARGET_NAME)_libretro.so CC = /opt/gcw0-toolchain/usr/bin/mipsel-linux-gcc CXX = /opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ AR = /opt/gcw0-toolchain/usr/bin/mipsel-linux-ar fpic := -fPIC SHARED := -shared -Wl,-version-script=libretro/link.T PLATFORM_DEFINES := -DCC_RESAMPLER CFLAGS += -O3 -fomit-frame-pointer -march=mips32 -mtune=mips32r2 -mhard-float CXXFLAGS += $(CFLAGS) # Windows else TARGET := $(TARGET_NAME)_libretro.dll CC = gcc CXX = g++ SHARED := -shared -static-libgcc -static-libstdc++ -Wl,-no-undefined -Wl,-version-script=libretro/link.T endif ifeq ($(DEBUG), 1) CFLAGS += -O0 -g CXXFLAGS += -O0 -g else CFLAGS += -O3 CXXFLAGS += -O3 -fno-exceptions -fno-rtti -DHAVE_STDINT_H endif CORE_DIR := src include Makefile.common OBJS := $(SOURCES_CXX:.cpp=.o) $(SOURCES_C:.c=.o) DEFINES := -D__LIBRETRO__ $(PLATFORM_DEFINES) -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DINLINE=inline -DVIDEO_RGB565 CFLAGS += $(CODE_DEFINES) $(fpic) $(DEFINES) CXXFLAGS += $(fpic) $(DEFINES) LIBS := %.o: %.cpp $(CXX) -c -o $@ $< $(CXXFLAGS) $(INCFLAGS) %.o: %.c $(CC) -c -o $@ $< $(CFLAGS) $(INCFLAGS) ifeq ($(platform), theos_ios) COMMON_FLAGS := -DIOS $(COMMON_DEFINES) $(INCFLAGS) -I$(THEOS_INCLUDE_PATH) -Wno-error $(LIBRARY_NAME)_CFLAGS += $(CFLAGS) $(COMMON_FLAGS) $(LIBRARY_NAME)_CXXFLAGS += $(CXXFLAGS) $(COMMON_FLAGS) ${LIBRARY_NAME}_FILES = $(SOURCES_CXX) $(SOURCES_C) include $(THEOS_MAKE_PATH)/library.mk else all: $(TARGET) ifeq ($(platform), osx) ifndef ($(NOUNIVERSAL)) CFLAGS += $(ARCHFLAGS) CXXFLAGS += $(ARCHFLAGS) LFLAGS += $(ARCHFLAGS) endif endif $(TARGET): $(OBJS) ifeq ($(STATIC_LINKING), 1) $(AR) rcs $@ $(OBJS) else $(CXX) -o $@ $(SHARED) $(OBJS) $(LDFLAGS) $(LIBS) endif clean-objs: rm -f $(OBJS) clean: rm -f $(OBJS) rm -f $(TARGET) .PHONY: clean clean-objs endif libgambatte/src/mem/000700 001750 001750 00000000000 12720366137 015515 5ustar00sergiosergio000000 000000 libgambatte/libretro/msvc/msvc-2010/msvc-2010.vcxproj000664 001750 001750 00000016205 12720365247 023260 0ustar00sergiosergio000000 000000  Debug Win32 Release Win32 {A79F81F6-3FEE-48AA-9157-24EB772B624E} Win32Proj msvc-2010 DynamicLibrary Unicode DynamicLibrary Unicode true $(OutDir)msvc-2010$(TargetExt) $(SolutionDir)msvc-2010\$(Configuration)\ $(OutDir)msvc-2010$(TargetExt) $(SolutionDir)msvc-2010\$(Configuration)\ NotUsing Level3 ProgramDatabase Disabled false true false $(OutDir)$(ProjectName).pch MultiThreadedDebug _DEBUG;_WIN32;_LIB;%(PreprocessorDefinitions);HAVE_STDINT_H Callcap ..\..\..\include;..\src\;..\src\video;..\src\file;..\src\sound;..\src\mem;..\..\..\..\common;..\libsnes;..\..\..\..\common\resample true libretro.def Level3 NotUsing Full true true ProgramDatabase Size false false $(OutDir)$(ProjectName).pch MultiThreaded NDEBUG;_WIN32;_LIB;%(PreprocessorDefinitions);HAVE_STDINT_H ..\..\..\include;..\..\..\src\;..\..\..\src\video;..\..\..\src\file;..\..\..\src\sound;..\..\..\src\mem;..\..\..\..\common;..\libsnes;..\..\..\..\common\resample true true true libretro.def libgambatte/libretro/msvc/msvc-2003-xbox1/000700 001750 001750 00000000000 12720366137 021333 5ustar00sergiosergio000000 000000 libgambatte/src/interruptrequester.cpp000664 001750 001750 00000006073 12720365247 021462 0ustar00sergiosergio000000 000000 // // Copyright (C) 2010 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "interruptrequester.h" #include "savestate.h" namespace gambatte { InterruptRequester::InterruptRequester() : eventTimes_(disabled_time) , minIntTime_(0) , ifreg_(0) , iereg_(0) { } void InterruptRequester::saveState(SaveState &state) const { state.mem.minIntTime = minIntTime_; state.mem.IME = ime(); state.mem.halted = halted(); } void InterruptRequester::loadState(SaveState const &state) { minIntTime_ = state.mem.minIntTime; ifreg_ = state.mem.ioamhram.get()[0x10F]; iereg_ = state.mem.ioamhram.get()[0x1FF] & 0x1F; intFlags_.set(state.mem.IME, state.mem.halted); eventTimes_.setValue(intFlags_.imeOrHalted() && pendingIrqs() ? minIntTime_ : static_cast(disabled_time)); } void InterruptRequester::resetCc(unsigned long oldCc, unsigned long newCc) { minIntTime_ = minIntTime_ < oldCc ? 0 : minIntTime_ - (oldCc - newCc); if (eventTimes_.value(intevent_interrupts) != disabled_time) eventTimes_.setValue(minIntTime_); } void InterruptRequester::ei(unsigned long cc) { intFlags_.setIme(); minIntTime_ = cc + 1; if (pendingIrqs()) eventTimes_.setValue(minIntTime_); } void InterruptRequester::di() { intFlags_.unsetIme(); if (!intFlags_.imeOrHalted()) eventTimes_.setValue(disabled_time); } void InterruptRequester::halt() { intFlags_.setHalted(); if (pendingIrqs()) eventTimes_.setValue(minIntTime_); } void InterruptRequester::unhalt() { intFlags_.unsetHalted(); if (!intFlags_.imeOrHalted()) eventTimes_.setValue(disabled_time); } void InterruptRequester::flagIrq(unsigned bit) { ifreg_ |= bit; if (intFlags_.imeOrHalted() && pendingIrqs()) eventTimes_.setValue(minIntTime_); } void InterruptRequester::ackIrq(unsigned bit) { ifreg_ ^= bit; di(); } void InterruptRequester::setIereg(unsigned iereg) { iereg_ = iereg & 0x1F; if (intFlags_.imeOrHalted()) { eventTimes_.setValue(pendingIrqs() ? minIntTime_ : static_cast(disabled_time)); } } void InterruptRequester::setIfreg(unsigned ifreg) { ifreg_ = ifreg; if (intFlags_.imeOrHalted()) { eventTimes_.setValue(pendingIrqs() ? minIntTime_ : static_cast(disabled_time)); } } } libgambatte/include/gambatte.h000664 001750 001750 00000012704 12720365247 017551 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef GAMBATTE_H #define GAMBATTE_H #include "inputgetter.h" #include "gbint.h" #include #include namespace gambatte { #ifdef VIDEO_RGB565 typedef uint16_t video_pixel_t; #else typedef uint_least32_t video_pixel_t; #endif enum { BG_PALETTE = 0, SP1_PALETTE = 1, SP2_PALETTE = 2 }; class GB { public: GB(); ~GB(); enum LoadFlag { FORCE_DMG = 1, /**< Treat the ROM as not having CGB support regardless of what its header advertises. */ GBA_CGB = 2, /**< Use GBA intial CPU register values when in CGB mode. */ MULTICART_COMPAT = 4 /**< Use heuristics to detect and support some multicart MBCs disguised as MBC1. */ }; int load(const void *romdata, unsigned size, unsigned flags = 0); /** Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer, * or until a video frame has been drawn. * * There are 35112 stereo sound samples in a video frame. * May run for uptil 2064 stereo samples too long. * A stereo sample consists of two native endian 2s complement 16-bit PCM samples, * with the left sample preceding the right one. Usually casting soundBuf to/from * short* is OK and recommended. The reason for not using a short* in the interface * is to avoid implementation-defined behaviour without compromising performance. * * Returns early when a new video frame has finished drawing in the video buffer, * such that the caller may update the video output before the frame is overwritten. * The return value indicates whether a new video frame has been drawn, and the * exact time (in number of samples) at which it was drawn. * * @param videoBuf 160x144 RGB32 (native endian) video frame buffer or 0 * @param pitch distance in number of pixels (not bytes) from the start of one line to the next in videoBuf. * @param soundBuf buffer with space >= samples + 2064 * @param samples in: number of stereo samples to produce, out: actual number of samples produced * @return sample number at which the video frame was produced. -1 means no frame was produced. */ long runFor(gambatte::video_pixel_t *videoBuf, int pitch, gambatte::uint_least32_t *soundBuf, unsigned &samples); /** Reset to initial state. * Equivalent to reloading a ROM image, or turning a Game Boy Color off and on again. */ void reset(); /** @param palNum 0 <= palNum < 3. One of BG_PALETTE, SP1_PALETTE and SP2_PALETTE. * @param colorNum 0 <= colorNum < 4 */ void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32); /** Sets the callback used for getting input state. */ void setInputGetter(InputGetter *getInput); /** Sets the directory used for storing save data. The default is the same directory as the ROM Image file. */ void setSaveDir(const std::string &sdir); void *savedata_ptr(); unsigned savedata_size(); void *rtcdata_ptr(); unsigned rtcdata_size(); /** Returns true if the currently loaded ROM image is treated as having CGB support. */ bool isCgb() const; /** Returns true if a ROM image is loaded. */ bool isLoaded() const; void saveState(void *data); void loadState(const void *data); size_t stateSize() const; void setColorCorrection(bool enable); video_pixel_t gbcToRgb32(const unsigned bgr15); /** Set Game Genie codes to apply to currently loaded ROM image. Cleared on ROM load. * @param codes Game Genie codes in format HHH-HHH-HHH;HHH-HHH-HHH;... where H is [0-9]|[A-F] */ void setGameGenie(const std::string &codes); /** Set Game Shark codes to apply to currently loaded ROM image. Cleared on ROM load. * @param codes Game Shark codes in format 01HHHHHH;01HHHHHH;... where H is [0-9]|[A-F] */ void setGameShark(const std::string &codes); void clearCheats(); #ifdef __LIBRETRO__ void *vram_ptr() const; void *rambank0_ptr() const; void *rambank1_ptr() const; void *rombank0_ptr() const; void *rombank1_ptr() const; #endif private: struct Priv; Priv *const p_; void loadState(const std::string &filepath, bool osdMessage); GB(const GB &); GB & operator=(const GB &); }; } #endif libgambatte/src/sound/duty_unit.h000664 001750 001750 00000004174 12720365247 020307 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef DUTY_UNIT_H #define DUTY_UNIT_H #include "sound_unit.h" #include "master_disabler.h" #include "../savestate.h" namespace gambatte { class DutyUnit : public SoundUnit { public: DutyUnit(); virtual void event(); virtual void resetCounters(unsigned long oldCc); bool isHighState() const { return high_; } void nr1Change(unsigned newNr1, unsigned long cc); void nr3Change(unsigned newNr3, unsigned long cc); void nr4Change(unsigned newNr4, unsigned long cc); void reset(); void saveState(SaveState::SPU::Duty &dstate, unsigned long cc); void loadState(SaveState::SPU::Duty const &dstate, unsigned nr1, unsigned nr4, unsigned long cc); void killCounter(); void reviveCounter(unsigned long cc); //intended for use by SweepUnit only. unsigned freq() const { return 2048 - (period_ >> 1); } void setFreq(unsigned newFreq, unsigned long cc); private: unsigned long nextPosUpdate_; unsigned short period_; unsigned char pos_; unsigned char duty_; unsigned char inc_; bool high_; bool enableEvents_; void setCounter(); void setDuty(unsigned nr1); void updatePos(unsigned long cc); }; class DutyMasterDisabler : public MasterDisabler { public: DutyMasterDisabler(bool &m, DutyUnit &dutyUnit) : MasterDisabler(m), dutyUnit_(dutyUnit) {} virtual void operator()() { MasterDisabler::operator()(); dutyUnit_.killCounter(); } private: DutyUnit &dutyUnit_; }; } #endif libgambatte/libretro/libretro.h000664 001750 001750 00000300744 12720365247 020012 0ustar00sergiosergio000000 000000 /* Copyright (C) 2010-2016 The RetroArch team * * --------------------------------------------------------------------------------------- * The following license statement only applies to this libretro API header (libretro.h). * --------------------------------------------------------------------------------------- * * Permission is hereby granted, free of charge, * to any person obtaining a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef LIBRETRO_H__ #define LIBRETRO_H__ #include #include #include #ifdef __cplusplus extern "C" { #endif #ifndef __cplusplus #if defined(_MSC_VER) && !defined(SN_TARGET_PS3) /* Hack applied for MSVC when compiling in C89 mode * as it isn't C99-compliant. */ #define bool unsigned char #define true 1 #define false 0 #else #include #endif #endif #ifndef RETRO_CALLCONV # if defined(__GNUC__) && defined(__i386__) && !defined(__x86_64__) # define RETRO_CALLCONV __attribute__((cdecl)) # elif defined(_MSC_VER) && defined(_M_X86) && !defined(_M_X64) # define RETRO_CALLCONV __cdecl # else # define RETRO_CALLCONV /* all other platforms only have one calling convention each */ # endif #endif #ifndef RETRO_API # if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) # ifdef RETRO_IMPORT_SYMBOLS # ifdef __GNUC__ # define RETRO_API RETRO_CALLCONV __attribute__((__dllimport__)) # else # define RETRO_API RETRO_CALLCONV __declspec(dllimport) # endif # else # ifdef __GNUC__ # define RETRO_API RETRO_CALLCONV __attribute__((__dllexport__)) # else # define RETRO_API RETRO_CALLCONV __declspec(dllexport) # endif # endif # else # if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__CELLOS_LV2__) # define RETRO_API RETRO_CALLCONV __attribute__((__visibility__("default"))) # else # define RETRO_API RETRO_CALLCONV # endif # endif #endif /* Used for checking API/ABI mismatches that can break libretro * implementations. * It is not incremented for compatible changes to the API. */ #define RETRO_API_VERSION 1 /* * Libretro's fundamental device abstractions. * * Libretro's input system consists of some standardized device types, * such as a joypad (with/without analog), mouse, keyboard, lightgun * and a pointer. * * The functionality of these devices are fixed, and individual cores * map their own concept of a controller to libretro's abstractions. * This makes it possible for frontends to map the abstract types to a * real input device, and not having to worry about binding input * correctly to arbitrary controller layouts. */ #define RETRO_DEVICE_TYPE_SHIFT 8 #define RETRO_DEVICE_MASK ((1 << RETRO_DEVICE_TYPE_SHIFT) - 1) #define RETRO_DEVICE_SUBCLASS(base, id) (((id + 1) << RETRO_DEVICE_TYPE_SHIFT) | base) /* Input disabled. */ #define RETRO_DEVICE_NONE 0 /* The JOYPAD is called RetroPad. It is essentially a Super Nintendo * controller, but with additional L2/R2/L3/R3 buttons, similar to a * PS1 DualShock. */ #define RETRO_DEVICE_JOYPAD 1 /* The mouse is a simple mouse, similar to Super Nintendo's mouse. * X and Y coordinates are reported relatively to last poll (poll callback). * It is up to the libretro implementation to keep track of where the mouse * pointer is supposed to be on the screen. * The frontend must make sure not to interfere with its own hardware * mouse pointer. */ #define RETRO_DEVICE_MOUSE 2 /* KEYBOARD device lets one poll for raw key pressed. * It is poll based, so input callback will return with the current * pressed state. * For event/text based keyboard input, see * RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. */ #define RETRO_DEVICE_KEYBOARD 3 /* Lightgun X/Y coordinates are reported relatively to last poll, * similar to mouse. */ #define RETRO_DEVICE_LIGHTGUN 4 /* The ANALOG device is an extension to JOYPAD (RetroPad). * Similar to DualShock it adds two analog sticks. * This is treated as a separate device type as it returns values in the * full analog range of [-0x8000, 0x7fff]. Positive X axis is right. * Positive Y axis is down. * Only use ANALOG type when polling for analog values of the axes. */ #define RETRO_DEVICE_ANALOG 5 /* Abstracts the concept of a pointing mechanism, e.g. touch. * This allows libretro to query in absolute coordinates where on the * screen a mouse (or something similar) is being placed. * For a touch centric device, coordinates reported are the coordinates * of the press. * * Coordinates in X and Y are reported as: * [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen, * and 0x7fff corresponds to the far right/bottom of the screen. * The "screen" is here defined as area that is passed to the frontend and * later displayed on the monitor. * * The frontend is free to scale/resize this screen as it sees fit, however, * (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the * game image, etc. * * To check if the pointer coordinates are valid (e.g. a touch display * actually being touched), PRESSED returns 1 or 0. * * If using a mouse on a desktop, PRESSED will usually correspond to the * left mouse button, but this is a frontend decision. * PRESSED will only return 1 if the pointer is inside the game screen. * * For multi-touch, the index variable can be used to successively query * more presses. * If index = 0 returns true for _PRESSED, coordinates can be extracted * with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with * index = 1, and so on. * Eventually _PRESSED will return false for an index. No further presses * are registered at this point. */ #define RETRO_DEVICE_POINTER 6 /* Buttons for the RetroPad (JOYPAD). * The placement of these is equivalent to placements on the * Super Nintendo controller. * L2/R2/L3/R3 buttons correspond to the PS1 DualShock. */ #define RETRO_DEVICE_ID_JOYPAD_B 0 #define RETRO_DEVICE_ID_JOYPAD_Y 1 #define RETRO_DEVICE_ID_JOYPAD_SELECT 2 #define RETRO_DEVICE_ID_JOYPAD_START 3 #define RETRO_DEVICE_ID_JOYPAD_UP 4 #define RETRO_DEVICE_ID_JOYPAD_DOWN 5 #define RETRO_DEVICE_ID_JOYPAD_LEFT 6 #define RETRO_DEVICE_ID_JOYPAD_RIGHT 7 #define RETRO_DEVICE_ID_JOYPAD_A 8 #define RETRO_DEVICE_ID_JOYPAD_X 9 #define RETRO_DEVICE_ID_JOYPAD_L 10 #define RETRO_DEVICE_ID_JOYPAD_R 11 #define RETRO_DEVICE_ID_JOYPAD_L2 12 #define RETRO_DEVICE_ID_JOYPAD_R2 13 #define RETRO_DEVICE_ID_JOYPAD_L3 14 #define RETRO_DEVICE_ID_JOYPAD_R3 15 /* Index / Id values for ANALOG device. */ #define RETRO_DEVICE_INDEX_ANALOG_LEFT 0 #define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1 #define RETRO_DEVICE_ID_ANALOG_X 0 #define RETRO_DEVICE_ID_ANALOG_Y 1 /* Id values for MOUSE. */ #define RETRO_DEVICE_ID_MOUSE_X 0 #define RETRO_DEVICE_ID_MOUSE_Y 1 #define RETRO_DEVICE_ID_MOUSE_LEFT 2 #define RETRO_DEVICE_ID_MOUSE_RIGHT 3 #define RETRO_DEVICE_ID_MOUSE_WHEELUP 4 #define RETRO_DEVICE_ID_MOUSE_WHEELDOWN 5 #define RETRO_DEVICE_ID_MOUSE_MIDDLE 6 #define RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP 7 #define RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN 8 /* Id values for LIGHTGUN types. */ #define RETRO_DEVICE_ID_LIGHTGUN_X 0 #define RETRO_DEVICE_ID_LIGHTGUN_Y 1 #define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2 #define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3 #define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4 #define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5 #define RETRO_DEVICE_ID_LIGHTGUN_START 6 /* Id values for POINTER. */ #define RETRO_DEVICE_ID_POINTER_X 0 #define RETRO_DEVICE_ID_POINTER_Y 1 #define RETRO_DEVICE_ID_POINTER_PRESSED 2 /* Returned from retro_get_region(). */ #define RETRO_REGION_NTSC 0 #define RETRO_REGION_PAL 1 /* Id values for LANGUAGE */ enum retro_language { RETRO_LANGUAGE_ENGLISH = 0, RETRO_LANGUAGE_JAPANESE = 1, RETRO_LANGUAGE_FRENCH = 2, RETRO_LANGUAGE_SPANISH = 3, RETRO_LANGUAGE_GERMAN = 4, RETRO_LANGUAGE_ITALIAN = 5, RETRO_LANGUAGE_DUTCH = 6, RETRO_LANGUAGE_PORTUGUESE = 7, RETRO_LANGUAGE_RUSSIAN = 8, RETRO_LANGUAGE_KOREAN = 9, RETRO_LANGUAGE_CHINESE_TRADITIONAL = 10, RETRO_LANGUAGE_CHINESE_SIMPLIFIED = 11, RETRO_LANGUAGE_ESPERANTO = 12, RETRO_LANGUAGE_POLISH = 13, RETRO_LANGUAGE_LAST, /* Ensure sizeof(enum) == sizeof(int) */ RETRO_LANGUAGE_DUMMY = INT_MAX }; /* Passed to retro_get_memory_data/size(). * If the memory type doesn't apply to the * implementation NULL/0 can be returned. */ #define RETRO_MEMORY_MASK 0xff /* Regular save RAM. This RAM is usually found on a game cartridge, * backed up by a battery. * If save game data is too complex for a single memory buffer, * the SAVE_DIRECTORY (preferably) or SYSTEM_DIRECTORY environment * callback can be used. */ #define RETRO_MEMORY_SAVE_RAM 0 /* Some games have a built-in clock to keep track of time. * This memory is usually just a couple of bytes to keep track of time. */ #define RETRO_MEMORY_RTC 1 /* System ram lets a frontend peek into a game systems main RAM. */ #define RETRO_MEMORY_SYSTEM_RAM 2 /* Video ram lets a frontend peek into a game systems video RAM (VRAM). */ #define RETRO_MEMORY_VIDEO_RAM 3 /* Keysyms used for ID in input state callback when polling RETRO_KEYBOARD. */ enum retro_key { RETROK_UNKNOWN = 0, RETROK_FIRST = 0, RETROK_BACKSPACE = 8, RETROK_TAB = 9, RETROK_CLEAR = 12, RETROK_RETURN = 13, RETROK_PAUSE = 19, RETROK_ESCAPE = 27, RETROK_SPACE = 32, RETROK_EXCLAIM = 33, RETROK_QUOTEDBL = 34, RETROK_HASH = 35, RETROK_DOLLAR = 36, RETROK_AMPERSAND = 38, RETROK_QUOTE = 39, RETROK_LEFTPAREN = 40, RETROK_RIGHTPAREN = 41, RETROK_ASTERISK = 42, RETROK_PLUS = 43, RETROK_COMMA = 44, RETROK_MINUS = 45, RETROK_PERIOD = 46, RETROK_SLASH = 47, RETROK_0 = 48, RETROK_1 = 49, RETROK_2 = 50, RETROK_3 = 51, RETROK_4 = 52, RETROK_5 = 53, RETROK_6 = 54, RETROK_7 = 55, RETROK_8 = 56, RETROK_9 = 57, RETROK_COLON = 58, RETROK_SEMICOLON = 59, RETROK_LESS = 60, RETROK_EQUALS = 61, RETROK_GREATER = 62, RETROK_QUESTION = 63, RETROK_AT = 64, RETROK_LEFTBRACKET = 91, RETROK_BACKSLASH = 92, RETROK_RIGHTBRACKET = 93, RETROK_CARET = 94, RETROK_UNDERSCORE = 95, RETROK_BACKQUOTE = 96, RETROK_a = 97, RETROK_b = 98, RETROK_c = 99, RETROK_d = 100, RETROK_e = 101, RETROK_f = 102, RETROK_g = 103, RETROK_h = 104, RETROK_i = 105, RETROK_j = 106, RETROK_k = 107, RETROK_l = 108, RETROK_m = 109, RETROK_n = 110, RETROK_o = 111, RETROK_p = 112, RETROK_q = 113, RETROK_r = 114, RETROK_s = 115, RETROK_t = 116, RETROK_u = 117, RETROK_v = 118, RETROK_w = 119, RETROK_x = 120, RETROK_y = 121, RETROK_z = 122, RETROK_DELETE = 127, RETROK_KP0 = 256, RETROK_KP1 = 257, RETROK_KP2 = 258, RETROK_KP3 = 259, RETROK_KP4 = 260, RETROK_KP5 = 261, RETROK_KP6 = 262, RETROK_KP7 = 263, RETROK_KP8 = 264, RETROK_KP9 = 265, RETROK_KP_PERIOD = 266, RETROK_KP_DIVIDE = 267, RETROK_KP_MULTIPLY = 268, RETROK_KP_MINUS = 269, RETROK_KP_PLUS = 270, RETROK_KP_ENTER = 271, RETROK_KP_EQUALS = 272, RETROK_UP = 273, RETROK_DOWN = 274, RETROK_RIGHT = 275, RETROK_LEFT = 276, RETROK_INSERT = 277, RETROK_HOME = 278, RETROK_END = 279, RETROK_PAGEUP = 280, RETROK_PAGEDOWN = 281, RETROK_F1 = 282, RETROK_F2 = 283, RETROK_F3 = 284, RETROK_F4 = 285, RETROK_F5 = 286, RETROK_F6 = 287, RETROK_F7 = 288, RETROK_F8 = 289, RETROK_F9 = 290, RETROK_F10 = 291, RETROK_F11 = 292, RETROK_F12 = 293, RETROK_F13 = 294, RETROK_F14 = 295, RETROK_F15 = 296, RETROK_NUMLOCK = 300, RETROK_CAPSLOCK = 301, RETROK_SCROLLOCK = 302, RETROK_RSHIFT = 303, RETROK_LSHIFT = 304, RETROK_RCTRL = 305, RETROK_LCTRL = 306, RETROK_RALT = 307, RETROK_LALT = 308, RETROK_RMETA = 309, RETROK_LMETA = 310, RETROK_LSUPER = 311, RETROK_RSUPER = 312, RETROK_MODE = 313, RETROK_COMPOSE = 314, RETROK_HELP = 315, RETROK_PRINT = 316, RETROK_SYSREQ = 317, RETROK_BREAK = 318, RETROK_MENU = 319, RETROK_POWER = 320, RETROK_EURO = 321, RETROK_UNDO = 322, RETROK_LAST, RETROK_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */ }; enum retro_mod { RETROKMOD_NONE = 0x0000, RETROKMOD_SHIFT = 0x01, RETROKMOD_CTRL = 0x02, RETROKMOD_ALT = 0x04, RETROKMOD_META = 0x08, RETROKMOD_NUMLOCK = 0x10, RETROKMOD_CAPSLOCK = 0x20, RETROKMOD_SCROLLOCK = 0x40, RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */ }; /* If set, this call is not part of the public libretro API yet. It can * change or be removed at any time. */ #define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000 /* Environment callback to be used internally in frontend. */ #define RETRO_ENVIRONMENT_PRIVATE 0x20000 /* Environment commands. */ #define RETRO_ENVIRONMENT_SET_ROTATION 1 /* const unsigned * -- * Sets screen rotation of graphics. * Is only implemented if rotation can be accelerated by hardware. * Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180, * 270 degrees counter-clockwise respectively. */ #define RETRO_ENVIRONMENT_GET_OVERSCAN 2 /* bool * -- * Boolean value whether or not the implementation should use overscan, * or crop away overscan. */ #define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 /* bool * -- * Boolean value whether or not frontend supports frame duping, * passing NULL to video frame callback. */ /* Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES), * and reserved to avoid possible ABI clash. */ #define RETRO_ENVIRONMENT_SET_MESSAGE 6 /* const struct retro_message * -- * Sets a message to be displayed in implementation-specific manner * for a certain amount of 'frames'. * Should not be used for trivial messages, which should simply be * logged via RETRO_ENVIRONMENT_GET_LOG_INTERFACE (or as a * fallback, stderr). */ #define RETRO_ENVIRONMENT_SHUTDOWN 7 /* N/A (NULL) -- * Requests the frontend to shutdown. * Should only be used if game has a specific * way to shutdown the game from a menu item or similar. */ #define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8 /* const unsigned * -- * Gives a hint to the frontend how demanding this implementation * is on a system. E.g. reporting a level of 2 means * this implementation should run decently on all frontends * of level 2 and up. * * It can be used by the frontend to potentially warn * about too demanding implementations. * * The levels are "floating". * * This function can be called on a per-game basis, * as certain games an implementation can play might be * particularly demanding. * If called, it should be called in retro_load_game(). */ #define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9 /* const char ** -- * Returns the "system" directory of the frontend. * This directory can be used to store system specific * content such as BIOSes, configuration data, etc. * The returned value can be NULL. * If so, no such directory is defined, * and it's up to the implementation to find a suitable directory. * * NOTE: Some cores used this folder also for "save" data such as * memory cards, etc, for lack of a better place to put it. * This is now discouraged, and if possible, cores should try to * use the new GET_SAVE_DIRECTORY. */ #define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10 /* const enum retro_pixel_format * -- * Sets the internal pixel format used by the implementation. * The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555. * This pixel format however, is deprecated (see enum retro_pixel_format). * If the call returns false, the frontend does not support this pixel * format. * * This function should be called inside retro_load_game() or * retro_get_system_av_info(). */ #define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11 /* const struct retro_input_descriptor * -- * Sets an array of retro_input_descriptors. * It is up to the frontend to present this in a usable way. * The array is terminated by retro_input_descriptor::description * being set to NULL. * This function can be called at any time, but it is recommended * to call it as early as possible. */ #define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12 /* const struct retro_keyboard_callback * -- * Sets a callback function used to notify core about keyboard events. */ #define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13 /* const struct retro_disk_control_callback * -- * Sets an interface which frontend can use to eject and insert * disk images. * This is used for games which consist of multiple images and * must be manually swapped out by the user (e.g. PSX). */ #define RETRO_ENVIRONMENT_SET_HW_RENDER 14 /* struct retro_hw_render_callback * -- * Sets an interface to let a libretro core render with * hardware acceleration. * Should be called in retro_load_game(). * If successful, libretro cores will be able to render to a * frontend-provided framebuffer. * The size of this framebuffer will be at least as large as * max_width/max_height provided in get_av_info(). * If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or * NULL to retro_video_refresh_t. */ #define RETRO_ENVIRONMENT_GET_VARIABLE 15 /* struct retro_variable * -- * Interface to acquire user-defined information from environment * that cannot feasibly be supported in a multi-system way. * 'key' should be set to a key which has already been set by * SET_VARIABLES. * 'data' will be set to a value or NULL. */ #define RETRO_ENVIRONMENT_SET_VARIABLES 16 /* const struct retro_variable * -- * Allows an implementation to signal the environment * which variables it might want to check for later using * GET_VARIABLE. * This allows the frontend to present these variables to * a user dynamically. * This should be called as early as possible (ideally in * retro_set_environment). * * 'data' points to an array of retro_variable structs * terminated by a { NULL, NULL } element. * retro_variable::key should be namespaced to not collide * with other implementations' keys. E.g. A core called * 'foo' should use keys named as 'foo_option'. * retro_variable::value should contain a human readable * description of the key as well as a '|' delimited list * of expected values. * * The number of possible options should be very limited, * i.e. it should be feasible to cycle through options * without a keyboard. * * First entry should be treated as a default. * * Example entry: * { "foo_option", "Speed hack coprocessor X; false|true" } * * Text before first ';' is description. This ';' must be * followed by a space, and followed by a list of possible * values split up with '|'. * * Only strings are operated on. The possible values will * generally be displayed and stored as-is by the frontend. */ #define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17 /* bool * -- * Result is set to true if some variables are updated by * frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE. * Variables should be queried with GET_VARIABLE. */ #define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18 /* const bool * -- * If true, the libretro implementation supports calls to * retro_load_game() with NULL as argument. * Used by cores which can run without particular game data. * This should be called within retro_set_environment() only. */ #define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19 /* const char ** -- * Retrieves the absolute path from where this libretro * implementation was loaded. * NULL is returned if the libretro was loaded statically * (i.e. linked statically to frontend), or if the path cannot be * determined. * Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can * be loaded without ugly hacks. */ /* Environment 20 was an obsolete version of SET_AUDIO_CALLBACK. * It was not used by any known core at the time, * and was removed from the API. */ #define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22 /* const struct retro_audio_callback * -- * Sets an interface which is used to notify a libretro core about audio * being available for writing. * The callback can be called from any thread, so a core using this must * have a thread safe audio implementation. * It is intended for games where audio and video are completely * asynchronous and audio can be generated on the fly. * This interface is not recommended for use with emulators which have * highly synchronous audio. * * The callback only notifies about writability; the libretro core still * has to call the normal audio callbacks * to write audio. The audio callbacks must be called from within the * notification callback. * The amount of audio data to write is up to the implementation. * Generally, the audio callback will be called continously in a loop. * * Due to thread safety guarantees and lack of sync between audio and * video, a frontend can selectively disallow this interface based on * internal configuration. A core using this interface must also * implement the "normal" audio interface. * * A libretro core using SET_AUDIO_CALLBACK should also make use of * SET_FRAME_TIME_CALLBACK. */ #define RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK 21 /* const struct retro_frame_time_callback * -- * Lets the core know how much time has passed since last * invocation of retro_run(). * The frontend can tamper with the timing to fake fast-forward, * slow-motion, frame stepping, etc. * In this case the delta time will use the reference value * in frame_time_callback.. */ #define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE 23 /* struct retro_rumble_interface * -- * Gets an interface which is used by a libretro core to set * state of rumble motors in controllers. * A strong and weak motor is supported, and they can be * controlled indepedently. */ #define RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES 24 /* uint64_t * -- * Gets a bitmask telling which device type are expected to be * handled properly in a call to retro_input_state_t. * Devices which are not handled or recognized always return * 0 in retro_input_state_t. * Example bitmask: caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG). * Should only be called in retro_run(). */ #define RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE (25 | RETRO_ENVIRONMENT_EXPERIMENTAL) /* struct retro_sensor_interface * -- * Gets access to the sensor interface. * The purpose of this interface is to allow * setting state related to sensors such as polling rate, * enabling/disable it entirely, etc. * Reading sensor state is done via the normal * input_state_callback API. */ #define RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE (26 | RETRO_ENVIRONMENT_EXPERIMENTAL) /* struct retro_camera_callback * -- * Gets an interface to a video camera driver. * A libretro core can use this interface to get access to a * video camera. * New video frames are delivered in a callback in same * thread as retro_run(). * * GET_CAMERA_INTERFACE should be called in retro_load_game(). * * Depending on the camera implementation used, camera frames * will be delivered as a raw framebuffer, * or as an OpenGL texture directly. * * The core has to tell the frontend here which types of * buffers can be handled properly. * An OpenGL texture can only be handled when using a * libretro GL core (SET_HW_RENDER). * It is recommended to use a libretro GL core when * using camera interface. * * The camera is not started automatically. The retrieved start/stop * functions must be used to explicitly * start and stop the camera driver. */ #define RETRO_ENVIRONMENT_GET_LOG_INTERFACE 27 /* struct retro_log_callback * -- * Gets an interface for logging. This is useful for * logging in a cross-platform way * as certain platforms cannot use use stderr for logging. * It also allows the frontend to * show logging information in a more suitable way. * If this interface is not used, libretro cores should * log to stderr as desired. */ #define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28 /* struct retro_perf_callback * -- * Gets an interface for performance counters. This is useful * for performance logging in a cross-platform way and for detecting * architecture-specific features, such as SIMD support. */ #define RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE 29 /* struct retro_location_callback * -- * Gets access to the location interface. * The purpose of this interface is to be able to retrieve * location-based information from the host device, * such as current latitude / longitude. */ #define RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY 30 /* Old name, kept for compatibility. */ #define RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY 30 /* const char ** -- * Returns the "core assets" directory of the frontend. * This directory can be used to store specific assets that the * core relies upon, such as art assets, * input data, etc etc. * The returned value can be NULL. * If so, no such directory is defined, * and it's up to the implementation to find a suitable directory. */ #define RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY 31 /* const char ** -- * Returns the "save" directory of the frontend. * This directory can be used to store SRAM, memory cards, * high scores, etc, if the libretro core * cannot use the regular memory interface (retro_get_memory_data()). * * NOTE: libretro cores used to check GET_SYSTEM_DIRECTORY for * similar things before. * They should still check GET_SYSTEM_DIRECTORY if they want to * be backwards compatible. * The path here can be NULL. It should only be non-NULL if the * frontend user has set a specific save path. */ #define RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO 32 /* const struct retro_system_av_info * -- * Sets a new av_info structure. This can only be called from * within retro_run(). * This should *only* be used if the core is completely altering the * internal resolutions, aspect ratios, timings, sampling rate, etc. * Calling this can require a full reinitialization of video/audio * drivers in the frontend, * * so it is important to call it very sparingly, and usually only with * the users explicit consent. * An eventual driver reinitialize will happen so that video and * audio callbacks * happening after this call within the same retro_run() call will * target the newly initialized driver. * * This callback makes it possible to support configurable resolutions * in games, which can be useful to * avoid setting the "worst case" in max_width/max_height. * * ***HIGHLY RECOMMENDED*** Do not call this callback every time * resolution changes in an emulator core if it's * expected to be a temporary change, for the reasons of possible * driver reinitialization. * This call is not a free pass for not trying to provide * correct values in retro_get_system_av_info(). If you need to change * things like aspect ratio or nominal width/height, * use RETRO_ENVIRONMENT_SET_GEOMETRY, which is a softer variant * of SET_SYSTEM_AV_INFO. * * If this returns false, the frontend does not acknowledge a * changed av_info struct. */ #define RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK 33 /* const struct retro_get_proc_address_interface * -- * Allows a libretro core to announce support for the * get_proc_address() interface. * This interface allows for a standard way to extend libretro where * use of environment calls are too indirect, * e.g. for cases where the frontend wants to call directly into the core. * * If a core wants to expose this interface, SET_PROC_ADDRESS_CALLBACK * **MUST** be called from within retro_set_environment(). */ #define RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO 34 /* const struct retro_subsystem_info * -- * This environment call introduces the concept of libretro "subsystems". * A subsystem is a variant of a libretro core which supports * different kinds of games. * The purpose of this is to support e.g. emulators which might * have special needs, e.g. Super Nintendo's Super GameBoy, Sufami Turbo. * It can also be used to pick among subsystems in an explicit way * if the libretro implementation is a multi-system emulator itself. * * Loading a game via a subsystem is done with retro_load_game_special(), * and this environment call allows a libretro core to expose which * subsystems are supported for use with retro_load_game_special(). * A core passes an array of retro_game_special_info which is terminated * with a zeroed out retro_game_special_info struct. * * If a core wants to use this functionality, SET_SUBSYSTEM_INFO * **MUST** be called from within retro_set_environment(). */ #define RETRO_ENVIRONMENT_SET_CONTROLLER_INFO 35 /* const struct retro_controller_info * -- * This environment call lets a libretro core tell the frontend * which controller types are recognized in calls to * retro_set_controller_port_device(). * * Some emulators such as Super Nintendo * support multiple lightgun types which must be specifically * selected from. * It is therefore sometimes necessary for a frontend to be able * to tell the core about a special kind of input device which is * not covered by the libretro input API. * * In order for a frontend to understand the workings of an input device, * it must be a specialized type * of the generic device types already defined in the libretro API. * * Which devices are supported can vary per input port. * The core must pass an array of const struct retro_controller_info which * is terminated with a blanked out struct. Each element of the struct * corresponds to an ascending port index to * retro_set_controller_port_device(). * Even if special device types are set in the libretro core, * libretro should only poll input based on the base input device types. */ #define RETRO_ENVIRONMENT_SET_MEMORY_MAPS (36 | RETRO_ENVIRONMENT_EXPERIMENTAL) /* const struct retro_memory_map * -- * This environment call lets a libretro core tell the frontend * about the memory maps this core emulates. * This can be used to implement, for example, cheats in a core-agnostic way. * * Should only be used by emulators; it doesn't make much sense for * anything else. * It is recommended to expose all relevant pointers through * retro_get_memory_* as well. * * Can be called from retro_init and retro_load_game. */ #define RETRO_ENVIRONMENT_SET_GEOMETRY 37 /* const struct retro_game_geometry * -- * This environment call is similar to SET_SYSTEM_AV_INFO for changing * video parameters, but provides a guarantee that drivers will not be * reinitialized. * This can only be called from within retro_run(). * * The purpose of this call is to allow a core to alter nominal * width/heights as well as aspect ratios on-the-fly, which can be * useful for some emulators to change in run-time. * * max_width/max_height arguments are ignored and cannot be changed * with this call as this could potentially require a reinitialization or a * non-constant time operation. * If max_width/max_height are to be changed, SET_SYSTEM_AV_INFO is required. * * A frontend must guarantee that this environment call completes in * constant time. */ #define RETRO_ENVIRONMENT_GET_USERNAME 38 /* const char ** * Returns the specified username of the frontend, if specified by the user. * This username can be used as a nickname for a core that has online facilities * or any other mode where personalization of the user is desirable. * The returned value can be NULL. * If this environ callback is used by a core that requires a valid username, * a default username should be specified by the core. */ #define RETRO_ENVIRONMENT_GET_LANGUAGE 39 /* unsigned * -- * Returns the specified language of the frontend, if specified by the user. * It can be used by the core for localization purposes. */ #define RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER (40 | RETRO_ENVIRONMENT_EXPERIMENTAL) /* struct retro_framebuffer * -- * Returns a preallocated framebuffer which the core can use for rendering * the frame into when not using SET_HW_RENDER. * The framebuffer returned from this call must not be used * after the current call to retro_run() returns. * * The goal of this call is to allow zero-copy behavior where a core * can render directly into video memory, avoiding extra bandwidth cost by copying * memory from core to video memory. * * If this call succeeds and the core renders into it, * the framebuffer pointer and pitch can be passed to retro_video_refresh_t. * If the buffer from GET_CURRENT_SOFTWARE_FRAMEBUFFER is to be used, * the core must pass the exact * same pointer as returned by GET_CURRENT_SOFTWARE_FRAMEBUFFER; * i.e. passing a pointer which is offset from the * buffer is undefined. The width, height and pitch parameters * must also match exactly to the values obtained from GET_CURRENT_SOFTWARE_FRAMEBUFFER. * * It is possible for a frontend to return a different pixel format * than the one used in SET_PIXEL_FORMAT. This can happen if the frontend * needs to perform conversion. * * It is still valid for a core to render to a different buffer * even if GET_CURRENT_SOFTWARE_FRAMEBUFFER succeeds. * * A frontend must make sure that the pointer obtained from this function is * writeable (and readable). */ enum retro_hw_render_interface_type { RETRO_HW_RENDER_INTERFACE_VULKAN = 0, RETRO_HW_RENDER_INTERFACE_DUMMY = INT_MAX }; /* Base struct. All retro_hw_render_interface_* types * contain at least these fields. */ struct retro_hw_render_interface { enum retro_hw_render_interface_type interface_type; unsigned interface_version; }; #define RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE (41 | RETRO_ENVIRONMENT_EXPERIMENTAL) /* const struct retro_hw_render_interface ** -- * Returns an API specific rendering interface for accessing API specific data. * Not all HW rendering APIs support or need this. * The contents of the returned pointer is specific to the rendering API * being used. See the various headers like libretro_vulkan.h, etc. * * GET_HW_RENDER_INTERFACE cannot be called before context_reset has been called. * Similarly, after context_destroyed callback returns, * the contents of the HW_RENDER_INTERFACE are invalidated. */ #define RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS (42 | RETRO_ENVIRONMENT_EXPERIMENTAL) /* const bool * -- * If true, the libretro implementation supports achievements * either via memory descriptors set with RETRO_ENVIRONMENT_SET_MEMORY_MAPS * or via retro_get_memory_data/retro_get_memory_size. * * This must be called before the first call to retro_run. */ #define RETRO_MEMDESC_CONST (1 << 0) /* The frontend will never change this memory area once retro_load_game has returned. */ #define RETRO_MEMDESC_BIGENDIAN (1 << 1) /* The memory area contains big endian data. Default is little endian. */ #define RETRO_MEMDESC_ALIGN_2 (1 << 16) /* All memory access in this area is aligned to their own size, or 2, whichever is smaller. */ #define RETRO_MEMDESC_ALIGN_4 (2 << 16) #define RETRO_MEMDESC_ALIGN_8 (3 << 16) #define RETRO_MEMDESC_MINSIZE_2 (1 << 24) /* All memory in this region is accessed at least 2 bytes at the time. */ #define RETRO_MEMDESC_MINSIZE_4 (2 << 24) #define RETRO_MEMDESC_MINSIZE_8 (3 << 24) struct retro_memory_descriptor { uint64_t flags; /* Pointer to the start of the relevant ROM or RAM chip. * It's strongly recommended to use 'offset' if possible, rather than * doing math on the pointer. * * If the same byte is mapped my multiple descriptors, their descriptors * must have the same pointer. * If 'start' does not point to the first byte in the pointer, put the * difference in 'offset' instead. * * May be NULL if there's nothing usable here (e.g. hardware registers and * open bus). No flags should be set if the pointer is NULL. * It's recommended to minimize the number of descriptors if possible, * but not mandatory. */ void *ptr; size_t offset; /* This is the location in the emulated address space * where the mapping starts. */ size_t start; /* Which bits must be same as in 'start' for this mapping to apply. * The first memory descriptor to claim a certain byte is the one * that applies. * A bit which is set in 'start' must also be set in this. * Can be zero, in which case each byte is assumed mapped exactly once. * In this case, 'len' must be a power of two. */ size_t select; /* If this is nonzero, the set bits are assumed not connected to the * memory chip's address pins. */ size_t disconnect; /* This one tells the size of the current memory area. * If, after start+disconnect are applied, the address is higher than * this, the highest bit of the address is cleared. * * If the address is still too high, the next highest bit is cleared. * Can be zero, in which case it's assumed to be infinite (as limited * by 'select' and 'disconnect'). */ size_t len; /* To go from emulated address to physical address, the following * order applies: * Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'. * * The address space name must consist of only a-zA-Z0-9_-, * should be as short as feasible (maximum length is 8 plus the NUL), * and may not be any other address space plus one or more 0-9A-F * at the end. * However, multiple memory descriptors for the same address space is * allowed, and the address space name can be empty. NULL is treated * as empty. * * Address space names are case sensitive, but avoid lowercase if possible. * The same pointer may exist in multiple address spaces. * * Examples: * blank+blank - valid (multiple things may be mapped in the same namespace) * 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace) * 'A'+'B' - valid (neither is a prefix of each other) * 'S'+blank - valid ('S' is not in 0-9A-F) * 'a'+blank - valid ('a' is not in 0-9A-F) * 'a'+'A' - valid (neither is a prefix of each other) * 'AR'+blank - valid ('R' is not in 0-9A-F) * 'ARB'+blank - valid (the B can't be part of the address either, because * there is no namespace 'AR') * blank+'B' - not valid, because it's ambigous which address space B1234 * would refer to. * The length can't be used for that purpose; the frontend may want * to append arbitrary data to an address, without a separator. */ const char *addrspace; }; /* The frontend may use the largest value of 'start'+'select' in a * certain namespace to infer the size of the address space. * * If the address space is larger than that, a mapping with .ptr=NULL * should be at the end of the array, with .select set to all ones for * as long as the address space is big. * * Sample descriptors (minus .ptr, and RETRO_MEMFLAG_ on the flags): * SNES WRAM: * .start=0x7E0000, .len=0x20000 * (Note that this must be mapped before the ROM in most cases; some of the * ROM mappers * try to claim $7E0000, or at least $7E8000.) * SNES SPC700 RAM: * .addrspace="S", .len=0x10000 * SNES WRAM mirrors: * .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000 * .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000 * SNES WRAM mirrors, alternate equivalent descriptor: * .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF * (Various similar constructions can be created by combining parts of * the above two.) * SNES LoROM (512KB, mirrored a couple of times): * .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024 * .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024 * SNES HiROM (4MB): * .flags=CONST, .start=0x400000, .select=0x400000, .len=4*1024*1024 * .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024 * SNES ExHiROM (8MB): * .flags=CONST, .offset=0, .start=0xC00000, .select=0xC00000, .len=4*1024*1024 * .flags=CONST, .offset=4*1024*1024, .start=0x400000, .select=0xC00000, .len=4*1024*1024 * .flags=CONST, .offset=0x8000, .start=0x808000, .select=0xC08000, .len=4*1024*1024 * .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024 * Clarify the size of the address space: * .ptr=NULL, .select=0xFFFFFF * .len can be implied by .select in many of them, but was included for clarity. */ struct retro_memory_map { const struct retro_memory_descriptor *descriptors; unsigned num_descriptors; }; struct retro_controller_description { /* Human-readable description of the controller. Even if using a generic * input device type, this can be set to the particular device type the * core uses. */ const char *desc; /* Device type passed to retro_set_controller_port_device(). If the device * type is a sub-class of a generic input device type, use the * RETRO_DEVICE_SUBCLASS macro to create an ID. * * E.g. RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1). */ unsigned id; }; struct retro_controller_info { const struct retro_controller_description *types; unsigned num_types; }; struct retro_subsystem_memory_info { /* The extension associated with a memory type, e.g. "psram". */ const char *extension; /* The memory type for retro_get_memory(). This should be at * least 0x100 to avoid conflict with standardized * libretro memory types. */ unsigned type; }; struct retro_subsystem_rom_info { /* Describes what the content is (SGB BIOS, GB ROM, etc). */ const char *desc; /* Same definition as retro_get_system_info(). */ const char *valid_extensions; /* Same definition as retro_get_system_info(). */ bool need_fullpath; /* Same definition as retro_get_system_info(). */ bool block_extract; /* This is set if the content is required to load a game. * If this is set to false, a zeroed-out retro_game_info can be passed. */ bool required; /* Content can have multiple associated persistent * memory types (retro_get_memory()). */ const struct retro_subsystem_memory_info *memory; unsigned num_memory; }; struct retro_subsystem_info { /* Human-readable string of the subsystem type, e.g. "Super GameBoy" */ const char *desc; /* A computer friendly short string identifier for the subsystem type. * This name must be [a-z]. * E.g. if desc is "Super GameBoy", this can be "sgb". * This identifier can be used for command-line interfaces, etc. */ const char *ident; /* Infos for each content file. The first entry is assumed to be the * "most significant" content for frontend purposes. * E.g. with Super GameBoy, the first content should be the GameBoy ROM, * as it is the most "significant" content to a user. * If a frontend creates new file paths based on the content used * (e.g. savestates), it should use the path for the first ROM to do so. */ const struct retro_subsystem_rom_info *roms; /* Number of content files associated with a subsystem. */ unsigned num_roms; /* The type passed to retro_load_game_special(). */ unsigned id; }; typedef void (*retro_proc_address_t)(void); /* libretro API extension functions: * (None here so far). * * Get a symbol from a libretro core. * Cores should only return symbols which are actual * extensions to the libretro API. * * Frontends should not use this to obtain symbols to standard * libretro entry points (static linking or dlsym). * * The symbol name must be equal to the function name, * e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo". * The returned function pointer must be cast to the corresponding type. */ typedef retro_proc_address_t (*retro_get_proc_address_t)(const char *sym); struct retro_get_proc_address_interface { retro_get_proc_address_t get_proc_address; }; enum retro_log_level { RETRO_LOG_DEBUG = 0, RETRO_LOG_INFO, RETRO_LOG_WARN, RETRO_LOG_ERROR, RETRO_LOG_DUMMY = INT_MAX }; /* Logging function. Takes log level argument as well. */ typedef void (*retro_log_printf_t)(enum retro_log_level level, const char *fmt, ...); struct retro_log_callback { retro_log_printf_t log; }; /* Performance related functions */ /* ID values for SIMD CPU features */ #define RETRO_SIMD_SSE (1 << 0) #define RETRO_SIMD_SSE2 (1 << 1) #define RETRO_SIMD_VMX (1 << 2) #define RETRO_SIMD_VMX128 (1 << 3) #define RETRO_SIMD_AVX (1 << 4) #define RETRO_SIMD_NEON (1 << 5) #define RETRO_SIMD_SSE3 (1 << 6) #define RETRO_SIMD_SSSE3 (1 << 7) #define RETRO_SIMD_MMX (1 << 8) #define RETRO_SIMD_MMXEXT (1 << 9) #define RETRO_SIMD_SSE4 (1 << 10) #define RETRO_SIMD_SSE42 (1 << 11) #define RETRO_SIMD_AVX2 (1 << 12) #define RETRO_SIMD_VFPU (1 << 13) #define RETRO_SIMD_PS (1 << 14) #define RETRO_SIMD_AES (1 << 15) #define RETRO_SIMD_VFPV3 (1 << 16) #define RETRO_SIMD_VFPV4 (1 << 17) #define RETRO_SIMD_POPCNT (1 << 18) #define RETRO_SIMD_MOVBE (1 << 19) typedef uint64_t retro_perf_tick_t; typedef int64_t retro_time_t; struct retro_perf_counter { const char *ident; retro_perf_tick_t start; retro_perf_tick_t total; retro_perf_tick_t call_cnt; bool registered; }; /* Returns current time in microseconds. * Tries to use the most accurate timer available. */ typedef retro_time_t (*retro_perf_get_time_usec_t)(void); /* A simple counter. Usually nanoseconds, but can also be CPU cycles. * Can be used directly if desired (when creating a more sophisticated * performance counter system). * */ typedef retro_perf_tick_t (*retro_perf_get_counter_t)(void); /* Returns a bit-mask of detected CPU features (RETRO_SIMD_*). */ typedef uint64_t (*retro_get_cpu_features_t)(void); /* Asks frontend to log and/or display the state of performance counters. * Performance counters can always be poked into manually as well. */ typedef void (*retro_perf_log_t)(void); /* Register a performance counter. * ident field must be set with a discrete value and other values in * retro_perf_counter must be 0. * Registering can be called multiple times. To avoid calling to * frontend redundantly, you can check registered field first. */ typedef void (*retro_perf_register_t)(struct retro_perf_counter *counter); /* Starts a registered counter. */ typedef void (*retro_perf_start_t)(struct retro_perf_counter *counter); /* Stops a registered counter. */ typedef void (*retro_perf_stop_t)(struct retro_perf_counter *counter); /* For convenience it can be useful to wrap register, start and stop in macros. * E.g.: * #ifdef LOG_PERFORMANCE * #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name)) * #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name)) * #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name)) * #else * ... Blank macros ... * #endif * * These can then be used mid-functions around code snippets. * * extern struct retro_perf_callback perf_cb; * Somewhere in the core. * * void do_some_heavy_work(void) * { * RETRO_PERFORMANCE_INIT(cb, work_1; * RETRO_PERFORMANCE_START(cb, work_1); * heavy_work_1(); * RETRO_PERFORMANCE_STOP(cb, work_1); * * RETRO_PERFORMANCE_INIT(cb, work_2); * RETRO_PERFORMANCE_START(cb, work_2); * heavy_work_2(); * RETRO_PERFORMANCE_STOP(cb, work_2); * } * * void retro_deinit(void) * { * perf_cb.perf_log(); * Log all perf counters here for example. * } */ struct retro_perf_callback { retro_perf_get_time_usec_t get_time_usec; retro_get_cpu_features_t get_cpu_features; retro_perf_get_counter_t get_perf_counter; retro_perf_register_t perf_register; retro_perf_start_t perf_start; retro_perf_stop_t perf_stop; retro_perf_log_t perf_log; }; /* FIXME: Document the sensor API and work out behavior. * It will be marked as experimental until then. */ enum retro_sensor_action { RETRO_SENSOR_ACCELEROMETER_ENABLE = 0, RETRO_SENSOR_ACCELEROMETER_DISABLE, RETRO_SENSOR_DUMMY = INT_MAX }; /* Id values for SENSOR types. */ #define RETRO_SENSOR_ACCELEROMETER_X 0 #define RETRO_SENSOR_ACCELEROMETER_Y 1 #define RETRO_SENSOR_ACCELEROMETER_Z 2 typedef bool (*retro_set_sensor_state_t)(unsigned port, enum retro_sensor_action action, unsigned rate); typedef float (*retro_sensor_get_input_t)(unsigned port, unsigned id); struct retro_sensor_interface { retro_set_sensor_state_t set_sensor_state; retro_sensor_get_input_t get_sensor_input; }; enum retro_camera_buffer { RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0, RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER, RETRO_CAMERA_BUFFER_DUMMY = INT_MAX }; /* Starts the camera driver. Can only be called in retro_run(). */ typedef bool (*retro_camera_start_t)(void); /* Stops the camera driver. Can only be called in retro_run(). */ typedef void (*retro_camera_stop_t)(void); /* Callback which signals when the camera driver is initialized * and/or deinitialized. * retro_camera_start_t can be called in initialized callback. */ typedef void (*retro_camera_lifetime_status_t)(void); /* A callback for raw framebuffer data. buffer points to an XRGB8888 buffer. * Width, height and pitch are similar to retro_video_refresh_t. * First pixel is top-left origin. */ typedef void (*retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer, unsigned width, unsigned height, size_t pitch); /* A callback for when OpenGL textures are used. * * texture_id is a texture owned by camera driver. * Its state or content should be considered immutable, except for things like * texture filtering and clamping. * * texture_target is the texture target for the GL texture. * These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly * more depending on extensions. * * affine points to a packed 3x3 column-major matrix used to apply an affine * transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0)) * After transform, normalized texture coord (0, 0) should be bottom-left * and (1, 1) should be top-right (or (width, height) for RECTANGLE). * * GL-specific typedefs are avoided here to avoid relying on gl.h in * the API definition. */ typedef void (*retro_camera_frame_opengl_texture_t)(unsigned texture_id, unsigned texture_target, const float *affine); struct retro_camera_callback { /* Set by libretro core. * Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER). */ uint64_t caps; /* Desired resolution for camera. Is only used as a hint. */ unsigned width; unsigned height; /* Set by frontend. */ retro_camera_start_t start; retro_camera_stop_t stop; /* Set by libretro core if raw framebuffer callbacks will be used. */ retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer; /* Set by libretro core if OpenGL texture callbacks will be used. */ retro_camera_frame_opengl_texture_t frame_opengl_texture; /* Set by libretro core. Called after camera driver is initialized and * ready to be started. * Can be NULL, in which this callback is not called. */ retro_camera_lifetime_status_t initialized; /* Set by libretro core. Called right before camera driver is * deinitialized. * Can be NULL, in which this callback is not called. */ retro_camera_lifetime_status_t deinitialized; }; /* Sets the interval of time and/or distance at which to update/poll * location-based data. * * To ensure compatibility with all location-based implementations, * values for both interval_ms and interval_distance should be provided. * * interval_ms is the interval expressed in milliseconds. * interval_distance is the distance interval expressed in meters. */ typedef void (*retro_location_set_interval_t)(unsigned interval_ms, unsigned interval_distance); /* Start location services. The device will start listening for changes to the * current location at regular intervals (which are defined with * retro_location_set_interval_t). */ typedef bool (*retro_location_start_t)(void); /* Stop location services. The device will stop listening for changes * to the current location. */ typedef void (*retro_location_stop_t)(void); /* Get the position of the current location. Will set parameters to * 0 if no new location update has happened since the last time. */ typedef bool (*retro_location_get_position_t)(double *lat, double *lon, double *horiz_accuracy, double *vert_accuracy); /* Callback which signals when the location driver is initialized * and/or deinitialized. * retro_location_start_t can be called in initialized callback. */ typedef void (*retro_location_lifetime_status_t)(void); struct retro_location_callback { retro_location_start_t start; retro_location_stop_t stop; retro_location_get_position_t get_position; retro_location_set_interval_t set_interval; retro_location_lifetime_status_t initialized; retro_location_lifetime_status_t deinitialized; }; enum retro_rumble_effect { RETRO_RUMBLE_STRONG = 0, RETRO_RUMBLE_WEAK = 1, RETRO_RUMBLE_DUMMY = INT_MAX }; /* Sets rumble state for joypad plugged in port 'port'. * Rumble effects are controlled independently, * and setting e.g. strong rumble does not override weak rumble. * Strength has a range of [0, 0xffff]. * * Returns true if rumble state request was honored. * Calling this before first retro_run() is likely to return false. */ typedef bool (*retro_set_rumble_state_t)(unsigned port, enum retro_rumble_effect effect, uint16_t strength); struct retro_rumble_interface { retro_set_rumble_state_t set_rumble_state; }; /* Notifies libretro that audio data should be written. */ typedef void (*retro_audio_callback_t)(void); /* True: Audio driver in frontend is active, and callback is * expected to be called regularily. * False: Audio driver in frontend is paused or inactive. * Audio callback will not be called until set_state has been * called with true. * Initial state is false (inactive). */ typedef void (*retro_audio_set_state_callback_t)(bool enabled); struct retro_audio_callback { retro_audio_callback_t callback; retro_audio_set_state_callback_t set_state; }; /* Notifies a libretro core of time spent since last invocation * of retro_run() in microseconds. * * It will be called right before retro_run() every frame. * The frontend can tamper with timing to support cases like * fast-forward, slow-motion and framestepping. * * In those scenarios the reference frame time value will be used. */ typedef int64_t retro_usec_t; typedef void (*retro_frame_time_callback_t)(retro_usec_t usec); struct retro_frame_time_callback { retro_frame_time_callback_t callback; /* Represents the time of one frame. It is computed as * 1000000 / fps, but the implementation will resolve the * rounding to ensure that framestepping, etc is exact. */ retro_usec_t reference; }; /* Pass this to retro_video_refresh_t if rendering to hardware. * Passing NULL to retro_video_refresh_t is still a frame dupe as normal. * */ #define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1) /* Invalidates the current HW context. * Any GL state is lost, and must not be deinitialized explicitly. * If explicit deinitialization is desired by the libretro core, * it should implement context_destroy callback. * If called, all GPU resources must be reinitialized. * Usually called when frontend reinits video driver. * Also called first time video driver is initialized, * allowing libretro core to initialize resources. */ typedef void (*retro_hw_context_reset_t)(void); /* Gets current framebuffer which is to be rendered to. * Could change every frame potentially. */ typedef uintptr_t (*retro_hw_get_current_framebuffer_t)(void); /* Get a symbol from HW context. */ typedef retro_proc_address_t (*retro_hw_get_proc_address_t)(const char *sym); enum retro_hw_context_type { RETRO_HW_CONTEXT_NONE = 0, /* OpenGL 2.x. Driver can choose to use latest compatibility context. */ RETRO_HW_CONTEXT_OPENGL = 1, /* OpenGL ES 2.0. */ RETRO_HW_CONTEXT_OPENGLES2 = 2, /* Modern desktop core GL context. Use version_major/ * version_minor fields to set GL version. */ RETRO_HW_CONTEXT_OPENGL_CORE = 3, /* OpenGL ES 3.0 */ RETRO_HW_CONTEXT_OPENGLES3 = 4, /* OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3, * use the corresponding enums directly. */ RETRO_HW_CONTEXT_OPENGLES_VERSION = 5, /* Vulkan, see RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE. */ RETRO_HW_CONTEXT_VULKAN = 6, RETRO_HW_CONTEXT_DUMMY = INT_MAX }; struct retro_hw_render_callback { /* Which API to use. Set by libretro core. */ enum retro_hw_context_type context_type; /* Called when a context has been created or when it has been reset. * An OpenGL context is only valid after context_reset() has been called. * * When context_reset is called, OpenGL resources in the libretro * implementation are guaranteed to be invalid. * * It is possible that context_reset is called multiple times during an * application lifecycle. * If context_reset is called without any notification (context_destroy), * the OpenGL context was lost and resources should just be recreated * without any attempt to "free" old resources. */ retro_hw_context_reset_t context_reset; /* Set by frontend. * TODO: This is rather obsolete. The frontend should not * be providing preallocated framebuffers. */ retro_hw_get_current_framebuffer_t get_current_framebuffer; /* Set by frontend. */ retro_hw_get_proc_address_t get_proc_address; /* Set if render buffers should have depth component attached. * TODO: Obsolete. */ bool depth; /* Set if stencil buffers should be attached. * TODO: Obsolete. */ bool stencil; /* If depth and stencil are true, a packed 24/8 buffer will be added. * Only attaching stencil is invalid and will be ignored. */ /* Use conventional bottom-left origin convention. If false, * standard libretro top-left origin semantics are used. * TODO: Move to GL specific interface. */ bool bottom_left_origin; /* Major version number for core GL context or GLES 3.1+. */ unsigned version_major; /* Minor version number for core GL context or GLES 3.1+. */ unsigned version_minor; /* If this is true, the frontend will go very far to avoid * resetting context in scenarios like toggling fullscreen, etc. * TODO: Obsolete? Maybe frontend should just always assume this ... */ bool cache_context; /* The reset callback might still be called in extreme situations * such as if the context is lost beyond recovery. * * For optimal stability, set this to false, and allow context to be * reset at any time. */ /* A callback to be called before the context is destroyed in a * controlled way by the frontend. */ retro_hw_context_reset_t context_destroy; /* OpenGL resources can be deinitialized cleanly at this step. * context_destroy can be set to NULL, in which resources will * just be destroyed without any notification. * * Even when context_destroy is non-NULL, it is possible that * context_reset is called without any destroy notification. * This happens if context is lost by external factors (such as * notified by GL_ARB_robustness). * * In this case, the context is assumed to be already dead, * and the libretro implementation must not try to free any OpenGL * resources in the subsequent context_reset. */ /* Creates a debug context. */ bool debug_context; }; /* Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. * Called by the frontend in response to keyboard events. * down is set if the key is being pressed, or false if it is being released. * keycode is the RETROK value of the char. * character is the text character of the pressed key. (UTF-32). * key_modifiers is a set of RETROKMOD values or'ed together. * * The pressed/keycode state can be indepedent of the character. * It is also possible that multiple characters are generated from a * single keypress. * Keycode events should be treated separately from character events. * However, when possible, the frontend should try to synchronize these. * If only a character is posted, keycode should be RETROK_UNKNOWN. * * Similarily if only a keycode event is generated with no corresponding * character, character should be 0. */ typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers); struct retro_keyboard_callback { retro_keyboard_event_t callback; }; /* Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE. * Should be set for implementations which can swap out multiple disk * images in runtime. * * If the implementation can do this automatically, it should strive to do so. * However, there are cases where the user must manually do so. * * Overview: To swap a disk image, eject the disk image with * set_eject_state(true). * Set the disk index with set_image_index(index). Insert the disk again * with set_eject_state(false). */ /* If ejected is true, "ejects" the virtual disk tray. * When ejected, the disk image index can be set. */ typedef bool (*retro_set_eject_state_t)(bool ejected); /* Gets current eject state. The initial state is 'not ejected'. */ typedef bool (*retro_get_eject_state_t)(void); /* Gets current disk index. First disk is index 0. * If return value is >= get_num_images(), no disk is currently inserted. */ typedef unsigned (*retro_get_image_index_t)(void); /* Sets image index. Can only be called when disk is ejected. * The implementation supports setting "no disk" by using an * index >= get_num_images(). */ typedef bool (*retro_set_image_index_t)(unsigned index); /* Gets total number of images which are available to use. */ typedef unsigned (*retro_get_num_images_t)(void); struct retro_game_info; /* Replaces the disk image associated with index. * Arguments to pass in info have same requirements as retro_load_game(). * Virtual disk tray must be ejected when calling this. * * Replacing a disk image with info = NULL will remove the disk image * from the internal list. * As a result, calls to get_image_index() can change. * * E.g. replace_image_index(1, NULL), and previous get_image_index() * returned 4 before. * Index 1 will be removed, and the new index is 3. */ typedef bool (*retro_replace_image_index_t)(unsigned index, const struct retro_game_info *info); /* Adds a new valid index (get_num_images()) to the internal disk list. * This will increment subsequent return values from get_num_images() by 1. * This image index cannot be used until a disk image has been set * with replace_image_index. */ typedef bool (*retro_add_image_index_t)(void); struct retro_disk_control_callback { retro_set_eject_state_t set_eject_state; retro_get_eject_state_t get_eject_state; retro_get_image_index_t get_image_index; retro_set_image_index_t set_image_index; retro_get_num_images_t get_num_images; retro_replace_image_index_t replace_image_index; retro_add_image_index_t add_image_index; }; enum retro_pixel_format { /* 0RGB1555, native endian. * 0 bit must be set to 0. * This pixel format is default for compatibility concerns only. * If a 15/16-bit pixel format is desired, consider using RGB565. */ RETRO_PIXEL_FORMAT_0RGB1555 = 0, /* XRGB8888, native endian. * X bits are ignored. */ RETRO_PIXEL_FORMAT_XRGB8888 = 1, /* RGB565, native endian. * This pixel format is the recommended format to use if a 15/16-bit * format is desired as it is the pixel format that is typically * available on a wide range of low-power devices. * * It is also natively supported in APIs like OpenGL ES. */ RETRO_PIXEL_FORMAT_RGB565 = 2, /* Ensure sizeof() == sizeof(int). */ RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX }; struct retro_message { const char *msg; /* Message to be displayed. */ unsigned frames; /* Duration in frames of message. */ }; /* Describes how the libretro implementation maps a libretro input bind * to its internal input system through a human readable string. * This string can be used to better let a user configure input. */ struct retro_input_descriptor { /* Associates given parameters with a description. */ unsigned port; unsigned device; unsigned index; unsigned id; /* Human readable description for parameters. * The pointer must remain valid until * retro_unload_game() is called. */ const char *description; }; struct retro_system_info { /* All pointers are owned by libretro implementation, and pointers must * remain valid until retro_deinit() is called. */ const char *library_name; /* Descriptive name of library. Should not * contain any version numbers, etc. */ const char *library_version; /* Descriptive version of core. */ const char *valid_extensions; /* A string listing probably content * extensions the core will be able to * load, separated with pipe. * I.e. "bin|rom|iso". * Typically used for a GUI to filter * out extensions. */ /* If true, retro_load_game() is guaranteed to provide a valid pathname * in retro_game_info::path. * ::data and ::size are both invalid. * * If false, ::data and ::size are guaranteed to be valid, but ::path * might not be valid. * * This is typically set to true for libretro implementations that must * load from file. * Implementations should strive for setting this to false, as it allows * the frontend to perform patching, etc. */ bool need_fullpath; /* If true, the frontend is not allowed to extract any archives before * loading the real content. * Necessary for certain libretro implementations that load games * from zipped archives. */ bool block_extract; }; struct retro_game_geometry { unsigned base_width; /* Nominal video width of game. */ unsigned base_height; /* Nominal video height of game. */ unsigned max_width; /* Maximum possible width of game. */ unsigned max_height; /* Maximum possible height of game. */ float aspect_ratio; /* Nominal aspect ratio of game. If * aspect_ratio is <= 0.0, an aspect ratio * of base_width / base_height is assumed. * A frontend could override this setting, * if desired. */ }; struct retro_system_timing { double fps; /* FPS of video content. */ double sample_rate; /* Sampling rate of audio. */ }; struct retro_system_av_info { struct retro_game_geometry geometry; struct retro_system_timing timing; }; struct retro_variable { /* Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE. * If NULL, obtains the complete environment string if more * complex parsing is necessary. * The environment string is formatted as key-value pairs * delimited by semicolons as so: * "key1=value1;key2=value2;..." */ const char *key; /* Value to be obtained. If key does not exist, it is set to NULL. */ const char *value; }; struct retro_game_info { const char *path; /* Path to game, UTF-8 encoded. * Usually used as a reference. * May be NULL if rom was loaded from stdin * or similar. * retro_system_info::need_fullpath guaranteed * that this path is valid. */ const void *data; /* Memory buffer of loaded game. Will be NULL * if need_fullpath was set. */ size_t size; /* Size of memory buffer. */ const char *meta; /* String of implementation specific meta-data. */ }; #define RETRO_MEMORY_ACCESS_WRITE (1 << 0) /* The core will write to the buffer provided by retro_framebuffer::data. */ #define RETRO_MEMORY_ACCESS_READ (1 << 1) /* The core will read from retro_framebuffer::data. */ #define RETRO_MEMORY_TYPE_CACHED (1 << 0) /* The memory in data is cached. * If not cached, random writes and/or reading from the buffer is expected to be very slow. */ struct retro_framebuffer { void *data; /* The framebuffer which the core can render into. Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. The initial contents of data are unspecified. */ unsigned width; /* The framebuffer width used by the core. Set by core. */ unsigned height; /* The framebuffer height used by the core. Set by core. */ size_t pitch; /* The number of bytes between the beginning of a scanline, and beginning of the next scanline. Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */ enum retro_pixel_format format; /* The pixel format the core must use to render into data. This format could differ from the format used in SET_PIXEL_FORMAT. Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */ unsigned access_flags; /* How the core will access the memory in the framebuffer. RETRO_MEMORY_ACCESS_* flags. Set by core. */ unsigned memory_flags; /* Flags telling core how the memory has been mapped. RETRO_MEMORY_TYPE_* flags. Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */ }; /* Callbacks */ /* Environment callback. Gives implementations a way of performing * uncommon tasks. Extensible. */ typedef bool (*retro_environment_t)(unsigned cmd, void *data); /* Render a frame. Pixel format is 15-bit 0RGB1555 native endian * unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT). * * Width and height specify dimensions of buffer. * Pitch specifices length in bytes between two lines in buffer. * * For performance reasons, it is highly recommended to have a frame * that is packed in memory, i.e. pitch == width * byte_per_pixel. * Certain graphic APIs, such as OpenGL ES, do not like textures * that are not packed in memory. */ typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch); /* Renders a single audio frame. Should only be used if implementation * generates a single sample at a time. * Format is signed 16-bit native endian. */ typedef void (*retro_audio_sample_t)(int16_t left, int16_t right); /* Renders multiple audio frames in one go. * * One frame is defined as a sample of left and right channels, interleaved. * I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames. * Only one of the audio callbacks must ever be used. */ typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data, size_t frames); /* Polls input. */ typedef void (*retro_input_poll_t)(void); /* Queries for input for player 'port'. device will be masked with * RETRO_DEVICE_MASK. * * Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that * have been set with retro_set_controller_port_device() * will still use the higher level RETRO_DEVICE_JOYPAD to request input. */ typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device, unsigned index, unsigned id); /* Sets callbacks. retro_set_environment() is guaranteed to be called * before retro_init(). * * The rest of the set_* functions are guaranteed to have been called * before the first call to retro_run() is made. */ RETRO_API void retro_set_environment(retro_environment_t); RETRO_API void retro_set_video_refresh(retro_video_refresh_t); RETRO_API void retro_set_audio_sample(retro_audio_sample_t); RETRO_API void retro_set_audio_sample_batch(retro_audio_sample_batch_t); RETRO_API void retro_set_input_poll(retro_input_poll_t); RETRO_API void retro_set_input_state(retro_input_state_t); /* Library global initialization/deinitialization. */ RETRO_API void retro_init(void); RETRO_API void retro_deinit(void); /* Must return RETRO_API_VERSION. Used to validate ABI compatibility * when the API is revised. */ RETRO_API unsigned retro_api_version(void); /* Gets statically known system info. Pointers provided in *info * must be statically allocated. * Can be called at any time, even before retro_init(). */ RETRO_API void retro_get_system_info(struct retro_system_info *info); /* Gets information about system audio/video timings and geometry. * Can be called only after retro_load_game() has successfully completed. * NOTE: The implementation of this function might not initialize every * variable if needed. * E.g. geom.aspect_ratio might not be initialized if core doesn't * desire a particular aspect ratio. */ RETRO_API void retro_get_system_av_info(struct retro_system_av_info *info); /* Sets device to be used for player 'port'. * By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all * available ports. * Setting a particular device type is not a guarantee that libretro cores * will only poll input based on that particular device type. It is only a * hint to the libretro core when a core cannot automatically detect the * appropriate input device type on its own. It is also relevant when a * core can change its behavior depending on device type. */ RETRO_API void retro_set_controller_port_device(unsigned port, unsigned device); /* Resets the current game. */ RETRO_API void retro_reset(void); /* Runs the game for one video frame. * During retro_run(), input_poll callback must be called at least once. * * If a frame is not rendered for reasons where a game "dropped" a frame, * this still counts as a frame, and retro_run() should explicitly dupe * a frame if GET_CAN_DUPE returns true. * In this case, the video callback can take a NULL argument for data. */ RETRO_API void retro_run(void); /* Returns the amount of data the implementation requires to serialize * internal state (save states). * Between calls to retro_load_game() and retro_unload_game(), the * returned size is never allowed to be larger than a previous returned * value, to ensure that the frontend can allocate a save state buffer once. */ RETRO_API size_t retro_serialize_size(void); /* Serializes internal state. If failed, or size is lower than * retro_serialize_size(), it should return false, true otherwise. */ RETRO_API bool retro_serialize(void *data, size_t size); RETRO_API bool retro_unserialize(const void *data, size_t size); RETRO_API void retro_cheat_reset(void); RETRO_API void retro_cheat_set(unsigned index, bool enabled, const char *code); /* Loads a game. */ RETRO_API bool retro_load_game(const struct retro_game_info *game); /* Loads a "special" kind of game. Should not be used, * except in extreme cases. */ RETRO_API bool retro_load_game_special( unsigned game_type, const struct retro_game_info *info, size_t num_info ); /* Unloads a currently loaded game. */ RETRO_API void retro_unload_game(void); /* Gets region of game. */ RETRO_API unsigned retro_get_region(void); /* Gets region of memory. */ RETRO_API void *retro_get_memory_data(unsigned id); RETRO_API size_t retro_get_memory_size(unsigned id); #ifdef __cplusplus } #endif #endif libgambatte/src/video/ly_counter.h000664 001750 001750 00000003203 12720365247 020414 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef LY_COUNTER_H #define LY_COUNTER_H namespace gambatte { struct SaveState; class LyCounter { public: LyCounter(); void doEvent(); bool isDoubleSpeed() const { return ds_; } unsigned long frameCycles(unsigned long cc) const { return ly_ * 456ul + lineCycles(cc); } unsigned lineCycles(unsigned long cc) const { return 456u - ((time_ - cc) >> isDoubleSpeed()); } unsigned lineTime() const { return lineTime_; } unsigned ly() const { return ly_; } unsigned long nextLineCycle(unsigned lineCycle, unsigned long cycleCounter) const; unsigned long nextFrameCycle(unsigned long frameCycle, unsigned long cycleCounter) const; void reset(unsigned long videoCycles, unsigned long lastUpdate); void setDoubleSpeed(bool ds); unsigned long time() const { return time_; } private: unsigned long time_; unsigned short lineTime_; unsigned char ly_; bool ds_; }; } #endif libgambatte/src/tima.h000664 001750 001750 00000004112 12720365247 016055 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef TIMA_H #define TIMA_H #include "interruptrequester.h" namespace gambatte { class TimaInterruptRequester { public: explicit TimaInterruptRequester(InterruptRequester &intreq) : intreq_(intreq) {} void flagIrq() const { intreq_.flagIrq(4); } unsigned long nextIrqEventTime() const { return intreq_.eventTime(intevent_tima); } void setNextIrqEventTime(unsigned long time) const { intreq_.setEventTime(time); } private: InterruptRequester &intreq_; }; class Tima { public: Tima(); void saveState(SaveState &) const; void loadState(const SaveState &, TimaInterruptRequester timaIrq); void resetCc(unsigned long oldCc, unsigned long newCc, TimaInterruptRequester timaIrq); void setTima(unsigned tima, unsigned long cc, TimaInterruptRequester timaIrq); void setTma(unsigned tma, unsigned long cc, TimaInterruptRequester timaIrq); void setTac(unsigned tac, unsigned long cc, TimaInterruptRequester timaIrq); unsigned tima(unsigned long cc); void doIrqEvent(TimaInterruptRequester timaIrq); private: unsigned long lastUpdate_; unsigned long tmatime_; unsigned char tima_; unsigned char tma_; unsigned char tac_; void updateIrq(unsigned long const cc, TimaInterruptRequester timaIrq) { while (cc >= timaIrq.nextIrqEventTime()) doIrqEvent(timaIrq); } void updateTima(unsigned long cc); }; } #endif libgambatte/src/mem/cartridge.cpp000664 001750 001750 00000052633 12720365247 020213 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007-2010 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "cartridge.h" #include "../savestate.h" #include #include #include #include namespace gambatte { static unsigned toMulti64Rombank(const unsigned rombank) { return (rombank >> 1 & 0x30) | (rombank & 0xF); } static inline unsigned rambanks(MemPtrs const &memptrs) { return (memptrs.rambankdataend() - memptrs.rambankdata()) / 0x2000; } static inline unsigned rombanks(MemPtrs const &memptrs) { return (memptrs.romdataend() - memptrs.romdata() ) / 0x4000; } class DefaultMbc : public Mbc { public: virtual bool isAddressWithinAreaRombankCanBeMappedTo(unsigned addr, unsigned bank) const { return (addr< 0x4000) == (bank == 0); } }; class Mbc0 : public DefaultMbc { MemPtrs &memptrs; bool enableRam; public: explicit Mbc0(MemPtrs &memptrs) : memptrs(memptrs), enableRam(false) { } virtual void romWrite(const unsigned P, const unsigned data) { if (P < 0x2000) { enableRam = (data & 0xF) == 0xA; memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, 0); } } virtual void saveState(SaveState::Mem &ss) const { ss.enableRam = enableRam; } virtual void loadState(const SaveState::Mem &ss) { enableRam = ss.enableRam; memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, 0); } }; class Mbc1 : public DefaultMbc { MemPtrs &memptrs; unsigned char rombank; unsigned char rambank; bool enableRam; bool rambankMode; static unsigned adjustedRombank(unsigned bank) { return (bank & 0x1F) ? bank : bank | 1; } void setRambank() const { memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, rambank & (rambanks(memptrs) - 1)); } void setRombank() const { memptrs.setRombank(adjustedRombank(rombank) & (rombanks(memptrs) - 1)); } public: explicit Mbc1(MemPtrs &memptrs) : memptrs(memptrs), rombank(1), rambank(0), enableRam(false), rambankMode(false) { } virtual void romWrite(const unsigned P, const unsigned data) { switch (P >> 13 & 3) { case 0: enableRam = (data & 0xF) == 0xA; setRambank(); break; case 1: rombank = rambankMode ? data & 0x1F : (rombank & 0x60) | (data & 0x1F); setRombank(); break; case 2: if (rambankMode) { rambank = data & 3; setRambank(); } else { rombank = (data << 5 & 0x60) | (rombank & 0x1F); setRombank(); } break; case 3: // Pretty sure this should take effect immediately, but I have a policy not to change old behavior // unless I have something (eg. a verified test or a game) that justifies it. rambankMode = data & 1; break; } } virtual void saveState(SaveState::Mem &ss) const { ss.rombank = rombank; ss.rambank = rambank; ss.enableRam = enableRam; ss.rambankMode = rambankMode; } virtual void loadState(const SaveState::Mem &ss) { rombank = ss.rombank; rambank = ss.rambank; enableRam = ss.enableRam; rambankMode = ss.rambankMode; setRambank(); setRombank(); } }; class Mbc1Multi64 : public Mbc { MemPtrs &memptrs; unsigned char rombank; bool enableRam; bool rombank0Mode; static unsigned adjustedRombank(unsigned bank) { return (bank & 0x1F) ? bank : bank | 1; } void setRombank() const { if (rombank0Mode) { const unsigned rb = toMulti64Rombank(rombank); memptrs.setRombank0(rb & 0x30); memptrs.setRombank(adjustedRombank(rb)); } else { memptrs.setRombank0(0); memptrs.setRombank(adjustedRombank(rombank) & (rombanks(memptrs) - 1)); } } public: explicit Mbc1Multi64(MemPtrs &memptrs) : memptrs(memptrs), rombank(1), enableRam(false), rombank0Mode(false) { } virtual void romWrite(const unsigned P, const unsigned data) { switch (P >> 13 & 3) { case 0: enableRam = (data & 0xF) == 0xA; memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, 0); break; case 1: rombank = (rombank & 0x60) | (data & 0x1F); memptrs.setRombank(rombank0Mode ? adjustedRombank(toMulti64Rombank(rombank)) : adjustedRombank(rombank) & (rombanks(memptrs) - 1)); break; case 2: rombank = (data << 5 & 0x60) | (rombank & 0x1F); setRombank(); break; case 3: rombank0Mode = data & 1; setRombank(); break; } } virtual void saveState(SaveState::Mem &ss) const { ss.rombank = rombank; ss.enableRam = enableRam; ss.rambankMode = rombank0Mode; } virtual void loadState(const SaveState::Mem &ss) { rombank = ss.rombank; enableRam = ss.enableRam; rombank0Mode = ss.rambankMode; memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, 0); setRombank(); } virtual bool isAddressWithinAreaRombankCanBeMappedTo(unsigned addr, unsigned bank) const { return (addr < 0x4000) == ((bank & 0xF) == 0); } }; class Mbc2 : public DefaultMbc { MemPtrs &memptrs; unsigned char rombank; bool enableRam; public: explicit Mbc2(MemPtrs &memptrs) : memptrs(memptrs), rombank(1), enableRam(false) { } virtual void romWrite(const unsigned P, const unsigned data) { switch (P & 0x6100) { case 0x0000: enableRam = (data & 0xF) == 0xA; memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, 0); break; case 0x2100: rombank = data & 0xF; memptrs.setRombank(rombank & (rombanks(memptrs) - 1)); break; } } virtual void saveState(SaveState::Mem &ss) const { ss.rombank = rombank; ss.enableRam = enableRam; } virtual void loadState(const SaveState::Mem &ss) { rombank = ss.rombank; enableRam = ss.enableRam; memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, 0); memptrs.setRombank(rombank & (rombanks(memptrs) - 1)); } }; class Mbc3 : public DefaultMbc { MemPtrs &memptrs; Rtc *const rtc; unsigned char rombank; unsigned char rambank; bool enableRam; void setRambank() const { unsigned flags = enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0; if (rtc) { rtc->set(enableRam, rambank); if (rtc->getActive()) flags |= MemPtrs::RTC_EN; } memptrs.setRambank(flags, rambank & (rambanks(memptrs) - 1)); } public: Mbc3(MemPtrs &memptrs, Rtc *const rtc) : memptrs(memptrs), rtc(rtc), rombank(1), rambank(0), enableRam(false) { } virtual void romWrite(const unsigned P, const unsigned data) { switch (P >> 13 & 3) { case 0: enableRam = (data & 0xF) == 0xA; setRambank(); break; case 1: rombank = data & 0x7F; setRombank(); break; case 2: rambank = data; setRambank(); break; case 3: if (rtc) rtc->latch(data); break; } } virtual void saveState(SaveState::Mem &ss) const { ss.rombank = rombank; ss.rambank = rambank; ss.enableRam = enableRam; } virtual void loadState(const SaveState::Mem &ss) { rombank = ss.rombank; rambank = ss.rambank; enableRam = ss.enableRam; setRambank(); setRombank(); } void setRombank() const { memptrs.setRombank(std::max(rombank & (rombanks(memptrs) - 1), 1u)); } }; class HuC1 : public DefaultMbc { MemPtrs &memptrs; unsigned char rombank; unsigned char rambank; bool enableRam; bool rambankMode; void setRambank() const { memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : MemPtrs::READ_EN, rambankMode ? rambank & (rambanks(memptrs) - 1) : 0); } void setRombank() const { memptrs.setRombank((rambankMode ? rombank : rambank << 6 | rombank) & (rombanks(memptrs) - 1)); } public: explicit HuC1(MemPtrs &memptrs) : memptrs(memptrs), rombank(1), rambank(0), enableRam(false), rambankMode(false) { } virtual void romWrite(const unsigned P, const unsigned data) { switch (P >> 13 & 3) { case 0: enableRam = (data & 0xF) == 0xA; setRambank(); break; case 1: rombank = data & 0x3F; setRombank(); break; case 2: rambank = data & 3; rambankMode ? setRambank() : setRombank(); break; case 3: rambankMode = data & 1; setRambank(); setRombank(); break; } } virtual void saveState(SaveState::Mem &ss) const { ss.rombank = rombank; ss.rambank = rambank; ss.enableRam = enableRam; ss.rambankMode = rambankMode; } virtual void loadState(const SaveState::Mem &ss) { rombank = ss.rombank; rambank = ss.rambank; enableRam = ss.enableRam; rambankMode = ss.rambankMode; setRambank(); setRombank(); } }; class Mbc5 : public DefaultMbc { MemPtrs &memptrs; unsigned short rombank; unsigned char rambank; bool enableRam; static unsigned adjustedRombank(const unsigned bank) { return bank; } void setRambank() const { memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, rambank & (rambanks(memptrs) - 1)); } void setRombank() const { memptrs.setRombank(adjustedRombank(rombank) & (rombanks(memptrs) - 1));} public: explicit Mbc5(MemPtrs &memptrs) : memptrs(memptrs), rombank(1), rambank(0), enableRam(false) { } virtual void romWrite(const unsigned P, const unsigned data) { switch (P >> 13 & 3) { case 0: enableRam = (data & 0xF) == 0xA; setRambank(); break; case 1: rombank = P < 0x3000 ? (rombank & 0x100) | data : (data << 8 & 0x100) | (rombank & 0xFF); setRombank(); break; case 2: rambank = data & 0xF; setRambank(); break; case 3: break; } } virtual void saveState(SaveState::Mem &ss) const { ss.rombank = rombank; ss.rambank = rambank; ss.enableRam = enableRam; } virtual void loadState(const SaveState::Mem &ss) { rombank = ss.rombank; rambank = ss.rambank; enableRam = ss.enableRam; setRambank(); setRombank(); } }; static bool hasRtc(unsigned headerByte0x147) { switch (headerByte0x147) { case 0x0F: case 0x10: return true; default: return false; } } void Cartridge::setStatePtrs(SaveState &state) { state.mem.vram.set(memptrs_.vramdata(), memptrs_.vramdataend() - memptrs_.vramdata()); state.mem.sram.set(memptrs_.rambankdata(), memptrs_.rambankdataend() - memptrs_.rambankdata()); state.mem.wram.set(memptrs_.wramdata(0), memptrs_.wramdataend() - memptrs_.wramdata(0)); } void Cartridge::saveState(SaveState &state) const { mbc->saveState(state.mem); rtc_.saveState(state); } void Cartridge::loadState(const SaveState &state) { rtc_.loadState(state); mbc->loadState(state.mem); } static void enforce8bit(unsigned char *data, unsigned long sz) { if (static_cast(0x100)) while (sz--) *data++ &= 0xFF; } static unsigned pow2ceil(unsigned n) { --n; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; ++n; return n; } int Cartridge::loadROM(const void *data, unsigned romsize, const bool forceDmg, const bool multiCartCompat) { uint8_t *romdata = (uint8_t*)data; if (romsize < 0x4000 || !romdata) return -1; unsigned rambanks = 1; unsigned rombanks = 2; bool cgb = false; enum Cartridgetype { PLAIN, MBC1, MBC2, MBC3, MBC5, HUC1 } type = PLAIN; { unsigned i; unsigned char header[0x150]; for (i = 0; i < 0x150; i++) header[i] = romdata[i]; switch (header[0x0147]) { case 0x00: printf("Plain ROM loaded.\n"); type = PLAIN; break; case 0x01: printf("MBC1 ROM loaded.\n"); type = MBC1; break; case 0x02: printf("MBC1 ROM+RAM loaded.\n"); type = MBC1; break; case 0x03: printf("MBC1 ROM+RAM+BATTERY loaded.\n"); type = MBC1; break; case 0x05: printf("MBC2 ROM loaded.\n"); type = MBC2; break; case 0x06: printf("MBC2 ROM+BATTERY loaded.\n"); type = MBC2; break; case 0x08: printf("Plain ROM with additional RAM loaded.\n"); type = MBC2; break; case 0x09: printf("Plain ROM with additional RAM and Battery loaded.\n"); type = MBC2;break; case 0x0B: printf("MM01 ROM not supported.\n"); return -1; case 0x0C: printf("MM01 ROM not supported.\n"); return -1; case 0x0D: printf("MM01 ROM not supported.\n"); return -1; case 0x0F: printf("MBC3 ROM+TIMER+BATTERY loaded.\n"); type = MBC3; break; case 0x10: printf("MBC3 ROM+TIMER+RAM+BATTERY loaded.\n"); type = MBC3; break; case 0x11: printf("MBC3 ROM loaded.\n"); type = MBC3; break; case 0x12: printf("MBC3 ROM+RAM loaded.\n"); type = MBC3; break; case 0x13: printf("MBC3 ROM+RAM+BATTERY loaded.\n"); type = MBC3; break; case 0x15: printf("MBC4 ROM not supported.\n"); return -1; case 0x16: printf("MBC4 ROM not supported.\n"); return -1; case 0x17: printf("MBC4 ROM not supported.\n"); return -1; case 0x19: printf("MBC5 ROM loaded.\n"); type = MBC5; break; case 0x1A: printf("MBC5 ROM+RAM loaded.\n"); type = MBC5; break; case 0x1B: printf("MBC5 ROM+RAM+BATTERY loaded.\n"); type = MBC5; break; case 0x1C: printf("MBC5+RUMBLE ROM not supported.\n"); type = MBC5; break; case 0x1D: printf("MBC5+RUMBLE+RAM ROM not suported.\n"); type = MBC5; break; case 0x1E: printf("MBC5+RUMBLE+RAM+BATTERY ROM not supported.\n"); type = MBC5; break; case 0x20: printf("MBC6 ROM not supported.\n"); return -1; case 0x22: printf("MBC7 ROM not supported.\n"); return -1; case 0xFC: printf("Pocket Camera ROM not supported.\n"); return -1; case 0xFD: printf("Bandai TAMA5 ROM not supported.\n"); return -1; case 0xFE: printf("HuC3 ROM+RAM+BATTERY loaded.\n"); return -1; case 0xFF: printf("HuC1 ROM+BATTERY loaded.\n"); type = HUC1; break; default: printf("Wrong data-format, corrupt or unsupported ROM.\n"); return -1; } switch (header[0x0149]) { case 0x00: /*std::puts("No RAM");*/ rambanks = type == MBC2; break; case 0x01: /*std::puts("2kB RAM");*/ /*rambankrom=1; break;*/ case 0x02: /*std::puts("8kB RAM");*/ rambanks = 1; break; case 0x03: /*std::puts("32kB RAM");*/ rambanks = 4; break; case 0x04: /*std::puts("128kB RAM");*/ rambanks = 16; break; case 0x05: /*std::puts("undocumented kB RAM");*/ rambanks = 16; break; default: /*std::puts("Wrong data-format, corrupt or unsupported ROM loaded.");*/ rambanks = 16; break; } cgb = header[0x0143] >> 7 & (1 ^ forceDmg); printf("cgb: %d\n", cgb); } printf("rambanks: %u\n", rambanks); rombanks = pow2ceil(romsize / 0x4000); printf("rombanks: %u\n", static_cast(romsize / 0x4000)); ggUndoList_.clear(); mbc.reset(); memptrs_.reset(rombanks, rambanks, cgb ? 8 : 2); rtc_.set(false, 0); memcpy(memptrs_.romdata(), romdata, ((romsize / 0x4000) * 0x4000ul) * sizeof(unsigned char)); std::memset(memptrs_.romdata() + (romsize / 0x4000) * 0x4000ul, 0xFF, (rombanks - romsize / 0x4000) * 0x4000ul); enforce8bit(memptrs_.romdata(), rombanks * 0x4000ul); switch (type) { case PLAIN: mbc.reset(new Mbc0(memptrs_)); break; case MBC1: if (!rambanks && rombanks == 64 && multiCartCompat) { std::puts("Multi-ROM \"MBC1\" presumed"); mbc.reset(new Mbc1Multi64(memptrs_)); } else mbc.reset(new Mbc1(memptrs_)); break; case MBC2: mbc.reset(new Mbc2(memptrs_)); break; case MBC3: mbc.reset(new Mbc3(memptrs_, hasRtc(memptrs_.romdata()[0x147]) ? &rtc_ : 0)); break; case MBC5: mbc.reset(new Mbc5(memptrs_)); break; case HUC1: mbc.reset(new HuC1(memptrs_)); break; } return 0; } static int asHex(const char c) { return c >= 'A' ? c - 'A' + 0xA : c - '0'; } void Cartridge::applyGameGenie(const std::string &code) { if (6 < code.length()) { const unsigned val = (asHex(code[0]) << 4 | asHex(code[1])) & 0xFF; const unsigned addr = (asHex(code[2]) << 8 | asHex(code[4]) << 4 | asHex(code[5]) | (asHex(code[6]) ^ 0xF) << 12) & 0x7FFF; unsigned cmp = 0xFFFF; if (10 < code.length()) { cmp = (asHex(code[8]) << 4 | asHex(code[10])) ^ 0xFF; cmp = ((cmp >> 2 | cmp << 6) ^ 0x45) & 0xFF; } for (unsigned bank = 0; bank < static_cast(memptrs_.romdataend() - memptrs_.romdata()) / 0x4000; ++bank) { if (mbc->isAddressWithinAreaRombankCanBeMappedTo(addr, bank) && (cmp > 0xFF || memptrs_.romdata()[bank * 0x4000ul + (addr & 0x3FFF)] == cmp)) { ggUndoList_.push_back(AddrData(bank * 0x4000ul + (addr & 0x3FFF), memptrs_.romdata()[bank * 0x4000ul + (addr & 0x3FFF)])); memptrs_.romdata()[bank * 0x4000ul + (addr & 0x3FFF)] = val; } } } } void Cartridge::setGameGenie(const std::string &codes) { #if 0 if (loaded()) #endif { for (std::vector::reverse_iterator it = ggUndoList_.rbegin(), end = ggUndoList_.rend(); it != end; ++it) { if (memptrs_.romdata() + it->addr < memptrs_.romdataend()) memptrs_.romdata()[it->addr] = it->data; } ggUndoList_.clear(); std::string code; for (std::size_t pos = 0; pos < codes.length() && (code = codes.substr(pos, codes.find(';', pos) - pos), true); pos += code.length() + 1) applyGameGenie(code); } } } libgambatte/src/initstate.h000664 001750 001750 00000002774 12720365247 017143 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2008 by Sindre Aam�s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef INITSTATE_H #define INITSTATE_H namespace gambatte { void setInitState(struct SaveState &state, bool cgb, bool gbaCgbMode); } #endif libgambatte/src/sound/sound_unit.h000664 001750 001750 00000002354 12720365247 020450 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef SOUND_UNIT_H #define SOUND_UNIT_H namespace gambatte { class SoundUnit { public: enum { counter_max = 0x80000000u, counter_disabled = 0xFFFFFFFFu }; virtual ~SoundUnit() {} virtual void event() = 0; virtual void resetCounters(unsigned long /*oldCc*/) { if (counter_ != counter_disabled) counter_ -= counter_max; } unsigned long counter() const { return counter_; } protected: SoundUnit() : counter_(counter_disabled) {} unsigned long counter_; }; } #endif libgambatte/src/statesaver.cpp000664 001750 001750 00000046277 12720365247 017661 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2008 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "statesaver.h" #include "savestate.h" #include "gambatte-array.h" #include #include #include #include class omemstream { public: omemstream(void *data) : wr_ptr(static_cast(data)), has_written(0) {} void put(uint8_t data) { if (wr_ptr) *wr_ptr++ = data; has_written++; } void write(const void *data, size_t size) { if (wr_ptr) { std::memcpy(wr_ptr, data, size); wr_ptr += size; } has_written += size; } size_t size() const { return has_written; } bool fail() const { return false; } bool good() const { return true; } private: uint8_t *wr_ptr; size_t has_written; }; class imemstream { public: imemstream(const void *data) : rd_ptr(static_cast(data)), has_read(0) {} uint8_t get() { uint8_t ret = *rd_ptr++; has_read++; return ret; } void read(void *data, size_t size) { std::memcpy(data, rd_ptr, size); rd_ptr += size; } void ignore(size_t len = 1) { rd_ptr += len; has_read += len; } void getline(char *data, size_t size, char delim = '\n') { size_t count = 0; while ((count < size - 1) && (*rd_ptr != delim)) { *data++ = *rd_ptr++; has_read++; } rd_ptr++; has_read++; *data = '\0'; } bool fail() const { return false; } bool good() const { return true; } private: const uint8_t *rd_ptr; size_t has_read; }; namespace { using namespace gambatte; enum AsciiChar { NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, TAB, LF, VT, FF, CR, SO, SI, DLE, DC1, DC2, DC3, DC4, NAK, SYN, ETB, CAN, EM, SUB, ESC, FS, GS, RS, US, SP, XCL, QOT, HSH, DLR, PRC, AMP, APO, LPA, RPA, AST, PLU, COM, HYP, STP, DIV, NO0, NO1, NO2, NO3, NO4, NO5, NO6, NO7, NO8, NO9, CLN, SCL, LT, EQL, GT, QTN, AT, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, LBX, BSL, RBX, CAT, UND, ACN, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, LBR, BAR, RBR, TLD, DEL }; struct Saver { const char *label; void (*save)(omemstream &file, const SaveState &state); void (*load)(imemstream &file, SaveState &state); unsigned char labelsize; }; static inline bool operator<(const Saver &l, const Saver &r) { return std::strcmp(l.label, r.label) < 0; } static void put24(omemstream &file, const unsigned long data) { file.put(data >> 16 & 0xFF); file.put(data >> 8 & 0xFF); file.put(data & 0xFF); } static void put32(omemstream &file, const unsigned long data) { file.put(data >> 24 & 0xFF); file.put(data >> 16 & 0xFF); file.put(data >> 8 & 0xFF); file.put(data & 0xFF); } static void write(omemstream &file, const unsigned char data) { static const char inf[] = { 0x00, 0x00, 0x01 }; file.write(inf, sizeof(inf)); file.put(data & 0xFF); } static void write(omemstream &file, const unsigned short data) { static const char inf[] = { 0x00, 0x00, 0x02 }; file.write(inf, sizeof(inf)); file.put(data >> 8 & 0xFF); file.put(data & 0xFF); } static void write(omemstream &file, const unsigned long data) { static const char inf[] = { 0x00, 0x00, 0x04 }; file.write(inf, sizeof(inf)); put32(file, data); } static inline void write(omemstream &file, const bool data) { write(file, static_cast(data)); } static void write(omemstream &file, const unsigned char *data, const unsigned long sz) { put24(file, sz); file.write(reinterpret_cast(data), sz); } static void write(omemstream &file, const bool *data, const unsigned long sz) { put24(file, sz); for (unsigned long i = 0; i < sz; ++i) file.put(data[i]); } static unsigned long get24(imemstream &file) { unsigned long tmp = file.get() & 0xFF; tmp = tmp << 8 | (file.get() & 0xFF); return tmp << 8 | (file.get() & 0xFF); } static unsigned long read(imemstream &file) { unsigned long size = get24(file); if (size > 4) { file.ignore(size - 4); size = 4; } unsigned long out = 0; switch (size) { case 4: out = (out | (file.get() & 0xFF)) << 8; case 3: out = (out | (file.get() & 0xFF)) << 8; case 2: out = (out | (file.get() & 0xFF)) << 8; case 1: out = out | (file.get() & 0xFF); } return out; } static inline void read(imemstream &file, unsigned char &data) { data = read(file) & 0xFF; } static inline void read(imemstream &file, unsigned short &data) { data = read(file) & 0xFFFF; } static inline void read(imemstream &file, unsigned long &data) { data = read(file); } static inline void read(imemstream &file, bool &data) { data = read(file); } static void read(imemstream &file, unsigned char *data, unsigned long sz) { const unsigned long size = get24(file); if (size < sz) sz = size; file.read(reinterpret_cast(data), sz); file.ignore(size - sz); if (static_cast(0x100)) { for (unsigned long i = 0; i < sz; ++i) data[i] &= 0xFF; } } static void read(imemstream &file, bool *data, unsigned long sz) { const unsigned long size = get24(file); if (size < sz) sz = size; for (unsigned long i = 0; i < sz; ++i) data[i] = file.get(); file.ignore(size - sz); } } // anon namespace namespace gambatte { class SaverList { public: typedef std::vector list_t; typedef list_t::const_iterator const_iterator; private: list_t list; unsigned char maxLabelsize_; public: SaverList(); const_iterator begin() const { return list.begin(); } const_iterator end() const { return list.end(); } unsigned maxLabelsize() const { return maxLabelsize_; } }; static void pushSaver(SaverList::list_t &list, const char *label, void (*save)(omemstream &file, const SaveState &state), void (*load)(imemstream &file, SaveState &state), unsigned labelsize) { const Saver saver = { label, save, load, labelsize }; list.push_back(saver); } SaverList::SaverList() { #define ADD(arg) do { \ struct Func { \ static void save(omemstream &file, const SaveState &state) { write(file, state.arg); } \ static void load(imemstream &file, SaveState &state) { read(file, state.arg); } \ }; \ \ pushSaver(list, label, Func::save, Func::load, sizeof label); \ } while (0) #define ADDPTR(arg) do { \ struct Func { \ static void save(omemstream &file, const SaveState &state) { write(file, state.arg.get(), state.arg.size()); } \ static void load(imemstream &file, SaveState &state) { read(file, state.arg.ptr, state.arg.size()); } \ }; \ \ pushSaver(list, label, Func::save, Func::load, sizeof label); \ } while (0) #define ADDARRAY(arg) do { \ struct Func { \ static void save(omemstream &file, const SaveState &state) { write(file, state.arg, sizeof(state.arg)); } \ static void load(imemstream &file, SaveState &state) { read(file, state.arg, sizeof(state.arg)); } \ }; \ \ pushSaver(list, label, Func::save, Func::load, sizeof label); \ } while (0) { static const char label[] = { c,c, NUL }; ADD(cpu.cycleCounter); } { static const char label[] = { p,c, NUL }; ADD(cpu.pc); } { static const char label[] = { s,p, NUL }; ADD(cpu.sp); } { static const char label[] = { a, NUL }; ADD(cpu.a); } { static const char label[] = { b, NUL }; ADD(cpu.b); } { static const char label[] = { c, NUL }; ADD(cpu.c); } { static const char label[] = { d, NUL }; ADD(cpu.d); } { static const char label[] = { e, NUL }; ADD(cpu.e); } { static const char label[] = { f, NUL }; ADD(cpu.f); } { static const char label[] = { h, NUL }; ADD(cpu.h); } { static const char label[] = { l, NUL }; ADD(cpu.l); } { static const char label[] = { s,k,i,p, NUL }; ADD(cpu.skip); } { static const char label[] = { h,a,l,t, NUL }; ADD(mem.halted); } { static const char label[] = { v,r,a,m, NUL }; ADDPTR(mem.vram); } { static const char label[] = { s,r,a,m, NUL }; ADDPTR(mem.sram); } { static const char label[] = { w,r,a,m, NUL }; ADDPTR(mem.wram); } { static const char label[] = { h,r,a,m, NUL }; ADDPTR(mem.ioamhram); } { static const char label[] = { l,d,i,v,u,p, NUL }; ADD(mem.divLastUpdate); } { static const char label[] = { l,t,i,m,a,u,p, NUL }; ADD(mem.timaLastUpdate); } { static const char label[] = { t,m,a,t,i,m,e, NUL }; ADD(mem.tmatime); } { static const char label[] = { s,e,r,i,a,l,t, NUL }; ADD(mem.nextSerialtime); } { static const char label[] = { l,o,d,m,a,u,p, NUL }; ADD(mem.lastOamDmaUpdate); } { static const char label[] = { m,i,n,i,n,t,t, NUL }; ADD(mem.minIntTime); } { static const char label[] = { u,n,h,a,l,t,t, NUL }; ADD(mem.unhaltTime); } { static const char label[] = { r,o,m,b,a,n,k, NUL }; ADD(mem.rombank); } { static const char label[] = { d,m,a,s,r,c, NUL }; ADD(mem.dmaSource); } { static const char label[] = { d,m,a,d,s,t, NUL }; ADD(mem.dmaDestination); } { static const char label[] = { r,a,m,b,a,n,k, NUL }; ADD(mem.rambank); } { static const char label[] = { o,d,m,a,p,o,s, NUL }; ADD(mem.oamDmaPos); } { static const char label[] = { i,m,e, NUL }; ADD(mem.IME); } { static const char label[] = { s,r,a,m,o,n, NUL }; ADD(mem.enableRam); } { static const char label[] = { r,a,m,b,m,o,d, NUL }; ADD(mem.rambankMode); } { static const char label[] = { h,d,m,a, NUL }; ADD(mem.hdmaTransfer); } { static const char label[] = { b,g,p, NUL }; ADDPTR(ppu.bgpData); } { static const char label[] = { o,b,j,p, NUL }; ADDPTR(ppu.objpData); } { static const char label[] = { s,p,o,s,b,u,f, NUL }; ADDPTR(ppu.oamReaderBuf); } { static const char label[] = { s,p,s,z,b,u,f, NUL }; ADDPTR(ppu.oamReaderSzbuf); } { static const char label[] = { s,p,a,t,t,r, NUL }; ADDARRAY(ppu.spAttribList); } { static const char label[] = { s,p,b,y,t,e,NO0, NUL }; ADDARRAY(ppu.spByte0List); } { static const char label[] = { s,p,b,y,t,e,NO1, NUL }; ADDARRAY(ppu.spByte1List); } { static const char label[] = { v,c,y,c,l,e,s, NUL }; ADD(ppu.videoCycles); } { static const char label[] = { e,d,M,NO0,t,i,m, NUL }; ADD(ppu.enableDisplayM0Time); } { static const char label[] = { m,NO0,t,i,m,e, NUL }; ADD(ppu.lastM0Time); } { static const char label[] = { n,m,NO0,i,r,q, NUL }; ADD(ppu.nextM0Irq); } { static const char label[] = { b,g,t,w, NUL }; ADD(ppu.tileword); } { static const char label[] = { b,g,n,t,w, NUL }; ADD(ppu.ntileword); } { static const char label[] = { w,i,n,y,p,o,s, NUL }; ADD(ppu.winYPos); } { static const char label[] = { x,p,o,s, NUL }; ADD(ppu.xpos); } { static const char label[] = { e,n,d,x, NUL }; ADD(ppu.endx); } { static const char label[] = { p,p,u,r,NO0, NUL }; ADD(ppu.reg0); } { static const char label[] = { p,p,u,r,NO1, NUL }; ADD(ppu.reg1); } { static const char label[] = { b,g,a,t,r,b, NUL }; ADD(ppu.attrib); } { static const char label[] = { b,g,n,a,t,r,b, NUL }; ADD(ppu.nattrib); } { static const char label[] = { p,p,u,s,t,a,t, NUL }; ADD(ppu.state); } { static const char label[] = { n,s,p,r,i,t,e, NUL }; ADD(ppu.nextSprite); } { static const char label[] = { c,s,p,r,i,t,e, NUL }; ADD(ppu.currentSprite); } { static const char label[] = { l,y,c, NUL }; ADD(ppu.lyc); } { static const char label[] = { m,NO0,l,y,c, NUL }; ADD(ppu.m0lyc); } { static const char label[] = { o,l,d,w,y, NUL }; ADD(ppu.oldWy); } { static const char label[] = { w,i,n,d,r,a,w, NUL }; ADD(ppu.winDrawState); } { static const char label[] = { w,s,c,x, NUL }; ADD(ppu.wscx); } { static const char label[] = { w,e,m,a,s,t,r, NUL }; ADD(ppu.weMaster); } { static const char label[] = { l,c,d,s,i,r,q, NUL }; ADD(ppu.pendingLcdstatIrq); } { static const char label[] = { s,p,u,c,n,t,r, NUL }; ADD(spu.cycleCounter); } { static const char label[] = { s,w,p,c,n,t,r, NUL }; ADD(spu.ch1.sweep.counter); } { static const char label[] = { s,w,p,s,h,d,w, NUL }; ADD(spu.ch1.sweep.shadow); } { static const char label[] = { s,w,p,n,e,g, NUL }; ADD(spu.ch1.sweep.negging); } { static const char label[] = { d,u,t,NO1,c,t,r, NUL }; ADD(spu.ch1.duty.nextPosUpdate); } { static const char label[] = { d,u,t,NO1,p,o,s, NUL }; ADD(spu.ch1.duty.pos); } { static const char label[] = { e,n,v,NO1,c,t,r, NUL }; ADD(spu.ch1.env.counter); } { static const char label[] = { e,n,v,NO1,v,o,l, NUL }; ADD(spu.ch1.env.volume); } { static const char label[] = { l,e,n,NO1,c,t,r, NUL }; ADD(spu.ch1.lcounter.counter); } { static const char label[] = { l,e,n,NO1,v,a,l, NUL }; ADD(spu.ch1.lcounter.lengthCounter); } { static const char label[] = { n,r,NO1,NO0, NUL }; ADD(spu.ch1.sweep.nr0); } { static const char label[] = { n,r,NO1,NO3, NUL }; ADD(spu.ch1.duty.nr3); } { static const char label[] = { n,r,NO1,NO4, NUL }; ADD(spu.ch1.nr4); } { static const char label[] = { c,NO1,m,a,s,t,r, NUL }; ADD(spu.ch1.master); } { static const char label[] = { d,u,t,NO2,c,t,r, NUL }; ADD(spu.ch2.duty.nextPosUpdate); } { static const char label[] = { d,u,t,NO2,p,o,s, NUL }; ADD(spu.ch2.duty.pos); } { static const char label[] = { e,n,v,NO2,c,t,r, NUL }; ADD(spu.ch2.env.counter); } { static const char label[] = { e,n,v,NO2,v,o,l, NUL }; ADD(spu.ch2.env.volume); } { static const char label[] = { l,e,n,NO2,c,t,r, NUL }; ADD(spu.ch2.lcounter.counter); } { static const char label[] = { l,e,n,NO2,v,a,l, NUL }; ADD(spu.ch2.lcounter.lengthCounter); } { static const char label[] = { n,r,NO2,NO3, NUL }; ADD(spu.ch2.duty.nr3); } { static const char label[] = { n,r,NO2,NO4, NUL }; ADD(spu.ch2.nr4); } { static const char label[] = { c,NO2,m,a,s,t,r, NUL }; ADD(spu.ch2.master); } { static const char label[] = { w,a,v,e,r,a,m, NUL }; ADDPTR(spu.ch3.waveRam); } { static const char label[] = { l,e,n,NO3,c,t,r, NUL }; ADD(spu.ch3.lcounter.counter); } { static const char label[] = { l,e,n,NO3,v,a,l, NUL }; ADD(spu.ch3.lcounter.lengthCounter); } { static const char label[] = { w,a,v,e,c,t,r, NUL }; ADD(spu.ch3.waveCounter); } { static const char label[] = { l,w,a,v,r,d,t, NUL }; ADD(spu.ch3.lastReadTime); } { static const char label[] = { w,a,v,e,p,o,s, NUL }; ADD(spu.ch3.wavePos); } { static const char label[] = { w,a,v,s,m,p,l, NUL }; ADD(spu.ch3.sampleBuf); } { static const char label[] = { n,r,NO3,NO3, NUL }; ADD(spu.ch3.nr3); } { static const char label[] = { n,r,NO3,NO4, NUL }; ADD(spu.ch3.nr4); } { static const char label[] = { c,NO3,m,a,s,t,r, NUL }; ADD(spu.ch3.master); } { static const char label[] = { l,f,s,r,c,t,r, NUL }; ADD(spu.ch4.lfsr.counter); } { static const char label[] = { l,f,s,r,r,e,g, NUL }; ADD(spu.ch4.lfsr.reg); } { static const char label[] = { e,n,v,NO4,c,t,r, NUL }; ADD(spu.ch4.env.counter); } { static const char label[] = { e,n,v,NO4,v,o,l, NUL }; ADD(spu.ch4.env.volume); } { static const char label[] = { l,e,n,NO4,c,t,r, NUL }; ADD(spu.ch4.lcounter.counter); } { static const char label[] = { l,e,n,NO4,v,a,l, NUL }; ADD(spu.ch4.lcounter.lengthCounter); } { static const char label[] = { n,r,NO4,NO4, NUL }; ADD(spu.ch4.nr4); } { static const char label[] = { c,NO4,m,a,s,t,r, NUL }; ADD(spu.ch4.master); } { static const char label[] = { r,t,c,b,a,s,e, NUL }; ADD(rtc.baseTime); } { static const char label[] = { r,t,c,h,a,l,t, NUL }; ADD(rtc.haltTime); } { static const char label[] = { r,t,c,d,h, NUL }; ADD(rtc.dataDh); } { static const char label[] = { r,t,c,d,l, NUL }; ADD(rtc.dataDl); } { static const char label[] = { r,t,c,h, NUL }; ADD(rtc.dataH); } { static const char label[] = { r,t,c,m, NUL }; ADD(rtc.dataM); } { static const char label[] = { r,t,c,s, NUL }; ADD(rtc.dataS); } { static const char label[] = { r,t,c,l,l,d, NUL }; ADD(rtc.lastLatchData); } #undef ADD #undef ADDPTR #undef ADDARRAY list.resize(list.size()); std::sort(list.begin(), list.end()); maxLabelsize_ = 0; for (std::size_t i = 0; i < list.size(); ++i) { if (list[i].labelsize > maxLabelsize_) maxLabelsize_ = list[i].labelsize; } } } namespace { static void writeSnapShot(omemstream &file) { put24(file, 0); } static SaverList list; } // anon namespace namespace gambatte { void StateSaver::saveState(const SaveState &state, void *data) { omemstream file(data); if (file.fail()) return; { static const char ver[] = { 0, 1 }; file.write(ver, sizeof(ver)); } writeSnapShot(file); for (SaverList::const_iterator it = list.begin(); it != list.end(); ++it) { file.write(it->label, it->labelsize); (*it->save)(file, state); } } bool StateSaver::loadState(SaveState &state, const void *data) { imemstream file(data); if (file.fail() || file.get() != 0) return false; file.ignore(); file.ignore(get24(file)); const Array labelbuf(list.maxLabelsize()); const Saver labelbufSaver = { labelbuf, 0, 0, list.maxLabelsize() }; SaverList::const_iterator done = list.begin(); while (file.good() && done != list.end()) { file.getline(labelbuf, list.maxLabelsize(), NUL); SaverList::const_iterator it = done; if (std::strcmp(labelbuf, it->label)) { it = std::lower_bound(it + 1, list.end(), labelbufSaver); if (it == list.end() || std::strcmp(labelbuf, it->label)) { file.ignore(get24(file)); continue; } } else ++done; (*it->load)(file, state); } state.cpu.cycleCounter &= 0x7FFFFFFF; state.spu.cycleCounter &= 0x7FFFFFFF; return true; } size_t StateSaver::stateSize(const SaveState &state) { omemstream file(0); if (file.fail()) return 0; { static const char ver[] = { 0, 1 }; file.write(ver, sizeof(ver)); } writeSnapShot(file); for (SaverList::const_iterator it = list.begin(); it != list.end(); ++it) { file.write(it->label, it->labelsize); (*it->save)(file, state); } return file.size(); } } libgambatte/include/gbint.h000664 001750 001750 00000004033 12720365247 017064 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef GAMBATTE_INT_H #define GAMBATTE_INT_H #ifdef HAVE_CSTDINT #include namespace gambatte { using std::uint_least32_t; using std::uint_least16_t; } #elif defined(HAVE_STDINT_H) #include namespace gambatte { using ::uint_least32_t; using ::uint_least16_t; } #else namespace gambatte { #ifdef CHAR_LEAST_32 typedef unsigned char uint_least32_t; #elif defined(SHORT_LEAST_32) typedef unsigned short uint_least32_t; #elif defined(INT_LEAST_32) typedef unsigned uint_least32_t; #else typedef unsigned long uint_least32_t; #endif #ifdef CHAR_LEAST_16 typedef unsigned char uint_least16_t; #else typedef unsigned short uint_least16_t; #endif } #endif #endif libgambatte/src/savestate.h000664 001750 001750 00000010233 12720365247 017123 0ustar00sergiosergio000000 000000 // // Copyright (C) 2008 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef SAVESTATE_H #define SAVESTATE_H #include #include namespace gambatte { class SaverList; struct SaveState { template class Ptr { public: Ptr() : ptr(0), size_(0) {} T const * get() const { return ptr; } std::size_t size() const { return size_; } void set(T *p, std::size_t size) { ptr = p; size_ = size; } friend class SaverList; friend void setInitState(SaveState &, bool, bool); private: T *ptr; std::size_t size_; }; struct CPU { unsigned long cycleCounter; unsigned short pc; unsigned short sp; unsigned char a; unsigned char b; unsigned char c; unsigned char d; unsigned char e; unsigned char f; unsigned char h; unsigned char l; bool skip; } cpu; struct Mem { Ptr vram; Ptr sram; Ptr wram; Ptr ioamhram; unsigned long divLastUpdate; unsigned long timaLastUpdate; unsigned long tmatime; unsigned long nextSerialtime; unsigned long lastOamDmaUpdate; unsigned long minIntTime; unsigned long unhaltTime; unsigned short rombank; unsigned short dmaSource; unsigned short dmaDestination; unsigned char rambank; unsigned char oamDmaPos; bool IME; bool halted; bool enableRam; bool rambankMode; bool hdmaTransfer; } mem; struct PPU { Ptr bgpData; Ptr objpData; //SpriteMapper::OamReader Ptr oamReaderBuf; Ptr oamReaderSzbuf; unsigned long videoCycles; unsigned long enableDisplayM0Time; unsigned short lastM0Time; unsigned short nextM0Irq; unsigned short tileword; unsigned short ntileword; unsigned char spAttribList[10]; unsigned char spByte0List[10]; unsigned char spByte1List[10]; unsigned char winYPos; unsigned char xpos; unsigned char endx; unsigned char reg0; unsigned char reg1; unsigned char attrib; unsigned char nattrib; unsigned char state; unsigned char nextSprite; unsigned char currentSprite; unsigned char lyc; unsigned char m0lyc; unsigned char oldWy; unsigned char winDrawState; unsigned char wscx; bool weMaster; bool pendingLcdstatIrq; } ppu; struct SPU { struct Duty { unsigned long nextPosUpdate; unsigned char nr3; unsigned char pos; bool high; }; struct Env { unsigned long counter; unsigned char volume; }; struct LCounter { unsigned long counter; unsigned short lengthCounter; }; struct { struct { unsigned long counter; unsigned short shadow; unsigned char nr0; bool negging; } sweep; Duty duty; Env env; LCounter lcounter; unsigned char nr4; bool master; } ch1; struct { Duty duty; Env env; LCounter lcounter; unsigned char nr4; bool master; } ch2; struct { Ptr waveRam; LCounter lcounter; unsigned long waveCounter; unsigned long lastReadTime; unsigned char nr3; unsigned char nr4; unsigned char wavePos; unsigned char sampleBuf; bool master; } ch3; struct { struct { unsigned long counter; unsigned short reg; } lfsr; Env env; LCounter lcounter; unsigned char nr4; bool master; } ch4; unsigned long cycleCounter; } spu; struct RTC { unsigned long baseTime; unsigned long haltTime; unsigned char dataDh; unsigned char dataDl; unsigned char dataH; unsigned char dataM; unsigned char dataS; bool lastLatchData; } rtc; }; } #endif libgambatte/000700 001750 001750 00000000000 12720366137 014150 5ustar00sergiosergio000000 000000 libgambatte/src/sound/channel3.h000664 001750 001750 00000005165 12720365247 017757 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef SOUND_CHANNEL3_H #define SOUND_CHANNEL3_H #include "gbint.h" #include "length_counter.h" #include "master_disabler.h" namespace gambatte { struct SaveState; class Channel3 { public: Channel3(); bool isActive() const { return master_; } void reset(); void init(bool cgb); void setStatePtrs(SaveState &state); void saveState(SaveState &state) const; void loadState(const SaveState &state); void setNr0(unsigned data); void setNr1(unsigned data) { lengthCounter_.nr1Change(data, nr4_, cycleCounter_); } void setNr2(unsigned data); void setNr3(unsigned data) { nr3_ = data; } void setNr4(unsigned data); void setSo(unsigned long soMask); void update(uint_least32_t *buf, unsigned long soBaseVol, unsigned long cycles); unsigned waveRamRead(unsigned index) const { if (master_) { if (!cgb_ && cycleCounter_ != lastReadTime_) return 0xFF; index = wavePos_ >> 1; } return waveRam_[index]; } void waveRamWrite(unsigned index, unsigned data) { if (master_) { if (!cgb_ && cycleCounter_ != lastReadTime_) return; index = wavePos_ >> 1; } waveRam_[index] = data; } private: class Ch3MasterDisabler : public MasterDisabler { public: Ch3MasterDisabler(bool &m, unsigned long &wC) : MasterDisabler(m), waveCounter_(wC) {} virtual void operator()() { MasterDisabler::operator()(); waveCounter_ = SoundUnit::counter_disabled; } private: unsigned long &waveCounter_; }; unsigned char waveRam_[0x10]; Ch3MasterDisabler disableMaster_; LengthCounter lengthCounter_; unsigned long cycleCounter_; unsigned long soMask_; unsigned long prevOut_; unsigned long waveCounter_; unsigned long lastReadTime_; unsigned char nr0_; unsigned char nr3_; unsigned char nr4_; unsigned char wavePos_; unsigned char rshift_; unsigned char sampleBuf_; bool master_; bool cgb_; void updateWaveCounter(unsigned long cc); }; } #endif libgambatte/libretro/msvc/msvc-2003-xbox1.sln000664 001750 001750 00000002716 12720365247 022074 0ustar00sergiosergio000000 000000 Microsoft Visual Studio Solution File, Format Version 8.00 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msvc-2003-xbox1", "msvc-2003-xbox1/msvc-2003-xbox1.vcproj", "{FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug Profile = Profile Profile_FastCap = Profile_FastCap Release = Release Release_LTCG = Release_LTCG EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Debug.ActiveCfg = Debug|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Debug.Build.0 = Debug|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Profile.ActiveCfg = Profile|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Profile.Build.0 = Profile|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Profile_FastCap.ActiveCfg = Profile_FastCap|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Profile_FastCap.Build.0 = Profile_FastCap|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Release.ActiveCfg = Release|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Release.Build.0 = Release|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Release_LTCG.ActiveCfg = Release_LTCG|Xbox {FAB7B0EE-4915-4CBA-A673-DDEF9B89F168}.Release_LTCG.Build.0 = Release_LTCG|Xbox EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection GlobalSection(ExtensibilityAddIns) = postSolution EndGlobalSection EndGlobal libgambatte/src/sound/length_counter.h000664 001750 001750 00000002647 12720365247 021306 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef LENGTH_COUNTER_H #define LENGTH_COUNTER_H #include "sound_unit.h" #include "../savestate.h" namespace gambatte { class MasterDisabler; class LengthCounter : public SoundUnit { public: LengthCounter(MasterDisabler &disabler, unsigned lengthMask); virtual void event(); void nr1Change(unsigned newNr1, unsigned nr4, unsigned long cc); void nr4Change(unsigned oldNr4, unsigned newNr4, unsigned long cc); void saveState(SaveState::SPU::LCounter &lstate) const; void loadState(SaveState::SPU::LCounter const &lstate, unsigned long cc); private: MasterDisabler &disableMaster_; unsigned short lengthCounter_; unsigned char const lengthMask_; }; } #endif common/uncopyable.h000664 001750 001750 00000003031 12720365247 015511 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2009 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef UNCOPYABLE_H #define UNCOPYABLE_H class Uncopyable { Uncopyable(const Uncopyable&); Uncopyable& operator=(const Uncopyable&); public: Uncopyable() {} }; #endif libgambatte/src/video.cpp000664 001750 001750 00000056571 12720365247 016604 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "video.h" #include "savestate.h" #include #include namespace gambatte { void LCD::reset(const unsigned char *const oamram, unsigned char const *vram, const bool cgb) { ppu_.reset(oamram, vram, cgb); lycIrq_.setCgb(cgb); refreshPalettes(); } static unsigned long mode2IrqSchedule(const unsigned statReg, const LyCounter &lyCounter, const unsigned long cycleCounter) { if (!(statReg & 0x20)) return disabled_time; unsigned next = lyCounter.time() - cycleCounter; if (lyCounter.ly() >= 143 || (lyCounter.ly() == 142 && next <= 4) || (statReg & 0x08)) next += (153u - lyCounter.ly()) * lyCounter.lineTime(); else { if (next <= 4) next += lyCounter.lineTime(); next -= 4; } return cycleCounter + next; } static inline unsigned long m0IrqTimeFromXpos166Time( const unsigned long xpos166Time, const bool cgb, const bool ds) { return xpos166Time + cgb - ds; } static inline unsigned long hdmaTimeFromM0Time( const unsigned long m0Time, const bool ds) { return m0Time + 1 - ds; } static unsigned long nextHdmaTime(const unsigned long lastM0Time, const unsigned long nextM0Time, const unsigned long cycleCounter, const bool ds) { return cycleCounter < hdmaTimeFromM0Time(lastM0Time, ds) ? hdmaTimeFromM0Time(lastM0Time, ds) : hdmaTimeFromM0Time(nextM0Time, ds); } void LCD::setStatePtrs(SaveState &state) { state.ppu.bgpData.set( bgpData_, sizeof bgpData_); state.ppu.objpData.set(objpData_, sizeof objpData_); ppu_.setStatePtrs(state); } void LCD::saveState(SaveState &state) const { state.mem.hdmaTransfer = hdmaIsEnabled(); state.ppu.nextM0Irq = eventTimes_(MODE0_IRQ) - ppu_.now(); state.ppu.pendingLcdstatIrq = eventTimes_(ONESHOT_LCDSTATIRQ) != disabled_time; lycIrq_.saveState(state); m0Irq_.saveState(state); ppu_.saveState(state); } void LCD::loadState(const SaveState &state, const unsigned char *const oamram) { statReg_ = state.mem.ioamhram.get()[0x141]; m2IrqStatReg_ = statReg_; m1IrqStatReg_ = statReg_; ppu_.loadState(state, oamram); lycIrq_.loadState(state); m0Irq_.loadState(state); if (ppu_.lcdc() & 0x80) { nextM0Time_.predictNextM0Time(ppu_); lycIrq_.reschedule(ppu_.lyCounter(), ppu_.now()); eventTimes_.setm(state.ppu.pendingLcdstatIrq ? ppu_.now() + 1 : static_cast(disabled_time)); eventTimes_.setm(state.ppu.oldWy != state.mem.ioamhram.get()[0x14A] ? ppu_.now() + 1 : static_cast(disabled_time)); eventTimes_.set(ppu_.lyCounter().time()); eventTimes_.setm(SpriteMapper::schedule(ppu_.lyCounter(), ppu_.now())); eventTimes_.setm(lycIrq_.time()); eventTimes_.setm(ppu_.lyCounter().nextFrameCycle(144 * 456, ppu_.now())); eventTimes_.setm(mode2IrqSchedule(statReg_, ppu_.lyCounter(), ppu_.now())); eventTimes_.setm((statReg_ & 0x08) ? ppu_.now() + state.ppu.nextM0Irq : static_cast(disabled_time)); eventTimes_.setm(state.mem.hdmaTransfer ? nextHdmaTime(ppu_.lastM0Time(), nextM0Time_.predictedNextM0Time(), ppu_.now(), isDoubleSpeed()) : static_cast(disabled_time)); } else { for (int i = 0; i < NUM_MEM_EVENTS; ++i) eventTimes_.set(static_cast(i), disabled_time); } refreshPalettes(); } void LCD::refreshPalettes() { if (ppu_.cgb()) { for (unsigned i = 0; i < 8 * 8; i += 2) { ppu_.bgPalette()[i >> 1] = gbcToRgb32( bgpData_[i] | bgpData_[i + 1] << 8); ppu_.spPalette()[i >> 1] = gbcToRgb32(objpData_[i] | objpData_[i + 1] << 8); } } else { setDmgPalette(ppu_.bgPalette() , dmgColorsRgb32_ , bgpData_[0]); setDmgPalette(ppu_.spPalette() , dmgColorsRgb32_ + 4, objpData_[0]); setDmgPalette(ppu_.spPalette() + 4, dmgColorsRgb32_ + 8, objpData_[1]); } } void LCD::resetCc(const unsigned long oldCc, const unsigned long newCc) { update(oldCc); ppu_.resetCc(oldCc, newCc); if (ppu_.lcdc() & 0x80) { const unsigned long dec = oldCc - newCc; nextM0Time_.invalidatePredictedNextM0Time(); lycIrq_.reschedule(ppu_.lyCounter(), newCc); for (int i = 0; i < NUM_MEM_EVENTS; ++i) { if (eventTimes_(static_cast(i)) != disabled_time) eventTimes_.set(static_cast(i), eventTimes_(static_cast(i)) - dec); } eventTimes_.set(ppu_.lyCounter().time()); } } void LCD::speedChange(const unsigned long cycleCounter) { update(cycleCounter); ppu_.speedChange(cycleCounter); if (ppu_.lcdc() & 0x80) { nextM0Time_.predictNextM0Time(ppu_); lycIrq_.reschedule(ppu_.lyCounter(), cycleCounter); eventTimes_.set(ppu_.lyCounter().time()); eventTimes_.setm(SpriteMapper::schedule(ppu_.lyCounter(), cycleCounter)); eventTimes_.setm(lycIrq_.time()); eventTimes_.setm(ppu_.lyCounter().nextFrameCycle(144 * 456, cycleCounter)); eventTimes_.setm(mode2IrqSchedule(statReg_, ppu_.lyCounter(), cycleCounter)); if (eventTimes_(MODE0_IRQ) != disabled_time && eventTimes_(MODE0_IRQ) - cycleCounter > 1) eventTimes_.setm(m0IrqTimeFromXpos166Time(ppu_.predictedNextXposTime(166), ppu_.cgb(), isDoubleSpeed())); if (hdmaIsEnabled() && eventTimes_(HDMA_REQ) - cycleCounter > 1) { eventTimes_.setm(nextHdmaTime(ppu_.lastM0Time(), nextM0Time_.predictedNextM0Time(), cycleCounter, isDoubleSpeed())); } } } static inline unsigned long m0TimeOfCurrentLine(const unsigned long nextLyTime, const unsigned long lastM0Time, const unsigned long nextM0Time) { return nextM0Time < nextLyTime ? nextM0Time : lastM0Time; } unsigned long LCD::m0TimeOfCurrentLine(const unsigned long cc) { if (cc >= nextM0Time_.predictedNextM0Time()) { update(cc); nextM0Time_.predictNextM0Time(ppu_); } return gambatte::m0TimeOfCurrentLine(ppu_.lyCounter().time(), ppu_.lastM0Time(), nextM0Time_.predictedNextM0Time()); } static bool isHdmaPeriod(const LyCounter &lyCounter, const unsigned long m0TimeOfCurrentLy, const unsigned long cycleCounter) { const unsigned timeToNextLy = lyCounter.time() - cycleCounter; return /*(ppu_.lcdc & 0x80) && */lyCounter.ly() < 144 && timeToNextLy > 4 && cycleCounter >= hdmaTimeFromM0Time(m0TimeOfCurrentLy, lyCounter.isDoubleSpeed()); } void LCD::enableHdma(const unsigned long cycleCounter) { if (cycleCounter >= nextM0Time_.predictedNextM0Time()) { update(cycleCounter); nextM0Time_.predictNextM0Time(ppu_); } else if (cycleCounter >= eventTimes_.nextEventTime()) update(cycleCounter); if (isHdmaPeriod(ppu_.lyCounter(), gambatte::m0TimeOfCurrentLine(ppu_.lyCounter().time(), ppu_.lastM0Time(), nextM0Time_.predictedNextM0Time()), cycleCounter)) eventTimes_.flagHdmaReq(); eventTimes_.setm(nextHdmaTime(ppu_.lastM0Time(), nextM0Time_.predictedNextM0Time(), cycleCounter, isDoubleSpeed())); } void LCD::disableHdma(const unsigned long cycleCounter) { if (cycleCounter >= eventTimes_.nextEventTime()) update(cycleCounter); eventTimes_.setm(disabled_time); } bool LCD::vramAccessible(const unsigned long cc) { if (cc >= eventTimes_.nextEventTime()) update(cc); return !(ppu_.lcdc() & 0x80) || ppu_.lyCounter().ly() >= 144 || ppu_.lyCounter().lineCycles(cc) < 80U || cc + isDoubleSpeed() - ppu_.cgb() + 2 >= m0TimeOfCurrentLine(cc); } bool LCD::cgbpAccessible(const unsigned long cc) { if (cc >= eventTimes_.nextEventTime()) update(cc); return !(ppu_.lcdc() & 0x80) || ppu_.lyCounter().ly() >= 144 || ppu_.lyCounter().lineCycles(cc) < 80U + isDoubleSpeed() || cc >= m0TimeOfCurrentLine(cc) + 3 - isDoubleSpeed(); } void LCD::doCgbBgColorChange(unsigned index, const unsigned data, const unsigned long cc) { if (cgbpAccessible(cc)) { update(cc); doCgbColorChange(bgpData_, ppu_.bgPalette(), index, data); } } void LCD::doCgbSpColorChange(unsigned index, const unsigned data, const unsigned long cc) { if (cgbpAccessible(cc)) { update(cc); doCgbColorChange(objpData_, ppu_.spPalette(), index, data); } } bool LCD::oamReadable(const unsigned long cc) { if (!(ppu_.lcdc() & 0x80) || ppu_.inactivePeriodAfterDisplayEnable(cc)) return true; if (cc >= eventTimes_.nextEventTime()) update(cc); if (ppu_.lyCounter().lineCycles(cc) + 4 - ppu_.lyCounter().isDoubleSpeed() * 3u >= 456) return ppu_.lyCounter().ly() >= 144-1 && ppu_.lyCounter().ly() != 153; return ppu_.lyCounter().ly() >= 144 || cc + isDoubleSpeed() - ppu_.cgb() + 2 >= m0TimeOfCurrentLine(cc); } bool LCD::oamWritable(const unsigned long cc) { if (!(ppu_.lcdc() & 0x80) || ppu_.inactivePeriodAfterDisplayEnable(cc)) return true; if (cc >= eventTimes_.nextEventTime()) update(cc); if (ppu_.lyCounter().lineCycles(cc) + 3 + ppu_.cgb() - ppu_.lyCounter().isDoubleSpeed() * 2u >= 456) return ppu_.lyCounter().ly() >= 144-1 && ppu_.lyCounter().ly() != 153; return ppu_.lyCounter().ly() >= 144 || cc + isDoubleSpeed() - ppu_.cgb() + 2 >= m0TimeOfCurrentLine(cc); } void LCD::mode3CyclesChange() { nextM0Time_.invalidatePredictedNextM0Time(); if (eventTimes_(MODE0_IRQ) != disabled_time && eventTimes_(MODE0_IRQ) > m0IrqTimeFromXpos166Time(ppu_.now(), ppu_.cgb(), isDoubleSpeed())) { eventTimes_.setm(m0IrqTimeFromXpos166Time(ppu_.predictedNextXposTime(166), ppu_.cgb(), isDoubleSpeed())); } if (eventTimes_(HDMA_REQ) != disabled_time && eventTimes_(HDMA_REQ) > hdmaTimeFromM0Time(ppu_.lastM0Time(), isDoubleSpeed())) { nextM0Time_.predictNextM0Time(ppu_); eventTimes_.setm(hdmaTimeFromM0Time(nextM0Time_.predictedNextM0Time(), isDoubleSpeed())); } } void LCD::wxChange(const unsigned newValue, const unsigned long cycleCounter) { update(cycleCounter + isDoubleSpeed() + 1); ppu_.setWx(newValue); mode3CyclesChange(); } void LCD::wyChange(const unsigned newValue, const unsigned long cc) { update(cc + 1); ppu_.setWy(newValue); // mode3CyclesChange(); // should be safe to wait until after wy2 delay, because no mode3 events are close to when wy1 is read. // wy2 is a delayed version of wy. really just slowness of ly == wy comparison. if (ppu_.cgb() && (ppu_.lcdc() & 0x80)) { eventTimes_.setm(cc + 5); } else { update(cc + 2); ppu_.updateWy2(); mode3CyclesChange(); } } void LCD::scxChange(const unsigned newScx, const unsigned long cycleCounter) { update(cycleCounter + ppu_.cgb() + isDoubleSpeed()); ppu_.setScx(newScx); mode3CyclesChange(); } void LCD::scyChange(const unsigned newValue, const unsigned long cycleCounter) { update(cycleCounter + ppu_.cgb() + isDoubleSpeed()); ppu_.setScy(newValue); } void LCD::oamChange(const unsigned long cc) { if (ppu_.lcdc() & 0x80) { update(cc); ppu_.oamChange(cc); eventTimes_.setm(SpriteMapper::schedule(ppu_.lyCounter(), cc)); } } void LCD::oamChange(const unsigned char *const oamram, const unsigned long cc) { update(cc); ppu_.oamChange(oamram, cc); if (ppu_.lcdc() & 0x80) eventTimes_.setm(SpriteMapper::schedule(ppu_.lyCounter(), cc)); } void LCD::lcdcChange(const unsigned data, const unsigned long cc) { const unsigned oldLcdc = ppu_.lcdc(); update(cc); if ((oldLcdc ^ data) & 0x80) { ppu_.setLcdc(data, cc); if (data & 0x80) { lycIrq_.lcdReset(); m0Irq_.lcdReset(statReg_, lycIrq_.lycReg()); if (lycIrq_.lycReg() == 0 && (statReg_ & 0x40)) eventTimes_.flagIrq(2); nextM0Time_.predictNextM0Time(ppu_); lycIrq_.reschedule(ppu_.lyCounter(), cc); eventTimes_.set(ppu_.lyCounter().time()); eventTimes_.setm(SpriteMapper::schedule(ppu_.lyCounter(), cc)); eventTimes_.setm(lycIrq_.time()); eventTimes_.setm(ppu_.lyCounter().nextFrameCycle(144 * 456, cc)); eventTimes_.setm(mode2IrqSchedule(statReg_, ppu_.lyCounter(), cc)); if (statReg_ & 0x08) eventTimes_.setm(m0IrqTimeFromXpos166Time(ppu_.predictedNextXposTime(166), ppu_.cgb(), isDoubleSpeed())); if (hdmaIsEnabled()) eventTimes_.setm(nextHdmaTime(ppu_.lastM0Time(), nextM0Time_.predictedNextM0Time(), cc, isDoubleSpeed())); } else { for (int i = 0; i < NUM_MEM_EVENTS; ++i) eventTimes_.set(static_cast(i), disabled_time); } } else if (data & 0x80) { if (ppu_.cgb()) { ppu_.setLcdc((oldLcdc & ~0x14) | (data & 0x14), cc); if ((oldLcdc ^ data) & 0x04) eventTimes_.setm(SpriteMapper::schedule(ppu_.lyCounter(), cc)); update(cc + isDoubleSpeed() + 1); ppu_.setLcdc(data, cc + isDoubleSpeed() + 1); if ((oldLcdc ^ data) & 0x20) mode3CyclesChange(); } else { ppu_.setLcdc(data, cc); if ((oldLcdc ^ data) & 0x04) eventTimes_.setm(SpriteMapper::schedule(ppu_.lyCounter(), cc)); if ((oldLcdc ^ data) & 0x22) mode3CyclesChange(); } } else ppu_.setLcdc(data, cc); } void LCD::lcdstatChange(const unsigned data, const unsigned long cc) { if (cc >= eventTimes_.nextEventTime()) update(cc); const unsigned old = statReg_; statReg_ = data; lycIrq_.statRegChange(data, ppu_.lyCounter(), cc); if (ppu_.lcdc() & 0x80) { if (!ppu_.cgb()) { const unsigned timeToNextLy = ppu_.lyCounter().time() - cc; const unsigned lycCmpLy = ppu_.lyCounter().ly() == 153 && timeToNextLy <= 444U + 8 ? 0 : ppu_.lyCounter().ly(); if (lycCmpLy == lycIrq_.lycReg()) { if (!(old & 0x40) && (ppu_.lyCounter().ly() < 144 || !(old & 0x10))) eventTimes_.flagIrq(2); } else if (ppu_.lyCounter().ly() >= 144) { if (!(old & 0x10)) eventTimes_.flagIrq(2); } else if (cc + 1 >= m0TimeOfCurrentLine(cc)) { if (!(old & 0x08)) eventTimes_.flagIrq(2); } } else { const unsigned timeToNextLy = ppu_.lyCounter().time() - cc; const unsigned lycCmpLy = ppu_.lyCounter().ly() == 153 && timeToNextLy <= (444U << isDoubleSpeed()) + 8 ? 0 : ppu_.lyCounter().ly(); const bool lycperiod = lycCmpLy == lycIrq_.lycReg() && timeToNextLy > 4U - isDoubleSpeed() * 4U; const bool lycperiodActive = lycperiod && (old & 0x40); if (lycperiod && (data & 0x40) - (old & 0x40) == 0x40 && (ppu_.lyCounter().ly() < 144 || !(old & 0x10))) eventTimes_.flagIrq(2); else if (ppu_.lyCounter().ly() >= 144 && (data & 0x10) - (old & 0x10) == 0x10 && (ppu_.lyCounter().ly() < 153 || timeToNextLy > 4U - isDoubleSpeed() * 4U) && !lycperiodActive) eventTimes_.flagIrq(2); else if ((data & 0x08) - (old & 0x08) == 0x08 && ppu_.lyCounter().ly() < 144 && !lycperiodActive && timeToNextLy > 4 && cc + isDoubleSpeed() * 2 >= m0TimeOfCurrentLine(cc)) eventTimes_.flagIrq(2); else if ((data & 0x28) == 0x20 && !(old & 0x20) && ((timeToNextLy <= 4 && ppu_.lyCounter().ly() < 143) || (timeToNextLy == 456*2 && ppu_.lyCounter().ly() < 144))) eventTimes_.flagIrq(2); } if ((data & 0x08) && eventTimes_(MODE0_IRQ) == disabled_time) { update(cc); eventTimes_.setm(m0IrqTimeFromXpos166Time(ppu_.predictedNextXposTime(166), ppu_.cgb(), isDoubleSpeed())); } eventTimes_.setm(mode2IrqSchedule(data, ppu_.lyCounter(), cc)); eventTimes_.setm(lycIrq_.time()); } m2IrqStatReg_ = eventTimes_(MODE2_IRQ) - cc > (ppu_.cgb() - isDoubleSpeed()) * 4U ? data : (m2IrqStatReg_ & 0x10) | (statReg_ & ~0x10); m1IrqStatReg_ = eventTimes_(MODE1_IRQ) - cc > (ppu_.cgb() - isDoubleSpeed()) * 4U ? data : (m1IrqStatReg_ & 0x08) | (statReg_ & ~0x08); m0Irq_.statRegChange(data, eventTimes_(MODE0_IRQ), cc, ppu_.cgb()); } void LCD::lycRegChange(const unsigned data, const unsigned long cc) { if (data == lycIrq_.lycReg()) return; if (cc >= eventTimes_.nextEventTime()) update(cc); m0Irq_.lycRegChange(data, eventTimes_(MODE0_IRQ), cc, isDoubleSpeed(), ppu_.cgb()); lycIrq_.lycRegChange(data, ppu_.lyCounter(), cc); if (!(ppu_.lcdc() & 0x80)) return; eventTimes_.setm(lycIrq_.time()); const unsigned timeToNextLy = ppu_.lyCounter().time() - cc; if ((statReg_ & 0x40) && data < 154 && (ppu_.lyCounter().ly() < 144 || !(statReg_ & 0x10) || (ppu_.lyCounter().ly() == 153 && timeToNextLy <= 4U))) { unsigned lycCmpLy = ppu_.lyCounter().ly(); if (ppu_.cgb()) { if (timeToNextLy <= 4U >> isDoubleSpeed()) lycCmpLy = lycCmpLy < 153 ? lycCmpLy + 1 : 0; else if (timeToNextLy <= 8) lycCmpLy = 0xFF; else if (lycCmpLy == 153 && timeToNextLy <= (448U << isDoubleSpeed()) + 8) lycCmpLy = 0; } else { if (timeToNextLy <= 4) lycCmpLy = 0xFF; else if (lycCmpLy == 153 && timeToNextLy <= 444U + 8) lycCmpLy = 0; } if (data == lycCmpLy) { if (ppu_.cgb() && !isDoubleSpeed()) eventTimes_.setm(cc + 5); else eventTimes_.flagIrq(2); } } } unsigned LCD::getStat(const unsigned lycReg, const unsigned long cc) { unsigned stat = 0; if (ppu_.lcdc() & 0x80) { if (cc >= eventTimes_.nextEventTime()) update(cc); const unsigned timeToNextLy = ppu_.lyCounter().time() - cc; if (ppu_.lyCounter().ly() > 143) { if (ppu_.lyCounter().ly() < 153 || timeToNextLy > 4 - isDoubleSpeed() * 4U) stat = 1; } else { const unsigned lineCycles = 456 - (timeToNextLy >> isDoubleSpeed()); if (lineCycles < 80) { if (!ppu_.inactivePeriodAfterDisplayEnable(cc)) stat = 2; } else if (cc + isDoubleSpeed() - ppu_.cgb() + 2 < m0TimeOfCurrentLine(cc)) stat = 3; } if ((ppu_.lyCounter().ly() == lycReg && timeToNextLy > 4 - isDoubleSpeed() * 4U) || (lycReg == 0 && ppu_.lyCounter().ly() == 153 && timeToNextLy >> isDoubleSpeed() <= 456 - 8)) stat |= 4; } return stat; } inline void LCD::doMode2IrqEvent() { const unsigned ly = eventTimes_(LY_COUNT) - eventTimes_(MODE2_IRQ) < 8 ? (ppu_.lyCounter().ly() == 153 ? 0 : ppu_.lyCounter().ly() + 1) : ppu_.lyCounter().ly(); if ((ly != 0 || !(m2IrqStatReg_ & 0x10)) && (!(m2IrqStatReg_ & 0x40) || (lycIrq_.lycReg() != 0 ? ly != (lycIrq_.lycReg() + 1U) : ly > 1))) eventTimes_.flagIrq(2); m2IrqStatReg_ = statReg_; if (!(statReg_ & 0x08)) { unsigned long nextTime = eventTimes_(MODE2_IRQ) + ppu_.lyCounter().lineTime(); if (ly == 0) nextTime -= 4; else if (ly == 143) nextTime += ppu_.lyCounter().lineTime() * 10 + 4; eventTimes_.setm(nextTime); } else eventTimes_.setm(eventTimes_(MODE2_IRQ) + (70224 << isDoubleSpeed())); } inline void LCD::event() { switch (eventTimes_.nextEvent()) { case MEM_EVENT: switch (eventTimes_.nextMemEvent()) { case MODE1_IRQ: eventTimes_.flagIrq((m1IrqStatReg_ & 0x18) == 0x10 ? 3 : 1); m1IrqStatReg_ = statReg_; eventTimes_.setm(eventTimes_(MODE1_IRQ) + (70224 << isDoubleSpeed())); break; case LYC_IRQ: { unsigned char ifreg = 0; lycIrq_.doEvent(&ifreg, ppu_.lyCounter()); eventTimes_.flagIrq(ifreg); eventTimes_.setm(lycIrq_.time()); } break; case SPRITE_MAP: eventTimes_.setm(ppu_.doSpriteMapEvent(eventTimes_(SPRITE_MAP))); mode3CyclesChange(); break; case HDMA_REQ: eventTimes_.flagHdmaReq(); nextM0Time_.predictNextM0Time(ppu_); eventTimes_.setm(hdmaTimeFromM0Time(nextM0Time_.predictedNextM0Time(), isDoubleSpeed())); break; case MODE2_IRQ: doMode2IrqEvent(); break; case MODE0_IRQ: { unsigned char ifreg = 0; m0Irq_.doEvent(&ifreg, ppu_.lyCounter().ly(), statReg_, lycIrq_.lycReg()); eventTimes_.flagIrq(ifreg); } eventTimes_.setm((statReg_ & 0x08) ? m0IrqTimeFromXpos166Time(ppu_.predictedNextXposTime(166), ppu_.cgb(), isDoubleSpeed()) : static_cast(disabled_time)); break; case ONESHOT_LCDSTATIRQ: eventTimes_.flagIrq(2); eventTimes_.setm(disabled_time); break; case ONESHOT_UPDATEWY2: ppu_.updateWy2(); mode3CyclesChange(); eventTimes_.setm(disabled_time); break; } break; case LY_COUNT: ppu_.doLyCountEvent(); eventTimes_.set(ppu_.lyCounter().time()); break; } } void LCD::update(const unsigned long cycleCounter) { if (!(ppu_.lcdc() & 0x80)) return; while (cycleCounter >= eventTimes_.nextEventTime()) { ppu_.update(eventTimes_.nextEventTime()); event(); } ppu_.update(cycleCounter); } } libgambatte/libretro/msvc/msvc-2010-360.sln000664 001750 001750 00000003516 12720365247 021340 0ustar00sergiosergio000000 000000  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msvc-2010-360", "msvc-2010-360/msvc-2010-360.vcxproj", "{A79F81F6-3FEE-48AA-9157-24EB772B624E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CodeAnalysis|Xbox 360 = CodeAnalysis|Xbox 360 Debug|Xbox 360 = Debug|Xbox 360 Profile_FastCap|Xbox 360 = Profile_FastCap|Xbox 360 Profile|Xbox 360 = Profile|Xbox 360 Release_LTCG|Xbox 360 = Release_LTCG|Xbox 360 Release|Xbox 360 = Release|Xbox 360 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {A79F81F6-3FEE-48AA-9157-24EB772B624E}.CodeAnalysis|Xbox 360.ActiveCfg = CodeAnalysis|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.CodeAnalysis|Xbox 360.Build.0 = CodeAnalysis|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Debug|Xbox 360.ActiveCfg = Debug|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Debug|Xbox 360.Build.0 = Debug|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Profile_FastCap|Xbox 360.ActiveCfg = Profile_FastCap|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Profile_FastCap|Xbox 360.Build.0 = Profile_FastCap|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Profile|Xbox 360.ActiveCfg = Profile|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Profile|Xbox 360.Build.0 = Profile|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Release_LTCG|Xbox 360.ActiveCfg = Release_LTCG|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Release_LTCG|Xbox 360.Build.0 = Release_LTCG|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Release|Xbox 360.ActiveCfg = Release|Xbox 360 {A79F81F6-3FEE-48AA-9157-24EB772B624E}.Release|Xbox 360.Build.0 = Release|Xbox 360 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal libgambatte/src/minkeeper.h000664 001750 001750 00000012604 12720365247 017107 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2009 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef MINKEEPER_H #define MINKEEPER_H #include namespace MinKeeperUtil { template struct CeiledLog2 { enum { RESULT = 1 + CeiledLog2<(n + 1) / 2>::RESULT }; }; template<> struct CeiledLog2<1> { enum { RESULT = 0 }; }; template struct RoundedDiv2n { enum { RESULT = RoundedDiv2n<(v + 1) / 2, n - 1>::RESULT }; }; template struct RoundedDiv2n { enum { RESULT = v }; }; template class T, int n> struct Sum { enum { RESULT = T::RESULT + Sum::RESULT }; }; template class T> struct Sum { enum { RESULT = 0 }; }; } // Keeps track of minimum value identified by id as values change. // Higher ids prioritized (as min value) if values are equal. Can easily be reversed by swapping < for <=. // Higher ids can be faster to change when the number of ids isn't a power of 2. // Thus the ones that change more frequently should have higher ids if priority allows it. template class MinKeeper { enum { LEVELS = MinKeeperUtil::CeiledLog2::RESULT }; template struct Num { enum { RESULT = MinKeeperUtil::RoundedDiv2n::RESULT }; }; template struct Sum { enum { RESULT = MinKeeperUtil::Sum::RESULT }; }; template struct UpdateValue { enum { P = Sum::RESULT + id }; enum { C0 = Sum::RESULT + id * 2 }; static void updateValue(MinKeeper *const s) { // GCC 4.3 generates better code with the ternary operator on i386. s->a[P] = (id * 2 + 1 == Num::RESULT || s->values[s->a[C0]] < s->values[s->a[C0 + 1]]) ? s->a[C0] : s->a[C0 + 1]; UpdateValue::updateValue(s); } }; template struct UpdateValue { static void updateValue(MinKeeper *const s) { s->minValue_ = s->values[s->a[0]]; } }; template struct FillLut { static void fillLut(MinKeeper *const s) { s->updateValueLut[id] = updateValue; FillLut::fillLut(s); } }; template struct FillLut<-1,dummy> { static void fillLut(MinKeeper *const) { } }; unsigned long values[ids]; unsigned long minValue_; void (*updateValueLut[Num::RESULT])(MinKeeper*const); int a[Sum::RESULT]; template static void updateValue(MinKeeper *const s); public: MinKeeper(unsigned long initValue = 0xFFFFFFFF); int min() const { return a[0]; } unsigned long minValue() const { return minValue_; } template void setValue(const unsigned long cnt) { values[id] = cnt; updateValue(this); } void setValue(const int id, const unsigned long cnt) { values[id] = cnt; updateValueLut[id >> 1](this); } unsigned long value(const int id) const { return values[id]; } }; template MinKeeper::MinKeeper(const unsigned long initValue) { std::fill(values, values + ids, initValue); for (int i = 0; i < Num::RESULT; ++i) { a[Sum::RESULT + i] = (i * 2 + 1 == ids || values[i * 2] < values[i * 2 + 1]) ? i * 2 : i * 2 + 1; } int n = Num::RESULT; int off = Sum::RESULT; while (off) { const int pn = (n + 1) >> 1; const int poff = off - pn; for (int i = 0; i < pn; ++i) { a[poff + i] = (i * 2 + 1 == n || values[a[off + i * 2]] < values[a[off + i * 2 + 1]]) ? a[off + i * 2] : a[off + i * 2 + 1]; } off = poff; n = pn; } minValue_ = values[a[0]]; FillLut::RESULT-1,0>::fillLut(this); } template template void MinKeeper::updateValue(MinKeeper *const s) { s->a[Sum::RESULT + id] = (id * 2 + 1 == ids || s->values[id * 2] < s->values[id * 2 + 1]) ? id * 2 : id * 2 + 1; UpdateValue::updateValue(s); } #endif README000664 001750 001750 00000011411 12720365247 012570 0ustar00sergiosergio000000 000000 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- Copyright (C) 2007 by Sindre Aamås aamas@stud.ntnu.no This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more details. You should have received a copy of the GNU General Public License version 2 along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- About -------------------------------------------------------------------------------- Gambatte is an accuracy-focused, open-source, cross-platform Game Boy Color emulator written in C++. It is based on hundreds of corner case hardware tests, as well as previous documentation and reverse engineering efforts. The core emulation code is contained in a separate library back-end (libgambatte) written in platform-independent C++. There is currently a GUI front-end (gambatte_qt) using Trolltech's Qt4 toolkit, and a simple command-line SDL front-end (gambatte_sdl). The GUI front-end contains platform-specific extensions for video, sound and timers. It should work on MS Windows, Linux/BSD/UNIX-like OSes, and Mac OS X. The SDL front-end should be usable on all platforms with a working SDL port. It should also be quite trivial to create new (simple) front-ends (note that the library API should in no way be considered stable). Usage -------------------------------------------------------------------------------- You will have to supply Gambatte with a ROM image file of the GB/GBC program/game you'd like to run/play, either as a command-line argument to gambatte_sdl, or through the File->Open... menu in gambatte_qt. gambatte_sdl keyboard commands: TAB - fast-forward Ctrl-f - toggle full screen Ctrl-r - reset F5 - save state F6 - previous state slot F7 - next state slot F8 - load state 0 to 9 - select state slot 0 to 9 Default key mapping: Up: Up Down: Down Left: Left Right: Right A: D B: C Start: Return Select: Shift Compiling -------------------------------------------------------------------------------- Building Gambatte from source code can be done by executing the build_.sh scripts for the qt/sdl front-ends respectively, or by issueing the correct build command (either 'scons' or 'qmake && make') in the top-level subdirectories (libgambatte will have to be built first). The clean.sh script can be executed to remove all generated files after a compile (including binaries). Requirements for building libgambatte: - A decent C++ compiler (like g++ in the GNU Compiler Collection). - SCons. - optionally zlib Requirements for building gambatte_sdl: - A decent C++ compiler (like g++ in the GNU Compiler Collection). - SDL headers and library. - SCons. (- libgambatte.) Requirements for building gambatte_qt: - A decent C++ compiler (like g++ in the GNU Compiler Collection). - Qt4 (Core, GUI, OpenGL) headers and library. - Qmake and make (GNU Make should work). - Platform-specific requirements: * MS Windows: - Win32 API headers and libraries. - DirectSound and DirectDraw7 headers and libraries. - Direct3D9 headers * Linux/BSD/UNIX-like OSes: - POSIX/UNIX headers (unistd.h, fcntl.h, sys/ioctl.h, sys/time.h, sys/shm.h). - Open Sound System header (sys/soundcard.h). - X11 Xlib, XVideo, XRandR and XShm headers and libraries. - Alsa headers and library (Linux only). * Max OS X: - Recent Mac OS X SDK (Panther Xcode/SDK should work) (- libgambatte.) Installing after a compile simply amounts to copying the generated binary (either gambatte_qt/bin/gambatte_qt<.exe> or gambatte_sdl/gambatte_sdl<.exe>) to wherever you'd like to keep it. Thanks -------------------------------------------------------------------------------- Derek Liauw Kie Fa (Kreed) Gilles Vollant Jeff Frohwein Jonathan Gevaryahu (Lord Nightmare) kOOPa Marat Fayzullin Martin Korth (nocash) Maxim Stepin (MaxSt) Nach Pan of Anthrox Pascal Felber Paul Robson SDL Shay Green (blargg) The OpenGL Extension Wrangler Library -------------------------------------------------------------------------------- Game Boy and Game Boy Color are registered trademarks of Nintendo of America Inc. Gambatte is not affiliated with or endorsed by any of the companies mentioned. libgambatte/src/video/next_m0_time.h000664 001750 001750 00000000575 12720365247 020632 0ustar00sergiosergio000000 000000 #ifndef NEXT_M0_TIME_H_ #define NEXT_M0_TIME_H_ namespace gambatte { class NextM0Time { public: NextM0Time() : predictedNextM0Time_(0) {} void predictNextM0Time(class PPU const &v); void invalidatePredictedNextM0Time() { predictedNextM0Time_ = 0; } unsigned predictedNextM0Time() const { return predictedNextM0Time_; } private: unsigned predictedNextM0Time_; }; } #endif libgambatte/src/sound/channel1.cpp000664 001750 001750 00000015174 12720365247 020311 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "channel1.h" #include "../savestate.h" #include namespace gambatte { Channel1::SweepUnit::SweepUnit(MasterDisabler &disabler, DutyUnit &dutyUnit) : disableMaster_(disabler) , dutyUnit_(dutyUnit) , shadow_(0) , nr0_(0) , negging_(false) , cgb_(false) { } unsigned Channel1::SweepUnit::calcFreq() { unsigned freq = shadow_ >> (nr0_ & 0x07); if (nr0_ & 0x08) { freq = shadow_ - freq; negging_ = true; } else freq = shadow_ + freq; if (freq & 2048) disableMaster_(); return freq; } void Channel1::SweepUnit::event() { unsigned long const period = nr0_ >> 4 & 0x07; if (period) { unsigned const freq = calcFreq(); if (!(freq & 2048) && (nr0_ & 0x07)) { shadow_ = freq; dutyUnit_.setFreq(freq, counter_); calcFreq(); } counter_ += period << 14; } else counter_ += 8ul << 14; } void Channel1::SweepUnit::nr0Change(unsigned newNr0) { if (negging_ && !(newNr0 & 0x08)) disableMaster_(); nr0_ = newNr0; } void Channel1::SweepUnit::nr4Init(unsigned long const cc) { negging_ = false; shadow_ = dutyUnit_.freq(); unsigned const period = nr0_ >> 4 & 0x07; unsigned const shift = nr0_ & 0x07; if (period | shift) counter_ = ((((cc + 2 + cgb_ * 2) >> 14) + (period ? period : 8)) << 14) + 2; else counter_ = counter_disabled; if (shift) calcFreq(); } void Channel1::SweepUnit::reset() { counter_ = counter_disabled; } void Channel1::SweepUnit::saveState(SaveState &state) const { state.spu.ch1.sweep.counter = counter_; state.spu.ch1.sweep.shadow = shadow_; state.spu.ch1.sweep.nr0 = nr0_; state.spu.ch1.sweep.negging = negging_; } void Channel1::SweepUnit::loadState(SaveState const &state) { counter_ = std::max(state.spu.ch1.sweep.counter, state.spu.cycleCounter); shadow_ = state.spu.ch1.sweep.shadow; nr0_ = state.spu.ch1.sweep.nr0; negging_ = state.spu.ch1.sweep.negging; } Channel1::Channel1() : staticOutputTest_(*this, dutyUnit_) , disableMaster_(master_, dutyUnit_) , lengthCounter_(disableMaster_, 0x3F) , envelopeUnit_(staticOutputTest_) , sweepUnit_(disableMaster_, dutyUnit_) , nextEventUnit_(0) , cycleCounter_(0) , soMask_(0) , prevOut_(0) , nr4_(0) , master_(false) { setEvent(); } void Channel1::setEvent() { nextEventUnit_ = &sweepUnit_; if (envelopeUnit_.counter() < nextEventUnit_->counter()) nextEventUnit_ = &envelopeUnit_; if (lengthCounter_.counter() < nextEventUnit_->counter()) nextEventUnit_ = &lengthCounter_; } void Channel1::setNr0(unsigned data) { sweepUnit_.nr0Change(data); setEvent(); } void Channel1::setNr1(unsigned data) { lengthCounter_.nr1Change(data, nr4_, cycleCounter_); dutyUnit_.nr1Change(data, cycleCounter_); setEvent(); } void Channel1::setNr2(unsigned data) { if (envelopeUnit_.nr2Change(data)) disableMaster_(); else staticOutputTest_(cycleCounter_); setEvent(); } void Channel1::setNr3(unsigned data) { dutyUnit_.nr3Change(data, cycleCounter_); setEvent(); } void Channel1::setNr4(unsigned const data) { lengthCounter_.nr4Change(nr4_, data, cycleCounter_); nr4_ = data; dutyUnit_.nr4Change(data, cycleCounter_); if (data & 0x80) { // init-bit nr4_ &= 0x7F; master_ = !envelopeUnit_.nr4Init(cycleCounter_); sweepUnit_.nr4Init(cycleCounter_); staticOutputTest_(cycleCounter_); } setEvent(); } void Channel1::setSo(unsigned long soMask) { soMask_ = soMask; staticOutputTest_(cycleCounter_); setEvent(); } void Channel1::reset() { // cycleCounter >> 12 & 7 represents the frame sequencer position. cycleCounter_ &= 0xFFF; cycleCounter_ += ~(cycleCounter_ + 2) << 1 & 0x1000; dutyUnit_.reset(); envelopeUnit_.reset(); sweepUnit_.reset(); setEvent(); } void Channel1::init(bool cgb) { sweepUnit_.init(cgb); } void Channel1::saveState(SaveState &state) { sweepUnit_.saveState(state); dutyUnit_.saveState(state.spu.ch1.duty, cycleCounter_); envelopeUnit_.saveState(state.spu.ch1.env); lengthCounter_.saveState(state.spu.ch1.lcounter); state.spu.cycleCounter = cycleCounter_; state.spu.ch1.nr4 = nr4_; state.spu.ch1.master = master_; } void Channel1::loadState(SaveState const &state) { sweepUnit_.loadState(state); dutyUnit_.loadState(state.spu.ch1.duty, state.mem.ioamhram.get()[0x111], state.spu.ch1.nr4, state.spu.cycleCounter); envelopeUnit_.loadState(state.spu.ch1.env, state.mem.ioamhram.get()[0x112], state.spu.cycleCounter); lengthCounter_.loadState(state.spu.ch1.lcounter, state.spu.cycleCounter); cycleCounter_ = state.spu.cycleCounter; nr4_ = state.spu.ch1.nr4; master_ = state.spu.ch1.master; } void Channel1::update(uint_least32_t *buf, unsigned long const soBaseVol, unsigned long cycles) { unsigned long const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; unsigned long const outLow = outBase * (0 - 15ul); unsigned long const endCycles = cycleCounter_ + cycles; for (;;) { unsigned long const outHigh = master_ ? outBase * (envelopeUnit_.getVolume() * 2 - 15ul) : outLow; unsigned long const nextMajorEvent = std::min(nextEventUnit_->counter(), endCycles); unsigned long out = dutyUnit_.isHighState() ? outHigh : outLow; while (dutyUnit_.counter() <= nextMajorEvent) { *buf = out - prevOut_; prevOut_ = out; buf += dutyUnit_.counter() - cycleCounter_; cycleCounter_ = dutyUnit_.counter(); dutyUnit_.event(); out = dutyUnit_.isHighState() ? outHigh : outLow; } if (cycleCounter_ < nextMajorEvent) { *buf = out - prevOut_; prevOut_ = out; buf += nextMajorEvent - cycleCounter_; cycleCounter_ = nextMajorEvent; } if (nextEventUnit_->counter() == nextMajorEvent) { nextEventUnit_->event(); setEvent(); } else break; } if (cycleCounter_ >= SoundUnit::counter_max) { dutyUnit_.resetCounters(cycleCounter_); lengthCounter_.resetCounters(cycleCounter_); envelopeUnit_.resetCounters(cycleCounter_); sweepUnit_.resetCounters(cycleCounter_); cycleCounter_ -= SoundUnit::counter_max; } } } libgambatte/src/insertion_sort.h000664 001750 001750 00000003656 12720365247 020220 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre Aamås * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef INSERTION_SORT_H #define INSERTION_SORT_H #include template void insertionSort(T *const start, T *const end, Less less) { if (start >= end) return; T *a = start; while (++a < end) { const T e = *a; T *b = a; while (b != start && less(e, *(b - 1))) { *b = *(b - 1); b = b - 1; } *b = e; } } template inline void insertionSort(T *const start, T *const end) { insertionSort(start, end, std::less()); } #endif /*INSERTION_SORT_H*/ libgambatte/libretro/msvc/msvc-2010.bat000664 001750 001750 00000007745 12720365247 021014 0ustar00sergiosergio000000 000000 @echo off @echo Setting environment for using Microsoft Visual Studio 2010 x86 tools. @call :GetVSCommonToolsDir @if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR @call "%VS100COMNTOOLS%VCVarsQueryRegistry.bat" 32bit No64bit @if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR @if "%FrameworkDir32%"=="" goto error_no_FrameworkDIR32 @if "%FrameworkVersion32%"=="" goto error_no_FrameworkVer32 @if "%Framework35Version%"=="" goto error_no_Framework35Version @set FrameworkDir=%FrameworkDir32% @set FrameworkVersion=%FrameworkVersion32% @if not "%WindowsSdkDir%" == "" ( @set "PATH=%WindowsSdkDir%bin\NETFX 4.0 Tools;%WindowsSdkDir%bin;%PATH%" @set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%" @set "LIB=%WindowsSdkDir%lib;%LIB%" ) @rem @rem Root of Visual Studio IDE installed files. @rem @set DevEnvDir=%VSINSTALLDIR%Common7\IDE\ @rem PATH @rem ---- @if exist "%VSINSTALLDIR%Team Tools\Performance Tools" ( @set "PATH=%VSINSTALLDIR%Team Tools\Performance Tools;%PATH%" ) @if exist "%ProgramFiles%\HTML Help Workshop" set PATH=%ProgramFiles%\HTML Help Workshop;%PATH% @if exist "%ProgramFiles(x86)%\HTML Help Workshop" set PATH=%ProgramFiles(x86)%\HTML Help Workshop;%PATH% @if exist "%VCINSTALLDIR%VCPackages" set PATH=%VCINSTALLDIR%VCPackages;%PATH% @set PATH=%FrameworkDir%%Framework35Version%;%PATH% @set PATH=%FrameworkDir%%FrameworkVersion%;%PATH% @set PATH=%VSINSTALLDIR%Common7\Tools;%PATH% @if exist "%VCINSTALLDIR%BIN" set PATH=%VCINSTALLDIR%BIN;%PATH% @set PATH=%DevEnvDir%;%PATH% @if exist "%VSINSTALLDIR%VSTSDB\Deploy" ( @set "PATH=%VSINSTALLDIR%VSTSDB\Deploy;%PATH%" ) @if not "%FSHARPINSTALLDIR%" == "" ( @set "PATH=%FSHARPINSTALLDIR%;%PATH%" ) @rem INCLUDE @rem ------- @if exist "%VCINSTALLDIR%ATLMFC\INCLUDE" set INCLUDE=%VCINSTALLDIR%ATLMFC\INCLUDE;%INCLUDE% @if exist "%VCINSTALLDIR%INCLUDE" set INCLUDE=%VCINSTALLDIR%INCLUDE;%INCLUDE% @rem LIB @rem --- @if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIB=%VCINSTALLDIR%ATLMFC\LIB;%LIB% @if exist "%VCINSTALLDIR%LIB" set LIB=%VCINSTALLDIR%LIB;%LIB% @rem LIBPATH @rem ------- @if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIBPATH=%VCINSTALLDIR%ATLMFC\LIB;%LIBPATH% @if exist "%VCINSTALLDIR%LIB" set LIBPATH=%VCINSTALLDIR%LIB;%LIBPATH% @set LIBPATH=%FrameworkDir%%Framework35Version%;%LIBPATH% @set LIBPATH=%FrameworkDir%%FrameworkVersion%;%LIBPATH% @goto end @REM ----------------------------------------------------------------------- :GetVSCommonToolsDir @set VS100COMNTOOLS= @call :GetVSCommonToolsDirHelper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper64 HKCU > nul 2>&1 @exit /B 0 :GetVSCommonToolsDirHelper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "VS100COMNTOOLS=%%k" ) ) @if "%VS100COMNTOOLS%"=="" exit /B 1 @SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\" @exit /B 0 :GetVSCommonToolsDirHelper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "VS100COMNTOOLS=%%k" ) ) @if "%VS100COMNTOOLS%"=="" exit /B 1 @SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\" @exit /B 0 @REM ----------------------------------------------------------------------- :error_no_VS100COMNTOOLSDIR @echo ERROR: Cannot determine the location of the VS Common Tools folder. @goto end :error_no_VSINSTALLDIR @echo ERROR: Cannot determine the location of the VS installation. @goto end :error_no_FrameworkDIR32 @echo ERROR: Cannot determine the location of the .NET Framework 32bit installation. @goto end :error_no_FrameworkVer32 @echo ERROR: Cannot determine the version of the .NET Framework 32bit installation. @goto end :error_no_Framework35Version @echo ERROR: Cannot determine the .NET Framework 3.5 version. @goto end :end msbuild msvc-2010.sln /p:Configuration=Release /target:clean msbuild msvc-2010.sln /p:Configuration=Release exit libgambatte/libretro/msvc/msvc-2010/msvc-2010.vcxproj.filters000664 001750 001750 00000013133 12720365247 024724 0ustar00sergiosergio000000 000000  {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hpp;hxx;hm;inl;inc;xsd {c6b3d008-3362-4d55-a3d9-6e980fb09074} {b1fb6fc7-40b0-46c5-86f5-c5d62718be48} {ec7ab185-9a6d-4fa6-95f4-2921e8dd9d06} {f5709d8a-86dc-402f-825c-25a7e425bddb} {6c58fa31-84ab-4bdf-94ba-61cd802cac92} {e2083396-20f9-42a2-a09f-59a19ec295c3} {8328f716-5a8e-4c0d-ad80-1057b626b35c} Source Files\libretro Source Files\resampler Source Files\resampler Source Files\resampler Source Files\resampler Source Files\resampler Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\mem Source Files\src\mem Source Files\src\mem Source Files\src\file Source Files\src\video Source Files\src\video Source Files\src\video Source Files\src\video Source Files\src\video Source Files\libretro libgambatte/src/sound/channel2.cpp000664 001750 001750 00000010633 12720365247 020305 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "channel2.h" #include "../savestate.h" #include namespace gambatte { Channel2::Channel2() : staticOutputTest_(*this, dutyUnit_) , disableMaster_(master_, dutyUnit_) , lengthCounter_(disableMaster_, 0x3F) , envelopeUnit_(staticOutputTest_) , cycleCounter_(0) , soMask_(0) , prevOut_(0) , nr4_(0) , master_(false) { setEvent(); } void Channel2::setEvent() { nextEventUnit = &envelopeUnit_; if (lengthCounter_.counter() < nextEventUnit->counter()) nextEventUnit = &lengthCounter_; } void Channel2::setNr1(unsigned data) { lengthCounter_.nr1Change(data, nr4_, cycleCounter_); dutyUnit_.nr1Change(data, cycleCounter_); setEvent(); } void Channel2::setNr2(unsigned data) { if (envelopeUnit_.nr2Change(data)) disableMaster_(); else staticOutputTest_(cycleCounter_); setEvent(); } void Channel2::setNr3(unsigned data) { dutyUnit_.nr3Change(data, cycleCounter_); setEvent(); } void Channel2::setNr4(unsigned const data) { lengthCounter_.nr4Change(nr4_, data, cycleCounter_); nr4_ = data; if (data & 0x80) { // init-bit nr4_ &= 0x7F; master_ = !envelopeUnit_.nr4Init(cycleCounter_); staticOutputTest_(cycleCounter_); } dutyUnit_.nr4Change(data, cycleCounter_); setEvent(); } void Channel2::setSo(unsigned long soMask) { soMask_ = soMask; staticOutputTest_(cycleCounter_); setEvent(); } void Channel2::reset() { // cycleCounter >> 12 & 7 represents the frame sequencer position. cycleCounter_ &= 0xFFF; cycleCounter_ += ~(cycleCounter_ + 2) << 1 & 0x1000; dutyUnit_.reset(); envelopeUnit_.reset(); setEvent(); } void Channel2::saveState(SaveState &state) { dutyUnit_.saveState(state.spu.ch2.duty, cycleCounter_); envelopeUnit_.saveState(state.spu.ch2.env); lengthCounter_.saveState(state.spu.ch2.lcounter); state.spu.ch2.nr4 = nr4_; state.spu.ch2.master = master_; } void Channel2::loadState(SaveState const &state) { dutyUnit_.loadState(state.spu.ch2.duty, state.mem.ioamhram.get()[0x116], state.spu.ch2.nr4, state.spu.cycleCounter); envelopeUnit_.loadState(state.spu.ch2.env, state.mem.ioamhram.get()[0x117], state.spu.cycleCounter); lengthCounter_.loadState(state.spu.ch2.lcounter, state.spu.cycleCounter); cycleCounter_ = state.spu.cycleCounter; nr4_ = state.spu.ch2.nr4; master_ = state.spu.ch2.master; } void Channel2::update(uint_least32_t *buf, unsigned long const soBaseVol, unsigned long cycles) { unsigned long const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; unsigned long const outLow = outBase * (0 - 15ul); unsigned long const endCycles = cycleCounter_ + cycles; for (;;) { unsigned long const outHigh = master_ ? outBase * (envelopeUnit_.getVolume() * 2 - 15ul) : outLow; unsigned long const nextMajorEvent = std::min(nextEventUnit->counter(), endCycles); unsigned long out = dutyUnit_.isHighState() ? outHigh : outLow; while (dutyUnit_.counter() <= nextMajorEvent) { *buf += out - prevOut_; prevOut_ = out; buf += dutyUnit_.counter() - cycleCounter_; cycleCounter_ = dutyUnit_.counter(); dutyUnit_.event(); out = dutyUnit_.isHighState() ? outHigh : outLow; } if (cycleCounter_ < nextMajorEvent) { *buf += out - prevOut_; prevOut_ = out; buf += nextMajorEvent - cycleCounter_; cycleCounter_ = nextMajorEvent; } if (nextEventUnit->counter() == nextMajorEvent) { nextEventUnit->event(); setEvent(); } else break; } if (cycleCounter_ >= SoundUnit::counter_max) { dutyUnit_.resetCounters(cycleCounter_); lengthCounter_.resetCounters(cycleCounter_); envelopeUnit_.resetCounters(cycleCounter_); cycleCounter_ -= SoundUnit::counter_max; } } } libgambatte/src/initstate.cpp000664 001750 001750 00000240370 12720365247 017472 0ustar00sergiosergio000000 000000 // // Copyright (C) 2008 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "initstate.h" #include "counterdef.h" #include "savestate.h" #include "sound/sound_unit.h" #include #include #include namespace { static void setInitialCgbWram(unsigned char wram[]) { static struct { unsigned short addr; unsigned char val; } const cgbWramDumpDiff[] = { { 0x0083, 0x7F }, { 0x008B, 0x10 }, { 0x00C0, 0x7F }, { 0x00E1, 0x7F }, { 0x00E2, 0x7F }, { 0x00EA, 0x10 }, { 0x010A, 0x40 }, { 0x0179, 0x01 }, { 0x01AF, 0x01 }, { 0x0201, 0xFB }, { 0x0254, 0xF7 }, { 0x0264, 0x7F }, { 0x02D1, 0xBF }, { 0x02D2, 0xFB }, { 0x0301, 0xF7 }, { 0x0313, 0xF7 }, { 0x0315, 0x7F }, { 0x0325, 0x7F }, { 0x0339, 0x04 }, { 0x0354, 0x7F }, { 0x0375, 0xFD }, { 0x0391, 0xFB }, { 0x03AC, 0x40 }, { 0x03C5, 0xFB }, { 0x03FB, 0x20 }, { 0x0412, 0xF7 }, { 0x0422, 0xF7 }, { 0x04B1, 0xFB }, { 0x04B5, 0x7F }, { 0x04C6, 0x7F }, { 0x04D0, 0xFB }, { 0x04D2, 0xDF }, { 0x0504, 0x7F }, { 0x051C, 0x01 }, { 0x0523, 0xFD }, { 0x0532, 0xF7 }, { 0x0535, 0xF7 }, { 0x0606, 0x7F }, { 0x0690, 0xF7 }, { 0x0697, 0xFB }, { 0x0698, 0x02 }, { 0x06B5, 0x7F }, { 0x06E4, 0x7F }, { 0x06F1, 0xDF }, { 0x06F9, 0x04 }, { 0x0730, 0xFD }, { 0x0783, 0xFB }, { 0x07B5, 0x7F }, { 0x07B6, 0xF7 }, { 0x080E, 0xF7 }, { 0x081C, 0xF7 }, { 0x0849, 0xBF }, { 0x0859, 0xF7 }, { 0x085E, 0x7F }, { 0x085F, 0x7F }, { 0x0869, 0x7F }, { 0x086D, 0x7F }, { 0x086E, 0x7F }, { 0x0879, 0xBF }, { 0x087C, 0xFB }, { 0x0889, 0xBB }, { 0x089A, 0xF7 }, { 0x089D, 0xD7 }, { 0x089E, 0x9F }, { 0x08A9, 0x7F }, { 0x08AA, 0xFB }, { 0x08AC, 0x7F }, { 0x08AF, 0xF7 }, { 0x08BB, 0xDF }, { 0x08D8, 0xFB }, { 0x08DB, 0x7F }, { 0x08DC, 0xBF }, { 0x08E8, 0xF7 }, { 0x08FB, 0x7D }, { 0x08FC, 0x7F }, { 0x08FD, 0xFD }, { 0x090A, 0xFB }, { 0x091C, 0xF7 }, { 0x091E, 0xDF }, { 0x0929, 0xF7 }, { 0x092B, 0xF7 }, { 0x092C, 0xF7 }, { 0x092D, 0xFB }, { 0x094B, 0xF7 }, { 0x094D, 0x7F }, { 0x095B, 0x7B }, { 0x0969, 0xF7 }, { 0x097C, 0x7F }, { 0x097E, 0xF7 }, { 0x09DC, 0x5F }, { 0x09EB, 0xFD }, { 0x09EE, 0xDF }, { 0x09EF, 0x7F }, { 0x09FB, 0xBF }, { 0x09FE, 0xF7 }, { 0x0A0A, 0xF7 }, { 0x0A0E, 0xBF }, { 0x0A0F, 0x7F }, { 0x0A1A, 0xBF }, { 0x0A1C, 0x3F }, { 0x0A2A, 0xFD }, { 0x0A2E, 0xF7 }, { 0x0A3C, 0xDF }, { 0x0A3E, 0xF7 }, { 0x0A4B, 0xFB }, { 0x0A4F, 0xDF }, { 0x0A5C, 0xF7 }, { 0x0A6E, 0xF7 }, { 0x0A7E, 0xB7 }, { 0x0A7F, 0xF7 }, { 0x0A81, 0x01 }, { 0x0A8D, 0xDF }, { 0x0A9F, 0x7F }, { 0x0AAB, 0xFD }, { 0x0AAC, 0xFB }, { 0x0ABE, 0xBF }, { 0x0AC9, 0xFB }, { 0x0ACF, 0xF7 }, { 0x0ADC, 0xF5 }, { 0x0ADD, 0xBF }, { 0x0AEA, 0x7B }, { 0x0AEB, 0x7F }, { 0x0AF8, 0xFB }, { 0x0AFB, 0xDF }, { 0x0B0D, 0x7F }, { 0x0B2E, 0xFD }, { 0x0B39, 0xF7 }, { 0x0B48, 0xBF }, { 0x0B5D, 0x7F }, { 0x0B6B, 0x7F }, { 0x0B6D, 0xFB }, { 0x0B76, 0x10 }, { 0x0B8B, 0x7F }, { 0x0B8C, 0xF5 }, { 0x0B8D, 0xDF }, { 0x0B9F, 0xBF }, { 0x0BB9, 0xDF }, { 0x0BBF, 0x7F }, { 0x0BCE, 0xF7 }, { 0x0BDF, 0x7F }, { 0x0BE9, 0x7F }, { 0x0BEE, 0xF7 }, { 0x0BF9, 0x7F }, { 0x0BFE, 0xB7 }, { 0x0C09, 0xFD }, { 0x0C0C, 0xFD }, { 0x0C0D, 0xFD }, { 0x0C0F, 0xFB }, { 0x0C18, 0xDB }, { 0x0C1A, 0xF7 }, { 0x0C1B, 0xBF }, { 0x0C1E, 0xF7 }, { 0x0C29, 0x7F }, { 0x0C2D, 0xFD }, { 0x0C3F, 0x77 }, { 0x0C5B, 0xF7 }, { 0x0C5E, 0xBF }, { 0x0C6B, 0x7F }, { 0x0C78, 0x7F }, { 0x0C79, 0xF7 }, { 0x0C7D, 0xF7 }, { 0x0C8F, 0x77 }, { 0x0C9A, 0xF7 }, { 0x0CBB, 0xDB }, { 0x0CBC, 0xF9 }, { 0x0CCE, 0x7F }, { 0x0CD8, 0xDF }, { 0x0CF8, 0x7F }, { 0x0CFE, 0xFB }, { 0x0CFF, 0x7F }, { 0x0D09, 0xDB }, { 0x0D1C, 0xDF }, { 0x0D1F, 0xF7 }, { 0x0D29, 0x7F }, { 0x0D2E, 0x7B }, { 0x0D39, 0x77 }, { 0x0D3A, 0xFB }, { 0x0D3B, 0x7F }, { 0x0D3C, 0xDF }, { 0x0D3E, 0xFB }, { 0x0D59, 0x7F }, { 0x0D5E, 0xDF }, { 0x0D6E, 0xFD }, { 0x0D78, 0xF7 }, { 0x0D79, 0xFB }, { 0x0D7A, 0x7F }, { 0x0D8B, 0xFB }, { 0x0D8F, 0xBF }, { 0x0D9B, 0xF7 }, { 0x0DBA, 0xBF }, { 0x0DBF, 0xD7 }, { 0x0DC9, 0x7F }, { 0x0DCA, 0xF7 }, { 0x0DD8, 0xFB }, { 0x0DD9, 0xFB }, { 0x0DDA, 0xFD }, { 0x0DDB, 0xF7 }, { 0x0DDD, 0xF7 }, { 0x0DDE, 0xF7 }, { 0x0DFB, 0xFB }, { 0x0DFD, 0x7F }, { 0x0E08, 0xFB }, { 0x0E09, 0xFB }, { 0x0E18, 0xFB }, { 0x0E29, 0xB7 }, { 0x0E2B, 0xFB }, { 0x0E3D, 0xF7 }, { 0x0E43, 0x20 }, { 0x0E48, 0xF7 }, { 0x0E4D, 0xF7 }, { 0x0E5F, 0xF7 }, { 0x0E69, 0x7F }, { 0x0E6B, 0xFB }, { 0x0E7E, 0x7B }, { 0x0E89, 0x7F }, { 0x0E8B, 0xFB }, { 0x0E8D, 0xF7 }, { 0x0E99, 0xBF }, { 0x0E9B, 0xF7 }, { 0x0E9D, 0xF7 }, { 0x0E9F, 0xF7 }, { 0x0EAB, 0xDF }, { 0x0EAF, 0xF7 }, { 0x0EB9, 0xDF }, { 0x0EBD, 0x7F }, { 0x0EBE, 0xFB }, { 0x0ECB, 0xDF }, { 0x0ECE, 0xF7 }, { 0x0ECF, 0x7F }, { 0x0EDF, 0xDF }, { 0x0EEB, 0xFD }, { 0x0EF8, 0xD7 }, { 0x0EFC, 0x77 }, { 0x0EFD, 0xDF }, { 0x0EFF, 0x7F }, { 0x0F08, 0xF7 }, { 0x0F0D, 0xDF }, { 0x0F1E, 0x7F }, { 0x0F2C, 0xDF }, { 0x0F2D, 0xF7 }, { 0x0F2E, 0xFB }, { 0x0F2F, 0x7F }, { 0x0F38, 0xFB }, { 0x0F3B, 0xDF }, { 0x0F43, 0x10 }, { 0x0F4B, 0x57 }, { 0x0F4C, 0x7F }, { 0x0F5F, 0xD7 }, { 0x0F78, 0xBF }, { 0x0F8F, 0xBB }, { 0x0F9F, 0xF7 }, { 0x0FAB, 0xFD }, { 0x0FAF, 0xF7 }, { 0x0FB8, 0xFB }, { 0x0FBE, 0x7F }, { 0x0FD9, 0xB3 }, { 0x0FDD, 0xFB }, { 0x0FDF, 0x7F }, { 0x0FF2, 0xF7 }, { 0x0FFC, 0xF7 }, { 0x10B0, 0xF7 }, { 0x10E0, 0xFD }, { 0x112B, 0x40 }, { 0x1150, 0xDF }, { 0x1184, 0xBF }, { 0x1188, 0x01 }, { 0x11C1, 0x7F }, { 0x11E4, 0x7F }, { 0x11F1, 0x7F }, { 0x1211, 0xF7 }, { 0x1214, 0xFD }, { 0x1215, 0xF7 }, { 0x1244, 0xFB }, { 0x125B, 0x20 }, { 0x126C, 0x04 }, { 0x1272, 0xFD }, { 0x12C1, 0xDF }, { 0x12DB, 0x10 }, { 0x12F0, 0x7F }, { 0x1364, 0xF7 }, { 0x13F2, 0xFB }, { 0x1413, 0xDF }, { 0x1430, 0xF7 }, { 0x1436, 0xF7 }, { 0x1450, 0x7F }, { 0x1470, 0xF7 }, { 0x1472, 0x7F }, { 0x14B4, 0xDF }, { 0x14B6, 0xFB }, { 0x1516, 0xF7 }, { 0x151B, 0x01 }, { 0x1565, 0x7F }, { 0x1597, 0xBF }, { 0x15A6, 0x7F }, { 0x15B0, 0x7F }, { 0x15C5, 0xBF }, { 0x15D5, 0xFB }, { 0x15F2, 0xFD }, { 0x15FC, 0x04 }, { 0x161A, 0x10 }, { 0x1689, 0x20 }, { 0x16A7, 0xFB }, { 0x170A, 0x02 }, { 0x1732, 0xFD }, { 0x1744, 0x7F }, { 0x1759, 0x01 }, { 0x1761, 0xF7 }, { 0x1774, 0xF7 }, { 0x1795, 0xFD }, { 0x179B, 0x10 }, { 0x17C4, 0xF7 }, { 0x1808, 0xDF }, { 0x180B, 0xDF }, { 0x180F, 0x77 }, { 0x181D, 0x7F }, { 0x181F, 0xF7 }, { 0x182C, 0x7F }, { 0x183F, 0x7F }, { 0x184A, 0x7F }, { 0x184D, 0x7F }, { 0x184E, 0xF7 }, { 0x1859, 0x7F }, { 0x185F, 0x7F }, { 0x1864, 0x01 }, { 0x1868, 0x3F }, { 0x186E, 0x9F }, { 0x186F, 0xF7 }, { 0x187A, 0xFB }, { 0x188F, 0xBF }, { 0x189D, 0x7F }, { 0x189E, 0xFB }, { 0x18AA, 0xDF }, { 0x18BE, 0x7F }, { 0x18CF, 0x7F }, { 0x18DB, 0x77 }, { 0x18DC, 0xDF }, { 0x18E8, 0x77 }, { 0x18E9, 0x7F }, { 0x18FB, 0xF7 }, { 0x18FE, 0xF7 }, { 0x191E, 0x7F }, { 0x191F, 0x7F }, { 0x1929, 0xBF }, { 0x192D, 0xDF }, { 0x194C, 0xFB }, { 0x194E, 0xDF }, { 0x195B, 0x7F }, { 0x1968, 0xBF }, { 0x196A, 0xF7 }, { 0x197F, 0xF7 }, { 0x198B, 0x7F }, { 0x198E, 0x7F }, { 0x199B, 0xFB }, { 0x19A8, 0xDF }, { 0x19AA, 0xB7 }, { 0x19AB, 0x77 }, { 0x19AD, 0xFD }, { 0x19B8, 0xBF }, { 0x19BE, 0xFD }, { 0x19BF, 0xDF }, { 0x19DC, 0x7F }, { 0x19DF, 0x7D }, { 0x19EA, 0xDF }, { 0x19EC, 0xDF }, { 0x19EF, 0x7F }, { 0x19FB, 0xFB }, { 0x19FC, 0xF7 }, { 0x19FD, 0xBF }, { 0x19FF, 0xFE }, { 0x1A08, 0xDF }, { 0x1A0B, 0xF7 }, { 0x1A0D, 0x7F }, { 0x1A0F, 0x7F }, { 0x1A1A, 0xBF }, { 0x1A1D, 0xBF }, { 0x1A1F, 0x7F }, { 0x1A29, 0xFD }, { 0x1A2A, 0xFD }, { 0x1A2F, 0xF7 }, { 0x1A3E, 0x7F }, { 0x1A49, 0xFD }, { 0x1A4A, 0xBB }, { 0x1A4C, 0xF7 }, { 0x1A4F, 0x7F }, { 0x1A68, 0xF7 }, { 0x1A6D, 0xBF }, { 0x1A78, 0xBF }, { 0x1A7D, 0x7F }, { 0x1A7E, 0xF7 }, { 0x1A9B, 0xF7 }, { 0x1A9C, 0xBF }, { 0x1A9D, 0xF7 }, { 0x1A9F, 0x7F }, { 0x1AAA, 0x7F }, { 0x1ABF, 0xBF }, { 0x1ACA, 0xBF }, { 0x1ACF, 0xF7 }, { 0x1ADA, 0xF7 }, { 0x1AEA, 0xFD }, { 0x1AFF, 0xFD }, { 0x1B0B, 0xF7 }, { 0x1B19, 0x7F }, { 0x1B1D, 0xF7 }, { 0x1B1E, 0xF7 }, { 0x1B29, 0xDF }, { 0x1B3B, 0xFB }, { 0x1B3C, 0xF7 }, { 0x1B4D, 0xFB }, { 0x1B4F, 0xF7 }, { 0x1B6D, 0x7F }, { 0x1B6E, 0xF7 }, { 0x1B78, 0xF7 }, { 0x1B9B, 0x7F }, { 0x1B9E, 0xDF }, { 0x1B9F, 0x7F }, { 0x1BAB, 0xBF }, { 0x1BAF, 0xFD }, { 0x1BB8, 0xFB }, { 0x1BBA, 0xF7 }, { 0x1BBF, 0xF7 }, { 0x1BCD, 0xDF }, { 0x1BDA, 0xDF }, { 0x1BDE, 0x77 }, { 0x1BF8, 0xBF }, { 0x1BFC, 0xFD }, { 0x1BFD, 0xFB }, { 0x1BFE, 0xF7 }, { 0x1C0C, 0xF7 }, { 0x1C0E, 0x7F }, { 0x1C1A, 0x7F }, { 0x1C1C, 0xFB }, { 0x1C2E, 0xFB }, { 0x1C3E, 0xFD }, { 0x1C4D, 0x7F }, { 0x1C4F, 0xF7 }, { 0x1C5F, 0x7F }, { 0x1C6A, 0xFD }, { 0x1C6E, 0xFB }, { 0x1C89, 0xFB }, { 0x1C8B, 0xFD }, { 0x1C8E, 0xFD }, { 0x1C9A, 0xFB }, { 0x1C9C, 0x7F }, { 0x1CA8, 0xBF }, { 0x1CA9, 0xBF }, { 0x1CAE, 0xBF }, { 0x1CB9, 0xF7 }, { 0x1CBA, 0x7F }, { 0x1CBD, 0xDF }, { 0x1CCF, 0xF7 }, { 0x1D0C, 0xFB }, { 0x1D0F, 0x7F }, { 0x1D18, 0xBF }, { 0x1D1F, 0xF7 }, { 0x1D28, 0xDF }, { 0x1D29, 0xF7 }, { 0x1D2F, 0xF7 }, { 0x1D48, 0xD7 }, { 0x1D4A, 0xF7 }, { 0x1D59, 0xF7 }, { 0x1D63, 0x40 }, { 0x1D6A, 0xF7 }, { 0x1D6C, 0xBF }, { 0x1D6E, 0xF7 }, { 0x1D7D, 0xBF }, { 0x1D8E, 0xB7 }, { 0x1D9B, 0xFB }, { 0x1D9E, 0xFD }, { 0x1DAD, 0x7F }, { 0x1DAF, 0x7F }, { 0x1DC8, 0xF7 }, { 0x1DCA, 0xBF }, { 0x1DCF, 0xFB }, { 0x1DDB, 0xF7 }, { 0x1DDE, 0xBF }, { 0x1DE9, 0xBF }, { 0x1E0F, 0xFD }, { 0x1E1B, 0xFD }, { 0x1E2B, 0xDF }, { 0x1E2D, 0x7F }, { 0x1E39, 0xFB }, { 0x1E3A, 0x04 }, { 0x1E3D, 0xDF }, { 0x1E48, 0x5F }, { 0x1E4D, 0x7F }, { 0x1E5E, 0x7F }, { 0x1E6B, 0x7F }, { 0x1E6F, 0x3F }, { 0x1E7B, 0xFB }, { 0x1E7E, 0xF7 }, { 0x1E89, 0x7F }, { 0x1E8C, 0x7B }, { 0x1E8F, 0xF7 }, { 0x1E99, 0xF7 }, { 0x1E9C, 0xF7 }, { 0x1E9F, 0xFB }, { 0x1EA8, 0xFD }, { 0x1EAC, 0x7F }, { 0x1EAD, 0xF7 }, { 0x1EBF, 0xF7 }, { 0x1ECF, 0x7F }, { 0x1EDC, 0xDF }, { 0x1EDD, 0xFD }, { 0x1EDE, 0x77 }, { 0x1EDF, 0xF7 }, { 0x1EEE, 0xF5 }, { 0x1EEF, 0xF7 }, { 0x1EFB, 0xF3 }, { 0x1F08, 0x7F }, { 0x1F09, 0xF7 }, { 0x1F0C, 0x7F }, { 0x1F19, 0xFB }, { 0x1F1E, 0xFD }, { 0x1F2A, 0x02 }, { 0x1F38, 0xF7 }, { 0x1F4B, 0xDF }, { 0x1F4F, 0xBF }, { 0x1F5C, 0xFD }, { 0x1F5D, 0xDF }, { 0x1F5F, 0x7F }, { 0x1F78, 0xFB }, { 0x1F7A, 0x01 }, { 0x1F85, 0x01 }, { 0x1F88, 0x7F }, { 0x1F89, 0xDF }, { 0x1F8B, 0xF7 }, { 0x1F9E, 0xFD }, { 0x1F9F, 0x7F }, { 0x1FA8, 0xFB }, { 0x1FAC, 0xDF }, { 0x1FAE, 0xF7 }, { 0x1FAF, 0xDF }, { 0x1FBB, 0xBF }, { 0x1FBE, 0xFB }, { 0x1FCB, 0x7F }, { 0x1FCE, 0x7F }, { 0x1FD9, 0xF7 }, { 0x1FDE, 0xFB }, { 0x1FDF, 0x7F }, { 0x1FEB, 0x7F }, { 0x1FF8, 0x7F }, { 0x1FFB, 0xDF }, { 0x1FFC, 0x7F }, { 0x1FFD, 0x7F }, { 0x1FFE, 0xF7 }, { 0x2008, 0x1C }, { 0x200B, 0x03 }, { 0x2840, 0xFF }, { 0x2841, 0x7F }, { 0x2842, 0xFF }, { 0x2843, 0x7F }, { 0x2844, 0xFF }, { 0x2845, 0x7F }, { 0x2846, 0xFF }, { 0x2847, 0x7F }, { 0x2848, 0xFF }, { 0x2849, 0x7F }, { 0x284A, 0xFF }, { 0x284B, 0x7F }, { 0x284C, 0xFF }, { 0x284D, 0x7F }, { 0x284E, 0xFF }, { 0x284F, 0x7F }, { 0x2850, 0xFF }, { 0x2851, 0x7F }, { 0x2852, 0xFF }, { 0x2853, 0x7F }, { 0x2854, 0xFF }, { 0x2855, 0x7F }, { 0x2856, 0xFF }, { 0x2857, 0x7F }, { 0x2858, 0xFF }, { 0x2859, 0x7F }, { 0x285A, 0xFF }, { 0x285B, 0x7F }, { 0x285C, 0xFF }, { 0x285D, 0x7F }, { 0x285E, 0xFF }, { 0x285F, 0x7F }, { 0x2860, 0xFF }, { 0x2861, 0x7F }, { 0x2862, 0xFF }, { 0x2863, 0x7F }, { 0x2864, 0xFF }, { 0x2865, 0x7F }, { 0x2866, 0xFF }, { 0x2867, 0x7F }, { 0x2868, 0xFF }, { 0x2869, 0x7F }, { 0x286A, 0xFF }, { 0x286B, 0x7F }, { 0x286C, 0xFF }, { 0x286D, 0x7F }, { 0x286E, 0xFF }, { 0x286F, 0x7F }, { 0x2870, 0xFF }, { 0x2871, 0x7F }, { 0x2872, 0xFF }, { 0x2873, 0x7F }, { 0x2874, 0xFF }, { 0x2875, 0x7F }, { 0x2876, 0xFF }, { 0x2877, 0x7F }, { 0x2878, 0xFF }, { 0x2879, 0x7F }, { 0x287A, 0xFF }, { 0x287B, 0x7F }, { 0x287C, 0xFF }, { 0x287D, 0x7F }, { 0x287E, 0xFF }, { 0x287F, 0x7F }, { 0x2900, 0x80 }, { 0x2901, 0x80 }, { 0x2902, 0x40 }, { 0x2903, 0x88 }, { 0x2904, 0x88 }, { 0x2905, 0x68 }, { 0x2906, 0xDE }, { 0x2907, 0xDE }, { 0x2908, 0x70 }, { 0x2909, 0xDE }, { 0x290A, 0xDE }, { 0x290B, 0x78 }, { 0x290C, 0x20 }, { 0x290D, 0x20 }, { 0x290E, 0x38 }, { 0x290F, 0x20 }, { 0x2910, 0x20 }, { 0x2911, 0x90 }, { 0x2912, 0x20 }, { 0x2913, 0x20 }, { 0x2914, 0xA0 }, { 0x2915, 0xE0 }, { 0x2916, 0xE0 }, { 0x2917, 0xC0 }, { 0x2918, 0x98 }, { 0x2919, 0x98 }, { 0x291A, 0x48 }, { 0x291B, 0x80 }, { 0x291C, 0x80 }, { 0x291D, 0x50 }, { 0x291E, 0x1E }, { 0x291F, 0x1E }, { 0x2920, 0x58 }, { 0x2921, 0x20 }, { 0x2922, 0x20 }, { 0x2923, 0xE0 }, { 0x2924, 0x88 }, { 0x2925, 0x88 }, { 0x2926, 0x10 }, { 0x2927, 0x20 }, { 0x2928, 0x20 }, { 0x2929, 0x10 }, { 0x292A, 0x20 }, { 0x292B, 0x20 }, { 0x292C, 0x18 }, { 0x292D, 0xE0 }, { 0x292E, 0xE0 }, { 0x2930, 0x18 }, { 0x2931, 0x18 }, { 0x2932, 0x20 }, { 0x2933, 0xA8 }, { 0x2934, 0xA8 }, { 0x2935, 0x20 }, { 0x2936, 0x18 }, { 0x2937, 0x18 }, { 0x2939, 0x20 }, { 0x293A, 0x20 }, { 0x293B, 0xD8 }, { 0x293C, 0xC8 }, { 0x293D, 0xC8 }, { 0x293E, 0xE0 }, { 0x2941, 0x40 }, { 0x2942, 0x28 }, { 0x2943, 0x28 }, { 0x2944, 0x28 }, { 0x2945, 0x18 }, { 0x2946, 0x18 }, { 0x2947, 0x60 }, { 0x2948, 0x20 }, { 0x2949, 0x20 }, { 0x294A, 0xE0 }, { 0x294D, 0x08 }, { 0x294E, 0xE0 }, { 0x294F, 0xE0 }, { 0x2950, 0x30 }, { 0x2951, 0xD0 }, { 0x2952, 0xD0 }, { 0x2953, 0xD0 }, { 0x2954, 0x20 }, { 0x2955, 0x20 }, { 0x2956, 0xE8 }, { 0x2957, 0xFF }, { 0x2958, 0xFF }, { 0x2959, 0xBF }, { 0x2A00, 0xFF }, { 0x2A01, 0x7F }, { 0x2A02, 0xDF }, { 0x2A03, 0x01 }, { 0x2A04, 0x12 }, { 0x2A05, 0x01 }, { 0x2A08, 0xFF }, { 0x2A09, 0x7F }, { 0x2A0A, 0xDF }, { 0x2A0B, 0x01 }, { 0x2A0C, 0x12 }, { 0x2A0D, 0x01 }, { 0x2A10, 0xFF }, { 0x2A11, 0x7F }, { 0x2A12, 0xB5 }, { 0x2A13, 0x42 }, { 0x2A14, 0xC8 }, { 0x2A15, 0x3D }, { 0x2A18, 0x1F }, { 0x2A19, 0x23 }, { 0x2A1A, 0x5F }, { 0x2A1B, 0x03 }, { 0x2A1C, 0xF2 }, { 0x2A1E, 0x09 }, { 0x2A20, 0x1F }, { 0x2A21, 0x23 }, { 0x2A22, 0x5F }, { 0x2A23, 0x03 }, { 0x2A24, 0xF2 }, { 0x2A26, 0x09 }, { 0x2A28, 0xFF }, { 0x2A29, 0x4F }, { 0x2A2A, 0xD2 }, { 0x2A2B, 0x7E }, { 0x2A2C, 0x4C }, { 0x2A2D, 0x3A }, { 0x2A2E, 0xE0 }, { 0x2A2F, 0x1C }, { 0x2A30, 0xFF }, { 0x2A31, 0x7F }, { 0x2A32, 0xFF }, { 0x2A33, 0x7F }, { 0x2A34, 0x8C }, { 0x2A35, 0x7E }, { 0x2A37, 0x7C }, { 0x2A38, 0xFF }, { 0x2A39, 0x7F }, { 0x2A3A, 0xFF }, { 0x2A3B, 0x7F }, { 0x2A3C, 0x8C }, { 0x2A3D, 0x7E }, { 0x2A3F, 0x7C }, { 0x2A40, 0xED }, { 0x2A41, 0x03 }, { 0x2A42, 0xFF }, { 0x2A43, 0x7F }, { 0x2A44, 0x5F }, { 0x2A45, 0x25 }, { 0x2A48, 0xFF }, { 0x2A49, 0x7F }, { 0x2A4A, 0xFF }, { 0x2A4B, 0x7F }, { 0x2A4C, 0x8C }, { 0x2A4D, 0x7E }, { 0x2A4F, 0x7C }, { 0x2A50, 0xFF }, { 0x2A51, 0x7F }, { 0x2A52, 0xFF }, { 0x2A53, 0x7F }, { 0x2A54, 0x8C }, { 0x2A55, 0x7E }, { 0x2A57, 0x7C }, { 0x2A58, 0x6A }, { 0x2A59, 0x03 }, { 0x2A5A, 0x1F }, { 0x2A5B, 0x02 }, { 0x2A5C, 0xFF }, { 0x2A5D, 0x03 }, { 0x2A5E, 0xFF }, { 0x2A5F, 0x7F }, { 0x2A60, 0xFF }, { 0x2A61, 0x7F }, { 0x2A62, 0x1F }, { 0x2A63, 0x42 }, { 0x2A64, 0xF2 }, { 0x2A65, 0x1C }, { 0x2A68, 0xFF }, { 0x2A69, 0x7F }, { 0x2A6A, 0x1F }, { 0x2A6B, 0x42 }, { 0x2A6C, 0xF2 }, { 0x2A6D, 0x1C }, { 0x2A70, 0xFF }, { 0x2A71, 0x7F }, { 0x2A72, 0xEF }, { 0x2A73, 0x03 }, { 0x2A74, 0xD6 }, { 0x2A75, 0x01 }, { 0x2A78, 0xFF }, { 0x2A79, 0x7F }, { 0x2A7A, 0x1F }, { 0x2A7B, 0x42 }, { 0x2A7C, 0xF2 }, { 0x2A7D, 0x1C }, { 0x2A80, 0xFF }, { 0x2A81, 0x7F }, { 0x2A82, 0x1F }, { 0x2A83, 0x42 }, { 0x2A84, 0xF2 }, { 0x2A85, 0x1C }, { 0x2A88, 0xFF }, { 0x2A89, 0x7F }, { 0x2A8A, 0xEA }, { 0x2A8B, 0x03 }, { 0x2A8C, 0x1F }, { 0x2A8D, 0x01 }, { 0x2A90, 0xFF }, { 0x2A91, 0x7F }, { 0x2A92, 0x1F }, { 0x2A93, 0x42 }, { 0x2A94, 0xF2 }, { 0x2A95, 0x1C }, { 0x2A98, 0xFF }, { 0x2A99, 0x7F }, { 0x2A9A, 0x1F }, { 0x2A9B, 0x42 }, { 0x2A9C, 0xF2 }, { 0x2A9D, 0x1C }, { 0x2AA0, 0xFF }, { 0x2AA1, 0x7F }, { 0x2AA2, 0x7F }, { 0x2AA3, 0x02 }, { 0x2AA4, 0x1F }, { 0x2AA8, 0xFF }, { 0x2AA9, 0x7F }, { 0x2AAA, 0x8C }, { 0x2AAB, 0x7E }, { 0x2AAD, 0x7C }, { 0x2AB0, 0xFF }, { 0x2AB1, 0x7F }, { 0x2AB2, 0x8C }, { 0x2AB3, 0x7E }, { 0x2AB5, 0x7C }, { 0x2AB8, 0xFF }, { 0x2AB9, 0x7F }, { 0x2ABA, 0xFF }, { 0x2ABB, 0x03 }, { 0x2ABC, 0x1F }, { 0x2AC0, 0x9F }, { 0x2AC1, 0x29 }, { 0x2AC2, 0x1A }, { 0x2AC4, 0x0C }, { 0x2AC8, 0x9F }, { 0x2AC9, 0x29 }, { 0x2ACA, 0x1A }, { 0x2ACC, 0x0C }, { 0x2AD0, 0x74 }, { 0x2AD1, 0x7E }, { 0x2AD2, 0xFF }, { 0x2AD3, 0x03 }, { 0x2AD4, 0x80 }, { 0x2AD5, 0x01 }, { 0x2AD8, 0xFF }, { 0x2AD9, 0x7F }, { 0x2ADA, 0xDF }, { 0x2ADB, 0x01 }, { 0x2ADC, 0x12 }, { 0x2ADD, 0x01 }, { 0x2AE0, 0xFF }, { 0x2AE1, 0x7F }, { 0x2AE2, 0xDF }, { 0x2AE3, 0x01 }, { 0x2AE4, 0x12 }, { 0x2AE5, 0x01 }, { 0x2AE8, 0xFF }, { 0x2AE9, 0x67 }, { 0x2AEA, 0xAC }, { 0x2AEB, 0x77 }, { 0x2AEC, 0x13 }, { 0x2AED, 0x1A }, { 0x2AEE, 0x6B }, { 0x2AEF, 0x2D }, { 0x2AF2, 0xFF }, { 0x2AF3, 0x7F }, { 0x2AF4, 0x1F }, { 0x2AF5, 0x42 }, { 0x2AF6, 0xF2 }, { 0x2AF7, 0x1C }, { 0x2AFA, 0xFF }, { 0x2AFB, 0x7F }, { 0x2AFC, 0x1F }, { 0x2AFD, 0x42 }, { 0x2AFE, 0xF2 }, { 0x2AFF, 0x1C }, { 0x2B00, 0xD6 }, { 0x2B01, 0x7E }, { 0x2B02, 0xFF }, { 0x2B03, 0x4B }, { 0x2B04, 0x75 }, { 0x2B05, 0x21 }, { 0x2B08, 0xFF }, { 0x2B09, 0x7F }, { 0x2B0A, 0x1F }, { 0x2B0B, 0x42 }, { 0x2B0C, 0xF2 }, { 0x2B0D, 0x1C }, { 0x2B10, 0xFF }, { 0x2B11, 0x7F }, { 0x2B12, 0x1F }, { 0x2B13, 0x42 }, { 0x2B14, 0xF2 }, { 0x2B15, 0x1C }, { 0x2B18, 0xFF }, { 0x2B19, 0x7F }, { 0x2B1A, 0x8C }, { 0x2B1B, 0x7E }, { 0x2B1D, 0x7C }, { 0x2B20, 0x1F }, { 0x2B21, 0x23 }, { 0x2B22, 0x5F }, { 0x2B23, 0x03 }, { 0x2B24, 0xF2 }, { 0x2B26, 0x09 }, { 0x2B28, 0x1F }, { 0x2B29, 0x23 }, { 0x2B2A, 0x5F }, { 0x2B2B, 0x03 }, { 0x2B2C, 0xF2 }, { 0x2B2E, 0x09 }, { 0x2B30, 0xFF }, { 0x2B31, 0x7F }, { 0x2B32, 0x31 }, { 0x2B33, 0x6E }, { 0x2B34, 0x4A }, { 0x2B35, 0x45 }, { 0x2B38, 0xFF }, { 0x2B39, 0x7F }, { 0x2B3A, 0x1F }, { 0x2B3B, 0x42 }, { 0x2B3C, 0xF2 }, { 0x2B3D, 0x1C }, { 0x2B40, 0xFF }, { 0x2B41, 0x7F }, { 0x2B42, 0x1F }, { 0x2B43, 0x42 }, { 0x2B44, 0xF2 }, { 0x2B45, 0x1C }, { 0x2B48, 0xFF }, { 0x2B49, 0x7F }, { 0x2B4A, 0x31 }, { 0x2B4B, 0x6E }, { 0x2B4C, 0x4A }, { 0x2B4D, 0x45 }, { 0x2B50, 0xFF }, { 0x2B51, 0x7F }, { 0x2B52, 0x1F }, { 0x2B53, 0x42 }, { 0x2B54, 0xF2 }, { 0x2B55, 0x1C }, { 0x2B58, 0xFF }, { 0x2B59, 0x7F }, { 0x2B5A, 0x1F }, { 0x2B5B, 0x42 }, { 0x2B5C, 0xF2 }, { 0x2B5D, 0x1C }, { 0x2B60, 0xFF }, { 0x2B61, 0x7F }, { 0x2B62, 0xEF }, { 0x2B63, 0x1B }, { 0x2B65, 0x02 }, { 0x2B68, 0xFF }, { 0x2B69, 0x7F }, { 0x2B6A, 0x8C }, { 0x2B6B, 0x7E }, { 0x2B6D, 0x7C }, { 0x2B70, 0xFF }, { 0x2B71, 0x7F }, { 0x2B72, 0x8C }, { 0x2B73, 0x7E }, { 0x2B75, 0x7C }, { 0x2B78, 0xFF }, { 0x2B79, 0x7F }, { 0x2B7A, 0xBF }, { 0x2B7B, 0x32 }, { 0x2B7C, 0xD0 }, { 0x2B80, 0xFF }, { 0x2B81, 0x7F }, { 0x2B82, 0xEF }, { 0x2B83, 0x1B }, { 0x2B85, 0x02 }, { 0x2B88, 0xFF }, { 0x2B89, 0x7F }, { 0x2B8A, 0xEF }, { 0x2B8B, 0x1B }, { 0x2B8D, 0x02 }, { 0x2B90, 0xFF }, { 0x2B91, 0x7F }, { 0x2B92, 0x1F }, { 0x2B93, 0x42 }, { 0x2B94, 0xF2 }, { 0x2B95, 0x1C }, { 0x2B98, 0xFF }, { 0x2B99, 0x7F }, { 0x2B9A, 0xE0 }, { 0x2B9B, 0x03 }, { 0x2B9C, 0x06 }, { 0x2B9D, 0x02 }, { 0x2B9E, 0x20 }, { 0x2B9F, 0x01 }, { 0x2BA0, 0xFF }, { 0x2BA1, 0x7F }, { 0x2BA2, 0xE0 }, { 0x2BA3, 0x03 }, { 0x2BA4, 0x06 }, { 0x2BA5, 0x02 }, { 0x2BA6, 0x20 }, { 0x2BA7, 0x01 }, { 0x2BA8, 0xFF }, { 0x2BA9, 0x7F }, { 0x2BAA, 0x1F }, { 0x2BAB, 0x42 }, { 0x2BAC, 0xF2 }, { 0x2BAD, 0x1C }, { 0x2BB0, 0xFF }, { 0x2BB1, 0x7F }, { 0x2BB2, 0xEF }, { 0x2BB3, 0x1B }, { 0x2BB5, 0x02 }, { 0x2BB8, 0xFF }, { 0x2BB9, 0x7F }, { 0x2BBA, 0xEF }, { 0x2BBB, 0x1B }, { 0x2BBD, 0x02 }, { 0x2BC0, 0xFF }, { 0x2BC1, 0x7F }, { 0x2BC2, 0xBF }, { 0x2BC3, 0x32 }, { 0x2BC4, 0xD0 }, { 0x2BC8, 0xFF }, { 0x2BC9, 0x7F }, { 0x2BCA, 0x1F }, { 0x2BCB, 0x42 }, { 0x2BCC, 0xF2 }, { 0x2BCD, 0x1C }, { 0x2BD0, 0xFF }, { 0x2BD1, 0x7F }, { 0x2BD2, 0x1F }, { 0x2BD3, 0x42 }, { 0x2BD4, 0xF2 }, { 0x2BD5, 0x1C }, { 0x2BDB, 0x42 }, { 0x2BDC, 0x7F }, { 0x2BDD, 0x03 }, { 0x2BDE, 0xFF }, { 0x2BDF, 0x7F }, { 0x2BE0, 0xFF }, { 0x2BE1, 0x03 }, { 0x2BE2, 0x1F }, { 0x2BE4, 0x0C }, { 0x2BE8, 0xFF }, { 0x2BE9, 0x03 }, { 0x2BEA, 0x1F }, { 0x2BEC, 0x0C }, { 0x2BF0, 0xFF }, { 0x2BF1, 0x7F }, { 0x2BF2, 0x8C }, { 0x2BF3, 0x7E }, { 0x2BF5, 0x7C }, { 0x2BF8, 0xFF }, { 0x2BF9, 0x7F }, { 0x2BFA, 0xBF }, { 0x2BFB, 0x32 }, { 0x2BFC, 0xD0 }, { 0x2C00, 0xFF }, { 0x2C01, 0x7F }, { 0x2C02, 0xBF }, { 0x2C03, 0x32 }, { 0x2C04, 0xD0 }, { 0x2C08, 0xFF }, { 0x2C09, 0x7F }, { 0x2C0A, 0xB5 }, { 0x2C0B, 0x42 }, { 0x2C0C, 0xC8 }, { 0x2C0D, 0x3D }, { 0x2C10, 0xFF }, { 0x2C11, 0x7F }, { 0x2C12, 0x94 }, { 0x2C13, 0x52 }, { 0x2C14, 0x4A }, { 0x2C15, 0x29 }, { 0x2C18, 0xFF }, { 0x2C19, 0x7F }, { 0x2C1A, 0x94 }, { 0x2C1B, 0x52 }, { 0x2C1C, 0x4A }, { 0x2C1D, 0x29 }, { 0x2C20, 0xFF }, { 0x2C21, 0x7F }, { 0x2C22, 0x94 }, { 0x2C23, 0x52 }, { 0x2C24, 0x4A }, { 0x2C25, 0x29 }, { 0x2C28, 0xFF }, { 0x2C29, 0x7F }, { 0x2C2A, 0xEF }, { 0x2C2B, 0x1B }, { 0x2C2D, 0x02 }, { 0x2C30, 0xFF }, { 0x2C31, 0x7F }, { 0x2C32, 0xEF }, { 0x2C33, 0x1B }, { 0x2C35, 0x02 }, { 0x2C38, 0xFF }, { 0x2C39, 0x53 }, { 0x2C3A, 0x5F }, { 0x2C3B, 0x4A }, { 0x2C3C, 0x52 }, { 0x2C3D, 0x7E }, { 0x2C40, 0xFF }, { 0x2C41, 0x7F }, { 0x2C42, 0x1F }, { 0x2C43, 0x42 }, { 0x2C44, 0xF2 }, { 0x2C45, 0x1C }, { 0x2C48, 0xFF }, { 0x2C49, 0x7F }, { 0x2C4A, 0x1F }, { 0x2C4B, 0x42 }, { 0x2C4C, 0xF2 }, { 0x2C4D, 0x1C }, { 0x2C50, 0xFF }, { 0x2C51, 0x7F }, { 0x2C52, 0x8C }, { 0x2C53, 0x7E }, { 0x2C55, 0x7C }, { 0x2C58, 0xFF }, { 0x2C59, 0x7F }, { 0x2C5A, 0xBF }, { 0x2C5B, 0x32 }, { 0x2C5C, 0xD0 }, { 0x2C60, 0xFF }, { 0x2C61, 0x7F }, { 0x2C62, 0xBF }, { 0x2C63, 0x32 }, { 0x2C64, 0xD0 }, { 0x2C68, 0x9F }, { 0x2C69, 0x63 }, { 0x2C6A, 0x79 }, { 0x2C6B, 0x42 }, { 0x2C6C, 0xB0 }, { 0x2C6D, 0x15 }, { 0x2C6E, 0xCB }, { 0x2C6F, 0x04 }, { 0x2C70, 0xFF }, { 0x2C71, 0x7F }, { 0x2C72, 0x8C }, { 0x2C73, 0x7E }, { 0x2C75, 0x7C }, { 0x2C78, 0xFF }, { 0x2C79, 0x7F }, { 0x2C7A, 0x8C }, { 0x2C7B, 0x7E }, { 0x2C7D, 0x7C }, { 0x2C80, 0xFF }, { 0x2C81, 0x7F }, { 0x2C82, 0xFF }, { 0x2C83, 0x03 }, { 0x2C84, 0x2F }, { 0x2C85, 0x01 }, { 0x2C88, 0xFF }, { 0x2C89, 0x7F }, { 0x2C8A, 0x3F }, { 0x2C8B, 0x03 }, { 0x2C8C, 0x93 }, { 0x2C8D, 0x01 }, { 0x2C90, 0xFF }, { 0x2C91, 0x7F }, { 0x2C92, 0x3F }, { 0x2C93, 0x03 }, { 0x2C94, 0x93 }, { 0x2C95, 0x01 }, { 0x2C98, 0xFF }, { 0x2C99, 0x7F }, { 0x2C9A, 0x3F }, { 0x2C9B, 0x03 }, { 0x2C9C, 0x93 }, { 0x2C9D, 0x01 }, { 0x2CA0, 0xFF }, { 0x2CA1, 0x7F }, { 0x2CA2, 0x1F }, { 0x2CA3, 0x42 }, { 0x2CA4, 0xF2 }, { 0x2CA5, 0x1C }, { 0x2CA8, 0xFF }, { 0x2CA9, 0x7F }, { 0x2CAA, 0x1F }, { 0x2CAB, 0x42 }, { 0x2CAC, 0xF2 }, { 0x2CAD, 0x1C }, { 0x2CB0, 0xFF }, { 0x2CB1, 0x7F }, { 0x2CB2, 0xEF }, { 0x2CB3, 0x1B }, { 0x2CB4, 0x80 }, { 0x2CB5, 0x61 }, { 0x2CB8, 0x20 }, { 0x2CB9, 0x21 }, { 0x2CBA, 0x22 }, { 0x2CBB, 0x80 }, { 0x2CBC, 0x81 }, { 0x2CBD, 0x82 }, { 0x2CBE, 0x10 }, { 0x2CBF, 0x11 }, { 0x2CC0, 0x20 }, { 0x2CC1, 0x21 }, { 0x2CC2, 0x22 }, { 0x2CC3, 0x80 }, { 0x2CC4, 0x81 }, { 0x2CC5, 0x82 }, { 0x2CC6, 0x10 }, { 0x2CC7, 0x11 }, { 0x2CC9, 0xFF }, { 0x2CCA, 0x7F }, { 0x2CCB, 0xFF }, { 0x2CCC, 0x03 }, { 0x2CCD, 0x1F }, { 0x2CD0, 0xFF }, { 0x2CD1, 0x7F }, { 0x2CD2, 0xBF }, { 0x2CD3, 0x32 }, { 0x2CD4, 0xD0 }, { 0x2CD8, 0xFF }, { 0x2CD9, 0x7F }, { 0x2CDA, 0xBF }, { 0x2CDB, 0x32 }, { 0x2CDC, 0xD0 }, { 0x2CE0, 0xFF }, { 0x2CE1, 0x7F }, { 0x2CE2, 0xBF }, { 0x2CE3, 0x32 }, { 0x2CE4, 0xD0 }, { 0x2CE8, 0xFF }, { 0x2CE9, 0x7F }, { 0x2CEA, 0xBF }, { 0x2CEB, 0x32 }, { 0x2CEC, 0xD0 }, { 0x2CF0, 0xFF }, { 0x2CF1, 0x7F }, { 0x2CF2, 0xBF }, { 0x2CF3, 0x32 }, { 0x2CF4, 0xD0 }, { 0x2CF8, 0xFF }, { 0x2CF9, 0x7F }, { 0x2CFA, 0xBF }, { 0x2CFB, 0x32 }, { 0x2CFC, 0xD0 }, { 0x307F, 0x40 }, { 0x30E9, 0x02 }, { 0x30F4, 0xBF }, { 0x3107, 0xF7 }, { 0x3180, 0x3F }, { 0x31BB, 0x10 }, { 0x31F4, 0xDF }, { 0x3212, 0x7F }, { 0x3225, 0x7F }, { 0x326A, 0x01 }, { 0x32B0, 0x7F }, { 0x32B5, 0xF7 }, { 0x32F0, 0xFD }, { 0x32F6, 0x7F }, { 0x3300, 0x7F }, { 0x3311, 0xF7 }, { 0x3331, 0xDF }, { 0x3354, 0xF7 }, { 0x3397, 0xBF }, { 0x33BC, 0x04 }, { 0x3437, 0xDF }, { 0x34D1, 0x7F }, { 0x34E1, 0xDF }, { 0x3510, 0xBF }, { 0x3547, 0x7F }, { 0x3573, 0xF7 }, { 0x3586, 0xDF }, { 0x35A5, 0xBF }, { 0x35B0, 0xF7 }, { 0x35D7, 0xF7 }, { 0x3601, 0xDF }, { 0x3607, 0xBD }, { 0x3634, 0xF7 }, { 0x3690, 0xF7 }, { 0x369A, 0x04 }, { 0x36C8, 0x10 }, { 0x36D2, 0xF7 }, { 0x36E3, 0xBF }, { 0x3705, 0xFD }, { 0x371C, 0x40 }, { 0x371D, 0x01 }, { 0x371F, 0x04 }, { 0x372E, 0x40 }, { 0x3731, 0xDF }, { 0x3768, 0x01 }, { 0x3780, 0xBF }, { 0x37A7, 0x7F }, { 0x37CD, 0x01 }, { 0x37F6, 0xF7 }, { 0x3808, 0x7F }, { 0x380C, 0xBF }, { 0x3834, 0x02 }, { 0x383A, 0xBF }, { 0x384D, 0xBF }, { 0x385A, 0x7F }, { 0x385D, 0x7F }, { 0x386B, 0xBF }, { 0x387B, 0xFB }, { 0x387C, 0xFD }, { 0x3889, 0xBF }, { 0x388A, 0x7F }, { 0x38A8, 0xF7 }, { 0x38AA, 0x7F }, { 0x38AE, 0xBF }, { 0x38BC, 0x7F }, { 0x38EC, 0xDF }, { 0x38FB, 0xF7 }, { 0x38FC, 0xFD }, { 0x390B, 0xBF }, { 0x392B, 0x7F }, { 0x392D, 0xBF }, { 0x393D, 0xFB }, { 0x3958, 0xFD }, { 0x395F, 0xF7 }, { 0x396F, 0x7F }, { 0x3979, 0xDF }, { 0x397F, 0x7F }, { 0x3989, 0xF3 }, { 0x398F, 0x7F }, { 0x3998, 0xBF }, { 0x399E, 0xF7 }, { 0x399F, 0xFB }, { 0x39AC, 0xF7 }, { 0x39AD, 0xDF }, { 0x39AE, 0xF7 }, { 0x39AF, 0xF7 }, { 0x39BA, 0xF7 }, { 0x39BB, 0xF7 }, { 0x39BE, 0xFB }, { 0x39BF, 0x7F }, { 0x39C8, 0xFB }, { 0x39CC, 0xF7 }, { 0x39D9, 0x7F }, { 0x39DE, 0x7F }, { 0x39DF, 0x7F }, { 0x39EA, 0xF7 }, { 0x39FD, 0xBF }, { 0x39FE, 0xF7 }, { 0x3A09, 0x7F }, { 0x3A18, 0xBF }, { 0x3A1B, 0xBF }, { 0x3A1D, 0xF7 }, { 0x3A2B, 0xBF }, { 0x3A2C, 0xF7 }, { 0x3A2F, 0x7F }, { 0x3A3E, 0xDF }, { 0x3A4E, 0x7F }, { 0x3A4F, 0x7F }, { 0x3A5D, 0x7F }, { 0x3A6D, 0xDF }, { 0x3A6E, 0xDF }, { 0x3A8B, 0xF7 }, { 0x3A99, 0xBF }, { 0x3A9D, 0x7F }, { 0x3A9E, 0xF7 }, { 0x3AAB, 0xF7 }, { 0x3AAC, 0xDF }, { 0x3AAE, 0xF7 }, { 0x3ACD, 0xD7 }, { 0x3ACE, 0xF7 }, { 0x3AD8, 0x7F }, { 0x3AE9, 0xFD }, { 0x3AEB, 0x3F }, { 0x3AFB, 0xF7 }, { 0x3B1C, 0xF5 }, { 0x3B2B, 0xF7 }, { 0x3B2C, 0x9F }, { 0x3B2D, 0xBF }, { 0x3B3C, 0xDB }, { 0x3B3D, 0xF7 }, { 0x3B3E, 0x7F }, { 0x3B3F, 0xFB }, { 0x3B48, 0xFB }, { 0x3B4B, 0x7F }, { 0x3B4C, 0xF7 }, { 0x3B5A, 0x7F }, { 0x3B6A, 0x7F }, { 0x3B6B, 0xBF }, { 0x3B7B, 0xFB }, { 0x3B7D, 0x7F }, { 0x3B7F, 0xBF }, { 0x3B8D, 0xFB }, { 0x3B8F, 0x5F }, { 0x3B98, 0x7F }, { 0x3B9A, 0x7F }, { 0x3B9E, 0xFD }, { 0x3BAB, 0xFD }, { 0x3BAC, 0xDF }, { 0x3BAF, 0xF7 }, { 0x3BB2, 0x02 }, { 0x3BBB, 0x7F }, { 0x3BCE, 0xFD }, { 0x3BDB, 0xBF }, { 0x3C18, 0x7F }, { 0x3C1F, 0x7F }, { 0x3C2B, 0xF7 }, { 0x3C39, 0xFD }, { 0x3C4A, 0x77 }, { 0x3C4C, 0x7F }, { 0x3C59, 0xBF }, { 0x3C5F, 0xFB }, { 0x3C68, 0x7F }, { 0x3C69, 0xDF }, { 0x3C6A, 0xBB }, { 0x3C6F, 0x7F }, { 0x3C79, 0xF7 }, { 0x3C8B, 0xDF }, { 0x3C9A, 0x5F }, { 0x3CA9, 0x7F }, { 0x3CAF, 0xBF }, { 0x3CB8, 0xBF }, { 0x3CB9, 0x7F }, { 0x3CBA, 0x7F }, { 0x3CBB, 0x7F }, { 0x3CBC, 0xBF }, { 0x3CBF, 0xDD }, { 0x3CC8, 0xDF }, { 0x3CCF, 0x7F }, { 0x3CDD, 0xF7 }, { 0x3CDE, 0x77 }, { 0x3CE8, 0xF7 }, { 0x3CEB, 0xDF }, { 0x3CEF, 0xFB }, { 0x3CF0, 0x01 }, { 0x3CF9, 0x7F }, { 0x3CFB, 0xF7 }, { 0x3D19, 0xF7 }, { 0x3D2A, 0xFB }, { 0x3D2F, 0x7F }, { 0x3D3B, 0xDD }, { 0x3D3F, 0xFB }, { 0x3D48, 0xBF }, { 0x3D5B, 0xF7 }, { 0x3D6F, 0xBF }, { 0x3D7D, 0xFB }, { 0x3D8A, 0x7F }, { 0x3D8C, 0xFB }, { 0x3D96, 0x40 }, { 0x3D9F, 0x7F }, { 0x3DAA, 0xF7 }, { 0x3DAD, 0xF7 }, { 0x3DAF, 0x77 }, { 0x3DB8, 0x7F }, { 0x3DBC, 0xBF }, { 0x3DBD, 0xDF }, { 0x3DC9, 0xF7 }, { 0x3DEF, 0xDF }, { 0x3DFA, 0xDF }, { 0x3DFD, 0xFD }, { 0x3DFE, 0xFB }, { 0x3E18, 0xFB }, { 0x3E1F, 0xF7 }, { 0x3E2D, 0xDF }, { 0x3E2F, 0xFB }, { 0x3E3D, 0x7F }, { 0x3E3F, 0xFB }, { 0x3E48, 0xF5 }, { 0x3E49, 0xFD }, { 0x3E5C, 0xFB }, { 0x3E5F, 0x5F }, { 0x3E6D, 0xBF }, { 0x3E6F, 0x7F }, { 0x3E7C, 0xFD }, { 0x3E7E, 0x7F }, { 0x3E88, 0xFD }, { 0x3E9E, 0xFD }, { 0x3EAE, 0x7F }, { 0x3EBC, 0xDF }, { 0x3ECD, 0x77 }, { 0x3EED, 0xF7 }, { 0x3EFB, 0x7F }, { 0x3F08, 0xF7 }, { 0x3F0F, 0xFD }, { 0x3F1D, 0xBF }, { 0x3F1E, 0x9F }, { 0x3F29, 0xFB }, { 0x3F2E, 0x7F }, { 0x3F39, 0xDF }, { 0x3F3F, 0xDF }, { 0x3F48, 0xDF }, { 0x3F4E, 0xFB }, { 0x3F69, 0xFD }, { 0x3F7C, 0xFD }, { 0x3F7E, 0x3F }, { 0x3F89, 0xF7 }, { 0x3F9B, 0xF7 }, { 0x3F9E, 0xF7 }, { 0x3FAE, 0x7F }, { 0x3FB2, 0xDF }, { 0x3FBC, 0xF7 }, { 0x3FD9, 0xBD }, { 0x3FDB, 0xD7 }, { 0x3FDE, 0x7F }, { 0x3FEE, 0x7F }, { 0x3FEF, 0x7F }, { 0x3FFE, 0x7B }, { 0x4045, 0x7F }, { 0x408C, 0x20 }, { 0x40A7, 0xFD }, { 0x40B3, 0xD7 }, { 0x40D1, 0x7F }, { 0x40E0, 0x77 }, { 0x40FE, 0x40 }, { 0x4103, 0x7F }, { 0x4130, 0xBF }, { 0x413D, 0x10 }, { 0x4152, 0xF7 }, { 0x4159, 0x01 }, { 0x417D, 0x02 }, { 0x41A5, 0xDF }, { 0x41A7, 0x7F }, { 0x4218, 0x40 }, { 0x421F, 0x02 }, { 0x4222, 0xF7 }, { 0x4286, 0xF7 }, { 0x42E3, 0x9F }, { 0x4303, 0xFB }, { 0x434E, 0x04 }, { 0x43BA, 0x01 }, { 0x4408, 0x01 }, { 0x4413, 0xF7 }, { 0x442E, 0x20 }, { 0x443B, 0x01 }, { 0x44C7, 0x7F }, { 0x44E0, 0x7F }, { 0x44E7, 0xF7 }, { 0x4523, 0xF7 }, { 0x4534, 0x7F }, { 0x4546, 0x7F }, { 0x4579, 0x10 }, { 0x458A, 0x01 }, { 0x4594, 0xFB }, { 0x459A, 0x02 }, { 0x45B4, 0xF7 }, { 0x45B6, 0xFD }, { 0x45C5, 0x7F }, { 0x45D5, 0x7F }, { 0x45F0, 0xF7 }, { 0x4613, 0xFB }, { 0x4638, 0x01 }, { 0x4678, 0x01 }, { 0x4694, 0xBF }, { 0x46A0, 0xF7 }, { 0x46CE, 0x01 }, { 0x46D6, 0xBF }, { 0x46F4, 0xF7 }, { 0x46F5, 0xDF }, { 0x4710, 0x7F }, { 0x4727, 0x7F }, { 0x472B, 0x04 }, { 0x4730, 0xBF }, { 0x4736, 0x7F }, { 0x4762, 0xF7 }, { 0x476C, 0x04 }, { 0x477B, 0x04 }, { 0x47D5, 0xFB }, { 0x47E4, 0xBF }, { 0x47F0, 0xDF }, { 0x4809, 0x7F }, { 0x480D, 0x7F }, { 0x481E, 0xDF }, { 0x4828, 0x7F }, { 0x482E, 0xFD }, { 0x4838, 0xFD }, { 0x483D, 0x7F }, { 0x483F, 0xFB }, { 0x484B, 0xFD }, { 0x484D, 0x7F }, { 0x485E, 0xFD }, { 0x486F, 0xBF }, { 0x4878, 0xDF }, { 0x4888, 0xFB }, { 0x4889, 0xF7 }, { 0x488D, 0x7F }, { 0x48A9, 0x7F }, { 0x48AC, 0xDF }, { 0x48AE, 0x7F }, { 0x48B4, 0x01 }, { 0x48BC, 0xF7 }, { 0x48BD, 0xBB }, { 0x48BE, 0xF7 }, { 0x48C8, 0xFB }, { 0x48CB, 0xDF }, { 0x48CC, 0x7F }, { 0x48ED, 0xFB }, { 0x48EE, 0x7F }, { 0x48F0, 0x10 }, { 0x490B, 0xB7 }, { 0x4929, 0x7F }, { 0x492E, 0xBF }, { 0x4930, 0x01 }, { 0x493D, 0xDF }, { 0x4948, 0xFB }, { 0x494A, 0x7F }, { 0x494E, 0xFB }, { 0x496E, 0x5F }, { 0x496F, 0xDF }, { 0x4979, 0xF7 }, { 0x498E, 0xDF }, { 0x499A, 0xFB }, { 0x499D, 0xF7 }, { 0x499F, 0xF7 }, { 0x49A9, 0xBF }, { 0x49AA, 0x7F }, { 0x49BD, 0xF7 }, { 0x49BE, 0xFD }, { 0x49C9, 0xBF }, { 0x49DE, 0x7F }, { 0x49EB, 0xFD }, { 0x49EE, 0x7F }, { 0x4A1B, 0xF7 }, { 0x4A1D, 0x77 }, { 0x4A1E, 0x7F }, { 0x4A1F, 0xBF }, { 0x4A2B, 0xDF }, { 0x4A30, 0x40 }, { 0x4A3F, 0xF3 }, { 0x4A4F, 0xFB }, { 0x4A58, 0xF7 }, { 0x4A69, 0xF7 }, { 0x4A6B, 0xF7 }, { 0x4A6E, 0xF7 }, { 0x4A7E, 0xFD }, { 0x4A8F, 0x7F }, { 0x4A99, 0x7F }, { 0x4A9A, 0xF7 }, { 0x4A9D, 0x7F }, { 0x4A9E, 0xFB }, { 0x4AAE, 0xFD }, { 0x4AB9, 0x7F }, { 0x4ABC, 0x7F }, { 0x4ABD, 0xF7 }, { 0x4ACB, 0xBF }, { 0x4ACE, 0xF7 }, { 0x4ACF, 0xDF }, { 0x4ADC, 0xF7 }, { 0x4ADE, 0xFB }, { 0x4AEE, 0xBF }, { 0x4AFF, 0x7F }, { 0x4B1B, 0xFB }, { 0x4B1E, 0xF3 }, { 0x4B28, 0xF7 }, { 0x4B3A, 0xF7 }, { 0x4B3B, 0x5D }, { 0x4B3D, 0xFB }, { 0x4B3F, 0x3F }, { 0x4B4D, 0xBF }, { 0x4B4E, 0xF7 }, { 0x4B5F, 0x7F }, { 0x4B6E, 0xFB }, { 0x4B8A, 0xDF }, { 0x4B8F, 0x7F }, { 0x4B90, 0x10 }, { 0x4B9B, 0xDD }, { 0x4B9F, 0x7F }, { 0x4BA9, 0x7F }, { 0x4BAC, 0xBF }, { 0x4BB9, 0xFD }, { 0x4BC8, 0xFB }, { 0x4BCA, 0xFB }, { 0x4BCB, 0xDB }, { 0x4BCD, 0x77 }, { 0x4BDB, 0xFD }, { 0x4BDC, 0xF7 }, { 0x4BDF, 0x7F }, { 0x4BE9, 0x7F }, { 0x4BF9, 0xF7 }, { 0x4BFA, 0xFB }, { 0x4BFB, 0xBF }, { 0x4BFD, 0x77 }, { 0x4BFE, 0xF9 }, { 0x4C0A, 0x7F }, { 0x4C0F, 0xBF }, { 0x4C18, 0xFD }, { 0x4C19, 0xBF }, { 0x4C1B, 0xF7 }, { 0x4C1C, 0x7F }, { 0x4C1E, 0x7F }, { 0x4C1F, 0x7F }, { 0x4C38, 0xF7 }, { 0x4C3D, 0xF7 }, { 0x4C48, 0xDF }, { 0x4C4A, 0xF7 }, { 0x4C4D, 0xDF }, { 0x4C5D, 0xF7 }, { 0x4C68, 0x7F }, { 0x4C6B, 0x7F }, { 0x4C6F, 0x7F }, { 0x4C7F, 0x7F }, { 0x4C81, 0x40 }, { 0x4C88, 0xFB }, { 0x4C99, 0xF7 }, { 0x4C9C, 0x7F }, { 0x4C9D, 0x7F }, { 0x4CAE, 0x7F }, { 0x4CAF, 0x7F }, { 0x4CBA, 0xBF }, { 0x4CBB, 0x7F }, { 0x4CBC, 0xFB }, { 0x4CBF, 0xF7 }, { 0x4CCA, 0xBF }, { 0x4CCB, 0xBF }, { 0x4CCF, 0xBF }, { 0x4CDA, 0xF3 }, { 0x4CDB, 0xBF }, { 0x4CE8, 0xFD }, { 0x4CEB, 0xFB }, { 0x4CED, 0xDF }, { 0x4D08, 0xBF }, { 0x4D0A, 0x77 }, { 0x4D19, 0xFB }, { 0x4D1C, 0xFB }, { 0x4D1F, 0xBF }, { 0x4D2F, 0x7D }, { 0x4D39, 0xBF }, { 0x4D3A, 0xDF }, { 0x4D3B, 0x77 }, { 0x4D5A, 0xBF }, { 0x4D5B, 0x77 }, { 0x4D5E, 0xF7 }, { 0x4D7A, 0xB7 }, { 0x4D7B, 0xF7 }, { 0x4D7C, 0x7F }, { 0x4D7F, 0x7F }, { 0x4D8D, 0xDF }, { 0x4D8F, 0xF7 }, { 0x4D9F, 0x7F }, { 0x4DBD, 0x7F }, { 0x4DCC, 0xBF }, { 0x4DCF, 0x7F }, { 0x4DD8, 0xFD }, { 0x4DDB, 0x7F }, { 0x4DE5, 0x04 }, { 0x4DFA, 0xBF }, { 0x4E0B, 0xDF }, { 0x4E0C, 0x7F }, { 0x4E19, 0xFD }, { 0x4E1B, 0xF7 }, { 0x4E1F, 0xFB }, { 0x4E4F, 0x7F }, { 0x4E69, 0x7F }, { 0x4E6F, 0xFD }, { 0x4E7B, 0xFB }, { 0x4E7F, 0xBF }, { 0x4E89, 0xF7 }, { 0x4E98, 0xFB }, { 0x4E9E, 0x7F }, { 0x4EA8, 0xF7 }, { 0x4EA9, 0xFD }, { 0x4EBB, 0xD7 }, { 0x4EC8, 0xBF }, { 0x4EE0, 0x40 }, { 0x4EEC, 0xF7 }, { 0x4EFB, 0xFB }, { 0x4EFC, 0x7F }, { 0x4EFF, 0xFD }, { 0x4F0C, 0x7F }, { 0x4F0D, 0xFB }, { 0x4F1D, 0xFB }, { 0x4F28, 0xBF }, { 0x4F3D, 0xBF }, { 0x4F4D, 0xDF }, { 0x4F4F, 0xFB }, { 0x4F5C, 0xF7 }, { 0x4F5E, 0xF7 }, { 0x4F6F, 0xFD }, { 0x4F78, 0xF7 }, { 0x4F7B, 0xF7 }, { 0x4F7D, 0x7F }, { 0x4F85, 0x10 }, { 0x4F99, 0xFD }, { 0x4F9D, 0x7F }, { 0x4F9F, 0x7F }, { 0x4FAB, 0xFB }, { 0x4FAC, 0x7F }, { 0x4FAD, 0x7D }, { 0x4FAF, 0xFD }, { 0x4FBD, 0xF7 }, { 0x4FC8, 0x7D }, { 0x4FD9, 0x9F }, { 0x4FDE, 0x7F }, { 0x4FE9, 0x7F }, { 0x4FED, 0xFD }, { 0x4FEE, 0xFD }, { 0x4FF9, 0xF7 }, { 0x4FFC, 0xBF }, { 0x4FFF, 0x7F }, { 0x5008, 0x01 }, { 0x5063, 0xBF }, { 0x5086, 0xBF }, { 0x509A, 0x04 }, { 0x50B1, 0xF7 }, { 0x50DC, 0x04 }, { 0x5131, 0x7F }, { 0x514E, 0x20 }, { 0x515A, 0x10 }, { 0x517B, 0x01 }, { 0x518F, 0x01 }, { 0x51A2, 0xBF }, { 0x51D1, 0x7F }, { 0x5201, 0xFB }, { 0x5212, 0xF7 }, { 0x5219, 0x04 }, { 0x5232, 0xF7 }, { 0x5242, 0x7F }, { 0x531B, 0x01 }, { 0x5347, 0x7F }, { 0x5367, 0x7F }, { 0x5372, 0xF7 }, { 0x5384, 0xFD }, { 0x53B4, 0xFB }, { 0x53D0, 0xF7 }, { 0x5410, 0xFB }, { 0x5442, 0xFD }, { 0x5455, 0x7F }, { 0x5456, 0xBF }, { 0x5462, 0x7F }, { 0x5490, 0xBF }, { 0x5524, 0xFB }, { 0x5542, 0xF7 }, { 0x5562, 0xDF }, { 0x5575, 0xF7 }, { 0x5581, 0xDF }, { 0x5582, 0xBF }, { 0x55D7, 0x7F }, { 0x55F6, 0xF7 }, { 0x5612, 0xDF }, { 0x5613, 0x7F }, { 0x5627, 0xFB }, { 0x5644, 0x7F }, { 0x56FA, 0x02 }, { 0x5725, 0xF7 }, { 0x5734, 0xFD }, { 0x5739, 0x02 }, { 0x57E9, 0x20 }, { 0x580A, 0xFB }, { 0x580D, 0x7F }, { 0x5819, 0x7F }, { 0x581E, 0xFD }, { 0x582F, 0xF7 }, { 0x584D, 0xBF }, { 0x584F, 0xFB }, { 0x5859, 0xF7 }, { 0x586D, 0xBF }, { 0x587C, 0xDF }, { 0x587E, 0xF7 }, { 0x5889, 0xFD }, { 0x5898, 0xBF }, { 0x589C, 0xF7 }, { 0x58AA, 0xBF }, { 0x58CB, 0xDF }, { 0x58EE, 0xF7 }, { 0x58FF, 0x7F }, { 0x590E, 0xFB }, { 0x5918, 0xBF }, { 0x5929, 0x7F }, { 0x592A, 0xBF }, { 0x592B, 0xFD }, { 0x593A, 0xBF }, { 0x593E, 0x7F }, { 0x5949, 0x7F }, { 0x595B, 0x7F }, { 0x5979, 0x7F }, { 0x597D, 0x7F }, { 0x5988, 0x7F }, { 0x5989, 0xBF }, { 0x598B, 0x7F }, { 0x5998, 0xBF }, { 0x599F, 0xFD }, { 0x59A8, 0xDF }, { 0x59AE, 0xFD }, { 0x59B8, 0x7F }, { 0x59CA, 0xFB }, { 0x59CE, 0x7F }, { 0x59CF, 0xFB }, { 0x59DD, 0xBF }, { 0x59EA, 0xFB }, { 0x59EB, 0x7F }, { 0x59F8, 0xF7 }, { 0x59F9, 0xFD }, { 0x59FA, 0xF7 }, { 0x5A0F, 0xDF }, { 0x5A1A, 0xF7 }, { 0x5A1D, 0x7F }, { 0x5A1F, 0xBF }, { 0x5A2E, 0xF7 }, { 0x5A3F, 0x7F }, { 0x5A59, 0xDF }, { 0x5A5A, 0xB7 }, { 0x5A5F, 0x7F }, { 0x5A6D, 0xF7 }, { 0x5A7C, 0xDF }, { 0x5A8F, 0x7F }, { 0x5A98, 0x7B }, { 0x5AAA, 0x7F }, { 0x5AAF, 0x7F }, { 0x5ABC, 0x7F }, { 0x5ABD, 0xFD }, { 0x5ACD, 0xDF }, { 0x5AD9, 0xBF }, { 0x5ADF, 0x7F }, { 0x5AE8, 0x7F }, { 0x5AEA, 0xF7 }, { 0x5AED, 0xF7 }, { 0x5AFE, 0xF7 }, { 0x5AFF, 0x5F }, { 0x5B09, 0xFB }, { 0x5B0A, 0xFB }, { 0x5B0E, 0xBF }, { 0x5B0F, 0x7B }, { 0x5B28, 0xFD }, { 0x5B2B, 0xFB }, { 0x5B2E, 0xBF }, { 0x5B2F, 0xFB }, { 0x5B3D, 0xF7 }, { 0x5B3F, 0xF7 }, { 0x5B49, 0x7F }, { 0x5B4E, 0xF7 }, { 0x5B5E, 0xF7 }, { 0x5B6B, 0x7F }, { 0x5B6C, 0xBF }, { 0x5B6F, 0x7F }, { 0x5B79, 0x7F }, { 0x5B7E, 0x5F }, { 0x5B8E, 0xDF }, { 0x5B99, 0xF3 }, { 0x5B9F, 0xD7 }, { 0x5BA8, 0xBF }, { 0x5BAA, 0xBF }, { 0x5BAC, 0xF7 }, { 0x5BAD, 0x77 }, { 0x5BBA, 0x7F }, { 0x5BBE, 0xF7 }, { 0x5BCA, 0xBF }, { 0x5BCF, 0x5F }, { 0x5BD2, 0x40 }, { 0x5BDB, 0xF7 }, { 0x5BEA, 0xF7 }, { 0x5BEB, 0xF7 }, { 0x5BFB, 0xBB }, { 0x5BFD, 0xF7 }, { 0x5C0E, 0x7F }, { 0x5C0F, 0xDF }, { 0x5C1A, 0xF7 }, { 0x5C28, 0x7F }, { 0x5C2B, 0xF7 }, { 0x5C3D, 0xDF }, { 0x5C3E, 0xFB }, { 0x5C4A, 0xDF }, { 0x5C4C, 0xDF }, { 0x5C4D, 0xFD }, { 0x5C5C, 0x7F }, { 0x5C6D, 0x7F }, { 0x5C7F, 0x7F }, { 0x5C85, 0x01 }, { 0x5C8A, 0xFD }, { 0x5C8B, 0x7F }, { 0x5C9B, 0xBF }, { 0x5C9F, 0x7F }, { 0x5CAE, 0x7F }, { 0x5CAF, 0x7F }, { 0x5CB9, 0xFB }, { 0x5CCE, 0xFD }, { 0x5CD3, 0x04 }, { 0x5CD6, 0x01 }, { 0x5CDF, 0xFD }, { 0x5CEB, 0x7F }, { 0x5CF9, 0xBF }, { 0x5D0B, 0xBF }, { 0x5D1D, 0xFD }, { 0x5D1E, 0x7F }, { 0x5D2B, 0xFD }, { 0x5D2C, 0xFD }, { 0x5D2D, 0x7F }, { 0x5D2F, 0xBF }, { 0x5D3A, 0x7F }, { 0x5D3B, 0xF7 }, { 0x5D4B, 0xFB }, { 0x5D4D, 0xFB }, { 0x5D4F, 0xF7 }, { 0x5D5A, 0xFD }, { 0x5D5B, 0xDF }, { 0x5D5C, 0x7F }, { 0x5D5E, 0xBF }, { 0x5D69, 0xFB }, { 0x5D6B, 0xB7 }, { 0x5D6D, 0xBF }, { 0x5D70, 0x02 }, { 0x5D78, 0xF7 }, { 0x5D7F, 0xFB }, { 0x5D8A, 0xDF }, { 0x5D8F, 0xFD }, { 0x5D99, 0xBF }, { 0x5D9E, 0xDF }, { 0x5DAC, 0xFB }, { 0x5DCB, 0x7F }, { 0x5DCD, 0xBF }, { 0x5DDB, 0xD7 }, { 0x5DDE, 0x7F }, { 0x5DE9, 0x7F }, { 0x5DEA, 0xFB }, { 0x5DFF, 0x7F }, { 0x5E19, 0xF7 }, { 0x5E1F, 0xFB }, { 0x5E28, 0xBF }, { 0x5E2D, 0xDF }, { 0x5E3D, 0x7F }, { 0x5E49, 0x7F }, { 0x5E4E, 0xFB }, { 0x5E5C, 0xBF }, { 0x5E68, 0xFD }, { 0x5E6C, 0xDF }, { 0x5E6D, 0xDF }, { 0x5E79, 0xDF }, { 0x5E7D, 0x7F }, { 0x5E99, 0x7F }, { 0x5EAF, 0xBF }, { 0x5EBC, 0xDF }, { 0x5EC8, 0xBF }, { 0x5ECC, 0xF7 }, { 0x5ED2, 0xBF }, { 0x5EF9, 0xF7 }, { 0x5EFE, 0xDF }, { 0x5F08, 0xF7 }, { 0x5F0F, 0xF7 }, { 0x5F18, 0xFD }, { 0x5F19, 0x7F }, { 0x5F1B, 0xFD }, { 0x5F3F, 0x7F }, { 0x5F4C, 0xFD }, { 0x5F4E, 0xF7 }, { 0x5F5C, 0x7F }, { 0x5F5D, 0xF7 }, { 0x5F5E, 0x7F }, { 0x5F69, 0xFB }, { 0x5F6C, 0xFD }, { 0x5F6F, 0xDF }, { 0x5F92, 0xF7 }, { 0x5FAD, 0x7F }, { 0x5FAE, 0xF7 }, { 0x5FCD, 0xF7 }, { 0x5FCF, 0xBF }, { 0x5FDC, 0xF7 }, { 0x5FDE, 0x7F }, { 0x5FDF, 0x7F }, { 0x5FEB, 0x7F }, { 0x5FED, 0xDF }, { 0x5FF8, 0xDF }, { 0x600C, 0x20 }, { 0x6041, 0xBF }, { 0x6045, 0x7F }, { 0x6062, 0xF7 }, { 0x6077, 0xBF }, { 0x60A0, 0xDF }, { 0x60C1, 0x7F }, { 0x60C7, 0xFD }, { 0x60CB, 0x40 }, { 0x60E8, 0x01 }, { 0x6118, 0x02 }, { 0x613C, 0x01 }, { 0x6143, 0xF7 }, { 0x614A, 0x40 }, { 0x615B, 0x10 }, { 0x616F, 0x01 }, { 0x617C, 0x01 }, { 0x6190, 0xDF }, { 0x6196, 0xF7 }, { 0x61A6, 0x7F }, { 0x61D6, 0xF7 }, { 0x61F8, 0x04 }, { 0x61FA, 0x10 }, { 0x6201, 0x7F }, { 0x62A7, 0xBF }, { 0x62D4, 0x7F }, { 0x6322, 0xF7 }, { 0x6361, 0xFB }, { 0x6363, 0x7F }, { 0x6374, 0xF7 }, { 0x6392, 0x7F }, { 0x639F, 0x01 }, { 0x63A0, 0xF7 }, { 0x63A1, 0x7F }, { 0x63D9, 0x20 }, { 0x63E8, 0x01 }, { 0x6406, 0x7F }, { 0x6424, 0x7F }, { 0x6437, 0x7F }, { 0x643B, 0x01 }, { 0x64B1, 0xFB }, { 0x6514, 0xF7 }, { 0x6536, 0xFD }, { 0x6546, 0x7F }, { 0x6578, 0x01 }, { 0x6582, 0x7F }, { 0x65A3, 0xFB }, { 0x65B9, 0x01 }, { 0x65C9, 0x01 }, { 0x65E0, 0xF7 }, { 0x6612, 0xDF }, { 0x6632, 0xF7 }, { 0x6636, 0x7F }, { 0x6651, 0xF7 }, { 0x6666, 0xF7 }, { 0x6675, 0x7F }, { 0x6684, 0x7F }, { 0x6687, 0x7F }, { 0x66E9, 0x40 }, { 0x6706, 0xFD }, { 0x6713, 0xDF }, { 0x6758, 0x11 }, { 0x6773, 0xF7 }, { 0x6776, 0xBF }, { 0x67F0, 0x7F }, { 0x682B, 0xFB }, { 0x682C, 0xFB }, { 0x683E, 0xF5 }, { 0x683F, 0x7F }, { 0x6849, 0xF7 }, { 0x685C, 0xF5 }, { 0x686C, 0x7F }, { 0x686D, 0xF7 }, { 0x686E, 0x7F }, { 0x687E, 0xDF }, { 0x6889, 0x7F }, { 0x688E, 0xBF }, { 0x688F, 0x7F }, { 0x689B, 0xF7 }, { 0x689C, 0xF7 }, { 0x689E, 0x7F }, { 0x68CB, 0xBF }, { 0x68E9, 0x7F }, { 0x68EA, 0xDF }, { 0x68EB, 0x7F }, { 0x68EF, 0xF7 }, { 0x690B, 0xF7 }, { 0x6918, 0xBF }, { 0x691D, 0xF7 }, { 0x6929, 0x7F }, { 0x6938, 0x7F }, { 0x693A, 0x3F }, { 0x693E, 0x3F }, { 0x6949, 0xF7 }, { 0x694C, 0x7F }, { 0x694D, 0xDF }, { 0x694E, 0x77 }, { 0x695A, 0xFD }, { 0x697B, 0x7F }, { 0x697E, 0x7F }, { 0x6989, 0x7F }, { 0x698A, 0x7F }, { 0x698E, 0xF7 }, { 0x698F, 0xF7 }, { 0x699B, 0xDF }, { 0x699E, 0x5F }, { 0x699F, 0xDF }, { 0x69AD, 0x7F }, { 0x69C9, 0xF7 }, { 0x69D9, 0xF7 }, { 0x69DC, 0xF7 }, { 0x69F9, 0xBF }, { 0x69FA, 0xF7 }, { 0x69FC, 0x7F }, { 0x6A09, 0xF7 }, { 0x6A1B, 0x7F }, { 0x6A2A, 0xF7 }, { 0x6A2D, 0xFD }, { 0x6A3C, 0xFD }, { 0x6A3D, 0x7F }, { 0x6A3F, 0x7F }, { 0x6A5A, 0xBF }, { 0x6A6C, 0xFB }, { 0x6A6F, 0xFD }, { 0x6A7A, 0xF7 }, { 0x6A7B, 0x7B }, { 0x6A89, 0x7F }, { 0x6A9F, 0x7F }, { 0x6AAB, 0xDF }, { 0x6AB8, 0xF7 }, { 0x6ABE, 0xFD }, { 0x6AC8, 0xFD }, { 0x6ACB, 0x7F }, { 0x6ACF, 0xD7 }, { 0x6ADC, 0xFD }, { 0x6AEA, 0xBF }, { 0x6AEB, 0xF7 }, { 0x6AF8, 0xFB }, { 0x6AFD, 0xBF }, { 0x6B1A, 0x7F }, { 0x6B1F, 0x7F }, { 0x6B2D, 0xFD }, { 0x6B2E, 0xD7 }, { 0x6B3E, 0xDF }, { 0x6B4B, 0xF7 }, { 0x6B4D, 0xFB }, { 0x6B4F, 0xBF }, { 0x6B5E, 0x7B }, { 0x6B5F, 0x7F }, { 0x6B6C, 0xFB }, { 0x6B6F, 0xDF }, { 0x6B88, 0xDD }, { 0x6B8A, 0xFB }, { 0x6B8B, 0x77 }, { 0x6BA8, 0x7F }, { 0x6BAA, 0xF7 }, { 0x6BCA, 0xFB }, { 0x6BCB, 0xF7 }, { 0x6BDB, 0xDF }, { 0x6BDC, 0xBF }, { 0x6BDD, 0x77 }, { 0x6BDF, 0xFD }, { 0x6BE8, 0x7F }, { 0x6BE9, 0xF7 }, { 0x6BED, 0x7F }, { 0x6BF8, 0xFD }, { 0x6BF9, 0xF5 }, { 0x6BFA, 0xF7 }, { 0x6BFD, 0xF5 }, { 0x6BFE, 0xF7 }, { 0x6BFF, 0xBF }, { 0x6C09, 0xFB }, { 0x6C0F, 0x7F }, { 0x6C29, 0xD7 }, { 0x6C2F, 0x7F }, { 0x6C3A, 0xDF }, { 0x6C3E, 0xF7 }, { 0x6C4E, 0xBF }, { 0x6C5E, 0x7F }, { 0x6C5F, 0xDF }, { 0x6C79, 0xDF }, { 0x6C7A, 0x7F }, { 0x6C7E, 0xBF }, { 0x6C8B, 0x7F }, { 0x6C8D, 0xDF }, { 0x6C99, 0xFD }, { 0x6C9A, 0xBF }, { 0x6C9E, 0x7F }, { 0x6CA9, 0x7F }, { 0x6CAA, 0xF7 }, { 0x6CAC, 0xFB }, { 0x6CAD, 0x7F }, { 0x6CAF, 0xF7 }, { 0x6CC9, 0xFB }, { 0x6CDC, 0xFD }, { 0x6CEC, 0xDF }, { 0x6CEF, 0xBF }, { 0x6CFB, 0x7F }, { 0x6D1D, 0xFD }, { 0x6D1F, 0xDF }, { 0x6D2B, 0xD9 }, { 0x6D3B, 0x7F }, { 0x6D3C, 0xB7 }, { 0x6D4D, 0xBF }, { 0x6D58, 0x7F }, { 0x6D5C, 0x7F }, { 0x6D6D, 0xFD }, { 0x6D7E, 0x7F }, { 0x6D89, 0xBF }, { 0x6D9B, 0x7F }, { 0x6D9F, 0xF7 }, { 0x6DB9, 0x7F }, { 0x6DBF, 0xFB }, { 0x6DE9, 0x7F }, { 0x6DEA, 0xF7 }, { 0x6DEC, 0xBF }, { 0x6DFB, 0x7F }, { 0x6E09, 0x7F }, { 0x6E0F, 0x7F }, { 0x6E10, 0x01 }, { 0x6E12, 0xDF }, { 0x6E1E, 0xFB }, { 0x6E28, 0xF7 }, { 0x6E2E, 0xFB }, { 0x6E4E, 0x7F }, { 0x6E72, 0x7F }, { 0x6E79, 0x7F }, { 0x6E7E, 0x9F }, { 0x6E88, 0x7F }, { 0x6E8E, 0xF7 }, { 0x6E9E, 0xBF }, { 0x6EAC, 0xFD }, { 0x6EAD, 0xF7 }, { 0x6EAF, 0x7F }, { 0x6EB9, 0xFB }, { 0x6EBE, 0x7F }, { 0x6EC9, 0x7F }, { 0x6EE8, 0xF7 }, { 0x6EE9, 0x77 }, { 0x6EEB, 0xF7 }, { 0x6EEC, 0x7F }, { 0x6F04, 0x04 }, { 0x6F0C, 0x7F }, { 0x6F0E, 0x7F }, { 0x6F18, 0xDF }, { 0x6F1F, 0x7F }, { 0x6F2B, 0xFB }, { 0x6F2E, 0xFD }, { 0x6F3C, 0xF7 }, { 0x6F3F, 0x7F }, { 0x6F4D, 0xFB }, { 0x6F59, 0x77 }, { 0x6F5E, 0x7F }, { 0x6F6B, 0xFB }, { 0x6F6E, 0x9F }, { 0x6F9F, 0x7F }, { 0x6FAD, 0xB7 }, { 0x6FBF, 0xF7 }, { 0x6FC8, 0xDF }, { 0x6FCD, 0x3F }, { 0x6FCE, 0xBB }, { 0x6FDC, 0x7F }, { 0x6FDD, 0xDF }, { 0x6FEF, 0xF7 }, { 0x6FFB, 0xFB }, { 0x6FFD, 0x77 }, { 0x701E, 0x10 }, { 0x7047, 0x7F }, { 0x7076, 0xF7 }, { 0x707C, 0x10 }, { 0x70D5, 0xFD }, { 0x70F4, 0xDF }, { 0x710C, 0x04 }, { 0x711A, 0x01 }, { 0x714E, 0x06 }, { 0x716F, 0x01 }, { 0x71A3, 0xDF }, { 0x71B0, 0xFD }, { 0x71DE, 0x10 }, { 0x7206, 0xBF }, { 0x720C, 0x40 }, { 0x7223, 0xFB }, { 0x726C, 0x04 }, { 0x7272, 0xF7 }, { 0x72A5, 0xBF }, { 0x72C0, 0xF7 }, { 0x72DE, 0x01 }, { 0x72F8, 0x04 }, { 0x7302, 0xDF }, { 0x7313, 0x7F }, { 0x7332, 0xF7 }, { 0x7372, 0xF7 }, { 0x73EB, 0x40 }, { 0x7410, 0xDF }, { 0x7423, 0xF7 }, { 0x7432, 0xF7 }, { 0x7433, 0xF7 }, { 0x744A, 0x01 }, { 0x748B, 0x01 }, { 0x7490, 0xF7 }, { 0x749A, 0x01 }, { 0x7526, 0xFB }, { 0x7536, 0x7F }, { 0x7540, 0x7F }, { 0x7557, 0x7F }, { 0x757F, 0x04 }, { 0x7584, 0x7F }, { 0x75B8, 0x01 }, { 0x75C2, 0xF7 }, { 0x75C6, 0x7F }, { 0x75D5, 0xB7 }, { 0x75F8, 0x01 }, { 0x7607, 0xDF }, { 0x764F, 0x02 }, { 0x7694, 0x7F }, { 0x7697, 0xFD }, { 0x76CC, 0x10 }, { 0x76D0, 0xF7 }, { 0x76E0, 0xF7 }, { 0x7702, 0xF7 }, { 0x7721, 0x7F }, { 0x7752, 0xFB }, { 0x77B6, 0xFB }, { 0x77B8, 0x01 }, { 0x77C2, 0xF7 }, { 0x77D2, 0xF7 }, { 0x77D3, 0x7F }, { 0x77E3, 0xFD }, { 0x780B, 0x7F }, { 0x780F, 0x3F }, { 0x7818, 0xF7 }, { 0x7834, 0x01 }, { 0x784C, 0x7F }, { 0x784F, 0x5F }, { 0x785B, 0x7F }, { 0x7878, 0x7F }, { 0x7888, 0x7F }, { 0x7889, 0xFB }, { 0x788A, 0xFB }, { 0x788B, 0xF7 }, { 0x78B9, 0x7F }, { 0x78CB, 0xDF }, { 0x78CD, 0x7F }, { 0x78DA, 0xF7 }, { 0x78EA, 0xF7 }, { 0x78FB, 0xFB }, { 0x790B, 0x7F }, { 0x790C, 0xF7 }, { 0x790D, 0xDF }, { 0x790E, 0xFB }, { 0x790F, 0xFD }, { 0x791A, 0x7F }, { 0x791D, 0xBF }, { 0x793B, 0xF7 }, { 0x793F, 0x7F }, { 0x7949, 0xFD }, { 0x794F, 0xFB }, { 0x795C, 0x7F }, { 0x7960, 0x01 }, { 0x7968, 0xBF }, { 0x7969, 0xFD }, { 0x7978, 0x7F }, { 0x797D, 0xF7 }, { 0x798D, 0xFE }, { 0x798E, 0xBF }, { 0x79A9, 0x7F }, { 0x79AD, 0xF7 }, { 0x79BB, 0xFD }, { 0x79C8, 0xF7 }, { 0x79C9, 0x7F }, { 0x79DB, 0x7F }, { 0x79DE, 0x7F }, { 0x79E9, 0xFB }, { 0x79F8, 0xB7 }, { 0x79FB, 0xBF }, { 0x79FF, 0xBF }, { 0x7A0C, 0xF3 }, { 0x7A0F, 0xDD }, { 0x7A18, 0x7F }, { 0x7A38, 0x7F }, { 0x7A39, 0x7F }, { 0x7A49, 0xBF }, { 0x7A4B, 0x77 }, { 0x7A4C, 0x7F }, { 0x7A51, 0x40 }, { 0x7A6D, 0xFD }, { 0x7A6F, 0x7F }, { 0x7A8E, 0x7F }, { 0x7AAF, 0xDF }, { 0x7ABB, 0x7F }, { 0x7ACE, 0xBF }, { 0x7ADC, 0xDF }, { 0x7ADF, 0xB7 }, { 0x7AEE, 0xF7 }, { 0x7AEF, 0xFB }, { 0x7AF8, 0xF7 }, { 0x7AFB, 0x7F }, { 0x7AFE, 0xFB }, { 0x7B0F, 0xDF }, { 0x7B19, 0xFD }, { 0x7B1F, 0xFD }, { 0x7B29, 0xF5 }, { 0x7B2D, 0x7F }, { 0x7B2F, 0xF7 }, { 0x7B38, 0x7F }, { 0x7B3C, 0xFB }, { 0x7B3D, 0xFD }, { 0x7B4A, 0xF7 }, { 0x7B4B, 0xF7 }, { 0x7B5A, 0x7F }, { 0x7B5E, 0x7F }, { 0x7B5F, 0xBF }, { 0x7B6D, 0xBF }, { 0x7B6F, 0x33 }, { 0x7B7A, 0xF7 }, { 0x7B7B, 0xFB }, { 0x7B7F, 0x7F }, { 0x7B8E, 0x7F }, { 0x7B95, 0x04 }, { 0x7B99, 0xF7 }, { 0x7BA9, 0x7F }, { 0x7BB8, 0x7F }, { 0x7BB9, 0xFD }, { 0x7BCE, 0x7F }, { 0x7BCF, 0x7F }, { 0x7BD8, 0xD7 }, { 0x7BDA, 0x7F }, { 0x7BDC, 0x7F }, { 0x7BDE, 0xF7 }, { 0x7BE9, 0xFB }, { 0x7BF8, 0x9F }, { 0x7BFA, 0xBF }, { 0x7BFB, 0xDF }, { 0x7BFE, 0xF7 }, { 0x7BFF, 0x77 }, { 0x7C08, 0x7F }, { 0x7C0A, 0xDF }, { 0x7C1A, 0x7F }, { 0x7C1C, 0xF7 }, { 0x7C2E, 0x7F }, { 0x7C2F, 0x7F }, { 0x7C3E, 0xF7 }, { 0x7C48, 0xF7 }, { 0x7C59, 0x7F }, { 0x7C5C, 0xF7 }, { 0x7C7B, 0xF7 }, { 0x7C7F, 0xFB }, { 0x7CB9, 0xDF }, { 0x7CBF, 0x7F }, { 0x7CD9, 0x7F }, { 0x7CDA, 0x7F }, { 0x7CDD, 0x7F }, { 0x7CFD, 0xDF }, { 0x7D08, 0xFD }, { 0x7D1D, 0xF7 }, { 0x7D2D, 0xD7 }, { 0x7D2F, 0x7F }, { 0x7D3B, 0xBF }, { 0x7D4A, 0xDF }, { 0x7D4D, 0xF7 }, { 0x7D4E, 0x7F }, { 0x7D5A, 0x7F }, { 0x7D5B, 0xDF }, { 0x7D5F, 0xDF }, { 0x7D6A, 0xBF }, { 0x7D6C, 0xFB }, { 0x7D6E, 0xF9 }, { 0x7D78, 0xF7 }, { 0x7D7D, 0xDF }, { 0x7D7E, 0x7F }, { 0x7D8D, 0xF7 }, { 0x7D8E, 0xF7 }, { 0x7D8F, 0x5F }, { 0x7D98, 0x77 }, { 0x7D9A, 0xF7 }, { 0x7D9D, 0xDF }, { 0x7D9E, 0xFB }, { 0x7DB8, 0xF7 }, { 0x7DB9, 0xF7 }, { 0x7DBB, 0xDF }, { 0x7DBC, 0xDF }, { 0x7DBF, 0xDF }, { 0x7DCC, 0xBF }, { 0x7DD9, 0xF7 }, { 0x7DEA, 0xDF }, { 0x7DEC, 0xFD }, { 0x7DEE, 0xDD }, { 0x7DF9, 0xF7 }, { 0x7DFD, 0x7F }, { 0x7E02, 0xFD }, { 0x7E0B, 0xFD }, { 0x7E18, 0xF7 }, { 0x7E1B, 0xFB }, { 0x7E1D, 0x7F }, { 0x7E48, 0xFB }, { 0x7E4A, 0x01 }, { 0x7E6C, 0xDF }, { 0x7E6F, 0xF7 }, { 0x7E8E, 0xFD }, { 0x7EDD, 0x7F }, { 0x7EEA, 0x20 }, { 0x7EEB, 0xBF }, { 0x7EEF, 0xEF }, { 0x7EFD, 0x77 }, { 0x7EFE, 0x7F }, { 0x7EFF, 0xDF }, { 0x7F28, 0xF7 }, { 0x7F2C, 0xF7 }, { 0x7F2E, 0x7B }, { 0x7F2F, 0xF7 }, { 0x7F36, 0x10 }, { 0x7F3D, 0xFD }, { 0x7F49, 0x7F }, { 0x7F58, 0x7B }, { 0x7F5E, 0xDF }, { 0x7F68, 0xF7 }, { 0x7F6C, 0xF7 }, { 0x7F7B, 0xF9 }, { 0x7F7E, 0xDF }, { 0x7F8D, 0xDF }, { 0x7F92, 0xF7 }, { 0x7F98, 0xF7 }, { 0x7F9C, 0x7F }, { 0x7FA9, 0xB9 }, { 0x7FAB, 0x7B }, { 0x7FBC, 0x7F }, { 0x7FBF, 0xF7 }, { 0x7FC9, 0x7F }, { 0x7FCB, 0x7F }, { 0x7FCD, 0xBF }, { 0x7FCE, 0x7F }, { 0x7FCF, 0xFB }, { 0x7FDB, 0xF7 }, { 0x7FDF, 0x7F }, { 0x7FE8, 0xDF }, { 0x7FEC, 0xFB }, { 0x7FF2, 0xF7 } }; for (unsigned addr = 0x0000; addr < 0x0800; addr += 0x10) { std::memset(wram + addr + 0x00, 0xFF, 0x08); std::memset(wram + addr + 0x08, 0x00, 0x08); } for (unsigned addr = 0x0800; addr < 0x1000; addr += 0x10) { std::memset(wram + addr + 0x00, 0x00, 0x08); std::memset(wram + addr + 0x08, 0xFF, 0x08); } for (unsigned addr = 0x0E00; addr < 0x1000; addr += 0x10) { wram[addr + 0x02] = 0xFF; wram[addr + 0x0A] = 0x00; } for (unsigned addr = 0x1000; addr < 0x8000; addr += 0x1000) { if (0x2000 != addr) std::memcpy(wram + addr, wram, 0x1000); } std::memset(wram + 0x2000, 0, 0x1000); for (std::size_t i = 0; i < sizeof cgbWramDumpDiff / sizeof cgbWramDumpDiff[0]; ++i) wram[cgbWramDumpDiff[i].addr] = cgbWramDumpDiff[i].val; } static void setInitialDmgWram(unsigned char wram[]) { static struct { unsigned short addr; unsigned char val; } const dmgWramDumpDiff[] = { { 0x0000, 0x08 }, { 0x0004, 0x08 }, { 0x0008, 0x4D }, { 0x000A, 0x80 }, { 0x0010, 0x02 }, { 0x0018, 0x04 }, { 0x0020, 0x10 }, { 0x0028, 0x05 }, { 0x002C, 0x08 }, { 0x0038, 0x21 }, { 0x003A, 0x40 }, { 0x0060, 0x02 }, { 0x0066, 0x03 }, { 0x0068, 0x40 }, { 0x0072, 0x80 }, { 0x0074, 0x40 }, { 0x0076, 0x80 }, { 0x007C, 0x80 }, { 0x007E, 0x20 }, { 0x0080, 0x0C }, { 0x0088, 0x08 }, { 0x008C, 0x02 }, { 0x008E, 0x04 }, { 0x0092, 0x01 }, { 0x0098, 0x02 }, { 0x00A2, 0x08 }, { 0x00A8, 0x02 }, { 0x00AC, 0x15 }, { 0x00B0, 0x02 }, { 0x00B2, 0x80 }, { 0x00B6, 0x80 }, { 0x00B8, 0x06 }, { 0x00BA, 0x01 }, { 0x00BC, 0x08 }, { 0x00C4, 0x04 }, { 0x00C8, 0x02 }, { 0x00CC, 0x01 }, { 0x00D0, 0x85 }, { 0x00D8, 0x81 }, { 0x00DC, 0x01 }, { 0x00DE, 0x01 }, { 0x00E0, 0x01 }, { 0x00E6, 0x08 }, { 0x00E8, 0x44 }, { 0x00EC, 0x44 }, { 0x00F0, 0x40 }, { 0x00F4, 0x20 }, { 0x00FA, 0x04 }, { 0x00FC, 0x12 }, { 0x00FE, 0x01 }, { 0x0103, 0x7F }, { 0x0107, 0xFD }, { 0x0113, 0xFB }, { 0x0119, 0xBF }, { 0x011B, 0xEF }, { 0x011D, 0xFB }, { 0x0121, 0xFB }, { 0x0133, 0xF7 }, { 0x0135, 0x6F }, { 0x0137, 0xBD }, { 0x013F, 0xF6 }, { 0x0145, 0xF7 }, { 0x0149, 0xDF }, { 0x014D, 0xFA }, { 0x014F, 0xFE }, { 0x0151, 0xFD }, { 0x0161, 0xFD }, { 0x0165, 0xBF }, { 0x0171, 0xFD }, { 0x0173, 0xEF }, { 0x0177, 0xFE }, { 0x0179, 0x7F }, { 0x0185, 0xF7 }, { 0x0189, 0xEF }, { 0x0199, 0xF7 }, { 0x01AB, 0xEF }, { 0x01B1, 0x7F }, { 0x01B3, 0xEF }, { 0x01B5, 0xBF }, { 0x01C1, 0xFB }, { 0x01C9, 0xFB }, { 0x01CB, 0xEF }, { 0x01CF, 0xBF }, { 0x01D5, 0x7F }, { 0x01E1, 0xDD }, { 0x01E7, 0xF7 }, { 0x01F5, 0xFE }, { 0x0218, 0x01 }, { 0x0220, 0x08 }, { 0x0226, 0x08 }, { 0x022C, 0x20 }, { 0x0230, 0x50 }, { 0x0238, 0x01 }, { 0x0246, 0x02 }, { 0x0256, 0x10 }, { 0x0258, 0x40 }, { 0x0260, 0x70 }, { 0x0264, 0x04 }, { 0x0268, 0x28 }, { 0x0278, 0x02 }, { 0x0284, 0x10 }, { 0x0298, 0x20 }, { 0x029A, 0x10 }, { 0x02A0, 0x44 }, { 0x02AE, 0x20 }, { 0x02B2, 0x20 }, { 0x02C0, 0x28 }, { 0x02CA, 0x64 }, { 0x02D0, 0x20 }, { 0x02E0, 0x80 }, { 0x02E8, 0x02 }, { 0x02EA, 0x02 }, { 0x02EE, 0x08 }, { 0x02F0, 0x0C }, { 0x02F2, 0x02 }, { 0x0305, 0xDF }, { 0x0307, 0xFE }, { 0x0309, 0xFD }, { 0x030F, 0xBF }, { 0x0311, 0xFB }, { 0x0325, 0xDF }, { 0x0329, 0xFD }, { 0x0335, 0xFD }, { 0x033B, 0xF7 }, { 0x0345, 0xFB }, { 0x0347, 0xFD }, { 0x034B, 0xEF }, { 0x0353, 0xF9 }, { 0x035B, 0xBF }, { 0x035D, 0xBF }, { 0x0361, 0xF5 }, { 0x0369, 0xBF }, { 0x0375, 0xFD }, { 0x0381, 0xEF }, { 0x0383, 0xDF }, { 0x038D, 0xF7 }, { 0x0391, 0xF7 }, { 0x039B, 0xFE }, { 0x03A9, 0xDF }, { 0x03B3, 0xFB }, { 0x03C1, 0xFE }, { 0x03CD, 0xFB }, { 0x03DB, 0xFB }, { 0x03DD, 0x7F }, { 0x03E1, 0x7F }, { 0x03ED, 0xFD }, { 0x03F3, 0xFD }, { 0x03FD, 0xFB }, { 0x0406, 0x20 }, { 0x040E, 0x04 }, { 0x0412, 0x05 }, { 0x041C, 0x08 }, { 0x0420, 0x10 }, { 0x0422, 0x40 }, { 0x0428, 0x40 }, { 0x042A, 0x08 }, { 0x0430, 0x32 }, { 0x0434, 0x02 }, { 0x0438, 0x80 }, { 0x043A, 0x01 }, { 0x044A, 0x02 }, { 0x0452, 0x50 }, { 0x0458, 0x01 }, { 0x0470, 0x14 }, { 0x0478, 0xA0 }, { 0x047A, 0x01 }, { 0x048E, 0x01 }, { 0x0490, 0x04 }, { 0x0492, 0x10 }, { 0x0496, 0x50 }, { 0x0498, 0x02 }, { 0x049E, 0x0C }, { 0x04A2, 0x40 }, { 0x04A6, 0x01 }, { 0x04A8, 0xC0 }, { 0x04B0, 0x02 }, { 0x04BE, 0x20 }, { 0x04C2, 0x01 }, { 0x04C8, 0x01 }, { 0x04CC, 0x01 }, { 0x04D0, 0x01 }, { 0x04D2, 0x20 }, { 0x04DE, 0x01 }, { 0x04E0, 0x0C }, { 0x04E2, 0x18 }, { 0x04EA, 0x08 }, { 0x04EE, 0x01 }, { 0x04F2, 0x90 }, { 0x04F8, 0x20 }, { 0x04FA, 0x81 }, { 0x04FC, 0x40 }, { 0x0505, 0xF7 }, { 0x0509, 0xFE }, { 0x0511, 0xCD }, { 0x0517, 0xF3 }, { 0x0525, 0xF7 }, { 0x052B, 0xF7 }, { 0x052D, 0x7F }, { 0x052F, 0xBF }, { 0x0531, 0xEF }, { 0x0533, 0xBF }, { 0x0545, 0xFB }, { 0x055D, 0xF7 }, { 0x0583, 0xFE }, { 0x0593, 0xFE }, { 0x05AB, 0xEF }, { 0x05B1, 0xDF }, { 0x05BD, 0x6F }, { 0x05CB, 0xBF }, { 0x05CD, 0xFB }, { 0x05CF, 0xFB }, { 0x05D3, 0xFB }, { 0x05FB, 0xD5 }, { 0x05FD, 0xF7 }, { 0x0600, 0x82 }, { 0x0606, 0x04 }, { 0x0618, 0x28 }, { 0x0630, 0x40 }, { 0x0638, 0x08 }, { 0x0640, 0x20 }, { 0x0654, 0x40 }, { 0x0658, 0x22 }, { 0x065C, 0x84 }, { 0x0664, 0x06 }, { 0x066E, 0x10 }, { 0x0672, 0x01 }, { 0x0678, 0x04 }, { 0x0680, 0x10 }, { 0x0686, 0x80 }, { 0x068A, 0x42 }, { 0x0690, 0x12 }, { 0x06A8, 0x11 }, { 0x06B0, 0x40 }, { 0x06CE, 0x08 }, { 0x06D8, 0x10 }, { 0x06DC, 0x81 }, { 0x06E2, 0x06 }, { 0x06F0, 0x04 }, { 0x0713, 0xF9 }, { 0x0715, 0xBF }, { 0x071B, 0xDF }, { 0x071D, 0xFD }, { 0x0725, 0xFD }, { 0x0745, 0xEF }, { 0x0749, 0xFA }, { 0x0753, 0xBF }, { 0x075B, 0xBF }, { 0x075F, 0xFD }, { 0x0763, 0xDF }, { 0x0771, 0xDF }, { 0x078F, 0xF7 }, { 0x0799, 0xFD }, { 0x07A5, 0xEF }, { 0x07D3, 0x7F }, { 0x07DD, 0xBF }, { 0x07E3, 0xFD }, { 0x07E5, 0xF6 }, { 0x07EB, 0xFD }, { 0x07FB, 0xBF }, { 0x0803, 0xBF }, { 0x080F, 0xED }, { 0x0811, 0xBF }, { 0x0813, 0xF7 }, { 0x081B, 0x7F }, { 0x0827, 0xFA }, { 0x0829, 0x7F }, { 0x082F, 0xEF }, { 0x0833, 0xEF }, { 0x083F, 0xEF }, { 0x0841, 0xDF }, { 0x0843, 0xFE }, { 0x084D, 0xFB }, { 0x0877, 0xBF }, { 0x087F, 0xFB }, { 0x088D, 0xFE }, { 0x088F, 0x7F }, { 0x089F, 0xEF }, { 0x08A5, 0xBF }, { 0x08A9, 0xEF }, { 0x08AB, 0xFD }, { 0x08B1, 0xEF }, { 0x08B5, 0xEF }, { 0x08BF, 0xDF }, { 0x08C7, 0xDF }, { 0x08CF, 0xFB }, { 0x08DD, 0xFE }, { 0x08DF, 0xF7 }, { 0x08E3, 0x5A }, { 0x08E7, 0xBF }, { 0x08EB, 0xFB }, { 0x08ED, 0xF9 }, { 0x08EF, 0xFB }, { 0x08F7, 0x9F }, { 0x08FF, 0xDF }, { 0x0914, 0x94 }, { 0x0916, 0x11 }, { 0x0918, 0x21 }, { 0x091C, 0x01 }, { 0x0922, 0x40 }, { 0x0926, 0x08 }, { 0x092C, 0x04 }, { 0x0934, 0x10 }, { 0x0938, 0x02 }, { 0x093A, 0x08 }, { 0x096A, 0x02 }, { 0x0986, 0x10 }, { 0x0988, 0x20 }, { 0x09A2, 0x03 }, { 0x09AA, 0x02 }, { 0x09B2, 0x08 }, { 0x09B8, 0x08 }, { 0x09BE, 0x10 }, { 0x09C2, 0x02 }, { 0x09CA, 0x40 }, { 0x09D4, 0x40 }, { 0x09E2, 0x01 }, { 0x09E8, 0x10 }, { 0x09EC, 0x40 }, { 0x0A01, 0xEF }, { 0x0A07, 0x6F }, { 0x0A17, 0xD7 }, { 0x0A27, 0xFE }, { 0x0A2D, 0xFB }, { 0x0A2F, 0xBF }, { 0x0A33, 0xEF }, { 0x0A37, 0xFE }, { 0x0A5F, 0xFA }, { 0x0A67, 0xFB }, { 0x0A8D, 0xDF }, { 0x0A8F, 0xFD }, { 0x0A91, 0xEF }, { 0x0A97, 0xFD }, { 0x0A9F, 0xFC }, { 0x0AA7, 0xEF }, { 0x0AAD, 0xEF }, { 0x0AB1, 0xBF }, { 0x0ABF, 0x7F }, { 0x0AD9, 0xDF }, { 0x0AF7, 0xFE }, { 0x0AFF, 0xBE }, { 0x0B14, 0x10 }, { 0x0B24, 0x08 }, { 0x0B2C, 0x02 }, { 0x0B44, 0x08 }, { 0x0B46, 0x01 }, { 0x0B4E, 0x80 }, { 0x0B52, 0x10 }, { 0x0B54, 0x80 }, { 0x0B6A, 0x04 }, { 0x0B72, 0x08 }, { 0x0B88, 0x20 }, { 0x0BB6, 0x20 }, { 0x0BC2, 0x04 }, { 0x0BCE, 0x10 }, { 0x0BD8, 0x08 }, { 0x0BEC, 0x40 }, { 0x0C0F, 0xFE }, { 0x0C11, 0xBF }, { 0x0C17, 0xB7 }, { 0x0C19, 0x7F }, { 0x0C23, 0xFB }, { 0x0C27, 0xFE }, { 0x0C2D, 0xDF }, { 0x0C2F, 0xBB }, { 0x0C37, 0xEF }, { 0x0C3F, 0xBD }, { 0x0C49, 0xFD }, { 0x0C4F, 0xF7 }, { 0x0C5F, 0xBF }, { 0x0C61, 0xDF }, { 0x0C67, 0x37 }, { 0x0C6B, 0xDF }, { 0x0C73, 0xF7 }, { 0x0C7D, 0x7F }, { 0x0C87, 0xDC }, { 0x0C89, 0xDF }, { 0x0C8B, 0xFD }, { 0x0C91, 0xEF }, { 0x0CA3, 0xFB }, { 0x0CA5, 0xFB }, { 0x0CB7, 0xF6 }, { 0x0CBF, 0x3F }, { 0x0CC5, 0xFB }, { 0x0CC7, 0x7F }, { 0x0CD1, 0x7F }, { 0x0CD5, 0x7F }, { 0x0CD7, 0xEF }, { 0x0CD9, 0x7F }, { 0x0CE5, 0xBF }, { 0x0CF5, 0x7F }, { 0x0CFB, 0x7F }, { 0x0CFF, 0xFE }, { 0x0D02, 0x01 }, { 0x0D0A, 0x11 }, { 0x0D0C, 0x80 }, { 0x0D0E, 0x08 }, { 0x0D12, 0x40 }, { 0x0D16, 0x0B }, { 0x0D1E, 0x08 }, { 0x0D22, 0x01 }, { 0x0D26, 0x04 }, { 0x0D28, 0x04 }, { 0x0D2A, 0x01 }, { 0x0D2E, 0x02 }, { 0x0D32, 0x10 }, { 0x0D44, 0x11 }, { 0x0D4E, 0x04 }, { 0x0D52, 0x80 }, { 0x0D5A, 0x40 }, { 0x0D5E, 0x04 }, { 0x0D72, 0x01 }, { 0x0D76, 0x02 }, { 0x0D7A, 0x04 }, { 0x0D7C, 0x80 }, { 0x0D82, 0x80 }, { 0x0D84, 0x04 }, { 0x0D90, 0x04 }, { 0x0DA0, 0x01 }, { 0x0DA4, 0x02 }, { 0x0DB0, 0x04 }, { 0x0DB4, 0x04 }, { 0x0DB6, 0x10 }, { 0x0DBC, 0x08 }, { 0x0DC2, 0x08 }, { 0x0DD0, 0x28 }, { 0x0DD2, 0x10 }, { 0x0DD6, 0x10 }, { 0x0DE2, 0x08 }, { 0x0E17, 0xFE }, { 0x0E19, 0xDF }, { 0x0E2B, 0xEF }, { 0x0E2F, 0xFD }, { 0x0E37, 0xF3 }, { 0x0E39, 0xDF }, { 0x0E3F, 0xDF }, { 0x0E4F, 0xFE }, { 0x0E53, 0xFB }, { 0x0E5B, 0xEF }, { 0x0E5D, 0xF7 }, { 0x0E5F, 0xFD }, { 0x0E71, 0xFB }, { 0x0E77, 0xFD }, { 0x0E7B, 0xFB }, { 0x0E7F, 0xFD }, { 0x0E85, 0x7F }, { 0x0E8B, 0xFD }, { 0x0E9B, 0x7B }, { 0x0EA7, 0xFE }, { 0x0EBB, 0xFB }, { 0x0ED7, 0x77 }, { 0x0EE1, 0xDF }, { 0x0EE3, 0xF7 }, { 0x0EEF, 0xFE }, { 0x0EFB, 0xFE }, { 0x0EFF, 0xF7 }, { 0x0F02, 0x10 }, { 0x0F06, 0x20 }, { 0x0F0A, 0x02 }, { 0x0F1C, 0x10 }, { 0x0F32, 0x08 }, { 0x0F54, 0x10 }, { 0x0F84, 0x10 }, { 0x0F92, 0x40 }, { 0x0FA6, 0x08 }, { 0x0FAA, 0x02 }, { 0x0FB6, 0x40 }, { 0x0FCE, 0x0A }, { 0x0FD2, 0x10 }, { 0x0FD4, 0x10 }, { 0x0FE0, 0x04 }, { 0x0FF0, 0x04 }, { 0x1000, 0x80 }, { 0x1004, 0x08 }, { 0x1008, 0x09 }, { 0x1010, 0x02 }, { 0x1012, 0x20 }, { 0x1020, 0x05 }, { 0x1024, 0x01 }, { 0x1026, 0x10 }, { 0x102A, 0x02 }, { 0x1032, 0x40 }, { 0x1034, 0x08 }, { 0x1036, 0x03 }, { 0x1038, 0x01 }, { 0x103E, 0x40 }, { 0x1040, 0x40 }, { 0x1042, 0x12 }, { 0x1046, 0x02 }, { 0x1050, 0x22 }, { 0x1056, 0x80 }, { 0x1058, 0x10 }, { 0x105E, 0x40 }, { 0x1066, 0x04 }, { 0x1068, 0x02 }, { 0x106C, 0x60 }, { 0x1070, 0x80 }, { 0x1076, 0x40 }, { 0x1078, 0x66 }, { 0x107C, 0x02 }, { 0x1080, 0x40 }, { 0x1088, 0x01 }, { 0x108A, 0x80 }, { 0x108E, 0x10 }, { 0x1090, 0x31 }, { 0x1092, 0x20 }, { 0x1098, 0x11 }, { 0x109A, 0x80 }, { 0x10A0, 0x05 }, { 0x10A4, 0x01 }, { 0x10A6, 0x81 }, { 0x10A8, 0x01 }, { 0x10AA, 0x01 }, { 0x10B0, 0x40 }, { 0x10B4, 0x40 }, { 0x10B6, 0x20 }, { 0x10B8, 0x03 }, { 0x10BC, 0x88 }, { 0x10BE, 0x02 }, { 0x10C0, 0x30 }, { 0x10C4, 0x42 }, { 0x10C6, 0x10 }, { 0x10C8, 0x01 }, { 0x10D4, 0x40 }, { 0x10D8, 0x80 }, { 0x10DE, 0x10 }, { 0x10E0, 0x10 }, { 0x10E2, 0x10 }, { 0x10E4, 0x01 }, { 0x10E8, 0x26 }, { 0x10EE, 0x10 }, { 0x10F0, 0x80 }, { 0x10F6, 0x40 }, { 0x10F8, 0x01 }, { 0x10FA, 0x20 }, { 0x10FC, 0x04 }, { 0x10FE, 0x80 }, { 0x1101, 0xFD }, { 0x1113, 0x7F }, { 0x1115, 0xEF }, { 0x1117, 0xFB }, { 0x1121, 0x7F }, { 0x1139, 0xF7 }, { 0x1141, 0xFD }, { 0x1153, 0xFD }, { 0x1159, 0xF5 }, { 0x115F, 0x7F }, { 0x116D, 0xF7 }, { 0x1171, 0x7E }, { 0x1179, 0xDF }, { 0x117B, 0xFB }, { 0x117F, 0xDF }, { 0x1189, 0x7F }, { 0x1195, 0xDF }, { 0x119D, 0xDF }, { 0x119F, 0xD7 }, { 0x11A7, 0xF9 }, { 0x11AB, 0xAF }, { 0x11AD, 0xBF }, { 0x11B9, 0xDF }, { 0x11BB, 0xBF }, { 0x11C5, 0xF9 }, { 0x11CF, 0x7F }, { 0x11D5, 0x7F }, { 0x11DF, 0xEF }, { 0x11E1, 0xFE }, { 0x11E7, 0xDF }, { 0x11E9, 0xF7 }, { 0x11ED, 0xFB }, { 0x1208, 0x01 }, { 0x1218, 0x16 }, { 0x1230, 0x04 }, { 0x1242, 0x0C }, { 0x1246, 0x80 }, { 0x1260, 0x01 }, { 0x1276, 0x10 }, { 0x1278, 0x10 }, { 0x1280, 0x04 }, { 0x1284, 0x44 }, { 0x1286, 0x01 }, { 0x128A, 0x02 }, { 0x1290, 0x80 }, { 0x12A0, 0x02 }, { 0x12A8, 0x50 }, { 0x12B0, 0x08 }, { 0x12B2, 0x40 }, { 0x12B4, 0x10 }, { 0x12B6, 0x02 }, { 0x12B8, 0x04 }, { 0x12C0, 0x04 }, { 0x12CC, 0x20 }, { 0x12D0, 0x42 }, { 0x12D8, 0x10 }, { 0x12DA, 0x10 }, { 0x12E4, 0x08 }, { 0x12F0, 0x40 }, { 0x12F2, 0x40 }, { 0x12F8, 0x42 }, { 0x12FC, 0x80 }, { 0x12FE, 0x40 }, { 0x1301, 0xFD }, { 0x1307, 0x7F }, { 0x1309, 0x3F }, { 0x1325, 0xDF }, { 0x132F, 0xFB }, { 0x134D, 0x7F }, { 0x1351, 0xDB }, { 0x1353, 0xE7 }, { 0x1357, 0xEF }, { 0x1363, 0xF7 }, { 0x136D, 0xF7 }, { 0x136F, 0xF7 }, { 0x1389, 0x7F }, { 0x138B, 0xFE }, { 0x138D, 0x7F }, { 0x139B, 0xEB }, { 0x13A1, 0xEF }, { 0x13BB, 0xEF }, { 0x13C7, 0x7F }, { 0x13D5, 0xF7 }, { 0x13EB, 0xFD }, { 0x13F5, 0xDF }, { 0x13F7, 0xFE }, { 0x1400, 0x11 }, { 0x1408, 0x90 }, { 0x140E, 0x20 }, { 0x1414, 0x10 }, { 0x1416, 0x01 }, { 0x1418, 0x10 }, { 0x1420, 0x20 }, { 0x1428, 0x0C }, { 0x142C, 0x11 }, { 0x1430, 0x01 }, { 0x1434, 0x20 }, { 0x1438, 0x10 }, { 0x143A, 0x02 }, { 0x143E, 0x10 }, { 0x1440, 0xA1 }, { 0x144A, 0x20 }, { 0x144C, 0x80 }, { 0x1450, 0x12 }, { 0x1452, 0x80 }, { 0x1458, 0x80 }, { 0x145A, 0x41 }, { 0x145C, 0x02 }, { 0x1460, 0x12 }, { 0x1466, 0x82 }, { 0x1468, 0x18 }, { 0x1470, 0x08 }, { 0x1472, 0x24 }, { 0x147C, 0x20 }, { 0x147E, 0x81 }, { 0x1484, 0x10 }, { 0x1488, 0x04 }, { 0x1490, 0x04 }, { 0x1492, 0x08 }, { 0x1498, 0x60 }, { 0x149C, 0x02 }, { 0x14A0, 0x80 }, { 0x14A2, 0x51 }, { 0x14A8, 0x04 }, { 0x14AC, 0x02 }, { 0x14B0, 0x01 }, { 0x14B8, 0x10 }, { 0x14BA, 0x80 }, { 0x14BE, 0x14 }, { 0x14C0, 0x02 }, { 0x14C4, 0x80 }, { 0x14C8, 0x8C }, { 0x14CA, 0x0C }, { 0x14D2, 0x80 }, { 0x14D8, 0x08 }, { 0x14DC, 0x80 }, { 0x14E8, 0x90 }, { 0x14EA, 0x09 }, { 0x14F0, 0x04 }, { 0x14F4, 0x04 }, { 0x14F8, 0x44 }, { 0x14FA, 0x02 }, { 0x14FC, 0x40 }, { 0x14FE, 0x08 }, { 0x1505, 0xFE }, { 0x150D, 0xF7 }, { 0x1513, 0xDF }, { 0x151B, 0xEF }, { 0x151F, 0xDF }, { 0x1527, 0x7F }, { 0x152B, 0xBB }, { 0x152D, 0xFE }, { 0x152F, 0xFD }, { 0x1531, 0xDF }, { 0x1539, 0xBF }, { 0x153B, 0xFE }, { 0x1541, 0xDF }, { 0x1547, 0xBF }, { 0x154B, 0x7F }, { 0x156B, 0x7F }, { 0x157D, 0xBF }, { 0x1585, 0xFE }, { 0x1587, 0xEF }, { 0x1591, 0xDF }, { 0x1593, 0xEF }, { 0x1597, 0xFB }, { 0x1599, 0xF7 }, { 0x159B, 0xBF }, { 0x15A3, 0xD5 }, { 0x15A5, 0xBF }, { 0x15B3, 0xEB }, { 0x15B5, 0xFE }, { 0x15C3, 0xF7 }, { 0x15C5, 0xEF }, { 0x15C9, 0xFD }, { 0x15D1, 0xFE }, { 0x15D7, 0xFE }, { 0x15D9, 0xEF }, { 0x15DD, 0xFB }, { 0x15E1, 0x7B }, { 0x15E3, 0xBF }, { 0x15E9, 0xFD }, { 0x15F5, 0x7F }, { 0x15FB, 0xEF }, { 0x1600, 0x20 }, { 0x160A, 0x10 }, { 0x161E, 0x04 }, { 0x1620, 0x02 }, { 0x1630, 0x04 }, { 0x1636, 0x40 }, { 0x1640, 0x2C }, { 0x1646, 0x20 }, { 0x1654, 0x20 }, { 0x1656, 0x18 }, { 0x1658, 0x4A }, { 0x165A, 0x20 }, { 0x165C, 0x80 }, { 0x1664, 0x08 }, { 0x1668, 0x02 }, { 0x1670, 0x48 }, { 0x167A, 0x20 }, { 0x1680, 0x10 }, { 0x1682, 0x08 }, { 0x1684, 0x40 }, { 0x168C, 0x01 }, { 0x1698, 0x21 }, { 0x169E, 0x40 }, { 0x16A0, 0x03 }, { 0x16A2, 0x40 }, { 0x16A4, 0x01 }, { 0x16A6, 0x01 }, { 0x16B6, 0x10 }, { 0x16B8, 0x80 }, { 0x16BA, 0x02 }, { 0x16BC, 0x01 }, { 0x16D0, 0x04 }, { 0x16D2, 0x02 }, { 0x16D8, 0x81 }, { 0x16E8, 0x03 }, { 0x16EE, 0x80 }, { 0x16F8, 0xA4 }, { 0x1703, 0xFE }, { 0x172B, 0xEF }, { 0x172D, 0xBF }, { 0x173B, 0xDF }, { 0x1745, 0x3D }, { 0x1749, 0xFB }, { 0x174B, 0xDF }, { 0x1753, 0xDF }, { 0x1759, 0xFD }, { 0x1763, 0xEF }, { 0x1765, 0xBF }, { 0x1775, 0xBF }, { 0x177D, 0xDF }, { 0x1781, 0xFE }, { 0x1789, 0xEF }, { 0x178B, 0xFE }, { 0x1791, 0xEF }, { 0x1793, 0xDF }, { 0x1795, 0xEF }, { 0x179B, 0xFE }, { 0x17A7, 0xFB }, { 0x17AD, 0xFE }, { 0x17B3, 0xFB }, { 0x17B5, 0xFA }, { 0x17B9, 0xFB }, { 0x17C3, 0xFB }, { 0x17DB, 0xFB }, { 0x17EB, 0xBF }, { 0x17F3, 0xFB }, { 0x1803, 0xBD }, { 0x1813, 0xBF }, { 0x181B, 0x7E }, { 0x1827, 0xFD }, { 0x1833, 0xFE }, { 0x1837, 0xDB }, { 0x1839, 0xF7 }, { 0x1845, 0xDF }, { 0x184B, 0xFD }, { 0x1853, 0xDF }, { 0x1867, 0xFD }, { 0x186F, 0xF7 }, { 0x1879, 0xDF }, { 0x187D, 0xEF }, { 0x1889, 0xFB }, { 0x188F, 0x9F }, { 0x1893, 0xDF }, { 0x1897, 0xFD }, { 0x189B, 0x7F }, { 0x18A9, 0xFD }, { 0x18AF, 0xFB }, { 0x18B5, 0xBF }, { 0x18B7, 0x2F }, { 0x18BD, 0xFE }, { 0x18BF, 0xFB }, { 0x18CD, 0xBF }, { 0x18D3, 0xF5 }, { 0x18D5, 0x7F }, { 0x18D7, 0xFD }, { 0x18E1, 0xFD }, { 0x18E3, 0xEF }, { 0x18E5, 0x7F }, { 0x18EB, 0xFE }, { 0x18EF, 0xDF }, { 0x18F3, 0xEF }, { 0x18F7, 0xEF }, { 0x18FB, 0x7B }, { 0x18FD, 0xDF }, { 0x18FF, 0xDF }, { 0x190A, 0x40 }, { 0x1910, 0x20 }, { 0x1916, 0x04 }, { 0x1920, 0x01 }, { 0x1924, 0x02 }, { 0x1926, 0x02 }, { 0x1936, 0x40 }, { 0x1946, 0x04 }, { 0x195A, 0x10 }, { 0x195C, 0x40 }, { 0x1968, 0x20 }, { 0x197C, 0x08 }, { 0x1988, 0x08 }, { 0x1994, 0x20 }, { 0x1996, 0x20 }, { 0x199A, 0x12 }, { 0x19BA, 0x08 }, { 0x19C4, 0x01 }, { 0x19CC, 0x04 }, { 0x19D4, 0x04 }, { 0x19DA, 0x80 }, { 0x19DC, 0x40 }, { 0x19E2, 0x02 }, { 0x19EE, 0x80 }, { 0x19F4, 0x02 }, { 0x19F6, 0x90 }, { 0x19FC, 0x02 }, { 0x19FE, 0x1A }, { 0x1A11, 0xDF }, { 0x1A1F, 0xEE }, { 0x1A25, 0xFB }, { 0x1A27, 0xF7 }, { 0x1A2D, 0xF5 }, { 0x1A2F, 0xFA }, { 0x1A3B, 0xEF }, { 0x1A3F, 0xFB }, { 0x1A4B, 0xDF }, { 0x1A6F, 0xFB }, { 0x1A77, 0xF7 }, { 0x1A81, 0xE7 }, { 0x1A8F, 0xE7 }, { 0x1A93, 0xDF }, { 0x1A9F, 0xDF }, { 0x1AAD, 0xEF }, { 0x1AC7, 0xF7 }, { 0x1AD5, 0xFE }, { 0x1ADF, 0xFB }, { 0x1AE3, 0xBF }, { 0x1AED, 0xF7 }, { 0x1AF1, 0xFE }, { 0x1AF9, 0xFD }, { 0x1B1A, 0x02 }, { 0x1B26, 0x10 }, { 0x1B6C, 0x02 }, { 0x1B84, 0x04 }, { 0x1B88, 0x40 }, { 0x1BA0, 0x08 }, { 0x1BAE, 0x08 }, { 0x1BBC, 0x02 }, { 0x1BF4, 0x04 }, { 0x1C07, 0xDF }, { 0x1C0B, 0x7F }, { 0x1C0F, 0xDF }, { 0x1C13, 0xBF }, { 0x1C1B, 0xFB }, { 0x1C1F, 0xEF }, { 0x1C27, 0xBD }, { 0x1C2F, 0x77 }, { 0x1C3D, 0xEF }, { 0x1C3F, 0xF7 }, { 0x1C41, 0xF7 }, { 0x1C43, 0xFE }, { 0x1C45, 0xDF }, { 0x1C47, 0xFE }, { 0x1C4F, 0xEF }, { 0x1C53, 0xF3 }, { 0x1C5D, 0xDF }, { 0x1C5F, 0xBB }, { 0x1C61, 0xFB }, { 0x1C67, 0xFE }, { 0x1C69, 0xFD }, { 0x1C6B, 0xFE }, { 0x1C73, 0xFB }, { 0x1C7B, 0xFE }, { 0x1C7D, 0xEF }, { 0x1C83, 0xEF }, { 0x1C87, 0x3F }, { 0x1C8B, 0xEF }, { 0x1C8F, 0xD9 }, { 0x1C97, 0xEF }, { 0x1C9B, 0xEF }, { 0x1C9F, 0xF7 }, { 0x1CA3, 0xFD }, { 0x1CA7, 0xBF }, { 0x1CA9, 0xF7 }, { 0x1CAB, 0xFB }, { 0x1CAD, 0xFD }, { 0x1CB1, 0x7F }, { 0x1CB3, 0xBB }, { 0x1CB9, 0xFD }, { 0x1CBB, 0xFB }, { 0x1CC7, 0xF6 }, { 0x1CCF, 0xBF }, { 0x1CD3, 0xEB }, { 0x1CE1, 0xBF }, { 0x1CF1, 0xFD }, { 0x1CF5, 0x7F }, { 0x1CF7, 0xEF }, { 0x1CFD, 0xDF }, { 0x1CFF, 0xFD }, { 0x1D02, 0x04 }, { 0x1D06, 0x40 }, { 0x1D08, 0x92 }, { 0x1D10, 0x04 }, { 0x1D1A, 0x02 }, { 0x1D1C, 0x08 }, { 0x1D24, 0x08 }, { 0x1D30, 0x01 }, { 0x1D34, 0x04 }, { 0x1D3A, 0x22 }, { 0x1D3E, 0x04 }, { 0x1D56, 0x10 }, { 0x1D5A, 0x02 }, { 0x1D7E, 0x40 }, { 0x1D8E, 0x01 }, { 0x1D90, 0x20 }, { 0x1D9A, 0x10 }, { 0x1DA0, 0x04 }, { 0x1DA4, 0x02 }, { 0x1DAC, 0x21 }, { 0x1DBE, 0x20 }, { 0x1DC2, 0x20 }, { 0x1DD6, 0x40 }, { 0x1DD8, 0x08 }, { 0x1DF2, 0x01 }, { 0x1DFE, 0x80 }, { 0x1E01, 0xEF }, { 0x1E05, 0xEF }, { 0x1E1D, 0xDF }, { 0x1E27, 0xDD }, { 0x1E2F, 0x7F }, { 0x1E33, 0xF5 }, { 0x1E37, 0xFB }, { 0x1E3F, 0xF7 }, { 0x1E4B, 0xDF }, { 0x1E5F, 0x7F }, { 0x1E71, 0xEB }, { 0x1E7F, 0xBF }, { 0x1E8F, 0xDF }, { 0x1E97, 0xBF }, { 0x1E9B, 0xEF }, { 0x1E9F, 0xF7 }, { 0x1EA7, 0xFD }, { 0x1EB3, 0xFB }, { 0x1EB7, 0x7F }, { 0x1EC5, 0x7F }, { 0x1EDF, 0x7F }, { 0x1EE9, 0xF7 }, { 0x1EF3, 0xFD }, { 0x1F02, 0x10 }, { 0x1F04, 0x05 }, { 0x1F20, 0x04 }, { 0x1F24, 0x10 }, { 0x1F3A, 0x80 }, { 0x1F44, 0x04 }, { 0x1F46, 0x04 }, { 0x1F4E, 0x40 }, { 0x1F50, 0x01 }, { 0x1F54, 0x03 }, { 0x1F60, 0x03 }, { 0x1F72, 0x01 }, { 0x1F76, 0x04 }, { 0x1F7A, 0x02 }, { 0x1F86, 0x80 }, { 0x1F8C, 0x02 }, { 0x1FA2, 0x40 }, { 0x1FB6, 0x80 }, { 0x1FC6, 0x10 }, { 0x1FCC, 0x20 }, { 0x1FD2, 0x20 }, { 0x1FD8, 0x04 }, { 0x1FDC, 0x10 }, { 0x1FDE, 0x04 } }; for (unsigned addr = 0x0000; addr < 0x0800; addr += 0x200) { std::memset(wram + addr , 0x00, 0x100); std::memset(wram + addr + 0x100, 0xFF, 0x100); } for (unsigned addr = 0x0800; addr < 0x1000; addr += 0x200) { std::memset(wram + addr , 0xFF, 0x100); std::memset(wram + addr + 0x100, 0x00, 0x100); } std::memcpy(wram + 0x1000, wram, 0x1000); for (std::size_t i = 0; i < sizeof dmgWramDumpDiff / sizeof dmgWramDumpDiff[0]; ++i) wram[dmgWramDumpDiff[i].addr] = dmgWramDumpDiff[i].val; } static void setInitialVram(unsigned char vram[], bool const cgb) { static unsigned char const even_numbered_8010_to_81a0_dump[] = { 0xF0, 0xF0, 0xFC, 0xFC, 0xFC, 0xFC, 0xF3, 0xF3, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0xF3, 0xF3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCF, 0xCF, 0x00, 0x00, 0x0F, 0x0F, 0x3F, 0x3F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF3, 0xF3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFF, 0xFF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0xF3, 0xF3, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x3C, 0x3C, 0xFC, 0xFC, 0xFC, 0xFC, 0x3C, 0x3C, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xCF, 0xCF, 0xCF, 0xCF, 0xCF, 0xCF, 0xCF, 0xCF, 0x3C, 0x3C, 0x3F, 0x3F, 0x3C, 0x3C, 0x0F, 0x0F, 0x3C, 0x3C, 0xFC, 0xFC, 0x00, 0x00, 0xFC, 0xFC, 0xFC, 0xFC, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xF0, 0xF0, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xFF, 0xFF, 0xCF, 0xCF, 0xCF, 0xCF, 0xCF, 0xCF, 0xC3, 0xC3, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFC, 0xFC, 0x3C, 0x42, 0xB9, 0xA5, 0xB9, 0xA5, 0x42, 0x3C }; std::memset(vram, 0, 0x4000); for (std::size_t i = 0; i < sizeof even_numbered_8010_to_81a0_dump; ++i) { vram[0x0010 + i * 2] = even_numbered_8010_to_81a0_dump[i]; } if (!cgb) { unsigned i = 1; for (unsigned addr = 0x1904; addr < 0x1910; ++addr) vram[addr] = i++; vram[0x1910] = 0x19; for (unsigned addr = 0x1924; addr < 0x1930; ++addr) vram[addr] = i++; } } static void setInitialCgbIoamhram(unsigned char ioamhram[]) { static unsigned char const feaxDump[0x60] = { 0x08, 0x01, 0xEF, 0xDE, 0x06, 0x4A, 0xCD, 0xBD, 0x08, 0x01, 0xEF, 0xDE, 0x06, 0x4A, 0xCD, 0xBD, 0x08, 0x01, 0xEF, 0xDE, 0x06, 0x4A, 0xCD, 0xBD, 0x08, 0x01, 0xEF, 0xDE, 0x06, 0x4A, 0xCD, 0xBD, 0x00, 0x90, 0xF7, 0x7F, 0xC0, 0xB1, 0xBC, 0xFB, 0x00, 0x90, 0xF7, 0x7F, 0xC0, 0xB1, 0xBC, 0xFB, 0x00, 0x90, 0xF7, 0x7F, 0xC0, 0xB1, 0xBC, 0xFB, 0x00, 0x90, 0xF7, 0x7F, 0xC0, 0xB1, 0xBC, 0xFB, 0x24, 0x13, 0xFD, 0x3A, 0x10, 0x10, 0xAD, 0x45, 0x24, 0x13, 0xFD, 0x3A, 0x10, 0x10, 0xAD, 0x45, 0x24, 0x13, 0xFD, 0x3A, 0x10, 0x10, 0xAD, 0x45, 0x24, 0x13, 0xFD, 0x3A, 0x10, 0x10, 0xAD, 0x45 }; static unsigned char const ffxxDump[0x100] = { 0xCF, 0x00, 0x7C, 0xFF, 0x44, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0x80, 0xBF, 0xF3, 0xFF, 0xBF, 0xFF, 0x3F, 0x00, 0xFF, 0xBF, 0x7F, 0xFF, 0x9F, 0xFF, 0xBF, 0xFF, 0xFF, 0x00, 0x00, 0xBF, 0x77, 0xF3, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x7E, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0xFF, 0xC1, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x8F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, 0x03, 0x73, 0x00, 0x83, 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E, 0xDC, 0xCC, 0x6E, 0xE6, 0xDD, 0xDD, 0xD9, 0x99, 0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC, 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E, 0x45, 0xEC, 0x42, 0xFA, 0x08, 0xB7, 0x07, 0x5D, 0x01, 0xF5, 0xC0, 0xFF, 0x08, 0xFC, 0x00, 0xE5, 0x0B, 0xF8, 0xC2, 0xCA, 0xF4, 0xF9, 0x0D, 0x7F, 0x44, 0x6D, 0x19, 0xFE, 0x46, 0x97, 0x33, 0x5E, 0x08, 0xFF, 0xD1, 0xFF, 0xC6, 0x8B, 0x24, 0x74, 0x12, 0xFC, 0x00, 0x9F, 0x94, 0xB7, 0x06, 0xD5, 0x40, 0x7A, 0x20, 0x9E, 0x04, 0x5F, 0x41, 0x2F, 0x3D, 0x77, 0x36, 0x75, 0x81, 0x8A, 0x70, 0x3A, 0x98, 0xD1, 0x71, 0x02, 0x4D, 0x01, 0xC1, 0xFF, 0x0D, 0x00, 0xD3, 0x05, 0xF9, 0x00, 0x0B, 0x00 }; std::memset(ioamhram, 0x00, 0x0A0); std::memcpy(ioamhram + 0x0A0, feaxDump, sizeof feaxDump); std::memcpy(ioamhram + 0x100, ffxxDump, sizeof ffxxDump); } static void setInitialDmgIoamhram(unsigned char ioamhram[]) { static unsigned char const oamDump[0xA0] = { 0xBB, 0xD8, 0xC4, 0x04, 0xCD, 0xAC, 0xA1, 0xC7, 0x7D, 0x85, 0x15, 0xF0, 0xAD, 0x19, 0x11, 0x6A, 0xBA, 0xC7, 0x76, 0xF8, 0x5C, 0xA0, 0x67, 0x0A, 0x7B, 0x75, 0x56, 0x3B, 0x65, 0x5C, 0x4D, 0xA3, 0x00, 0x05, 0xD7, 0xC9, 0x1B, 0xCA, 0x11, 0x6D, 0x38, 0xE7, 0x13, 0x2A, 0xB1, 0x10, 0x72, 0x4D, 0xA7, 0x47, 0x13, 0x89, 0x7C, 0x62, 0x5F, 0x90, 0x64, 0x2E, 0xD3, 0xEF, 0xAB, 0x01, 0x15, 0x85, 0xE8, 0x2A, 0x6E, 0x4A, 0x1F, 0xBE, 0x49, 0xB1, 0xE6, 0x0F, 0x93, 0xE2, 0xB6, 0x87, 0x5D, 0x35, 0xD8, 0xD4, 0x4A, 0x45, 0xCA, 0xB3, 0x33, 0x74, 0x18, 0xC1, 0x16, 0xFB, 0x8F, 0xA4, 0x8E, 0x70, 0xCD, 0xB4, 0x4A, 0xDC, 0xE6, 0x34, 0x32, 0x41, 0xF9, 0x84, 0x6A, 0x99, 0xEC, 0x92, 0xF1, 0x8B, 0x5D, 0xA5, 0x09, 0xCF, 0x3A, 0x93, 0xBC, 0xE0, 0x15, 0x19, 0xE4, 0xB6, 0x9A, 0x04, 0x3B, 0xC1, 0x96, 0xB7, 0x56, 0x85, 0x6A, 0xAA, 0x1E, 0x2A, 0x80, 0xEE, 0xE7, 0x46, 0x76, 0x8B, 0x0D, 0xBA, 0x24, 0x40, 0x42, 0x05, 0x0E, 0x04, 0x20, 0xA6, 0x5E, 0xC1, 0x97, 0x7E, 0x44, 0x05, 0x01, 0xA9 }; static unsigned char const ffxxDump[0x100] = { 0xCF, 0x00, 0x7E, 0xFF, 0xD3, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0x80, 0xBF, 0xF3, 0xFF, 0xBF, 0xFF, 0x3F, 0x00, 0xFF, 0xBF, 0x7F, 0xFF, 0x9F, 0xFF, 0xBF, 0xFF, 0xFF, 0x00, 0x00, 0xBF, 0x77, 0xF3, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x71, 0x72, 0xD5, 0x91, 0x58, 0xBB, 0x2A, 0xFA, 0xCF, 0x3C, 0x54, 0x75, 0x48, 0xCF, 0x8F, 0xD9, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x2B, 0x0B, 0x64, 0x2F, 0xAF, 0x15, 0x60, 0x6D, 0x61, 0x4E, 0xAC, 0x45, 0x0F, 0xDA, 0x92, 0xF3, 0x83, 0x38, 0xE4, 0x4E, 0xA7, 0x6C, 0x38, 0x58, 0xBE, 0xEA, 0xE5, 0x81, 0xB4, 0xCB, 0xBF, 0x7B, 0x59, 0xAD, 0x50, 0x13, 0x5E, 0xF6, 0xB3, 0xC1, 0xDC, 0xDF, 0x9E, 0x68, 0xD7, 0x59, 0x26, 0xF3, 0x62, 0x54, 0xF8, 0x36, 0xB7, 0x78, 0x6A, 0x22, 0xA7, 0xDD, 0x88, 0x15, 0xCA, 0x96, 0x39, 0xD3, 0xE6, 0x55, 0x6E, 0xEA, 0x90, 0x76, 0xB8, 0xFF, 0x50, 0xCD, 0xB5, 0x1B, 0x1F, 0xA5, 0x4D, 0x2E, 0xB4, 0x09, 0x47, 0x8A, 0xC4, 0x5A, 0x8C, 0x4E, 0xE7, 0x29, 0x50, 0x88, 0xA8, 0x66, 0x85, 0x4B, 0xAA, 0x38, 0xE7, 0x6B, 0x45, 0x3E, 0x30, 0x37, 0xBA, 0xC5, 0x31, 0xF2, 0x71, 0xB4, 0xCF, 0x29, 0xBC, 0x7F, 0x7E, 0xD0, 0xC7, 0xC3, 0xBD, 0xCF, 0x59, 0xEA, 0x39, 0x01, 0x2E, 0x00, 0x69, 0x00 }; std::memcpy(ioamhram , oamDump, sizeof oamDump); std::memset(ioamhram + 0x0A0, 0x00, 0x060); std::memcpy(ioamhram + 0x100, ffxxDump, sizeof ffxxDump); } } // anon namespace void gambatte::setInitState(SaveState &state, bool const cgb, bool const gbaCgbMode) { static unsigned char const cgbObjpDump[0x40] = { 0x00, 0x00, 0xF2, 0xAB, 0x61, 0xC2, 0xD9, 0xBA, 0x88, 0x6E, 0xDD, 0x63, 0x28, 0x27, 0xFB, 0x9F, 0x35, 0x42, 0xD6, 0xD4, 0x50, 0x48, 0x57, 0x5E, 0x23, 0x3E, 0x3D, 0xCA, 0x71, 0x21, 0x37, 0xC0, 0xC6, 0xB3, 0xFB, 0xF9, 0x08, 0x00, 0x8D, 0x29, 0xA3, 0x20, 0xDB, 0x87, 0x62, 0x05, 0x5D, 0xD4, 0x0E, 0x08, 0xFE, 0xAF, 0x20, 0x02, 0xD7, 0xFF, 0x07, 0x6A, 0x55, 0xEC, 0x83, 0x40, 0x0B, 0x77 }; state.cpu.cycleCounter = cgb ? 0x102A0 : 0x102A0 + 0x8D2C; state.cpu.pc = 0x100; state.cpu.sp = 0xFFFE; state.cpu.a = cgb * 0x10 | 0x01; state.cpu.b = cgb & gbaCgbMode; state.cpu.c = 0x13; state.cpu.d = 0x00; state.cpu.e = 0xD8; state.cpu.f = 0xB0; state.cpu.h = 0x01; state.cpu.l = 0x4D; state.cpu.skip = false; std::memset(state.mem.sram.ptr, 0xFF, state.mem.sram.size()); setInitialVram(state.mem.vram.ptr, cgb); if (cgb) { setInitialCgbWram(state.mem.wram.ptr); setInitialCgbIoamhram(state.mem.ioamhram.ptr); } else { setInitialDmgWram(state.mem.wram.ptr); setInitialDmgIoamhram(state.mem.ioamhram.ptr); } state.mem.ioamhram.ptr[0x104] = 0x1C; state.mem.ioamhram.ptr[0x140] = 0x91; state.mem.ioamhram.ptr[0x144] = 0x00; state.mem.divLastUpdate = 0; state.mem.timaLastUpdate = 0; state.mem.tmatime = disabled_time; state.mem.nextSerialtime = disabled_time; state.mem.lastOamDmaUpdate = disabled_time; state.mem.unhaltTime = disabled_time; state.mem.minIntTime = 0; state.mem.rombank = 1; state.mem.dmaSource = 0; state.mem.dmaDestination = 0; state.mem.rambank = 0; state.mem.oamDmaPos = 0xFE; state.mem.IME = false; state.mem.halted = false; state.mem.enableRam = false; state.mem.rambankMode = false; state.mem.hdmaTransfer = false; for (int i = 0x00; i < 0x40; i += 0x02) { state.ppu.bgpData.ptr[i ] = 0xFF; state.ppu.bgpData.ptr[i + 1] = 0x7F; } std::memcpy(state.ppu.objpData.ptr, cgbObjpDump, sizeof cgbObjpDump); if (!cgb) { state.ppu.bgpData.ptr[0] = state.mem.ioamhram.get()[0x147]; state.ppu.objpData.ptr[0] = state.mem.ioamhram.get()[0x148]; state.ppu.objpData.ptr[1] = state.mem.ioamhram.get()[0x149]; } for (int pos = 0; pos < 80; ++pos) state.ppu.oamReaderBuf.ptr[pos] = state.mem.ioamhram.ptr[(pos * 2 & ~3) | (pos & 1)]; std::fill_n(state.ppu.oamReaderSzbuf.ptr, 40, false); std::memset(state.ppu.spAttribList, 0, sizeof state.ppu.spAttribList); std::memset(state.ppu.spByte0List, 0, sizeof state.ppu.spByte0List); std::memset(state.ppu.spByte1List, 0, sizeof state.ppu.spByte1List); state.ppu.videoCycles = cgb ? 144*456ul + 164 : 153*456ul + 396; state.ppu.enableDisplayM0Time = state.cpu.cycleCounter; state.ppu.winYPos = 0xFF; state.ppu.xpos = 0; state.ppu.endx = 0; state.ppu.reg0 = 0; state.ppu.reg1 = 0; state.ppu.tileword = 0; state.ppu.ntileword = 0; state.ppu.attrib = 0; state.ppu.nattrib = 0; state.ppu.state = 0; state.ppu.nextSprite = 0; state.ppu.currentSprite = 0; state.ppu.lyc = state.mem.ioamhram.get()[0x145]; state.ppu.m0lyc = state.mem.ioamhram.get()[0x145]; state.ppu.weMaster = false; state.ppu.winDrawState = 0; state.ppu.wscx = 0; state.ppu.lastM0Time = 1234; state.ppu.nextM0Irq = 0; state.ppu.oldWy = state.mem.ioamhram.get()[0x14A]; state.ppu.pendingLcdstatIrq = false; // spu.cycleCounter >> 12 & 7 represents the frame sequencer position. state.spu.cycleCounter = (cgb ? 0x1E00 : 0x2400) | (state.cpu.cycleCounter >> 1 & 0x1FF); state.spu.ch1.sweep.counter = SoundUnit::counter_disabled; state.spu.ch1.sweep.shadow = 0; state.spu.ch1.sweep.nr0 = 0; state.spu.ch1.sweep.negging = false; if (cgb) { state.spu.ch1.duty.nextPosUpdate = (state.spu.cycleCounter & ~1ul) + 37 * 2; state.spu.ch1.duty.pos = 6; state.spu.ch1.duty.high = true; } else { state.spu.ch1.duty.nextPosUpdate = (state.spu.cycleCounter & ~1ul) + 69 * 2; state.spu.ch1.duty.pos = 3; state.spu.ch1.duty.high = false; } state.spu.ch1.duty.nr3 = 0xC1; state.spu.ch1.env.counter = SoundUnit::counter_disabled; state.spu.ch1.env.volume = 0; state.spu.ch1.lcounter.counter = SoundUnit::counter_disabled; state.spu.ch1.lcounter.lengthCounter = 0x40; state.spu.ch1.nr4 = 0x07; state.spu.ch1.master = true; state.spu.ch2.duty.nextPosUpdate = SoundUnit::counter_disabled; state.spu.ch2.duty.nr3 = 0; state.spu.ch2.duty.pos = 0; state.spu.ch2.duty.high = false; state.spu.ch2.env.counter = SoundUnit::counter_disabled; state.spu.ch2.env.volume = 0; state.spu.ch2.lcounter.counter = SoundUnit::counter_disabled; state.spu.ch2.lcounter.lengthCounter = 0x40; state.spu.ch2.nr4 = 0; state.spu.ch2.master = false; std::memcpy(state.spu.ch3.waveRam.ptr, state.mem.ioamhram.get() + 0x130, 0x10); state.spu.ch3.lcounter.counter = SoundUnit::counter_disabled; state.spu.ch3.lcounter.lengthCounter = 0x100; state.spu.ch3.waveCounter = SoundUnit::counter_disabled; state.spu.ch3.lastReadTime = SoundUnit::counter_disabled; state.spu.ch3.nr3 = 0; state.spu.ch3.nr4 = 0; state.spu.ch3.wavePos = 0; state.spu.ch3.sampleBuf = 0; state.spu.ch3.master = false; state.spu.ch4.lfsr.counter = state.spu.cycleCounter + 4; state.spu.ch4.lfsr.reg = 0xFF; state.spu.ch4.env.counter = SoundUnit::counter_disabled; state.spu.ch4.env.volume = 0; state.spu.ch4.lcounter.counter = SoundUnit::counter_disabled; state.spu.ch4.lcounter.lengthCounter = 0x40; state.spu.ch4.nr4 = 0; state.spu.ch4.master = false; state.rtc.baseTime = std::time(0); state.rtc.haltTime = state.rtc.baseTime; state.rtc.dataDh = 0; state.rtc.dataDl = 0; state.rtc.dataH = 0; state.rtc.dataM = 0; state.rtc.dataS = 0; state.rtc.lastLatchData = false; } libgambatte/src/sound.cpp000664 001750 001750 00000013320 12720365247 016607 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "sound.h" #include "savestate.h" #include #include /* Frame Sequencer Step Length Ctr Vol Env Sweep - - - - - - - - - - - - - - - - - - - - 0 Clock - Clock S 1 - Clock - 2 Clock - - 3 - - - 4 Clock - Clock 5 - - - 6 Clock - - 7 - - - - - - - - - - - - - - - - - - - - - - - Rate 256 Hz 64 Hz 128 Hz S) start step on sound power on. */ namespace gambatte { PSG::PSG() : buffer_(0) , bufferPos_(0) , lastUpdate_(0) , soVol_(0) , rsum_(0x8000) // initialize to 0x8000 to prevent borrows from high word, xor away later , enabled_(false) { } void PSG::init(const bool cgb) { ch1_.init(cgb); ch3_.init(cgb); } void PSG::reset() { ch1_.reset(); ch2_.reset(); ch3_.reset(); ch4_.reset(); } void PSG::setStatePtrs(SaveState &state) { ch3_.setStatePtrs(state); } void PSG::saveState(SaveState &state) { ch1_.saveState(state); ch2_.saveState(state); ch3_.saveState(state); ch4_.saveState(state); } void PSG::loadState(const SaveState &state) { ch1_.loadState(state); ch2_.loadState(state); ch3_.loadState(state); ch4_.loadState(state); lastUpdate_ = state.cpu.cycleCounter; setSoVolume(state.mem.ioamhram.get()[0x124]); mapSo(state.mem.ioamhram.get()[0x125]); enabled_ = state.mem.ioamhram.get()[0x126] >> 7 & 1; } void PSG::accumulateChannels(const unsigned long cycles) { uint_least32_t *const buf = buffer_ + bufferPos_; std::memset(buf, 0, cycles * sizeof(uint_least32_t)); ch1_.update(buf, soVol_, cycles); ch2_.update(buf, soVol_, cycles); ch3_.update(buf, soVol_, cycles); ch4_.update(buf, soVol_, cycles); } void PSG::generateSamples(unsigned long const cycleCounter, bool const doubleSpeed) { unsigned long const cycles = (cycleCounter - lastUpdate_) >> (1 + doubleSpeed); lastUpdate_ += cycles << (1 + doubleSpeed); if (cycles) accumulateChannels(cycles); bufferPos_ += cycles; } void PSG::resetCounter(unsigned long newCc, unsigned long oldCc, bool doubleSpeed) { generateSamples(oldCc, doubleSpeed); lastUpdate_ = newCc - (oldCc - lastUpdate_); } size_t PSG::fillBuffer() { uint_least32_t sum = rsum_; uint_least32_t *b = buffer_; unsigned n = bufferPos_; if (unsigned n2 = n >> 3) { n -= n2 << 3; do { sum += b[0]; b[0] = sum ^ 0x8000; sum += b[1]; b[1] = sum ^ 0x8000; sum += b[2]; b[2] = sum ^ 0x8000; sum += b[3]; b[3] = sum ^ 0x8000; sum += b[4]; b[4] = sum ^ 0x8000; sum += b[5]; b[5] = sum ^ 0x8000; sum += b[6]; b[6] = sum ^ 0x8000; sum += b[7]; b[7] = sum ^ 0x8000; b += 8; } while (--n2); } while (n--) { sum += *b; /* xor away the initial rsum value of 0x8000 (which prevents * borrows from the high word) from the low word */ *b++ = sum ^ 0x8000; } rsum_ = sum; return bufferPos_; } #ifdef WORDS_BIGENDIAN static const unsigned long so1Mul = 0x00000001; static const unsigned long so2Mul = 0x00010000; #else static const unsigned long so1Mul = 0x00010000; static const unsigned long so2Mul = 0x00000001; #endif void PSG::setSoVolume(const unsigned nr50) { soVol_ = (((nr50 & 0x7) + 1) * so1Mul + ((nr50 >> 4 & 0x7) + 1) * so2Mul) * 64; } void PSG::mapSo(const unsigned nr51) { const unsigned long tmp = nr51 * so1Mul + (nr51 >> 4) * so2Mul; ch1_.setSo((tmp & 0x00010001) * 0xFFFF); ch2_.setSo((tmp >> 1 & 0x00010001) * 0xFFFF); ch3_.setSo((tmp >> 2 & 0x00010001) * 0xFFFF); ch4_.setSo((tmp >> 3 & 0x00010001) * 0xFFFF); } unsigned PSG::getStatus() const { return ch1_.isActive() | ch2_.isActive() << 1 | ch3_.isActive() << 2 | ch4_.isActive() << 3; } } libgambatte/src/interrupter.h000664 001750 001750 00000002512 12720365247 017510 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef INTERRUPTER_H #define INTERRUPTER_H #include #include namespace gambatte { struct GsCode { unsigned short address; unsigned char value; unsigned char type; }; class Memory; class Interrupter { public: Interrupter(unsigned short &sp, unsigned short &pc); unsigned long interrupt(unsigned address, unsigned long cycleCounter, Memory &memory); void setGameShark(std::string const &codes); private: unsigned short &sp_; unsigned short &pc_; std::vector gsCodes_; void applyVblankCheats(unsigned long cc, Memory &mem); }; } #endif libgambatte/src/sound/channel1.h000664 001750 001750 00000004616 12720365247 017755 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef SOUND_CHANNEL1_H #define SOUND_CHANNEL1_H #include "duty_unit.h" #include "envelope_unit.h" #include "gbint.h" #include "length_counter.h" #include "master_disabler.h" #include "static_output_tester.h" namespace gambatte { struct SaveState; class Channel1 { public: Channel1(); void setNr0(unsigned data); void setNr1(unsigned data); void setNr2(unsigned data); void setNr3(unsigned data); void setNr4(unsigned data); void setSo(unsigned long soMask); bool isActive() const { return master_; } void update(uint_least32_t *buf, unsigned long soBaseVol, unsigned long cycles); void reset(); void init(bool cgb); void saveState(SaveState &state); void loadState(SaveState const &state); private: class SweepUnit : public SoundUnit { public: SweepUnit(MasterDisabler &disabler, DutyUnit &dutyUnit); virtual void event(); void nr0Change(unsigned newNr0); void nr4Init(unsigned long cycleCounter); void reset(); void init(bool cgb) { cgb_ = cgb; } void saveState(SaveState &state) const; void loadState(SaveState const &state); private: MasterDisabler &disableMaster_; DutyUnit &dutyUnit_; unsigned short shadow_; unsigned char nr0_; bool negging_; bool cgb_; unsigned calcFreq(); }; friend class StaticOutputTester; StaticOutputTester staticOutputTest_; DutyMasterDisabler disableMaster_; LengthCounter lengthCounter_; DutyUnit dutyUnit_; EnvelopeUnit envelopeUnit_; SweepUnit sweepUnit_; SoundUnit *nextEventUnit_; unsigned long cycleCounter_; unsigned long soMask_; unsigned long prevOut_; unsigned char nr4_; bool master_; void setEvent(); }; } #endif libgambatte/src/sound/channel3.cpp000664 001750 001750 00000012627 12720365247 020313 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "channel3.h" #include "../savestate.h" #include #include static inline unsigned toPeriod(unsigned nr3, unsigned nr4) { return 0x800 - ((nr4 << 8 & 0x700) | nr3); } namespace gambatte { Channel3::Channel3() : disableMaster_(master_, waveCounter_) , lengthCounter_(disableMaster_, 0xFF) , cycleCounter_(0) , soMask_(0) , prevOut_(0) , waveCounter_(SoundUnit::counter_disabled) , lastReadTime_(0) , nr0_(0) , nr3_(0) , nr4_(0) , wavePos_(0) , rshift_(4) , sampleBuf_(0) , master_(false) , cgb_(false) { } void Channel3::setNr0(unsigned data) { nr0_ = data & 0x80; if (!(data & 0x80)) disableMaster_(); } void Channel3::setNr2(unsigned data) { rshift_ = (data >> 5 & 3U) - 1; if (rshift_ > 3) rshift_ = 4; } void Channel3::setNr4(unsigned const data) { lengthCounter_.nr4Change(nr4_, data, cycleCounter_); nr4_ = data & 0x7F; if (data & nr0_/* & 0x80*/) { if (!cgb_ && waveCounter_ == cycleCounter_ + 1) { unsigned const pos = ((wavePos_ + 1) & 0x1F) >> 1; if (pos < 4) waveRam_[0] = waveRam_[pos]; else std::memcpy(waveRam_, waveRam_ + (pos & ~3), 4); } master_ = true; wavePos_ = 0; lastReadTime_ = waveCounter_ = cycleCounter_ + toPeriod(nr3_, data) + 3; } } void Channel3::setSo(unsigned long soMask) { soMask_ = soMask; } void Channel3::reset() { // cycleCounter >> 12 & 7 represents the frame sequencer position. cycleCounter_ &= 0xFFF; cycleCounter_ += ~(cycleCounter_ + 2) << 1 & 0x1000; sampleBuf_ = 0; } void Channel3::init(bool cgb) { cgb_ = cgb; } void Channel3::setStatePtrs(SaveState &state) { state.spu.ch3.waveRam.set(waveRam_, sizeof waveRam_); } void Channel3::saveState(SaveState &state) const { lengthCounter_.saveState(state.spu.ch3.lcounter); state.spu.ch3.waveCounter = waveCounter_; state.spu.ch3.lastReadTime = lastReadTime_; state.spu.ch3.nr3 = nr3_; state.spu.ch3.nr4 = nr4_; state.spu.ch3.wavePos = wavePos_; state.spu.ch3.sampleBuf = sampleBuf_; state.spu.ch3.master = master_; } void Channel3::loadState(SaveState const &state) { lengthCounter_.loadState(state.spu.ch3.lcounter, state.spu.cycleCounter); cycleCounter_ = state.spu.cycleCounter; waveCounter_ = std::max(state.spu.ch3.waveCounter, state.spu.cycleCounter); lastReadTime_ = state.spu.ch3.lastReadTime; nr3_ = state.spu.ch3.nr3; nr4_ = state.spu.ch3.nr4; wavePos_ = state.spu.ch3.wavePos & 0x1F; sampleBuf_ = state.spu.ch3.sampleBuf; master_ = state.spu.ch3.master; nr0_ = state.mem.ioamhram.get()[0x11A] & 0x80; setNr2(state.mem.ioamhram.get()[0x11C]); } void Channel3::updateWaveCounter(unsigned long const cc) { if (cc >= waveCounter_) { unsigned const period = toPeriod(nr3_, nr4_); unsigned long const periods = (cc - waveCounter_) / period; lastReadTime_ = waveCounter_ + periods * period; waveCounter_ = lastReadTime_ + period; wavePos_ += periods + 1; wavePos_ &= 0x1F; sampleBuf_ = waveRam_[wavePos_ >> 1]; } } void Channel3::update(uint_least32_t *buf, unsigned long const soBaseVol, unsigned long cycles) { unsigned long const outBase = nr0_/* & 0x80*/ ? soBaseVol & soMask_ : 0; if (outBase && rshift_ != 4) { unsigned long const endCycles = cycleCounter_ + cycles; for (;;) { unsigned long const nextMajorEvent = std::min(lengthCounter_.counter(), endCycles); unsigned long out = master_ ? ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - 15ul : 0 - 15ul; out *= outBase; while (waveCounter_ <= nextMajorEvent) { *buf += out - prevOut_; prevOut_ = out; buf += waveCounter_ - cycleCounter_; cycleCounter_ = waveCounter_; lastReadTime_ = waveCounter_; waveCounter_ += toPeriod(nr3_, nr4_); ++wavePos_; wavePos_ &= 0x1F; sampleBuf_ = waveRam_[wavePos_ >> 1]; out = ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - 15ul; out *= outBase; } if (cycleCounter_ < nextMajorEvent) { *buf += out - prevOut_; prevOut_ = out; buf += nextMajorEvent - cycleCounter_; cycleCounter_ = nextMajorEvent; } if (lengthCounter_.counter() == nextMajorEvent) { lengthCounter_.event(); } else break; } } else { unsigned long const out = outBase * (0 - 15ul); *buf += out - prevOut_; prevOut_ = out; cycleCounter_ += cycles; while (lengthCounter_.counter() <= cycleCounter_) { updateWaveCounter(lengthCounter_.counter()); lengthCounter_.event(); } updateWaveCounter(cycleCounter_); } if (cycleCounter_ >= SoundUnit::counter_max) { lengthCounter_.resetCounters(cycleCounter_); if (waveCounter_ != SoundUnit::counter_disabled) waveCounter_ -= SoundUnit::counter_max; lastReadTime_ -= SoundUnit::counter_max; cycleCounter_ -= SoundUnit::counter_max; } } } libgambatte/libretro/libretro.cpp000664 001750 001750 00000047327 12720365247 020352 0ustar00sergiosergio000000 000000 #include "libretro.h" #include "blipper.h" #include #include "gbcpalettes.h" #include #include #include #include #include #include #ifdef _3DS extern "C" void* linearMemAlign(size_t size, size_t alignment); extern "C" void linearFree(void* mem); #endif retro_log_printf_t log_cb; static retro_video_refresh_t video_cb; static retro_input_poll_t input_poll_cb; static retro_input_state_t input_state_cb; static retro_audio_sample_batch_t audio_batch_cb; static retro_environment_t environ_cb; static gambatte::video_pixel_t* video_buf; static gambatte::uint_least32_t video_pitch; static gambatte::GB gb; #ifdef CC_RESAMPLER #include "cc_resampler.h" #endif namespace input { struct map { unsigned snes; unsigned gb; }; static const map btn_map[] = { { RETRO_DEVICE_ID_JOYPAD_A, gambatte::InputGetter::A }, { RETRO_DEVICE_ID_JOYPAD_B, gambatte::InputGetter::B }, { RETRO_DEVICE_ID_JOYPAD_SELECT, gambatte::InputGetter::SELECT }, { RETRO_DEVICE_ID_JOYPAD_START, gambatte::InputGetter::START }, { RETRO_DEVICE_ID_JOYPAD_RIGHT, gambatte::InputGetter::RIGHT }, { RETRO_DEVICE_ID_JOYPAD_LEFT, gambatte::InputGetter::LEFT }, { RETRO_DEVICE_ID_JOYPAD_UP, gambatte::InputGetter::UP }, { RETRO_DEVICE_ID_JOYPAD_DOWN, gambatte::InputGetter::DOWN }, }; } class SNESInput : public gambatte::InputGetter { public: unsigned operator()() { unsigned res = 0; for (unsigned i = 0; i < sizeof(input::btn_map) / sizeof(input::map); i++) res |= input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, input::btn_map[i].snes) ? input::btn_map[i].gb : 0; return res; } } static gb_input; static blipper_t *resampler_l; static blipper_t *resampler_r; void retro_get_system_info(struct retro_system_info *info) { info->library_name = "Gambatte"; info->library_version = "v0.5.0"; info->need_fullpath = false; info->block_extract = false; info->valid_extensions = "gb|gbc|dmg"; } static struct retro_system_timing g_timing; void retro_get_system_av_info(struct retro_system_av_info *info) { retro_game_geometry geom = { 160, 144, 160, 144 }; info->geometry = geom; info->timing = g_timing; } static void check_system_specs(void) { unsigned level = 4; environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level); } static void log_null(enum retro_log_level level, const char *fmt, ...) {} void retro_init(void) { struct retro_log_callback log; if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) log_cb = log.log; else log_cb = log_null; // Using uint_least32_t in an audio interface expecting you to cast to short*? :( Weird stuff. assert(sizeof(gambatte::uint_least32_t) == sizeof(uint32_t)); gb.setInputGetter(&gb_input); double fps = 4194304.0 / 70224.0; double sample_rate = fps * 35112; #ifdef CC_RESAMPLER CC_init(); if (environ_cb) { g_timing.fps = fps; g_timing.sample_rate = sample_rate / CC_DECIMATION_RATE; // ~64k } #else resampler_l = blipper_new(32, 0.85, 6.5, 64, 1024, NULL); resampler_r = blipper_new(32, 0.85, 6.5, 64, 1024, NULL); if (environ_cb) { g_timing.fps = fps; g_timing.sample_rate = sample_rate / 64; // ~32k } #endif #ifdef _3DS video_buf = (gambatte::video_pixel_t*) linearMemAlign(256 * 144 * sizeof(gambatte::video_pixel_t), 128); #else video_buf = (gambatte::video_pixel_t*) malloc(256 * 144 * sizeof(gambatte::video_pixel_t)); #endif video_pitch = 256; check_system_specs(); } void retro_deinit() { #ifndef CC_RESAMPLER blipper_free(resampler_l);; blipper_free(resampler_r);; #endif #ifdef _3DS linearFree(video_buf); #else free(video_buf); #endif } void retro_set_environment(retro_environment_t cb) { environ_cb = cb; static const struct retro_variable vars[] = { { "gambatte_gb_colorization", "GB Colorization; disabled|auto|internal|custom" }, { "gambatte_gb_internal_palette", "Internal Palette; GBC - Blue|GBC - Brown|GBC - Dark Blue|GBC - Dark Brown|GBC - Dark Green|GBC - Grayscale|GBC - Green|GBC - Inverted|GBC - Orange|GBC - Pastel Mix|GBC - Red|GBC - Yellow|Special 1|Special 2|Special 3" }, { "gambatte_gbc_color_correction", "Color correction; enabled|disabled" }, { "gambatte_gb_hwmode", "Emulated hardware; Auto|GB|GBA" }, // unfortunately, libgambatte does not have a 'force GBC' flag { NULL, NULL }, }; cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars); } void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; } void retro_set_audio_sample(retro_audio_sample_t) { } void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; } void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; } void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; } void retro_set_controller_port_device(unsigned, unsigned) {} void retro_reset() { // gambatte seems to clear out SRAM on reset. uint8_t *sram = 0; if (gb.savedata_size()) { sram = new uint8_t[gb.savedata_size()]; memcpy(sram, gb.savedata_ptr(), gb.savedata_size()); } gb.reset(); if (sram) { memcpy(gb.savedata_ptr(), sram, gb.savedata_size()); delete[] sram; } } static size_t serialize_size = 0; size_t retro_serialize_size(void) { return gb.stateSize(); } bool retro_serialize(void *data, size_t size) { serialize_size = retro_serialize_size(); if (size != serialize_size) return false; gb.saveState(data); return true; } bool retro_unserialize(const void *data, size_t size) { serialize_size = retro_serialize_size(); if (size != serialize_size) return false; gb.loadState(data); return true; } void retro_cheat_reset() { gb.clearCheats(); } void retro_cheat_set(unsigned index, bool enabled, const char *code) { std::string s = code; if (s.find("-") != std::string::npos) gb.setGameGenie(code); else gb.setGameShark(code); } static std::string basename(std::string filename) { // Remove directory if present. // Do this before extension removal incase directory has a period character. const size_t last_slash_idx = filename.find_last_of("\\/"); if (std::string::npos != last_slash_idx) filename.erase(0, last_slash_idx + 1); // Remove extension if present. const size_t period_idx = filename.rfind('.'); if (std::string::npos != period_idx) filename.erase(period_idx); return filename; } static bool startswith(const std::string s1, const std::string prefix) { return s1.compare(0, prefix.length(), prefix) == 0; } static int gb_colorization_enable = 0; static std::string rom_path; char internal_game_name[17]; static void load_custom_palette(void) { unsigned rgb32 = 0; const char *system_directory_c = NULL; environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_directory_c); if (!system_directory_c) { log_cb(RETRO_LOG_WARN, "[Gambatte]: no system directory defined, unable to look for custom palettes.\n"); return; } std::string system_directory(system_directory_c); std::string custom_palette_path = system_directory + "/palettes/" + basename(rom_path) + ".pal"; std::ifstream palette_file(custom_palette_path.c_str()); // try to open the palette file in read-only mode if (!palette_file.is_open()) { // try again with the internal game name from the ROM header custom_palette_path = system_directory + "/palettes/" + std::string(internal_game_name) + ".pal"; palette_file.open(custom_palette_path.c_str()); } if (!palette_file.is_open())// && !findGbcTitlePal(internal_game_name)) { // try again with default.pal //- removed last line if colorization is enabled custom_palette_path = system_directory + "/palettes/" + "default.pal"; palette_file.open(custom_palette_path.c_str()); } if (!palette_file.is_open()) return; // unable to find any custom palette file #if 0 fprintf(RETRO_LOG_INFO, "[Gambatte]: using custom palette %s.\n", custom_palette_path.c_str()); #endif unsigned line_count = 0; for (std::string line; getline(palette_file, line); ) // iterate over file lines { line_count++; if (line[0]=='[') // skip ini sections continue; if (line[0]==';') // skip ini comments continue; if (line[0]=='\n') // skip empty lines continue; if (line.find("=") == std::string::npos) { log_cb(RETRO_LOG_WARN, "[Gambatte]: error in %s, line %d (color left as default).\n", custom_palette_path.c_str(), line_count); continue; // current line does not contain a palette color definition, so go to next line } // Supposed to be a typo here. if (startswith(line, "slectedScheme=")) continue; std::string line_value = line.substr(line.find("=") + 1); // extract the color value string std::stringstream ss(line_value); // convert the color value to int ss >> rgb32; if (!ss) { log_cb(RETRO_LOG_WARN, "[Gambatte]: unable to read palette color in %s, line %d (color left as default).\n", custom_palette_path.c_str(), line_count); continue; } #ifdef VIDEO_RGB565 rgb32=(rgb32&0x0000F8)>>3 |//red (rgb32&0x00FC00)>>5 |//green (rgb32&0xF80000)>>8;//blue #endif if (startswith(line, "Background0=")) gb.setDmgPaletteColor(0, 0, rgb32); else if (startswith(line, "Background1=")) gb.setDmgPaletteColor(0, 1, rgb32); else if (startswith(line, "Background2=")) gb.setDmgPaletteColor(0, 2, rgb32); else if (startswith(line, "Background3=")) gb.setDmgPaletteColor(0, 3, rgb32); else if (startswith(line, "Sprite%2010=")) gb.setDmgPaletteColor(1, 0, rgb32); else if (startswith(line, "Sprite%2011=")) gb.setDmgPaletteColor(1, 1, rgb32); else if (startswith(line, "Sprite%2012=")) gb.setDmgPaletteColor(1, 2, rgb32); else if (startswith(line, "Sprite%2013=")) gb.setDmgPaletteColor(1, 3, rgb32); else if (startswith(line, "Sprite%2020=")) gb.setDmgPaletteColor(2, 0, rgb32); else if (startswith(line, "Sprite%2021=")) gb.setDmgPaletteColor(2, 1, rgb32); else if (startswith(line, "Sprite%2022=")) gb.setDmgPaletteColor(2, 2, rgb32); else if (startswith(line, "Sprite%2023=")) gb.setDmgPaletteColor(2, 3, rgb32); else log_cb(RETRO_LOG_WARN, "[Gambatte]: error in %s, line %d (color left as default).\n", custom_palette_path.c_str(), line_count); } // endfor } static void check_variables(void) { bool colorCorrection=true; struct retro_variable var = {0}; var.key = "gambatte_gbc_color_correction"; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && !strcmp(var.value, "disabled")) colorCorrection=false; gb.setColorCorrection(colorCorrection); var.key = "gambatte_gb_colorization"; if (!environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || !var.value) return; if (gb.isCgb()) return; // else it is a GB-mono game -> set a color palette //bool gb_colorization_old = gb_colorization_enable; if (strcmp(var.value, "disabled") == 0) gb_colorization_enable = 0; else if (strcmp(var.value, "auto") == 0) gb_colorization_enable = 1; else if (strcmp(var.value, "custom") == 0) gb_colorization_enable = 2; else if (strcmp(var.value, "internal") == 0) gb_colorization_enable = 3; //std::string internal_game_name = gb.romTitle(); // available only in latest Gambatte //std::string internal_game_name = reinterpret_cast(info->data + 0x134); // buggy with some games ("YOSSY NO COOKIE", "YOSSY NO PANEPON, etc.) // load a GBC BIOS builtin palette unsigned short* gbc_bios_palette = NULL; switch (gb_colorization_enable) { case 1: gbc_bios_palette = const_cast(findGbcTitlePal(internal_game_name)); if (!gbc_bios_palette) { // no custom palette found, load the default (blue) gbc_bios_palette = const_cast(findGbcDirPal("GBC - Blue")); } break; case 2: load_custom_palette(); break; case 3: var.key = "gambatte_gb_internal_palette"; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { // Load the selected internal palette gbc_bios_palette = const_cast(findGbcDirPal(var.value)); } break; default: gbc_bios_palette = const_cast(findGbcDirPal("GBC - Grayscale")); break; } //gambatte is using custom colorization then we have a previously palette loaded, //skip this loop then if (gb_colorization_enable != 2) { unsigned rgb32 = 0; for (unsigned palnum = 0; palnum < 3; ++palnum) { for (unsigned colornum = 0; colornum < 4; ++colornum) { rgb32 = gb.gbcToRgb32(gbc_bios_palette[palnum * 4 + colornum]); gb.setDmgPaletteColor(palnum, colornum, rgb32); } } } } static unsigned pow2ceil(unsigned n) { --n; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; ++n; return n; } bool retro_load_game(const struct retro_game_info *info) { bool can_dupe = false; environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &can_dupe); if (!can_dupe) { log_cb(RETRO_LOG_ERROR, "[Gambatte]: Cannot dupe frames!\n"); return false; } struct retro_input_descriptor desc[] = { { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, { 0 }, }; environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); #ifdef VIDEO_RGB565 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { log_cb(RETRO_LOG_ERROR, "[Gambatte]: RGB565 is not supported.\n"); return false; } #else enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { log_cb(RETRO_LOG_ERROR, "[Gambatte]: XRGB8888 is not supported.\n"); return false; } #endif unsigned flags = 0; struct retro_variable var = {0}; var.key = "gambatte_gb_hwmode"; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (!strcmp(var.value, "GB")) flags |= gambatte::GB::FORCE_DMG; if (!strcmp(var.value, "GBA")) flags |= gambatte::GB::GBA_CGB; } if (gb.load(info->data, info->size, flags) != 0) return false; rom_path = info->path ? info->path : ""; strncpy(internal_game_name, (const char*)info->data + 0x134, sizeof(internal_game_name) - 1); internal_game_name[sizeof(internal_game_name)-1]='\0'; log_cb(RETRO_LOG_INFO, "[Gambatte]: Got internal game name: %s.\n", internal_game_name); check_variables(); //Ugly hack alert: This entire thing depends upon cartridge.cpp and memptrs.cpp not changing in weird ways. unsigned sramlen = gb.savedata_size(); struct retro_memory_descriptor descs[] = { { 0, gb.rambank0_ptr(), 0, 0xC000, 0, 0, 0x1000, NULL }, { 0, gb.rambank1_ptr(), 0, 0xD000, 0, 0, 0x1000, NULL }, { 0, gb.vram_ptr(), 0, 0x8000, 0, 0, 0x2000, NULL }, { RETRO_MEMDESC_CONST, gb.rombank0_ptr(), 0, 0x0000, 0, 0, 0x4000, NULL }, { RETRO_MEMDESC_CONST, gb.rombank1_ptr(), 0, 0x4000, 0, 0, 0x4000, NULL }, { 0, gb.savedata_ptr(), 0, 0xA000, (size_t)~0x1FFF, 0, sramlen, NULL }, }; struct retro_memory_map mmaps = { descs, sizeof(descs) / sizeof(descs[0]) - (sramlen == 0) }; environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &mmaps); bool yes = true; environ_cb(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &yes); return true; } bool retro_load_game_special(unsigned, const struct retro_game_info*, size_t) { return false; } void retro_unload_game() {} unsigned retro_get_region() { return RETRO_REGION_NTSC; } void *retro_get_memory_data(unsigned id) { switch (id) { case RETRO_MEMORY_SAVE_RAM: return gb.savedata_ptr(); case RETRO_MEMORY_RTC: return gb.rtcdata_ptr(); case RETRO_MEMORY_SYSTEM_RAM: /* Really ugly hack here, relies upon * libgambatte/src/memory/memptrs.cpp MemPtrs::reset not * realizing that that memchunk hack is ugly, or * otherwise getting rearranged. */ return gb.rambank0_ptr(); } return 0; } size_t retro_get_memory_size(unsigned id) { switch (id) { case RETRO_MEMORY_SAVE_RAM: return gb.savedata_size(); case RETRO_MEMORY_RTC: return gb.rtcdata_size(); case RETRO_MEMORY_SYSTEM_RAM: /* This is rather hacky too... it relies upon * libgambatte/src/memory/cartridge.cpp not changing * the call to memptrs.reset, but this is * probably mostly safe. * * GBC will probably not get a * hardware upgrade anytime soon. */ return (gb.isCgb() ? 8 : 2) * 0x1000ul; } return 0; } static void render_audio(const int16_t *samples, unsigned frames) { if (!frames) return; blipper_push_samples(resampler_l, samples + 0, frames, 2); blipper_push_samples(resampler_r, samples + 1, frames, 2); } void retro_run() { static uint64_t samples_count = 0; static uint64_t frames_count = 0; input_poll_cb(); uint64_t expected_frames = samples_count / 35112; if (frames_count < expected_frames) // Detect frame dupes. { #ifdef VIDEO_RGB565 video_cb(0, 160, 144, 512); #else video_cb(0, 160, 144, 1024); #endif frames_count++; return; } union { gambatte::uint_least32_t u32[2064 + 2064]; int16_t i16[2 * (2064 + 2064)]; } static sound_buf; unsigned samples = 2064; while (gb.runFor(video_buf, video_pitch, sound_buf.u32, samples) == -1) { #ifdef CC_RESAMPLER CC_renderaudio((audio_frame_t*)sound_buf.u32, samples); #else render_audio(sound_buf.i16, samples); unsigned read_avail = blipper_read_avail(resampler_l); if (read_avail >= 512) { blipper_read(resampler_l, sound_buf.i16 + 0, read_avail, 2); blipper_read(resampler_r, sound_buf.i16 + 1, read_avail, 2); audio_batch_cb(sound_buf.i16, read_avail); } #endif samples_count += samples; samples = 2064; } samples_count += samples; #ifdef CC_RESAMPLER CC_renderaudio((audio_frame_t*)sound_buf.u32, samples); #else render_audio(sound_buf.i16, samples); #endif #ifdef VIDEO_RGB565 video_cb(video_buf, 160, 144, 512); #else video_cb(video_buf, 160, 144, 1024); #endif #ifndef CC_RESAMPLER unsigned read_avail = blipper_read_avail(resampler_l); blipper_read(resampler_l, sound_buf.i16 + 0, read_avail, 2); blipper_read(resampler_r, sound_buf.i16 + 1, read_avail, 2); audio_batch_cb(sound_buf.i16, read_avail); #endif frames_count++; bool updated = false; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) check_variables(); } unsigned retro_api_version() { return RETRO_API_VERSION; } common/gambatte-array.h000664 001750 001750 00000003517 12720365247 016261 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2008 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef ARRAY_H #define ARRAY_H #include #include "uncopyable.h" template class Array : Uncopyable { T *a; std::size_t sz; public: explicit Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {} ~Array() { delete []a; } void reset(const std::size_t size = 0) { delete []a; a = size ? new T[size] : 0; sz = size; } std::size_t size() const { return sz; } T * get() const { return a; } operator T*() const { return a; } }; #endif libgambatte/src/sound/channel4.cpp000664 001750 001750 00000014726 12720365247 020316 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "channel4.h" #include "../savestate.h" #include static unsigned long toPeriod(unsigned const nr3) { unsigned s = (nr3 >> 4) + 3; unsigned r = nr3 & 7; if (!r) { r = 1; --s; } return r << s; } namespace gambatte { Channel4::Lfsr::Lfsr() : backupCounter_(counter_disabled) , reg_(0x7FFF) , nr3_(0) , master_(false) { } void Channel4::Lfsr::updateBackupCounter(unsigned long const cc) { if (backupCounter_ <= cc) { unsigned long const period = toPeriod(nr3_); unsigned long periods = (cc - backupCounter_) / period + 1; backupCounter_ += periods * period; if (master_ && nr3_ < 0xE0) { if (nr3_ & 8) { while (periods > 6) { unsigned const xored = (reg_ << 1 ^ reg_) & 0x7E; reg_ = (reg_ >> 6 & ~0x7E) | xored | xored << 8; periods -= 6; } unsigned const xored = ((reg_ ^ reg_ >> 1) << (7 - periods)) & 0x7F; reg_ = (reg_ >> periods & ~(0x80 - (0x80 >> periods))) | xored | xored << 8; } else { while (periods > 15) { reg_ = reg_ ^ reg_ >> 1; periods -= 15; } reg_ = reg_ >> periods | (((reg_ ^ reg_ >> 1) << (15 - periods)) & 0x7FFF); } } } } void Channel4::Lfsr::reviveCounter(unsigned long cc) { updateBackupCounter(cc); counter_ = backupCounter_; } inline void Channel4::Lfsr::event() { if (nr3_ < 0xE0) { unsigned const shifted = reg_ >> 1; unsigned const xored = (reg_ ^ shifted) & 1; reg_ = shifted | xored << 14; if (nr3_ & 8) reg_ = (reg_ & ~0x40) | xored << 6; } counter_ += toPeriod(nr3_); backupCounter_ = counter_; } void Channel4::Lfsr::nr3Change(unsigned newNr3, unsigned long cc) { updateBackupCounter(cc); nr3_ = newNr3; } void Channel4::Lfsr::nr4Init(unsigned long cc) { disableMaster(); updateBackupCounter(cc); master_ = true; backupCounter_ += 4; counter_ = backupCounter_; } void Channel4::Lfsr::reset(unsigned long cc) { nr3_ = 0; disableMaster(); backupCounter_ = cc + toPeriod(nr3_); } void Channel4::Lfsr::resetCounters(unsigned long oldCc) { updateBackupCounter(oldCc); backupCounter_ -= counter_max; SoundUnit::resetCounters(oldCc); } void Channel4::Lfsr::saveState(SaveState &state, unsigned long cc) { updateBackupCounter(cc); state.spu.ch4.lfsr.counter = backupCounter_; state.spu.ch4.lfsr.reg = reg_; } void Channel4::Lfsr::loadState(SaveState const &state) { counter_ = backupCounter_ = std::max(state.spu.ch4.lfsr.counter, state.spu.cycleCounter); reg_ = state.spu.ch4.lfsr.reg; master_ = state.spu.ch4.master; nr3_ = state.mem.ioamhram.get()[0x122]; } Channel4::Channel4() : staticOutputTest_(*this, lfsr_) , disableMaster_(master_, lfsr_) , lengthCounter_(disableMaster_, 0x3F) , envelopeUnit_(staticOutputTest_) , nextEventUnit_(0) , cycleCounter_(0) , soMask_(0) , prevOut_(0) , nr4_(0) , master_(false) { setEvent(); } void Channel4::setEvent() { nextEventUnit_ = &envelopeUnit_; if (lengthCounter_.counter() < nextEventUnit_->counter()) nextEventUnit_ = &lengthCounter_; } void Channel4::setNr1(unsigned data) { lengthCounter_.nr1Change(data, nr4_, cycleCounter_); setEvent(); } void Channel4::setNr2(unsigned data) { if (envelopeUnit_.nr2Change(data)) disableMaster_(); else staticOutputTest_(cycleCounter_); setEvent(); } void Channel4::setNr4(unsigned const data) { lengthCounter_.nr4Change(nr4_, data, cycleCounter_); nr4_ = data; if (data & 0x80) { // init-bit nr4_ &= 0x7F; master_ = !envelopeUnit_.nr4Init(cycleCounter_); if (master_) lfsr_.nr4Init(cycleCounter_); staticOutputTest_(cycleCounter_); } setEvent(); } void Channel4::setSo(unsigned long soMask) { soMask_ = soMask; staticOutputTest_(cycleCounter_); setEvent(); } void Channel4::reset() { // cycleCounter >> 12 & 7 represents the frame sequencer position. cycleCounter_ &= 0xFFF; cycleCounter_ += ~(cycleCounter_ + 2) << 1 & 0x1000; lfsr_.reset(cycleCounter_); envelopeUnit_.reset(); setEvent(); } void Channel4::saveState(SaveState &state) { lfsr_.saveState(state, cycleCounter_); envelopeUnit_.saveState(state.spu.ch4.env); lengthCounter_.saveState(state.spu.ch4.lcounter); state.spu.ch4.nr4 = nr4_; state.spu.ch4.master = master_; } void Channel4::loadState(SaveState const &state) { lfsr_.loadState(state); envelopeUnit_.loadState(state.spu.ch4.env, state.mem.ioamhram.get()[0x121], state.spu.cycleCounter); lengthCounter_.loadState(state.spu.ch4.lcounter, state.spu.cycleCounter); cycleCounter_ = state.spu.cycleCounter; nr4_ = state.spu.ch4.nr4; master_ = state.spu.ch4.master; } void Channel4::update(uint_least32_t *buf, unsigned long const soBaseVol, unsigned long cycles) { unsigned long const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; unsigned long const outLow = outBase * (0 - 15ul); unsigned long const endCycles = cycleCounter_ + cycles; for (;;) { unsigned long const outHigh = outBase * (envelopeUnit_.getVolume() * 2 - 15ul); unsigned long const nextMajorEvent = std::min(nextEventUnit_->counter(), endCycles); unsigned long out = lfsr_.isHighState() ? outHigh : outLow; while (lfsr_.counter() <= nextMajorEvent) { *buf += out - prevOut_; prevOut_ = out; buf += lfsr_.counter() - cycleCounter_; cycleCounter_ = lfsr_.counter(); lfsr_.event(); out = lfsr_.isHighState() ? outHigh : outLow; } if (cycleCounter_ < nextMajorEvent) { *buf += out - prevOut_; prevOut_ = out; buf += nextMajorEvent - cycleCounter_; cycleCounter_ = nextMajorEvent; } if (nextEventUnit_->counter() == nextMajorEvent) { nextEventUnit_->event(); setEvent(); } else break; } if (cycleCounter_ >= SoundUnit::counter_max) { lengthCounter_.resetCounters(cycleCounter_); lfsr_.resetCounters(cycleCounter_); envelopeUnit_.resetCounters(cycleCounter_); cycleCounter_ -= SoundUnit::counter_max; } } } libgambatte/include/inputgetter.h000664 001750 001750 00000003353 12720365247 020337 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef GAMBATTE_INPUTGETTER_H #define GAMBATTE_INPUTGETTER_H namespace gambatte { class InputGetter { public: enum { A = 0x01, B = 0x02, SELECT = 0x04, START = 0x08, RIGHT = 0x10, LEFT = 0x20, UP = 0x40, DOWN = 0x80 }; virtual ~InputGetter() {}; /** @return A|B|SELECT|START|RIGHT|LEFT|UP|DOWN if those buttons are pressed. */ virtual unsigned operator()() = 0; }; } #endif libgambatte/src/video/ly_counter.cpp000664 001750 001750 00000003374 12720365247 020760 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "ly_counter.h" #include "../savestate.h" namespace gambatte { LyCounter::LyCounter() : time_(0) , lineTime_(0) , ly_(0) , ds_(false) { setDoubleSpeed(false); reset(0, 0); } void LyCounter::doEvent() { ++ly_; if (ly_ == 154) ly_ = 0; time_ = time_ + lineTime_; } unsigned long LyCounter::nextLineCycle(unsigned const lineCycle, unsigned long const cc) const { unsigned long tmp = time_ + (lineCycle << ds_); if (tmp - cc > lineTime_) tmp -= lineTime_; return tmp; } unsigned long LyCounter::nextFrameCycle(unsigned long const frameCycle, unsigned long const cc) const { unsigned long tmp = time_ + (((153U - ly()) * 456U + frameCycle) << ds_); if (tmp - cc > 70224U << ds_) tmp -= 70224U << ds_; return tmp; } void LyCounter::reset(unsigned long videoCycles, unsigned long lastUpdate) { ly_ = videoCycles / 456; time_ = lastUpdate + ((456 - (videoCycles - ly_ * 456ul)) << isDoubleSpeed()); } void LyCounter::setDoubleSpeed(bool ds) { ds_ = ds; lineTime_ = 456U << ds; } } libgambatte/src/mem/cartridge.h000664 001750 001750 00000011436 12720365247 017654 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007-2010 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef CARTRIDGE_H #define CARTRIDGE_H #include "memptrs.h" #include "rtc.h" #include "savestate.h" #include #include #include namespace gambatte { class Mbc { public: virtual ~Mbc() {} virtual void romWrite(unsigned P, unsigned data) = 0; virtual void saveState(SaveState::Mem &ss) const = 0; virtual void loadState(const SaveState::Mem &ss) = 0; virtual bool isAddressWithinAreaRombankCanBeMappedTo(unsigned address, unsigned rombank) const = 0; }; class Cartridge { public: void setStatePtrs(SaveState &); void saveState(SaveState &) const; void loadState(const SaveState &); bool loaded() const { return mbc.get(); } const unsigned char * rmem(unsigned area) const { return memptrs_.rmem(area); } unsigned char * wmem(unsigned area) const { return memptrs_.wmem(area); } unsigned char * vramdata() const { return memptrs_.vramdata(); } unsigned char * romdata(unsigned area) const { return memptrs_.romdata(area); } unsigned char * wramdata(unsigned area) const { return memptrs_.wramdata(area); } const unsigned char * rdisabledRam() const { return memptrs_.rdisabledRam(); } const unsigned char * rsrambankptr() const { return memptrs_.rsrambankptr(); } unsigned char * wsrambankptr() const { return memptrs_.wsrambankptr(); } unsigned char * vrambankptr() const { return memptrs_.vrambankptr(); } OamDmaSrc oamDmaSrc() const { return memptrs_.oamDmaSrc(); } void setVrambank(unsigned bank) { memptrs_.setVrambank(bank); } void setWrambank(unsigned bank) { memptrs_.setWrambank(bank); } void setOamDmaSrc(OamDmaSrc oamDmaSrc) { memptrs_.setOamDmaSrc(oamDmaSrc); } void mbcWrite(unsigned addr, unsigned data) { mbc->romWrite(addr, data); } bool isCgb() const { return gambatte::isCgb(memptrs_); } void rtcWrite(unsigned data) { rtc_.write(data); } unsigned char rtcRead() const { return *rtc_.getActive(); } const std::string saveBasePath() const; void setSaveDir(const std::string &dir); int loadROM(const void *romdata, unsigned romsize, bool forceDmg, bool multicartCompat); void setGameGenie(const std::string &codes); void clearCheats(); void *savedata_ptr(); unsigned savedata_size(); // Not endian-safe at all, but hey. void *rtcdata_ptr(); unsigned rtcdata_size(); private: struct AddrData { unsigned long addr; unsigned char data; AddrData(unsigned long addr, unsigned data) : addr(addr), data(data) { } }; MemPtrs memptrs_; Rtc rtc_; std::auto_ptr mbc; std::vector ggUndoList_; void applyGameGenie(const std::string &code); }; } #endif libgambatte/src/gambatte-memory.h000664 001750 001750 00000012647 12720365247 020231 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef MEMORY_H #define MEMORY_H #include "mem/cartridge.h" #include "interrupter.h" #include "sound.h" #include "tima.h" #include "video.h" namespace gambatte { class InputGetter; class Memory { public: explicit Memory(Interrupter const &interrupter); bool loaded() const { return cart_.loaded(); } void setStatePtrs(SaveState &state); unsigned long saveState(SaveState &state, unsigned long cc); void loadState(SaveState const &state); #ifdef __LIBRETRO__ void *savedata_ptr() { return cart_.savedata_ptr(); } unsigned savedata_size() { return cart_.savedata_size(); } void *rtcdata_ptr() { return cart_.rtcdata_ptr(); } unsigned rtcdata_size() { return cart_.rtcdata_size(); } void display_setColorCorrection(bool enable) { lcd_.setColorCorrection(enable); } video_pixel_t display_gbcToRgb32(const unsigned bgr15) { return lcd_.gbcToRgb32(bgr15); } void clearCheats() { cart_.clearCheats(); } void *vram_ptr() const { return cart_.vramdata(); } void *rambank0_ptr() const { return cart_.wramdata(0); } void *rambank1_ptr() const { return cart_.wramdata(0) + 0x1000; } void *rombank0_ptr() const { return cart_.romdata(0); } void *rombank1_ptr() const { return cart_.romdata(0) + 0x4000; } #else void loadSavedata() { cart_.loadSavedata(); } void saveSavedata() { cart_.saveSavedata(); } #endif std::string const saveBasePath() const { return cart_.saveBasePath(); } unsigned long stop(unsigned long cycleCounter); bool isCgb() const { return lcd_.isCgb(); } bool ime() const { return intreq_.ime(); } bool halted() const { return intreq_.halted(); } unsigned long nextEventTime() const { return intreq_.minEventTime(); } bool isActive() const { return intreq_.eventTime(intevent_end) != disabled_time; } long cyclesSinceBlit(unsigned long cc) const { if (cc < intreq_.eventTime(intevent_blit)) return -1; return (cc - intreq_.eventTime(intevent_blit)) >> isDoubleSpeed(); } void halt() { intreq_.halt(); } void ei(unsigned long cycleCounter) { if (!ime()) { intreq_.ei(cycleCounter); } } void di() { intreq_.di(); } unsigned ff_read(unsigned p, unsigned long cc) { return p < 0x80 ? nontrivial_ff_read(p, cc) : ioamhram_[p + 0x100]; } unsigned read(unsigned p, unsigned long cc) { return cart_.rmem(p >> 12) ? cart_.rmem(p >> 12)[p] : nontrivial_read(p, cc); } void write(unsigned p, unsigned data, unsigned long cc) { if (cart_.wmem(p >> 12)) { cart_.wmem(p >> 12)[p] = data; } else nontrivial_write(p, data, cc); } void ff_write(unsigned p, unsigned data, unsigned long cc) { if (p - 0x80u < 0x7Fu) { ioamhram_[p + 0x100] = data; } else nontrivial_ff_write(p, data, cc); } unsigned long event(unsigned long cycleCounter); unsigned long resetCounters(unsigned long cycleCounter); void setSaveDir(std::string const &dir) { cart_.setSaveDir(dir); } void setInputGetter(InputGetter *getInput) { getInput_ = getInput; } void setEndtime(unsigned long cc, unsigned long inc); void setSoundBuffer(uint_least32_t *buf) { psg_.setBuffer(buf); } std::size_t fillSoundBuffer(unsigned long cc); void setVideoBuffer(video_pixel_t *videoBuf, std::ptrdiff_t pitch) { lcd_.setVideoBuffer(videoBuf, pitch); } void setDmgPaletteColor(int palNum, int colorNum, unsigned long rgb32) { lcd_.setDmgPaletteColor(palNum, colorNum, rgb32); } void setGameGenie(std::string const &codes) { cart_.setGameGenie(codes); } void setGameShark(std::string const &codes) { interrupter_.setGameShark(codes); } void updateInput(); int loadROM(const void *romdata, unsigned romsize, const bool forceDmg, const bool multicartCompat); private: Cartridge cart_; unsigned char ioamhram_[0x200]; InputGetter *getInput_; unsigned long divLastUpdate_; unsigned long lastOamDmaUpdate_; InterruptRequester intreq_; Tima tima_; LCD lcd_; PSG psg_; Interrupter interrupter_; unsigned short dmaSource_; unsigned short dmaDestination_; unsigned char oamDmaPos_; unsigned char serialCnt_; bool blanklcd_; void decEventCycles(IntEventId eventId, unsigned long dec); void oamDmaInitSetup(); void updateOamDma(unsigned long cycleCounter); void startOamDma(unsigned long cycleCounter); void endOamDma(unsigned long cycleCounter); unsigned char const * oamDmaSrcPtr() const; unsigned nontrivial_ff_read(unsigned p, unsigned long cycleCounter); unsigned nontrivial_read(unsigned p, unsigned long cycleCounter); void nontrivial_ff_write(unsigned p, unsigned data, unsigned long cycleCounter); void nontrivial_write(unsigned p, unsigned data, unsigned long cycleCounter); void updateSerial(unsigned long cc); void updateTimaIrq(unsigned long cc); void updateIrqs(unsigned long cc); bool isDoubleSpeed() const { return lcd_.isDoubleSpeed(); } }; } #endif libgambatte/src/interruptrequester.h000664 001750 001750 00000006644 12720365247 021133 0ustar00sergiosergio000000 000000 // // Copyright (C) 2010 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef INTERRUPT_REQUESTER_H #define INTERRUPT_REQUESTER_H #include "counterdef.h" #include "minkeeper.h" namespace gambatte { struct SaveState; enum IntEventId { intevent_unhalt, intevent_end, intevent_blit, intevent_serial, intevent_oam, intevent_dma, intevent_tima, intevent_video, intevent_interrupts, intevent_last = intevent_interrupts }; class InterruptRequester { public: InterruptRequester(); void saveState(SaveState &) const; void loadState(SaveState const &); void resetCc(unsigned long oldCc, unsigned long newCc); unsigned ifreg() const { return ifreg_; } unsigned pendingIrqs() const { return ifreg_ & iereg_; } bool ime() const { return intFlags_.ime(); } bool halted() const { return intFlags_.halted(); } void ei(unsigned long cc); void di(); void halt(); void unhalt(); void flagIrq(unsigned bit); void ackIrq(unsigned bit); void setIereg(unsigned iereg); void setIfreg(unsigned ifreg); IntEventId minEventId() const { return static_cast(eventTimes_.min()); } unsigned long minEventTime() const { return eventTimes_.minValue(); } template void setEventTime(unsigned long value) { eventTimes_.setValue(value); } void setEventTime(IntEventId id, unsigned long value) { eventTimes_.setValue(id, value); } unsigned long eventTime(IntEventId id) const { return eventTimes_.value(id); } private: class IntFlags { public: IntFlags() : flags_(0) {} bool ime() const { return flags_ & flag_ime; } bool halted() const { return flags_ & flag_halted; } bool imeOrHalted() const { return flags_; } void setIme() { flags_ |= flag_ime; } void unsetIme() { flags_ &= ~flag_ime; } void setHalted() { flags_ |= flag_halted; } void unsetHalted() { flags_ &= ~flag_halted; } void set(bool ime, bool halted) { flags_ = halted * flag_halted + ime * flag_ime; } private: unsigned char flags_; enum { flag_ime = 1, flag_halted = 2 }; }; MinKeeper eventTimes_; unsigned long minIntTime_; unsigned ifreg_; unsigned iereg_; IntFlags intFlags_; }; inline void flagHdmaReq(InterruptRequester &intreq) { intreq.setEventTime(0); } inline void flagGdmaReq(InterruptRequester &intreq) { intreq.setEventTime(1); } inline void ackDmaReq(InterruptRequester &intreq) { intreq.setEventTime(disabled_time); } inline bool hdmaReqFlagged(InterruptRequester const &intreq) { return intreq.eventTime(intevent_dma) == 0; } inline bool gdmaReqFlagged(InterruptRequester const &intreq) { return intreq.eventTime(intevent_dma) == 1; } } #endif libgambatte/src/sound/duty_unit.cpp000664 001750 001750 00000007264 12720365247 020645 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "duty_unit.h" #include static inline bool toOutState(unsigned duty, unsigned pos) { return 0x7EE18180 >> (duty * 8 + pos) & 1; } static inline unsigned toPeriod(unsigned freq) { return (2048 - freq) * 2; } namespace gambatte { DutyUnit::DutyUnit() : nextPosUpdate_(counter_disabled) , period_(4096) , pos_(0) , duty_(0) , inc_(0) , high_(false) , enableEvents_(true) { } void DutyUnit::updatePos(unsigned long const cc) { if (cc >= nextPosUpdate_) { unsigned long const inc = (cc - nextPosUpdate_) / period_ + 1; nextPosUpdate_ += period_ * inc; pos_ += inc; pos_ &= 7; high_ = toOutState(duty_, pos_); } } void DutyUnit::setCounter() { static unsigned char const nextStateDistance[4 * 8] = { 7, 6, 5, 4, 3, 2, 1, 1, 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 2 }; if (enableEvents_ && nextPosUpdate_ != counter_disabled) { unsigned const npos = (pos_ + 1) & 7; counter_ = nextPosUpdate_; inc_ = nextStateDistance[duty_ * 8 + npos]; if (toOutState(duty_, npos) == high_) { counter_ += period_ * inc_; inc_ = nextStateDistance[duty_ * 8 + ((npos + inc_) & 7)]; } } else counter_ = counter_disabled; } void DutyUnit::setFreq(unsigned newFreq, unsigned long cc) { updatePos(cc); period_ = toPeriod(newFreq); setCounter(); } void DutyUnit::event() { static unsigned char const inc[] = { 1, 7, 2, 6, 4, 4, 6, 2, }; high_ ^= true; counter_ += inc_ * period_; inc_ = inc[duty_ * 2 + high_]; } void DutyUnit::nr1Change(unsigned newNr1, unsigned long cc) { updatePos(cc); duty_ = newNr1 >> 6; setCounter(); } void DutyUnit::nr3Change(unsigned newNr3, unsigned long cc) { setFreq((freq() & 0x700) | newNr3, cc); } void DutyUnit::nr4Change(unsigned const newNr4, unsigned long const cc) { setFreq((newNr4 << 8 & 0x700) | (freq() & 0xFF), cc); if (newNr4 & 0x80) { nextPosUpdate_ = (cc & ~1ul) + period_ + 4; setCounter(); } } void DutyUnit::reset() { pos_ = 0; high_ = false; nextPosUpdate_ = counter_disabled; setCounter(); } void DutyUnit::saveState(SaveState::SPU::Duty &dstate, unsigned long const cc) { updatePos(cc); setCounter(); dstate.nextPosUpdate = nextPosUpdate_; dstate.nr3 = freq() & 0xFF; dstate.pos = pos_; dstate.high = high_; } void DutyUnit::loadState(SaveState::SPU::Duty const &dstate, unsigned const nr1, unsigned const nr4, unsigned long const cc) { nextPosUpdate_ = std::max(dstate.nextPosUpdate, cc); pos_ = dstate.pos & 7; high_ = dstate.high; duty_ = nr1 >> 6; period_ = toPeriod((nr4 << 8 & 0x700) | dstate.nr3); enableEvents_ = true; setCounter(); } void DutyUnit::resetCounters(unsigned long const oldCc) { if (nextPosUpdate_ == counter_disabled) return; updatePos(oldCc); nextPosUpdate_ -= counter_max; setCounter(); } void DutyUnit::killCounter() { enableEvents_ = false; setCounter(); } void DutyUnit::reviveCounter(unsigned long const cc) { updatePos(cc); enableEvents_ = true; setCounter(); } } libgambatte/libretro/msvc/msvc-2010-360/msvc-2010-360.vcxproj.filters000664 001750 001750 00000013133 12720365247 025540 0ustar00sergiosergio000000 000000  {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hpp;hxx;hm;inl;inc;xsd {c6b3d008-3362-4d55-a3d9-6e980fb09074} {b1fb6fc7-40b0-46c5-86f5-c5d62718be48} {ec7ab185-9a6d-4fa6-95f4-2921e8dd9d06} {f5709d8a-86dc-402f-825c-25a7e425bddb} {6c58fa31-84ab-4bdf-94ba-61cd802cac92} {e2083396-20f9-42a2-a09f-59a19ec295c3} {8328f716-5a8e-4c0d-ad80-1057b626b35c} Source Files\libretro Source Files\resampler Source Files\resampler Source Files\resampler Source Files\resampler Source Files\resampler Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\sound Source Files\src\mem Source Files\src\mem Source Files\src\mem Source Files\src\file Source Files\src\video Source Files\src\video Source Files\src\video Source Files\src\video Source Files\src\video Source Files\libretro libgambatte/src/statesaver.h000664 001750 001750 00000003546 12720365247 017316 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2008 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef STATESAVER_H #define STATESAVER_H #include "gbint.h" #include #include namespace gambatte { struct SaveState; class StateSaver { StateSaver(); public: enum { SS_SHIFT = 2 }; enum { SS_DIV = 1 << 2 }; enum { SS_WIDTH = 160 >> SS_SHIFT }; enum { SS_HEIGHT = 144 >> SS_SHIFT }; static void saveState(const SaveState &state, void *data); static bool loadState(SaveState &state, const void *data); static size_t stateSize(const SaveState &state); }; } #endif libgambatte/src/000700 001750 001750 00000000000 12720366137 014737 5ustar00sergiosergio000000 000000 libgambatte/src/video_libretro.cpp000664 001750 001750 00000012246 12720365247 020475 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "video.h" #include "savestate.h" #include #include namespace gambatte { void LCD::setDmgPaletteColor(const unsigned index, const video_pixel_t rgb32) { dmgColorsRgb32_[index] = rgb32; } void LCD::setDmgPalette(video_pixel_t *const palette, const video_pixel_t *const dmgColors, const unsigned data) { palette[0] = dmgColors[data & 3]; palette[1] = dmgColors[data >> 2 & 3]; palette[2] = dmgColors[data >> 4 & 3]; palette[3] = dmgColors[data >> 6 & 3]; } void LCD::setColorCorrection(bool colorCorrection_) { colorCorrection=colorCorrection_; refreshPalettes(); } LCD::LCD(const unsigned char *const oamram, const unsigned char *const vram, const VideoInterruptRequester memEventRequester) : ppu_(nextM0Time_, oamram, vram), eventTimes_(memEventRequester), statReg_(0), m2IrqStatReg_(0), m1IrqStatReg_(0) { std::memset( bgpData_, 0, sizeof bgpData_); std::memset(objpData_, 0, sizeof objpData_); for (std::size_t i = 0; i < sizeof(dmgColorsRgb32_) / sizeof(dmgColorsRgb32_[0]); ++i) { #ifdef VIDEO_RGB565 uint16_t dmgColors[4]={0xFFFF, //11111 111111 11111 0xAD55, //10101 101010 10101 0x52AA, //01010 010101 01010 0x0000};//00000 000000 00000 setDmgPaletteColor(i, dmgColors[i&3]); #else setDmgPaletteColor(i, (3 - (i & 3)) * 85 * 0x010101); #endif } reset(oamram, vram, false); setVideoBuffer(0, 160); setColorCorrection(true); } void LCD::doCgbColorChange(unsigned char *const pdata, video_pixel_t *const palette, unsigned index, const unsigned data) { pdata[index] = data; index >>= 1; palette[index] = gbcToRgb32(pdata[index << 1] | pdata[(index << 1) + 1] << 8); } void LCD::setVideoBuffer(video_pixel_t *const videoBuf, const int pitch) { ppu_.setFrameBuf(videoBuf, pitch); } static void clear(video_pixel_t *buf, const unsigned long color, const int dpitch) { unsigned lines = 144; while (lines--) { std::fill_n(buf, 160, color); buf += dpitch; } } void LCD::setDmgPaletteColor(const unsigned palNum, const unsigned colorNum, const video_pixel_t rgb32) { if (palNum > 2 || colorNum > 3) return; setDmgPaletteColor(palNum * 4 | colorNum, rgb32); refreshPalettes(); } void LCD::updateScreen(const bool blanklcd, const unsigned long cycleCounter) { update(cycleCounter); if (blanklcd && ppu_.frameBuf().fb()) { const video_pixel_t color = ppu_.cgb() ? gbcToRgb32(0xFFFF) : dmgColorsRgb32_[0]; clear(ppu_.frameBuf().fb(), color, ppu_.frameBuf().pitch()); } } video_pixel_t LCD::gbcToRgb32(const unsigned bgr15) { if (colorCorrection) { #ifdef VIDEO_RGB565 const unsigned r = bgr15 & 0x1F; const unsigned g = bgr15 >> 5 & 0x1F; const unsigned b = bgr15 >> 10 & 0x1F; return (((r * 13 + g * 2 + b + 8) << 7) & 0xF800) | ((g * 3 + b + 1) >> 1) << 5 | ((r * 3 + g * 2 + b * 11 + 8) >> 4); #else const unsigned r = bgr15 & 0x1F; const unsigned g = bgr15 >> 5 & 0x1F; const unsigned b = bgr15 >> 10 & 0x1F; return ((r * 13 + g * 2 + b) >> 1) << 16 | (g * 3 + b) << 9 | (r * 3 + g * 2 + b * 11) >> 1; #endif } else { #ifdef VIDEO_RGB565 const unsigned r = bgr15 & 0x1F; const unsigned g = bgr15 >> 5 & 0x1F; const unsigned b = bgr15 >> 10 & 0x1F; return r<<11 | g<<6 | b; #else const unsigned r = bgr15 & 0x1F; const unsigned g = bgr15 >> 5 & 0x1F; const unsigned b = bgr15 >> 10 & 0x1F; return r<<16 | g<<8 | b; #endif } } } libgambatte/libretro/gbcpalettes.h000664 001750 001750 00000043074 12720365247 020465 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * sinamas@users.sourceforge.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include namespace { #define TO5BIT(c8) (((c8) * 0x1F * 2 + 0xFF) / (0xFF*2)) #define PACK15_1(rgb24) (TO5BIT((rgb24) & 0xFF) << 10 | TO5BIT((rgb24) >> 8 & 0xFF) << 5 | TO5BIT((rgb24) >> 16 & 0xFF)) #define PACK15_4(c0, c1, c2, c3) \ PACK15_1(c0), PACK15_1(c1), PACK15_1(c2), PACK15_1(c3) static const unsigned short p005[] = { PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000) }; static const unsigned short p006[] = { PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000) }; static const unsigned short p007[] = { PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000) }; static const unsigned short p008[] = { PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000), PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000), PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000) }; static const unsigned short p012[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000) }; static const unsigned short p013[] = { PACK15_4(0x000000, 0x008484, 0xFFDE00, 0xFFFFFF), PACK15_4(0x000000, 0x008484, 0xFFDE00, 0xFFFFFF), PACK15_4(0x000000, 0x008484, 0xFFDE00, 0xFFFFFF) }; static const unsigned short p016[] = { PACK15_4(0xFFFFFF, 0xA5A5A5, 0x525252, 0x000000), PACK15_4(0xFFFFFF, 0xA5A5A5, 0x525252, 0x000000), PACK15_4(0xFFFFFF, 0xA5A5A5, 0x525252, 0x000000) }; static const unsigned short p017[] = { PACK15_4(0xFFFFA5, 0xFF9494, 0x9494FF, 0x000000), PACK15_4(0xFFFFA5, 0xFF9494, 0x9494FF, 0x000000), PACK15_4(0xFFFFA5, 0xFF9494, 0x9494FF, 0x000000) }; static const unsigned short p01B[] = { PACK15_4(0xFFFFFF, 0xFFCE00, 0x9C6300, 0x000000), PACK15_4(0xFFFFFF, 0xFFCE00, 0x9C6300, 0x000000), PACK15_4(0xFFFFFF, 0xFFCE00, 0x9C6300, 0x000000) }; static const unsigned short p100[] = { PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000), PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000) }; static const unsigned short p10B[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; static const unsigned short p10D[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000) }; static const unsigned short p110[] = { PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p11C[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x0063C5, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x0063C5, 0x000000) }; static const unsigned short p20B[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p20C[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000) }; static const unsigned short p300[] = { PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000) }; static const unsigned short p304[] = { PACK15_4(0xFFFFFF, 0x7BFF00, 0xB57300, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p305[] = { PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p306[] = { PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p308[] = { PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000), PACK15_4(0xFF6352, 0xD60000, 0x630000, 0x000000), PACK15_4(0xFF6352, 0xD60000, 0x630000, 0x000000) }; static const unsigned short p30A[] = { PACK15_4(0xB5B5FF, 0xFFFF94, 0xAD5A42, 0x000000), PACK15_4(0x000000, 0xFFFFFF, 0xFF8484, 0x943A3A), PACK15_4(0x000000, 0xFFFFFF, 0xFF8484, 0x943A3A) }; static const unsigned short p30C[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000) }; static const unsigned short p30D[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p30E[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p30F[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; static const unsigned short p312[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; static const unsigned short p319[] = { PACK15_4(0xFFE6C5, 0xCE9C84, 0x846B29, 0x5A3108), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000) }; static const unsigned short p31C[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x0063C5, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p405[] = { PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF) }; static const unsigned short p406[] = { PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF ) }; static const unsigned short p407[] = { PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF) }; static const unsigned short p500[] = { PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF) }; static const unsigned short p501[] = { PACK15_4(0xFFFF9C, 0x94B5FF, 0x639473, 0x003A3A), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p502[] = { PACK15_4(0x6BFF00, 0xFFFFFF, 0xFF524A, 0x000000), PACK15_4(0xFFFFFF, 0xFFFFFF, 0x63A5FF, 0x0000FF), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000) }; static const unsigned short p503[] = { PACK15_4(0x52DE00, 0xFF8400, 0xFFFF00, 0xFFFFFF), PACK15_4(0xFFFFFF, 0xFFFFFF, 0x63A5FF, 0x0000FF), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; static const unsigned short p508[] = { PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000), PACK15_4(0xFF6352, 0xD60000, 0x630000, 0x000000), PACK15_4(0x0000FF, 0xFFFFFF, 0xFFFF7B, 0x0084FF) }; static const unsigned short p509[] = { PACK15_4(0xFFFFCE, 0x63EFEF, 0x9C8431, 0x5A5A5A), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; static const unsigned short p50B[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFFFF7B, 0x0084FF, 0xFF0000) }; static const unsigned short p50C[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF) }; static const unsigned short p50D[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000) }; static const unsigned short p50E[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; static const unsigned short p50F[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; static const unsigned short p510[] = { PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; static const unsigned short p511[] = { PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x00FF00, 0x318400, 0x004A00), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; static const unsigned short p512[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; static const unsigned short p514[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFF00, 0xFF0000, 0x630000, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; static const unsigned short p515[] = { PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; static const unsigned short p518[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; static const unsigned short p51A[] = { PACK15_4(0xFFFFFF, 0xFFFF00, 0x7B4A00, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; static const unsigned short p51C[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x0063C5, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; // Extra palettes static const unsigned short pExt1[] = { PACK15_4(0xE5EA93, 0xC4C641, 0x5E7C39, 0x21442A), PACK15_4(0xE5EA93, 0xC4C641, 0x5E7C39, 0x21442A), PACK15_4(0xE5EA93, 0xC4C641, 0x5E7C39, 0x21442A) }; static const unsigned short pExt2[] = { PACK15_4(0xF8F8F8, 0x83C656, 0x187890, 0x000000), PACK15_4(0xF8F8F8, 0xE18096, 0x7F3848, 0x000000), PACK15_4(0xF8F8F8, 0xFFDA03, 0x958401, 0x000000) }; static const unsigned short pExt3[] = { PACK15_4(0xF8F8F8, 0xA59E8C, 0x49726C, 0x000000), PACK15_4(0xF8F8F8, 0xE49685, 0x6E241E, 0x000000), PACK15_4(0xF8F8F8, 0xD7543C, 0x7D3023, 0x000000) }; #undef PACK15_4 #undef PACK15_1 #undef TO5BIT struct GbcPaletteEntry { const char *title; const unsigned short *p; }; static const GbcPaletteEntry gbcDirPalettes[] = { { "GBC - Blue", p518 }, { "GBC - Brown", p012 }, { "GBC - Dark Blue", p50D }, { "GBC - Dark Brown", p319 }, { "GBC - Dark Green", p31C }, { "GBC - Grayscale", p016 }, { "GBC - Green", p005 }, { "GBC - Inverted", p013 }, { "GBC - Orange", p007 }, { "GBC - Pastel Mix", p017 }, { "GBC - Red", p510 }, { "GBC - Yellow", p51A }, { "Special 1", pExt1 }, { "Special 2", pExt2 }, { "Special 3", pExt3 }, }; static const GbcPaletteEntry gbcTitlePalettes[] = { { "ALLEY WAY", p008 }, { "ASTEROIDS/MISCMD", p30E }, { "ATOMIC PUNK", p30F }, // unofficial ("DYNABLASTER" alt.) { "BA.TOSHINDEN", p50F }, { "BALLOON KID", p006 }, { "BASEBALL", p503 }, { "BOMBERMAN GB", p31C }, // unofficial ("WARIO BLAST" alt.) { "BOY AND BLOB GB1", p512 }, { "BOY AND BLOB GB2", p512 }, { "BT2RAGNAROKWORLD", p312 }, { "DEFENDER/JOUST", p50F }, { "DMG FOOTBALL", p30E }, { "DONKEY KONG", p306 }, { "DONKEYKONGLAND", p50C }, { "DONKEYKONGLAND 2", p50C }, { "DONKEYKONGLAND 3", p50C }, { "DONKEYKONGLAND95", p501 }, { "DR.MARIO", p20B }, { "DYNABLASTER", p30F }, { "F1RACE", p012 }, { "FOOTBALL INT'L", p502 }, // unofficial ("SOCCER" alt.) { "G&W GALLERY", p304 }, { "GALAGA&GALAXIAN", p013 }, { "GAME&WATCH", p012 }, { "GAMEBOY GALLERY", p304 }, { "GAMEBOY GALLERY2", p304 }, { "GBWARS", p500 }, { "GBWARST", p500 }, // unofficial ("GBWARS" alt.) { "GOLF", p30E }, { "Game and Watch 2", p304 }, { "HOSHINOKA-BI", p508 }, { "JAMES BOND 007", p11C }, { "KAERUNOTAMENI", p10D }, { "KEN GRIFFEY JR", p31C }, { "KID ICARUS", p30D }, { "KILLERINSTINCT95", p50D }, { "KINGOFTHEZOO", p30F }, { "KIRAKIRA KIDS", p012 }, { "KIRBY BLOCKBALL", p508 }, { "KIRBY DREAM LAND", p508 }, { "KIRBY'S PINBALL", p308 }, { "KIRBY2", p508 }, { "LOLO2", p50F }, { "MAGNETIC SOCCER", p50E }, { "MANSELL", p012 }, { "MARIO & YOSHI", p305 }, { "MARIO'S PICROSS", p012 }, { "MARIOLAND2", p509 }, { "MEGA MAN 2", p50F }, { "MEGAMAN", p50F }, { "MEGAMAN3", p50F }, { "METROID2", p514 }, { "MILLI/CENTI/PEDE", p31C }, { "MOGURANYA", p300 }, { "MYSTIC QUEST", p50E }, { "NETTOU KOF 95", p50F }, { "NEW CHESSMASTER", p30F }, { "OTHELLO", p50E }, { "PAC-IN-TIME", p51C }, { "PENGUIN WARS", p30F }, // unofficial ("KINGOFTHEZOO" alt.) { "PENGUINKUNWARSVS", p30F }, // unofficial ("KINGOFTHEZOO" alt.) { "PICROSS 2", p012 }, { "PINOCCHIO", p20C }, { "POKEBOM", p30C }, { "POKEMON BLUE", p10B }, { "POKEMON GREEN", p11C }, { "POKEMON RED", p110 }, { "POKEMON YELLOW", p007 }, { "QIX", p407 }, { "RADARMISSION", p100 }, { "ROCKMAN WORLD", p50F }, { "ROCKMAN WORLD2", p50F }, { "ROCKMANWORLD3", p50F }, { "SEIKEN DENSETSU", p50E }, { "SOCCER", p502 }, { "SOLARSTRIKER", p013 }, { "SPACE INVADERS", p013 }, { "STAR STACKER", p012 }, { "STAR WARS", p512 }, { "STAR WARS-NOA", p512 }, { "STREET FIGHTER 2", p50F }, { "SUPER BOMBLISS ", p006 }, // unofficial ("TETRIS BLAST" alt.) { "SUPER MARIOLAND", p30A }, { "SUPER RC PRO-AM", p50F }, { "SUPERDONKEYKONG", p501 }, { "SUPERMARIOLAND3", p500 }, { "TENNIS", p502 }, { "TETRIS", p007 }, { "TETRIS ATTACK", p405 }, { "TETRIS BLAST", p006 }, { "TETRIS FLASH", p407 }, { "TETRIS PLUS", p31C }, { "TETRIS2", p407 }, { "THE CHESSMASTER", p30F }, { "TOPRANKINGTENNIS", p502 }, { "TOPRANKTENNIS", p502 }, { "TOY STORY", p30E }, //{ "TRIP WORLD", p500 }, // unofficial { "VEGAS STAKES", p50E }, { "WARIO BLAST", p31C }, { "WARIOLAND2", p515 }, { "WAVERACE", p50B }, { "WORLD CUP", p30E }, { "X", p016 }, { "YAKUMAN", p012 }, { "YOSHI'S COOKIE", p406 }, { "YOSSY NO COOKIE", p406 }, { "YOSSY NO PANEPON", p405 }, { "YOSSY NO TAMAGO", p305 }, { "ZELDA", p511 }, }; static inline std::size_t gbcDirPalettesSize() { return (sizeof gbcDirPalettes) / (sizeof gbcDirPalettes[0]); } static inline const struct GbcPaletteEntry * gbcDirPalettesEnd() { return gbcDirPalettes + gbcDirPalettesSize(); } static inline std::size_t gbcTitlePalettesSize() { return (sizeof gbcTitlePalettes) / (sizeof gbcTitlePalettes[0]); } static inline const struct GbcPaletteEntry * gbcTitlePalettesEnd() { return gbcTitlePalettes + gbcTitlePalettesSize(); } struct GbcPaletteEntryLess { bool operator()(const GbcPaletteEntry &lhs, const char *const rhstitle) const { return std::strcmp(lhs.title, rhstitle) < 0; } }; static const unsigned short * findGbcDirPal(const char *const title) { const GbcPaletteEntry *const r = std::lower_bound(gbcDirPalettes, gbcDirPalettesEnd(), title, GbcPaletteEntryLess()); return r < gbcDirPalettesEnd() && !std::strcmp(r->title, title) ? r->p : 0; } static const unsigned short * findGbcTitlePal(const char *const title) { const GbcPaletteEntry *const r = std::lower_bound(gbcTitlePalettes, gbcTitlePalettesEnd(), title, GbcPaletteEntryLess()); return r < gbcTitlePalettesEnd() && !std::strcmp(r->title, title) ? r->p : 0; } static const unsigned short * findGbcPal(const char *const title) { if (const unsigned short *const pal = findGbcDirPal(title)) return pal; return findGbcTitlePal(title); } } libgambatte/src/video/ppu.h000664 001750 001750 00000010715 12720365247 017043 0ustar00sergiosergio000000 000000 // // Copyright (C) 2010 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef PPU_H #define PPU_H #include "lcddef.h" #include "ly_counter.h" #include "sprite_mapper.h" #include "gbint.h" #include "gambatte.h" #include namespace gambatte { class PPUFrameBuf { public: PPUFrameBuf() : buf_(0), fbline_(nullfbline()), pitch_(0) {} video_pixel_t * fb() const { return buf_; } video_pixel_t * fbline() const { return fbline_; } std::ptrdiff_t pitch() const { return pitch_; } void setBuf(video_pixel_t *buf, std::ptrdiff_t pitch) { buf_ = buf; pitch_ = pitch; fbline_ = nullfbline(); } void setFbline(unsigned ly) { fbline_ = buf_ ? buf_ + std::ptrdiff_t(ly) * pitch_ : nullfbline(); } private: video_pixel_t *buf_; video_pixel_t *fbline_; std::ptrdiff_t pitch_; static video_pixel_t * nullfbline() { static video_pixel_t nullfbline_[160]; return nullfbline_; } }; struct PPUPriv; struct PPUState { void (*f)(PPUPriv &v); unsigned (*predictCyclesUntilXpos_f)(PPUPriv const &v, int targetxpos, unsigned cycles); unsigned char id; }; struct PPUPriv { video_pixel_t bgPalette[8 * 4]; video_pixel_t spPalette[8 * 4]; struct Sprite { unsigned char spx, oampos, line, attrib; } spriteList[11]; unsigned short spwordList[11]; unsigned char nextSprite; unsigned char currentSprite; unsigned char const *vram; PPUState const *nextCallPtr; unsigned long now; unsigned long lastM0Time; long cycles; unsigned tileword; unsigned ntileword; SpriteMapper spriteMapper; LyCounter lyCounter; PPUFrameBuf framebuf; unsigned char lcdc; unsigned char scy; unsigned char scx; unsigned char wy; unsigned char wy2; unsigned char wx; unsigned char winDrawState; unsigned char wscx; unsigned char winYPos; unsigned char reg0; unsigned char reg1; unsigned char attrib; unsigned char nattrib; unsigned char xpos; unsigned char endx; bool cgb; bool weMaster; PPUPriv(NextM0Time &nextM0Time, unsigned char const *oamram, unsigned char const *vram); }; class PPU { public: PPU(NextM0Time &nextM0Time, unsigned char const *oamram, unsigned char const *vram) : p_(nextM0Time, oamram, vram) { } video_pixel_t * bgPalette() { return p_.bgPalette; } bool cgb() const { return p_.cgb; } void doLyCountEvent() { p_.lyCounter.doEvent(); } unsigned long doSpriteMapEvent(unsigned long time) { return p_.spriteMapper.doEvent(time); } PPUFrameBuf const & frameBuf() const { return p_.framebuf; } bool inactivePeriodAfterDisplayEnable(unsigned long cc) const { return p_.spriteMapper.inactivePeriodAfterDisplayEnable(cc); } unsigned long lastM0Time() const { return p_.lastM0Time; } unsigned lcdc() const { return p_.lcdc; } void loadState(SaveState const &state, unsigned char const *oamram); LyCounter const & lyCounter() const { return p_.lyCounter; } unsigned long now() const { return p_.now; } void oamChange(unsigned long cc) { p_.spriteMapper.oamChange(cc); } void oamChange(unsigned char const *oamram, unsigned long cc) { p_.spriteMapper.oamChange(oamram, cc); } unsigned long predictedNextXposTime(unsigned xpos) const; void reset(unsigned char const *oamram, unsigned char const *vram, bool cgb); void resetCc(unsigned long oldCc, unsigned long newCc); void saveState(SaveState &ss) const; void setFrameBuf(video_pixel_t *buf, std::ptrdiff_t pitch) { p_.framebuf.setBuf(buf, pitch); } void setLcdc(unsigned lcdc, unsigned long cc); void setScx(unsigned scx) { p_.scx = scx; } void setScy(unsigned scy) { p_.scy = scy; } void setStatePtrs(SaveState &ss) { p_.spriteMapper.setStatePtrs(ss); } void setWx(unsigned wx) { p_.wx = wx; } void setWy(unsigned wy) { p_.wy = wy; } void updateWy2() { p_.wy2 = p_.wy; } void speedChange(unsigned long cycleCounter); video_pixel_t * spPalette() { return p_.spPalette; } void update(unsigned long cc); private: PPUPriv p_; }; } #endif changelog000664 001750 001750 00000064611 12720365247 013574 0ustar00sergiosergio000000 000000 -- 0.4.1 -- 2009-01-10 libgambatte: - Fix HqXx filter pitch. - Fix mbc2 not getting a rambank. - Make sure to reset passed pointers when deleted. Fixes potential crash when loading ROM during OAM busy. common: - Substantially improved rate estimation averaging. - RateEst: Add a convenient way of filtering measures that extend beyond a buffer time, and are as such probably invalid. - RateEst: Allow using a custom timestamp in feed(). - RateEst: Keep a queue of the last ~100 msec worth of samples and duration, and filter out collective samples that give a pre-estimate that seems way off. - Replace "Game Boy / Game Boy Color emulator" with "Game Boy Color emulator" for now to avoid misleading anyone on the current status. gambatte_qt: - Disable BlitterWidget updates (paintEvents) while not paused. - QGLBlitter: Do a cheap front blit rather than a vsynced flip if audio buffers are low. - Allow BlitterWidgets to opt in to get paintEvents while unpaused. Do so for QGLBlitter since it may need to clear buffers afterwards. - QGLBlitter: Try to blit right after sync in the case of single buffering. - Up default audio buffer latency to 100 ms (some common system audio servers require a lot of buffering to work well). - Adaptively skip BlitterWidget syncs if audio buffer is low, in a manner that should minimize wasted skips in sync to vblank situation, and tries to be non-disturbing. This replaces frame time halving, and blitter specific rescueing. - Clear display buffers in DirectDrawBlitter and Direct3DBlitter in exclusive mode, since blits don't necessarily cover the entire buffers. - DirectDrawBlitter: Make sure that a minimum amount of time has passed between calls to WaitForVerticalBlank, since it can return in the same vblank period twice on a fast system. - DirectDrawBlitter: Support vsync for refresh rate ~= 2x frame rate. - DirectDrawBlitter: Refactor somewhat and get rid of a couple minor potential bugs. - DirectDrawBlitter: Some tweaks to get updates closer to sync time in certain situations. - DirectDrawBlitter: Some tweaks to better support DONOTWAIT. - DirectDrawBlitter: Make only updating during vblank while page flipping optional. - Direct3DBlitter: Some tweaks to get updates closer to sync time in certain situations. - Filter out very short frame times in frame time estimation. - Don't adjust frame time during turbo, but rather skip BlitterWidget syncs to speed up, which avoids vsync limits without disabling vsync. - DirectDrawBlitter: Add triple buffering option. - Direct3DBlitter: Use D3DSWAPEFFECT_DISCARD in non-exclusive mode. - Direct3DBlitter: Allow triple buffering and vblank-only updates in non-excusive mode. - Rename "Page flipping" in Direct3D and DirectDraw blitters to "Exclusive full screen". - Pause audio on win32 titlebar clicks/drags to avoid looping audio due to underruns from blocked timerEvents. - Use wildcards for platform detection to avoid being unnecessarily compiler/architecture specific. Fixes bug 2377772. - Rewrite most of DirectSoundEngine, supporting primary buffer option, making it more robust, correct and hopefully cleaner. Only use part of the primary buffer if the desired buffer size is lower than the primary buffer size. - Direct3DBlitter and DirectDrawBlitter: Force blocking updates when sync to vblank is enabled. Some updates only block if there's a prior unfinished update in progress. This screws up frame time estimation in turn screwing up vsync. To fix this we do a double update (and extra blit) if close to a frame time period has passed since the last update when sync to vblank is enabled. I really should have noticed this earlier as it pretty much breaks vsync adaption completely. - Direct3DBlitter: Use the D3DCREATE_FPU_PRESERVE flag when creating device. Omitting this flag can screw up floating point calculations in other parts of the code. For instance WASAPI cursor timestamps get utterly screwed up here. - Direct3DBlitter: It appears that managed textures are updated before they are unlocked, which screws up redraws, making things appear choppy in some situations. Use a default memory texture and a system memory texture and the UpdateTexure method instead. - DirectSoundEngine: Make use of the sample period limit feature of RateEst, rather than duplicating the feature. - Add polling WASAPI engine with exclusive mode support. Latency and rate estimation is generally better than DirectSound, and in exclusive mode there is less blocking as well as exclusive mode being better than shared mode in the other areas too. - WasapiEngine: Add device selection. - WasapiEngine: Add static isUsable() method. Only listed if isUsable(). Default engine if isUsable(). - WasapiEngine: Use default device if there's only one device available, since we don't show the combobox anyway. - DirectSoundEngine: Provide the integrated read and status get write method optimization. - XvBlitter: Set NosystemBackground attribute rather than OpaquePaintEvent. Reimplement paintEngine to return NULL as suggested by Qt docs. - X11Blitter: Reimplement paintEngine to return NULL. - AlsaEngine: Make use of sample period limit feature of RateEst. Don't increase estimated sample rate on underrun. - OssEngine: Make use of sample period limit feature of RateEst. Don't increase estimated sample rate on underrun. - Esc exits fullscreen on macx. - Drop OpenAL from default macx binary. - Add some useful but commented build flags for macx to .pro files. -- 0.4.0 -- 2008-10-27 libgambatte: - less fixed-width type dependencies. don't assume unsigned int > 16 bits - slightly faster sprite mapping - Skip potential high frequency events when they don't matter. - do sprite sorting and cycle calculations pr line as needed instead of all at once - fix broken volume on/off event notification - less int > 16-bits assumptions - more type width dependency fixes - int width deps. Gambatte namespace - wx affects sprite m3 cycles - cache m3 cycles, related refactoring - readjust cgb dma cycles to previously changed m3 timing - clean up goofy lyc calculation. - cgb dma from various areas results in 0xFF being written. - 0xFEA0-0xFEFF not writable when OAM isn't - unusable ioram bits fixes - dmg ioram startup state fixes. - various oamdma accuracy - oamdma bus conflicts with cpu, ppu, cgbdma. - rewritten memory read/write methods. - accurate timing of ppu sprite mapping reads. - fix recent cgb sprite cycles sorting slip up. - preoffset mem pointers. - get rid of unused memory. - save state infrastructure, - clean up video timing code, - use save state for initialization and reset, - do color conversion outside filters - fast rgb32ToUyvy, - add overlooked oamdma event, - adjust subcycle irq timing (shouldn't affect anything), - various refactoring - save savedata before loading state - fix silly initstate ifreg regression - save state selection - save state osd preview snapshots - fix a few potential security holes when loading invalid state - get rid of some undefined behaviour in statesaver - always draw in rgb32, color convert afterwards, too bad for maemo/16-bit depth users - get rid of silly c string stuff - add bitmap font rendering with font based on Bitstream Vera Sans - osd state n saved/loaded text - empty state osd thumbs marked with "Empty" text - adjust thumbnail interpolation weighing slightly - utilize templates for more flexible osd text printing - use grey osd text with black outline for save/load state messages - move state 0 OSD pos to rightmost to match kbd layout - state 1 default on ROM load - support external save state files - missing includes - missing virtual destructor - std::ifstream construction missing binary flag - fix gcc-4.3 compilation - avoid signed overflow in constant (which is both undefined and likely to cause problems on architectures where sizeof(long) != sizeof(int)) in rgb2yuv code. - Fix wrong pitch passed to filter if color conversion is needed. - Fix potential problem with rgb32ToUyvy cache init values on 16-bit systems - Correct unhalttime when resetting counters. Fixes perodic infinite halt issue in Kirby's Star Stacker and probably other games. - Fix LY display disable regression - Use deltas and a running sum to decrease buffer writes in sound emulation sample generation. - Rearrange sound emulation event loop to optimize for high-frequency event units. - Initialize palette arrays to avoid valgrind noise. - Don't do resampling in libgambatte. Update API to reflect this. - No rambanks for ROMs that don't request any. - Route invalid rombank addresses in non-power-of-2 number of rombanks cases to disabled area assuming ceiled power of 2 address bus. - no sprites or sprite mapping busy cycles on first line after display enable. slight cleanup. - small oam accessibility correction. - Tile loading and tile rendering can seemingly get out of sync when modifying scx at a critical time. Another pessimation with little gain in the name of accuracy. - Use a look-up table to do tile byte merging. - Append "_dmg" to save base name when forcing DMG mode, to avoid corrupting CGB save files and vice versa. - saner ly write behaviour - Add adapted and optimized hq3x. - Revert to big f'ing switch hq2x code, as there's less duplication now. Also optimized interpolation functions further. No idea how I missed that initially. - Lower opacity OSD text. gambatte_sdl: - less retarded indenting - saner placement of fill_buffer function - int width deps. Gambatte namespace - Scalebuffer dstpitch aware. - save state selection - add number key slot selection shortcuts - Estimate actual output sample rate in terms of OS timers and derive frame rate from it. - Move AudioData and RingBuffer classes to separate files. - Make underruns slightly less painful, by resetting buffer positions. - Skip resampling when fast-forwarding - Fill available buffer space before waiting for more. - Audio buffer command line options. - Use half video frame sleep time if audio buffer is close to underrun. - Adjust estimated frame time each frame. gambatte_qt: - more likely to build on mac os x - Fix fixed window size issues with various window managers (metacity, xfwm4...) - macx build fixes - hopefully fix opengl clearing issues - Gambatte namespace - Decouple Qt GUI from gambatte. - Lots of cleanups, flexibility added - setting of various properties, frame time, aspect ratio, button events, video sources, sample rates, pauseOnDialogExec, custom menus etc. - Document some interfaces. - Support for setting approximate sound buffer latency. - Use rational math for 100% exact timers (even though the actual system timers are unlikely to be accurate). - Add fast-forward to input settings. - timeGetTime() fallback for win32 - Store full screen mode values/text rather than less reliable indexes. - Repaint on xvblitter port changes to avoid color key not getting repainted. - improved ALSA buffer reporting - add sampleRate info to MediaSource::setSampleBuffer. - clarify that "samples" refers to stereo samples - fix 24-bit depth non-shm ximage creation - fix blittercontainer incorrectly using minimumSize for integer scaling - add unrestricted fast bilinear and nearest neighbor sw scaling to x11/qpainter blitter - swscale: remove forgotten static qualifiers - swscale: center linear weighing bias - swscale: exclude iostream - swscale: less bloated - macx fixed/variable window size change issue fixed - macx opengl drawbuffer change issues worked around - add openal engine, default on macx - add macx quartz video mode toggler - multi-head infrastructure - support multiple monitors in macx quartz toggler - more work-arounds for Qt failing to set correct geometry on video mode changes. - more explicit fast-forward button handling, to avoid missed key press/release events on macx - opengl doublebuffer preblitting, try to make actual screen updates as close to right after sync wait is over as possible - add xf86vidmode toggler (xrandrtoggler is default) - x11blitter: check for other supported visuals if the default is unsupported. - temporarily return to original video mode and minimize on full screen alt-tab (except on macx or if there are multiple screens), switch back on focus-in - hide mouse cursor after move timeout, or key/joystick pressed (more sane on macx) - exit fullscreen rather than toggle menubar on macx (note that the menubar will automatically pop-up on macx full screen if the mouse is moved to the top of the primary screen) - add (independent) pause counter for non-client pauses. - reset X11 screen saver on joystick activity - change "turbo"-mode to temporarily set frametime as a way of avoiding vsync issues (for a laugh, check out the video dialog while in fast-forward mode and see "Sync to vertical blank in 65535 and 131070 Hz modes"). - fix win32 compilation - refix win32 fullscreen geometry correction - neater win32 BlitterWidget::sync - avoid misleading minimize on fullscreen close - refactor Blitterwidget::sync - directdrawblitter: remove unecessary turbo conditions - gditoggler: add multi-monitor support (win32) - videodialog: save actual hz values for real this time - quartztoggler: avoid potentially reverting to the wrong mode on double setFullMode(false) in multi-head configs - make sure window is within screen after mode change, so Qt doesn't reset it to the primary screen - revert to previous win32 fullscreen geometry correction behaviour so that the geometry gets properly reset after fullscreen - Add directdraw device selection. - directsoundengine: add device selection. - directdrawblitter: only list devices if there are more than 2 devices (including primary) - directdrawblitter: use private static member rather than global friend enumeration callback - capitalization changes - add direct3d9 blitter with support for vsync, bf, page flipping, triple buffering, device selection, multi-head etc. d3d9.dll loaded at runtime - more strict and thorough exclusive mode handling to support d3d fullscreen - work around file open dialog not returning focus properly - gditoggler: use current registry settings for return modes - directsoundengine: set DSBCAPS_GETCURRENTPOSITION2 flag - revert bad macx return from fullscreen on menu-toggle - don't build xf86vidmodetoggler by default - add save state actions to GUI menu - clean up GUI menu creation code - move GUI recent files to submenu - support external save state files - add number key slot selection shortcuts - missing includes - missing virtual destructor - make sure windows path arguments don't use backslashes by using QFileInfo - add Play menu with Pause, Frame Step, Dec/Inc/Reset Frame Rate - Add tab support to input settings dialog. - Add alternate key support to input settings dialog. - Auto-focus to next likely input box after settings key in input dialog. - Add "Play" and "State" input settings dialog tabs. - Avoid using the most convenient keys as forced menu short-cuts, set them as default keys in input settings dialog instead. This unfortunately makes the more useful shortcuts less visible, but it allows remapping the most convenient keyboard keys. - Avoid duplicate joystick axis "press" events by keeping a map of axis states. - Make sure to discard irrelevant/old joystick events. - Don't give MediaSource button events when stopped. - Allow joystick-based button events while paused by using a very low-frequency poll timer. - Make some of the joystick event wrapping stuff less messy. - missing string include - use QString for videoSourceLabel passed to MainWindow constructor - store currently selected scheme as string, since it appears ModelIndex is neither tied to the data it points to nor invalidated by changes. enforce valid state on reject since the list of schemes may have changed. - Direct3DCreate function pointer typedef needs WINAPI macro - disable page flipping dependent checkboxes in constructor to ensure correct start state - add custom sample rate support - change default buffer latency to 67 ms - don't auto-repeat buttons bound to keyboard - use enums for somewhat more robust gambattesource button setup - fix silly "alsa not using default device by default" bug - Only ask for xrandr config once to avoid potential server roundtrips in some xrandr versions. - Make sure xrandr version is >= 1.1 and < 2 - Prevent all text editing of input boxes. - Add custom context menu to input boxes. - Update AudioEngine to support sample rate estimation in terms of OS timers. - Implement sample rate estimation in ALSA and OSS audio engines. - AlsaEngine: Revert to using snd_pcm_avail_update for buffer status since snd_pcm_delay may consider external latencies. - AlsaEngine: Use snd_pcm_hw_params_set_buffer_time_near. Don't request a particular number of periods per buffer. - AlsaEngine: Use hw as default custom device string, rather than hw:0,0. - OssEngine: Don't trust GETOSPACE fragment info. - Estimate optimal frame rate based on sample rate estimations. - Extend BlitterWidget to support estimation of vsynced frame rate in terms of OS timers. - Implement vsync frame rate estimation in QGlBlitter, Direct3DBlitter and DirectDrawBlitter. - Use a combination of OS timer sample rate estimation and vsync frame rate estimation to derive resampling ratio for no-frame-duplication vsync. - Change API to reflect MediaSources not being responsible for resampling. - Make sure to parent PaletteDialog list model, so it gets deleted properly. - Various refactoring, small changes and stuff I forgot. - limit vsync frame rate estimation deviation - More averaging in estimation code. - Stricter estimate deviation limit - Adjust estimated frame time each frame. - Use half frame time if audio buffer is close to underrun. - Provide combined audioengine write and status get, to avoid doing potentially expensive operations twice. Utilized in OSS and ALSA engines. - Saner vsync estimate variance protection. - allow dynamically setting samples per frame - Don't bother allowing sources the choice of which output sample rates are selecrable, as it's not really a per source thing at this point. If resampling avoidance is desired, then that should rather be a user option (to depend on the OS for resampling, which is mostly nonsensical for the Game Boy/NES/PSG-system case btw). - Move Qt media framework to a separate subdir - postpone buffered x11 blits to after sync. - Add support for XRandR 1.2 + multi-head - use crtc mode dimensions rather than crtc dimensions when discarding modes since crtc dimensions may be rotated - Fractional bits for intermediate rate estimation averages. - Add RateEst reset method. Initialize RateEst count to 1. - Less refresh rate estimation averaging. - Allow more refresh rate estimation deviation. - Return NULL paintEngine in windows blitters that use the PaintToScreen attribute. - Add checks for things not being initialized in DirectDraw-blitter and QPainterBlitter paintEvents. - Don't reparent blitters (mainly to make a bug in Qt 4.4.3 win less annoying, widgets that do internal reparenting are still affected). - Check for window position less than screen top-left after mode change, before full screen, to avoid Qt moving it to the primary screen. - Add rate estimation to DirectSound engine. - Better underrun detection in DirectSound engine. - Don't duplicate blitter pointer in mainwindow. - Use RateEst.reset rather than re-initing on pause. - Add CoreAudio engine with rate estimation and buffer status support. Default engine on Mac OS X. - 44100 Hz default sample rate on OS X, since OS X tends to resample everything to 44100 Hz. - Get rid of buffer status averaging in OpenAlEngine, since it makes assumptions on usage pattern that shouldn't be made. - Fix CoreAudio engine reporting buffer status in samples rather than frames. - Update SDL_Joystick to SDL-1.2 SVN. - #undef UNICODE in win32/SDL_mmjoystick.c to avoid joystick name mangling. - work around annoying random non-updating OpenGL on Mac OS X after full screen. common/other: - Fix GCC 4.3 warnings about people getting confused by operator precedence by adding parentheses. - Real-time, sophisticated resampling framework with several performance/quality profiles for dynamically generated windowed sinc and CIC chains based on analysis of fourier transforms and optimal cost equations. Fast 2-tap linear as a low quality alternative. - Move non-emulation common code to a common directory to avoid duplication. - Update front-ends to new libgambatte API. - Utilize resampling framework in front-ends. Selectable resamplers. - Improved adaptive sleep class that estimates oversleep. - Various refactoring, small changes and stuff I forgot. - Do per phase normalization to avoid dc fluctuations. - More averaging in estimation code. - Stricter estimate deviation limit - Fractional bits for intermediate rate estimation averages. - Add RateEst reset method. Initialize RateEst count to 1. - Extend ringbuffer.h to support resetting size, and move it to common dir since gambatte_qt/coreaudioengine uses it too now. - Add "force DMG mode" option. - Allow more rate estimation deviation. hwtests: - wx affects sprite m3 cycles. - cgb dma from various areas results in 0xFF being written. - add hwtests for oam dma - m3 cycles wo bg - more oamdma tests - various oamdma accuracy. oamdma bus conflicts with cpu, ppu, cgbdma. - accurate timing of ppu sprite mapping reads. -- 0.3.1 -- 2007-10-26 -- gambatte_qt: - Enable Joystick POV-Hat events. -- 0.3.0 -- 2007-10-26 -- libgambatte: - Fix adc/sbc and add_hl_rr hfc calc, sp_plus_n cf/hcf calc and daa thanks to blargg. - document HF2 better - Update sound core according to blargg's findings. - Improve resampling quality and performance. - Fix overlooked "add hl,sp" flag calculation. - fix initial endtime value - check for resampling ratio < 1 - Add support for DMG palette customization. gambatte_sdl: - use std::map for parser - Don't bother hashing. - Add input config support. - Add joystick support. - Fix horrid "turbo can affect emulation" bug. - Add sw and yuv overlay scaling. - Use cond/mutex for thread syncing, RAII, refactor. - add option for sample rate choice - Add option to list valid input keys - don't die if audio fails gambatte_qt: - no point in filter being non-static anymore - use std::map for input vectors - remove unused unusedBool - Fix horrid "turbo can affect emulation" bug. - remove some useless optimizations - auto_ptr love. - support joystick hat. - nicer input handling. - Add sound dialog. - Add custom dev choice for oss, alsa engines. - Use rgb if available for xv. - Get rid of BAD_MATCH warnings for setting non-existent xv attributes. - make subblitters private nested classes - add reset action - Add support for DMG palette customization. - Add global buffer option for dsound engine -- 0.2.0 -- 2007-09-05 -- libgambatte: - fix 64-bit compile and segfault. Thanks to Nach for noticing. - Add zip support. Thanks to Nach for contributing nice, clear code - fix sound ch4 frequency calculation - Several PPU reads timings depend on wx. Thanks to franpa for noticing the corrupt line in The LoZ: Oracle of Seasons. - remove unused doubleSpeed parameter from m3ExtraCycles call gambatte_sdl: - Thread safety, bigger sound buffer - Compile on more platforms. Thanks to Thristian for the find. - actually increment iterator so the loop makes some sense (parser.cpp) gambatte_qt: - fix 64-bit compile. Thanks to Nach. - better license info for x11getprocaddress.cpp - initial joystick support, mostly using SDL's joystick code (separated from the rest of SDL) - use binary search for gb inputs. all: - make sure to use std:: despite sloppy compilers allowing omission. Thanks to blargg for the reminder. - get rid of some valgrind warnings. Thanks to Nach for noticing. hwtests: - add tests for wx effects on PPU read timings. build: - add -Wextra to default compile flags doc: - mention optional zlib dependency - additions to thanks section -- 0.1.1 -- 2007-08-29 -- libgambatte: - fix integer overflow in color conversion to rgb16 - only accept valid filter indexes gambatte_sdl: - print version - print usage - support command line arguments. - add option for starting in full-screen - add option for using video filter gambatte_qt: - clean up obsolete includes. - directdraw: only use alpha if primary surface uses it. - add support for loading rom from porgam argument. - s/"a highly accurate"/"an accuracy-focused"/ in about box - gditoggler: fix unordered video mode listing build: - Support external CPPFLAGS - Use sdl-config doc: - fix silly wording in README about section - s/seperate/separate/ - s/Automake/Make/ - mention XShm dependency - mention sys/shm.h requirement - document key mapping better - s/"a highly accurate"/"an accuracy-focused"/ - add man pages libgambatte/src/video.h000664 001750 001750 00000021775 12720365247 016247 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef VIDEO_H #define VIDEO_H #include "interruptrequester.h" #include "video/lyc_irq.h" #include "video/m0_irq.h" #include "video/next_m0_time.h" #include "video/ppu.h" #include namespace gambatte { class VideoInterruptRequester { public: explicit VideoInterruptRequester(InterruptRequester &intreq) : intreq_(intreq) {} void flagHdmaReq() const { gambatte::flagHdmaReq(intreq_); } void flagIrq(const unsigned bit) const { intreq_.flagIrq(bit); } void setNextEventTime(const unsigned long time) const { intreq_.setEventTime(time); } private: InterruptRequester &intreq_; }; class LCD { public: LCD(const unsigned char *oamram, const unsigned char *vram_in, VideoInterruptRequester memEventRequester); void reset(const unsigned char *oamram, unsigned char const *vram, bool cgb); void setStatePtrs(SaveState &state); void saveState(SaveState &state) const; void loadState(const SaveState &state, const unsigned char *oamram); void setDmgPaletteColor(unsigned palNum, unsigned colorNum, video_pixel_t rgb32); void setVideoBuffer(video_pixel_t *videoBuf, int pitch); void dmgBgPaletteChange(const unsigned data, const unsigned long cycleCounter) { update(cycleCounter); bgpData_[0] = data; setDmgPalette(ppu_.bgPalette(), dmgColorsRgb32_, data); } void dmgSpPalette1Change(const unsigned data, const unsigned long cycleCounter) { update(cycleCounter); objpData_[0] = data; setDmgPalette(ppu_.spPalette(), dmgColorsRgb32_ + 4, data); } void dmgSpPalette2Change(const unsigned data, const unsigned long cycleCounter) { update(cycleCounter); objpData_[1] = data; setDmgPalette(ppu_.spPalette() + 4, dmgColorsRgb32_ + 8, data); } void cgbBgColorChange(unsigned index, const unsigned data, const unsigned long cycleCounter) { if (bgpData_[index] != data) doCgbBgColorChange(index, data, cycleCounter); } void cgbSpColorChange(unsigned index, const unsigned data, const unsigned long cycleCounter) { if (objpData_[index] != data) doCgbSpColorChange(index, data, cycleCounter); } unsigned cgbBgColorRead(const unsigned index, const unsigned long cycleCounter) { return (ppu_.cgb() & cgbpAccessible(cycleCounter)) ? bgpData_[index] : 0xFF; } unsigned cgbSpColorRead(const unsigned index, const unsigned long cycleCounter) { return (ppu_.cgb() & cgbpAccessible(cycleCounter)) ? objpData_[index] : 0xFF; } void updateScreen(bool blanklcd, unsigned long cc); void resetCc(unsigned long oldCC, unsigned long newCc); void speedChange(unsigned long cycleCounter); bool vramAccessible(unsigned long cycleCounter); bool oamReadable(unsigned long cycleCounter); bool oamWritable(unsigned long cycleCounter); void wxChange(unsigned newValue, unsigned long cycleCounter); void wyChange(unsigned newValue, unsigned long cycleCounter); void oamChange(unsigned long cycleCounter); void oamChange(const unsigned char *oamram, unsigned long cycleCounter); void scxChange(unsigned newScx, unsigned long cycleCounter); void scyChange(unsigned newValue, unsigned long cycleCounter); void vramChange(const unsigned long cycleCounter) { update(cycleCounter); } unsigned getStat(unsigned lycReg, unsigned long cycleCounter); unsigned getLyReg(const unsigned long cycleCounter) { unsigned lyReg = 0; if (ppu_.lcdc() & 0x80) { if (cycleCounter >= ppu_.lyCounter().time()) update(cycleCounter); lyReg = ppu_.lyCounter().ly(); if (lyReg == 153) { lyReg = 0; } else if (ppu_.lyCounter().time() - cycleCounter <= 4) ++lyReg; } return lyReg; } unsigned long nextMode1IrqTime() const { return eventTimes_(MODE1_IRQ); } void lcdcChange(unsigned data, unsigned long cycleCounter); void lcdstatChange(unsigned data, unsigned long cycleCounter); void lycRegChange(unsigned data, unsigned long cycleCounter); void enableHdma(unsigned long cycleCounter); void disableHdma(unsigned long cycleCounter); bool hdmaIsEnabled() const { return eventTimes_(HDMA_REQ) != disabled_time; } void update(unsigned long cycleCounter); bool isCgb() const { return ppu_.cgb(); } bool isDoubleSpeed() const { return ppu_.lyCounter().isDoubleSpeed(); } void setColorCorrection(bool colorCorrection); video_pixel_t gbcToRgb32(const unsigned bgr15); private: enum Event { MEM_EVENT, LY_COUNT }; enum { NUM_EVENTS = LY_COUNT + 1 }; enum MemEvent { ONESHOT_LCDSTATIRQ, ONESHOT_UPDATEWY2, MODE1_IRQ, LYC_IRQ, SPRITE_MAP, HDMA_REQ, MODE2_IRQ, MODE0_IRQ }; enum { NUM_MEM_EVENTS = MODE0_IRQ + 1 }; class EventTimes { public: explicit EventTimes(const VideoInterruptRequester memEventRequester) : memEventRequester_(memEventRequester) {} Event nextEvent() const { return static_cast(eventMin_.min()); } unsigned long nextEventTime() const { return eventMin_.minValue(); } unsigned long operator()(const Event e) const { return eventMin_.value(e); } template void set(const unsigned long time) { eventMin_.setValue(time); } void set(const Event e, const unsigned long time) { eventMin_.setValue(e, time); } MemEvent nextMemEvent() const { return static_cast(memEventMin_.min()); } unsigned long nextMemEventTime() const { return memEventMin_.minValue(); } unsigned long operator()(const MemEvent e) const { return memEventMin_.value(e); } template void setm(const unsigned long time) { memEventMin_.setValue(time); setMemEvent(); } void set(const MemEvent e, const unsigned long time) { memEventMin_.setValue(e, time); setMemEvent(); } void flagIrq(const unsigned bit) { memEventRequester_.flagIrq(bit); } void flagHdmaReq() { memEventRequester_.flagHdmaReq(); } private: MinKeeper eventMin_; MinKeeper memEventMin_; VideoInterruptRequester memEventRequester_; void setMemEvent() { const unsigned long nmet = nextMemEventTime(); eventMin_.setValue(nmet); memEventRequester_.setNextEventTime(nmet); } }; PPU ppu_; video_pixel_t dmgColorsRgb32_[3 * 4]; unsigned char bgpData_[8 * 8]; unsigned char objpData_[8 * 8]; EventTimes eventTimes_; M0Irq m0Irq_; LycIrq lycIrq_; NextM0Time nextM0Time_; unsigned char statReg_; unsigned char m2IrqStatReg_; unsigned char m1IrqStatReg_; static void setDmgPalette(video_pixel_t *palette, const video_pixel_t *dmgColors, unsigned data); void setDmgPaletteColor(unsigned index, video_pixel_t rgb32); void refreshPalettes(); void setDBuffer(); void doMode2IrqEvent(); void event(); unsigned long m0TimeOfCurrentLine(unsigned long cc); bool cgbpAccessible(unsigned long cycleCounter); void mode3CyclesChange(); void doCgbBgColorChange(unsigned index, unsigned data, unsigned long cycleCounter); void doCgbSpColorChange(unsigned index, unsigned data, unsigned long cycleCounter); bool colorCorrection; void doCgbColorChange(unsigned char *const pdata, video_pixel_t *const palette, unsigned index, const unsigned data); }; } #endif libgambatte/src/video/sprite_mapper.cpp000664 001750 001750 00000012132 12720365247 021437 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "sprite_mapper.h" #include "counterdef.h" #include "next_m0_time.h" #include "../insertion_sort.h" #include #include namespace { class SpxLess { public: explicit SpxLess(unsigned char const *spxlut) : spxlut_(spxlut) {} bool operator()(unsigned char lhs, unsigned char rhs) const { return spxlut_[lhs] < spxlut_[rhs]; } private: unsigned char const *const spxlut_; }; } namespace gambatte { SpriteMapper::OamReader::OamReader(LyCounter const &lyCounter, unsigned char const *oamram) : lyCounter_(lyCounter) , oamram_(oamram) , cgb_(false) { reset(oamram, false); } void SpriteMapper::OamReader::reset(unsigned char const *const oamram, bool const cgb) { oamram_ = oamram; cgb_ = cgb; setLargeSpritesSrc(false); lu_ = 0; lastChange_ = 0xFF; std::fill(szbuf_, szbuf_ + 40, largeSpritesSrc_); unsigned pos = 0; unsigned distance = 80; while (distance--) { buf_[pos] = oamram[((pos * 2) & ~3) | (pos & 1)]; ++pos; } } static unsigned toPosCycles(unsigned long const cc, LyCounter const &lyCounter) { unsigned lc = lyCounter.lineCycles(cc) + 3 - lyCounter.isDoubleSpeed() * 3u; if (lc >= 456) lc -= 456; return lc; } void SpriteMapper::OamReader::update(unsigned long const cc) { if (cc > lu_) { if (changed()) { unsigned const lulc = toPosCycles(lu_, lyCounter_); unsigned pos = std::min(lulc, 80u); unsigned distance = 80; if ((cc - lu_) >> lyCounter_.isDoubleSpeed() < 456) { unsigned cclc = toPosCycles(cc, lyCounter_); distance = std::min(cclc, 80u) - pos + (cclc < lulc ? 80 : 0); } { unsigned targetDistance = lastChange_ - pos + (lastChange_ <= pos ? 80 : 0); if (targetDistance <= distance) { distance = targetDistance; lastChange_ = 0xFF; } } while (distance--) { if (!(pos & 1)) { if (pos == 80) pos = 0; if (cgb_) szbuf_[pos >> 1] = largeSpritesSrc_; buf_[pos ] = oamram_[pos * 2 ]; buf_[pos + 1] = oamram_[pos * 2 + 1]; } else szbuf_[pos >> 1] = (szbuf_[pos >> 1] & cgb_) | largeSpritesSrc_; ++pos; } } lu_ = cc; } } void SpriteMapper::OamReader::change(unsigned long cc) { update(cc); lastChange_ = std::min(toPosCycles(lu_, lyCounter_), 80u); } void SpriteMapper::OamReader::setStatePtrs(SaveState &state) { state.ppu.oamReaderBuf.set(buf_, sizeof buf_); state.ppu.oamReaderSzbuf.set(szbuf_, sizeof szbuf_ / sizeof *szbuf_); } void SpriteMapper::OamReader::loadState(SaveState const &ss, unsigned char const *const oamram) { oamram_ = oamram; largeSpritesSrc_ = ss.mem.ioamhram.get()[0x140] >> 2 & 1; lu_ = ss.ppu.enableDisplayM0Time; change(lu_); } void SpriteMapper::OamReader::enableDisplay(unsigned long cc) { std::memset(buf_, 0x00, sizeof buf_); std::fill(szbuf_, szbuf_ + 40, false); lu_ = cc + (80 << lyCounter_.isDoubleSpeed()); lastChange_ = 80; } SpriteMapper::SpriteMapper(NextM0Time &nextM0Time, LyCounter const &lyCounter, unsigned char const *oamram) : nextM0Time_(nextM0Time) , oamReader_(lyCounter, oamram) { clearMap(); } void SpriteMapper::reset(unsigned char const *oamram, bool cgb) { oamReader_.reset(oamram, cgb); clearMap(); } void SpriteMapper::clearMap() { std::memset(num_, need_sorting_mask, sizeof num_); } void SpriteMapper::mapSprites() { clearMap(); for (unsigned i = 0x00; i < 0x50; i += 2) { int const spriteHeight = 8 << largeSprites(i >> 1); unsigned const bottomPos = posbuf()[i] - (17u - spriteHeight); if (bottomPos < 143u + spriteHeight) { unsigned const startly = std::max(int(bottomPos) + 1 - spriteHeight, 0); unsigned char *map = spritemap_ + startly * 10; unsigned char *n = num_ + startly; unsigned char *const nend = num_ + std::min(bottomPos, 143u) + 1; do { if (*n < need_sorting_mask + 10) map[(*n)++ - need_sorting_mask] = i; map += 10; } while (++n != nend); } } nextM0Time_.invalidatePredictedNextM0Time(); } void SpriteMapper::sortLine(unsigned const ly) const { num_[ly] &= ~need_sorting_mask; insertionSort(spritemap_ + ly * 10, spritemap_ + ly * 10 + num_[ly], SpxLess(posbuf() + 1)); } unsigned long SpriteMapper::doEvent(unsigned long const time) { oamReader_.update(time); mapSprites(); return oamReader_.changed() ? time + oamReader_.lineTime() : static_cast(disabled_time); } } libgambatte/libretro/jni/000700 001750 001750 00000000000 12720366137 016552 5ustar00sergiosergio000000 000000 libgambatte/src/sound/static_output_tester.h000664 001750 001750 00000002570 12720365247 022556 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef STATIC_OUTPUT_TESTER_H #define STATIC_OUTPUT_TESTER_H #include "envelope_unit.h" namespace gambatte { template class StaticOutputTester : public EnvelopeUnit::VolOnOffEvent { public: StaticOutputTester(Channel const &ch, Unit &unit) : ch_(ch), unit_(unit) {} void operator()(unsigned long cc); private: Channel const &ch_; Unit &unit_; }; template void StaticOutputTester::operator()(unsigned long cc) { if (ch_.soMask_ && ch_.master_ && ch_.envelopeUnit_.getVolume()) unit_.reviveCounter(cc); else unit_.killCounter(); } } #endif libgambatte/Makefile.common000664 001750 001750 00000002315 12720365247 017115 0ustar00sergiosergio000000 000000 INCFLAGS := -I$(CORE_DIR) -I$(CORE_DIR)/../include -I$(CORE_DIR)/../../common -I$(CORE_DIR)/../../common/resample -I$(CORE_DIR)/../libretro SOURCES_CXX := $(CORE_DIR)/cpu.cpp \ $(CORE_DIR)/gambatte.cpp \ $(CORE_DIR)/initstate.cpp \ $(CORE_DIR)/interrupter.cpp \ $(CORE_DIR)/interruptrequester.cpp \ $(CORE_DIR)/gambatte-memory.cpp \ $(CORE_DIR)/sound.cpp \ $(CORE_DIR)/statesaver.cpp \ $(CORE_DIR)/tima.cpp \ $(CORE_DIR)/video.cpp \ $(CORE_DIR)/video_libretro.cpp \ $(CORE_DIR)/mem/cartridge.cpp \ $(CORE_DIR)/mem/cartridge_libretro.cpp \ $(CORE_DIR)/mem/memptrs.cpp \ $(CORE_DIR)/mem/rtc.cpp \ $(CORE_DIR)/sound/channel1.cpp \ $(CORE_DIR)/sound/channel2.cpp \ $(CORE_DIR)/sound/channel3.cpp \ $(CORE_DIR)/sound/channel4.cpp \ $(CORE_DIR)/sound/duty_unit.cpp \ $(CORE_DIR)/sound/envelope_unit.cpp \ $(CORE_DIR)/sound/length_counter.cpp \ $(CORE_DIR)/video/ly_counter.cpp \ $(CORE_DIR)/video/lyc_irq.cpp \ $(CORE_DIR)/video/next_m0_time.cpp \ $(CORE_DIR)/video/ppu.cpp \ $(CORE_DIR)/video/sprite_mapper.cpp \ $(CORE_DIR)/../libretro/libretro.cpp SOURCES_C := $(CORE_DIR)/../libretro/blipper.c libgambatte/include/000700 001750 001750 00000000000 12720366137 015573 5ustar00sergiosergio000000 000000 libgambatte/src/video/ppu.cpp000664 001750 001750 00000153770 12720365247 017407 0ustar00sergiosergio000000 000000 // // Copyright (C) 2010 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include "ppu.h" #include "savestate.h" #include #include #include namespace { using namespace gambatte; #define PREP(u8) (((u8) << 7 & 0x80) | ((u8) << 5 & 0x40) | ((u8) << 3 & 0x20) | ((u8) << 1 & 0x10) \ | ((u8) >> 1 & 0x08) | ((u8) >> 3 & 0x04) | ((u8) >> 5 & 0x02) | ((u8) >> 7 & 0x01)) #define EXPAND(u8) ((PREP(u8) << 7 & 0x4000) | (PREP(u8) << 6 & 0x1000) \ | (PREP(u8) << 5 & 0x0400) | (PREP(u8) << 4 & 0x0100) \ | (PREP(u8) << 3 & 0x0040) | (PREP(u8) << 2 & 0x0010) \ | (PREP(u8) << 1 & 0x0004) | (PREP(u8) & 0x0001)) #define EXPAND_ROW(n) EXPAND((n)|0x0), EXPAND((n)|0x1), EXPAND((n)|0x2), EXPAND((n)|0x3), \ EXPAND((n)|0x4), EXPAND((n)|0x5), EXPAND((n)|0x6), EXPAND((n)|0x7), \ EXPAND((n)|0x8), EXPAND((n)|0x9), EXPAND((n)|0xA), EXPAND((n)|0xB), \ EXPAND((n)|0xC), EXPAND((n)|0xD), EXPAND((n)|0xE), EXPAND((n)|0xF) #define EXPAND_TABLE EXPAND_ROW(0x00), EXPAND_ROW(0x10), EXPAND_ROW(0x20), EXPAND_ROW(0x30), \ EXPAND_ROW(0x40), EXPAND_ROW(0x50), EXPAND_ROW(0x60), EXPAND_ROW(0x70), \ EXPAND_ROW(0x80), EXPAND_ROW(0x90), EXPAND_ROW(0xA0), EXPAND_ROW(0xB0), \ EXPAND_ROW(0xC0), EXPAND_ROW(0xD0), EXPAND_ROW(0xE0), EXPAND_ROW(0xF0) static unsigned short const expand_lut[0x200] = { EXPAND_TABLE, #undef PREP #define PREP(u8) (u8) EXPAND_TABLE }; #undef EXPAND_TABLE #undef EXPAND_ROW #undef EXPAND #undef PREP #define DECLARE_FUNC(n, id) \ enum { ID##n = id }; \ static void f##n (PPUPriv &); \ static unsigned predictCyclesUntilXpos_f##n (PPUPriv const &, int targetxpos, unsigned cycles); \ static PPUState const f##n##_ = { f##n, predictCyclesUntilXpos_f##n, ID##n } namespace M2_Ly0 { DECLARE_FUNC(0, 0); } namespace M2_LyNon0 { DECLARE_FUNC(0, 0); DECLARE_FUNC(1, 0); } namespace M3Start { DECLARE_FUNC(0, 0); DECLARE_FUNC(1, 0); } namespace M3Loop { namespace Tile { DECLARE_FUNC(0, 0x80); DECLARE_FUNC(1, 0x81); DECLARE_FUNC(2, 0x82); DECLARE_FUNC(3, 0x83); DECLARE_FUNC(4, 0x84); DECLARE_FUNC(5, 0x85); } namespace LoadSprites { DECLARE_FUNC(0, 0x88); DECLARE_FUNC(1, 0x89); DECLARE_FUNC(2, 0x8A); DECLARE_FUNC(3, 0x8B); DECLARE_FUNC(4, 0x8C); DECLARE_FUNC(5, 0x8D); } namespace StartWindowDraw { DECLARE_FUNC(0, 0x90); DECLARE_FUNC(1, 0x91); DECLARE_FUNC(2, 0x92); DECLARE_FUNC(3, 0x93); DECLARE_FUNC(4, 0x94); DECLARE_FUNC(5, 0x95); } } // namespace M3Loop #undef DECLARE_FUNC enum { win_draw_start = 1, win_draw_started = 2 }; enum { m2_ds_offset = 3 }; enum { max_m3start_cycles = 80 }; enum { attr_yflip = 0x40, attr_bgpriority = 0x80 }; static inline int lcdcEn( PPUPriv const &p) { return p.lcdc & lcdc_en; } static inline int lcdcWinEn(PPUPriv const &p) { return p.lcdc & lcdc_we; } static inline int lcdcObj2x(PPUPriv const &p) { return p.lcdc & lcdc_obj2x; } static inline int lcdcObjEn(PPUPriv const &p) { return p.lcdc & lcdc_objen; } static inline int lcdcBgEn( PPUPriv const &p) { return p.lcdc & lcdc_bgen; } static inline int weMasterCheckPriorToLyIncLineCycle(bool cgb) { return 450 - cgb; } static inline int weMasterCheckAfterLyIncLineCycle(bool cgb) { return 454 - cgb; } static inline int m3StartLineCycle(bool /*cgb*/) { return 83; } static inline void nextCall(int const cycles, PPUState const &state, PPUPriv &p) { int const c = p.cycles - cycles; if (c >= 0) { p.cycles = c; return state.f(p); } p.cycles = c; p.nextCallPtr = &state; } namespace M2_Ly0 { static void f0(PPUPriv &p) { p.weMaster = lcdcWinEn(p) && 0 == p.wy; p.winYPos = 0xFF; nextCall(m3StartLineCycle(p.cgb), M3Start::f0_, p); } } namespace M2_LyNon0 { static void f0(PPUPriv &p) { p.weMaster |= lcdcWinEn(p) && p.lyCounter.ly() == p.wy; nextCall( weMasterCheckAfterLyIncLineCycle(p.cgb) - weMasterCheckPriorToLyIncLineCycle(p.cgb), f1_, p); } static void f1(PPUPriv &p) { p.weMaster |= lcdcWinEn(p) && p.lyCounter.ly() + 1 == p.wy; nextCall(456 - weMasterCheckAfterLyIncLineCycle(p.cgb) + m3StartLineCycle(p.cgb), M3Start::f0_, p); } } static int loadTileDataByte0(PPUPriv const &p) { unsigned const yoffset = (p.winDrawState & win_draw_started) ? p.winYPos : p.scy + p.lyCounter.ly(); return p.vram[0x1000 + (p.nattrib << 10 & 0x2000) - ((p.reg1 * 32 | p.lcdc << 8) & 0x1000) + p.reg1 * 16 + ((-(p.nattrib >> 6 & 1) ^ yoffset) & 7) * 2]; } static int loadTileDataByte1(PPUPriv const &p) { unsigned const yoffset = (p.winDrawState & win_draw_started) ? p.winYPos : p.scy + p.lyCounter.ly(); return p.vram[0x1000 + (p.nattrib << 10 & 0x2000) - ((p.reg1 * 32 | p.lcdc << 8) & 0x1000) + p.reg1 * 16 + ((-(p.nattrib >> 6 & 1) ^ yoffset) & 7) * 2 + 1]; } namespace M3Start { static void f0(PPUPriv &p) { p.xpos = 0; if ((p.winDrawState & win_draw_start) && lcdcWinEn(p)) { p.winDrawState = win_draw_started; p.wscx = 8 + (p.scx & 7); ++p.winYPos; } else p.winDrawState = 0; p.nextCallPtr = &f1_; f1(p); } static void f1(PPUPriv &p) { while (p.xpos < max_m3start_cycles) { if ((p.xpos & 7) == (p.scx & 7)) break; switch (p.xpos & 7) { case 0: if (p.winDrawState & win_draw_started) { p.reg1 = p.vram[(p.lcdc << 4 & 0x400) + (p.winYPos & 0xF8) * 4 + (p.wscx >> 3 & 0x1F) + 0x1800]; p.nattrib = p.vram[(p.lcdc << 4 & 0x400) + (p.winYPos & 0xF8) * 4 + (p.wscx >> 3 & 0x1F) + 0x3800]; } else { p.reg1 = p.vram[((p.lcdc << 7 | p.scx >> 3) & 0x41F) + ((p.scy + p.lyCounter.ly()) & 0xF8) * 4 + 0x1800]; p.nattrib = p.vram[((p.lcdc << 7 | p.scx >> 3) & 0x41F) + ((p.scy + p.lyCounter.ly()) & 0xF8) * 4 + 0x3800]; } break; case 2: p.reg0 = loadTileDataByte0(p); break; case 4: { int const r1 = loadTileDataByte1(p); p.ntileword = (expand_lut + (p.nattrib << 3 & 0x100))[p.reg0] + (expand_lut + (p.nattrib << 3 & 0x100))[r1 ] * 2; } break; } ++p.xpos; if (--p.cycles < 0) return; } { unsigned const ly = p.lyCounter.ly(); unsigned const numSprites = p.spriteMapper.numSprites(ly); unsigned char const *const sprites = p.spriteMapper.sprites(ly); for (unsigned i = 0; i < numSprites; ++i) { unsigned pos = sprites[i]; unsigned spy = p.spriteMapper.posbuf()[pos ]; unsigned spx = p.spriteMapper.posbuf()[pos+1]; p.spriteList[i].spx = spx; p.spriteList[i].line = ly + 16u - spy; p.spriteList[i].oampos = pos * 2; p.spwordList[i] = 0; } p.spriteList[numSprites].spx = 0xFF; p.nextSprite = 0; } p.xpos = 0; p.endx = 8 - (p.scx & 7); static PPUState const *const flut[8] = { &M3Loop::Tile::f0_, &M3Loop::Tile::f1_, &M3Loop::Tile::f2_, &M3Loop::Tile::f3_, &M3Loop::Tile::f4_, &M3Loop::Tile::f5_, &M3Loop::Tile::f5_, &M3Loop::Tile::f5_ }; nextCall(1-p.cgb, *flut[p.scx & 7], p); } } namespace M3Loop { static void doFullTilesUnrolledDmg(PPUPriv &p, int const xend, video_pixel_t *const dbufline, unsigned char const *const tileMapLine, unsigned const tileline, unsigned tileMapXpos) { unsigned const tileIndexSign = ~p.lcdc << 3 & 0x80; unsigned char const *const tileDataLine = p.vram + tileIndexSign * 32 + tileline * 2; int xpos = p.xpos; do { int nextSprite = p.nextSprite; if (int(p.spriteList[nextSprite].spx) < xpos + 8) { int cycles = p.cycles - 8; if (lcdcObjEn(p)) { cycles -= std::max(11 - (int(p.spriteList[nextSprite].spx) - xpos), 6); for (unsigned i = nextSprite + 1; int(p.spriteList[i].spx) < xpos + 8; ++i) cycles -= 6; if (cycles < 0) break; p.cycles = cycles; do { unsigned char const *const oam = p.spriteMapper.oamram(); unsigned reg0, reg1 = oam[p.spriteList[nextSprite].oampos + 2] * 16; unsigned const attrib = oam[p.spriteList[nextSprite].oampos + 3]; unsigned const spline = ( (attrib & attr_yflip) ? p.spriteList[nextSprite].line ^ 15 : p.spriteList[nextSprite].line ) * 2; reg0 = p.vram[(lcdcObj2x(p) ? (reg1 & ~16) | spline : reg1 | (spline & ~16)) ]; reg1 = p.vram[(lcdcObj2x(p) ? (reg1 & ~16) | spline : reg1 | (spline & ~16)) + 1]; p.spwordList[nextSprite] = expand_lut[reg0 + (attrib << 3 & 0x100)] + expand_lut[reg1 + (attrib << 3 & 0x100)] * 2; p.spriteList[nextSprite].attrib = attrib; ++nextSprite; } while (int(p.spriteList[nextSprite].spx) < xpos + 8); } else { if (cycles < 0) break; p.cycles = cycles; do { ++nextSprite; } while (int(p.spriteList[nextSprite].spx) < xpos + 8); } p.nextSprite = nextSprite; } else if (nextSprite-1 < 0 || int(p.spriteList[nextSprite-1].spx) <= xpos - 8) { if (!(p.cycles & ~7)) break; int n = (( xend + 7 < int(p.spriteList[nextSprite].spx) ? xend + 7 : int(p.spriteList[nextSprite].spx)) - xpos) & ~7; n = (p.cycles & ~7) < n ? p.cycles & ~7 : n; p.cycles -= n; unsigned ntileword = p.ntileword; video_pixel_t * dst = dbufline + xpos - 8; video_pixel_t *const dstend = dst + n; xpos += n; if (!lcdcBgEn(p)) { do { *dst++ = p.bgPalette[0]; } while (dst != dstend); tileMapXpos += n >> 3; unsigned const tno = tileMapLine[(tileMapXpos - 1) & 0x1F]; ntileword = expand_lut[(tileDataLine + tno * 16 - (tno & tileIndexSign) * 32)[0]] + expand_lut[(tileDataLine + tno * 16 - (tno & tileIndexSign) * 32)[1]] * 2; } else do { dst[0] = p.bgPalette[ ntileword & 0x0003 ]; dst[1] = p.bgPalette[(ntileword & 0x000C) >> 2]; dst[2] = p.bgPalette[(ntileword & 0x0030) >> 4]; dst[3] = p.bgPalette[(ntileword & 0x00C0) >> 6]; dst[4] = p.bgPalette[(ntileword & 0x0300) >> 8]; dst[5] = p.bgPalette[(ntileword & 0x0C00) >> 10]; dst[6] = p.bgPalette[(ntileword & 0x3000) >> 12]; dst[7] = p.bgPalette[ ntileword >> 14]; dst += 8; unsigned const tno = tileMapLine[tileMapXpos & 0x1F]; tileMapXpos = (tileMapXpos & 0x1F) + 1; ntileword = expand_lut[(tileDataLine + tno * 16 - (tno & tileIndexSign) * 32)[0]] + expand_lut[(tileDataLine + tno * 16 - (tno & tileIndexSign) * 32)[1]] * 2; } while (dst != dstend); p.ntileword = ntileword; continue; } else { int cycles = p.cycles - 8; if (cycles < 0) break; p.cycles = cycles; } { video_pixel_t *const dst = dbufline + (xpos - 8); unsigned const tileword = -(p.lcdc & 1U) & p.ntileword; dst[0] = p.bgPalette[ tileword & 0x0003 ]; dst[1] = p.bgPalette[(tileword & 0x000C) >> 2]; dst[2] = p.bgPalette[(tileword & 0x0030) >> 4]; dst[3] = p.bgPalette[(tileword & 0x00C0) >> 6]; dst[4] = p.bgPalette[(tileword & 0x0300) >> 8]; dst[5] = p.bgPalette[(tileword & 0x0C00) >> 10]; dst[6] = p.bgPalette[(tileword & 0x3000) >> 12]; dst[7] = p.bgPalette[ tileword >> 14]; int i = nextSprite - 1; if (!lcdcObjEn(p)) { do { int pos = int(p.spriteList[i].spx) - xpos; p.spwordList[i] >>= pos * 2 >= 0 ? 16 - pos * 2 : 16 + pos * 2; --i; } while (i >= 0 && int(p.spriteList[i].spx) > xpos - 8); } else { do { int n; int pos = int(p.spriteList[i].spx) - xpos; if (pos < 0) { n = pos + 8; pos = 0; } else n = 8 - pos; unsigned const attrib = p.spriteList[i].attrib; unsigned spword = p.spwordList[i]; video_pixel_t const *const spPalette = p.spPalette + (attrib >> 2 & 4); video_pixel_t *d = dst + pos; if (!(attrib & attr_bgpriority)) { switch (n) { case 8: if (spword >> 14 ) { d[7] = spPalette[spword >> 14 ]; } case 7: if (spword >> 12 & 3) { d[6] = spPalette[spword >> 12 & 3]; } case 6: if (spword >> 10 & 3) { d[5] = spPalette[spword >> 10 & 3]; } case 5: if (spword >> 8 & 3) { d[4] = spPalette[spword >> 8 & 3]; } case 4: if (spword >> 6 & 3) { d[3] = spPalette[spword >> 6 & 3]; } case 3: if (spword >> 4 & 3) { d[2] = spPalette[spword >> 4 & 3]; } case 2: if (spword >> 2 & 3) { d[1] = spPalette[spword >> 2 & 3]; } case 1: if (spword & 3) { d[0] = spPalette[spword & 3]; } } spword >>= n * 2; /*do { if (spword & 3) dst[pos] = spPalette[spword & 3]; spword >>= 2; ++pos; } while (--n);*/ } else { unsigned tw = tileword >> pos * 2; d += n; n = -n; do { if (spword & 3) { d[n] = (tw & 3) ? p.bgPalette[ tw & 3] : spPalette[spword & 3]; } spword >>= 2; tw >>= 2; } while (++n); } p.spwordList[i] = spword; --i; } while (i >= 0 && int(p.spriteList[i].spx) > xpos - 8); } } unsigned const tno = tileMapLine[tileMapXpos & 0x1F]; tileMapXpos = (tileMapXpos & 0x1F) + 1; p.ntileword = expand_lut[(tileDataLine + tno * 16 - (tno & tileIndexSign) * 32)[0]] + expand_lut[(tileDataLine + tno * 16 - (tno & tileIndexSign) * 32)[1]] * 2; xpos = xpos + 8; } while (xpos < xend); p.xpos = xpos; } static void doFullTilesUnrolledCgb(PPUPriv &p, int const xend, video_pixel_t *const dbufline, unsigned char const *const tileMapLine, unsigned const tileline, unsigned tileMapXpos) { int xpos = p.xpos; unsigned char const *const vram = p.vram; unsigned const tdoffset = tileline * 2 + (~p.lcdc & 0x10) * 0x100; do { int nextSprite = p.nextSprite; if (int(p.spriteList[nextSprite].spx) < xpos + 8) { int cycles = p.cycles - 8; cycles -= std::max(11 - (int(p.spriteList[nextSprite].spx) - xpos), 6); for (unsigned i = nextSprite + 1; int(p.spriteList[i].spx) < xpos + 8; ++i) cycles -= 6; if (cycles < 0) break; p.cycles = cycles; do { unsigned char const *const oam = p.spriteMapper.oamram(); unsigned reg0, reg1 = oam[p.spriteList[nextSprite].oampos + 2] * 16; unsigned const attrib = oam[p.spriteList[nextSprite].oampos + 3]; unsigned const spline = ( (attrib & attr_yflip) ? p.spriteList[nextSprite].line ^ 15 : p.spriteList[nextSprite].line ) * 2; reg0 = vram[(attrib << 10 & 0x2000) + (lcdcObj2x(p) ? (reg1 & ~16) | spline : reg1 | (spline & ~16)) ]; reg1 = vram[(attrib << 10 & 0x2000) + (lcdcObj2x(p) ? (reg1 & ~16) | spline : reg1 | (spline & ~16)) + 1]; p.spwordList[nextSprite] = expand_lut[reg0 + (attrib << 3 & 0x100)] + expand_lut[reg1 + (attrib << 3 & 0x100)] * 2; p.spriteList[nextSprite].attrib = attrib; ++nextSprite; } while (int(p.spriteList[nextSprite].spx) < xpos + 8); p.nextSprite = nextSprite; } else if (nextSprite-1 < 0 || int(p.spriteList[nextSprite-1].spx) <= xpos - 8) { if (!(p.cycles & ~7)) break; int n = (( xend + 7 < int(p.spriteList[nextSprite].spx) ? xend + 7 : int(p.spriteList[nextSprite].spx)) - xpos) & ~7; n = (p.cycles & ~7) < n ? p.cycles & ~7 : n; p.cycles -= n; unsigned ntileword = p.ntileword; unsigned nattrib = p.nattrib; video_pixel_t * dst = dbufline + xpos - 8; video_pixel_t *const dstend = dst + n; xpos += n; do { video_pixel_t const *const bgPalette = p.bgPalette + (nattrib & 7) * 4; dst[0] = bgPalette[ ntileword & 0x0003 ]; dst[1] = bgPalette[(ntileword & 0x000C) >> 2]; dst[2] = bgPalette[(ntileword & 0x0030) >> 4]; dst[3] = bgPalette[(ntileword & 0x00C0) >> 6]; dst[4] = bgPalette[(ntileword & 0x0300) >> 8]; dst[5] = bgPalette[(ntileword & 0x0C00) >> 10]; dst[6] = bgPalette[(ntileword & 0x3000) >> 12]; dst[7] = bgPalette[ ntileword >> 14]; dst += 8; unsigned const tno = tileMapLine[ tileMapXpos & 0x1F ]; nattrib = tileMapLine[(tileMapXpos & 0x1F) + 0x2000]; tileMapXpos = (tileMapXpos & 0x1F) + 1; unsigned const tdo = (tdoffset & ~(tno << 5)); unsigned char const *const td = vram + tno * 16 + ((nattrib & attr_yflip) ? tdo ^ 14 : tdo) + (nattrib << 10 & 0x2000); unsigned short const *const explut = expand_lut + (nattrib << 3 & 0x100); ntileword = explut[td[0]] + explut[td[1]] * 2; } while (dst != dstend); p.ntileword = ntileword; p.nattrib = nattrib; continue; } else { int cycles = p.cycles - 8; if (cycles < 0) break; p.cycles = cycles; } { video_pixel_t *const dst = dbufline + (xpos - 8); unsigned const tileword = p.ntileword; unsigned const attrib = p.nattrib; video_pixel_t const *const bgPalette = p.bgPalette + (attrib & 7) * 4; dst[0] = bgPalette[ tileword & 0x0003 ]; dst[1] = bgPalette[(tileword & 0x000C) >> 2]; dst[2] = bgPalette[(tileword & 0x0030) >> 4]; dst[3] = bgPalette[(tileword & 0x00C0) >> 6]; dst[4] = bgPalette[(tileword & 0x0300) >> 8]; dst[5] = bgPalette[(tileword & 0x0C00) >> 10]; dst[6] = bgPalette[(tileword & 0x3000) >> 12]; dst[7] = bgPalette[ tileword >> 14]; int i = nextSprite - 1; if (!lcdcObjEn(p)) { do { int pos = int(p.spriteList[i].spx) - xpos; p.spwordList[i] >>= pos * 2 >= 0 ? 16 - pos * 2 : 16 + pos * 2; --i; } while (i >= 0 && int(p.spriteList[i].spx) > xpos - 8); } else { unsigned char idtab[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; unsigned const bgprioritymask = p.lcdc << 7; do { int n; int pos = int(p.spriteList[i].spx) - xpos; if (pos < 0) { n = pos + 8; pos = 0; } else n = 8 - pos; unsigned char const id = p.spriteList[i].oampos; unsigned const sattrib = p.spriteList[i].attrib; unsigned spword = p.spwordList[i]; video_pixel_t const *const spPalette = p.spPalette + (sattrib & 7) * 4; if (!((attrib | sattrib) & bgprioritymask)) { unsigned char *const idt = idtab + pos; video_pixel_t *const d = dst + pos; switch (n) { case 8: if ((spword >> 14 ) && id < idt[7]) { idt[7] = id; d[7] = spPalette[spword >> 14 ]; } case 7: if ((spword >> 12 & 3) && id < idt[6]) { idt[6] = id; d[6] = spPalette[spword >> 12 & 3]; } case 6: if ((spword >> 10 & 3) && id < idt[5]) { idt[5] = id; d[5] = spPalette[spword >> 10 & 3]; } case 5: if ((spword >> 8 & 3) && id < idt[4]) { idt[4] = id; d[4] = spPalette[spword >> 8 & 3]; } case 4: if ((spword >> 6 & 3) && id < idt[3]) { idt[3] = id; d[3] = spPalette[spword >> 6 & 3]; } case 3: if ((spword >> 4 & 3) && id < idt[2]) { idt[2] = id; d[2] = spPalette[spword >> 4 & 3]; } case 2: if ((spword >> 2 & 3) && id < idt[1]) { idt[1] = id; d[1] = spPalette[spword >> 2 & 3]; } case 1: if ((spword & 3) && id < idt[0]) { idt[0] = id; d[0] = spPalette[spword & 3]; } } spword >>= n * 2; /*do { if ((spword & 3) && id < idtab[pos]) { idtab[pos] = id; dst[pos] = spPalette[spword & 3]; } spword >>= 2; ++pos; } while (--n);*/ } else { unsigned tw = tileword >> pos * 2; do { if ((spword & 3) && id < idtab[pos]) { idtab[pos] = id; dst[pos] = (tw & 3) ? bgPalette[ tw & 3] : spPalette[spword & 3]; } spword >>= 2; tw >>= 2; ++pos; } while (--n); } p.spwordList[i] = spword; --i; } while (i >= 0 && int(p.spriteList[i].spx) > xpos - 8); } } { unsigned const tno = tileMapLine[ tileMapXpos & 0x1F ]; unsigned const nattrib = tileMapLine[(tileMapXpos & 0x1F) + 0x2000]; tileMapXpos = (tileMapXpos & 0x1F) + 1; unsigned const tdo = tdoffset & ~(tno << 5); unsigned char const *const td = vram + tno * 16 + ((nattrib & attr_yflip) ? tdo ^ 14 : tdo) + (nattrib << 10 & 0x2000); unsigned short const *const explut = expand_lut + (nattrib << 3 & 0x100); p.ntileword = explut[td[0]] + explut[td[1]] * 2; p.nattrib = nattrib; } xpos = xpos + 8; } while (xpos < xend); p.xpos = xpos; } static void doFullTilesUnrolled(PPUPriv &p) { int xpos = p.xpos; int const xend = static_cast(p.wx) < xpos || p.wx >= 168 ? 161 : static_cast(p.wx) - 7; if (xpos >= xend) return; video_pixel_t *const dbufline = p.framebuf.fbline(); unsigned char const *tileMapLine; unsigned tileline; unsigned tileMapXpos; if (p.winDrawState & win_draw_started) { tileMapLine = p.vram + (p.lcdc << 4 & 0x400) + (p.winYPos & 0xF8) * 4 + 0x1800; tileMapXpos = (xpos + p.wscx) >> 3; tileline = p.winYPos & 7; } else { tileMapLine = p.vram + (p.lcdc << 7 & 0x400) + ((p.scy + p.lyCounter.ly()) & 0xF8) * 4 + 0x1800; tileMapXpos = (p.scx + xpos + 1 - p.cgb) >> 3; tileline = (p.scy + p.lyCounter.ly()) & 7; } if (xpos < 8) { video_pixel_t prebuf[16]; if (p.cgb) { doFullTilesUnrolledCgb(p, xend < 8 ? xend : 8, prebuf + (8 - xpos), tileMapLine, tileline, tileMapXpos); } else { doFullTilesUnrolledDmg(p, xend < 8 ? xend : 8, prebuf + (8 - xpos), tileMapLine, tileline, tileMapXpos); } int const newxpos = p.xpos; if (newxpos > 8) { std::memcpy(dbufline, prebuf + (8 - xpos), (newxpos - 8) * sizeof *dbufline); } else if (newxpos < 8) return; if (newxpos >= xend) return; tileMapXpos += (newxpos - xpos) >> 3; } if (p.cgb) { doFullTilesUnrolledCgb(p, xend, dbufline, tileMapLine, tileline, tileMapXpos); } else doFullTilesUnrolledDmg(p, xend, dbufline, tileMapLine, tileline, tileMapXpos); } static void plotPixel(PPUPriv &p) { int const xpos = p.xpos; unsigned const tileword = p.tileword; video_pixel_t *const fbline = p.framebuf.fbline(); if (static_cast(p.wx) == xpos && (p.weMaster || (p.wy2 == p.lyCounter.ly() && lcdcWinEn(p))) && xpos < 167) { if (p.winDrawState == 0 && lcdcWinEn(p)) { p.winDrawState = win_draw_start | win_draw_started; ++p.winYPos; } else if (!p.cgb && (p.winDrawState == 0 || xpos == 166)) p.winDrawState |= win_draw_start; } unsigned const twdata = tileword & ((p.lcdc & 1) | p.cgb) * 3; video_pixel_t pixel = p.bgPalette[twdata + (p.attrib & 7) * 4]; int i = static_cast(p.nextSprite) - 1; if (i >= 0 && int(p.spriteList[i].spx) > xpos - 8) { unsigned spdata = 0; unsigned attrib = 0; if (p.cgb) { unsigned minId = 0xFF; do { if ((p.spwordList[i] & 3) && p.spriteList[i].oampos < minId) { spdata = p.spwordList[i] & 3; attrib = p.spriteList[i].attrib; minId = p.spriteList[i].oampos; } p.spwordList[i] >>= 2; --i; } while (i >= 0 && int(p.spriteList[i].spx) > xpos - 8); if (spdata && lcdcObjEn(p) && (!((attrib | p.attrib) & attr_bgpriority) || !twdata || !lcdcBgEn(p))) { pixel = p.spPalette[(attrib & 7) * 4 + spdata]; } } else { do { if (p.spwordList[i] & 3) { spdata = p.spwordList[i] & 3; attrib = p.spriteList[i].attrib; } p.spwordList[i] >>= 2; --i; } while (i >= 0 && int(p.spriteList[i].spx) > xpos - 8); if (spdata && lcdcObjEn(p) && (!(attrib & attr_bgpriority) || !twdata)) pixel = p.spPalette[(attrib >> 2 & 4) + spdata]; } } if (xpos - 8 >= 0) fbline[xpos - 8] = pixel; p.xpos = xpos + 1; p.tileword = tileword >> 2; } static void plotPixelIfNoSprite(PPUPriv &p) { if (p.spriteList[p.nextSprite].spx == p.xpos) { if (!(lcdcObjEn(p) | p.cgb)) { do { ++p.nextSprite; } while (p.spriteList[p.nextSprite].spx == p.xpos); plotPixel(p); } } else plotPixel(p); } static unsigned long nextM2Time(PPUPriv const &p) { unsigned long nextm2 = p.lyCounter.isDoubleSpeed() ? p.lyCounter.time() + (weMasterCheckPriorToLyIncLineCycle(true ) + m2_ds_offset) * 2 - 456 * 2 : p.lyCounter.time() + weMasterCheckPriorToLyIncLineCycle(p.cgb) - 456 ; if (p.lyCounter.ly() == 143) nextm2 += (456 * 10 + 456 - weMasterCheckPriorToLyIncLineCycle(p.cgb)) << p.lyCounter.isDoubleSpeed(); return nextm2; } static void xpos168(PPUPriv &p) { p.lastM0Time = p.now - (p.cycles << p.lyCounter.isDoubleSpeed()); unsigned long const nextm2 = nextM2Time(p); p.cycles = p.now >= nextm2 ? long((p.now - nextm2) >> p.lyCounter.isDoubleSpeed()) : -long((nextm2 - p.now) >> p.lyCounter.isDoubleSpeed()); nextCall(0, p.lyCounter.ly() == 143 ? M2_Ly0::f0_ : M2_LyNon0::f0_, p); } static bool handleWinDrawStartReq(PPUPriv const &p, int const xpos, unsigned char &winDrawState) { bool const startWinDraw = (xpos < 167 || p.cgb) && (winDrawState &= win_draw_started); if (!lcdcWinEn(p)) winDrawState &= ~win_draw_started; return startWinDraw; } static bool handleWinDrawStartReq(PPUPriv &p) { return handleWinDrawStartReq(p, p.xpos, p.winDrawState); } namespace StartWindowDraw { static void inc(PPUState const &nextf, PPUPriv &p) { if (!lcdcWinEn(p) && p.cgb) { plotPixelIfNoSprite(p); if (p.xpos == p.endx) { if (p.xpos < 168) { nextCall(1, Tile::f0_, p); } else xpos168(p); return; } } nextCall(1, nextf, p); } static void f0(PPUPriv &p) { if (p.xpos == p.endx) { p.tileword = p.ntileword; p.attrib = p.nattrib; p.endx = p.xpos < 160 ? p.xpos + 8 : 168; } p.wscx = 8 - p.xpos; if (p.winDrawState & win_draw_started) { p.reg1 = p.vram[(p.lcdc << 4 & 0x400) + (p.winYPos & 0xF8) * 4 + 0x1800]; p.nattrib = p.vram[(p.lcdc << 4 & 0x400) + (p.winYPos & 0xF8) * 4 + 0x3800]; } else { p.reg1 = p.vram[(p.lcdc << 7 & 0x400) + ((p.scy + p.lyCounter.ly()) & 0xF8) * 4 + 0x1800]; p.nattrib = p.vram[(p.lcdc << 7 & 0x400) + ((p.scy + p.lyCounter.ly()) & 0xF8) * 4 + 0x3800]; } inc(f1_, p); } static void f1(PPUPriv &p) { inc(f2_, p); } static void f2(PPUPriv &p) { p.reg0 = loadTileDataByte0(p); inc(f3_, p); } static void f3(PPUPriv &p) { inc(f4_, p); } static void f4(PPUPriv &p) { int const r1 = loadTileDataByte1(p); p.ntileword = (expand_lut + (p.nattrib << 3 & 0x100))[p.reg0] + (expand_lut + (p.nattrib << 3 & 0x100))[r1 ] * 2; inc(f5_, p); } static void f5(PPUPriv &p) { inc(Tile::f0_, p); } } namespace LoadSprites { static void inc(PPUState const &nextf, PPUPriv &p) { plotPixelIfNoSprite(p); if (p.xpos == p.endx) { if (p.xpos < 168) { nextCall(1, Tile::f0_, p); } else xpos168(p); } else nextCall(1, nextf, p); } static void f0(PPUPriv &p) { p.reg1 = p.spriteMapper.oamram()[p.spriteList[p.currentSprite].oampos + 2]; nextCall(1, f1_, p); } static void f1(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); p.spriteList[p.currentSprite].attrib = p.spriteMapper.oamram()[p.spriteList[p.currentSprite].oampos + 3]; inc(f2_, p); } static void f2(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); unsigned const spline = ( (p.spriteList[p.currentSprite].attrib & attr_yflip) ? p.spriteList[p.currentSprite].line ^ 15 : p.spriteList[p.currentSprite].line ) * 2; p.reg0 = p.vram[(p.spriteList[p.currentSprite].attrib << 10 & p.cgb * 0x2000) + (lcdcObj2x(p) ? (p.reg1 * 16 & ~16) | spline : p.reg1 * 16 | (spline & ~16))]; inc(f3_, p); } static void f3(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); inc(f4_, p); } static void f4(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); unsigned const spline = ( (p.spriteList[p.currentSprite].attrib & attr_yflip) ? p.spriteList[p.currentSprite].line ^ 15 : p.spriteList[p.currentSprite].line ) * 2; p.reg1 = p.vram[(p.spriteList[p.currentSprite].attrib << 10 & p.cgb * 0x2000) + (lcdcObj2x(p) ? (p.reg1 * 16 & ~16) | spline : p.reg1 * 16 | (spline & ~16)) + 1]; inc(f5_, p); } static void f5(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); plotPixelIfNoSprite(p); unsigned entry = p.currentSprite; if (entry == p.nextSprite) { ++p.nextSprite; } else { entry = p.nextSprite - 1; p.spriteList[entry] = p.spriteList[p.currentSprite]; } p.spwordList[entry] = expand_lut[p.reg0 + (p.spriteList[entry].attrib << 3 & 0x100)] + expand_lut[p.reg1 + (p.spriteList[entry].attrib << 3 & 0x100)] * 2; p.spriteList[entry].spx = p.xpos; if (p.xpos == p.endx) { if (p.xpos < 168) { nextCall(1, Tile::f0_, p); } else xpos168(p); } else { p.nextCallPtr = &Tile::f5_; nextCall(1, Tile::f5_, p); } } } namespace Tile { static void inc(PPUState const &nextf, PPUPriv &p) { plotPixelIfNoSprite(p); if (p.xpos == 168) { xpos168(p); } else nextCall(1, nextf, p); } static void f0(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); doFullTilesUnrolled(p); if (p.xpos == 168) { ++p.cycles; return xpos168(p); } p.tileword = p.ntileword; p.attrib = p.nattrib; p.endx = p.xpos < 160 ? p.xpos + 8 : 168; if (p.winDrawState & win_draw_started) { p.reg1 = p.vram[(p.lcdc << 4 & 0x400) + (p.winYPos & 0xF8) * 4 + ((p.xpos + p.wscx) >> 3 & 0x1F) + 0x1800]; p.nattrib = p.vram[(p.lcdc << 4 & 0x400) + (p.winYPos & 0xF8) * 4 + ((p.xpos + p.wscx) >> 3 & 0x1F) + 0x3800]; } else { p.reg1 = p.vram[((p.lcdc << 7 | (p.scx + p.xpos + 1 - p.cgb) >> 3) & 0x41F) + ((p.scy + p.lyCounter.ly()) & 0xF8) * 4 + 0x1800]; p.nattrib = p.vram[((p.lcdc << 7 | (p.scx + p.xpos + 1 - p.cgb) >> 3) & 0x41F) + ((p.scy + p.lyCounter.ly()) & 0xF8) * 4 + 0x3800]; } inc(f1_, p); } static void f1(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); inc(f2_, p); } static void f2(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); p.reg0 = loadTileDataByte0(p); inc(f3_, p); } static void f3(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); inc(f4_, p); } static void f4(PPUPriv &p) { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); int const r1 = loadTileDataByte1(p); p.ntileword = (expand_lut + (p.nattrib << 3 & 0x100))[p.reg0] + (expand_lut + (p.nattrib << 3 & 0x100))[r1 ] * 2; plotPixelIfNoSprite(p); if (p.xpos == 168) { xpos168(p); } else nextCall(1, f5_, p); } static void f5(PPUPriv &p) { int endx = p.endx; p.nextCallPtr = &f5_; do { if ((p.winDrawState & win_draw_start) && handleWinDrawStartReq(p)) return StartWindowDraw::f0(p); if (p.spriteList[p.nextSprite].spx == p.xpos) { if (lcdcObjEn(p) | p.cgb) { p.currentSprite = p.nextSprite; return LoadSprites::f0(p); } do { ++p.nextSprite; } while (p.spriteList[p.nextSprite].spx == p.xpos); } plotPixel(p); if (p.xpos == endx) { if (endx < 168) { nextCall(1, f0_, p); } else xpos168(p); return; } } while (--p.cycles >= 0); } } } // namespace M3Loop namespace M2_Ly0 { static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, unsigned winDrawState, int targetxpos, unsigned cycles); } namespace M2_LyNon0 { static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, unsigned winDrawState, int targetxpos, unsigned cycles); } namespace M3Loop { static unsigned predictCyclesUntilXposNextLine( PPUPriv const &p, unsigned winDrawState, int const targetx) { if (p.wx == 166 && !p.cgb && p.xpos < 167 && (p.weMaster || (p.wy2 == p.lyCounter.ly() && lcdcWinEn(p)))) { winDrawState = win_draw_start | (lcdcWinEn(p) ? win_draw_started : 0); } unsigned const cycles = (nextM2Time(p) - p.now) >> p.lyCounter.isDoubleSpeed(); return p.lyCounter.ly() == 143 ? M2_Ly0::predictCyclesUntilXpos_f0(p, winDrawState, targetx, cycles) : M2_LyNon0::predictCyclesUntilXpos_f0(p, winDrawState, targetx, cycles); } namespace StartWindowDraw { static unsigned predictCyclesUntilXpos_fn(PPUPriv const &p, int xpos, int endx, unsigned ly, unsigned nextSprite, bool weMaster, unsigned winDrawState, int fno, int targetx, unsigned cycles); } namespace Tile { static unsigned char const * addSpriteCycles(unsigned char const *nextSprite, unsigned char const *spriteEnd, unsigned char const *const spxOf, unsigned const maxSpx, unsigned const firstTileXpos, unsigned prevSpriteTileNo, unsigned *const cyclesAccumulator) { unsigned sum = 0; while (nextSprite < spriteEnd && spxOf[*nextSprite] <= maxSpx) { unsigned cycles = 6; unsigned const distanceFromTileStart = (spxOf[*nextSprite] - firstTileXpos) & 7; unsigned const tileNo = (spxOf[*nextSprite] - firstTileXpos) & ~7; if (distanceFromTileStart < 5 && tileNo != prevSpriteTileNo) cycles = 11 - distanceFromTileStart; prevSpriteTileNo = tileNo; sum += cycles; ++nextSprite; } *cyclesAccumulator += sum; return nextSprite; } static unsigned predictCyclesUntilXpos_fn(PPUPriv const &p, int const xpos, int const endx, unsigned const ly, unsigned const nextSprite, bool const weMaster, unsigned char winDrawState, int const fno, int const targetx, unsigned cycles) { if ((winDrawState & win_draw_start) && handleWinDrawStartReq(p, xpos, winDrawState)) { return StartWindowDraw::predictCyclesUntilXpos_fn(p, xpos, endx, ly, nextSprite, weMaster, winDrawState, 0, targetx, cycles); } if (xpos > targetx) return predictCyclesUntilXposNextLine(p, winDrawState, targetx); enum { NO_TILE_NUMBER = 1 }; // low bit set, so it will never be equal to an actual tile number. int nwx = 0xFF; cycles += targetx - xpos; if (p.wx - unsigned(xpos) < targetx - unsigned(xpos) && lcdcWinEn(p) && (weMaster || p.wy2 == ly) && !(winDrawState & win_draw_started) && (p.cgb || p.wx != 166)) { nwx = p.wx; cycles += 6; } if (lcdcObjEn(p) | p.cgb) { unsigned char const *sprite = p.spriteMapper.sprites(ly); unsigned char const *const spriteEnd = sprite + p.spriteMapper.numSprites(ly); sprite += nextSprite; if (sprite < spriteEnd) { int const spx = p.spriteMapper.posbuf()[*sprite + 1]; unsigned firstTileXpos = endx & 7u; // ok even if endx is capped at 168, // because fno will be used. unsigned prevSpriteTileNo = (xpos - firstTileXpos) & ~7; // this tile. all sprites on this // tile will now add 6 cycles. // except this one if (fno + spx - xpos < 5 && spx <= nwx) { cycles += 11 - (fno + spx - xpos); sprite += 1; } if (nwx < targetx) { sprite = addSpriteCycles(sprite, spriteEnd, p.spriteMapper.posbuf() + 1, nwx, firstTileXpos, prevSpriteTileNo, &cycles); firstTileXpos = nwx + 1; prevSpriteTileNo = NO_TILE_NUMBER; } addSpriteCycles(sprite, spriteEnd, p.spriteMapper.posbuf() + 1, targetx, firstTileXpos, prevSpriteTileNo, &cycles); } } return cycles; } static unsigned predictCyclesUntilXpos_fn(PPUPriv const &p, int endx, int fno, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.xpos, endx, p.lyCounter.ly(), p.nextSprite, p.weMaster, p.winDrawState, fno, targetx, cycles); } static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.xpos < 160 ? p.xpos + 8 : 168, 0, targetx, cycles); } static unsigned predictCyclesUntilXpos_f1(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 1, targetx, cycles); } static unsigned predictCyclesUntilXpos_f2(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 2, targetx, cycles); } static unsigned predictCyclesUntilXpos_f3(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 3, targetx, cycles); } static unsigned predictCyclesUntilXpos_f4(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 4, targetx, cycles); } static unsigned predictCyclesUntilXpos_f5(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 5, targetx, cycles); } } namespace StartWindowDraw { static unsigned predictCyclesUntilXpos_fn(PPUPriv const &p, int xpos, int const endx, unsigned const ly, unsigned const nextSprite, bool const weMaster, unsigned const winDrawState, int const fno, int const targetx, unsigned cycles) { if (xpos > targetx) return predictCyclesUntilXposNextLine(p, winDrawState, targetx); unsigned cinc = 6 - fno; if (!lcdcWinEn(p) && p.cgb) { unsigned xinc = std::min(cinc, std::min(endx, targetx + 1) - xpos); if ((lcdcObjEn(p) | p.cgb) && p.spriteList[nextSprite].spx < xpos + xinc) { xpos = p.spriteList[nextSprite].spx; } else { cinc = xinc; xpos += xinc; } } cycles += cinc; if (xpos <= targetx) { return Tile::predictCyclesUntilXpos_fn(p, xpos, xpos < 160 ? xpos + 8 : 168, ly, nextSprite, weMaster, winDrawState, 0, targetx, cycles); } return cycles - 1; } static unsigned predictCyclesUntilXpos_fn(PPUPriv const &p, int endx, int fno, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.xpos, endx, p.lyCounter.ly(), p.nextSprite, p.weMaster, p.winDrawState, fno, targetx, cycles); } static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, int targetx, unsigned cycles) { int endx = p.xpos == p.endx ? (p.xpos < 160 ? p.xpos + 8 : 168) : p.endx; return predictCyclesUntilXpos_fn(p, endx, 0, targetx, cycles); } static unsigned predictCyclesUntilXpos_f1(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 1, targetx, cycles); } static unsigned predictCyclesUntilXpos_f2(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 2, targetx, cycles); } static unsigned predictCyclesUntilXpos_f3(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 3, targetx, cycles); } static unsigned predictCyclesUntilXpos_f4(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 4, targetx, cycles); } static unsigned predictCyclesUntilXpos_f5(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, p.endx, 5, targetx, cycles); } } namespace LoadSprites { static unsigned predictCyclesUntilXpos_fn(PPUPriv const &p, int const fno, int const targetx, unsigned cycles) { unsigned nextSprite = p.nextSprite; if (lcdcObjEn(p) | p.cgb) { cycles += 6 - fno; nextSprite += 1; } return Tile::predictCyclesUntilXpos_fn(p, p.xpos, p.endx, p.lyCounter.ly(), nextSprite, p.weMaster, p.winDrawState, 5, targetx, cycles); } static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, 0, targetx, cycles); } static unsigned predictCyclesUntilXpos_f1(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, 1, targetx, cycles); } static unsigned predictCyclesUntilXpos_f2(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, 2, targetx, cycles); } static unsigned predictCyclesUntilXpos_f3(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, 3, targetx, cycles); } static unsigned predictCyclesUntilXpos_f4(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, 4, targetx, cycles); } static unsigned predictCyclesUntilXpos_f5(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_fn(p, 5, targetx, cycles); } } } // namespace M3Loop namespace M3Start { static unsigned predictCyclesUntilXpos_f1(PPUPriv const &p, unsigned xpos, unsigned ly, bool weMaster, unsigned winDrawState, int targetx, unsigned cycles) { cycles += std::min(unsigned(p.scx - xpos) & 7, max_m3start_cycles - xpos) + 1 - p.cgb; return M3Loop::Tile::predictCyclesUntilXpos_fn(p, 0, 8 - (p.scx & 7), ly, 0, weMaster, winDrawState, std::min(p.scx & 7, 5), targetx, cycles); } static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, unsigned ly, bool weMaster, unsigned winDrawState, int targetx, unsigned cycles) { winDrawState = (winDrawState & win_draw_start) && lcdcWinEn(p) ? win_draw_started : 0; return predictCyclesUntilXpos_f1(p, 0, ly, weMaster, winDrawState, targetx, cycles); } static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, int targetx, unsigned cycles) { unsigned ly = p.lyCounter.ly() + (p.lyCounter.time() - p.now < 16); return predictCyclesUntilXpos_f0(p, ly, p.weMaster, p.winDrawState, targetx, cycles); } static unsigned predictCyclesUntilXpos_f1(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_f1(p, p.xpos, p.lyCounter.ly(), p.weMaster, p.winDrawState, targetx, cycles); } } namespace M2_Ly0 { static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, unsigned winDrawState, int targetx, unsigned cycles) { bool weMaster = lcdcWinEn(p) && 0 == p.wy; unsigned ly = 0; return M3Start::predictCyclesUntilXpos_f0(p, ly, weMaster, winDrawState, targetx, cycles + m3StartLineCycle(p.cgb)); } static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_f0(p, p.winDrawState, targetx, cycles); } } namespace M2_LyNon0 { static unsigned predictCyclesUntilXpos_f1(PPUPriv const &p, bool weMaster, unsigned winDrawState, int targetx, unsigned cycles) { unsigned ly = p.lyCounter.ly() + 1; weMaster |= lcdcWinEn(p) && ly == p.wy; return M3Start::predictCyclesUntilXpos_f0(p, ly, weMaster, winDrawState, targetx, cycles + 456 - weMasterCheckAfterLyIncLineCycle(p.cgb) + m3StartLineCycle(p.cgb)); } static unsigned predictCyclesUntilXpos_f1(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_f1(p, p.weMaster, p.winDrawState, targetx, cycles); } static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, unsigned winDrawState, int targetx, unsigned cycles) { bool weMaster = p.weMaster || (lcdcWinEn(p) && p.lyCounter.ly() == p.wy); return predictCyclesUntilXpos_f1(p, weMaster, winDrawState, targetx, cycles + weMasterCheckAfterLyIncLineCycle(p.cgb) - weMasterCheckPriorToLyIncLineCycle(p.cgb)); } static unsigned predictCyclesUntilXpos_f0(PPUPriv const &p, int targetx, unsigned cycles) { return predictCyclesUntilXpos_f0(p, p.winDrawState, targetx, cycles); } } } // anon namespace namespace gambatte { PPUPriv::PPUPriv(NextM0Time &nextM0Time, unsigned char const *const oamram, unsigned char const *const vram) : nextSprite(0) , currentSprite(0xFF) , vram(vram) , nextCallPtr(&M2_Ly0::f0_) , now(0) , lastM0Time(0) , cycles(-4396) , tileword(0) , ntileword(0) , spriteMapper(nextM0Time, lyCounter, oamram) , lcdc(0) , scy(0) , scx(0) , wy(0) , wy2(0) , wx(0) , winDrawState(0) , wscx(0) , winYPos(0) , reg0(0) , reg1(0) , attrib(0) , nattrib(0) , xpos(0) , endx(0) , cgb(false) , weMaster(false) { std::memset(spriteList, 0, sizeof spriteList); std::memset(spwordList, 0, sizeof spwordList); } static void saveSpriteList(PPUPriv const &p, SaveState &ss) { for (unsigned i = 0; i < 10; ++i) { ss.ppu.spAttribList[i] = p.spriteList[i].attrib; ss.ppu.spByte0List[i] = p.spwordList[i] & 0xFF; ss.ppu.spByte1List[i] = p.spwordList[i] >> 8; } ss.ppu.nextSprite = p.nextSprite; ss.ppu.currentSprite = p.currentSprite; } void PPU::saveState(SaveState &ss) const { p_.spriteMapper.saveState(ss); ss.ppu.videoCycles = lcdcEn(p_) ? p_.lyCounter.frameCycles(p_.now) : 0; ss.ppu.xpos = p_.xpos; ss.ppu.endx = p_.endx; ss.ppu.reg0 = p_.reg0; ss.ppu.reg1 = p_.reg1; ss.ppu.tileword = p_.tileword; ss.ppu.ntileword = p_.ntileword; ss.ppu.attrib = p_.attrib; ss.ppu.nattrib = p_.nattrib; ss.ppu.winDrawState = p_.winDrawState; ss.ppu.winYPos = p_.winYPos; ss.ppu.oldWy = p_.wy2; ss.ppu.wscx = p_.wscx; ss.ppu.weMaster = p_.weMaster; saveSpriteList(p_, ss); ss.ppu.state = p_.nextCallPtr->id; ss.ppu.lastM0Time = p_.now - p_.lastM0Time; } namespace { template struct BSearch { static std::size_t upperBound(T const a[], K e) { if (e < a[start + len / 2]) return BSearch::upperBound(a, e); return BSearch::upperBound(a, e); } }; template struct BSearch { static std::size_t upperBound(T const [], K ) { return start; } }; template std::size_t upperBound(T const a[], K e) { return BSearch::upperBound(a, e); } struct CycleState { PPUState const *state; long cycle; operator long() const { return cycle; } }; static PPUState const * decodeM3LoopState(unsigned state) { switch (state) { case M3Loop::Tile::ID0: return &M3Loop::Tile::f0_; case M3Loop::Tile::ID1: return &M3Loop::Tile::f1_; case M3Loop::Tile::ID2: return &M3Loop::Tile::f2_; case M3Loop::Tile::ID3: return &M3Loop::Tile::f3_; case M3Loop::Tile::ID4: return &M3Loop::Tile::f4_; case M3Loop::Tile::ID5: return &M3Loop::Tile::f5_; case M3Loop::LoadSprites::ID0: return &M3Loop::LoadSprites::f0_; case M3Loop::LoadSprites::ID1: return &M3Loop::LoadSprites::f1_; case M3Loop::LoadSprites::ID2: return &M3Loop::LoadSprites::f2_; case M3Loop::LoadSprites::ID3: return &M3Loop::LoadSprites::f3_; case M3Loop::LoadSprites::ID4: return &M3Loop::LoadSprites::f4_; case M3Loop::LoadSprites::ID5: return &M3Loop::LoadSprites::f5_; case M3Loop::StartWindowDraw::ID0: return &M3Loop::StartWindowDraw::f0_; case M3Loop::StartWindowDraw::ID1: return &M3Loop::StartWindowDraw::f1_; case M3Loop::StartWindowDraw::ID2: return &M3Loop::StartWindowDraw::f2_; case M3Loop::StartWindowDraw::ID3: return &M3Loop::StartWindowDraw::f3_; case M3Loop::StartWindowDraw::ID4: return &M3Loop::StartWindowDraw::f4_; case M3Loop::StartWindowDraw::ID5: return &M3Loop::StartWindowDraw::f5_; } return 0; } static long cyclesUntilM0Upperbound(PPUPriv const &p) { long cycles = 168 - p.xpos + 6; for (unsigned i = p.nextSprite; i < 10 && p.spriteList[i].spx < 168; ++i) cycles += 11; return cycles; } static void loadSpriteList(PPUPriv &p, SaveState const &ss) { if (ss.ppu.videoCycles < 144 * 456UL && ss.ppu.xpos < 168) { unsigned const ly = ss.ppu.videoCycles / 456; unsigned const numSprites = p.spriteMapper.numSprites(ly); unsigned char const *const sprites = p.spriteMapper.sprites(ly); for (unsigned i = 0; i < numSprites; ++i) { unsigned pos = sprites[i]; unsigned spy = p.spriteMapper.posbuf()[pos ]; unsigned spx = p.spriteMapper.posbuf()[pos+1]; p.spriteList[i].spx = spx; p.spriteList[i].line = ly + 16u - spy; p.spriteList[i].oampos = pos * 2; p.spriteList[i].attrib = ss.ppu.spAttribList[i] & 0xFF; p.spwordList[i] = (ss.ppu.spByte1List[i] * 0x100 + ss.ppu.spByte0List[i]) & 0xFFFF; } p.spriteList[numSprites].spx = 0xFF; p.nextSprite = std::min(ss.ppu.nextSprite, numSprites); while (p.spriteList[p.nextSprite].spx < ss.ppu.xpos) ++p.nextSprite; p.currentSprite = std::min(p.nextSprite, ss.ppu.currentSprite); } } } void PPU::loadState(SaveState const &ss, unsigned char const *const oamram) { PPUState const *const m3loopState = decodeM3LoopState(ss.ppu.state); long const videoCycles = std::min(ss.ppu.videoCycles, 70223UL); bool const ds = p_.cgb & ss.mem.ioamhram.get()[0x14D] >> 7; long const vcycs = videoCycles - ds * m2_ds_offset < 0 ? videoCycles - ds * m2_ds_offset + 70224 : videoCycles - ds * m2_ds_offset; long const lineCycles = static_cast(vcycs) % 456; p_.now = ss.cpu.cycleCounter; p_.lcdc = ss.mem.ioamhram.get()[0x140]; p_.lyCounter.setDoubleSpeed(ds); p_.lyCounter.reset(std::min(ss.ppu.videoCycles, 70223ul), ss.cpu.cycleCounter); p_.spriteMapper.loadState(ss, oamram); p_.winYPos = ss.ppu.winYPos; p_.scy = ss.mem.ioamhram.get()[0x142]; p_.scx = ss.mem.ioamhram.get()[0x143]; p_.wy = ss.mem.ioamhram.get()[0x14A]; p_.wy2 = ss.ppu.oldWy; p_.wx = ss.mem.ioamhram.get()[0x14B]; p_.xpos = std::min(ss.ppu.xpos, 168); p_.endx = (p_.xpos & ~7) + (ss.ppu.endx & 7); p_.endx = std::min(p_.endx <= p_.xpos ? p_.endx + 8 : p_.endx, 168); p_.reg0 = ss.ppu.reg0 & 0xFF; p_.reg1 = ss.ppu.reg1 & 0xFF; p_.tileword = ss.ppu.tileword & 0xFFFF; p_.ntileword = ss.ppu.ntileword & 0xFFFF; p_.attrib = ss.ppu.attrib & 0xFF; p_.nattrib = ss.ppu.nattrib & 0xFF; p_.wscx = ss.ppu.wscx; p_.weMaster = ss.ppu.weMaster; p_.winDrawState = ss.ppu.winDrawState & (win_draw_start | win_draw_started); p_.lastM0Time = p_.now - ss.ppu.lastM0Time; loadSpriteList(p_, ss); if (m3loopState && videoCycles < 144 * 456L && p_.xpos < 168 && lineCycles + cyclesUntilM0Upperbound(p_) < weMasterCheckPriorToLyIncLineCycle(p_.cgb)) { p_.nextCallPtr = m3loopState; p_.cycles = -1; } else if (vcycs < 143 * 456L + static_cast(m3StartLineCycle(p_.cgb)) + max_m3start_cycles) { CycleState const lineCycleStates[] = { { &M3Start::f0_, m3StartLineCycle(p_.cgb) }, { &M3Start::f1_, m3StartLineCycle(p_.cgb) + max_m3start_cycles }, { &M2_LyNon0::f0_, weMasterCheckPriorToLyIncLineCycle(p_.cgb) }, { &M2_LyNon0::f1_, weMasterCheckAfterLyIncLineCycle(p_.cgb) }, { &M3Start::f0_, m3StartLineCycle(p_.cgb) + 456 } }; std::size_t const pos = upperBound(lineCycleStates, lineCycles); p_.cycles = lineCycles - lineCycleStates[pos].cycle; p_.nextCallPtr = lineCycleStates[pos].state; if (&M3Start::f1_ == lineCycleStates[pos].state) { p_.xpos = lineCycles - m3StartLineCycle(p_.cgb) + 1; p_.cycles = -1; } } else { p_.cycles = vcycs - 70224; p_.nextCallPtr = &M2_Ly0::f0_; } } void PPU::reset(unsigned char const *oamram, unsigned char const *vram, bool cgb) { p_.vram = vram; p_.cgb = cgb; p_.spriteMapper.reset(oamram, cgb); } void PPU::resetCc(unsigned long const oldCc, unsigned long const newCc) { unsigned long const dec = oldCc - newCc; unsigned long const videoCycles = lcdcEn(p_) ? p_.lyCounter.frameCycles(p_.now) : 0; p_.now -= dec; p_.lastM0Time = p_.lastM0Time ? p_.lastM0Time - dec : p_.lastM0Time; p_.lyCounter.reset(videoCycles, p_.now); p_.spriteMapper.resetCycleCounter(oldCc, newCc); } void PPU::speedChange(unsigned long const cycleCounter) { unsigned long const videoCycles = lcdcEn(p_) ? p_.lyCounter.frameCycles(p_.now) : 0; p_.spriteMapper.preSpeedChange(cycleCounter); p_.lyCounter.setDoubleSpeed(!p_.lyCounter.isDoubleSpeed()); p_.lyCounter.reset(videoCycles, p_.now); p_.spriteMapper.postSpeedChange(cycleCounter); if (&M2_Ly0::f0_ == p_.nextCallPtr || &M2_LyNon0::f0_ == p_.nextCallPtr) { if (p_.lyCounter.isDoubleSpeed()) { p_.cycles -= m2_ds_offset; } else p_.cycles += m2_ds_offset; } } unsigned long PPU::predictedNextXposTime(unsigned xpos) const { return p_.now + (p_.nextCallPtr->predictCyclesUntilXpos_f(p_, xpos, -p_.cycles) << p_.lyCounter.isDoubleSpeed()); } void PPU::setLcdc(unsigned const lcdc, unsigned long const cc) { if ((p_.lcdc ^ lcdc) & lcdc & lcdc_en) { p_.now = cc; p_.lastM0Time = 0; p_.lyCounter.reset(0, p_.now); p_.spriteMapper.enableDisplay(cc); p_.weMaster = (lcdc & lcdc_we) && 0 == p_.wy; p_.winDrawState = 0; p_.nextCallPtr = &M3Start::f0_; p_.cycles = -int(m3StartLineCycle(p_.cgb) + m2_ds_offset * p_.lyCounter.isDoubleSpeed()); } else if ((p_.lcdc ^ lcdc) & lcdc_we) { if (!(lcdc & lcdc_we)) { if (p_.winDrawState == win_draw_started || p_.xpos == 168) p_.winDrawState &= ~win_draw_started; } else if (p_.winDrawState == win_draw_start) { p_.winDrawState |= win_draw_started; ++p_.winYPos; } } if ((p_.lcdc ^ lcdc) & lcdc_obj2x) { if (p_.lcdc & lcdc & lcdc_en) p_.spriteMapper.oamChange(cc); p_.spriteMapper.setLargeSpritesSource(lcdc & lcdc_obj2x); } p_.lcdc = lcdc; } void PPU::update(unsigned long const cc) { int const cycles = (cc - p_.now) >> p_.lyCounter.isDoubleSpeed(); p_.now += cycles << p_.lyCounter.isDoubleSpeed(); p_.cycles += cycles; if (p_.cycles >= 0) { p_.framebuf.setFbline(p_.lyCounter.ly()); p_.nextCallPtr->f(p_); } } } libgambatte/src/video/lcddef.h000664 001750 001750 00000000572 12720365247 017460 0ustar00sergiosergio000000 000000 #ifndef LCDDEF_H #define LCDDEF_H namespace gambatte { enum { lcdc_bgen = 0x01, lcdc_objen = 0x02, lcdc_obj2x = 0x04, lcdc_tdsel = 0x10, lcdc_we = 0x20, lcdc_en = 0x80 }; enum { lcdstat_lycflag = 0x04, lcdstat_m0irqen = 0x08, lcdstat_m1irqen = 0x10, lcdstat_m2irqen = 0x20, lcdstat_lycirqen = 0x40 }; } #endif libgambatte/src/mem/cartridge_libretro.cpp000664 001750 001750 00000002740 12720365247 022107 0ustar00sergiosergio000000 000000 #include "cartridge.h" #include "../savestate.h" #include #include #include "../../libretro/libretro.h" extern retro_log_printf_t log_cb; namespace gambatte { static bool hasBattery(unsigned char headerByte0x147) { switch (headerByte0x147) { case 0x03: case 0x06: case 0x09: case 0x0F: case 0x10: case 0x13: case 0x1B: case 0x1E: case 0xFF: return true; default: return false; } } static bool hasRtc(unsigned headerByte0x147) { switch (headerByte0x147) { case 0x0F: case 0x10: return true; default: return false; } } void *Cartridge::savedata_ptr() { // Check ROM header for battery. if (hasBattery(memptrs_.romdata()[0x147])) return memptrs_.rambankdata(); return 0; } unsigned Cartridge::savedata_size() { if (hasBattery(memptrs_.romdata()[0x147])) return memptrs_.rambankdataend() - memptrs_.rambankdata(); return 0; } void *Cartridge::rtcdata_ptr() { if (hasRtc(memptrs_.romdata()[0x147])) return &rtc_.getBaseTime(); return 0; } unsigned Cartridge::rtcdata_size() { if (hasRtc(memptrs_.romdata()[0x147])) return sizeof(rtc_.getBaseTime()); return 0; } void Cartridge::clearCheats() { ggUndoList_.clear(); } } libgambatte/src/mem/rtc.cpp000664 001750 001750 00000012420 12720365247 017025 0ustar00sergiosergio000000 000000 /*************************************************************************** * Copyright (C) 2007 by Sindre AamÃ¥s * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 as * * published by the Free Software Foundation. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License version 2 for more details. * * * * You should have received a copy of the GNU General Public License * * version 2 along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "rtc.h" #include "../savestate.h" namespace gambatte { Rtc::Rtc() : activeData_(NULL), activeSet_(NULL), baseTime_(0), haltTime_(0), index_(5), dataDh_(0), dataDl_(0), dataH_(0), dataM_(0), dataS_(0), enabled_(false), lastLatchData_(false) { } void Rtc::doLatch() { uint64_t tmp = ((dataDh_ & 0x40) ? haltTime_ : std::time(0)) - baseTime_; while (tmp > 0x1FF * 86400) { baseTime_ += 0x1FF * 86400; tmp -= 0x1FF * 86400; dataDh_ |= 0x80; } dataDl_ = (tmp / 86400) & 0xFF; dataDh_ &= 0xFE; dataDh_ |= ((tmp / 86400) & 0x100) >> 8; tmp %= 86400; dataH_ = tmp / 3600; tmp %= 3600; dataM_ = tmp / 60; tmp %= 60; dataS_ = tmp; } void Rtc::doSwapActive() { if (!enabled_ || index_ > 4) { activeData_ = NULL; activeSet_ = NULL; } else switch (index_) { case 0x00: activeData_ = &dataS_; activeSet_ = &Rtc::setS; break; case 0x01: activeData_ = &dataM_; activeSet_ = &Rtc::setM; break; case 0x02: activeData_ = &dataH_; activeSet_ = &Rtc::setH; break; case 0x03: activeData_ = &dataDl_; activeSet_ = &Rtc::setDl; break; case 0x04: activeData_ = &dataDh_; activeSet_ = &Rtc::setDh; break; } } void Rtc::saveState(SaveState &state) const { state.rtc.baseTime = baseTime_; state.rtc.haltTime = haltTime_; state.rtc.dataDh = dataDh_; state.rtc.dataDl = dataDl_; state.rtc.dataH = dataH_; state.rtc.dataM = dataM_; state.rtc.dataS = dataS_; state.rtc.lastLatchData = lastLatchData_; } void Rtc::loadState(const SaveState &state) { baseTime_ = state.rtc.baseTime; haltTime_ = state.rtc.haltTime; dataDh_ = state.rtc.dataDh; dataDl_ = state.rtc.dataDl; dataH_ = state.rtc.dataH; dataM_ = state.rtc.dataM; dataS_ = state.rtc.dataS; lastLatchData_ = state.rtc.lastLatchData; doSwapActive(); } void Rtc::setDh(const unsigned new_dh) { const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0); const uint64_t old_highdays = ((unixtime - baseTime_) / 86400) & 0x100; baseTime_ += old_highdays * 86400; baseTime_ -= ((new_dh & 0x1) << 8) * 86400; if ((dataDh_ ^ new_dh) & 0x40) { if (new_dh & 0x40) haltTime_ = std::time(0); else baseTime_ += std::time(0) - haltTime_; } } void Rtc::setDl(const unsigned new_lowdays) { const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0); const uint64_t old_lowdays = ((unixtime - baseTime_) / 86400) & 0xFF; baseTime_ += old_lowdays * 86400; baseTime_ -= new_lowdays * 86400; } void Rtc::setH(const unsigned new_hours) { const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0); const uint64_t old_hours = ((unixtime - baseTime_) / 3600) % 24; baseTime_ += old_hours * 3600; baseTime_ -= new_hours * 3600; } void Rtc::setM(const unsigned new_minutes) { const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0); const uint64_t old_minutes = ((unixtime - baseTime_) / 60) % 60; baseTime_ += old_minutes * 60; baseTime_ -= new_minutes * 60; } void Rtc::setS(const unsigned new_seconds) { const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0); baseTime_ += (unixtime - baseTime_) % 60; baseTime_ -= new_seconds; } } libgambatte/src/sound/envelope_unit.h000664 001750 001750 00000003072 12720365247 021133 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef ENVELOPE_UNIT_H #define ENVELOPE_UNIT_H #include "sound_unit.h" #include "../savestate.h" namespace gambatte { class EnvelopeUnit : public SoundUnit { public: struct VolOnOffEvent { virtual ~VolOnOffEvent() {} virtual void operator()(unsigned long /*cc*/) {} }; explicit EnvelopeUnit(VolOnOffEvent &volOnOffEvent = nullEvent_); void event(); bool dacIsOn() const { return nr2_ & 0xF8; } unsigned getVolume() const { return volume_; } bool nr2Change(unsigned newNr2); bool nr4Init(unsigned long cycleCounter); void reset(); void saveState(SaveState::SPU::Env &estate) const; void loadState(SaveState::SPU::Env const &estate, unsigned nr2, unsigned long cc); private: static VolOnOffEvent nullEvent_; VolOnOffEvent &volOnOffEvent_; unsigned char nr2_; unsigned char volume_; }; } #endif libgambatte/src/sound/channel4.h000664 001750 001750 00000005403 12720365247 017753 0ustar00sergiosergio000000 000000 // // Copyright (C) 2007 by sinamas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License version 2 for more details. // // You should have received a copy of the GNU General Public License // version 2 along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #ifndef SOUND_CHANNEL4_H #define SOUND_CHANNEL4_H #include "envelope_unit.h" #include "gbint.h" #include "length_counter.h" #include "master_disabler.h" #include "static_output_tester.h" namespace gambatte { struct SaveState; class Channel4 { public: Channel4(); void setNr1(unsigned data); void setNr2(unsigned data); void setNr3(unsigned data) { lfsr_.nr3Change(data, cycleCounter_); } void setNr4(unsigned data); void setSo(unsigned long soMask); bool isActive() const { return master_; } void update(uint_least32_t *buf, unsigned long soBaseVol, unsigned long cycles); void reset(); void saveState(SaveState &state); void loadState(SaveState const &state); private: class Lfsr : public SoundUnit { public: Lfsr(); virtual void event(); virtual void resetCounters(unsigned long oldCc); bool isHighState() const { return ~reg_ & 1; } void nr3Change(unsigned newNr3, unsigned long cc); void nr4Init(unsigned long cc); void reset(unsigned long cc); void saveState(SaveState &state, unsigned long cc); void loadState(SaveState const &state); void disableMaster() { killCounter(); master_ = false; reg_ = 0x7FFF; } void killCounter() { counter_ = counter_disabled; } void reviveCounter(unsigned long cc); private: unsigned long backupCounter_; unsigned short reg_; unsigned char nr3_; bool master_; void updateBackupCounter(unsigned long cc); }; class Ch4MasterDisabler : public MasterDisabler { public: Ch4MasterDisabler(bool &m, Lfsr &lfsr) : MasterDisabler(m), lfsr_(lfsr) {} virtual void operator()() { MasterDisabler::operator()(); lfsr_.disableMaster(); } private: Lfsr &lfsr_; }; friend class StaticOutputTester; StaticOutputTester staticOutputTest_; Ch4MasterDisabler disableMaster_; LengthCounter lengthCounter_; EnvelopeUnit envelopeUnit_; Lfsr lfsr_; SoundUnit *nextEventUnit_; unsigned long cycleCounter_; unsigned long soMask_; unsigned long prevOut_; unsigned char nr4_; bool master_; void setEvent(); }; } #endif libgambatte/libretro/msvc/000700 001750 001750 00000000000 12720366137 016742 5ustar00sergiosergio000000 000000 common/000700 001750 001750 00000000000 12720366137 013165 5ustar00sergiosergio000000 000000 libgambatte/libretro/msvc/msvc-2010/000700 001750 001750 00000000000 12720366137 020272 5ustar00sergiosergio000000 000000