home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d564
/
aload.lha
/
ALoad
/
src.lzh
/
src4
/
aload.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-24
|
19KB
|
716 lines
/* :ts=4 ***************************************************
ALoad
(c) by Alexandru-Aurel Balmosan [aug 1991]
************************************************************/
#include "adef.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <exec/tasks.h>
#include <exec/memory.h>
#include <hardware/custom.h>
#include <hardware/intbits.h>
#include <hardware/dmabits.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/layers.h>
#include <workbench/icon.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <intuition/screens.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/icon.h>
#include <proto/gadtools.h>
long _BackGroundIO = 0;
char * _procname = "Aurel's ALoad v1.1c";
long _priority = 11;
long _old_pri = 0;
long _stack = 4000;
extern struct GfxBase * GfxBase;
extern struct IntuitionBase * IntuitionBase;
struct Library * IconBase=NULL;
struct Library * GadToolsBase=NULL;
struct Interrupt VBankIT;
struct MsgPort * port;
extern char * _ProgramName;
extern void XCEXIT(long);
struct WIN_DEF wd;
#define NG_1 (NGAry + 0)
#define NG_2 (NGAry + 1)
#define NG_3 (NGAry + 2)
#define NG_4 (NGAry + 3)
#define GAD_1 0
#define GAD_2 1
#define GAD_3 2
#define GAD_4 3
struct Gadget * GList;
struct VisualInfo * VisInfo;
struct TextAttr MyFont =
{ "topaz.font",
8,
FS_NORMAL,
FPF_ROMFONT
};
struct NewGadget NGAry[4] = {
{ 0,0,16,12,"S",NULL,GAD_1,PLACETEXT_IN,NULL},
{ 0,0,16,12,"R",NULL,GAD_4,PLACETEXT_IN,NULL},
{ 0,0,42,12,"Time",NULL,GAD_2,PLACETEXT_BELOW,NULL},
{ 0,0,42,12,"Factor",NULL,GAD_3,PLACETEXT_BELOW,NULL}
};
struct Gadget * Gad_1;
struct Gadget * Gad_2;
struct Gadget * Gad_3;
struct Gadget * Gad_4;
char * Buf_2;
char * Buf_3;
int DefNumber_2 = 5*50;
int DefNumber_3 = 26;
int GadSet=FALSE;
int width, height, x, y, time, factor;
int size_abuffer=0,size_buffer=0;
#define MASK_CURVE (0x1)
#define MASK_LEVEL (0x2)
#define LEVEL_COLOR (0x2)
#define BACK_FILL_COLOR (0x0)
struct Gadget *
InitGads(scr)
struct Screen *scr;
{
struct Gadget *gad,*CreateGadget(),*CreateContext();
struct VisualInfo *GetVisualInfo();
short i;
GList = NULL;
if ((VisInfo = GetVisualInfo(scr, TAG_END)) == NULL) return(NULL);
{ struct NewGadget *ng;
for (i = 0, ng = NGAry; i < sizeof(NGAry)/sizeof(NGAry[0]); ++i, ++ng)
{ ng->ng_VisualInfo = (APTR)VisInfo;
ng->ng_TextAttr = &MyFont;
}
}
if ((gad = CreateContext(&GList)) == NULL) return(NULL);
GadSet = TRUE;
Gad_1 = gad = CreateGadget(BUTTON_KIND, gad, NGAry + 0,
TAG_END
);
if (gad == NULL)
return(NULL);
Gad_2 = gad = CreateGadget(BUTTON_KIND, gad, NGAry + 1,
TAG_END
);
if (gad == NULL)
return(NULL);
Gad_3 = gad = CreateGadget(INTEGER_KIND, gad, NGAry + 2,
GTIN_Number, DefNumber_2,
TAG_END
);
if (gad == NULL)
return(NULL);
Buf_2 = ((struct StringInfo *)gad->SpecialInfo)->Buffer;
Gad_4 = gad = CreateGadget(INTEGER_KIND, gad, NGAry + 3,
GTIN_Number, DefNumber_3,
TAG_END
);
if (gad == NULL)
return(NULL);
Buf_3 = ((struct StringInfo *)gad->SpecialInfo)->Buffer;
return(GList);
}
void
FreeGads()
{
if (GList)
FreeGadgets(GList);
if (VisInfo)
FreeVisualInfo(VisInfo);
VisInfo = NULL;
GList = NULL;
GadSet=FALSE;
}
#define malloc(s) AllocMem(size_abuffer=(s),MEMF_PUBLIC)
#define calloc(s,w) AllocMem(size_buffer=((s)*(w)),MEMF_PUBLIC | MEMF_CLEAR)
void exit_all(er)
int er;
{
Forbid();
(void)SetFunction((struct Library *)IntuitionBase, -78, (APTR)GetOldCloseWB());
(void)SetFunction((struct Library *)IntuitionBase, -210, (APTR)GetOldOpenWB());
Permit();
if (er >= 0) RemIntServer(INTB_VERTB, &VBankIT);
if (wd.raster) FreeRaster((PLANEPTR)wd.raster,wd.width,wd.height);
if (wd.abuffer) FreeMem((char *)wd.abuffer,size_abuffer);
if (wd.buffer) FreeMem((char *)wd.buffer,size_buffer);
if (wd.win) CloseWindow(wd.win);
if (GadSet) FreeGads();
if (GadToolsBase) CloseLibrary((struct Library *)GadToolsBase);
if (IconBase) CloseLibrary((struct Library *)IconBase);
if (IntuitionBase)CloseLibrary((struct Library *)IntuitionBase);
if (GfxBase) CloseLibrary((struct Library *)GfxBase);
SetTaskPri(FindTask(0),_old_pri);
XCEXIT(er);
}
void CloseWin(wd)
register struct WIN_DEF *wd;
{ Signal(wd->owner,wd->signal_close);
while (wd->ss_rast!=2) ;
}
void OpenWin(wd)
register struct WIN_DEF *wd;
{ if (wd->ss_rast == 2)
{ Signal(wd->owner, wd->signal_open);
while(wd->ss_rast == 2);
}
}
struct Window *OpenDisplayWindow(x,y,width,height,name,size)
int x, y, width, height;
char *name;
int size;
{ register struct Window *win;
TitlePtr = name;
SizeFlag = size;
WIN_XPOS = x;
WIN_YPOS = y;
WIN_WIDTH = width;
WIN_HEIGHT= height;
IDCMPFlags = IDCMP_CLOSEWINDOW ;
if (size)
IDCMPFlags |= BUTTONIDCMP|IDCMP_REFRESHWINDOW;
win = (struct Window *)OpenWindowTagList(NULL, WinTagList);
if (win != NULL)
{ win->RPort->AreaInfo = &wd.ainfo;
win->RPort->TmpRas = &wd.tmpras;
SetDrMd(win->RPort, JAM1);
}
return (win);
}
int NewPrefs()
{ struct Window *win;
struct DiskObject *di;
char **ToolArray;
static char wstr[80],tstr[40],fstr[40];
int not_done=1,cont=1,x,i;
struct IntuiMessage *im;
struct Gadget *Gad;
char *c,**s,*w,*ti,*fa,**p_wd,**p_ti,**p_fa;
width = wd.width;
height = wd.height;
win = OpenDisplayWindow(wd.x,wd.y,wd.width,wd.height,"Set new preferences",TRUE);
if (win)
{ x=win->BorderLeft;
for (i=0;i<4;i++)
{ NGAry[i].ng_TopEdge = win->BorderTop;
NGAry[i].ng_LeftEdge=x;
x += NGAry[i].ng_Width;
}
DefNumber_2 = wd.End_CNT;
DefNumber_3 = wd.factor;
if (InitGads(win->WScreen))
{ AddGList(win,GList,0,-1,NULL);
RefreshGList(GList, win, NULL, -1);
GT_RefreshWindow(win,NULL);
RefreshWindowFrame(win);
while (not_done)
{ WaitPort(win->UserPort);
while (im = (struct IntuiMessage *)GT_GetIMsg(win->UserPort))
{ switch (im->Class)
{ case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(win);
GT_EndRefresh(win, TRUE);
break;
case IDCMP_CLOSEWINDOW:
not_done=0;
cont=0;
break;
case BUTTONIDCMP:
Gad = (struct Gadget *)im->IAddress;
wd.x = win->LeftEdge;
wd.y = win->TopEdge;
wd.width = win->Width;
wd.height = win->Height;
stcd_i(Buf_3,&factor);
if (factor <1 || factor >31) factor = 26;
wd.factor = factor;
stcd_i(Buf_2,&time);
wd.End_CNT = time;
switch(Gad->GadgetID)
{ case GAD_1:
if (di = (struct DiskObject *) GetDiskObject(_ProgramName))
{ ToolArray = di->do_ToolTypes;
c=(char *)FindToolType(ToolArray,"WINDOW");
if (c)
{ s = ToolArray;
while (*s != 0 &&
(c<*s || c> (*s + strlen(*s)))) s++;
w = *s;
p_wd = s;
strcpy(wstr,"WINDOW=");
c = wstr + strlen("WINDOW=");
c += stci_d(c,wd.x); *c++ = '/';
c += stci_d(c,wd.y); *c++ = '/';
c += stci_d(c,wd.width); *c++ = '/';
(void) stci_d(c,wd.height);
*s = wstr;
}
else w = NULL;
c = (char *)FindToolType(ToolArray,"TIME");
if (c)
{ s = ToolArray;
while (*s != 0 &&
(c<*s || c> (*s + strlen(*s)))) s++;
ti = *s;
p_ti = s;
strcpy(tstr,"TIME=");
(void) stci_d(tstr + strlen("TIME="),wd.End_CNT);
*s = tstr;
}
else ti = NULL;
c = (char *)FindToolType(ToolArray,"FACTOR");
if (c)
{ s = ToolArray;
while (*s != 0 &&
(c<*s || c> (*s + strlen(*s)))) s++;
fa = *s;
p_fa = s;
strcpy(fstr,"FACTOR=");
(void) stci_d(fstr + strlen("FACTOR="),wd.factor);
*s = fstr;
}
else fa = NULL;
PutDiskObject(_ProgramName,di);
if (w) { *p_wd = w; w = 0; }
if (ti) { *p_ti = ti; ti = 0; }
if (fa) { *p_fa = fa; fa = 0; }
FreeDiskObject(di);
}
break;
case GAD_4:
not_done=0;
cont=1;
default: break;
}
default: break;
}
GT_ReplyIMsg(im);
}
}
}
CloseWindow(win);
FreeGads();
}
return cont;
}
void set_values()
{
wd.xstart = wd.win->BorderLeft;
wd.ystart = wd.height - wd.win->BorderBottom-1;
wd.dy = wd.ystart - wd.win->BorderTop;
wd.dx = wd.width - wd.xstart - wd.win->BorderRight;
if (wd.dx <=0) wd.dx = 1;
if (wd.dy <=0) wd.dy = 1;
wd.buffer_size = wd.dx;
}
void init_all()
{ struct DiskObject *di;
char **ToolArray;
char *c;
memset((char *)&wd,0,sizeof(wd));
memset((char *)&VBankIT, 0, sizeof(VBankIT));
GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",36);
if (GfxBase == NULL) exit_all(-100);
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library",36);
if (IntuitionBase == NULL) exit_all(-99);
IconBase = (struct Library *)OpenLibrary("icon.library",36);
if (IconBase == NULL) exit_all(-98);
GadToolsBase = (struct Library *)OpenLibrary("gadtools.library",36);
if (GadToolsBase == NULL) exit_all(-97);
if (di = (struct DiskObject *) GetDiskObject(_ProgramName))
{ ToolArray = di->do_ToolTypes;
c=(char *)FindToolType(ToolArray,"WINDOW");
if (c != 0)
{ c += stcd_i(c,&x);
if (*c++ == '/' )
{ c += stcd_i(c,&y);
if (*c++ == '/')
{ c += stcd_i(c, &width);
if (*c++ == '/') (void) stcd_i(c, &height);
else goto a;
} else goto a;
} else goto a;
}
else
{
a: x=y=0;
height = 64;
width = 256;
}
c = (char *)FindToolType(ToolArray,"TIME");
if (c != 0)
{ stcd_i(c,&time);
if (time <=0 ) time = 5*50;
}
else time = 5*50;
c = (char *)FindToolType(ToolArray,"FACTOR");
if (c != 0)
{ stcd_i(c, &factor);
if (factor <=0 || factor >31) factor = 26;
}
else factor = 26;
wd.factor = factor;
FreeDiskObject(di);
}
else
{ x=y=0;
height = 64;
width = 256;
time = 5*50;
wd.factor = 26;
}
SetBase(&wd);
wd.owner = (struct Task *)FindTask(0);
wd.signal= 1L << AllocSignal(-1);
wd.signal_open= 1L << AllocSignal(-1);
wd.signal_close= 1L << AllocSignal(-1);
_old_pri=SetTaskPri(wd.owner, _priority);
wd.cnt = wd.End_CNT = time;
wd.win = OpenDisplayWindow(x,y,width,height,_procname,0);
if (wd.win == NULL) exit_all(-50);
wd.width = width;
wd.height = height;
wd.x = x;
wd.y = y;
wd.abuffer = (APTR) malloc((width+3)*5);
if (wd.abuffer == NULL) exit_all(-49);
wd.raster = (APTR) AllocRaster(width,height);
if (wd.raster == NULL) exit_all(-48);
InitArea(&wd.ainfo,(short *)wd.abuffer,(long)width);
InitTmpRas(&wd.tmpras,(PLANEPTR)wd.raster,RASSIZE(width,height));
set_values();
if ( (wd.buffer = (long *) calloc(wd.dx,4)) == NULL) exit_all(-47);
wd.buffer_end = wd.buffer + (wd.dx-1);
VBankIT.is_Node.ln_Type = NT_INTERRUPT;
VBankIT.is_Node.ln_Pri = 126;
VBankIT.is_Node.ln_Name = "ALoad V1.03a VBlank Sumer";
VBankIT.is_Data = (APTR) &wd;
VBankIT.is_Code = VertBServer;
AddIntServer(INTB_VERTB, &VBankIT);
wd.open = OpenWin;
wd.close = CloseWin;
wd.ss_rast = 0;
Forbid();
SetOldCloseWB(SetFunction((struct Library *)IntuitionBase, -78, NewClose));
SetOldOpenWB(SetFunction((struct Library *)IntuitionBase, -210, NewOpen));
Permit();
}
#define FreeRasterSem(ww) (ww)->ss_rast=0
int GetRasterSem(wd)
struct WIN_DEF *wd;
{ register int value;
if ((value=GfxBase->BlitLock) && (wd->ss_rast==0) )
{ wd->ss_rast = 1;
if (wd->win->WScreen->LayerInfo.Lock.ss_QueueCount>=0)
{ value = 0;
FreeRasterSem(wd);
}
}
else value = 0;
return value;
}
void ReDraw(scale,start)
register short scale;
short start;
{ register struct RastPort *RP=wd.win->RPort;
register short delta=wd.dy-1;
register short rb,i=wd.xstart+start,h;
short ybase = wd.ystart;
short pos = wd.b_pos-2-start;
short cnt;
register long *ptr = wd.buffer + ((wd.pos+start)%wd.dx);
#define RB() CalcShift(delta*(*ptr)/scale)
#define NEXT() if ((++ptr)>wd.buffer_end) ptr=wd.buffer
wd.s_rast++;
AreaMove(RP, i, ybase);
rb = RB(); NEXT();
if (rb>delta) rb = delta;
h = rb;
AreaDraw(RP, i, ybase - rb);
cnt=0;
for(i++;pos>0;i++,pos--)
{ rb = RB(); NEXT();
if (rb>delta) rb = delta;
if (h != rb)
{ if (cnt) AreaDraw(RP, i-1, ybase - h);
h = rb; cnt=0;
AreaDraw(RP, i, ybase - rb);
}
else cnt++;
}
rb = RB();
if (rb>delta) rb = delta;
if (h != rb && cnt) AreaDraw(RP, i-1, ybase - h);
AreaDraw(RP, i, ybase - rb);
AreaDraw(RP, i, ybase);
wd.s_rast--;
if (wd.scale != scale)
{ if (scale < wd.dy)
{ SetWrMsk(RP,MASK_CURVE | MASK_LEVEL);
SetAPen(RP, BACK_FILL_COLOR);
RectFill(RP, wd.xstart+start, ybase-delta, h=wd.xstart+wd.dx-1, ybase);
SetWrMsk(RP, MASK_LEVEL);
SetAPen(RP, LEVEL_COLOR);
for(i=scale-1; i>0; i--)
{ rb = delta * i / scale;
Move(RP, h, ybase - rb);
Draw(RP, wd.xstart+start, ybase - rb);
}
}
else
{ SetWrMsk(RP, MASK_CURVE | MASK_LEVEL);
SetAPen(RP, LEVEL_COLOR);
RectFill(RP, wd.xstart+start, ybase-delta, wd.xstart+wd.dx-1, ybase);
}
}
wd.scale = scale;
SetWrMsk(RP, MASK_CURVE);
SetAPen(RP, MASK_CURVE);
AreaEnd(RP);
}
void Update(wd)
register struct WIN_DEF *wd;
{ register short dx = wd->dx;
register long h;
if (wd->Ready_CNT < ((1<<15)-1))
h = (wd->Ready_CNT<<16);
else
h = (1<<31)-1;
if (wd->Count_CNT>0) h /= wd->Count_CNT;
wd->Ready_CNT = wd->Count_CNT = 0;
if ( (wd->value = h - (((h - wd->value)*wd->factor)>>5)-1) <0) wd->value=0;
if ( wd->b_pos<dx )
{ wd->buffer[wd->b_pos] = wd->value;
wd->b_pos++;
}
else
{ wd->buffer[(wd->pos+dx)%dx] = wd->value ;
wd->pos++;
}
Signal(wd->owner,wd->signal);
}
void DrawPeak(rp,i)
register struct RastPort *rp;
register int i;
{ if (i>(wd.dy-1)) i=wd.dy-1;
SetWrMsk(rp,MASK_CURVE);
SetAPen(rp,MASK_CURVE);
Move(rp, wd.xstart + wd.b_pos-1, wd.ystart - i);
Draw(rp, wd.xstart + wd.b_pos-1, wd.ystart);
}
void _main()
{ int old_pos, old_bpos,pos,bpos;
register unsigned long h;
long value;
register short scale, maxscale;
register struct RastPort *RP;
struct Message *msg;
init_all();
old_pos = 0;
old_bpos = 1;
wd.scale = 1;
scale = 1;
wd.s_int = 1;
RP = wd.win->RPort;
SetWrMsk(RP,MASK_CURVE | MASK_LEVEL);
SetAPen(RP, BACK_FILL_COLOR);
RectFill(RP, wd.xstart, wd.ystart - wd.dy, wd.xstart+wd.dx-1, wd.ystart);
for (;;)
{ if (wd.win) h = 1 << wd.win->UserPort->mp_SigBit;
else h = 0;
h = Wait( h | wd.signal | wd.signal_open | wd.signal_close);
if (h & wd.signal_close && wd.win )
{ wd.width = wd.win->Width;
wd.height= wd.win->Height;
wd.x = wd.win->LeftEdge;
wd.y = wd.win->TopEdge;
CloseWindow(wd.win);
wd.win = NULL;
wd.ss_rast = 2;
}
if (wd.win == NULL && h & wd.signal_open)
{ wd.win = OpenDisplayWindow(wd.x,wd.y,wd.width,wd.height,_procname,0);
if (wd.win != NULL)
{ FreeRasterSem(&wd);
RP = wd.win->RPort;
SetWrMsk(RP,MASK_CURVE | MASK_LEVEL);
SetAPen(RP, BACK_FILL_COLOR);
RectFill(RP, wd.xstart, wd.ystart - wd.dy, wd.xstart+wd.dx-1, wd.ystart);
wd.s_rast++;
scale = CalcShift( FindMaxValue(&wd))+1;
wd.scale = 1;
wd.s_rast--;
ReDraw(scale,0);
}
}
if (wd.win && (h & (1<< wd.win->UserPort->mp_SigBit)))
{ msg = (struct Message *)GetMsg(wd.win->UserPort);
ReplyMsg(msg);
wd.width = wd.win->Width;
wd.height= wd.win->Height;
wd.x = wd.win->LeftEdge;
wd.y = wd.win->TopEdge;
wd.s_int=0;
wd.ss_rast = 1;
wd.s_rast++;
CloseWindow(wd.win);
wd.win = NULL;
if (NewPrefs())
{ FreeMem((char *)wd.buffer,size_buffer);
FreeMem((char *)wd.abuffer,size_abuffer);
wd.abuffer = (APTR) malloc((wd.width+3)*5);
if (wd.abuffer == NULL) exit_all(-49);
FreeRaster((PLANEPTR)wd.raster,width,height);
wd.raster = (APTR) AllocRaster(wd.width,wd.height);
if (wd.raster == NULL) exit_all(-48);
InitArea(&wd.ainfo,(short *)wd.abuffer,(long)wd.width);
InitTmpRas(&wd.tmpras,(PLANEPTR)wd.raster,RASSIZE(wd.width,wd.height));
wd.win = OpenDisplayWindow(wd.x,wd.y,wd.width,wd.height,_procname,0);
if (wd.win != NULL)
{ set_values();
if ( (wd.buffer = (long *) calloc(wd.dx,4)) == NULL)
{
exit_all(-47);
}
wd.buffer_end = wd.buffer + (wd.dx-1);
wd.b_pos = wd.pos = 0;
wd.scale = -1;
wd.value = 0;
old_bpos = 1;
old_pos = 0;
scale = 1;
RP = wd.win->RPort;
SetWrMsk(RP,MASK_CURVE | MASK_LEVEL);
SetAPen(RP, BACK_FILL_COLOR);
RectFill(RP, wd.xstart, wd.ystart - wd.dy, wd.xstart+wd.dx-1, wd.ystart);
}
}
else exit_all(0);
wd.s_rast--;
wd.ss_rast = 0;
wd.s_int=1;
}
if (wd.win && (h & wd.signal) && GetRasterSem(&wd))
{ RP = wd.win->RPort;
wd.s_rast++;
bpos = wd.b_pos;
pos = wd.pos;
value = wd.value;
maxscale = CalcShift( FindMaxValue(&wd))+1;
wd.s_rast--;
if (bpos < wd.dx)
{ scale = CalcShift(value)+1;
if (scale > wd.scale) ReDraw(scale,0);
else
{ h = bpos - old_bpos+1;
if (h==1)
DrawPeak(RP,CalcShift((wd.dy-1)*value/wd.scale));
else
{ if (maxscale > wd.scale)
ReDraw(maxscale, 0);
else
ReDraw(wd.scale, old_bpos-1);
}
}
}
else
{ h = pos - old_pos;
if (maxscale != wd.scale)
ReDraw(maxscale, 0);
else
{ if (h >= wd.dx || old_bpos < bpos)
ReDraw(maxscale, 0);
else
{ SetWrMsk(RP, MASK_CURVE);
ScrollRaster(RP, h, 0, wd.xstart, wd.ystart - wd.dy + 1,
wd.xstart + wd.dx -1, wd.ystart);
if (h>1)
ReDraw(maxscale, wd.dx-h);
else
DrawPeak(RP,CalcShift((wd.dy-1)*value/wd.scale));
}
}
}
old_bpos = bpos+1;
old_pos = pos;
FreeRasterSem(&wd);
}
}
}