コード例 #1
0
ファイル: CPU.cs プロジェクト: TaireruBenaru/NesCOM
        public void ADCImmInstruction(byte Instruction)
        {
            InstructionLength = 2;

            byte Fetched = ROM.GetByte(PC_Register + 1);
            int  Carry   = Status_Register.HasFlag(StatusFlags.C) ? 1 : 0;

            byte Sum = (byte)(A_Register + Fetched + Carry);

            A_Register = Sum;

            if (A_Register == 0)
            {
                Status_Register |= (StatusFlags)StatusFlags.Z;
            }

            if ((A_Register & (1 << 7 - 1)) != 0)
            {
                Status_Register |= (StatusFlags)StatusFlags.N;
            }

            if ((~(A_Register ^ Fetched) & (A_Register ^ Sum) & 0x80) != 0)
            {
                Status_Register |= (StatusFlags)StatusFlags.V;
            }

            if ((A_Register + Fetched + Carry) > 0xFF)
            {
                Status_Register |= (StatusFlags)StatusFlags.C;
            }

            Debug.WriteLine("ADC #" + Fetched + " - Identifier byte: " + Instruction);
        }
コード例 #2
0
            public UnitScaling(SwitchPositions switchPosition, int range, StatusFlags status, OptionsFlags options)
            {
                //todo could add lots of data validation here to check settings match behavior but beyond the scope of intial version

                switch (switchPosition)
                {
                case SwitchPositions.V:
                    if (options.HasFlag(OptionsFlags.VoltAmpHz))
                    {
                        if (status.HasFlag(StatusFlags.dutyCycle))
                        {
                            units = "% V";
                            //todo
                        }
                        else
                        {
                            units = "Hz V";
                            //todo
                        }
                    }
                    else
                    {
                        if (range == 4)
                        {
                            units           = "mV";
                            valueMuntiplyer = 0.01M;
                        }
                        else
                        {
                            units           = "V";
                            valueMuntiplyer = 1 / (decimal)Math.Pow(10, 4 - range);
                        }
                        if (status.HasFlag(StatusFlags.negertive))
                        {
                            valueMuntiplyer *= -1;
                        }
                        if (options.HasFlag(OptionsFlags.AC))
                        {
                            units += " AC";
                        }
                    }
                    break;

                case SwitchPositions.Ohms:
                    units = "Ohms";
                    break;

                case SwitchPositions.F:
                    units = "F";
                    //todo
                    break;


                case SwitchPositions.uA:
                    if (options.HasFlag(OptionsFlags.VoltAmpHz))
                    {
                        //todo
                        if (status.HasFlag(StatusFlags.dutyCycle))
                        {
                            units = "% uA";
                            //todo
                        }
                        else
                        {
                            units = "Hz uA";
                            //todo
                        }
                    }
                    else
                    {
                        units           = "uA";
                        valueMuntiplyer = 1 / (decimal)Math.Pow(10, 2 - range);
                        if (status.HasFlag(StatusFlags.negertive))
                        {
                            valueMuntiplyer *= -1;
                        }
                        if (options.HasFlag(OptionsFlags.AC))
                        {
                            units += " AC";
                        }
                    }
                    break;

                case SwitchPositions.mA:
                    if (options.HasFlag(OptionsFlags.VoltAmpHz))
                    {
                        //todo
                        if (status.HasFlag(StatusFlags.dutyCycle))
                        {
                            units = "% mA";
                            //todo
                        }
                        else
                        {
                            units = "Hz mA";
                            //todo
                        }
                    }
                    else
                    {
                        units           = "mA";
                        valueMuntiplyer = 1 / (decimal)Math.Pow(10, 3 - range);
                        if (status.HasFlag(StatusFlags.negertive))
                        {
                            valueMuntiplyer *= -1;
                        }
                        if (options.HasFlag(OptionsFlags.AC))
                        {
                            units += " AC";
                        }
                    }
                    break;

                case SwitchPositions.A:
                    if (options.HasFlag(OptionsFlags.VoltAmpHz))
                    {
                        if (status.HasFlag(StatusFlags.dutyCycle))
                        {
                            units = "% A";
                            //todo
                        }
                        else
                        {
                            units = "Hz A";
                            //todo
                        }
                    }
                    else
                    {
                        units           = "A";
                        valueMuntiplyer = 0.001M;
                        if (status.HasFlag(StatusFlags.negertive))
                        {
                            valueMuntiplyer *= -1;
                        }
                        if (options.HasFlag(OptionsFlags.AC))
                        {
                            units += " AC";
                        }
                    }
                    break;

                case SwitchPositions.BEEP:
                    units = "BEEP";
                    //todo - future task not important
                    break;

                case SwitchPositions.DIODE:
                    units = "DIODE";
                    //todo - future task not important
                    break;

                case SwitchPositions.HZdutycycle:
                    if (status.HasFlag(StatusFlags.dutyCycle))
                    {
                        units = "%";
                        //todo
                    }
                    else
                    {
                        units = "Hz";
                        //todo
                    }
                    //todo

                    break;

                default:
                    throw (new ArgumentException("switch positon given is invaid"));
                }
            }
コード例 #3
0
            public UnitScaling(SwitchPositions switchPosition, CouplingFlags coupling, StatusFlags status, int range)
            {
                bool negertiveValue = status.HasFlag(StatusFlags.neg);

                //todo could add lots of data validation here to check settings match behavior but beyond the scope of intial version

                switch (switchPosition)
                {
                case SwitchPositions.V:
                    units           = "V";
                    valueMuntiplyer = 1 / (decimal)Math.Pow(10, 5 - range);
                    if (negertiveValue)
                    {
                        valueMuntiplyer *= -1;
                    }
                    break;

                case SwitchPositions.VAC:
                    units           = "V AC";
                    valueMuntiplyer = 1 / (decimal)Math.Pow(10, 5 - range);
                    break;

                case SwitchPositions.mV:
                    units           = "mV";
                    valueMuntiplyer = 0.01M;
                    if (negertiveValue)
                    {
                        valueMuntiplyer *= -1;
                    }
                    break;

                case SwitchPositions.Ohms:
                    switch (range)
                    {
                    case 1:
                        units           = "Ohms";
                        valueMuntiplyer = 0.01M;
                        break;

                    case 2:
                        units           = "KOhms";
                        valueMuntiplyer = 0.0001M;
                        break;

                    case 3:
                        units           = "KOhms";
                        valueMuntiplyer = 0.001M;
                        break;

                    case 4:
                        units           = "KOhms";
                        valueMuntiplyer = 0.01M;
                        break;

                    case 5:
                        units           = "MOhms";
                        valueMuntiplyer = 0.0001M;
                        break;

                    case 6:
                        units           = "MOhms";
                        valueMuntiplyer = 0.001M;
                        break;

                    case 7:
                        units           = "MOhms";
                        valueMuntiplyer = 0.01M;
                        break;
                    }
                    break;

                case SwitchPositions.F:
                    //meter doen't like this mode stops outputing values to RS232 not sure why
                    units = "F";
                    //todo
                    break;

                case SwitchPositions.degC:
                    units           = "°C";
                    valueMuntiplyer = 0.1M;
                    if (negertiveValue)
                    {
                        valueMuntiplyer *= -1;
                    }
                    break;

                case SwitchPositions.uA:
                    units           = "uA";
                    valueMuntiplyer = 1 / (decimal)Math.Pow(10, 2 - range);
                    if (negertiveValue & !coupling.HasFlag(CouplingFlags.AC))
                    {
                        valueMuntiplyer *= -1;
                    }
                    break;

                case SwitchPositions.mA:
                    units           = "mA";
                    valueMuntiplyer = 1 / (decimal)Math.Pow(10, 3 - range);
                    if (negertiveValue & !coupling.HasFlag(CouplingFlags.AC))
                    {
                        valueMuntiplyer *= -1;
                    }
                    break;

                case SwitchPositions.A:
                    units           = "A";
                    valueMuntiplyer = 0.001M;
                    if (negertiveValue)
                    {
                        valueMuntiplyer *= -1;
                    }
                    break;

                case SwitchPositions.BEEP:
                    units = "BEEP";
                    //todo - future task not important
                    break;

                case SwitchPositions.DIODE:
                    units = "DIODE";
                    //todo - future task not important
                    break;

                case SwitchPositions.HZdutycycle:
                    if (negertiveValue)
                    {
                        units           = "duty cycle %";
                        valueMuntiplyer = 0.01M;
                    }
                    else
                    {
                        switch (range)
                        {
                        case 0:
                            units           = "Hz";
                            valueMuntiplyer = 0.001M;
                            break;

                        case 1:
                            units           = "Hz";
                            valueMuntiplyer = 0.01M;
                            break;

                        case 2:
                            units           = "KHz";
                            valueMuntiplyer = 0.0001M;
                            break;

                        case 3:
                            units           = "KHz";
                            valueMuntiplyer = 0.001M;
                            break;

                        case 4:
                            units           = "KHz";
                            valueMuntiplyer = 0.01M;
                            break;

                        case 5:
                            units           = "MHz";
                            valueMuntiplyer = 0.0001M;
                            break;

                        case 6:
                            units           = "MHz";
                            valueMuntiplyer = 0.001M;
                            break;

                        case 7:
                            units           = "MHz";
                            valueMuntiplyer = 0.01M;
                            break;
                        }
                    }
                    break;

                case SwitchPositions.degF:
                    units           = "°F";
                    valueMuntiplyer = 0.1M;
                    if (negertiveValue)
                    {
                        valueMuntiplyer *= -1;
                    }
                    break;

                case SwitchPositions.Percent4To20mA:
                    units           = "%";
                    valueMuntiplyer = 0.01M;
                    if (negertiveValue)
                    {
                        valueMuntiplyer *= -1;
                    }
                    break;

                default:
                    throw (new ApplicationException("switch positon given is invaid"));
                }
            }
コード例 #4
0
        public void HandleEvent(object sender, StatusFileEvent currentStatusData)
        {
            Log.Instance.Info("Handling Status Event: {statusevent}", currentStatusData.ToString());
            StatusData statusData = new StatusData();

            if (currentStatusData != null)
            {
                statusData.LastUpdate = DateTime.Now;

                // Original Status Flags
                StatusFlags curState = currentStatusData.Flags;
                if (curState.HasFlag(StatusFlags.Docked))
                {
                    statusData.Docked = true;
                }
                if (curState.HasFlag(StatusFlags.Landed))
                {
                    statusData.Landed = true;
                }
                if (curState.HasFlag(StatusFlags.LandingGearDown))
                {
                    statusData.LandingGearDown = true;
                }
                if (curState.HasFlag(StatusFlags.ShieldsUp))
                {
                    statusData.ShieldsUp = true;
                }
                if (curState.HasFlag(StatusFlags.Supercruise))
                {
                    statusData.Supercruise = true;
                }
                if (curState.HasFlag(StatusFlags.FlightAssistOff))
                {
                    statusData.FlightAssistOff = true;
                }
                if (curState.HasFlag(StatusFlags.HardpointsDeployed))
                {
                    statusData.HardpointsDeployed = true;
                }
                if (curState.HasFlag(StatusFlags.InWing))
                {
                    statusData.InWing = true;
                }
                if (curState.HasFlag(StatusFlags.LightsOn))
                {
                    statusData.LightsOn = true;
                }
                if (curState.HasFlag(StatusFlags.CargoScoopDeployed))
                {
                    statusData.CargoScoopDeployed = true;
                }
                if (curState.HasFlag(StatusFlags.SilentRunning))
                {
                    statusData.SilentRunning = true;
                }
                if (curState.HasFlag(StatusFlags.ScoopingFuel))
                {
                    statusData.ScoopingFuel = true;
                }
                if (curState.HasFlag(StatusFlags.SrvHandbrake))
                {
                    statusData.SrvHandbrake = true;
                }
                if (curState.HasFlag(StatusFlags.SrvTurret))
                {
                    statusData.SrvTurret = true;
                }
                if (curState.HasFlag(StatusFlags.SrvUnderShip))
                {
                    statusData.SrvUnderShip = true;
                }
                if (curState.HasFlag(StatusFlags.SrvDriveAssist))
                {
                    statusData.SrvDriveAssist = true;
                }
                if (curState.HasFlag(StatusFlags.FsdMassLocked))
                {
                    statusData.FsdMassLocked = true;
                }
                if (curState.HasFlag(StatusFlags.FsdCharging))
                {
                    statusData.FsdCharging = true;
                }
                if (curState.HasFlag(StatusFlags.FsdCooldown))
                {
                    statusData.FsdCooldown = true;
                }
                if (curState.HasFlag(StatusFlags.LowFuel))
                {
                    statusData.LowFuel = true;
                }
                if (curState.HasFlag(StatusFlags.Overheating))
                {
                    statusData.Overheating = true;
                }
                if (curState.HasFlag(StatusFlags.HasLatLong))
                {
                    statusData.HasLatLong = true;
                    statusData.Latitude   = currentStatusData.Latitude;
                    statusData.Longitude  = currentStatusData.Longitude;
                }
                if (curState.HasFlag(StatusFlags.IsInDanger))
                {
                    statusData.InDanger = true;
                }
                if (curState.HasFlag(StatusFlags.BeingInterdicted))
                {
                    statusData.BeingInterdicted = true;
                }
                if (curState.HasFlag(StatusFlags.InMainShip))
                {
                    statusData.InMainShip = true;
                }
                if (curState.HasFlag(StatusFlags.InFighter))
                {
                    statusData.InFighter = true;
                }
                if (curState.HasFlag(StatusFlags.HudInAnalysisMode))
                {
                    statusData.HudAnalysisMode = true;
                }
                if (curState.HasFlag(StatusFlags.NightVision))
                {
                    statusData.NightVision = true;
                }
                if (curState.HasFlag(StatusFlags.FsdJump))
                {
                    statusData.FsdJump = true;
                }
                if (curState.HasFlag(StatusFlags.AltitudeFromAverageRadius))
                {
                    statusData.AltitudeFromAverageRadius = true;
                }
                if (curState.HasFlag(StatusFlags.SrvHighBeam))
                {
                    statusData.SrvHighBeam = true;
                }

                // Extended Flags from Odyssey
                MoreStatusFlags curState2 = currentStatusData.Flags2;
                if (curState2.HasFlag(MoreStatusFlags.OnFoot))
                {
                    statusData.OnFoot = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.InTaxi))
                {
                    statusData.InTaxi = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.InMulticrew))
                {
                    statusData.InMulticrew = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.OnFootInStation))
                {
                    statusData.OnFootInStation = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.OnFootOnPlanet))
                {
                    statusData.OnFootOnPlanet = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.AimDownSight))
                {
                    statusData.AimDownSight = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.LowOxygen))
                {
                    statusData.LowOxygen = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.LowHealth))
                {
                    statusData.LowHealth = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.Cold))
                {
                    statusData.Cold = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.Hot))
                {
                    statusData.Hot = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.VeryCold))
                {
                    statusData.VeryCold = true;
                }
                if (curState2.HasFlag(MoreStatusFlags.VeryHot))
                {
                    statusData.VeryHot = true;
                }

                if (currentStatusData.Flags != 0)
                {
                    if (currentStatusData.Pips.System != null)
                    {
                        statusData.SystemPips = currentStatusData.Pips.System;
                    }
                    if (currentStatusData.Pips.Engine != null)
                    {
                        statusData.EnginePips = currentStatusData.Pips.Engine;
                    }
                    if (currentStatusData.Pips.Weapons != null)
                    {
                        statusData.WeaponPips = currentStatusData.Pips.Weapons;
                    }
                    if (currentStatusData.Firegroup != null)
                    {
                        statusData.FireGroup = currentStatusData.Firegroup;
                    }
                    if (currentStatusData.GuiFocus != null)
                    {
                        statusData.GuiFocus = currentStatusData.GuiFocus.ToString();
                    }
                    if (currentStatusData.Fuel != null)
                    {
                        statusData.FuelMain = currentStatusData.Fuel.FuelMain;
                    }
                    if (currentStatusData.Fuel != null)
                    {
                        statusData.FuelReservoir = currentStatusData.Fuel.FuelReservoir;
                    }
                    if (currentStatusData.Cargo != null)
                    {
                        statusData.Cargo = currentStatusData.Cargo;
                    }
                    if (currentStatusData.LegalState != null)
                    {
                        statusData.LegalState = currentStatusData.LegalState;
                    }
                    if (currentStatusData.Altitude != null)
                    {
                        statusData.Altitude = currentStatusData.Altitude;
                    }
                    if (currentStatusData.Heading != null)
                    {
                        statusData.Heading = currentStatusData.Heading;
                    }
                    if (currentStatusData.BodyName != null)
                    {
                        statusData.BodyName = currentStatusData.BodyName;
                    }
                    if (currentStatusData.PlanetRadius != null)
                    {
                        statusData.PlanetRadius = currentStatusData.PlanetRadius;
                    }
                    if (currentStatusData.Balance != null)
                    {
                        statusData.Balance = currentStatusData.Balance;
                    }
                    if (currentStatusData.Destination.System != null)
                    {
                        statusData.DestinationSystem = currentStatusData.Destination.System;
                    }
                    if (currentStatusData.Destination.Body != null)
                    {
                        statusData.DestinationBody = currentStatusData.Destination.Body;
                    }
                    if (currentStatusData.Destination.Name != null)
                    {
                        statusData.DestinationName = currentStatusData.Destination.Name;
                    }
                    if (currentStatusData.Oxygen != null)
                    {
                        statusData.Oxygen = currentStatusData.Oxygen;
                    }
                    if (currentStatusData.Health != null)
                    {
                        statusData.Health = currentStatusData.Health;
                    }
                    if (currentStatusData.Temperature != null)
                    {
                        statusData.Temperature = currentStatusData.Temperature;
                    }
                    if (currentStatusData.SelectedWeapon != null)
                    {
                        statusData.SelectedWeapon = currentStatusData.SelectedWeapon;
                    }
                    if (currentStatusData.Gravity != null)
                    {
                        statusData.Gravity = currentStatusData.Gravity;
                    }
                }

                Log.Instance.Info("Sending Status to worker {status}", statusData.ToString());
                Caller.GameDataEvent(GameEventType.Status, statusData);
            }
        }