Tools for working with Cidco Mailstations
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add util/tribble_getty

+141 -4
+6 -2
Makefile
··· 24 24 .endif 25 25 .endif 26 26 27 - all: objdir loader.bin codedump.bin datadump.bin recvdump sendload 27 + all: objdir loader.bin codedump.bin datadump.bin recvdump sendload tribble_getty 28 28 29 29 objdir: 30 30 @mkdir -p ${OBJ} 31 31 32 32 clean: 33 - rm -f *.{map,bin,ihx,lst,rel,sym,lk,noi} recvdump sendload 33 + rm -f *.{map,bin,ihx,lst,rel,sym,lk,noi} recvdump sendload tribble_getty 34 34 35 35 # parallel loader 36 36 loader.rel: loader.asm ··· 69 69 # program loader 70 70 sendload: util/sendload.c util/tribble.c 71 71 $(CC) $(CFLAGS) -o $@ $> $(IOPL_LIB) 72 + 73 + # tribble getty 74 + tribble_getty: util/tribble_getty.c util/tribble.c 75 + $(CC) $(CFLAGS) -o $@ $> $(IOPL_LIB) -lutil
+32 -2
util/tribble.c
··· 4 4 5 5 #include "tribble.h" 6 6 7 + int tribble_debug = 0; 8 + 9 + unsigned int 10 + havetribble(void) 11 + { 12 + int tries; 13 + 14 + /* drop busy */ 15 + outb(DATA, 0); 16 + 17 + /* wait for (inverted) strobe */ 18 + for (tries = 0; tries < 100; tries++) 19 + if ((inb(STATUS) & stbin) == 0) 20 + /* 21 + * leave busy dropped, assume recvtribble() will deal 22 + * with it 23 + */ 24 + return 1; 25 + 26 + /* re-raise busy */ 27 + outb(DATA, bsyout); 28 + 29 + return 0; 30 + } 31 + 7 32 unsigned char 8 33 recvtribble(void) 9 34 { 10 35 unsigned char b; 11 36 12 - /* drop busy/ack */ 37 + /* drop busy */ 13 38 outb(DATA, 0); 39 + 40 + if (tribble_debug) { 41 + printf("waiting for strobe..."); 42 + fflush(stdout); 43 + } 14 44 15 45 /* wait for (inverted) strobe */ 16 46 while ((inb(STATUS) & stbin) != 0) ··· 50 80 outb(DATA, b & tribmask); 51 81 52 82 /* strobe */ 53 - outb(DATA, b & tribmask | stbout); 83 + outb(DATA, (b & tribmask) | stbout); 54 84 55 85 /* wait for ack */ 56 86 while ((inb(STATUS) & bsyin) == 0)
+1
util/tribble.h
··· 11 11 #define tribmask 0x07 12 12 #define dibmask 0x03 13 13 14 + unsigned int havetribble(void); 14 15 unsigned char recvtribble(void); 15 16 unsigned char recvbyte(void); 16 17 void sendtribble(unsigned char b);
+102
util/tribble_getty.c
··· 1 + /* 2 + * tribble_getty 3 + * 4 + * must be run as root to set iopl and use inb/outb 5 + * 6 + * interfaces getty(8) to the parallel port tribble routines for sending and 7 + * receiving bytes 8 + * 9 + */ 10 + 11 + #include <stdio.h> 12 + #include <string.h> 13 + #include <signal.h> 14 + #include <err.h> 15 + #include <errno.h> 16 + #include <unistd.h> 17 + #include <termios.h> 18 + #include <util.h> 19 + #include <sys/types.h> 20 + #include <sys/stat.h> 21 + #include <machine/sysarch.h> 22 + #include <machine/pio.h> 23 + 24 + #include "tribble.h" 25 + 26 + int 27 + main(int argc, char *argv[]) 28 + { 29 + struct timeval tv = { 0 }; 30 + char obuf[BUFSIZ]; 31 + size_t cc, off; 32 + fd_set rfds; 33 + pid_t child; 34 + int master, slave; 35 + char b; 36 + 37 + if (geteuid() != 0) 38 + errx(1, "must be run as root"); 39 + 40 + #ifdef __OpenBSD__ 41 + #ifdef __amd64__ 42 + if (amd64_iopl(1) != 0) 43 + errx(1, "amd64_iopl failed (is machdep.allowaperture=1?)"); 44 + #elif defined(__i386__) 45 + if (i386_iopl(1) != 0) 46 + errx(1, "i386_iopl failed (is machdep.allowaperture=1?)"); 47 + #endif 48 + #endif 49 + 50 + if (openpty(&master, &slave, NULL, NULL, NULL) == -1) 51 + errx(1, "openpty"); 52 + 53 + child = fork(); 54 + if (child == 0) { 55 + char *argp[] = { "sh", "-c", NULL, NULL }; 56 + 57 + close(master); 58 + login_tty(slave); 59 + 60 + argp[2] = "/usr/libexec/getty"; 61 + execv("/bin/sh", argp); 62 + } 63 + 64 + close(STDIN_FILENO); 65 + 66 + for (;;) { 67 + FD_ZERO(&rfds); 68 + FD_SET(master, &rfds); 69 + tv.tv_usec = 10; 70 + 71 + if (select(master + 1, &rfds, NULL, NULL, &tv)) { 72 + cc = read(master, obuf, sizeof(obuf)); 73 + if (cc == -1 && errno == EINTR) 74 + continue; 75 + if (cc <= 0) 76 + break; 77 + 78 + for (off = 0; off < cc; off++) { 79 + #if 0 80 + printf("sendbyte(0x%x): %c\n", obuf[off], 81 + (obuf[off] >= 32 && obuf[off] <= 126 ? 82 + obuf[off] : ' ')); 83 + #endif 84 + sendbyte(obuf[off]); 85 + } 86 + } 87 + 88 + if (havetribble()) { 89 + b = recvbyte(); 90 + #if 0 91 + printf("recvbyte() = 0x%x: %c\n", b, 92 + (b >= 32 && b <= 126 ? b : ' ')); 93 + #endif 94 + write(master, &b, 1); 95 + } 96 + } 97 + 98 + close(master); 99 + close(slave); 100 + 101 + return 0; 102 + }