00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __AMX_H
00009 #define __AMX_H
00010
00011
00012 #ifndef NDEBUG
00013 #define NDEBUG
00014 #endif
00015
00016 #if defined __unix__
00017 #define LINUX
00018 #endif
00019
00020 #if defined __unix__
00021 #include "sclinux.h"
00022 #endif
00023
00024 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
00025
00026
00027
00028 #if (defined __LCC__ || defined __GNUC__) && !defined __FreeBSD__
00029 #include <stdint.h>
00030 #else
00031 #if defined __FreeBSD__
00032 #include <inttypes.h>
00033 #else
00034 typedef short int int16_t;
00035 typedef unsigned short int uint16_t;
00036 #if defined SN_TARGET_PS2
00037 typedef int int32_t;
00038 typedef unsigned int uint32_t;
00039 #else
00040 typedef long int int32_t;
00041 typedef unsigned long int uint32_t;
00042 #endif
00043 #endif
00044 #endif
00045 #endif
00046
00047
00048
00049
00050 #if defined SN_TARGET_PS2
00051 #define AMX_NO_ALIGN
00052 #endif
00053
00054 #ifdef __cplusplus
00055 extern "C" {
00056 #endif
00057
00058
00059 #if !defined AMX_NATIVE_CALL
00060 #define AMX_NATIVE_CALL
00061 #endif
00062
00063 #if !defined AMXAPI
00064 #define AMXAPI
00065 #endif
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #define MIN_FILE_VERSION 6
00077 #define CUR_FILE_VERSION 6
00078
00079 #if !defined CELL_TYPE
00080 #define CELL_TYPE
00081 #if defined(BIT16)
00082 typedef uint16_t ucell;
00083 typedef int16_t cell;
00084 #elif defined __alpha__ || defined __x86_64__
00085 typedef uint64_t ucell;
00086 typedef int64_t cell;
00087 #else
00088 typedef uint32_t ucell;
00089 typedef int32_t cell;
00090 #endif
00091 #endif
00092
00093 struct __amx;
00094 typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct __amx *amx, cell *params);
00095 typedef int (AMXAPI *AMX_CALLBACK)(struct __amx *amx, cell index,
00096 cell *result, cell *params);
00097 typedef int (AMXAPI *AMX_DEBUG)(struct __amx *amx);
00098 #if !defined FAR
00099 #define FAR
00100 #endif
00101
00102 #if defined _MSC_VER
00103 #pragma warning(disable:4103)
00104
00105 #endif
00106
00107 #if !defined AMX_NO_ALIGN
00108 #if defined __GNUC__
00109 #pragma pack(1)
00110 #else
00111 #pragma pack(push)
00112 #pragma pack(1)
00113 #if defined __TURBOC__
00114 #pragma option -a-
00115 #endif
00116 #endif
00117 #endif
00118
00119 typedef struct {
00120 char FAR *name;
00121 AMX_NATIVE func;
00122 } AMX_NATIVE_INFO;
00123
00124 #define AMX_USERNUM 4
00125 #define sEXPMAX 30
00126 typedef struct {
00127 cell address;
00128 char name[sEXPMAX+1];
00129 } AMX_FUNCSTUB;
00130
00131
00132
00133
00134 typedef struct __amx {
00135 unsigned char FAR *base;
00136 unsigned char FAR *data;
00137 AMX_CALLBACK callback;
00138 AMX_DEBUG debug;
00139
00140 cell cip;
00141 cell frm;
00142 cell hea, hlw, stk, stp;
00143 int flags;
00144
00145 cell curline, curfile;
00146 int dbgcode;
00147 cell dbgaddr, dbgparam;
00148 char FAR *dbgname;
00149
00150 long usertags[AMX_USERNUM];
00151 void FAR *userdata[AMX_USERNUM];
00152
00153 int error;
00154
00155 cell pri, alt, reset_stk, reset_hea;
00156 #if defined JIT
00157
00158 int reloc_size;
00159 long code_size;
00160 #endif
00161 } AMX;
00162
00163
00164
00165
00166 typedef struct __amx_header {
00167 int32_t size;
00168 uint16_t magic;
00169 char file_version;
00170 char amx_version;
00171 int16_t flags;
00172 int16_t defsize;
00173 int32_t cod;
00174 int32_t dat;
00175 int32_t hea;
00176 int32_t stp;
00177 int32_t cip;
00178 int32_t publics;
00179 int32_t natives;
00180 int32_t libraries;
00181 int32_t pubvars;
00182 int32_t tags;
00183 } AMX_HEADER;
00184 #define AMX_MAGIC 0xf1e0
00185
00186 static const char amx_errMsg [30] [50] = {
00187 "No error", "forced exit", "assertion failed", "stack/heap collision", "index out of bounds", "invalid memory access", "invalid instruction", "stack underflow",
00188 "heap underflow", "no callback, or invalid callback", "native function failed", "divide by zero", "go into sleepmode - code can be restarted", "", ""
00189 , "",""
00190 "out of memory", "invalid file format", "file is for a newer version of the AMX", "function not found", "invalid index parameter (bad entry point)",
00191 "debugger cannot run", "AMX not initialized (or doubly initialized)", "unable to set user data field (table full)", "cannot initialize the JIT",
00192 "parameter error", "", "", "", };
00193
00194 enum {
00195 AMX_ERR_NONE,
00196
00197 AMX_ERR_EXIT,
00198 AMX_ERR_ASSERT,
00199 AMX_ERR_STACKERR,
00200 AMX_ERR_BOUNDS,
00201 AMX_ERR_MEMACCESS,
00202 AMX_ERR_INVINSTR,
00203 AMX_ERR_STACKLOW,
00204 AMX_ERR_HEAPLOW,
00205 AMX_ERR_CALLBACK,
00206 AMX_ERR_NATIVE,
00207 AMX_ERR_DIVIDE,
00208 AMX_ERR_SLEEP,
00209
00210 AMX_ERR_MEMORY = 16,
00211 AMX_ERR_FORMAT,
00212 AMX_ERR_VERSION,
00213 AMX_ERR_NOTFOUND,
00214 AMX_ERR_INDEX,
00215 AMX_ERR_DEBUG,
00216 AMX_ERR_INIT,
00217 AMX_ERR_USERDATA,
00218 AMX_ERR_INIT_JIT,
00219 AMX_ERR_PARAMS,
00220 };
00221
00222 enum {
00223 DBG_INIT,
00224 DBG_FILE,
00225 DBG_LINE,
00226 DBG_SYMBOL,
00227 DBG_CLRSYM,
00228 DBG_CALL,
00229 DBG_RETURN,
00230 DBG_TERMINATE,
00231 DBG_SRANGE,
00232 };
00233
00234 #define AMX_FLAG_CHAR16 0x01
00235 #define AMX_FLAG_DEBUG 0x02
00236 #define AMX_FLAG_COMPACT 0x04
00237 #define AMX_FLAG_BIGENDIAN 0x08
00238 #define AMX_FLAG_BROWSE 0x4000
00239 #define AMX_FLAG_RELOC 0x8000
00240
00241 #define AMX_EXEC_MAIN -1
00242 #define AMX_EXEC_CONT -2
00243
00244 #define AMX_USERTAG(a,b,c,d) ((a) | ((b)<<8) | ((long)(c)<<16) | ((long)(d)<<24))
00245
00246 uint16_t * AMXAPI amx_Align16(uint16_t *v);
00247 uint32_t * AMXAPI amx_Align32(uint32_t *v);
00248 int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr);
00249 int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params);
00250 int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data);
00251 int AMXAPI amx_Debug(AMX *amx);
00252 int AMXAPI amx_Exec(AMX *amx, cell *retval, int index, int numparams, ...);
00253 int AMXAPI amx_Execv(AMX *amx, cell *retval, int index, int numparams, cell params[]);
00254 int AMXAPI amx_FindPublic(AMX *amx, char *funcname, int *index);
00255 int AMXAPI amx_FindPubVar(AMX *amx, char *varname, cell *amx_addr);
00256 int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname);
00257 int AMXAPI amx_Flags(AMX *amx,uint16_t *flags);
00258 int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr);
00259 int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname);
00260 int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr);
00261 int AMXAPI amx_GetString(char *dest,cell *source);
00262 int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id);
00263 int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr);
00264 int AMXAPI amx_Init(AMX *amx, void *program);
00265 int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code);
00266 int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap);
00267 int AMXAPI amx_NameLength(AMX *amx, int *length);
00268 AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(char *name,AMX_NATIVE func);
00269 int AMXAPI amx_NumPublics(AMX *amx, int *number);
00270 int AMXAPI amx_NumPubVars(AMX *amx, int *number);
00271 int AMXAPI amx_NumTags(AMX *amx, int *number);
00272 int AMXAPI amx_RaiseError(AMX *amx, int error);
00273 int AMXAPI amx_Register(AMX *amx, AMX_NATIVE_INFO *nativelist, int number);
00274 int AMXAPI amx_Release(AMX *amx, cell amx_addr);
00275 int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback);
00276 int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug);
00277 int AMXAPI amx_SetString(cell *dest, char *source, int pack);
00278 int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr);
00279 int AMXAPI amx_StrLen(cell *cstring, int *length);
00280 char * amx_FindFunctionbyIndex(AMX *amx, int index);
00281
00282 #if !defined AMX_NO_ALIGN
00283 #if defined __GNUC__
00284 #pragma pack()
00285 #else
00286 #pragma pack(pop)
00287 #endif
00288 #endif
00289
00290 #ifdef __cplusplus
00291 }
00292 #endif
00293
00294 #endif