fastspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler

1131415161719»

Comments

  • jmgjmg Posts: 13,778
    ozpropdev wrote: »
    004c4 031 030000FF
    004c8 032 D4EC07F6    | copyx		mov	pa,##_copy0		'start video buffer update
    
    In the above example "copyx" should be on the previous line, the AUGS line.
    Here the label "debug" is at the end of the data not the beginning.
    If every relevant line was tagged here, would that be ok for your extract debug data from fastspin .lst files ?
    That would make for a clearer file.
  • ersmithersmith Posts: 3,230
    edited 2019-08-09 - 23:48:41
    jmg wrote: »
    ersmith wrote: »
    If you can find out how to set higher clock speeds on the Mac I'd be delighted to put that into my version of loadp2.

    I presume you mean Baud settings ?

    Yes, I meant baud rate.
    DB: If I use both "-b 230400" and "-l 230400" everything seems to work
    On that topic, I hope loadp2 has no issues with this "-b 3" and "-l 3" ?
    For setting the serial baud rate loadp2 just passes the baud rate through to the OS. The loader baud rate also needs to be set in the P2 loader code, and that just uses the value after "-l" directly. So "-l 3" will probably set your download speed to 3 baud.

  • jmgjmg Posts: 13,778
    ersmith wrote: »
    For setting the serial baud rate loadp2 just passes the baud rate through to the OS. The loader baud rate also needs to be set in the P2 loader code, and that just uses the value after "-l" directly. So "-l 3" will probably set your download speed to 3 baud.

    That's all good then. The final actual baud depends on firmware, as mentioned above.
    I've used a dual plane to produce 24MHz/M, for M < 367, so that '3' yields 8MBd. That's done because some drivers block at the PC side, and refuse large numbers...

  • I tried this on the Mac and it also works. I haven't gotten it to work with 2000000 baud though. Maybe 921600 should be made the default on the Mac?
    loadp2 -t -b 230400 -l 921600 -p /dev/cu.usbserial-P2EEQXU test
    
  • jmgjmg Posts: 13,778
    David Betz wrote: »
    I tried this on the Mac and it also works. I haven't gotten it to work with 2000000 baud though. Maybe 921600 should be made the default on the Mac?
    loadp2 -t -b 230400 -l 921600 -p /dev/cu.usbserial-P2EEQXU test
    

    Yes, it makes sense to use a default that is reliable and portable :)
    What messages does 2Mbd give ? Does it try to download anything ?

    I see a cryptic [ -b baud ] use baud rate (default is 115200) in some docs, and digging I see that is actually applied to the terminal after boot, so maybe that should be called terminal baud rate or user terminal baud rate ?

    I do not see a Prop_Txt mode in loadp2 ? The DOCs say this mode is 2.25x faster :

    Prop_Txt ... This format is 2.25x denser than hex, and so minimizes transmission size and time.
  • dgatelydgately Posts: 1,105
    edited 2019-08-10 - 06:31:13
    David Betz wrote: »
    I'm not at home right now but I believe it was this:
    loadp2 -t -b 230400 -l 230400 -p /dev/cu.usbserial-P2EEQXU test
    
    I use several python scripts that call loadp2 with differing baud rates. Here's your C example compiling, loading and executing successfully on a P2ES from a MacBook Pro, running macOS Mojave 10.14.6:
    $ fastspin -2 test.c -L ~/source/spin2cpp/include -o test.binary
    $ loady3.py test.binary 
    Load my O2 Eval Board with a binary and setup a terminal.
    Note: Always uses -b 230400 & -l 230400.
    USAGE: loady.py [P2 binary filename]
    
    loading test.binary ...
    not an ELF file
    ( Entering terminal mode.  Press Ctrl-] to exit. )
    Hello, world!
    
    The loady3.py script contains (among other things) this:
    return_code = subprocess.call("loadp2 -p /dev/cu.usbserial-P2EEI8V -b 230400 -l 230400 -t -CHIP " + fn, shell=True)  
    

    dgately
    Livermore, CA (50 miles SE of San Francisco)
  • roglohrogloh Posts: 1,145
    edited 2019-08-10 - 21:31:47
    David Betz wrote: »
    I tried this on the Mac and it also works. I haven't gotten it to work with 2000000 baud though. Maybe 921600 should be made the default on the Mac?
    loadp2 -t -b 230400 -l 921600 -p /dev/cu.usbserial-P2EEQXU test
    

    I have found that 2000000 can work on the MAC. I am using Yosemite 10.10.5 with some specific changes to loadp2 that I made a while back and discussed in the p2gcc thread. When I return from vacation I will try to collect them as a github request if Eric wants to get them integrated into loadp2. It also enabled the auto detect feature if I recall correctly.
  • rogloh wrote: »
    David Betz wrote: »
    I tried this on the Mac and it also works. I haven't gotten it to work with 2000000 baud though. Maybe 921600 should be made the default on the Mac?
    loadp2 -t -b 230400 -l 921600 -p /dev/cu.usbserial-P2EEQXU test
    

    I have found that 2000000 can work on the MAC. I am using Yosemite 10.10.5 with some specific changes to loadp2 that I made a while back and discussed in the p2gcc thread. When I return from vacation I will try to collect them as a github request if Eric wants to get them integrated into loadp2. It also enabled the auto detect feature if I recall correctly.
    That sounds great! I was just going to integrate the auto-detect code from propeller-load but I won't bother if you already have that done.
  • ersmithersmith Posts: 3,230
    edited 2019-08-14 - 20:14:53
    I've published new releases (3.9.29) of fastspin and spin2gui. @ozpropdev and @Cluso99, the listing files should work better in this version. I've also fixed some Spin compatibility issues that affected Numbers.spin.

    Most of the new features are in the BASIC language. Passing objects to functions works more smoothly now in BASIC, and there have been some other object cleanups. You can now declare classes inline like:
      class counter
        dim c as integer
        sub increment()
          c = c + 1
        end sub
        function get() as integer
          return c
        end function
      end class
    
      dim x as counter
    
    (The old "class using" syntax still works of course, and still supports including Spin or C files as classes).

    The C compiler also supports having methods inside structs, sort of a poor man's C++ class.

    BASIC also has a simple form of function template for polymorphic programming. You can specify a function that takes any kind of argument and that will be specialized at compile time:
    any(t) function twice(x as t) as t
      return x+x
    end function
    
    print twice(10) ' prints 20
    print twice(1.4) ' prints 2.8
    print twice("abc") ' prints "abcabc"
    

    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).
  • ersmith wrote: »
    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).
    Another language? Sounds intriguing. Is this an existing language you're planning to support or one you're designing yourself?
  • David Betz wrote: »
    ersmith wrote: »
    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).
    Another language? Sounds intriguing. Is this an existing language you're planning to support or one you're designing yourself?

    I'd like to see if there's some subset of python that could be compiled. python in general is too dynamic to be efficiently compiled, but on the other hand many practical python programs don't rely on those dynamic features and could be compiled. So I was thinking that a python program like:
    def twice(x):
      return x+x
    
    could be compiled into something like the BASIC template I posted above, and then specialized based on the type of arguments actually passed to the "twice" function. That depends on being able to deduce the types at compile time, but in many cases that should be possible.
  • ersmith wrote: »
    David Betz wrote: »
    ersmith wrote: »
    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).
    Another language? Sounds intriguing. Is this an existing language you're planning to support or one you're designing yourself?

    I'd like to see if there's some subset of python that could be compiled. python in general is too dynamic to be efficiently compiled, but on the other hand many practical python programs don't rely on those dynamic features and could be compiled. So I was thinking that a python program like:
    def twice(x):
      return x+x
    
    could be compiled into something like the BASIC template I posted above, and then specialized based on the type of arguments actually passed to the "twice" function. That depends on being able to deduce the types at compile time, but in many cases that should be possible.
    Sounds interesting.

  • jmgjmg Posts: 13,778
    ersmith wrote: »
    BASIC also has a simple form of function template for polymorphic programming. You can specify a function that takes any kind of argument and that will be specialized at compile time:
    any(t) function twice(x as t) as t
      return t+t
    end function
    
    print twice(10) ' prints 20
    print twice(1.4) ' prints 2.8
    print twice("abc") ' prints "abcabc"
    

    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).

    That's impressively simple, and very student friendly. What is the code overhead cost of that flexibility ?

    ersmith wrote: »

    I'd like to see if there's some subset of python that could be compiled. python in general is too dynamic to be efficiently compiled, but on the other hand many practical python programs don't rely on those dynamic features and could be compiled. So I was thinking that a python program like:
    def twice(x):
      return x+x
    
    could be compiled into something like the BASIC template I posted above, and then specialized based on the type of arguments actually passed to the "twice" function. That depends on being able to deduce the types at compile time, but in many cases that should be possible.
    Sounds like a very appealing approach. Keep us posted.

  • ersmithersmith Posts: 3,230
    edited 2019-08-14 - 20:28:54
    jmg wrote: »
    ersmith wrote: »
    BASIC also has a simple form of function template for polymorphic programming. You can specify a function that takes any kind of argument and that will be specialized at compile time:
    any(t) function twice(x as t) as t
      return t+t
    end function
    
    Whoops! There was a typo in my original post, that should have read "return x+x". Sorry about that (I've edited the post now).
    That's impressively simple, and very student friendly. What is the code overhead cost of that flexibility ?
    Each different type passed to "twice" creates a new function. So if "twice" gets used in different places with an integer, float, and string argument (as in the example above) we end up with three functions:
    function twice__i4(x as integer) as integer
      return x+x
    end function
    function twice__f4(x as single) as single
      return x+x
    end function
    function twice__s(x as string) as string
      return x+x
    end function
    
    For this particular example the integer version is simple enough that it'll be inlined automatically, so there's really no code overhead for it. But we will get new functions created for the float ("single") and string versions.

    Once a specific version of the "twice" function is created (e.g. the "twice__s" version for strings) then it'll be re-used when further calls to "twice(string)" happen, so the overhead is only once per distinct type, not once per call.
  • Cluso99Cluso99 Posts: 15,220
    edited 2019-08-17 - 11:20:52
    Eric,
    I've been using spingui/fastspin for the past 3 weeks. What a great suite of programs!
    I really like the way the terminal program comes up automatically after downloading :)

    I have found that the find/search section in the editor doesn't seem to work. Perhaps I don't understand the metrics behind it, so can you enlighten me please,
    Thanks, Ray

    Postedit...
    Forgot to ask. How best to include a binary file (it has z80 instructions)?
    I've seen this example..
    framebuffer            file "rose.gray"
    
    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)
  • Cluso99 wrote: »
    I have found that the find/search section in the editor doesn't seem to work. Perhaps I don't understand the metrics behind it, so can you enlighten me please,
    Hi Ray. Glad you're finding spin2gui useful!

    It looks like there's a bug in the search menu command... it doesn't work unless you first click on the text window that you want to search in (that is, there's no default). If you load a file, click once on the window containing that file, and then do control-f (or select the menu entry) then it should bring up a dialog box asking what you want to search for, and it should work fine after that. (If you don't click on the window after loading the file it reports an error about missing tags).
    Forgot to ask. How best to include a binary file (it has z80 instructions)?
    I've seen this example..
    framebuffer            file "rose.gray"
    

    Yes, fastspin should support the standard Spin FILE command to include binary data. Are you finding that it doesn't work for you? It's certainly possible that there's a bug there, although it does seem to work in many cases.

    Regards,
    Eric
  • Thanks Eric. I’ll try find again.

    Yes. I’ve since tried the file insert and it works works fine.
    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)
  • ersmith wrote: »
    I've published new releases (3.9.29) of fastspin and spin2gui. @ozpropdev and @Cluso99, the listing files should work better in this version.
    Thanks Eric!
    It's all good now except for RES cog addresses don't increment.
    00478 01e             | junk1		res	1
    00478 01e 
    00478 01e             | junk2		res	1
    00478 01e 
    00478 01e             | junk3		res	1
    00478 01e 
    


    Melbourne, Australia
  • That'll be because those addresses in the .lst file are the file offset, not the symbol address. Well, except for the accompanying cog addresses that is.
    "... peers into the actual workings of a quantum jump for the first time. The results
    reveal a surprising finding that contradicts Danish physicist Niels Bohr's established view
    —the jumps are neither abrupt nor as random as previously thought."
  • ozpropdev wrote: »
    ersmith wrote: »
    I've published new releases (3.9.29) of fastspin and spin2gui. @ozpropdev and @Cluso99, the listing files should work better in this version.
    Thanks Eric!
    It's all good now except for RES cog addresses don't increment.
    00478 01e             | junk1		res	1
    00478 01e 
    00478 01e             | junk2		res	1
    00478 01e 
    00478 01e             | junk3		res	1
    00478 01e 
    

    Ah, I missed that one. Thanks for catching it!

    Here's a binary that should have that fixed, along with a few other minor fixes. It's not a complete release yet so it's still marked as "beta".

  • ersmith wrote: »
    ozpropdev wrote: »
    ersmith wrote: »
    I've published new releases (3.9.29) of fastspin and spin2gui. @ozpropdev and @Cluso99, the listing files should work better in this version.
    Thanks Eric!
    It's all good now except for RES cog addresses don't increment.
    00478 01e             | junk1		res	1
    00478 01e 
    00478 01e             | junk2		res	1
    00478 01e 
    00478 01e             | junk3		res	1
    00478 01e 
    

    Ah, I missed that one. Thanks for catching it!

    Here's a binary that should have that fixed, along with a few other minor fixes. It's not a complete release yet so it's still marked as "beta".
    Now it's:
    00dc8 046             | 	org	COG_BSS_START
    00dc8 046             | _main_i_0002
    00dc8 047             | 	res	1
    00dc8 047             | _main_pinmask_0001
    00dc8 048             | 	res	1
    00dc8 048             | _var01
    00dc8 049             | 	res	1
    
    I would think it should be:
    00dc8 046             | 	org	COG_BSS_START
    00dc8 046             | _main_i_0002
    00dc8 046             | 	res	1
    00dc8 047             | _main_pinmask_0001
    00dc8 047             | 	res	1
    00dc8 048             | _var01
    00dc8 048             | 	res	1
    

    Or am I wrong ?
    οἶδα οὐκ εἰδώς
  • jmgjmg Posts: 13,778
    dnalor wrote: »
    ...
    I would think it should be:
    00dc8 046             | 	org	COG_BSS_START
    00dc8 046             | _main_i_0002
    00dc8 046             | 	res	1
    00dc8 047             | _main_pinmask_0001
    00dc8 047             | 	res	1
    00dc8 048             | _var01
    00dc8 048             | 	res	1
    
    Or am I wrong ?

    I think you are right, here is another LST file which reports the start address / address of in the left most column, for reserved variables.
       994:    = A5                         T_THEN  EQU     T_LAST+1 
       995:    0233  A5                             DB      T_THEN
       996:    0234  54 48 45 4E                    DB      'THEN'
       997:                                         ;
       998:    = A6                         T_TO    EQU     T_LAST+2   
       999:    0238  A6                             DB      T_TO
    
Sign In or Register to comment.