145 lines
3.4 KiB
C#
145 lines
3.4 KiB
C#
using System.IO;
|
|
using System.Linq;
|
|
using BizHawk.Emulation.Common;
|
|
using Jellyfish.Virtu;
|
|
using Jellyfish.Virtu.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace BizHawk.Emulation.Cores.Computers.AppleII
|
|
{
|
|
[CoreAttributes(
|
|
"Virtu",
|
|
"TODO",
|
|
isPorted: true,
|
|
isReleased: false
|
|
)]
|
|
public partial class AppleII : IEmulator
|
|
{
|
|
public AppleII(CoreComm comm, IEnumerable<GameInfo> gameInfoSet, IEnumerable<byte[]> 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)
|
|
{
|
|
GameInfoSet = new List<GameInfo>();
|
|
|
|
var ser = new BasicServiceProvider(this);
|
|
ServiceProvider = ser;
|
|
CoreComm = comm;
|
|
|
|
_disk1 = rom;
|
|
RomSet.Add(rom);
|
|
|
|
_appleIIRom = comm.CoreFileProvider.GetFirmware(
|
|
SystemId, "AppleIIe", true, "The Apple IIe BIOS firmware is required");
|
|
_diskIIRom = comm.CoreFileProvider.GetFirmware(
|
|
SystemId, "DiskII", true, "The DiskII firmware is required");
|
|
|
|
_machine = new Machine(_appleIIRom, _diskIIRom);
|
|
|
|
_machine.BizInitialize();
|
|
|
|
//make a writeable memory stream cloned from the rom.
|
|
//for junk.dsk the .dsk is important because it determines the format from that
|
|
InitDisk();
|
|
|
|
InitSaveStates();
|
|
SetupMemoryDomains();
|
|
}
|
|
|
|
public List<GameInfo> GameInfoSet { get; private set; }
|
|
private readonly List<byte[]> RomSet = new List<byte[]>();
|
|
|
|
public int CurrentDisk { get; private set; }
|
|
public int DiskCount { get { return RomSet.Count; } }
|
|
|
|
public void SetDisk(int discNum)
|
|
{
|
|
CurrentDisk = discNum;
|
|
InitDisk();
|
|
}
|
|
|
|
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
|
|
|
|
bool writeProtected = false; //!!!!!!!!!!!!!!!!!!
|
|
_machine.BootDiskII.Drives[0].InsertDisk("junk.dsk", (byte[])_disk1.Clone(), false);
|
|
}
|
|
|
|
private Machine _machine;
|
|
private byte[] _disk1;
|
|
private readonly byte[] _appleIIRom;
|
|
private readonly byte[] _diskIIRom;
|
|
|
|
private static readonly ControllerDefinition AppleIIController;
|
|
|
|
private static readonly List<string> RealButtons = new List<string>(Keyboard.GetKeyNames());
|
|
|
|
private static readonly List<string> ExtraButtons = new List<string>
|
|
{
|
|
"Previous Disk",
|
|
"Next Disk",
|
|
};
|
|
|
|
static AppleII()
|
|
{
|
|
AppleIIController = new ControllerDefinition { Name = "Apple IIe Keyboard" };
|
|
AppleIIController.BoolButtons.AddRange(RealButtons);
|
|
AppleIIController.BoolButtons.AddRange(ExtraButtons);
|
|
}
|
|
|
|
private void FrameAdv(bool render, bool rendersound)
|
|
{
|
|
if (Controller["Next Disk"])
|
|
{
|
|
IncrementDisk();
|
|
}
|
|
else if (Controller["Previous Disk"])
|
|
{
|
|
DecrementDisk();
|
|
}
|
|
|
|
_machine.BizFrameAdvance(RealButtons.Where(b => Controller[b]));
|
|
if (IsLagFrame)
|
|
{
|
|
LagCount++;
|
|
}
|
|
|
|
Frame++;
|
|
}
|
|
|
|
}
|
|
}
|