home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / Garshnelib37 / Garshnelib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-19  |  12.9 KB  |  480 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <graphics/gfxmacros.h>
  11. #include <graphics/videocontrol.h>
  12. #include <intuition/intuitionbase.h>
  13. #include <libraries/reqtools.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/graphics_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/asl_protos.h>
  19. #include <clib/reqtools_protos.h>
  20. #include <clib/alib_protos.h>
  21.  
  22. #include <pragmas/exec_pragmas.h>
  23. #include <pragmas/graphics_pragmas.h>
  24. #include <pragmas/intuition_pragmas.h>
  25. #include <pragmas/asl_pragmas.h>
  26. #include <pragmas/reqtools_pragmas.h>
  27.  
  28. #include "Garshnelib_protos.h"
  29.  
  30. VOID SASM ScreenModeRequest( AREG(0) struct Window *Wnd,
  31.                             AREG(1) LONG *Mode, AREG(2) LONG *Depth )
  32. {
  33.     struct AslBase *AslBase;
  34.     
  35.     if( AslBase = ( struct AslBase * )OpenLibrary( AslName, 38L ))
  36.     {
  37.         struct ScreenModeRequester *smRequest;
  38.         
  39.         if( smRequest = AllocAslRequestTags( ASL_ScreenModeRequest, TAG_END ))
  40.         {
  41.             if( Depth )
  42.             {
  43.                 if( AslRequestTags( smRequest, ASLSM_Window, Wnd,
  44.                                    ASLSM_SleepWindow, TRUE,
  45.                                    ASLSM_TitleText, "Screen Mode",
  46.                                    ASLSM_InitialDisplayID, *Mode,
  47.                                    ASLSM_InitialDisplayDepth, *Depth,
  48.                                    ASLSM_DoDepth, TRUE, TAG_END ))
  49.                 {
  50.                     *Mode = smRequest->sm_DisplayID;
  51.                     *Depth = smRequest->sm_DisplayDepth;
  52.                 }
  53.             }
  54.             else
  55.             {
  56.                 if( AslRequestTags( smRequest, ASLSM_Window, Wnd,
  57.                                    ASLSM_SleepWindow, TRUE,
  58.                                    ASLSM_TitleText, "Screen Mode",
  59.                                    ASLSM_InitialDisplayID, *Mode, TAG_END ))
  60.                     *Mode = smRequest->sm_DisplayID;
  61.             }
  62.             FreeAslRequest( smRequest );
  63.         }
  64.         CloseLibrary(( struct Library * )AslBase );
  65.     }
  66.     else
  67.     {
  68.         struct ReqToolsBase *ReqToolsBase;
  69.  
  70.         if( ReqToolsBase = ( struct ReqToolsBase * )
  71.            OpenLibrary( REQTOOLSNAME, REQTOOLSVERSION ))
  72.         {
  73.             struct rtScreenModeRequester *smRequest;
  74.             
  75.             if( smRequest = rtAllocRequestA( RT_SCREENMODEREQ, 0L ))
  76.             {
  77.                 if( Depth )
  78.                 {
  79.                     LONG Tags[] = { RT_Window, 0L, RT_LockWindow, TRUE,
  80.                                         RTSC_Flags, SCREQF_DEPTHGAD, TAG_END };
  81.                     LONG ReqTags[] = { RTSC_DisplayID, 0L,
  82.                                            RTSC_DisplayDepth, 0L, TAG_END };
  83.                     ReqTags[1] = *Mode;
  84.                     ReqTags[3] = *Depth;
  85.                     rtChangeReqAttrA( smRequest, ( struct TagItem * )ReqTags );
  86.                     
  87.                     Tags[1] = ( LONG )Wnd;
  88.                     if( rtScreenModeRequestA( smRequest, "Screen Mode",
  89.                                              ( struct TagItem * )Tags ))
  90.                     {
  91.                         *Mode = smRequest->DisplayID;
  92.                         *Depth = smRequest->DisplayDepth;
  93.                     }
  94.                 }
  95.                 else
  96.                 {
  97.                     LONG Tags[] = { RT_Window, 0L, RT_LockWindow, TRUE,
  98.                                         TAG_END };
  99.                     LONG ReqTags[] = { RTSC_DisplayID, 0L, TAG_END };
  100.                     
  101.                     ReqTags[1] = *Mode;
  102.                     rtChangeReqAttrA( smRequest, ( struct TagItem * )ReqTags );
  103.                     
  104.                     Tags[1] = ( LONG )Wnd;
  105.                     if( rtScreenModeRequestA( smRequest, "Screen Mode",
  106.                                              ( struct TagItem * )Tags ))
  107.                         *Mode = smRequest->DisplayID;
  108.                 }
  109.                 rtFreeRequest( smRequest );
  110.             }
  111.             CloseLibrary(( struct Library * )ReqToolsBase );
  112.         }
  113.     }
  114. }
  115.  
  116. #define NUMCOLORS 45
  117. LONG spectrum[] = {
  118.     0x0F00, 0x0E10, 0x0D20, 0x0C30, 0x0B40, 0x0A50, 0x0960,    0x0870, 0x0780,
  119.     0x0690, 0x05A0, 0x04B0, 0x03C0, 0x02D0,    0x01E0, 0x00F0, 0x00E1, 0x00D2,
  120.     0x00C3, 0x00B4, 0x00A5,    0x0096, 0x0087, 0x0078, 0x0069, 0x005A, 0x004B,
  121.     0x003C,    0x002D, 0x001E, 0x000F, 0x010E, 0x020D, 0x030C, 0x040B,    0x050A,
  122.     0x0609, 0x0708, 0x0807, 0x0906, 0x0A05, 0x0B04,    0x0C03, 0x0D02, 0x0E01
  123.     };
  124.  
  125. VOID SASM setCopperList( DREG(0) LONG Hei, DREG(1) LONG Col,
  126.                         AREG(0) struct ViewPort *VPort,
  127.                         AREG(1) struct Custom *Custom )
  128. {
  129.     struct Library *GfxBase, *IntuitionBase;
  130.     struct UCopList *uCopList;
  131.  
  132.     IntuitionBase = OpenLibrary( "intuition.library", 37L );
  133.     GfxBase = OpenLibrary( "graphics.library", 37L );
  134.     
  135.     if( IntuitionBase && GfxBase &&
  136.        ( uCopList = AllocVec( sizeof( struct UCopList ), MEMF_CLEAR )))
  137.     {
  138.         struct TagItem uCopTags[] = {{VTAG_USERCLIP_SET,0L},{VTAG_END_CM,0L}};
  139.         LONG i, spc;
  140.  
  141.         spc = Hei/NUMCOLORS;
  142.         CINIT( uCopList, NUMCOLORS );
  143.         for( i = 0; i < NUMCOLORS; ++i )
  144.         {
  145.             CWAIT( uCopList, i * spc, 0 );
  146.             CMOVE( uCopList, Custom->color[Col], spectrum[i%NUMCOLORS] );
  147.         }
  148.         CEND( uCopList );
  149.         Forbid();
  150.         VPort->UCopIns = uCopList;
  151.         Permit();
  152.         VideoControl( VPort->ColorMap, uCopTags );
  153.         RethinkDisplay();
  154.     }
  155.     
  156.     if( GfxBase )
  157.         CloseLibrary( GfxBase );
  158.     
  159.     if( IntuitionBase )
  160.         CloseLibrary( IntuitionBase );
  161. }
  162.  
  163. VOID SASM clearCopperList( AREG(0) struct ViewPort *VPort )
  164. {
  165.     struct Library *GfxBase;
  166.     
  167.     if( GfxBase = OpenLibrary( "graphics.library", 37L ))
  168.     {
  169.         struct TagItem uCopTags[] = {{VTAG_USERCLIP_CLR,0L},{VTAG_END_CM,0L}};
  170.         struct UCopList *uCopList;
  171.  
  172.         VideoControl( VPort->ColorMap, uCopTags );
  173.         Forbid();
  174.         uCopList = VPort->UCopIns;
  175.         VPort->UCopIns = 0L;
  176.         Permit();
  177.         FreeVec( uCopList );
  178.     }
  179. }
  180.  
  181. LONG SASM getTopScreenMode( VOID )
  182. {
  183.     struct IntuitionBase *IntuitionBase;
  184.     struct Library *GfxBase;
  185.     struct Screen *pubScr;
  186.     LONG scrMode;
  187.     BPTR lock;
  188.     
  189.     IntuitionBase =
  190.         ( struct IntuitionBase * )OpenLibrary( "intuition.library", 37L );
  191.     GfxBase = OpenLibrary( "graphics.library", 37L );
  192.     
  193.     if( IntuitionBase && GfxBase )
  194.     {
  195.         lock = LockIBase( 0 );
  196.         pubScr = IntuitionBase->FirstScreen;
  197.         scrMode = GetVPModeID(&( pubScr->ViewPort));
  198.         UnlockIBase( lock );
  199.     }
  200.     
  201.     if( GfxBase )
  202.         CloseLibrary( GfxBase );
  203.     
  204.     if( IntuitionBase )
  205.         CloseLibrary(( struct Library * )IntuitionBase );
  206.     
  207.     return scrMode;
  208. }
  209.  
  210. LONG SASM getTopScreenDepth( VOID )
  211. {
  212.     struct IntuitionBase *IntuitionBase;
  213.     LONG Dep = 0;
  214.     
  215.     if( IntuitionBase =
  216.         ( struct IntuitionBase * )OpenLibrary( "intuition.library", 37L ))
  217.     {
  218.         struct Screen *PubScr;
  219.         struct DrawInfo *dri;
  220.         BPTR Lock;
  221.  
  222.         Lock = LockIBase( 0 );
  223.         PubScr = IntuitionBase->FirstScreen;
  224.         if( dri = GetScreenDrawInfo( PubScr ))
  225.         {
  226.             Dep = dri->dri_Depth;
  227.             FreeScreenDrawInfo( PubScr, dri );
  228.         }
  229.         UnlockIBase( Lock );
  230.     
  231.         CloseLibrary(( struct Library * )IntuitionBase );
  232.     }
  233.     
  234.     return Dep;
  235. }
  236.  
  237. struct Screen *SASM cloneTopScreen( DREG(0) LONG MoreColors,
  238.                                    DREG(1) LONG GetPublic )
  239. {
  240.     LONG sMod, sDep, i, Wid, Hei, offx, offy;
  241.     struct IntuitionBase *IntuitionBase;
  242.     struct Screen *Scr, *nScr = 0L;
  243.     struct Rectangle DispRect;
  244.     struct Library *GfxBase;
  245.     struct DrawInfo *dri;
  246.     UWORD *cols;
  247.     BPTR lock;
  248.     
  249.     IntuitionBase =
  250.         ( struct IntuitionBase * )OpenLibrary( "intuition.library", 37L );
  251.     GfxBase = OpenLibrary( "graphics.library", 37L );
  252.     
  253.     if( IntuitionBase && GfxBase )
  254.     {
  255.         /* Lock IntuitionBase so nothing goes away */
  256.         lock = LockIBase( 0 );
  257.         
  258.         /* Grab the first screen and get its attributes */
  259.         if( GetPublic )
  260.             Scr = LockPubScreen( 0L );
  261.         else
  262.             Scr = IntuitionBase->FirstScreen;
  263.         sMod = GetVPModeID(&( Scr->ViewPort )); /* Screen Mode ID */
  264.         offx = Scr->LeftEdge; 
  265.         offy = Scr->TopEdge;
  266.         Wid = Scr->Width;
  267.         Hei = Scr->Height;
  268.         if( dri = GetScreenDrawInfo( Scr ))
  269.             sDep = MoreColors ? dri->dri_Depth + 1 : dri->dri_Depth;
  270.         if( cols = AllocVec( sizeof( WORD ) * ( 1L << sDep ), MEMF_CLEAR ))
  271.             for( i = 0; i < ( 1L << dri->dri_Depth ); ++i )
  272.                 cols[i] = GetRGB4( Scr->ViewPort.ColorMap, i );
  273.         
  274.         if( GetPublic )
  275.             UnlockPubScreen( 0L, Scr );
  276.         
  277.         UnlockIBase( lock );
  278.         
  279.         QueryOverscan( sMod, &DispRect, OSCAN_TEXT );
  280.         
  281.         Wid = min( Wid, DispRect.MaxX - DispRect.MinX + 1 );
  282.         Hei = min( Hei, DispRect.MaxY - DispRect.MinY + 1 );
  283.         
  284.         if( sMod != INVALID_ID )
  285.         {
  286.             nScr = OpenScreenTags( NULL, SA_DisplayID, sMod, SA_Depth, sDep,
  287.                                   SA_Width, Wid, SA_Height, Hei,
  288.                                   SA_Behind, TRUE, SA_Quiet, TRUE, TAG_DONE );
  289.             if( nScr )
  290.             {
  291.                 BltBitMap( Scr->RastPort.BitMap, offx < 0 ? -offx : 0,
  292.                           offy < 0 ? -offy : 0, nScr->RastPort.BitMap, 0, 0,
  293.                           Wid, Hei, 0x00C0, 0x00FF, NULL );
  294.                 LoadRGB4( &(nScr->ViewPort), cols, 1L << sDep );
  295.                 if( offx > 0 )
  296.                     MoveScreen( nScr, offx, 0 );
  297.                 WaitBlit();
  298.                 ScreenToFront( nScr );
  299.             }
  300.         }
  301.         
  302.         if( cols )
  303.             FreeVec( cols );
  304.         
  305.         if( dri )
  306.             FreeScreenDrawInfo( Scr, dri );
  307.     }
  308.     
  309.     if( GfxBase )
  310.         CloseLibrary( GfxBase );
  311.     
  312.     if( IntuitionBase )
  313.         CloseLibrary(( struct Library * )IntuitionBase );
  314.     
  315.     return nScr;
  316. }
  317.  
  318. ULONG *SASM GetColorTable( AREG(0) struct Screen *Screen )
  319. {
  320.     return 0L;
  321. }
  322.  
  323. LONG SASM AvgBitsPerGun( DREG(0) LONG ModeID )
  324. {
  325.     return 4L;
  326. }
  327.  
  328. VOID SASM FadeAndLoadTable( AREG(0) struct Screen *Screen, DREG(0) LONG BPG,
  329.                            AREG(1) ULONG *ColorTable )
  330. {
  331.     struct Library *GfxBase;
  332.     
  333.     if( GfxBase = OpenLibrary( "graphics.library", 37L ))
  334.     {
  335.         LONG NumCols = ( 1L << Screen->RastPort.BitMap->Depth ), i, col;
  336.         
  337.         for( i = 0; i < NumCols; ++i )
  338.         {
  339.             col = GetRGB4( Screen->ViewPort.ColorMap, i );
  340.             SetRGB4(&( Screen->ViewPort ), i,
  341.                     (( col & 0x0F00 ) >> 8 ) > 0 ?
  342.                     (( col & 0x0F00 ) >> 8 ) - 1 : 0,
  343.                     (( col & 0x00F0 ) >> 4 ) > 0 ?
  344.                     (( col & 0x00F0 ) >> 4 ) - 1 : 0,
  345.                     ( col & 0x000F ) > 0 ? ( col & 0x000F ) - 1 : 0 );
  346.         }
  347.     }
  348.     
  349.     if( GfxBase )
  350.         CloseLibrary( GfxBase );
  351. }
  352.  
  353. struct Window *SASM BlankMousePointer( AREG(0) struct Screen *Scr )
  354. {
  355.     struct Library *IntuitionBase, *GfxBase;
  356.     struct Window *Wnd;
  357.     ULONG oldmodes;
  358.     
  359.     IntuitionBase = OpenLibrary( "intuition.library", 37L );
  360.     GfxBase = OpenLibrary( "graphics.library", 37L );
  361.     
  362.     if( IntuitionBase && GfxBase )
  363.     {
  364.         oldmodes = SetPubScreenModes( 0 );
  365.         if( Wnd = OpenWindowTags( 0L, WA_Activate, TRUE, WA_Left, 0, WA_Top, 0,
  366.                                  WA_Width, 1, WA_Height, 1, WA_Borderless,
  367.                                  TRUE, WA_CustomScreen, Scr, TAG_END ))
  368.         {
  369.             if( Wnd->UserData = AllocVec( 3 * 2 * sizeof( UWORD ),
  370.                                          MEMF_CHIP|MEMF_CLEAR ))
  371.             {
  372.                 /* Set a pointer sprite of size 16*1 (alloc and clear data for
  373.                    sprite def which is 2 control words, 2 words 4-color data
  374.                    for each line and 2 empty words at the end (as suggested in
  375.                    Hardware Reference Manual)). */
  376.                 SetPointer( Wnd, ( UWORD * )Wnd->UserData, 1, 16, 0, 0 );
  377.             }
  378.         }
  379.         SetPubScreenModes( oldmodes );
  380.     }
  381.     
  382.     if( GfxBase )
  383.         CloseLibrary( GfxBase );
  384.     
  385.     if( IntuitionBase )
  386.         CloseLibrary( IntuitionBase );
  387.  
  388.     return Wnd;
  389. }
  390.  
  391. VOID SASM UnblankMousePointer( AREG(0) struct Window *Wnd )
  392. {
  393.     struct Library *IntuitionBase;
  394.     
  395.     if( IntuitionBase = OpenLibrary( "intuition.library", 37L ))
  396.     {
  397.         if( Wnd )
  398.         {
  399.             if( Wnd->UserData )
  400.                 FreeVec( Wnd->UserData );
  401.             CloseWindow( Wnd );
  402.         }
  403.         CloseLibrary( IntuitionBase );
  404.     }
  405. }
  406.  
  407. Triplet *AllocTable( LONG Colors, LONG Dep, LONG Offset )
  408. {
  409.     return 0L;
  410. }
  411.  
  412. UWORD Table1[] = { 0, 0x0FFF };
  413. UWORD Table2[] = { 0, 0x0E00, 0x00E0, 0x000E, 0x0E00, 0x00E0, 0x000E };
  414. WORD Table3[] = {
  415.     0,
  416.     0x0E00, 0x0770, 0x00E0, 0x0077, 0x000E, 0x0707, 0x0707, 0x0E00, 0x0770,
  417.     0x00E0, 0x0077, 0x000E, 0x0707, 0x0707 };
  418. UWORD Table4[] = {
  419.     0,
  420.     0x0E03, 0x0B06, 0x0909, 0x060B, 0x030E, 0x003E, 0x006B, 0x0099, 0x00B6,
  421.     0x00E3, 0x03E0, 0x06B0, 0x0990, 0x0B60, 0x0E30, 0x0E03, 0x0B06, 0x0909,
  422.     0x060B, 0x030E, 0x003E, 0x006B, 0x0099, 0x00B6, 0x00E3, 0x03E0, 0x06B0,
  423.     0x0990, 0x0B60, 0x0E30 };
  424. UWORD Table5[] = {
  425.     0,
  426.     0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980, 0x0890, 0x06B0, 0x05C0, 0x03E0,
  427.     0x02F0, 0x00F2, 0x00E3, 0x00C5, 0x00B6, 0x0098, 0x006B, 0x005C, 0x003E,
  428.     0x002F, 0x020F, 0x030E, 0x050C, 0x060B, 0x0809, 0x0908, 0x0B06, 0x0C05,
  429.     0x0E03, 0x0F02, 0x0F00, 0x0F00, 0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980,
  430.     0x0890, 0x06B0, 0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3, 0x00C5, 0x00B6,
  431.     0x0098, 0x006B, 0x005C, 0x003E, 0x002F, 0x020F, 0x030E, 0x050C, 0x060B,
  432.     0x0809, 0x0908, 0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00, 0x0F00 };
  433. UWORD Table6[] = {
  434.     0,
  435.     0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980, 0x0890, 0x06B0, 0x05C0, 0x03E0,
  436.     0x02F0, 0x00F2, 0x00E3, 0x00C5, 0x00B6, 0x0098, 0x006B, 0x005C, 0x003E,
  437.     0x002F, 0x020F, 0x030E, 0x050C, 0x060B, 0x0809, 0x0908, 0x0B06, 0x0C05,
  438.     0x0E03, 0x0F02, 0x0F00, 0x0F00, 0x0F00, 0x0F20, 0x0E30, 0x0C50, 0x0B60,
  439.     0x0980, 0x0890, 0x06B0, 0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3, 0x00C5,
  440.     0x00B6, 0x0098, 0x006B, 0x005C, 0x003E, 0x002F, 0x020F, 0x030E, 0x050C,
  441.     0x060B, 0x0809, 0x0908, 0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00, 0x0F20,
  442.     0x0E30, 0x0C50, 0x0B60, 0x0980, 0x0890, 0x06B0, 0x05C0, 0x03E0, 0x02F0,
  443.     0x00F2, 0x00E3, 0x00C5, 0x00B6, 0x0098, 0x006B, 0x005C, 0x003E, 0x002F,
  444.     0x020F, 0x030E, 0x050C, 0x060B, 0x0809, 0x0908, 0x0B06, 0x0C05, 0x0E03,
  445.     0x0F02, 0x0F00, 0x0F00, 0x0F00, 0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980,
  446.     0x0890, 0x06B0, 0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3, 0x00C5, 0x00B6,
  447.     0x0098, 0x006B, 0x005C, 0x003E, 0x002F, 0x020F, 0x030E, 0x050C, 0x060B,
  448.     0x0809, 0x0908, 0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00 };
  449. UWORD *TblPtr[] = { Table1, Table2, Table3, Table4, Table5, Table6 };
  450.  
  451. Triplet *SASM RainbowPalette( AREG(0) struct Screen *Screen,
  452.                              AREG(1) Triplet *Table, DREG(0) LONG Offset,
  453.                              DREG(1) LONG EP )
  454. {
  455.     struct Library *GfxBase;
  456.     static LONG i = 0L;
  457.     
  458.     if( Screen )
  459.     {
  460.         if( GfxBase = OpenLibrary( "graphics.library", 37L ))
  461.         {
  462.             LONG Colors[] = { 2, 4, 8, 16, 32, 64 };
  463.             LONG Depth = Screen->BitMap.Depth;
  464.             UWORD *Cols, Tmp;
  465.     
  466.             Cols = &( TblPtr[Depth-1][i] );
  467.             Tmp = Cols[0];
  468.             Cols[0] = 0;
  469.             LoadRGB4(&( Screen->ViewPort ), Cols, Colors[Depth-1] );
  470.             Cols[0] = Tmp;
  471.             i = ++i % ( Colors[Depth-1] );
  472.         }
  473.         
  474.         if( GfxBase )
  475.             CloseLibrary( GfxBase );
  476.     }
  477.  
  478.     return 0L;
  479. }
  480.