]> pd.if.org Git - mmurtl/commitdiff
autocommit for file dated 1995-02-09 15:55:22
authorRichard Burgess <>
Thu, 9 Feb 1995 15:55:22 +0000 (15:55 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 17 Oct 2016 14:03:48 +0000 (14:03 +0000)
msamples/dumbterm/dumbterm.c [new file with mode: 0644]

diff --git a/msamples/dumbterm/dumbterm.c b/msamples/dumbterm/dumbterm.c
new file mode 100644 (file)
index 0000000..5ff7633
--- /dev/null
@@ -0,0 +1,158 @@
+/* Possibly the dumbest terminal program in existance... */\r
+/* Simply here to demo the MMURTL device drive interface for comms */\r
+/* Build with MakeIT.Bat, use CM32 and DASM separately:\r
+   CM32 DumbTerm.C\r
+   DASM DumbTerm.ATF\r
+*/\r
+\r
+#include <stdio.h>\r
+#include <ctype.h>\r
+#include <string.h>\r
+\r
+#include "\OSSOURCE\MDevDrv.h"\r
+#include "\OSSOURCE\MJob.h"\r
+#include "\OSSOURCE\MKbd.h"\r
+#include "\OSSOURCE\MTimer.h"\r
+#include "\OSSOURCE\MVid.h"\r
+#include "\OSSOURCE\RS232.h"\r
+\r
+#define NORMVID BRITEWHITE|BGBLUE\r
+#define CLIVID WHITE|BGBLACK\r
+\r
+unsigned long key;\r
+\r
+struct statRecC com;\r
+\r
+/*****************************************************/\r
+/*****************************************************/\r
+/*****************************************************/\r
+/*****************************************************/\r
+\r
+void    main(void)\r
+\r
+{\r
+\r
+int           erc, i;\r
+unsigned char b, lastb;\r
+char          fOK;\r
+\r
+\r
+SetNormVid(NORMVID);\r
+ClrScr();\r
+\r
+printf("     Terminally DUMB, Dumb Terminal Program\r\n");\r
+printf("      (MMURTL Comms Device Driver demo) \r\n");\r
+\r
+/* Get the 64 byte device status block which is specific to the\r
+RS-232 device driver. The structure is defined in commdrv.h\r
+*/\r
+\r
+ erc = DeviceStat(6, &com, 64, &i);\r
+\r
+ if (erc) \r
+ {\r
+       SetNormVid(CLIVID);\r
+       ClrScr();\r
+       printf("Error on Device Stat: %d\r\n", erc);\r
+       ExitJob(erc);\r
+ }\r
+\r
+  /* set the params in the block */\r
+\r
+  com.Baudrate = 9600;\r
+  com.parity = NO_PAR;\r
+  com.databits = 8;\r
+  com.stopbits = 1;\r
+\r
+/* View other params which we could set, but should already be\r
+   defaulted with standard values when driver was initialized.\r
+*/\r
+\r
+  printf("IRQNum: %d\r\n", com.IRQNum);\r
+  printf("IOBase: %d\r\n", com.IOBase);\r
+  printf("sXBuf:  %d\r\n", com.XBufSize);\r
+  printf("sRBuf:  %d\r\n", com.RBufSize);\r
+  printf("RTimeO: %d\r\n", com.RTimeOut);\r
+  printf("XTimeO: %d\r\n", com.XTimeOut);\r
+\r
+/* Set the params we changed with a DeviceInit */\r
+\r
+ erc = DeviceInit(6, &com, 64);\r
+ if (erc) \r
+ {\r
+       SetNormVid(CLIVID);\r
+       ClrScr();\r
+       printf("Error on Device Init: %d\r\n", erc);\r
+       ExitJob(erc);\r
+ }\r
+\r
+   /* If device init went OK, we open the comms port */\r
+\r
+\r
+                /* device, dOpNum,   dLBA, dnBlocks, pData */\r
+       erc = DeviceOp(6,      CmdOpenC, 0,    0,        &i);\r
+\r
+       if (erc) \r
+       {\r
+               SetNormVid(CLIVID);\r
+               ClrScr();\r
+           printf("OpenCommC ERROR: %d \r\n", erc);\r
+           ExitJob(erc);\r
+       }\r
+\r
+    printf("Communications Port Initialized.\r\n");\r
+\r
+       fOK = 1;\r
+\r
+    /* This is it... */\r
+\r
+       while (fOK) \r
+       {\r
+\r
+               if (!ReadKbd(&key, 0))          /* no wait */\r
+               {\r
+                       b = key & 0x7f;\r
+\r
+                       if (key & 0x3000) \r
+                       {               /* ALT key is down */\r
+                               switch (toupper(b)) \r
+                               {\r
+                                       case 'Q' :\r
+                                /* device, dOpNum,   dLBA, dnBlocks, pData */\r
+                                               erc = DeviceOp(6,    CmdCloseC, 0,  0,  &i);\r
+                                               SetNormVid(CLIVID);\r
+                                               ClrScr();\r
+                                               ExitJob(erc);\r
+                                               break;\r
+                                       default: break;\r
+                               }\r
+                       }\r
+                       else \r
+                       {\r
+                /* device, dOpNum,   dLBA, dnBlocks, pData */\r
+                               erc = DeviceOp(6,    CmdWriteB, 0,  0,  &b);\r
+                               if (erc)\r
+                                   printf("WriteByteCError: %d \r\n", erc);\r
+                               else \r
+                               {\r
+                    if (b == 0x0D) \r
+                    {\r
+                           b = 0x0A;\r
+                                               erc = DeviceOp(6,    CmdWriteB, 0,  0,  &b);\r
+                                       }\r
+                               }\r
+                   }\r
+               }\r
+           /* device, dOpNum,   dLBA, dnBlocks, pData */\r
+               erc = DeviceOp(6,    CmdReadB, 0,  0,  &b);\r
+               if (!erc) \r
+               {\r
+                               TTYOut (&b, 1, NORMVID);\r
+                               /* add a LF if it's not there after a CR... */\r
+                               if ((lastb == 0x0D) && (b != 0x0A))\r
+                                       TTYOut ("\n", 1, NORMVID);\r
+                               lastb = b;\r
+               }\r
+       }\r
+\r
+}\r