-
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.
Add clipboard support and paste functionality (#112)
Integrated the `TextCopy` library to enable clipboard operations across multiple projects. Added a "Paste" button to the `C64MenuConsole`, `SilkNetImGuiMenu`, and Blazor-based `C64Menu.razor` components to allow pasting text into the C64 emulator.
- Loading branch information
Showing
12 changed files
with
159 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
src/libraries/Highbyte.DotNet6502.Systems.Commodore64/Utils/C64TextPaste.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Highbyte.DotNet6502.Systems.Commodore64.Video; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Highbyte.DotNet6502.Systems.Commodore64.Utils; | ||
public class C64TextPaste | ||
{ | ||
private readonly Queue<char> _charQueue = new(); | ||
private readonly ILogger<C64TextPaste> _logger; | ||
private readonly C64 _c64; | ||
|
||
internal bool HasCharactersPending => _charQueue.Count > 0; | ||
|
||
|
||
public C64TextPaste(C64 c64, ILoggerFactory loggerFactory) | ||
{ | ||
_logger = loggerFactory.CreateLogger<C64TextPaste>(); | ||
_c64 = c64; | ||
} | ||
|
||
public void Paste(string text) | ||
{ | ||
foreach (char c in text) | ||
_charQueue.Enqueue(c); | ||
} | ||
|
||
internal void InsertNextCharacterToKeyboardBuffer() | ||
{ | ||
bool foundChar = _charQueue.TryPeek(out char ansiChar); | ||
if (!foundChar) | ||
return; | ||
|
||
// In Windows, a new line is CRLF (Carrige Return 13 and Line Feed 10) | ||
// In Linux and macOS, a new line is only LF (Line feed 10). | ||
// C64 only uses LF (13) which is "Return" for new line. | ||
// | ||
// Ignore Windows LF (10), and map Line Feed for all systems (10) to C64 Return (13). | ||
if (ansiChar == 13) | ||
{ | ||
_charQueue.Dequeue(); | ||
return; | ||
} | ||
|
||
if (ansiChar == 10) | ||
ansiChar = (char)13; | ||
|
||
if (!Petscii.CharToPetscii.ContainsKey(ansiChar)) | ||
{ | ||
_charQueue.Dequeue(); | ||
_logger.LogWarning($"'{ansiChar}' has no mapped PetscII char."); | ||
return; | ||
} | ||
|
||
var petsciiChar = Petscii.CharToPetscii[ansiChar]; | ||
var inserted = _c64.Cia.Keyboard.InsertPetsciiCharIntoBuffer(petsciiChar); | ||
if (inserted) | ||
{ | ||
_charQueue.Dequeue(); | ||
} | ||
else | ||
{ | ||
_logger.LogWarning($"'{ansiChar}' could not be inserted into keyboard buffer."); | ||
} | ||
} | ||
} |