Skip to content

Commit

Permalink
Misc. fixes (#121)
Browse files Browse the repository at this point in the history
* Fix C64 keyboard joytstick config bug.

* Cleanup.
  • Loading branch information
highbyte authored Oct 5, 2024
1 parent ae07120 commit e7894ea
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@ Label CreateLabel(string text, int col, int row, string? name = null)
Controls.Add(labelTemp);
return labelTemp;
}
Label CreateLabelValue(string text, int col, int row, string? name = null)
{
var labelTemp = new Label(text) { Position = new Point(col, row), TextColor = Controls.GetThemeColors().Title, Name = name };
Controls.Add(labelTemp);
return labelTemp;
}

// Force OnIsDirtyChanged event which will set control states (see SetControlStates)
OnIsDirtyChanged();
Expand All @@ -272,7 +266,7 @@ private void ShowROMFilePickerDialog(string romName)
{
if (window.DialogResult)
{
C64SystemConfig.SetROM(romName, Path.GetFileName(window.SelectedFile.FullName));
C64SystemConfig.SetROM(romName, Path.GetFileName(window.SelectedFile!.FullName));
IsDirty = true;
}
};
Expand Down Expand Up @@ -308,15 +302,15 @@ private void SetControlStates()
romDirectoryTextBox!.IsDirty = true;

var kernalROMTextBox = Controls["kernalROMTextBox"] as TextBox;
kernalROMTextBox!.Text = C64SystemConfig.ROMs.SingleOrDefault(x => x.Name == C64SystemConfig.KERNAL_ROM_NAME).File;
kernalROMTextBox!.Text = C64SystemConfig.ROMs.Single(x => x.Name == C64SystemConfig.KERNAL_ROM_NAME).File!;
kernalROMTextBox!.IsDirty = true;

var basicROMTextBox = Controls["basicROMTextBox"] as TextBox;
basicROMTextBox!.Text = C64SystemConfig.ROMs.SingleOrDefault(x => x.Name == C64SystemConfig.BASIC_ROM_NAME).File;
basicROMTextBox!.Text = C64SystemConfig.ROMs.Single(x => x.Name == C64SystemConfig.BASIC_ROM_NAME).File!;
basicROMTextBox!.IsDirty = true;

var chargenROMTextBox = Controls["chargenROMTextBox"] as TextBox;
chargenROMTextBox!.Text = C64SystemConfig.ROMs.SingleOrDefault(x => x.Name == C64SystemConfig.CHARGEN_ROM_NAME).File;
chargenROMTextBox!.Text = C64SystemConfig.ROMs.Single(x => x.Name == C64SystemConfig.CHARGEN_ROM_NAME).File!;
chargenROMTextBox!.IsDirty = true;

var codingAssistantTestButton = Controls["codingAssistantTestButton"] as Button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void DrawUIItems()
Name = "c64CopyBasicSourceCodeButton",
Position = (1, c64SaveBasicButton.Bounds.MaxExtentY + 2),
};
c64CopyBasicSourceCodeButton.Click += C64CopyBasicSourceCodeButton_Click;
c64CopyBasicSourceCodeButton.Click += C64CopyBasicSourceCodeButton_Click!;
Controls.Add(c64CopyBasicSourceCodeButton);

// Paste
Expand All @@ -85,7 +85,7 @@ private void DrawUIItems()
Name = "c64PasteTextButton",
Position = (c64CopyBasicSourceCodeButton.Bounds.MaxExtentX + 9, c64CopyBasicSourceCodeButton.Position.Y),
};
c64PasteTextButton.Click += C64PasteTextButton_Click;
c64PasteTextButton.Click += C64PasteTextButton_Click!;
Controls.Add(c64PasteTextButton);

// Paste
Expand All @@ -106,20 +106,14 @@ private void DrawUIItems()
Name = "c64ConfigButton",
Position = (1, c64aiBasicAssistantCheckbox.Bounds.MaxExtentY + 2),
};
c64ConfigButton.Click += C64ConfigButton_Click;
c64ConfigButton.Click += C64ConfigButton_Click!;
Controls.Add(c64ConfigButton);


var validationMessageValueLabel = CreateLabelValue(new string(' ', 20), 1, c64ConfigButton.Bounds.MaxExtentY + 2, "validationMessageValueLabel");
validationMessageValueLabel.TextColor = Controls.GetThemeColors().Red;

// Helper function to create a label and add it to the console
Label CreateLabel(string text, int col, int row, string? name = null)
{
var labelTemp = new Label(text) { Position = new Point(col, row), Name = name };
Controls.Add(labelTemp);
return labelTemp;
}
Label CreateLabelValue(string text, int col, int row, string? name = null)
{
var labelTemp = new Label(text) { Position = new Point(col, row), TextColor = Controls.GetThemeColors().Title, Name = name };
Expand Down Expand Up @@ -148,9 +142,9 @@ private void C64LoadBasicButton_Click(object? sender, EventArgs e)
{
try
{
var fileName = window.SelectedFile.FullName;
var fileName = window.SelectedFile!.FullName;
BinaryLoader.Load(
_sadConsoleHostApp.CurrentRunningSystem.Mem,
_sadConsoleHostApp.CurrentRunningSystem!.Mem,
fileName,
out ushort loadedAtAddress,
out ushort fileLength);
Expand Down Expand Up @@ -200,7 +194,7 @@ private void C64SaveBasicButton_Click(object? sender, EventArgs e)
var fileName = window.SelectedFile.FullName;

Check warning on line 194 in src/apps/Highbyte.DotNet6502.App.SadConsole/ConfigUI/C64MenuConsole.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
// TODO: Does FilePickerConsole check if file already exists and ask for overwrite? Or do this here?
ushort startAddressValue = C64.BASIC_LOAD_ADDRESS;
var endAddressValue = ((C64)_sadConsoleHostApp.CurrentRunningSystem).GetBasicProgramEndAddress();
var endAddressValue = ((C64)_sadConsoleHostApp.CurrentRunningSystem!).GetBasicProgramEndAddress();
BinarySaver.Save(
_sadConsoleHostApp.CurrentRunningSystem.Mem,
fileName,
Expand Down Expand Up @@ -300,10 +294,11 @@ private void SetControlStates()
validationMessageValueLabel!.IsVisible = !isOk;
}

public async Task ToggleBasicAIAssistant()
public Task ToggleBasicAIAssistant()
{
var c64aiBasicAssistantCheckbox = Controls["c64aiBasicAssistantCheckbox"] as CheckBox;
c64aiBasicAssistantCheckbox.IsSelected = !c64aiBasicAssistantCheckbox.IsSelected;
return Task.CompletedTask;
}

private async Task SetBasicAIAssistant(bool enabled)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.IO;
using SadConsole.UI;
using SadConsole.UI.Controls;

Expand Down Expand Up @@ -166,7 +165,7 @@ private void FileListBox_SelectedItemChanged(object? sender, ListBox.SelectedIte
_selectedDirectory = new DirectoryInfo(fileListBox.CurrentFolder);

Check warning on line 165 in src/apps/Highbyte.DotNet6502.App.SadConsole/FilePickerConsole.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'path' in 'DirectoryInfo.DirectoryInfo(string path)'.
if (_filePickerMode == FilePickerMode.OpenFile || _filePickerMode == FilePickerMode.SaveFile)
{
if (_selectedFile != null && _selectedDirectory.FullName != _selectedFile.Directory.FullName)
if (_selectedFile != null && _selectedDirectory.FullName != _selectedFile.Directory!.FullName)
_selectedFile = new FileInfo(Path.Combine(_selectedDirectory.FullName, _selectedFile.Name));
}
else
Expand All @@ -176,8 +175,8 @@ private void FileListBox_SelectedItemChanged(object? sender, ListBox.SelectedIte
//selectedItemTextBox.IsDirty = true;
}
}

}

if (e.Item is DirectoryInfo directoryInfo)
{
//Debug.WriteLine($"DirectoryInfo: {directoryInfo.FullName}");
Expand All @@ -203,7 +202,7 @@ private void FileListBox_SelectedItemChanged(object? sender, ListBox.SelectedIte
return;

_selectedFile = fileInfo;
_selectedDirectory = fileInfo.Directory;
_selectedDirectory = fileInfo.Directory!;

selectedItemTextBox.Text = _selectedFile.Name;
selectedItemTextBox.IsDirty = true;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/Highbyte.DotNet6502.App.SadConsole/InfoConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Label CreateLabel(string text, int col, int row, string? name = null)
// System debug info panel
Panel debugInfoPanel = new Panel(10, 10);
{
var labelTitleLength = 25;
var labelTitleLength = 28;
_debugInfoLabels = new List<Label>();
_debugInfoLabelValues = new List<Label>();

Expand Down
4 changes: 0 additions & 4 deletions src/apps/Highbyte.DotNet6502.App.SadConsole/MonitorConsole.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Highbyte.DotNet6502.Monitor;
using SadConsole.Components;
using SadConsole.UI.Controls;
using SadRogue.Primitives;
using Console = SadConsole.Console;

Expand All @@ -19,9 +18,6 @@ internal class MonitorConsole : Console
public SadConsoleMonitor Monitor => _monitor;
private readonly ClassicConsoleKeyboardHandler _keyboardHandlerObject;

private Label _processorStatusLabel;
private List<Label> _sysInfoLabels;

/// <summary>
/// Console to display the monitor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Highbyte.DotNet6502.Systems;
using Highbyte.DotNet6502.Utils;
using SadConsole.UI;
using SadRogue.Primitives;
Expand All @@ -13,10 +12,8 @@ internal class MonitorStatusConsole : ControlsConsole

private readonly SadConsoleHostApp _sadConsoleHostApp;

public event EventHandler<bool>? MonitorStateChange;

private const int NUMBER_OF_SYS_INFO_ROWS = USABLE_HEIGHT - 1; // 1 row for CPU state
private string _emptyRow = new string(' ', USABLE_WIDTH);
private readonly string _emptyRow = new string(' ', USABLE_WIDTH);


/// <summary>
Expand Down
24 changes: 12 additions & 12 deletions src/apps/Highbyte.DotNet6502.App.SadConsole/SadConsoleHostApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private IScreenObject CreateMainSadConsoleScreen(GameHost gameHost)
// Position monitor to the right of the emulator console
_monitorConsole.UsePixelPositioning = true;
// Note: _sadConsoleEmulatorConsole has already changed to UsePixelPositioning = true, so its Position.X is in pixels (not Width though).
var emulatorMaxX = _sadConsoleEmulatorConsole.Position.X + ((int)(_sadConsoleEmulatorConsole.Width * _sadConsoleEmulatorConsole.Font.GlyphWidth * CommonHostSystemConfig.DefaultFontSize.GetFontSizeScaleFactor()));
var emulatorMaxX = _sadConsoleEmulatorConsole!.Position.X + ((int)(_sadConsoleEmulatorConsole.Width * _sadConsoleEmulatorConsole.Font.GlyphWidth * CommonHostSystemConfig.DefaultFontSize.GetFontSizeScaleFactor()));
var infoConsoleMax = _infoConsole != null && _infoConsole.IsVisible ? _infoConsole.Position.X + _infoConsole.WidthPixels : 0;
_monitorConsole.Position = new Point(Math.Max(emulatorMaxX, infoConsoleMax), 0);
Expand All @@ -195,7 +195,7 @@ private IScreenObject CreateMainSadConsoleScreen(GameHost gameHost)
}
else
{
_sadConsoleEmulatorConsole.IsFocused = true;
_sadConsoleEmulatorConsole!.IsFocused = true;
_sadConsoleEmulatorConsole.UseKeyboard = false;
}
Expand All @@ -205,9 +205,9 @@ private IScreenObject CreateMainSadConsoleScreen(GameHost gameHost)
_sadConsoleScreen.Children.Add(_monitorConsole);

// Logo
int logoWidthAndHeight = 256; // Pixels
_logoDrawImage = new DrawImage("Resources/Images/logo-256.png");
_logoDrawImage.PositionMode = DrawImage.PositionModes.Pixels;
//int logoWidthAndHeight = 256; // Pixels
//var logoX = (MenuConsole.CONSOLE_WIDTH * _menuConsole.Font.GlyphWidth) + ((StartupScreenWidth - MenuConsole.CONSOLE_WIDTH) * _menuConsole.Font.GlyphWidth - logoWidthAndHeight) / 2;
//var logoY = ((MenuConsole.CONSOLE_HEIGHT * _menuConsole.Font.GlyphHeight) - logoWidthAndHeight) / 2;
var logoX = (MenuConsole.CONSOLE_WIDTH * _menuConsole.Font.GlyphWidth) + 10;
Expand Down Expand Up @@ -236,7 +236,7 @@ public override void OnAfterSelectSystem()
// Clear any old system specific menu console
if (_systemMenuConsole != null)
{
if (_sadConsoleScreen.Children.Contains(_systemMenuConsole))
if (_sadConsoleScreen!.Children.Contains(_systemMenuConsole))
_sadConsoleScreen.Children.Remove(_systemMenuConsole);
_systemMenuConsole.Dispose();
_systemMenuConsole = null;
Expand All @@ -246,7 +246,7 @@ public override void OnAfterSelectSystem()
{
_systemMenuConsole = new C64MenuConsole(this, _loggerFactory, _configuration);
_systemMenuConsole.Position = (MENU_POSITION_X, _menuConsole.Height);
_sadConsoleScreen.Children.Add(_systemMenuConsole);
_sadConsoleScreen!.Children.Add(_systemMenuConsole);
}

_infoConsole.ShowSelectedSystemInfoHelp();
Expand All @@ -273,9 +273,9 @@ public override bool OnBeforeStart(ISystem systemAboutToBeStarted)
}
_sadConsoleEmulatorConsole = EmulatorConsole.Create(systemAboutToBeStarted, font, CommonHostSystemConfig.DefaultFontSize, SadConsoleUISettings.CreateEmulatorConsoleDrawBoxBorderParameters(font.SolidGlyphIndex));
_sadConsoleEmulatorConsole.UsePixelPositioning = true;
_sadConsoleEmulatorConsole.Position = new Point((_menuConsole.Position.X * _menuConsole.Font.GlyphWidth) + (_menuConsole.Width * _menuConsole.Font.GlyphWidth), 0);
_sadConsoleEmulatorConsole.Position = new Point((_menuConsole!.Position.X * _menuConsole.Font.GlyphWidth) + (_menuConsole.Width * _menuConsole.Font.GlyphWidth), 0);
_sadConsoleEmulatorConsole.IsFocused = true;
_sadConsoleScreen.Children.Add(_sadConsoleEmulatorConsole);
_sadConsoleScreen!.Children.Add(_sadConsoleEmulatorConsole);

// Resize main window to fit menu, emulator, and other consoles
Game.Instance.ResizeWindow(CalculateWindowWidthPixels(), CalculateWindowHeightPixels());
Expand Down Expand Up @@ -309,7 +309,7 @@ public override void OnAfterStart(EmulatorState emulatorStateBeforeStart)
public override void OnBeforeStop()
{
// Disable monitor if it is visible
if (_monitorConsole.IsVisible)
if (_monitorConsole!.IsVisible)
DisableMonitor();
// Clear stats in info console if it is visible (logs will still be shown)
if (_infoConsole.IsVisible)
Expand All @@ -320,7 +320,7 @@ public override void OnAfterStop()
// Remove the console containing the running system
if (_sadConsoleEmulatorConsole != null)
{
if (_sadConsoleScreen.Children.Contains(_sadConsoleEmulatorConsole))
if (_sadConsoleScreen!.Children.Contains(_sadConsoleEmulatorConsole))
_sadConsoleScreen.Children.Remove(_sadConsoleEmulatorConsole);
_sadConsoleEmulatorConsole.Dispose();
_sadConsoleEmulatorConsole = null;
Expand All @@ -346,7 +346,7 @@ public override void OnAfterClose()
private void UpdateSadConsole(object? sender, GameHost gameHost)
{
// Handle UI-specific keyboard inputs such as toggle monitor, info, etc.
HandleUIKeyboardInput();
HandleUIKeyboardInput().Wait();

// RunEmulatorOneFrame() will first handle input, then emulator in run for one frame.
RunEmulatorOneFrame();
Expand Down Expand Up @@ -586,10 +586,10 @@ public void SetEmulatorConsoleFocus()
private async Task HandleUIKeyboardInput()
{
var keyboard = GameHost.Instance.Keyboard;
//if (keyboard.IsKeyPressed(Keys.F10))
//if (keyboard.IsKeyReleased(Keys.F10))
// ToggleLogs();

if (keyboard.IsKeyPressed(Keys.F11))
if (keyboard.IsKeyReleased(Keys.F11))
{
keyboard.Clear();
ToggleInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class C64HostConfig : SadConsoleHostSystemConfigBase
{
public const string ConfigSectionName = "Highbyte.DotNet6502.C64.SadConsole";

public C64SystemConfig SystemConfig
public new C64SystemConfig SystemConfig
{
get { return (C64SystemConfig)base.SystemConfig; }
set { base.SystemConfig = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public Task<ISystem> BuildSystem(string configurationVariant, IHostSystemConfig
C64Model = configurationVariant,
Vic2Model = C64ModelInventory.C64Models[configurationVariant].Vic2Models.First().Name, // NTSC, NTSC_old, PAL
AudioEnabled = c64HostSystemConfig.SystemConfig.AudioEnabled,
KeyboardJoystickEnabled = c64HostSystemConfig.SystemConfig.KeyboardJoystickEnabled,
KeyboardJoystick = c64HostSystemConfig.SystemConfig.KeyboardJoystick,
ROMs = c64HostSystemConfig.SystemConfig.ROMs,
ROMDirectory = c64HostSystemConfig.SystemConfig.ROMDirectory,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class GenericComputerHostConfig : SadConsoleHostSystemConfigBase
{
public const string ConfigSectionName = "Highbyte.DotNet6502.GenericComputer.SadConsole";

public GenericComputerSystemConfig SystemConfig
public new GenericComputerSystemConfig SystemConfig
{
get { return (GenericComputerSystemConfig)base.SystemConfig; }
set { base.SystemConfig = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private SilkNetImGuiStatsPanel CreateStatsUI()

private SilkNetImGuiDebugPanel CreateDebugUI()
{
return new SilkNetImGuiDebugPanel(GetDebugInfo);
return new SilkNetImGuiDebugPanel(() => CurrentRunningSystem!.DebugInfo);
}

private SilkNetImGuiLogsPanel CreateLogsUI(DotNet6502InMemLogStore logStore, DotNet6502InMemLoggerConfiguration logConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public Task<ISystem> BuildSystem(string configurationVariant, IHostSystemConfig
C64Model = configurationVariant,
Vic2Model = C64ModelInventory.C64Models[configurationVariant].Vic2Models.First().Name, // NTSC, NTSC_old, PAL
AudioEnabled = c64HostSystemConfig.SystemConfig.AudioEnabled,
KeyboardJoystickEnabled = c64HostSystemConfig.SystemConfig.KeyboardJoystickEnabled,
KeyboardJoystick = c64HostSystemConfig.SystemConfig.KeyboardJoystick,
ROMs = c64HostSystemConfig.SystemConfig.ROMs,
ROMDirectory = c64HostSystemConfig.SystemConfig.ROMDirectory,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public Task<ISystem> BuildSystem(string configurationVariant, IHostSystemConfig
C64Model = configurationVariant,
Vic2Model = C64ModelInventory.C64Models[configurationVariant].Vic2Models.First().Name, // NTSC, NTSC_old, PAL
AudioEnabled = c64HostSystemConfig.SystemConfig.AudioEnabled,
KeyboardJoystickEnabled = c64HostSystemConfig.SystemConfig.KeyboardJoystickEnabled,
KeyboardJoystick = c64HostSystemConfig.SystemConfig.KeyboardJoystick,
ROMs = c64HostSystemConfig.SystemConfig.ROMs,
ROMDirectory = c64HostSystemConfig.SystemConfig.ROMDirectory,
};
Expand Down Expand Up @@ -206,7 +208,7 @@ public static async Task<ICodeSuggestion> GetCodeSuggestionImplementation(C64Hos
if (c64HostConfig.CodeSuggestionBackendType == CodeSuggestionBackendTypeEnum.OpenAI)
{
var openAIApiConfig = await GetOpenAIConfig(localStorageService);
codeSuggestion = OpenAICodeSuggestion.CreateOpenAICodeSuggestionForOpenAI(openAIApiConfig, C64BasicCodingAssistant.CODE_COMPLETION_LANGUAGE_DESCRIPTION, C64BasicCodingAssistant.CODE_COMPLETION_ADDITIONAL_SYSTEM_INSTRUCTION);
codeSuggestion = OpenAICodeSuggestion.CreateOpenAICodeSuggestion(openAIApiConfig, C64BasicCodingAssistant.CODE_COMPLETION_LANGUAGE_DESCRIPTION, C64BasicCodingAssistant.CODE_COMPLETION_ADDITIONAL_SYSTEM_INSTRUCTION);
}
else if (c64HostConfig.CodeSuggestionBackendType == CodeSuggestionBackendTypeEnum.OpenAISelfHostedCodeLlama)
{
Expand Down
Loading

0 comments on commit e7894ea

Please sign in to comment.