GithubHelp home page GithubHelp logo

Comments (3)

rickcollette avatar rickcollette commented on June 12, 2024

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.

dmsc avatar dmsc commented on June 12, 2024

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.

rickcollette avatar rickcollette commented on June 12, 2024

Excellent - I'll make sure to wrap this up with lots of error and bounds checking ;)

from fastbasic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.