summaryrefslogtreecommitdiff
path: root/demo/morphos/openlib.pas
blob: 8fdd688907db3054d4e8c7a3cf1ad1af2ebe9b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{
    Two ways of opening and using libraries
    Free Pascal for MorphOS example

    Copyright (C) 2004 by Karoly Balogh

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

{ * 2004.12.10 * }

program openlib;

uses exec, intuition, graphics, utility;

{ * You can enable this to manually open needed libraries, * }
{ * else it will use functions built into the units;       * }
{ * _DO NOT_ open/close DOS and Utility libraries manually * }
{ * since that's handled by the default startup/shutdown code. * }
{ DEFINE USEOPENLIB}


const
  ERRMSG_NOINTUI = 'Unable to open intuition.library V50!';
  ERRMSG_NOGFX   = 'Unable to open graphics.library V50!';

const
  MSG_INTUIOK = 'intuition.library V50 opened successfully.';
  MSG_GFXOK   = 'graphics.library V50 opened successfully.';


procedure ShutDown(exitString: String; code: LongInt);
begin

  { * When using opening functions built into the units, * }
  { * it's not needed to close libs manually, since unit exit  *}
  { * code will do it for you. * }
{$IFDEF USEOPENLIB}
  if assigned(intuitionBase) then CloseLibrary(PLibrary(intuitionBase));
  if assigned(gfxBase) then CloseLibrary(gfxBase);
{$ENDIF}

  if exitString<>'' then writeln(exitString);
  Halt(code);
end;

procedure Init;
begin

  { * Using built-in or custom library opening functions. * }
  { * It's recommended not to mix up the two ways. * }
  { * It's not needed to implement both of them in your * }
  { * programs, it's just an example to show it. * }
{$IFDEF USEOPENLIB}

  IntuitionBase:=OpenLibrary(INTUITIONNAME,50);
  if IntuitionBase=NIL then
    ShutDown(ERRMSG_NOINTUI,20)
  else
    writeln(MSG_INTUIOK);

  GfxBase:=OpenLibrary(GRAPHICSNAME,50);
  if GfxBase=NIL then
    ShutDown(ERRMSG_NOGFX,20)
  else
    writeln(MSG_GFXOK);

{$ELSE}

  if Not InitIntuitionLibrary then
    ShutDown(ERRMSG_NOINTUI,20)
  else
    writeln(MSG_INTUIOK);

  if Not InitGraphicsLibrary then
    ShutDown(ERRMSG_NOGFX,20)
  else
    writeln(MSG_GFXOK);

{$ENDIF}
end;


begin
  Init;
  ShutDown('',0);
end.