home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / new / dev / c / hce / examples / amiga / darkdemo / dark.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  13KB  |  537 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *                   !! This IS a Nasty Copper Hack!!                      *
  4. *                                                                         *
  5. *  By stealing other peoples code and nutting out the AMIGA Manuals       *
  6. *  I have put something of little value together.                         *
  7. *                                                                         *
  8. *  Oh well, next time those sprites might bite.                           *
  9. *                                                                         *
  10. *  Phil Robertson. At the end of '87                                      *
  11. *                                                                         *
  12. ***************************************************************************
  13. *                                                                         *
  14. * 1994 - Minor changes made by Jason Petty to work with HCE.              *
  15. *        Now uses the left mouse button to stop the demo.                 *
  16. *        Changes marked, VANSOFT.                                         *
  17. *                                                                         *
  18. *        NOTE: When linking the object files to make 'Dark' an            *
  19. *              undefined symbol (custom) message is displayed in          *
  20. *              the CLI by the linker. This is because the external        *
  21. *              reference to 'custom' is not present in the Amiga          *
  22. *              library and is not resolved until runtime.                 *
  23. *              This is normal!.                                           *
  24. *        ALSO NOTE:                                                       *
  25. *              This demo was originally made for an older version of the  *
  26. *              Amiga's operating system (1.2-1.3) and may not work        *
  27. *              correctly on newer versions.                               *
  28. *                                                                         *
  29. **************************************************************************/
  30.  
  31. /* Added  '#include's. VANSOFT. */
  32. #include <intuition/intuition.h>
  33. #include <exec/memory.h>
  34. #include <graphics/sprite.h>
  35. #include <graphics/copper.h>
  36. #include <graphics/gfx.h>
  37. #include <graphics/gfxmacros.h>
  38. #include <graphics/gfxbase.h>
  39. #include <hardware/custom.h>
  40. #include <hardware/cia.h>
  41. #include <proto/all.h>
  42. #include <stdio.h>
  43.  
  44. #define AllocChip(size) AllocMem((ULONG)size,(ULONG)(MEMF_CHIP|MEMF_CLEAR))
  45. #define REV        0L
  46. #define DEPTH      3
  47. #define DEPTH2     3
  48. #define WIDTH      640L
  49. #define HEIGHT     400L
  50. #define DWIDTH     320
  51. #define DHEIGHT    200
  52. #define MODES      SPRITES | DUALPF
  53. #define ever       (;;)
  54. #define MTCU       0x00CCL
  55. #define joy        custom.joy1dat
  56.  
  57. UWORD Palette[16] = {
  58.    0x0000,
  59.    0x0444,
  60.    0x0777,
  61.    0x0BBB,
  62.    0x0D26,
  63.    0x0960,
  64.    0x0750,
  65.    0x0650,
  66.    0x0000,
  67.    0x0DA0,
  68.    0x0FC0,
  69.    0x0DA0,
  70.    0x0B90,
  71.    0x0B90,
  72.    0x0DA0,
  73.    0x0FC0
  74. };
  75.  
  76.  
  77. #define COLOURCOUNT 16L
  78.  
  79. /* Added 'custom' and 'ciaa'. VANSOFT. */
  80. extern struct Custom far custom;
  81. struct CIA *ciaa = (struct CIA *) CIAAPRA;
  82.  
  83. extern UWORD HeyData[];
  84. extern UWORD WowData[];
  85. extern UWORD DoorDownData[];
  86. extern UWORD DoorUpData[];
  87. extern UWORD GateData[];
  88. extern UWORD AWData[];
  89. extern UWORD ship_col[];
  90. extern UWORD ship1_dat[];
  91. extern UWORD ship2_dat[];
  92. extern UWORD ship3_dat[];
  93. extern UWORD ship4_dat[];
  94. extern WORD   sound[];
  95.  
  96. struct SimpleSprite Sprites[5];
  97.  
  98. /* Added 'chip'. VANSOFT. */
  99. chip struct Image AW = {
  100.    0,0,
  101.    243,53,
  102.    3,
  103.    AWData,
  104.    0x0007,0x0000,
  105.    NULL
  106. };
  107.  
  108. struct Image Gate = {
  109.    0,0,
  110.    79,187,
  111.    3,
  112.    GateData,
  113.    0x0003,0x0000,
  114.    NULL
  115. };
  116.  
  117. struct Image DoorDown = {
  118.    0,0,
  119.    26,34,
  120.    3,
  121.    DoorDownData,
  122.    0x0007,0x0000,
  123.    NULL
  124. };
  125.  
  126. struct Image DoorUp = {
  127.    0,0,
  128.    26,34,
  129.    3,
  130.    DoorUpData,
  131.    0x0007,0x0000,
  132.    NULL
  133. };
  134.  
  135. /* Changed IntuitionBase to long. VANSOFT. */
  136. long IntuitionBase=NULL;
  137. struct GfxBase *GfxBase=NULL;
  138.  
  139. /* Added. VANSOFT. */
  140. BOOL JoyStick();
  141.  
  142. struct UCopList   *cl;
  143. struct View   v,  *oldview;
  144. struct ViewPort    vp;
  145. struct ColorMap   *cm;
  146. struct RasInfo     ri,ri2;
  147. struct BitMap     *bm[2]={NULL,NULL};
  148. struct RastPort    rp, rp2;
  149.  
  150. WORD Wrp = 0;
  151. long  WX = 370; HX = 420;
  152. WORD X = 2,Y = 2;
  153. long Frq = 700;
  154. long DY1 = 22, DY2 = 141, DY3 = 22, DY4 = 141;
  155. BOOL SFlag = FALSE;
  156.  
  157.  
  158. main()
  159.  
  160. {
  161.    openstuff ();
  162.    makescreen ();
  163.    DrawObjects();
  164.    SetSprites();
  165.    SetColour();
  166.    SoundOn();
  167.    for ever {
  168.       MoveSprites();
  169.       ShipSprite();
  170.       MakeVPort (&v, &vp);
  171.       MrgCop(&v);
  172.       LoadView (&v);
  173.       if (JoyStick()) {
  174.           break;
  175.           }
  176.    }
  177. bye:
  178.    closeeverything ();
  179. }
  180.  
  181.  
  182. openstuff ()
  183. {
  184.    long err;
  185.  
  186.    if (!(IntuitionBase = (long)OpenLibrary("intuition.library",REV)))
  187.       die ("What the F...???!!!\n");
  188.  
  189.    if (!(GfxBase = (struct GfxBase *)OpenLibrary ("graphics.library", REV)))
  190.       die ("Art shop closed.\n");
  191.  
  192.    if (!(bm[0] = AllocChip(sizeof(struct BitMap))))
  193.       die ("Can't allocate BitMap 0.\n");
  194.  
  195.    if (!(bm[1] = AllocChip(sizeof(struct BitMap))))
  196.       die ("Can't allocate BitMap 1.\n");
  197. }
  198.  
  199. makescreen ()
  200. {
  201.    register int i;
  202.  
  203.    InitView (&v);
  204.    InitVPort (&vp);
  205.    InitBitMap (bm[0], (long) DEPTH, WIDTH, HEIGHT);
  206.    InitBitMap (bm[1], (long) DEPTH2, WIDTH, HEIGHT);
  207.    InitRastPort (&rp);
  208.    InitRastPort (&rp2);
  209.  
  210.    v.ViewPort = &vp;
  211.  
  212.    ri.BitMap = bm[0];    ri2.BitMap = bm[1];
  213.    ri.RxOffset = 0;      ri.RyOffset = 0; ri.Next = &ri2;
  214.    ri2.RxOffset = 0;     ri2.RyOffset = 0; ri2.Next = NULL;
  215.    rp.BitMap = bm[0];    rp2.BitMap = bm[1];
  216.  
  217.    for (i=0; i<DEPTH; i++)   /* Added PLANEPTR. VANSOFT */
  218.       if (!(bm[0]->Planes[i] = (PLANEPTR)AllocRaster (WIDTH, HEIGHT)))
  219.          die ("Can't allocate memory for plane (bm 0).\n");
  220.  
  221.    for (i=0; i<DEPTH2; i++)  /* Added PLANEPTR. VANSOFT */
  222.       if (!(bm[1]->Planes[i] = (PLANEPTR)AllocRaster (WIDTH, HEIGHT)))
  223.          die ("Can't allocate memory for plane (bm 1).\n");
  224.  
  225.    oldview = GfxBase->ActiView;
  226.    vp.DWidth = DWIDTH;
  227.    vp.DHeight = DHEIGHT;
  228.    vp.RasInfo = &ri;
  229.    vp.ColorMap = GetColorMap(COLOURCOUNT);
  230.    vp.Modes = MODES;
  231. }
  232.  
  233. closeeverything ()
  234. {
  235.    register int i;
  236.  
  237.    SoundOff();
  238.    FreeSprite(2L);
  239.    FreeSprite(3L);
  240.    FreeSprite(4L);
  241.  
  242.    if (oldview) {
  243.       LoadView (oldview);
  244.       WaitTOF ();
  245.       FreeVPortCopLists (&vp);
  246.       FreeCprList (v.LOFCprList);
  247.    }
  248.  
  249.    if (vp.ColorMap)
  250.       FreeColorMap (vp.ColorMap);
  251.  
  252.    for (i=0; i<DEPTH; i++)
  253.       if ((bm[0]->Planes[i]) != NULL)
  254.          FreeRaster(bm[0]->Planes[i],WIDTH,HEIGHT);
  255.  
  256.    for (i=0; i<DEPTH2; i++)
  257.       if ((bm[1]->Planes[i]) != NULL)
  258.          FreeRaster(bm[1]->Planes[i],WIDTH,HEIGHT);
  259.  
  260.    if (GfxBase) CloseLibrary (GfxBase);
  261.    if (IntuitionBase) CloseLibrary (IntuitionBase);
  262. }
  263.  
  264. die (str)
  265. char *str;
  266. {
  267.    puts (str);
  268.    closeeverything ();
  269.    exit (100);
  270. }
  271.  
  272. DrawObjects()
  273. {
  274.    SetRast (&rp2, 0L);
  275.    SetRast (&rp, 0L);
  276.  
  277.    DrawImage(&rp, &Gate, 1L, 5L);
  278.    DrawImage(&rp, &Gate, 240L, 5L);
  279.    DrawImage(&rp, &Gate, 500L, 5L);
  280.  
  281.    DrawImage(&rp2, &AW, 45L, 147L);
  282.    DrawImage(&rp, &DoorDown, 400L, 42L);
  283.    DrawImage(&rp, &DoorUp, 430L, 141L);
  284. }
  285.  
  286. short getbit(num,bit)    /* extract a bit */
  287.   short num,bit;
  288. { return (num>>bit & 1); }
  289.  
  290.  
  291. BOOL JoyStick() /* Changed, now checks gameport 0 for left mouse button. */
  292. {               /* VANSOFT. */
  293.    short button,up,down,left,right;
  294.  
  295.                            /* Added CIAB_GAMEPORT0, VANSOFT. */
  296.  button = !getbit((UWORD)ciaa->ciapra,CIAB_GAMEPORT0);  /* 0 for closed */
  297.  up = getbit(joy,8) ^ getbit(joy,9);                    /* xor of bits 8,9 */
  298.  down = getbit(joy,0) ^ getbit(joy,1);                  /* xor of bits 0,1*/
  299.  left = getbit(joy,9);
  300.  right = getbit(joy,1);
  301.  return(button);
  302. }
  303.  
  304. SetSprites()
  305.  
  306. {
  307.    short sgot;
  308.    register int i;
  309.  
  310.    if (sgot = GetSprite(&Sprites[0],2L)==0) die("Sprites Failed\n");
  311.    Sprites[0].x=30;
  312.    Sprites[0].y=92;
  313.    Sprites[0].height = 16;
  314.    if (sgot = GetSprite(&Sprites[1],3L)==0) die("Sprites Failed\n");
  315.    Sprites[1].x=270;
  316.    Sprites[1].y=92;
  317.    Sprites[1].height = 16;
  318.  
  319.    if (sgot = GetSprite(&Sprites[2],4L)==