From a55cf000e7ce90f56015454df3fbd1453c79bf27 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Tue, 13 Mar 2018 13:09:44 +0000 Subject: [PATCH] Some code tidy --- .../Machine/SpectrumBase.Input.cs | 5 + .../Machine/SpectrumBase.Media.cs | 4 +- .../Machine/SpectrumBase.Memory.cs | 70 +++++++++++- .../Machine/SpectrumBase.Port.cs | 1 - .../SinclairSpectrum/Machine/SpectrumBase.cs | 104 ++++++++---------- 5 files changed, 119 insertions(+), 65 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs index bf6a679f15..c14a7bcc62 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs @@ -28,6 +28,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum bool pressed_PrevBlock = false; bool pressed_TapeStatus = false; + /// + /// Cycles through all the input callbacks + /// This should be done once per frame + /// public void PollInput() { Spectrum.InputCallbacks.Call(); @@ -247,6 +251,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Signs whether input read has been requested + /// This forms part of the IEmulator LagFrame implementation /// private bool inputRead; public bool InputRead diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs index aa1b943823..de2f5206d7 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs @@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum protected List diskImages { get; set; } /// - /// The index of the currently 'loaded' tape or disk image + /// The index of the currently 'loaded' tape image /// protected int tapeMediaIndex; public int TapeMediaIndex @@ -63,7 +63,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } /// - /// The index of the currently 'loaded' tape or disk image + /// The index of the currently 'loaded' disk image /// protected int diskMediaIndex; public int DiskMediaIndex diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Memory.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Memory.cs index 5a21a8db42..48058ee084 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Memory.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Memory.cs @@ -12,6 +12,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public abstract partial class SpectrumBase { + #region Memory Fields & Properties + /// /// ROM Banks /// @@ -19,7 +21,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public byte[] ROM1 = new byte[0x4000]; public byte[] ROM2 = new byte[0x4000]; public byte[] ROM3 = new byte[0x4000]; - + /// /// RAM Banks /// @@ -32,6 +34,65 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public byte[] RAM6 = new byte[0x4000]; // Bank 6 public byte[] RAM7 = new byte[0x4000]; // Bank 7 + /// + /// Signs that the shadow screen is now displaying + /// Note: normal screen memory in RAM5 is not altered, the ULA just outputs Screen1 instead (RAM7) + /// + protected bool SHADOWPaged; + + /// + /// Index of the current RAM page + /// /// 128k, +2/2a and +3 only + /// + public int RAMPaged; + + /// + /// Signs that all paging is disabled + /// If this is TRUE, then 128k and above machines need a hard reset before paging is allowed again + /// + protected bool PagingDisabled; + + /// + /// Index of the currently paged ROM + /// 128k, +2/2a and +3 only + /// + protected int ROMPaged; + public virtual int _ROMpaged + { + get { return ROMPaged; } + set { ROMPaged = value; } + } + + /* + * +3/+2A only + */ + + /// + /// High bit of the ROM selection (in normal paging mode) + /// + protected bool ROMhigh = false; + + /// + /// Low bit of the ROM selection (in normal paging mode) + /// + protected bool ROMlow = false; + + /// + /// Signs that the +2a/+3 special paging mode is activated + /// + protected bool SpecialPagingMode; + + /// + /// Index of the current special paging mode (0-3) + /// + protected int PagingConfiguration; + + #endregion + + + + #region Memory Related Methods + /// /// Simulates reading from the bus /// Paging should be handled here @@ -95,6 +156,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum return value; } + #endregion + + #region Helper Methods + /// /// Detects whether this is a 48k machine (or a 128k in 48k mode) /// @@ -110,6 +175,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum else return false; } - + + #endregion } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Port.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Port.cs index 874345ba9d..3b53dd28e3 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Port.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Port.cs @@ -22,7 +22,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum set { LastULAOutByte = value; } } - /// /// Reads a byte of data from a specified port address /// diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs index 9650e8cfd0..c4b241b898 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs @@ -12,52 +12,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public abstract partial class SpectrumBase { - /// - /// Index of the currently paged ROM - /// - protected int ROMPaged; - public virtual int _ROMpaged - { - get { return ROMPaged; } - set { ROMPaged = value; } - } - - /// - /// Signs that the shadow screen has been paged in - /// - protected bool SHADOWPaged; - - /// - /// Index of the current RAM page - /// - public int RAMPaged; - - /// - /// Signs that all paging is disabled - /// - protected bool PagingDisabled; - - // +3/+2A only - - protected bool ROMhigh = false; - protected bool ROMlow = false; - - /// - /// Signs that the +2a/+3 special paging mode is activated - /// - protected bool SpecialPagingMode; - - /// - /// Index of the current special paging config - /// - protected int PagingConfiguration; - - /// - /// Signs whether the disk motor is on or off - /// - protected bool DiskMotorState; - - protected bool PrinterPortStrobe; + #region Devices /// /// The calling ZXSpectrum class (piped in via constructor) @@ -103,7 +58,21 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// Holds the currently selected joysticks /// public virtual IJoystick[] JoystickCollection { get; set; } - + + /// + /// Signs whether the disk motor is on or off + /// + protected bool DiskMotorState; + + /// + /// +3/2a printer port strobe + /// + protected bool PrinterPortStrobe; + + #endregion + + #region Emulator State + /// /// Signs whether the frame has ended /// @@ -140,16 +109,23 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public bool _render; public bool _renderSound; + #endregion + + #region Constants + /// - /// Mask constants + /// Mask constants & misc /// protected const int BORDER_BIT = 0x07; protected const int EAR_BIT = 0x10; protected const int MIC_BIT = 0x08; protected const int TAPE_BIT = 0x40; - protected const int AY_SAMPLE_RATE = 16; + #endregion + + #region Emulation Loop + /// /// Executes a single frame /// @@ -169,7 +145,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } PollInput(); - + while (CurrentFrameCycle < ULADevice.FrameLength) // UlaFrameCycleCount) { // check for interrupt @@ -183,18 +159,18 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { if (AYDevice != null) AYDevice.UpdateSound(CurrentFrameCycle); - } + } } - + // we have reached the end of a frame LastFrameStartCPUTick = CPU.TotalExecutedCycles - OverFlow; // paint the buffer if needed if (ULADevice.needsPaint && _render) ULADevice.UpdateScreenBuffer(ULADevice.FrameLength); - + if (_renderSound) - BuzzerDevice.EndFrame(); + BuzzerDevice.EndFrame(); FrameCount++; @@ -208,14 +184,18 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // is this a lag frame? Spectrum.IsLagFrame = !InputRead; } - + + #endregion + + #region Reset Functions + /// /// Hard reset of the emulated machine /// public virtual void HardReset() - { + { //ResetBorder(); - ULADevice.ResetInterrupt(); + ULADevice.ResetInterrupt(); } /// @@ -227,6 +207,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ULADevice.ResetInterrupt(); } + #endregion + + #region IStatable + public void SyncState(Serializer ser) { ser.BeginSection("ZXMachine"); @@ -236,7 +220,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ser.Sync("_frameCycles", ref _frameCycles); ser.Sync("inputRead", ref inputRead); ser.Sync("LastFrameStartCPUTick", ref LastFrameStartCPUTick); - ser.Sync("LastULAOutByte", ref LastULAOutByte); + ser.Sync("LastULAOutByte", ref LastULAOutByte); ser.Sync("ROM0", ref ROM0, false); ser.Sync("ROM1", ref ROM1, false); ser.Sync("ROM2", ref ROM2, false); @@ -273,8 +257,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum TapeDevice.SyncState(ser); ser.EndSection(); - - //ReInitMemory(); } + + #endregion } }