/* Peek 1.0 * * June 10th, 1997. August 26th, 1997 * (C)opyright 1997 by Kelvin Sherlock * * Displays the SHR screen until return is pressed. * */ #include #include #include #include #pragma lint -1 /* * So I don't have to include || * */ extern pascal void GrafOff(void) inline(0x0B04,dispatcher); extern pascal void GrafOn(void) inline(0x0A04,dispatcher); extern pascal Word FlushEvents(Word, Word) inline(0x1506,dispatcher); /* * Prototyped functions * */ int GrafStatus(void); int needsgno(void); void SigHandler(int,int); void Version (char *); void Usage (char *); /* * Globals * */ jmp_buf buffer; int main(int argc, char **argv){ int i; int flush; int c; flush=0; if (argc>1) { if (*argv[1]!='-') { Usage(*argv); return(1); } switch (argv[1][1]) { case 'V':Version(*argv); return(0); case 'h':Usage(*argv); return(0); case 'f':flush++; break; default:Usage(*argv); return(1); } } /* If the hires screen is active, just quit */ if ( GrafStatus() ) return (2); if ( needsgno() ) for(i=1;i<25;i++) signal(i, SigHandler); GrafOn(); if (setjmp(buffer)); else /* * While waiting for a character, the process will be * blocked, which means ~0 cpu time spent on it */ while (fgetc(stdin)!='\n'); /* slurp all the chars */ GrafOff(); if (flush && needsgno()) FlushEvents(0xffff,0); return (0); } /* GrafStatus() * Inputs: none * Outputs: returns boolean true if the SHR * screen is active */ /* int GrafStatus(void){ return ( *(char *)0xe0c029 & 0x80 ); } */ asm int GrafStatus(void){ sep #0x20 lda 0xE0C029 rep #0x20 and #0x0080 rtl } /* * Signal Handler. transfers control to past the * getchar() call * */ #pragma databank 1 void SigHandler(int sig, int code){ longjmp(buffer,1); } #pragma databank 0 void Usage(char *fname) { fprintf(stdout,"\n%s -f -h -V\n",fname); fputs("Display the SHR screen\n",stdout); fputs("-f\tFlush All Events\n",stdout); fputs("-h\tshow help and exit\n",stdout); fputs("-V\tShow version information and exit\n",stdout); } void Version(char *fname) { fprintf(stdout,"\n%s version 1.0 by Kelvin Sherlock\n\n",fname); fputs("\tThis program contains material from the ORCA/C\n",stdout); fputs("\tRuntime Libraries, copyright 1987-1996\n",stdout); fputs("\tby Byte Works, Inc. Used with permission.\n",stdout); }