Skip to content

dh73/SpaceInvaders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SystemC Over-Engineered Space Invaders Simulator

A hardware-software co-design implementation of the classic Space Invaders game using SystemC for system-level modeling and simulation. This project demonstrates transaction-level modeling (TLM), hardware acceleration, neural network processing, and power modeling in a SystemC environment.

Screenshot

Space Invaders Game Screenshot

Architecture Overview

The system implements a modular architecture using SystemC TLM sockets for inter-module communication:

GameTop (Top-level module)
├── CPU (Game logic processor)
├── Bus (TLM interconnect)
├── Display (SDL2 rendering)
├── Input (Keyboard handling)
├── Memory (System memory)
├── Accelerator (Collision detection HW)
├── NNAccelerator (Neural network processing)
└── PowerModel (Power consumption modeling)

Core Components

  • CPU (modules/cpu.{h,cpp}): Main game logic processor implementing Space Invaders gameplay, including player movement, bullet physics, collision detection, and game state management
  • Bus (modules/bus.{h,cpp}): TLM-based interconnect routing transactions between CPU and peripheral modules using address decoding
  • Display (modules/display.{h,cpp}): SDL2-based graphics renderer with command queue processing for draw and text operations
  • Input (modules/input.{h,cpp}): Keyboard input handler with interrupt generation capabilities
  • Accelerator (modules/accelerator.{h,cpp}): Hardware accelerator for collision detection and row boundary calculations with parallel processing
  • NNAccelerator (modules/nn_accelerator.{h,cpp}): Neural network processing unit implementing MLP for AI-based game behavior
  • Memory (modules/memory.{h,cpp}): System memory module with TLM interface
  • PowerModel (modules/power_model.{h,cpp}): Dynamic power consumption modeling and DVFS control

Key Features

  • Transaction-Level Modeling: TLM 2.0 sockets for communication between modules
  • Hardware Acceleration: Dedicated accelerator for computationally intensive collision detection
  • Neural Network Integration: On-chip MLP for adaptive gameplay mechanics
  • Power Modeling: Dynamic power tracking with frequency scaling simulation
  • Quantum Random Number Generation: QRNG implementation for enhanced randomness
  • Debug Support: Comprehensive debug mode with performance metrics

Implementation Details

Memory Map

  • Input Controller: 0x1000
  • Display Controller: 0x2000
  • Power Manager: 0x3000
  • Accelerator: 0x4000
  • System Memory: 0x5000-0x6FFF
  • NN Accelerator: 0x6000

Game Mechanics

  • 5x11 invader formation with row-based movement patterns
  • Destructible bunkers with pixel-level damage tracking
  • Multi-bullet system (100 player, 200 invader bullets max)
  • Adaptive difficulty through neural network-based speed control

Hardware Acceleration

The collision detection accelerator processes invader rows in parallel, computing:

  • Row boundary calculations (min/max positions)
  • Bullet-invader collision detection
  • Bunker collision and damage modeling

Dependencies

Required Libraries

  • SystemC 2.3+: System-level modeling framework
  • SDL2: Graphics and input handling
  • SDL2_ttf: Text rendering support
  • SDL2_mixer: Audio support (linked but optional)

System Requirements

  • C++17 compatible compiler (GCC recommended)
  • POSIX-compliant system (Linux/macOS)
  • SystemC installation with TLM support

Installation

Ubuntu/Debian

sudo apt-get install libsystemc-dev libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev

Building from Source

  1. Install SystemC from https://systemc.org
  2. Install SDL2 development libraries
  3. Set SYSTEMC_HOME environment variable if needed

Build Instructions

make clean
make all

Available Targets

  • make all: Build the executable
  • make run: Build and run the simulation
  • make debug: Build and run with debug output
  • make clean: Remove build artifacts

Usage

Basic Execution

./space_invaders

Debug Mode

./space_invaders -debug

Debug mode provides detailed logging of:

  • SystemC simulation events
  • TLM transaction details
  • Performance metrics
  • Power consumption data

Controls

  • Left/Right Arrow: Move player
  • Spacebar: Fire bullets
  • ESC: Quit game

Performance Considerations

The simulator includes several performance optimizations:

  • TLM Direct Memory Interface (DMI) for high-speed memory access
  • Parallel collision detection using hardware acceleration
  • Optimized SDL2 rendering with command queues
  • Quantum keeper for SystemC simulation performance

Technical Notes

  • Uses TLM 2.0 blocking transport for simplicity and determinism
  • Implements approximate timing for realistic hardware modeling
  • Neural network training occurs during gameplay for adaptive behavior
  • Power modeling includes both static and dynamic components
  • QRNG provides quantum-inspired randomness for enhanced gameplay variety

License

This project is intended for educational and research purposes, demonstrating SystemC-based hardware-software co-design methodologies.

About

A SystemC/TLM implementation of Space Invaders Game

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published