Implement IEC Serial Bus and 1541 Disk Drive for Commodore 64.#131
Implement IEC Serial Bus and 1541 Disk Drive for Commodore 64.#131
Conversation
Implement limited support for 1541 Disk Drive. Implement attaching .D64 disk images for reading.
…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.
…emulator is restarted.
…the C64 library. Implement IHostApp interface to be able to control Start/Stop of a host app.
…otnet-6502 into feature/diskdrive1541
…ator for first time.
There was a problem hiding this comment.
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 |
| //const int NumberOfInstructionsToWaitForReadForDataAcknowledgement = 198; | ||
| const int NumberOfInstructionsToWaitForReadForDataAcknowledgement = 198/7; |
There was a problem hiding this comment.
Magic number calculation should be documented or extracted to a constant with explanation. The division by 7 and the base value 198 need clarification.
| //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; |
|
|
||
| _logger?.LogTrace($"[1541] Bit {_receiveBitPos} received: {(_receiveBitValue ? 1 : 0)}"); | ||
|
|
||
| if (_receiveBitPos == 8) |
There was a problem hiding this comment.
Magic number 8 should be extracted to a named constant like 'BITS_PER_BYTE' for better readability and maintainability.
| if (_receiveBitPos == 8) | |
| if (_receiveBitPos == BITS_PER_BYTE) |
| /// </summary> | ||
| public class D64Parser | ||
| { | ||
| private const int TRACK_18_OFFSET = 0x16500; // Track 18 starts here |
There was a problem hiding this comment.
Magic number 256 should include a comment explaining it represents the standard D64 sector size in bytes.
| 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 |
| // 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; |
There was a problem hiding this comment.
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.
| // 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; |
…c2.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…otnet-6502 into feature/diskdrive1541
|



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.