memory pack question


Author Message
Volhout

Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6103
Posted: 10:04am 15 Jan 2025      

All,

This is a generic question about MEMORY PACK and MEMORY UNPACK.
These commands can be used to pack data into 64 bit integers (i.e. 8 bytes per integer).

What I am trying to achieve is packing text (ASCII data) for use in PIO FIFO's.
The FIFO's are 32 bit wide, and a DMA of integers will fill the PIO FIFO 32 bits at at time (2 FIFO locations per integer). But I need to fill the FIFO with text in a$.

I already experimented with peek(varaddr a$) as sourceaddr% and an array%() as destination. But I never seem to get the right mapping of text into the integer to match the FIFO. What I need is

MSByte                      LSbyte
0   0   0  a$:2  0   0   0  a$:1

I currently use a loop (slow) to transfer character for character into integers (1 char per integer), and then pack the integers in a new array (2 char per integer).

But the loop is slow (when the string is long). So I wonder if there is a way to avoid the loop, and use either a single MEMORY PACK, or 2 MEMORY PACK's ...

Any advise ?

Volhout
PicomiteVGA PETSCII ROBOTS

matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11842
Posted: 10:12am 15 Jan 2025      

s$="1234567890"
a%=Peek(varaddr s$)+1
Dim o%(4)
b%=Peek(varaddr o%())
Memory copy a%,b%,10,1,4
For i=0 To 4
Print Hex$(o%(i))
Next

Volhout

Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6103
Posted: 10:19am 15 Jan 2025      

Wauw

that is fast....
tested: it works...

Thanks a lot.
Can use this the other way around also.

Volhout
Edited 2025-01-15 20:46 by Volhout

thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4395
Posted: 02:29pm 15 Jan 2025      

That form of MEMORY COPY doesn't seem to be in the manual.

Would I be correct in assuming it is a byte copy and that the last two parameters are the optional source and destination increments (c.f. MEMORY COPY INTEGER and MEMORY COPY FLOAT).

Best wishes,

Tom

matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11842
Posted: 03:08pm 15 Jan 2025      

Yes, it's a manual omission. I've asked Geoff to update.

You could also do what Harm wants with an UNPACK from char to integer and then a pack from integer to word. Bit clunkier but works fine.

s$="1234567890"
a%=Peek(varaddr s$)+1
Dim o%(9),oo%(4)
Memory unpack a%,o%(),10,8
Memory pack o%(),oo%(),10,32
For i=0 To 4
Print Hex$(oo%(i))
Next

thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4395
Posted: 03:47pm 15 Jan 2025      

Thanks Peter, more stuff to go in MMB4L post v0.7.

Tom

javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 603
Posted: 04:41pm 15 Jan 2025      

To play music in MOD format, a MODBUFFER is used, which is located in the Pico flash, and each time a composition is loaded, this area of ​​​​flash memory is reflashed, which is not good for intensive listening to many compositions.
Is it possible to make it so that if there is a PSRAM, this MODBUFFER is located in it?

Volhout

Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6103
Posted: 04:54pm 15 Jan 2025      

Javavi,

A system is in place to only reprogram when changed.

Volhout

javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 603
Posted: 05:10pm 15 Jan 2025      

  Volhout said  A system is in place to only reprogram when changed.

Yes, but I wrote a music player and just listen to this music for hours and the compositions change one after another continuously.
And I'm already starting to worry about the state of Pico's flash memory!
That's why I'm saying that it wouldn't be bad to have this MODBUFFER in RAM in a configuration with PSRAM.
Edited 2025-01-16 03:12 by javavi

matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11842
Posted: 05:25pm 15 Jan 2025      

  Quote  To play music in MOD format, a MODBUFFER is used, which is located in the Pico flash, and each time a composition is loaded, this area of ​​​​flash memory is reflashed, which is not good for intensive listening to many compositions.
Is it possible to make it so that if there is a PSRAM, this MODBUFFER is located in it?


Wrong thread - but good idea