Shop OBEX P1 Docs P2 Docs Learn Events
Is there a library of sub-routines somewhere? - Page 2 — Parallax Forums

Is there a library of sub-routines somewhere?

2»

Comments

  • SapiehaSapieha Posts: 2,964
    edited 2010-12-08 08:52
    Hi Cluso99.

    I still think them need be in OBEX but Maybe as it is now OBEX need some extension to separate Propeller TOOL and Other type of Compiler's.

    As my opinion are that it is good to have them in one place That have separate entries for type of TOOL's used
    Cluso99 wrote: »
    Thanks Steve :) I have never used a cpp or the GNU chain so I am glad you answered the question.

    I agree with the comments that the code snippets should be kept separate from the OBEX or it will get too cluttered. So, unless Parallax want to jump in now, I guess the wiki will do. I am not a fan of the wiki because it is more open to abuse than a privately held site like the OBEX.
  • potatoheadpotatohead Posts: 10,261
    edited 2010-12-08 09:19
    Re: Wiki abuse.

    Yep, however, ours is archived, and does have revision control, with a few of us looking at it. No real harm is gonna get done. I take a full archive, from time to time as well. Actually, it's getting time to do that again.

    We have not used it much, but the other thing the Wiki can do is have some basic discussion. Say somebody sees a improvement, or bug, or a use case limit of some kind. Those could be discussed, with that discussion contained with the code.

    @Heater, I like code repositories like that. Where? Sourceforge, or something? There is a conflict in my mind over just snippets, and projects and a code repository. Thinking of a greater library that can be pulled when people want it maybe? Best of? Curious about how that could / might work.
  • lonesocklonesock Posts: 917
    edited 2010-12-08 17:10
    Semi-on-topic:

    Self-contained PASM code fragments are nice for when you want to just add some functionality to your existing PASM code. It's a different story if you want to access to a variety of PASM functions from Spin.

    If you want to re-use a cog to call a bunch of PASM functions from Spin, you can simply cognew the code each time of course. But then you get the 512longs * 16clocks of load time, followed by run time, followed by the time spent checking to see if the function is done.

    You can also do an overlay loader cog (which can minimize load times, but suffers the same "checking to see if we're done" problem), but of course you have to have specify an interface (which is usually a bit cumbersome) on how to call & use the PASM overlay fragments. I'm attaching a fairly simple implementation of this.

    The reason I bring this up is that if there is interest in a repository of PASM overlay functions, it might be nice to adopt a common interface if possible (certainly doesn't have to be mine!) to ease code reuse.

    Here's my example code:
    {{
      Test PFunc - the PASM Functionalizer
    
      Jonathan "lonesock" Dummer
    }}
    
    ' set for the standard 5MHz crystal...this must be correct for the serial code to work
    CON
      _CLKMODE = XTAL1 + PLL16X 
      _XINFREQ = 5_000_000
    
    OBJ
      term          : "FullDuplexSerial"
      pf            : "PFunc"
      
    PUB main | i, s, tSpin, tPF
    
      ' init my objects
      term.start( 31, 30, 0, 115_200 )
      waitcnt( (clkfreq >> 2) + cnt )
      pf.start
    
      ' OK, try testing something
      pf.run( @pf_SimpleTest, @i )
      term.str( string( 13, 13, "The simple test: 105 =?= " ) )
      term.dec( i )
      term.tx( 13 )
    
      ' Try the 2nd test
      i := 254870
      's := i
      tSpin := -cnt
      s := ^^i
      tSpin += cnt
      tPF := -cnt
      pf.run( @pf_TestSQRT, @i )
      tPF += cnt
      term.str( string( "The sqrt test: " ) )
      term.dec( s )
      term.str( string( " =?= " ) )
      term.dec( i )
      term.str( string( 13, "Timing (PF vs Spin): " ) )
      term.dec( tPF )
      term.str( string( " vs " ) )
      term.dec( tSpin )
      term.tx( 13 )
        
    
    '' simple example: write a value into (fake) PAR
    DAT
    ORG pf#PAR_address
    pf_SimpleTest           long    startvalue-pf_SimpleTest ' length of this routine (excluding this register)
                            mov     value, startvalue
                            add     value, #5
                            wrlong  value, pf#PAR_address
    
                            jmp     #0                      ' done with the function
    
    startvalue    long      100
    value         res       1
    
    
    '' harder example, take the square-root of an integer
    DAT
    ORG pf#PAR_address
    pf_TestSQRT             long    mask-pf_TestSQRT ' length of this routine (excluding this register)
                            rdlong  input, pf#PAR_address 
                            mov     root, #0                'reset root
    :loop                   or      root,mask       'set trial bit
                            cmpsub  input,root wc   'subtract root from input if fits
                            sumnc   root,mask       'cancel trial bit, set root bit if fit
                            shr     root,#1         'shift root down
                            ror     mask,#2 wc      'shift mask down
                  if_nc     jmp     #:loop          'loop until mask empty
                            wrlong  root, pf#PAR_address
    
                            jmp     #0                      ' done with the function
    
    mask          long      $40000000
    input         res       1
    root          res       1
    
    And here is the output:
    The simple test: 105 =?= 105
    The sqrt test: 504 =?= 504
    Timing (PF vs Spin): 3696 vs 1680
    

    Jonathan
  • Chris_DChris_D Posts: 305
    edited 2010-12-09 02:54
    Looks to me like the community has come up with a solution once again! Now how do we get people to put these code fragments into it?

    Chris
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-12-09 15:53
    lonesock: I have posted a fast overlay loader (pasm) in OBEX. It is the basis of ZiCog's non-resident emulation code segments.

    Chris_D: SO where are we going to put them? OBEX or Wiki ? I prefer obex so long as we have a separate section called "code snippets" or whatever. We need to ask Parallax to create a new section. Ken/Bump..?
  • Chris_DChris_D Posts: 305
    edited 2010-12-10 03:19
    Cluso99, I agree with you, a code snippets section on the object exchange would make a lot of sense. It was the first place I started looking for things like that.

    PARALLAX HELP!!!!!!!!!!!!!!
  • Chris_DChris_D Posts: 305
    edited 2010-12-14 02:37
    Bumping thread to the top
  • prof_brainoprof_braino Posts: 4,313
    edited 2010-12-14 06:52
    potatohead wrote: »
    I like code repositories like that. Where? Sourceforge, or something? There is a conflict in my mind over just snippets, and projects and a code repository. Thinking of a greater library that can be pulled when people want it maybe? Best of? Curious about how that could / might work.

    Google code is great as a code repository. Of course, somebody has to own it. If a parallax desiginee controled user registration, google code might be an option for non-obex code explorations. Of course, google code is the only one I have experience with, so it might not be the most suitable.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-12-14 22:48
    PARALLAX HELP!!!!!!!!!!!!!!

    Chris_D, any chance you could host something? Or at least, start collecting some fragments? I've got a few I can send you if you want to start acting as the 'keeper of the code fragments'.
  • Chris_DChris_D Posts: 305
    edited 2010-12-15 02:34
    @ Prof Braino

    I think it would be best to keep this on the Parallax website where people would naturally go to find such things. BTW, not much creeps me out, but your avatar creeps me out - yikes.

    @ Dr_Acula

    I have no website or webspace anywhere but I certainly wouldn't mind being the keeper of the code fragments till I can convince Paralllax to provide a proper home. Perhaps we shold post these code-frags here in this thread?

    Chris
  • ErNaErNa Posts: 1,752
    edited 2010-12-15 02:46
    Off topic: cost of goods sold (COGS) : Is it this ? or what does COGs stand for?
    I could easily give away some webspace, and also I could try to make a directory of such modules. I do not follow this thread on a regular basis, but what about placing such snippets of code in the second half of a 64k eeprom, like in the protoboard?
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-12-15 04:54
    hm why not using just some keywords like "codesnippets" "subroutine" etc. and upload into the tool-section of the OBEX?

    These subroutines are tools.

    best regards
    Stefan
Sign In or Register to comment.