You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
318 lines
8.5 KiB
318 lines
8.5 KiB
/*- |
|
* Copyright (c) 2017-2021 Carsten Sonne Larsen <cs@innolan.net> |
|
* All rights reserved. |
|
* |
|
* Redistribution and use in source and binary forms, with or without |
|
* modification, are permitted provided that the following conditions |
|
* are met: |
|
* 1. Redistributions of source code must retain the above copyright |
|
* notice, this list of conditions and the following disclaimer. |
|
* 2. Redistributions in binary form must reproduce the above copyright |
|
* notice, this list of conditions and the following disclaimer in the |
|
* documentation and/or other materials provided with the distribution. |
|
* |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
* |
|
*/ |
|
|
|
#include "config.h" |
|
#include "global.h" |
|
#include "timer.h" |
|
#include "text.h" |
|
#include "ptz.h" |
|
#include "mem.h" |
|
|
|
#include <graphics/gfxbase.h> |
|
#include <libraries/dos.h> |
|
#include <libraries/commodities.h> |
|
#include <intuition/intuitionbase.h> |
|
#include <graphics/gfxbase.h> |
|
#include <utility/utility.h> |
|
#include <workbench/icon.h> |
|
#include <resources/battclock.h> |
|
#include <rexx/rxslib.h> |
|
|
|
#if defined(SCREENNOTIFY) |
|
#include "libraries/screennotify.h" |
|
#endif |
|
|
|
#include "logmod.h" |
|
#define MODULENAME "Library" |
|
|
|
/* Library and resource identifiers */ |
|
#ifndef DOSNAME |
|
#define DOSNAME "dos.library" |
|
#endif |
|
#ifndef UTILITYNAME |
|
#define UTILITYNAME "utility.library" |
|
#endif |
|
#ifndef COMMODITIESNAME |
|
#define COMMODITIESNAME "commodities.library" |
|
#endif |
|
#ifndef INTUITIONNAME |
|
#define INTUITIONNAME "intuition.library" |
|
#endif |
|
#ifndef GADTOOLSNAME |
|
#define GADTOOLSNAME "gadtools.library" |
|
#endif |
|
#ifndef ICONNAME |
|
#define ICONNAME "icon.library" |
|
#endif |
|
#ifndef GRAPHICSNAME |
|
#define GRAPHICSNAME "graphics.library" |
|
#endif |
|
#ifndef LOCALENAME |
|
#define LOCALENAME "locale.library" |
|
#endif |
|
#ifndef RXSNAME |
|
#define RXSNAME "rexxsyslib.library" |
|
#endif |
|
#ifndef BATTCLOCKNAME |
|
#define BATTCLOCKNAME "battclock.resource" |
|
#endif |
|
#ifndef TIMERNAME |
|
#define TIMERNAME "timer.device" |
|
#endif |
|
#ifndef LIBREV |
|
#define LIBREV 34L |
|
#endif |
|
|
|
#ifndef NOAREXX |
|
#define NOAREXX "No ARexx library found" |
|
#endif |
|
#ifndef NORTCCLOCK |
|
#define NORTCCLOCK "No RTC found" |
|
#endif |
|
|
|
struct DosLibrary *DOSBase2 = NULL; |
|
struct UtilityBase *UtilityBase = NULL; |
|
struct Library *CxBase = NULL; |
|
struct IntuitionBase *IntuitionBase = NULL; |
|
struct Library *GadToolsBase = NULL; |
|
struct Library *IconBase = NULL; |
|
struct GfxBase *GfxBase = NULL; |
|
struct LocaleBase *LocaleBase = NULL; |
|
struct RxsLib *RexxSysBase = NULL; |
|
struct Library *ScreenNotifyBase = NULL; |
|
struct Library *BattClockBase = NULL; |
|
struct Device *TimerDevice = NULL; |
|
|
|
static void OpenLibrarySuccess(char *name, char *ident) |
|
{ |
|
LogDebug(Text2P, TextOpened, (ident == NULL ? name : ident)); |
|
} |
|
|
|
static void ClosingLibrary(char *name, char *ident) |
|
{ |
|
LogDebug(Text2P, TextClosing, (ident == NULL ? name : ident)); |
|
} |
|
|
|
static void OpenLibraryError(char *name, long version) |
|
{ |
|
char message[128]; |
|
SNPrintf(message, 127, "%s %s %ld.0", TextNoOpen, name, version); |
|
Printf((STRPTR)message); |
|
LogError(message); |
|
} |
|
|
|
int OpenLibraries(void) |
|
{ |
|
LogInfo(Text2P, TextStarting, "up"); |
|
|
|
// DOS Library |
|
if (!(DOSBase2 = (struct DosLibrary *)OpenLibrary((STRPTR)DOSNAME, LIBREV))) |
|
{ |
|
OpenLibraryError(DOSNAME, LIBREV); |
|
return LIB_ERROR; |
|
} |
|
OpenLibrarySuccess(DOSNAME, DOSBase2->dl_lib.lib_IdString); |
|
|
|
// Utility Library |
|
if (!(UtilityBase = (struct UtilityBase *)OpenLibrary((STRPTR)UTILITYNAME, LIBREV))) |
|
{ |
|
OpenLibraryError(UTILITYNAME, LIBREV); |
|
return LIB_ERROR; |
|
} |
|
OpenLibrarySuccess(UTILITYNAME, UtilityBase->ub_LibNode.lib_IdString); |
|
|
|
// Commodity Library |
|
if (!(CxBase = OpenLibrary((STRPTR)COMMODITIESNAME, LIBREV))) |
|
{ |
|
OpenLibraryError(COMMODITIESNAME, LIBREV); |
|
return LIB_ERROR; |
|
} |
|
OpenLibrarySuccess(COMMODITIESNAME, CxBase->lib_IdString); |
|
|
|
// Intuition Library |
|
if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary((STRPTR)INTUITIONNAME, LIBREV))) |
|
{ |
|
OpenLibraryError(INTUITIONNAME, LIBREV); |
|
return LIB_ERROR; |
|
} |
|
OpenLibrarySuccess(INTUITIONNAME, IntuitionBase->LibNode.lib_IdString); |
|
|
|
// Gadget Library |
|
if (!(GadToolsBase = OpenLibrary((STRPTR)GADTOOLSNAME, LIBREV))) |
|
{ |
|
OpenLibraryError(GADTOOLSNAME, LIBREV); |
|
return LIB_ERROR; |
|
} |
|
OpenLibrarySuccess(GADTOOLSNAME, GadToolsBase->lib_IdString); |
|
|
|
// Icon Library |
|
if (!(IconBase = OpenLibrary((STRPTR)ICONNAME, LIBREV))) |
|
{ |
|
OpenLibraryError(ICONNAME, LIBREV); |
|
return LIB_ERROR; |
|
} |
|
OpenLibrarySuccess(ICONNAME, IconBase->lib_IdString); |
|
|
|
// Graphics Library |
|
if (!(GfxBase = (struct GfxBase *)OpenLibrary((STRPTR)GRAPHICSNAME, LIBREV))) |
|
{ |
|
OpenLibraryError(GRAPHICSNAME, LIBREV); |
|
return LIB_ERROR; |
|
} |
|
OpenLibrarySuccess(GRAPHICSNAME, GfxBase->LibNode.lib_IdString); |
|
|
|
// Locale Library |
|
if (!(LocaleBase = (struct LocaleBase *)OpenLibrary((STRPTR)LOCALENAME, LIBREV))) |
|
{ |
|
OpenLibraryError(LOCALENAME, LIBREV); |
|
return LIB_ERROR; |
|
} |
|
OpenLibrarySuccess(LOCALENAME, LocaleBase->lb_LibNode.lib_IdString); |
|
|
|
// ARexx Library |
|
RexxSysBase = (struct RxsLib *)OpenLibrary((STRPTR)RXSNAME, 0); |
|
if (RexxSysBase != NULL) |
|
{ |
|
OpenLibrarySuccess(RXSNAME, RexxSysBase->rl_Node.lib_IdString); |
|
} |
|
else |
|
{ |
|
LogWarn(NOAREXX); |
|
} |
|
|
|
// Timer Device |
|
if (!(TimerDevice = OpenTimerBase())) |
|
{ |
|
LogError(Text2P, TextNoOpen, TIMERNAME); |
|
return LIB_ERROR; |
|
} |
|
LogDebug(Text2P, TextOpened, TIMERNAME); |
|
|
|
// RTC Clock |
|
BattClockBase = OpenResource((STRPTR)BATTCLOCKNAME); |
|
if (BattClockBase != NULL) |
|
{ |
|
LogDebug(Text2P, TextOpened, BATTCLOCKNAME); |
|
} |
|
else |
|
{ |
|
LogNotice(NORTCCLOCK); |
|
} |
|
|
|
#if defined(SCREENNOTIFY) |
|
ScreenNotifyBase = OpenLibrary((STRPTR)SCREENNOTIFY_NAME, SCREENNOTIFY_VERSION); |
|
if (ScreenNotifyBase != NULL) |
|
{ |
|
LogNotice(Text2P, TextFound, SCREENNOTIFY_NAME); |
|
} |
|
#endif |
|
|
|
SeedRandom(); |
|
|
|
return LIB_OK; |
|
} |
|
|
|
void CloseLibraries(void) |
|
{ |
|
if (TimerDevice != NULL) |
|
{ |
|
LogDebug(Text2P, TextClosing, TIMERNAME); |
|
CloseTimerBase(); |
|
TimerDevice = NULL; |
|
} |
|
|
|
#if defined(SCREENNOTIFY) |
|
if (ScreenNotifyBase != NULL) |
|
{ |
|
ClosingLibrary(SCREENNOTIFY_NAME, ScreenNotifyBase->lib_IdString); |
|
CloseLibrary(ScreenNotifyBase); |
|
ScreenNotifyBase = NULL; |
|
} |
|
#endif |
|
|
|
if (RexxSysBase != NULL) |
|
{ |
|
ClosingLibrary(RXSNAME, RexxSysBase->rl_Node.lib_IdString); |
|
CloseLibrary((struct Library *)RexxSysBase); |
|
RexxSysBase = NULL; |
|
} |
|
|
|
if (LocaleBase != NULL) |
|
{ |
|
ClosingLibrary(LOCALENAME, LocaleBase->lb_LibNode.lib_IdString); |
|
CloseLibrary((struct Library *)LocaleBase); |
|
LocaleBase = NULL; |
|
} |
|
|
|
if (GfxBase != NULL) |
|
{ |
|
ClosingLibrary(GRAPHICSNAME, GfxBase->LibNode.lib_IdString); |
|
CloseLibrary((struct Library *)GfxBase); |
|
GfxBase = NULL; |
|
} |
|
|
|
if (IconBase != NULL) |
|
{ |
|
ClosingLibrary(ICONNAME, IconBase->lib_IdString); |
|
CloseLibrary(IconBase); |
|
IconBase = NULL; |
|
} |
|
|
|
if (GadToolsBase != NULL) |
|
{ |
|
ClosingLibrary(GADTOOLSNAME, GadToolsBase->lib_IdString); |
|
CloseLibrary(GadToolsBase); |
|
GadToolsBase = NULL; |
|
} |
|
|
|
if (IntuitionBase != NULL) |
|
{ |
|
ClosingLibrary(INTUITIONNAME, IntuitionBase->LibNode.lib_IdString); |
|
CloseLibrary((struct Library *)IntuitionBase); |
|
IntuitionBase = NULL; |
|
} |
|
|
|
if (CxBase != NULL) |
|
{ |
|
ClosingLibrary(COMMODITIESNAME, CxBase->lib_IdString); |
|
CloseLibrary(CxBase); |
|
CxBase = NULL; |
|
} |
|
|
|
if (UtilityBase != NULL) |
|
{ |
|
ClosingLibrary(UTILITYNAME, UtilityBase->ub_LibNode.lib_IdString); |
|
CloseLibrary((struct Library *)UtilityBase); |
|
UtilityBase = NULL; |
|
} |
|
|
|
if (DOSBase2 != NULL) |
|
{ |
|
ClosingLibrary(DOSNAME, DOSBase2->dl_lib.lib_IdString); |
|
CloseLibrary((struct Library *)DOSBase2); |
|
DOSBase2 = NULL; |
|
} |
|
}
|
|
|