Skip to content

Commit

Permalink
Merge pull request #1405 from rommapp/feat/experimental-psp-emulation
Browse files Browse the repository at this point in the history
feat: Experimental PSP emulation
  • Loading branch information
adamantike authored Jan 2, 2025
2 parents 08b4668 + 6c42783 commit 5dbec93
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
36 changes: 32 additions & 4 deletions frontend/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ const _EJS_CORES_MAP = {
gbc: ["gambatte", "mgba"],
"pc-fx": ["mednafen_pcfx"],
ps: ["pcsx_rearmed", "mednafen_psx"],
psp: ["ppsspp"],
segacd: ["genesis_plus_gx", "picodrive"],
// sega32: ["picodrive"], // Broken: https://github.com/EmulatorJS/EmulatorJS/issues/579
gamegear: ["genesis_plus_gx"],
Expand Down Expand Up @@ -387,8 +388,23 @@ export type EJSPlatformSlug = keyof typeof _EJS_CORES_MAP;
* @param platformSlug The platform slug.
* @returns An array of supported cores.
*/
export function getSupportedEJSCores(platformSlug: string) {
return _EJS_CORES_MAP[platformSlug.toLowerCase() as EJSPlatformSlug] || [];
export function getSupportedEJSCores(platformSlug: string): string[] {
const cores =
_EJS_CORES_MAP[platformSlug.toLowerCase() as EJSPlatformSlug] || [];
const threadsSupported = isEJSThreadsSupported();
return cores.filter(
(core) => !areThreadsRequiredForEJSCore(core) || threadsSupported,
);
}

/**
* Check if a given EJS core requires threads enabled.
*
* @param core The core name.
* @returns True if threads are required, false otherwise.
*/
export function areThreadsRequiredForEJSCore(core: string): boolean {
return ["ppsspp"].includes(core);
}

/**
Expand All @@ -403,11 +419,23 @@ export function isEJSEmulationSupported(
heartbeat: Heartbeat,
) {
return (
platformSlug.toLowerCase() in _EJS_CORES_MAP &&
!heartbeat.EMULATION.DISABLE_EMULATOR_JS
!heartbeat.EMULATION.DISABLE_EMULATOR_JS &&
getSupportedEJSCores(platformSlug).length > 0
);
}

/**
* Check if EJS threads are supported.
*
* EmulatorJS threads are supported if SharedArrayBuffer is available.
* Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
*
* @returns True if supported, false otherwise.
*/
export function isEJSThreadsSupported(): boolean {
return typeof SharedArrayBuffer !== "undefined";
}

/**
* Check if Ruffle emulation is supported for a given platform.
*
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/views/Player/EmulatorJS/Player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import saveApi, { saveApi as api } from "@/services/api/save";
import screenshotApi from "@/services/api/screenshot";
import stateApi from "@/services/api/state";
import type { DetailedRom } from "@/stores/roms";
import { getSupportedEJSCores } from "@/utils";
import { areThreadsRequiredForEJSCore, getSupportedEJSCores } from "@/utils";
import { onBeforeUnmount, onMounted, ref } from "vue";
const props = defineProps<{
Expand Down Expand Up @@ -77,6 +77,7 @@ declare global {
EJS_alignStartButton: "top" | "center" | "bottom";
EJS_startOnLoaded: boolean;
EJS_fullscreenOnLoaded: boolean;
EJS_threads: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
EJS_emulator: any;
EJS_onGameStart: () => void;
Expand All @@ -90,6 +91,7 @@ declare global {
const supportedCores = getSupportedEJSCores(romRef.value.platform_slug);
window.EJS_core =
supportedCores.find((core) => core === props.core) ?? supportedCores[0];
window.EJS_threads = areThreadsRequiredForEJSCore(window.EJS_core);
window.EJS_gameID = romRef.value.id;
window.EJS_gameUrl = `/api/roms/${romRef.value.id}/content/${romRef.value.file_name}`;
window.EJS_biosUrl = props.bios
Expand Down Expand Up @@ -438,7 +440,7 @@ window.EJS_onGameStart = async () => {
}
</style>

<!-- Other config options: https://emulatorjs.org/docs/Options.html -->
<!-- Other config options: https://emulatorjs.org/docs/options -->

<!-- window.EJS_biosUrl; -->
<!-- window.EJS_VirtualGamepadSettings; -->
Expand Down

0 comments on commit 5dbec93

Please sign in to comment.