PDA

View Full Version : Wierd byte alignment gotcha



Erik Friesen
01-02-2009, 07:17 AM
here is the code



VAR
long flag,position,shiftdn,shiftrt,height,contrast,off
word characterposition
byte chartoprint,sizecolor,loopcommand,loopgo,test3',te st4
byte data[totalsize+1]
byte cols,col,rows,row,size,color,move


PUB Start |q'no backlight
waitcnt(5_000_000+cnt)'Wait for screen to stabilize
contrast:=%100000
long[@data]:=@SL 'send address pointers
long[@data+4]:=@Bl 'to assembly
long[@data+8]:=@characterposition
long[@data+12]:=@chartoprint
cognew(@entry,@data)
waitcnt(5_000_000+cnt)
out($d) 'initialize with small size )
out(1)
out(0)
loopcommand:=1
loopgo:=1

str(string($d,1,"Hello how are you today I am fine thanks and you and what will I do if this doesn't work now?"))
test3:=$FF
'test4:=$aa
loopcommand:=$FF
loopgo:=$aa

'repeat q from 0 to totalsize-1
'data[q]:=$AA
repeat
waitcnt(10000+cnt)

return @data



If I use test4 everything is great. If I comment it out, loopcommand,loopgo, and test3 are a mirror into data[0-3]. Or more correctly said, data[0] equals loopcommand, data[ 1] equals loopgo and data[ 2] equals test3 when set from within spin as shown above.

note- once again the automatic forum deleter strikes again with the brackets shown above( why can't this be fixed?)

Post Edited (Erik Friesen) : 1/2/2009 12:10:14 AM GMT

StefanL38
01-02-2009, 07:38 AM
Hello Erik,

if you insert a space right after the opening square-bracket it will be shown as written

best regards

Stefan

Phil Pilgrim (PhiPi)
01-02-2009, 10:17 AM
Erik,

You can also use www.phipi.com/format (http://www.phipi.com/format) to eliminate the square bracket problem.

-Phil

Erik Friesen
01-02-2009, 10:28 AM
I see whats going on now. Its a case of special characters similar to what C needs to see when placing certain characters within quotes.

Still don't understand the mirror thing though.

mpark
01-03-2009, 02:28 AM
What is totalsize?

Erik Friesen
01-03-2009, 06:39 AM
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

mask=1


pixelwidth = 240
pixelheight= 128
totalsize = (pixelwidth*pixelheight)/8
byteswide = pixelwidth/8

mpark
01-03-2009, 07:18 AM
I can't repro your "mirroring" bug, but you should rethink using @data as the address of a long, for example in this line:

long[@data]:=@SL 'send address pointers

The way you have your vars declared, you have a word, six bytes (if you include test4), and data. That puts data on a long boundary, so saying long[@data] works, but only by chance. Once you comment out test4, data is no longer long-aligned.

Erik Friesen
01-03-2009, 07:24 AM
You are exactly right. Sometimes an extra set of eyes helps I guess. I don't know why it didn't hit me sooner. I had added those in after the fact to an older piece of code.