kootstra-rene / enge-js

eNGE JavaScript PlayStation Emulator
https://kootstra-rene.github.io/enge-js/
MIT License
233 stars 40 forks source link

Can you add support for auto loading games from URLs? #45

Open ff7man opened 11 months ago

ff7man commented 11 months ago

Loading from the filesystem is not an option on an Xbox Series X

To get around this I've made a few changes.

to index.js I've added

  function loadFileFromURL(url) {
    alert("loading "+url)
    fetch(url)
      .then(response => response.arrayBuffer())
      .then(arrayBuffer => {
        loadFileData(arrayBuffer);
      })
      .catch(error => {
        console.error('Error loading file from URL:', error);
      });
}

to index.js:init() I've added

    const loadBiosButton = document.getElementById('loadBiosButton');
    loadBiosButton.addEventListener('click', function () {
        loadFileFromURL("bios.bin")
    })
    const loadGameButton = document.getElementById('loadGameButton');
    loadGameButton.addEventListener('click', function () {
        loadFileFromURL("game.bin")
    })

and to index.html I've added

    <button id="loadBiosButton">Load BIOS from URL</button></br>
    <button id="loadGameButton">Load Game from URL</button>
kootstra-rene commented 11 months ago

Good idea, ENGE working on XBOX would be great. I will have a look.

ff7man commented 11 months ago

I only tested one game, but it does load and the controller works. However after using the controller the window is locked to game control mode disabling the emulated mouse. Normally to exit this mode you would just hold down Start, but with the emulator it never disables game control mode. Not sure why. To get control of the console again I've been pressing the Xbox button and force closing the app. Maybe a click in on one of the sticks to disable to the gamepad would fix this?

ff7man commented 11 months ago

Here's a video of it running on an xbox series x,

https://youtu.be/MZYelnoZ4UE

game controls can be disabled using a keyboard so no need for the fix only games < 350mB can be loaded due to memory constraints (edge crashes when more than 1gB of memory is used) To get around this we would have to stream files from the server as needed instead of all at once, I'm not sure how complicated that would be... Definitely beyond my abilities.

Button pressing doesn't always work either, so to have it autoload I added

loadFileFromURL("bios.bin")
loadFileFromURL("game.bin")

to the bottom of init() in index.js

games are hosted locally using python

#!/usr/bin/env python3
from http.server import HTTPServer, SimpleHTTPRequestHandler
import sys

class CORSRequestHandler(SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header('Access-Control-Allow-Origin', '*')
        SimpleHTTPRequestHandler.end_headers(self)

if __name__ == '__main__':
    host = '0.0.0.0'  # Listen on all available network interfaces
    port = 80         # Use port 80 (requires superuser privileges)
    server_address = (host, port)
    httpd = HTTPServer(server_address, CORSRequestHandler)
    print(f"Serving on {host}:{port}")
    httpd.serve_forever()
ff7man commented 10 months ago

We can close this out, auto game loading wasn't terribly difficult to add with those lines above, and if you make a browser app for the xbox using the new webview2 https://learn.microsoft.com/en-us/microsoft-edge/webview2/get-started/winui2 it doesn't have strict memory limits and can load large games without a problem now