BASIC Commands: Using from DOS & ProDOS

The following guidelines apply equally to DOS, the predecessor of ProDOS.

Using a ProDOS command from a BASIC program extends the capability of your programs in several ways. For example, you might use deferred execution ProDOS commands to automatically display a disk's catalog, to save a backup copy of records in a file, or to save an unfinished game so you can continue it later.
This article has been archived and is no longer updated by Apple.
To use a ProDOS command from a program, use the BASIC statement PRINT followed by the string you want to print. In this case, the string will contain a ProDOS command. To indicate that you're printing a ProDOS command rather than text, type the control character CTRL-D as the first character of the string.

This is the general form:

PRINT CTRL-D "ProDOS command"

ProDOS and DOS from Integer BASIC
In Integer BASIC, there is only one way to get a CTRL-D into your program: type CTRL-D right after you type the quote marks that begin the string you want to print:

10 PRINT "CATALOG" (There is a CTRL-D between " and C.) The CTRL-D is there, although you can't see it.

CAUTION: Using the right arrow key to copy a BASIC statement will NOT copy invisible control characters. In effect, the right arrow key deletes control characters.

ProDOS and DOS from Applesoft
To get a CTRL-D into your program with Applesoft, you can use (1) the method above, or (2) the Applesoft CHR$ function in the expression CHR$(4). "4" is the argument the CHR$ function takes to return CTRL-D in a one-character ASCII string. Set any string variable to CHR$(4) at the beginning of your program and print that string variable before each ProDOS command. This gives you the advantage of seeing the CTRL-D in your code and the conveinece of fixing it in only one place if you've declared it improperly. Using the variable in a PRINT statement, CTRL-D from a CHR$ functions looks like this:

10 D$=CHR$(4)

The string variable name is D as a reminder of the control character it contains.

You can omit the semicolon. The semicolon after D$ is optional. When your program has many ProDOS commands in PRINT statements, you'll save typing time and memory space by omitting the semicolon. Without a semicolon, line 20 looks like this:


There are three things you should watch out for while using ProDOS commands from Applesoft programs.

1. Be sure you have only one ProDOS command per PRINT statement

2. Be sure a carriage return is the last character printed before printing a CTRL-D. If the statement before a ProDOS command ends with a semicolon, a tab character, or a comma, the ProDOS command will not go to the ProDOS command interpreter. When your program unexpectedly prints a ProDOS command instead of executing it, look for a program statement that ends with a semicolon

If you set your D$ variable to precede CTRL-D with a carriage return (i.e., 10 D$=CHR$(13)+CHR$(4)), this D$ WILL CAUSE PROBLEMS WHEN YOU WRITE OR APPEND TEXT, INTRODUCING UNWANTED CARRIAGE RETURNS.

3. Remember that some ProDOS commands work only in programs. The ProDOS commands that can be issued only in deferred execution are APPEND, OPEN, POSITION, READ, and WRITE.
Published Date: Feb 19, 2012