Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : PicoMite: Memory Pack/Unpack and 2D Arrays
Author | Message | ||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
Is there an efficient way to apply MEMORY PACK and UNPACK to 2 dimensional arrays? Or do I have to resort to a mess of MATH SLICE/INSERT commands in a loop to do this? Suppose I have dim a%(63,31) I would really like todim b%(7,31) MEMORY PACK a%(),b%(),64,8,,2 where the blank parameter indicates to pack along the first index.Thanks. Visit Vegipete's *Mite Library for cool programs. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9121 |
MEMORY PACK and UNPACK both support arrays or addresses as parameters. So you can PACK by address. Of course the packed array doesn't need to have the same number of dimensions dim a%(63,31) dim b%(8*32-1) MEMORY PACK peek(varaddr a%()),b%(),64*32,8 should work but untested |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
OK, pretty close. Still needs a loop, and some 'esoteric' numbers, but it appears to work: Option default integer The output looks like what I would expect.Dim a(15,7) Dim b(1,7) Math set 3,a() Print "Before" Print "Unpacked source:" Math m_print a() Print "Packed result:" Math m_print b() For i = 0 To 7 Memory pack Peek(varaddr a())+i*64,Peek(varaddr b())+i*16,16,8 Next i Print "After" Print "Unpacked source:" Math m_print a() Print "Packed result:" Math m_print b() Visit Vegipete's *Mite Library for cool programs. |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
Ooooo! Far simpler: replace the entire loop above with Memory pack Peek(varaddr a()),Peek(varaddr b()),128,8 Visit Vegipete's *Mite Library for cool programs. |
||||
Print this page |