#ifndef _INLINE_XPK_H
#define _INLINE_XPK_H

#if __GNUC__ < 2
#error Bad luck guy, get a better compiler!
#endif

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

#include <stdarg.h>

__BEGIN_DECLS

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

/* ANSI-C wants a forward declaration for an unknown struct */
struct XpkFH;
#define XFH  struct XpkFH

static __inline LONG 
XpkClose (BASE_PAR_DECL XFH *xbuf)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct Library* a6 __asm("a6") = BASE_NAME;
  register XFH *a0 __asm("a0") = xbuf;
  __asm __volatile ("jsr a6@(-0x54)"
  : "=r" (_res)
  : "r" (a6), "r" (a0)
  : "a0","a1","d0","d1");
  *(char *)a0 = *(char *)a0;
  return _res;
}
static __inline LONG
XpkExamine (BASE_PAR_DECL XFIB *tag,TAGS *fib)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct Library* a6 __asm("a6") = BASE_NAME;
  register XFIB *a0 __asm("a0") = tag;
  register TAGS *a1 __asm("a1") = fib;
  __asm __volatile ("jsr a6@(-0x24)"
  : "=r" (_res)
  : "r" (a6), "r" (a0), "r" (a1)
  : "a0","a1","d0","d1");
  *(char *)a0 = *(char *)a0;  *(char *)a1 = *(char *)a1;
  return _res;
}
static __inline LONG 
XpkOpen (BASE_PAR_DECL XFH **xbuf,TAGS *tags)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct Library* a6 __asm("a6") = BASE_NAME;
  register XFH **a0 __asm("a0") = xbuf;
  register TAGS *a1 __asm("a1") = tags;
  __asm __volatile ("jsr a6@(-0x36)"
  : "=r" (_res)
  : "r" (a6), "r" (a0), "r" (a1)
  : "a0","a1","d0","d1");
  *(char *)a0 = *(char *)a0;  *(char *)a1 = *(char *)a1;
  return _res;
}
static __inline LONG 
XpkPack (BASE_PAR_DECL TAGS *tags)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct Library* a6 __asm("a6") = BASE_NAME;
  register TAGS *a0 __asm("a0") = tags;
  __asm __volatile ("jsr a6@(-0x2a)"
  : "=r" (_res)
  : "r" (a6), "r" (a0)
  : "a0","a1","d0","d1");
  *(char *)a0 = *(char *)a0;
  return _res;
}
static __inline LONG 
XpkRead (BASE_PAR_DECL XFH *xbuf,UBYTE *buf,LONG len)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct Library* a6 __asm("a6") = BASE_NAME;
  register XFH *a0 __asm("a0") = xbuf;
  register UBYTE *a1 __asm("a1") = buf;
  register LONG d0 __asm("d0") = len;
  __asm __volatile ("jsr a6@(-0x3c)"
  : "=r" (_res)
  : "r" (a6), "r" (a0), "r" (a1), "r" (d0)
  : "a0","a1","d0","d1");
  *(char *)a0 = *(char *)a0;  *(char *)a1 = *(char *)a1;
  return _res;
}
static __inline LONG 
XpkSeek (BASE_PAR_DECL XFH *xbuf,LONG len,LONG mode)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct Library* a6 __asm("a6") = BASE_NAME;
  register XFH *a0 __asm("a0") = xbuf;
  register LONG d0 __asm("d0") = len;
  register LONG d1 __asm("d1") = mode;
  __asm __volatile ("jsr a6@(-0x48)"
  : "=r" (_res)
  : "r" (a6), "r" (a0), "r" (d0), "r" (d1)
  : "a0","a1","d0","d1");
  *(char *)a0 = *(char *)a0;
  return _res;
}
static __inline LONG 
XpkUnpack (BASE_PAR_DECL TAGS *tags)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct Library* a6 __asm("a6");
  register TAGS *a0 __asm("a0");

  a6 = BASE_NAME;
  a0  = tags;
  __asm __volatile ("jsr a6@(-0x30)"
  : "=r" (_res)
  : "r" (a6), "r" (a0)
  : "a0","a1","d0","d1");
  *(char *)a0 = *(char *)a0;
  return _res;
}
static __inline LONG 
XpkWrite (BASE_PAR_DECL XFH *xbuf,UBYTE *buf,LONG len)
{
  BASE_EXT_DECL
  register LONG  _res  __asm("d0");
  register struct Library* a6 __asm("a6") = BASE_NAME;
  register XFH *a0 __asm("a0") = xbuf;
  register UBYTE *a1 __asm("a1") = buf;
  register LONG d0 __asm("d0") = len;
  __asm __volatile ("jsr a6@(-0x42)"
  : "=r" (_res)
  : "r" (a6), "r" (a0), "r" (a1), "r" (d0)
  : "a0","a1","d0","d1");
  *(char *)a0 = *(char *)a0;  *(char *)a1 = *(char *)a1;
  return _res;
}

/* those two are not really inlineable, because they take varargs parameter.
   Well... perhaps they can be inlined some day .. */

#ifndef NO_VARARGS_INLINE

static __inline LONG 
XpkPackTags (ULONG tag, ...)
{
  return XpkPack ((struct TagItem *) & tag);
}

static __inline LONG 
XpkUnpackTags (ULONG tag, ...)
{
  return XpkUnpack ((struct TagItem *) & tag);
}

#endif

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

__END_DECLS

#endif /* _INLINE_XPK_H */
