🕹 GBA emulator on your React project - easy and powerful to use!

Overview

GBA emulator on your React project - easy and powerful to use!

Just three steps to set it up

1 - Apply GbaProvider

import { GbaProvider } from 'react-gbajs'

const App = () => (
  <GbaProvider>
    ...
  </GbaProvider>
)

2 - Get play function from GbaContext and call it with the game ROM

import { useContext } from 'react'
import { GbaContext } from 'react-gbajs'

const ButtonStartEmulator = () => {
  const {
    play,
  } = useContext(GbaContext)

  const startEmulator = () => {
    const gameRom = getGameRom()
    play({ newRomBuffer: gameRom })
  }

  return (
    <button onClick={() => startEmulator()}>
      Start Emulator
    </button>
  )
}

3 - And render the emulator using the default export

import ReactGbaJs from 'react-gbajs'

const Emulator = () => (
  <ReactGbaJs />
)

Done! 🎉
Check a full example in /sample.

How it works

This package is a React wrapper for GBA.js.

GBA.js is vendored, with new features over the original version:

  • save and restore state
  • freeze address with a given value

Who is using


klo-gba.js, level editor for Klonoa: Empire of Dreams
Add your project here

Features

GbaContext

GbaContext exports the following properties:

play({ newRomBuffer, restoreState }): boolean

Use this function to start or restart the emulator.

Pass at newRomBuffer the game's ROM to load it:

play({ newRomBuffer: myGameRom })

You can also fill the property restoreState to restore to a previous state saved using saveState. If both are present, the emulator will be reset loading the ROM, and then restored to the given state:

play({ newRomBuffer: myGameRom, restoreState: someState })

If you pass only restoreState, the previous ROM will be re-loaded and will start on the given state. If there is no ROM previously loaded, it won't work.

play({ restoreState: someState })

saveState()

Return the serializable state of the emulator.

addFreezeAddress({ address: number, size: 8 | 16 | 32, value: number })

Freeze an address with the given value.

removeFreezeAddress(address: number)

Remove the freeze value on the given address.

frozenAddresses()

Return the list of the addresses frozen in the following format:

{
  [address in number]: { size: 8 | 16 | 32, value: number }
}

<ReactGbaJs />

<ReactGbaJs /> has the following props:

volume={number} (optional)

Should be a number between 0 (default, muted) or 1 (max volume).

onFpsReported={((fps: number) => void)} (optional)

Callback called every time that an FPS is reported.

scale={number} (optional)

Set the emulator scale. Default value is 1, which has width 240px and height 160px.

onLogReceived={(level: 'error' | 'warn' | 'stub' | 'info', message: string) => void} (optional)

Callback called every time that a log is received within the levels set as true by the prop watchLogLevels.

watchLogLevels={{ error?: boolean, warn?: boolean, stub?: boolean, info?: boolean }} (optional)

Set when the callback onLogReceived should be called. By default the value is { error: true }.

Contribution

1 - Clone this repository

> git clone [email protected]:macabeus/react-gbajs.git
> cd react-gbajs

2 - Build and watch the project

> npm run start

3 - In another terminal window, go to the /sample project, then build and watch it

> cd sample
> npm run start

Finished! Now you can develop the package and test it in real-time 🎉

Thanks

@endrift for GBA.js.
@felix.rodent for the logo.

Comments
  • Issues cloning & reproducing Sample

    Issues cloning & reproducing Sample

    After cloning even after npm installing -g react-gbajs I run into both issues: Cannot find module 'react-gbajs' or its corresponding type declarations. and Parameter 'level' implicitly has an 'any' type. TS7006: Parameter 'message' implicitly has an 'any' type.

    Is this package no-longer updated or am I doing something horribly wrong. Thank you - Getting used to React

    opened by Alx-AI 4
  • NextJS module not found

    NextJS module not found

    Hi

    Do you have any idea why nextjs is giving me module not found with this library?

    here's the error (there's nothing else really)

    // _app.tsx
    import { GbaProvider } from "react-gbajs"
    
    const AppWrapper = ({ Component, pageProps }: Props) => {
      console.log(GbaProvider)
      return (
        <I18nextProvider i18n={i18n}>
          <GlobalContextProvider>
            <App {...{ Component, pageProps }}></App>
          </GlobalContextProvider>
        </I18nextProvider>
      )
    }
    
    error - ./pages/_app.tsx:17:0
    Module not found: Can't resolve 'react-gbajs'
      15 | import { env } from "../infrastructure/utils/environment"
      16 | import { themes } from "../infrastructure/theme"
    > 17 | import { GbaProvider } from "react-gbajs"
      18 | 
      19 | const AppWrapper = ({ Component, pageProps }: Props) => {
      20 |   console.log(GbaProvider)
    

    I'm using NextJS 12.0.7 with typscript

    Thank you for your hard work

    Have a nice day

    opened by Flowrome 3
  • Improve canvas: scale and ref

    Improve canvas: scale and ref

    Two improvements on the canvas:

    • use css transform to change its scale, which is faster (suggested here https://github.com/city41/smaghetti/discussions/29#discussioncomment-776751)
    • use ref instead of id to find the element, to avoid name conflict
    opened by macabeus 0
  • fps: replace requestAnimationFrame to setTimetout

    fps: replace requestAnimationFrame to setTimetout

    requestAnimationFrame doesn't work well for emulators since it could be faster than 60 FPS on some computers. Then this PR replaces it to setTimeout such as gbajs originally was using.

    https://github.com/city41/smaghetti/issues/25#issuecomment-847305380

    opened by macabeus 0
  • Uncaught ReferenceError: FlashSavedata is not defined

    Uncaught ReferenceError: FlashSavedata is not defined

    Hi

    Sorry to bother you again, but from the issue 14 now i'm getting this error, i don't know if it is a problem with the .gba file but i've tried multiple and i'm getting the same error:

    Uncaught (in promise) ReferenceError: FlashSavedata is not defined
        at window.GameBoyAdvanceMMU.GameBoyAdvanceMMU.loadRom (react-gbajs.js?323e:10)
        at G.setRom (react-gbajs.js?323e:10)
        at G.loadRomFromFile (react-gbajs.js?323e:10)
        at H (react-gbajs.js?323e:10)
        at play (react-gbajs.js?323e:10)
        at _callee$ (emulator.js?a22c:33)
        at tryCatch (runtime.js?c56e:45)
        at Generator.invoke [as _invoke] (runtime.js?c56e:274)
        at Generator.prototype.<computed> [as next] (runtime.js?c56e:97)
        at asyncGeneratorStep (emulator.js?a22c:1)
        at _next (emulator.js?a22c:1)
    

    I've also cloned your example and it seems that it gives me the same error

    Let me know if i can provide more information

    Thank you

    opened by Flowrome 6
  • Squeak on emulator when running on Chrome

    Squeak on emulator when running on Chrome

    On this PR we added the GBA emulator. It works very well, but when it starts on Chrome, it plays some squeak for short time, even when the volume is set to 0. It only plays this squeak on Chrome, and if we to comment the function writeSoundControlHi, we don't have anymore the squeak, but the sound will not work very well while running the game.

    opened by macabeus 0
Releases(1.0.2)
  • 1.0.2(Dec 21, 2021)

  • 1.0.0(Jun 18, 2021)

    First stable release 🎉

    Major updates:

    • rewritten to typescript (https://github.com/macabeus/react-gbajs/pull/7)
    • add props onFpsReported, onLogReceived and watchLogLevels (https://github.com/macabeus/react-gbajs/pull/4, https://github.com/macabeus/react-gbajs/pull/9)
    • simplify API, merging the function updateState into play (https://github.com/macabeus/react-gbajs/pull/6)
    • add logo (https://github.com/macabeus/react-gbajs/pull/8)

    Minors:

    • faster scale (https://github.com/macabeus/react-gbajs/pull/5)
    • prop volume now is optional, default value is 0 (https://github.com/macabeus/react-gbajs/pull/10)
    • now use id attribute on canvas (https://github.com/macabeus/react-gbajs/pull/5)
    • fix FPS rate in some computers (https://github.com/macabeus/react-gbajs/pull/3)
    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(May 24, 2021)

INeedHelp is a Game Boy, Game Boy Advance, and Nintendo DS emulator written in JavaScript and TypeScript.

INeedHelp INeedHelp is a Game Boy Advance and Nintendo DS emulator written in JavaScript/TypeScript. FAQ Why is it called INeedHelp? You would need he

Powerlated 6 Jun 29, 2022
A chip8 and super chip8 emulator.

(s)chip8 Emulator CHIP-8 是一种解释型编程语言,由 Joseph Weisbecker 开发。它最初用于 COSMAC VIP 和 Telmac 1800 8 位微型计算机在 70 年代中期。CHIP-8 程序在一个 CHIP-8 虚拟机上运行。它的问世是为了让电子游戏更容易

daief 2 Jun 13, 2022
A Chip-8 Emulator written in javascript

Chippy A Chip-8 Emulator written in javascript Live DEMO Features Display Controls CPU Controls Sound Controls Rom Selection Debug Features Register D

Kenneth Lamb 4 Jun 15, 2022
A browser-based emulator for Zeal 8-bit Computer

Zeal 8-bit Computer emulator This project is a software emulator for Zeal 8-bit Computer: a homebrew 8-bit computer based on a Z80 CPU. Click here for

Zeal 8-bit 33 Nov 27, 2022
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands

JavaScript Library for Web Based Terminal Emulators Summary jQuery Terminal Emulator is a plugin for creating command line interpreters in your applic

Jakub T. Jankiewicz 2.8k Jan 1, 2023
Multithread emulator. The wrun allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file

wrun This lib allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file. This means tha

Felippe Regazio 9 Nov 5, 2022
jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light <7ko min.js and <1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Renan LAVAREC 2 Jan 18, 2022
An easy to implement marquee JQuery plugin with pause on hover support. I know its easy because even I can use it.

Simple-Marquee Copyright (C) 2016 Fabian Valle An easy to implement marquee plugin. I know its easy because even I can use it. Forked from: https://gi

null 16 Aug 29, 2022
Easy-to-use tool to inform you about potential risks in your project dependencies list

sdc-check Easy-to-use tool to inform you about potential risks in your project dependencies list Usage Add to your project Add new npm command to scri

Maksim Balabash 132 Dec 4, 2022
Node WebStation is a powerful tool designed for developers allowing them to create advanced web sockets for any use all without having the requirement to code.

Node WebStation Node WebStation is a powerful tool designed for developers to use to create an advanced WebStation for any use all without not having

null 2 Jun 4, 2022
A high-resolution local database that uses precise algorithms to easily record data in local files within a project with persistent JSON and YAML support designed to be easy to set up and use

About A high-resolution local database that uses precise algorithms to easily record data in local files within a project with persistent JSON and YML

Shuruhatik 5 Dec 28, 2022
Lavanstax project - Makes it easy and fun to use İnstagram. Also first userbot for İnstagram

Lavanstax Lavanstax project - Makes it easy and fun to use İnstagram. Also first userbot for İnstagram | İnstagram | Telegram Channel | Telegram Group

Berathan Yedibela 19 Oct 15, 2022
An easy to use Remix + React Native Web starter

remix-react-native-web-starter Using this template This template is based on the How to Setup React Native Web in a Remix project article Requisites:

Horus Lugo 39 Dec 5, 2022
A quick and powerful plugin for your pull-to-refresh needs in your webapp.

PulltoRefresh.js • Demos A small, but powerful Javascript library crafted to power your webapp's pull to refresh feature. No markup needed, highly cus

Box Factura 3.9k Jan 6, 2023
Quickly get up and running with a powerful Solidity project in no time.

Solidity template Quickly get up and running with a powerful Solidity project in no time. ✨ Tech stack used Hardhat. Tooling for compiling, deploying

0xSaturn 3 Jun 6, 2022
Quickly get up and running with a powerful Solidity project in no time.

Solidity template Quickly get up and running with a powerful Solidity project in no time. ✨ Tech stack used Hardhat. Tooling for compiling, deploying

Sunrit Jana 3 Jun 6, 2022
An affordable and easy-to-use monitoring tool for your AWS serverless applications.

AWS Serverless Applications Monitoring Tool Table of Contents Motivation for Project Getting Started AWS End Users Installation and Setup Lambda Metri

OSLabs Beta 54 Sep 21, 2022
A superfast and easy to use knowledge base to help your customers get the info they need, when they need it most.

A superfast and easy to use knowledge base to help your customers get the info they need, when they need it most. helpkb is an open-source Next.js (A

Mark Moffat 11 Dec 5, 2022
Complete, flexible, extensible and easy to use page transition library for your static web.

We're looking for maintainers! Complete, flexible, extensible and easy to use page transition library for your static web. Here's what's new in v2. Ch

null 3.7k Jan 2, 2023