Shop OBEX P1 Docs P2 Docs Learn Events
FemtoBASIC for P2 — Parallax Forums

FemtoBASIC for P2

David BetzDavid Betz Posts: 14,511
edited 2020-04-17 14:58 in Propeller 2
Someone suggested recently that it would be nice if there was a Femto2 for P2. Is there a document describing the FemtoBASIC language somewhere? I can find the source code but I haven't found a document describing its features.
«134

Comments

  • David BetzDavid Betz Posts: 14,511
    edited 2020-04-11 16:05
    Excellent! That is what I was looking for. Thanks!

    Oddly, it doesn't describe an IF statement although I'm sure FemtoBASIC has one.
  • Yes, there is an IF statement and I have no idea why no one noticed earlier that I didn't describe it in the manual.

    I hadn't thought yet about redoing it for the P2. Although I can run Windows 10 on my Mac PowerBook Pro using Parallels Desktop, I haven't tried the various programming tools for the P2 (like PNut or FastSpin). I've also stayed on the sidelines while the instruction set was being developed, so I'm not up on it. Maybe it's time to jump in.

    The IF statement looks like: IF <expr> THEN <statement>

    If the expression is non-zero, the interpreter continues after the THEN. If the expression is zero, the interpreter ignores the rest of the line (which may have one or more statements separated by ":").

    Would it be more useful to have a P2 version of PBasic with a P2 compiler and compatible byte-code interpreter? If so, it would be useful to have access to the sources of the compiler/editor and the interpreter.
  • David BetzDavid Betz Posts: 14,511
    edited 2020-04-11 18:13
    Mike Green wrote: »
    Yes, there is an IF statement and I have no idea why no one noticed earlier that I didn't describe it in the manual.

    I hadn't thought yet about redoing it for the P2. Although I can run Windows 10 on my Mac PowerBook Pro using Parallels Desktop, I haven't tried the various programming tools for the P2 (like PNut or FastSpin). I've also stayed on the sidelines while the instruction set was being developed, so I'm not up on it. Maybe it's time to jump in.

    The IF statement looks like: IF <expr> THEN <statement>

    If the expression is non-zero, the interpreter continues after the THEN. If the expression is zero, the interpreter ignores the rest of the line (which may have one or more statements separated by ":").

    Would it be more useful to have a P2 version of PBasic with a P2 compiler and compatible byte-code interpreter? If so, it would be useful to have access to the sources of the compiler/editor and the interpreter.
    You can run FastSpin directly on your Mac. You don't need Parallels. That's what I do. I'm not sure if anyone provides prebuilt executables for the Mac but if you have Xcode installed you can build it yourself. I can also provide prebuilt binaries if that would be useful to you.

    I'm not working on a port of FemtoBASIC but I am working on a version of BASIC to run on the P2. I asked about Femto mainly as an example of a fairly simple version of BASIC that was none the less found to be useful by many people. It's my gold standard at present although I am implementing a more modern BASIC with functions that take parameters, etc. My stretch goal is to get it to generate PASM code but I'm starting with a fairly ordinary virtual machine. What does the PBASIC VM look like?

  • Would it be more useful to have a P2 version of PBasic with a P2 compiler and compatible byte-code interpreter?
    Long-term, I think that would be very cool -- in my mind, I call it P2BASIC. I'm not a tool maker, so I could be wrong, but I think having the PNut source and Spin2 interpreter source is going to provide a neat template for you guys who are experimenting with adding other interpreted languages.
  • how can the compiler be an issue evanh is all over this!

    anyway...femto was an extra layer...an actual os should be that layer...an os is a compiler
  • David,
    I have Xcode installed, but I'm not familiar with its use. Can you point me to an example of building the executable for fastspin on MacOS?

    JonnyMac,
    I had thought of making a variant of FemtoBasic with compatible I/O statements, but it started to take way too much memory for the interpreter. I started looking at compiling PBasic to bytecodes and interpreting that, but got busy with some personal projects and never came back to it. It would be helpful if the PBasic bytecodes for the BS2 were documented, even if proprietary.

    overhere,
    Actually, an OS is not a compiler. It's a layer between the user and the hardware that provides various services to the user's programs like file management, program loading, specialized I/O (like display, keyboard, serial ports, network communications), memory management, etc.

    FemtoBasic provides many of the same services directly and does not use an OS.
  • overhere wrote: »
    how can the compiler be an issue evanh is all over this!
    What is @evanh doing?

  • David BetzDavid Betz Posts: 14,511
    edited 2020-04-11 20:03
    Mike Green wrote: »
    David,
    I have Xcode installed, but I'm not familiar with its use. Can you point me to an example of building the executable for fastspin on MacOS?
    Are you comfortable with command line tools? If so, you can just do this:
    cd <wherever-you-want-your-spin2cpp-repository>
    git clone https://github.com/totalspectrum/spin2cpp.git
    cd spin2cpp
    make
    
    You will find the fastspin executable in the spin2cpp/build directory. I'm not sure though if git is installed by default when you install Xcode. You might have to install that separately.

    If you want to use flexgui, that's a different story. I always use BBEdit and the command line tools.

  • David Betz wrote: »
    You can run FastSpin directly on your Mac. You don't need Parallels. That's what I do. I'm not sure if anyone provides prebuilt executables for the Mac but if you have Xcode installed you can build it yourself.
    The standard FlexGUI .zip file (see my signature for a link) comes with Mac binaries as well as Windows binaries of fastspin and loadp2 prebuilt.

    It also comes with a BASIC to P2 native code compiler, so if you want to you could write your P2 BASIC interpreter in BASIC. That might be an interesting way to bootstrap a self-hosting system.

  • Thanks David. That worked smoothly and the executable runs. I guess it's time to start playing with my P2 Eval Board.
  • RaymanRayman Posts: 13,897
    I’m glad to see Mike green on the case!
  • JonnyMac wrote: »
    I'm not a tool maker, so I could be wrong, but I think having the PNut source and Spin2 interpreter source is going to provide a neat template for you guys who are experimenting with adding other interpreted languages.
    I think the source for the Spin2 interpreter is already available. However, it won't be of much use to language developers until it is documented well enough so people other than Chip can use it. Maybe that's already true. I haven't looked at the code myself. It wasn't true for the P1 Spin interpreter though and I think that is why there weren't more languages designed to use it. Also, since the Spin2 interpreter is not in ROM it isn't useful to use it to save RAM like it was on the P1. However, Chip's code is likely pretty clever and efficient so that might be a good reason to target it with a compiler. I doubt that the Spin2 compiler source code would be of much help since it's written in x86 assembly language.
  • RaymanRayman Posts: 13,897
    edited 2020-04-11 21:54
    No offense intended David...
    Looking forward to seeing your ideas too

    You said it would be different ...
  • RaymanRayman Posts: 13,897
    I’d also be torn between vga or 1080p resolutions ...

    I think it could be both... a mixed 1080p mode for coding with vga graphics window that could be full screened via user interface
  • RaymanRayman Posts: 13,897
    Or were you guys thinking about serial interface only?
  • Rayman wrote: »
    No offense intended David...
    Looking forward to seeing your ideas too

    You said it would be different ...
    Mine will likely not be used by anyone other than me. I have got the simple line editor and the BASIC parser working. I need to do code generation next.

  • RaymanRayman Posts: 13,897
    There’s a lot of opportunity here ...
    Super Femto Basic is one

    But, sky is wide open...
  • Is there any PASM in the P1 version of FemtoBASIC? If not then it might be interesting to try to compile it with FastSpin. It might be pretty easy to get it to run on the P2.
  • The only PASM is in the I/O drivers it uses. Where are the "standard" I/O drivers for an SD card and console serial?
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-04-12 05:08
    @"Mike Green",
    Believe it or not, you can actually use the P2 ROM SD code to read from the SD card, including locating/loading 8.3 files within the FAT32 root directory. Unfortunately there was no room for the write routine - maybe I should publish that.
    You can also use the ROM Monitor code to initialise/read/write to the serial port on pins 63 & 62, as well as loading/dumping cog/lut/hub memory.
    There is an old thread where I explained how to use the ROM Monitor/Debugger routines. They didn't change from RevA but the SD card routines did change.

    Yesterday I compiled Kye's FAT32 spin1 driver as a spin2 program. Note I have removed some seldom used PUB/PRI routines and now I'm sorry I did that :(
    I have had the PASM SD driver done for months. Just a matter of putting it together.
  • Cluso99 wrote: »
    @"Mike Green",
    ...
    There is an old thread where I explained how to use the ROM Monitor/Debugger routines. They didn't change from RevA but the SD card routines did change.

    ...

    https://forums.parallax.com/discussion/170638/p2-rom-monitor-debugger-rev-1-rev-2-silicon
  • Okay, I've got the source for the stripped down version of FemtoBasic (DongleBasic) that uses a serial port for the console. I've identified things that need to be removed (CTRx registers) and things that need to be added or changed (waits, # pins for I/O). The SD card I/O and RAM manipulation need to be rewritten. Smart I/O pins support should be added. Any thoughts on what should come first? How would you use a P2 FemtoBasic when there's already a nice compiler for Basic and a built-in Forth interpreter?
  • mike: i have been studying tinybasic....how similiar femtobasic is an interpreter...but tinybasic is a compiler...

    how similiar is the code that they both use?
  • Mike Green wrote: »
    Okay, I've got the source for the stripped down version of FemtoBasic (DongleBasic) that uses a serial port for the console. I've identified things that need to be removed (CTRx registers) and things that need to be added or changed (waits, # pins for I/O). The SD card I/O and RAM manipulation need to be rewritten. Smart I/O pins support should be added. Any thoughts on what should come first? How would you use a P2 FemtoBasic when there's already a nice compiler for Basic and a built-in Forth interpreter?
    Does the stripped down version work? Are you compiling it using PNut or FastSpin?

  • I'm using FastSpin and I'm getting invalid generated assembly (cmp #0, #0 wz). Attached is my current source. Once I get it successfully compiled and tested, I'll add some features. I'm assuming PNut is Windows-only. That's inconvenient, but I'll move to that if I have to.
  • overhere,
    FemtoBasic is an interpreter. It converts the program as it is entered or read from a file into a compressed form where keywords become single bytes with values over 127. Everything else is stored as entered. Take a look at the source code (above). There's a big CASE statement with one entry for each of the statement keyword bytecodes. There's also a group of subroutines that handles expressions. For example, the GOTO code is one of these CASE entries and it simply calls the Expr routine which returns the value found. There's a search routine that looks up a line number and returns the address of the statement at that line number. GOTO then calls that and changes the execution pointer to the value returned by the search routine.
  • David BetzDavid Betz Posts: 14,511
    edited 2020-04-14 21:46
    deleted
  • David BetzDavid Betz Posts: 14,511
    edited 2020-04-14 21:47
    Mike Green wrote: »
    I'm using FastSpin and I'm getting invalid generated assembly (cmp #0, #0 wz). Attached is my current source. Once I get it successfully compiled and tested, I'll add some features. I'm assuming PNut is Windows-only. That's inconvenient, but I'll move to that if I have to.
    I tried compiling it but it is looking for 'SmartSerial'. Is that your file?

  • Sorry, no. I found that while looking for various P2 resources. Here it is.
Sign In or Register to comment.