protected int Chk(int opcode) { int reg = (opcode >> 9) & 0x07; int dval = cpu.GetDataRegisterWordSigned(reg); IOperand op = cpu.ResolveSrcEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int sval = op.GetWord(); bool raiseException = false; if (dval < 0) { cpu.SetFlags(cpu.NFlag); raiseException = true; } else if (dval > sval) { cpu.ClrFlags(cpu.NFlag); raiseException = true; } if (raiseException) { cpu.RaiseException(6); return(40 + op.GetTiming()); } return(10 + op.GetTiming()); }
protected int Divu(int opcode) { IOperand op = cpu.ResolveSrcEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int s = op.GetWord(); int reg = (opcode >> 9) & 0x07; int d = cpu.GetDataRegisterLong(reg); int time; if (s == 0) { cpu.RaiseException(5); time = 38 + op.GetTiming(); } else { long dl = d & 4294967295L; long quot = dl / (long)s; if (quot > 65535L) { cpu.SetFlags(cpu.VFlag); cpu.SetFlags(cpu.NFlag); } else { int remain = (int)((dl % s) & 0xffff); int result = (int)(quot & 0x0000ffff) | (remain << 16); cpu.SetDataRegisterLong(reg, result); if ((quot & 0x8000) != 0) { cpu.SetFlags(cpu.NFlag); } else { cpu.ClrFlags(cpu.NFlag); } if (quot == 0) { cpu.SetFlags(cpu.ZFlag); } else { cpu.ClrFlags(cpu.ZFlag); } cpu.ClrFlags((cpu.VFlag | cpu.CFlag)); } time = 140 + op.GetTiming(); } return(time); }
protected int Divs(int opcode) { IOperand op = cpu.ResolveSrcEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int s = op.GetWordSigned(); int reg = (opcode >> 9) & 0x07; int d = cpu.GetDataRegisterLong(reg); int time; if (s == 0) { cpu.RaiseException(5); time = 38 + op.GetTiming(); } else { int quot = d / s; if (quot > 32767 || quot < -32768) { cpu.SetFlags(cpu.VFlag); } else { int remain = (d % s) & 0xffff; int result = (quot & 0x0000ffff) | (remain << 16); cpu.SetDataRegisterLong(reg, result); if ((quot & 0x8000) != 0) { cpu.SetFlags(cpu.NFlag); cpu.ClrFlags(cpu.ZFlag); } else { cpu.ClrFlags(cpu.NFlag); if (quot == 0) { cpu.SetFlags(cpu.ZFlag); } else { cpu.ClrFlags(cpu.ZFlag); } } cpu.ClrFlags((cpu.VFlag | cpu.CFlag)); } time = 158 + op.GetTiming(); } return(time); }
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 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 RoxlWordMem(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int v = op.GetWord(); int last_out = v & 0x8000; v <<= 1; if (cpu.IsFlagSet(cpu.XFlag)) { v |= 0x01; } op.SetWord(v); int maskFlags; if (last_out != 0) { maskFlags = cpu.XFlag + cpu.CFlag; } else { maskFlags = 0; } if ((v & 0xffff) == 0) { maskFlags += cpu.ZFlag; } if ((v & 0x8000) != 0) { maskFlags += cpu.NFlag; } cpu.SetCCRegister(maskFlags); return(8 + op.GetTiming()); }
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 TstLong(int opcode) { int mode = (opcode >> 3) & 0x07; int reg = (opcode & 0x07); IOperand op = cpu.ResolveSrcEA(mode, reg, Size.SizeLong); int v = op.GetLong(); if (v == 0) { cpu.SetFlags(cpu.ZFlag); } else { cpu.ClrFlags(cpu.ZFlag); } if ((v & 0x80000000) != 0) { cpu.SetFlags(cpu.NFlag); } else { cpu.ClrFlags(cpu.NFlag); } cpu.ClrFlags(cpu.CFlag | cpu.VFlag); return(4 + op.GetTiming()); }
protected int DoMoveToCcr(int opcode) { IOperand src = cpu.ResolveSrcEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Word); int s = src.GetWord() & 31; cpu.SetCCRegister(s); return(12 + src.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 AddaWord(int opcode) { IOperand src = cpu.ResolveSrcEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int s = src.GetWordSigned(); int reg = (opcode >> 9) & 0x07; cpu.SetAddrRegisterLong(reg, cpu.GetAddrRegisterLong(reg) + s); return(8 + src.GetTiming()); }
protected int AddaLong(int opcode) { IOperand src = cpu.ResolveSrcEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.SizeLong); int s = src.GetLong(); int reg = (opcode >> 9) & 0x07; cpu.SetAddrRegisterLong(reg, cpu.GetAddrRegisterLong(reg) + s); return(6 + src.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 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 CmpaWord(int opcode) { IOperand op = cpu.ResolveSrcEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int d = cpu.GetAddrRegisterLong((opcode >> 9) & 0x07); int s = op.GetWordSigned(); int r = d - s; cpu.CalcFlags(InstructionType.CMP, s, d, r, Size.SizeLong); return(6 + 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 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 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 CmpWord(int opcode) { IOperand op = cpu.ResolveSrcEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int s = op.GetWord(); int d = cpu.GetDataRegisterWord((opcode >> 9) & 0x07); int r = d - s; cpu.CalcFlags(InstructionType.CMP, s, d, r, Size.Word); return(4 + 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 LslWordMem(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int v = op.GetWord(); int last_out = v & 0x8000; v <<= 1; op.SetWord(v); cpu.CalcFlags(InstructionType.LSL, 1, last_out, v, Size.Word); return(8 + 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 SubWordEaDest(int opcode) { int s = cpu.GetDataRegisterWordSigned((opcode >> 9) & 0x07); IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Word); int d = dst.GetWordSigned(); int r = d - s; dst.SetWord(r); int time = 8 + dst.GetTiming(); cpu.CalcFlags(InstructionType.SUB, s, d, r, Size.Word); return(time); }
protected int SubLongEaDest(int opcode) { int s = cpu.GetDataRegisterLong((opcode >> 9) & 0x07); IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.SizeLong); int d = dst.GetLong(); int r = d - s; dst.SetLong(r); int time = 12 + dst.GetTiming(); cpu.CalcFlags(InstructionType.SUB, s, d, r, Size.SizeLong); return(time); }
protected int AddByteEaDest(int opcode) { int s = cpu.GetDataRegisterByteSigned((opcode >> 9) & 0x07); IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Byte); int d = dst.GetByteSigned(); int r = s + d; dst.SetByte(r); int time = 8 + dst.GetTiming(); cpu.CalcFlags(InstructionType.ADD, s, d, r, Size.Byte); return(time); }
protected int AsrWordMem(int opcode) { IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Word); int v = op.GetWord(); int last_out = v & 0x01; int msb = v & 0x8000; v = (int)((uint)v >> 1); v |= msb; op.SetWord(v); cpu.CalcFlags(InstructionType.ASR, 1, last_out, v, Size.Word); return(8 + op.GetTiming()); }