@thenick775/mgba-wasm
TypeScript icon, indicating that this package has built-in type declarations

2.3.2 • Public • Published

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

/@thenick775/mgba-wasm/

    Package Sidebar

    Install

    npm i @thenick775/mgba-wasm

    Weekly Downloads

    71

    Version

    2.3.2

    License

    MPL-2.0

    Unpacked Size

    2.82 MB

    Total Files

    6

    Last publish

    Collaborators

    • thenick775