Esempio n. 1
0
      };// TODO handle that in Instruc...

    public static Action ret(CPU cpu, FlagCondition o) =>
      () => {
        if (o.Target) {
          cpu.Return();
          cpu.pc -= 1;
        }
      };
 public static Action add(CPU cpu, Register16 o1, Register16 o2) =>
   () => {
     ushort hl = o1.Target;
     o1.Target += o2.Target;
     cpu.HalfCarry = (hl & 0xFFF) + (o2.Target & 0xFFF) > 0xFFF;
     cpu.AddSub = false;
     cpu.Carry = hl + o2.Target > 0xFFFF;
   };
 public static Action inc(CPU cpu, Operand<byte> o) =>
   () => {
     ++o.Target;
     cpu.Sign = o.Target > 0x7F;
     cpu.Zero = o.Target == 0;
     cpu.HalfCarry = (o.Target & 0x0F) == 0;
     cpu.Overflow = o.Target == 0x80;
     cpu.AddSub = false;
   };
 public static Action dec(CPU cpu, Operand<byte> o) =>
   () => {
     --o.Target;
     cpu.Sign = o.Target > 0x7F;
     cpu.Zero = o.Target == 0;
     cpu.HalfCarry = (o.Target & 0x0F) == 0x0F;
     cpu.Overflow = o.Target == 0x7F;
     cpu.AddSub = true;
   };
Esempio n. 5
0
 public static Action rla(CPU cpu) =>
   () => {
     bool bit7 = Utils.Bit(cpu.registers.a, 7);
     cpu.registers.a <<= 1;
     cpu.registers.a = Utils.Bit(cpu.registers.a, 0, cpu.Carry);
     cpu.HalfCarry = false;
     cpu.AddSub = false;
     cpu.Carry = bit7;
   };
Esempio n. 6
0
 public static Action rra(CPU cpu) =>
   () => {
     bool bit0 = Utils.Bit(cpu.registers.a, 0);
     cpu.registers.a >>= 1;
     cpu.registers.a = Utils.Bit(cpu.registers.a, 7, cpu.Carry);
     cpu.HalfCarry = false;
     cpu.AddSub = false;
     cpu.Carry = bit0;
   };
 public static Action adc(CPU cpu, Register8 o1, Operand<byte> o2) =>
   () => {
     cpu.registers.a += (byte)(o2.Target + Convert.ToByte(cpu.Carry));
     cpu.Sign = cpu.registers.a > 0x7F;
     cpu.Zero = cpu.registers.a == 0;
     cpu.HalfCarry = true; // TODO
     cpu.Overflow = true; // TODO
     cpu.AddSub = false;
     cpu.Carry = false; // TODO
   };
 public static Action sub(CPU cpu, Operand<byte> o2) =>
   () => {
     cpu.registers.a -= o2.Target;
     cpu.Sign = cpu.registers.a > 0x7F;
     cpu.Zero = cpu.registers.a == 0;
     cpu.HalfCarry = true; // TODO
     cpu.Overflow = true; // TODO
     cpu.AddSub = true;
     cpu.Carry = false; // TODO
   };
 public static Action adc(CPU cpu, Register16 o1, Register16 o2) =>
   () => {
     cpu.registers.hl += (ushort)(o2.Target + Convert.ToByte(cpu.Carry));
     cpu.Sign = cpu.registers.a > 0x7F;
     cpu.Zero = cpu.registers.a == 0;
     cpu.HalfCarry = true; // TODO
     cpu.Overflow = true; // TODO
     cpu.AddSub = false;
     cpu.Carry = false; // TODO
   };
 public static Action add(CPU cpu, Register8 o1, Operand<byte> o2) =>
   () => {
     byte a = o1.Target;
     o1.Target += o2.Target;
     cpu.Sign = o1.Target > 0x7F;
     cpu.Zero = o1.Target == 0;
     cpu.HalfCarry = (a & 0x0F) + (o2.Target & 0x0F) > 0x0F;
     cpu.Overflow = Utils.Sign(a) == Utils.Sign(o2.Target) &&
                    Utils.Sign(a) != Utils.Sign(o1.Target);
     cpu.AddSub = false; 
     cpu.Carry = a + o2.Target > 0xFF;
   };
Esempio n. 11
0
    public Instruction(CPU cpu, byte opcode, string mnemonics, string description, byte size, byte cycles, Action implementation) {

      info = new Info {
        opcode = opcode,
        mnemonics = mnemonics,
        description  = description,
        size = size,
        cycles = cycles
      };

      this.implementation = implementation;
      this.cpu = cpu;
    }
Esempio n. 12
0
 public static Action pop(CPU cpu, Register16 o) =>
   () => o.Target = cpu.Pop();
Esempio n. 13
0
 public static Action res(CPU cpu, Fixed bit, Operand<byte> value) =>
   () => value.Target = Utils.SetBit(value.Target, bit.Target);
Esempio n. 14
0
 public static Action rst(CPU cpu, Fixed o) =>
   () => cpu.Call(o.Target, 1);
Esempio n. 15
0
 public static Action push(CPU cpu, Register16 o) =>
   () => cpu.Push(o.Target);
Esempio n. 16
0
 public static Action ret(CPU cpu) =>
   () => {
     cpu.Return();
     cpu.pc -= 1;
   };// TODO handle that in Instruc...
 public static Action inc(CPU cpu, Register16 o) =>
   () => ++o.Target;
Esempio n. 18
0
 public static Action call(CPU cpu, Immediate<ushort> o) =>
   () => cpu.Call(o.Target, 3);
 public static Action sbc(CPU cpu, Register16 o1, Operand<ushort> o) =>
   () => {
     cpu.registers.hl -= o.Target;
     cpu.Sign = cpu.registers.hl > 0x7F;
     cpu.Zero = cpu.registers.hl == 0;
     cpu.HalfCarry = true; // TODO
     cpu.Overflow = true; // TODO
     cpu.AddSub = true;
     cpu.Carry = false; // TODO
   };
Esempio n. 20
0
 public static Action jp(CPU cpu, Operand<ushort> o) =>
   () => cpu.pc = (ushort) (o.Target - 3); // TODO handle adjustment in Instr
Esempio n. 21
0
      () => cpu.pc = (ushort) (o.Target - 3); // TODO handle adjustment in Instr

    public static Action jp(CPU cpu, FlagCondition o1, Operand<ushort> o2) =>
      () => {
        if (o1.Target)
          cpu.pc = (ushort) (o2.Target - 3);
      };
 public static Action xor(CPU cpu, Operand<byte> o) =>
   () => {
     cpu.registers.a ^= o.Target;
     cpu.Sign = cpu.registers.a > 0x7F;
     cpu.Zero = cpu.registers.a == 0;
     cpu.HalfCarry = false;
     cpu.Overflow = Utils.Parity(cpu.registers.a);
     cpu.AddSub = false;
     cpu.Carry = false;
   };
Esempio n. 23
0
 public static Action bit(CPU cpu, Fixed bit, Operand<byte> value) =>
   () => {
     cpu.Zero = Utils.Bit(value.Target, bit.Target);
     cpu.HalfCarry = true;
     cpu.AddSub = false;
   };
Esempio n. 24
0
 public static Action jr(CPU cpu, Operand<byte> o) =>
   () => cpu.pc += (ushort) Utils.Signed(o.Target);
 public static Action cpl(CPU cpu) =>
   () => {
     cpu.registers.a = (byte) ~cpu.registers.a;
     cpu.HalfCarry = true;
     cpu.AddSub = true;
   };
Esempio n. 26
0
 public static Action call(CPU cpu, FlagCondition o1, Immediate<ushort> o2) =>
   () => {
     if (o1.Target)
       cpu.Call(o2.Target, 3);
   };
Esempio n. 27
0
 public static Action jr(CPU cpu, FlagCondition o1, Operand<byte> o2) =>
   () => {
     if (o1.Target)
       cpu.pc = (ushort) (cpu.pc + Utils.Signed(o2.Target));
   };
 public static Action dec(CPU cpu, Register16 o) =>
   () => --o.Target;
Esempio n. 29
0
 public MasterSystem() {
   memory = new Memory();
   cpu = new CPU(memory);
 }
Esempio n. 30
0
 public static Action djnz(CPU cpu, Immediate8 o) =>
   () => {
     if (--cpu.registers.b == 0)
       cpu.pc += o.Target;
   };