From 9f02fd75af1422c7c9c109143535946d79a8a992 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 21 Mar 2015 21:45:12 +0000 Subject: [PATCH] Apple II - some reorg --- .../BizHawk.Emulation.Cores.csproj | 9 + .../Computers/AppleII/AppleII.IEmulator.cs | 63 ++++ .../Computers/AppleII/AppleII.IStatable.cs | 55 ++++ .../AppleII/AppleII.IVideoProvider.cs | 47 +++ .../Computers/AppleII/AppleII.cs | 307 +++++------------- .../AppleII/Virtu/Services/GamePortService.cs | 2 +- 6 files changed, 253 insertions(+), 230 deletions(-) create mode 100644 BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IEmulator.cs create mode 100644 BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs create mode 100644 BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index c2b585a2ab..b2ae4a472f 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -116,6 +116,15 @@ + + 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 new file mode 100644 index 0000000000..2a031ec783 --- /dev/null +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IEmulator.cs @@ -0,0 +1,63 @@ +using BizHawk.Emulation.Common; + +namespace BizHawk.Emulation.Cores.Computers.AppleII +{ + public partial class AppleII : IEmulator + { + public IEmulatorServiceProvider ServiceProvider { get; private set; } + + [FeatureNotImplemented] + public ISoundProvider SoundProvider + { + get { return NullSound.SilenceProvider; } + } + + [FeatureNotImplemented] + public ISyncSoundProvider SyncSoundProvider + { + get { return new FakeSyncSound(NullSound.SilenceProvider, 735); } + } + + [FeatureNotImplemented] + public bool StartAsyncSound() + { + return true; + } + + [FeatureNotImplemented] + public void EndAsyncSound() { } + + public ControllerDefinition ControllerDefinition + { + get { return AppleIIController; } + } + + public IController Controller { get; set; } + + + public int Frame { get; set; } + + public string SystemId { get { return "AppleII"; } } + + public bool DeterministicEmulation { get { return true; } } + + public void FrameAdvance(bool render, bool rendersound) + { + FrameAdv(render, rendersound); + } + + public string BoardName { get { return null; } } + + public void ResetCounters() + { + Frame = 0; + } + + public CoreComm CoreComm { get; private set; } + + public void Dispose() + { + _machine.Dispose(); + } + } +} diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs new file mode 100644 index 0000000000..6e380cb67f --- /dev/null +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs @@ -0,0 +1,55 @@ +using BizHawk.Emulation.Common; +using System.IO; + +namespace BizHawk.Emulation.Cores.Computers.AppleII +{ + public partial class AppleII : IStatable + { + public bool BinarySaveStatesPreferred { get { return true; } } + + [FeatureNotImplemented] + public void SaveStateText(TextWriter writer) + { + + } + + [FeatureNotImplemented] + public void LoadStateText(TextReader reader) + { + + } + + public void SaveStateBinary(BinaryWriter writer) + { + _machine.SaveState(writer); + } + + public void LoadStateBinary(BinaryReader reader) + { + _machine.LoadState(reader); + } + + public byte[] SaveStateBinary() + { + if (_stateBuffer == null) + { + var stream = new MemoryStream(); + var writer = new BinaryWriter(stream); + SaveStateBinary(writer); + _stateBuffer = stream.ToArray(); + writer.Close(); + return _stateBuffer; + } + else + { + var stream = new MemoryStream(_stateBuffer); + var writer = new BinaryWriter(stream); + SaveStateBinary(writer); + writer.Close(); + return _stateBuffer; + } + } + + private byte[] _stateBuffer; + } +} diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs new file mode 100644 index 0000000000..ea2041f74e --- /dev/null +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs @@ -0,0 +1,47 @@ +using BizHawk.Emulation.Common; +using Jellyfish.Virtu; + +namespace BizHawk.Emulation.Cores.Computers.AppleII +{ + public partial class AppleII + { + public class BizVideoService : Jellyfish.Virtu.Services.VideoService, IVideoProvider + { + public int[] fb; + + int[] IVideoProvider.GetVideoBuffer() { return 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; } } + + 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 9d70bf2735..a70bcc871e 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs @@ -1,6 +1,7 @@ using System.IO; using BizHawk.Emulation.Common; using Jellyfish.Virtu; +using Jellyfish.Virtu.Services; namespace BizHawk.Emulation.Cores.Computers.AppleII { @@ -50,62 +51,6 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII Jellyfish.Virtu.Services.StorageService.LoadFile(ms, stream => _machine.BootDiskII.Drives[0].InsertDisk("junk.dsk", stream, writeProtected)); } - class BizKeyboardService : Jellyfish.Virtu.Services.KeyboardService - { - public BizKeyboardService(Machine _machine) : base(_machine) { } - public override bool IsKeyDown(int key) - { - return key > 0; - } - } - - class BizAudioService : Jellyfish.Virtu.Services.AudioService - { - public BizAudioService(Machine _machine) : base(_machine) { } - public override void SetVolume(float volume) - { - - } - } - - public class BizVideoService : Jellyfish.Virtu.Services.VideoService, IVideoProvider - { - public int[] fb; - - int[] IVideoProvider.GetVideoBuffer() { return 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; } } - - 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() - { - } - } - - private readonly Machine _machine; private readonly byte[] _disk1; private readonly byte[] _appleIIRom; @@ -118,189 +63,93 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII BoolButtons = { "Up", "Down", "Left", "Right", - "Tab", "Enter", "Escape", "Back", "Space", - "Ctrl", "Shift", "Caps", - //there has got to be a better way than assigning every one of these manually - "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" + "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" } }; + private class BizKeyboardService : KeyboardService + { + public BizKeyboardService(Machine _machine) : base(_machine) { } + public override bool IsKeyDown(int key) + { + return key > 0; + } + } + + private class BizAudioService : AudioService + { + public BizAudioService(Machine _machine) : base(_machine) { } + public override void SetVolume(float volume) + { + + } + } + private void FrameAdv(bool render, bool rendersound) { - _machine.Buttons = GetButtons(); + _machine.Buttons = GetButtons(); _machine.BizFrameAdvance(); Frame++; } - #region IEmulator - - public IEmulatorServiceProvider ServiceProvider { get; private set; } - - [FeatureNotImplemented] - public ISoundProvider SoundProvider + private Buttons GetButtons() { - get { return NullSound.SilenceProvider; } + 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; } - - [FeatureNotImplemented] - public ISyncSoundProvider SyncSoundProvider - { - get { return new FakeSyncSound(NullSound.SilenceProvider, 735); } - } - - [FeatureNotImplemented] - public bool StartAsyncSound() - { - return true; - } - - [FeatureNotImplemented] - public void EndAsyncSound() { } - - public ControllerDefinition ControllerDefinition - { - get { return AppleIIController; } - } - - public IController Controller { get; set; } - - - - Jellyfish.Virtu.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; - } - - public int Frame { get; set; } - - [FeatureNotImplemented] - public void FrameAdvance(bool render, bool rendersound) - { - FrameAdv(render, rendersound); - } - - public string SystemId { get { return "AppleII"; } } - - public bool DeterministicEmulation { get { return true; } } - - public string BoardName { get { return null; } } - - public void ResetCounters() - { - Frame = 0; - } - - public CoreComm CoreComm { get; private set; } - - public void Dispose() - { - _machine.Dispose(); - } - - #endregion - - #region IStatable - - public bool BinarySaveStatesPreferred { get { return true; } } - - [FeatureNotImplemented] - public void SaveStateText(TextWriter writer) - { - - } - - [FeatureNotImplemented] - public void LoadStateText(TextReader reader) - { - - } - - public void SaveStateBinary(BinaryWriter writer) - { - _machine.SaveState(writer); - } - - public void LoadStateBinary(BinaryReader reader) - { - _machine.LoadState(reader); - } - - public byte[] SaveStateBinary() - { - if (_stateBuffer == null) - { - var stream = new MemoryStream(); - var writer = new BinaryWriter(stream); - SaveStateBinary(writer); - _stateBuffer = stream.ToArray(); - writer.Close(); - return _stateBuffer; - } - else - { - var stream = new MemoryStream(_stateBuffer); - var writer = new BinaryWriter(stream); - SaveStateBinary(writer); - writer.Close(); - return _stateBuffer; - } - } - - private byte[] _stateBuffer; - - #endregion } } diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/GamePortService.cs b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/GamePortService.cs index 837612762a..0972680ba4 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/GamePortService.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/GamePortService.cs @@ -54,7 +54,7 @@ namespace Jellyfish.Virtu.Services } } - static int t = 0; + //static int t = 0; private void UpdateKey(ulong key, bool isActive, ref bool isKeyDown, ref bool wasKeyDown) {