From df9ba74d687bd4045d59ab6ebb80a91c8b30c468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Engstr=C3=B6m?= Date: Mon, 5 Feb 2024 06:25:46 +0100 Subject: [PATCH 1/2] Updated packages --- Platforms/ZXBox.Blazor/ZXBox.Blazor.csproj | 8 ++++---- ZXBox.Core.Tests/ZXBox.Core.Tests.csproj | 6 +++--- ZXBox.sln | 9 --------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/Platforms/ZXBox.Blazor/ZXBox.Blazor.csproj b/Platforms/ZXBox.Blazor/ZXBox.Blazor.csproj index 467fda9..4fbf52f 100644 --- a/Platforms/ZXBox.Blazor/ZXBox.Blazor.csproj +++ b/Platforms/ZXBox.Blazor/ZXBox.Blazor.csproj @@ -11,11 +11,11 @@ - - + + - - + + diff --git a/ZXBox.Core.Tests/ZXBox.Core.Tests.csproj b/ZXBox.Core.Tests/ZXBox.Core.Tests.csproj index 54372a4..11a4b20 100644 --- a/ZXBox.Core.Tests/ZXBox.Core.Tests.csproj +++ b/ZXBox.Core.Tests/ZXBox.Core.Tests.csproj @@ -7,9 +7,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ZXBox.sln b/ZXBox.sln index 869f879..ce1664a 100644 --- a/ZXBox.sln +++ b/ZXBox.sln @@ -11,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZXBox.Blazor", "Platforms\Z EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZXBox.Core.Tests", "ZXBox.Core.Tests\ZXBox.Core.Tests.csproj", "{A1CEA0B2-9204-4BAF-9BBC-F6B22FE11A85}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZXBox.Meadow", "ZXBox.Meadow\ZXBox.Meadow.csproj", "{7D87F833-543E-4F45-9467-E4766A998495}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,19 +29,12 @@ Global {A1CEA0B2-9204-4BAF-9BBC-F6B22FE11A85}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1CEA0B2-9204-4BAF-9BBC-F6B22FE11A85}.Release|Any CPU.ActiveCfg = Release|Any CPU {A1CEA0B2-9204-4BAF-9BBC-F6B22FE11A85}.Release|Any CPU.Build.0 = Release|Any CPU - {7D87F833-543E-4F45-9467-E4766A998495}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7D87F833-543E-4F45-9467-E4766A998495}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7D87F833-543E-4F45-9467-E4766A998495}.Debug|Any CPU.Deploy.0 = Debug|Any CPU - {7D87F833-543E-4F45-9467-E4766A998495}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7D87F833-543E-4F45-9467-E4766A998495}.Release|Any CPU.Build.0 = Release|Any CPU - {7D87F833-543E-4F45-9467-E4766A998495}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {50F28AF7-10CD-46F9-9B8A-55009B96C5F9} = {00F4C7F3-4C41-48AC-91D7-BC7339DC12E6} - {7D87F833-543E-4F45-9467-E4766A998495} = {00F4C7F3-4C41-48AC-91D7-BC7339DC12E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D52DCA43-01EB-4AE5-B69B-E064911874F7} From defefc8e7792587e2b557af5cedd9aabd09f6db1 Mon Sep 17 00:00:00 2001 From: Johan Lindfors Date: Mon, 15 Jul 2024 10:06:55 +0200 Subject: [PATCH 2/2] Refactored and modernized a lot of code --- .../Components/EmulatorComponent.razor.cs | 144 +-- Platforms/ZXBox.Blazor/Hardware/Kempston.cs | 8 +- Platforms/ZXBox.Blazor/Hardware/Keyboard.cs | 11 +- ZXBox.Core.Tests/CoreTest.cs | 14 +- ZXBox.Core.Tests/GameBoy/GBFileFormatTests.cs | 4 +- ZXBox.Core.Tests/TestState.cs | 7 +- ZXBox.Core.Tests/TestfileHandler.cs | 64 +- ZXBox.Core/Cpus/Sharp/LR35902.cs | 19 +- ZXBox.Core/Cpus/Z80/Z80.cs | 304 +++--- .../Cpus/Z80/Z80AssemblerInstructions.cs | 893 +++++++----------- .../Cpus/Z80/Z80CBPrefixInstructions.cs | 484 +++++----- .../Cpus/Z80/Z80DDandFDPrefixInstructions.cs | 844 ++++++++--------- .../Cpus/Z80/Z80EDPrefixInstructions.cs | 114 ++- .../Cpus/Z80/Z80NOPrefixInstructions.cs | 601 +++++------- ZXBox.Core/Gameboy.cs | 100 +- ZXBox.Core/Hardware/Input/TapePlayer.cs | 12 +- ZXBox.Core/Hardware/Interfaces/IInput.cs | 5 +- ZXBox.Core/Hardware/Interfaces/IOutput.cs | 2 +- ZXBox.Core/Hardware/Output/Beeper.cs | 2 +- ZXBox.Core/Hardware/Output/Screen.cs | 223 +---- ZXBox.Core/Snapshot/MemoryHandler.cs | 2 +- ZXBox.Core/Snapshot/SNAFileFormat.cs | 28 +- ZXBox.Core/Snapshot/Z80FileFormat.cs | 11 +- ZXBox.Core/ZxSpectrum.cs | 46 +- ZXBox.Meadow/MeadowApp.cs | 2 +- ZXBox.Meadow/Z80/Z80.cs | 88 +- 26 files changed, 1766 insertions(+), 2266 deletions(-) diff --git a/Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs b/Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs index 059b977..a822fd2 100644 --- a/Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs +++ b/Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs @@ -1,21 +1,21 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Forms; -using Microsoft.JSInterop; -using Microsoft.JSInterop.WebAssembly; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Net.Http; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using System.Timers; -using ZXBox.Core.Hardware.Input; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.JSInterop; +using Microsoft.JSInterop.WebAssembly; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Net.Http; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using System.Timers; +using ZXBox.Core.Hardware.Input; using ZXBox.Hardware.Input; using ZXBox.Hardware.Input.Joystick; -using ZXBox.Hardware.Output; -using ZXBox.Snapshot; - +using ZXBox.Hardware.Output; +using ZXBox.Snapshot; + namespace ZXBox.Blazor.Pages { public partial class EmulatorComponentModel : ComponentBase, IAsyncDisposable @@ -50,8 +50,8 @@ public ZXSpectrum GetZXSpectrum(RomEnum rom) public void StartZXSpectrum(RomEnum rom) { speccy = GetZXSpectrum(rom); - speccy.InputHardware.Add(Keyboard); - + speccy.InputHardware.Add(Keyboard); + kempston = new Kempston(); speccy.InputHardware.Add(kempston); //48000 samples per second, 50 frames per second (20ms per frame) Mono @@ -67,26 +67,26 @@ public void StartZXSpectrum(RomEnum rom) public string TapeName { get; set; } public async Task HandleFileSelected(InputFileChangeEventArgs args) { - if (args.File.Name.ToLower().EndsWith(".tap")) - { - //Load the tape - var file = args.File; - var ms = new MemoryStream(); + if (args.File.Name.ToLower().EndsWith(".tap")) + { + //Load the tape + var file = args.File; + var ms = new MemoryStream(); await file.OpenReadStream().CopyToAsync(ms); tapePlayer.LoadTape(ms.ToArray()); TapeName = Path.GetFileNameWithoutExtension(args.File.Name); } - else - { - var file = args.File; - var ms = new MemoryStream(); - - await file.OpenReadStream().CopyToAsync(ms); - - var handler = FileFormatFactory.GetSnapShotHandler(file.Name); - var bytes = ms.ToArray(); - handler.LoadSnapshot(bytes, speccy); - } + else + { + var file = args.File; + var ms = new MemoryStream(); + + await file.OpenReadStream().CopyToAsync(ms); + + var handler = FileFormatFactory.GetSnapShotHandler(file.Name); + var bytes = ms.ToArray(); + handler.LoadSnapshot(bytes, speccy); + } } [Inject] HttpClient httpClient { get; set; } @@ -104,37 +104,37 @@ public async Task LoadGame(string filename, string instructions) private async void GameLoop_Elapsed(object sender, ElapsedEventArgs e) { - Stopwatch sw = new Stopwatch(); - - //Get gamepads - kempston.Gamepads = await GamePadList.GetGamepadsAsync(); - //Run JavaScriptInterop to find the currently pressed buttons + Stopwatch sw = new Stopwatch(); + + //Get gamepads + kempston.Gamepads = await GamePadList.GetGamepadsAsync(); + //Run JavaScriptInterop to find the currently pressed buttons Keyboard.KeyBuffer = await JSRuntime.InvokeAsync>("getKeyStatus"); sw.Start(); - speccy.DoIntructions(69888); - + speccy.DoInstructions(69888); + beeper.GenerateSound(); - await BufferSound(); - - Paint(); - sw.Stop(); - if (tapePlayer != null && tapePlayer.IsPlaying) - { - TapeStopped = false; - PercentLoaded = ((Convert.ToDouble(tapePlayer.CurrentTstate) / Convert.ToDouble(tapePlayer.TotalTstates)) * 100); - await InvokeAsync(() => StateHasChanged()); + await BufferSound(); + + Paint(); + sw.Stop(); + if (tapePlayer != null && tapePlayer.IsPlaying) + { + TapeStopped = false; + PercentLoaded = ((Convert.ToDouble(tapePlayer.CurrentTstate) / Convert.ToDouble(tapePlayer.TotalTstates)) * 100); + await InvokeAsync(() => StateHasChanged()); } - if (!TapeStopped && !tapePlayer.IsPlaying) - { - TapeStopped = true; - await InvokeAsync(() => StateHasChanged()); + if (!TapeStopped && !tapePlayer.IsPlaying) + { + TapeStopped = true; + await InvokeAsync(() => StateHasChanged()); } - } - bool TapeStopped = false; - GCHandle gchsound; - IntPtr pinnedsound; - WebAssemblyJSRuntime mono; - byte[] soundbytes; + } + bool TapeStopped = false; + GCHandle gchsound; + IntPtr pinnedsound; + WebAssemblyJSRuntime mono; + byte[] soundbytes; protected async Task BufferSound() { soundbytes = beeper.GetSoundBuffer(); @@ -154,7 +154,7 @@ protected async override void OnAfterRender(bool firstRender) base.OnAfterRender(firstRender); } - GCHandle gchscreen; + GCHandle gchscreen; IntPtr pinnedscreen; //uint[] screen = new uint[68672]; //Height * width (256+20+20)*(192+20+20) public async void Paint() @@ -169,20 +169,20 @@ public async void Paint() flashcounter--; } - var screen = speccy.GetScreenInUint(flash); - - //Allocate memory + var screen = speccy.GetScreenInUint(flash); + + //Allocate memory gchscreen = GCHandle.Alloc(screen, GCHandleType.Pinned); pinnedscreen = gchscreen.AddrOfPinnedObject(); mono.InvokeUnmarshalled("PaintCanvas", pinnedscreen); gchscreen.Free(); - } - - public ValueTask DisposeAsync() - { - gameLoop.Stop(); - gameLoop.Dispose(); - return ValueTask.CompletedTask; - } + } + + public ValueTask DisposeAsync() + { + gameLoop.Stop(); + gameLoop.Dispose(); + return ValueTask.CompletedTask; + } } } \ No newline at end of file diff --git a/Platforms/ZXBox.Blazor/Hardware/Kempston.cs b/Platforms/ZXBox.Blazor/Hardware/Kempston.cs index 7c0c65e..84d15ca 100644 --- a/Platforms/ZXBox.Blazor/Hardware/Kempston.cs +++ b/Platforms/ZXBox.Blazor/Hardware/Kempston.cs @@ -11,7 +11,7 @@ namespace ZXBox.Hardware.Input.Joystick /// /// The Kempston joystick interface differs from the other common types in that it does not map to the ZX Spectrum keyboard directly. Rather, it maps to a particular hardware port (0x1f) and support must therefore be 'built-in' to the software. Fortunately, the Kempston joystick interface was enormously popular, and support was very easy to provide, making Kempston control a common, almost standard, feature of most games. /// Assuming an appropriate interface is attached, reading from port 0x1f returns the current state of the Kempston joystick in the form 000FUDLR, with active bits high. - /// � www.worldofspectrum.com + /// � www.worldofspectrum.com /// public class Kempston:IInput @@ -38,9 +38,11 @@ public bool Enabled #region IInput Members - public int Input(int Port,int tact) + public void AddTStates(int tstates) { } + + public byte Input(ushort Port,int tact) { - int returnvalue = 0xFF; + byte returnvalue = 0xFF; if ((Port &0xff) == 0x1f) { returnvalue = 0x0; diff --git a/Platforms/ZXBox.Blazor/Hardware/Keyboard.cs b/Platforms/ZXBox.Blazor/Hardware/Keyboard.cs index 56f521d..cd06fa6 100644 --- a/Platforms/ZXBox.Blazor/Hardware/Keyboard.cs +++ b/Platforms/ZXBox.Blazor/Hardware/Keyboard.cs @@ -26,7 +26,9 @@ public bool GetKeyStatus(string key) return KeyBuffer.Any(k => k.ToLower() == key.ToLower()); } - public int Input(int Port, int tstates) + public void AddTStates(int tstates) { } + + public byte Input(ushort Port, int tstates) { if ((Port & 0xFF) == 0xFE) @@ -57,8 +59,7 @@ public int Input(int Port, int tstates) right = true; } - bool symbol = false; - int returnvalue = 0xFF; + var returnvalue = 0xFF; //Special cace for any key if (((Port >> 8) & 0xFF) == 0x01 || ((Port >> 8) & 0xFF) == 0x00 || ((Port >> 8) & 0xFF) == 0x02) @@ -66,7 +67,7 @@ public int Input(int Port, int tstates) if (KeyBuffer.Count() > 0) { - return returnvalue &= ~1; + return (byte)(returnvalue &= ~1); } } @@ -197,7 +198,7 @@ public int Input(int Port, int tstates) break; } - return returnvalue; + return (byte)returnvalue; } return 0xFF; } diff --git a/ZXBox.Core.Tests/CoreTest.cs b/ZXBox.Core.Tests/CoreTest.cs index 1077f1a..7cebb59 100644 --- a/ZXBox.Core.Tests/CoreTest.cs +++ b/ZXBox.Core.Tests/CoreTest.cs @@ -22,7 +22,7 @@ public static void RunTest() public static bool TestInstruction(string file) { - file = $"{Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName}\\Testfiles\\" + file; + file = $"{Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName}/Testfiles/" + file; ZXSpectrum z80 = new ZXSpectrum(); z80.Reset(); @@ -45,15 +45,15 @@ public static bool TestInstruction(string file) //z80.Memory = ts.Memory; for(int m=0;m< ts.Memory.Length; m++) { - z80.WriteByteToMemory(m, ts.Memory[m]); + z80.WriteByteToMemory((ushort)m, ts.Memory[m]); } z80.PC = ts.pc; z80.R = ts.r; z80.SP = ts.sp; - z80.DoIntructions(ts.end_tstates2); + z80.DoInstructions(ts.end_tstates2); - TestState tsout = TestfileHandler.ReadOUTFile(Path.GetDirectoryName(file) + "\\" + Path.GetFileNameWithoutExtension(file) + ".out", ts.Memory); + TestState tsout = TestfileHandler.ReadOUTFile(Path.GetDirectoryName(file) + "/" + Path.GetFileNameWithoutExtension(file) + ".out", ts.Memory); //Compare bool result = CoreTest.CompareFunction(tsout, ExtractState(z80)); @@ -71,7 +71,7 @@ public static bool CompareFunction(TestState ts, TestState z80) //Assert.AreEqual(ts.af,z80.af,"af"); //Assert.AreEqual(ts.af_, z80.af_,"af_"); - Assert.AreEqual(ts.bc,z80.bc,"bc"); + Assert.AreEqual (ts.bc,z80.bc,"bc"); Assert.AreEqual (ts.bc_, z80.bc_,"bc_"); Assert.AreEqual (ts.de, z80.de,"de"); @@ -83,7 +83,7 @@ public static bool CompareFunction(TestState ts, TestState z80) //Assert.AreEqual (ts.iff2 , z80.iff2, "iff2"); Assert.AreEqual (ts.im , z80.im, "im"); Assert.AreEqual (ts.ix , z80.ix, "ix"); - Assert.AreEqual(ts.iy, z80.iy, "iy"); + Assert.AreEqual( ts.iy, z80.iy, "iy"); //Not comparing this due to not fully implemented contended memory. //Assert.AreEqual(ts.end_tstates2, z80.end_tstates2,"tstates2"); @@ -195,7 +195,7 @@ public static TestState ExtractState(Zilog.Z80 z80) ts.iy = z80.IY; for (int m = 0; m < ts.Memory.Length; m++) { - ts.Memory[m] = z80.ReadByteFromMemory(m); + ts.Memory[m] = z80.ReadByteFromMemory((ushort)m); } ts.pc = z80.PC; ts.r = z80.R; diff --git a/ZXBox.Core.Tests/GameBoy/GBFileFormatTests.cs b/ZXBox.Core.Tests/GameBoy/GBFileFormatTests.cs index 96dbc12..9d8fdbe 100644 --- a/ZXBox.Core.Tests/GameBoy/GBFileFormatTests.cs +++ b/ZXBox.Core.Tests/GameBoy/GBFileFormatTests.cs @@ -25,8 +25,8 @@ public void LoadTileTest() ff.LoadSnapshot(bytes, gb); List tiles = new List(); //gb.PC = 0x100; //Entry point - gb.DoIntructions(1000000000); - for (int b = 0x8000; b <= 0x97FF; b++) + gb.DoInstructions(1000000000); + for (ushort b = 0x8000; b <= 0x97FF; b++) { tiles.Add(gb.ReadByteFromMemory(b)); } diff --git a/ZXBox.Core.Tests/TestState.cs b/ZXBox.Core.Tests/TestState.cs index a556a29..3e2fec2 100644 --- a/ZXBox.Core.Tests/TestState.cs +++ b/ZXBox.Core.Tests/TestState.cs @@ -4,10 +4,11 @@ namespace ZXBox.Core.Tests { public class TestState { - public int af, bc, de, hl, af_, bc_, de_, hl_, ix, iy, sp, pc; - public int i, r, im; + public ushort af, bc, de, hl, af_, bc_, de_, hl_, ix, iy, sp, pc; + public byte i, r; + public int im; public bool iff1, iff2,halted; public int end_tstates2; - public int[] Memory=new int[4*16 * 1024]; + public byte[] Memory=new byte[4*16 * 1024]; } } \ No newline at end of file diff --git a/ZXBox.Core.Tests/TestfileHandler.cs b/ZXBox.Core.Tests/TestfileHandler.cs index 33fe5ea..d0f3535 100644 --- a/ZXBox.Core.Tests/TestfileHandler.cs +++ b/ZXBox.Core.Tests/TestfileHandler.cs @@ -19,18 +19,18 @@ public static TestState ReadINFile(string Path) while (rows[0].IndexOf(" ") > 0) rows[0] = rows[0].Replace(" ", " "); string[] rowdata = rows[0].Split(' '); - ts.af = Convert.ToInt32(rowdata[0], 16); - ts.bc = Convert.ToInt32(rowdata[1], 16); - ts.de = Convert.ToInt32(rowdata[2], 16); - ts.hl = Convert.ToInt32(rowdata[3], 16); - ts.af_ = Convert.ToInt32(rowdata[4], 16); - ts.bc_ = Convert.ToInt32(rowdata[5], 16); - ts.de_ = Convert.ToInt32(rowdata[6], 16); - ts.hl_ = Convert.ToInt32(rowdata[7], 16); - ts.ix = Convert.ToInt32(rowdata[8], 16); - ts.iy = Convert.ToInt32(rowdata[9], 16); - ts.sp = Convert.ToInt32(rowdata[10], 16); - ts.pc = Convert.ToInt32(rowdata[11], 16); + ts.af = Convert.ToUInt16(rowdata[0], 16); + ts.bc = Convert.ToUInt16(rowdata[1], 16); + ts.de = Convert.ToUInt16(rowdata[2], 16); + ts.hl = Convert.ToUInt16(rowdata[3], 16); + ts.af_ = Convert.ToUInt16(rowdata[4], 16); + ts.bc_ = Convert.ToUInt16(rowdata[5], 16); + ts.de_ = Convert.ToUInt16(rowdata[6], 16); + ts.hl_ = Convert.ToUInt16(rowdata[7], 16); + ts.ix = Convert.ToUInt16(rowdata[8], 16); + ts.iy = Convert.ToUInt16(rowdata[9], 16); + ts.sp = Convert.ToUInt16(rowdata[10], 16); + ts.pc = Convert.ToUInt16(rowdata[11], 16); //&i, &r, &iff1, &iff2, &im, &z80.halted, &end_tstates2 //Since C# lacks the fscanf function we need to do this in a ugly way @@ -41,8 +41,8 @@ public static TestState ReadINFile(string Path) while (rows[1].IndexOf(" ") > 0) rows[1]=rows[1].Replace(" ", " "); rowdata = rows[1].Split(' '); - ts.i = Convert.ToInt32(rowdata[0], 16); - ts.r = Convert.ToInt32(rowdata[1], 16); + ts.i = Convert.ToByte(rowdata[0], 16); + ts.r = Convert.ToByte(rowdata[1], 16); ts.iff1 = rowdata[2]=="0"?false:true; ts.iff2 = rowdata[3]=="0"?false:true; ts.im = Convert.ToInt32(rowdata[4]); @@ -56,18 +56,18 @@ public static TestState ReadINFile(string Path) rowdata = rows[a].Split(' '); if (rowdata[0].Length > 1) { - int mempos = Convert.ToInt32(rowdata[0],16); + int mempos = Convert.ToUInt16(rowdata[0],16); for (int b = 1; b < rowdata.Length; b++) { if (rowdata[b] != "-1") - ts.Memory[mempos++] = Convert.ToInt32(rowdata[b], 16); + ts.Memory[mempos++] = Convert.ToByte(rowdata[b], 16); } } } return ts; } - public static TestState ReadOUTFile(string Path,int[] MemoryPreset) + public static TestState ReadOUTFile(string Path,byte[] MemoryPreset) { TextReader tr = new StreamReader(Path); string file = tr.ReadToEnd(); @@ -81,18 +81,18 @@ public static TestState ReadOUTFile(string Path,int[] MemoryPreset) //&af, &bc,&de, &hl, &af_, &bc_, &de_, &hl_, &ix, &iy, &sp, &pc string[] rowdata = rows[LineToStarttRead].Split(' '); - ts.af = Convert.ToInt32(rowdata[0], 16); - ts.bc = Convert.ToInt32(rowdata[1], 16); - ts.de = Convert.ToInt32(rowdata[2], 16); - ts.hl = Convert.ToInt32(rowdata[3], 16); - ts.af_ = Convert.ToInt32(rowdata[4], 16); - ts.bc_ = Convert.ToInt32(rowdata[5], 16); - ts.de_ = Convert.ToInt32(rowdata[6], 16); - ts.hl_ = Convert.ToInt32(rowdata[7], 16); - ts.ix = Convert.ToInt32(rowdata[8], 16); - ts.iy = Convert.ToInt32(rowdata[9], 16); - ts.sp = Convert.ToInt32(rowdata[10], 16); - ts.pc = Convert.ToInt32(rowdata[11], 16); + ts.af = Convert.ToUInt16(rowdata[0], 16); + ts.bc = Convert.ToUInt16(rowdata[1], 16); + ts.de = Convert.ToUInt16(rowdata[2], 16); + ts.hl = Convert.ToUInt16(rowdata[3], 16); + ts.af_ = Convert.ToUInt16(rowdata[4], 16); + ts.bc_ = Convert.ToUInt16(rowdata[5], 16); + ts.de_ = Convert.ToUInt16(rowdata[6], 16); + ts.hl_ = Convert.ToUInt16(rowdata[7], 16); + ts.ix = Convert.ToUInt16(rowdata[8], 16); + ts.iy = Convert.ToUInt16(rowdata[9], 16); + ts.sp = Convert.ToUInt16(rowdata[10], 16); + ts.pc = Convert.ToUInt16(rowdata[11], 16); //&i, &r, &iff1, &iff2, &im, &z80.halted, &end_tstates2 //Since C# lacks the fscanf function we need to do this in a ugly way @@ -103,8 +103,8 @@ public static TestState ReadOUTFile(string Path,int[] MemoryPreset) while (rows[LineToStarttRead + 1].IndexOf(" ") > 0) rows[LineToStarttRead + 1] = rows[LineToStarttRead+1].Replace(" ", " "); rowdata = rows[LineToStarttRead+1].Split(' '); - ts.i = Convert.ToInt32(rowdata[0], 16); - ts.r = Convert.ToInt32(rowdata[1], 16); + ts.i = Convert.ToByte(rowdata[0], 16); + ts.r = Convert.ToByte(rowdata[1], 16); ts.iff1 = rowdata[2] == "0" ? false : true; ts.iff2 = rowdata[3] == "0" ? false : true; ts.im = Convert.ToInt32(rowdata[4]); @@ -123,7 +123,7 @@ public static TestState ReadOUTFile(string Path,int[] MemoryPreset) for (int b = 1; b < rowdata.Length; b++) { if (rowdata[b] != "-1") - ts.Memory[mempos++] = Convert.ToInt32(rowdata[b], 16); + ts.Memory[mempos++] = Convert.ToByte(rowdata[b], 16); } } } diff --git a/ZXBox.Core/Cpus/Sharp/LR35902.cs b/ZXBox.Core/Cpus/Sharp/LR35902.cs index c9b4872..647ddae 100644 --- a/ZXBox.Core/Cpus/Sharp/LR35902.cs +++ b/ZXBox.Core/Cpus/Sharp/LR35902.cs @@ -5,23 +5,23 @@ namespace ZXBox.Core.Cpus.Sharp { public class LR35902 : Z80 { - public override int ReadByteFromMemory(int address) + public override byte ReadByteFromMemory(ushort address) { throw new System.NotImplementedException(); } - public override void WriteByteToMemory(int address, int bytetowrite) + public override void WriteByteToMemory(ushort address, byte bytetowrite) { throw new System.NotImplementedException(); } - public override void WriteWordToMemory(int address, int word) + public override void WriteWordToMemory(ushort address, ushort word) { throw new System.NotImplementedException(); } //This is implemented base on information found here https://gbdev.io/pandocs/CPU_Comparison_with_Z80.html - public override void DoIntructions(int numberOfTStates, Func gameSpecificFunc) + public override void DoInstructions(int numberOfTStates, Func gameSpecificFunc) { NumberOfTstates = numberOfTStates; _numberOfTStatesLeft += numberOfTStates; @@ -64,7 +64,8 @@ public override void DoIntructions(int numberOfTStates, Func gameSpeci switch (opcode) { case 0x08: - WriteByteToMemory(GetNextPCWord(), SP); + WriteWordToMemory(GetNextPCWord(), SP); + //WriteByteToMemory(GetNextPCWord(), SP); SubtractNumberOfTStatesLeft(13); break; case 0x10://STOP @@ -94,10 +95,10 @@ public override void DoIntructions(int numberOfTStates, Func gameSpeci case 0xDB://- break; case 0xE0://LD(FF00 + n),A - WriteByteToMemory(0xFF00 + GetNextPCByte(), A); + WriteByteToMemory((ushort)(0xFF00 + GetNextPCByte()), A); break; case 0xE2://LD(FF00 + C),A - WriteByteToMemory(0xFF00 + C, A); + WriteByteToMemory((ushort)(0xFF00 + C), A); break; case 0xE3://- break; @@ -117,11 +118,11 @@ public override void DoIntructions(int numberOfTStates, Func gameSpeci case 0xED://- break; case 0xF0://LD A,(FF00 + n) - A = ReadByteFromMemory(0xFF00 + GetNextPCByte()); + A = ReadByteFromMemory((ushort)(0xFF00 + GetNextPCByte())); SubtractNumberOfTStatesLeft(7); break; case 0xF2://LD A,(FF00 + C) - A = ReadByteFromMemory(0xFF00 + C); + A = ReadByteFromMemory((ushort)(0xFF00 + C)); SubtractNumberOfTStatesLeft(7); break; case 0xF4://- diff --git a/ZXBox.Core/Cpus/Z80/Z80.cs b/ZXBox.Core/Cpus/Z80/Z80.cs index ce17d7a..9e9c763 100644 --- a/ZXBox.Core/Cpus/Z80/Z80.cs +++ b/ZXBox.Core/Cpus/Z80/Z80.cs @@ -6,7 +6,7 @@ namespace Zilog; public abstract partial class Z80 { - public void WriteByteToMemoryOverridden(int address, int b) + public void WriteByteToMemoryOverridden(ushort address, byte b) { this.WriteByteToMemory(address, b); } @@ -34,12 +34,12 @@ public virtual void TstateChange(int diff) #region Ports //Override these - public virtual int In(int port) + public virtual byte In(ushort port) { return 0xff; } - public virtual void Out(int Port, int ByteValue, int tStates) + public virtual void Out(ushort Port, byte ByteValue, int tStates) { } @@ -104,249 +104,243 @@ public int F private static int R_H = 0x04; private static int R_L = 0x05; //Index Registers - public int[] IndexRegistry = new int[2]; - public int IX + public ushort[] IndexRegistry = new ushort[2]; + public ushort IX { - get { return IndexRegistry[(int)IndexRegistryEnum.IX]; } - set { IndexRegistry[(int)IndexRegistryEnum.IX] = value; } + get => IndexRegistry[(int)IndexRegistryEnum.IX]; + set => IndexRegistry[(int)IndexRegistryEnum.IX] = value; } - public int IY + public ushort IY { - get { return IndexRegistry[(int)IndexRegistryEnum.IY]; } - set { IndexRegistry[(int)IndexRegistryEnum.IY] = value; } + get => IndexRegistry[(int)IndexRegistryEnum.IY]; + set => IndexRegistry[(int)IndexRegistryEnum.IY] = value; } //Interrupt Register - public int I = 0; - public int[] Registers = new int[10]; + public byte I = 0; + public byte[] Registers = new byte[10]; //Registers Prim - public int[] RegitersPrim = new int[10]; - public int Fprim = 0; + public byte[] RegitersPrim = new byte[10]; + public byte Fprim = 0; //8bit - public int A + public byte A { - get { return Registers[R_A]; } - set { Registers[R_A] = value; } + get => Registers[R_A]; + set => Registers[R_A] = value; } - public int B + public byte B { - get { return Registers[R_B]; } - set { Registers[R_B] = value; } + get => Registers[R_B]; + set => Registers[R_B] = value; } - public int C + public byte C { - get { return Registers[R_C]; } - set { Registers[R_C] = value; } + get => Registers[R_C]; + set => Registers[R_C] = value; } - public int D + public byte D { - get { return Registers[R_D]; } - set { Registers[R_D] = value; } + get => Registers[R_D]; + set => Registers[R_D] = value; } - public int E + public byte E { - get { return Registers[R_E]; } - set { Registers[R_E] = value; } + get => Registers[R_E]; + set => Registers[R_E] = value; } - public int H + public byte H { - get { return Registers[R_H]; } - set { Registers[R_H] = value; } + get => Registers[R_H]; + set => Registers[R_H] = value; } - public int L + public byte L { - get { return Registers[R_L]; } - set { Registers[R_L] = value; } + get => Registers[R_L]; + set => Registers[R_L] = value; } - public int APrim + public byte APrim { - get { return RegitersPrim[R_A]; } - set { RegitersPrim[R_A] = value; } + get => RegitersPrim[R_A]; + set => RegitersPrim[R_A] = value; } - public int BPrim + public byte BPrim { - get { return RegitersPrim[R_B]; } - set { RegitersPrim[R_B] = value; } + get => RegitersPrim[R_B]; + set => RegitersPrim[R_B] = value; } - public int CPrim + public byte CPrim { - get { return RegitersPrim[R_C]; } - set { RegitersPrim[R_C] = value; } + get => RegitersPrim[R_C]; + set => RegitersPrim[R_C] = value; } - public int DPrim + public byte DPrim { - get { return RegitersPrim[R_D]; } - set { RegitersPrim[R_D] = value; } + get => RegitersPrim[R_D]; + set => RegitersPrim[R_D] = value; } - public int EPrim + public byte EPrim { - get { return RegitersPrim[R_E]; } - set { RegitersPrim[R_E] = value; } + get => RegitersPrim[R_E]; + set => RegitersPrim[R_E] = value; } - public int HPrim + public byte HPrim { - get { return RegitersPrim[R_H]; } - set { RegitersPrim[R_H] = value; } + get => RegitersPrim[R_H]; + set => RegitersPrim[R_H] = value; } - public int LPrim + public byte LPrim { - get { return RegitersPrim[R_L]; } - set { RegitersPrim[R_L] = value; } + get => RegitersPrim[R_L]; + set => RegitersPrim[R_L] = value; } - public int FPrim + public byte FPrim { - get { return Fprim; } - set { Fprim = value; } + get => Fprim; + set => Fprim = value; } //16 bit - public int HL + public ushort HL { get { - return Registers[R_H] << 8 | Registers[R_L]; + return (ushort)(Registers[R_H] << 8 | Registers[R_L]); } set { - Registers[R_H] = value >> 8; - Registers[R_L] = value & 0xff; - //if (value == 23672) - //{ - // Console.WriteLine("SET hl:" + HL.ToString()); - // Console.WriteLine("PC: " + PC.ToString()); - // Console.WriteLine("OP: 0x" + opcode.ToString("x")); - //} + Registers[R_H] = (byte)(value >> 8); + Registers[R_L] = (byte)(value & 0xff); } } - public int HLPrim + public ushort HLPrim { get { - return RegitersPrim[R_H] << 8 | RegitersPrim[R_L]; + return (ushort)(RegitersPrim[R_H] << 8 | RegitersPrim[R_L]); } set { - RegitersPrim[R_H] = value >> 8; - RegitersPrim[R_L] = value & 0xff; + RegitersPrim[R_H] = (byte)(value >> 8); + RegitersPrim[R_L] = (byte)(value & 0xff); } } - public int DE + public ushort DE { get { - return Registers[R_D] << 8 | Registers[R_E]; + return (ushort)(Registers[R_D] << 8 | Registers[R_E]); } set { - Registers[R_D] = value >> 8; - Registers[R_E] = value & 0xff; + Registers[R_D] = (byte)(value >> 8); + Registers[R_E] = (byte)(value & 0xff); } } - public int DEPrim + public ushort DEPrim { get { - return RegitersPrim[R_D] << 8 | RegitersPrim[R_E]; + return (ushort)(RegitersPrim[R_D] << 8 | RegitersPrim[R_E]); } set { - RegitersPrim[R_D] = value >> 8; - RegitersPrim[R_E] = value & 0xff; + RegitersPrim[R_D] = (byte)(value >> 8); + RegitersPrim[R_E] = (byte)(value & 0xff); } } - public int BC + public ushort BC { get { - return Registers[R_B] << 8 | Registers[R_C]; + return (ushort)(Registers[R_B] << 8 | Registers[R_C]); } set { - Registers[R_B] = value >> 8; - Registers[R_C] = value & 0xff; + Registers[R_B] = (byte)(value >> 8); + Registers[R_C] = (byte)(value & 0xff); } } - public int BCPrim + public ushort BCPrim { get { - return RegitersPrim[R_B] << 8 | RegitersPrim[R_C]; + return (ushort)(RegitersPrim[R_B] << 8 | RegitersPrim[R_C]); } set { - RegitersPrim[R_B] = value >> 8; - RegitersPrim[R_C] = value & 0xff; + RegitersPrim[R_B] = (byte)(value >> 8); + RegitersPrim[R_C] = (byte)(value & 0xff); } } - public int AF + public ushort AF { get { - return Registers[R_A] << 8 | F; + return (ushort)(Registers[R_A] << 8 | F); } set { - Registers[R_A] = value >> 8; + Registers[R_A] = (byte)(value >> 8); F = value & 0xff; } } - public int AFPrim + public ushort AFPrim { get { - return RegitersPrim[R_A] << 8 | FPrim; + return (ushort)(RegitersPrim[R_A] << 8 | FPrim); } set { - RegitersPrim[R_A] = value >> 8; - Fprim = value & 0xff; + RegitersPrim[R_A] = (byte)(value >> 8); + Fprim = (byte)(value & 0xff); } } - public int IXL + public byte IXL { - get { return IX & 0xff; } - set { IX = (IX & 0xff00) | (value); } + get => (byte)(IX & 0xff); + set => IX = (ushort)((IX & 0xff00) | (value)); } - public int IXH + public byte IXH { - get { return (IX >> 8) & 0xff; } - set { IX = (IX & 0xff) | (value << 8); } + get => (byte)((IX >> 8) & 0xff); + set => IX = (ushort)((IX & 0xff) | (value << 8)); } - public int IYL + public byte IYL { - get { return IY & 0xff; } - set { IY = (IY & 0xff00) | (value); } + get => (byte)(IY & 0xff); + set => IY = (ushort)((IY & 0xff00) | (value)); } - public int IYH + public byte IYH { - get { return (IY >> 8) & 0xff; } - set { IY = (IY & 0xff) | (value << 8); } + get => (byte)((IY >> 8) & 0xff); + set => IY = (ushort)((IY & 0xff) | (value << 8)); } /// @@ -354,20 +348,11 @@ public int IYH /// /// /// - public int RegisterValueFromOP(int rpos) - { - return Registers[(opcode >> rpos) & 7]; - } + public byte RegisterValueFromOP(int rpos) => Registers[(opcode >> rpos) & 7]; - public int BitValueFromOP - { - get { return ((opcode >> 3) & 7); } - } + public int BitValueFromOP => (opcode >> 3) & 7; - private int d - { - get { return Sign(ReadByteFromMemory(PC++)); } - } + private sbyte d => Sign(ReadByteFromMemory(PC++)); #endregion @@ -382,57 +367,57 @@ public void PCFromStack() PC = StackpopWord(); } - protected int GetNextPCByte() + protected byte GetNextPCByte() { - int b = ReadByteFromMemory(PC); - PC = PC + 1 & 0xffff; + byte b = ReadByteFromMemory(PC); + PC = (ushort)(PC + 1 & 0xffff); return b; } - protected int GetNextPCWord() + protected ushort GetNextPCWord() { - int w = ReadByteFromMemory(PC++); - w |= (ReadByteFromMemory(PC++ & 0xffff) << 8); + ushort w = ReadByteFromMemory(PC++); + w |= (ushort)(ReadByteFromMemory((ushort)(PC++ & 0xffff)) << 8); return w; } #endregion #region Stack - public void StackpushWord(int word) + public void StackpushWord(ushort word) { - int sp = ((SP - 2) & 0xffff); + ushort sp = (ushort)((SP - 2) & 0xffff); SP = sp; WriteWordToMemory(sp, word); } - public int StackpopWord() + public ushort StackpopWord() { - int w = ReadByteFromMemory(SP); + ushort w = ReadByteFromMemory(SP); SP++; - w |= (ReadByteFromMemory(SP & 0xffff) << 8); - SP = (SP + 1 & 0xffff); + w |= (ushort)(ReadByteFromMemory((ushort)(SP & 0xffff)) << 8); + SP = (ushort)(SP + 1 & 0xffff); return w; } #endregion #region Memory - public abstract void WriteWordToMemory(int address, int word); + public abstract void WriteWordToMemory(ushort address, ushort word); - public abstract void WriteByteToMemory(int address, int bytetowrite); + public abstract void WriteByteToMemory(ushort address, byte bytetowrite); - public abstract int ReadByteFromMemory(int address); + public abstract byte ReadByteFromMemory(ushort address); - public int ReadWordFromMemory(int address) + public ushort ReadWordFromMemory(ushort address) { - return (ReadByteFromMemory(address + 1 & 0xffff) << 8 | ReadByteFromMemory(address & 0xffff)) & 0xffff; + return (ushort)((ReadByteFromMemory((ushort)(address + 1 & 0xffff)) << 8 | ReadByteFromMemory((ushort)(address & 0xffff))) & 0xffff); } #endregion //Program Counter - public int PC; + public ushort PC; //Stack Pointer - public int SP = 0x10000; - protected int opcode = 0; + public ushort SP = 0xffff; + protected ushort opcode = 0; protected int _numberOfTStatesLeft; - int diff = 0; + // int diff = 0; public void SubtractNumberOfTStatesLeft(int tstates = 0) { _numberOfTStatesLeft -= tstates; @@ -441,13 +426,7 @@ public void SubtractNumberOfTStatesLeft(int tstates = 0) public bool[] Parity = new bool[256]; protected int _EndTstates2 = 0; - public int EndTstates2 - { - get - { - return _EndTstates2 + (_numberOfTStatesLeft * -1); - } - } + public int EndTstates2 => _EndTstates2 + (_numberOfTStatesLeft * -1); //Interupts and memory public bool BlockINT = true; public bool IFF = false; @@ -457,13 +436,13 @@ public int EndTstates2 public int _R = 0; public int R7 { - get { return _R7; } - set { _R7 = value; } + get => _R7; + set => _R7 = value; } - public int R + public byte R { - get { return (_R & 0x7f) | _R7; } + get { return (byte)((_R & 0x7f) | _R7); } set { _R = value; @@ -473,9 +452,7 @@ public int R public void Refresh(int t) { - // _R += t; _R = (byte)(((_R + 1) & 0x7F) | (_R & 0x80)); - //SubtractNumberOfTStatesLeft( 1; } public void Reset() @@ -513,15 +490,15 @@ public void Reset() //Clear Memory for (int a = 16384; a < 3 * 16384; a++) { - WriteByteToMemory(a, 0); + WriteByteToMemory((ushort)a, 0); } } //System.Text.StringBuilder sb = new StringBuilder(); public void NextOpcode() { - opcode = (ReadByteFromMemory(PC) & 0xff); - PC = (PC + 1) & 0xffff; + opcode = (ushort)(ReadByteFromMemory(PC) & 0xff); + PC = (ushort)((PC + 1) & 0xffff); } public int interrupt() @@ -534,7 +511,6 @@ public int interrupt() switch (IM) { - case 0: case 1: PCToStack(); IFF = false; @@ -545,9 +521,9 @@ public int interrupt() PCToStack(); IFF = false; IFF2 = false; - int t = (I << 8) | 0x00ff; + var t = (ushort)((I << 8) | 0x00ff); PC = ReadWordFromMemory(t); - return 19; + return 19; } return 0; @@ -556,13 +532,13 @@ public int interrupt() public int NumberOfTstates = 0; public StringBuilder sb = new StringBuilder(); - private DateTime start; - public void DoIntructions(int numberOfTStates = 69888) + // private DateTime start; + public void DoInstructions(int numberOfTStates = 69888) { - DoIntructions(numberOfTStates, null); + DoInstructions(numberOfTStates, null); } - public virtual void DoIntructions(int numberOfTStates, Func gameSpecificFunc) + public virtual void DoInstructions(int numberOfTStates, Func gameSpecificFunc) { NumberOfTstates = numberOfTStates; _numberOfTStatesLeft += numberOfTStates; diff --git a/ZXBox.Core/Cpus/Z80/Z80AssemblerInstructions.cs b/ZXBox.Core/Cpus/Z80/Z80AssemblerInstructions.cs index 26289da..0298bad 100644 --- a/ZXBox.Core/Cpus/Z80/Z80AssemblerInstructions.cs +++ b/ZXBox.Core/Cpus/Z80/Z80AssemblerInstructions.cs @@ -17,34 +17,29 @@ public void Refresh() public bool interruptTriggered(int tstates) { - return (tstates <= 0); + return tstates <= 0; } - int pushsp; - public void PUSH(int word) + public void PUSH(ushort word) { - // int sp = ((SP() - 2) & 0xffff); - // SP(sp); - // PokeW(sp, word); - pushsp = (SP - 2 & 0xffff); + var pushsp = (ushort)(SP - 2 & 0xffff); SP = pushsp; WriteWordToMemory(pushsp, word); } - private int RES(int bit, int value, int tstates) + private byte RES(int bit, byte value, int tstates) { SubtractNumberOfTStatesLeft(tstates); - return value & ~bitArray[bit]; + return (byte)(value & ~bitArray[bit]); } - bool rlc; - public int RL(int value, int tstates) + public byte RL(byte value, int tstates) { - rlc = (value & 0x80) != 0; + var rlc = (value & 0x80) != 0; if (fC) { - value = (value << 1) | 0x01; + value = (byte)((value << 1) | 0x01); } else { @@ -53,27 +48,26 @@ public int RL(int value, int tstates) value &= 0xff; fS = (value & F_S) != 0; - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; fPV = Parity[value]; fH = false; fN = false; fC = rlc; SubtractNumberOfTStatesLeft(tstates); - return (value); + return value; } - int rlcavalue; public void RLCA() { - rlcavalue = A; + var rlcavalue = A; bool c = (rlcavalue & 0x80) != 0; if (c) { - rlcavalue = (rlcavalue << 1) | 0x01; + rlcavalue = (byte)((rlcavalue << 1) | 0x01); } else { @@ -81,8 +75,8 @@ public void RLCA() } rlcavalue &= 0xff; - f3 = ((rlcavalue & F_3) != 0); - f5 = ((rlcavalue & F_5) != 0); + f3 = (rlcavalue & F_3) != 0; + f5 = (rlcavalue & F_5) != 0; fN = false; fH = false; fC = c; @@ -90,24 +84,20 @@ public void RLCA() A = rlcavalue; } - int sbc8a; - int sbc8c; - int value; - int sbc8truncated; - private int SBC8(int b, int tstates) - { - sbc8a = A; - sbc8c = fC ? 1 : 0; - value = sbc8a - b - sbc8c; - sbc8truncated = value & 0xff; - - fS = ((sbc8truncated & F_S) != 0); - f3 = ((sbc8truncated & F_3) != 0); - f5 = ((sbc8truncated & F_5) != 0); - fZ = ((sbc8truncated) == 0); - fC = ((value & 0x100) != 0); - fPV = (((sbc8a ^ b) & (sbc8a ^ sbc8truncated) & 0x80) != 0); - fH = ((((sbc8a & 0x0f) - (b & 0x0f) - sbc8c) & F_H) != 0); + private byte SBC8(byte b, int tstates) + { + var sbc8a = A; + var sbc8c = fC ? 1 : 0; + var value = sbc8a - b - sbc8c; + var sbc8truncated = (byte)(value & 0xff); + + fS = (sbc8truncated & F_S) != 0; + f3 = (sbc8truncated & F_3) != 0; + f5 = (sbc8truncated & F_5) != 0; + fZ = sbc8truncated == 0; + fC = (value & 0x100) != 0; + fPV = ((sbc8a ^ b) & (sbc8a ^ sbc8truncated) & 0x80) != 0; + fH = (((sbc8a & 0x0f) - (b & 0x0f) - sbc8c) & F_H) != 0; fN = true; SubtractNumberOfTStatesLeft(tstates); @@ -115,36 +105,32 @@ private int SBC8(int b, int tstates) return sbc8truncated; } - int sbc16c; - int sbc16value; - int sbc16truncated; - private int SBC16(int a, int b, int tstates) + private ushort SBC16(ushort a, ushort b, int tstates) { - sbc16c = fC ? 1 : 0; - sbc16value = a - b - sbc16c; - sbc16truncated = sbc16value & 0xffff; + var sbc16c = fC ? 1 : 0; + var sbc16value = (a - b - sbc16c); + var sbc16truncated = (ushort)(sbc16value & 0xffff); - fS = ((sbc16truncated & (F_S << 8)) != 0); - f3 = ((sbc16truncated & (F_3 << 8)) != 0); - f5 = ((sbc16truncated & (F_5 << 8)) != 0); - fZ = ((sbc16truncated) == 0); - fC = ((sbc16value & 0x10000) != 0); - fPV = (((a ^ b) & (a ^ sbc16truncated) & 0x8000) != 0); - fH = ((((a & 0x0fff) - (b & 0x0fff) - sbc16c) & 0x1000) != 0); + fS = (sbc16truncated & (F_S << 8)) != 0; + f3 = (sbc16truncated & (F_3 << 8)) != 0; + f5 = (sbc16truncated & (F_5 << 8)) != 0; + fZ = sbc16truncated == 0; + fC = (sbc16value & 0x10000) != 0; // TODO: Does this even make sense? + fPV = ((a ^ b) & (a ^ sbc16truncated) & 0x8000) != 0; + fH = (((a & 0x0fff) - (b & 0x0fff) - sbc16c) & 0x1000) != 0; fN = true; SubtractNumberOfTStatesLeft(tstates); return sbc16truncated; } - bool rlcc; - public int RLC(int value, int tstates) + public byte RLC(byte value, int tstates) { - rlcc = (value & 0x80) != 0; + var rlcc = (value & 0x80) != 0; if (rlcc) { - value = (value << 1) | 0x01; + value = (byte)((value << 1) | 0x01); } else { @@ -152,11 +138,11 @@ public int RLC(int value, int tstates) } value &= 0xff; - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); - fPV = (Parity[value]); + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; + fPV = Parity[value]; fH = false; fN = false; fC = rlcc; @@ -165,15 +151,14 @@ public int RLC(int value, int tstates) return value; } - int rlavalue; bool rlac; public void RLA() { - rlavalue = A; - rlac = (rlavalue & 0x80) != 0; + var rlavalue = A; + var rlac = (rlavalue & 0x80) != 0; if (fC) { - rlavalue = (rlavalue << 1) | 0x01; + rlavalue = (byte)((rlavalue << 1) | 0x01); } else { @@ -182,8 +167,8 @@ public void RLA() rlavalue &= 0xff; - f3 = ((rlavalue & F_3) != 0); - f5 = ((rlavalue & F_5) != 0); + f3 = (rlavalue & F_3) != 0; + f5 = (rlavalue & F_5) != 0; fN = false; fH = false; fC = rlac; @@ -191,24 +176,23 @@ public void RLA() A = rlavalue; } - bool rrc; - public int RR(int value, int tstates) + public byte RR(byte value, int tstates) { - rrc = (value & 0x01) != 0; + var rrc = (value & 0x01) != 0; if (fC) { - value = (value >> 1) | 0x80; + value = (byte)((value >> 1) | 0x80); } else { value >>= 1; } - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; fPV = Parity[value]; fH = false; fN = false; @@ -220,56 +204,55 @@ public int RR(int value, int tstates) public void Halt() { - tmphaltsToInterrupt = (((_numberOfTStatesLeft - 1) / 4) + 1); - SubtractNumberOfTStatesLeft((tmphaltsToInterrupt * 4)); + tmphaltsToInterrupt = ((_numberOfTStatesLeft - 1) / 4) + 1; + SubtractNumberOfTStatesLeft(tmphaltsToInterrupt * 4); Refresh(tmphaltsToInterrupt - 1); } - public void RST(int position) + public void RST(ushort position) { PUSH(PC); PC = position; SubtractNumberOfTStatesLeft(11); } - int rrdvalue; int rrdm; int rrdq; public void RRD() { - rrdvalue = A; - rrdm = ReadByteFromMemory(HL); - rrdq = rrdm; + var rrdvalue = A; + var rrdm = ReadByteFromMemory(HL); + var rrdq = rrdm; - rrdm = (rrdm >> 4) | (rrdvalue << 4); - rrdvalue = (rrdvalue & 0xf0) | (rrdq & 0x0f); + rrdm = (byte)((rrdm >> 4) | (rrdvalue << 4)); + rrdvalue = (byte)((rrdvalue & 0xf0) | (rrdq & 0x0f)); WriteByteToMemory(HL, rrdm); - fS = ((rrdvalue & F_S) != 0); - f3 = ((rrdvalue & F_3) != 0); - f5 = ((rrdvalue & F_5) != 0); - fZ = (rrdvalue == 0); + fS = (rrdvalue & F_S) != 0; + f3 = (rrdvalue & F_3) != 0; + f5 = (rrdvalue & F_5) != 0; + fZ = rrdvalue == 0; fPV = Parity[rrdvalue]; fH = false; fN = false; SubtractNumberOfTStatesLeft(18); A = rrdvalue; } - int rrcavalue; bool rrcac; + public void RRCA() { - rrcavalue = A; - rrcac = (rrcavalue & 0x01) != 0; + var rrcavalue = A; + var rrcac = (rrcavalue & 0x01) != 0; if (rrcac) { - rrcavalue = (rrcavalue >> 1) | 0x80; + rrcavalue = (byte)((rrcavalue >> 1) | 0x80); } else { rrcavalue >>= 1; } - f3 = ((rrcavalue & F_3) != 0); - f5 = ((rrcavalue & F_5) != 0); + f3 = (rrcavalue & F_3) != 0; + f5 = (rrcavalue & F_5) != 0; fN = false; fH = false; fC = rrcac; @@ -278,180 +261,154 @@ public void RRCA() A = rrcavalue; } - bool rrcc; - public int RRC(int value, int tstates) + public byte RRC(byte value, int tstates) { - rrcc = (value & 0x01) != 0; + var rrcc = (value & 0x01) != 0; if (rrcc) { - value = (value >> 1) | 0x80; + value = (byte)((value >> 1) | 0x80); } else { value >>= 1; } - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); - fPV = (Parity[value]); + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; + fPV = Parity[value]; fH = false; fN = false; fC = rrcc; SubtractNumberOfTStatesLeft(tstates); - return value; + return (byte)value; } - int rravalue; bool rrac; public void RRA() { - rravalue = A; - rrac = (rravalue & 0x01) != 0; + var rravalue = A; + var rrac = (rravalue & 0x01) != 0; if (fC) { - rravalue = (rravalue >> 1) | 0x80; + rravalue = (byte)((rravalue >> 1) | 0x80); } else { rravalue >>= 1; } - f3 = ((rravalue & F_3) != 0); - f5 = ((rravalue & F_5) != 0); - fN = (false); - fH = (false); - fC = (rrac); + f3 = (rravalue & F_3) != 0; + f5 = (rravalue & F_5) != 0; + fN = false; + fH = false; + fC = rrac; SubtractNumberOfTStatesLeft(4); - A = rravalue; + A = (byte)rravalue; } - int rldm; int rldq; int rldvalue; + public void RLD() { - rldvalue = A; - rldm = ReadByteFromMemory(HL); - rldq = rldm; + var rldvalue = A; + var rldm = ReadByteFromMemory(HL); + var rldq = rldm; - rldm = (rldm << 4) | (rldvalue & 0x0f); - rldvalue = (rldvalue & 0xf0) | (rldq >> 4); - WriteByteToMemory(HL, rldm & 0xff); + rldm = (byte)((rldm << 4) | (rldvalue & 0x0f)); + rldvalue = (byte)((rldvalue & 0xf0) | (rldq >> 4)); + WriteByteToMemory(HL, (byte)(rldm & 0xff)); - fS = ((rldvalue & F_S) != 0); - f3 = ((rldvalue & F_3) != 0); - f5 = ((rldvalue & F_5) != 0); - fZ = (rldvalue == 0); + fS = (rldvalue & F_S) != 0; + f3 = (rldvalue & F_3) != 0; + f5 = (rldvalue & F_5) != 0; + fZ = rldvalue == 0; fPV = Parity[rldvalue]; fH = false; fN = false; SubtractNumberOfTStatesLeft(18); - A = rldvalue; + A = (byte)rldvalue; } - bool srac; - public int SRA(int value, int tstates) + public byte SRA(int value, int tstates) { - srac = (value & 0x01) != 0; + var srac = (value & 0x01) != 0; value = (value >> 1) | (value & 0x80); - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; fPV = Parity[value]; fH = false; fN = false; fC = srac; SubtractNumberOfTStatesLeft(tstates); - return value; + return (byte)value; } - //public void SUB(int value,int tstates) - //{ - // int a = A; - // int subtracted = a - value; - // int truncated = wans & 0xff; - - // fS=((truncated & F_S) != 0); - // f3=((truncated & F_3) != 0); - // f5=((truncated & F_5) != 0); - // fZ=((truncated) == 0); - // fC=((wans & 0x100) != 0); - // fPV=(((a ^ value) & (a ^ truncated) & 0x80) != 0); - // fH=((((a & 0x0f) - (value & 0x0f)) & F_H) != 0); - // fN=true; - - // SubtractNumberOfTStatesLeft( tstates; - - // A=truncated; - //} - - int xornewvalue; public void XOR(int value, int tstates) { - xornewvalue = (A ^ value) & 0xff; + var xornewvalue = (A ^ value) & 0xff; - fS = ((xornewvalue & F_S) != 0); - f3 = ((xornewvalue & F_3) != 0); - f5 = ((xornewvalue & F_5) != 0); - fH = (false); - fPV = (Parity[xornewvalue]); - fZ = (xornewvalue == 0); + fS = (xornewvalue & F_S) != 0; + f3 = (xornewvalue & F_3) != 0; + f5 = (xornewvalue & F_5) != 0; + fH = false; + fPV = Parity[xornewvalue]; + fZ = xornewvalue == 0; fN = false; fC = false; SubtractNumberOfTStatesLeft(tstates); - A = xornewvalue; + A = (byte)xornewvalue; } - bool srlc; - private int SRL(int value, int tstates) + private byte SRL(int value, int tstates) { - srlc = (value & 0x01) != 0; + var srlc = (value & 0x01) != 0; value = value >> 1; - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; fPV = Parity[value]; fH = false; fN = false; fC = srlc; SubtractNumberOfTStatesLeft(tstates); - return (value); + return (byte)value; } - bool slac; - public int SLA(int value, int tstates) + public byte SLA(int value, int tstates) { - slac = (value & 0x80) != 0; + var slac = (value & 0x80) != 0; value = (value << 1) & 0xff; - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; fPV = Parity[value]; fH = false; fN = false; fC = slac; SubtractNumberOfTStatesLeft(tstates); - return value; + return (byte)value; } - private int SET(int bit, int value, int tstates) + private byte SET(int bit, int value, int tstates) { SubtractNumberOfTStatesLeft(tstates); - return value | bitArray[bit]; + return (byte)(value | bitArray[bit]); } public void RET(bool condition, int tstates, int notmettstates) @@ -467,19 +424,14 @@ public void RET(bool condition, int tstates, int notmettstates) } } - int popsp; int popt; - public int POP() + public ushort POP() { - popsp = SP; - popt = ReadByteFromMemory(popsp); + var popsp = SP; + ushort popt = ReadByteFromMemory(popsp); popsp++; - popt |= (ReadByteFromMemory(popsp & 0xffff) << 8); - SP = (++popsp & 0xffff); + popt |= (ushort)(ReadByteFromMemory((ushort)(popsp & 0xffff)) << 8); + SP = (ushort)(++popsp & 0xffff); return popt; - - //int retval = ReadWordFromMemory(SP); - //SP=(SP+2 & 0xffff); - //return retval; } public void OUTI() @@ -490,7 +442,7 @@ public void OUTI() Out(BC, ReadByteFromMemory(HL), NumberOfTstates - Math.Abs(_numberOfTStatesLeft)); HL = INC16(HL, 0); - fZ = (B == 0); + fZ = B == 0; fN = true; if (ReadByteFromMemory(HL) + L > 255) { @@ -502,22 +454,21 @@ public void OUTI() fH = false; fC = false; } - fPV = Parity[(((ReadByteFromMemory(HL) + L) & 7) ^ B)]; + fPV = Parity[((ReadByteFromMemory(HL) + L) & 7) ^ B]; SubtractNumberOfTStatesLeft(7); } - int outdvalue; public void OUTD() { B = DEC8(B, 0); - outdvalue = ReadByteFromMemory(HL); + var outdvalue = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(9); Out(BC, outdvalue, NumberOfTstates - Math.Abs(_numberOfTStatesLeft)); HL = DEC16(HL, 0); - fZ = (B == 0); + fZ = B == 0; fN = (outdvalue >> 7 & 0x01) != 1; if ((outdvalue + L) > 255) { @@ -529,14 +480,13 @@ public void OUTD() fH = false; fC = false; } - fPV = Parity[(((outdvalue + L) & 7) ^ B)]; + fPV = Parity[((outdvalue + L) & 7) ^ B]; SubtractNumberOfTStatesLeft(7); } - int otirvalue; public void OTIR() { - otirvalue = ReadByteFromMemory(HL); + var otirvalue = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(9); B = DEC8(B, 0); Out(BC, otirvalue, NumberOfTstates - Math.Abs(_numberOfTStatesLeft)); @@ -553,11 +503,11 @@ public void OTIR() fH = true; fC = true; } - fPV = Parity[(((otirvalue + L) & 7) ^ B)]; + fPV = Parity[((otirvalue + L) & 7) ^ B]; if (B != 0) { - PC = (PC - 2) & 0xffff; + PC = (ushort)((PC - 2) & 0xffff); SubtractNumberOfTStatesLeft(12); } else @@ -578,7 +528,7 @@ public void OTDR() fZ = true; if (B != 0) { - PC = (PC - 2) & 0xffff; + PC = (ushort)((PC - 2) & 0xffff); SubtractNumberOfTStatesLeft(12); } else @@ -587,10 +537,9 @@ public void OTDR() } } - int orvalue; public void OR(int b, int tstates) { - orvalue = A | b; + var orvalue = A | b; fS = (orvalue & F_S) != 0; f3 = (orvalue & F_3) != 0; @@ -601,7 +550,7 @@ public void OR(int b, int tstates) fN = false; fC = false; SubtractNumberOfTStatesLeft(tstates); - A = orvalue; + A = (byte)orvalue; } public void NOP() @@ -609,21 +558,19 @@ public void NOP() SubtractNumberOfTStatesLeft(4); } - int negtmp; public void NEG() { - negtmp = A; + var negtmp = A; A = 0; SUB(negtmp, 0); SubtractNumberOfTStatesLeft(8); } - int lddmemval; int lddn; public void LDD() { - lddmemval = ReadByteFromMemory(HL); - WriteByteToMemory(DE, lddmemval); + var lddmemval = ReadByteFromMemory(HL); + WriteByteToMemory(DE, (byte)lddmemval); DE = DEC16(DE, 0); HL = DEC16(HL, 0); BC = DEC16(BC, 0); @@ -632,22 +579,21 @@ public void LDD() fH = false; fN = false; - lddn = lddmemval + A; + var lddn = lddmemval + A; - f5 = ((lddn & 0x01) == 1); - f3 = ((lddn >> 3 & 0x01) == 1); + f5 = (lddn & 0x01) == 1; + f3 = (lddn >> 3 & 0x01) == 1; SubtractNumberOfTStatesLeft(16); } - int lddr_local_tstates; int lddrcount, lddrdest, lddrfrom; public void LDDR() { //TODO:fix this - lddr_local_tstates = 0; + var lddr_local_tstates = 0; - lddrcount = BC; - lddrdest = DE; - lddrfrom = HL; + var lddrcount = BC; + var lddrdest = DE; + var lddrfrom = HL; Refresh(-2); do { @@ -656,7 +602,7 @@ public void LDDR() lddrdest = DEC16(lddrdest, 0); lddrcount = DEC16(lddrcount, 0); - lddr_local_tstates += (21); + lddr_local_tstates += 21; Refresh(2); if (interruptTriggered(lddr_local_tstates)) { @@ -667,46 +613,28 @@ public void LDDR() if (lddrcount != 0) { - PC = ((PC - 2) & 0xffff); + PC = (ushort)((PC - 2) & 0xffff); fH = false; fN = false; fPV = true; } else { - lddr_local_tstates += (-5); + lddr_local_tstates += -5; fH = false; fN = false; fPV = false; } - DE = lddrdest; - HL = lddrfrom; - BC = lddrcount; + DE = (ushort)lddrdest; + HL = (ushort)lddrfrom; + BC = (ushort)lddrcount; SubtractNumberOfTStatesLeft(lddr_local_tstates); - //int tstates = (5 + 16 * (BC)); - //int tmp1 = DE; - //int tmp2 = HL; // LDDR - ok - //Refresh(-2); - //for (int n = (BC); n > 0; n--) - //{ - // WriteByteToMemory(tmp1--, ReadByteFromMemory(tmp2--)); - // Refresh(2); - //} - //E = tmp1 & 0xff; - //D = tmp1 >> 8; - //B = C = 0; - //L = tmp2 & 0xff; - //H = tmp2 >> 8; - //F &= 0xe9; - - //SubtractNumberOfTStatesLeft( tstates; - } - - int ldimemval = 0; + } + public void LDI() { int ldimemval = ReadByteFromMemory(HL); - WriteByteToMemory(DE, ldimemval); + WriteByteToMemory(DE, (byte)ldimemval); DE = INC16(DE, 0); HL = INC16(HL, 0); BC = DEC16(BC, 0); @@ -716,43 +644,21 @@ public void LDI() fPV = BC != 0; fH = false; fN = false; - f5 = ((n & 0x01) == 1); - f3 = ((n >> 3 & 0x01) == 1); + f5 = (n & 0x01) == 1; + f3 = (n >> 3 & 0x01) == 1; SubtractNumberOfTStatesLeft(16); } - int ldir_local_tstates, ldircount, ldirdest, ldirfrom; public void LDIR() { - ldir_local_tstates = 0; + var ldir_local_tstates = 0; - ldircount = BC; - ldirdest = DE; - ldirfrom = HL; + var ldircount = BC; + var ldirdest = DE; + var ldirfrom = HL; Refresh(-2); - //var timeleft = NumberOfTStatesLeft/21; - //int lenght = count; - //if (timeleft < count) - //{ - // lenght = timeleft; - // if (lenght == 0) //Always let it run once - // { - // lenght = 1; - // } - //} - - ////Buffer.BlockCopy(Memory, from * sizeof(int), Memory, dest * sizeof(int), lenght * sizeof(int)); - //Array.Copy(Memory, from , Memory, dest , lenght); - - //count = (count - lenght) & 0xffff; - //from = (from + lenght) & 0xffff; - //dest = (dest + lenght) & 0xffff; - - //_local_tstates = 21 * lenght; - //Refresh(2 * lenght); - do { WriteByteToMemory(ldirdest, ReadByteFromMemory(ldirfrom)); @@ -761,7 +667,7 @@ public void LDIR() ldirdest = INC16(ldirdest, 0); ldircount = DEC16(ldircount, 0); - ldir_local_tstates += (21); + ldir_local_tstates += 21; Refresh(2); if (interruptTriggered(_numberOfTStatesLeft - ldir_local_tstates)) { @@ -771,14 +677,14 @@ public void LDIR() if (ldircount != 0) { - PC = (PC - 2) & 0xffff; + PC = (ushort)((PC - 2) & 0xffff); fH = false; fN = false; fPV = true; } else { - ldir_local_tstates += (-5); + ldir_local_tstates += -5; fH = false; fN = false; fPV = false; @@ -787,60 +693,17 @@ public void LDIR() HL = ldirfrom; BC = ldircount; - /*int tstates = 0; - int tmp1 = DE; - int tmp2 = HL; - int nvalue = 0; - int count = BC; - Refresh(-2); - do // for (int n = (BC); n > 0; n--) - { - int b = ReadByteFromMemory(tmp2); - WriteByteToMemory(tmp1, b); - tmp1 = (tmp1 + 1) & 0xffff; - tmp2 = (tmp2 + 1) & 0xffff; - nvalue = b + A; - Refresh(2); - tstates += (21); - if (interruptTriggered(tstates)) - { - break; - } - }while (count != 0); - - if (count != 0) - { - PC = PC - 2; - fH = false; - fN = false; - fPV = true; - } - else - { - tstates += (-5); - f5=((nvalue & 0x01)==1); - fH=false; - f3=((nvalue>>3 & 0x01)==1); - fPV = (BC != 0); - } - E = tmp1 & 0xff; - D = tmp1 >> 8; - //B = C = 0; - L = tmp2 & 0xff; - H = tmp2 >> 8;*/ - SubtractNumberOfTStatesLeft(ldir_local_tstates); } - int ldarvalue; private void LDAR() { - ldarvalue = R; + var ldarvalue = R; - fS = ((ldarvalue & F_S) != 0); - f3 = ((ldarvalue & F_3) != 0); - f5 = ((ldarvalue & F_5) != 0); - fZ = (ldarvalue == 0); + fS = (ldarvalue & F_S) != 0; + f3 = (ldarvalue & F_3) != 0; + f5 = (ldarvalue & F_5) != 0; + fZ = ldarvalue == 0; fPV = IFF2; fH = false; fN = false; @@ -848,14 +711,14 @@ private void LDAR() SubtractNumberOfTStatesLeft(9); A = ldarvalue; } - int ldaivalue; + public void LDAI() { - ldaivalue = I; + var ldaivalue = I; - fS = ((ldaivalue & F_S) != 0); - f3 = ((ldaivalue & F_3) != 0); - f5 = ((ldaivalue & F_5) != 0); + fS = (ldaivalue & F_S) != 0; + f3 = (ldaivalue & F_3) != 0; + f5 = (ldaivalue & F_5) != 0; fZ = ldaivalue == 0; fPV = IFF2; fH = false; @@ -868,35 +731,34 @@ public void LDAI() public void JP(bool argument, int position, int tstates) { if (argument) - PC = position; + PC = (ushort)position; SubtractNumberOfTStatesLeft(tstates); } - private int Sign(int nn) + private sbyte Sign(byte nn) { - return nn - ((nn & 128) << 1); + return (sbyte)(nn);// - ((nn & 128) << 1)); } public void JR(bool argument, int position, int tstates) { if (argument) { - PC = (PC + Sign(position)) & 0xFFFF; + PC = (ushort)((PC + Sign((byte)position)) & 0xFFFF); } SubtractNumberOfTStatesLeft(tstates); } - int inbcvalue; - public int INBC(int tstates) + public byte INBC(int tstates) { - inbcvalue = In(BC); + var inbcvalue = (byte)In(BC); SubtractNumberOfTStatesLeft(tstates); - fZ = (inbcvalue == 0); - fS = ((inbcvalue & F_S) != 0); - f3 = ((inbcvalue & F_3) != 0); - f5 = ((inbcvalue & F_5) != 0); + fZ = inbcvalue == 0; + fS = (inbcvalue & F_S) != 0; + f3 = (inbcvalue & F_3) != 0; + f5 = (inbcvalue & F_5) != 0; fPV = Parity[inbcvalue]; fN = false; fH = false; @@ -910,19 +772,18 @@ public void INDR() if (B != 0) //If B is not zero Do instruction again { - PC = PC - 2; + PC = (ushort)(PC - 2); SubtractNumberOfTStatesLeft(21); } else SubtractNumberOfTStatesLeft(16); } - int indb; public void IND(int tstates) { - indb = DEC8(B, 0); - WriteByteToMemory(HL, In(BC)); - B = indb; + var indb = DEC8(B, 0); + WriteByteToMemory(HL, (byte)In(BC)); + B = (byte)indb; HL = DEC16(HL, 0); fZ = indb == 0; @@ -937,16 +798,15 @@ public void IND(int tstates) fC = false; fH = false; } - fPV = Parity[(((ReadByteFromMemory(HL) + ((C - 1) & 255)) & 7) ^ B)]; + fPV = Parity[((ReadByteFromMemory(HL) + ((C - 1) & 255)) & 7) ^ B]; SubtractNumberOfTStatesLeft(tstates); } - int inib, inival; public void INI(int tstates) { - inib = DEC8(B, 0); - inival = In(BC); - WriteByteToMemory(HL, inival); + var inib = DEC8(B, 0); + var inival = (byte)In(BC); + WriteByteToMemory(HL, (byte)inival); B = inib; HL = INC16(HL, 0); @@ -962,7 +822,7 @@ public void INI(int tstates) fC = false; fH = false; } - fPV = Parity[(((inival + ((C + 1) & 255)) & 7) ^ B)]; + fPV = Parity[((inival + ((C + 1) & 255)) & 7) ^ B]; SubtractNumberOfTStatesLeft(tstates); } @@ -972,7 +832,7 @@ public void INIR() if (B != 0) { SubtractNumberOfTStatesLeft(21); - PC = PC - 2; + PC = (ushort)(PC - 2); } else { @@ -981,24 +841,23 @@ public void INIR() } - int addadc8c, addadc8newvalue, addadc8truncated; - public int ADDADC8(int a, int b, bool Carry, int tStates) + public byte ADDADC8(byte a, byte b, bool Carry, int tStates) { - addadc8c = 0; + var addadc8c = 0; if (Carry) addadc8c = fC ? 1 : 0; //Add 1 if carry is set - addadc8newvalue = a + b + addadc8c; - addadc8truncated = addadc8newvalue & 0xff; + var addadc8newvalue = a + b + addadc8c; + var addadc8truncated = (byte)(addadc8newvalue & 0xff); //Set flags - fS = ((addadc8truncated & F_S) != 0); - f3 = ((addadc8truncated & F_3) != 0); - f5 = ((addadc8truncated & F_5) != 0); - fZ = ((addadc8truncated) == 0); - fC = ((addadc8newvalue & 0x100) != 0); - fPV = (((a ^ ~b) & (a ^ addadc8truncated) & 0x80) != 0); - fH = ((((a & 0x0f) + (b & 0x0f) + addadc8c) & F_H) != 0); + fS = (addadc8truncated & F_S) != 0; + f3 = (addadc8truncated & F_3) != 0; + f5 = (addadc8truncated & F_5) != 0; + fZ = addadc8truncated == 0; + fC = (addadc8newvalue & 0x100) != 0; + fPV = ((a ^ ~b) & (a ^ addadc8truncated) & 0x80) != 0; + fH = (((a & 0x0f) + (b & 0x0f) + addadc8c) & F_H) != 0; fN = false; SubtractNumberOfTStatesLeft(tStates); @@ -1006,12 +865,11 @@ public int ADDADC8(int a, int b, bool Carry, int tStates) return addadc8truncated; } - int addadc16c, addadc16added, addadc16truncated; - private int ADDADC16(int a, int b, bool Carry, int tStates) + private ushort ADDADC16(ushort a, ushort b, bool Carry, int tStates) { - addadc16c = fC && Carry ? 1 : 0; - addadc16added = a + b + addadc16c; - addadc16truncated = addadc16added & 0xffff; + var addadc16c = fC && Carry ? 1 : 0; + var addadc16added = a + b + addadc16c; + var addadc16truncated = (ushort)(addadc16added & 0xffff); f3 = (addadc16truncated & (F_3 << 8)) != 0; f5 = (addadc16truncated & (F_5 << 8)) != 0; @@ -1022,16 +880,15 @@ private int ADDADC16(int a, int b, bool Carry, int tStates) { fS = (addadc16truncated & (F_S << 8)) != 0; fPV = ((a ^ ~b) & (a ^ addadc16truncated) & 0x8000) != 0; - fZ = (addadc16truncated) == 0; + fZ = addadc16truncated == 0; } SubtractNumberOfTStatesLeft(tStates); - return (addadc16truncated); + return addadc16truncated; } - int and8newvalue; - public int AND8(int a, int b, int tStates) + public byte AND8(byte a, byte b, int tStates) { - and8newvalue = a & b; + var and8newvalue = a & b; fS = (and8newvalue & F_S) != 0; f3 = (and8newvalue & F_3) != 0; @@ -1043,135 +900,108 @@ public int AND8(int a, int b, int tStates) fC = false; SubtractNumberOfTStatesLeft(tStates); - return and8newvalue; + return (byte)and8newvalue; } - bool bitbitIsSet; public void BIT(int bit, int regvalue, int tStates) { - bitbitIsSet = ((regvalue & bitArray[bit]) != 0); - - //fN = false; - //fH = true; - //if (bit == 3) - // f3 = bitIsSet; - //if (bit == 5) - // f5 = bitIsSet; - //fS = ((bit == 7) ? bitIsSet : false); - //fZ = !bitIsSet; - //fPV = !bitIsSet; - SubtractNumberOfTStatesLeft(tStates); - //fN=false; - //fH=true; - //f3=((regvalue & F_3) != 0); - //f5=((regvalue & F_5) != 0); - //fS=((bit == F_S) ? bitIsSet : false); - //fZ=(!bitIsSet); - //fPV=(!bitIsSet); F = (byte)((F & F_C) | - F_H | - (regvalue & (F_3 | F_5)) | - ((regvalue & (0x01 << bit)) != 0 ? 0 : (F_PV | F_Z))); - + F_H | + (regvalue & (F_3 | F_5)) | + ((regvalue & (0x01 << bit)) != 0 ? 0 : (F_PV | F_Z))); } - bool bitixydbitIsSet; public void BITixyd(int bit, int regvalue, int ixyd, int tStates) { - bitixydbitIsSet = ((regvalue & bitArray[bit]) != 0); + var bitixydbitIsSet = (regvalue & bitArray[bit]) != 0; fN = false; fH = true; - f3 = ((ixyd >> 11 & 0x01) == 1) ? true : false; - f5 = ((ixyd >> 13 & 0x01) == 1) ? true : false; - fS = ((bit == 7) ? bitixydbitIsSet : false); + f3 = (ixyd >> 11 & 0x01) == 1; + f5 = (ixyd >> 13 & 0x01) == 1; + fS = (bit == 7) && bitixydbitIsSet; fZ = !bitixydbitIsSet; fPV = !bitixydbitIsSet; SubtractNumberOfTStatesLeft(tStates); } - int callnnw; public void CALLnn() { - callnnw = GetNextPCWord(); + var callnnw = GetNextPCWord(); PCToStack(); PC = callnnw; SubtractNumberOfTStatesLeft(17); } - int sllc; - private int SLL(int value, int tstates) + private byte SLL(byte value, int tstates) { - sllc = (value & 0x80) >> 7; - value = ((value << 1) | 1) & 0xff; + var sllc = (value & 0x80) >> 7; + value = (byte)(((value << 1) | 1) & 0xff); - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; fPV = Parity[value]; fH = false; fN = false; - fC = (sllc == 1); + fC = sllc == 1; SubtractNumberOfTStatesLeft(tstates); return value; } - int cpa, cpwvalue, cpnewvalue; /// /// Compare operand s to ackumulator /// /// Operand /// Number of tstates - private void CP(int value, int tstates) + private void CP(byte value, int tstates) { - cpa = A; - cpwvalue = cpa - value; - cpnewvalue = cpwvalue & 0xff; + var cpa = A; + var cpwvalue = cpa - value; + var cpnewvalue = (byte)(cpwvalue & 0xff); - fS = ((cpnewvalue & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fN = (true); - fZ = (cpnewvalue == 0); - fC = ((cpwvalue & 0x100) != 0); - fH = ((((cpa & 0x0f) - (value & 0x0f)) & F_H) != 0); - fPV = (((cpa ^ value) & (cpa ^ cpnewvalue) & 0x80) != 0); + fS = (cpnewvalue & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fN = true; + fZ = cpnewvalue == 0; + fC = (cpwvalue & 0x100) != 0; + fH = (((cpa & 0x0f) - (value & 0x0f)) & F_H) != 0; + fPV = ((cpa ^ value) & (cpa ^ cpnewvalue) & 0x80) != 0; SubtractNumberOfTStatesLeft(tstates); } - int cp2sub, cp2truncated; - public void CP2(int s, int tStates) + public void CP2(byte s, int tStates) { SubtractNumberOfTStatesLeft(tStates); - cp2sub = A - s; - cp2truncated = cp2sub & 0xff; + var cp2sub = A - s; + var cp2truncated = (byte)(cp2sub & 0xff); - fS = ((cp2truncated & F_S) != 0); - f3 = ((s & F_3) != 0); - f5 = ((s & F_5) != 0); + fS = (cp2truncated & F_S) != 0; + f3 = (s & F_3) != 0; + f5 = (s & F_5) != 0; fN = true; - fZ = (cp2truncated == 0); - fC = ((cp2sub & 0x100) != 0); - fH = ((((A & 0x0f) - (s & 0x0f)) & F_H) != 0); - fPV = (((A ^ s) & (A ^ cp2truncated) & 0x80) != 0); + fZ = cp2truncated == 0; + fC = (cp2sub & 0x100) != 0; + fH = (((A & 0x0f) - (s & 0x0f)) & F_H) != 0; + fPV = ((A ^ s) & (A ^ cp2truncated) & 0x80) != 0; } - int callw; public void CALL(bool argument) { if (argument) { - callw = GetNextPCWord(); + var callw = GetNextPCWord(); PCToStack(); PC = callw; SubtractNumberOfTStatesLeft(17); } else { - PC = ((PC + 2) & 0xffff); + PC = (ushort)((PC + 2) & 0xffff); SubtractNumberOfTStatesLeft(10); } } @@ -1181,75 +1011,72 @@ public void CALL(bool argument) /// public void CCF() { - f3 = ((A & F_3) != 0); - f5 = ((A & F_5) != 0); + f3 = (A & F_3) != 0; + f5 = (A & F_5) != 0; fN = false; fC = !fC; SubtractNumberOfTStatesLeft(4); } - bool cpdc, cpdpv; - int cpdn; public void CPD() { - cpdc = fC; + var cpdc = fC; CP(ReadByteFromMemory(HL), 0); HL = DEC16(HL, 0); BC = DEC16(BC, 0); - fPV = (BC != 0); + fPV = BC != 0; fC = cpdc; //--------------- - cpdn = A - ReadByteFromMemory(HL) - (fH ? 1 : 0); - cpdpv = (BC != 0); + var cpdn = (byte)(A - ReadByteFromMemory(HL) - (fH ? 1 : 0)); + var cpdpv = BC != 0; fN = true; fC = cpdc; - f5 = ((cpdn & 0x01) == 1); - f3 = ((cpdn >> 3 & 0x01) == 1); + f5 = (cpdn & 0x01) == 1; + f3 = (cpdn >> 3 & 0x01) == 1; //----------------------- SubtractNumberOfTStatesLeft(16); } - bool cpic; int cpimemvalue; int cpin; + public void CPI() { - cpic = fC; - cpimemvalue = ReadByteFromMemory(HL); + var cpic = fC; + var cpimemvalue = ReadByteFromMemory(HL); CP(cpimemvalue, 0); HL = INC16(HL, 0); BC = DEC16(BC, 0); - cpin = A - cpimemvalue - (fH ? 1 : 0); - f5 = ((cpin & 0x01) == 1); - f3 = ((cpin >> 3 & 0x01) == 1); - fPV = (BC != 0); + var cpin = A - cpimemvalue - (fH ? 1 : 0); + f5 = (cpin & 0x01) == 1; + f3 = (cpin >> 3 & 0x01) == 1; + fPV = BC != 0; fC = cpic; SubtractNumberOfTStatesLeft(16); } - bool cpirc; int cpirvalue; int cpirn; bool cpirpv; public void CPIR() { - cpirc = fC; - cpirvalue = ReadByteFromMemory(HL); + var cpirc = fC; + var cpirvalue = ReadByteFromMemory(HL); CP(cpirvalue, 0); HL = INC16(HL, 0); BC = DEC16(BC, 0); - cpirn = A - cpirvalue - (fH ? 1 : 0); - cpirpv = (BC != 0); + var cpirn = A - cpirvalue - (fH ? 1 : 0); + var cpirpv = BC != 0; fN = true; fPV = cpirpv; fC = cpirc; - f5 = ((cpirn & 0x01) == 1); - f3 = ((cpirn >> 3 & 0x01) == 1); + f5 = (cpirn & 0x01) == 1; + f3 = (cpirn >> 3 & 0x01) == 1; if (BC != 0 && A != cpirvalue) { //Repeat until BC ==0 - PC = ((PC - 2) & 0xffff); + PC = (ushort)((PC - 2) & 0xffff); SubtractNumberOfTStatesLeft(21); } else @@ -1258,24 +1085,23 @@ public void CPIR() } } - private int INC16(int value, int tStates) + private ushort INC16(ushort value, int tStates) { SubtractNumberOfTStatesLeft(tStates); - return (value + 1) & 0xffff; + return (ushort)((value + 1) & 0xffff); } - bool inc8pv, inc8h; - private int INC8(int value, int tStates) + private byte INC8(byte value, int tStates) { - inc8pv = (value == 0x7f); - inc8h = (((value & 0x0f) + 1) & F_H) != 0; - value = (value + 1) & 0xff; + var inc8pv = value == 0x7f; + var inc8h = (((value & 0x0f) + 1) & F_H) != 0; + value = (byte)((value + 1) & 0xff); - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); - fPV = (inc8pv); + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; + fPV = inc8pv; fH = inc8h; fN = false; @@ -1289,30 +1115,29 @@ private int INC8(int value, int tStates) /// Value to decrement with /// Number of tstates /// Decremented value - private int DEC16(int value, int tStates) + private ushort DEC16(ushort value, int tStates) { SubtractNumberOfTStatesLeft(tStates); - return (value - 1) & 0xffff; + return (ushort)((value - 1) & 0xffff); } - bool dec8pv, dev8h; /// /// Decrement for 8bit register /// /// Value to decrement /// Number of tstates /// Decremented value - private int DEC8(int value, int tStates) + private byte DEC8(byte value, int tStates) { SubtractNumberOfTStatesLeft(tStates); - dec8pv = (value == 0x80); - dev8h = (((value & 0x0f) - 1) & F_H) != 0; - value = (value - 1) & 0xff; - - fS = ((value & F_S) != 0); - f3 = ((value & F_3) != 0); - f5 = ((value & F_5) != 0); - fZ = ((value) == 0); + var dec8pv = value == 0x80; + var dev8h = (((value & 0x0f) - 1) & F_H) != 0; + value = (byte)((value - 1) & 0xff); + + fS = (value & F_S) != 0; + f3 = (value & F_3) != 0; + f5 = (value & F_5) != 0; + fZ = value == 0; fPV = dec8pv; fH = dev8h; fN = true; @@ -1320,41 +1145,35 @@ private int DEC8(int value, int tStates) return value; } - //private int INC16NoFlags(int a) - //{ - // return (a + 1) & 0xffff; - //} - - private int INC8NoFlags(int a) + private byte INC8NoFlags(byte a) { - return (a + 1) & 0xff; + return (byte)((a + 1) & 0xff); } - private int DEC8NoFlags(int a) + private byte DEC8NoFlags(byte a) { - return (a - 1) & 0xff; + return (byte)((a - 1) & 0xff); } - bool cpdrc, cpdrpv; /// /// Block compare with decrement /// public void CPDR() { - bool cpdrc = fC; + var cpdrc = fC; CP(ReadByteFromMemory(HL), 0); HL = DEC16(HL, 0); BC = DEC16(BC, 0); - cpdrpv = (BC != 0); + var cpdrpv = BC != 0; fPV = cpdrpv; fC = cpdrc; if (cpdrpv && !fZ) { //Repeat until BC==0 - PC = ((PC - 2) & 0xffff); + PC = (ushort)((PC - 2) & 0xffff); SubtractNumberOfTStatesLeft(21); } else @@ -1369,7 +1188,7 @@ public void CPDR() public void CPL() { SubtractNumberOfTStatesLeft(4); - int comp = A ^ 0xff; + var comp = (byte)(A ^ 0xff); f3 = (comp & F_3) != 0; f5 = (comp & F_5) != 0; @@ -1379,18 +1198,16 @@ public void CPL() A = comp; } - int daaa, daaincrement; - bool daac; /// /// Deciaml Adjust accumulator (4 tstates) /// public void DAA() { - daaa = A; - daaincrement = 0; - daac = fC; + var daaa = A; + byte daaincrement = 0; + var daac = fC; - if ((fH) || ((daaa & 0x0f) > 0x09)) + if (fH || ((daaa & 0x0f) > 0x09)) { daaincrement |= 0x06; } @@ -1408,7 +1225,7 @@ public void DAA() } else { - A = ADDADC8(A, daaincrement, false, 0); + A = (byte)ADDADC8(A, daaincrement, false, 0); } fC = daac; @@ -1416,20 +1233,19 @@ public void DAA() SubtractNumberOfTStatesLeft(4); } - int suba, subsubtracted, subtruncated; - public void SUB(int b, int tStates) + public void SUB(byte b, int tStates) { - suba = A; - subsubtracted = suba - b; - subtruncated = subsubtracted & 0xff; + var suba = A; + var subsubtracted = suba - b; + var subtruncated = (byte)(subsubtracted & 0xff); - fS = ((subtruncated & F_S) != 0); - f3 = ((subtruncated & F_3) != 0); - f5 = ((subtruncated & F_5) != 0); - fZ = ((subtruncated) == 0); - fC = ((subsubtracted & 0x100) != 0); - fPV = (((suba ^ b) & (suba ^ subtruncated) & 0x80) != 0); - fH = ((((suba & 0x0f) - (b & 0x0f)) & F_H) != 0); + fS = (subtruncated & F_S) != 0; + f3 = (subtruncated & F_3) != 0; + f5 = (subtruncated & F_5) != 0; + fZ = subtruncated == 0; + fC = (subsubtracted & 0x100) != 0; + fPV = ((suba ^ b) & (suba ^ subtruncated) & 0x80) != 0; + fH = (((suba & 0x0f) - (b & 0x0f)) & F_H) != 0; fN = true; A = subtruncated; @@ -1438,28 +1254,11 @@ public void SUB(int b, int tStates) public void DNJZ() { - ////No effects on flags - //int f = F; - - //B--; - //if (B != 0) - //{ - // int d = GetNextPCByte(); - // PC = (PC + d) & 0xffff; - // SubtractNumberOfTStatesLeft( 13; - //} - //else - //{ - // PC = INC16(PC, 0); - // SubtractNumberOfTStatesLeft( 8; - //} - //F = f; - - B = (B - 1) & 0xff; + B = (byte)((B - 1) & 0xff); if (B != 0) { SubtractNumberOfTStatesLeft(13); - PC += Sign(GetNextPCByte()); + PC = (ushort)(PC + Sign(GetNextPCByte())); PC++; } else @@ -1469,10 +1268,9 @@ public void DNJZ() } } - int exxtmp; public void EXX() { - exxtmp = BC; + var exxtmp = BC; BC = BCPrim; BCPrim = exxtmp; @@ -1487,5 +1285,4 @@ public void EXX() SubtractNumberOfTStatesLeft(4); } #endregion - } diff --git a/ZXBox.Core/Cpus/Z80/Z80CBPrefixInstructions.cs b/ZXBox.Core/Cpus/Z80/Z80CBPrefixInstructions.cs index b6a43f1..d255bd3 100644 --- a/ZXBox.Core/Cpus/Z80/Z80CBPrefixInstructions.cs +++ b/ZXBox.Core/Cpus/Z80/Z80CBPrefixInstructions.cs @@ -4,121 +4,120 @@ public partial class Z80 { public void DoCBPrefixInstruction() { - //TODO: Check i values are read from the right places Refresh(1); switch (opcode) { - case 0x36: //SLL (HL)* + case 0x36: //SLL (HL)* WriteByteToMemory(HL, SLL(ReadByteFromMemory(HL), 12)); break; - case 0x37: //SLL A* + case 0x37: //SLL A* A = SLL(A, 8); break; - case 0x30: //SLL B* + case 0x30: //SLL B* B = SLL(B, 8); break; - case 0x31: //SLL C* + case 0x31: //SLL C* C = SLL(C, 8); break; - case 0x32: //SLL D* + case 0x32: //SLL D* D = SLL(D, 8); break; - case 0x33: //SLL E* + case 0x33: //SLL E* E = SLL(E, 8); break; - case 0x34: //SLL H* + case 0x34: //SLL H* H = SLL(H, 8); break; - case 0x35: //SLL L* + case 0x35: //SLL L* L = SLL(L, 8); break; - case 0x46: //BIT 0,(HL) - case 0x4E: //BIT 1,(HL) - case 0x56: //BIT 2,(HL) - case 0x5E: //BIT 3,(HL) - case 0x66: //BIT 4,(HL) - case 0x6E: //BIT 5,(HL) - case 0x76: //BIT 6,(HL) - case 0x7E: //BIT 7,(HL) + case 0x46: //BIT 0,(HL) + case 0x4E: //BIT 1,(HL) + case 0x56: //BIT 2,(HL) + case 0x5E: //BIT 3,(HL) + case 0x66: //BIT 4,(HL) + case 0x6E: //BIT 5,(HL) + case 0x76: //BIT 6,(HL) + case 0x7E: //BIT 7,(HL) BIT(BitValueFromOP, ReadByteFromMemory(HL), 12); break; - case 0x47: //BIT 0,A - case 0x40: //BIT 0,B - case 0x41: //BIT 0,C - case 0x42: //BIT 0,D - case 0x43: //BIT 0,E - case 0x44: //BIT 0,H - case 0x45: //BIT 0,L - case 0x4F: //BIT 1,A - case 0x48: //BIT 1,B - case 0x49: //BIT 1,C - case 0x4A: //BIT 1,D - case 0x4B: //BIT 1,E - case 0x4C: //BIT 1,H - case 0x4D: //BIT 1,L - case 0x57: //BIT 2,A - case 0x50: //BIT 2,B - case 0x51: //BIT 2,C - case 0x52: //BIT 2,D - case 0x53: //BIT 2,E - case 0x54: //BIT 2,H - case 0x55: //BIT 2,L - case 0x5F: //BIT 3,A - case 0x58: //BIT 3,B - case 0x59: //BIT 3,C - case 0x5A: //BIT 3,D - case 0x5B: //BIT 3,E - case 0x5C: //BIT 3,H - case 0x5D: //BIT 3,L - case 0x67: //BIT 4,A - case 0x60: //BIT 4,B - case 0x61: //BIT 4,C - case 0x62: //BIT 4,D - case 0x63: //BIT 4,E - case 0x64: //BIT 4,H - case 0x65: //BIT 4,L - case 0x6F: //BIT 5,A - case 0x68: //BIT 5,B - case 0x69: //BIT 5,C - case 0x6A: //BIT 5,D - case 0x6B: //BIT 5,E - case 0x6C: //BIT 5,H - case 0x6D: //BIT 5,L - case 0x77: //BIT 6,A - case 0x70: //BIT 6,B - case 0x71: //BIT 6,C - case 0x72: //BIT 6,D - case 0x73: //BIT 6,E - case 0x74: //BIT 6,H - case 0x75: //BIT 6,L - case 0x7F: //BIT 7,A - case 0x78: //BIT 7,B - case 0x79: //BIT 7,C - case 0x7A: //BIT 7,D - case 0x7B: //BIT 7,E - case 0x7C: //BIT 7,H - case 0x7D: //BIT 7,L + case 0x47: //BIT 0,A + case 0x40: //BIT 0,B + case 0x41: //BIT 0,C + case 0x42: //BIT 0,D + case 0x43: //BIT 0,E + case 0x44: //BIT 0,H + case 0x45: //BIT 0,L + case 0x4F: //BIT 1,A + case 0x48: //BIT 1,B + case 0x49: //BIT 1,C + case 0x4A: //BIT 1,D + case 0x4B: //BIT 1,E + case 0x4C: //BIT 1,H + case 0x4D: //BIT 1,L + case 0x57: //BIT 2,A + case 0x50: //BIT 2,B + case 0x51: //BIT 2,C + case 0x52: //BIT 2,D + case 0x53: //BIT 2,E + case 0x54: //BIT 2,H + case 0x55: //BIT 2,L + case 0x5F: //BIT 3,A + case 0x58: //BIT 3,B + case 0x59: //BIT 3,C + case 0x5A: //BIT 3,D + case 0x5B: //BIT 3,E + case 0x5C: //BIT 3,H + case 0x5D: //BIT 3,L + case 0x67: //BIT 4,A + case 0x60: //BIT 4,B + case 0x61: //BIT 4,C + case 0x62: //BIT 4,D + case 0x63: //BIT 4,E + case 0x64: //BIT 4,H + case 0x65: //BIT 4,L + case 0x6F: //BIT 5,A + case 0x68: //BIT 5,B + case 0x69: //BIT 5,C + case 0x6A: //BIT 5,D + case 0x6B: //BIT 5,E + case 0x6C: //BIT 5,H + case 0x6D: //BIT 5,L + case 0x77: //BIT 6,A + case 0x70: //BIT 6,B + case 0x71: //BIT 6,C + case 0x72: //BIT 6,D + case 0x73: //BIT 6,E + case 0x74: //BIT 6,H + case 0x75: //BIT 6,L + case 0x7F: //BIT 7,A + case 0x78: //BIT 7,B + case 0x79: //BIT 7,C + case 0x7A: //BIT 7,D + case 0x7B: //BIT 7,E + case 0x7C: //BIT 7,H + case 0x7D: //BIT 7,L BIT(BitValueFromOP, RegisterValueFromOP(0), 8); break; - case 0x86: //RES 0,(HL) - case 0x8E: //RES 1,(HL) - case 0x96: //RES 2,(HL) - case 0x9E: //RES 3,(HL) - case 0xA6: //RES 4,(HL) - case 0xAE: //RES 5,(HL) - case 0xB6: //RES 6,(HL) - case 0xBE: //RES 7,(HL) + case 0x86: //RES 0,(HL) + case 0x8E: //RES 1,(HL) + case 0x96: //RES 2,(HL) + case 0x9E: //RES 3,(HL) + case 0xA6: //RES 4,(HL) + case 0xAE: //RES 5,(HL) + case 0xB6: //RES 6,(HL) + case 0xBE: //RES 7,(HL) WriteByteToMemory(HL, RES(BitValueFromOP, ReadByteFromMemory(HL), 15)); break; case 0x87: //RES 0,A - case 0x8F: //RES 1,A - case 0x97: //RES 2,A - case 0x9F: //RES 3,A - case 0xA7: //RES 4,A - case 0xAF: //RES 5,A - case 0xB7: //RES 6,A - case 0xBF: //RES 7,A + case 0x8F: //RES 1,A + case 0x97: //RES 2,A + case 0x9F: //RES 3,A + case 0xA7: //RES 4,A + case 0xAF: //RES 5,A + case 0xB7: //RES 6,A + case 0xBF: //RES 7,A A = RES(BitValueFromOP, A, 8); break; case 0x80: //RES 0,B @@ -181,234 +180,257 @@ public void DoCBPrefixInstruction() case 0xBD: //RES 7,L L = RES(BitValueFromOP, L, 8); break; - case 0x16: //RL (HL) + case 0x16: //RL (HL) WriteByteToMemory(HL, RL(ReadByteFromMemory(HL), 15)); break; - case 0x17: //RL A + case 0x17: //RL A A = RL(A, 8); break; - case 0x10: //RL B + case 0x10: //RL B B = RL(B, 8); break; - case 0x11: //RL C + case 0x11: //RL C C = RL(C, 8); break; - case 0x12: //RL D + case 0x12: //RL D D = RL(D, 8); break; - case 0x13: //RL E + case 0x13: //RL E E = RL(E, 8); break; - case 0x14: //RL H + case 0x14: //RL H H = RL(H, 8); break; - case 0x15: //RL L + case 0x15: //RL L L = RL(L, 8); break; - case 0x06: //RLC (HL) + case 0x06: //RLC (HL) WriteByteToMemory(HL, RLC(ReadByteFromMemory(HL), 15)); break; - case 0x07: //RLC A + case 0x07: //RLC A A = RLC(A, 8); break; - case 0x00: //RLC B + case 0x00: //RLC B B = RLC(B, 8); break; - case 0x01: //RLC C + case 0x01: //RLC C C = RLC(C, 8); break; - case 0x02: //RLC D + case 0x02: //RLC D D = RLC(D, 8); break; - case 0x03: //RLC E + case 0x03: //RLC E E = RLC(E, 8); break; - case 0x04: //RLC H + case 0x04: //RLC H H = RLC(H, 8); break; - case 0x05: //RLC L + case 0x05: //RLC L L = RLC(L, 8); break; - case 0x1E: //RR (HL) + case 0x1E: //RR (HL) WriteByteToMemory(HL, RR(ReadByteFromMemory(HL), 15)); break; - case 0x1F: //RR A + case 0x1F: //RR A A = RR(A, 8); break; - case 0x18: //RR B + case 0x18: //RR B B = RR(B, 8); break; - case 0x19: //RR C + case 0x19: //RR C C = RR(C, 8); break; - case 0x1A: //RR D + case 0x1A: //RR D D = RR(D, 8); break; - case 0x1B: //RR E + case 0x1B: //RR E E = RR(E, 8); break; - case 0x1C: //RR H + case 0x1C: //RR H H = RR(H, 8); break; - case 0x1D: //RR L + case 0x1D: //RR L L = RR(L, 8); break; - case 0x0E: //RRC (HL) + case 0x0E: //RRC (HL) WriteByteToMemory(HL, RRC(ReadByteFromMemory(HL), 15)); break; - case 0x0F: //RRC A + case 0x0F: //RRC A A = RRC(A, 8); break; - case 0x08: //RRC B + case 0x08: //RRC B B = RRC(B, 8); break; - case 0x09: //RRC C + case 0x09: //RRC C C = RRC(C, 8); break; - case 0x0A: //RRC D + case 0x0A: //RRC D D = RRC(D, 8); break; - case 0x0B: //RRC E + case 0x0B: //RRC E E = RRC(E, 8); break; - case 0x0C: //RRC H + case 0x0C: //RRC H H = RRC(H, 8); break; - case 0x0D: //RRC L + case 0x0D: //RRC L L = RRC(L, 8); break; - case 0xC6: // SET 0,(HL) - case 0xCE: //SET 1,(HL) - case 0xD6: //SET 2,(HL) - case 0xDE: //SET 3,(HL) - case 0xE6: //SET 4,(HL) - case 0xEE: //SET 5,(HL) - case 0xF6: //SET 6,(HL) - case 0xFE: //SET 7,(HL) + case 0xC6: //SET 0,(HL) + case 0xCE: //SET 1,(HL) + case 0xD6: //SET 2,(HL) + case 0xDE: //SET 3,(HL) + case 0xE6: //SET 4,(HL) + case 0xEE: //SET 5,(HL) + case 0xF6: //SET 6,(HL) + case 0xFE: //SET 7,(HL) WriteByteToMemory(HL, SET(BitValueFromOP, ReadByteFromMemory(HL), 15)); break; - case 0xC7: //SET 0,A - case 0xCF: //SET 1,A - case 0xD7: //SET 2,A - case 0xDF: //SET 3,A - case 0xE7: //SET 4,A - case 0xEF: //SET 5,A - case 0xF7: //SET 6,A - case 0xFF: //SET 7,A + case 0xC7: //SET 0,A + case 0xCF: //SET 1,A + case 0xD7: //SET 2,A + case 0xDF: //SET 3,A + case 0xE7: //SET 4,A + case 0xEF: //SET 5,A + case 0xF7: //SET 6,A + case 0xFF: //SET 7,A A = SET(BitValueFromOP, A, 8); break; - case 0xC0: //SET 0,B - case 0xC8: //SET 1,B - case 0xD0: //SET 2,B - case 0xD8: //SET 3,B - case 0xE0: //SET 4,B - case 0xE8: //SET 5,B - case 0xF0: //SET 6,B - case 0xF8: //SET 7,B + case 0xC0: //SET 0,B + case 0xC8: //SET 1,B + case 0xD0: //SET 2,B + case 0xD8: //SET 3,B + case 0xE0: //SET 4,B + case 0xE8: //SET 5,B + case 0xF0: //SET 6,B + case 0xF8: //SET 7,B B = SET(BitValueFromOP, B, 8); break; - case 0xC1: //SET 0,C - case 0xC9: //SET 1,C - case 0xD1: //SET 2,C - case 0xD9: //SET 3,C - case 0xE1: //SET 4,C - case 0xE9: //SET 5,C - case 0xF1: //SET 6,C - case 0xF9: //SET 7,C + case 0xC1: //SET 0,C + case 0xC9: //SET 1,C + case 0xD1: //SET 2,C + case 0xD9: //SET 3,C + case 0xE1: //SET 4,C + case 0xE9: //SET 5,C + case 0xF1: //SET 6,C + case 0xF9: //SET 7,C C = SET(BitValueFromOP, C, 8); break; - case 0xC2: //SET 0,D - case 0xCA: //SET 1,D - case 0xD2: //SET 2,D - case 0xDA: //SET 3,D' - case 0xE2: //SET 4,D - case 0xEA: //SET 5,D - case 0xF2: //SET 6,D - case 0xFA: //SET 7,D + case 0xC2: //SET 0,D + case 0xCA: //SET 1,D + case 0xD2: //SET 2,D + case 0xDA: //SET 3,D' + case 0xE2: //SET 4,D + case 0xEA: //SET 5,D + case 0xF2: //SET 6,D + case 0xFA: //SET 7,D D = SET(BitValueFromOP, D, 8); break; - case 0xC3: //SET 0,E - case 0xCB: //SET 1,E - case 0xD3: //SET 2,E - case 0xDB: //SET 3,E - case 0xE3: //SET 4,E - case 0xEB: //SET 5,E - case 0xF3: //SET 6,E - case 0xFB: //SET 7,E + case 0xC3: //SET 0,E + case 0xCB: //SET 1,E + case 0xD3: //SET 2,E + case 0xDB: //SET 3,E + case 0xE3: //SET 4,E + case 0xEB: //SET 5,E + case 0xF3: //SET 6,E + case 0xFB: //SET 7,E E = SET(BitValueFromOP, E, 8); break; - case 0xC4: //SET 0,H - case 0xCC: //SET 1,H - case 0xD4: //SET 2,H - case 0xDC: //SET 3,H - case 0xE4: //SET 4,H - case 0xEC: //SET 5,H - case 0xF4: //SET 6,H - case 0xFC: //SET 7,H + case 0xC4: //SET 0,H + case 0xCC: //SET 1,H + case 0xD4: //SET 2,H + case 0xDC: //SET 3,H + case 0xE4: //SET 4,H + case 0xEC: //SET 5,H + case 0xF4: //SET 6,H + case 0xFC: //SET 7,H H = SET(BitValueFromOP, H, 8); break; - case 0xC5: //SET 0,L - case 0xCD: //SET 1,L - case 0xD5: //SET 2,L - case 0xDD: //SET 3,L - case 0xE5: //SET 4,L - case 0xED: //SET 5,L - case 0xF5: //SET 6,L - case 0xFD: //SET 7,L + case 0xC5: //SET 0,L + case 0xCD: //SET 1,L + case 0xD5: //SET 2,L + case 0xDD: //SET 3,L + case 0xE5: //SET 4,L + case 0xED: //SET 5,L + case 0xF5: //SET 6,L + case 0xFD: //SET 7,L L = SET(BitValueFromOP, L, 8); break; - case 0x26: //SLA (HL) + case 0x26: //SLA (HL) WriteByteToMemory(HL, SLA(ReadByteFromMemory(HL), 15)); break; - case 0x27: //SLA A - A = SLA(A, 8); break; - case 0x20: //SLA B - B = SLA(B, 8); break; - case 0x21: //SLA C - C = SLA(C, 8); break; - case 0x22: //SLA D - D = SLA(D, 8); break; - case 0x23: //SLA E - E = SLA(E, 8); break; - case 0x24: //SLA H - H = SLA(H, 8); break; - case 0x25: //SLA L - L = SLA(L, 8); break; - case 0x2E: //SRA (HL) - WriteByteToMemory(HL, SRA(ReadByteFromMemory(HL), 15)); break; - case 0x2F: //SRA A - A = SRA(A, 8); break; - case 0x28: //SRA B - B = SRA(B, 8); break; - case 0x29: //SRA C - C = SRA(C, 8); break; - case 0x2A: //SRA D - D = SRA(D, 8); break; - case 0x2B: //SRA E - E = SRA(E, 8); break; - case 0x2C: //SRA H - H = SRA(H, 8); break; - case 0x2D: //SRA L - L = SRA(L, 8); break; - case 0x3E: //SRL (HL) - WriteByteToMemory(HL, SRL(ReadByteFromMemory(HL), 15)); break; - case 0x3F: //SRL A - A = SRL(A, 8); break; - case 0x38: //SRL B - B = SRL(B, 8); break; - case 0x39: //SRL C - C = SRL(C, 8); break; - case 0x3A: //SRL D - D = SRL(D, 8); break; - case 0x3B: //SRL E - E = SRL(E, 8); break; - case 0x3C: //SRL H - H = SRL(H, 8); break; - case 0x3D: //SRL L - L = SRL(L, 8); break; + case 0x27: //SLA A + A = SLA(A, 8); + break; + case 0x20: //SLA B + B = SLA(B, 8); + break; + case 0x21: //SLA C + C = SLA(C, 8); + break; + case 0x22: //SLA D + D = SLA(D, 8); + break; + case 0x23: //SLA E + E = SLA(E, 8); + break; + case 0x24: //SLA H + H = SLA(H, 8); + break; + case 0x25: //SLA L + L = SLA(L, 8); + break; + case 0x2E: //SRA (HL) + WriteByteToMemory(HL, SRA(ReadByteFromMemory(HL), 15)); + break; + case 0x2F: //SRA A + A = SRA(A, 8); + break; + case 0x28: //SRA B + B = SRA(B, 8); + break; + case 0x29: //SRA C + C = SRA(C, 8); + break; + case 0x2A: //SRA D + D = SRA(D, 8); + break; + case 0x2B: //SRA E + E = SRA(E, 8); + break; + case 0x2C: //SRA H + H = SRA(H, 8); + break; + case 0x2D: //SRA L + L = SRA(L, 8); + break; + case 0x3E: //SRL (HL) + WriteByteToMemory(HL, SRL(ReadByteFromMemory(HL), 15)); + break; + case 0x3F: //SRL A + A = SRL(A, 8); + break; + case 0x38: //SRL B + B = SRL(B, 8); + break; + case 0x39: //SRL C + C = SRL(C, 8); + break; + case 0x3A: //SRL D + D = SRL(D, 8); + break; + case 0x3B: //SRL E + E = SRL(E, 8); + break; + case 0x3C: //SRL H + H = SRL(H, 8); + break; + case 0x3D: //SRL L + L = SRL(L, 8); + break; default: //Console.WriteLine("CB" + opcode.ToString()); break; diff --git a/ZXBox.Core/Cpus/Z80/Z80DDandFDPrefixInstructions.cs b/ZXBox.Core/Cpus/Z80/Z80DDandFDPrefixInstructions.cs index b5b3bfa..6521fb3 100644 --- a/ZXBox.Core/Cpus/Z80/Z80DDandFDPrefixInstructions.cs +++ b/ZXBox.Core/Cpus/Z80/Z80DDandFDPrefixInstructions.cs @@ -11,11 +11,11 @@ public enum IndexRegistryEnum IX = 0, IY = 1 } - int ixd; + ushort ixd; int index; - int dvalue; - int tmp; - int tmpValue = 0; + sbyte dvalue; + ushort tmp; + byte tmpValue = 0; public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) { ixd = 0; @@ -24,43 +24,43 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) Refresh(1); switch (opcode) { - case 0x84: //ADD A,IXH* + case 0x84: //ADD A,IXH* if (IRindex == IndexRegistryEnum.IX) A = ADDADC8(A, IXH, false, 4); else A = ADDADC8(A, IYH, false, 4); break; - case 0x8C: //ADC A,IXH* + case 0x8C: //ADC A,IXH* if (IRindex == IndexRegistryEnum.IX) A = ADDADC8(A, IXH, true, 4); else A = ADDADC8(A, IYH, true, 4); break; - case 0x8D: //ADC A,IXL* + case 0x8D: //ADC A,IXL* if (IRindex == IndexRegistryEnum.IX) A = ADDADC8(A, IXL, true, 4); else A = ADDADC8(A, IYL, true, 4); break; - case 0x85: //ADD A,IXL* + case 0x85: //ADD A,IXL* if (IRindex == IndexRegistryEnum.IX) A = ADDADC8(A, IXL, false, 4); else A = ADDADC8(A, IYL, false, 4); break; - case 0xA4: //AND IXYH* + case 0xA4: //AND IXYH* if (IRindex == IndexRegistryEnum.IX) A = AND8(A, IXH, 4); else A = AND8(A, IYH, 4); break; - case 0xA5: //AND IXYL* + case 0xA5: //AND IXYL* if (IRindex == IndexRegistryEnum.IX) A = AND8(A, IXL, 4); else A = AND8(A, IYL, 4); break; - case 0x2A: //LD IX,(nn) + case 0x2A: //LD IX,(nn) IndexRegistry[index] = ReadWordFromMemory(GetNextPCWord()); SubtractNumberOfTStatesLeft(20); break; @@ -68,141 +68,141 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) WriteWordToMemory(GetNextPCWord(), IndexRegistry[index]); SubtractNumberOfTStatesLeft(14); break; - case 0x21: //LD IX,nn + case 0x21: //LD IX,nn IndexRegistry[index] = GetNextPCWord(); SubtractNumberOfTStatesLeft(14); break; - case 0x36: //LD (IX+d),n - WriteByteToMemory(IndexRegistry[index] + d, GetNextPCByte()); + case 0x36: //LD (IX+d),n + WriteByteToMemory((ushort)(IndexRegistry[index] + d), GetNextPCByte()); SubtractNumberOfTStatesLeft(19); break; - case 0x8E: //ADC A,(IX+d) With PrefixDD - A = ADDADC8(A, ReadByteFromMemory(IndexRegistry[index] + d), true, 19); + case 0x8E: //ADC A,(IX+d) With PrefixDD + A = ADDADC8(A, ReadByteFromMemory((ushort)(IndexRegistry[index] + d)), true, 19); break; - //case 0xCE: //ADC A,n - // A = ADDADC8(A, Memory[PC++], true, 7); - // break; - case 0x86: //ADD A,(IX+d) - A = ADDADC8(A, ReadByteFromMemory(IndexRegistry[index] + d), false, 19); + // case 0xCE: //ADC A,n + // A = ADDADC8(A, Memory[PC++], true, 7); + // break; + case 0x86: //ADD A,(IX+d) + A = ADDADC8(A, ReadByteFromMemory((ushort)(IndexRegistry[index] + d)), false, 19); break; - case 0x09://ADD IX,BC + case 0x09: //ADD IX,BC IndexRegistry[index] = ADDADC16(IndexRegistry[index], BC, false, 15); break; - case 0x19://ADD IX,DE + case 0x19: //ADD IX,DE IndexRegistry[index] = ADDADC16(IndexRegistry[index], DE, false, 15); break; - case 0x29://ADD IX,IX + case 0x29: //ADD IX,IX IndexRegistry[index] = ADDADC16(IndexRegistry[index], IndexRegistry[index], false, 15); break; - case 0x39://ADD IX,SP + case 0x39: //ADD IX,SP IndexRegistry[index] = ADDADC16(IndexRegistry[index], SP, false, 15); break; - case 0xA6://AND (IX+d) - A = AND8(A, ReadByteFromMemory(IndexRegistry[index] + d), 19); + case 0xA6: //AND (IX+d) + A = AND8(A, ReadByteFromMemory((ushort)(IndexRegistry[index] + d)), 19); break; - case 0xBE://CP (IX+d) - CP(ReadByteFromMemory(IndexRegistry[index] + d), 19); + case 0xBE: //CP (IX+d) + CP(ReadByteFromMemory((ushort)(IndexRegistry[index] + d)), 19); break; - case 0xBC://CP IXH* + case 0xBC: //CP IXH* if (IRindex == IndexRegistryEnum.IX) CP(IXH, 7); else CP(IYH, 7); break; - case 0xBD://CP IXH* + case 0xBD: //CP IXH* if (IRindex == IndexRegistryEnum.IX) CP(IXL, 7); else CP(IYL, 7); break; - case 0x35: //DEC (IX+d) - ixd = IndexRegistry[index] + d; + case 0x35: //DEC (IX+d) + ixd = (ushort)(IndexRegistry[index] + d); WriteByteToMemory(ixd, DEC8(ReadByteFromMemory(ixd), 23)); break; - case 0x25: //DEC IXH* + case 0x25: //DEC IXH* if (IRindex == IndexRegistryEnum.IX) IXH = DEC8(IXH, 4); //TODO: Verify tstates else IYH = DEC8(IYH, 4); //TODO: Verify tstates break; - case 0x2B://DEC IX + case 0x2B: //DEC IX IndexRegistry[index] = DEC16(IndexRegistry[index], 10); break; - case 0x2D://DEC IXL + case 0x2D: //DEC IXL if (IRindex == IndexRegistryEnum.IX) IXL = DEC8(IXL, 6); //TODO: Verify tstates else IYL = DEC8(IYL, 6); //TODO: Verify tstates break; - case 0xE3: //EX (SP),IX + case 0xE3: //EX (SP),IX tmp = ReadWordFromMemory(SP); WriteWordToMemory(SP, IndexRegistry[index]); IndexRegistry[index] = tmp; SubtractNumberOfTStatesLeft(23); break; - case 0x34://INC (IX+d) + case 0x34: //INC (IX+d) dvalue = d; - WriteByteToMemory(IndexRegistry[index] + dvalue, INC8(ReadByteFromMemory(IndexRegistry[index] + dvalue), 0)); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), INC8(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 0)); SubtractNumberOfTStatesLeft(23); break; - case 0x24: //INC IXH* + case 0x24: //INC IXH* if (IRindex == IndexRegistryEnum.IX) IXH = INC8(IXH, 4); else IYH = INC8(IYH, 4); break; - case 0x23: //INC IX + case 0x23: //INC IX IndexRegistry[index] = INC16(IndexRegistry[index], 10); break; - case 0x2C://INC IXL* + case 0x2C: //INC IXL* if (IRindex == IndexRegistryEnum.IX) IXL = INC8(IXL, 4); else IYL = INC8(IYL, 4); break; - case 0xE9://JP (IX) + case 0xE9: //JP (IX) JP(true, IndexRegistry[index], 8); break; - case 0x77: //LD (IYX + d),A - case 0x70: //LD (IYX + d),B - case 0x71: //LD (IYX + d),C - case 0x72: //LD (IYX + d),D - case 0x73: //LD (IYX + d),E - case 0x74: //LD (IYX + d),H - case 0x75: //LD (IYX + d),L - WriteByteToMemory(IndexRegistry[index] + d, RegisterValueFromOP(0)); + case 0x77: //LD (IYX + d),A + case 0x70: //LD (IYX + d),B + case 0x71: //LD (IYX + d),C + case 0x72: //LD (IYX + d),D + case 0x73: //LD (IYX + d),E + case 0x74: //LD (IYX + d),H + case 0x75: //LD (IYX + d),L + WriteByteToMemory((ushort)(IndexRegistry[index] + d), RegisterValueFromOP(0)); SubtractNumberOfTStatesLeft(19); break; - case 0x7E://LD A,(IX+d) - A = ReadByteFromMemory(IndexRegistry[index] + d); + case 0x7E: //LD A,(IX+d) + A = ReadByteFromMemory((ushort)(IndexRegistry[index] + d)); SubtractNumberOfTStatesLeft(19); break; - case 0x7C: //LD A,IXH* + case 0x7C: //LD A,IXH* if (IRindex == IndexRegistryEnum.IX) A = IXH; else A = IYH; SubtractNumberOfTStatesLeft(4); break; - case 0x7D://LD A,IXL* + case 0x7D: //LD A,IXL* if (IRindex == IndexRegistryEnum.IX) A = IXL; else A = IYL; SubtractNumberOfTStatesLeft(4); break; - case 0x46: //LD B,(IX+d) - B = ReadByteFromMemory(IndexRegistry[index] + d); + case 0x46: //LD B,(IX+d) + B = ReadByteFromMemory((ushort)(IndexRegistry[index] + d)); SubtractNumberOfTStatesLeft(19); break; - case 0x44: //LD B,IXH* + case 0x44: //LD B,IXH* if (IRindex == IndexRegistryEnum.IX) B = IXH; else B = IYH; SubtractNumberOfTStatesLeft(4); break; - case 0x45://LD B,IXL* + case 0x45: //LD B,IXL* if (IRindex == IndexRegistryEnum.IX) B = IXL; else @@ -210,18 +210,18 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) SubtractNumberOfTStatesLeft(4); break; //C register - case 0x4E: //LD C,(IX+d) - C = ReadByteFromMemory(IndexRegistry[index] + d); + case 0x4E: //LD C,(IX+d) + C = ReadByteFromMemory((ushort)(IndexRegistry[index] + d)); SubtractNumberOfTStatesLeft(19); break; - case 0x4C: //LD C,IXH* + case 0x4C: //LD C,IXH* if (IRindex == IndexRegistryEnum.IX) C = IXH; else C = IYH; SubtractNumberOfTStatesLeft(4); break; - case 0x4D://LD B,IXL* + case 0x4D: //LD B,IXL* if (IRindex == IndexRegistryEnum.IX) C = IXL; else @@ -229,18 +229,18 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) SubtractNumberOfTStatesLeft(4); break; //D Register - case 0x56: //LD D,(IX+d) - D = ReadByteFromMemory(IndexRegistry[index] + d); + case 0x56: //LD D,(IX+d) + D = ReadByteFromMemory((ushort)(IndexRegistry[index] + d)); SubtractNumberOfTStatesLeft(19); break; - case 0x54: //LD D,IXH* + case 0x54: //LD D,IXH* if (IRindex == IndexRegistryEnum.IX) D = IXH; else D = IYH; SubtractNumberOfTStatesLeft(4); break; - case 0x55://LD D,IXL* + case 0x55: //LD D,IXL* if (IRindex == IndexRegistryEnum.IX) D = IXL; else @@ -248,18 +248,18 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) SubtractNumberOfTStatesLeft(4); break; //E Register - case 0x5E: //LD E,(IX+d) - E = ReadByteFromMemory(IndexRegistry[index] + d); + case 0x5E: //LD E,(IX+d) + E = ReadByteFromMemory((ushort)(IndexRegistry[index] + d)); SubtractNumberOfTStatesLeft(19); break; - case 0x5C: //LD D,IXH* + case 0x5C: //LD D,IXH* if (IRindex == IndexRegistryEnum.IX) E = IXH; else E = IYH; SubtractNumberOfTStatesLeft(4); break; - case 0x5D://LD E,IXL* + case 0x5D: //LD E,IXL* if (IRindex == IndexRegistryEnum.IX) E = IXL; else @@ -267,56 +267,56 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) SubtractNumberOfTStatesLeft(4); break; //H Register - case 0x66: //LD H,(IX+d) - H = ReadByteFromMemory(IndexRegistry[index] + d); + case 0x66: //LD H,(IX+d) + H = ReadByteFromMemory((ushort)(IndexRegistry[index] + d)); SubtractNumberOfTStatesLeft(19); break; - case 0x67://LD IXH,A* + case 0x67: //LD IXH,A* if (IRindex == IndexRegistryEnum.IX) IXH = A; else IYH = A; SubtractNumberOfTStatesLeft(4); break; - case 0x60: //LD IXH,B* + case 0x60: //LD IXH,B* if (IRindex == IndexRegistryEnum.IX) IXH = B; else IYH = B; SubtractNumberOfTStatesLeft(4); break; - case 0x61: //LD IXH,C* + case 0x61: //LD IXH,C* if (IRindex == IndexRegistryEnum.IX) IXH = C; else IYH = C; SubtractNumberOfTStatesLeft(4); break; - case 0x62: //LD IXH,D* + case 0x62: //LD IXH,D* if (IRindex == IndexRegistryEnum.IX) IXH = D; else IYH = D; SubtractNumberOfTStatesLeft(4); break; - case 0x63: //LD IXH,E* + case 0x63: //LD IXH,E* if (IRindex == IndexRegistryEnum.IX) IXH = E; else IYH = E; SubtractNumberOfTStatesLeft(4); break; - case 0x64: //LD IXYH,IYXH* + case 0x64: //LD IXYH,IYXH* SubtractNumberOfTStatesLeft(4); break; - case 0x65://LD IXH,IXL* + case 0x65: //LD IXH,IXL* if (IRindex == IndexRegistryEnum.IX) IXH = IXL; else IYH = IYL; SubtractNumberOfTStatesLeft(4); break; - case 0x26://LD IXH,n* + case 0x26: //LD IXH,n* if (IRindex == IndexRegistryEnum.IX) IXH = GetNextPCByte(); else @@ -324,76 +324,76 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) SubtractNumberOfTStatesLeft(4); break; //L Register - case 0x6E: //LD L,(IX+d) - L = ReadByteFromMemory(IndexRegistry[index] + d); + case 0x6E: //LD L,(IX+d) + L = ReadByteFromMemory((ushort)(IndexRegistry[index] + d)); SubtractNumberOfTStatesLeft(19); break; - case 0x6F://LD IXL,A* + case 0x6F: //LD IXL,A* if (IRindex == IndexRegistryEnum.IX) IXL = A; else IYL = A; SubtractNumberOfTStatesLeft(4); break; - case 0x68: //LD IXL,B* + case 0x68: //LD IXL,B* if (IRindex == IndexRegistryEnum.IX) IXL = B; else IYL = B; SubtractNumberOfTStatesLeft(4); break; - case 0x69: //LD IXL,C* + case 0x69: //LD IXL,C* if (IRindex == IndexRegistryEnum.IX) IXL = C; else IYL = C; SubtractNumberOfTStatesLeft(4); break; - case 0x6A: //LD IXL,D* + case 0x6A: //LD IXL,D* if (IRindex == IndexRegistryEnum.IX) IXL = D; else IYL = D; SubtractNumberOfTStatesLeft(4); break; - case 0x6B: //LD IXL,E* + case 0x6B: //LD IXL,E* if (IRindex == IndexRegistryEnum.IX) IXL = E; else IYL = E; SubtractNumberOfTStatesLeft(4); break; - case 0x6C: //LD IXL,IXH* + case 0x6C: //LD IXL,IXH* if (IRindex == IndexRegistryEnum.IX) IXL = IXH; else IYL = IYH; SubtractNumberOfTStatesLeft(4); break; - case 0x6D://LD IXL,IXL* + case 0x6D: //LD IXL,IXL* SubtractNumberOfTStatesLeft(4); break; - case 0x2E://LD IXL,n* + case 0x2E: //LD IXL,n* if (IRindex == IndexRegistryEnum.IX) IXL = GetNextPCByte(); else IYL = GetNextPCByte(); SubtractNumberOfTStatesLeft(4); break; - case 0xF9://LD SP,IX + case 0xF9: //LD SP,IX SP = IndexRegistry[index]; SubtractNumberOfTStatesLeft(10); break; - case 0xB6://OR (IX+d) - OR(ReadByteFromMemory(IndexRegistry[index] + d), 7); + case 0xB6: //OR (IX+d) + OR(ReadByteFromMemory((ushort)(IndexRegistry[index] + d)), 7); break; - case 0xB4: //OR IXH* + case 0xB4: //OR IXH* if (IRindex == IndexRegistryEnum.IX) OR(IXH, 7); else OR(IYH, 7); break; - case 0xB5://OR IXL* + case 0xB5: //OR IXL* if (IRindex == IndexRegistryEnum.IX) OR(IXL, 7); else @@ -405,408 +405,408 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) NextOpcode(); switch (opcode) { - case 0x00: //LD B,RLC (IX+d)* - tmpValue = RLC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x00: //LD B,RLC (IX+d)* + tmpValue = RLC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; - case 0x01: //LD C,RLC (IX+d)* - tmpValue = RLC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x01: //LD C,RLC (IX+d)* + tmpValue = RLC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; - case 0x02: //LD D,RLC (IX+d)* - tmpValue = RLC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x02: //LD D,RLC (IX+d)* + tmpValue = RLC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; - case 0x03: //LD E,RLC (IX+d)* - tmpValue = RLC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x03: //LD E,RLC (IX+d)* + tmpValue = RLC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; - case 0x04: //LD H,RLC (IX+d)* - tmpValue = RLC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x04: //LD H,RLC (IX+d)* + tmpValue = RLC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; - case 0x05: //LD L,RLC (IX+d)* - tmpValue = RLC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x05: //LD L,RLC (IX+d)* + tmpValue = RLC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; - case 0x06: //RLC (IX+d) - tmpValue = RLC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x06: //RLC (IX+d) + tmpValue = RLC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; - case 0x22: //LD D,SLA (IX+d)* - tmpValue = SLA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x22: //LD D,SLA (IX+d)* + tmpValue = SLA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; - case 0x07: //LD A,RLC (IX+d)* - tmpValue = RLC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x07: //LD A,RLC (IX+d)* + tmpValue = RLC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; - case 0x08: //LD B,RRC (IX+d)* - tmpValue = RRC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x08: //LD B,RRC (IX+d)* + tmpValue = RRC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; - case 0x09: //LD C,RRC (IX+d)* - tmpValue = RRC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x09: //LD C,RRC (IX+d)* + tmpValue = RRC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; - case 0x0A: //LD D,RRC (IX+d)* - tmpValue = RRC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x0A: //LD D,RRC (IX+d)* + tmpValue = RRC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; - case 0x0B: //LD E,RRC (IX+d)* - tmpValue = RRC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x0B: //LD E,RRC (IX+d)* + tmpValue = RRC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; - case 0x0C: //LD H,RRC (IX+d)* - tmpValue = RRC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x0C: //LD H,RRC (IX+d)* + tmpValue = RRC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; - case 0x0D: //LD L,RRC (IX+d)* - tmpValue = RRC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x0D: //LD L,RRC (IX+d)* + tmpValue = RRC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; - case 0x0E: //RRC (IX+d) - tmpValue = RRC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x0E: //RRC (IX+d) + tmpValue = RRC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; - case 0x0F: //LD A,RRC (IX+d)* - tmpValue = RRC(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x0F: //LD A,RRC (IX+d)* + tmpValue = RRC(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; - case 0x10: //LD B,RL (IX+d)* - tmpValue = RL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x10: //LD B,RL (IX+d)* + tmpValue = RL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; - case 0x11: //LD C,RL (IX+d)* - tmpValue = RL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x11: //LD C,RL (IX+d)* + tmpValue = RL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; - case 0x12: //LD D,RL (IX+d)* - tmpValue = RL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x12: //LD D,RL (IX+d)* + tmpValue = RL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; - case 0x13: //LD E,RL (IX+d)* - tmpValue = RL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x13: //LD E,RL (IX+d)* + tmpValue = RL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; - case 0x14: //LD H,RL (IX+d)* - tmpValue = RL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x14: //LD H,RL (IX+d)* + tmpValue = RL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; - case 0x15: //LD L,RL (IX+d)* - tmpValue = RL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x15: //LD L,RL (IX+d)* + tmpValue = RL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; - case 0x16: //RL (IX+d) - tmpValue = RL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x16: //RL (IX+d) + tmpValue = RL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; - case 0x17: //LD A,RL (IX+d)* - tmpValue = RL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x17: //LD A,RL (IX+d)* + tmpValue = RL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; - case 0x18: //LD B,RR (IX+d)* - tmpValue = RR(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x18: //LD B,RR (IX+d)* + tmpValue = RR(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; - case 0x19: //LD C,RR (IX+d)* - tmpValue = RR(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x19: //LD C,RR (IX+d)* + tmpValue = RR(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; - case 0x1A: //LD D,RR (IX+d)* - tmpValue = RR(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x1A: //LD D,RR (IX+d)* + tmpValue = RR(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; - case 0x1B: //LD E,RR (IX+d)* - tmpValue = RR(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x1B: //LD E,RR (IX+d)* + tmpValue = RR(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; - case 0x1C: //LD H,RR (IX+d)* - tmpValue = RR(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x1C: //LD H,RR (IX+d)* + tmpValue = RR(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; - case 0x1D: //LD L,RR (IX+d)* - tmpValue = RR(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x1D: //LD L,RR (IX+d)* + tmpValue = RR(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; - case 0x1E: //RR (IX+d) - tmpValue = RR(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x1E: //RR (IX+d) + tmpValue = RR(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; - case 0x1F: //LD A,RR (IX+d)* - tmpValue = RR(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x1F: //LD A,RR (IX+d)* + tmpValue = RR(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; - case 0x20: //LD B,SLA (IX+d)* - tmpValue = SLA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x20: //LD B,SLA (IX+d)* + tmpValue = SLA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; - case 0x21: //LD C,SLA (IX+d)* - tmpValue = SLA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x21: //LD C,SLA (IX+d)* + tmpValue = SLA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; - case 0x23: //LD E,SLA (IX+d)* - tmpValue = SLA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x23: //LD E,SLA (IX+d)* + tmpValue = SLA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; - case 0x24: //LD H,SLA (IX+d)* - tmpValue = SLA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x24: //LD H,SLA (IX+d)* + tmpValue = SLA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; - case 0x25: //LD L,SLA (IX+d)* - tmpValue = SLA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x25: //LD L,SLA (IX+d)* + tmpValue = SLA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; - case 0x26: //SLA (IX+d) - tmpValue = SLA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x26: //SLA (IX+d) + tmpValue = SLA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; - case 0x27: //LD A,SLA (IX+d)* - tmpValue = SLA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x27: //LD A,SLA (IX+d)* + tmpValue = SLA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; - case 0x28: //LD B,SRA (IX+d)* - tmpValue = SRA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x28: //LD B,SRA (IX+d)* + tmpValue = SRA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; - case 0x29: //LD C,SRA (IX+d)* - tmpValue = SRA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x29: //LD C,SRA (IX+d)* + tmpValue = SRA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; - case 0x2A: //LD D,SRA (IX+d)* - tmpValue = SRA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x2A: //LD D,SRA (IX+d)* + tmpValue = SRA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; - case 0x2B: //LD E,SRA (IX+d)* - tmpValue = SRA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x2B: //LD E,SRA (IX+d)* + tmpValue = SRA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; - case 0x2C: //LD H,SRA (IX+d)* - tmpValue = SRA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x2C: //LD H,SRA (IX+d)* + tmpValue = SRA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; - case 0x2D: //LD L,SRA (IX+d)* - tmpValue = SRA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x2D: //LD L,SRA (IX+d)* + tmpValue = SRA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; - case 0x2E: //SRA (IX+d) - tmpValue = SRA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x2E: //SRA (IX+d) + tmpValue = SRA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; - case 0x2F: //LD A,SRA (IX+d)* - tmpValue = SRA(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x2F: //LD A,SRA (IX+d)* + tmpValue = SRA(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; - case 0x30: //LD B,SLL (IX+d)* - tmpValue = SLL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x30: //LD B,SLL (IX+d)* + tmpValue = SLL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; - case 0x31: //LD C,SLL (IX+d)* - tmpValue = SLL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x31: //LD C,SLL (IX+d)* + tmpValue = SLL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; - case 0x32: //LD D,SLL (IX+d)* - tmpValue = SLL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x32: //LD D,SLL (IX+d)* + tmpValue = SLL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; - case 0x33: //LD E,SLL (IX+d)* - tmpValue = SLL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x33: //LD E,SLL (IX+d)* + tmpValue = SLL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; - case 0x34: //LD H,SLL (IX+d)* - tmpValue = SLL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x34: //LD H,SLL (IX+d)* + tmpValue = SLL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; - case 0x35: //LD L,SLL (IX+d)* - tmpValue = SLL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x35: //LD L,SLL (IX+d)* + tmpValue = SLL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; - case 0x36: //SLL (IX+d)* - tmpValue = SLL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x36: //SLL (IX+d)* + tmpValue = SLL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; - case 0x37: //LD A,SLL (IX+d)* - tmpValue = SLL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x37: //LD A,SLL (IX+d)* + tmpValue = SLL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; - case 0x38: //LD B,SRL (IX+d)* - tmpValue = SRL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x38: //LD B,SRL (IX+d)* + tmpValue = SRL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; - case 0x39: //LD C,SRL (IX+d)* - tmpValue = SRL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x39: //LD C,SRL (IX+d)* + tmpValue = SRL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; - case 0x3A: //LD D,SRL (IX+d)* - tmpValue = SRL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x3A: //LD D,SRL (IX+d)* + tmpValue = SRL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; - case 0x3B: //LD E,SRL (IX+d)* - tmpValue = SRL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x3B: //LD E,SRL (IX+d)* + tmpValue = SRL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; - case 0x3C: //LD H,SRL (IX+d)* - tmpValue = SRL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x3C: //LD H,SRL (IX+d)* + tmpValue = SRL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; - case 0x3D: //LD L,SRL (IX+d)* - tmpValue = SRL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x3D: //LD L,SRL (IX+d)* + tmpValue = SRL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; - case 0x3E: //SRL (IX+d) - tmpValue = SRL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x3E: //SRL (IX+d) + tmpValue = SRL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; - case 0x3F: //LD A,SRL (IX+d)* - tmpValue = SRL(ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x3F: //LD A,SRL (IX+d)* + tmpValue = SRL(ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; - case 0x40: //BIT 0,(IX+d)* - case 0x41: //BIT 0,(IX+d)* - case 0x42: //BIT 0,(IX+d)* - case 0x43: //BIT 0,(IX+d)* - case 0x44: //BIT 0,(IX+d)* - case 0x45: //BIT 0,(IX+d)* - case 0x46: //BIT 0,(IX+d) - case 0x47: //BIT 0,(IX+d)* - BITixyd(0, ReadByteFromMemory(IndexRegistry[index] + dvalue), IndexRegistry[index] + dvalue, 20); - break; - case 0x48: //BIT 1,(IX+d)* - case 0x49: //BIT 1,(IX+d)* - case 0x4A: //BIT 1,(IX+d)* - case 0x4B: //BIT 1,(IX+d)* - case 0x4C: //BIT 1,(IX+d)* - case 0x4D: //BIT 1,(IX+d)* - case 0x4E: //BIT 1,(IX+d) - case 0x4F: //BIT 1,(IX+d)* - BITixyd(1, ReadByteFromMemory(IndexRegistry[index] + dvalue), IndexRegistry[index] + dvalue, 20); - break; - case 0x50: //BIT 2,(IX+d)* - case 0x51: //BIT 2,(IX+d)* - case 0x52: //BIT 2,(IX+d)* - case 0x53: //BIT 2,(IX+d)* - case 0x54: //BIT 2,(IX+d)* - case 0x55: //BIT 2,(IX+d)* - case 0x56: //BIT 2,(IX+d) - case 0x57: //BIT 2,(IX+d)* - BITixyd(2, ReadByteFromMemory(IndexRegistry[index] + dvalue), IndexRegistry[index] + dvalue, 20); - break; - case 0x58: //BIT 3,(IX+d)* - case 0x59: //BIT 3,(IX+d)* - case 0x5A: //BIT 3,(IX+d)* - case 0x5B: //BIT 3,(IX+d)* - case 0x5C: //BIT 3,(IX+d)* - case 0x5D: //BIT 3,(IX+d)* - case 0x5E: //BIT 3,(IX+d) - BITixyd(3, ReadByteFromMemory(IndexRegistry[index] + dvalue), IndexRegistry[index] + dvalue, 20); - break; - case 0x5F: //BIT 3,(IX+d)* - case 0x60: //BIT 4,(IX+d)* - case 0x61: //BIT 4,(IX+d)* - case 0x62: //BIT 4,(IX+d)* - case 0x63: //BIT 4,(IX+d)* - case 0x64: //BIT 4,(IX+d)* - case 0x65: //BIT 4,(IX+d)* - case 0x66: //BIT 4,(IX+d) - case 0x67: //BIT 4,(IX+d)* - BITixyd(4, ReadByteFromMemory(IndexRegistry[index] + dvalue), IndexRegistry[index] + dvalue, 20); - break; - case 0x68: //BIT 5,(IX+d)* - case 0x69: //BIT 5,(IX+d)* - case 0x6A: //BIT 5,(IX+d)* - case 0x6B: //BIT 5,(IX+d)* - case 0x6C: //BIT 5,(IX+d)* - case 0x6D: //BIT 5,(IX+d)* - case 0x6E: //BIT 5,(IX+d) - case 0x6F: //BIT 5,(IX+d)* - BITixyd(5, ReadByteFromMemory(IndexRegistry[index] + dvalue), IndexRegistry[index] + dvalue, 20); - break; - case 0x70: //BIT 6,(IX+d)* - case 0x71: //BIT 6,(IX+d)* - case 0x72: //BIT 6,(IX+d)* - case 0x73: //BIT 6,(IX+d)* - case 0x74: //BIT 6,(IX+d)* - case 0x75: //BIT 6,(IX+d)* - case 0x76: //BIT 6,(IX+d) - case 0x77: //BIT 6,(IX+d)* - BITixyd(6, ReadByteFromMemory(IndexRegistry[index] + dvalue), IndexRegistry[index] + dvalue, 20); - break; - case 0x78: //BIT 7,(IX+d)* - case 0x79: //BIT 7,(IX+d)* - case 0x7A: //BIT 7,(IX+d)* - case 0x7B: //BIT 7,(IX+d)* - case 0x7C: //BIT 7,(IX+d)* - case 0x7D: //BIT 7,(IX+d)* - case 0x7E: //BIT 7,(IX+d) - case 0x7F: //BIT 7,(IX+d)* - BITixyd(7, ReadByteFromMemory(IndexRegistry[index] + dvalue), IndexRegistry[index] + dvalue, 20); - break; - case 0x87: //LD A,RES 0,(IX+d)* - case 0x8F: //LD A,RES 1,(IX+d)* - case 0x97: //LD A,RES 2,(IX+d)* - case 0x9F: //LD A,RES 3,(IX+d)* - case 0xA7: //LD A,RES 4,(IX+d)* - case 0xAF: //LD A,RES 5,(IX+d)* - case 0xB7: //LD A,RES 6,(IX+d)* - case 0xBF: //LD A,RES 7,(IX+d)* - tmpValue = RES(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + case 0x40: //BIT 0,(IX+d)* + case 0x41: //BIT 0,(IX+d)* + case 0x42: //BIT 0,(IX+d)* + case 0x43: //BIT 0,(IX+d)* + case 0x44: //BIT 0,(IX+d)* + case 0x45: //BIT 0,(IX+d)* + case 0x46: //BIT 0,(IX+d) + case 0x47: //BIT 0,(IX+d)* + BITixyd(0, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), (ushort)(IndexRegistry[index] + dvalue), 20); + break; + case 0x48: //BIT 1,(IX+d)* + case 0x49: //BIT 1,(IX+d)* + case 0x4A: //BIT 1,(IX+d)* + case 0x4B: //BIT 1,(IX+d)* + case 0x4C: //BIT 1,(IX+d)* + case 0x4D: //BIT 1,(IX+d)* + case 0x4E: //BIT 1,(IX+d) + case 0x4F: //BIT 1,(IX+d)* + BITixyd(1, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), (ushort)(IndexRegistry[index] + dvalue), 20); + break; + case 0x50: //BIT 2,(IX+d)* + case 0x51: //BIT 2,(IX+d)* + case 0x52: //BIT 2,(IX+d)* + case 0x53: //BIT 2,(IX+d)* + case 0x54: //BIT 2,(IX+d)* + case 0x55: //BIT 2,(IX+d)* + case 0x56: //BIT 2,(IX+d) + case 0x57: //BIT 2,(IX+d)* + BITixyd(2, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), (ushort)(IndexRegistry[index] + dvalue), 20); + break; + case 0x58: //BIT 3,(IX+d)* + case 0x59: //BIT 3,(IX+d)* + case 0x5A: //BIT 3,(IX+d)* + case 0x5B: //BIT 3,(IX+d)* + case 0x5C: //BIT 3,(IX+d)* + case 0x5D: //BIT 3,(IX+d)* + case 0x5E: //BIT 3,(IX+d) + BITixyd(3, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), (ushort)(IndexRegistry[index] + dvalue), 20); + break; + case 0x5F: //BIT 3,(IX+d)* + case 0x60: //BIT 4,(IX+d)* + case 0x61: //BIT 4,(IX+d)* + case 0x62: //BIT 4,(IX+d)* + case 0x63: //BIT 4,(IX+d)* + case 0x64: //BIT 4,(IX+d)* + case 0x65: //BIT 4,(IX+d)* + case 0x66: //BIT 4,(IX+d) + case 0x67: //BIT 4,(IX+d)* + BITixyd(4, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), (ushort)(IndexRegistry[index] + dvalue), 20); + break; + case 0x68: //BIT 5,(IX+d)* + case 0x69: //BIT 5,(IX+d)* + case 0x6A: //BIT 5,(IX+d)* + case 0x6B: //BIT 5,(IX+d)* + case 0x6C: //BIT 5,(IX+d)* + case 0x6D: //BIT 5,(IX+d)* + case 0x6E: //BIT 5,(IX+d) + case 0x6F: //BIT 5,(IX+d)* + BITixyd(5, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), (ushort)(IndexRegistry[index] + dvalue), 20); + break; + case 0x70: //BIT 6,(IX+d)* + case 0x71: //BIT 6,(IX+d)* + case 0x72: //BIT 6,(IX+d)* + case 0x73: //BIT 6,(IX+d)* + case 0x74: //BIT 6,(IX+d)* + case 0x75: //BIT 6,(IX+d)* + case 0x76: //BIT 6,(IX+d) + case 0x77: //BIT 6,(IX+d)* + BITixyd(6, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), (ushort)(IndexRegistry[index] + dvalue), 20); + break; + case 0x78: //BIT 7,(IX+d)* + case 0x79: //BIT 7,(IX+d)* + case 0x7A: //BIT 7,(IX+d)* + case 0x7B: //BIT 7,(IX+d)* + case 0x7C: //BIT 7,(IX+d)* + case 0x7D: //BIT 7,(IX+d)* + case 0x7E: //BIT 7,(IX+d) + case 0x7F: //BIT 7,(IX+d)* + BITixyd(7, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), (ushort)(IndexRegistry[index] + dvalue), 20); + break; + case 0x87: //LD A,RES 0,(IX+d)* + case 0x8F: //LD A,RES 1,(IX+d)* + case 0x97: //LD A,RES 2,(IX+d)* + case 0x9F: //LD A,RES 3,(IX+d)* + case 0xA7: //LD A,RES 4,(IX+d)* + case 0xAF: //LD A,RES 5,(IX+d)* + case 0xB7: //LD A,RES 6,(IX+d)* + case 0xBF: //LD A,RES 7,(IX+d)* + tmpValue = RES(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; case 0xC7: //LD A,SET 0,(IX+d)* @@ -817,8 +817,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xEF: //LD A,SET 5,(IX+d)* case 0xF7: //LD A,SET 6,(IX+d)* case 0xFF: //LD A,SET 7,(IX+d)* - tmpValue = SET(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = SET(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); A = tmpValue; break; case 0x80: //LD B,RES 0,(IX+d)* @@ -829,8 +829,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xA8: //LD B,RES 5,(IX+d)* case 0xB0: //LD B,RES 6,(IX+d)* case 0xB8: //LD B,RES 7,(IX+d)* - tmpValue = RES(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = RES(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; case 0xC0: //LD B,SET 0,(IX+d)* @@ -841,8 +841,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xE8: //LD B,SET 5,(IX+d)* case 0xF0: //LD B,SET 6,(IX+d)* case 0xF8: //LD B,SET 7,(IX+d)* - tmpValue = SET(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = SET(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); B = tmpValue; break; case 0x81: //LD C,RES 0,(IX+d)* @@ -853,8 +853,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xA9: //LD C,RES 5,(IX+d)* case 0xB1: //LD C,RES 6,(IX+d)* case 0xB9: //LD C,RES 7,(IX+d)* - tmpValue = RES(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = RES(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; case 0xC1: //LD C,SET 0,(IX+d)* @@ -865,8 +865,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xE9: //LD C,SET 5,(IX+d)* case 0xF1: //LD C,SET 6,(IX+d)* case 0xF9: //LD C,SET 7,(IX+d)* - tmpValue = SET(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = SET(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); C = tmpValue; break; case 0x82: //LD D,RES 0,(IX+d)* @@ -877,8 +877,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xAA: //LD D,RES 5,(IX+d)* case 0xB2: //LD D,RES 6,(IX+d)* case 0xBA: //LD D,RES 7,(IX+d)* - tmpValue = RES(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = RES(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; case 0xC2: //LD D,SET 0,(IX+d)* @@ -889,8 +889,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xEA: //LD D,SET 5,(IX+d)* case 0xF2: //LD D,SET 6,(IX+d)* case 0xFA: //LD D,SET 7,(IX+d)* - tmpValue = SET(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = SET(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); D = tmpValue; break; case 0x83: //LD E,RES 0,(IX+d)* @@ -901,8 +901,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xAB: //LD E,RES 5,(IX+d)* case 0xB3: //LD E,RES 6,(IX+d)* case 0xBB: //LD E,RES 7,(IX+d)* - tmpValue = RES(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = RES(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; case 0xC3: //LD E,SET 0,(IX+d)* @@ -913,8 +913,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xEB: //LD E,SET 5,(IX+d)* case 0xF3: //LD E,SET 6,(IX+d)* case 0xFB: //LD E,SET 7,(IX+d)* - tmpValue = SET(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = SET(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); E = tmpValue; break; case 0x84: //LD H,RES 0,(IX+d)* @@ -925,8 +925,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xAC: //LD H,RES 5,(IX+d)* case 0xB4: //LD H,RES 6,(IX+d)* case 0xBC: //LD H,RES 7,(IX+d)* - tmpValue = RES(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = RES(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; case 0xC4: //LD H,SET 0,(IX+d)* @@ -937,8 +937,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xEC: //LD H,SET 5,(IX+d)* case 0xF4: //LD H,SET 6,(IX+d)* case 0xFC: //LD H,SET 7,(IX+d)* - tmpValue = SET(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = SET(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); H = tmpValue; break; case 0x85: //LD L,RES 0,(IX+d)* @@ -949,8 +949,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xAD: //LD L,RES 5,(IX+d)* case 0xB5: //LD L,RES 6,(IX+d)* case 0xBD: //LD L,RES 7,(IX+d)* - tmpValue = RES(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = RES(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; case 0xC5: //LD L,SET 0,(IX+d)* @@ -961,8 +961,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xED: //LD L,SET 5,(IX+d)* case 0xF5: //LD L,SET 6,(IX+d)* case 0xFD: //LD L,SET 7,(IX+d)* - tmpValue = SET(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = SET(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); L = tmpValue; break; case 0x86: //RES 0,(IX+d) @@ -973,8 +973,8 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xAE: //RES 5,(IX+d) case 0xB6: //RES 6,(IX+d) case 0xBE: //RES 7,(IX+d) - tmpValue = RES(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = RES(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; case 0xC6: //SET 0,(IX+d) case 0xCE: //SET 1,(IX+d) @@ -984,59 +984,59 @@ public void DoDDorFDPrefixInstruction(IndexRegistryEnum IRindex) case 0xEE: //SET 5,(IX+d) case 0xF6: //SET 6,(IX+d) case 0xFE: //SET 7,(IX+d) - tmpValue = SET(BitValueFromOP, ReadByteFromMemory(IndexRegistry[index] + dvalue), 23); - WriteByteToMemory(IndexRegistry[index] + dvalue, tmpValue); + tmpValue = SET(BitValueFromOP, ReadByteFromMemory((ushort)(IndexRegistry[index] + dvalue)), 23); + WriteByteToMemory((ushort)(IndexRegistry[index] + dvalue), tmpValue); break; } break; - case 0xE1: //POP IX + case 0xE1: //POP IX IndexRegistry[index] = POP(); SubtractNumberOfTStatesLeft(14); break; - case 0xE5: //PUSH IX + case 0xE5: //PUSH IX PUSH(IndexRegistry[index]); SubtractNumberOfTStatesLeft(15); break; - case 0x9E: //SBC A,(IX+d) - A = SBC8(ReadByteFromMemory(IndexRegistry[index] + d), 19); + case 0x9E: //SBC A,(IX+d) + A = SBC8(ReadByteFromMemory((ushort)(IndexRegistry[index] + d)), 19); break; - case 0x9C: //SBC A,IXH* + case 0x9C: //SBC A,IXH* if (IRindex == IndexRegistryEnum.IX) A = SBC8(IXH, 4); else A = SBC8(IYH, 4); break; - case 0x9D: //SBC A,IXL* + case 0x9D: //SBC A,IXL* if (IRindex == IndexRegistryEnum.IX) A = SBC8(IXL, 4); else A = SBC8(IYL, 4); break; - case 0x96: //SUB (IX+d) - SUB(ReadByteFromMemory(IndexRegistry[index] + d), 7); + case 0x96: //SUB (IX+d) + SUB(ReadByteFromMemory((ushort)(IndexRegistry[index] + d)), 7); break; - case 0x94: //SUB IXH* + case 0x94: //SUB IXH* if (IRindex == IndexRegistryEnum.IX) SUB(IXH, 4); else SUB(IYH, 4); break; - case 0x95: //SUB IXL* + case 0x95: //SUB IXL* if (IRindex == IndexRegistryEnum.IX) SUB(IXL, 4); else SUB(IYL, 4); break; - case 0xAE: //XOR (IX+d) - XOR(ReadByteFromMemory(IndexRegistry[index] + d), 19); + case 0xAE: //XOR (IX+d) + XOR(ReadByteFromMemory((ushort)(IndexRegistry[index] + d)), 19); break; - case 0xAC: //XOR IXH* + case 0xAC: //XOR IXH* if (IRindex == IndexRegistryEnum.IX) XOR(IXH, 4); else XOR(IYH, 4); break; - case 0xAD: //XOR IXL* + case 0xAD: //XOR IXL* if (IRindex == IndexRegistryEnum.IX) XOR(IXL, 19); else diff --git a/ZXBox.Core/Cpus/Z80/Z80EDPrefixInstructions.cs b/ZXBox.Core/Cpus/Z80/Z80EDPrefixInstructions.cs index 0031729..701a3f9 100644 --- a/ZXBox.Core/Cpus/Z80/Z80EDPrefixInstructions.cs +++ b/ZXBox.Core/Cpus/Z80/Z80EDPrefixInstructions.cs @@ -32,70 +32,89 @@ public void DoEDPrefixInstruction() IM = 0; SubtractNumberOfTStatesLeft(8); break; - case 0x56: //IM 1 - case 0x76: //IM 1* + case 0x56: //IM 1 + case 0x76: //IM 1* IM = 1; SubtractNumberOfTStatesLeft(8); break; - case 0x5E: //IM 2 - case 0x7E: //IM 2* + case 0x5E: //IM 2 + case 0x7E: //IM 2* IM = 2; SubtractNumberOfTStatesLeft(8); break; - case 0x63: //LD (nn),HL + case 0x63: //LD (nn),HL WriteWordToMemory(GetNextPCWord(), HL); SubtractNumberOfTStatesLeft(16); break; - case 0x6B: //LD HL,(nn) + case 0x6B: //LD HL,(nn) HL = ReadWordFromMemory(GetNextPCWord()); SubtractNumberOfTStatesLeft(20); break; - case 0x73: //LD (nn),SP + case 0x73: //LD (nn),SP WriteWordToMemory(GetNextPCWord(), SP); SubtractNumberOfTStatesLeft(16); break; - case 0x7B: //LD SP,(nn) + case 0x7B: //LD SP,(nn) SP = ReadWordFromMemory(GetNextPCWord()); SubtractNumberOfTStatesLeft(20); break; - case 0xA2: //INI - INI(16); break; + case 0xA2: //INI + INI(16); + break; case 0x78: //IN A,(C) - A = INBC(12); break; + A = INBC(12); + break; case 0x40: //IN B,(C) - B = INBC(12); break; + B = INBC(12); + break; case 0x48: //IN C,(C) - C = INBC(12); break; + C = INBC(12); + break; case 0x50: //IN D,(C) - D = INBC(12); break; + D = INBC(12); + break; case 0x58: //IN E,(C) - E = INBC(12); break; + E = INBC(12); + break; case 0x70: //IN F,(C)* / IN (C)* - INBC(12); break; + INBC(12); + break; case 0x60: //IN H,(C) - H = INBC(12); break; + H = INBC(12); + break; case 0x68: //IN L,(C)F - L = INBC(12); break; + L = INBC(12); + break; case 0xAA: //IND - IND(16); break; + IND(16); + break; case 0xBA: //INDR - INDR(); break; - case 0x57: //LD A,I - LDAI(); break; + INDR(); + break; + case 0x57: //LD A,I + LDAI(); + break; case 0x5F: //LD A,R - LDAR(); break; - case 0x47: //LD I,A - I = A; SubtractNumberOfTStatesLeft(9); break; - case 0x4F: //LD R,A - R = A; SubtractNumberOfTStatesLeft(9); break; - case 0xA8: //LDD - LDD(); break; - case 0xB8: //LDDR - LDDR(); break; + LDAR(); + break; + case 0x47: //LD I,A + I = A; SubtractNumberOfTStatesLeft(9); + break; + case 0x4F: //LD R,A + R = A; SubtractNumberOfTStatesLeft(9); + break; + case 0xA8: //LDD + LDD(); + break; + case 0xB8: //LDDR + LDDR(); + break; case 0xA0: //LDI - LDI(); break; + LDI(); + break; case 0xB0: //LDIR - LDIR(); break; + LDIR(); + break; case 0x44: //NEG case 0x4C: //NEG* case 0x54: //NEG* @@ -104,11 +123,14 @@ public void DoEDPrefixInstruction() case 0x6C: //NEG* case 0x74: //NEG* case 0x7C: //NEG* - NEG(); break; + NEG(); + break; case 0xBB: - OTDR(); break; + OTDR(); + break; case 0xB3: - OTIR(); break; + OTIR(); + break; case 0x71: //OUT (C),0* SubtractNumberOfTStatesLeft(8); Out(BC, 0, NumberOfTstates - Math.Abs(_numberOfTStatesLeft)); @@ -125,12 +147,12 @@ public void DoEDPrefixInstruction() Out(BC, RegisterValueFromOP(3), NumberOfTstates - Math.Abs(_numberOfTStatesLeft)); SubtractNumberOfTStatesLeft(4); //12 break; - case 0xAB: //OUTD + case 0xAB: //OUTD OUTD(); break; - case 0xA3: //OUTI + case 0xA3: //OUTI OUTI(); break; - case 0x4D: //RETI + case 0x4D: //RETI RET(true, 14, 0); break; case 0x45: //RETN @@ -143,10 +165,10 @@ public void DoEDPrefixInstruction() RET(true, 14, 0); IFF = IFF2; break; - case 0x6F: //RLD + case 0x6F: //RLD RLD(); break; - case 0x67://RRD + case 0x67: //RRD RRD(); break; case 0x42: //SBC HL,BC @@ -161,23 +183,23 @@ public void DoEDPrefixInstruction() case 0x72: //SBC HL,SP HL = SBC16(HL, SP, 15); break; - case 0x53: //LD (nn),DE + case 0x53: //LD (nn),DE WriteWordToMemory(GetNextPCWord(), DE); SubtractNumberOfTStatesLeft(20); break; - case 0x43: //LD (nn),BC + case 0x43: //LD (nn),BC WriteWordToMemory(GetNextPCWord(), BC); SubtractNumberOfTStatesLeft(20); break; - case 0x4B: //LD BC,(nn) + case 0x4B: //LD BC,(nn) BC = ReadWordFromMemory(GetNextPCWord()); SubtractNumberOfTStatesLeft(10); break; - case 0x5B: //LD DE,(nn) + case 0x5B: //LD DE,(nn) DE = ReadWordFromMemory(GetNextPCWord()); SubtractNumberOfTStatesLeft(10); break; - case 0xB2: //INIR + case 0xB2: //INIR INIR(); break; default: diff --git a/ZXBox.Core/Cpus/Z80/Z80NOPrefixInstructions.cs b/ZXBox.Core/Cpus/Z80/Z80NOPrefixInstructions.cs index aa8c401..e969cde 100644 --- a/ZXBox.Core/Cpus/Z80/Z80NOPrefixInstructions.cs +++ b/ZXBox.Core/Cpus/Z80/Z80NOPrefixInstructions.cs @@ -4,130 +4,129 @@ namespace Zilog; public partial class Z80 { - - int tmpw; - int tmpAF; - int tmpDE; + ushort tmpw; + ushort tmpAF; + ushort tmpDE; int tmphaltsToInterrupt; - int tmpport; - public void DoNoPrefixInstruction() { switch (opcode) { - case 0x2A: //LD HL,(nn) + case 0x2A: //LD HL,(nn) HL = ReadWordFromMemory(GetNextPCWord()); SubtractNumberOfTStatesLeft(20); break; - case 0x21: //LD HL,nn + case 0x21: //LD HL,nn HL = GetNextPCWord(); SubtractNumberOfTStatesLeft(10); break; //Adc A, r - case 0x8F: //ADC A,A - case 0x88: //ADC A,B - case 0x89: //ADC A,C - case 0x8A: //ADC A,D - case 0x8B: //ADC A,E - case 0x8C: //ADC A,H - case 0x8D: //ADC A,L - A = ADDADC8(A, RegisterValueFromOP(0), true, 4); break; - case 0x8E: //ADC A,(HL) + case 0x8F: //ADC A,A + case 0x88: //ADC A,B + case 0x89: //ADC A,C + case 0x8A: //ADC A,D + case 0x8B: //ADC A,E + case 0x8C: //ADC A,H + case 0x8D: //ADC A,L + A = ADDADC8(A, RegisterValueFromOP(0), true, 4); + break; + case 0x8E: //ADC A,(HL) A = ADDADC8(A, ReadByteFromMemory(HL), true, 7); break; - case 0xCE: //ADC A,n - A = ADDADC8(A, GetNextPCByte(), true, 7); break; + case 0xCE: //ADC A,n + A = ADDADC8(A, GetNextPCByte(), true, 7); + break; //Add a,ss - case 0x86://ADD A,(HL) + case 0x86: //ADD A,(HL) A = ADDADC8(A, ReadByteFromMemory(HL), false, 7); break; - case 0x87: //ADD A,A - case 0x80: //ADD A,B - case 0x81: //ADD A,C - case 0x82: //ADD A,D - case 0x83: //ADD A,E - case 0x84: //ADD A,H - case 0x85: //ADD A,L + case 0x87: //ADD A,A + case 0x80: //ADD A,B + case 0x81: //ADD A,C + case 0x82: //ADD A,D + case 0x83: //ADD A,E + case 0x84: //ADD A,H + case 0x85: //ADD A,L A = ADDADC8(A, RegisterValueFromOP(0), false, 4); break; - case 0xC6: //ADD A,n + case 0xC6: //ADD A,n A = ADDADC8(A, GetNextPCByte(), false, 7); break; - case 0x09://ADD HL,BC + case 0x09: //ADD HL,BC HL = ADDADC16(HL, BC, false, 11); break; - case 0x19://ADD HL,DE + case 0x19: //ADD HL,DE HL = ADDADC16(HL, DE, false, 11); break; - case 0x29: //ADD HL,HL + case 0x29: //ADD HL,HL HL = ADDADC16(HL, HL, false, 11); break; - case 0x39://ADD HL,SP + case 0x39: //ADD HL,SP HL = ADDADC16(HL, SP, false, 11); break; - case 0xA6://AND (HL) + case 0xA6: //AND (HL) A = AND8(A, ReadByteFromMemory(HL), 7); break; - case 0xA7: //AND A - case 0xA0: //AND B - case 0xA1: //AND C - case 0xA2: //AND D - case 0xA3: //AND E - case 0xA4: //AND H - case 0xA5: //AND L + case 0xA7: //AND A + case 0xA0: //AND B + case 0xA1: //AND C + case 0xA2: //AND D + case 0xA3: //AND E + case 0xA4: //AND H + case 0xA5: //AND L A = AND8(A, RegisterValueFromOP(0), 4); break; case 0xE6: //AND n A = AND8(A, GetNextPCByte(), 12); break; - case 0xCD: //CALL (nn) + case 0xCD: //CALL (nn) CALLnn(); break; - case 0xDC: //CALL C,(nn) + case 0xDC: //CALL C,(nn) CALL(fC); break; - case 0xFC: //CALL M,(nn) + case 0xFC: //CALL M,(nn) CALL(fS); break; - case 0xD4: //CALL NC,(nn) + case 0xD4: //CALL NC,(nn) CALL(!fC); break; - case 0xC4: //CALL NZ,(nn) + case 0xC4: //CALL NZ,(nn) CALL(!fZ); break; - case 0xF4: //CALL P,(nn) + case 0xF4: //CALL P,(nn) CALL(!fS); break; - case 0xEC: //CALL PE,(nn) + case 0xEC: //CALL PE,(nn) CALL(fPV); break; - case 0xE4: //CALL PO,(nn) + case 0xE4: //CALL PO,(nn) CALL(!fPV); break; - case 0xCC: //CALL Z,(nn) + case 0xCC: //CALL Z,(nn) CALL(fZ); break; - case 0x3F: //CCF + case 0x3F: //CCF CCF(); break; - case 0xBE: //CP (HL) + case 0xBE: //CP (HL) CP(ReadByteFromMemory(HL), 7); break; - case 0xBF: //CP A - case 0xB8: //CP B - case 0xB9: //CP C - case 0xBA: //CP D - case 0xBB: //CP E + case 0xBF: //CP A + case 0xB8: //CP B + case 0xB9: //CP C + case 0xBA: //CP D + case 0xBB: //CP E CP(RegisterValueFromOP(0), 4); break; //TODO: Check number of tstates for undocumented function - case 0xBC: //CP H + case 0xBC: //CP H CP(H, 4); break; - case 0xBD: //CP H + case 0xBD: //CP H CP(L, 4); break; - case 0xFE: //CP n + case 0xFE: //CP n CP(GetNextPCByte(), 7); break; case 0x2F: //CPL @@ -136,32 +135,40 @@ public void DoNoPrefixInstruction() case 0x27: //DAA DAA(); break; - case 0x35: //DEC(HL) + case 0x35: //DEC(HL) WriteByteToMemory(HL, DEC8(ReadByteFromMemory(HL), 11)); break; - case 0x3D: //DEC A - A = DEC8(A, 4); break; - case 0x05: //DEC B - B = DEC8(B, 4); break; - case 0x0B: //DEC BC - BC = DEC16(BC, 6); break; - case 0x0D: //DEC C - C = DEC8(C, 4); break; - case 0x15: //DEC D - D = DEC8(D, 4); break; - case 0x1B: //DEC DE - DE = DEC16(DE, 6); break; - case 0x1D: //DEC E - E = DEC8(E, 6); break; + case 0x3D: //DEC A + A = DEC8(A, 4); + break; + case 0x05: //DEC B + B = DEC8(B, 4); + break; + case 0x0B: //DEC BC + BC = DEC16(BC, 6); + break; + case 0x0D: //DEC C + C = DEC8(C, 4); + break; + case 0x15: //DEC D + D = DEC8(D, 4); + break; + case 0x1B: //DEC DE + DE = DEC16(DE, 6); + break; + case 0x1D: //DEC E + E = DEC8(E, 6); + break; case 0x25: //DEC H - H = DEC8(H, 6); break; - case 0x2B: //DEC HL + H = DEC8(H, 6); + break; + case 0x2B: //DEC HL HL = DEC16(HL, 6); break; - case 0x2D: //DEC L + case 0x2D: //DEC L L = DEC8(L, 6); break; - case 0x3B: //DEC SP + case 0x3B: //DEC SP SP = DEC16(SP, 6); break; case 0xF3: //DI @@ -175,7 +182,7 @@ public void DoNoPrefixInstruction() IFF = IFF2 = true; SubtractNumberOfTStatesLeft(4); break; - case 0xE3: //EX (SP),HL + case 0xE3: //EX (SP),HL tmpw = ReadWordFromMemory(SP); WriteWordToMemory(SP, HL); HL = tmpw; @@ -199,125 +206,131 @@ public void DoNoPrefixInstruction() case 0x76: //Halt Halt(); break; - case 0xDB: //IN A,(n) - - tmpport = (A << 8) | GetNextPCByte(); + case 0xDB: //IN A,(n) + byte tmpport = (byte)((A << 8) | GetNextPCByte()); A = In(tmpport); SubtractNumberOfTStatesLeft(11); break; - case 0x34: //INC (HL) + case 0x34: //INC (HL) WriteByteToMemory(HL, INC8(ReadByteFromMemory(HL), 0)); SubtractNumberOfTStatesLeft(11); break; - case 0x3C: //INC A + case 0x3C: //INC A A = INC8(A, 4); break; - case 0x04: //INC B + case 0x04: //INC B B = INC8(B, 4); break; - case 0x03: //INC BC + case 0x03: //INC BC BC = INC16(BC, 6); break; - case 0x0C: //INC C + case 0x0C: //INC C C = INC8(C, 4); break; - case 0x14: //INC D + case 0x14: //INC D D = INC8(D, 4); break; - case 0x13: //INC DE + case 0x13: //INC DE DE = INC16(DE, 6); break; - case 0x1C: //INC E + case 0x1C: //INC E E = INC8(E, 4); break; - case 0x24: //INC H + case 0x24: //INC H H = INC8(H, 4); break; - case 0x23://INC HL + case 0x23: //INC HL HL = INC16(HL, 6); break; - - case 0x2C: //INC L + case 0x2C: //INC L L = INC8(L, 4); break; - case 0x33: //INC SP + case 0x33: //INC SP SP = INC16(SP, 6); break; - case 0xE9: //JP (HL) + case 0xE9: //JP (HL) JP(true, HL, 4); break; - case 0xC3: //JP (nn) - JP(true, GetNextPCWord(), 10); break; - case 0xDA: //JP C,(nn) - JP(fC, GetNextPCWord(), 10); break; - case 0xFA: //JP M,(nn) - JP(fS, GetNextPCWord(), 10); break; - case 0xD2: //JP NC,(nn) - JP(!fC, GetNextPCWord(), 10); break; - case 0xC2: //JP NZ,(nn) - JP(!fZ, GetNextPCWord(), 10); break; - case 0xF2: //JP P,(nn) - JP(!fS, GetNextPCWord(), 10); break; - case 0xEA: //JP PE,(nn) - JP(fPV, GetNextPCWord(), 10); break; - case 0xE2: //JP PO,(nn) - JP(!fPV, GetNextPCWord(), 10); break; - case 0xCA: //JP Z,(nn) - JP(fZ, GetNextPCWord(), 10); break; + case 0xC3: //JP (nn) + JP(true, GetNextPCWord(), 10); + break; + case 0xDA: //JP C,(nn) + JP(fC, GetNextPCWord(), 10); + break; + case 0xFA: //JP M,(nn) + JP(fS, GetNextPCWord(), 10); + break; + case 0xD2: //JP NC,(nn) + JP(!fC, GetNextPCWord(), 10); + break; + case 0xC2: //JP NZ,(nn) + JP(!fZ, GetNextPCWord(), 10); + break; + case 0xF2: //JP P,(nn) + JP(!fS, GetNextPCWord(), 10); + break; + case 0xEA: //JP PE,(nn) + JP(fPV, GetNextPCWord(), 10); + break; + case 0xE2: //JP PO,(nn) + JP(!fPV, GetNextPCWord(), 10); + break; + case 0xCA: //JP Z,(nn) + JP(fZ, GetNextPCWord(), 10); + break; case 0x18: //JR (PC+e) - JR(true, GetNextPCByte(), 12); break; - case 0x38: //JR C,(PC+e) - JR(fC, GetNextPCByte(), fC ? 12 : 7); break; - case 0x30: //JR NC,(PC+e) - JR(!fC, GetNextPCByte(), !fC ? 12 : 7); break; - case 0x20: //JR NZ,(PC+e) - JR(!fZ, GetNextPCByte(), !fZ ? 12 : 7); break; - case 0x28: //JR Z,(PC+e) - JR(fZ, GetNextPCByte(), fZ ? 12 : 7); break; - case 0x02: //LD (BC),A - WriteByteToMemory(BC, A); SubtractNumberOfTStatesLeft(7); break; - case 0x12: //LD (DE),A - WriteByteToMemory(DE, A); SubtractNumberOfTStatesLeft(7); break; - case 0x77: //LD (HL),A - case 0x70: //LD (HL),B - case 0x71: //LD (HL),C - case 0x72: //LD (HL),D - case 0x73: //LD (HL),E - case 0x74: //LD (HL),H + JR(true, GetNextPCByte(), 12); + break; + case 0x38: //JR C,(PC+e) + JR(fC, GetNextPCByte(), fC ? 12 : 7); + break; + case 0x30: //JR NC,(PC+e) + JR(!fC, GetNextPCByte(), !fC ? 12 : 7); + break; + case 0x20: //JR NZ,(PC+e) + JR(!fZ, GetNextPCByte(), !fZ ? 12 : 7); + break; + case 0x28: //JR Z,(PC+e) + JR(fZ, GetNextPCByte(), fZ ? 12 : 7); + break; + case 0x02: //LD (BC),A + WriteByteToMemory(BC, A); + SubtractNumberOfTStatesLeft(7); + break; + case 0x12: //LD (DE),A + WriteByteToMemory(DE, A); + SubtractNumberOfTStatesLeft(7); + break; + case 0x77: //LD (HL),A + case 0x70: //LD (HL),B + case 0x71: //LD (HL),C + case 0x72: //LD (HL),D + case 0x73: //LD (HL),E + case 0x74: //LD (HL),H case 0x75: //LD (HL),L - WriteByteToMemory(HL, RegisterValueFromOP(0)); SubtractNumberOfTStatesLeft(7); break; - case 0x36: //LD (HL),n - WriteByteToMemory(HL, GetNextPCByte()); SubtractNumberOfTStatesLeft(10); break; - case 0x32: //LD (nn),A - WriteByteToMemory(GetNextPCWord(), A); SubtractNumberOfTStatesLeft(13); break; - case 0x22: //LD (nn),HL + WriteByteToMemory(HL, RegisterValueFromOP(0)); + SubtractNumberOfTStatesLeft(7); + break; + case 0x36: //LD (HL),n + WriteByteToMemory(HL, GetNextPCByte()); + SubtractNumberOfTStatesLeft(10); + break; + case 0x32: //LD (nn),A + WriteByteToMemory(GetNextPCWord(), A); + SubtractNumberOfTStatesLeft(13); + break; + case 0x22: //LD (nn),HL WriteWordToMemory(GetNextPCWord(), HL); SubtractNumberOfTStatesLeft(20); break; - case 0x0A: //LD A,(BC) + case 0x0A: //LD A,(BC) A = ReadByteFromMemory(BC); SubtractNumberOfTStatesLeft(7); break; - case 0x1A: //LD A,(DE) + case 0x1A: //LD A,(DE) A = ReadByteFromMemory(DE); SubtractNumberOfTStatesLeft(7); break; - case 0x7E://LD A,(HL) + case 0x7E: //LD A,(HL) A = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(7); break; - case 0x3A: //LD A,(nn) + case 0x3A: //LD A,(nn) A = ReadByteFromMemory(GetNextPCWord()); SubtractNumberOfTStatesLeft(13); break; - //case 0x7F: //LD A,A - //case 0x78: //LD A,B - //case 0x79: //LD A,C - //case 0x7A: //LD A,D - //case 0x7B: //LD A,E - // A = RegisterValueFromOP(0); - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x7C: //LD A,H - // A = H; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x7D: //LD A,L - // A = L; - // SubtractNumberOfTStatesLeft(4); - // break; case >= 0x78 and <= 0x7D or 0x7F: //LD A,r case >= 0x40 and <= 0x43 or 0x47: //LD B,r case >= 0x48 and <= 0x4D or 0x4F: //LD C,r @@ -332,31 +345,23 @@ public void DoNoPrefixInstruction() A = GetNextPCByte(); SubtractNumberOfTStatesLeft(7); break; - case 0x46: //LD B,(HL) + case 0x46: //LD B,(HL) B = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(7); break; - //case 0x47: //LD B,A - //case 0x40: //LD B,B - //case 0x41: //LD B,C - //case 0x42: //LD B,D - //case 0x43: //LD B,E - // B = RegisterValueFromOP(0); - // SubtractNumberOfTStatesLeft(4); - // break; case 0x44: //LD B,H B = H; SubtractNumberOfTStatesLeft(4); break; - case 0x45://LD B,L + case 0x45: //LD B,L B = L; SubtractNumberOfTStatesLeft(4); break; - case 0x06: //LD B,n + case 0x06: //LD B,n B = GetNextPCByte(); SubtractNumberOfTStatesLeft(7); break; - case 0x01: //LD BC,nn + case 0x01: //LD BC,nn BC = GetNextPCWord(); SubtractNumberOfTStatesLeft(10); break; @@ -364,23 +369,7 @@ public void DoNoPrefixInstruction() C = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(7); break; - //case 0x4F: //LD C,A - //case 0x48: //LD C,B - //case 0x49: //LD C,C - //case 0x4A: //LD C,D - //case 0x4B: //LD C,E - // C = RegisterValueFromOP(0); - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x4C: //LD C,H - // C = H; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x4D://LD C,L - // C = L; - // SubtractNumberOfTStatesLeft(4); - // break; - case 0x0E: //LD C,n + case 0x0E: //LD C,n C = GetNextPCByte(); SubtractNumberOfTStatesLeft(7); break; @@ -388,27 +377,11 @@ public void DoNoPrefixInstruction() D = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(7); break; - //case 0x57: //LD D,A - //case 0x50: //LD D,B - //case 0x51: //LD D,C - //case 0x52: //LD D,D - //case 0x53: //LD D,E - // D = RegisterValueFromOP(0); - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x54: //LD D,H - // D = H; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x55: //LD D,L - // D = L; - // SubtractNumberOfTStatesLeft(4); - // break; - case 0x16: //LD D,n + case 0x16: //LD D,n D = GetNextPCByte(); SubtractNumberOfTStatesLeft(7); break; - case 0x11: //LD DE,nn + case 0x11: //LD DE,nn DE = GetNextPCWord(); SubtractNumberOfTStatesLeft(7); break; @@ -416,59 +389,15 @@ public void DoNoPrefixInstruction() E = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(7); break; - //case 0x5F: //LD E,A - //case 0x58: //LD E,B - //case 0x59: //LD E,C - //case 0x5A: //LD E,D - //case 0x5B: //LD E,E - // E = RegisterValueFromOP(0); - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x5C: //LD E,H - // E = H; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x5D://LD E,L - // E = L; - // SubtractNumberOfTStatesLeft(4); - // break; - case 0x1E: //LD E,n + case 0x1E: //LD E,n E = GetNextPCByte(); SubtractNumberOfTStatesLeft(7); break; - case 0x66://LD H,(HL) + case 0x66: //LD H,(HL) H = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(7); break; - //case 0x67: //LD H,A - // H = A; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x60: //LD H,B - // H = B; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x61: //LD H,C - // H = C; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x62: //LD H,D - // H = D; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x63: //LD H,E - // H = E; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x64: //LD H,H - // H = H; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x65://LD H,L - // H = L; - // SubtractNumberOfTStatesLeft(4); - // break; - case 0x26: //LD H,n + case 0x26: //LD H,n H = GetNextPCByte(); SubtractNumberOfTStatesLeft(7); break; @@ -476,173 +405,145 @@ public void DoNoPrefixInstruction() L = ReadByteFromMemory(HL); SubtractNumberOfTStatesLeft(7); break; - //case 0x6F://LD L,A - // L = A; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x68: //LD L,B - // L = B; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x69: //LD L,C - // L = C; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x6A: //LD L,D - // L = D; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x6B: //LD L,E - // L = E; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x6C: //LD L,H - // L = H; - // SubtractNumberOfTStatesLeft(4); - // break; - //case 0x6D://LD L,L - // L = L; - // SubtractNumberOfTStatesLeft(4); - // break; - case 0x2E: //LD L ,n + case 0x2E: //LD L ,n L = GetNextPCByte(); SubtractNumberOfTStatesLeft(7); break; - case 0xF9: //LD SP HL + case 0xF9: //LD SP HL SP = HL; SubtractNumberOfTStatesLeft(6); break; - case 0x31: //LD SP,nn + case 0x31: //LD SP,nn SP = GetNextPCWord(); SubtractNumberOfTStatesLeft(10); break; - case 0x00: //Nop + case 0x00: //Nop NOP(); break; - case 0xB6: //OR (HL) + case 0xB6: //OR (HL) OR(ReadByteFromMemory(HL), 7); break; - case 0xB7: //OR A - case 0xB0: //OR B - case 0xB1: //OR C - case 0xB2: //OR D - case 0xB3: //OR E + case 0xB7: //OR A + case 0xB0: //OR B + case 0xB1: //OR C + case 0xB2: //OR D + case 0xB3: //OR E OR(RegisterValueFromOP(0), 4); break; - case 0xB4://OR H + case 0xB4: //OR H OR(H, 4); break; - case 0xB5://OR L + case 0xB5: //OR L OR(L, 4); break; - case 0xF6: //OR n + case 0xF6: //OR n OR(GetNextPCByte(), 7); break; - case 0xD3: //OUT (n),A + case 0xD3: //OUT (n),A SubtractNumberOfTStatesLeft(7); Out(GetNextPCByte(), A, NumberOfTstates - Math.Abs(_numberOfTStatesLeft)); SubtractNumberOfTStatesLeft(4); break; - case 0xF1: //POP AF + case 0xF1: //POP AF AF = POP(); SubtractNumberOfTStatesLeft(10); break; - case 0xC1: //POP BC + case 0xC1: //POP BC BC = POP(); SubtractNumberOfTStatesLeft(10); break; - case 0xD1: //POP DE + case 0xD1: //POP DE DE = POP(); SubtractNumberOfTStatesLeft(10); break; - case 0xE1: //POP HL + case 0xE1: //POP HL HL = POP(); SubtractNumberOfTStatesLeft(10); break; - case 0xF5: //PUSH AF + case 0xF5: //PUSH AF PUSH(AF); SubtractNumberOfTStatesLeft(11); break; - case 0xC5: //PUSH BC + case 0xC5: //PUSH BC PUSH(BC); SubtractNumberOfTStatesLeft(11); break; - case 0xD5: //PUSH DE + case 0xD5: //PUSH DE PUSH(DE); SubtractNumberOfTStatesLeft(11); break; - case 0xE5: //PUSH HL + case 0xE5: //PUSH HL PUSH(HL); SubtractNumberOfTStatesLeft(11); break; - case 0xC9: //RET + case 0xC9: //RET RET(true, 10, 0); break; - case 0xD8: //RET C + case 0xD8: //RET RET(fC, 10, 5); break; - case 0xF8: //RET M + case 0xF8: //RET M RET(fS, 11, 5); break; - case 0xD0: //RET NC + case 0xD0: //RET NC RET(!fC, 11, 5); break; - case 0xC0: //RET NZ + case 0xC0: //RET NZ RET(!fZ, 11, 5); break; - case 0xF0: //RET P + case 0xF0: //RET P RET(!fS, 11, 5); break; - case 0xE8: //RET PE + case 0xE8: //RET PE RET(fPV, 11, 5); break; - case 0xE0: //RET PO + case 0xE0: //RET PO RET(!fPV, 11, 5); break; - case 0xC8: //RET Z + case 0xC8: //RET Z RET(fZ, 11, 5); break; - case 0x17: //RLA + case 0x17: //RLA RLA(); break; - case 0x07: //RLCA + case 0x07: //RLCA RLCA(); break; - case 0x1F: //RRA + case 0x1F: //RRA RRA(); break; - case 0x0F: //RRCA + case 0x0F: //RRCA RRCA(); break; - case 0xC7: //RST 0H + case 0xC7: //RST 0H RST(0x00); break; - case 0xCF: //RST 8H + case 0xCF: //RST 8H RST(0x08); break; - case 0xD7: //RST 10H + case 0xD7: //RST 10H RST(0x10); break; - case 0xDF: //RST 18H + case 0xDF: //RST 18H RST(0x18); break; - case 0xE7: //RST 20H + case 0xE7: //RST 20H RST(0x20); break; - case 0xEF: //RST 28H + case 0xEF: //RST 28H RST(0x28); break; - case 0xF7: //RST 30H + case 0xF7: //RST 30H RST(0x30); break; - case 0xFF: //RST 38H + case 0xFF: //RST 38H RST(0x38); break; - case 0x9E: //SBC A,(HL) + case 0x9E: //SBC A,(HL) A = SBC8(ReadByteFromMemory(HL), 7); break; - case 0x9F: //SBC A,A - case 0x98: //SBC A,B - case 0x99: //SBC A,C - case 0x9A: //SBC A,D - case 0x9B: //SBC A,E - case 0x9C: //SBC A,H - case 0x9D: //SBC A,L + case 0x9F: //SBC A,A + case 0x98: //SBC A,B + case 0x99: //SBC A,C + case 0x9A: //SBC A,D + case 0x9B: //SBC A,E + case 0x9C: //SBC A,H + case 0x9D: //SBC A,L A = SBC8(RegisterValueFromOP(0), 4); break; - case 0xDE://SBC a,n + case 0xDE: //SBC a,n A = SBC8(GetNextPCByte(), 7); break; - case 0x37: //SCF + case 0x37: //SCF fC = true; fN = false; fH = false; @@ -651,31 +552,31 @@ public void DoNoPrefixInstruction() SubtractNumberOfTStatesLeft(4); break; - case 0x96: //SUB (HL) + case 0x96: //SUB (HL) SUB(ReadByteFromMemory(HL), 7); break; - case 0x97: //SUB A - case 0x90: //SUB B - case 0x91: //SUB C - case 0x92: //SUB D - case 0x93: //SUB E - case 0x94: //SUB H - case 0x95: //SUB L + case 0x97: //SUB A + case 0x90: //SUB B + case 0x91: //SUB C + case 0x92: //SUB D + case 0x93: //SUB E + case 0x94: //SUB H + case 0x95: //SUB L SUB(RegisterValueFromOP(0), 4); break; case 0xD6: SUB(GetNextPCByte(), 7); break; - case 0xAE: //XOR (HL) + case 0xAE: //XOR (HL) XOR(ReadByteFromMemory(HL), 7); break; - case 0xAF: //XOR A - case 0xA8: //XOR B - case 0xA9: //XOR C - case 0xAA: //XOR D - case 0xAB: //XOR E - case 0xAC: //XOR H - case 0xAD: //XOR L + case 0xAF: //XOR A + case 0xA8: //XOR B + case 0xA9: //XOR C + case 0xAA: //XOR D + case 0xAB: //XOR E + case 0xAC: //XOR H + case 0xAD: //XOR L XOR(RegisterValueFromOP(0), 4); break; case 0xEE: //XOR n diff --git a/ZXBox.Core/Gameboy.cs b/ZXBox.Core/Gameboy.cs index c701638..3816667 100644 --- a/ZXBox.Core/Gameboy.cs +++ b/ZXBox.Core/Gameboy.cs @@ -1,26 +1,26 @@ -using System.Collections.Generic; +using System.Collections.Generic; using ZXBox.Core.Cpus.Sharp; -using ZXBox.Hardware.Interfaces; - -namespace ZXBox; +using ZXBox.Hardware.Interfaces; -public class Gameboy : LR35902 -{ - public List Roms = new List { new byte[0x4000], new byte[0x4000] }; - public List Banks = new List { new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000] }; - public List RamBanks = new List { new byte[0x2000], new byte[0x2000], new byte[0x2000] }; - byte[] VideoMemory = new byte[0x2000]; - byte[] InternalRam = new byte[0x2000]; - byte[] SpriteAttributes = new byte[0x9F]; - byte[] IO = new byte[0x80]; - byte[] HighRam = new byte[0x7E]; - byte InteruptRegister = 0; - public List InputHardware = new List(); - public List OutputHardware = new List(); - - int bank = 0; - int rom = 0; - public override void WriteByteToMemory(int address, int bytetowrite) +namespace ZXBox; + +public class Gameboy : LR35902 +{ + public List Roms = new List { new byte[0x4000], new byte[0x4000] }; + public List Banks = new List { new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000] }; + public List RamBanks = new List { new byte[0x2000], new byte[0x2000], new byte[0x2000] }; + byte[] VideoMemory = new byte[0x2000]; + byte[] InternalRam = new byte[0x2000]; + byte[] SpriteAttributes = new byte[0x9F]; + byte[] IO = new byte[0x80]; + byte[] HighRam = new byte[0x7E]; + byte InteruptRegister = 0; + public List InputHardware = new List(); + public List OutputHardware = new List(); + + // int bank = 0; + int rom = 0; + public override void WriteByteToMemory(ushort address, byte bytetowrite) { if (address <= 0x3FFF) //rom { @@ -57,42 +57,42 @@ public override void WriteByteToMemory(int address, int bytetowrite) else if (address == 0xFFFF) //Interupt Register { InteruptRegister = (byte)(bytetowrite & 0xff); ; - } - } - - public override void WriteWordToMemory(int address, int word) - { - WriteByteToMemory(address, word & 0xff); - address++; - WriteByteToMemory(address, word >> 8); + } + } + + public override void WriteWordToMemory(ushort address, ushort word) + { + WriteByteToMemory(address, (byte)(word & 0xff)); + address++; + WriteByteToMemory(address, (byte)(word >> 8)); } - public override int ReadByteFromMemory(int address) + public override byte ReadByteFromMemory(ushort address) { if (IO[0xFF50 - 0xFF00] == 0 && address < GameboyClassic.Length) { return GameboyClassic[address]; } - if (address <= 0x3FFF) //rom - { - return Roms[0][address & 0xffff]; - } - else if (address >= 0x4000 && address <= 0x7FFF) //Switchable rom - { - return Banks[rom][address - 0x4000]; - } - else if (address >= 0x8000 && address <= 0x9FFF) //Video memory - { - return VideoMemory[address - 0x8000]; - } + if (address <= 0x3FFF) //rom + { + return Roms[0][address & 0xffff]; + } + else if (address >= 0x4000 && address <= 0x7FFF) //Switchable rom + { + return Banks[rom][address - 0x4000]; + } + else if (address >= 0x8000 && address <= 0x9FFF) //Video memory + { + return VideoMemory[address - 0x8000]; + } else if (address >= 0xA000 && address <= 0xBFFF) //Switchable RAM Bank { return RamBanks[0][address - 0xA000]; - } + } else if (address >= 0xC000 && address <= 0xDFFF) //Internal RAM { return InternalRam[address - 0xC000]; - } + } else if (address >= 0xFE00 && address <= 0xFE9F) //SpriteAttributes { return SpriteAttributes[address - 0xFE00]; @@ -100,20 +100,20 @@ public override int ReadByteFromMemory(int address) else if (address >= 0xFF00 && address <= 0xFF7F) //IO { return IO[address - 0xFF00]; - } + } else if (address >= 0xFF80 && address <= 0xFFFE) //HighRam { return HighRam[address - 0xFF80]; - } + } else if (address == 0xFFFF) //Interupt Register { return InteruptRegister; } - return 0; + return 0; } - public static int[] GameboyClassic = { + public static byte[] GameboyClassic = { 0x31, 0xFE, 0xFF, 0xAF, 0x21, 0xFF, 0x9F, 0x32, 0xCB, 0x7C, 0x20, 0xFB, 0x21, 0x26, 0xFF, 0x0E, 0x11, 0x3E, 0x80, 0x32, 0xE2, 0x0C, 0x3E, 0xF3, 0xE2, 0x32, 0x3E, 0x77, 0x77, 0x3E, 0xFC, 0xE0, 0x47, 0x11, 0x04, 0x01, 0x21, 0x10, 0x80, 0x1A, 0xCD, 0x95, 0x00, 0xCD, 0x96, 0x00, 0x13, 0x7B, @@ -130,5 +130,5 @@ public override int ReadByteFromMemory(int address) 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E, 0x3C, 0x42, 0xB9, 0xA5, 0xB9, 0xA5, 0x42, 0x3C, 0x21, 0x04, 0x01, 0x11, 0xA8, 0x00, 0x1A, 0x13, 0xBE, 0x00, 0x00, 0x23, 0x7D, 0xFE, 0x34, 0x20, 0xF5, 0x06, 0x19, 0x78, 0x86, 0x23, 0x05, 0x20, 0xFB, 0x86, 0x00, 0x00, 0x3E, 0x01, 0xE0, 0x50 - }; -} + }; +} diff --git a/ZXBox.Core/Hardware/Input/TapePlayer.cs b/ZXBox.Core/Hardware/Input/TapePlayer.cs index 109b60c..1758f2e 100644 --- a/ZXBox.Core/Hardware/Input/TapePlayer.cs +++ b/ZXBox.Core/Hardware/Input/TapePlayer.cs @@ -101,13 +101,13 @@ public void Play() public long CurrentTstate = 0; public long TotalTstates = 0; - private long lastTstate = 0; - private long diff = 0; - int returnvalue = 0xff; + // private long lastTstate = 0; + // private long diff = 0; + byte returnvalue = 0xff; EarValue ear; bool firstread = true; int tapeposition = 0; - public int Input(int Port, int tact) + public byte Input(ushort Port, int tact) { if (IsPlaying) { @@ -133,7 +133,7 @@ public int Input(int Port, int tact) } ear = EarValues[tapeposition]; - _beeper.Output(0xfe, (ear.Ear ? 1 : 0) << 4, tact); + _beeper.Output(0xfe, (byte)((ear.Ear ? 1 : 0) << 4), tact); if (ear != null) { if (ear.Pulse == PulseTypeEnum.Stop) @@ -143,7 +143,7 @@ public int Input(int Port, int tact) if (ear.Ear) return returnvalue |= 1 << 6; else - return returnvalue &= ~(1 << 6); + return returnvalue = (byte)(returnvalue & ~(1 << 6)); } } if (CurrentTstate > TotalTstates) diff --git a/ZXBox.Core/Hardware/Interfaces/IInput.cs b/ZXBox.Core/Hardware/Interfaces/IInput.cs index 18e08bc..1b4ae72 100644 --- a/ZXBox.Core/Hardware/Interfaces/IInput.cs +++ b/ZXBox.Core/Hardware/Interfaces/IInput.cs @@ -2,7 +2,6 @@ namespace ZXBox.Hardware.Interfaces; public interface IInput { - int Input(int Port, int tact); - void AddTStates(int tstates) - { } + byte Input(ushort Port, int tact); + void AddTStates(int tstates); } diff --git a/ZXBox.Core/Hardware/Interfaces/IOutput.cs b/ZXBox.Core/Hardware/Interfaces/IOutput.cs index 532aec2..cea159e 100644 --- a/ZXBox.Core/Hardware/Interfaces/IOutput.cs +++ b/ZXBox.Core/Hardware/Interfaces/IOutput.cs @@ -2,5 +2,5 @@ namespace ZXBox.Hardware.Interfaces; public interface IOutput { - void Output(int Port, int ByteValue, int tState); + void Output(ushort Port, byte ByteValue, int tState); } diff --git a/ZXBox.Core/Hardware/Output/Beeper.cs b/ZXBox.Core/Hardware/Output/Beeper.cs index 78d2627..793382c 100644 --- a/ZXBox.Core/Hardware/Output/Beeper.cs +++ b/ZXBox.Core/Hardware/Output/Beeper.cs @@ -93,7 +93,7 @@ public void GenerateSound(int tStates = 69888) int counter = 0; #region IOutput Members //The output is is not dependent on the way the sound will be outputted but rather all the values the buzzer would have at any given tstate - public void Output(int Port, int ByteValue, int tState) + public void Output(ushort Port, byte ByteValue, int tState) { double buffertstate = Convert.ToDouble(samplesPerFrame) / 69888d; diff --git a/ZXBox.Core/Hardware/Output/Screen.cs b/ZXBox.Core/Hardware/Output/Screen.cs index 65e1a31..53cca61 100644 --- a/ZXBox.Core/Hardware/Output/Screen.cs +++ b/ZXBox.Core/Hardware/Output/Screen.cs @@ -16,7 +16,6 @@ public class Screen : IOutput //32*24 public ScreenAttribute[] ScreenAttributes { get; set; } = new ScreenAttribute[768]; - bool dirtyborder = true; public void SwitchColors(bool switchColors) { if (switchColors) @@ -29,14 +28,6 @@ public void SwitchColors(bool switchColors) 0x000000FF, 0x0000ffFF, 0xff0000FF, 0xff00ffFF, 0x00ff00FF, 0x00ffffFF, 0xffff00FF, 0xffffffFF }; - - //colours = new uint[16] - //{ - // 0xFF000000, 0xFF0000cd, 0xFFcd0000, 0xFFcd00cd, - // 0xFF00cd00, 0xFF00cdcd, 0xFFcdcd00, 0xFFcdcdcd, - // 0xFF000000, 0xFF0000ff, 0xFFff0000, 0xFFff00ff, - // 0xFF00ff00, 0xFF00ffff, 0xFFffff00, 0xFFffffff - //}; } else { @@ -183,11 +174,10 @@ private uint GetBorderColor(double tState) private uint[] screen = null; private uint[] screenflash = null; private bool[] pixels = null; - //private int border; private List border = new List(); public uint LastBorderColor; - public void Output(int Port, int ByteValue, int tState) + public void Output(ushort Port, byte ByteValue, int tState) { if ((Port & 0x0001) == 0) { @@ -231,17 +221,6 @@ public uint[] drawScreen(bool flash) } - //for (int py = bordertop; py < Height; py++) - //{ - // for (int px = Width - bordersides; px < Width; px++) - // { - // var pixel = ((py * Width) + px); - // screen[pixel] = GetBorderColor(pixel * tstatesperpixel); - // screenflash[pixel] = GetBorderColor(pixel * tstatesperpixel); - // } - - //} - for (p = (Width * (Height - borderbottom)); p < (Height * Width); p++) { screen[p] = GetBorderColor(p * tstatesperpixel); @@ -259,206 +238,8 @@ public uint[] drawScreen(bool flash) { return screen; } - /* RGB palette entries for Spectrums 8 colours in normal and bright mode */ - tstate = 0; - pixmapIndex = 0; - bordercounter = 0; - foreground = colours[0]; - background = colours[15]; - - /* Fill in top part of screen with border colour */ - for (x = Width * bordertop; x-- > 0;) - screen[pixmapIndex++] = GetBorderColor(tstate += tstatesperpixel); - - for (attributeIndex = screenIndex + 24 * 32 * 8, pixelIndex = screenIndex, y = 0; y < 192;) - { - /* Fill in left part of border with border colour */ - - for (x = bordersides; x-- > 0; pixmapIndex++) - screen[pixmapIndex] = GetBorderColor(tstate += tstatesperpixel); - - /* Calculate start address of pixel row, the Spectrums video ram is - * connected to the screen handler with a few wires crossed, bit order - * is 7621 0543 instead of 7654 3210. */ - - pixelIndex = screenIndex + ((((y & 0x7) << 3) | ((y & 0x38) >> 3) | (y & 0xc0)) << 5); - - /* Loop through the 32 bytes in a pixel row */ - - for (x = 32; x-- > 0;) - { - /* Set background and foreground colours for this byte */ - - if (!flash || (cpu.ReadByteFromMemory(attributeIndex) & 0x80) == 0) - { - /* Three bit foreground colour is encoded in bits 0..2. - * The "bright" attribute is in bit 6. */ - - foreground = colours[(cpu.ReadByteFromMemory(attributeIndex) & 0x7) + (((cpu.ReadByteFromMemory(attributeIndex) & 0x40) != 0) ? 8 : 0)]; - - /* Three bit background colour is encoded in bits 3..5. - * "Bright" attribute still in bit 6. */ - - background = colours[((cpu.ReadByteFromMemory(attributeIndex) >> 3) & 0x7) + (((cpu.ReadByteFromMemory(attributeIndex) & 0x40) != 0) ? 8 : 0)]; - } - else - { - /* Three bit foreground colour is encoded in bits 0..2. - * However, we are in the inverse flash phase... */ - - background = colours[(cpu.ReadByteFromMemory(attributeIndex) & 0x7) + (((cpu.ReadByteFromMemory(attributeIndex) & 0x40) != 0) ? 8 : 0)]; - - /* Three bit background colour is encoded in bits 3..5. - * The inverse flash phase makes this the foreground. */ - - foreground = colours[((cpu.ReadByteFromMemory(attributeIndex) >> 3) & 0x7) + (((cpu.ReadByteFromMemory(attributeIndex) & 0x40) != 0) ? 8 : 0)]; - } - - /* We are done with this attribute, advance to next byte */ - - attributeIndex++; - - /* Loop through the pixels in the current pixel byte and add them to the - * output pixmap*/ - - for (pixelMask = 0x80, pixelByte = cpu.ReadByteFromMemory(pixelIndex++); pixelMask != 0; pixelMask >>= 1) - { - screen[pixmapIndex++] = ((pixelMask & pixelByte) != 0) ? foreground : background; - //pixmapIndex += 2; - tstate += tstatesperpixel; - } - } - - /* Add 32 pixels of border colour to both pixel rows */ - - for (x = bordersides; x-- > 0; pixmapIndex++) - screen[pixmapIndex] = GetBorderColor(tstate += tstatesperpixel); - - /* Skip next pixel row as we have already filled it */ - - //pixmapIndex += width; - - /* Unless the next row is a multiple of 8, we need to rewind the attribute - * pointer to the beginning of the pixel row. */ - - if ((++y & 0x7) != 0) - attributeIndex -= 32; - } - - /* Fill in bottom part of screen with border colour */ - - for (x = Width * borderbottom; x-- > 0;) - screen[pixmapIndex++] = GetBorderColor(tstate += tstatesperpixel); - - border.Clear(); - border.Add(new Border(LastBorderColor, 0)); - return screen; - } - int pixelIndex, attributeIndex; - int x, pixelByte, pixelMask; - uint foreground, background; + int x; int y; - double tstate = 0; - int pixmapIndex = 0; - int screenIndex = 16 * 1024; - - //public void drawScreen(Span screen,bool flash) - //{ - // tstate = 0; - // pixmapIndex = 0; - // /* RGB palette entries for Spectrums 8 colours in normal and bright mode */ - // bordercounter = 0; - - // foreground = colours[0]; - // background = colours[15]; - - // /* Fill in top part of screen with border colour */ - // for (x = Width * bordertop; x-- > 0; ) - // screen[pixmapIndex++] = (int)GetBorderColor(tstate += tstatesperpixel); - - // for (attributeIndex = screenIndex + 24 * 32 * 8, pixelIndex = screenIndex, y = 0; y < 192; ) - // { - // /* Fill in left part of border with border colour */ - - // for (x = bordersides; x-- > 0; pixmapIndex++) - // screen[pixmapIndex] = (int)GetBorderColor(tstate += tstatesperpixel); - - // /* Calculate start address of pixel row, the Spectrums video ram is - // * connected to the screen handler with a few wires crossed, bit order - // * is 7621 0543 instead of 7654 3210. */ - - // pixelIndex = screenIndex + ((((y & 0x7) << 3) | ((y & 0x38) >> 3) | (y & 0xc0)) << 5); - - // /* Loop through the 32 bytes in a pixel row */ - - // for (x = 32; x-- > 0; ) - // { - // /* Set background and foreground colours for this byte */ - - // if (!flash || (cpu.ReadByteFromMemory(attributeIndex) & 0x80) == 0) - // { - // /* Three bit foreground colour is encoded in bits 0..2. - // * The "bright" attribute is in bit 6. */ - - // foreground = colours[(cpu.ReadByteFromMemory(attributeIndex) & 0x7) + (((cpu.ReadByteFromMemory(attributeIndex) & 0x40) != 0) ? 8 : 0)]; - - // /* Three bit background colour is encoded in bits 3..5. - // * "Bright" attribute still in bit 6. */ - - // background = colours[((cpu.ReadByteFromMemory(attributeIndex) >> 3) & 0x7) + (((cpu.ReadByteFromMemory(attributeIndex) & 0x40) != 0) ? 8 : 0)]; - // } - // else - // { - // /* Three bit foreground colour is encoded in bits 0..2. - // * However, we are in the inverse flash phase... */ - - // background = colours[(cpu.ReadByteFromMemory(attributeIndex) & 0x7) + (((cpu.ReadByteFromMemory(attributeIndex) & 0x40) != 0) ? 8 : 0)]; - - // /* Three bit background colour is encoded in bits 3..5. - // * The inverse flash phase makes this the foreground. */ - - // foreground = colours[((cpu.ReadByteFromMemory(attributeIndex) >> 3) & 0x7) + (((cpu.ReadByteFromMemory(attributeIndex) & 0x40) != 0) ? 8 : 0)]; - // } - - // /* We are done with this attribute, advance to next byte */ - - // attributeIndex++; - - // /* Loop through the pixels in the current pixel byte and add them to the - // * output pixmap*/ - - // for (pixelMask = 0x80, pixelByte = cpu.ReadByteFromMemory(pixelIndex++); pixelMask != 0; pixelMask >>= 1) - // { - // screen[pixmapIndex++] = (int)(((pixelMask & pixelByte) != 0) ? foreground : background); - // //pixmapIndex += 2; - // tstate += tstatesperpixel; - // } - // } - - // /* Add 32 pixels of border colour to both pixel rows */ - - // for (x = bordersides; x-- > 0; pixmapIndex++) - // screen[pixmapIndex] = (int)GetBorderColor(tstate += tstatesperpixel); - - // /* Skip next pixel row as we have already filled it */ - - // //pixmapIndex += width; - - // /* Unless the next row is a multiple of 8, we need to rewind the attribute - // * pointer to the beginning of the pixel row. */ - - // if ((++y & 0x7) != 0) - // attributeIndex -= 32; - // } - - // /* Fill in bottom part of screen with border colour */ - - // for (x = Width * borderbottom; x-- > 0; ) - // screen[pixmapIndex++] = (int)GetBorderColor(tstate += tstatesperpixel); - - // border.Clear(); - // border.Add(new Border(LastBorderColor, 0)); - //} } diff --git a/ZXBox.Core/Snapshot/MemoryHandler.cs b/ZXBox.Core/Snapshot/MemoryHandler.cs index c2a013c..a98dda2 100644 --- a/ZXBox.Core/Snapshot/MemoryHandler.cs +++ b/ZXBox.Core/Snapshot/MemoryHandler.cs @@ -15,7 +15,7 @@ public static void LoadBytesintoMemory(Byte[] bytes, int ByteArrayStartIndex, in { for (int a = ByteArrayStartIndex; a < bytes.Length && MemoryStartIndex < bytes.Length; a++) { - cpu.WriteByteToMemory(MemoryStartIndex++, bytes[a]); + cpu.WriteByteToMemory((ushort)MemoryStartIndex++, bytes[a]); } } diff --git a/ZXBox.Core/Snapshot/SNAFileFormat.cs b/ZXBox.Core/Snapshot/SNAFileFormat.cs index a173736..9e3174f 100644 --- a/ZXBox.Core/Snapshot/SNAFileFormat.cs +++ b/ZXBox.Core/Snapshot/SNAFileFormat.cs @@ -24,19 +24,19 @@ public void LoadSnapshot(byte[] snapshotbytes, Zilog.Z80 cpu) //cpu.SP = (ushort)(snapshotbytes[23] + 256 * snapshotbytes[24]); cpu.I = snapshotbytes[0]; - cpu.HLPrim = snapshotbytes[1] | (snapshotbytes[2] << 8); - cpu.DEPrim = snapshotbytes[3] | (snapshotbytes[4] << 8); - cpu.BCPrim = snapshotbytes[5] | (snapshotbytes[6] << 8); - cpu.AFPrim = snapshotbytes[7] | (snapshotbytes[8] << 8); - cpu.HL = snapshotbytes[9] | (snapshotbytes[10] << 8); - cpu.DE = snapshotbytes[11] | (snapshotbytes[12] << 8); - cpu.BC = snapshotbytes[13] | (snapshotbytes[14] << 8); - cpu.IY = snapshotbytes[15] | (snapshotbytes[16] << 8); - cpu.IX = snapshotbytes[17] | (snapshotbytes[18] << 8); - cpu.IFF = cpu.IFF2 = ((snapshotbytes[19] & 0x04) == 0x04); + cpu.HLPrim = (ushort)(snapshotbytes[1] | (snapshotbytes[2] << 8)); + cpu.DEPrim = (ushort)(snapshotbytes[3] | (snapshotbytes[4] << 8)); + cpu.BCPrim = (ushort)(snapshotbytes[5] | (snapshotbytes[6] << 8)); + cpu.AFPrim = (ushort)(snapshotbytes[7] | (snapshotbytes[8] << 8)); + cpu.HL = (ushort)(snapshotbytes[9] | (snapshotbytes[10] << 8)); + cpu.DE = (ushort)(snapshotbytes[11] | (snapshotbytes[12] << 8)); + cpu.BC = (ushort)(snapshotbytes[13] | (snapshotbytes[14] << 8)); + cpu.IY = (ushort)(snapshotbytes[15] | (snapshotbytes[16] << 8)); + cpu.IX = (ushort)(snapshotbytes[17] | (snapshotbytes[18] << 8)); + cpu.IFF = cpu.IFF2 = (snapshotbytes[19] & 0x04) == 0x04; cpu.R = snapshotbytes[20]; - cpu.AF = snapshotbytes[21] | (snapshotbytes[22] << 8); - cpu.SP = snapshotbytes[23] | (snapshotbytes[24] << 8); + cpu.AF = (ushort)(snapshotbytes[21] | (snapshotbytes[22] << 8)); + cpu.SP = (ushort)(snapshotbytes[23] | (snapshotbytes[24] << 8)); cpu.IM = (byte)(snapshotbytes[25] & 0x03); if (cpu.IM > 2) { @@ -51,7 +51,7 @@ public void LoadSnapshot(byte[] snapshotbytes, Zilog.Z80 cpu) //Debug.WriteLine("Load PC:" + pc); //cpu.SP++; //cpu.SP++; - cpu.PC = pc; + cpu.PC = (ushort)pc; cpu.RET(true, 0, 0); } @@ -103,7 +103,7 @@ public byte[] SaveSnapshot(Zilog.Z80 cpu) for (int a = 0x4001; a < 64 * 1024; a++) { - snapshotData[mempos++] = (byte)cpu.ReadByteFromMemory(a); + snapshotData[mempos++] = (byte)cpu.ReadByteFromMemory((ushort)a); } //foreach (byte b in cpu.Memory.Skip(0x4000)) //{ diff --git a/ZXBox.Core/Snapshot/Z80FileFormat.cs b/ZXBox.Core/Snapshot/Z80FileFormat.cs index 99a277d..84d12fc 100644 --- a/ZXBox.Core/Snapshot/Z80FileFormat.cs +++ b/ZXBox.Core/Snapshot/Z80FileFormat.cs @@ -17,8 +17,8 @@ public void LoadSnapshot(byte[] snapshotbytes, Zilog.Z80 cpu) cpu.B = snapshotbytes[3]; cpu.L = snapshotbytes[4]; cpu.H = snapshotbytes[5]; - cpu.PC = (snapshotbytes[7] << 8) | snapshotbytes[6]; - cpu.SP = (snapshotbytes[9] << 8) | snapshotbytes[8]; + cpu.PC = (ushort)((snapshotbytes[7] << 8) | snapshotbytes[6]); + cpu.SP = (ushort)((snapshotbytes[9] << 8) | snapshotbytes[8]); cpu.I = snapshotbytes[10]; cpu.R = snapshotbytes[11]; @@ -54,8 +54,8 @@ public void LoadSnapshot(byte[] snapshotbytes, Zilog.Z80 cpu) cpu.APrim = snapshotbytes[21]; cpu.FPrim = snapshotbytes[22]; - cpu.IY = snapshotbytes[23] | (snapshotbytes[24] << 8); - cpu.IX = snapshotbytes[25] | (snapshotbytes[26] << 8); + cpu.IY = (ushort)(snapshotbytes[23] | (snapshotbytes[24] << 8)); + cpu.IX = (ushort)(snapshotbytes[25] | (snapshotbytes[26] << 8)); cpu.IFF = (snapshotbytes[27] != 0); cpu.IFF2 = (snapshotbytes[28] != 0); @@ -94,7 +94,7 @@ No need to read an support all of these. Most bytes in the extended section will be discarded since there are no support for them */ int numberofheaderbytes = snapshotbytes[snappshotposition++] | (snapshotbytes[snappshotposition++] << 8); - cpu.PC = (snapshotbytes[32]) | (snapshotbytes[33] << 8); + cpu.PC = (ushort)(snapshotbytes[32] | (snapshotbytes[33] << 8)); //The rest of the header information is not relevant for this emulator snappshotposition += numberofheaderbytes; @@ -160,7 +160,6 @@ No need to read an support all of these. case 5: //Normal c000-ffff MemoryHandler.LoadBytesintoMemory(mb.MemoryData.ToArray(), 0xc000, cpu); break; - break; //case 3: case 8: //Normal 4000-7ffff //Loaded from 3 diff --git a/ZXBox.Core/ZxSpectrum.cs b/ZXBox.Core/ZxSpectrum.cs index e731d32..7e54889 100644 --- a/ZXBox.Core/ZxSpectrum.cs +++ b/ZXBox.Core/ZxSpectrum.cs @@ -4,15 +4,15 @@ using ZXBox.Hardware.Output; namespace ZXBox; - + public class ZXSpectrum : Zilog.Z80 { public List Roms = new List { new byte[0x4000], new byte[0x4000] }; public List Banks = new List { new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000], new byte[0x4000] }; Screen speccyscreen; - byte[] romBytes; - + // byte[] romBytes; + public ZXSpectrum(bool renderBorder = true, bool loadRom = true, int borderTop = 48, int borderBottom = 56, int borderSide = 64, RomEnum rom = RomEnum.ZXSpectrum48k) { speccyscreen = new Screen(this, renderBorder, false, borderTop, borderBottom, borderSide); @@ -39,7 +39,7 @@ public void LoadRom(RomEnum rom) } } - uint[] screenints; + uint[] screenints; byte[] result; public byte[] GetScreenInBytes(bool flash) { @@ -66,32 +66,31 @@ public uint[] GetScreenInUint(bool flash) public List OutputHardware = new List(); public int bordercolor = 1; - int retvalue = 0xFF; int i = 0; - public override int In(int port) + public override byte In(ushort port) { - retvalue = 0xFF; + byte retvalue = 0xFF; for (i = 0; i < InputHardware.Count; i++) { retvalue &= InputHardware[i].Input(port, NumberOfTstates - Math.Abs(_numberOfTStatesLeft)); } return retvalue; } - public override void TstateChange(int diff) - { - for (i = 0; i < InputHardware.Count; i++) - { - InputHardware[i].AddTStates(diff); - } + public override void TstateChange(int diff) + { + for (i = 0; i < InputHardware.Count; i++) + { + InputHardware[i].AddTStates(diff); + } } int activescreen = 0; bool disablepaging = false; - public override void Out(int Port, int ByteValue, int tStates) + public override void Out(ushort Port, byte ByteValue, int tStates) { //128k if (Port == 0x7ffd) - { - bank = ByteValue & 0x03; + { + bank = ByteValue & 0x03; rom = (ByteValue >> 4) & 0x01; activescreen = (ByteValue >> 3) & 0x01; disablepaging = ((ByteValue >> 5) & 0x01) == 1; @@ -104,9 +103,8 @@ public override void Out(int Port, int ByteValue, int tStates) } int bank = 0; int rom = 0; - public override void WriteByteToMemory(int address, int bytetowrite) + public override void WriteByteToMemory(ushort address, byte bytetowrite) { - if (address < 0x4000) //rom { Roms[rom][address & 0xffff] = (byte)(bytetowrite & 0xff); @@ -135,19 +133,19 @@ public override void WriteByteToMemory(int address, int bytetowrite) if ((address & 0xffff) >= 0x5800 && (address & 0xffff) <= 0x5AFF) { - speccyscreen.SetAttribute(address, (((bytetowrite & 0x80) >> 7) & 0x01) == 1, (((bytetowrite & 0x40) >> 6) & 0x01) == 1, (bytetowrite & 0x07), (bytetowrite >> 3) & 0x07); - + speccyscreen.SetAttribute(address, (((bytetowrite & 0x80) >> 7) & 0x01) == 1, (((bytetowrite & 0x40) >> 6) & 0x01) == 1, (bytetowrite & 0x07), (bytetowrite >> 3) & 0x07); + } } - public override void WriteWordToMemory(int address, int word) + public override void WriteWordToMemory(ushort address, ushort word) { - WriteByteToMemory(address, word & 0xff); + WriteByteToMemory(address, (byte)(word & 0xff)); address++; - WriteByteToMemory(address, word >> 8); + WriteByteToMemory(address, (byte)(word >> 8)); } - public override int ReadByteFromMemory(int address) + public override byte ReadByteFromMemory(ushort address) { if (address < 0x4000) //rom { diff --git a/ZXBox.Meadow/MeadowApp.cs b/ZXBox.Meadow/MeadowApp.cs index a396d33..eba4e35 100644 --- a/ZXBox.Meadow/MeadowApp.cs +++ b/ZXBox.Meadow/MeadowApp.cs @@ -71,7 +71,7 @@ void RunEmulator() { try { - speccy.DoIntructions(69888*50); + speccy.DoInstructions(69888*50); Console.WriteLine("OnCycle"); var screen = speccy.GetScreenInUint(true); Console.WriteLine("Got screen"); diff --git a/ZXBox.Meadow/Z80/Z80.cs b/ZXBox.Meadow/Z80/Z80.cs index a6ec879..5f2c260 100644 --- a/ZXBox.Meadow/Z80/Z80.cs +++ b/ZXBox.Meadow/Z80/Z80.cs @@ -9,7 +9,7 @@ public abstract partial class Z80 { - public void WriteByteToMemoryOverridden(int address, int b) + public void WriteByteToMemoryOverridden(ushort address, byte b) { this.WriteByteToMemory(address, b); } @@ -117,97 +117,97 @@ public int IY //Interrupt Register public int I=0; - public int[] Registers=new int[10]; + public byte[] Registers=new byte[10]; //Registers Prim - public int[] RegitersPrim=new int[10]; - public int Fprim=0; + public byte[] RegitersPrim=new byte[10]; + public byte Fprim=0; //8bit - public int A + public byte A { get { return Registers[R_A]; } set { Registers[R_A] = value; } } - public int B + public byte B { get { return Registers[R_B]; } set { Registers[R_B] = value; } } - public int C + public byte C { get { return Registers[R_C]; } set { Registers[R_C] = value; } } - public int D + public byte D { get { return Registers[R_D]; } set { Registers[R_D] = value; } } - public int E + public byte E { get { return Registers[R_E]; } set { Registers[R_E] = value; } } - public int H + public byte H { get { return Registers[R_H]; } set { Registers[R_H] = value; } } - public int L + public byte L { get { return Registers[R_L]; } set { Registers[R_L] = value; } } - public int APrim + public byte APrim { get { return RegitersPrim[R_A]; } set { RegitersPrim[R_A] = value; } } - public int BPrim + public byte BPrim { get { return RegitersPrim[R_B]; } set { RegitersPrim[R_B] = value; } } - public int CPrim + public byte CPrim { get { return RegitersPrim[R_C]; } set { RegitersPrim[R_C] = value; } } - public int DPrim + public byte DPrim { get { return RegitersPrim[R_D]; } set { RegitersPrim[R_D] = value; } } - public int EPrim + public byte EPrim { get { return RegitersPrim[R_E]; } set { RegitersPrim[R_E] = value; } } - public int HPrim + public byte HPrim { get { return RegitersPrim[R_H]; } set { RegitersPrim[R_H] = value; } } - public int LPrim + public byte LPrim { get { return RegitersPrim[R_L]; } set { RegitersPrim[R_L] = value; } } - public int FPrim + public byte FPrim { get { return Fprim; } set { Fprim = value; } @@ -215,7 +215,7 @@ public int FPrim //16 bit - public int HL + public ushort HL { get { @@ -234,7 +234,7 @@ public int HL } } - public int HLPrim + public ushort HLPrim { get { @@ -248,7 +248,7 @@ public int HLPrim } - public int DE + public ushort DE { get { @@ -261,7 +261,7 @@ public int DE } } - public int DEPrim + public ushort DEPrim { get { @@ -275,7 +275,7 @@ public int DEPrim } - public int BC + public ushort BC { get { @@ -288,7 +288,7 @@ public int BC } } - public int BCPrim + public ushort BCPrim { get { @@ -301,7 +301,7 @@ public int BCPrim } } - public int AF + public ushort AF { get { @@ -314,7 +314,7 @@ public int AF } } - public int AFPrim + public ushort AFPrim { get { @@ -327,25 +327,25 @@ public int AFPrim } } - public int IXL + public byte IXL { get {return IX & 0xff;} set { IX=(IX & 0xff00) | (value); } } - public int IXH + public byte IXH { get { return (IX >> 8) & 0xff; } set { IX = (IX & 0xff) | (value << 8); } } - public int IYL + public byte IYL { get { return IY & 0xff; } set { IY = (IY & 0xff00) | (value); } } - public int IYH + public byte IYH { get { return (IY >> 8) & 0xff; } set { IY = (IY & 0xff) | (value << 8); } @@ -384,28 +384,28 @@ public void PCFromStack() PC = StackpopWord(); } - private int GetNextPCByte() + private byte GetNextPCByte() { - int b = ReadByteFromMemory(PC); + byte b = ReadByteFromMemory(PC); PC = PC+1 & 0xffff; return b; } - private int GetNextPCWord() + private ushort GetNextPCWord() { - int w = ReadByteFromMemory(PC++); + ushort w = ReadByteFromMemory(PC++); w |= (ReadByteFromMemory(PC++ & 0xffff) << 8); return w; } #endregion #region Stack - public void StackpushWord(int word) + public void StackpushWord(ushort word) { int sp = ((SP - 2) & 0xffff); SP=sp; WriteWordToMemory(sp, word); } - public int StackpopWord() + public ushort StackpopWord() { int w = ReadByteFromMemory(SP); SP++; @@ -416,16 +416,16 @@ public int StackpopWord() #endregion #region Memory - public abstract void WriteWordToMemory(int address, int word); + public abstract void WriteWordToMemory(ushort address, ushort word); - public abstract void WriteByteToMemory(int address, int bytetowrite); + public abstract void WriteByteToMemory(ushort address, byte bytetowrite); - public abstract int ReadByteFromMemory(int address); + public abstract byte ReadByteFromMemory(ushort address); - public int ReadWordFromMemory(int address) + public ushort ReadWordFromMemory(ushort address) { return (ReadByteFromMemory(address+1 & 0xffff) << 8 | ReadByteFromMemory(address & 0xffff)) & 0xffff; } @@ -554,12 +554,12 @@ public int interrupt() public int NumberOfTstates = 0; public StringBuilder sb = new StringBuilder(); private DateTime start; - public void DoIntructions(int numberOfTStates) + public void DoInstructions(int numberOfTStates) { - DoIntructions(numberOfTStates, null); + DoInstructions(numberOfTStates, null); } - public void DoIntructions(int numberOfTStates, Func gameSpecificFunc) + public void DoInstructions(int numberOfTStates, Func gameSpecificFunc) { //sb = new StringBuilder(); NumberOfTstates = numberOfTStates;