diff --git a/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs b/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs index a1ef204cc0..57fdcd6fc4 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs @@ -7,9 +7,13 @@ using BizHawk.Emulation.Sound; namespace BizHawk.Emulation.Consoles.Sega { - [CoreVersion("0.0.0.1", FriendlyName = "MegaHawk")] - public sealed partial class Genesis : IEmulator + [CoreVersion("0.0.0.1", FriendlyName = "MegaHawk")] + public sealed partial class Genesis : IEmulator { + private int _lagcount = 0; + private bool lagged = true; + private bool islag = false; + // ROM public byte[] RomData; @@ -78,16 +82,18 @@ namespace BizHawk.Emulation.Consoles.Sega SoundCPU.ReadHardware = x => 0xFF; SoundCPU.IRQCallback = () => SoundCPU.Interrupt = false; Z80Reset = true; - RomData = new byte[0x400000]; - for (int i = 0; i < rom.Length; i++) - RomData[i] = rom[i]; + RomData = new byte[0x400000]; + for (int i = 0; i < rom.Length; i++) + RomData[i] = rom[i]; - SetupMemoryDomains(); - MainCPU.Reset(); + SetupMemoryDomains(); + MainCPU.Reset(); } public void FrameAdvance(bool render) { + lagged = true; + Frame++; PSG.BeginFrame(SoundCPU.TotalExecutedCycles); for (VDP.ScanLine = 0; VDP.ScanLine < 262; VDP.ScanLine++) @@ -96,7 +102,7 @@ namespace BizHawk.Emulation.Consoles.Sega if (VDP.ScanLine < 224) VDP.RenderLine(); - + MainCPU.ExecuteCycles(487); // 488?? if (Z80Runnable) { @@ -107,7 +113,7 @@ namespace BizHawk.Emulation.Consoles.Sega if (VDP.ScanLine == 224) { - MainCPU.ExecuteCycles(16);// stupid crap to sync with genesis plus for log testing + MainCPU.ExecuteCycles(16);// stupid crap to sync with genesis plus for log testing // End-frame stuff if (VDP.VInterruptEnabled) MainCPU.Interrupt = 6; @@ -117,6 +123,15 @@ namespace BizHawk.Emulation.Consoles.Sega } } PSG.EndFrame(SoundCPU.TotalExecutedCycles); + + Controller.UpdateControls(Frame++); + if (lagged) + { + _lagcount++; + islag = true; + } + else + islag = false; } public CoreInputComm CoreInputComm { get; set; } @@ -133,8 +148,8 @@ namespace BizHawk.Emulation.Consoles.Sega } public int Frame { get; set; } - public int LagCount { get { return -1; } set { return; } } //TODO: Implement - public bool IsLagFrame { get { return false; } } + public int LagCount { get { return _lagcount; } set { _lagcount = value; } } + public bool IsLagFrame { get { return islag; } } public bool DeterministicEmulation { get; set; } public string SystemId { get { return "GEN"; } } @@ -180,30 +195,30 @@ namespace BizHawk.Emulation.Consoles.Sega return new byte[0]; } - IList memoryDomains; + IList memoryDomains; - void SetupMemoryDomains() - { - var domains = new List(3); - var MainMemoryDomain = new MemoryDomain("68000 RAM", Ram.Length, Endian.Big, - addr => Ram[addr & 0xFFFF], - (addr, value) => Ram[addr & 0xFFFF] = value); - var Z80Domain = new MemoryDomain("Z80 RAM", Z80Ram.Length, Endian.Little, - addr => Z80Ram[addr & 0x1FFF], - (addr, value) => { Z80Ram[addr & 0x1FFF] = value; }); + void SetupMemoryDomains() + { + var domains = new List(3); + var MainMemoryDomain = new MemoryDomain("68000 RAM", Ram.Length, Endian.Big, + addr => Ram[addr & 0xFFFF], + (addr, value) => Ram[addr & 0xFFFF] = value); + var Z80Domain = new MemoryDomain("Z80 RAM", Z80Ram.Length, Endian.Little, + addr => Z80Ram[addr & 0x1FFF], + (addr, value) => { Z80Ram[addr & 0x1FFF] = value; }); - var VRamDomain = new MemoryDomain("Video RAM", VDP.VRAM.Length, Endian.Big, - addr => VDP.VRAM[addr & 0xFFFF], - (addr, value) => VDP.VRAM[addr & 0xFFFF] = value); + var VRamDomain = new MemoryDomain("Video RAM", VDP.VRAM.Length, Endian.Big, + addr => VDP.VRAM[addr & 0xFFFF], + (addr, value) => VDP.VRAM[addr & 0xFFFF] = value); - domains.Add(MainMemoryDomain); - domains.Add(Z80Domain); - domains.Add(VRamDomain); - memoryDomains = domains.AsReadOnly(); - } + domains.Add(MainMemoryDomain); + domains.Add(Z80Domain); + domains.Add(VRamDomain); + memoryDomains = domains.AsReadOnly(); + } - public IList MemoryDomains { get { return memoryDomains; } } - public MemoryDomain MainMemory { get { return memoryDomains[0]; } } + public IList MemoryDomains { get { return memoryDomains; } } + public MemoryDomain MainMemory { get { return memoryDomains[0]; } } public void Dispose() { } } diff --git a/BizHawk.Emulation/Consoles/Sega/Genesis/Input.cs b/BizHawk.Emulation/Consoles/Sega/Genesis/Input.cs index e1eb55ce85..14e7746d97 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/Input.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/Input.cs @@ -1,18 +1,18 @@ namespace BizHawk.Emulation.Consoles.Sega { - partial class Genesis - { - public static readonly ControllerDefinition GenesisController = new ControllerDefinition - { - Name = "Genesis 3-Button Controller", - BoolButtons = - { - "Reset", - "P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 A", "P1 B", "P1 C", "P1 Start" - } - }; + partial class Genesis + { + public static readonly ControllerDefinition GenesisController = new ControllerDefinition + { + Name = "Genesis 3-Button Controller", + BoolButtons = + { + "Reset", + "P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 A", "P1 B", "P1 C", "P1 Start" + } + }; - public ControllerDefinition ControllerDefinition { get { return GenesisController; } } - public IController Controller { get; set; } - } + public ControllerDefinition ControllerDefinition { get { return GenesisController; } } + public IController Controller { get; set; } + } } \ No newline at end of file diff --git a/BizHawk.MultiClient/Config.cs b/BizHawk.MultiClient/Config.cs index e4435c1dc1..dea685ac8b 100644 --- a/BizHawk.MultiClient/Config.cs +++ b/BizHawk.MultiClient/Config.cs @@ -17,6 +17,9 @@ NESController[3] = new NESControllerTemplate(false); GameBoyController = new NESControllerTemplate(true); TI83Controller[0] = new TI83ControllerTemplate(true); + + GenesisController[0] = new GenControllerTemplate(true); + GenesisAutoController[0] = new GenControllerTemplate(true); NESAutoController[0] = new NESControllerTemplate(false); NESAutoController[1] = new NESControllerTemplate(false); @@ -443,8 +446,8 @@ public PCEControllerTemplate[] PCEAutoController = new PCEControllerTemplate[5]; // Genesis Settings - public GenControllerTemplate GenesisController = new GenControllerTemplate(true); - public GenControllerTemplate GenesisAutoController = new GenControllerTemplate(); + public GenControllerTemplate[] GenesisController = new GenControllerTemplate[1]; + public GenControllerTemplate[] GenesisAutoController = new GenControllerTemplate[1]; //GameBoy Settings public NESControllerTemplate GameBoyController = new NESControllerTemplate(true); @@ -621,33 +624,35 @@ } } - public class GenControllerTemplate - { - public string Up = ""; - public string Down = ""; - public string Left = ""; - public string Right = ""; - public string A = ""; - public string B = ""; - public string C = ""; - public string Start = ""; + public class GenControllerTemplate + { + public string Up = ""; + public string Down = ""; + public string Left = ""; + public string Right = ""; + public string A = ""; + public string B = ""; + public string C = ""; + public string Start = ""; + public bool Enabled; - public GenControllerTemplate() { } - public GenControllerTemplate(bool defaults) - { - if (defaults) - { - Up = "UpArrow, J1 Up"; - Down = "DownArrow, J1 Down"; - Left = "LeftArrow, J1 Left"; - Right = "RightArrow, J1 Right"; - A = "Z, J1 B1"; - B = "X, J1 B3"; - C = "C, J1 B4"; - Start = "Return, J1 B8"; - } - } - } + public GenControllerTemplate() { } + public GenControllerTemplate(bool defaults) + { + if (defaults) + { + Enabled = true; + Up = "UpArrow, J1 Up"; + Down = "DownArrow, J1 Down"; + Left = "LeftArrow, J1 Left"; + Right = "RightArrow, J1 Right"; + A = "Z, J1 B1"; + B = "X, J1 B3"; + C = "C, J1 B4"; + Start = "Return, J1 B8"; + } + } + } public class TI83ControllerTemplate { diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 37bed92adf..720eeb9ec9 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -634,26 +634,26 @@ namespace BizHawk.MultiClient Global.AutofireGBControls = agbControls; var genControls = new Controller(Genesis.GenesisController); - genControls.BindMulti("P1 Up", Global.Config.GenesisController.Up); - genControls.BindMulti("P1 Left", Global.Config.GenesisController.Left); - genControls.BindMulti("P1 Right", Global.Config.GenesisController.Right); - genControls.BindMulti("P1 Down", Global.Config.GenesisController.Down); - genControls.BindMulti("P1 A", Global.Config.GenesisController.A); - genControls.BindMulti("P1 B", Global.Config.GenesisController.B); - genControls.BindMulti("P1 C", Global.Config.GenesisController.C); - genControls.BindMulti("P1 Start", Global.Config.GenesisController.Start); + genControls.BindMulti("P1 Up", Global.Config.GenesisController[0].Up); + genControls.BindMulti("P1 Left", Global.Config.GenesisController[0].Left); + genControls.BindMulti("P1 Right", Global.Config.GenesisController[0].Right); + genControls.BindMulti("P1 Down", Global.Config.GenesisController[0].Down); + genControls.BindMulti("P1 A", Global.Config.GenesisController[0].A); + genControls.BindMulti("P1 B", Global.Config.GenesisController[0].B); + genControls.BindMulti("P1 C", Global.Config.GenesisController[0].C); + genControls.BindMulti("P1 Start", Global.Config.GenesisController[0].Start); Global.GenControls = genControls; var agenControls = new AutofireController(Genesis.GenesisController); agbControls.Autofire = true; - genControls.BindMulti("P1 Up", Global.Config.GenesisAutoController.Up); - genControls.BindMulti("P1 Left", Global.Config.GenesisAutoController.Left); - genControls.BindMulti("P1 Right", Global.Config.GenesisAutoController.Right); - genControls.BindMulti("P1 Down", Global.Config.GenesisAutoController.Down); - genControls.BindMulti("P1 A", Global.Config.GenesisAutoController.A); - genControls.BindMulti("P1 B", Global.Config.GenesisAutoController.B); - genControls.BindMulti("P1 C", Global.Config.GenesisAutoController.C); - genControls.BindMulti("P1 Start", Global.Config.GenesisAutoController.Start); + genControls.BindMulti("P1 Up", Global.Config.GenesisAutoController[0].Up); + genControls.BindMulti("P1 Left", Global.Config.GenesisAutoController[0].Left); + genControls.BindMulti("P1 Right", Global.Config.GenesisAutoController[0].Right); + genControls.BindMulti("P1 Down", Global.Config.GenesisAutoController[0].Down); + genControls.BindMulti("P1 A", Global.Config.GenesisAutoController[0].A); + genControls.BindMulti("P1 B", Global.Config.GenesisAutoController[0].B); + genControls.BindMulti("P1 C", Global.Config.GenesisAutoController[0].C); + genControls.BindMulti("P1 Start", Global.Config.GenesisAutoController[0].Start); Global.AutofireGenControls = agenControls; var TI83Controls = new Controller(TI83.TI83Controller); diff --git a/BizHawk.MultiClient/config/InputConfig.cs b/BizHawk.MultiClient/config/InputConfig.cs index 4ef4de771f..9320c868ac 100644 --- a/BizHawk.MultiClient/config/InputConfig.cs +++ b/BizHawk.MultiClient/config/InputConfig.cs @@ -20,7 +20,7 @@ namespace BizHawk.MultiClient const string ControllerStr = "Configure Controllers - "; public static string[] SMSControlList = new string[] { "Up", "Down", "Left", "Right", "B1", "B2", "Pause", "Reset" }; public static string[] PCEControlList = new string[] { "Up", "Down", "Left", "Right", "I", "II", "Run", "Select" }; - public static string[] GenesisControlList = new string[] { "Up", "Down", "Left", "Right", "A", "B", "C", "Start", "X,T,0", "Y=", "Z" }; + public static string[] GenesisControlList = new string[] { "Up", "Down", "Left", "Right", "A", "B", "C", "Start", }; public static string[] NESControlList = new string[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start" }; public static string[] TI83ControlList = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "ON", "ENTER", "Up", "Down", "Left", "Right", "+", "-", "Multiply", "Divide", "CLEAR", "^", "-", "(", ")", "TAN", "VARS", @@ -309,8 +309,80 @@ namespace BizHawk.MultiClient private void DoGen() { + Label TempLabel; + InputWidget TempTextBox; this.Text = ControllerStr + "Sega Genesis"; ControllerImage.Image = BizHawk.MultiClient.Properties.Resources.GENController; + int jpad = this.ControllComboBox.SelectedIndex; + string[] ButtonMappings = new string[GenesisControlList.Length]; + ButtonMappings[0] = Global.Config.GenesisController[0].Up; + ButtonMappings[1] = Global.Config.GenesisController[0].Down; + ButtonMappings[2] = Global.Config.GenesisController[0].Left; + ButtonMappings[3] = Global.Config.GenesisController[0].Right; + ButtonMappings[4] = Global.Config.GenesisController[0].A; + ButtonMappings[5] = Global.Config.GenesisController[0].B; + ButtonMappings[6] = Global.Config.GenesisController[0].C; + ButtonMappings[7] = Global.Config.GenesisController[0].Start; + + IDX_CONTROLLERENABLED.Checked = Global.Config.GenesisController[0].Enabled; + Changed = true; + Labels.Clear(); + TextBoxes.Clear(); + + for (int i = 0; i < GenesisControlList.Length; i++) + { + TempLabel = new Label(); + TempLabel.Text = GenesisControlList[i]; + TempLabel.Location = new Point(8, 20 + (i * 24)); + Labels.Add(TempLabel); + TempTextBox = new InputWidget(); + TempTextBox.Location = new Point(48, 20 + (i * 24)); + TextBoxes.Add(TempTextBox); + TempTextBox.SetBindings(ButtonMappings[i]); + ButtonsGroupBox.Controls.Add(TempTextBox); + ButtonsGroupBox.Controls.Add(TempLabel); + } + Changed = true; + + } + + private void UpdateGen(int prev) + { + ButtonsGroupBox.Controls.Clear(); + InputWidget TempBox; + Label TempLabel; + + TempBox = TextBoxes[0] as InputWidget; + Global.Config.GenesisController[0].Up = AppendButtonMapping(TempBox.Text, Global.Config.PCEController[prev].Up); + TempBox.Dispose(); + TempBox = TextBoxes[1] as InputWidget; + Global.Config.GenesisController[0].Down = AppendButtonMapping(TempBox.Text, Global.Config.PCEController[prev].Down); + TempBox.Dispose(); + TempBox = TextBoxes[2] as InputWidget; + Global.Config.GenesisController[0].Left = AppendButtonMapping(TempBox.Text, Global.Config.PCEController[prev].Left); + TempBox.Dispose(); + TempBox = TextBoxes[3] as InputWidget; + Global.Config.GenesisController[0].Right = AppendButtonMapping(TempBox.Text, Global.Config.PCEController[prev].Right); + TempBox.Dispose(); + TempBox = TextBoxes[4] as InputWidget; + Global.Config.GenesisController[0].A = AppendButtonMapping(TempBox.Text, Global.Config.PCEController[prev].I); + TempBox.Dispose(); + TempBox = TextBoxes[5] as InputWidget; + Global.Config.GenesisController[0].B = AppendButtonMapping(TempBox.Text, Global.Config.PCEController[prev].II); + TempBox.Dispose(); + TempBox = TextBoxes[6] as InputWidget; + Global.Config.GenesisController[0].C = AppendButtonMapping(TempBox.Text, Global.Config.PCEController[prev].Run); + TempBox.Dispose(); + TempBox = TextBoxes[7] as InputWidget; + Global.Config.GenesisController[0].Start = AppendButtonMapping(TempBox.Text, Global.Config.PCEController[prev].Select); + TempBox.Dispose(); + Global.Config.GenesisController[0].Enabled = IDX_CONTROLLERENABLED.Checked; + + for (int i = 0; i < GenesisControlList.Length; i++) + { + TempLabel = Labels[i] as Label; + TempLabel.Dispose(); + } } private void DoTI83()