Fills up a complete byte-array in memory with a given 8-bit value (as std memset)
void cpct_memset (void* array, u8 value, u16 size);
(2B DE) array | Pointer to the first byte of the array to be filled up (starting point in memory) |
(1B A ) value | 8-bit value to be set |
(2B BC) size | Number of bytes to be set (>= 2) |
call cpct_memset_asm
Sets all the bytes of an array in memory to the same given value. This is the same operation as std memset, from the standard C library does. However, this function is much faster than std C memset, so it is recommended for your productions. The technique this function uses to be so faster is as follows:
1 | Sets up the first byte of the array to the value |
2 | Makes HL point to the first byte and DE to the second |
3 | BC has the total bytes to copy minus 1 (the first already set) |
4 | LDIR copies first byte into second, then second into third... |
This function works for array sizes from 2 to 65535 (it does not work for 0 or 1). However, it is recommended that you use it for values greater than 2. Depending on your code, using memset for values in the range [2-8] could underperform simple variable assignments.
AF, BC, DE, HL
C-binding | 14 bytes |
ASM-binding | 8 bytes |
Case | microSecs (us) | CPU Cycles | ------------------------------------------ Any | 28 + 6*S | 112 + 24*S | ------------------------------------------ Asm saving | -18 | -72 | ------------------------------------------
S = size (Number of total bytes to set)