home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
037.lha
/
DU
/
MyStart.mod
< prev
next >
Wrap
Text File
|
1987-05-16
|
4KB
|
122 lines
IMPLEMENTATION MODULE MyStart;
(* Original code provided by TDI *)
(* Turned into a module by Mike Lawrence:CIS 70030,160 *)
(* Rev: 3/14/87 1:55pm for 3/87 release of TDI Modula-2 *)
(* Revised way back to my DirUtil needs - 4/28/87 - G. Browne *)
(* THIS STARTUP IS SPECIFIC TO MY DIRUTIL NEEDS. IT DOESN'T CONSIDER
ANY CLICKED IN OR TAIL ARGUMENTS AND DOESN'T BOTHER TO CD TO THE
PASSED IN DIRECTORY LOCK.
*)
(*$S-,$T-,$A+*)
FROM SYSTEM IMPORT CODE,ADR,SETREG,REGISTER,NULL,ADDRESS;
FROM DOSLibrary IMPORT DOSName,DOSBase;
FROM DOSFiles IMPORT Open,Close,Write,CurrentDir,FileHandle,FileLock,
ModeNewFile,ModeOldFile,Output,Input;
FROM DOSExtensions IMPORT ProcessPtr,FileHandleBlock;
FROM Libraries IMPORT OpenLibrary,CloseLibrary;
FROM Ports IMPORT GetMsg,ReplyMsg,WaitPort,MessagePtr;
FROM Workbench IMPORT WBStartup,WBArgPtr;
FROM Interrupts IMPORT Forbid;
FROM Strings IMPORT Length,Concat;
(* Replacement for findtask *)
CONST
D0 = 0; A1 = 9; A6 = 14;
JSRA6 = 4EAEH; SAVEA6 = 2F0EH; RESTOREA6 = 2C5FH;
FindTaskVec = -30-264;
VAR
(* My AMIGAX has a problem. Kludge the ExecBase right here *)
ExecBase[4] : ADDRESS;
(* Tasks.FindTask has a bug. Use this instead *)
PROCEDURE FindTask(name: ADDRESS): ADDRESS;
(* find a task with a given name, or find oneself. *)
BEGIN
CODE(SAVEA6);
SETREG(A1, name);
SETREG(A6,ExecBase);
CODE(JSRA6,FindTaskVec);
CODE(RESTOREA6);
RETURN REGISTER(D0);
END FindTask;
TYPE
ProjectString = ARRAY [0..40] OF CHAR;
VAR
myProcess : ProcessPtr;
WBenchMsg : POINTER TO WBStartup;
name : POINTER TO ProjectString;
args : WBArgPtr;
Window, tool: FileHandle;
oldLock : FileLock;
fh : POINTER TO FileHandleBlock;
wName,
ProjectName : ProjectString;
FROMwb : BOOLEAN;
OrigConsTask: ADDRESS;
PROCEDURE EnteredFromWorkbench():BOOLEAN;
(*
Sets up for either CLI or WB RETURNS TRUE IF WB
*)
BEGIN
myProcess := ProcessPtr(FindTask(NULL));
IF myProcess^.prCLI <> NULL THEN (* running from CLI : *)
InitialInput := Input();
InitialOutput := Output();
FROMwb := FALSE;
ELSE
(* OTHERWISE running from Workbench : wait for the WB startup message *)
WBenchMsg := WaitPort(ADR(myProcess^.prMsgPort));
WBenchMsg := GetMsg(ADR(myProcess^.prMsgPort));
args := WBenchMsg^.smArgList;
IF DOSBase = 0 THEN DOSBase := OpenLibrary(DOSName,0) END;
wName := "RAW:0/0/320/80/";
(* don't bother with matching directories since we change to ram: soon
IF args <> NULL THEN
oldLock := CurrentDir(FileLock(args^.waLock))
END;
*)
name := ADDRESS(args^.waName);
ProjectName := name^;
Concat(wName,ProjectName,wName); (* window name = tool name *)
InitialOutput := Open(wName, ModeNewFile);
InitialInput := InitialOutput;
fh := ADDRESS(InitialOutput * 4);
myProcess^.prConsoleTask := fh^.fhType;
(* needed for window handlers *)
FROMwb := TRUE;
END;
RETURN FROMwb;
END EnteredFromWorkbench;
PROCEDURE CleanUpAndExit;
BEGIN
IF FROMwb THEN (* was started from Workbench *)
Close(InitialInput);
IF DOSBase <> 0 THEN CloseLibrary(DOSBase) END;
Forbid; (* very important - will fail without the forbid *)
ReplyMsg(MessagePtr(WBenchMsg)); (* free memory *)
ELSIF DOSBase <> 0 THEN CloseLibrary(DOSBase) (* Close if from CLI *)
END;
END CleanUpAndExit;
BEGIN
END MyStart.