summaryrefslogtreecommitdiff
path: root/packages/graph/src/amiga/graph.pp
blob: 8021716d2eff9eb6d894417fa497820a9ad1392d (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
unit Graph;

{ *********************************************************************

  Info:

  This units mimics some parts of borland's graph unit for
  Amiga.

  You have to use crt for readln, readkey and stuff like
  that for your programs. When the show is over you should
  just press a key or hit return to close everything down.

  If that doesn't work just flip the screens with left-Amiga n
  and activate the shell you started from.

  I have compiled and run mandel.pp without any problems.

  This version requires Free Pascal 0.99.5c or higher.

  It will also use some amigaunits, when the unit gets
  better we can remove those units.

  Large parts have not yet been implemented or tested.

  nils.sjoholm@mailbox.swipnet.se  (Nils Sjoholm)

  History:

  Date       Version  Who      Comments
  ---------- -------- -------  -------------------------------------
  27-Nov-98  0.1      nsjoholm Initial version.

  License Conditions:

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library 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.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


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


interface

uses Exec, Intuition, Graphics, Utility;

{ ---------------------------------------------------------------------
   Constants

  ---------------------------------------------------------------------}

const
  NormalPut       = 0;
  CopyPut         = 0;
  XORPut          = 1;
  ORPut           = 2;
  ANDPut          = 3;
  NotPut          = 4;
  BackPut         = 8;

  Black           =  0;
  Blue            =  1;
  Green           =  2;
  Cyan            =  3;
  Red             =  4;
  Magenta         =  5;
  Brown           =  6;
  LightGray       =  7;
  DarkGray        =  8;
  LightBlue       =  9;
  LightGreen      = 10;
  LightCyan       = 11;
  LightRed        = 12;
  LightMagenta    = 13;
  Yellow          = 14;
  White           = 15;
  Border          = 16;

  SolidLn         = 0;
  DottedLn        = 1;
  CenterLn        = 2;
  DashedLn        = 3;
  UserBitLn       = 4;

  EmptyFill       = 0;
  SolidFill       = 1;
  LineFill        = 2;
  LtSlashFill     = 3;
  SlashFill       = 4;
  BkSlashFill     = 5;
  LtBkSlashFill   = 6;
  HatchFill       = 7;
  XHatchFill      = 8;
  InterleaveFill  = 9;
  WideDotFill     = 10;
  CloseDotFill    = 11;
  UserFill        = 12;

  NormWidth       = 1;
  ThickWidth      = 3;

const
  LeftText      = 0;
  CenterText    = 1;
  RightText     = 2;
  BottomText    = 0;
  TopText       = 2;
  BaseLine      = 3;
  LeadLine      = 4;

const
  { Error codes }
  grOK             = 0;
  grNoInitGraph    = -1;
  grNotDetected    = -2;
  grFileNotFound   = -3;
  grInvalidDriver  = -4;
  grNoLOadMem      = -5;
  grNoScanMem      = -6;
  grNoFloodMem     = -7;
  grFontNotFound   = -8;
  grNoFontMem      = -9;
  grInvalidmode    = -10;
  grError          = -11;
  grIOerror        = -12;
  grInvalidFont    = -13;
  grInvalidFontNum = -14;

Type
  FillPatternType = array[1..8] of byte;

  ArcCoordsType = record
     x,y : integer;
     xstart,ystart : integer;
     xend,yend : integer;
  end;

  RGBColor = record
    r,g,b,i : byte;
  end;


  PaletteType = record
     Size   : integer;
     Colors : array[0..767]of Byte;
  end;


  LineSettingsType = record
     linestyle : word;
     pattern : word;
     thickness : word;
  end;

  TextSettingsType = record
     font : word;
     direction : word;
     charsize : word;
     horiz : word;
     vert : word;
  end;

  FillSettingsType = record
     pattern : word;
     color : longint;
  end;

  PointType = record
     x,y : integer;
  end;

  ViewPortType = record
     x1,y1,x2,y2 : integer;
     Clip : boolean;
  end;

 const
  fillpattern : array[0..12] of FillPatternType = (
      ($00,$00,$00,$00,$00,$00,$00,$00),     { Hintergrundfarbe }
      ($ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff),     { Vordergrundfarbe }
      ($ff,$ff,$00,$00,$ff,$ff,$00,$00),     { === }
      ($01,$02,$04,$08,$10,$20,$40,$80),     { /// }
      ($07,$0e,$1c,$38,$70,$e0,$c1,$83),     { /// als dicke Linien }
      ($07,$83,$c1,$e0,$70,$38,$1c,$0e),     { \\\ als dicke Linien }
      ($5a,$2d,$96,$4b,$a5,$d2,$69,$b4),     { \ \\ \ }
      ($ff,$88,$88,$88,$ff,$88,$88,$88),     { K„stchen }
      ($18,$24,$42,$81,$81,$42,$24,$18),     { Rauten }
      ($cc,$33,$cc,$33,$cc,$33,$cc,$33),     { "Mauermuster" }
      ($80,$00,$08,$00,$80,$00,$08,$00),     { weit auseinanderliegende Punkte }
      ($88,$00,$22,$00,$88,$00,$22,$00),     { dichte Punkte}
      (0,0,0,0,0,0,0,0)                      { benutzerdefiniert }
     );





{ ---------------------------------------------------------------------
   Function Declarations

  ---------------------------------------------------------------------}

{ Retrieving coordinates }
function  GetX: Integer;
function  GetY: Integer;

{ Pixel-oriented routines }
procedure PutPixel(X, Y: Integer; Pixel: Word);
function  GetPixel(X, Y: Integer): Integer;

{ Line-oriented primitives }
procedure LineTo(X, Y: Integer);
procedure LineRel(Dx, Dy: Integer);
procedure MoveTo(X, Y: Integer);
procedure MoveRel(Dx, Dy: Integer);
procedure Line(x1, y1, x2, y2: Integer);

{ Linearly bounded primitives }
procedure Rectangle(x1, y1, x2, y2: Integer);
procedure Bar(x1, y1, x2, y2: Integer);
procedure Bar3D(x1, y1, x2, y2: Integer; Depth: Word; Top: Boolean);
procedure FloodFill(X, Y: Integer; Border: Word);

{ Nonlinearly bounded primitives }

procedure Arc(X, Y: Integer; StAngle, EndAngle, Radius: Word);
procedure GetArcCoords(var ArcCoords: ArcCoordsType);
procedure Circle(X, Y: Integer; Radius: Word);
procedure Ellipse(X, Y: Integer; StAngle, EndAngle: Word; XRadius, YRadius : Word);
procedure FillEllipse(X, Y: Integer; XRadius, YRadius : Word);
procedure SetAspectRatio(Xasp, Yasp: Word);
procedure PieSlice(X, Y: Integer; StAngle, EndAngle, Radius: Word);
procedure Sector(X, Y: Integer; StAngle, EndAngle, XRadius, YRadius: Word);

{ Color routines }
procedure SetBkColor(ColorNum: Word);
procedure SetColor(Color: Word);
Function  GetBkColor : Word;
Function  GetColor : Word;
function  GetMaxColor : Word;

function  GetMaxX : Integer;
function  GetMAxY : Integer;
function  GetAspect: Real;
procedure GetAspectRatio(var x,y : Word);

{ Graph clipping method }
Procedure ClearViewPort;

function GraphResult: Integer;

{ For compatibility }
Procedure InitGraph (Var Driver,Mode : Integer;DriverPath : String);
Procedure CloseGraph;

const
  NoGraphics: Boolean = false;

  { VGA modes }
  GTEXT             = 0;                { Compatible with VGAlib v1.2 }
  G320x200x16       = 1;
  G640x200x16       = 2;
  G640x350x16       = 3;
  G640x480x16       = 4;
  G320x200x256      = 5;
  G320x240x256      = 6;
  G320x400x256      = 7;
  G360x480x256      = 8;
  G640x480x2        = 9;

  G640x480x256      = 10;
  G800x600x256      = 11;
  G1024x768x256     = 12;

  G1280x1024x256    = 13;   { Additional modes. }

  G320x200x32K      = 14;
  G320x200x64K      = 15;
  G320x200x16M      = 16;
  G640x480x32K      = 17;
  G640x480x64K      = 18;
  G640x480x16M      = 19;
  G800x600x32K      = 20;
  G800x600x64K      = 21;
  G800x600x16M      = 22;
  G1024x768x32K     = 23;
  G1024x768x64K     = 24;
  G1024x768x16M     = 25;
  G1280x1024x32K    = 26;
  G1280x1024x64K    = 27;
  G1280x1024x16M    = 28;

  G800x600x16       = 29;
  G1024x768x16      = 30;
  G1280x1024x16     = 31;

  G720x348x2        = 32;               { Hercules emulation mode }

  G320x200x16M32    = 33;       { 32-bit per pixel modes. }
  G640x480x16M32    = 34;
  G800x600x16M32    = 35;
  G1024x768x16M32   = 36;
  G1280x1024x16M32  = 37;

  { additional resolutions }
  G1152x864x16      = 38;
  G1152x864x256     = 39;
  G1152x864x32K     = 40;
  G1152x864x64K     = 41;
  G1152x864x16M     = 42;
  G1152x864x16M32   = 43;

  G1600x1200x16     = 44;
  G1600x1200x256    = 45;
  G1600x1200x32K    = 46;
  G1600x1200x64K    = 47;
  G1600x1200x16M    = 48;
  G1600x1200x16M32  = 49;

  GLASTMODE         = 49;


implementation

{$I tagutils.inc}

{ ---------------------------------------------------------------------
   Types, constants and variables

  ---------------------------------------------------------------------}
VAR     GraphScr     :pScreen;
        GraphWin     :pWindow;
        CurrentRastPort : pRastPort;
        TheAspect   : Real;
        GraphResultCode : Integer;

        Msg     :pIntuiMessage;
        Ende    :Boolean;

var
  DrawDelta: TPoint;
  CurX, CurY: Integer;
  TheColor, TheFillColor: LongInt;
  IsVirtual: Boolean;
  ColorTable: array[0..15] of LongInt;
  TheFillPattern : FillPatternType;
  TheLineSettings : LineSettingsType;
  ThePalette : PaletteType;
  TheTextSettings : TextSettingsType;
  TheFillSettings : FillSettingsType;

const
  BgiColors: array[0..15] of LongInt
    = ($000000, $000080, $008000, $008080,
       $800000, $800080, $808000, $C0C0C0,
       $808080, $0000FF, $00FF00, $00FFFF,
       $FF0000, $FF00FF, $FFFF00, $FFFFFF);

const
  DoUseMarker: Boolean = true;
  TheMarker: Char      = '~';
  TextColor: LongInt   = 15;
  MarkColor: LongInt   = 15;
  BackColor: LongInt   = 0;
  FontWidth: Integer   = 8;
  FontHeight: Integer  = 8;

var
  sHoriz, sVert: Word;

{ initialisierte Variablen }
const
  SourcePage: Word = 0;
  DestPage: Word = 0;

{ Retrieves the capabilities for the current mode }
const
  vmcImage       = 1;
  vmcCopy        = 2;
  vmcSaveRestore = 4;
  vmcBuffer      = 8;
  vmcBackPut     = 16;

{ ---------------------------------------------------------------------
   Graphics Vision Layer
  ---------------------------------------------------------------------}


{ Types and constants }
var
  SizeX, SizeY: Word;

{ Font attributes }
const
  ftNormal          = 0;
  ftBold            = 1;
  ftThin            = 2;
  ftItalic          = 4;

var
  sFont, sColor:Word;
  sCharSpace: Integer;
{ Not used
  sMarker: Char;
  sAttr: Word; }

{ Bitmap utilities }
type
  PBitmap = ^TBitmap;
  TBitmap = record
              Width, Height: Integer;
              Data: record end;
            end;


const
  pbNone  = 0;
  pbCopy  = 1;
  pbClear = 2;

procedure SetColors;
begin
   SetRGB4(@GraphScr^.ViewPort, Black    , 0,0,0);
   SetRGB4(@GraphScr^.ViewPort, Blue     , 0,0,15);
   SetRGB4(@GraphScr^.ViewPort, Green    , 0,15,0);
   SetRGB4(@GraphScr^.ViewPort, Cyan     , 0,15,15);
   SetRGB4(@GraphScr^.ViewPort, Red      , 15,0,0);
   SetRGB4(@GraphScr^.ViewPort, Magenta  , 15,0,15);
   SetRGB4(@GraphScr^.ViewPort, Brown    , 6,2,0);
   SetRGB4(@GraphScr^.ViewPort, LightGray, 13,13,13);
   SetRGB4(@GraphScr^.ViewPort, DarkGray , 4,4,4);
   SetRGB4(@GraphScr^.ViewPort, LightBlue, 5,5,5);
   SetRGB4(@GraphScr^.ViewPort, LightGreen ,9,15,1);
   SetRGB4(@GraphScr^.ViewPort, LightRed   ,14,5,0);
   SetRGB4(@GraphScr^.ViewPort, LightMagenta ,0,15,8);
   SetRGB4(@GraphScr^.ViewPort, Yellow   ,15,15,0);
   SetRGB4(@GraphScr^.ViewPort, White    ,15,15,15);
end;


{ ---------------------------------------------------------------------
   Real graph implementation
  ---------------------------------------------------------------------}

function GraphResult: Integer;
begin
   GraphResult := GraphResultCode;
end;

Procedure ClearViewPort;
begin
   SetRast(CurrentRastPort,Black);
end;

function GetX: Integer;
begin
  GetX := CurX;
end;

function GetY: Integer;
begin
  GetY := CurY;
end;

function GetAspect: Real;
begin
   GetAspect := GetMaxY/GetMaxX;
end;

procedure GetAspectRatio(var x,y : Word);
begin
   x := GetMaxX;
   y := GetMaxY;
end;

{ Pixel-oriented routines }
procedure PutPixel(x,y : Integer; Pixel : Word);
begin
   SetAPen(CurrentRastPort,Pixel);
   WritePixel(CurrentRastPort,x,y);
   CurX := x;
   CurY := y;
end;

function GetPixel(X, Y: Integer): Integer;
begin
   GetPixel := ReadPixel(CurrentRastPort,X,Y);
end;

{ Line-oriented primitives }

procedure LineTo(X, Y: Integer);
begin
   Draw(CurrentRastPort,X,Y);
   CurX := X;
   CurY := Y;
end;

procedure LineRel(Dx, Dy: Integer);
begin
   CurX := CurX + Dx;
   CurY := CurY + Dy;
   Draw(CurrentRastPort, Curx, CurY);
end;

procedure MoveTo(X, Y: Integer);
begin
   Move(CurrentRastPort, X , Y);
   CurX := X;
   CurY := Y;
end;

procedure MoveRel(Dx, Dy: Integer);
begin
   CurX := CurX + Dx;
   CurY := CurY + Dy;
   Move(CurrentRastPort, Curx, CurY);
end;

procedure Line(x1,y1,x2,y2: Integer);
begin
   Move(CurrentRastPort,x1,y1);
   Draw(CurrentRastPort,x2,y2);
   Move(CurrentRastPort,CurX, CurY);
end;

procedure Rectangle(x1, y1, x2, y2: Integer);
begin
   Move(CurrentRastPort, x1, y1);
   Draw(CurrentRastPort, x2, y1);
   Draw(CurrentRastPort, x2, y2);
   Draw(CurrentRastPort, x1, y2);
   Draw(CurrentRastPort, x1, y1);
   CurX := x1;
   CurY := y1;
end;

procedure Bar(x1, y1, x2, y2: Integer);
begin
   RectFill(CurrentRastPort, x1, y1, x2, y2);
   CurX := x1;
   CurY := y1;
end;

procedure Bar3D(x1, y1, x2, y2: Integer; Depth: Word; Top: Boolean);
begin
  Bar(x1,y1,x2,y2);
  Rectangle(x1,y1,x2,y2);
  if top then begin
     Moveto(x1,y1);
     Lineto(x1+depth,y1-depth);
     Lineto(x2+depth,y1-depth);
     Lineto(x2,y1);
  end;
  Moveto(x2+depth,y1-depth);
  Lineto(x2+depth,y2-depth);
  Lineto(x2,y2);

end;

procedure FloodFill(X, Y: Integer; Border: Word);
begin

end;

Var LastArcCoords : ArcCoordsType;


procedure SetArcCoords (X,y,xradius,yradius,Stangle,endangle : integer);

begin
  LastArcCoords.X:=X;
  LastArccOords.y:=y;
  Lastarccoords.xstart:=x+round(xradius*cos(stangle*pi/180));
  Lastarccoords.ystart:=y-round(yradius*sin(stangle*pi/180));
  LastArccoords.xend:=x+round(xradius*cos(endangle*pi/180));
  LastArccoords.yend:=y-round(yradius*sin(endangle*pi/180));
end;


procedure GetArcCoords(var ArcCoords: ArcCoordsType);

begin
  ArcCoords:=LastArcCoords;
end;

procedure Arc(X, Y: Integer; StAngle, EndAngle, Radius: Word);

begin
 Ellipse (X,y,stangle,endangle,Radius,radius);
end;

procedure Circle(X, Y: Integer; Radius: Word);
begin
   DrawEllipse(CurrentRastPort, x, y, Round(Radius * TheAspect), Radius);
end;

procedure Ellipse(X, Y: Integer;
  StAngle, EndAngle: Word; XRadius, YRadius : Word);

Var I : longint;
    tmpang : real;

begin
 SetArcCoords (X,Y,xradius,yradius,Stangle,EndAngle);
 For i:= StAngle To EndAngle Do
  Begin
   tmpAng:= i*Pi/180;
   curX:= X + Round (xRadius*Cos (tmpAng));
   curY:= Y - Round (YRadius*Sin (tmpAng));
   PutPixel (curX, curY, TheColor);
  End;
end;

procedure FillEllipse(X, Y: Integer; XRadius, YRadius : Word);

Var I,tmpcolor : longint;
    tmpang : real;
    tmpx,tmpy : Integer;

begin
 tmpcolor:=Thecolor;
 SetColor(TheFillColor);
 For i:= 0 to 180 Do
  Begin
   tmpAng:= i*Pi/180;
   curX:= Round (xRadius*Cos (tmpAng));
   curY:= Round (YRadius*Sin (tmpAng));
   tmpX:= X - curx;
   tmpy:= Y + cury;
   curx:=x+curx;
   cury:=y-cury;
   Line (curX, curY,tmpx,tmpy);
   PutPixel (curx,cury,tmpcolor);
   PutPixel (tmpx,tmpy,tmpcolor);
  End;
  SetColor(tmpcolor);
end;

procedure SetAspectRatio(Xasp, Yasp: Word);
begin
  //!! Needs implementing.
end;

procedure PieSlice(X, Y: Integer; StAngle, EndAngle, Radius: Word);

Begin
 sector (x,y,stangle,endangle,radius,radius);
end;

procedure Sector(X, Y: Integer;
  StAngle, EndAngle, XRadius, YRadius: Word);

Var I,tmpcolor : longint;
    tmpang : real;
    ac : arccoordstype;

begin
 tmpcolor:=Thecolor;
 SetColor(TheFillColor);
 For i:= stangle to endangle Do
   Begin
   tmpAng:= i*Pi/180;
   curX:= x+Round (xRadius*Cos (tmpAng));
   curY:= y-Round (YRadius*Sin (tmpAng));
   Line (x,y,curX, curY);
   PutPixel (curx,cury,tmpcolor);
   End;
 SetColor(tmpcolor);
 getarccoords(ac);
 Line (x,y,ac.xstart,ac.ystart);
 Line (x,y,ac.xend,ac.yend);
end;

{ Color routines
}

procedure SetBkColor(ColorNum: Word);
begin
  SetBPen(CurrentRastPort, ColorNum);
  BackColor := ColorNum;
end;

Function GetBkColor : Word;

begin
  GetBkColor:=BackColor;
end;

Function GetColor : Word;

begin
  GetColor:=TheColor;
end;

procedure SetColor(color : Word);
begin
   SetAPen(CurrentRastPort,color);
   TheColor := color;
end;

function GetMaxColor: word;
begin
   GetMaxColor := 15;
end;

function GetMaxX: Integer;
begin
   GetMaxX := GraphWin^.Width;
end;

function GetMaxY: Integer;
begin
   GetMaxY := GraphWin^.Height;
end;

Procedure InitGraph (Var Driver,Mode : Integer;DriverPath : String);
var
  thetags : array[0..3] of tTagItem;

BEGIN
  GraphResultCode := grOK;
  GfxBase := OpenLibrary(GRAPHICSNAME,0);
  if GfxBase = nil then begin
      GraphResultCode := grNoInitGraph;
      Exit;
  end;

  GraphScr:=Nil;  GraphWin:=Nil;

  { Will open an hires interlace screen, if you
    want just an hires screen change HIRESLACE_KEY
    to HIRES_KEY
  }
  thetags[0] := TagItem(SA_Depth,     4);
  thetags[1] := TagItem(SA_DisplayID, HIRESLACE_KEY);
  thetags[2].ti_Tag := TAG_END;

  GraphScr := OpenScreenTagList(NIL,@thetags);
  If GraphScr=Nil Then begin
      GraphResultCode := grNoInitGraph;
      Exit;
  end;

  thetags[0] := TagItem(WA_Flags, WFLG_BORDERLESS);
  thetags[1] := TagItem(WA_IDCMP, IDCMP_MOUSEBUTTONS);
  thetags[2] := TagItem(WA_CustomScreen, Longint(GraphScr));
  thetags[3].ti_Tag := TAG_DONE;

  GraphWin:=OpenWindowTagList(Nil, @thetags);
  If GraphWin=Nil Then CloseGraph;

  CurrentRastPort := GraphWin^.RPort;

  SetColors;
  TheAspect := GetAspect;
END;

PROCEDURE CloseGraph;
BEGIN
  { Ende:=false;
  Repeat
    Msg:=pIntuiMessage(GetMsg(GraphWin^.UserPort));
    If Msg<>Nil Then Begin
      ReplyMsg(Pointer(Msg));
      Ende:=true;
    End;
  Until Ende;}
  If GraphWin<>Nil Then
     CloseWindow(GraphWin);
  If (GraphScr<>Nil) then CloseScreen(GraphScr);
  if GfxBase <> nil then CloseLibrary(GfxBase);
  Halt;
END;

begin

  CurX := 0;
  CurY := 0;
end.