Input loop: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Simpler.) |
(Added Commodore BASIC) |
||
Line 489: | Line 489: | ||
200 IF PEEK(222) <> 5 THEN RESUME |
200 IF PEEK(222) <> 5 THEN RESUME |
||
210 PRINT D$"CLOSE"F$</lang> |
210 PRINT D$"CLOSE"F$</lang> |
||
==={{header|Commodore BASIC}}=== |
|||
This example should generally work across all Commodore models. It is important to note that when using the reserved variable STATUS (or ST for short) to detect the end of file marker (bit 6), the KERNAL updates this variable based on ''any'' previous I/O operation, including the OPEN command, but makes no indication as to which I/O access the status applies to. Therefore, it is best to open the command file number and channel (15) ''before'' opening the actual file on disk or tape and leave it open while the file is opened and operated on as shown in the example. |
|||
<lang CommodoreBASICv2> |
|||
10 rem input loop - rosetta code |
|||
15 print chr$(147);chr$(14);:rem clear screen, switch to lower case |
|||
20 input "filename";f$ |
|||
25 if f$="" then end |
|||
30 open 15,8,15:open 5,8,5,f$+",s,r" |
|||
40 gosub 1000 |
|||
50 if er=62 then print "that file is not found. try again.":goto 20 |
|||
60 if er<>0 then print "there was an unexpected error.":gosub 1100 |
|||
70 get#5,a$ |
|||
80 if st and 64 then close 5:close 15:end |
|||
90 print a$;:goto 70 |
|||
1000 rem check command channel for error |
|||
1005 rem error number, error msg$, track number, sector number |
|||
1010 input#15,er,er$,tk,sc |
|||
1020 return |
|||
1100 rem print error |
|||
1110 print:print er;"- ";er$;" track:";tk;"sector:";sc |
|||
1120 return |
|||
</lang> |
|||
==={{header|BBC BASIC}}=== |
==={{header|BBC BASIC}}=== |