home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 6
/
FreshFish_September1994.bin
/
new
/
dev
/
c
/
hce
/
examples
/
amiga
/
darkdemo
/
dark.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-02
|
13KB
|
537 lines
/**************************************************************************
* *
* !! This IS a Nasty Copper Hack!! *
* *
* By stealing other peoples code and nutting out the AMIGA Manuals *
* I have put something of little value together. *
* *
* Oh well, next time those sprites might bite. *
* *
* Phil Robertson. At the end of '87 *
* *
***************************************************************************
* *
* 1994 - Minor changes made by Jason Petty to work with HCE. *
* Now uses the left mouse button to stop the demo. *
* Changes marked, VANSOFT. *
* *
* NOTE: When linking the object files to make 'Dark' an *
* undefined symbol (custom) message is displayed in *
* the CLI by the linker. This is because the external *
* reference to 'custom' is not present in the Amiga *
* library and is not resolved until runtime. *
* This is normal!. *
* ALSO NOTE: *
* This demo was originally made for an older version of the *
* Amiga's operating system (1.2-1.3) and may not work *
* correctly on newer versions. *
* *
**************************************************************************/
/* Added '#include's. VANSOFT. */
#include <intuition/intuition.h>
#include <exec/memory.h>
#include <graphics/sprite.h>
#include <graphics/copper.h>
#include <graphics/gfx.h>
#include <graphics/gfxmacros.h>
#include <graphics/gfxbase.h>
#include <hardware/custom.h>
#include <hardware/cia.h>
#include <proto/all.h>
#include <stdio.h>
#define AllocChip(size) AllocMem((ULONG)size,(ULONG)(MEMF_CHIP|MEMF_CLEAR))
#define REV 0L
#define DEPTH 3
#define DEPTH2 3
#define WIDTH 640L
#define HEIGHT 400L
#define DWIDTH 320
#define DHEIGHT 200
#define MODES SPRITES | DUALPF
#define ever (;;)
#define MTCU 0x00CCL
#define joy custom.joy1dat
UWORD Palette[16] = {
0x0000,
0x0444,
0x0777,
0x0BBB,
0x0D26,
0x0960,
0x0750,
0x0650,
0x0000,
0x0DA0,
0x0FC0,
0x0DA0,
0x0B90,
0x0B90,
0x0DA0,
0x0FC0
};
#define COLOURCOUNT 16L
/* Added 'custom' and 'ciaa'. VANSOFT. */
extern struct Custom far custom;
struct CIA *ciaa = (struct CIA *) CIAAPRA;
extern UWORD HeyData[];
extern UWORD WowData[];
extern UWORD DoorDownData[];
extern UWORD DoorUpData[];
extern UWORD GateData[];
extern UWORD AWData[];
extern UWORD ship_col[];
extern UWORD ship1_dat[];
extern UWORD ship2_dat[];
extern UWORD ship3_dat[];
extern UWORD ship4_dat[];
extern WORD sound[];
struct SimpleSprite Sprites[5];
/* Added 'chip'. VANSOFT. */
chip struct Image AW = {
0,0,
243,53,
3,
AWData,
0x0007,0x0000,
NULL
};
struct Image Gate = {
0,0,
79,187,
3,
GateData,
0x0003,0x0000,
NULL
};
struct Image DoorDown = {
0,0,
26,34,
3,
DoorDownData,
0x0007,0x0000,
NULL
};
struct Image DoorUp = {
0,0,
26,34,
3,
DoorUpData,
0x0007,0x0000,
NULL
};
/* Changed IntuitionBase to long. VANSOFT. */
long IntuitionBase=NULL;
struct GfxBase *GfxBase=NULL;
/* Added. VANSOFT. */
BOOL JoyStick();
struct UCopList *cl;
struct View v, *oldview;
struct ViewPort vp;
struct ColorMap *cm;
struct RasInfo ri,ri2;
struct BitMap *bm[2]={NULL,NULL};
struct RastPort rp, rp2;
WORD Wrp = 0;
long WX = 370; HX = 420;
WORD X = 2,Y = 2;
long Frq = 700;
long DY1 = 22, DY2 = 141, DY3 = 22, DY4 = 141;
BOOL SFlag = FALSE;
main()
{
openstuff ();
makescreen ();
DrawObjects();
SetSprites();
SetColour();
SoundOn();
for ever {
MoveSprites();
ShipSprite();
MakeVPort (&v, &vp);
MrgCop(&v);
LoadView (&v);
if (JoyStick()) {
break;
}
}
bye:
closeeverything ();
}
openstuff ()
{
long err;
if (!(IntuitionBase = (long)OpenLibrary("intuition.library",REV)))
die ("What the F...???!!!\n");
if (!(GfxBase = (struct GfxBase *)OpenLibrary ("graphics.library", REV)))
die ("Art shop closed.\n");
if (!(bm[0] = AllocChip(sizeof(struct BitMap))))
die ("Can't allocate BitMap 0.\n");
if (!(bm[1] = AllocChip(sizeof(struct BitMap))))
die ("Can't allocate BitMap 1.\n");
}
makescreen ()
{
register int i;
InitView (&v);
InitVPort (&vp);
InitBitMap (bm[0], (long) DEPTH, WIDTH, HEIGHT);
InitBitMap (bm[1], (long) DEPTH2, WIDTH, HEIGHT);
InitRastPort (&rp);
InitRastPort (&rp2);
v.ViewPort = &vp;
ri.BitMap = bm[0]; ri2.BitMap = bm[1];
ri.RxOffset = 0; ri.RyOffset = 0; ri.Next = &ri2;
ri2.RxOffset = 0; ri2.RyOffset = 0; ri2.Next = NULL;
rp.BitMap = bm[0]; rp2.BitMap = bm[1];
for (i=0; i<DEPTH; i++) /* Added PLANEPTR. VANSOFT */
if (!(bm[0]->Planes[i] = (PLANEPTR)AllocRaster (WIDTH, HEIGHT)))
die ("Can't allocate memory for plane (bm 0).\n");
for (i=0; i<DEPTH2; i++) /* Added PLANEPTR. VANSOFT */
if (!(bm[1]->Planes[i] = (PLANEPTR)AllocRaster (WIDTH, HEIGHT)))
die ("Can't allocate memory for plane (bm 1).\n");
oldview = GfxBase->ActiView;
vp.DWidth = DWIDTH;
vp.DHeight = DHEIGHT;
vp.RasInfo = &ri;
vp.ColorMap = GetColorMap(COLOURCOUNT);
vp.Modes = MODES;
}
closeeverything ()
{
register int i;
SoundOff();
FreeSprite(2L);
FreeSprite(3L);
FreeSprite(4L);
if (oldview) {
LoadView (oldview);
WaitTOF ();
FreeVPortCopLists (&vp);
FreeCprList (v.LOFCprList);
}
if (vp.ColorMap)
FreeColorMap (vp.ColorMap);
for (i=0; i<DEPTH; i++)
if ((bm[0]->Planes[i]) != NULL)
FreeRaster(bm[0]->Planes[i],WIDTH,HEIGHT);
for (i=0; i<DEPTH2; i++)
if ((bm[1]->Planes[i]) != NULL)
FreeRaster(bm[1]->Planes[i],WIDTH,HEIGHT);
if (GfxBase) CloseLibrary (GfxBase);
if (IntuitionBase) CloseLibrary (IntuitionBase);
}
die (str)
char *str;
{
puts (str);
closeeverything ();
exit (100);
}
DrawObjects()
{
SetRast (&rp2, 0L);
SetRast (&rp, 0L);
DrawImage(&rp, &Gate, 1L, 5L);
DrawImage(&rp, &Gate, 240L, 5L);
DrawImage(&rp, &Gate, 500L, 5L);
DrawImage(&rp2, &AW, 45L, 147L);
DrawImage(&rp, &DoorDown, 400L, 42L);
DrawImage(&rp, &DoorUp, 430L, 141L);
}
short getbit(num,bit) /* extract a bit */
short num,bit;
{ return (num>>bit & 1); }
BOOL JoyStick() /* Changed, now checks gameport 0 for left mouse button. */
{ /* VANSOFT. */
short button,up,down,left,right;
/* Added CIAB_GAMEPORT0, VANSOFT. */
button = !getbit((UWORD)ciaa->ciapra,CIAB_GAMEPORT0); /* 0 for closed */
up = getbit(joy,8) ^ getbit(joy,9); /* xor of bits 8,9 */
down = getbit(joy,0) ^ getbit(joy,1); /* xor of bits 0,1*/
left = getbit(joy,9);
right = getbit(joy,1);
return(button);
}
SetSprites()
{
short sgot;
register int i;
if (sgot = GetSprite(&Sprites[0],2L)==0) die("Sprites Failed\n");
Sprites[0].x=30;
Sprites[0].y=92;
Sprites[0].height = 16;
if (sgot = GetSprite(&Sprites[1],3L)==0) die("Sprites Failed\n");
Sprites[1].x=270;
Sprites[1].y=92;
Sprites[1].height = 16;
if (sgot = GetSprite(&Sprites[2],4L)==