This repository has been archived by the owner on Jan 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
zecoo edited this page Mar 3, 2019
·
8 revisions
Weaknes is a NES emulator written with JavaScript.
$ npm install
$ npm run build
AllInOne instance includes instances of nes, screen, audio and rom.
async function main() {
const path = './assets/nestest/nestest.nes'
const AllInOne = NesPack.AllInOne
const screenId = 'canvas'
const isDebug = false
const allInOne = new AllInOne(screenId, isDebug)
await allInOne.run(path)
}
main()
async function main() {
const Nes = NesPack.Nes
const Screen = NesPack.Screen
const Audio = NesPack.Audio
const Rom = NesPack.Rom
nes = new Nes()
/* A screen's argument is Canvas tag's id */
const screen = new Screen.Browser('canvas')
const audio = new Audio()
nes.connect({
screen,
audio
})
/* Download ROM */
const path = './assets/nestest/nestest.nes'
const data = await fetch(path)
.then(response => response.arrayBuffer())
.then(buffer => new Uint8Array(buffer))
const rom = new Rom(data)
nes.rom = rom
nes.run()
}
main()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="icon" href="data:;base64,iVBORwOKGO=" />
<title>Screen of NES emulator</title>
</head>
<body>
<canvas id="canvas" width="256" height="240"></canvas>
<script src="dist/bundle.js"></script>
<script src="index.js"></script>
</body>
</html>
Tool dumps CHR-ROM, Color palettes and 4 nametables.
If you want to update dumps automatically, use setInterval.
async function main() {
const path = './assets/nestest/nestest.nes'
const AllInOne = NesPack.AllInOne
const screenId = 'canvas'
const isDebug = false
const allInOne = new AllInOne(screenId, isDebug)
await allInOne.run(path)
const nes = allInOne.nes
const Tools = NesPack.Tools
const palette = [0x31, 0x3d, 0x2d, 0x1f]
const tools = new Tools(nes)
tools.dumpChrRom('chr-dump', palette)
//Auto update
const interval = 300
setInterval(tools.dumpPalette.bind(tools, 'palette-dump'), 300)
const isShadowEnabled = true
setInterval(tools.dumpBackground.bind(tools, 'background', isShadowEnabled), 300)
}
main()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="icon" href="data:;base64,iVBORwOKGO=" />
<title>Screen of NES emulator</title>
</head>
<body>
<canvas id="canvas" width="256" height="240"></canvas>
<div>
<canvas id="chr-dump" width="256" height="120"></canvas>
<canvas id="palette-dump" width="256" height="120"></canvas>
</div>
<canvas id="background" width="512" height="480"></canvas>
<script src="dist/bundle.js"></script>
<script src="index.js"></script>
</body>
</html>
There are samples in samples directory.
Let's run below commands with rom's path.
$ npm run nes:browser <rom's path>
$ npm run nes:electron <rom's path>
$ npm run nes:nodejs <rom's path>