home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1993 Michael D. Bayne.
- * All rights reserved.
- *
- * Please see the documentation accompanying the distribution for distribution and disclaimer information.
- */
-
- #include <exec/types.h>
- #include <exec/memory.h>
-
- #include <dos/dos.h>
-
- #include <intuition/intuition.h>
- #include <intuition/screens.h>
- #include <intuition/intuitionbase.h>
-
- #include <graphics/gfxbase.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/copper.h>
- #include <graphics/videocontrol.h>
-
- #include <hardware/custom.h>
-
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/dos_protos.h>
-
- extern struct IntuitionBase *IntuitionBase;
- __far extern struct Custom custom;
- extern struct GfxBase *GfxBase;
- struct BitMap *newMap;
- ULONG FRandSeed;
-
- VOID setCopperList( ULONG height, ULONG color, struct ViewPort *vp )
- {
- #define NUMCOLORS 45
-
- struct UCopList *uCopList;
- struct TagItem uCopTags[] = { { VTAG_USERCLIP_SET, 0L }, { VTAG_END_CM, 0L } };
- register USHORT i, index = VBeamPos()%NUMCOLORS, spc;
- UWORD spectrum[] = { 0x0F00, 0x0E10, 0x0D20, 0x0C30, 0x0B40, 0x0A50, 0x0960, 0x0870, 0x0780, 0x0690,
- 0x05A0, 0x04B0, 0x03C0, 0x02D0, 0x01E0, 0x00F0, 0x00E1, 0x00D2, 0x00C3, 0x00B4,
- 0x00A5, 0x0096, 0x0087, 0x0078, 0x0069, 0x005A, 0x004B, 0x003C, 0x002D, 0x001E,
- 0x000F, 0x010E, 0x020D, 0x030C, 0x040B, 0x050A, 0x0609, 0x0708, 0x0807, 0x0906,
- 0x0A05, 0x0B04, 0x0C03, 0x0D02, 0x0E01 };
-
- if( uCopList = ( struct UCopList * )AllocMem( sizeof( struct UCopList ), MEMF_PUBLIC|MEMF_CLEAR )) {
-
- spc = height/NUMCOLORS;
-
- CINIT( uCopList, NUMCOLORS );
-
- for( i = 0; i<NUMCOLORS; ++i ) {
- CWAIT( uCopList, i*spc, 0 );
- CMOVE( uCopList, custom.color[color], spectrum[(i+index)%NUMCOLORS] );
- }
-
- CEND( uCopList );
-
- Forbid();
- vp->UCopIns = uCopList;
- Permit();
-
- VideoControl( vp->ColorMap, uCopTags );
-
- RethinkDisplay();
- }
- }
-
- ULONG getTopScreenMode( void )
- {
- BPTR lock;
- struct Screen *pubScr;
- ULONG scrMode;
-
- lock = LockIBase( 0 );
- pubScr = IntuitionBase->FirstScreen;
- scrMode = GetVPModeID( &(pubScr->ViewPort));
- UnlockIBase( lock );
- return( scrMode );
- }
-
- ULONG getTopScreenDepth( void )
- {
- BPTR lock;
- struct Screen *pubScr;
- struct DrawInfo *dri;
- ULONG sDep = 0;
-
- lock = LockIBase( 0 );
- pubScr = IntuitionBase->FirstScreen;
- if( dri = GetScreenDrawInfo( pubScr )) {
- sDep = dri->dri_Depth;
- FreeScreenDrawInfo( pubScr, dri );
- }
- UnlockIBase( lock );
- return( sDep );
- }
-
- VOID FreeBitMap37( struct BitMap *bm, LONG Width, LONG Height )
- {
- LONG i;
-
- if( GfxBase->LibNode.lib_Version < 39 ) {
- for( i = 0; i < bm->Depth; i++ ) if( bm->Planes[i] ) FreeRaster( bm->Planes[i], Width, Height );
- FreeVec( bm );
- } else FreeBitMap( bm );
- }
-
- struct BitMap *AllocBitMap37( ULONG Width, ULONG Height, ULONG Depth, struct Screen *Scr )
- {
- struct BitMap *bm;
- LONG i;
-
- if( GfxBase->LibNode.lib_Version < 39 ) {
- if( bm = AllocVec( sizeof( struct BitMap ), MEMF_CLEAR|MEMF_PUBLIC )) {
- InitBitMap( bm, Depth, Width, Height );
- for( i = 0; i < Depth; i++ ) if(!( bm->Planes[i] = AllocRaster( Width, Height ))) break;
- if( i == Depth ) return( bm );
- FreeBitMap37( bm, Width, Height );
- return( NULL );
- }
- } else return( AllocBitMap( Width, Height, Depth, BMF_DISPLAYABLE, Scr->RastPort.BitMap ));
- }
-
- struct Screen *cloneTopScreen( void )
- {
- struct Screen *Scr, *nScr = 0L;
- struct DrawInfo *dri;
- BPTR lock;
- ULONG sMod, sDep, i, Wid, Hei, offx, offy;
- UWORD *cols;
-
- /* Lock IntuitionBase so nothing goes away while we're playing with it */
- lock = LockIBase( 0 );
-
- /* Grab the first screen and get its attributes */
- Scr = IntuitionBase->FirstScreen;
- sMod = GetVPModeID( &(Scr->ViewPort)); /* Screen Mode ID */
- offx = Scr->LeftEdge;
- offy = Scr->TopEdge;
- Wid = Scr->Width;
- Hei = Scr->Height;
- if( dri = GetScreenDrawInfo( Scr )) sDep = dri->dri_Depth;
- if( cols = AllocMem( sizeof( WORD ) * ( 1L<<sDep ), MEMF_CLEAR ))
- for( i = 0; i < (1L<<sDep); ++i )
- cols[i] = GetRGB4( Scr->ViewPort.ColorMap, i );
-
- if( newMap = AllocBitMap37( Wid, Hei, sDep, Scr ))
- BltBitMap( Scr->RastPort.BitMap, 0, 0, newMap, 0, 0, Wid, Hei, 0x00C0, 0x00FF, NULL );
-
- UnlockIBase( lock );
-
- if(( newMap )&&( sMod != INVALID_ID )) {
- if( nScr = OpenScreenTags( NULL, SA_Width, Wid, SA_Height, Hei, SA_Depth, sDep, SA_Overscan,
- OSCAN_MAX, SA_DisplayID, sMod, SA_Pens, (ULONG)dri->dri_Pens, SA_Behind, TRUE, SA_BitMap,
- (ULONG)newMap, SA_Quiet, TRUE )) {
- LoadRGB4( &(nScr->ViewPort), cols, 1L << sDep );
- MoveScreen( nScr, offx, offy<0?offy:0 );
- ScreenToFront( nScr );
- }
- }
- if( cols ) FreeMem( cols, ( 1L << sDep ) * sizeof( UWORD ));
- if( dri ) FreeScreenDrawInfo( Scr, dri );
- return( nScr );
- }
-
- void closeTopScreen( struct Screen *Scr )
- {
- ULONG Wid, Hei;
-
- Wid = Scr->Width;
- Hei = Scr->Height;
- CloseScreen( Scr );
- FreeBitMap37( newMap, Wid, Hei );
- }
-
- ULONG fadeScreen( struct Screen *Screen, ULONG delay )
- {
- UWORD col, i, go = 1;
-
- while( go ) {
- go = 0;
- for( i = 0; i < (1L << Screen->RastPort.BitMap->Depth); ++i ) {
- if( SetSignal( 0L, SIGBREAKF_CTRL_C ) & SIGBREAKF_CTRL_C ) break;
- if( col = GetRGB4( Screen->ViewPort.ColorMap, i )) go = 1;
- SetRGB4( &(Screen->ViewPort), i,
- ((col & 0x0F00)>>8)?((col & 0x0F00)>>8)-1:0,
- ((col & 0x00F0)>>4)?((col & 0x00F0)>>4)-1:0,
- (col & 0x000F)?(col & 0x000F)-1:0 );
- }
- if( i == ( 1L<<Screen->RastPort.BitMap->Depth )) Delay( delay );
- else return( FALSE );
- }
- return( TRUE );
- }
-
- ULONG FRand( VOID )
- {
- return( FRandSeed = ( FRandSeed << 1 )^( 0x1D872B41 ));
- }
-
- UWORD *BlankPtr;
- struct Window *BlankWnd;
-
- VOID BlankMousePointer( VOID )
- {
- if( BlankPtr = AllocVec( sizeof( WORD ) * 4, MEMF_CHIP )) {
- if( BlankWnd = OpenWindowTags( 0L, WA_Activate, TRUE, WA_Width, 10, WA_Height, 10, WA_Borderless,
- TRUE, TAG_END )) {
- SetPointer( BlankWnd, BlankPtr, 0, 0, 0, 0 );
- }
- }
- }
-
- VOID UnblankMousePointer( VOID )
- {
- if( BlankWnd ) CloseWindow( BlankWnd );
- if( BlankPtr ) FreeVec( BlankPtr );
- }
-