├── .github ├── CODEOWNERS └── workflows │ └── dotnetcore.yml ├── .gitignore ├── Essenbee.Spectrum48 ├── App.config ├── Essenbee.Spectrum48.csproj ├── Libs │ ├── Licences.txt │ └── PixelEngine.dll ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── ROM │ └── 48.rom ├── SimpleBus.cs ├── Z80FileReader.cs └── Z80Snapshot.cs ├── Essenbee.Z80.Debugger ├── App.xaml ├── App.xaml.cs ├── BasicBus.cs ├── ControlPanel.xaml ├── ControlPanel.xaml.cs ├── CpuFlags.xaml ├── CpuFlags.xaml.cs ├── CpuStatus.xaml ├── CpuStatus.xaml.cs ├── DependencyProperties.ttinclude ├── Disassembler.xaml ├── Disassembler.xaml.cs ├── Essenbee.Z80.Debugger.csproj ├── Generated_DependencyProperties.cs ├── Generated_DependencyProperties.tt ├── Generated_ViewModel.cs ├── Generated_ViewModel.tt ├── Header.ttinclude ├── HeaderCommon.ttinclude ├── HexFileLoader.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── MainWindowViewModel.cs ├── MemoryMap.xaml ├── MemoryMap.xaml.cs ├── MsxScreen.xaml ├── MsxScreen.xaml.cs ├── ObservableDictionary.cs ├── ROM │ ├── 48.rom │ └── 48.rom.data ├── StackDisplay.xaml ├── StackDisplay.xaml.cs └── UserCommand.cs ├── Essenbee.Z80.Sample ├── Essenbee.Z80.Sample.csproj ├── Program.cs ├── ROM │ └── 48.rom └── SimpleBus.cs ├── Essenbee.Z80.Tests ├── BinaryCodedDecimalArithmeticTests.cs ├── CallAndReturnGroupShould.cs ├── Classes │ ├── BasicBus.cs │ ├── FuseTester.cs │ ├── HexFileReader.cs │ └── Results.cs ├── ComparisonsShould.cs ├── DisassemblerShould.cs ├── EightBitArithmeticLogicADDGroupShould.cs ├── EightBitArithmeticLogicSUBGroupShould.cs ├── EightBitLoadGroupShould.cs ├── EightBitLogicGroupShould.cs ├── Essenbee.Z80.Tests.csproj ├── ExchangeShould.cs ├── FlagsShould.cs ├── FuseTests │ ├── FUSE_Expected.txt │ └── FUSE_Tests.txt ├── GeneralControlGroupShould.cs ├── HexFileReaderTests.cs ├── HexFiles │ ├── Arithmetic1.hex │ ├── ExampleMonitor.hex │ ├── HexFileFormat.txt │ ├── Multiplication.hex │ ├── Multiplication2.hex │ └── TestDDCBandFDCB.hex ├── InputOutputShould.cs ├── IsSupportedShould.cs ├── JumpGroupShould.cs ├── RotateAndShiftGroupShould.cs ├── SixteenBitArithmeticLogicGroupShould.cs ├── SixteenBitLoadGroupShould.cs └── Z80EmulatorShould.cs ├── Essenbee.Z80 ├── .cr │ └── images │ │ ├── CF3C03E9AEA956395291BE98C580C27F.png │ │ └── E5D9CCCCCD8B82BB1159F822CFE086F8.png ├── Essenbee.Z80.csproj ├── Essenbee.Z80.sln ├── IBus.cs ├── Instruction.cs ├── InterruptMode.cs ├── Z80.AddressModes.cs ├── Z80.ArithmeticLogic.cs ├── Z80.BitGroup.cs ├── Z80.Helpers.cs ├── Z80.IO.cs ├── Z80.Instructions.cs ├── Z80.Jump.cs ├── Z80.Load.cs ├── Z80.ShiftRotate.cs └── Z80.cs ├── LICENSE └── README.md /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @essenbee 2 | -------------------------------------------------------------------------------- /.github/workflows/dotnetcore.yml: -------------------------------------------------------------------------------- 1 | name: .NET Core 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: windows-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Setup .NET Core 13 | uses: actions/setup-dotnet@v1 14 | with: 15 | dotnet-version: 3.1.100 16 | - name: Build with dotnet 17 | run: dotnet build ./Essenbee.Z80 --configuration Release 18 | - name: Tests 19 | run: dotnet test ./Essenbee.Z80.Tests 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /Essenbee.Spectrum48/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Essenbee.Spectrum48/Essenbee.Spectrum48.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0B15FF0C-414B-4F4F-81E2-694074257B3B} 8 | Exe 9 | Essenbee.Spectrum48 10 | Essenbee.Spectrum48 11 | v4.6.1 12 | 512 13 | true 14 | true 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | False 39 | Libs\PixelEngine.dll 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | {7D5005D4-A8F1-4E80-8689-8DDD04264F3A} 67 | Essenbee.Z80 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /Essenbee.Spectrum48/Libs/Licences.txt: -------------------------------------------------------------------------------- 1 | License (OLC-3) 2 | ~~~~~~~~~~~~~~~ 3 | Copyright 2018 OneLoneCoder.com 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions or derivations of source code must retain the above 8 | copyright notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions or derivative works in binary form must reproduce 10 | the above copyright notice. This list of conditions and the following 11 | disclaimer must be reproduced in the documentation and/or other 12 | materials provided with the distribution. 13 | 3. Neither the name of the copyright holder nor the names of its 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /Essenbee.Spectrum48/Libs/PixelEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/essenbee/z80emu/8085dc449deb35d8b76ed76e26c4b1347e1286eb/Essenbee.Spectrum48/Libs/PixelEngine.dll -------------------------------------------------------------------------------- /Essenbee.Spectrum48/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Essenbee.Spectrum48")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Essenbee.Spectrum48")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0b15ff0c-414b-4f4f-81e2-694074257b3b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Essenbee.Spectrum48/ROM/48.rom: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/essenbee/z80emu/8085dc449deb35d8b76ed76e26c4b1347e1286eb/Essenbee.Spectrum48/ROM/48.rom -------------------------------------------------------------------------------- /Essenbee.Spectrum48/SimpleBus.cs: -------------------------------------------------------------------------------- 1 | using PixelEngine; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Essenbee.Z80.Spectrum48 6 | { 7 | public class SimpleBus : IBus 8 | { 9 | public bool ScreenReady { get; set; } 10 | public bool SoundOn { get; set; } 11 | public Pixel BorderColour { get; set; } = Pixel.Presets.Black; 12 | 13 | public int[] KeyMatrix { get; set; } = new int[8]; 14 | public bool Interrupt { get; set; } 15 | public bool NonMaskableInterrupt { get; set; } 16 | public IList Data { get; set; } = new List(); 17 | 18 | private byte[] _memory; 19 | private int _lineRendered = 0; 20 | private int _pixelLine = 0; 21 | private int _screenLine = 0; 22 | private Sprite _screenBuffer = new Sprite(32 * 8, 24 * 8); 23 | private const ushort _screenStart = 0x4000; // Beginning of Spectrum video RAM 24 | private const ushort _attributeStart = 0x5800; // 768 bytes of colour attributes 25 | private int _ink0, _ink1, _ink2; 26 | private int _paper0, _paper1, _paper2; 27 | private int _bright0, _bright1, _bright2; 28 | private int _flash0, _flash1, _flash2; 29 | private int _frameCounter; 30 | 31 | public SimpleBus(byte[] ram) => _memory = ram; 32 | 33 | public IReadOnlyCollection RAM 34 | => _memory; 35 | 36 | public byte Read(ushort addr, bool ro = false) => _memory[addr]; 37 | 38 | public byte ReadPeripheral(ushort port) 39 | { 40 | // Console.WriteLine($"IN 0x{port:X4}"); 41 | 42 | if ((port & 1) == 0) 43 | { 44 | // Keyboard handling.. 45 | byte result = 0xFF; 46 | var keyRow = (port & 0xFF00) >> 8; 47 | 48 | if (keyRow == 0x7F) 49 | { 50 | result &= (byte)KeyMatrix[7]; 51 | } 52 | 53 | if (keyRow == 0xBF) 54 | { 55 | result &= (byte)KeyMatrix[6]; 56 | } 57 | 58 | if (keyRow == 0xDF) 59 | { 60 | result &= (byte)KeyMatrix[5]; 61 | } 62 | 63 | if (keyRow == 0xEF) 64 | { 65 | result &= (byte)KeyMatrix[4]; 66 | } 67 | 68 | if (keyRow == 0xF7) 69 | { 70 | result &= (byte)KeyMatrix[3]; 71 | } 72 | 73 | if (keyRow == 0xFB) 74 | { 75 | result &= (byte)KeyMatrix[2]; 76 | } 77 | 78 | if (keyRow == 0xFD) 79 | { 80 | result &= (byte)KeyMatrix[1]; 81 | } 82 | 83 | if (keyRow == 0xFE) 84 | { 85 | result &= (byte)KeyMatrix[0]; 86 | } 87 | 88 | result &= 0x1F; //mask out bits 0 to 4 89 | result |= 0b11100000; //set bit 5 - 7 90 | //Console.WriteLine($">>>>>>> Sending {Convert.ToString(result ,2)}"); 91 | 92 | return result; 93 | } 94 | 95 | return 0; 96 | } 97 | 98 | public void Write(ushort addr, byte data) => _memory[addr] = data; 99 | 100 | public void WritePeripheral(ushort port, byte data) 101 | { 102 | // Console.WriteLine($"OUT 0x{port:X4} Data 0x{data:X2}"); 103 | 104 | //` Bit 7 6 5 4 3 2 1 0 105 | //` +-------------------------------+ 106 | //` | | | | E | M | Border | 107 | //` +-------------------------------+ 108 | 109 | // ULA select 110 | if ((port & 0x00FF) == 0xFE) 111 | { 112 | // Set border colour (0 - 7) 113 | if (port >> 8 < 8) 114 | { 115 | var borderColour = data & 0b00000111; 116 | BorderColour = GetColouredPixel(borderColour, 0); 117 | return; 118 | } 119 | 120 | if ((port & 0b00001000) > 1) 121 | { 122 | // Activate MIC 123 | } 124 | 125 | if ((port & 0b00010000) > 1) 126 | { 127 | // Activate EAR 128 | SoundOn = true; 129 | } 130 | else 131 | { 132 | SoundOn = false; 133 | } 134 | } 135 | } 136 | 137 | public Sprite GetScreen() => _screenBuffer; 138 | 139 | public void RunRenderer() 140 | { 141 | StepRenderer(); 142 | 143 | if (ScreenReady) 144 | { 145 | Interrupt = true; // 50 Hz maskable interrupt 146 | 147 | // If interrupt Mode is 2:- 148 | // The Spectrum didn’t use IM 2 normally; it was widely assumed that cannot 149 | // guarantee what is on the data bus when the interrupt occurred, so programmers 150 | // tend to generate a vector table with 128 addresses, all pointing to the routine. 151 | // The data bus will read 0xFF in this case. 152 | Data = new List { 0xFF }; 153 | } 154 | } 155 | 156 | private void StepRenderer() 157 | { 158 | var offset = _screenStart + (_pixelLine << 8) + (_screenLine << 5); 159 | // Top third of screen 160 | var memOffset0 = (0 << 11) + offset; 161 | // Middle third of screen 162 | var memOffset1 = (1 << 11) + offset; 163 | // Bottom third of screen 164 | var memOffset2 = (2 << 11) + offset; 165 | 166 | for (var c = 0; c < 32; c++) 167 | { 168 | var c0 = _memory[memOffset0 + c]; // Get byte value 0 169 | var c1 = _memory[memOffset1 + c]; // Get byte value 1 170 | var c2 = _memory[memOffset2 + c]; // Get byte value 2 171 | 172 | ReadAttributesForCharacter(c); 173 | 174 | // Decode bits 175 | for (var bitPos = 0; bitPos < 8; ++bitPos) 176 | { 177 | var b0 = 0x1 & (c0 >> (7 - bitPos)); 178 | var b1 = 0x1 & (c1 >> (7 - bitPos)); 179 | var b2 = 0x1 & (c2 >> (7 - bitPos)); 180 | var x = (c * 8) + bitPos; 181 | 182 | _screenBuffer[x, _lineRendered + 0] = GetPixel(b0 != 0, _ink0, _paper0, _bright0, _flash0 == 1); 183 | _screenBuffer[x, _lineRendered + 64] = GetPixel(b1 != 0, _ink1, _paper1, _bright1, _flash1 == 1); 184 | _screenBuffer[x, _lineRendered + 128] = GetPixel(b2 != 0, _ink2, _paper2, _bright2, _flash2 == 1); 185 | } 186 | } 187 | 188 | _lineRendered++; 189 | _pixelLine++; 190 | 191 | if (_pixelLine > 7) 192 | { 193 | _pixelLine = 0; 194 | _screenLine++; 195 | } 196 | 197 | if (_screenLine > 7) 198 | { 199 | _screenLine = 0; ; 200 | } 201 | 202 | if (_lineRendered > 63) 203 | { 204 | _lineRendered = 0; 205 | ScreenReady = true; 206 | _frameCounter++; 207 | } 208 | } 209 | 210 | private void ReadAttributesForCharacter(int c) 211 | { 212 | var offset = _attributeStart + (_screenLine << 5); 213 | var attrOffset0 = (0 << 8) + offset + c; 214 | var attrOffset1 = (1 << 8) + offset + c; 215 | var attrOffset2 = (2 << 8) + offset + c; 216 | 217 | var attr0 = _memory[attrOffset0]; 218 | var attr1 = _memory[attrOffset1]; 219 | var attr2 = _memory[attrOffset2]; 220 | 221 | _ink0 = attr0 & 0b00000111; 222 | _paper0 = (attr0 & 0b00111000) >> 3; 223 | _bright0 = (attr0 & 0b01000000) >> 6; 224 | _flash0 = (attr0 & 0b10000000) >> 7; 225 | 226 | _ink1 = attr1 & 0b00000111; 227 | _paper1 = (attr1 & 0b00111000) >> 3; 228 | _bright1 = (attr1 & 0b01000000) >> 6; 229 | _flash1 = (attr1 & 0b10000000) >> 7; 230 | 231 | _ink2 = attr2 & 0b00000111; 232 | _paper2 = (attr2 & 0b00111000) >> 3; 233 | _bright2 = (attr2 & 0b01000000) >> 6; 234 | _flash2 = (attr2 & 0b10000000) >> 7; 235 | } 236 | private Pixel GetPixel(bool foreground, int ink, int paper, int brightness, bool flashing) 237 | { 238 | if (flashing) 239 | { 240 | if (_frameCounter < 17) 241 | { 242 | return NormalPixel(foreground, ink, paper, brightness); 243 | } 244 | 245 | if (_frameCounter > 32) 246 | { 247 | _frameCounter = 0; 248 | } 249 | 250 | return InvertedPixel(foreground, ink, paper, brightness); 251 | } 252 | 253 | return NormalPixel(foreground, ink, paper, brightness); 254 | } 255 | 256 | private Pixel InvertedPixel(bool foreground, int ink, int paper, int brightness) => 257 | foreground ? GetColouredPixel(paper, brightness) : GetColouredPixel(ink, brightness); 258 | 259 | private Pixel NormalPixel(bool foreground, int ink, int paper, int brightness) => 260 | foreground ? GetColouredPixel(ink, brightness) : GetColouredPixel(paper, brightness); 261 | 262 | private Pixel GetColouredPixel(int colour, int brightness) 263 | { 264 | if (brightness == 0) 265 | { 266 | switch (colour) 267 | { 268 | case 0: return Pixel.Presets.Black; 269 | case 1: return Pixel.Presets.DarkBlue; 270 | case 2: return Pixel.Presets.DarkRed; 271 | case 3: return Pixel.Presets.DarkMagenta; 272 | case 4: return Pixel.Presets.DarkGreen; 273 | case 5: return Pixel.Presets.DarkCyan; 274 | case 6: return Pixel.Presets.DarkYellow; 275 | default: return Pixel.Presets.Grey; 276 | } 277 | } 278 | else 279 | { 280 | switch (colour) 281 | { 282 | case 0: return Pixel.Presets.Black; 283 | case 1: return Pixel.Presets.Blue; 284 | case 2: return Pixel.Presets.Red; 285 | case 3: return Pixel.Presets.Magenta; 286 | case 4: return Pixel.Presets.Green; 287 | case 5: return Pixel.Presets.Cyan; 288 | case 6: return Pixel.Presets.Yellow; 289 | default: return Pixel.Presets.White; 290 | } 291 | } 292 | } 293 | } 294 | } 295 | -------------------------------------------------------------------------------- /Essenbee.Spectrum48/Z80Snapshot.cs: -------------------------------------------------------------------------------- 1 | namespace Essenbee.Z80.Spectrum48 2 | { 3 | public class Z80Snapshot 4 | { 5 | public int Type; 6 | public byte I; 7 | public int HL1, DE1, BC1, AF1; 8 | public int HL, DE, BC, IX, IY; 9 | public byte R; 10 | public int AF, SP; 11 | public byte IM; 12 | public byte Border; 13 | public int PC; 14 | public byte Port7FFD; 15 | public byte PortFFFD; 16 | public byte Port1FFD; 17 | public byte[] AYRegisters; 18 | public bool IFF1; 19 | public bool IFF2; 20 | public bool IsIssue2; 21 | public bool AY48K; 22 | public int TStates; 23 | public byte[][] RAMBank = new byte[16][]; 24 | public byte[] Spectrum48 = new byte[49152]; 25 | } 26 | } -------------------------------------------------------------------------------- /Essenbee.Z80.Debugger/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Essenbee.Z80.Debugger/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace Essenbee.Z80.Debugger 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Essenbee.Z80.Debugger/BasicBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Essenbee.Z80.Debugger 5 | { 6 | public class BasicBus : IBus 7 | { 8 | public bool Interrupt { get; set; } 9 | public bool NonMaskableInterrupt { get; set; } 10 | public IList Data { get; set; } = new List(); 11 | 12 | private byte[] _memory; 13 | public BasicBus(int RAMSize) 14 | { 15 | _memory = new byte[RAMSize * 1024]; 16 | } 17 | 18 | public BasicBus(byte[] ram) 19 | { 20 | _memory = ram; 21 | } 22 | 23 | public IReadOnlyCollection RAM 24 | { 25 | get => _memory; 26 | } 27 | 28 | public byte Read(ushort addr, bool ro = false) 29 | { 30 | return _memory[addr]; 31 | } 32 | 33 | public byte ReadPeripheral(ushort port) 34 | { 35 | 36 | Console.WriteLine($"IN 0x{port:X4}"); 37 | 38 | return 0; 39 | } 40 | 41 | public void Write(ushort addr, byte data) 42 | { 43 | _memory[addr] = data; 44 | } 45 | 46 | public void WritePeripheral(ushort port, byte data) 47 | { 48 | Console.WriteLine($"OUT 0x{port:X4}, 0x{data:X2}"); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Essenbee.Z80.Debugger/ControlPanel.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 |