long post containing BASIC code
been looking through the sample tutorials of Stefan's Tiny BASIC to try and work out exactly how it handles file operations...
10 REM "Simple FILE I/O demo"
20 REM ""
30 N=4
40 DIM A$(80)
100 PRINT "Write squares to file"
110 OPEN "daten.txt",1
120 FOR I=1 TO N
130 PRINT I, I*I
140 PRINT &16, I
150 PRINT &16, I*I
160 NEXT I
170 CLOSE 1
200 PRINT "Read data as numbers"
210 OPEN "daten.txt"
220 FOR I=1 TO N
230 INPUT &16, A
240 INPUT &16, B
250 PRINT "Read "; A; "^2="; B
260 NEXT
270 CLOSE 0
300 PRINT "Read data as strings, use EOF status"
310 @S=0
320 OPEN "daten.txt"
330 IF @S<>0 THEN PRINT "OPEN failed" : END
340 FOR I
350 INPUT &16, A$
360 IF @S=-1 THEN BREAK
370 PRINT "Line",I,"string '";A$; "' Status = " @S
380 NEXT
390 CLOSE 0
400 PRINT I, "lines read"
410 PRINT "Status =", @S
500 PRINT "Read Character by Character use EOF status"
510 @S=0
520 OPEN "daten.txt"
530 IF @S<>0 THEN PRINT "OPEN failed" : END
540 FOR I=1
550 GET &16, A
560 PRINT "Character ";I;" :",A
570 IF A=-1 THEN BREAK
580 NEXT
590 PRINT I, "characters read"
600 PRINT "Status =", @S
610 CLOSE 0
700 END
- replies
- 1
- announces
- 1
- likes
- 0
re: long post containing BASIC code
this is the relevant bit of code from EDIT.BAS:
460 REM-----------------------------------------------------------R COMMAND
465 J=1:A2=0:LN=1:I=1:FE=0:GOSUB 470:GOTO 105
470 IF @S=-1 THEN PRINT "EOF1":I=I-1:FE=1:GOTO 495
475 INPUT &16,L$:IF L$="" THEN GOTO 470
480 A2=A2+LEN(L$)
485 L1$(I)=L$:M1(I,0)=I-1:IF I=1 THEN 490 ELSE M1(I-1,1)=I
490 IF I=50 OR A2>2000 THEN GOTO 495 ELSE I=I+1:GOTO 470
495 M1(I,1)=I+1:I=I+1:L1$(I)="END OF BUFFER":M1(I,0)=I-1:M1(I,1)=-1:H=1:IN=I+1
500 FOR I2=IN TO 100:M1(I2,1)=I2+1:M1(I2,0)=I2-1:NEXT
505 M1(IN,0)=0:M1(I2-1,1)=-1:RETURN