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/
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)
osdefs.h@0:3ab1d2d14eb3, 2012-11-15 (annotated)
- Committer:
- tylerwilson
- Date:
- Thu Nov 15 17:41:21 2012 +0000
- Revision:
- 0:3ab1d2d14eb3
- Child:
- 1:cc719e522b5d
Initial Pawn 4.x interpreter for mbed check-in
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tylerwilson | 0:3ab1d2d14eb3 | 1 | /* |
tylerwilson | 0:3ab1d2d14eb3 | 2 | * Platform |
tylerwilson | 0:3ab1d2d14eb3 | 3 | * __MSDOS__ set when compiling for DOS (not Windows) |
tylerwilson | 0:3ab1d2d14eb3 | 4 | * _Windows set when compiling for any version of Microsoft Windows |
tylerwilson | 0:3ab1d2d14eb3 | 5 | * __WIN32__ set when compiling for Windows95 or WindowsNT (32 bit mode) |
tylerwilson | 0:3ab1d2d14eb3 | 6 | * __32BIT__ set when compiling in 32-bit "flat" mode (DOS, Windows, ARM) |
tylerwilson | 0:3ab1d2d14eb3 | 7 | * __64BIT__ set when compiling in 64-bit mode |
tylerwilson | 0:3ab1d2d14eb3 | 8 | * __ECOS__ set if Pawn was included with the eCos with configtool |
tylerwilson | 0:3ab1d2d14eb3 | 9 | * __LINUX__ set when compiling for Linux |
tylerwilson | 0:3ab1d2d14eb3 | 10 | * |
tylerwilson | 0:3ab1d2d14eb3 | 11 | * Copyright 1998-2011, ITB CompuPhase, The Netherlands. |
tylerwilson | 0:3ab1d2d14eb3 | 12 | * No usage restrictions, no warranties. |
tylerwilson | 0:3ab1d2d14eb3 | 13 | */ |
tylerwilson | 0:3ab1d2d14eb3 | 14 | |
tylerwilson | 0:3ab1d2d14eb3 | 15 | #ifndef _OSDEFS_H |
tylerwilson | 0:3ab1d2d14eb3 | 16 | #define _OSDEFS_H |
tylerwilson | 0:3ab1d2d14eb3 | 17 | |
tylerwilson | 0:3ab1d2d14eb3 | 18 | /* Every compiler uses different "default" macros to indicate the mode |
tylerwilson | 0:3ab1d2d14eb3 | 19 | * it is in. Throughout the source, we use the Borland C++ macros, so |
tylerwilson | 0:3ab1d2d14eb3 | 20 | * the macros of Watcom C/C++ and Microsoft Visual C/C++ are mapped to |
tylerwilson | 0:3ab1d2d14eb3 | 21 | * those of Borland C++. |
tylerwilson | 0:3ab1d2d14eb3 | 22 | */ |
tylerwilson | 0:3ab1d2d14eb3 | 23 | #if defined(__WATCOMC__) |
tylerwilson | 0:3ab1d2d14eb3 | 24 | #if defined(__WINDOWS__) || defined(__NT__) |
tylerwilson | 0:3ab1d2d14eb3 | 25 | #define _Windows 1 |
tylerwilson | 0:3ab1d2d14eb3 | 26 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 27 | #if defined(__386__) || defined(__NT__) |
tylerwilson | 0:3ab1d2d14eb3 | 28 | #define __32BIT__ 1 |
tylerwilson | 0:3ab1d2d14eb3 | 29 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 30 | #if defined(_Windows) && defined(__32BIT__) |
tylerwilson | 0:3ab1d2d14eb3 | 31 | #define __WIN32__ 1 |
tylerwilson | 0:3ab1d2d14eb3 | 32 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 33 | #elif defined(_MSC_VER) |
tylerwilson | 0:3ab1d2d14eb3 | 34 | #if defined(_WINDOWS) || defined(_WIN32) |
tylerwilson | 0:3ab1d2d14eb3 | 35 | #define _Windows 1 |
tylerwilson | 0:3ab1d2d14eb3 | 36 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 37 | #if defined(_WIN32) |
tylerwilson | 0:3ab1d2d14eb3 | 38 | #define __WIN32__ 1 |
tylerwilson | 0:3ab1d2d14eb3 | 39 | #define __32BIT__ 1 |
tylerwilson | 0:3ab1d2d14eb3 | 40 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 41 | #elif defined __arm__ |
tylerwilson | 0:3ab1d2d14eb3 | 42 | #define __32BIT__ 1 |
tylerwilson | 0:3ab1d2d14eb3 | 43 | #elif defined __AVR__ |
tylerwilson | 0:3ab1d2d14eb3 | 44 | #define __16BIT__ 1 |
tylerwilson | 0:3ab1d2d14eb3 | 45 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 46 | #if !defined __16BIT__ && !defined __32BIT__ && !defined __64BIT__ |
tylerwilson | 0:3ab1d2d14eb3 | 47 | #define __32BIT__ 1 |
tylerwilson | 0:3ab1d2d14eb3 | 48 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 49 | |
tylerwilson | 0:3ab1d2d14eb3 | 50 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) |
tylerwilson | 0:3ab1d2d14eb3 | 51 | #define AMX_ANSIONLY 1 |
tylerwilson | 0:3ab1d2d14eb3 | 52 | #define AMX_NODYNALOAD 1 |
tylerwilson | 0:3ab1d2d14eb3 | 53 | #define AMX_TERMINAL 1 |
tylerwilson | 0:3ab1d2d14eb3 | 54 | |
tylerwilson | 0:3ab1d2d14eb3 | 55 | // #define TCHAR char |
tylerwilson | 0:3ab1d2d14eb3 | 56 | // #define __T(x) (x) |
tylerwilson | 0:3ab1d2d14eb3 | 57 | #define stime(x) (x) |
tylerwilson | 0:3ab1d2d14eb3 | 58 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 59 | |
tylerwilson | 0:3ab1d2d14eb3 | 60 | #if (defined __linux || defined __linux__) && !defined __LINUX__ |
tylerwilson | 0:3ab1d2d14eb3 | 61 | #define __LINUX__ |
tylerwilson | 0:3ab1d2d14eb3 | 62 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 63 | /* To be able to eventually set __ECOS__, we have to find a symbol |
tylerwilson | 0:3ab1d2d14eb3 | 64 | * defined in a common place (so including the header file won't break |
tylerwilson | 0:3ab1d2d14eb3 | 65 | * anything for other platforms). <sys/types.h> includes |
tylerwilson | 0:3ab1d2d14eb3 | 66 | * <pkgconf/system.h> and in this later file we can find CYGPKG_PAWN |
tylerwilson | 0:3ab1d2d14eb3 | 67 | * if the Pawn package was included with configtool and so we know |
tylerwilson | 0:3ab1d2d14eb3 | 68 | * that we are compiling for eCos. |
tylerwilson | 0:3ab1d2d14eb3 | 69 | */ |
tylerwilson | 0:3ab1d2d14eb3 | 70 | #if defined CCSINFO |
tylerwilson | 0:3ab1d2d14eb3 | 71 | #include <sys/types.h> |
tylerwilson | 0:3ab1d2d14eb3 | 72 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 73 | #if defined CYGPKG_PAWN |
tylerwilson | 0:3ab1d2d14eb3 | 74 | #define __ECOS__ 1 |
tylerwilson | 0:3ab1d2d14eb3 | 75 | #define HAVE_ALLOCA_H 0 |
tylerwilson | 0:3ab1d2d14eb3 | 76 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 77 | |
tylerwilson | 0:3ab1d2d14eb3 | 78 | |
tylerwilson | 0:3ab1d2d14eb3 | 79 | #if defined __FreeBSD__ |
tylerwilson | 0:3ab1d2d14eb3 | 80 | #include <sys/endian.h> |
tylerwilson | 0:3ab1d2d14eb3 | 81 | #elif defined __LINUX__ |
tylerwilson | 0:3ab1d2d14eb3 | 82 | #include <endian.h> |
tylerwilson | 0:3ab1d2d14eb3 | 83 | #elif defined __ECOS__ |
tylerwilson | 0:3ab1d2d14eb3 | 84 | #include <cyg/hal/hal_endian.h> |
tylerwilson | 0:3ab1d2d14eb3 | 85 | #define BIG_ENDIAN 4321 |
tylerwilson | 0:3ab1d2d14eb3 | 86 | #define LITTLE_ENDIAN 1234 |
tylerwilson | 0:3ab1d2d14eb3 | 87 | #if (CYG_BYTEORDER == CYG_LSBFIRST) |
tylerwilson | 0:3ab1d2d14eb3 | 88 | #define BYTE_ORDER LITTLE_ENDIAN |
tylerwilson | 0:3ab1d2d14eb3 | 89 | #else |
tylerwilson | 0:3ab1d2d14eb3 | 90 | #define BYTE_ORDER BIG_ENDIAN |
tylerwilson | 0:3ab1d2d14eb3 | 91 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 92 | /* |
tylerwilson | 0:3ab1d2d14eb3 | 93 | * eCos option management. |
tylerwilson | 0:3ab1d2d14eb3 | 94 | */ |
tylerwilson | 0:3ab1d2d14eb3 | 95 | #include <pkgconf/pawn.h> |
tylerwilson | 0:3ab1d2d14eb3 | 96 | #if CYGPKG_PAWN_AMX_ANSIONLY==1 |
tylerwilson | 0:3ab1d2d14eb3 | 97 | #define AMX_ANSIONLY |
tylerwilson | 0:3ab1d2d14eb3 | 98 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 99 | #define PAWN_CELL_SIZE CYGPKG_PAWN_AMX_CELLSIZE |
tylerwilson | 0:3ab1d2d14eb3 | 100 | #if CYGPKG_PAWN_CORE_RANDOM==0 |
tylerwilson | 0:3ab1d2d14eb3 | 101 | #define AMX_NORANDOM |
tylerwilson | 0:3ab1d2d14eb3 | 102 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 103 | #if CYGPKG_PAWN_CORE_PROPERTY==0 |
tylerwilson | 0:3ab1d2d14eb3 | 104 | #define AMX_NOPROPLIST |
tylerwilson | 0:3ab1d2d14eb3 | 105 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 106 | #if CYGPKG_PAWN_AMX_CONS_FIXEDPOINT==1 |
tylerwilson | 0:3ab1d2d14eb3 | 107 | #define FIXEDPOINT |
tylerwilson | 0:3ab1d2d14eb3 | 108 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 109 | #if CYGPKG_PAWN_AMX_CONS_FLOATPOINT==1 |
tylerwilson | 0:3ab1d2d14eb3 | 110 | #define FLOATPOINT |
tylerwilson | 0:3ab1d2d14eb3 | 111 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 112 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 113 | |
tylerwilson | 0:3ab1d2d14eb3 | 114 | /* Linux now has these */ |
tylerwilson | 0:3ab1d2d14eb3 | 115 | #if !defined BIG_ENDIAN |
tylerwilson | 0:3ab1d2d14eb3 | 116 | #define BIG_ENDIAN 4321 |
tylerwilson | 0:3ab1d2d14eb3 | 117 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 118 | #if !defined LITTLE_ENDIAN |
tylerwilson | 0:3ab1d2d14eb3 | 119 | #define LITTLE_ENDIAN 1234 |
tylerwilson | 0:3ab1d2d14eb3 | 120 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 121 | |
tylerwilson | 0:3ab1d2d14eb3 | 122 | /* educated guess, BYTE_ORDER is undefined, i386 is common => little endian */ |
tylerwilson | 0:3ab1d2d14eb3 | 123 | #if !defined BYTE_ORDER |
tylerwilson | 0:3ab1d2d14eb3 | 124 | #if defined UCLINUX |
tylerwilson | 0:3ab1d2d14eb3 | 125 | #define BYTE_ORDER BIG_ENDIAN |
tylerwilson | 0:3ab1d2d14eb3 | 126 | #else |
tylerwilson | 0:3ab1d2d14eb3 | 127 | #define BYTE_ORDER LITTLE_ENDIAN |
tylerwilson | 0:3ab1d2d14eb3 | 128 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 129 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 130 | |
tylerwilson | 0:3ab1d2d14eb3 | 131 | #if defined __MSDOS__ || defined __WIN32__ || defined _Windows |
tylerwilson | 0:3ab1d2d14eb3 | 132 | #define DIRSEP_CHAR '\\' |
tylerwilson | 0:3ab1d2d14eb3 | 133 | #elif defined macintosh || defined __APPLE__ |
tylerwilson | 0:3ab1d2d14eb3 | 134 | #define DIRSEP_CHAR ':' |
tylerwilson | 0:3ab1d2d14eb3 | 135 | #else |
tylerwilson | 0:3ab1d2d14eb3 | 136 | #define DIRSEP_CHAR '/' /* directory separator character */ |
tylerwilson | 0:3ab1d2d14eb3 | 137 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 138 | |
tylerwilson | 0:3ab1d2d14eb3 | 139 | /* _MAX_PATH is sometimes called differently and it may be in limits.h or |
tylerwilson | 0:3ab1d2d14eb3 | 140 | * stdlib.h instead of stdio.h. |
tylerwilson | 0:3ab1d2d14eb3 | 141 | */ |
tylerwilson | 0:3ab1d2d14eb3 | 142 | #if !defined _MAX_PATH |
tylerwilson | 0:3ab1d2d14eb3 | 143 | /* not defined, perhaps stdio.h was not included */ |
tylerwilson | 0:3ab1d2d14eb3 | 144 | #if !defined PATH_MAX |
tylerwilson | 0:3ab1d2d14eb3 | 145 | #include <stdio.h> |
tylerwilson | 0:3ab1d2d14eb3 | 146 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 147 | #if !defined _MAX_PATH && !defined PATH_MAX |
tylerwilson | 0:3ab1d2d14eb3 | 148 | /* no _MAX_PATH and no MAX_PATH, perhaps it is in limits.h */ |
tylerwilson | 0:3ab1d2d14eb3 | 149 | #include <limits.h> |
tylerwilson | 0:3ab1d2d14eb3 | 150 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 151 | #if !defined _MAX_PATH && !defined PATH_MAX |
tylerwilson | 0:3ab1d2d14eb3 | 152 | /* no _MAX_PATH and no MAX_PATH, perhaps it is in stdlib.h */ |
tylerwilson | 0:3ab1d2d14eb3 | 153 | #include <stdlib.h> |
tylerwilson | 0:3ab1d2d14eb3 | 154 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 155 | /* if _MAX_PATH is undefined, try common alternative names */ |
tylerwilson | 0:3ab1d2d14eb3 | 156 | #if !defined _MAX_PATH |
tylerwilson | 0:3ab1d2d14eb3 | 157 | #if defined MAX_PATH |
tylerwilson | 0:3ab1d2d14eb3 | 158 | #define _MAX_PATH MAX_PATH |
tylerwilson | 0:3ab1d2d14eb3 | 159 | #elif defined _POSIX_PATH_MAX |
tylerwilson | 0:3ab1d2d14eb3 | 160 | #define _MAX_PATH _POSIX_PATH_MAX |
tylerwilson | 0:3ab1d2d14eb3 | 161 | #else |
tylerwilson | 0:3ab1d2d14eb3 | 162 | /* everything failed, actually we have a problem here... */ |
tylerwilson | 0:3ab1d2d14eb3 | 163 | #define _MAX_PATH 1024 |
tylerwilson | 0:3ab1d2d14eb3 | 164 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 165 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 166 | #endif |
tylerwilson | 0:3ab1d2d14eb3 | 167 | |
tylerwilson | 0:3ab1d2d14eb3 | 168 | #endif /* _OSDEFS_H */ |