Recently I commented on how an INPUT# command can cause execution to hang on a Commodore home-computer if the device for which it is intended is not on the IEC bus. I thought to provide some more details on what the right course of action is to avoid the hanging and what one might be doing that causes a hanging.
In a BASIC program genuinely interested in working with a disk drive, such as the ones listed in Inside Commodore DOS, it is not uncommon to read something along these lines:
10 OPEN 15,8,15 20 PRINT#15,"I0" 30 INPUT#15,EN$,EM$,ET$,ES$ 40 IF EN$="00" GOTO 70 50 PRINT EN$", "EM$","ET$","ES$ 60 END 70 REM PROCEED FURTHER WITH DRIVE 8 ... 200 CLOSE 15
The lesson to take home here is that at the beginning of a disk utility you issue a disk initialization (line 20). This operation fails with “?DEVICE NOT PRESENT ERROR IN 20” if drive number 8 is not on the IEC bus. And that’s all good as we don’t get to line 30 where execution would hang.
Now let’s suppose we remove line 20 because we want to check the DOS version of a drive at power-on or after a drive reset. A 1541 would return:
73,CBM DOS V2.6 1541,00,00
However, if drive 8 is not on the IEC bus and the above BASIC program is run without line 20, execution hangs at line 30 (executing the loop at $EDD6 – on a Commodore 64 – until the serial clock is pulled low by the non-existing device, which obviously does not happen).