npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nes-wasm

v0.4.0

Published

WebAssembly bindings for the nes-sim NES emulator core.

Readme

nes-wasm

nes-sim 核心库的 WebAssembly 绑定(wasm-bindgen)。纯 Rust 实现的 NES/FC 模拟器核心,无依赖,可用于浏览器、Node 及各类 JS 运行时。

安装

npm install nes-wasm
import init, { NesWasm } from "nes-wasm";
await init();

本地构建

wasm-pack build nes-wasm --target web --release
# 产物输出到 nes-wasm/pkg/

其他 target:--target bundler(webpack/vite)、--target web(原生 ESM)、--target nodejs。

使用示例

import init, { NesWasm } from "./pkg/nes_wasm.js"; // npm 安装时: from "nes-wasm"

await init(); // 或传 URL / 字节: init({ module_or_path: bytes })

const nes = new NesWasm();
nes.load_rom(new Uint8Array(romBytes));   // iNES;FDS 用 load_fds(image, bios)

const canvas = document.querySelector("canvas");
canvas.width = 256;
canvas.height = 240;
const ctx = canvas.getContext("2d");
const imageData = ctx.createImageData(256, 240);

// 手柄位掩码:A=1 B=2 Select=4 Start=8 Up=16 Down=32 Left=64 Right=128
nes.set_controller_bits(0, 0x08 | 0x10); // Start + Up
// 或按名称:nes.set_button(0, "Start", true)

function loop() {
  nes.run_frame();                        // 模拟一帧
  imageData.data.set(nes.frame_rgba());   // RGBA 帧缓冲
  ctx.putImageData(imageData, 0, 0);

  // 音频(单声道 f32,采样率见 nes.audio_sample_rate())
  const samples = nes.audio_samples();
  nes.clear_audio_samples();

  requestAnimationFrame(loop);
}
loop();

API 摘要

| 方法 | 说明 | | --- | --- | | load_rom(rom) / load_fds(image, bios) | 加载 ROM | | reset() / power_cycle() | 复位 / 断电重启 | | run_frame() | 运行一帧,返回帧号 | | frame_rgba() | RGBA 帧缓冲(256×240×4),可直接写 ImageData | | frame_pixels() | 8 位调色板索引帧;palette_rgb() 为 64 色系统调色板 | | set_palette(bytes) / clear_palette() | 加载/重置 .pal 调色板(FCEUX/Nestopia 格式,192=64 色或 1536=512 色);palette_rgb_full() 返回当前 512×3 字节 | | audio_samples() / clear_audio_samples() / audio_sample_rate() / set_audio_sample_rate(rate) | 音频 | | set_controller_bits(port, bits) / set_button(port, name, pressed) | 手柄输入 | | save_state() / load_state(bytes) | 快照存读档 | | battery_ram() / load_battery_ram(data) | 电池 RAM(.sav) | | fds_dirty() / fds_sides_flattened() / fds_side_lengths() | FDS 磁盘写回 | | rom_md5_hex() / frame_number() / master_clock() | 元信息 |

冒烟测试:node nes-wasm/smoke.mjs [rom路径](需先构建 pkg)。