C# ZX Spectrum Emulator
This project is a C# port of Jasper (Java Spectrum Emulator) for .NET Standard (2.0.3), Windows Forms (on .NET Framework 4.6.1), and now Blazor Server-side and Blazor Client-side (using WebAssembly) on .NET Core 3.1.
Download or fork this repository and open the Casper.sln
file in Visual Studio 2019 (version 16.5.4 or above).
You will need to have the following workloads installed
using the Visual Studio Installer:
- ASP.NET and web development
- .NET desktop development
In Visual Studio, set one of the following projects to be your startup project and press F5 to start debugging:
- Casper.BlazorServer
- Casper.BlazerWebAssembly
- Casper.Forms
- Click in the window to get keyboard focus.
- Press Enter when the Manic Miner text starts to flash.
- Press Enter to start the game.
- Collect all the pulsating keys and head to the exit for each level.
Key | Action |
---|---|
Left | |
Right | |
Jump |
The BlazorWebAssembly project is setup as a Progressive Web App (PWA) so you should see a (+) sign appear in the address bar in your browser, indicating that you can install it locally as a desktop app.
For now there is no installer for Windows Forms or Blazor Server side.
The original 16Kb/48Kb ZX Spectrum had a rubber keyboard and the BASIC language keywords were entered using a combination of keys. Later keyboards weren't rubber but still retained the keyword tokens until finally the 128Kb ZX Spectrum allowed for free form text entry, after which is tokenized the BASIC keywords again. Here is the layout of the original model:
In 1982 the hugely popular home computer the Sinclair ZX Spectrum was created by Clive Sinclair. It seeded a generation of software developers and I owe my entire career to that one purchasing decision made for me when I was 12 years old. Thanks Mum!
In 1989 my friend Andrew Pollard created this emulator in Motorola 68000 assembly code in order to play Steve Davis Snooker on his Atari ST because he was disappointed in the Atari ST version.
In 1992 Andrew ported the emulator to C code and we then ported it to X Windows so we could play Match Day where each of us played on our own Sun SparcStation with the emulator essentially running as a back-end server.
In 1996 Sun released their first version of the Java Develop Kit with the tag line write once, run anywhere. I was completely sold, especially when I saw their Web Browser implementation HotJava written 100% in Java with a new Java Applet model for running Java content inside a Web Browser. I could see that we could resurrect the emulator and port it to Java. Yes it would be slow, since the Java Bytecode was interpreted, but Just-in-Time (JIT) compilation was coming and I knew I couldn't wait.
In 1997 during the browser wars Netscape and Internet Explorer were both vying to be the best Web Browser on the market and Java Applet performance was a differentiator for them. They both came our with JIT support for Java Applets around the same time and suddenly the Java Spectrum Emulator (Jasper) got a new lease of life. With JIT it ran in real-time on a 133Mhz Pentium in 16Mb RAM. We even got some interest from the press, Internet Magazine ran an article on our website in March 1997:
In 2019 in a bid to learn about Blazor I decided to resurrect the old emulator code again and port it to C#. I did a Windows Forms reference first so I could make sure things were working as they should be. Then I moved on to the Blazor version. I could see the same story of interpreted byte code initially with the promise of JIT or AOT (Ahead-of-Time) compilation hopefully making the Blazor WebAssembly version run in real-time once again.
I hit a roadblock straight away. The promise of Blazor was that you didn't have to write JavaScript, you could create an app, in the browser, with just C# code. However I couldn't see how to write a canvas object in C# without all the messy JavaScript interop which I really didn't want to deal with.
In 2020, Coronavirus lock-down has given us a lot of time for fun projects so I thought I'd revisit this one. Blazor (or Razor) is all about DOM manipulation but the HTML Canvas doesn't have a DOM, it's all immediate. However I realized that HTML Scalable Vector Graphics (SVG) does and so I set about creating a Blazor SVG version of the ZX Spectrum Emulator. Crazy, right?!
Andrew Pollard who created the original emulator code and painstakingly went through each Z80 Mnemonic checking that they functioned as they did in the original Zilog Z80.
Amstrad who now own the ZX Spectrum brand are the owners of the Spectrum.rom file, which is a copy of the original ZX Spectrum 16K ROM code. In a post on comp.sys.sinclair they requested this notice be attached whenever their ROM files were redistributed:
Amstrad have kindly given their permission for the redistribution of their copyrighted material but retain that copyright
The font used on the web page is the ZX82 System Font by Paul van der Laan.
The Keyboard SVG was derived from a PowerPoint of the ZX Spectrum Keyboard by Magnus Krook.
The Manic Miner game was written by Matthew Smith and published by Bug Byte Software Limited in 1983.
NOTE: The Manic Miner game is not covered by the MIT license.