From 1bcf2ae684db0f61148e2d5550b6641e7355927d Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 12 Apr 2015 23:38:19 +0000 Subject: [PATCH] Apple II - multi-disc support using XmlGame (the same file format as dual GB), currently no ui to make an xml. Added Previous and Next Disk controller buttons --- BizHawk.Client.Common/RomLoader.cs | 10 +++ .../Computers/AppleII/AppleII.IStatable.cs | 3 + .../Computers/AppleII/AppleII.cs | 66 ++++++++++++++++++- .../Computers/AppleII/Virtu/Machine.cs | 5 ++ 4 files changed, 81 insertions(+), 3 deletions(-) diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index 2bcf2858ed..123c4265b2 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.IO; using BizHawk.Common; using BizHawk.Emulation.Common; @@ -337,6 +338,15 @@ namespace BizHawk.Client.Common // other stuff todo break; + case "AppleII": + var assets = xmlGame.Assets.Select(a => Database.GetGameInfo(a.Value, a.Key)); + var roms = xmlGame.Assets.Select(a => a.Value); + nextEmulator = new AppleII( + nextComm, + assets, + roms, + GetCoreSettings()); + break; default: return false; } diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs index 6e380cb67f..fde2b4dccb 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs @@ -21,11 +21,14 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII public void SaveStateBinary(BinaryWriter writer) { + writer.Write(CurrentDisk); _machine.SaveState(writer); } public void LoadStateBinary(BinaryReader reader) { + CurrentDisk = reader.ReadInt32(); + InitDisk(); _machine.LoadState(reader); } diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs index e536417e25..4f170a3f5f 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs @@ -4,6 +4,7 @@ using BizHawk.Emulation.Common; using Jellyfish.Virtu; using Jellyfish.Virtu.Services; using System; +using System.Collections.Generic; namespace BizHawk.Emulation.Cores.Computers.AppleII { @@ -15,6 +16,13 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII )] public partial class AppleII : IEmulator, IStatable { + public AppleII(CoreComm comm, IEnumerable gameInfoSet, IEnumerable romSet, object settings) + : this(comm, gameInfoSet.First(), romSet.First(), settings) + { + GameInfoSet = gameInfoSet.ToList(); + RomSet = romSet.ToList(); + } + [CoreConstructor("AppleII")] public AppleII(CoreComm comm, GameInfo game, byte[] rom, object Settings) { @@ -48,14 +56,56 @@ 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(rom,0,rom.Length); + 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)); } + private readonly List GameInfoSet; + private readonly List RomSet; + + public int CurrentDisk { get; private set; } + + private void IncrementDisk() + { + CurrentDisk++; + if (CurrentDisk >= RomSet.Count) + { + CurrentDisk = 0; + } + + InitDisk(); + } + + private void DecrementDisk() + { + CurrentDisk--; + if (CurrentDisk < 0) + { + CurrentDisk = RomSet.Count - 1; + } + + InitDisk(); + } + + + private void InitDisk() + { + _disk1 = RomSet[CurrentDisk]; + + //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(); + } + private readonly Machine _machine; - private readonly byte[] _disk1; + private byte[] _disk1; private readonly byte[] _appleIIRom; private readonly byte[] _diskIIRom; private readonly BizAudioService _soundService; @@ -72,7 +122,8 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII "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" + "S", "T", "U", "V", "W", "X", "Y", "Z", + "Next Disk", "Previous Disk" } }; @@ -99,6 +150,15 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII private void FrameAdv(bool render, bool rendersound) { + if (Controller["Next Disk"]) + { + IncrementDisk(); + } + else if (Controller["Previous Disk"]) + { + DecrementDisk(); + } + _machine.Buttons = GetButtons(); _machine.BizFrameAdvance(); Frame++; diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Machine.cs b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Machine.cs index 73d6041efb..fe25d4522a 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Machine.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Machine.cs @@ -320,6 +320,11 @@ namespace Jellyfish.Virtu Reset(); } + public void BizNewDisk() + { + _storageService = Services.GetService(); + } + public void BizFrameAdvance() { Services.GetService().Update();