Comments (3)
For sequential (I would still like to understand binary files) files - this is what I am doing currently:
Write then read and print line by line
' Open the IOCB channel for writing a file
OPEN #1, 8, 0, "D:example.txt"
' Write some lines to the file
PRINT #1, "Hello, FastBasic!"
PRINT #1, "This is a test file."
PRINT #1, "End of file."
' Do not forget to close the open channel
CLOSE #1
' Now, lets read what we wrote:
OPEN #1, 4, 0, "D:example.txt"
WHILE ERR() < 128
INPUT #1, A$
IF ERR() <> 136
? A$
ENDIF
WEND
CLOSE #1
Write then read into a buffer and print buffer
' Open the IOCB channel for writing a file
OPEN #1, 8, 0, "D:example.txt"
' Write some lines to the file
PRINT #1, "Hello, FastBasic!"
PRINT #1, "This is a test file."
PRINT #1, "End of file."
' Do not forget to close the open channel
CLOSE #1
' Now, lets read what we wrote:
OPEN #1, 4, 0, "D:example.txt"
WHILE ERR() < 128
INPUT #1, A$
IF ERR() <> 136
LINE$=+A$
LINE$=+CHR$(155) ' add a return here
ENDIF
WEND
CLOSE #1
' lets print the lines we collected
? LINE$
from fastbasic.
Hi!
Yes, currently FastBasic lacks the NOTE and POINT Atari statements. You can emulate them with XIO currently:
' Emulates "NOTE", returns values in "SEC" and "BYT" variables
PROC Note
XIO #1,38,4,0,""
SEC=DPEEK($35C)
BYT=PEEK($35E)
ENDPROC
' Emulates "POINT"
PROC Point PointSec PointByt
DPOKE $35C, PointSec
POKE $35E, PointByt
XIO #1,37,4,0,""
ENDPROC
' Open a "big" file, read 20 lines and then "note" the position
OPEN #1,4,0,"D:MANUAL.TXT"
? "Skiping..."
FOR L=1 TO 20
INPUT #1,A$
NEXT L
@Note
INPUT #1,A$
?"Line 21: "
? A$
CLOSE #1
? "Line 21 File Position: ";SEC,BYT
?
' Open the file again, and go to the saved position:
OPEN #1,4,0,"D:MANUAL.TXT"
@Point SEC, BYT
? "Read Again:"
INPUT #1,A$
? A$
CLOSE #1
You must be careful when using XIO like that, do not overwrite the value of AUX1 (the "4" above), as it will mess up with the DOS calls if it is different than the one used in the OPEN call.
Have Fun!
from fastbasic.
Excellent - I'll make sure to wrap this up with lots of error and bounds checking ;)
from fastbasic.
Related Issues (20)
- cc65 as submodule HOT 2
- output minified listings HOT 2
- ADR() on string array doesn't seem to work HOT 7
- libstdc++.6 removed in ventura. recompile using libstdc++ HOT 9
- Running cross compiler from PATH HOT 3
- Support for other DOS , problem with blank ATR HOT 2
- Proposed enhancement FUNCTION or DEF FN HOT 1
- Enhancement Request - add Image Get and Put HOT 2
- Enhancement request: support floating point variables in FOR HOT 2
- partial reserved word matching in variables HOT 2
- test fails HOT 2
- clang warnings HOT 2
- Interoperability with Fujinet N: device HOT 6
- Atari BASIC Call "STATUS" for RS232 HOT 5
- Support for TRAP statement
- Editor in FB.COM: Bug when pressing Ctrl-DEL at end of sourcefile HOT 1
- Question on virtual disk access HOT 9
- Calling PROCs with array arguments doesn't work HOT 2
- help with assembler HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastbasic.