FPGA Multiplayer Tetris
ardware-accelerated Tetris on a Spartan-7 FPGA + MicroBlaze by @michaelxu2288, with a VGA/audio pipeline and two-player UDP Ethernet over a WIZnet W5500 Pmod.
프로젝트가 하는 일
FPGA Multiplayer Tetris는 Xilinx Spartan-7(Urbana) FPGA 위에 구현한 하드웨어 가속 테트리스입니다. MicroBlaze 소프트 프로세서(SoC)가 게임 로직·입력·점수·네트워크를 담당하고, 그래픽·오디오·네트워킹은 커스텀 SystemVerilog 엔진으로 처리합니다. 최신 리비전에서 2인 이더넷 대전(UDP/IPv4) 이 추가되었습니다.
- 하드웨어 가속 VGA/HDMI 파이프라인: shape ROM + palette ROM 조회로 640×480@60Hz 렌더링(25.175MHz 픽셀 클럭)
- MicroBlaze SoC: C 펌웨어가 게임플레이·USB 키보드 입력(AXI UART-Lite/MAX3421E)·점수·이더넷 소켓 관리
- 온칩 BRAM: 10×20 플레이필드를 듀얼포트로 저장 → 로직과 CPU가 충돌 없이 동시 접근
- 오디오: AXI SPI 코덱 + PWM IP로 MIDI 스타일 ROM의 사각파 톤을 재생(테트리스 테마)
- 결정적 타이밍: vsync 기반 tick으로 낙하 속도 제어
- 멀티플레이어: lwIP(소프트웨어) 또는 W5500 하드웨어 스택을 통해 UDP로 두 인스턴스를 <16ms 지연으로 동기화
WIZnet이 들어가는 위치
이 프로젝트의 이더넷은 두 가지 옵션 중 선택하는데, 그중 하나가 WIZnet W5500 Pmod(Digilent NIC100) 입니다.
- W5500 Pmod (SPI): MAC+PHY가 통합된 plug-and-play 방식. 하드웨어 TCP/UDP 스택을 내장해 별도 소프트웨어 스택 없이 바로 소켓 통신이 가능하고, 보드에 이더넷이 없어도 Pmod 헤더 + SPI만으로 네트워크를 붙일 수 있습니다. (실용 처리량은 SPI 특성상 ~50Mbps)
- 대안인 AXI Ethernet Lite + 외부 PHY는 100Mbps 라인레이트에 lwIP와 매끄럽지만, MII/RMII 배선·25MHz 클럭·마그네틱스가 필요합니다.
즉, W5500은 "가장 빠르게 이더넷을 붙이는 길" 로 제시됩니다. FPGA는 spi_master + w5500_ctrl 모듈로 W5500 Pmod를 8-bit SPI로 구동하고, socket 0을 UDP 모드로 열어 상대 보드와 게임 상태를 주고받습니다. 게임처럼 지연에 민감한 실시간 통신에서 하드웨어 TCP/IP 오프로드가 특히 유리합니다.
게임 상태 동기화
- 프로토콜: 오버헤드가 작은 raw UDP 데이터그램
- 페이로드 방식: ① 입력 동기(lock-step) — 키 입력만 전송, 각 FPGA가 양쪽 보드를 시뮬레이션 / ② 이벤트 동기(versus) — 라인클리어·가비지·점수 스냅샷 전송
- 타이밍: 네트워크 TX/RX를 비디오 프레임당 1회 수행(폴링으로 충분, 패킷 도착 IRQ도 사용 가능)
- 신뢰성: 가끔의 패킷 손실은 자기보정, 중요한 이벤트는 중복 전송/ACK로 보강
구현 메모
- 주요 모듈:
tetris_core(중력·회전·충돌·라인클리어),tetris_render(RGB 픽셀 매핑),vga_controller(640×480@60Hz),udp_tx_engine/udp_rx_engine(IPv4+UDP 헤더·체크섬),spi_master+w5500_ctrl(W5500 SPI·socket0 UDP),axi_emaclite_wrapper,axi_lite_slv(펌웨어 제어 레지스터) - 리소스/전력: LUT 3,245 · FF 4,283 · BRAM18K 22 · DSP 0 · Fclk 100MHz · 총 전력 0.504W (매우 낮음)
- 빌드: Vivado 2023.x에서 프로젝트 열기 → 백엔드 선택(
BACKEND=ETH_W5500_SPI로 NIC100을JD에 연결, 또는ETH_AXI_MAC) → 비트스트림 생성 → Vitis에서 lwIP v2 활성화 후tetris_mb.elf빌드 → FPGA 프로그래밍 → 두 보드를 크로스오버/스위치로 연결.
유사 프로젝트
https://maker.wiznet.io/irina/projects/atarix/
두 프로젝트는 모두 FPGA 기반의 레트로/게임 지향 시스템에서 W5500으로 네트워크를 붙인다는 점에서 유사합니다. 다만 이 테트리스는 테트리스라는 특정 게임을 하드웨어 가속으로 구현하고 2인 UDP 대전을 하는 프로젝트이고, ATARIX는 W65C816S CPU + ECP5 FPGA 패브릭 기반의 레트로 컴퓨터/콘솔형 플랫폼으로 W5500을 부팅(netboot/NTP) 브링업에 쓴다는 점이 다릅니다.
| 항목 | FPGA Multiplayer Tetris | ATARIX |
|---|---|---|
| 성격 | 하드웨어 가속 게임(테트리스) | 레트로 컴퓨터/콘솔형 플랫폼 |
| 코어 | MicroBlaze SoC (Spartan-7) | W65C816S CPU + ECP5 FPGA + RP2350 |
| W5500 역할 | 2인 UDP 대전 링크 | 부팅(netboot/NTP) 브링업 |
| 프로토콜 | UDP/IPv4 | netboot / NTP |
| 초점 | 실시간 게임플레이·렌더 | 레트로 시스템 아키텍처 |
FAQ
Q: 이 프로젝트는 무엇인가요? A: Spartan-7 FPGA + MicroBlaze로 만든 하드웨어 가속 테트리스로, VGA 출력·오디오·2인 UDP 이더넷 대전을 지원합니다.
Q: W5500은 어떻게 쓰이나요? A: 두 가지 이더넷 옵션 중 plug-and-play 방식으로, W5500 Pmod를 SPI로 구동하고 socket 0을 UDP 모드로 열어 상대 보드와 게임 상태를 주고받습니다.
Q: W5500 없이도 되나요? A: 네. 대안으로 AXI Ethernet Lite + 외부 PHY 구성이 가능합니다. 다만 보드에 이더넷이 없으면 W5500 Pmod가 가장 빠른 방법입니다.
Q: 지연은 얼마나 되나요? A: UDP 링크로 종단 간 <16ms를 목표로 하며, 네트워크 송수신은 비디오 프레임당 1회 수행합니다.
What the Project Does
FPGA Multiplayer Tetris is a hardware-accelerated Tetris on a Xilinx Spartan-7 (Urbana) FPGA. A MicroBlaze soft-processor (SoC) runs game logic, input, scoring, and networking, while graphics/audio/networking are handled by custom SystemVerilog engines. The latest revision adds two-player Ethernet play over UDP/IPv4.
- Hardware-accelerated VGA/HDMI pipeline: shape ROM + palette ROM lookups render 640×480@60 Hz (25.175 MHz pixel clock)
- MicroBlaze SoC: C firmware manages gameplay, USB keyboard input (AXI UART-Lite / MAX3421E), scoring, and Ethernet sockets
- On-chip BRAM: dual-port 10×20 playfield for hazard-free concurrent access by logic and CPU
- Audio: AXI SPI codec + PWM IP plays square-wave tones from a MIDI-style ROM (Tetris theme)
- Deterministic timing: a vsync-derived tick controls piece gravity
- Multiplayer: lwIP (software) or the W5500 hardware stack synchronizes two instances over UDP with <16 ms end-to-end delay
Where WIZnet Fits
Ethernet is a choice of two options, one of which is the WIZnet W5500 Pmod (Digilent NIC100).
- W5500 Pmod (SPI): an integrated MAC+PHY, plug-and-play. Its hardware TCP/UDP stack enables socket communication with no separate software stack, and it adds networking to a board that has none using only a Pmod header + SPI. (Practical throughput ~50 Mbps over SPI.)
- The alternative, AXI Ethernet Lite + external PHY, offers 100 Mbps line-rate and clean lwIP integration but needs MII/RMII wiring, a 25 MHz clock, and magnetics.
So the W5500 is presented as the fastest way to add Ethernet. The FPGA drives the W5500 Pmod over 8-bit SPI via spi_master + w5500_ctrl, opening socket 0 in UDP mode to exchange game state with the peer board. For latency-sensitive real-time comms like a game, the hardware TCP/IP offload is especially helpful.
Game-State Synchronization
- Protocol: low-overhead raw UDP datagrams
- Payload options: (1) input-driven lock-step — send keystrokes, each FPGA simulates both boards; (2) event-driven versus — send line-clear/garbage events and score snapshots
- Timing: network TX/RX once per video frame (polling suffices; packet-arrival IRQ also available)
- Reliability: occasional packet loss is self-correcting; critical events can be resent/ACKed
Implementation Notes
- Key modules:
tetris_core(gravity/rotation/collision/line-clears),tetris_render(RGB pixel mapping),vga_controller(640×480@60 Hz),udp_tx_engine/udp_rx_engine(IPv4+UDP headers/checksum),spi_master+w5500_ctrl(W5500 SPI, socket 0 UDP),axi_emaclite_wrapper,axi_lite_slv(firmware control registers) - Resources/power: LUT 3,245 · FF 4,283 · BRAM18K 22 · DSP 0 · Fclk 100 MHz · total power 0.504 W (very low)
- Build: open the project in Vivado 2023.x → pick backend (
BACKEND=ETH_W5500_SPIwith the NIC100 onJD, orETH_AXI_MAC) → generate bitstream → in Vitis enable lwIP v2 and buildtetris_mb.elf→ program the FPGA → connect two boards via crossover cable or switch.
Similar Project
https://maker.wiznet.io/irina/projects/atarix/
Both projects are FPGA-based retro/gaming-oriented systems that add networking via the W5500. However, this Tetris implements a specific game (Tetris) with hardware acceleration and two-player UDP play, while ATARIX is a retro computer / console-style platform (W65C816S CPU + ECP5 FPGA fabric + RP2350) that uses the W5500 for boot (netboot/NTP) bring-up.
| Item | FPGA Multiplayer Tetris | ATARIX |
|---|---|---|
| Nature | HW-accelerated game (Tetris) | Retro computer/console platform |
| Core | MicroBlaze SoC (Spartan-7) | W65C816S CPU + ECP5 FPGA + RP2350 |
| W5500 role | Two-player UDP link | Boot (netboot/NTP) bring-up |
| Protocol | UDP/IPv4 | netboot / NTP |
| Focus | Real-time gameplay & render | Retro system architecture |
FAQ
Q: What is this project? A: A hardware-accelerated Tetris on a Spartan-7 FPGA + MicroBlaze, with VGA output, audio, and two-player UDP Ethernet play.
Q: How is the W5500 used? A: As the plug-and-play Ethernet option — the W5500 Pmod is driven over SPI, opening socket 0 in UDP mode to exchange game state with the peer board.
Q: Can it work without the W5500? A: Yes. The alternative is AXI Ethernet Lite + an external PHY. But if the board has no Ethernet, the W5500 Pmod is the quickest path.
Q: What's the latency? A: The UDP link targets <16 ms end-to-end, with network TX/RX performed once per video frame.
