Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------------------------------------------------------*\
- Function:
- memset
- rawMemset
- Params:
- arr[], iAddress - Array or address to set to a value.
- iSize - Number of cells to fill.
- iValue - What to set the cells to.
- Return:
- -
- Notes:
- Based on code by Slice:
- http://forum.sa-mp.com/showthread.php?p=1606781#post1606781
- Modified to use binary flags instead of a loop.
- \*----------------------------------------------------------------------------*/
- stock memset(arr[], size = sizeof (arr), val = 0)
- {
- new
- addr;
- #emit LOAD.S.pri arr
- #emit STOR.S.pri addr
- rawMemset(addr, size, val);
- return 0;
- }
- stock rawMemset(iAddress, iSize, iValue)
- {
- // Convert the size from cells to bytes.
- iSize *= 4;
- // Loop until there are only little bits left to fill.
- while (iSize >= 4096)
- {
- // I have to do this because the FILL instruction doesn't accept a
- // dynamic number.
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 4096
- iSize -= 4096;
- iAddress += 4096;
- }
- if (iSize & 2048)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 2048
- iAddress += 2048;
- }
- if (iSize & 1024)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 1024
- iAddress += 1024;
- }
- if (iSize & 512)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 512
- iAddress += 512;
- }
- if (iSize & 256)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 256
- iAddress += 256;
- }
- if (iSize & 128)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 128
- iAddress += 128;
- }
- if (iSize & 64)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 64
- iAddress += 64;
- }
- if (iSize & 32)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 32
- iAddress += 32;
- }
- if (iSize & 16)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 16
- iAddress += 16;
- }
- if (iSize & 8)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 8
- iAddress += 8;
- }
- if (iSize & 4)
- {
- #emit LOAD.S.alt iAddress
- #emit LOAD.S.pri iValue
- #emit FILL 4
- iAddress += 4;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment