home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff236.lzh / XprZmodem / protolib.c < prev    next >
C/C++ Source or Header  |  1989-08-09  |  3KB  |  156 lines

  1. /** protolib.c
  2. *
  3. *   DESCRIPTION:
  4. *   ===========
  5. *
  6. *    An exec library compiled with Aztec 3.40b, small model.
  7. *
  8. *    Based on "elib", an example library:
  9. *    created by jim mackraz using mylib.asm by neil katin.
  10. *    May be used and distributed providing this comment block
  11. *    is retained in the source code.
  12. *
  13. *   THIS VERSION:
  14. *   ============
  15. *
  16. *
  17. *    This version implements a protocol transfer handler.
  18. *    This file only handles the calls to Open, Close and Expunge.
  19. *
  20. *   AUTHOR/DATE:  W.G.J. Langeveld, February 1989.
  21. *   ============
  22. *
  23. **/
  24.  
  25. #include "protolib.h"
  26.  
  27. extern PFL   libfunctab[];   /* XPR function table (libface.asm)     */
  28. extern LONG  funkyInit();    /* hacked up version of Aztec crt0.a68   */
  29.  
  30. LONG XPRExpunge();
  31.  
  32. struct InitTable XPRInitTab =  {
  33.    sizeof (struct XPRBase),
  34.    libfunctab,
  35.    NULL,                     /* will initialize XPR data in funkymain() */
  36.    funkyInit
  37. };
  38.  
  39. extern UWORD XPRrevision;
  40.  
  41. extern char XPRname[];
  42. extern char XPRid[];
  43. extern struct Resident XPRRomTag;
  44.  
  45. unsigned long XPRO = ('X' << 24) | ('P' << 16) | ('R' << 8) | 'O';
  46.  
  47. /**
  48. *
  49. *   This function is Jim's C-language library initRoutine.  It is called
  50. *   by funkyInit() after register saves and small model initialization is
  51. *   done.
  52. *
  53. **/
  54. LONG funkymain(libbase, seglist)
  55. struct XPRBase *libbase;
  56. ULONG seglist;
  57. {
  58.    register   struct XPRBase *base;
  59. /*
  60. *   Cookie
  61. */
  62.    base = libbase;
  63. /*
  64. *   Debug kind of stuff
  65. */
  66.    base->mb_Cookie = XPRO;
  67.    base->mb_SegList = seglist;
  68. /*
  69. *   init. library structure (since I don't do automatic data init.)
  70. */
  71.    base->mb_Lib.lib_Node.ln_Type = NT_LIBRARY;
  72.    base->mb_Lib.lib_Node.ln_Name = (char *) XPRname;   
  73.    base->mb_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
  74.    base->mb_Lib.lib_Version = XPRRomTag.rt_Version;
  75.    base->mb_Lib.lib_Revision = XPRrevision;
  76.    base->mb_Lib.lib_IdString = (APTR) XPRid;
  77.  
  78.    return;
  79. }
  80.  
  81.  
  82. /**
  83. *
  84. *   Open library. Baseptr in A6, version in D0.
  85. *
  86. **/
  87. LONG XPROpen(base)
  88. struct XPRBase *base;
  89. {
  90. /*
  91. *   mark us as having another customer
  92. */
  93.    base->mb_Lib.lib_OpenCnt++;
  94. /*
  95. *   prevent delayed expunges (standard procedure)
  96. */
  97.    base->mb_Lib.lib_Flags &= ~LIBF_DELEXP;
  98.  
  99.    return ((LONG) base);
  100. }
  101.  
  102. /**
  103. *
  104. *   Close library
  105. *
  106. **/
  107. LONG XPRClose(base)
  108. struct XPRBase *base;
  109. {
  110.    LONG retval = 0;
  111.  
  112.    if ((--base->mb_Lib.lib_OpenCnt == 0) &&
  113.          (base->mb_Lib.lib_Flags & LIBF_DELEXP)) {
  114. /*
  115. *   No more people have me open,
  116. *   and I have a delayed expunge pending:
  117. *   return segment list.
  118. */
  119.       retval = XPRExpunge();
  120.    }
  121.  
  122.    return (retval);
  123. }
  124.  
  125. /**
  126. *
  127. *   Expunge library
  128. *
  129. **/
  130. LONG XPRExpunge(base)
  131. struct XPRBase *base;
  132. {
  133.    ULONG seglist = 0;
  134.    LONG libsize;
  135.  
  136.    if (base->mb_Lib.lib_OpenCnt == 0) {
  137. /*
  138. *   Really expunge: remove libbase and freemem
  139. */
  140.       seglist   = base->mb_SegList;
  141.  
  142.       Remove(base);
  143.  
  144.       libsize = base->mb_Lib.lib_NegSize + base->mb_Lib.lib_PosSize;
  145.  
  146.       FreeMem((char *) base - base->mb_Lib.lib_NegSize, (LONG) libsize);
  147.    }
  148.    else {
  149.       base->mb_Lib.lib_Flags |= LIBF_DELEXP;
  150.    }
  151. /*
  152. *   Return NULL or real seglist
  153. */
  154.    return ((LONG) seglist);
  155. }
  156.