diff --git a/mdl/mdltest0.pas b/mdl/mdltest0.pas new file mode 100644 index 0000000..292efdc --- /dev/null +++ b/mdl/mdltest0.pas @@ -0,0 +1,17 @@ +program test0; + +uses + crt; + +var ch : char; + +begin + repeat + ch := readkey; + + if ch = #0 then + writeln('Extended: ', ord(ch)) + else + writeln('Got: ' + ch + ' ', ord(ch)); + until ch = #27; +end. diff --git a/mdl/mdltest1.pas b/mdl/mdltest1.pas new file mode 100644 index 0000000..c7c811d --- /dev/null +++ b/mdl/mdltest1.pas @@ -0,0 +1,46 @@ +Program TestIO_1; + +{$I M_OPS.PAS} + +Uses + m_Input, + m_Output, + m_Strings; + +Var + Keyboard : TInput; + Screen : TOutput; + TempChar : Char; + IdleCount : LongInt; +Begin + Keyboard := TInput.Create; + Screen := TOutput.Create(True); + + Screen.SetWindowTitle('MDL: TEST #1'); + Screen.WriteLine('MDL: Input/Output test program. (ESCAPE) to Quit'); + Screen.SetWindow(1, 3, 80, 25, True); + + IdleCount := 0; + + Repeat + If Keyboard.KeyWait(1000) Then Begin + IdleCount := 0; + TempChar := Keyboard.ReadKey; + Case TempChar of + #0 : Screen.WriteLine('Extended key: ' + strI2S(Ord(Keyboard.ReadKey))); + #27 : Begin + Screen.WriteLine('Escape pressed!'); + Break; + End; + Else + Screen.WriteLine('Key pressed: ' + TempChar); + End; + End Else Begin + Inc (IdleCount); + Screen.WriteLine('No key has been pressed (for ' + strI2S(IdleCount) + ' seconds)'); + End; + Until False; + + Keyboard.Free; + Screen.Free; +End. diff --git a/mdl/mdltest2.pas b/mdl/mdltest2.pas new file mode 100644 index 0000000..a53b543 --- /dev/null +++ b/mdl/mdltest2.pas @@ -0,0 +1,211 @@ +Program TESTIO_2; + +{$I M_OPS.PAS} + +Uses + m_Types, + m_Strings, + m_Input, + m_Output, + m_MenuBox, + m_MenuForm; + +Const + { TheDraw Pascal Crunched Screen Image. Date: 09/03/02 } + TESTMAIN_WIDTH=80; + TESTMAIN_LENGTH=128; + TESTMAIN : array [1..128] of Char = ( + #15,#16,#26,'N','Ü', #7,'Ü',#24,#15,'Û',#23,#25,'M', #8,#16,'Û',#24, + #7,'ß', #8,#26,'N','ß',#24,#26,'O','°',#24,#26,'O','°',#24,#26,'O', + '°',#24,#26,'O','°',#24,#26,'O','°',#24,#26,'O','°',#24,#26,'O','°', + #24,#26,'O','°',#24,#26,'O','°',#24,#26,'O','°',#24,#26,'O','°',#24, + #26,'O','°',#24,#26,'O','°',#24,#26,'O','°',#24,#26,'O','°',#24,#26, + 'O','°',#24,#26,'O','°',#24,#26,'O','°',#24,#26,'O','°',#24,#26,'O', + '°',#24,#26,'@','Ä',' ',#26, #3,'Ä',' ','Ä','Ä',' ',' ','Ä',' ',' ', + 'ù',#24,#15,':', #7,':', #8,':',#24); + +Var + Screen : TOutput; + Menu : TMenuForm; + Box : TMenuBox; + Image : TConsoleImageRec; + MenuPosition : Byte; + Res : Char; + +Procedure BoxOpen (X1, Y1, X2, Y2: Byte); +Begin + Box := TMenuBox.Create(Screen); + + Box.Open(X1, Y1, X2, Y2); +End; + +Procedure BoxClose; +Begin + Box.Close; + Box.Free; +End; + +Procedure CoolBoxOpen (X1: Byte; Text: String); +Var + Len : Byte; +Begin + Len := Length(Text) + 6; + + Screen.GetScreenImage(X1, 1, X1 + Len, 3, Image); + + Screen.WriteXYPipe (X1, 1, 8, Len, 'Ü|15Ü|11ÜÜ|03ÜÜ|09Ü|03Ü|09' + strRep('Ü', Len - 9) + '|08Ü'); + Screen.WriteXYPipe (X1 ,2, 8, Len, 'Ý|09|17² |15' + Text + ' |00°|16|08Þ'); + Screen.WriteXYPipe (X1, 3, 8, Len, 'ß|01²|17 |11À|03ÄÄ|08' + strRep('Ä', Length(Text) - 4) + '|00¿ ±|16|08ß'); +End; + +Procedure CoolBoxClose; +Begin + Screen.PutScreenImage(Image); +End; + +Procedure AboutBox; +Begin + BoxOpen (19, 7, 62, 19); + + Screen.WriteXY (21, 8, 31, strPadC('Test IO Program', 40, ' ')); + Screen.WriteXY (21, 9, 112, strRep('-', 40)); + Screen.WriteXY (26, 11, 113, 'Copyright (C) 2003 By No One'); + Screen.WriteXY (31, 12, 113, 'All Rights Reserved'); + Screen.WriteXY (21, 14, 113, strPadC('Version 1.00', 40, ' ')); + Screen.WriteXY (32, 16, 113, 'www.someplace.com'); + Screen.WriteXY (21, 17, 112, strRep('-', 40)); + Screen.WriteXY (21, 18, 31, strPadC('(PRESS A KEY)', 40, ' ')); + + Menu.Input.ReadKey; + + BoxClose; +End; + +Procedure FormTest; +Var + MyBox : TMenuBox; + MyForm : TMenuForm; + Data : Array[1..9] of String; +Begin + MyBox := TMenuBox.Create(Screen); + MyForm := TMenuForm.Create(Screen); + + MyBox.Header := ' Input Test '; + + MyBox.Open (5, 6, 75, 18); + + MyForm.AddStr ('1', ' String Test #1 ', 8, 8, 28, 8, 16, 45, 60, @Data[1], 'String input test #1'); + MyForm.AddStr ('2', ' String Test #2 ', 8, 9, 28, 9, 16, 45, 60, @Data[2], 'String input test #2'); + MyForm.AddStr ('3', ' String Test #3 ', 8, 10, 28, 10, 16, 45, 60, @Data[3], 'String input test #3'); + MyForm.AddStr ('4', ' String Test #4 ', 8, 11, 28, 11, 16, 45, 60, @Data[4], 'String input test #4'); + MyForm.AddStr ('5', ' String Test #5 ', 8, 12, 28, 12, 16, 45, 60, @Data[5], 'String input test #5'); + MyForm.AddStr ('6', ' String Test #6 ', 8, 13, 28, 13, 16, 45, 60, @Data[6], 'String input test #6'); + MyForm.AddStr ('7', ' String Test #7 ', 8, 14, 28, 14, 16, 45, 60, @Data[7], 'String input test #7'); + MyForm.AddStr ('8', ' String Test #8 ', 8, 15, 28, 15, 16, 45, 60, @Data[8], 'String input test #8'); + MyForm.AddStr ('9', ' String Test #9 ', 8, 16, 28, 16, 16, 45, 60, @Data[9], 'String input test #9'); + + MyForm.Execute; + + Box.Close; + + MyForm.Free; + MyBox.Free; +End; + +Begin + Screen := TOutput.Create(True); + Menu := TMenuForm.Create(Screen); + + Screen.SetWindowTitle('IO TEST #2'); + Screen.LoadScreenImage(TESTMAIN, TESTMAIN_LENGTH, TESTMAIN_WIDTH, 1, 1); + + MenuPosition := 0; + + Repeat + Menu.Clear; + + If MenuPosition = 0 Then Begin + Menu.HiExitChars := #80; + Menu.ExitOnFirst := False; + End Else Begin + Menu.HiExitChars := #75#77; + Menu.ExitOnFirst := True; + End; + + Case MenuPosition of + 0 : Begin + Menu.AddNone('M', ' Main Menu ', 3, 2, 11, 'Menu menu options'); + Menu.AddNone('X', ' Exit ' , 16, 2, 6, 'Exit/About options'); + + Res := Menu.Execute; + + If Menu.WasHiExit Then + MenuPosition := Menu.ItemPos + Else + Case Res of + #27 : Break; + 'M' : MenuPosition := 1; + 'X' : MenuPosition := 2; + End; + End; + 1 : Begin + BoxOpen (2, 4, 20, 9); + CoolBoxOpen (1, 'Main Menu'); + + Menu.AddNone ('F', ' Form/Input Test ', 3, 5, 17, 'Test form and input functions'); + Menu.AddNone ('N', ' Nothing #1' , 3, 6, 17, 'Nothing at all #1'); + Menu.AddNone ('N', ' Nothing #2' , 3, 7, 17, 'Nothing at all #2'); + Menu.AddNone ('N', ' Nothing #3' , 3, 8, 17, 'Nothing at all #3'); + + Res := Menu.Execute; + + BoxClose; + CoolBoxClose; + + If Menu.WasHiExit Then Begin + Case Res of + #75 : MenuPosition := 2; + #77 : MenuPosition := 2; + End; + End Else + Case Res of + 'F' : FormTest; + 'N' : ; + Else + MenuPosition := 0; + End; + End; + 2 : Begin + BoxOpen (15, 4, 23, 7); + CoolBoxOpen (14, 'Exit'); + + Menu.AddNone ('A', ' About ', 16, 5, 7, 'About this test program'); + Menu.AddNone ('X', ' Exit ' , 16, 6, 7, 'Exit this program'); + + Res := Menu.Execute; + + BoxClose; + CoolBoxClose; + + If Menu.WasHiExit Then Begin + Case Res of + #75 : MenuPosition := 1; + #77 : MenuPosition := 1; + End; + End Else + Case Res of + 'A' : AboutBox; + 'X' : Break; + Else + MenuPosition := 0; + End; + End; + End; + Until False; + + Screen.ClearScreen; + Screen.WriteLine('MDL: Test Program #2 Completed'); + + Menu.Free; + Screen.Free; +End. diff --git a/mdl/mdltest3.pas b/mdl/mdltest3.pas new file mode 100644 index 0000000..17df42d --- /dev/null +++ b/mdl/mdltest3.pas @@ -0,0 +1,40 @@ +Program Test3; + +{$I m_ops.pas} + +Uses + m_Socket_Class; + +Var + Server : TSocketClass; + Client : TSocketClass; + Str : String; +Begin + Server := TSocketClass.Create; + + Server.WaitInit(23); + + WriteLn('Waiting on port 23 for TEST4 client example...'); + + Client := Server.WaitConnection; + + If Client = NIL Then Begin + WriteLn ('An error has occured; no client detected'); + Server.Free; + Halt; + End; + + WriteLn; + WriteLn ('Got connection from:'); + WriteLn (' Host: ', Client.FPeerName); + WriteLn (' IP: ', Client.FPeerIP); + WriteLn; + + Client.WriteLine('Welcome to the MDL test server!'); + Client.ReadLine(Str); + + WriteLn('Received: ', Str); + + Server.Free; + Client.Free; +End. diff --git a/mdl/mdltest4.pas b/mdl/mdltest4.pas new file mode 100644 index 0000000..7466ce8 --- /dev/null +++ b/mdl/mdltest4.pas @@ -0,0 +1,26 @@ +Program Test4; + +Uses + m_Socket_Class; + +Var + Client : TSocketClass; + Str : String; +Begin + Client := TSocketClass.Create; + + WriteLn ('Attempting to connect to localhost port 23 for TEST3 server test'); + + If Not Client.Connect ('localhost', 23) Then Begin + WriteLn ('Connection failed'); + Client.Free; + Halt; + End; + + Client.ReadLine(Str); + + WriteLn('Received: ', Str); + Client.WriteLine ('Client connection successful!'); + + Client.Free; +End. diff --git a/mdl/mdltest5.pas b/mdl/mdltest5.pas new file mode 100644 index 0000000..c5bc9ae --- /dev/null +++ b/mdl/mdltest5.pas @@ -0,0 +1,120 @@ +Program TEST5; + +Uses + m_Types, + m_Input, + m_Output, + m_Socket_Class, + m_DateTime, + m_Term_Ansi, + m_Strings; + +Var + Input : TInput; + Output : TOutput; + Client : TSocketClass; + Term : TTermAnsi; + +Procedure Init; +Begin + Input := TInput.Create; + Output := TOutput.Create(True); + Client := TSocketClass.Create; + Term := TTermAnsi.Create(Output); +End; + +Procedure Cleanup; +Begin + Client.Free; + Term.Free; + Output.Free; + Input.Free; +End; + +Var + Ch : Char; + Res : LongInt; + Buf : Array[1..1024] of Char; + Done : Boolean; + Image : TConsoleImageRec; +Begin + Init; + + If ParamCount <> 2 Then Begin + Output.WriteLine('Invalid options: test5 [address] [port]'); + Cleanup; + Halt; + End; + + Output.WriteStr ('Connecting to: ' + ParamStr(1) + ':' + ParamStr(2) + '. '); + + If Not Client.Connect(ParamStr(1), strS2I(ParamStr(2))) Then Begin + Output.WriteLine('Unable to connect'); + Cleanup; + Halt; + End; + + Output.WriteLine('Connected!'); + Output.SetWindowTitle('MDL Terminal Demo'); + + Client.SetBlocking(False); + Term.SetReplyClient(Client); + + Output.TextAttr := 7; + Output.ClearScreen(); + Output.WriteXYPipe (1, 25, 15 + 1 * 16, 79, ' MDL Terminal Demo '); + Output.SetWindow(1, 1, 80, 24, True); + + Done := False; + + Repeat + If Input.KeyPressed Then Begin + Ch := Input.ReadKey; + + Case Ch of + #00 : Case Input.ReadKey of + #45 : Break; + #71 : Client.WriteStr(#27 + '[H'); + #72 : Client.WriteStr(#27 + '[A'); + #73 : Client.WriteStr(#18); + #75 : Client.WriteStr(#27 + '[D'); + #77 : Client.WriteStr(#27 + '[C'); + #79 : Client.WriteStr(#27 + '[K'); + #80 : Client.WriteStr(#27 + '[B'); + #81 : Client.WriteStr(#3); + #83 : Client.WriteStr(#127); + #34 : Begin + Output.GetScreenImage(1, 1, 80, 25, Image); + End; + #25 : Begin + Output.ClearScreen; + Output.PutScreenImage(Image); + End; + ^C : Break; + End; + End; + + Client.WriteBuf(Ch, 1); + End Else + If Client.WaitForData(10) > 0 Then Begin + Repeat + Res := Client.ReadBuf(Buf, SizeOf(Buf)); + + If Res < 0 Then Begin + Done := True; + Break; + End; + + Term.ProcessBuf(Buf[1], Res); + + Until Res <> SizeOf(Buf); + End Else + WaitMS(10); + Until Done; + + Output.WriteLine(''); + Output.WriteLine('Connection terminated.'); + Output.SetWindow(1, 1, 80, 25, False); + + Cleanup; +End. diff --git a/mdl/mdltest6.pas b/mdl/mdltest6.pas new file mode 100644 index 0000000..a44afa3 --- /dev/null +++ b/mdl/mdltest6.pas @@ -0,0 +1,33 @@ +Program Test6; + +{$I M_OPS.PAS} + +Uses + m_Input, + m_Output; + +Var + Keyboard : TInput; + Screen : TOutput; + TempChar : Char; +Begin + Keyboard := TInput.Create; + Screen := TOutput.Create(True); + + Screen.WriteLine('MDL: Input/Output test program. (ESCAPE) to Quit'); + Screen.SetWindow(1, 3, 80, 25, True); + + Repeat + If Keyboard.KeyPressed Then Begin + TempChar := Keyboard.ReadKey; + + If TempChar = #27 Then + Break + Else + Screen.WriteLine('Key pressed: ' + TempChar); + End; + Until False; + + Keyboard.Free; + Screen.Free; +End. diff --git a/mdl/mdltest7.pas b/mdl/mdltest7.pas new file mode 100644 index 0000000..cbe585e --- /dev/null +++ b/mdl/mdltest7.pas @@ -0,0 +1,120 @@ +Program Test7; + +{$I M_OPS.PAS} + +Uses + m_Types, + m_Strings, + m_Output, + m_Input, + m_MenuBox; + +Var + Screen : TOutput; + Input : TInput; + +Procedure UpdateBottom (Num: Word; Str: String); +Var + Image : TConsoleImageRec; + Count : Byte; +Begin + Screen.GetScreenImage(1, 1, 80, 25, Image); + + For Count := 1 to 24 Do + Screen.WriteLineRec(26 + Count, Image.Data[Count]); +End; + +Var + Box : TMenuBox; + List : TMenuList; + Count : Byte; + Image : TConsoleImageRec; +Begin + Screen := TOutput.Create(True); + Input := TInput.Create; + + Screen.SetScreenSize(50); + Screen.ClearScreen; + + For Count := 1 to 24 Do + Screen.WriteXY(1, Count, 8, strRep('°', 80)); + + For Count := 1 to 24 Do + If Odd(Count) Then + Screen.WriteXY(5, Count, 8, '123456789012345678901234567890123456789012345678901234567890123456789012345') + Else + Screen.WriteXY(5, Count, 9, '098765432109876543210987654321098765432109876543210987654321098765432109876'); + + + For Count := 1 to 25 Do + Screen.WriteXY(1, Count, 7, strI2S(Count)); + + UpdateBottom(1, ''); + + Input.ReadKey; + + Screen.WriteXY(3, 5, 7, 'This is a test of some random text'); + Screen.WriteXYPipe(3,6, 7, 80, '|12And this is also random text'); + Screen.CursorXY (50, 15); + Screen.WriteStr('And some more text here too!'); + + UpdateBottom(1, ''); + + Input.ReadKey; + + Box := TMenuBox.Create(Screen); + + Box.Open(3, 6, 75, 23); + + UpdateBottom(1, ''); + + Input.ReadKey; + + Screen.GetScreenImage(1, 1, 80, 25, Image); + + Screen.ClearScreen; + Screen.WriteLine('Press a key to restore screen.'); + Input.ReadKey; + Screen.PutScreenImage(Image); + + UpdateBottom(1, ''); + + Input.ReadKey; + + // Screen.WriteXY(20, 18, 15, '12345678901234567890123456789012345678901234567890'); + Box.Close; + Box.Free; + + UpdateBottom(1, ''); + + Input.ReadKey; + + Repeat + List := TMenuList.Create(Screen); + + List.Add('Option 1', 0); + List.Add('Option 2', 0); + List.Add('Exit', 0); + + List.SetStatusProc(@UpdateBottom); + + List.Open(20, 8, 70, 17); + List.Close; + List.Free; + Until List.Picked = 3; + + UpdateBottom(1, ''); + + Input.ReadKey; + + Screen.ClearScreen; + + Screen.WriteLine('Press a key to end'); + + UpdateBottom(1, ''); + + Input.ReadKey; + + Input.Free; + Screen.Free; +End. diff --git a/mdl/mdltest8.pas b/mdl/mdltest8.pas new file mode 100644 index 0000000..8319c1c --- /dev/null +++ b/mdl/mdltest8.pas @@ -0,0 +1,32 @@ +Program Test8; + +Uses + m_Output, + m_DateTime, + m_Strings; + +Procedure WriteLine(S:String); +Var + A:Byte; +Begin + for a := 1 to length(s) do write(s[a]); +End; + + +Var + StartTime, + EndTime : LongInt; + Count : LongInt; + Screen : TOutput; +Begin + Screen := TOutput.Create(True); + + StartTime := TimerSeconds; + + For Count := 1 to 5000 Do + Screen.WriteStr('This is a test of the emergency broadcast system and I hope it is fast' + #13#10); + + EndTime := TimerSeconds; + + screen.WriteLine('Time was: ' + strI2S(EndTime - StartTime)); +End.