-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* C64 Skia (native & WASM): Fix rendering of multicolor text colors. * C64 specific config options for Silk.NET input handling. More stable ImGui modal popup dialog. * Fix precision issue with C64 CIA timer * Improve C64 VIC2 perf * Change C64 CIA timer code to use executed CPU cyles instead of C# timer for timing. * C64: Fix extend textmode bug * WASM C64 joystick configuration UI.
- Loading branch information
Showing
43 changed files
with
1,082 additions
and
644 deletions.
There are no files selected for viewing
214 changes: 111 additions & 103 deletions
214
src/apps/Highbyte.DotNet6502.App.SkiaNative/ConfigUI/SilkNetImGuiC64Config.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,156 @@ | ||
using System.Diagnostics; | ||
using System.Numerics; | ||
using Highbyte.DotNet6502.Impl.SilkNet.Commodore64.Input; | ||
using Highbyte.DotNet6502.App.SkiaNative.SystemSetup; | ||
using Highbyte.DotNet6502.Systems.Commodore64.Config; | ||
using Highbyte.DotNet6502.Systems.Commodore64.TimerAndPeripheral; | ||
|
||
namespace Highbyte.DotNet6502.App.SkiaNative.ConfigUI; | ||
|
||
public class SilkNetImGuiC64Config | ||
{ | ||
private C64Config? _config; | ||
public C64Config UpdatedConfig => _config!; | ||
private readonly SilkNetImGuiMenu _mainMenu; | ||
C64Config _config => (C64Config)_mainMenu.GetSelectedSystemConfig(); | ||
C64HostConfig _hostConfig => (C64HostConfig)_mainMenu.GetSelectedSystemHostConfig(); | ||
|
||
|
||
private string? _romDirectory; | ||
private string? _kernalRomFile; | ||
private string? _basicRomFile; | ||
private string? _chargenRomFile; | ||
|
||
public bool Visible { get; set; } | ||
public bool Ok { get; set; } | ||
public bool Cancel { get; set; } | ||
|
||
private bool _isValidConfig = true; | ||
private bool _open; | ||
|
||
public bool IsValidConfig => _isValidConfig; | ||
private List<string>? _validationErrors; | ||
public bool IsValidConfig | ||
{ | ||
get | ||
{ | ||
if (_config == null) | ||
{ | ||
_validationErrors.Clear(); | ||
return true; | ||
} | ||
else | ||
{ | ||
return _config.IsValid(out _validationErrors); | ||
} | ||
} | ||
} | ||
private List<string> _validationErrors = new(); | ||
|
||
private const int POS_X = 50; | ||
private const int POS_Y = 50; | ||
private const int WIDTH = 400; | ||
private const int HEIGHT = 550; | ||
//private static Vector4 s_informationColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); | ||
private static Vector4 s_errorColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f); | ||
//private static Vector4 s_warningColor = new Vector4(0.5f, 0.8f, 0.8f, 1); | ||
private static Vector4 s_okButtonColor = new Vector4(0.0f, 0.6f, 0.0f, 1.0f); | ||
|
||
public SilkNetImGuiC64Config() | ||
public SilkNetImGuiC64Config(SilkNetImGuiMenu mainMenu) | ||
{ | ||
_mainMenu = mainMenu; | ||
} | ||
|
||
internal void Init(C64Config c64Config) | ||
internal void Init() | ||
{ | ||
_config = c64Config.Clone(); | ||
_isValidConfig = _config.IsValid(out _validationErrors); | ||
|
||
_romDirectory = _config.ROMDirectory; | ||
_kernalRomFile = _config.HasROM(C64Config.KERNAL_ROM_NAME) ? _config.GetROM(C64Config.KERNAL_ROM_NAME).File! : ""; | ||
_basicRomFile = _config.HasROM(C64Config.KERNAL_ROM_NAME) ? _config.GetROM(C64Config.BASIC_ROM_NAME).File! : ""; | ||
_chargenRomFile = _config.HasROM(C64Config.KERNAL_ROM_NAME) ? _config.GetROM(C64Config.CHARGEN_ROM_NAME).File! : ""; | ||
|
||
Visible = true; | ||
|
||
} | ||
|
||
public void Reset(C64Config c64Config) | ||
public void PostOnRender(string dialogLabel) | ||
{ | ||
_config = c64Config; | ||
_isValidConfig = _config!.IsValid(out _validationErrors); | ||
|
||
Visible = false; | ||
Cancel = false; | ||
Ok = false; | ||
} | ||
_open = true; | ||
if (ImGui.BeginPopupModal(dialogLabel, ref _open, ImGuiWindowFlags.AlwaysAutoResize)) | ||
{ | ||
ImGui.Text("C64 model"); | ||
ImGui.LabelText("C64 model", $"{_config!.C64Model}"); | ||
ImGui.LabelText("VIC2 model", $"{_config!.Vic2Model}"); | ||
|
||
public void PostOnRender() | ||
{ | ||
ImGui.SetNextWindowSize(new Vector2(WIDTH, HEIGHT), ImGuiCond.Once); | ||
ImGui.SetNextWindowPos(new Vector2(POS_X, POS_Y), ImGuiCond.Once); | ||
ImGui.SetNextWindowFocus(); | ||
ImGui.Text("ROMs"); | ||
if (ImGui.InputText("Directory", ref _romDirectory, 255)) | ||
{ | ||
_config!.ROMDirectory = _romDirectory; | ||
} | ||
if (ImGui.InputText("Kernal file", ref _kernalRomFile, 100)) | ||
{ | ||
_config!.SetROM(C64Config.KERNAL_ROM_NAME, _kernalRomFile); | ||
} | ||
if (ImGui.InputText("Basic file", ref _basicRomFile, 100)) | ||
{ | ||
_config!.SetROM(C64Config.BASIC_ROM_NAME, _basicRomFile); | ||
} | ||
if (ImGui.InputText("CharGen file", ref _chargenRomFile, 100)) | ||
{ | ||
_config!.SetROM(C64Config.CHARGEN_ROM_NAME, _chargenRomFile); | ||
} | ||
|
||
ImGui.Begin($"C64 config"); | ||
//ImGui.BeginPopupModal($"C64 config"); | ||
// Joystick | ||
ImGui.Text("Joystick:"); | ||
ImGui.SameLine(); | ||
ImGui.PushItemWidth(35); | ||
if (ImGui.Combo("##joystick", ref _mainMenu.C64SelectedJoystick, _mainMenu.C64AvailableJoysticks, _mainMenu.C64AvailableJoysticks.Length)) | ||
{ | ||
_hostConfig.InputConfig.CurrentJoystick = _mainMenu.C64SelectedJoystick + 1; | ||
} | ||
ImGui.PopItemWidth(); | ||
|
||
ImGui.Text("C64 model"); | ||
ImGui.LabelText("C64 model", $"{_config!.C64Model}"); | ||
ImGui.LabelText("VIC2 model", $"{_config!.Vic2Model}"); | ||
ImGui.BeginDisabled(disabled: true); | ||
foreach (var mapKey in _hostConfig.InputConfig.GamePadToC64JoystickMap[_hostConfig.InputConfig.CurrentJoystick]) | ||
{ | ||
ImGui.LabelText($"{string.Join(",", mapKey.Key)}", $"{string.Join(",", mapKey.Value)}"); | ||
} | ||
ImGui.EndDisabled(); | ||
|
||
ImGui.Text("ROMs"); | ||
if (ImGui.InputText("Directory", ref _romDirectory, 255)) | ||
{ | ||
_config!.ROMDirectory = _romDirectory; | ||
} | ||
if (ImGui.InputText("Kernal file", ref _kernalRomFile, 100)) | ||
{ | ||
_config!.SetROM(C64Config.KERNAL_ROM_NAME, _kernalRomFile); | ||
} | ||
if (ImGui.InputText("Basic file", ref _basicRomFile, 100)) | ||
{ | ||
_config!.SetROM(C64Config.BASIC_ROM_NAME, _basicRomFile); | ||
} | ||
if (ImGui.InputText("CharGen file", ref _chargenRomFile, 100)) | ||
{ | ||
_config!.SetROM(C64Config.CHARGEN_ROM_NAME, _chargenRomFile); | ||
} | ||
// Keyboard joystick | ||
ImGui.Text($"Keyboard Joystick"); | ||
ImGui.SameLine(); | ||
ImGui.PushItemWidth(35); | ||
if (ImGui.Combo("##keyboardJoystick", ref _mainMenu.C64KeyboardJoystick, _mainMenu.C64AvailableJoysticks, _mainMenu.C64AvailableJoysticks.Length)) | ||
{ | ||
_config.KeyboardJoystick = _mainMenu.C64KeyboardJoystick + 1; | ||
} | ||
ImGui.PopItemWidth(); | ||
var keyToJoystickMap = _config!.KeyboardJoystickMap; | ||
ImGui.BeginDisabled(disabled: true); | ||
foreach (var mapKey in keyToJoystickMap.GetMap(_config.KeyboardJoystick)) | ||
{ | ||
ImGui.LabelText($"{string.Join(",", mapKey.Key)}", $"{string.Join(",", mapKey.Value)}"); | ||
} | ||
ImGui.EndDisabled(); | ||
|
||
int joystick = 2; | ||
ImGui.Text($"Joystick {joystick}"); | ||
ImGui.BeginDisabled(disabled: true); | ||
foreach (var mapKey in C64SilkNetGamepad.SilkNetGamePadToC64JoystickMap) | ||
{ | ||
ImGui.LabelText($"{string.Join(",", mapKey.Key)}", $"{string.Join(",", mapKey.Value)}"); | ||
} | ||
ImGui.EndDisabled(); | ||
// Update validation fields | ||
if (_config!.IsDirty) | ||
{ | ||
_config.ClearDirty(); | ||
} | ||
if (!IsValidConfig) | ||
{ | ||
ImGui.PushStyleColor(ImGuiCol.Text, s_errorColor); | ||
foreach (var error in _validationErrors!) | ||
{ | ||
ImGui.TextWrapped($"Error: {error}"); | ||
} | ||
ImGui.PopStyleColor(); | ||
} | ||
|
||
ImGui.Text($"Keyboard Joystick {joystick}"); | ||
var keyToJoystickMap = _config!.KeyboardJoystickMap; | ||
ImGui.BeginDisabled(disabled: true); | ||
foreach (var mapKey in keyToJoystickMap.GetMap(joystick)) | ||
{ | ||
ImGui.LabelText($"{string.Join(",", mapKey.Key)}", $"{string.Join(",", mapKey.Value)}"); | ||
} | ||
ImGui.EndDisabled(); | ||
// Close buttons | ||
if (ImGui.Button("Cancel")) | ||
{ | ||
Debug.WriteLine("Cancel pressed"); | ||
ImGui.CloseCurrentPopup(); | ||
_mainMenu.RestoreOriginalConfigs(); | ||
} | ||
|
||
if (_config!.IsDirty) | ||
{ | ||
_config.ClearDirty(); | ||
_isValidConfig = _config!.IsValid(out _validationErrors); | ||
} | ||
if (!_isValidConfig) | ||
{ | ||
ImGui.PushStyleColor(ImGuiCol.Text, s_errorColor); | ||
foreach (var error in _validationErrors!) | ||
ImGui.SameLine(); | ||
ImGui.BeginDisabled(disabled: !IsValidConfig); | ||
ImGui.PushStyleColor(ImGuiCol.Button, s_okButtonColor); | ||
if (ImGui.Button("Ok")) | ||
{ | ||
ImGui.TextWrapped($"Error: {error}"); | ||
Debug.WriteLine("Ok pressed"); | ||
ImGui.CloseCurrentPopup(); | ||
_mainMenu.UpdateCurrentSystemConfig(_config, _hostConfig); | ||
} | ||
ImGui.PopStyleColor(); | ||
} | ||
ImGui.EndDisabled(); | ||
|
||
if (ImGui.Button("Cancel")) | ||
{ | ||
Visible = false; | ||
Cancel = true; | ||
ImGui.EndPopup(); | ||
} | ||
|
||
ImGui.SameLine(); | ||
ImGui.BeginDisabled(disabled: !_isValidConfig); | ||
ImGui.PushStyleColor(ImGuiCol.Button, s_okButtonColor); | ||
if (ImGui.Button("Ok")) | ||
{ | ||
Visible = false; | ||
Ok = true; | ||
} | ||
ImGui.PopStyleColor(); | ||
ImGui.EndDisabled(); | ||
|
||
//ImGui.EndPopup(); | ||
ImGui.End(); | ||
} | ||
} |
Oops, something went wrong.