in BASIC ROM:
|List of all BASIC keywords|
Type: Command General programming syntax: OPEN <logical filenumber> [,<device number> [,<secondary number> [,"<filename>[,<type>[,<modus>]]" ] ] ]
The BASIC command OPEN is used for opening a logical file, or a "channel" to a peripheral device like printer, datassette or disk drive and for data input and output operations from respectively to external devices.
It is important to use OPEN before using any of the following BASIC commands: CLOSE, CMD, GET#, INPUT# and PRINT#. Furthermore, the OPEN command has to use the right file in the right device with the right logical filenumber with values between 1 until 255 (reasonably below 128).
On the C64 each device has got a separate device number, and in the OPEN command this number is used to identify the right peripheral device. If the device number is omitted, the first device — the datasette — will be used.
The use of the secondary address will vary from device to device and specifies what kind of device operation is to be executed, e.g. reading or writing data files or formatting a disk. By omitting the secondary number, the secondary number is 0 and a data file read will be used.
- Device number 0 | keyboard (not counted as first device!)
- Device number 1 | datasette | secondary number 0 = for loading; 1 = for writing; 2 = for writing with file end (EOT - End Of Tape)
- Device number 2 | modem / RS-232 | secondary number 0
- Device number 3 | screen | secondary number 0 or 1
- Device number 4 or 5 | printer | secondary number 0 = capital letters/graphic symbols 7 = capital/small Letters
- Device number 8 until 15 | disk drive | secondary number 2-14 = data channels; 15 channel for commands
The following BASIC error messages can occur when using the device commands, whereas only the first 3 errors occur when using a datasette:
- ?FILE NOT OPEN: one of the commands CLOSE, CMD, GET#, INPUT# or PRINT# tries to use a file that has not been opened with the BASIC-command OPEN before.
- ?FILE OPEN: the command OPEN tries to open an already opened (and not closed) file again.
- ?DEVICE NOT PRESENT: the selected device doesn't exist or is turned off; datasette: the file end (EOT) on the tape cannot be identified.
- ?FILE NOT FOUND: no file of that name seems to exist (check spelling)
- ?FILE EXISTS: occurs when giving a file a name already reserved for another file on that disk.
See also Drive command.
OPEN 50, 0 (another way for keyboard input) OPEN 1, 1, 0, "FILENAME"
(Reading a file from datasette)
OPEN 1, 1, 1, "FILENAME"
(Writing a file on datasette)
OPEN 1, 1, 2, "FILEEND"
(Writing a file on datasette with file end (EOT)) OPEN 1, 2, 0, CHR$(10)
(open the RS-232 or modem) OPEN 11, 3
(Example output on screen) OPEN 5, 4, "Control Character"
(Use a control char at printer)
OPEN 4, 4, 0, "CAPITAL LETTERS"
(Only capital letters on printer)
OPEN 3, 4, 7, "Capital-/Small Letters"
(capital-/small letters on printer) OPEN 1, 8, 8, "FILENAME, SEQ, R"
(1. disk drive for reading a sequential file)
OPEN 2, 9, 4, "FILENAME, SEQ, W"
(2. disk drive for writing to a sequential file)
OPEN 1, 8, 8, "FILENAME, REL, R"
(1. disk drive for reading relative file)
OPEN 1, 8, 8, "FILENAME, USR, R"
(1. disk drive for reading a User-file)
The file type specifications SEQ, REL, USR might be specified by their first letter only, i.e. S, R, U.
OPEN 1, 8, 15, "N:DISKNAME,ID"
(Command for formatting a disk with name and ID.)
- Channel 0 and 1 are officially dedicated to LOAD and SAVE. They differ from normal channels in that the file type is always PRG and the mode is "read" for channel 0 and "write" for channel 1. With this convention the KERNAL does not need to add ",p,r" or ",p,w" to the filename. If this behavior suits your program, nothing stops you to use channel 0 and 1 in your own programs.