#include <exec/types.h>             /* Include-Files laden */
#include <exec/tasks.h>
#include <exec/libraries.h>
#include <exec/devices.h>
#include <devices/keymap.h>
#include <graphics/copper.h>
#include <graphics/display.h>
#include <graphics/gfxbase.h>
#include <graphics/text.h>
#include <graphics/view.h>
#include <graphics/gels.h>
#include <graphics/regions.h>
#include <graphics/sprite.h>
#include <hardware/blit.h>
#include <libraries/dos.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <exec/execbase.h>
#include <exec/memory.h>
#include <libraries/diskfont.h>

UWORD Data1[6][36] = {
                 {0,0,
                 0x0100,0x0000,0x0200,0x0180,0x0000,0x0380,0x0380,0x0180,
                 0x0380,0x0380,0x0100,0x0100,0x0100,0x0080,0x0300,0x00C0,
                 0x0200,0x01C0,0x0400,0x07C0,0x03C0,0x0040,0x0380,0x0000,
                 0x0500,0x0280,0x0480,0x0240,0x0440,0x0200,0x0C80,0x0000,
                 0,0,},
                 {0,0,
                 0x0100,0x0000,0x0200,0x0180,0x0000,0x0380,0x0380,0x0180,
                 0x0380,0x0380,0x0100,0x0100,0x0100,0x0080,0x0200,0x01C0,
                 0x0080,0x0340,0x0080,0x0340,0x0380,0x0100,0x0380,0x0000,
                 0x0380,0x0040,0x02E0,0x0000,0x0220,0x0000,0x0400,0x0200,
                 0,0,},
                 {0,0,
                 0x0100,0x0000,0x0200,0x0180,0x0000,0x0380,0x0380,0x0180,
                 0x0380,0x0380,0x0100,0x0100,0x0100,0x0080,0x0200,0x01C0,
                 0x0080,0x0340,0x0100,0x02C0,0x0600,0x0580,0x0380,0x0000,
                 0x0480,0x0300,0x0280,0x0140,0x00C0,0x0000,0x0100,0x0080,
                 0,0,},
                 {0,0,
                 0x0080,0x0000,0x0040,0x0180,0x0000,0x01C0,0x01C0,0x0180,
                 0x01C0,0x01C0,0x0080,0x0080,0x0080,0x0100,0x00C0,0x0300,
                 0x0040,0x0380,0x0020,0x03E0,0x03C0,0x0200,0x01C0,0x0000,
                 0x00A0,0x0140,0x0120,0x0240,0x0220,0x0040,0x0130,0x0000,
                 0,0,},
                 {0,0,
                 0x0080,0x0000,0x0040,0x0180,0x0000,0x01C0,0x01C0,0x0180,
                 0x01C0,0x01C0,0x0080,0x0080,0x0080,0x0100,0x0040,0x0380,
                 0x0100,0x02C0,0x0100,0x02C0,0x01C0,0x0080,0x01C0,0x0000,
                 0x01C0,0x0200,0x0740,0x0000,0x0440,0x0000,0x0020,0x0040,
                 0,0,},
                 {0,0,
                 0x0080,0x0000,0x0040,0x0180,0x0000,0x01C0,0x01C0,0x0180,
                 0x01C0,0x01C0,0x0080,0x0080,0x0080,0x0100,0x0040,0x0380,
                 0x0100,0x02C0,0x0080,0x0340,0x0060,0x01A0,0x01C0,0x0000,
                 0x0120,0x00C0,0x0140,0x0280,0x0300,0x0000,0x0080,0x0100,
                 0,0,},
                 };

UWORD Tod[] = {
                0,0,
                 0x07C0,0x0780,0x1FF0,0x1FB0,0x3FF8,0x3DF8,0x739C,0x739C,
                 0x610C,0x210C,0x610C,0x610C,0x711C,0x7114,0x3FF8,0x3FF8,
                 0x3EF8,0x2EF8,0x1C70,0x1C50,0x1C70,0x1470,0x0FE0,0x0FE0,
                 0x0C60,0x0C60,0x0820,0x0820,0x07C0,0x06C0,0x0380,0x0380,
                0,0
                };

UWORD Ghost[4][36] = {
                 {0,0,
                 0x03F0,0x0000,0x07E0,0x0000,0x0FF0,0x0240,0x0FE0,0x0010,
                 0x07C0,0x01A0,0x0380,0x0040,0x0380,0x0040,0x07C0,0x0020,
                 0x0FE0,0x0010,0x1F80,0x0070,0x1F00,0x00E0,0x0E00,0x01C0,
                 0x0700,0x00C0,0x0380,0x0040,0x01C0,0x0020,0x0070,0x0000,
                 0,0,},
                 {0,0,
                 0x01E0,0x0000,0x03F0,0x0000,0x06D8,0x0120,0x07F0,0x0008,
                 0x03E0,0x00D0,0x01C0,0x0020,0x03F0,0x0000,0x07F0,0x0008,
                 0x0FE0,0x0018,0x0FC0,0x0038,0x0F80,0x0070,0x0780,0x0060,
                 0x0380,0x0040,0x0180,0x0040,0x0180,0x0040,0x0080,0x0000,
                 0,0,},
                 {0,0,
                 0x03F0,0x0000,0x01F8,0x0000,0x03FC,0x0090,0x03F8,0x0004,
                 0x01F0,0x0068,0x00E0,0x0010,0x01F8,0x0000,0x03F8,0x0004,
                 0x07F8,0x0004,0x07F0,0x000C,0x07E0,0x0018,0x03C0,0x0030,
                 0x01C0,0x0030,0x0380,0x0060,0x0600,0x0180,0x0C00,0x0200,
                 0,0,},
                 {0,0,
                 0x01E0,0x0000,0x03F0,0x0000,0x07F8,0x0120,0x07F0,0x0008,
                 0x0320,0x00D0,0x01C0,0x0020,0x03F0,0x0000,0x07F0,0x0008,
                 0x0FE0,0x0018,0x0FC0,0x0038,0x0F80,0x0070,0x0780,0x0060,
                 0x0380,0x0040,0x0180,0x0040,0x0180,0x0040,0x0080,0x0000,
                 0,0,},
                 };

UWORD Vogel[4][36] = {
                 {0,0,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x4002,0x0000,
                 0x2004,0x0000,0x381C,0x0000,0x1E78,0x0000,0x07E0,0x0990,
                 0x0180,0x0660,0x0180,0x0000,0x0240,0x0000,0x0000,0x0000,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0,0,},
                 {0,0,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0x0000,0x0000,0xFC3F,0x0000,0x1FF8,0x0180,0x0180,0x0E70,
                 0x0180,0x0000,0x0240,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0,0,},
                 {0,0,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0x0000,0x0000,0x0DB8,0x0180,0x3FFC,0x0000,0x718E,0x0E70,
                 0x8241,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0,0,},
                 {0,0,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0x0000,0x0000,0xFC3F,0x0000,0x0FF8,0x0180,0x0180,0x0670,
                 0x0180,0x0000,0x0240,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                 0,0,},
                 };

struct SimpleSprite sprite1 =
	{
	&Data1[0][0],16,100,100,1
	};	

struct SimpleSprite sprite2 =
	{
	&Ghost[0][0],16,100,100,2
	};

struct SimpleSprite sprite3 =
	{
	&Vogel[0][0],16,100,100,4
	};

struct NewScreen et =
	{
	0,0,320,200,5,0,1,NULL|SPRITES,CUSTOMSCREEN,NULL,"TEST",NULL,NULL
	};

struct IntuitionBase *IntuitionBase;
struct GfxBase       *GfxBase;
struct Screen        *screen;
struct BitMap        *ptr;
struct RastPort      *rp;
struct ViewPort      *vp;
struct TextFont      *textfont;
struct TextAttr      textattr;
 
int scranz=30;        
int joyx,joyy,joyf;
int ghostf=0;
int ghostwait=0;
int vx=100,vy=35;
int vf=1;
UWORD mancol;
ULONG timecnt=0;
ULONG codemem;
UWORD codelen;
ULONG screenmem;
UWORD screenlen;
ULONG rgbmem;
UWORD rgblen;
ULONG hilfsmem;
ULONG picmem;
ULONG file;
ULONG DosBase;
UBYTE level=0;
ULONG rgbquelle;
UBYTE rot,gruen,blau;
ULONG drei,land,scoff,posn,codn;
ULONG splane0,splane1,splane2,splane3,splane4;
ULONG dplane0,dplane1,dplane2,dplane3,dplane4;
BYTE leben=5;
UBYTE sammel=10;
int score=0;
UWORD hutcode,fuscode;
WORD startsx=20,startsy=120;
WORD sx,sy;
WORD gx=-20,gy=-20;
ULONG dummy;
ULONG DiskfontBase;
ULONG colpoke;
char *LeftMouse=(char *)0xbfe001;
int real;
int real1;
int real2;
char canimz=0;
WORD ghostcnt=0;
char animpic=0;
char todflag=0;
APTR soundadr;
UWORD soundlen;

main()
{
int i,j,k,l,m,n;
int col1,col2,col3,col4;
char hoch=35;
char hzahler=0;
char rzahler=0;
char ahoch=0;
char speed=0;
char sflag=0;
char animcnt=7,animend=7;
char fus1=5;
char fus2=10;

IntuitionBase = (struct IntuitionBase *)
  	OpenLibrary("intuition.library",0);
if(IntuitionBase == NULL) exit(FALSE);

GfxBase = (struct GfxBase *)
  	OpenLibrary("graphics.library",0);
if(GfxBase == NULL) exit(FALSE);

if ((DosBase =
        OpenLibrary("dos.library",0)) == 0) exit();

if((screen=(struct Screen*)
  	OpenScreen(&et)) == NULL) goto myend;

rp=&screen->RastPort;
vp=&screen->ViewPort;
ptr=rp->BitMap;
SetRGB4(vp,0,0,0,0);
SetRGB4(vp,1,0,0,0);
SetRGB4(vp,2,0,0,0);
SetRGB4(vp,10,0,0,0);
Move(rp,120,100);
SetAPen(rp,10);
dummy=Text(rp,"Loading...",10);
for (i=0;i<16;++i)
    for (j=0;j<80;++j)
        SetRGB4(vp,10,i,i,i);

if ((DiskfontBase =
        OpenLibrary("diskfont.library",0)) == 0) exit();
textattr.ta_Name ="game.font";
textattr.ta_YSize=8;
textattr.ta_Style=0;
textattr.ta_Flags=0;
textfont=(struct TextFont *)OpenDiskFont(&textattr);
if (textfont!=0)
   SetFont(rp,textfont);

dplane0 = ptr->Planes[0];
dplane1 = ptr->Planes[1];
dplane2 = ptr->Planes[2];
dplane3 = ptr->Planes[3];
dplane4 = ptr->Planes[4];

codemem=(ULONG)AllocMem(40000,MEMF_CHIP|MEMF_CLEAR);
if (!codemem) goto myend;
screenmem=(ULONG)AllocMem(scranz*1920,MEMF_CHIP|MEMF_CLEAR);
if (!screenmem) goto myend;
rgbmem=(ULONG)AllocMem(scranz*96,MEMF_CHIP|MEMF_CLEAR);
if (!rgbmem) goto myend;
hilfsmem=(ULONG)AllocMem(1920,MEMF_CHIP|MEMF_CLEAR);
if (!hilfsmem) goto myend;

file=Open("demoa",MODE_OLDFILE);
codelen=(UWORD)Read(file,codemem,40000);
Close(file);
if (!codelen) goto myend;
 
file=Open("democ",MODE_OLDFILE);
screenlen=(UWORD)Read(file,screenmem,scranz*1920);
Close(file);
if (!screenlen) goto myend;

file=Open("demob",MODE_OLDFILE);
rgblen=(UWORD)Read(file,rgbmem,scranz*96);
Close(file);
if (!rgblen) goto myend;

picmem=(ULONG)AllocMem(5*8000,MEMF_CHIP|MEMF_CLEAR);
if (!picmem) goto myend;
file=Open("title",MODE_OLDFILE);
if (file==0) goto myend;
Read(file,picmem,5*8000);
Close(file);

soundadr=(APTR)AllocMem(63000,MEMF_CHIP|MEMF_CLEAR);
if (!soundadr) goto myend;
file=Open("sound",MODE_OLDFILE);
if (!file) goto myend;
soundlen=(UWORD)(Read(file,soundadr,100000)/2);
Close(file);

#asm 
      move.l _soundadr,$dff0a0
      move.w _soundlen,$dff0a4
      move.w #344,$dff0a6
      move.w #64,$dff0a8
      move.w #%1000001000000001,$dff096
#endasm

splane0=codemem;
splane1=codemem+1*8000;
splane2=codemem+2*8000;
splane3=codemem+3*8000;
splane4=codemem+4*8000;
land=screenmem;

titel:
for(i=0;i<16;++i)
	SetRGB4(vp,i,i,i,i);
titlepic();   
for(i=0;i<1;)
	{
	joy();
	if (joyf==1)
		i=1;
	}
SetRGB4(vp,1,0,0,0);
SetAPen(rp,0);
Move(rp,10,200);
RectFill(rp,0,192,319,199);
SetAPen(rp,1);
Text(rp,"Score:         Lives:     Level:",32);
String(55,200,score,6);
String(165,200,leben,1);
String(240,200,level,1);

start:
real = GetSprite(&sprite1,1);
real1 = GetSprite(&sprite2,2);
real2 = GetSprite(&sprite3,4);
dummy=screenmem+level*1920;
copymem();

sx=startsx,sy=startsy;
for(j=0;j<31;++j)
   	SetRGB4(vp,j,0,0,0);

scoff=1920*level;
makescreen(); 
for(j=0;j<31;++j)
   	{
   	rgbquelle=rgbmem+level*96+j*3;
   	rgbpeek();
   	SetRGB4(vp,j,rot,gruen,blau);
   	}
SetRGB4(vp,17,11,11,11);
SetRGB4(vp,18,8,8,8);
SetRGB4(vp,19,10,7,3);
SetRGB4(vp,21,15,15,15);
SetRGB4(vp,22,10,10,10);
SetRGB4(vp,23,14,0,0);
SetRGB4(vp,25,13,9,7);
SetRGB4(vp,26,6,11,7);
SetRGB4(vp,27,14,0,0);

for(i=0;i<1;)
    	{
    	if (sy>=-16)
        	{
       		col1=ReadPixel(rp,sx+fus1,sy+16);
    		col2=ReadPixel(rp,sx+fus2,sy+16);
    		col3=ReadPixel(rp,sx+fus1-1,sy+15);
    		col4=ReadPixel(rp,sx+fus2+1,sy+15);
        	} 
  
 	if ((col1<=15&&col2<=15)&&sflag==0)   /* fall */
      		++sy;
    	joy();

	++timecnt;
	if (timecnt==2000)
		ghostf=1;
	if (ghostf==1&&ghostwait==5)
		{
		if (sx>gx)
			++gx;
		if (sx<gx)
			--gx;
		if (sy>gy)
			++gy;
		if (sy<gy)
			--gy;
		}
	++ghostwait;
	if (ghostwait==6)
		ghostwait=0;
	if (sx==gx&&sy==gy)
		Tot();

    	if ((joyf==1&&(col1>=16||col2>=16))||sflag==1)   /* hupf */
      		{
      		sflag=1;
      		++hzahler;
      		--speed;
      		if (speed<1)
         		{
          		--sy;
          		speed=hzahler/10;
          		++ahoch;
          		}
      		if (ahoch>hoch)
          		{
          		hzahler=0;
          		sflag=0;
          		ahoch=0;
          		speed=0;
          		}
      		}

    	if (joyx!=0)            /* bewegen */
       		{
       		if (joyx==1&&col4>=16)
          		--sx;
       		if (joyx==-1&&col3>=16)
          		++sx;
       			++rzahler;
       		}
    	if (rzahler==2)
       		{
       		rzahler=0;
     		sx=sx+joyx;
       		--animcnt;
       		if (animcnt==0)
         		{
          		animcnt=animend;
          		if (joyx==-1)
           			ChangeSprite(vp,&sprite1,&Data1[animpic][0]);
          		if (joyx==1)
           			ChangeSprite(vp,&sprite1,&Data1[3+animpic][0]);
          		++animpic;
          		if (animpic==3)
             			animpic=0;
          		}         
       		}
	 zpeek();                     /* bonus */
	 if (hutcode==800)
		{
         	codn=0;
		mkcode();
		score=score+200;
		ghostf=0;
		timecnt=0;
		gx=-20;
		gy=-20;
		String(55,200,score,6);       
		}
	 if (hutcode>=960&&hutcode<=999)
		{
         	codn=0;
		mkcode();
		score=score+80;
		--sammel;
		String(55,200,score,6);       
		}
	 if (fuscode>=960&&fuscode<=999)
		{
         	codn=0;
		posn=posn+40;
		mkcode();
		score=score+80;
		--sammel;
		String(55,200,score,6);
		}
	 if (fuscode>=840&&fuscode<=959)      /* tot */
		Tot();

	collision();
	if (mancol==1)
		Tot();
	++canimz;
	if (canimz==20)
	{
		canimz=0;
		Colanim();
	}
	if (sammel==0)
		i=1;
	if ((*LeftMouse&0x40)!=0x40)
		goto myend;

	MoveSprite(vp,&sprite1,sx,sy);
	MoveSprite(vp,&sprite2,gx,gy);
	MoveSprite(vp,&sprite3,vx,vy);
	vx=vx+vf;
	if (vx==70||vx==235)
		vf=-vf;
    	++ghostcnt;
	if (ghostcnt==60)
		{
		ChangeSprite(vp,&sprite2,&Ghost[3][0]);
		ChangeSprite(vp,&sprite3,&Vogel[3][0]);
		ghostcnt=0;
		}
	if (ghostcnt==15)
		{
		ChangeSprite(vp,&sprite2,&Ghost[0][0]);
		ChangeSprite(vp,&sprite3,&Vogel[0][0]);
		}
	if (ghostcnt==30)	
		{
		ChangeSprite(vp,&sprite2,&Ghost[1][0]);
		ChangeSprite(vp,&sprite3,&Vogel[1][0]);
		}
	if (ghostcnt==45)
		{
		ChangeSprite(vp,&sprite2,&Ghost[2][0]);
		ChangeSprite(vp,&sprite3,&Vogel[2][0]);
		}
	if (todflag==1)
		{
		leben=5;
		todflag=0;
		i=1;
		}

	for(j=0;j<500;++j);           /*  Wait */
	}
SetAPen (rp,0);
if(real!=0)      FreeSprite(real);
if(real1!=0)     FreeSprite(real1);
if(real2!=0)     FreeSprite(real2);
for (j=0;j<96;j++)
	{
	RectFill (rp,0,j,320,j);
	RectFill (rp,0,191-j,320,191-j);
	for (k=0;k<800;++k);
	}
leben=5;
score=0;
gx=-20;
gy=-20;
ghostf=0;
timecnt=0;
SetAPen (rp,1);
sammel=10;
goto titel;

++level;
String(240,200,level,1);
goto start;

myend:
#asm 
	move.w #%0000000000000001,$dff096
#endasm

if(real!=0)      FreeSprite(real);
if(real1!=0)     FreeSprite(real1);
if(real2!=0)     FreeSprite(real2);
if(soundadr!=0)  FreeMem(soundadr,63000);
if(codemem!=0)   FreeMem(codemem,codelen);
if(picmem!=0)    FreeMem(picmem,5*8000);
if(screenmem!=0) FreeMem(screenmem,screenlen);
if(rgbmem!=0)    FreeMem(rgbmem,rgblen);
if(hilfsmem!=0)  FreeMem(hilfsmem,1920);
if(screen!=0)    CloseScreen(screen);
if(textfont!=0)  CloseFont(textfont);
CloseLibrary (DiskfontBase);
CloseLibrary (IntuitionBase);
CloseLibrary (GfxBase);
}

Tot()
{
int k,j;
--leben;
if (leben==-1)
	todflag=1;
ChangeSprite(vp,&sprite1,&Tod[0]);
for (j=sy;j>-16;--j)
	{
	MoveSprite(vp,&sprite1,sx,j);
	for(k=0;k<400;++k);
	}
ChangeSprite(vp,&sprite1,&Data1[animpic][0]);
ghostf=0;
collision();
timecnt=0;
gx=-20;
gy=-20;
sx=startsx;
sy=startsy;
String(165,200,leben,1);
}

String(xpos,ypos,number,len)
WORD xpos,ypos;
ULONG number;
BYTE len;
{
char s[6];
register BYTE i;
for (i=0;i<6;++i) s[i]='0';
i=len;
do {
	s[i]=(number%10)+48;
	number/=10;
   }
while(i--!=0);
Move(rp,xpos,ypos);
Text(rp,&s,len+1);
}

Colanim()
{
BYTE rdum,gdum,bdum;
rgbquelle=rgbmem+level*96+13*3;
colpoke=rgbquelle;
rgbpeek();
rdum=rot;
gdum=gruen;
bdum=blau;
rgbquelle=rgbmem+level*96+14*3;
rgbpeek();
rgbpoke();
colpoke=rgbquelle;
SetRGB4(vp,13,rot,gruen,blau);
rgbquelle=rgbmem+level*96+15*3;
rgbpeek();
rgbpoke();
colpoke=rgbquelle;
SetRGB4(vp,14,rot,gruen,blau);
SetRGB4(vp,15,rdum,gdum,bdum);
rot=rdum;
gruen=gdum;
blau=bdum;
rgbpoke();
}

titlepic()
{
#asm
        movem.l d0-d1/a0-a1,-(sp)
    	move.l _picmem,d1
	move.l d1,a0
    	move.l _dplane0,a1
	move.w #7999,d0
_tp1:   move.b (a0)+,(a1)+	
	dbf d0,_tp1
	add.l #8000,d1
    	move.l d1,a0
    	move.l _dplane1,a1
	move.w #7999,d0
_tp2:   move.b (a0)+,(a1)+	
	dbf d0,_tp2
	add.l #8000,d1
    	move.l d1,a0
    	move.l _dplane2,a1
	move.w #7999,d0
_tp3:   move.b (a0)+,(a1)+	
	dbf d0,_tp3
	add.l #8000,d1
    	move.l d1,a0
    	move.l _dplane3,a1
	move.w #7999,d0
_tp4:   move.b (a0)+,(a1)+	
	dbf d0,_tp4
	add.l #8000,d1
    	move.l d1,a0
    	move.l _dplane4,a1
	move.w #7999,d0
_tp5:   move.b (a0)+,(a1)+
	dbf d0,_tp5
        movem.l (sp)+,d0-d1/a0-a1
#endasm 
}


copymem()
{
#asm
     movem.l a0-a1/d0,-(sp)
     move.l _dummy,a0
     move.l _hilfsmem,a1
     move.w #959,d0
coplab:
     move.w (a0)+,(a1)+
     dbra    d0,coplab
     movem.l (sp)+,a0-a1/d0
#endasm
}

zpeek()
{
#asm
     movem.l a0/d0-d2,-(sp)
     clr.l d0
     move.w _sx,d0
     addq.w #8,d0
     lsr.w  #3,d0
     move.w _sy,d1
     addq.w #4,d1
     lsr.w #3,d1
     move.w d1,d2
     lsl.w #3,d2
     lsl.w #5,d1
     add.w d2,d1
     add.w d1,d0
     move.l d0,_posn
     lsl.w #1,d0
     add.l _hilfsmem,d0
     move.l d0,a0
     move.w (a0),_hutcode
     adda.l #80,a0
     move.w (a0),_fuscode
     movem.l (sp)+,a0/d0-d2
#endasm
}



rgbpeek()
{
#asm
     move.l a0,-(sp)
     move.l _rgbquelle,a0
     move.b (a0)+,_rot
     move.b (a0)+,_gruen
     move.b (a0)+,_blau
     move.l (sp)+,a0
#endasm
}

rgbpoke()
{
#asm
     move.l a0,-(sp)
     move.l _colpoke,a0
     move.b _rot,(a0)+
     move.b _gruen,(a0)+
     move.b _blau,(a0)+
     move.l (sp)+,a0
#endasm
}

joy()
{
#asm
     movem.l d0-d7,-(a7)
     move.l #0,_joyx
     move.l #0,_joyy
     move.l #0,_joyf
     move.w $dff00c,d0
     btst #1,d0
     beq _a1
     move.l #1,_joyx
     bra _a2
_a1  btst #9,d0
     beq _a2
     move.l #-1,_joyx
_a2  move.w d0,d1
     lsr.w #1,d1
     eor.w d0,d1
     btst #0,d1
     beq _a3
     move.l #1,_joyy
     bra _a4
_a3  btst #8,d1
     beq _a4
     move.l #-1,_joyy
_a4  move.b $bfe001,d0
     btst #7,d0
     bne _a5
     move.l #1,_joyf
_a5  movem.l (a7)+,d0-d7
#endasm
}

makescreen()
{
#asm
	movem.l	d0-d7/a0-a5,-(sp)
	move.l	_land,a3
	adda.l	_scoff,a3
	move	#959,d3
	move	#0,d5
_gcl:
	clr.l	d0
	move	(a3)+,d0	
	bsr	_getoffset
	move.l	d0,-(sp)
	move	d5,d0
	bsr	_getoffset	
	move.l	(sp)+,d1	
	move.l	d0,d2		
	bsr	_putch
	addq	#1,d5		
	dbra	d3,_gcl  	
	movem.l	(sp)+,d0-d7/a0-a5
#endasm
}

mkcode()
{
#asm
	movem.l	d0-d7/a0-a5,-(sp)
	move.l	_codn,d0		
	bsr	_getoffset
	move.l	d0,-(sp)
	move.l	_posn,d0
        move.l _posn,d5		
	bsr	_getoffset
	move.l	(sp)+,d1		
	move.l	d0,d2			
	bsr	_putch
        lsl.l #1,d5
        move.l _hilfsmem,a0
        adda.l d5,a0
        move.w #0,(a0)
	movem.l	(sp)+,d0-d7/a0-a5
#endasm
}

#asm
public_putch
_putch	
        move.l	_splane0,a0
	move.l	_dplane0,a1
	bsr	_copy
	move.l	_splane1,a0
	move.l	_dplane1,a1
	bsr	_copy
	move.l	_splane2,a0
	move.l	_dplane2,a1
	bsr	_copy
	move.l	_splane3,a0
	move.l	_dplane3,a1
	bsr	_copy
	move.l	_splane4,a0
	move.l	_dplane4,a1
	bsr	_copy
	rts
_copy:
	move	#7,d0	
	move.l	#40,d4	
	adda.l	d1,a0	
	adda.l	d2,a1	
_loop:
	move.b	(a0),(a1)
	adda.l	d4,a0
	adda.l	d4,a1		
	dbra	d0,_loop
	rts
#endasm

#asm
public_getoffset
_getoffset
	move.l	d0,d1		
	divu	#40,d1		
	clr.l	d2
	move	d1,d2		
	move.l	d2,d4
	lsl	#8,d2
	lsl	#6,d4
	add	d4,d2		
	move	d1,d4		
	lsl	#5,d1
	lsl	#3,d4
	add	d1,d4		
	sub.l	d4,d0		
	add.l	d2,d0		
	rts
#endasm

collision()
{
#asm
	move.l	d0,-(sp)
	or.w #4096,$dff098
	move.w $dff00e,d0
	btst #10,d0
	beq _nocol
	move.w #1,_mancol
	bra _colq
_nocol:
	move.w #0,_mancol
_colq:
	move.l (sp)+,d0
#endasm
}	
