home *** CD-ROM | disk | FTP | other *** search
- /*
- * BLANKER.C - Screen saver program.
- *
- *
- * PROGRAMMER: Martti Ylikoski
- * CREATED: 11.7.1991
- */
- static char *VERSION = "Version 1.0" ;
- /*
- */
-
- static char *progname ;
-
- #include <stdio.h>
- #include <string.h>
- #include <memory.h>
- #include <time.h>
- #include <process.h>
- #include <stddef.h>
- #include <stdlib.h>
- #define INCL_DOS
- #define INCL_KBD
- #define INCL_VIO
- #define INCL_DOSPROCESS
- #include <os2.h>
-
- typedef struct kbdpacket
- {
- unsigned monflags ;
- KBDKEYINFO kbdkeyinfo ;
- unsigned ddflags ;
- } KBDBUF ;
-
- KBDBUF kbdbuf ;
-
- #define STACKSIZE 4096
- static char monstack[12][STACKSIZE] ;
- static char timestack[STACKSIZE] ;
- ULONG ntime = 0L, otime = 0L ;
- time_t newtime, oldtime ;
- void monitor_th( USHORT tindex ) ;
- void time_th( void ) ;
- ULONG exitsem = 0L ;
- ULONG blanksem = 0L ;
- ULONG timesem = 0L ;
- static HMONITOR hmon ;
- static USHORT tindex ;
- static int sleeptime ;
- DEFINEMUXSEMLIST(MuxList, 2) ;
-
- int main(int argc, char *argv[])
- {
- TID tid, time_tid ;
- USHORT ret ;
- USHORT fWait ;
- VIOMODEINFO viomodeinfo ;
- KBDKEYINFO kbdkeyinfo ;
- int col, row, outf ;
- USHORT usSemIndex ;
-
-
- fWait = VP_WAIT | VP_OPAQUE ;
- MuxList.cmxs = 2 ;
- MuxList.amxs[0].zero = 0 ;
- MuxList.amxs[1].zero = 0 ;
-
- MuxList.amxs[0].hsem = &exitsem ;
- MuxList.amxs[1].hsem = &blanksem ;
-
- DosSemSet(MuxList.amxs[0].hsem) ;
- DosSemSet(MuxList.amxs[1].hsem) ;
-
- //DosSemSet(&exitsem) ;
- DosSemClear(×em) ;
- newtime = time(NULL) ;
- oldtime = time(NULL) ;
- if (argc == 1)
- {
- sleeptime = 300 ;
- }
- else
- sleeptime = atoi(argv[1]) ;
-
- if (( ret = DosMonOpen("KBD$", &hmon)) != 0)
- {
- printf("%s: error opening monitor", progname) ;
- return(1) ;
- }
-
- if (( time_tid = _beginthread(time_th, timestack, sizeof(timestack), NULL)) == -1)
- // if (( ret = DosCreateThread(time_th, &time_tid, timestack + sizeof(monstack) )) != 0)
- {
- printf("%s: error in DosCreateThread", progname) ;
- return( 1 ) ;
- }
-
- for (tindex = 0 ; tindex < 12 ; tindex ++)
- if (( tid = _beginthread(monitor_th, &monstack[tindex][0], sizeof(monstack[0]), tindex+4)) == -1)
- //if (( ret = DosCreateThread(monitor_th, &tid, &monstack[tindex][0] + sizeof(monstack[0]) )) != 0)
- {
- printf("%s: error in DosCreateThread", progname) ;
- return( 1 ) ;
- }
- ;
- while (TRUE)
- {
- DosMuxSemWait(&usSemIndex, &MuxList, SEM_INDEFINITE_WAIT) ;
-
- if (usSemIndex == 0)
- break ;
-
-
- //DosSemWait(&exitsem, SEM_INDEFINITE_WAIT) ;
- ret = DosSuspendThread(tid) ;
- VioPopUp( &fWait, 0 ) ;
- viomodeinfo.cb = sizeof(viomodeinfo) ;
- VioGetMode(&viomodeinfo, 0) ;
- outf = FALSE ;
- while ( outf == FALSE)
- for (row = 0; row < viomodeinfo.row && outf == FALSE ; row ++)
- for (col = 0 ; col < viomodeinfo.col && outf == FALSE; col ++)
- {
- - VioSetCurPos(row, col, 0) ;
- ret = KbdCharIn(&kbdkeyinfo, IO_NOWAIT, 0) ;
- if (kbdkeyinfo.fbStatus != 0)
- {
- outf = TRUE ;
- break ;
- }
- DosSleep(1000L) ;
- }
-
- putchar(7) ;
- VioEndPopUp(0) ;
- DosSemSet(MuxList.amxs[1].hsem) ;
- ret = DosResumeThread(tid) ;
- }
-
- return( 0 ) ;
- }
-
-
- void monitor_th( USHORT th_index )
- {
-
- USHORT ret ;
- MONIN monin ;
- MONOUT monout ;
- SEL ginfo, linfo ;
- GINFOSEG FAR *pgis ;
- USHORT count ;
-
-
- monin.cb = sizeof(monin) ;
- monout.cb = sizeof(monout) ;
- if (( ret = DosGetInfoSeg(&ginfo, &linfo)) != 0)
- {
- printf("%s: error in DosGetInfoSeg", progname) ;
- return ;
- }
-
- pgis = MAKEPGINFOSEG(ginfo) ;
-
- while ((ret = DosMonReg(hmon, (PBYTE) &monin, (PBYTE) &monout, MONITOR_DEFAULT, th_index /*pgis->sgCurrent*/)) != 0)
- DosSleep(1500L) ;
-
- if ((ret = DosSetPrty(PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MINIMUM+1, 0)) != 0)
- {
- printf("%s: error raising priority", progname) ;
- return ;
- }
-
- while ( TRUE )
- {
- count = sizeof(kbdbuf) ;
- if (( ret = DosMonRead( (PBYTE) &monin, DCWW_WAIT, (PBYTE) &kbdbuf, &count )) != 0)
- {
- printf("%s: error in DosMonRead", progname) ;
- return ;
- }
-
- if(kbdbuf.kbdkeyinfo.chScan == 0x67)
- DosSemClear(MuxList.amxs[0].hsem) ;
- //DosSemClear(&exitsem) ;
-
- if ( kbdbuf.kbdkeyinfo.fsState & ALT && kbdbuf.kbdkeyinfo.chScan == 48)
- // if (kbdbuf.kbdkeyinfo.chChar == 'b'|| kbdbuf.kbdkeyinfo.chChar == 'B')
- DosSemClear(MuxList.amxs[1].hsem) ; /* blanksem */
- //DosSemClear(&exitsem) ;
-
- DosSemRequest(×em, SEM_INDEFINITE_WAIT) ;
- ntime = kbdbuf.kbdkeyinfo.time ;
- DosSemClear(×em) ;
-
- if (( ret = DosMonWrite( (PBYTE) &monout, (PBYTE) &kbdbuf, count)) != 0)
- {
- printf("%s: error in DosMonWrite", progname) ;
- return ;
- }
- }
-
- DosMonClose(hmon) ;
-
- }
-
-
- void time_th( void )
- {
-
- while( TRUE)
- {
- DosSemRequest(×em, SEM_INDEFINITE_WAIT) ;
- newtime = time(NULL) ;
- if (otime != ntime)
- {
- otime = ntime ;
- oldtime = newtime ;
- }
- if (newtime - oldtime > sleeptime) /* default 300 seconds */
- DosSemClear(&exitsem) ;
- DosSemClear(×em) ;
- DosSleep( 1000L ) ;
- }
- }
-