Wang Disk Basic Cheat Sheet

Wang Disk BASIC is a complicated arrangement of three basic access modes mixed in with some unusual syntax and age-appropriate limitations. This quirkiness is part of the charm of a BASIC dialect, and Wang has plenty if it.

If you never used Wang BASIC, or it has been a long time, it would be way too frustrating to expect you to guess how to do some simple operations or to figure it out by reading a large manual.

The purpose of this page is to describe a few key Wang Disk BASIC concepts and the most important commands.  If you really want to understand Wang Disk BASIC, then you'll have to just read the manual.

Here are the topics explained on this page.

Before going any further, here is the super-condensed cheat sheet:

Disk BASIC Concepts

Wang Disk BASIC offers three access modes to the contents of a disk.  The BASIC exposes a lot of details of the disk system, and the burden is on the programmer/program to manage things more so than any modern OS, and even as compared to Microsoft Disk BASIC circa 1976.

All disks, from the smallest floppy to the largest hard disk uses a 256 byte sector as the atomic unit of transfer.  Disks start with sector 0 and increase up to the limit of the number of sectors on the disk.  A disk can have at most 65536 sectors, or about 15 MB.  Although programs can build whatever file access mechanisms they want, all the intrinsically supported file mechanisms assume a file is allocated in a contiguous range of sector addresses.  That is, a file begins at sector N, the next sector is at N+1, the next at sector N+2, etc., up to N+k, where k is the number of sectors in the file.

Perhaps the Wang file allocated policy should be viewed more like a random access tape.  Once a file occupies a section of the disk, it can only be expanded by moving the file to a larger open range of sectors on the disk, or by overwriting whatever is on the sectors immediately following the file.  The programmer must spend a lot more time managing the details of the file policy on the disk.

The three access modes are

DC mode reserves a fixed number of sectors at the start of the disk to contain a catalog of files on the disk.  The catalog is flat, i.e., there are no nested directories -- just a list of filenames and locations.

In DC mode, the first 16 bytes of the first sector of a disk contains a small amount of data describing a few key parameters of that disk's structure for use by the DC commands.  If a disk won't be operated on by the DC commands, then this information doesn't have to be present and all sectors of the disk can be used by the program.

The first parameter sets aside sectors 0 through N-1 of the disk to contain a list of the files on the disk.

The second parameter allows a programmer to tell the DC commands to use only the first N sectors of the disk, leaving any remaining sectors for self-managed file operation.

Wang disk controllers typically supported up to two disk drives.  One was called the fixed disk, and the second was the removable disk, referenced as F and R respectively.  Although this naming was appropriate for the first controllers produced by Wang, it didn't have any bearing on reality for other models of disk controllers and disk drives (e.g., a dual floppy system).  Perhaps it is best to think of disk F as "drive 0" and disk R as "drive 1".


Typographic Conventions

In all of the syntax examples below, the following typographic conventions have been followed to make it clear what is literal syntax and what is a dummy field representing the type of thing that needs to be entered.
{THIS|THAT}
represents that either THIS or THAT needs to be typed, but not both.
[OPTIONAL]
represents that the parameter OPTIONAL can be there but doesn't have to be.
italics
represents something that should be replaced with a number or string.

All commands refer to drive 0 as the F (fixed) drive, and drive 1 as the R (removable) drive.

Most commands allow an optional controller I/O address to be specified, in hex. This parameter is shown as "[/dev]" below.  If the address isn't specified, it was whatever the most recent "SELECT DISK" command specified.  If that command hasn't been performed, then it defaults to /310.


Initialize a Disk

SCRATCH DISK {F|R} [/dev] [LS=m,] END=n
After a new disk has been created or reformatted, all the sectors will be set to 00 bytes.  This command initializes sector zero of the disk with a small record of how the disk is structured for use by the DC (catalog) commands.  If a disk will not be operated upon by a DC command, then the SCRATCH DISK command doesn't need to be performed on a disk.

Either the fixed (F) or removable (R) disk drive connected to the controller must be specified.

Optionally, a disk controller address can be specified, in hex.

Optionally, the LS parameter specifies how many sectors should be set aside to hold the catalog of filenames.  Each sector set aside contains the name and parameters for 16 files.  However, the first sector contains room for only 15 names since the first slot is reserved to hold the disk structure bytes.

Examples:

SCRATCH DISK F END=300
SCRATCH DISK F LS=4, END=300
SCRATCH DISK F /320 LS=4, END=300
SCRATCH DISK R LS=64, END=15000


List Contents of Disk

LIST DC {F|R} [/dev]
This command is used to print the contents of the disk catalog.  An example catalog might be
 
INDEX SECTORS = 00004
END CAT. AREA = 00300
CURRENT END   = 00068

NAME     TYPE  START   END   USED
PRIMES     P   00004  00006  00003
TEST       P   00007  00009  00003
FOOTBALL   P   00010  00039  00030
MSTRMIND  SP   00040  00068  00029

In this example, there are four programs.  The first part of the output lists the information established by the SCRATCH DISK command, namely that the first four sectors have been reserved for holding the disk catalog, and that anything after sector 300 is reserved for use by the programs.  The first three entries have type "P" meaning they are executable programs, and the fourth entry, MSTRMIND, has type "SP" indicating that the program has been SCRATCH'd (erased), and thus can't be executed.  Although this disk doesn't have any data files, they are indicated with a "D" in the TYPE column.

The START column indicates which sector the file begins on; END indicates which sector is the last of the file, and USED is how many of the sectors are in use by that file.  It is possible to preallocate space for a file on the disk and not use all of it, in which case USED is less than (END-START+1).

Examples:

LIST DC F
LIST DC R
LIST DC F /320

Load a Program from Disk

LOAD DC {F|R} [/dev,] "filename"
This command is used to read a program of a specified name from the disk.

Examples:

LOAD DC F "PRIMES"
LOAD DC F /320, "FOOTBALL"
LOAD DC R "TEST"

Save a Program to Disk

SAVE DC {F|R} [/dev,] "filename"
This command is used to save a program to the disk with the specified name.  You can't save a program using a name that is already on the disk.

Examples:

SAVE DC F "PRIMES"
SAVE DC F /320, "PRIMES"
SAVE DC R "PRIMES"

Erase a Program from the Disk

SCRATCH {F|R} [/dev,] "filename"
This command actually doesn't erase the program or release the area for further use. Instead, it simply marks the file for later removal.  In the meantime, the program can't be loaded.  When a "LIST DC" command is performed, scratched files show up with an "S" as part of the TYPE field.

SCRATCH'd programs get removed via a MOVE operation.

Examples:

SCRATCH F "FOOTBALL"
SCRATCH F /320, "PRIMES"
SCRATCH R /330, "BACKUP"

Housekeeping

MOVE {FR|RF}
COPY {FR|RF}
MOVE copies all non-scratched programs from one drive to the other drive, skipping any that are marked as being SCRATCH'd.  A common operation is to MOVE from the F drive to a scratch disk in the R drive, and then to immediately MOVE or COPY it back to the F drive.

COPY just does a blind sector by sector cloning from one drive to the other drive.

In both of these commands, the first drive letter is the source disk and the second drive letter is the destination disk.  For example, "COPY FR" will make the disk in the R drive get a copy of whatever is in the F drive.

Examples:

MOVE FR
MOVE RF
COPY FR
COPY RF

Last update: September 25, 2003