/*H********************************************************************** * FILENAME : intrinsics.h START DATE : 10 Sept 16 * * DESCRIPTION : * Intrinsic functions to be used with all targets and platforms of SC-CL. * * NOTES : * This file is part of SC-CL's include library. * * LICENSE : * * Copyright 2016 SC-CL * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither SC-CL nor its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * * Redistribution of this software in source or binary forms shall be free * of all charges or fees to the recipient of this software. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL SC-CL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * AUTHORS : * Rocko Tompkins * Nathan James *H*/ #pragma once #include "types.h" #include "constants.h" //Fix for intellisense nonsense #ifndef _MSC_VER /// Defines a function as an intrinsic for use in the compiler. #define __intrinsic __attribute((intrinsic(false))) /// Defines a function as an unsafe intrinsic for use in the compiler. #define __unsafeIntrinsic __attribute((intrinsic(true))) #else /// Computes the Jenkins one-at-a-time hash at compile time. /// String to be hashed. /// The Jenkins one-at-a-time hash key of the string. #define hashof(str) 0 /// Computes the Jenkins one-at-a-time hash at compile time. /// String to be hashed. /// The Jenkins one-at-a-time hash key of the string. #define joaat(str) 0 /// Defines a function as an intrinsic for use in the compiler. #define __intrinsic /// Defines a function as an unsafe intrinsic for use in the compiler. #define __unsafeIntrinsic #pragma warning( disable : 4391 ) #pragma warning( disable : 4392 ) #pragma warning( disable : 4244 ) #endif /// This macro with functional form returns the offset value in bytes of member in the data structure or union type type. /// A type in which member is a valid member designator. /// A member of type. /// A value of type unsigned int with the offset value of member in type. #define offsetof(type, member) ((uint)&(((type *)0)->member)) /// Computes the number of elements in a statically-allocated array /// The name of an array. /// The number of elements in the array, expressed as a unsigned int. #define countof(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) /// Computes the stack size of a type. /// The name of the type. /// The stack size of the type, expressed as a unsigned int. #define stacksizeof(x) ((sizeof(x) + 3) >> 2) #pragma region String //{ /// Sets the first num bytes of the block of memory pointed by ptr to the specified value. /// Pointer to the block of memory to fill. /// Value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value. /// Number of bytes to be set. /// extern __intrinsic void memset(void* ptr, byte value, unsigned int len); /// Copies the values of len bytes from the location pointed to by source directly to the memory block pointed to by destination. /// Pointer to the destination array where the content is to be copied. /// Pointer to the source of data to be copied. /// Number of bytes to copy. /// extern __intrinsic void memcpy(void* dest, const void* src, unsigned int len); /// Copies the string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point). /// Pointer to the destination array where the content is to be copied. /// String to be copied. /// The length of the dest buffer.This value must be an integer literal in the range of 1 - 255. /// extern __intrinsic void strcpy(char* dest, const char* src, const byte destBufferLen); /// /// Appends a copy of the source string to the destination string. /// The terminating null character in destination is overwritten by the first character of source, /// and a null-character is included at the end of the new string formed by the concatenation of both in destination. /// /// Pointer to the destination array, which should contain a string, and be large enough to contain the concatenated resulting string. /// String to be appended. This should not overlap destination. /// The length of the dest buffer.This value must be an integer literal in the range of 1 - 255. /// extern __intrinsic void stradd(char* dest, const char* src, const byte destBufferLen); /// /// Appends a integer to the destination string. /// The terminating null character in destination is overwritten by the first character of the integer conversion, /// and a null-character is included at the end of the new string formed by the concatenation of both in destination. /// /// Pointer to the destination array, which should contain a string, and be large enough to contain the concatenated resulting string. /// Integer to be appended. /// The length of the dest buffer.This value must be an integer literal in the range of 1 - 255. /// extern __intrinsic void straddi(char* dest, int value, const byte destBufferLen); /// Converts a integer to a string. /// Pointer to the destination array where the content is to be copied. /// Integer to be copied. /// The length of the dest buffer.This value must be an integer literal in the range of 1 - 255. /// extern __intrinsic void itos(char* dest, int value, const byte destBufferLen); /// Copies the null-terminated byte string pointed to by src, including the null terminator, to the character array whose first element is pointed to by dest. /// Pointer to the character array to write to. /// Pointer to the null-terminated byte string to copy from. /// extern __intrinsic void strcpy_s(char* dest, const char* src); /// Appends a copy of the null-terminated byte string pointed to by src to the end of the null-terminated byte string pointed to by dest. /// Pointer to the null-terminated byte string to append to. /// Pointer to the null-terminated byte string to copy from. /// extern __intrinsic void stradd_s(char* dest, const char* src); /// Appends a copy of the null-terminated byte string converted from value to the end of the null-terminated byte string pointed to by dest. /// Pointer to the null-terminated byte string to append to. /// Value to be converted to a null-terminated byte string then appended. /// extern __intrinsic void straddi_s(char* dest, int value); /// Copies the null-terminated byte string converted from value, including the null terminator, to the character array whose first element is pointed to by dest. /// Pointer to the character array to write to. /// Value to be converted to a null-terminated byte string then copied. /// extern __intrinsic void itos_s(char* dest, int value); /// Computes the Jenkins one-at-a-time hash. /// String to be hashed. /// The Jenkins one-at-a-time hash key of the string. extern __intrinsic int getHashKey(const char* str); #pragma endregion //} #pragma region Misc_Opcodes //{ /// Gets a variable's index by its name. /// The variable name to be found.This value must be an string literal. /// The var index. extern __intrinsic const uint __varIndex(const char* varName); #pragma endregion //} #pragma region Math/Conversions //{ /// Reinterprets a int to a float without type conversion. /// The integer value to be converted. /// The integer data now representing an float. extern __intrinsic float reinterpretIntToFloat(int intValue); /// Reinterprets a float to a int without type conversion. /// The floating-point value to be converted. /// The floating-point data now representing an int extern __intrinsic int reinterpretFloatToInt(float floatValue); /// Creates a vector3 with all values initialized as the floating-point value. /// The floating-point value to be set. /// A vector3 with all values set as the floating-point value extern __intrinsic vector3 toVector3(float value); /// Adds each value of the left vector3 to each value the right vector3. /// The left side of the operation. /// The right side of the operation. /// The addition result of the two vector3s. extern __intrinsic vector3 vector3Add(vector3 left, vector3 right); /// Substacts each value of the left vector3 from each value the right vector3. /// The left side of the operation. /// The right side of the operation. /// The subtraction result of the two vector3s. extern __intrinsic vector3 vector3Sub(vector3 left, vector3 right); /// Multiplies each value of the left vector3 by each value the right vector3. /// The left side of the operation. /// The right side of the operation. /// The multiplication result of the two vector3s. extern __intrinsic vector3 vector3Mult(vector3 left, vector3 right); /// Divides each value of the left vector3 by each value the right vector3. /// The left side of the operation. /// The right side of the operation. /// The division result of the two vector3s. extern __intrinsic vector3 vector3Div(vector3 left, vector3 right); /// Negates each value of the vector3. /// The vector to be negated. /// The negation result of the vector3. extern __intrinsic vector3 vector3Neg(vector3 vector); /// Calculates the dot product of two vector3s. /// The left side of the operation. /// The right side of the operation. /// The dot product of the two vector3s. extern __intrinsic float vector3Dot(vector3 left, vector3 right); /// Flattens the height value of the vector3 to 0. /// The vector to be flattened. /// The flatten result of the vector3. extern __intrinsic vector3 vector3Flatten(vector3 vector); /// Creates a vector2 with all values initialized as the floating-point value. /// The floating-point value to be set. /// A vector2 with all values set as the floating-point value extern __intrinsic vector2 toVector2(float value); /// Adds each value of the left vector2 to each value the right vector2. /// The left side of the operation. /// The right side of the operation. /// The addition result of the two vector2s. extern __intrinsic vector2 vector2Add(vector2 left, vector2 right); /// Substacts each value of the left vector2 from each value the right vector3. /// The left side of the operation. /// The right side of the operation. /// The subtraction result of the two vector2s. extern __intrinsic vector2 vector2Sub(vector2 left, vector2 right); /// Multiplies each value of the left vector2 by each value the right vector3. /// The left side of the operation. /// The right side of the operation. /// The multiplication result of the two vector2s. extern __intrinsic vector2 vector2Mult(vector2 left, vector2 right); /// Divides each value of the left vector2 by each value the right vector3. /// The left side of the operation. /// The right side of the operation. /// The division result of the two vector2s. extern __intrinsic vector2 vector2Div(vector2 left, vector2 right); /// Negates each value of the vector2. /// The vector to be negated. /// The negation result of the vector2. extern __intrinsic vector2 vector2Neg(vector2 vector); /// Calculates the dot product of two vector2s. /// The left side of the operation. /// The right side of the operation. /// The dot product of the two vector2s. extern __intrinsic float vector2Dot(vector2 left, vector2 right); /// Converts a vector2 to a vector3 with z initialized as 0. /// The vector2 to be converted. /// The vector2 as a vector3 with z initialized as 0. extern __intrinsic vector3 vector2ToVector3(vector2 vector); /// Converts a vector3 to a vector2 with z truncated. /// The vector3 to be converted. /// The vector3 as a vector2 with z truncated. extern __intrinsic vector2 vector3ToVector2(vector3 vector); /// Returns the floating-point remainder of numer/denom /// The Value of the quotient numerator. /// The Value of the quotient denominator.If denom is zero, the function may either return zero or cause a domain error /// The remainder of dividing the arguments. extern __intrinsic float fMod(float numer, float denom); /// Tests if the bit at a index of a value is set. /// The value of the integer to be tested. /// The bit index to be tested.This value must be an integer literal. /// The if the bit is set. extern __intrinsic bool bit_test(int value, const byte bitIndex); /// Sets the bit at a index at the address of a value. /// The address of the value. /// The bit index to be set.This value must be an integer literal. /// extern __intrinsic void bit_set(int* address, const byte bitIndex); /// Resets the bit at a index at the address of a value. /// The address of the value. /// The bit index to be reset.This value must be an integer literal. /// extern __intrinsic void bit_reset(int* address, const byte bitIndex); /// Flips the bit at a index at the address of a value. /// The address of the value. /// The bit index to be flipped.This value must be an integer literal. /// extern __intrinsic void bit_flip(int* address, const byte bitIndex); /// Gets the byte at an address in big endian. /// The address of the value you want to get. /// The the byte at an address in big endian. extern __intrinsic unsigned char getByte(void* addr); /// Sets the byte at an address. /// The address of the value you want to set. /// The value you want to set. extern __intrinsic void setByte(void* addr, unsigned char value); #pragma endregion //} #pragma region Variables //{ /// Sets a static variable at a specific index. /// The index of the static to set.This value must be an integer literal. /// The value to set the static. /// extern __intrinsic void setStaticAtIndex(const uint index, int value); /// Gets a static variable at a specific index. /// The index of the static to get.This value must be an integer literal. /// The static value. extern __intrinsic int getStaticAtIndex(const uint index); /// Gets the pointer to a static variable at a specific index. /// The index of the static to get.This value must be an integer literal. /// The pointer to the static. extern __intrinsic void* getStaticPtrAtIndex(const uint index); /// Sets a global variable at a specific index. /// The index of the global to set.This value must be an integer literal. /// The value to set the global. /// extern __intrinsic void setGlobalAtIndex(const uint index, int value); /// Gets a global variable at a specific index. /// The index of the global to get.This value must be an integer literal. /// The global value. extern __intrinsic int getGlobalAtIndex(const uint index); /// Gets the pointer to a global variable at a specific index. /// The index of the global to get.This value must be an integer literal. /// The pointer to the global. extern __intrinsic void* getGlobalPtrAtIndex(const uint index); /// Gets the pointer to a variable at a specific index in a array. /// The pointer to the array. /// The index of the array item. /// The array item size.This value must be an integer literal. /// The pointer to the array item. extern __intrinsic void* getPtrFromArrayIndex(const void* array, int index, const int arrayItemSize); /// Gets the pointer at a immediate index of a pointer. /// The starting pointer. /// The immediate index.This value must be an integer literal. /// The pointer + immIndex * 4. extern __intrinsic void* getPtrImmIndex(const void* pointer, const int immIndex); #pragma endregion //} #if PTRWIDTH == 64 #pragma region YSC_Specific //{ /// Sets the lower 32 bits of a value. /// The address of the value you want to set. /// The value to set. extern __intrinsic void setLoDWord(void* addr, int value); /// Sets the higher 32 bits of a value. /// The address of the value you want to set. /// The value to set. extern __intrinsic void setHiDWord(void* addr, int value); /// Gets the lower 32 bits of a value. /// The address of the value you want to get. /// The the lower 32 bits of the value. extern __intrinsic int getLoDWord(void* addr); /// Gets the higher 32 bits of a value. /// The address of the value you want to get. /// The the higher 32 bits of the value. extern __intrinsic int getHiDWord(void* addr); #pragma endregion //} #endif #pragma region Custom_ASM //{ /************************************************************************* * These perform the operation on the item(or vector) on top of the stack * This can lead to dangerous behaviour if you aren't sure what is currently on the stack *************************************************************************/ /// Pops multiple items off the stack. /// The amount of items to pop off.This value must be an integer literal. /// extern __unsafeIntrinsic void __popMult(const uint count); /// Pushes a vector3 on the stack. /// The vector3 to be pushed. /// extern __unsafeIntrinsic void __pushV(vector3 value); /// Pushes a struct on the stack. /// The struct to be pushed. /// extern __unsafeIntrinsic void __pushStruct(void* structure); /// Pops a struct off the stack. /// The struct to be poped. /// extern __unsafeIntrinsic void __popStruct(void* structure); /// Reverses items on the stack. /// The amount of items to be reversed.This value must be an integer literal. /// extern __unsafeIntrinsic void __rev(const int numItems); /// Exchanges two same sized structs on the stack. /// The size of the struct.This value must be an integer literal. /// extern __unsafeIntrinsic void __exch(const int structStackSize); /// Gets the top item on the stack as a int. /// The top item on the stack as a int. extern __unsafeIntrinsic int __popI(); /// Gets the top item on the stack as a float. /// The top item on the stack as a float. extern __unsafeIntrinsic float __popF(); /// Gets the top 3 items on the stack as a vector3. /// The top 3 items on the stack as a vector3. extern __unsafeIntrinsic vector3 __popV(); /// Pushes an amount of items from the specified pointer to the stack. /// The pointer to draw from. /// The amount of items to push to the stack. /// extern __unsafeIntrinsic void __ptrToStack(const void* address, int count); /// Pops an amount of items from the stack to the specified pointer. /// The pointer to place the items. /// The amount of items to pop from the stack. /// extern __unsafeIntrinsic void __ptrFromStack(const void* address, int count); #pragma endregion //} #pragma region ASM //{ /************************************************************************* * These perform an operation on the item(or vector) on top of the stack * This can lead to dangerous behaviour if you aren't sure what is currently on the stack *************************************************************************/ /// /// Adds specified amount of nops to the script in the interval [0,4096]. /// Note: GTAIV nops exit the script. /// /// The amount of nops to add.This value must be an integer literal. /// extern __intrinsic void __nop(const uint count); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) + Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __add(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) - Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __sub(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) * Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __mult(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) / Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __div(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) % Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __mod(); /// /// Pops one item off the stack. (signed int32) /// Performs {!Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __not(); /// /// Pops one item off the stack. (signed int32) /// Performs {-Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __neg(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) == Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpEq(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) != Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpNe(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) > Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpGt(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) >= Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpGe(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) < Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpLt(); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) <= Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpLe(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) + Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __addF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) - Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __subF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) * Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __multF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) / Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __divF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) % Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __modF(); /// /// Pops one item off the stack. (float) /// Performs {-Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __negF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) == Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpEqF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) != Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpNeF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) > Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpGtF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) >= Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpGeF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) < Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpLtF(); /// /// Pops two items off the stack. (float, float) /// Performs {(Stack.Top - 1) <= Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __cmpLeF(); /// /// Pops six items off the stack. (float, float, float, float, float, float) /// Performs {(Stack.Top - 5) + (Stack.Top - 2)} as a float. /// Performs {(Stack.Top - 4) + (Stack.Top - 1)} as a float. /// Performs {(Stack.Top - 3) + Stack.Top} as a float. /// Pushes three items on the stack. /// extern __unsafeIntrinsic void __addV(); /// /// Pops six items off the stack. (float, float, float, float, float, float) /// Performs {(Stack.Top - 5) - (Stack.Top - 2)} as a float. /// Performs {(Stack.Top - 4) - (Stack.Top - 1)} as a float. /// Performs {(Stack.Top - 3) - Stack.Top} as a float. /// Pushes three items on the stack. /// extern __unsafeIntrinsic void __subV(); /// /// Pops six items off the stack. (float, float, float, float, float, float) /// Performs {(Stack.Top - 5) * (Stack.Top - 2)} as a float. /// Performs {(Stack.Top - 4) * (Stack.Top - 1)} as a float. /// Performs {(Stack.Top - 3) * Stack.Top} as a float. /// Pushes three items on the stack. /// extern __unsafeIntrinsic void __multV(); /// /// Pops six items off the stack. (float, float, float, float, float, float) /// Performs {(Stack.Top - 5) / (Stack.Top - 2)} as a float. /// Performs {(Stack.Top - 4) / (Stack.Top - 1)} as a float. /// Performs {(Stack.Top - 3) / Stack.Top} as a float. /// Pushes three items on the stack. /// extern __unsafeIntrinsic void __divV(); /// /// Pops three items off the stack. (float, float, float) /// Performs {-(Stack.Top - 2)} as a float. /// Performs {-(Stack.Top - 1)} as a float. /// Performs {-Stack.Top} as a float. /// Pushes three items on the stack. /// extern __unsafeIntrinsic void __negV(); /// /// Pops two item off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) & Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __and(); /// /// Pops two item off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) | Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __or(); /// /// Pops two item off the stack. (signed int32, signed int32) /// Performs {(Stack.Top - 1) ^ Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __xor(); /// /// Pops one item off the stack. (signed int32) /// Performs {(float)Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __iToF(); /// /// Pops one item off the stack. (float) /// Performs {(int)Stack.Top} as a float. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __fToI(); /// /// Pops one item off the stack. (float) /// Pushes three items of value Stack.Top on the stack. /// extern __unsafeIntrinsic void __fToV(); /// Pushes two signed int32 values to the stack. /// The first value to push to the stack.This value must be an integer literal. /// The second value to push to the stack.This value must be an integer literal. extern __unsafeIntrinsic void __push2(const int value0, const int value1); /// Pushes three signed int32 values to the stack. /// The first value to push to the stack.This value must be an integer literal. /// The second value to push to the stack.This value must be an integer literal. /// The third value to push to the stack.This value must be an integer literal. extern __unsafeIntrinsic void __push3(const int value0, const int value1, const int value2); /// Pushes one signed int32 value to the stack. /// The value to push to the stack.This value must be an integer literal. extern __unsafeIntrinsic void __push(const int value); /// Pushes one float value to the stack. /// The value to push to the stack.This value must be an floating-point literal. extern __unsafeIntrinsic void __pushF(const float value); /// Pushes a duplicate of Stack.Top to the stack. extern __unsafeIntrinsic void __dup(); /// Pops one item off the stack and discards it. extern __unsafeIntrinsic void __drop(); /// /// Pops the amount of items off the stack that the function takes. /// Calls a native function. /// /// The hash relating to the native.This value must be an integer literal. /// The param count of the native.This value must be an integer literal. /// The return count of the native.This value must be an integer literal. extern __unsafeIntrinsic void __callNative(const uint nativeHash, const uint paramCount, const uint returnCount); /// /// Pops the amount of items off the stack that the function takes. /// Calls a native function. /// /// The upper 32 bits of the hash relating to the native.This value must be an integer literal. /// The lower 32 bits of the hash relating to the native.This value must be an integer literal. /// The param count of the native.This value must be an integer literal. /// The return count of the native.This value must be an integer literal. extern __unsafeIntrinsic void __callNativePc(const uint nativeHash64Part1, const uint nativeHash64Part2, const uint paramCount, const uint returnCount); /// Returns a function. /// The param count of the function.This value must be an integer literal. /// The return count of the function.This value must be an integer literal. extern __unsafeIntrinsic void __return(const uint paramCount, const uint returnCount); /// /// Pops one item off the stack. (void*) /// Performs {*Stack.Top} as a signed int32. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __pGet(); /// /// Pops two items off the stack. (signed int32, void*) /// Performs {*Stack.Top = (Stack.Top - 1)} as a signed int32. /// extern __unsafeIntrinsic void __pSet(); /// /// Pops two items off the stack. (void*, signed int32) /// Performs {*(Stack.Top - 1) = Stack.Top} as a signed int32. /// Pushes Stack.Top on the stack. /// extern __unsafeIntrinsic void __pPeekSet(); /// /// Pops two items off the stack. (signed int32, void*) /// Pushes items at the pointer Stack.Top for (Stack.Top - 1) on the stack. /// extern __unsafeIntrinsic void __toStack(); /// /// Pops two items off the stack. (signed int32, void*) /// Pops off items from the stack for (Stack.Top - 1) into the pointer Stack.Top. /// extern __unsafeIntrinsic void __fromStack(); /// /// Pops two items off the stack. (signed int32, void*) /// Performs {&Stack.Top[(Stack.Top - 1)]}.> /// /// The array item stack size.This value must be an integer literal. extern __unsafeIntrinsic void __getArrayP(const uint arraySize); /// /// Pops two items off the stack. (signed int32, void*) /// Performs {Stack.Top[(Stack.Top - 1)]}. /// Pushes one item on the stack. /// /// The array item stack size.This value must be an integer literal. extern __unsafeIntrinsic void __getArray(const uint arraySize); /// /// Pops two items off the stack. (signed int32, void*) /// Performs {&Stack.Top[(Stack.Top - 1)] = (Stack.Top - 2)}. /// /// The array item stack size.This value must be an integer literal. extern __unsafeIntrinsic void __setArray(const uint arraySize); /// /// Gets a local functon frame pointer by an index. /// Pushes the frame pointer on the stack. /// /// The index to get the frame at.This value must be an integer literal. extern __unsafeIntrinsic void __getFrameP(const uint frameIndex); /// /// Gets a local functon frame pointer by it's name. /// Pushes the frame pointer on the stack. /// /// The name of the local function frame.This value must be an string literal. extern __unsafeIntrinsic void __getNamedFrameP(const char* frameName); /// /// Gets a local functon frame by an index. /// Pushes the frame on the stack. /// /// The index to get the frame at.This value must be an integer literal. extern __unsafeIntrinsic void __getFrame(const uint frameIndex); /// /// Gets a local functon frame by it's name. /// Pushes the frame on the stack. /// /// The name of the local function frame.This value must be an string literal. extern __unsafeIntrinsic void __getNamedFrame(const char* frameName); /// /// Pops one item off the stack. (signed int32) /// Sets a local functon frame by an index. /// /// The index to set the frame at.This value must be an integer literal. extern __unsafeIntrinsic void __setFrame(const uint frameIndex); /// /// Pops one item off the stack. (signed int32) /// Sets a local functon frame by it's name. /// /// The name of the local function frame.This value must be an string literal. extern __unsafeIntrinsic void __setNamedFrame(const char* frameName); /// /// Gets a static var pointer by an index. /// Pushes the static var pointer on the stack. /// /// The index to get the static at.This value must be an integer literal. extern __unsafeIntrinsic void __getStaticP(const uint staticIndex); /// /// Gets a static var pointer by it's name. /// Pushes the static var pointer on the stack. /// /// The name of the static var.This value must be an string literal. extern __unsafeIntrinsic void __getNamedStaticP(const char* StaticName); /// /// Gets a static var by an index. /// Pushes the static var on the stack. /// /// The index to get the static at.This value must be an integer literal. extern __unsafeIntrinsic void __getStatic(const uint staticIndex); /// /// Gets a static var by it's name. /// Pushes the static var on the stack. /// /// The name of the static var.This value must be an string literal. extern __unsafeIntrinsic void __getNamedStatic(const char* StaticName); /// /// Pops one item off the stack. (signed int32) /// Sets a static var by an index. /// /// The index to set the static at.This value must be an integer literal. extern __unsafeIntrinsic void __setStatic(const uint staticIndex); /// /// Pops one item off the stack. (signed int32) /// Sets a static var by it's name. /// /// The name of the static var.This value must be an string literal. extern __unsafeIntrinsic void __setNamedStatic(const char* StaticName); /// /// Pops one item off the stack. (signed int32) /// Performs {Stack.Top + value} as a signed int32. /// Pushes one item on the stack. /// /// Right hand side of the math operation.This value must be an integer literal. extern __unsafeIntrinsic void __addImm(const uint value); /// /// Pops one item off the stack. (signed int32) /// Performs {Stack.Top * value} as a signed int32. /// Pushes one item on the stack. /// /// Right hand side of the math operation.This value must be an integer literal. extern __unsafeIntrinsic void __multImm(const uint value); /// /// Pops one item off the stack. (void*) /// Performs {Stack.Top + immediate * 4} as a signed int32. /// Pushes one item on the stack. /// /// The immediate value of a pointer.This value must be an integer literal. extern __unsafeIntrinsic void __getImmP(const uint immediate); /// /// Pops one item off the stack. (void*) /// Performs {*(Stack.Top + immediate * 4)} as a signed int32. /// Pushes one item on the stack. /// /// The immediate value of a pointer.This value must be an integer literal. extern __unsafeIntrinsic void __getImm(const uint immediate); /// /// Pops one item off the stack. (signed int32, void*) /// Performs {*(Stack.Top + immediate * 4) = (Stack.Top - 1)} as a signed int32. /// /// The immediate value of a pointer.This value must be an integer literal. extern __unsafeIntrinsic void __setImm(const uint immediate); /// /// Gets a global var pointer by an index. /// Pushes the global var pointer on the stack. /// /// The index to get the global at.This value must be an integer literal. extern __unsafeIntrinsic void __getGlobalP(const uint globalIndex); /// /// Gets a global var by an index. /// Pushes the global var on the stack. /// /// The index to get the global at.This value must be an integer literal. extern __unsafeIntrinsic void __getGlobal(const uint globalIndex); /// /// Pops one item off the stack. (signed int32) /// Sets a global var by an index. /// /// The index to set the global at.This value must be an integer literal. extern __unsafeIntrinsic void __setGlobal(const uint globalIndex); /// /// Pops one item off the stack. (signed int32) /// Switchs on Stack.Top to the case. /// This function must have a label for every case. /// /// The case of the switch.This value must be an integer literal. /// The label of the switch to jump to if Stack.Top == Case.This value must be an string literal. extern __unsafeIntrinsic void __switch(const int Case, const char* label, ...); /// /// Performs {goto label;}. /// /// The label to jump to.This value must be an string literal. extern __unsafeIntrinsic void __jump(const char* label); /// /// Pops one item off the stack. (signed int32) /// Performs {if(Stack.Top) goto label;}. /// /// The label to jump to.This value must be an string literal. extern __unsafeIntrinsic void __jumpFalse(const char* label); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {if((Stack.Top - 1) != Stack.Top) goto label;}. /// /// The label to jump to.This value must be an string literal. extern __unsafeIntrinsic void __jumpNE(const char* label); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {if((Stack.Top - 1) == Stack.Top) goto label;}. /// /// The label to jump to.This value must be an string literal. extern __unsafeIntrinsic void __jumpEQ(const char* label); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {if((Stack.Top - 1) <= Stack.Top) goto label;}. /// /// The label to jump to.This value must be an string literal. extern __unsafeIntrinsic void __jumpLE(const char* label); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {if((Stack.Top - 1) < Stack.Top) goto label;}. /// /// The label to jump to.This value must be an string literal. extern __unsafeIntrinsic void __jumpLT(const char* label); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {if((Stack.Top - 1) >= Stack.Top) goto label;}. /// /// The label to jump to.This value must be an string literal. extern __unsafeIntrinsic void __jumpGE(const char* label); /// /// Pops two items off the stack. (signed int32, signed int32) /// Performs {if((Stack.Top - 1) > Stack.Top) goto label;}. /// /// The label to jump to.This value must be an string literal. extern __unsafeIntrinsic void __jumpGT(const char* label); /// /// Pops the amount of items off the stack that the function takes. /// Calls a function. /// /// The name of the function to call.This value must be an string literal. extern __unsafeIntrinsic void __call(const char* functionName); /// Pushes one char* to the stack. /// The string that will be referenced by the pointer.This value must be an string literal. extern __unsafeIntrinsic void __pushString(const char* value); /// /// Pops one item off the stack. (char*) /// Performs {joaat(Stack.Top);}. /// Pushes one item on the stack. /// extern __unsafeIntrinsic void __getHash(); /// /// Pops two items off the stack. (char*, char*) /// Copies (Stack.Top - 1) into Stack.Top for strLen bytes or until a 0 was hit in (Stack.Top - 1). /// /// The length of the string destination buffer.This value must be an integer literal. extern __unsafeIntrinsic void __strCopy(const uint strLen); /// /// Pops two items off the stack. (signed int32, char*) /// Copies the string representation of (Stack.Top - 1) into Stack.Top for strLen bytes or until a 0 was hit in (Stack.Top - 1). /// /// The length of the string destination buffer.This value must be an integer literal. extern __unsafeIntrinsic void __iToS(const uint strLen); /// /// Pops two items off the stack. (char*, char*) /// Appends (Stack.Top - 1) into Stack.Top for strLen bytes or until a 0 was hit in (Stack.Top - 1). /// /// The length of the string destination buffer.This value must be an integer literal. extern __unsafeIntrinsic void __strAdd(const uint strLen); /// /// Pops two items off the stack. (signed int32, char*) /// appends the string representation of (Stack.Top - 1) into Stack.Top for strLen bytes or until a 0 was hit in (Stack.Top - 1). /// /// The length of the string destination buffer.This value must be an integer literal. extern __unsafeIntrinsic void __strAddI(const uint strLen); /// /// Pops three items off the stack. (signed int32, signed int32, void*) /// Pops off items from the stack for {(Stack.Top - 2) * (Stack.Top - 1) / 4} into the pointer Stack.Top. /// extern __unsafeIntrinsic void __memCopy(); /// /// Pops one item off the stack. (void*) then pops the amount of items off the stack that the function takes. /// Calls the function at the pointer Stack.Top. /// extern __unsafeIntrinsic void __pCall(); #pragma endregion //} #undef __intrinsic #undef __unsafeIntrinsic /// Creates a array with the first item as the size. /// The type of array to create. /// The name of the array to create. /// The size of the array to create. #define CreateSizedArray(type, name, sizein, ...)\ struct SizedArray\ {\ unsigned int size;\ type items[sizein];\ } name = {.size = sizein, .items = {__VA_ARGS__}} /// Gets the size of the sized array. /// The pointer to the sized array. #define GetSizedArraySize(sizedarr) (*(unsigned int*)sizedarr) /// Gets an item of the sized array. /// The pointer to the sized array. /// The type of the sized array. /// The index of the sized array item. #define GetSizedArrayItem(sizedarr, type, index) (*(type*)((int*)sizedarr + 1 + index)) /// Converts an array to a sized array. /// The pointer to the array. /// The pointer to the sized array. #define ArrayToSizedArray(arr, sizedarr)\ if(sizeof(arr) == sizeof(sizedarr.items))\ memcpy(sizedarr.items, arr, countof(arr)); /// Converts an sized array to a array. /// The pointer to the sized array. /// The pointer to the array. #define SizedArrayToArray(sizedarr, arr)\ if(sizeof(arr) == sizeof(sizedarr.items))\ memcpy(arr, sizedarr.items, countof(sizedarr.items));