Shop OBEX P1 Docs P2 Docs Learn Events
How do you write your time sensitive pasm code? — Parallax Forums

How do you write your time sensitive pasm code?

Agent420Agent420 Posts: 439
edited 2009-09-01 01:09 in Propeller 1
I'm working on hacking one of the video drivers to include support for 3· 64x32 monochrome sprites.· This is my first real foray into pasm programming.· I've done a lot of 8 bit asm with 6502's and avr's, but some aspects of pasm are different enough to make me scratch my head.

For those of you who have programmed time sensitive code, what working style do you use to keep track of your cycles?· Do you keep a running track within comment code on the right?



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • BradCBradC Posts: 2,601
    edited 2009-08-31 12:17
    Agent420 said...

    For those of you who have programmed time sensitive code, what working style do you use to keep track of your cycles? Do you keep a running track within comment code on the right?

    Either that (comments on right) or I print out time sensitive portions and annotate them by hand in pencil. Whatever works for you really.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lt's not particularly silly, is it?
  • ericballericball Posts: 774
    edited 2009-08-31 14:29
    For simple stuff I'll scribble on printouts. But for complicated stuff I'll use an Excel spreadsheet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • Agent420Agent420 Posts: 439
    edited 2009-08-31 14:38
    That's a great idea...· and perhaps I could write a vba macro that automatically associates / calculates clock cycles based on instruction code.·

    It would be neat if there was some kind of plugin that automatically inserted the correct cycle times inside the Propeller Tool, or a similar option for the compiler that provides an automatic listing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • AleAle Posts: 2,363
    edited 2009-08-31 14:38
    I normally comment the amount of cycles used on the right side of the source. I check it with my simulator to see that is does what I want, too. SOmetimes I write it down on paper to consolidate an idea, especially when it is quite vage like accessing external SRAM should take a couple of cycles... but how exactly should I access the external SRAM ?.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • RSimontonRSimonton Posts: 10
    edited 2009-08-31 14:38
    I use an Excel spreadsheet to first work out the numbers.
    Then in the comments I put the clock cycles for each line and then somewhere in the comments I include the total for the routine.
  • Agent420Agent420 Posts: 439
    edited 2009-08-31 14:43
    Ale said...
    I check it with my simulator to see that is does what I want, too.
    Apologies for not knowing, but what simulator would that be?·· That is exactly the kind of thing I would like to do in order to test code ideas that may be incomplete or otherwise not suitable for execution with a debugger.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • potatoheadpotatohead Posts: 10,261
    edited 2009-08-31 15:40
    Deffo Excel + scribbles.

    One thing I find handy is to express things in terms of a primary time unit. In the templates Eric provided for us, that's PLLA / Pixel. This is extremely handy.

    What I like to do with Excel is express everything parametrically, so that changes roll down through the spreadsheet, and if you want to, the driver can respond in real time.

    Do new calcs during the VBLANK, and draw the next frame with the new timings.

    Excel is also handy for proofing out assembly math. I've just started doing this and have had some good results. You run two columns, one with the timings just expressed in ordinary math. Then do the other one using the operations the propeller can do. When they match over a number of values, then code.

    (I have spent way too much time NOT doing that. Live 'n learn.)

    The other thing I find handy is to break your timings down to coarse totals. For NTSC as an example, there are lots of timings that really don't change. Sync, cburst, etc... What can and does change is what that active scanline looks like.

    Do a sum of your base timing for that. The porches, plus the active pixel area. Then, when you decide to change resolutions, you can build your VSCL, calculate number of waitvids, add the PLLAs up, then take the difference between the sum for the scanline, and use that for the porches. This saves a ton of hassle.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
    Safety Tip: Life is as good as YOU think it is!
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-08-31 15:55
    Agent420,


    All of the methods mentioned above are good, you can even use the "{ }" to insert a comment inline with your code.

             {4 clocks} mov temp,  par
    
    




    With hub operations it is easy to lose your determinism, but it can be re-gained by using waitcnt command.
    See this link: http://forums.parallax.com/showthread.php?p=689451

    In the end it is best to measure your timing or at least measure sections of code during the debugging process.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Agent420Agent420 Posts: 439
    edited 2009-08-31 16:06
    Great info, thanks!
    I was coincidentally trying to comprehend the cog synching mechanism, as I may have to add an additional cog to those already in the code source I am hacking away at (which is in here btw).· I see this is how his vga driver accomplishes the task...
    ' Synchronize all cogs' video circuits so that waitvid's will be pixel-locked
                                                                                                  
                            movi    frqa,#(pr / 5) << 2     'set pixel rate (VCO runs at 2x)                     
                            mov     vscl,#1                 'set video shifter to reload on every pixel
                            waitcnt cnt,d8_d4               'wait for sync count, add ~3ms - cogs locked!
                            movi    ctra,#%00001_110        'enable PLLs now - NCOs locked!
                            waitcnt cnt,#0                  'wait ~3ms for PLLs to stabilize - PLLs locked!
                            mov     vscl,#100               'subsequent WAITVIDs will now be pixel-locked!
    

    But what I am having trouble understanding is why the Spin code that launches these cogs allows the first 2 to start before launching the 3rd...· I would think they would all want to be in synch?

    'Launch cogs, abort if error
      repeat i from 0 to 2
        if i == 2                   'cursor cog?
          ifnot cursor_ptr          'cursor enabled?
            quit                    'if not, quit loop
          waitcnt($2000 + cnt)      'cursor cog, allow prior cog to launch
          vcfg_ ^= $10000000        'set two-color mode
          array_ptr_~               'flag cursor function
        ifnot cog[noparse][[/noparse]i] := cognew(@entry, @dira_ + i << 15) + 1
          stop
          return {false}
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Agent420Agent420 Posts: 439
    edited 2009-08-31 17:02
    Another question regarding hub access timings...· would the below timing be correct?· If I understand, there are 9 clocks between hub access periods after using·rdlong, so I need to compensate for any difference?
    ' Do three lines minus horizontal back porch pixels to buy a big block of time
                            mov     vscl,vscl_three_lines_mhb
                            waitvid ccolor,#0               ' start of my timing window (4765 free)
    ' Get cursor data
                            rdlong  cx,regs                 ' unknown 7-22? but creates a base
                            add     regs,#4                 ' + 4
                            rdlong  cy,regs                 ' +12 (7+5 for hub access)
                            add     regs,#4                 ' + 4 
                            rdlong  ccolor,regs             ' +12 (7+5 for hub access)
                            add     regs,#4                 ' + 4
                            and     ccolor,#$FC             ' + 4
                            rdlong  cshape_l,regs           ' + 8 (7+1 for hub access)
                            add     regs,#32                ' + 4
                            shl     ccolor,#8               ' + 4
                            rdlong  cshape_r,regs           ' + 8 (7+1 for hub access)
                            add     regs,#32                ' + 4
                            rdlong  coff,regs               ' +12 (7+5 for hub access)
                            sub     regs,#76                ' + 4
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-31 17:54
    I invariably miscount cycles when trying to add them up a priori and rely much more heavily on strategically placed outa markers that I can measure with a scope. It also makes any hub access jitter instantly obvious.

    -Phil
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2009-08-31 18:06
    Ah the scope-debugging equivalent of a debug write! Clever idea, Phil - thanks - H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • ericballericball Posts: 774
    edited 2009-09-01 01:09
    Agent420 said...
    Another question regarding hub access timings...· would the below timing be correct?· If I understand, there are 9 clocks between hub access periods after using·rdlong, so I need to compensate for any difference?
    Your counts are correct.· Hub access occur on 16 cycle intervals.· When I count I think of the first hub access starting on cycle 0.· Then I add up the cycle counts; rounding up to the next 16 when I get to another hub access.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
Sign In or Register to comment.