protected int SubqWord(int opcode) { int s = (opcode >> 9 & 0x07); if (s == 0) { s = 8; } int mode = (opcode >> 3) & 0x07; if (mode != 1) { IOperand dst = cpu.ResolveDstEA(mode, (opcode & 0x07), Size.Word); int d = dst.GetWordSigned(); int r = d - s; dst.SetWord(r); cpu.CalcFlags(InstructionType.SUB, s, d, r, Size.Word); return(dst.IsRegisterMode() ? 4 : 8 + dst.GetTiming()); } else { int reg = opcode & 0x07; cpu.SetAddrRegisterLong(reg, cpu.GetAddrRegisterLong(reg) - s); return(4); } }
protected int Tas(int opcode) { lock (lockObject) { int mode = (opcode >> 3) & 0x07; int reg = (opcode & 0x07); IOperand op = cpu.ResolveSrcEA(mode, reg, Size.Byte); int v = op.GetByte(); if (v == 0) { cpu.SetFlags(cpu.ZFlag); } else { cpu.ClrFlags(cpu.ZFlag); } if ((v & 0x080) != 0) { cpu.SetFlags(cpu.NFlag); } else { cpu.ClrFlags(cpu.NFlag); } cpu.ClrFlags(cpu.CFlag | cpu.VFlag); if (!EmulateBrokenTAS) { op.SetByte(v | 0x80); } return(op.IsRegisterMode() ? 4 : 14 + op.GetTiming()); } }
protected int EoriWord(int opcode) { int s = cpu.FetchPCWord(); IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Word); int d = dst.GetWord(); int r = s ^ d; if (dst.IsSR()) { if (cpu.IsSupervisorMode()) { cpu.SetSR(r); } else { cpu.RaiseSRException(); return(34); } } else { dst.SetWord(r); cpu.CalcFlags(InstructionType.EOR, s, d, r, Size.Word); } return(dst.IsRegisterMode() ? 8 : 12 + dst.GetTiming()); }
protected int DoMoveFromSr(int opcode) { IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Word); dst.GetWord(); dst.SetWord(cpu.GetSR()); return(dst.IsRegisterMode() ? 6 : 8 + dst.GetTiming()); }
protected int NegByte(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Byte); int s = op.GetByte(); int r = 0 - s; op.SetByte(r); cpu.CalcFlags(InstructionType.NEG, s, 0, r, Size.Byte); return(op.IsRegisterMode() ? 4 : 8 + op.GetTiming()); }
protected int NotWord(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int s = op.GetWord(); int r = (~s) & 0xffff; op.SetWord(r); cpu.CalcFlags(InstructionType.NOT, s, 0, r, Size.Word); return(op.IsRegisterMode() ? 4 : 8 + op.GetTiming()); }
protected int Sxx(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Byte); int cc = (opcode >> 8) & 0x0f; int time; if (cpu.TestCC(cc)) { op.SetByte(0xff); time = (op.IsRegisterMode() ? 6 : 8 + op.GetTiming()); } else { op.SetByte(0); time = (op.IsRegisterMode() ? 4 : 8 + op.GetTiming()); } return(time); }
protected int NotLong(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.SizeLong); int s = op.GetLong(); int r = ~s; op.SetLong(r); cpu.CalcFlags(InstructionType.NOT, s, 0, r, Size.SizeLong); return(op.IsRegisterMode() ? 6 : 12 + op.GetTiming()); }
protected int CmpiWord(int opcode) { int s = cpu.FetchPCWordSigned(); IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int d = op.GetWordSigned(); int r = d - s; cpu.CalcFlags(InstructionType.CMP, s, d, r, Size.Word); return(op.IsRegisterMode() ? 8 : 8 + op.GetTiming()); }
protected int NegxWord(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int s = op.GetWord(); int r = (0 - (s + (cpu.IsFlagSet(cpu.XFlag) ? 1 : 0))); op.SetWord(r); cpu.CalcFlags(InstructionType.NEGX, s, 0, r, Size.Word); return(op.IsRegisterMode() ? 4 : 8 + op.GetTiming()); }
protected int CmpiLong(int opcode) { int s = cpu.FetchPCLong(); IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.SizeLong); int d = op.GetLong(); int r = d - s; cpu.CalcFlags(InstructionType.CMP, s, d, r, Size.SizeLong); return(op.IsRegisterMode() ? 14 : 12 + op.GetTiming()); }
protected int EorWord(int opcode) { int s = cpu.GetDataRegisterWord((opcode >> 9) & 0x07); IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Word); int d = dst.GetWord(); int r = s ^ d; dst.SetWord(r); cpu.CalcFlags(InstructionType.EOR, s, d, r, Size.Word); return(dst.IsRegisterMode() ? 4 : 8 + dst.GetTiming()); }
protected int SubiByte(int opcode) { int s = CpuUtils.SignExtendByte(cpu.FetchPCWord()); IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Byte); int d = dst.GetByteSigned(); int r = d - s; dst.SetByte(r); cpu.CalcFlags(InstructionType.SUB, s, d, r, Size.Byte); return(dst.IsRegisterMode() ? 8 : 12 + dst.GetTiming()); }
protected int SubiLong(int opcode) { int s = cpu.FetchPCLong(); IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.SizeLong); int d = dst.GetLong(); int r = d - s; dst.SetLong(r); cpu.CalcFlags(InstructionType.SUB, s, d, r, Size.SizeLong); return(dst.IsRegisterMode() ? 16 : 20 + dst.GetTiming()); }
protected int AddiWord(int opcode) { int s = cpu.FetchPCWordSigned(); IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Word); int d = dst.GetWordSigned(); int r = s + d; dst.SetWord(r); cpu.CalcFlags(InstructionType.ADD, s, d, r, Size.Word); return(dst.IsRegisterMode() ? 8 : 12 + dst.GetTiming()); }
protected int ClrWord(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); op.GetWord(); op.SetWord(0); int flags = cpu.GetCCRegister(); flags &= ~(cpu.NFlag | cpu.CFlag | cpu.VFlag); flags |= cpu.ZFlag; cpu.SetCCRegister(flags); return(op.IsRegisterMode() ? 4 : 8 + op.GetTiming()); }
protected int Nbcd(int opcode) { int mode = (opcode >> 3) & 0x07; int reg = (opcode & 0x07); IOperand op = cpu.ResolveDstEA(mode, reg, Size.Byte); int s = op.GetByte(); int x = (cpu.IsFlagSet(cpu.XFlag) ? 1 : 0); int c; int lo = 10 - (s & 0x0f) - x; if (lo < 10) { c = 1; } else { lo = 0; c = 0; } int hi = 10 - ((s >> 4) & 0x0f) - c; if (hi < 10) { c = 1; } else { c = 0; hi = 0; } int result = (hi << 4) + lo; if (c != 0) { cpu.SetFlags(cpu.XFlag | cpu.CFlag); } else { cpu.ClrFlags(cpu.XFlag | cpu.CFlag); } if (result != 0) { cpu.ClrFlags(cpu.ZFlag); } op.SetByte(result); return(op.IsRegisterMode() ? 6 : 8); }
protected int EoriByte(int opcode) { int s = cpu.FetchPCWord() & 0x00ff; IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Byte); int d = dst.GetByte(); int r = s ^ d; dst.SetByte(r); if (!dst.IsSR()) { cpu.CalcFlags(InstructionType.EOR, s, d, r, Size.Byte); } return(dst.IsRegisterMode() ? 8 : 12 + dst.GetTiming()); }
protected int SubqByte(int opcode) { int s = (opcode >> 9 & 0x07); if (s == 0) { s = 8; } IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Byte); int d = dst.GetByteSigned(); int r = d - s; dst.SetByte(r); cpu.CalcFlags(InstructionType.SUB, s, d, r, Size.Byte); return(dst.IsRegisterMode() ? 4 : 8 + dst.GetTiming()); }
protected int SubqLong(int opcode) { int s = (opcode >> 9 & 0x07); if (s == 0) { s = 8; } int mode = (opcode >> 3) & 0x07; IOperand dst = cpu.ResolveDstEA(mode, (opcode & 0x07), Size.SizeLong); int d = dst.GetLong(); int r = d - s; dst.SetLong(r); if (mode != 1) { cpu.CalcFlags(InstructionType.SUB, s, d, r, Size.SizeLong); } return(dst.IsRegisterMode() ? 8 : 12 + dst.GetTiming()); }