Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:34 01 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 (& PicoMite ?): MEMORY COPY and overlapping regions

Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 08:55pm 30 Dec 2021
Copy link to clipboard 
Print this post

Peter,

What is the expected behaviour of MEMORY COPY (which is still not in the manual) for overlapping source and destination, or is it simply undefined as it is for the C memcpy() function ?

Best wishes,

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 10:52pm 30 Dec 2021
Copy link to clipboard 
Print this post

Same
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 10:08pm 03 Jan 2022
Copy link to clipboard 
Print this post

Hi Peter,

FYI according to the limited unit-test coverage I have written, MEMORY COPY on the CMM2 works correctly for overlapping regions where the destination address is less than the source address, but not where the destination address is greater in which case data already copied gets duplicated.

MMB4L alpha 3 will handle it "correctly", or at least according to the semantics of C's standard memmove().

If you were so inclined it should (microcontroller memory weirdness aside) be possible to do it "correctly" on the CMM2 too by comparing psrc and pdst and if pdst > psrc then copy the data in reverse order, i.e. from highest address to lowest address.

Best wishes,

Tom
Edited 2022-01-04 08:18 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 10:24pm 03 Jan 2022
Copy link to clipboard 
Print this post

On the ancient Nascom we had an intelligent memory copy - same thing really! It subtracted the source & destination values to decide whether  to start the copy at the beginning or end. That way you could safely copy a block over itself to move it. The Z80 was pretty good at shifting memory around.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
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