|
pc2g,电脑好游戏
A JavaScript NES emulator.
在线演示
国外https://jsnes.org/
国内http://jsnes.cn/
http://i8game.net/jsnes/index.html
用Javascript写成的小霸王游戏机模拟器。JSNES是利用 JavaScript和Canvas建立的.
有人说: 这个模拟器让人们知道了三件事。JavaScript很强大,Opera/Chrome的JS引擎 够强、Firefox太慢,什么样的电脑能做到上网不卡。
现在配合HTML5的JavaScript更为强大。
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. An example is in the example/ directory.
For a more complex example, see jsnes-web, a web UI written in React.
A potential improvement (hello contributors!) would be to make the React components in jsnes-web reusable so you could use them to embed a single ROM in a web page.
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
作者官方https://github.com/bfirsh/jsnes |
|