Skip to content

Commit

Permalink
Compile: Fix PS2 Paths / Fix PSP to compile on AppleTV
Browse files Browse the repository at this point in the history
  • Loading branch information
SeiRyu committed May 8, 2024
1 parent 69605ab commit 934fe49
Show file tree
Hide file tree
Showing 140 changed files with 36,869 additions and 13,047 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4838,8 +4838,10 @@
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ARCHS = "$(ARCHS_STANDARD)";
BUILD_DIR = ../lib;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = XXXXXXXXXX;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PREPROCESSOR_DEFINITIONS = (
__APPLE__,
IOS,
Expand Down
188 changes: 109 additions & 79 deletions Cores/PPSSPP/PVPPSSPP.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions Cores/PPSSPP/PVPPSSPPCore/Core/AppleBatteryClient.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// AppleBatteryClient.m
// PPSSPP
//
// Created by Serena on 24/01/2023.
//

#include "Battery.h"
#import <Foundation/Foundation.h>

#if PPSSPP_PLATFORM(MAC)
#include <IOKit/ps/IOPSKeys.h>
#include <IOKit/ps/IOPowerSources.h>
#elif PPSSPP_PLATFORM(IOS)
#import <UIKit/UIKit.h>
#endif

@interface AppleBatteryClient : NSObject
+(instancetype)sharedClient;
-(void)setNeedsToUpdateLevel;
@property int batteryLevel;
@end

void _powerSourceRunLoopCallback(void * __unused ctx) {
// IOKit has told us that battery information has changed, now update the batteryLevel var
[[AppleBatteryClient sharedClient] setNeedsToUpdateLevel];
}

// You may ask,
// "Why an entire class?
// Why not just call the UIDevice/IOKitPowerSource functions every time getCurrentBatteryCapacity() is called?"
// Well, calling the UIDevice/IOKitPowerSource functions very frequently (every second, it seems?) is expensive
// So, instead, I made a class with a cached batteryLevel property
// that only gets set when it needs to.
@implementation AppleBatteryClient

+ (instancetype)sharedClient {
static AppleBatteryClient *client;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
client = [AppleBatteryClient new];
[client initialSetup];
[client setNeedsToUpdateLevel];
});

return client;
}

-(void)initialSetup {
#if TARGET_OS_IOS
// on iOS, this needs to be true to get the battery level
// and it needs to be set just once, so do it here
UIDevice.currentDevice.batteryMonitoringEnabled = YES;
// Register for when the battery % changes
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setNeedsToUpdateLevel)
name:UIDeviceBatteryLevelDidChangeNotification object:nil];
#elif TARGET_OS_TV
//
#elif TARGET_OS_MAC
CFRunLoopSourceRef loop = IOPSNotificationCreateRunLoopSource(_powerSourceRunLoopCallback, nil);
CFRunLoopAddSource(CFRunLoopGetMain(), loop, kCFRunLoopDefaultMode);
#endif
}

- (void)setNeedsToUpdateLevel {
#if TARGET_OS_IOS
// `-[UIDevice batteryLevel]` returns the % like '0.(actual %)' (ie, 0.28 when the battery is 28%)
// so multiply it by 100 to get a visually appropriate version
self.batteryLevel = [[UIDevice currentDevice] batteryLevel] * 100;
#elif TARGET_OS_TV
self.batteryLevel = 100;
#elif TARGET_OS_MAC
CFTypeRef snapshot = IOPSCopyPowerSourcesInfo();
NSArray *sourceList = (__bridge NSArray *)IOPSCopyPowerSourcesList(snapshot);
if (!sourceList) {
if (snapshot) CFRelease(snapshot);
return;
}

for (NSDictionary *source in sourceList) {
// kIOPSCurrentCapacityKey = battery level
NSNumber *currentCapacity = [source objectForKey:@(kIOPSCurrentCapacityKey)];
if (currentCapacity) {
// we found what we want
self.batteryLevel = currentCapacity.intValue;
break;
}
}
CFRelease(snapshot);
#endif
}

@end


int getCurrentBatteryCapacity() {
return [[AppleBatteryClient sharedClient] batteryLevel];
}
8 changes: 8 additions & 0 deletions Cores/PPSSPP/PVPPSSPPCore/Core/PVPPSSPPCore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,11 @@ void System_LaunchUrl(LaunchUrlType urlType, char const* url) {}
deviceList.empty();
return deviceList;
}

#if TARGET_OS_TV
int getCurrentBatteryCapacity() {
return 100;
}
void _powerSourceRunLoopCallback(void * __unused ctx) {
}
#endif
46 changes: 27 additions & 19 deletions Cores/PPSSPP/cmake/PPSSPP.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions Cores/PPSSPP/cmake/ffmpeg-tv-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
#build ffmpeg for all archs and uses lipo to create fat libraries and deletes the originals

set -e

. shared_options.sh
PATH=$(PWD)/gas-preprocessor:$PATH

ARCHS="arm64"

for arch in ${ARCHS}; do
rm -f config.h

ffarch=${arch}
versionmin=6.0
cpu=generic

if [[ ${arch} == "arm64" ]]; then
sdk=appletvos
ffarch=aarch64
versionmin=7.0
elif [[ ${arch} == "i386" ]]; then
sdk=iphonesimulator
ffarch=x86
elif [[ ${arch} == "x86_64" ]]; then
sdk=iphonesimulator
fi

./configure \
--prefix=ios/${arch} \
--enable-cross-compile \
--arch=${ffarch} \
--cc=$(xcrun -f clang) \
--sysroot="$(xcrun --sdk ${sdk} --show-sdk-path)" \
--extra-cflags="-arch ${arch} -D_DARWIN_FEATURE_CLOCK_GETTIME=0 -mtvos-version-min=${versionmin} ${cflags}" \
${CONFIGURE_OPTS} \
--extra-ldflags="-arch ${arch} -isysroot $(xcrun --sdk ${sdk} --show-sdk-path) -mtvos-version-min=${versionmin}" \
--target-os=darwin \
${extraopts} \
--cpu=${cpu} \
--enable-pic

make clean
make -j8 install
done

cd ios
mkdir -p universal/lib

for i in arm64/lib/*.a; do
libname=$(basename $i)
xcrun lipo -create $(
for a in ${ARCHS}; do
echo -arch ${a} ${a}/lib/${libname}
done
) -output universal/lib/${libname}
done

cp -r arm64/include universal/

rm -rf ${ARCHS}

0 comments on commit 934fe49

Please sign in to comment.