This is a personal project, and its purpose is a narrow one: to reconstruct the core loop of Five Nights at Freddy's 4 in hardware, on an FPGA, with no processor and no operating system underneath it. The entire game exists as digital logic on the chip. It drives a VGA display directly, reads a keyboard, and produces its own audio.
The goal was never a large game. It was to take a single idea, the tension of watching two doors and surviving the night, and express it cleanly in register-transfer logic: the graphics, the state machine, the audio, and the input. Nothing more than the work requires, and nothing left half finished.
This is a fan-made, educational project. It is not affiliated with, endorsed by, or associated with Scott Cawthon or the official Five Nights at Freddy's franchise. All original FNAF characters and concepts remain the property of their respective owner.
Five Nights at Freddy's is a survival horror series created by Scott Cawthon and first released in 2014. It is built on a particular kind of pressure: limited resources, limited information, and consequences that arrive without warning.
Nightmare Bonnie, taken from the project's own Block RAM asset (Picture/bonnie.coe) and rendered on the FPGA.
Five Nights at Freddy's 4, released in 2015, is the fourth entry. It sets aside the security cameras of the earlier games and places the player in a child's bedroom. Survival depends on attention and discipline:
- listening for movement and checking the left and right doorways,
- using a flashlight to inspect the halls,
- holding a door shut at the correct moment.
The threats are not defeated. They are managed, one at a time, until the night is over. This project reproduces that loop in a deliberately reduced form: move through the room, check the doors, use the flashlight, and close a door when it is warranted.
A field-programmable gate array is a chip made of reconfigurable digital logic. A processor executes instructions in sequence. An FPGA does not. You describe the circuit you want in a hardware description language, in this case Verilog, and the toolchain configures the device to become that circuit.
The distinction matters here, because this game runs no software. There is nothing beneath it executing code. The game logic, the VGA timing, the audio driver, and the keyboard interface are all circuits, running at the same time, kept in order by a single clock.
The Digilent Basys 3 (Xilinx Artix-7 XC7A35T), the board this project runs on.
The design is written in Verilog and divided into small, self-contained modules.
| Area | Modules |
|---|---|
| Game state machine | main_state.v, gameplay_state.v, gameplay_countdown.v |
| Rendering and VGA | screen_controller.v, game_map.v, vga.v, jumpscare_control.v |
| Characters | bonnie.v, chika.v |
| Input | keyboard_control.v, KeyboardCtrl (PS/2) |
| Audio | audio_control.v |
| Board output | led_control.v, seven_segment_display_control.v |
The artwork, meaning the menus, rooms, doors, characters, and jumpscares, is held in on-chip Block RAM. The .coe files and the small Python utility under Picture/ convert each image into the memory-initialization format that the Block RAM cores load at build time.
To run this on real hardware you will need the following.
- A Digilent Basys 3 development board (Xilinx Artix-7 XC7A35T-1CPG236C).
- A VGA monitor and cable. The game outputs 640x480.
- A PS/2 keyboard, or a USB keyboard with a USB-to-PS/2 adapter, on the board's keyboard port.
- Audio output through the board's audio circuit (I2S:
audio_mclk,audio_lrck,audio_sck,audio_sdin), for example a Pmod I2S DAC or the board's audio out, with headphones or speakers. - A micro-USB cable to program the board.
If you intend to build from source, you will also need Xilinx Vivado 2019.2, the version this project was created with.
Input is read from a PS/2 keyboard.
| Key | Action |
|---|---|
| Enter | Start the game from the menu, or return to the menu after a win or loss |
| A | Look or move left |
| D | Look or move right |
| W | Step forward into the doorway you are facing |
| S | Step back into the main room |
| Space | Close or open the door you are standing at |
| F | Toggle the flashlight to check the hallway |
The board's switches set the volume. The LEDs and the seven-segment display show status, including the countdown.
- At the main menu, press Enter to begin the night.
- From the main room, use A and D to look toward the left or the right side.
- Press W to move up to a door, then use F to flash the light down the hall and check for an animatronic. Bonnie approaches from one side, Chica from the other.
- If one is there, press Space to shut the door and keep it out. Press S to return to the room.
- Survive until the night's timer runs out and you win. Let one reach you, and the jumpscare ends the night in a loss.
A ready-to-use bitstream, FNAF4.bit, is included, so no build step is required.
- Connect the Basys 3 to your PC with the micro-USB cable and power it on.
- Connect the VGA monitor, the PS/2 keyboard, and audio to the board.
- In Vivado, open the Hardware Manager, open the target, and auto-connect.
- Choose Program Device, select
FNAF4.bit, and program. - The main menu appears on the monitor. Press Enter to play.
If you prefer not to open the full Vivado interface, the Vivado Tcl console (program_hw_devices) or Digilent's Adept utility can flash FNAF4.bit directly.
- Install Xilinx Vivado 2019.2.
- Clone or download this repository.
- Open
FNAF/FNAF.xprin Vivado. - Confirm the target part is
xc7a35tcpg236-1and that the constraints fileFNAF_4_constraint.xdcis enabled. - Run Generate Bitstream. This performs synthesis and implementation, and the Block RAM cores regenerate from the included
.coeassets. - Open the Hardware Manager, connect to the board, and program it with the generated bitstream, following Option A from step 3.
Please check out these similar projects by friends of mine.
- Code and hardware design by Fincarson.
- Art by a friend, who is a great artist.
Five Nights at Freddy's and Five Nights at Freddy's 4 were created by Scott Cawthon. This is an unofficial, non-commercial project made for learning. All rights to the original characters and the franchise remain with their respective owner.
The original source code in this repository is released under the MIT License. See LICENSE for the full text.
This covers the original code only. The Five Nights at Freddy's characters and artwork are the property of Scott Cawthon and are not licensed here.
Contributions are welcome. See CONTRIBUTING.md and the Code of Conduct.
A personal project in FPGA design. One idea, carried out carefully, in hardware.



