Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:46 27 Nov 2024 Privacy Policy
Jump to

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: Canada
Posts: 1109
Posted: 05:34pm 02 Dec 2023
Copy link to clipboard 
Print this post

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)
dim b%(7,31)
I would really like to
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 Kingdom
Posts: 9121
Posted: 06:07pm 02 Dec 2023
Copy link to clipboard 
Print this post

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: Canada
Posts: 1109
Posted: 06:37pm 02 Dec 2023
Copy link to clipboard 
Print this post

OK, pretty close. Still needs a loop, and some 'esoteric' numbers, but it appears to work:
Option default integer

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()
The output looks like what I would expect.
Visit Vegipete's *Mite Library for cool programs.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 06:44pm 02 Dec 2023
Copy link to clipboard 
Print this post

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


To reply to this topic, you need to log in.

© JAQ Software 2024