Пример #1
0
        public SimpleEngine()
        {
            _enabled = false;
            Interval = 1;
            thread   = new Thread(delegate()
            {
                while (true)
                {
                    if (_enabled)
                    {
                        TickEvent.Invoke(this, 0);
                    }
                    Thread.Sleep((int)(Interval * 1000)); // 至少等待Interval秒
                }
            });
            var time = DateTime.Now;

            TickEvent += (sender, tick) =>
            {
                var newtime = DateTime.Now;
                //Trace.WriteLine(newtime-time); // 测试函数,显示间隔
#if DEBUG
                Fps = (int)(1000 / (newtime - time).TotalMilliseconds);
                Notify("Fps");
#endif
                time = newtime;
                Trace.Flush();
            };
        }
Пример #2
0
 public void RaiseTickEvent()
 {
     if (TickEvent != null)
     {
         TickEvent.Invoke(this, e);
     }
 }
Пример #3
0
        public void JumpRelative(byte value, ref ushort pc)
        {
            sbyte signed = unchecked ((sbyte)value);

            pc = (ushort)(pc + signed);
            TickEvent?.Invoke();
        }
Пример #4
0
 public void Push(ref ushort pointer, byte valueHigh, byte valueLow)
 {
     pointer -= 2;
     TickEvent?.Invoke();
     memory.WriteWord(pointer, BitUtils.BytesToUshort(valueHigh, valueLow));
     TickEvent?.Invoke();
     TickEvent?.Invoke();
 }
Пример #5
0
 public void Return(ref ushort sp, ref ushort pc)
 {
     pc = memory.ReadWord(sp);
     TickEvent?.Invoke();
     TickEvent?.Invoke();
     sp = (ushort)(sp + 2);
     TickEvent?.Invoke();
 }
Пример #6
0
 public void ReturnConditional(ref ushort sp, ref ushort pc, Flag flag, bool condition, byte flags)
 {
     TickEvent?.Invoke();
     if (FlagUtils.GetFlag(flag, flags) == condition)
     {
         Return(ref sp, ref pc);
     }
 }
Пример #7
0
 public void Call(ushort address, ref ushort sp, ref ushort pc)
 {
     sp = (ushort)(sp - 2);
     memory.WriteWord(sp, pc);
     TickEvent?.Invoke();
     TickEvent?.Invoke();
     pc = address;
     TickEvent?.Invoke();
 }
Пример #8
0
        public void DecrementWord(ref byte targetHigh, ref byte targetLow)
        {
            ushort target = BitUtils.BytesToUshort(targetHigh, targetLow);

            target     = (ushort)(target - 1);
            targetHigh = BitUtils.MostSignificantByte(target);
            targetLow  = BitUtils.LeastSignificantByte(target);
            TickEvent?.Invoke();
        }
Пример #9
0
        public void SetBit(byte addrHigh, byte addrLow, int index, bool bit)
        {
            ushort address = BitUtils.BytesToUshort(addrHigh, addrLow);
            byte   data    = memory.ReadByte(address);

            TickEvent?.Invoke();
            SetBit(ref data, index, bit);
            memory.WriteByte(address, data);
            TickEvent?.Invoke();
        }
Пример #10
0
        public void WriteToAddressAndIncrement(ref byte addrHigh, ref byte addrLow, byte value, short addValue)
        {
            ushort address = BitUtils.BytesToUshort(addrHigh, addrLow);

            memory.WriteByte(address, value);
            TickEvent?.Invoke();
            address  = (ushort)(address + addValue);
            addrHigh = BitUtils.MostSignificantByte(address);
            addrLow  = BitUtils.LeastSignificantByte(address);
        }
Пример #11
0
        public void LoadFromAddressAndIncrement(ref byte dest, ref byte addrHigh, ref byte addrLow, short value)
        {
            ushort address = BitUtils.BytesToUshort(addrHigh, addrLow);

            dest = memory.ReadByte(address);
            TickEvent?.Invoke();
            address  = (ushort)(address + value);
            addrHigh = BitUtils.MostSignificantByte(address);
            addrLow  = BitUtils.LeastSignificantByte(address);
        }
Пример #12
0
        public void Pop(ref byte valueHigh, ref byte valueLow, ref ushort pointer)
        {
            ushort value = memory.ReadWord(pointer);

            pointer += 2;
            TickEvent?.Invoke();
            TickEvent?.Invoke();
            valueHigh = BitUtils.MostSignificantByte(value);
            valueLow  = BitUtils.LeastSignificantByte(value);
        }
Пример #13
0
        public void Swap(byte addrHigh, byte addrLow, ref byte flags)
        {
            ushort address = BitUtils.BytesToUshort(addrHigh, addrLow);
            byte   data    = memory.ReadByte(address);

            TickEvent?.Invoke();
            Swap(ref data, ref flags);
            memory.WriteByte(address, data);
            TickEvent?.Invoke();
        }
Пример #14
0
        public void RotateLeftThroughCarry(byte addrHigh, byte addrLow, ref byte flags)
        {
            ushort address = BitUtils.BytesToUshort(addrHigh, addrLow);
            byte   data    = memory.ReadByte(address);

            TickEvent?.Invoke();
            RotateLeftThroughCarry(ref data, ref flags, false);
            memory.WriteByte(address, data);
            TickEvent?.Invoke();
        }
Пример #15
0
        private void OnTimerEvent(object sender, ElapsedEventArgs args)
        {
            _timeRemainingInSeconds -= 1;
            TickEvent?.Invoke(this, EventArgs.Empty);

            if (_timeRemainingInSeconds <= 0)
            {
                Expire();
            }
        }
Пример #16
0
        void ICountdownService.Reset()
        {
            if (-1 == infoPtr)
            {
                return;
            }
            base.Stop();

            CurrentInfo = countdownInfos[infoPtr];
            TickEvent?.Invoke(CurrentInfo);
        }
Пример #17
0
 public TimerEngine()
 {
     _tick    = 0;
     Elapsed += delegate(object sender, ElapsedEventArgs e)
     {
         lock (this)
         {
             TickEvent.Invoke(this, _tick++);
         }
     };
 }
Пример #18
0
        public void DecrementInMemory(byte addrHigh, byte addrLow, ref byte flags)
        {
            ushort address   = BitUtils.BytesToUshort(addrHigh, addrLow);
            byte   origValue = memory.ReadByte(address);

            TickEvent?.Invoke();
            memory.WriteByte(address, (byte)(origValue - 1));
            FlagUtils.SetFlag(Flag.Z, (byte)(origValue - 1) == 0, ref flags);
            FlagUtils.SetFlag(Flag.N, true, ref flags);
            FlagUtils.SetFlag(Flag.H, (origValue & 0x0F) < 1, ref flags);
            TickEvent?.Invoke();
        }
Пример #19
0
        private static void TickLoop(UInt64 times)
        {
            UInt64 i = 0;

            while (i != times)
            {
                GameTick++;

                TickEvent?.Invoke(null, GameTick);
                i++;
            }
        }
Пример #20
0
 public void Tick()
 {
     if (!IsRunning)
     {
         return;
     }
     timeLeft = Mathf.Max(0, timeLeft - Time.deltaTime);
     TickEvent?.Invoke();
     if (timeLeft <= 0)
     {
         IsRunning = false;
     }
 }
Пример #21
0
        public void AddSigned(ref ushort to, byte value, ref byte flags)
        {
            ushort originalValue = to;
            sbyte  valueSigned   = unchecked ((sbyte)value);

            to = (ushort)(to + valueSigned);
            FlagUtils.SetFlag(Flag.Z, false, ref flags);
            FlagUtils.SetFlag(Flag.N, false, ref flags);
            FlagUtils.SetFlag(Flag.H, (originalValue & 0x0F) + (value & 0x0F) > 0x0F, ref flags);
            FlagUtils.SetFlag(Flag.C, (originalValue & 0xFF) + value > 0xFF, ref flags);
            TickEvent?.Invoke();
            TickEvent?.Invoke();
        }
Пример #22
0
        public void Add(ref byte toHigh, ref byte toLow, byte valueHigh, byte valueLow, ref byte flags)
        {
            ushort to     = BitUtils.BytesToUshort(toHigh, toLow);
            ushort value  = BitUtils.BytesToUshort(valueHigh, valueLow);
            ushort result = (ushort)((to + value) & 0xFFFF);

            toHigh = BitUtils.MostSignificantByte(result);
            toLow  = BitUtils.LeastSignificantByte(result);
            // Zero flag is not affected
            FlagUtils.SetFlag(Flag.N, false, ref flags);
            FlagUtils.SetFlag(Flag.H, (to & 0xFFF) + (value & 0xFFF) > 0xFFF, ref flags);
            FlagUtils.SetFlag(Flag.C, to + value > 0xFFFF, ref flags);
            TickEvent?.Invoke();
        }
Пример #23
0
        void ICountdownService.Next()
        {
            if (-1 == infoPtr)
            {
                return;
            }

            switch (currentInfo.Status)
            {
            case CountdownInfoStatus.NotStart:
                infoPtr     = (infoPtr + countdownInfos.Count + 1) % countdownInfos.Count;
                CurrentInfo = countdownInfos[infoPtr];

                TickEvent?.Invoke(CurrentInfo);
                return;

            case CountdownInfoStatus.Running:
                base.Stop();
                currentInfo.Minute     = 0;
                currentInfo.Second     = 0;
                currentInfo.FinishTime = DateTime.Now;
                currentInfo.Status     = CountdownInfoStatus.Completed;

                TickEvent?.Invoke(CurrentInfo);
                ReachEndEvent?.Invoke(CurrentInfo);
                return;

            case CountdownInfoStatus.Paused:
                base.Stop();
                currentInfo.Minute     = 0;
                currentInfo.Second     = 0;
                currentInfo.FinishTime = DateTime.Now;
                currentInfo.InterruptionInfos.Last().FinishTime = DateTime.Now;
                currentInfo.Status = CountdownInfoStatus.Completed;

                TickEvent?.Invoke(CurrentInfo);
                ReachEndEvent?.Invoke(CurrentInfo);
                return;

            case CountdownInfoStatus.Completed:
                infoPtr     = (infoPtr + countdownInfos.Count + 1) % countdownInfos.Count;
                CurrentInfo = countdownInfos[infoPtr];

                TickEvent?.Invoke(CurrentInfo);
                return;

            default:
                return;
            }
        }
Пример #24
0
        public void LoadAdjusted(ref byte destHigh, ref byte destLow, ushort value, byte addValue, ref byte flags)
        {
            ushort originalValue = value;
            sbyte  signed        = unchecked ((sbyte)addValue);

            FlagUtils.SetFlag(Flag.C, ((originalValue & 0xFF) + addValue) > 0xFF, ref flags);
            FlagUtils.SetFlag(Flag.H, (originalValue & 0x0F) + (addValue & 0x0F) > 0xF, ref flags);
            ushort result = (ushort)(value + signed);

            destHigh = BitUtils.MostSignificantByte(result);
            destLow  = BitUtils.LeastSignificantByte(result);
            FlagUtils.SetFlag(Flag.Z, false, ref flags);
            FlagUtils.SetFlag(Flag.N, false, ref flags);
            TickEvent?.Invoke();
        }
Пример #25
0
            public bool Update()
            {
                if (ticked)
                {
                    return(true);
                }

                FramesRemain--;
                if (FramesRemain <= 0)
                {
                    TickEvent?.Invoke();
                    ticked = true;
                    return(true);
                }

                return(false);
            }
    // Setup the two Ai players
    private void Start()
    {
        if (OnStart != null)
        {
            OnStart();
        }

        //Set Lane listeners
        foreach (LaneManager lane in lanes)
        {
            lane.OnLaneReady.AddListener(LaneReady);
        }

        P1.init();
        P2.init();

        IBoardState[] data = lanes.ToArray();
        OnTick.Invoke(data);

        // LogStack.Log ("Tournament Manager initialised", LogLevel.System);
    }
Пример #27
0
 // Update is called once per frame
 protected override void UpdateLate()
 {
     spanEv.Invoke();
 }
Пример #28
0
 public void JumpToAddress(ushort address, ref ushort pc)
 {
     pc = address;
     TickEvent?.Invoke();
 }
Пример #29
0
 private void SecondTick(object sender, WorkoutTimerChangesEventArgs e)
 {
     TickEvent?.Invoke(this, new TrainChangeEventArgs());
 }
Пример #30
0
 // Update is called once per frame
 protected override void FixedUpdateLate()
 {
     span40.Invoke();
     span600.Invoke();
 }