#include /* module databas9 */ #include #include #include #include #include #include #include #include #include #include #include #include #include union REGS inregs,outregs; /* each log is structured as 8 bytes of ascii time of day, followed by 8 bytes of ascii date, followed by nb binary status bytes, followed by 64 metering bytes (32 integers), for a total of nb+80 bytes. */ /*****************************************************************************/ database(void) /* display database in hex */ { char string[30]; int i,x,color; screen=14; font(3); clkey(); if(screen!=oldscrn) refresh=1; if(refresh) { clear(); oldayt[0]=0; font(0); text(PALEBLUE,100,479,"DATABASE"); txnumber(); text(PALEBLUE,0,420,"TIME (DEC)"); tex(300,420,"DATE (DEC)"); tex(0,380,"STATUS (HEX)"); tex(0,230,"METER (DEC)"); box(DARKGREY,95,385,590,365,DARKGREY," "); box(DARKGREY,95,335,590,315,DARKGREY," "); box(DARKGREY,95,235,570,215,DARKGREY," "); box(DARKGREY,95,185,570,165,DARKGREY," "); texcolor(WHITE); for(i=0;i<24;i++) /* status byte numbers */ { number(100+20*i,380,i,0); number(100+20*i,330,i+24,0); } for(i=0;i<=15;i++) /* meter numbers */ { number(100+30*i,230,i,0); number(100+30*i,180,i+16,0); } } rect(BLACK,100,420,160,400); /* erase old time */ strncpy(string,tyme,2); string[2]=0; text(PALEBLUE,100,420,string); /* hours */ strncpy(string,&tyme[3],2); tex(120,420,string); /* minutes */ strncpy(string,&tyme[6],2); tex(140,420,string); /* seconds */ rect(BLACK,400,420,460,400); /* erase old date */ strncpy(string,dayt,2); text(PALEBLUE,400,420,string); /* month */ strncpy(string,&dayt[3],2); tex(420,420,string); /* day */ strncpy(string,&dayt[6],2); tex(440,420,string); /* year */ /*---------------------------------------------------------------------------*/ for(i=0;i<24;i++) /* status */ { if(refresh||(status[i]!=statup[i])||(status[i+24]!=statup[i+24])) { x=100+20*i; rect(BLACK,x,360,x+19,340); hex(status[i]); text(PALEBLUE,x,360,numb); rect(BLACK,x,310,x+19,290); hex(status[i+24]); text(PALEBLUE,x,310,numb); } } /*---------------------------------------------------------------------------*/ for(i=0;i<=15;i++) /* meters */ { x=100+30*i; if(refresh||(avmet[i]!=oldav[i])) { color=PALEBLUE; if(avmet[i]hilim[i]) color=YELLOW; itoa(avmet[i],numb,10); rect(BLACK,x,210,x+19,190); text(color,x,210,numb); } if(refresh||(avmet[i+16]!=oldav[i+16])) { color=PALEBLUE; if(avmet[i+16]hilim[i+16]) color=YELLOW; itoa(avmet[i+16],numb,10); rect(BLACK,x,160,x+19,140); text(color,x,160,numb); } } refresh=0; oldscrn=screen; } /****************************************************************************/ basename(void) /* database signal names in real-time */ { char string[30]; unsigned char mask; int i,index,j,jj,l,m,x,y,color,tcolor; font(3); if(parse[0]&&parse[4]!=CR) { if(arg(1,3)) goto abort; screen=atoi(&parse[4])+14; } if(parse[4]==CR) screen=15; /* default */ jj=screen-15; /* page number */ clkey(); if(screen!=oldscrn) refresh=1; if(refresh) { clear(); oldayt[0]=0; font(1); text(PALEBLUE,0,479,"DATABASE SIGNAL NAMES"); txnumber(); texcolor(PALEBLUE); for(i=0;i<=7;i++) /* bit numbers */ { x=600-i*80; tex(x,450,itoa(i,numb,10)); } } for(j=0;j<=19;j++) /* 20 bytes */ { mask=0x01; if((j+20*jj)==nb) goto abort; /* last byte */ for(i=0;i<=7;i++) /* 8 bits per byte */ { if(refresh||((status[j+20*jj]&mask)!=(statup[j+20*jj]&mask))) { x=560-80*i; y=440-21*j; color=DARKGREY; tcolor=WHITE; if(status[j+20*jj]&mask) { color=WHITE; tcolor=BLUE; } box(color,x,y,x+80,y-21,color," "); texcolor(tcolor); index=8*(j+20*jj)+i; strcpy(string,bitlist[index]); l=strlen(string); if(l>11) { for(m=0;m<=10;m++) { if(string[11-m]==SP) /* end of word */ { string[11-m]=0; break; } } tex(x+2,y,string); strcpy(string,bitlist[index]+12-m); tex(x+2,y-10,string); } else tex(x+2,y-5,string); if(i==7) text(PALEBLUE,628,y-10,itoa(j+20*jj,numb,10)); } mask=mask<<1; } } abort: refresh=0; oldscrn=screen; } /****************************************************************************/ simulate(void) /* modify database signal levels */ /* return to real-time mode with ESC key in main program loop */ { char string[30]; unsigned char mask; int k,i,index,j,jj,l,m,mold,n,nold,x,y,color,w; if(!(status[35]&0x80)) backdata(); status[35]|=0x80; /* simulation mode */ if(parse[0]&&parse[4]!=CR) { if(arg(1,3)) goto abort; jj=atoi(&parse[4])-1; } else jj=0; /* page number */ clkey(); clear(); oldayt[0]=0; font(1); text(PALEBLUE,0,479,"SIMULATION SIGNAL NAMES"); font(3); for(i=0;i<=7;i++) /* bit labels */ { x=600-i*80; tex(x,450,itoa(i,numb,10)); } loop: mold=0; nold=0; n=0; m=0; rect(BLACK,0,0,639,440); for(j=0;j<=19;j++) /* 20 bytes */ { mask=0x01; if((j+20*jj)==nb) goto loop1; /* last byte */ for(i=0;i<=7;i++) /* 8 bits per byte */ { x=561-80*i; y=440-21*j; color=DARKGREY; if(status[j+20*jj]&mask) color=BLUE; rect(color,x,y-1,x+78,y-20); index=8*(j+20*jj)+i; strcpy(string,bitlist[index]); l=strlen(string); if(l>11) { for(w=0;w<=10;w++) { if(string[11-w]==SP) /* end of word */ { string[11-w]=0; break; } } text(WHITE,x,y,string); strcpy(string,bitlist[index]+12-w); text(WHITE,x,y-10,string); } else text(WHITE,x,y-5,string); mask=mask<<1; } text(PALEBLUE,628,y-10,itoa(j+20*jj,numb,10)); } loop1: message(WHITE,"USE CURSOR KEYS OR CLICK LEFT TO SELECT, PageUp FOR PREVIOUS, PageDown FOR NEXT SCREEN"); onmouse(); while(!kbhit()) { odapc(); switch(click()) /* mouse button */ { case 1: /* left click */ x=outregs.x.cx; y=479-outregs.x.dx; m=(x-1)/80; if(m>7) m=0; n=(440-y)/21; if(n>nb-20*jj-1) n=0; goto exec; case 3: /* both click */ k=ESC; goto cursor; } } k=caps(); cursor: offmouse(); if(k>128) switch(k) { case LEFT: --m; if(m==-1) m=7; /* wrap */ break; case RIGHT: ++m; if(m==8) m=0; /* wrap */ break; case UP: if(--n<0) if(jj==2) n=nb-jj*20-1; else n=19; /* wrap */ break; case DOWN: if(++n>19) n=0; /* wrap */ if(n>nb-20*jj-1) n=0; break; case HOME: n=0; break; case END: if(jj==2) n=nb-jj*20-1; /* end of database */ else n=19; break; case PDN: if(++jj>2) jj=0; goto loop; break; case PUP: if(--jj<0) jj=1; goto loop; break; default: goto abort; } else goto abort; exec: x=1+80*mold; /* un-highlight old selection */ y=440-21*nold; offmouse(); color=DARKGREY; if(status[nold+20*jj]&(0x80>>mold)) color=BLUE; rect(color,x,y-1,x+78,y-20); index=8*(nold+20*jj)+7-mold; strcpy(string,bitlist[index]); l=strlen(string); if(l>11) { for(w=0;w<=10;w++) { if(string[11-w]==SP) /* end of word */ { string[11-w]=0; break; } } text(WHITE,x,y,string); strcpy(string,bitlist[index]+12-w); text(WHITE,x,y-10,string); } else text(WHITE,x,y-5,string); x=1+80*m; /* highlight selection */ y=440-21*n; rect(YELLOW,x,y-1,x+78,y-20); index=8*(n+20*jj)+7-m; strcpy(string,bitlist[index]); l=strlen(string); if(l>11) { for(w=0;w<=10;w++) { if(string[11-w]==SP) /* end of word */ { string[11-w]=0; break; } } text(BLACK,x,y,string); strcpy(string,bitlist[index]+12-w); text(BLACK,x,y-10,string); } else text(BLACK,x,y-5,string); mold=m; nold=n; message(WHITE,"Enter OR CLICK RIGHT TO TOGGLE STATUS BIT SIGNAL LEVEL"); onmouse(); while(!kbhit()) { odapc(); switch(click()) { case 1: /* left click */ x=outregs.x.cx; y=479-outregs.x.dx; m=(x-1)/80; if(m>7) m=0; n=(440-y)/21; if(n>nb-20*jj-1) n=0; goto exec; case 2: /* right click */ k=CR; goto exec2; case 3: /* both click */ k=ESC; goto exec2; } } k=caps(); exec2: offmouse(); if(k==CR) { status[n+20*jj]=status[n+20*jj]^(0x80>>m); /* toggle */ color=DARKGREY; if(status[n+20*jj]&(0x80>>m)) color=BLUE; rect(color,x,y-1,x+78,y-20); index=8*(n+20*jj)+7-m; strcpy(string,bitlist[index]); l=strlen(string); if(l>11) { for(w=0;w<=10;w++) { if(string[11-w]==SP) /* end of word */ { string[11-w]=0; break; } } text(WHITE,x,y,string); strcpy(string,bitlist[index]+12-w); text(WHITE,x,y-10,string); } else text(WHITE,x,y-5,string); goto loop1; } else goto cursor; abort: clkey(); refresh=1; }