]> pd.if.org Git - mmurtl/blob - msamples/dumbterm/dumbterm.c
autocommit for file dated 1995-02-09 16:03:42
[mmurtl] / msamples / dumbterm / dumbterm.c
1 /* Possibly the dumbest terminal program in existance... */\r
2 /* Simply here to demo the MMURTL device drive interface for comms */\r
3 /* Build with MakeIT.Bat, use CM32 and DASM separately:\r
4    CM32 DumbTerm.C\r
5    DASM DumbTerm.ATF\r
6 */\r
7 \r
8 #include <stdio.h>\r
9 #include <ctype.h>\r
10 #include <string.h>\r
11 \r
12 #include "\OSSOURCE\MDevDrv.h"\r
13 #include "\OSSOURCE\MJob.h"\r
14 #include "\OSSOURCE\MKbd.h"\r
15 #include "\OSSOURCE\MTimer.h"\r
16 #include "\OSSOURCE\MVid.h"\r
17 #include "\OSSOURCE\RS232.h"\r
18 \r
19 #define NORMVID BRITEWHITE|BGBLUE\r
20 #define CLIVID WHITE|BGBLACK\r
21 \r
22 unsigned long key;\r
23 \r
24 struct statRecC com;\r
25 \r
26 /*****************************************************/\r
27 /*****************************************************/\r
28 /*****************************************************/\r
29 /*****************************************************/\r
30 \r
31 void    main(void)\r
32 \r
33 {\r
34 \r
35 int           erc, i;\r
36 unsigned char b, lastb;\r
37 char          fOK;\r
38 \r
39 \r
40 SetNormVid(NORMVID);\r
41 ClrScr();\r
42 \r
43 printf("     Terminally DUMB, Dumb Terminal Program\r\n");\r
44 printf("      (MMURTL Comms Device Driver demo) \r\n");\r
45 \r
46 /* Get the 64 byte device status block which is specific to the\r
47 RS-232 device driver. The structure is defined in commdrv.h\r
48 */\r
49 \r
50  erc = DeviceStat(6, &com, 64, &i);\r
51 \r
52  if (erc) \r
53  {\r
54         SetNormVid(CLIVID);\r
55         ClrScr();\r
56         printf("Error on Device Stat: %d\r\n", erc);\r
57         ExitJob(erc);\r
58  }\r
59 \r
60   /* set the params in the block */\r
61 \r
62   com.Baudrate = 9600;\r
63   com.parity = NO_PAR;\r
64   com.databits = 8;\r
65   com.stopbits = 1;\r
66 \r
67 /* View other params which we could set, but should already be\r
68    defaulted with standard values when driver was initialized.\r
69 */\r
70 \r
71   printf("IRQNum: %d\r\n", com.IRQNum);\r
72   printf("IOBase: %d\r\n", com.IOBase);\r
73   printf("sXBuf:  %d\r\n", com.XBufSize);\r
74   printf("sRBuf:  %d\r\n", com.RBufSize);\r
75   printf("RTimeO: %d\r\n", com.RTimeOut);\r
76   printf("XTimeO: %d\r\n", com.XTimeOut);\r
77 \r
78 /* Set the params we changed with a DeviceInit */\r
79 \r
80  erc = DeviceInit(6, &com, 64);\r
81  if (erc) \r
82  {\r
83         SetNormVid(CLIVID);\r
84         ClrScr();\r
85         printf("Error on Device Init: %d\r\n", erc);\r
86         ExitJob(erc);\r
87  }\r
88 \r
89    /* If device init went OK, we open the comms port */\r
90 \r
91 \r
92                 /* device, dOpNum,   dLBA, dnBlocks, pData */\r
93         erc = DeviceOp(6,      CmdOpenC, 0,    0,        &i);\r
94 \r
95         if (erc) \r
96         {\r
97                 SetNormVid(CLIVID);\r
98                 ClrScr();\r
99             printf("OpenCommC ERROR: %d \r\n", erc);\r
100             ExitJob(erc);\r
101         }\r
102 \r
103     printf("Communications Port Initialized.\r\n");\r
104 \r
105         fOK = 1;\r
106 \r
107     /* This is it... */\r
108 \r
109         while (fOK) \r
110         {\r
111 \r
112                 if (!ReadKbd(&key, 0))          /* no wait */\r
113                 {\r
114                         b = key & 0x7f;\r
115 \r
116                         if (key & 0x3000) \r
117                         {               /* ALT key is down */\r
118                                 switch (toupper(b)) \r
119                                 {\r
120                                         case 'Q' :\r
121                                  /* device, dOpNum,   dLBA, dnBlocks, pData */\r
122                                                 erc = DeviceOp(6,    CmdCloseC, 0,  0,  &i);\r
123                                                 SetNormVid(CLIVID);\r
124                                                 ClrScr();\r
125                                                 ExitJob(erc);\r
126                                                 break;\r
127                                         default: break;\r
128                                 }\r
129                         }\r
130                         else \r
131                         {\r
132                 /* device, dOpNum,   dLBA, dnBlocks, pData */\r
133                                 erc = DeviceOp(6,    CmdWriteB, 0,  0,  &b);\r
134                                 if (erc)\r
135                                     printf("WriteByteCError: %d \r\n", erc);\r
136                                 else \r
137                                 {\r
138                     if (b == 0x0D) \r
139                     {\r
140                             b = 0x0A;\r
141                                                 erc = DeviceOp(6,    CmdWriteB, 0,  0,  &b);\r
142                                         }\r
143                                 }\r
144                     }\r
145                 }\r
146            /* device, dOpNum,   dLBA, dnBlocks, pData */\r
147                 erc = DeviceOp(6,    CmdReadB, 0,  0,  &b);\r
148                 if (!erc) \r
149                 {\r
150                                 TTYOut (&b, 1, NORMVID);\r
151                                 /* add a LF if it's not there after a CR... */\r
152                                 if ((lastb == 0x0D) && (b != 0x0A))\r
153                                         TTYOut ("\n", 1, NORMVID);\r
154                                 lastb = b;\r
155                 }\r
156         }\r
157 \r
158 }\r