How botrandomness/code-dmg works
Project Type and Purpose
• CODE‑DMG is an open‑source Gameboy emulator written in C#. It provides a “Core” emulation engine (CLI) and a minimal GUI wrapper via Raylib‑cs for rendering and input. Its primary goal is to emulate the DMG‑CPU, PPU, MMU, MBC chips, timers, and joypad of the original Gameboy hardware in a cycle‑driven loop.
File Structure Analysis
• Top‑level files:
• CODE‑DMG.csproj – C# project file
• fall_back.gb – fallback ROM for testing
• git‑res/ – assets (logo, boot GIF, screenshots)
• src/ – core emulator components:
• Program.cs – entry point, parses CLI flags, initializes DMG
• DMG.cs – orchestrator wiring CPU, PPU, MMU, Timer, Joypad, and main emulation loop
• CPU.cs – executes instructions, drives cycle counts
• PPU.cs – Picture Processing Unit, scanline renderer
• MMU.cs – Memory Management Unit, unified 16‑bit address space and MMIO
• MBC.cs – Memory Bank Controller logic (bank switching for ROM/RAM)
• Timer.cs – hardware timer, interrupt generation
• Joypad.cs – input handling, updates MMIO bits
• Helper.cs – static constants, palettes, global enums
• Test.cs – JSON‑based CPU instruction test harness
• test/ – test resource descriptions
Key Insights from README
• Architecture is object‑oriented: one class per hardware component
• Emulation loop in DMG.Run() is “CPU‑driven”: fetch/execute instruction → returns cycle count → step PPU & Timer → after 70224 T‑cycles, end frame → render via Raylib at 60 FPS
• Dependencies: Raylib‑cs for graphics & input, .NET 6.0 runtime