JSPM

  • Created
  • Published
  • Downloads 97
  • Score
    100M100P100Q73578F
  • License MPL-2.0

mGBA emulator compiled to webassembly

Package Exports

  • @thenick775/mgba-wasm
  • @thenick775/mgba-wasm/dist/mgba.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thenick775/mgba-wasm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mGBA-wasm

This package is a bundled version of my mGBA fork compiled to webassembly.

This core currently powers gbajs3!

To instantiate the emulator using react:

import mGBA, { type mGBAEmulator } from '@thenick775/mgba-wasm';
import { useEffect, useState } from 'react';

export const useEmulator = (canvas: HTMLCanvasElement | null) => {
  const [emulator, setEmulator] = useState<mGBAEmulator | null>(null);

  useEffect(() => {
    const initialize = async () => {
      if (canvas) {
        const Module = await mGBA({ canvas });

        const mGBAVersion =
          Module.version.projectName + ' ' + Module.version.projectVersion;
        console.log(mGBAVersion);

        await Module.FSInit();

        setEmulator(Module);
      }
    };

    initialize();
  }, [canvas]);

  return emulator;
};

This core uses threads, you must serve these files in a way that supports cross origin isolation:

Cross-Origin-Opener-Policy same-origin
Cross-Origin-Embedder-Policy require-corp

See the feature/wasm README for further details such as:

  • available emulator interface methods
  • building from source
  • embedding and usage in vanilla javascript