1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! The actual emulation code, provided as a library.
//!
//! A library for emulating the behaviour of the Nintendo Entertainment System.
//! Contains the entire state of the machine, and updates it accordingly as the NES is advanced.
//! The visual output can be accessed through the [Ppu::rgb_output] or [Ppu::rgb_output_buf],
//! and the audio output can be accessed through [Apu::sample_queue] as a queue of samples.
//! Input is updated though [Nes::set_controller_state].
//!
//! [Nes] and all of its fields can be serialized with the [serde] library,
//! allowing for quick and easy savestate implementations in whichever format you'd like.
//! ```
//! use yane::core::{Nes, Controller, Settings, HV_TO_RGB};
//! // The actual state of the NES
//! let mut nes = Nes::new();
//! // Various configurable settings for how to run the emulator
//! let settings = Settings::default();
//! // Advance the NES by 1 instruction
//! nes.advance_instruction(&settings);
//! // Advance the NES by 1 frame (continue advancing until a VBlank interval is triggered)
//! nes.advance_frame(&settings);
//! // Press the A button on player 1's controller
//! nes.set_controller_state(0, Controller {
//! up: false,
//! left: false,
//! right: false,
//! down: false,
//! a: true,
//! b: false,
//! start: false,
//! select: false
//! });
//! // Read the screen output
//! let rgb_output = nes.ppu.rgb_output();
//! let top_left_pixel = rgb_output[0][0];
//! println!("Top left pixel is R={} B={} G={}", top_left_pixel[0], top_left_pixel[1], top_left_pixel[2]);
//! // Get the audio output as a vector of samples
//! let audio_output = nes.apu.sample_queue();
//! println!("Read {} audio samples", audio_output.len());
//! // Reset the nes
//! nes.reset();
//! ```
pub use ;
pub use Cpu;
pub use Apu;
pub use StatusRegister;
pub use *;
pub use Ppu;
pub use Controller;
pub use Settings;
/// The debug palette, used instead of the palette ram if [Settings::use_debug_palette] is [true].
pub const DEBUG_PALETTE: = ;
/// The approximate clock speed of an NES, in hertz.
pub const CPU_CLOCK_SPEED: u32 = 1_789_000;
/// The location of the cartridge's interrupt vector.
pub const CARTRIDGE_IRQ_ADDR: usize = 0xFFFE;
/// The location of the reset interrupt vector.
pub const RESET_IRQ_ADDR: usize = 0xFFFC;
/// The location of the non-maskable interrupt's vector.
pub const NMI_IRQ_ADDR: usize = 0xFFFA;
const PALETTE_DATA: & = include_bytes!;
/// Map of the console's Hue/Value output to RGB values
pub const HV_TO_RGB: & =
// This is unsafe but it should only be evaluated at compile time
unsafe ;