public static R8 ToR8(TX a)
        {
            R8 res = default(R8);

            Conversions.DefaultInstance.Convert(in a, ref res);
            return(res);
        }
 public static R8 ToR8(R8 a)
 {
     // Note that the cast is intentional and NOT a no-op. It forces the JIT
     // to narrow to R4 when it might be tempted to keep intermediate
     // computations in larger precision.
     return(a);
 }
 public static R8 Atan2(R8 a, R8 b)
 {
     // According to the documentation of Math.Atan2: if x and y are either System.Double.PositiveInfinity
     // or System.Double.NegativeInfinity, the method returns System.Double.NaN, but this seems to not be the case.
     if (R8.IsInfinity(a) && R8.IsInfinity(b))
     {
         return(R8.NaN);
     }
     return(Math.Atan2(a, b));
 }
示例#4
0
 private void Show(R8 x)
 {
     if (R8.IsNaN(x))
     {
         _wrt.Write("NA");
     }
     else
     {
         _wrt.Write("{0:R}", x);
     }
 }
示例#5
0
 public static Service ToContract(this R8 dataBaseService)
 {
     if (dataBaseService == null)
     {
         return(null);
     }
     return(new Service
     {
         Id = dataBaseService.RNo,
         Description = dataBaseService.Nm
     });
 }
        /// <summary>
        /// Returns whether the given object is non-null and an NA value for one of the standard types.
        /// </summary>
        public static bool IsNA(object v)
        {
            if (v == null)
            {
                return(false);
            }
            Type type = v.GetType();

            if (type == typeof(R4))
            {
                return(R4.IsNaN((R4)v));
            }
            if (type == typeof(R8))
            {
                return(R8.IsNaN((R8)v));
            }
            Contracts.Assert(type == typeof(BL) || type == typeof(I4) || type == typeof(I8) || type == typeof(TX),
                             "Unexpected constant value type!");
            return(false);
        }
示例#7
0
        internal void setReg8(R8 t, byte i)
        {
            switch (t)
            {
            case R8.A: this._r.a = i; break;

            case R8.B: this._r.b = i; break;

            case R8.C: this._r.c = i; break;

            case R8.D: this._r.d = i; break;

            case R8.E: this._r.e = i; break;

            case R8.H: this._r.h = i; break;

            case R8.L: this._r.l = i; break;

            case R8.iHL: this.WriteMem8(this._r.hl, i); break;

            default: throw new ArgumentException();
            }
        }
示例#8
0
        internal byte getReg8(R8 t)
        {
            switch (t)
            {
            case R8.A: return(this._r.a);

            case R8.B: return(this._r.b);

            case R8.C: return(this._r.c);

            case R8.D: return(this._r.d);

            case R8.E: return(this._r.e);

            case R8.H: return(this._r.h);

            case R8.L: return(this._r.l);

            case R8.iHL: return(this.FetchMem8(this._r.hl));

            default: throw new ArgumentException();
            }
        }
 public static R8 SinD(R8 a)
 {
     return(MathUtils.Sin(a * (Math.PI / 180)));
 }
 public static R8 Sin(R8 a)
 {
     return(MathUtils.Sin(a));
 }
 public static R8 Rad(R8 a)
 {
     return(a * (Math.PI / 180));
 }
 public static R8 Deg(R8 a)
 {
     return(a * (180 / Math.PI));
 }
示例#13
0
 public Rm8(R8 register, bool isPointer = false)
 {
     Register  = register;
     IsPointer = isPointer;
 }
 public static BL IsNA(R8 a)
 {
     return(R8.IsNaN(a));
 }
 public static R8 TanD(R8 a)
 {
     return(Math.Tan(a * (Math.PI / 180)));
 }
示例#16
0
 public Options(R8 r8, R8 r8_2)
 {
     this.r8   = r8;
     this.r8_2 = r8_2;
 }
 public static TX ToTX(R8 src) => src.ToString("G17", CultureInfo.InvariantCulture).AsMemory();
示例#18
0
 public Options(R8 r8, ushort numtype)
 {
     this.r8      = r8;
     this.numtype = numtype;
 }
示例#19
0
        Instruction rgOpcode(byte id)
        {
            Executor e           = Ops.LD_HL_SPaddE8;
            int      upperNybble = id >> 4;

            int lowerNybble = id & 0b1111;

            switch (id)
            {
            /** JR */
            case 0x18:     // JR E8
                return(new Instruction(Ops.JR_E8, 2, new Options(CC.NONE)));

            case 0x38:     // JR C, E8
                return(new Instruction(Ops.JR_E8, 2, new Options(CC.C)));

            case 0x30:     // JR NC, E8
                return(new Instruction(Ops.JR_E8, 2, new Options(CC.NC)));

            case 0x28:     // JR Z, E8
                return(new Instruction(Ops.JR_E8, 2, new Options(CC.Z)));

            case 0x20:     // JR NZ, E8
                return(new Instruction(Ops.JR_E8, 2, new Options(CC.NZ)));


            /** LD R8, N8 */
            case 0x3E:     // LD A, N8
                return(new Instruction(Ops.LD_R8_N8, 2, new Options(R8.A)));

            case 0x06:     // LD B, N8
                return(new Instruction(Ops.LD_R8_N8, 2, new Options(R8.B)));

            case 0x0E:     // LD C, N8
                return(new Instruction(Ops.LD_R8_N8, 2, new Options(R8.C)));

            case 0x16:     // LD D, N8
                return(new Instruction(Ops.LD_R8_N8, 2, new Options(R8.D)));

            case 0x1E:     // LD E, n8
                return(new Instruction(Ops.LD_R8_N8, 2, new Options(R8.E)));

            case 0x26:     // LD H, N8
                return(new Instruction(Ops.LD_R8_N8, 2, new Options(R8.H)));

            case 0x2E:     // LD L, N8
                return(new Instruction(Ops.LD_R8_N8, 2, new Options(R8.L)));

            /** PUSH R16 */
            case 0xF5:     // PUSH AF
                return(new Instruction(Ops.PUSH_R16, 1, new Options(R16.AF)));

            case 0xC5:     // PUSH BC
                return(new Instruction(Ops.PUSH_R16, 1, new Options(R16.BC)));

            case 0xD5:     // PUSH DE
                return(new Instruction(Ops.PUSH_R16, 1, new Options(R16.DE)));

            case 0xE5:     // PUSH HL
                return(new Instruction(Ops.PUSH_R16, 1, new Options(R16.HL)));

            /** POP R16 */
            case 0xF1:     // POP AF
                return(new Instruction(Ops.POP_R16, 1, new Options(R16.AF)));

            case 0xC1:     // POP BC
                return(new Instruction(Ops.POP_R16, 1, new Options(R16.BC)));

            case 0xD1:     // POP DE
                return(new Instruction(Ops.POP_R16, 1, new Options(R16.DE)));

            case 0xE1:     // POP HL
                return(new Instruction(Ops.POP_R16, 1, new Options(R16.HL)));

            /** INC R8 */
            case 0x3C:     // INC A
                return(new Instruction(Ops.INC_R8, 1, new Options(R8.A)));

            case 0x04:     // INC B
                return(new Instruction(Ops.INC_R8, 1, new Options(R8.B)));

            case 0x0C:     // INC C
                return(new Instruction(Ops.INC_R8, 1, new Options(R8.C)));

            case 0x14:     // INC D
                return(new Instruction(Ops.INC_R8, 1, new Options(R8.D)));

            case 0x1C:     // INC E
                return(new Instruction(Ops.INC_R8, 1, new Options(R8.E)));

            case 0x24:     // INC H
                return(new Instruction(Ops.INC_R8, 1, new Options(R8.H)));

            case 0x2C:     // INC L
                return(new Instruction(Ops.INC_R8, 1, new Options(R8.L)));

            case 0x34:     // INC [HL]
                return(new Instruction(Ops.INC_R8, 1, new Options(R8.iHL)));

            /** DEC R8 */
            case 0x3D:     // DEC A
                return(new Instruction(Ops.DEC_R8, 1, new Options(R8.A)));

            case 0x05:     // DEC B
                return(new Instruction(Ops.DEC_R8, 1, new Options(R8.B)));

            case 0x0D:     // DEC C
                return(new Instruction(Ops.DEC_R8, 1, new Options(R8.C)));

            case 0x15:     // DEC D
                return(new Instruction(Ops.DEC_R8, 1, new Options(R8.D)));

            case 0x1D:     // DEC E
                return(new Instruction(Ops.DEC_R8, 1, new Options(R8.E)));

            case 0x25:     // DEC H
                return(new Instruction(Ops.DEC_R8, 1, new Options(R8.H)));

            case 0x2D:     // DEC L
                return(new Instruction(Ops.DEC_R8, 1, new Options(R8.L)));

            case 0x35:     // DEC [HL]
                return(new Instruction(Ops.DEC_R8, 1, new Options(R8.iHL)));

            /** INC R16 */
            case 0x03:     // INC BC
                return(new Instruction(Ops.INC_R16, 1, new Options(R16.BC)));

            case 0x13:     // INC DE
                return(new Instruction(Ops.INC_R16, 1, new Options(R16.DE)));

            case 0x23:     // INC HL
                return(new Instruction(Ops.INC_R16, 1, new Options(R16.HL)));

            case 0x33:     // INC SP
                return(new Instruction(Ops.INC_R16, 1, new Options(R16.SP)));

            /** DEC R16 */
            case 0x0B:     // DEC BC
                return(new Instruction(Ops.DEC_R16, 1, new Options(R16.BC)));

            case 0x1B:     // DEC DE
                return(new Instruction(Ops.DEC_R16, 1, new Options(R16.DE)));

            case 0x2B:     // DEC HL
                return(new Instruction(Ops.DEC_R16, 1, new Options(R16.HL)));

            case 0x3B:     // DEC SP
                return(new Instruction(Ops.DEC_R16, 1, new Options(R16.SP)));

            /** LD R16, N16 */
            case 0x01:     // LD BC, N16
                return(new Instruction(Ops.LD_R16_N16, 3, new Options(R16.BC)));

            case 0x11:     // LD DE, N16
                return(new Instruction(Ops.LD_R16_N16, 3, new Options(R16.DE)));

            case 0x21:     // LD HL, N16
                return(new Instruction(Ops.LD_R16_N16, 3, new Options(R16.HL)));

            case 0x31:     // LD SP, N16
                return(new Instruction(Ops.LD_R16_N16, 3, new Options(R16.SP)));

            /** Arithmetic */
            case 0xC6:     // ADD A, N8
                return(new Instruction(Ops.ADD_A_N8, 2));

            case 0xCE:     // ADC A, N8
                return(new Instruction(Ops.ADC_A_N8, 2));

            case 0xD6:     // SUB A, N8
                return(new Instruction(Ops.SUB_A_N8, 2));

            case 0xDE:     // SBC A, N8
                return(new Instruction(Ops.SBC_A_N8, 2));

            /** RET */
            case 0xC9:     // RET
                return(new Instruction(Ops.RET, 1, new Options(CC.NONE)));

            case 0xD8:     // RET C
                return(new Instruction(Ops.RET, 1, new Options(CC.C)));

            case 0xD0:     // RET NC
                return(new Instruction(Ops.RET, 1, new Options(CC.NC)));

            case 0xC8:     // RET Z
                return(new Instruction(Ops.RET, 1, new Options(CC.Z)));

            case 0xC0:     // RET NZ
                return(new Instruction(Ops.RET, 1, new Options(CC.NZ)));

            /** SP ops */
            case 0xF8:     // LD HL, SP+e8
                return(new Instruction(Ops.LD_HL_SPaddE8, 2));

            case 0xF9:     // LD SP, HL
                return(new Instruction(Ops.LD_SP_HL, 1));

            case 0xE8:     // ADD SP, E8
                return(new Instruction(Ops.ADD_SP_E8, 2));

            /** A rotate */
            case 0x07:     // RLCA
                return(new Instruction(Ops.RLCA, 1));

            case 0x0F:     // RRCA
                return(new Instruction(Ops.RRCA, 1));

            case 0x1F:     // RRA
                return(new Instruction(Ops.RRA, 1));

            case 0x17:     // RLA
                return(new Instruction(Ops.RLA, 1));

            /** A ops */
            case 0xE6:     // AND A, N8
                return(new Instruction(Ops.AND_N8, 2));

            case 0xF6:     // OR A, N8
                return(new Instruction(Ops.OR_A_N8, 2));

            case 0xEE:     // XOR A, N8
                return(new Instruction(Ops.XOR_A_N8, 2));

            case 0xFE:     // CP A, N8
                return(new Instruction(Ops.CP_A_N8, 2));

            /** Interrupts */
            case 0x10:     // STOP
                return(new Instruction(Ops.STOP, 2));

            case 0x76:     // HALT
                return(new Instruction(Ops.HALT, 1));

            /** Carry flag */
            case 0x37:     // SCF
                return(new Instruction(Ops.SCF, 1));

            case 0x3F:     // CCF
                return(new Instruction(Ops.CCF, 1));

            /** JP */
            case 0xE9:     // JP HL
                return(new Instruction(Ops.JP_HL, 1));

            case 0xC3:     // JP N16
                return(new Instruction(Ops.JP_N16, 3, new Options(CC.NONE)));

            case 0xDA:     // JP C, N16
                return(new Instruction(Ops.JP_N16, 3, new Options(CC.C)));

            case 0xD2:     // JP NC, N16
                return(new Instruction(Ops.JP_N16, 3, new Options(CC.NC)));

            case 0xCA:     // JP Z, N16
                return(new Instruction(Ops.JP_N16, 3, new Options(CC.Z)));

            case 0xC2:     // JP NZ, N16
                return(new Instruction(Ops.JP_N16, 3, new Options(CC.NZ)));

            /** CALL */
            case 0xCD:     // CALL N16
                return(new Instruction(Ops.CALL_N16, 3, new Options(CC.NONE)));

            case 0xDC:     // CALL C, N16
                return(new Instruction(Ops.CALL_N16, 3, new Options(CC.C)));

            case 0xD4:     // CALL NC, N16
                return(new Instruction(Ops.CALL_N16, 3, new Options(CC.NC)));

            case 0xCC:     // CALL Z, N16
                return(new Instruction(Ops.CALL_N16, 3, new Options(CC.Z)));

            case 0xC4:     // CALL NZ, N16
                return(new Instruction(Ops.CALL_N16, 3, new Options(CC.NZ)));

            /** ADD HL, R16 */
            case 0x09:     // ADD HL, BC
                return(new Instruction(Ops.ADD_HL_R16, 1, new Options(R16.BC)));

            case 0x19:     // ADD HL, DE
                return(new Instruction(Ops.ADD_HL_R16, 1, new Options(R16.DE)));

            case 0x29:     // ADD HL, HL
                return(new Instruction(Ops.ADD_HL_R16, 1, new Options(R16.HL)));

            case 0x39:     // ADD HL, SP
                return(new Instruction(Ops.ADD_HL_R16, 1, new Options(R16.SP)));

            /** Reset Vectors */
            case 0xC7:     // RST 00h
                return(new Instruction(Ops.RST, 1, new Options((ushort)0x00)));

            case 0xCF:     // RST 08h
                return(new Instruction(Ops.RST, 1, new Options((ushort)0x08)));

            case 0xD7:     // RST 10h
                return(new Instruction(Ops.RST, 1, new Options((ushort)0x10)));

            case 0xDF:     // RST 18h
                return(new Instruction(Ops.RST, 1, new Options((ushort)0x18)));

            case 0xE7:     // RST 20h
                return(new Instruction(Ops.RST, 1, new Options((ushort)0x20)));

            case 0xEF:     // RST 28h
                return(new Instruction(Ops.RST, 1, new Options((ushort)0x28)));

            case 0xF7:     // RST 30h
                return(new Instruction(Ops.RST, 1, new Options((ushort)0x30)));

            case 0xFF:     // RST 38h
                return(new Instruction(Ops.RST, 1, new Options((ushort)0x38)));

            /** LD between A and R16 */
            case 0x02:     // LD [BC], A
                return(new Instruction(Ops.LD_iR16_A, 1, new Options(R16.BC)));

            case 0x12:     // LD [DE], A
                return(new Instruction(Ops.LD_iR16_A, 1, new Options(R16.DE)));

            case 0x22:     // LD [HL+], A
                return(new Instruction(Ops.LD_iHLinc_A, 1));

            case 0x32:     // LD [HL-], A
                return(new Instruction(Ops.LD_iHLdec_A, 1));

            case 0x0A:     // LD A, [BC]
                return(new Instruction(Ops.LD_A_iR16, 1, new Options(R16.BC)));

            case 0x1A:     // LD A, [DE]
                return(new Instruction(Ops.LD_A_iR16, 1, new Options(R16.DE)));

            case 0x2A:     // LD A, [HL+]
                return(new Instruction(Ops.LD_A_iHLinc, 1));

            case 0x3A:     // LD A, [HL-]
                return(new Instruction(Ops.LD_A_iHLdec, 1));

            /** LD between A and High RAM */
            case 0xF0:     // LD A, [$FF00+N8]
                return(new Instruction(Ops.LD_A_iFF00plusN8, 2));

            case 0xE0:     // LD [$FF00+N8], A
                return(new Instruction(Ops.LD_iFF00plusN8_A, 2));

            case 0xF2:     // LD A, [$FF00+C]
                return(new Instruction(Ops.LD_A_iFF00plusC, 1));

            case 0xE2:     // LD [$FF00+C], A
                return(new Instruction(Ops.LD_iFF00plusC_A, 1));


            case 0xFA:     // LD A, [N16]
                return(new Instruction(Ops.LD_A_iN16, 3));

            case 0xEA:     // LD [N16], A
                return(new Instruction(Ops.LD_iN16_A, 3));

            case 0x08:     // LD [N16], SP
                return(new Instruction(Ops.LD_iN16_SP, 3));

            case 0xF3:     // DI - Disable interrupts master flag
                return(new Instruction(Ops.DI, 1));

            case 0xFB:     // EI - Enable interrupts master flag
                return(new Instruction(Ops.EI, 1));

            case 0x36:     // LD [HL], N8
                return(new Instruction(Ops.LD_iHL_N8, 2));

            case 0x2F:     // CPL
                return(new Instruction(Ops.CPL, 1));

            case 0xD9:     // RETI
                return(new Instruction(Ops.RETI, 1));

            case 0x27:     // DAA
                return(new Instruction(Ops.DA_A, 1));

            case 0x00:     // NOP
                return(new Instruction(Ops.NOP, 1));


            /** Invalid */
            case 0xD3:
            case 0xDB:
            case 0xDD:
            case 0xE3:
            case 0xE4:
            case 0xEB:
            case 0xEC:
            case 0xED:
            case 0xF4:
            case 0xFC:
            case 0xFD:
                return(new Instruction(Ops.INVALID_OPCODE, 1));
            }

            R8[] typeTable = new R8[] { R8.B, R8.C, R8.D, R8.E, R8.H, R8.L, R8.iHL, R8.A };
            // Mask for the low or high half of the table
            var HALF_MASK = 1 << 3;

            // #region Algorithm decoding ADD, ADC, SUB, SBC, AND, XOR, OR, CP in 0x80-0xBF
            if (upperNybble >= 0x8 && upperNybble <= 0xB)
            {
                var lowOps  = new Executor[] { Ops.ADD_A_R8, Ops.SUB_A_R8, Ops.AND_A_R8, Ops.OR_A_R8 };
                var highOps = new Executor[] { Ops.ADC_A_R8, Ops.SBC_A_R8, Ops.XOR_A_R8, Ops.CP_A_R8 };

                var type  = typeTable[lowerNybble & 0b111];
示例#20
0
 public void SetValue(R8 value)
 {
     SetType(ExprTypeKind.R8);
     ExprValue = value;
 }
 public static R8 Cos(R8 a)
 {
     return(MathUtils.Cos(a));
 }
示例#22
0
 public static BL Ge(this R8 a, R8 b)
 {
     return(a >= b ? BL.True : a < b ? BL.False : BL.NA);
 }
 public static R8 CosD(R8 a)
 {
     return(MathUtils.Cos(a * (Math.PI / 180)));
 }
 public static R8 Default(R8 a)
 {
     return(default(R8));
 }
示例#25
0
 public Options(R8 r8)
 {
     this.r8 = r8;
 }
 public static R8 Sign(R8 a)
 {
     // Preserves NaN. Unfortunately, it also preserves negative zero,
     // but perhaps that is a good thing?
     return(a > 0 ? +1 : a < 0 ? -1 : a);
 }
 public static R4 ToR4(R8 a)
 {
     return((R4)a);
 }
示例#28
0
 public static string GetStringFromR8(R8 r)
 => R8RegMap[(int)r];
 public static R8 NA(R8 a)
 {
     return(R8.NaN);
 }
示例#30
0
 public static BL Le(this R8 a, R8 b)
 {
     return(a <= b ? BL.True : a > b ? BL.False : BL.NA);
 }