home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 10 / Fresh_Fish_10_2352.bin / new / dev / obero / oberon-a / examples / libraries / intuition / dualplayfield.mod < prev    next >
Text File  |  1995-07-02  |  6KB  |  217 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: DualPlayfield.mod $
  4.   Description: A port of dualplayfield.c in the RKM:Libraries.
  5.  
  6.                Shows how to turn on dual-playfield mode in a screen.
  7.  
  8.    Created by: fjc (Frank Copeland)
  9.     $Revision: 1.4 $
  10.       $Author: fjc $
  11.         $Date: 1995/01/25 23:52:19 $
  12.  
  13.   Copyright © 1994-1995, Frank Copeland.
  14.   This example program is part of Oberon-A.
  15.   See Oberon-A.doc for conditions of use and distribution.
  16.  
  17. *************************************************************************)
  18.  
  19. <* STANDARD- *>
  20.  
  21. MODULE DualPlayfield;
  22.  
  23. IMPORT SYS := SYSTEM, e := Exec, gfx := Graphics, i := Intuition;
  24.  
  25. CONST
  26.   VersionTag = "$VER: DualPlayfield 1.3 (24.1.95)\r\n";
  27.   VersionStr = "DualPlayfield 1.3 (23.1.95)\r\n";
  28.   CopyrightStr = "Copyright © 1994-1995 Frank Copeland";
  29.  
  30. (*------------------------------------
  31. ** Manhandle the viewport:
  32. ** install second playfield and change modes
  33. *)
  34. PROCEDURE InstallDualPF
  35.   ( scrn : i.ScreenPtr; rinfo2 : gfx.RasInfoPtr )
  36.   : BOOLEAN;
  37.  
  38.   VAR
  39.     screenModeID : LONGINT;
  40.     returnCode : BOOLEAN;
  41.  
  42. BEGIN (* InstallDualPF *)
  43.   screenModeID := gfx.GetVPModeID (SYS.ADR (scrn.viewPort));
  44.   IF screenModeID # gfx.invalidID THEN
  45.     (* You can only play with the bits in the modes field
  46.     ** if the upper half of the screen mode ID is zero!!!
  47.     *)
  48.     IF SYS.AND (screenModeID, 0FFFF0000H) = 0 THEN
  49.       returnCode := TRUE;
  50.       e.Forbid();
  51.         (* Install rinfo for viewport's second playfield *)
  52.         scrn.viewPort.rasInfo.next := rinfo2;
  53.         INCL (scrn.viewPort.modes, gfx.dualpf);
  54.       e.Permit();
  55.       (* Put viewport change into effect *)
  56.       i.MakeScreen (scrn);
  57.       i.RethinkDisplay ();
  58.     END
  59.   END;
  60.   RETURN returnCode
  61. END InstallDualPF;
  62.  
  63. (*------------------------------------*)
  64. (* Draw some lines in a rastport...This is used to get some data into
  65. ** the second playfield.  The windows on the screen will move underneath
  66. ** these graphics without disturbing them.
  67. *)
  68. PROCEDURE DrawSomething (rp : gfx.RastPortPtr);
  69.  
  70.   VAR
  71.     width, height : INTEGER;
  72.     r, c : INTEGER;
  73.  
  74. BEGIN (* DrawSomething *)
  75.   width := rp.bitMap.bytesPerRow * 8;
  76.   height := rp.bitMap.rows;
  77.   gfx.SetAPen (rp, 1);
  78.   FOR r := 0 TO height - 1 BY 40 DO
  79.     FOR c := 0 TO width - 1 BY 40 DO
  80.       gfx.Move (rp, 0, r);
  81.       gfx.Draw (rp, c, 0)
  82.     END
  83.   END
  84. END DrawSomething;
  85.  
  86. (*------------------------------------*)
  87. (* simple event loop to wait for the user to hit the close gadget
  88. ** on the window.
  89. *)
  90. PROCEDURE HandleIDCMP (win : i.WindowPtr);
  91.  
  92.   VAR
  93.     done    : BOOLEAN;
  94.     message : i.IntuiMessagePtr;
  95.     class   : SET;
  96.     signals : SET;
  97.  
  98. BEGIN (* HandleIDCMP *)
  99.   done := FALSE;
  100.   WHILE ~done DO
  101.     signals := e.Wait ({win.userPort.sigBit});
  102.     IF win.userPort.sigBit IN signals THEN
  103.       LOOP
  104.         message :=
  105.           SYS.VAL (i.IntuiMessagePtr, e.GetMsg (win.userPort));
  106.         IF message = NIL THEN EXIT END;
  107.         class := message.class;
  108.         e.ReplyMsg (message);
  109.         IF class = {i.closeWindow} THEN
  110.           done := TRUE
  111.         END;
  112.         IF done THEN EXIT END;
  113.       END
  114.     END
  115.   END
  116. END HandleIDCMP;
  117.  
  118. (*------------------------------------*)
  119. (* remove the effects of InstallDualPF();
  120. ** only call if InstallDualPF() succeeded.
  121. *)
  122. PROCEDURE RemoveDualPF (scrn : i.ScreenPtr);
  123.  
  124. BEGIN (* RemoveDualPF *)
  125.   e.Forbid();
  126.     scrn.viewPort.rasInfo.next := NIL;
  127.     EXCL (scrn.viewPort.modes, gfx.dualpf);
  128.   e.Permit();
  129.   i.MakeScreen (scrn);
  130.   i.RethinkDisplay ();
  131. END RemoveDualPF;
  132.  
  133. (*------------------------------------*)
  134. PROCEDURE DoDualPF (win : i.WindowPtr);
  135.  
  136.   VAR
  137.     myScreen : i.ScreenPtr;
  138.     rinfo2   : gfx.RasInfoPtr;
  139.     bmap2    : gfx.BitMapPtr;
  140.     rport2   : gfx.RastPortPtr;
  141.  
  142. BEGIN (* DoDualPF *)
  143.   myScreen := win.wScreen; (* Find the window's screen *)
  144.  
  145.   (* Allocate the second playfield's rasinfo, bitmap, and bitplane *)
  146.   rinfo2 := e.AllocMem (SIZE (gfx.RasInfo), {e.public, e.memClear});
  147.   IF rinfo2 # NIL THEN
  148.     (* Get a rastport, and set it up for rendering into bmap2 *)
  149.     rport2 := e.AllocMem (SIZE (gfx.RastPort), {e.public});
  150.     IF rport2 # NIL THEN
  151.       bmap2 := e.AllocMem (SIZE (gfx.BitMap), {e.public, e.memClear});
  152.       IF bmap2 # NIL THEN
  153.         gfx.InitBitMap (bmap2^, 1, myScreen.width, myScreen.height);
  154.         (* extra playfield will only use one bitplane here. *)
  155.         bmap2.planes [0] :=
  156.           gfx.AllocRaster (myScreen.width, myScreen.height);
  157.         IF bmap2.planes [0] # NIL THEN
  158.           gfx.InitRastPort (rport2^);
  159.           rinfo2.bitMap := bmap2; rport2.bitMap := bmap2;
  160.           gfx.SetRast (rport2, 0);
  161.           IF InstallDualPF (myScreen, rinfo2) THEN
  162.             (* Set foreground color; color 9 is color 1 for
  163.             ** second playfield of hi-res viewport.
  164.             *)
  165.             gfx.SetRGB4 (SYS.ADR (myScreen.viewPort), 9, 0, 0FH, 0);
  166.             DrawSomething (rport2);
  167.             HandleIDCMP (win);
  168.             RemoveDualPF (myScreen);
  169.           END;
  170.           gfx.FreeRaster
  171.             (bmap2.planes [0], myScreen.width, myScreen.height)
  172.         END;
  173.         e.FreeMem (bmap2, SIZE (gfx.BitMap))
  174.       END;
  175.       e.FreeMem (rport2, SIZE (gfx.RastPort))
  176.     END;
  177.     e.FreeMem (rinfo2, SIZE (gfx.RasInfo))
  178.   END;
  179. END DoDualPF;
  180.  
  181. (*------------------------------------*)
  182. PROCEDURE Main ();
  183.  
  184.   VAR
  185.     win : i.WindowPtr;
  186.     scr : i.ScreenPtr;
  187.  
  188. BEGIN (* Main *)
  189.   scr := i.OpenScreenTagsA
  190.     ( NIL,
  191.       i.saDepth,     2,
  192.       i.saDisplayID, gfx.hiresKey,
  193.       i.saTitle,     SYS.ADR ("Dual Playfield Test Screen"),
  194.       0 );
  195.   IF scr # NIL THEN
  196.     win := i.OpenWindowTagsA
  197.       ( NIL,
  198.         i.waTitle,        SYS.ADR ("Dual Playfield Mode"),
  199.         i.waIDCMP,        {i.closeWindow},
  200.         i.waWidth,        200,
  201.         i.waHeight,       100,
  202.         i.waDragBar,      1,
  203.         i.waCloseGadget,  1,
  204.         i.waCustomScreen, scr,
  205.         0 );
  206.     IF win # NIL THEN
  207.       DoDualPF (win);
  208.       i.CloseWindow (win)
  209.     END;
  210.     i.OldCloseScreen (scr)
  211.   END;
  212. END Main;
  213.  
  214. BEGIN (* DualPlayfield *)
  215.   Main ();
  216. END DualPlayfield.
  217.