windemo.mod 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. (*$I-,R-,O-*)
  2. MODULE WinDemo ;
  3. IMPORT SYSTEM,Window,IO,Lib,Str,Process ;
  4. VAR
  5. IsBW : BOOLEAN ;
  6. TYPE KBFlagSet = SET OF ( RShift, LShift, Ctrl, Alt, Scroll, Num, Cap, Ins ) ;
  7. VAR KeyFlags [40H:17H] : KBFlagSet ;
  8. PROCEDURE CheckScrollLock () ;
  9. BEGIN
  10. IF Scroll IN KeyFlags THEN
  11. Process.Lock ;
  12. WHILE Scroll IN KeyFlags DO
  13. Lib.Delay(10) ;
  14. END ;
  15. Process.Unlock ;
  16. END ;
  17. END CheckScrollLock ;
  18. PROCEDURE SetC ( cc,bwc : Window.Color ) ;
  19. BEGIN
  20. IF IsBW THEN cc := bwc END ;
  21. Window.TextColor(cc) ;
  22. END SetC ;
  23. PROCEDURE Intro ;
  24. (* Display startup and demonstration description *)
  25. TYPE W = RECORD x,y : CARDINAL END ;
  26. WW = ARRAY[0..29] OF W ;
  27. CONST
  28. ww = WW( W(0,0) ,W(5,0) ,W(10,0),W(15,0),W(20,0),
  29. W(10,2) ,W(10,4),W(10,6),W(10,8),W(10,10),
  30. W(5,10) ,W(0,10),W(35,4),W(35,2),W(35,0),
  31. W(40,0), W(45,0),W(50,2),W(50,4),W(45,6),
  32. W(40,6), W(35,6),W(35,8),W(35,10),W(65,0),
  33. W(65,2), W(65,4),W(65,6),W(65,8),W(65,10)
  34. ) ;
  35. PROCEDURE IntroText ;
  36. BEGIN
  37. SetC(Window.White,Window.LightGray);
  38. IO.WrLn ; IO.WrStr(' This is a demonstration of the ');
  39. SetC(Window.Yellow,Window.White); IO.WrStr('Window') ;
  40. SetC(Window.White,Window.LightGray); IO.WrStr(' and ') ;
  41. SetC(Window.Yellow,Window.White) ; IO.WrStr('Process') ;
  42. SetC(Window.White,Window.LightGray); IO.WrStr(' Modules') ;
  43. IO.WrLn ;
  44. IO.WrLn ;
  45. SetC(Window.LightGray,Window.LightGray);
  46. IO.WrStr(' 9 time-sliced processes are created, which output to,');IO.WrLn;
  47. IO.WrStr(' move, re-size and re-colour 4 overlapping windows');IO.WrLn;
  48. IO.WrLn ;
  49. SetC(Window.White,Window.White);
  50. IO.WrStr(' Press any key to start, Esc to finish and ScrollLock to freeze ');
  51. END IntroText ;
  52. VAR
  53. WD : Window.WinDef ;
  54. w : Window.WinType ;
  55. title : ARRAY[0..39] OF CHAR ;
  56. Win : ARRAY[0..29] OF Window.WinType ;
  57. i,j,wn : CARDINAL ;
  58. num : ARRAY[0..6] OF CHAR ;
  59. b,up : BOOLEAN ;
  60. DescWin : Window.WinType ;
  61. delay : CARDINAL ;
  62. exit,
  63. change : BOOLEAN ;
  64. CONST
  65. targetX = 32 ;
  66. targetY = 5 ;
  67. BEGIN
  68. FOR i := 0 TO 29 DO
  69. WITH WD DO
  70. IF i<30 THEN
  71. IF IsBW THEN
  72. IF ODD(i) THEN
  73. Background := Window.Black ;
  74. Foreground := Window.White ;
  75. ELSE
  76. Background := Window.LightGray ;
  77. Foreground := Window.Black ;
  78. END ;
  79. ELSE
  80. Background := Window.Color(i MOD 8) ;
  81. Foreground := Window.Color(15-i MOD 8) ;
  82. END ;
  83. X1 := ww[i].x ; Y1 := ww[i].y ;
  84. X2 := X1+9 ; Y2 := Y1+3 ;
  85. END ;
  86. CursorOn := FALSE ;
  87. WrapOn := FALSE ;
  88. Hidden := FALSE ;
  89. FrameOn := TRUE ;
  90. FrameDef := Window.SingleFrame ;
  91. IF NOT IsBW AND (Background=Window.Black) THEN
  92. FrameBack := Window.Green ;
  93. ELSE
  94. FrameBack := Background ;
  95. END ;
  96. (* Window.Color(ORD(Foreground)MOD 8) *) ;
  97. IF FrameBack=Window.LightGray THEN FrameFore := Window.Black ;
  98. ELSE FrameFore := Window.LightGray ;
  99. END ;
  100. END ;
  101. Win[i] := Window.Open(WD) ;
  102. Window.SetTitle(Win[i],'JPI',Window.CenterUpperTitle);
  103. Str.CardToStr(LONGCARD(i+1),num,10,b) ;
  104. (*
  105. IF (i=29)OR(ww[i].x+5<>ww[i+1].x) THEN IO.WrChar(' '); END ;
  106. *)
  107. IO.WrStr('TopSpeed');
  108. IO.WrLn ;
  109. IO.WrStr('Modula-2');
  110. END ;
  111. WD := Window.WinDef(0,15,75,24,Window.White,Window.Black,
  112. FALSE,TRUE,FALSE,TRUE,
  113. Window.DoubleFrame,Window.Blue,Window.LightGray) ;
  114. IF IsBW THEN WD.FrameFore := Window.Black END ;
  115. DescWin := Window.Open(WD) ;
  116. Window.SetTitle(DescWin,' JPI TopSpeed Modula-2 : Window Demonstration ',Window.CenterUpperTitle);
  117. IntroText ;
  118. delay := 1000 ;
  119. i := 0 ;
  120. WHILE NOT IO.KeyPressed() DO
  121. CheckScrollLock ;
  122. IF delay>100 THEN DEC(delay,20)
  123. ELSIF delay>1 THEN DEC(delay) ;
  124. END ;
  125. Lib.Delay(delay) ;
  126. Window.PutOnTop(Win[i]) ;
  127. i := (i+1)MOD 30 ;
  128. END ;
  129. REPEAT
  130. exit := TRUE ;
  131. FOR i := 0 TO 29 DO
  132. Window.Info(Win[i],WD) ;
  133. change := TRUE ;
  134. IF WD.X1<targetX-3 THEN INC(WD.X1,3);INC(WD.X2,3);
  135. ELSIF WD.X1>targetX+3 THEN DEC(WD.X1,3);DEC(WD.X2,3);
  136. ELSIF WD.Y1=targetY THEN change := FALSE ;
  137. END ;
  138. IF WD.Y1<targetY THEN INC(WD.Y1);INC(WD.Y2);
  139. ELSIF WD.Y1>targetY THEN DEC(WD.Y1);DEC(WD.Y2);
  140. END ;
  141. IF change THEN
  142. Window.Change(Win[i],WD.X1,WD.Y1,WD.X2,WD.Y2) ;
  143. exit := FALSE ;
  144. END ;
  145. END ;
  146. UNTIL exit ;
  147. FOR i := 0 TO 30 DO
  148. w := Window.Top() ;
  149. Lib.Delay(10) ;
  150. Window.Close(w) ;
  151. END ;
  152. IF IO.RdKey()=CHR(27) THEN HALT END ;
  153. END Intro;
  154. (* Actual demo starts here *)
  155. (* ----------------------- *)
  156. VAR
  157. W1,W2,W3,W4 : Window.WinType;
  158. DS : Process.SIGNAL ;
  159. Initialize : BOOLEAN ;
  160. pal : Window.PaletteDef ;
  161. (* Random Colouring *)
  162. PROCEDURE RandPalette ( VAR p : Window.PaletteDef ) ;
  163. VAR
  164. i : SHORTCARD ;
  165. TYPE BW3 = ARRAY[0..2] OF Window.Color ;
  166. CONST bw3 = BW3(Window.Black,Window.LightGray,Window.White) ;
  167. BEGIN
  168. FOR i := 0 TO Window.PaletteMax DO
  169. IF IsBW THEN
  170. p[i].Fore := bw3[Lib.RANDOM(3)] ;
  171. ELSE
  172. p[i].Fore := VAL(Window.Color,Lib.RANDOM(16)) ;
  173. END ;
  174. REPEAT
  175. IF IsBW THEN
  176. p[i].Back := bw3[Lib.RANDOM(2)] ;
  177. ELSE
  178. p[i].Back := VAL(Window.Color,Lib.RANDOM(8)) ;
  179. END ;
  180. UNTIL p[i].Back<>p[i].Fore ;
  181. END ;
  182. END RandPalette ;
  183. (* Random Movement *)
  184. PROCEDURE Rmove ( W : Window.WinType ) ;
  185. (* random move process *)
  186. VAR
  187. dx1,dy1 : CARDINAL ;
  188. ix,iy,nx,ny : CARDINAL ;
  189. BEGIN
  190. CheckScrollLock ;
  191. LOOP
  192. Process.Delay(5+Lib.RANDOM(15)) ;
  193. REPEAT
  194. dx1 := W^.WDef.X1+(Lib.RANDOM(16)-8)*2 ;
  195. dy1 := W^.WDef.Y1+Lib.RANDOM(16)-8 ;
  196. UNTIL (dx1<80)AND(dy1<24)
  197. AND(dx1+W^.OWidth<=80)AND(dy1+W^.ODepth<=24) ;
  198. IF dx1>W^.WDef.X1 THEN ix := 2 ELSE ix := 0 END ;
  199. IF dy1>W^.WDef.Y1 THEN iy := 2 ELSE iy := 0 END ;
  200. WHILE (dx1<>W^.WDef.X1) AND (dy1<>W^.WDef.Y1) DO
  201. IF (dx1<>W^.WDef.X1) THEN nx := W^.WDef.X1+ix-1 END ;
  202. IF (dy1<>W^.WDef.Y1) THEN ny := W^.WDef.Y1+iy-1 END ;
  203. Window.Change(W,nx,ny,nx+W^.OWidth-1,ny+W^.ODepth-1) ;
  204. END ;
  205. END ;
  206. END Rmove ;
  207. (* Random Change Size *)
  208. PROCEDURE RChangeSize ( W : Window.WinType ) ;
  209. (* this randomly changes the size of a window *)
  210. VAR
  211. nx,ny : CARDINAL ;
  212. BEGIN
  213. CheckScrollLock ;
  214. REPEAT
  215. nx := W^.WDef.X2+(Lib.RANDOM(16)-8)*2 ;
  216. ny := W^.WDef.Y2+Lib.RANDOM(16)-8 ;
  217. UNTIL (nx-W^.WDef.X1<70)AND(ny-W^.WDef.Y1<18)
  218. AND(nx-W^.WDef.X1>10)AND(ny-W^.WDef.Y1>4) ;
  219. Window.Change(W,W^.WDef.X1,W^.WDef.Y1,nx,ny) ;
  220. END RChangeSize ;
  221. (* Processes *)
  222. (* P1 prints out numbers in Hex, Dec and Binary *)
  223. PROCEDURE P1;
  224. VAR S : ARRAY[0..30] OF CHAR;
  225. i : CARDINAL;
  226. b : BOOLEAN ;
  227. BEGIN
  228. Window.Use(W1) ;
  229. LOOP
  230. FOR i := 0 TO 1000 DO
  231. Str.CardToStr(VAL(LONGCARD,i),S,2,b); IO.WrStr(S);
  232. IO.WrCharRep(' ',16-Str.Length(S));
  233. IO.WrCard(i,5) ;
  234. IO.WrStr(' ') ;
  235. Str.CardToStr(VAL(LONGCARD,i),S,16,b); IO.WrStr(S);
  236. IO.WrCharRep(' ',5-Str.Length(S));
  237. IO.WrLn;
  238. END;
  239. END ;
  240. END P1;
  241. (* P2 displays out a sideways barchart *)
  242. PROCEDURE P2;
  243. VAR i,j : CARDINAL;
  244. V : ARRAY[1..9] OF CARDINAL ;
  245. WD : Window.WinDef ;
  246. PROCEDURE DrawBar ( x,y : CARDINAL ; val : CARDINAL ; on : BOOLEAN ) ;
  247. BEGIN
  248. IF ODD(y) THEN
  249. IF IsBW THEN Window.TextColor(Window.White) ;
  250. ELSE Window.TextColor(Window.Red) ;
  251. END ;
  252. ELSE
  253. Window.TextColor(Window.LightGray) ;
  254. END ;
  255. IF val>0 THEN
  256. DEC(val) ;
  257. Window.GotoXY(x+val DIV 2,y) ;
  258. IF on THEN
  259. IF ODD(val) THEN IO.WrChar('Û') ELSE IO.WrChar('Ý') END ;
  260. ELSE
  261. IF ODD(val) THEN IO.WrChar('Ý') ELSE IO.WrChar(' ') END ;
  262. END ;
  263. END ;
  264. END DrawBar ;
  265. BEGIN
  266. Window.Use(W2) ;
  267. i := 0 ;
  268. FOR i := 1 TO 9 DO
  269. V[i] := Lib.RANDOM(50) ;
  270. FOR j := 0 TO V[i] DO
  271. DrawBar(1,i,j,TRUE) ;
  272. END ;
  273. END ;
  274. LOOP
  275. FOR i := 1 TO 9 DO
  276. Window.Info(W2,WD) ;
  277. IF i<WD.X2-WD.X1-2 THEN
  278. IF Lib.RANDOM(2)=0 THEN
  279. IF V[i]<50 THEN INC(V[i]) ; DrawBar(1,i,V[i],TRUE) END ;
  280. ELSE
  281. IF V[i]>0 THEN DrawBar(1,i,V[i],FALSE) ; DEC(V[i]) ; END ;
  282. END ;
  283. END ;
  284. END ;
  285. CheckScrollLock ;
  286. END ;
  287. END P2;
  288. (* P3 displays a character grid with randomly changing pallette colours *)
  289. PROCEDURE P3;
  290. VAR
  291. X,Y,D : CARDINAL;
  292. CH : CHAR;
  293. BEGIN
  294. CH := '*' ;
  295. D := 0 ;
  296. Window.Use(W3) ;
  297. LOOP
  298. FOR X := 1 TO 8 DO
  299. FOR Y := 1 TO 8 DO
  300. Window.SetPaletteColor(VAL(SHORTCARD,(Y*7+X+D))MOD 8) ;
  301. Window.GotoXY(X,Y);
  302. IO.WrChar(CH);
  303. Window.GotoXY(1,10);
  304. Window.SetPaletteColor(0) ;
  305. IO.WrCard(X,2);
  306. IO.WrChar(',');
  307. IO.WrCard(Y,2);
  308. END;
  309. END;
  310. RandPalette ( pal ) ;
  311. Window.SetPalette(W3,pal) ;
  312. INC(D) ;
  313. CheckScrollLock ;
  314. END ;
  315. END P3;
  316. (* P4 displays some text *)
  317. PROCEDURE P4;
  318. VAR i : CARDINAL ;
  319. BEGIN
  320. Window.Use(W4) ;
  321. REPEAT
  322. FOR i := 1 TO 100 DO
  323. IO.WrStr('This is a test of 9 time-sliced processes, and also of window writing, moving, rearranging and resizing.');
  324. W4^.WDef.Foreground := Window.White ;
  325. IF IsBW THEN
  326. W4^.WDef.Background := Window.Black ;
  327. END ;
  328. IO.WrStr(' Press any key to terminate, ScrollLock to freeze. ');
  329. W4^.WDef.Foreground := Window.Black ;
  330. IF IsBW THEN
  331. W4^.WDef.Background := Window.LightGray
  332. END ;
  333. END;
  334. CheckScrollLock ;
  335. UNTIL IO.KeyPressed() ;
  336. Process.StopScheduler ;
  337. Window.Use(Window.FullScreen) ;
  338. Window.SnapShot ;
  339. Window.PutOnTop(Window.FullScreen) ;
  340. Window.GotoXY(1,Window.ScreenDepth-1);
  341. Window.CursorOn ;
  342. IF IO.RdKey()=' ' THEN END ;
  343. HALT ;
  344. END P4;
  345. (* P5 Re-sizes and Re-arranges text *)
  346. PROCEDURE P5;
  347. BEGIN
  348. LOOP
  349. Process.Delay(10+Lib.RANDOM(20)) ;
  350. CASE Lib.RANDOM(4) OF
  351. 0 : Window.PutOnTop(W1) |
  352. 1 : Window.PutOnTop(W2) |
  353. 2 : Window.PutOnTop(W3) |
  354. 3 : Window.PutOnTop(W4)
  355. END ;
  356. Process.Delay(10+Lib.RANDOM(20)) ;
  357. CASE Lib.RANDOM(4) OF
  358. 0 : RChangeSize(W1) |
  359. 1 : |
  360. 2 : |
  361. 3 : RChangeSize(W4)
  362. END ;
  363. END ;
  364. END P5;
  365. (* P6 Moves window 1 *)
  366. PROCEDURE P6 ;
  367. BEGIN
  368. Rmove(W1) ;
  369. END P6 ;
  370. (* P7 Moves window 2 *)
  371. PROCEDURE P7 ;
  372. BEGIN
  373. Rmove(W2) ;
  374. END P7;
  375. (* P8 Moves window 2 *)
  376. PROCEDURE P8 ;
  377. BEGIN
  378. Rmove(W3) ;
  379. END P8;
  380. (* P9 Moves window 2 *)
  381. PROCEDURE P9 ;
  382. BEGIN
  383. Rmove(W4) ;
  384. END P9 ;
  385. PROCEDURE Demo ;
  386. VAR
  387. WD : Window.WinDef ;
  388. BEGIN
  389. Lib.RANDOMIZE ;
  390. Initialize := TRUE ;
  391. Window.SetProcessLocks(Process.Lock,Process.Unlock) ;
  392. Window.CursorOff ;
  393. Window.Clear ;
  394. WITH WD DO
  395. X1 := 10 ; Y1 := 2 ;
  396. X2 := 60 ; Y2 := 8 ;
  397. Foreground := Window.White ;
  398. IF IsBW THEN
  399. Background := Window.Black ;
  400. ELSE
  401. Background := Window.Red ;
  402. END ;
  403. CursorOn := FALSE ;
  404. WrapOn := TRUE ;
  405. Hidden := FALSE ;
  406. FrameOn := TRUE ;
  407. FrameDef := Window.SingleFrame ;
  408. FrameFore := Window.White ;
  409. FrameBack := Background ;
  410. END ;
  411. W1 := Window.Open(WD) ;
  412. Window.SetTitle(W1,' Process 1 ',Window.CenterUpperTitle);
  413. WITH WD DO
  414. X1 := 40 ; Y1 := 2 ;
  415. X2 := 70 ; Y2 := 12 ;
  416. Foreground := Window.White ;
  417. Background := Window.Blue ;
  418. CursorOn := FALSE ;
  419. WrapOn := TRUE ;
  420. Hidden := FALSE ;
  421. FrameOn := TRUE ;
  422. FrameDef := Window.DoubleFrame ;
  423. FrameFore := Window.Black ;
  424. FrameBack := Window.Cyan ;
  425. IF IsBW THEN
  426. Background := Window.Black ;
  427. FrameBack := Window.LightGray
  428. END ;
  429. END ;
  430. W2 := Window.Open(WD) ;
  431. Window.SetTitle(W2,' Process 2 ',Window.CenterUpperTitle);
  432. RandPalette(pal) ;
  433. WITH WD DO
  434. X1 := 40 ; Y1 := 6 ;
  435. X2 := 50 ; Y2 := 17 ;
  436. pal[0].Fore:= Window.Yellow ;
  437. pal[0].Back:= Window.Black ;
  438. CursorOn := FALSE ;
  439. WrapOn := TRUE ;
  440. Hidden := FALSE ;
  441. FrameOn := TRUE ;
  442. FrameDef := Window.SingleFrame ;
  443. pal[1].Fore:= Window.White ;
  444. pal[1].Back:= Window.Green ;
  445. IF IsBW THEN
  446. pal[0].Fore:= Window.LightGray ;
  447. pal[1].Back:= Window.Black ;
  448. END ;
  449. END ;
  450. W3 := Window.PaletteOpen(WD,pal) ;
  451. Window.SetTitle(W3,'Process 3',Window.CenterUpperTitle);
  452. WITH WD DO
  453. X1 := 10 ; Y1 := 10 ;
  454. X2 := 70 ; Y2 := 20 ;
  455. Foreground := Window.Black ;
  456. Background := Window.LightGray ;
  457. CursorOn := FALSE ;
  458. WrapOn := TRUE ;
  459. Hidden := FALSE ;
  460. FrameOn := TRUE ;
  461. FrameDef := Window.DoubleFrame ;
  462. FrameFore := Window.White ;
  463. FrameBack := Window.Green ;
  464. IF IsBW THEN
  465. FrameBack := Window.Black ;
  466. END ;
  467. END ;
  468. W4 := Window.Open(WD) ;
  469. Window.SetTitle(W4,' Process 4 ',Window.CenterUpperTitle);
  470. Process.StartScheduler ;
  471. Process.StartProcess(P1,2000,1) ;
  472. Process.StartProcess(P2,2000,1) ;
  473. Process.StartProcess(P3,2000,1) ;
  474. Process.StartProcess(P4,2000,1) ;
  475. Process.StartProcess(P5,2000,1) ;
  476. Process.StartProcess(P6,2000,1) ;
  477. Process.StartProcess(P7,2000,1) ;
  478. Process.StartProcess(P8,2000,1) ;
  479. Process.StartProcess(P9,2000,1) ;
  480. Process.Init(DS) ;
  481. Process.WAIT(DS) ;
  482. Window.CursorOn ;
  483. END Demo;
  484. PROCEDURE CheckBW ;
  485. VAR
  486. R : SYSTEM.Registers ;
  487. BEGIN
  488. R.AH := 15 ;
  489. Lib.Intr(R,10H) ;
  490. IsBW := (R.AL = 0)OR(R.AL = 2)OR(R.AL = 5)OR(R.AL = 6)OR(R.AL = 7) ;
  491. END CheckBW ;
  492. BEGIN
  493. CheckBW ;
  494. Intro;
  495. Demo;
  496. END WinDemo.
  497.