Shop OBEX P1 Docs P2 Docs Learn Events
How to copy a buffer in spin — Parallax Forums

How to copy a buffer in spin

soshimososhimo Posts: 215
edited 2010-07-15 21:07 in Propeller 1
I have a need to copy a buffer from a spin object. This buffer is in the VAR section of the object I'm consuming.

My first thought was something like this:
VAR 
   byte source[noparse][[/noparse]32]
   
PUB ReadBuffer
   ' do something with source buffer

PUB CopyBuffer(bufferAddress, sizeAddress) | size, dest, index
  size := long[noparse][[/noparse]size]

  ' what to do with dest here?
  'dest := long[noparse][[/noparse]bufferAddress]
  
  repeat index from 0 to size
     ' again, don't know how to set the destination buffer
     ' @dest := @source + index

     ' I think this is the right thing to do in order to increment my destination pointer
     dest := @dest + 1




The line @dest := @source + index doesn't compile, and I understand why. I guess my question is, is it possible to increment and address passed into a subroutine and how do I reference it as a destination?

TIA

Comments

  • soshimososhimo Posts: 215
    edited 2010-07-15 18:51
    NVM, figured it out.

    Here is the code that works:
    PUB CopyBuffer(bufferAddress, size) | dest, index
      dest := byte[noparse][[/noparse]bufferAddress]
      
      repeat Index from 0 to size - 1
         dest := @buf + index
         dest := byte[noparse][[/noparse]@dest + 1]
    
    



    Edited to fix the off by one error.

    Post Edited (soshimo) : 7/15/2010 7:11:09 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-07-15 19:54
    Are your sure you copied that code correctly? What you've posted doesn't do anything at all. To where are you supposed to be copying the buffer contents? Also, be sure to look at Spin's bytemove command. I could make your job a lot easier.

    -Phil
  • soshimososhimo Posts: 215
    edited 2010-07-15 21:07
    PUB CopyBuffer(bufferAddress, size)
       bytemove(bufferAddress, @src, size)
    
    
    



    I want to copy a buffer from an object. This pub will expose that functionality for me. I will call it like so:

    theobj.copybuffer(@dest, 32)
    
    



    I'm hoping that will do it for me.

    Thanks for the help.

    Post Edited (soshimo) : 7/15/2010 9:33:00 PM GMT
Sign In or Register to comment.