CopyMemory with modulo
CopyMemory with modulo
Hi,
does it exist any command like CopyMemory to do the same job but with a modulo for both source and target,only for target and, only for source ?
It's to make something similar to old Amiga blitter in the past for those that know about this.
does it exist any command like CopyMemory to do the same job but with a modulo for both source and target,only for target and, only for source ?
It's to make something similar to old Amiga blitter in the past for those that know about this.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
I don't completely understand, what you mean by "modulo for source/target"
do you mean something like copying the same 1024byte block repetively into 16K target?
or just modifying the adresses to creating a kind of map-display that switches at the end of a big source-area to the beginning of it within the same copy-loop?
I'm quite sure there will be a really performant solution if we know what you finally want to achieve...
do you mean something like copying the same 1024byte block repetively into 16K target?
or just modifying the adresses to creating a kind of map-display that switches at the end of a big source-area to the beginning of it within the same copy-loop?
I'm quite sure there will be a really performant solution if we know what you finally want to achieve...

oh... and have a nice day.
no.
In fact, imagine, I want from source :
-Read 16 bytes
-Donc read the X following.
-Read 16 bytes
-Donc read the X following.
-Read 16 bytes
-Donc read the X following.
XXX times ...
Target :
-Write 16 bytes
-Donc Write the Y following.
-Write 16 bytes
-Donc Write the Y following.
-Write 16 bytes
-Donc Write the Y following.
XXX times ...
X and Y are modulos.
Here is what I though
In fact, imagine, I want from source :
-Read 16 bytes
-Donc read the X following.
-Read 16 bytes
-Donc read the X following.
-Read 16 bytes
-Donc read the X following.
XXX times ...
Target :
-Write 16 bytes
-Donc Write the Y following.
-Write 16 bytes
-Donc Write the Y following.
-Write 16 bytes
-Donc Write the Y following.
XXX times ...
X and Y are modulos.
Here is what I though

- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
hm.. and where come the 16 in your example from?
so that would be Copy(Length, Skip1, Skip2),
for your example Length=16, Skip1=X, Skip2=Y
but that is not really "modulo", modulo would be "read L, skip X-L"
however, a function like that is easy to program yourself.
I think it is not implemented, because the use of this isn't too obvious...
...what is the use of it?
so that would be Copy(Length, Skip1, Skip2),
for your example Length=16, Skip1=X, Skip2=Y
but that is not really "modulo", modulo would be "read L, skip X-L"
however, a function like that is easy to program yourself.
I think it is not implemented, because the use of this isn't too obvious...
...what is the use of it?
oh... and have a nice day.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Like this ?
Code: Select all
; *Src = source
; *Dst = destination
; bpCycle = bytes to copy per cycle
; rSkip = read skip value
; wSkip = write skip value
; cycles = number of cycles
Procedure CopyMemoryM(*Src, *Dst, bpCycle, rSkip, wSkip, cycles)
; push registers used
!push ecx
!push esi
!push edi
!pushfd
; set direction for movsb
!cld
; retrieve some parameters
!mov esi,[esp + 20]
!mov edi,[esp + 24]
!mov ecx,[esp + 40]
; exit if bpCycle or cycles are 0
!mov eax,[esp + 28]
!and eax,ecx
!jz cmm_exit
; main loop
!cmm_loop1:
!mov eax,[esp + 28]
!cmm_loop2:
!movsb
!dec eax
!jnz cmm_loop2
!add esi,[esp + 32]
!add edi,[esp + 36]
!dec ecx
!jnz cmm_loop1
; pop registers used and exit
!cmm_exit:
!popfd
!pop edi
!pop esi
!pop ecx
EndProcedure
S.s = "This is a source string to see if the copy function works as it should"
D.s = " "
CopyMemoryM(@S, @D, 4, 1, 3, 6)
Debug D
Writing out the movsb instruction is a bit fasterbut requires a bit more code.
If you don't copy very much data you probably won't notice the difference.
I'm still wondering what practical use it has
Code: Select all
Procedure CopyMemoryM(*Src, *Dst, bpCycle, rSkip, wSkip, cycles)
; push registers used
!push ecx
!push edx
!push esi
!push edi
!pushfd
; retrieve some parameters
!mov esi,[esp + 24]
!mov edi,[esp + 28]
!mov ecx,[esp + 44]
; exit if bpCycle or cycles are 0
!mov edx,[esp + 32]
!and edx,ecx
!jz cmm_exit
; main loop
!cmm_loop1:
!mov edx,[esp + 32]
!cmm_loop2:
!mov al,[esi]
!mov [edi],al
!inc esi
!inc edi
!dec edx
!jnz cmm_loop2
!add esi,[esp + 36]
!add edi,[esp + 40]
!dec ecx
!jnz cmm_loop1
; pop registers used and exit
!cmm_exit:
!popfd
!pop edi
!pop esi
!pop edx
!pop ecx
EndProcedure
If you don't copy very much data you probably won't notice the difference.
I'm still wondering what practical use it has

-
- Enthusiast
- Posts: 767
- Joined: Sat Jan 24, 2004 6:56 pm
The code I posted before contained a bug. Here's a fixed version with two examples at the end of the code. I suppose the function can be useful for repetitive copy of data.
Code: Select all
; *Src = source
; *Dst = destination
; bpCycle = bytes to copy per cycle
; rSkip = read skip value
; wSkip = write skip value
; cycles = number of cycles
Procedure CopyMemoryM(*Src, *Dst, bpCycle, rSkip, wSkip, cycles)
; push registers used
!push ecx
!push edx
!push esi
!push edi
!pushfd
; retrieve some parameters
!mov ecx,[esp + 44]
!mov edx,[esp + 32]
!mov esi,[esp + 24]
!mov edi,[esp + 28]
; exit if bpCycle or cycles are 0
!and ecx,ecx
!jz cmm_exit
!and edx,edx
!jz cmm_exit
; main loop
!cmm_loop1:
!push edx
!cmm_loop2:
!mov al,[esi]
!mov [edi],al
!inc esi
!inc edi
!dec edx
!jnz cmm_loop2
!pop edx
!add esi,[esp + 36]
!add edi,[esp + 40]
!dec ecx
!jnz cmm_loop1
; pop registers used and exit
!cmm_exit:
!popfd
!pop edi
!pop esi
!pop edx
!pop ecx
EndProcedure
; filling a string with another one
S1.s = Space(50)
CopyMemoryM(@"12345", @S1, 5, -5, 0, 10)
Debug S1
; pairs of numbers
S2.s = Space(26)
CopyMemoryM(@"1234567890", @S2, 2, -1, 1, 9)
Debug S2