#include <sys/cdefs.h>
#include <inline/stubs.h>

__BEGIN_DECLS

#ifndef BASE_EXT_DECL
#define BASE_EXT_DECL extern struct ExecBase * SysBase;
#endif
#ifndef BASE_PAR_DECL
#define BASE_PAR_DECL
#define BASE_PAR_DECL0 void
#endif
#ifndef BASE_NAME
#define BASE_NAME SysBase
#endif

static __inline APTR 
AllocMem (BASE_PAR_DECL unsigned long byteSize,unsigned long requirements)
{
  BASE_EXT_DECL
  register APTR  _res  __asm("d0");
  register struct ExecBase *a6 __asm("a6") = BASE_NAME;
  register unsigned long d0 __asm("d0") = byteSize;
  register unsigned long d1 __asm("d1") = requirements;
  __asm __volatile ("jsr a6@(-0xc6)"
  : "=r" (_res)
  : "r" (a6), "r" (d0), "r" (d1)
  : "a0","a1","d0","d1", "memory");
  return _res;
}

static __inline APTR 
AllocVec (BASE_PAR_DECL unsigned long byteSize,unsigned long requirements)
{
  BASE_EXT_DECL
  register APTR  _res  __asm("d0");
  register struct ExecBase *a6 __asm("a6") = BASE_NAME;
  register unsigned long d0 __asm("d0") = byteSize;
  register unsigned long d1 __asm("d1") = requirements;
  __asm __volatile ("jsr a6@(-0x2ac)"
  : "=r" (_res)
  : "r" (a6), "r" (d0), "r" (d1)
  : "a0","a1","d0","d1", "memory");
  return _res;
}

static __inline void 
CloseLibrary (BASE_PAR_DECL struct Library *library)
{
  BASE_EXT_DECL
  register struct ExecBase *a6 __asm("a6") = BASE_NAME;
  register struct Library *a1 __asm("a1") = library;
  __asm __volatile ("jsr a6@(-0x19e)"
  : /* no output */
  : "r" (a6), "r" (a1)
  : "a0","a1","d0","d1", "memory");
}

static __inline void 
FreeMem (BASE_PAR_DECL APTR memoryBlock,unsigned long byteSize)
{
  BASE_EXT_DECL
  register struct ExecBase *a6 __asm("a6") = BASE_NAME;
  register APTR a1 __asm("a1") = memoryBlock;
  register unsigned long d0 __asm("d0") = byteSize;
  __asm __volatile ("jsr a6@(-0xd2)"
  : /* no output */
  : "r" (a6), "r" (a1), "r" (d0)
  : "a0","a1","d0","d1", "memory");
}

static __inline struct Library *
OpenLibrary (BASE_PAR_DECL UBYTE *libName,unsigned long version)
{
  BASE_EXT_DECL
  register struct Library * _res  __asm("d0");
  register struct ExecBase *a6 __asm("a6") = BASE_NAME;
  register UBYTE *a1 __asm("a1") = libName;
  register unsigned long d0 __asm("d0") = version;
  __asm __volatile ("jsr a6@(-0x228)"
  : "=r" (_res)
  : "r" (a6), "r" (a1), "r" (d0)
  : "a0","a1","d0","d1", "memory");
  return _res;
}

#undef BASE_EXT_DECL
#undef BASE_PAR_DECL
#undef BASE_PAR_DECL0
#undef BASE_NAME

#ifndef BASE_EXT_DECL
#define BASE_EXT_DECL extern struct IntuitionBase*  IntuitionBase;
#endif
#ifndef BASE_PAR_DECL
#define BASE_PAR_DECL
#define BASE_PAR_DECL0 void
#endif
#ifndef BASE_NAME
#define BASE_NAME IntuitionBase
#endif

static __inline LONG 
GetScreenData (BASE_PAR_DECL APTR buffer,unsigned long size,unsigned long type,struct Screen *screen)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct IntuitionBase* a6 __asm("a6") = BASE_NAME;
  register APTR a0 __asm("a0") = buffer;
  register unsigned long d0 __asm("d0") = size;
  register unsigned long d1 __asm("d1") = type;
  register struct Screen *a1 __asm("a1") = screen;
  __asm __volatile ("jsr a6@(-0x1aa)"
  : "=r" (_res)
  : "r" (a6), "r" (a0), "r" (d0), "r" (d1), "r" (a1)
  : "a0","a1","d0","d1", "memory");
  return _res;
}

#undef BASE_EXT_DECL
#undef BASE_PAR_DECL
#undef BASE_PAR_DECL0
#undef BASE_NAME

#ifndef BASE_EXT_DECL
#define BASE_EXT_DECL extern struct GfxBase*  GfxBase;
#endif
#ifndef BASE_PAR_DECL
#define BASE_PAR_DECL
#define BASE_PAR_DECL0 void
#endif
#ifndef BASE_NAME
#define BASE_NAME GfxBase
#endif

static __inline void 
InitBitMap (BASE_PAR_DECL struct BitMap *bitMap,long depth,long width,long height)
{
  BASE_EXT_DECL
  register struct GfxBase* a6 __asm("a6") = BASE_NAME;
  register struct BitMap *a0 __asm("a0") = bitMap;
  register long d0 __asm("d0") = depth;
  register long d1 __asm("d1") = width;
  register long d2 __asm("d2") = height;
  __asm __volatile ("jsr a6@(-0x186)"
  : /* no output */
  : "r" (a6), "r" (a0), "r" (d0), "r" (d1), "r" (d2)
  : "a0","a1","d0","d1","d2", "memory");
}

#undef BASE_EXT_DECL
#undef BASE_PAR_DECL
#undef BASE_PAR_DECL0
#undef BASE_NAME

#ifndef BASE_EXT_DECL
#define BASE_EXT_DECL extern struct DosLibrary * DOSBase;
#endif
#ifndef BASE_PAR_DECL
#define BASE_PAR_DECL
#define BASE_PAR_DECL0 void
#endif
#ifndef BASE_NAME
#define BASE_NAME DOSBase
#endif

static __inline void 
FreeArgs (BASE_PAR_DECL struct RDArgs *args)
{
  BASE_EXT_DECL
  register struct DosLibrary *a6 __asm("a6") = BASE_NAME;
  register struct RDArgs *d1 __asm("d1") = args;
  __asm __volatile ("jsr a6@(-0x35a)"
  : /* no output */
  : "r" (a6), "r" (d1)
  : "a0","a1","d0","d1", "memory");
}

static __inline struct RDArgs *
ReadArgs (BASE_PAR_DECL STRPTR arg_template,LONG *array,struct RDArgs *args)
{
  BASE_EXT_DECL
  register struct RDArgs * _res  __asm("d0");
  register struct DosLibrary *a6 __asm("a6") = BASE_NAME;
  register STRPTR d1 __asm("d1") = arg_template;
  register LONG *d2 __asm("d2") = array;
  register struct RDArgs *d3 __asm("d3") = args;
  __asm __volatile ("jsr a6@(-0x31e)"
  : "=r" (_res)
  : "r" (a6), "r" (d1), "r" (d2), "r" (d3)
  : "a0","a1","d0","d1","d2","d3", "memory");
  return _res;
}

#undef BASE_EXT_DECL
#undef BASE_PAR_DECL
#undef BASE_PAR_DECL0
#undef BASE_NAME

#ifndef BASE_EXT_DECL
#define BASE_EXT_DECL extern struct Library * LocaleBase;
#endif
#ifndef BASE_PAR_DECL
#define BASE_PAR_DECL
#define BASE_PAR_DECL0 void
#endif
#ifndef BASE_NAME
#define BASE_NAME LocaleBase
#endif

static __inline void 
CloseLocale (BASE_PAR_DECL struct Locale * locale)
{
  BASE_EXT_DECL
  register struct Library * a6 __asm("a6") = BASE_NAME;
  register struct Locale *a0 __asm("a0") = locale;
  __asm __volatile ("jsr a6@(-0x2a)"
  : /* no output */
  : "r" (a6), "r" (a0)
  : "a0","a1","d0","d1", "memory");
}

static __inline struct Locale *
OpenLocale (BASE_PAR_DECL STRPTR name)
{
  BASE_EXT_DECL
  register struct Locale * _res  __asm("d0");
  register struct Library * a6 __asm("a6") = BASE_NAME;
  register STRPTR a0 __asm("a0") = name;
  __asm __volatile ("jsr a6@(-0x9c)"
  : "=r" (_res)
  : "r" (a6), "r" (a0)
  : "a0","a1","d0","d1", "memory");
  return _res;
}

#undef BASE_EXT_DECL
#undef BASE_PAR_DECL
#undef BASE_PAR_DECL0
#undef BASE_NAME

__END_DECLS
