This is the open source Pawn interpreter ported to mbed. See here: http://www.compuphase.com/pawn/pawn.htm and here: http://code.google.com/p/pawnscript/

Dependents:   Pawn4Test

Some instructions:

  • Put the attached include folder next to your source, so when you compile you get all the proper definitions
  • Use the attached main.p as a starting point if you wish
  • Compile your main.p into main.amx - Put your main.amx on the mbed 'drive'
  • Reset and be amazed.

Important Compile Notes:

  • You should use the -S# option to define a smaller default stack size. Start with -S64 and go up from there if needed.
  • To use on the Cortex-M0 version of the mbed (LPC11U24), you MUST include the TARGET=3 command-line option as well, so the pin names are properly defined. In the future this may be handled on the native code side.

Known Issues:

  • At the moment it appears the kbhit() function is not working right - at least on my mac. Will continue testing on Windows. Working fine.

Todo:

  • Add more wrappers for the mbed peripherals
  • Add Pawn overlay support, to allow much larger scripts to run (even on the LPC11U24)
Committer:
Lobo
Date:
Fri May 24 17:49:26 2013 +0000
Revision:
3:185fdbb7ccf0
Parent:
0:3ab1d2d14eb3
Now includes AnalogIn and AnalogOut functions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerwilson 0:3ab1d2d14eb3 1 /* Pawn Abstract Machine (for the Pawn language)
tylerwilson 0:3ab1d2d14eb3 2 *
tylerwilson 0:3ab1d2d14eb3 3 * Copyright (c) ITB CompuPhase, 1997-2012
tylerwilson 0:3ab1d2d14eb3 4 *
tylerwilson 0:3ab1d2d14eb3 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
tylerwilson 0:3ab1d2d14eb3 6 * use this file except in compliance with the License. You may obtain a copy
tylerwilson 0:3ab1d2d14eb3 7 * of the License at
tylerwilson 0:3ab1d2d14eb3 8 *
tylerwilson 0:3ab1d2d14eb3 9 * http://www.apache.org/licenses/LICENSE-2.0
tylerwilson 0:3ab1d2d14eb3 10 *
tylerwilson 0:3ab1d2d14eb3 11 * Unless required by applicable law or agreed to in writing, software
tylerwilson 0:3ab1d2d14eb3 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
tylerwilson 0:3ab1d2d14eb3 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
tylerwilson 0:3ab1d2d14eb3 14 * License for the specific language governing permissions and limitations
tylerwilson 0:3ab1d2d14eb3 15 * under the License.
tylerwilson 0:3ab1d2d14eb3 16 *
tylerwilson 0:3ab1d2d14eb3 17 * Version: $Id: amx.h 4731 2012-06-21 11:11:18Z thiadmer $
tylerwilson 0:3ab1d2d14eb3 18 */
tylerwilson 0:3ab1d2d14eb3 19
tylerwilson 0:3ab1d2d14eb3 20 #ifndef AMX_H_INCLUDED
tylerwilson 0:3ab1d2d14eb3 21 #define AMX_H_INCLUDED
tylerwilson 0:3ab1d2d14eb3 22
tylerwilson 0:3ab1d2d14eb3 23 #include <stdlib.h> /* for size_t */
tylerwilson 0:3ab1d2d14eb3 24 #include <limits.h>
tylerwilson 0:3ab1d2d14eb3 25
tylerwilson 0:3ab1d2d14eb3 26 #if defined __linux || defined __linux__
tylerwilson 0:3ab1d2d14eb3 27 #define __LINUX__
tylerwilson 0:3ab1d2d14eb3 28 #endif
tylerwilson 0:3ab1d2d14eb3 29 #if defined FREEBSD && !defined __FreeBSD__
tylerwilson 0:3ab1d2d14eb3 30 #define __FreeBSD__
tylerwilson 0:3ab1d2d14eb3 31 #endif
tylerwilson 0:3ab1d2d14eb3 32 #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
tylerwilson 0:3ab1d2d14eb3 33 #include <sclinux.h>
tylerwilson 0:3ab1d2d14eb3 34 #endif
tylerwilson 0:3ab1d2d14eb3 35
tylerwilson 0:3ab1d2d14eb3 36 #if !defined HAVE_STDINT_H
tylerwilson 0:3ab1d2d14eb3 37 #if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) \
tylerwilson 0:3ab1d2d14eb3 38 || defined __GNUC__ || defined __LCC__ || defined __DMC__ \
tylerwilson 0:3ab1d2d14eb3 39 || (defined __WATCOMC__ && __WATCOMC__ >= 1200)
tylerwilson 0:3ab1d2d14eb3 40 #define HAVE_STDINT_H 1
tylerwilson 0:3ab1d2d14eb3 41 #endif
tylerwilson 0:3ab1d2d14eb3 42 #endif
tylerwilson 0:3ab1d2d14eb3 43 #if !defined HAVE_INTTYPES_H
tylerwilson 0:3ab1d2d14eb3 44 #if defined __FreeBSD__
tylerwilson 0:3ab1d2d14eb3 45 #define HAVE_INTTYPES_H 1
tylerwilson 0:3ab1d2d14eb3 46 #endif
tylerwilson 0:3ab1d2d14eb3 47 #endif
tylerwilson 0:3ab1d2d14eb3 48 #if defined HAVE_STDINT_H
tylerwilson 0:3ab1d2d14eb3 49 #include <stdint.h>
tylerwilson 0:3ab1d2d14eb3 50 #elif defined HAVE_INTTYPES_H
tylerwilson 0:3ab1d2d14eb3 51 #include <inttypes.h>
tylerwilson 0:3ab1d2d14eb3 52 #else
tylerwilson 0:3ab1d2d14eb3 53 #if defined __MACH__
tylerwilson 0:3ab1d2d14eb3 54 #include <ppc/types.h>
tylerwilson 0:3ab1d2d14eb3 55 #endif
tylerwilson 0:3ab1d2d14eb3 56 typedef short int int16_t;
tylerwilson 0:3ab1d2d14eb3 57 typedef unsigned short int uint16_t;
tylerwilson 0:3ab1d2d14eb3 58 #if defined SN_TARGET_PS2
tylerwilson 0:3ab1d2d14eb3 59 typedef int int32_t;
tylerwilson 0:3ab1d2d14eb3 60 typedef unsigned int uint32_t;
tylerwilson 0:3ab1d2d14eb3 61 #else
tylerwilson 0:3ab1d2d14eb3 62 typedef long int int32_t;
tylerwilson 0:3ab1d2d14eb3 63 typedef unsigned long int uint32_t;
tylerwilson 0:3ab1d2d14eb3 64 #endif
tylerwilson 0:3ab1d2d14eb3 65 #if defined __WIN32__ || defined _WIN32 || defined WIN32
tylerwilson 0:3ab1d2d14eb3 66 typedef __int64 int64_t;
tylerwilson 0:3ab1d2d14eb3 67 typedef unsigned __int64 uint64_t;
tylerwilson 0:3ab1d2d14eb3 68 #define HAVE_I64
tylerwilson 0:3ab1d2d14eb3 69 #endif
tylerwilson 0:3ab1d2d14eb3 70 #if !defined _INTPTR_T_DEFINED
tylerwilson 0:3ab1d2d14eb3 71 #if defined _LP64 || defined WIN64 || defined _WIN64
tylerwilson 0:3ab1d2d14eb3 72 typedef __int64 intptr_t;
tylerwilson 0:3ab1d2d14eb3 73 #else
tylerwilson 0:3ab1d2d14eb3 74 typedef int32_t intptr_t;
tylerwilson 0:3ab1d2d14eb3 75 #endif
tylerwilson 0:3ab1d2d14eb3 76 #endif
tylerwilson 0:3ab1d2d14eb3 77 #endif
tylerwilson 0:3ab1d2d14eb3 78 #if defined _LP64 || defined WIN64 || defined _WIN64
tylerwilson 0:3ab1d2d14eb3 79 #if !defined __64BIT__
tylerwilson 0:3ab1d2d14eb3 80 #define __64BIT__
tylerwilson 0:3ab1d2d14eb3 81 #endif
tylerwilson 0:3ab1d2d14eb3 82 #endif
tylerwilson 0:3ab1d2d14eb3 83
tylerwilson 0:3ab1d2d14eb3 84 #if !defined HAVE_ALLOCA_H
tylerwilson 0:3ab1d2d14eb3 85 #if defined __GNUC__ || defined __LCC__ || defined __DMC__ || defined __ARMCC_VERSION
tylerwilson 0:3ab1d2d14eb3 86 #define HAVE_ALLOCA_H 1
tylerwilson 0:3ab1d2d14eb3 87 #elif defined __WATCOMC__ && __WATCOMC__ >= 1200
tylerwilson 0:3ab1d2d14eb3 88 #define HAVE_ALLOCA_H 1
tylerwilson 0:3ab1d2d14eb3 89 #endif
tylerwilson 0:3ab1d2d14eb3 90 #endif
tylerwilson 0:3ab1d2d14eb3 91 #if defined HAVE_ALLOCA_H && HAVE_ALLOCA_H
tylerwilson 0:3ab1d2d14eb3 92 #include <alloca.h>
tylerwilson 0:3ab1d2d14eb3 93 #elif defined __BORLANDC__
tylerwilson 0:3ab1d2d14eb3 94 #include <malloc.h>
tylerwilson 0:3ab1d2d14eb3 95 #endif
tylerwilson 0:3ab1d2d14eb3 96 #if defined __WIN32__ || defined _WIN32 || defined WIN32 /* || defined __MSDOS__ */
tylerwilson 0:3ab1d2d14eb3 97 #if !defined alloca
tylerwilson 0:3ab1d2d14eb3 98 #define alloca(n) _alloca(n)
tylerwilson 0:3ab1d2d14eb3 99 #endif
tylerwilson 0:3ab1d2d14eb3 100 #endif
tylerwilson 0:3ab1d2d14eb3 101
tylerwilson 0:3ab1d2d14eb3 102 #if !defined assert_static
tylerwilson 0:3ab1d2d14eb3 103 /* see "Compile-Time Assertions" by Greg Miller,
tylerwilson 0:3ab1d2d14eb3 104 * (with modifications to port it to C)
tylerwilson 0:3ab1d2d14eb3 105 */
tylerwilson 0:3ab1d2d14eb3 106 #define _ASSERT_STATIC_SYMBOL_INNER(line) __ASSERT_STATIC_ ## line
tylerwilson 0:3ab1d2d14eb3 107 #define _ASSERT_STATIC_SYMBOL(line) _ASSERT_STATIC_SYMBOL_INNER(line)
tylerwilson 0:3ab1d2d14eb3 108 #define assert_static(test) \
tylerwilson 0:3ab1d2d14eb3 109 do { \
tylerwilson 0:3ab1d2d14eb3 110 typedef char _ASSERT_STATIC_SYMBOL(__LINE__)[ ((test) ? 1 : -1) ]; \
tylerwilson 0:3ab1d2d14eb3 111 } while (0)
tylerwilson 0:3ab1d2d14eb3 112 #endif
tylerwilson 0:3ab1d2d14eb3 113
tylerwilson 0:3ab1d2d14eb3 114 #if defined __cplusplus
tylerwilson 0:3ab1d2d14eb3 115 extern "C" {
tylerwilson 0:3ab1d2d14eb3 116 #endif
tylerwilson 0:3ab1d2d14eb3 117
tylerwilson 0:3ab1d2d14eb3 118 #if defined PAWN_DLL
tylerwilson 0:3ab1d2d14eb3 119 #if !defined AMX_NATIVE_CALL
tylerwilson 0:3ab1d2d14eb3 120 #define AMX_NATIVE_CALL __stdcall
tylerwilson 0:3ab1d2d14eb3 121 #endif
tylerwilson 0:3ab1d2d14eb3 122 #if !defined AMXAPI
tylerwilson 0:3ab1d2d14eb3 123 #define AMXAPI __stdcall
tylerwilson 0:3ab1d2d14eb3 124 #endif
tylerwilson 0:3ab1d2d14eb3 125 #if !defined AMXEXPORT
tylerwilson 0:3ab1d2d14eb3 126 #define AMXEXPORT __declspec(dllexport)
tylerwilson 0:3ab1d2d14eb3 127 #endif
tylerwilson 0:3ab1d2d14eb3 128 #endif
tylerwilson 0:3ab1d2d14eb3 129
tylerwilson 0:3ab1d2d14eb3 130 /* calling convention for native functions */
tylerwilson 0:3ab1d2d14eb3 131 #if !defined AMX_NATIVE_CALL
tylerwilson 0:3ab1d2d14eb3 132 #define AMX_NATIVE_CALL
tylerwilson 0:3ab1d2d14eb3 133 #endif
tylerwilson 0:3ab1d2d14eb3 134 /* calling convention for all interface functions and callback functions */
tylerwilson 0:3ab1d2d14eb3 135 #if !defined AMXAPI
tylerwilson 0:3ab1d2d14eb3 136 #if defined STDECL
tylerwilson 0:3ab1d2d14eb3 137 #define AMXAPI __stdcall
tylerwilson 0:3ab1d2d14eb3 138 #elif defined CDECL
tylerwilson 0:3ab1d2d14eb3 139 #define AMXAPI __cdecl
tylerwilson 0:3ab1d2d14eb3 140 #elif defined GCC_HASCLASSVISIBILITY
tylerwilson 0:3ab1d2d14eb3 141 #define AMXAPI __attribute__((visibility("default")))
tylerwilson 0:3ab1d2d14eb3 142 #else
tylerwilson 0:3ab1d2d14eb3 143 #define AMXAPI
tylerwilson 0:3ab1d2d14eb3 144 #endif
tylerwilson 0:3ab1d2d14eb3 145 #endif
tylerwilson 0:3ab1d2d14eb3 146 #if !defined AMXEXPORT
tylerwilson 0:3ab1d2d14eb3 147 #define AMXEXPORT
tylerwilson 0:3ab1d2d14eb3 148 #endif
tylerwilson 0:3ab1d2d14eb3 149
tylerwilson 0:3ab1d2d14eb3 150 /* File format version (in CUR_FILE_VERSION)
tylerwilson 0:3ab1d2d14eb3 151 * 0 original version
tylerwilson 0:3ab1d2d14eb3 152 * 1 opcodes JUMP.pri, SWITCH and CASETBL
tylerwilson 0:3ab1d2d14eb3 153 * 2 compressed files
tylerwilson 0:3ab1d2d14eb3 154 * 3 public variables
tylerwilson 0:3ab1d2d14eb3 155 * 4 opcodes SWAP.pri/alt and PUSHADDR
tylerwilson 0:3ab1d2d14eb3 156 * 5 tagnames table
tylerwilson 0:3ab1d2d14eb3 157 * 6 reformatted header
tylerwilson 0:3ab1d2d14eb3 158 * 7 name table, opcodes SYMTAG & SYSREQ.D
tylerwilson 0:3ab1d2d14eb3 159 * 8 opcode BREAK, renewed debug interface
tylerwilson 0:3ab1d2d14eb3 160 * 9 macro opcodes
tylerwilson 0:3ab1d2d14eb3 161 * 10 position-independent code, overlays, packed instructions
tylerwilson 0:3ab1d2d14eb3 162 * 11 relocating instructions for the native interface, reorganized instruction set
tylerwilson 0:3ab1d2d14eb3 163 * MIN_FILE_VERSION is the lowest file version number that the current AMX
tylerwilson 0:3ab1d2d14eb3 164 * implementation supports. If the AMX file header gets new fields, this number
tylerwilson 0:3ab1d2d14eb3 165 * often needs to be incremented. MIN_AMX_VERSION is the lowest AMX version that
tylerwilson 0:3ab1d2d14eb3 166 * is needed to support the current file version. When there are new opcodes,
tylerwilson 0:3ab1d2d14eb3 167 * this number needs to be incremented.
tylerwilson 0:3ab1d2d14eb3 168 * The file version supported by the JIT may run behind MIN_AMX_VERSION. So
tylerwilson 0:3ab1d2d14eb3 169 * there is an extra constant for it: MAX_FILE_VER_JIT.
tylerwilson 0:3ab1d2d14eb3 170 */
tylerwilson 0:3ab1d2d14eb3 171 #define CUR_FILE_VERSION 11 /* current file version; also the current AMX version */
tylerwilson 0:3ab1d2d14eb3 172 #define MIN_FILE_VERSION 11 /* lowest supported file format version for the current AMX version */
tylerwilson 0:3ab1d2d14eb3 173 #define MIN_AMX_VERSION 11 /* minimum AMX version needed to support the current file format */
tylerwilson 0:3ab1d2d14eb3 174 #define MAX_FILE_VER_JIT 11 /* file version supported by the JIT */
tylerwilson 0:3ab1d2d14eb3 175 #define MIN_AMX_VER_JIT 11 /* AMX version supported by the JIT */
tylerwilson 0:3ab1d2d14eb3 176
tylerwilson 0:3ab1d2d14eb3 177 #if !defined PAWN_CELL_SIZE
tylerwilson 0:3ab1d2d14eb3 178 #define PAWN_CELL_SIZE 32 /* by default, use 32-bit cells */
tylerwilson 0:3ab1d2d14eb3 179 #endif
tylerwilson 0:3ab1d2d14eb3 180 #if PAWN_CELL_SIZE==16
tylerwilson 0:3ab1d2d14eb3 181 typedef uint16_t ucell;
tylerwilson 0:3ab1d2d14eb3 182 typedef int16_t cell;
tylerwilson 0:3ab1d2d14eb3 183 #elif PAWN_CELL_SIZE==32
tylerwilson 0:3ab1d2d14eb3 184 typedef uint32_t ucell;
tylerwilson 0:3ab1d2d14eb3 185 typedef int32_t cell;
tylerwilson 0:3ab1d2d14eb3 186 #elif PAWN_CELL_SIZE==64
tylerwilson 0:3ab1d2d14eb3 187 typedef uint64_t ucell;
tylerwilson 0:3ab1d2d14eb3 188 typedef int64_t cell;
tylerwilson 0:3ab1d2d14eb3 189 #else
tylerwilson 0:3ab1d2d14eb3 190 #error Unsupported cell size (PAWN_CELL_SIZE)
tylerwilson 0:3ab1d2d14eb3 191 #endif
tylerwilson 0:3ab1d2d14eb3 192
tylerwilson 0:3ab1d2d14eb3 193 #define UNPACKEDMAX (((cell)1 << (sizeof(cell)-1)*8) - 1)
tylerwilson 0:3ab1d2d14eb3 194 #define UNLIMITED (~1u >> 1)
tylerwilson 0:3ab1d2d14eb3 195
tylerwilson 0:3ab1d2d14eb3 196 struct tagAMX;
tylerwilson 0:3ab1d2d14eb3 197 typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct tagAMX *amx, const cell *params);
tylerwilson 0:3ab1d2d14eb3 198 typedef int (AMXAPI *AMX_CALLBACK)(struct tagAMX *amx, cell index,
tylerwilson 0:3ab1d2d14eb3 199 cell *result, const cell *params);
tylerwilson 0:3ab1d2d14eb3 200 typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
tylerwilson 0:3ab1d2d14eb3 201 typedef int (AMXAPI *AMX_OVERLAY)(struct tagAMX *amx, int index);
tylerwilson 0:3ab1d2d14eb3 202 typedef int (AMXAPI *AMX_IDLE)(struct tagAMX *amx, int AMXAPI Exec(struct tagAMX *, cell *, int));
tylerwilson 0:3ab1d2d14eb3 203 #if !defined _FAR
tylerwilson 0:3ab1d2d14eb3 204 #define _FAR
tylerwilson 0:3ab1d2d14eb3 205 #endif
tylerwilson 0:3ab1d2d14eb3 206
tylerwilson 0:3ab1d2d14eb3 207 #if defined _MSC_VER
tylerwilson 0:3ab1d2d14eb3 208 #pragma warning(disable:4103) /* disable warning message 4103 that complains
tylerwilson 0:3ab1d2d14eb3 209 * about pragma pack in a header file */
tylerwilson 0:3ab1d2d14eb3 210 #pragma warning(disable:4100) /* "'%$S' : unreferenced formal parameter" */
tylerwilson 0:3ab1d2d14eb3 211 #pragma warning(disable:4996) /* POSIX name is deprecated */
tylerwilson 0:3ab1d2d14eb3 212 #endif
tylerwilson 0:3ab1d2d14eb3 213
tylerwilson 0:3ab1d2d14eb3 214 /* Some compilers do not support the #pragma align, which should be fine. Some
tylerwilson 0:3ab1d2d14eb3 215 * compilers give a warning on unknown #pragmas, which is not so fine...
tylerwilson 0:3ab1d2d14eb3 216 */
tylerwilson 0:3ab1d2d14eb3 217 #if (defined SN_TARGET_PS2 || defined __GNUC__) && !defined AMX_NO_ALIGN
tylerwilson 0:3ab1d2d14eb3 218 #define AMX_NO_ALIGN
tylerwilson 0:3ab1d2d14eb3 219 #endif
tylerwilson 0:3ab1d2d14eb3 220
tylerwilson 0:3ab1d2d14eb3 221 #if defined __GNUC__
tylerwilson 0:3ab1d2d14eb3 222 #define PACKED __attribute__((packed))
tylerwilson 0:3ab1d2d14eb3 223 #else
tylerwilson 0:3ab1d2d14eb3 224 #define PACKED
tylerwilson 0:3ab1d2d14eb3 225 #endif
tylerwilson 0:3ab1d2d14eb3 226
tylerwilson 0:3ab1d2d14eb3 227 #if !defined AMX_NO_ALIGN
tylerwilson 0:3ab1d2d14eb3 228 #if defined __LINUX__ || defined __FreeBSD__
tylerwilson 0:3ab1d2d14eb3 229 #pragma pack(1) /* structures must be packed (byte-aligned) */
tylerwilson 0:3ab1d2d14eb3 230 #elif defined MACOS && defined __MWERKS__
tylerwilson 0:3ab1d2d14eb3 231 #pragma options align=mac68k
tylerwilson 0:3ab1d2d14eb3 232 #else
tylerwilson 0:3ab1d2d14eb3 233 #pragma pack(push)
tylerwilson 0:3ab1d2d14eb3 234 #pragma pack(1) /* structures must be packed (byte-aligned) */
tylerwilson 0:3ab1d2d14eb3 235 #if defined __TURBOC__
tylerwilson 0:3ab1d2d14eb3 236 #pragma option -a- /* "pack" pragma for older Borland compilers */
tylerwilson 0:3ab1d2d14eb3 237 #endif
tylerwilson 0:3ab1d2d14eb3 238 #endif
tylerwilson 0:3ab1d2d14eb3 239 #endif
tylerwilson 0:3ab1d2d14eb3 240
tylerwilson 0:3ab1d2d14eb3 241 typedef struct tagAMX_NATIVE_INFO {
tylerwilson 0:3ab1d2d14eb3 242 const char _FAR *name;
tylerwilson 0:3ab1d2d14eb3 243 AMX_NATIVE func;
tylerwilson 0:3ab1d2d14eb3 244 } PACKED AMX_NATIVE_INFO;
tylerwilson 0:3ab1d2d14eb3 245
tylerwilson 0:3ab1d2d14eb3 246 #if !defined AMX_USERNUM
tylerwilson 0:3ab1d2d14eb3 247 #define AMX_USERNUM 4
tylerwilson 0:3ab1d2d14eb3 248 #endif
tylerwilson 0:3ab1d2d14eb3 249 #define sEXPMAX 19 /* maximum name length for file version <= 6 */
tylerwilson 0:3ab1d2d14eb3 250 #define sNAMEMAX 31 /* maximum name length of symbol name */
tylerwilson 0:3ab1d2d14eb3 251
tylerwilson 0:3ab1d2d14eb3 252 typedef struct tagFUNCSTUB {
tylerwilson 0:3ab1d2d14eb3 253 uint32_t address;
tylerwilson 0:3ab1d2d14eb3 254 uint32_t nameofs;
tylerwilson 0:3ab1d2d14eb3 255 } PACKED AMX_FUNCSTUB;
tylerwilson 0:3ab1d2d14eb3 256
tylerwilson 0:3ab1d2d14eb3 257 typedef struct tagOVERLAYINFO {
tylerwilson 0:3ab1d2d14eb3 258 int32_t offset; /* offset relative to the start of the code block */
tylerwilson 0:3ab1d2d14eb3 259 int32_t size; /* size in bytes */
tylerwilson 0:3ab1d2d14eb3 260 } PACKED AMX_OVERLAYINFO;
tylerwilson 0:3ab1d2d14eb3 261
tylerwilson 0:3ab1d2d14eb3 262 /* The AMX structure is the internal structure for many functions. Not all
tylerwilson 0:3ab1d2d14eb3 263 * fields are valid at all times; many fields are cached in local variables.
tylerwilson 0:3ab1d2d14eb3 264 */
tylerwilson 0:3ab1d2d14eb3 265 typedef struct tagAMX {
tylerwilson 0:3ab1d2d14eb3 266 unsigned char _FAR *base; /* points to the AMX header, perhaps followed by P-code and data */
tylerwilson 0:3ab1d2d14eb3 267 unsigned char _FAR *code; /* points to P-code block, possibly in ROM or in an overlay pool */
tylerwilson 0:3ab1d2d14eb3 268 unsigned char _FAR *data; /* points to separate data+stack+heap, may be NULL */
tylerwilson 0:3ab1d2d14eb3 269 AMX_CALLBACK callback; /* native function callback */
tylerwilson 0:3ab1d2d14eb3 270 AMX_DEBUG debug; /* debug callback */
tylerwilson 0:3ab1d2d14eb3 271 AMX_OVERLAY overlay; /* overlay reader callback */
tylerwilson 0:3ab1d2d14eb3 272 /* for external functions a few registers must be accessible from the outside */
tylerwilson 0:3ab1d2d14eb3 273 cell cip; /* instruction pointer: relative to base + amxhdr->cod */
tylerwilson 0:3ab1d2d14eb3 274 cell frm; /* stack frame base: relative to base + amxhdr->dat */
tylerwilson 0:3ab1d2d14eb3 275 cell hea; /* top of the heap: relative to base + amxhdr->dat */
tylerwilson 0:3ab1d2d14eb3 276 cell hlw; /* bottom of the heap: relative to base + amxhdr->dat */
tylerwilson 0:3ab1d2d14eb3 277 cell stk; /* stack pointer: relative to base + amxhdr->dat */
tylerwilson 0:3ab1d2d14eb3 278 cell stp; /* top of the stack: relative to base + amxhdr->dat */
tylerwilson 0:3ab1d2d14eb3 279 int flags; /* current status, see amx_Flags() */
tylerwilson 0:3ab1d2d14eb3 280 /* user data */
tylerwilson 0:3ab1d2d14eb3 281 #if AMX_USERNUM > 0
tylerwilson 0:3ab1d2d14eb3 282 long usertags[AMX_USERNUM];
tylerwilson 0:3ab1d2d14eb3 283 void _FAR *userdata[AMX_USERNUM];
tylerwilson 0:3ab1d2d14eb3 284 #endif
tylerwilson 0:3ab1d2d14eb3 285 /* native functions can raise an error */
tylerwilson 0:3ab1d2d14eb3 286 int error;
tylerwilson 0:3ab1d2d14eb3 287 /* passing parameters requires a "count" field */
tylerwilson 0:3ab1d2d14eb3 288 int paramcount;
tylerwilson 0:3ab1d2d14eb3 289 /* the sleep opcode needs to store the full AMX status */
tylerwilson 0:3ab1d2d14eb3 290 cell pri;
tylerwilson 0:3ab1d2d14eb3 291 cell alt;
tylerwilson 0:3ab1d2d14eb3 292 cell reset_stk;
tylerwilson 0:3ab1d2d14eb3 293 cell reset_hea;
tylerwilson 0:3ab1d2d14eb3 294 /* extra fields for increased performance */
tylerwilson 0:3ab1d2d14eb3 295 cell sysreq_d; /* relocated address/value for the SYSREQ.D opcode */
tylerwilson 0:3ab1d2d14eb3 296 /* fields for overlay support and JIT support */
tylerwilson 0:3ab1d2d14eb3 297 int ovl_index; /* current overlay index */
tylerwilson 0:3ab1d2d14eb3 298 long codesize; /* size of the overlay, or estimated memory footprint of the native code */
tylerwilson 0:3ab1d2d14eb3 299 #if defined AMX_JIT
tylerwilson 0:3ab1d2d14eb3 300 /* support variables for the JIT */
tylerwilson 0:3ab1d2d14eb3 301 int reloc_size; /* required temporary buffer for relocations */
tylerwilson 0:3ab1d2d14eb3 302 #endif
tylerwilson 0:3ab1d2d14eb3 303 } PACKED AMX;
tylerwilson 0:3ab1d2d14eb3 304
tylerwilson 0:3ab1d2d14eb3 305 /* The AMX_HEADER structure is both the memory format as the file format. The
tylerwilson 0:3ab1d2d14eb3 306 * structure is used internaly.
tylerwilson 0:3ab1d2d14eb3 307 */
tylerwilson 0:3ab1d2d14eb3 308 typedef struct tagAMX_HEADER {
tylerwilson 0:3ab1d2d14eb3 309 int32_t size; /* size of the "file" */
tylerwilson 0:3ab1d2d14eb3 310 uint16_t magic; /* signature */
tylerwilson 0:3ab1d2d14eb3 311 char file_version; /* file format version */
tylerwilson 0:3ab1d2d14eb3 312 char amx_version; /* required version of the AMX */
tylerwilson 0:3ab1d2d14eb3 313 int16_t flags;
tylerwilson 0:3ab1d2d14eb3 314 int16_t defsize; /* size of a definition record */
tylerwilson 0:3ab1d2d14eb3 315 int32_t cod; /* initial value of COD - code block */
tylerwilson 0:3ab1d2d14eb3 316 int32_t dat; /* initial value of DAT - data block */
tylerwilson 0:3ab1d2d14eb3 317 int32_t hea; /* initial value of HEA - start of the heap */
tylerwilson 0:3ab1d2d14eb3 318 int32_t stp; /* initial value of STP - stack top */
tylerwilson 0:3ab1d2d14eb3 319 int32_t cip; /* initial value of CIP - the instruction pointer */
tylerwilson 0:3ab1d2d14eb3 320 int32_t publics; /* offset to the "public functions" table */
tylerwilson 0:3ab1d2d14eb3 321 int32_t natives; /* offset to the "native functions" table */
tylerwilson 0:3ab1d2d14eb3 322 int32_t libraries; /* offset to the table of libraries */
tylerwilson 0:3ab1d2d14eb3 323 int32_t pubvars; /* offset to the "public variables" table */
tylerwilson 0:3ab1d2d14eb3 324 int32_t tags; /* offset to the "public tagnames" table */
tylerwilson 0:3ab1d2d14eb3 325 int32_t nametable; /* offset to the name table */
tylerwilson 0:3ab1d2d14eb3 326 int32_t overlays; /* offset to the overlay table */
tylerwilson 0:3ab1d2d14eb3 327 } PACKED AMX_HEADER;
tylerwilson 0:3ab1d2d14eb3 328
tylerwilson 0:3ab1d2d14eb3 329 #define AMX_MAGIC_16 0xf1e2
tylerwilson 0:3ab1d2d14eb3 330 #define AMX_MAGIC_32 0xf1e0
tylerwilson 0:3ab1d2d14eb3 331 #define AMX_MAGIC_64 0xf1e1
tylerwilson 0:3ab1d2d14eb3 332 #if PAWN_CELL_SIZE==16
tylerwilson 0:3ab1d2d14eb3 333 #define AMX_MAGIC AMX_MAGIC_16
tylerwilson 0:3ab1d2d14eb3 334 #elif PAWN_CELL_SIZE==32
tylerwilson 0:3ab1d2d14eb3 335 #define AMX_MAGIC AMX_MAGIC_32
tylerwilson 0:3ab1d2d14eb3 336 #elif PAWN_CELL_SIZE==64
tylerwilson 0:3ab1d2d14eb3 337 #define AMX_MAGIC AMX_MAGIC_64
tylerwilson 0:3ab1d2d14eb3 338 #endif
tylerwilson 0:3ab1d2d14eb3 339
tylerwilson 0:3ab1d2d14eb3 340 enum {
tylerwilson 0:3ab1d2d14eb3 341 AMX_ERR_NONE,
tylerwilson 0:3ab1d2d14eb3 342 /* reserve the first 15 error codes for exit codes of the abstract machine */
tylerwilson 0:3ab1d2d14eb3 343 AMX_ERR_EXIT, /* forced exit */
tylerwilson 0:3ab1d2d14eb3 344 AMX_ERR_ASSERT, /* assertion failed */
tylerwilson 0:3ab1d2d14eb3 345 AMX_ERR_STACKERR, /* stack/heap collision */
tylerwilson 0:3ab1d2d14eb3 346 AMX_ERR_BOUNDS, /* index out of bounds */
tylerwilson 0:3ab1d2d14eb3 347 AMX_ERR_MEMACCESS, /* invalid memory access */
tylerwilson 0:3ab1d2d14eb3 348 AMX_ERR_INVINSTR, /* invalid instruction */
tylerwilson 0:3ab1d2d14eb3 349 AMX_ERR_STACKLOW, /* stack underflow */
tylerwilson 0:3ab1d2d14eb3 350 AMX_ERR_HEAPLOW, /* heap underflow */
tylerwilson 0:3ab1d2d14eb3 351 AMX_ERR_CALLBACK, /* no callback, or invalid callback */
tylerwilson 0:3ab1d2d14eb3 352 AMX_ERR_NATIVE, /* native function failed */
tylerwilson 0:3ab1d2d14eb3 353 AMX_ERR_DIVIDE, /* divide by zero */
tylerwilson 0:3ab1d2d14eb3 354 AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */
tylerwilson 0:3ab1d2d14eb3 355 AMX_ERR_INVSTATE, /* no implementation for this state, no fall-back */
tylerwilson 0:3ab1d2d14eb3 356
tylerwilson 0:3ab1d2d14eb3 357 AMX_ERR_MEMORY = 16, /* out of memory */
tylerwilson 0:3ab1d2d14eb3 358 AMX_ERR_FORMAT, /* invalid file format */
tylerwilson 0:3ab1d2d14eb3 359 AMX_ERR_VERSION, /* file is for a newer version of the AMX */
tylerwilson 0:3ab1d2d14eb3 360 AMX_ERR_NOTFOUND, /* function not found */
tylerwilson 0:3ab1d2d14eb3 361 AMX_ERR_INDEX, /* invalid index parameter (bad entry point) */
tylerwilson 0:3ab1d2d14eb3 362 AMX_ERR_DEBUG, /* debugger cannot run */
tylerwilson 0:3ab1d2d14eb3 363 AMX_ERR_INIT, /* AMX not initialized (or doubly initialized) */
tylerwilson 0:3ab1d2d14eb3 364 AMX_ERR_USERDATA, /* unable to set user data field (table full) */
tylerwilson 0:3ab1d2d14eb3 365 AMX_ERR_INIT_JIT, /* cannot initialize the JIT */
tylerwilson 0:3ab1d2d14eb3 366 AMX_ERR_PARAMS, /* parameter error */
tylerwilson 0:3ab1d2d14eb3 367 AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */
tylerwilson 0:3ab1d2d14eb3 368 AMX_ERR_GENERAL, /* general error (unknown or unspecific error) */
tylerwilson 0:3ab1d2d14eb3 369 AMX_ERR_OVERLAY, /* overlays are unsupported (JIT) or uninitialized */
tylerwilson 0:3ab1d2d14eb3 370 };
tylerwilson 0:3ab1d2d14eb3 371
tylerwilson 0:3ab1d2d14eb3 372 #define AMX_FLAG_OVERLAY 0x01 /* all function calls use overlays */
tylerwilson 0:3ab1d2d14eb3 373 #define AMX_FLAG_DEBUG 0x02 /* symbolic info. available */
tylerwilson 0:3ab1d2d14eb3 374 #define AMX_FLAG_NOCHECKS 0x04 /* no array bounds checking; no BREAK opcodes */
tylerwilson 0:3ab1d2d14eb3 375 #define AMX_FLAG_SLEEP 0x08 /* script uses the sleep instruction (possible re-entry or power-down mode) */
tylerwilson 0:3ab1d2d14eb3 376 #define AMX_FLAG_CRYPT 0x10 /* file is encrypted */
tylerwilson 0:3ab1d2d14eb3 377 #define AMX_FLAG_DSEG_INIT 0x20 /* data section is explicitly initialized */
tylerwilson 0:3ab1d2d14eb3 378 #define AMX_FLAG_SYSREQN 0x800 /* script uses new (optimized) version of SYSREQ opcode */
tylerwilson 0:3ab1d2d14eb3 379 #define AMX_FLAG_NTVREG 0x1000 /* all native functions are registered */
tylerwilson 0:3ab1d2d14eb3 380 #define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */
tylerwilson 0:3ab1d2d14eb3 381 #define AMX_FLAG_VERIFY 0x4000 /* busy verifying P-code */
tylerwilson 0:3ab1d2d14eb3 382 #define AMX_FLAG_INIT 0x8000 /* AMX has been initialized */
tylerwilson 0:3ab1d2d14eb3 383
tylerwilson 0:3ab1d2d14eb3 384 #define AMX_EXEC_MAIN (-1) /* start at program entry point */
tylerwilson 0:3ab1d2d14eb3 385 #define AMX_EXEC_CONT (-2) /* continue from last address */
tylerwilson 0:3ab1d2d14eb3 386
tylerwilson 0:3ab1d2d14eb3 387 #define AMX_USERTAG(a,b,c,d) ((a) | ((b)<<8) | ((long)(c)<<16) | ((long)(d)<<24))
tylerwilson 0:3ab1d2d14eb3 388
tylerwilson 0:3ab1d2d14eb3 389 /* for native functions that use floating point parameters, the following
tylerwilson 0:3ab1d2d14eb3 390 * two macros are convenient for casting a "cell" into a "float" type _without_
tylerwilson 0:3ab1d2d14eb3 391 * changing the bit pattern
tylerwilson 0:3ab1d2d14eb3 392 */
tylerwilson 0:3ab1d2d14eb3 393 #if PAWN_CELL_SIZE==32
tylerwilson 0:3ab1d2d14eb3 394 #define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */
tylerwilson 0:3ab1d2d14eb3 395 #define amx_ctof(c) ( * ((float*)&c) ) /* cell to float */
tylerwilson 0:3ab1d2d14eb3 396 #elif PAWN_CELL_SIZE==64
tylerwilson 0:3ab1d2d14eb3 397 #define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */
tylerwilson 0:3ab1d2d14eb3 398 #define amx_ctof(c) ( * ((double*)&c) ) /* cell to float */
tylerwilson 0:3ab1d2d14eb3 399 #else
tylerwilson 0:3ab1d2d14eb3 400 // amx_ftoc() and amx_ctof() cannot be used
tylerwilson 0:3ab1d2d14eb3 401 #endif
tylerwilson 0:3ab1d2d14eb3 402
tylerwilson 0:3ab1d2d14eb3 403 /* when a pointer cannot be stored in a cell, cells that hold relocated
tylerwilson 0:3ab1d2d14eb3 404 * addresses need to be expanded
tylerwilson 0:3ab1d2d14eb3 405 */
tylerwilson 0:3ab1d2d14eb3 406 #if defined __64BIT__ && PAWN_CELL_SIZE<64
tylerwilson 0:3ab1d2d14eb3 407 #define CELLMASK (((int64_t)1 << PAWN_CELL_SIZE) - 1)
tylerwilson 0:3ab1d2d14eb3 408 #define amx_Address(amx,addr) \
tylerwilson 0:3ab1d2d14eb3 409 (cell*)(((int64_t)((amx)->data ? (amx)->data : (amx)->code) & ~CELLMASK) | ((int64_t)(addr) & CELLMASK))
tylerwilson 0:3ab1d2d14eb3 410 #elif defined __32BIT__ && PAWN_CELL_SIZE<32
tylerwilson 0:3ab1d2d14eb3 411 #define CELLMASK ((1L << PAWN_CELL_SIZE) - 1)
tylerwilson 0:3ab1d2d14eb3 412 #define amx_Address(amx,addr) \
tylerwilson 0:3ab1d2d14eb3 413 (cell*)(((int32_t)((amx)->data ? (amx)->data : (amx)->code) & ~CELLMASK) | ((int32_t)(addr) & CELLMASK))
tylerwilson 0:3ab1d2d14eb3 414 #else
tylerwilson 0:3ab1d2d14eb3 415 #define amx_Address(amx,addr) ((void)(amx),(cell*)(addr))
tylerwilson 0:3ab1d2d14eb3 416 #endif
tylerwilson 0:3ab1d2d14eb3 417
tylerwilson 0:3ab1d2d14eb3 418 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
tylerwilson 0:3ab1d2d14eb3 419 /* C99: use variable-length arrays */
tylerwilson 0:3ab1d2d14eb3 420 #define amx_StrParam_Type(amx,param,result,type) \
tylerwilson 0:3ab1d2d14eb3 421 int result##_length_; \
tylerwilson 0:3ab1d2d14eb3 422 amx_StrLen(amx_Address(amx,param),&result##_length_); \
tylerwilson 0:3ab1d2d14eb3 423 char result##_vla_[(result##_length_+1)*sizeof(*(result))]; \
tylerwilson 0:3ab1d2d14eb3 424 (result)=(type)result##_vla_; \
tylerwilson 0:3ab1d2d14eb3 425 amx_GetString((char*)(result),amx_Address(amx,param), \
tylerwilson 0:3ab1d2d14eb3 426 sizeof(*(result))>1,result##_length_+1)
tylerwilson 0:3ab1d2d14eb3 427 #define amx_StrParam(amx,param,result) \
tylerwilson 0:3ab1d2d14eb3 428 amx_StrParam_Type(amx,param,result,void*)
tylerwilson 0:3ab1d2d14eb3 429 #else
tylerwilson 0:3ab1d2d14eb3 430 /* macro using alloca() */
tylerwilson 0:3ab1d2d14eb3 431 #define amx_StrParam_Type(amx,param,result,type) \
tylerwilson 0:3ab1d2d14eb3 432 do { \
tylerwilson 0:3ab1d2d14eb3 433 int result##_length_; \
tylerwilson 0:3ab1d2d14eb3 434 amx_StrLen(amx_Address(amx,param),&result##_length_); \
tylerwilson 0:3ab1d2d14eb3 435 if (result##_length_>0 && \
tylerwilson 0:3ab1d2d14eb3 436 ((result)=(type)alloca((result##_length_+1)*sizeof(*(result))))!=NULL) \
tylerwilson 0:3ab1d2d14eb3 437 amx_GetString((char*)(result),amx_Address(amx,param), \
tylerwilson 0:3ab1d2d14eb3 438 sizeof(*(result))>1,result##_length_+1); \
tylerwilson 0:3ab1d2d14eb3 439 else (result) = NULL; \
tylerwilson 0:3ab1d2d14eb3 440 } while (0)
tylerwilson 0:3ab1d2d14eb3 441 #define amx_StrParam(amx,param,result) \
tylerwilson 0:3ab1d2d14eb3 442 amx_StrParam_Type(amx,param,result,void*)
tylerwilson 0:3ab1d2d14eb3 443 #endif
tylerwilson 0:3ab1d2d14eb3 444
tylerwilson 0:3ab1d2d14eb3 445 uint16_t * AMXAPI amx_Align16(uint16_t *v);
tylerwilson 0:3ab1d2d14eb3 446 uint32_t * AMXAPI amx_Align32(uint32_t *v);
tylerwilson 0:3ab1d2d14eb3 447 #if defined _I64_MAX || defined INT64_MAX || defined HAVE_I64
tylerwilson 0:3ab1d2d14eb3 448 uint64_t * AMXAPI amx_Align64(uint64_t *v);
tylerwilson 0:3ab1d2d14eb3 449 #endif
tylerwilson 0:3ab1d2d14eb3 450 int AMXAPI amx_Allot(AMX *amx, int cells, cell **address);
tylerwilson 0:3ab1d2d14eb3 451 int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, const cell *params);
tylerwilson 0:3ab1d2d14eb3 452 int AMXAPI amx_Cleanup(AMX *amx);
tylerwilson 0:3ab1d2d14eb3 453 int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data);
tylerwilson 0:3ab1d2d14eb3 454 int AMXAPI amx_Exec(AMX *amx, cell *retval, int index);
tylerwilson 0:3ab1d2d14eb3 455 int AMXAPI amx_FindNative(AMX *amx, const char *name, int *index);
tylerwilson 0:3ab1d2d14eb3 456 int AMXAPI amx_FindPublic(AMX *amx, const char *name, int *index);
tylerwilson 0:3ab1d2d14eb3 457 int AMXAPI amx_FindPubVar(AMX *amx, const char *name, cell **address);
tylerwilson 0:3ab1d2d14eb3 458 int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname);
tylerwilson 0:3ab1d2d14eb3 459 int AMXAPI amx_Flags(AMX *amx,uint16_t *flags);
tylerwilson 0:3ab1d2d14eb3 460 int AMXAPI amx_GetNative(AMX *amx, int index, char *name);
tylerwilson 0:3ab1d2d14eb3 461 int AMXAPI amx_GetPublic(AMX *amx, int index, char *name, ucell *address);
tylerwilson 0:3ab1d2d14eb3 462 int AMXAPI amx_GetPubVar(AMX *amx, int index, char *name, cell **address);
tylerwilson 0:3ab1d2d14eb3 463 int AMXAPI amx_GetString(char *dest,const cell *source, int use_wchar, size_t size);
tylerwilson 0:3ab1d2d14eb3 464 int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id);
tylerwilson 0:3ab1d2d14eb3 465 int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr);
tylerwilson 0:3ab1d2d14eb3 466 int AMXAPI amx_Init(AMX *amx, void *program);
tylerwilson 0:3ab1d2d14eb3 467 int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code);
tylerwilson 0:3ab1d2d14eb3 468 int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap);
tylerwilson 0:3ab1d2d14eb3 469 int AMXAPI amx_NameLength(AMX *amx, int *length);
tylerwilson 0:3ab1d2d14eb3 470 AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(const char *name, AMX_NATIVE func);
tylerwilson 0:3ab1d2d14eb3 471 int AMXAPI amx_NumNatives(AMX *amx, int *number);
tylerwilson 0:3ab1d2d14eb3 472 int AMXAPI amx_NumPublics(AMX *amx, int *number);
tylerwilson 0:3ab1d2d14eb3 473 int AMXAPI amx_NumPubVars(AMX *amx, int *number);
tylerwilson 0:3ab1d2d14eb3 474 int AMXAPI amx_NumTags(AMX *amx, int *number);
tylerwilson 0:3ab1d2d14eb3 475 int AMXAPI amx_Push(AMX *amx, cell value);
tylerwilson 0:3ab1d2d14eb3 476 int AMXAPI amx_PushAddress(AMX *amx, cell *address);
tylerwilson 0:3ab1d2d14eb3 477 int AMXAPI amx_PushArray(AMX *amx, cell **address, const cell array[], int numcells);
tylerwilson 0:3ab1d2d14eb3 478 int AMXAPI amx_PushString(AMX *amx, cell **address, const char *string, int pack, int use_wchar);
tylerwilson 0:3ab1d2d14eb3 479 int AMXAPI amx_RaiseError(AMX *amx, int error);
tylerwilson 0:3ab1d2d14eb3 480 int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number);
tylerwilson 0:3ab1d2d14eb3 481 int AMXAPI amx_Release(AMX *amx, cell *address);
tylerwilson 0:3ab1d2d14eb3 482 int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback);
tylerwilson 0:3ab1d2d14eb3 483 int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug);
tylerwilson 0:3ab1d2d14eb3 484 int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar, size_t size);
tylerwilson 0:3ab1d2d14eb3 485 int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr);
tylerwilson 0:3ab1d2d14eb3 486 int AMXAPI amx_StrLen(const cell *cstring, int *length);
tylerwilson 0:3ab1d2d14eb3 487 int AMXAPI amx_UTF8Check(const char *string, int *length);
tylerwilson 0:3ab1d2d14eb3 488 int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value);
tylerwilson 0:3ab1d2d14eb3 489 int AMXAPI amx_UTF8Len(const cell *cstr, int *length);
tylerwilson 0:3ab1d2d14eb3 490 int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value);
tylerwilson 0:3ab1d2d14eb3 491
tylerwilson 0:3ab1d2d14eb3 492 #if PAWN_CELL_SIZE==16
tylerwilson 0:3ab1d2d14eb3 493 #define amx_AlignCell(v) amx_Align16(v)
tylerwilson 0:3ab1d2d14eb3 494 #elif PAWN_CELL_SIZE==32
tylerwilson 0:3ab1d2d14eb3 495 #define amx_AlignCell(v) amx_Align32(v)
tylerwilson 0:3ab1d2d14eb3 496 #elif PAWN_CELL_SIZE==64 && (defined _I64_MAX || defined INT64_MAX || defined HAVE_I64)
tylerwilson 0:3ab1d2d14eb3 497 #define amx_AlignCell(v) amx_Align64(v)
tylerwilson 0:3ab1d2d14eb3 498 #else
tylerwilson 0:3ab1d2d14eb3 499 #error Unsupported cell size
tylerwilson 0:3ab1d2d14eb3 500 #endif
tylerwilson 0:3ab1d2d14eb3 501
tylerwilson 0:3ab1d2d14eb3 502 #define amx_RegisterFunc(amx, name, func) \
tylerwilson 0:3ab1d2d14eb3 503 amx_Register((amx), amx_NativeInfo((name),(func)), 1);
tylerwilson 0:3ab1d2d14eb3 504
tylerwilson 0:3ab1d2d14eb3 505 #if !defined AMX_NO_ALIGN
tylerwilson 0:3ab1d2d14eb3 506 #if defined __LINUX__ || defined __FreeBSD__
tylerwilson 0:3ab1d2d14eb3 507 #pragma pack() /* reset default packing */
tylerwilson 0:3ab1d2d14eb3 508 #elif defined MACOS && defined __MWERKS__
tylerwilson 0:3ab1d2d14eb3 509 #pragma options align=reset
tylerwilson 0:3ab1d2d14eb3 510 #else
tylerwilson 0:3ab1d2d14eb3 511 #pragma pack(pop) /* reset previous packing */
tylerwilson 0:3ab1d2d14eb3 512 #endif
tylerwilson 0:3ab1d2d14eb3 513 #endif
tylerwilson 0:3ab1d2d14eb3 514
tylerwilson 0:3ab1d2d14eb3 515 #ifdef __cplusplus
tylerwilson 0:3ab1d2d14eb3 516 }
tylerwilson 0:3ab1d2d14eb3 517 #endif
tylerwilson 0:3ab1d2d14eb3 518
tylerwilson 0:3ab1d2d14eb3 519 #endif /* AMX_H_INCLUDED */