Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic & Viewport — Parallax Forums

PropBasic & Viewport

FriedVFriedV Posts: 77
edited 2012-10-12 13:45 in Propeller 1
After several trial & error attempts, I'm stuck:
Using PropBasic I compiled the following to spin code:
' ----------------------------------------------------------------------
' File......    Counter.pbas
' Author....    fgvissel    15.09.2011
' ----------------------------------------------------------------------

' ----- Device Settings ------------------------------------------------
    DEVICE P8X32A, XTAL1, PLL16X
    XIN 5_000_000

' ----- Conditional Compilation Symbols --------------------------------
 
' ----- Constants ------------------------------------------------------

' ----- IO Pins --------------------------------------------------------
    Leds Pin 3..0 Low
' ----- Shared (HUB) Variables (Byte, Word, Long) ----------------------
    counter HUB long = 0
' ----- User Data (DATA, WDATA, LDATA, FILE) ---------------------------

' ----- TASK Definitions -----------------------------------------------

' ----- Local Variables (LONG only) ------------------------------------
    locCounter VAR long
    delta VAR long
    target VAR long
' ----- SUB and FUNC Definitions ---------------------------------------

PROGRAM Start

Start:
' setup code
Main:
    rdlong 0, delta
    delta = delta >> 2
    target = cnt +delta
    do
        rdlong counter, locCounter
        locCounter = locCounter + 1
        wrlong counter, locCounter
        Leds = locCounter
        if loccounter = 16 then
            loccounter = 1
            wrlong counter, loccounter
            endif
        waitcnt target, delta 
        loop


GOTO Main
END
Program works fine on Propeller chip, showing counter on the 4 leds.
Then I edited the Spin code adding the conduit object
and adding two vp.config lines:
'{$BST PATH C:\Work\Propeller\PBasic\Stingray}
''  *** COMPILED WITH PropBasic VERSION 00.01.14  July 26, 2011 ***
                                                             '' ----------------------------------------------------------------------
                                                             '' File......  Counter.pbas
                                                             '' Author....  fgvissel  15.09.2011
                                                             '' ----------------------------------------------------------------------

                                                             '' ----- Device Settings ------------------------------------------------


CON                                                          '  DEVICE P8X32A, XTAL1, PLL16X
  _ClkMode = XTAL1 + PLL16X                                 

  _XInFreq = 5000000                                         '  XIN 5_000_000


                                                             '' ----- Conditional Compilation Symbols --------------------------------

                                                             '' ----- Constants ------------------------------------------------------

                                                             '' ----- IO Pins --------------------------------------------------------
'   Leds Pin 3..0 Low                                         '  Leds Pin 3..0 Low

                                                             '' ----- Shared (HUB) Variables (Byte, Word, Long) ----------------------
' HUB LONG counter                                           '  counter HUB long = 0

                                                             '' ----- User Data (DATA, WDATA, LDATA, FILE) ---------------------------

                                                             '' ----- TASK Definitions -----------------------------------------------

                                                             '' ----- Local Variables (LONG only) ------------------------------------
'   locCounter VAR long                                       '  locCounter VAR long

'   delta VAR long                                            '  delta VAR long

'   target VAR long                                           '  target VAR long

                                                             '' ----- SUB and FUNC Definitions ---------------------------------------
VAR
  long frame[400]

OBJ

  vp : "Conduit"                             ' Declare ViewPort conduit


PUB __Program

  vp.config(string("var:counter"))
  vp.share(@counter,@counter)
                                                'PROGRAM Start
  CogInit(0, @__Init, @__DATASTART)

DAT
                  org           0                           
__Init                                                      
__RAM                                                       
                  mov           dira,__InitDirA             
                  mov           outa,__InitOutA             
                  jmp           #Start                      


Start                                                        'Start:

                                                             '' setup code
Main                                                         'Main:

                  mov           __temp1,#0                   '  rdlong 0, delta
                  rdlong        delta,__temp1               

                                                             '  delta = delta >> 2
                  shr           delta,#2                    

                  mov           target,cnt                   '  target = cnt +delta
                  adds          target,delta                

__DO_1                                                       '  do

                  mov           __temp1,par                  '    rdlong counter, locCounter
                  rdlong        locCounter,__temp1          

                                                             '    locCounter = locCounter + 1
                  adds          locCounter,#1               

                  mov           __temp1,par                  '    wrlong counter, locCounter
                  wrlong        locCounter,__temp1          

                  cmps          locCounter,#16 WZ, WC        '    if loccounter = 16 then
    IF_NE         jmp           #__ELSE_1                   

                  mov           locCounter,#1                '      loccounter = 1

                  mov           __temp1,par                  '      wrlong counter, loccounter
                  wrlong        locCounter,__temp1          

__ELSE_1                                                     '      endif
__ENDIF_1                                                   

                  waitcnt       target,delta                 '    waitcnt target, delta 

                  jmp           #__DO_1                      '    loop
__LOOP_1                                                    



                  jmp           #Main                        'GOTO Main

                  mov           __temp1,#0                   'END
                  waitpne       __temp1,__temp1             


                                                             '' ----- SUB and FUNC Code ----------------------------------------------

                                                             '' ----- TASK Code ------------------------------------------------------



                                                             '' ----------------------------------------------------------------------
'**********************************************************************
__InitDirA       LONG %00000000_00000000_00000000_00001111
__InitOutA       LONG %00000000_00000000_00000000_00000000
Leds             LONG 15 << 0
_FREQ            LONG 80000000


__remainder
__temp1          RES 1
__temp2          RES 1
__temp3          RES 1
__temp4          RES 1
__temp5          RES 1
__param1         RES 1
__param2         RES 1
__param3         RES 1
__param4         RES 1
__paramcnt       RES 1
locCounter       RES 1
delta            RES 1
target           RES 1

FIT 492

CON
  LSBFIRST                         = 0
  MSBFIRST                         = 1
  MSBPRE                           = 0
  LSBPRE                           = 1
  MSBPOST                          = 2
  LSBPOST                          = 3
  counter_ofs                      = 0

DAT
__DATASTART
counter          LONG 0
When compiling the code, it flags warnings in the conduit.spin:
org without value
and several
JMP/DJNZ without #

Running Viewport and loading the propeller works partially,
I can watch the counter var in Viewport, but the Propeller does not execute the program,
and the red interface led stays on.
What to do?
Thx, Friedrich
«134

Comments

  • BeanBean Posts: 8,129
    edited 2011-09-16 05:59
    I posted your spin code into viewport and it ran fine. I didn't get any errors. I did notice that the spin code does NOT have the "Leds=locCounter" line though...

    I was not able to compile your PropBasic code because of invalid characters...

    Bean
  • FriedVFriedV Posts: 77
    edited 2011-09-16 08:39
    Strange, I compiled the PropBasic File to Spin without any problems.

    The Leds Pin 3..0 Low is compiled to
    __InitDirA LONG %00000000_00000000_00000000_00001111
    __InitOutA LONG %00000000_00000000_00000000_00000000

    The spin compiler output are only warnings, not errors, perhaps you disabled them.
    I tried again to load the edited spin file into viewport, and now all seems to be fine.
    What worries me a bit is invalid character error your getting with the PropBasic Compiler.
    I use win7 on a MacBook with the German Keyboard and environment, perhaps this is the reason.
  • HannoHanno Posts: 1,130
    edited 2011-09-16 15:31
    Hi,
    Thanks Bean for looking into this. Is there anything I should do to make PropBasic work better with ViewPort?
    Hanno
  • BeanBean Posts: 8,129
    edited 2011-09-16 19:30
    Hanno,
    One problem is that I have to use BST to compile PropBasic code to a .spin file. Then switch to Viewport and reload the .spin file with every source code change.
    Another problem is that Viewport doesn't seem to like the spaces in the .spin file. I'm not sure why, but it shows vertical lines.

    See attached screen image and .spin file

    Bean
  • FriedVFriedV Posts: 77
    edited 2011-09-17 00:36
    Thanks Bean for the nice trick to get spin code into PBasic, I used to edit the spin file separately, a real pain! Much better now.
    The vertical bars in Viewport are AFAIK only a visual help to show indentation.
    Fried
  • HannoHanno Posts: 1,130
    edited 2011-09-17 01:41
    Glad things are working for you Fried!

    Bean- Yes, the vertical lines are a "feature". ViewPort places the vertical lines at every tab stop up to the first text- works great for properly indented spin code, not ideal on indented comments.

    12Blocks recognizes when the underlying file was changed by another process and then prompts the user "File has changed, reload file"- I could do the same thing for ViewPort. That way you could use other tools to edit PropBasic, compile to spin- and tab to ViewPort to debug- all without file browsing.

    Even smoother would be to edit PropBasic in ViewPort and press "Run" to compile to spin and upload. That already works for Catalina C and Basic for the BS2 chips. Looks like I'll need to read up on how to compile PropBasic :)
    Hanno
  • BeanBean Posts: 8,129
    edited 2011-09-17 05:05
    Hanno wrote: »
    Even smoother would be to edit PropBasic in ViewPort and press "Run" to compile to spin and upload. That already works for Catalina C and Basic for the BS2 chips. Looks like I'll need to read up on how to compile PropBasic :)
    Hanno

    Hanno,

    PropBasic.exe "full path to pbas file" /switches

    Switches:
    /Q = Quiet (No screen output)
    /P = Pause on warning or error (used to debug compiler)
    /B = Brief output (does not show source code)
    /O = "Output_Directory" Specifies a diffrent directory for output files
    /V = Returns Version number as exit code (exit immediately)
    /NC = No Code (Does NOT include the BASIC code in the output file)

    The path to to pbas file MUST be in quotes.
    The files invalid.txt and reserved.txt must be in the same directory as propbasic.exe
    The compiler will create a .spin file in the same directory as the source file (unless the /O switch is used).
    The compiler will create a .err file in the same directory as the source file (unless the /O switch is used). This tell you where the errors/warnings have occured.

    Code that writes to error file when an error occurs:
        Write(g_tfErr, 'ERROR,', g_sCurrentFile, ',', g_iInLineCnt, ',', pv_iError, ',', c_asErrorText[pv_iError]);
        If pv_iParam <> 0 Then WriteLn(g_tfErr, ' "', g_asCmdLine[pv_iParam], '"') Else WriteLn(g_tfErr);
    

    Code that writes to error file when a warning occurs:
        Write(g_tfErr, 'WARNING,', g_sCurrentFile, ',', g_iInLineCnt, ',', pv_iWarning, ',', c_asWarningText[pv_iWarning]);
        If pv_iParam <> 0 Then WriteLn(g_tfErr, ' "', g_asCmdLine[pv_iParam], '"') Else WriteLn(g_tfErr);
    

    Hanno, Let me know if you need any more info.

    Bean
  • HannoHanno Posts: 1,130
    edited 2011-09-17 16:09
    Awesome- Thanks Bean!
    Am busy with kids today but should get this into VP tomorrow. Thanks for including your error code- that helps immensely for parsing.
    I hope to:
    - include PropBasic configuration options in program preferences to let users specify where PropBasic is installed and what flags to use.
    - use syntax highlighting for BASIC- I'll look at your .txt files for inspiration of additional keywords to highlight
    - turn off vertical lines while editing BASIC
    - compile to spin, compile to bytecode, find prop, load prop all in one step- with appropriate error handling at each step
    - "view spin code"
    - navigate and highlight syntax errors
    - include some tutorials showcasing ease of PropBasic and visual debugging of ViewPort
    - allow users to develop basic code and then debug resulting spin code with breakpoint/line by line stepping.

    Am I missing anything?
    Hanno
  • BeanBean Posts: 8,129
    edited 2011-09-17 19:23
    Hanno,
    That would be great to have PropBasic supported in ViewPort.
    One issue is that PropBasic uses COG RAM for variables. So they only can be "seen" by viewport by writing the values to HUB RAM. But I don't think there is anything that can be done about that.

    I am also willing to modify PropBasic to support Viewport also. It would be cool to be able to use "WATCH varName", and "BREAK" in PropBasic.

    With the speed of PropBasic I bet some good demos of using the "video from propeller" could be done (game of life comes to mind).

    Bean
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-17 19:51
    @Bean: Are you looking into the Leds=locCounter issue? It does generate code in my - admittedly rather old - version (0.98a). Just checked the latest(?) 1.14-79 and this does generate proper code for it. Odd.
  • BeanBean Posts: 8,129
    edited 2011-09-17 20:27
    Yeah, I think that was fixed in a recent update.

    Bean
  • HannoHanno Posts: 1,130
    edited 2011-09-18 00:38
    I've managed to sneak in a bit of time see attached for status!
    Hanno
    ps- Yes, please add at least a "WATCH" keyword to easily monitor variables (and arrays?)
    How do you envision "BREAK" working?
  • BeanBean Posts: 8,129
    edited 2011-09-18 11:11
    Hanno,
    That looks good, but don't call it "pbasic" that is what Parallax uses for the basic stamps. IOW PropBasic is not pbasic. I would call it either "basic" or "propbasic".

    BREAK would be for break-points. What would I have to do to implement that on my end ? Single stepping might be alot harder, but break-points would be nice.

    I think I'll have to have some kind of "sync" or "update" command to transfer the variable values to HUB ram (and get values changed in viewport). I would be harder to update variables "on the fly".

    Bean
  • HannoHanno Posts: 1,130
    edited 2011-09-18 13:36
    Hi Bean,
    Thanks! Sorry for the name mixup- I'll make sure it's called "PropBasic" everywhere. For Catalina C and Spin users can single step and set breakpoints at run time- ie they can let code run to a point, set another breakpoint and run again- just like in Visual Studio. An intermediate solution could involve what I think you're suggesting- having the user add "break" statements into their code where the program pauses until it receives some command from ViewPort. I think a "sync" command to update variables is fine "for now". At some point I/we could look into adding some of conduit's functionality into your "interpreter" to allow both full breakpoints/stepping and full ViewPort monitor/view variables. But let's do this one step at a time :)
    Hanno
  • HannoHanno Posts: 1,130
    edited 2011-09-18 23:27
    Ok, time for you to have a play with the latest!
    ViewPort v4.63 now has support for PropBasic including:

    + include PropBasic configuration options in program preferences to let users specify where PropBasic is installed and what flags to use.
    + can configure vertical lines on/off
    + use syntax highlighting for PropBasic
    + compile to spin, compile to bytecode, find prop, load prop all in one step- with appropriate error handling at each step
    + compiled propbasic "spin" files are left in source directory- can view/edit/run those
    + navigate and highlight syntax errors- both PropBasic and Spin
    + include some tutorials showcasing ease of PropBasic and visual debugging of ViewPort
    + allow users to develop basic code and then debug resulting spin code with breakpoint/line by line stepping.
    + if source file changed by other editor, ViewPort will ask if want to reload

    Attached is updated guide. Download the latest ViewPort beta from here:
    http://hannoware.com/viewport/beta.php
    I'd love feedback!
    Hanno
  • FriedVFriedV Posts: 77
    edited 2011-09-18 23:30
    Hi Bean & Hanno,
    thanks very much for your efforts. If you want me to beta test any of the combo PropBasic/Viewport versions,
    I'd be glad to do so.
    Here is the "syntax" file I use with Edit3+ (BTW I like this editor very much because of it's very flexible
    user interface configuration)
    Fried
    #TITLE=PROPELLER BASIC
    ; Syntax file for PBASIC written my Michael Schwab (mcstar)
    ; modified by fgv

    #DELIMITER=,(){}[]-+*%/=~!&|\<>?:;.#$
    #QUOTATION1="
    #QUOTATION2=
    #LINECOMMENT='
    #WHOLELINE=
    #LINECOMMENT2=rem
    #COMMENTON=
    #COMMENTOFF=
    #ESCAPE=\
    #CASE=N
    #PREFIX1=
    #PREFIX2=
    #PREFIX3=
    #PREFIX4=
    #PREFIX5=
    #SUFFIX1=
    #SUFFIX2=
    #SUFFIX3=
    #SUFFIX4=
    #SUFFIX5=
    #UNARY=ABS,SGN

    ; Reserved words
    #KEYWORD
    ABS
    ADD
    ADDRESS
    AND
    ANDN
    ASM
    BIT
    BRANCH
    BYTE
    CALL
    CNT
    COGSTART
    CON
    CTRA
    CTRB
    DATA
    DEC
    DEVICE
    DIRA
    DIRB
    DJNZ
    DO
    ELSE
    ELSEIF
    ENDIF
    FALSE
    FOR
    FREQ
    FRQA
    FRQB
    GOSUB
    GOTO
    HIGH
    HUB
    I2CREAD
    I2CWRITE
    I2CSPEED
    I2CSTART
    I2CSTOP
    IF
    INA
    INB
    INC
    INCLUDE
    INPUT
    LET
    LOAD
    LOCKCLR
    LOCKNEW
    LOCKRET
    LOCKSET
    LONG
    LOOP
    LOW
    MAX
    MIN
    NEVER
    NEXT
    NOCODE
    NOP
    NOT
    ON
    OR
    OUTA
    OUTB
    OUTPUT
    OWRDBIT
    OWRDBYTE
    OWRESET
    OWWRBIT
    OWWRBYTE
    OWWRITE
    OWREAD
    PAR
    PAUSE
    PAUSEUS
    PHSA
    PHSB
    PIN
    PLL1X
    PLL2X
    PLL4X
    PLL8X
    PLL16X
    PULSIN
    PULSOUT
    RANDOM
    RCFAST
    RCL
    RCR
    RCSLOW
    RCTIME
    RDBYTE
    RDLONG
    RDWORD
    REM
    REPEAT
    RETURN
    REVERSE
    ROL
    ROR
    SERIN
    SEROUT
    SGN
    SHIFTIN
    SHIFTOUT
    SHL
    SHR
    STEP
    STR
    SWAP
    TEST
    THEN
    TO
    TOGGLE
    TRUE
    UNTIL
    VAL
    VAR
    VCFG
    VSCL
    WAITCNT
    WAITPEQ
    WAITPNE
    WAITVID
    WATCH
    WHILE
    WORD
    WRBYTE
    WRLONG
    WRWORD
    XIN
    XOR
    XTAL1
    XTAL2
    XTAL3

    ; Compile Time Options
    #KEYWORD
    '{
    }
    $DEF
    $UNDEF
    $IDEF
    $IFDEF
    $ELSE
    $ENDIF
    $IFFREQ
    $WARNING
    $ERROR
    $USES

    ; Functions and Subs
    #KEYWORD
    END
    ENDASM
    ENDSUB
    ENDTASK
    EXIT
    ENDFUNC
    ENDSUB
    FUNC
    SUB
    TASK
    PROGRAM

    ; Data Types
    #KEYWORD
    BYTE
    WORD
    LONG

    ; Operators
    #KEYWORD
    -
    &
    &~
    *
    /
    //
    ^
    |
    +
    <<
    >>


    ; System Variables
    __TEMP1
    __TEMP2
    __TEMP3
    __TEMP4
    __TEMP5
    __PARAM1
    __PARAM2
    __PARAM3
    __PARAM4
    __PARAMCNT
    _CLKFREQ
    _CLKMODE
    _FREE
    _STACK
    _XINFREQ
  • skynuggetskynugget Posts: 172
    edited 2011-09-20 03:46
    hey hanno, i have been trying to download the beta at http://hannoware.com/viewport/beta.php, but i get a 500 error. is it me or you? thanks!
  • HannoHanno Posts: 1,130
    edited 2011-09-20 07:19
    Hi Skynugget,
    Seems my phpbb forum software broke itself- I'm working with hosting provider to get it fixed.
    In the mean time, you can download v4.63 here: http://hannoware.com/viewport/viewport463.exe
    Thanks Fried for the highlighting help, I'll make good use of it.
    Hanno
  • HannoHanno Posts: 1,130
    edited 2011-09-20 13:31
    Daily backups of all files and database tables are a nice thing to have! All is fine now..
    Hanno
  • skynuggetskynugget Posts: 172
    edited 2011-09-20 16:03
    it looks like their may be a bug if you have multiple TASKS in your code. it looks like there is a sharing violation when viewport tries to open the TASK's resulting spin file.

    will viewport compile LMM code properly, or will you have to still sue bst for that?

    thanks for adding propbasic, you just sold another copy of viewport :)
    1024 x 640 - 87K
  • BeanBean Posts: 8,129
    edited 2011-09-20 16:23
    skynugget,
    I'm looking into it...

    Bean
  • skynuggetskynugget Posts: 172
    edited 2011-09-20 16:32
    take your time, i gave up on trying to use it a while ago, not realizing that cedit not being able to compile LMM code was my problem the whole time till a couple days ago!
  • HannoHanno Posts: 1,130
    edited 2011-09-20 16:44
    Thanks for giving this a try skynugget, I'm happy it's "mostly" working for you.
    Bean- sounds like PropBasics isn't closing an included file?
    ViewPort uses the HomeSpun spin compiler- should produce same code as BST.
    Hanno
  • BeanBean Posts: 8,129
    edited 2011-09-20 16:49
    Hanno,
    I can't get anything to compile. It keeps saying "File Not Found".
    Does the {0} return the complete path to the *.pbas file ? PropBasic.exe needs the complete path.

    I have attached the compiler (without the BST modifications). That should work.
    [edit] see later posts for latest version...

    Bean
  • HannoHanno Posts: 1,130
    edited 2011-09-20 16:58
    Hi Bean,
    Yes, {0} provides the complete path to the *.pbas file.
    I placed your "PropBasic.exe" file into "C:/Program Files/PropBasic/PropBasic.exe", loaded "29_PropBasic.pbas" in ViewPort and pressed "Run".
    If it can't find "PropBasic" it should tell you to install it/edit settings.
    Hanno
  • BeanBean Posts: 8,129
    edited 2011-09-20 17:01
    It can't find the .spin file that propBasic is suppose to generate.
    If I compile it and place the .spin file in the same directory it ViewPort will load it.
    But if I change the .pbas file and press "RUN" Viewport loads the old .spin file. I assume that the compiler is terminating without compiling.
    Would it be possible to not hide the window that PropBasic.exe is running in ?

    Bean
  • BeanBean Posts: 8,129
    edited 2011-09-20 17:15
    Hanno,
    Make sure you don't have 29_PropBasic.spin already in that directory.
    Viewport may be just loading the file that is already there.

    Bean
  • BeanBean Posts: 8,129
    edited 2011-09-20 17:18
    Never mind. My bad...
    I didn't have the two .TXT file in the directory with PropBasic.exe

    Bean
  • HannoHanno Posts: 1,130
    edited 2011-09-20 17:19
    Very odd, when using the " PropBasic_1_15.zip" 2 posts up, I'm now seeing the "file not found" error.
    Until now I've been using your "PropBasicBST" file- that hasn't had any issues. What's the difference between those two?
    I'm running the compiler in a process- not trivial to show both standard out and error due to threading issues, but I'll work on it.
    Hanno
  • BeanBean Posts: 8,129
    edited 2011-09-20 17:21
    Hanno,
    See my previous post. I had forgotten to put the two .TXT files in the same directory "Reserved.txt" and "invalid.txt".

    The version 1.15 doesn't have the BST hooks. I'm not sure what these are as BradC modifies it.

    With the version 1.15 that I just posted you can run this program:
    DEVICE P8X32A, XTAL1, PLL16X
    XIN 5_000_000
    
    cntr  VAR LONG
    cntr2 VAR LONG
    
    WATCH cntr
    WATCH cntr2
    
    PROGRAM Start
    
    Start:
      FOR cntr = 1 to 10
        FOR cntr2 = 1 to 10
          PAUSE 1
        NEXT
      NEXT
      GOTO Start
    END
    

    Bean
Sign In or Register to comment.