Skip to content

Implement NOTE and POINT statements. #79

Open

Description

@rickcollette

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)

Activity

  1. rickcollette commented on Dec 8, 2023

    @rickcollette
    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$
    
  2. dmsc commented on Dec 8, 2023

    @dmsc
    Owner

    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!

  3. changed the title [-]Request for Example code: File IO[/-] [+]Implement NOTE and POINT statements.[/+] on Dec 8, 2023
  4. rickcollette commented on Dec 8, 2023

    @rickcollette
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions