Shop OBEX P1 Docs P2 Docs Learn Events
Clearing my code: Accessing variables between cogs — Parallax Forums

Clearing my code: Accessing variables between cogs

jmspaggijmspaggi Posts: 629
edited 2010-10-05 18:57 in Propeller 1
Hi all,

In my main program, I have some variables declaration:
VAR
  long lfNumber ' How many files do we have in the current directory
  long lfBuffer [c#bufferedFilesName * c#maxLenghtFileName / 4] ' Buffer for file names to display
  long lfCurrent ' Which file, in the buffer, we are pointing at.
  long lfFirst   ' Which file is the first in the buffer. IE, if lfFirst = 10, then buffer contain files from 12 to 12+bufferedFilesName
  long lfChangeDirectory ' $FFFF= Do nothing. $FFFE= One directory up. everything else: Move to the x directory in the current folder.
  long lfPlayFile ' $FFFF= Do nothing. else: Play the file x.

I have a cog which have to handle the SD card and will update/read those variables, so I call it that way:
  sd.start (@lfNumber)

On the cog side, here is the way I'm ready/updating those variables:
      if LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName)] < c#bufferedFilesName
        LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName)]++ '' lfCurrent++
      else
        LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName)+4]++
      LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName+4+4+4)] := LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName+4)] + LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName)] - 1 ''lfPlayFile := lfFirst + lfCurrent - 1

... No comments! I'm sure there is an easier and cleaner way to do that.. Because each time I have to update one of those variables, I have to copy this LONG statement :(

Is there another way to do what I'm doing here?

Thanks,

JM

Comments

  • mparkmpark Posts: 1,305
    edited 2010-10-05 17:14
    You could call sd.start with more pointers:
    sd.start( @lfNumber, @lfBuffer, @lfCurrent, @lfFirst, @lfChangeDirectory, @lfPlayFile )
    
    In sd.start you'd have, in addition to lf_number_addr, lf_buffer_addr, lf_current_addr, etc.

    Alternatively, you could just pass @lfNumber and then compute the other addresses at the beginning of sd.start:
    lf_buffer_addr := lf_number_addr + 4
    lf_current_addr := lf_buffer_addr + constant(c#bufferedFilesName*c#maxLenghtFileName)
    lf_first_addr := lfCurrent + 4
    etc.
    

    Then you could write something like this:
    if LONG[lf_current_addr] < c#bufferedFilesName
            LONG[lf_current_addr]++
    

    Btw, there's a typo in c#maxLenghtFileName.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-05 17:23
    You could also define some local constants like

    CON
    bFN = c#bufferedFilesName
    mLFN = c#maxLengthFileName
    plus = bFN + mLFN
  • jmspaggijmspaggi Posts: 629
    edited 2010-10-05 18:57
    Thanks for your replies.

    I understand for the CON section. I can also rename maxLengthFileName mLFN directly in c. But I like verbose things ;)

    Regarding adding the variables lf_buffer_addr, lf_current_addr and lf_first_addr to the VAR section, that will add 4 bytes per variables :( And I would like to avoid that. Is there a way to reference it directly?

    Since I have only one instance of this object, is there something like the "#" but for the variables and not only the constrantes?

    Thanks,

    JM
Sign In or Register to comment.