cpct_memcpy

Copies a bunch of bytes from one place in memory to other.

C Definition

void cpct_memcpy (void* to, const void* from, u16 size) __z88dk_callee;

Input Parameters (6 Bytes)

(2B DE) toPointer to the destination (first byte where bytes will be written)
(2B HL) fromPointer to the source (first byte from which bytes will be read)
(2B BC) sizeNumber of bytes to be set (>= 1)

Assembly call (Input parameters on registers)

call cpct_memcpy_asm
  • Note: you may prefer using Z80’s LDIR instead.

Parameter Restrictions

  • to, from can be any 16-bit values.  Just take into account that this function doest not do any kind of check, so you are responsible for where you copy bytes to.  If you accidentally copy bytes to an undesired location, unpredictable things may happen.
  • size could also be any 16-bit value and, again, you are responsible for giving the right size in bytes that you wanted to copy.  Again, giving an incorrect value for size can make this routine to overwrite memory places you did not meant to, causing unpredictable behaviour.

Details

Copies a size bytes from one location to other in memory.  This function is an specific implementation of standard C memcpy for Z80 machines, and it is fully compatible with the standard.

Destroyed Register values

AF, BC, DE, HL

Required memory

C-bindings8 bytes
ASM-bindings3 bytes

Time Measures

  Case     | microSecs (us) | CPU Cycles
-----------------------------------------
  Any      |    18 + 6S     |  72 + 24S
-----------------------------------------
Asm saving |      -16       |    -64
-----------------------------------------

S = size (Number of total bytes to set)

Copies a bunch of bytes from one place in memory to other.
unsigned int (u16 = unsigned 16-bits, 2 bytes)
Close