neser 0.1.1

NESER - NES Emulator in Rust - is a NES emulator written in Rust. It aims to be a high-quality, hardware-accurate emulator that is also easy to use and extend. It supports a wide range of NES games and features, including various mappers, audio processing, and input handling. NESER is designed to be modular and extensible, allowing developers to easily add new features or support for additional hardware. It can be run using one of two frontends: a native desktop application using SDL2, or a web application using WebAssembly. The desktop application provides a high-performance, feature-rich experience with support for various input devices and display options, while the web application allows users to play NES games directly in their browsers without needing to install any software in a BYOR manner (Bring Your Own Roms).
Documentation
"""Shared test helpers for mappertool tests."""

import zlib


def make_ines_rom(
    mapper: int,
    *,
    submapper: int | None = None,
    prg_size: int = 16 * 1024,
    chr_size: int = 8 * 1024,
    fill_prg: int = 0xAA,
    fill_chr: int = 0x55,
) -> bytes:
    """Build a minimal iNES/NES 2.0 ROM image for tests."""

    header = bytearray(16)
    header[0:4] = b"NES\x1A"
    header[4] = prg_size // (16 * 1024)
    header[5] = chr_size // (8 * 1024)

    if submapper is None:
        header[6] = (mapper & 0x0F) << 4
        header[7] = mapper & 0xF0
    else:
        header[6] = (mapper & 0x0F) << 4
        header[7] = (mapper & 0xF0) | 0x08
        header[8] = ((submapper & 0x0F) << 4) | ((mapper >> 8) & 0x0F)

    return bytes(header) + (bytes([fill_prg]) * prg_size) + (bytes([fill_chr]) * chr_size)


def crc_from_rom_bytes(rom_bytes: bytes) -> str:
    """Compute PRG+CHR CRC from a minimal iNES ROM for test fixtures."""

    prg_size = rom_bytes[4] * 16 * 1024
    chr_size = rom_bytes[5] * 8 * 1024
    prg_offset = 16
    chr_offset = prg_offset + prg_size
    crc = zlib.crc32(rom_bytes[prg_offset : prg_offset + prg_size])
    crc = zlib.crc32(rom_bytes[chr_offset : chr_offset + chr_size], crc) & 0xFFFFFFFF
    return f"{crc:08X}"