Path: news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!howland.reston.ans.net!nntp.coast.net!news.kei.com!uhog.mit.edu!uw-beaver!nntp.cs.ubc.ca!unixg.ubc.ca!van-bc!uniserve!news1.ottawa.istar.net!fonorola!news.ottawa.istar.net!news.mulberry.com!news From: dmitton@mulberry.com (Douglas E. Mitton) Newsgroups: comp.sys.apple2.gno Subject: Console Clock Utility - Request For Comments!!! Date: Sun, 10 Mar 1996 12:41:17 GMT Organization: Uniquest On-Line Services Lines: 184 Message-ID: <4huikq$oii@news.mulberry.com> NNTP-Posting-Host: ppp9.mulberry.com X-Newsreader: Forte Free Agent v0.55 I'm posting this again, it appears my server had a lapse of memory and it didn't make it out; I'm sorry if my information was wrong, this is sort of a long one ... Hi All GNO/ME Gurus!!! I've been sorta' working on various approaches to implement a console clock (date and/or time display) for some time. I've asked various questions here and on GEnie A2PRO's GNO/ME conference. I've tried a CDA (GEnie A2PRO library DTime is a very early version) but though it worked well for everything else GNO/ME didn't like it! (Caused strange crashes, P8 with P8CDA and other GS/OS text based utilities liked it, but not GNO/ME.)(If you look at the shareware DTime and like it let me know and I'll upload the current version free, I'm planning to BUT just haven't yet! :-))) I've written a GNO/ME version which works BUT apparently grabs a lot of real-time. For 3 hours og GNO/ME uptime this 'SClock' utility grabs 8:52 of process 'ps' time. I'm including the source for the current version that I'm using; please feel free to comment on any GNO/ME implementation features which could/should be used. By the way, the code works BUT I'M NOT AN ARTIST!!! :-) Any and all 'creative' comments are welcome!!! (Looks like my editor kills the formatting some, sorry!!!) --------------------------------------------------------- /* 960302 - SClock - GNO/ME shell screen time display utility. 960302 - V1.0 - Based on my experimental time utility. Used text I/F. 960302 - V1.1 - Try direct screen addressing; Banks $E0/E1 and $400-$427. 960303 - V1.1a - Add a few varaibles to clean up the implementation. 960303 - V1.1b - Add date option. 960303 - V1.1c - Modify so that day and hour DO NOT take two positions UNLESS they require 2 positions. Also make so that display always starts from the RIGHT margin, instead of from a HorizTab position. Notes: - Add de-activation when text shell is not active. - Add de-activation when system is busy - GSOS indication. - Add de-activation on GNO/ME request, some signal. - Allow command line options; seconds, refresh rate, date, etc. - Allow screen co-ordinates to be selected from the command line. - Allow direct screen RAM write without performace hit as CPU switches to SLOW mode with every access to slow memory. Stack: - 256 - not enough. - 512 - appears to be OK! - 768 - not tried! - 1024 - was working fine! */ #pragma optimize -1 #pragma debug 25 #pragma stacksize 512 #include #include #include #include struct tm *myt; time_t rawt; char *AM = "AM"; int TheHour; char *DTime = " Mth dd xx:yy:zz AMx..."; int x, SLen, STime, date; byte *B0Addr = (byte *) 0xE00427; byte *B1Addr = (byte *) 0xE10427; byte B0, B1; char *mnth[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; int help(void) { printf("\n"); printf("<>GNO/ME Console clock display - Douglas E. Mitton<>\n"); printf(" SClock V1.1c - 960303 by dmitton@mulberry.com\n"); printf(" Usage: 'sclock [[-d] [-?]] &' In inittab preferably!\n\n"); exit(1); } int main(int argc, char *argv[]) { if (argc > 2) help(); if ((argc == 2) && (argv[1][1] == '?')) help(); STime = 1; /* Sleep 1 second */ date = 0; if ((argc == 2) && (argv[1][1] == 'd')) { date = 1; } else if (argc == 2) help(); do { rawt = time(NULL); myt = localtime(&rawt); AM = "AM"; TheHour = (myt->tm_hour); if ((myt->tm_hour) >= 12){ AM = "PM"; } if ((myt->tm_hour) > 12){ TheHour = (myt->tm_hour) - 12; } if ((myt->tm_hour) == 24) { AM = "AM"; } sprintf(DTime, "\0"); if (date == 1) sprintf(DTime, " %s %d %d:%02d:%02d %s" \ ,mnth[myt->tm_mon], myt->tm_mday, TheHour, myt->tm_min, myt->tm_sec, AM); else sprintf(DTime, " %d:%02d:%02d %s" \ ,TheHour, myt->tm_min, myt->tm_sec, AM); SLen = strlen(DTime); if (SLen % 2 != 0) { strcat(DTime, " "); SLen++; } SLen = SLen/2-1; for (x=0; x<=SLen; x++) { B1 = 0x80 | *(DTime+2*x); B0 = 0x80 | *(DTime+2*x+1); *(B1Addr-SLen+x) = B1; *(B0Addr-SLen+x) = B0; } sleep(STime); } while (rawt); /* End of do loop */ } --------------------------------------------------------- ---------------------------------- Doug Mitton * In Brockville, Ontario, Canada (City of the Thousand Islands!) EMail: dmitton@mulberry.com d.mitton@genie.geis.com ---------------------------------