Shop OBEX P1 Docs P2 Docs Learn Events
flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler - Page 82 — Parallax Forums

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

17980828485116

Comments

  • Thanks @iseries and @ersmith. The mental picture is now much clearer.

  • I don't know if this makes sense but is there a way to write straight assembly code and have it compile like a MASM program.

    Would like it to be code independent and not have any underlying language.

    Mike

  • ersmithersmith Posts: 5,900
    edited 2021-04-06 23:53

    @iseries said:
    I don't know if this makes sense but is there a way to write straight assembly code and have it compile like a MASM program.

    Would like it to be code independent and not have any underlying language.

    All you have to do is write DAT in front of all the assembly and then build it as a Spin or Spin2 file. See for example the blink_pasm.spin sample that comes with flexprop (that one does have a CON section too, but that's optional and actually kind of useful sometimes for assembly).

    On the P2 if there are no PUB or PRI statements then you get just your assembly program, no overhead at all. On P1 you do also get a minimal Spin program (8 bytes, IIRC) appended that restarts the COG with your assembly.

  • evanhevanh Posts: 15,126

    Eric,
    I bumped into a couple of missing predefined constants for the streamer that are listed in the Spin2 doc: X_8P_1DAC8_WFBYTE and X_PINS_ON. Presumably there is more.

  • SuracSurac Posts: 176
    edited 2021-04-14 11:33

    Hello,

    i Think i found a strange behaviour in Flexprop 5.3.2

    DAT
            testp #1
            testpn #1
            testb 0,#0
            testbn 0,#0
    

    this assembler instruction should give an error. They are only allowed with WC, WZ, ANDC, ANDZ, ORC, ORZ, XORC, XORZ. Flexprop accepts them and produces code for them (but not the right one). PNUT gives a syntax error.
    Found this while working on my P2 disassembler.

    :smile: and have a nice day!

  • pik33pik33 Posts: 2,347

    Please do something with TAB key, either disable it at all, or make the character inserted by it visible or make it add some spaces instead. Another half an hour lost because of automatically used TAB.

  • @evanh : thanks, I've added those constants

    @Surac : thank you. Using "testp" or "testb" without setting flags doesn't make much sense, and now the compiler will give an error for this.

  • @pik33 said:
    Please do something with TAB key, either disable it at all, or make the character inserted by it visible or make it add some spaces instead. Another half an hour lost because of automatically used TAB.

    flexspin does nothing at all with TAB. FlexProp is pretty consistent in its use of tabs: if you type the TAB key then it inserts one, if you do not then it does not.

  • Visual Code always uses spaces and looks at your code and guesses at the number of spaces to use in place of the tab key.

    Mike

  • @iseries
    You can use VSCODE to edit the source file and then use the flexspin compiler to do the compile work. There is a tutorial how to set this up at: https://parallax.com/visual-studio/

  • pik33pik33 Posts: 2,347

    @ersmith said:

    @pik33 said:
    Please do something with TAB key, either disable it at all, or make the character inserted by it visible or make it add some spaces instead. Another half an hour lost because of automatically used TAB.

    flexspin does nothing at all with TAB. FlexProp is pretty consistent in its use of tabs: if you type the TAB key then it inserts one, if you do not then it does not.

    Yes, it does exactly that. The result is perfect looking, but not working program.

  • pik33pik33 Posts: 2,347
    edited 2021-04-15 07:56

    Something doesn't work as expected with method pointers

    This works in Propeller Tool - this is a fragment of graphics mode setting. The goal was to select putpixel function according to bit per pixel.:

    if (mode & (%10_00_11_0000))==(%10_00_11_0000)  
      timings[5]:=4
      timings[11]:=timings[11]<<1
      putpixel:=@putpixel8
    
    if (mode & (%10_00_11_0000))==(%10_00_01_0000) 
      timings[5]:=16
      timings[11]:=timings[11]>>1
      putpixel:=@putpixel2
    
    if (mode & (%10_00_11_0000))==(%10_00_00_0000)  
      timings[5]:=32
      timings[11]:=timings[11]>>2
      putpixel:=@putpixel1
    
    if (mode & (%10_00_11_0000))==(%10_00_10_0000)  
      putpixel:=@putpixel4
    
    

    With Flexprop it works, but only once. The second call to setmode fails (and I don't know what exactly fails, the HDMI stops working)

    However, if I add 4 variables for these pointers and initialize them once at the start of the driver, it works.

    var
    
    (...)
    
    long p1,p2,p4,p8
    
    (...)
    if (mode & (%10_00_11_0000))==(%10_00_11_0000) ' 8bit graphics, 4 pixels per long instead of 8, cpp x2
      timings[5]:=4
      timings[11]:=timings[11]<<1
      putpixel:=p8
    
    if (mode & (%10_00_11_0000))==(%10_00_01_0000) ' 2bit graphics, 16 pixels per long instead of 8, cpp /2
      timings[5]:=16
      timings[11]:=timings[11]>>1
      putpixel:=p2
    
    if (mode & (%10_00_11_0000))==(%10_00_00_0000) ' 1bit graphics, 32 pixels per long instead of 8, cpp /4
      timings[5]:=32
      timings[11]:=timings[11]>>2
      putpixel:=p1
    
    if (mode & (%10_00_11_0000))==(%10_00_10_0000) ' 4bit graphics,
      putpixel:=p4
    
    (...)
    
    pub start(mode,base):result
    
    (...)
    
    p1:=@putpixel1
    p2:=@putpixel2
    p4:=@putpixel4
    p8:=@putpixel8
    
  • A few suggestions regarding .lst files produced by FlexSpin:

    1. The last line in a .lst file is the last source line that generates code. This line has no CR or LF. Any later comment lines are ignored. Could you please either (a) include all the source file lines or (b) add CR+LF to last code line? Preferably (a) as comments are meaningful.

    2. Is it possible to show CON values in the same four byte columns as DAT values? It would be useful to see constant values derived from other constants or the hex equivalent of decimal constants.

    3. Is it possible to have an option to list DAT (and CON) values as big-endian? Perhaps no spaces between bytes or underscores replacing spaces.

  • @pik33 : I'd need to see more of your code to see what might be going wrong. Certainly flexspin is OK with changing method pointers at run time, e.g. the follwing program runs fine:

    con
        _clkfreq = 180_000_000
    
    obj
      ser: "spin/SmartSerial"
      fmt: "spin/ers_fmt"
    
    var
      long ptr
    
    pub main() | x
      ser.start(230_400)
      send := @ser.tx
      repeat
        waitms(1000)
        x := getrnd()
        if (x&1)
          ptr := @oddfunc
        else
          ptr := @evenfunc
        ptr(x)
    
    pub oddfunc(x)
      send("ODD function: x=", fmt.hex(x), 13, 10)
    
    pub evenfunc(x)
      send("even function: x=", fmt.hex(x), 13, 10)
    

    As for your tab problems, try changing the "Tab stops" setting under "Options > Editor Options" to 8.

  • evanhevanh Posts: 15,126

    @TonyB_ said:
    2. Is it possible to show CON values in the same four byte columns as DAT values? It would be useful to see constant values derived from other constants or the hex equivalent of decimal constants.

    1. Is it possible to have an option to list DAT (and CON) values as big-endian? Perhaps no spaces between bytes or underscores replacing spaces.

    The existing column group is clearly the generated data for the binary file output. These ideas would have to go in a separate column group. I wouldn't want them mixed.

  • pik33pik33 Posts: 2,347
    edited 2021-04-15 15:31

    @ersmith said:
    @pik33 : I'd need to see more of your code to see what might be going wrong. Certainly flexspin is OK with changing method pointers at run time, e.g. the follwing program runs fine:

    con
        _clkfreq = 180_000_000
    
    obj
      ser: "spin/SmartSerial"
      fmt: "spin/ers_fmt"
    
    var
      long ptr
      
    pub main() | x
      ser.start(230_400)
      send := @ser.tx
      repeat
        waitms(1000)
        x := getrnd()
        if (x&1)
          ptr := @oddfunc
        else
          ptr := @evenfunc
        ptr(x)
    
    pub oddfunc(x)
      send("ODD function: x=", fmt.hex(x), 13, 10)
    
    pub evenfunc(x)
      send("even function: x=", fmt.hex(x), 13, 10)
    

    As for your tab problems, try changing the "Tab stops" setting under "Options > Editor Options" to 8.

    https://github.com/pik33/ultibo-propeller/blob/main/hng012/hng021a.spin2

    This is work in progress and I haven't commited the latest version, left at the university, where I will return in Tuesday :(

    There are 2 version of setmode function in this file : setmode (works) and setmode2 (made for debugging)

    The "dummy" method at the beginning calls setmode 3 times. The result should be blue screen without border, then white screen with blue border, then a red screen without border and with a cursor . If putpixel assigned, the third screen is weird. The "dummy" method don't use putpixel at all.

    Maybe a bug somewhere else causes this problem. I will continue developing the driver after the weekend.

  • @TonyB_ said:
    A few suggestions regarding .lst files produced by FlexSpin:

    1. The last line in a .lst file is the last source line that generates code. This line has no CR or LF. Any later comment lines are ignored. Could you please either (a) include all the source file lines or (b) add CR+LF to last code line? Preferably (a) as comments are meaningful.

    2. Is it possible to show CON values in the same four byte columns as DAT values? It would be useful to see constant values derived from other constants or the hex equivalent of decimal constants.

    3. Is it possible to have an option to list DAT (and CON) values as big-endian? Perhaps no spaces between bytes or underscores replacing spaces.

    I didn't realize the listing file didn't end with CR+LF. That I can fix.

    The other requests are hard, because the listing file probably works the reverse of how you think of it. It doesn't go through the source and show what's generated. Rather it goes through the final binary and shows what source led to that binary. That is, the bytes of the output are kind of tagged with the source that they came from, and the listing file works by showing those bytes and annotating them with content from the appropriate source files. (It's done that way so that the source can be shown for inline functions that come from other objects). So the output comes out in little-endian order because we're walking through the literal binary (which is little endian), and things that don't produce code don't get shown unless they happen to fall between two pieces of code (there's special hackery to handle that).

  • @ersmith said:

    @TonyB_ said:
    A few suggestions regarding .lst files produced by FlexSpin:

    1. The last line in a .lst file is the last source line that generates code. This line has no CR or LF. Any later comment lines are ignored. Could you please either (a) include all the source file lines or (b) add CR+LF to last code line? Preferably (a) as comments are meaningful.

    2. Is it possible to show CON values in the same four byte columns as DAT values? It would be useful to see constant values derived from other constants or the hex equivalent of decimal constants.

    3. Is it possible to have an option to list DAT (and CON) values as big-endian? Perhaps no spaces between bytes or underscores replacing spaces.

    I didn't realize the listing file didn't end with CR+LF. That I can fix.

    The other requests are hard, because the listing file probably works the reverse of how you think of it.

    Eric, thanks for your consideration and explanation. None of my suggestions is vitally important and I'd be content with 1(b).

  • @TonyB_ : Would it be helpful to print the constants separately in a section at the end of the listing? That wouldn't be hard to do.

  • I just upgraded to flexprop 5.3.2 for the contained flexspin and loadp2 under Linux. I'm playing around with DEBUG for the first time, and the first hurdle was the difference in DEBUG_BAUD. According to https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw I expected 2_000_000 - but it turns out it's 230_400. I tried to influence this using DEBUG_BAUD as constant-declaration, but that didn't have any effect.

    So I guess I have two questions:

    • how do I influence the DEBUG_BAUD using flexspin? Is a constant the right way, or is this supposed to be something on the commandline? I tried -D but that's just for flags it seems.
    • shouldn't the default be the same as documented?
  • @deets : the version in github now has support for DEBUG_BAUD.

  • @ersmith I have a bit of compiler mischief to report with regards to the SD/MMC filesystem code under FlexBASIC v5.3.2.

    The following code works just fine with "Default Optimization" or "Full Optimization" enabled, but causes a "error: Unknown symbol _ff_cc_memcpy" when "No Optimization" is selected:

        mount "/sd", _vfs_open_sdcard()
        open "/sd/test.txt" for append as #3
        print #3 "This is a test"
        close #3
    
    

    This isn't a show-stopper by any means, but having the ability to turn optimization off often shows me some additional bugs in (unused) INCLUDE or CLASS libraries that wouldn't be picked-up otherwise.

  • @ersmith said:
    @TonyB_ : Would it be helpful to print the constants separately in a section at the end of the listing? That wouldn't be hard to do.

    If the hex values of constants can't be included on the lines that declare them then I'd say don't bother at all, to be honest.

    A couple more requests:

    1. First byte in listing file is LF. Could that be removed please? If so, line numbers of source and listing files would match if label lines contain no code and there are no includes.

    2. Could the 00000 at start of lines be replaced with spaces until ORG/ORGH is found?

  • @JRoark said:
    @ersmith I have a bit of compiler mischief to report with regards to the SD/MMC filesystem code under FlexBASIC v5.3.2.

    The following code works just fine with "Default Optimization" or "Full Optimization" enabled, but causes a "error: Unknown symbol _ff_cc_memcpy" when "No Optimization" is selected:

      mount "/sd", _vfs_open_sdcard()
      open "/sd/test.txt" for append as #3
      print #3 "This is a test"
      close #3
    
    

    This isn't a show-stopper by any means, but having the ability to turn optimization off often shows me some additional bugs in (unused) INCLUDE or CLASS libraries that wouldn't be picked-up otherwise.

    Fixed in github now, thanks for the bug report.

  • Hello, I have a strange effect when assiging variables in several loops in BASIC on P2 & flexprop 5.3.2 :
    This code

    Dim Address as ulong
    Dim bla     as ubyte
    For Address = 1 to 3
        bla = Address
        print bla;
    Next
    For Address = 1 to 3
        bla = Address
        print bla;
    Next
    For Address = 1 to 3
        bla = Address
        print bla;
    Next
    

    Produces this: 012456456

    Seems wrong

  • @aaaaaaaargh : This looks like a bug in the optimizer. I'll look into it, but in the meantime the work-around is to select the "Default Optimization" level instead of "Full Optimization".

  • @ersmith said:
    @aaaaaaaargh : This looks like a bug in the optimizer. I'll look into it, but in the meantime the work-around is to select the "Default Optimization" level instead of "Full Optimization".

    Thank you very much that works - I only used full optimization because of a large array - the upload is so much faster with full optimization in that case

  • JRoarkJRoark Posts: 1,214
    edited 2021-04-22 16:35

    @ersmith FlexBASIC Version 5.4.0-Beta has some new mischief afoot. I am getting an "error: fit 480 failed: pc is 524" and the error points to the last line of the PASM file which says "FIT 480".

    Consider this a preliminary report because I haven't yet isolated exactly what part of my code is triggering this (5 cogs running, huge program, multiple libs and classes), but Version 5.4.0-beta throws this error regardless of the optimizer settings on a project that compiled ok under the previous version. I'll try to get it isolated and post some code in a bit. In the interim, the compiler messages are below:

    "d:/Flex2Gui/flexgui/bin/flexspin" -2 -l -D_BAUD=230400 -O1 -Wall   -I "d:/Flex2Gui/flexgui/include"  "d:/Flex2Gui/flexgui/P2 Libs/Generator Project/GPS-RTC-Serial-VGA-TestP2-02Apr2021.bas"
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2021 Total Spectrum Software Inc.
    Version 5.4.0-beta-v5.3.2-56-gff09e2d3 Compiled on: Apr 22 2021
    GPS-RTC-Serial-VGA-TestP2-02Apr2021.bas
    |-jm_serial.spin2
    |-|-jm_nstr.spin2
    |-DS3231RTC_P2_V2.spin
    |-DateTimeLibP2.bas
    |-|-StringLibP2.bas
    |-StringLibP2.bas
    |-PropellerLibP2.bas
    |-ANSILibP2.bas
    |-ansi.spin2
    |-|-timing1024x768.spin2
    |-|-unscii-16.spin2
    |-|-vga_tile_driver.spin2
    |-DHT22LibP2.bas
    mount.c
    fmt.c
    strings.bas
    ieee32.c
    powers.c
    errno.c
    posixio.c
    fatfs_vfs.c
    |-ff.cc
    bufio.c
    vfs.c
    ioctl.c
    strcpy.c
    strncpy.c
    strncat.c
    strncmp.c
    memset.c
    strlen.c
    sdmm.cc
    stat.c
    malloc.c
    strcpy.c
    memset.c
    GPS-RTC-Serial-VGA-TestP2-02Apr2021.p2asm
    Done.
    d:/Flex2Gui/flexgui/P2 Libs/Generator Project/GPS-RTC-Serial-VGA-TestP2-02Apr2021.p2asm:29971: error: fit 480 failed: pc is 515
    child process exited abnormally
    Finished at Thu Apr 22 11:32:43 2021
    
  • @JRoark : Thanks for the bug report. I was afraid something like this would happen -- there's less COG RAM available now because the FCACHE space was moved from LUT to COG for Spin2 compatibility. I'll see what I can do about freeing some more space up.

  • @ersmith said:
    @JRoark : Thanks for the bug report. I was afraid something like this would happen -- there's less COG RAM available now because the FCACHE space was moved from LUT to COG for Spin2 compatibility. I'll see what I can do about freeing some more space up.

    @ersmith
    Rut-roh, Shaggy.
    Is there something I could do to free-up some COG space within my code? Or is this one of those "nope, I need to fix it under the hood" sort of things?

Sign In or Register to comment.