/* * This function creates and initializes a pair of ttys. */ static void nmdminit(int n) { cdev_t dev1, dev2; struct nm_softc *pt; /* * Simplified unit number, use low 8 bits of minor number * (remember, the minor number mask is 0xffff00ff). */ if (n & ~0x7f) return; pt = kmalloc(sizeof(*pt), M_NLMDM, M_WAITOK | M_ZERO); pt->part1.dev = dev1 = make_dev(&nmdm_ops, n << 1, 0, 0, 0666, "nmdm%dA", n); pt->part2.dev = dev2 = make_dev(&nmdm_ops, (n << 1) + 1, 0, 0, 0666, "nmdm%dB", n); dev1->si_drv1 = dev2->si_drv1 = pt; dev1->si_tty = &pt->part1.nm_tty; dev2->si_tty = &pt->part2.nm_tty; ttyinit(&pt->part1.nm_tty); ttyinit(&pt->part2.nm_tty); ttyregister(&pt->part1.nm_tty); ttyregister(&pt->part2.nm_tty); pt->part1.nm_tty.t_oproc = nmdmstart; pt->part2.nm_tty.t_oproc = nmdmstart; pt->part1.nm_tty.t_stop = nmdmstop; pt->part2.nm_tty.t_dev = dev1; pt->part1.nm_tty.t_dev = dev2; pt->part2.nm_tty.t_stop = nmdmstop; }
/* Set modes */ void hmode(void) { switch(parry[0]) { case 1: mapplication=1; break; case 3: ttyinit(); break; case 4: minsert=1; break; case 6: dowrap=0; minmargins=1; parry[0]=0; parry[1]=0; pos(); break; case 7: mautowrap=1; break; case 20: mnl=1; break; case 25: minvisable=0; cpos(x,y); break; } }
/* Reset modes */ void lmode(void) { switch(parry[0]) { case 1: mapplication=0; break; case 3: ttyinit(); break; case 4: minsert=0; break; case 6: dowrap=0; minmargins=0; parry[0]=0; parry[1]=0; pos(); break; case 7: dowrap=0; mautowrap=0; break; case 20: mnl=0; break; case 25: minvisable=1; cpos(width,height); break; } }
void ttyout(unsigned char c) { switch(mode) { /* Print mode */ case 5: if(c==6) break; pp(c); return; /* No prefix characters */ case 0: switch(c) { case 6: mode=5; return; /* Pass-thru printing */ case 7: bell(); break; case 8: dowrap=0; bs(); break; case 9: tab(); break; case 10: case 11: case 12: dowrap=0; if(mnl) cr(); lf(); break; case 13: dowrap=0; cr(); break; case 27: mode=1; return; case 0x84: dowrap=0; lf(); break; case 0x85: dowrap=0; cr(); lf(); break; case 0x88: settab(); break; case 0x8d: dowrap=0; ups(); break; case 0x9b: begin(); mode=2; return; default: if(minsert) insc(c); else type(c); } break; /* ESC has been received */ case 1: switch(c) { case 27: return; case '[': begin(); mode=2; return; case 'D': dowrap=0; lf(); break; case 'E': dowrap=0; cr(); lf(); break; case 'H': settab(); break; case 'M': dowrap=0; ups(); break; case '#': mode=3; return; } break; /* ESC [ or 0x9B has been received */ case 2: /* Enter numbers */ switch(c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': parry[nptr]=parry[nptr]*10+c-'0'; return; case ';': if(MAXPARMS== ++nptr) break; else return; case 27: mode=1; return; case '[': begin(); return; case 'c': ttyinit(); break; case 'p': dowrap=0; break; /* Reset what? */ case 'r': dowrap=0; setregn(); break; case 'm': setattrib(); break; case 'J': clrs(); break; case 'K': clrl(); break; case 'X': clrc(); break; case 'H': dowrap=0; pos(); break; case 'C': dowrap=0; right(); break; case 'D': dowrap=0; left(); break; case 'A': dowrap=0; up(); break; case 'B': dowrap=0; down(); break; case 'g': clrt(); break; case 'M': dell(); break; case 'L': insl(); break; case 'P': delc(); break; case '@': inss(); break; case 'h': hmode(); break; case 'l': lmode(); break; case '!': case '?': return; } break; /* ESC # has been received */ case 3: switch(c) { case 27: mode=1; return; case '[': begin(); mode=2; return; } break; } mode=0; }
main(int argc,char *argv[]) { long old; int sport= -1; /* Serial port number */ long baud= -1; /* Baud rate */ int vecno= -1; /* Vector number */ int port= -1; /* Printer port number */ unsigned short c; if(argc!=3) { oops: fprintf(stderr,"jterm COMx:[BAUD][,IRQ] LPy:\n"); exit(1); } sscanf(argv[1],"com%d:%ld,%d",&sport,&baud,&vecno); if(sport== -1) sscanf(argv[1],"COM%d:%ld,%d",&sport,&baud,&vecno); sscanf(argv[2],"lp%d:",&port); if(port== -1) sscanf(argv[2],"LP%d:",&port); --sport; if(port<0 || port>2 || sport<0 || sport>3) goto oops; /* Install break interrupt handler */ disable(); old= *(long far *)0x0000006C; *(long far *)0x0000006C=(long)brkint; enable(); if(vecno== -1) vecno=ints[sport]; else vecno+=8; if(baud!= -1) spbaud(ports[sport],baud); /* Open serial port */ spopen(ports[sport],vecno,1<<(vecno-8)); /* Open parallel port */ port=lports[port]; /* Initialize tty */ ttyinit(); loop: /* Print chracters */ if(psize) if(pcheck(port)) { pout(port,pbuf[pold++]); if(pold==pbufsiz) pold=0; psize--; } if(intflg) { intflg=0; spbreak(); } /* Check keyboard */ /* The trick here is to use the DOS interrupt 6 instead of the bios interrupt. * This eliminates untold numbers of problems with ^C and Ctrl-Break for * some microsoft's-programmers-only-know reason. */ _DL=0xFF; _AH=0x6; geninterrupt(0x21); __emit__(0x75,0x2,0x31,0xC0); /* Clear AX if no chars ready */ c=_AX; if(c) { c&=0xFF; if(!c) { _DL=0xFF; _AH=0x6; geninterrupt(0x21); c=_AX; c<<=8; } /* Check for exit key */ if((c&0xff)==']'-64) { spclose(); disable(); *(long far *)0x0000006C=old; enable(); bioscpos(0,height-1); exit(1); } if(c&0xff) spputc(c&0xff); /* ASCII code */ else switch(c) /* Xenix special keys */ { case 0x0300: spputc(0); break; case 0x4800: spputc('\033'); if(mapplication) spputc('O'), spputc('A'); else spputc('['), spputc('A'); break; case 0x5000: spputc('\033'); if(mapplication) spputc('O'), spputc('B'); else spputc('['), spputc('B'); break; case 0x4d00: spputc('\033'); if(mapplication) spputc('O'), spputc('C'); else spputc('['), spputc('C'); break; case 0x4b00: spputc('\033'); if(mapplication) spputc('O'), spputc('D'); else spputc('['), spputc('D'); break; case 0x4700: spputc('\033'), spputc('['), spputc('H'); break; case 0x4f00: spputc('\033'), spputc('['), spputc('F'); break; case 0x4900: spputc('\033'), spputc('['), spputc('I'); break; case 0x5100: spputc('\033'), spputc('['), spputc('G'); break; case 0x5200: spputc('\033'), spputc('['), spputc('L'); break; case 0x5300: spputc(127); break; case 0x0f00: spputc('\033'), spputc('['), spputc('Z'); break; case 0x3b00: spputc('\033'), spputc('['), spputc('M'); break; case 0x3c00: spputc('\033'), spputc('['), spputc('N'); break; case 0x3d00: spputc('\033'), spputc('['), spputc('O'); break; case 0x3e00: spputc('\033'), spputc('['), spputc('P'); break; case 0x3f00: spputc('\033'), spputc('['), spputc('Q'); break; case 0x4000: spputc('\033'), spputc('['), spputc('R'); break; case 0x4100: spputc('\033'), spputc('['), spputc('S'); break; case 0x4200: spputc('\033'), spputc('['), spputc('T'); break; case 0x4300: spputc('\033'), spputc('['), spputc('U'); break; case 0x4400: spputc('\033'), spputc('['), spputc('V'); break; case 0x5400: spputc('\033'), spputc('['), spputc('Y'); break; case 0x5500: spputc('\033'), spputc('['), spputc('Z'); break; case 0x5600: spputc('\033'), spputc('['), spputc('a'); break; case 0x5700: spputc('\033'), spputc('['), spputc('b'); break; case 0x5800: spputc('\033'), spputc('['), spputc('c'); break; case 0x5900: spputc('\033'), spputc('['), spputc('d'); break; case 0x5a00: spputc('\033'), spputc('['), spputc('e'); break; case 0x5b00: spputc('\033'), spputc('['), spputc('f'); break; case 0x5c00: spputc('\033'), spputc('['), spputc('g'); break; case 0x5d00: spputc('\033'), spputc('['), spputc('h'); break; case 0x5e00: spputc('\033'), spputc('['), spputc('k'); break; case 0x5f00: spputc('\033'), spputc('['), spputc('l'); break; case 0x6000: spputc('\033'), spputc('['), spputc('m'); break; case 0x6100: spputc('\033'), spputc('['), spputc('n'); break; case 0x6200: spputc('\033'), spputc('['), spputc('o'); break; case 0x6300: spputc('\033'), spputc('['), spputc('p'); break; case 0x6400: spputc('\033'), spputc('['), spputc('q'); break; case 0x6500: spputc('\033'), spputc('['), spputc('r'); break; case 0x6600: spputc('\033'), spputc('['), spputc('s'); break; case 0x6700: spputc('\033'), spputc('['), spputc('t'); break; case 0x6800: spputc('\033'), spputc('['), spputc('w'); break; case 0x6900: spputc('\033'), spputc('['), spputc('x'); break; case 0x6a00: spputc('\033'), spputc('['), spputc('y'); break; case 0x6b00: spputc('\033'), spputc('['), spputc('z'); break; case 0x6c00: spputc('\033'), spputc('['), spputc('@'); break; case 0x6d00: spputc('\033'), spputc('['), spputc('['); break; case 0x6e00: spputc('\033'), spputc('['), spputc('\\'); break; case 0x6f00: spputc('\033'), spputc('['), spputc(']'); break; case 0x7000: spputc('\033'), spputc('['), spputc('^'); break; case 0x7100: spputc('\033'), spputc('['), spputc('_'); break; } } /* Check serial port */ if(spcangetc()) ttyout(spgetc()); goto loop; }