OSD message handling implementation

This commit is contained in:
Asnivor 2018-03-05 13:29:34 +00:00
parent 90c1e293bf
commit 23c07cdb67
8 changed files with 291 additions and 10 deletions

View File

@ -659,10 +659,17 @@ namespace BizHawk.Client.Common
(C64.C64SyncSettings)GetCoreSyncSettings<C64>());
break;
case "ZXSpectrum":
List<GameInfo> zxGI = new List<GameInfo>();
foreach (var a in xmlGame.Assets)
{
zxGI.Add(new GameInfo { Name = Path.GetFileNameWithoutExtension(a.Key) });
}
nextEmulator = new ZXSpectrum(
nextComm,
xmlGame.Assets.Select(a => a.Value), //.First(),
GameInfo.NullInstance,
zxGI, // GameInfo.NullInstance,
(ZXSpectrum.ZXSpectrumSettings)GetCoreSettings<ZXSpectrum>(),
(ZXSpectrum.ZXSpectrumSyncSettings)GetCoreSyncSettings<ZXSpectrum>());
break;
@ -1000,7 +1007,7 @@ namespace BizHawk.Client.Common
nextEmulator = c64;
break;
case "ZXSpectrum":
var zx = new ZXSpectrum(nextComm, Enumerable.Repeat(rom.RomData, 1), rom.GameInfo, GetCoreSettings<ZXSpectrum>(), GetCoreSyncSettings<ZXSpectrum>());
var zx = new ZXSpectrum(nextComm, Enumerable.Repeat(rom.RomData, 1), Enumerable.Repeat(rom.GameInfo, 1).ToList(), GetCoreSettings<ZXSpectrum>(), GetCoreSyncSettings<ZXSpectrum>());
nextEmulator = zx;
break;
case "GBA":

View File

@ -296,6 +296,7 @@
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IMemoryDomains.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.ISettable.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IStatable.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.Messaging.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.Util.cs" />
<Compile Include="Consoles\Atari\2600\Atari2600.cs" />
<Compile Include="Consoles\Atari\2600\Atari2600.Core.cs">

View File

@ -133,6 +133,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
if (_tapeIsPlaying)
return;
_machine.Spectrum.OSD_TapePlaying();
// update the lastCycle
_lastCycle = _cpu.TotalExecutedCycles;
@ -183,6 +185,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
if (!_tapeIsPlaying)
return;
_machine.Spectrum.OSD_TapeStopped();
// sign that the tape is no longer playing
_tapeIsPlaying = false;
@ -224,6 +228,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public void RTZ()
{
Stop();
_machine.Spectrum.OSD_TapeRTZ();
_currentDataBlockIndex = 0;
}

View File

@ -13,6 +13,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
string NextTape = "Insert Next Tape";
string PrevTape = "Insert Previous Tape";
bool pressed_Play = false;
bool pressed_Stop = false;
bool pressed_RTZ = false;
bool pressed_NextTape = false;
bool pressed_PrevTape = false;
public void PollInput()
{
Spectrum.InputCallbacks.Call();
@ -22,8 +28,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// parse single keyboard matrix keys
for (var i = 0; i < KeyboardDevice.KeyboardMatrix.Length; i++)
{
string key = KeyboardDevice.KeyboardMatrix[i];
bool prevState = KeyboardDevice.GetKeyStatus(key);
bool currState = Spectrum._controller.IsPressed(key);
@ -57,28 +61,67 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// Tape control
if (Spectrum._controller.IsPressed(Play))
{
TapeDevice.Play();
if (!pressed_Play)
{
Spectrum.OSD_FireInputMessage(Play);
TapeDevice.Play();
pressed_Play = true;
}
}
else
pressed_Play = false;
if (Spectrum._controller.IsPressed(Stop))
{
TapeDevice.Stop();
if (!pressed_Stop)
{
Spectrum.OSD_FireInputMessage(Stop);
TapeDevice.Stop();
pressed_Stop = true;
}
}
else
pressed_Stop = false;
if (Spectrum._controller.IsPressed(RTZ))
{
TapeDevice.RTZ();
if (!pressed_RTZ)
{
Spectrum.OSD_FireInputMessage(RTZ);
TapeDevice.RTZ();
pressed_RTZ = true;
}
}
else
pressed_RTZ = false;
if (Spectrum._controller.IsPressed(Record))
{
}
if (Spectrum._controller.IsPressed(NextTape))
{
TapeMediaIndex++;
if (!pressed_NextTape)
{
Spectrum.OSD_FireInputMessage(NextTape);
TapeMediaIndex++;
pressed_NextTape = true;
}
}
else
pressed_NextTape = false;
if (Spectrum._controller.IsPressed(PrevTape))
{
TapeMediaIndex--;
if (!pressed_PrevTape)
{
Spectrum.OSD_FireInputMessage(PrevTape);
TapeMediaIndex--;
pressed_PrevTape = true;
}
}
else
pressed_PrevTape = false;
}
}
}

View File

@ -56,6 +56,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// load the media into the tape device
tapeMediaIndex = result;
// fire osd message
Spectrum.OSD_TapeInserted();
LoadTapeMedia();
}
}
@ -103,6 +105,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
mediaImages = files;
LoadAllMedia();
Spectrum.OSD_TapeInit();
}
/// <summary>

View File

@ -48,6 +48,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
[DefaultValue(true)]
public bool StereoSound { get; set; }
[DisplayName("Core OSD Message Verbosity")]
[Description("Full: Display all GUI messages\nMedium: Display only emulator/device generated messages\nNone: Show no messages")]
[DefaultValue(OSDVerbosity.Medium)]
public OSDVerbosity OSDMessageVerbosity { get; set; }
public ZXSpectrumSettings Clone()
{
@ -98,6 +103,22 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
}
}
public enum OSDVerbosity
{
/// <summary>
/// Show all OSD messages
/// </summary>
Full,
/// <summary>
/// Only show machine/device generated messages
/// </summary>
Medium,
/// <summary>
/// No core-driven OSD messages
/// </summary>
None
}
/// <summary>
/// The size of the Spectrum border
/// </summary>

View File

@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
/// <summary>
/// Handles all messaging (OSD) operations
/// </summary>
public partial class ZXSpectrum
{
/// <summary>
/// Writes a message to the OSD
/// </summary>
/// <param name="message"></param>
/// <param name="category"></param>
public void SendMessage(string message, MessageCategory category)
{
if (!CheckMessageSettings(category))
return;
StringBuilder sb = new StringBuilder();
switch (category)
{
case MessageCategory.Tape:
sb.Append("DATACORDER: ");
sb.Append(message);
break;
case MessageCategory.Input:
sb.Append("INPUT DETECTED: ");
sb.Append(message);
break;
case MessageCategory.Disk:
sb.Append("DISK DRIVE: ");
sb.Append(message);
break;
case MessageCategory.Emulator:
case MessageCategory.Misc:
sb.Append("ZXHAWK: ");
sb.Append(message);
break;
}
CoreComm.Notify(sb.ToString());
}
#region Input Message Methods
/// <summary>
/// Called when certain input presses are detected
/// </summary>
/// <param name="input"></param>
public void OSD_FireInputMessage(string input)
{
StringBuilder sb = new StringBuilder();
sb.Append(input);
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Input);
}
#endregion
#region TapeDevice Message Methods
/// <summary>
/// Tape message that is fired on core init
/// </summary>
public void OSD_TapeInit()
{
StringBuilder sb = new StringBuilder();
sb.Append("Tape Media Imported (count: " + _gameInfo.Count() + ")");
sb.Append("\n");
for (int i = 0; i < _gameInfo.Count(); i++)
sb.Append(i.ToString() + ": " + _gameInfo[i].Name + "\n");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Emulator);
}
/// <summary>
/// Tape message that is fired when tape is playing
/// </summary>
public void OSD_TapePlaying()
{
StringBuilder sb = new StringBuilder();
sb.Append("PLAYING (" + _machine.TapeMediaIndex + ": " + _gameInfo[_machine.TapeMediaIndex].Name + ")");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
}
/// <summary>
/// Tape message that is fired when tape is stopped
/// </summary>
public void OSD_TapeStopped()
{
StringBuilder sb = new StringBuilder();
sb.Append("STOPPED (" + _machine.TapeMediaIndex + ": " + _gameInfo[_machine.TapeMediaIndex].Name + ")");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
}
/// <summary>
/// Tape message that is fired when tape is rewound
/// </summary>
public void OSD_TapeRTZ()
{
StringBuilder sb = new StringBuilder();
sb.Append("REWOUND (" + _machine.TapeMediaIndex + ": " + _gameInfo[_machine.TapeMediaIndex].Name + ")");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
}
/// <summary>
/// Tape message that is fired when a new tape is inserted into the datacorder
/// </summary>
public void OSD_TapeInserted()
{
StringBuilder sb = new StringBuilder();
sb.Append("TAPE INSERTED (" + _machine.TapeMediaIndex + ": " + _gameInfo[_machine.TapeMediaIndex].Name + ")");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
}
/// <summary>
/// Tape message that is fired when a tape is stopped automatically
/// </summary>
public void OSD_TapeStoppedAuto()
{
StringBuilder sb = new StringBuilder();
sb.Append("STOPPED (Auto Tape Trap) (" + _machine.TapeMediaIndex + ": " + _gameInfo[_machine.TapeMediaIndex].Name + ")");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
}
#endregion
/// <summary>
/// Checks whether message category is allowed to be sent
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
public bool CheckMessageSettings(MessageCategory category)
{
switch (Settings.OSDMessageVerbosity)
{
case OSDVerbosity.Full:
return true;
case OSDVerbosity.None:
return false;
case OSDVerbosity.Medium:
switch (category)
{
case MessageCategory.Disk:
case MessageCategory.Emulator:
case MessageCategory.Tape:
case MessageCategory.Misc:
return true;
default:
return false;
}
default:
return true;
}
}
/// <summary>
/// Defines the different message categories
/// </summary>
public enum MessageCategory
{
/// <summary>
/// No defined category as such
/// </summary>
Misc,
/// <summary>
/// User generated input messages (at the moment only tape/disk controls)
/// </summary>
Input,
/// <summary>
/// Tape device generated messages
/// </summary>
Tape,
/// <summary>
/// Disk device generated messages
/// </summary>
Disk,
/// <summary>
/// Emulator generated messages
/// </summary>
Emulator
}
}
}

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public partial class ZXSpectrum : IDebuggable, IInputPollable, IStatable, IRegionable
{
[CoreConstructor("ZXSpectrum")]
public ZXSpectrum(CoreComm comm, IEnumerable<byte[]> files, GameInfo game, object settings, object syncSettings)
public ZXSpectrum(CoreComm comm, IEnumerable<byte[]> files, List<GameInfo> game, object settings, object syncSettings)
{
PutSyncSettings((ZXSpectrumSyncSettings)syncSettings ?? new ZXSpectrumSyncSettings());
PutSettings((ZXSpectrumSettings)settings ?? new ZXSpectrumSettings());
@ -30,6 +30,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
CoreComm = comm;
_gameInfo = game;
_cpu = new Z80A();
_tracer = new TraceBuffer { Header = _cpu.TraceHeader };
@ -101,6 +103,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public IController _controller;
private SpectrumBase _machine;
private List<GameInfo> _gameInfo;
private SoundProviderMixer SoundMixer;
private DCFilter dcf;