|
| 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 | +
|
1 | 4 | struct Emulator {
|
2 | 5 | state: nes::State,
|
3 | 6 | }
|
@@ -27,19 +30,36 @@ fn main() {
|
27 | 30 | nes.load_rom(ROM).unwrap();
|
28 | 31 |
|
29 | 32 | 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. |
31 | 47 | for _ in 0..4 {
|
32 | 48 | nes.execute_until_vblank().unwrap();
|
33 | 49 | }
|
34 | 50 |
|
| 51 | + // Now we can press a button to start the game. |
35 | 52 | nes.press(nes::ControllerPort::First, nes::Button::Select);
|
36 | 53 | nes.execute_until_vblank().unwrap();
|
37 | 54 | nes.release(nes::ControllerPort::First, nes::Button::Select);
|
38 | 55 |
|
| 56 | + // We need to wait for at least three frames until we can trigger |
| 57 | + // the autosolve mechanism. |
39 | 58 | for _ in 0..3 {
|
40 | 59 | nes.execute_until_vblank().unwrap();
|
41 | 60 | }
|
42 | 61 |
|
| 62 | + // Now we can press select to make the game start playing itself. |
43 | 63 | nes.press(nes::ControllerPort::First, nes::Button::Select);
|
44 | 64 | nes.execute_until_vblank().unwrap();
|
45 | 65 | nes.release(nes::ControllerPort::First, nes::Button::Select);
|
|
0 commit comments