Shop OBEX P1 Docs P2 Docs Learn Events
Fun with pointers — Parallax Forums

Fun with pointers

RedNifreRedNifre Posts: 84
edited 2007-12-10 00:21 in Propeller 1
Hello!

I have several arrays and one pointer to the currently active array. Lets say I want to change the fourth LONG of the currently active array. How to do that?

  [noparse][[/noparse]...]
  arrayPointer := @array3

  ??arrayPointer??.LONG[noparse][[/noparse] 4 ] := 99


DAT
  array1 long blablabla
  array2 long blablabla
  array3 long blablabla
  array4 long blablabla


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hydra in a LEGO NES:
http://forums.parallax.com/showthread.php?p=654788

Comments

  • potatoheadpotatohead Posts: 10,260
    edited 2007-12-09 20:15
    I like to use this

    
    'Build Render Table
        repeat index from 0 to 189 * 4 step 4
          byte [noparse][[/noparse]@render_tab] [noparse][[/noparse]index] := 0           'set background color
          byte [noparse][[/noparse]@render_tab] [noparse][[/noparse]index + 1] := $20       'set sprite 0 x pos
          byte [noparse][[/noparse]@render_tab] [noparse][[/noparse]index + 2] := $40       'set sprite 1 x pos
          byte [noparse][[/noparse]@render_tab] [noparse][[/noparse]index + 3] := $00       'unused at present
    
    
    



    That's an array of longs, but I need to modify bytes. @render_tab is an array of bytes, organized into longs. index is the address pointer. It's some code I'm working on right now.

    In your case, since you are working with longs, you can just take the number of the long you want to modify, multiply it by 4, then do:

    long [noparse][[/noparse]@your_array] [noparse][[/noparse]index] := value of long

    , where index = number_of_long * 4

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-12-09 20:15
    Try LONG[noparse][[/noparse] arrayPointer][noparse][[/noparse] 4]:=99

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Help to build the Propeller wiki - propeller.wikispaces.com
    Play Defender - Propeller version of the classic game
    Prop Room Robotics - my web store for Roomba spare parts in the UK
  • RedNifreRedNifre Posts: 84
    edited 2007-12-09 21:22
    Ah, thanks alot!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hydra in a LEGO NES:
    http://forums.parallax.com/showthread.php?p=654788
  • AndreLAndreL Posts: 1,004
    edited 2007-12-10 00:21
    There are a lot of ways to manipulate memory with SPIN both the reference manual and the HYDRA book have examples. The HYDRA book has pretty long section on this since there are a lot of features that you can do with pointers and casting that I wanted to cover, so make sure to check that out if you have the book.

    Andre'
Sign In or Register to comment.