#include #include #include #include #include /* TO COMPILE: gcc -O2 -o status status.c -lncurses TO RUN: ./status 888 use port 888 (default) for Lpt1, 632 for Lpt2 */ static struct termios orig, new; static int peek = -1; int kbhit() { char ch; int nread; if(peek != -1) return 1; new.c_cc[VMIN]=0; tcsetattr(0, TCSANOW, &new); nread = read(0,&ch,1); new.c_cc[VMIN]=1; tcsetattr(0, TCSANOW, &new); if(nread == 1) { peek = ch; return 1; } return 0; } int readch() { char ch; if(peek != -1) { ch = peek; peek = -1; return ch; } read(0,&ch,1); return ch; } int main(int argc, char *argv[]) { int a,x,c,BASEPORT,v,b,i; int s[8]={4,5,1,9,8,10,2,6}; int st[8]={0,0,0,64,16,20,28,24}; int dt[8]={60,56,52,48,44,40,36,32}; int ct[8]={0,59,55,51,0,0,0,0}; int ch =0; if (argc>1) { BASEPORT=atoi(argv[1]); } else {BASEPORT=888;} if (ioperm(BASEPORT,3,1)) {perror("ioperm");exit(1);} initscr(); /* record kb modes */ tcgetattr(0, &orig); new = orig; new.c_lflag &= ~ICANON; new.c_lflag &= ~ECHO; new.c_lflag &= ~ISIG; new.c_cc[VMIN] = 1; new.c_cc[VTIME] = 0; tcsetattr(0, TCSANOW, &new); /* screen setup */ move(1,30); printw("Parallel Port Analyzer"); move(5,10); printw("Data (%d): %d",BASEPORT,inb(BASEPORT)); move(6,10); printw("Status (%d): %d",(BASEPORT+1),inb(BASEPORT+1)); move(7,10); printw("Control (%d): %d",(BASEPORT+2),inb(BASEPORT+2)); move(9,20); printw("Parallel Port Location: %d",BASEPORT); move(11,15); printw("Sel PE Busy Ack [7] [6] [5] [4] [3] [2] [1] [0] Strobe"); move(12,15); printw("13 12 11 10 09 08 07 06 05 04 03 02 01"); move(13,16); printw("o o o o o o o o o o o o o"); move(14,19); printw("<----------Ground----------> s/d Init Err LF"); move(15,18); printw("25 24 23 22 21 20 19 18 17 16 15 14"); move(16,19); printw("o o o o o o o o o o o o"); move(20,15); printw("Toggle Data bits by typing the corresponding number"); move(21,15); printw("Toggle Control bits by hitting s,i,l buttons"); move(24,25); printw("PPA v2.0 4/28/2001 kyoorius@techfreakz.org"); refresh(); while((ch!='q')&&(ch!='Q')) { move(5,22); printw("%d ",inb(BASEPORT)); move(6,24); printw("%d ",inb(BASEPORT+1)); move(7,25); printw("%d ",inb(BASEPORT+2)); move(13,32); /* DATA REGISTER */ v=inb(BASEPORT);b=1; for (x=0;x<8;x++) { move(13,dt[x]); if ((b&v)>0) { standout(); printw(" "); standend();} else {printw("o");} b=b<<1; } /* STATUS REGISTER */ v=inb(BASEPORT+1); b=8; for (x=3;x<8;x++) { move(13,st[x]); if (b&v) { standout(); printw(" ");standend();} else{printw("o");} b=b<<1; } /* CONTROL REGISTER */ v=inb(BASEPORT+2); b=2; for (x=1;x<4;x++) { move(16,ct[x]); if (b&v) { standout(); printw(" ");standend();} else{printw("o");} b=b<<1; } move(0,0); refresh(); if(kbhit()) { ch = readch(); i=atoi(&ch);b=1; /* TAKE CARE OF DATA PINS */ if (i>0 || ch=='0') { b=b<1) {v=inb(BASEPORT+2);v=v^b;outb(v,(BASEPORT+2));} } } if (ioperm(BASEPORT,3,0)) {perror("ioperm");exit(1);} tcsetattr(0,TCSANOW, &orig); endwin(); exit(0); }