Exemplo n.º 1
0
        public void initialize()
        {
            Veldrid.StartupUtilities.VeldridStartup.CreateWindowAndGraphicsDevice(
                new Veldrid.StartupUtilities.WindowCreateInfo(48, 48, 1280, 720, Veldrid.WindowState.Normal, "Example"),
                new Veldrid.GraphicsDeviceOptions(true, null, true), out window, out gd);

            window.Resized += () =>
            {
                gd.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);
                controller.WindowResized(window.Width, window.Height);
            };

            cl         = gd.ResourceFactory.CreateCommandList();
            controller = new Veldrid.ImGuiRenderer(gd, gd.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height);
        }
        static void Main(string[] args)
        {
            //AppDomain.CurrentDomain.ProcessExit+= (s,e)=>{}

            var path = Path.GetTempFileName();

            System.IO.File.WriteAllText(path, testVGAOutputProgram);
            var assemblerInst   = new assembler.Assembler(path);
            var assembledResult = assemblerInst.ConvertToBinary();
            var binaryProgram   = assembledResult.Select(x => Convert.ToInt32(x, 16));

            //lets convert our final assembled program back to assembly instructions so we can view it.
            //dissasembly)
            var assembler2 = new assembler.Assembler(path);

            expandedCode = assembler2.ExpandMacros().ToArray();


            simulatorInstance = new simulator.eightChipsSimulator(16, (int)Math.Pow(2, 16));
            simulatorInstance.setUserCode(binaryProgram.ToArray());

            //TODO use cancellation token here.
            simulationThread = Task.Run(() =>
            {
                simulatorInstance.ProgramCounter = (int)assembler.Assembler.MemoryMap[assembler.Assembler.MemoryMapKeys.user_code].AbsoluteStart;
                simulatorInstance.runSimulation();
            });


            // Create window, GraphicsDevice, and all resources necessary for the demo.
            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, "8 chips simulator 2"),
                new GraphicsDeviceOptions(true, null, true),
                out mainWindow,
                out gd);

            mainWindow.Resized += () =>
            {
                gd.MainSwapchain.Resize((uint)mainWindow.Width, (uint)mainWindow.Height);
                controller.WindowResized(mainWindow.Width, mainWindow.Height);
            };
            commandList = gd.ResourceFactory.CreateCommandList();
            controller  = new Veldrid.ImGuiRenderer(gd, gd.MainSwapchain.Framebuffer.OutputDescription, mainWindow.Width, mainWindow.Height);

            var data = simulatorInstance.mainMemory.Select(x => convertShortFormatToFullColor(Convert.ToInt32(x).ToBinary())).ToArray();

            //try creating an texture and binding it to an image which imgui will draw...
            //we'll need to modify this image every frame potentially...

            var texture = gd.ResourceFactory.CreateTexture(TextureDescription.Texture2D(width, height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled));

            CPUframeBufferTextureId = controller.GetOrCreateImGuiBinding(gd.ResourceFactory, texture);
            gd.UpdateTexture(texture, data, 0, 0, 0, width, height, 1, 0, 0);
            textureMap.Add(CPUframeBufferTextureId, texture);

            /*
             *          var state = new object();
             *          var timer = new System.Threading.Timer((o) =>
             *          {
             *              int[] newdata = simulatorInstance.mainMemory.Select(x => convertShortFormatToFullColor(x)).ToArray();
             *              var currenttexture = textureMap[CPUframeBufferTextureId];
             *              gd.UpdateTexture(currenttexture, newdata, 0, 0, 0, 256, 256, 1, 0, 0);
             *          }, state, 1000, 150);
             *
             */
            // Main application loop
            while (mainWindow.Exists)
            {
                InputSnapshot snapshot = mainWindow.PumpEvents();
                if (!mainWindow.Exists)
                {
                    break;
                }
                controller.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

                SubmitUI();

                commandList.Begin();
                commandList.SetFramebuffer(gd.MainSwapchain.Framebuffer);
                commandList.ClearColorTarget(0, new RgbaFloat(.1f, .1f, .1f, .2f));
                controller.Render(gd, commandList);
                commandList.End();
                gd.SubmitCommands(commandList);
                gd.SwapBuffers(gd.MainSwapchain);
            }

            // Clean up Veldrid resources
            gd.WaitForIdle();
            controller.Dispose();
            commandList.Dispose();
            gd.Dispose();
        }