Shop OBEX P1 Docs P2 Docs Learn Events
trouble with array containing mixed-length strings with a data byte — Parallax Forums

trouble with array containing mixed-length strings with a data byte

Hello,

I'm having trouble figuring out what I'm doing wrong.

OBJECTIVE:
Repeat the following for all entries in @Files
Read a filename(string), null-terminated. Read a byte of data associated with said filename.
DAT
Files
  byte { "filename" , 0, byte,  
       } "temp1"    , 0,  $31, {
       } "temp23"   , 0,  $32, {
       } "temp456"  , 0,  $34, {
       } $FF
PUB MAIN
  InitializeFiles(@Files)

PRI InitializeFiles(FilesPointer) | pointer, entry, dataoffset, datasize

  datasize:=1
  pointer~
  repeat until byte[FilesPointer][pointer]==$FF   '                                                                   
    DisplayCLS                                    ' files = "temp1,temp23,temp456"                                    
                                                  '                                                                   
    DisplayHex(0,0,byte[FilesPointer][pointer],2) ' first pass = $74      second pass = $74          third pass = $6D 
    entry     :=FilesPointer[pointer]             '                                                                   
    dataoffset:=strsize(entry)+1                  '                                                                   
    DisplayStr(1, 0,entry                    )    ' first pass = "temp1"  second pass = unprintable  third pass = unprintable     
    DisplayDec(2, 5,pointer                  )    ' first pass = 0        second pass = 7            third pass = 9    
    DisplayDec(2,10,dataoffset               )    ' first pass = 6        second pass = 1            third pass = 1    
    DisplayHex(1,18,byte[entry][dataoffset],2)    ' first pass = $31      second pass = $B4          third pass = $B4    
                                                  '                                                                   
    DisplayPage                                   '                                                                   
    pause(32)                                     '                                                                   

    pointer+=dataoffset+datasize ' advance pointer to next filename (or $FF)


The .SPIN file containing the code above was extracted from a larger program. The larger program was copied into a new file and code unnecessary to help bring focus to the problem was removed. All necessary files for execution are included in the archive attached.

This code is being developed for a Propeller Activity Board. A 4x20 Serial LCD Display is connected at P12.

Thanks, in advance, for your help.
pidzero

Comments

  • pidzero wrote: »
    I'm having trouble figuring out what I'm doing wrong.

    What is happening unexpected?

  • Duane Degn wrote: »
    pidzero wrote: »
    I'm having trouble figuring out what I'm doing wrong.

    What is happening unexpected?

    My apologies for not indicating this in the OP.

    The results I'm getting are documented in the PRIvate method InitializeFiles of the code in the OP.
    The "first pass" results are as expected. The "second pass" and "third pass" results are unexpected.

    On execution, the first pass produces this text on the LCD. The data produced is as expected.
    74
    temp1             31
         0    6
    

    On second pass, I expect the following:
    74
    temp23            32
         7    7
    

    On third pass, I expect the following:
    74
    temp456           34
        15    8
    

    Instead, on the second pass I get:
    74
                      B4
         7    1
    

    The third pass displays this:
    6D
                      B4
         9    1
    

    Also, I failed to note in the OP that the faulty loop executes more than the 3 times necessary to produce the expected results.
  • I received a PM with information indicating the problem code:
    This
    entry := FilesPointer[pointer]
    
    should most likely be entry := FilesPointer + pointer, the former is an array access of all input parameters which are treated as longs.

    Changing the code as suggested produced the results I expected.
  • pidzero wrote: »
    Changing the code as suggested produced the results I expected.

    Good to hear.

    Thanks for letting us know what the problem was.

    BTW, welcome to the forum.

Sign In or Register to comment.