예제 #1
0
        public static int LdD16(Opcode op, GbMemory mem)
        {
            byte low = mem.ReadCycleI8();

            mem.R.SetR16(op.Dest, new GbUInt16(mem.ReadCycleI8(), low));
            return(3);
        }
예제 #2
0
        public static int LdA16Sp(Opcode op, GbMemory mem)
        {
            byte low  = mem.ReadCycleI8();
            byte high = mem.ReadCycleI8();

            mem.WriteCycle(new GbUInt16(high, low), mem.R.Sp.LowByte);
            mem.WriteCycle((GbUInt16)(new GbUInt16(high, low) + 1), mem.R.Sp.HighByte);
            return(5);
        }
예제 #3
0
        public static int LdH(Opcode op, GbMemory mem)
        {
            if (op.Dest == 7)
            {
                mem.R.A = mem.ReadCycle(new GbUInt16(0xFF, mem.ReadCycleI8()));
            }
            else
            {
                mem.WriteCycle(new GbUInt16(0xFF, mem.ReadCycleI8()), mem.R.A);
            }

            return(3);
        }
예제 #4
0
파일: Branching.cs 프로젝트: izik1/JAGBE
        public static int Call(Opcode op, GbMemory mem)
        {
            byte low  = mem.ReadCycleI8();
            byte high = mem.ReadCycleI8();

            if (op.Src != 0 && GetConditionalJumpState(op.Dest, op.Src, mem.R.F))
            {
                return(3);
            }

            mem.Update();
            mem.Call(new GbUInt16(high, low));
            return(6);
        }
예제 #5
0
        public static int LdA16(Opcode op, GbMemory mem)
        {
            byte low  = mem.ReadCycleI8();
            byte high = mem.ReadCycleI8();

            if (op.Dest == 7)
            {
                mem.R.A = mem.ReadCycle(new GbUInt16(high, low));
            }
            else
            {
                mem.WriteCycle(new GbUInt16(high, low), mem.R.A);
            }

            return(4);
        }
예제 #6
0
        public static int LdHlSpR8(Opcode op, GbMemory mem)
        {
            sbyte s = (sbyte)mem.ReadCycleI8();

            mem.Update();
            mem.R.F = (((mem.R.Sp & 0xFF) +
                        (s & 0xFF)) > 0xFF ? RFlags.CB : (byte)0).AssignBit(RFlags.HF, ((mem.R.Sp & 0x0F) + (s & 0x0F)) > 0x0F);
            mem.R.Hl = mem.R.Sp + s;
            return(3);
        }
예제 #7
0
        /// <summary>
        /// Adds a 8 bit signed value to the Stack Pointer.
        /// </summary>
        /// <param name="op">The op.</param>
        /// <param name="memory">The memory.</param>
        /// <returns>The number of ticks the operation took to complete.</returns>
        /// <remarks>Affected Flags: - - H C</remarks>
        public static int AddSpR8(Opcode op, GbMemory memory)
        {
            sbyte v = (sbyte)memory.ReadCycleI8();

            memory.Update();
            memory.Update();
            memory.R.F = (((memory.R.Sp & 0x0F) + (v & 0x0F)) > 0x0F ? RFlags.HB : byte.MinValue)
                         .AssignBit(RFlags.CF, ((memory.R.Sp & 0xFF) + (v & 0xFF)) > 0xFF);
            memory.R.Sp += v;
            return(4);
        }
예제 #8
0
파일: Branching.cs 프로젝트: izik1/JAGBE
        public static int Jr8(Opcode op, GbMemory mem)
        {
            byte val = mem.ReadCycleI8();

            if (op.Src != 0 && GetConditionalJumpState(op.Dest, op.Src, mem.R.F))
            {
                return(2);
            }

            mem.Update();
            mem.R.Pc += (sbyte)val;
            return(3);
        }
예제 #9
0
        public static int LdD8(Opcode op, GbMemory mem)
        {
            byte val = mem.ReadCycleI8();

            if (op.Dest == 6)
            {
                mem.WriteCycle(mem.R.Hl, val);
                return(3);
            }

            mem.R.SetR8(op.Dest, val);
            return(2);
        }
예제 #10
0
        /// <summary>
        /// A framework for calling arithmetic operation instructions.
        /// </summary>
        /// <param name="op">The op.</param>
        /// <param name="memory">The memory.</param>
        /// <param name="operation">The operation.</param>
        /// <exception cref="ArgumentNullException"><paramref name="operation"/> is null</exception>
        internal static int ArithOp8Func(Opcode op, GbMemory memory, ArithOp8 operation)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            if (op.Src != 6 && op.Src != 8)
            {
                operation(memory, memory.R.GetR8(op.Src));
                return(1);
            }

            operation(memory, op.Src == 6 ? memory.ReadCycleHl() : memory.ReadCycleI8());
            return(2);
        }