Using disk drives: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[programming features|Programming Features]] - <strong>Using Disk Drives</strong> | [[programming features|Programming Features]] - <strong>Using Disk Drives</strong> | ||
== Disk Drives == | |||
---- | |||
=== Using Legacy Commodore Disk Drives === | |||
To access a file on a Commodore-compatible disk drive, five parameters define how the computer communicates with the device: | |||
* Logical File Number | |||
* Device Number | |||
* Secondary Address | |||
* Drive Number | |||
* Filename | |||
The BASIC <strong>OPEN</strong> command uses these parameters. Its syntax is: | |||
: <code>OPEN <logical file #>, <device #>, <secondary address>, <file name></code> | |||
: | |||
The drive number is included in the file name. Example: | |||
: <code>OPEN 9,8,2,"0:TEST"</code> | |||
: | |||
In this example: | |||
: | |||
* <strong>9</strong> = logical file number | |||
* <strong>8</strong> = device number | |||
* <strong>2</strong> = secondary address | |||
* <strong>0</strong> = drive number | |||
* <strong>TEST</strong> = file name | |||
Each parameter is described below. | |||
==== Device Number ==== | |||
Any device connected to the Commodore serial port has a <strong>device number</strong>. This number allows the computer to distinguish between multiple devices such as printers, plotters, disk drives, or other peripherals. | |||
Each device connected to the system must have a unique device number. If two devices share the same number, the computer cannot determine which device should respond. | |||
<strong> | Traditionally, disk drives use device numbers from <strong>8 to 30</strong>. For example: | ||
* The Commodore 1541 drive typically supports device numbers <strong>8–15</strong>. | |||
* Devices such as the CMD HD can support device numbers up to <strong>30</strong>. | |||
Example: | |||
{| class="wikitable | : <code>LOAD "0:FILE",8</code> | ||
In this command, <strong>8</strong> is the device number. | |||
==== Drive Number ==== | |||
In addition to the device number, many disk devices also support a <strong>drive number</strong>. This allows a single device to access multiple disk mechanisms. | |||
Examples: | |||
* The Commodore 1541 has only one drive and it is permanently <strong>drive 0</strong>. | |||
* Dual-drive units such as the MSD-SD2 allow selection of multiple drives. | |||
* On Lt. Kernal hard drives, the drive number is commonly referred to as the <strong>LU (Logical Unit)</strong>. | |||
Example: | |||
: <code>LOAD "0:FILE",8</code> | |||
Here the <strong>0</strong> indicates drive 0, which appears before the filename and is separated by a colon. | |||
==== Secondary Address ==== | |||
To communicate with a disk drive, the computer must open a communications <em>channel</em>. When using the <strong>OPEN</strong> command, this channel number is called the <strong>secondary address</strong>. | |||
Important channel assignments include: | |||
* <strong>0–1</strong> — Reserved for program loading and saving | |||
* <strong>15</strong> — Command channel | |||
* <strong>2–127</strong> — Available for normal file access | |||
When multiple files are opened on the same device, each file must use a unique secondary address. This allows the disk drive to determine which file the computer is referencing. | |||
The <strong>command channel (15)</strong> is used to send commands to the disk drive, such as: | |||
* Initialize | |||
* Validate | |||
* Scratch | |||
* Copy | |||
Some devices also support additional commands. For example, the Lt. Kernal drive supports the <code>LG</code> command for retrieving hard drive information. | |||
When opening the command channel, the “filename” parameter is interpreted as a command string rather than a file name. | |||
==== Logical File Number ==== | |||
The <strong>logical file number</strong> is used internally by BASIC to track open files. After opening a file, this number is used with the <strong>PRINT#</strong> and <strong>INPUT#</strong> statements. | |||
This simplifies program code because it avoids repeatedly specifying the device and drive numbers when performing file operations. | |||
The logical file number is strictly for BASIC’s internal tracking and does not affect the device itself. Because of this, the logical file number and secondary address are technically independent. | |||
However, programmers often use the same value for both. For example: | |||
: <code>OPEN 8,DV,8,DR$+FI$</code> | |||
==== File Name ==== | |||
The final parameter is the <strong>file name</strong>. Each file on a disk has a unique name, up to <strong>16 characters</strong> long. | |||
In the <strong>OPEN</strong> command, the drive number is included in the filename string: | |||
: <code>"0:FILENAME"</code> | |||
The format is: | |||
: <code><drive number>:<file name></code> | |||
Hard drive systems such as CMD HD or Lt. Kernal provide additional functionality. Many hard drives divide storage into <strong>partitions</strong>. In some systems, partitions are accessed through drive numbers; in others, special drive commands must be used to select the active partition. | |||
---- | |||
=== Using SD2IEC === | |||
Color 64 BBS v8.1 and v8.10a operate reliably using only an <strong>SD2IEC</strong> drive or in combination with traditional Commodore disk drives. | |||
Using SD2IEC offers several advantages: | |||
* Significantly more available disk space | |||
* Larger storage for messages and uploads | |||
* Removal of traditional directory file limits | |||
Successful SD2IEC operation depends on using the correct <strong>device initialization commands</strong> when assigning drives in the <strong>+SETUP</strong> program. | |||
While discussions on the internet sometimes mention REL file problems with SD2IEC, no issues were encountered during testing. This may be related to running the system directly from the SD card’s folder structure rather than using disk image files such as <code>.D64</code> or <code>.D81</code>. | |||
An example SD2IEC folder configuration is shown below. | |||
{| class="wikitable" | |||
|- | |- | ||
|+SD2IEC Folder Setup Example | |+ SD2IEC Folder Setup Example | ||
! Folder name on SD card | ! Folder name on SD card | ||
! Functional area (or “Drive selection”) | ! Functional area (or “Drive selection”) | ||
! Settings in +SETUP for Drive Assignment | ! Settings in +SETUP for Drive Assignment | ||
|- | |- | ||
| | | (root folder) | ||
| Programs & | | Programs & System files | ||
| Drive: 8 | | | ||
Device Init: 0:!cd// | Drive: 8 | ||
Device Init: <code>0:!cd//</code> | |||
|- | |- | ||
| HELP | | HELP | ||
| Help & Text files | | Help & Text files | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//help | Drive: 8 | ||
Device Init: <code>0:!cd//help</code> | |||
|- | |- | ||
| PRIMSGS | | PRIMSGS | ||
| Private | | Private messages | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//primsgs | Drive: 8 | ||
Device Init: <code>0:!cd//primsgs</code> | |||
|- | |- | ||
| PUBMSGS | | PUBMSGS | ||
| Public | | Public messages | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//pubmsgs | Drive: 8 | ||
Device Init: <code>0:!cd//pubmsgs</code> | |||
|- | |- | ||
| AUX1 | | AUX1 | ||
| | | AUX 1 drive | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//aux1 | Drive: 8 | ||
Device Init: <code>0:!cd//aux1</code> | |||
|- | |- | ||
| AUX2 | | AUX2 | ||
| | | AUX 2 drive | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//aux2 | Drive: 8 | ||
Device Init: <code>0:!cd//aux2</code> | |||
|- | |- | ||
| AUX3 | | AUX3 | ||
| | | AUX 3 drive | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//aux3 | Drive: 8 | ||
Device Init: <code>0:!cd//aux3</code> | |||
|- | |- | ||
| UPLOADS | | UPLOADS | ||
| Uploads | | Uploads directory | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//uploads | Drive: 8 | ||
Device Init: <code>0:!cd//uploads</code> | |||
|- | |- | ||
| GAMES | | GAMES | ||
| Games | | Games download directory | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//games | Drive: 8 | ||
Device Init: <code>0:!cd//games</code> | |||
|- | |- | ||
| USERS | | USERS | ||
| User | | User profile storage (v8.1a only) | ||
| Drive: 8 | | | ||
Device Init: 0:!cd//users | Drive: 8 | ||
Device Init: <code>0:!cd//users</code> | |||
|} | |} | ||
Additional directories may be used depending on your system configuration, but the same approach applies. | |||
When using SD2IEC, the same drive selection methods work with other Color 64 features such as: | |||
* DOS Wedge | |||
* Message Editor | |||
* Any routine that prompts for device and drive numbers | |||
One minor issue to be aware of: SD2IEC does not support the Commodore <strong>VALIDATE</strong> command used during the BBS midnight maintenance routine. As a result, two syntax errors may appear in the system log at midnight. These errors do not affect BBS operation and can safely be ignored. | |||
---- | |||
=== Lt. Kernal or CMD HD === | |||
No special configuration is required specifically for Lt. Kernal or CMD hard drives beyond normal drive assignments. However, these systems make extensive use of initialization commands and partition selection. | |||
For this reason, the next section (<em>Drive Initialization Commands</em>) is particularly important when configuring these devices. | |||
Next section: [[initialization commands|Drive Initialization Commands]] | Next section: [[initialization commands|Drive Initialization Commands]] | ||
[[programming features|Programming Features]] | [[programming features|Programming Features]] | ||
Latest revision as of 16:08, 7 March 2026
Programming Features - Using Disk Drives
Disk Drives
Using Legacy Commodore Disk Drives
To access a file on a Commodore-compatible disk drive, five parameters define how the computer communicates with the device:
- Logical File Number
- Device Number
- Secondary Address
- Drive Number
- Filename
The BASIC OPEN command uses these parameters. Its syntax is:
OPEN <logical file #>, <device #>, <secondary address>, <file name>
The drive number is included in the file name. Example:
OPEN 9,8,2,"0:TEST"
In this example:
- 9 = logical file number
- 8 = device number
- 2 = secondary address
- 0 = drive number
- TEST = file name
Each parameter is described below.
Device Number
Any device connected to the Commodore serial port has a device number. This number allows the computer to distinguish between multiple devices such as printers, plotters, disk drives, or other peripherals.
Each device connected to the system must have a unique device number. If two devices share the same number, the computer cannot determine which device should respond.
Traditionally, disk drives use device numbers from 8 to 30. For example:
- The Commodore 1541 drive typically supports device numbers 8–15.
- Devices such as the CMD HD can support device numbers up to 30.
Example:
LOAD "0:FILE",8
In this command, 8 is the device number.
Drive Number
In addition to the device number, many disk devices also support a drive number. This allows a single device to access multiple disk mechanisms.
Examples:
- The Commodore 1541 has only one drive and it is permanently drive 0.
- Dual-drive units such as the MSD-SD2 allow selection of multiple drives.
- On Lt. Kernal hard drives, the drive number is commonly referred to as the LU (Logical Unit).
Example:
LOAD "0:FILE",8
Here the 0 indicates drive 0, which appears before the filename and is separated by a colon.
Secondary Address
To communicate with a disk drive, the computer must open a communications channel. When using the OPEN command, this channel number is called the secondary address.
Important channel assignments include:
- 0–1 — Reserved for program loading and saving
- 15 — Command channel
- 2–127 — Available for normal file access
When multiple files are opened on the same device, each file must use a unique secondary address. This allows the disk drive to determine which file the computer is referencing.
The command channel (15) is used to send commands to the disk drive, such as:
- Initialize
- Validate
- Scratch
- Copy
Some devices also support additional commands. For example, the Lt. Kernal drive supports the LG command for retrieving hard drive information.
When opening the command channel, the “filename” parameter is interpreted as a command string rather than a file name.
Logical File Number
The logical file number is used internally by BASIC to track open files. After opening a file, this number is used with the PRINT# and INPUT# statements.
This simplifies program code because it avoids repeatedly specifying the device and drive numbers when performing file operations.
The logical file number is strictly for BASIC’s internal tracking and does not affect the device itself. Because of this, the logical file number and secondary address are technically independent.
However, programmers often use the same value for both. For example:
OPEN 8,DV,8,DR$+FI$
File Name
The final parameter is the file name. Each file on a disk has a unique name, up to 16 characters long.
In the OPEN command, the drive number is included in the filename string:
"0:FILENAME"
The format is:
<drive number>:<file name>
Hard drive systems such as CMD HD or Lt. Kernal provide additional functionality. Many hard drives divide storage into partitions. In some systems, partitions are accessed through drive numbers; in others, special drive commands must be used to select the active partition.
Using SD2IEC
Color 64 BBS v8.1 and v8.10a operate reliably using only an SD2IEC drive or in combination with traditional Commodore disk drives.
Using SD2IEC offers several advantages:
- Significantly more available disk space
- Larger storage for messages and uploads
- Removal of traditional directory file limits
Successful SD2IEC operation depends on using the correct device initialization commands when assigning drives in the +SETUP program.
While discussions on the internet sometimes mention REL file problems with SD2IEC, no issues were encountered during testing. This may be related to running the system directly from the SD card’s folder structure rather than using disk image files such as .D64 or .D81.
An example SD2IEC folder configuration is shown below.
| Folder name on SD card | Functional area (or “Drive selection”) | Settings in +SETUP for Drive Assignment |
|---|---|---|
| (root folder) | Programs & System files |
Drive: 8
Device Init: |
| HELP | Help & Text files |
Drive: 8
Device Init: |
| PRIMSGS | Private messages |
Drive: 8
Device Init: |
| PUBMSGS | Public messages |
Drive: 8
Device Init: |
| AUX1 | AUX 1 drive |
Drive: 8
Device Init: |
| AUX2 | AUX 2 drive |
Drive: 8
Device Init: |
| AUX3 | AUX 3 drive |
Drive: 8
Device Init: |
| UPLOADS | Uploads directory |
Drive: 8
Device Init: |
| GAMES | Games download directory |
Drive: 8
Device Init: |
| USERS | User profile storage (v8.1a only) |
Drive: 8
Device Init: |
Additional directories may be used depending on your system configuration, but the same approach applies.
When using SD2IEC, the same drive selection methods work with other Color 64 features such as:
- DOS Wedge
- Message Editor
- Any routine that prompts for device and drive numbers
One minor issue to be aware of: SD2IEC does not support the Commodore VALIDATE command used during the BBS midnight maintenance routine. As a result, two syntax errors may appear in the system log at midnight. These errors do not affect BBS operation and can safely be ignored.
Lt. Kernal or CMD HD
No special configuration is required specifically for Lt. Kernal or CMD hard drives beyond normal drive assignments. However, these systems make extensive use of initialization commands and partition selection.
For this reason, the next section (Drive Initialization Commands) is particularly important when configuring these devices.
Next section: Drive Initialization Commands