diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj
index 22418902bb..ccdf468532 100644
--- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj
+++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj
@@ -119,11 +119,12 @@
+
AppleII.cs
- AppleII.cs
+ AppleII.cs
AppleII.cs
diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IEmulator.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IEmulator.cs
index 2b1726e992..bf871b57ab 100644
--- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IEmulator.cs
+++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IEmulator.cs
@@ -15,7 +15,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
[FeatureNotImplemented]
public ISyncSoundProvider SyncSoundProvider
{
- get { return _soundService; }
+ get { return this; }
}
[FeatureNotImplemented]
diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs
index 7a42219d89..f6fefbc326 100644
--- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs
+++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs
@@ -1,5 +1,8 @@
using BizHawk.Emulation.Common;
using System.IO;
+using System;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
namespace BizHawk.Emulation.Cores.Computers.AppleII
{
@@ -7,39 +10,84 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
{
public bool BinarySaveStatesPreferred { get { return true; } }
+ private class OtherData
+ {
+ public int Frame;
+ public int LagCount;
+ public bool IsLagFrame;
+ public int CurrentDisk;
+ public JObject Core;
+ }
+ private JsonSerializer ser = new JsonSerializer();
+
[FeatureNotImplemented]
public void SaveStateText(TextWriter writer)
{
+ var w = new JTokenWriter();
+ _machine.Serialize(w);
+ var o = new OtherData
+ {
+ Frame = Frame,
+ LagCount = LagCount,
+ IsLagFrame = IsLagFrame,
+ CurrentDisk = CurrentDisk,
+ Core = (JObject)w.Token,
+ };
+
+ var jw = new JsonTextWriter(writer) { Formatting = Newtonsoft.Json.Formatting.Indented };
+ ser.Serialize(jw, o);
}
- [FeatureNotImplemented]
public void LoadStateText(TextReader reader)
{
+ var o = (OtherData)ser.Deserialize(reader, typeof(OtherData));
+ Frame = o.Frame;
+ LagCount = o.LagCount;
+ IsLagFrame = o.IsLagFrame;
+ CurrentDisk = o.CurrentDisk;
+ var r = new JTokenReader(o.Core);
+ try
+ {
+ _machine = Jellyfish.Virtu.Machine.Deserialize(r);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.ToString());
+ throw;
+ }
+ // should not be needed.
+ // InitDisk();
}
public void SaveStateBinary(BinaryWriter writer)
{
+ /*
writer.Write(Frame);
writer.Write(LagCount);
writer.Write(IsLagFrame);
writer.Write(CurrentDisk);
_machine.SaveState(writer);
+ */
}
public void LoadStateBinary(BinaryReader reader)
{
+ /*
Frame = reader.ReadInt32();
LagCount = reader.ReadInt32();
IsLagFrame = reader.ReadBoolean();
CurrentDisk = reader.ReadInt32();
InitDisk();
_machine.LoadState(reader);
+ */
}
public byte[] SaveStateBinary()
{
+ return new byte[16];
+
if (_stateBuffer == null)
{
var stream = new MemoryStream();
diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs
index ea2041f74e..3de60f4e10 100644
--- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs
+++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs
@@ -3,45 +3,23 @@ using Jellyfish.Virtu;
namespace BizHawk.Emulation.Cores.Computers.AppleII
{
- public partial class AppleII
+ public partial class AppleII : IVideoProvider
{
- public class BizVideoService : Jellyfish.Virtu.Services.VideoService, IVideoProvider
- {
- public int[] fb;
+ private Jellyfish.Virtu.Services.VideoService _V
+ { get { return _machine.Video.VideoService; } }
- int[] IVideoProvider.GetVideoBuffer() { return fb; }
+ int[] IVideoProvider.GetVideoBuffer() { return _V.fb; }
- // put together, these describe a metric on the screen
- // they should define the smallest size that the buffer can be placed inside such that:
- // 1. no actual pixel data is lost
- // 2. aspect ratio is accurate
- int IVideoProvider.VirtualWidth { get { return 560; } }
- int IVideoProvider.VirtualHeight { get { return 384; } }
+ // put together, these describe a metric on the screen
+ // they should define the smallest size that the buffer can be placed inside such that:
+ // 1. no actual pixel data is lost
+ // 2. aspect ratio is accurate
+ int IVideoProvider.VirtualWidth { get { return 560; } }
+ int IVideoProvider.VirtualHeight { get { return 384; } }
- int IVideoProvider.BufferWidth { get { return 560; } }
- int IVideoProvider.BufferHeight { get { return 384; } }
- int IVideoProvider.BackgroundColor { get { return 0; } }
+ int IVideoProvider.BufferWidth { get { return 560; } }
+ int IVideoProvider.BufferHeight { get { return 384; } }
+ int IVideoProvider.BackgroundColor { get { return 0; } }
- public BizVideoService(Machine machine) :
- base(machine)
- {
- fb = new int[560 * 384];
- }
-
- public override void SetFullScreen(bool isFullScreen)
- {
-
- }
-
- public override void SetPixel(int x, int y, uint color)
- {
- int i = 560 * y + x;
- fb[i] = fb[i + 560] = (int)color;
- }
- public override void Update()
- {
-
- }
- }
}
}
diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs
index f4805d4713..cd28019296 100644
--- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs
+++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs
@@ -14,7 +14,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
isPorted: true,
isReleased: false
)]
- public partial class AppleII : IEmulator, IStatable
+ public partial class AppleII : IEmulator
{
public AppleII(CoreComm comm, IEnumerable gameInfoSet, IEnumerable romSet, object settings)
: this(comm, gameInfoSet.First(), romSet.First(), settings)
@@ -42,27 +42,11 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
_machine = new Machine(_appleIIRom, _diskIIRom);
- var vidService = new BizVideoService(_machine);
- _soundService = new BizAudioService(_machine);
- var gpService = new Jellyfish.Virtu.Services.GamePortService(_machine);
- var kbService = new BizKeyboardService(_machine);
-
- _machine.Services.AddService(typeof(Jellyfish.Virtu.Services.DebugService), new Jellyfish.Virtu.Services.DebugService(_machine));
- _machine.Services.AddService(typeof(Jellyfish.Virtu.Services.AudioService), _soundService);
- _machine.Services.AddService(typeof(Jellyfish.Virtu.Services.VideoService), vidService);
- _machine.Services.AddService(typeof(Jellyfish.Virtu.Services.GamePortService), gpService);
- _machine.Services.AddService(typeof(Jellyfish.Virtu.Services.KeyboardService), kbService);
_machine.BizInitialize();
- (ServiceProvider as BasicServiceProvider).Register(vidService);
-
//make a writeable memory stream cloned from the rom.
//for junk.dsk the .dsk is important because it determines the format from that
- var ms = new MemoryStream();
- ms.Write(_disk1, 0, _disk1.Length);
- ms.Position = 0;
- bool writeProtected = false; //!!!!!!!!!!!!!!!!!!!
- Jellyfish.Virtu.Services.StorageService.LoadFile(ms, stream => _machine.BootDiskII.Drives[0].InsertDisk("junk.dsk", stream, writeProtected));
+ InitDisk();
SetupMemoryDomains();
}
@@ -108,56 +92,31 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
//make a writeable memory stream cloned from the rom.
//for junk.dsk the .dsk is important because it determines the format from that
- var ms = new MemoryStream();
- ms.Write(_disk1, 0, _disk1.Length);
- ms.Position = 0;
- bool writeProtected = false; //!!!!!!!!!!!!!!!!!!!
- Jellyfish.Virtu.Services.StorageService.LoadFile(ms, stream => _machine.BootDiskII.Drives[0].InsertDisk("junk.dsk", stream, writeProtected));
- _machine.BizNewDisk();
+
+ bool writeProtected = false; //!!!!!!!!!!!!!!!!!!
+ _machine.BootDiskII.Drives[0].InsertDisk("junk.dsk", (byte[])_disk1.Clone(), false);
}
- private readonly Machine _machine;
+ private Machine _machine;
private byte[] _disk1;
private readonly byte[] _appleIIRom;
private readonly byte[] _diskIIRom;
- private readonly BizAudioService _soundService;
- private static readonly ControllerDefinition AppleIIController =
- new ControllerDefinition
- {
- Name = "Apple II Keyboard",
- BoolButtons =
- {
- "Up", "Down", "Left", "Right",
- "Tab", "Enter", "Escape", "Back", "Space",
- "Ctrl", "Shift", "Caps",
- "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
- "A", "B", "C", "D", "E", "F", "G", "H", "I",
- "J", "K", "L", "M", "N", "O", "P", "Q", "R",
- "S", "T", "U", "V", "W", "X", "Y", "Z",
- "Next Disk", "Previous Disk"
- }
- };
+ private static readonly ControllerDefinition AppleIIController;
- private class BizKeyboardService : KeyboardService
+ private static readonly List RealButtons = new List(Keyboard.GetKeyNames());
+
+ private static readonly List ExtraButtons = new List
{
- public BizKeyboardService(Machine _machine) : base(_machine) { }
- public override bool IsKeyDown(int key)
- {
- return key > 0;
- }
- }
+ "Previous Disk",
+ "Next Disk",
+ };
- private class BizAudioService : AudioService, ISyncSoundProvider
+ static AppleII()
{
- public BizAudioService(Machine _machine) : base(_machine) { }
- public override void SetVolume(float volume)
- {
- }
- public void DiscardSamples()
- {
- Reset();
- }
+ AppleIIController = new ControllerDefinition { Name = "Apple IIe Keyboard" };
+ AppleIIController.BoolButtons.AddRange(RealButtons);
+ AppleIIController.BoolButtons.AddRange(ExtraButtons);
}
private void FrameAdv(bool render, bool rendersound)
@@ -170,9 +129,8 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
{
DecrementDisk();
}
-
- _machine.Buttons = GetButtons();
- _machine.BizFrameAdvance();
+
+ _machine.BizFrameAdvance(RealButtons.Where(b => Controller[b]));
if (IsLagFrame)
{
LagCount++;
@@ -181,59 +139,5 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
Frame++;
}
- private Buttons GetButtons()
- {
- Jellyfish.Virtu.Buttons ret = 0;
- if (Controller["Up"]) ret |= Jellyfish.Virtu.Buttons.Up;
- if (Controller["Down"]) ret |= Jellyfish.Virtu.Buttons.Down;
- if (Controller["Left"]) ret |= Jellyfish.Virtu.Buttons.Left;
- if (Controller["Right"]) ret |= Jellyfish.Virtu.Buttons.Right;
- if (Controller["Tab"]) ret |= Jellyfish.Virtu.Buttons.Tab;
- if (Controller["Enter"]) ret |= Jellyfish.Virtu.Buttons.Enter;
- if (Controller["Escape"]) ret |= Jellyfish.Virtu.Buttons.Escape;
- if (Controller["Back"]) ret |= Jellyfish.Virtu.Buttons.Back;
- if (Controller["Space"]) ret |= Jellyfish.Virtu.Buttons.Space;
- if (Controller["Ctrl"]) ret |= Jellyfish.Virtu.Buttons.Ctrl;
- if (Controller["Shift"]) ret |= Jellyfish.Virtu.Buttons.Shift;
- if (Controller["Caps"]) ret |= Jellyfish.Virtu.Buttons.Caps;
- if (Controller["1"]) ret |= Jellyfish.Virtu.Buttons.Key1;
- if (Controller["2"]) ret |= Jellyfish.Virtu.Buttons.Key2;
- if (Controller["3"]) ret |= Jellyfish.Virtu.Buttons.Key3;
- if (Controller["4"]) ret |= Jellyfish.Virtu.Buttons.Key4;
- if (Controller["5"]) ret |= Jellyfish.Virtu.Buttons.Key5;
- if (Controller["6"]) ret |= Jellyfish.Virtu.Buttons.Key6;
- if (Controller["7"]) ret |= Jellyfish.Virtu.Buttons.Key7;
- if (Controller["8"]) ret |= Jellyfish.Virtu.Buttons.Key8;
- if (Controller["9"]) ret |= Jellyfish.Virtu.Buttons.Key9;
- if (Controller["0"]) ret |= Jellyfish.Virtu.Buttons.Key0;
- if (Controller["A"]) ret |= Jellyfish.Virtu.Buttons.KeyA;
- if (Controller["B"]) ret |= Jellyfish.Virtu.Buttons.KeyB;
- if (Controller["C"]) ret |= Jellyfish.Virtu.Buttons.KeyC;
- if (Controller["D"]) ret |= Jellyfish.Virtu.Buttons.KeyD;
- if (Controller["E"]) ret |= Jellyfish.Virtu.Buttons.KeyE;
- if (Controller["F"]) ret |= Jellyfish.Virtu.Buttons.KeyF;
- if (Controller["G"]) ret |= Jellyfish.Virtu.Buttons.KeyG;
- if (Controller["H"]) ret |= Jellyfish.Virtu.Buttons.KeyH;
- if (Controller["I"]) ret |= Jellyfish.Virtu.Buttons.KeyI;
- if (Controller["J"]) ret |= Jellyfish.Virtu.Buttons.KeyJ;
- if (Controller["K"]) ret |= Jellyfish.Virtu.Buttons.KeyK;
- if (Controller["L"]) ret |= Jellyfish.Virtu.Buttons.KeyL;
- if (Controller["M"]) ret |= Jellyfish.Virtu.Buttons.KeyM;
- if (Controller["N"]) ret |= Jellyfish.Virtu.Buttons.KeyN;
- if (Controller["O"]) ret |= Jellyfish.Virtu.Buttons.KeyO;
- if (Controller["P"]) ret |= Jellyfish.Virtu.Buttons.KeyP;
- if (Controller["Q"]) ret |= Jellyfish.Virtu.Buttons.KeyQ;
- if (Controller["R"]) ret |= Jellyfish.Virtu.Buttons.KeyR;
- if (Controller["S"]) ret |= Jellyfish.Virtu.Buttons.KeyS;
- if (Controller["T"]) ret |= Jellyfish.Virtu.Buttons.KeyT;
- if (Controller["U"]) ret |= Jellyfish.Virtu.Buttons.KeyU;
- if (Controller["V"]) ret |= Jellyfish.Virtu.Buttons.KeyV;
- if (Controller["W"]) ret |= Jellyfish.Virtu.Buttons.KeyW;
- if (Controller["X"]) ret |= Jellyfish.Virtu.Buttons.KeyX;
- if (Controller["Y"]) ret |= Jellyfish.Virtu.Buttons.KeyY;
- if (Controller["Z"]) ret |= Jellyfish.Virtu.Buttons.KeyZ;
-
- return ret;
- }
}
}
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VRC7.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VRC7.cs
index 2c84cf4106..0012ee430c 100644
--- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VRC7.cs
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VRC7.cs
@@ -130,7 +130,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
}
prg_bank_mask_8k = Cart.prg_size / 8 - 1;
- chr_bank_mask_1k = Cart.chr_size - 1;
+ chr_bank_mask_1k = 0xff; // Cart.chr_size - 1;
SetMirrorType(EMirrorType.Vertical);
diff --git a/ExternalCoreProjects/Virtu/Cassette.cs b/ExternalCoreProjects/Virtu/Cassette.cs
index 93abdb9d2f..0cde6083b2 100644
--- a/ExternalCoreProjects/Virtu/Cassette.cs
+++ b/ExternalCoreProjects/Virtu/Cassette.cs
@@ -4,18 +4,17 @@ namespace Jellyfish.Virtu
{
public sealed class Cassette : MachineComponent
{
+ public Cassette() { }
public Cassette(Machine machine) :
base(machine)
{
}
- [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public bool ReadInput()
{
return false;
}
- [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void ToggleOutput()
{
}
diff --git a/ExternalCoreProjects/Virtu/Cpu.cs b/ExternalCoreProjects/Virtu/Cpu.cs
index 816908ae25..c05f799f32 100644
--- a/ExternalCoreProjects/Virtu/Cpu.cs
+++ b/ExternalCoreProjects/Virtu/Cpu.cs
@@ -7,6 +7,7 @@ namespace Jellyfish.Virtu
{
public sealed partial class Cpu : MachineComponent
{
+ public Cpu() { }
public Cpu(Machine machine) :
base(machine)
{
@@ -169,44 +170,6 @@ namespace Jellyfish.Virtu
}
}
- public override void LoadState(BinaryReader reader, Version version)
- {
- if (reader == null)
- {
- throw new ArgumentNullException("reader");
- }
-
- Is65C02 = reader.ReadBoolean();
- IsThrottled = reader.ReadBoolean();
- Multiplier = reader.ReadInt32();
-
- RA = reader.ReadInt32();
- RX = reader.ReadInt32();
- RY = reader.ReadInt32();
- RS = reader.ReadInt32();
- RP = reader.ReadInt32();
- RPC = reader.ReadInt32();
- }
-
- public override void SaveState(BinaryWriter writer)
- {
- if (writer == null)
- {
- throw new ArgumentNullException("writer");
- }
-
- writer.Write(Is65C02);
- writer.Write(IsThrottled);
- writer.Write(Multiplier);
-
- writer.Write(RA);
- writer.Write(RX);
- writer.Write(RY);
- writer.Write(RS);
- writer.Write(RP);
- writer.Write(RPC);
- }
-
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "A = 0x{0:X2} X = 0x{1:X2} Y = 0x{2:X2} P = 0x{3:X2} S = 0x01{4:X2} PC = 0x{5:X4} EA = 0x{6:X4} CC = {7}",
@@ -214,14 +177,15 @@ namespace Jellyfish.Virtu
}
public int Execute()
- {
- CC = 0;
+ {
+ CC = 0;
OpCode = _memory.Read(RPC);
RPC = (RPC + 1) & 0xFFFF;
_executeOpCode[OpCode]();
Cycles += CC;
- return CC;
+
+ return CC;
}
#region Core Operand Actions
@@ -3238,6 +3202,7 @@ namespace Jellyfish.Virtu
}
#endregion
+ [Newtonsoft.Json.JsonIgnore]
public bool Is65C02 { get { return _is65C02; } set { _is65C02 = value; _executeOpCode = _is65C02 ? ExecuteOpCode65C02 : ExecuteOpCode65N02; } }
public bool IsThrottled { get; set; }
public int Multiplier { get; set; }
diff --git a/ExternalCoreProjects/Virtu/CpuData.cs b/ExternalCoreProjects/Virtu/CpuData.cs
index b0baaefc1d..e21859092c 100644
--- a/ExternalCoreProjects/Virtu/CpuData.cs
+++ b/ExternalCoreProjects/Virtu/CpuData.cs
@@ -6,8 +6,8 @@ namespace Jellyfish.Virtu
{
private const int OpCodeCount = 256;
- private readonly Action[] ExecuteOpCode65N02;
- private readonly Action[] ExecuteOpCode65C02;
+ private Action[] ExecuteOpCode65N02;
+ private Action[] ExecuteOpCode65C02;
private const int PC = 0x01;
private const int PZ = 0x02;
diff --git a/ExternalCoreProjects/Virtu/Disk525.cs b/ExternalCoreProjects/Virtu/Disk525.cs
index 888a536813..0dccaf1c2a 100644
--- a/ExternalCoreProjects/Virtu/Disk525.cs
+++ b/ExternalCoreProjects/Virtu/Disk525.cs
@@ -8,6 +8,7 @@ namespace Jellyfish.Virtu
{
public abstract class Disk525
{
+ public Disk525() { }
protected Disk525(string name, byte[] data, bool isWriteProtected)
{
Name = name;
@@ -15,43 +16,13 @@ namespace Jellyfish.Virtu
IsWriteProtected = isWriteProtected;
}
- public static Disk525 CreateDisk(string name, Stream stream, bool isWriteProtected)
+ public static Disk525 CreateDisk(string name, byte[] data, bool isWriteProtected)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
- if (name.EndsWith(".do", StringComparison.OrdinalIgnoreCase) ||
- name.EndsWith(".dsk", StringComparison.OrdinalIgnoreCase)) // assumes dos sector skew
- {
- return new DiskDsk(name, stream, isWriteProtected, SectorSkew.Dos);
- }
- else if (name.EndsWith(".nib", StringComparison.OrdinalIgnoreCase))
- {
- return new DiskNib(name, stream, isWriteProtected);
- }
- else if (name.EndsWith(".po", StringComparison.OrdinalIgnoreCase))
- {
- return new DiskDsk(name, stream, isWriteProtected, SectorSkew.ProDos);
- }
-
- return null;
- }
-
- [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "version")]
- public static Disk525 LoadState(BinaryReader reader, Version version)
- {
- if (reader == null)
- {
- throw new ArgumentNullException("reader");
- }
-
- string name = reader.ReadString();
- var dataSize = reader.ReadInt32();
- var data = reader.ReadBytes(dataSize);
- bool isWriteProtected = reader.ReadBoolean();
-
if (name.EndsWith(".do", StringComparison.OrdinalIgnoreCase) ||
name.EndsWith(".dsk", StringComparison.OrdinalIgnoreCase)) // assumes dos sector skew
{
@@ -69,19 +40,6 @@ namespace Jellyfish.Virtu
return null;
}
- public void SaveState(BinaryWriter writer)
- {
- if (writer == null)
- {
- throw new ArgumentNullException("writer");
- }
-
- writer.Write(Name);
- writer.Write(Data.Length);
- writer.Write(Data);
- writer.Write(IsWriteProtected);
- }
-
public abstract void ReadTrack(int number, int fraction, byte[] buffer);
public abstract void WriteTrack(int number, int fraction, byte[] buffer);
diff --git a/ExternalCoreProjects/Virtu/DiskDsk.cs b/ExternalCoreProjects/Virtu/DiskDsk.cs
index 90cc81add1..11c3a598f6 100644
--- a/ExternalCoreProjects/Virtu/DiskDsk.cs
+++ b/ExternalCoreProjects/Virtu/DiskDsk.cs
@@ -8,6 +8,7 @@ namespace Jellyfish.Virtu
public sealed class DiskDsk : Disk525
{
+ public DiskDsk() { }
public DiskDsk(string name, byte[] data, bool isWriteProtected, SectorSkew sectorSkew) :
base(name, data, isWriteProtected)
{
diff --git a/ExternalCoreProjects/Virtu/DiskIIController.cs b/ExternalCoreProjects/Virtu/DiskIIController.cs
index 99d579ed8c..a969f4bfc9 100644
--- a/ExternalCoreProjects/Virtu/DiskIIController.cs
+++ b/ExternalCoreProjects/Virtu/DiskIIController.cs
@@ -4,11 +4,13 @@ using System.Diagnostics.CodeAnalysis;
using System.IO;
using Jellyfish.Library;
using Jellyfish.Virtu.Services;
+using System.Collections.Generic;
namespace Jellyfish.Virtu
{
public sealed class DiskIIController : PeripheralCard
{
+ public DiskIIController() { }
public DiskIIController(Machine machine, byte[] diskIIRom) :
base(machine)
{
@@ -16,7 +18,7 @@ namespace Jellyfish.Virtu
Drive1 = new DiskIIDrive(machine);
Drive2 = new DiskIIDrive(machine);
- Drives = new Collection { Drive1, Drive2 };
+ Drives = new List { Drive1, Drive2 };
BootDrive = Drive1;
}
@@ -32,50 +34,6 @@ namespace Jellyfish.Virtu
_writeMode = false;
}
- public override void LoadState(BinaryReader reader, Version version)
- {
- if (reader == null)
- {
- throw new ArgumentNullException("reader");
- }
-
- _latch = reader.ReadInt32();
- _phaseStates = reader.ReadInt32();
- _motorOn = reader.ReadBoolean();
- _driveNumber = reader.ReadInt32();
- _loadMode = reader.ReadBoolean();
- _writeMode = reader.ReadBoolean();
- _driveSpin = reader.ReadBoolean();
- foreach (var drive in Drives)
- {
- DebugService.WriteMessage("Loading machine '{0}'", drive.GetType().Name);
- drive.LoadState(reader, version);
- //DebugService.WriteMessage("Loaded machine '{0}'", drive.GetType().Name);
- }
- }
-
- public override void SaveState(BinaryWriter writer)
- {
- if (writer == null)
- {
- throw new ArgumentNullException("writer");
- }
-
- writer.Write(_latch);
- writer.Write(_phaseStates);
- writer.Write(_motorOn);
- writer.Write(_driveNumber);
- writer.Write(_loadMode);
- writer.Write(_writeMode);
- writer.Write(_driveSpin);
- foreach (var drive in Drives)
- {
- DebugService.WriteMessage("Saving machine '{0}'", drive.GetType().Name);
- drive.SaveState(writer);
- //DebugService.WriteMessage("Saved machine '{0}'", drive.GetType().Name);
- }
- }
-
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
public override int ReadIoRegionC0C0(int address)
{
@@ -263,7 +221,7 @@ namespace Jellyfish.Virtu
public DiskIIDrive Drive1 { get; private set; }
public DiskIIDrive Drive2 { get; private set; }
- public Collection Drives { get; private set; }
+ public List Drives { get; private set; }
public DiskIIDrive BootDrive { get; private set; }
diff --git a/ExternalCoreProjects/Virtu/DiskIIDrive.cs b/ExternalCoreProjects/Virtu/DiskIIDrive.cs
index c59c2cf096..8dbb6e75b2 100644
--- a/ExternalCoreProjects/Virtu/DiskIIDrive.cs
+++ b/ExternalCoreProjects/Virtu/DiskIIDrive.cs
@@ -7,6 +7,7 @@ namespace Jellyfish.Virtu
{
public sealed class DiskIIDrive : MachineComponent
{
+ public DiskIIDrive() { }
public DiskIIDrive(Machine machine) :
base(machine)
{
@@ -16,60 +17,11 @@ namespace Jellyfish.Virtu
DriveArmStepDelta[3] = new int[] { 0, 1, 0, 1, -1, 0, -1, 0, 0, 1, 0, 1, -1, 0, -1, 0 }; // phase 3
}
- public override void LoadState(BinaryReader reader, Version version)
- {
- if (reader == null)
- {
- throw new ArgumentNullException("reader");
- }
-
- _trackLoaded = reader.ReadBoolean();
- _trackChanged = reader.ReadBoolean();
- _trackNumber = reader.ReadInt32();
- _trackOffset = reader.ReadInt32();
- if (_trackLoaded)
- {
- reader.Read(_trackData, 0, _trackData.Length);
- }
- if (reader.ReadBoolean())
- {
- DebugService.WriteMessage("Loading machine '{0}'", typeof(Disk525).Name);
- _disk = Disk525.LoadState(reader, version);
- }
- else
- {
- _disk = null;
- }
- }
-
- public override void SaveState(BinaryWriter writer)
- {
- if (writer == null)
- {
- throw new ArgumentNullException("writer");
- }
-
- writer.Write(_trackLoaded);
- writer.Write(_trackChanged);
- writer.Write(_trackNumber);
- writer.Write(_trackOffset);
- if (_trackLoaded)
- {
- writer.Write(_trackData);
- }
- writer.Write(_disk != null);
- if (_disk != null)
- {
- DebugService.WriteMessage("Saving machine '{0}'", _disk.GetType().Name);
- _disk.SaveState(writer);
- }
- }
-
- public void InsertDisk(string name, Stream stream, bool isWriteProtected)
+ public void InsertDisk(string name, byte[] data, bool isWriteProtected)
{
DebugService.WriteMessage("Inserting disk '{0}'", name);
FlushTrack();
- _disk = Disk525.CreateDisk(name, stream, isWriteProtected);
+ _disk = Disk525.CreateDisk(name, data, isWriteProtected);
_trackLoaded = false;
}
@@ -116,7 +68,9 @@ namespace Jellyfish.Virtu
return data;
}
- return _random.Next(0x01, 0xFF);
+ return 0x80;
+ // TODO: WTF was this
+ //return _random.Next(0x01, 0xFF);
}
public void Write(int data)
@@ -152,13 +106,14 @@ namespace Jellyfish.Virtu
}
}
+ [Newtonsoft.Json.JsonIgnore]
public bool IsWriteProtected { get { return _disk.IsWriteProtected; } }
private const int TrackNumberMax = 0x44;
private const int PhaseCount = 4;
- private readonly int[][] DriveArmStepDelta = new int[PhaseCount][];
+ private int[][] DriveArmStepDelta = new int[PhaseCount][];
private bool _trackLoaded;
private bool _trackChanged;
@@ -166,7 +121,5 @@ namespace Jellyfish.Virtu
private int _trackOffset;
private byte[] _trackData = new byte[Disk525.TrackSize];
private Disk525 _disk;
-
- private Random _random = new Random();
}
}
diff --git a/ExternalCoreProjects/Virtu/DiskNib.cs b/ExternalCoreProjects/Virtu/DiskNib.cs
index e186e007c2..e3c0db90c1 100644
--- a/ExternalCoreProjects/Virtu/DiskNib.cs
+++ b/ExternalCoreProjects/Virtu/DiskNib.cs
@@ -6,6 +6,7 @@ namespace Jellyfish.Virtu
{
public sealed class DiskNib : Disk525
{
+ public DiskNib() { }
public DiskNib(string name, byte[] data, bool isWriteProtected) :
base(name, data, isWriteProtected)
{
diff --git a/ExternalCoreProjects/Virtu/ExtraConverters.cs b/ExternalCoreProjects/Virtu/ExtraConverters.cs
new file mode 100644
index 0000000000..2e66bfc438
--- /dev/null
+++ b/ExternalCoreProjects/Virtu/ExtraConverters.cs
@@ -0,0 +1,184 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using Newtonsoft.Json.Linq;
+using System.Reflection;
+
+namespace Jellyfish.Virtu
+{
+ public class ArrayConverter : JsonConverter
+ {
+ // JSON.NET cannot, when reading, use PreserveReferencesHandling on arrays, although it fully supports it on writing.
+ // stupid decision, but there you have it. we need that to work here.
+
+ // as an added "bonus", this disables base64ing of byte[] arrays.
+ // TODO: optimize the byte/short/int cases.
+
+ // TODO: on serialization, the type of the object is available, but is the expected type (ie, the one that we'll be fed during deserialization) available?
+ // need this to at least detect covariance cases...
+
+ public override bool CanConvert(Type objectType)
+ {
+ if (!typeof(Array).IsAssignableFrom(objectType))
+ return false;
+
+ if (objectType.GetArrayRank() > 1)
+ throw new NotImplementedException();
+
+ return true;
+ }
+
+ public override bool CanRead { get { return true; } }
+ public override bool CanWrite { get { return true; } }
+
+ int nextRef = 1;
+ Dictionary