Shop OBEX P1 Docs P2 Docs Learn Events
Flash file driver for P2 and FemtoBasic version for P2 — Parallax Forums

Flash file driver for P2 and FemtoBasic version for P2

Mike GreenMike Green Posts: 23,101
edited 2021-12-27 22:37 in Propeller 2

Attached is a ZIP file of a flash file system driver for the P2 based on the same driver for the P1. Also included is a version of FemtoBasic used to exercise the driver. This includes some extensions including one-dimensional arrays. Note this is experimental and is still being debugged. It does create and delete files and will write to a new file. It compiles using FLEXPROP on a Mac Pro. I've not tried it recently using PNut. This version of FemtoBasic does not support SD cards, only flash memory. That will change eventually.

I will post any changes / updates here.

This version of FemtoBasic has some simple floating point included. See the manual file. Note that there are not any floating point operators, but you can do floating point operations (IEEE-754) on integer values.

Comments

  • See attached ZIP file

  • Now allows FLOAT[ "" ] so floating constants can be included in a program.

    You may be asking "what's the reason for having FemtoBasic and updating it frequently?"

    FemtoBasic while allowing some programming of a P2 with nothing but a serial terminal
    is really intended as a testbed for other code like the flash driver and floating point. It's
    very easy to add or modify statements in the interpreter, exercise new I/O devices,
    control some I/O devices directly with the I/O pins, etc. Even though the floating point
    functions are very awkward to use, they were easy to add and can make some floating
    point possible to use.

  • Hey Mike,

    Should I be getting excited about this becoming a full-blown resident interpreter? :smiley:

  • It depends on what you mean by "full-blown". I don't think the design is suitable for a "standard" Basic interpreter. It would need to be rewritten with that in mind. I think it's reasonable to add some mechanism to allow for mixed integer and floating point variables and to extend the arithmetic operators to handle them appropriately. It's also reasonable to add back in the ability to use SD cards ... although I would need a stable I/O driver like the P1 version of FSRW.

    The additional memory and speed of the P2 over the P1 is what makes this possible. Thanks Chip and everyone else who contributed.

  • @"Mike Green" said:
    Now allows FLOAT[ "" ] so floating constants can be included in a program.

    You may be asking "what's the reason for having FemtoBasic and updating it frequently?"

    FemtoBasic while allowing some programming of a P2 with nothing but a serial terminal
    is really intended as a testbed for other code like the flash driver and floating point. It's
    very easy to add or modify statements in the interpreter, exercise new I/O devices,
    control some I/O devices directly with the I/O pins, etc. Even though the floating point
    functions are very awkward to use, they were easy to add and can make some floating
    point possible to use.

    Mike, I get some errors when trying to run your code in PNut35r or PropTool

    pub startConsole(rxpin, txpin, mode, baudrate) | bitperiod, bit_mode
      'rxpin, txpin are defined constants, so these need to be something different, I changed them to rxpin1, txpin1
      'in the routine
    
    pri autobaud(pin) : delay | a, b, c, port, mask  'Moved delay to be return variable
    waitx(1000)  'Line 277, undefined routine, I haven't checked to see if this is equal to waitms or waitus
    if pin >= 32  'Changed to >= from =>
    pinwrite(a,specialExpr())  'Line 1372 was mssing a set of ()
    pinsetup(a,b,c,d)  'Line 1478, undefined routine
    

    I can get it to compile and download after the above changes (or commented out the unknown routines).

    I haven't yet figured out how to get it to work with the Parallax Serial Terminal.

    I'll have to spend more time on it later, I need to get back to what I was working on...

  • Thanks for your message. I'll make the changes and post them with the next update. Flexprop and PNut are not quite compatible with each other and I haven't been able to get PNut to run on my Mac using either Wine, CrossOver, or Parallels Desktop + Windows 10.

    The Parallax Serial Terminal should work. FemtoBasic only uses Backspace, Carriage Return, Linefeed, and displayable characters for serial output and Backspace, Carriage Return, Escape, and displayable characters for serial input. You have to type a character for autobaud timing when FemtoBasic first starts up. You can recompile it with a fixed Baud (see line 45 in TestFlash.spin2).

  • I've had no problem running PNut (& Propeller Tool) via Parallels Desktop on macOS 12.1... What issues do you see?

    dgately

  • I've had problems reinstalling Windows 10 after upgrading to the latest Parallels Desktop after installing MacOS 12.1. I'll try again probably after New Years. Thanks for the info.

  • Mike,

    I realized today that I was working with the previous version of TestFlash without the Float additions, which I was able to get to at least compile in PNut35r with the above items/changes I mentioned done.

    What did you use for the FloatMath.spin2 and FloatString.spin2 libraries in the latest version? They weren't in your zip file and I haven't found any anywhere else...

    There are spin1 versions in the zip file, so I'm confused as to what libraries were used.

    Granted, Spin2 now has float operations internally and the code probably needs conversion to Spin2 style float syntax.

  • I've been using FlexProp and I just grabbed the Spin1 versions. Apparently FlexProp very happily compiled those into P2 instructions along with all the rest of the Spin2 stuff. I did get Parallels Desktop and Windows 10 running and I'll install PNut so I can make sure TestFlash works with PNut as well as FlexProp ... probably after New Years'.

  • Attached is the New Year's version of FemtoBasic, Winbond_Driver, and BinFloat. You can use flash for storing Basic programs and text (data) files including the ability to delete files and list all filenames on flash. I'm still exercising the driver, but it seems reliable.

    There's still only limited support for floating point in FemtoBasic, but what's there seems to work. FlexSpin is the compiler I'm currently using. I will check from time to time to make sure this all compiles with PNut as well.

    I've included an example of the use of floating point. The program itself is not correct, but it will run.

    Next steps: More testing. Add floating point to INPUT statement.

  • @"Mike Green" said:
    Attached is the New Year's version of FemtoBasic, Winbond_Driver, and BinFloat. You can use flash for storing Basic programs and text (data) files including the ability to delete files and list all filenames on flash. I'm still exercising the driver, but it seems reliable.

    There's still only limited support for floating point in FemtoBasic, but what's there seems to work. FlexSpin is the compiler I'm currently using. I will check from time to time to make sure this all compiles with PNut as well.

    I've included an example of the use of floating point. The program itself is not correct, but it will run.

    Next steps: More testing. Add floating point to INPUT statement.

    Thank you, Mike. I'm able to compile and run it successfully now using PNut35r. I'll experiment around with it more as time permits.
    Let me know if there are anything you want me to exercise or try...

  • Please exercise the flash memory file system. ERASEDATA, READDATA, and WRITEDATA use the low level I/O routines and are all directly usable as Basic statements. FILES, OPEN, CLOSE, SAVE, LOAD, DELETE, READ, and WRITE use the file system from Basic. Next step is to provide for the loading and execution of a binary program from flash similar to what you can do in P1 FemtoBasic.

    The floating point stuff uses Eric Smith's BinFloat.spin2 (Very much thanks Eric). The changes to FemtoBasic for this are there only to make it possible to exercise BinFloat from FemtoBasic, not necessarily conveniently. I have some ideas as to how to make this smoother with automatic conversion between floating point and integer.

  • Here's the next version. There's no change to the flash memory I/O. The floating point stuff is still being debugged, but much seems to work. Numeric values carry a type with them ... integer and floating point. Operators like "+", "-", "*", "/" (and others) work the way you might expect with + done using floating point with a floating point result. + is done with integer arithmetic and an integer result. Mixed types are usually forced to floating point. Functions like SIN, COS, ATAN, EXP, LOG all promote their argument to floating point and produce a floating point result. INPUT and READ will set the type of the input variable based on the input data. A decimal point or exponent will force floating point. PRINT and WRITE will format based on the type of value used. Note that array elements are all of the same type, set by the initial value given in a DIM statement. Things like FOR statements force the initial value, limit, and step all to integer.

  • This version compiles under both Propeller Tool and flexprop.

  • @"Mike Green" said:
    This version compiles under both Propeller Tool and flexprop.

    Mike,

    With your latest posted version the 'NewtonRaphson.bas' program won't run due to the following errors:

    100 a = FLOAT [0] <-- Syntax error in expression

    It appears that the syntax now wants ( ) not [ ].

    Line 1030 complains about missing a '=' even after you change [ ] to ( ), so I'm not sure what is happening...

    The last two versions you posted have the testver variable set to 11 and 15. The previous one has it set to 22. I don't understand the numbering...

  • Francis,
    Thank you. I need to pause a little and revise the documentation. The use of [ ] in P1 FemtoBasic was to make things easier to parse for functions and statements that need parameters. I'm trying to change this back to the use of ( ) where possible. The latest versions of TestFlash allow floating point constants that have a decimal point, so
    100 a = 0.0
    is allowed

    The complaint about a missing "=" usually means that there's an error in the preceeding variable name. I'll look into that.

    I've been using testver as a number, but displaying it as a letter. Once it got to "z", I reset it. I'll just use a number.

  • Here's a newer version. I've only supplied the copy compiled with PNut35r. When compiled with FlexProp under MacOS, it exhibits some bugs that don't show up in the PNut version.

    I've corrected some errors in the Manual and added some new features to it.

    I've left out the sample program for now. I'll rewrite it and include that in the next version I post.

Sign In or Register to comment.