Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NOTE and POINT statements. #79

Open
rickcollette opened this issue Dec 6, 2023 · 3 comments
Open

Implement NOTE and POINT statements. #79

rickcollette opened this issue Dec 6, 2023 · 3 comments

Comments

@rickcollette
Copy link

Hi, I am wondering if there is an example of the following Atari BASIC in FastBASIC?

10 OPEN #1,8,0,"D:MYFILE.DAT":NOTE #1,MSECT,MBYTE
20 FOR Y=1 TO 10:? #1;B$:NEXT Y:CLOSE #1
30 OPEN #1,8,0,"D:MYFILE.CFG"
40 ? #1;MSECT;CR$;MBYTE

"NOTE" is what I am missing - and maybe there is a better way to handle file IO
Basically the thing I want to solve is creating a datafile, and then tracking the BYTE and SECTOR for indexed retrieval.

Use cases:
Mailing list Database
User data (Passwords and email addresses)
Message Database (For a BBS)

@rickcollette
Copy link
Author

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$

@dmsc
Copy link
Owner

dmsc commented Dec 8, 2023

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!

@dmsc dmsc changed the title Request for Example code: File IO Implement NOTE and POINT statements. Dec 8, 2023
@rickcollette
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants