From 409339566dd218868d43875a1cdbdf3d5bf1c2a8 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 5 Jun 2012 20:31:32 +0000 Subject: Updated headers and reorganised to use new update mechanisms. Emulation now needs rewriting to try emulating screen via NMI generation and ULA processing. --- WPZX81.sln | 34 ++- WPZX81/WPZX81/AboutPage.xaml.cs | 19 +- WPZX81/WPZX81/App.xaml.cs | 33 ++- WPZX81/WPZX81/ApplicationIcon.png | Bin 3601 -> 9244 bytes WPZX81/WPZX81/Background.png | Bin 36309 -> 62390 bytes WPZX81/WPZX81/Converters/ConvertFlagsToString.cs | 59 +++++ WPZX81/WPZX81/Converters/ConvertIntToHex2.cs | 42 ++++ WPZX81/WPZX81/Converters/ConvertIntToHex4.cs | 42 ++++ WPZX81/WPZX81/GamePage.xaml.cs | 267 ++++++++++++++++++++- WPZX81/WPZX81/MainPage.xaml | 6 +- WPZX81/WPZX81/MainPage.xaml.cs | 23 +- WPZX81/WPZX81/Resources/Strings.Designer.cs | 57 +---- WPZX81/WPZX81/Resources/Strings.resx | 23 +- WPZX81/WPZX81/Resources/ZX81.keyboard | Bin 0 -> 914 bytes WPZX81/WPZX81/Resources/controls.keyboard | Bin 0 -> 125 bytes WPZX81/WPZX81/Resources/keyboard_image.png | Bin 0 -> 1355399 bytes WPZX81/WPZX81/Settings.cs | 36 +-- WPZX81/WPZX81/SettingsPage.xaml | 5 +- WPZX81/WPZX81/SettingsPage.xaml.cs | 25 +- WPZX81/WPZX81/Shared.cs | 40 ++- WPZX81/WPZX81/ViewKeyboardPage.xaml | 24 ++ WPZX81/WPZX81/ViewKeyboardPage.xaml.cs | 40 +++ WPZX81/WPZX81/ViewModels/BaseViewModel.cs | 19 +- WPZX81/WPZX81/WPZX81.csproj | 30 ++- WPZX81/WPZX81/ZX81/Emulation.cs | 223 +++++------------ WPZX81/WPZX81/ZX81/ZX81KeySymbol.cs | 38 +++ .../WPZX81LibContent/WPZX81LibContent.contentproj | 27 +++ WPZX81/WPZX81LibContent/button.png | Bin 0 -> 4370 bytes WPZX81/WPZX81LibContent/controls.png | Bin 0 -> 2518 bytes WPZX81/WPZX81LibContent/joystick.png | Bin 0 -> 12582 bytes WPZX81/WPZX81LibContent/joystick_background.png | Bin 0 -> 8839 bytes WPZX81/WPZX81LibContent/keyboard.png | Bin 0 -> 3395 bytes non-solution items/controls.pspimage | Bin 11463 -> 12050 bytes non-solution items/joystick_background.pspimage | Bin 1712 -> 45677 bytes non-solution items/keyboard_image.jpg | Bin 0 -> 5993543 bytes 35 files changed, 813 insertions(+), 299 deletions(-) create mode 100644 WPZX81/WPZX81/Converters/ConvertFlagsToString.cs create mode 100644 WPZX81/WPZX81/Converters/ConvertIntToHex2.cs create mode 100644 WPZX81/WPZX81/Converters/ConvertIntToHex4.cs create mode 100644 WPZX81/WPZX81/Resources/ZX81.keyboard create mode 100644 WPZX81/WPZX81/Resources/controls.keyboard create mode 100644 WPZX81/WPZX81/Resources/keyboard_image.png create mode 100644 WPZX81/WPZX81/ViewKeyboardPage.xaml create mode 100644 WPZX81/WPZX81/ViewKeyboardPage.xaml.cs create mode 100644 WPZX81/WPZX81/ZX81/ZX81KeySymbol.cs create mode 100644 WPZX81/WPZX81LibContent/button.png create mode 100644 WPZX81/WPZX81LibContent/controls.png create mode 100644 WPZX81/WPZX81LibContent/joystick.png create mode 100644 WPZX81/WPZX81LibContent/joystick_background.png create mode 100644 WPZX81/WPZX81LibContent/keyboard.png create mode 100644 non-solution items/keyboard_image.jpg diff --git a/WPZX81.sln b/WPZX81.sln index 4d26e48..cba2e45 100644 --- a/WPZX81.sln +++ b/WPZX81.sln @@ -13,7 +13,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Noddybox.Emulation.EightBit EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Noddybox.Emulation.EightBit.Z80", "..\Noddybox.Emulation\WindowsPhone\Noddybox.Emulation.EightBit.Z80\Noddybox.Emulation.EightBit.Z80.csproj", "{7F257886-40D3-4E2A-BA9C-C5FEE93C08E9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Noddybox.Emulation.EightBit.Z80.Disassembler", "..\Noddybox.Emulation\WindowsPhone\Noddybox.Emulation.EightBit.Z80.Disassembler\Noddybox.Emulation.EightBit.Z80.Disassembler.csproj", "{08D7120E-3D84-49D2-B73D-255E5DB9655C}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Noddybox.Emulation.Xna.Input", "..\EmulationKeyboard\WindowsPhone\Noddybox.Emulation.Xna.Input\Noddybox.Emulation.Xna.Input.csproj", "{0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Noddybox.Emulation.Keyboard.Schema", "..\EmulationKeyboard\WindowsPhone\Noddybox.Emulation.Keyboard.Schema\Noddybox.Emulation.Keyboard.Schema.csproj", "{0F5AA96A-9253-4E06-A3F9-5517A2A9C558}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -85,16 +87,26 @@ Global {7F257886-40D3-4E2A-BA9C-C5FEE93C08E9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {7F257886-40D3-4E2A-BA9C-C5FEE93C08E9}.Release|Mixed Platforms.Build.0 = Release|Any CPU {7F257886-40D3-4E2A-BA9C-C5FEE93C08E9}.Release|Windows Phone.ActiveCfg = Release|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Debug|Windows Phone.ActiveCfg = Debug|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Release|Any CPU.Build.0 = Release|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {08D7120E-3D84-49D2-B73D-255E5DB9655C}.Release|Windows Phone.ActiveCfg = Release|Any CPU + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Debug|Any CPU.ActiveCfg = Debug|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Debug|Mixed Platforms.ActiveCfg = Debug|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Debug|Mixed Platforms.Build.0 = Debug|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Debug|Windows Phone.ActiveCfg = Debug|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Debug|Windows Phone.Build.0 = Debug|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Release|Any CPU.ActiveCfg = Release|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Release|Mixed Platforms.ActiveCfg = Release|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Release|Mixed Platforms.Build.0 = Release|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Release|Windows Phone.ActiveCfg = Release|Windows Phone + {0F95CAB2-B79A-45B5-B5F2-14F4CED2EF20}.Release|Windows Phone.Build.0 = Release|Windows Phone + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Debug|Windows Phone.ActiveCfg = Debug|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Release|Any CPU.Build.0 = Release|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {0F5AA96A-9253-4E06-A3F9-5517A2A9C558}.Release|Windows Phone.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WPZX81/WPZX81/AboutPage.xaml.cs b/WPZX81/WPZX81/AboutPage.xaml.cs index 13c2bca..bfacde2 100644 --- a/WPZX81/WPZX81/AboutPage.xaml.cs +++ b/WPZX81/WPZX81/AboutPage.xaml.cs @@ -1,4 +1,21 @@ -using System; +// This file is part of the WPZX81 Windows Phone ZX81 emulator. +// +// Noddybox.Emulation is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Noddybox.Emulation is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Noddybox.Emulation. If not, see . +// +// Copyright (c) 2012 Ian Cowburn +// +using System; using System.Collections.Generic; using System.Linq; using System.Net; diff --git a/WPZX81/WPZX81/App.xaml.cs b/WPZX81/WPZX81/App.xaml.cs index b16ca7b..763293d 100644 --- a/WPZX81/WPZX81/App.xaml.cs +++ b/WPZX81/WPZX81/App.xaml.cs @@ -1,4 +1,21 @@ -using System; +// This file is part of the WPZX81 Windows Phone ZX81 emulator. +// +// Noddybox.Emulation is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Noddybox.Emulation is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Noddybox.Emulation. If not, see . +// +// Copyright (c) 2012 Ian Cowburn +// +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -15,6 +32,8 @@ using Microsoft.Phone.Shell; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; +using Noddybox.Emulation.Keyboard.Schema; +using System.IO; namespace WPZX81 { @@ -84,6 +103,18 @@ namespace WPZX81 private void Application_Launching(object sender, LaunchingEventArgs e) { Shared.ZX81 = new ZX81.Emulation(); + + // Dodgy, as these resources really belong to the XNA code, but it saves reloading every time the page is navigated to + // + using (BinaryReader stream = new BinaryReader(App.GetResourceStream(new Uri("Resources/ZX81.keyboard", UriKind.Relative)).Stream)) + { + Shared.ZX81Keyboard = KeyboardDefinition.Load(stream); + } + + using (BinaryReader stream = new BinaryReader(App.GetResourceStream(new Uri("Resources/controls.keyboard", UriKind.Relative)).Stream)) + { + Shared.ControlKeyboard = KeyboardDefinition.Load(stream); + } } // Code to execute when the application is activated (brought to foreground) diff --git a/WPZX81/WPZX81/ApplicationIcon.png b/WPZX81/WPZX81/ApplicationIcon.png index a3de0bb..ac20584 100644 Binary files a/WPZX81/WPZX81/ApplicationIcon.png and b/WPZX81/WPZX81/ApplicationIcon.png differ diff --git a/WPZX81/WPZX81/Background.png b/WPZX81/WPZX81/Background.png index 13e6cfa..98446bf 100644 Binary files a/WPZX81/WPZX81/Background.png and b/WPZX81/WPZX81/Background.png differ diff --git a/WPZX81/WPZX81/Converters/ConvertFlagsToString.cs b/WPZX81/WPZX81/Converters/ConvertFlagsToString.cs new file mode 100644 index 0000000..0cc17fd --- /dev/null +++ b/WPZX81/WPZX81/Converters/ConvertFlagsToString.cs @@ -0,0 +1,59 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.Windows.Data; +using Noddybox.Emulation.EightBit.Z80; + +namespace WPZX81.Converters +{ + /// + /// + /// + public class ConvertFlagsToString : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + object ret = null; + + if (value is Z80Flags) + { + int flag = (int)value; + char[] names = new char[8] {'C', 'N', 'P', '3', 'H', '5', 'Z', 'S'}; + char[] flags = new char[8]; + int f; + + for(f = 0; f < 8; f++) + { + if ((flag & (1 << f)) == (1 << f)) + { + flags[7-f] = names[7-f]; + } + else + { + flags[7-f] = '-'; + } + } + + ret = new string(flags); + } + + return ret; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} diff --git a/WPZX81/WPZX81/Converters/ConvertIntToHex2.cs b/WPZX81/WPZX81/Converters/ConvertIntToHex2.cs new file mode 100644 index 0000000..2a04953 --- /dev/null +++ b/WPZX81/WPZX81/Converters/ConvertIntToHex2.cs @@ -0,0 +1,42 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.Windows.Data; + +namespace WPZX81.Converters +{ + /// + /// Convert an integer to a 2-digit hex string. + /// + public class ConvertIntToHex2 : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + object ret = null; + + if (value is int) + { + int i = (int)value; + ret = i.ToString("X2"); + } + + return ret; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} diff --git a/WPZX81/WPZX81/Converters/ConvertIntToHex4.cs b/WPZX81/WPZX81/Converters/ConvertIntToHex4.cs new file mode 100644 index 0000000..77d9bd5 --- /dev/null +++ b/WPZX81/WPZX81/Converters/ConvertIntToHex4.cs @@ -0,0 +1,42 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.Windows.Data; + +namespace WPZX81.Converters +{ + /// + /// Convert an integer to a 4-digit hex string. + /// + public class ConvertIntToHex4 : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + object ret = null; + + if (value is int) + { + int i = (int)value; + ret = i.ToString("X4"); + } + + return ret; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} diff --git a/WPZX81/WPZX81/GamePage.xaml.cs b/WPZX81/WPZX81/GamePage.xaml.cs index 6d19bbc..7857007 100644 --- a/WPZX81/WPZX81/GamePage.xaml.cs +++ b/WPZX81/WPZX81/GamePage.xaml.cs @@ -1,4 +1,21 @@ -using System; +// This file is part of the WPZX81 Windows Phone ZX81 emulator. +// +// Noddybox.Emulation is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Noddybox.Emulation is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Noddybox.Emulation. If not, see . +// +// Copyright (c) 2012 Ian Cowburn +// +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -7,20 +24,47 @@ using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Navigation; -using System.Windows.Shapes; using Microsoft.Phone.Controls; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using System.Diagnostics; +using WPZX81.ZX81; +using Noddybox.Emulation.Xna.Input; +using Noddybox.Emulation.Xna.Input.Keyboard; +using Microsoft.Xna.Framework.Input.Touch; +using Noddybox.Emulation.Xna.Input.Joystick; namespace WPZX81 { public partial class GamePage : PhoneApplicationPage { - ContentManager contentManager; - GameTimer timer; - SpriteBatch spriteBatch; + private enum ControlKeySymbol + { + KeyReset, KeyTurbo, KeyJoystick, KeyKeyboard + } + + private ContentManager contentManager; + private GameTimer timer; + private SpriteBatch spriteBatch; + + private Texture2D screen; + private Vector2 location; + private Rectangle locationZoomed; + + private Texture2D keyboardImage; + private Texture2D controlImage; + private Texture2D joystickBackgroundImage; + private Texture2D joystickButtonImage; + private Texture2D joystickImage; + + private InputManager inputManager; + private KeyboardDriver keyboard; + private KeyboardDriver control; + private JoystickDriver joystick; + private bool resetPressed; + + private bool turbo; public GamePage() { @@ -38,16 +82,116 @@ namespace WPZX81 protected override void OnNavigatedTo(NavigationEventArgs e) { + // Set the sharing mode of the graphics device to turn on XNA rendering + // SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true); + + // Create a new SpriteBatch, which can be used to draw textures. + // spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice); + + // Create screen object + // + screen = new Texture2D + (SharedGraphicsDeviceManager.Current.GraphicsDevice, + Shared.ZX81.Width, + Shared.ZX81.Height, + false, Shared.ZX81.ScreenFormat); + + // Start the timer + // timer.Start(); + + // Initialise locations for normal and zoomed display + // + location = new Vector2(SharedGraphicsDeviceManager.Current.GraphicsDevice.DisplayMode.Width / 2 - Shared.ZX81.Width / 2, 10); + locationZoomed = new Rectangle(SharedGraphicsDeviceManager.Current.GraphicsDevice.DisplayMode.Width / 2 - Shared.ZX81.Width * 100 / 140, 10, + Shared.ZX81.Height * 100 / 70, Shared.ZX81.Width * 100 / 70); + + // Create a keyboard driver + // + resetPressed = false; + + inputManager = new InputManager(); + + keyboardImage = contentManager.Load("keyboard"); + controlImage = contentManager.Load("controls"); + joystickBackgroundImage = contentManager.Load("joystick_background"); + joystickImage = contentManager.Load("joystick"); + joystickButtonImage = contentManager.Load("button"); + + keyboard = new KeyboardDriver + (inputManager, + SharedGraphicsDeviceManager.Current.GraphicsDevice, + keyboardImage, + new Vector2(0, 490), + Shared.ZX81Keyboard); + + keyboard.KeyEvent += HandleKeyboardEvent; + + control = new KeyboardDriver + (inputManager, + SharedGraphicsDeviceManager.Current.GraphicsDevice, + controlImage, + new Vector2(0, 450), + Shared.ControlKeyboard); + + control.KeyEvent += HandleControlEvent; + + joystick = new JoystickDriver(inputManager, + SharedGraphicsDeviceManager.Current.GraphicsDevice, + JoystickType.Digital, + joystickBackgroundImage, joystickImage, joystickButtonImage, + new Vector2(0, 490), + new Vector2(125), + new Vector2[2] {new Vector2(280, 100), new Vector2(380, 125)}, + 20, 75); + + joystick.DigitalEvent += HandleJoystickEvent; + + if (Shared.IsJoystickDisplayed) + { + keyboard.StopKeyboardUpdates(); + } + else + { + joystick.StopJoystickUpdates(); + } + + inputManager.TouchEvent += HandleTouchEvent; + base.OnNavigatedTo(e); } protected override void OnNavigatedFrom(NavigationEventArgs e) { + // Stop the timer + // timer.Stop(); + + // Set the sharing mode of the graphics device to turn off XNA rendering + // SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false); + + screen.Dispose(); + screen = null; + + // Remove the inputs + // + keyboard.StopKeyboardUpdates(); + joystick.StopJoystickUpdates(); + control.StopKeyboardUpdates(); + + keyboard.KeyEvent -= HandleKeyboardEvent; + control.KeyEvent -= HandleControlEvent; + joystick.DigitalEvent -= HandleJoystickEvent; + inputManager.TouchEvent -= HandleTouchEvent; + + keyboard = null; + control = null; + joystick = null; + inputManager = null; + base.OnNavigatedFrom(e); } @@ -57,6 +201,7 @@ namespace WPZX81 /// private void OnUpdate(object sender, GameTimerEventArgs e) { + inputManager.Update(); Shared.ZX81.Run(); } @@ -65,15 +210,117 @@ namespace WPZX81 /// private void OnDraw(object sender, GameTimerEventArgs e) { - Stopwatch s = Stopwatch.StartNew(); - SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.Black); + + screen.SetData(Shared.ZX81.Screen); + spriteBatch.Begin(); - Shared.ZX81.UpdateDisplay(spriteBatch); + + if (Shared.IsZoomed) + { + spriteBatch.Draw(screen, locationZoomed, Color.White); + } + else + { + spriteBatch.Draw(screen, location, Color.White); + } + + if (Shared.IsJoystickDisplayed) + { + joystick.Draw(spriteBatch); + } + else + { + keyboard.Draw(spriteBatch); + } + + control.Draw(spriteBatch); + spriteBatch.End(); - s.Stop(); - Debug.WriteLine("*** RENDER {0} msec {1} ticks", s.ElapsedMilliseconds, s.ElapsedTicks); + SharedGraphicsDeviceManager.Current.GraphicsDevice.Textures[0] = null; + } + + #region Keyboard driver events + + private void HandleControlEvent(object sender, KeyboardDriver.KeyPressEventArgs e) + { + switch (e.Key) + { + case ControlKeySymbol.KeyReset: + if (!e.Pressed) + { + if (resetPressed) + { + resetPressed = false; + Shared.ZX81.Reset(); + } + else + { + resetPressed = true; + } + } + break; + + case ControlKeySymbol.KeyTurbo: + resetPressed = false; + turbo = e.Pressed; + break; + + case ControlKeySymbol.KeyJoystick: + resetPressed = false; + + if (!Shared.IsJoystickDisplayed) + { + joystick.StartJoystickUpdates(); + keyboard.StopKeyboardUpdates(); + Shared.IsJoystickDisplayed = true; + } + break; + + case ControlKeySymbol.KeyKeyboard: + resetPressed = false; + + if (Shared.IsJoystickDisplayed) + { + joystick.StopJoystickUpdates(); + keyboard.StartKeyboardUpdates(); + Shared.IsJoystickDisplayed = false; + } + break; + } + } + + private void HandleKeyboardEvent(object sender, KeyboardDriver.KeyPressEventArgs e) + { + resetPressed = false; + + if (e.Pressed) + { + Shared.ZX81.KeyPressed(e.Key); + } + else + { + Shared.ZX81.KeyReleased(e.Key); + } + } + + private void HandleTouchEvent(object sender, InputManager.TouchLocationEventArgs e) + { + resetPressed = false; + + if (e.Location.State == TouchLocationState.Released && e.Location.Position.Y < 400) + { + e.Handled = true; + Shared.IsZoomed = !Shared.IsZoomed; + } } + + private void HandleJoystickEvent(object sender, JoystickDriver.DigitalJoystickEventArgs e) + { + resetPressed = false; + } + + #endregion } } \ No newline at end of file diff --git a/WPZX81/WPZX81/MainPage.xaml b/WPZX81/WPZX81/MainPage.xaml index caa591c..b38e2da 100644 --- a/WPZX81/WPZX81/MainPage.xaml +++ b/WPZX81/WPZX81/MainPage.xaml @@ -54,12 +54,12 @@ FontSize="18" Click="RunEmulationClick"> - +