Skip to content

Commit

Permalink
Project: Redefining the apps versioning scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
shadergz committed Dec 21, 2023
1 parent 1a0c99c commit 992c255
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Cosmic Project

### Project Progress:
- Progression: ```11%```
- Progression: ```12%```
- Current top priority: Add more instructions to the respective EE, IOP, and VUs interpreters
- Target for the first demo release: 2025

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
minSdk = 31

targetSdk = 34
versionCode = 115
versionName = "1.1.5"
versionCode = 16
versionName = "0.0.16"
ndk {
abiFilters.clear()
abiFilters.add("arm64-v8a")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

cmake_minimum_required(VERSION 3.22.1)

project(CosmicEmu LANGUAGES C CXX ASM VERSION "115")
project(CosmicEmu LANGUAGES C CXX ASM VERSION 0.0)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/cpp/bios_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ Java_emu_cosmic_helpers_BiosHelper_00024Companion_addBios(JNIEnv* env, jobject t
info.fillInstance(object);
return object;
}

info.chkAndLoad(biosHld);

biosMgr->storeAndFill(object, std::move(info));

return object;
}
extern "C"
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/cpp/cosmic/common/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ namespace cosmic {
std::shared_ptr<GlobalLogger> userLog;
std::shared_ptr<CoreApplication> app;

CoreApplication::CoreApplication()
: simulated(std::make_shared<console::VirtDevices>()) {
CoreApplication::CoreApplication() :
simulated(std::make_shared<console::VirtDevices>()) {

apiLevel = android_get_device_api_level();
std::array<bool, 1> feats{
riscFeatures.haveCrc32C()
Expand All @@ -28,12 +29,10 @@ namespace cosmic {
scene = std::make_shared<gpu::ExhibitionEngine>(device->android);
vm = std::make_unique<vm::EmuVM>(device->android, simulated, scene);
}

std::shared_ptr<hle::HleBiosGroup> CoreApplication::getBiosMgr() {
auto group{vm->biosHLE->group};
auto group{vm->biosHigh->group};
return group;
}

const std::string& CoreApplication::getDeviceName() {
if (artDeviceName.empty()) {
std::array<char, 40> model;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/engine/ee_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace cosmic::engine {
GPRs[0].dw[1] = 0;
eeTlb = std::make_shared<mio::TlbCache>(observer->controller->mapped);

device->getStates()->eeMode.observer = [this]() {
device->getStates()->addObserver(os::EeMode, [this](JNIEnv* os) {
procCpuMode = static_cast<ExecutionMode>(*device->getStates()->eeMode);
if (executor)
executor.reset();
Expand All @@ -98,7 +98,7 @@ namespace cosmic::engine {
} else if (procCpuMode == JitRe) {
executor = std::make_unique<rearm::ee64::EeArm64Jitter>(*this);
}
};
});
}
void EeMipsCore::invalidateExecRegion(u32 address) {
if (address & 0x1fffffff)
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/cpp/cosmic/fs/bios_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace cosmic::fs {
void BiosLoader::triggerBios(hle::BiosInfo& info) {
biosf = info.fd;
}

bool BiosLoader::fetchBiosInfo(JNIEnv* android, hle::BiosInfo& bios) {
if (!romHeader)
romHeader = std::make_unique<os::MappedMemory<u8>>(hdrSize);
Expand All @@ -40,7 +39,6 @@ namespace cosmic::fs {
fillVersion(android, bios, std::span<char>{bit_cast<char*>(romGroup.data()), romGroup.size()});
return true;
}

bool BiosLoader::isABios() {
// Discard game.bin because it isn't the kernel
static std::array<u8, 6> biosId{'K', 'E', 'R', 'N', 'E', 'L'};
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/gpu/graphics_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ namespace cosmic::gpu {
hardware = std::make_unique<RenderDriver>();
hardware->pickUserRender(renderMode);

device->getStates()->customDriver.observer = [this]() {
device->getStates()->addObserver(os::GpuCustomDriver, [this](JNIEnv* os) {
graphicsApi = HardwareVulkan;
hardware->pickUserRender(graphicsApi, true);
updateLayer();
};
});
displayApiVersion = displayVersion;
}
u32 GraphicsLayer::reloadReferences() {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/cpp/cosmic/hle/bios_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
namespace cosmic::hle {
class BiosInfo : java::JavaClass {
public:
BiosInfo(JNIEnv* env)
: java::JavaClass(env, "emu/cosmic/data/BiosInfo") {}
BiosInfo(JNIEnv* env) : java::JavaClass(env, "emu/cosmic/data/BiosInfo") {}
i32 position;
DescriptorRaii fd;
u32 dataCRC;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/iop/iop_cop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace cosmic::iop {
void IopCop::mtc(u8 copId, u32 regVal) {
std::bitset<8*8> leaf{status.to64()};
if (copId != 12) {
throw AppFail("Unknown register with index {} being used", copId);
// throw AppFail("Unknown register with index {} being used", copId);
}
leaf[0] = regVal & 1;
leaf[1] = regVal & (1 << 1);
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/cpp/cosmic/java/device_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <java/device_handler.h>

namespace cosmic::java {
JvmManager::JvmManager(JavaVM* jvm)
: androidRuntime(jvm) {
JvmManager::JvmManager(JavaVM* jvm) : androidRuntime(jvm) {
void* env{};
androidRuntime->GetEnv(&env, JNI_VERSION_1_6);
android = reinterpret_cast<JNIEnv*>(env);

state = std::make_shared<os::OSMachState>(android);
state = std::make_shared<os::OsMachState>(android);
}
}
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/java/device_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ namespace cosmic::java {
JNIEnv* android{};

private:
std::shared_ptr<os::OSMachState> state;
std::shared_ptr<os::OsMachState> state;
};
}
18 changes: 16 additions & 2 deletions app/src/main/cpp/cosmic/os/system_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ namespace cosmic::os {
"dsdbBiosPath",
"dsdbSchedAffinity"
};
void OsMachState::addObserver(StateId state, ObserveFunc observe) {
if (state == AppStorage) {
appStorage.observers.push_back(observe);
} else if (state == GpuTurboMode) {
turboMode.observers.push_back(observe);
} else if (state == GpuCustomDriver) {
customDriver.observers.push_back(observe);
} else if (state == EeMode) {
eeMode.observers.push_back(observe);
} else if (state == BiosPath) {
biosPath.observers.push_back(observe);
} else if (state == SchedulerAffinity) {
schedAffinity.observers.push_back(observe);
}
}

void OSMachState::syncAllSettings() {
void OsMachState::syncAllSettings() {
appStorage.updateValue();
turboMode.updateValue();
customDriver.updateValue();
eeMode.updateValue();
biosPath.updateValue();
// schedAffinity.updateValue();
}
}
52 changes: 28 additions & 24 deletions app/src/main/cpp/cosmic/os/system_state.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include <array>
#include <functional>
#include <vector>
#include <cassert>

#include <java/jclasses.h>
#include <common/types.h>
namespace cosmic::os {
enum StateIDs : u16 {
enum StateId : u16 {
AppStorage,
GpuTurboMode,
GpuCustomDriver,
Expand All @@ -15,18 +17,19 @@ namespace cosmic::os {
SchedulerAffinity
};
extern std::array<const std::string, 6> dsKeys;
using ObserveFunc = std::function<void(JNIEnv*)>;

template <typename T>
struct OSVariable {
struct OsVariable {
public:
OSVariable<T>(JNIEnv* androidEnv, const std::string& stateName)
: osEnv(androidEnv), cachedState() {
OsVariable<T>(JNIEnv* androidEnv, const std::string& stateName) :
osEnv(androidEnv), cachedState() {

auto state{osEnv->NewStringUTF(stateName.data())};
varName = static_cast<jstring>(osEnv->NewGlobalRef(state));

osEnv->DeleteLocalRef(state);
}
~OSVariable() {
~OsVariable() {
osEnv->DeleteGlobalRef(varName);
}
void operator=(const T&& variable) {
Expand All @@ -44,65 +47,66 @@ namespace cosmic::os {
T cachedState;
jstring varName;

std::function<void()> observer;
std::vector<ObserveFunc> observers{2};
};

template<typename T>
void OSVariable<T>::updateValue() {
void OsVariable<T>::updateValue() {
auto settingsClass{osEnv->FindClass("emu/cosmic/data/CosmicSettings")};
auto updateEnvMethod{osEnv->GetStaticMethodID(settingsClass, "getDataStoreValue", "(Ljava/lang/String;)Ljava/lang/Object;")};

if (osEnv->ExceptionCheck())
osEnv->ExceptionOccurred();

auto result{osEnv->CallStaticObjectMethod(settingsClass, updateEnvMethod, varName)};
bool hasChanged{false};
bool isModified{false};
T stateValue;

if constexpr (std::is_same<T, java::JNIString>::value) {
stateValue = java::JNIString(osEnv, bit_cast<jstring>(result));
hasChanged = stateValue != cachedState;
isModified = stateValue != cachedState;
} else if constexpr (std::is_same<T, java::JNIInteger>::value) {
auto getInt{osEnv->GetMethodID(osEnv->GetObjectClass(result), "intValue", "()I")};
stateValue = osEnv->CallIntMethod(result, getInt);
hasChanged = stateValue != cachedState;
isModified = stateValue != cachedState;
} else if constexpr (std::is_same<T, java::JNIBool>::value) {
assert(osEnv->IsInstanceOf(result, osEnv->FindClass("java/lang/Boolean")));
auto getBool{osEnv->GetMethodID(osEnv->GetObjectClass(result), "booleanValue", "()Z")};
stateValue = osEnv->CallBooleanMethod(result, getBool);
hasChanged = stateValue != cachedState;
isModified = stateValue != cachedState;
}

if (hasChanged) {
if (isModified) {
if constexpr (std::is_same<T, java::JNIString>::value)
cachedState = std::move(stateValue);
else
cachedState = stateValue;
if (observer)
observer();
for (auto& observe : observers)
if (observe)
observe(osEnv);
}
osEnv->DeleteLocalRef(result);
}

class OSMachState {
class OsMachState {
public:
OSMachState(JNIEnv* androidEnv) :
OsMachState(JNIEnv* androidEnv) :
appStorage(androidEnv, dsKeys.at(AppStorage)),
turboMode(androidEnv, dsKeys.at(GpuTurboMode)),
customDriver(androidEnv, dsKeys.at(GpuCustomDriver)),
eeMode(androidEnv, dsKeys.at(EeMode)),
biosPath(androidEnv, dsKeys.at(BiosPath)),
schedAffinity(androidEnv, dsKeys.at(SchedulerAffinity)) {

}
void addObserver(StateId state, ObserveFunc observe);

void syncAllSettings();
// Directory with write permissions kSelected by the user
OSVariable<java::JNIString> appStorage;
OSVariable<java::JNIBool> turboMode;
OSVariable<java::JNIString> customDriver;
OSVariable<java::JNIInteger> eeMode;
OSVariable<java::JNIString> biosPath;
OSVariable<java::JNIInteger> schedAffinity;
OsVariable<java::JNIString> appStorage;
OsVariable<java::JNIBool> turboMode;
OsVariable<java::JNIString> customDriver;
OsVariable<java::JNIInteger> eeMode;
OsVariable<java::JNIString> biosPath;
OsVariable<java::JNIInteger> schedAffinity;
};
}
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/translator/fastmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace cosmic::translator {
if (!checkPc(pc))
return std::make_pair(0, false);
auto roMem{savedPc[pc & 0xfffff000]};
u32* pcVal{reinterpret_cast<u32*>(roMem + (pc & 0xfff))};
auto pcVal{reinterpret_cast<u32*>(roMem + (pc & 0xfff))};
return std::make_pair(*pcVal, true);
}
}
7 changes: 4 additions & 3 deletions app/src/main/cpp/cosmic/translator/inst_operands.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <translator/inst_operands.h>
namespace cosmic::translator {
std::array<const char*, 3> opsNames{
""
"", "", ""
};
std::array<const char*, 2> interpreters{
std::array<const char*, 3> interpreters{
"Emotion Engine by Cached Interpreter",
"IOP Interpreter"
"IOP Interpreter",
"VU (0, 1) Interpreters"
};
std::array<const char*, 1> eeOps{
""
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/translator/inst_operands.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace cosmic::translator {
instruction operation;
};
extern std::array<const char*, 3> opsNames;
extern std::array<const char*, 2> interpreters;
extern std::array<const char*, 3> interpreters;
extern std::array<const char*, 1> eeOps;
extern std::array<const char*, 1> psxOps;
}
23 changes: 12 additions & 11 deletions app/src/main/cpp/cosmic/vm/emu_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@ namespace cosmic::vm {
pthread_setname_np(pthread_self(), "Vm.Emu");
auto vm{owner->frame};
mlCond.wait(unique, [owner](){ return (owner->check & 0xff) == svrMonitor2; });
device->getStates()->schedAffinity.observer = [&]() {

device->getStates()->addObserver(os::StateId::SchedulerAffinity, [&](JNIEnv* os) {
bool state{owner->isRunning};
if (owner->isRunning)
owner->isRunning = false;
switch (device->getStates()->schedAffinity.cachedState) {
case Normal:
// EE, GS, VUs
vm->scheduler->affinity = EmotionEngine | GS << 4 | VUs << 8; break;
case PrioritizeVectors:
// VUs, EE, GS
vm->scheduler->affinity = VUs | EmotionEngine << 4 | GS << 8; break;
case GraphicsFirst:
// GS, VUs, EE
vm->scheduler->affinity = GS | VUs << 4 | EmotionEngine << 8; break;
case Normal:
// EE, GS, VUs
vm->scheduler->affinity = EmotionEngine | GS << 4 | VUs << 8; break;
case PrioritizeVectors:
// VUs, EE, GS
vm->scheduler->affinity = VUs | EmotionEngine << 4 | GS << 8; break;
case GraphicsFirst:
// GS, VUs, EE
vm->scheduler->affinity = GS | VUs << 4 | EmotionEngine << 8; break;
}
owner->isRunning = state;
};
});

auto cyclesSched{vm->scheduler};
if (!cyclesSched->affinity)
Expand Down
Loading

0 comments on commit 992c255

Please sign in to comment.