Exemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();
            this.spinningTriangleControl.Size = GetControlSize();
            chip8 = new Chip8();

            // Create an emulator renderer control that will be displayed when a ROM is loaded
            this.emulatorRendererControl = new Chip8Emulator.GraphicsControls.EmulatorRendererControl(chip8);
            this.emulatorRendererControl.Location = new System.Drawing.Point(0, 24);
            this.emulatorRendererControl.Margin = new Padding(0);
            this.emulatorRendererControl.Name = "emulatorRendererControl";
            this.emulatorRendererControl.TabIndex = 1;
            this.emulatorRendererControl.Text = "Emulator renderer control";

            // Attaching the key listeners to the renderer control
            this.emulatorRendererControl.KeyUp += new KeyEventHandler(KeyUpHandler);
            this.emulatorRendererControl.KeyDown += new KeyEventHandler(KeyDownHandler);

            // Loading a soundplayer and a sound file
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
            String[] hurr = a.GetManifestResourceNames();
            System.IO.Stream s = a.GetManifestResourceStream("Chip8Emulator.Resources.durr_quiet.wav");
            player = new SoundPlayer(s);

            sw = Stopwatch.StartNew();
            // Setting the timer to tick 60 times per second
            // the timer is started when loading applications and stopped unloading
            //refreshTimer = new Timer();
            //refreshTimer.Interval = 1000 / 60;
            //refreshTimer.Tick += delegate { this.UpdateScreen(); };
        }
Exemplo n.º 2
0
        public Screen(Chip8 chip8)
        {
            _cpu = chip8.Cpu;
            _width = InternalWidth * Pixel.PixelWidth;
            _height = InternalHeight * Pixel.PixelHeight;

            _pixels = new Pixel[InternalWidth][];
            for (int i = 0; i < InternalWidth; i++)
                _pixels[i] = new Pixel[InternalHeight];
        }
Exemplo n.º 3
0
        private bool _waitForInput; // Utilisé par FX0A afin d'attendre une entrée clavier

        #endregion Fields

        #region Constructors

        public Cpu(Chip8 chip8)
        {
            this._memory = new byte[SharpChip8.Core.Memory.MemorySize];
            this._V = new byte[16];
            this._I = 0;
            this._stack = new Stack<ushort>(16);
            this._stackSize = 0;
            this._delayTimer = 0;
            this._soundTimer = 0;
            this._Pc = SharpChip8.Core.Memory.StartAddress;
            this._hp48 = new ushort[8];
            this._opcode = Opcode.GetOpcodeTable();
            this._input = new Input();
            this._chip8 = chip8;
            this._running = false; // Le processeur n'est pas démarré à la création
            this._waitForInput = false;
            this._currentOpcode = 0x0;
            ResetMemory();
            Reset();
        }
Exemplo n.º 4
0
 public BaseCommand(Chip8 chip)
 {
     Chip = chip;
 }
Exemplo n.º 5
0
 public x8XY5(ushort opcode, Chip8 chip) : base(chip)
 {
     X = (opcode & 0x0F00) >> 8;
     Y = (opcode & 0x00F0) >> 4;
 }
Exemplo n.º 6
0
 public x3XNN(ushort opcode, Chip8 chip) : base(chip)
 {
     X  = (opcode & 0x0F00) >> 8;
     NN = (opcode & 0x00FF);
 }
Exemplo n.º 7
0
 public OpcodeParser(Chip8 chip8Device)
 {
     this._chip8Device         = chip8Device;
     this._instructionResolver = new InstructionResolver();
 }
Exemplo n.º 8
0
 public xBNNN(ushort opcode, Chip8 chip) : base(chip)
 {
     NNN = (ushort)(opcode & 0x0FFF);
 }
Exemplo n.º 9
0
        public void Execute(Chip8 chip8Device, Opcode opcode)
        {
            byte registerX = (byte)((opcode.Value & 0x0F00) >> 8);

            chip8Device.SoundTimer = chip8Device.RegisterBank.V[registerX];
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Error no ROM file specified");
                return;
            }
            else
            {
                bool debugMode     = false;
                int  filePathIndex = 0;

                if (args[0].ToUpper() == "-DEBUG")
                {
                    debugMode     = true;
                    filePathIndex = 1;
                }

                if (!File.Exists(args[filePathIndex]))
                {
                    Console.WriteLine($"Error ROM file ({args[filePathIndex]}) not found.");
                }
                else
                {
                    audio    = new Audio();
                    input    = new Input();
                    graphics = new Graphics();

                    chp8 = new Chip8(graphics, audio, input);

                    //byte[] rom = LoadROMFile(@"/home/chippy/src/dotnet/core-chip8/chip8.roms/PONG");
                    byte[] rom = LoadROMFile(args[filePathIndex]);
                    //LoadROM
                    chp8.LoadROM(rom);

                    try
                    {
                        Gtk.Application.Init();
                        emulatorWindow              = new EmulatorWindow("Core Chip8");
                        emulatorWindow.DeleteEvent += delegate
                        {
                            KILL_EMULATION = true;
                            Gtk.Application.Quit();
                        };

                        if (debugMode)
                        {
                            LoadDebugEnvironment();
                        }

                        emulatorWindow.KeyPressEvent += new KeyPressEventHandler(input.KeyPressEventHandler);
                        emulatorWindow.ShowAll();

                        Thread t = new Thread(new ThreadStart(BackgroundTick));
                        t.Start();

                        Gtk.Application.Run();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
            }
        }
Exemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     chip = GetComponent <Chip8>();
     startEmulation(txt.bytes);
 }
Exemplo n.º 12
0
        public void Execute(Chip8 chip8Device, Opcode opcode)
        {
            ushort address = (ushort)(opcode.Value & 0x0FFF);

            chip8Device.RegisterBank.I = address;
        }
Exemplo n.º 13
0
 public Disassembler(Chip8 chip8)
 {
     _chip8 = chip8;
     asmWithoutLineNumber = String.Empty;
     asmWithLineNumber    = String.Empty;
 }
Exemplo n.º 14
0
        public void Execute(Chip8 chip8Device, Opcode opcode)
        {
            byte registerX = (byte)((opcode.Value & 0x0F00) >> 8);

            chip8Device.RegisterBank.I = (ushort)(chip8Device.RegisterBank.V[registerX] * 5);
        }
Exemplo n.º 15
0
        protected override void OnLoad()
        {
            base.OnLoad();

            GL.Enable(EnableCap.DebugOutput);
            DebugProc openGLDebugDelegate = new DebugProc(OpenGLDebugCallback);

            GL.DebugMessageCallback(openGLDebugDelegate, IntPtr.Zero);

            // Create shader
            shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag");
            shader.Use();

            // Create target texture
            textureHandle = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, textureHandle);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

            Random random = new Random();

            byte[] pixels = new byte[64 * 32];
            for (int i = 0; i < 64 * 32; i++)
            {
                pixels[i] = (byte)(random.NextDouble() * 255.0f);
            }
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R8, 64, 32, 0, PixelFormat.Red, PixelType.UnsignedByte, pixels);

            // Create mesh
            float[] vertices = new float[]
            {
                // vec2 position
                // vec2 texCoord

                // Top left triangle
                -1, -1, 0, 1,
                1, -1, 1, 1,
                -1, 1, 0, 0,

                // Bottom right triangle
                1, -1, 1, 1,
                1, 1, 1, 0,
                -1, 1, 0, 0,
            };

            vboHandle = GL.GenBuffer();
            vaoHandle = GL.GenVertexArray();

            GL.BindVertexArray(vaoHandle);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vboHandle);

            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0 * sizeof(float));

            GL.EnableVertexAttribArray(1);
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float));

            GL.BindVertexArray(vaoHandle);
            GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StreamDraw);

            // Load program
            byte[] fileBytes = File.ReadAllBytes("Roms/life.ch8");

            // Create emulator
            ushort[] instructions = new ushort[]
            {
                0x00E0, 0xF029, 0xD115, 0x7001, 0x1200
            };

            chip8 = new Chip8(fileBytes);
            //chip8 = new Chip8(instructions);

            chip8.DumpMemory();
        }
Exemplo n.º 16
0
        public void Execute(Chip8 chip8Device, Opcode opcode)
        {
            chip8Device.RegisterBank.I += (chip8Device.RegisterBank.V[((opcode.Value & 0x0F00) >> 8)]);

            int i = 0;
        }
Exemplo n.º 17
0
 public x00E0(Chip8 chip) : base(chip)
 {
 }
Exemplo n.º 18
0
 public void Setup()
 {
     chip8 = new Chip8();
     chip8.Initalize();
 }
Exemplo n.º 19
0
 public xFX18(ushort opcode, Chip8 chip) : base(chip)
 {
     X = (opcode & 0x0F00) >> 8;
 }
Exemplo n.º 20
0
 public x2NNN(ushort opcode, Chip8 chip) : base(chip)
 {
     address = (ushort)(opcode & 0x0FFF);
 }
Exemplo n.º 21
0
 public Disassembler(Chip8 chip8)
 {
     _chip8 = chip8;
     asmWithoutLineNumber = String.Empty;
     asmWithLineNumber = String.Empty;
 }
Exemplo n.º 22
0
 public void Execute(Chip8 chip8Device, Opcode opcode)
 {
     chip8Device.RegisterBank.PC = chip8Device.Cpu.Stack.Pop();
 }