home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
180.lha
/
TES.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-04-28
|
9KB
|
342 lines
/******************************************************************************
********** **********
********** THE ELECTRIC SLAVE V1.1a **********
********** **********
********** This stuff seems to be the ultimate CLI tool... **********
********** **********
*******************************************************************************
********** **********
********** Designed by Magic Ceee to add ultimate power **********
********** **********
******************************************************************************/
#include "exec/types.h"
#include "exec/tasks.h"
#include "exec/execbase.h"
#include "intuition/intuition.h"
#include "intuition/intuitionbase.h"
#include "graphics/gfxbase.h"
#include "libraries/dos.h"
/*--------------------------------------------------------------------------*/
#define MAGIX_IDCMP (GADGETUP)
#define NO_INTUI "Intuition won't open!\n"
#define NO_GFX "Graphics won't open!\n"
#define NO_WINDOW "Can't open window!\n"
/*--------------------------------------------------------------------------*/
struct ExecBase *SysBase;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Window *MagicWindow,*OutputWindow;
struct IntuiMessage *MagicMsg;
struct DateStamp MagicDate;
long magix=0;
char Date[50],Time[50];
/*****************************************************************************
*** The following strings contain the CLI-commands to be executed. ***
*****************************************************************************/
char *gad_def[] = { "DIR DF0:","DIR DF1:","DIR RAM:","INFO","RUN ED",
"","" };
/****************************************************************************/
USHORT Pairs2[] = { -1,0,-1,10,51,10,51,0 };
struct Border Border1 = { 0,0,1,0,JAM2,4,&Pairs2,NULL };
struct IntuiText TextHELP = { 3,0,JAM2,10,1,NULL,"Help",NULL };
struct IntuiText TextTIME = { 3,0,JAM2,9,1,NULL,"Time",NULL };
struct IntuiText TextMAGIC = { 3,0,JAM2,7,1,NULL,"Magic",NULL };
struct IntuiText TextU0 = { 3,0,JAM2,16,1,NULL,"U0",NULL };
struct IntuiText TextU1 = { 3,0,JAM2,16,1,NULL,"U1",NULL };
struct IntuiText TextU2 = { 3,0,JAM2,16,1,NULL,"U2",NULL };
struct IntuiText TextU3 = { 3,0,JAM2,16,1,NULL,"U3",NULL };
struct IntuiText TextU4 = { 3,0,JAM2,16,1,NULL,"U4",NULL };
struct IntuiText TextU5 = { 3,0,JAM2,16,1,NULL,"U5",NULL };
struct IntuiText TextU6 = { 3,0,JAM2,16,1,NULL,"U6",NULL };
struct IntuiText TextQUIT = { 3,0,JAM2,9,1,NULL,"Quit",NULL };
struct Gadget GadgetQUIT = {
NULL,530,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextQUIT,0,NULL,10,NULL };
struct Gadget Gadget6 = {
&GadgetQUIT,477,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextU6,0,NULL,9,NULL };
struct Gadget Gadget5 = {
&Gadget6,424,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextU5,0,NULL,8,NULL };
struct Gadget Gadget4 = {
&Gadget5,371,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextU4,0,NULL,7,NULL };
struct Gadget Gadget3 = {
&Gadget4,318,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextU3,0,NULL,6,NULL };
struct Gadget Gadget2 = {
&Gadget3,265,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextU2,0,NULL,5,NULL };
struct Gadget Gadget1 = {
&Gadget2,212,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextU1,0,NULL,4,NULL };
struct Gadget Gadget0 = {
&Gadget1,159,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextU0,0,NULL,3,NULL };
struct Gadget GadgetMAGIC = {
&Gadget0,106,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextMAGIC,0,NULL,2,NULL };
struct Gadget GadgetTIME = {
&GadgetMAGIC,53,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextTIME,0,NULL,1,NULL };
struct Gadget GadgetHELP = {
&GadgetTIME,0,0,50,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,
&Border1,NULL,&TextHELP,0,NULL,0,NULL };
/*--------------------------------------------------------------------------*/
struct NewWindow nw = {
3,0,583,10,1,1,MAGIX_IDCMP,NULL,&GadgetHELP,NULL,NULL,NULL,NULL,
0,0,0,0,WBENCHSCREEN };
/****************************************************************************/
OpenStuff()
{
if(!(IntuitionBase=(struct Intuitionbase *)
OpenLibrary("intuition.library",0)))
{
Write(Output(),NO_INTUI,strlen(NO_INTUI));
exit(0);
}
if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)))
{
Write(Output(),NO_GFX,strlen(NO_GFX));
CloseLibrary(IntuitionBase);
exit(0);
}
OutputWindow=IntuitionBase->FirstScreen->FirstWindow;
if(!(MagicWindow=OpenWindow(&nw)))
{
Write(Output(),NO_WINDOW,strlen(NO_WINDOW));
CloseLibrary(IntuitionBase);
CloseLibrary(GfxBase);
exit(0);
}
}
/*****************************************************************************/
CloseStuff()
{
CloseWindow(MagicWindow); /* Bye, folx... */
CloseLibrary(IntuitionBase);
CloseLibrary(GfxBase); /* Ceee ya next time! */
}
/*****************************************************************************/
Update()
{
struct MemHeader *MeH;
struct MemChunk *MeC;
char msg[100];
Forbid(); /* All tasks shut up */
for(MeH=(struct MemHeader *)SysBase->MemList.lh_Head;
MeH->mh_Node.ln_Succ;
MeH=(struct MemHeader *)MeH->mh_Node.ln_Succ)
{
for(MeC=MeH->mh_First;MeC;MeC=MeC->mc_Next)
{
if(MeC->mc_Bytes>sizeof(*MeC))
setmem((char *)MeC+sizeof(*MeC),
MeC->mc_Bytes-sizeof(*MeC),0);
magix+=MeC->mc_Bytes-sizeof(*MeC);
}
}
Permit(); /* Tasks may talk again */
ActivateWindow(OutputWindow);
sprintf(msg,"\nCleared %ld bytes.\n\n",magix);
Write(Output(),msg,strlen(msg));
magix=0;
}
/*****************************************************************************/
GetDate(v)
long *v;
{
int m,d,y;
long n;
n=v[0]-2251;
y=(4*n+3)/1461;
n-=1461*y/4;
y+=1984;
m=(5*n+2)/153;
d=n-(153*m+2)/5+1;
m+=3;
if(m>12)
{
y++;
m-=12;
}
sprintf(Date,"%02d.%02d.%d",d,m,y);
}
/****************************************************************************/
GetTime()
{
int h,m;
DateStamp(&MagicDate);
h=MagicDate.ds_Minute/60;
m=MagicDate.ds_Minute%60;
sprintf(Time,"%02d:%02d:%02d",h,m,MagicDate.ds_Tick/TICKS_PER_SECOND);
}
/****************************************************************************/
Assignment()
{
int i;
char msg[100];
Write(Output(),"\n",1);
for(i=0;i<=6;i++)
{
if(strlen(gad_def[i])<1)
{
sprintf(msg,"Gadget U%d not assigned\n",i);
Write(Output(),msg,strlen(msg));
}
else
{
sprintf(msg,"Gadget U%d assigned to <%s>\n",i,gad_def[i]);
Write(Output(),msg,strlen(msg));
}
}
Write(Output(),"\n",1);
}
/****************************************************************************/
ShowTime()
{
long chip,fast,v[3];
char msg[100];
DateStamp(v);
GetDate(v);
GetTime();
chip=AvailMem(MEMF_CHIP);
fast=AvailMem(MEMF_FAST);
sprintf(msg,"\nToday is %s, %s. Free memory: %ld bytes.\n\n",Date,Time,fast+chip);
ActivateWindow(OutputWindow);
Write(Output(),msg,strlen(msg));
}
/****************************************************************************/
Action(what)
int what;
{
ActivateWindow(OutputWindow);
Write(Output(),"\n",1);
Execute(gad_def[what-3],0,0);
Write(Output(),"\n",1);
}
/****************************************************************************/
KickThem()
{
if(strlen(gad_def[0])<1) OffGadget(&Gadget0,MagicWindow,NULL);
if(strlen(gad_def[1])<1) OffGadget(&Gadget1,MagicWindow,NULL);
if(strlen(gad_def[2])<1) OffGadget(&Gadget2,MagicWindow,NULL);
if(strlen(gad_def[3])<1) OffGadget(&Gadget3,MagicWindow,NULL);
if(strlen(gad_def[4])<1) OffGadget(&Gadget4,MagicWindow,NULL);
if(strlen(gad_def[5])<1) OffGadget(&Gadget5,MagicWindow,NULL);
if(strlen(gad_def[6])<1) OffGadget(&Gadget6,MagicWindow,NULL);
}
/****************************************************************************/
main()
{
int end=FALSE,gadg;
long chip,fast,total,Code,Class,v[3];
unsigned char w_msg;
OpenStuff();
KickThem();
while(!end)
{
Wait(1<<MagicWindow->UserPort->mp_SigBit);
while(MagicMsg=(struct IntuiMessage *)GetMsg(MagicWindow->UserPort))
{
Code=MagicMsg->Code;
Class=MagicMsg->Class;
gadg=((struct Gadget *)(MagicMsg->IAddress))->GadgetID;
ReplyMsg(MagicMsg);
if(Class==GADGETUP)
{
switch(gadg)
{
case 0: Assignment(); break;
case 1: ShowTime(); break;
case 2: Update(); break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9: Action(gadg); break;
case 10: end=TRUE; break;
}
}
}
}
CloseStuff();
}