Shop OBEX P1 Docs P2 Docs Learn Events
Wierd byte alignment gotcha — Parallax Forums

Wierd byte alignment gotcha

Erik FriesenErik Friesen Posts: 1,071
edited 2009-01-02 23:24 in Propeller 1
here is the code
VAR
long    flag,position,shiftdn,shiftrt,height,contrast,off
word    characterposition
byte    chartoprint,sizecolor,loopcommand,loopgo,test3',test4
byte    data[noparse][[/noparse]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[noparse][[/noparse]@data]:=@SL       'send address pointers
  long[noparse][[/noparse]@data+4]:=@Bl     'to assembly
  long[noparse][[/noparse]@data+8]:=@characterposition
  long[noparse][[/noparse]@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[noparse][[/noparse]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[noparse][[/noparse]0-3]. Or more correctly said, data[noparse][[/noparse]0] equals loopcommand, data[noparse][[/noparse] 1] equals loopgo and data[noparse][[/noparse] 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

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2009-01-01 23:38
    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)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-01-02 02:17
    Erik,

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

    -Phil
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2009-01-02 02:28
    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.
  • mparkmpark Posts: 1,305
    edited 2009-01-02 18:28
    What is totalsize?
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2009-01-02 22:39
    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    
    mask=1      
    
    
    pixelwidth = 240
    pixelheight= 128
    totalsize = (pixelwidth*pixelheight)/8
    byteswide = pixelwidth/8
    
  • mparkmpark Posts: 1,305
    edited 2009-01-02 23:18
    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[noparse][[/noparse]@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[noparse][[/noparse]@data] works, but only by chance. Once you comment out test4, data is no longer long-aligned.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2009-01-02 23:24
    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.
Sign In or Register to comment.