Example #1
0
 void Se_3(ChipInstruction inst)
 {
     if (VRegisters[inst.X] == inst.KK)
     {
         IncrementPC();
     }
 }
Example #2
0
 void Sne_4(ChipInstruction inst)
 {
     if (VRegisters[inst.X] != inst.KK)
     {
         IncrementPC();
     }
 }
Example #3
0
 void Load_F65(ChipInstruction inst)
 {
     for (int i = 0; i <= inst.X; i++)
     {
         VRegisters[i] = Memory[AddressRegister + i];
     }
 }
Example #4
0
 void Sne_9(ChipInstruction inst)
 {
     if (VRegisters[inst.X] != VRegisters[inst.Y])
     {
         IncrementPC();
     }
 }
Example #5
0
 void Load_F85(ChipInstruction inst)
 {
     for (int i = 0; i <= inst.X; i++)
     {
         VRegisters[i] = RPLRegisters[i];
     }
 }
Example #6
0
 void Se_5(ChipInstruction inst)
 {
     if (VRegisters[inst.X] == VRegisters[inst.Y])
     {
         IncrementPC();
     }
 }
Example #7
0
        void Load_F33(ChipInstruction inst)
        {
            byte val = VRegisters[inst.X];

            Memory[AddressRegister]     = (byte)(val / 100);
            Memory[AddressRegister + 1] = (byte)((val % 100) / 10);
            Memory[AddressRegister + 2] = (byte)((val % 100) % 10);
        }
Example #8
0
        void Load_F07(ChipInstruction inst)
        {
            if (DelayTimer < 0)
            {
                DelayTimer = 0;
            }

            this.VRegisters[inst.X] = (byte)this.DelayTimer;
        }
Example #9
0
        protected void OnPixelSet(ChipInstruction inst)
        {
            m_VRegs[0xF] = 0;
            byte x    = m_VRegs[inst.X];
            byte y    = m_VRegs[inst.Y];
            byte read = 0;

            if (inst.N > 0)
            {
                // Loop through the sprite bytes by N
                for (byte i = 0; i < inst.N; i++)
                {
                    // Get the next byte of the sprite data
                    read = Memory.ReadByte((int)(m_IReg + i));

                    // Sprite is always 8 in width, loop through each bit
                    for (byte j = 0; j < 8; j++)
                    {
                        // If we hit an on bit then Set a pixel at X, Y
                        if ((read & (0x80 >> j)) != 0)
                        {
                            // If we colliude, set VF
                            if (VideoInterface.SetPixel((x + j), (y + i)))
                            {
                                m_VRegs[0xF] = 1;
                            }
                        }
                    }
                }
            }
            else
            {
                for (int k = 0; k < 0x10; k++)
                {
                    ushort data = Tools.Create16(Memory.ReadByte((int)(m_IReg + (k << 1))),
                                                 Memory.ReadByte((int)(m_IReg + (k << 1) + 1)));

                    for (int m = 0; m < 0x10; m++)
                    {
                        if ((data & (((int)0x8000) >> m)) != 0)
                        {
                            if (VideoInterface.SetPixel((x + m), (y + k)))
                            {
                                m_VRegs[0xF] = 1;
                            }
                        }
                    }
                }
            }

            if (m_VRegs[0xF] == 1 && m_AntiFlickerHack)
            {
                return;
            }

            VideoInterface.RenderWait();
        }
Example #10
0
        public void Step(int cycles)
        {
            while (cycles > 0)
            {
                cycles--;
                byte       a      = SystemMemory.ReadByte(m_CodeEngine.PC);
                byte       b      = SystemMemory.ReadByte(m_CodeEngine.PC + 1);
                ushort     data   = Tools.Create16(a, b);
                ChipOpCode opcode = Disassembler.DecodeInstruction(data);
                //Console.WriteLine("Instuction: " + opcode.ToString());
                //Console.WriteLine(m_CodeEngine.PC.ToString("X2") + " " + opcode.ToString());
                ChipInstruction inst = new ChipInstruction(data, opcode);
                inst.Address = m_CodeEngine.PC;
                m_CodeEngine.IncrementPC();

                if (m_PatchEngine.PatchAddress(m_CodeEngine, (ushort)(m_CodeEngine.PC - 2)))
                {
                    continue;
                }

                if (opcode == ChipOpCode.Unknown)
                {
                    if (data != 0)
                    {
                        //Console.WriteLine(m_CodeEngine.PC.ToString("X2"));
                        Console.WriteLine("Syscall: " + inst.NNN.ToString("x"));

                        if (m_UseHybridDynarec)
                        {
                            if (inst.NNN < SystemMemory.Size)
                            {
                                m_HybridDynarec.Execute(inst.NNN, m_CodeEngine);
                            }
                            else
                            {
                                Console.WriteLine("1802 Call is beyond memory bounds! (" + inst.NNN.ToString("X4") + ")");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Syscall Emitter Disabled!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Warning: 0 opcode doing Nop!");
                    }
                }
                else
                {
                    m_CodeEngine.Call(inst);
                }
            }
        }
Example #11
0
 void Ret(ChipInstruction inst)
 {
     if (Stack.Count > 0)
     {
         PC = Stack.Pop();
     }
     else
     {
         PC = 512;
     }
 }
Example #12
0
 void Sknp(ChipInstruction inst)
 {
     if (VRegisters[inst.X] != PressedKey)
     {
         IncrementPC();
     }
     else
     {
         //Console.WriteLine("Checked for unpressed key: " + VRegisters[inst.X].ToString());
     }
 }
Example #13
0
 void Add_F(ChipInstruction inst)
 {
     if (((int)AddressRegister + (int)VRegisters[inst.X]) >= 0x1000)
     {
         AddressRegister = (ushort)Memory.Size;
         VRegisters[0xF] = 1;
     }
     else
     {
         AddressRegister += VRegisters[inst.X];
     }
 }
Example #14
0
        public override void Call(ChipInstruction inst)
        {
            OpcodeHandler handler;

            if (m_MethodCallTable != null)
            {
                if (this.m_MethodCallTable.TryGetValue(inst.OpCode, out handler))
                {
                    handler.Invoke(inst);
                }
            }
        }
Example #15
0
        void Subn(ChipInstruction inst)
        {
            if (VRegisters[inst.Y] >= VRegisters[inst.X])
            {
                VRegisters[0xF] = 1;
            }
            else
            {
                VRegisters[0xF] = 0;
            }

            VRegisters[inst.X] = (byte)(VRegisters[inst.Y] - VRegisters[inst.X]);
        }
Example #16
0
        void Sub(ChipInstruction inst)
        {
            if (VRegisters[inst.X] > VRegisters[inst.Y])
            {
                VRegisters[0xF] = 1;
            }
            else
            {
                VRegisters[0xF] = 0;
            }

            VRegisters[inst.X] -= VRegisters[inst.Y];
        }
Example #17
0
        void Shl(ChipInstruction inst)
        {
            if (((VRegisters[inst.X] & 0x80) >> 7) == 1)
            {
                VRegisters[0xF] = 1;
            }
            else
            {
                VRegisters[0xF] = 0;
            }

            VRegisters[inst.X] *= 2;
        }
Example #18
0
        void Shr(ChipInstruction inst)
        {
            if ((VRegisters[inst.X] & 1) == 1)
            {
                VRegisters[0xF] = 1;
            }
            else
            {
                VRegisters[0xF] = 0;
            }

            VRegisters[inst.X] /= 2;
        }
Example #19
0
        void Add_8(ChipInstruction inst)
        {
            int result = VRegisters[inst.X] + VRegisters[inst.Y];

            if (result > (int)byte.MaxValue)
            {
                VRegisters[0xF] = 1;
            }
            else
            {
                VRegisters[0xF] = 0;
            }

            VRegisters[inst.X] = (byte)result;
        }
Example #20
0
 void Load_F0A(ChipInstruction inst)
 {
     OnWaitForKey();
     VRegisters[inst.X] = PressedKey;
 }
Example #21
0
 private void ScrollDown(ChipInstruction inst)
 {
     OnPixelScroll(2, inst.N);
 }
Example #22
0
 private void Drw(ChipInstruction inst)
 {
     OnPixelSet(inst);
 }
Example #23
0
 private void Clr(ChipInstruction inst)
 {
     OnScreenClear();
 }
Example #24
0
 void Load_F30(ChipInstruction inst)
 {
     AddressRegister = (ushort)(80 + (VRegisters[inst.X] * 10));
 }
Example #25
0
 void Exit(ChipInstruction inst)
 {
     return;
 }
Example #26
0
 void ExtOff(ChipInstruction inst)
 {
     VideoInterface.Initialize(ChipMode.Chip8);
 }
Example #27
0
 void ExtOn(ChipInstruction inst)
 {
     VideoInterface.Initialize(ChipMode.SuperChip);
 }
Example #28
0
 void Load_DT(ChipInstruction inst)
 {
     OnSetDelayTimer(VRegisters[inst.X]);
 }
Example #29
0
 void Load_F29(ChipInstruction inst)
 {
     AddressRegister = (ushort)(VRegisters[inst.X] * 5);
 }
Example #30
0
 void Load_ST(ChipInstruction inst)
 {
     OnSetSoundTimer(VRegisters[inst.X]);
 }