Exemple #1
0
        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();
        }
Exemple #2
0
        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}");
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
 private static void Run(IChip8Device device, NCursesDisplay display)
 {
     while (true)
     {
         device.Tick();
         display.Draw();
         System.Threading.Thread.Sleep(100);
     }
 }
Exemple #5
0
 public ProgramLoader(IChip8Device device) => _device = device;
Exemple #6
0
 static bool BuildDevice(ref IChip8Device device, DisplayBuffer buffer)
 {
     using (var builder = new Chip8DeviceBuilder())
         device = builder.Build(new KeyboardStub(), buffer);
     return(true);
 }
Exemple #7
0
 static void LoadProgram(IChip8Device device, string programPath)
 {
     using (var stream = new FileStream("program", FileMode.Open))
         using (var loader = new ProgramLoader(device))
             loader.Load(stream);
 }