2005-07-25 06:03:43 +00:00
|
|
|
/* Pawn Abstract Machine (for the Pawn language)
|
2004-01-31 20:56:22 +00:00
|
|
|
*
|
2005-07-25 06:03:43 +00:00
|
|
|
* Copyright (c) ITB CompuPhase, 1997-2005
|
2004-01-31 20:56:22 +00:00
|
|
|
*
|
2004-02-03 09:24:30 +00:00
|
|
|
* This software is provided "as-is", without any express or implied warranty.
|
|
|
|
* In no event will the authors be held liable for any damages arising from
|
|
|
|
* the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
|
|
|
*
|
2004-03-27 16:58:13 +00:00
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software in
|
|
|
|
* a product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
2004-01-31 20:56:22 +00:00
|
|
|
*/
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#if defined FREEBSD && !defined __FreeBSD__
|
|
|
|
#define __FreeBSD__
|
|
|
|
#endif
|
2013-02-13 07:14:37 +00:00
|
|
|
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
|
2004-09-02 08:25:48 +00:00
|
|
|
#include <sclinux.h>
|
2004-01-31 20:56:22 +00:00
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
|
|
|
#ifndef AMX_H_INCLUDED
|
|
|
|
#define AMX_H_INCLUDED
|
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#if defined HAVE_STDINT_H
|
2004-03-27 16:58:13 +00:00
|
|
|
#include <stdint.h>
|
2005-07-25 06:03:43 +00:00
|
|
|
#else
|
2013-02-13 07:14:37 +00:00
|
|
|
#if defined __LCC__ || defined __DMC__ || defined LINUX || defined __APPLE__
|
2005-07-25 06:03:43 +00:00
|
|
|
#if defined HAVE_INTTYPES_H
|
|
|
|
#include <inttypes.h>
|
2004-01-31 20:56:22 +00:00
|
|
|
#else
|
2005-07-25 06:03:43 +00:00
|
|
|
#include <stdint.h>
|
2004-01-31 20:56:22 +00:00
|
|
|
#endif
|
2005-07-25 06:03:43 +00:00
|
|
|
#elif !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
|
|
|
|
/* The ISO C99 defines the int16_t and int_32t types. If the compiler got
|
|
|
|
* here, these types are probably undefined.
|
|
|
|
*/
|
|
|
|
#if defined __MACH__
|
|
|
|
#include <ppc/types.h>
|
|
|
|
typedef unsigned short int uint16_t;
|
|
|
|
typedef unsigned long int uint32_t;
|
|
|
|
#elif defined __FreeBSD__
|
|
|
|
#include <inttypes.h>
|
|
|
|
#else
|
|
|
|
typedef short int int16_t;
|
|
|
|
typedef unsigned short int uint16_t;
|
|
|
|
#if defined SN_TARGET_PS2
|
|
|
|
typedef int int32_t;
|
|
|
|
typedef unsigned int uint32_t;
|
|
|
|
#else
|
|
|
|
typedef long int int32_t;
|
|
|
|
typedef unsigned long int uint32_t;
|
|
|
|
#endif
|
|
|
|
#if defined __WIN32__ || defined _WIN32 || defined WIN32
|
|
|
|
typedef __int64 int64_t;
|
|
|
|
typedef unsigned __int64 uint64_t;
|
|
|
|
#define HAVE_I64
|
|
|
|
#elif defined __GNUC__
|
|
|
|
typedef long long int64_t;
|
|
|
|
typedef unsigned long long uint64_t;
|
|
|
|
#define HAVE_I64
|
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
#endif
|
2004-01-31 20:56:22 +00:00
|
|
|
#endif
|
2005-07-25 06:03:43 +00:00
|
|
|
#define HAVE_STDINT_H
|
|
|
|
#endif
|
|
|
|
#if defined _LP64 || defined WIN64 || defined _WIN64
|
|
|
|
#if !defined __64BIT__
|
|
|
|
#define __64BIT__
|
|
|
|
#endif
|
2004-01-31 20:56:22 +00:00
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#if !defined arraysize
|
|
|
|
#define arraysize(array) (sizeof(array) / sizeof((array)[0]))
|
|
|
|
#endif
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#if defined PAWN_DLL
|
|
|
|
#if !defined AMX_NATIVE_CALL
|
|
|
|
#define AMX_NATIVE_CALL __stdcall
|
|
|
|
#endif
|
|
|
|
#if !defined AMXAPI
|
|
|
|
#define AMXAPI __stdcall
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
/* calling convention for native functions */
|
|
|
|
#if !defined AMX_NATIVE_CALL
|
|
|
|
#define AMX_NATIVE_CALL
|
|
|
|
#endif
|
|
|
|
/* calling convention for all interface functions and callback functions */
|
|
|
|
#if !defined AMXAPI
|
2004-02-03 09:24:30 +00:00
|
|
|
#if defined STDECL
|
|
|
|
#define AMXAPI __stdcall
|
|
|
|
#elif defined CDECL
|
|
|
|
#define AMXAPI __cdecl
|
2005-07-25 06:03:43 +00:00
|
|
|
#elif defined GCC_HASCLASSVISIBILITY
|
|
|
|
#define AMXAPI __attribute__ ((visibility("default")))
|
2004-02-03 09:24:30 +00:00
|
|
|
#else
|
|
|
|
#define AMXAPI
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if !defined AMXEXPORT
|
|
|
|
#define AMXEXPORT
|
2004-01-31 20:56:22 +00:00
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
/* File format version Required AMX version
|
|
|
|
* 0 (original version) 0
|
|
|
|
* 1 (opcodes JUMP.pri, SWITCH and CASETBL) 1
|
|
|
|
* 2 (compressed files) 2
|
|
|
|
* 3 (public variables) 2
|
|
|
|
* 4 (opcodes SWAP.pri/alt and PUSHADDR) 4
|
|
|
|
* 5 (tagnames table) 4
|
|
|
|
* 6 (reformatted header) 6
|
2004-02-03 09:24:30 +00:00
|
|
|
* 7 (name table, opcodes SYMTAG & SYSREQ.D) 7
|
2005-07-25 06:03:43 +00:00
|
|
|
* 8 (opcode STMT, renewed debug interface) 8
|
2004-01-31 20:56:22 +00:00
|
|
|
*/
|
2005-07-25 06:03:43 +00:00
|
|
|
#define CUR_FILE_VERSION 8 /* current file version; also the current AMX version */
|
2004-02-03 09:24:30 +00:00
|
|
|
#define MIN_FILE_VERSION 6 /* lowest supported file format version for the current AMX version */
|
2005-07-25 06:03:43 +00:00
|
|
|
#define MIN_AMX_VERSION 8 /* minimum AMX version needed to support the current file format */
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#if !defined PAWN_CELL_SIZE
|
|
|
|
#define PAWN_CELL_SIZE 32 /* by default, use 32-bit cells */
|
2004-01-31 20:56:22 +00:00
|
|
|
#endif
|
2005-07-25 06:03:43 +00:00
|
|
|
#if PAWN_CELL_SIZE==16
|
2004-03-27 16:58:13 +00:00
|
|
|
typedef uint16_t ucell;
|
|
|
|
typedef int16_t cell;
|
2005-07-25 06:03:43 +00:00
|
|
|
#elif PAWN_CELL_SIZE==32
|
2004-03-27 16:58:13 +00:00
|
|
|
typedef uint32_t ucell;
|
|
|
|
typedef int32_t cell;
|
2005-07-25 06:48:54 +00:00
|
|
|
#define REAL float
|
2005-07-25 06:03:43 +00:00
|
|
|
#elif PAWN_CELL_SIZE==64
|
2004-03-27 16:58:13 +00:00
|
|
|
typedef uint64_t ucell;
|
|
|
|
typedef int64_t cell;
|
2005-07-25 06:48:54 +00:00
|
|
|
#define REAL double
|
2004-03-27 16:58:13 +00:00
|
|
|
#else
|
2005-07-25 06:03:43 +00:00
|
|
|
#error Unsupported cell size (PAWN_CELL_SIZE)
|
2004-03-27 16:58:13 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#define UNPACKEDMAX ((1L << (sizeof(cell)-1)*8) - 1)
|
|
|
|
#define UNLIMITED (~1u >> 1)
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-02-03 09:24:30 +00:00
|
|
|
struct tagAMX;
|
|
|
|
typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct tagAMX *amx, cell *params);
|
|
|
|
typedef int (AMXAPI *AMX_CALLBACK)(struct tagAMX *amx, cell index,
|
2004-01-31 20:56:22 +00:00
|
|
|
cell *result, cell *params);
|
2004-02-03 09:24:30 +00:00
|
|
|
typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
|
2005-09-11 03:58:38 +00:00
|
|
|
typedef int (AMXAPI *AMX_NATIVE_FILTER)(struct tagAMX *amx, int index);
|
2004-02-03 09:24:30 +00:00
|
|
|
#if !defined _FAR
|
|
|
|
#define _FAR
|
2004-01-31 20:56:22 +00:00
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
#if defined _MSC_VER
|
|
|
|
#pragma warning(disable:4103) /* disable warning message 4103 that complains
|
|
|
|
* about pragma pack in a header file */
|
2004-02-03 09:24:30 +00:00
|
|
|
#pragma warning(disable:4100) /* "'%$S' : unreferenced formal parameter" */
|
2006-04-06 12:56:45 +00:00
|
|
|
|
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
// MSVC8 - Replace POSIX stricmp with ISO C++ conformant one as it is deprecated
|
|
|
|
#define stricmp _stricmp
|
|
|
|
|
|
|
|
// Need this because of some stupid bug
|
|
|
|
#pragma warning (disable : 4996)
|
|
|
|
#endif
|
2004-02-03 09:24:30 +00:00
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-02-03 09:24:30 +00:00
|
|
|
/* Some compilers do not support the #pragma align, which should be fine. Some
|
|
|
|
* compilers give a warning on unknown #pragmas, which is not so fine...
|
|
|
|
*/
|
2005-07-25 06:03:43 +00:00
|
|
|
#if (defined SN_TARGET_PS2 || defined __GNUC__) && !defined AMX_NO_ALIGN
|
2004-02-03 09:24:30 +00:00
|
|
|
#define AMX_NO_ALIGN
|
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-02-03 09:24:30 +00:00
|
|
|
#if defined __GNUC__
|
|
|
|
#define PACKED __attribute__((packed))
|
|
|
|
#else
|
|
|
|
#define PACKED
|
2004-01-31 20:56:22 +00:00
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
#if !defined AMX_NO_ALIGN
|
2013-02-13 07:14:37 +00:00
|
|
|
#if defined LINUX || defined __FreeBSD__ || defined __APPLE__
|
2004-01-31 20:56:22 +00:00
|
|
|
#pragma pack(1) /* structures must be packed (byte-aligned) */
|
2005-07-25 06:03:43 +00:00
|
|
|
#elif defined MACOS && defined __MWERKS__
|
|
|
|
#pragma options align=mac68k
|
2004-01-31 20:56:22 +00:00
|
|
|
#else
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1) /* structures must be packed (byte-aligned) */
|
|
|
|
#if defined __TURBOC__
|
|
|
|
#pragma option -a- /* "pack" pragma for older Borland compilers */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
typedef struct tagAMX_NATIVE_INFO {
|
2004-03-27 16:58:13 +00:00
|
|
|
const char _FAR *name PACKED;
|
2004-02-03 09:24:30 +00:00
|
|
|
AMX_NATIVE func PACKED;
|
2005-07-25 06:03:43 +00:00
|
|
|
} PACKED AMX_NATIVE_INFO;
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
#define AMX_USERNUM 4
|
2004-02-03 09:24:30 +00:00
|
|
|
#define sEXPMAX 19 /* maximum name length for file version <= 6 */
|
2014-03-24 00:04:17 +00:00
|
|
|
#define sNAMEMAX 63 /* maximum name length of symbol name */
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-02-03 09:24:30 +00:00
|
|
|
typedef struct tagAMX_FUNCSTUB {
|
2005-07-25 06:03:43 +00:00
|
|
|
ucell address PACKED;
|
2006-08-27 02:17:18 +00:00
|
|
|
char name[sEXPMAX+1];
|
2005-07-25 06:03:43 +00:00
|
|
|
} PACKED AMX_FUNCSTUB;
|
|
|
|
|
|
|
|
typedef struct tagFUNCSTUBNT {
|
|
|
|
ucell address PACKED;
|
|
|
|
ucell nameofs PACKED; //we need this for amxx to be backwards comaptible
|
|
|
|
} PACKED AMX_FUNCSTUBNT;
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
/* The AMX structure is the internal structure for many functions. Not all
|
|
|
|
* fields are valid at all times; many fields are cached in local variables.
|
|
|
|
*/
|
2004-02-03 09:24:30 +00:00
|
|
|
typedef struct tagAMX {
|
2005-07-25 06:03:43 +00:00
|
|
|
unsigned char _FAR *base PACKED; /* points to the AMX header plus the code, optionally also the data */
|
2004-02-03 09:24:30 +00:00
|
|
|
unsigned char _FAR *data PACKED; /* points to separate data+stack+heap, may be NULL */
|
|
|
|
AMX_CALLBACK callback PACKED;
|
|
|
|
AMX_DEBUG debug PACKED; /* debug callback */
|
2004-01-31 20:56:22 +00:00
|
|
|
/* for external functions a few registers must be accessible from the outside */
|
2004-02-03 09:24:30 +00:00
|
|
|
cell cip PACKED; /* instruction pointer: relative to base + amxhdr->cod */
|
|
|
|
cell frm PACKED; /* stack frame base: relative to base + amxhdr->dat */
|
|
|
|
cell hea PACKED; /* top of the heap: relative to base + amxhdr->dat */
|
|
|
|
cell hlw PACKED; /* bottom of the heap: relative to base + amxhdr->dat */
|
|
|
|
cell stk PACKED; /* stack pointer: relative to base + amxhdr->dat */
|
|
|
|
cell stp PACKED; /* top of the stack: relative to base + amxhdr->dat */
|
|
|
|
int flags PACKED; /* current status, see amx_Flags() */
|
2004-01-31 20:56:22 +00:00
|
|
|
/* user data */
|
2006-02-10 15:43:27 +00:00
|
|
|
void _FAR *usertags[AMX_USERNUM] PACKED;
|
2005-07-25 06:48:54 +00:00
|
|
|
//okay userdata[3] in AMX Mod X is for the CPlugin * pointer
|
|
|
|
//we're also gonna set userdata[2] to a special debug structure
|
2005-09-09 03:23:31 +00:00
|
|
|
//lastly, userdata[1] is for opcode_list from amx_BrowseRelocate
|
2004-02-03 09:24:30 +00:00
|
|
|
void _FAR *userdata[AMX_USERNUM] PACKED;
|
2004-01-31 20:56:22 +00:00
|
|
|
/* native functions can raise an error */
|
2004-02-03 09:24:30 +00:00
|
|
|
int error PACKED;
|
2005-07-25 06:03:43 +00:00
|
|
|
/* passing parameters requires a "count" field */
|
|
|
|
int paramcount;
|
2004-01-31 20:56:22 +00:00
|
|
|
/* the sleep opcode needs to store the full AMX status */
|
2004-02-03 09:24:30 +00:00
|
|
|
cell pri PACKED;
|
|
|
|
cell alt PACKED;
|
|
|
|
cell reset_stk PACKED;
|
|
|
|
cell reset_hea PACKED;
|
2004-03-27 16:58:13 +00:00
|
|
|
cell sysreq_d PACKED; /* relocated address/value for the SYSREQ.D opcode */
|
2005-07-25 06:03:43 +00:00
|
|
|
/* support variables for the JIT */
|
2004-09-03 06:53:00 +00:00
|
|
|
int reloc_size PACKED; /* required temporary buffer for relocations */
|
|
|
|
long code_size PACKED; /* estimated memory footprint of the native code */
|
2005-07-25 06:03:43 +00:00
|
|
|
} PACKED AMX;
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
/* The AMX_HEADER structure is both the memory format as the file format. The
|
|
|
|
* structure is used internaly.
|
|
|
|
*/
|
2004-02-03 09:24:30 +00:00
|
|
|
typedef struct tagAMX_HEADER {
|
|
|
|
int32_t size PACKED; /* size of the "file" */
|
|
|
|
uint16_t magic PACKED; /* signature */
|
2006-08-27 02:17:18 +00:00
|
|
|
char file_version; /* file format version */
|
|
|
|
char amx_version; /* required version of the AMX */
|
2004-02-03 09:24:30 +00:00
|
|
|
int16_t flags PACKED;
|
|
|
|
int16_t defsize PACKED; /* size of a definition record */
|
|
|
|
int32_t cod PACKED; /* initial value of COD - code block */
|
|
|
|
int32_t dat PACKED; /* initial value of DAT - data block */
|
|
|
|
int32_t hea PACKED; /* initial value of HEA - start of the heap */
|
|
|
|
int32_t stp PACKED; /* initial value of STP - stack top */
|
|
|
|
int32_t cip PACKED; /* initial value of CIP - the instruction pointer */
|
|
|
|
int32_t publics PACKED; /* offset to the "public functions" table */
|
|
|
|
int32_t natives PACKED; /* offset to the "native functions" table */
|
|
|
|
int32_t libraries PACKED; /* offset to the table of libraries */
|
|
|
|
int32_t pubvars PACKED; /* the "public variables" table */
|
|
|
|
int32_t tags PACKED; /* the "public tagnames" table */
|
2005-07-25 06:03:43 +00:00
|
|
|
int32_t nametable PACKED; /* name table */
|
|
|
|
} PACKED AMX_HEADER;
|
|
|
|
|
|
|
|
//This is always the same for us
|
|
|
|
#define AMX_MAGIC 0xf1e0
|
2004-09-15 04:18:35 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
enum {
|
|
|
|
AMX_ERR_NONE,
|
|
|
|
/* reserve the first 15 error codes for exit codes of the abstract machine */
|
|
|
|
AMX_ERR_EXIT, /* forced exit */
|
|
|
|
AMX_ERR_ASSERT, /* assertion failed */
|
|
|
|
AMX_ERR_STACKERR, /* stack/heap collision */
|
|
|
|
AMX_ERR_BOUNDS, /* index out of bounds */
|
|
|
|
AMX_ERR_MEMACCESS, /* invalid memory access */
|
|
|
|
AMX_ERR_INVINSTR, /* invalid instruction */
|
|
|
|
AMX_ERR_STACKLOW, /* stack underflow */
|
|
|
|
AMX_ERR_HEAPLOW, /* heap underflow */
|
|
|
|
AMX_ERR_CALLBACK, /* no callback, or invalid callback */
|
|
|
|
AMX_ERR_NATIVE, /* native function failed */
|
|
|
|
AMX_ERR_DIVIDE, /* divide by zero */
|
|
|
|
AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */
|
2005-07-25 06:03:43 +00:00
|
|
|
AMX_ERR_INVSTATE, /* invalid state for this access */
|
2005-09-11 03:58:38 +00:00
|
|
|
AMX_ERR_INVNATIVE, /* invalid native was used */
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
AMX_ERR_MEMORY = 16, /* out of memory */
|
|
|
|
AMX_ERR_FORMAT, /* invalid file format */
|
|
|
|
AMX_ERR_VERSION, /* file is for a newer version of the AMX */
|
|
|
|
AMX_ERR_NOTFOUND, /* function not found */
|
|
|
|
AMX_ERR_INDEX, /* invalid index parameter (bad entry point) */
|
|
|
|
AMX_ERR_DEBUG, /* debugger cannot run */
|
|
|
|
AMX_ERR_INIT, /* AMX not initialized (or doubly initialized) */
|
|
|
|
AMX_ERR_USERDATA, /* unable to set user data field (table full) */
|
|
|
|
AMX_ERR_INIT_JIT, /* cannot initialize the JIT */
|
|
|
|
AMX_ERR_PARAMS, /* parameter error */
|
2004-02-03 09:24:30 +00:00
|
|
|
AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */
|
2005-07-25 06:03:43 +00:00
|
|
|
AMX_ERR_GENERAL, /* general error (unknown or unspecific error) */
|
2004-01-31 20:56:22 +00:00
|
|
|
};
|
2004-03-27 16:58:13 +00:00
|
|
|
|
|
|
|
/* AMX_FLAG_CHAR16 0x01 no longer used */
|
2004-01-31 20:56:22 +00:00
|
|
|
#define AMX_FLAG_DEBUG 0x02 /* symbolic info. available */
|
|
|
|
#define AMX_FLAG_COMPACT 0x04 /* compact encoding */
|
2005-07-25 06:03:43 +00:00
|
|
|
#define AMX_FLAG_BYTEOPC 0x08 /* opcode is a byte (not a cell) */
|
|
|
|
#define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking; no STMT opcode */
|
2014-06-05 20:00:47 +00:00
|
|
|
/* AMX_FLAG_OLDFILE 0x20 Old AMX Mod plugin */
|
2005-07-31 20:11:58 +00:00
|
|
|
#define AMX_FLAG_PRENIT 0x100 /* pre-initialized, do not check natives */
|
2005-07-25 06:03:43 +00:00
|
|
|
#define AMX_FLAG_NTVREG 0x1000 /* all native functions are registered */
|
|
|
|
#define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */
|
|
|
|
#define AMX_FLAG_BROWSE 0x4000 /* busy browsing */
|
2004-01-31 20:56:22 +00:00
|
|
|
#define AMX_FLAG_RELOC 0x8000 /* jump/call addresses relocated */
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
#define AMX_EXEC_MAIN -1 /* start at program entry point */
|
|
|
|
#define AMX_EXEC_CONT -2 /* continue from last address */
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
#define AMX_USERTAG(a,b,c,d) ((a) | ((b)<<8) | ((long)(c)<<16) | ((long)(d)<<24))
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#if !defined AMX_COMPACTMARGIN
|
|
|
|
#define AMX_COMPACTMARGIN 64
|
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2005-09-09 03:23:31 +00:00
|
|
|
#define UD_FINDPLUGIN 3
|
|
|
|
#define UD_DEBUGGER 2
|
|
|
|
#define UD_OPCODELIST 1
|
2005-09-09 16:04:44 +00:00
|
|
|
#define UD_HANDLER 0
|
2005-09-11 03:58:38 +00:00
|
|
|
#define UT_NATIVE 3
|
2006-02-10 15:43:27 +00:00
|
|
|
#define UT_OPTIMIZER 2
|
|
|
|
#define UT_BROWSEHOOK 1
|
2006-03-16 06:36:01 +00:00
|
|
|
#define UT_BINLOGS 0
|
2006-02-10 15:43:27 +00:00
|
|
|
|
|
|
|
typedef void (*BROWSEHOOK)(AMX *amx, cell *oplist, cell *cip);
|
2005-07-25 06:48:54 +00:00
|
|
|
|
2004-02-03 09:24:30 +00:00
|
|
|
/* for native functions that use floating point parameters, the following
|
|
|
|
* two macros are convenient for casting a "cell" into a "float" type _without_
|
|
|
|
* changing the bit pattern
|
|
|
|
*/
|
2005-07-25 06:03:43 +00:00
|
|
|
#if PAWN_CELL_SIZE==32
|
2004-03-27 16:58:13 +00:00
|
|
|
#define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */
|
|
|
|
#define amx_ctof(c) ( * ((float*)&c) ) /* cell to float */
|
2005-07-25 06:03:43 +00:00
|
|
|
#elif PAWN_CELL_SIZE==64
|
2004-03-27 16:58:13 +00:00
|
|
|
#define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */
|
|
|
|
#define amx_ctof(c) ( * ((double*)&c) ) /* cell to float */
|
|
|
|
#else
|
|
|
|
#error Unsupported cell size
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define amx_StrParam(amx,param,result) \
|
|
|
|
do { \
|
|
|
|
cell *amx_cstr_; int amx_length_; \
|
|
|
|
amx_GetAddr((amx), (param), &amx_cstr_); \
|
|
|
|
amx_StrLen(amx_cstr_, &amx_length_); \
|
|
|
|
if (amx_length_ > 0 && \
|
|
|
|
((result) = (void*)alloca((amx_length_ + 1) * sizeof(*(result)))) != NULL) \
|
2005-07-25 06:03:43 +00:00
|
|
|
amx_GetString((char*)(result), amx_cstr_, sizeof(*(result))>1, amx_length_); \
|
2004-03-27 16:58:13 +00:00
|
|
|
else (result) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
uint16_t * AMXAPI amx_Align16(uint16_t *v);
|
|
|
|
uint32_t * AMXAPI amx_Align32(uint32_t *v);
|
2004-03-27 16:58:13 +00:00
|
|
|
#if defined _I64_MAX || defined HAVE_I64
|
|
|
|
uint64_t * AMXAPI amx_Align64(uint64_t *v);
|
|
|
|
#endif
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr);
|
|
|
|
int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params);
|
2005-09-11 03:58:38 +00:00
|
|
|
int AMXAPI amx_CheckNatives(AMX *amx, AMX_NATIVE_FILTER nf);
|
2004-02-03 09:24:30 +00:00
|
|
|
int AMXAPI amx_Cleanup(AMX *amx);
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data);
|
2005-07-25 06:03:43 +00:00
|
|
|
int AMXAPI amx_Exec(AMX *amx, cell *retval, int index);
|
2004-03-27 16:58:13 +00:00
|
|
|
int AMXAPI amx_FindNative(AMX *amx, const char *name, int *index);
|
|
|
|
int AMXAPI amx_FindPublic(AMX *amx, const char *funcname, int *index);
|
|
|
|
int AMXAPI amx_FindPubVar(AMX *amx, const char *varname, cell *amx_addr);
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname);
|
|
|
|
int AMXAPI amx_Flags(AMX *amx,uint16_t *flags);
|
|
|
|
int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr);
|
2004-02-03 09:24:30 +00:00
|
|
|
int AMXAPI amx_GetNative(AMX *amx, int index, char *funcname);
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname);
|
|
|
|
int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr);
|
2005-07-25 06:03:43 +00:00
|
|
|
int AMXAPI amx_GetString(char *dest,const cell *source, int use_wchar, size_t size);
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id);
|
|
|
|
int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr);
|
|
|
|
int AMXAPI amx_Init(AMX *amx, void *program);
|
|
|
|
int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code);
|
|
|
|
int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap);
|
|
|
|
int AMXAPI amx_NameLength(AMX *amx, int *length);
|
2005-07-25 06:03:43 +00:00
|
|
|
AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(const char *name, AMX_NATIVE func);
|
2004-02-03 09:24:30 +00:00
|
|
|
int AMXAPI amx_NumNatives(AMX *amx, int *number);
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_NumPublics(AMX *amx, int *number);
|
|
|
|
int AMXAPI amx_NumPubVars(AMX *amx, int *number);
|
|
|
|
int AMXAPI amx_NumTags(AMX *amx, int *number);
|
2005-07-25 06:03:43 +00:00
|
|
|
int AMXAPI amx_Push(AMX *amx, cell value);
|
|
|
|
int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell array[], int numcells);
|
|
|
|
int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar);
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_RaiseError(AMX *amx, int error);
|
2005-07-25 06:03:43 +00:00
|
|
|
int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number);
|
2006-05-19 01:54:51 +00:00
|
|
|
int AMXAPI amx_Reregister(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number);
|
2005-09-11 03:58:38 +00:00
|
|
|
int AMXAPI amx_RegisterToAny(AMX *amx, AMX_NATIVE f);
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_Release(AMX *amx, cell amx_addr);
|
|
|
|
int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback);
|
|
|
|
int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug);
|
2005-07-25 06:03:43 +00:00
|
|
|
int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar, size_t size);
|
2004-01-31 20:56:22 +00:00
|
|
|
int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr);
|
2005-07-25 06:03:43 +00:00
|
|
|
int AMXAPI amx_StrLen(const cell *cstring, int *length);
|
|
|
|
int AMXAPI amx_UTF8Check(const char *string, int *length);
|
2004-03-27 16:58:13 +00:00
|
|
|
int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value);
|
2005-07-25 06:03:43 +00:00
|
|
|
int AMXAPI amx_UTF8Len(const cell *cstr, int *length);
|
2004-03-27 16:58:13 +00:00
|
|
|
int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value);
|
2005-07-15 19:15:58 +00:00
|
|
|
int AMXAPI amx_GetLibraries(AMX *amx);
|
|
|
|
const char *AMXAPI amx_GetLibrary(AMX *amx, int index, char *buffer, int len);
|
2005-07-25 06:03:43 +00:00
|
|
|
int AMXAPI amx_SetStringOld(cell *dest,const char *source,int pack,int use_wchar);
|
|
|
|
int AMXAPI amx_GetStringOld(char *dest,const cell *source,int use_wchar);
|
|
|
|
|
|
|
|
#if PAWN_CELL_SIZE==16
|
|
|
|
#define amx_AlignCell(v) amx_Align16(v)
|
|
|
|
#elif PAWN_CELL_SIZE==32
|
|
|
|
#define amx_AlignCell(v) amx_Align32(v)
|
|
|
|
#elif PAWN_CELL_SIZE==64 && (defined _I64_MAX || defined HAVE_I64)
|
|
|
|
#define amx_AlignCell(v) amx_Align64(v)
|
|
|
|
#else
|
|
|
|
#error Unsupported cell size
|
|
|
|
#endif
|
2005-07-15 19:15:58 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#define amx_RegisterFunc(amx, name, func) \
|
|
|
|
amx_Register((amx), amx_NativeInfo((name),(func)), 1);
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
#if !defined AMX_NO_ALIGN
|
2013-02-13 07:14:37 +00:00
|
|
|
#if defined LINUX || defined __FreeBSD__ || defined __APPLE__
|
2004-01-31 20:56:22 +00:00
|
|
|
#pragma pack() /* reset default packing */
|
2005-07-25 06:03:43 +00:00
|
|
|
#elif defined MACOS && defined __MWERKS__
|
|
|
|
#pragma options align=reset
|
2004-01-31 20:56:22 +00:00
|
|
|
#else
|
|
|
|
#pragma pack(pop) /* reset previous packing */
|
|
|
|
#endif
|
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
2006-03-16 06:36:01 +00:00
|
|
|
#if defined BINLOG_ENABLED
|
|
|
|
typedef struct tagBINLOG
|
|
|
|
{
|
|
|
|
void (*pfnLogNative)(AMX *amx, int native, int params);
|
|
|
|
void (*pfnLogReturn)(AMX *amx, cell retval);
|
|
|
|
void (*pfnLogParams)(AMX *amx, cell *params);
|
|
|
|
} binlogfuncs_t;
|
|
|
|
#endif
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-27 16:58:13 +00:00
|
|
|
|
|
|
|
#endif /* AMX_H_INCLUDED */
|