home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / ixnet / ixnet_init.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  2KB  |  95 lines

  1. /*
  2.  *  This file is part of ixnet.library for the Amiga.
  3.  *  Copyright (C) 1996 by Jeff Shepherd
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  $Id:$
  20.  *
  21.  *  $Log:$
  22.  *
  23.  */
  24.  
  25. #define _KERNEL
  26. #include "ixnet.h"
  27. #include "kprintf.h"
  28.  
  29. #include <exec/memory.h>
  30. #include <dos/var.h>
  31.  
  32. #include <string.h>
  33. #include <unistd.h>
  34.  
  35. /* not changed after the library is initialized */
  36. struct ixnet_base        *ixnetbase = NULL;
  37. struct ixemul_base        *ixemulbase = NULL;
  38. struct ExecBase         *SysBase = NULL;
  39. struct DosLibrary        *DOSBase = NULL;
  40.  
  41. static struct
  42. {
  43.   void **base;
  44.   char *name;
  45. }
  46. ix_libs[] =
  47. {
  48.   { (void **)&DOSBase, "dos.library" },
  49.   { NULL, NULL }
  50. };
  51.  
  52.  
  53. int open_libraries(void)
  54. {
  55.   int i;
  56.  
  57.   for (i = 0; ix_libs[i].base; i++)
  58.     if (!(*(ix_libs[i].base) = (void *)OpenLibrary(ix_libs[i].name, 0)))
  59.       {
  60.     return 0;
  61.       }
  62.   return 1;
  63. }
  64.  
  65. void close_libraries(void)
  66. {
  67.   int i;
  68.  
  69.   for (i = 0; ix_libs[i].base; i++)
  70.     if (*ix_libs[i].base)
  71.       CloseLibrary(*ix_libs[i].base);
  72. }
  73.  
  74.  
  75. struct ixnet_base *ixnet_init (struct ixnet_base *ixbase)
  76. {
  77.   /* First set SysBase, because it is used by the 'u' macro. The Enforcer
  78.      manual recommends caching ExecBase because low-memory accesses are slower
  79.      when using Enforcer, besides the extra penalty of being in CHIP memory.
  80.      Also, lots of accesses to address 4 can hurt interrupt performance. */
  81.   SysBase = *(struct ExecBase **)4;
  82.   ixnetbase = ixbase;
  83.  
  84.   /* This can't go here since we are running as ramlib */
  85.   /* ixemulbase = u.u_ixbase; */
  86.  
  87.   if (!open_libraries())
  88.     {
  89.       close_libraries();
  90.       return 0;
  91.     }
  92.   return ixbase;
  93. }
  94.  
  95.