home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 064.lha / all4096.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-20  |  6.0 KB  |  207 lines

  1. /* This was written way back in Dec. 86 for Lattice C under WB 1.1 */
  2. /* It may work if re-compiled under other compilers or versions of */
  3. /* Kickstart, but then again....                                   */
  4.  
  5. /* Besides, it works as is under 1.2.... just type "All4096"       */
  6.  
  7.  
  8. /* 'C' Header files required */
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <graphics/gfxbase.h>
  13. #include <graphics/display.h>
  14. #include <lattice/stdio.h>
  15.  
  16.  
  17. #define WE_SURVIVED 0                 /* My names for exit codes */
  18. #define NO_INTUITION 1
  19. #define NO_GRAPHICS 2
  20. #define NO_MAKEE_SCREEN 3
  21. #define NO_MAKEE_WINDOW 4
  22.  
  23.  
  24. struct IntuitionBase *IntuitionBase;  /* These are all pointers to system */
  25. struct GfxBase       *GfxBase;        /* data structures I need access to */
  26. struct RastPort      *drawport;
  27. struct ViewPort      *my_view;
  28.  
  29. #define INTUITION_REV 0        /* yeah, yeah... I know */
  30. #define MILLION 1000000
  31.  
  32. struct NewScreen my_screen_needs=   /* This is the structure I pass to */
  33.    {                                /* the OpenScreen() function to    */
  34.    0,                               /* open my own screen */
  35.    0,
  36.    320,
  37.    200,
  38.    6,
  39.    0, 1,
  40.    HAM,
  41.    CUSTOMSCREEN,
  42.    NULL,
  43.    "4096, count em, 4096 colours!",
  44.    NULL,
  45.    NULL
  46.    };
  47.  
  48. main()
  49. {
  50.    struct Screen *my_screen_pointer;/* This will point at my new screen */
  51.    struct NewWindow my_window_needs;/* This is my window request structure*/
  52.    struct Window *my_window_pointer;/* Will point at my new window */
  53.    long i,x,y,y2;
  54.  
  55.    IntuitionBase=                                 /* Open up Intuition... */
  56.       (struct IntuitionBase *)OpenLibrary("intuition.library",INTUITION_REV);
  57.    if(IntuitionBase==NULL) exit(NO_INTUITION);
  58.  
  59.    GfxBase=                             /* ...and the Graphics Library... */
  60.       (struct GfxBase *)OpenLibrary("graphics.library",0);
  61.    if(GfxBase==NULL)
  62.       {
  63.       CloseLibrary(IntuitionBase);
  64.       exit(NO_GRAPHICS);
  65.       };
  66.  
  67.    my_screen_pointer=                            /* ...and a new screen... */
  68.       (struct Screen *)OpenScreen(&my_screen_needs);
  69.    if (my_screen_pointer==NULL)
  70.       {
  71.       CloseLibrary(GfxBase);
  72.       CloseLibrary(IntuitionBase);
  73.       exit(NO_MAKEE_SCREEN);
  74.       };
  75.  
  76.  
  77.    my_window_needs.LeftEdge=0;  /* setting my requirements */
  78.    my_window_needs.TopEdge=11;
  79.    my_window_needs.Width=280;
  80.    my_window_needs.Height=173;
  81.    my_window_needs.DetailPen=0;
  82.    my_window_needs.BlockPen=1;
  83.    my_window_needs.Title="Blitter Assisted Jet Takeoff!";
  84.    my_window_needs.Flags=
  85.      SMART_REFRESH | WINDOWCLOSE | ACTIVATE | NOCAREREFRESH |
  86.      WINDOWDRAG;
  87.    my_window_needs.IDCMPFlags= CLOSEWINDOW;
  88.    my_window_needs.Type=CUSTOMSCREEN;
  89.    my_window_needs.FirstGadget=NULL;
  90.    my_window_needs.CheckMark=NULL;
  91.    my_window_needs.Screen=my_screen_pointer; /* link it to my new screen */
  92.    my_window_needs.BitMap=NULL;
  93.    my_window_needs.MinWidth=278;
  94.    my_window_needs.MinHeight=173;
  95.    my_window_needs.MaxWidth=278;
  96.    my_window_needs.MaxHeight=173;
  97.  
  98.    /* ...and open the bastard!*/
  99.    if ( (my_window_pointer=(struct Window *)OpenWindow(&my_window_needs))
  100.       == NULL)
  101.       {
  102.       CloseScreen(my_screen_pointer);
  103.       CloseLibrary(GfxBase);
  104.       CloseLibrary(IntuitionBase);
  105.       exit(NO_MAKEE_WINDOW);
  106.       };
  107.    my_view=&my_screen_pointer->ViewPort; /* extract ViewPort pointer...*/
  108.    drawport=my_window_pointer->RPort;    /* and RastPort pointer   */
  109.  
  110.  
  111.    /* AND LET THE GAMES BEGIN!!! */
  112.  
  113.    WritePixel(drawport,5,11); /* First pixel */
  114.  
  115.    /* first draw a 17 pixel line using HAM & going from no to full blue */
  116.    for(x=6;x<22;x++)
  117.       {
  118.       SetAPen(drawport,(x-6)+16);
  119.       WritePixel(drawport,x,11);
  120.       };
  121.  
  122.    /* now Blitterize it - copy it sixteen times across the screen */
  123.    for(x=1;x<16;x++)
  124.       BltBitMap(drawport->BitMap,5,22,
  125.                 drawport->BitMap,5+(x*17),22,
  126.                 17,1,
  127.                 0xca,0xff,NULL);
  128.  
  129.    /* change every 17'th pixel to a different red value */
  130.    for(x=0;x<16;x++)
  131.       {
  132.       SetAPen(drawport,x+32);
  133.       WritePixel(drawport,5+(x*17),11);
  134.       };
  135.  
  136.    /* copy this line 10 times to make a rectangle (using the Blitter) */
  137.    for(y=23;y<32;y++)
  138.       BltBitMap(drawport->BitMap,5,22,
  139.                 drawport->BitMap,5,y,
  140.                 274,1,
  141.                 0xca,0xff,NULL);
  142.  
  143.    /* copy this rectangle 16 times (Blitterly), and the window's full */
  144.    /* elapsed time so far, about 1/10 second */
  145.    for(y=1;y<16;y++)
  146.       BltBitMap(drawport->BitMap,5,22,
  147.                 drawport->BitMap,5,22+(y*10),
  148.                 274,10,
  149.                 0xca,0xff,NULL);
  150.  
  151.  
  152.    /* all I do now is adjust the first pixel in each line to an appropriate
  153.    green value, et voila! 40960 pixels & 4096 colors before you can blink */
  154.    for(y=11;y<171;y++)
  155.       {
  156.       SetAPen(drawport,((y-11)/10)+48);
  157.       WritePixel(drawport,4,y);
  158.       };
  159.  
  160.    for(i=0;i<200000;i++); /* wait for blink */
  161.  
  162.  
  163.    /* Change Window & Screen titles */
  164.    SetWindowTitles(my_window_pointer,
  165.                    "Window on the World",
  166.                    "Hold & Modify Demo"
  167.                    );
  168.  
  169.  
  170.    /* Wait until window is closed */
  171.    Wait(1<<my_window_pointer->UserPort->mp_SigBit);
  172.  
  173.    /* Temporary titles */
  174.    SetWindowTitles(my_window_pointer,
  175.                    "Blitter Assisted Landing!",
  176.                    "4096, count em, 4096 colours"
  177.                   );
  178.  
  179.  
  180.    /* Roller-blind scrolling algorithm */
  181.    for(i=171;i>=11;i-=2)
  182.       {
  183.       WaitBOVP(my_view);
  184.       /* The WaitBOVP() is to try and eliminate flicker when scrolling */
  185.       /* didn't work too good though... any ideas out there? */
  186.       ScrollRaster(drawport,0,2,4,11,275,i);
  187.       };
  188.  
  189.    /* Closing Titles & Credits */
  190.    SetWindowTitles(my_window_pointer,
  191.                    "'C' you later!",
  192.                    "Coded by Pete Patterson"
  193.                   );
  194.  
  195.    for(i=0;i<200000;i++); /* Give em a good look */
  196.  
  197.  
  198.    /* Close up shop, clean up & go home */
  199.    CloseWindow(my_window_pointer);
  200.    CloseScreen(my_screen_pointer);
  201.    CloseLibrary(GfxBase);
  202.    CloseLibrary(IntuitionBase);
  203.    exit(WE_SURVIVED);
  204. }
  205.  
  206.  
  207.