Using disk drives

Revision as of 16:08, 7 March 2026 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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