home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / amiga / programm / 15900 < prev    next >
Encoding:
Text File  |  1992-11-16  |  6.2 KB  |  228 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!think.com!ames!saimiri.primate.wisc.edu!doug.cae.wisc.edu!pochanay
  3. From: pochanay@cae.wisc.edu (Adisak Pochanayon)
  4. Subject: Re: Bug in ViewPorts under 2.0
  5. Organization: College of Engineering, Univ. of Wisconsin--Madison
  6. Date: 16 Nov 92 07:28:03 CST
  7. Message-ID: <1992Nov16.072803.1545@doug.cae.wisc.edu>
  8. References: <1992Nov16.065000.1070@doug.cae.wisc.edu>
  9. Sender: pochanay@cae.wisc.ed
  10. Lines: 216
  11.  
  12.  
  13.      This program illustrates the bug I mentioned about RxOffset under
  14.      2.0 using hi-resolution screens.
  15.  
  16.      pochanay@cae.wisc.edu
  17.  
  18. ----------------------------  cut here   -----------------------------
  19.  
  20. /* 
  21.    boxomatic.c    by Gregg Williams
  22.                      BYTE Magazine
  23.                      PO Box 372
  24.                      Hancock NH  03449
  25.                      Phone: 603-924-9281
  26.                      BIX: greggw
  27.  
  28.  
  29. modified by Adisak Pochanayon to show hires scrolling problem under 2.0.
  30. Ignore all the dual playfield comments.  The second playfield has been
  31. removed.  pochanay@cae.wisc.edu
  32. */
  33.  
  34. #include <exec/types.h>
  35. #include <stdio.h>
  36. #include <graphics/gfx.h>
  37. #include <hardware/dmabits.h>
  38. #include <hardware/custom.h>
  39. #include <hardware/blit.h>
  40. #include <graphics/gfxmacros.h>
  41. #include <graphics/copper.h>
  42. #include <graphics/view.h>
  43. #include <graphics/rastport.h>
  44. #include <graphics/gels.h>
  45. #include <graphics/regions.h>
  46. #include <graphics/clip.h>
  47. #include <exec/exec.h>
  48. #include <graphics/text.h>
  49. #include <graphics/gfxbase.h>
  50. #include <proto/graphics.h>
  51. #include <proto/exec.h>
  52.  
  53. #define DEPTH 3L      /* depth of playfield 1, (scrolling, on bottom) */
  54. #define WIDTH 640L    /* dimensions of playfield 1 */
  55. #define HEIGHT 400L
  56. #define VPWIDTH 322L   /* dimensions of the viewport */
  57. #define VPHEIGHT 200L
  58. #define NOT_ENOUGH_MEMORY -1000
  59. #define PF1_BACKGD 7L
  60.  
  61. /* construct a simple display */
  62.  
  63. struct View view;
  64. struct ViewPort viewport;
  65. struct ColorMap *cm;
  66. struct RasInfo rasinfo;
  67. struct BitMap bitmap;
  68. struct RastPort rastport;
  69. struct GfxBase *GfxBase;
  70. struct View *oldview;
  71.  
  72. USHORT colortable[]={
  73.   0x000, 0xfb0, 0xccc, 0xf15,  0xa50, 0x0c5, 0x777, 0x77f,
  74.   0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0
  75. };
  76.  
  77. UWORD *colorpalette;
  78.  
  79. void draw_playfields(void);
  80. void draw_box(LONG, LONG, LONG, LONG);
  81. void FreeMemory(void);
  82.  
  83. void _main()
  84.  
  85. {
  86.   LONG i, n;
  87.   SHORT nmax;
  88.   SHORT pf1_xmove, pf1_ymove;
  89.  
  90.   /* 'nmax' determines how long the display runs; see below */
  91.  
  92.     nmax = 10;
  93.  
  94.   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
  95.   if (GfxBase == NULL) _exit(100);
  96.   oldview = GfxBase->ActiView;
  97.  
  98.   InitView(&view);
  99.   InitVPort(&viewport);
  100.   view.ViewPort = &viewport;
  101. /**************************************************************************
  102.  
  103.     Works fine if Modes = 0;  Does the wierd 2 pixel thing under 2.0
  104.   if Modes = HIRES;  How do you get around this.  It works fine under
  105.   1.3 either way.
  106.  
  107. **************************************************************************/
  108.   view.Modes = viewport.Modes = HIRES;   
  109.  
  110.   InitBitMap(&bitmap, DEPTH, WIDTH, HEIGHT);
  111.   InitRastPort(&rastport);
  112.   rastport.BitMap = &bitmap;
  113.   rasinfo.BitMap = &bitmap;
  114.   rasinfo.RxOffset = 0;
  115.   rasinfo.RyOffset = 0;
  116.   rasinfo.Next = NULL;
  117.  
  118.   viewport.DWidth = VPWIDTH;
  119.   viewport.DHeight = VPHEIGHT;
  120.   viewport.RasInfo = &rasinfo;
  121.  
  122.   cm = GetColorMap(32);
  123.   if (cm == NULL) {
  124.     FreeMemory();
  125.     _exit(100);
  126.   }
  127.   colorpalette = (UWORD *)cm->ColorTable;
  128.   for(i=0; i<32; i++) {
  129.     *colorpalette++ = colortable[i];
  130.   }
  131.   viewport.ColorMap = cm;
  132.  
  133.   for(i=0; i<DEPTH; i++) {
  134.     bitmap.Planes[i] = (PLANEPTR) AllocRaster(WIDTH, HEIGHT);
  135.         if(bitmap.Planes[i] == NULL) {
  136.         FreeMemory();
  137.         _exit(NOT_ENOUGH_MEMORY);
  138.       }
  139.     BltClear(bitmap.Planes[i], RASSIZE(WIDTH, HEIGHT), 1);
  140.   }
  141.  
  142.   draw_playfields();
  143.  
  144.   /* These three instructions assemble and "load" the view we've defined.*/
  145.   MakeVPort(&view, &viewport);
  146.   MrgCop(&view);
  147.   LoadView(&view);
  148.   pf1_xmove = 1; pf1_ymove = 1;
  149.   for( n=1; n<=nmax;  )   {
  150. /**************************************************************************
  151.  
  152.       All right, here is where the RxOffset is modified.
  153.       Note that under 2.0 in hires, RxOffset is multiplied by 2
  154.       somehow during the display.  This is a bug I wish to get
  155.       around.  Please send help to pochanay@cae.wisc.edu.
  156.  
  157. **************************************************************************/
  158.           rasinfo.RxOffset = rasinfo.RxOffset + pf1_xmove;
  159.           rasinfo.RyOffset = rasinfo.RyOffset + pf1_ymove;
  160.  
  161.       if (rasinfo.RxOffset <= 0  ||  rasinfo.RxOffset >= 319)  {
  162.             pf1_xmove = -pf1_xmove;
  163.                 n = n + 1;
  164.       }
  165.       if (rasinfo.RyOffset <= 0  ||  rasinfo.RyOffset >= 199)  {
  166.             pf1_ymove = -pf1_ymove;
  167.                 n = n + 1;
  168.       }
  169.  
  170.      /* Reexecute this trio of instructions to make the changes visible. */
  171.           MakeVPort(&view, &viewport);
  172.           MrgCop(&view);
  173.           LoadView(&view);
  174.  
  175.           WaitTOF();
  176.   }
  177.  
  178.   /* Restore the system to its original state. */
  179.   LoadView(oldview);
  180.   FreeMemory();
  181.   CloseLibrary((struct Library *)GfxBase);
  182. }
  183.  
  184. void draw_playfields()
  185. {
  186.   LONG x, y, temp, color1, color2;
  187.   SetRast( &rastport, PF1_BACKGD );
  188.   temp = 1L;
  189.   for( x=25L; x<=590L; x=x+50L )   {
  190.     for ( y=0L; y<=350L; y=y+50L)   {
  191.           color1 = temp;
  192.           temp = temp + 1L;
  193.           if (temp > 7L) temp = 1L;
  194.           color2 = temp;
  195.           temp = temp + 1L;
  196.           if (temp > 7L) temp = 1L;
  197.           draw_box( x, y, color1, color2 );
  198.         }
  199.   }
  200. }
  201.  
  202. void draw_box( x, y, bigsq_color, smallsq_color )
  203. LONG x, y, bigsq_color, smallsq_color;
  204. {
  205.    SetAPen( &rastport, 0 );   /* draw black shadow */
  206.    RectFill( &rastport, x+4L, y+4L, x+40L, y+40L );
  207.    SetAPen( &rastport, 0 );   /* draw large black box */
  208.    RectFill( &rastport, x, y, x+36L, y+36L );
  209.    SetAPen( &rastport, bigsq_color );   /* draw large colored box */
  210.    RectFill( &rastport, x+2L, y+2L, x+34L, y+34L );
  211.    SetAPen( &rastport, smallsq_color );   /* draw small colored box */
  212.    RectFill( &rastport, x+12L, y+12L, x+24L, y+24L );
  213. }
  214.  
  215. void FreeMemory()
  216. {
  217.   LONG i;
  218.   for (i=0; i<DEPTH; i++) {
  219.         if (bitmap.Planes[i] != NULL) {
  220.       FreeRaster(bitmap.Planes[i], WIDTH, HEIGHT);
  221.         }
  222.   }
  223.   if (cm != NULL)  FreeColorMap(cm);
  224.   FreeVPortCopLists(&viewport);
  225.   FreeCprList(view.LOFCprList);
  226. }
  227.  
  228.