Shop Learn P1 Docs P2 Docs
FlexProp: a complete programming system for P2 (and P1) - Page 37 — Parallax Forums

FlexProp: a complete programming system for P2 (and P1)

13233343537

Comments

  • Wuerfel_21Wuerfel_21 Posts: 3,142
    edited 2022-09-16 16:44

    I always read it directly on Github's web interface. Just reading the files as plain text is also an obvious option.

  • evanhevanh Posts: 13,628

    Oh, so those .md files are generated by Github itself?

  • @evanh said:
    Oh, so those .md files are generated by Github itself?

    No, but they're formatted to work with GitHub's markdown parser (which is slightly ideosyncratic - it's called "Github-flavoured markdown" for a reason)

  • Greg LaPollaGreg LaPolla Posts: 295
    edited 2022-09-16 22:20

    @ersmith said:

    Could you post your source code, or at least a snippet of it? Are you using flexprop, or the command line? Is this for a P1 or P2?

    This for the P2. I am porting some code from arduino. Code is attached

    I am using flexprop right now.

  • @ersmith

    Scratch that problem. It was my code. Found a missing semicolon

  • @ersmith said:

    Otherwise, you'll have to wait for the next full release, which should be fairly soon.

    Looking forward to it! This will give your tool a great boost!

  • JRoarkJRoark Posts: 1,104

    Encountered a new warning in FlexBasic, most recent release:

    D:/Flex2Gui/flexgui/include/libc/time/localtim.c:36: warning: Non-const member variable _timezone cannot be initialized at compile time; assuming variable is shared
    

    It doesn't seem to break anything, but if you get bored @ersmith this could be an easy squish for your BugHammer.

  • Christof Eb.Christof Eb. Posts: 695
    edited 2022-09-18 08:55

    Hi,
    how can I in SPIN2 trick DEBUG and normal serial to understand/work around that my kiss board has a 25MHz crystal?
    Tried different things for some time now....
    Thanks a lot!
    Christof

    Edit got it:
    _setbaud(230400*20/25)

  • evanhevanh Posts: 13,628

    Tell it the truth. :) In the CON section of the top level object/file place a couple of special constants. I always template my projects with the following, then edit as desired:

    CON
        _xtlfreq = 20_000_000
        _clkfreq = 80_000_000
        DOWNLOAD_BAUD = 230_400
        DEBUG_BAUD = DOWNLOAD_BAUD
    
    

    In your case change the 20_000_000 to 25_000_000.

  • @evanh said:
    Tell it the truth. :) In the CON section of the top level object/file place a couple of special constants. I always template my projects with the following, then edit as desired:

    CON
      _xtlfreq = 20_000_000
      _clkfreq = 80_000_000
      DOWNLOAD_BAUD = 230_400
      DEBUG_BAUD = DOWNLOAD_BAUD
    
    

    In your case change the 20_000_000 to 25_000_000.

    Oh, yes! Honesty is really a great virtue! Now VGA works flicker-free too!
    Thank you very much!

  • Hi,
    question:
    How I can I avoid push of locals.

    int myFunction(a) {
      if(b) 
            return(a);
      ...
      ...
     return(xyz);
    }
    

    Unfortunately since I made the 2nd part after return(a) bigger, the compiler inserts
    0f140 02 4C 05 F6 | mov COUNT_, #2
    0f144 A9 00 A0 FD | call #pushregs_

    at the beginning of the function and destroys speed.
    I have tried a macro, but this is used so often, that I get something like 430kB of code including a 256k array. And this doesn't run.
    Many thanks, Christof

  • Hi,
    is there a way and an example how to write a non-inline assembler function to be called in C?
    int myFunction( int x );
    Just one parameter and one result.
    Many thanks!!! Christof

  • ersmithersmith Posts: 5,446

    @"Christof Eb." said:
    Hi,
    question:
    How I can I avoid push of locals.

    int myFunction(a) {
      if(b) 
            return(a);
      ...
      ...
     return(xyz);
    }
    

    I would implement the main part in a separate function:

    int myFunctionReal(int a) {
       // do the !b case
    }
    int myFunction(int a) {
       if (b) return a;
       myFunctionReal(a)
    }
    

    This could also be made a macro like

    #define myFunction(a) ((b) ? (a) : myFunctionReal(a))
    
  • ersmithersmith Posts: 5,446

    @"Christof Eb." said:
    Hi,
    is there a way and an example how to write a non-inline assembler function to be called in C?
    int myFunction( int x );
    Just one parameter and one result.
    Many thanks!!! Christof

    int myFunction(int x) {
       int r;
       __asm {
          mov r, x;
          add r, #1
       }
       return r;
    }
    
  • Christof Eb.Christof Eb. Posts: 695
    edited 2022-09-21 14:46

    @ersmith said:

    @"Christof Eb." said:
    Hi,
    question:
    How I can I avoid push of locals.

    int myFunction(a) {
      if(b) 
            return(a);
      ...
      ...
     return(xyz);
    }
    

    I would implement the main part in a separate function:

    int myFunctionReal(int a) {
       // do the !b case
    }
    int myFunction(int a) {
       if (b) return a;
       myFunctionReal(a)
    }
    

    This could also be made a macro like

    #define myFunction(a) ((b) ? (a) : myFunctionReal(a))
    

    Thanks, Eric, I have had exactly these 2 versions. This led to the situation, that the outer function was inlined, giving 30.000 (!) more lines in the pasm Listing. And 120k more code. I have now found, that it can be marked this as cog code to avoid inlining. The function for the memory access via mmu is used about 600 times.

    FlexProp had thrown me back from 2.6MHz to 0.6MHz; now at about 1.2MHz.

  • @ersmith said:

    @"Christof Eb." said:
    Hi,
    is there a way and an example how to write a non-inline assembler function to be called in C?
    int myFunction( int x );
    Just one parameter and one result.
    Many thanks!!! Christof

    int myFunction(int x) {
       int r;
       __asm {
          mov r, x;
          add r, #1
       }
       return r;
    }
    

    Thanks, yes, this is the example from the docu for inline asm. I meant asm in a Dat section, which is not manipulated by the compiler.

  • ersmithersmith Posts: 5,446

    @"Christof Eb." said:

    @ersmith said:

    @"Christof Eb." said:
    Hi,
    is there a way and an example how to write a non-inline assembler function to be called in C?
    int myFunction( int x );
    Just one parameter and one result.
    Many thanks!!! Christof

    int myFunction(int x) {
       int r;
       __asm {
          mov r, x;
          add r, #1
       }
       return r;
    }
    

    Thanks, yes, this is the example from the docu for inline asm. I meant asm in a Dat section, which is not manipulated by the compiler.

    There isn't any way to directly call asm in a DAT section; I'm sure you could figure out a way, but I don't think it's worth it. If you just want to avoid compiler optimization you can use __asm const instead of __asm.

  • Hi, what's the maximum size for a program?
    When I had a lot of inlined and the "Program size is xx bytes" grew to xx>430k including 256k byte array, then the code crashed.
    But if I have a byte array of 426k and a xx=506k it still works.
    Thanks, Christof

  • evanhevanh Posts: 13,628
    edited 2022-09-23 08:46

    Upper limit will be 1 MB. That's the address range of hubexec. Data space is 4 GB.

  • pik33pik33 Posts: 1,759

    There is 512 k in a P2. If you want to use debug, 498k is available- 16 k is used for a debugger.

    The program has to be shorter than that, as on top of it there is a stack and heap space

  • ersmithersmith Posts: 5,446

    @"Christof Eb." said:
    Hi, what's the maximum size for a program?
    When I had a lot of inlined and the "Program size is xx bytes" grew to xx>430k including 256k byte array, then the code crashed.
    But if I have a byte array of 426k and a xx=506k it still works.
    Thanks, Christof

    The maximum size of the program depends heavily on how much stack it uses. Most programs can get by with a small stack (1K or 2K) but some C programs declare local arrays (on the stack) and hence need much bigger stacks. The program + stack must fit in available memory, which is 512K (496K if DEBUG is used).

  • ersmithersmith Posts: 5,446

    FlexProp version 5.9.17 is now available on the github releases page. New in this version:

    - Added '=' as alternate immediate syntax for use in C macros.
    - Added REGISTER keyword to BASIC
    - Fixed ++ and -- operators for 64 bit variables
    - Fixed signed modulus for 64 bit integers
    - Fixed a bug in varargs handling for 64 bit values in bytecode
    - Fixed output of C boolean operators in bytecode
    - Fixed some problems with 32 to 64 bit casts in ASM output
    - Fixed a bad check for immediate values in P1 rdlong/rdbyte/etc.
    - Fixed a warning in BASIC about the _timezone variable.
    - Made ALIGNW and ALIGNL keywords Spin2 only (some older Spin1 programs used these)
    - On P2, allow coginit() of COG and LUT functions.
    - Support register variables in C and BASIC
    - Renamed LMM pc to __pc to avoid conflict with user code
    
  • JRoarkJRoark Posts: 1,104
    edited 2022-09-24 18:45

    @ersmith Feature request for FlexBASIC: We have special symbols like FUNCTION, DATE, FILE, LINE, TIME, VERSION, etc. Would it be possible to have something similar that would return:

    1). the size (in bytes) of the executing image (compiled image, actually),
    2). the last hub address used by the program? (ie, writing something here wouldn't upset anything the program was using).

    Maybe something like IMAGESIZE and LASTADDR ? This isn't a priority, but it would be nice to have.

    edit: Whoops. The forum software auto converts leading and trailing underscores to bold text. There should be two leading and two trailing underscores before DATE, TIME, FUNCTION etc.

  • pik33pik33 Posts: 1,759

    @JRoark said:
    @ersmith Feature request for FlexBASIC: We have special symbols like FUNCTION, DATE, FILE, LINE, TIME, VERSION, etc. Would it be possible to have something similar that would return:

    1). the size (in bytes) of the executing image (compiled image, actually),
    2). the last hub address used by the program? (ie, writing something here wouldn't upset anything the program was using).

    Maybe something like IMAGESIZE and LASTADDR ? This isn't a priority, but it would be nice to have.

    edit: Whoops. The forum software auto converts leading and trailing underscores to bold text. There should be two leading and two trailing underscores before DATE, TIME, FUNCTION etc.

    Until you have these, use _builtin_alloca.

    It allocates memory on the stack, returning a pointer. As the memory map is program->heap->stack, the returned pointer is the start of unused memory. Then you can free this and use the address remembering that the stack can still grow up.

  • JRoarkJRoark Posts: 1,104

    @ersmith It appears something went wonky in your SPIN2 VGA driver at GitHub: "ANSI VGA text driver for Parallax Propeller P2-ES Eval boards". It appears multiple files have tab chars in the spin2 files which changes the way IF/ELSEIF gets interpreted in any given editor.

    An example of a compliation attemption using the FlexBASIC demo you provided in the above zip (no code changes made):

    "d:/Flex2Gui/flexgui/bin/flexspin" -2 -l --tabs=3 -D_BAUD=230400 -O1    --charset=utf8 -I "d:/Flex2Gui/flexgui/include"  "d:/Flex2Gui/flexgui/ERSmith Code/ANSIVGA2/basdemo.bas"
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2022 Total Spectrum Software Inc.
    Version 5.9.17 Compiled on: Sep 18 2022
    basdemo.bas
    |-vgatext_800x600.spin2
    |-|-vga_tile_driver.spin2
    vga_text_routines.spinh:118: error: syntax error, unexpected ELSE
    vga_text_routines.spinh:120: error: syntax error, unexpected ELSEIF
    vga_text_routines.spinh:122: error: syntax error, unexpected ELSEIF
    vga_text_routines.spinh:123: error: syntax error, unexpected number
    vga_text_routines.spinh:126: error: syntax error, unexpected ELSE
    std_text_routines.spinh:57: error: syntax error, unexpected ELSE
    child process exited abnormally
    Finished at Sun Sep 25 17:08:39 2022
    

    This same issue also impacts ANSI.SPIN2, which is the file I actually use as the driver for my projects since it pulls-in all of the pieces without need of INCLUDEs and allows configuration of resolution and depth. I've tried to fix these issues, but I'm just not a Spin coder, and when we get into nested IFs with mismatched intentation, I'm lost in the combinations when there is more than one or two errors.

    Your driver code for all of the above was formerly bulletproof, but I recently lost my dev system and I had to build another machine... which means I downloaded your driver anew from the Total Spectrum GitHub... and this showed-up. (And nope, I didn't have a backup of the working driver. Agh!!! Bangs head on table).

    So if you happen to find yourself bored... :)

  • ersmithersmith Posts: 5,446

    @JRoark said:
    @ersmith Feature request for FlexBASIC: We have special symbols like FUNCTION, DATE, FILE, LINE, TIME, VERSION, etc. Would it be possible to have something similar that would return:

    1). the size (in bytes) of the executing image (compiled image, actually),
    2). the last hub address used by the program? (ie, writing something here wouldn't upset anything the program was using).

    Item (1) would certainly be do-able, although because the final size is only known quite late in compilation it would probably have to be a value stored in HUB memory (like the current clock frequency) rather than a compile time constant. But would it really be useful?

    Item (2) depends on the stack used by the program, so it's only findable at run time. As @pik33 mentioned, __builtin_alloca(1) will return the current stack pointer position.

    @JRoark said:
    @ersmith It appears something went wonky in your SPIN2 VGA driver at GitHub: "ANSI VGA text driver for Parallax Propeller P2-ES Eval boards". It appears multiple files have tab chars in the spin2 files which changes the way IF/ELSEIF gets interpreted in any given editor.

    Tabs are evil :). The most recent version of my VGA driver is at https://github.com/totalspectrum/p2_vga_text, and should compile OK with other tab settings.

  • JRoarkJRoark Posts: 1,104

    @ersmith Your latest upload gets us down the road a bit. It complies fine but only sort of works. There is an issue with the driver not displaying text past a certain line, then it hangs, then eventually crashes after a while. The limit of how many lines it displays will change with the size of the strings I try to display. (Longer lines of text means an earlier failure). This code shows it clearly:

    '' BASIC text demo - with Jeff's mods to demo failure mode
    '' set up our environment
    '' pin to use for VGA
    #define VGA_BASE_PIN 48
    
    '' clock mode (for 160 MHz)
    #define CLKMODE 0x010007f8
    #define CLKFREQ 160_000_000
    
    '' create a Spin VGA text class with the name 'vga'
    dim vga as class using "ansi.spin2"
    
    '' some useful variables
    dim x, y, a as integer
    dim esc$
    esc$ = chr$(27) + "["
    
    '' set the system clock
    clkset(CLKMODE, CLKFREQ)
    
    '' start up the emulation
    vga.start(VGA_BASE_PIN)
    '' hook it up to the BASIC print system
    open SendRecvDevice(@vga.tx, nil, @vga.stop) as #2
    
    '' print 60 lines of stuff to VGA - NOTE: >>> FAILS AT ~LINE 22 <<<
    for a = 1 to 60
        print #2, " THIS IS A TEST OF BASDEMO.BAS 01234567889 abcdefghijklmnopqrstuvwxyz " + str$(a) + chr$(13)
    next a
    do
    loop
    
    sub gotoxy(x, y)
      print #2, esc$; y; ";"; x; "H";
    end sub
    

    @ersmith said:
    Item (1) would certainly be do-able, although because the final size is only known quite late in compilation it would probably have to be a value stored in HUB memory (like the current clock frequency) rather than a compile time constant. But would it really be useful?

    Useful, but it's probably not worth the effort. I think my "need" stemmed from a misunderstanding as to how the stack, heap and code were arranged. builtin_alloc gets me where I need to be.

    Tabs are evil :). The most recent version of my VGA driver is at https://github.com/totalspectrum/p2_vga_text, and should compile OK with other tab settings.

    Indeed they are! lol.

  • ersmithersmith Posts: 5,446
    edited 2022-09-26 13:28

    @JRoark said:
    @ersmith Your latest upload gets us down the road a bit. It complies fine but only sort of works. There is an issue with the driver not displaying text past a certain line, then it hangs, then eventually crashes after a while. The limit of how many lines it displays will change with the size of the strings I try to display. (Longer lines of text means an earlier failure). This code shows it clearly:

    Unfortunately that exact code works fine for me :(. From your description I'd suspect a memory allocation problem more than a driver problem, and I notice you're using +, str$, and chr$ a lot, which further raises my suspicion. Have you tried increasing the HEAPSIZE?

    Also, there's no need to use "+" in the print, nor str$, you can just print integers as usual (you don't need to make the whole thing a string).

  • MicksterMickster Posts: 2,222

    PMJI
    @ersmith
    Hey Eric, I avoid strings completely in my FlexBasic code; does this mean I'll never have a GC issue?

    Craig

  • ersmithersmith Posts: 5,446

    @Mickster said:
    PMJI
    @ersmith
    Hey Eric, I avoid strings completely in my FlexBasic code; does this mean I'll never have a GC issue?

    There are only a few things that dynamically allocate memory in FlexBasic. Strings are the most common one; function pointers are the other that I can think of (although function pointers use so little memory that they're rarely a problem in practice). If you avoid those, then yes, you should never have a GC issue.

Sign In or Register to comment.