FemtoBASIC for P2
David Betz
Posts: 14,516
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.
Comments
https://github.com/parallaxinc/propeller/blob/master/libraries/community/p1/All/FemtoBasic/FemtoBasic Manual.pdf
Oddly, it doesn't describe an IF statement although I'm sure FemtoBASIC has one.
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.
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?
anyway...femto was an extra layer...an actual os should be that layer...an os is a compiler
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.
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.
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.
Looking forward to seeing your ideas too
You said it would be different ...
I think it could be both... a mixed 1080p mode for coding with vga graphics window that could be full screened via user interface
Super Femto Basic is one
But, sky is wide open...
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.
https://forums.parallax.com/discussion/170638/p2-rom-monitor-debugger-rev-1-rev-2-silicon
how similiar is the code that they both use?
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.