Testing the new Fastspin Assembly, Spin, BASIC, and C for P1
rsut
Posts: 45
I thought I would start this new thread for users trying out Fastspin basic rather than posting to the author's thread which focuses on the development.
Hopeful the author will make suggestions to users that post code here. Reading the thread, there are going to be some changes to fastspin basic which may, effect the syntax a little, but hopefully not the style.
My first contribution, a very simple piece of code to demonstrate a function using fsrw.spin and FullDeplexSerial.spin which I tried whilst exploring fastspin(basic). There are probably better ways to do this. Fastspin(basic), is still in under development so do expect to have to make changes.
Give it a try
Ron
Hopeful the author will make suggestions to users that post code here. Reading the thread, there are going to be some changes to fastspin basic which may, effect the syntax a little, but hopefully not the style.
My first contribution, a very simple piece of code to demonstrate a function using fsrw.spin and FullDeplexSerial.spin which I tried whilst exploring fastspin(basic). There are probably better ways to do this. Fastspin(basic), is still in under development so do expect to have to make changes.
rem very simple test of a fastspin(basic)function with fsrw26.and FullDuplexSerial. rem rem test returns a value from spin object. rem abort is a known issue ATM, refered to author of fastspin(basic) rem compile code code with ...............propeller-load -e -p<com port> -r -t %1.eeprom rem load eeprom with....... ................. fastspin --fcache=0 -e -O1 %f dim sd as class using "fsrw.spin" dim ser as class using "FullDuplexSerial" dim mode as ubyte dim file_name as string dim text as string dim len as integer function wrfile(file_name$, text$, len) dim message as string dim x as integer message = "Writing file done...... val returned from pub sd.popen h_" mode= asc("w") x=sd.popen(file_name$,mode) sd.pwrite(text$,len) sd.pclose() ser.str(message) ser.hex(x, 4) end function REM Test wrfile function ser.start(31,30,0,115200) pausems (1000) sd.mount(0) wrfile("data5.txt","This is a test",14) sd.unmount()
Give it a try
Ron
Comments
Thanks for posting
I don't think there will be any major changes to syntax that will affect existing fastspin BASIC programs now, but I am adding new features. Definitely one thing I want to add is an easy way to use BASIC functions like print with the fsrw (and similar) objects.
(BTW, try/catch is in the current source code repository and seems to be working. I hope to make a new binary release this weekend.)
These functions seem work OK. I need to look at the returns from spin methods more closely,
so that I can use them, but at the moment I can't catch *aborts* so I can't see the return results.
Fsrw.spin has countless * aborts*
I understand we might see a new exe version next week. Eric has included a try/catch scheme in the upcoming release.
Writing fastspin(basic) feels quite intuitive, but having used propbasic for a while and without LMM
(although it's available) I'm not yet comfortable with how to best write code to minimise the code size.
I do like the fact than you can use spin instructions in fastspin(basic)
I have yet to look at writing code for a cog with fastspin basic.
Here is my take on functions coded in fastspin basic.
Ron
Have you tried the new fastspin 3.9.7 yet? It uses a lot less COG memory and has some nice new features (like the LEN function). The reduction in COG memory lets us hook up the BASIC I/O routines to Spin, so you can do things like:
The only thing that isn't working correctly right now is that "close #2" is messing up the rest of the program, due to a bug in the BASIC close function. I've already fixed that in the github source release so it'll be in the next binary release too.
But I seem to have different Spin library versions here: It builds fine when I use the single argument (pingroup) mount call or when I add 3 zeroes as the missing args.
This is due to the C3 adaption. I would not need C3 support for the Propeller-Platform+SD board but I didn't find the other (not C3ified) versions of `fsrw` and `safe-spi`.
It's too late for me to dive deeper into this today.
I'll look at it later...
My last test with `fsrw` mentioned somewhere else worked with "pingroup 0".
I tested it on a file of about 3k and worked fine, albeit a little slow.
Ron
This example is very basic: It just displays a constant picture given as an initialised BASIC array. So there is no need to have subroutines to set pixels. The program is just starting the (Spin) graphics engine to turn the BASIC array into VGA signals.
The initialisation of the graphics is very similar to the example above but the bitmap array is not a constant. Pixels calculated by a simple iteration are drawn forever.
The constants defining the iteration and the scale factor for displaying the results are set in the source code.
Right?
This program uses [Kwabena W. Agyeman]'s "VGA64 Bitmap Engine" to display a 320x240x2 image. Its initialisation is slightly different than in the monochrome examples above and its drawing routine and named constants for the colours are used from BASIC.
The Mandelbrot algorithm is run in 16 bit rational arithmetic with 12 bit accuracy (1/4096) for the broken part. That's enough for some simple pictures but for deeper zooms you'd need 32 bit rationals or floating point. The main focus of the example is how to interface this VGA engine, so using the faster and a bit less accurate arithmetic is ok here.
What if you want to experiment with some graphics, but your Propeller board lacks TV or VGA output?
Run it "headless", i.e. calculate the picture and output it e.g. via the usual serial connection to the PC or save calculated pictures to a SD card... there are lots of workarounds.
This example calculates the Mandelbrot image line per line and instead of storing it in a bitmap, each pixel's "result" is printed when it got calculated. I'm not good with colours, so I used PGM, a grayscale picture file format. Using a RGB file format would not have been more complicated. Click a description of the PPM file format for more. ;-)
And surprise: A side effect of not needing a large bitmap in RAM is being able to generate much larger images. \o/
Btw.: This Mandelbrot calculation variant uses BASIC's single precision floating point type.
The captured output, the PGM image, was converted to PNG format for being displayable here and for compactness.
I wrote this one for Spin, but maybe can work here too...
http://www.rayslogic.com/propeller/programming/PropMonitor/PropMonitor.htm
Wait, probably not with Kye's driver though...
Or: Bilingual without Spin? Spin and PASM hide under the hood in this example, so it actually involves all 4 languages FastSpin currently can handle.
This thread fell asleep?
@rsut would it be ok for you to widen the focus of this thread?
I think striking through or removing the "basic" in the title ("Testing the new Fastspin basic compiler for P1") to allow all FastSpin languages here would make more sense than starting an other thread for "FastSpin on P1 stuff except BASIC".
Edit@20190904: Newer FastSpin BASIC can declare 2 dimensional arrays directly.
—▷ https://github.com/totalspectrum/spin2cpp/blob/master/doc/basic.md#arrays
(preparing for a flaming )
The best starting place is spin2gui, which is an IDE that supports all of the languages fastspin has. It can be downloaded from my patreon page at https://www.patreon.com/totalspectrum or from github at https://github.com/totalspectrum/spin2gui/releases.
Yeti has some great resources at http://yeti.freeshell.org/orgy/fastspin/fastspin.html.
No kidding; where do you guys find the time????
Brilliant stuff
Dave
Agreed....only just became aware of this stuff.
Totally appreciate everything but it seems hidden in plain sight.
I have never known of so many great contributions that are never brought to the forefront....I thought it was only PropBASIC that was underexposed.
\o/
Interesting.
Mike
Gear has it's problems, but Gear and SpinSim are like virtual Propeller boards with some standard features and so both are nice for documenting things by screenshots or console logs (SpinSim).
I had to modify Gear's VGA plugin to double or even quadruple the scanline (pixel) length (depends on the VGA object in use) to get a normal looking x:y ratio but that was no big deal: They come as C# sources.
Edit: Nah! Gear's master branch still crashes here (Debian10, Mono-5.$WHATSOEVER) after loading the Propeller binary.
:-(