Esempio n. 1
0
		private Controller BindToDefinition(ControllerDefinition def, IDictionary<string, Dictionary<string, string>> allbinds, IDictionary<string, Dictionary<string, Config.AnalogBind>> analogbinds)
		{
			var ret = new Controller(def);
			Dictionary<string, string> binds;
			if (allbinds.TryGetValue(def.Name, out binds))
			{
				foreach (var cbutton in def.BoolButtons)
				{
					string bind;
					if (binds.TryGetValue(cbutton, out bind))
					{
						ret.BindMulti(cbutton, bind);
					}
				}
			}

			Dictionary<string, Config.AnalogBind> abinds;
			if (analogbinds.TryGetValue(def.Name, out abinds))
			{
				foreach (var cbutton in def.FloatControls)
				{
					Config.AnalogBind bind;
					if (abinds.TryGetValue(cbutton, out bind))
					{
						ret.BindFloat(cbutton, bind);
					}
				}
			}

			return ret;
		}
Esempio n. 2
0
		public Controller(ControllerDefinition definition)
		{
			_type = definition;
			for (int i = 0; i < _type.FloatControls.Count; i++)
			{
				_floatButtons[_type.FloatControls[i]] = _type.FloatRanges[i].Mid;
				_floatRanges[_type.FloatControls[i]] = _type.FloatRanges[i];
			}
		}
Esempio n. 3
0
 public ControllerDefinition(ControllerDefinition source)
     : this()
 {
     Name = source.Name;
     BoolButtons.AddRange(source.BoolButtons);
     FloatControls.AddRange(source.FloatControls);
     FloatRanges.AddRange(source.FloatRanges);
     AxisConstraints.AddRange(source.AxisConstraints);
 }
Esempio n. 4
0
		public MovieZone(IMovie movie, int start, int length, string key = "")
		{
			Bk2LogEntryGenerator lg = Global.MovieSession.LogGeneratorInstance() as Bk2LogEntryGenerator;
			lg.SetSource(Global.MovieSession.MovieControllerAdapter);
			targetController = new Bk2ControllerAdapter();
			targetController.Type = Global.Emulator.ControllerDefinition;
			targetController.LatchFromSource(targetController); // Reference and create all buttons

			if (key == "")
				key = lg.GenerateLogKey();
			key = key.Replace("LogKey:", "").Replace("#", "");
			key = key.Substring(0, key.Length - 1);

			_inputKey = key;
			Length = length;
			_log = new string[length];

			// Get a IController that only contains buttons in key.
			string[] keys = key.Split('|');
			ControllerDefinition d = new ControllerDefinition();
			for (int i = 0; i < keys.Length; i++)
			{
				if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(keys[i]))
					d.BoolButtons.Add(keys[i]);
				else
					d.FloatControls.Add(keys[i]);
			}

			controller = new Bk2ControllerAdapter() { Type = d };
			Bk2LogEntryGenerator logGenerator = new Bk2LogEntryGenerator("");
			logGenerator.SetSource(controller);
			logGenerator.GenerateLogEntry(); // Reference and create all buttons.

			string movieKey = logGenerator.GenerateLogKey().Replace("LogKey:", "").Replace("#", "");
			movieKey = movieKey.Substring(0, movieKey.Length - 1);
			if (key == movieKey)
			{
				for (int i = 0; i < length; i++)
					_log[i] = movie.GetInputLogEntry(i + start);
			}
			else
			{
				for (int i = 0; i < length; i++)
				{
					controller.LatchFromSource(movie.GetInputState(i + start));
					_log[i] = logGenerator.GenerateLogEntry();
				}
			}
		}
Esempio n. 5
0
		private static AutofireController BindToDefinitionAF(ControllerDefinition def, IEmulator emulator, IDictionary<string, Dictionary<string, string>> allbinds)
		{
			var ret = new AutofireController(def, emulator);
			Dictionary<string, string> binds;
			if (allbinds.TryGetValue(def.Name, out binds))
			{
				foreach (var cbutton in def.BoolButtons)
				{
					string bind;
					if (binds.TryGetValue(cbutton, out bind))
					{
						ret.BindMulti(cbutton, bind);
					}
				}
			}

			return ret;
		}
Esempio n. 6
0
        private void CheckPads(IEnumerable <PadSchema> schemas, BizHawk.Emulation.Common.ControllerDefinition def)
        {
            HashSet <string> analogs = new HashSet <string>(def.FloatControls);
            HashSet <string> bools   = new HashSet <string>(def.BoolButtons);

            foreach (var schema in schemas)
            {
                foreach (var button in schema.Buttons)
                {
                    HashSet <string> searchset = null;
                    switch (button.Type)
                    {
                    case PadSchema.PadInputType.AnalogStick:
                    case PadSchema.PadInputType.FloatSingle:
                    case PadSchema.PadInputType.TargetedPair:
                        // analog
                        searchset = analogs;
                        break;

                    case PadSchema.PadInputType.Boolean:
                        searchset = bools;
                        break;

                    case PadSchema.PadInputType.DiscManager:
                        searchset = bools;
                        searchset.UnionWith(analogs);
                        break;
                    }
                    if (!searchset.Contains(button.Name))
                    {
                        MessageBox.Show(this,
                                        string.Format("Schema warning: Schema entry '{0}':'{1}' will not correspond to any control in definition '{2}'", schema.DisplayName, button.Name, def.Name),
                                        "Dev Warning");
                    }
                }
            }
        }
Esempio n. 7
0
		public GPGXControlConverter(LibGPGX.InputData input)
		{
			Console.WriteLine("Genesis Controller report:");
			foreach (var e in input.system)
				Console.WriteLine("S:{0}", e);
			foreach (var e in input.dev)
				Console.WriteLine("D:{0}", e);

			int player = 1;

			ControllerDef = new ControllerDefinition();

			ControllerDef.BoolButtons.Add("Power");
			ControllerDef.BoolButtons.Add("Reset");

			for (int i = 0; i < LibGPGX.MAX_DEVICES; i++)
			{
				switch (input.dev[i])
				{
					case LibGPGX.INPUT_DEVICE.DEVICE_PAD3B:
						AddToController(i, player, Genesis3);
						player++;
						break;
					case LibGPGX.INPUT_DEVICE.DEVICE_PAD6B:
						AddToController(i, player, Genesis6);
						player++;
						break;
					case LibGPGX.INPUT_DEVICE.DEVICE_MOUSE:
						AddToController(i, player, Mouse);
						DoMouseAnalog(i, player);
						player++;
						break;
					case LibGPGX.INPUT_DEVICE.DEVICE_NONE:
						break;
					case LibGPGX.INPUT_DEVICE.DEVICE_LIGHTGUN:
						// supports menacers and justifiers
						AddToController(i, player, Lightgun);
						DoLightgunAnalog(i, player);
						player++;
						break;
					case LibGPGX.INPUT_DEVICE.DEVICE_PAD2B:
					case LibGPGX.INPUT_DEVICE.DEVICE_PADDLE:
					case LibGPGX.INPUT_DEVICE.DEVICE_SPORTSPAD:
					case LibGPGX.INPUT_DEVICE.DEVICE_TEREBI:
						throw new Exception("Master System only device?  Something went wrong.");
					case LibGPGX.INPUT_DEVICE.DEVICE_ACTIVATOR:
						AddToController(i, player, Activator);
						player++;
						break;
					case LibGPGX.INPUT_DEVICE.DEVICE_XE_A1P:
						AddToController(i, player, XEA1P);
						DoXEA1PAnalog(i, player);
						player++;
						break;
					case LibGPGX.INPUT_DEVICE.DEVICE_PICO:
						// PICO isn't finished on the unmanaged side either
						throw new Exception("Sega PICO not implemented yet!");
					default:
						throw new Exception("Unknown Genesis control device!  Something went wrong.");
				}
			}

			ControllerDef.Name = "GPGX Genesis Controller";
		}
Esempio n. 8
0
 static AppleII()
 {
     AppleIIController = new ControllerDefinition { Name = "Apple IIe Keyboard" };
     AppleIIController.BoolButtons.AddRange(RealButtons);
     AppleIIController.BoolButtons.AddRange(ExtraButtons);
 }
Esempio n. 9
0
		public AutofireController(ControllerDefinition definition)
		{
			On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn;
			Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff;
			_type = definition;
		}
Esempio n. 10
0
			/// <summary>
			/// this controller's definition changes to that of source
			/// </summary>
			/// <param name="source"></param>
			public void CopyFrom(IController source)
			{
				this.def = source.Type;
				buttons.Clear();
				foreach (var k in def.BoolButtons)
					buttons.Add(k, source.IsPressed(k) ? 1.0f : 0);
				foreach (var k in def.FloatControls)
				{
					if (buttons.Keys.Contains(k))
						throw new Exception("name collision between bool and float lists!");
					buttons.Add(k, source.GetFloat(k));
				}
			}
Esempio n. 11
0
		public void HardReset()
		{
			cpu = new MOS6502X();
			cpu.SetCallbacks(ReadMemory, ReadMemory, PeekMemory, WriteMemory);

			cpu.BCD_Enabled = false;
			cpu.OnExecFetch = ExecFetch;
			ppu = new PPU(this);
			ram = new byte[0x800];
			CIRAM = new byte[0x800];
			
			// wire controllers
			// todo: allow changing this
			ControllerDeck = ControllerSettings.Instantiate(ppu.LightGunCallback);
			// set controller definition first time only
			if (ControllerDefinition == null)
			{
				ControllerDefinition = new ControllerDefinition(ControllerDeck.GetDefinition());
				ControllerDefinition.Name = "NES Controller";
				// controls other than the deck
				ControllerDefinition.BoolButtons.Add("Power");
				ControllerDefinition.BoolButtons.Add("Reset");
				if (Board is FDS)
				{
					var b = Board as FDS;
					ControllerDefinition.BoolButtons.Add("FDS Eject");
					for (int i = 0; i < b.NumSides; i++)
						ControllerDefinition.BoolButtons.Add("FDS Insert " + i);
				}
			}

			// don't replace the magicSoundProvider on reset, as it's not needed
			// if (magicSoundProvider != null) magicSoundProvider.Dispose();

			// set up region
			switch (_display_type)
			{
				case Common.DisplayType.PAL:
					apu = new APU(this, apu, true);
					ppu.region = PPU.Region.PAL;
					CoreComm.VsyncNum = 50;
					CoreComm.VsyncDen = 1;
					cpuclockrate = 1662607;
					cpu_sequence = cpu_sequence_PAL;
					_display_type = DisplayType.PAL;
					break;
				case Common.DisplayType.NTSC:
					apu = new APU(this, apu, false);
					ppu.region = PPU.Region.NTSC;
					CoreComm.VsyncNum = 39375000;
					CoreComm.VsyncDen = 655171;
					cpuclockrate = 1789773;
					cpu_sequence = cpu_sequence_NTSC;
					break;
				// this is in bootgod, but not used at all
				case Common.DisplayType.DENDY:
					apu = new APU(this, apu, false);
					ppu.region = PPU.Region.Dendy;
					CoreComm.VsyncNum = 50;
					CoreComm.VsyncDen = 1;
					cpuclockrate = 1773448;
					cpu_sequence = cpu_sequence_NTSC;
					_display_type = DisplayType.DENDY;
					break;
				default:
					throw new Exception("Unknown displaytype!");
			}
			if (magicSoundProvider == null)
				magicSoundProvider = new MagicSoundProvider(this, (uint)cpuclockrate);

			BoardSystemHardReset();

			//check fceux's PowerNES and FCEU_MemoryRand function for more information:
			//relevant games: Cybernoid; Minna no Taabou no Nakayoshi Daisakusen; Huang Di; and maybe mechanized attack
			for(int i=0;i<0x800;i++) if((i&4)!=0) ram[i] = 0xFF; else ram[i] = 0x00;

			SetupMemoryDomains();

			//in this emulator, reset takes place instantaneously
			cpu.PC = (ushort)(ReadMemory(0xFFFC) | (ReadMemory(0xFFFD) << 8));
			cpu.P = 0x34;
			cpu.S = 0xFD;
		}
Esempio n. 12
0
			public SnesSaveController()
			{
				this.def = null;
			}
Esempio n. 13
0
			public SnesSaveController(ControllerDefinition def)
			{
				this.def = def;
			}
Esempio n. 14
0
		/// <summary>don't do this</summary>
		public void ForceType(ControllerDefinition newtype) { _type = newtype; }
Esempio n. 15
0
			public Bk2ControllerDefinition(ControllerDefinition source)
				: base(source)
			{

			}
Esempio n. 16
0
			public ControlAdapter(ControllerDefinition Type, Controller Left, Controller Right, Action<IController, InputState> Convert)
			{
				this.Type = Type;
				this.Left = Left;
				this.Right = Right;
				this.Convert = Convert;
			}
Esempio n. 17
0
 /// <summary>
 /// Adds an axis to the receiver <see cref="ControllerDefinition"/>, and returns it.
 /// The new axis will appear after any that were previously defined.
 /// </summary>
 /// <param name="constraint">pass only for one axis in a pair, by convention the X axis</param>
 /// <returns>identical reference to <paramref name="def"/>; the object is mutated</returns>
 public static ControllerDefinition AddAxis(this ControllerDefinition def, string name, Range <int> range, int neutral, bool isReversed = false, AxisConstraint constraint = null)
 {
     def.Axes.Add(name, new AxisSpec(range, neutral, isReversed, constraint));
     return(def);
 }
Esempio n. 18
0
		private void ReSetLog()
		{
			// Get a IController that only contains buttons in key.
			string[] keys = _inputKey.Split('|');
			ControllerDefinition d = new ControllerDefinition();
			for (int i = 0; i < keys.Length; i++)
			{
				if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(keys[i]))
					d.BoolButtons.Add(keys[i]);
				else
					d.FloatControls.Add(keys[i]);
			}
			Bk2ControllerAdapter newController = new Bk2ControllerAdapter() { Type = d };

			Bk2LogEntryGenerator logGenerator = new Bk2LogEntryGenerator("");
			logGenerator.SetSource(newController);
			logGenerator.GenerateLogEntry(); // Reference and create all buttons.
			// Reset all buttons in targetController (it may still have buttons that aren't being set here set true)
			Bk2LogEntryGenerator tC = new Bk2LogEntryGenerator("");
			tC.SetSource(targetController);
			targetController.SetControllersAsMnemonic(tC.EmptyEntry);
			for (int i = 0; i < Length; i++)
			{
				controller.SetControllersAsMnemonic(_log[i]);
				LatchFromSourceButtons(targetController, controller);
				newController.LatchFromSource(targetController);
				_log[i] = logGenerator.GenerateLogEntry();
			}

			controller = newController;
		}
Esempio n. 19
0
 /// <summary>
 /// Adds an X/Y pair of axes to the receiver <see cref="ControllerDefinition"/>, and returns it.
 /// The new axes will appear after any that were previously defined.
 /// </summary>
 /// <param name="nameFormat">format string e.g. <c>"P1 Left {0}"</c> (will be used to interpolate <c>"X"</c> and <c>"Y"</c>)</param>
 /// <returns>identical reference to <paramref name="def"/>; the object is mutated</returns>
 public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range <int> rangeBoth, int neutralBoth, AxisConstraint constraint = null)
 => def.AddXYPair(nameFormat, pDir, rangeBoth, neutralBoth, rangeBoth, neutralBoth, constraint);
Esempio n. 20
0
		public MovieZone(string fileName)
		{
			if (!File.Exists(fileName))
				return;

			string[] readText = File.ReadAllLines(fileName);
			// If the LogKey contains buttons/controls not accepted by the emulator,
			//	tell the user and display the macro's controller name and player count
			_inputKey = readText[0];
			Bk2LogEntryGenerator lg = Global.MovieSession.LogGeneratorInstance() as Bk2LogEntryGenerator;
			lg.SetSource(Global.MovieSession.MovieControllerAdapter);
			string key = lg.GenerateLogKey();
			key = key.Replace("LogKey:", "").Replace("#", "");
			key = key.Substring(0, key.Length - 1);
			string[] emuKeys = key.Split('|');
			string[] macroKeys = _inputKey.Split('|');
			for (int i = 0; i < macroKeys.Length; i++)
			{
				if (!emuKeys.Contains(macroKeys[i]))
				{
					System.Windows.Forms.MessageBox.Show("The selected macro is not compatible with the current emulator core." +
						"\nMacro controller: " + readText[1] + "\nMacro player count: " + readText[2], "Error");
					return;
				}
			}

			// Settings
			string[] settings = readText[3].Split(',');
			Overlay = Convert.ToBoolean(settings[0]);
			Replace = Convert.ToBoolean(settings[1]);

			_log = new string[readText.Length - 4];
			readText.ToList().CopyTo(4, _log, 0, _log.Length);
			Length = _log.Length;
			Start = 0;

			Name = Path.GetFileNameWithoutExtension(fileName);

			// Adapters
			targetController = new Bk2ControllerAdapter();
			targetController.Type = Global.Emulator.ControllerDefinition;
			targetController.LatchFromSource(targetController); // Reference and create all buttons
			string[] keys = _inputKey.Split('|');
			ControllerDefinition d = new ControllerDefinition();
			for (int i = 0; i < keys.Length; i++)
			{
				if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(keys[i]))
					d.BoolButtons.Add(keys[i]);
				else
					d.FloatControls.Add(keys[i]);
			}
			controller = new Bk2ControllerAdapter() { Type = d };
		}
Esempio n. 21
0
 public SaveController(ControllerDefinition def)
 {
     Definition = def;
 }
Esempio n. 22
0
 /// <summary>
 /// Adds an X/Y/Z triple of axes to the receiver <see cref="ControllerDefinition"/>, and returns it.
 /// The new axes will appear after any that were previously defined.
 /// </summary>
 /// <param name="nameFormat">format string e.g. <c>"P1 Tilt {0}"</c> (will be used to interpolate <c>"X"</c>, <c>"Y"</c>, and <c>"Z"</c>)</param>
 /// <returns>identical reference to <paramref name="def"/>; the object is mutated</returns>
 public static ControllerDefinition AddXYZTriple(this ControllerDefinition def, string nameFormat, Range <int> rangeAll, int neutralAll)
 => def.AddAxis(string.Format(nameFormat, "X"), rangeAll, neutralAll)
 .AddAxis(string.Format(nameFormat, "Y"), rangeAll, neutralAll)
 .AddAxis(string.Format(nameFormat, "Z"), rangeAll, neutralAll);
Esempio n. 23
0
		public Atari7800Control(MachineBase mac)
		{
			var l = mac.InputState.LeftControllerJack;
			var r = mac.InputState.RightControllerJack;

			foreach (var a in Adapters)
			{
				if (a.Left == l && a.Right == r)
				{
					Convert = a.Convert;
					ControlType = a.Type;
					return;
				}
			}
			throw new Exception(string.Format("Couldn't connect Atari 7800 controls \"{0}\" and \"{1}\"", l.ToString(), r.ToString()));
		}
Esempio n. 24
0
		public AutofireController(ControllerDefinition definition, IEmulator emulator)
		{
			On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn;
			Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff;
			_type = definition;
			_emulator = emulator;
		}