示例#1
0
 protected override void Initialize()
 {
     Render.Initialize(graphics.GraphicsDevice);
     MouseInput.Initialize();
     KeyboardInput.Initialize();
     base.Initialize();
     Console.WriteLine("engine initialized");
     cpu.Initialize();
 }
示例#2
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            base.Update(gameTime);
            cpu.Cycle();
            MouseInput.Update();
            KeyboardInput.Update();
        }
示例#3
0
        private void Dispatch0x0E(ParsedOpCode parsedOpCode)
        {
            switch (parsedOpCode.NN)
            {
            case 0x9E:
                // Skip the next instruction if the key mapped to the hex value in register VX is pressed
                if (KeyboardInput.IsKeyPressed(CPU.V[parsedOpCode.X]))
                {
                    CPU.ProgramCounter += 2;
                }
                break;

            case 0xA1:
                // Skip the next instruction if the key mapped to the hex value in register VX is not pressed
                if (!KeyboardInput.IsKeyPressed(CPU.V[parsedOpCode.X]))
                {
                    CPU.ProgramCounter += 2;
                }
                break;

            default:
                throw new NotSupportedException();
            }
        }
示例#4
0
        private void Dispatch0x0F(ParsedOpCode parsedOpCode)
        {
            switch (parsedOpCode.NN)
            {
            case 0x07:
                // Store the current value of the delay timer in register VX
                CPU.V[parsedOpCode.X] = CPU.DelayTimer.Value;
                break;

            case 0x0A:
                // Wait for a keypress and store the result in register VX
                var hexKey = KeyboardInput.WaitForKey();
                CPU.V[parsedOpCode.X] = hexKey;

                break;

            case 0x15:
                // Set the delay timer to the value of register VX
                CPU.DelayTimer.Value = parsedOpCode.X;
                break;

            case 0x18:
                // Set the sound timer to the value of register VX
                CPU.SoundTimer.Value = parsedOpCode.X;
                break;

            case 0x1E:
                // Add the value stored in register VX to register I
                CPU.Index += CPU.V[parsedOpCode.X];
                break;

            case 0x29:
                // Set I to the memory address of the sprite data stored in register VX
                CPU.Index = (UInt16)(CPU.V[parsedOpCode.X] * 5 + Memory.StartFontLocation);
                break;

            case 0x33:
                // Store the binary-coded decimal equivalent of the value stored in register VX at addresses I, I + 1, and I + 2
                var decimalNum = CPU.V[parsedOpCode.X];

                Memory[CPU.Index]     = (byte)(decimalNum / 100);
                Memory[CPU.Index + 1] = (byte)((decimalNum % 100) / 10);
                Memory[CPU.Index + 2] = (byte)((decimalNum % 10) % 10);
                break;

            case 0x55:
                // Store the values of registers V0 to VX inclusive in memory starting at address I.
                // X + 1 is added to I after completion
                for (int i = 0; i <= parsedOpCode.X; i += 1)
                {
                    Memory[CPU.Index + i] = CPU.V[i];
                }

                CPU.Index += (UInt16)(parsedOpCode.X + 1);
                break;

            case 0x65:
                // Fill registers V0 to VX inclusive with the values stored in memory starting at address I
                // X + 1 is added to I after operation
                for (int i = 0; i <= parsedOpCode.X; i += 1)
                {
                    CPU.V[i] = Memory[CPU.Index + i];
                }

                CPU.Index += (UInt16)(parsedOpCode.X + 1);
                break;

            default:
                throw new NotSupportedException();
            }
        }