Code Monkey home page Code Monkey logo

jsnes's Introduction

JSNES

A JavaScript NES emulator.

It's a library that works in both the browser and Node.js. The browser UI is available at https://github.com/bfirsh/jsnes-web.

Installation

For Node.js or Webpack:

$ npm install jsnes

(Or yarn add jsnes.)

In the browser, you can use unpkg:

<script type="text/javascript" src="https://unpkg.com/jsnes/dist/jsnes.min.js"></script>

Usage

// Initialize and set up outputs
var nes = new jsnes.NES({
  onFrame: function(frameBuffer) {
    // ... write frameBuffer to screen
  },
  onAudioSample: function(left, right) {
    // ... play audio sample
  }
});

// Read ROM data from disk (using Node.js APIs, for the sake of this example)
const fs = require('fs');
var romData = fs.readFileSync('path/to/rom.nes', {encoding: 'binary'});

// Load ROM data as a string or byte array
nes.loadROM(romData);

// Run frames at 60 fps, or as fast as you can.
// You are responsible for reliable timing as best you can on your platform.
nes.frame();
nes.frame();
// ...

// Hook up whatever input device you have to the controller.
nes.buttonDown(1, jsnes.Controller.BUTTON_A);
nes.frame();
nes.buttonUp(1, jsnes.Controller.BUTTON_A);
nes.frame();
// ...

Build

To build a distribution:

$ yarn run build

This will create dist/jsnes.min.js.

Running tests

$ yarn test

Embedding JSNES in a web page

You can use JSNES to embed a playable version of a ROM in a web page. This is handy if you are a homebrew ROM developer and want to put a playable version of your ROM on its web page.

The best implementation is jsnes-web but unfortunately it is not trivial to reuse the code. You'll have to copy and paste the code from that repository, the use the <Emulator> React component. Here is a usage example..

A project for potential contributors (hello!): jsnes-web should be reusable and on NPM! It just needs compiling and bundling.

A more basic example is in the example/ directory of this repository. Unfortunately this is known to be flawed, and doesn't do timing and sound as well as jsnes-web.

Formatting code

All code must conform to Prettier formatting. The test suite won't pass unless it does.

To automatically format all your code, run:

$ yarn run format

Maintainers

JSNES is based on James Sanders' vNES, and owes an awful lot to it. It also wouldn't have happened without Matt Wescott's JSSpeccy, which sparked the original idea. (Ben, circa 2008: "Hmm, I wonder what else could run in a browser?!")

jsnes's People

Contributors

allie avatar benshelton avatar bfirsh avatar darthgoldstein avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar ecin avatar isharacomix avatar jancborchardt avatar joemeeks avatar kira1928 avatar malignantz avatar matthewbauer avatar minimi avatar nesblast avatar ninjadynamics avatar nosrevi avatar pubby avatar rcopera avatar shicks avatar slembcke avatar workhorsy avatar yasaricli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsnes's Issues

The Grunt build process

I was looking into a way of having npm build the project on "post install". I don't think that having the grunt CLI as a dependency is really wise, I think that the mainstream way of packing the library would be to include the build files. NPM should provided a ready-to-use version of the library when you install it rather then.

git clone https://github.com/bfirsh/jsnes
cd jsnes
npm install
grunt

Sound

i have no sound in my hosting server

Don't use y&z as default keys

Hi,

in germany, we have y+z swapped. Using x+c would possibly be better, as its the same on en+ger keyboards.

cheers
Felicitus

Undefined function in source/ui.js

There is an undefined function in source/ui.js at line 197, JSNESBinaryToArray(), that is not referenced nor used elsewhere in the code.

Replacing lines 197-199 by:
var charCodes = xhr.responseBody.toArray();
seems to be OK.

Is it safe to delete?

Up/down is not working

I tried the JSNES, but hitting the up or down (with any key) is not working. I tried several times in Chrome 10, Fx 4.

this.nes.stop()

in the line 1028 of cpu.js:

this.nes.stop();

while the stop() function has been removed in nes.js

Buttons commands not working for Zelda

Looks like using X and Z for buttons work in other games but it doesn't seem to work for Zelda. Any idea why? I've tried in latest version of Chrome and Safari.

Screen drawing waiting slows down CPU on fast machines.

Currently jsnes has a bug with the way it times screen drawing. It tries to draw at 120 FPS (8.333 MS per frame) instead of 60 FPS (16.667 MS per frame). But it also does an infinite loop while checking the time till 16.6667 MS has passes. So it looks like it is doing 60 FPS, even though it is trying to do 120 FPS.

This can be easily fixed by removing the limitFrames code, and changing the FPS to 60.

This will not make any speed improvement on a machine that is too slow to run the emulator. But on my Intel i7 test machine, it went from 99% CPU to 24% CPU. I'm pretty sure it would do 99% CPU on any machine because of the waiting.

One game per page without dropdown

Hello.
How will look the code (index.html) if I want to load only one game, without dropdown select game. Just load the game with loading the page?

I want to put an game in my wordpress.

Typo in source/cpu.js

There is an undefined function in source/cpu.js at line 141:
doIrq(temp);
should probably read:
this.doIrq(temp);

Automatically fix JavaScript errors on pull requests

I run Stickler-CI which is a service aimed at improving code quality by simplifying code review by automating code feedback in pull requests.

We just launched auto-fixing for JavaScript through pull request commits. As a JavaScript open source project, our service will save you time and brain power by automatically fixing style errors.

If you are interested in trying out our product, we can submit a pull request with the configuration file, but a maintainer will need to enable webhooks by logging into https://stickler-ci.com and enabling the webhook.

Thank you!

Run 6502 ASM Code

I'm working on a project and I'd like to have a console that runs NES 6502 code. Is there any way I could adapt this to run that code instead of .nes files? How are you loading the .nes files?

How Me Install this jsnes

I need help installing this to me site. I use cpanel and their is not a tutorial on it. I don't know how to do it. I want it to look like the one the creator has. I don't know if this github stuff will get me that end result. I think that is the demo of this. I don't know and I need help.

Additional Joystick buttons AA & BB

On standard joystick has two buttons A and two buttons B. A lot of games controlled by including two keys AA and BB, access to which is not in the current edition.

Uncaught TypeError: Cannot read property 'pix' of undefined

Game: Darkwing Duck (U) and some others

Console output:
Uncaught TypeError: Cannot read property 'pix' of undefined ppu.js:1011
JSNES.PPU.renderBgScanline ppu.js:1011
JSNES.PPU.endScanline ppu.js:428
JSNES.frame nes.js:149
(anonymous function) nes.js:82

Ugly solve is add
if(!t) break;
after
t = ptTile[baseTile+nameTable[this.curNt].getTileIndex(this.cntHT,this.cntVT)];

Redo the memory reading and writing into a function in array system

I originally had nested switches inside my JS GameBoy Color emulator, but it turns out doing functions in an array where the entire 8-bit (16-bit addressing) memory map is mapped to an array by either assigning references to the actual function or assigning the handling function itself to the array. is wat fasrer Something along this format: memoryWrite[address](self, address, data) {do stuff to the memory accessed from the self reference of the emulator object itself. }. It's definitely faster in all browsers I've tested it in.

Show it in canvas

Please can any one give me a sample of code for showing the frame in canvas, any help please i dont know how to do it with the new code

IE10 Compatibility

Hello Ben,

I am a Program Manager with the Ecosystem Engineering team at Microsoft. I am writing to notify you of a compatibility issue with fir.sh/projects/jsnes/ on the Internet Explorer 10.

At BUILD in September, Microsoft announced the availability of the Windows Developer Preview. The Windows Developer Preview provides a great opportunity to begin testing your websites against the new environment featured in IE10. In November, the IE team announced the fourth version of the IE10 Platform Preview. This is a new IE10 preview designed to work in conjunction with the Windows Developer Preview. You can learn more about IE10 Platform Preview at IEBlog.

We encourage you to download the Windows Developer Preview and IE10 Platform Preview to begin testing your website and applications. Important: Windows Developer Preview is required in order to run the new IE10 Platform Preview.

Windows 8 includes one HTML5 browsing engine that powers two browsing experiences: the new Metro style browser and IE10 on the desktop. The common HTML5 engine provides strong support for Web standards and a consistently fast, safe, and powerful Web programming model for both browser experiences as well as for Metro style applications. Learn more about the many new technologies supported by IE10 on Windows 8 at the IEBlog.

Microsoft’s goal is to ensure that fir.sh/projects/jsnes/ is compatible with the latest web industry standards implemented in IE10. These standards offer key benefits to your customers including improved security and browsing performance. We are committed to working closely with you to determine the cause of any compatibility issues occurring with IE 10 so that our mutual users have a great experience in the future.

Based on preliminary testing, the following compatibility issues have been identified with fir.sh/projects/jsnes:

Reference #: 556524
Description of the Problem: JSNes doesn't work in Standards docmode - script error unless IE9 docmode
Steps to Reproduce:

  1. Navigate to http://fir.sh/projects/jsnes/
  2. Choose "Bubble bobble" ROM

Issue:
Script error SCRIPT5: Access is denied.
like.php, line 1 character 1
SCRIPT5: Access is denied.
tweet_button.html, line 1 character 1

Developer Notes: Changing Browser Mode to IE9 fixes this. This is due to this markup in the HTML:

This workaround is described in detail here: http://stackoverflow.com/questions/1919972/how-do-i-access-xhr-responsebody-for-binary-data-from-javascript-in-ie

*Note: This issue may not be visible while running Internet Explorer in Compatibility View or in other document modes. See “IE Blog: IE’s Compatibility Features for Site Developer” (http://blogs.msdn.com/b/ie/archive/2010/06/16/ie-s-compatibility-features-for-site-developers.aspx) for more details on Compatibility View.

Please let me know if you have an estimated timeframe to address this issue, and if our team can further assist in this process.

Thanks,

Permita Tomar
Microsoft PC Ecosystem Engineering
[email protected]

this.nes.stop is not a function

Whenever the emulator reads bad data, it loops endlessly because stop is not defined (#24) (#82), and no matter what I do, it won't not do that. Am I loading it wrong? I am using XMLHttpRequest, and reading responseText, but I think this is wrong.

Cannot call method 'load' of null

Uncaught TypeError: Cannot call method 'load' of null cpu.js:162
JSNES.CPU.emulate cpu.js:162
JSNES.frame nes.js:106
(anonymous function) nes.js:82

Try to load Battletoads ROM

add the controller parameter in useage

In readme.md, buttonDown is

nes.buttonDown(jsnes.Controller.BUTTON_A);

but acturally the function is

buttonDown: function(controller, button) {
  this.controllers[controller].buttonDown(button);
},

you forget to add the controller parameter :)

save state

To be able to actually play the games properly rather than just fiddle around, the game state should be saved. Not sure if internal game save functions can be accessed or if it’s feasible to just always have the latest state changed. The Gameboy Emulator by Grant Galitz seems to do both.

It’s probably best to always automatically save in localStorage/IndexedDB so that people can return to their game. Maybe even use remotestorage so you can change browsers.

Where is index .html and/or roms?

When I was browsing this morning, I saw the index .html and the roms right there. But when I went back later, they were all gone! Where did they go?

nes online - sync problems

I want to make play nes online with my friends, but it is easily out of sync and I don't know the main reasons.
My way : synchronize time with server-> players keydown/keyup -> send it to server -> get current time and add a delay(for example, 100ms) -> do actions at the same time for player1 & player2

Undefined backgrounds freeze execution

When a game has enabled backgrounds, but has not initialized the background's name table in the PPU VRAM, I get a type error "t is not defined" pointing to this line of the code:

    // Fetch data:
        t = ptTile[baseTile+nameTable[this.curNt].getTileIndex(this.cntHT,this.cntVT)];
        tpix = t.pix; // <-- t is not defined
        att = nameTable[this.curNt].getAttrib(this.cntHT,this.cntVT);
        scantile[tile] = t;
        attrib[tile] = att;

While this doesn't lock up the browser, it prevents the game from advancing. Can be reproduced with this rom image - runs in Mednafen, not in JSNES: http://isharacomix.org/junk/jsnes_bugreport.nes

sound issues

In Chrome, the sound is choppy (no errors though).

In Firefox (15) when I enable sound, the game effectively pauses, dropping the framerate to 0 and giving this error with dynamicaudio-min.js:
TypeMismatchError: The type of an object is incompatible with the expected type of the parameter associated to the object

can not load rom of MapperType2

jsnes can not load rom of MapperType2 .

I saw the source of JavaNes , The code is different from Jsnes.
The code is below

public class MapperCNROM extends MapperDefault {

	public MapperCNROM() {
	}

	public void init(NES nes) {
		super.init(nes);
	}

	public void write(int i, short word0) {
		if (i < 32768)
			super.write(i, word0);
		else
			load8kVromBank(word0 * 2, 0);
	}
}

NPM Publish

I just found this project and tried to npm install jsnes --save and found that the package was never published to NPM, I didn't want anyone to grab it so I published it myself. I'd love to transfer the ownership over to you. Just let me know your NPM username. Since your using NPM for installing everyone should be using it to install for versioning benefits. Let me know!

https://www.npmjs.org/package/jsnes

Jackal nes support

At this moment when I'm using jackal.nes I'm get just grey background:
jsnes jackal not-loading

Infinite loop when undefined opcode is read

When an undefined opcode is read, the .stop() method is called, which sets the running flag to false, but the FRAMELOOP in nes.js keeps running even when nes.running is false. I fixed this by changing the for loop to for (; this.running ;) and that seemed to work.

I tested this by running a blank ROM, which is just 0s for all of the PRG and CHR ROM. It locks up the browser and is very unpleasant.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.