home *** CD-ROM | disk | FTP | other *** search
- {From Micro/Systems Journal, Nov 88}
- {Simple windowing package -
- Provide simple WindowOpen, WindowWrite, WindowWriteln, and
- WindowClose procedures to allow user applications to readily
- open and manipulate single windows (text mode only). Note in
- test code that while it is possible to open multiple windows,
- only topmost window may be scrolled or written to.
- }
- {Toad Hall Tweaks:
- Using PRED(int) instead of int - 1
- Using ShL 1 instead of *2
- }
-
- TYPE
- display = ARRAY[0..24] OF ARRAY[0..79] OF INTEGER;
- datablock = ARRAY[0..1] OF INTEGER;
- Str80 = STRING[80];
- windowNodePtr = ^windowNode;
- windowNode = RECORD
- deltaX,deltaY : INTEGER;
- winX,winY : INTEGER;
- color : INTEGER;
- currentX,currentY : INTEGER;
- data : ^datablock;
- END;
-
- CONST
- cga = $B800; {offset of CGA/EGA}
- mono = $B000; {mono screen}
-
- VAR
- screen : display absolute mono:0; {currently set for mono}
-
- FUNCTION window_Open (x,y,width,height,attr : INTEGER) : windowNodePtr;
- VAR
- pntr : windowNodePtr;
- size, i, j : INTEGER;
-
- BEGIN
- NEW(pntr);
- WITH pntr^ DO BEGIN
- {Save data into window}
- deltaX := x;
- deltaY := y;
- winX := width;
- winY := height;
- color := attr;
- currentX := 0; {set cursor to beginning of window}
- currentY := 0;
-
- {store off section of screen into windownode}
- size := (winY * winX) ShL 1; {TH}
- GetMem(data,size);
-
- FOR i := 0 to PRED(winY) DO
- FOR j := 0 TO PRED(winX) DO BEGIN
- data^[i * winX + j] := screen [deltaY + i][deltaX + j];
- screen [deltaY + i][deltaX + j] := color + INTEGER(' ');
- END;
- END; {with}
- window_Open := pntr; {return function result}
- END; {of window_Open}
-
-
- PROCEDURE Window_Close(w : windowNodePtr);
- VAR i,j : INTEGER;
- BEGIN
- WITH w^ DO BEGIN
- {put original screen back}
- FOR i := 0 TO PRED(winY) DO
- FOR j := 0 TO PRED(winX) DO
- screen [deltaY + i][deltaX +j] := data^[i * winX + j];
- {now release memory to heap}
- FreeMem(data,(winX * winY) ShL 1); {TH}
- END; {with}
- Dispose(w);
- END; {of Window_Close}
-
-
- PROCEDURE Window_Scroll(w : windowNodePtr; count : INTEGER);
- VAR index,xindex,yindex : INTEGER;
- BEGIN
- WITH w^ DO BEGIN
- currentX := 0; {carriage return}
- currentY := currentY + count; {line feed(s)}
- IF currentY >= winY {if beyond window's end...}
- THEN BEGIN {... scroll window's contents}
- count := SUCC(currentY - winY); {TH}
- currentY := PRED(winY); {TH}
- FOR index := 0 TO PRED(winY - count) DO BEGIN
- yindex := index + deltaY;
- FOR xindex := deltaX to PRED(deltaX + winX) DO
- screen [yindex][xindex]
- := screen [yindex + count][xindex];
- END;
- FOR index := 1 TO count DO BEGIN {blank bottom line(s)}
- yindex := deltaY + (winY - index);
- FOR xindex := deltaX TO PRED(deltaX + winX) DO
- screen [yindex][xindex] := color + INTEGER(' ');
- END; {index loop}
- END; {if scrolling}
- END; {with}
- END; {of Window_Scroll}
-
-
- PROCEDURE Window_Write(w : windowNodePtr; OutStr : Str80);
- VAR
- i,offset,value : INTEGER;
- count : byte Absolute OutStr;
- BEGIN
- WITH w^ DO
- FOR i := 1 TO count DO
- IF currentX < winX THEN BEGIN
- value := color + INTEGER(outstr[i]);
- screen [deltaY + currentY][deltaX + currentX] := value;
- currentX := SUCC(currentX); {TH}
- END; {if}
- END; {of Window_Write}
-
-
- PROCEDURE Window_Writeln(w : windowNodePtr; OutStr : Str80);
- BEGIN
- Window_Write(w,OutStr);
- Window_Scroll(w,1);
- END; {of Window_Writeln);
-
-
- {give above routines a few trial calls}
-
- PROCEDURE Exercise_W (w : windowNodePtr);
- VAR i : INTEGER;
- BEGIN
- FOR i := 1 TO 100 DO BEGIN
- Window_Write(w, 'this is a silly string');
- Window_Writeln(w,' continuation');
- Window_writeln(w,'another string');
- END;
- END; {of Exercise_W}
-
- VAR w1,w2 : windowNodePtr;
-
- BEGIN {main}
- w1 := Window_Open(10,10,50,10,$1300);
- Exercise_W(w1);
- w2 := Window_Open(20,5,30,17,$4200);
- Exercise_W(w2);
- Window_Close(w2);
- Exercise_W(w1);
- Window_Close(w1);
- END.