MODULE CoDemo;
(* Program to demonstrate the use of Coroutines *)
FROM IO IMPORT KeyPressed, RdKey, WrChar, WrStr;
FROM Screen IMPORT Clear, Cursor;
FROM SYSTEM IMPORT NEWPROCESS, TRANSFER;
VAR TimeToGoHome: BOOLEAN;
WorkSpace1, WorkSpace2, WorkSpace3: ARRAY[0..999] OF BYTE;
Main, Coroutine1, Coroutine2, Coroutine3: ADDRESS;
PROCEDURE Box(line, column: CARDINAL);
(* Outputs a box at specified position *)
VAR count: [0..20];
BEGIN
Cursor(line, column);
WrChar(332C);
FOR count := 0 TO 19 DO
WrChar(304C)
END (*FOR*);
WrChar(277C);
Cursor(line+1, column);
WrChar(263C);
FOR count := 0 TO 19 DO
WrChar(' ')
END (*FOR*);
WrChar(263C);
Cursor(line+2, column);
WrChar(300C);
FOR count := 0 TO 19 DO
WrChar(304C)
END(*FOR*);
WrChar(331C)
END Box;
PROCEDURE Cycle;
(* Cycle a message around in the top box *)
VAR CyclePos, count: [0..20];
Message: ARRAY[0..20] OF CHAR;
BEGIN
Box(4, 29);
CyclePos := 0;
Message := "* HAVE A NICE DAY ! ";
LOOP
FOR count := 0 TO 19 DO
Cursor(5, 30 + count);
WrChar(Message[ (CyclePos + count) MOD 20 ]);
TRANSFER(Coroutine1, Main)
END(*FOR*);
CyclePos := (CyclePos + 1) MOD 20
END(*LOOP*)
END Cycle;
PROCEDURE Star;
(* Move a star backwards and forwards *)
VAR StarPos, delay: [0..20];
BEGIN
Box(12, 29);
LOOP
FOR StarPos := 0 TO 19 DO
Cursor(13, 30 + StarPos);
WrChar('*');
FOR delay := 1 TO 10 DO
TRANSFER(Coroutine2, Main)
END(*FOR*);
Cursor(13, 30 + StarPos);
WrChar(' ')
END(*FOR*);
FOR StarPos := 18 TO 1 BY -1 DO
Cursor(13, 30 + StarPos);
WrChar('*');
FOR delay := 1 TO 10 DO
TRANSFER(Coroutine2, Main)
END(*FOR*);
Cursor(13, 30 + StarPos);
WrChar(' ')
END(*FOR*)
END(*LOOP*)
END Star;
PROCEDURE Input;
(* Allow text to be entered and displayed *)
VAR InputPos: [0..20];
InKey: CHAR;
BEGIN
Cursor(19, 29);