├── app
├── .gitignore
├── nesemulator.jks
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── themes.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── activity_nes_emulator.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── ym
│ │ │ │ └── nesemulator
│ │ │ │ ├── App.kt
│ │ │ │ ├── MainActivity.kt
│ │ │ │ └── MyEmulatorActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── ym
│ │ │ └── nesemulator
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── ym
│ │ └── nesemulator
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── screen_shot
└── screen_shot.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle
├── gradle.properties
├── gradlew.bat
├── README-CN.md
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/nesemulator.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/nesemulator.jks
--------------------------------------------------------------------------------
/screen_shot/screen_shot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/screen_shot/screen_shot.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NesEmulator
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beseting/NesEmulator/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 14 15:00:03 CST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 | .idea
17 | secret.gpg
18 | secret.gradle
19 | /library
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/ym/nesemulator/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.ym.nesemulator
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | jcenter()
5 | google()
6 | mavenCentral()
7 | }
8 | }
9 | dependencyResolutionManagement {
10 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11 | repositories {
12 | jcenter()
13 | google()
14 | mavenCentral()
15 | }
16 | }
17 | rootProject.name = "NesEmulator"
18 | include ':app'
19 | //include ':library'
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/ym/nesemulator/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.ym.nesemulator
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.ym.nesemulator", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ym/nesemulator/App.kt:
--------------------------------------------------------------------------------
1 | package com.ym.nesemulator
2 |
3 | import android.app.Application
4 | import com.ym.library.sdk.EmulatorManager
5 | import com.ym.library.sdk.EmulatorSDK
6 |
7 | /**
8 | * @Desc:
9 | * @Author:Kevin
10 | * @Date:2023/2/22 17:52:51
11 | */
12 | class App : Application() {
13 |
14 | override fun onCreate() {
15 | super.onCreate()
16 | EmulatorSDK.init(this)
17 |
18 | EmulatorManager.getInstance()
19 | //是否展示界面控制器 默认:是
20 | .set(EmulatorManager.Settings.SHOW_CONTROLLER, false)
21 | //模拟器画质 默认:中
22 | .set(EmulatorManager.Settings.EMULATION_QUALITY,EmulatorManager.EmulationQuality.MEDIUM)
23 | //模拟器屏幕方向 默认:自动
24 | .set(EmulatorManager.Settings.SCREEN_ORIENTATION,EmulatorManager.EmulatorScreenOrientation.AUTO)
25 | //是否强制模拟器画面全屏 默认:否
26 | .set(EmulatorManager.Settings.FORCE_FULL_SCREEN, false)
27 |
28 | }
29 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
16 |
17 |
18 |
19 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
23 | -keepclasseswithmembers class com.ym.library.ui.gamegallery.GameDescription{*;}
24 | -keepclasseswithmembers class com.ym.library.ui.gamegallery.ZipRomFile{*;}
25 | -keepclassmembers class * extends com.ym.library.base.JniEmulator{public ** getInstance();}
26 |
27 | -keep class com.blankj.utilcode.** { *; }
28 | -keepclassmembers class com.blankj.utilcode.** { *; }
29 | -dontwarn com.blankj.utilcode.**
30 |
31 | -keep class **_FragmentFinder {*;}
32 | -keep class androidx.fragment.app.*{*;}
33 | -keep class com.qmuiteam.qmui.* {*;}
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | android.enableJetifier=true
19 | # Kotlin code style for this project: "official" or "obsolete":
20 | kotlin.code.style=official
21 | # Enables namespacing of each library's R class so that its R class includes only the
22 | # resources declared in the library itself and none from the library's dependencies,
23 | # thereby reducing the size of the R class for that library
24 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | android {
7 | namespace 'com.ym.nesemulator'
8 | compileSdk 33
9 |
10 | defaultConfig {
11 | applicationId "com.ym.nesemulator"
12 | minSdk 23
13 | targetSdk 33
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 |
19 | ndk {
20 | abiFilters 'arm64-v8a' // , 'armeabi-v7a', 'x86'
21 | }
22 | }
23 |
24 | signingConfigs {
25 | nesemulatorkey {
26 | storeFile file('nesemulator.jks')
27 | storePassword "123456"
28 | keyAlias 'nesemulator'
29 | keyPassword '123456'
30 | }
31 | }
32 |
33 | buildTypes {
34 | debug {
35 | signingConfig signingConfigs.nesemulatorkey
36 | }
37 | release {
38 | minifyEnabled true
39 | zipAlignEnabled true
40 | shrinkResources true
41 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
42 | signingConfig signingConfigs.nesemulatorkey
43 | }
44 | }
45 | applicationVariants.all { variant ->
46 | variant.outputs.all {
47 | def fileName = project.name + '-' + variant.name + '_v' +
48 | defaultConfig.versionName + ".apk"
49 | outputFileName = fileName
50 | }
51 | }
52 | compileOptions {
53 | sourceCompatibility JavaVersion.VERSION_1_8
54 | targetCompatibility JavaVersion.VERSION_1_8
55 | }
56 | kotlinOptions {
57 | jvmTarget = '1.8'
58 | }
59 | lintOptions {
60 | abortOnError false
61 | }
62 | }
63 |
64 | dependencies {
65 |
66 | implementation 'androidx.core:core-ktx:1.7.0'
67 | implementation 'androidx.appcompat:appcompat:1.4.1'
68 | implementation 'com.google.android.material:material:1.5.0'
69 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
70 | testImplementation 'junit:junit:4.13.2'
71 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
72 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
73 |
74 | implementation 'io.github.beseting:NesEmulator:1.0.1'
75 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ym/nesemulator/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.ym.nesemulator
2 |
3 | import android.Manifest
4 | import android.content.pm.PackageManager
5 | import android.os.Bundle
6 | import android.os.Environment
7 | import android.widget.Button
8 | import android.widget.Toast
9 | import androidx.appcompat.app.AppCompatActivity
10 | import androidx.core.content.ContextCompat
11 | import com.ym.library.sdk.EmulatorManager
12 | import java.io.File
13 |
14 | class MainActivity : AppCompatActivity() {
15 |
16 | private val btnStart: Button by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
17 | findViewById(R.id.btnStart)
18 | }
19 |
20 | override fun onCreate(savedInstanceState: Bundle?) {
21 | super.onCreate(savedInstanceState)
22 | setContentView(R.layout.activity_main)
23 |
24 | btnStart.setOnClickListener {
25 | reqPermission()
26 | }
27 | }
28 |
29 | /**
30 | * 请求权限
31 | */
32 | private fun reqPermission() {
33 | if (ContextCompat.checkSelfPermission(
34 | this,
35 | Manifest.permission.READ_EXTERNAL_STORAGE
36 | ) == PackageManager.PERMISSION_GRANTED &&
37 | ContextCompat.checkSelfPermission(
38 | this,
39 | Manifest.permission.WRITE_EXTERNAL_STORAGE
40 | ) == PackageManager.PERMISSION_GRANTED
41 | ) {
42 | startGame()
43 | } else {
44 | requestPermissions(
45 | arrayOf(
46 | Manifest.permission.READ_EXTERNAL_STORAGE,
47 | Manifest.permission.WRITE_EXTERNAL_STORAGE
48 | ), 1000
49 | )
50 | }
51 | }
52 |
53 | override fun onRequestPermissionsResult(
54 | requestCode: Int,
55 | permissions: Array,
56 | grantResults: IntArray
57 | ) {
58 | super.onRequestPermissionsResult(requestCode, permissions, grantResults)
59 | if (requestCode != 1000)
60 | return
61 | if (grantResults.isEmpty() || grantResults.size < 2) {
62 | Toast.makeText(this, "权限获取失败", Toast.LENGTH_SHORT).show()
63 | } else {
64 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
65 | startGame()
66 | } else {
67 | Toast.makeText(this, "权限获取失败", Toast.LENGTH_SHORT).show()
68 | }
69 | }
70 | }
71 |
72 | /**
73 | * 启动游戏
74 | */
75 | private fun startGame() {
76 | val romFile = File(Environment.getExternalStorageDirectory().path + "/魂斗罗1.nes")
77 | if (!romFile.exists()) {
78 | Toast.makeText(this, "文件不存在", Toast.LENGTH_SHORT).show()
79 | return
80 | }
81 | // 默认游戏界面
82 | // EmulatorManager.getInstance().startGame(this, romFile)
83 | //自定义游戏界面
84 | EmulatorManager.getInstance().startGame(this, MyEmulatorActivity::class.java, romFile)
85 | finish()
86 | }
87 | }
--------------------------------------------------------------------------------
/README-CN.md:
--------------------------------------------------------------------------------
1 | # Nes Emulator(Nes模拟器/FC任天堂/小霸王游戏)
2 |
3 | 
4 |
5 | ## :clap: Supporters
6 | [](https://github.com/Beseting/NesEmulator/stargazers)
7 |
8 | **简体中文 | [English](https://github.com/Beseting/NesEmulator/blob/master/README.md)**
9 |
10 | ## 1.引入
11 | `implementation 'io.github.beseting:NesEmulator:1.0.1'`
12 |
13 | ## 2.初始化
14 | `
15 | EmulatorSDK.init(appContext)//建议在Application中初始化SDK
16 | `
17 | ## 3.配置(可选)
18 | ```Kotlin
19 | EmulatorManager.getInstance()
20 | //是否展示界面控制器 默认:
21 | .set(EmulatorManager.Settings.SHOW_CONTROLLER, false)
22 | //模拟器画质 默认:中
23 | .set(EmulatorManager.Settings.EMULATION_QUALITY,
24 | EmulatorManager.EmulationQuality.MEDIUM)
25 | //模拟器屏幕方向 默认:自动
26 | .set(EmulatorManager.Settings.SCREEN_ORIENTATION,
27 | EmulatorManager.EmulatorScreenOrientation.AUTO)
28 | //是否强制模拟器画面全屏 默认:否
29 | .set(EmulatorManager.Settings.FORCE_FULL_SCREEN, false)
30 | ```
31 |
32 |
33 | ## 4.使用
34 | ### 4.1 方式一:使用默认游戏渲染界面
35 | ```Kotlin
36 | val romFile = File("/sdcard/魂斗罗1.nes")
37 | EmulatorManager.getInstance().startGame(mActivity, romFile)
38 | ```
39 | ### 4.2 方式二:使用自定义游戏渲染界面
40 | #### step1:继承BaseEmulatorActivity
41 | ```Kotlin
42 | class MyEmulatorActivity : BaseEmulatorActivity(){
43 |
44 | //自定义界面 可自定义界面控制器(方向+AB键等业务组件)
45 | //如需自定义控制器,可以在配置项中将默认的控制器关闭
46 | override fun getLayoutResId(): Int {
47 | return R.layout.activity_nes_emulator
48 | }
49 |
50 | override fun onCreate(savedInstanceState: Bundle?) {
51 | super.onCreate(savedInstanceState)
52 | // write your code...
53 |
54 | }
55 | }
56 | ```
57 | #### step2:跳转到此界面
58 | ```Kotlin
59 | val romFile = File("/sdcard/魂斗罗1.nes")
60 | EmulatorManager.getInstance()
61 | .startGame(mAct, MyEmulatorActivity::class.java,romFile)
62 | ```
63 | ## 5.API
64 | ```Kotlin
65 | //控制器键按下
66 | EmulatorManager.getInstance().pressKey(player, key)
67 | //控制器键松开
68 | EmulatorManager.getInstance().unPressKey(player, key)
69 | ```
70 | ### 5.1 角色属性
71 | |Player(角色)|描述|
72 | |:-|:-:|
73 | |PLAYER1|1P|
74 | |PLAYER2|2P|
75 |
76 | **调用方式:EmulatorManager.Player.PLAYER1**
77 | ***
78 | ### 5.2 控制器属性
79 | |ControllerKey(控制器键)|描述|
80 | |:-|:-|
81 | |UP|上|
82 | |DOWN|下|
83 | |LEFT|左|
84 | |RIGHT|右|
85 | |SELECT|选择|
86 | |START|开始|
87 | |A|按钮A|
88 | |B|按钮B|
89 | |A_TURBO|按钮A连续|
90 | |B_TURBO|按钮B连续|
91 |
92 | **调用方式:EmulatorManager.ControllerKey.UP**
93 | ***
94 | ### 5.3 设置属性
95 | |Settings(设置)|取值类型|默认值|描述|
96 | |:-|:-|:-|:-|
97 | |SHOW_CONTROLLER|Boolean|true|是否显示默认控制器|
98 | |EMULATION_QUALITY|EmulationQuality|MEDIUM|模拟器画质|
99 | |SCREEN_ORIENTATION|EmulatorScreenOrientation|AUTO|模拟器屏幕方向|
100 | |FORCE_FULL_SCREEN|Boolean|false|是否强制全屏|
101 |
102 | **调用方式:EmulatorManager.Settings.SHOW_CONTROLLER**
103 | ***
104 | ## 6.Thanks
105 | **此框架基于[NostalgiaLite](https://github.com/huzongyao/NostalgiaLite)进行二次封装开发,感谢作者[huzongyao](https://github.com/huzongyao)提供的基于AS NDK的可编译Jni/C++代码;NesEmulator库提供已完整编译so库(arm64-v8a、armeabi-v7a、x86),按需使用,提供SDK能力,封装相关操作API,快速引入开发!**
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Nes Emulator(Nes Emulator/FC/Nintendo Game)
2 |
3 | 
4 |
5 | ## :clap: Supporters
6 | [](https://github.com/Beseting/NesEmulator/stargazers)
7 |
8 | **[简体中文](https://github.com/Beseting/NesEmulator/blob/master/README-CN.md) | English**
9 |
10 | ## 1.Getting Started
11 | `implementation 'io.github.beseting:NesEmulator:1.0.1'`
12 |
13 | ## 2.initialization
14 | ```Kotlin
15 | //It is recommended to initialize the SDK in the Application
16 | EmulatorSDK.init(appContext)
17 | ```
18 | ## 3.Configuration(Optional)
19 | ```Kotlin
20 | EmulatorManager.getInstance()
21 | //is show view controller(default:true)
22 | .set(EmulatorManager.Settings.SHOW_CONTROLLER, false)
23 | //emulator display quality(default:MEDIUM)
24 | .set(EmulatorManager.Settings.EMULATION_QUALITY,
25 | EmulatorManager.EmulationQuality.MEDIUM)
26 | //emulator screen orientation(default:AUTO)
27 | .set(EmulatorManager.Settings.SCREEN_ORIENTATION,
28 | EmulatorManager.EmulatorScreenOrientation.AUTO)
29 | //is force emulator display fullscreen(default:false)
30 | .set(EmulatorManager.Settings.FORCE_FULL_SCREEN, false)
31 | ```
32 |
33 |
34 | ## 4.Use
35 | ### 4.1 Use the default rendering
36 | ```Kotlin
37 | val romFile = File("/sdcard/contra.nes")
38 | EmulatorManager.getInstance().startGame(mActivity, romFile)
39 | ```
40 | ### 4.2 Use custom game rendering
41 | #### step1:Extends BaseEmulatorActivity
42 | ```Kotlin
43 | //Custom Activity
44 | class MyEmulatorActivity : BaseEmulatorActivity(){
45 |
46 | //Customizable Display Controller(Direction&A/B Button)
47 | //If You Want Custom Display Controller,You Can Hide The Default Show.
48 | override fun getLayoutResId(): Int {
49 | return R.layout.activity_nes_emulator
50 | }
51 |
52 | override fun onCreate(savedInstanceState: Bundle?) {
53 | super.onCreate(savedInstanceState)
54 | // Write Your Code...
55 |
56 | }
57 | }
58 | ```
59 | #### step2:To Your Custom Activity
60 | ```Kotlin
61 | val romFile = File("/sdcard/contra.nes")
62 | EmulatorManager.getInstance()
63 | .startGame(mAct, MyEmulatorActivity::class.java,romFile)
64 | ```
65 | ## 5.API
66 | ```Kotlin
67 | //Controller Key Press
68 | EmulatorManager.getInstance().pressKey(player, key)
69 | //Controller Key Unpress
70 | EmulatorManager.getInstance().unPressKey(player, key)
71 | ```
72 | ### 5.1 Role Properties
73 | |Player(Role)|Description|
74 | |:-|:-:|
75 | |PLAYER1|1P|
76 | |PLAYER2|2P|
77 |
78 | **Use:EmulatorManager.Player.PLAYER1**
79 | ***
80 | ### 5.2 Controller Properties
81 | |ControllerKey(Controller Key)|Description|
82 | |:-|:-|
83 | |UP|direction for up|
84 | |DOWN|direction for down|
85 | |LEFT|direction for left|
86 | |RIGHT|direction for right|
87 | |SELECT|button for select|
88 | |START|button for start|
89 | |A|button for A|
90 | |B|button for B|
91 | |A_TURBO|button for A Turbo|
92 | |B_TURBO|button for B Turbo|
93 |
94 | **Use:EmulatorManager.ControllerKey.UP**
95 | ***
96 | ### 5.3 Setting Properties
97 | |Settings|Type|Default|Description|
98 | |:-|:-|:-|:-|
99 | |SHOW_CONTROLLER|Boolean|true|is show default controller|
100 | |EMULATION_QUALITY|EmulationQuality|MEDIUM|display quality|
101 | |SCREEN_ORIENTATION|EmulatorScreenOrientation|AUTO|screen direction|
102 | |FORCE_FULL_SCREEN|Boolean|false|is force fullscreen|
103 |
104 | **Use:EmulatorManager.Settings.SHOW_CONTROLLER**
105 | ***
106 | ## 6.Thanks
107 | **This library is based on [NostalgiaLite](https://github.com/huzongyao/NostalgiaLite) to develop plus,Thanks the author [huzongyao](https://github.com/huzongyao) provided based on Android Studio NDK's compilable for Jni/C++ code.NesEmulator library provide the fully compiled so library(arm64-v8a、armeabi-v7a、x86),As your need,Provide SDK capabilities,Package the API,Fast develop.Enjoy it!**
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ym/nesemulator/MyEmulatorActivity.kt:
--------------------------------------------------------------------------------
1 | package com.ym.nesemulator
2 |
3 | import android.annotation.SuppressLint
4 | import android.os.Bundle
5 | import android.view.MotionEvent
6 | import android.view.View
7 | import android.view.View.OnTouchListener
8 | import android.widget.TextView
9 | import com.ym.library.base.BaseEmulatorActivity
10 | import com.ym.library.sdk.EmulatorManager
11 |
12 | /**
13 | * @Desc:自定义Nes游戏界面 在这里可以定义界面控件 诸如按钮等
14 | * @Author:Kevin
15 | * @Date:2023/2/17 15:25:37
16 | */
17 | class MyEmulatorActivity : BaseEmulatorActivity(), OnTouchListener {
18 |
19 | //组件map 组件id为key value储存游戏玩家和对应的控制key
20 | private val keyCompMap: HashMap>> =
21 | HashMap()
22 |
23 |
24 | override fun getLayoutResId(): Int {
25 | return R.layout.activity_nes_emulator
26 | }
27 |
28 | override fun onCreate(savedInstanceState: Bundle?) {
29 | super.onCreate(savedInstanceState)
30 | this.initKeyCompMap()
31 | }
32 |
33 | /**
34 | * 初始化控件-key的映射
35 | */
36 | @SuppressLint("ClickableViewAccessibility")
37 | private fun initKeyCompMap() {
38 | //Player 1
39 | findViewById(R.id.keyLeft)?.apply {
40 | keyCompMap[id] = Pair(
41 | EmulatorManager.Player.PLAYER1,
42 | arrayListOf(EmulatorManager.ControllerKey.LEFT)
43 | )
44 | this.setOnTouchListener(this@MyEmulatorActivity)
45 | }
46 | findViewById(R.id.keyUp)?.apply {
47 | keyCompMap[id] =
48 | Pair(EmulatorManager.Player.PLAYER1, arrayListOf(EmulatorManager.ControllerKey.UP))
49 | this.setOnTouchListener(this@MyEmulatorActivity)
50 | }
51 | findViewById(R.id.keyRight)?.apply {
52 | keyCompMap[id] = Pair(
53 | EmulatorManager.Player.PLAYER1,
54 | arrayListOf(EmulatorManager.ControllerKey.RIGHT)
55 | )
56 | this.setOnTouchListener(this@MyEmulatorActivity)
57 | }
58 | findViewById(R.id.keyDown)?.apply {
59 | keyCompMap[id] = Pair(
60 | EmulatorManager.Player.PLAYER1,
61 | arrayListOf(EmulatorManager.ControllerKey.DOWN)
62 | )
63 | this.setOnTouchListener(this@MyEmulatorActivity)
64 | }
65 | findViewById(R.id.keyLeftUp)?.apply {
66 | keyCompMap[id] = Pair(
67 | EmulatorManager.Player.PLAYER1,
68 | arrayListOf(EmulatorManager.ControllerKey.LEFT, EmulatorManager.ControllerKey.UP)
69 | )
70 | this.setOnTouchListener(this@MyEmulatorActivity)
71 | }
72 | findViewById(R.id.keyRightUp)?.apply {
73 | keyCompMap[id] = Pair(
74 | EmulatorManager.Player.PLAYER1,
75 | arrayListOf(EmulatorManager.ControllerKey.RIGHT, EmulatorManager.ControllerKey.UP)
76 | )
77 | this.setOnTouchListener(this@MyEmulatorActivity)
78 | }
79 | findViewById(R.id.keyRightDown)?.apply {
80 | keyCompMap[id] = Pair(
81 | EmulatorManager.Player.PLAYER1,
82 | arrayListOf(EmulatorManager.ControllerKey.RIGHT, EmulatorManager.ControllerKey.DOWN)
83 | )
84 | this.setOnTouchListener(this@MyEmulatorActivity)
85 | }
86 | findViewById(R.id.keyLeftDown)?.apply {
87 | keyCompMap[id] = Pair(
88 | EmulatorManager.Player.PLAYER1,
89 | arrayListOf(EmulatorManager.ControllerKey.LEFT, EmulatorManager.ControllerKey.DOWN)
90 | )
91 | this.setOnTouchListener(this@MyEmulatorActivity)
92 | }
93 | findViewById(R.id.keySelect)?.apply {
94 | keyCompMap[id] = Pair(
95 | EmulatorManager.Player.PLAYER1,
96 | arrayListOf(EmulatorManager.ControllerKey.SELECT)
97 | )
98 | this.setOnTouchListener(this@MyEmulatorActivity)
99 | }
100 | findViewById(R.id.keyStart)?.apply {
101 | keyCompMap[id] = Pair(
102 | EmulatorManager.Player.PLAYER1,
103 | arrayListOf(EmulatorManager.ControllerKey.START)
104 | )
105 | this.setOnTouchListener(this@MyEmulatorActivity)
106 | }
107 | findViewById(R.id.keyA)?.apply {
108 | keyCompMap[id] = Pair(
109 | EmulatorManager.Player.PLAYER1,
110 | arrayListOf(EmulatorManager.ControllerKey.A)
111 | )
112 | this.setOnTouchListener(this@MyEmulatorActivity)
113 | }
114 | findViewById(R.id.keyB)?.apply {
115 | keyCompMap[id] = Pair(
116 | EmulatorManager.Player.PLAYER1,
117 | arrayListOf(EmulatorManager.ControllerKey.B)
118 | )
119 | this.setOnTouchListener(this@MyEmulatorActivity)
120 | }
121 | findViewById(R.id.keyATurbo)?.apply {
122 | keyCompMap[id] = Pair(
123 | EmulatorManager.Player.PLAYER1,
124 | arrayListOf(EmulatorManager.ControllerKey.A_TURBO)
125 | )
126 | this.setOnTouchListener(this@MyEmulatorActivity)
127 | }
128 | findViewById(R.id.keyBTurbo)?.apply {
129 | keyCompMap[id] = Pair(
130 | EmulatorManager.Player.PLAYER1,
131 | arrayListOf(EmulatorManager.ControllerKey.B_TURBO)
132 | )
133 | this.setOnTouchListener(this@MyEmulatorActivity)
134 | }
135 |
136 | //Player 2
137 | findViewById(R.id.keyLeft2)?.apply {
138 | keyCompMap[id] = Pair(
139 | EmulatorManager.Player.PLAYER2,
140 | arrayListOf(EmulatorManager.ControllerKey.LEFT)
141 | )
142 | this.setOnTouchListener(this@MyEmulatorActivity)
143 | }
144 | findViewById(R.id.keyUp2)?.apply {
145 | keyCompMap[id] =
146 | Pair(EmulatorManager.Player.PLAYER2, arrayListOf(EmulatorManager.ControllerKey.UP))
147 | this.setOnTouchListener(this@MyEmulatorActivity)
148 | }
149 | findViewById(R.id.keyRight2)?.apply {
150 | keyCompMap[id] = Pair(
151 | EmulatorManager.Player.PLAYER2,
152 | arrayListOf(EmulatorManager.ControllerKey.RIGHT)
153 | )
154 | this.setOnTouchListener(this@MyEmulatorActivity)
155 | }
156 | findViewById(R.id.keyDown2)?.apply {
157 | keyCompMap[id] = Pair(
158 | EmulatorManager.Player.PLAYER2,
159 | arrayListOf(EmulatorManager.ControllerKey.DOWN)
160 | )
161 | this.setOnTouchListener(this@MyEmulatorActivity)
162 | }
163 | findViewById(R.id.keyLeftUp2)?.apply {
164 | keyCompMap[id] = Pair(
165 | EmulatorManager.Player.PLAYER2,
166 | arrayListOf(EmulatorManager.ControllerKey.LEFT, EmulatorManager.ControllerKey.UP)
167 | )
168 | this.setOnTouchListener(this@MyEmulatorActivity)
169 | }
170 | findViewById(R.id.keyRightUp2)?.apply {
171 | keyCompMap[id] = Pair(
172 | EmulatorManager.Player.PLAYER2,
173 | arrayListOf(EmulatorManager.ControllerKey.RIGHT, EmulatorManager.ControllerKey.UP)
174 | )
175 | this.setOnTouchListener(this@MyEmulatorActivity)
176 | }
177 | findViewById(R.id.keyRightDown2)?.apply {
178 | keyCompMap[id] = Pair(
179 | EmulatorManager.Player.PLAYER2,
180 | arrayListOf(EmulatorManager.ControllerKey.RIGHT, EmulatorManager.ControllerKey.DOWN)
181 | )
182 | this.setOnTouchListener(this@MyEmulatorActivity)
183 | }
184 | findViewById(R.id.keyLeftDown2)?.apply {
185 | keyCompMap[id] = Pair(
186 | EmulatorManager.Player.PLAYER2,
187 | arrayListOf(EmulatorManager.ControllerKey.LEFT, EmulatorManager.ControllerKey.DOWN)
188 | )
189 | this.setOnTouchListener(this@MyEmulatorActivity)
190 | }
191 | findViewById(R.id.keySelect2)?.apply {
192 | keyCompMap[id] = Pair(
193 | EmulatorManager.Player.PLAYER2,
194 | arrayListOf(EmulatorManager.ControllerKey.SELECT)
195 | )
196 | this.setOnTouchListener(this@MyEmulatorActivity)
197 | }
198 | findViewById(R.id.keyStart2)?.apply {
199 | keyCompMap[id] = Pair(
200 | EmulatorManager.Player.PLAYER2,
201 | arrayListOf(EmulatorManager.ControllerKey.START)
202 | )
203 | this.setOnTouchListener(this@MyEmulatorActivity)
204 | }
205 | findViewById(R.id.keyA2)?.apply {
206 | keyCompMap[id] = Pair(
207 | EmulatorManager.Player.PLAYER2,
208 | arrayListOf(EmulatorManager.ControllerKey.A)
209 | )
210 | this.setOnTouchListener(this@MyEmulatorActivity)
211 | }
212 | findViewById(R.id.keyB2)?.apply {
213 | keyCompMap[id] = Pair(
214 | EmulatorManager.Player.PLAYER2,
215 | arrayListOf(EmulatorManager.ControllerKey.B)
216 | )
217 | this.setOnTouchListener(this@MyEmulatorActivity)
218 | }
219 | findViewById(R.id.keyATurbo2)?.apply {
220 | keyCompMap[id] = Pair(
221 | EmulatorManager.Player.PLAYER2,
222 | arrayListOf(EmulatorManager.ControllerKey.A_TURBO)
223 | )
224 | this.setOnTouchListener(this@MyEmulatorActivity)
225 | }
226 | findViewById(R.id.keyBTurbo2)?.apply {
227 | keyCompMap[id] = Pair(
228 | EmulatorManager.Player.PLAYER2,
229 | arrayListOf(EmulatorManager.ControllerKey.B_TURBO)
230 | )
231 | this.setOnTouchListener(this@MyEmulatorActivity)
232 | }
233 | }
234 |
235 | @SuppressLint("ClickableViewAccessibility")
236 | override fun onTouch(v: View?, event: MotionEvent?): Boolean {
237 | when (event?.action) {
238 | MotionEvent.ACTION_DOWN -> {//按下
239 | val player = this.keyCompMap[v?.id]?.first
240 | this.keyCompMap[v?.id]?.second?.forEach {
241 | EmulatorManager.getInstance()
242 | .pressKey(player, it)
243 | }
244 | }
245 | MotionEvent.ACTION_UP,
246 | MotionEvent.ACTION_CANCEL -> {//松开
247 | val player = this.keyCompMap[v?.id]?.first
248 | this.keyCompMap[v?.id]?.second?.forEach {
249 | EmulatorManager.getInstance()
250 | .unPressKey(player, it)
251 | }
252 | }
253 | }
254 | return true
255 | }
256 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_nes_emulator.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
22 |
23 |
34 |
35 |
48 |
49 |
63 |
64 |
77 |
78 |
92 |
93 |
106 |
107 |
121 |
122 |
135 |
136 |
144 |
145 |
156 |
157 |
167 |
168 |
169 |
183 |
184 |
198 |
199 |
213 |
214 |
228 |
229 |
230 |
231 |
245 |
246 |
257 |
258 |
271 |
272 |
286 |
287 |
300 |
301 |
315 |
316 |
329 |
330 |
344 |
345 |
358 |
359 |
367 |
368 |
379 |
380 |
390 |
391 |
392 |
406 |
407 |
421 |
422 |
436 |
437 |
451 |
--------------------------------------------------------------------------------