!c
plank:4,blulectric_motor,red_doped_wafer,plank,ribbon_cable,plank=disk_drive;

Overview

DiskRibbon.gif
Both methods of connection
The disk drive is a Redbus slave device that provides the ability to read and write floppy disks. Disk drives are a crucial part of any computer system because they are the only way to boot an operating system (whether the FORTH interpreter included in MineOS or a custom operating system). Once the disk drive is placed in the world and connected to a computer (either by placing it adjacent to the computer or by connecting the two with ribbon cable), a disk can be inserted by holding the disk in hand and right-clicking on the drive. If a disk is already in the drive, right-clicking the drive will eject the disk. Note that the disk cannot be ejected if it is actively being accessed by a computer; when this is occurring, a small red light on the front of the drive illuminates.

Redbus interface

A newly-placed disk drive has Redbus slave ID 2; this can be changed by shift+right-clicking the disk drive with a screwdriver in hand.

The disk drive exposes the following memory locations over Redbus:
Offset
Length
Function
0x00
128
Data buffer
0x80
2
Sector number
0x82
1
Command
To use the disk drive, software first fills in any necessary parameters then writes the command number for the desired operation into [Command]. Disk drive commands do not execute immediately; once a command has finished executing, the disk drive changes the [Command] register to 0x00 if the command was successful or 0xFF if it failed.

The disk drive understands five commands, detailed below:
Command
Function
0x01
Read name
0x02
Write name
0x03
Read serial
0x04
Read sector
0x05
Write sector

Read name

Every floppy disk has a name, which is a human-readable label of up to 64 characters. For normal disks, the disk name is displayed in the item’s tooltip (unless the name is empty, in which case the tooltip displays “Blank Floppy”—even if the disk is not actually blank!). For FORTH boot disks crafted with redstone dust, the tooltip is “FORTH Boot Disk” but the disk name is “System Disk”. For extended FORTH boot disks crafted with a second unit of redstone dust, the tooltip is “Extended FORTH Boot Disk” (as of this writing, the disk name is untested).

The Read name command does not require any parameters. If the drive is empty, the command fails; otherwise, it copies the disk name into [Data buffer] and pads it with NUL (0x00) bytes to a length of 64.

Write name

Ordinary floppy disks can be renamed by using the disk drive. Before executing the command, software must first place the new name in [Data buffer]. If the name is less than 64 characters long, a NUL (0x00) byte must be added following the name; if the name is exactly 64 characters long, the NUL is optional (but harmless as it will simply write to byte 64 of [Data buffer]). The command fails if the drive is empty; it also fails if executed on a FORTH boot disk or extended FORTH boot disk as those cannot be renamed.

Read serial

Every floppy disk has a serial number, a sequence of hexadecimal digits. FORTH boot disks all have serial number 0000000000000001 and extended FORTH boot disks all have serial number 0000000000000002. All other disks have a random, globally unique serial number. The serial number can never be changed, but the Read serial command copies the disk’s serial number into [Data buffer] has a string of 16 hexadecimal digits. The command fails only if the drive is empty.

Read sector

Floppy disks, both in real life and in Redpower, store data in the form of sectors, fixed-size blocks of bytes that can be read or written as a unit. In real life, an ordinary 1.44 MB floppy disk has 2,880 sectors each of which is 512 bytes long, for a total of 2,880×512=1,474,560 bytes. In Redpower, a floppy disk has up to 2,049 sectors (numbered 0 through 2,048), each of which is 128 bytes long, for a total of 2,049×128=262,272 bytes. Interestingly, Redpower floppy disks are actually variable-length: a freshly-crafted floppy disk contains no sectors; whenever a sector is written, that sector and all sectors before it come into existence if they did not already exist; and attempting to read a sector that does not yet exist will fail. The disk’s sectors are stored as a flat array in a file named “disk_serial.img” in the “redpower” directory inside the world; the data is not cached (every single read or write accesses the file directly), so external tools can modify the image file and the new data can be used immediately, without even removing the disk from the drive. The number of sectors in the disk is equal to the length of the file divided by 128, rounded down.

The Read sector command reads the contents of one sector (which must be specified in [Sector number], in little endian, before executing the command) and stores the data into [Data buffer], where software can retrieve it. The command fails if the sector does not exist or if the drive is empty.

Write sector

The Write sector command writes the contents of [Data buffer] (which must be filled before executing the command) to a sector of the disk (which must be specified in [Sector number], in little endian), growing the disk if necessary. The command fails if the drive is empty, if [Sector number] is greater than 2,048, or if the disk is a FORTH boot disk or extended FORTH boot disk (which are read-only).