Skip to content

feat: Complete emulator loop and add keyboard input support#1

Open
zqigolden wants to merge 3 commits intomasterfrom
feat/complete-emulator-6470720059225870883
Open

feat: Complete emulator loop and add keyboard input support#1
zqigolden wants to merge 3 commits intomasterfrom
feat/complete-emulator-6470720059225870883

Conversation

@zqigolden
Copy link
Copy Markdown
Owner

This pull request finalizes the initial "half-finished" state of the PyNes emulator by addressing the core requirements: it loads a sample game, properly accepts user inputs, and lets the simulation run until explicitly closed.

Changes:

  1. main.py: The simulation loop no longer forcefully stops at 1000000 cycles. Instead, it runs as long as the Pygame engine continues to run (while not bus.ppu.engine.finished).
  2. Sample Game: Switched from the test ROM full_palette.nes to an actual game, Pac-Man (USA) (Namco).nes.
  3. Inputs: Implemented logic to capture keyboard states (Z, X, A, S, and Arrow Keys) and bitwise map them to the corresponding NES buttons. The input polling occurs once per frame when bus.ppu.frame_complete is True.
  4. engine.py: Added a get_keys function that pumps the Pygame event queue and reads the pressed keys.

PR created automatically by Jules for task 6470720059225870883 started by @zqigolden

- Removed 1,000,000 cycle limitation in main loop so simulation runs continuously.
- Replaced debug ROM with Pac-Man (USA) (Namco).nes sample game.
- Added get_keys() in pynes/engine.py to process pygame events and capture input.
- Mapped pygame keyboard keys to NES controller bit sequence (A, B, Select, Start, Up, Down, Left, Right).
- Ensured inputs are polled once per frame when the PPU signals frame_complete.

Co-authored-by: zqigolden <27563199+zqigolden@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules bot and others added 2 commits March 22, 2026 22:54
- Fixed SBC overflow logic to use inverted operand (val)
- Fixed PHP to correctly handle B flag
- Fixed PLP to correctly set U and clear B flag
- Fixed RTI to correctly set U flag

Co-authored-by: zqigolden <27563199+zqigolden@users.noreply.github.com>
- Updated `requirements.txt` to include `pygame`, `easydict`, `typer`, and `loguru`.
- Added detailed English `README.md` and Chinese `README-CN.md`.
- Added high-level docstrings to `Bus`, `CPU`, `PPU`, `Engine` classes, and `main()`.

Co-authored-by: zqigolden <27563199+zqigolden@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant