Skip to content

Implement IEC Serial Bus and 1541 Disk Drive for Commodore 64.#131

Merged
highbyte merged 46 commits intomasterfrom
feature/diskdrive1541
Jul 30, 2025
Merged

Implement IEC Serial Bus and 1541 Disk Drive for Commodore 64.#131
highbyte merged 46 commits intomasterfrom
feature/diskdrive1541

Conversation

@highbyte
Copy link
Copy Markdown
Owner

@highbyte highbyte commented Jul 15, 2025

Implement limited support for 1541 Disk Drive using IEC serial bus load commands.

Implement attaching .D64 disk images for reading in WASM, SilkNet and SadConsole host apps.

Implement auto-download & run a list of preconfigured .D64 images in WASM host app.

Implement limited support for 1541 Disk Drive.
Implement attaching .D64 disk images for reading.
@highbyte highbyte requested a review from Copilot July 15, 2025 10:35

This comment was marked as outdated.

highbyte and others added 27 commits July 15, 2025 12:38
…Peripheral/IEC/IECEnums.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…c2.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Restart C64 before loading and running.
…the C64 library. Implement IHostApp interface to be able to control Start/Stop of a host app.
@highbyte highbyte requested a review from Copilot July 29, 2025 12:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements limited support for the Commodore 1541 disk drive and IEC serial bus communication in the C64 emulator. The main functionality allows attaching .D64 disk images and using basic LOAD commands to read files from the disk images.

Key changes include:

  • Implementation of IEC serial bus protocol for C64-to-disk drive communication
  • 1541 disk drive emulation with basic file reading capabilities
  • D64 disk image parsing and file extraction functionality
  • Auto-download and run capabilities for preconfigured D64 images in the WASM app

Reviewed Changes

Copilot reviewed 37 out of 39 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
IECBus.cs, IECHost.cs, IECEnums.cs Core IEC serial bus implementation and protocol definitions
DiskDrive1541.cs 1541 disk drive emulation with file loading support
D64Parser.cs, D64DiskImage.cs D64 disk image format parsing and file extraction
D64Downloader.cs, D64AutoDownloadAndRun.cs Auto-download functionality for WASM app
Vic2.cs Integration of IEC bus with CIA #2 port A for serial communication
C64.cs Integration of IEC bus and disk drive into C64 system
UI components Menu additions for disk image attachment/detachment across all host apps

Comment thread src/libraries/Highbyte.DotNet6502.Systems.Commodore64/Video/Vic2.cs Outdated
Comment on lines +293 to +294
//const int NumberOfInstructionsToWaitForReadForDataAcknowledgement = 198;
const int NumberOfInstructionsToWaitForReadForDataAcknowledgement = 198/7;
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number calculation should be documented or extracted to a constant with explanation. The division by 7 and the base value 198 need clarification.

Suggested change
//const int NumberOfInstructionsToWaitForReadForDataAcknowledgement = 198;
const int NumberOfInstructionsToWaitForReadForDataAcknowledgement = 198/7;
// Number of instructions to wait for data acknowledgement, based on timing calculations:
const int TotalCyclesFor200Microseconds = 198; // 200 µs ÷ 1.015 µs/cycle ≈ 197.04 cycles, rounded up to 198
const int CyclesPerInstruction = 7; // Assumes a worst-case scenario of 7 cycles per instruction
const int NumberOfInstructionsToWaitForReadForDataAcknowledgement = TotalCyclesFor200Microseconds / CyclesPerInstruction;

Copilot uses AI. Check for mistakes.

_logger?.LogTrace($"[1541] Bit {_receiveBitPos} received: {(_receiveBitValue ? 1 : 0)}");

if (_receiveBitPos == 8)
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number 8 should be extracted to a named constant like 'BITS_PER_BYTE' for better readability and maintainability.

Suggested change
if (_receiveBitPos == 8)
if (_receiveBitPos == BITS_PER_BYTE)

Copilot uses AI. Check for mistakes.
/// </summary>
public class D64Parser
{
private const int TRACK_18_OFFSET = 0x16500; // Track 18 starts here
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number 256 should include a comment explaining it represents the standard D64 sector size in bytes.

Suggested change
private const int TRACK_18_OFFSET = 0x16500; // Track 18 starts here
private const int TRACK_18_OFFSET = 0x16500; // Track 18 starts here
// Standard D64 sector size in bytes

Copilot uses AI. Check for mistakes.
Comment on lines +198 to +200
// Use calculation that matches VICE: 664 total capacity minus used blocks
// Standard D64 has 664 blocks available for files (excluding directory track)
return 664 - TotalBlocks;
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number 664 should be extracted to a named constant with documentation explaining it represents the total available blocks in a standard D64 image excluding the directory track.

Suggested change
// Use calculation that matches VICE: 664 total capacity minus used blocks
// Standard D64 has 664 blocks available for files (excluding directory track)
return 664 - TotalBlocks;
// Use calculation that matches VICE: total capacity minus used blocks
return TotalAvailableBlocks - TotalBlocks;

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

@highbyte highbyte marked this pull request as ready for review July 30, 2025 11:52
@highbyte highbyte merged commit 164d1f6 into master Jul 30, 2025
5 checks passed
@highbyte highbyte deleted the feature/diskdrive1541 branch July 30, 2025 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants