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

  1. /*
  2.          graphics demo of overscan
  3.          (variation on a theme from Kernighan and Ritchie)
  4.          Jan. 15, 1987 by Steve Joust
  5.  
  6.  
  7.          A lot of this code is from the ROM Kernal Manuals, volume 1
  8.          chapter 2, pages 28-31.
  9.          The comments are unfortunately mine.
  10.  
  11.          This code does not seem to work under 1.1, *unless* WIDTH and
  12.          HEIGHT are changed to "normal" values ie., 320 and 200 respectively
  13.          for a lo-res non-interlaced display.  Also, VERSION will have to be
  14.          bumped down to a 1.1 value.
  15.  
  16.          This program is presented "as is" for demonstration purposes only,
  17.          if it breaks something - TOUGH!
  18.  
  19.          To compile under Lattice v3.10:
  20.  
  21.             LC1 -iinclude view.c
  22.             LC2 -v -cdb view.q
  23.             BLINK c.o+view.o LIBRARY amiga.lib TO view MAP nil:
  24.  
  25.          note on c.o - the one I used was modified a bit so it didn't
  26.                        need the LC.LIB.  It goes something like this:
  27.  
  28.                        1) get hold of the 'c.a' file from Lattice 3.03 disk
  29.                        2) change all __main to _main
  30.                        3) put 'clr.l d0'  before opening DOS
  31.                        4) delete all lines with _MemCleanup
  32.                        5) assemble with the Metacomco assembler
  33.                        6) don't hold your breath - 'though it works for me
  34.  
  35.  
  36.       Credits:
  37.          Mike Farren's "Gi" program, which I used to convert
  38.          DPaint brushes to image data.  Good job, Mr. Farren!
  39.  
  40.          DPaint 2.0 and the full video (shifted s) mode, which
  41.          stimulated the brain cells into action (and created brushes with).
  42.  
  43.          6 brown (now empty) bottles of Henry Weinhards, which stimulated
  44.          the rest of the body into action. Good job, Mr. Weinhard!
  45. */
  46.  
  47. #include "exec/types.h"
  48. #include "exec/exec.h"
  49. #include "graphics/gfx.h"
  50. #include "hardware/dmabits.h"
  51. #include "hardware/custom.h"
  52. #include "hardware/blit.h"
  53. #include "graphics/gfxmacros.h"
  54. #include "graphics/copper.h"
  55. #include "graphics/view.h"
  56. #include "graphics/gels.h"
  57. #include "graphics/regions.h"
  58. #include "graphics/clip.h"
  59. #include "graphics/text.h"
  60. #include "graphics/gfxbase.h"
  61. #include "intuition/intuition.h"
  62. #include "libraries/dos.h"
  63.  
  64.  
  65.  
  66. #define DEPTH  2       /* number of bit planes */
  67.  
  68. /*  WARNING - the following numbers are larger than the system
  69.     software allows for in a low-res, noninterlaced display, BUT they
  70.     don't *seem* to do any damage.  I chose them because the image data
  71.     width and height divide evenly into them.  I know it's a poor excuse,
  72.     but tough!  It's only a demo.
  73. */
  74. #define WIDTH  384     /* width of display - 352 is the limit */
  75. #define HEIGHT 280     /* height of display - 232 is the limit */
  76.  
  77. #define VERSION 33     /* as supplied to OpenLibrary() */
  78.  
  79. #define IW  48         /* Image Width */
  80. #define IH  70         /* Image Height */
  81.  
  82. /* this is the image data that gets stamped all over the display */
  83.  
  84. UWORD hw[] = {             /* place your owm image data here and adjust */
  85.                            /* the IW and IH defines accordingly. */
  86.    0x0000,0x0000,0x0000,
  87.    0x0000,0x0000,0x0000,
  88.    0x0000,0x0000,0x0000,
  89.    0x0000,0x0000,0x0000,
  90.    0x0000,0x0001,0x8100,
  91.    0x0000,0x0003,0xc380,
  92.    0x0000,0x0000,0xc100,
  93.    0x0000,0x0002,0xe000,
  94.    0x0000,0x0002,0x7800,
  95.    0x0000,0x0007,0x1000,
  96.    0x0000,0x0183,0x6000,
  97.    0x0000,0x03c0,0x8000,
  98.    0x0000,0x00c0,0x0000,
  99.    0x0000,0x0060,0x0000,
  100.    0x0000,0x0078,0x0000,
  101.    0x0000,0x1030,0x0000,
  102.    0x0000,0x3c00,0x0000,
  103.    0x0000,0x6c00,0x0000,
  104.    0x0001,0xe000,0x0000,
  105.    0x0001,0x6000,0x0000,
  106.    0x000e,0x7800,0x0000,
  107.    0x001f,0x3000,0x0000,
  108.    0x0023,0x0000,0x0000,
  109.    0x00b1,0x0000,0x0000,
  110.    0x01ba,0x0000,0x0000,
  111.    0x00dc,0x0000,0x0000,
  112.    0x0a80,0x0000,0x0000,
  113.    0x19c0,0x0000,0x0000,
  114.    0x0cc0,0x0000,0x0000,
  115.    0x0b00,0x0000,0x0000,
  116.    0x0200,0x0000,0x0000,
  117.    0x0000,0x0000,0x0000,
  118.    0x0000,0x0000,0x0000,
  119.    0x0000,0x0000,0x0000,
  120.    0x0000,0x0000,0x0000,
  121.    0x0000,0x0000,0x0000,
  122.    0x0000,0x0000,0x0010,
  123.    0x0000,0x0000,0x0018,
  124.    0x0000,0x0000,0x0c18,
  125.    0x0000,0x0000,0x3610,
  126.    0x0000,0x0000,0x2700,
  127.    0x0000,0x0000,0x7200,
  128.    0x0000,0x0018,0x3400,
  129.    0x0000,0x003c,0x0800,
  130.    0x0000,0x000c,0x0000,
  131.    0x0000,0x0006,0x0000,
  132.    0x0000,0x0407,0x8000,
  133.    0x0000,0x0e03,0x0000,
  134.    0x0000,0x0700,0x0000,
  135.    0x0000,0x0300,0x0000,
  136.    0x0000,0x0180,0x0000,
  137.    0x0000,0x01c0,0x0000,
  138.    0x0000,0xe180,0x0000,
  139.    0x0001,0xf000,0x0000,
  140.    0x0023,0x6000,0x0000,
  141.    0x0063,0x9000,0x0000,
  142.    0x0031,0xa000,0x0000,
  143.    0x0339,0x4000,0x0000,
  144.    0x03bc,0x0000,0x0000,
  145.    0x01cc,0x0000,0x0000,
  146.    0x00c4,0x0000,0x0000,
  147.    0x00e0,0x0000,0x0000,
  148.    0x0060,0x0000,0x0000,
  149.    0x0000,0x0000,0x0000,
  150.    0x0000,0x0000,0x0000,
  151.    0x0000,0x0000,0x0000,
  152.    0x0000,0x0000,0x0000,
  153.    0x0000,0x0000,0x0000,
  154.    0x0000,0x0000,0x0000,
  155.    0x0000,0x0000,0x0000,
  156.  
  157. /* Bit Plane #1 */
  158.  
  159.    0xffff,0xffff,0xffff,
  160.    0xffff,0xffff,0xffff,
  161.    0xffff,0xfff3,0xf7ff,
  162.    0xffff,0xffe1,0xe3ff,
  163.    0xffff,0xfff8,0x76ff,
  164.    0xffff,0xffe8,0x3c7f,
  165.    0xffff,0xffec,0x3eff,
  166.    0xffff,0xffc5,0x1fff,
  167.    0xffff,0xf3e4,0x87ff,
  168.    0xffff,0xe1f8,0xefff,
  169.    0xffff,0xf87c,0x9fff,
  170.    0xffff,0xfc3f,0x7fff,
  171.    0xffff,0xfc3f,0xffff,
  172.    0xffff,0x7e1f,0xffff,
  173.    0xfffe,0x1f87,0xffff,
  174.    0xfffc,0x8fcf,0xffff,
  175.    0xfff0,0xc3ff,0xffff,
  176.    0xfff4,0x93ff,0xffff,
  177.    0xff8c,0x1fff,0xffff,
  178.    0xff06,0x1fff,0xffff,
  179.    0xfee1,0x87ff,0xffff,
  180.    0xfa60,0xcfff,0xffff,
  181.    0xf20c,0xffff,0xffff,
  182.    0xf90e,0xffff,0xffff,
  183.    0xaa45,0xffff,0xffff,
  184.    0x3123,0xffff,0xffff,
  185.    0x917f,0xffff,0xffff,
  186.    0xa63f,0xffff,0xffff,
  187.    0xe33f,0xffff,0xffff,
  188.    0xf4ff,0xffff,0xffff,
  189.    0xfdff,0xffff,0xffff,
  190.    0xffff,0xffff,0xffff,
  191.    0xffff,0xffff,0xffff,
  192.    0xffff,0xffff,0xffff,
  193.    0xffff,0xffff,0xff7f,
  194.    0xffff,0xffff,0xff3f,
  195.    0xffff,0xffff,0x9f2f,
  196.    0xffff,0xfffe,0x4f67,
  197.    0xffff,0xfffe,0xc3e7,
  198.    0xffff,0xfffc,0x49ef,
  199.    0xffff,0xff3e,0x58ff,
  200.    0xffff,0xfe1f,0x8dff,
  201.    0xffff,0xff87,0xcbff,
  202.    0xffff,0xffc3,0xf7ff,
  203.    0xffff,0xdfc3,0xffff,
  204.    0xffff,0x8fe1,0xffff,
  205.    0xffff,0xc3f8,0x7fff,
  206.    0xffff,0xe1fc,0xffff,
  207.    0xffff,0xf0ff,0xffff,
  208.    0xffff,0xf0ff,0xffff,
  209.    0xfff8,0xf27f,0xffff,
  210.    0xfff0,0x7e3f,0xffff,
  211.    0xfee4,0x1e7f,0xffff,
  212.    0xfce2,0x0fff,0xffff,
  213.    0xfe50,0x9fff,0xffff,
  214.    0xe614,0x6fff,0xffff,
  215.    0xe20e,0x5fff,0xffff,
  216.    0xf086,0xbfff,0xffff,
  217.    0xf843,0xffff,0xffff,
  218.    0xf833,0xffff,0xffff,
  219.    0xfc3b,0xffff,0xffff,
  220.    0xff1f,0xffff,0xffff,
  221.    0xff9f,0xffff,0xffff,
  222.    0xffff,0xffff,0xffff,
  223.    0xffff,0xffff,0xffff,
  224.    0xffff,0xffff,0xffff,
  225.    0xffff,0xffff,0xffff,
  226.    0xffff,0xffff,0xffff,
  227.    0xffff,0xffff,0xffff,
  228.    0xffff,0xffff,0xffff
  229. };
  230.  
  231.  
  232. /* the one and only image struct for above data */
  233.  
  234. struct Image si =
  235. {
  236.    0, 0,
  237.    IW, IH, DEPTH,
  238.    &hw[0],
  239.    0x3, 0x00,
  240.    NULL
  241. };
  242.  
  243.  
  244. struct View v;
  245. struct ViewPort vp;
  246. struct ColorMap *cm;
  247. struct RasInfo ri;
  248. struct BitMap b;
  249.  
  250. struct View *oldview;         /* the view we will hopefully return to */
  251. struct RastPort my_rast;      /* drawing will be done to this rastport */
  252. struct RastPort *rp;          /* pointer to my_rast */
  253.  
  254. ULONG fp;                     /* file pointer as returned by Open() */
  255.  
  256. USHORT colortable[] =         /* a few simple (rather dull) colors */
  257. {
  258.    0x000, 0x778, 0x555, 0x008
  259. };
  260.  
  261. UBYTE *displaymem;
  262. UWORD *colorpalette;
  263.  
  264. struct GfxBase *GfxBase;
  265. struct IntuitionBase *IntuitionBase;
  266.  
  267. main(argc, argv)
  268. LONG argc;
  269. char **argv;
  270. {
  271.    register USHORT i;
  272.    SHORT nx, ny;           /* new x, y coordinates to ClipBlit() to */
  273.    SHORT x_line;           /* number of times to ClipBlit() across display */
  274.    SHORT y_line;           /* number of times to ClipBlit() down display */
  275.  
  276.  
  277.    if (!(fp = Open("CON:100/50/300/50/Hello, world.", MODE_OLDFILE)))
  278.       Exit(IoErr());
  279.  
  280.    if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", VERSION)))
  281.    {
  282.       print("Must run under AmigaDOS 1.2\n");
  283.       Delay(150);
  284.       Close(fp);
  285.       Exit(0);
  286.    }
  287.  
  288.    IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", VERSION);
  289.    if (!IntuitionBase)
  290.    {
  291.       print("How did the graphics library get opened?\n");
  292.       Delay(150);
  293.       Close(fp);
  294.       Exit(0);
  295.    }
  296.  
  297.    oldview = GfxBase->ActiView;     /* save that view */
  298.  
  299. /* set up some important structs */
  300.    InitView(&v);
  301.    InitVPort(&vp);
  302.    v.ViewPort = &vp;
  303.    InitBitMap(&b, DEPTH, WIDTH, HEIGHT);
  304.  
  305. /* set up the rastport */
  306.    InitRastPort(&my_rast);
  307.    my_rast.BitMap = (struct BitMap *)&b;
  308.    rp = (struct RastPort *)&my_rast;
  309.  
  310. /* set up rasinfo stuff */
  311.    ri.BitMap = &b;
  312.    ri.RxOffset = 0;
  313.    ri.RyOffset = 0;
  314.    ri.Next = NULL;
  315.  
  316. /* set up view port stuff */
  317.    vp.DWidth = WIDTH;
  318.    vp.DHeight = HEIGHT;
  319.    vp.DxOffset = -16;      /* this is the max negative offset */
  320.    vp.DyOffset = -16;      /* ditto */
  321.    vp.RasInfo = &ri;
  322.  
  323. /* make room for MY colors */
  324.    cm = GetColorMap(4);
  325.    colorpalette = (UWORD *)cm->ColorTable;
  326.    for (i = 0; i < 4; i++)
  327.       *colorpalette++ = colortable[i];
  328.  
  329.    vp.ColorMap = cm;    /* tell view port about them */
  330.  
  331. /* make room for the bit map */
  332.    for (i = 0; i < DEPTH; i++)
  333.    {
  334.       b.Planes[i] = AllocRaster(WIDTH, HEIGHT);
  335.       if (b.Planes[i] == NULL)
  336.         Exit(1);
  337.    }
  338.  
  339.    x_line = (WIDTH / IW) - 1;  /* num times to stamp image across display */
  340.    y_line = (HEIGHT / IH) - 1; /* number of times to ClipBlit() down display */
  341.  
  342.    SetRast(rp, 0);             /* paint it black (the rast port) */
  343.    DrawImage(rp, &si, 0, 0);   /* draw image in the upper left hand corner */
  344.  
  345. /* copy that image across the top of the display */
  346.    for (i = 0, nx = IW; i < x_line; i++, nx += IW)
  347.       ClipBlit(rp, 0, 0, rp, nx, 0, IW, IH, 0xc0);  /* 0xc0 = as is */
  348.  
  349. /* now copy the top line down the rest of the display  */
  350.    for (i = 0, ny = IH; i < y_line; i++, ny += IH)
  351.       ClipBlit(rp, 0, 0, rp, 0, ny, WIDTH, IH, 0xc0);
  352.  
  353. /* make sure every thing is in its proper place */
  354.    MakeVPort(&v, &vp);
  355.    MrgCop(&v);
  356.    LoadView(&v);        /* ta da! */
  357.  
  358. /* tap our toes until someone hits return */
  359.  
  360.    while (!(WaitForChar(fp, 500000)))  /* 500000 = 1/2 sec */
  361.       print("Press <RETURN> to exit.\n");
  362.  
  363.    Close(fp);
  364.  
  365.    LoadView(oldview);        /* return to the old display */
  366.  
  367.    FreeMemory();
  368.    CloseLibrary(GfxBase);
  369.    CloseLibrary(IntuitionBase);
  370. }
  371.  
  372.  
  373. FreeMemory()
  374. {
  375.    USHORT i;
  376.  
  377.    for (i = 0; i < DEPTH; i++)
  378.       FreeRaster(b.Planes[i], WIDTH, HEIGHT);
  379.  
  380.    FreeColorMap(cm);
  381.    FreeVPortCopLists(&vp);
  382.    FreeCprList(v.LOFCprList);
  383.    return(0);
  384. }
  385.  
  386.  
  387. strlen(s)   /* from K&R */
  388. char *s;
  389. {
  390.    char *p = s;
  391.  
  392.    while(*p)
  393.       p++;
  394.    return(p-s);
  395. }
  396.  
  397.  
  398. print(str)
  399. char *str;
  400. {
  401.    Write(fp, str, strlen(str));
  402. }
  403.  
  404.