diff --git a/BizHawk.Client.Common/movie/import/MovieImport.cs b/BizHawk.Client.Common/movie/import/MovieImport.cs index 94059338f6..2bed3b7826 100644 --- a/BizHawk.Client.Common/movie/import/MovieImport.cs +++ b/BizHawk.Client.Common/movie/import/MovieImport.cs @@ -199,6 +199,8 @@ namespace BizHawk.Client.Common errorMsg = except.ToString(); } + m.Filename += "." + BkmMovie.Extension; + return m; } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs index d59a8b82e5..1b00ba1d3c 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs @@ -335,6 +335,8 @@ namespace BizHawk.Client.Common var minuend = Math.Min(lastFrame + 1, movie.InputLogLength); if (firstFrame > minuend) undoLength = minuend; + else if (firstFrame == minuend) + undoLength = Math.Max(lastFrame + 1, movie.InputLogLength) - firstFrame; else undoLength = minuend - firstFrame; diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 1bec1774b1..aa2037a39c 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -85,6 +85,7 @@ namespace BizHawk.Client.Common public TasMovieMarkerList Markers { get; set; } public bool BindMarkersToInput { get; set; } public bool UseInputCache { get; set; } + public bool LastPositionStable = true; public string NewBranchText = ""; public int CurrentBranch { get; set; } public int BranchCount { get { return Branches.Count; } } @@ -310,12 +311,18 @@ namespace BizHawk.Client.Common public void GreenzoneCurrentFrame() { - LagLog[Global.Emulator.Frame] = Global.Emulator.AsInputPollable().IsLagFrame; + if (Global.Emulator.Frame > LastValidFrame) + { + // emulated a new frame, current editing segment may change now. taseditor logic + LastPositionStable = false; + } - if (!StateManager.HasState(Global.Emulator.Frame)) - { - StateManager.Capture(); - } + LagLog[Global.Emulator.Frame] = Global.Emulator.AsInputPollable().IsLagFrame; + + if (!StateManager.HasState(Global.Emulator.Frame)) + { + StateManager.Capture(); + } } public void ClearLagLog() diff --git a/BizHawk.Client.EmuHawk/Extensions/ToolExtensions.cs b/BizHawk.Client.EmuHawk/Extensions/ToolExtensions.cs index be6f7dc225..5f9d3d4832 100644 --- a/BizHawk.Client.EmuHawk/Extensions/ToolExtensions.cs +++ b/BizHawk.Client.EmuHawk/Extensions/ToolExtensions.cs @@ -221,7 +221,8 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions } else { - var result = MessageBox.Show("Could not open " + path + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error); + // ensure topmost, not to have to minimize everything to see and use our modal window, if it somehow got covered + var result = MessageBox.Show(new Form(){TopMost = true},"Could not open " + path + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (result == DialogResult.Yes) { if (encodedPath != null) diff --git a/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs b/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs index fd361818c8..c5fd91a6c2 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs @@ -14,10 +14,6 @@ namespace BizHawk.Client.EmuHawk // General case "Pause": - // check this here since TogglePause() has no idea who triggered it - // and we need to treat pause hotkey specially in tastudio - if (GlobalWin.MainForm.EmulatorPaused && GlobalWin.Tools.IsLoaded()) - GlobalWin.Tools.TAStudio.IgnoreSeekFrame = true; TogglePause(); break; case "Toggle Throttle": diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index f5a8fbf3f7..582c2bb2f1 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -607,7 +607,8 @@ namespace BizHawk.Client.EmuHawk public LoadRomArgs CurrentlyOpenRomArgs; public bool PauseAVI = false; public bool PressFrameAdvance = false; - public bool PressRewind = false; + public bool HoldFrameAdvance = false; // necessary for tastudio > button + public bool PressRewind = false; // necessary for tastudio < button public bool FastForward = false; public bool TurboFastForward = false; public bool RestoreReadWriteOnStop = false; @@ -2678,7 +2679,7 @@ namespace BizHawk.Client.EmuHawk runFrame = true; } - if (Global.ClientControls["Frame Advance"] || PressFrameAdvance) + if (Global.ClientControls["Frame Advance"] || PressFrameAdvance || HoldFrameAdvance) { // handle the initial trigger of a frame advance if (_frameAdvanceTimestamp == 0) @@ -2687,8 +2688,6 @@ namespace BizHawk.Client.EmuHawk runFrame = true; _runloopFrameadvance = true; _frameAdvanceTimestamp = currentTimestamp; - if (GlobalWin.Tools.IsLoaded()) - GlobalWin.Tools.TAStudio.IgnoreSeekFrame = false; } else { @@ -2864,6 +2863,16 @@ namespace BizHawk.Client.EmuHawk UpdateToolsAfter(); } + if (GlobalWin.Tools.IsLoaded() && + GlobalWin.Tools.TAStudio.LastPositionFrame == Global.Emulator.Frame) + { + TasMovieRecord record = (Global.MovieSession.Movie as TasMovie)[Global.Emulator.Frame]; + if (!record.Lagged.HasValue && IsSeeking) + // haven't yet greenzoned the frame, hence it's after editing + // then we want to pause here. taseditor fasion + PauseEmulator(); + } + if (IsSeeking && Global.Emulator.Frame == PauseOnFrame.Value) { PauseEmulator(); @@ -2882,7 +2891,7 @@ namespace BizHawk.Client.EmuHawk if (Global.ClientControls["Rewind"] || PressRewind) { UpdateToolsAfter(); - PressRewind = false; + //PressRewind = false; } if (UpdateFrame) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs index e23924fc39..b28f720227 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs @@ -94,6 +94,14 @@ namespace BizHawk.Client.EmuHawk EmulatorLuaLibrary.YieldCallback = EmuYield; } + public void Restart() + { + foreach (var lib in Libraries) + { + ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, lib.Value); + } + } + public LuaDocumentation Docs { get; private set; } public bool IsRunning { get; set; } public EventWaitHandle LuaWait { get; private set; } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index ac8482ffff..c5471b4e7e 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -135,6 +135,13 @@ namespace BizHawk.Client.EmuHawk public void Restart() { + // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies + if (IsRebootingCore) + { + LuaImp.Restart(); + return; + } + if (LuaImp != null && LuaImp.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface) { LuaImp.GuiLibrary.DrawFinish(); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.Designer.cs index 315e2f2284..dade7783ff 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.Designer.cs @@ -126,7 +126,9 @@ this.FrameAdvanceButton.TabIndex = 3; this.FrameAdvanceButton.Text = ">"; this.FrameAdvanceButton.UseVisualStyleBackColor = true; - this.FrameAdvanceButton.Click += new System.EventHandler(this.FrameAdvanceButton_Click); + this.FrameAdvanceButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.FrameAdvanceButton_MouseDown); + this.FrameAdvanceButton.MouseLeave += new System.EventHandler(this.FrameAdvanceButton_MouseLeave); + this.FrameAdvanceButton.MouseUp += new System.Windows.Forms.MouseEventHandler(this.FrameAdvanceButton_MouseUp); // // PauseButton // @@ -148,7 +150,9 @@ this.RewindButton.TabIndex = 1; this.RewindButton.Text = "<"; this.RewindButton.UseVisualStyleBackColor = true; - this.RewindButton.Click += new System.EventHandler(this.RewindButton_Click); + this.RewindButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.RewindButton_MouseDown); + this.RewindButton.MouseLeave += new System.EventHandler(this.RewindButton_MouseLeave); + this.RewindButton.MouseUp += new System.Windows.Forms.MouseEventHandler(this.RewindButton_MouseUp); // // PreviousMarkerButton // diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.cs index 915484a313..82c3d9cf39 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.cs @@ -115,45 +115,11 @@ namespace BizHawk.Client.EmuHawk Tastudio.GoToPreviousMarker(); } - private void RewindButton_Click(object sender, EventArgs e) - { - if (GlobalWin.MainForm.IsSeeking) - { - GlobalWin.MainForm.PauseOnFrame--; - if (Global.Emulator.Frame == GlobalWin.MainForm.PauseOnFrame) - { - GlobalWin.MainForm.PauseEmulator(); - GlobalWin.MainForm.PauseOnFrame = null; - Tastudio.StopSeeking(); - } - Tastudio.RefreshDialog(); - } - else - { - Tastudio.GoToPreviousFrame(); - } - } - private void PauseButton_Click(object sender, EventArgs e) { - if (GlobalWin.MainForm.EmulatorPaused) - Tastudio.IgnoreSeekFrame = true; Tastudio.TogglePause(); } - private void FrameAdvanceButton_Click(object sender, EventArgs e) - { - if (GlobalWin.MainForm.IsSeeking) - { - GlobalWin.MainForm.PauseOnFrame++; - Tastudio.RefreshDialog(); - } - else - { - Tastudio.GoToNextFrame(); - } - } - private void NextMarkerButton_Click(object sender, EventArgs e) { Tastudio.GoToNextMarker(); @@ -193,5 +159,37 @@ namespace BizHawk.Client.EmuHawk { RecordingMode ^= true; } + + private void RewindButton_MouseDown(object sender, MouseEventArgs e) + { + GlobalWin.MainForm.PressRewind = true; + } + + private void RewindButton_MouseUp(object sender, MouseEventArgs e) + { + GlobalWin.MainForm.PressRewind = false; + } + + private void RewindButton_MouseLeave(object sender, EventArgs e) + { + GlobalWin.MainForm.PressRewind = false; + } + + private void FrameAdvanceButton_MouseDown(object sender, MouseEventArgs e) + { + GlobalWin.MainForm.HoldFrameAdvance = true; + } + + private void FrameAdvanceButton_MouseLeave(object sender, EventArgs e) + { + GlobalWin.MainForm.HoldFrameAdvance = false; + } + + private void FrameAdvanceButton_MouseUp(object sender, MouseEventArgs e) + { + GlobalWin.MainForm.HoldFrameAdvance = false; + } + + } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs index 0b0605edb3..2ecc788c54 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs @@ -78,21 +78,24 @@ namespace BizHawk.Client.EmuHawk public bool Rewind() { - //if (GlobalWin.MainForm.IsSeeking) - //{ - // GlobalWin.MainForm.PauseOnFrame--; - // if (Emulator.Frame == GlobalWin.MainForm.PauseOnFrame) - // { - // GlobalWin.MainForm.PauseEmulator(); - // GlobalWin.MainForm.PauseOnFrame = null; - // StopSeeking(); - // } - // RefreshDialog(); - //} - //else - //{ + // copypasted from TasView_MouseWheel(), just without notch logic + if (Mainform.IsSeeking) + { + Mainform.PauseOnFrame--; + // that's a weird condition here, but for whatever reason it works best + if (Emulator.Frame >= Mainform.PauseOnFrame) + { + Mainform.PauseEmulator(); + Mainform.PauseOnFrame = null; + StopSeeking(); + GoToPreviousFrame(); + } + RefreshDialog(); + } + else + { GoToPreviousFrame(); - //} + } return true; } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs index a9cc1f74eb..9b848f5069 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs @@ -100,7 +100,6 @@ namespace BizHawk.Client.EmuHawk return true; } - IgnoreSeekFrame = false; // don't unpause StopSeeking(); if (CurrentTasMovie != null && CurrentTasMovie.Changes) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index 810ef6c8e3..d1b35b139e 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -62,29 +62,25 @@ namespace BizHawk.Client.EmuHawk { if (_autoRestorePaused == null) { - _autoRestorePaused = GlobalWin.MainForm.EmulatorPaused; - if (GlobalWin.MainForm.IsSeeking) // If seeking, do not shorten seek. - _autoRestoreFrame = GlobalWin.MainForm.PauseOnFrame; + _autoRestorePaused = Mainform.EmulatorPaused; + if (Mainform.IsSeeking) // If seeking, do not shorten seek. + _autoRestoreFrame = Mainform.PauseOnFrame; } GoToLastEmulatedFrameIfNecessary(CurrentTasMovie.LastValidFrame); - StartSeeking(_autoRestoreFrame, true); } } - private void StartSeeking(int? frame, bool pause = false) + private void StartSeeking(int? frame) { if (!frame.HasValue) return; _seekStartFrame = Emulator.Frame; - GlobalWin.MainForm.PauseOnFrame = frame.Value; - int? diff = GlobalWin.MainForm.PauseOnFrame - _seekStartFrame; + Mainform.PauseOnFrame = frame.Value; + int? diff = Mainform.PauseOnFrame - _seekStartFrame; - if (pause) - GlobalWin.MainForm.PauseEmulator(); - else - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); if (!_seekBackgroundWorker.IsBusy && diff.Value > TasView.VisibleRows) _seekBackgroundWorker.RunWorkerAsync(); @@ -98,11 +94,6 @@ namespace BizHawk.Client.EmuHawk TastudioRecordMode(); _wasRecording = false; } - if (IgnoreSeekFrame) - { - GlobalWin.MainForm.UnpauseEmulator(); - IgnoreSeekFrame = false; - } } public bool FloatEditingMode @@ -111,7 +102,8 @@ namespace BizHawk.Client.EmuHawk } // public static Color CurrentFrame_FrameCol = Color.FromArgb(0xCFEDFC); Why? - public static Color CurrentFrame_InputLog = Color.FromArgb(0xB5E7F7); + public static Color CurrentFrame_InputLog = Color.FromArgb(0x00B5E7F7); + public static Color SeekFrame_InputLog = Color.FromArgb(0x70B5E7F7); public static Color GreenZone_FrameCol = Color.FromArgb(0xDDFFDD); public static Color GreenZone_InputLog = Color.FromArgb(0xD2F9D3); @@ -159,7 +151,7 @@ namespace BizHawk.Client.EmuHawk if (columnName == CursorColumnName) { - if (index == Emulator.Frame && index == GlobalWin.MainForm.PauseOnFrame) + if (index == Emulator.Frame && index == Mainform.PauseOnFrame) { bitmap = TasView.HorizontalOrientation ? ts_v_arrow_green_blue : @@ -171,7 +163,7 @@ namespace BizHawk.Client.EmuHawk ts_v_arrow_blue : ts_h_arrow_blue; } - else if (index == GlobalWin.MainForm.PauseOnFrame) + else if (index == LastPositionFrame) { bitmap = TasView.HorizontalOrientation ? ts_v_arrow_green : @@ -227,11 +219,16 @@ namespace BizHawk.Client.EmuHawk if (player != 0 && player % 2 == 0) color = Color.FromArgb(0x0D000000); } + private void TasView_QueryRowBkColor(int index, ref Color color) { TasMovieRecord record = CurrentTasMovie[index]; - if (Emulator.Frame == index) + if (Mainform.IsSeeking && Mainform.PauseOnFrame == index) + { + color = CurrentFrame_InputLog; + } + else if (!Mainform.IsSeeking && Emulator.Frame == index) { color = CurrentFrame_InputLog; } @@ -404,9 +401,18 @@ namespace BizHawk.Client.EmuHawk if (e.Button == MouseButtons.Middle) { - if (GlobalWin.MainForm.EmulatorPaused) - IgnoreSeekFrame = false; - TogglePause(); + if (Mainform.EmulatorPaused) + { + TasMovieRecord record = CurrentTasMovie[LastPositionFrame]; + if (!record.Lagged.HasValue && LastPositionFrame > Global.Emulator.Frame) + StartSeeking(LastPositionFrame); + else + Mainform.UnpauseEmulator(); + } + else + { + Mainform.PauseEmulator(); + } return; } @@ -420,6 +426,7 @@ namespace BizHawk.Client.EmuHawk if (e.Button == MouseButtons.Left) { + bool wasHeld = _leftButtonHeld; _leftButtonHeld = true; // SuuperW: Exit float editing mode, or re-enter mouse editing if (_floatEditRow != -1) @@ -459,7 +466,17 @@ namespace BizHawk.Client.EmuHawk } else // User changed input { - bool wasPaused = GlobalWin.MainForm.EmulatorPaused; + bool wasPaused = Mainform.EmulatorPaused; + + if (Emulator.Frame > frame || CurrentTasMovie.LastValidFrame > frame) + { + if (wasPaused && !Mainform.IsSeeking && !CurrentTasMovie.LastPositionStable) + { + LastPositionFrame = Emulator.Frame; + CurrentTasMovie.LastPositionStable = true; // until new frame is emulated + } + } + if (Global.MovieSession.MovieControllerAdapter.Type.BoolButtons.Contains(buttonName)) { CurrentTasMovie.ChangeLog.BeginNewBatch("Paint Bool " + buttonName + " from frame " + frame); @@ -533,10 +550,7 @@ namespace BizHawk.Client.EmuHawk // taseditor behavior if (!wasPaused) - GlobalWin.MainForm.UnpauseEmulator(); - - if (!Settings.AutoRestoreLastPosition) - IgnoreSeekFrame = true; + Mainform.UnpauseEmulator(); } } else if (e.Button == System.Windows.Forms.MouseButtons.Right) @@ -653,20 +667,20 @@ namespace BizHawk.Client.EmuHawk { _supressContextMenu = true; int notch = e.Delta / 120; + if (notch > 1) + notch *= 2; - if (GlobalWin.MainForm.IsSeeking) + // warning: tastudio rewind hotkey/button logic is copypasted from here! + if (Mainform.IsSeeking && !Mainform.EmulatorPaused) { - if (e.Delta < 0) - GlobalWin.MainForm.PauseOnFrame++; - else + Mainform.PauseOnFrame -= notch; + // that's a weird condition here, but for whatever reason it works best + if (notch > 0 && Global.Emulator.Frame >= Mainform.PauseOnFrame) { - GlobalWin.MainForm.PauseOnFrame--; - if (Global.Emulator.Frame == GlobalWin.MainForm.PauseOnFrame) - { - GlobalWin.MainForm.PauseEmulator(); - GlobalWin.MainForm.PauseOnFrame = null; - StopSeeking(); - } + Mainform.PauseEmulator(); + Mainform.PauseOnFrame = null; + StopSeeking(); + GoToFrame(Emulator.Frame - notch); } RefreshDialog(); } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 9957ac3051..1bd8be02f4 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -41,7 +41,7 @@ namespace BizHawk.Client.EmuHawk private void NewTasMenuItem_Click(object sender, EventArgs e) { - if (GlobalWin.MainForm.GameIsClosing) + if (Mainform.GameIsClosing) { Close(); } @@ -387,7 +387,7 @@ namespace BizHawk.Client.EmuHawk // TODO: if highlighting 2 rows and pasting 3, only paste 2 of them // FCEUX Taseditor does't do this, but I think it is the expected behavior in editor programs - var wasPaused = GlobalWin.MainForm.EmulatorPaused; + var wasPaused = Mainform.EmulatorPaused; if (_tasClipboard.Any()) { @@ -404,7 +404,7 @@ namespace BizHawk.Client.EmuHawk } else { - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } } else @@ -416,7 +416,7 @@ namespace BizHawk.Client.EmuHawk private void PasteInsertMenuItem_Click(object sender, EventArgs e) { - var wasPaused = GlobalWin.MainForm.EmulatorPaused; + var wasPaused = Mainform.EmulatorPaused; if (_tasClipboard.Any()) { @@ -433,7 +433,7 @@ namespace BizHawk.Client.EmuHawk } else { - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } } else @@ -447,7 +447,7 @@ namespace BizHawk.Client.EmuHawk { if (TasView.AnyRowsSelected) { - var wasPaused = GlobalWin.MainForm.EmulatorPaused; + var wasPaused = Mainform.EmulatorPaused; var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var rollBackFrame = TasView.FirstSelectedIndex.Value; @@ -480,7 +480,7 @@ namespace BizHawk.Client.EmuHawk } else { - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } } else @@ -494,7 +494,7 @@ namespace BizHawk.Client.EmuHawk { if (TasView.AnyRowsSelected) { - bool wasPaused = GlobalWin.MainForm.EmulatorPaused; + bool wasPaused = Mainform.EmulatorPaused; bool needsToRollback = !(TasView.FirstSelectedIndex > Emulator.Frame); int rollBackFrame = TasView.FirstSelectedIndex.Value; @@ -514,7 +514,7 @@ namespace BizHawk.Client.EmuHawk } else { - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } } else @@ -528,7 +528,7 @@ namespace BizHawk.Client.EmuHawk { if (TasView.AnyRowsSelected) { - var wasPaused = GlobalWin.MainForm.EmulatorPaused; + var wasPaused = Mainform.EmulatorPaused; var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var rollBackFrame = TasView.FirstSelectedIndex.Value; if (rollBackFrame >= CurrentTasMovie.InputLogLength) @@ -549,7 +549,7 @@ namespace BizHawk.Client.EmuHawk } else { - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } } else @@ -563,7 +563,7 @@ namespace BizHawk.Client.EmuHawk { if (TasView.AnyRowsSelected) { - var wasPaused = GlobalWin.MainForm.EmulatorPaused; + var wasPaused = Mainform.EmulatorPaused; var framesToInsert = TasView.SelectedRows.ToList(); var insertionFrame = Math.Min(TasView.LastSelectedIndex.Value + 1, CurrentTasMovie.InputLogLength); var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; @@ -583,7 +583,7 @@ namespace BizHawk.Client.EmuHawk } else { - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } } else @@ -595,7 +595,7 @@ namespace BizHawk.Client.EmuHawk private void InsertFrameMenuItem_Click(object sender, EventArgs e) { - var wasPaused = GlobalWin.MainForm.EmulatorPaused; + var wasPaused = Mainform.EmulatorPaused; var insertionFrame = TasView.AnyRowsSelected ? TasView.FirstSelectedIndex.Value : 0; var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; @@ -610,7 +610,7 @@ namespace BizHawk.Client.EmuHawk } else { - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } } else @@ -621,7 +621,7 @@ namespace BizHawk.Client.EmuHawk private void InsertNumFramesMenuItem_Click(object sender, EventArgs e) { - bool wasPaused = GlobalWin.MainForm.EmulatorPaused; + bool wasPaused = Mainform.EmulatorPaused; int insertionFrame = TasView.AnyRowsSelected ? TasView.FirstSelectedIndex.Value : 0; bool needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; @@ -641,7 +641,7 @@ namespace BizHawk.Client.EmuHawk } else { - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } } else @@ -720,7 +720,7 @@ namespace BizHawk.Client.EmuHawk int goToFrame = CurrentTasMovie.TasStateManager.LastEmulatedFrame; do { - GlobalWin.MainForm.FrameAdvance(); + Mainform.FrameAdvance(); if (CurrentTasMovie.TasStateManager.HasState(Emulator.Frame)) { @@ -936,7 +936,7 @@ namespace BizHawk.Client.EmuHawk { new MovieHeaderEditor(CurrentTasMovie) { - Owner = GlobalWin.MainForm, + Owner = Mainform, Location = this.ChildPointToScreen(TasView) }.Show(); UpdateChangesIndicator(); @@ -946,7 +946,7 @@ namespace BizHawk.Client.EmuHawk { new StateHistorySettingsForm(CurrentTasMovie.TasStateManager.Settings) { - Owner = GlobalWin.MainForm, + Owner = Mainform, Location = this.ChildPointToScreen(TasView), Statable = this.StatableEmulator }.ShowDialog(); @@ -1231,13 +1231,13 @@ namespace BizHawk.Client.EmuHawk StartFromNowSeparator.Visible =StartNewProjectFromNowMenuItem.Visible || StartANewProjectFromSaveRamMenuItem.Visible; RemoveMarkersContextMenuItem.Enabled = CurrentTasMovie.Markers.Any(m => TasView.SelectedRows.Contains(m.Frame)); // Disable the option to remove markers if no markers are selected (FCEUX does this). - CancelSeekContextMenuItem.Enabled = GlobalWin.MainForm.PauseOnFrame.HasValue; + CancelSeekContextMenuItem.Enabled = Mainform.PauseOnFrame.HasValue; BranchContextMenuItem.Visible = TasView.CurrentCell.RowIndex == Emulator.Frame; } private void CancelSeekContextMenuItem_Click(object sender, EventArgs e) { - GlobalWin.MainForm.PauseOnFrame = null; + Mainform.PauseOnFrame = null; RefreshTasView(); } @@ -1255,7 +1255,7 @@ namespace BizHawk.Client.EmuHawk TasMovie newProject = CurrentTasMovie.ConvertToSavestateAnchoredMovie( index, (byte[])StatableEmulator.SaveStateBinary().Clone()); - GlobalWin.MainForm.PauseEmulator(); + Mainform.PauseEmulator(); LoadFile(new FileInfo(newProject.Filename), true); } } @@ -1270,7 +1270,7 @@ namespace BizHawk.Client.EmuHawk TasMovie newProject = CurrentTasMovie.ConvertToSaveRamAnchoredMovie( SaveRamEmulator.CloneSaveRam()); - GlobalWin.MainForm.PauseEmulator(); + Mainform.PauseEmulator(); LoadFile(new FileInfo(newProject.Filename), true); } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs index f7186c1239..63232eb129 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs @@ -43,10 +43,10 @@ namespace BizHawk.Client.EmuHawk { if (frame == Emulator.Frame + 1) // We are at the end of the movie and advancing one frame, therefore we are recording, simply emulate a frame { - bool wasPaused = GlobalWin.MainForm.EmulatorPaused; - GlobalWin.MainForm.FrameAdvance(); + bool wasPaused = Mainform.EmulatorPaused; + Mainform.FrameAdvance(); if (!wasPaused) - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } else { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 27267f404d..453e4bf494 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -50,7 +50,6 @@ namespace BizHawk.Client.EmuHawk } public bool IsInMenuLoop { get; private set; } - public bool IgnoreSeekFrame { get; set; } [ConfigPersist] public TAStudioSettings Settings { get; set; } @@ -111,6 +110,18 @@ namespace BizHawk.Client.EmuHawk get { return Global.MovieSession.Movie as TasMovie; } } + public MainForm Mainform + { + get { return GlobalWin.MainForm; } + } + + /// + /// Separates "restore last position" logic from seeking caused by navigation. + /// TASEditor never kills LastPositionFrame, and it only pauses on it, + /// if it hasn't been greenzoned beforehand and middle mouse button was pressed. + /// + public int LastPositionFrame { get; set; } + #region "Initializing" public TAStudio() @@ -158,7 +169,7 @@ namespace BizHawk.Client.EmuHawk TasView.PointedCellChanged += TasView_PointedCellChanged; TasView.MultiSelect = true; TasView.MaxCharactersInHorizontal = 1; - IgnoreSeekFrame = false; + LastPositionFrame = -1; } private void AutosaveTimerEventProcessor(object sender, EventArgs e) @@ -244,7 +255,7 @@ namespace BizHawk.Client.EmuHawk } int diff = Global.Emulator.Frame - _seekStartFrame.Value; - int unit = GlobalWin.MainForm.PauseOnFrame.Value - _seekStartFrame.Value; + int unit = Mainform.PauseOnFrame.Value - _seekStartFrame.Value; double progress = 0; if (diff != 0 && unit != 0) @@ -503,16 +514,16 @@ namespace BizHawk.Client.EmuHawk private void EngageTastudio() { - GlobalWin.MainForm.PauseOnFrame = null; + Mainform.PauseOnFrame = null; GlobalWin.OSD.AddMessage("TAStudio engaged"); SetTasMovieCallbacks(); SetTextProperty(); - GlobalWin.MainForm.PauseEmulator(); - GlobalWin.MainForm.RelinquishControl(this); + Mainform.PauseEmulator(); + Mainform.RelinquishControl(this); _originalEndAction = Global.Config.MovieEndAction; - GlobalWin.MainForm.ClearRewindData(); + Mainform.ClearRewindData(); Global.Config.MovieEndAction = MovieEndAction.Record; - GlobalWin.MainForm.SetMainformMovieInfo(); + Mainform.SetMainformMovieInfo(); Global.MovieSession.ReadOnly = true; } @@ -646,7 +657,7 @@ namespace BizHawk.Client.EmuHawk if (movie == null) movie = CurrentTasMovie; SetTasMovieCallbacks(movie as TasMovie); - bool result = GlobalWin.MainForm.StartNewMovie(movie, record); + bool result = Mainform.StartNewMovie(movie, record); TastudioPlayMode(); _initializing = false; @@ -698,17 +709,17 @@ namespace BizHawk.Client.EmuHawk private void TastudioStopMovie() { Global.MovieSession.StopMovie(false); - GlobalWin.MainForm.SetMainformMovieInfo(); + Mainform.SetMainformMovieInfo(); } private void DisengageTastudio() { - GlobalWin.MainForm.PauseOnFrame = null; + Mainform.PauseOnFrame = null; GlobalWin.OSD.AddMessage("TAStudio disengaged"); Global.MovieSession.Movie = MovieService.DefaultInstance; - GlobalWin.MainForm.TakeBackControl(); + Mainform.TakeBackControl(); Global.Config.MovieEndAction = _originalEndAction; - GlobalWin.MainForm.SetMainformMovieInfo(); + Mainform.SetMainformMovieInfo(); // Do not keep TAStudio's disk save states. //if (Directory.Exists(statesPath)) Directory.Delete(statesPath, true); //TODO - do we need to dispose something here instead? @@ -795,8 +806,7 @@ namespace BizHawk.Client.EmuHawk if (_autoRestorePaused.HasValue && !_autoRestorePaused.Value) { // this happens when we're holding the left button while unpaused - view scrolls down, new input gets drawn, seek pauses - IgnoreSeekFrame = true; - GlobalWin.MainForm.UnpauseEmulator(); + Mainform.UnpauseEmulator(); } _autoRestorePaused = null; } @@ -819,7 +829,7 @@ namespace BizHawk.Client.EmuHawk // frame == Emualtor.Frame when frame == 0 if (frame > Emulator.Frame) { - if (GlobalWin.MainForm.EmulatorPaused || GlobalWin.MainForm.IsSeeking) // make seek frame keep up with emulation on fast scrolls + if (Mainform.EmulatorPaused || Mainform.IsSeeking) // make seek frame keep up with emulation on fast scrolls { StartSeeking(frame); } @@ -861,7 +871,7 @@ namespace BizHawk.Client.EmuHawk public void TogglePause() { - GlobalWin.MainForm.TogglePause(); + Mainform.TogglePause(); } private void SetSplicer() diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index fc7de1142c..6749e2d55c 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -456,12 +456,8 @@ namespace BizHawk.Client.EmuHawk if (ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, tool.GetType())) { ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, tool); - bool restartTool = false; + if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch) // Hack for RAM Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic - restartTool = true; - if (tool is LuaConsole && ((LuaConsole)tool).IsRebootingCore) - restartTool = false; - if (restartTool) { tool.Restart(); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper015.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper015.cs index c8d64e94de..389a6d243e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper015.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper015.cs @@ -44,17 +44,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES int mode = addr & 3; int prg_high = value & 0x3F; bool prg_low = value.Bit(7); - int prg_low_val = prg_low ? 1 : 0; + int prg_low_val = 0; + if (mode==2) + prg_low_val = prg_low ? 1 : 0; bool mirror = value.Bit(6); - SetMirrorType(mirror ? EMirrorType.Horizontal : EMirrorType.Vertical); + SetMirrorType(!mirror ? EMirrorType.Horizontal : EMirrorType.Vertical); switch(mode) { case 0: prg_banks_8k[0] = (byte)((prg_high * 2 + 0) ^ prg_low_val); prg_banks_8k[1] = (byte)((prg_high * 2 + 1) ^ prg_low_val); - prg_banks_8k[2] = (byte)((prg_high * 2 + 2) ^ prg_low_val); - prg_banks_8k[3] = (byte)((prg_high * 2 + 3) ^ prg_low_val); + prg_high = prg_high | 0x01; + prg_banks_8k[2] = (byte)((prg_high * 2 + 0) ^ prg_low_val); + prg_banks_8k[3] = (byte)((prg_high * 2 + 1) ^ prg_low_val); break; case 1: prg_banks_8k[0] = (byte)((prg_high*2+0) ^ prg_low_val); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/TENGEN-800032.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/TENGEN-800032.cs index 797f8e1d23..7a59062a2a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/TENGEN-800032.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/TENGEN-800032.cs @@ -236,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { irq_pending = true; SyncIRQ(); - } + } } } @@ -251,6 +251,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES if (irq_countdown == 0) { ClockIRQ(); + if (irq_mode==true) + irq_countdown = 12; } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Taito_TC0190FMC.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Taito_TC0190FMC.cs index eb0da2a162..c770bef585 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Taito_TC0190FMC.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Taito_TC0190FMC.cs @@ -57,9 +57,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES if (delay > 0) { + delay--; - if(delay==0) + if(delay==0 && irq_pending) board.IRQSignal = true; + } } } @@ -187,11 +189,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES break; case 0x4002: if (!pal16) break; - mmc3.WritePRG(0x6000, value); + mmc3.WritePRG(0x6001, value); break; case 0x4003: if (!pal16) break; - mmc3.WritePRG(0x6001, value); + mmc3.WritePRG(0x6000, value); break; case 0x6000: