diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs index 6ae03f9c67..dc15f8fa97 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII isPorted: true, isReleased: false )] - public partial class AppleII : IEmulator, IVideoProvider + public partial class AppleII : IEmulator { [CoreConstructor("AppleII")] public AppleII(CoreComm comm, GameInfo game, byte[] rom, object Settings) @@ -25,10 +25,86 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII _appleIIRom = File.ReadAllBytes("C:\\apple\\AppleIIe.rom"); _diskIIRom = File.ReadAllBytes("C:\\apple\\DiskII.rom"); - _machine = new Machine(); - _machine.Pause(); + + _machine = new Machine(); + + var vidService = new BizVideoService(_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), new BizAudioService(_machine)); + _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(rom,0,rom.Length); + ms.Position = 0; + bool writeProtected = false; //!!!!!!!!!!!!!!!!!!! + 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 false; //TODO! lol + } + } + + 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) + { + fb[560 * y + x] = (int)color; + } + public override void Update() + { + } + } + + private readonly Machine _machine; private readonly byte[] _disk1; private readonly byte[] _appleIIRom; @@ -46,38 +122,10 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII private void FrameAdv(bool render, bool rendersound) { - _machine.Unpause(); - while (!_machine.Video.IsVBlank) - { - // Do nothing - } - - while (_machine.Video.IsVBlank) - { - // Do nothing - } - - _machine.Pause(); - + _machine.BizFrameAdvance(); Frame++; } - #region IVideoProvider - - public int VirtualWidth { get { return 256; } } - public int VirtualHeight { get { return 192; } } - public int BufferWidth { get { return 256; } } - public int BufferHeight { get { return 192; } } - public int BackgroundColor { get { return 0; } } - - public int[] GetVideoBuffer() - { - //_machine.Video // Uh, yeah, something - return new int[BufferWidth * BufferHeight]; - } - - #endregion - #region IEmulator public IEmulatorServiceProvider ServiceProvider { get; private set; } diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/DiskIIController.cs b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/DiskIIController.cs index d082a118a4..d64b426399 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/DiskIIController.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/DiskIIController.cs @@ -22,7 +22,8 @@ namespace Jellyfish.Virtu public override void Initialize() { - StorageService.LoadResource("Roms/DiskII.rom", stream => stream.ReadBlock(_romRegionC1C7)); + //TODO lol!! + StorageService.LoadResource("c:\\apple\\DiskII.rom", stream => stream.ReadBlock(_romRegionC1C7)); } public override void Reset() diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Machine.cs b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Machine.cs index 0b66ad8189..75536e8578 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Machine.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Machine.cs @@ -40,7 +40,7 @@ namespace Jellyfish.Virtu BootDiskII = Slots.OfType().Last(); - Thread = new Thread(Run) { Name = "Machine" }; + //Thread = new Thread(Run) { Name = "Machine" }; } public void Dispose() @@ -59,48 +59,48 @@ namespace Jellyfish.Virtu } } - [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] - public void Start() - { - _debugService = Services.GetService(); - _storageService = Services.GetService(); + //[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] + //public void Start() + //{ + // _debugService = Services.GetService(); + // _storageService = Services.GetService(); - _debugService.WriteMessage("Starting machine"); - State = MachineState.Starting; - Thread.Start(); - } + // _debugService.WriteMessage("Starting machine"); + // State = MachineState.Starting; + // Thread.Start(); + //} - [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] - public void Pause() - { - _debugService.WriteMessage("Pausing machine"); - State = MachineState.Pausing; - _pauseEvent.WaitOne(); - State = MachineState.Paused; - _debugService.WriteMessage("Paused machine"); - } + //[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] + //public void Pause() + //{ + // _debugService.WriteMessage("Pausing machine"); + // State = MachineState.Pausing; + // _pauseEvent.WaitOne(); + // State = MachineState.Paused; + // _debugService.WriteMessage("Paused machine"); + //} - [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] - public void Unpause() - { - _debugService.WriteMessage("Running machine"); - State = MachineState.Running; - _unpauseEvent.Set(); - } + //[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] + //public void Unpause() + //{ + // _debugService.WriteMessage("Running machine"); + // State = MachineState.Running; + // _unpauseEvent.Set(); + //} - [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] - public void Stop() - { - _debugService.WriteMessage("Stopping machine"); - State = MachineState.Stopping; - _unpauseEvent.Set(); - if (Thread.IsAlive) - { - Thread.Join(); - } - State = MachineState.Stopped; - _debugService.WriteMessage("Stopped machine"); - } + //[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] + //public void Stop() + //{ + // _debugService.WriteMessage("Stopping machine"); + // State = MachineState.Stopping; + // _unpauseEvent.Set(); + // if (Thread.IsAlive) + // { + // Thread.Join(); + // } + // State = MachineState.Stopped; + // _debugService.WriteMessage("Stopped machine"); + //} private void Initialize() { @@ -201,40 +201,64 @@ namespace Jellyfish.Virtu } } - [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] - private void Run() // machine thread - { - Initialize(); - Reset(); - LoadState(); + //[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")] + //private void Run() // machine thread + //{ + // Initialize(); + // Reset(); + // LoadState(); - _debugService.WriteMessage("Running machine"); - State = MachineState.Running; - do - { - do - { - Events.HandleEvents(Cpu.Execute()); - } - while (State == MachineState.Running); + // _debugService.WriteMessage("Running machine"); + // State = MachineState.Running; + // do + // { + // do + // { + // Events.HandleEvents(Cpu.Execute()); + // } + // while (State == MachineState.Running); - if (State == MachineState.Pausing) - { - _pauseEvent.Set(); - _unpauseEvent.WaitOne(); - } - } - while (State != MachineState.Stopping); + // if (State == MachineState.Pausing) + // { + // _pauseEvent.Set(); + // _unpauseEvent.WaitOne(); + // } + // } + // while (State != MachineState.Stopping); - SaveState(); - Uninitialize(); - } + // SaveState(); + // Uninitialize(); + //} + + public void BizInitialize() + { + _debugService = Services.GetService(); + _storageService = Services.GetService(); + + Initialize(); + Reset(); + } + + public void BizFrameAdvance() + { + //frame begins at vsync.. beginning of vblank + while (Video.IsVBlank) + Events.HandleEvents(Cpu.Execute()); + //now, while not vblank, we're in a frame + while (!Video.IsVBlank) + Events.HandleEvents(Cpu.Execute()); + } + + public void BizShutdown() + { + Uninitialize(); + } public const string Version = "0.9.4.0"; public MachineEvents Events { get; private set; } public MachineServices Services { get; private set; } - public MachineState State { get { return _state; } private set { _state = value; } } + //public MachineState State { get { return _state; } private set { _state = value; } } public Cpu Cpu { get; private set; } public Memory Memory { get; private set; } @@ -265,7 +289,7 @@ namespace Jellyfish.Virtu private DebugService _debugService; private StorageService _storageService; - private volatile MachineState _state; + //private volatile MachineState _state; private AutoResetEvent _pauseEvent = new AutoResetEvent(false); private AutoResetEvent _unpauseEvent = new AutoResetEvent(false); diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Memory.cs b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Memory.cs index 683835fbf5..6b1498fac0 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Memory.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Memory.cs @@ -96,7 +96,8 @@ namespace Jellyfish.Virtu _video = Machine.Video; _noSlotClock = Machine.NoSlotClock; - StorageService.LoadResource("Roms/AppleIIe.rom", stream => + //TODO lol!! + StorageService.LoadResource("c:\\apple\\AppleIIe.rom", stream => { stream.SkipBlock(0x0100); stream.ReadBlock(_romInternalRegionC1CF); diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/KeyboardService.cs b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/KeyboardService.cs index 6068f47842..d49ba4ddb3 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/KeyboardService.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/KeyboardService.cs @@ -18,14 +18,16 @@ if (!_resetKeyDown) { _resetKeyDown = true; // entering reset; pause until key released - Machine.Pause(); - Machine.Reset(); + //TODO ADELIKAT : HANDLE RESET DIFFERENTLY + //Machine.Pause(); + //Machine.Reset(); } } else if (_resetKeyDown) { _resetKeyDown = false; // leaving reset - Machine.Unpause(); + //TODO ADELIKAT : HANDLE RESET DIFFERENTLY + //Machine.Unpause(); } } diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/StorageService.cs b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/StorageService.cs index b1a438e81b..f70ad21c0d 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/StorageService.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/Virtu/Services/StorageService.cs @@ -36,7 +36,7 @@ namespace Jellyfish.Virtu.Services [SecuritySafeCritical] #endif [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] - public static bool LoadFile(string fileName, Action reader) + public static bool LoadFile(Stream stream, Action reader) { if (reader == null) { @@ -45,8 +45,7 @@ namespace Jellyfish.Virtu.Services try { - DebugService.Default.WriteMessage("Loading file '{0}'", fileName); - using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) + DebugService.Default.WriteMessage("Loading file '{0}'", "STREAM"); { reader(stream); } @@ -103,10 +102,12 @@ namespace Jellyfish.Virtu.Services try { DebugService.Default.WriteMessage("Loading resource '{0}'", resourceName); - using (var stream = GetResourceStream(resourceName)) - { - reader(stream); - } + using (var stream = File.OpenRead(resourceName)) + reader(stream); + //using (var stream = GetResourceStream(resourceName)) + //{ + // reader(stream); + //} } catch (Exception ex) {