Shop OBEX P1 Docs P2 Docs Learn Events
alphebatizing scheme not working — Parallax Forums

alphebatizing scheme not working

Erik FriesenErik Friesen Posts: 1,071
edited 2008-08-02 18:59 in Propeller 1
I am trying to load a buffer from the eeprom and alphabatize the buffer.· The buffer is 100 longs.· long 0 and 1 are 8 bytes consisting of the file name in bytes. long 2 is the eeprom address, and so on.·

I think what I am trying to do is similar to what I have seen called a bubble sort.

However for some reason this code is swapping the upper bytes and lower bytes to the wrong place, thereby messing up the filenames in the buffer.·

I am hoping that a new set of eyes will help me.

 
pri alphebatize (idsize):corrections|abc,swap0,swap1,swap2 'long 2 and 5 are eeprom address
corrections:=0
repeat abc from 0 to idsize
  if buffer[noparse][[/noparse]abc]<buffer[noparse][[/noparse]abc+3]  'upper letters
    swap0:=buffer[noparse][[/noparse]abc+3]
    swap1:=buffer[noparse][[/noparse]abc+4]
    swap2:=buffer[noparse][[/noparse]abc+5]
    buffer[noparse][[/noparse]abc+3]:=buffer[noparse][[/noparse]abc+0]
    buffer[noparse][[/noparse]abc+4]:=buffer[noparse][[/noparse]abc+1]
    buffer[noparse][[/noparse]abc+5]:=buffer[noparse][[/noparse]abc+2]
    buffer[noparse][[/noparse]abc+0]:=swap0
    buffer[noparse][[/noparse]abc+1]:=swap1
    buffer[noparse][[/noparse]abc+2]:=swap2
    corrections++
  elseif buffer[noparse][[/noparse]abc]==buffer[noparse][[/noparse]abc+3]  'lower letters
      if buffer[noparse][[/noparse]abc+1]<buffer[noparse][[/noparse]abc+4]
        swap0:=buffer[noparse][[/noparse]abc+3]
        swap1:=buffer[noparse][[/noparse]abc+4]
        swap2:=buffer[noparse][[/noparse]abc+5]
        buffer[noparse][[/noparse]abc+3]:=buffer[noparse][[/noparse]abc]
        buffer[noparse][[/noparse]abc+4]:=buffer[noparse][[/noparse]abc+1]
        buffer[noparse][[/noparse]abc+5]:=buffer[noparse][[/noparse]abc+2]
        buffer[noparse][[/noparse]abc+0]:=swap0
        buffer[noparse][[/noparse]abc+1]:=swap1
        buffer[noparse][[/noparse]abc+2]:=swap2
        corrections++        

 
pri loadfiles|temp,totalfiles
longfill(@buffer,0,100)'clear buffer
temp:=0
totalfiles:=0
repeat until not lockset(1) 'lock i2c
repeat temp from 0 to 31     'filename starts at @levels+200
  i2c.readpage(lc512_addr,(projectmemory+200+(temp<<8)),16,(@buffer+(totalfiles*12)),8,1)  
  if buffer[noparse][[/noparse]totalfiles*3]>0 'if memory occupied
     buffer[noparse][[/noparse](totalfiles*3)+2]:=projectmemory+(temp<<8) 'set third long to eeprom address
     totalfiles++   'increment to next buffer location
repeat 10
  alphebatize(totalfiles)
'waitcnt(clkfreq+cnt)
lockclr(1) 'unlock i2c 
return totalfiles

Comments

  • hippyhippy Posts: 1,981
    edited 2008-08-02 14:30
    repeat abc from 0 to idsize

    should that not be

    repeat abc from 0 to idsize step 3
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-08-02 14:57
    Thanks I have been puzzling too long over a duh moment. It is actually 0 to idsize*3 step 3.

    My other problem is that my byte are ordered backwards for the number thing to work so I need to figured out how to swap the bytes. For example "filename" is long "elif" and "eman".
  • hippyhippy Posts: 1,981
    edited 2008-08-02 16:35
    It may even be "(idsize-1)*3" but I'm sure you'll work out the boundary issues. One thing I'd
    do is add methods to determine which is alphabetically before the other and another to do the
    actual swapping; that should simplify things ...

      repeat abs from 0 to idsize*3 step 3
        if SecondBeforeFirst( abc, abc+3 )
          Swap( abc, abc+3 )
    
    



    In the swapping routine you could get a good speed improvement by using LongMove to load
    a 'swap' array, move the long down, re-load the second long ( untested ) ...

    PRI Swap ( first,s econd ) | swap[noparse][[/noparse] 3 ]
      LongMove( @swap, @buffer[noparse][[/noparse] first ], 3 )
      LongMove( @buffer[noparse][[/noparse] first ], @buffer[noparse][[/noparse] second ], 3 )
      LongMove( @buffer[noparse][[/noparse] second ], @swap, 3 )
    
    
    

    Post Edited (hippy) : 8/2/2008 4:43:57 PM GMT
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-08-02 17:58
    You are right hippy. Actually it is idsize-2 to keep the bottom longs from mixing at the end.

    I also had to mod the i2c to load the bytes reverse order.

    Are you sure which long in the longmove instruction gets written to first?

    I like what you are saying about adding methods but as of this posting I have 24 methods in my top object.· I wish there was a way to complete the method and file it away so it looks like the summary view.
  • hippyhippy Posts: 1,981
    edited 2008-08-02 18:16
    You could move the methods into a sub-object. That adds a little overhead in memory use and
    calling time but could build into a generic object useful in other projects or by others.

    In terms of longmove and which long gets written first, does that matter ? Must admit I don't
    understand the nature of that question or the problem you envisage.

    AIUI, longmove( a, b, 3 ) is the same as

    long[noparse][[/noparse]a+0] := long[noparse][[/noparse]b+0]
    long[noparse][[/noparse]a+4] := long[noparse][[/noparse]b+4]
    long[noparse][[/noparse]a+8] := long[noparse][[/noparse]b+8]

    But reversed (+8,+4,+0) when a > b to deal with potentially over-lapped memory spaces.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-08-02 18:59
    Yeah that was a dumb question. I guess that was my brain in the propeller.
Sign In or Register to comment.