Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Oct 21, 2023
1 parent 977ab53 commit 4c0931b
Show file tree
Hide file tree
Showing 46 changed files with 955 additions and 26 deletions.
46 changes: 22 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 12)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fbracket-depth=4096")
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")

project(Alber)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
Expand All @@ -35,26 +35,26 @@ option(ENABLE_VULKAN "Enable Vulkan rendering backend" ON)
option(ENABLE_LTO "Enable link-time optimization" OFF)
option(ENABLE_USER_BUILD "Make a user-facing build. These builds have various assertions disabled, LTO, and more" OFF)
option(ENABLE_HTTP_SERVER "Enable HTTP server. Used for Discord bot support" OFF)
option(ENABLE_DISCORD_RPC "Compile with Discord RPC support (disabled by default)" ON)
option(ENABLE_DISCORD_RPC "Compile with Discord RPC support (disabled by default)" OFF)
option(ENABLE_LUAJIT "Enable scripting with the Lua programming language" ON)
option(ENABLE_QT_GUI "Enable the Qt GUI. If not selected then the emulator uses a minimal SDL-based UI instead" OFF)
option(BUILD_HYDRA_CORE "Build a Hydra core" OFF)

include_directories(${PROJECT_SOURCE_DIR}/include/)
include_directories(${PROJECT_SOURCE_DIR}/include/kernel)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/kernel)
include_directories (${FMT_INCLUDE_DIR})
include_directories(third_party/boost/)
include_directories(third_party/elfio/)
include_directories(third_party/imgui/)
include_directories(third_party/dynarmic/src)
include_directories(third_party/cryptopp/)
include_directories(third_party/cityhash/include)
include_directories(third_party/result/include)
include_directories(third_party/xxhash/include)
include_directories(third_party/httplib)
include_directories(third_party/stb)
include_directories(third_party/opengl)
include_directories(third_party/mio/single_include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/boost/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/elfio/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/imgui/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/dynarmic/src)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/cryptopp/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/cityhash/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/result/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/xxhash/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/httplib)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/stb)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/opengl)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_party/mio/single_include)

add_compile_definitions(NOMINMAX) # Make windows.h not define min/max macros because third-party deps don't like it
add_compile_definitions(WIN32_LEAN_AND_MEAN) # Make windows.h not include literally everything
Expand All @@ -81,17 +81,15 @@ endif()
set(SDL_STATIC ON CACHE BOOL "" FORCE)
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
set(SDL_TEST OFF CACHE BOOL "" FORCE)
add_subdirectory(third_party/SDL2)

add_subdirectory(third_party/toml11)
include_directories(${SDL2_INCLUDE_DIR})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third_party/toml11)
include_directories(third_party/toml11)
include_directories(third_party/glm)

add_subdirectory(third_party/cmrc)

set(BOOST_ROOT "${CMAKE_SOURCE_DIR}/third_party/boost")
set(Boost_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/third_party/boost")
set(BOOST_ROOT "${CMAKE_CURRENT_LIST_DIR}/third_party/boost")
set(Boost_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/third_party/boost")
set(Boost_NO_SYSTEM_PATHS ON)
add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE) # Forbid Boost from using std::unary_function (Fixes MacOS build)

Expand Down Expand Up @@ -192,8 +190,8 @@ if(ENABLE_QT_GUI)
source_group("Header Files\\Qt" FILES ${FRONTEND_HEADER_FILES})
include_directories(${Qt6Gui_PRIVATE_INCLUDE_DIRS})
else()
set(FRONTEND_SOURCE_FILES src/panda_sdl/main.cpp src/panda_sdl/frontend_sdl.cpp)
set(FRONTEND_HEADER_FILES "")
# set(FRONTEND_SOURCE_FILES src/panda_sdl/main.cpp src/panda_sdl/frontend_sdl.cpp)
# set(FRONTEND_HEADER_FILES "")
endif()

set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/termcolor.hpp
Expand Down Expand Up @@ -390,7 +388,7 @@ if(ENABLE_LTO OR ENABLE_USER_BUILD)
set_target_properties(Alber PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

target_link_libraries(Alber PRIVATE dynarmic SDL2-static cryptopp glad resources_console_fonts)
target_link_libraries(Alber PRIVATE log dynarmic cryptopp glad resources_console_fonts)

if(ENABLE_DISCORD_RPC AND NOT ANDROID)
target_compile_definitions(Alber PUBLIC "PANDA3DS_ENABLE_DISCORD_RPC=1")
Expand Down
1 change: 1 addition & 0 deletions include/cpu_dynarmic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "helpers.hpp"
#include "kernel.hpp"
#include "memory.hpp"
#include <android/log.h>

class CPU;

Expand Down
4 changes: 4 additions & 0 deletions include/emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ enum class ROMType {
HB_3DSX,
};

struct CrashShitdroid {
std::optional<std::filesystem::path> path = std::nullopt;
};

class Emulator {
EmulatorConfig config;
CPU cpu;
Expand Down
4 changes: 4 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#include "helpers.hpp"
#include "toml.hpp"

#include <android/log.h>
// Largely based on https://github.com/nba-emu/NanoBoyAdvance/blob/master/src/platform/core/src/config.cpp
// We are legally allowed, as per the author's wish, to use the above code without any licensing restrictions
// However we still want to follow the license as closely as possible and offer the proper attributions.

EmulatorConfig::EmulatorConfig(const std::filesystem::path& path) { load(path); }

void EmulatorConfig::load(const std::filesystem::path& path) {
__android_log_print(3, "Panda3D", "Loading config file from %s", path.c_str());
// If the configuration file does not exist, create it and return
std::error_code error;
if (!std::filesystem::exists(path, error)) {
Expand Down Expand Up @@ -82,6 +84,7 @@ void EmulatorConfig::load(const std::filesystem::path& path) {
sdWriteProtected = toml::find_or<toml::boolean>(sd, "WriteProtectVirtualSD", false);
}
}
__android_log_print(3, "Panda3D", "Loaded config file from %s", path.c_str());
}

void EmulatorConfig::save(const std::filesystem::path& path) {
Expand Down Expand Up @@ -116,4 +119,5 @@ void EmulatorConfig::save(const std::filesystem::path& path) {
std::ofstream file(path, std::ios::out);
file << data;
file.close();
__android_log_print(3, "Panda3D", "Save config file from %s", path.c_str());
}
1 change: 1 addition & 0 deletions src/core/CPU/cpu_dynarmic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CPU::CPU(Memory& mem, Kernel& kernel) : mem(mem), env(mem, kernel) {
config.processor_id = 0;

jit = std::make_unique<Dynarmic::A32::Jit>(config);
__android_log_print(ANDROID_LOG_INFO, "Dynarmic", "Dynarmic initialized");
}

void CPU::reset() {
Expand Down
2 changes: 2 additions & 0 deletions src/core/PICA/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifdef PANDA3DS_ENABLE_VULKAN
#include "renderer_vk/renderer_vk.hpp"
#endif
#include<android/log.h>

constexpr u32 topScreenWidth = 240;
constexpr u32 topScreenHeight = 400;
Expand Down Expand Up @@ -58,6 +59,7 @@ GPU::GPU(Memory& mem, EmulatorConfig& config) : mem(mem), config(config) {
break;
}
}
__android_log_print(ANDROID_LOG_INFO, "Panda3D", "GPU::GPU()");
}

void GPU::reset() {
Expand Down
2 changes: 2 additions & 0 deletions src/core/cheats.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "cheats.hpp"

#include <android/log.h>
Cheats::Cheats(Memory& mem, HIDService& hid) : ar(mem, hid) { reset(); }

void Cheats::reset() {
clear(); // Clear loaded cheats
ar.reset(); // Reset ActionReplay
__android_log_print(ANDROID_LOG_INFO, "Cheats", "Cheats reset");
}

void Cheats::addCheat(const Cheat& cheat) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/kernel/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "kernel.hpp"
#include "kernel_types.hpp"
#include "cpu.hpp"
#include <android/log.h>

Kernel::Kernel(CPU& cpu, Memory& mem, GPU& gpu, const EmulatorConfig& config)
: cpu(cpu), regs(cpu.regs()), mem(mem), handleCounter(0), serviceManager(regs, mem, gpu, currentProcess, *this, config) {
Expand All @@ -24,6 +25,7 @@ Kernel::Kernel(CPU& cpu, Memory& mem, GPU& gpu, const EmulatorConfig& config)
}

setVersion(1, 69);
__android_log_print(ANDROID_LOG_INFO, "Kernel", "Kernel initialized");
}

void Kernel::serviceSVC(u32 svc) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "config_mem.hpp"
#include "resource_limits.hpp"
#include "services/ptm.hpp"
#include <android/log.h>

CMRC_DECLARE(ConsoleFonts);

Expand All @@ -20,6 +21,7 @@ Memory::Memory(u64& cpuTicks, const EmulatorConfig& config) : cpuTicks(cpuTicks)
readTable.resize(totalPageCount, 0);
writeTable.resize(totalPageCount, 0);
memoryInfo.reserve(32); // Pre-allocate some room for memory allocation info to avoid dynamic allocs
__android_log_print(ANDROID_LOG_INFO, "Memory", "Memory initialized");
}

void Memory::reset() {
Expand Down
4 changes: 2 additions & 2 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "emulator.hpp"

#include <SDL_filesystem.h>

#include <fstream>

#ifdef _WIN32
Expand All @@ -21,6 +19,7 @@ Emulator::Emulator()
, httpServer(this)
#endif
{
__android_log_print(ANDROID_LOG_INFO, "Panda3D", "Emulator::Emulator()");
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
if (config.discordRpcEnabled) {
discordRpc.init();
Expand All @@ -33,6 +32,7 @@ Emulator::Emulator()
Emulator::~Emulator() {
config.save(std::filesystem::current_path() / "config.toml");
lua.close();
__android_log_print(ANDROID_LOG_INFO, "DESTURCTOR", "Destructor");

#ifdef PANDA3DS_ENABLE_DISCORD_RPC
discordRpc.stop();
Expand Down
15 changes: 15 additions & 0 deletions src/pandroid/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions src/pandroid/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
87 changes: 87 additions & 0 deletions src/pandroid/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

android {
namespace = "com.panda3ds.panda3ds"
compileSdk = 34

defaultConfig {
applicationId = "com.panda3ds.panda3ds"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
packagingOptions {
doNotStrip += "**.so"
}
externalNativeBuild {
cmake {
cppFlags += "-Wl,--build-id -g"
arguments += "-DANDROID_ARM_MODE=arm -DANDROID_STL=c++_shared"
}
}
ndk {
abiFilters += listOf("x86_64")
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
version = "3.22.1"
}
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}//
}

dependencies {
implementation("androidx.core:core-ktx:1.8.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.activity:activity-compose:1.8.0")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}
21 changes: 21 additions & 0 deletions src/pandroid/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
29 changes: 29 additions & 0 deletions src/pandroid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light"
tools:targetApi="31">
<activity
android:name="com.panda3ds.panda3ds.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Panda3DS">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />

</manifest>
Loading

0 comments on commit 4c0931b

Please sign in to comment.