Exemplo n.º 1
0
        private IServerDeltaButtonState GetButtonDelta(IButtonState state)
        {
            if (!DeltaButtonStates.ContainsKey(state.ProviderName))
            {
                DeltaButtonStates[state.ProviderName] = new Dictionary <string, IServerDeltaButtonState>();
            }

            if (!DeltaButtonStates[state.ProviderName].ContainsKey(state.InputName))
            {
                var deltaState = new DeltaButtonState
                {
                    InputName      = state.InputName,
                    ProviderName   = state.ProviderName,
                    IsPressed      = false,
                    Acceleration   = 0,
                    Velocity       = 0,
                    LastPressCount = 0,
                    PressCount     = 0,
                    TimeDelta      = 1
                };

                DeltaButtonStates[state.ProviderName][state.InputName] = deltaState;
                AllDeltas.Add(deltaState);
                AllMeasuredDeltas.Add(deltaState);
                return(deltaState);
            }

            return(DeltaButtonStates[state.ProviderName][state.InputName]);
        }
Exemplo n.º 2
0
        void Awake()
        {
            OnValidate();

            _idleState        = new IdleState(this);
            _hoveredOverState = new HoveredOverState(this);
            _pressedDownState = new PressedDownState(this);
            _currentState     = _idleState;
        }
        public void ApplyNewState(IButtonState newState)
        {
            var wasPressed = IsPressed;

            IsPressed = newState.IsPressed;
            if (!wasPressed && IsPressed)
            {
                _accumulatedPressCount++;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///     This updates the key map. If they key exists, it will overwrite the existing value.
 ///     if
 /// </summary>
 /// <param name="inputState"></param>
 public void UpdateKeyMap(IButtonState inputState)
 {
     if (buttonState.ContainsKey(inputState.buttons))
     {
         buttonState[inputState.buttons] = inputState;
     }
     else
     {
         buttonState.Add(inputState.buttons, inputState);
     }
 }
Exemplo n.º 5
0
        public override void Exit(NoArgDelegate callback = null)
        {
            _currentState = _idleState;

            if (_animation != null)
            {
                StopCoroutine(_animation);
            }

            _animation = StartCoroutine(Exit(_animatedElementSettings._exitDuration, _exitDelay, callback));
        }
Exemplo n.º 6
0
        public EmulationEngine(string bootromFile, string romFile)
        {
            _logger = Console.Out;

            var vram = new MemoryBlock(8192);
            var oam  = new MemoryBlock(160);
            var io   = new AddressableRegisterField(256);

            // TODO: replace this with the real registers
            for (var i = 0; i < io.Size; i++)
            {
                io.Add(i, new Register <byte>());
            }

            var @if = new Register <byte>();
            var ie  = new Register <byte>();

            var vblankInterrupt      = new InterruptTrigger(new BoolPointer(@if, 0));
            var lcdStatusInterrupt   = new InterruptTrigger(new BoolPointer(@if, 1));
            var timerInterrupt       = new InterruptTrigger(new BoolPointer(@if, 2));
            var buttonPressInterrupt = new InterruptTrigger(new BoolPointer(@if, 4));

            _timerController = new TimerController(timerInterrupt);

            var p1 = new ButtonInputRegister(buttonPressInterrupt);

            Buttons = p1;

            var lcdc       = new LcdControlRegister();
            var lcdcLogger = new LoggingRegister <byte>(lcdc, "lcdc", _logger, logReads: false);
            var stat       = new LcdStatusRegister();
            var statLogger = new LoggingRegister <byte>(stat, "stat", _logger, logReads: false);
            var scy        = new Register <byte>();
            var scx        = new Register <byte>();
            var ly         = new Register <byte>();

            var lyLogger = new LoggingRegister <byte>(ly, "ly", _logger, logReads: false);
            var lyc      = new Register <byte>();

            var bgp  = new Register <byte>();
            var obp0 = new Register <byte>();
            var obp1 = new Register <byte>();

            var wy = new Register <byte>();
            var wx = new Register <byte>();

            var bootromEnable = new Register <byte>();

            io.Add(0x00, p1);

            var serialLog      = new StreamWriter("C:/Users/Andreas/Dropbox/DMG/serial_log.txt", true);
            var lastSerialByte = 0;

            io.Add(0x01, new LambdaRegister <byte>(b => lastSerialByte = b)); // SB serial transfer
            io.Add(0x02, new LambdaRegister <byte>(b => { if (b == 0x81)
                                                          {
                                                              serialLog.Write(Convert.ToChar(lastSerialByte));
                                                          }
                                                          serialLog.Flush(); }));                                                                // SC serial clock

            io.Add(0x04, _timerController.DIV);
            io.Add(0x05, _timerController.TIMA);
            io.Add(0x06, _timerController.TMA);
            io.Add(0x07, _timerController.TAC);

            io.Add(0x40, lcdc);
            io.Add(0x41, stat);
            io.Add(0x42, scy);
            io.Add(0x43, scx);
            io.Add(0x44, lyLogger);
            io.Add(0x45, lyc);
            io.Add(0x47, bgp);
            io.Add(0x48, obp0);
            io.Add(0x49, obp1);
            io.Add(0x4A, wy);
            io.Add(0x4B, wx);
            io.Add(0x50, bootromEnable);

            io.Add(0x0F, @if);
            io.Add(0xFF, ie);

            var cartridge = CartridgeLoader.FromFile(romFile);

            var memoryMap = new TopLevelMemoryMap(
                new ShadowedMemoryBlock(
                    MemoryBlock.LoadFromFile(bootromFile),
                    cartridge.ROM,
                    new BoolPointer(bootromEnable, 0)
                    ),
                cartridge.RAM,
                vram,
                new MemoryBlock(8192), // internal ram
                oam,
                io);

            io.Add(0x46, new OamDmaController(memoryMap));

            State         = new MachineState(new RegisterField(), memoryMap);
            _loggingState = new MachineState(State.Registers,
                                             new LoggingMemoryBlock(State.Memory, _logger));
            _lcdController = new LcdController(lcdc, stat, scx, scy, ly, lyc, bgp,
                                               vram, oam, obp0, obp1, wy, wx, vblankInterrupt, lcdStatusInterrupt);

            //SkipBootrom();

            //_trace = new StreamWriter($"C:/Users/Andreas/Desktop/trace_{DateTime.Now.ToFileTime()}.txt");
        }
 public virtual void StateChange(IButtonState s)
 {
 }