Shop OBEX P1 Docs P2 Docs Learn Events
New BASIC compiler for Prop1 and Prop2 - Page 15 — Parallax Forums

New BASIC compiler for Prop1 and Prop2

1121315171820

Comments

  • The "then" isn't optional because it's what indicates a multi-line "if" (for a single command you can include it on the same line as the "if"). But there's certainly room to improve the error messages!
  • That's fine.
    It threw the error, but just was too early in the day for me :)
  • Eric

    Global variables ? Example taking from docs
    dim shared ctr as integer
    


    Throws error on compiling !
  • rsut wrote: »
    Eric

    Global variables ? Example taking from docs
    dim shared ctr as integer
    


    Throws error on compiling !

    I haven't played with this yet but from an earlier post, it would be:
    dim shared as integer ctr
    
  • rsut wrote: »
    Eric

    Global variables ? Example taking from docs
    dim shared ctr as integer
    


    Throws error on compiling !

    Sorry, that's a bug (an oversight in the type parsing code) that will be fixed in the next release. For now use Mickster's suggestion:
    dim shared as integer ctr
    
  • Eric
    We can do this
    ser.str(@message) 
    
    but
    ser.str(string("We should also be able to this, I think")) 
    

    Ron

  • Ron:

    Just write
    ser.str("We should also be able to do this, I think")
    
    In BASIC there's no need for the `string` operator, things between quotes are always strings. But this means you have to watch out for cases where in Spin you are using a single character. For example, to send one character "X" in BASIC you would do:
    ser.tx(asc("X"))
    
    or
    ser.str("X")
    
    whereas in Spin that would be ser.tx("X").

    Eric
  • Ariba wrote: »
    ON x GOTO/GOSUB label1, label2, ...

    I think this can be replaced by a function table, and a call per function pointer.
    ON x GOTO would probably be feasible to implement, although I think the "modern" BASIC way to do that is SELECT/CASE (which is partially implemented in fastspin now, as a series of if/then/else, but I really should provide the optimization of turning that into a jump table when the CASEs are contiguous).

    ON x GOSUB is a bit more problematic, since we don't support GOSUB in general. I guess it could be made to work for the specific case that all of the labels are actually declared as zero parameter SUBs. Is it worth it? I'm not sure.

    I'm still thinking about DATA/READ/RESTORE, but you're right, we do need those in some form.

    Thanks,
    Eric
  • ON x GOTO would be fine because you could return with another GOTO and, no, this doesn't result in "spaghetti code" :wink:
  • I suppose with this being a compiler, you could always create aliases such as jmp for GOTO so that some would feel that they are using a real programming language :lol::lol:
  • Eric

    If you want to, you can send a character in fds.spin like so
    ser.tx(chr)        ' outputs a byte contained in *chr* . No need to  type cast.
    

    In fds.spin you cannot send a string without using a pointer to the string or inserting the word *string* inside
    the expression, agreed? So if new prop users comes to flexibasic and uses spin objects in a progam (which, I think, was one of the primary objectives) may wonder why their code fails to compile. Fds.spin is used in other objects which can be down loaded from the OBEX. Maybe there should be a warning in the docs
    This works in spin, but not in flexibasic
    serial.str(string("Testing the FullDuplexSerial object."))     'print a test string 
    

    I am only a tool user and not a tool maker. :)

    Ron

    Eric


  • Mickster wrote: »
    I suppose with this being a compiler, you could always create aliases such as jmp for GOTO so that some would feel that they are using a real programming language :lol::lol:

    You can access labels from inline assembly, so it would be OK to write something like:
    var x = 0
    
    start:
    
    if x = 1 then
      asm
        jmp isone
      end asm
    end if
    print "hello"
    x = x + 1
    asm
      jmp start
    end asm
    
    isone:
    
    print "goodbye"
    
  • Ron:

    I will add a note to the documentation about the difference between BASIC and Spin strings. I think the BASIC ones are more natural (I hate having to write string("hello") instead of just "hello") but it may trip people up if they use a string where an integer is expected.

    Thanks,
    Eric
  • jmgjmg Posts: 15,173
    I saw this in another thread
    https://www.b4x.com/
    could be useful on a few fronts.
    Seems it is Basic -> C, so you could use the emitted C to test your C compiler parts, and there may be bits of the Basic side that can be harvested ?

    Frequently asked questions
    Q: Is B4R completely free, including for commercial purposes?
    A: Yes.
    Q: Can I access the C source code and the generated objects?
    A: Yes. The code and the compiled objects are available under the Objects folder.
    Q: Are the libraries open source?
    A: Yes. B4R libraries are open source (MIT license). The code is available in GitHub.

  • Thanks for the pointer @jmg. Unfortunately it looks like b4x itself is not open source, so there's not much that can be harvested directly from it. We could look at the C code it generates and "reverse engineer" what it's doing for some constructs. If anyone would like to take that on it for DATA/READ/RESTORE it could be helpful.
  • yetiyeti Posts: 818
    edited 2018-12-20 14:06
    BaCon (another BASIC->C "converter") has "DATA".
    Docs —▷ http://www.basic-converter.org/doc_frame.html

    (...but I don't think, FlexBASIC needs the classic "DATA" and friends from punch card days only storing strings and so wasting a lot of space. YMMV.)
  • Eric,
    Another nubie question.
    I've been playing with BASIC and trying different things to see if they compile. Now I'm actually trying to run programs on the P1 on a QuickStart board (flash LEDs, run multiple cogs) getting ready to try them out on the P2ES.

    I am using spin2gui with Windows 7. When I try to use "Compile & Run", I get an error message "Propeller not found on com 1". That makes sense since my Prop 1 is on com 6.
    Same thing happens if I just try run binary.

    How can I change the binary loading program to use a different com port?

    My work around is to associate the PropTool with .binary files, and click on the binary file. Then use the PropTool info screen to load the EEPROM. I'm also using the Parallax Serial Terminal as the print device.

    Tom
  • Tom:

    I think you can change the Run command line (under Commands > Configure Commands...) to include a "-p COM6" option to specify the port. I'm surprised proploader would need this, it's usually pretty good at finding propellers automatically. I have been meaning to add a menu option for doing this, because some people have asked about supporting multiple props; but I haven't had a chance yet.

    Regards,
    Eric
  • Hi,

    I've been experimenting with spin2gui, and it seems tthat it does not identify the Propeller chip on any of my boards. It works with the Activity Board. So, it can be one or both:
    - My boards use a 6MHz crystal instead of a 5MHz one.
    - My boards use the !RTS signal AC coupled via a capacitor, without any inverting transistor, for the reset. The Activity Board uses the !DTR signal, AC coupled and inverted via a transistor.

    I haven't explored what is going wrong. SimpleIDE works fine with my boards, provided that the correct settings are configured. Does your software allows to to change the frequency and signals, to account for different hardware?

    Kind regards, Samuel Lourenço
  • Samuell:

    spin2gui doesn't do anything to detect the boards, it relies on the proploader tool (written by @dbetz) to do that. The tool to be used can be configured easily in the spin2gui Commands menu, so if proploader doesn't work but propeller-load does then you could try that.

    Regards,
    Eric
  • Eric,
    I tried that and got a compiler error. The message window listed all the compiler switches and -p is eliminate the preprocessor.

    Tom
  • ersmith wrote: »
    Samuell:

    spin2gui doesn't do anything to detect the boards, it relies on the proploader tool (written by @dbetz) to do that. The tool to be used can be configured easily in the spin2gui Commands menu, so if proploader doesn't work but propeller-load does then you could try that.

    Regards,
    Eric
    The original version of proploader only knew how to load boards with 5mhz crystals because that's what Parallax asked for. I've been working on a new version that uses the same board configuration files as propeller-load and hence can load boards with different clock settings. Until that is ready you can continue to use propeller-load. You only really need to use proploader if you want to load over a wifi connection using a WX module.

  • Is there some sample code somewhere that shows how to use a couple of smart pins to implement a serial interface? I'm looking for PASM2 code not C or Spin.
  • twm47099 wrote: »
    Eric,
    I tried that and got a compiler error. The message window listed all the compiler switches and -p is eliminate the preprocessor.

    Tom

    spin2gui has two separate phases: first it compiles the source code into a binary by invoking a compiler (the default is fastspin). Then it loads that binary to the board and runs it there, using proploader by default on P1 and loadp2 on P2.

    I think you changed the "Compile command" (the one that invokes fastspin) and not the "Run command" (the one that invokes proploader). The "-p COM6" needs to go after "%D/bin/proploader" in the "Run command", the second command shown in the "Configure commands..." dialog box.

    Regards,
    Eric
  • David Betz wrote: »
    Is there some sample code somewhere that shows how to use a couple of smart pins to implement a serial interface? I'm looking for PASM2 code not C or Spin.

    There's a "smartpin_serial_turnaround.spin2" file in the v32i FPGA distribution. I'm not sure if that's exactly what you wanted, but it probably would provide some nice hints.
  • RaymanRayman Posts: 14,640
    Here's the P2ASM serial code I use for debugging:
    CON  ''Start of serial output code - This is serial output code adapted from code posted by mindrobots in the P2 forum 
    dat     ''Start of serial output code
            org     0
    SerialStart     
        
                    wrpin pm_tx,  #TX_PIN      'set asynchronous tx mode in smart pin 
                    wxpin ##nco_baud, #TX_PIN      'set tx bit period
                    wrpin pm_rx,  #RX_PIN      'set asynchronous rx mode in smart pin 
                    wxpin ## nco_baud, #RX_PIN      'set rx bit period
                    dirh #TX_PIN    'enable smartpin tx
                    dirh #RX_PIN    'enable smartpin rx
                    jmp     #loopback
    
    'for V27 had to make these two vars into registers
    pm_tx   long  %0000_0000_00_0_0000000000000_01_11110_0        'async tx byte mode, dir high
    pm_rx   long  %0111_0000_00_0_0000000000000_01_11111_0        'async rx byte mode, dir low, inputs pin 0                                       '
    
    'Main loop start
    loopback
    
                    'Look for command
                    rdbyte  tx_cmd, rx_target                
                    cmp     tx_cmd,#0 wcz
            if_e    jmp     #loopback
    
    
                    'check for write byte command
                    cmp     tx_cmd,#1 wcz
            if_e    rdbyte  tx_char,hex_target        
            if_e    call    #send_char
    
                    'check for write hex long
                    cmp     tx_cmd,#2 wcz
            if_e    rdlong  tx_hex, hex_target               
            if_e    call    #send_LongHexSub
                    
    
                    'check for write hex byte
                    cmp     tx_cmd,#3 wcz
            if_e    rdbyte  tx_hex, hex_target               
            if_e    call    #send_ByteHexSub
    
                    'check for write string byte
                    cmp     tx_cmd,#4 wcz
            if_e    rdlong  tx_hex, hex_target               
            if_e    call    #send_StringSub        
    
                    wrbyte  #0,rx_target 'message received and processed
                    jmp     #loopback
    
    Send_StringSub 'send a string
                    rdbyte  tx_char,tx_hex
                    cmp     tx_char,#0 wcz
            if_z    ret
                    
                    call    #send_char
                    add     tx_hex,#1
                    jmp     #Send_StringSub
                                    
                    
    Send_LongHexSub  'Send 8 hex chars
                    getnib  tx_temp,tx_hex,#7
                    call    #SendHexSub
                    getnib  tx_temp,tx_hex,#6
                    call    #SendHexSub
                    getnib  tx_temp,tx_hex,#5
                    call    #SendHexSub
                    getnib  tx_temp,tx_hex,#4
                    call    #SendHexSub
                    getnib  tx_temp,tx_hex,#3
                    call    #SendHexSub
                    getnib  tx_temp,tx_hex,#2               
                    call    #SendHexSub
                    getnib  tx_temp,tx_hex,#1
                    call    #SendHexSub
                    getnib  tx_temp,tx_hex,#0
                    call    #SendHexSub
                    ret
    
    Send_ByteHexSub
                    push    tx_hex
                    mov     tx_temp,tx_hex
                    shr     tx_temp,#4
                    and     tx_temp,#$0F
                    call    #SendHexSub
                    pop     tx_hex
                    mov     tx_temp,tx_hex
                    and     tx_temp,#$0F
                    call    #SendHexSub
                    ret
                                                   
    SendHexSub 'Send hex
                    mov     tx_char,tx_temp
    
                    cmp     tx_char,#9 wcz
            if_a    add     tx_char,#"A"-10
            if_be   add     tx_char,#"0"
                    call    #Send_Char
                    ret 
    
    
    '*******************************************************************************
    ' Get one character from the input port.
    '*******************************************************************************
    
    rcv_char                  
    
                  testb   inb,#RX_PIN     wc      'sample rx
              if_nc jmp     #rcv_char
                  akpin     #RX_PIN
                  rdpin     rx_char,#RX_PIN
                  ret
    
    
    '*******************************************************************************
    ' Output a single character to the tx_pin.         
    '*******************************************************************************
                               
    send_char       rdpin temp,#tx_pin wc                   'wait if busy
            if_c    jmp     #send_char
                    wypin tx_char,#tx_pin
                    ret wcz
    
    
    rx_target       long    Mailbox1
    hex_target      long    Mailbox2
    tx_cmd          res     1
    tx_char         res     1
    tx_hex          res     1
    timer           res     1
    rx_char         res     1
    tx_temp         res     1
    temp            res     1             
                    fit     $1F0
    
  • RaymanRayman Posts: 14,640
    edited 2018-12-22 14:31
    I think it's from garryj originally, but heavily modified...
    You might want this too:
    nco_baud =round(fclk / 115_200.0 * 65536.0) & $fffffc00 | 7  'adapted from garryj's V19 USB code
    
    CON  'Serial pin definites and mailboxes
    
            RX_PIN = 63
            TX_PIN = 62
            'Mailbox for serial commands (right before BmpAddressBackground)
            Mailbox1=$FF80  
            Mailbox2=$FF81
    
  • ersmith wrote: »
    twm47099 wrote: »
    Eric,
    I tried that and got a compiler error. The message window listed all the compiler switches and -p is eliminate the preprocessor.

    Tom

    spin2gui has two separate phases: first it compiles the source code into a binary by invoking a compiler (the default is fastspin). Then it loads that binary to the board and runs it there, using proploader by default on P1 and loadp2 on P2.

    I think you changed the "Compile command" (the one that invokes fastspin) and not the "Run command" (the one that invokes proploader). The "-p COM6" needs to go after "%D/bin/proploader" in the "Run command", the second command shown in the "Configure commands..." dialog box.

    Regards,
    Eric

    Eric,
    Thanks for the help. I haven't used BASIC in many years. It was fun then. It is also now. Thanks for developing this. I especially like being able to see the resulting PASM.

    Tom
  • Thank you for the gui and all. It is just what I was hoping for. I downloaded the version currently in page 1 of this thread.

    So I followed your advice to twm and put -p COM33 into the loader command and believe I am now talking to the P2.

    Now when I "compile and load" blink1 from the samples (changing ledpin = 56), I see activity on LED P63 and P60 and P61. Then P60 goes out, then P61. But nothing on P56. I'm sure I have some simple error. Can you advise?

    Secondly, how do I configure the terminal that comes up to COM33?

    AdThanksVance
  • RaymanRayman Posts: 14,640
    Looks like you have to do:
    Commands->Configure Commands->P2 Defaults
    to compile for P2...
Sign In or Register to comment.