Device number

From C64-Wiki
(Redirected from device number)
Jump to navigationJump to search

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. 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.

Number Device Description
0 Keyboard Special routine through KERNAL
1 Datasette Special routine through KERNAL
2 RS-232 or Modem Special routine through KERNAL
3 Monitor or text screen Special routine through KERNAL
4 First Printer from 4: for IEC devices
5 Second Printer
6 e.g. first Plotter
7 e.g. second Plotter, RAM-Disk
ab 8 Floppy, Harddisk or other hardware like SD2IEC etc.


Often the default device number of printers, plotters and disk drives can be changed via dip-switches.

Example Code[edit | edit source]

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