Testing the new Fastspin basic compiler for P1

rsutrsut Posts: 27
edited October 20 in Propeller 1 Vote Up0Vote Down
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.
rem very simple test of a fastspin(basic)function with fsrw26.and FullDuplexSerial. 
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")
     ser.hex(x, 4)     
 end function
REM Test wrfile function
pausems (1000)
wrfile("data5.txt","This is a test",14)

Give it a try


  • 9 Comments sorted by Date Added Votes
  • Cluso99Cluso99 Posts: 14,054
    edited October 18 Vote Up0Vote Down
    I see that you can use existing spin object. That's really nice :)
    Thanks for posting
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
  • Thanks for starting this thread, Ron.

    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.)
  • rsutrsut Posts: 27
    edited October 20 Vote Up0Vote Down
    I did some more tests last night.

    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.
    rem A test of fastspin(basic) function with fsrw26.and FullDuplexSerial. 
    rem last updated 19/10/18
    rem  test  return value from spin methods.
    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"
    REM ====================GLOBAL Variables ======================
    dim ubuf(256) as ubyte      REM   buffer for read_file   256  is a dummy val  to test function
    dim mode as ubyte             REM   Holder of  vals asc "a",asc"r",asc"w",asc"d" 
    dim file_name$ as string    REM   File name str--Only one file can be opened at any one time in  fsrw.spin
    dim lx as word                   REM  Used in Subs and Func to hold str(len)
    dim rtx as word                 REM   Holder of val ireturned from a spin  method
    dim message as string       REM   General purpose message holder
    dim fcnt as short               REM  Total # .of chars written to file
    rem ===========================================================
    REM Used for append and write only. A mode error will cause the test prog to Abort.ATM
    function update_file( file_name$,mode,text$)           lx = strsize(text$)                                               
         if (rtx=0) then
             fcnt=fcnt + lx    REM    TODO ---create a log file to save fcnt 
     end function
     function read_file( file_name$,fcnt)       REM== Get fcnt from log file
     end function
     sub newline()
    end sub
      REM Test file functions
    pausems (1000)
    update_file("file3.txt",asc("w"),"New data saved....")
    update_file("file3.txt",asc("a"),"New data appended")
    if (rtx=0) then
       message = "File was successfully updated, now to read the file "
       ser.str (message)
       read_file( "file3.txt",36 )    REM 36 is just a dummy to test the function
        message = "Error  "
    end if   

  • 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:
    ' basdemo.bas
    dim fsrw as class using "fsrw.spin"
    const D0=22, CLK=23, DI=24, CS=25
    sub openfile(n as integer, name as string, mode as string)
      dim r
      r = fsrw.popen(name, asc(mode))
      if r < 0 then
        throw r
      end if
      open SendRecvDevice(@fsrw.pputc, @fsrw.pgetc, @fsrw.pclose) as #n
    end sub
    dim err
    dim s$
    dim cycles as uinteger
    dim c as integer
      fsrw.mount_explicit(D0, CLK, DI, CS)
      print "testing write"
      openfile(2, "hello.txt", "w")
      print #2, "Hello from basdemo.bas"
      cycles = getcnt()
      print #2, "When this was written, cycles = "; cycles
      print #2, "Goodbye!"
      fsrw.pclose()  ' should be close #2, but close has a bug right now
      ' try reading it back
      pausems 1000
      print "testing read"
      openfile(2, "hello.txt", "r")
      print ".. input"
      s$ = input$(80, 2) ' 80 is a bit of a hack, I happen to know everything fits in 80 bytes
      if s$ then
        print "read back:"
        print s$
        print "got end of file"
      fsrw.pclose() ' should be close #2, but close is bugged
      print "all done"
    catch err
      print "caught error: "; err
    end try

    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.
  • yetiyeti Posts: 436
    edited October 22 Vote Up0Vote Down
    `basdemo.bas` looks really good!
    But I seem to have different Spin library versions here:
    $ make build
    /opt/spin2cpp/bin/fastspin -O2 basdemo.bas
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc.
    Version 3.9.8-beta Compiled on: Oct 22 2018
    basdemo.bas(22) error: Bad number of parameters in call to Mount_explicit: expected 7 found 4
    Makefile:24: recipe for target 'basdemo.binary' failed
    make: *** [basdemo.binary] Error 1
    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...
    ◁ Stay OmmmmmmPtimistic! ▷ ◁ No Source – No Go! ▷ ◁ Please help: http://rosettacode.org/wiki/Category:Spin ▷ ◁ Why Asimov's Laws of Robotics Don't Work - Computerphile ▷ ◁ DNA is a four letter word. ▷
  • I was using the fsrw26.zip version of fsrw. It does seem that there are several floating around. I think either of your solutions (adding zeros for the missing args, or using the pingroup form) should work.
  • Yes.
    My last test with `fsrw` mentioned somewhere else worked with "pingroup 0".
    ◁ Stay OmmmmmmPtimistic! ▷ ◁ No Source – No Go! ▷ ◁ Please help: http://rosettacode.org/wiki/Category:Spin ▷ ◁ Why Asimov's Laws of Robotics Don't Work - Computerphile ▷ ◁ DNA is a four letter word. ▷
  • My sample program was flawed in that it only did one input$() call (because I happened to know that the file was short, but in general this isn't the case). The read back routine should look more like:
        s$ = input$(1, 2)  ' read back 1 byte at a time from handle 2
        print s$;
      loop until s$ = ""
    The decision about how many bytes to read is pretty arbitrary; 1 is the smallest possible, but for better performance you might want to chunk the reads and use "s$ = input$(20, 2)", or whatever. Either way input$ will read as much as it can up to the number of bytes specified, and return a string with that many bytes. At the end of input the string will be short, but that's OK; and reading past end of file will give an empty string.

  • I did the same.
    #ifdef TRY_READ
      pausems 500
      ' try reading it back
      print "testing read"
      openfile(3, "test2.txt", "r")
      s$ = input$(1, 3)
     do while s$ 
         print s$;
         s$ = input$(1, 3)
        print "got end of file"
      close #3
      print "all done"
    catch err
      print "caught error: "; err
    end try

    I tested it on a file of about 3k and worked fine, albeit a little slow.


Sign In or Register to comment.