Some code tidy

This commit is contained in:
Asnivor 2018-03-13 13:09:44 +00:00
parent 97c453ae91
commit a55cf000e7
5 changed files with 119 additions and 65 deletions

View File

@ -28,6 +28,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
bool pressed_PrevBlock = false;
bool pressed_TapeStatus = false;
/// <summary>
/// Cycles through all the input callbacks
/// This should be done once per frame
/// </summary>
public void PollInput()
{
Spectrum.InputCallbacks.Call();
@ -247,6 +251,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary>
/// Signs whether input read has been requested
/// This forms part of the IEmulator LagFrame implementation
/// </summary>
private bool inputRead;
public bool InputRead

View File

@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
protected List<byte[]> diskImages { get; set; }
/// <summary>
/// The index of the currently 'loaded' tape or disk image
/// The index of the currently 'loaded' tape image
/// </summary>
protected int tapeMediaIndex;
public int TapeMediaIndex
@ -63,7 +63,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
}
/// <summary>
/// The index of the currently 'loaded' tape or disk image
/// The index of the currently 'loaded' disk image
/// </summary>
protected int diskMediaIndex;
public int DiskMediaIndex

View File

@ -12,6 +12,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
public abstract partial class SpectrumBase
{
#region Memory Fields & Properties
/// <summary>
/// ROM Banks
/// </summary>
@ -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];
/// <summary>
/// RAM Banks
/// </summary>
@ -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
/// <summary>
/// Signs that the shadow screen is now displaying
/// Note: normal screen memory in RAM5 is not altered, the ULA just outputs Screen1 instead (RAM7)
/// </summary>
protected bool SHADOWPaged;
/// <summary>
/// Index of the current RAM page
/// /// 128k, +2/2a and +3 only
/// </summary>
public int RAMPaged;
/// <summary>
/// Signs that all paging is disabled
/// If this is TRUE, then 128k and above machines need a hard reset before paging is allowed again
/// </summary>
protected bool PagingDisabled;
/// <summary>
/// Index of the currently paged ROM
/// 128k, +2/2a and +3 only
/// </summary>
protected int ROMPaged;
public virtual int _ROMpaged
{
get { return ROMPaged; }
set { ROMPaged = value; }
}
/*
* +3/+2A only
*/
/// <summary>
/// High bit of the ROM selection (in normal paging mode)
/// </summary>
protected bool ROMhigh = false;
/// <summary>
/// Low bit of the ROM selection (in normal paging mode)
/// </summary>
protected bool ROMlow = false;
/// <summary>
/// Signs that the +2a/+3 special paging mode is activated
/// </summary>
protected bool SpecialPagingMode;
/// <summary>
/// Index of the current special paging mode (0-3)
/// </summary>
protected int PagingConfiguration;
#endregion
#region Memory Related Methods
/// <summary>
/// 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
/// <summary>
/// Detects whether this is a 48k machine (or a 128k in 48k mode)
/// </summary>
@ -110,6 +175,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
else
return false;
}
#endregion
}
}

View File

@ -22,7 +22,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
set { LastULAOutByte = value; }
}
/// <summary>
/// Reads a byte of data from a specified port address
/// </summary>

View File

@ -12,52 +12,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
public abstract partial class SpectrumBase
{
/// <summary>
/// Index of the currently paged ROM
/// </summary>
protected int ROMPaged;
public virtual int _ROMpaged
{
get { return ROMPaged; }
set { ROMPaged = value; }
}
/// <summary>
/// Signs that the shadow screen has been paged in
/// </summary>
protected bool SHADOWPaged;
/// <summary>
/// Index of the current RAM page
/// </summary>
public int RAMPaged;
/// <summary>
/// Signs that all paging is disabled
/// </summary>
protected bool PagingDisabled;
// +3/+2A only
protected bool ROMhigh = false;
protected bool ROMlow = false;
/// <summary>
/// Signs that the +2a/+3 special paging mode is activated
/// </summary>
protected bool SpecialPagingMode;
/// <summary>
/// Index of the current special paging config
/// </summary>
protected int PagingConfiguration;
/// <summary>
/// Signs whether the disk motor is on or off
/// </summary>
protected bool DiskMotorState;
protected bool PrinterPortStrobe;
#region Devices
/// <summary>
/// The calling ZXSpectrum class (piped in via constructor)
@ -103,7 +58,21 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// Holds the currently selected joysticks
/// </summary>
public virtual IJoystick[] JoystickCollection { get; set; }
/// <summary>
/// Signs whether the disk motor is on or off
/// </summary>
protected bool DiskMotorState;
/// <summary>
/// +3/2a printer port strobe
/// </summary>
protected bool PrinterPortStrobe;
#endregion
#region Emulator State
/// <summary>
/// Signs whether the frame has ended
/// </summary>
@ -140,16 +109,23 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public bool _render;
public bool _renderSound;
#endregion
#region Constants
/// <summary>
/// Mask constants
/// Mask constants & misc
/// </summary>
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
/// <summary>
/// Executes a single frame
/// </summary>
@ -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
/// <summary>
/// Hard reset of the emulated machine
/// </summary>
public virtual void HardReset()
{
{
//ResetBorder();
ULADevice.ResetInterrupt();
ULADevice.ResetInterrupt();
}
/// <summary>
@ -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
}
}