예제 #1
0
      };// TODO handle that in Instruc...

    public static Action ret(CPU cpu, FlagCondition o) =>
      () => {
        if (o.Target) {
          cpu.Return();
          cpu.pc -= 1;
        }
      };
예제 #2
0
 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;
   };
예제 #3
0
 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;
   };
예제 #4
0
 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;
   };
예제 #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;
   };
예제 #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;
   };
예제 #7
0
 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
   };
예제 #8
0
 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
   };
예제 #9
0
 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
   };
예제 #10
0
 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;
   };
예제 #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;
    }
예제 #12
0
 public static Action pop(CPU cpu, Register16 o) =>
   () => o.Target = cpu.Pop();
예제 #13
0
 public static Action res(CPU cpu, Fixed bit, Operand<byte> value) =>
   () => value.Target = Utils.SetBit(value.Target, bit.Target);
예제 #14
0
 public static Action rst(CPU cpu, Fixed o) =>
   () => cpu.Call(o.Target, 1);
예제 #15
0
 public static Action push(CPU cpu, Register16 o) =>
   () => cpu.Push(o.Target);
예제 #16
0
 public static Action ret(CPU cpu) =>
   () => {
     cpu.Return();
     cpu.pc -= 1;
   };// TODO handle that in Instruc...
예제 #17
0
 public static Action inc(CPU cpu, Register16 o) =>
   () => ++o.Target;
예제 #18
0
 public static Action call(CPU cpu, Immediate<ushort> o) =>
   () => cpu.Call(o.Target, 3);
예제 #19
0
 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
   };
예제 #20
0
 public static Action jp(CPU cpu, Operand<ushort> o) =>
   () => cpu.pc = (ushort) (o.Target - 3); // TODO handle adjustment in Instr
예제 #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);
      };
예제 #22
0
 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;
   };
예제 #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;
   };
예제 #24
0
 public static Action jr(CPU cpu, Operand<byte> o) =>
   () => cpu.pc += (ushort) Utils.Signed(o.Target);
예제 #25
0
 public static Action cpl(CPU cpu) =>
   () => {
     cpu.registers.a = (byte) ~cpu.registers.a;
     cpu.HalfCarry = true;
     cpu.AddSub = true;
   };
예제 #26
0
 public static Action call(CPU cpu, FlagCondition o1, Immediate<ushort> o2) =>
   () => {
     if (o1.Target)
       cpu.Call(o2.Target, 3);
   };
예제 #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));
   };
예제 #28
0
 public static Action dec(CPU cpu, Register16 o) =>
   () => --o.Target;
예제 #29
0
 public MasterSystem() {
   memory = new Memory();
   cpu = new CPU(memory);
 }
예제 #30
0
 public static Action djnz(CPU cpu, Immediate8 o) =>
   () => {
     if (--cpu.registers.b == 0)
       cpu.pc += o.Target;
   };