Add README.md
[pdp8.git] / sw / dumprest / original / dumbterm.c
CommitLineData
81e70d48
PH
1/* This program will act as a dumb terminal, sending characters typed to
2 the PDP-8 and printing characters received. Can be used to test the
3 serial communications.
4
5 The 8th bit is stripped for printing and set for sending to the PDP-8.
6
7 On the PC ctrl-break will terminate the program
8*/
9#ifdef PC
10#include "encom.h"
11#include <io.h>
12#else
13#include <termios.h>
14#include <unistd.h>
15#include <memory.h>
16#endif
17
18#include <stdio.h>
19#include <fcntl.h>
20#include <time.h>
21#include <signal.h>
22#include <stdlib.h>
23#include <string.h>
24
25#define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
26
27int terminate = 0;
28
29#include "config.c"
30#include "comm.c"
31
32#ifndef STDOUT_FILENO
33#define STDOUT_FILENO 0
34#endif
35
36main(argc,argv)
37 int argc;
38 char *argv[];
39{
40 int fd;
41 char serial_dev[256];
42 long baud;
43 int two_stop;
44 unsigned char buf[256];
45 int rc;
46 int cntr;
47
48 printf("Enter ^I (control-I) or ^break to terminate program\n");
49 setup_config(&baud,&two_stop,serial_dev);
50
51 fd = init_comm(serial_dev,baud,two_stop);
52
53 while(!terminate) {
54 if ((rc = getchar_nonblock()) > 0) {
55 buf[0] = rc | 0x80;
56 ser_write(fd,(char *)buf,1);
57 if (rc == '\n') {
58 buf[0] = '\r' | 0x80;
59 ser_write(fd,(char *)buf,1);
60 }
61 }
62 if ((rc = ser_read(fd,(char *) buf,sizeof(buf))) < 0) {
63 perror("\nstdin read failed\n");
64 exit(1);
65 }
66 if (rc > 0) {
67 for (cntr = 0; cntr < rc; cntr++)
68 buf[cntr] &= 0x7f;
69 write(STDOUT_FILENO, buf, rc);
70 }
71 }
72 printf("Done\n");
73 exit(0);
74 return(0);
75}