BizHawk/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs

205 lines
5.0 KiB
C#
Raw Normal View History

2016-02-28 14:15:52 +00:00
using System.Collections.Generic;
using System.Linq;
2016-02-28 14:15:52 +00:00
2015-02-17 22:58:25 +00:00
using BizHawk.Emulation.Common;
using Jellyfish.Virtu;
namespace BizHawk.Emulation.Cores.Computers.AppleII
{
[CoreAttributes(
"Virtu",
"fool",
2015-02-17 22:58:25 +00:00
isPorted: true,
isReleased: true
2015-02-17 22:58:25 +00:00
)]
[ServiceNotApplicable(typeof(ISaveRam), typeof(IRegionable))]
public partial class AppleII : IEmulator, ISoundProvider, IVideoProvider, IStatable, IDriveLight
2015-02-17 22:58:25 +00:00
{
2015-06-16 23:24:52 +00:00
public AppleII(CoreComm comm, IEnumerable<GameInfo> gameInfoSet, IEnumerable<byte[]> romSet, Settings settings)
: this(comm, gameInfoSet.First(), romSet.First(), settings)
{
GameInfoSet = gameInfoSet.ToList();
RomSet = romSet.ToList();
}
2015-02-17 22:58:25 +00:00
[CoreConstructor("AppleII")]
2015-06-16 23:24:52 +00:00
public AppleII(CoreComm comm, GameInfo game, byte[] rom, Settings settings)
2015-02-17 22:58:25 +00:00
{
2015-04-13 00:46:11 +00:00
GameInfoSet = new List<GameInfo>();
2015-02-17 22:58:25 +00:00
var ser = new BasicServiceProvider(this);
ServiceProvider = ser;
CoreComm = comm;
2016-02-28 14:15:52 +00:00
Tracer = new TraceBuffer
{
Header = "6502: PC, opcode, register (A, X, Y, P, SP, Cy), flags (NVTBDIZC)"
2016-02-28 14:15:52 +00:00
};
MemoryCallbacks = new MemoryCallbackSystem();
InputCallbacks = new InputCallbackSystem();
2015-02-17 22:58:25 +00:00
_disk1 = rom;
RomSet.Add(rom);
2015-02-17 22:58:25 +00:00
_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");
2015-02-18 00:06:49 +00:00
_machine = new Machine(_appleIIRom, _diskIIRom);
2015-02-18 00:06:49 +00:00
_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
2015-05-18 00:14:00 +00:00
InitDisk();
ser.Register<ITraceable>(Tracer);
setCallbacks();
2015-05-18 01:30:30 +00:00
InitSaveStates();
SetupMemoryDomains();
2015-06-16 23:24:52 +00:00
PutSettings(settings ?? new Settings());
2015-02-18 00:06:49 +00:00
}
2015-04-13 00:46:11 +00:00
public List<GameInfo> GameInfoSet { get; private set; }
private readonly List<byte[]> RomSet = new List<byte[]>();
public int CurrentDisk { get; private set; }
2015-04-13 00:46:11 +00:00
public int DiskCount { get { return RomSet.Count; } }
private ITraceable Tracer { get; set; }
2015-04-13 00:46:11 +00:00
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
2015-05-18 00:14:00 +00:00
_machine.BootDiskII.Drives[0].InsertDisk("junk.dsk", (byte[])_disk1.Clone(), false);
}
2015-05-18 00:14:00 +00:00
private Machine _machine;
private byte[] _disk1;
2015-02-17 22:58:25 +00:00
private readonly byte[] _appleIIRom;
private readonly byte[] _diskIIRom;
2015-05-18 00:14:00 +00:00
private static readonly ControllerDefinition AppleIIController;
private static readonly List<string> RealButtons = new List<string>(Keyboard.GetKeyNames()
.Where(k => k != "White Apple") // Hack because these buttons aren't wired up yet
.Where(k => k != "Black Apple")
.Where(k => k != "Reset"));
2015-05-18 00:14:00 +00:00
private static readonly List<string> ExtraButtons = new List<string>
{
2015-05-18 00:14:00 +00:00
"Previous Disk",
"Next Disk",
};
2015-05-18 00:14:00 +00:00
static AppleII()
{
2015-05-18 00:14:00 +00:00
AppleIIController = new ControllerDefinition { Name = "Apple IIe Keyboard" };
AppleIIController.BoolButtons.AddRange(RealButtons);
AppleIIController.BoolButtons.AddRange(ExtraButtons);
}
2015-05-19 23:33:50 +00:00
public bool DriveLightEnabled { get { return true; } }
public bool DriveLightOn { get { return _machine.DriveLight; } }
private bool _nextPressed = false;
private bool _prevPressed = false;
private void TracerWrapper(string[] content)
{
Tracer.Put(new TraceInfo
{
Disassembly = content[0],
RegisterInfo = content[1]
});
}
2015-03-21 21:45:12 +00:00
private void FrameAdv(bool render, bool rendersound)
{
if (Tracer.Enabled)
{
_machine.Cpu.TraceCallback = (s) => TracerWrapper(s);
}
else
{
_machine.Cpu.TraceCallback = null;
}
if (Controller.IsPressed("Next Disk") && !_nextPressed)
{
_nextPressed = true;
IncrementDisk();
}
else if (Controller.IsPressed("Previous Disk") && !_prevPressed)
{
_prevPressed = true;
DecrementDisk();
}
2015-05-18 00:14:00 +00:00
if (!Controller.IsPressed("Next Disk"))
{
_nextPressed = false;
}
if (!Controller.IsPressed("Previous Disk"))
{
_prevPressed = false;
}
_machine.BizFrameAdvance(RealButtons.Where(b => Controller.IsPressed(b)));
if (IsLagFrame)
{
LagCount++;
}
2015-03-21 21:45:12 +00:00
Frame++;
}
private void setCallbacks()
{
_machine.Memory.ReadCallback = MemoryCallbacks.CallReads;
_machine.Memory.WriteCallback = MemoryCallbacks.CallWrites;
_machine.Memory.ExecuteCallback = MemoryCallbacks.CallExecutes;
_machine.Memory.InputCallback = InputCallbacks.Call;
}
2015-02-17 22:58:25 +00:00
}
}