fastbasic icon indicating copy to clipboard operation
fastbasic copied to clipboard

Implement NOTE and POINT statements.

Open rickcollette opened this issue 2 years ago • 3 comments

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 avatar Dec 06 '23 16:12 rickcollette

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$

rickcollette avatar Dec 08 '23 16:12 rickcollette

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 avatar Dec 08 '23 23:12 dmsc

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

rickcollette avatar Dec 08 '23 23:12 rickcollette