Device number
Device numbers are numbers that identify various peripheral devices connected to (or, in some cases, built into) the C64: The device number is used when creating logical files through the KERNAL file system; see OPEN (BASIC command) and OPEN (KERNAL routine).
The first four device numbers relate to various hardware that requires the CPU, memory and other resources of the core C64:
- 0 is the keyboard.
- 1 is the datassette, if any is connected.
- 2 is the RS232 interface.
- 3 is the text screen.
Device numbers above 3 all refer to devices connected through the serial port. They are all handled in exactly the same way from KERNAL's point of view, but by convention:
- 4 and 5 are printers.
- 6 and 7 are plotters.
- 8 thru 30 are disk drives.
Often the default device number of printers, plotters and disk drives can be changed via dip-switches.
Example Code[edit]
The following code can be used to change, temporarily, the device number of Commodore disk drives (such as 1541 or 1571) to a number between 8 and 30:
OPEN 15,8,15:PRINT#15,"M-W";CHR$(119);CHR$(0);CHR$(2);CHR$(device number+32)+
CHR$(device number+64):CLOSE 15