static void Main(string[] args) { short[] colorMap = new short[] { 1, 2 }; IntPtr screen = default; NCursesDisplay display = null; IChip8Device device = null; Func <bool>[] initializers = { () => InitializeNCurses(ref screen, colorMap, DefaultWidth, DefaultHeight), () => InitializeDisplayBuffer(ref display, screen, colorMap), () => BuildDevice(ref device, display.Buffer), () => LoadProgram(device, "program") }; try { if (initializers.All(p => p())) { Run(device, display); } } catch (Exception e) { Console.Error.WriteLine($"Caught an exception: {e.Message}"); } NCurses.EndWin(); }
static void Main(string[] args) { try { IChip8Device device = BuildDevice(); LoadProgram(device, "program"); int displayContentVersion = _display.ContentVersion; while (true) { device.Tick(); if (displayContentVersion != _display.ContentVersion) { DrawScreen(_display); displayContentVersion = _display.ContentVersion; } // System.Threading.Thread.Sleep(100); } } catch (Exception e) { Console.Error.WriteLine($"Caught an exception: {e.Message}"); } }
static bool LoadProgram(IChip8Device device, string programPath) { using (var stream = new FileStream(programPath, FileMode.Open)) using (var loader = new ProgramLoader(device)) loader.Load(stream); return(true); }
private static void Run(IChip8Device device, NCursesDisplay display) { while (true) { device.Tick(); display.Draw(); System.Threading.Thread.Sleep(100); } }
public ProgramLoader(IChip8Device device) => _device = device;
static bool BuildDevice(ref IChip8Device device, DisplayBuffer buffer) { using (var builder = new Chip8DeviceBuilder()) device = builder.Build(new KeyboardStub(), buffer); return(true); }
static void LoadProgram(IChip8Device device, string programPath) { using (var stream = new FileStream("program", FileMode.Open)) using (var loader = new ProgramLoader(device)) loader.Load(stream); }