Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:10 02 Aug 2025 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 : CMM2: arbitrary memory copy routine ?

Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 02:02pm 29 Oct 2020
Copy link to clipboard 
Print this post

Is there a command for arbitrarily copying bytes of memory around that I have missed, e.g.

BLIT MEM src_adr, dst_adr, num_bytes


If not then could it be added to the list of possibilities for 5.05.07, I don't think there are enough ways for us to crash the firmware

Seriously though it would be useful for more efficient string storage and implementation of some datastructure manipulations such as insertion into an array without having to resort to a CSUB.

Tom
Edited 2020-10-30 00:04 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 02:20pm 29 Oct 2020
Copy link to clipboard 
Print this post

Try

MEMORY COPY sourceaddress, destinationaddres, numberofbytes  

You can also try:

MEMORY SET address, byte, numberofbytes
MEMORY SET BYTE address, byte, numberofbytes
MEMORY SET SHORT address, short, numberofshorts '2 bytes per short
MEMORY SET WORD address, word, numberofwords '4 bytes per word
MEMORY SET INTEGER address, integer, numberofintegers '8bytes per integer
MEMORY SET FLOAT address, float, numberoffloats '8 bytes per float
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 02:27pm 29 Oct 2020
Copy link to clipboard 
Print this post

  matherp said  Try

MEMORY COPY sourceaddress, destinationaddres, numberofbytes

...


Wow, when did we get those      

Please note they do not appear to be in the manual accompanying the lastest firmware RC.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 203
Posted: 03:23pm 29 Oct 2020
Copy link to clipboard 
Print this post

I suspect Peter has many such tricks up his sleeve :-)  And documentation always lags :-(
Live in the Future. It's Just Starting Now!
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 01:35am 30 Oct 2020
Copy link to clipboard 
Print this post

Very nice!

Is this a CMM specific addition, or does it apply to lower grade devices as well (I have an Explore 100: PIC32MX470)?

Cheers,
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 03:23am 30 Oct 2020
Copy link to clipboard 
Print this post

  MustardMan said  Very nice!

Is this a CMM specific addition, or does it apply to lower grade devices as well (I have an Explore 100: PIC32MX470)?

Cheers,

Only CMM2 but some of the new functions will filter down to the other variants.

It is a useful addition to the MATHs functions.
As a test, I filled  a subset of elements in an array.
Useful for clearing part of an array or moving data arround quickly.

dim integer bigarray(20)
dim integer n, x, addr, startfill

x = 99
'find the starting address of the target array
addr = PEEK(VARADDR bigarray())

' set the starting point to the 5th array element
startfill = addr + 8*5

' fill 10 array elements starting at element 5
memory set integer startfill, x, 10

'show the results
for n = 0 to 20
print n,bigarray(n)
next n

Output:
0 0
1 0
2 0
3 0
4 0
5 99
6 99
7 99
8 99
9 99
10 99
11 99
12 99
13 99
14 99
15 0
16 0
17 0
18 0
19 0
20 0


Jim
VK7JH
MMedit
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 04:00pm 30 Oct 2020
Copy link to clipboard 
Print this post

New functionality in RC10 just posted

MEMORY SET INTEGER address, integervalue ,numberofintegers [,increment]
MEMORY SET FLOAT address, floatingvalue ,numberofloats [,increment]
MEMORY COPY INTEGER sourceaddress, destinationaddress, numberofintegers [,sourceincrement][,destinationincrement]
MEMORY COPY FLOAT sourceaddress, destinationaddress, numberoffloats [,sourceincrement][,destinationincrement]


Together these allow you to crash the system in more ways than you can imagine but more importantly they allow for very fast copies between single and multidimensional arrays i.e array slicing. In all cases the increments default to one unless specified.

option explicit
option default none
dim float sourcearray(3,39),destinationarray(39),d2array(39),x=99.99
dim integer n, addr, addr2, addr3


'find the starting address of the source 2 dimensional array
addr = PEEK(VARADDR sourcearray())

'find the starting address of the first desination 1 dimensional array
addr2 = PEEK(VARADDR destinationarray())

'find the starting address of the second desination 1 dimensional array
addr3 = PEEK(VARADDR d2array())

' fill 160 array elements starting at element 0,0
memory set float addr, x,160

'now make some changes to the source array to prove it all works
for n=0 to 39: sourcearray(2,n)=n:next n

'copy the sourcearray(0,all) to destinationarray
memory copy float addr, addr2,40,BOUND(sourcearray(),1)-BOUND(sourcearray(),0)+1,1

'now point to the start of the second dimension in the source array
addr = addr + 8*2

'copy the sourcearray(2,all) to destinationarray2
memory copy float addr, addr3,40,BOUND(sourcearray(),1)-BOUND(sourcearray(),0)+1,1

'show the results
for n = 0 to 39
 print n,sourcearray(0,n),sourcearray(2,n),destinationarray(n),d2array(n)
next n


For large arrays this will be massively faster than using Basic FOR loops
Edited 2020-10-31 03:07 by matherp
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 06:43pm 30 Oct 2020
Copy link to clipboard 
Print this post

Hi Peter!
  matherp said  ... in RC10 just posted

Where?

Regards
Michael
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 06:51pm 30 Oct 2020
Copy link to clipboard 
Print this post

  Quote  Where?


Usual place

http://geoffg.net/Downloads/Maximite/CMM2_Beta.zip
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 06:57pm 30 Oct 2020
Copy link to clipboard 
Print this post

  matherp said  
  Quote  Where?


Usual place


Contains CMM2V5.05.05RC9.bin
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 06:59pm 30 Oct 2020
Copy link to clipboard 
Print this post

  Quote  Contains CMM2V5.05.05RC9.bin


Try clearing your cache or similar and try again - works for me
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 07:07pm 30 Oct 2020
Copy link to clipboard 
Print this post

  matherp said  
  Quote  Contains CMM2V5.05.05RC9.bin


Try clearing your cache or similar and try again - works for me

I confirm.
causality ≠ correlation ≠ coincidence
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025