
 /***************************************************************************
 *Rolf Schneider | Am Birkenwaeldchen 16/18 | 58 Hagen 7 | Tel.: 02331/45569*
 *                                                                          *
 *                      First Amiga Artists Program:                        *
 *                                                                          *
 *                          -- Artist's Copy I --                           *
 *AC2                                                                       *
 ***************************************************************************/

 /**** Includes... *********************************************************/

#include "libraries/dosextens.h"
#include "exec/memory.h"
#include "intuition/intuition.h"


 /**** Globals... **********************************************************/

extern struct FileLock *Lock();

typedef char FName[32]; 

struct Window *Wini2;
struct RastPort *RP;
struct FileInfoBlock Mbl,*Myfib,*chip;
struct FileLock *lock;
struct InfoData Mid,*MyMid,*Ichip;

long DosBase=0;
int Dis[2];

USHORT DPoint[] = {
	0x0000,0x0000,

	0x300c,0x300c,
	0x4002,0x4002,
	0x9819,0x9819,
	0xa005,0xa005,
	0x2814,0x2ff4,
	0x0810,0x0ff0,
	0x0810,0x0ff0,
	0x0810,0x0ff0,
	0x0ff0,0x0ff0,
	0x0ff0,0x0c30,
	0x0ff0,0x0d30,
	0x27f4,0x2534,
	0xa005,0xa005,
	0x9819,0x9819,
	0x4002,0x4002,
	0x300c,0x300c,

	0x0000,0x0000 };
 /**** Code... *************************************************************/

InitAC2 (Wn)
struct Window *Wn;
{
DosBase = OpenLibrary ("dos.library",0);
chip    = (struct FileInfoBlock *)  AllocMem (sizeof (Mbl),MEMF_CHIP);
Myfib   = &Mbl;
Ichip   = (struct InfoData *)  AllocMem (sizeof (Mid),MEMF_CHIP);
MyMid   = &Mid;
Wini2   = Wn;
RP      = Wini2->RPort;
}

AntiInitAC2 ()
{
FreeMem (chip,sizeof(Mbl),MEMF_CHIP);
FreeMem (Ichip,sizeof(Mid),MEMF_CHIP);
CloseLibrary (DosBase);
}

int Dir (Name,Feld,Status,Drive,NewName)

UBYTE *Status;
char *Name;
FName *Feld;
short Drive;
char *NewName;
{
UBYTE *S;
short st,j;
FName *F;
int i=0;

Dis[Drive] = 0;
S 	   = Status;
F 	   = Feld;

Disk (0);
lock = Lock (Name,ACCESS_READ);
if ((Examine (lock,Myfib)) == 0) return (0);
namcpy (Myfib->fib_FileName,NewName);
for (j=0;j<=199;++j)
	{
	st = ExNext (lock,Myfib);
	if (st == 0) break;
	*Status++ = (Myfib->fib_DirEntryType<0)?(0):(1);
	namcpy (Myfib->fib_FileName,Feld++);
	i++;
	}
UnLock (lock);

SetAPen (RP,1);
RectFill (RP,Drive*316+8,22,Drive*316+279,173);
RectFill (RP,Drive*316+5,11,Drive*316+312,18);
SetAPen (RP,2);
Move (RP,Drive*316+12,18);
Text (RP,NewName,namlen(NewName));
Move (RP,Drive*316+5,19);
Draw (RP,Drive*316+312,19);
Puti (F,S,0,i,Drive);

Disk (1);
return (i);
}

int namlen (st)

char *st;
{
int i;
UBYTE j;

for (i=0;i<=110;++i)
	{
	j=*st++;
	if ((j&127)<32) break;
	}
return (i);
}

namcpy (st1,st2)

char *st1,*st2;
{
while (*st1 != '\0')
	{
	*st2++ = *st1++;
	}
*st2 = '\0';
}

namcat (st1,st2)

char *st1,*st2;
{
namcpy (st2,(st1+namlen(st1)));
}

namcut (st)

char *st;
{
int i,j=0;

st += namlen(st);
if (*st == ':') return(0);
for (i=0;i<=110;++i)
	{
	if (*st == '/') j=1;
	if (*st == ':') {j=1; st++;}
	if (j == 1) break;
	st--;
	}
*st = '\0';
return (1);
}

Scroll (Feld,Status,Grose,Drive,Richtung)

FName *Feld;
UBYTE *Status;
short Drive,Grose,Richtung;
{
struct IntuiMessage *Mymes;
short i,Px,Py,Sx1,Sy1,Sx2,Sy2,g,h,st=0,w=0;
char c[3],lk1[3],lk2[3];

namcpy (" |",lk1);
namcpy ("d|",lk2);
lk1[1] = 0xb7;
lk2[1] = 0xb7;

if (Grose < 19) return(0);

Px = 8+Drive*316;
Py = 100+Richtung*72;
Sx1= 8+Drive*316;
Sy1= 22;
Sx2= 279+Drive*316;
Sy2= 173;

if (Richtung == 1) w=18;
Status += (Dis[Drive]+w+Richtung);
Feld   += (Dis[Drive]+w+Richtung);
g       = Dis[Drive];
h       = ((Richtung+1)/2)*(Grose-19);

for (i=g;i!=h;i+=Richtung)
	{
	SetAPen (RP,2);
	SetBPen (RP,1);
	ScrollRaster (RP,0,8*Richtung,Sx1,Sy1,Sx2,Sy2);
	Move (RP,Px,Py);
	if (*Status == 0) namcpy (lk1,c);
	else if (*Status == 1) namcpy (lk2,c);
	else {  namcpy (lk1,c);
		st = 3;
	     }
	Text (RP,c,2);
	Move (RP,Px+16,Py);
	if (st == 3) {
		     SetBPen (RP,2);
		     SetAPen (RP,1);
		     }
	Text (RP,Feld,namlen(Feld));

	if (st == 0) Delay (7);
	st = 1;
	Mymes = (struct IntuiMessage *) GetMsg(Wini2->UserPort);
	if (Mymes->Class == GADGETUP) {i+=Richtung; st=2; ReplyMsg (Mymes); }
	if (st == 2) break;

	Delay (3);
	Feld   += Richtung;
	Status += Richtung;
	}
SetBPen (RP,1);
Dis[Drive] = i;
}

int Fuck (Drive)

short Drive;
{
return (Dis[Drive]);
}

Disk (a)

short a;
{
switch (a)
	{
	case 0: 
		SetPointer (Wini2,DPoint,16,16,-7,-7);
		break;

	case 1:
		ClearPointer (Wini2);
		break;
	}
}

Puti (Feld,Status,Feldposi,Anzahl,Drive)

FName *Feld;
UBYTE *Status;
short Feldposi,Anzahl,Drive;
{
short j,x,y=28;
char lk[2];

lk[0] = 0xb7;
lk[1] = 0x00;
Feld   += Feldposi;
Status += Feldposi;
x       = Drive*316+24;
for (j=0;j<=18;++j)
	{
	if (j==Anzahl) break;
	Move (RP,x,y);
	Text (RP,Feld,namlen(Feld));
	if (*Status++ == 1)
		{
		Move (RP,x-16,y);
		Text (RP,"d",1);
		}
	Move (RP,x-8,y);
	Text (RP,lk,1);
	y += 8;
	Feld++;
	}
}


char s[]="SOURCE:  Free:xxxx, State:Rx, Errs:xxxx|DESTI:  Free:xxxx, State:Rx, Errs:xxxx";

Attack (Sc,Dt)

char *Sc,*Dt;
{
int j;

for (j=0;j<=1;++j)
	{
	lock = Lock (((j==0) ? Sc : Dt),ACCESS_READ);
	Info (lock,MyMid);
	Trs (&s[j*39+14],((MyMid->id_NumBlocks)-(MyMid->id_NumBlocksUsed)));
	if ((MyMid->id_DiskState) == 80) s[j*39+27] = 'O';
	else				 s[j*39+27] = 'W';
	Trs (&s[j*39+35],MyMid->id_NumSoftErrors);
	UnLock (lock);
	}
SetWindowTitles (Wini2,s,-1);
}


int z[] = {1000,100,10,1};

Trs (String,n)

char *String;
int n;
{
int j,h;

for (j=0;j<=3;++j)
	{
	h 	  = n/z[j];
	*String++ = h+48;
	n	  = n-h*z[j];
	}
}

