#include #include #include #include #define TRUE -1 #define FALSE 0 #define YES -1 #define NO 0 main(argc, argv) int argc; char *argv[]; { int xx, loc_x, loc_y; xx = 0; /* argc = 2; argv[2] = 2; */ if (argc >= 2) { /* 119, 68, 18 */ sscanf(argv[1], "%d", &xx); if (argc >= 4) { sscanf(argv[2], "%d", &loc_x); sscanf(argv[3], "%d", &loc_y); } else { loc_x = 35; loc_y = 9; } if ((loc_x > 68) || (loc_y > 18)) { usage(); printf("\n"); printf("\n"); printf("Note: x range is 0 - 68 and y range is 0 - 18 \n"); return; } xx = count_down(xx, loc_y, loc_x); } else { usage(); } return xx; } count_down(chron, y_pos, x_pos) int chron, y_pos, x_pos; { int xx, cha, chb, hnd, lhnd, sec, jnk, tsec, old_col, old_row; struct time tmbf; for (xx=0; xx < 32; xx++) getkey(); /* Purge key buffer */ cha = EOF; chb = 0; hnd = 0; /* zero hundredths of seconds */ if (chron > 119) chron = 119; /* limit max to 120 seconds */ sec = (chron % 10) + 1; /* init 10 second spinner */ old_col = curscol(); old_row = cursrow(); cursoff(); outr_rotate(-1,y_pos,x_pos); tsec = 12; /* Start with a full dial */ while ((119 - chron) >= 10) /* Setup the timer dial */ { tsec = tsec - 1; outr_rotate(tsec,y_pos,x_pos); chron+=10; } do { tsec = tsec - 1; outr_rotate(tsec,y_pos,x_pos); jnk = -1; rotate(&jnk, y_pos + 2, x_pos + 3); do { cha = getkey(); gettime(&tmbf); /* read system time */ if (tmbf.ti_hund != lhnd) { /* did hundredths change by minimum possible, 1/18th sec */ lhnd = tmbf.ti_hund; /* Yes? set to current */ hnd = hnd + 1; /* note that it happend */ if (hnd >= 2) /* did 1/9th second go by ? */ { hnd = 0; /* Yes? Zap counter */ /* Display the change for user */ rotate(&sec, y_pos + 2, x_pos + 3); } } } while ((cha == EOF) && (sec > 0)); if ((tsec > 0) && (sec == 0)) sec = 10; } while ((cha == EOF) && (sec > 0) && (tsec > 0)); /* the above loop runs until key press or timeout */ sec = 0; /* by setting seconds to zero we cause count-down ind to erase */ rotate(&sec, y_pos + 2, x_pos + 3); /* Do it! */ if (cha == EOF) { curson(); curslin(); poscurs(old_row, old_col); return 0; } else { outr_rotate(0,y_pos,x_pos); curson(); curslin(); poscurs(old_row, old_col); return cha; } } /* The Rotate function is repeatedly called 10 times (aprox) a second to draw */ /* at cursor position row, & column a count-down display reminiscent of early */ /* 16mm Black & White newsreel films. At every point a full second elapses */ /* the seconds variable who's address is passed to it, is decremented. */ /* if second is zero the display is erased. if second is -1 it is drawn for */ /* the first time (frame work only, fillin is done later) */ rotate(sec,row,col) int *sec, row, col; { static int spn; char bcn[]={"wxyz\\-/|\\-/abc "}; /* ===> "wxyz\-/|\-/abc" */ if (*sec == -1) /* Draw box for the first time */ { poscurs(row + 0,col);printf("ÚÄÄÄ¿"); poscurs(row + 1,col);printf("³ ³"); poscurs(row + 2,col);printf("ÀÄÄÄÙ"); spn = 3; return; } if (*sec == 0) /* Erase box when seconds go to zero */ { poscurs(row + 0,col);printf(" "); poscurs(row + 1,col);printf(" "); poscurs(row + 2,col);printf(" "); return; } if ((spn >= 0)&&(spn <= 3)) /* Are we drawing the count-down digit */ { if (spn == 3) { /* decrement seconds if digit is displayed after a spin ends */ *sec = *sec - 1; } if (spn == 0) { /* start a new spin */ spn = 10; } else spn = spn - 1; /* or continue the present spin */ poscurs(row + 0,col);printf("ÚÄÄÄ¿"); /* clean highlighter off box */ poscurs(row + 1,col + 2); /* move into middle of box */ printf("%d",*sec); /* place the count-down digit in there */ } else { /* If we aren't we drawing the count-down digit draw a spin segment */ poscurs(row + 1,col + 2); putch(bcn[spn]); /* put a spin segment in the box */ switch (spn) /* and highlight the appropriate portion of the border */ { case 10: poscurs(row + 0,col + 3); printf("Í»"); break; /* hi lite*/ case 9: poscurs(row + 0,col + 3); printf("Ä¿"); /* un hi lite */ poscurs(row + 1,col + 4); printf("º"); break; /* hi lite */ case 8: poscurs(row + 1,col + 4); printf("³"); /* un hi lite */ poscurs(row + 2,col + 3); printf("ͼ"); break; /* hi lite */ case 7: poscurs(row + 2,col + 1); printf("ÍÍÍÙ"); break; /* both */ case 6: poscurs(row + 2,col + 0); printf("ÈÍÄÄ"); break; /* both */ case 5: poscurs(row + 1,col + 0); printf("º"); /* hi lite */ poscurs(row + 2,col + 0); printf("ÀÄ"); break; /* un hi lt*/ case 4: poscurs(row + 0,col + 0); printf("ÉÍ"); /* hi lite */ poscurs(row + 1,col + 0); printf("³"); break; /* un hi lit*/ } spn = spn - 1; } } /* Outr_Rotate function is repeatedly called 1 time (aprox) a second to draw */ /* at cursor position row, & column a count-down display reminiscent of early */ /* 16mm Black & White newsreel films. */ /* if second is zero the display is erased. if second is -1 it is drawn for */ /* the first time (frame work only, fillin is done later) */ outr_rotate(sec,row,col) int sec, row, col; { static int spn; if (sec == -1) /* Draw box for the first time */ { poscurs(row + 0,col);printf("ÚÄÄÄÄÄÄÄÄÄ¿"); poscurs(row + 1,col);printf("³ ³"); poscurs(row + 2,col);printf("³ ÚÄÄÄ¿ ³"); poscurs(row + 3,col);printf("³ ³ ³ ³"); poscurs(row + 4,col);printf("³ ÀÄÄÄÙ ³"); poscurs(row + 5,col);printf("³ ³"); poscurs(row + 6,col);printf("ÀÄÄÄÄÄÄÄÄÄÙ"); spn = 12; return; } if (sec == 0) /* Erase box when seconds go to zero */ { poscurs(row + 0,col);printf(" "); poscurs(row + 1,col);printf(" "); poscurs(row + 2,col);printf(" "); poscurs(row + 3,col);printf(" "); poscurs(row + 4,col);printf(" "); poscurs(row + 5,col);printf(" "); poscurs(row + 6,col);printf(" "); return; } switch (spn) /* and highlight the appropriate portion of the border */ { case 12: poscurs(row + 1,col + 5); printf(""); break; /* hi lite */ case 11: poscurs(row + 1,col + 8); printf(""); break; /* hi lite */ case 10: poscurs(row + 2,col + 9); printf(""); break; /* hi lite */ case 9: poscurs(row + 3,col + 9); printf(""); break; /* hi lite */ case 8: poscurs(row + 4,col + 9); printf(""); break; /* hi lite */ case 7: poscurs(row + 5,col + 8); printf(""); break; /* hi lite */ case 6: poscurs(row + 5,col + 5); printf(""); break; /* hi lite */ case 5: poscurs(row + 5,col + 2); printf(""); break; /* hi lite */ case 4: poscurs(row + 4,col + 1); printf(""); break; /* hi lite */ case 3: poscurs(row + 3,col + 1); printf(""); break; /* hi lite */ case 2: poscurs(row + 2,col + 1); printf(""); break; /* hi lite */ case 1: poscurs(row + 1,col + 2); printf(""); break; /* hi lite */ } spn = spn - 1; } usage() { clrscrn(); printf("Usage: eggtimer n [x y] Where: n is a number 1 to 119 seconds\n"); printf(" program times for n seconds or until\n"); printf(" a key is struck. It sets ERRORLEVEL \n"); printf(" to value of key, or zero if it times \n"); printf(" out. \n"); printf(" \n"); printf(" And where: x and y are the X and Y "); printf("Corrdinates\n"); printf(" of a count-down display reminiscent of"); printf(" early\n"); printf(" 16mm Black & White newsreel films.\n"); }