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)

osdefs.h

Committer:
Lobo
Date:
2013-05-24
Revision:
3:185fdbb7ccf0
Parent:
2:01588bd27169

File content as of revision 3:185fdbb7ccf0:

/*
 * Platform
 *   __MSDOS__    set when compiling for DOS (not Windows)
 *   _Windows     set when compiling for any version of Microsoft Windows
 *   __WIN32__    set when compiling for Windows95 or WindowsNT (32 bit mode)
 *   __32BIT__    set when compiling in 32-bit "flat" mode (DOS, Windows, ARM)
 *   __64BIT__    set when compiling in 64-bit mode
 *   __ECOS__     set if Pawn was included with the eCos with configtool
 *   __LINUX__    set when compiling for Linux
 *
 * Copyright 1998-2011, ITB CompuPhase, The Netherlands.
 * No usage restrictions, no warranties.
 */

#ifndef _OSDEFS_H
#define _OSDEFS_H

/* Every compiler uses different "default" macros to indicate the mode
 * it is in. Throughout the source, we use the Borland C++ macros, so
 * the macros of Watcom C/C++ and Microsoft Visual C/C++ are mapped to
 * those of Borland C++.
 */
#if defined(__WATCOMC__)
  #if defined(__WINDOWS__) || defined(__NT__)
    #define _Windows    1
  #endif
  #if defined(__386__) || defined(__NT__)
    #define __32BIT__   1
  #endif
  #if defined(_Windows) && defined(__32BIT__)
    #define __WIN32__   1
  #endif
#elif defined(_MSC_VER)
  #if defined(_WINDOWS) || defined(_WIN32)
    #define _Windows    1
  #endif
  #if defined(_WIN32)
    #define __WIN32__   1
    #define __32BIT__   1
  #endif
#elif defined __arm__
  #define __32BIT__     1
#elif defined __AVR__
  #define __16BIT__     1
#endif
#if !defined __16BIT__ && !defined __32BIT__ && !defined __64BIT__
  #define __32BIT__     1
#endif

#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24)
    // no Unicode support, so force only ANSI
    #define AMX_ANSIONLY 1
    // No dynamically loaded module
    #define AMX_NODYNALOAD 1
    // use the simplest Console I/O type - serial terminal
    #define AMX_TERMINAL 1
    // If we get the core VM working with RVDS assember, this will speed things up
//    #define AMX_ASM 1
    // for the amxtime module. On Linux, stime is the standard set time call. On mbed,
    // it is set_time. Fortunately, they both take the same param - seconds since 01/01/70 
    #define stime(x) set_time(x)
#endif

#if (defined __linux || defined __linux__) && !defined __LINUX__
  #define __LINUX__
#endif
/* To be able to eventually set __ECOS__, we have to find a symbol
 * defined in a common place (so including the header file won't break
 * anything for other platforms). <sys/types.h> includes
 * <pkgconf/system.h> and in this later file we can find CYGPKG_PAWN
 * if the Pawn package was included with configtool and so we know
 * that we are compiling for eCos.
 */
#if defined CCSINFO
  #include <sys/types.h>
#endif
#if defined CYGPKG_PAWN
  #define __ECOS__      1
  #define HAVE_ALLOCA_H 0
#endif


#if defined __FreeBSD__
  #include <sys/endian.h>
#elif defined __LINUX__
  #include <endian.h>
#elif defined __ECOS__
  #include <cyg/hal/hal_endian.h>
  #define BIG_ENDIAN    4321
  #define LITTLE_ENDIAN 1234
  #if (CYG_BYTEORDER == CYG_LSBFIRST)
  #define BYTE_ORDER  LITTLE_ENDIAN
  #else
    #define BYTE_ORDER  BIG_ENDIAN
  #endif
   /*
    * eCos option management.
    */
  #include <pkgconf/pawn.h>
  #if CYGPKG_PAWN_AMX_ANSIONLY==1
    #define AMX_ANSIONLY
  #endif
  #define PAWN_CELL_SIZE CYGPKG_PAWN_AMX_CELLSIZE
  #if CYGPKG_PAWN_CORE_RANDOM==0
    #define AMX_NORANDOM
  #endif
  #if CYGPKG_PAWN_CORE_PROPERTY==0
    #define AMX_NOPROPLIST
  #endif
  #if CYGPKG_PAWN_AMX_CONS_FIXEDPOINT==1
    #define FIXEDPOINT
  #endif
  #if CYGPKG_PAWN_AMX_CONS_FLOATPOINT==1
    #define FLOATPOINT
  #endif
#endif

/* Linux now has these */
#if !defined BIG_ENDIAN
  #define BIG_ENDIAN    4321
#endif
#if !defined LITTLE_ENDIAN
  #define LITTLE_ENDIAN 1234
#endif

/* educated guess, BYTE_ORDER is undefined, i386 is common => little endian */
#if !defined BYTE_ORDER
  #if defined UCLINUX
    #define BYTE_ORDER BIG_ENDIAN
  #else
    #define BYTE_ORDER LITTLE_ENDIAN
  #endif
#endif

#if defined __MSDOS__ || defined __WIN32__ || defined _Windows
  #define DIRSEP_CHAR '\\'
#elif defined macintosh || defined __APPLE__
  #define DIRSEP_CHAR ':'
#else
  #define DIRSEP_CHAR '/'   /* directory separator character */
#endif

/* _MAX_PATH is sometimes called differently and it may be in limits.h or
 * stdlib.h instead of stdio.h.
 */
#if !defined _MAX_PATH
  /* not defined, perhaps stdio.h was not included */
  #if !defined PATH_MAX
    #include <stdio.h>
  #endif
  #if !defined _MAX_PATH && !defined PATH_MAX
    /* no _MAX_PATH and no MAX_PATH, perhaps it is in limits.h */
    #include <limits.h>
  #endif
  #if !defined _MAX_PATH && !defined PATH_MAX
    /* no _MAX_PATH and no MAX_PATH, perhaps it is in stdlib.h */
    #include <stdlib.h>
  #endif
  /* if _MAX_PATH is undefined, try common alternative names */
  #if !defined _MAX_PATH
    #if defined MAX_PATH
      #define _MAX_PATH    MAX_PATH
    #elif defined _POSIX_PATH_MAX
      #define _MAX_PATH  _POSIX_PATH_MAX
    #else
      /* everything failed, actually we have a problem here... */
      #define _MAX_PATH  1024
    #endif
  #endif
#endif

#endif  /* _OSDEFS_H */