home *** CD-ROM | disk | FTP | other *** search
- /** DoRev Header ** Do not edit! **
- *
- * Name : main.c
- * Copyright : Free Software
- * Creation date : 12-May-93
- * Translator : SAS/C 6.2
- * Compiler opts. : See Makefile
- *
- * Date Rev Author Comment
- * --------- --- ------------------- ----------------------------------------
- * 22-May-93 1 Michael D. Bayne Removed mouse blanker
- * 12-May-93 0 Michael D. Bayne Startup & utility code for Blanker
- *
- *** DoRev End **/
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <exec/ports.h>
- #include <dos/dos.h>
- #include <dos/dostags.h>
- #include <intuition/intuition.h>
- #include <graphics/displayinfo.h>
- #include <libraries/reqtools.h>
-
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/alib_protos.h>
- #include <clib/utility_protos.h>
-
- #include "defs.h"
- #include "Blanker.h"
-
- /* Program revision tag. */
- STATIC const UBYTE VersTag[] = "\0$VER: "BVERSION" (5.22.93)";
-
- /* Prototypes */
- LONG handleCxMess( void );
- LONG SetupCX( void );
- LONG UpdateCX( void );
- void ShutdownCX( void );
- void defBlanker( void );
-
- void setPrefs( struct bPrefObject *, UBYTE );
- void loadPrefs( UBYTE *, UBYTE *, struct bPrefObject * );
- void savePrefs( UBYTE *, UBYTE *, struct bPrefObject * );
-
- extern ULONG cxSigFlag, cxBlankFlag;
- extern UBYTE prefName[], prefDir[], modInfo[];
- ULONG blankSig, validPrefs;
- struct ReqToolsBase *ReqToolsBase;
- struct Library *CxBase, *IconBase;
- struct Task *Task = 0L, *bTask = 0L;
- struct MsgPort *blankerPort, *modulePort = 0L;
- struct bMessage bMsg;
- struct bPrefObject bPrefs = { 0x00008004, 4, 1800, "shift F2", "shift F1", FALSE, "Moire", "Blankers" };
- struct Screen *bScr;
- struct NewBroker nbBroker = { NB_VERSION, "Blanker", BVERSION, "A system friendly screen blanker",
- NBU_UNIQUE|NBU_NOTIFY, COF_SHOW_HIDE, 0, 0, 0 };
-
- int getBlanker( void )
- {
- UBYTE path[256];
- struct bMessage *rMsg;
- BPTR checkExists;
-
- CopyMem( bPrefs.modDir, path, 108 );
- if( !AddPart( path, bPrefs.modName, 256 )) return( 0 );
- if( !modulePort ) {
- if( checkExists = Open( path, MODE_OLDFILE ) ) {
- Close( checkExists );
- SystemTags( path, NP_FreeSeglist, TRUE, SYS_Asynch, TRUE, SYS_Input,
- Open( "NIL:", MODE_OLDFILE ), SYS_Output, Open( "NIL:", MODE_OLDFILE ), TAG_END );
- WaitPort( blankerPort );
- rMsg = ( struct bMessage * )GetMsg( blankerPort );
- modulePort = ( struct MsgPort * )rMsg->bMess.mn_ReplyPort;
- bTask = ( struct Task * )rMsg->prefData;
- ReplyMsg(( struct Message * )rMsg );
- return( 1 );
- } else return( 0 );
- } else return( 1 );
- }
-
- void getInfo( UBYTE *Info )
- {
- if( getBlanker()) {
- if( bPrefs.resident ) bMsg.bm_Type = BM_INFO;
- else bMsg.bm_Type = BM_INFO|BM_QUIT;
- bMsg.bm_Valid = validPrefs;
- bMsg.prefData = bPrefs.prefData;
- PutMsg( modulePort, ( struct Message * )( &bMsg ));
- WaitPort( blankerPort );
- GetMsg( blankerPort );
- CopyMem( bMsg.prefData, Info, 64 );
- if( !bPrefs.resident ) modulePort = 0l;
- } else CopyMem( "Simple Blanker", Info, 15 );
- }
-
- void callBlanker( void )
- {
- if( getBlanker()) {
- if( bPrefs.resident ) bMsg.bm_Type = BM_BLANK;
- else bMsg.bm_Type = BM_BLANK|BM_QUIT;
- bMsg.bm_Valid = validPrefs;
- bMsg.sMod = bPrefs.sMod;
- bMsg.sDep = bPrefs.sDep;
- bMsg.prefData = bPrefs.prefData;
- PutMsg( modulePort, ( struct Message * )( &bMsg ));
- if( !bPrefs.resident ) modulePort = 0l;
- WaitPort( blankerPort );
- GetMsg( blankerPort );
- } else defBlanker();
- }
-
- LONG openMainWindow( void )
- {
- if( !BlankerWnd ) {
- if( SetupScreen()) return( 1 );
- OpenBlankerWindow();
- CloseDownScreen();
- }
- if( !BlankerWnd ) return( QUIT );
- getInfo( modInfo );
- setPrefs( &bPrefs, Blanker_CNT );
- return( OK );
- }
-
- void exitBlanker( LONG exitValue )
- {
- if( modulePort ) {
- bMsg.bm_Type = BM_UNLOAD;
- PutMsg( modulePort, ( struct Message * )( &bMsg ));
- WaitPort( blankerPort );
- GetMsg( blankerPort );
- }
-
- switch( exitValue ) {
- case 0L:
- CloseBlankerWindow();
- DeletePort( blankerPort );
- case 1L:
- ShutdownCX();
- case 2L:
- FreeSignal( blankSig );
- case 3L:
- CloseLibrary(( struct Library * )ReqToolsBase );
- case 4L:
- CloseLibrary( IconBase );
- case 5L:
- CloseLibrary( CxBase );
- case 6L:
- CloseLibrary(( struct Library * )GfxBase );
- case 7L:
- CloseLibrary( GadToolsBase );
- case 8L:
- CloseLibrary(( struct Library * )IntuitionBase );
- }
- }
-
- void main( int argc, char *argv[] )
- {
- ULONG sigs;
- LONG retval = 1;
- UBYTE **ttypes;
-
- if(!( IntuitionBase = ( struct IntuitionBase * )OpenLibrary( "intuition.library", 37L ))) exitBlanker( 9L );
- if(!( GfxBase = ( struct GfxBase * )OpenLibrary( "graphics.library", 37L ))) exitBlanker( 8L );
- if(!( GadToolsBase = OpenLibrary( "gadtools.library", 37L ))) exitBlanker( 7L );
- if(!( CxBase = OpenLibrary( "commodities.library", 37L ))) exitBlanker( 6L );
- if(!( IconBase = OpenLibrary( "icon.library", 36L ))) exitBlanker( 5L );
- if(!( ReqToolsBase = ( struct ReqToolsBase * )OpenLibrary( REQTOOLSNAME, REQTOOLSVERSION )))
- exitBlanker( 4L );
-
- Task = FindTask( 0L );
-
- if( ttypes = ArgArrayInit( argc, argv )) {
- nbBroker.nb_Pri = ( BYTE )ArgInt( ttypes, "CX_PRIORITY", 0 );
- if( !Stricmp( ArgString( ttypes, "CX_POPUP", "no" ), "yes" )) retval = 5;
- ArgArrayDone();
- } else nbBroker.nb_Pri = 0;
-
- if(( blankSig = ( ULONG )AllocSignal( -1L )) == -1 ) exitBlanker( 3L );
- cxBlankFlag = 1L << blankSig;
-
- if(!( SetupCX())) exitBlanker( 2L );
-
- loadPrefs( "Blanker.prefs", "ENV:", &bPrefs );
-
- if(!( blankerPort = CreatePort( "BlankerCC", 0 ))) exitBlanker( 1L );
- bMsg.bMess.mn_ReplyPort = blankerPort;
- bMsg.bMess.mn_Length = sizeof( struct bMessage );
-
- UpdateCX();
-
- if( retval == 5 ) retval = openMainWindow();
-
- while( retval ) {
- sigs = Wait( SIG_BREAK | cxSigFlag | cxBlankFlag | SIG_WINDOW );
- if( sigs & SIG_WINDOW ) retval = HandleBlankerIDCMP();
- if( sigs & cxSigFlag ) retval = handleCxMess();
- if( sigs & cxBlankFlag ) callBlanker();
- if( sigs & SIG_BREAK ) retval = 0L;
- if( retval == CLOSEWIN ) CloseBlankerWindow();
- }
-
- exitBlanker( 0L );
- }
-