Skip to content

Commit 1b1eef8

Browse files
committed
Add more comments
1 parent 7f7d463 commit 1b1eef8

File tree

1 file changed

+21
-1
lines changed
  • collector/runtime-benchmarks/nes/src

1 file changed

+21
-1
lines changed

collector/runtime-benchmarks/nes/src/main.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! This benchmark runs a simple game under a mostly cycle-accurate NES emulator,
2+
//! which under the hood is essentially just a fancy bytecode interpreter.
3+
14
struct Emulator {
25
state: nes::State,
36
}
@@ -27,19 +30,36 @@ fn main() {
2730
nes.load_rom(ROM).unwrap();
2831

2932
move || {
30-
// Trigger the autosolve mechanism in the ROM.
33+
// By default the game which we're emulating stays on the main menu
34+
// screen without anything happening on screen; it doesn't even try
35+
// to play any music.
36+
//
37+
// Pressing any button on the gamepad actually starts the game, and
38+
// once the game is started pressing the select button triggers
39+
// an autosolve mechanism which makes the game automatically play itself.
40+
//
41+
// So let's trigger this here.
42+
43+
// We need to wait for four frames until the game accepts any input.
44+
//
45+
// I don't know why; I just started to empirically increase the number
46+
// of frames until it worked.
3147
for _ in 0..4 {
3248
nes.execute_until_vblank().unwrap();
3349
}
3450

51+
// Now we can press a button to start the game.
3552
nes.press(nes::ControllerPort::First, nes::Button::Select);
3653
nes.execute_until_vblank().unwrap();
3754
nes.release(nes::ControllerPort::First, nes::Button::Select);
3855

56+
// We need to wait for at least three frames until we can trigger
57+
// the autosolve mechanism.
3958
for _ in 0..3 {
4059
nes.execute_until_vblank().unwrap();
4160
}
4261

62+
// Now we can press select to make the game start playing itself.
4363
nes.press(nes::ControllerPort::First, nes::Button::Select);
4464
nes.execute_until_vblank().unwrap();
4565
nes.release(nes::ControllerPort::First, nes::Button::Select);

0 commit comments

Comments
 (0)