Exemplo n.º 1
0
 private void SetVxRandomNumberAndNn(Instruction instruction)
 {
     var rnd = new Random(System.Environment.TickCount);
     this.RegisterV[instruction.X] = (byte)(rnd.Next(255) & instruction.Nn);
 }
Exemplo n.º 2
0
 private void FillV0ToVxFromMemory(Instruction instruction)
 {
     for (int i = 0; i <= instruction.X; i++)
     {
         this.RegisterV[i] = this.Memory[this.RegisterI + i];
     }
 }
Exemplo n.º 3
0
 private void CallRoutine(Instruction instruction)
 {
     this.stack.Push((ushort)this.ProgramCounter);
     this.ProgramCounter = instruction.Nnn;
 }
Exemplo n.º 4
0
 private void AddVxToI(Instruction instruction)
 {
     if (this.RegisterI + this.RegisterV[instruction.X] >= 0x1000)
     {
         this.RegisterI = (ushort)this.Memory.Size;
         this.RegisterV[0xF] = 1;
     }
     else
     {
         this.RegisterI += this.RegisterV[instruction.X];
     }
 }
Exemplo n.º 5
0
 private void StoreInVxDecimalRegisterI(Instruction instruction)
 {
     byte val = this.RegisterV[instruction.X];
     this.Memory[this.RegisterI] = (byte)(val / 100);
     this.Memory[this.RegisterI + 1] = (byte)((val % 100) / 10);
     this.Memory[this.RegisterI + 2] = (byte)((val % 100) % 10);
 }
Exemplo n.º 6
0
        private void SetVxToDelayTimer(Instruction instruction)
        {
            if (this.delayTimer < 0)
            {
                this.delayTimer = 0;
            }

            this.RegisterV[instruction.X] = (byte)this.delayTimer;
        }
Exemplo n.º 7
0
 private void SetDelayTimerToVx(Instruction instruction)
 {
     this.delayTimer = this.RegisterV[instruction.X];
 }
Exemplo n.º 8
0
        private void AddVyToVx(Instruction instruction)
        {
            const int Carry = 0xF;
            int result = this.RegisterV[instruction.X] + this.RegisterV[instruction.Y];

            this.RegisterV[Carry] = (byte)((result > (int)byte.MaxValue) ? 0x1 : 0x0);
            this.RegisterV[instruction.X] = (byte)result;
        }
Exemplo n.º 9
0
 private void SubtractVyToVx(Instruction instruction)
 {
     const int Carry = 0xF;
     this.RegisterV[Carry] = (byte)((this.RegisterV[instruction.X] > this.RegisterV[instruction.Y]) ? 0x1 : 0x0);
     this.RegisterV[instruction.X] -= this.RegisterV[instruction.Y];
 }
Exemplo n.º 10
0
 private void SetVxToVy(Instruction instruction)
 {
     this.RegisterV[instruction.X] = this.RegisterV[instruction.Y];
 }
Exemplo n.º 11
0
 private void SetVxToVxXorVy(Instruction instruction)
 {
     this.RegisterV[instruction.X] ^= this.RegisterV[instruction.Y];
     this.RegisterV[0xF] = 0;
 }
Exemplo n.º 12
0
 private void AddNnToVx(Instruction instruction)
 {
     this.RegisterV[instruction.X] += (byte)instruction.Nn;
 }
Exemplo n.º 13
0
 private void SetVxToNn(Instruction instruction)
 {
     this.RegisterV[instruction.X] = (byte)instruction.Nn;
 }
Exemplo n.º 14
0
 private void SkipNextRegisterVxNotEqualAddress(Instruction instruction)
 {
     if (this.RegisterV[instruction.X] != instruction.Nn)
     {
         this.ProgramCounter += 0x2;
     }
 }
Exemplo n.º 15
0
        private void DrawSprite(Instruction instruction)
        {
            const int Carry = 0xF;
            int size = instruction.N;

            int[] sprite = new int[size];
            int count = 0;
            for (int index = this.RegisterI; index < (this.RegisterI + size); index++)
            {
                sprite[count++] = this.Memory[index];
            }
            this.RegisterV[Carry] = this.Gpu.Draw(this.RegisterV[instruction.X], this.RegisterV[instruction.Y], sprite);
            this.Gpu.DrawFrame();
        }
Exemplo n.º 16
0
 private void ShiftVxRightByOne(Instruction instruction)
 {
     const int Carry = 0xF;
     this.RegisterV[Carry] = (byte)((this.RegisterV[instruction.X] & 0x1) == 0x1 ? 0x1 : 0x0);
     this.RegisterV[instruction.X] /= 2;
 }
Exemplo n.º 17
0
 private void SkipIfKeyInVxNotPressed(Instruction instruction)
 {
     if (this.RegisterV[instruction.X] != this.Keyboard.LastPressedKey)
     {
         this.ProgramCounter += 0x2;
     }
 }
Exemplo n.º 18
0
 private void SetVxToVyMinusVx(Instruction instruction)
 {
     const int Carry = 0xF;
     this.RegisterV[Carry] = (byte)((this.RegisterV[instruction.Y] >= this.RegisterV[instruction.X]) ? 0x1 : 0x0);
     this.RegisterV[instruction.X] = (byte)(this.RegisterV[instruction.Y] - this.RegisterV[instruction.X]);
 }
Exemplo n.º 19
0
 private void StoreWaitingKeyInVx(Instruction instruction)
 {
     var keyPressed = this.Keyboard.WaitingForKey();
     if (keyPressed > -1)
     {
         this.RegisterV[instruction.X] = (byte)keyPressed;
     }
 }
Exemplo n.º 20
0
 private void ShiftVxLeftByOne(Instruction instruction)
 {
     const int Carry = 0xF;
     this.RegisterV[Carry] = (byte)((this.RegisterV[instruction.X] & 0x80) >> 7 == 0x1 ? 0x1 : 0x0);
     this.RegisterV[instruction.X] *= 2;
 }
Exemplo n.º 21
0
 private void SetSoundTimerToVx(Instruction instruction)
 {
     this.Sound.Timer = this.RegisterV[instruction.X];
 }
Exemplo n.º 22
0
 private void SkipNextRegisterVxNotEqualVy(Instruction instruction)
 {
     if (this.RegisterV[instruction.X] != this.RegisterV[instruction.Y])
     {
         this.ProgramCounter += 0x2;
     }
 }
Exemplo n.º 23
0
 private void SetIToCharacterVx(Instruction instruction)
 {
     this.RegisterI = this.RegisterV[instruction.X] * 5;
 }
Exemplo n.º 24
0
 private void SetIToAddressNnn(Instruction instruction)
 {
     this.RegisterI = instruction.Nnn;
 }
Exemplo n.º 25
0
 private void StoreV0ToVx(Instruction instruction)
 {
     for (int i = 0; i <= instruction.X; i++)
     {
         this.Memory[this.RegisterI + i] = (byte)this.RegisterV[i];
     }
 }
Exemplo n.º 26
0
 private void JumpToPlusV0(Instruction instruction)
 {
     this.ProgramCounter = (ushort)(instruction.Nnn + this.RegisterV[0x0]);
 }
Exemplo n.º 27
0
        private void InterpretOpcode (Instruction instruction)
		{
			switch (instruction.Opcode) {
			case Opcodes.CLS:
				this.Gpu.Clear ();
				break;
			case Opcodes.RET:
				this.ReturnRoutine ();
				break;
			case Opcodes.JP:
				this.JumpTo (instruction);
				break;
			case Opcodes.CALL:
				this.CallRoutine (instruction);
				break;
			case Opcodes.SE:
				this.SkipNextRegisterVxEqualAddress (instruction);
				break;
			case Opcodes.SNE:
				SkipNextRegisterVxNotEqualAddress (instruction);
				break;
			case Opcodes.SER:
				SkipNextRegisterVxEqualVy (instruction);
				break;
			case Opcodes.SETB:
				SetVxToNn (instruction);
				break;
			case Opcodes.ADD:
				AddNnToVx (instruction);
				break;
			case Opcodes.SET:
				SetVxToVy (instruction);
				break;
			case Opcodes.OR:
				SetVxToVxOrVy (instruction);
				break;
			case Opcodes.AND:
				SetVxToVxAndVy (instruction);
				break;
			case Opcodes.XOR:
				SetVxToVxXorVy (instruction);
				break;
			case Opcodes.ADDR:
				AddVyToVx (instruction);
				break;
			case Opcodes.SUB:
				SubtractVyToVx (instruction);
				break;
			case Opcodes.SHR:
				ShiftVxRightByOne (instruction);
				break;
			case Opcodes.SUBN:
				SetVxToVyMinusVx (instruction);
				break;
			case Opcodes.SHL:
				ShiftVxLeftByOne (instruction);
				break;
			case Opcodes.SNER:
				SkipNextRegisterVxNotEqualVy (instruction);
				break;
			case Opcodes.SETI:
				SetIToAddressNnn (instruction);
				break;
			case Opcodes.JPR:
				JumpToPlusV0 (instruction);
				break;
			case Opcodes.RND:
				SetVxRandomNumberAndNn (instruction);
				break;
			case Opcodes.DRW:
				DrawSprite (instruction);
				break;
			case Opcodes.SKP:
				SkipIfKeyInVxPressed (instruction);
				break;
			case Opcodes.SKPN:
				SkipIfKeyInVxNotPressed (instruction);
				break;
			case Opcodes.DT:
				SetVxToDelayTimer (instruction);
				break;
			case Opcodes.KEY:
				StoreWaitingKeyInVx (instruction);
				break;
			case Opcodes.DTR:
				SetDelayTimerToVx (instruction);
				break;
			case Opcodes.ST:
				SetSoundTimerToVx (instruction);
				break;
			case Opcodes.ADDI:
				AddVxToI (instruction);
				break;
			case Opcodes.LDI:
				SetIToCharacterVx (instruction);
				break;
			case Opcodes.LDB:
				StoreInVxDecimalRegisterI (instruction);
				break;
			case Opcodes.STR:
				StoreV0ToVx (instruction);
				break;
			case Opcodes.FILL:
				FillV0ToVxFromMemory (instruction);
				break;
			}
        }
Exemplo n.º 28
0
 private void JumpTo(Instruction instruction)
 {
     this.ProgramCounter = instruction.Nnn;
 }