alphebatizing scheme not working
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.
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
should that not be
repeat abc from 0 to idsize 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".
do is add methods to determine which is alphabetically before the other and another to do the
actual swapping; that should simplify things ...
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 ) ...
Post Edited (hippy) : 8/2/2008 4:43:57 PM GMT
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.
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.