Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "Run DesktopGL platform",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "buildDesktopGL",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Platforms/ZXBox.Monogame/bin/Debug/net10.0/ZXBox.Monogame.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.exclude": {
"**/bin": true,
"**/obj": true
}
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "buildDesktopGL",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Platforms/ZXBox.Monogame/ZXBox.Monogame.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
6 changes: 4 additions & 2 deletions Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
Expand All @@ -23,6 +24,7 @@

namespace ZXBox.Blazor.Pages
{
[SupportedOSPlatform("browser")]
public partial class EmulatorComponentModel : ComponentBase, IAsyncDisposable
{
private const float BeeperMixGain = 0.45f;
Expand Down Expand Up @@ -245,7 +247,7 @@

}

private async Task<byte[]?> TryLoadAssetAsync(string assetPath)

Check warning on line 250 in Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
using var response = await httpClient.GetAsync(assetPath);

Expand All @@ -272,10 +274,10 @@
//Get gamepads
kempston.Gamepads = await GamePadList.GetGamepadsAsync();
//Run JavaScriptInterop to find the currently pressed buttons
Keyboard.KeyBuffer = await JSRuntime.InvokeAsync<List<string>>("getKeyStatus");
Keyboard.SetKeyBuffer(await JSRuntime.InvokeAsync<List<string>>("getKeyStatus"));
sw.Start();
var frameTStates = speccy.FrameTStates;
speccy.DoIntructions(frameTStates);
speccy.DoInstructions(frameTStates);

beeper.GenerateSound(frameTStates);
await BufferSound();
Expand All @@ -301,8 +303,8 @@
}
bool TapeStopped = false;
private int _frameInProgress;
GCHandle gchsound;

Check warning on line 306 in Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs

View workflow job for this annotation

GitHub Actions / build

The field 'EmulatorComponentModel.gchsound' is never used
IntPtr pinnedsound;

Check warning on line 307 in Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs

View workflow job for this annotation

GitHub Actions / build

The field 'EmulatorComponentModel.pinnedsound' is never used
WebAssemblyJSRuntime mono;
float[] soundbytes;

Expand Down Expand Up @@ -372,8 +374,8 @@
base.OnAfterRender(firstRender);
}

GCHandle gchscreen;

Check warning on line 377 in Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs

View workflow job for this annotation

GitHub Actions / build

The field 'EmulatorComponentModel.gchscreen' is never used
IntPtr pinnedscreen;

Check warning on line 378 in Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs

View workflow job for this annotation

GitHub Actions / build

The field 'EmulatorComponentModel.pinnedscreen' is never used

uint[] screen = new uint[68672]; //Height * width (256+20+20)*(192+20+20)
public async void Paint()
Expand Down Expand Up @@ -555,7 +557,7 @@

using var paint = new SKPaint
{
FilterQuality = SKFilterQuality.None,

Check warning on line 560 in Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs

View workflow job for this annotation

GitHub Actions / build

'SKFilterQuality' is obsolete: 'Use SKSamplingOptions instead.'

Check warning on line 560 in Platforms/ZXBox.Blazor/Components/EmulatorComponent.razor.cs

View workflow job for this annotation

GitHub Actions / build

'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
IsAntialias = false
};

Expand Down
18 changes: 12 additions & 6 deletions Platforms/ZXBox.Blazor/Hardware/Kempston.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Toolbelt.Blazor.Gamepad;
using ZXBox.Hardware.Interfaces;
Expand All @@ -11,7 +10,7 @@ namespace ZXBox.Hardware.Input.Joystick
/// <summary>
/// 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
/// </summary>

public class Kempston:IInput
Expand All @@ -38,21 +37,28 @@ 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;

this.Gamepad = Gamepads.FirstOrDefault();
if (Gamepads == null || Gamepads.Count == 0)
{
return returnvalue;
}

this.Gamepad = Gamepads[0];
if (Gamepad == null)
{
return returnvalue;
}
//GamePadState currentState = GamePad.GetState(playerIndex);
//000FUDLR
if (Gamepad.Buttons.Count() > 0)
if (Gamepad.Buttons.Count > 0)
{
if (Gamepad.Buttons[0].Pressed)
returnvalue |= 16;
Expand Down
29 changes: 20 additions & 9 deletions Platforms/ZXBox.Blazor/Hardware/Keyboard.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
//using Microsoft.Xna.Framework.Input;
Expand All @@ -10,8 +9,9 @@
{
public class JavaScriptKeyboard : IInput
{
public List<string> KeyBuffer = new List<string>();
private readonly HashSet<string> _pressedKeys = new(StringComparer.OrdinalIgnoreCase);
public IReadOnlyCollection<string> KeyBuffer { get; private set; } = Array.Empty<string>();
int NoKeyCounter = 0;

Check warning on line 14 in Platforms/ZXBox.Blazor/Hardware/Keyboard.cs

View workflow job for this annotation

GitHub Actions / build

The field 'JavaScriptKeyboard.NoKeyCounter' is assigned but its value is never used
bool SymbolShift = false;
int sectionnumber = 1;
bool up = false;
Expand All @@ -21,12 +21,24 @@
bool fire = false;
public JoystickTypeEnum JoystickType { get; set; }

public void SetKeyBuffer(IReadOnlyCollection<string> keys)
{
KeyBuffer = keys;
_pressedKeys.Clear();
foreach (var key in keys)
{
_pressedKeys.Add(key);
}
}

public bool GetKeyStatus(string key)
{
return KeyBuffer.Any(k => k.ToLower() == key.ToLower());
return _pressedKeys.Contains(key);
}

public int Input(int Port, int tstates)
public void AddTStates(int tstates) { }

public byte Input(ushort Port, int tstates)
{

if ((Port & 0xFF) == 0xFE)
Expand Down Expand Up @@ -57,16 +69,15 @@
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)
{ //Check for any key including joy, we might need to add more joy buttons later on

if (KeyBuffer.Count() > 0)
if (KeyBuffer.Count > 0)
{
return returnvalue &= ~1;
return (byte)(returnvalue &= ~1);
}

}
Expand Down Expand Up @@ -197,7 +208,7 @@
break;
}

return returnvalue;
return (byte)returnvalue;
}
return 0xFF;
}
Expand Down
15 changes: 9 additions & 6 deletions Platforms/ZXBox.Blazor/ZXBox.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<RunAOTCompilation>true</RunAOTCompilation>
<OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
<RunAOTCompilation>true</RunAOTCompilation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand All @@ -11,12 +12,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.8" PrivateAssets="all" />
<PackageReference Include="SkiaSharp.Views.Blazor" Version="3.119.1" />

<PackageReference Include="System.Net.Http.Json" Version="10.0.0" />
<PackageReference Include="Toolbelt.Blazor.Gamepad" Version="9.0.0" />
<PackageReference Include="Toolbelt.Blazor.Gamepad" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
<StaticWebAssetFingerprintPattern Include="JavaScript" Pattern="JavaScript.js" Expression="#[.{fingerprint}]!" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions Platforms/ZXBox.Blazor/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>ZX Spectrum emulator running on Blazor</title>
<base href="/" />
<link rel="preload" id="webassembly" />
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/app.css" rel="stylesheet" />
<link href="ZXBox.Blazor.styles.css" rel="stylesheet" />
<script type="importmap"></script>
</head>

<body>
<script>
window.Toolbelt = window.Toolbelt || {};
window.Toolbelt.Blazor = window.Toolbelt.Blazor || {};
window.Toolbelt.Blazor.getProperty = function (path) {
return path
.replace(/^window\./, '')
.split('.')
.reduce(function (target, part) {
return target == null ? target : target[part];
}, window);
};

// Variables
var nextStartTime = 0;
var buffersize = 960;
Expand Down Expand Up @@ -141,8 +154,8 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="JavaScript.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
<script src="JavaScript#[.{fingerprint}].js"></script>
<script src="_framework/blazor.webassembly#[.{fingerprint}].js"></script>

</body>

Expand Down
20 changes: 20 additions & 0 deletions Platforms/ZXBox.Monogame/Hardware/JoystickFake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using ZXBox.Hardware.Interfaces;

namespace ZXBox.Monogame.Hardware
{
public class JoystickFake : ZXBox.Hardware.Interfaces.IInput
{
public byte Input(ushort Port, int tact)
{
byte returnvalue = 0xFF;
if ((Port & 0xff) == 0x1f)
{
returnvalue = 0x0;
}
return returnvalue;
}

public void AddTStates(int tstates) { }
}
}
Loading
Loading