home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
17 Bit Software 3: The Continuation
/
17-Bit_The_Continuation_Disc.iso
/
files
/
nz10.dms
/
nz10.adf
/
Tunnel
/
Tunnel.mod
< prev
next >
Wrap
Text File
|
1993-12-03
|
10KB
|
340 lines
(*$T- note: some progs (not this one) won't run properly like this; TDI to blame: type conversion problems *)
(*$S- *)
MODULE Tunnel;
(* Not Just another cute demo of Amiga graphics and menus, etc.
the code is not optimised; the doloop cycles could have been much more
compact with a procedure but who cares! Just watch the output like
everybody else.
Created: 17/2/88 by Garth Thornton
Modified: 27/2/88
Copyright (c) 1988 by Garth Thornton
This program can be freely copied, but please
leave my name in. Thanks, Garth.
*)
FROM SYSTEM IMPORT ADR, BYTE, ADDRESS, SETREG, NULL, WORD;
FROM WBStart IMPORT GetWBStartUpMsg, ReturnWBStartUpMsg;
FROM Intuition IMPORT IntuitionName, IntuitionBase, WindowPtr, ScreenPtr,
CurrentTime, IntuiMessagePtr, IDCMPFlags, IDCMPFlagSet;
FROM GraphicsLibrary IMPORT GraphicsName, GraphicsBase, Jam1,
DrawingModeSet, PlanePtr;
FROM Pens IMPORT SetAPen, SetDrMd, RectFill;
FROM Libraries IMPORT OpenLibrary, CloseLibrary;
FROM Windows IMPORT CloseWindow;
FROM Ports IMPORT ReplyMsg, MessagePtr, GetMsg;
FROM Screens IMPORT CloseScreen, ShowTitle;
FROM Areas IMPORT AreaInfo, InitArea, AreaEllipse, AreaEnd;
FROM Rasters IMPORT RastPort, RastPortPtr, TmpRas, InitTmpRas, AllocRaster,
FreeRaster;
FROM Views IMPORT ModeSet ;
FROM Colors IMPORT LoadRGB4 ;
FROM RandomNumbers IMPORT Random, Seed;
FROM MathLib0 IMPORT power, entier;
FROM InOut IMPORT WriteString, WriteLn;
(* The modules below are home grown, or borrowed etc *)
FROM TunnelMenu IMPORT ConnectMenu, DisconnectMenu, TunMenuType,
ActionItemType, ViewItemType, PatternItemType,
StyleItemType;
FROM MyScreen IMPORT SetUpScreen, MyIDCMPFlagSet;
FROM TunInfo IMPORT ShowTunInfo, InitTunInfo;
FROM DecodeMenu IMPORT MenuNull, MenuNumber, ItemNumber;
(* theres a TDI module that does these now.. *)
CONST
depth = 5;
width = 320;
height = 200;
IntuitionRev = 0;
Maxdelay = 3000;
Mindelay = 100;
VAR
wp : WindowPtr;
sp : ScreenPtr;
ColourTable : ARRAY [0..31] OF CARDINAL;
wbmsg : ADDRESS;
areabuffer: ARRAY [0..799] OF WORD;
AI: AreaInfo;
AP: LONGINT;
TR: TmpRas;
TRplane: PlanePtr;
RP: RastPortPtr;
(* These variables hold the state of things *)
Patt : CARDINAL;
RGBFold, SpeedLk, Forward : BOOLEAN;
(* ++++++++++++++++++++++++++++++++++ *)
PROCEDURE OpenLibraries () : BOOLEAN;
BEGIN
(* Open intuition library *)
IntuitionBase := OpenLibrary (IntuitionName,IntuitionRev);
IF IntuitionBase = 0 THEN
WriteString ("Open intuition failed"); WriteLn;
RETURN FALSE
END;
(* Now open the graphics library *)
GraphicsBase := OpenLibrary (GraphicsName, 0);
IF GraphicsBase = 0 THEN
WriteString ("Open of graphics library failed "); WriteLn;
RETURN FALSE
END;
RETURN TRUE
END OpenLibraries;
(* ++++++++++++++++++++++++++++++++++++ *)
PROCEDURE ProcessMenuRequest (code : CARDINAL; VAR quit : BOOLEAN);
VAR
menu, item : CARDINAL;
BEGIN
menu := MenuNumber (code); item := ItemNumber (code);
CASE TunMenuType (menu) OF
Actions:
CASE ActionItemType (item) OF
HideTitle: ShowTitle (sp, FALSE); |
UnHideTitle: ShowTitle (sp, TRUE); |
AboutTunnel: ShowTunInfo (wp); |
QuitTunnel: quit := TRUE
END;
|
View:
CASE ViewItemType (item) OF
Front: Forward := TRUE;|
Rear: Forward := FALSE;
END;
|
Pattern:
CASE PatternItemType (item) OF
Single: Patt:=1; |
Double: Patt:=2; |
Reverse: Patt:=3; |
END;
|
Style:
CASE StyleItemType (item) OF
RGBFoldover: RGBFold := TRUE; |
RGBBounce: RGBFold := FALSE; |
Speedlocked: SpeedLk := TRUE; |
Speedfree : SpeedLk := FALSE; |
END;
END;
END ProcessMenuRequest;
(* ++++++++++++++++++++++++++++++++++++ *)
VAR
MsgPtr : IntuiMessagePtr;
Quit : BOOLEAN;
code : CARDINAL;
class : IDCMPFlagSet;
PROCEDURE InitColourTable;
VAR i: CARDINAL;
BEGIN
FOR i := 0 TO 31 DO
ColourTable[i] := 0H; (* black *)
END ;
LoadRGB4(ADR(sp^.VPort), ADR(ColourTable),32)
END InitColourTable;
VAR
i, j, count1, count2 : CARDINAL;
secs, mics : LONGCARD;
t1, t2, delay1, delay2, delinc1, delinc2 : INTEGER;
h, v, colour1, colour2 : CARDINAL ;
rinc1,ginc1,binc1, red1, blue1, green1 : INTEGER ;
rinc2,ginc2,binc2, red2, blue2, green2 : INTEGER ;
rgb1, rgb2 : ARRAY [0..31] OF CARDINAL;
PROCEDURE DoLoop1;
BEGIN
red1:=red1+rinc1;
IF (red1<1) OR (red1>318) THEN red1:=red1 DIV 319 * 319;
IF RGBFold AND (Random(100)<30) THEN red1:=319-red1;
ELSE rinc1:= INTEGER(Random(40)+1);
IF red1=319 THEN rinc1:=-rinc1 END;
END;
END;
blue1:=blue1+binc1;
IF (blue1<1) OR (blue1>318) THEN blue1:=blue1 DIV 319 * 319;
IF RGBFold AND (Random(100)<30) THEN blue1:=319-blue1;
ELSE binc1:= INTEGER(Random(40)+1);
IF blue1=319 THEN binc1:=-binc1 END;
END;
END;
green1:=green1+ginc1;
IF (green1<1) OR (green1>318) THEN green1:=green1 DIV 319 * 319;
IF RGBFold AND (Random(100)<30) THEN green1:=319-green1;
ELSE ginc1:= INTEGER(Random(40)+1);
IF green1=319 THEN ginc1:=-ginc1 END;
END;
END;
rgb1[count1]:= CARDINAL(red1 DIV 20 * 256 + green1 DIV 20 *16 + blue1 DIV 20);
IF Patt=1 THEN
count1:= (count1+1) MOD 32;
FOR i:=31 TO 0 BY -1 DO
IF Forward THEN j:=i ELSE j:=31-i END;
ColourTable[j]:= rgb1[(i+count1) MOD 32];
END;
ELSE
count1:= (count1+1) MOD 16;
FOR i:=31 TO 1 BY -2 DO
IF Forward THEN j:=i ELSE j:=32-i END;
ColourTable[j]:= rgb1[(i DIV 2 +count1) MOD 16];
END;
END;
LoadRGB4(ADR(sp^.VPort),ADR(ColourTable),32);
END DoLoop1;
PROCEDURE DoLoop2;
BEGIN
red2:=red2+rinc2;
IF (red2<1) OR (red2>318) THEN red2:=red2 DIV 319 * 319;
IF RGBFold AND (Random(100)<30) THEN red2:=319-red2;
ELSE rinc2:= INTEGER(Random(40)+1);
IF red2=319 THEN rinc2:=-rinc2 END;
END;
END;
blue2:=blue2+binc2;
IF (blue2<1) OR (blue2>318) THEN blue2:=blue2 DIV 319 * 319;
IF RGBFold AND (Random(100)<30) THEN blue2:=319-blue2;
ELSE binc2:= INTEGER(Random(40)+1);
IF blue2=319 THEN binc2:=-binc2 END;
END;
END;
green2:=green2+ginc2;
IF (green2<1) OR (green2>318) THEN green2:=green2 DIV 319 * 319;
IF RGBFold AND (Random(100)<30) THEN green2:=319-green2;
ELSE ginc2:= INTEGER(Random(40)+1);
IF green2=319 THEN ginc2:=-ginc2 END;
END;
END;
rgb2[count2]:= CARDINAL(red2 DIV 20 * 256 + green2 DIV 20 *16 + blue2 DIV 20);
count2:= (count2+1) MOD 16;
FOR i:=30 TO 0 BY -2 DO
IF Patt=3 THEN
IF Forward THEN j:=30-i ELSE j:=i END;
ELSE
IF Forward THEN j:=i ELSE j:=30-i END;
END;
ColourTable[j]:= rgb2[(i DIV 2 +count2) MOD 16];
END;
LoadRGB4(ADR(sp^.VPort),ADR(ColourTable),32);
END DoLoop2;
BEGIN (* main *)
wbmsg := GetWBStartUpMsg();
IF OpenLibraries () THEN
InitTunInfo ();
Quit := FALSE;
(* Initialize state variables *)
RGBFold := FALSE;
SpeedLk := TRUE;
Patt := 1;
Forward := TRUE;
CurrentTime(ADR(secs),ADR(mics));
Seed(secs + mics);
MyIDCMPFlagSet := IDCMPFlagSet{MenuPick};
SetUpScreen (wp, sp, width, height, depth, ModeSet{});
RP := wp^.RPort;
SetDrMd(RP, Jam1);
InitArea(AI,areabuffer,SIZE(areabuffer));
TRplane := AllocRaster(width,height);
IF TRplane # 0 THEN
AP := -1 ;
InitTmpRas(ADR(TR),TRplane,width DIV 16 * height);
WITH RP^ DO
areaInfo := ADR(AI);
AreaPtrn := ADR(AP);
AreaPtSz := BYTE(1);
tmpRas := ADR(TR);
END;
InitColourTable ;
(* Attach menu to the window *)
ConnectMenu (wp);
(* set up tunnel graphix *)
SetAPen(RP,0);
RectFill(RP,0,0,319,199);
FOR i:= 30 TO 0 BY -1 DO
SetAPen(RP,31-i);
h:= (i*i + i*17) DIV 10 + 1; IF i>26 THEN h:=h+(i-26)*(i-26) END;
v:= (i*i*7 +i*110) DIV 100 + 1;
IF AreaEllipse(RP,160,100,h,v) THEN END ;
AreaEnd(RP)
END ;
(* init loop vars *)
count1:=0; count2:=0;
rinc1:=INTEGER(Random(5)+1); binc1:=INTEGER(Random(5)+1);
ginc1:=INTEGER(Random(5)+1);
red1:=0; green1:=0; blue1:=0;
rinc2:=INTEGER(Random(5)+1); binc2:=INTEGER(Random(5)+1);
ginc2:=INTEGER(Random(5)+1);
red2:=0; green2:=0; blue2:=0;
delay1:=Maxdelay; delay2:= Mindelay;
delinc1:=-10; delinc2:=-5;
t1:=0; t2:=0;
(* THE loop! *)
REPEAT
INC(t1); INC(t2);
IF t1 > delay1 THEN
(* see if menu picked *)
MsgPtr := GetMsg(wp^.UserPort);
IF MsgPtr <> NULL THEN
class := MsgPtr^.Class; code := MsgPtr^.Code;
ReplyMsg (MessagePtr(MsgPtr));
IF (class = IDCMPFlagSet {MenuPick}) AND (code <> MenuNull)
THEN ProcessMenuRequest (code, Quit)
END;
END;
t1 := 0;
DoLoop1;
delay1 := delay1 + delinc1;
IF delay1 > Maxdelay THEN delinc1:= -(5 + INTEGER(Random(20)))
ELSIF delay1 < Mindelay THEN delinc1:= (5 + INTEGER(Random(20)))
END;
END;
IF Patt > 1 THEN
IF SpeedLk AND (t1=0) THEN DoLoop2;
ELSIF t2 > delay2 THEN
t2 := 0;
DoLoop2;
delay2 := delay2 + delinc2;
IF delay2 > Maxdelay THEN delinc2:= -(5 + INTEGER(Random(20)))
ELSIF delay2 < Mindelay THEN delinc2:= (5 + INTEGER(Random(20)))
END;
END;
END;
UNTIL Quit;
DisconnectMenu (wp);
(* Close the window and screen *)
CloseWindow (wp);
CloseScreen (sp);
FreeRaster(TRplane,width,height);
END;
END; (* IF *)
ReturnWBStartUpMsg;
END Tunnel.