Shop OBEX P1 Docs P2 Docs Learn Events
Modifying Dat in program. — Parallax Forums

Modifying Dat in program.

Clock LoopClock Loop Posts: 2,069
edited 2009-06-06 23:43 in Propeller 1
Can a dat entry, like such.

DAT

FourBytes                byte    $00, $FF, $00, $0F  




Be modified in a running program?

Say I wanted to modify the first byte in FourBytes.

From value $00 to value $FF. How would I do this?

I tried looking at the prop manual, and didn't see anything there. I tried a forum search...

Comments

  • RaymanRayman Posts: 14,829
    edited 2009-06-05 12:47
    There are many ways to do it... One is:

    byte[noparse][[/noparse]@FourBytes]:=$FF

    You can also just do (since you just want the first byte):

    FourBytes:=$FF

    If you want to get at·the nth byte (n=0..3), you can do:

    FourBytes[noparse][[/noparse]n]:=$FF

    or,

    byte[noparse][[/noparse]@FourBytes][noparse][[/noparse]n]:=$FF

    or,

    byte[noparse][[/noparse]@FourBytes+n]:=$FF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
  • Clock LoopClock Loop Posts: 2,069
    edited 2009-06-05 12:55
    So DAT is just a different way of declaring a variable?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Meh. Nothing here, move along.
  • heaterheater Posts: 3,370
    edited 2009-06-05 13:10
    Yes and no.

    If you create many instances of an object in your program they will all have their own private VAR space in memory but they will all share the same DAT space.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Clock LoopClock Loop Posts: 2,069
    edited 2009-06-05 18:54
    I get it now.

    If I ran 2 copys of the same object(different names), their DAT statements would be accessable to eachother, but their variables stay local to that object?

    Thats why one doesn't need to be careful with variable names, but im assuming with DAT you must be careful with names because if two objects have a Dat with the same name problems happen?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Meh. Nothing here, move along.
  • BradCBradC Posts: 2,601
    edited 2009-06-05 23:55
    BPM said...
    I get it now.

    If I ran 2 copys of the same object(different names), their DAT statements would be accessable to eachother, but their variables stay local to that object?

    Thats why one doesn't need to be careful with variable names, but im assuming with DAT you must be careful with names because if two objects have a Dat with the same name problems happen?

    No all symbol names (DAT/VAR/PUB/PRI) are local to the object. There are no collisions between names across different objects.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "VOOM"?!? Mate, this bird wouldn't "voom" if you put four million volts through it! 'E's bleedin' demised!
  • Clock LoopClock Loop Posts: 2,069
    edited 2009-06-06 21:53
    I have another question along the same lines.

    Lets say I launched an object to read a value and told it to store that value at the address of INFO.

    
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      modinfo: "modinfo"
      serial : "fullDuplexSerialPlus"
    
    PUB start
    
    modinfo.start(@info)
    
    serial.start(03, 02, 0, 57600)
    serial.hex(info[noparse][[/noparse]0],2)
    serial.str(string(9)) 'TAB
    serial.hex(info,2)
    serial.str(string(9)) 'TAB
    waitcnt(400_000 + cnt)  ' let serial finish printing before stopping.
    serial.stop
    
    DAT
    
    info                byte    $00, $FF
    
    
    
    
    






    Now the modinfo.spin code.

    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
    PUB start (infopointer) | moreinfo
    
    moreinfo := $FF
    
    infopointer[noparse][[/noparse]0]:= moreinfo   
    
    
    




    This part
    infopointer[noparse][[/noparse]0]:= moreinfo
    is not working.
    Or something.
    Because when i run the program, it still prints

    $00              $FF
    
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-06-06 22:40
    You're passing an address via infopointer. So instead of

    infopointer[noparse][[/noparse]0]:= moreinfo 
    
    
    


    use

    byte[noparse][[/noparse]infopointer] := moreinfo
    
    
    


    infopointer is just a local variable that receives the value @info. Changing a local variable by assigning to it has no effect outside the method to which it's local.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 6/6/2009 10:45:15 PM GMT
  • Clock LoopClock Loop Posts: 2,069
    edited 2009-06-06 22:44
    so not only do I have to tell it where, I have to tell it how much info to pass?

    well what if I wanted to pass the n'th byte?

    byte[noparse][[/noparse]infopointer [noparse][[/noparse]n] ] := moreinfo    '?
    
    



    Well this doesn't work, ...


    I just read the prop manual on

    BYTE

    That answered my questions.

    Thank you all.

    byte[noparse][[/noparse]infopointer][noparse][[/noparse]n] := moreinfo   
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ** P O O F **

    Post Edited (BPM) : 6/6/2009 11:17:48 PM GMT
  • mparkmpark Posts: 1,305
    edited 2009-06-06 23:43
    That manual is just chock full of useful information.
Sign In or Register to comment.