Using disk drives: Difference between revisions

From Color 64 BBS Wiki
No edit summary
No edit summary
 
Line 3: Line 3:
== Disk Drives ==
== Disk Drives ==
----
----
=== Using Legacy Commodore Disk Drives ===
=== Using Legacy Commodore Disk Drives ===


To access a file on a Commodore compatible disk drive, there are five parameters that define how the computer communicates with a disk device:  
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  
* Logical File Number
* Secondary Address  
* Device Number
* Drive Number  
* Secondary Address
* Filename  
* Drive Number
* Filename
 
The BASIC <strong>OPEN</strong> command uses these parameters. Its syntax is:
 
: <code>OPEN &lt;logical file #&gt;, &lt;device #&gt;, &lt;secondary address&gt;, &lt;file name&gt;</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.
 
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:
 
: <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 OPEN command uses all these parameters and here is its syntax: 
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.
: <strong>OPEN <logical file #>, <device #>, <secondary address>, <file name>  </strong>


The drive number is included in the file name. Here is an example of the use of all of these elements: 
However, programmers often use the same value for both. For example:
: <strong>OPEN 9, 8, 2, "0:TEST"  </strong>


Nine (9) is the logical file number, Eight (8) is the device number, Two (2) is the secondary address, zero (0) is the drive number, and "TEST" is the file name.  I will discuss the use of each of these elements in order of importance.
: <code>OPEN 8,DV,8,DR$+FI$</code>


* Device Number
==== File Name ====
: Any device that plugs into the Commodore's serial port has a DEVICE NUMBER assigned to it, which allows the computer to distinguish between several different devices.  A device can be a printer, plotter, disk drive, or any other device that can interface through the serial port.  All the devices connected to the computer must have their own individual device number, or the computer will not be able to figure out which device is which. 


: Traditionally, disk drives may have any device number from 8 to 30. The Commodore 1541 disk drive, for example, can be customized to a device number from 8 to 15, but other devices such as the CMD HD can be set to be any device number from 8 to 30.  In the example command LOAD"0:FILE",8 the device number is 8.  
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.


* Drive Number
In the <strong>OPEN</strong> command, the drive number is included in the filename string:
: Along with the device number, disk devices are also accessed by a DRIVE NUMBER.  The drive number was designed to allow one device to access more than one disk (as with the MSD-SD2 dual disk drive).  The 1541 disk drive has only one drive permanently set to drive 0.  In the example command <strong>LOAD"0:FILE",8</strong> the drive number is 0, because the drive number precedes the file name separated by a colon.  For Lt.  Kernal hard drives, the drive number is also referred to as the LU (logical unit).


* Secondary Address
: <code>"0:FILENAME"</code>
: To communicate with a disk drive, the computer must open up a communications "channel".  When the OPEN command is used, this channel is referred to as the SECONDARY ADDRESS.  Channel numbers 0 and 1 are reserved for loading and saving programs.  Channel number 15 is used as the "command channel".  All the other channel numbers (up to 127) are free for use with common communications.  Another thing to note is that when opening more than one file on a single device, each file must have its own individual channel number, because this is how the disk drive knows which file you want to access. 


: The command channel is used to send special commands to the disk drive. Some of the more common commands are the initialize, validate, scratch, and copy commands.  Other commands are specific to certain devices.  For example, the Lt. Kernal drive has the "LG" command which is used to get information about the hard drive.  When opening the command channel, a file name is not used.  Instead, the text you use as the file name is sent to the channel as a drive command.
The format is:


* Logical File Number
: <code>&lt;drive number&gt;:&lt;file name&gt;</code>
: The computer also uses a LOGICAL FILE NUMBER to keep track of all open files.  Once you open a file, the file number is what you use with the PRINT# and INPUT# statements.  This sure makes things a lot simpler than having to refer to the device number, drive number, etc. every time you want to send or receive information to or from a file.  The file number is for the computer's own use and has nothing to do with actual device communications.  This means that the file number and secondary address are completely independent of each other, although programmers traditionally make the secondary address the same as the logical file number (i.e. OPEN 8, DV, 8, DR$+FI$).


* File Name
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.
: Finally, the last parameter needed is the FILE NAME.  Each of the files on a drive has a unique name, which makes things easier to keep track of, especially since a file name can be up to 16 characters in length.  Note that the drive number is included in the file name in the OPEN command.  The drive number is first, followed by a colon, then the actual file name.


: Hard drive devices, such as the CMD and Lt. Kernal hard drives, have many more features than the traditional floppy devices.  Most hard drives divide up their storage into units called "partitions".  Sometimes, the computer can access these partitions by using the drive number.  Otherwise, special commands must be sent to the HD to select a partition for use.
----
----


=== Using SD2IEC ===
=== Using SD2IEC ===


Color 64 BBS v8.1 and 8.10a work fine running on only a SD2IEC drive or a combination of it and standard drives. This is advantageous when it comes to blocks free available to users for Uploads, messages stored on the system, and breaking the barrier of limited number of files for a directory. The key to successfully implementing SD2IEC is to ensure you have the right INIT command in your system setup when selecting your disk assignments while running +SETUP. If you track discussions on the internet regarding REL files and SD2IEC, I’ve had no problems. I believe it has to do with running the system with a normal folder structure on the SD card and not utilizing .D64/.D81 images.
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:


As I hinted in the main text of this manual, I use the following setup on my system:
* Significantly more available disk space
* Larger storage for messages and uploads
* Removal of traditional directory file limits


{| class="wikitable
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
|-
|-
| Nothing (root folder)  
| (root folder)
| Programs & Systems drive
| 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 Messages Drive
| Private messages
| Drive: 8  
|
Device Init: 0:!cd//primsgs  
Drive: 8
Device Init: <code>0:!cd//primsgs</code>
|-
|-
| PUBMSGS  
| PUBMSGS
| Public Messages Drive
| Public messages
| Drive: 8  
|
Device Init: 0:!cd//pubmsgs  
Drive: 8
Device Init: <code>0:!cd//pubmsgs</code>
|-
|-
| AUX1  
| AUX1
| Drive for AUX 1  
| AUX 1 drive
| Drive: 8  
|
Device Init: 0:!cd//aux1  
Drive: 8
Device Init: <code>0:!cd//aux1</code>
|-
|-
| AUX2  
| AUX2
| Drive for AUX 2  
| AUX 2 drive
| Drive: 8  
|
Device Init: 0:!cd//aux2  
Drive: 8
Device Init: <code>0:!cd//aux2</code>
|-
|-
| AUX3  
| AUX3
| Drive for AUX3
| AUX 3 drive
| Drive: 8  
|
Device Init: 0:!cd//aux3  
Drive: 8
Device Init: <code>0:!cd//aux3</code>
|-
|-
| UPLOADS  
| UPLOADS
| Uploads drive
| Uploads directory
| Drive: 8  
|
Device Init: 0:!cd//uploads  
Drive: 8
Device Init: <code>0:!cd//uploads</code>
|-
|-
| GAMES  
| GAMES
| Games Download folder
| Games download directory
| Drive: 8  
|
Device Init: 0:!cd//games  
Drive: 8
Device Init: <code>0:!cd//games</code>
|-
|-
| USERS  
| USERS
| User Profile area (applies to version 8.1a only)  
| User profile storage (v8.1a only)
| Drive: 8  
|
Device Init: 0:!cd//users  
Drive: 8
Device Init: <code>0:!cd//users</code>
|}
|}


There are more assignments for my system, but hopefully you get the idea. Color 64 will execute on this smartly! Use this same approach when using DOS Wedge and any other functions where the system will prompt you for Drive and Device – like Message Editor.  
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.


Note that for SD2IEC Sysops, Color 64 will kick out 2 errors at midnight – but it does not affect BBS operations. This is when the system performs a Validation command to the drive; something that SD2IEC does not understand. You will get syntax errors generated in your log, but the system just continues along. No harm, no foul.
----
----


=== Lt. Kernal or CMD HD ===
=== Lt. Kernal or CMD HD ===


There's nothing particular for this specific section to discuss on Lt. Kernal or CMD Hard Drives, though you will definitely want to look at the next section, Drive Initialization Commands!
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.

SD2IEC Folder Setup Example
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: 0:!cd//

HELP Help & Text files

Drive: 8 Device Init: 0:!cd//help

PRIMSGS Private messages

Drive: 8 Device Init: 0:!cd//primsgs

PUBMSGS Public messages

Drive: 8 Device Init: 0:!cd//pubmsgs

AUX1 AUX 1 drive

Drive: 8 Device Init: 0:!cd//aux1

AUX2 AUX 2 drive

Drive: 8 Device Init: 0:!cd//aux2

AUX3 AUX 3 drive

Drive: 8 Device Init: 0:!cd//aux3

UPLOADS Uploads directory

Drive: 8 Device Init: 0:!cd//uploads

GAMES Games download directory

Drive: 8 Device Init: 0:!cd//games

USERS User profile storage (v8.1a only)

Drive: 8 Device Init: 0:!cd//users

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

Programming Features